@maqiuyao/dxf-viewer 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var ia=Object.defineProperty;var sa=(h,t,e)=>t in h?ia(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e;var p=(h,t,e)=>sa(h,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Se=require("three"),ks=require("three-mesh-bvh"),ra=require("loglevel"),sn=require("three/examples/jsm/renderers/CSS2DRenderer.js"),na=require("three/examples/jsm/exporters/DRACOExporter.js"),aa=require("three/examples/jsm/exporters/GLTFExporter.js"),oa=require("three/examples/jsm/exporters/OBJExporter.js"),la=require("three/examples/jsm/exporters/STLExporter.js"),ha=require("poly-extrude"),ca=require("i18next"),xe=require("three/examples/jsm/utils/BufferGeometryUtils.js"),da=require("three/src/extras/Earcut.js"),ua=require("2d-polygon-self-intersections"),fa=require("three/examples/jsm/modifiers/SimplifyModifier.js"),pa=require("three/examples/jsm/renderers/SVGRenderer.js"),ma=require("three/examples/jsm/loaders/RGBELoader.js"),ga=require("js-base64"),ya=require("concaveman"),xa=require("polybooljs"),bi=require("jsbi"),ba=require("3d-tiles-renderer"),va=require("protobufjs"),wa=require("three/examples/jsm/loaders/DDSLoader.js"),Ds=require("pako"),Ma=require("three/examples/jsm/geometries/TextGeometry.js"),Ta=require("opentype.js"),Ca=require("three/examples/jsm/loaders/FontLoader.js"),Sa=require("three/examples/jsm/loaders/ColladaLoader.js"),Oa=require("three/examples/jsm/loaders/DRACOLoader.js"),Ea=require("three/examples/jsm/loaders/FBXLoader.js"),_a=require("three/examples/jsm/loaders/GLTFLoader.js"),Pa=require("three/examples/jsm/loaders/MTLLoader.js"),Aa=require("three/examples/jsm/loaders/OBJLoader.js"),Ia=require("three/examples/jsm/loaders/PLYLoader.js"),ka=require("three/examples/jsm/loaders/STLLoader.js"),Xt=require("polygon-clipping"),Da=require("three/examples/jsm/postprocessing/EffectComposer.js"),Ba=require("three/examples/jsm/postprocessing/RenderPass.js"),La=require("three/examples/jsm/postprocessing/ShaderPass.js"),Ra=require("three/examples/jsm/postprocessing/SAOPass.js"),Fa=require("three/examples/jsm/postprocessing/SSAOPass.js"),za=require("three/examples/jsm/postprocessing/OutlinePass.js"),ja=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),Va=require("three/examples/jsm/postprocessing/BloomPass.js"),Ua=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),Na=require("three/examples/jsm/shaders/FXAAShader.js"),Ha=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),qs=require("lodash");function gi(h){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(h){for(const e in h)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>h[e]})}}return t.default=h,Object.freeze(t)}const d=gi(Se),Ws=gi(ra),Ga=gi(ga),yt=gi(xa),qa=gi(va),Ft=1,Ge=new d.Sphere,ts=new d.Vector3,is=new d.Vector3,Ys=new d.Vector3,Xs=new d.Vector3;d.Line.prototype.raycast=function(h,t){const e=this.geometry,i=this.matrixWorld,s=h.params.Line.threshold,r=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),Ge.copy(e.boundingSphere),Ge.applyMatrix4(i),Ge.radius+=s,h.ray.intersectsSphere(Ge)===!1)return;const n=s*s,a=this.isLineSegments?2:1,o=e.index,l=e.attributes,c=l.position,u=t.length;if(o!==null){const f=this.userData.batches;if(f&&f.length>0&&f[0].boundingSphere)for(let m=0;m<f.length;m++){const g=f[m];if(Ge.copy(g.boundingSphere),Ge.applyMatrix4(i),h.ray.intersectsSphere(Ge)!==!1)for(let x=g.indexStart,y=g.indexStart+g.indexCount-1;x<y;x+=a){const T=o.getX(x),v=o.getX(x+1);if(vi(this,c,h,T,v,n,t)&&(t[t.length-1].index=x,t.length-u>=Ft))return}}else{const m=Math.max(0,r.start),g=Math.min(o.count,r.start+r.count);for(let x=m,y=g-1;x<y;x+=a){const T=o.getX(x),v=o.getX(x+1);if(vi(this,c,h,T,v,n,t)&&(t[t.length-1].index=x,t.length-u>=Ft))return}}}else{const f=this.userData.batches;if(f&&f.length>0&&f[0].boundingSphere)for(let m=0;m<f.length;m++){const g=f[m];if(Ge.copy(g.boundingSphere),Ge.applyMatrix4(i),h.ray.intersectsSphere(Ge)!==!1){for(let x=g.positionStart,y=g.positionStart+g.positionCount-1;x<y;x+=a)if(vi(this,c,h,x,x+1,n,t)&&t.length-u>=Ft)return}}else{const m=Math.max(0,r.start),g=Math.min(c.count,r.start+r.count);for(let x=m,y=g-1;x<y;x+=a)if(vi(this,c,h,x,x+1,n,t)&&t.length-u>=Ft)return}}};function vi(h,t,e,i,s,r,n){if(ts.fromBufferAttribute(t,i),ts.applyMatrix4(h.matrixWorld),is.fromBufferAttribute(t,s),is.applyMatrix4(h.matrixWorld),e.ray.distanceSqToSegment(ts,is,Xs,Ys)>r)return!1;const o=e.ray.origin.distanceTo(Xs);return o<e.near||o>e.far?!1:(n.push({distance:o,point:Ys.clone(),index:i,object:h}),!0)}const Wa=d.Line;Se.Mesh.prototype.raycast=ks.acceleratedRaycast;const wi=new d.Sphere,Mi=new d.Vector3;d.Points.prototype.raycast=function(h,t){const e=this.geometry,i=this.matrixWorld,s=h.params.Points.threshold,r=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),wi.copy(e.boundingSphere),wi.applyMatrix4(i),wi.radius+=s,h.ray.intersectsSphere(wi)===!1)return;const n=s*s,a=e.index,o=e.attributes,l=o.position,c=t.length;if(a!==null){const u=Math.max(0,r.start),f=Math.min(a.count,r.start+r.count);for(let m=u,g=f;m<g;m++){const x=a.getX(m);if(Mi.fromBufferAttribute(l,x).applyMatrix4(i),Zs(Mi,x,n,h,t,this),t.length-c>=Ft)return}}else{const u=Math.max(0,r.start),f=Math.min(l.count,r.start+r.count);for(let m=u,g=f;m<g;m++)if(Mi.fromBufferAttribute(l,m).applyMatrix4(i),Zs(Mi,m,n,h,t,this),t.length-c>=Ft)return}};function Zs(h,t,e,i,s,r){const n=i.ray.distanceSqToPoint(h);if(n<e){const a=new d.Vector3;i.ray.closestPointToPoint(h,a);const o=i.ray.origin.distanceTo(a);if(o<i.near||o>i.far)return;s.push({distance:o,distanceToRay:Math.sqrt(n),point:a,index:t,face:null,object:r})}}const Ya=d.Points,Xa=`
1
+ "use strict";var sa=Object.defineProperty;var ra=(h,t,e)=>t in h?sa(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e;var p=(h,t,e)=>ra(h,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Se=require("three"),ks=require("three-mesh-bvh"),na=require("loglevel"),rn=require("three/examples/jsm/renderers/CSS2DRenderer.js"),aa=require("three/examples/jsm/exporters/DRACOExporter.js"),oa=require("three/examples/jsm/exporters/GLTFExporter.js"),la=require("three/examples/jsm/exporters/OBJExporter.js"),ha=require("three/examples/jsm/exporters/STLExporter.js"),ca=require("poly-extrude"),da=require("i18next"),xe=require("three/examples/jsm/utils/BufferGeometryUtils.js"),ua=require("three/src/extras/Earcut.js"),fa=require("2d-polygon-self-intersections"),pa=require("three/examples/jsm/modifiers/SimplifyModifier.js"),ma=require("three/examples/jsm/renderers/SVGRenderer.js"),ga=require("three/examples/jsm/loaders/RGBELoader.js"),ya=require("js-base64"),xa=require("concaveman"),ba=require("polybooljs"),wi=require("jsbi"),va=require("3d-tiles-renderer"),wa=require("protobufjs"),Ma=require("three/examples/jsm/loaders/DDSLoader.js"),Ds=require("pako"),Ta=require("three/examples/jsm/geometries/TextGeometry.js"),Ca=require("opentype.js"),Sa=require("three/examples/jsm/loaders/FontLoader.js"),Oa=require("three/examples/jsm/loaders/ColladaLoader.js"),Ea=require("three/examples/jsm/loaders/DRACOLoader.js"),_a=require("three/examples/jsm/loaders/FBXLoader.js"),Pa=require("three/examples/jsm/loaders/GLTFLoader.js"),Aa=require("three/examples/jsm/loaders/MTLLoader.js"),Ia=require("three/examples/jsm/loaders/OBJLoader.js"),ka=require("three/examples/jsm/loaders/PLYLoader.js"),Da=require("three/examples/jsm/loaders/STLLoader.js"),Zt=require("polygon-clipping"),Ba=require("three/examples/jsm/postprocessing/EffectComposer.js"),La=require("three/examples/jsm/postprocessing/RenderPass.js"),Ra=require("three/examples/jsm/postprocessing/ShaderPass.js"),Fa=require("three/examples/jsm/postprocessing/SAOPass.js"),za=require("three/examples/jsm/postprocessing/SSAOPass.js"),ja=require("three/examples/jsm/postprocessing/OutlinePass.js"),Va=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),Ua=require("three/examples/jsm/postprocessing/BloomPass.js"),Ha=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),Na=require("three/examples/jsm/shaders/FXAAShader.js"),Ga=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),qs=require("lodash");function yi(h){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(h){for(const e in h)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>h[e]})}}return t.default=h,Object.freeze(t)}const d=yi(Se),Ws=yi(na),qa=yi(ya),yt=yi(ba),Wa=yi(wa),zt=1,Ge=new d.Sphere,ts=new d.Vector3,is=new d.Vector3,Ys=new d.Vector3,Xs=new d.Vector3;d.Line.prototype.raycast=function(h,t){const e=this.geometry,i=this.matrixWorld,s=h.params.Line.threshold,r=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),Ge.copy(e.boundingSphere),Ge.applyMatrix4(i),Ge.radius+=s,h.ray.intersectsSphere(Ge)===!1)return;const n=s*s,a=this.isLineSegments?2:1,o=e.index,l=e.attributes,c=l.position,u=t.length;if(o!==null){const f=this.userData.batches;if(f&&f.length>0&&f[0].boundingSphere)for(let m=0;m<f.length;m++){const g=f[m];if(Ge.copy(g.boundingSphere),Ge.applyMatrix4(i),h.ray.intersectsSphere(Ge)!==!1)for(let x=g.indexStart,y=g.indexStart+g.indexCount-1;x<y;x+=a){const T=o.getX(x),v=o.getX(x+1);if(Mi(this,c,h,T,v,n,t)&&(t[t.length-1].index=x,t.length-u>=zt))return}}else{const m=Math.max(0,r.start),g=Math.min(o.count,r.start+r.count);for(let x=m,y=g-1;x<y;x+=a){const T=o.getX(x),v=o.getX(x+1);if(Mi(this,c,h,T,v,n,t)&&(t[t.length-1].index=x,t.length-u>=zt))return}}}else{const f=this.userData.batches;if(f&&f.length>0&&f[0].boundingSphere)for(let m=0;m<f.length;m++){const g=f[m];if(Ge.copy(g.boundingSphere),Ge.applyMatrix4(i),h.ray.intersectsSphere(Ge)!==!1){for(let x=g.positionStart,y=g.positionStart+g.positionCount-1;x<y;x+=a)if(Mi(this,c,h,x,x+1,n,t)&&t.length-u>=zt)return}}else{const m=Math.max(0,r.start),g=Math.min(c.count,r.start+r.count);for(let x=m,y=g-1;x<y;x+=a)if(Mi(this,c,h,x,x+1,n,t)&&t.length-u>=zt)return}}};function Mi(h,t,e,i,s,r,n){if(ts.fromBufferAttribute(t,i),ts.applyMatrix4(h.matrixWorld),is.fromBufferAttribute(t,s),is.applyMatrix4(h.matrixWorld),e.ray.distanceSqToSegment(ts,is,Xs,Ys)>r)return!1;const o=e.ray.origin.distanceTo(Xs);return o<e.near||o>e.far?!1:(n.push({distance:o,point:Ys.clone(),index:i,object:h}),!0)}const Ya=d.Line;Se.Mesh.prototype.raycast=ks.acceleratedRaycast;const Ti=new d.Sphere,Ci=new d.Vector3;d.Points.prototype.raycast=function(h,t){const e=this.geometry,i=this.matrixWorld,s=h.params.Points.threshold,r=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),Ti.copy(e.boundingSphere),Ti.applyMatrix4(i),Ti.radius+=s,h.ray.intersectsSphere(Ti)===!1)return;const n=s*s,a=e.index,o=e.attributes,l=o.position,c=t.length;if(a!==null){const u=Math.max(0,r.start),f=Math.min(a.count,r.start+r.count);for(let m=u,g=f;m<g;m++){const x=a.getX(m);if(Ci.fromBufferAttribute(l,x).applyMatrix4(i),Zs(Ci,x,n,h,t,this),t.length-c>=zt)return}}else{const u=Math.max(0,r.start),f=Math.min(l.count,r.start+r.count);for(let m=u,g=f;m<g;m++)if(Ci.fromBufferAttribute(l,m).applyMatrix4(i),Zs(Ci,m,n,h,t,this),t.length-c>=zt)return}};function Zs(h,t,e,i,s,r){const n=i.ray.distanceSqToPoint(h);if(n<e){const a=new d.Vector3;i.ray.closestPointToPoint(h,a);const o=i.ray.origin.distanceTo(a);if(o<i.near||o>i.far)return;s.push({distance:o,distanceToRay:Math.sqrt(n),point:a,index:t,face:null,object:r})}}const Xa=d.Points,Za=`
2
2
  // When an object is transparent, we'll change its alpha value,
3
3
  // but we should not assign a fixed value because it may already
4
4
  // has an alpha value that is lower than 1.
@@ -140,12 +140,12 @@
140
140
  }
141
141
 
142
142
  // TODO: isHighlighted isOverride isHovered
143
- `,Za=`
143
+ `,Ka=`
144
144
  attribute int tileObjectId;
145
145
  flat varying int vTileObjectId;
146
- `,Ka=`
147
- vTileObjectId = tileObjectId;
148
146
  `,$a=`
147
+ vTileObjectId = tileObjectId;
148
+ `,Ja=`
149
149
  #ifdef USE_BC_OUTLINE
150
150
  // Restore barycentric coordinates
151
151
  int barycentricX = int(barycentric) & 0x1;
@@ -153,14 +153,14 @@
153
153
  int barycentricZ = int(barycentric) & 0x4;
154
154
  vBarycentric = vec3(float(barycentricX), float(barycentricY), float(barycentricZ));
155
155
  #endif
156
- `,Ja=`
156
+ `,Qa=`
157
157
  #ifdef USE_BC_OUTLINE
158
158
  vec3 finWireframeColor = outlineColor;
159
159
  vec3 tempColor = gl_FragColor.rgb;
160
160
 
161
161
  gl_FragColor.rgb = mix(finWireframeColor, tempColor, edgeFactor3());
162
162
  #endif
163
- `,Qa=`
163
+ `,eo=`
164
164
  #ifdef USE_BC_OUTLINE
165
165
  varying vec3 vBarycentric;
166
166
  uniform vec3 outlineColor;
@@ -174,12 +174,12 @@
174
174
  return min(min(a3.x, a3.y), a3.z);
175
175
  }
176
176
  #endif
177
- `,eo=`
177
+ `,to=`
178
178
  #ifdef USE_BC_OUTLINE
179
179
  attribute float barycentric;
180
180
  varying vec3 vBarycentric;
181
181
  #endif
182
- `,to=`
182
+ `,io=`
183
183
  flat varying int vTileObjectId;
184
184
  uniform float uTextureWidth;
185
185
  uniform float uTextureHeight;
@@ -188,7 +188,7 @@
188
188
  // uniform int uHoverId;
189
189
  // uniform bool uIsIsolating;
190
190
  // uniform bool uTransparentOthersForIsolation;
191
- `,io=`
191
+ `,so=`
192
192
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
193
193
  // if (uHoverId == tileObjectId) {
194
194
  // gl_FragColor = uHoverColor;
@@ -225,7 +225,7 @@
225
225
  // gl_FragColor = vec4(0.5, 0.5, 0.5, 0.8);
226
226
  // }
227
227
  // }
228
- `,so=`
228
+ `,ro=`
229
229
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
230
230
  // State priority (high to low):
231
231
  // - Hidden
@@ -243,7 +243,7 @@
243
243
  gl_FragColor = HIGHLIGHT_COLOR;
244
244
  return;
245
245
  }
246
- `,ro=`
246
+ `,no=`
247
247
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
248
248
  // State priority (high to low):
249
249
  // - Hidden
@@ -261,7 +261,7 @@
261
261
  gl_FragColor = HIGHLIGHT_COLOR;
262
262
  return;
263
263
  }
264
- `,no=`
264
+ `,ao=`
265
265
  #define STANDARD
266
266
 
267
267
  varying vec3 vViewPosition;
@@ -321,7 +321,7 @@ void main() {
321
321
 
322
322
  #endif
323
323
  }
324
- `,ao=`
324
+ `,oo=`
325
325
  #define STANDARD
326
326
 
327
327
  #ifdef PHYSICAL
@@ -487,7 +487,7 @@ void main() {
487
487
 
488
488
  #include <outline_bc_fragment>
489
489
  }
490
- `,oo=`
490
+ `,lo=`
491
491
  #include <clipping_planes_pars_vertex>
492
492
 
493
493
  attribute int tileObjectId;
@@ -504,7 +504,7 @@ void main() {
504
504
  #endif
505
505
  gl_Position = projectionMatrix * modelViewMatrix * mvPosition;
506
506
  }
507
- `,lo=`
507
+ `,ho=`
508
508
  #include <clipping_planes_pars_fragment>
509
509
 
510
510
  flat varying int vTileObjectId;
@@ -531,9 +531,9 @@ void main() {
531
531
 
532
532
  gl_FragColor = tileObjectId2Color(vTileObjectId);
533
533
  }
534
- `,we=d.ShaderChunk;we.outline_bc_vertex=$a;we.outline_bc_fragment=Ja;we.outline_bc_pars_fragment=Qa;we.outline_bc_pars_vertex=eo;we.standard_ex_vertex=no;we.standard_ex_fragment=ao;we.common_ex=Xa;we.id_pars_vertex=Za;we.id_vertex=Ka;we.state_pars_fragment=to;we.state_fragment=io;we.state_transparent_fragment=so;we.state_highlight_fragment=ro;we.pick_ex_vertex=oo;we.pick_ex_fragment=lo;const ho=d.ShaderChunk;class co{constructor(t){p(this,"promise");p(this,"cancelReject");const e=new Promise((i,s)=>{this.cancelReject=s});this.promise=Promise.race([e,t])}cancel(){this.cancelReject&&this.cancelReject({type:"cancel"})}}const uo=Ws.default??Ws,S=uo;S.setLevel("warn");const rn=h=>{try{S.setLevel(h)}catch(t){S.setLevel("error"),S.error(t)}},jt=class jt{static isTouchScreenDevice(){return"ontouchstart"in window}static printDeviceInfo(){const t=navigator.userAgent,e=/(?:Android)/.test(t),i=/(?:Firefox)/.test(t),s=/(?:Chrome|CriOS)/.test(t),r=/(?:iPad|PlayBook)/.test(t)||e&&!/(?:Mobile)/.test(t)||i&&/(?:Tablet)/.test(t),n=/(?:iPhone)/.test(t)&&!r,a=!n&&!e,o=jt.isTouchScreenDevice();e&&S.debug("[DI] is android"),i&&S.debug("[DI] is fireFox"),s&&S.debug("[DI] is chrome"),r&&S.debug("[DI] is tablet"),n&&S.debug("[DI] is iPhone"),a&&S.debug("[DI] is PC"),o&&S.debug("[DI] is touch device")}static creatReactNativeCanvas(t){const e=t,i=e.drawingBufferWidth||e.width||0,s=e.drawingBufferHeight||e.height||0;return{style:{},width:i,height:s,clientWidth:Math.ceil(i/(window.devicePixelRatio||1)),clientHeight:Math.ceil(s/(window.devicePixelRatio||1)),addEventListener:()=>{},removeEventListener:()=>{}}}};p(jt,"isMobile",/mobile/i.test(navigator.userAgent)),p(jt,"isBrowser",typeof document<"u"),p(jt,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let be=jt;const Vt=class Vt{static isFullScreen(){return!!(document.fullscreenElement||document.mozFullScreenElement)}static fullScreen(t=document.documentElement){(t.requestFullscreen||t.mozRequestFullScreen||t.webkitRequestFullscreen||t.msRequestFullscreen).call(t)}static exitFullscreen(){(document.exitFullscreen||document.mozCancelFullscreen||document.webkitExitFullscreen||document.msExitFullscreen).call(document)}static joinStrings(...t){return t.join("")}static numberToString(t){let e=2;return Math.abs(t)<1e-6?e=2:Math.abs(t)<1e-5?e=7:Math.abs(t)<1e-4?e=6:Math.abs(t)<.001?e=5:Math.abs(t)<.01?e=4:Math.abs(t)<.1&&(e=3),t.toFixed(e)}static byteCountToString(t){let e=t;return t>1e9?(e=t/1e9,this.numberToString(e)+" G"):t>1e6?(e=t/1e6,this.numberToString(e)+" M"):t>1e3?(e=t/1e3,this.numberToString(e)+" K"):this.numberToString(e)}static hexToBase64(t){return btoa((t.match(/\w{2}/g)||[]).map(function(e){return String.fromCharCode(parseInt(e,16))}).join(""))}static vectorToString(t){return Array.isArray(t)?"("+this.numberToString(t[0])+", "+this.numberToString(t[1])+", "+this.numberToString(t[2])+")":t instanceof d.Vector3?"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+", "+this.numberToString(t.z)+")":"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+")"}static arrayToVector2(t){if(t){if(t instanceof d.Vector2)return t;if(Array.isArray(t)&&t.length>=2)return new d.Vector2(t[0],t[1])}else return t}static arrayToVector3(t){if(t){if(t instanceof d.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new d.Vector3(t[0],t[1],t.length>2?t[2]:0)}else return t}static arrayToEuler(t){if(t){if(t instanceof d.Euler)return t;if(Array.isArray(t)&&t.length>=3)return new d.Euler(t[0],t[1],t[2])}else return t}static arrayOrObjectToVector3(t){if(t){if(t instanceof d.Vector3)return t;if(t instanceof d.Vector2)return new d.Vector3(t.x,t.y,0);if(Array.isArray(t)&&t.length>=2)return new d.Vector3(t[0],t[1],t[2]||0)}else return t;const e=t;if(e.x!=null&&e.y!=null)return new d.Vector3(e.x,e.y,e.z||0)}static isVectorValid(t){let e=t&&!isNaN(t.x)&&!isNaN(t.y)&&isFinite(t.x)&&isFinite(t.y);return e&&t instanceof d.Vector3&&(e=!isNaN(t.z)&&isFinite(t.z)),e}static isBoxValid(t){return t&&!t.isEmpty()&&this.isVectorValid(t.min)&&this.isVectorValid(t.max)}static isMatrixValid(t){const e=t&&t.elements;if(!e||e.length<16)return!1;for(let i=0;i<16;++i){const s=e[i];if(Number.isNaN(s))return!1}return!0}static guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}static expandBoxByScale(t,e){const i=new d.Vector3;t.getCenter(i);const s=(t.max.x-t.min.x)*e,r=(t.max.y-t.min.y)*e,n=(t.max.z-t.min.z)*e,a=new d.Vector3(i.x-s/2,i.y-r/2,i.z-n/2),o=new d.Vector3(i.x+s/2,i.y+r/2,i.z+n/2);t.set(a,o)}static expandBoxByMinSize(t,e){const i=new d.Vector3;t.getCenter(i);const s=t.max.x-t.min.x,r=t.max.y-t.min.y,n=t.max.z-t.min.z;s<e&&(t.min.setX(i.x-e/2),t.max.setX(i.x+e/2)),r<e&&(t.min.setY(i.y-e/2),t.max.setY(i.y+e/2)),n<e&&(t.min.setZ(i.z-e/2),t.max.setZ(i.z+e/2))}static generateRandomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static convertDecimalToHex(t){return t==null?"#ffffff":"#"+t.toString(16).padStart(6,"0")}static canvasToImage(t){const e=t.toDataURL(),i=new Image;return i.src=e,new Promise(s=>{i.onload=function(){s(i)}})}static renderingContextToImage(t,e,i="image/png",s=.8){if(e){const r=Math.max(e.min.x,0),n=Math.max(e.min.y,0),a=Math.max(e.max.x-r,0),o=Math.max(e.max.y-n,0),l=t.getImageData(r,n,a,o),c=document.createElement("canvas");return c.width=a,c.height=o,c.getContext("2d").putImageData(l,0,0),c.toDataURL(i,s)}return t.canvas.toDataURL(i,s)}static printMemory(t){if(!be.isBrowser)return;const e=performance.memory;if(!e){S.warn("[Util] performance.memory is not available in this browser");return}const i=(e.jsHeapSizeLimit/(1024*1024)).toFixed(2),s=(e.totalJSHeapSize/(1024*1024)).toFixed(2),r=(e.usedJSHeapSize/(1024*1024)).toFixed(2);S.info("[Util] "+t+". jsHeapSizeLimit: "+i+"M , totalJSHeapSize: "+s+"M , usedJSHeapSize: "+r+"M ")}static printGpuInfo(t){if(!be.isBrowser)return;const e=t.getExtension("webgl_debug_renderer_info"),i=t.getParameter(e.UNMASKED_RENDERER_WEBGL);S.info("[Util] gpu:",i)}static getExtension(t){return t.substring(t.lastIndexOf(".")+1)}static isBinaryFile(t){return Vt.getExtension(t)==="bin"}static isGzip(t){return t.length<=3?!1:t[0]==31&&t[1]==139&&t[2]==8}static async sleep(t){let e;await new Promise(i=>{e=setTimeout(()=>{i()},t)}),clearTimeout(e)}static async twinkle(t,e=500){const i=this.twinklingObjectIds;i[t.id]||(i[t.id]=!0,t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,delete i[t.id])}static getUpdateProgressFunc(t){return e=>{t&&t(new ProgressEvent("",{loaded:e,total:100}))}}static getUpdateProgressFuncAsync(t){let e=Date.now();return async i=>{if(t){t(new ProgressEvent("",{loaded:i,total:100}));const s=500,r=Date.now();r-e>s&&(await Vt.sleep(0),e=r)}}}static getUpdateProgressFuncForLoop(t,e){const i=Math.round(Math.pow(t,.5));let s=Date.now();return async r=>{if(e&&(r%i===0||r===t-1)){e(new ProgressEvent("",{loaded:r+1,total:t}));const n=500,a=Date.now();(a-s>n||r===t-1)&&(await Vt.sleep(0),s=a)}}}static getUpdateSubProgressFunc(t,e,i){let s=!1;return r=>{let n=r.loaded*100/r.total;n=n*(e-t)/100+t,n>e&&(s||(S.warn("[Progress] Invalid ProgressEvent:",r),s=!0),n=e),i&&i(new ProgressEvent(r.type,{loaded:n,total:100}))}}};p(Vt,"twinklingObjectIds",{});let V=Vt;const fo=(h,t,e)=>{const{default:i,active:s}=t;e?(h.remove(i),h.add(s||i)):(s&&h.remove(s),h.add(i))};class Gt{static color2rgba(t){let e=[0,0,0,1],i;if(i=/^(\w+)\(([^)]*)\)/.exec(t)){let s;const r=i[1],n=i[2];switch(r){case"rgb":case"rgba":(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))&&(e=[Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,Number(s[4]||1)]),(s=/^\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))&&(e=[Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,Number(s[4]||1)]);break;case"hsl":case"hsla":(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))&&(e=[parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,Number(s[4]||1)]);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(r===3)e=[parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,1];else if(r===6){const n=parseInt(s,16);e=[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255,1]}else console.warn("THREE.Color: Invalid hex color "+t)}return e}static rgba2Color(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]),r=t[3]!=null?t[3]:1;return"rgba("+e+","+i+","+s+","+r+")"}static colorStr2Rgba(t){let e=t.replace("rgba(","");e=e.replace(")","");const i=e.split(","),s=[];return s.push(this.to1(parseInt(i[0]))),s.push(this.to1(parseInt(i[1]))),s.push(this.to1(parseInt(i[2]))),i[3]!=null&&s.push(parseFloat(i[3])),s}static rgb2Hex(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]);return(e<<16)+(i<<8)+s}static to255(t){let e=Math.max(t,0);return e=Math.min(t,1),e*255}static to1(t){let e=Math.max(t,0);return e=Math.min(t,255),e/255}}class pe{static getScreenCoordinateByEvent(t,e){const i=new d.Vector2,{left:s,top:r}=e.getBoundingClientRect();return i.x=t.clientX-s,i.y=t.clientY-r,i}static getScreenCoordinateByTouchEvent(t,e){const i=new d.Vector2,{left:s,top:r}=e.getBoundingClientRect();return i.x=t.touches[0].clientX-s,i.y=t.touches[0].clientY-r,i}static world2Screen(t,e,i){const{clientWidth:s,clientHeight:r}=i,n=t.clone(),a=new d.Vector2;return n.project(e),a.x=Math.round((.5+n.x/2)*s),a.y=Math.round((.5-n.y/2)*r),a}static worldBBox2Screen(t,e,i){const s=new d.Box2,r=t.min,n=t.max,a=(o,l,c)=>{const u=new d.Vector3(o,l,c),f=this.world2Screen(u,e,i);s.expandByPoint(f)};return a(r.x,r.y,r.z),a(r.x,r.y,n.z),a(r.x,n.y,r.z),a(r.x,n.y,n.z),a(n.x,r.y,r.z),a(n.x,r.y,n.z),a(n.x,n.y,r.z),a(n.x,n.y,n.z),s}static screen2World(t,e,i){const s=pe.screen2Ndc(t,e,i);return new d.Vector3(s.x,s.y,1).unproject(e)}static screen2Ndc(t,e,i){const{clientWidth:s,clientHeight:r}=i,n=new d.Vector2;return n.x=t.x/s*2-1,n.y=-(t.y/r)*2+1,n}static world2NormalizedScreen(t,e,i){const s=new d.Vector3,r=t instanceof d.Vector2?0:t.z;s.set(t.x,t.y,r);const n=pe.world2Screen(s,e,i);return n.x/=i.clientWidth,n.y/=i.clientHeight,n}}class po{static createCSS2DObject(t){const e=new sn.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 nn={"Precision from file":99},mo=(h,t)=>h.toFixed(t===nn["Precision from file"]?2:t),an="en",He=!1,on=10,Ce=11,ft=12,Bs=583902,go=[.031,.906,.867,.5],ji=[.3,.3,.3,.8],Ls=.5,Vi=.1,Ui=5e3,ln=45,yo="x-viewer-iconfont",xo="x-viewer-iconfont2",Rs=10,Ks=new d.Vector3,$s=new d.Vector3,Js=new d.Vector3,ni=new d.Vector3,it=new d.Vector3,Qs=new d.Triangle;function bo(h,t,e,i,s){const r=[],n={};let a,o,l,c;const f=Math.pow(10,4);let m,g,x=0;for(m=0,g=h.length;m<g;m+=3)a=h[m],o=h[m+1],l=h[m+2],c=Math.round(a*f)+"_"+Math.round(o*f)+"_"+Math.round(l*f),!n[c]&&(n[c]=x/3,e[x++]=a,e[x++]=o,e[x++]=l),r[m/3]=n[c];for(m=0,g=t.length;m<g;m++)s[m]=r[t[m]],i[s[m]]=t[m]}function vo(h,t,e,i){for(let s=0,r=h;s<r;s+=3){const n=t[s]*3,a=t[s+1]*3,o=t[s+2]*3;Ks.set(e[n],e[n+1],e[n+2]),$s.set(e[a],e[a+1],e[a+2]),Js.set(e[o],e[o+1],e[o+2]),d.Triangle.getNormal(Ks,$s,Js,ni),i.push({normal:ni.clone()})}}const ss=[new d.Vector3(1,0,0),new d.Vector3(0,1,0),new d.Vector3(0,0,1),new d.Vector3(1,1,0),new d.Vector3(0,1,1),new d.Vector3(1,0,1),new d.Vector3(1,1,1),new d.Vector3(0,0,0)];function wo(h,t){return it.addVectors(h,t),it.x===0||it.y===0||it.z===0}class hn{static buildEdge(t,e,i=Rs){const s=[],r=[],n=[];bo(t,e,s,r,n);const a=[];vo(e.length,n,s,a);const o=[],l=Math.cos(d.MathUtils.DEG2RAD*i),c={};let u=!1;for(let f=0,m=e.length;f<m;f+=3){const g=f/3;for(let x=0;x<3;x++){const y=n[f+x],T=n[f+(x+1)%3],v=Math.min(y,T),b=Math.max(y,T),E=v+","+b;c[E]===void 0?c[E]={index1:v,index2:b,face1:g,face2:void 0}:c[E].face2=g}}for(const f in c){const m=c[f];if(m.face2!==void 0){const y=a[m.face1].normal,T=a[m.face2].normal;if(y.dot(T)>l)continue}const g=r[m.index1],x=r[m.index2];(!u&&g>65535||x>65535)&&(u=!0),o.push(g),o.push(x)}return u?new Uint32Array(o):new Uint16Array(o)}static buildBarycentrics(t){const e=t.getAttribute("position");if(!e||e.count===0)return console.warn(" no positions in geometry!"),!1;const i=4,s=Math.pow(10,i),r=Math.cos(d.MathUtils.DEG2RAD*20),n=t.getIndex(),a=n?n.count:e.count,o=[0,0,0],l=new Array(3),c=ss.length,u=[];for(let M=0;M<e.count;M++)u.push({point:new d.Vector3(1,1,1),inited:!1,barycentricIndex:-1});const f={},m={},g={},x={};for(let M=0;M<a;M+=3){n?(o[0]=n.getX(M),o[1]=n.getX(M+1),o[2]=n.getX(M+2)):(o[0]=M,o[1]=M+1,o[2]=M+2);const{a:P,b:A,c:I}=Qs;if(P.fromBufferAttribute(e,o[0]),A.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),Qs.getNormal(ni),g[o[0]]?l[0]=g[o[0]]:(l[0]=Math.round(P.x*s)+","+Math.round(P.y*s)+","+Math.round(P.z*s),g[o[0]]=l[0]),g[o[1]]?l[1]=g[o[1]]:(l[1]=Math.round(A.x*s)+","+Math.round(A.y*s)+","+Math.round(A.z*s),g[o[1]]=l[1]),g[o[2]]?l[2]=g[o[2]]:(l[2]=Math.round(I.x*s)+","+Math.round(I.y*s)+","+Math.round(I.z*s),g[o[2]]=l[2]),l[0]===l[1]||l[1]===l[2]||l[2]===l[0]){S.warn(" skip degenerate triangles in geometry!");continue}const k={a:o[0],b:o[1],c:o[2]};!m[o[0]]&&(m[o[0]]=[]),m[o[0]].push(k),!m[o[1]]&&(m[o[1]]=[]),m[o[1]].push(k),!m[o[2]]&&(m[o[2]]=[]),m[o[2]].push(k);for(let B=0;B<3;B++){const L=(B+1)%3,q=l[B],me=l[L],ue=o[B],nt=o[L];!f[ue]&&(f[ue]=new Set),f[ue].add(nt),!f[nt]&&(f[nt]=new Set),f[nt].add(ue);const es=q+"_"+me,gt=me+"_"+q;if(gt in x&&x[gt]){if(x[gt].outer){S.warn("[Edge] edge: "+gt+" is already outer!");continue}ni.dot(x[gt].normal)<=r?x[gt].outer=!0:x[gt].find=!0}else es in x?S.warn("[Edge] "+es+" has existed in geometry!"):x[es]={startIndex:ue,endIndex:nt,normal:ni.clone(),outer:!1,find:!1}}}for(const M in x)x[M]&&!x[M].find&&!x[M].outer&&(x[M].outer=!0);const y=[],T=[];for(const M in m)T.push(m[M]);let v=new Set;for(const M of T[0])v.add(M.a),v.add(M.b),v.add(M.c);let b=0;for(T.splice(b,1);;){let M=!1;for(let P=0;P<T.length&&!M;P++)for(const A of T[P])if(v.has(A.a)||v.has(A.b)||v.has(A.c)){b=P,M=!0;break}if(M){for(const P of T[b])v.add(P.a),v.add(P.b),v.add(P.c);if(T.splice(b,1),b=0,T.length===0){y.push(v);break}}else if(!M)if(y.push(v),T.length>0){v=new Set;for(const P of T[b])v.add(P.a),v.add(P.b),v.add(P.c);T.splice(b,1),b=0}else break}const E=new Set;for(let M=0;M<y.length;M++)y[M].forEach(A=>{E.has(A)?S.warn("[Edge] "+A+" is already in positionIndexSet!"):E.add(A)});const O=(M,P)=>{let A=!1;const I=g[M];if(!I)return console.warn(M+" is not in positionIndexHash!"),A;const k=g[P];if(!k)return console.warn(P+" is not in positionIndexHash!"),A;const B=I+"_"+k;if(x[B])A=x[B].outer;else{const L=k+"_"+I;x[L]&&(A=x[L].outer)}return A},_=(M,P,A)=>{const I=[];return I.push(O(M,P)),I.push(O(P,A)),I.push(O(A,M)),I.filter(k=>k===!0).length>=2},C=(M,P)=>{if(!f[M])return S.warn("[Edge] "+M+" position isn't used!"),!0;const A=f[M];for(const k of A){const B=O(M,k),L=u[k];if(!L.inited)continue;const q=wo(P,L.point);if(B&&!q||!B&&q)return!1}const I=m[M];for(const k of I){const B=P;let L=u[k.b],q=u[k.c];if(k.b===M?L=u[k.a]:k.c===M&&(q=u[k.a]),_(k.a,k.b,k.c)&&(L.inited&&B.equals(L.point)||q.inited&&B.equals(q.point)))return!1;if(!(!L.inited||!q.inited)&&(it.addVectors(B,L.point),it.add(q.point),it.x+it.y+it.z<2))return!1}return!0};let w=!1;for(let M=0;M<y.length;M++){const P=Array.from(y[M]);w=!1;let A=0,I=0;for(;I>=0;){A=P[I];let k=u[A].inited?u[A].barycentricIndex+1:0;for(;k<c&&!C(A,ss[k]);k++);if(k<c)if(u[A].inited=!0,u[A].barycentricIndex=k,u[A].point.copy(ss[k]),I==P.length-1){w=!0,S.debug("[Edge]",u);break}else I++;else u[A].inited=!1,I--}if(!w){S.warn("[Edge] no result: "+P+"!");break}}if(w){const M=[];for(let A=0;A<u.length;A++){!u[A].inited&&S.warn("[Edge] "+A+" is not initialized !");let I=0;I|=u[A].point.x,I|=u[A].point.y<<1,I|=u[A].point.z<<2,M.push(I)}const P=new d.Uint8BufferAttribute(M,1,!1);t.setAttribute("barycentric",P)}else S.warn("[Edge] No suitable barycentric found!");return w}}class mt{constructor(){p(this,"map");this.map=new Map}addEventListener(t,e){let i=this.map.get(t);i||(i=new Set,this.map.set(t,i)),i.add(e)}dispatchEvent(t,e={}){const i=this.map.get(t);if(!i)return;[...i].forEach(r=>r(e))}hasEventListener(t){return!!this.map.get(t)}removeEventListener(t,e){if(!t){this.map.clear();return}if(!e){this.map.delete(t);return}const i=this.map.get(t);i&&i.delete(e)}}const X=class X{static exportToGltf(t,e){X.exportToGltfOrGlb(t,e,{binary:!1})}static exportToGlb(t,e){X.exportToGltfOrGlb(t,e,{binary:!0})}static exportToGltfOrGlb(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");const s=new aa.GLTFExporter;i=Object.assign({},{binary:!0,onlyVisible:!1,includeCustomExtensions:!1},i),s.parse(t,n=>{if(i.binary){e=X.addExtention(e,X.EXTENSION_GLB);const a=n;X.saveArrayBuffer(a,e)}else e=X.addExtention(e,X.EXTENSION_GLTF),X.saveJson(n,e)},n=>console.log(n),i)}static exportToObj(t,e){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_OBJ);const i=new oa.OBJExporter,s=i.parse(t);X.saveString(s,e)}static exportToDraco(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_DRACO);const s=new na.DRACOExporter;i=Object.assign({},{encodeSpeed:5},i);const n=s.parse(t,i);X.saveArrayBuffer(n,e)}static exportToStl(t,e,i=!1){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_STL);const s=new la.STLExporter;if(i){const r={binary:!0},n=s.parse(t,r);X.saveDataView(n,e)}else{const r=s.parse(t);X.saveString(r,e)}}static exportToThreeJsJson(t,e){const i=t.toJSON();e.toLowerCase().endsWith(X.EXTENSION_JSON)||(e+=X.EXTENSION_JSON),X.saveJson(i,e)}static save(t,e){let i=X.downloadLink;i||(i=document.createElement("a"),i.style.display="none",document.body.appendChild(i),X.downloadLink=i),i.href=URL.createObjectURL(t),i.download=e,i.click()}static saveArrayBuffer(t,e){X.save(new Blob([t],{type:"application/octet-stream"}),e)}static saveJson(t,e){X.saveJsonString(JSON.stringify(t),e)}static saveJsonString(t,e){X.save(new Blob([t],{type:"application/json"}),e)}static saveString(t,e){X.save(new Blob([t],{type:"text/plain"}),e)}static saveDataView(t,e){X.save(new Blob([t],{type:"application/octet-stream"}),e)}static addExtention(t,e){return t.toLowerCase().endsWith(e.toLowerCase())||(t+=e),t}};p(X,"EXTENSION_GLTF",".gltf"),p(X,"EXTENSION_GLB",".glb"),p(X,"EXTENSION_OBJ",".obj"),p(X,"EXTENSION_DRACO",".drc"),p(X,"EXTENSION_JSON",".json"),p(X,"EXTENSION_STL",".stl"),p(X,"downloadLink");let Ss=X;class Mo{constructor(){p(this,"prevTime");p(this,"beginTime");p(this,"frames");p(this,"fps");this.prevTime=(performance||Date).now(),this.beginTime=(performance||Date).now(),this.frames=0,this.fps=Number.NaN}begin(){this.beginTime=(performance||Date).now()}end(){this.frames++;const t=(performance||Date).now();return t>=this.prevTime+1e3&&(this.fps=Math.round(this.frames*1e3/(t-this.prevTime)),this.frames=0,this.prevTime=t),t}update(){this.beginTime=this.end()}}const rs=1e-15,er=new d.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),tr=new d.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class R{static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static floorNumber(t,e){return Math.floor(t*Math.pow(10,e))/Math.pow(10,e)}static areNumbersEqual(t,e,i=1e-7){return Math.abs(t-e)<i*Math.max(1,Math.abs(t),Math.abs(e))}static areVector2sEqual(t,e,i=1e-7){return R.areNumbersEqual(t.x,e.x,i)&&R.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return R.areNumbersEqual(t.x,e.x,i)&&R.areNumbersEqual(t.y,e.y,i)&&R.areNumbersEqual(t.z,e.z,i)}static areNumbersClose(t,e,i=1e-9,s=1e-12){return Math.abs(t-e)<=Math.max(i*Math.max(Math.abs(t),Math.abs(e)),s)}static areVector2sClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)}static areVectorsClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)&&this.areNumbersClose(t.z,e.z,i,s)}static getArcAngleSpanInRadian(t,e){const i=Math.PI*2;return R.areNumbersClose(t,e,rs)?0:(t%=i,R.areNumbersClose(t,e%i,rs)?i:(R.areNumbersClose(e,i,rs)&&(e%=i),e<t&&(e+=i),e-t))}static getIntegerPartLength(t){return t=Math.abs(t),t<1?0:Math.ceil(Math.log10(Math.abs(t)+1))}static getRelativeEps(t,e=1e-7){const i=R.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(R.getRelativeEps(t.x,e),R.getRelativeEps(t.y,e))}static getControlPointByTwoPoints(t,e){const i=new d.Vector2().subVectors(e,t),s=i.angle(),r=i.length(),n=d.MathUtils.degToRad(45),a=r/2/Math.cos(n);return new d.Vector2(t.x+a*Math.cos(n-s),t.y-a*Math.sin(n-s))}static convertPointFromUEToGltf(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(er.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(er),e}static convertPointFromUEToRevit(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(tr.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(tr),e}static getBox(t,e){const i=[Math.min(t.x,e.x),Math.min(t.y,e.y),Math.min(t.z,e.z)],s=[Math.max(t.x,e.x),Math.max(t.y,e.y),Math.max(t.z,e.z)];return[...i,...s]}static getCenter(t){const e=new d.Vector3(t.min.x,t.min.y,t.min.z),i=new d.Vector3(t.max.x,t.max.y,t.max.z),s=new d.Vector3().addVectors(e,i).multiplyScalar(.5);return{x:s.x,y:s.y,z:s.z}}static convertBoxFromGltfToUE(t){const e=R.convertPointFromGltfToUE(t.min),i=R.convertPointFromGltfToUE(t.max);return R.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=R.convertPointFromUEToGltf(t.min),i=R.convertPointFromUEToGltf(t.max);return R.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=R.convertPointFromRevitToUE(t.min),i=R.convertPointFromRevitToUE(t.max);return R.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=R.convertPointFromUEToRevit(t.min),i=R.convertPointFromUEToRevit(t.max);return R.getBox(e,i)}static clamp(t,e,i){return Math.max(e,Math.min(i,t))}static getLookAtMatrix(t,e,i){const s=new d.Matrix4,r=new d.Vector3(t.x,t.y,t.z),n=new d.Vector3(e.x,e.y,e.z),a=new d.Vector3(i.x,i.y,i.z);s.lookAt(r,n,a),s.transpose();const o=[];return s.toArray(o),o}static getLocationFromMatrix(t){const e=new d.Vector3;return e.setFromMatrixPosition(t),e}static toDegrees(t){return d.MathUtils.radToDeg(t)}static toRadians(t){return d.MathUtils.degToRad(t)}static signNotZero(t){return t<0?-1:1}static fromSnorm(t,e){return R.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=R.fromSnorm(t.x,i),e.y=R.fromSnorm(t.y,i),e.z=1-(Math.abs(e.x)+Math.abs(e.y)),e.z<0){const s=e.x;e.x=(1-Math.abs(e.y))*R.signNotZero(s),e.y=(1-Math.abs(s))*R.signNotZero(e.y)}}}const ns=1e7,ir=new d.Box2,sr=new d.Box2,rr=new d.Vector3,nr=new d.Vector3,ar=new d.Vector3,at=new d.Triangle;class U{static geometriesEqual(t,e){return t===e?!0:t.type===e.type&&t.name===e.name&&t.morphTargetsRelative===e.morphTargetsRelative&&this.equal(t.boundingBox,e.boundingBox)&&this.equal(t.boundingSphere,e.boundingSphere)&&this.attributesEqual(t.attributes,e.attributes)&&this.bufferAttributesEqual(t.index,e.index)}static equal(t,e){return t===e||!t&&!e?!0:t&&e?t.equals(e):!1}static attributesEqual(t,e){if(t===e)return!0;const i=Object.keys(t).sort(),s=Object.keys(e).sort();if(i.length!==s.length)return!1;for(let r=0;r<i.length;++r){if(i[r]!==s[r])return!1;const n=t[i[r]],a=e[s[r]];if(!this.bufferAttributesEqual(n,a))return!1}return!0}static bufferAttributesEqual(t,e){if(t===e)return!0;if(!t||!e||!(t.name===e.name&&t.itemSize===e.itemSize&&t.count===e.count&&t.normalized===e.normalized))return!1;if(t.array&&e.array){if(t.array.length!==e.array.length)return!1;for(let n=0;n<t.array.length;++n)if(t.array[n]!==e.array[n])return!1}else if(t.array||e.array)return!1;const s=t.data,r=e.data;if(s&&r){if(s.length!==r.length)return!1;for(let n=0;n<s.length;++n)if(s[n]!==r[n])return!1}else if(s||r)return!1;return!0}static tryConvertInterleavedBufferAttributes(t){!t||!t.attributes||Object.keys(t.attributes).forEach(e=>{const i=t.attributes[e];if(i instanceof d.InterleavedBufferAttribute){const s=i.clone();t.attributes[e]=s}})}static isPointInPolygon(t,e,i=!1){const s=t.x,r=t.y;let n=!1;const a=e.length;for(let o=0,l=a-1;o<a;l=o++){const c=e[o].x,u=e[o].y,f=e[l].x,m=e[l].y;let g=u>r!=m>r;i&&(g=u>=r!=m>=r),g&&s<(f-c)*(r-u)/(m-u)+c&&(n=!n)}return n}static caculateGeometryCenter(t){if(!t.hasAttribute("position"))return null;const e=t.getAttribute("position");if(e.count===0)return null;const i=new d.Vector3,s=e.itemSize,r=e.array,n=[0,0,0];for(let a=0;a<e.count;a++)for(let o=0;o<s;o++)n[o]+=r[a*s+o];for(let a=0;a<s;a++)i.setComponent(a,n[a]/e.count);return i}static isConvex(t){const e=t.length;let i=0,s=0;const r=new d.Vector2,n=new d.Vector2;for(let a=0;a<e;++a){const o=t[a],l=t[(a+1)%e],c=t[(a+2)%e];if(r.subVectors(l,o),n.subVectors(c,l),s=r.cross(n),s!=0){if(s>0&&i<0||s<0&&i>0)return!1;i=s}}return!0}static areLineSegmentsIntersecting(t,e){const{start:i,end:s}=t,{start:r,end:n}=e,a=r.clone().sub(i),o=s.clone().sub(i),l=n.clone().sub(i),c=a.cross(o).dot(l.cross(o)),u=i.clone().sub(r),f=n.clone().sub(r),m=s.clone().sub(r),g=u.cross(f).dot(m.cross(f));return c<0&&g<0}static getLineSegmentsIntersectingPoint(t,e){const{start:i,end:s}=t,{start:r,end:n}=e,a=rr.subVectors(s,i).normalize(),o=nr.subVectors(n,r).normalize();if(a.dot(o)===1)return null;const l=ar.subVectors(r,i),c=a.clone().cross(o),u=l.clone().cross(o),f=l.clone().dot(c);if(f>=1e-5||f<=-1e-5)return null;const m=c.lengthSq();if(R.areNumbersEqual(0,m))return;const g=u.clone().dot(c)/m,x=i.clone().add(a.multiplyScalar(g));return x.equals(i)||x.equals(s)?null:x}static isPointOnLineSegment(t,e,i=.001){const{start:s,end:r}=e,n=rr.subVectors(s,r).length(),a=nr.subVectors(t,s).length(),o=ar.subVectors(t,r).length();return Math.abs(n-(a+o))<=i}static isPointOnLineSegments(t,e,i=.001){let s=!1;for(let r=0;r<e.length-1;r+=2){const n=e[r],a=e[r+1];if(s=this.isPointOnLineSegment(t,{start:n,end:a},i),s)break}return s}static checkAndRebasePositionsOnRTC(t,e){if(t.length===0)return!1;const i=t[0]instanceof d.Vector3;t.forEach(r=>{i?e.add(r):(e.x+=r.x,e.y+=r.y)}),e.divideScalar(t.length);let s=!1;if(U.shouldRebasePositionOnRTC(e)){s=!0;for(let r=0;r<t.length;r++){const n=t[r].x-e.x,a=t[r].y-e.y;i?t[r]=new d.Vector3(n,a,t[r].z-e.z):t[r]=new d.Vector2(n,a)}}else e.setScalar(0);return s}static shouldRebasePositionOnRTC(t){return Math.abs(t.x)>ns||Math.abs(t.y)>ns||t instanceof d.Vector3&&Math.abs(t.z)>ns}static calculateSurfaceArea(t){let e=0;const i=t.getAttribute("position"),s=t.index;if(s)for(let r=0;r<s.count;r+=3)at.a.fromBufferAttribute(i,s.getX(r)),at.b.fromBufferAttribute(i,s.getX(r+1)),at.c.fromBufferAttribute(i,s.getX(r+2)),e+=at.getArea();else for(let r=0;r<i.count;r+=3)at.a.fromBufferAttribute(i,r),at.b.fromBufferAttribute(i,r+1),at.c.fromBufferAttribute(i,r+2),e+=at.getArea();return e}static convertLineStripToLine(t,e=!1){const i=t.getIndex();if(!i)return;const s=i.array.constructor,r=i.count;let n=r;r>2&&(n=e?r*2:r*2-2);const a=new s(n);let o=0;for(let l=0;l<r;l++){const c=i.getX(l);a[o++]=c,l>0&&l<r-1&&(a[o++]=c)}e&&(a[o++]=i.getX(r-1),a[o++]=i.getX(0)),t.setIndex(a)}static convertGeometryWithIndexedToNonIndexed(t){if(!t.index)return t;const e=new d.BufferGeometry,i=t.index;for(const s in t.attributes)e.setAttribute(s,U.createGeometryAttributeByIndex(t.attributes[s],i));return e}static createGeometryAttributeByIndex(t,e){const i=e.count,s=t.itemSize,r=t.array.constructor,n=new r(i*s);for(let a=0;a<i;a++){const o=e.getX(a),l=o*s;for(let c=0;c<s;c++)n[a*s+c]=t.array[l+c]}return new d.BufferAttribute(n,s,t.normalized)}static getLineEndPointsByIndex(t,e){const i=l=>{const c=t.geometry.attributes.position,u=c.array;return t.localToWorld(new d.Vector3(u[3*l],u[3*l+1],u[3*l+2]))};t.updateWorldMatrix(!0,!1);const s=t.geometry.getIndex()?.array||[],r=s[e]??e,n=s[e+1]??e+1,a=i(r),o=i(n);return[a,o]}static arePolygonsIntersect(t,e){if(t.length===0||e.length===0||(ir.setFromPoints(t),sr.setFromPoints(e),!ir.intersectsBox(sr)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&R.areVector2sEqual(t[i+1],t[i])&&++i,++i}return!1}static getLineLineIntersectionPoint(t,e,i,s,r=.001){const n=e.clone().sub(t).normalize(),a=s.clone().sub(i).normalize();if(Math.abs(n.dot(a))>1-r)return;const o=e.y-t.y,l=t.x-e.x,c=o*t.x+l*t.y,u=s.y-i.y,f=i.x-s.x,m=u*i.x+f*i.y,g=o*f-u*l;if(Math.abs(g)<r)return;const x=(f*c-l*m)/g,y=(o*m-u*c)/g;return new d.Vector2(x,y)}static getOffsetPoint(t,e,i){const s=e.x-t.x,r=e.y-t.y,n=Math.sqrt(s*s+r*r),a=i/n;return new d.Vector2(-a*r,a*s)}static convertSimpleWidthLineToMeshGeometry(t,e){let i,s=!1,r=!1,n=[],a=[],o,l,c=new d.Vector2,u=new d.Vector2,f=new d.Vector2,m=new d.Vector2;const g=[],x=e/2;for(let b=0,E=t.length-1;b<E;b++)s=!b,r=b===t.length-2,i=this.getOffsetPoint(t[b],t[b+1],x),c=new d.Vector2(t[b].x+i.x,t[b].y+i.y),u=new d.Vector2(t[b+1].x+i.x,t[b+1].y+i.y),f=new d.Vector2(t[b].x-i.x,t[b].y-i.y),m=new d.Vector2(t[b+1].x-i.x,t[b+1].y-i.y),s||(o=this.getLineLineIntersectionPoint(n[0],n[1],c,u),o!==void 0?g.unshift(o):g.unshift(c),l=this.getLineLineIntersectionPoint(a[0],a[1],f,m),l!==void 0?g.push(l):g.push(f)),s&&(g.unshift(c),g.push(f)),r&&(g.unshift(u),g.push(m)),r||(n=[c,u],a=[f,m]);if(g.length<3)return;const y=d.ShapeUtils.triangulateShape(g,[]),T=[];for(let b=0;b<y.length;b++)T.push(...y[b]);const v=new d.BufferGeometry().setFromPoints(g);return v.setIndex(T),v}static convertWidthLineToMeshGeometry(t,e){if(t.length<2)return;const i=[];t.forEach(s=>{i.push([s.x,s.y])});try{const{indices:s,position:r}=ha.extrudePolylines([i],{lineWidth:e,depth:1}),n=new d.BufferGeometry;return n.setAttribute("position",new d.Float32BufferAttribute(r,3)),n.setIndex(Array.from(s)),n}catch{return}}static releaseGeometryManually(t){t.index=null,t.attributes={}}static getAdjacentNonRepeatPoints(t,e=1e-7){const i=[],s=t.length;for(let r=0;r<s-1;r++)R.areVector3sEqual(t[r],t[r+1],e)||i.push(t[r]);return i.push(t[s-1]),i}static mergeBBoxes(t){const e=[...t];if(e.length<2)return e;const i=[],s=[];for(let r=0;r<e.length;r++){const n=e[r];if(!s.includes(r)){for(let a=0;a<e.length;a++){const o=e[a];n.equals(o)||n.intersectsBox(o)&&(n.union(o),s.push(a))}i.push(n)}}return i}}const To={ProgressBar:{Loading:"Loading",Comparing:"Comparing"},Tooltip:{boxSelect:"Box select an area to confirm the screenshot range",pickMarkup:"Click on a markup to confirm the screenshot range"}},Os={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"}},Re=ca.createInstance(),Co="cn";Re.init({lng:Co,debug:!1,resources:{en:{translation:Os},cn:{translation:Os}}});class de{static materialEquals(t,e){if(t===e)return!0;if(t.type!==e.type)return!1;if(t instanceof d.Material&&e instanceof d.Material){const i=t,s=e;return i.alphaTest===s.alphaTest&&i.opacity===s.opacity&&i.side===s.side&&i.visible===s.visible&&i.name===s.name&&i.transparent===s.transparent&&this.colorEquals(i.color,s.color)&&this.colorEquals(i.emissive,s.emissive)&&i.roughness===s.roughness&&i.metalness===s.metalness&&i.alphaMap===s.alphaMap&&i.uniforms===s.uniforms&&i.defines===s.defines&&i.vertexShader===s.vertexShader&&i.fragmentShader===s.fragmentShader&&i.clippingPlanes===s.clippingPlanes&&i.map===s.map&&i.clipIntersection===s.clipIntersection}return!1}static materialsEquals(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)&&t.length===e.length){for(let i=0;i<t.length;++i)if(!this.materialEquals(t[i],e[i]))return!1;return!0}else if(t instanceof d.Material&&e instanceof d.Material)return this.materialEquals(t,e);return!1}static colorEquals(t,e){return t===e?!0:t instanceof d.Color&&e instanceof d.Color?t.equals(e):!1}static clonedHighlightMaterials(t,e={}){if(!t||!t.material)return;const i=t.material;if(Array.isArray(i)&&i.length>0){const s=[];return i.forEach(r=>{s.push(this.clonedHighlightMaterial(r,e))}),s}else{if(i instanceof d.Material)return this.clonedHighlightMaterial(i,e);console.warn("[MaterialUtils] Invalid material: "+i)}}static clonedHighlightMaterial(t,e={}){const{depthTest:i=void 0,highlightColor:s=new d.Color(Bs),opacity:r=.7}=e,n=t.clone();return this.setMaterialColor(n,s),n.opacity=r,n.transparent=!0,i!==void 0&&(n.depthTest=i,n.side=d.DoubleSide),n}static cloneMaterial(t){if(!t)return t;if(Array.isArray(t)){const e=[];return t.forEach(i=>{e.push(i.clone())}),e}return t.clone()}static getMaterialColor(t){let e=new d.Color(16777215);return t instanceof d.PointsMaterial||t instanceof d.LineBasicMaterial||t instanceof d.MeshBasicMaterial?e=t.color:t instanceof d.ShaderMaterial&&t.uniforms.u_color&&(e=t.uniforms.u_color.value),e}static setMaterialColor(t,e){const i=t;i.color?.set(e),i.emissive?.set(e),i.uniforms?.u_color&&i.uniforms.u_color.value.set(e)}static setMaterialOpacity(t,e){const i=t;i.transparent=!0,i.opacity=e,i.uniforms?.opacity&&(i.uniforms.opacity.value=e)}static cloneMaterials(t){const e=new Map,i=s=>{if(Array.isArray(s)){const r=[];return s.forEach(n=>{let a=e.get(n);a||(a=n.clone(),e.set(n,a)),r.push(a)}),r}if(s){let r=e.get(s);return r||(r=s.clone(),e.set(s,r)),r}return s};t.traverse(s=>{const r=s;r.material&&(r.material=i(r.material))})}}const So=new d.Vector3(0,1,0),ke=class ke{static resetObjectStyle(t){this.revertWireframeMode(t),this.revertObjectOpacity(t,[]),this.revertAppliedMaterialToObject(t),this.revertVisibleForFloors(t)}static resetObjectStyleById(t,e){const i=this.getObjectById(t,e);this.resetObjectStyle(i)}static setObjectOpacity(t,e=.3,i,s){const r=[],n=o=>{r.find(l=>l.id===o.id)||(r.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side}),o.opacity*=e,o.transparent=!0,o.side=d.DoubleSide)},a=o=>{const l=r.find(c=>c.id===o.id);if(!l){const c=o.clone();return r.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side,material:o,clonedMaterial:c}),c.opacity*=e,c.transparent=!0,c}return l.clonedMaterial};return t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof d.Mesh){const l=o;if(i||s){if(Array.isArray(l.material)){const c=[];l.material.forEach(u=>{const f=a(u);f&&c.push(f)}),l.material=c}else if(l.material){const c=a(l.material);c&&(l.material=c)}}else if(Array.isArray(l.material))l.material.forEach(c=>{n(c)});else if(l.material){const c=l.material;n(c)}}}),r}static revertObjectOpacity(t,e,i,s){const r=new Set,n=o=>{if(!o||o.id==null||r.has(o.id))return;r.add(o.id);const l=e.find(c=>c.id===o.id);l&&(o.opacity=l.opacity,o.transparent=l.transparent,o.side=l.side,o.opacity===0&&S.warn("[ObjectUtils] Material '"+o.name+"'s opacity is 0, you may not be able to see your objects!"))},a=o=>{const l=e.find(c=>c.clonedMaterial&&c.clonedMaterial.id===o.id);if(l)return l.material};t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof d.Mesh){if(Array.isArray(o.material)){const l=[];o.material.forEach(c=>{const u=a(c);u?l.push(u):n(c)}),o.material=l}else if(o.material){const l=a(o.material);l?o.material=l:n(o.material)}}})}static setObjectOpacityById(t,e,i=.3,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);return ke.setObjectOpacity(n,i,s,r)}static revertObjectOpacityById(t,e,i,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);ke.revertObjectOpacity(n,i,s,r)}static applyMaterialToObject(t,e,i,s){t.traverse(r=>{s&&s.indexOf(r.id)!==-1||i&&i.indexOf(r.id)===-1||r instanceof d.Mesh&&(r.userData.originalMaterial||(r.userData.originalMaterial=r.material),r.material=e)})}static revertAppliedMaterialToObject(t,e,i){t.traverse(s=>{i&&i.indexOf(s.id)!==-1||e&&e.indexOf(s.id)===-1||s.userData.originalMaterial&&(s.material=s.userData.originalMaterial,s.userData.originalMaterial=void 0)})}static applyMaterialToObjectById(t,e,i,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);this.applyMaterialToObject(n,i,s,r)}static revertAppliedMaterialToObjectById(t,e,i,s){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);this.revertAppliedMaterialToObject(r,i,s)}static applyOpacityMaterialToObject(t,e,i){const s=new d.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});this.applyMaterialToObject(t,s,e,i)}static setDoubleSidedMaterialToObject(t){const e=i=>{i.side!==d.DoubleSide&&(i.userData.originalSide==null&&(i.userData.originalSide=i.side),i.side=d.DoubleSide)};t.traverse(i=>{i instanceof d.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof d.Material&&e(i.material))})}static revertDoubleSidedMaterialToObject(t){const e=i=>{i.userData.originalSide!=null&&(i.side=i.userData.originalSide,i.userData.originalSide=void 0)};t.traverse(i=>{i instanceof d.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof d.Material&&e(i.material))})}static setWireframeMode(t){const e=new d.MeshBasicMaterial({color:16732160,wireframe:!0,transparent:!0,opacity:.8});t.traverseVisible(i=>{if(i instanceof d.Mesh){const s=i;s.userData.materialForWireframe=s.material,s.material=e}})}static setWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);ke.setWireframeMode(i)}static revertWireframeMode(t){t.traverseVisible(e=>{e instanceof d.Mesh&&e.userData.materialForWireframe&&(e.material=e.userData.materialForWireframe,e.userData.materialForWireframe=void 0)})}static revertWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);ke.revertWireframeMode(i)}static findInner(t,e,i=[],s=!1){const r=e.toLowerCase(),n=[],a=c=>c.toLowerCase().indexOf(r)!==-1,o=c=>c.toString().indexOf(r)!==-1,l=c=>{if(c.name&&c.name.toLowerCase().indexOf(r)!==-1)return!0;if(c.gltfExtensions){const u=c.gltfExtensions,f=u.objectId&&u.objectId.Value||u.elementId&&u.elementId.Value;if(f&&f.toLowerCase().indexOf(r)!==-1)return!0}return!1};if(i.length>0)for(let c=0;c<i.length;++c){const u=i[c],f=t.getObjectById(u);if(f&&f.traverse(m=>{(a(m.name)||o(m.id)||l(m.userData))&&n.push(m)}),s&&n.length>0)return[n[0]]}else if(t.traverse(c=>{(a(c.name)||o(c.id)||l(c.userData))&&n.push(c)}),s&&n.length>0)return[n[0]];return n}static find(t,e,i=[],s=!1){return this.findInner(t,e,i,s)}static findFirst(t,e,i=[],s=!1){const r=this.findInner(t,e,i,s);if(r.length>0)return r[0]}static getFloorsFromString(t){const e=[],s=new RegExp(/(?:-?(?:\d+(?:\.5)?)F)(?=\W|$)/,"g").exec(t);return s&&s.length>0&&s.forEach(r=>{if(r){const n=r.replace("F",""),a=Number(n);a?e.push(a):console.log("[OU] invalid floor: "+r)}}),e}static matchFloor(t,e){return this.getFloorsFromString(t).findIndex(r=>r===e)!==-1}static matchFloors(t,e){return this.getFloorsFromString(t).findIndex(r=>e.findIndex(a=>a===r)!==-1)!==-1}static distinctFloors(t,e){const i=[],s=r=>{this.getFloorsFromString(r).forEach(a=>{i[a]=!0})};return e.forEach(r=>{const n=t.getObjectById(r);n&&n.traverse(a=>{if(s(a.name),a.userData.gltfExtensions){const o=a.userData.gltfExtensions;o.level&&o.level.Value&&s(o.level.Value)}})}),Object.keys(i).sort()}static traverseObjectByFloors(t,e,i,s,r){const n=t.getObjectById(e);if(!n)return[];n.traverse(a=>{let o=this.matchFloors(a.name,i);if(!o&&a.userData&&a.userData.gltfExtensions){const l=a.userData.gltfExtensions;l.level&&l.level.Value&&(o=this.matchFloors(l.level.Value,i))}o&&s&&s(a),!o&&r&&r(a)})}static setVisibleForFloors(t,e,i,s=!0){this.traverseObjectByFloors(t,e,i,r=>{let n=r;for(;n;)n.visible=!0,n=n.parent||void 0},r=>{s&&(r.visible=!1)})}static revertVisibleForFloors(t){t.traverse(e=>{e.visible=!0})}static revertVisibleForFloorsById(t,e){const i=this.getObjectById(t,e);this.revertVisibleForFloors(i)}static getObjectById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);return i}static async createOutlines(t,e={onlyVisible:!0,meshOnly:!0},i){if(!t)return[];if(t.children.length===0&&(e.onlyVisible&&!t.visible||e.meshOnly&&!(t instanceof d.Mesh)))return[];const s=[],r=t,n=r.children.length,a=Math.round(Math.pow(n,.5)),o=V.getUpdateProgressFuncAsync(i);for(let l=n-1;l>=0;--l){const c=n-l-1;let u;if(i&&(c%a===0||c===0||c===n-1)){const g=c*90/n,x=(c+1)*90/n;u=V.getUpdateSubProgressFunc(g,x,i)}const f=r.children[l],m=await this.createOutlines(f,e,u);s.push(...m)}if(!r.geometry)return await o(100),s;if(r instanceof d.Mesh&&!this.hasOutline(r,!1)){await o(50);const l=this.createOutline(r.geometry);r.add(l),l.updateWorldMatrix(!0,!1),s.push(l)}return await o(100),s}static removeOutlines(t){if(!(!t||!Array.isArray(t.children)))for(let e=t.children.length-1;e>=0;--e){const i=t.children[e];i.children.length>0&&this.removeOutlines(i),i.userData.isOutline&&t.remove(i)}}static hasOutline(t,e=!0){let i=!1;for(let s=0;s<t.children.length;++s){const r=t.children[s];if(r.userData.isOutline){i=!0;break}if(e&&r.children.length>0&&(i=this.hasOutline(r),i))break}return i}static setOutlinesVisibility(t,e){t.traverse(i=>{i.userData.isOutline&&(i.visible=e)})}static createOutline(t,e=this.OUTLINE_MATERIAL,i){const s=new d.EdgesGeometry(t,Rs),r=new d.LineSegments(s,e);return r.layers.enableAll(),ke.disableLayerChannels(r,[ft,Ce]),r.userData.isOutline=!0,r.matrixAutoUpdate=He,i&&r.applyMatrix4(i),r}static cloneObject(t,e=!0){const i=t.clone();return e&&i.traverse(s=>{if(s instanceof d.Mesh||s instanceof d.Line){const r=s;r.material=de.cloneMaterial(r.material)}}),i}static createBox(t,e,i,s=this.BOX_FACE_MATERIAL,r=!0){const n=[],a=(c,u,f)=>{n.push(new d.Vector3(c,u,f))};a(0,0,0),a(t,0,0),a(t,e,0),a(0,e,0),a(0,0,i),a(t,0,i),a(t,e,i),a(0,e,i);const o=new d.BufferGeometry;o.setFromPoints(n);const l=[0,3,2,0,2,1,4,6,7,4,5,6,0,7,3,0,4,7,3,6,2,3,7,6,1,6,5,1,2,6];return r&&l.push(0,5,4,0,1,5),o.setIndex(l),o.computeVertexNormals(),new d.Mesh(o,s)}static rebaseObjectOnRTC(t){const e=t;if(!(e.isMesh||e.isLine||e.isPoints)||!e.geometry||!(e.geometry instanceof d.BufferGeometry))return t;const i=e.geometry;if(!i.hasAttribute("position"))return t;const s=i.getAttribute("position");if(s.count===0)return t;const r=s.itemSize,n=s.array,a=[];for(let c=0;c<r;c++)a.push(n[c]);for(let c=0;c<s.count;c++)for(let u=0;u<r;u++)n[c*r+u]-=a[u];t.updateMatrix();const o=t.matrix.clone();t.matrix.makeTranslation(a[0],a[1],a.length>2?a[2]:0);const l=t.matrixAutoUpdate;return t.matrixAutoUpdate=!1,t.applyMatrix4(o),t.matrixAutoUpdate=l,t}static isEmptyObject(t){if(t.children.length===0){const i=t.geometry;if(!i||!i.hasAttribute("position")||i.getAttribute("position").count===0)return!0}return!1}static removeEmptyObjects(t){for(let e=0;e<t.children.length;)this.removeEmptyObjects(t.children[e])||++e;return this.isEmptyObject(t)?(t.removeFromParent(),!0):!1}static removeEmptyObjectsFromRemovingObjects(t,e){t.length!==0&&(t.forEach(i=>{i.removeFromParent()}),this.removeEmptyObjects(e))}static setSharedVariablesOfObject(t){t.uuid="",t.up=So;const e=t;e.material&&(Array.isArray(e.material)?e.material.forEach(i=>{i.uuid&&(i.uuid="")}):e.material.uuid&&(e.material.uuid=""))}static isLeafObject(t){return!(t instanceof d.Mesh)&&!(t instanceof d.Line)&&!(t instanceof d.Points)?!1:!!t.geometry}static enableLayerChannels(t,e,i=!0){for(let s=0,r=e.length;s<r;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.enableLayerChannels(s[r],e,!0)}}static disableLayerChannels(t,e,i=!0){for(let s=0,r=e.length;s<r;s++)t.layers.disable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.disableLayerChannels(s[r],e,!0)}}static setLayerChannels(t,e,i=!0){t.layers.disableAll();for(let s=0,r=e.length;s<r;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.setLayerChannels(s[r],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(on)}static isObjectSnapable(t){return t.layers.isEnabled(Ce)}static isObjectSelectable(t){return t.layers.isEnabled(ft)}};p(ke,"OUTLINE_MATERIAL",new d.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),p(ke,"BOX_FACE_MATERIAL",new d.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:d.FrontSide}));let $=ke;const Ti=new d.Matrix4,Oo=new d.Matrix4,ci=class ci{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},r=[];for(let c=0;c<i;++c){const u=t.children[c];if(u.children.length>0){this.mergeInner(u,e);continue}if(u.isInstancedMesh||!u.geometry||!(u.geometry instanceof d.BufferGeometry))continue;let f=!1;const m=Object.values(s);for(let g=m.length-1;g>=0;--g){const x=m[g].indexes[0];if(f=this.tryHandleMergeableObjects(t,c,x,s,r),f)break}for(let g=r.length-1;!f&&g>=0;--g){const x=r[g];if(f=this.tryHandleMergeableObjects(t,c,x,s,r),f)break}!f&&r.push(c)}if(Object.keys(s).length<=0)return;const n=[],a=[],o=[],l=[];Object.values(s).forEach(c=>{const u=c.indexes,f=t.children[u[0]];let m=[],g=0,x=0,y=0;const T=[];if(u.forEach(b=>{const E=t.children[b],O=E.geometry.clone();if(O.applyMatrix4(E.matrix),U.tryConvertInterleavedBufferAttributes(O),O.userData.isLineSegments=E.isLineSegments===!0,m.push(O),e){const _=E.name,C=O.attributes?.position?.count,w=O.index?.count||0,M={batchId:g,name:_,positionStart:x,positionCount:C,indexStart:y,indexCount:w};Object.keys(E.userData).length!==0&&(M.userData=E.userData),T.push(M),x+=C,y+=w,g++}}),m.length===0)return;let v;if(f.isMesh){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new d.Mesh(b,f.material),n.push(v)}else if(f.isLine){const b=this.mergeLineGeometries(m,e,f.material instanceof d.LineDashedMaterial||f.material instanceof d.ShaderMaterial,T);if(!b)return;v=new d.LineSegments(b,f.material),a.push(v)}else if(f.isPoints){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new d.Points(b,f.material),o.push(v)}v&&(e?v.userData.batches=T:(v.userData=f.userData,v.userData.batches=void 0),v.userData.layerName=f.userData.layerName,v.name="[Merged] "+f.name,v.matrixAutoUpdate=He,v.renderOrder=f.renderOrder,v.layers.mask=f.layers.mask,v.visible=f.visible,l.push(...u)),m.forEach(b=>{b.dispose(),U.releaseGeometryManually(b)}),m=[]}),l.sort((c,u)=>u-c),l.forEach(c=>{const u=t.children[c];t.remove(u)}),[...n,...a,...o].forEach(c=>{t.add(c)}),t.updateMatrix(),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=n.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,r){let n=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return n;const l=a?t[e]:t.children[e],c=a?t[i]:t.children[i];return this.areObjectsMergeable(l,c)&&this.areGeometriesMergeable(l.geometry,c.geometry)&&de.materialsEquals(l.material,c.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(r,i)),s[i].indexes.push(e),n=!0),n}static deepMerge(t,e=void 0,i=!0,s=!0,r=!0){const n={added:[],removed:[]};if(t.length<=1)return n;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){const T=t[y];if(T.isInstancedMesh||!T.geometry||!(T.geometry instanceof d.BufferGeometry))continue;let v=!1;const b=Object.values(o);for(let E=b.length-1;E>=0;--E){const O=b[E].indexes[0];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}for(let E=l.length-1;!v&&E>=0;--E){const O=l[E];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}!v&&l.push(y)}if(Object.keys(o).length<=0)return n;S.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const c=[],u=[],f=[],m=[];Object.values(o).forEach(y=>{const T=y.indexes;if(T.length<2)return;const v=t[T[0]];let b=[],E=0,O=0,_=0;const C=[];if(T.forEach(M=>{const P=t[M],A=P.geometry.clone();if(v.material instanceof d.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,P,e),A.userData.isLineSegments=P.isLineSegments===!0,b.push(A),r){const I=P.name,k=A.attributes?.position?.count,B=A.index?.count||0;let L;v.isLine&&(!A.boundingSphere&&A.computeBoundingSphere(),L=A.boundingSphere.clone());const q={batchId:E,name:I,positionStart:O,positionCount:k,indexStart:_,indexCount:B,boundingSphere:L};!P.parent.geometry&&Object.keys(P.parent.userData).length!==0&&(q.parentUserData=P.parent.userData),Object.keys(P.userData).length!==0&&(q.userData=P.userData),C.push(q),O+=k,_+=B,E++}}),b.length===0)return;let w;if(v.isMesh){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new d.Mesh(M,v.material),c.push(w)}else if(v.isLine){const M=this.mergeLineGeometries(b,r,v.material instanceof d.LineDashedMaterial||v.material instanceof d.ShaderMaterial,C);if(!M)return;w=new d.LineSegments(M,v.material),u.push(w)}else if(v.isPoints){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new d.Points(M,v.material),f.push(w)}w&&(r?w.userData.batches=C:(w.userData=v.userData,w.userData.batches=void 0),w.userData.layerName=v.userData.layerName,w.name="[Merged] "+v.name,w.matrixAutoUpdate=He,w.renderOrder=v.renderOrder,w.layers.mask=v.layers.mask,w.visible=v.visible,T.forEach(M=>m.push(M))),b.forEach(M=>{M.dispose(),U.releaseGeometryManually(M)}),b=[]}),S.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const g=n.removed;m.forEach(y=>{const T=t[y];g.push(T),i&&T.removeFromParent()});const x=n.added;return[...c,...u,...f].forEach(y=>{x.push(y),i&&e&&(e.add(y),y.updateWorldMatrix(!1,!1))}),this.MergeInfo.removedObjects+=m.length,this.MergeInfo.mergedMeshes+=c.length,this.MergeInfo.mergedLines+=u.length,this.MergeInfo.mergedPoints+=f.length,s&&e&&$.removeEmptyObjects(e),n}static applyMatrix(t,e,i){let s=e;for(Ti.identity();s&&s!==i&&(Ti.premultiply(s.matrix),!!s.parent);)s=s.parent;return Ti.equals(Oo)?t:t.applyMatrix4(Ti)}static mergeLineGeometries(t,e,i,s){let r;if(i)r=ci.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(r=xe.mergeGeometries(t),!r)return;r.userData={};const n=[];let a=0;t.forEach((o,l)=>{const c=o.attributes.position;if(!c)return;const u=o.index,f=o.userData.isLineSegments===!0,m=n.length;if(u)for(let g=0;g<u.count;g++){const x=u.array[g];f?n.push(a+x):g>0&&n.push(a+u.array[g-1],a+x)}else for(let g=0;g<c.count;g++)g>0&&(f?g%2===1&&n.push(a+g-1,a+g):n.push(a+g-1,a+g));a+=c.count,e&&s&&(s[l].indexStart=m,s[l].indexCount=n.length-m)}),r.setIndex(n)}return r}static mergeBufferGeometriesWithLinesToLineSegments(t,e,i){const s=new Set(Object.keys(t[0].attributes)),r={},n=new d.BufferGeometry,a=[];let o=0;for(let l=0;l<t.length;++l){let c=t[l];const u=c.userData.isLineSegments===!0;a.push(u),c.index&&(S.debug("[Merge] Geometry '"+l+"' contains index buffer, going to convert it to non-indexed."),c=U.convertGeometryWithIndexedToNonIndexed(c));let f=0;for(const m in c.attributes){if(!s.has(m))return S.error("[Merge] mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure "+m+" attribute exists among all geometries, or in none of them"),void 0;!r[m]&&(r[m]=[]),r[m].push(c.attributes[m]),f++}if(f!==s.size)return S.error("[Merge] mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),void 0;if(e&&i){const m=c.attributes.position;i[l].indexStart=0,i[l].indexCount=0;const g=u?m.count:m.count*2-2;i[l].positionStart=o,i[l].positionCount=g,o+=g}}for(const l in r){const c=ci.mergeBufferAttributesWithLinesToLineSegments(r[l],a);if(!c)return S.error("[Merge] mergeGeometries() failed while trying to merge the "+l+" attribute."),void 0;n.setAttribute(l,c)}return n}static mergeBufferAttributesWithLinesToLineSegments(t,e){let i,s,r,n=0;for(let l=0;l<t.length;++l){const c=t[l];if(i===void 0&&(i=c.array.constructor),i!==c.array.constructor)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.array must be of consistent array types across matching attributes."),void 0;if(s===void 0&&(s=c.itemSize),s!==c.itemSize)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.itemSize must be consistent across matching attributes."),void 0;if(r===void 0&&(r=c.normalized),r!==c.normalized)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.normalized must be consistent across matching attributes."),void 0;const u=e[l],f=u?0:c.count-2,m=c.count+f;n+=m*s}const a=new i(n);let o=0;for(let l=0;l<t.length;++l){const c=e[l],u=t[l],f=c?0:u.count-2,m=u.count+f,g=u.itemSize,x=new i(m*g);let y=0;for(let T=0;T<u.count;T++){const v=T*g,b=T!==0&&T!==u.count-1&&!c;for(let E=0;E<g;E++)x[y+E]=u.array[v+E],b&&(x[y+g+E]=u.array[v+E]);y+=b?2*g:g}a.set(x,o),o+=m*g}return new d.BufferAttribute(a,s,r)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static removeObjectFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areGeometriesMergeable(t,e){if(!t||!e||t.type==="InstancedBufferGeometry"||e.type==="InstancedBufferGeometry"||!!t.index!=!!e.index)return!1;const i=Object.keys(t.attributes);if(i.length!==Object.keys(e.attributes).length)return!1;for(const s of i)if(!e.attributes[s])return!1;return!0}static areObjectsMergeable(t,e){if(t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.visible!==e.visible||t.userData.layerName!==e.userData.layerName)return!1;if(t.type===e.type)return!0;const i=t,s=e;return i.isMesh&&s.isMesh||i.isLine&&s.isLine||i.isPoints&&s.isPoints}static isMergedMesh(t){return!!(t&&t.userData.batches)}static isFaceIndexInBatch(t,e,i){if(t.boundsTree){const s=t.index,r=s.getX(i*3);if(r>=e.positionStart&&r<e.positionStart+e.positionCount)return!0}else if(t.index){const s=e.indexStart/3,r=(e.indexStart+e.indexCount)/3-1;if(i>=s&&i<=r)return!0}else{const s=i*3;if(s>=e.positionStart&&s<e.positionStart+e.positionCount)return!0}return!1}static getBatchByFaceIndex(t,e){if(e<0)return S.error("[Merge]: Invalid faceIndex: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const r=i[s];if(this.isFaceIndexInBatch(t.geometry,r,e))return r}}static getBatchByLineIndex(t,e){if(e<0)return S.error("[Merge]: Invalid index: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(!i)return;const s=t.geometry,r=s.index;for(let n=0;n<i.length;++n){const a=i[n];if(r){if(e>=a.indexStart&&e<a.indexStart+a.indexCount)return a}else if(e>=a.positionStart&&e<a.positionStart+a.positionCount)return a}}static getBatchIdByFaceIndex(t,e){const i=this.getBatchByFaceIndex(t,e);return i?i.batchId:-1}static getBatchByBatchId(t,e){const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const r=i[s];if(r.batchId===e)return r}}static cloneGeometryForBatch(t,e){const i=t&&t.geometry;if(!i)return;const s=i.attributes.position,r=s?.array;let n=i.index?.array;if(!r||!n)return S.warn("[Merge]: Unexpected position: "+r+", or index: "+n+"!"),void 0;const a=new d.BufferGeometry,o=e.positionStart,l=e.positionStart+e.positionCount,c=i.attributes;for(const x in c){const y=c[x],T=y.itemSize,v=y.array.slice(o*T,l*T);a.setAttribute(x,new d.BufferAttribute(v,T,y.normalized))}if(i.boundsTree&&(n=i.userData.originalIndex,!n))return S.warn("[Merge] After building bvh, the original index data is not preserved !"),void 0;const u=e.indexStart,f=e.indexStart+e.indexCount,m=[];let g=0;for(let x=u;x<f&&x<n.length;++x)m[g++]=n[x]-e.positionStart;return a.setIndex(m),i.boundingBox&&a.computeBoundingBox(),i.boundingSphere&&a.computeBoundingSphere(),a}};p(ci,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let oe=ci;const Eo=.01;class _o{static getFaces(t){const e=t.map(r=>r.toArray()).reduce((r,n)=>(r.push(...n),r),[]),i=[];return da.Earcut.triangulate(e,[],3).forEach(r=>i.push(r)),i}static arePointsCoplanar(t){if(t.length<4)return!0;const e=t[1].clone().sub(t[0]),s=t[2].clone().sub(t[0]).cross(e).normalize();for(let r=3;r<t.length;r++)if(t[r].clone().sub(t[0]).projectOnVector(s).length()>Eo)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return ua(e).length>0}}class st{static getVisibleObjectBoundingBox(t){const e=new d.Box3;return t.traverse(i=>{i.visible&&(i instanceof d.Mesh||i instanceof d.Line)&&$.isObjectSelectable(i)&&e.expandByObject(i)}),e}static getObjectsBoundingBox(t,e,i){const s=new d.Box3;return e.forEach(r=>{const n=t.getObjectById(r);if(n){const a=st.getBoundingBox(n,i);a.isEmpty()||s.union(a)}}),s}static getBoundingBox(t,e=!0){const i=new d.Box3;if(t instanceof d.InstancedMesh)return st.getInstancedMeshBoundingBox(t);if(t.children.length===0)return i.expandByObject(t),i;const s=t.children.length;let r=1;s>20&&(r=3),s>100&&(r=5),s>200&&(r=10),s>1e3&&(r=100),t.updateMatrixWorld(!1);for(let n=0;n<s;++n){const a=t.children[n];if(!e||n%r===0)if(a.updateMatrix(),a instanceof d.InstancedMesh){const o=st.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(V.isMatrixValid(a.matrixWorld)){const o=st.getBoundingBox(a);o.isEmpty()||i.union(o)}else console.warn("[SceneUtils] Found object("+a.type+") with invalid matrix: "+a.matrixWorld.elements)}return t.geometry&&i.expandByObject(t),i}static getInstancedMeshBoundingBox(t){const e=new d.Box3,i=new d.Matrix4;for(let s=0;s<t.count;++s){t.getMatrixAt(s,i);const r=t.geometry.clone();if(r.boundingBox){const n=r.boundingBox.applyMatrix4(i);!n.isEmpty()&&V.isBoxValid(n)&&e.union(n)}}return e.applyMatrix4(t.matrixWorld),e}static getObjectCenter(t,e){const i=st.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class dt{static setMaterialSection(t,e,i=!1,s=!1){const r=i&&t.clippingPlanes?t.clippingPlanes:[];r.push(...e),t.clippingPlanes=r,t.clipIntersection=s}static removeSection(t){t&&t.traverse(e=>{const i=e.material;Array.isArray(i)?i.forEach(s=>{s.clippingPlanes=[]}):i&&(i.clippingPlanes=[])})}static addSection(t,e,i=!1,s=!1){t&&t.traverse(r=>{const n=r.material;Array.isArray(n)?n.forEach(a=>{dt.setMaterialSection(a,e,i,s)}):n&&dt.setMaterialSection(n,e,i,s)})}static generateSectionPlanesByBox(t){const e=t.min,i=t.max;return[new d.Plane(new d.Vector3(0,-1,0),i.y),new d.Plane(new d.Vector3(0,1,0),-e.y),new d.Plane(new d.Vector3(1,0,0),-e.x),new d.Plane(new d.Vector3(-1,0,0),i.x)]}static generateSectionPlanesByPoints(t,e=!0){const i=t.length;if(i<2)return;const s=[];for(let r=0;r<i-1;r++){const n=t[r],a=t[(r+1)%i],o=new d.Plane;o.setFromCoplanarPoints(new d.Vector3(n.x,n.y,-1),new d.Vector3(n.x,n.y,0),new d.Vector3(a.x,a.y,0)),e||o.negate(),s.push(o)}return s}}class Po{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new fa.SimplifyModifier().modify(t,i):t}static getNumberOfVerticesToRemove(t,e){let i=0;t instanceof d.BufferGeometry&&t.index&&(i=t.attributes.position.count);const s=Math.floor(i*e);return i<20?0:s}}const Ao=10;var tt=(h=>(h.TripleCross="TripleCross",h.Square="Square",h.Triangle="Triangle",h.CircleWithCross="CircleWithCross",h.Cross="Cross",h.Perpendicular="Perpendicular",h))(tt||{});class Io{static createSVGObject(t){return new pa.SVGObject(t)}}class fi{static async createEnvTexture(t,e){const i=new ma.RGBELoader;return new Promise(s=>{i.load(e,r=>{if(t){const n=t.fromEquirectangular(r).texture;t.dispose(),s(n)}})})}static async createEnvTextureFromDataArray(t,e=this.HDR_CITY_STREET_64x32,i=64,s=32){if(t){const r=new d.DataTexture(e,i,s);r.flipY=!0,r.magFilter=d.LinearFilter,r.minFilter=d.LinearFilter,r.type=d.HalfFloatType,r.version=1;const n=t.fromEquirectangular(r).texture;return t.dispose(),Promise.resolve(n)}return Promise.reject("Invalid pmremGenerator!")}}p(fi,"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 ko(){if(be.isBrowser){const h=document.createElement("div");return h.setAttribute("style","height: 1in; visibility: hidden; position: absolute; margin: 0; padding: 0;"),document.body.appendChild(h),.0254/h.clientHeight}else return .0254/96}const Es={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:ko()},cn={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},dn=h=>h===2?"²":h===3?"³":"",_s=(h,t=1)=>cn[h]+dn(t),Do=(h,t,e,i=1)=>(e==null&&(e=t),e===t?{value:h,unit:_s(e)}:{value:h*Math.pow(Es[t]/Es[e],i),unit:_s(e)+dn(i)});var un=(h=>(h.Top="Top",h.Bottom="Bottom",h.Front="Front",h.Back="Back",h.Left="Left",h.Right="Right",h))(un||{});class Bo{static getCameraDirectionByView(t){const e=new d.Vector3(1,0,0);return t==="Top"?e.set(0,-1,0):t==="Bottom"?e.set(0,1,0):t==="Front"?e.set(0,0,-1):t==="Back"?e.set(0,0,1):t==="Left"?e.set(1,0,0):t==="Right"&&e.set(-1,0,0),e}}var re=(h=>(h.MouseClick="mouseclick",h.LayoutChange="layoutchange",h.ModelLoad="modelload",h.BeforeRender="beforerender",h.AfterRender="afterrender",h.OnAnimate="onanimate",h.CameraChange="camerachange",h.ControlChange="controlchange",h.BoxSelectActivate="boxselectactivate",h.BoxSelectDeactivate="boxselectdeactivate",h.PickMarkupActivate="pickmarkupactivate",h.PickMarkupDeactivate="pickmarkupdeactivate",h.MarkupActivate="markupactivate",h.MarkupDeactivate="markupdeactivate",h.MarkupAdd="markupadd",h.MarkupUpdate="markupupdate",h.MarkupRemove="markupremove",h.BeforeRemoveMarkup="beforeremovemarkup",h.MeasurementActivate="measurementactivate",h.MeasurementDeactivate="measurementdeactivate",h.MeasurementAdd="measurementadd",h.MeasurementRemove="measurementremove",h.HotpointClick="hotpointclick",h))(re||{});const or={};class yi extends mt{constructor(e){super();p(this,"viewer");p(this,"drawableLists");p(this,"canvas");p(this,"context");p(this,"frustum");p(this,"projScreenMatrix");this.drawableLists=[],this.frustum=new d.Frustum,this.projScreenMatrix=new d.Matrix4,this.viewer=e,this.init()}static _registerDrawableClass(e){const i=e;or[i.prototype.getClassType()]=e}static createDrawable(e){const i=or[e.type];if(!i)throw new Error("Invalid drawable type: "+i);const s=e.points.map(n=>new d.Vector3(n[0],n[1],n[2]||0)),r=new i(e.id,s);return r.setData(e),r}get is3d(){return this.viewer.is3d()}get container(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}init(){this.initCanvas(),this.viewer.addEventListener(re.AfterRender,()=>{this.projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projScreenMatrix),this.render()})}initCanvas(){const e=this.viewer.getViewerConfig();if(be.isBrowser&&!e.context2d){const i=this.canvas=document.createElement("canvas"),s=this.viewer.viewerContainer;s.appendChild(i),i.classList.add("overlay-renderer"),i.style.pointerEvents="none",i.style.position="absolute",i.style.left="0px",i.style.top="0px",i.style.userSelect="none",this.context=i.getContext("2d",{willReadFrequently:!0});const{clientWidth:r,clientHeight:n}=s;this.setSize(r,n)}else e.context2d&&(this.context=e.context2d,this.canvas=be.creatReactNativeCanvas(this.context),this.context.canvas||(this.context.canvas=this.canvas))}toHighDpr(e,i,s){const r=Math.max(window.devicePixelRatio||1,1),n=this.canvas;return n.width=i*r,n.height=s*r,e.scale(r,r),n.style.width=i+"px",n.style.height=s+"px",e}clearCanvas(){this.context?.clearRect(0,0,this.canvas?.width??0,this.canvas?.height??0)}addDrawableList(e){this.drawableLists.push(e)}render(){if(!this.canvas||!this.context||this.drawableLists.length<1)return;this.clearCanvas();const e=this.getSortedDrawables(!1);if(e.length===0)return;const i=new d.Sphere,s=this.viewer.getPixelSizeInWorldCoord();for(let r=0;r<e.length;r++){const n=e[r];n.setTolerance(s),!(!n.visible||(n.getBounds().getBoundingSphere(i),n.needsFrustumCulled&&!this.frustum.intersectsSphere(i)))&&n.render(this.context,this.camera)}}setSize(e,i){const s=this.canvas;s.width=e,s.height=i,s.style.width=e+"px",s.style.height=i+"px",this.toHighDpr(this.context,e,i)}getSortedDrawables(e=!1){const i=[];return this.drawableLists.forEach(s=>{let r=Array.from(s.getDrawables().values());e&&(r=r.filter(n=>n.visible)),r.length>0&&i.push(...r)}),i.sort((s,r)=>s.renderOrder===r.renderOrder?r.getCenter().distanceTo(this.camera.position)-s.getCenter().distanceTo(this.camera.position):s.renderOrder-r.renderOrder),i}getDrawablesByDrawableListAndPosition(e,i){return this.is3d||(i.z=0),e.getDrawableByPosition(i,this.raycaster)}getDrawablesByPosition(e){this.is3d||(e.z=0);const i=this.getSortedDrawables(),s=[];for(let r=0;r<i.length;r++){const n=i[r];n.isPointInPath(e,this.raycaster)&&s.push(n)}return s}getDrawableById(e){return this.getSortedDrawables().find(s=>s.id===e)}measureTextLength(e,i){const s=this.context,r=e.split(`
535
- `);let n=0;for(let a=0;a<r.length;a++){const o=r[a];s.save(),s.font=i;const l=s.measureText(o).width;s.restore(),n=Math.max(n,l)}return n}getImage(e){this.clearCanvas();const i=this.getSortedDrawables();for(let s=0;s<i.length;s++){const r=i[s];e(r)&&r.render(this.context,this.camera)}return V.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 $i extends mt{constructor(e){super();p(this,"category");p(this,"drawableMap");this.drawableMap=new Map,this.category=e}addDrawable(e){this.drawableMap.set(e.id,e),this.dispatchEvent("add",e.getData())}updateDrawable(e,i){e.setData(i),this.dispatchEvent("update",e.getData())}removeDrawable(e){this.drawableMap.delete(e.id),this.dispatchEvent("remove",e.getData())}getDrawableById(e){return this.drawableMap.get(e)}clear(){this.drawableMap.forEach(e=>this.removeDrawable(e))}getDrawables(){return this.drawableMap}getDrawableDatas(){return Array.from(this.drawableMap).map(([,e])=>e.getData())}setDrawableDatas(e){for(let i=0;i<e.length;i++){const s=e[i],r=yi.createDrawable(s);this.addDrawable(r)}}getDrawableByPosition(e,i){let s;for(const[,r]of this.drawableMap)if(r.visible&&r.isPointInPath(e,i)){s=r;break}return s}}class pt extends mt{constructor(e){super();p(this,"DEFAULT_LINE_WIDTH",1);p(this,"DEFAULT_STROKE_STYLE",[0,0,0,1]);p(this,"DEFAULT_FILL_STYLE",[0,0,0,1]);p(this,"id");p(this,"lineWidth");p(this,"lineColor");p(this,"fillColor");p(this,"x");p(this,"y");p(this,"width");p(this,"height");p(this,"points");p(this,"userData");p(this,"tolerance");p(this,"visible");p(this,"selected");p(this,"renderOrder");p(this,"needsFrustumCulled");p(this,"editPointSize");p(this,"editPointFillColor");p(this,"editPointStrokeColor");p(this,"matrix");p(this,"ctx");this.lineWidth=this.DEFAULT_LINE_WIDTH,this.lineColor=this.DEFAULT_STROKE_STYLE,this.fillColor=this.DEFAULT_FILL_STYLE,this.x=0,this.y=0,this.width=0,this.height=0,this.points=[],this.userData={},this.tolerance=1,this.visible=!0,this.selected=!1,this.renderOrder=1,this.needsFrustumCulled=!0,this.editPointSize=3,this.editPointFillColor="#ffffff",this.editPointStrokeColor="#939ea4",this.matrix=new d.Matrix4,this.id=e||V.guid()}setTolerance(e){this.tolerance=e}render(e,i){this.ctx=e,this.draw(e,i),this.selected&&this.drawSelect(e,i)}getData(){return{id:this.id,points:this.points.map(e=>[e.x,e.y]),lineWidth:this.lineWidth,lineColor:this.lineColor,fillColor:this.fillColor,type:this.getClassType()}}setData(e){this.id=e.id,this.setLineWidth(e.lineWidth),this.setLineColor(e.lineColor),this.setFillColor(e.fillColor)}getVertexes(){const e=new d.Vector3(this.x,this.y,0),i=new d.Vector3(this.x+this.width,this.y,0),s=new d.Vector3(this.x+this.width,this.y-this.height,0),r=new d.Vector3(this.x,this.y-this.height,0);return[e,i,s,r]}setLineWidth(e){this.lineWidth=e||this.DEFAULT_LINE_WIDTH}setLineColor(e){this.lineColor=e||this.DEFAULT_STROKE_STYLE}setFillColor(e){this.fillColor=e||this.DEFAULT_FILL_STYLE}isSelected(){return this.selected}getCenter(){return this.getBounds().getCenter(new d.Vector3)}transToScreenCoord(e,i){return this.ctx?pe.world2Screen(e,i,this.ctx.canvas):new d.Vector2}drawBounds(e,i){const{min:s,max:r}=this.getBounds(),n=[],a=(o,l,c)=>n.push(new d.Vector3(o,l,c));a(r.x,r.y,r.z),a(s.x,r.y,r.z),a(s.x,s.y,r.z),a(r.x,s.y,r.z),a(r.x,r.y,s.z),a(s.x,r.y,s.z),a(s.x,s.y,s.z),a(r.x,s.y,s.z),a(s.x,r.y,r.z),a(s.x,s.y,r.z),a(r.x,r.y,r.z),a(r.x,s.y,r.z),a(r.x,r.y,s.z),a(r.x,s.y,s.z),a(s.x,r.y,s.z),a(s.x,s.y,s.z),a(s.x,r.y,r.z),a(s.x,r.y,s.z),a(r.x,r.y,r.z),a(r.x,r.y,s.z),a(s.x,s.y,r.z),a(s.x,s.y,s.z),a(r.x,s.y,r.z),a(r.x,s.y,s.z),e.save(),e.strokeStyle="yellow",e.beginPath(),n.forEach((o,l)=>{const c=this.transToScreenCoord(o,i);l%2===0?e.moveTo(c.x,c.y):e.lineTo(c.x,c.y)}),e.closePath(),e.stroke(),e.restore()}drawCenter(e,i){const s=this.transToScreenCoord(this.getCenter(),i);e.save(),e.fillStyle="yellow",e.beginPath(),e.arc(s.x,s.y,5,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}getBounds(){const e=this.getVertexes();return new d.Box3().setFromPoints(e)}}const as=new d.Vector3;class rt extends pt{constructor(e,i,s=[1,0,0,1],r){super(e);p(this,"boxes");p(this,"lineSegments");this.lineSegments=[],this.boxes=rt.expandBoxesWithGap(i),this.lineColor=s,this.fillColor=r??[s[0],s[1],s[2],.12],this.lineWidth=2,this.calculateCloudLineSegments(this.boxes)}static expandBoxesWithGap(e){return e.map(i=>{const s=i.clone(),r=s.getSize(as),n=Math.max(r.x,r.y)*.12||1;return s.expandByScalar(n)})}calculateCloudLineSegments(e){for(let i=0;i<e.length;i++){const s=e[i],r=[new d.Vector3(s.min.x,s.min.y),new d.Vector3(s.max.x,s.min.y),new d.Vector3(s.max.x,s.max.y),new d.Vector3(s.min.x,s.max.y),new d.Vector3(s.min.x,s.min.y)],n=as.subVectors(r[0],r[2]).length()/10||1e-4,a=[];for(let o=0;o<r.length-1;o++){const l=r[o],c=r[o+1],u=as.subVectors(c,l),f=u.length(),m=u.normalize(),g=Math.ceil(f/n);for(let x=0;x<g;x++)a.push(l.clone().add(m.clone().multiplyScalar(n*x)))}a.push(a[0]),this.lineSegments?.push(a)}}draw(e,i){e.save(),e.lineWidth=this.lineWidth,e.strokeStyle=Gt.rgba2Color(this.lineColor),e.fillStyle=Gt.rgba2Color(this.fillColor);for(let s=0;s<this.lineSegments.length;s++){const r=this.boxes[s];r&&this.fillRect(e,i,r);const n=this.lineSegments[s];this.drawBox(e,i,n)}e.restore()}fillRect(e,i,s){const r=[new d.Vector3(s.min.x,s.min.y),new d.Vector3(s.max.x,s.min.y),new d.Vector3(s.max.x,s.max.y),new d.Vector3(s.min.x,s.max.y)];e.beginPath();for(let n=0;n<r.length;n++){const a=this.transToScreenCoord(r[n],i);n===0?e.moveTo(a.x,a.y):e.lineTo(a.x,a.y)}e.closePath(),e.fill()}drawBox(e,i,s){e.beginPath();for(let r=0;r<s.length-1;r++){const n=this.transToScreenCoord(s[r],i),a=this.transToScreenCoord(s[r+1],i),o=rt.getControlPointByTwoPoints(a,n);r===0&&e.moveTo(n.x,n.y),e.quadraticCurveTo(o.x,o.y,a.x,a.y)}e.stroke()}static getControlPointByTwoPoints(e,i){const s=new d.Vector2().subVectors(i,e),r=s.angle(),n=s.length(),a=d.MathUtils.degToRad(45),o=n/2/Math.cos(a);return new d.Vector2(e.x+o*Math.cos(a-r),e.y-o*Math.sin(a-r))}drawSelect(e,i){throw new Error("Method not implemented.")}isPointInPath(e){return!1}getBounds(){const e=new d.Box3;for(let i=0;i<this.boxes.length;i++){const s=this.boxes[i];e.union(s)}return e}getClassType(){return"CompareDrawable"}}yi._registerDrawableClass(rt);const Lo=[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],Ro=["PROXY","REGION","INSERT","HATCH"];function Nt(h){return Lo[h]}function Ie(h){const t={};let e=h.lastReadGroup,i=e.code;if(t.x=e.value,i+=10,e=h.next(),e.code!==i)throw new Error("Expected code for point value to be "+i+" but got "+e.code);return t.y=e.value,i+=10,e=h.next(),e.code!==i||(t.z=e.value,h.next()),t}const Fo="OriginalHandle",zo="OriginalType",jo="Outlines";function Q(h,t){switch(t.code){case 0:h.type=t.value;break;case 5:h.handle=t.value;break;case 6:h.lineType=(t.value||"BYLAYER").toUpperCase();break;case 8:h.layer=t.value||"0";break;case 39:h.thickness=t.value;break;case 48:h.lineTypeScale=t.value>0?t.value:1;break;case 60:h.visible=t.value!==1;break;case 62:if(!h.isTrueColor){const e=t.value;h.colorIndex=e,e<0&&console.warn("[DxfParser] Negative colorIndex indicates layer is off or BYBLOCK/BYLAYER"),h.color=Nt(Math.abs(e))}break;case 67:h.inPaperSpace=t.value===1;break;case 330:h.ownerHandle=t.value;break;case 370:h.lineweight=t.value;break;case 410:h.layoutName=t.value;break;case 420:h.isTrueColor=!0,h.color=t.value;break;case 1e3:if(t.value&&typeof t.value=="string"){if(t.value.includes(Fo)){const e=t.value.split(":").map(i=>i.trim());h.extendedData||(h.extendedData={}),h.extendedData.originalHandle=e[1]}if(t.value.includes(jo)&&(h.extendedData||(h.extendedData={}),h.extendedData.outlines=[]),t.value.includes(zo)){const e=t.value.split(":").map(i=>i.trim());h.extendedData||(h.extendedData={}),h.extendedData.originalType=e[1]}}break;case 1001:break;case 92:case 331:case 347:break;default:return!1}return!0}function Yt(h,t){switch(t.code){case 0:h.type=t.value;break;case 5:h.handle=t.value;break;case 330:h.ownerHandle=t.value;break;case 1e3:break;case 1001:break;default:return!1}return!0}const Fs="BYLAYER",pi="BYBLOCK";var ge=(h=>(h[h.Mesh=-1]="Mesh",h[h.MeshWithPattern=0]="MeshWithPattern",h[h.LineWithWidth=1]="LineWithWidth",h[h.Line=2]="Line",h[h.LineWithPattern=3]="LineWithPattern",h[h.Point=4]="Point",h[h.Text=5]="Text",h))(ge||{});const ai=["INSERT","DIMENSION"];function Vo(h,t,e,i,s){if(!t)return 0;const r=/[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff]/.test(h),n=s&&s.toLowerCase().endsWith(".shx");let a=0,o=0;if(t.userData&&typeof t.userData.advanceWidth=="number")a=t.userData.advanceWidth,r||(a+=a*.15);else if(t.boundingBox){const l=new d.Vector3;t.boundingBox.getSize(l),a=l.x}if(h===" ")return a=e*.25,a;if(n)i>1?o=(i-1)*e*.1:o=a*.05;else{const l=e*.04;r?o=i>1?(i-1)*e*.1:0:o=i*l}return a+o}function Uo(h){const t=/(\\M\+(?:[0-5])[0-9A-Fa-f]{4,})/g,e=h.match(t);if(!e)return h;let i=h;for(const s of e){const r=s.substring(4);if(r.length<4){console.error(`警告:提取的十六进制数 '${r}' 长度不足,已保留原始编码。`);continue}const n=r.substring(0,4),a=r.substring(4);try{const o=new Uint8Array(n.match(/.{1,2}/g).map(u=>parseInt(u,16))),c=new TextDecoder("gbk").decode(o);i=i.replace(s,c+a)}catch(o){console.error("转换失败:",o)}}return i}function lr(h){const t=[];let e=h;const i=/\\[a-z]+\d*\.?\d*;?/g;return(h.match(i)||[]).forEach(r=>{e=e.replace(r,""),t.push(r)}),{formatCodes:t,plainText:e}}function No(h,t){const e=lr(h.text).plainText,i=lr(t.text).plainText;return e===i}var Te=(h=>(h.Added="Added",h.Removed="Removed",h.Modified="Modified",h.NoChange="NoChange",h))(Te||{});let ve=1;const et=class et{constructor(t,e,i={}){p(this,"dxf1");p(this,"dxf2");p(this,"changes");p(this,"comparedBlocks");p(this,"isComparingBlock");p(this,"isComparingDimension");p(this,"enableDetailComparision");if(this.changes={},this.comparedBlocks=new Map,this.isComparingBlock=!1,this.isComparingDimension=!1,this.enableDetailComparision=i.enableDetailComparision!=null?i.enableDetailComparision:!0,this.dxf1=t,this.dxf2=e,!t||!e)throw new Error("Invalid DXF data to compare!")}getLayerFrozen(t,e){const i=e.layer;if(!i)return;const s=t.tables?.layer?.layers;return s?s[i]?.frozen:void 0}async compare(t){this.changes={};const e=[],i=new Map;return this.dxf1.entities.forEach(s=>{if(!s.inPaperSpace){const r=this.getLayerFrozen(this.dxf1,s)===!0;!et.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!r&&e.push(s)}}),this.dxf2.entities.forEach(s=>{if(!s.inPaperSpace){const r=this.getLayerFrozen(this.dxf2,s)===!0;!et.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!r&&i.set(s.handle,s)}}),await this.compareEntities(e,i,t),Promise.resolve(this.changes)}isDimensionBlock(t){return t.includes("*D")}compareInsertOrDemensionEntities(t,e,i,s){if(!t.block||!e.block)return;const r=t.block;let n;if(this.isComparingBlock=!0,this.isDimensionBlock(r)){const a=this.dxf1.blocks[t.block],o=this.dxf2.blocks[e.block],l=Date.now();this.isComparingDimension=!0,n=this.compareBlock(t,e,a,o),this.isComparingDimension=!1,S.debug("[DxfCompare] compare block: "+r+" took "+(Date.now()-l)/1e3+"s")}else{if(!this.comparedBlocks.has(r)){const a=this.dxf1.blocks[r],o=this.dxf2.blocks[r],l=Date.now(),c=this.compareBlock(t,e,a,o);this.comparedBlocks.set(r,c),S.debug("[DxfCompare] compare block: "+r+" took "+(Date.now()-l)/1e3+"s")}n=this.comparedBlocks.get(r)}return n?.forEach(a=>{if(!a.parentHandles&&(a.parentHandles=[]),i&&s)a.type==="Added"?a.parentHandles.push(s):a.type==="Removed"&&a.parentHandles.push(i);else{const o=[...a.parentHandles,t.handle];a.type==="Added"?this.changes[ve]={id:ve,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[ve]={id:ve,...a,parentHandles:o}),ve++}}),!i&&!s&&(this.isComparingBlock=!1),n}compareBlock(t,e,i,s){const r=[],n=[];i?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&r.push(l)}),s?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&n.push(l)});const a=[],o=[];for(let l=0;l<r.length;l++){const c=r[l];let u=!1;n.length===0&&(u=!0),!this.isComparingDimension&&(this.isComparingDimension=c.type==="DIMENSION");for(let f=0;f<n.length;f++){const m=n[f];if(!this.entitiesEqual(c,m,t,e))u=!0;else if(c.type==="INSERT"&&m.type==="INSERT"||c.type==="DIMENSION"&&m.type==="DIMENSION"){const g=this.compareInsertOrDemensionEntities(c,m,c.handle,m.handle);g&&g.length>0&&a.push(...g),u=!1,n.splice(f--,1);break}else{u=!1,n.splice(f--,1);break}}u&&(a.push({type:"Removed",handle:c.handle}),o.push(c.handle))}return n.forEach(l=>{!o.includes(l.handle)&&a.push({type:"Added",handle:l.handle})}),a}async compareEntities(t,e,i){const s=V.getUpdateProgressFuncForLoop(t.length,i);for(let r=0;r<t.length;r++){const n=t[r].handle;if(!e.has(n))this.changes[ve]={id:ve,type:"Removed",handle:n},ve++;else{const a=t[r],o=e.get(n),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(ai.includes(a.type)){if(this.bIgnoreChildEntitiesOriginalType(a)){e.delete(n),S.warn("[DxfCompare] We cannot compare insert (handle '"+a.handle+"') yet, ignored!");continue}this.compareInsertOrDemensionEntities(a,o)}}else{if(a.extendedData?.originalType&&o.extendedData?.originalType&&a.block!==o.block){e.delete(n);continue}this.changes[ve]={id:ve,type:"Modified",handle:n},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[ve].detailChanges=l),ve++}e.delete(n)}await s(r)}for(const r of e){const n=r[0];this.changes[ve]={id:ve,type:"Added",handle:n},ve++}}bIgnoreChildEntitiesOriginalType(t){return Ro.includes(t.extendedData?.originalType)}entitiesEqual(t,e,i,s,r){if(!this.baseEntitiesEqual(t,e,i,s,r))return!1;const n=t.type;let a=!0;switch(n){case"CIRCLE":case"ARC":a=this.arcsEqual(t,e);break;case"LWPOLYLINE":case"LINE":a=this.linesEqual(t,e,r);break;case"POLYLINE":a=this.polylinesEqual(t,e);break;case"TEXT":a=this.textsEqual(t,e);break;case"SOLID":a=this.solidsEqual(t,e);break;case"POINT":a=this.pointsEqual(t,e);break;case"INSERT":a=this.insertsEqual(t,e);break;case"SPLINE":a=this.splinesEqual(t,e);break;case"MTEXT":a=this.mtextsEqual(t,e);break;case"ELLIPSE":a=this.ellipsesEqual(t,e);break;case"DIMENSION":a=this.dimensionsEqual(t,e);break;case"REGION":a=this.regionsEqual(t,e);break;case"ATTDEF":a=this.attDefsEqual(t,e);break;case"ATTRIB":a=this.attribsEqual(t,e);break;case"HATCH":a=this.hatchesEqual(t,e);break;case"VIEWPORT":a=this.viewportsEqual(t,e);break;case"LEADER":a=this.leadersEqual(t,e);break;case"MULTILEADER":a=this.mleadersEqual(t,e);break;case"OLE2FRAME":a=this.ole2framesEqual(t,e);break;case"SEQEND":a=!0;break;default:a=!1}return a}getColor(t,e,i){if(t.isTrueColor||t.colorIndex>0&&t.colorIndex<256)return t.color;if(t.colorIndex===0)return i?this.getColor(i,e):e.tables?.layer?.layers[0].color;let s=0;if(t.colorIndex===256){const r=e.tables?.layer?.layers,n=r&&r[t.layer],a=r&&i&&r[i.layer];n&&n.name!=="0"?s=n.color:a?s=a.color:n?s=n.color:s=e.tables?.layer?.layers[0].color}return s}getLineType(t,e,i){if(i&&i.type==="DIMENSION")return this.getLineType(i,e);if(t.lineType!==Fs&&t.lineType!==pi)return t.lineType;if(t.lineType===pi)return i?this.getLineType(i,e):t.lineType;const s=e.tables?.layer?.layers,r="CONTINUOUS";if(t.layer!=="0"){const n=s&&s[t.layer];if(n)return n.lineType}else if(i){const n=s&&s[i.layer];if(n)return n.lineType}return r}addModificationItem(t,e,i,s){s&&(s[i]={old:t,new:e})}baseEntitiesEqual(t,e,i,s,r){let n=!0;const a=this.getColor(t,this.dxf1,i),o=this.getColor(e,this.dxf2,s);if(a!==o)if(n=!1,this.enableDetailComparision)this.addModificationItem(a,o,"color",r);else return n;const l=this.getLineType(t,this.dxf1,i),c=this.getLineType(e,this.dxf2,s);if(l!==c){if(n=!1,this.enableDetailComparision)this.addModificationItem(l,c,"lineType",r);else return n;return!1}return t.extendedData?.originalType!==e.extendedData?.originalType||!this.isComparingBlock&&!this.isComparingDimension&&t.handle!==e.handle||!this.isComparingDimension&&t.ownerHandle!==e.ownerHandle||t.type!==e.type?!1:n}arcsEqual(t,e){return!(!this.vectorsEqual(t.center,e.center)||!this.numberEqual(t.radius,e.radius)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}linesEqual(t,e,i){let s=!0;const r=t.constantWidth,n=e.constantWidth;if(!this.numberEqual(r,n))if(s=!1,this.enableDetailComparision)this.addModificationItem(r||0,n||0,"constantWidth",i);else return!1;return!this.verticesEqual(t.vertices,e.vertices)||t.shape!==e.shape?!1:s}polylinesEqual(t,e){return!(!this.vertexEntitiesEqual(t.vertices,e.vertices)||t.shape!==e.shape||t.isPolyfaceMesh!==e.isPolyfaceMesh)}textsEqual(t,e){if(t.halign!==e.halign)return!1;if(t.halign===3||t.halign===5){if(!this.pointsEqual(t.startPoint,e.startPoint))return!1}else if(!this.pointsEqual(t.endPoint,e.endPoint))return!1;return t.text===e.text}solidsEqual(t,e){return!!this.verticesEqual(t.points,e.points)}pointEntitiesEqual(t,e){return!!this.pointsEqual(t.position,e.position)}splinesEqual(t,e){return!(!this.verticesEqual(t.controlPoints,e.controlPoints)||!this.numbersEqual(t.knotValues,e.knotValues)||!this.numberEqual(t.degreeOfSplineCurve,e.degreeOfSplineCurve))}mtextsEqual(t,e,i={}){const{compareFormat:s=!1,comparePosition:r=!0}=i;if(r&&!this.pointsEqual(t.position,e.position))return!1;if(s){if(t.text!==e.text)return!1}else if(!No(t,e))return!1;return!!this.numberEqual(t.rotation,e.rotation)}ellipsesEqual(t,e){return!(!this.pointsEqual(t.center,e.center)||!this.pointsEqual(t.majorAxisEndPoint,e.majorAxisEndPoint)||!this.numberEqual(t.axisRatio,e.axisRatio)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}attDefsEqual(t,e){return!(!this.pointsEqual(t.startPoint,e.startPoint)||!this.pointsEqual(t.endPoint,e.endPoint)||!this.numberEqual(t.xScale,e.xScale)||t.text!==e.text||t.tag!==e.tag||t.prompt!==e.prompt)}attribsEqual(t,e){return this.attDefsEqual(t,e)}hatchesEqual(t,e){const i=t,s=e;return!(!this.numberEqual(i.elevationX,s.elevationX)||!this.numberEqual(i.elevationY,s.elevationY)||!this.numberEqual(i.elevationZ,s.elevationZ)||!this.hatchBoundaryPathArraysEqual(i.boundaryPaths,s.boundaryPaths))}viewportsEqual(t,e){const i=t,s=e;return!(!this.pointsEqual(i.centerPoint,s.centerPoint)||!this.pointsEqual(i.centerPoint_dcs,s.centerPoint_dcs)||!this.pointsEqual(i.viewDirection,s.viewDirection)||!this.numberEqual(i.viewHeight,s.viewHeight)||i.width_paperSpace!==s.width_paperSpace||i.height_paperSpace!==s.height_paperSpace)}leadersEqual(t,e){return!(!this.pointsEqual(t.position,e.position)||!this.verticesEqual(t.vertices,e.vertices)||t.arrowHeadBlockHandle!==e.arrowHeadBlockHandle||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)||!this.numberEqual(t.rotation,e.rotation)||t.block!==e.block)}mleadersEqual(t,e){return t.arrowHeadId!==e.arrowHeadId||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)?!1:this.mleaderContextEqual(t.contextData,e.contextData)}ole2framesEqual(t,e){return!(t.leftUpX!==e.leftUpX||t.leftUpY!==e.leftUpY||t.leftUpZ!==e.leftUpZ||t.rightDownX!==e.rightDownX||t.rightDownY!==e.rightDownY||t.rightDownZ!==e.rightDownZ)}insertsEqual(t,e){return t.extendedData?.originalType==="INSERT"&&e.extendedData?.originalType==="INSERT"?(S.warn("[DxfCompare] We cannot compare insert (handle '"+t.handle+"') yet, ignored!"),!0):!(!this.pointsEqual(t.position,e.position)||!this.numberEqual(t.xScale===void 0?1:t.xScale,e.xScale===void 0?1:e.xScale)||!this.numberEqual(t.yScale===void 0?1:t.yScale,e.yScale===void 0?1:e.yScale)||!this.numberEqual(t.zScale===void 0?1:t.zScale,e.zScale===void 0?1:e.zScale)||t.block!==e.block||t.entities?.length!==e.entities?.length)}dimensionsEqual(t,e){return!!this.pointsEqual(t.anchorPoint,e.anchorPoint)}regionsEqual(t,e){return S.warn("Cannot compare region yet!"),!0}vectorsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z):!1}pointsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z)&&this.numberEqual(t.bulge,e.bulge):!1}vertexEntityEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t,e)||t.polyfaceMeshVertex!==e.polyfaceMeshVertex||t.threeDPolylineMesh!==e.threeDPolylineMesh):!1}numbersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.numberEqual(t[i],e[i]))return!1;return!0}return!1}numberEqual(t,e){return t==null&&e==null?!0:t!=null&&e!=null?R.areNumbersEqual(t,e):!1}vectorArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vectorsEqual(t[i],e[i]))return!1;return!0}return!1}verticesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.pointsEqual(t[i],e[i]))return!1;return!0}return!1}verticesArrayEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.verticesEqual(t[i],e[i]))return!1;return!0}return!1}vertexEntitiesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vertexEntityEqual(t[i],e[i]))return!1;return!0}return!1}hatchEdgesEqual(t,e){return!t&&!e?!0:t&&e?t.type===e.type:!1}hatchEdgeArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchEdgesEqual(t[i],e[i]))return!1;return!0}return!1}hatchBoundaryPathsEqual(t,e){return!t&&!e?!0:t&&e?t.pathTypeFlag!==e.pathTypeFlag?!1:this.hatchEdgeArraysEqual(t.edges,e.edges):!1}hatchBoundaryPathArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchBoundaryPathsEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLineEqual(t,e){return!t&&!e?!0:t&&e?!(!this.verticesArrayEqual(t.vertices,e.vertices)||t.leaderLineIndex!==e.leaderLineIndex):!1}mleaderLinesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLineEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLeaderEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.lastLeaderLinePoint,e.lastLeaderLinePoint)||!this.pointsEqual(t.doglegVector,e.doglegVector)||!this.mleaderLinesEqual(t.leaderLines,e.leaderLines)):!1}mleaderLeadersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLeaderEqual(t[i],e[i]))return!1;return!0}return!1}mleaderContextEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.contentBasePosition,e.contentBasePosition)||!this.pointsEqual(t.blockContentPosition,e.blockContentPosition)||!this.mleaderLeadersEqual(t.leaders,e.leaders)):!1}compareHexStrings(t,e){return parseInt(t,16)-parseInt(e,16)}};p(et,"ENTITY_COLOR_ADDED",65280),p(et,"ENTITY_COLOR_REMOVED",16711680),p(et,"ENTITY_COLOR_NO_CHANGE",10066329),p(et,"ENTITY_COLOR_MARKUP",16744231),p(et,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let Ue=et;var N=(h=>(h[h.Object=0]="Object",h[h.Point=1]="Point",h[h.Line=2]="Line",h[h.LineSegment=3]="LineSegment",h[h.Mesh=4]="Mesh",h))(N||{});const os=new Se.Box3,ls=new Se.Matrix4;class F{constructor(t=0){p(this,"name");p(this,"type");p(this,"matrix");p(this,"parent");p(this,"children");p(this,"layers");p(this,"renderOrder");p(this,"userData");p(this,"material");p(this,"geometry");p(this,"matrixWorld");this.name="",this.type=0,this.matrix=new Se.Matrix4,this.children=[],this.layers=new Se.Layers,this.renderOrder=0,this.userData={},this.type=t}add(t,...e){for(let i=0;i<e.length;i++)this.add(e[i]);return t===this?(console.error("object can't be added as a child of itself.",t),this):(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),this)}remove(t,...e){for(let s=0;s<e.length;s++)this.remove(e[s]);const i=this.children.indexOf(t);return i!==-1&&(t.parent=void 0,this.children.splice(i,1)),this}removeFromParent(){const t=this.parent;return t&&t.remove(this),this}clear(){this.material=void 0,this.geometry=void 0;for(let t=0;t<this.children.length;t++){const e=this.children[t];e.parent=void 0}return this.children.length=0,this}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}clone(t=!0){return new F().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.type=t.type,this.matrix.copy(t.matrix),this.layers.mask=t.layers.mask,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),this.material=t.material,this.geometry=t.geometry,e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}convertToThreejsObject(t=!0){let e;switch(this.type){case 0:e=new Se.Object3D;break;case 1:if(!this.geometry)return;e=new d.Points(this.geometry,this.material);break;case 2:if(!this.geometry)return;e=new d.Line(this.geometry,this.material);break;case 3:if(!this.geometry)return;e=new d.LineSegments(this.geometry,this.material);break;case 4:if(!this.geometry)return;e=new d.Mesh(this.geometry,this.material);break}if(e){if(e.name=this.name,e.matrixAutoUpdate=He,e.applyMatrix4(this.matrix),e.layers.mask=this.layers.mask,e.renderOrder=this.renderOrder,e.userData=this.userData,t===!0)for(let i=0;i<this.children.length;i++){const s=this.children[i],r=s.convertToThreejsObject(t);r&&e.add(r)}return e}}static getBox(t,e,i){if(t.geometry)!t.geometry.boundingBox&&t.geometry.computeBoundingBox(),ls.copy(t.matrix),i&&ls.premultiply(i),os.copy(t.geometry.boundingBox),os.applyMatrix4(ls),e.union(os);else if(t.children.length>0){!t.matrixWorld&&(t.matrixWorld=new Se.Matrix4),t.matrixWorld.copy(t.matrix),i&&t.matrixWorld.premultiply(i);const s=t.children;for(let r=0,n=s.length;r<n;r++)this.getBox(s[r],e,t.matrixWorld)}return e}computeBoundingllBox(t,e,i){const s={x:0,y:0};s.x=e.position?.x||0,s.y=e.position?.y||0;let r=e.blockPosition?.x||0,n=e.blockPosition?.y||0;s.x=s.x-r,s.y=s.y-n;const a=new Se.Box3().makeEmpty();t.userData.boundingBoxs=[];const o=[];t.children.forEach(l=>{for(new Se.Box3;!l.geometry&&l.children&&l.children.length===1;)l={...l.children[0],loneMatrix:l.matrix};if(l.geometry){!l.geometry.boundingBox&&l.geometry.computeBoundingBox();const c=new Se.Box3().copy(l.geometry.boundingBox);c.applyMatrix4(l.loneMatrix||l.matrix),o.push({min:{x:c.min.x,y:c.min.y,z:c.min.z},max:{x:c.max.x,y:c.max.y,z:c.max.z},positions:[{x:c.min.x+s.x,y:c.min.y+s.y},{x:c.min.x+s.x,y:c.max.y+s.y},{x:c.max.x+s.x,y:c.max.y+s.y},{x:c.max.x+s.x,y:c.min.y+s.y}],rotation:e.rotation,center:{x:(c.min.x+c.max.x)/2+s.x,y:(c.min.y+c.max.y)/2+s.y,z:(c.min.z+c.max.z)/2},size:{x:c.max.x-c.min.x,y:c.max.y-c.min.y,z:c.max.z-c.min.z}}),a.union(c)}}),!a.isEmpty()&&a.max.x-a.min.x<20&&a.max.y-a.min.y<20?t.userData.boundingBoxs=[{min:{x:a.min.x,y:a.min.y,z:a.min.z},max:{x:a.max.x,y:a.max.y,z:a.max.z},positions:[{x:a.min.x+s.x,y:a.min.y+s.y},{x:a.min.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.min.y+s.y}],rotation:e.rotation,center:{x:(a.min.x+a.max.x)/2+s.x,y:(a.min.y+a.max.y)/2+s.y,z:(a.min.z+a.max.z)/2},size:{x:a.max.x-a.min.x,y:a.max.y-a.min.y,z:a.max.z-a.min.z}}]:t.userData.boundingBoxs=o}rotateRectByBottomLeft(t,e,i,s,r){const n=i-t,a=s-e,o=r*Math.PI/180,l=Math.cos(o),c=Math.sin(o);return[{dx:0,dy:0},{dx:n,dy:0},{dx:n,dy:a},{dx:0,dy:a}].map(f=>{const m=f.dx*l-f.dy*c,g=f.dx*c+f.dy*l;return{x:t+m,y:e+g}})}}const Ci=new d.Matrix4,Ho=new d.Matrix4;class Qe{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},r=[];for(let c=0;c<i;++c){const u=t.children[c];if(u.children.length>0){this.mergeInner(u,e);continue}if(u.userData.relativeToCenter||!u.geometry)continue;let m=!1;const g=Object.values(s);for(let x=g.length-1;x>=0;--x){const y=g[x].indexes[0];if(m=this.tryHandleMergeableObjects(t,c,y,s,r),m)break}for(let x=r.length-1;!m&&x>=0;--x){const y=r[x];if(m=this.tryHandleMergeableObjects(t,c,y,s,r),m)break}!m&&r.push(c)}if(Object.keys(s).length<=0)return;const n=[],a=[],o=[],l=[];Object.values(s).forEach(c=>{const u=c.indexes,f=t.children[u[0]];let m=[],g=0,x=0,y=0;const T=[];if(u.forEach(b=>{const E=t.children[b],O=E.geometry?.clone();if(O.applyMatrix4(E.matrix),O.userData.isLineSegments=E.type===N.LineSegment,m.push(O),e){const _=O.attributes?.position?.count,C=O.index?.count||0;T.push({batchId:g,positionStart:x,positionCount:_,indexStart:y,indexCount:C}),x+=_,y+=C,g++}}),m.length===0)return;let v;if(f.type===N.Mesh){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new F(f.type),v.geometry=b,v.material=f.material,n.push(v)}else if(f.type===N.Line||f.type===N.LineSegment){const b=oe.mergeLineGeometries(m,e,f.material instanceof d.LineDashedMaterial||f.material instanceof d.ShaderMaterial,T);if(!b)return;v=new F(N.LineSegment),v.geometry=b,v.material=f.material,a.push(v)}else if(f.type===N.Point){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new F(f.type),v.geometry=b,v.material=f.material,o.push(v)}v&&(e?v.userData.batches=T:(v.userData=f.userData,v.userData.batches=void 0),v.userData.layerName=f.userData.layerName,v.name="[Merged] "+f.name,v.renderOrder=f.renderOrder,v.layers.mask=f.layers.mask,l.push(...u)),m.forEach(b=>{b.dispose(),U.releaseGeometryManually(b)}),m=[]}),l.sort((c,u)=>u-c),l.forEach(c=>{const u=t.children[c];t.remove(u)}),[...n,...a,...o].forEach(c=>{t.add(c)}),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=n.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,r){let n=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return n;const l=a?t[e]:t.children[e],c=a?t[i]:t.children[i];return this.areObjectsMergeable(l,c)&&oe.areGeometriesMergeable(l.geometry,c.geometry)&&de.materialsEquals(l.material,c.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(r,i)),s[i].indexes.push(e),n=!0),n}static isFilteredByOtherFactors(t,e){const i=t;if(i.type===N.Mesh&&i.material&&i.material.isShaderMaterial)return!0;let s=!1,r=t;for(;r&&r!==e;){const n=r.userData;if(n.relativeToCenter||n.spatialFilterHandle){s=!0;break}r=r.parent}return s}static deepMerge(t,e=void 0,i=!0,s=!0,r=!0){const n={added:[],removed:[]};if(t.length<=1)return n;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){if(!t[y].geometry||this.isFilteredByOtherFactors(t[y],e))continue;let v=!1;const b=Object.values(o);for(let E=b.length-1;E>=0;--E){const O=b[E].indexes[0];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}for(let E=l.length-1;!v&&E>=0;--E){const O=l[E];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}!v&&l.push(y)}if(Object.keys(o).length<=0)return n;S.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const c=[],u=[],f=[],m=[];Object.values(o).forEach(y=>{const T=y.indexes;if(T.length<2)return;const v=t[T[0]];let b=[],E=0,O=0,_=0;const C=[];if(T.forEach(M=>{const P=t[M],A=P.geometry?.clone();if(v.material instanceof d.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,P,e),A.userData.isLineSegments=P.type===N.LineSegment,b.push(A),r){const I=A.attributes?.position?.count,k=A.index?.count||0;let B;(v.type===N.Line||v.type===N.LineSegment)&&(!A.boundingSphere&&A.computeBoundingSphere(),B=A.boundingSphere?.clone());const L={batchId:E,positionStart:O,positionCount:I,indexStart:_,indexCount:k,boundingSphere:B};Object.keys(P.userData).length!==0&&(L.userData=P.userData),C.push(L),O+=I,_+=k,E++}}),b.length===0)return;let w;if(v.type===N.Mesh){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new F(v.type),w.geometry=M,w.material=v.material,c.push(w)}else if(v.type===N.Line||v.type===N.LineSegment){const M=oe.mergeLineGeometries(b,r,v.material instanceof d.LineDashedMaterial||v.material instanceof d.ShaderMaterial,C);if(!M)return;w=new F(N.LineSegment),w.geometry=M,w.material=v.material,u.push(w)}else if(v.type===N.Point){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new F(v.type),w.geometry=M,w.material=v.material,f.push(w)}w&&(r?w.userData.batches=C:(w.userData=v.userData,w.userData.batches=void 0),w.userData.layerName=v.userData.layerName,w.name="[Merged] "+v.name,w.renderOrder=v.renderOrder,w.layers.mask=v.layers.mask,T.forEach(M=>m.push(M))),b.forEach(M=>{M.dispose(),U.releaseGeometryManually(M)}),b=[]}),S.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const g=n.removed;m.forEach(y=>{const T=t[y];g.push(T),i&&T.removeFromParent()});const x=n.added;return[...c,...u,...f].forEach(y=>{x.push(y),i&&e&&e.add(y)}),this.MergeInfo.removedObjects+=m.length,this.MergeInfo.mergedMeshes+=c.length,this.MergeInfo.mergedLines+=u.length,this.MergeInfo.mergedPoints+=f.length,s&&e&&$.removeEmptyObjects(e),n}static applyMatrix(t,e,i){let s=e;for(Ci.identity();s&&s!==i&&(Ci.premultiply(s.matrix),!!s.parent);)s=s.parent;return Ci.equals(Ho)?t:t.applyMatrix4(Ci)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areObjectsMergeable(t,e){return t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.userData.layerName!==e.userData.layerName?!1:t.type===e.type?!0:(t.type===N.Line||t.type===N.LineSegment)&&(e.type===N.Line||e.type===N.LineSegment)}}p(Qe,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});const fn=(h,t)=>{if(typeof t>"u"||+t==0)return Math.round(h);let e=+h;if(t=+t,isNaN(e)||!(typeof t=="number"&&t%1===0))return NaN;let i=e.toString().split("e");return e=Math.round(+(i[0]+"e"+(i[1]?+i[1]-t:-t))),i=e.toString().split("e"),+(i[0]+"e"+(i[1]?+i[1]+t:t))},pn=(h,t,e,i,s)=>{const r=e.length,n=e[0].length;if(h<0||h>1)throw new Error("t out of bounds [0,1]: "+h);if(t<1)throw new Error("degree must be at least 1 (linear)");if(t>r-1)throw new Error("degree must be less than or equal to point count - 1");if(i){if(i.length!==r+t+1)throw new Error("bad knot vector length")}else{i=[];for(let g=0;g<r+t+1;g++)i[g]=g}const a=[t,i.length-1-t],o=i[a[0]],l=i[a[1]];h=h*(l-o)+o,h=Math.max(h,o),h=Math.min(h,l);let c;for(c=a[0];c<a[1]&&!(h>=i[c]&&h<=i[c+1]);c++);const u=[];for(let g=0;g<r;g++){u[g]=[];const x=s?s[g]:1;for(let y=0;y<n;y++)u[g][y]=e[g][y]*x;u[g][n]=x}let f;for(let g=1;g<=t+1;g++)for(let x=c;x>c-t-1+g;x--){f=(h-i[x])/(i[x+t+1-g]-i[x]);for(let y=0;y<n+1;y++)u[x][y]=(1-f)*u[x-1][y]+f*u[x][y]}const m=[];for(let g=0;g<n;g++)m[g]=fn(u[c][g]/u[c][n],-9);return m},Go={d:"°",c:"⌀",p:"±"},oi=(h,t)=>{if(!h)return[];h=h.replace(/%%(.)/g,(o,l)=>Go[l]||l).replace(/\^I/g," ");const e=t?.encoding;let i=e instanceof TextDecoder?e:void 0,s="",r;const n=[],a=o=>{s&&(n.push(s),s=""),n.push(o)};for(let o=0;o<h.length;o++)switch(r=h[o]){default:s+=r;break;case"\\":{switch(r=h[++o]){default:s+=r;break;case"p":{const l=h.slice(o,o=h.indexOf(";",o));l.startsWith("pxq")||l.startsWith("pxi")||l.startsWith("pxt")||l.startsWith("pt")||l.startsWith("pi")||(l.startsWith("psm")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):l.startsWith("pq")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):a({[l.slice(0,l.length-1)]:l[l.length-1]}));break}case"P":s+=`
536
- `;break;case"f":case"F":{let l="";for(;r=h[++o];){if(r===";"){a({f:l});break}if(r==="|"){const c={f:l},u=h.indexOf(";",++o);for(const f of h.slice(o,u).split("|"))c[f[0]]=+f.slice(1);o=u,a(c);break}l+=r==="\\"?h[++o]:r}break}case"S":{let l="",c,u="";for(;r=h[++o];){if(r===";"){const f=l+u;f&&a(f);break}if(r==="\\"){const f=h[++o];c?u+=f:l+=f}else!c&&(r==="^"||r==="/"||r==="#")?c=r:c?u+=r:l+=r}break}case"H":case"W":{const l=++o,[,c,u]=h.slice(l,o=h.indexOf(";",o)).match(/^(\d*(?:\.\d+)?)(\D*)$/);a({[r]:[+c,u]})}break;case"Q":case"A":case"C":case"c":case"T":{const l=++o;a({[r]:+h.slice(l,o=h.indexOf(";",o))});break}case"L":case"O":case"K":a({[r]:1});break;case"l":case"o":case"k":a({[r.toUpperCase()]:0});break;case"U":case"u":h[o+1]==="+"?(s+=String.fromCodePoint(parseInt(h.substr(o+2,4),16)),o+=5):s+=r;break;case"M":case"m":e?h[o+1]==="+"&&(h[o+2]==="0"||h[o+2]==="1")?(s+=(i=i||new TextDecoder(e)).decode(new Uint8Array([parseInt(h.substr(o+3,2),16),parseInt(h.substr(o+5,2),16)])),o+=6):s+=r:s+="\\"+r;break}break}case"{":{let l=1;const c=o;for(;r=h[++o];)if(r==="{")l++;else if(r==="}"){if(--l===0){a(oi(h.slice(c+1,o)));break}}else r==="\\"&&o++;break}}return s&&n.push(s),n},qo={d:"°",c:"⌀",p:"±"},mn=(h,t)=>(h=gn(h),t?yn(h,t):h),gn=h=>h.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))),yn=(h,t)=>{let e=t instanceof TextDecoder?t:new TextDecoder(t);return h.replace(/\\[mM]\+[0|1]([0-9a-fA-F]{2})([0-9a-fA-F]{2})/g,(i,s,r)=>(e=e||new TextDecoder(t)).decode(new Uint8Array([parseInt(s,16),parseInt(r,16)])))},Ni=(h,t)=>{h=mn(h,t?.encoding);let e=0,i={text:""};const s=[i],r=h.matchAll(/%%(\d\d\d|.)/g);for(const n of r){i.text+=h.slice(e,n.index);const a=n[1],o=a.toLowerCase(),l=qo[o];l?i.text+=l:o.length===3?i.text+=String.fromCodePoint(+o):o==="k"||o==="o"||o==="u"?(i=Object.assign(Object.assign({},i),{text:""}),i[o]?delete i[o]:i[o]=1,s.push(i)):i.text+=o,e=n.index+n[0].length}return i.text+=h.slice(e),s.filter(n=>n.text)};class xn{static createLineShaderMaterial(t,e,i,s,r){let n=0;const a=[];for(let u=0;u<t.length;u++)a[u]=t[u],a[u]===0&&(a[u]=.5),a[u]*=i,n+=Math.abs(a[u]);const o=d.UniformsUtils.merge([d.UniformsLib.common,{pattern:{value:a},patternLength:{value:n},u_color:{value:new d.Color(e)}}]);o.u_viewportScale=s,o.u_cameraZoom=r;const l=`
534
+ `,we=d.ShaderChunk;we.outline_bc_vertex=Ja;we.outline_bc_fragment=Qa;we.outline_bc_pars_fragment=eo;we.outline_bc_pars_vertex=to;we.standard_ex_vertex=ao;we.standard_ex_fragment=oo;we.common_ex=Za;we.id_pars_vertex=Ka;we.id_vertex=$a;we.state_pars_fragment=io;we.state_fragment=so;we.state_transparent_fragment=ro;we.state_highlight_fragment=no;we.pick_ex_vertex=lo;we.pick_ex_fragment=ho;const co=d.ShaderChunk;class uo{constructor(t){p(this,"promise");p(this,"cancelReject");const e=new Promise((i,s)=>{this.cancelReject=s});this.promise=Promise.race([e,t])}cancel(){this.cancelReject&&this.cancelReject({type:"cancel"})}}const fo=Ws.default??Ws,S=fo;S.setLevel("warn");const nn=h=>{try{S.setLevel(h)}catch(t){S.setLevel("error"),S.error(t)}},Vt=class Vt{static isTouchScreenDevice(){return"ontouchstart"in window}static printDeviceInfo(){const t=navigator.userAgent,e=/(?:Android)/.test(t),i=/(?:Firefox)/.test(t),s=/(?:Chrome|CriOS)/.test(t),r=/(?:iPad|PlayBook)/.test(t)||e&&!/(?:Mobile)/.test(t)||i&&/(?:Tablet)/.test(t),n=/(?:iPhone)/.test(t)&&!r,a=!n&&!e,o=Vt.isTouchScreenDevice();e&&S.debug("[DI] is android"),i&&S.debug("[DI] is fireFox"),s&&S.debug("[DI] is chrome"),r&&S.debug("[DI] is tablet"),n&&S.debug("[DI] is iPhone"),a&&S.debug("[DI] is PC"),o&&S.debug("[DI] is touch device")}static creatReactNativeCanvas(t){const e=t,i=e.drawingBufferWidth||e.width||0,s=e.drawingBufferHeight||e.height||0;return{style:{},width:i,height:s,clientWidth:Math.ceil(i/(window.devicePixelRatio||1)),clientHeight:Math.ceil(s/(window.devicePixelRatio||1)),addEventListener:()=>{},removeEventListener:()=>{}}}};p(Vt,"isMobile",/mobile/i.test(navigator.userAgent)),p(Vt,"isBrowser",typeof document<"u"),p(Vt,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let be=Vt;const Ut=class Ut{static isFullScreen(){return!!(document.fullscreenElement||document.mozFullScreenElement)}static fullScreen(t=document.documentElement){(t.requestFullscreen||t.mozRequestFullScreen||t.webkitRequestFullscreen||t.msRequestFullscreen).call(t)}static exitFullscreen(){(document.exitFullscreen||document.mozCancelFullscreen||document.webkitExitFullscreen||document.msExitFullscreen).call(document)}static joinStrings(...t){return t.join("")}static numberToString(t){let e=2;return Math.abs(t)<1e-6?e=2:Math.abs(t)<1e-5?e=7:Math.abs(t)<1e-4?e=6:Math.abs(t)<.001?e=5:Math.abs(t)<.01?e=4:Math.abs(t)<.1&&(e=3),t.toFixed(e)}static byteCountToString(t){let e=t;return t>1e9?(e=t/1e9,this.numberToString(e)+" G"):t>1e6?(e=t/1e6,this.numberToString(e)+" M"):t>1e3?(e=t/1e3,this.numberToString(e)+" K"):this.numberToString(e)}static hexToBase64(t){return btoa((t.match(/\w{2}/g)||[]).map(function(e){return String.fromCharCode(parseInt(e,16))}).join(""))}static vectorToString(t){return Array.isArray(t)?"("+this.numberToString(t[0])+", "+this.numberToString(t[1])+", "+this.numberToString(t[2])+")":t instanceof d.Vector3?"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+", "+this.numberToString(t.z)+")":"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+")"}static arrayToVector2(t){if(t){if(t instanceof d.Vector2)return t;if(Array.isArray(t)&&t.length>=2)return new d.Vector2(t[0],t[1])}else return t}static arrayToVector3(t){if(t){if(t instanceof d.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new d.Vector3(t[0],t[1],t.length>2?t[2]:0)}else return t}static arrayToEuler(t){if(t){if(t instanceof d.Euler)return t;if(Array.isArray(t)&&t.length>=3)return new d.Euler(t[0],t[1],t[2])}else return t}static arrayOrObjectToVector3(t){if(t){if(t instanceof d.Vector3)return t;if(t instanceof d.Vector2)return new d.Vector3(t.x,t.y,0);if(Array.isArray(t)&&t.length>=2)return new d.Vector3(t[0],t[1],t[2]||0)}else return t;const e=t;if(e.x!=null&&e.y!=null)return new d.Vector3(e.x,e.y,e.z||0)}static isVectorValid(t){let e=t&&!isNaN(t.x)&&!isNaN(t.y)&&isFinite(t.x)&&isFinite(t.y);return e&&t instanceof d.Vector3&&(e=!isNaN(t.z)&&isFinite(t.z)),e}static isBoxValid(t){return t&&!t.isEmpty()&&this.isVectorValid(t.min)&&this.isVectorValid(t.max)}static isMatrixValid(t){const e=t&&t.elements;if(!e||e.length<16)return!1;for(let i=0;i<16;++i){const s=e[i];if(Number.isNaN(s))return!1}return!0}static guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}static expandBoxByScale(t,e){const i=new d.Vector3;t.getCenter(i);const s=(t.max.x-t.min.x)*e,r=(t.max.y-t.min.y)*e,n=(t.max.z-t.min.z)*e,a=new d.Vector3(i.x-s/2,i.y-r/2,i.z-n/2),o=new d.Vector3(i.x+s/2,i.y+r/2,i.z+n/2);t.set(a,o)}static expandBoxByMinSize(t,e){const i=new d.Vector3;t.getCenter(i);const s=t.max.x-t.min.x,r=t.max.y-t.min.y,n=t.max.z-t.min.z;s<e&&(t.min.setX(i.x-e/2),t.max.setX(i.x+e/2)),r<e&&(t.min.setY(i.y-e/2),t.max.setY(i.y+e/2)),n<e&&(t.min.setZ(i.z-e/2),t.max.setZ(i.z+e/2))}static generateRandomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static convertDecimalToHex(t){return t==null?"#ffffff":"#"+t.toString(16).padStart(6,"0")}static canvasToImage(t){const e=t.toDataURL(),i=new Image;return i.src=e,new Promise(s=>{i.onload=function(){s(i)}})}static renderingContextToImage(t,e,i="image/png",s=.8){if(e){const r=Math.max(e.min.x,0),n=Math.max(e.min.y,0),a=Math.max(e.max.x-r,0),o=Math.max(e.max.y-n,0),l=t.getImageData(r,n,a,o),c=document.createElement("canvas");return c.width=a,c.height=o,c.getContext("2d").putImageData(l,0,0),c.toDataURL(i,s)}return t.canvas.toDataURL(i,s)}static printMemory(t){if(!be.isBrowser)return;const e=performance.memory;if(!e){S.warn("[Util] performance.memory is not available in this browser");return}const i=(e.jsHeapSizeLimit/(1024*1024)).toFixed(2),s=(e.totalJSHeapSize/(1024*1024)).toFixed(2),r=(e.usedJSHeapSize/(1024*1024)).toFixed(2);S.info("[Util] "+t+". jsHeapSizeLimit: "+i+"M , totalJSHeapSize: "+s+"M , usedJSHeapSize: "+r+"M ")}static printGpuInfo(t){if(!be.isBrowser)return;const e=t.getExtension("webgl_debug_renderer_info"),i=t.getParameter(e.UNMASKED_RENDERER_WEBGL);S.info("[Util] gpu:",i)}static getExtension(t){return t.substring(t.lastIndexOf(".")+1)}static isBinaryFile(t){return Ut.getExtension(t)==="bin"}static isGzip(t){return t.length<=3?!1:t[0]==31&&t[1]==139&&t[2]==8}static async sleep(t){let e;await new Promise(i=>{e=setTimeout(()=>{i()},t)}),clearTimeout(e)}static async twinkle(t,e=500){const i=this.twinklingObjectIds;i[t.id]||(i[t.id]=!0,t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,delete i[t.id])}static getUpdateProgressFunc(t){return e=>{t&&t(new ProgressEvent("",{loaded:e,total:100}))}}static getUpdateProgressFuncAsync(t){let e=Date.now();return async i=>{if(t){t(new ProgressEvent("",{loaded:i,total:100}));const s=500,r=Date.now();r-e>s&&(await Ut.sleep(0),e=r)}}}static getUpdateProgressFuncForLoop(t,e){const i=Math.round(Math.pow(t,.5));let s=Date.now();return async r=>{if(e&&(r%i===0||r===t-1)){e(new ProgressEvent("",{loaded:r+1,total:t}));const n=500,a=Date.now();(a-s>n||r===t-1)&&(await Ut.sleep(0),s=a)}}}static getUpdateSubProgressFunc(t,e,i){let s=!1;return r=>{let n=r.loaded*100/r.total;n=n*(e-t)/100+t,n>e&&(s||(S.warn("[Progress] Invalid ProgressEvent:",r),s=!0),n=e),i&&i(new ProgressEvent(r.type,{loaded:n,total:100}))}}};p(Ut,"twinklingObjectIds",{});let z=Ut;const po=(h,t,e)=>{const{default:i,active:s}=t;e?(h.remove(i),h.add(s||i)):(s&&h.remove(s),h.add(i))};class qt{static color2rgba(t){let e=[0,0,0,1],i;if(i=/^(\w+)\(([^)]*)\)/.exec(t)){let s;const r=i[1],n=i[2];switch(r){case"rgb":case"rgba":(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))&&(e=[Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,Number(s[4]||1)]),(s=/^\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))&&(e=[Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,Number(s[4]||1)]);break;case"hsl":case"hsla":(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))&&(e=[parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,Number(s[4]||1)]);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(r===3)e=[parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,1];else if(r===6){const n=parseInt(s,16);e=[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255,1]}else console.warn("THREE.Color: Invalid hex color "+t)}return e}static rgba2Color(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]),r=t[3]!=null?t[3]:1;return"rgba("+e+","+i+","+s+","+r+")"}static colorStr2Rgba(t){let e=t.replace("rgba(","");e=e.replace(")","");const i=e.split(","),s=[];return s.push(this.to1(parseInt(i[0]))),s.push(this.to1(parseInt(i[1]))),s.push(this.to1(parseInt(i[2]))),i[3]!=null&&s.push(parseFloat(i[3])),s}static rgb2Hex(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]);return(e<<16)+(i<<8)+s}static to255(t){let e=Math.max(t,0);return e=Math.min(t,1),e*255}static to1(t){let e=Math.max(t,0);return e=Math.min(t,255),e/255}}class pe{static getScreenCoordinateByEvent(t,e){const i=new d.Vector2,{left:s,top:r}=e.getBoundingClientRect();return i.x=t.clientX-s,i.y=t.clientY-r,i}static getScreenCoordinateByTouchEvent(t,e){const i=new d.Vector2,{left:s,top:r}=e.getBoundingClientRect();return i.x=t.touches[0].clientX-s,i.y=t.touches[0].clientY-r,i}static world2Screen(t,e,i){const{clientWidth:s,clientHeight:r}=i,n=t.clone(),a=new d.Vector2;return n.project(e),a.x=Math.round((.5+n.x/2)*s),a.y=Math.round((.5-n.y/2)*r),a}static worldBBox2Screen(t,e,i){const s=new d.Box2,r=t.min,n=t.max,a=(o,l,c)=>{const u=new d.Vector3(o,l,c),f=this.world2Screen(u,e,i);s.expandByPoint(f)};return a(r.x,r.y,r.z),a(r.x,r.y,n.z),a(r.x,n.y,r.z),a(r.x,n.y,n.z),a(n.x,r.y,r.z),a(n.x,r.y,n.z),a(n.x,n.y,r.z),a(n.x,n.y,n.z),s}static screen2World(t,e,i){const s=pe.screen2Ndc(t,e,i);return new d.Vector3(s.x,s.y,1).unproject(e)}static screen2Ndc(t,e,i){const{clientWidth:s,clientHeight:r}=i,n=new d.Vector2;return n.x=t.x/s*2-1,n.y=-(t.y/r)*2+1,n}static world2NormalizedScreen(t,e,i){const s=new d.Vector3,r=t instanceof d.Vector2?0:t.z;s.set(t.x,t.y,r);const n=pe.world2Screen(s,e,i);return n.x/=i.clientWidth,n.y/=i.clientHeight,n}}class mo{static createCSS2DObject(t){const e=new rn.CSS2DObject(t);return t.dataset.objectId=e.id.toString(),e}static createDefaultHotpoint(t=12){const e=document.createElement("div"),i=e.style;return i.width=t+"px",i.height=t+"px",i.opacity="0.8",i.cursor="pointer",i.top=-t/2+"px",i.left=-t/2+"px",i.backgroundColor="#ffffff",i.border="2px solid #00DAB7",i.borderRadius="50%",this.createCSS2DObject(e)}static createHotpoint(t){if(t){const e=document.createElement("div"),i=e.style;return i.top="0px",i.left="0px",e.innerHTML=t,this.createCSS2DObject(e)}return this.createDefaultHotpoint()}static createLabel(t,e=""){const i=document.createElement("div");if(i.innerHTML=t,e)i.classList.add(e);else{const s=i.style;s.padding="5px 9px",s.color="#ffffffdd",s.fontSize="12px",s.position="absolute",s.backgroundColor="rgba(0, 0, 0, 0.3)",s.borderRadius="12px",s.cursor="pointer",s.top="0px",s.left="0px"}return this.createCSS2DObject(i)}static tryFindObjectId(t){if(t.dataset.objectId!=null)return parseInt(t.dataset.objectId);const e=t.parentElement;if(e&&!(e instanceof HTMLBodyElement))return this.tryFindObjectId(e)}}const an={"Precision from file":99},go=(h,t)=>h.toFixed(t===an["Precision from file"]?2:t),on="en",Ne=!1,ln=10,Ce=11,ft=12,Bs=583902,yo=[.031,.906,.867,.5],Vi=[.3,.3,.3,.8],Ls=.5,Ui=.1,Hi=5e3,hn=45,xo="x-viewer-iconfont",bo="x-viewer-iconfont2",Rs=10,Ks=new d.Vector3,$s=new d.Vector3,Js=new d.Vector3,ai=new d.Vector3,st=new d.Vector3,Qs=new d.Triangle;function vo(h,t,e,i,s){const r=[],n={};let a,o,l,c;const f=Math.pow(10,4);let m,g,x=0;for(m=0,g=h.length;m<g;m+=3)a=h[m],o=h[m+1],l=h[m+2],c=Math.round(a*f)+"_"+Math.round(o*f)+"_"+Math.round(l*f),!n[c]&&(n[c]=x/3,e[x++]=a,e[x++]=o,e[x++]=l),r[m/3]=n[c];for(m=0,g=t.length;m<g;m++)s[m]=r[t[m]],i[s[m]]=t[m]}function wo(h,t,e,i){for(let s=0,r=h;s<r;s+=3){const n=t[s]*3,a=t[s+1]*3,o=t[s+2]*3;Ks.set(e[n],e[n+1],e[n+2]),$s.set(e[a],e[a+1],e[a+2]),Js.set(e[o],e[o+1],e[o+2]),d.Triangle.getNormal(Ks,$s,Js,ai),i.push({normal:ai.clone()})}}const ss=[new d.Vector3(1,0,0),new d.Vector3(0,1,0),new d.Vector3(0,0,1),new d.Vector3(1,1,0),new d.Vector3(0,1,1),new d.Vector3(1,0,1),new d.Vector3(1,1,1),new d.Vector3(0,0,0)];function Mo(h,t){return st.addVectors(h,t),st.x===0||st.y===0||st.z===0}class cn{static buildEdge(t,e,i=Rs){const s=[],r=[],n=[];vo(t,e,s,r,n);const a=[];wo(e.length,n,s,a);const o=[],l=Math.cos(d.MathUtils.DEG2RAD*i),c={};let u=!1;for(let f=0,m=e.length;f<m;f+=3){const g=f/3;for(let x=0;x<3;x++){const y=n[f+x],T=n[f+(x+1)%3],v=Math.min(y,T),b=Math.max(y,T),E=v+","+b;c[E]===void 0?c[E]={index1:v,index2:b,face1:g,face2:void 0}:c[E].face2=g}}for(const f in c){const m=c[f];if(m.face2!==void 0){const y=a[m.face1].normal,T=a[m.face2].normal;if(y.dot(T)>l)continue}const g=r[m.index1],x=r[m.index2];(!u&&g>65535||x>65535)&&(u=!0),o.push(g),o.push(x)}return u?new Uint32Array(o):new Uint16Array(o)}static buildBarycentrics(t){const e=t.getAttribute("position");if(!e||e.count===0)return console.warn(" no positions in geometry!"),!1;const i=4,s=Math.pow(10,i),r=Math.cos(d.MathUtils.DEG2RAD*20),n=t.getIndex(),a=n?n.count:e.count,o=[0,0,0],l=new Array(3),c=ss.length,u=[];for(let M=0;M<e.count;M++)u.push({point:new d.Vector3(1,1,1),inited:!1,barycentricIndex:-1});const f={},m={},g={},x={};for(let M=0;M<a;M+=3){n?(o[0]=n.getX(M),o[1]=n.getX(M+1),o[2]=n.getX(M+2)):(o[0]=M,o[1]=M+1,o[2]=M+2);const{a:P,b:A,c:I}=Qs;if(P.fromBufferAttribute(e,o[0]),A.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),Qs.getNormal(ai),g[o[0]]?l[0]=g[o[0]]:(l[0]=Math.round(P.x*s)+","+Math.round(P.y*s)+","+Math.round(P.z*s),g[o[0]]=l[0]),g[o[1]]?l[1]=g[o[1]]:(l[1]=Math.round(A.x*s)+","+Math.round(A.y*s)+","+Math.round(A.z*s),g[o[1]]=l[1]),g[o[2]]?l[2]=g[o[2]]:(l[2]=Math.round(I.x*s)+","+Math.round(I.y*s)+","+Math.round(I.z*s),g[o[2]]=l[2]),l[0]===l[1]||l[1]===l[2]||l[2]===l[0]){S.warn(" skip degenerate triangles in geometry!");continue}const k={a:o[0],b:o[1],c:o[2]};!m[o[0]]&&(m[o[0]]=[]),m[o[0]].push(k),!m[o[1]]&&(m[o[1]]=[]),m[o[1]].push(k),!m[o[2]]&&(m[o[2]]=[]),m[o[2]].push(k);for(let B=0;B<3;B++){const L=(B+1)%3,q=l[B],me=l[L],ue=o[B],nt=o[L];!f[ue]&&(f[ue]=new Set),f[ue].add(nt),!f[nt]&&(f[nt]=new Set),f[nt].add(ue);const es=q+"_"+me,gt=me+"_"+q;if(gt in x&&x[gt]){if(x[gt].outer){S.warn("[Edge] edge: "+gt+" is already outer!");continue}ai.dot(x[gt].normal)<=r?x[gt].outer=!0:x[gt].find=!0}else es in x?S.warn("[Edge] "+es+" has existed in geometry!"):x[es]={startIndex:ue,endIndex:nt,normal:ai.clone(),outer:!1,find:!1}}}for(const M in x)x[M]&&!x[M].find&&!x[M].outer&&(x[M].outer=!0);const y=[],T=[];for(const M in m)T.push(m[M]);let v=new Set;for(const M of T[0])v.add(M.a),v.add(M.b),v.add(M.c);let b=0;for(T.splice(b,1);;){let M=!1;for(let P=0;P<T.length&&!M;P++)for(const A of T[P])if(v.has(A.a)||v.has(A.b)||v.has(A.c)){b=P,M=!0;break}if(M){for(const P of T[b])v.add(P.a),v.add(P.b),v.add(P.c);if(T.splice(b,1),b=0,T.length===0){y.push(v);break}}else if(!M)if(y.push(v),T.length>0){v=new Set;for(const P of T[b])v.add(P.a),v.add(P.b),v.add(P.c);T.splice(b,1),b=0}else break}const E=new Set;for(let M=0;M<y.length;M++)y[M].forEach(A=>{E.has(A)?S.warn("[Edge] "+A+" is already in positionIndexSet!"):E.add(A)});const O=(M,P)=>{let A=!1;const I=g[M];if(!I)return console.warn(M+" is not in positionIndexHash!"),A;const k=g[P];if(!k)return console.warn(P+" is not in positionIndexHash!"),A;const B=I+"_"+k;if(x[B])A=x[B].outer;else{const L=k+"_"+I;x[L]&&(A=x[L].outer)}return A},_=(M,P,A)=>{const I=[];return I.push(O(M,P)),I.push(O(P,A)),I.push(O(A,M)),I.filter(k=>k===!0).length>=2},C=(M,P)=>{if(!f[M])return S.warn("[Edge] "+M+" position isn't used!"),!0;const A=f[M];for(const k of A){const B=O(M,k),L=u[k];if(!L.inited)continue;const q=Mo(P,L.point);if(B&&!q||!B&&q)return!1}const I=m[M];for(const k of I){const B=P;let L=u[k.b],q=u[k.c];if(k.b===M?L=u[k.a]:k.c===M&&(q=u[k.a]),_(k.a,k.b,k.c)&&(L.inited&&B.equals(L.point)||q.inited&&B.equals(q.point)))return!1;if(!(!L.inited||!q.inited)&&(st.addVectors(B,L.point),st.add(q.point),st.x+st.y+st.z<2))return!1}return!0};let w=!1;for(let M=0;M<y.length;M++){const P=Array.from(y[M]);w=!1;let A=0,I=0;for(;I>=0;){A=P[I];let k=u[A].inited?u[A].barycentricIndex+1:0;for(;k<c&&!C(A,ss[k]);k++);if(k<c)if(u[A].inited=!0,u[A].barycentricIndex=k,u[A].point.copy(ss[k]),I==P.length-1){w=!0,S.debug("[Edge]",u);break}else I++;else u[A].inited=!1,I--}if(!w){S.warn("[Edge] no result: "+P+"!");break}}if(w){const M=[];for(let A=0;A<u.length;A++){!u[A].inited&&S.warn("[Edge] "+A+" is not initialized !");let I=0;I|=u[A].point.x,I|=u[A].point.y<<1,I|=u[A].point.z<<2,M.push(I)}const P=new d.Uint8BufferAttribute(M,1,!1);t.setAttribute("barycentric",P)}else S.warn("[Edge] No suitable barycentric found!");return w}}class mt{constructor(){p(this,"map");this.map=new Map}addEventListener(t,e){let i=this.map.get(t);i||(i=new Set,this.map.set(t,i)),i.add(e)}dispatchEvent(t,e={}){const i=this.map.get(t);if(!i)return;[...i].forEach(r=>r(e))}hasEventListener(t){return!!this.map.get(t)}removeEventListener(t,e){if(!t){this.map.clear();return}if(!e){this.map.delete(t);return}const i=this.map.get(t);i&&i.delete(e)}}const X=class X{static exportToGltf(t,e){X.exportToGltfOrGlb(t,e,{binary:!1})}static exportToGlb(t,e){X.exportToGltfOrGlb(t,e,{binary:!0})}static exportToGltfOrGlb(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");const s=new oa.GLTFExporter;i=Object.assign({},{binary:!0,onlyVisible:!1,includeCustomExtensions:!1},i),s.parse(t,n=>{if(i.binary){e=X.addExtention(e,X.EXTENSION_GLB);const a=n;X.saveArrayBuffer(a,e)}else e=X.addExtention(e,X.EXTENSION_GLTF),X.saveJson(n,e)},n=>console.log(n),i)}static exportToObj(t,e){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_OBJ);const i=new la.OBJExporter,s=i.parse(t);X.saveString(s,e)}static exportToDraco(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_DRACO);const s=new aa.DRACOExporter;i=Object.assign({},{encodeSpeed:5},i);const n=s.parse(t,i);X.saveArrayBuffer(n,e)}static exportToStl(t,e,i=!1){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_STL);const s=new ha.STLExporter;if(i){const r={binary:!0},n=s.parse(t,r);X.saveDataView(n,e)}else{const r=s.parse(t);X.saveString(r,e)}}static exportToThreeJsJson(t,e){const i=t.toJSON();e.toLowerCase().endsWith(X.EXTENSION_JSON)||(e+=X.EXTENSION_JSON),X.saveJson(i,e)}static save(t,e){let i=X.downloadLink;i||(i=document.createElement("a"),i.style.display="none",document.body.appendChild(i),X.downloadLink=i),i.href=URL.createObjectURL(t),i.download=e,i.click()}static saveArrayBuffer(t,e){X.save(new Blob([t],{type:"application/octet-stream"}),e)}static saveJson(t,e){X.saveJsonString(JSON.stringify(t),e)}static saveJsonString(t,e){X.save(new Blob([t],{type:"application/json"}),e)}static saveString(t,e){X.save(new Blob([t],{type:"text/plain"}),e)}static saveDataView(t,e){X.save(new Blob([t],{type:"application/octet-stream"}),e)}static addExtention(t,e){return t.toLowerCase().endsWith(e.toLowerCase())||(t+=e),t}};p(X,"EXTENSION_GLTF",".gltf"),p(X,"EXTENSION_GLB",".glb"),p(X,"EXTENSION_OBJ",".obj"),p(X,"EXTENSION_DRACO",".drc"),p(X,"EXTENSION_JSON",".json"),p(X,"EXTENSION_STL",".stl"),p(X,"downloadLink");let Ss=X;class To{constructor(){p(this,"prevTime");p(this,"beginTime");p(this,"frames");p(this,"fps");this.prevTime=(performance||Date).now(),this.beginTime=(performance||Date).now(),this.frames=0,this.fps=Number.NaN}begin(){this.beginTime=(performance||Date).now()}end(){this.frames++;const t=(performance||Date).now();return t>=this.prevTime+1e3&&(this.fps=Math.round(this.frames*1e3/(t-this.prevTime)),this.frames=0,this.prevTime=t),t}update(){this.beginTime=this.end()}}const rs=1e-15,er=new d.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),tr=new d.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class R{static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static floorNumber(t,e){return Math.floor(t*Math.pow(10,e))/Math.pow(10,e)}static areNumbersEqual(t,e,i=1e-7){return Math.abs(t-e)<i*Math.max(1,Math.abs(t),Math.abs(e))}static areVector2sEqual(t,e,i=1e-7){return R.areNumbersEqual(t.x,e.x,i)&&R.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return R.areNumbersEqual(t.x,e.x,i)&&R.areNumbersEqual(t.y,e.y,i)&&R.areNumbersEqual(t.z,e.z,i)}static areNumbersClose(t,e,i=1e-9,s=1e-12){return Math.abs(t-e)<=Math.max(i*Math.max(Math.abs(t),Math.abs(e)),s)}static areVector2sClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)}static areVectorsClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)&&this.areNumbersClose(t.z,e.z,i,s)}static getArcAngleSpanInRadian(t,e){const i=Math.PI*2;return R.areNumbersClose(t,e,rs)?0:(t%=i,R.areNumbersClose(t,e%i,rs)?i:(R.areNumbersClose(e,i,rs)&&(e%=i),e<t&&(e+=i),e-t))}static getIntegerPartLength(t){return t=Math.abs(t),t<1?0:Math.ceil(Math.log10(Math.abs(t)+1))}static getRelativeEps(t,e=1e-7){const i=R.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(R.getRelativeEps(t.x,e),R.getRelativeEps(t.y,e))}static getControlPointByTwoPoints(t,e){const i=new d.Vector2().subVectors(e,t),s=i.angle(),r=i.length(),n=d.MathUtils.degToRad(45),a=r/2/Math.cos(n);return new d.Vector2(t.x+a*Math.cos(n-s),t.y-a*Math.sin(n-s))}static convertPointFromUEToGltf(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(er.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(er),e}static convertPointFromUEToRevit(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(tr.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(tr),e}static getBox(t,e){const i=[Math.min(t.x,e.x),Math.min(t.y,e.y),Math.min(t.z,e.z)],s=[Math.max(t.x,e.x),Math.max(t.y,e.y),Math.max(t.z,e.z)];return[...i,...s]}static getCenter(t){const e=new d.Vector3(t.min.x,t.min.y,t.min.z),i=new d.Vector3(t.max.x,t.max.y,t.max.z),s=new d.Vector3().addVectors(e,i).multiplyScalar(.5);return{x:s.x,y:s.y,z:s.z}}static convertBoxFromGltfToUE(t){const e=R.convertPointFromGltfToUE(t.min),i=R.convertPointFromGltfToUE(t.max);return R.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=R.convertPointFromUEToGltf(t.min),i=R.convertPointFromUEToGltf(t.max);return R.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=R.convertPointFromRevitToUE(t.min),i=R.convertPointFromRevitToUE(t.max);return R.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=R.convertPointFromUEToRevit(t.min),i=R.convertPointFromUEToRevit(t.max);return R.getBox(e,i)}static clamp(t,e,i){return Math.max(e,Math.min(i,t))}static getLookAtMatrix(t,e,i){const s=new d.Matrix4,r=new d.Vector3(t.x,t.y,t.z),n=new d.Vector3(e.x,e.y,e.z),a=new d.Vector3(i.x,i.y,i.z);s.lookAt(r,n,a),s.transpose();const o=[];return s.toArray(o),o}static getLocationFromMatrix(t){const e=new d.Vector3;return e.setFromMatrixPosition(t),e}static toDegrees(t){return d.MathUtils.radToDeg(t)}static toRadians(t){return d.MathUtils.degToRad(t)}static signNotZero(t){return t<0?-1:1}static fromSnorm(t,e){return R.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=R.fromSnorm(t.x,i),e.y=R.fromSnorm(t.y,i),e.z=1-(Math.abs(e.x)+Math.abs(e.y)),e.z<0){const s=e.x;e.x=(1-Math.abs(e.y))*R.signNotZero(s),e.y=(1-Math.abs(s))*R.signNotZero(e.y)}}}const ns=1e7,ir=new d.Box2,sr=new d.Box2,rr=new d.Vector3,nr=new d.Vector3,ar=new d.Vector3,at=new d.Triangle;class U{static geometriesEqual(t,e){return t===e?!0:t.type===e.type&&t.name===e.name&&t.morphTargetsRelative===e.morphTargetsRelative&&this.equal(t.boundingBox,e.boundingBox)&&this.equal(t.boundingSphere,e.boundingSphere)&&this.attributesEqual(t.attributes,e.attributes)&&this.bufferAttributesEqual(t.index,e.index)}static equal(t,e){return t===e||!t&&!e?!0:t&&e?t.equals(e):!1}static attributesEqual(t,e){if(t===e)return!0;const i=Object.keys(t).sort(),s=Object.keys(e).sort();if(i.length!==s.length)return!1;for(let r=0;r<i.length;++r){if(i[r]!==s[r])return!1;const n=t[i[r]],a=e[s[r]];if(!this.bufferAttributesEqual(n,a))return!1}return!0}static bufferAttributesEqual(t,e){if(t===e)return!0;if(!t||!e||!(t.name===e.name&&t.itemSize===e.itemSize&&t.count===e.count&&t.normalized===e.normalized))return!1;if(t.array&&e.array){if(t.array.length!==e.array.length)return!1;for(let n=0;n<t.array.length;++n)if(t.array[n]!==e.array[n])return!1}else if(t.array||e.array)return!1;const s=t.data,r=e.data;if(s&&r){if(s.length!==r.length)return!1;for(let n=0;n<s.length;++n)if(s[n]!==r[n])return!1}else if(s||r)return!1;return!0}static tryConvertInterleavedBufferAttributes(t){!t||!t.attributes||Object.keys(t.attributes).forEach(e=>{const i=t.attributes[e];if(i instanceof d.InterleavedBufferAttribute){const s=i.clone();t.attributes[e]=s}})}static isPointInPolygon(t,e,i=!1){const s=t.x,r=t.y;let n=!1;const a=e.length;for(let o=0,l=a-1;o<a;l=o++){const c=e[o].x,u=e[o].y,f=e[l].x,m=e[l].y;let g=u>r!=m>r;i&&(g=u>=r!=m>=r),g&&s<(f-c)*(r-u)/(m-u)+c&&(n=!n)}return n}static caculateGeometryCenter(t){if(!t.hasAttribute("position"))return null;const e=t.getAttribute("position");if(e.count===0)return null;const i=new d.Vector3,s=e.itemSize,r=e.array,n=[0,0,0];for(let a=0;a<e.count;a++)for(let o=0;o<s;o++)n[o]+=r[a*s+o];for(let a=0;a<s;a++)i.setComponent(a,n[a]/e.count);return i}static isConvex(t){const e=t.length;let i=0,s=0;const r=new d.Vector2,n=new d.Vector2;for(let a=0;a<e;++a){const o=t[a],l=t[(a+1)%e],c=t[(a+2)%e];if(r.subVectors(l,o),n.subVectors(c,l),s=r.cross(n),s!=0){if(s>0&&i<0||s<0&&i>0)return!1;i=s}}return!0}static areLineSegmentsIntersecting(t,e){const{start:i,end:s}=t,{start:r,end:n}=e,a=r.clone().sub(i),o=s.clone().sub(i),l=n.clone().sub(i),c=a.cross(o).dot(l.cross(o)),u=i.clone().sub(r),f=n.clone().sub(r),m=s.clone().sub(r),g=u.cross(f).dot(m.cross(f));return c<0&&g<0}static getLineSegmentsIntersectingPoint(t,e){const{start:i,end:s}=t,{start:r,end:n}=e,a=rr.subVectors(s,i).normalize(),o=nr.subVectors(n,r).normalize();if(a.dot(o)===1)return null;const l=ar.subVectors(r,i),c=a.clone().cross(o),u=l.clone().cross(o),f=l.clone().dot(c);if(f>=1e-5||f<=-1e-5)return null;const m=c.lengthSq();if(R.areNumbersEqual(0,m))return;const g=u.clone().dot(c)/m,x=i.clone().add(a.multiplyScalar(g));return x.equals(i)||x.equals(s)?null:x}static isPointOnLineSegment(t,e,i=.001){const{start:s,end:r}=e,n=rr.subVectors(s,r).length(),a=nr.subVectors(t,s).length(),o=ar.subVectors(t,r).length();return Math.abs(n-(a+o))<=i}static isPointOnLineSegments(t,e,i=.001){let s=!1;for(let r=0;r<e.length-1;r+=2){const n=e[r],a=e[r+1];if(s=this.isPointOnLineSegment(t,{start:n,end:a},i),s)break}return s}static checkAndRebasePositionsOnRTC(t,e){if(t.length===0)return!1;const i=t[0]instanceof d.Vector3;t.forEach(r=>{i?e.add(r):(e.x+=r.x,e.y+=r.y)}),e.divideScalar(t.length);let s=!1;if(U.shouldRebasePositionOnRTC(e)){s=!0;for(let r=0;r<t.length;r++){const n=t[r].x-e.x,a=t[r].y-e.y;i?t[r]=new d.Vector3(n,a,t[r].z-e.z):t[r]=new d.Vector2(n,a)}}else e.setScalar(0);return s}static shouldRebasePositionOnRTC(t){return Math.abs(t.x)>ns||Math.abs(t.y)>ns||t instanceof d.Vector3&&Math.abs(t.z)>ns}static calculateSurfaceArea(t){let e=0;const i=t.getAttribute("position"),s=t.index;if(s)for(let r=0;r<s.count;r+=3)at.a.fromBufferAttribute(i,s.getX(r)),at.b.fromBufferAttribute(i,s.getX(r+1)),at.c.fromBufferAttribute(i,s.getX(r+2)),e+=at.getArea();else for(let r=0;r<i.count;r+=3)at.a.fromBufferAttribute(i,r),at.b.fromBufferAttribute(i,r+1),at.c.fromBufferAttribute(i,r+2),e+=at.getArea();return e}static convertLineStripToLine(t,e=!1){const i=t.getIndex();if(!i)return;const s=i.array.constructor,r=i.count;let n=r;r>2&&(n=e?r*2:r*2-2);const a=new s(n);let o=0;for(let l=0;l<r;l++){const c=i.getX(l);a[o++]=c,l>0&&l<r-1&&(a[o++]=c)}e&&(a[o++]=i.getX(r-1),a[o++]=i.getX(0)),t.setIndex(a)}static convertGeometryWithIndexedToNonIndexed(t){if(!t.index)return t;const e=new d.BufferGeometry,i=t.index;for(const s in t.attributes)e.setAttribute(s,U.createGeometryAttributeByIndex(t.attributes[s],i));return e}static createGeometryAttributeByIndex(t,e){const i=e.count,s=t.itemSize,r=t.array.constructor,n=new r(i*s);for(let a=0;a<i;a++){const o=e.getX(a),l=o*s;for(let c=0;c<s;c++)n[a*s+c]=t.array[l+c]}return new d.BufferAttribute(n,s,t.normalized)}static getLineEndPointsByIndex(t,e){const i=l=>{const c=t.geometry.attributes.position,u=c.array;return t.localToWorld(new d.Vector3(u[3*l],u[3*l+1],u[3*l+2]))};t.updateWorldMatrix(!0,!1);const s=t.geometry.getIndex()?.array||[],r=s[e]??e,n=s[e+1]??e+1,a=i(r),o=i(n);return[a,o]}static arePolygonsIntersect(t,e){if(t.length===0||e.length===0||(ir.setFromPoints(t),sr.setFromPoints(e),!ir.intersectsBox(sr)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&R.areVector2sEqual(t[i+1],t[i])&&++i,++i}return!1}static getLineLineIntersectionPoint(t,e,i,s,r=.001){const n=e.clone().sub(t).normalize(),a=s.clone().sub(i).normalize();if(Math.abs(n.dot(a))>1-r)return;const o=e.y-t.y,l=t.x-e.x,c=o*t.x+l*t.y,u=s.y-i.y,f=i.x-s.x,m=u*i.x+f*i.y,g=o*f-u*l;if(Math.abs(g)<r)return;const x=(f*c-l*m)/g,y=(o*m-u*c)/g;return new d.Vector2(x,y)}static getOffsetPoint(t,e,i){const s=e.x-t.x,r=e.y-t.y,n=Math.sqrt(s*s+r*r),a=i/n;return new d.Vector2(-a*r,a*s)}static convertSimpleWidthLineToMeshGeometry(t,e){let i,s=!1,r=!1,n=[],a=[],o,l,c=new d.Vector2,u=new d.Vector2,f=new d.Vector2,m=new d.Vector2;const g=[],x=e/2;for(let b=0,E=t.length-1;b<E;b++)s=!b,r=b===t.length-2,i=this.getOffsetPoint(t[b],t[b+1],x),c=new d.Vector2(t[b].x+i.x,t[b].y+i.y),u=new d.Vector2(t[b+1].x+i.x,t[b+1].y+i.y),f=new d.Vector2(t[b].x-i.x,t[b].y-i.y),m=new d.Vector2(t[b+1].x-i.x,t[b+1].y-i.y),s||(o=this.getLineLineIntersectionPoint(n[0],n[1],c,u),o!==void 0?g.unshift(o):g.unshift(c),l=this.getLineLineIntersectionPoint(a[0],a[1],f,m),l!==void 0?g.push(l):g.push(f)),s&&(g.unshift(c),g.push(f)),r&&(g.unshift(u),g.push(m)),r||(n=[c,u],a=[f,m]);if(g.length<3)return;const y=d.ShapeUtils.triangulateShape(g,[]),T=[];for(let b=0;b<y.length;b++)T.push(...y[b]);const v=new d.BufferGeometry().setFromPoints(g);return v.setIndex(T),v}static convertWidthLineToMeshGeometry(t,e){if(t.length<2)return;const i=[];t.forEach(s=>{i.push([s.x,s.y])});try{const{indices:s,position:r}=ca.extrudePolylines([i],{lineWidth:e,depth:1}),n=new d.BufferGeometry;return n.setAttribute("position",new d.Float32BufferAttribute(r,3)),n.setIndex(Array.from(s)),n}catch{return}}static releaseGeometryManually(t){t.index=null,t.attributes={}}static getAdjacentNonRepeatPoints(t,e=1e-7){const i=[],s=t.length;for(let r=0;r<s-1;r++)R.areVector3sEqual(t[r],t[r+1],e)||i.push(t[r]);return i.push(t[s-1]),i}static mergeBBoxes(t){const e=[...t];if(e.length<2)return e;const i=[],s=[];for(let r=0;r<e.length;r++){const n=e[r];if(!s.includes(r)){for(let a=0;a<e.length;a++){const o=e[a];n.equals(o)||n.intersectsBox(o)&&(n.union(o),s.push(a))}i.push(n)}}return i}}const Co={ProgressBar:{Loading:"Loading",Comparing:"Comparing"},Tooltip:{boxSelect:"Box select an area to confirm the screenshot range",pickMarkup:"Click on a markup to confirm the screenshot range"}},Os={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"}},Re=da.createInstance(),So="cn";Re.init({lng:So,debug:!1,resources:{en:{translation:Os},cn:{translation:Os}}});class de{static materialEquals(t,e){if(t===e)return!0;if(t.type!==e.type)return!1;if(t instanceof d.Material&&e instanceof d.Material){const i=t,s=e;return i.alphaTest===s.alphaTest&&i.opacity===s.opacity&&i.side===s.side&&i.visible===s.visible&&i.name===s.name&&i.transparent===s.transparent&&this.colorEquals(i.color,s.color)&&this.colorEquals(i.emissive,s.emissive)&&i.roughness===s.roughness&&i.metalness===s.metalness&&i.alphaMap===s.alphaMap&&i.uniforms===s.uniforms&&i.defines===s.defines&&i.vertexShader===s.vertexShader&&i.fragmentShader===s.fragmentShader&&i.clippingPlanes===s.clippingPlanes&&i.map===s.map&&i.clipIntersection===s.clipIntersection}return!1}static materialsEquals(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)&&t.length===e.length){for(let i=0;i<t.length;++i)if(!this.materialEquals(t[i],e[i]))return!1;return!0}else if(t instanceof d.Material&&e instanceof d.Material)return this.materialEquals(t,e);return!1}static colorEquals(t,e){return t===e?!0:t instanceof d.Color&&e instanceof d.Color?t.equals(e):!1}static clonedHighlightMaterials(t,e={}){if(!t||!t.material)return;const i=t.material;if(Array.isArray(i)&&i.length>0){const s=[];return i.forEach(r=>{s.push(this.clonedHighlightMaterial(r,e))}),s}else{if(i instanceof d.Material)return this.clonedHighlightMaterial(i,e);console.warn("[MaterialUtils] Invalid material: "+i)}}static clonedHighlightMaterial(t,e={}){const{depthTest:i=void 0,highlightColor:s=new d.Color(Bs),opacity:r=.7}=e,n=t.clone();return this.setMaterialColor(n,s),n.opacity=r,n.transparent=!0,i!==void 0&&(n.depthTest=i,n.side=d.DoubleSide),n}static cloneMaterial(t){if(!t)return t;if(Array.isArray(t)){const e=[];return t.forEach(i=>{e.push(i.clone())}),e}return t.clone()}static getMaterialColor(t){let e=new d.Color(16777215);return t instanceof d.PointsMaterial||t instanceof d.LineBasicMaterial||t instanceof d.MeshBasicMaterial?e=t.color:t instanceof d.ShaderMaterial&&t.uniforms.u_color&&(e=t.uniforms.u_color.value),e}static setMaterialColor(t,e){const i=t;i.color?.set(e),i.emissive?.set(e),i.uniforms?.u_color&&i.uniforms.u_color.value.set(e)}static setMaterialOpacity(t,e){const i=t;i.transparent=!0,i.opacity=e,i.uniforms?.opacity&&(i.uniforms.opacity.value=e)}static cloneMaterials(t){const e=new Map,i=s=>{if(Array.isArray(s)){const r=[];return s.forEach(n=>{let a=e.get(n);a||(a=n.clone(),e.set(n,a)),r.push(a)}),r}if(s){let r=e.get(s);return r||(r=s.clone(),e.set(s,r)),r}return s};t.traverse(s=>{const r=s;r.material&&(r.material=i(r.material))})}}const Oo=new d.Vector3(0,1,0),ke=class ke{static resetObjectStyle(t){this.revertWireframeMode(t),this.revertObjectOpacity(t,[]),this.revertAppliedMaterialToObject(t),this.revertVisibleForFloors(t)}static resetObjectStyleById(t,e){const i=this.getObjectById(t,e);this.resetObjectStyle(i)}static setObjectOpacity(t,e=.3,i,s){const r=[],n=o=>{r.find(l=>l.id===o.id)||(r.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side}),o.opacity*=e,o.transparent=!0,o.side=d.DoubleSide)},a=o=>{const l=r.find(c=>c.id===o.id);if(!l){const c=o.clone();return r.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side,material:o,clonedMaterial:c}),c.opacity*=e,c.transparent=!0,c}return l.clonedMaterial};return t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof d.Mesh){const l=o;if(i||s){if(Array.isArray(l.material)){const c=[];l.material.forEach(u=>{const f=a(u);f&&c.push(f)}),l.material=c}else if(l.material){const c=a(l.material);c&&(l.material=c)}}else if(Array.isArray(l.material))l.material.forEach(c=>{n(c)});else if(l.material){const c=l.material;n(c)}}}),r}static revertObjectOpacity(t,e,i,s){const r=new Set,n=o=>{if(!o||o.id==null||r.has(o.id))return;r.add(o.id);const l=e.find(c=>c.id===o.id);l&&(o.opacity=l.opacity,o.transparent=l.transparent,o.side=l.side,o.opacity===0&&S.warn("[ObjectUtils] Material '"+o.name+"'s opacity is 0, you may not be able to see your objects!"))},a=o=>{const l=e.find(c=>c.clonedMaterial&&c.clonedMaterial.id===o.id);if(l)return l.material};t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof d.Mesh){if(Array.isArray(o.material)){const l=[];o.material.forEach(c=>{const u=a(c);u?l.push(u):n(c)}),o.material=l}else if(o.material){const l=a(o.material);l?o.material=l:n(o.material)}}})}static setObjectOpacityById(t,e,i=.3,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);return ke.setObjectOpacity(n,i,s,r)}static revertObjectOpacityById(t,e,i,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);ke.revertObjectOpacity(n,i,s,r)}static applyMaterialToObject(t,e,i,s){t.traverse(r=>{s&&s.indexOf(r.id)!==-1||i&&i.indexOf(r.id)===-1||r instanceof d.Mesh&&(r.userData.originalMaterial||(r.userData.originalMaterial=r.material),r.material=e)})}static revertAppliedMaterialToObject(t,e,i){t.traverse(s=>{i&&i.indexOf(s.id)!==-1||e&&e.indexOf(s.id)===-1||s.userData.originalMaterial&&(s.material=s.userData.originalMaterial,s.userData.originalMaterial=void 0)})}static applyMaterialToObjectById(t,e,i,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);this.applyMaterialToObject(n,i,s,r)}static revertAppliedMaterialToObjectById(t,e,i,s){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);this.revertAppliedMaterialToObject(r,i,s)}static applyOpacityMaterialToObject(t,e,i){const s=new d.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});this.applyMaterialToObject(t,s,e,i)}static setDoubleSidedMaterialToObject(t){const e=i=>{i.side!==d.DoubleSide&&(i.userData.originalSide==null&&(i.userData.originalSide=i.side),i.side=d.DoubleSide)};t.traverse(i=>{i instanceof d.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof d.Material&&e(i.material))})}static revertDoubleSidedMaterialToObject(t){const e=i=>{i.userData.originalSide!=null&&(i.side=i.userData.originalSide,i.userData.originalSide=void 0)};t.traverse(i=>{i instanceof d.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof d.Material&&e(i.material))})}static setWireframeMode(t){const e=new d.MeshBasicMaterial({color:16732160,wireframe:!0,transparent:!0,opacity:.8});t.traverseVisible(i=>{if(i instanceof d.Mesh){const s=i;s.userData.materialForWireframe=s.material,s.material=e}})}static setWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);ke.setWireframeMode(i)}static revertWireframeMode(t){t.traverseVisible(e=>{e instanceof d.Mesh&&e.userData.materialForWireframe&&(e.material=e.userData.materialForWireframe,e.userData.materialForWireframe=void 0)})}static revertWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);ke.revertWireframeMode(i)}static findInner(t,e,i=[],s=!1){const r=e.toLowerCase(),n=[],a=c=>c.toLowerCase().indexOf(r)!==-1,o=c=>c.toString().indexOf(r)!==-1,l=c=>{if(c.name&&c.name.toLowerCase().indexOf(r)!==-1)return!0;if(c.gltfExtensions){const u=c.gltfExtensions,f=u.objectId&&u.objectId.Value||u.elementId&&u.elementId.Value;if(f&&f.toLowerCase().indexOf(r)!==-1)return!0}return!1};if(i.length>0)for(let c=0;c<i.length;++c){const u=i[c],f=t.getObjectById(u);if(f&&f.traverse(m=>{(a(m.name)||o(m.id)||l(m.userData))&&n.push(m)}),s&&n.length>0)return[n[0]]}else if(t.traverse(c=>{(a(c.name)||o(c.id)||l(c.userData))&&n.push(c)}),s&&n.length>0)return[n[0]];return n}static find(t,e,i=[],s=!1){return this.findInner(t,e,i,s)}static findFirst(t,e,i=[],s=!1){const r=this.findInner(t,e,i,s);if(r.length>0)return r[0]}static getFloorsFromString(t){const e=[],s=new RegExp(/(?:-?(?:\d+(?:\.5)?)F)(?=\W|$)/,"g").exec(t);return s&&s.length>0&&s.forEach(r=>{if(r){const n=r.replace("F",""),a=Number(n);a?e.push(a):console.log("[OU] invalid floor: "+r)}}),e}static matchFloor(t,e){return this.getFloorsFromString(t).findIndex(r=>r===e)!==-1}static matchFloors(t,e){return this.getFloorsFromString(t).findIndex(r=>e.findIndex(a=>a===r)!==-1)!==-1}static distinctFloors(t,e){const i=[],s=r=>{this.getFloorsFromString(r).forEach(a=>{i[a]=!0})};return e.forEach(r=>{const n=t.getObjectById(r);n&&n.traverse(a=>{if(s(a.name),a.userData.gltfExtensions){const o=a.userData.gltfExtensions;o.level&&o.level.Value&&s(o.level.Value)}})}),Object.keys(i).sort()}static traverseObjectByFloors(t,e,i,s,r){const n=t.getObjectById(e);if(!n)return[];n.traverse(a=>{let o=this.matchFloors(a.name,i);if(!o&&a.userData&&a.userData.gltfExtensions){const l=a.userData.gltfExtensions;l.level&&l.level.Value&&(o=this.matchFloors(l.level.Value,i))}o&&s&&s(a),!o&&r&&r(a)})}static setVisibleForFloors(t,e,i,s=!0){this.traverseObjectByFloors(t,e,i,r=>{let n=r;for(;n;)n.visible=!0,n=n.parent||void 0},r=>{s&&(r.visible=!1)})}static revertVisibleForFloors(t){t.traverse(e=>{e.visible=!0})}static revertVisibleForFloorsById(t,e){const i=this.getObjectById(t,e);this.revertVisibleForFloors(i)}static getObjectById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);return i}static async createOutlines(t,e={onlyVisible:!0,meshOnly:!0},i){if(!t)return[];if(t.children.length===0&&(e.onlyVisible&&!t.visible||e.meshOnly&&!(t instanceof d.Mesh)))return[];const s=[],r=t,n=r.children.length,a=Math.round(Math.pow(n,.5)),o=z.getUpdateProgressFuncAsync(i);for(let l=n-1;l>=0;--l){const c=n-l-1;let u;if(i&&(c%a===0||c===0||c===n-1)){const g=c*90/n,x=(c+1)*90/n;u=z.getUpdateSubProgressFunc(g,x,i)}const f=r.children[l],m=await this.createOutlines(f,e,u);s.push(...m)}if(!r.geometry)return await o(100),s;if(r instanceof d.Mesh&&!this.hasOutline(r,!1)){await o(50);const l=this.createOutline(r.geometry);r.add(l),l.updateWorldMatrix(!0,!1),s.push(l)}return await o(100),s}static removeOutlines(t){if(!(!t||!Array.isArray(t.children)))for(let e=t.children.length-1;e>=0;--e){const i=t.children[e];i.children.length>0&&this.removeOutlines(i),i.userData.isOutline&&t.remove(i)}}static hasOutline(t,e=!0){let i=!1;for(let s=0;s<t.children.length;++s){const r=t.children[s];if(r.userData.isOutline){i=!0;break}if(e&&r.children.length>0&&(i=this.hasOutline(r),i))break}return i}static setOutlinesVisibility(t,e){t.traverse(i=>{i.userData.isOutline&&(i.visible=e)})}static createOutline(t,e=this.OUTLINE_MATERIAL,i){const s=new d.EdgesGeometry(t,Rs),r=new d.LineSegments(s,e);return r.layers.enableAll(),ke.disableLayerChannels(r,[ft,Ce]),r.userData.isOutline=!0,r.matrixAutoUpdate=Ne,i&&r.applyMatrix4(i),r}static cloneObject(t,e=!0){const i=t.clone();return e&&i.traverse(s=>{if(s instanceof d.Mesh||s instanceof d.Line){const r=s;r.material=de.cloneMaterial(r.material)}}),i}static createBox(t,e,i,s=this.BOX_FACE_MATERIAL,r=!0){const n=[],a=(c,u,f)=>{n.push(new d.Vector3(c,u,f))};a(0,0,0),a(t,0,0),a(t,e,0),a(0,e,0),a(0,0,i),a(t,0,i),a(t,e,i),a(0,e,i);const o=new d.BufferGeometry;o.setFromPoints(n);const l=[0,3,2,0,2,1,4,6,7,4,5,6,0,7,3,0,4,7,3,6,2,3,7,6,1,6,5,1,2,6];return r&&l.push(0,5,4,0,1,5),o.setIndex(l),o.computeVertexNormals(),new d.Mesh(o,s)}static rebaseObjectOnRTC(t){const e=t;if(!(e.isMesh||e.isLine||e.isPoints)||!e.geometry||!(e.geometry instanceof d.BufferGeometry))return t;const i=e.geometry;if(!i.hasAttribute("position"))return t;const s=i.getAttribute("position");if(s.count===0)return t;const r=s.itemSize,n=s.array,a=[];for(let c=0;c<r;c++)a.push(n[c]);for(let c=0;c<s.count;c++)for(let u=0;u<r;u++)n[c*r+u]-=a[u];t.updateMatrix();const o=t.matrix.clone();t.matrix.makeTranslation(a[0],a[1],a.length>2?a[2]:0);const l=t.matrixAutoUpdate;return t.matrixAutoUpdate=!1,t.applyMatrix4(o),t.matrixAutoUpdate=l,t}static isEmptyObject(t){if(t.children.length===0){const i=t.geometry;if(!i||!i.hasAttribute("position")||i.getAttribute("position").count===0)return!0}return!1}static removeEmptyObjects(t){for(let e=0;e<t.children.length;)this.removeEmptyObjects(t.children[e])||++e;return this.isEmptyObject(t)?(t.removeFromParent(),!0):!1}static removeEmptyObjectsFromRemovingObjects(t,e){t.length!==0&&(t.forEach(i=>{i.removeFromParent()}),this.removeEmptyObjects(e))}static setSharedVariablesOfObject(t){t.uuid="",t.up=Oo;const e=t;e.material&&(Array.isArray(e.material)?e.material.forEach(i=>{i.uuid&&(i.uuid="")}):e.material.uuid&&(e.material.uuid=""))}static isLeafObject(t){return!(t instanceof d.Mesh)&&!(t instanceof d.Line)&&!(t instanceof d.Points)?!1:!!t.geometry}static enableLayerChannels(t,e,i=!0){for(let s=0,r=e.length;s<r;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.enableLayerChannels(s[r],e,!0)}}static disableLayerChannels(t,e,i=!0){for(let s=0,r=e.length;s<r;s++)t.layers.disable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.disableLayerChannels(s[r],e,!0)}}static setLayerChannels(t,e,i=!0){t.layers.disableAll();for(let s=0,r=e.length;s<r;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.setLayerChannels(s[r],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(ln)}static isObjectSnapable(t){return t.layers.isEnabled(Ce)}static isObjectSelectable(t){return t.layers.isEnabled(ft)}};p(ke,"OUTLINE_MATERIAL",new d.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),p(ke,"BOX_FACE_MATERIAL",new d.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:d.FrontSide}));let $=ke;const Si=new d.Matrix4,Eo=new d.Matrix4,di=class di{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},r=[];for(let c=0;c<i;++c){const u=t.children[c];if(u.children.length>0){this.mergeInner(u,e);continue}if(u.isInstancedMesh||!u.geometry||!(u.geometry instanceof d.BufferGeometry))continue;let f=!1;const m=Object.values(s);for(let g=m.length-1;g>=0;--g){const x=m[g].indexes[0];if(f=this.tryHandleMergeableObjects(t,c,x,s,r),f)break}for(let g=r.length-1;!f&&g>=0;--g){const x=r[g];if(f=this.tryHandleMergeableObjects(t,c,x,s,r),f)break}!f&&r.push(c)}if(Object.keys(s).length<=0)return;const n=[],a=[],o=[],l=[];Object.values(s).forEach(c=>{const u=c.indexes,f=t.children[u[0]];let m=[],g=0,x=0,y=0;const T=[];if(u.forEach(b=>{const E=t.children[b],O=E.geometry.clone();if(O.applyMatrix4(E.matrix),U.tryConvertInterleavedBufferAttributes(O),O.userData.isLineSegments=E.isLineSegments===!0,m.push(O),e){const _=E.name,C=O.attributes?.position?.count,w=O.index?.count||0,M={batchId:g,name:_,positionStart:x,positionCount:C,indexStart:y,indexCount:w};Object.keys(E.userData).length!==0&&(M.userData=E.userData),T.push(M),x+=C,y+=w,g++}}),m.length===0)return;let v;if(f.isMesh){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new d.Mesh(b,f.material),n.push(v)}else if(f.isLine){const b=this.mergeLineGeometries(m,e,f.material instanceof d.LineDashedMaterial||f.material instanceof d.ShaderMaterial,T);if(!b)return;v=new d.LineSegments(b,f.material),a.push(v)}else if(f.isPoints){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new d.Points(b,f.material),o.push(v)}v&&(e?v.userData.batches=T:(v.userData=f.userData,v.userData.batches=void 0),v.userData.layerName=f.userData.layerName,v.name="[Merged] "+f.name,v.matrixAutoUpdate=Ne,v.renderOrder=f.renderOrder,v.layers.mask=f.layers.mask,v.visible=f.visible,l.push(...u)),m.forEach(b=>{b.dispose(),U.releaseGeometryManually(b)}),m=[]}),l.sort((c,u)=>u-c),l.forEach(c=>{const u=t.children[c];t.remove(u)}),[...n,...a,...o].forEach(c=>{t.add(c)}),t.updateMatrix(),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=n.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,r){let n=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return n;const l=a?t[e]:t.children[e],c=a?t[i]:t.children[i];return this.areObjectsMergeable(l,c)&&this.areGeometriesMergeable(l.geometry,c.geometry)&&de.materialsEquals(l.material,c.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(r,i)),s[i].indexes.push(e),n=!0),n}static deepMerge(t,e=void 0,i=!0,s=!0,r=!0){const n={added:[],removed:[]};if(t.length<=1)return n;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){const T=t[y];if(T.isInstancedMesh||!T.geometry||!(T.geometry instanceof d.BufferGeometry))continue;let v=!1;const b=Object.values(o);for(let E=b.length-1;E>=0;--E){const O=b[E].indexes[0];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}for(let E=l.length-1;!v&&E>=0;--E){const O=l[E];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}!v&&l.push(y)}if(Object.keys(o).length<=0)return n;S.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const c=[],u=[],f=[],m=[];Object.values(o).forEach(y=>{const T=y.indexes;if(T.length<2)return;const v=t[T[0]];let b=[],E=0,O=0,_=0;const C=[];if(T.forEach(M=>{const P=t[M],A=P.geometry.clone();if(v.material instanceof d.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,P,e),A.userData.isLineSegments=P.isLineSegments===!0,b.push(A),r){const I=P.name,k=A.attributes?.position?.count,B=A.index?.count||0;let L;v.isLine&&(!A.boundingSphere&&A.computeBoundingSphere(),L=A.boundingSphere.clone());const q={batchId:E,name:I,positionStart:O,positionCount:k,indexStart:_,indexCount:B,boundingSphere:L};!P.parent.geometry&&Object.keys(P.parent.userData).length!==0&&(q.parentUserData=P.parent.userData),Object.keys(P.userData).length!==0&&(q.userData=P.userData),C.push(q),O+=k,_+=B,E++}}),b.length===0)return;let w;if(v.isMesh){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new d.Mesh(M,v.material),c.push(w)}else if(v.isLine){const M=this.mergeLineGeometries(b,r,v.material instanceof d.LineDashedMaterial||v.material instanceof d.ShaderMaterial,C);if(!M)return;w=new d.LineSegments(M,v.material),u.push(w)}else if(v.isPoints){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new d.Points(M,v.material),f.push(w)}w&&(r?w.userData.batches=C:(w.userData=v.userData,w.userData.batches=void 0),w.userData.layerName=v.userData.layerName,w.name="[Merged] "+v.name,w.matrixAutoUpdate=Ne,w.renderOrder=v.renderOrder,w.layers.mask=v.layers.mask,w.visible=v.visible,T.forEach(M=>m.push(M))),b.forEach(M=>{M.dispose(),U.releaseGeometryManually(M)}),b=[]}),S.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const g=n.removed;m.forEach(y=>{const T=t[y];g.push(T),i&&T.removeFromParent()});const x=n.added;return[...c,...u,...f].forEach(y=>{x.push(y),i&&e&&(e.add(y),y.updateWorldMatrix(!1,!1))}),this.MergeInfo.removedObjects+=m.length,this.MergeInfo.mergedMeshes+=c.length,this.MergeInfo.mergedLines+=u.length,this.MergeInfo.mergedPoints+=f.length,s&&e&&$.removeEmptyObjects(e),n}static applyMatrix(t,e,i){let s=e;for(Si.identity();s&&s!==i&&(Si.premultiply(s.matrix),!!s.parent);)s=s.parent;return Si.equals(Eo)?t:t.applyMatrix4(Si)}static mergeLineGeometries(t,e,i,s){let r;if(i)r=di.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(r=xe.mergeGeometries(t),!r)return;r.userData={};const n=[];let a=0;t.forEach((o,l)=>{const c=o.attributes.position;if(!c)return;const u=o.index,f=o.userData.isLineSegments===!0,m=n.length;if(u)for(let g=0;g<u.count;g++){const x=u.array[g];f?n.push(a+x):g>0&&n.push(a+u.array[g-1],a+x)}else for(let g=0;g<c.count;g++)g>0&&(f?g%2===1&&n.push(a+g-1,a+g):n.push(a+g-1,a+g));a+=c.count,e&&s&&(s[l].indexStart=m,s[l].indexCount=n.length-m)}),r.setIndex(n)}return r}static mergeBufferGeometriesWithLinesToLineSegments(t,e,i){const s=new Set(Object.keys(t[0].attributes)),r={},n=new d.BufferGeometry,a=[];let o=0;for(let l=0;l<t.length;++l){let c=t[l];const u=c.userData.isLineSegments===!0;a.push(u),c.index&&(S.debug("[Merge] Geometry '"+l+"' contains index buffer, going to convert it to non-indexed."),c=U.convertGeometryWithIndexedToNonIndexed(c));let f=0;for(const m in c.attributes){if(!s.has(m))return S.error("[Merge] mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure "+m+" attribute exists among all geometries, or in none of them"),void 0;!r[m]&&(r[m]=[]),r[m].push(c.attributes[m]),f++}if(f!==s.size)return S.error("[Merge] mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),void 0;if(e&&i){const m=c.attributes.position;i[l].indexStart=0,i[l].indexCount=0;const g=u?m.count:m.count*2-2;i[l].positionStart=o,i[l].positionCount=g,o+=g}}for(const l in r){const c=di.mergeBufferAttributesWithLinesToLineSegments(r[l],a);if(!c)return S.error("[Merge] mergeGeometries() failed while trying to merge the "+l+" attribute."),void 0;n.setAttribute(l,c)}return n}static mergeBufferAttributesWithLinesToLineSegments(t,e){let i,s,r,n=0;for(let l=0;l<t.length;++l){const c=t[l];if(i===void 0&&(i=c.array.constructor),i!==c.array.constructor)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.array must be of consistent array types across matching attributes."),void 0;if(s===void 0&&(s=c.itemSize),s!==c.itemSize)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.itemSize must be consistent across matching attributes."),void 0;if(r===void 0&&(r=c.normalized),r!==c.normalized)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.normalized must be consistent across matching attributes."),void 0;const u=e[l],f=u?0:c.count-2,m=c.count+f;n+=m*s}const a=new i(n);let o=0;for(let l=0;l<t.length;++l){const c=e[l],u=t[l],f=c?0:u.count-2,m=u.count+f,g=u.itemSize,x=new i(m*g);let y=0;for(let T=0;T<u.count;T++){const v=T*g,b=T!==0&&T!==u.count-1&&!c;for(let E=0;E<g;E++)x[y+E]=u.array[v+E],b&&(x[y+g+E]=u.array[v+E]);y+=b?2*g:g}a.set(x,o),o+=m*g}return new d.BufferAttribute(a,s,r)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static removeObjectFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areGeometriesMergeable(t,e){if(!t||!e||t.type==="InstancedBufferGeometry"||e.type==="InstancedBufferGeometry"||!!t.index!=!!e.index)return!1;const i=Object.keys(t.attributes);if(i.length!==Object.keys(e.attributes).length)return!1;for(const s of i)if(!e.attributes[s])return!1;return!0}static areObjectsMergeable(t,e){if(t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.visible!==e.visible||t.userData.layerName!==e.userData.layerName)return!1;if(t.type===e.type)return!0;const i=t,s=e;return i.isMesh&&s.isMesh||i.isLine&&s.isLine||i.isPoints&&s.isPoints}static isMergedMesh(t){return!!(t&&t.userData.batches)}static isFaceIndexInBatch(t,e,i){if(t.boundsTree){const s=t.index,r=s.getX(i*3);if(r>=e.positionStart&&r<e.positionStart+e.positionCount)return!0}else if(t.index){const s=e.indexStart/3,r=(e.indexStart+e.indexCount)/3-1;if(i>=s&&i<=r)return!0}else{const s=i*3;if(s>=e.positionStart&&s<e.positionStart+e.positionCount)return!0}return!1}static getBatchByFaceIndex(t,e){if(e<0)return S.error("[Merge]: Invalid faceIndex: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const r=i[s];if(this.isFaceIndexInBatch(t.geometry,r,e))return r}}static getBatchByLineIndex(t,e){if(e<0)return S.error("[Merge]: Invalid index: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(!i)return;const s=t.geometry,r=s.index;for(let n=0;n<i.length;++n){const a=i[n];if(r){if(e>=a.indexStart&&e<a.indexStart+a.indexCount)return a}else if(e>=a.positionStart&&e<a.positionStart+a.positionCount)return a}}static getBatchIdByFaceIndex(t,e){const i=this.getBatchByFaceIndex(t,e);return i?i.batchId:-1}static getBatchByBatchId(t,e){const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const r=i[s];if(r.batchId===e)return r}}static cloneGeometryForBatch(t,e){const i=t&&t.geometry;if(!i)return;const s=i.attributes.position,r=s?.array;let n=i.index?.array;if(!r||!n)return S.warn("[Merge]: Unexpected position: "+r+", or index: "+n+"!"),void 0;const a=new d.BufferGeometry,o=e.positionStart,l=e.positionStart+e.positionCount,c=i.attributes;for(const x in c){const y=c[x],T=y.itemSize,v=y.array.slice(o*T,l*T);a.setAttribute(x,new d.BufferAttribute(v,T,y.normalized))}if(i.boundsTree&&(n=i.userData.originalIndex,!n))return S.warn("[Merge] After building bvh, the original index data is not preserved !"),void 0;const u=e.indexStart,f=e.indexStart+e.indexCount,m=[];let g=0;for(let x=u;x<f&&x<n.length;++x)m[g++]=n[x]-e.positionStart;return a.setIndex(m),i.boundingBox&&a.computeBoundingBox(),i.boundingSphere&&a.computeBoundingSphere(),a}};p(di,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let oe=di;const _o=.01;class Po{static getFaces(t){const e=t.map(r=>r.toArray()).reduce((r,n)=>(r.push(...n),r),[]),i=[];return ua.Earcut.triangulate(e,[],3).forEach(r=>i.push(r)),i}static arePointsCoplanar(t){if(t.length<4)return!0;const e=t[1].clone().sub(t[0]),s=t[2].clone().sub(t[0]).cross(e).normalize();for(let r=3;r<t.length;r++)if(t[r].clone().sub(t[0]).projectOnVector(s).length()>_o)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return fa(e).length>0}}class rt{static getVisibleObjectBoundingBox(t){const e=new d.Box3;return t.traverse(i=>{i.visible&&(i instanceof d.Mesh||i instanceof d.Line)&&$.isObjectSelectable(i)&&e.expandByObject(i)}),e}static getObjectsBoundingBox(t,e,i){const s=new d.Box3;return e.forEach(r=>{const n=t.getObjectById(r);if(n){const a=rt.getBoundingBox(n,i);a.isEmpty()||s.union(a)}}),s}static getBoundingBox(t,e=!0){const i=new d.Box3;if(t instanceof d.InstancedMesh)return rt.getInstancedMeshBoundingBox(t);if(t.children.length===0)return i.expandByObject(t),i;const s=t.children.length;let r=1;s>20&&(r=3),s>100&&(r=5),s>200&&(r=10),s>1e3&&(r=100),t.updateMatrixWorld(!1);for(let n=0;n<s;++n){const a=t.children[n];if(!e||n%r===0)if(a.updateMatrix(),a instanceof d.InstancedMesh){const o=rt.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(z.isMatrixValid(a.matrixWorld)){const o=rt.getBoundingBox(a);o.isEmpty()||i.union(o)}else console.warn("[SceneUtils] Found object("+a.type+") with invalid matrix: "+a.matrixWorld.elements)}return t.geometry&&i.expandByObject(t),i}static getInstancedMeshBoundingBox(t){const e=new d.Box3,i=new d.Matrix4;for(let s=0;s<t.count;++s){t.getMatrixAt(s,i);const r=t.geometry.clone();if(r.boundingBox){const n=r.boundingBox.applyMatrix4(i);!n.isEmpty()&&z.isBoxValid(n)&&e.union(n)}}return e.applyMatrix4(t.matrixWorld),e}static getObjectCenter(t,e){const i=rt.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class dt{static setMaterialSection(t,e,i=!1,s=!1){const r=i&&t.clippingPlanes?t.clippingPlanes:[];r.push(...e),t.clippingPlanes=r,t.clipIntersection=s}static removeSection(t){t&&t.traverse(e=>{const i=e.material;Array.isArray(i)?i.forEach(s=>{s.clippingPlanes=[]}):i&&(i.clippingPlanes=[])})}static addSection(t,e,i=!1,s=!1){t&&t.traverse(r=>{const n=r.material;Array.isArray(n)?n.forEach(a=>{dt.setMaterialSection(a,e,i,s)}):n&&dt.setMaterialSection(n,e,i,s)})}static generateSectionPlanesByBox(t){const e=t.min,i=t.max;return[new d.Plane(new d.Vector3(0,-1,0),i.y),new d.Plane(new d.Vector3(0,1,0),-e.y),new d.Plane(new d.Vector3(1,0,0),-e.x),new d.Plane(new d.Vector3(-1,0,0),i.x)]}static generateSectionPlanesByPoints(t,e=!0){const i=t.length;if(i<2)return;const s=[];for(let r=0;r<i-1;r++){const n=t[r],a=t[(r+1)%i],o=new d.Plane;o.setFromCoplanarPoints(new d.Vector3(n.x,n.y,-1),new d.Vector3(n.x,n.y,0),new d.Vector3(a.x,a.y,0)),e||o.negate(),s.push(o)}return s}}class Ao{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new pa.SimplifyModifier().modify(t,i):t}static getNumberOfVerticesToRemove(t,e){let i=0;t instanceof d.BufferGeometry&&t.index&&(i=t.attributes.position.count);const s=Math.floor(i*e);return i<20?0:s}}const Io=10;var it=(h=>(h.TripleCross="TripleCross",h.Square="Square",h.Triangle="Triangle",h.CircleWithCross="CircleWithCross",h.Cross="Cross",h.Perpendicular="Perpendicular",h))(it||{});class ko{static createSVGObject(t){return new ma.SVGObject(t)}}class pi{static async createEnvTexture(t,e){const i=new ga.RGBELoader;return new Promise(s=>{i.load(e,r=>{if(t){const n=t.fromEquirectangular(r).texture;t.dispose(),s(n)}})})}static async createEnvTextureFromDataArray(t,e=this.HDR_CITY_STREET_64x32,i=64,s=32){if(t){const r=new d.DataTexture(e,i,s);r.flipY=!0,r.magFilter=d.LinearFilter,r.minFilter=d.LinearFilter,r.type=d.HalfFloatType,r.version=1;const n=t.fromEquirectangular(r).texture;return t.dispose(),Promise.resolve(n)}return Promise.reject("Invalid pmremGenerator!")}}p(pi,"HDR_CITY_STREET_64x32",Uint16Array.from([11910,12340,12797,15360,11926,12348,12806,15360,11958,12364,12814,15360,11974,12380,12830,15360,11958,12364,12822,15360,11926,12348,12797,15360,11878,12324,12773,15360,11830,12308,12749,15360,11798,12292,12733,15360,11782,12279,12725,15360,11765,12263,12709,15360,11749,12247,12701,15360,11733,12231,12701,15360,11701,12215,12693,15360,11685,12199,12685,15360,11685,12199,12685,15360,11701,12215,12693,15360,11717,12231,12701,15360,11733,12247,12709,15360,11749,12263,12717,15360,11749,12279,12717,15360,11765,12279,12725,15360,11765,12279,12725,15360,11765,12292,12725,15360,11798,12300,12733,15360,11830,12316,12749,15360,11846,12324,12757,15360,11894,12340,12781,15360,11926,12356,12797,15360,11942,12356,12797,15360,11926,12348,12789,15360,11926,12348,12789,15360,11942,12356,12797,15360,11942,12356,12797,15360,11942,12348,12806,15360,11942,12356,12806,15360,11942,12356,12814,15360,11958,12372,12830,15360,11974,12372,12830,15360,11974,12372,12838,15360,11990,12388,12854,15360,12055,12420,12886,15360,12119,12452,12918,15360,12167,12476,12950,15360,12231,12500,12982,15360,12263,12516,12998,15360,12231,12500,12974,15360,12199,12484,12958,15360,12199,12484,12958,15360,12199,12492,12966,15360,12247,12508,12982,15360,12247,12508,12990,15360,12231,12500,12982,15360,12199,12484,12966,15360,12167,12468,12942,15360,12119,12444,12918,15360,12087,12436,12902,15360,12055,12420,12886,15360,12055,12412,12878,15360,12039,12412,12878,15360,12022,12396,12862,15360,12006,12388,12846,15360,11958,12364,12830,15360,11910,12340,12806,15360,12119,12508,13103,15360,12087,12484,13071,15360,12055,12468,13046,15360,12006,12436,13006,15360,11926,12396,12958,15360,11878,12364,12926,15360,11846,12348,12894,15360,11782,12308,12854,15360,11749,12292,12830,15360,11717,12263,12814,15360,11685,12247,12806,15360,11669,12215,12789,15360,11685,12231,12789,15360,11701,12247,12797,15360,11701,12247,12806,15360,11717,12263,12814,15360,11749,12292,12822,15360,11782,12308,12838,15360,11798,12316,12846,15360,11814,12332,12862,15360,11846,12340,12870,15360,11862,12348,12878,15360,11846,12340,12870,15360,11846,12340,12862,15360,11878,12356,12886,15360,11910,12372,12910,15360,11942,12396,12934,15360,11958,12412,12958,15360,12039,12452,12998,15360,12071,12468,13022,15360,12039,12452,12998,15360,12039,12452,12998,15360,12006,12444,13006,15360,11974,12436,12998,15360,11942,12412,12982,15360,11926,12396,12974,15360,11926,12404,12974,15360,11958,12420,12998,15360,12006,12452,13038,15360,12055,12476,13071,15360,12039,12476,13079,15360,12087,12508,13127,15360,12247,12597,13231,15360,12388,12693,13332,15360,12420,12741,13364,15360,12436,12757,13372,15360,12468,12773,13380,15360,12500,12806,13388,15360,12516,12822,13404,15360,12629,12934,13452,15360,12741,13046,13508,15360,12806,13095,13532,15360,12757,13046,13516,15360,12645,12950,13460,15360,12565,12870,13428,15360,12532,12838,13412,15360,12549,12854,13412,15360,12516,12838,13396,15360,12452,12757,13356,15360,12420,12725,13340,15360,12404,12709,13332,15360,12372,12677,13316,15360,12279,12589,13207,15360,12135,12516,13119,15360,12388,12709,13348,15360,12247,12581,13223,15360,12055,12476,13087,15360,11910,12388,12982,15360,11733,12308,12886,15360,11669,12247,12846,15360,11621,12199,12814,15360,11541,12103,12765,15360,11492,12055,12733,15360,11508,12055,12733,15360,11476,12022,12717,15360,11525,12055,12725,15360,11589,12135,12757,15360,11669,12199,12765,15360,11765,12292,12814,15360,11862,12348,12886,15360,11910,12372,12910,15360,12006,12420,12966,15360,12071,12452,12998,15360,12119,12476,13022,15360,12167,12492,13046,15360,12183,12500,13063,15360,12199,12524,13079,15360,12308,12589,13151,15360,12300,12581,13151,15360,12167,12516,13087,15360,12087,12468,13030,15360,12022,12444,13014,15360,11990,12420,12990,15360,11974,12420,12990,15360,11974,12420,12990,15360,11990,12436,13014,15360,11990,12444,13030,15360,12103,12500,13103,15360,12087,12508,13111,15360,12039,12484,13103,15360,12039,12476,13103,15360,11942,12436,13054,15360,11974,12452,13087,15360,12039,12492,13135,15360,12103,12532,13199,15360,12183,12581,13263,15360,12308,12661,13340,15360,12484,12822,13436,15360,12613,12918,13484,15360,12725,13046,13540,15360,13046,13332,13677,15360,13143,13380,13717,15360,13223,13420,13741,15360,13396,13540,13862,15360,13436,13589,13902,15360,13484,13629,13942,15360,13468,13621,13934,15360,13412,13564,13878,15360,13372,13524,13846,15360,13287,13452,13781,15360,13223,13428,13749,15360,13340,13492,13805,15360,13239,13428,13749,15360,13095,13364,13685,15360,12918,13223,13597,15360,12822,13111,13556,15360,12613,12934,13468,15360,12532,12854,13428,15360,12565,12870,13444,15360,12468,12789,13396,15360,12372,12693,13340,15360,12087,12492,13111,15360,11846,12364,12958,15360,11717,12300,12878,15360,11557,12135,12781,15360,11476,12055,12741,15360,11460,12022,12725,15360,11476,12022,12725,15360,11476,12022,12709,15360,11476,11958,12605,15360,11364,11733,12332,15360,11111,11412,11661,15360,11223,11476,11773,15360,11388,11669,12095,15360,11765,12119,12492,15360,12388,12613,13079,15360,12661,12902,13356,15360,12998,13255,13564,15360,13372,13508,13797,15360,13412,13548,13846,15360,13287,13436,13725,15360,13271,13428,13709,15360,13287,13428,13717,15360,13014,13287,13597,15360,12709,12998,13460,15360,12452,12741,13332,15360,12364,12653,13271,15360,12404,12693,13316,15360,12420,12709,13316,15360,12420,12709,13332,15360,12263,12589,13231,15360,12332,12661,13312,15360,12300,12629,13295,15360,12263,12605,13287,15360,12231,12597,13279,15360,12247,12613,13303,15360,12231,12597,13295,15360,12231,12605,13312,15360,12199,12597,13324,15360,12231,12613,13340,15360,12516,12870,13468,15360,12725,13063,13564,15360,12741,13079,13573,15360,12854,13175,13613,15360,12902,13223,13629,15360,13046,13348,13693,15360,13356,13516,13846,15360,13605,13765,14078,15360,13717,13870,14191,15360,13765,13918,14255,15360,13765,13910,14247,15360,13701,13854,14191,15360,13573,13733,14070,15360,13508,13677,14006,15360,13380,13548,13886,15360,13111,13380,13741,15360,13063,13348,13709,15360,12886,13207,13629,15360,12725,13046,13548,15360,12645,12966,13508,15360,12677,12982,13508,15360,12629,12950,13492,15360,12452,12789,13412,15360,12324,12661,13332,15360,12356,12677,13340,15360,12388,12693,13348,15360,12279,12597,13247,15360,11894,12396,12998,15360,11637,12231,12846,15360,11573,12135,12789,15360,11589,12151,12797,15360,11621,12167,12797,15360,11637,12119,12677,15360,11079,11404,11693,15360,10517,10701,10653,15360,10252,10348,10007,15360,9902,9999,9428,15360,9846,9886,9047,15360,10135,10260,9685,15360,10412,10533,10412,15360,11268,11436,11549,15360,12364,12605,13087,15360,12444,12709,13255,15360,12549,12822,13348,15360,12613,12886,13396,15360,12597,12886,13412,15360,12581,12870,13404,15360,12661,12950,13460,15360,12725,13014,13492,15360,13079,13332,13645,15360,12757,13046,13500,15360,12677,12982,13476,15360,12854,13143,13556,15360,12693,12982,13492,15360,12581,12886,13452,15360,12709,13030,13508,15360,12372,12709,13364,15360,12324,12661,13348,15360,12292,12645,13340,15360,12292,12645,13348,15360,12468,12806,13436,15360,12532,12854,13460,15360,12500,12854,13468,15360,12500,12854,13484,15360,12725,13063,13589,15360,12982,13324,13701,15360,13111,13388,13741,15360,13014,13340,13709,15360,13014,13332,13717,15360,13287,13476,13862,15360,13436,13621,13974,15360,13532,13717,14095,15360,13725,13902,14295,15360,13942,14103,14420,15360,13974,14135,14436,15360,13862,14022,14388,15360,13725,13894,14295,15360,13789,13958,14336,15360,13830,13990,14348,15360,13372,13548,13942,15360,13014,13332,13733,15360,12886,13239,13661,15360,12854,13207,13637,15360,12757,13095,13589,15360,12757,13079,13573,15360,12645,12982,13516,15360,12629,12966,13532,15360,12549,12870,13468,15360,12356,12693,13372,15360,12151,12549,13231,15360,12215,12573,13247,15360,12199,12565,13231,15360,12071,12492,13135,15360,12055,12468,13087,15360,11878,12372,12958,15360,11685,12199,12781,15360,10774,11159,11412,15360,9533,9621,8870,15360,9308,9340,8071,15360,9276,9300,7878,15360,9324,9332,8420,15360,9191,9216,7991,15360,8950,8983,7766,15360,9493,9525,8677,15360,10252,10332,10007,15360,10661,10846,10894,15360,10701,10926,10998,15360,10950,11276,11428,15360,11364,11637,12063,15360,11958,12388,12926,15360,12183,12540,13175,15360,12340,12645,13295,15360,12420,12693,13316,15360,12757,13030,13460,15360,13046,13324,13645,15360,13095,13348,13677,15360,13303,13460,13781,15360,13207,13404,13741,15360,13127,13372,13717,15360,13372,13524,13862,15360,12693,13030,13540,15360,12725,13046,13548,15360,12468,12822,13436,15360,12263,12629,13348,15360,12436,12773,13428,15360,12693,12998,13524,15360,12725,13046,13564,15360,12645,12982,13556,15360,12613,12966,13556,15360,12886,13255,13685,15360,13436,13629,14022,15360,13637,13813,14231,15360,13621,13789,14215,15360,13878,14038,14412,15360,14022,14183,14468,15360,13926,14119,14452,15360,14054,14231,14508,15360,14135,14311,14540,15360,14348,14436,14669,15360,14460,14540,14749,15360,14404,14484,14709,15360,14420,14500,14709,15360,14653,14717,14894,15360,14119,14279,14508,15360,13484,13669,14078,15360,13063,13380,13773,15360,12677,13079,13613,15360,12484,12886,13516,15360,12436,12822,13476,15360,12468,12838,13476,15360,12039,12532,13316,15360,12231,12613,13340,15360,12468,12789,13436,15360,12388,12725,13396,15360,12135,12557,13287,15360,12151,12557,13271,15360,12039,12484,13175,15360,11878,12396,13038,15360,11814,12348,12950,15360,11492,11894,12460,15360,9950,10103,9621,15360,8830,8838,7220,15360,8565,8533,7015,15360,8541,8501,6919,15360,8332,8300,6822,15360,8412,8372,7220,15360,8710,8701,7686,15360,9372,9404,8549,15360,9533,9621,9079,15360,9268,9292,8196,15360,9452,9460,8167,15360,9533,9581,8533,15360,9742,9870,9316,15360,11460,11814,12348,15360,11942,12388,12902,15360,11749,12167,12573,15360,11300,11492,11621,15360,11974,12332,12669,15360,12436,12741,13364,15360,12597,12886,13460,15360,12966,13271,13653,15360,12998,13303,13669,15360,13476,13629,13974,15360,13733,13886,14239,15360,13364,13524,13894,15360,13063,13356,13725,15360,12982,13287,13669,15360,12484,12806,13444,15360,12565,12902,13500,15360,12950,13287,13693,15360,12934,13271,13677,15360,12693,13046,13589,15360,12661,13030,13605,15360,12870,13271,13717,15360,13348,13548,13966,15360,13621,13813,14271,15360,13797,13974,14412,15360,13942,14119,14484,15360,14263,14388,14629,15360,14420,14508,14733,15360,14460,14548,14773,15360,14982,15046,15231,15360,15564,15580,15669,15360,15974,15982,16078,15360,15805,15821,15926,15360,15460,15476,15572,15360,15436,15460,15556,15360,14781,14862,15127,15360,13621,13813,14348,15360,12789,13207,13757,15360,12452,12886,13581,15360,12263,12709,13476,15360,12039,12597,13396,15360,11942,12516,13340,15360,11846,12468,13271,15360,11733,12380,13127,15360,11926,12460,13191,15360,12055,12524,13263,15360,11878,12428,13159,15360,11605,12231,12886,15360,11412,11990,12709,15360,11508,12103,12789,15360,11637,12231,12854,15360,10661,11079,11380,15360,9541,9685,9252,15360,8573,8605,7493,15360,8404,8388,7348,15360,8830,8822,8212,15360,9308,9324,9095,15360,9324,9364,9220,15360,9047,9119,8653,15360,9023,9055,8404,15360,9055,9063,8167,15360,8870,8846,7541,15360,8862,8806,7380,15360,8950,8910,7252,15360,9268,9284,7557,15360,10316,10468,10380,15360,11239,11476,11677,15360,10653,10942,11047,15360,9661,9814,9324,15360,10693,10958,11047,15360,11396,11653,11990,15360,11878,12292,12597,15360,12468,12789,13396,15360,12773,13095,13589,15360,13364,13516,13894,15360,13894,14054,14380,15360,13717,13870,14247,15360,13420,13589,13958,15360,13255,13452,13830,15360,12806,13143,13637,15360,13159,13412,13830,15360,13629,13813,14215,15360,13303,13500,13910,15360,13079,13396,13805,15360,13191,13452,13878,15360,13412,13621,14062,15360,14103,14279,14540,15360,14773,14854,15086,15360,14717,14805,15046,15360,14295,14420,14685,15360,14380,14476,14733,15360,14572,14661,14902,15360,15596,15612,15701,15360,16351,16335,16384,15360,16484,16476,16492,15360,16516,16500,16516,15360,16388,16375,16404,15360,16054,16054,16118,15360,15918,15926,16006,15360,15556,15572,15669,15360,14653,14725,14982,15360,13637,13838,14319,15360,13412,13613,14054,15360,12870,13287,13789,15360,12404,12838,13524,15360,12199,12677,13428,15360,12324,12741,13452,15360,11942,12516,13324,15360,11765,12380,13111,15360,11428,11942,12589,15360,10886,11388,11902,15360,10372,10717,11006,15360,9846,10240,10191,15360,10252,10549,10766,15360,10613,11079,11484,15360,10581,10998,11388,15360,9613,9846,9629,15360,8525,8557,7541,15360,8605,8613,7814,15360,9292,9324,9079,15360,9388,9396,9220,15360,10709,10846,11031,15360,9894,9966,9854,15360,9252,9236,8774,15360,8822,8790,8183,15360,8292,8260,6533,15360,8111,8007,6324,15360,8228,8183,6405,15360,8501,8501,6565,15360,8814,8878,7172,15360,9260,9364,8244,15360,8902,9095,8252,15360,9444,9581,9047,15360,9509,9637,8790,15360,9477,9613,8806,15360,10725,11063,11079,15360,11508,11910,12356,15360,12484,12789,13380,15360,12838,13159,13629,15360,13428,13589,13974,15360,14135,14279,14484,15360,13942,14087,14396,15360,13677,13846,14247,15360,13436,13613,14006,15360,13597,13781,14183,15360,14183,14340,14540,15360,14022,14215,14484,15360,13637,13838,14271,15360,14038,14231,14508,15360,14380,14476,14701,15360,14757,14854,15078,15360,15030,15111,15343,15360,15420,15452,15556,15360,15476,15500,15588,15360,15351,15388,15492,15360,15572,15596,15677,15360,15653,15669,15717,15360,15821,15821,15853,15360,15845,15845,15869,15360,15998,15990,16022,15360,15926,15926,15974,15360,15653,15669,15733,15360,15661,15677,15749,15360,15612,15629,15717,15360,15271,15335,15452,15360,14484,14572,14821,15360,14215,14372,14588,15360,13468,13677,14167,15360,12773,13175,13653,15360,12725,13143,13637,15360,12452,12886,13532,15360,12263,12709,13444,15360,11894,12436,13103,15360,10252,10533,10661,15360,8613,8693,7445,15360,8742,8782,7047,15360,8420,8412,6565,15360,7926,7910,6405,15360,8806,8854,7300,15360,9127,9228,8007,15360,8685,8750,7300,15360,8348,8356,6758,15360,8380,8340,7300,15360,8991,8918,8388,15360,9838,9790,9549,15360,10055,10127,10047,15360,9501,9493,9268,15360,9332,9292,8902,15360,9079,9007,8509,15360,8300,8260,7252,15360,8693,8701,8196,15360,8228,8212,7111,15360,8469,8501,7380,15360,8420,8501,6919,15360,8549,8645,6983,15360,8581,8661,6951,15360,9268,9332,7718,15360,9063,9207,7445,15360,9284,9380,7718,15360,9412,9557,8693,15360,10276,10517,10103,15360,11830,12279,12589,15360,12725,13079,13589,15360,13127,13396,13773,15360,14087,14231,14460,15360,13974,14119,14412,15360,13677,13854,14247,15360,14119,14279,14500,15360,13990,14167,14460,15360,14364,14452,14653,15360,14564,14653,14837,15360,14404,14492,14701,15360,14870,14942,15135,15360,15388,15420,15500,15360,15207,15287,15420,15360,14797,14894,15127,15360,15271,15335,15452,15360,15926,15942,15990,15360,16207,16207,16231,15360,16118,16110,16126,15360,15741,15733,15741,15360,16239,16207,16175,15360,16444,16460,16484,15360,16046,16022,16006,15360,15942,15950,15966,15360,15773,15789,15829,15360,15789,15797,15845,15360,15693,15709,15757,15360,15540,15564,15653,15360,15303,15364,15468,15360,14733,14813,15014,15360,13862,14054,14420,15360,12838,13255,13725,15360,12789,13207,13693,15360,12468,12918,13564,15360,12404,12838,13500,15360,11428,11862,12412,15360,9143,9276,8388,15360,8541,8533,6726,15360,8444,8428,6629,15360,8212,8183,6597,15360,8388,8380,7015,15360,8726,8710,6758,15360,8332,8316,6437,15360,8453,8428,6565,15360,8597,8605,7814,15360,8701,8661,8151,15360,9452,9396,9015,15360,10581,10557,10380,15360,10950,10974,10846,15360,10380,10356,10252,15360,10749,10741,10685,15360,9870,9854,9693,15360,9023,9039,8669,15360,8790,8854,8509,15360,8196,8167,7332,15360,7975,8015,7079,15360,8589,8750,7445,15360,9095,9260,7111,15360,8983,9135,7188,15360,8902,8991,7252,15360,8862,9007,7015,15360,8967,9111,7300,15360,8742,8878,7493,15360,9557,9999,9549,15360,11292,11613,11862,15360,12135,12468,12982,15360,12215,12460,12878,15360,13356,13468,13685,15360,13821,13934,14199,15360,13548,13701,14022,15360,14103,14263,14468,15360,14279,14388,14572,15360,14364,14452,14645,15360,14709,14789,14950,15360,15143,15199,15327,15360,15388,15412,15468,15360,15476,15500,15548,15360,15420,15444,15492,15360,15436,15460,15516,15360,15612,15637,15685,15360,16086,16086,16110,15360,16396,16388,16396,15360,16094,16094,16110,15360,15869,15861,15861,15360,16135,16110,16070,15360,16428,16420,16404,15360,15588,15556,15524,15360,15484,15500,15508,15360,15335,15364,15396,15360,15677,15685,15717,15360,15604,15621,15661,15360,15420,15444,15500,15360,15303,15372,15452,15360,14717,14805,14998,15360,14412,14508,14701,15360,13548,13765,14199,15360,13271,13508,13942,15360,12661,13159,13709,15360,12468,12854,13436,15360,10260,10484,10509,15360,8613,8669,6951,15360,8151,8143,6469,15360,8653,8629,7814,15360,8469,8444,7541,15360,8718,8693,7814,15360,8372,8332,6597,15360,8356,8308,7111,15360,9047,8983,8396,15360,8822,8798,8308,15360,9372,9348,8967,15360,10364,10364,10183,15360,10268,10260,9894,15360,10541,10533,10468,15360,10380,10364,10276,15360,10621,10613,10549,15360,9910,9942,9758,15360,8364,8380,7621,15360,8581,8637,8135,15360,8252,8300,7573,15360,8119,8175,7300,15360,8372,8453,7493,15360,8420,8501,6983,15360,8742,8822,7573,15360,8782,8854,8151,15360,8581,8661,7079,15360,9220,9268,8340,15360,9549,9645,8854,15360,11717,11950,12127,15360,12468,12741,13207,15360,12709,12966,13388,15360,12300,12508,12886,15360,12492,12709,13063,15360,13239,13372,13548,15360,12476,12597,12814,15360,13581,13685,13878,15360,14476,14548,14685,15360,14556,14629,14773,15360,14765,14829,14966,15360,15159,15207,15303,15360,15372,15396,15444,15360,15516,15532,15572,15360,15653,15661,15693,15360,15829,15837,15853,15360,16022,16014,16022,15360,16311,16295,16279,15360,16343,16319,16303,15360,16412,16388,16359,15360,15813,15797,15773,15360,13063,13151,13183,15360,11484,11701,11798,15360,12300,12412,12468,15360,14613,14637,14653,15360,11974,12215,12316,15360,14135,14215,14303,15360,15604,15629,15677,15360,15524,15548,15596,15360,15351,15380,15428,15360,14797,14894,15054,15360,13990,14231,14500,15360,13492,13709,14070,15360,12886,13316,13701,15360,12613,13207,13749,15360,11525,11974,12428,15360,9284,9412,8629,15360,8597,8653,6951,15360,7806,7790,6292,15360,7589,7541,6437,15360,7485,7437,6597,15360,7453,7404,6180,15360,7774,7686,6565,15360,8300,8260,7332,15360,9918,9942,9862,15360,10348,10372,10231,15360,9725,9709,9228,15360,10613,10621,10509,15360,10199,10175,9838,15360,10380,10388,10340,15360,11207,11255,11284,15360,10661,10717,10725,15360,10103,10135,9950,15360,8444,8436,7669,15360,8469,8501,7445,15360,8950,9111,8854,15360,9485,9798,10071,15360,8364,8501,8039,15360,7959,7951,6806,15360,8597,8605,8039,15360,8501,8533,7557,15360,8758,8830,7509,15360,10758,10830,10693,15360,11508,11605,11621,15360,13524,13669,13886,15360,13830,14022,14327,15360,13926,14103,14364,15360,13460,13621,13886,15360,12854,13191,13420,15360,13597,13733,13926,15360,13846,13990,14223,15360,13773,13942,14199,15360,13910,14087,14356,15360,13813,14022,14319,15360,14247,14396,14540,15360,14693,14765,14878,15360,15223,15279,15343,15360,15508,15524,15540,15360,15540,15548,15564,15360,15327,15335,15319,15360,15303,15311,15303,15360,15918,15910,15886,15360,16247,16207,16151,15360,16175,16143,16086,15360,14436,14452,14436,15360,12263,12380,12404,15360,11476,11701,11773,15360,12380,12492,12532,15360,14797,14797,14757,15360,11372,11589,11677,15360,12597,12934,13356,15360,13990,14364,14725,15360,14183,14444,14773,15360,14231,14444,14717,15360,14412,14532,14709,15360,14054,14199,14380,15360,12372,12500,12605,15360,12199,12565,13006,15360,12581,13175,13653,15360,10055,10380,10324,15360,8557,8573,6726,15360,8167,8196,6533,15360,7517,7485,6119,15360,7244,7172,5798,15360,7071,6959,5718,15360,7669,7581,6260,15360,8661,8605,7975,15360,10942,11079,11151,15360,12573,12741,13014,15360,11902,12030,12191,15360,10308,10332,10135,15360,11255,11300,11284,15360,11276,11348,11396,15360,10055,10215,10292,15360,12183,12332,12468,15360,9918,9966,9798,15360,8734,8742,8196,15360,8967,8950,8469,15360,10260,10276,10039,15360,9734,9758,9605,15360,9388,9404,9308,15360,7943,7878,7095,15360,7726,7637,6645,15360,8047,7983,7204,15360,9284,9236,8693,15360,9621,9565,9143,15360,11255,11268,11047,15360,13175,13332,13420,15360,13773,13934,14175,15360,13854,14022,14271,15360,13870,14038,14279,15360,13388,13516,13677,15360,12279,12629,12966,15360,13348,13452,13564,15360,13821,13918,14054,15360,13701,13846,14022,15360,13460,13605,13781,15360,13492,13637,13821,15360,13709,13821,13950,15360,14372,14428,14476,15360,14516,14572,14613,15360,14741,14789,14813,15360,14725,14749,14749,15360,13452,13484,13468,15360,13476,13500,13492,15360,14990,15022,15022,15360,14556,14572,14564,15360,15094,15111,15094,15360,13231,13287,13215,15360,11255,11380,11175,15360,10677,10886,10492,15360,11846,12006,11934,15360,14327,14340,14279,15360,10766,11039,10862,15360,12918,13255,13452,15360,14231,14548,14886,15360,13878,14380,14765,15360,13444,13862,14412,15360,12151,12404,12621,15360,12637,12902,13215,15360,11549,11749,11870,15360,12279,12653,13119,15360,13223,13404,13516,15360,9228,9260,8276,15360,8087,7991,6308,15360,7918,7814,6919,15360,7469,7364,6148,15360,7485,7380,6212,15360,8228,7991,7204,15360,9276,8967,8212,15360,9806,9573,8742,15360,10135,10087,9621,15360,11452,11452,11452,15360,10629,10637,10509,15360,10693,10733,10637,15360,11095,11111,10982,15360,11292,11348,11372,15360,10199,10244,10167,15360,10814,10926,10846,15360,8669,8774,7493,15360,7870,7910,6244,15360,8204,8183,6919,15360,9806,9758,9159,15360,9460,9436,8629,15360,9159,9087,8260,15360,7637,7509,6790,15360,7758,7629,6838,15360,7967,7918,6774,15360,10854,10749,10501,15360,11508,11412,11316,15360,12372,12300,12151,15360,12030,12119,12063,15360,12781,12910,12982,15360,13476,13581,13661,15360,13484,13589,13677,15360,12404,12428,12380,15360,11605,11765,11798,15360,11492,11533,11452,15360,11838,11886,11798,15360,12263,12372,12380,15360,12151,12231,12175,15360,11492,11508,11412,15360,11119,11111,10838,15360,12508,12581,12573,15360,12621,12693,12677,15360,12573,12629,12589,15360,12292,12324,12231,15360,12476,12565,12573,15360,11998,12159,12215,15360,12950,13071,13159,15360,12263,12372,12428,15360,12380,12428,12444,15360,11300,11308,11143,15360,10199,10244,9734,15360,9709,9701,9252,15360,10492,10581,10404,15360,11476,11516,11388,15360,9477,9517,8790,15360,11717,11854,11838,15360,14247,14420,14524,15360,14054,14311,14436,15360,13597,13805,13982,15360,11364,11533,11597,15360,12263,12428,12549,15360,11436,11605,11653,15360,13079,13324,13444,15360,12516,12613,12605,15360,10039,10015,9605,15360,8693,8621,7878,15360,7951,7862,6902,15360,8196,8204,7015,15360,8677,8589,7637,15360,9284,9031,8340,15360,9814,9605,8902,15360,10685,10428,9910,15360,10492,10260,9685,15360,9404,9252,7943,15360,8830,8766,7220,15360,9220,9047,7943,15360,9693,9669,9015,15360,11412,11468,11372,15360,11135,11159,11023,15360,10087,10055,9428,15360,9910,10007,9621,15360,9236,9300,8934,15360,9597,9557,8902,15360,10669,10549,9782,15360,9926,9870,9127,15360,9894,9918,9047,15360,8685,8742,7910,15360,9958,10167,10284,15360,10215,10332,10396,15360,11396,11428,11452,15360,11223,11255,11300,15360,11814,11862,11958,15360,10685,10846,10870,15360,10340,10380,10007,15360,11175,11207,10894,15360,12103,12207,12215,15360,11143,11103,10902,15360,9910,9966,9613,15360,10015,10079,9493,15360,10806,10846,10517,15360,10862,10934,10637,15360,10838,10942,10661,15360,10958,11087,10878,15360,10709,10838,10701,15360,10669,10741,10589,15360,10581,10669,10525,15360,10252,10348,9974,15360,11396,11500,11525,15360,11207,11255,11264,15360,10878,10910,10934,15360,11031,11063,11159,15360,11292,11324,11396,15360,11223,11255,11300,15360,10693,10685,10645,15360,10428,10420,10324,15360,10300,10252,9991,15360,10838,10846,10798,15360,10428,10428,10364,15360,9669,9605,9380,15360,10167,10244,10087,15360,11709,11854,11910,15360,11223,11284,11268,15360,10231,10244,9878,15360,10199,10244,9862,15360,10183,10260,9942,15360,10525,10653,10541,15360,12500,12597,12621,15360,11814,11741,11597,15360,11533,11460,11175,15360,11103,11006,10557,15360,10444,10396,9846,15360,10007,10023,9228,15360,9653,9790,8469,15360,9316,9372,8039,15360,9557,9830,8071,15360,9621,9918,8071,15360,9677,10015,8167,15360,9991,10284,8420,15360,10215,10436,8581,15360,10260,10484,8645,15360,10292,10476,8902,15360,10324,10468,9252,15360,9910,9894,8886,15360,10525,10573,9701,15360,9782,10039,8581,15360,9565,9814,8167,15360,9950,10039,8934,15360,10749,10758,10199,15360,10669,10685,10244,15360,10838,10838,10460,15360,11215,10910,10087,15360,11492,11364,10806,15360,11095,11159,11055,15360,11364,11388,11356,15360,11023,11039,10990,15360,11653,11653,11613,15360,11798,11725,11557,15360,11974,11862,11637,15360,12039,11942,11765,15360,12119,12047,11934,15360,12151,12071,11950,15360,12087,12006,11886,15360,12047,11966,11838,15360,11990,11926,11790,15360,11974,11910,11798,15360,11998,11934,11814,15360,12111,12039,11886,15360,12231,12143,11998,15360,12292,12199,12039,15360,12039,11974,11846,15360,11822,11782,11653,15360,11862,11838,11765,15360,11798,11765,11701,15360,11782,11733,11669,15360,11798,11749,11685,15360,11838,11790,11725,15360,11870,11822,11749,15360,11741,11701,11621,15360,11565,11541,11452,15360,11533,11500,11412,15360,11621,11581,11484,15360,11605,11557,11460,15360,11516,11468,11372,15360,11565,11533,11444,15360,11677,11637,11541,15360,11725,11661,11557,15360,11725,11661,11557,15360,11733,11669,11573,15360,11838,11773,11677,15360,11998,11926,11814,15360,12014,11926,11798,15360,11460,11404,11332,15360,11637,11557,11428,15360,12014,11894,11693,15360,12167,12022,11765,15360,12119,11982,11709,15360,11926,11806,11516,15360,11685,11589,11300,15360,11476,11404,10886,15360,11239,11151,10468,15360,10766,10733,9894,15360,10565,10565,9589,15360,10436,10444,9332,15360,10308,10308,9031,15360,10308,10316,8999,15360,10199,10244,8774,15360,9725,9645,8549,15360,10244,10276,8967,15360,10878,10838,10183,15360,11055,10966,10348,15360,11119,11006,10404,15360,11264,11135,10565,15360,11404,11316,10822,15360,11492,11388,10982,15360,11798,11613,11223,15360,12047,11830,11412,15360,12039,11894,11597,15360,12127,11990,11693,15360,12127,11990,11725,15360,12191,12055,11806,15360,12191,12055,11830,15360,11870,11773,11613,15360,11573,11516,11428,15360,11533,11484,11412,15360,11541,11492,11420,15360,11565,11516,11452,15360,11589,11541,11476,15360,11605,11557,11500,15360,11637,11589,11533,15360,11669,11621,11557,15360,11701,11645,11573,15360,11733,11669,11589,15360,11798,11717,11605,15360,11838,11749,11621,15360,11878,11782,11661,15360,11894,11798,11661,15360,11926,11806,11653,15360,11958,11822,11661,15360,11982,11846,11677,15360,12006,11870,11685,15360,12095,11950,11765,15360,12047,11910,11741,15360,11886,11765,11605,15360,11838,11733,11589,15360,11814,11717,11589,15360,11814,11709,11573,15360,11790,11693,11565,15360,11741,11677,11589,15360,11733,11677,11613,15360,11733,11685,11629,15360,11717,11669,11621,15360,11685,11645,11589,15360,11629,11589,11533,15360,11573,11525,11468,15360,11492,11444,11380,15360,11316,11255,11111,15360,11348,11292,11143,15360,11516,11436,11316,15360,11854,11749,11589,15360,12127,11990,11765,15360,12199,12055,11782,15360,12340,12231,11910,15360,12372,12292,11958,15360,12380,12300,11974,15360,12348,12247,11910,15360,12324,12215,11878,15360,12247,12103,11773,15360,12095,11958,11637,15360,12055,11926,11613,15360,11974,11854,11541,15360,11870,11765,11468,15360,11966,11854,11541,15360,12300,12151,11846,15360,12396,12316,12006,15360,12388,12308,11990,15360,12388,12308,12006,15360,12396,12316,12022,15360,12396,12308,12022,15360,12396,12308,12022,15360,12364,12279,11974,15360,12340,12247,11942,15360,12340,12231,11926,15360,12215,12071,11806,15360,12095,11966,11749,15360,11741,11645,11500,15360,11420,11356,11255,15360,11364,11308,11207,15360,11356,11300,11175,15360,11348,11292,11191,15360,11372,11324,11255,15360,11412,11364,11308,15360,11420,11372,11316,15360,11428,11380,11324,15360,11444,11388,11332,15360,11484,11428,11364,15360,11508,11460,11396,15360,11557,11500,11436,15360,11589,11533,11460,15360,11613,11557,11484,15360,11621,11557,11492,15360,11613,11557,11500,15360,11621,11557,11500,15360,11629,11573,11508,15360,11629,11573,11508,15360,11605,11557,11484,15360,11589,11533,11468,15360,11557,11508,11436,15360,11549,11500,11428,15360,11557,11500,11436,15360,11549,11492,11436,15360,11533,11484,11428,15360,11525,11476,11428,15360,11516,11476,11428,15360,11525,11484,11444,15360,11516,11476,11428,15360,11468,11428,11380,15360,11428,11388,11332,15360,11356,11308,11239,15360,11308,11255,11127,15360,11167,11071,10926,15360,11223,11119,10966,15360,11276,11175,10998,15360,11404,11332,11191,15360,11773,11693,11557,15360,11926,11798,11613,15360,12207,12039,11773,15360,12348,12231,11894,15360,12308,12151,11846,15360,12332,12215,11894,15360,12364,12279,11958,15360,12380,12292,11974,15360,12396,12316,12022,15360,12404,12316,12039,15360,12412,12332,12087,15360,12412,12332,12103,15360,12436,12356,12135,15360,12372,12292,12039,15360,12420,12332,12087,15360,12396,12316,12055,15360,12356,12263,11990,15360,12340,12231,11942,15360,12271,12127,11854,15360,12215,12071,11814,15360,12292,12135,11878,15360,12288,12135,11870,15360,12111,11982,11765,15360,11990,11886,11717,15360,11637,11557,11428,15360,11364,11300,11143,15360,11316,11239,11079,15360,11300,11207,11047,15360,11268,11159,11015,15360,11268,11159,11015,15360,11268,11159,11031,15360,11300,11223,11095,15360,11340,11292,11191,15360,11348,11300,11223,15360,11372,11324,11255,15360,11380,11332,11255,15360,11372,11316,11239,15360,11396,11340,11268,15360,11468,11404,11300,15360,11460,11404,11324,15360,11484,11428,11356,15360,11492,11436,11372,15360,11500,11444,11388,15360,11508,11460,11404,15360,11500,11452,11396,15360,11492,11436,11380,15360,11468,11412,11356,15360,11444,11388,11324,15360,11444,11388,11324,15360,11428,11380,11316,15360,11412,11356,11300,15360,11404,11348,11300,15360,11404,11356,11308,15360,11396,11356,11308,15360,11388,11348,11308,15360,11372,11340,11292,15360,11348,11308,11255,15360,11284,11223,11111,15360,11231,11143,11023,15360,11199,11111,10974,15360,11047,10958,10814,15360,11127,11023,10870,15360,11119,11006,10846,15360,11175,11055,10886,15360,11292,11191,10998,15360,11525,11404,11284,15360,11822,11637,11476,15360,11878,11733,11549,15360,11918,11790,11573,15360,12063,11918,11653,15360,12223,12063,11765,15360,12300,12151,11846,15360,12255,12103,11814,15360,12271,12127,11846,15360,12271,12127,11862,15360,12271,12127,11886,15360,12308,12183,11942,15360,12175,12039,11814,15360,12063,11934,11709,15360,12159,12014,11765,15360,12215,12063,11798,15360,12143,11998,11757,15360,12071,11934,11693,15360,11998,11870,11661,15360,11974,11870,11685,15360,11998,11910,11757,15360,11846,11765,11629,15360,11468,11396,11284,15360,11308,11223,11031,15360,11215,11103,10934,15360,11207,11095,10942,15360,11215,11103,10950,15360,11191,11087,10942,15360,11175,11079,10942,15360,11167,11063,10934,15360,11143,11031,10902,15360,11247,11143,11015,15360,11284,11191,11079,15360,11300,11223,11095,15360,11316,11268,11127,15360,11340,11284,11143,15360,11340,11284,11159,15360,11356,11300,11191,15360,11372,11316,11239,15360,11380,11324,11255,15360,11372,11316,11255,15360,11380,11324,11276,15360,11380,11324,11268,15360,11372,11316,11255,15360,11364,11316,11255,15360,11364,11308,11239,15360,11348,11292,11207,15360,11340,11284,11191,15360,11348,11292,11191,15360,11348,11292,11207,15360,11340,11292,11207,15360,11340,11292,11207,15360,11324,11276,11207,15360,11308,11255,11175,15360,11264,11175,11079,15360,11119,11039,10934,15360,11103,11015,10902,15360,11095,11006,10878,15360,11031,10942,10806,15360,10990,10902,10766,15360,11047,10942,10814,15360,11031,10926,10790,15360,11055,10942,10806,15360,11119,10998,10846,15360,11151,11015,10830,15360,11268,11095,10886,15360,11484,11396,11268,15360,11790,11701,11549,15360,11886,11790,11637,15360,11838,11741,11581,15360,11838,11725,11541,15360,11902,11782,11581,15360,11966,11838,11629,15360,11974,11846,11629,15360,11958,11838,11629,15360,11950,11838,11637,15360,11814,11701,11525,15360,11581,11492,11332,15360,11645,11541,11380,15360,11806,11701,11533,15360,11902,11806,11637,15360,11950,11862,11717,15360,12014,11934,11790,15360,11942,11862,11725,15360,11565,11492,11388,15360,11292,11191,11015,15360,11231,11111,10950,15360,11159,11047,10894,15360,11119,11006,10854,15360,11127,11023,10878,15360,11159,11055,10902,15360,11135,11031,10894,15360,11111,11006,10878,15360,11095,10990,10870,15360,11095,10998,10886,15360,11071,10966,10846,15360,11111,11006,10902,15360,11191,11095,10974,15360,11268,11159,11031,15360,11284,11191,11063,15360,11292,11207,11063,15360,11300,11223,11079,15360,11332,11268,11143,15360,11316,11255,11127,15360,11316,11255,11143,15360,11308,11239,11127,15360,11316,11255,11159,15360,11300,11223,11127,15360,11292,11207,11095,15360,11300,11223,11111,15360,11300,11223,11095,15360,11300,11223,11095,15360,11308,11239,11111,15360,11300,11223,11111,15360,11292,11207,11111,15360,11264,11167,11071,15360,11215,11127,11047,15360,11135,11055,10966,15360,11015,10934,10846,15360,10918,10838,10733,15360,10982,10894,10782,15360,10974,10886,10766,15360,10982,10894,10766,15360,10958,10862,10749,15360,10982,10886,10774,15360,10958,10862,10758,15360,10958,10862,10749,15360,11015,10910,10790,15360,11023,10910,10774,15360,11079,10958,10806,15360,11103,10974,10798,15360,11191,11047,10846,15360,11468,11388,11276,15360,11846,11765,11637,15360,12006,11918,11782,15360,11998,11910,11782,15360,11902,11822,11693,15360,11838,11749,11637,15360,11782,11709,11605,15360,11806,11741,11645,15360,11782,11717,11629,15360,11773,11717,11621,15360,11870,11806,11701,15360,11942,11862,11757,15360,12183,12103,11974,15360,11974,11894,11765,15360,11476,11404,11308,15360,11268,11143,10966,15360,11183,11063,10902,15360,11111,10998,10854,15360,11055,10942,10806,15360,11023,10910,10766,15360,11047,10934,10782,15360,11039,10926,10782,15360,11079,10966,10830,15360,11031,10918,10782,15360,11031,10926,10806,15360,10990,10894,10782,15360,10974,10886,10790,15360,10966,10870,10774,15360,11006,10902,10806,15360,11039,10942,10838,15360,11127,11023,10910,15360,11175,11079,10958,15360,11191,11087,10958,15360,11207,11095,10958,15360,11268,11143,11015,15360,11276,11175,11047,15360,11284,11191,11079,15360,11292,11191,11079,15360,11276,11175,11079,15360,11239,11135,11031,15360,11268,11159,11047,15360,11215,11111,11006,15360,11239,11127,11015,15360,11255,11143,11031,15360,11223,11119,11015,15360,11199,11103,10998,15360,11175,11087,10982,15360,11143,11047,10958,15360,11031,10942,10854,15360,10958,10878,10790,15360,10910,10830,10741,15360,10942,10862,10758,15360,10926,10838,10733,15360,10854,10758,10637,15360,10918,10830,10709,15360,10910,10822,10717,15360,10942,10846,10749,15360,10942,10854,10741,15360,10942,10854,10749,15360,10966,10870,10758,15360,10966,10870,10758,15360,10958,10854,10733,15360,10998,10886,10741,15360,10942,10830,10677,15360,11039,10918,10749,15360,11095,10974,10806,15360,11308,11223,11031,15360,11468,11396,11292,15360,11605,11533,11428,15360,11701,11621,11525,15360,11693,11629,11541,15360,11685,11621,11549,15360,11685,11629,11549,15360,11629,11565,11484,15360,11589,11533,11444,15360,11364,11308,11191,15360,11191,11087,10958,15360,11135,11031,10902,15360,11135,11031,10894,15360,11055,10950,10830,15360,11015,10910,10782,15360,10958,10854,10733,15360,10942,10838,10717,15360,10974,10870,10733,15360,10982,10878,10749,15360,10990,10886,10758,15360,11015,10910,10798,15360,10966,10862,10758,15360,10950,10854,10758,15360,10910,10822,10733,15360,10894,10798,10709,15360,10902,10814,10725,15360,10934,10846,10758,15360,10910,10822,10733,15360,10950,10854,10749,15360,10974,10878,10766,15360,11047,10942,10830,15360,11095,10990,10878,15360,11167,11055,10942,15360,11199,11103,10990,15360,11191,11087,10982,15360,11151,11047,10950,15360,11135,11031,10934,15360,11095,10998,10902,15360,11143,11047,10950,15360,11079,10990,10894,15360,11079,10990,10902,15360,11103,11006,10910,15360,11079,10982,10886,15360,11023,10926,10822,15360,10982,10894,10798,15360,10958,10870,10782,15360,10910,10814,10725,15360,10926,10838,10741,15360,10934,10838,10733,15360,10950,10854,10749,15360,10886,10798,10709,15360,10910,10814,10709,15360,10926,10830,10725,15360,10910,10814,10701,15360,10862,10774,10677,15360,10950,10854,10733,15360,10926,10830,10717,15360,10926,10838,10725,15360,10926,10830,10725,15360,10894,10798,10685,15360,10926,10830,10701,15360,10958,10854,10717,15360,10934,10830,10685,15360,10950,10846,10709,15360,10974,10862,10717,15360,10942,10830,10685,15360,10958,10846,10701,15360,11006,10894,10749,15360,10950,10846,10725,15360,10958,10862,10741,15360,10894,10806,10701,15360,10854,10774,10669,15360,10886,10806,10701,15360,10862,10790,10693,15360,10878,10806,10717,15360,10982,10902,10798,15360,10990,10902,10798,15360,10950,10862,10758,15360,10942,10846,10733,15360,10870,10774,10669,15360,10894,10798,10693,15360,10918,10830,10725,15360,10894,10806,10701,15360,10926,10830,10733,15360,10902,10830,10725,15360,10870,10790,10693,15360,10886,10814,10725,15360,10814,10741,10661,15360,10838,10766,10677,15360,10822,10741,10661,15360,10822,10741,10669,15360,10862,10790,10709,15360,10846,10758,10669,15360,10894,10798,10693,15360,10974,10878,10766,15360,10966,10870,10766,15360,11023,10926,10814,15360,11079,10974,10862,15360,11006,10910,10814,15360,10950,10862,10766,15360,10982,10894,10798,15360,10958,10862,10774,15360,10958,10870,10782,15360,10910,10830,10741,15360,10950,10862,10766,15360,10982,10886,10790,15360,10918,10822,10725,15360,10886,10798,10701,15360,10854,10766,10669,15360,10894,10806,10709,15360,10926,10830,10725,15360,10926,10830,10725,15360,10958,10862,10749,15360,10958,10862,10749,15360,10894,10806,10717,15360,10902,10814,10717,15360,10878,10790,10677,15360,10942,10838,10717,15360,10918,10814,10701,15360,10886,10790,10661,15360,10942,10838,10717,15360,10950,10854,10725,15360,10950,10854,10725,15360,10910,10814,10693,15360,10910,10814,10685,15360,10942,10838,10709,15360,10894,10790,10661,15360,10910,10806,10669,15360,10822,10725,10597,15360,10749,10661,10541,15360,10830,10733,10613,15360,10838,10741,10629,15360,10806,10709,10597,15360,10854,10766,10653,15360,10862,10774,10669,15360,10798,10725,10629,15360,10822,10749,10653,15360,10854,10782,10693,15360,10806,10741,10661,15360,10862,10790,10701,15360,10870,10790,10685,15360,10870,10790,10693,15360,10878,10790,10677,15360,10862,10782,10677,15360,10870,10790,10693,15360,10870,10782,10685,15360,10894,10814,10709,15360,10886,10814,10709,15360,10846,10782,10685,15360,10741,10669,10573,15360,10766,10693,10589,15360,10709,10637,10541,15360,10741,10669,10589,15360,10741,10677,10589,15360,10709,10637,10557,15360,10774,10701,10613,15360,10862,10774,10677,15360,11006,10918,10806,15360,11006,10902,10782,15360,10974,10870,10749,15360,10958,10854,10733,15360,10934,10838,10725,15360,10934,10838,10733,15360,10934,10838,10725,15360,10886,10790,10685,15360,10854,10766,10661,15360,10886,10798,10701,15360,10838,10749,10645,15360,10878,10782,10661,15360,10822,10725,10613,15360,10822,10717,10605,15360,10846,10749,10629,15360,10854,10749,10637,15360,10950,10854,10733,15360,10958,10854,10741,15360,10910,10806,10693,15360,10926,10822,10693,15360,10934,10838,10725,15360,10910,10822,10709,15360,10910,10822,10709,15360,10886,10782,10661,15360,10910,10814,10677,15360,10910,10806,10677,15360,10926,10822,10685,15360,10958,10854,10717,15360,10974,10870,10725,15360,10926,10830,10693,15360,10926,10830,10693,15360,10918,10822,10693,15360,10934,10838,10701,15360,10918,10814,10685,15360,10878,10782,10653,15360,10870,10774,10645,15360,10838,10749,10629,15360,10806,10717,10605,15360,10822,10733,10621,15360,10822,10733,10621,15360,10846,10758,10653,15360,10846,10766,10653,15360,10822,10741,10629,15360,10806,10733,10629,15360,10806,10725,10621,15360,10790,10709,10605,15360,10766,10693,10589,15360,10814,10741,10629,15360,10846,10766,10653,15360,10838,10758,10653,15360,10878,10790,10677,15360,10894,10798,10685,15360,10830,10741,10629,15360,10830,10758,10653,15360,10798,10725,10629,15360,10806,10733,10629,15360,10717,10637,10525,15360,10661,10581,10476,15360,10701,10621,10517,15360,10733,10661,10565,15360,10782,10685,10557,15360,10862,10758,10613,15360,10974,10862,10725,15360,10958,10846,10709,15360,11006,10902,10766,15360,11006,10902,10774,15360,11039,10934,10814,15360,11006,10902,10790,15360,11006,10910,10790,15360,10950,10854,10741,15360,10934,10830,10709,15360,10918,10814,10701,15360,10854,10758,10653,15360,10918,10814,10701,15360,10870,10766,10645,15360,10830,10733,10621,15360,10934,10830,10709,15360,10990,10886,10758,15360,10950,10838,10717,15360,10910,10814,10701,15360,10926,10822,10693,15360,10934,10830,10709,15360,10878,10774,10653,15360,10934,10830,10701,15360,10926,10822,10693,15360,10878,10782,10661,15360,10878,10782,10661,15360,10862,10766,10621,15360,10886,10782,10645,15360,10886,10782,10653,15360,10926,10822,10701,15360,10902,10806,10685,15360,10926,10822,10701,15360,10918,10814,10685,15360,10878,10782,10645,15360,10910,10806,10669,15360,10854,10758,10621,15360,10886,10790,10645,15360,10854,10758,10629,15360,10830,10741,10613,15360,10918,10814,10685,15360,10862,10766,10645,15360,10830,10741,10613,15360,10806,10717,10597,15360,10741,10661,10557,15360,10774,10693,10581,15360,10749,10669,10557,15360,10774,10693,10581,15360,10766,10685,10573,15360,10790,10709,10597,15360,10782,10701,10589,15360,10790,10709,10597,15360,10838,10749,10621,15360,10870,10774,10645,15360,10894,10790,10661,15360,10878,10782,10653,15360,10846,10741,10613,15360,10790,10693,10557,15360,10814,10717,10597,15360,10790,10701,10581,15360,10741,10645,10525,15360,10717,10629,10509,15360,10774,10685,10573,15360,10725,10637,10525,15360,10854,10749,10621,15360,10950,10846,10701,15360,10966,10854,10709,15360,10934,10814,10677,15360,10926,10822,10701,15360,10982,10878,10766,15360,10998,10894,10782,15360,10990,10878,10766,15360,10998,10894,10782,15360,10998,10886,10774,15360,10998,10886,10758,15360,11006,10894,10774,15360,10942,10838,10733,15360,10958,10854,10741,15360,10958,10854,10749,15360,11006,10902,10790,15360,11015,10902,10798,15360,10982,10870,10758,15360,10998,10894,10782,15360,10974,10870,10758,15360,11006,10902,10790,15360,10998,10894,10774,15360,10974,10870,10758,15360,10950,10854,10741,15360,10878,10790,10693,15360,10902,10814,10701,15360,10918,10822,10709,15360,10838,10733,10613,15360,10878,10782,10661,15360,10934,10838,10717,15360,10902,10806,10693,15360,10918,10822,10709,15360,10926,10830,10709,15360,10838,10733,10605,15360,10910,10806,10661,15360,10942,10838,10693,15360,10886,10782,10645,15360,10886,10782,10637,15360,10854,10749,10621,15360,10926,10830,10709,15360,10966,10862,10741,15360,10846,10749,10629,15360,10830,10733,10605,15360,10854,10758,10637,15360,10822,10725,10605,15360,10886,10790,10661,15360,10902,10806,10669,15360,10918,10814,10677,15360,10830,10733,10605,15360,10806,10717,10589,15360,10870,10774,10645,15360,10934,10838,10709,15360,10958,10862,10733,15360,10886,10790,10661,15360,10894,10798,10661,15360,10958,10854,10709,15360,10934,10830,10709,15360,10814,10717,10581,15360,10862,10758,10613,15360,10854,10741,10589,15360,10814,10717,10573,15360,10886,10782,10645,15360,10814,10725,10597,15360,10862,10766,10637,15360,10910,10806,10669,15360,10942,10838,10709,15360,10966,10862,10733,15360,10974,10870,10741,15360,10974,10870,10749,15360,10958,10862,10749,15360,11031,10934,10822,15360,10998,10894,10782,15360,10974,10870,10766,15360,11023,10918,10814,15360,11039,10926,10822,15360,10958,10846,10741,15360,10918,10814,10693,15360,10966,10870,10741,15360,10982,10886,10766,15360,10982,10878,10766,15360,10942,10846,10733,15360,10958,10862,10758,15360,10950,10854,10758,15360,10934,10830,10717,15360,10966,10862,10733,15360,10942,10846,10725,15360,10934,10846,10733,15360,10934,10846,10733,15360,10878,10798,10693,15360,10886,10798,10693,15360,10910,10814,10709,15360,10942,10846,10733,15360,10838,10733,10597,15360,10878,10774,10645,15360,10918,10822,10701,15360,10878,10782,10653,15360,10894,10790,10661,15360,10934,10838,10725,15360,10958,10854,10725,15360,10966,10862,10733,15360,10910,10806,10685,15360,10982,10878,10758,15360,10942,10854,10749,15360,10934,10838,10733,15360,10918,10814,10701,15360,10894,10798,10669,15360,10894,10798,10669,15360,10814,10725,10605,15360,10902,10798,10669,15360,10814,10725,10605,15360,10894,10798,10685,15360,10958,10862,10749,15360,10910,10814,10701,15360,10910,10806,10685,15360,10918,10814,10693,15360,10926,10822,10709,15360,10894,10790,10661,15360,10902,10806,10677,15360,10902,10806,10685,15360,10934,10838,10717,15360,10934,10838,10701,15360,10934,10838,10717,15360,10950,10854,10725,15360,10894,10798,10661,15360,10862,10749,10597,15360,10894,10798,10677,15360,10878,10782,10661,15360,10926,10838,10717,15360,10926,10838,10717,15360,10918,10822,10709,15360,10934,10838,10733,15360,10926,10838,10733,15360,10958,10870,10766,15360,10942,10854,10749,15360,10958,10870,10774,15360,10974,10878,10774,15360,10958,10854,10741,15360,10950,10846,10741,15360,10950,10854,10758,15360,10934,10838,10733,15360,10942,10846,10725,15360,10966,10862,10741,15360,10926,10838,10733,15360,10958,10862,10749,15360,10910,10822,10709,15360,10942,10854,10758,15360,10926,10838,10733,15360,10910,10822,10717,15360,10934,10838,10733,15360,10934,10846,10733,15360,10902,10814,10709,15360,10926,10830,10717,15360,10918,10822,10709,15360,10838,10749,10637,15360,10878,10790,10677,15360,10942,10846,10733,15360,10926,10822,10701,15360,10958,10862,10749,15360,10886,10790,10685,15360,10918,10814,10693,15360,10910,10814,10693,15360,10902,10806,10701,15360,10878,10774,10637,15360,10798,10693,10565,15360,10822,10725,10597,15360,10934,10838,10709,15360,10958,10854,10725,15360,10886,10790,10669,15360,10910,10806,10677,15360,10886,10782,10645,15360,10830,10725,10597,15360,10822,10717,10581,15360,10862,10758,10637,15360,10878,10782,10669,15360,10926,10822,10709,15360,10974,10878,10774,15360,10966,10870,10758,15360,10918,10822,10709,15360,10846,10749,10645,15360,10894,10798,10693,15360,10918,10822,10709,15360,10974,10878,10774,15360,10918,10822,10717,15360,10982,10886,10774,15360,10974,10878,10758,15360,10950,10854,10741,15360,10958,10854,10725,15360,10982,10886,10766,15360,10918,10822,10701,15360,10878,10782,10669,15360,10886,10790,10669,15360,10934,10838,10717,15360,10950,10854,10741,15360,10934,10838,10733,15360,10982,10886,10782,15360,10886,10798,10701,15360,10870,10782,10685,15360,10894,10814,10717,15360,10910,10822,10725,15360,10934,10838,10733,15360,10950,10846,10741,15360,10934,10838,10725,15360,10934,10846,10749,15360,10902,10814,10717,15360,10878,10790,10677,15360,10878,10782,10669,15360,10854,10766,10645,15360,10838,10749,10629,15360,10902,10814,10701,15360,10910,10814,10693,15360,10902,10798,10669,15360,10910,10806,10677,15360,10886,10782,10653,15360,10854,10749,10629,15360,10870,10774,10653,15360,10974,10870,10758,15360,10990,10878,10758,15360,10918,10822,10709,15360,10926,10838,10725,15360,10958,10854,10733,15360,10894,10790,10653,15360,10822,10725,10605,15360,10878,10782,10661,15360,10974,10870,10749,15360,10902,10806,10677,15360,10934,10838,10725,15360,10870,10774,10653,15360,10798,10701,10581,15360,10854,10749,10621,15360,10894,10798,10669,15360,10934,10822,10685,15360,10942,10830,10701,15360,10910,10806,10669,15360,10870,10758,10629,15360,10886,10774,10645,15360,10950,10838,10701,15360,10966,10870,10749,15360,10886,10790,10685,15360,10870,10782,10677,15360,10934,10838,10733,15360,10934,10838,10725,15360,10822,10725,10621,15360,10878,10790,10677,15360,10894,10798,10693,15360,10822,10733,10629,15360,10894,10798,10685,15360,10998,10902,10790,15360,11015,10918,10806,15360,10950,10854,10741,15360,10950,10846,10741,15360,10934,10838,10733,15360,10942,10846,10749,15360,10910,10822,10725,15360,10846,10758,10653,15360,10878,10790,10685,15360,10894,10798,10701,15360,10862,10774,10669,15360,10814,10725,10621,15360,10846,10758,10645,15360,10870,10774,10661,15360,10870,10774,10677,15360,10878,10790,10693,15360,10878,10782,10677,15360,10830,10741,10637,15360,10870,10782,10677,15360,10966,10870,10766,15360,11015,10918,10814,15360,10910,10814,10701,15360,10942,10846,10725,15360,10950,10846,10725,15360,10942,10838,10725,15360,10934,10830,10701,15360,10910,10798,10677,15360,10886,10782,10653,15360,10838,10733,10597,15360,10902,10806,10669,15360,10830,10733,10613,15360,10838,10741,10621,15360,10838,10741,10621,15360,10894,10798,10669,15360,10934,10830,10685,15360,10886,10790,10669,15360,10902,10806,10685,15360,10854,10749,10637,15360]));function Do(){if(be.isBrowser){const h=document.createElement("div");return h.setAttribute("style","height: 1in; visibility: hidden; position: absolute; margin: 0; padding: 0;"),document.body.appendChild(h),.0254/h.clientHeight}else return .0254/96}const Es={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:Do()},dn={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},un=h=>h===2?"²":h===3?"³":"",_s=(h,t=1)=>dn[h]+un(t),Bo=(h,t,e,i=1)=>(e==null&&(e=t),e===t?{value:h,unit:_s(e)}:{value:h*Math.pow(Es[t]/Es[e],i),unit:_s(e)+un(i)});var fn=(h=>(h.Top="Top",h.Bottom="Bottom",h.Front="Front",h.Back="Back",h.Left="Left",h.Right="Right",h))(fn||{});class Lo{static getCameraDirectionByView(t){const e=new d.Vector3(1,0,0);return t==="Top"?e.set(0,-1,0):t==="Bottom"?e.set(0,1,0):t==="Front"?e.set(0,0,-1):t==="Back"?e.set(0,0,1):t==="Left"?e.set(1,0,0):t==="Right"&&e.set(-1,0,0),e}}var re=(h=>(h.MouseClick="mouseclick",h.LayoutChange="layoutchange",h.ModelLoad="modelload",h.BeforeRender="beforerender",h.AfterRender="afterrender",h.OnAnimate="onanimate",h.CameraChange="camerachange",h.ControlChange="controlchange",h.BoxSelectActivate="boxselectactivate",h.BoxSelectDeactivate="boxselectdeactivate",h.PickMarkupActivate="pickmarkupactivate",h.PickMarkupDeactivate="pickmarkupdeactivate",h.MarkupActivate="markupactivate",h.MarkupDeactivate="markupdeactivate",h.MarkupAdd="markupadd",h.MarkupUpdate="markupupdate",h.MarkupRemove="markupremove",h.BeforeRemoveMarkup="beforeremovemarkup",h.MeasurementActivate="measurementactivate",h.MeasurementDeactivate="measurementdeactivate",h.MeasurementAdd="measurementadd",h.MeasurementRemove="measurementremove",h.HotpointClick="hotpointclick",h))(re||{});const or={};class xi extends mt{constructor(e){super();p(this,"viewer");p(this,"drawableLists");p(this,"canvas");p(this,"context");p(this,"frustum");p(this,"projScreenMatrix");this.drawableLists=[],this.frustum=new d.Frustum,this.projScreenMatrix=new d.Matrix4,this.viewer=e,this.init()}static _registerDrawableClass(e){const i=e;or[i.prototype.getClassType()]=e}static createDrawable(e){const i=or[e.type];if(!i)throw new Error("Invalid drawable type: "+i);const s=e.points.map(n=>new d.Vector3(n[0],n[1],n[2]||0)),r=new i(e.id,s);return r.setData(e),r}get is3d(){return this.viewer.is3d()}get container(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}init(){this.initCanvas(),this.viewer.addEventListener(re.AfterRender,()=>{this.projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projScreenMatrix),this.render()})}initCanvas(){const e=this.viewer.getViewerConfig();if(be.isBrowser&&!e.context2d){const i=this.canvas=document.createElement("canvas"),s=this.viewer.viewerContainer;s.appendChild(i),i.classList.add("overlay-renderer"),i.style.pointerEvents="none",i.style.position="absolute",i.style.left="0px",i.style.top="0px",i.style.userSelect="none",this.context=i.getContext("2d",{willReadFrequently:!0});const{clientWidth:r,clientHeight:n}=s;this.setSize(r,n)}else e.context2d&&(this.context=e.context2d,this.canvas=be.creatReactNativeCanvas(this.context),this.context.canvas||(this.context.canvas=this.canvas))}toHighDpr(e,i,s){const r=Math.max(window.devicePixelRatio||1,1),n=this.canvas;return n.width=i*r,n.height=s*r,e.scale(r,r),n.style.width=i+"px",n.style.height=s+"px",e}clearCanvas(){this.context?.clearRect(0,0,this.canvas?.width??0,this.canvas?.height??0)}addDrawableList(e){this.drawableLists.push(e)}render(){if(!this.canvas||!this.context||this.drawableLists.length<1)return;this.clearCanvas();const e=this.getSortedDrawables(!1);if(e.length===0)return;const i=new d.Sphere,s=this.viewer.getPixelSizeInWorldCoord();for(let r=0;r<e.length;r++){const n=e[r];n.setTolerance(s),!(!n.visible||(n.getBounds().getBoundingSphere(i),n.needsFrustumCulled&&!this.frustum.intersectsSphere(i)))&&n.render(this.context,this.camera)}}setSize(e,i){const s=this.canvas;s.width=e,s.height=i,s.style.width=e+"px",s.style.height=i+"px",this.toHighDpr(this.context,e,i)}getSortedDrawables(e=!1){const i=[];return this.drawableLists.forEach(s=>{let r=Array.from(s.getDrawables().values());e&&(r=r.filter(n=>n.visible)),r.length>0&&i.push(...r)}),i.sort((s,r)=>s.renderOrder===r.renderOrder?r.getCenter().distanceTo(this.camera.position)-s.getCenter().distanceTo(this.camera.position):s.renderOrder-r.renderOrder),i}getDrawablesByDrawableListAndPosition(e,i){return this.is3d||(i.z=0),e.getDrawableByPosition(i,this.raycaster)}getDrawablesByPosition(e){this.is3d||(e.z=0);const i=this.getSortedDrawables(),s=[];for(let r=0;r<i.length;r++){const n=i[r];n.isPointInPath(e,this.raycaster)&&s.push(n)}return s}getDrawableById(e){return this.getSortedDrawables().find(s=>s.id===e)}measureTextLength(e,i){const s=this.context,r=e.split(`
535
+ `);let n=0;for(let a=0;a<r.length;a++){const o=r[a];s.save(),s.font=i;const l=s.measureText(o).width;s.restore(),n=Math.max(n,l)}return n}getImage(e){this.clearCanvas();const i=this.getSortedDrawables();for(let s=0;s<i.length;s++){const r=i[s];e(r)&&r.render(this.context,this.camera)}return z.canvasToImage(this.canvas)}getCanvas(){return this.canvas}destroy(){this.drawableLists.forEach(e=>e.clear()),this.drawableLists=[],this.canvas&&(this.viewer.viewerContainer?.removeChild(this.canvas),this.canvas=void 0)}}class bi extends mt{constructor(e){super();p(this,"category");p(this,"drawableMap");this.drawableMap=new Map,this.category=e}addDrawable(e){this.drawableMap.set(e.id,e),this.dispatchEvent("add",e.getData())}updateDrawable(e,i){e.setData(i),this.dispatchEvent("update",e.getData())}removeDrawable(e){this.drawableMap.delete(e.id),this.dispatchEvent("remove",e.getData())}getDrawableById(e){return this.drawableMap.get(e)}clear(){this.drawableMap.forEach(e=>this.removeDrawable(e))}getDrawables(){return this.drawableMap}getDrawableDatas(){return Array.from(this.drawableMap).map(([,e])=>e.getData())}setDrawableDatas(e){for(let i=0;i<e.length;i++){const s=e[i],r=xi.createDrawable(s);this.addDrawable(r)}}getDrawableByPosition(e,i){let s;for(const[,r]of this.drawableMap)if(r.visible&&r.isPointInPath(e,i)){s=r;break}return s}}class pt extends mt{constructor(e){super();p(this,"DEFAULT_LINE_WIDTH",1);p(this,"DEFAULT_STROKE_STYLE",[0,0,0,1]);p(this,"DEFAULT_FILL_STYLE",[0,0,0,1]);p(this,"id");p(this,"lineWidth");p(this,"lineColor");p(this,"fillColor");p(this,"x");p(this,"y");p(this,"width");p(this,"height");p(this,"points");p(this,"userData");p(this,"tolerance");p(this,"visible");p(this,"selected");p(this,"renderOrder");p(this,"needsFrustumCulled");p(this,"editPointSize");p(this,"editPointFillColor");p(this,"editPointStrokeColor");p(this,"matrix");p(this,"ctx");this.lineWidth=this.DEFAULT_LINE_WIDTH,this.lineColor=this.DEFAULT_STROKE_STYLE,this.fillColor=this.DEFAULT_FILL_STYLE,this.x=0,this.y=0,this.width=0,this.height=0,this.points=[],this.userData={},this.tolerance=1,this.visible=!0,this.selected=!1,this.renderOrder=1,this.needsFrustumCulled=!0,this.editPointSize=3,this.editPointFillColor="#ffffff",this.editPointStrokeColor="#939ea4",this.matrix=new d.Matrix4,this.id=e||z.guid()}setTolerance(e){this.tolerance=e}render(e,i){this.ctx=e,this.draw(e,i),this.selected&&this.drawSelect(e,i)}getData(){return{id:this.id,points:this.points.map(e=>[e.x,e.y]),lineWidth:this.lineWidth,lineColor:this.lineColor,fillColor:this.fillColor,type:this.getClassType()}}setData(e){this.id=e.id,this.setLineWidth(e.lineWidth),this.setLineColor(e.lineColor),this.setFillColor(e.fillColor)}getVertexes(){const e=new d.Vector3(this.x,this.y,0),i=new d.Vector3(this.x+this.width,this.y,0),s=new d.Vector3(this.x+this.width,this.y-this.height,0),r=new d.Vector3(this.x,this.y-this.height,0);return[e,i,s,r]}setLineWidth(e){this.lineWidth=e||this.DEFAULT_LINE_WIDTH}setLineColor(e){this.lineColor=e||this.DEFAULT_STROKE_STYLE}setFillColor(e){this.fillColor=e||this.DEFAULT_FILL_STYLE}isSelected(){return this.selected}getCenter(){return this.getBounds().getCenter(new d.Vector3)}transToScreenCoord(e,i){return this.ctx?pe.world2Screen(e,i,this.ctx.canvas):new d.Vector2}drawBounds(e,i){const{min:s,max:r}=this.getBounds(),n=[],a=(o,l,c)=>n.push(new d.Vector3(o,l,c));a(r.x,r.y,r.z),a(s.x,r.y,r.z),a(s.x,s.y,r.z),a(r.x,s.y,r.z),a(r.x,r.y,s.z),a(s.x,r.y,s.z),a(s.x,s.y,s.z),a(r.x,s.y,s.z),a(s.x,r.y,r.z),a(s.x,s.y,r.z),a(r.x,r.y,r.z),a(r.x,s.y,r.z),a(r.x,r.y,s.z),a(r.x,s.y,s.z),a(s.x,r.y,s.z),a(s.x,s.y,s.z),a(s.x,r.y,r.z),a(s.x,r.y,s.z),a(r.x,r.y,r.z),a(r.x,r.y,s.z),a(s.x,s.y,r.z),a(s.x,s.y,s.z),a(r.x,s.y,r.z),a(r.x,s.y,s.z),e.save(),e.strokeStyle="yellow",e.beginPath(),n.forEach((o,l)=>{const c=this.transToScreenCoord(o,i);l%2===0?e.moveTo(c.x,c.y):e.lineTo(c.x,c.y)}),e.closePath(),e.stroke(),e.restore()}drawCenter(e,i){const s=this.transToScreenCoord(this.getCenter(),i);e.save(),e.fillStyle="yellow",e.beginPath(),e.arc(s.x,s.y,5,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}getBounds(){const e=this.getVertexes();return new d.Box3().setFromPoints(e)}}const as=new d.Vector3;class Je extends pt{constructor(e,i,s=[1,0,0,1],r){super(e);p(this,"boxes");p(this,"lineSegments");this.lineSegments=[],this.boxes=Je.expandBoxesWithGap(i),this.lineColor=s,this.fillColor=r??[s[0],s[1],s[2],.12],this.lineWidth=2,this.calculateCloudLineSegments(this.boxes)}static expandBoxesWithGap(e){return e.map(i=>{const s=i.clone(),r=s.getSize(as),n=Math.max(r.x,r.y)*.12||1;return s.expandByScalar(n)})}calculateCloudLineSegments(e){for(let i=0;i<e.length;i++){const s=e[i],r=[new d.Vector3(s.min.x,s.min.y),new d.Vector3(s.max.x,s.min.y),new d.Vector3(s.max.x,s.max.y),new d.Vector3(s.min.x,s.max.y),new d.Vector3(s.min.x,s.min.y)],n=as.subVectors(r[0],r[2]).length()/10||1e-4,a=[];for(let o=0;o<r.length-1;o++){const l=r[o],c=r[o+1],u=as.subVectors(c,l),f=u.length(),m=u.normalize(),g=Math.ceil(f/n);for(let x=0;x<g;x++)a.push(l.clone().add(m.clone().multiplyScalar(n*x)))}a.push(a[0]),this.lineSegments?.push(a)}}draw(e,i){e.save(),e.lineWidth=this.lineWidth,e.strokeStyle=qt.rgba2Color(this.lineColor),e.fillStyle=qt.rgba2Color(this.fillColor);for(let s=0;s<this.lineSegments.length;s++){const r=this.boxes[s];r&&this.fillRect(e,i,r);const n=this.lineSegments[s];this.drawBox(e,i,n)}e.restore()}fillRect(e,i,s){const r=[new d.Vector3(s.min.x,s.min.y),new d.Vector3(s.max.x,s.min.y),new d.Vector3(s.max.x,s.max.y),new d.Vector3(s.min.x,s.max.y)];e.beginPath();for(let n=0;n<r.length;n++){const a=this.transToScreenCoord(r[n],i);n===0?e.moveTo(a.x,a.y):e.lineTo(a.x,a.y)}e.closePath(),e.fill()}drawBox(e,i,s){e.beginPath();for(let r=0;r<s.length-1;r++){const n=this.transToScreenCoord(s[r],i),a=this.transToScreenCoord(s[r+1],i),o=Je.getControlPointByTwoPoints(a,n);r===0&&e.moveTo(n.x,n.y),e.quadraticCurveTo(o.x,o.y,a.x,a.y)}e.stroke()}static getControlPointByTwoPoints(e,i){const s=new d.Vector2().subVectors(i,e),r=s.angle(),n=s.length(),a=d.MathUtils.degToRad(45),o=n/2/Math.cos(a);return new d.Vector2(e.x+o*Math.cos(a-r),e.y-o*Math.sin(a-r))}drawSelect(e,i){throw new Error("Method not implemented.")}isPointInPath(e){return!1}getBounds(){const e=new d.Box3;for(let i=0;i<this.boxes.length;i++){const s=this.boxes[i];e.union(s)}return e}getClassType(){return"CompareDrawable"}}xi._registerDrawableClass(Je);const Ro=[0,16711680,16776960,65280,65535,255,16711935,16777215,8421504,12632256,16711680,16744319,13369344,13395558,10027008,10046540,8323072,8339263,4980736,4990502,16727808,16752511,13382400,13401958,10036736,10051404,8331008,8343359,4985600,4992806,16744192,16760703,13395456,13408614,10046464,10056268,8339200,8347455,4990464,4995366,16760576,16768895,13408512,13415014,10056192,10061132,8347392,8351551,4995328,4997670,16776960,16777087,13421568,13421670,10000384,10000460,8355584,8355647,5000192,5000230,12582656,14679935,10079232,11717734,7510016,8755276,6258432,7307071,3755008,4344870,8388352,12582783,6736896,10079334,5019648,7510092,4161280,6258495,2509824,3755046,4194048,10485631,3394560,8375398,2529280,6264908,2064128,5209919,1264640,3099686,65280,8388479,52224,6736998,38912,5019724,32512,4161343,19456,2509862,65343,8388511,52275,6737023,38950,5019743,32543,4161359,19475,2509871,65407,8388543,52326,6737049,38988,5019762,32575,4161375,19494,2509881,65471,8388575,52377,6737074,39026,5019781,32607,4161391,19513,2509890,65535,8388607,52428,6737100,39064,5019800,32639,4161407,19532,2509900,49151,8380415,39372,6730444,29336,5014936,24447,4157311,14668,2507340,32767,8372223,26316,6724044,19608,5010072,16255,4153215,9804,2505036,16383,8364031,13260,6717388,9880,5005208,8063,4149119,4940,2502476,255,8355839,204,6710988,152,5000344,127,4145023,76,2500172,4129023,10452991,3342540,8349388,2490520,6245528,2031743,5193599,1245260,3089996,8323327,12550143,6684876,10053324,4980888,7490712,4128895,6242175,2490444,3745356,12517631,14647295,10027212,11691724,7471256,8735896,6226047,7290751,3735628,4335180,16711935,16744447,13369548,13395660,9961624,9981080,8323199,8339327,4980812,4990540,16711871,16744415,13369497,13395634,9961586,9981061,8323167,8339311,4980793,4990530,16711807,16744383,13369446,13395609,9961548,9981042,8323135,8339295,4980774,4990521,16711743,16744351,13369395,13395583,9961510,9981023,8323103,8339279,4980755,4990511,3355443,5987163,8684676,11382189,14079702,16777215],Fo=["PROXY","REGION","INSERT","HATCH"];function Nt(h){return Ro[h]}function Ie(h){const t={};let e=h.lastReadGroup,i=e.code;if(t.x=e.value,i+=10,e=h.next(),e.code!==i)throw new Error("Expected code for point value to be "+i+" but got "+e.code);return t.y=e.value,i+=10,e=h.next(),e.code!==i||(t.z=e.value,h.next()),t}const zo="OriginalHandle",jo="OriginalType",Vo="Outlines";function Q(h,t){switch(t.code){case 0:h.type=t.value;break;case 5:h.handle=t.value;break;case 6:h.lineType=(t.value||"BYLAYER").toUpperCase();break;case 8:h.layer=t.value||"0";break;case 39:h.thickness=t.value;break;case 48:h.lineTypeScale=t.value>0?t.value:1;break;case 60:h.visible=t.value!==1;break;case 62:if(!h.isTrueColor){const e=t.value;h.colorIndex=e,e<0&&console.warn("[DxfParser] Negative colorIndex indicates layer is off or BYBLOCK/BYLAYER"),h.color=Nt(Math.abs(e))}break;case 67:h.inPaperSpace=t.value===1;break;case 330:h.ownerHandle=t.value;break;case 370:h.lineweight=t.value;break;case 410:h.layoutName=t.value;break;case 420:h.isTrueColor=!0,h.color=t.value;break;case 1e3:if(t.value&&typeof t.value=="string"){if(t.value.includes(zo)){const e=t.value.split(":").map(i=>i.trim());h.extendedData||(h.extendedData={}),h.extendedData.originalHandle=e[1]}if(t.value.includes(Vo)&&(h.extendedData||(h.extendedData={}),h.extendedData.outlines=[]),t.value.includes(jo)){const e=t.value.split(":").map(i=>i.trim());h.extendedData||(h.extendedData={}),h.extendedData.originalType=e[1]}}break;case 1001:break;case 92:case 331:case 347:break;default:return!1}return!0}function Xt(h,t){switch(t.code){case 0:h.type=t.value;break;case 5:h.handle=t.value;break;case 330:h.ownerHandle=t.value;break;case 1e3:break;case 1001:break;default:return!1}return!0}const Fs="BYLAYER",mi="BYBLOCK";var ge=(h=>(h[h.Mesh=-1]="Mesh",h[h.MeshWithPattern=0]="MeshWithPattern",h[h.LineWithWidth=1]="LineWithWidth",h[h.Line=2]="Line",h[h.LineWithPattern=3]="LineWithPattern",h[h.Point=4]="Point",h[h.Text=5]="Text",h))(ge||{});const oi=["INSERT","DIMENSION"];function Uo(h,t,e,i,s){if(!t)return 0;const r=/[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff]/.test(h),n=s&&s.toLowerCase().endsWith(".shx");let a=0,o=0;if(t.userData&&typeof t.userData.advanceWidth=="number")a=t.userData.advanceWidth,r||(a+=a*.15);else if(t.boundingBox){const l=new d.Vector3;t.boundingBox.getSize(l),a=l.x}if(h===" ")return a=e*.25,a;if(n)i>1?o=(i-1)*e*.1:o=a*.05;else{const l=e*.04;r?o=i>1?(i-1)*e*.1:0:o=i*l}return a+o}function Ho(h){const t=/(\\M\+(?:[0-5])[0-9A-Fa-f]{4,})/g,e=h.match(t);if(!e)return h;let i=h;for(const s of e){const r=s.substring(4);if(r.length<4){console.error(`警告:提取的十六进制数 '${r}' 长度不足,已保留原始编码。`);continue}const n=r.substring(0,4),a=r.substring(4);try{const o=new Uint8Array(n.match(/.{1,2}/g).map(u=>parseInt(u,16))),c=new TextDecoder("gbk").decode(o);i=i.replace(s,c+a)}catch(o){console.error("转换失败:",o)}}return i}function lr(h){const t=[];let e=h;const i=/\\[a-z]+\d*\.?\d*;?/g;return(h.match(i)||[]).forEach(r=>{e=e.replace(r,""),t.push(r)}),{formatCodes:t,plainText:e}}function No(h,t){const e=lr(h.text).plainText,i=lr(t.text).plainText;return e===i}var Te=(h=>(h.Added="Added",h.Removed="Removed",h.Modified="Modified",h.NoChange="NoChange",h))(Te||{});let ve=1;const tt=class tt{constructor(t,e,i={}){p(this,"dxf1");p(this,"dxf2");p(this,"changes");p(this,"comparedBlocks");p(this,"isComparingBlock");p(this,"isComparingDimension");p(this,"enableDetailComparision");if(this.changes={},this.comparedBlocks=new Map,this.isComparingBlock=!1,this.isComparingDimension=!1,this.enableDetailComparision=i.enableDetailComparision!=null?i.enableDetailComparision:!0,this.dxf1=t,this.dxf2=e,!t||!e)throw new Error("Invalid DXF data to compare!")}getLayerFrozen(t,e){const i=e.layer;if(!i)return;const s=t.tables?.layer?.layers;return s?s[i]?.frozen:void 0}async compare(t){this.changes={};const e=[],i=new Map;return this.dxf1.entities.forEach(s=>{if(!s.inPaperSpace){const r=this.getLayerFrozen(this.dxf1,s)===!0;!tt.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!r&&e.push(s)}}),this.dxf2.entities.forEach(s=>{if(!s.inPaperSpace){const r=this.getLayerFrozen(this.dxf2,s)===!0;!tt.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!r&&i.set(s.handle,s)}}),await this.compareEntities(e,i,t),Promise.resolve(this.changes)}isDimensionBlock(t){return t.includes("*D")}compareInsertOrDemensionEntities(t,e,i,s){if(!t.block||!e.block)return;const r=t.block;let n;if(this.isComparingBlock=!0,this.isDimensionBlock(r)){const a=this.dxf1.blocks[t.block],o=this.dxf2.blocks[e.block],l=Date.now();this.isComparingDimension=!0,n=this.compareBlock(t,e,a,o),this.isComparingDimension=!1,S.debug("[DxfCompare] compare block: "+r+" took "+(Date.now()-l)/1e3+"s")}else{if(!this.comparedBlocks.has(r)){const a=this.dxf1.blocks[r],o=this.dxf2.blocks[r],l=Date.now(),c=this.compareBlock(t,e,a,o);this.comparedBlocks.set(r,c),S.debug("[DxfCompare] compare block: "+r+" took "+(Date.now()-l)/1e3+"s")}n=this.comparedBlocks.get(r)}return n?.forEach(a=>{if(!a.parentHandles&&(a.parentHandles=[]),i&&s)a.type==="Added"?a.parentHandles.push(s):a.type==="Removed"&&a.parentHandles.push(i);else{const o=[...a.parentHandles,t.handle];a.type==="Added"?this.changes[ve]={id:ve,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[ve]={id:ve,...a,parentHandles:o}),ve++}}),!i&&!s&&(this.isComparingBlock=!1),n}compareBlock(t,e,i,s){const r=[],n=[];i?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&r.push(l)}),s?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&n.push(l)});const a=[],o=[];for(let l=0;l<r.length;l++){const c=r[l];let u=!1;n.length===0&&(u=!0),!this.isComparingDimension&&(this.isComparingDimension=c.type==="DIMENSION");for(let f=0;f<n.length;f++){const m=n[f];if(!this.entitiesEqual(c,m,t,e))u=!0;else if(c.type==="INSERT"&&m.type==="INSERT"||c.type==="DIMENSION"&&m.type==="DIMENSION"){const g=this.compareInsertOrDemensionEntities(c,m,c.handle,m.handle);g&&g.length>0&&a.push(...g),u=!1,n.splice(f--,1);break}else{u=!1,n.splice(f--,1);break}}u&&(a.push({type:"Removed",handle:c.handle}),o.push(c.handle))}return n.forEach(l=>{!o.includes(l.handle)&&a.push({type:"Added",handle:l.handle})}),a}async compareEntities(t,e,i){const s=z.getUpdateProgressFuncForLoop(t.length,i);for(let r=0;r<t.length;r++){const n=t[r].handle;if(!e.has(n))this.changes[ve]={id:ve,type:"Removed",handle:n},ve++;else{const a=t[r],o=e.get(n),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(oi.includes(a.type)){if(this.bIgnoreChildEntitiesOriginalType(a)){e.delete(n),S.warn("[DxfCompare] We cannot compare insert (handle '"+a.handle+"') yet, ignored!");continue}this.compareInsertOrDemensionEntities(a,o)}}else{if(a.extendedData?.originalType&&o.extendedData?.originalType&&a.block!==o.block){e.delete(n);continue}this.changes[ve]={id:ve,type:"Modified",handle:n},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[ve].detailChanges=l),ve++}e.delete(n)}await s(r)}for(const r of e){const n=r[0];this.changes[ve]={id:ve,type:"Added",handle:n},ve++}}bIgnoreChildEntitiesOriginalType(t){return Fo.includes(t.extendedData?.originalType)}entitiesEqual(t,e,i,s,r){if(!this.baseEntitiesEqual(t,e,i,s,r))return!1;const n=t.type;let a=!0;switch(n){case"CIRCLE":case"ARC":a=this.arcsEqual(t,e);break;case"LWPOLYLINE":case"LINE":a=this.linesEqual(t,e,r);break;case"POLYLINE":a=this.polylinesEqual(t,e);break;case"TEXT":a=this.textsEqual(t,e);break;case"SOLID":a=this.solidsEqual(t,e);break;case"POINT":a=this.pointsEqual(t,e);break;case"INSERT":a=this.insertsEqual(t,e);break;case"SPLINE":a=this.splinesEqual(t,e);break;case"MTEXT":a=this.mtextsEqual(t,e);break;case"ELLIPSE":a=this.ellipsesEqual(t,e);break;case"DIMENSION":a=this.dimensionsEqual(t,e);break;case"REGION":a=this.regionsEqual(t,e);break;case"ATTDEF":a=this.attDefsEqual(t,e);break;case"ATTRIB":a=this.attribsEqual(t,e);break;case"HATCH":a=this.hatchesEqual(t,e);break;case"VIEWPORT":a=this.viewportsEqual(t,e);break;case"LEADER":a=this.leadersEqual(t,e);break;case"MULTILEADER":a=this.mleadersEqual(t,e);break;case"OLE2FRAME":a=this.ole2framesEqual(t,e);break;case"SEQEND":a=!0;break;default:a=!1}return a}getColor(t,e,i){if(t.isTrueColor||t.colorIndex>0&&t.colorIndex<256)return t.color;if(t.colorIndex===0)return i?this.getColor(i,e):e.tables?.layer?.layers[0].color;let s=0;if(t.colorIndex===256){const r=e.tables?.layer?.layers,n=r&&r[t.layer],a=r&&i&&r[i.layer];n&&n.name!=="0"?s=n.color:a?s=a.color:n?s=n.color:s=e.tables?.layer?.layers[0].color}return s}getLineType(t,e,i){if(i&&i.type==="DIMENSION")return this.getLineType(i,e);if(t.lineType!==Fs&&t.lineType!==mi)return t.lineType;if(t.lineType===mi)return i?this.getLineType(i,e):t.lineType;const s=e.tables?.layer?.layers,r="CONTINUOUS";if(t.layer!=="0"){const n=s&&s[t.layer];if(n)return n.lineType}else if(i){const n=s&&s[i.layer];if(n)return n.lineType}return r}addModificationItem(t,e,i,s){s&&(s[i]={old:t,new:e})}baseEntitiesEqual(t,e,i,s,r){let n=!0;const a=this.getColor(t,this.dxf1,i),o=this.getColor(e,this.dxf2,s);if(a!==o)if(n=!1,this.enableDetailComparision)this.addModificationItem(a,o,"color",r);else return n;const l=this.getLineType(t,this.dxf1,i),c=this.getLineType(e,this.dxf2,s);if(l!==c){if(n=!1,this.enableDetailComparision)this.addModificationItem(l,c,"lineType",r);else return n;return!1}return t.extendedData?.originalType!==e.extendedData?.originalType||!this.isComparingBlock&&!this.isComparingDimension&&t.handle!==e.handle||!this.isComparingDimension&&t.ownerHandle!==e.ownerHandle||t.type!==e.type?!1:n}arcsEqual(t,e){return!(!this.vectorsEqual(t.center,e.center)||!this.numberEqual(t.radius,e.radius)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}linesEqual(t,e,i){let s=!0;const r=t.constantWidth,n=e.constantWidth;if(!this.numberEqual(r,n))if(s=!1,this.enableDetailComparision)this.addModificationItem(r||0,n||0,"constantWidth",i);else return!1;return!this.verticesEqual(t.vertices,e.vertices)||t.shape!==e.shape?!1:s}polylinesEqual(t,e){return!(!this.vertexEntitiesEqual(t.vertices,e.vertices)||t.shape!==e.shape||t.isPolyfaceMesh!==e.isPolyfaceMesh)}textsEqual(t,e){if(t.halign!==e.halign)return!1;if(t.halign===3||t.halign===5){if(!this.pointsEqual(t.startPoint,e.startPoint))return!1}else if(!this.pointsEqual(t.endPoint,e.endPoint))return!1;return t.text===e.text}solidsEqual(t,e){return!!this.verticesEqual(t.points,e.points)}pointEntitiesEqual(t,e){return!!this.pointsEqual(t.position,e.position)}splinesEqual(t,e){return!(!this.verticesEqual(t.controlPoints,e.controlPoints)||!this.numbersEqual(t.knotValues,e.knotValues)||!this.numberEqual(t.degreeOfSplineCurve,e.degreeOfSplineCurve))}mtextsEqual(t,e,i={}){const{compareFormat:s=!1,comparePosition:r=!0}=i;if(r&&!this.pointsEqual(t.position,e.position))return!1;if(s){if(t.text!==e.text)return!1}else if(!No(t,e))return!1;return!!this.numberEqual(t.rotation,e.rotation)}ellipsesEqual(t,e){return!(!this.pointsEqual(t.center,e.center)||!this.pointsEqual(t.majorAxisEndPoint,e.majorAxisEndPoint)||!this.numberEqual(t.axisRatio,e.axisRatio)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}attDefsEqual(t,e){return!(!this.pointsEqual(t.startPoint,e.startPoint)||!this.pointsEqual(t.endPoint,e.endPoint)||!this.numberEqual(t.xScale,e.xScale)||t.text!==e.text||t.tag!==e.tag||t.prompt!==e.prompt)}attribsEqual(t,e){return this.attDefsEqual(t,e)}hatchesEqual(t,e){const i=t,s=e;return!(!this.numberEqual(i.elevationX,s.elevationX)||!this.numberEqual(i.elevationY,s.elevationY)||!this.numberEqual(i.elevationZ,s.elevationZ)||!this.hatchBoundaryPathArraysEqual(i.boundaryPaths,s.boundaryPaths))}viewportsEqual(t,e){const i=t,s=e;return!(!this.pointsEqual(i.centerPoint,s.centerPoint)||!this.pointsEqual(i.centerPoint_dcs,s.centerPoint_dcs)||!this.pointsEqual(i.viewDirection,s.viewDirection)||!this.numberEqual(i.viewHeight,s.viewHeight)||i.width_paperSpace!==s.width_paperSpace||i.height_paperSpace!==s.height_paperSpace)}leadersEqual(t,e){return!(!this.pointsEqual(t.position,e.position)||!this.verticesEqual(t.vertices,e.vertices)||t.arrowHeadBlockHandle!==e.arrowHeadBlockHandle||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)||!this.numberEqual(t.rotation,e.rotation)||t.block!==e.block)}mleadersEqual(t,e){return t.arrowHeadId!==e.arrowHeadId||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)?!1:this.mleaderContextEqual(t.contextData,e.contextData)}ole2framesEqual(t,e){return!(t.leftUpX!==e.leftUpX||t.leftUpY!==e.leftUpY||t.leftUpZ!==e.leftUpZ||t.rightDownX!==e.rightDownX||t.rightDownY!==e.rightDownY||t.rightDownZ!==e.rightDownZ)}insertsEqual(t,e){return t.extendedData?.originalType==="INSERT"&&e.extendedData?.originalType==="INSERT"?(S.warn("[DxfCompare] We cannot compare insert (handle '"+t.handle+"') yet, ignored!"),!0):!(!this.pointsEqual(t.position,e.position)||!this.numberEqual(t.xScale===void 0?1:t.xScale,e.xScale===void 0?1:e.xScale)||!this.numberEqual(t.yScale===void 0?1:t.yScale,e.yScale===void 0?1:e.yScale)||!this.numberEqual(t.zScale===void 0?1:t.zScale,e.zScale===void 0?1:e.zScale)||t.block!==e.block||t.entities?.length!==e.entities?.length)}dimensionsEqual(t,e){return!!this.pointsEqual(t.anchorPoint,e.anchorPoint)}regionsEqual(t,e){return S.warn("Cannot compare region yet!"),!0}vectorsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z):!1}pointsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z)&&this.numberEqual(t.bulge,e.bulge):!1}vertexEntityEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t,e)||t.polyfaceMeshVertex!==e.polyfaceMeshVertex||t.threeDPolylineMesh!==e.threeDPolylineMesh):!1}numbersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.numberEqual(t[i],e[i]))return!1;return!0}return!1}numberEqual(t,e){return t==null&&e==null?!0:t!=null&&e!=null?R.areNumbersEqual(t,e):!1}vectorArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vectorsEqual(t[i],e[i]))return!1;return!0}return!1}verticesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.pointsEqual(t[i],e[i]))return!1;return!0}return!1}verticesArrayEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.verticesEqual(t[i],e[i]))return!1;return!0}return!1}vertexEntitiesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vertexEntityEqual(t[i],e[i]))return!1;return!0}return!1}hatchEdgesEqual(t,e){return!t&&!e?!0:t&&e?t.type===e.type:!1}hatchEdgeArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchEdgesEqual(t[i],e[i]))return!1;return!0}return!1}hatchBoundaryPathsEqual(t,e){return!t&&!e?!0:t&&e?t.pathTypeFlag!==e.pathTypeFlag?!1:this.hatchEdgeArraysEqual(t.edges,e.edges):!1}hatchBoundaryPathArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchBoundaryPathsEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLineEqual(t,e){return!t&&!e?!0:t&&e?!(!this.verticesArrayEqual(t.vertices,e.vertices)||t.leaderLineIndex!==e.leaderLineIndex):!1}mleaderLinesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLineEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLeaderEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.lastLeaderLinePoint,e.lastLeaderLinePoint)||!this.pointsEqual(t.doglegVector,e.doglegVector)||!this.mleaderLinesEqual(t.leaderLines,e.leaderLines)):!1}mleaderLeadersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLeaderEqual(t[i],e[i]))return!1;return!0}return!1}mleaderContextEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.contentBasePosition,e.contentBasePosition)||!this.pointsEqual(t.blockContentPosition,e.blockContentPosition)||!this.mleaderLeadersEqual(t.leaders,e.leaders)):!1}compareHexStrings(t,e){return parseInt(t,16)-parseInt(e,16)}};p(tt,"ENTITY_COLOR_ADDED",65280),p(tt,"ENTITY_COLOR_REMOVED",16711680),p(tt,"ENTITY_COLOR_NO_CHANGE",10066329),p(tt,"ENTITY_COLOR_MARKUP",16744231),p(tt,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let Ue=tt;var H=(h=>(h[h.Object=0]="Object",h[h.Point=1]="Point",h[h.Line=2]="Line",h[h.LineSegment=3]="LineSegment",h[h.Mesh=4]="Mesh",h))(H||{});const os=new Se.Box3,ls=new Se.Matrix4;class F{constructor(t=0){p(this,"name");p(this,"type");p(this,"matrix");p(this,"parent");p(this,"children");p(this,"layers");p(this,"renderOrder");p(this,"userData");p(this,"material");p(this,"geometry");p(this,"matrixWorld");this.name="",this.type=0,this.matrix=new Se.Matrix4,this.children=[],this.layers=new Se.Layers,this.renderOrder=0,this.userData={},this.type=t}add(t,...e){for(let i=0;i<e.length;i++)this.add(e[i]);return t===this?(console.error("object can't be added as a child of itself.",t),this):(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),this)}remove(t,...e){for(let s=0;s<e.length;s++)this.remove(e[s]);const i=this.children.indexOf(t);return i!==-1&&(t.parent=void 0,this.children.splice(i,1)),this}removeFromParent(){const t=this.parent;return t&&t.remove(this),this}clear(){this.material=void 0,this.geometry=void 0;for(let t=0;t<this.children.length;t++){const e=this.children[t];e.parent=void 0}return this.children.length=0,this}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}clone(t=!0){return new F().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.type=t.type,this.matrix.copy(t.matrix),this.layers.mask=t.layers.mask,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),this.material=t.material,this.geometry=t.geometry,e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}convertToThreejsObject(t=!0){let e;switch(this.type){case 0:e=new Se.Object3D;break;case 1:if(!this.geometry)return;e=new d.Points(this.geometry,this.material);break;case 2:if(!this.geometry)return;e=new d.Line(this.geometry,this.material);break;case 3:if(!this.geometry)return;e=new d.LineSegments(this.geometry,this.material);break;case 4:if(!this.geometry)return;e=new d.Mesh(this.geometry,this.material);break}if(e){if(e.name=this.name,e.matrixAutoUpdate=Ne,e.applyMatrix4(this.matrix),e.layers.mask=this.layers.mask,e.renderOrder=this.renderOrder,e.userData=this.userData,t===!0)for(let i=0;i<this.children.length;i++){const s=this.children[i],r=s.convertToThreejsObject(t);r&&e.add(r)}return e}}static getBox(t,e,i){if(t.geometry)!t.geometry.boundingBox&&t.geometry.computeBoundingBox(),ls.copy(t.matrix),i&&ls.premultiply(i),os.copy(t.geometry.boundingBox),os.applyMatrix4(ls),e.union(os);else if(t.children.length>0){!t.matrixWorld&&(t.matrixWorld=new Se.Matrix4),t.matrixWorld.copy(t.matrix),i&&t.matrixWorld.premultiply(i);const s=t.children;for(let r=0,n=s.length;r<n;r++)this.getBox(s[r],e,t.matrixWorld)}return e}computeBoundingllBox(t,e,i){const s={x:0,y:0};s.x=e.position?.x||0,s.y=e.position?.y||0;let r=e.blockPosition?.x||0,n=e.blockPosition?.y||0;s.x=s.x-r,s.y=s.y-n;const a=new Se.Box3().makeEmpty();t.userData.boundingBoxs=[];const o=[];t.children.forEach(l=>{for(new Se.Box3;!l.geometry&&l.children&&l.children.length===1;)l={...l.children[0],loneMatrix:l.matrix};if(l.geometry){!l.geometry.boundingBox&&l.geometry.computeBoundingBox();const c=new Se.Box3().copy(l.geometry.boundingBox);c.applyMatrix4(l.loneMatrix||l.matrix),o.push({min:{x:c.min.x,y:c.min.y,z:c.min.z},max:{x:c.max.x,y:c.max.y,z:c.max.z},positions:[{x:c.min.x+s.x,y:c.min.y+s.y},{x:c.min.x+s.x,y:c.max.y+s.y},{x:c.max.x+s.x,y:c.max.y+s.y},{x:c.max.x+s.x,y:c.min.y+s.y}],rotation:e.rotation,center:{x:(c.min.x+c.max.x)/2+s.x,y:(c.min.y+c.max.y)/2+s.y,z:(c.min.z+c.max.z)/2},size:{x:c.max.x-c.min.x,y:c.max.y-c.min.y,z:c.max.z-c.min.z}}),a.union(c)}}),!a.isEmpty()&&a.max.x-a.min.x<20&&a.max.y-a.min.y<20?t.userData.boundingBoxs=[{min:{x:a.min.x,y:a.min.y,z:a.min.z},max:{x:a.max.x,y:a.max.y,z:a.max.z},positions:[{x:a.min.x+s.x,y:a.min.y+s.y},{x:a.min.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.min.y+s.y}],rotation:e.rotation,center:{x:(a.min.x+a.max.x)/2+s.x,y:(a.min.y+a.max.y)/2+s.y,z:(a.min.z+a.max.z)/2},size:{x:a.max.x-a.min.x,y:a.max.y-a.min.y,z:a.max.z-a.min.z}}]:t.userData.boundingBoxs=o}rotateRectByBottomLeft(t,e,i,s,r){const n=i-t,a=s-e,o=r*Math.PI/180,l=Math.cos(o),c=Math.sin(o);return[{dx:0,dy:0},{dx:n,dy:0},{dx:n,dy:a},{dx:0,dy:a}].map(f=>{const m=f.dx*l-f.dy*c,g=f.dx*c+f.dy*l;return{x:t+m,y:e+g}})}}const Oi=new d.Matrix4,Go=new d.Matrix4;class et{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},r=[];for(let c=0;c<i;++c){const u=t.children[c];if(u.children.length>0){this.mergeInner(u,e);continue}if(u.userData.relativeToCenter||!u.geometry)continue;let m=!1;const g=Object.values(s);for(let x=g.length-1;x>=0;--x){const y=g[x].indexes[0];if(m=this.tryHandleMergeableObjects(t,c,y,s,r),m)break}for(let x=r.length-1;!m&&x>=0;--x){const y=r[x];if(m=this.tryHandleMergeableObjects(t,c,y,s,r),m)break}!m&&r.push(c)}if(Object.keys(s).length<=0)return;const n=[],a=[],o=[],l=[];Object.values(s).forEach(c=>{const u=c.indexes,f=t.children[u[0]];let m=[],g=0,x=0,y=0;const T=[];if(u.forEach(b=>{const E=t.children[b],O=E.geometry?.clone();if(O.applyMatrix4(E.matrix),O.userData.isLineSegments=E.type===H.LineSegment,m.push(O),e){const _=O.attributes?.position?.count,C=O.index?.count||0;T.push({batchId:g,positionStart:x,positionCount:_,indexStart:y,indexCount:C}),x+=_,y+=C,g++}}),m.length===0)return;let v;if(f.type===H.Mesh){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new F(f.type),v.geometry=b,v.material=f.material,n.push(v)}else if(f.type===H.Line||f.type===H.LineSegment){const b=oe.mergeLineGeometries(m,e,f.material instanceof d.LineDashedMaterial||f.material instanceof d.ShaderMaterial,T);if(!b)return;v=new F(H.LineSegment),v.geometry=b,v.material=f.material,a.push(v)}else if(f.type===H.Point){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new F(f.type),v.geometry=b,v.material=f.material,o.push(v)}v&&(e?v.userData.batches=T:(v.userData=f.userData,v.userData.batches=void 0),v.userData.layerName=f.userData.layerName,v.name="[Merged] "+f.name,v.renderOrder=f.renderOrder,v.layers.mask=f.layers.mask,l.push(...u)),m.forEach(b=>{b.dispose(),U.releaseGeometryManually(b)}),m=[]}),l.sort((c,u)=>u-c),l.forEach(c=>{const u=t.children[c];t.remove(u)}),[...n,...a,...o].forEach(c=>{t.add(c)}),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=n.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,r){let n=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return n;const l=a?t[e]:t.children[e],c=a?t[i]:t.children[i];return this.areObjectsMergeable(l,c)&&oe.areGeometriesMergeable(l.geometry,c.geometry)&&de.materialsEquals(l.material,c.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(r,i)),s[i].indexes.push(e),n=!0),n}static isFilteredByOtherFactors(t,e){const i=t;if(i.type===H.Mesh&&i.material&&i.material.isShaderMaterial)return!0;let s=!1,r=t;for(;r&&r!==e;){const n=r.userData;if(n.relativeToCenter||n.spatialFilterHandle){s=!0;break}r=r.parent}return s}static deepMerge(t,e=void 0,i=!0,s=!0,r=!0){const n={added:[],removed:[]};if(t.length<=1)return n;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){if(!t[y].geometry||this.isFilteredByOtherFactors(t[y],e))continue;let v=!1;const b=Object.values(o);for(let E=b.length-1;E>=0;--E){const O=b[E].indexes[0];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}for(let E=l.length-1;!v&&E>=0;--E){const O=l[E];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}!v&&l.push(y)}if(Object.keys(o).length<=0)return n;S.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const c=[],u=[],f=[],m=[];Object.values(o).forEach(y=>{const T=y.indexes;if(T.length<2)return;const v=t[T[0]];let b=[],E=0,O=0,_=0;const C=[];if(T.forEach(M=>{const P=t[M],A=P.geometry?.clone();if(v.material instanceof d.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,P,e),A.userData.isLineSegments=P.type===H.LineSegment,b.push(A),r){const I=A.attributes?.position?.count,k=A.index?.count||0;let B;(v.type===H.Line||v.type===H.LineSegment)&&(!A.boundingSphere&&A.computeBoundingSphere(),B=A.boundingSphere?.clone());const L={batchId:E,positionStart:O,positionCount:I,indexStart:_,indexCount:k,boundingSphere:B};Object.keys(P.userData).length!==0&&(L.userData=P.userData),C.push(L),O+=I,_+=k,E++}}),b.length===0)return;let w;if(v.type===H.Mesh){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new F(v.type),w.geometry=M,w.material=v.material,c.push(w)}else if(v.type===H.Line||v.type===H.LineSegment){const M=oe.mergeLineGeometries(b,r,v.material instanceof d.LineDashedMaterial||v.material instanceof d.ShaderMaterial,C);if(!M)return;w=new F(H.LineSegment),w.geometry=M,w.material=v.material,u.push(w)}else if(v.type===H.Point){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new F(v.type),w.geometry=M,w.material=v.material,f.push(w)}w&&(r?w.userData.batches=C:(w.userData=v.userData,w.userData.batches=void 0),w.userData.layerName=v.userData.layerName,w.name="[Merged] "+v.name,w.renderOrder=v.renderOrder,w.layers.mask=v.layers.mask,T.forEach(M=>m.push(M))),b.forEach(M=>{M.dispose(),U.releaseGeometryManually(M)}),b=[]}),S.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const g=n.removed;m.forEach(y=>{const T=t[y];g.push(T),i&&T.removeFromParent()});const x=n.added;return[...c,...u,...f].forEach(y=>{x.push(y),i&&e&&e.add(y)}),this.MergeInfo.removedObjects+=m.length,this.MergeInfo.mergedMeshes+=c.length,this.MergeInfo.mergedLines+=u.length,this.MergeInfo.mergedPoints+=f.length,s&&e&&$.removeEmptyObjects(e),n}static applyMatrix(t,e,i){let s=e;for(Oi.identity();s&&s!==i&&(Oi.premultiply(s.matrix),!!s.parent);)s=s.parent;return Oi.equals(Go)?t:t.applyMatrix4(Oi)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areObjectsMergeable(t,e){return t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.userData.layerName!==e.userData.layerName?!1:t.type===e.type?!0:(t.type===H.Line||t.type===H.LineSegment)&&(e.type===H.Line||e.type===H.LineSegment)}}p(et,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});const pn=(h,t)=>{if(typeof t>"u"||+t==0)return Math.round(h);let e=+h;if(t=+t,isNaN(e)||!(typeof t=="number"&&t%1===0))return NaN;let i=e.toString().split("e");return e=Math.round(+(i[0]+"e"+(i[1]?+i[1]-t:-t))),i=e.toString().split("e"),+(i[0]+"e"+(i[1]?+i[1]+t:t))},mn=(h,t,e,i,s)=>{const r=e.length,n=e[0].length;if(h<0||h>1)throw new Error("t out of bounds [0,1]: "+h);if(t<1)throw new Error("degree must be at least 1 (linear)");if(t>r-1)throw new Error("degree must be less than or equal to point count - 1");if(i){if(i.length!==r+t+1)throw new Error("bad knot vector length")}else{i=[];for(let g=0;g<r+t+1;g++)i[g]=g}const a=[t,i.length-1-t],o=i[a[0]],l=i[a[1]];h=h*(l-o)+o,h=Math.max(h,o),h=Math.min(h,l);let c;for(c=a[0];c<a[1]&&!(h>=i[c]&&h<=i[c+1]);c++);const u=[];for(let g=0;g<r;g++){u[g]=[];const x=s?s[g]:1;for(let y=0;y<n;y++)u[g][y]=e[g][y]*x;u[g][n]=x}let f;for(let g=1;g<=t+1;g++)for(let x=c;x>c-t-1+g;x--){f=(h-i[x])/(i[x+t+1-g]-i[x]);for(let y=0;y<n+1;y++)u[x][y]=(1-f)*u[x-1][y]+f*u[x][y]}const m=[];for(let g=0;g<n;g++)m[g]=pn(u[c][g]/u[c][n],-9);return m},qo={d:"°",c:"⌀",p:"±"},li=(h,t)=>{if(!h)return[];h=h.replace(/%%(.)/g,(o,l)=>qo[l]||l).replace(/\^I/g," ");const e=t?.encoding;let i=e instanceof TextDecoder?e:void 0,s="",r;const n=[],a=o=>{s&&(n.push(s),s=""),n.push(o)};for(let o=0;o<h.length;o++)switch(r=h[o]){default:s+=r;break;case"\\":{switch(r=h[++o]){default:s+=r;break;case"p":{const l=h.slice(o,o=h.indexOf(";",o));l.startsWith("pxq")||l.startsWith("pxi")||l.startsWith("pxt")||l.startsWith("pt")||l.startsWith("pi")||(l.startsWith("psm")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):l.startsWith("pq")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):a({[l.slice(0,l.length-1)]:l[l.length-1]}));break}case"P":s+=`
536
+ `;break;case"f":case"F":{let l="";for(;r=h[++o];){if(r===";"){a({f:l});break}if(r==="|"){const c={f:l},u=h.indexOf(";",++o);for(const f of h.slice(o,u).split("|"))c[f[0]]=+f.slice(1);o=u,a(c);break}l+=r==="\\"?h[++o]:r}break}case"S":{let l="",c,u="";for(;r=h[++o];){if(r===";"){const f=l+u;f&&a(f);break}if(r==="\\"){const f=h[++o];c?u+=f:l+=f}else!c&&(r==="^"||r==="/"||r==="#")?c=r:c?u+=r:l+=r}break}case"H":case"W":{const l=++o,[,c,u]=h.slice(l,o=h.indexOf(";",o)).match(/^(\d*(?:\.\d+)?)(\D*)$/);a({[r]:[+c,u]})}break;case"Q":case"A":case"C":case"c":case"T":{const l=++o;a({[r]:+h.slice(l,o=h.indexOf(";",o))});break}case"L":case"O":case"K":a({[r]:1});break;case"l":case"o":case"k":a({[r.toUpperCase()]:0});break;case"U":case"u":h[o+1]==="+"?(s+=String.fromCodePoint(parseInt(h.substr(o+2,4),16)),o+=5):s+=r;break;case"M":case"m":e?h[o+1]==="+"&&(h[o+2]==="0"||h[o+2]==="1")?(s+=(i=i||new TextDecoder(e)).decode(new Uint8Array([parseInt(h.substr(o+3,2),16),parseInt(h.substr(o+5,2),16)])),o+=6):s+=r:s+="\\"+r;break}break}case"{":{let l=1;const c=o;for(;r=h[++o];)if(r==="{")l++;else if(r==="}"){if(--l===0){a(li(h.slice(c+1,o)));break}}else r==="\\"&&o++;break}}return s&&n.push(s),n},Wo={d:"°",c:"⌀",p:"±"},gn=(h,t)=>(h=yn(h),t?xn(h,t):h),yn=h=>h.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))),xn=(h,t)=>{let e=t instanceof TextDecoder?t:new TextDecoder(t);return h.replace(/\\[mM]\+[0|1]([0-9a-fA-F]{2})([0-9a-fA-F]{2})/g,(i,s,r)=>(e=e||new TextDecoder(t)).decode(new Uint8Array([parseInt(s,16),parseInt(r,16)])))},Ni=(h,t)=>{h=gn(h,t?.encoding);let e=0,i={text:""};const s=[i],r=h.matchAll(/%%(\d\d\d|.)/g);for(const n of r){i.text+=h.slice(e,n.index);const a=n[1],o=a.toLowerCase(),l=Wo[o];l?i.text+=l:o.length===3?i.text+=String.fromCodePoint(+o):o==="k"||o==="o"||o==="u"?(i=Object.assign(Object.assign({},i),{text:""}),i[o]?delete i[o]:i[o]=1,s.push(i)):i.text+=o,e=n.index+n[0].length}return i.text+=h.slice(e),s.filter(n=>n.text)};class bn{static createLineShaderMaterial(t,e,i,s,r){let n=0;const a=[];for(let u=0;u<t.length;u++)a[u]=t[u],a[u]===0&&(a[u]=.5),a[u]*=i,n+=Math.abs(a[u]);const o=d.UniformsUtils.merge([d.UniformsLib.common,{pattern:{value:a},patternLength:{value:n},u_color:{value:new d.Color(e)}}]);o.u_viewportScale=s,o.u_cameraZoom=r;const l=`
537
537
  attribute float lineDistance;
538
538
  varying float vLineDistance;
539
539
 
@@ -588,7 +588,7 @@ void main() {
588
588
  }
589
589
  }
590
590
  #include <colorspace_fragment>
591
- }`;return new d.ShaderMaterial({uniforms:o,vertexShader:l,fragmentShader:c,clipping:!0})}}function bn(h,t,e,i,s=0){const r={u_cameraZoom:e,u_patternLines:{value:h},u_patternAngle:{value:t},u_color:{value:i}},n=`
591
+ }`;return new d.ShaderMaterial({uniforms:o,vertexShader:l,fragmentShader:c,clipping:!0})}}function vn(h,t,e,i,s=0){const r={u_cameraZoom:e,u_patternLines:{value:h},u_patternAngle:{value:t},u_color:{value:i}},n=`
592
592
  varying vec3 v_pos;
593
593
 
594
594
  #include <clipping_planes_pars_vertex>
@@ -788,14 +788,14 @@ void main() {
788
788
  gl_FragColor = vec4(u_color * total, 1.0);
789
789
  #include <colorspace_fragment>
790
790
  }
791
- `;return new d.ShaderMaterial({uniforms:r,vertexShader:n,fragmentShader:a,clipping:!0})}var De=(h=>(h.Unitless="Unitless",h.Inches="Inches",h.Feet="Feet",h.Millimeters="Millimeters",h.Centimeters="Centimeters",h.Meters="Meters",h))(De||{});const Ps=h=>h==="Unitless"?1:h==="Inches"?.0254:h==="Feet"?.3048:h==="Millimeters"?.001:h==="Centimeters"?.01:(h==="Meters"||console.warn("[Units] Unsupported unit '"+h+"', will return 1 for unit scale."),1),Wo=(h,t)=>Ps(h)/Ps(t);class vn{constructor(){p(this,"pointer");p(this,"eof");p(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class xi{constructor(t,e){p(this,"endian");p(this,"position");p(this,"data");p(this,"decoder");this.endian=e&&e==="big"?"big":"little",this.position=0,this.data=new DataView(t)}readAsciiString(t){if(this.data.byteLength<this.position+t)throw"range error";let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(this.data.getInt8(this.position+i));return this.position+=t,e}readUtf8String(t){const e=this.readBytes(t);return this.decoder||(this.decoder=new TextDecoder("utf-8")),this.decoder.decode(e)}readBytes(t=1){if(this.data.byteLength<this.position+t)throw"range error";const e=new Uint8Array(t);for(let i=0;i<t;i++)e[i]=this.data.getUint8(this.position+i);return this.position+=t,e}readUint8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getUint8(this.position);return this.position+=1,t}readInt8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getInt8(this.position);return this.position+=1,t}readUint16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getUint16(this.position,this.endian==="little");return this.position+=2,t}readInt16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getInt16(this.position,this.endian==="little");return this.position+=2,t}readUint32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getUint32(this.position,this.endian==="little");return this.position+=4,t}readInt32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getInt32(this.position,this.endian==="little");return this.position+=4,t}readFloat32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getFloat32(this.position,this.endian==="little");return this.position+=4,t}readFloat64(){if(this.data.byteLength<this.position+8)throw"range error";const t=this.data.getFloat64(this.position,this.endian==="little");return this.position+=8,t}readInt64(){if(this.data.byteLength<this.position+8)throw"range error";const t=bi.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,bi.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=bi.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,bi.toNumber(t)}getPosition(){return this.position}setPosition(t){if(this.data.byteLength<t)throw"range error";this.position=t}isEnd(){return this.position===this.data.byteLength-1}}const hr=1e3;class Yo extends vn{constructor(e){super();p(this,"reader");p(this,"decoder");p(this,"int8Array");p(this,"caches");this.int8Array=new Int8Array(hr),this.caches=new Map,this.reader=new xi(e);const i=this.reader.readBytes(22);let s="";for(let r=0;r<18;r++)s+=String.fromCharCode(i[r]);if(s!=="AutoCAD Binary DXF")throw new Error("Invalid DXF file")}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file.");const e={code:this.reader.readInt16()};return e.value=this.parseGroupValue(e.code),e.code===0&&e.value==="EOF"&&(this.eof=!0),this.lastReadGroup=e,e}hasNext(){return this.eof?!1:!this.reader.isEnd()}isEOF(){return this.eof}parseGroupValue(e){if(e>=0&&e<=9)return this.readNullTerminatedString();if(e>=10&&e<=59)return this.reader.readFloat64();if(e>=60&&e<=79)return this.reader.readInt16();if(e>=90&&e<=99)return this.reader.readInt32();if(e>=100&&e<=109)return this.readNullTerminatedString();if(e>=110&&e<=149)return this.reader.readFloat64();if(e>=160&&e<=169)return this.reader.readInt64();if(e>=170&&e<=179)return this.reader.readInt16();if(e>=210&&e<=239)return this.reader.readFloat64();if(e>=270&&e<=289)return this.reader.readInt16();if(e>=290&&e<=299)return this.reader.readInt8()>0;if(e>=300&&e<=309)return this.readNullTerminatedString();if(e>=310&&e<=319){const i=this.ReadBinaryData();return cr(i)}if(e>=320&&e<=369)return this.readNullTerminatedString();if(e>=370&&e<=389)return this.reader.readInt16();if(e>=390&&e<=399)return this.readNullTerminatedString();if(e>=400&&e<=409)return this.reader.readInt16();if(e>=410&&e<=419)return this.readNullTerminatedString();if(e>=420&&e<=429)return this.reader.readInt32();if(e>=430&&e<=439)return this.readNullTerminatedString();if(e>=440&&e<=449)return this.reader.readInt32();if(e>=450&&e<=459)return this.reader.readFloat64();if(e>=460&&e<=469)return this.readNullTerminatedString();if(e>=470&&e<=479)return this.readNullTerminatedString();if(e>=480&&e<=481)return this.readNullTerminatedString();if(e>=999&&e<=999)throw new Error("The comment group 999, is not used in binary DXF files at byte address!");if(e===1004){const i=this.ReadBinaryData();return cr(i)}if(e>=1e3&&e<=1009)return this.readNullTerminatedString();if(e>=1010&&e<=1059)return this.reader.readFloat64();if(e>=1060&&e<=1070)return this.reader.readInt16();if(e===1071)return this.reader.readInt32();console.warn("[DxfBinReader] Invalid code '"+e+"' at byte address "+this.reader.getPosition())}readNullTerminatedString(){this.decoder||(this.decoder=new TextDecoder("utf-8"));let e=0,i=this.reader.readInt8();for(;i!==0;)this.int8Array[e++]=i,i=this.reader.readInt8();if(e===0)return"";if(e>hr)return console.warn("[DxfBinReader] Failed to read string! The number of bytes is "+e+" !"),"";const s=this.int8Array.subarray(0,e),r=s.toString();if(this.caches.get(r))return this.caches.get(r);const n=this.decoder?.decode(s);return this.caches.set(r,n),n}ReadBinaryData(){const e=this.reader.readUint8();return this.reader.readBytes(e)}}function cr(h){return Array.prototype.map.call(h,t=>("00"+t.toString(16)).slice(-2)).join("")}class dr extends vn{constructor(e){super();p(this,"data");this.data=e}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file. Ended on code "+this.data[this.pointer]);const e={code:parseInt(this.data[this.pointer])};return this.pointer++,e.value=Xo(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 Xo(h,t,e){return h>=0&&h<=9?e:h>=10&&h<=59?parseFloat(t):h>=60&&h<=99?parseInt(t):h>=100&&h<=109?t:h>=110&&h<=149?parseFloat(t):h>=160&&h<=179?parseInt(t):h>=210&&h<=239?parseFloat(t):h>=270&&h<=289?parseInt(t):h>=290&&h<=299?Zo(t):h>=300&&h<=369?t:h>=370&&h<=389?parseInt(t):h>=390&&h<=399?t:h>=400&&h<=409?parseInt(t):h>=410&&h<=419?t:h>=420&&h<=429?parseInt(t):h>=430&&h<=439?t:h>=440&&h<=449?parseInt(t):h>=450&&h<=459?parseFloat(t):h>=460&&h<=469||h===999||h>=1e3&&h<=1009?t:h>=1010&&h<=1059?parseFloat(t):h>=1060&&h<=1071?parseInt(t):(console.info("WARNING: Group code does not have a defined type: %j",{code:h,value:t}),t)}function Zo(h){if(h==="0")return!1;if(h==="1")return!0;throw TypeError("String '"+h+"' cannot be cast to Boolean type")}function Ko(h){if(h==null)return!0;for(const t in h)if(Object.prototype.hasOwnProperty.call(h,t))return!1;return!0}function $o(h,t){const e=[];let i=!1,s=!1;const r=4;for(let n=0;n<=r;n++){const a={};for(;!h.isEOF()&&!(t.code===0||s);){switch(t.code){case 10:case 11:case 12:case 13:if(i){s=!0;continue}a.x=t.value,i=!0;break;case 20:case 21:case 22:case 23:a.y=t.value;break;case 30:case 31:case 32:case 33:a.z=t.value;break;default:return e}t=h.next()}Ko(a)||e.push(a),i=!1,s=!1}return e}class Jo{constructor(){p(this,"ForEntityName","3DFACE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:if(e.value!==0){const s=Math.log2(e.value)-1;i.vertices.splice(s,0,1)}e=t.next();break;case 10:i.vertices=$o(t,e),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class Qo{constructor(){p(this,"ForEntityName","ARC")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=el(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:i.endAngle=Math.PI/180*e.value,i.angleLength=i.endAngle-i.startAngle,e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function el(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class tl{constructor(){p(this,"ForEntityName","ATTDEF")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=ur(t),e=t.lastReadGroup;break;case 11:i.endPoint=ur(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function ur(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class il{constructor(){p(this,"ForEntityName","ATTRIB")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=fr(t),e=t.lastReadGroup;break;case 11:i.endPoint=fr(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function fr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class sl{constructor(){p(this,"ForEntityName","CIRCLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=rl(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:const s=Math.PI/180*e.value;s<i.startAngle?i.angleLength=s+2*Math.PI-i.startAngle:i.angleLength=s-i.startAngle,i.endAngle=s,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function rl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class nl{constructor(){p(this,"ForEntityName","DIMENSION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 3:i.dimStyleName=e.value,e=t.next();break;case 10:i.anchorPoint=xt(t),e=t.lastReadGroup;break;case 11:i.middleOfText=xt(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=xt(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=xt(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=xt(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=xt(t),e=t.lastReadGroup;break;case 16:i.arcPoint=xt(t),e=t.lastReadGroup;break;case 70:i.dimensionType=e.value,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 42:i.actualMeasurement=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 50:i.angle=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function xt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class al{constructor(){p(this,"ForEntityName","MULTILEADER")}parseEntity(t,e){const i={type:e.value};i.contextData={leaders:[]},e=t.next();const s=()=>{const o=i.contextData.leaders[i.contextData.leaders.length-1],l={vertices:[[]]};for(o.leaderLines.push(l);!t.isEOF();)switch(e.code){case 10:l.vertices[0].push(_e(t)),e=t.lastReadGroup;break;case 305:return;default:e=t.next();break}},r=()=>{const o={leaderLines:[]};for(i.contextData.leaders.push(o);!t.isEOF();)switch(e.code){case 290:o.hasSetLastLeaderLinePoint=e.value,e=t.next();break;case 291:o.hasSetDoglegVector=e.value,e=t.next();break;case 10:o.lastLeaderLinePoint=_e(t),e=t.lastReadGroup;break;case 11:o.doglegVector=_e(t),e=t.lastReadGroup;break;case 90:o.leaderBranchIndex=e.value,e=t.next();break;case 40:o.doglegLength=e.value,e=t.next();break;case 303:return;case 304:s(),e=t.lastReadGroup;break;default:e=t.next();break}},n=()=>{for(;!t.isEOF();)switch(e.code){case 40:i.contextData.contentScale=e.value,e=t.next();break;case 10:i.contextData.contentBasePosition=_e(t),e=t.lastReadGroup;break;case 145:i.contextData.landingGap=e.value,e=t.next();break;case 290:i.contextData.hasMText=e.value,e=t.next();break;case 300:i.contextData.defaultTextContents=e.value,e=t.next();break;case 11:i.contextData.textNormalDirection=_e(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=_e(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=_e(t),e=t.lastReadGroup;break;case 140:i.contextData.arrowHeadSize=e.value,e=t.next();break;case 41:i.contextData.textHeight=e.value,e=t.next();break;case 42:i.contextData.textRotation=e.value,e=t.next();break;case 43:i.contextData.textWidth=e.value,e=t.next();break;case 44:e=t.next();break;case 45:i.contextData.textLineSpacingFactor=e.value,e=t.next();break;case 90:i.contextData.textColor=e.value,e=t.next();break;case 170:i.contextData.textLineSpacingStyle=e.value,e=t.next();break;case 171:i.contextData.textAttachment=e.value,e=t.next();break;case 172:i.contextData.textFlowDirection=e.value,e=t.next();break;case 141:i.contextData.textBackgroundScaleFactor=e.value,e=t.next();break;case 92:i.contextData.textBackgroundTransparency=e.value,e=t.next();break;case 291:i.contextData.textBackgroundColorOn=e.value,e=t.next();break;case 292:i.contextData.textBackgroundFillOn=e.value,e=t.next();break;case 293:i.contextData.textUseAutoHeight=e.value,e=t.next();break;case 173:i.contextData.textColumnType=e.value,e=t.next();break;case 142:i.contextData.textColumnWidth=e.value,e=t.next();break;case 143:i.contextData.textColumnGutterWidth=e.value,e=t.next();break;case 144:i.contextData.textColumnHeight=e.value,e=t.next();break;case 295:i.contextData.textUseWordBreak=e.value,e=t.next();break;case 296:i.contextData.hasBlock=e.value,e=t.next();break;case 341:i.contextData.blockContentId=e.value,e=t.next();break;case 14:i.contextData.blockContentNormalDirection=_e(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=_e(t),e=t.lastReadGroup;break;case 16:i.contextData.blockContentScale=e.value,e=t.next();break;case 46:i.contextData.blockContentRotation=e.value,e=t.next();break;case 93:i.contextData.blockContentColor=e.value,e=t.next();break;case 47:i.contextData.blockTransformationMatrix=ol(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=_e(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=_e(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=_e(t),e=t.lastReadGroup;break;case 297:i.contextData.planeNormalReversed=e.value,e=t.next();break;case 301:return;case 302:r(),e=t.lastReadGroup;break;default:e=t.next();break}};return(()=>{for(;!t.isEOF();)switch(e.code){case 0:return;case 340:i.leaderStyleId=e.value,e=t.next();break;case 170:i.leaderLineType=e.value,e=t.next();break;case 91:i.leaderLineColor=e.value,e=t.next();break;case 341:i.leaderLineTypeId=e.value,e=t.next();break;case 171:i.leaderLineWeight=e.value,e=t.next();break;case 41:i.doglegLength=e.value,e=t.next();break;case 290:i.enableLanding=e.value,e=t.next();break;case 291:i.enableDogLeg=e.value,e=t.next();break;case 342:i.arrowHeadId=e.value,e=t.next();break;case 42:i.arrowHeadSize=e.value,e=t.next();break;case 172:i.contentType=e.value,e=t.next();break;case 173:i.textLeftAttachmentType=e.value,e=t.next();break;case 95:i.textLeftAttachmentType=e.value,e=t.next();break;case 174:i.textAngleType=e.value,e=t.next();break;case 175:i.textAlignmentType=e.value,e=t.next();break;case 343:i.textStyleId=e.value,e=t.next();break;case 92:i.textColor=e.value,e=t.next();break;case 292:i.enableFrameText=e.value,e=t.next();break;case 344:i.blockContentId=e.value,e=t.next();break;case 93:i.blockContentColor=e.value,e=t.next();break;case 10:i.blockContentScale=_e(t),e=t.lastReadGroup;break;case 43:i.blockContentRotation=e.value,e=t.next();break;case 176:i.blockContentConnectionType=e.value,e=t.next();break;case 293:i.enableAnotationScale=e.value,e=t.next();break;case 94:i.arrowHeadIndex=e.value,e=t.next();break;case 177:i.blockAttributeIndex=e.value,e=t.next();break;case 44:i.blockAttributeWidth=e.value,e=t.next();break;case 302:i.blockAttributeTextString=e.value,e=t.next();break;case 294:i.textDirectionNegative=e.value,e=t.next();break;case 178:i.textAlignInIPE=e.value,e=t.next();break;case 179:i.textAttachmentPoint=e.value,e=t.next();break;case 271:i.textAttachmentDirectionMText=e.value,e=t.next();break;case 272:i.textAttachmentDirectionBottom=e.value,e=t.next();break;case 273:i.textAttachmentDirectionTop=e.value,e=t.next();break;case 300:n(),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}})(),i}}function _e(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 110:case 111:case 112:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 120:case 121:case 122:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=h.next()}return t}function ol(h,t){const e=[];let i=h.lastReadGroup||h.next();for(;!h.isEOF()&&(i.code>=t&&i.code<t+16);){e.push(i.value);i=h.next()}return e}class ll{constructor(){p(this,"ForEntityName","ELLIPSE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=hs(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=hs(t),e=t.lastReadGroup;break;case 40:i.axisRatio=e.value,e=t.next();break;case 41:i.startAngle=e.value,e=t.next();break;case 42:i.endAngle=e.value,e=t.next();break;case 210:i.extrusionDirection=hs(t),e=t.lastReadGroup;break;case 2:i.name=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function hs(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}var wn=(h=>(h[h.Default=0]="Default",h[h.External=1]="External",h[h.Polyline=2]="Polyline",h[h.Derived=4]="Derived",h[h.Textbox=8]="Textbox",h[h.Outermost=16]="Outermost",h[h.MaxFlags=31]="MaxFlags",h))(wn||{}),Bt=(h=>(h[h.Polyline=0]="Polyline",h[h.Line=1]="Line",h[h.Arc=2]="Arc",h[h.Ellipse=3]="Ellipse",h[h.Spline=4]="Spline",h))(Bt||{});function Lt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;if(e.code===i)if(t.x=e.value,!h.isEOF()&&h.hasNext())e=h.next();else return t;if(e.code===i+10)if(t.y=e.value,!h.isEOF()&&h.hasNext())e=h.next();else return t;return e.code===i+20&&(t.z=e.value,!h.isEOF()&&h.hasNext()&&(e=h.next())),t}function hl(h){const t={type:0,points:[],isClosed:!0};let e=h.next();const i=e.value!==0;e=h.next(),t.isClosed=e.value!==0,e=h.next();const s=e.value;e=h.next();for(let n=0;n<s;n++){const a=Lt(h);e=h.lastReadGroup,i&&(a.bulge=e.value,e=h.next()),t.points.push(a)}e=h.lastReadGroup,console.assert(e.code===97,"The reference count code 97 was expected.");const r=e.value;e=h.next();for(let n=0;n<r;n++)console.assert(e.code===330,"The reference handle code 330 was expected."),e=h.next();return{edges:[t],pathTypeFlag:-1}}function cl(h,t){const e=[];let i=t.next();for(;e.length<h;){if(i.code!==72){i=t.next();continue}switch(i.value){case 1:{i=t.next();const n={type:1,startPoint:Lt(t),endPoint:Lt(t)};i=t.lastReadGroup,e.push(n);break}case 2:{i=t.next();const n={type:2,center:Lt(t),radius:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,n.radius=i.value,i=t.next(),n.startAngle=i.value,i=t.next(),n.endAngle=i.value,i=t.next(),n.bCounterclockwise=i.value!==0,i=t.next(),e.push(n);break}case 3:{i=t.next();const n={type:3,center:Lt(t),majorAxisEndPoint:Lt(t),minorRatio:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,n.minorRatio=i.value,i=t.next(),n.startAngle=i.value,i=t.next(),n.endAngle=i.value,i=t.next(),n.bCounterclockwise=i.value!==0,i=t.next(),e.push(n);break}case 4:{i=t.next();const n={type:4,degreeOfSplineCurve:i.value,bRational:!1,bPeriodic:!1,numKnots:0,numControlPoints:0,knotValues:[],controlPoints:[]};i=t.next(),n.bRational=i.value!==0,i=t.next(),n.bPeriodic=i.value!==0,i=t.next(),n.numKnots=i.value,i=t.next(),n.numControlPoints=i.value,i=t.next();for(let a=0;a<n.numKnots;a++)n.knotValues.push(i.value),i=t.next();for(let a=0;a<n.numControlPoints;a++){const o=i.value;i=t.next();const l=i.value;let c=1;i=t.next(),i.code===42&&(c=i.value,i=t.next()),n.controlPoints.push({x:o,y:l,z:c})}e.push(n);break}default:i=t.next();break}}i=t.lastReadGroup,console.assert(i.code===97,"The reference count code 97 was expected.");const s=i.value;i=t.next();for(let r=0;r<s;r++)console.assert(i.code===330,"The reference handle code 330 was expected."),i=t.next();return{edges:e,pathTypeFlag:-1}}function dl(h,t){const e=[];let i=-1,s=t.next();for(;e.length<h;){let r;switch(s.code){case 92:if(i=s.value,i&2){if(r=hl(t),r)r.pathTypeFlag=i,e.push(r);else throw new Error("[Hatch] Failed to parse hatch polyline boundary path !");s=t.lastReadGroup}else s=t.next();break;case 93:{const n=s.value;r=cl(n,t),r.pathTypeFlag=i,e.push(r),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function ul(h,t){if(h<=0){t.next();return}const e=[];let i=t.next();for(let s=0;s<h;s++){let r=0;const n={x:0,y:0},a={x:0,y:0};let o=-1;const l=[];for(;!t.isEOF()&&i.code!==0;){let c=!1;switch(i.code){case 53:r=i.value;break;case 43:n.x=i.value;break;case 44:n.y=i.value;break;case 45:a.x=i.value;break;case 46:a.y=i.value;break;case 79:o=i.value;break;case 49:l.push(i.value);break;default:c=!0}if(i=t.next(),c||l.length===o)break}o>=0&&e.push({angle:r,origin:n,delta:a,dashPattern:l})}return e}function fl(h,t){const e=[];let i=t.next();for(;e.length<h&&!t.isEOF()&&i.code!==void 0&&i.code!==0;)switch(i.code){case 63:i=t.next();break;case 421:e.push(i.value),i=t.next();break;default:i=t.next();break}return e}class pl{constructor(){p(this,"ForEntityName","HATCH")}parseEntity(t,e){const i={type:e.value,boundaryPaths:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.patternName=e.value,e=t.next();break;case 10:i.elevationX=e.value,e=t.next();break;case 20:i.elevationY=e.value,e=t.next();break;case 30:i.elevationZ=e.value,e=t.next();break;case 41:i.patternScale=e.value,e=t.next();break;case 47:i.pixelSize=e.value,e=t.next();break;case 52:i.patternAngle=e.value,e=t.next();break;case 63:i.patternFillColor=e.value,e=t.next();break;case 70:i.solidFill=(e.value&1)!==0,e=t.next();break;case 71:i.associativity=(e.value&1)!==0,e=t.next();break;case 73:i.annotatedBoundary=(e.value&1)!==0,e=t.next();break;case 75:i.style=e.value,e=t.next();break;case 76:i.patternType=e.value,e=t.next();break;case 78:i.patternLines=ul(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=dl(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=fl(i.gradientColorCount,t),e=t.next();break;case 460:e=t.next();break;case 461:e=t.next();break;case 462:e=t.next();break;case 463:e=t.next();break;case 470:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}var Hi=(h=>(h[h.ShowImage=1]="ShowImage",h[h.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",h[h.UseClippingBoundary=4]="UseClippingBoundary",h[h.TransparencyIsOn=8]="TransparencyIsOn",h))(Hi||{});let ml=class{constructor(){p(this,"ForEntityName","IMAGE")}parseEntity(t,e){const i={type:e.value,clippingBoundaryPath:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=Zt(t),e=t.lastReadGroup;break;case 11:i.uPixel=Zt(t),e=t.lastReadGroup;break;case 12:i.vPixel=Zt(t),e=t.lastReadGroup;break;case 13:i.imageSize=Zt(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(Zt(t)),e=t.lastReadGroup;break;case 290:i.clipMode=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}};function Zt(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=h.next()}return t}class gl{constructor(){p(this,"ForEntityName","INSERT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 66:i.attributesFollow=e.value!=0,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 42:i.yScale=e.value,e=t.next();break;case 43:i.zScale=e.value,e=t.next();break;case 10:i.position=pr(t),e=t.lastReadGroup;break;case 50:i.rotation=e.value,e=t.next();break;case 70:i.columnCount=e.value,e=t.next();break;case 71:i.rowCount=e.value,e=t.next();break;case 44:i.columnSpacing=e.value,e=t.next();break;case 45:i.rowSpacing=e.value,e=t.next();break;case 210:i.extrusionDirection=pr(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;case 1e3:i.zdysx?i.zdysx+=e.value:i.zdysx=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function pr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}function yl(h){switch(h){case 40:return"DIMSCALE";case 41:return"DIMASZ";case 42:return"DIMEXO";case 44:return"DIMEXE";case 75:return"DIMSE1";case 76:return"DIMSE2";case 77:return"DIMTAD";case 140:return"DIMTXT";case 144:return"DIMLFAC";case 147:return"DIMGAP";case 176:return"DIMCLRD";case 178:return"DIMCLRT";case 271:return"DIMDEC";case 341:return"DIMLDRBLK";default:return null}}class xl{constructor(){p(this,"ForEntityName","LEADER")}parseEntity(t,e){const i={type:e.value,arrowFlag:1,vertices:[]};e=t.next();let s=!1;for(;!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.push(bl(t)),e=t.lastReadGroup;break;case 3:i.dimensionStyle=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.textWidth=e.value,e=t.next();break;case 71:i.arrowFlag=e.value,e=t.next();break;case 72:i.pathType=e.value,e=t.next();break;case 73:i.creationFlag=e.value,e=t.next();break;case 74:i.direction=e.value,e=t.next();break;case 75:i.hasHookline=e.value===1,e=t.next();break;case 1001:s=e.value==="ACAD",e=t.next();break;case 1070:if(s){const r=yl(e.value);r&&(e=t.next(),(e.code==1005||e.code==1040||e.code==1070)&&(r==="DIMLDRBLK"?i.arrowHeadBlockHandle=e.value:r==="DIMASZ"?i.arrowHeight=e.value:r==="DIMSCALE"?i.arrowHeadScale=e.value:r==="DIMCLRD"&&e.value>0&&(i.colorIndex=e.value,i.color=Nt(Math.abs(e.value)))))}e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function bl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class vl{constructor(){p(this,"ForEntityName","LINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(cs(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(cs(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=cs(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function cs(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}function wl(h,t){if(!h||h<=0)throw Error("n must be greater than 0 verticies");const e=[];let i=!1,s=!1,r=t.lastReadGroup;const n={};for(;!t.isEOF()&&!(r.code===0||s);)switch(r.code){case 10:if(i){s=!0;continue}n.x=r.value,i=!0,r=t.next();break;case 20:n.y=r.value,r=t.next();break;case 30:n.z=r.value,r=t.next();break;case 40:n.startWidth=r.value,r=t.next();break;case 41:n.endWidth=r.value,r=t.next();break;case 42:r.value!=0&&(n.bulge=r.value),r=t.next();break;default:return i&&e.push(n),e}return e.push(n),i=!1,s=!1,e}class Ml{constructor(){p(this,"ForEntityName","LWPOLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};let s=0;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 38:i.elevation=e.value,e=t.next();break;case 39:i.thickness=e.value,e=t.next();break;case 70:i.shape=(e.value&1)===1,i.hasContinuousLinetypePattern=(e.value&128)===128,e=t.next();break;case 90:s=e.value,e=t.next();break;case 10:i.vertices.push(...wl(s,t)),e=t.lastReadGroup;break;case 43:e.value!==0&&(i.constantWidth=e.value),e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class Tl{constructor(){p(this,"ForEntityName","MTEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 3:const s=e.value;i.text?i.text+=s:i.text=s,e=t.next();break;case 1:const r=e.value;i.text?i.text+=r:i.text=r,e=t.next();break;case 10:i.position=mr(t),e=t.lastReadGroup;break;case 7:i.textStyle=e.value,e=t.next();break;case 44:i.lineSpaceFactor=e.value,e=t.next();break;case 11:i.directionVector=mr(t),i.rotation=void 0,e=t.lastReadGroup;break;case 40:i.height=e.value,e=t.next();break;case 41:const n=e.value;Math.abs(n)<1e-6?i.width=void 0:i.width=n,e=t.next();break;case 50:i.rotation=e.value,i.directionVector=void 0,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 72:i.drawingDirection=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function mr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Cl{constructor(){p(this,"ForEntityName","OLE2FRAME")}parseEntity(t,e){const i={type:e.value,binaryData:""};for(e=t.next();e.value!=="OLE"&&e.code!==0;)switch(e.code){case 3:i.documentType=e.value,e=t.next();break;case 70:i.version=e.value,e=t.next();break;case 10:i.leftUpX=e.value,e=t.next();break;case 20:i.leftUpY=e.value,e=t.next();break;case 30:i.leftUpZ=e.value,e=t.next();break;case 11:i.rightDownX=e.value,e=t.next();break;case 21:i.rightDownY=e.value,e=t.next();break;case 31:i.rightDownZ=e.value,e=t.next();break;case 90:i.lengthOfBinaryData=e.value,e=t.next();break;case 310:i.binaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class Sl{constructor(){p(this,"ForEntityName","POINT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=gr(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=gr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function gr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Ol{constructor(){p(this,"ForEntityName","VERTEX")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.x=e.value,e=t.next();break;case 20:i.y=e.value,e=t.next();break;case 30:i.z=e.value,e=t.next();break;case 40:e=t.next();break;case 41:e=t.next();break;case 42:e.value!=0&&(i.bulge=e.value),e=t.next();break;case 70:i.curveFittingVertex=(e.value&1)!==0,i.curveFitTangent=(e.value&2)!==0,i.splineVertex=(e.value&8)!==0,i.splineControlPoint=(e.value&16)!==0,i.threeDPolylineVertex=(e.value&32)!==0,i.threeDPolylineMesh=(e.value&64)!==0,i.polyfaceMeshVertex=(e.value&128)!==0,e=t.next();break;case 50:e=t.next();break;case 71:i.faceA=e.value,e=t.next();break;case 72:i.faceB=e.value,e=t.next();break;case 73:i.faceC=e.value,e=t.next();break;case 74:i.faceD=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function El(h,t){const e=new Ol,i=[];for(;!h.isEOF();)if(t.code===0){if(t.value==="VERTEX")i.push(e.parseEntity(h,t)),t=h.lastReadGroup;else if(t.value==="SEQEND"){_l(h,t);break}}return i}function _l(h,t){const e={type:t.value};for(t=h.next();!h.isEOF()&&t.code!==0;)if(t.code===101)for(;t.code!=0;)t=h.next();else Q(e,t),t=h.next();return e}class Pl{constructor(){p(this,"ForEntityName","POLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:e=t.next();break;case 20:e=t.next();break;case 30:e=t.next();break;case 39:e=t.next(),i.thickness=e.value;break;case 40:e=t.next();break;case 41:e=t.next();break;case 70:i.shape=(e.value&1)!==0,i.includesCurveFitVertices=(e.value&2)!==0,i.includesSplineFitVertices=(e.value&4)!==0,i.is3dPolyline=(e.value&8)!==0,i.is3dPolygonMesh=(e.value&16)!==0,i.is3dPolygonMeshClosed=(e.value&32)!==0,i.isPolyfaceMesh=(e.value&64)!==0,i.hasContinuousLinetypePattern=(e.value&128)!==0,e=t.next();break;case 71:e=t.next();break;case 72:e=t.next();break;case 73:e=t.next();break;case 74:e=t.next();break;case 75:e=t.next();break;case 210:i.extrusionDirection=Al(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i.vertices=El(t,e),i}}function Al(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Il{constructor(){p(this,"ForEntityName","REGION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:i.modelerVersion=e.value,e=t.next();break;case 1:i.proprietaryData=e.value,e=t.next();break;case 3:i.proprietaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class kl{constructor(){p(this,"ForEntityName","RAY")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(yr(t)),e=t.lastReadGroup;break;case 11:i.directionVector=yr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function yr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Dl{constructor(){p(this,"ForEntityName","SEQEND")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===-2||(Q(i,e),e=t.next());return i}}class Bl{constructor(){p(this,"ForEntityName","SOLID")}parseEntity(t,e){const i={type:e.value,points:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.points[0]=Kt(t),e=t.lastReadGroup;break;case 11:i.points[1]=Kt(t),e=t.lastReadGroup;break;case 12:i.points[2]=Kt(t),e=t.lastReadGroup;break;case 13:i.points[3]=Kt(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=Kt(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function Kt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Ll{constructor(){p(this,"ForEntityName","SPLINE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.controlPoints||(i.controlPoints=[]),i.controlPoints.push($t(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push($t(t)),e=t.lastReadGroup;break;case 12:i.startTangent=$t(t),e=t.lastReadGroup;break;case 13:i.endTangent=$t(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=$t(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function $t(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}function Rl(h,t,e){let i=h;for(;i.code!==304;)switch(i.code){case 301:i=e.next();break;case 93:i=e.next();break;case 90:i=e.next();break;case 1:t.text=i.value,i=e.next();break;case 94:i=e.next();break;case 300:t.attrText=i.value,i=e.next();break;case 302:t.text=i.value?i.value:t.text,i=e.next();break;default:console.log("[DXF ACAD_TABLE] ignore code: "+i.code+", value: "+i.value),i=e.next();break}}function xr(h,t){const e={};for(h.code===171&&(e.cellType=h.value);!t.isEOF();){const i=t.next();if(i.code===0||i.code===171){t.lastReadGroup=i;break}if(i.code===301){Rl(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 Fl{constructor(){p(this,"ForEntityName","ACAD_TABLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=br(t),e=t.lastReadGroup;break;case 11:i.directionVector=br(t),e=t.lastReadGroup;break;case 90:i.tableValue=e.value,e=t.next();break;case 91:i.rowCount=e.value,e=t.next();break;case 92:i.columnCount=e.value,e=t.next();break;case 93:i.overrideFlag=e.value,e=t.next();break;case 94:i.borderColorOverrideFlag=e.value,e=t.next();break;case 95:i.borderLineWeightOverrideFlag=e.value,e=t.next();break;case 96:i.borderVisibilityOverrideFlag=e.value,e=t.next();break;case 141:i.rowHeightArr?i.rowHeightArr.push(e.value):i.rowHeightArr=[e.value],e=t.next();break;case 142:i.columnWidthArr?i.columnWidthArr.push(e.value):i.columnWidthArr=[e.value],e=t.next();break;case 280:i.version=e.value,e=t.next();break;case 342:i.tableStyleId=e.value,e=t.next();break;case 343:i.blockRecordHandle=e.value,e=t.next();break;case 171:i.cells?i.cells.push(xr(e,t)):i.cells=[xr(e,t)],e=t.lastReadGroup;break;default:Q(i,e),e=t.next();break}return i}}function br(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class zl{constructor(){p(this,"ForEntityName","TEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=vr(t),e=t.lastReadGroup;break;case 11:i.endPoint=vr(t),e=t.lastReadGroup;break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 72:i.halign=e.value,e=t.next();break;case 73:i.valign=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 71:i.mirrored=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function vr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class jl{constructor(){p(this,"ForEntityName","VIEWPORT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 68:i.viewportStatus=e.value,e=t.next();break;case 40:i.width_paperSpace=e.value,e=t.next();break;case 41:i.height_paperSpace=e.value,e=t.next();break;case 69:i.viewportId=e.value,e=t.next();break;case 10:i.centerPoint=qe(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=qe(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=qe(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=qe(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=qe(t),e=t.lastReadGroup;break;case 16:i.viewDirection=qe(t),e=t.lastReadGroup;break;case 17:i.viewTarget=qe(t),e=t.lastReadGroup;break;case 42:i.perspectiveLens=e.value,e=t.next();break;case 43:i.frontClippingPlaneZ=e.value,e=t.next();break;case 44:i.backClippingPlaneZ=e.value,e=t.next();break;case 45:i.viewHeight=e.value,e=t.next();break;case 50:i.snapAngle=e.value,e=t.next();break;case 51:i.viewTwistAngle=e.value,e=t.next();break;case 72:i.circleZoomPercent=e.value,e=t.next();break;case 331:i.frozenLayerHandles=i.frozenLayerHandles||[],i.frozenLayerHandles.push(e.value),e=t.next();break;case 90:i.viewportStatusFlags=e.value,e=t.next();break;case 340:i.viewportClippingBoundaryhandleId=e.value,e=t.next();break;case 1:i.plotStyleSheetName=e.value,e=t.next();break;case 281:i.renderMode=e.value,e=t.next();break;case 71:i.viewportFlag_ucs=e.value,e=t.next();break;case 74:i.ucsIcon=e.value,e=t.next();break;case 110:i.ucsOrigin=qe(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=qe(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=qe(t),e=t.lastReadGroup;break;case 345:i.ucsTableRecordHandle=e.value,e=t.next();break;case 346:i.baseUcsTableRecordHandle=e.value,e=t.next();break;case 79:i.orthographicType=e.value,e=t.next();break;case 146:i.elevation=e.value,e=t.next();break;case 170:i.shadePlotMode=e.value,e=t.next();break;case 61:i.frequency=e.value,e=t.next();break;case 292:i.lightingFlag=e.value,e=t.next();break;case 282:i.lightingType=e.value,e=t.next();break;case 141:i.viewBrightness=e.value,e=t.next();break;case 142:i.viewContrast=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function qe(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.isEOF();){switch(e.code){case 10:case 12:case 13:case 14:case 15:case 16:case 17:case 110:case 111:case 112:t.x=e.value;break;case 20:case 22:case 23:case 24:case 25:case 26:case 27:case 120:case 121:case 122:t.y=e.value;break;case 30:case 32:case 33:case 34:case 35:case 36:case 37:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=h.next()}return t}class Vl{constructor(){p(this,"ForEntityName","XLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(wr(t)),e=t.lastReadGroup;break;case 11:i.directionVector=wr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function wr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Ul{constructor(){p(this,"ForObjectName","DICTIONARY")}parseObject(t,e){const s={type:e.value},r=[],n=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 280:s.isHardOwner=e.value===1,e=t.next();break;case 281:s.cloningFlag=e.value,e=t.next();break;case 3:r.push(e.value),e=t.next();break;case 350:n.push(e.value),e=t.next();break;case 360:n.push(e.value),e=t.next();break;case 100:e=t.next();break;case 102:e=t.next();break;default:Yt(s,e),e=t.next();break}if(r.length!==n.length)throw new Error("The number of Dictionary entries does not match !");return s.entries={},r.forEach((a,o)=>{s.entries[n[o]]=a}),s}}class Nl{constructor(){p(this,"ForObjectName","IMAGEDEF")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 90:s.classVersion=e.value,e=t.next();break;case 1:s.filename=e.value,e=t.next();break;case 10:s.imageSize=Mr(t),e=t.next();break;case 11:s.pixelSize=Mr(t),e=t.next();break;case 280:s.loaded=e.value,e=t.next();break;case 281:s.resolutionUnits=e.value,e=t.next();break;default:Yt(s,e),e=t.next();break}return s}}function Mr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Hl{constructor(){p(this,"ForObjectName","LAYOUT")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 1:s.layoutName=e.value,e=t.next();break;case 70:s.flag=e.value,e=t.next();break;case 71:s.tabOrder=e.value,e=t.next();break;case 76:s.orthographicType=e.value,e=t.next();break;case 10:s.minLimit=ot(t),e=t.lastReadGroup;break;case 11:s.maxLimit=ot(t),e=t.lastReadGroup;break;case 12:s.basePoint=ot(t),e=t.lastReadGroup;break;case 13:s.origin=ot(t),e=t.lastReadGroup;break;case 14:s.minExtent=ot(t),e=t.lastReadGroup;break;case 15:s.maxExtent=ot(t),e=t.lastReadGroup;break;case 16:s.XAxis=ot(t),e=t.lastReadGroup;break;case 17:s.YAxis=ot(t),e=t.lastReadGroup;break;case 146:s.elevation=e.value,e=t.next();break;case 330:s.viewportHandle=e.value,e=t.next();break;default:Yt(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function ot(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Gl{constructor(){p(this,"ForObjectName","SORTENTSTABLE")}parseObject(t,e){const s={type:e.value};let r=!1;s.sortEntsObject={},s.sortEntsObject.entityHandles=[];let n=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 5:r?(n.push(e.value),s.sortEntsObject.entityHandles.push(n),n=[]):s.handle=e.value,e=t.next();break;case 100:e=t.next(),r=!0;break;case 102:e=t.next();break;case 330:r?s.sortEntsObject.ownerHandle=e.value:s.ownerHandle=e.value,e=t.next();break;case 331:n.push(e.value),e=t.next();break;default:Yt(s,e),e=t.next();break}return s}}class ql{constructor(){p(this,"ForObjectName","SPATIAL_FILTER")}parseObject(t,e){const s={type:e.value};s.vertices=[];let r,n;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 11:s.origin=Gi(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),r=Gi(t),e=t.lastReadGroup,n=Gi(t),e=t.lastReadGroup,s.vertices.push(r,{x:n.x,y:r.y},n,{x:r.x,y:n.y},r)):s.numberOfPointsOnClipBoundary>2?(s.vertices=Wl(s.numberOfPointsOnClipBoundary,t),e=t.lastReadGroup):e=t.next();break;case 71:s.clipBoundaryVisible=e.value===1,e=t.next();break;case 72:s.frontClippingPlaneFlag=e.value===1,e=t.next(),s.frontClippingPlaneFlag&&e.code===40&&(s.frontClippingPlaneDistance=e.value,e=t.next());break;case 73:s.backClippingPlaneFlag=e.value===1,e=t.next(),s.backClippingPlaneFlag&&e.code===41&&(s.backClippingPlaneDistance=e.value,e=t.next());break;case 100:e=t.next();break;case 102:e=t.next();break;case 210:s.extrusionDirectionX=e.value,e=t.next();break;case 220:s.extrusionDirectionY=e.value,e=t.next();break;case 230:s.extrusionDirectionZ=e.value,e=t.next();break;case 40:s.invertBlockMatrix=Tr(t,40),s.matrix=Tr(t,40),e=t.lastReadGroup;break;default:Yt(s,e),e=t.next();break}return s}}function Wl(h,t){t.next();const e=[];for(;e.length<h;)e.push(Gi(t));return e}function Tr(h,t){let e=h.lastReadGroup;const i=[];for(let s=0;s<12;s++){if(e.code!==t)throw new Error("Expected code for matrix value to be "+t+" but got "+e.code);i.push(e.value),e=h.next()}return i}function Gi(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Yl{constructor(){p(this,"ForObjectName","XRECORD")}parseObject(t,e){const s={type:e.value,binaryData:""};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 280:s.cloningFlag=e.value,e=t.next();break;case 310:s.binaryData+=e.value,e=t.next();break;case 311:e=t.next();break;default:Yt(s,e),e=t.next();break}return s}}function Xl(h){h.registerEntityHandler(Jo),h.registerEntityHandler(Qo),h.registerEntityHandler(tl),h.registerEntityHandler(il),h.registerEntityHandler(sl),h.registerEntityHandler(nl),h.registerEntityHandler(al),h.registerEntityHandler(ll),h.registerEntityHandler(pl),h.registerEntityHandler(ml),h.registerEntityHandler(gl),h.registerEntityHandler(xl),h.registerEntityHandler(vl),h.registerEntityHandler(Ml),h.registerEntityHandler(Tl),h.registerEntityHandler(Cl),h.registerEntityHandler(Sl),h.registerEntityHandler(Pl),h.registerEntityHandler(Il),h.registerEntityHandler(kl),h.registerEntityHandler(Dl),h.registerEntityHandler(Bl),h.registerEntityHandler(Ll),h.registerEntityHandler(Fl),h.registerEntityHandler(zl),h.registerEntityHandler(jl),h.registerEntityHandler(Vl)}function Zl(h){h.registerObjectHandler(Ul),h.registerObjectHandler(Nl),h.registerObjectHandler(Hl),h.registerObjectHandler(Gl),h.registerObjectHandler(ql),h.registerObjectHandler(Yl)}function Kl(h){const t=new Uint8Array(h,0,18);let e="";for(let i=0;i<18;i++)e+=String.fromCharCode(t[i]);return e==="AutoCAD Binary DXF"}class Mn{constructor(t){p(this,"_entityHandlers",{});p(this,"_objectHandlers",{});p(this,"_layoutBlocks",{});p(this,"unhandledSections",{});p(this,"unhandledObjects",{});p(this,"unhandledEntities",{});p(this,"unsupportedLineTypes",{});p(this,"encoding");this.encoding=t,Xl(this),Zl(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new dr(e);return this._parse(i)}else{let e;if(Kl(t))e=new Yo(t);else{const i=new TextDecoder(this.encoding).decode(t),s=Date.now(),r=this.splitByLineSeparator(i);console.info("[DxfParser] string.split took "+(Date.now()-s)/1e3+"s, it is avoidable by using dxf in binary."),e=new dr(r)}return this._parse(e)}}registerEntityHandler(t){const e=new t;this._entityHandlers[e.ForEntityName]=e}registerObjectHandler(t){const e=new t;this._objectHandlers[e.ForObjectName]=e}parseSync(t){return this.parse(t)}parseStream(t){let e="";const i=this;return new Promise((s,r)=>{t.on("data",n=>{e+=n}),t.on("end",()=>{try{s(i.parse(e))}catch(n){r(n)}}),t.on("error",n=>{r(n)})})}_parse(t){const e={};let i=0;if(!t.hasNext())throw Error("Empty file");const s=this;let r;function n(){for(r=t.next();r.code===999;)r=t.next();for(;!t.isEOF();)if(r.code===0&&r.value==="SECTION"){if(r=t.next(),r.code!==2){console.error("Unexpected code %s after 0:SECTION",Tn(r)),r=t.next();continue}if(r.value==="HEADER")S.trace("> HEADER"),e.header=a(),S.trace("<");else if(r.value==="TABLES")S.trace("> TABLES"),e.tables=c(),S.trace("<");else if(r.value==="BLOCKS")S.trace("> BLOCKS"),e.blocks=o(),S.trace("<");else if(r.value==="ENTITIES")S.trace("> ENTITIES"),e.entities=E(!1),S.trace("<");else if(r.value==="OBJECTS")S.trace("> OBJECTS"),e.objects=O(),S.trace("<");else if(r.value==="EOF")S.trace("EOF");else{const C=r.value;s.unhandledSections[C]?s.unhandledSections[C]++:s.unhandledSections[C]=1}}else r=t.next();s.unhandledSections={},s.unhandledEntities={},s.unhandledObjects={},s.unsupportedLineTypes={}}function a(){let C=null,w=null;const M={};for(r=t.next();;){if(Pe(r,0,"ENDSEC")){C&&(M[C]=w);break}else r.code===9?(C&&(M[C]=w),C=r.value):r.code===10?w={x:r.value}:r.code===20?w.y=r.value:r.code===30?w.z=r.value:w=r.value;r=t.next()}return r=t.next(),M}function o(){const C={};for(r=t.next();r.value!=="EOF"&&!Pe(r,0,"ENDSEC");)if(Pe(r,0,"BLOCK")){S.trace("block {");const w=l();S.trace("}"),_(w),w.name?C[w.name]=w:console.error("[DxfParser] Block with handle '"+w.handle+"' is missing a name, ignored!")}else Je(r),r=t.next();return C}function l(){const C={};for(r=t.next();r.value!=="EOF";){switch(r.code){case 1:C.xrefPath=r.value,r=t.next();break;case 2:C.name=r.value,r=t.next();break;case 3:C.name2=r.value,r=t.next();break;case 4:C.description=r.value,r=t.next();break;case 5:C.handle=r.value,r=t.next();break;case 8:C.layer=r.value,r=t.next();break;case 10:C.position=Ie(t),r=t.lastReadGroup;break;case 67:C.paperSpace=!!(r.value&&r.value===1),r=t.next();break;case 70:C.blockType=r.value,r=t.next();break;case 100:r=t.next();break;case 330:C.ownerHandle=r.value,r=t.next();break;case 0:if(r.value==="ENDBLK")break;C.entities=E(!0);break;default:Je(r),r=t.next();break}if(Pe(r,0,"ENDBLK")){r=t.next();break}}return C}function c(){const C={};for(r=t.next();r.value!=="EOF"&&!Pe(r,0,"ENDSEC");)Pe(r,0,"TABLE")?(r=t.next(),b[r.value]?(S.trace(r.value+" Table {"),C[b[r.value].tableName]=f(r),S.trace("}")):S.trace("Unhandled Table "+r.value)):r=t.next();return r=t.next(),C}const u="ENDTAB";function f(C){const w=b[C.value],M={};let P=0;for(r=t.next();!Pe(r,0,u);)switch(r.code){case 5:M.handle=r.value,r=t.next();break;case 330:M.ownerHandle=r.value,r=t.next();break;case 100:r.value==="AcDbSymbolTable"||Je(r),r=t.next();break;case 70:P=r.value,r=t.next();break;case 0:r.value===w.dxfSymbolName?M[w.tableRecordsProperty]=w.parseTableRecords():(Je(r),r=t.next());break;default:Je(r),r=t.next();break}const A=M[w.tableRecordsProperty];if(A){const I=(()=>{if(A.constructor===Array)return A.length;if(typeof A=="object")return Object.keys(A).length})();P!==I&&console.warn("[DxfParser] Parsed "+I+" "+w.dxfSymbolName+"s but expected "+P)}return r=t.next(),M}function m(){const C=[];let w={};for(S.trace("Viewport {"),r=t.next();!Pe(r,0,u);)switch(r.code){case 2:w.name=r.value,r=t.next();break;case 10:w.lowerLeftCorner=Ie(t),r=t.lastReadGroup;break;case 11:w.upperRightCorner=Ie(t),r=t.lastReadGroup;break;case 12:w.center=Ie(t),r=t.lastReadGroup;break;case 13:w.snapBasePoint=Ie(t),r=t.lastReadGroup;break;case 14:w.snapSpacing=Ie(t),r=t.lastReadGroup;break;case 15:w.gridSpacing=Ie(t),r=t.lastReadGroup;break;case 16:w.viewDirectionFromTarget=Ie(t),r=t.lastReadGroup;break;case 17:w.viewTarget=Ie(t),r=t.lastReadGroup;break;case 40:w.viewHeight=r.value,r=t.next();break;case 41:w.aspectRatio=r.value,r=t.next();break;case 42:w.lensLength=r.value,r=t.next();break;case 43:w.frontClippingPlane=r.value,r=t.next();break;case 44:w.backClippingPlane=r.value,r=t.next();break;case 45:w.viewHeight=r.value,r=t.next();break;case 50:w.snapRotationAngle=r.value,r=t.next();break;case 51:w.viewTwistAngle=r.value,r=t.next();break;case 79:w.orthographicType=r.value,r=t.next();break;case 110:w.ucsOrigin=Ie(t),r=t.lastReadGroup;break;case 111:w.ucsXAxis=Ie(t),r=t.lastReadGroup;break;case 112:w.ucsYAxis=Ie(t),r=t.lastReadGroup;break;case 281:w.renderMode=r.value,r=t.next();break;case 282:w.defaultLightingType=r.value,r=t.next();break;case 292:w.defaultLightingOn=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 63:case 421:case 431:w.ambientColor=r.value,r=t.next();break;case 0:r.value==="VPORT"&&(S.trace("}"),C.push(w),S.trace("Viewport {"),w={},r=t.next());break;default:Je(r),r=t.next();break}return S.trace("}"),C.push(w),C}function g(){const C={};let w={},M=0,P="",A=!1;for(S.trace("LType {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.name=r.value.toUpperCase(),P=w.name,r=t.next();break;case 3:w.description=r.value,r=t.next();break;case 9:r=t.next();break;case 40:w.patternLength=r.value,r=t.next();break;case 44:r=t.next();break;case 45:r=t.next();break;case 46:r=t.next();break;case 49:let I=r.value;A&&(I=Math.abs(I),A=!1),w.pattern.push(I),r=t.next();break;case 70:r=t.next();break;case 73:M=r.value,M>0&&(w.pattern=[]),r=t.next();break;case 74:r.value!==0&&(A=!0,s.unsupportedLineTypes[w.name]?s.unsupportedLineTypes[w.name]++:s.unsupportedLineTypes[w.name]=1),r=t.next();break;case 75:r=t.next();break;case 0:S.trace("}"),M>0&&M!==w.pattern.length&&console.warn("[DxfParser] lengths do not match on LTYPE pattern"),C[P]=w,w={},S.trace("LType {"),r=t.next();break;default:r=t.next();break}return S.trace("}"),C[P]=w,C}function x(){const C={};let w={},M;for(S.trace("Layer {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.name=r.value,M=r.value,r=t.next();break;case 5:w.handle=r.value,r=t.next();break;case 62:w.visible=r.value>=0,w.colorIndex=Math.abs(r.value),w.color=Nt(w.colorIndex),r=t.next();break;case 70:w.flag=r.value,w.frozen=(w.flag&1)>0,r=t.next();break;case 420:w.color=Math.abs(r.value),r=t.next();break;case 6:w.lineType=r.value.toUpperCase(),r=t.next();break;case 370:w.lineweight=r.value,r=t.next();break;case 0:r.value==="LAYER"&&(S.trace("}"),M&&(C[M]=w),S.trace("Layer {"),w={},M=void 0,r=t.next());break;default:Je(r),r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function y(){const C={};let w={},M;for(S.trace("Style {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.styleName=r.value,M=r.value,r=t.next();break;case 3:w.fontFile=r.value,r=t.next();break;case 4:w.bigFontFile=r.value,r=t.next();break;case 5:w.handle=r.value,r=t.next();break;case 40:w.textHeight=r.value,r=t.next();break;case 41:w.xScale=r.value,r=t.next();break;case 42:w.priorTextHeight=r.value,r=t.next();break;case 50:w.rotation=r.value,r=t.next();break;case 70:r=t.next();break;case 71:w.mirrorType=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 0:r.value==="STYLE"&&(S.trace("}"),M&&(C[M]=w),S.trace("Style {"),w={},M=void 0,r=t.next());break;default:r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function T(){const C={};let w={},M;for(S.trace("DimStyle {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.styleName=r.value,M=r.value,r=t.next();break;case 40:w.DIMSCALE=r.value,r=t.next();break;case 41:w.DIMASZ=r.value,r=t.next();break;case 42:w.DIMEXO=r.value,r=t.next();break;case 44:w.DIMEXE=r.value,r=t.next();break;case 75:w.DIMSE1=r.value,r=t.next();break;case 76:w.DIMSE2=r.value,r=t.next();break;case 77:w.DIMTAD=r.value,r=t.next();break;case 140:w.DIMTXT=r.value,r=t.next();break;case 144:w.DIMLFAC=r.value,r=t.next();break;case 147:w.DIMGAP=r.value,r=t.next();break;case 176:w.DIMCLRD=r.value,r=t.next();break;case 178:w.DIMCLRT=r.value,r=t.next();break;case 271:w.DIMDEC=r.value,r=t.next();break;case 341:w.DIMLDRBLK=r.value,r=t.next();break;case 70:r=t.next();break;case 0:r.value==="DIMSTYLE"&&(S.trace("}"),M&&(C[M]=w),S.trace("DimStyle {"),w={},M=void 0,r=t.next());break;default:r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function v(){const C={};let w={},M;for(S.trace("BlockRecord {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 5:w.handle=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 2:w.blockName=r.value,M=w.blockName,r=t.next();break;case 340:w.layoutHandle=r.value,r=t.next();break;case 70:w.blockInsertUnits=r.value,r=t.next();break;case 280:w.blockExplodability=r.value,r=t.next();break;case 281:w.blockScalability=r.value,r=t.next();break;case 310:w.bitmap=r.value,r=t.next();break;case 0:if(r.value==="BLOCK_RECORD"){S.trace("}"),M&&(C[M]=w);const A=w.layoutHandle;M&&A&&A.length>0&&A!=="0"&&(s._layoutBlocks[A]=w),S.trace("BlockRecord {"),w={},M=void 0,r=t.next()}else Je(r),r=t.next();break;default:Je(r),r=t.next();break}S.trace("}"),M&&(C[M]=w);const P=w.layoutHandle;return M&&P&&P.length>0&&P!=="0"&&(s._layoutBlocks[P]=w),C}const b={VPORT:{tableRecordsProperty:"viewports",tableName:"viewport",dxfSymbolName:"VPORT",parseTableRecords:m},LTYPE:{tableRecordsProperty:"lineTypes",tableName:"lineType",dxfSymbolName:"LTYPE",parseTableRecords:g},LAYER:{tableRecordsProperty:"layers",tableName:"layer",dxfSymbolName:"LAYER",parseTableRecords:x},BLOCK_RECORD:{tableRecordsProperty:"blockRecords",tableName:"blockRecord",dxfSymbolName:"BLOCK_RECORD",parseTableRecords:v},STYLE:{tableRecordsProperty:"styles",tableName:"style",dxfSymbolName:"STYLE",parseTableRecords:y},DIMSTYLE:{tableRecordsProperty:"dimStyles",tableName:"dimStyle",dxfSymbolName:"DIMSTYLE",parseTableRecords:T}};function E(C){const w=[],M=C?"ENDBLK":"ENDSEC";for(C||(r=t.next());;)if(r.code===0){if(r.value===M)break;const P=s._entityHandlers[r.value];if(P!=null){S.trace(r.value+" {");const A=P.parseEntity(t,r);A&&(A.layer||(A.layer="0"),A.colorIndex===void 0&&(A.colorIndex=256),A.lineType||(A.lineType="BYLAYER"),r=t.lastReadGroup,S.trace("}"),_(A),w.push(A))}else{const A=r.value;s.unhandledEntities[A]||(s.unhandledEntities[A]=0),s.unhandledEntities[A]++,r=t.next();continue}}else r=t.next();return M==="ENDSEC"&&(r=t.next()),w}function O(){const C={},w="ENDSEC";for(r=t.next();r.value!=="EOF";)if(r.code===0){if(r.value===w)break;const M=s._objectHandlers[r.value];if(M!=null){S.trace(r.value+" {");const P=M.parseObject(t,r),A=r.value;r=t.lastReadGroup,S.trace("}"),_(P),C[A]||(C[A]=[]),C[A].push(P)}else{const P=r.value;s.unhandledObjects[P]||(s.unhandledObjects[P]=0),s.unhandledObjects[P]++,r=t.next();continue}}else r=t.next();return r=t.next(),C.LAYOUT&&(Object.keys(s._layoutBlocks).length!==C.LAYOUT.length&&console.warn("[DxfParser] The number of layout and block associations does not match!"),C.LAYOUT.forEach(M=>{s._layoutBlocks[M.handle]&&(M.associatedBlockName=s._layoutBlocks[M.handle].blockName)}),C.LAYOUT.sort((M,P)=>M.tabOrder-P.tabOrder)),C}function _(C){if(!C)throw new TypeError("entity cannot be undefined or null");C.handle||(C.handle=(i++).toString())}return n(),e}splitByLineSeparator(t){const e=[];let i=0;for(let s=0,r=t.length;s<r;++s){const n=t[s];if(n==="\r"||n===`
792
- `){let a=t.substring(i,s);a&&a.indexOf("M+")>-1&&(a=Uo(a)),a&&(a=a),e.push(a),n==="\r"&&t[s+1]===`
793
- `&&s++,i=s+1}}return e.push(t.substring(i,t.length)),e}}function Pe(h,t,e){return h.code===t&&h.value===e}function Je(h){S.trace("unhandled group "+Tn(h))}function Tn(h){return h.code+":"+h.value}const Cn="0.4.0",Sn="VERSION",$l=()=>window.localStorage.getItem(Sn),Jl=()=>{window.localStorage.setItem(Sn,Cn)},Ql=()=>$l()!==Cn?(Jl(),!0):!1,Tt=class Tt{constructor(){p(this,"DATABASE_NAME","x_viewer");p(this,"DEFAULT_TABLES",[{name:"dxf_data",options:{keyPath:"dxfDataId",autoIncrement:!1}},{name:"fonts",options:{keyPath:"fileName",autoIncrement:!0}}]);p(this,"db");p(this,"tables");this.db=void 0,this.tables=this.DEFAULT_TABLES}static instance(){return!Tt._instance&&(Tt._instance=new Tt),Tt._instance}setTables(t){this.tables=t}getTables(){return this.tables}async getDatabase(){let t=await this.getDB(this.DATABASE_NAME);return this.db||(t.close(),Ql()&&await this.deleteDataBase(this.DATABASE_NAME),t=await this.getUpgradedDB(t)),t.onclose=()=>{this.db=void 0,S.debug("[DB] Db "+t.name+" is closed.")},t.onerror=e=>{this.db=void 0,S.debug("[DB] Db "+t.name+" encountered error.",e)},t.onabort=e=>{this.db=void 0,S.debug("[DB] Db "+t.name+" aborted.",e)},t.onversionchange=e=>{S.debug("onversionchange",e)},this.db=t,Promise.resolve(this.db)}closeDatabase(){this.db&&this.db.close()}deleteDataBase(t){return new Promise((e,i)=>{const s=window.indexedDB.deleteDatabase(t);s.onerror=r=>{S.debug(r),i(r)},s.onsuccess=r=>{const n=r.target;S.debug("[DB] Db "+t+" delete old version "+r.oldVersion+"."),e(n)}})}async getDB(t){return new Promise((e,i)=>{const s=window.indexedDB.open(t);s.onerror=i,s.onsuccess=r=>{const n=r.target.result;S.debug("[DB] Db "+n.name+" opened (version "+n.version+")."),e(n)}})}async getUpgradedDB(t){return new Promise((e,i)=>{S.debug("[DB] Upgrading db "+t.name+" (version "+t.version+")");const s=window.indexedDB.open(t.name,t.version+1);s.onerror=i,s.onblocked=r=>{S.debug("onblocked",r)},s.onupgradeneeded=r=>{const n=r.target.transaction;n.oncomplete=()=>{S.debug("[DB] Upgrade is done (new version: "+a.version+").")};const a=r.target.result,o=[];for(let l=0;l<this.tables.length;++l){const c=this.tables[l];if(!a.objectStoreNames.contains(c.name)){S.debug("[DB] Creating table "+c.name+"...");const u=this.createTable(a,c.name,c.options,c.indexArray);o.push(u)}}o.length>0&&Promise.all(o).then(()=>{S.debug("[DB] All("+o.length+") tables created.")})},s.onsuccess=r=>{const n=r.target.result;S.debug("[DB] Db "+n.name+" opened (version "+n.version+")."),e(n)}})}async createTable(t,e,i,s){return new Promise(r=>{const n=t.createObjectStore(e,i);s&&s.forEach(a=>{n.createIndex(a.name,a.fields,{unique:a.unique})}),S.debug("[DB] Table "+e+" created."),r(t)})}};p(Tt,"_instance");let ae=Tt;class On{constructor(){p(this,"db");p(this,"isCreatingTable");if(this.db=void 0,this.isCreatingTable=!1,ae.instance().getTables().findIndex(i=>i.name===this.tableName())===-1)throw new Error("Failed to find table '"+this.tableName()+"' from indexeddb!")}tableName(){throw new Error("Derived class have to override 'tableName', and set a proper table name!")}add(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.add(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()}).catch(r=>{i&&i(r)})}save(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.put(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()})}delete(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.delete(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()})}update(){ae.instance().getDatabase().then(()=>{})}query(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readonly").objectStore(i),n=r.openCursor();n.onsuccess=a=>{const o=a.target.result;o&&o.continue(),t&&t(o)},n.onerror=e}).finally(()=>{ae.instance().closeDatabase()})}queryByIndex(t,e,i,s){const r=this.tableName();ae.instance().getDatabase().then(n=>{const a=n.transaction([r],"readonly").objectStore(r),o=a.index(t).get(e);o.onerror=s,o.onsuccess=function(l){const c=l.target?.result;i&&i(c)}}).finally(()=>{ae.instance().closeDatabase()})}queryAll(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readonly").objectStore(i),n=r.getAll();n.onsuccess=a=>{t&&t(a.target.result)},n.onerror=e}).finally(()=>{ae.instance().closeDatabase()})}clearAll(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readwrite").objectStore(i),n=r.clear();n.onsuccess=a=>{t&&t(a)},n.onerror=a=>{e&&e(a)}}).finally(()=>{ae.instance().closeDatabase()})}}const Ct=class Ct extends On{tableName(){return"dxf_data"}static instance(){return!Ct._instance&&(Ct._instance=new Ct),Ct._instance}query(t,e,i){const s=[],r=this.tableName();ae.instance().getDatabase().then(n=>{const a=n.transaction([r],"readonly").objectStore(r),o=a.get(t);o.onerror=l=>{i&&i(l),S.info("[DxfDataTable] Failed to query !",l)},o.onsuccess=()=>{o.result&&s.push(o.result),e&&e(s)}}).finally(()=>{ae.instance().closeDatabase()})}};p(Ct,"_instance");let Wi=Ct;const Ae=new d.Vector3(1,0,0),ds=new d.Vector3(0,1,0),Et=new d.Vector3(0,0,1),Cr=new d.Vector3(0,0,0),ct=16777215,eh="CONTINUOUS",Si=new d.PointsMaterial({color:ct}),le=new d.LineBasicMaterial({color:ct}),_t=new d.MeshBasicMaterial({color:ct}),Sr=new d.BufferGeometry().setFromPoints([new d.Vector3]),Or=new d.Matrix4,Fe=new d.Matrix4,ne=new d.Matrix4,z=new d.Vector3,Z=new d.Vector3,ze=new d.Vector3,Jt=new d.Vector2,he=new d.Quaternion,Oi=new d.Object3D,We=new d.Box3,Er=new d.PointsMaterial({color:65280,size:5,depthTest:!1}),_r=new d.PointsMaterial({color:65280,depthTest:!1}),Pr=new d.PointsMaterial({color:65280,depthTest:!1}),th=h=>h.viewDirectionFromTarget!==void 0,ih=h=>{if(h){const t=h.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);if(t&&t.length>0){const e=t[1],i=h.replace("data:"+e+";","").split(",");if(i&&i.length===2&&i[0]==="base64"){const s=i[1];return Ga.decode(s)}}}return null},Ar=(h,t)=>{const e=new d.Vector2(h.x,h.y),i=new d.Vector2(t.x,t.y);return i.sub(e),i.normalize(),i.y<0?-Math.acos(i.x):Math.acos(i.x)},Ir=(h,t,e)=>({x:h.x+t*Math.cos(e),y:h.y+t*Math.sin(e)}),sh=(h,t,e,i)=>{const s=h?new d.Vector2(h.x,h.y):new d.Vector2(0,0),r=t?new d.Vector2(t.x,t.y):new d.Vector2(1,0);e=e||1;const n=4*Math.atan(e),a=s.distanceTo(r)/2/Math.sin(n/2),o=Ir(h,a,Ar(s,r)+(Math.PI/2-n/2));i=i||Math.max(Math.abs(Math.ceil(n/(Math.PI/18))),6);const l=Ar(o,s),c=n/i,u=[];u.push(new d.Vector3(s.x,s.y,0));for(let f=1;f<=i-1;f++){const m=Ir(o,Math.abs(a),l+c*f);u.push(new d.Vector3(m.x,m.y,0))}return u},kr=(h,t,e,i=h.length*2,s)=>{const r=[];if(!h||h.length<t+1||t<1)return r;const n=h.map(a=>[a.x,a.y]);try{for(let a=0;a<1;a+=1/i){const o=pn(a,t,n,e,s);r.push(new d.Vector3(o[0],o[1],0))}}catch{if(r.length===0)return r}return r},us=(h,t=!1)=>{const e=[],i=h.length;for(let s=0;s<i;s++){const r=h[s];if(r.bulge&&(s!==i-1||t)){const n=r.bulge,a=s+1<i?h[s+1]:e[0],o=sh(r,a,n);e.push(...o)}else e.push(new d.Vector3(r.x,r.y,0))}return e},rh=h=>{const t=[];return h.faceA&&t.push(h.faceA),h.faceB&&t.push(h.faceB),h.faceC&&t.push(h.faceC),h.faceD&&t.push(h.faceD),t},nh=h=>{const t=[],e=[];h.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new d.Vector3(s.x,s.y,s.z)):e.push(rh(s)))});const i=[];for(let s=0;s<e.length;s++){const r=e[s];if(r.length===0)continue;const n=[];let a=!0;for(let o=0;o<r.length;o++){const l=r[o]-1;if(l>=t.length||l<0){a=!1;break}n.push(t[l])}!a||n.length===0||(n.push(n[0]),i.push(n))}return i},j=class j extends d.Loader{constructor(e,i){super(e);p(this,"timer");p(this,"ignorePaperSpace");p(this,"font");p(this,"encoding");p(this,"overrideColor");p(this,"overrideHatchPatternLineThickness");p(this,"angBase");p(this,"angDir");p(this,"header");p(this,"pointsMaterials");p(this,"lineBasicMaterials");p(this,"lineShaderMaterials");p(this,"meshBasicMaterials");p(this,"meshTextureMaterials");p(this,"hatchShaderMaterials");p(this,"entityCount");p(this,"curveCount");p(this,"averageCurveSize");p(this,"enableRenderOrder");p(this,"enableLocalCache");p(this,"enableReleaseData");p(this,"enableMerge");p(this,"enableRTC");p(this,"enablePlineWidth");p(this,"dxfDataId");p(this,"compareContext");p(this,"statsInfo");p(this,"llbDatas");p(this,"mtextDatas");p(this,"requestHeader");p(this,"blockReferencesCache");p(this,"blockRecordsCache");p(this,"entitiesCache");p(this,"blocksCache");p(this,"dictionaryOwnerHandleAndSpatialFilterHandlesCache");p(this,"spatialFiltersCache");p(this,"entityThreejsCache");p(this,"entityTypesAndTimes");p(this,"nonSnapableTypes");p(this,"layoutsSnapObjectsMap");p(this,"aborted");p(this,"entityHandlesWithRenderOrder");p(this,"addViewport");this.timer=Date.now(),this.ignorePaperSpace=!1,this.encoding="UTF-8",this.angBase=0,this.angDir=0,this.header=void 0,this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[],this.entityCount=0,this.curveCount=0,this.averageCurveSize=0,this.enableRenderOrder=!1,this.enableLocalCache=!1,this.enableReleaseData=!0,this.enableMerge=!0,this.enableRTC=!0,this.enablePlineWidth=!0,this.dxfDataId=void 0,this.compareContext=void 0,this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0,requestHeader:{}},this.llbDatas=[],this.mtextDatas=[],this.blockReferencesCache={},this.blockRecordsCache=void 0,this.entitiesCache=void 0,this.blocksCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.nonSnapableTypes=new Set(["ATTDEF","ATTRIB","LEADER","MTEXT","MULTILEADER","OLE2FRAME","TEXT"]),this.layoutsSnapObjectsMap={},this.aborted=!1,this.entityHandlesWithRenderOrder={},this.addViewport=(s,r)=>{if(s.type==="VIEWPORT"){!r[s.ownerHandle]&&(r[s.ownerHandle]=[]);const n=s;r[s.ownerHandle].push(n)}},i&&(this.ignorePaperSpace=i.ignorePaperSpace===!0,this.enableLocalCache=i.enableLocalCache===!0,this.enableMerge=j.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.overrideColor!=null&&(this.overrideColor=Gt.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[ct]=Si,this.lineBasicMaterials[ct]=le,this.meshBasicMaterials[ct]=_t}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=ih(e);if(!s){const r=Date.now(),n=new d.FileLoader(this.manager),a=j.REQUWSTHEADER;a&&n.setRequestHeader(a),n.setResponseType("arraybuffer"),n.setPath(this.path),s=await n.loadAsync(e,i),S.info("[Dxf] "+e+" dxf file downloaded in "+(Date.now()-r)/1e3+"s")}return s}async loadEx(e,i,s){return this.enableLocalCache&&i&&(i=i.trim()).length>0&&(this.dxfDataId=i),this.loadAsync(e,s)}async loadAsync(e,i){const s=V.getUpdateSubProgressFunc(0,50,i),r=V.getUpdateSubProgressFunc(50,100,i),n=V.getUpdateSubProgressFunc(10,100,i);if(be.isBrowser&&this.enableLocalCache&&this.dxfDataId){let l;try{if(this.timer=Date.now(),l=await this.getDxfDataFromIndexedDb(this.dxfDataId),l){this.tryFixDxfData(l),S.info("[Dxf] Loaded DxfData from indexedDb in "+(Date.now()-this.timer)/1e3+"s");const c=await this.loadEntities(l,n);return Promise.resolve(c)}}catch(c){S.warn("[Dxf] Failed to parse data from indexedDb",c)}}const a=await this.parse(e,s);return this.tryFixDxfData(a),await this.loadEntities(a,r)}async parse(e,i){const s=V.getUpdateProgressFunc(i),r=V.getUpdateSubProgressFunc(0,40,i),n=await this.download(e,r);if(!n)return Promise.reject("[Dxf] Failed to download "+e);if(this.aborted)return Promise.reject("[Dxf] Job aborted");this.timer=Date.now(),S.info("[Dxf] Start parsing...");const a=new Mn(this.encoding).parseSync(n);if(this.tryFixDxfData(a),s(80),S.info("[Dxf] Parsed in "+(Date.now()-this.timer)/1e3+"s, creating entities..."),this.aborted)return Promise.reject("[Dxf] Job aborted");if(a&&be.isBrowser&&this.enableLocalCache&&this.dxfDataId){const o=Date.now();try{await this.setDxfDataToIndexedDb(this.dxfDataId,a),S.info("[Dxf] Saved to indexedDb in "+(Date.now()-o)/1e3+"s")}catch(l){S.warn("[Dxf] Failed to save '"+this.dxfDataId+"' to indexedDb!",l)}}return s(100),a}abort(){this.aborted=!0}isAborted(){return this.aborted}parseHeader(e){if(!e){S.error("[Dxf]: Invalid header!");return}this.header=e;const i=e.$ACADVER.toString();i!=="AC1032"&&S.warn("[Dxf] Unexpected version: "+i+". But we'll try to continue."),this.angBase=e.$ANGBASE||0,this.angDir=e.$ANGDIR||0}tryFixDxfData(e){e&&(!e.objects&&(S.warn("[Dxf] No objects found, Will add one."),e.objects={}),!e.objects.LAYOUT&&(S.warn("[Dxf] No layout defined! Will add a default 'Model' layout!"),e.objects.LAYOUT=[{layoutName:j.MODEL_LAYOUT_NAME}]),!e.tables&&(S.warn("[Dxf] No tables found, Will add one."),e.tables={}),!e.tables.layer&&(e.tables.layer={}),!e.tables.layer.layers&&(e.tables.layer.layers={}))}async loadEntities(e,i){const s=Date.now();this.parseHeader(e.header),this.enableRenderOrder&&(this.initRenderOrderInfo(e),this.enableMerge=!1),this.getFontFilesFromDxf(e);let r=0;const n=e.entities.length;this.entityCount=n,Object.keys(e.blocks).forEach(b=>{this.entityCount+=e.blocks[b].entities?.length||0});const a=V.getUpdateProgressFuncForLoop(n,i);let o={};const l=b=>{const E=b.userData.layerName;let O=o[E];!O&&(O=[],o[E]=O),O.push(b)},c={},u={},f=new F;for(let b=0;b<n&&!this.aborted;b++){const E=e.entities[b];this.addViewport(E,c);const O=this.loadEntity(E,e);if(!O&&await a(b),!O)continue;const _=this.getLayout(e,E),C=_.layoutName;let w=f.children.find(M=>M.name===C);if(!w&&(w=new F,w.name=C,w.userData.isLayoutLevelObject=!0,f.add(w)),O.traverse(M=>{M.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[C]&&(this.layoutsSnapObjectsMap[C]=[]),this.layoutsSnapObjectsMap[C].push(M))}),this.enableMerge){Qe.merge(O,!1),!u[C]&&(u[C]={object:w,layerObjects:{}});const P=u[C];if(O.geometry){const A=O.userData.layerName;!P.layerObjects[A]&&(P.layerObjects[A]=[]),P.layerObjects[A].push(O),O.children.forEach(I=>{I.userData.isSnapObject&&l(I)})}else O.children.length>0&&(w.add(O),O.traverse(A=>{A.geometry&&l(A)}))}else w.add(O),O.traverse(M=>{M.geometry&&l(M)});r++,await a(b)}e.objects.LAYOUT.forEach(b=>{const E=b,O=E.layoutName;if(this.ignorePaperSpace&&O!==j.MODEL_LAYOUT_NAME)return;const _=E.associatedBlockName,C=e.blocks[_];C&&this.loadLayout(C,e,E,f,o,c)}),S.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const b in this.layoutsSnapObjectsMap){const E=f.children.find(C=>C.name===b),O=new F;O.name=j.SNAP_GROUP_NAME,O.userData.isSnapGroup=!0,E.add(O);const _=this.layoutsSnapObjectsMap[b];for(let C=0;C<_.length;C++){const w=_[C],M=w.userData.layerName;this.getLayerVisible(e,M)===!1&&w.layers.disable(Ce),j.SHOW_SNAP_OBJECT&&(w.layers.enableAll(),w.material instanceof d.PointsMaterial?w.material=Er:w.material instanceof d.LineBasicMaterial?w.material=_r:w.material instanceof d.MeshBasicMaterial&&(w.material=Pr));let P=w;const A=ne.identity();for(;P&&P.userData.isLayoutLevelObject!==!0;)A.premultiply(P.matrix),P=P.parent;w.matrix.copy(A),O.add(w)}}if(this.enableMerge)for(const b in u){const E=u[b],O=E.object;for(const _ in E.layerObjects){const C=E.layerObjects[_],w=Qe.deepMerge(C,void 0,!1,!1,!0),M=w.added,P=w.removed;if(P.length!==C.length){let A=P;P.length>=100&&(A=new Set(P));const I=k=>Array.isArray(A)?A.indexOf(k)>=0:A.has(k);for(let k=0,B=C.length;k<B;k++){const L=C[k];!I(L)&&(O.add(L),l(L))}}for(let A=0;A<M.length;A++){const I=M[A];O.add(I),l(I)}E.layerObjects[_]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&j.mergeDxfObjects({root:f,layersAndObjects:o});const g=f.convertToThreejsObject();f.clear(),o={};const x={};e.objects.LAYOUT.forEach(b=>{const E=b;x[E.layoutName]=E});const y={},T=b=>{const E=b.userData.layerName;let O=y[E];!O&&(O=[],y[E]=O),O.push(b)};g.children.forEach(b=>{if($.setSharedVariablesOfObject(b),!b.userData.isLayoutLevelObject)return;const E=b.name;let O;if(E!==j.MODEL_LAYOUT_NAME){const _=x[E];!_.directAssociatedLeafObjectSet&&(_.directAssociatedLeafObjectSet=new Set),O=_.directAssociatedLeafObjectSet}b.traverse(_=>{if($.setSharedVariablesOfObject(_),_.userData.isSnapGroup&&(_.visible=j.SHOW_SNAP_OBJECT),_.geometry){const C=_.userData.layerName;this.getLayerVisible(e,C)===!1&&(_.visible=!1,_.userData.layerVisible=!1),T(_),O&&O.add(_)}})}),S.info("[Dxf] loadEntities() done in "+(Date.now()-s)/1e3+"s");const v=Object.assign(Object.assign({},e),{threejsObject:g,layersAndThreejsObjects:y,loadedEntityCount:r,layoutViewportsMap:c});if(j.LOADLLDATA){const b=g.children[0].children,E=[];for(let O=0;O<b.length;O++){const _=b[O];if(_?.userData?.llbData){const C=new d.Box3().setFromObject(_);C.getSize(new d.Vector3);const w=C.getCenter(new d.Vector3);E.push({..._,boundingBox:{max:C.max,min:C.min,center:w}})}else if(_.children&&_.children.some(C=>C.userData?.llbData))for(let C=0;C<_.children.length;C++){const w=_.children[C];if(w.userData?.llbData){w.updateWorldMatrix(!0,!0);const M=new d.Box3().setFromObject(w);M.getSize(new d.Vector3);const P=M.getCenter(new d.Vector3);E.push({...w,boundingBox:{max:M.max,min:M.min,center:P}})}}}v.llbMesh=E}return Promise.resolve(v)}getFontFilesFromDxf(e){const i=new Set,s=e.tables?.style?.styles;if(s)for(const r in s){const n=s[r],a=n.fontFile,o=n.bigFontFile;a&&i.add(a),o&&i.add(o)}S.info("[Dxf] Fonts used by dxf: "+Array.from(i).join())}async loadEntitiesForCompare(e,i,s,r=!0,n){const a=e.entities.length,o=i.entities.length,l=async()=>{const u=this.compareContext,f=u.isTheFirstFile,m=f?e:i,g=new F,x=f?a:o;this.entityCount=x,Object.keys(m.blocks).forEach(w=>{this.entityCount+=m.blocks[w].entities?.length||0});const y=Math.round(Math.pow(x,.5));let T=Date.now();const v=async w=>{if(n&&(w%y===0||w===x-1)){let M=w+1;!f&&(M+=a),n(new ProgressEvent("parseProgress",{loaded:M,total:a+o}));const P=500,A=Date.now();(A-T>P||w===x-1)&&(await V.sleep(0),T=A)}};this.parseHeader(m.header);let b={};for(let w=0;w<x;w++){if(this.aborted)return;const M=m.entities[w],P=this.getLayout(m,M);if(P.layoutName!==j.MODEL_LAYOUT_NAME){await v(w);continue}const A=this.loadEntity(M,m);if(!A){await v(w);continue}let I=g.children.find(k=>k.name===j.MODEL_LAYOUT_NAME);!I&&(I=new F,I.name=j.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,g.add(I)),I.add(A),A.traverse(k=>{if(k.geometry){const B=k.userData.layerName,L=this.getLayerVisible(m,B);k.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[P.layoutName]&&(this.layoutsSnapObjectsMap[P.layoutName]=[]),this.layoutsSnapObjectsMap[P.layoutName].push(k),L===!1&&A.layers.disable(Ce));let q=b[B];!q&&(q=[],b[B]=q),q.push(k)}}),await v(w)}r&&f&&!u.preservedHandles&&(u.preservedHandles=new Set);for(const w in s){const M=s[w];f&&(M.type===Te.Added||M.type===Te.Modified)&&(u.preservedHandles?.add(M.handle),M.parentHandles&&M.parentHandles.forEach(A=>u.preservedHandles?.add(A)));let P=this.entityThreejsCache&&this.entityThreejsCache[M.handle];if(M.parentHandles&&(P=this.entityThreejsCache&&this.entityThreejsCache[M.parentHandles[M.parentHandles.length-1]]),P){if(P.parent&&P.parent.userData.originalType){this.setObjectColorByChange(P,{type:Te.NoChange});continue}P=this.setObjectColorByChange(P,M)}if(M.type!==Te.NoChange&&P){let A=P.parent;const I=ne.identity();for(;A&&A.userData.isLayoutLevelObject!==!0;)I.premultiply(A.matrix),A=A.parent;We.makeEmpty();const k=F.getBox(P,We);k.applyMatrix4(I),M.type===Te.Added?!f&&(M.box=new d.Box3().copy(k)):M.type===Te.Removed?f&&(M.box=new d.Box3().copy(k)):M.type===Te.Modified&&(M.box?M.box.union(k):M.box=new d.Box3().copy(k))}}for(const w in this.layoutsSnapObjectsMap){const M=g.children.find(I=>I.name===w),P=new F;P.name=j.SNAP_GROUP_NAME,M.add(P);const A=this.layoutsSnapObjectsMap[w];for(let I=0;I<A.length;I++){const k=A[I];j.SHOW_SNAP_OBJECT&&(k.layers.enableAll(),k.material instanceof d.PointsMaterial?k.material=Er:k.material instanceof d.LineBasicMaterial?k.material=_r:k.material instanceof d.MeshBasicMaterial&&(k.material=Pr));let B=k;const L=ne.identity();for(;B&&B.userData.isLayoutLevelObject!==!0;)L.premultiply(B.matrix),B=B.parent;k.matrix.copy(L),P.add(k)}}this.enableMerge&&j.mergeDxfObjects({root:g,layersAndObjects:b});const E=g.convertToThreejsObject();g.clear(),b={};const O={},_=w=>{const M=w.userData.layerName;let P=O[M];!P&&(P=[],O[M]=P),P.push(w)};E.children.forEach(w=>{$.setSharedVariablesOfObject(w),w.userData.isLayoutLevelObject&&w.traverse(M=>{if($.setSharedVariablesOfObject(M),M.userData.isSnapGroup&&(M.visible=j.SHOW_SNAP_OBJECT),M.geometry){const P=M.userData.layerName;this.getLayerVisible(m,P)===!1&&(M.visible=!1,M.userData.layerVisible=!1),_(M)}})});const C=m;C.threejsObject=E,C.layersAndThreejsObjects=O,C.layoutViewportsMap={}};let c=Date.now();this.compareContext={changes:s,isTheFirstFile:!0},V.printMemory("Before loading entities for first dxf"),await l(),S.info("[Dxf] loadEntities for first dxf in "+(Date.now()-c)/1e3+"s"),V.printMemory("After loading entities for first dxf"),this.releaseCachedData(!1),this.releaseDxfData(e),V.printMemory("Before loading entities for second dxf"),c=Date.now(),this.compareContext.isTheFirstFile=!1,await l(),S.info("[Dxf] loadEntities for second dxf in "+(Date.now()-c)/1e3+"s"),this.printStatsInfo();for(const u of Object.values(s))!u.box&&delete s[u.id];this.compareContext.preservedHandles=void 0,this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(i)),V.printMemory("After loading entities for second dxf")}setObjectColorByChange(e,i){const s=a=>{let o=Ue.ENTITY_COLOR_NO_CHANGE;return a.type===Te.Added?o=Ue.ENTITY_COLOR_ADDED:a.type===Te.Removed?o=Ue.ENTITY_COLOR_REMOVED:a.type===Te.Modified&&(o=this.compareContext?.isTheFirstFile?Ue.ENTITY_COLOR_REMOVED:Ue.ENTITY_COLOR_ADDED),o},r=(a,o)=>{a.traverse(l=>{if(l.material){if(l.material instanceof d.LineBasicMaterial)l.material=this.getLineBasicMaterial(o);else if(l.material instanceof d.MeshBasicMaterial)l.material=this.getMeshBasicMaterial(o);else if(l.material instanceof d.PointsMaterial)l.material=this.getPointsMaterial(o);else if(l.material instanceof d.ShaderMaterial){const c=l.material.clone();j.updateMaterialUniforms(c),c.uniforms.u_color.value.set(o),l.material=c}}})},n=s(i);return e.traverse(a=>{i.parentHandles?a.userData&&a.userData.handle&&a.userData.handle===i.handle&&(r(a,n),e=a):r(a,n)}),e}releaseCachedData(e=!0){e&&(this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[]),this.header=void 0,this.blockReferencesCache={},this.blockRecordsCache=void 0,this.blocksCache=void 0,this.entitiesCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.entityHandlesWithRenderOrder={},this.layoutsSnapObjectsMap={},this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0}}releaseEntity(e){e.vertices&&(e.vertices=void 0),e.knotValues&&(e.knotValues=void 0),e.controlPoints&&(e.controlPoints=void 0),e.binaryData&&(e.binaryData=void 0),e.text&&(e.text=void 0),e.extendedData&&(e.extendedData=void 0),e.contextData&&(e.contextData=void 0);const i=e;i.boundaryPaths&&(i.boundaryPaths=[]),i.patternLines&&(i.patternLines=void 0)}releaseDxfData(e){delete e.objects.DICTIONARY,delete e.objects.SORTENTSTABLE,delete e.objects.XRECORD,e.tables&&(delete e.tables.dimStyle,delete e.tables.lineType,delete e.tables.style,delete e.tables.blockRecord),e.entities=[],e.blocks={}}loadEntity(e,i,s,r=!1){if(this.compareContext&&this.compareContext.preservedHandles&&this.compareContext.preservedHandles.has(e.handle)&&ai.includes(e.type)&&(r=!0),!r&&this.compareContext&&this.compareContext.preservedHandles&&!ai.includes(e.type)&&!this.compareContext.preservedHandles.has(e.handle)&&(!s||s&&!this.compareContext.preservedHandles.has(s.handle)))return;if(this.getLayerFrozen(i,e)===!0){const m=e.layer;return!this.statsInfo.ignoredFrozenLayersAndEntityCount[m]&&(this.statsInfo.ignoredFrozenLayersAndEntityCount[m]=0),this.statsInfo.ignoredFrozenLayersAndEntityCount[m]++,void 0}if(e.visible===!1||e.invisible)return!this.statsInfo.invisibleEntities[e.type]&&(this.statsInfo.invisibleEntities[e.type]=0),this.statsInfo.invisibleEntities[e.type]++,void 0;if(this.ignorePaperSpace&&e.inPaperSpace)return!this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]&&(this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]=0),this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]++,void 0;!this.entityThreejsCache&&(this.entityThreejsCache={});const a=Date.now();let o,l=!1;if(!this.compareContext&&this.entityThreejsCache[e.handle])o=this.entityThreejsCache[e.handle].clone(),l=!0;else if(!this.statsInfo.unsupportedEntity[e.handle]){const m=e.isTable;if(e.type==="CIRCLE"||e.type==="ARC")o=this.loadArc(e,i,s);else if(e.type==="LINE"||e.type==="POLYLINE")o=this.loadLine(e,i);else if(e.type==="XLINE")o=this.loadXLine(e);else if(e.type!=="SEQEND"){if(e.type==="RAY")o=this.loadRay(e);else if(e.type==="LWPOLYLINE")o=this.loadLWPolyline(e,i,s);else if(e.type==="3DFACE")o=this.load3DFace(e);else if(e.type==="TEXT")o=this.loadText(e,i,s);else if(e.type==="SOLID")o=this.loadSolid(e,i,s);else if(e.type==="POINT")o=this.loadPoint(e,i,s);else if(e.type==="IMAGE")o=this.loadImage(e,i,s);else if(e.type==="INSERT")o=this.loadInsert(e,i,s,r);else if(e.type==="SPLINE")o=this.loadSpline(e,s);else if(e.type==="MTEXT")m?o=this.loadTableMText(e,i,s):o=this.loadMText(e,i,s);else if(e.type==="ELLIPSE")o=this.loadEllipse(e,i,s);else if(e.type==="DIMENSION")o=this.loadDimension(e,i);else if(e.type!=="REGION")if(e.type==="ATTDEF")o=this.loadAttDef(e,i,s);else if(e.type==="ATTRIB"){if(!s)for(let g=0;g<i.entities.length;g++){const x=i.entities[g];if(e.ownerHandle===x.handle&&(s=x,s.attributesFollow))break}o=this.loadAttrib(e,i,s)}else e.type==="HATCH"?o=this.loadHatch(e,i,s):e.type==="VIEWPORT"?o=this.loadViewport(e,i,s):e.type==="LEADER"?o=this.loadLeader(e,i,s):e.type==="MULTILEADER"?o=this.loadMLeader(e,i,s):e.type==="OLE2FRAME"?o=this.loadOle2frame(e,i):e.type==="ACAD_TABLE"&&(o=this.loadTable(e,i))}o&&(this.entityThreejsCache[e.handle]=o),this.enableReleaseData&&!this.compareContext&&this.releaseEntity(e)}if(o){const m=this.getLayerName(e,i,s);o.userData.handle=e.handle,e.type!=="INSERT"&&e.type!=="DIMENSION"&&o.traverse(g=>{g.geometry&&(g.userData.layerName=m,this.setMaterial(g,e,i,s))}),!l&&(this.nonSnapableTypes.has(e.type)&&o.traverse(g=>{g.layers.disable(Ce)}),this.enableRenderOrder&&(this.entityHandlesWithRenderOrder[e.handle]?o.renderOrder=parseInt(this.entityHandlesWithRenderOrder[e.handle],16)+.1:o.renderOrder=parseInt(e.handle,16)))}const c=e.type,u=e.handle,f=ai.includes(c);if(!f){this.entityTypesAndTimes||(this.entityTypesAndTimes={}),this.entityTypesAndTimes[c]||(this.entityTypesAndTimes[c]={createCount:0,totalTime:0,averageTime:0});const m=this.entityTypesAndTimes[c];m.createCount++,m.totalTime+=Date.now()-a}return o?this.statsInfo.entityTypesAndMeshCount[c]?this.statsInfo.entityTypesAndMeshCount[c]++:this.statsInfo.entityTypesAndMeshCount[c]=1:(this.statsInfo.unsupportedEntityTypes[c]?this.statsInfo.unsupportedEntityTypes[c]++:this.statsInfo.unsupportedEntityTypes[c]=1,f||(this.statsInfo.unsupportedEntity[u]?this.statsInfo.unsupportedEntity[u]++:this.statsInfo.unsupportedEntity[u]=1)),o}loadEllipse(e,i,s){if(!e.majorAxisEndPoint||!e.center||e.axisRatio===void 0||e.startAngle===void 0||e.endAngle===void 0)return;let r=e.startAngle,n=e.endAngle;if(e.extrusionDirection&&e.extrusionDirection.z<0&&(r=Math.PI*2-e.endAngle,n=Math.PI*2-e.startAngle),R.areNumbersEqual(r,n,1e-5))return S.warn("[Dxf] Ellipse entity (handle '%s') contains the same start and end angle, ignored!",e.handle),void 0;let a=n-r;for(;a>Math.PI*2;)a-=Math.PI*2;Math.abs(a)<=1e-5&&(n=R.floorNumber(r+Math.PI*2,5));const o=Math.sqrt(Math.pow(e.majorAxisEndPoint.x,2)+Math.pow(e.majorAxisEndPoint.y,2)),l=o*e.axisRatio,c=Math.atan2(e.majorAxisEndPoint.y,e.majorAxisEndPoint.x),u=new d.EllipseCurve(e.center.x,e.center.y,o,l,r,n,!1,c);let f=1;const m=s;m?.xScale&&m?.yScale&&(f=Math.max(Math.abs(m.xScale),Math.abs(m.yScale)));const g=this.getDivision(r,n,Math.max(o,l)*f),x=u.getPoints(g),y=[],T=x.length;for(let C=0;C<T-1;C++)R.areVector2sEqual(x[C],x[C+1],1e-9)||y.push(x[C]);if(y.push(x[T-1]),y.length<2)return S.warn("[Dxf] Ellipse entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const v=new d.Vector3;let b=!1;this.enableRTC&&(b=U.checkAndRebasePositionsOnRTC(y,v));const E=new d.BufferGeometry().setFromPoints(y),O=new F(N.Line);O.geometry=E,O.material=le;const _=new F(N.Point);return _.geometry=Sr,_.material=Si,_.matrix.setPosition(e.center.x,e.center.y,e.center.z),_.userData.isSnapObject=!0,_.userData.type="CircleCenter",_.layers.set(Ce),O.add(_),b&&(this.setRTCUserData(O),O.matrix.setPosition(v.x,v.y,0)),O.layers.enableAll(),O}loadMText(e,i,s){if(!e.text)return;if(!this.font)return S.info("[Dxf] Font file not set, ignoring text entity."),void 0;const r=this.getTextStyle(i,e),n=oi(e.text,{encoding:this.getTextEncoding(r)}),a=this.getMTextGroup(n,e,r,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(Z,he,ze),e.position&&(Z.x+=e.position.x,Z.y+=e.position.y,o.matrix.compose(Z,he,ze)),We.makeEmpty();const l=F.getBox(o,We),c=l.getSize(z),u=e.width||c.x,f=e.height||c.y,m=e.lineSpaceFactor||1.657,g=e.text;let x=0,y=0;switch(document.createElement("canvas").getContext("2d"),e.attachmentPoint){case 1:x=0,y=0;break;case 2:x-=u/2,y=0;break;case 3:x-=u,y=0;break;case 4:x=0,y+=f/2;break;case 5:x-=u/2,y+=f/2;break;case 6:x-=u,y+=f/2;break;case 7:x=0;const k=g.split("\\P").length-1;k>0?y+=f*(k+1)+f*m*.8*k:y+=f;break;case 8:x-=u/2,y+=f;break;case 9:x-=u,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=f;break;case 4:break;case 5:const I=g.split("\\P");let k=0;I>1&&(k=I-1),k>1?y+=f*(k-1):y-=f/4;break;default:return}o.traverse(I=>{I.geometry&&I.geometry.translate(x,y,0),I.layers.enableAll()});let v=0;if(e.rotation&&(v=e.rotation*Math.PI/180),e.directionVector){const I=e.directionVector,k=new d.Vector3(I.x,I.y,I.z),B=k.clone().cross(Ae),L=Ae.angleTo(k);v=B.z>0?-L:L}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(o),o.matrix.compose(Z,he,ze);const b=e.position?Z.clone().sub(e.position):Z;Fe.makeTranslation(-b.x,-b.y,0),ne.makeRotationZ(v),o.matrix.multiply(Fe),o.matrix.multiply(ne),o.matrix.multiply(Fe.invert()),o.userData||(o.userData={});const E=o.matrix.elements,O=E&&E[12]||0,_=E&&E[13]||0,C=E&&E[14]||0,w=new d.Box3;F.getBox(o,w);const M=new d.Vector3;w.getCenter(M);const P=new d.Vector3;w.getSize(P),o.userData.renderArea={position:{x:O,y:_,z:C},bbox:{min:{x:w.min.x,y:w.min.y,z:w.min.z},max:{x:w.max.x,y:w.max.y,z:w.max.z},center:{x:M.x,y:M.y,z:M.z},width:P.x,height:P.y,depth:P.z},textSize:{width:u,height:f},rotation:v,attachmentPoint:e.attachmentPoint||0,drawingDirection:e.drawingDirection||0};const A=this;return o.userData.textContent=e.text||"",o.userData.cleanText=A.cleanMTextContent?A.cleanMTextContent(e.text):e.text,o.userData.dxfType="MTEXT",o.userData.isMText=!0,o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",o.traverse(I=>{I.geometry&&(I.userData.textContent=e.text||"",I.userData.dxfType="MTEXT",I.userData.layer=e.layer||"0",I.userData.handle=e.handle||"")}),o.userData.entityId=e.entityId||e.handle,o}loadTableMText(e,i,s){if(!e.text)return;if(!this.font)return S.info("[Dxf] Font file not set, ignoring text entity."),void 0;const r=this.getTextStyle(i,e),n=oi(e.text,{encoding:this.getTextEncoding(r)}),a=this.getMTextGroup(n,e,r,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(Z,he,ze),e.position&&(Z.x+=e.position.x,Z.y+=e.position.y,o.matrix.compose(Z,he,ze)),We.makeEmpty();const l=F.getBox(o,We),c=l.getSize(z),u=e.width||c.x,f=e.height||c.y,m=e.lineSpaceFactor||1.657,g=e.text;let x=0,y=0;switch(e.attachmentPoint){case 1:x=0,y=0;break;case 2:x-=u/2,y=0;break;case 3:x-=u,y=0;break;case 4:x=0,y+=f/2;break;case 5:x-=u/2,y+=f/2;break;case 6:x-=u,y+=f/2;break;case 7:x=0;const E=g.split("\\P").length-1;E>0?y+=f*(E+1)+f*m*.8*E:y+=f;break;case 8:x-=u/2,y+=f;break;case 9:x-=u,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=f;break;case 4:break;case 5:break;default:return}o.traverse(b=>{b.geometry&&b.geometry.translate(x,y,0),b.layers.enableAll()});let T=0;if(e.rotation&&(T=e.rotation*Math.PI/180),e.directionVector){const b=e.directionVector,E=new d.Vector3(b.x,b.y,b.z),O=E.clone().cross(Ae),_=Ae.angleTo(E);T=O.z>0?-_:_}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(o),o.matrix.compose(Z,he,ze);const v=e.position?Z.clone().sub(e.position):Z;return Fe.makeTranslation(-v.x,-v.y,0),ne.makeRotationZ(T),o.matrix.multiply(Fe),o.matrix.multiply(ne),o.matrix.multiply(Fe.invert()),o}getMTextGroup(e,i,s,r,n,a=0,o=0,l=[]){if(e.length===0)return;let c=i.height||i.contextData&&i.contextData.textHeight||0;if(i.textStyle){if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const O=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[O]&&(this.statsInfo.unsupportedTextStyles[O]=0),this.statsInfo.unsupportedTextStyles[O]++}c=c||s.textHeight}let u="Left";i.width&&i.attachmentPoint&&([1,4,7].includes(i.attachmentPoint)?u="Left":[2,5,8].includes(i.attachmentPoint)?u="Center":[3,6,9].includes(i.attachmentPoint)&&(u="Right"));const f=i.width||0,m=new F;let g,x=s.fontFile,y=1,T=1,v=256,b=c*.8,E=b+c;for(let O=0;O<e.length;O++){const _=e[O];if(typeof _=="string"){const C=[],w=A=>{let I;if(A.forEach((k,B)=>{!k.boundingBox&&k.computeBoundingBox(),B===0?I=k.boundingBox:I.union(k.boundingBox)}),I){const k=I.getSize(z);switch(u){case"Left":break;case"Center":A.forEach(B=>B.translate((f-k.x)/2,0,0));break;case"Right":A.forEach(B=>B.translate(f-k.x,0,0));break}}C.push(...A)};let M;for(let A=0;A<_.length;A++){const I=_[A];if(I===`
794
- `){a=0,o-=E,l.length>0&&w(l),l=[];continue}if(b=c*.8,E=b+c,M=this.font?.getCharShape(I,x,c),s.bigFontFile&&!M&&(M=this.font?.getCharShape(I,s.bigFontFile,c)),!M&&(M=this.font?.getCharShape(I,"",c)),!M&&(M=this.font?.getNotFoundTextShape(c)),!M){a+=c+T*(c/3.5);continue}a>(f||1/0)&&(l.length>0&&w(l),a=0,o-=E,l=[]),M.translate(a,o,0),M.scale(y,1,1),M.boundingBox||M.computeBoundingBox(),_.T&&(T=_.T);const k=Vo(I,M,c,T,x);a+=k,l.push(M)}l.length>0&&(w(l),l=[]);const P=new F;if(C.length>0){!g&&(g=i.colorIndex),v!==void 0&&v!==256?(i.color=Nt(v),i.colorIndex=v):i.colorIndex=g;const A=this.getColor(i,r,n),I=C.filter(B=>B instanceof d.ExtrudeGeometry),k=C.filter(B=>!(B instanceof d.ExtrudeGeometry));if(I.length>0){const B=new F(N.Mesh);B.geometry=xe.mergeGeometries(I),B.material=this.getMeshBasicMaterial(A),P.add(B)}if(k.length>0){const B=new F(N.LineSegment);B.geometry=xe.mergeGeometries(k),B.material=this.getLineBasicMaterial(A),P.add(B)}}P.matrix.makeTranslation(0,-c,0),m.add(P),y=1,T=1,v=256}else if(Array.isArray(_)){const C=this.getMTextGroup(_,i,s,r,n,a,o,l);C&&(m.add(C.object),a=C.hOffset,o=C.vOffset)}else typeof _=="object"&&(_.f&&(x=_.f,x&&x.includes(".shx")&&S.info("[Dxf] Doesn't support custom fonts: "+x)),_.C&&(v=_.C),_.W&&(_.W[1]==="x"?y=_.W[0]*i.width:y=_.W[0]),_.H&&(_.H[1]==="x"?c=_.H[0]*i.height:c=_.H[0]),_.T&&(T=_.T))}if(m.children.length!==0)return Qe.merge(m,!1),g&&(i.colorIndex=g),m.children.length===1?{object:m.children[0],hOffset:a,vOffset:o}:{object:m,hOffset:a,vOffset:o}}mtextContentAndFormattingToTextAndStyle(e,i){const s={horizontalAlignment:"",textHeight:i.height||i.contextData&&i.contextData.textHeight},r={};let n=1;const a=[];for(let o=0;o<e.length;o++){const l=e[o];if(typeof l=="string"){if(l.startsWith("\\pxq")&&l.endsWith(";"))l.indexOf("c")!==-1?s.horizontalAlignment="center":l.indexOf("l")!==-1?s.horizontalAlignment="left":l.indexOf("r")!==-1?s.horizontalAlignment="right":l.indexOf("j")!==-1&&(s.horizontalAlignment="justify");else if(!l.startsWith("pi")){if(!l.startsWith("pxt")){if(!l.startsWith("pt")){const c=this.getTextLineNum(l);a.push({font:r.f,colorIndex:r.C,text:l,lineNum:n}),n+=c}}}}else if(Array.isArray(l)){const c=this.mtextContentAndFormattingToTextAndStyle(l,i);c.text.forEach(u=>{a.push(u)}),n=c.lineLength}else if(typeof l=="object")if(l.S&&l.S.length===3){const c=l.S[0]+"/"+l.S[2],u=this.getTextLineNum(c);a.push({text:l.S[0]+"/"+l.S[2],lineNum:n}),n+=u}else l.C!==void 0?r.C=l.C:l.W!==void 0?r.W=l.W:l.H!==void 0?r.H=l.H:l.f!==void 0&&(r.f=l.f)}return{text:a,lineLength:n,style:s}}getTextLineNum(e){const i=e.match(new RegExp("\\n","g"));return i?i.length:0}load3DFace(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=e.vertices.map(o=>new d.Vector3(o.x,o.y,o.z));if(i.length===0)return;!R.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new d.Vector3;let r=!1;this.enableRTC&&(r=U.checkAndRebasePositionsOnRTC(i,s));const n=new d.BufferGeometry().setFromPoints(i),a=new F(N.Line);return a.geometry=n,a.material=le,r&&(this.setRTCUserData(a),a.matrix.setPosition(s.x,s.y,0)),a.layers.enableAll(),a}loadSpline(e,i){if(!e.controlPoints||!e.degreeOfSplineCurve||!e.knotValues)return;if(e.controlPoints.length<e.degreeOfSplineCurve+1)return S.warn("[Dxf] Spline entity (handle '%s') has degree (%s) >= point count (%s), ignored!",e.handle,e.degreeOfSplineCurve,e.controlPoints.length),void 0;let s=1/0,r=1/0,n=-1/0,a=-1/0;for(const v of e.controlPoints)v.x<s&&(s=v.x),v.y<r&&(r=v.y),v.x>n&&(n=v.x),v.y>a&&(a=v.y);let o=1;const l=i;l?.xScale&&l?.yScale&&(o=Math.max(Math.abs(l.xScale),Math.abs(l.yScale)));const c=Math.max(n-s,a-r),u=this.getBSplineInterpolationsPerSplineSegment(e.controlPoints.length,c*o),f=kr(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,u),m=new d.Vector3;let g=!1;this.enableRTC&&(g=U.checkAndRebasePositionsOnRTC(f,m));const x=U.getAdjacentNonRepeatPoints(f);if(x.length<2)return S.warn("[Dxf] Spline entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const y=new d.BufferGeometry().setFromPoints(x),T=new F(N.Line);return T.geometry=y,T.material=le,g&&(this.setRTCUserData(T),T.matrix.setPosition(m.x,m.y,0)),T.layers.enableAll(),T}loadXLine(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=V.arrayOrObjectToVector3(e.directionVector),s=new d.Vector3(e.vertices[0].x,e.vertices[0].y,0),r=[];if(r.push(i.clone().multiplyScalar(-1e6).add(s)),r.push(i.clone().multiplyScalar(1e6).add(s)),r.length===0)return;const n=new d.Vector3;let a=!1;this.enableRTC&&(a=U.checkAndRebasePositionsOnRTC(r,n));const o=new d.BufferGeometry().setFromPoints(r),l=new F(N.Line);return l.geometry=o,l.material=le,a&&(this.setRTCUserData(l),l.matrix.setPosition(n.x,n.y,0)),l.layers.enableAll(),l}loadRay(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=V.arrayOrObjectToVector3(e.directionVector),s=e.vertices.map(l=>new d.Vector3(l.x,l.y,0));if(s.push(i.multiplyScalar(1e6).add(s[0])),s.length===0)return;const r=new d.Vector3;let n=!1;this.enableRTC&&(n=U.checkAndRebasePositionsOnRTC(s,r));const a=new d.BufferGeometry().setFromPoints(s),o=new F(N.Line);return o.geometry=a,o.material=le,n&&(this.setRTCUserData(o),o.matrix.setPosition(r.x,r.y,0)),o.layers.enableAll(),o}loadLine(e,i){if(!e.vertices||e.vertices.length===0){S.warn("[Dxf] Entity is missing vertices:",e.handle);return}let s=[];if(e.isPolyfaceMesh)s=nh(e.vertices);else{const c=us(e.vertices,e.shape);e.shape&&c.length>0&&c.push(c[0]),c.length>0&&(s=[c])}if(s.length===0)return;const r=[];for(let c=0;c<s.length;){const[u,f]=s[c];R.areVector3sEqual(u,f)&&s[c].length<=2?(r.push(u.clone()),s.splice(c,1)):c++}const n=new d.Vector3;let a=!1,o=0;s.forEach(c=>{c.forEach(u=>n.add(u)),o+=c.length}),o>0&&(n.divideScalar(o),a=this.enableRTC&&U.shouldRebasePositionOnRTC(n));let l=null;if(s.length>0){let c=function(v){return Array.isArray(v.pattern)&&v.pattern.length>0};const u=[],f=[];let m=0;s.forEach(v=>{v.forEach(b=>{a?u.push(new d.Vector3(b.x-n.x,b.y-n.y,b.z-n.z)):u.push(b.clone())});for(let b=1;b<v.length;b++)f.push(m+b-1,m+b);m+=v.length});const g=this.getLineType(e,i),x=i.tables?.lineType?.lineTypes?.[g],y=new d.BufferGeometry().setFromPoints(u);let T=le;if(x&&c(x)){let v=function(_){const C=_.attributes.position,w=C.count,M=new Float32Array(w);for(let P=0;P<w;P+=2){const A=P*3,I=(P+1)*3,k=C.array[I]-C.array[A],B=C.array[I+1]-C.array[A+1],L=C.array[I+2]-C.array[A+2],q=Math.sqrt(k*k+B*B+L*L);M[P]=P===0?0:M[P-1],M[P+1]=M[P]+q}_.setAttribute("lineDistance",new d.Float32BufferAttribute(M,1))};const b=x.pattern?.[0]||.5,E=x.pattern?.[1]||.5,O=.1;T=new d.LineDashedMaterial({color:le.color,linewidth:le.linewidth||1,dashSize:b*O,gapSize:E*O,scale:O}),v(y)}else y.setIndex(f);l=new F(N.LineSegment),l.geometry=y,l.material=T}if(r.length>0){a&&U.checkAndRebasePositionsOnRTC(r,n);const c=new d.BufferGeometry().setFromPoints(r),u=new F(N.Point);u.geometry=c,u.material=Si,l?console.warn("Line has both segments and points – consider using a Group"):l=u}if(l)return a&&(this.setRTCUserData(l),l.matrix.setPosition(n.x,n.y,n.z)),l.layers.enableAll(),l}loadLWPolyline(e,i,s){if(!e.vertices||e.vertices.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const r=[...e.vertices];if(e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0){z.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const g=j.getOcsMatrix(z).invert(),x=e.elevation!==void 0?e.elevation:0;r.forEach(y=>{z.set(y.x,y.y,x).applyMatrix4(g),y.x=z.x,y.y=z.y})}let n=us(r,e.shape);if(e.shape&&n.length>0&&!R.areVector3sEqual(n[0],n[n.length-1])&&n.push(n[0]),n.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}let a=new F;const o=e.extendedData;if(o?.outlines){const g=o.outlines,x=[];g.forEach(v=>{const b=new d.Shape;v.forEach((E,O)=>{O===0?b.moveTo(E[0],E[1]):b.lineTo(E[0],E[1])}),b.closePath(),x.push(new d.ShapeGeometry(b))});const y=xe.mergeGeometries(x),T=new F(N.Mesh);T.geometry=y,T.material=_t,T.layers.enableAll(),T.layers.disable(Ce),a.add(T)}let l=!1;const c=new d.Vector3;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(n,c));const u=U.getAdjacentNonRepeatPoints(n);if(u.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const f=e.constantWidth;if(this.enablePlineWidth){const g=r.some(x=>x.startWidth!==void 0||x.endWidth!==void 0);if(g||f!==void 0&&f>0){let x;const y=i.tables?.lineType?.lineTypes,T=this.getLineType(e,i,s),v=y?.[T];if(!v||!v.pattern||v.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,g?x=this.createTaperedPolylineGeometry(r):x=U.convertWidthLineToMeshGeometry(u,f),!x)S.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const b=new F(N.Mesh);b.geometry=x,b.material=_t,b.layers.enableAll(),b.layers.disable(Ce),a.add(b);const E=$.createOutline(x,le,b.matrix),O=new F(N.LineSegment);O.geometry=E.geometry,O.material=E.material,O.matrix=E.matrix,O.layers.enableAll(),O.layers.disable(Ce),a.add(O)}}}const m=new F(N.Line);return m.geometry=new d.BufferGeometry().setFromPoints(u),m.material=le,m.layers.enableAll(),a.children.length>0?a.add(m):a=m,l&&(this.setRTCUserData(a),a.matrix.setPosition(c)),a}createTaperedPolylineGeometry(e){if(!e||e.length<2)return null;const i=[],s=[],r=[],n=[];for(let l=0;l<e.length-1;l++){const c=e[l],u=e[l+1],f=u.x-c.x,m=u.y-c.y,g=Math.hypot(f,m);if(g===0)continue;const x=-m/g,y=f/g,T=l===0?c.startWidth:c.endWidth,v=u.startWidth,b=T/2,E=v/2;c.x+x*b,c.y+y*b,c.x-x*b,c.y-y*b;const O={x:u.x+x*E,y:u.y+y*E},_={x:u.x-x*E,y:u.y-y*E};r.push(O),n.push(_)}const a=r.length;for(let l=0;l<a;l++)i.push(r[l].x,r[l].y,0),i.push(n[l].x,n[l].y,0);for(let l=0;l<a-1;l++){const c=l*2;s.push(c,c+1,c+2),s.push(c+1,c+3,c+2)}const o=new d.BufferGeometry;return o.setAttribute("position",new d.Float32BufferAttribute(i,3)),o.setIndex(s),o}loadMLeader(e,i,s){const r=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i),n=e.contextData?.defaultTextContents;if(!n)return;const a=new F,o=oi(n),l=this.getTextStyle(i,e),c=this.getMTextGroup(o,e,l,i,s),u=c&&c.object;if(u){u.matrix.decompose(Z,he,ze),e.contextData?.textLocation&&(Z.x+=e.contextData.textLocation.x,Z.y+=e.contextData.textLocation.y,u.matrix.compose(Z,he,ze)),We.makeEmpty();const f=F.getBox(u,We),m=f.getSize(z),g=m.x,x=m.y;let y=0,T=0;switch(e.contextData?.textAttachment){case 1:y=0,T=0;break;case 2:y-=g/2,T=0;break;case 3:y-=g,T=0;break;case 4:y=0,T+=x/2;break;case 5:y-=g/2,T+=x/2;break;case 6:y-=g,T+=x/2;break;case 7:y=0,T+=x;break;case 8:y-=g/2,T+=x;break;case 9:y-=g,T+=x;break;default:return}u.traverse(E=>{E.geometry&&E.geometry.translate(y,T,0)});let v=0;if(e.contextData?.textRotation&&(v=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const E=e.contextData.textDirection,O=new d.Vector3(E.x,E.y,E.z),_=O.clone().cross(Ae),C=Ae.angleTo(O);v+=_.z>0?-C:C}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(u),u.matrix.compose(Z,he,ze),e.contextData?.textLocation?z.set(e.contextData.textLocation.x,e.contextData.textLocation.y,0):z.set(0,0,0);const b=Z.clone().sub(z);Fe.makeTranslation(-b.x,-b.y,0),ne.makeRotationZ(v),u.matrix.multiply(Fe),u.matrix.multiply(ne),u.matrix.multiply(Fe.invert()),u.renderOrder=ge.Text,a.add(u)}if(e.leaderLineType!==0){const f=[],m=e.contextData?.leaders[0];if(!m)return a;const g=m.lastLeaderLinePoint;if(e.enableDogLeg){const E=new d.Vector3(g.x,g.y,g.z),O=m.doglegLength,_=new d.Vector3(m.doglegVector.x,m.doglegVector.y,m.doglegVector.z),C=_.multiplyScalar(O),w=E.clone().add(C);f.push(w,E)}const x=e.contextData?.leaders[0].leaderLines||[];for(let E=0;E<x.length;E++){const O=x[E].vertices[0],_=O.reverse().map(k=>new d.Vector3(k.x,k.y,k.z));let C=new d.Vector3(g.x,g.y,g.z);for(let k=0;k<_.length;k++)f.push(C,_[k]),C=_[k];const w=z.subVectors(f[0],f[1]).length(),M=e.arrowHeadSize||r.DIMASZ||2.5,P=e.arrowHeadScale||r.DIMSCALE||1,A=M*P;e.leaderLineType;let I="";if(e.arrowHeadId?I=e.arrowHeadId:r&&r.DIMLDRBLK&&(I=r.DIMLDRBLK),I){const k=this.getBlockByHandle(i.blocks,I);if(k&&k.entities)for(let B=0;B<k.entities.length;B++){const L=this.loadEntity(k.entities[B],i,e);if(L){const q=new d.Vector3(f[f.length-1].x,f[f.length-1].y,f[f.length-1].z),me=new d.Vector3(f[f.length-2].x,f[f.length-2].y,f[f.length-2].z),ue=Math.atan2(q.y-me.y,q.x-me.x);z.copy(q),Z.setScalar(A),he.setFromAxisAngle(Et,ue),L.matrix.compose(z,he,Z),a.add(L)}}}else this.loadDefaultLeadArrow(f[f.length-2],f[f.length-1],w/2e3,f)}const y=new d.Vector3;let T=!1;this.enableRTC&&(T=U.checkAndRebasePositionsOnRTC(f,y));const v=new d.BufferGeometry().setFromPoints(f),b=new F(N.LineSegment);b.geometry=v,b.material=le,b.renderOrder=ge.Line,T&&(this.setRTCUserData(b),b.matrix.setPosition(y.x,y.y,0)),a.add(b)}else return u?.traverse(f=>{f.layers.enableAll()}),u;return Qe.merge(a,!1),a.traverse(f=>{f.layers.enableAll()}),a.children.length===1?a.children[0]:a}loadLeader(e,i,s){const r=[];if(!e.vertices)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;if(e.vertices.length<2)return S.warn("leader's vertices number must be greater than 2"),void 0;const n=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i);let a=e.vertices;if(e.pathType===1&&(a=new d.SplineCurve(e.vertices).getPoints(50)),e.textWidth){const T=e.textWidth,v=new d.Vector3(a[a.length-1].x,a[a.length-1].y,a[a.length-1].z);if(e.direction===0){const b=new d.Vector3(1,0,0).multiplyScalar(T);a.push(b.add(v))}else{const b=new d.Vector3(-1,0,0).multiplyScalar(T);a.push(b.add(v))}}for(let T=0;T<a.length-1;T++){const v=a[T],b=a[T+1];r.push(v,b)}const o=z.subVectors(r[0],r[1]).setZ(0).length(),l=e.arrowHeight||n.DIMASZ||2.5,c=e.arrowHeadScale||n.DIMSCALE||1,u=l*c,f=new F;if(e.arrowFlag===1){let T="";e.arrowHeadBlockHandle?T=e.arrowHeadBlockHandle:n&&n.DIMLDRBLK&&(T=n.DIMLDRBLK);const v=this.getBlockByHandle(i.blocks,T);if(v&&v.entities){n&&(e.colorIndex=n.DIMCLRD||256,e.color=Nt(e.colorIndex));for(let b=0;b<v.entities.length;b++){const E=this.loadEntity(v.entities[b],i,e);if(E){const O=new d.Vector3(r[0].x,r[0].y,r[0].z),_=new d.Vector3(r[1].x,r[1].y,r[1].z),C=Math.atan2(O.y-_.y,O.x-_.x);z.copy(O),Z.setScalar(u),he.setFromAxisAngle(Et,C),E.matrix.compose(z,he,Z),f.add(E)}}}else this.loadDefaultLeadArrow(r[1],r[0],u/o/2,r)}if(r.length===0)return;const m=new d.Vector3;let g=!1;this.enableRTC&&(g=U.checkAndRebasePositionsOnRTC(r,m));const x=new d.BufferGeometry().setFromPoints(r),y=new F(N.Line);return y.geometry=x,y.material=le,y.renderOrder=ge.Line,g&&(this.setRTCUserData(y),y.matrix.setPosition(m.x,m.y,0)),f.children.length>0?(f.add(y),Qe.merge(f,!1),f.traverse(T=>{T.layers.enableAll()}),f.children.length===1?f.children[0]:f):(y.layers.enableAll(),y)}getTableTextOffset(e,i,s){const r=new d.Vector3;switch(e){case 1:break;case 2:r.setX(i/2);break;case 3:r.setX(i);break;case 4:r.setY(-s/2);break;case 5:r.set(i/2,-s/2,0);break;case 6:r.set(i,-s/2,0);break;case 7:r.setY(-s);break;case 8:r.set(i/2,-s,0);break;case 9:r.set(i,-s,0);break}return r}loadTable(e,i,s){if(!e.startPoint){S.warn("[Dxf] Entity is missing startPoint:",e.handle);return}if(e.cells.length===0){S.warn("[Dxf] Entity is missing cells:",e.handle);return}if(e.rowHeightArr.length===0){S.warn("[Dxf] Entity is missing rowHeightArr:",e.handle);return}if(e.columnWidthArr.length===0){S.warn("[Dxf] Entity is missing columnWidthArr:",e.handle);return}const r=new F,{cells:n,rowCount:a,columnCount:o,rowHeightArr:l,columnWidthArr:c}=e,u=[];let f=0;for(let y=0;y<a;y++){u[y]=[];for(let T=0;T<o;T++)u[y][T]=f<n.length?n[f++]:null}for(let y=0;y<a;y++)for(let T=0;T<o;T++){const v=u[y][T];if(!v||v.mergedValue!==0)continue;let b=1,E=1;for(;y+b<a&&u[y+b][T]&&u[y+b][T].mergedValue===1;)b++;for(;T+E<o&&u[y][T+E]&&u[y][T+E].mergedValue===1;)E++;v.rowSpan=b,v.colSpan=E}const m=[0];for(let y=0;y<a;y++)m.push(m[y]-l[y]);const g=[0];for(let y=0;y<o;y++)g.push(g[y]+c[y]);const x=[];for(let y=0;y<=a;y++){let T=g[0],v=!1;for(let b=0;b<o;b++){y>0&&u[y-1][b],y<a&&u[y][b];let E=!0;if(y===0||y===a)E=!0;else{const O=this._getMergeOwner(u,y-1,b,a,o),_=this._getMergeOwner(u,y,b,a,o);E=O!==_}E?v||(v=!0,T=g[b]):v&&(x.push(new d.Vector3(T,m[y],0),new d.Vector3(g[b],m[y],0)),v=!1)}v&&x.push(new d.Vector3(T,m[y],0),new d.Vector3(g[o],m[y],0))}for(let y=0;y<=o;y++){let T=m[0],v=!1;for(let b=0;b<a;b++){y>0&&u[b][y-1],y<o&&u[b][y];let E=!0;if(y===0||y===o)E=!0;else{const O=this._getMergeOwner(u,b,y-1,a,o),_=this._getMergeOwner(u,b,y,a,o);E=O!==_}E?v||(v=!0,T=m[b]):v&&(x.push(new d.Vector3(g[y],T,0),new d.Vector3(g[y],m[b],0)),v=!1)}v&&x.push(new d.Vector3(g[y],T,0),new d.Vector3(g[y],m[a],0))}if(x.length>0){const y=new d.BufferGeometry().setFromPoints(x),T=new F(N.LineSegment);T.geometry=y,T.material=le,T.layers.enableAll(),r.add(T)}for(let y=0;y<a;y++)for(let T=0;T<o;T++){const v=u[y][T];if(!v||v.mergedValue!==0)continue;const b=g[T],E=m[y];let O=0;for(let M=0;M<(v.colSpan||1);M++)O+=c[T+M];let _=0;for(let M=0;M<(v.rowSpan||1);M++)_+=l[y+M];v.colorIndex=e.colorIndex,v.height=v.textHeight||2.5;const C=this.getTableTextOffset(v.attachmentPoint||1,O,_);z.set(b,E,0),z.add(C),v.position=z.clone();const w=this.loadMText(v,i,s);w&&r.add(w)}if(e.blockRecordHandle){const y=this.getBlockByHandle(i.blocks,e.blockRecordHandle);if(y&&y.entities)for(const T of y.entities){T.isTable=!0;const v=this.loadEntity(T,i,e);v&&r.add(v)}}return r.matrix.decompose(z,he,ze),z.x+=e.startPoint.x,z.y+=e.startPoint.y,r.matrix.compose(z,he,ze),r}_getMergeOwner(e,i,s,r,n){let a=i,o=s;for(;a>=0&&e[a][o]&&e[a][o].mergedValue===1;){if(a>0&&e[a-1][o]&&e[a-1][o].mergedValue!==1){a--;break}if(o>0&&e[a][o-1]&&e[a][o-1].mergedValue!==1){o--;break}if(a>0)a--;else if(o>0)o--;else break}return e[a]?.[o]||null}loadDefaultLeadArrow(e,i,s,r){const n=s*(e.x-i.x),a=s*(e.y-i.y),o=a,l=-n,c=new d.Vector3(i.x+n+o/6,i.y+a+l/6,0),u=new d.Vector3(i.x+n-o/6,i.y+a-l/6,0);r.push(i,c),r.push(i,u),r.push(c,u)}getBlockByHandle(e,i){if(!this.blocksCache){this.blocksCache={};for(const s in e){const r=e[s];!this.blocksCache[r.ownerHandle]&&(this.blocksCache[r.ownerHandle]=r)}}return this.blocksCache[i]}static updateMaterialUniforms(e){e instanceof d.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=j.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=j.ViewportScaleUniform))}static transformAngleByOcsMatrix(e,i){const s=z.set(Math.cos(i)*1,Math.sin(i)*1,0),r=s.applyMatrix4(e);return Math.atan2(r.y,r.x)}static getArcAnglesByOcsMatrix(e,i,s){let r=R.getArcAngleSpanInRadian(i,s);const n=j.transformAngleByOcsMatrix(e,i),a=j.transformAngleByOcsMatrix(e,s);let o;if(R.areNumbersClose(r,Math.PI)){r=1;const l=j.transformAngleByOcsMatrix(e,i+r);o=R.getArcAngleSpanInRadian(n,l)}else{if(R.areNumbersClose(r,Math.PI*2))return[n,n+Math.PI*2];o=R.getArcAngleSpanInRadian(n,a)}return R.areNumbersClose(r,o,1e-5)?[n,a]:[a,n]}loadArc(e,i,s){if(!e.radius||e.radius<.001)return S.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is undefined, ignored!"),void 0;if(!e.radius||e.radius<.001)return S.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is too small, ignored!"),void 0;const r=new d.Vector3(0,0,1);e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0&&r.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const n=j.getOcsMatrix(r);let a,o;if(e.type==="CIRCLE")a=e.startAngle||0,o=a+2*Math.PI;else{if(e.startAngle==null||e.endAngle==null||(a=e.startAngle,o=e.endAngle,R.areNumbersEqual(a,o,1e-6)))return;if(!R.areNumbersClose(R.getArcAngleSpanInRadian(a,o),Math.PI*2)){const _=j.getArcAnglesByOcsMatrix(n,a,o);a=_[0],o=_[1]}}const l=new d.ArcCurve(0,0,e.radius,a,o,this.angBase!==0);let c=1;const u=s;u?.xScale&&u?.yScale&&(c=Math.max(Math.abs(u.xScale),Math.abs(u.yScale)));const f=this.getDivision(a,o,e.radius*c),m=l.getPoints(f),g=new d.Vector3;let x=!1;this.enableRTC&&(x=U.checkAndRebasePositionsOnRTC(m,g));const y=new d.BufferGeometry().setFromPoints(m),T=new F(N.Line);T.geometry=y,T.material=le;const v=new d.Vector3;e.center&&(v.x=e.center.x,v.y=e.center.y);const b=new d.Vector3(e.center?.x,e.center?.y,e.center?.z).applyMatrix4(n.invert());v.x=b.x,v.y=b.y;const E=v,O=new F(N.Point);return O.geometry=Sr,O.material=Si,O.userData.handle=e.handle,O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(Ce),T.add(O),x?(this.setRTCUserData(T),E.x+=g.x,E.y+=g.y):U.shouldRebasePositionOnRTC(E)&&this.setRTCUserData(T),T.matrix.setPosition(E),T.layers.enableAll(),T}addTriangleFacingCamera(e,i,s,r){const n=new d.Vector3,a=new d.Vector3;n.subVectors(s,i),a.subVectors(r,i),n.cross(a);const o=new d.Vector3(i.x,i.y,i.z),l=new d.Vector3(s.x,s.y,s.z),c=new d.Vector3(r.x,r.y,r.z);n.z<0?e.push(c,l,o):e.push(o,l,c)}loadSolid(e,i,s){const r=e.points;if(!r||r.length<4)return;if(e.extrusionDirection&&e.extrusionDirection.z){z.set(0,0,e.extrusionDirection.z);const f=j.getOcsMatrix(z).invert();r.forEach(m=>{const g=z.set(m.x,m.y,0).applyMatrix4(f);m.x=g.x,m.y=g.y})}const n=[],a=[];this.addTriangleFacingCamera(n,r[0],r[1],r[2]),a.push(0,1,2),this.addTriangleFacingCamera(n,r[1],r[2],r[3]),a.push(3,4,5);const o=new d.Vector3;let l=!1;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(n,o));const c=new d.BufferGeometry().setFromPoints(n);c.setIndex(a);const u=new F(N.Mesh);return u.geometry=c,u.material=_t,l&&(this.setRTCUserData(u),u.matrix.setPosition(o.x,o.y,0)),u.layers.enableAll(),u}getTextStyle(e,i){const s=e.tables?.style?.styles;return s?s[i.textStyle]||s.STANDARD||s.Standard||{}:{}}getDefaultDimensionStyle(e){return e.tables.dimStyle.dimStyles.STANDARD||e.tables.dimStyle.dimStyles.Standard||{}}getTextEncoding(e){return e?.bigFontFile&&e.bigFontFile.toUpperCase().startsWith("GB")?"gbk":"utf8"}getTextMesh(e,i,s,r){if(!e)return;const n=s?.styleName||"";if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const c=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[c]&&(this.statsInfo.unsupportedTextStyles[c]=0),this.statsInfo.unsupportedTextStyles[c]++}let a=.8;const o={_TCH_DIM:1.45,ROMANS:1};n&&o[n]&&(a=o[n]),r.xScale&&(a*=r.xScale),a>1&&n&&(a*=s?.xScale||1,i=i||s?.textHeight||0),i===0&&(n?i=1:i=.2);const l=this.createTextMeshByText(e,s,i,0,i/12,a);return l.traverse(c=>{c.geometry&&c.geometry.scale(a,1,1)}),l}createTextMeshByText(e,i,s=12,r=0,n=0,a=1,o=1/0,l=0){const c=new F,u=[];let f=0,m=0;i?.xScale;const g=r+s,x=i?.fontFile||"",y=typeof x=="string"&&x.toLowerCase().endsWith(".shx"),T=y?s*.06:s*.04,v=[];for(let O=0;O<e.length;O++){const _=e[O];_!==" "&&_!==`
791
+ `;return new d.ShaderMaterial({uniforms:r,vertexShader:n,fragmentShader:a,clipping:!0})}var De=(h=>(h.Unitless="Unitless",h.Inches="Inches",h.Feet="Feet",h.Millimeters="Millimeters",h.Centimeters="Centimeters",h.Meters="Meters",h))(De||{});const Ps=h=>h==="Unitless"?1:h==="Inches"?.0254:h==="Feet"?.3048:h==="Millimeters"?.001:h==="Centimeters"?.01:(h==="Meters"||console.warn("[Units] Unsupported unit '"+h+"', will return 1 for unit scale."),1),Yo=(h,t)=>Ps(h)/Ps(t);class wn{constructor(){p(this,"pointer");p(this,"eof");p(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class vi{constructor(t,e){p(this,"endian");p(this,"position");p(this,"data");p(this,"decoder");this.endian=e&&e==="big"?"big":"little",this.position=0,this.data=new DataView(t)}readAsciiString(t){if(this.data.byteLength<this.position+t)throw"range error";let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(this.data.getInt8(this.position+i));return this.position+=t,e}readUtf8String(t){const e=this.readBytes(t);return this.decoder||(this.decoder=new TextDecoder("utf-8")),this.decoder.decode(e)}readBytes(t=1){if(this.data.byteLength<this.position+t)throw"range error";const e=new Uint8Array(t);for(let i=0;i<t;i++)e[i]=this.data.getUint8(this.position+i);return this.position+=t,e}readUint8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getUint8(this.position);return this.position+=1,t}readInt8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getInt8(this.position);return this.position+=1,t}readUint16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getUint16(this.position,this.endian==="little");return this.position+=2,t}readInt16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getInt16(this.position,this.endian==="little");return this.position+=2,t}readUint32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getUint32(this.position,this.endian==="little");return this.position+=4,t}readInt32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getInt32(this.position,this.endian==="little");return this.position+=4,t}readFloat32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getFloat32(this.position,this.endian==="little");return this.position+=4,t}readFloat64(){if(this.data.byteLength<this.position+8)throw"range error";const t=this.data.getFloat64(this.position,this.endian==="little");return this.position+=8,t}readInt64(){if(this.data.byteLength<this.position+8)throw"range error";const t=wi.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,wi.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=wi.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,wi.toNumber(t)}getPosition(){return this.position}setPosition(t){if(this.data.byteLength<t)throw"range error";this.position=t}isEnd(){return this.position===this.data.byteLength-1}}const hr=1e3;class Xo extends wn{constructor(e){super();p(this,"reader");p(this,"decoder");p(this,"int8Array");p(this,"caches");this.int8Array=new Int8Array(hr),this.caches=new Map,this.reader=new vi(e);const i=this.reader.readBytes(22);let s="";for(let r=0;r<18;r++)s+=String.fromCharCode(i[r]);if(s!=="AutoCAD Binary DXF")throw new Error("Invalid DXF file")}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file.");const e={code:this.reader.readInt16()};return e.value=this.parseGroupValue(e.code),e.code===0&&e.value==="EOF"&&(this.eof=!0),this.lastReadGroup=e,e}hasNext(){return this.eof?!1:!this.reader.isEnd()}isEOF(){return this.eof}parseGroupValue(e){if(e>=0&&e<=9)return this.readNullTerminatedString();if(e>=10&&e<=59)return this.reader.readFloat64();if(e>=60&&e<=79)return this.reader.readInt16();if(e>=90&&e<=99)return this.reader.readInt32();if(e>=100&&e<=109)return this.readNullTerminatedString();if(e>=110&&e<=149)return this.reader.readFloat64();if(e>=160&&e<=169)return this.reader.readInt64();if(e>=170&&e<=179)return this.reader.readInt16();if(e>=210&&e<=239)return this.reader.readFloat64();if(e>=270&&e<=289)return this.reader.readInt16();if(e>=290&&e<=299)return this.reader.readInt8()>0;if(e>=300&&e<=309)return this.readNullTerminatedString();if(e>=310&&e<=319){const i=this.ReadBinaryData();return cr(i)}if(e>=320&&e<=369)return this.readNullTerminatedString();if(e>=370&&e<=389)return this.reader.readInt16();if(e>=390&&e<=399)return this.readNullTerminatedString();if(e>=400&&e<=409)return this.reader.readInt16();if(e>=410&&e<=419)return this.readNullTerminatedString();if(e>=420&&e<=429)return this.reader.readInt32();if(e>=430&&e<=439)return this.readNullTerminatedString();if(e>=440&&e<=449)return this.reader.readInt32();if(e>=450&&e<=459)return this.reader.readFloat64();if(e>=460&&e<=469)return this.readNullTerminatedString();if(e>=470&&e<=479)return this.readNullTerminatedString();if(e>=480&&e<=481)return this.readNullTerminatedString();if(e>=999&&e<=999)throw new Error("The comment group 999, is not used in binary DXF files at byte address!");if(e===1004){const i=this.ReadBinaryData();return cr(i)}if(e>=1e3&&e<=1009)return this.readNullTerminatedString();if(e>=1010&&e<=1059)return this.reader.readFloat64();if(e>=1060&&e<=1070)return this.reader.readInt16();if(e===1071)return this.reader.readInt32();console.warn("[DxfBinReader] Invalid code '"+e+"' at byte address "+this.reader.getPosition())}readNullTerminatedString(){this.decoder||(this.decoder=new TextDecoder("utf-8"));let e=0,i=this.reader.readInt8();for(;i!==0;)this.int8Array[e++]=i,i=this.reader.readInt8();if(e===0)return"";if(e>hr)return console.warn("[DxfBinReader] Failed to read string! The number of bytes is "+e+" !"),"";const s=this.int8Array.subarray(0,e),r=s.toString();if(this.caches.get(r))return this.caches.get(r);const n=this.decoder?.decode(s);return this.caches.set(r,n),n}ReadBinaryData(){const e=this.reader.readUint8();return this.reader.readBytes(e)}}function cr(h){return Array.prototype.map.call(h,t=>("00"+t.toString(16)).slice(-2)).join("")}class dr extends wn{constructor(e){super();p(this,"data");this.data=e}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file. Ended on code "+this.data[this.pointer]);const e={code:parseInt(this.data[this.pointer])};return this.pointer++,e.value=Zo(e.code,this.data[this.pointer].trim(),this.data[this.pointer]),this.pointer++,e.code===0&&e.value==="EOF"&&(this.eof=!0),this.lastReadGroup=e,e}hasNext(){return!(this.eof||this.pointer>this.data.length-2)}isEOF(){return this.eof}}function Zo(h,t,e){return h>=0&&h<=9?e:h>=10&&h<=59?parseFloat(t):h>=60&&h<=99?parseInt(t):h>=100&&h<=109?t:h>=110&&h<=149?parseFloat(t):h>=160&&h<=179?parseInt(t):h>=210&&h<=239?parseFloat(t):h>=270&&h<=289?parseInt(t):h>=290&&h<=299?Ko(t):h>=300&&h<=369?t:h>=370&&h<=389?parseInt(t):h>=390&&h<=399?t:h>=400&&h<=409?parseInt(t):h>=410&&h<=419?t:h>=420&&h<=429?parseInt(t):h>=430&&h<=439?t:h>=440&&h<=449?parseInt(t):h>=450&&h<=459?parseFloat(t):h>=460&&h<=469||h===999||h>=1e3&&h<=1009?t:h>=1010&&h<=1059?parseFloat(t):h>=1060&&h<=1071?parseInt(t):(console.info("WARNING: Group code does not have a defined type: %j",{code:h,value:t}),t)}function Ko(h){if(h==="0")return!1;if(h==="1")return!0;throw TypeError("String '"+h+"' cannot be cast to Boolean type")}function $o(h){if(h==null)return!0;for(const t in h)if(Object.prototype.hasOwnProperty.call(h,t))return!1;return!0}function Jo(h,t){const e=[];let i=!1,s=!1;const r=4;for(let n=0;n<=r;n++){const a={};for(;!h.isEOF()&&!(t.code===0||s);){switch(t.code){case 10:case 11:case 12:case 13:if(i){s=!0;continue}a.x=t.value,i=!0;break;case 20:case 21:case 22:case 23:a.y=t.value;break;case 30:case 31:case 32:case 33:a.z=t.value;break;default:return e}t=h.next()}$o(a)||e.push(a),i=!1,s=!1}return e}class Qo{constructor(){p(this,"ForEntityName","3DFACE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:if(e.value!==0){const s=Math.log2(e.value)-1;i.vertices.splice(s,0,1)}e=t.next();break;case 10:i.vertices=Jo(t,e),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class el{constructor(){p(this,"ForEntityName","ARC")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=tl(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:i.endAngle=Math.PI/180*e.value,i.angleLength=i.endAngle-i.startAngle,e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function tl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class il{constructor(){p(this,"ForEntityName","ATTDEF")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=ur(t),e=t.lastReadGroup;break;case 11:i.endPoint=ur(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function ur(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class sl{constructor(){p(this,"ForEntityName","ATTRIB")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=fr(t),e=t.lastReadGroup;break;case 11:i.endPoint=fr(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function fr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class rl{constructor(){p(this,"ForEntityName","CIRCLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=nl(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:const s=Math.PI/180*e.value;s<i.startAngle?i.angleLength=s+2*Math.PI-i.startAngle:i.angleLength=s-i.startAngle,i.endAngle=s,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function nl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class al{constructor(){p(this,"ForEntityName","DIMENSION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 3:i.dimStyleName=e.value,e=t.next();break;case 10:i.anchorPoint=xt(t),e=t.lastReadGroup;break;case 11:i.middleOfText=xt(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=xt(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=xt(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=xt(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=xt(t),e=t.lastReadGroup;break;case 16:i.arcPoint=xt(t),e=t.lastReadGroup;break;case 70:i.dimensionType=e.value,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 42:i.actualMeasurement=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 50:i.angle=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function xt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class ol{constructor(){p(this,"ForEntityName","MULTILEADER")}parseEntity(t,e){const i={type:e.value};i.contextData={leaders:[]},e=t.next();const s=()=>{const o=i.contextData.leaders[i.contextData.leaders.length-1],l={vertices:[[]]};for(o.leaderLines.push(l);!t.isEOF();)switch(e.code){case 10:l.vertices[0].push(_e(t)),e=t.lastReadGroup;break;case 305:return;default:e=t.next();break}},r=()=>{const o={leaderLines:[]};for(i.contextData.leaders.push(o);!t.isEOF();)switch(e.code){case 290:o.hasSetLastLeaderLinePoint=e.value,e=t.next();break;case 291:o.hasSetDoglegVector=e.value,e=t.next();break;case 10:o.lastLeaderLinePoint=_e(t),e=t.lastReadGroup;break;case 11:o.doglegVector=_e(t),e=t.lastReadGroup;break;case 90:o.leaderBranchIndex=e.value,e=t.next();break;case 40:o.doglegLength=e.value,e=t.next();break;case 303:return;case 304:s(),e=t.lastReadGroup;break;default:e=t.next();break}},n=()=>{for(;!t.isEOF();)switch(e.code){case 40:i.contextData.contentScale=e.value,e=t.next();break;case 10:i.contextData.contentBasePosition=_e(t),e=t.lastReadGroup;break;case 145:i.contextData.landingGap=e.value,e=t.next();break;case 290:i.contextData.hasMText=e.value,e=t.next();break;case 300:i.contextData.defaultTextContents=e.value,e=t.next();break;case 11:i.contextData.textNormalDirection=_e(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=_e(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=_e(t),e=t.lastReadGroup;break;case 140:i.contextData.arrowHeadSize=e.value,e=t.next();break;case 41:i.contextData.textHeight=e.value,e=t.next();break;case 42:i.contextData.textRotation=e.value,e=t.next();break;case 43:i.contextData.textWidth=e.value,e=t.next();break;case 44:e=t.next();break;case 45:i.contextData.textLineSpacingFactor=e.value,e=t.next();break;case 90:i.contextData.textColor=e.value,e=t.next();break;case 170:i.contextData.textLineSpacingStyle=e.value,e=t.next();break;case 171:i.contextData.textAttachment=e.value,e=t.next();break;case 172:i.contextData.textFlowDirection=e.value,e=t.next();break;case 141:i.contextData.textBackgroundScaleFactor=e.value,e=t.next();break;case 92:i.contextData.textBackgroundTransparency=e.value,e=t.next();break;case 291:i.contextData.textBackgroundColorOn=e.value,e=t.next();break;case 292:i.contextData.textBackgroundFillOn=e.value,e=t.next();break;case 293:i.contextData.textUseAutoHeight=e.value,e=t.next();break;case 173:i.contextData.textColumnType=e.value,e=t.next();break;case 142:i.contextData.textColumnWidth=e.value,e=t.next();break;case 143:i.contextData.textColumnGutterWidth=e.value,e=t.next();break;case 144:i.contextData.textColumnHeight=e.value,e=t.next();break;case 295:i.contextData.textUseWordBreak=e.value,e=t.next();break;case 296:i.contextData.hasBlock=e.value,e=t.next();break;case 341:i.contextData.blockContentId=e.value,e=t.next();break;case 14:i.contextData.blockContentNormalDirection=_e(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=_e(t),e=t.lastReadGroup;break;case 16:i.contextData.blockContentScale=e.value,e=t.next();break;case 46:i.contextData.blockContentRotation=e.value,e=t.next();break;case 93:i.contextData.blockContentColor=e.value,e=t.next();break;case 47:i.contextData.blockTransformationMatrix=ll(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=_e(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=_e(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=_e(t),e=t.lastReadGroup;break;case 297:i.contextData.planeNormalReversed=e.value,e=t.next();break;case 301:return;case 302:r(),e=t.lastReadGroup;break;default:e=t.next();break}};return(()=>{for(;!t.isEOF();)switch(e.code){case 0:return;case 340:i.leaderStyleId=e.value,e=t.next();break;case 170:i.leaderLineType=e.value,e=t.next();break;case 91:i.leaderLineColor=e.value,e=t.next();break;case 341:i.leaderLineTypeId=e.value,e=t.next();break;case 171:i.leaderLineWeight=e.value,e=t.next();break;case 41:i.doglegLength=e.value,e=t.next();break;case 290:i.enableLanding=e.value,e=t.next();break;case 291:i.enableDogLeg=e.value,e=t.next();break;case 342:i.arrowHeadId=e.value,e=t.next();break;case 42:i.arrowHeadSize=e.value,e=t.next();break;case 172:i.contentType=e.value,e=t.next();break;case 173:i.textLeftAttachmentType=e.value,e=t.next();break;case 95:i.textLeftAttachmentType=e.value,e=t.next();break;case 174:i.textAngleType=e.value,e=t.next();break;case 175:i.textAlignmentType=e.value,e=t.next();break;case 343:i.textStyleId=e.value,e=t.next();break;case 92:i.textColor=e.value,e=t.next();break;case 292:i.enableFrameText=e.value,e=t.next();break;case 344:i.blockContentId=e.value,e=t.next();break;case 93:i.blockContentColor=e.value,e=t.next();break;case 10:i.blockContentScale=_e(t),e=t.lastReadGroup;break;case 43:i.blockContentRotation=e.value,e=t.next();break;case 176:i.blockContentConnectionType=e.value,e=t.next();break;case 293:i.enableAnotationScale=e.value,e=t.next();break;case 94:i.arrowHeadIndex=e.value,e=t.next();break;case 177:i.blockAttributeIndex=e.value,e=t.next();break;case 44:i.blockAttributeWidth=e.value,e=t.next();break;case 302:i.blockAttributeTextString=e.value,e=t.next();break;case 294:i.textDirectionNegative=e.value,e=t.next();break;case 178:i.textAlignInIPE=e.value,e=t.next();break;case 179:i.textAttachmentPoint=e.value,e=t.next();break;case 271:i.textAttachmentDirectionMText=e.value,e=t.next();break;case 272:i.textAttachmentDirectionBottom=e.value,e=t.next();break;case 273:i.textAttachmentDirectionTop=e.value,e=t.next();break;case 300:n(),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}})(),i}}function _e(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 110:case 111:case 112:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 120:case 121:case 122:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=h.next()}return t}function ll(h,t){const e=[];let i=h.lastReadGroup||h.next();for(;!h.isEOF()&&(i.code>=t&&i.code<t+16);){e.push(i.value);i=h.next()}return e}class hl{constructor(){p(this,"ForEntityName","ELLIPSE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=hs(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=hs(t),e=t.lastReadGroup;break;case 40:i.axisRatio=e.value,e=t.next();break;case 41:i.startAngle=e.value,e=t.next();break;case 42:i.endAngle=e.value,e=t.next();break;case 210:i.extrusionDirection=hs(t),e=t.lastReadGroup;break;case 2:i.name=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function hs(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}var Mn=(h=>(h[h.Default=0]="Default",h[h.External=1]="External",h[h.Polyline=2]="Polyline",h[h.Derived=4]="Derived",h[h.Textbox=8]="Textbox",h[h.Outermost=16]="Outermost",h[h.MaxFlags=31]="MaxFlags",h))(Mn||{}),Lt=(h=>(h[h.Polyline=0]="Polyline",h[h.Line=1]="Line",h[h.Arc=2]="Arc",h[h.Ellipse=3]="Ellipse",h[h.Spline=4]="Spline",h))(Lt||{});function Rt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;if(e.code===i)if(t.x=e.value,!h.isEOF()&&h.hasNext())e=h.next();else return t;if(e.code===i+10)if(t.y=e.value,!h.isEOF()&&h.hasNext())e=h.next();else return t;return e.code===i+20&&(t.z=e.value,!h.isEOF()&&h.hasNext()&&(e=h.next())),t}function cl(h){const t={type:0,points:[],isClosed:!0};let e=h.next();const i=e.value!==0;e=h.next(),t.isClosed=e.value!==0,e=h.next();const s=e.value;e=h.next();for(let n=0;n<s;n++){const a=Rt(h);e=h.lastReadGroup,i&&(a.bulge=e.value,e=h.next()),t.points.push(a)}e=h.lastReadGroup,console.assert(e.code===97,"The reference count code 97 was expected.");const r=e.value;e=h.next();for(let n=0;n<r;n++)console.assert(e.code===330,"The reference handle code 330 was expected."),e=h.next();return{edges:[t],pathTypeFlag:-1}}function dl(h,t){const e=[];let i=t.next();for(;e.length<h;){if(i.code!==72){i=t.next();continue}switch(i.value){case 1:{i=t.next();const n={type:1,startPoint:Rt(t),endPoint:Rt(t)};i=t.lastReadGroup,e.push(n);break}case 2:{i=t.next();const n={type:2,center:Rt(t),radius:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,n.radius=i.value,i=t.next(),n.startAngle=i.value,i=t.next(),n.endAngle=i.value,i=t.next(),n.bCounterclockwise=i.value!==0,i=t.next(),e.push(n);break}case 3:{i=t.next();const n={type:3,center:Rt(t),majorAxisEndPoint:Rt(t),minorRatio:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,n.minorRatio=i.value,i=t.next(),n.startAngle=i.value,i=t.next(),n.endAngle=i.value,i=t.next(),n.bCounterclockwise=i.value!==0,i=t.next(),e.push(n);break}case 4:{i=t.next();const n={type:4,degreeOfSplineCurve:i.value,bRational:!1,bPeriodic:!1,numKnots:0,numControlPoints:0,knotValues:[],controlPoints:[]};i=t.next(),n.bRational=i.value!==0,i=t.next(),n.bPeriodic=i.value!==0,i=t.next(),n.numKnots=i.value,i=t.next(),n.numControlPoints=i.value,i=t.next();for(let a=0;a<n.numKnots;a++)n.knotValues.push(i.value),i=t.next();for(let a=0;a<n.numControlPoints;a++){const o=i.value;i=t.next();const l=i.value;let c=1;i=t.next(),i.code===42&&(c=i.value,i=t.next()),n.controlPoints.push({x:o,y:l,z:c})}e.push(n);break}default:i=t.next();break}}i=t.lastReadGroup,console.assert(i.code===97,"The reference count code 97 was expected.");const s=i.value;i=t.next();for(let r=0;r<s;r++)console.assert(i.code===330,"The reference handle code 330 was expected."),i=t.next();return{edges:e,pathTypeFlag:-1}}function ul(h,t){const e=[];let i=-1,s=t.next();for(;e.length<h;){let r;switch(s.code){case 92:if(i=s.value,i&2){if(r=cl(t),r)r.pathTypeFlag=i,e.push(r);else throw new Error("[Hatch] Failed to parse hatch polyline boundary path !");s=t.lastReadGroup}else s=t.next();break;case 93:{const n=s.value;r=dl(n,t),r.pathTypeFlag=i,e.push(r),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function fl(h,t){if(h<=0){t.next();return}const e=[];let i=t.next();for(let s=0;s<h;s++){let r=0;const n={x:0,y:0},a={x:0,y:0};let o=-1;const l=[];for(;!t.isEOF()&&i.code!==0;){let c=!1;switch(i.code){case 53:r=i.value;break;case 43:n.x=i.value;break;case 44:n.y=i.value;break;case 45:a.x=i.value;break;case 46:a.y=i.value;break;case 79:o=i.value;break;case 49:l.push(i.value);break;default:c=!0}if(i=t.next(),c||l.length===o)break}o>=0&&e.push({angle:r,origin:n,delta:a,dashPattern:l})}return e}function pl(h,t){const e=[];let i=t.next();for(;e.length<h&&!t.isEOF()&&i.code!==void 0&&i.code!==0;)switch(i.code){case 63:i=t.next();break;case 421:e.push(i.value),i=t.next();break;default:i=t.next();break}return e}class ml{constructor(){p(this,"ForEntityName","HATCH")}parseEntity(t,e){const i={type:e.value,boundaryPaths:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.patternName=e.value,e=t.next();break;case 10:i.elevationX=e.value,e=t.next();break;case 20:i.elevationY=e.value,e=t.next();break;case 30:i.elevationZ=e.value,e=t.next();break;case 41:i.patternScale=e.value,e=t.next();break;case 47:i.pixelSize=e.value,e=t.next();break;case 52:i.patternAngle=e.value,e=t.next();break;case 63:i.patternFillColor=e.value,e=t.next();break;case 70:i.solidFill=(e.value&1)!==0,e=t.next();break;case 71:i.associativity=(e.value&1)!==0,e=t.next();break;case 73:i.annotatedBoundary=(e.value&1)!==0,e=t.next();break;case 75:i.style=e.value,e=t.next();break;case 76:i.patternType=e.value,e=t.next();break;case 78:i.patternLines=fl(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=ul(i.boundaryPathsCount,t),e=t.lastReadGroup;break;case 98:i.seedPointsCount=e.value,e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 450:i.isGradientColor=e.value===1,e=t.next();break;case 451:e=t.next();break;case 452:e=t.next();break;case 453:i.gradientColorCount=e.value,i.gradientColors=pl(i.gradientColorCount,t),e=t.next();break;case 460:e=t.next();break;case 461:e=t.next();break;case 462:e=t.next();break;case 463:e=t.next();break;case 470:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}var Gi=(h=>(h[h.ShowImage=1]="ShowImage",h[h.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",h[h.UseClippingBoundary=4]="UseClippingBoundary",h[h.TransparencyIsOn=8]="TransparencyIsOn",h))(Gi||{});let gl=class{constructor(){p(this,"ForEntityName","IMAGE")}parseEntity(t,e){const i={type:e.value,clippingBoundaryPath:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=Kt(t),e=t.lastReadGroup;break;case 11:i.uPixel=Kt(t),e=t.lastReadGroup;break;case 12:i.vPixel=Kt(t),e=t.lastReadGroup;break;case 13:i.imageSize=Kt(t),e=t.lastReadGroup;break;case 340:i.imageDefHandle=e.value,e=t.next();break;case 70:i.flags=e.value,e=t.next();break;case 280:i.clipping=e.value,e=t.next();break;case 281:i.brightness=e.value,e=t.next();break;case 282:i.contrast=e.value,e=t.next();break;case 283:i.fade=e.value,e=t.next();break;case 360:i.imageDefReactorHandle=e.value,e=t.next();break;case 71:i.clippingBoundaryType=e.value,e=t.next();break;case 91:i.countBoundaryPoints=e.value,e=t.next();break;case 14:i.clippingBoundaryPath.push(Kt(t)),e=t.lastReadGroup;break;case 290:i.clipMode=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}};function Kt(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=h.next()}return t}class yl{constructor(){p(this,"ForEntityName","INSERT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 66:i.attributesFollow=e.value!=0,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 42:i.yScale=e.value,e=t.next();break;case 43:i.zScale=e.value,e=t.next();break;case 10:i.position=pr(t),e=t.lastReadGroup;break;case 50:i.rotation=e.value,e=t.next();break;case 70:i.columnCount=e.value,e=t.next();break;case 71:i.rowCount=e.value,e=t.next();break;case 44:i.columnSpacing=e.value,e=t.next();break;case 45:i.rowSpacing=e.value,e=t.next();break;case 210:i.extrusionDirection=pr(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;case 1e3:i.zdysx?i.zdysx+=e.value:i.zdysx=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function pr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}function xl(h){switch(h){case 40:return"DIMSCALE";case 41:return"DIMASZ";case 42:return"DIMEXO";case 44:return"DIMEXE";case 75:return"DIMSE1";case 76:return"DIMSE2";case 77:return"DIMTAD";case 140:return"DIMTXT";case 144:return"DIMLFAC";case 147:return"DIMGAP";case 176:return"DIMCLRD";case 178:return"DIMCLRT";case 271:return"DIMDEC";case 341:return"DIMLDRBLK";default:return null}}class bl{constructor(){p(this,"ForEntityName","LEADER")}parseEntity(t,e){const i={type:e.value,arrowFlag:1,vertices:[]};e=t.next();let s=!1;for(;!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.push(vl(t)),e=t.lastReadGroup;break;case 3:i.dimensionStyle=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.textWidth=e.value,e=t.next();break;case 71:i.arrowFlag=e.value,e=t.next();break;case 72:i.pathType=e.value,e=t.next();break;case 73:i.creationFlag=e.value,e=t.next();break;case 74:i.direction=e.value,e=t.next();break;case 75:i.hasHookline=e.value===1,e=t.next();break;case 1001:s=e.value==="ACAD",e=t.next();break;case 1070:if(s){const r=xl(e.value);r&&(e=t.next(),(e.code==1005||e.code==1040||e.code==1070)&&(r==="DIMLDRBLK"?i.arrowHeadBlockHandle=e.value:r==="DIMASZ"?i.arrowHeight=e.value:r==="DIMSCALE"?i.arrowHeadScale=e.value:r==="DIMCLRD"&&e.value>0&&(i.colorIndex=e.value,i.color=Nt(Math.abs(e.value)))))}e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function vl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class wl{constructor(){p(this,"ForEntityName","LINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(cs(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(cs(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=cs(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function cs(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}function Ml(h,t){if(!h||h<=0)throw Error("n must be greater than 0 verticies");const e=[];let i=!1,s=!1,r=t.lastReadGroup;const n={};for(;!t.isEOF()&&!(r.code===0||s);)switch(r.code){case 10:if(i){s=!0;continue}n.x=r.value,i=!0,r=t.next();break;case 20:n.y=r.value,r=t.next();break;case 30:n.z=r.value,r=t.next();break;case 40:n.startWidth=r.value,r=t.next();break;case 41:n.endWidth=r.value,r=t.next();break;case 42:r.value!=0&&(n.bulge=r.value),r=t.next();break;default:return i&&e.push(n),e}return e.push(n),i=!1,s=!1,e}class Tl{constructor(){p(this,"ForEntityName","LWPOLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};let s=0;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 38:i.elevation=e.value,e=t.next();break;case 39:i.thickness=e.value,e=t.next();break;case 70:i.shape=(e.value&1)===1,i.hasContinuousLinetypePattern=(e.value&128)===128,e=t.next();break;case 90:s=e.value,e=t.next();break;case 10:i.vertices.push(...Ml(s,t)),e=t.lastReadGroup;break;case 43:e.value!==0&&(i.constantWidth=e.value),e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class Cl{constructor(){p(this,"ForEntityName","MTEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 3:const s=e.value;i.text?i.text+=s:i.text=s,e=t.next();break;case 1:const r=e.value;i.text?i.text+=r:i.text=r,e=t.next();break;case 10:i.position=mr(t),e=t.lastReadGroup;break;case 7:i.textStyle=e.value,e=t.next();break;case 44:i.lineSpaceFactor=e.value,e=t.next();break;case 11:i.directionVector=mr(t),i.rotation=void 0,e=t.lastReadGroup;break;case 40:i.height=e.value,e=t.next();break;case 41:const n=e.value;Math.abs(n)<1e-6?i.width=void 0:i.width=n,e=t.next();break;case 50:i.rotation=e.value,i.directionVector=void 0,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 72:i.drawingDirection=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function mr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Sl{constructor(){p(this,"ForEntityName","OLE2FRAME")}parseEntity(t,e){const i={type:e.value,binaryData:""};for(e=t.next();e.value!=="OLE"&&e.code!==0;)switch(e.code){case 3:i.documentType=e.value,e=t.next();break;case 70:i.version=e.value,e=t.next();break;case 10:i.leftUpX=e.value,e=t.next();break;case 20:i.leftUpY=e.value,e=t.next();break;case 30:i.leftUpZ=e.value,e=t.next();break;case 11:i.rightDownX=e.value,e=t.next();break;case 21:i.rightDownY=e.value,e=t.next();break;case 31:i.rightDownZ=e.value,e=t.next();break;case 90:i.lengthOfBinaryData=e.value,e=t.next();break;case 310:i.binaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class Ol{constructor(){p(this,"ForEntityName","POINT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=gr(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=gr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function gr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class El{constructor(){p(this,"ForEntityName","VERTEX")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.x=e.value,e=t.next();break;case 20:i.y=e.value,e=t.next();break;case 30:i.z=e.value,e=t.next();break;case 40:e=t.next();break;case 41:e=t.next();break;case 42:e.value!=0&&(i.bulge=e.value),e=t.next();break;case 70:i.curveFittingVertex=(e.value&1)!==0,i.curveFitTangent=(e.value&2)!==0,i.splineVertex=(e.value&8)!==0,i.splineControlPoint=(e.value&16)!==0,i.threeDPolylineVertex=(e.value&32)!==0,i.threeDPolylineMesh=(e.value&64)!==0,i.polyfaceMeshVertex=(e.value&128)!==0,e=t.next();break;case 50:e=t.next();break;case 71:i.faceA=e.value,e=t.next();break;case 72:i.faceB=e.value,e=t.next();break;case 73:i.faceC=e.value,e=t.next();break;case 74:i.faceD=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function _l(h,t){const e=new El,i=[];for(;!h.isEOF();)if(t.code===0){if(t.value==="VERTEX")i.push(e.parseEntity(h,t)),t=h.lastReadGroup;else if(t.value==="SEQEND"){Pl(h,t);break}}return i}function Pl(h,t){const e={type:t.value};for(t=h.next();!h.isEOF()&&t.code!==0;)if(t.code===101)for(;t.code!=0;)t=h.next();else Q(e,t),t=h.next();return e}class Al{constructor(){p(this,"ForEntityName","POLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:e=t.next();break;case 20:e=t.next();break;case 30:e=t.next();break;case 39:e=t.next(),i.thickness=e.value;break;case 40:e=t.next();break;case 41:e=t.next();break;case 70:i.shape=(e.value&1)!==0,i.includesCurveFitVertices=(e.value&2)!==0,i.includesSplineFitVertices=(e.value&4)!==0,i.is3dPolyline=(e.value&8)!==0,i.is3dPolygonMesh=(e.value&16)!==0,i.is3dPolygonMeshClosed=(e.value&32)!==0,i.isPolyfaceMesh=(e.value&64)!==0,i.hasContinuousLinetypePattern=(e.value&128)!==0,e=t.next();break;case 71:e=t.next();break;case 72:e=t.next();break;case 73:e=t.next();break;case 74:e=t.next();break;case 75:e=t.next();break;case 210:i.extrusionDirection=Il(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i.vertices=_l(t,e),i}}function Il(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class kl{constructor(){p(this,"ForEntityName","REGION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:i.modelerVersion=e.value,e=t.next();break;case 1:i.proprietaryData=e.value,e=t.next();break;case 3:i.proprietaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class Dl{constructor(){p(this,"ForEntityName","RAY")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(yr(t)),e=t.lastReadGroup;break;case 11:i.directionVector=yr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function yr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Bl{constructor(){p(this,"ForEntityName","SEQEND")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===-2||(Q(i,e),e=t.next());return i}}class Ll{constructor(){p(this,"ForEntityName","SOLID")}parseEntity(t,e){const i={type:e.value,points:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.points[0]=$t(t),e=t.lastReadGroup;break;case 11:i.points[1]=$t(t),e=t.lastReadGroup;break;case 12:i.points[2]=$t(t),e=t.lastReadGroup;break;case 13:i.points[3]=$t(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=$t(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function $t(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Rl{constructor(){p(this,"ForEntityName","SPLINE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.controlPoints||(i.controlPoints=[]),i.controlPoints.push(Jt(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push(Jt(t)),e=t.lastReadGroup;break;case 12:i.startTangent=Jt(t),e=t.lastReadGroup;break;case 13:i.endTangent=Jt(t),e=t.lastReadGroup;break;case 40:i.knotValues||(i.knotValues=[]),i.knotValues.push(e.value),e=t.next();break;case 70:(e.value&1)!=0&&(i.closed=!0),(e.value&2)!=0&&(i.periodic=!0),(e.value&4)!=0&&(i.rational=!0),(e.value&8)!=0&&(i.planar=!0),(e.value&16)!=0&&(i.planar=!0,i.linear=!0),e=t.next();break;case 71:i.degreeOfSplineCurve=e.value,e=t.next();break;case 72:i.numberOfKnots=e.value,e=t.next();break;case 73:i.numberOfControlPoints=e.value,e=t.next();break;case 74:i.numberOfFitPoints=e.value,e=t.next();break;case 210:i.normalVector=Jt(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function Jt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}function Fl(h,t,e){let i=h;for(;i.code!==304;)switch(i.code){case 301:i=e.next();break;case 93:i=e.next();break;case 90:i=e.next();break;case 1:t.text=i.value,i=e.next();break;case 94:i=e.next();break;case 300:t.attrText=i.value,i=e.next();break;case 302:t.text=i.value?i.value:t.text,i=e.next();break;default:console.log("[DXF ACAD_TABLE] ignore code: "+i.code+", value: "+i.value),i=e.next();break}}function xr(h,t){const e={};for(h.code===171&&(e.cellType=h.value);!t.isEOF();){const i=t.next();if(i.code===0||i.code===171){t.lastReadGroup=i;break}if(i.code===301){Fl(i,e,t);continue}switch(i.code){case 172:e.flagValue=i.value;break;case 173:e.mergedValue=i.value;break;case 174:e.autoFit=i.value;break;case 175:e.borderWidth=i.value;break;case 176:e.borderHeight=i.value;break;case 177:e.overrideFlag=i.value;break;case 178:e.virtualEdgeFlag=i.value;break;case 145:e.rotation=i.value;break;case 140:e.textHeight=i.value;break;case 170:e.attachmentPoint=i.value;break;case 91:e.extendedCellFlags=i.value;break;case 7:e.textStyle=i.value;break;case 340:e.blockTableRecordId=i.value;break;case 345:e.fieldObjetId=i.value;break;case 146:e.blockScale=i.value;break;case 179:e.blockAttrNum=i.value;break;case 1:e.text=i.value;break;case 302:e.attrText=i.value;break}}return e}class zl{constructor(){p(this,"ForEntityName","ACAD_TABLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=br(t),e=t.lastReadGroup;break;case 11:i.directionVector=br(t),e=t.lastReadGroup;break;case 90:i.tableValue=e.value,e=t.next();break;case 91:i.rowCount=e.value,e=t.next();break;case 92:i.columnCount=e.value,e=t.next();break;case 93:i.overrideFlag=e.value,e=t.next();break;case 94:i.borderColorOverrideFlag=e.value,e=t.next();break;case 95:i.borderLineWeightOverrideFlag=e.value,e=t.next();break;case 96:i.borderVisibilityOverrideFlag=e.value,e=t.next();break;case 141:i.rowHeightArr?i.rowHeightArr.push(e.value):i.rowHeightArr=[e.value],e=t.next();break;case 142:i.columnWidthArr?i.columnWidthArr.push(e.value):i.columnWidthArr=[e.value],e=t.next();break;case 280:i.version=e.value,e=t.next();break;case 342:i.tableStyleId=e.value,e=t.next();break;case 343:i.blockRecordHandle=e.value,e=t.next();break;case 171:i.cells?i.cells.push(xr(e,t)):i.cells=[xr(e,t)],e=t.lastReadGroup;break;default:Q(i,e),e=t.next();break}return i}}function br(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class jl{constructor(){p(this,"ForEntityName","TEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=vr(t),e=t.lastReadGroup;break;case 11:i.endPoint=vr(t),e=t.lastReadGroup;break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 72:i.halign=e.value,e=t.next();break;case 73:i.valign=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 71:i.mirrored=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function vr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Vl{constructor(){p(this,"ForEntityName","VIEWPORT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 68:i.viewportStatus=e.value,e=t.next();break;case 40:i.width_paperSpace=e.value,e=t.next();break;case 41:i.height_paperSpace=e.value,e=t.next();break;case 69:i.viewportId=e.value,e=t.next();break;case 10:i.centerPoint=qe(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=qe(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=qe(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=qe(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=qe(t),e=t.lastReadGroup;break;case 16:i.viewDirection=qe(t),e=t.lastReadGroup;break;case 17:i.viewTarget=qe(t),e=t.lastReadGroup;break;case 42:i.perspectiveLens=e.value,e=t.next();break;case 43:i.frontClippingPlaneZ=e.value,e=t.next();break;case 44:i.backClippingPlaneZ=e.value,e=t.next();break;case 45:i.viewHeight=e.value,e=t.next();break;case 50:i.snapAngle=e.value,e=t.next();break;case 51:i.viewTwistAngle=e.value,e=t.next();break;case 72:i.circleZoomPercent=e.value,e=t.next();break;case 331:i.frozenLayerHandles=i.frozenLayerHandles||[],i.frozenLayerHandles.push(e.value),e=t.next();break;case 90:i.viewportStatusFlags=e.value,e=t.next();break;case 340:i.viewportClippingBoundaryhandleId=e.value,e=t.next();break;case 1:i.plotStyleSheetName=e.value,e=t.next();break;case 281:i.renderMode=e.value,e=t.next();break;case 71:i.viewportFlag_ucs=e.value,e=t.next();break;case 74:i.ucsIcon=e.value,e=t.next();break;case 110:i.ucsOrigin=qe(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=qe(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=qe(t),e=t.lastReadGroup;break;case 345:i.ucsTableRecordHandle=e.value,e=t.next();break;case 346:i.baseUcsTableRecordHandle=e.value,e=t.next();break;case 79:i.orthographicType=e.value,e=t.next();break;case 146:i.elevation=e.value,e=t.next();break;case 170:i.shadePlotMode=e.value,e=t.next();break;case 61:i.frequency=e.value,e=t.next();break;case 292:i.lightingFlag=e.value,e=t.next();break;case 282:i.lightingType=e.value,e=t.next();break;case 141:i.viewBrightness=e.value,e=t.next();break;case 142:i.viewContrast=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function qe(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.isEOF();){switch(e.code){case 10:case 12:case 13:case 14:case 15:case 16:case 17:case 110:case 111:case 112:t.x=e.value;break;case 20:case 22:case 23:case 24:case 25:case 26:case 27:case 120:case 121:case 122:t.y=e.value;break;case 30:case 32:case 33:case 34:case 35:case 36:case 37:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=h.next()}return t}class Ul{constructor(){p(this,"ForEntityName","XLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(wr(t)),e=t.lastReadGroup;break;case 11:i.directionVector=wr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function wr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Hl{constructor(){p(this,"ForObjectName","DICTIONARY")}parseObject(t,e){const s={type:e.value},r=[],n=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 280:s.isHardOwner=e.value===1,e=t.next();break;case 281:s.cloningFlag=e.value,e=t.next();break;case 3:r.push(e.value),e=t.next();break;case 350:n.push(e.value),e=t.next();break;case 360:n.push(e.value),e=t.next();break;case 100:e=t.next();break;case 102:e=t.next();break;default:Xt(s,e),e=t.next();break}if(r.length!==n.length)throw new Error("The number of Dictionary entries does not match !");return s.entries={},r.forEach((a,o)=>{s.entries[n[o]]=a}),s}}class Nl{constructor(){p(this,"ForObjectName","IMAGEDEF")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 90:s.classVersion=e.value,e=t.next();break;case 1:s.filename=e.value,e=t.next();break;case 10:s.imageSize=Mr(t),e=t.next();break;case 11:s.pixelSize=Mr(t),e=t.next();break;case 280:s.loaded=e.value,e=t.next();break;case 281:s.resolutionUnits=e.value,e=t.next();break;default:Xt(s,e),e=t.next();break}return s}}function Mr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Gl{constructor(){p(this,"ForObjectName","LAYOUT")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 1:s.layoutName=e.value,e=t.next();break;case 70:s.flag=e.value,e=t.next();break;case 71:s.tabOrder=e.value,e=t.next();break;case 76:s.orthographicType=e.value,e=t.next();break;case 10:s.minLimit=ot(t),e=t.lastReadGroup;break;case 11:s.maxLimit=ot(t),e=t.lastReadGroup;break;case 12:s.basePoint=ot(t),e=t.lastReadGroup;break;case 13:s.origin=ot(t),e=t.lastReadGroup;break;case 14:s.minExtent=ot(t),e=t.lastReadGroup;break;case 15:s.maxExtent=ot(t),e=t.lastReadGroup;break;case 16:s.XAxis=ot(t),e=t.lastReadGroup;break;case 17:s.YAxis=ot(t),e=t.lastReadGroup;break;case 146:s.elevation=e.value,e=t.next();break;case 330:s.viewportHandle=e.value,e=t.next();break;default:Xt(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function ot(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class ql{constructor(){p(this,"ForObjectName","SORTENTSTABLE")}parseObject(t,e){const s={type:e.value};let r=!1;s.sortEntsObject={},s.sortEntsObject.entityHandles=[];let n=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 5:r?(n.push(e.value),s.sortEntsObject.entityHandles.push(n),n=[]):s.handle=e.value,e=t.next();break;case 100:e=t.next(),r=!0;break;case 102:e=t.next();break;case 330:r?s.sortEntsObject.ownerHandle=e.value:s.ownerHandle=e.value,e=t.next();break;case 331:n.push(e.value),e=t.next();break;default:Xt(s,e),e=t.next();break}return s}}class Wl{constructor(){p(this,"ForObjectName","SPATIAL_FILTER")}parseObject(t,e){const s={type:e.value};s.vertices=[];let r,n;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 11:s.origin=qi(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),r=qi(t),e=t.lastReadGroup,n=qi(t),e=t.lastReadGroup,s.vertices.push(r,{x:n.x,y:r.y},n,{x:r.x,y:n.y},r)):s.numberOfPointsOnClipBoundary>2?(s.vertices=Yl(s.numberOfPointsOnClipBoundary,t),e=t.lastReadGroup):e=t.next();break;case 71:s.clipBoundaryVisible=e.value===1,e=t.next();break;case 72:s.frontClippingPlaneFlag=e.value===1,e=t.next(),s.frontClippingPlaneFlag&&e.code===40&&(s.frontClippingPlaneDistance=e.value,e=t.next());break;case 73:s.backClippingPlaneFlag=e.value===1,e=t.next(),s.backClippingPlaneFlag&&e.code===41&&(s.backClippingPlaneDistance=e.value,e=t.next());break;case 100:e=t.next();break;case 102:e=t.next();break;case 210:s.extrusionDirectionX=e.value,e=t.next();break;case 220:s.extrusionDirectionY=e.value,e=t.next();break;case 230:s.extrusionDirectionZ=e.value,e=t.next();break;case 40:s.invertBlockMatrix=Tr(t,40),s.matrix=Tr(t,40),e=t.lastReadGroup;break;default:Xt(s,e),e=t.next();break}return s}}function Yl(h,t){t.next();const e=[];for(;e.length<h;)e.push(qi(t));return e}function Tr(h,t){let e=h.lastReadGroup;const i=[];for(let s=0;s<12;s++){if(e.code!==t)throw new Error("Expected code for matrix value to be "+t+" but got "+e.code);i.push(e.value),e=h.next()}return i}function qi(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=h.next()}return t}class Xl{constructor(){p(this,"ForObjectName","XRECORD")}parseObject(t,e){const s={type:e.value,binaryData:""};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 280:s.cloningFlag=e.value,e=t.next();break;case 310:s.binaryData+=e.value,e=t.next();break;case 311:e=t.next();break;default:Xt(s,e),e=t.next();break}return s}}function Zl(h){h.registerEntityHandler(Qo),h.registerEntityHandler(el),h.registerEntityHandler(il),h.registerEntityHandler(sl),h.registerEntityHandler(rl),h.registerEntityHandler(al),h.registerEntityHandler(ol),h.registerEntityHandler(hl),h.registerEntityHandler(ml),h.registerEntityHandler(gl),h.registerEntityHandler(yl),h.registerEntityHandler(bl),h.registerEntityHandler(wl),h.registerEntityHandler(Tl),h.registerEntityHandler(Cl),h.registerEntityHandler(Sl),h.registerEntityHandler(Ol),h.registerEntityHandler(Al),h.registerEntityHandler(kl),h.registerEntityHandler(Dl),h.registerEntityHandler(Bl),h.registerEntityHandler(Ll),h.registerEntityHandler(Rl),h.registerEntityHandler(zl),h.registerEntityHandler(jl),h.registerEntityHandler(Vl),h.registerEntityHandler(Ul)}function Kl(h){h.registerObjectHandler(Hl),h.registerObjectHandler(Nl),h.registerObjectHandler(Gl),h.registerObjectHandler(ql),h.registerObjectHandler(Wl),h.registerObjectHandler(Xl)}function $l(h){const t=new Uint8Array(h,0,18);let e="";for(let i=0;i<18;i++)e+=String.fromCharCode(t[i]);return e==="AutoCAD Binary DXF"}class Tn{constructor(t){p(this,"_entityHandlers",{});p(this,"_objectHandlers",{});p(this,"_layoutBlocks",{});p(this,"unhandledSections",{});p(this,"unhandledObjects",{});p(this,"unhandledEntities",{});p(this,"unsupportedLineTypes",{});p(this,"encoding");this.encoding=t,Zl(this),Kl(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new dr(e);return this._parse(i)}else{let e;if($l(t))e=new Xo(t);else{const i=new TextDecoder(this.encoding).decode(t),s=Date.now(),r=this.splitByLineSeparator(i);console.info("[DxfParser] string.split took "+(Date.now()-s)/1e3+"s, it is avoidable by using dxf in binary."),e=new dr(r)}return this._parse(e)}}registerEntityHandler(t){const e=new t;this._entityHandlers[e.ForEntityName]=e}registerObjectHandler(t){const e=new t;this._objectHandlers[e.ForObjectName]=e}parseSync(t){return this.parse(t)}parseStream(t){let e="";const i=this;return new Promise((s,r)=>{t.on("data",n=>{e+=n}),t.on("end",()=>{try{s(i.parse(e))}catch(n){r(n)}}),t.on("error",n=>{r(n)})})}_parse(t){const e={};let i=0;if(!t.hasNext())throw Error("Empty file");const s=this;let r;function n(){for(r=t.next();r.code===999;)r=t.next();for(;!t.isEOF();)if(r.code===0&&r.value==="SECTION"){if(r=t.next(),r.code!==2){console.error("Unexpected code %s after 0:SECTION",Cn(r)),r=t.next();continue}if(r.value==="HEADER")S.trace("> HEADER"),e.header=a(),S.trace("<");else if(r.value==="TABLES")S.trace("> TABLES"),e.tables=c(),S.trace("<");else if(r.value==="BLOCKS")S.trace("> BLOCKS"),e.blocks=o(),S.trace("<");else if(r.value==="ENTITIES")S.trace("> ENTITIES"),e.entities=E(!1),S.trace("<");else if(r.value==="OBJECTS")S.trace("> OBJECTS"),e.objects=O(),S.trace("<");else if(r.value==="EOF")S.trace("EOF");else{const C=r.value;s.unhandledSections[C]?s.unhandledSections[C]++:s.unhandledSections[C]=1}}else r=t.next();s.unhandledSections={},s.unhandledEntities={},s.unhandledObjects={},s.unsupportedLineTypes={}}function a(){let C=null,w=null;const M={};for(r=t.next();;){if(Pe(r,0,"ENDSEC")){C&&(M[C]=w);break}else r.code===9?(C&&(M[C]=w),C=r.value):r.code===10?w={x:r.value}:r.code===20?w.y=r.value:r.code===30?w.z=r.value:w=r.value;r=t.next()}return r=t.next(),M}function o(){const C={};for(r=t.next();r.value!=="EOF"&&!Pe(r,0,"ENDSEC");)if(Pe(r,0,"BLOCK")){S.trace("block {");const w=l();S.trace("}"),_(w),w.name?C[w.name]=w:console.error("[DxfParser] Block with handle '"+w.handle+"' is missing a name, ignored!")}else Qe(r),r=t.next();return C}function l(){const C={};for(r=t.next();r.value!=="EOF";){switch(r.code){case 1:C.xrefPath=r.value,r=t.next();break;case 2:C.name=r.value,r=t.next();break;case 3:C.name2=r.value,r=t.next();break;case 4:C.description=r.value,r=t.next();break;case 5:C.handle=r.value,r=t.next();break;case 8:C.layer=r.value,r=t.next();break;case 10:C.position=Ie(t),r=t.lastReadGroup;break;case 67:C.paperSpace=!!(r.value&&r.value===1),r=t.next();break;case 70:C.blockType=r.value,r=t.next();break;case 100:r=t.next();break;case 330:C.ownerHandle=r.value,r=t.next();break;case 0:if(r.value==="ENDBLK")break;C.entities=E(!0);break;default:Qe(r),r=t.next();break}if(Pe(r,0,"ENDBLK")){r=t.next();break}}return C}function c(){const C={};for(r=t.next();r.value!=="EOF"&&!Pe(r,0,"ENDSEC");)Pe(r,0,"TABLE")?(r=t.next(),b[r.value]?(S.trace(r.value+" Table {"),C[b[r.value].tableName]=f(r),S.trace("}")):S.trace("Unhandled Table "+r.value)):r=t.next();return r=t.next(),C}const u="ENDTAB";function f(C){const w=b[C.value],M={};let P=0;for(r=t.next();!Pe(r,0,u);)switch(r.code){case 5:M.handle=r.value,r=t.next();break;case 330:M.ownerHandle=r.value,r=t.next();break;case 100:r.value==="AcDbSymbolTable"||Qe(r),r=t.next();break;case 70:P=r.value,r=t.next();break;case 0:r.value===w.dxfSymbolName?M[w.tableRecordsProperty]=w.parseTableRecords():(Qe(r),r=t.next());break;default:Qe(r),r=t.next();break}const A=M[w.tableRecordsProperty];if(A){const I=(()=>{if(A.constructor===Array)return A.length;if(typeof A=="object")return Object.keys(A).length})();P!==I&&console.warn("[DxfParser] Parsed "+I+" "+w.dxfSymbolName+"s but expected "+P)}return r=t.next(),M}function m(){const C=[];let w={};for(S.trace("Viewport {"),r=t.next();!Pe(r,0,u);)switch(r.code){case 2:w.name=r.value,r=t.next();break;case 10:w.lowerLeftCorner=Ie(t),r=t.lastReadGroup;break;case 11:w.upperRightCorner=Ie(t),r=t.lastReadGroup;break;case 12:w.center=Ie(t),r=t.lastReadGroup;break;case 13:w.snapBasePoint=Ie(t),r=t.lastReadGroup;break;case 14:w.snapSpacing=Ie(t),r=t.lastReadGroup;break;case 15:w.gridSpacing=Ie(t),r=t.lastReadGroup;break;case 16:w.viewDirectionFromTarget=Ie(t),r=t.lastReadGroup;break;case 17:w.viewTarget=Ie(t),r=t.lastReadGroup;break;case 40:w.viewHeight=r.value,r=t.next();break;case 41:w.aspectRatio=r.value,r=t.next();break;case 42:w.lensLength=r.value,r=t.next();break;case 43:w.frontClippingPlane=r.value,r=t.next();break;case 44:w.backClippingPlane=r.value,r=t.next();break;case 45:w.viewHeight=r.value,r=t.next();break;case 50:w.snapRotationAngle=r.value,r=t.next();break;case 51:w.viewTwistAngle=r.value,r=t.next();break;case 79:w.orthographicType=r.value,r=t.next();break;case 110:w.ucsOrigin=Ie(t),r=t.lastReadGroup;break;case 111:w.ucsXAxis=Ie(t),r=t.lastReadGroup;break;case 112:w.ucsYAxis=Ie(t),r=t.lastReadGroup;break;case 281:w.renderMode=r.value,r=t.next();break;case 282:w.defaultLightingType=r.value,r=t.next();break;case 292:w.defaultLightingOn=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 63:case 421:case 431:w.ambientColor=r.value,r=t.next();break;case 0:r.value==="VPORT"&&(S.trace("}"),C.push(w),S.trace("Viewport {"),w={},r=t.next());break;default:Qe(r),r=t.next();break}return S.trace("}"),C.push(w),C}function g(){const C={};let w={},M=0,P="",A=!1;for(S.trace("LType {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.name=r.value.toUpperCase(),P=w.name,r=t.next();break;case 3:w.description=r.value,r=t.next();break;case 9:r=t.next();break;case 40:w.patternLength=r.value,r=t.next();break;case 44:r=t.next();break;case 45:r=t.next();break;case 46:r=t.next();break;case 49:let I=r.value;A&&(I=Math.abs(I),A=!1),w.pattern.push(I),r=t.next();break;case 70:r=t.next();break;case 73:M=r.value,M>0&&(w.pattern=[]),r=t.next();break;case 74:r.value!==0&&(A=!0,s.unsupportedLineTypes[w.name]?s.unsupportedLineTypes[w.name]++:s.unsupportedLineTypes[w.name]=1),r=t.next();break;case 75:r=t.next();break;case 0:S.trace("}"),M>0&&M!==w.pattern.length&&console.warn("[DxfParser] lengths do not match on LTYPE pattern"),C[P]=w,w={},S.trace("LType {"),r=t.next();break;default:r=t.next();break}return S.trace("}"),C[P]=w,C}function x(){const C={};let w={},M;for(S.trace("Layer {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.name=r.value,M=r.value,r=t.next();break;case 5:w.handle=r.value,r=t.next();break;case 62:w.visible=r.value>=0,w.colorIndex=Math.abs(r.value),w.color=Nt(w.colorIndex),r=t.next();break;case 70:w.flag=r.value,w.frozen=(w.flag&1)>0,r=t.next();break;case 420:w.color=Math.abs(r.value),r=t.next();break;case 6:w.lineType=r.value.toUpperCase(),r=t.next();break;case 370:w.lineweight=r.value,r=t.next();break;case 0:r.value==="LAYER"&&(S.trace("}"),M&&(C[M]=w),S.trace("Layer {"),w={},M=void 0,r=t.next());break;default:Qe(r),r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function y(){const C={};let w={},M;for(S.trace("Style {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.styleName=r.value,M=r.value,r=t.next();break;case 3:w.fontFile=r.value,r=t.next();break;case 4:w.bigFontFile=r.value,r=t.next();break;case 5:w.handle=r.value,r=t.next();break;case 40:w.textHeight=r.value,r=t.next();break;case 41:w.xScale=r.value,r=t.next();break;case 42:w.priorTextHeight=r.value,r=t.next();break;case 50:w.rotation=r.value,r=t.next();break;case 70:r=t.next();break;case 71:w.mirrorType=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 0:r.value==="STYLE"&&(S.trace("}"),M&&(C[M]=w),S.trace("Style {"),w={},M=void 0,r=t.next());break;default:r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function T(){const C={};let w={},M;for(S.trace("DimStyle {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.styleName=r.value,M=r.value,r=t.next();break;case 40:w.DIMSCALE=r.value,r=t.next();break;case 41:w.DIMASZ=r.value,r=t.next();break;case 42:w.DIMEXO=r.value,r=t.next();break;case 44:w.DIMEXE=r.value,r=t.next();break;case 75:w.DIMSE1=r.value,r=t.next();break;case 76:w.DIMSE2=r.value,r=t.next();break;case 77:w.DIMTAD=r.value,r=t.next();break;case 140:w.DIMTXT=r.value,r=t.next();break;case 144:w.DIMLFAC=r.value,r=t.next();break;case 147:w.DIMGAP=r.value,r=t.next();break;case 176:w.DIMCLRD=r.value,r=t.next();break;case 178:w.DIMCLRT=r.value,r=t.next();break;case 271:w.DIMDEC=r.value,r=t.next();break;case 341:w.DIMLDRBLK=r.value,r=t.next();break;case 70:r=t.next();break;case 0:r.value==="DIMSTYLE"&&(S.trace("}"),M&&(C[M]=w),S.trace("DimStyle {"),w={},M=void 0,r=t.next());break;default:r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function v(){const C={};let w={},M;for(S.trace("BlockRecord {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 5:w.handle=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 2:w.blockName=r.value,M=w.blockName,r=t.next();break;case 340:w.layoutHandle=r.value,r=t.next();break;case 70:w.blockInsertUnits=r.value,r=t.next();break;case 280:w.blockExplodability=r.value,r=t.next();break;case 281:w.blockScalability=r.value,r=t.next();break;case 310:w.bitmap=r.value,r=t.next();break;case 0:if(r.value==="BLOCK_RECORD"){S.trace("}"),M&&(C[M]=w);const A=w.layoutHandle;M&&A&&A.length>0&&A!=="0"&&(s._layoutBlocks[A]=w),S.trace("BlockRecord {"),w={},M=void 0,r=t.next()}else Qe(r),r=t.next();break;default:Qe(r),r=t.next();break}S.trace("}"),M&&(C[M]=w);const P=w.layoutHandle;return M&&P&&P.length>0&&P!=="0"&&(s._layoutBlocks[P]=w),C}const b={VPORT:{tableRecordsProperty:"viewports",tableName:"viewport",dxfSymbolName:"VPORT",parseTableRecords:m},LTYPE:{tableRecordsProperty:"lineTypes",tableName:"lineType",dxfSymbolName:"LTYPE",parseTableRecords:g},LAYER:{tableRecordsProperty:"layers",tableName:"layer",dxfSymbolName:"LAYER",parseTableRecords:x},BLOCK_RECORD:{tableRecordsProperty:"blockRecords",tableName:"blockRecord",dxfSymbolName:"BLOCK_RECORD",parseTableRecords:v},STYLE:{tableRecordsProperty:"styles",tableName:"style",dxfSymbolName:"STYLE",parseTableRecords:y},DIMSTYLE:{tableRecordsProperty:"dimStyles",tableName:"dimStyle",dxfSymbolName:"DIMSTYLE",parseTableRecords:T}};function E(C){const w=[],M=C?"ENDBLK":"ENDSEC";for(C||(r=t.next());;)if(r.code===0){if(r.value===M)break;const P=s._entityHandlers[r.value];if(P!=null){S.trace(r.value+" {");const A=P.parseEntity(t,r);A&&(A.layer||(A.layer="0"),A.colorIndex===void 0&&(A.colorIndex=256),A.lineType||(A.lineType="BYLAYER"),r=t.lastReadGroup,S.trace("}"),_(A),w.push(A))}else{const A=r.value;s.unhandledEntities[A]||(s.unhandledEntities[A]=0),s.unhandledEntities[A]++,r=t.next();continue}}else r=t.next();return M==="ENDSEC"&&(r=t.next()),w}function O(){const C={},w="ENDSEC";for(r=t.next();r.value!=="EOF";)if(r.code===0){if(r.value===w)break;const M=s._objectHandlers[r.value];if(M!=null){S.trace(r.value+" {");const P=M.parseObject(t,r),A=r.value;r=t.lastReadGroup,S.trace("}"),_(P),C[A]||(C[A]=[]),C[A].push(P)}else{const P=r.value;s.unhandledObjects[P]||(s.unhandledObjects[P]=0),s.unhandledObjects[P]++,r=t.next();continue}}else r=t.next();return r=t.next(),C.LAYOUT&&(Object.keys(s._layoutBlocks).length!==C.LAYOUT.length&&console.warn("[DxfParser] The number of layout and block associations does not match!"),C.LAYOUT.forEach(M=>{s._layoutBlocks[M.handle]&&(M.associatedBlockName=s._layoutBlocks[M.handle].blockName)}),C.LAYOUT.sort((M,P)=>M.tabOrder-P.tabOrder)),C}function _(C){if(!C)throw new TypeError("entity cannot be undefined or null");C.handle||(C.handle=(i++).toString())}return n(),e}splitByLineSeparator(t){const e=[];let i=0;for(let s=0,r=t.length;s<r;++s){const n=t[s];if(n==="\r"||n===`
792
+ `){let a=t.substring(i,s);a&&a.indexOf("M+")>-1&&(a=Ho(a)),a&&(a=a),e.push(a),n==="\r"&&t[s+1]===`
793
+ `&&s++,i=s+1}}return e.push(t.substring(i,t.length)),e}}function Pe(h,t,e){return h.code===t&&h.value===e}function Qe(h){S.trace("unhandled group "+Cn(h))}function Cn(h){return h.code+":"+h.value}const Sn="0.4.0",On="VERSION",Jl=()=>window.localStorage.getItem(On),Ql=()=>{window.localStorage.setItem(On,Sn)},eh=()=>Jl()!==Sn?(Ql(),!0):!1,Tt=class Tt{constructor(){p(this,"DATABASE_NAME","x_viewer");p(this,"DEFAULT_TABLES",[{name:"dxf_data",options:{keyPath:"dxfDataId",autoIncrement:!1}},{name:"fonts",options:{keyPath:"fileName",autoIncrement:!0}}]);p(this,"db");p(this,"tables");this.db=void 0,this.tables=this.DEFAULT_TABLES}static instance(){return!Tt._instance&&(Tt._instance=new Tt),Tt._instance}setTables(t){this.tables=t}getTables(){return this.tables}async getDatabase(){let t=await this.getDB(this.DATABASE_NAME);return this.db||(t.close(),eh()&&await this.deleteDataBase(this.DATABASE_NAME),t=await this.getUpgradedDB(t)),t.onclose=()=>{this.db=void 0,S.debug("[DB] Db "+t.name+" is closed.")},t.onerror=e=>{this.db=void 0,S.debug("[DB] Db "+t.name+" encountered error.",e)},t.onabort=e=>{this.db=void 0,S.debug("[DB] Db "+t.name+" aborted.",e)},t.onversionchange=e=>{S.debug("onversionchange",e)},this.db=t,Promise.resolve(this.db)}closeDatabase(){this.db&&this.db.close()}deleteDataBase(t){return new Promise((e,i)=>{const s=window.indexedDB.deleteDatabase(t);s.onerror=r=>{S.debug(r),i(r)},s.onsuccess=r=>{const n=r.target;S.debug("[DB] Db "+t+" delete old version "+r.oldVersion+"."),e(n)}})}async getDB(t){return new Promise((e,i)=>{const s=window.indexedDB.open(t);s.onerror=i,s.onsuccess=r=>{const n=r.target.result;S.debug("[DB] Db "+n.name+" opened (version "+n.version+")."),e(n)}})}async getUpgradedDB(t){return new Promise((e,i)=>{S.debug("[DB] Upgrading db "+t.name+" (version "+t.version+")");const s=window.indexedDB.open(t.name,t.version+1);s.onerror=i,s.onblocked=r=>{S.debug("onblocked",r)},s.onupgradeneeded=r=>{const n=r.target.transaction;n.oncomplete=()=>{S.debug("[DB] Upgrade is done (new version: "+a.version+").")};const a=r.target.result,o=[];for(let l=0;l<this.tables.length;++l){const c=this.tables[l];if(!a.objectStoreNames.contains(c.name)){S.debug("[DB] Creating table "+c.name+"...");const u=this.createTable(a,c.name,c.options,c.indexArray);o.push(u)}}o.length>0&&Promise.all(o).then(()=>{S.debug("[DB] All("+o.length+") tables created.")})},s.onsuccess=r=>{const n=r.target.result;S.debug("[DB] Db "+n.name+" opened (version "+n.version+")."),e(n)}})}async createTable(t,e,i,s){return new Promise(r=>{const n=t.createObjectStore(e,i);s&&s.forEach(a=>{n.createIndex(a.name,a.fields,{unique:a.unique})}),S.debug("[DB] Table "+e+" created."),r(t)})}};p(Tt,"_instance");let ae=Tt;class En{constructor(){p(this,"db");p(this,"isCreatingTable");if(this.db=void 0,this.isCreatingTable=!1,ae.instance().getTables().findIndex(i=>i.name===this.tableName())===-1)throw new Error("Failed to find table '"+this.tableName()+"' from indexeddb!")}tableName(){throw new Error("Derived class have to override 'tableName', and set a proper table name!")}add(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.add(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()}).catch(r=>{i&&i(r)})}save(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.put(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()})}delete(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.delete(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()})}update(){ae.instance().getDatabase().then(()=>{})}query(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readonly").objectStore(i),n=r.openCursor();n.onsuccess=a=>{const o=a.target.result;o&&o.continue(),t&&t(o)},n.onerror=e}).finally(()=>{ae.instance().closeDatabase()})}queryByIndex(t,e,i,s){const r=this.tableName();ae.instance().getDatabase().then(n=>{const a=n.transaction([r],"readonly").objectStore(r),o=a.index(t).get(e);o.onerror=s,o.onsuccess=function(l){const c=l.target?.result;i&&i(c)}}).finally(()=>{ae.instance().closeDatabase()})}queryAll(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readonly").objectStore(i),n=r.getAll();n.onsuccess=a=>{t&&t(a.target.result)},n.onerror=e}).finally(()=>{ae.instance().closeDatabase()})}clearAll(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readwrite").objectStore(i),n=r.clear();n.onsuccess=a=>{t&&t(a)},n.onerror=a=>{e&&e(a)}}).finally(()=>{ae.instance().closeDatabase()})}}const Ct=class Ct extends En{tableName(){return"dxf_data"}static instance(){return!Ct._instance&&(Ct._instance=new Ct),Ct._instance}query(t,e,i){const s=[],r=this.tableName();ae.instance().getDatabase().then(n=>{const a=n.transaction([r],"readonly").objectStore(r),o=a.get(t);o.onerror=l=>{i&&i(l),S.info("[DxfDataTable] Failed to query !",l)},o.onsuccess=()=>{o.result&&s.push(o.result),e&&e(s)}}).finally(()=>{ae.instance().closeDatabase()})}};p(Ct,"_instance");let Yi=Ct;const Ae=new d.Vector3(1,0,0),ds=new d.Vector3(0,1,0),Et=new d.Vector3(0,0,1),Cr=new d.Vector3(0,0,0),ct=16777215,th="CONTINUOUS",Ei=new d.PointsMaterial({color:ct}),le=new d.LineBasicMaterial({color:ct}),_t=new d.MeshBasicMaterial({color:ct}),Sr=new d.BufferGeometry().setFromPoints([new d.Vector3]),Or=new d.Matrix4,Fe=new d.Matrix4,ne=new d.Matrix4,j=new d.Vector3,Z=new d.Vector3,ze=new d.Vector3,Qt=new d.Vector2,he=new d.Quaternion,_i=new d.Object3D,We=new d.Box3,Er=new d.PointsMaterial({color:65280,size:5,depthTest:!1}),_r=new d.PointsMaterial({color:65280,depthTest:!1}),Pr=new d.PointsMaterial({color:65280,depthTest:!1}),ih=h=>h.viewDirectionFromTarget!==void 0,sh=h=>{if(h){const t=h.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);if(t&&t.length>0){const e=t[1],i=h.replace("data:"+e+";","").split(",");if(i&&i.length===2&&i[0]==="base64"){const s=i[1];return qa.decode(s)}}}return null},Ar=(h,t)=>{const e=new d.Vector2(h.x,h.y),i=new d.Vector2(t.x,t.y);return i.sub(e),i.normalize(),i.y<0?-Math.acos(i.x):Math.acos(i.x)},Ir=(h,t,e)=>({x:h.x+t*Math.cos(e),y:h.y+t*Math.sin(e)}),rh=(h,t,e,i)=>{const s=h?new d.Vector2(h.x,h.y):new d.Vector2(0,0),r=t?new d.Vector2(t.x,t.y):new d.Vector2(1,0);e=e||1;const n=4*Math.atan(e),a=s.distanceTo(r)/2/Math.sin(n/2),o=Ir(h,a,Ar(s,r)+(Math.PI/2-n/2));i=i||Math.max(Math.abs(Math.ceil(n/(Math.PI/18))),6);const l=Ar(o,s),c=n/i,u=[];u.push(new d.Vector3(s.x,s.y,0));for(let f=1;f<=i-1;f++){const m=Ir(o,Math.abs(a),l+c*f);u.push(new d.Vector3(m.x,m.y,0))}return u},kr=(h,t,e,i=h.length*2,s)=>{const r=[];if(!h||h.length<t+1||t<1)return r;const n=h.map(a=>[a.x,a.y]);try{for(let a=0;a<1;a+=1/i){const o=mn(a,t,n,e,s);r.push(new d.Vector3(o[0],o[1],0))}}catch{if(r.length===0)return r}return r},us=(h,t=!1)=>{const e=[],i=h.length;for(let s=0;s<i;s++){const r=h[s];if(r.bulge&&(s!==i-1||t)){const n=r.bulge,a=s+1<i?h[s+1]:e[0],o=rh(r,a,n);e.push(...o)}else e.push(new d.Vector3(r.x,r.y,0))}return e},nh=h=>{const t=[];return h.faceA&&t.push(h.faceA),h.faceB&&t.push(h.faceB),h.faceC&&t.push(h.faceC),h.faceD&&t.push(h.faceD),t},ah=h=>{const t=[],e=[];h.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new d.Vector3(s.x,s.y,s.z)):e.push(nh(s)))});const i=[];for(let s=0;s<e.length;s++){const r=e[s];if(r.length===0)continue;const n=[];let a=!0;for(let o=0;o<r.length;o++){const l=r[o]-1;if(l>=t.length||l<0){a=!1;break}n.push(t[l])}!a||n.length===0||(n.push(n[0]),i.push(n))}return i},V=class V extends d.Loader{constructor(e,i){super(e);p(this,"timer");p(this,"ignorePaperSpace");p(this,"font");p(this,"encoding");p(this,"overrideColor");p(this,"overrideHatchPatternLineThickness");p(this,"angBase");p(this,"angDir");p(this,"header");p(this,"pointsMaterials");p(this,"lineBasicMaterials");p(this,"lineShaderMaterials");p(this,"meshBasicMaterials");p(this,"meshTextureMaterials");p(this,"hatchShaderMaterials");p(this,"entityCount");p(this,"curveCount");p(this,"averageCurveSize");p(this,"enableRenderOrder");p(this,"enableLocalCache");p(this,"enableReleaseData");p(this,"enableMerge");p(this,"enableRTC");p(this,"enablePlineWidth");p(this,"dxfDataId");p(this,"compareContext");p(this,"statsInfo");p(this,"llbDatas");p(this,"mtextDatas");p(this,"requestHeader");p(this,"blockReferencesCache");p(this,"blockRecordsCache");p(this,"entitiesCache");p(this,"blocksCache");p(this,"dictionaryOwnerHandleAndSpatialFilterHandlesCache");p(this,"spatialFiltersCache");p(this,"entityThreejsCache");p(this,"entityTypesAndTimes");p(this,"nonSnapableTypes");p(this,"layoutsSnapObjectsMap");p(this,"aborted");p(this,"entityHandlesWithRenderOrder");p(this,"addViewport");this.timer=Date.now(),this.ignorePaperSpace=!1,this.encoding="UTF-8",this.angBase=0,this.angDir=0,this.header=void 0,this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[],this.entityCount=0,this.curveCount=0,this.averageCurveSize=0,this.enableRenderOrder=!1,this.enableLocalCache=!1,this.enableReleaseData=!0,this.enableMerge=!0,this.enableRTC=!0,this.enablePlineWidth=!0,this.dxfDataId=void 0,this.compareContext=void 0,this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0,requestHeader:{}},this.llbDatas=[],this.mtextDatas=[],this.blockReferencesCache={},this.blockRecordsCache=void 0,this.entitiesCache=void 0,this.blocksCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.nonSnapableTypes=new Set(["ATTDEF","ATTRIB","LEADER","MTEXT","MULTILEADER","OLE2FRAME","TEXT"]),this.layoutsSnapObjectsMap={},this.aborted=!1,this.entityHandlesWithRenderOrder={},this.addViewport=(s,r)=>{if(s.type==="VIEWPORT"){!r[s.ownerHandle]&&(r[s.ownerHandle]=[]);const n=s;r[s.ownerHandle].push(n)}},i&&(this.ignorePaperSpace=i.ignorePaperSpace===!0,this.enableLocalCache=i.enableLocalCache===!0,this.enableMerge=V.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.overrideColor!=null&&(this.overrideColor=qt.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[ct]=Ei,this.lineBasicMaterials[ct]=le,this.meshBasicMaterials[ct]=_t}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=sh(e);if(!s){const r=Date.now(),n=new d.FileLoader(this.manager),a=V.REQUWSTHEADER;a&&n.setRequestHeader(a),n.setResponseType("arraybuffer"),n.setPath(this.path),s=await n.loadAsync(e,i),S.info("[Dxf] "+e+" dxf file downloaded in "+(Date.now()-r)/1e3+"s")}return s}async loadEx(e,i,s){return this.enableLocalCache&&i&&(i=i.trim()).length>0&&(this.dxfDataId=i),this.loadAsync(e,s)}async loadAsync(e,i){const s=z.getUpdateSubProgressFunc(0,50,i),r=z.getUpdateSubProgressFunc(50,100,i),n=z.getUpdateSubProgressFunc(10,100,i);if(be.isBrowser&&this.enableLocalCache&&this.dxfDataId){let l;try{if(this.timer=Date.now(),l=await this.getDxfDataFromIndexedDb(this.dxfDataId),l){this.tryFixDxfData(l),S.info("[Dxf] Loaded DxfData from indexedDb in "+(Date.now()-this.timer)/1e3+"s");const c=await this.loadEntities(l,n);return Promise.resolve(c)}}catch(c){S.warn("[Dxf] Failed to parse data from indexedDb",c)}}const a=await this.parse(e,s);return this.tryFixDxfData(a),await this.loadEntities(a,r)}async parse(e,i){const s=z.getUpdateProgressFunc(i),r=z.getUpdateSubProgressFunc(0,40,i),n=await this.download(e,r);if(!n)return Promise.reject("[Dxf] Failed to download "+e);if(this.aborted)return Promise.reject("[Dxf] Job aborted");this.timer=Date.now(),S.info("[Dxf] Start parsing...");const a=new Tn(this.encoding).parseSync(n);if(this.tryFixDxfData(a),s(80),S.info("[Dxf] Parsed in "+(Date.now()-this.timer)/1e3+"s, creating entities..."),this.aborted)return Promise.reject("[Dxf] Job aborted");if(a&&be.isBrowser&&this.enableLocalCache&&this.dxfDataId){const o=Date.now();try{await this.setDxfDataToIndexedDb(this.dxfDataId,a),S.info("[Dxf] Saved to indexedDb in "+(Date.now()-o)/1e3+"s")}catch(l){S.warn("[Dxf] Failed to save '"+this.dxfDataId+"' to indexedDb!",l)}}return s(100),a}abort(){this.aborted=!0}isAborted(){return this.aborted}parseHeader(e){if(!e){S.error("[Dxf]: Invalid header!");return}this.header=e;const i=e.$ACADVER.toString();i!=="AC1032"&&S.warn("[Dxf] Unexpected version: "+i+". But we'll try to continue."),this.angBase=e.$ANGBASE||0,this.angDir=e.$ANGDIR||0}tryFixDxfData(e){e&&(!e.objects&&(S.warn("[Dxf] No objects found, Will add one."),e.objects={}),!e.objects.LAYOUT&&(S.warn("[Dxf] No layout defined! Will add a default 'Model' layout!"),e.objects.LAYOUT=[{layoutName:V.MODEL_LAYOUT_NAME}]),!e.tables&&(S.warn("[Dxf] No tables found, Will add one."),e.tables={}),!e.tables.layer&&(e.tables.layer={}),!e.tables.layer.layers&&(e.tables.layer.layers={}))}async loadEntities(e,i){const s=Date.now();this.parseHeader(e.header),this.enableRenderOrder&&(this.initRenderOrderInfo(e),this.enableMerge=!1),this.getFontFilesFromDxf(e);let r=0;const n=e.entities.length;this.entityCount=n,Object.keys(e.blocks).forEach(b=>{this.entityCount+=e.blocks[b].entities?.length||0});const a=z.getUpdateProgressFuncForLoop(n,i);let o={};const l=b=>{const E=b.userData.layerName;let O=o[E];!O&&(O=[],o[E]=O),O.push(b)},c={},u={},f=new F;for(let b=0;b<n&&!this.aborted;b++){const E=e.entities[b];this.addViewport(E,c);const O=this.loadEntity(E,e);if(!O&&await a(b),!O)continue;const _=this.getLayout(e,E),C=_.layoutName;let w=f.children.find(M=>M.name===C);if(!w&&(w=new F,w.name=C,w.userData.isLayoutLevelObject=!0,f.add(w)),O.traverse(M=>{M.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[C]&&(this.layoutsSnapObjectsMap[C]=[]),this.layoutsSnapObjectsMap[C].push(M))}),this.enableMerge){et.merge(O,!1),!u[C]&&(u[C]={object:w,layerObjects:{}});const P=u[C];if(O.geometry){const A=O.userData.layerName;!P.layerObjects[A]&&(P.layerObjects[A]=[]),P.layerObjects[A].push(O),O.children.forEach(I=>{I.userData.isSnapObject&&l(I)})}else O.children.length>0&&(w.add(O),O.traverse(A=>{A.geometry&&l(A)}))}else w.add(O),O.traverse(M=>{M.geometry&&l(M)});r++,await a(b)}e.objects.LAYOUT.forEach(b=>{const E=b,O=E.layoutName;if(this.ignorePaperSpace&&O!==V.MODEL_LAYOUT_NAME)return;const _=E.associatedBlockName,C=e.blocks[_];C&&this.loadLayout(C,e,E,f,o,c)}),S.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const b in this.layoutsSnapObjectsMap){const E=f.children.find(C=>C.name===b),O=new F;O.name=V.SNAP_GROUP_NAME,O.userData.isSnapGroup=!0,E.add(O);const _=this.layoutsSnapObjectsMap[b];for(let C=0;C<_.length;C++){const w=_[C],M=w.userData.layerName;this.getLayerVisible(e,M)===!1&&w.layers.disable(Ce),V.SHOW_SNAP_OBJECT&&(w.layers.enableAll(),w.material instanceof d.PointsMaterial?w.material=Er:w.material instanceof d.LineBasicMaterial?w.material=_r:w.material instanceof d.MeshBasicMaterial&&(w.material=Pr));let P=w;const A=ne.identity();for(;P&&P.userData.isLayoutLevelObject!==!0;)A.premultiply(P.matrix),P=P.parent;w.matrix.copy(A),O.add(w)}}if(this.enableMerge)for(const b in u){const E=u[b],O=E.object;for(const _ in E.layerObjects){const C=E.layerObjects[_],w=et.deepMerge(C,void 0,!1,!1,!0),M=w.added,P=w.removed;if(P.length!==C.length){let A=P;P.length>=100&&(A=new Set(P));const I=k=>Array.isArray(A)?A.indexOf(k)>=0:A.has(k);for(let k=0,B=C.length;k<B;k++){const L=C[k];!I(L)&&(O.add(L),l(L))}}for(let A=0;A<M.length;A++){const I=M[A];O.add(I),l(I)}E.layerObjects[_]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&V.mergeDxfObjects({root:f,layersAndObjects:o});const g=f.convertToThreejsObject();f.clear(),o={};const x={};e.objects.LAYOUT.forEach(b=>{const E=b;x[E.layoutName]=E});const y={},T=b=>{const E=b.userData.layerName;let O=y[E];!O&&(O=[],y[E]=O),O.push(b)};g.children.forEach(b=>{if($.setSharedVariablesOfObject(b),!b.userData.isLayoutLevelObject)return;const E=b.name;let O;if(E!==V.MODEL_LAYOUT_NAME){const _=x[E];!_.directAssociatedLeafObjectSet&&(_.directAssociatedLeafObjectSet=new Set),O=_.directAssociatedLeafObjectSet}b.traverse(_=>{if($.setSharedVariablesOfObject(_),_.userData.isSnapGroup&&(_.visible=V.SHOW_SNAP_OBJECT),_.geometry){const C=_.userData.layerName;this.getLayerVisible(e,C)===!1&&(_.visible=!1,_.userData.layerVisible=!1),T(_),O&&O.add(_)}})}),S.info("[Dxf] loadEntities() done in "+(Date.now()-s)/1e3+"s");const v=Object.assign(Object.assign({},e),{threejsObject:g,layersAndThreejsObjects:y,loadedEntityCount:r,layoutViewportsMap:c});if(V.LOADLLDATA){const b=g.children[0].children,E=[];for(let O=0;O<b.length;O++){const _=b[O];if(_?.userData?.llbData){const C=new d.Box3().setFromObject(_);C.getSize(new d.Vector3);const w=C.getCenter(new d.Vector3);E.push({..._,boundingBox:{max:C.max,min:C.min,center:w}})}else if(_.children&&_.children.some(C=>C.userData?.llbData))for(let C=0;C<_.children.length;C++){const w=_.children[C];if(w.userData?.llbData){w.updateWorldMatrix(!0,!0);const M=new d.Box3().setFromObject(w);M.getSize(new d.Vector3);const P=M.getCenter(new d.Vector3);E.push({...w,boundingBox:{max:M.max,min:M.min,center:P}})}}}v.llbMesh=E}return Promise.resolve(v)}getFontFilesFromDxf(e){const i=new Set,s=e.tables?.style?.styles;if(s)for(const r in s){const n=s[r],a=n.fontFile,o=n.bigFontFile;a&&i.add(a),o&&i.add(o)}S.info("[Dxf] Fonts used by dxf: "+Array.from(i).join())}async loadEntitiesForCompare(e,i,s,r=!0,n){const a=e.entities.length,o=i.entities.length,l=async()=>{const u=this.compareContext,f=u.isTheFirstFile,m=f?e:i,g=new F,x=f?a:o;this.entityCount=x,Object.keys(m.blocks).forEach(w=>{this.entityCount+=m.blocks[w].entities?.length||0});const y=Math.round(Math.pow(x,.5));let T=Date.now();const v=async w=>{if(n&&(w%y===0||w===x-1)){let M=w+1;!f&&(M+=a),n(new ProgressEvent("parseProgress",{loaded:M,total:a+o}));const P=500,A=Date.now();(A-T>P||w===x-1)&&(await z.sleep(0),T=A)}};this.parseHeader(m.header);let b={};for(let w=0;w<x;w++){if(this.aborted)return;const M=m.entities[w],P=this.getLayout(m,M);if(P.layoutName!==V.MODEL_LAYOUT_NAME){await v(w);continue}const A=this.loadEntity(M,m);if(!A){await v(w);continue}let I=g.children.find(k=>k.name===V.MODEL_LAYOUT_NAME);!I&&(I=new F,I.name=V.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,g.add(I)),I.add(A),A.traverse(k=>{if(k.geometry){const B=k.userData.layerName,L=this.getLayerVisible(m,B);k.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[P.layoutName]&&(this.layoutsSnapObjectsMap[P.layoutName]=[]),this.layoutsSnapObjectsMap[P.layoutName].push(k),L===!1&&A.layers.disable(Ce));let q=b[B];!q&&(q=[],b[B]=q),q.push(k)}}),await v(w)}r&&f&&!u.preservedHandles&&(u.preservedHandles=new Set);for(const w in s){const M=s[w];f&&(M.type===Te.Added||M.type===Te.Modified)&&(u.preservedHandles?.add(M.handle),M.parentHandles&&M.parentHandles.forEach(A=>u.preservedHandles?.add(A)));let P=this.entityThreejsCache&&this.entityThreejsCache[M.handle];if(M.parentHandles&&(P=this.entityThreejsCache&&this.entityThreejsCache[M.parentHandles[M.parentHandles.length-1]]),P){if(P.parent&&P.parent.userData.originalType){this.setObjectColorByChange(P,{type:Te.NoChange});continue}P=this.setObjectColorByChange(P,M)}if(M.type!==Te.NoChange&&P){let A=P.parent;const I=ne.identity();for(;A&&A.userData.isLayoutLevelObject!==!0;)I.premultiply(A.matrix),A=A.parent;We.makeEmpty();const k=F.getBox(P,We);k.applyMatrix4(I),M.type===Te.Added?!f&&(M.box=new d.Box3().copy(k)):M.type===Te.Removed?f&&(M.box=new d.Box3().copy(k)):M.type===Te.Modified&&(M.box?M.box.union(k):M.box=new d.Box3().copy(k))}}for(const w in this.layoutsSnapObjectsMap){const M=g.children.find(I=>I.name===w),P=new F;P.name=V.SNAP_GROUP_NAME,M.add(P);const A=this.layoutsSnapObjectsMap[w];for(let I=0;I<A.length;I++){const k=A[I];V.SHOW_SNAP_OBJECT&&(k.layers.enableAll(),k.material instanceof d.PointsMaterial?k.material=Er:k.material instanceof d.LineBasicMaterial?k.material=_r:k.material instanceof d.MeshBasicMaterial&&(k.material=Pr));let B=k;const L=ne.identity();for(;B&&B.userData.isLayoutLevelObject!==!0;)L.premultiply(B.matrix),B=B.parent;k.matrix.copy(L),P.add(k)}}this.enableMerge&&V.mergeDxfObjects({root:g,layersAndObjects:b});const E=g.convertToThreejsObject();g.clear(),b={};const O={},_=w=>{const M=w.userData.layerName;let P=O[M];!P&&(P=[],O[M]=P),P.push(w)};E.children.forEach(w=>{$.setSharedVariablesOfObject(w),w.userData.isLayoutLevelObject&&w.traverse(M=>{if($.setSharedVariablesOfObject(M),M.userData.isSnapGroup&&(M.visible=V.SHOW_SNAP_OBJECT),M.geometry){const P=M.userData.layerName;this.getLayerVisible(m,P)===!1&&(M.visible=!1,M.userData.layerVisible=!1),_(M)}})});const C=m;C.threejsObject=E,C.layersAndThreejsObjects=O,C.layoutViewportsMap={}};let c=Date.now();this.compareContext={changes:s,isTheFirstFile:!0},z.printMemory("Before loading entities for first dxf"),await l(),S.info("[Dxf] loadEntities for first dxf in "+(Date.now()-c)/1e3+"s"),z.printMemory("After loading entities for first dxf"),this.releaseCachedData(!1),this.releaseDxfData(e),z.printMemory("Before loading entities for second dxf"),c=Date.now(),this.compareContext.isTheFirstFile=!1,await l(),S.info("[Dxf] loadEntities for second dxf in "+(Date.now()-c)/1e3+"s"),this.printStatsInfo();for(const u of Object.values(s))!u.box&&delete s[u.id];this.compareContext.preservedHandles=void 0,this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(i)),z.printMemory("After loading entities for second dxf")}setObjectColorByChange(e,i){const s=a=>{let o=Ue.ENTITY_COLOR_NO_CHANGE;return a.type===Te.Added?o=Ue.ENTITY_COLOR_ADDED:a.type===Te.Removed?o=Ue.ENTITY_COLOR_REMOVED:a.type===Te.Modified&&(o=this.compareContext?.isTheFirstFile?Ue.ENTITY_COLOR_REMOVED:Ue.ENTITY_COLOR_ADDED),o},r=(a,o)=>{a.traverse(l=>{if(l.material){if(l.material instanceof d.LineBasicMaterial)l.material=this.getLineBasicMaterial(o);else if(l.material instanceof d.MeshBasicMaterial)l.material=this.getMeshBasicMaterial(o);else if(l.material instanceof d.PointsMaterial)l.material=this.getPointsMaterial(o);else if(l.material instanceof d.ShaderMaterial){const c=l.material.clone();V.updateMaterialUniforms(c),c.uniforms.u_color.value.set(o),l.material=c}}})},n=s(i);return e.traverse(a=>{i.parentHandles?a.userData&&a.userData.handle&&a.userData.handle===i.handle&&(r(a,n),e=a):r(a,n)}),e}releaseCachedData(e=!0){e&&(this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[]),this.header=void 0,this.blockReferencesCache={},this.blockRecordsCache=void 0,this.blocksCache=void 0,this.entitiesCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.entityHandlesWithRenderOrder={},this.layoutsSnapObjectsMap={},this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0}}releaseEntity(e){e.vertices&&(e.vertices=void 0),e.knotValues&&(e.knotValues=void 0),e.controlPoints&&(e.controlPoints=void 0),e.binaryData&&(e.binaryData=void 0),e.text&&(e.text=void 0),e.extendedData&&(e.extendedData=void 0),e.contextData&&(e.contextData=void 0);const i=e;i.boundaryPaths&&(i.boundaryPaths=[]),i.patternLines&&(i.patternLines=void 0)}releaseDxfData(e){delete e.objects.DICTIONARY,delete e.objects.SORTENTSTABLE,delete e.objects.XRECORD,e.tables&&(delete e.tables.dimStyle,delete e.tables.lineType,delete e.tables.style,delete e.tables.blockRecord),e.entities=[],e.blocks={}}loadEntity(e,i,s,r=!1){if(this.compareContext&&this.compareContext.preservedHandles&&this.compareContext.preservedHandles.has(e.handle)&&oi.includes(e.type)&&(r=!0),!r&&this.compareContext&&this.compareContext.preservedHandles&&!oi.includes(e.type)&&!this.compareContext.preservedHandles.has(e.handle)&&(!s||s&&!this.compareContext.preservedHandles.has(s.handle)))return;if(this.getLayerFrozen(i,e)===!0){const m=e.layer;return!this.statsInfo.ignoredFrozenLayersAndEntityCount[m]&&(this.statsInfo.ignoredFrozenLayersAndEntityCount[m]=0),this.statsInfo.ignoredFrozenLayersAndEntityCount[m]++,void 0}if(e.visible===!1||e.invisible)return!this.statsInfo.invisibleEntities[e.type]&&(this.statsInfo.invisibleEntities[e.type]=0),this.statsInfo.invisibleEntities[e.type]++,void 0;if(this.ignorePaperSpace&&e.inPaperSpace)return!this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]&&(this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]=0),this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]++,void 0;!this.entityThreejsCache&&(this.entityThreejsCache={});const a=Date.now();let o,l=!1;if(!this.compareContext&&this.entityThreejsCache[e.handle])o=this.entityThreejsCache[e.handle].clone(),l=!0;else if(!this.statsInfo.unsupportedEntity[e.handle]){const m=e.isTable;if(e.type==="CIRCLE"||e.type==="ARC")o=this.loadArc(e,i,s);else if(e.type==="LINE"||e.type==="POLYLINE")o=this.loadLine(e,i);else if(e.type==="XLINE")o=this.loadXLine(e);else if(e.type!=="SEQEND"){if(e.type==="RAY")o=this.loadRay(e);else if(e.type==="LWPOLYLINE")o=this.loadLWPolyline(e,i,s);else if(e.type==="3DFACE")o=this.load3DFace(e);else if(e.type==="TEXT")o=this.loadText(e,i,s);else if(e.type==="SOLID")o=this.loadSolid(e,i,s);else if(e.type==="POINT")o=this.loadPoint(e,i,s);else if(e.type==="IMAGE")o=this.loadImage(e,i,s);else if(e.type==="INSERT")o=this.loadInsert(e,i,s,r);else if(e.type==="SPLINE")o=this.loadSpline(e,s);else if(e.type==="MTEXT")m?o=this.loadTableMText(e,i,s):o=this.loadMText(e,i,s);else if(e.type==="ELLIPSE")o=this.loadEllipse(e,i,s);else if(e.type==="DIMENSION")o=this.loadDimension(e,i);else if(e.type!=="REGION")if(e.type==="ATTDEF")o=this.loadAttDef(e,i,s);else if(e.type==="ATTRIB"){if(!s)for(let g=0;g<i.entities.length;g++){const x=i.entities[g];if(e.ownerHandle===x.handle&&(s=x,s.attributesFollow))break}o=this.loadAttrib(e,i,s)}else e.type==="HATCH"?o=this.loadHatch(e,i,s):e.type==="VIEWPORT"?o=this.loadViewport(e,i,s):e.type==="LEADER"?o=this.loadLeader(e,i,s):e.type==="MULTILEADER"?o=this.loadMLeader(e,i,s):e.type==="OLE2FRAME"?o=this.loadOle2frame(e,i):e.type==="ACAD_TABLE"&&(o=this.loadTable(e,i))}o&&(this.entityThreejsCache[e.handle]=o),this.enableReleaseData&&!this.compareContext&&this.releaseEntity(e)}if(o){const m=this.getLayerName(e,i,s);o.userData.handle=e.handle,e.type!=="INSERT"&&e.type!=="DIMENSION"&&o.traverse(g=>{g.geometry&&(g.userData.layerName=m,g.userData.handle=e.handle,g.userData.dxfType=e.type,this.setMaterial(g,e,i,s))}),!l&&(this.nonSnapableTypes.has(e.type)&&o.traverse(g=>{g.layers.disable(Ce)}),this.enableRenderOrder&&(this.entityHandlesWithRenderOrder[e.handle]?o.renderOrder=parseInt(this.entityHandlesWithRenderOrder[e.handle],16)+.1:o.renderOrder=parseInt(e.handle,16)))}const c=e.type,u=e.handle,f=oi.includes(c);if(!f){this.entityTypesAndTimes||(this.entityTypesAndTimes={}),this.entityTypesAndTimes[c]||(this.entityTypesAndTimes[c]={createCount:0,totalTime:0,averageTime:0});const m=this.entityTypesAndTimes[c];m.createCount++,m.totalTime+=Date.now()-a}return o?this.statsInfo.entityTypesAndMeshCount[c]?this.statsInfo.entityTypesAndMeshCount[c]++:this.statsInfo.entityTypesAndMeshCount[c]=1:(this.statsInfo.unsupportedEntityTypes[c]?this.statsInfo.unsupportedEntityTypes[c]++:this.statsInfo.unsupportedEntityTypes[c]=1,f||(this.statsInfo.unsupportedEntity[u]?this.statsInfo.unsupportedEntity[u]++:this.statsInfo.unsupportedEntity[u]=1)),o}loadEllipse(e,i,s){if(!e.majorAxisEndPoint||!e.center||e.axisRatio===void 0||e.startAngle===void 0||e.endAngle===void 0)return;let r=e.startAngle,n=e.endAngle;if(e.extrusionDirection&&e.extrusionDirection.z<0&&(r=Math.PI*2-e.endAngle,n=Math.PI*2-e.startAngle),R.areNumbersEqual(r,n,1e-5))return S.warn("[Dxf] Ellipse entity (handle '%s') contains the same start and end angle, ignored!",e.handle),void 0;let a=n-r;for(;a>Math.PI*2;)a-=Math.PI*2;Math.abs(a)<=1e-5&&(n=R.floorNumber(r+Math.PI*2,5));const o=Math.sqrt(Math.pow(e.majorAxisEndPoint.x,2)+Math.pow(e.majorAxisEndPoint.y,2)),l=o*e.axisRatio,c=Math.atan2(e.majorAxisEndPoint.y,e.majorAxisEndPoint.x),u=new d.EllipseCurve(e.center.x,e.center.y,o,l,r,n,!1,c);let f=1;const m=s;m?.xScale&&m?.yScale&&(f=Math.max(Math.abs(m.xScale),Math.abs(m.yScale)));const g=this.getDivision(r,n,Math.max(o,l)*f),x=u.getPoints(g),y=[],T=x.length;for(let C=0;C<T-1;C++)R.areVector2sEqual(x[C],x[C+1],1e-9)||y.push(x[C]);if(y.push(x[T-1]),y.length<2)return S.warn("[Dxf] Ellipse entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const v=new d.Vector3;let b=!1;this.enableRTC&&(b=U.checkAndRebasePositionsOnRTC(y,v));const E=new d.BufferGeometry().setFromPoints(y),O=new F(H.Line);O.geometry=E,O.material=le;const _=new F(H.Point);return _.geometry=Sr,_.material=Ei,_.matrix.setPosition(e.center.x,e.center.y,e.center.z),_.userData.isSnapObject=!0,_.userData.type="CircleCenter",_.layers.set(Ce),O.add(_),b&&(this.setRTCUserData(O),O.matrix.setPosition(v.x,v.y,0)),O.layers.enableAll(),O}loadMText(e,i,s){if(!e.text)return;if(!this.font)return S.info("[Dxf] Font file not set, ignoring text entity."),void 0;const r=this.getTextStyle(i,e),n=li(e.text,{encoding:this.getTextEncoding(r)}),a=this.getMTextGroup(n,e,r,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(Z,he,ze),e.position&&(Z.x+=e.position.x,Z.y+=e.position.y,o.matrix.compose(Z,he,ze)),We.makeEmpty();const l=F.getBox(o,We),c=l.getSize(j),u=e.width||c.x,f=e.height||c.y,m=e.lineSpaceFactor||1.657,g=e.text;let x=0,y=0;switch(document.createElement("canvas").getContext("2d"),e.attachmentPoint){case 1:x=0,y=0;break;case 2:x-=u/2,y=0;break;case 3:x-=u,y=0;break;case 4:x=0,y+=f/2;break;case 5:x-=u/2,y+=f/2;break;case 6:x-=u,y+=f/2;break;case 7:x=0;const k=g.split("\\P").length-1;k>0?y+=f*(k+1)+f*m*.8*k:y+=f;break;case 8:x-=u/2,y+=f;break;case 9:x-=u,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=f;break;case 4:break;case 5:const I=g.split("\\P");let k=0;I>1&&(k=I-1),k>1?y+=f*(k-1):y-=f/4;break;default:return}o.traverse(I=>{I.geometry&&I.geometry.translate(x,y,0),I.layers.enableAll()});let v=0;if(e.rotation&&(v=e.rotation*Math.PI/180),e.directionVector){const I=e.directionVector,k=new d.Vector3(I.x,I.y,I.z),B=k.clone().cross(Ae),L=Ae.angleTo(k);v=B.z>0?-L:L}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(o),o.matrix.compose(Z,he,ze);const b=e.position?Z.clone().sub(e.position):Z;Fe.makeTranslation(-b.x,-b.y,0),ne.makeRotationZ(v),o.matrix.multiply(Fe),o.matrix.multiply(ne),o.matrix.multiply(Fe.invert()),o.userData||(o.userData={});const E=o.matrix.elements,O=E&&E[12]||0,_=E&&E[13]||0,C=E&&E[14]||0,w=new d.Box3;F.getBox(o,w);const M=new d.Vector3;w.getCenter(M);const P=new d.Vector3;w.getSize(P),o.userData.renderArea={position:{x:O,y:_,z:C},bbox:{min:{x:w.min.x,y:w.min.y,z:w.min.z},max:{x:w.max.x,y:w.max.y,z:w.max.z},center:{x:M.x,y:M.y,z:M.z},width:P.x,height:P.y,depth:P.z},textSize:{width:u,height:f},rotation:v,attachmentPoint:e.attachmentPoint||0,drawingDirection:e.drawingDirection||0};const A=this;return o.userData.textContent=e.text||"",o.userData.cleanText=A.cleanMTextContent?A.cleanMTextContent(e.text):e.text,o.userData.dxfType="MTEXT",o.userData.isMText=!0,o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",o.traverse(I=>{I.geometry&&(I.userData.textContent=e.text||"",I.userData.dxfType="MTEXT",I.userData.layer=e.layer||"0",I.userData.handle=e.handle||"")}),o.userData.entityId=e.entityId||e.handle,o}loadTableMText(e,i,s){if(!e.text)return;if(!this.font)return S.info("[Dxf] Font file not set, ignoring text entity."),void 0;const r=this.getTextStyle(i,e),n=li(e.text,{encoding:this.getTextEncoding(r)}),a=this.getMTextGroup(n,e,r,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(Z,he,ze),e.position&&(Z.x+=e.position.x,Z.y+=e.position.y,o.matrix.compose(Z,he,ze)),We.makeEmpty();const l=F.getBox(o,We),c=l.getSize(j),u=e.width||c.x,f=e.height||c.y,m=e.lineSpaceFactor||1.657,g=e.text;let x=0,y=0;switch(e.attachmentPoint){case 1:x=0,y=0;break;case 2:x-=u/2,y=0;break;case 3:x-=u,y=0;break;case 4:x=0,y+=f/2;break;case 5:x-=u/2,y+=f/2;break;case 6:x-=u,y+=f/2;break;case 7:x=0;const E=g.split("\\P").length-1;E>0?y+=f*(E+1)+f*m*.8*E:y+=f;break;case 8:x-=u/2,y+=f;break;case 9:x-=u,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=f;break;case 4:break;case 5:break;default:return}o.traverse(b=>{b.geometry&&b.geometry.translate(x,y,0),b.layers.enableAll()});let T=0;if(e.rotation&&(T=e.rotation*Math.PI/180),e.directionVector){const b=e.directionVector,E=new d.Vector3(b.x,b.y,b.z),O=E.clone().cross(Ae),_=Ae.angleTo(E);T=O.z>0?-_:_}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(o),o.matrix.compose(Z,he,ze);const v=e.position?Z.clone().sub(e.position):Z;return Fe.makeTranslation(-v.x,-v.y,0),ne.makeRotationZ(T),o.matrix.multiply(Fe),o.matrix.multiply(ne),o.matrix.multiply(Fe.invert()),o}getMTextGroup(e,i,s,r,n,a=0,o=0,l=[]){if(e.length===0)return;let c=i.height||i.contextData&&i.contextData.textHeight||0;if(i.textStyle){if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const O=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[O]&&(this.statsInfo.unsupportedTextStyles[O]=0),this.statsInfo.unsupportedTextStyles[O]++}c=c||s.textHeight}let u="Left";i.width&&i.attachmentPoint&&([1,4,7].includes(i.attachmentPoint)?u="Left":[2,5,8].includes(i.attachmentPoint)?u="Center":[3,6,9].includes(i.attachmentPoint)&&(u="Right"));const f=i.width||0,m=new F;let g,x=s.fontFile,y=1,T=1,v=256,b=c*.8,E=b+c;for(let O=0;O<e.length;O++){const _=e[O];if(typeof _=="string"){const C=[],w=A=>{let I;if(A.forEach((k,B)=>{!k.boundingBox&&k.computeBoundingBox(),B===0?I=k.boundingBox:I.union(k.boundingBox)}),I){const k=I.getSize(j);switch(u){case"Left":break;case"Center":A.forEach(B=>B.translate((f-k.x)/2,0,0));break;case"Right":A.forEach(B=>B.translate(f-k.x,0,0));break}}C.push(...A)};let M;for(let A=0;A<_.length;A++){const I=_[A];if(I===`
794
+ `){a=0,o-=E,l.length>0&&w(l),l=[];continue}if(b=c*.8,E=b+c,M=this.font?.getCharShape(I,x,c),s.bigFontFile&&!M&&(M=this.font?.getCharShape(I,s.bigFontFile,c)),!M&&(M=this.font?.getCharShape(I,"",c)),!M&&(M=this.font?.getNotFoundTextShape(c)),!M){a+=c+T*(c/3.5);continue}a>(f||1/0)&&(l.length>0&&w(l),a=0,o-=E,l=[]),M.translate(a,o,0),M.scale(y,1,1),M.boundingBox||M.computeBoundingBox(),_.T&&(T=_.T);const k=Uo(I,M,c,T,x);a+=k,l.push(M)}l.length>0&&(w(l),l=[]);const P=new F;if(C.length>0){!g&&(g=i.colorIndex),v!==void 0&&v!==256?(i.color=Nt(v),i.colorIndex=v):i.colorIndex=g;const A=this.getColor(i,r,n),I=C.filter(B=>B instanceof d.ExtrudeGeometry),k=C.filter(B=>!(B instanceof d.ExtrudeGeometry));if(I.length>0){const B=new F(H.Mesh);B.geometry=xe.mergeGeometries(I),B.material=this.getMeshBasicMaterial(A),P.add(B)}if(k.length>0){const B=new F(H.LineSegment);B.geometry=xe.mergeGeometries(k),B.material=this.getLineBasicMaterial(A),P.add(B)}}P.matrix.makeTranslation(0,-c,0),m.add(P),y=1,T=1,v=256}else if(Array.isArray(_)){const C=this.getMTextGroup(_,i,s,r,n,a,o,l);C&&(m.add(C.object),a=C.hOffset,o=C.vOffset)}else typeof _=="object"&&(_.f&&(x=_.f,x&&x.includes(".shx")&&S.info("[Dxf] Doesn't support custom fonts: "+x)),_.C&&(v=_.C),_.W&&(_.W[1]==="x"?y=_.W[0]*i.width:y=_.W[0]),_.H&&(_.H[1]==="x"?c=_.H[0]*i.height:c=_.H[0]),_.T&&(T=_.T))}if(m.children.length!==0)return et.merge(m,!1),g&&(i.colorIndex=g),m.children.length===1?{object:m.children[0],hOffset:a,vOffset:o}:{object:m,hOffset:a,vOffset:o}}mtextContentAndFormattingToTextAndStyle(e,i){const s={horizontalAlignment:"",textHeight:i.height||i.contextData&&i.contextData.textHeight},r={};let n=1;const a=[];for(let o=0;o<e.length;o++){const l=e[o];if(typeof l=="string"){if(l.startsWith("\\pxq")&&l.endsWith(";"))l.indexOf("c")!==-1?s.horizontalAlignment="center":l.indexOf("l")!==-1?s.horizontalAlignment="left":l.indexOf("r")!==-1?s.horizontalAlignment="right":l.indexOf("j")!==-1&&(s.horizontalAlignment="justify");else if(!l.startsWith("pi")){if(!l.startsWith("pxt")){if(!l.startsWith("pt")){const c=this.getTextLineNum(l);a.push({font:r.f,colorIndex:r.C,text:l,lineNum:n}),n+=c}}}}else if(Array.isArray(l)){const c=this.mtextContentAndFormattingToTextAndStyle(l,i);c.text.forEach(u=>{a.push(u)}),n=c.lineLength}else if(typeof l=="object")if(l.S&&l.S.length===3){const c=l.S[0]+"/"+l.S[2],u=this.getTextLineNum(c);a.push({text:l.S[0]+"/"+l.S[2],lineNum:n}),n+=u}else l.C!==void 0?r.C=l.C:l.W!==void 0?r.W=l.W:l.H!==void 0?r.H=l.H:l.f!==void 0&&(r.f=l.f)}return{text:a,lineLength:n,style:s}}getTextLineNum(e){const i=e.match(new RegExp("\\n","g"));return i?i.length:0}load3DFace(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=e.vertices.map(o=>new d.Vector3(o.x,o.y,o.z));if(i.length===0)return;!R.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new d.Vector3;let r=!1;this.enableRTC&&(r=U.checkAndRebasePositionsOnRTC(i,s));const n=new d.BufferGeometry().setFromPoints(i),a=new F(H.Line);return a.geometry=n,a.material=le,r&&(this.setRTCUserData(a),a.matrix.setPosition(s.x,s.y,0)),a.layers.enableAll(),a}loadSpline(e,i){if(!e.controlPoints||!e.degreeOfSplineCurve||!e.knotValues)return;if(e.controlPoints.length<e.degreeOfSplineCurve+1)return S.warn("[Dxf] Spline entity (handle '%s') has degree (%s) >= point count (%s), ignored!",e.handle,e.degreeOfSplineCurve,e.controlPoints.length),void 0;let s=1/0,r=1/0,n=-1/0,a=-1/0;for(const v of e.controlPoints)v.x<s&&(s=v.x),v.y<r&&(r=v.y),v.x>n&&(n=v.x),v.y>a&&(a=v.y);let o=1;const l=i;l?.xScale&&l?.yScale&&(o=Math.max(Math.abs(l.xScale),Math.abs(l.yScale)));const c=Math.max(n-s,a-r),u=this.getBSplineInterpolationsPerSplineSegment(e.controlPoints.length,c*o),f=kr(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,u),m=new d.Vector3;let g=!1;this.enableRTC&&(g=U.checkAndRebasePositionsOnRTC(f,m));const x=U.getAdjacentNonRepeatPoints(f);if(x.length<2)return S.warn("[Dxf] Spline entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const y=new d.BufferGeometry().setFromPoints(x),T=new F(H.Line);return T.geometry=y,T.material=le,g&&(this.setRTCUserData(T),T.matrix.setPosition(m.x,m.y,0)),T.layers.enableAll(),T}loadXLine(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=z.arrayOrObjectToVector3(e.directionVector),s=new d.Vector3(e.vertices[0].x,e.vertices[0].y,0),r=[];if(r.push(i.clone().multiplyScalar(-1e6).add(s)),r.push(i.clone().multiplyScalar(1e6).add(s)),r.length===0)return;const n=new d.Vector3;let a=!1;this.enableRTC&&(a=U.checkAndRebasePositionsOnRTC(r,n));const o=new d.BufferGeometry().setFromPoints(r),l=new F(H.Line);return l.geometry=o,l.material=le,a&&(this.setRTCUserData(l),l.matrix.setPosition(n.x,n.y,0)),l.layers.enableAll(),l}loadRay(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=z.arrayOrObjectToVector3(e.directionVector),s=e.vertices.map(l=>new d.Vector3(l.x,l.y,0));if(s.push(i.multiplyScalar(1e6).add(s[0])),s.length===0)return;const r=new d.Vector3;let n=!1;this.enableRTC&&(n=U.checkAndRebasePositionsOnRTC(s,r));const a=new d.BufferGeometry().setFromPoints(s),o=new F(H.Line);return o.geometry=a,o.material=le,n&&(this.setRTCUserData(o),o.matrix.setPosition(r.x,r.y,0)),o.layers.enableAll(),o}loadLine(e,i){if(!e.vertices||e.vertices.length===0){S.warn("[Dxf] Entity is missing vertices:",e.handle);return}let s=[];if(e.isPolyfaceMesh)s=ah(e.vertices);else{const c=us(e.vertices,e.shape);e.shape&&c.length>0&&c.push(c[0]),c.length>0&&(s=[c])}if(s.length===0)return;const r=[];for(let c=0;c<s.length;){const[u,f]=s[c];R.areVector3sEqual(u,f)&&s[c].length<=2?(r.push(u.clone()),s.splice(c,1)):c++}const n=new d.Vector3;let a=!1,o=0;s.forEach(c=>{c.forEach(u=>n.add(u)),o+=c.length}),o>0&&(n.divideScalar(o),a=this.enableRTC&&U.shouldRebasePositionOnRTC(n));let l=null;if(s.length>0){let c=function(v){return Array.isArray(v.pattern)&&v.pattern.length>0};const u=[],f=[];let m=0;s.forEach(v=>{v.forEach(b=>{a?u.push(new d.Vector3(b.x-n.x,b.y-n.y,b.z-n.z)):u.push(b.clone())});for(let b=1;b<v.length;b++)f.push(m+b-1,m+b);m+=v.length});const g=this.getLineType(e,i),x=i.tables?.lineType?.lineTypes?.[g],y=new d.BufferGeometry().setFromPoints(u);let T=le;if(x&&c(x)){let v=function(_){const C=_.attributes.position,w=C.count,M=new Float32Array(w);for(let P=0;P<w;P+=2){const A=P*3,I=(P+1)*3,k=C.array[I]-C.array[A],B=C.array[I+1]-C.array[A+1],L=C.array[I+2]-C.array[A+2],q=Math.sqrt(k*k+B*B+L*L);M[P]=P===0?0:M[P-1],M[P+1]=M[P]+q}_.setAttribute("lineDistance",new d.Float32BufferAttribute(M,1))};const b=x.pattern?.[0]||.5,E=x.pattern?.[1]||.5,O=.1;T=new d.LineDashedMaterial({color:le.color,linewidth:le.linewidth||1,dashSize:b*O,gapSize:E*O,scale:O}),v(y)}else y.setIndex(f);l=new F(H.LineSegment),l.geometry=y,l.material=T}if(r.length>0){a&&U.checkAndRebasePositionsOnRTC(r,n);const c=new d.BufferGeometry().setFromPoints(r),u=new F(H.Point);u.geometry=c,u.material=Ei,l?console.warn("Line has both segments and points – consider using a Group"):l=u}if(l)return a&&(this.setRTCUserData(l),l.matrix.setPosition(n.x,n.y,n.z)),l.layers.enableAll(),l}loadLWPolyline(e,i,s){if(!e.vertices||e.vertices.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const r=[...e.vertices];if(e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0){j.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const g=V.getOcsMatrix(j).invert(),x=e.elevation!==void 0?e.elevation:0;r.forEach(y=>{j.set(y.x,y.y,x).applyMatrix4(g),y.x=j.x,y.y=j.y})}let n=us(r,e.shape);if(e.shape&&n.length>0&&!R.areVector3sEqual(n[0],n[n.length-1])&&n.push(n[0]),n.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}let a=new F;const o=e.extendedData;if(o?.outlines){const g=o.outlines,x=[];g.forEach(v=>{const b=new d.Shape;v.forEach((E,O)=>{O===0?b.moveTo(E[0],E[1]):b.lineTo(E[0],E[1])}),b.closePath(),x.push(new d.ShapeGeometry(b))});const y=xe.mergeGeometries(x),T=new F(H.Mesh);T.geometry=y,T.material=_t,T.layers.enableAll(),T.layers.disable(Ce),a.add(T)}let l=!1;const c=new d.Vector3;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(n,c));const u=U.getAdjacentNonRepeatPoints(n);if(u.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const f=e.constantWidth;if(this.enablePlineWidth){const g=r.some(x=>x.startWidth!==void 0||x.endWidth!==void 0);if(g||f!==void 0&&f>0){let x;const y=i.tables?.lineType?.lineTypes,T=this.getLineType(e,i,s),v=y?.[T];if(!v||!v.pattern||v.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,g?x=this.createTaperedPolylineGeometry(r):x=U.convertWidthLineToMeshGeometry(u,f),!x)S.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const b=new F(H.Mesh);b.geometry=x,b.material=_t,b.layers.enableAll(),b.layers.disable(Ce),a.add(b);const E=$.createOutline(x,le,b.matrix),O=new F(H.LineSegment);O.geometry=E.geometry,O.material=E.material,O.matrix=E.matrix,O.layers.enableAll(),O.layers.disable(Ce),a.add(O)}}}const m=new F(H.Line);return m.geometry=new d.BufferGeometry().setFromPoints(u),m.material=le,m.layers.enableAll(),a.children.length>0?a.add(m):a=m,l&&(this.setRTCUserData(a),a.matrix.setPosition(c)),a}createTaperedPolylineGeometry(e){if(!e||e.length<2)return null;const i=[],s=[],r=[],n=[];for(let l=0;l<e.length-1;l++){const c=e[l],u=e[l+1],f=u.x-c.x,m=u.y-c.y,g=Math.hypot(f,m);if(g===0)continue;const x=-m/g,y=f/g,T=l===0?c.startWidth:c.endWidth,v=u.startWidth,b=T/2,E=v/2;c.x+x*b,c.y+y*b,c.x-x*b,c.y-y*b;const O={x:u.x+x*E,y:u.y+y*E},_={x:u.x-x*E,y:u.y-y*E};r.push(O),n.push(_)}const a=r.length;for(let l=0;l<a;l++)i.push(r[l].x,r[l].y,0),i.push(n[l].x,n[l].y,0);for(let l=0;l<a-1;l++){const c=l*2;s.push(c,c+1,c+2),s.push(c+1,c+3,c+2)}const o=new d.BufferGeometry;return o.setAttribute("position",new d.Float32BufferAttribute(i,3)),o.setIndex(s),o}loadMLeader(e,i,s){const r=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i),n=e.contextData?.defaultTextContents;if(!n)return;const a=new F,o=li(n),l=this.getTextStyle(i,e),c=this.getMTextGroup(o,e,l,i,s),u=c&&c.object;if(u){u.matrix.decompose(Z,he,ze),e.contextData?.textLocation&&(Z.x+=e.contextData.textLocation.x,Z.y+=e.contextData.textLocation.y,u.matrix.compose(Z,he,ze)),We.makeEmpty();const f=F.getBox(u,We),m=f.getSize(j),g=m.x,x=m.y;let y=0,T=0;switch(e.contextData?.textAttachment){case 1:y=0,T=0;break;case 2:y-=g/2,T=0;break;case 3:y-=g,T=0;break;case 4:y=0,T+=x/2;break;case 5:y-=g/2,T+=x/2;break;case 6:y-=g,T+=x/2;break;case 7:y=0,T+=x;break;case 8:y-=g/2,T+=x;break;case 9:y-=g,T+=x;break;default:return}u.traverse(E=>{E.geometry&&E.geometry.translate(y,T,0)});let v=0;if(e.contextData?.textRotation&&(v=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const E=e.contextData.textDirection,O=new d.Vector3(E.x,E.y,E.z),_=O.clone().cross(Ae),C=Ae.angleTo(O);v+=_.z>0?-C:C}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(u),u.matrix.compose(Z,he,ze),e.contextData?.textLocation?j.set(e.contextData.textLocation.x,e.contextData.textLocation.y,0):j.set(0,0,0);const b=Z.clone().sub(j);Fe.makeTranslation(-b.x,-b.y,0),ne.makeRotationZ(v),u.matrix.multiply(Fe),u.matrix.multiply(ne),u.matrix.multiply(Fe.invert()),u.renderOrder=ge.Text,a.add(u)}if(e.leaderLineType!==0){const f=[],m=e.contextData?.leaders[0];if(!m)return a;const g=m.lastLeaderLinePoint;if(e.enableDogLeg){const E=new d.Vector3(g.x,g.y,g.z),O=m.doglegLength,_=new d.Vector3(m.doglegVector.x,m.doglegVector.y,m.doglegVector.z),C=_.multiplyScalar(O),w=E.clone().add(C);f.push(w,E)}const x=e.contextData?.leaders[0].leaderLines||[];for(let E=0;E<x.length;E++){const O=x[E].vertices[0],_=O.reverse().map(k=>new d.Vector3(k.x,k.y,k.z));let C=new d.Vector3(g.x,g.y,g.z);for(let k=0;k<_.length;k++)f.push(C,_[k]),C=_[k];const w=j.subVectors(f[0],f[1]).length(),M=e.arrowHeadSize||r.DIMASZ||2.5,P=e.arrowHeadScale||r.DIMSCALE||1,A=M*P;e.leaderLineType;let I="";if(e.arrowHeadId?I=e.arrowHeadId:r&&r.DIMLDRBLK&&(I=r.DIMLDRBLK),I){const k=this.getBlockByHandle(i.blocks,I);if(k&&k.entities)for(let B=0;B<k.entities.length;B++){const L=this.loadEntity(k.entities[B],i,e);if(L){const q=new d.Vector3(f[f.length-1].x,f[f.length-1].y,f[f.length-1].z),me=new d.Vector3(f[f.length-2].x,f[f.length-2].y,f[f.length-2].z),ue=Math.atan2(q.y-me.y,q.x-me.x);j.copy(q),Z.setScalar(A),he.setFromAxisAngle(Et,ue),L.matrix.compose(j,he,Z),a.add(L)}}}else this.loadDefaultLeadArrow(f[f.length-2],f[f.length-1],w/2e3,f)}const y=new d.Vector3;let T=!1;this.enableRTC&&(T=U.checkAndRebasePositionsOnRTC(f,y));const v=new d.BufferGeometry().setFromPoints(f),b=new F(H.LineSegment);b.geometry=v,b.material=le,b.renderOrder=ge.Line,T&&(this.setRTCUserData(b),b.matrix.setPosition(y.x,y.y,0)),a.add(b)}else return u?.traverse(f=>{f.layers.enableAll()}),u;return et.merge(a,!1),a.traverse(f=>{f.layers.enableAll()}),a.children.length===1?a.children[0]:a}loadLeader(e,i,s){const r=[];if(!e.vertices)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;if(e.vertices.length<2)return S.warn("leader's vertices number must be greater than 2"),void 0;const n=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i);let a=e.vertices;if(e.pathType===1&&(a=new d.SplineCurve(e.vertices).getPoints(50)),e.textWidth){const T=e.textWidth,v=new d.Vector3(a[a.length-1].x,a[a.length-1].y,a[a.length-1].z);if(e.direction===0){const b=new d.Vector3(1,0,0).multiplyScalar(T);a.push(b.add(v))}else{const b=new d.Vector3(-1,0,0).multiplyScalar(T);a.push(b.add(v))}}for(let T=0;T<a.length-1;T++){const v=a[T],b=a[T+1];r.push(v,b)}const o=j.subVectors(r[0],r[1]).setZ(0).length(),l=e.arrowHeight||n.DIMASZ||2.5,c=e.arrowHeadScale||n.DIMSCALE||1,u=l*c,f=new F;if(e.arrowFlag===1){let T="";e.arrowHeadBlockHandle?T=e.arrowHeadBlockHandle:n&&n.DIMLDRBLK&&(T=n.DIMLDRBLK);const v=this.getBlockByHandle(i.blocks,T);if(v&&v.entities){n&&(e.colorIndex=n.DIMCLRD||256,e.color=Nt(e.colorIndex));for(let b=0;b<v.entities.length;b++){const E=this.loadEntity(v.entities[b],i,e);if(E){const O=new d.Vector3(r[0].x,r[0].y,r[0].z),_=new d.Vector3(r[1].x,r[1].y,r[1].z),C=Math.atan2(O.y-_.y,O.x-_.x);j.copy(O),Z.setScalar(u),he.setFromAxisAngle(Et,C),E.matrix.compose(j,he,Z),f.add(E)}}}else this.loadDefaultLeadArrow(r[1],r[0],u/o/2,r)}if(r.length===0)return;const m=new d.Vector3;let g=!1;this.enableRTC&&(g=U.checkAndRebasePositionsOnRTC(r,m));const x=new d.BufferGeometry().setFromPoints(r),y=new F(H.Line);return y.geometry=x,y.material=le,y.renderOrder=ge.Line,g&&(this.setRTCUserData(y),y.matrix.setPosition(m.x,m.y,0)),f.children.length>0?(f.add(y),et.merge(f,!1),f.traverse(T=>{T.layers.enableAll()}),f.children.length===1?f.children[0]:f):(y.layers.enableAll(),y)}getTableTextOffset(e,i,s){const r=new d.Vector3;switch(e){case 1:break;case 2:r.setX(i/2);break;case 3:r.setX(i);break;case 4:r.setY(-s/2);break;case 5:r.set(i/2,-s/2,0);break;case 6:r.set(i,-s/2,0);break;case 7:r.setY(-s);break;case 8:r.set(i/2,-s,0);break;case 9:r.set(i,-s,0);break}return r}loadTable(e,i,s){if(!e.startPoint){S.warn("[Dxf] Entity is missing startPoint:",e.handle);return}if(e.cells.length===0){S.warn("[Dxf] Entity is missing cells:",e.handle);return}if(e.rowHeightArr.length===0){S.warn("[Dxf] Entity is missing rowHeightArr:",e.handle);return}if(e.columnWidthArr.length===0){S.warn("[Dxf] Entity is missing columnWidthArr:",e.handle);return}const r=new F,{cells:n,rowCount:a,columnCount:o,rowHeightArr:l,columnWidthArr:c}=e,u=[];let f=0;for(let y=0;y<a;y++){u[y]=[];for(let T=0;T<o;T++)u[y][T]=f<n.length?n[f++]:null}for(let y=0;y<a;y++)for(let T=0;T<o;T++){const v=u[y][T];if(!v||v.mergedValue!==0)continue;let b=1,E=1;for(;y+b<a&&u[y+b][T]&&u[y+b][T].mergedValue===1;)b++;for(;T+E<o&&u[y][T+E]&&u[y][T+E].mergedValue===1;)E++;v.rowSpan=b,v.colSpan=E}const m=[0];for(let y=0;y<a;y++)m.push(m[y]-l[y]);const g=[0];for(let y=0;y<o;y++)g.push(g[y]+c[y]);const x=[];for(let y=0;y<=a;y++){let T=g[0],v=!1;for(let b=0;b<o;b++){y>0&&u[y-1][b],y<a&&u[y][b];let E=!0;if(y===0||y===a)E=!0;else{const O=this._getMergeOwner(u,y-1,b,a,o),_=this._getMergeOwner(u,y,b,a,o);E=O!==_}E?v||(v=!0,T=g[b]):v&&(x.push(new d.Vector3(T,m[y],0),new d.Vector3(g[b],m[y],0)),v=!1)}v&&x.push(new d.Vector3(T,m[y],0),new d.Vector3(g[o],m[y],0))}for(let y=0;y<=o;y++){let T=m[0],v=!1;for(let b=0;b<a;b++){y>0&&u[b][y-1],y<o&&u[b][y];let E=!0;if(y===0||y===o)E=!0;else{const O=this._getMergeOwner(u,b,y-1,a,o),_=this._getMergeOwner(u,b,y,a,o);E=O!==_}E?v||(v=!0,T=m[b]):v&&(x.push(new d.Vector3(g[y],T,0),new d.Vector3(g[y],m[b],0)),v=!1)}v&&x.push(new d.Vector3(g[y],T,0),new d.Vector3(g[y],m[a],0))}if(x.length>0){const y=new d.BufferGeometry().setFromPoints(x),T=new F(H.LineSegment);T.geometry=y,T.material=le,T.layers.enableAll(),r.add(T)}for(let y=0;y<a;y++)for(let T=0;T<o;T++){const v=u[y][T];if(!v||v.mergedValue!==0)continue;const b=g[T],E=m[y];let O=0;for(let M=0;M<(v.colSpan||1);M++)O+=c[T+M];let _=0;for(let M=0;M<(v.rowSpan||1);M++)_+=l[y+M];v.colorIndex=e.colorIndex,v.height=v.textHeight||2.5;const C=this.getTableTextOffset(v.attachmentPoint||1,O,_);j.set(b,E,0),j.add(C),v.position=j.clone();const w=this.loadMText(v,i,s);w&&r.add(w)}if(e.blockRecordHandle){const y=this.getBlockByHandle(i.blocks,e.blockRecordHandle);if(y&&y.entities)for(const T of y.entities){T.isTable=!0;const v=this.loadEntity(T,i,e);v&&r.add(v)}}return r.matrix.decompose(j,he,ze),j.x+=e.startPoint.x,j.y+=e.startPoint.y,r.matrix.compose(j,he,ze),r}_getMergeOwner(e,i,s,r,n){let a=i,o=s;for(;a>=0&&e[a][o]&&e[a][o].mergedValue===1;){if(a>0&&e[a-1][o]&&e[a-1][o].mergedValue!==1){a--;break}if(o>0&&e[a][o-1]&&e[a][o-1].mergedValue!==1){o--;break}if(a>0)a--;else if(o>0)o--;else break}return e[a]?.[o]||null}loadDefaultLeadArrow(e,i,s,r){const n=s*(e.x-i.x),a=s*(e.y-i.y),o=a,l=-n,c=new d.Vector3(i.x+n+o/6,i.y+a+l/6,0),u=new d.Vector3(i.x+n-o/6,i.y+a-l/6,0);r.push(i,c),r.push(i,u),r.push(c,u)}getBlockByHandle(e,i){if(!this.blocksCache){this.blocksCache={};for(const s in e){const r=e[s];!this.blocksCache[r.ownerHandle]&&(this.blocksCache[r.ownerHandle]=r)}}return this.blocksCache[i]}static updateMaterialUniforms(e){e instanceof d.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=V.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=V.ViewportScaleUniform))}static transformAngleByOcsMatrix(e,i){const s=j.set(Math.cos(i)*1,Math.sin(i)*1,0),r=s.applyMatrix4(e);return Math.atan2(r.y,r.x)}static getArcAnglesByOcsMatrix(e,i,s){let r=R.getArcAngleSpanInRadian(i,s);const n=V.transformAngleByOcsMatrix(e,i),a=V.transformAngleByOcsMatrix(e,s);let o;if(R.areNumbersClose(r,Math.PI)){r=1;const l=V.transformAngleByOcsMatrix(e,i+r);o=R.getArcAngleSpanInRadian(n,l)}else{if(R.areNumbersClose(r,Math.PI*2))return[n,n+Math.PI*2];o=R.getArcAngleSpanInRadian(n,a)}return R.areNumbersClose(r,o,1e-5)?[n,a]:[a,n]}loadArc(e,i,s){if(!e.radius||e.radius<.001)return S.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is undefined, ignored!"),void 0;if(!e.radius||e.radius<.001)return S.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is too small, ignored!"),void 0;const r=new d.Vector3(0,0,1);e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0&&r.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const n=V.getOcsMatrix(r);let a,o;if(e.type==="CIRCLE")a=e.startAngle||0,o=a+2*Math.PI;else{if(e.startAngle==null||e.endAngle==null||(a=e.startAngle,o=e.endAngle,R.areNumbersEqual(a,o,1e-6)))return;if(!R.areNumbersClose(R.getArcAngleSpanInRadian(a,o),Math.PI*2)){const _=V.getArcAnglesByOcsMatrix(n,a,o);a=_[0],o=_[1]}}const l=new d.ArcCurve(0,0,e.radius,a,o,this.angBase!==0);let c=1;const u=s;u?.xScale&&u?.yScale&&(c=Math.max(Math.abs(u.xScale),Math.abs(u.yScale)));const f=this.getDivision(a,o,e.radius*c),m=l.getPoints(f),g=new d.Vector3;let x=!1;this.enableRTC&&(x=U.checkAndRebasePositionsOnRTC(m,g));const y=new d.BufferGeometry().setFromPoints(m),T=new F(H.Line);T.geometry=y,T.material=le;const v=new d.Vector3;e.center&&(v.x=e.center.x,v.y=e.center.y);const b=new d.Vector3(e.center?.x,e.center?.y,e.center?.z).applyMatrix4(n.invert());v.x=b.x,v.y=b.y;const E=v,O=new F(H.Point);return O.geometry=Sr,O.material=Ei,O.userData.handle=e.handle,O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(Ce),T.add(O),x?(this.setRTCUserData(T),E.x+=g.x,E.y+=g.y):U.shouldRebasePositionOnRTC(E)&&this.setRTCUserData(T),T.matrix.setPosition(E),T.layers.enableAll(),T}addTriangleFacingCamera(e,i,s,r){const n=new d.Vector3,a=new d.Vector3;n.subVectors(s,i),a.subVectors(r,i),n.cross(a);const o=new d.Vector3(i.x,i.y,i.z),l=new d.Vector3(s.x,s.y,s.z),c=new d.Vector3(r.x,r.y,r.z);n.z<0?e.push(c,l,o):e.push(o,l,c)}loadSolid(e,i,s){const r=e.points;if(!r||r.length<4)return;if(e.extrusionDirection&&e.extrusionDirection.z){j.set(0,0,e.extrusionDirection.z);const f=V.getOcsMatrix(j).invert();r.forEach(m=>{const g=j.set(m.x,m.y,0).applyMatrix4(f);m.x=g.x,m.y=g.y})}const n=[],a=[];this.addTriangleFacingCamera(n,r[0],r[1],r[2]),a.push(0,1,2),this.addTriangleFacingCamera(n,r[1],r[2],r[3]),a.push(3,4,5);const o=new d.Vector3;let l=!1;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(n,o));const c=new d.BufferGeometry().setFromPoints(n);c.setIndex(a);const u=new F(H.Mesh);return u.geometry=c,u.material=_t,l&&(this.setRTCUserData(u),u.matrix.setPosition(o.x,o.y,0)),u.layers.enableAll(),u}getTextStyle(e,i){const s=e.tables?.style?.styles;return s?s[i.textStyle]||s.STANDARD||s.Standard||{}:{}}getDefaultDimensionStyle(e){return e.tables.dimStyle.dimStyles.STANDARD||e.tables.dimStyle.dimStyles.Standard||{}}getTextEncoding(e){return e?.bigFontFile&&e.bigFontFile.toUpperCase().startsWith("GB")?"gbk":"utf8"}getTextMesh(e,i,s,r){if(!e)return;const n=s?.styleName||"";if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const c=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[c]&&(this.statsInfo.unsupportedTextStyles[c]=0),this.statsInfo.unsupportedTextStyles[c]++}let a=.8;const o={_TCH_DIM:1.45,ROMANS:1};n&&o[n]&&(a=o[n]),r.xScale&&(a*=r.xScale),a>1&&n&&(a*=s?.xScale||1,i=i||s?.textHeight||0),i===0&&(n?i=1:i=.2);const l=this.createTextMeshByText(e,s,i,0,i/12,a);return l.traverse(c=>{c.geometry&&c.geometry.scale(a,1,1)}),l}createTextMeshByText(e,i,s=12,r=0,n=0,a=1,o=1/0,l=0){const c=new F,u=[];let f=0,m=0;i?.xScale;const g=r+s,x=i?.fontFile||"",y=typeof x=="string"&&x.toLowerCase().endsWith(".shx"),T=y?s*.06:s*.04,v=[];for(let O=0;O<e.length;O++){const _=e[O];_!==" "&&_!==`
795
795
  `&&v.push(O)}const b=v.length;let E=0;for(let O=0;O<e.length;O++){const _=e[O];if(_===" "){f+=s*(y?.4:.33);continue}if(_===`
796
- `){f=0,m-=g*.5;continue}let C=this.font?.getCharShape?.(_,i?.fontFile,s);if(!C&&i?.bigFontFile&&(C=this.font?.getCharShape?.(_,i.bigFontFile,s)),!C&&this.font?.fileNames){const w=this.font.fileNames.filter(M=>M!==i?.fontFile);for(let M=w.length-1;M>=0&&(i.fontFile=w[M],i.styleName="Standard",C=this.font?.getCharShape?.(_,i.fontFile,s),!C);M--);}if(C||(C=this.font?.getNotFoundTextShape?.(s)),!!C){if(C.translate(f,m,0),f>o)f=0,m-=g;else{!C.boundingBox&&C.computeBoundingBox();const w=C.boundingBox.getSize(z).x,M=_.charCodeAt(0),A=M>=19968&&M<=40959||M>=13312&&M<=19903||M>=63744&&M<=64255||M>=12288&&M<=12351||M>=65280&&M<=65519||[8216,8217,8220,8221].includes(M)?Math.max(w,s):w+T;E++,f+=A+(E===b?0:l)}u.push(C)}}if(u.length>0){const O=u.filter(C=>C instanceof d.ExtrudeGeometry),_=u.filter(C=>!(C instanceof d.ExtrudeGeometry));if(O.length>0){const C=new F(N.Mesh);C.geometry=xe.mergeGeometries(O),C.material=_t,c.add(C)}if(_.length>0){const C=new F(N.LineSegment);C.geometry=xe.mergeGeometries(_),C.material=le,c.add(C)}}return c}transformTextMesh(e,i){We.makeEmpty();const s=F.getBox(i,We),r=s.getSize(z),{halign:n,valign:a}=e;i.matrix.decompose(Oi.position,Oi.quaternion,Oi.scale);const o=Oi,l=e.width||e.textWidth||r.x,c=e.height||e.textHeight||r.y;if(n===void 0&&a===void 0&&e.startPoint||[3,5].includes(n)&&e.startPoint?(o.position.x+=e.startPoint.x,o.position.y+=e.startPoint.y,o.position.z+=e.startPoint.z):e.endPoint&&(o.position.x+=e.endPoint.x,o.position.y+=e.endPoint.y,o.position.z+=e.endPoint.z),n!==3&&n!==5){if(e.rotation){const u=e.rotation*Math.PI/180;o.rotateZ(u)}e.mirrored&2&&o.rotateY(Math.PI),e.mirrored&4&&o.rotateX(Math.PI)}switch(n){case 0:break;case 1:o.translateX(-l/2);break;case 2:o.translateX(-l);break;case 3:if(e.startPoint&&e.endPoint){const u=new d.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new d.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new d.Vector3().subVectors(u,f),g=m.length(),x=g/l;o.scale.multiplyScalar(x);const y=m.clone().cross(Ae),T=m.angleTo(Ae);o.rotateZ(y.z>0?Math.PI-T:T-Math.PI),(e.mirrored===2||e.mirrored===4)&&o.rotateX(Math.PI)}break;case 4:o.translateX(-l/2),o.translateY(-c/12);break;case 5:if(e.startPoint&&e.endPoint){const u=new d.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new d.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new d.Vector3().subVectors(u,f),g=m.length(),x=g/l,T=(e.text||"").length;if(T>1){const E=(g-l)/(T-1);o.userData.letterSpacing=E}else x<3&&o.scale.setX(x);const v=m.clone().cross(Ae),b=m.angleTo(Ae);o.rotateZ(v.z>0?Math.PI-b:b-Math.PI)}break}switch(a){case 0:break;case 1:break;case 2:o.translateY(-c/2);break;case 3:o.translateY(-c);break}return o.position.z=0,o.updateMatrix(),i.matrix.copy(o.matrix),i}loadText(e,i,s){const r=e.text;if(!r)return;if(!this.font){S.info("[Dxf] Font file not set, ignoring text entity.");return}const n=this.getTextStyle(i,e),o=Ni(r,{encoding:this.getTextEncoding(n)}).map(u=>u.text).join(""),l=this.getTextMesh(o,e.textHeight,n,e);if(!l||l.children.length===0)return;this.transformTextMesh(e,l),z.set(l.matrix.elements[12],l.matrix.elements[13],l.matrix.elements[14]);const c=U.shouldRebasePositionOnRTC(z);return c&&this.setRTCUserData(l),l.userData={...l.userData,textContent:r,dxfType:"TEXT",isMText:!1,layer:e.layer||"0",handle:e.handle,entityId:e.entityId||e.handle},l.traverse(u=>{const f=u.geometry;if(f){if(u.userData.textContent=r,u.userData.dxfType="TEXT",u.userData.layer=e.layer||"0",u.userData.handle=e.handle,u instanceof d.Mesh&&!f.getIndex()){const m=f.getAttribute("position"),g=[];for(let x=0;x<m.count;x+=3)g.push(x,x+1,x+2);f.setIndex(g)}if(f.hasAttribute("uv")&&f.deleteAttribute("uv"),f.hasAttribute("normal")&&f.deleteAttribute("normal"),!c){const m=U.caculateGeometryCenter(f);m&&U.shouldRebasePositionOnRTC(m)&&this.setRTCUserData(u)}}}),l.layers.enableAll(),l}loadAttDef(e,i,s){let r=e.tag||e.text||e.prompt;if(!r||!this.font)return;const n=this.getTextStyle(i,e);r=Ni(r).map(c=>c.text).join();const o=this.getTextMesh(r,e.textHeight,n,e);if(!o||o.children.length===0)return;this.transformTextMesh(e,o),z.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=U.shouldRebasePositionOnRTC(z);return l&&this.setRTCUserData(o),o.traverse(c=>{const u=c.geometry;if(u){if(c instanceof d.Mesh&&!u.getIndex()){const f=u.getAttribute("position"),m=[];for(let g=0;g<f.count;g+=3)m.push(g,g+1,g+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),!l){const f=U.caculateGeometryCenter(u);f&&U.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(c)}}}),o.layers.enableAll(),o}loadAttrib(e,i,s){let r=e.text;if(!r||!this.font)return;const n=this.getTextStyle(i,e);r=Ni(r).map(c=>c.text).join("");const o=this.getTextMesh(r,e.textHeight,n,e);if(!o||o.children.length===0)return;o.userData.llbData=s?.zdysx,o.userData.textContent=r||"",o.userData.dxfType="ATTRIB",o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",this.transformTextMesh(e,o),z.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=U.shouldRebasePositionOnRTC(z);return l&&this.setRTCUserData(o),o.traverse(c=>{const u=c.geometry;if(u){if(c instanceof d.Mesh&&!u.getIndex()){const f=u.getAttribute("position"),m=[];for(let g=0;g<f.count;g+=3)m.push(g,g+1,g+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),c instanceof d.Mesh&&(c.entity=e,c.userData.entity=e),c.userData.textContent=r,c.userData.dxfType="ATTRIB",c.userData.layer=e.layer||"0",c.userData.handle=e.handle||"",!l){const f=U.caculateGeometryCenter(u);f&&U.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(c)}}}),o.layers.enableAll(),o}loadPoint(e,i,s){if(!e.position)return;const r=new d.BufferGeometry,n=[new d.Vector3(e.position.x,e.position.y,e.position.z)];z.set(0,0,0);const a=z;let o=!1;this.enableRTC&&(o=U.checkAndRebasePositionsOnRTC(n,a)),r.setFromPoints(n);const l=new F(N.Point);return l.geometry=r,l.material=le,o&&(this.setRTCUserData(l),l.matrix.setPosition(a.x,a.y,0)),l.layers.enableAll(),l}loadDimension(e,i){if(!e.block)return;const s=i.blocks[e.block];if(!s||!s.entities)return;const r=i.tables.dimStyle.dimStyles[e.dimStyleName]||this.getDefaultDimensionStyle(i);r&&r.DIMCLRD>0&&(e.colorIndex=r.DIMCLRD,e.color=Nt(e.colorIndex));const n=new F;for(let o=0;o<s.entities.length;o++){const l=this.loadEntity(s.entities[o],i,e);l&&n.add(l)}if(n.children.length===0){const o=e.name||e.block;return!this.statsInfo.ignoredInserts[o]&&(this.statsInfo.ignoredInserts[o]=0),this.statsInfo.ignoredInserts[o]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const o=this.blockReferencesCache[e.block];o.referenceCount++}n.name=e.type+"<"+s.name+">",n.userData.entityType=e.type;const a=e.insertionPoint;return z.set(0,0,0),a&&z.set(a.x,a.y,0),U.shouldRebasePositionOnRTC(z)&&this.setRTCUserData(n),n.matrix.setPosition(z),n}loadImage(e,i,s){if(!e.imageSize||!i.objects.IMAGEDEF?.length)return;const r=i.objects.IMAGEDEF.filter(y=>y.handle===e.imageDefHandle)[0];if(!r)return;const n=e.imageSize.x,a=e.imageSize.y,o=new F;let l=!1;e.flags===Hi.ShowImageWhenNotAlignedWithScreen||e.flags===Hi.UseClippingBoundary||e.flags===Hi.TransparencyIsOn||(l=!0);const c=new d.PlaneGeometry(n,a);if(l){const y=new d.TextureLoader(this.manager).load(r.filename,void 0,void 0,()=>{console.warn("Please upload the pictures in the same folder, or use url link in the dxf file.")});y.colorSpace=d.SRGBColorSpace;const T=new d.MeshBasicMaterial({transparent:!0,side:d.FrontSide,map:y}),v=new F(N.Mesh);v.geometry=c,v.material=T,o.add(v)}const u=new d.EdgesGeometry(c),f=this.getColor(e,i,s),m=new F(N.Line);m.geometry=u,m.material=this.getLineBasicMaterial(f);const g=e.uPixel?new d.Vector3(e.uPixel.x,e.uPixel.y,e.uPixel.z):new d.Vector3(r.pixelSize.x,0,0),x=e.vPixel?new d.Vector3(e.vPixel.x,e.vPixel.y,e.vPixel.z):new d.Vector3(r.pixelSize.y,0,0);if(o.add(m),Z.set(g.x,x.y,1),z.set(0,0,0),e.position){const y=new d.Vector3(e.position.x,e.position.y,e.position.z);y.add(g.multiplyScalar(n/2)).add(x.multiplyScalar(a/2)),z.copy(y)}return U.shouldRebasePositionOnRTC(z)&&this.setRTCUserData(o),he.identity(),o.matrix.compose(z,he,Z),o}loadInsert(e,i,s,r=!1){if(!e||!e.block)return;const n=i.blocks[e.block];if(!n||!n.entities)return;s&&e.layer==="0"&&(e.layer=s.layer),e.blockPosition=n.position;const a=new F;for(let f=0;f<n.entities.length;f++){if(n.entities[f].type==="ATTDEF")continue;const m=this.loadEntity(n.entities[f],i,e,r);m&&(e&&e.zdysx&&j.LOADLLDATA&&(m.userData.llbData=e.zdysx),a.add(m))}if(a.children.length===0){const f=e.name||e.block;return!this.statsInfo.ignoredInserts[f]&&(this.statsInfo.ignoredInserts[f]=0),this.statsInfo.ignoredInserts[f]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const f=this.blockReferencesCache[e.block];f.referenceCount++}a.name=e.type+"<"+n.name+">",a.userData.entityType=e.type,e.extendedData?.originalType&&(a.userData.originalType=e.extendedData?.originalType),e?.blockPosition&&a.matrix.setPosition(-e.blockPosition.x,-e.blockPosition.y,0);const o=z.set(1,1,1);e.xScale&&(o.x=e.xScale),e.yScale&&(o.y=e.yScale);const l=new d.Euler;e.rotation&&(l.z=e.rotation*Math.PI/180),he.setFromEuler(l,!1);const c=Z.set(0,0,0);e.position&&(c.x=e.position.x,c.y=e.position.y),ne.compose(c,he,o),e.extrusionDirection&&e.extrusionDirection.z<0&&ne.premultiply(Or.identity().makeScale(-1,1,1)),Fe.copy(a.matrix),a.matrix.premultiply(ne),Z.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(a);const u=this.findSpatialFilterByHandle(e.handle,i);if(u){this.loadSpatialFilter(u);const f=u;f&&f.clipPolylines&&f.clipPolylines.length>0&&(a.userData.spatialFilterHandle=u.handle,this.cloneMaterialsForSpatialFilter(a),S.debug("[Dxf] Spatial filter:",e.associatedSpatialFilter))}return a}loadSpatialFilter(e){const i=e;if(i.threejsObject)return i.threejsObject.clone();const s=e.invertBlockMatrix;ne.set(s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],s[11],0,0,0,1);const r=[];e.vertices.forEach(o=>{r.push(new d.Vector3(o.x,o.y,0))});const n={polyline:[],bConcave:!1,bReversed:!1};if(e.numberOfPointsOnClipBoundary===2)n.polyline=r;else{const o=e.numberOfPointsOnClipBoundary,l=3;if(o<l)return S.warn("[Dxf] Invalid clipBoundary: "+e.handle+" !"),void 0;let c=[],u=-1;for(let g=0;g<o;g++){const x=r[g];for(let y=o-1;y>g;y--){const T=r[y];if(R.areVector3sEqual(x,T)&&g+1<y-1&&g+1<o-1&&R.areVector3sEqual(r[g+1],r[y-1])){c.push(x),u=y;break}}if(u>0)break;c.push(x)}if(u>0)for(let g=u+1;g<o;g++)c.push(r[g]);if(c.length<l)return S.warn("[Dxf] Invalid clipBoundary: "+e.handle+"!"),void 0;const f=[],m=[];if(c.forEach(g=>{f.push(new d.Vector2(g.x,g.y)),m.push([g.x,g.y])}),!U.isConvex(f)){S.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const g=ya(m,1/0);c=[],g.forEach(x=>{c.push(new d.Vector3(x[0],x[1],0))})}!R.areVector3sEqual(c[0],c[c.length-1])&&c.push(c[0]),n.polyline=c,n.bReversed=u>0}let a;return this.enableReleaseData&&(e.vertices=[],e.matrix=[],e.invertBlockMatrix=[]),i.localMatrix=ne.clone(),i.clipPolylines=[],i.clipPolylines.push(n),a}loadLayout(e,i,s,r,n,a){if(!e.entities)return;const o=new F;for(let u=0;u<e.entities.length;u++){const f=e.entities[u];this.addViewport(f,a);const m=this.loadEntity(f,i);m&&(this.enableMerge&&Qe.merge(m,!1),o.add(m),m.traverse(g=>{if(g.geometry){const x=g.userData.layerName;let y=n[x];!y&&(y=[],n[x]=y),y.push(g),g.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[s.layoutName]&&(this.layoutsSnapObjectsMap[s.layoutName]=[]),this.layoutsSnapObjectsMap[s.layoutName].push(g))}}))}if(o.children.length===0)return;o.userData.layerName=e.layer;const l=s.layoutName;let c=r.children.find(u=>u.name===l);!c&&(c=new F,c.name=l,c.userData.isLayoutLevelObject=!0,r.add(c)),c.add(o),e.position&&o.matrix.setPosition(e.position.x,e.position.y,e.position.z||0)}convertEdgeToPoints(e){const i=[];if(!e)return i;switch(e.type){case Bt.Line:{const r=e;i.push(new d.Vector2(r.startPoint.x,r.startPoint.y)),i.push(new d.Vector2(r.endPoint.x,r.endPoint.y));break}case Bt.Arc:{const r=e;let n=r.startAngle*d.MathUtils.DEG2RAD,a=r.endAngle*d.MathUtils.DEG2RAD;!r.bCounterclockwise&&(n=Math.PI*2-n,a=Math.PI*2-a);const o=new d.ArcCurve(r.center.x,r.center.y,r.radius,n,a,!r.bCounterclockwise),l=this.getDivision(n,a,r.radius),c=o.getPoints(l);e.startPoint=c[0],e.endPoint=c[c.length-1],i.push(...c);break}case Bt.Ellipse:{const r=e,n=Math.sqrt(Math.pow(r.majorAxisEndPoint.x,2)+Math.pow(r.majorAxisEndPoint.y,2)),a=n*r.minorRatio,o=Math.atan2(r.majorAxisEndPoint.y,r.majorAxisEndPoint.x);let l=r.startAngle*d.MathUtils.DEG2RAD,c=r.endAngle*d.MathUtils.DEG2RAD;!r.bCounterclockwise&&(l=Math.PI*2-l,c=Math.PI*2-c);const u=new d.EllipseCurve(r.center.x,r.center.y,n,a,l,c,!r.bCounterclockwise,o),f=this.getDivision(l,c,Math.max(n,a)),m=u.getPoints(f);e.startPoint=m[0],e.endPoint=m[m.length-1],i.push(...m);break}case Bt.Spline:{const r=e,n=kr(r.controlPoints,r.degreeOfSplineCurve,r.knotValues);if(n.length===0)break;e.startPoint=n[0],e.endPoint=n[n.length-1],i.push(...n);break}case Bt.Polyline:{const r=e,n=us(r.points,r.isClosed);e.startPoint=n[0],e.endPoint=n[n.length-1],i.push(...n);break}}return i}loadHatch(e,i,s){const r=e;let n=[];function a(O,_){const{startPoint:C,endPoint:w}=O,{startPoint:M,endPoint:P}=_,A=w.x-C.x,I=w.y-C.y,k=P.x-M.x,B=P.y-M.y,L=A*B-I*k;if(Math.abs(L)<1e-10)return null;const q=C.x-M.x,me=C.y-M.y,ue=(k*me-B*q)/L,nt=(A*me-I*q)/L;return ue>=0&&ue<=1&&nt>=0&&nt<=1?{x:C.x+ue*A,y:C.y+ue*I}:null}function o(O){const{edges:_}=O,C=[],w=_.length;if({...O},w!==4)return[O];for(let M=0;M<w;M++)for(let P=M+2;P<w;P++){if(P===M+1||M===0&&P===w-1)continue;const A=a(_[M],_[P]);A&&C.push({edgeIndex1:M,edgeIndex2:P,point:{x:A.x,y:A.y}})}if(C.length&&C.length===1){const M={pathTypeFlag:O.pathTypeFlag,edges:[_[C[0].edgeIndex1-1],{startPoint:{..._[C[0].edgeIndex1].startPoint},endPoint:{x:C[0].point.x,y:C[0].point.y},type:_[C[0].edgeIndex1].type},{startPoint:{x:C[0].point.x,y:C[0].point.y},endPoint:{x:_[C[0].edgeIndex2].startPoint.x,y:_[C[0].edgeIndex2].startPoint.y},type:_[C[0].edgeIndex2].type}]},P={pathTypeFlag:O.pathTypeFlag,edges:[{startPoint:{x:C[0].point.x-1e-5,y:C[0].point.y-1e-5},endPoint:{..._[C[0].edgeIndex1].endPoint},type:_[C[0].edgeIndex1].type},{..._[C[0].edgeIndex2-1]},{startPoint:_[C[0].edgeIndex2].startPoint,endPoint:{x:C[0].point.x-1e-5,y:C[0].point.y-1e-5},type:_[C[0].edgeIndex2].type}]};return[M,P]}return[O]}if(r.boundaryPaths.length==0)return;for(let O=0;O<r.boundaryPaths.length;O++){const _=r.boundaryPaths[O],C=o(_);n=[...n,...C]}if(r.boundaryPaths=n,!r.solidFill&&!r.patternLines?.length){S.warn("[Dxf] Hatch entity(handle: '"+r.handle+"') doesn't have solid fill, nor patternLines, ignored!");return}const l=[],c=[],u=[],f=O=>{const _=[];let C=[];C.push(...this.convertEdgeToPoints(O[0]));for(let w=1;w<O.length;w++){const M=this.convertEdgeToPoints(O[w]);if(C.push(...M),C.length>2){const P=this.convertEdgeToPoints(O[w-1]);R.areVector2sEqual(P[P.length-1],M[0])?R.areVector2sEqual(C[0],M[M.length-1],1e-5)&&(_.push(C),C=[]):R.areVector2sEqual(P[0],M[M.length-1])?R.areVector2sEqual(C[1],M[0],1e-5)&&(_.push(C),C=[]):C=[]}}return _};if(r.boundaryPaths.forEach((O,_)=>{let C=[];if(this.IsfilteredByPathTypeFlag(O.pathTypeFlag)){S.info("[Dxf] The %d path type flag is filtered at the %dth boundrayPath (hatch handle '%s')",O.pathTypeFlag,_,r.handle);return}const w=O.edges;if(w.length===0)return;const M=[];for(let P=0;P<w.length;P++){const A=this.convertEdgeToPoints(w[P]);if(A.length<2){S.warn("[Dxf] The %dth edge of the %dth boundaryPath (hatch handle '%s') has less than 2 points, ignored!",P,_,r.handle);continue}M.push(...A)}if(M.length<3){S.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has less than 3 points, ignored!",_,r.handle);return}if(C.push(M),O.pathTypeFlag>wn.MaxFlags&&(!(A=>{for(let I=1;I<A.length;++I){const k=A[I-1].endPoint,B=A[I].startPoint;if(!k||!B||!R.areVector2sEqual(k,B))return!1}return!0})(O.edges)||!r.associativity)&&(C=f(w),C.length<2)){S.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",_,r.handle);return}C.forEach(P=>{!R.areVector2sEqual(P[0],P[P.length-1])&&P.push(P[0]);const A=P.map(I=>new d.Vector2(V.roundNumber(I.x,7),V.roundNumber(I.y,7)));if(A?.length>0){l.push(A);const I=new d.Box2().setFromPoints(A);c.push(I);const k=I.getSize(Jt),B=k.x*k.y;u.push({area:B,index:l.length-1})}})}),l.length===0)return;const m=new d.Vector2,g=this.checkAndRebasePolygonsOnRTC(l,m);u.sort((O,_)=>O.area-_.area);const x=[];u.forEach(O=>{x.push(O.index)});const y=this.buildContainHierarchyTree(l,c,x),T=[];this.buildHatchGeometry(l,y,T);let v;if(T.length>0&&(v=xe.mergeGeometries(T)),!v||!v.getIndex()||v.getIndex()?.count===0)return S.warn("[Dxf] Failed to convert hatch boundaries!"),void 0;const b=new F(N.Mesh);b.geometry=v,b.material=_t,this.setHatchMaterial(b,r,i,m,s);const E=b;return g&&(this.setRTCUserData(E),E.matrix.setPosition(m.x,m.y,0)),E.traverse(O=>{O.layers.enableAll(),O.layers.disable(Ce)}),E}loadOle2frame(e,i){const{leftUpX:s,leftUpY:r,rightDownX:n,rightDownY:a}=e;if(!s||!r||!n||!a)return;const o=[new d.Vector2(s,r),new d.Vector2(s,a),new d.Vector2(n,a),new d.Vector2(n,r),new d.Vector2(s,r)],l=new d.Vector3;let c=!1;this.enableRTC&&(c=U.checkAndRebasePositionsOnRTC(o,l));const u=new d.BufferGeometry().setFromPoints(o),f=this.getLineBasicMaterial(16777215),m=new F(N.Line);m.geometry=u,m.material=f,m.layers.enableAll(),c&&(this.setRTCUserData(m),m.matrix.setPosition(l.x,l.y,0));const g=new F;g.add(m);let x;const y=i.objects.DICTIONARY;for(const v of y)for(const b in v.entries)if(v.entries[b]===e.handle){x=b;break}let T;if(x)if(this.meshTextureMaterials[x])T=this.meshTextureMaterials[x];else for(let v=0;v<i.objects.XRECORD.length;v++){const b=i.objects.XRECORD[v];if(b.handle===x){const E=b.binaryData,O=V.hexToBase64(E),_="data:image/jpg;base64,"+O,C=new d.TextureLoader(this.manager).load(_);C.colorSpace=d.SRGBColorSpace;const w=new d.MeshBasicMaterial({transparent:!0,map:C});this.meshTextureMaterials[x]=w,T=w;break}}if(T){const v=new d.Box2().setFromPoints(o),b=v.getSize(Jt),E=new d.PlaneGeometry(b.x,b.y),O=new F(N.Mesh);O.geometry=E,O.material=T;const _=v.getCenter(Jt);z.set(_.x,_.y,0),c&&(this.setRTCUserData(O),z.x+=l.x,z.y+=l.y),O.matrix.setPosition(z),O.layers.enableAll(),g.add(O)}return g.children.length>1?g:m}static getOcsMatrix(e){let i=Ae,s=ds,r=Et;const n=new d.Vector3(0,1,0),a=new d.Vector3(0,0,1);return R.areVectorsClose(e,a)?ne.identity():(r=e.clone().normalize(),!R.areVectorsClose(r,a)&&(Math.abs(r.x)<1/64&&Math.abs(r.y)<1/64?i=n.cross(r).normalize():i=a.cross(r).normalize(),s=r.clone().cross(i).normalize()),ne.set(i.x,i.y,i.z,0,s.x,s.y,s.z,0,r.x,r.y,r.z,0,0,0,0,1))}static getDcs2WcsMatrix(e,i){let s;th(e)?s=e.viewDirectionFromTarget:s=e.viewDirection,s??(s={x:0,y:0,z:1});const r=e.viewTarget??{x:0,y:0,z:0},n=new d.Vector3(R.roundNumber(s.x,7),R.roundNumber(s.y,7),s.z),a=new d.Vector3(r.x,r.y,r.z),o=e.viewTwistAngle||0;let l,c,u;u=n.clone().normalize(),l=Et.clone().cross(n),l.length()>0?(l.normalize(),c=u.clone().cross(l)):u.z<0?(l=Ae.clone().negate(),c=ds,u=Et.clone().negate()):(l=Ae,c=ds,u=Et);const f=new d.Matrix4,m=ne.identity();return m.makeBasis(l,c,u),f.premultiply(m),f.premultiply(ne.identity().compose(a.clone(),new d.Quaternion().setFromAxisAngle(new d.Vector3(0,0,1),d.MathUtils.degToRad(i?o:-o)),new d.Vector3(1,1,1))),f}getViewportMsToPsMatrix(e){const i=e.centerPoint_dcs??{x:0,y:0},s=e.centerPoint??{x:0,y:0,z:0},r=new d.Vector3(i.x,i.y,0),n=new d.Vector3(s.x,s.y,s.z),a=e.viewHeight,o=e.height_paperSpace||1,l=(a||o)/o,c=j.getDcs2WcsMatrix(e,this.angDir),u=new d.Matrix4;u.setPosition(Cr.clone().sub(n));const f=Or.identity();f.scale(z.set(l,l,l));const m=Fe.identity().setPosition(Cr.clone().sub(n));f.premultiply(m.clone().invert()).multiply(m),u.multiply(f);const g=ne.identity();g.setPosition(r),c.multiply(g);const x=ne.identity();return u.invert().multiply(x).multiply(c.invert())}loadViewport(e,i,s){if(e.viewportId+""=="1"){e.psBBox=new d.Box3,e.msToPsMatrix=new d.Matrix4;return}const r=e.centerPoint;if(!r||!Number.isFinite(r.x)||!Number.isFinite(r.y)){e.psBBox=new d.Box3,e.msToPsMatrix=new d.Matrix4;return}const n=e.width_paperSpace/2,a=e.height_paperSpace/2,o=[new d.Vector3(r.x-n,r.y-a,0),new d.Vector3(r.x-n,r.y+a,0),new d.Vector3(r.x+n,r.y+a,0),new d.Vector3(r.x+n,r.y-a,0)];o.push(o[0]),e.psBBox=new d.Box3().setFromPoints([o[0],o[2]]),e.msToPsMatrix=this.getViewportMsToPsMatrix(e);let l=!1;const c=new d.Vector3;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(o,c));const u=new d.BufferGeometry().setFromPoints(o),f=new F(N.Line);f.geometry=u,f.material=le,f.userData.entityType=e.type,f.layers.enableAll(),l&&(this.setRTCUserData(f),f.matrix.setPosition(c.x,c.y,0));const m=e.psBBox.clone();m.applyMatrix4(e.msToPsMatrix.clone().invert()),m.min.z=0,m.max.z=0;const g=[m.min,new d.Vector3(m.min.x,m.max.y,0),m.max,new d.Vector3(m.max.x,m.min.y,0)];g.push(g[0]);let x=!1;const y=new d.Vector3;this.enableRTC&&(x=U.checkAndRebasePositionsOnRTC(g,y));const T=new d.BufferGeometry().setFromPoints(g),v=new F(N.Line);v.geometry=T,v.material=le,v.userData.entityType=e.type,v.userData.inPaperSpace=[],v.layers.enableAll(),x&&(this.setRTCUserData(v),v.matrix.setPosition(y.x,y.y,0));const b=new F;return b.add(f),b.add(v),f}getColor(e,i,s){if(this.compareContext)return Ue.ENTITY_COLOR_NO_CHANGE;if(this.overrideColor!=null)return this.overrideColor;const r=e;if(r&&r.isGradientColor){const n=r.gradientColors;if(n&&n.length>=2){if(n[0]!==n[1]){const a="[Dxf] Gradient colors are not supported for hatch '"+e.handle+"', will use the first color!";S.warn(a)}return n[0]}}if(e.isTrueColor||e.colorIndex>0&&e.colorIndex<256)return e.color;if(e.colorIndex===0)return s?this.getColor(s,i):i.tables?.layer?.layers[0].color;if(e.colorIndex===256){const n=i.tables?.layer?.layers,a=n&&n[e.layer],o=n&&s&&n[s.layer];let l=ct;return a&&a.name!=="0"?l=a.color:o?l=o.color:a?l=a.color:n&&n[0].color&&(l=n[0].color),l}return S.warn("[Dxf] Unknown colorIndex"),ct}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==Fs&&e.lineType!==pi)return e.lineType;if(e.lineType===pi)return s?this.getLineType(s,i):e.lineType;const r=i.tables?.layer?.layers,n=eh;if(e.layer!=="0"){const a=r&&r[e.layer];if(a)return a.lineType}else if(s){const a=r&&r[s.layer];if(a)return a.lineType}return n}getLayerName(e,i,s){const r=c=>{n&&c&&!n[e.layer]&&(console.warn("[Dxf] Failed to find layer object for '"+c+"', adding a default one."),n[c]={name:c,handle:"",colorIndex:256,lineType:"",visible:!0})},n=i.tables?.layer?.layers;r(e.layer);const a=n&&n[e.layer];r(s?.layer);const o=n&&s&&n[s.layer];let l=a?.name||"";return a&&a.name==="0"&&o&&(l=o.name),l}setMaterial(e,i,s,r){const n=e;if(!n.geometry||(this.setRenderOrderByObjectType(e),i.type==="OLE2FRAME"))return;if(i.type==="MTEXT"){e.renderOrder=ge.Text;return}if(i.type==="HATCH"){Jt.set(0,0),this.setHatchMaterial(e,i,s,Jt,r);return}if(i.type==="IMAGE")return;let a;const o=this.getColor(i,s,r);if(i.type==="LWPOLYLINE"&&(n.isMesh?(a=this.getMeshBasicMaterial(o),e.renderOrder=ge.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=ge.LineWithPattern),a)){n.material=a;return}if(i.type==="SOLID")a=this.getMeshBasicMaterial(o);else if(i.type==="TEXT"||i.type==="ATTDEF"||i.type==="ATTRIB")a=this.getLineBasicMaterial(o),e.renderOrder=ge.Text;else if(i.type==="LEADER"||i.type==="MULTILEADER"||i.type==="VIEWPORT")a=this.getLineBasicMaterial(o);else if(i.type==="POINT")a=this.getPointsMaterial(o);else{if(e.material instanceof d.PointsMaterial){a=this.getPointsMaterial(o),n.material=a;return}const l=s.tables?.lineType?.lineTypes,c=l&&l[this.getLineType(i,s,r)];if(c&&c.pattern&&c.pattern.length!==0){const u=i.lineTypeScale||1;a=this.getLineShaderMaterial(c,o,u),e.renderOrder=ge.LineWithPattern}else a=this.getLineBasicMaterial(o)}n.material=a}setHatchMaterial(e,i,s,r,n){const a=e;if(!a.geometry)return;const o=this.getColor(i,s,n);if(a.type===N.Line||a.type===N.LineSegment){a.material=this.getLineBasicMaterial(o);return}let l=ge.Mesh,c;if(i.solidFill)c=this.getMeshBasicMaterial(o);else{if(a.material instanceof d.ShaderMaterial){c=a.material;const u=new d.Color(o);!a.material.uniforms.u_color.value.equals(u)&&(c=a.material.clone(),j.updateMaterialUniforms(c),c.uniforms.u_color.value.set(o))}else c=this.getHatchShaderMaterial(i,o,r);l=ge.MeshWithPattern}!c&&(c=this.getMeshBasicMaterial(o),l=ge.Mesh),a.material=c,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=ge.Mesh:i.isLine?s=ge.Line:i.isPoints&&(s=ge.Point),e.renderOrder=s}getPointsMaterial(e){return!this.pointsMaterials[e]&&(this.pointsMaterials[e]=new d.PointsMaterial({size:.2,color:e})),this.pointsMaterials[e]}getLineBasicMaterial(e){return!this.lineBasicMaterials[e]&&(this.lineBasicMaterials[e]=new d.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,i,s){const r=e.name+"_"+i+"_"+s;if(!this.lineShaderMaterials[r]){const n=this.getLineTypeScales(),a=n.ltScale*n.celtScale*s;this.lineShaderMaterials[r]=xn.createLineShaderMaterial(e.pattern,i,a,j.ViewportScaleUniform,j.CameraZoomUniform)}return this.lineShaderMaterials[r]}getMeshBasicMaterial(e){return!this.meshBasicMaterials[e]&&(this.meshBasicMaterials[e]=new d.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getHatchShaderMaterial(e,i,s){if(!e.patternLines||e.patternLines.length<1)return;const r=this.findMatchedHatchShaderMaterial(e,i);if(r)return r;const n=.005,a=.05;let o=2;e.patternLines.forEach(m=>{o=Math.max(m.dashPattern.length,o)});let l=0;const c=[],u=new d.Vector2;for(const m of e.patternLines){const g=new d.Vector2(m.origin.x,m.origin.y).sub(s).rotateAround(u,-d.MathUtils.degToRad(e.patternAngle)),x=new d.Vector2(m.delta.x,m.delta.y).rotateAround(u,-d.MathUtils.degToRad(m.angle));if(x.y===0)return S.warn("[Dxf] delta.y is equal to zero !"),void 0;const y=m.dashPattern.length;let T=!0,v=0;for(let w=0;w<y;++w){const M=m.dashPattern[w];M>0&&(T=!1),v+=Math.abs(M)}const b=T?a:n,E=[],O=[];let _=0;O[0]=_;for(let w=0;w<y;++w)E[w]=m.dashPattern[w],E[w]===0&&(E[w]=b*v),_+=Math.abs(E[w]),O[w+1]=_;for(let w=y;w<o;++w)E[w]=0;for(let w=O.length;w<o+1;++w)O[w]=_;const C={origin:g,delta:x,angle:m.angle-e.patternAngle,pattern:E,patternSum:O,patternLength:_};if(l+=4,l+=o,l+=o+1,l>j.MaxFragmentUniforms){S.warn("[Dxf] There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}c.push(C)}const f=bn(c,e.patternAngle,j.CameraZoomUniform,new d.Color(i),this.overrideHatchPatternLineThickness);return f.defines={MAX_PATTERN_SEGMENT_COUNT:o},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:i,material:f}),f}getDivision(e,i,s){let r=Math.round(5e4/this.entityCount);r=Math.max(r,2),r=Math.min(r,10);const n=r*5;let o=r*2;if(this.averageCurveSize){const u=Math.pow(s/this.averageCurveSize,.5);o*=u,o=Math.max(o,r),o=Math.min(o,n)}let l=i-e;l<0&&(l+=Math.PI*2),o=Math.ceil(o*(l/Math.PI));let c=8;return l<.087?c=2:l<.174?c=3:l<.52?c=4:l<1.57?c=5:l<3.14?c=6:l<4.71&&(c=7),o=Math.max(o,c),this.averageCurveSize=(this.averageCurveSize*this.curveCount+s)/(this.curveCount+1),this.curveCount++,Math.max(o,12)}getBSplineInterpolationsPerSplineSegment(e,i){let s=1;this.averageCurveSize&&(s=Math.pow(i/this.averageCurveSize,.5),s=Math.max(s,.5),s=Math.min(s,2)),this.averageCurveSize=(this.averageCurveSize*this.curveCount+i)/(this.curveCount+1),this.curveCount++;let r=e*2*s;if(e>20){const n=Math.log10(e);r/=n}return r}async setDxfDataToIndexedDb(e,i){const s={dxfDataId:e,dxf:i};return new Promise((r,n)=>{Wi.instance().add(s,()=>{S.info("[Dxf] Saved '"+e+"' to indexedDb"),r()},a=>{n(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{Wi.instance().query(e,r=>{r&&r.length>0&&i(r[0].dxf),i(void 0)},()=>s())})}buildContainHierarchyTree(e,i,s){const r=new Map,n=s.length;for(let o=0;o<n;o++)r.set(s[o],{index:s[o],children:[]});const a={index:-1,children:[]};for(let o=0;o<n;o++){const l=s[o],c=e[l],u=i[l];let f=o+1;for(;f<n;f++){const m=s[f],g=e[m];if(i[m].containsBox(u)&&U.isPointInPolygon(c[V.generateRandomInt(0,c.length-1)],g)){r.get(m)?.children.push(r.get(l));break}}f===n&&a.children.push(r.get(l))}return a}buildHatchGeometry(e,i,s){if(i.children.length===0)return;const r=[],n=new Map;i.children.forEach(l=>{l.children.length===0?r.push(l.index):n.set(l.index,l.children.map(c=>c.index))});const a=l=>{try{const c=new d.ShapeGeometry(l);c.hasAttribute("uv")&&c.deleteAttribute("uv"),c.hasAttribute("normal")&&c.deleteAttribute("normal"),s.push(c)}catch{S.warn("[Dxf] triangulate shape error: "+l.getPoints().map(u=>u.toArray()).toString())}};r.forEach(l=>{const c=e[l];if(c.length===0)return;const u=new d.Shape(c);a(u)});const o=l=>l.map(c=>c.toArray());for(const l of n){const c=new d.Shape(e[l[0]]);let u={regions:[],inverted:!1};const f=this.findIntersectHole(e,l[1]);f.forEach(g=>{let x={regions:[],inverted:!1};try{g.forEach((y,T)=>{if(yt.epsilon(R.getVector2RelativeEps(e[y][0]),1e-6),T===0)x=yt.segments({regions:[o(e[y])],inverted:!1});else{const v=yt.segments({regions:[o(e[y])],inverted:!1}),b=yt.combine(x,v);u=yt.polygon(yt.selectUnion(b)),u.regions.length>0?u.regions.forEach(E=>{if(E.length===0)return;const O=E.map(_=>new d.Vector2(_[0],_[1]));c.holes.push(new d.Path(O))}):S.warn("[Dxf] mergedHoles.regions is empty")}})}catch(y){S.warn("[Dxf] polybooljs has error: "+y+", epsilon is "+yt.epsilon())}});const m=f.flat(2);for(let g=0;g<l[1].length;g++){const x=l[1][g];!m.includes(x)&&c.holes.push(new d.Path(e[x]))}a(c)}i.children.forEach(l=>{l.children.forEach(c=>{this.buildHatchGeometry(e,c,s)})})}findIntersectHole(e,i){const s=i.length,r=[];for(let n=0;n<s;n++){const a=e[i[n]];let o=!1;const l=[];for(let c=n+1;c<s;c++){const u=e[i[c]];U.arePolygonsIntersect(a,u)&&(o=!0,l.push(i[c]))}o&&(l.push(i[n]),r.push(l))}return r}checkAndRebasePolygonsOnRTC(e,i){if(!this.enableRTC||e.length===0)return!1;let s=0;e.forEach(n=>{n.forEach(a=>{i.add(a),s++})}),i.divideScalar(s);let r=!1;if(this.enableRTC&&U.shouldRebasePositionOnRTC(i)){r=!0;for(let n=0;n<e.length;n++){const a=e[n];for(let o=0;o<a.length;o++){const l=a[o].x-i.x,c=a[o].y-i.y;a[o]=new d.Vector2(l,c)}}}else i.set(0,0);return r}setRTCUserData(e){e.userData.relativeToCenter=!0,this.statsInfo.rebasedEntityCount++}IsfilteredByPathTypeFlag(e){return e<0}findSpatialFilterByHandle(e,i){const s=i.objects.DICTIONARY;if(!s)return;if(!this.dictionaryOwnerHandleAndSpatialFilterHandlesCache){this.dictionaryOwnerHandleAndSpatialFilterHandlesCache={};for(const n of s){const a=n;let o="";for(const l in a.entries)if(a.entries[l]==="ACAD_FILTER"){o=l;break}o&&(this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[n.ownerHandle]&&S.warn("[Dxf] Why this.dictionaryObjectsCache[obj.ownerHandle] already exist?",n.ownerHandle),this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[n.ownerHandle]=o)}}const r=this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[e];if(r){if(!this.spatialFiltersCache){this.spatialFiltersCache={};const n=i.objects.SPATIAL_FILTER||[];for(const a of n){const o=a;o.numberOfPointsOnClipBoundary<2||(this.spatialFiltersCache[o.ownerHandle]&&S.warn("[Dxf] Why this.spatialFiltersCache[spatialFilterObj.ownerHandle] already exist?",r),this.spatialFiltersCache[o.ownerHandle]=o)}}return this.spatialFiltersCache[r]}}initRenderOrderInfo(e){const i=new Set,s=e.objects.DICTIONARY;for(const n of s){const a=n;Object.keys(a.entries).forEach(o=>{a.entries[o]&&a.entries[o]==="ACAD_SORTENTS"&&i.add(o)})}if(i.size===0)return;const r=e.objects.SORTENTSTABLE;if(r)for(let n=0;n<r.length;++n){const a=r[n];if(i.has(a.handle)){for(let o=0;o<a.sortEntsObject.entityHandles.length;++o){const l=a.sortEntsObject.entityHandles[o];l.length===2&&!this.entityHandlesWithRenderOrder[l[0]]?this.entityHandlesWithRenderOrder[l[0]]=l[1]:S.warn("[Dxf] Failed to handle sortEntsTable: "+a.handle+".")}break}}}findMatchedHatchShaderMaterial(e,i){const s=e.patternLines;if(!s||s.length<1)return;const r=(c,u)=>Math.abs(c-u)<1e-5,n=(c,u)=>{if(c.length!==u.length)return!1;for(let f=0;f<c.length;++f)if(!r(c[f],u[f]))return!1;return!0},a=(c,u)=>r(c.angle,u.angle)&&r(c.delta.x,u.delta.x)&&r(c.delta.y,u.delta.y)&&r(c.origin.x,u.origin.x)&&r(c.origin.y,u.origin.y)&&n(c.dashPattern,u.dashPattern),o=(c,u)=>{if(c.length!==u.length)return!1;for(let f=0;f<c.length;++f)if(!a(c[f],u[f]))return!1;return!0};return this.hatchShaderMaterials.find(c=>c.color===i&&c.patternAngle===e.patternAngle&&o(c.patternLines,s))?.material}getLayout(e,i){if(!this.blockRecordsCache){this.blockRecordsCache={};const n=this.blockRecordsCache,a=e.tables?.blockRecord?.blockRecords;a&&Object.values(a).forEach(o=>{n[o.handle]=o.layoutHandle})}const s=this.blockRecordsCache[i.ownerHandle];if(s){const n=e.objects.LAYOUT,a=n.find(o=>o.handle===s);if(a)return a}if(!this.entitiesCache){this.entitiesCache={};const n=this.entitiesCache;Object.values(e.entities).forEach(a=>{n[a.handle]=a})}const r=this.entitiesCache[i.ownerHandle];return r?this.getLayout(e,r):e.objects.LAYOUT.find(n=>n.layoutName===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=r=>{let n;if(Array.isArray(r)){const a=[];n=a,r.forEach(o=>{if(i.has(o.id))a.push(i.get(o.id));else{const l=o.clone();j.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else r&&(i.has(r.id)?n=i.get(r.id):(n=r.clone(),j.updateMaterialUniforms(n),i.set(r.id,n)));return n};e.traverse(r=>{r.material&&(r.material=s(r.material))})}getLineTypeScales(){const e={ltScale:1,celtScale:1};return this.header&&(e.ltScale=this.header.$LTSCALE||1,e.celtScale=this.header.$CELTSCALE||1),e}static getDxfUnits(e){switch(e||0){case 0:return De.Unitless;case 1:return De.Inches;case 2:return De.Feet;case 4:return De.Millimeters;case 5:return De.Centimeters;case 6:return De.Meters;default:S.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return De.Unitless}static computeLineDistance(e){const i=e.isLineSegments===!0;let s=e.geometry;const r=e.matrixWorld;if(s.index&&(S.debug("[Dxf] Line with id '"+e.id+"' contains index buffer, going to convert it to non-indexed."),s=U.convertGeometryWithIndexedToNonIndexed(s),e.userData.batches&&e.userData.batches.length>0)){S.debug("[Dxf] This line has been merged!");let n=0;e.userData.batches.forEach(a=>{a.positionStart=n,a.positionCount=a.indexCount,a.indexStart=0,a.indexCount=0,n+=a.positionCount})}if(s.index===null){const n=s.attributes.position;if(!n||n.count===0)return;const a=[];if(i)for(let o=0,l=n.count;o<l;o+=2)z.fromBufferAttribute(n,o).applyMatrix4(r),Z.fromBufferAttribute(n,o+1).applyMatrix4(r),a[o]=o===0?0:a[o-1],a[o+1]=a[o]+z.distanceTo(Z);else{a[0]=0;for(let o=1,l=n.count;o<l;o++)z.fromBufferAttribute(n,o-1).applyMatrix4(r),Z.fromBufferAttribute(n,o).applyMatrix4(r),a[o]=a[o-1],a[o]+=z.distanceTo(Z)}s.setAttribute("lineDistance",new d.Float32BufferAttribute(a,1)),e.geometry=s}else S.warn("[Dxf] computeLineDistances only possible with non-indexed BufferGeometry.")}static computeLineDistances(e){const i=Date.now();e.traverse(s=>{const r=s;r.isLine&&r.material instanceof d.ShaderMaterial&&j.computeLineDistance(r)}),S.debug("[Dxf] Computed line distances in "+(Date.now()-i)/1e3+"s")}static mergeDxfObjects(e){const i=Date.now(),s={},r={},n=15e3;let a=0,o=0;const l=()=>{const u=Date.now();for(const f in s){const m=s[f];j.removeEmptyObjectsFromRemovingMarkedObjects2(m.children,m.object),m.children=[]}a=0,o+=Date.now()-u};for(const u in e.layersAndObjects){const f=e.layersAndObjects[u];if(f.length<=1)continue;const m=Date.now(),g={},x=[];for(const y of f){if(y.userData.isSnapObject){x.push(y);continue}let T,v=y;for(;v;){if(v.userData.isLayoutLevelObject){T=v;break}v=v.parent}if(!T)continue;const b=T.name;!g[b]&&(g[b]={object:T,children:[]}),g[b].children.push(y)}for(const y in g){const T=g[y],v=Qe.deepMerge(T.children,T.object,!1,!1,!0),b=v.added,E=v.removed;!s[y]&&(s[y]={object:T.object,children:[]}),!r[y]&&(r[y]={object:T.object,children:[]});const O=E.length>n;if(O){const _=Date.now();j.removeEmptyObjectsFromRemovingMarkedObjects2(E,T.object),o+=Date.now()-_}else a+=E.length;if(E.length===T.children.length)!O&&E.forEach(_=>{s[y].children.push(_)});else{let _=E;E.length>=100&&(_=new Set(E));const C=w=>Array.isArray(_)?_.indexOf(w)>=0:_.has(w);for(let w=0;w<T.children.length;w++){const M=T.children[w];C(M)?!O&&s[y].children.push(M):x.push(M)}}for(let _=0;_<b.length;_++){const C=b[_];x.push(C),r[y].children.push(C)}a>n&&l()}e.layersAndObjects[u]=x,S.debug("[Dxf] Merged layer '"+u+"' in "+(Date.now()-m)/1e3+"s")}a>0&&l();for(const u in r){const f=r[u];!e.root.children.find(g=>g.name===u)&&e.root.add(f.object),f.children.forEach(g=>{f.object.add(g)}),f.children=[]}S.debug("[Dxf] MergeUtils.deepMerge took "+oe.MergeInfo.elapsedTime/1e3+"s"),S.debug("[Dxf] The remove operation of deep merge took "+o/1e3+"s"),S.debug("[Dxf] Deep merge totally took "+(Date.now()-i)/1e3+"s");const c=oe.MergeInfo;S.debug("[Dxf] Totally merged "+c.removedObjects+" objects to "+c.mergedMeshes+"meshes, "+c.mergedLines+"lines, "+c.mergedPoints+"points, "+(c.mergedUnknownTypeObjects?c.mergedUnknownTypeObjects+" unknown type,":" ")+" ")}static async merge(e,i){const s=V.getUpdateProgressFuncAsync(i),r={};e.objects.LAYOUT.forEach(y=>{const T=y;r[T.layoutName]=T,T.directAssociatedLeafObjectSet?.clear()});const n=Date.now(),a={},o={},l=15e3;let c=0,u=0;const f=()=>{const y=Date.now();for(const T in a){const v=a[T];j.removeEmptyObjectsFromRemovingMarkedObjects(v.children,v.object),v.children=[]}c=0,u+=Date.now()-y},m=Object.keys(e.layersAndThreejsObjects).length;let g=0;for(const y in e.layersAndThreejsObjects){const T=e.layersAndThreejsObjects[y];if(T.length<=1){await s(++g/m*100);continue}const v=Date.now(),b={},E=[];for(const C of T){if(C.userData.isSnapObject){E.push(C);continue}let w,M=C;for(;M;){if(M.userData.isLayoutLevelObject){w=M;break}M=M.parent}if(!w)continue;const P=w.name;!b[P]&&(b[P]={object:w,children:[]}),b[P].children.push(C)}const O=Object.keys(b).length;let _=0;for(const C in b){let w;if(C!==j.MODEL_LAYOUT_NAME){const B=r[C];!B.directAssociatedLeafObjectSet&&(B.directAssociatedLeafObjectSet=new Set),w=B.directAssociatedLeafObjectSet}const M=b[C],P=oe.deepMerge(M.children,M.object,!1,!1,!0),A=P.added,I=P.removed;!a[C]&&(a[C]={object:M.object,children:[]}),!o[C]&&(o[C]={object:M.object,children:[]});const k=I.length>l;if(k){const B=Date.now();j.removeEmptyObjectsFromRemovingMarkedObjects(I,M.object),u+=Date.now()-B}else c+=I.length;if(I.length===M.children.length)!k&&I.forEach(B=>{a[C].children.push(B)});else{let B=I;I.length>=100&&(B=new Set(I));const L=q=>Array.isArray(B)?B.indexOf(q)>=0:B.has(q);for(let q=0;q<M.children.length;q++){const me=M.children[q];L(me)?!k&&a[C].children.push(me):(E.push(me),w&&w.add(me))}}for(let B=0;B<A.length;B++){const L=A[B];$.setSharedVariablesOfObject(L),E.push(L),o[C].children.push(L),w&&w.add(L)}c>l&&f(),await s((g+ ++_/O)/m*100)}await s(++g/m*100),e.layersAndThreejsObjects[y]=E,S.debug("[Dxf] Merged layer '"+y+"' in "+(Date.now()-v)/1e3+"s")}c>0&&f();for(const y in o){const T=o[y],v=e.threejsObject.children.find(b=>b.name===y);if(v){const b=v.children.find(E=>E.name===j.SNAP_GROUP_NAME);if(b&&y!==j.MODEL_LAYOUT_NAME){const E=r[y];!E.directAssociatedLeafObjectSet&&(E.directAssociatedLeafObjectSet=new Set),b.children.forEach(O=>E.directAssociatedLeafObjectSet?.add(O))}}!v&&e.threejsObject.add(T.object),T.children.forEach(b=>{!b.visible&&(b.userData.layerVisible=!1),T.object.add(b),b.updateWorldMatrix(!1,!1)}),T.children=[]}S.debug("[Dxf] MergeUtils.deepMerge took "+oe.MergeInfo.elapsedTime/1e3+"s"),S.debug("[Dxf] The remove operation of deep merge took "+u/1e3+"s"),S.debug("[Dxf] Deep merge totally took "+(Date.now()-n)/1e3+"s");const x=oe.MergeInfo;S.debug("[Dxf] Totally merged "+x.removedObjects+" objects to "+x.mergedMeshes+"meshes, "+x.mergedLines+"lines, "+x.mergedPoints+"points, "+(x.mergedUnknownTypeObjects?x.mergedUnknownTypeObjects+" unknown type,":" ")+" "),s(100)}printStatsInfo(){const e=this.entityTypesAndTimes;for(const r in e)e[r].averageTime=e[r].totalTime/e[r].createCount;S.debug("[Dxf] Entity types and took how much time in ms:",e),S.debug("[Dxf] Entity types and mesh count:",this.statsInfo.entityTypesAndMeshCount);let i=0;if(Object.values(this.statsInfo.entityTypesAndMeshCount).forEach(r=>{i+=r}),this.enableRTC&&S.debug("[Dxf] Totally rebased "+this.statsInfo.rebasedEntityCount+"(out of "+i+") entities"),this.enableMerge){const r=oe.MergeInfo;S.debug("[Dxf] Inner merged "+r.removedObjects+" objects to "+r.mergedMeshes+"meshes, "+r.mergedLines+"lines, "+r.mergedPoints+"points, "+(r.mergedUnknownTypeObjects?r.mergedUnknownTypeObjects+" unknown type,":" ")+"in "+r.elapsedTime/1e3+"s")}const s=(r,n,...a)=>{Object.keys(n).length>0};s("[Dxf] Unsupported entity types and count:",this.statsInfo.unsupportedEntityTypes),s("[Dxf] Unsupported text style names and count:",this.statsInfo.unsupportedTextStyles,". Will use a default style."),s("[Dxf] Unsupported hatch pattern names and count:",this.statsInfo.unsupportedHatchPatterns,". Filling in solid lines instead."),this.statsInfo.unsupportedPolylineCount&&S.warn("[Dxf] Unsupported polyline (with both width and linetype) count: "+this.statsInfo.unsupportedPolylineCount+", linetype will be ignored."),s("[Dxf] Ignored invisible entity types and count:",this.statsInfo.invisibleEntities),s("[Dxf] Ignored frozen layers and entity count:",this.statsInfo.ignoredFrozenLayersAndEntityCount),s("[Dxf] Ignored inserts and count (may because they don't contain anything):",this.statsInfo.ignoredInserts),this.ignorePaperSpace&&s("[Dxf] Ignored paper space entity count:",this.statsInfo.ignoredPaperSpaceEntityTypesAndCount),this.font&&s("[Dxf] Unsupported chars and count:",this.font.getUnsupportedChar())}static statLayoutAndLayerObjects(e){const i=new WeakSet;let s=0;for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&(s++,i.has(l)?console.warn(l):i.add(l))});const r=new WeakSet;let n=0;if(e.threejsObject.traverse(a=>{a.geometry&&(n++,r.has(a)?console.warn(a):r.add(a))}),s!=n)for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&!r.has(l)&&console.warn(l)});S.info("[Dxf] The count of layer objects is "+s+",The count of layout objects is "+n+" ")}static removeEmptyObjectsFromRemovingMarkedObjects(e,i){if(e.length===0)return;const s=r=>{const n=[];for(const a of r){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&n.push(o))}n.length>0&&s(n)};s(e),this.removeEmptyObjectsFromMark(i)}static removeEmptyObjectsFromMark(e){if(e.userData.validCount===0||$.isEmptyObject(e))return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark(e.children[i])&&++i;return!1}static removeEmptyObjectsFromRemovingMarkedObjects2(e,i){if(e.length===0)return;const s=r=>{const n=[];for(const a of r){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&n.push(o))}n.length>0&&s(n)};s(e),this.removeEmptyObjectsFromMark2(i)}static removeEmptyObjectsFromMark2(e){if(e.userData.validCount===0||e.type===N.Object&&e.children.length===0)return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark2(e.children[i])&&++i;return!1}};p(j,"MODEL_LAYOUT_NAME","Model"),p(j,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),p(j,"SHOW_SNAP_OBJECT",!1),p(j,"REQUWSTHEADER"),p(j,"CameraZoomUniform",{value:1}),p(j,"ViewportScaleUniform",{value:1}),p(j,"TransformMatrixUniform",{value:new d.Matrix4}),p(j,"ResolutionUniform",{value:new d.Vector2}),p(j,"LOADLLDATA",!1),p(j,"MaxFragmentUniforms",1024);let Y=j;class As extends mt{constructor(e){super();p(this,"viewer");p(this,"overlayRender");p(this,"drawableList");this.drawableList=new $i("compare"),this.viewer=e,this.overlayRender=this.viewer.getOverlayRender(),this.overlayRender?.addDrawableList(this.drawableList)}drawCompareDrawable(e){const i=[],s=[],r=[];for(const l of Object.values(e)){const c=l.box;c&&(l.type===Te.Added?i.push(c):l.type===Te.Removed?s.push(c):r.push(c))}const n=U.mergeBBoxes(i),a=U.mergeBBoxes(s),o=U.mergeBBoxes(r);this.drawableList.addDrawable(new rt(V.guid(),n,[.1,.9,.2,1])),this.drawableList.addDrawable(new rt(V.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new rt(V.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class Ji{}const Pt=new d.Matrix4,fs=new d.Box3;class qt extends Ji{constructor(e){super();p(this,"modelId");p(this,"modelData");p(this,"modelObject");p(this,"bbox");this.modelData=e,this.modelId=e.modelId,this.modelObject=e.dxfData?.threejsObject||e.pdfData?.threejsObject,this.modelObject.name=this.modelId,this.modelObject.userData.modelId=this.modelId}get pdfData(){return this.modelData.pdfData}get dxfData(){return this.modelData.dxfData}get msTransformMatrix(){return this.modelData.msTransformMatrix}set msTransformMatrix(e){this.modelData.msTransformMatrix=e}get loadedEntityCount(){return this.dxfData?.loadedEntityCount||this.pdfData?.loadedEntityCount||0}get header(){return this.dxfData?.header}get viewports(){return this.dxfData?.tables.viewport.viewports}get layers(){const e=this.dxfData||this.pdfData;return e.tables?.layer.layers||e.layers}get layoutViewportsMap(){return this.dxfData?.layoutViewportsMap}getModelObject(){const e=this.dxfData||this.pdfData;if(!e)throw new Error("Failed to find model by modelId '"+this.modelId+"'!");return e.threejsObject}getBBox(){if(!this.bbox){const e=new d.Box3,i=this.getModelObject();e.setFromObject(i),this.bbox=e}return this.bbox}getUnits(){if(!this.dxfData)return De.Unitless;const e=this.dxfData.header;if(!e)return S.warn("DxfData or its header is undefined!"),De.Unitless;const i=e.$INSUNITS;return Y.getDxfUnits(i)}getModelSpaceExtent(){const e=this.header,i=new d.Vector3,s=new d.Vector3;if(!e){S.error("Header is undefined in "+this.modelId+"!");return}const r=this.viewports;let n=e.$EXTMIN,a=e.$EXTMAX;const o=e.$ANGDIR;if(r&&r.length>0)for(let l=0;l<r.length;l++){const c=r[l];if(c.name.toLocaleUpperCase()==="*ACTIVE"){const{center:u,viewHeight:f,aspectRatio:m}=c,g=f*m,x=Y.getDcs2WcsMatrix(c,o),y=new d.Vector3(u.x,u.y,0);y.applyMatrix4(x),n={x:y.x-g/2,y:y.y-f/2,z:0},a={x:y.x+g/2,y:y.y+f/2,z:0};break}}return i.set(n.x,n.y,n.z),s.set(a.x,a.y,a.z),new d.Box3(i,s)}getLayer(e){if(this.layers)return this.layers[e]}getObjectsByLayer(e){const i=this.dxfData||this.pdfData;return i?.layersAndThreejsObjects&&i.layersAndThreejsObjects[e]}getLayouts(){const e=[];return this.dxfData?.objects.LAYOUT?.forEach(r=>{e.push(r)}),e}getLayoutByName(e){let i;const s=this.getLayouts();for(const r of s)if(r.layoutName===e){i=r;break}return i}getLayoutExtent(e){const i=this.header,s=new d.Vector3,r=new d.Vector3;if(!i)throw new Error("Header is undefined in "+this.modelId+"!");const n=this.getLayoutViewports(e);let a=i.$PEXTMIN,o=i.$PEXTMAX;const l=i.$ANGDIR;if(n&&n.length>0){const c=n.filter(T=>parseInt(T.viewportId)===1);let u;c.length>0?u=c[0]:u=n[0];const{centerPoint:f,width_paperSpace:m,height_paperSpace:g}=u,x=Y.getDcs2WcsMatrix(u,l),y=new d.Vector3(f.x,f.y,0);y.applyMatrix4(x),a={x:y.x-m/2,y:y.y-g/2,z:0},o={x:y.x+m/2,y:y.y+g/2,z:0}}return s.set(a.x,a.y,a.z),r.set(o.x,o.y,o.z),new d.Box3(s,r)}getLayoutViewports(e){const s=this.layoutViewportsMap[e.ownerHandle];return s||[]}getLayoutLevelObject(e){return this.getModelObject()?.children.find(s=>s.name===e)}setVisible(e){const i=this.getModelObject();i.visible=e}setLayerVisible(e,i,s,r){const n=this.getLayer(e);n?n.visible=i:S.warn("[Viewer] Layer '"+e+"' not found from modelData!");const a=this.getObjectsByLayer(e);if(a)for(let o=0;o<a.length;o++){const l=a[o];!(s&&i&&r&&l.userData.visibleMinZoom&&r<l.userData.visibleMinZoom)&&(l.visible=i),(i===!1||l.userData.layerVisible!=null)&&(l.userData.layerVisible=i),l.userData.isSnapObject&&(l.visible?Y.SHOW_SNAP_OBJECT?l.layers.enableAll():l.layers.set(Ce):Y.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(Ce))}else S.info("[Viewer] No object found for layer '"+e+"'")}setLayerOpacity(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const r=this.getObjectsByLayer(e);r?r.forEach(n=>{const a=n;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=de.cloneMaterial(a.material));const o=de.cloneMaterial(a.material);de.setMaterialOpacity(o,i),Y.updateMaterialUniforms(o),a.material=o}}):S.info("[Viewer] No object found for layer '"+e+"'")}setLayerColor(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const r=this.getObjectsByLayer(e);r?r.forEach(n=>{const a=n;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=de.cloneMaterial(a.material));const o=de.cloneMaterial(a.material);de.setMaterialColor(o,new d.Color(i)),Y.updateMaterialUniforms(o),a.material=o}}):S.info("[Viewer] No object found for layer '"+e+"'")}resetLayerColor(e){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const s=this.getObjectsByLayer(e);s?s.forEach(r=>{const n=r;n.material&&n.userData.originalMaterial&&(n.material.dispose(),n.material=n.userData.originalMaterial,delete n.userData.originalMaterial)}):S.info("[Viewer] No object found for layer '"+e+"'")}switchTransformMs(e){const i=this.msTransformMatrix;if(Pt.identity(),!i||!V.isMatrixValid(i)||i.equals(Pt))return;const s=this.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME);s&&(e===Y.MODEL_LAYOUT_NAME?s.applyMatrix4(i):s.applyMatrix4(i.clone().invert()),s.updateMatrixWorld(!0))}activateLayout(e=Y.MODEL_LAYOUT_NAME,i){this.switchTransformMs(e);const s=this.getLayoutByName(e);if(s){if(!i){const r=this.getLayoutViewports(s);let n=[];r.length>0&&(n=r[0].frozenLayerHandles);const a=e!==Y.MODEL_LAYOUT_NAME,o=this.getLayoutLevelObject(e);if(o){const u=[];o.traverse(f=>{this.addSpatialFilterSection(f,this.dxfData);const m=f;if(a&&m.material&&m.geometry){const g=m.userData.layerName;if(this.isLayerFrozenForViewport(g,n))return;u.push(m);let x=-1;const y=this.getObjectsByLayer(g);y&&(x=y.indexOf(m),x>=0&&y.splice(x,1)),x<0&&S.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+g+"', layout '"+e+"'")}}),u.forEach(f=>{f.removeFromParent()})}const l=this.getFilteredViewports(s);S.debug("[Viewer] Active layout:",e,", viewports:",l);const c=Date.now();l.forEach(u=>{this.generateObjectsByViewport(e,u,this)}),S.info("[Viewer] generateObjectsByViewport in "+(Date.now()-c)/1e3+"s")}this.showLayoutObjects(e)}}getFilteredViewports(e){const i=this.getLayoutViewports(e);let s=i.filter(r=>r.viewportId!=="1");return s.length===i.length&&(s=i.filter((r,n)=>n!==0)),s}generateObjectsByViewport(e,i,s,r=[]){const n=i;if(i.viewportId=="1")return;if(!n.psBBox||!n.msToPsMatrix)throw new Error("The bbox or matrix is invalid in the viewport!");Y.TransformMatrixUniform={value:n.msToPsMatrix},Y.ViewportScaleUniform={value:i.viewHeight/i.height_paperSpace};const a=n.psBBox.clone();a.applyMatrix4(n.msToPsMatrix.clone().invert()),a.min.setZ(-1),a.max.setZ(1);const o=this.getObjectsByBoundingBox(a);if(o.length===0)return;const l=n.psBBox.min,c=n.psBBox.max,u=new d.Box2(new d.Vector2(l.x,l.y),new d.Vector2(c.x,c.y)),f=dt.generateSectionPlanesByBox(u),m=[],g=M=>(!m[M.id]&&(m[M.id]=M.clone(),this.setMaterialUniforms(m[M.id],s.dxfData),dt.setMaterialSection(m[M.id],f)),m[M.id]),x=M=>{if(Array.isArray(M)){const P=[];return M.forEach(A=>{const I=g(A);P.push(I)}),P}else return g(M)},y=[...r,...i.frozenLayerHandles||[]];let T;if(e!==Y.MODEL_LAYOUT_NAME){const M=n;!M.associatedLeafObjectSet&&(M.associatedLeafObjectSet=new Set),T=M.associatedLeafObjectSet}const v=new d.Group;v.name=n.viewportId;const b=[];if(o.forEach(M=>{const P=M.clone();P.traverse(A=>{const I=A;if(I.material&&I.geometry){const k=I.userData.layerName;if(this.isLayerFrozenForViewport(k,y)){b.push(I);return}I.userData.layerVisible!==!1&&(I.visible=!0),I.material=x(I.material),T?.add(I);const B=s.getObjectsByLayer(k);B?B.push(I):S.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+k+"', layout '"+e+"'")}}),v.add(P)}),T&&T.size===0)return;const E=s.getModelObject();let O=s.getLayoutLevelObject(e);!O&&(O=new d.Group,$.setSharedVariablesOfObject(O),O.name=e,E?.add(O)),O.add(v),v.applyMatrix4(n.msToPsMatrix),v.updateMatrixWorld(!0);let _=O.children.find(M=>M.name===Y.SNAP_GROUP_NAME);!_&&(_=new d.Group,_.visible=Y.SHOW_SNAP_OBJECT,_.name=Y.SNAP_GROUP_NAME,O.add(_));const C=s.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME),w=C?.children.find(M=>M.name===Y.SNAP_GROUP_NAME);w&&w.traverse(M=>{if(!M.geometry)return;const P=M.userData.layerName;if(this.isLayerFrozenForViewport(P,y)||(fs.makeEmpty(),fs.expandByObject(M),!a.intersectsBox(fs)))return;const A=M.clone();$.setSharedVariablesOfObject(A);let I=A.parent;const k=Pt.identity();for(;I&&I.userData.isLayoutLevelObject!==!0;)k.premultiply(I.matrix),I=I.parent;k.premultiply(n.msToPsMatrix),A.applyMatrix4(k),_?.add(A),T?.add(A);const B=s.getObjectsByLayer(P);B&&B.push(A)}),b.length>0&&$.removeEmptyObjectsFromRemovingObjects(b,v),v.traverse(M=>{$.setSharedVariablesOfObject(M),this.addSpatialFilterSection(M,s.dxfData,!0)})}setMaterialUniforms(e,i){e instanceof d.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=Y.CameraZoomUniform),e.uniforms.u_viewportScale&&i?.header.$PSLTSCALE===1&&(e.uniforms.u_viewportScale=Y.ViewportScaleUniform))}getObjectsByBoundingBox(e){const i=[];if(e.isEmpty())return S.warn("[Viewer] bbox is empty !"),i;const s=n=>{const a=st.getBoundingBox(n,!1);e.intersectsBox(a)&&i.push(n)},r=this.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME);return r&&r.children.forEach(n=>{n.name!==Y.SNAP_GROUP_NAME&&s(n)}),i}showLayoutObjects(e){let i=0,s=0;const r=this.getModelObject();r.children.forEach(n=>{const a=n.name===e;n.visible=a,a?i++:s++}),S.debug("[Viewer] showLayoutObjects('"+e+"') sets "+i+" layout level object(s) to visible and "+s+" to hidden for model '"+r?.name+"'")}isLayerFrozenForViewport(e,i){const s=this.getLayer(e);return s&&(s.flag&1)>0?!0:!i||i.length<=0?!1:s&&i.indexOf(s.handle)>=0}addSpatialFilterSection(e,i,s=!1){if(e.userData.entityType!=="INSERT"||!e.userData.spatialFilterHandle)return;const r=this.findSpatialFilter(e.userData.spatialFilterHandle,i);if(r){let n=s,a=!1;const o=this.getAnyMaterial(e);if(o&&(o.clippingPlanes&&(n=o.clippingPlanes.length>0),a=o.clipIntersection),n&&a!==r.clipPolylines[0].bReversed){S.warn("[Viewer] Material cannot set clipIntersection to different values at the same time. clipIntersection needs to be set to true here!");return}a=r.clipPolylines[0].bReversed;const l=this.generateSectionsBySpatialFilter(r,e.matrixWorld);if(l){const c=m=>{let g=0;return m.clippingPlanes&&(g=m.clippingPlanes.length),g+l.length>Y.MaxFragmentUniforms},u=new Set,f=m=>{u.has(m.id)||(u.add(m.id),!c(m)&&dt.setMaterialSection(m,l,n,a))};e.traverse(m=>{const g=m.material;Array.isArray(g)?g.forEach(x=>{f(x)}):g&&f(g)})}}}findSpatialFilter(e,i){const s=i.objects.SPATIAL_FILTER;if(!s)return;let r;for(const n of s)if(n.handle===e){r=n;break}return r}getAnyMaterial(e){const i=e;if(i.material)return Array.isArray(i.material)?i.material[0]:i.material;let s;for(let r=0;r<e.children.length&&(s=this.getAnyMaterial(e.children[r]),!s);r++);return s}generateSectionsBySpatialFilter(e,i){const s=e.clipPolylines[0];if(s.bConcave){S.warn("[Viewer] clipPolyline.bConcave = true is not supported yet in spatialFilter !");return}Pt.copy(i),e.localMatrix&&Pt.multiply(e.localMatrix);const r=s.polyline,n=[];r.forEach(l=>{const c=l.clone().applyMatrix4(Pt);n.push(new d.Vector2(c.x,c.y))});const a=d.ShapeUtils.isClockWise(n),o=!a&&!s.bReversed||a&&s.bReversed;return dt.generateSectionPlanesByPoints(n,o)}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}highlightObject(e){if(!this.hasObject(e))return;const i=de.clonedHighlightMaterials(e,{depthTest:!1});i&&(e.userData.originalMaterial=e.material,e.material=i)}unHighlightObject(e){if(!this.hasObject(e))return;const i=e.material;e.material=e.userData.originalMaterial,delete e.userData.originalMaterial,Array.isArray(i)?i.forEach(s=>s.dispose()):i instanceof d.Material&&i.dispose()}clearHighlight(){}}class zs extends Ji{constructor(e){super();p(this,"modelId");p(this,"bbox");p(this,"rootObject");p(this,"modelObject");p(this,"highlighUsage");p(this,"transparentUsage");p(this,"edges");p(this,"highlighedObject");this.modelId=e.modelId,this.bbox=e.bbox,this.modelObject=e.object,this.rootObject=new d.Group,this.rootObject.name="rootObject-"+this.modelId,this.rootObject.userData.modelId=this.modelId,this.highlighUsage=new d.Group,this.highlighUsage.name="highlighUsage-"+this.modelId,this.highlighUsage.layers.disable(ft),this.transparentUsage=new d.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(ft),this.rootObject.add(this.modelObject),this.rootObject.add(this.highlighUsage),this.rootObject.add(this.transparentUsage)}setDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&$.setDoubleSidedMaterialToObject(e)})}revertDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&$.revertDoubleSidedMaterialToObject(e)})}getModelObject(){return this.rootObject}getBBox(){return!this.bbox&&(this.bbox=new d.Box3,this.bbox.setFromObject(this.getModelObject())),this.bbox}async enableOutline(e,i){e&&!this.edges&&(this.edges=await $.createOutlines(this.getModelObject(),void 0,i)),this.edges&&this.edges.forEach(s=>s.visible=e)}setObjectColor(e,i){this.hasObject(e)&&e.material.color.set(i)}setObjectOpacity(e,i=.5,s,r){if(this.hasObject(e)){if(e instanceof d.InstancedMesh&&r){const n=this.createInstanceMeshById(e,r,{opacity:i});n.material.opacity*=i,e.userData.instanceId=r,e.userData.transparentedMesh=n,this.transparentUsage.add(n)}else if(oe.isMergedMesh(e)&&s){const n=this.createBatchMeshById(e,s,{opacity:i});n.material.opacity*=i,e.userData.batchId=s,e.userData.transparentedMesh=n,this.transparentUsage.add(n)}else{const n=new d.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});n&&(e.userData.originalMaterial=e.material,e.material=n)}e.userData.isTransparent=!0}}clearObjectOpacity(e,i,s){if(!this.isObjectTransparent(e))return;const{transparentedMesh:r,originalMaterial:n}=e.userData;r&&(this.transparentUsage.remove(r),delete e.userData.batchId,delete e.userData.instanceId,delete e.userData.transparentedMesh),n&&(e.material=n),delete e.userData.isTransparent}isObjectTransparent(e){const{isTransparent:i}=e.userData;return!!i}setOpacity(e=.5){this.getModelObject().traverse(i=>{i instanceof d.Mesh&&this.setObjectOpacity(i,e)})}clearOpacity(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&this.clearObjectOpacity(e)})}highlightObjectById(e,i,s){if(!this.hasObjectWithId(e))return;const r=this.getModelObject().getObjectById(e);r&&this.highlightObject(r,i,s)}highlightObject(e,i,s){if(!this.hasObject(e))return;const r=new d.Color(Bs);if(e instanceof d.InstancedMesh&&s){const n=this.createInstanceMeshById(e,s,{depthTest:!1});n.material.opacity=.7,de.setMaterialColor(n.material,r),e.userData.instanceId=s,e.userData.clonedMesh=n,this.highlighUsage.add(n)}else if(oe.isMergedMesh(e)&&i){const n=this.createBatchMeshById(e,i,{depthTest:!1});n.material.opacity=.7,de.setMaterialColor(n.material,r),e.userData.batchId=i,e.userData.clonedMesh=n,this.highlighUsage.add(n)}else{const n=de.clonedHighlightMaterials(e,{depthTest:!1});n&&(e.userData.originalMaterial=e.material,e.material=n)}e.userData.isHighlight=!0,this.highlighedObject=e}clearHighlight(){if(this.highlighedObject&&this.highlighedObject.userData){const e=this.highlighedObject.userData,{clonedMesh:i,originalMaterial:s,instanceId:r,originalMatrix:n}=e;i&&(i.removeFromParent(),i.geometry.dispose(),delete e.clonedMesh),r&&n&&(this.highlighedObject.setMatrixAt(r,n),delete e.instanceId,delete e.originalMatrix),s&&(this.highlighedObject.material=s,delete e.originalMaterial),delete e.isHighlight}this.highlighUsage.clear(),this.highlighedObject=void 0}setObjectVisible(e,i){this.hasObject(e)&&(e.visible=i)}setVisible(e){this.getModelObject().traverse(i=>{i instanceof d.Mesh&&(i.visible=e)})}hasVisibleObject(){let e=0;return this.modelObject.traverseVisible(i=>{i instanceof d.Mesh&&e++}),e>0}hasInvisibleObject(){let e=0;return this.modelObject.traverse(i=>{i instanceof d.Mesh&&e++}),this.modelObject.traverseVisible(i=>{i instanceof d.Mesh&&e--}),e>0}createBatchMeshById(e,i,{opacity:s=1,depthTest:r=!0}){const n=oe.getBatchByBatchId(e,i);let a="[Viewer] Clicked on merged mesh(id: "+e.id+").";a+=" batchId: "+i+", object name: "+n?.name,n?.userData&&(a+=`
796
+ `){f=0,m-=g*.5;continue}let C=this.font?.getCharShape?.(_,i?.fontFile,s);if(!C&&i?.bigFontFile&&(C=this.font?.getCharShape?.(_,i.bigFontFile,s)),!C&&this.font?.fileNames){const w=this.font.fileNames.filter(M=>M!==i?.fontFile);for(let M=w.length-1;M>=0&&(i.fontFile=w[M],i.styleName="Standard",C=this.font?.getCharShape?.(_,i.fontFile,s),!C);M--);}if(C||(C=this.font?.getNotFoundTextShape?.(s)),!!C){if(C.translate(f,m,0),f>o)f=0,m-=g;else{!C.boundingBox&&C.computeBoundingBox();const w=C.boundingBox.getSize(j).x,M=_.charCodeAt(0),A=M>=19968&&M<=40959||M>=13312&&M<=19903||M>=63744&&M<=64255||M>=12288&&M<=12351||M>=65280&&M<=65519||[8216,8217,8220,8221].includes(M)?Math.max(w,s):w+T;E++,f+=A+(E===b?0:l)}u.push(C)}}if(u.length>0){const O=u.filter(C=>C instanceof d.ExtrudeGeometry),_=u.filter(C=>!(C instanceof d.ExtrudeGeometry));if(O.length>0){const C=new F(H.Mesh);C.geometry=xe.mergeGeometries(O),C.material=_t,c.add(C)}if(_.length>0){const C=new F(H.LineSegment);C.geometry=xe.mergeGeometries(_),C.material=le,c.add(C)}}return c}transformTextMesh(e,i){We.makeEmpty();const s=F.getBox(i,We),r=s.getSize(j),{halign:n,valign:a}=e;i.matrix.decompose(_i.position,_i.quaternion,_i.scale);const o=_i,l=e.width||e.textWidth||r.x,c=e.height||e.textHeight||r.y;if(n===void 0&&a===void 0&&e.startPoint||[3,5].includes(n)&&e.startPoint?(o.position.x+=e.startPoint.x,o.position.y+=e.startPoint.y,o.position.z+=e.startPoint.z):e.endPoint&&(o.position.x+=e.endPoint.x,o.position.y+=e.endPoint.y,o.position.z+=e.endPoint.z),n!==3&&n!==5){if(e.rotation){const u=e.rotation*Math.PI/180;o.rotateZ(u)}e.mirrored&2&&o.rotateY(Math.PI),e.mirrored&4&&o.rotateX(Math.PI)}switch(n){case 0:break;case 1:o.translateX(-l/2);break;case 2:o.translateX(-l);break;case 3:if(e.startPoint&&e.endPoint){const u=new d.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new d.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new d.Vector3().subVectors(u,f),g=m.length(),x=g/l;o.scale.multiplyScalar(x);const y=m.clone().cross(Ae),T=m.angleTo(Ae);o.rotateZ(y.z>0?Math.PI-T:T-Math.PI),(e.mirrored===2||e.mirrored===4)&&o.rotateX(Math.PI)}break;case 4:o.translateX(-l/2),o.translateY(-c/12);break;case 5:if(e.startPoint&&e.endPoint){const u=new d.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new d.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new d.Vector3().subVectors(u,f),g=m.length(),x=g/l,T=(e.text||"").length;if(T>1){const E=(g-l)/(T-1);o.userData.letterSpacing=E}else x<3&&o.scale.setX(x);const v=m.clone().cross(Ae),b=m.angleTo(Ae);o.rotateZ(v.z>0?Math.PI-b:b-Math.PI)}break}switch(a){case 0:break;case 1:break;case 2:o.translateY(-c/2);break;case 3:o.translateY(-c);break}return o.position.z=0,o.updateMatrix(),i.matrix.copy(o.matrix),i}loadText(e,i,s){const r=e.text;if(!r)return;if(!this.font){S.info("[Dxf] Font file not set, ignoring text entity.");return}const n=this.getTextStyle(i,e),o=Ni(r,{encoding:this.getTextEncoding(n)}).map(u=>u.text).join(""),l=this.getTextMesh(o,e.textHeight,n,e);if(!l||l.children.length===0)return;this.transformTextMesh(e,l),j.set(l.matrix.elements[12],l.matrix.elements[13],l.matrix.elements[14]);const c=U.shouldRebasePositionOnRTC(j);return c&&this.setRTCUserData(l),l.userData={...l.userData,textContent:r,dxfType:"TEXT",isMText:!1,layer:e.layer||"0",handle:e.handle,entityId:e.entityId||e.handle},l.traverse(u=>{const f=u.geometry;if(f){if(u.userData.textContent=r,u.userData.dxfType="TEXT",u.userData.layer=e.layer||"0",u.userData.handle=e.handle,u instanceof d.Mesh&&!f.getIndex()){const m=f.getAttribute("position"),g=[];for(let x=0;x<m.count;x+=3)g.push(x,x+1,x+2);f.setIndex(g)}if(f.hasAttribute("uv")&&f.deleteAttribute("uv"),f.hasAttribute("normal")&&f.deleteAttribute("normal"),!c){const m=U.caculateGeometryCenter(f);m&&U.shouldRebasePositionOnRTC(m)&&this.setRTCUserData(u)}}}),l.layers.enableAll(),l}loadAttDef(e,i,s){let r=e.tag||e.text||e.prompt;if(!r||!this.font)return;const n=this.getTextStyle(i,e);r=Ni(r).map(c=>c.text).join();const o=this.getTextMesh(r,e.textHeight,n,e);if(!o||o.children.length===0)return;this.transformTextMesh(e,o),j.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=U.shouldRebasePositionOnRTC(j);return l&&this.setRTCUserData(o),o.traverse(c=>{const u=c.geometry;if(u){if(c instanceof d.Mesh&&!u.getIndex()){const f=u.getAttribute("position"),m=[];for(let g=0;g<f.count;g+=3)m.push(g,g+1,g+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),!l){const f=U.caculateGeometryCenter(u);f&&U.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(c)}}}),o.layers.enableAll(),o}loadAttrib(e,i,s){let r=e.text;if(!r||!this.font)return;const n=this.getTextStyle(i,e);r=Ni(r).map(c=>c.text).join("");const o=this.getTextMesh(r,e.textHeight,n,e);if(!o||o.children.length===0)return;o.userData.llbData=s?.zdysx,o.userData.textContent=r||"",o.userData.dxfType="ATTRIB",o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",this.transformTextMesh(e,o),j.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=U.shouldRebasePositionOnRTC(j);return l&&this.setRTCUserData(o),o.traverse(c=>{const u=c.geometry;if(u){if(c instanceof d.Mesh&&!u.getIndex()){const f=u.getAttribute("position"),m=[];for(let g=0;g<f.count;g+=3)m.push(g,g+1,g+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),c instanceof d.Mesh&&(c.entity=e,c.userData.entity=e),c.userData.textContent=r,c.userData.dxfType="ATTRIB",c.userData.layer=e.layer||"0",c.userData.handle=e.handle||"",!l){const f=U.caculateGeometryCenter(u);f&&U.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(c)}}}),o.layers.enableAll(),o}loadPoint(e,i,s){if(!e.position)return;const r=new d.BufferGeometry,n=[new d.Vector3(e.position.x,e.position.y,e.position.z)];j.set(0,0,0);const a=j;let o=!1;this.enableRTC&&(o=U.checkAndRebasePositionsOnRTC(n,a)),r.setFromPoints(n);const l=new F(H.Point);return l.geometry=r,l.material=le,o&&(this.setRTCUserData(l),l.matrix.setPosition(a.x,a.y,0)),l.layers.enableAll(),l}loadDimension(e,i){if(!e.block)return;const s=i.blocks[e.block];if(!s||!s.entities)return;const r=i.tables.dimStyle.dimStyles[e.dimStyleName]||this.getDefaultDimensionStyle(i);r&&r.DIMCLRD>0&&(e.colorIndex=r.DIMCLRD,e.color=Nt(e.colorIndex));const n=new F;for(let o=0;o<s.entities.length;o++){const l=this.loadEntity(s.entities[o],i,e);l&&n.add(l)}if(n.children.length===0){const o=e.name||e.block;return!this.statsInfo.ignoredInserts[o]&&(this.statsInfo.ignoredInserts[o]=0),this.statsInfo.ignoredInserts[o]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const o=this.blockReferencesCache[e.block];o.referenceCount++}n.name=e.type+"<"+s.name+">",n.userData.entityType=e.type;const a=e.insertionPoint;return j.set(0,0,0),a&&j.set(a.x,a.y,0),U.shouldRebasePositionOnRTC(j)&&this.setRTCUserData(n),n.matrix.setPosition(j),n}loadImage(e,i,s){if(!e.imageSize||!i.objects.IMAGEDEF?.length)return;const r=i.objects.IMAGEDEF.filter(y=>y.handle===e.imageDefHandle)[0];if(!r)return;const n=e.imageSize.x,a=e.imageSize.y,o=new F;let l=!1;e.flags===Gi.ShowImageWhenNotAlignedWithScreen||e.flags===Gi.UseClippingBoundary||e.flags===Gi.TransparencyIsOn||(l=!0);const c=new d.PlaneGeometry(n,a);if(l){const y=new d.TextureLoader(this.manager).load(r.filename,void 0,void 0,()=>{console.warn("Please upload the pictures in the same folder, or use url link in the dxf file.")});y.colorSpace=d.SRGBColorSpace;const T=new d.MeshBasicMaterial({transparent:!0,side:d.FrontSide,map:y}),v=new F(H.Mesh);v.geometry=c,v.material=T,o.add(v)}const u=new d.EdgesGeometry(c),f=this.getColor(e,i,s),m=new F(H.Line);m.geometry=u,m.material=this.getLineBasicMaterial(f);const g=e.uPixel?new d.Vector3(e.uPixel.x,e.uPixel.y,e.uPixel.z):new d.Vector3(r.pixelSize.x,0,0),x=e.vPixel?new d.Vector3(e.vPixel.x,e.vPixel.y,e.vPixel.z):new d.Vector3(r.pixelSize.y,0,0);if(o.add(m),Z.set(g.x,x.y,1),j.set(0,0,0),e.position){const y=new d.Vector3(e.position.x,e.position.y,e.position.z);y.add(g.multiplyScalar(n/2)).add(x.multiplyScalar(a/2)),j.copy(y)}return U.shouldRebasePositionOnRTC(j)&&this.setRTCUserData(o),he.identity(),o.matrix.compose(j,he,Z),o}loadInsert(e,i,s,r=!1){if(!e||!e.block)return;const n=i.blocks[e.block];if(!n||!n.entities)return;s&&e.layer==="0"&&(e.layer=s.layer),e.blockPosition=n.position;const a=new F;for(let f=0;f<n.entities.length;f++){if(n.entities[f].type==="ATTDEF")continue;const m=this.loadEntity(n.entities[f],i,e,r);m&&(e&&e.zdysx&&V.LOADLLDATA&&(m.userData.llbData=e.zdysx),a.add(m))}if(a.children.length===0){const f=e.name||e.block;return!this.statsInfo.ignoredInserts[f]&&(this.statsInfo.ignoredInserts[f]=0),this.statsInfo.ignoredInserts[f]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const f=this.blockReferencesCache[e.block];f.referenceCount++}a.name=e.type+"<"+n.name+">",a.userData.entityType=e.type,e.extendedData?.originalType&&(a.userData.originalType=e.extendedData?.originalType),e?.blockPosition&&a.matrix.setPosition(-e.blockPosition.x,-e.blockPosition.y,0);const o=j.set(1,1,1);e.xScale&&(o.x=e.xScale),e.yScale&&(o.y=e.yScale);const l=new d.Euler;e.rotation&&(l.z=e.rotation*Math.PI/180),he.setFromEuler(l,!1);const c=Z.set(0,0,0);e.position&&(c.x=e.position.x,c.y=e.position.y),ne.compose(c,he,o),e.extrusionDirection&&e.extrusionDirection.z<0&&ne.premultiply(Or.identity().makeScale(-1,1,1)),Fe.copy(a.matrix),a.matrix.premultiply(ne),Z.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(a);const u=this.findSpatialFilterByHandle(e.handle,i);if(u){this.loadSpatialFilter(u);const f=u;f&&f.clipPolylines&&f.clipPolylines.length>0&&(a.userData.spatialFilterHandle=u.handle,this.cloneMaterialsForSpatialFilter(a),S.debug("[Dxf] Spatial filter:",e.associatedSpatialFilter))}return a}loadSpatialFilter(e){const i=e;if(i.threejsObject)return i.threejsObject.clone();const s=e.invertBlockMatrix;ne.set(s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],s[11],0,0,0,1);const r=[];e.vertices.forEach(o=>{r.push(new d.Vector3(o.x,o.y,0))});const n={polyline:[],bConcave:!1,bReversed:!1};if(e.numberOfPointsOnClipBoundary===2)n.polyline=r;else{const o=e.numberOfPointsOnClipBoundary,l=3;if(o<l)return S.warn("[Dxf] Invalid clipBoundary: "+e.handle+" !"),void 0;let c=[],u=-1;for(let g=0;g<o;g++){const x=r[g];for(let y=o-1;y>g;y--){const T=r[y];if(R.areVector3sEqual(x,T)&&g+1<y-1&&g+1<o-1&&R.areVector3sEqual(r[g+1],r[y-1])){c.push(x),u=y;break}}if(u>0)break;c.push(x)}if(u>0)for(let g=u+1;g<o;g++)c.push(r[g]);if(c.length<l)return S.warn("[Dxf] Invalid clipBoundary: "+e.handle+"!"),void 0;const f=[],m=[];if(c.forEach(g=>{f.push(new d.Vector2(g.x,g.y)),m.push([g.x,g.y])}),!U.isConvex(f)){S.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const g=xa(m,1/0);c=[],g.forEach(x=>{c.push(new d.Vector3(x[0],x[1],0))})}!R.areVector3sEqual(c[0],c[c.length-1])&&c.push(c[0]),n.polyline=c,n.bReversed=u>0}let a;return this.enableReleaseData&&(e.vertices=[],e.matrix=[],e.invertBlockMatrix=[]),i.localMatrix=ne.clone(),i.clipPolylines=[],i.clipPolylines.push(n),a}loadLayout(e,i,s,r,n,a){if(!e.entities)return;const o=new F;for(let u=0;u<e.entities.length;u++){const f=e.entities[u];this.addViewport(f,a);const m=this.loadEntity(f,i);m&&(this.enableMerge&&et.merge(m,!1),o.add(m),m.traverse(g=>{if(g.geometry){const x=g.userData.layerName;let y=n[x];!y&&(y=[],n[x]=y),y.push(g),g.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[s.layoutName]&&(this.layoutsSnapObjectsMap[s.layoutName]=[]),this.layoutsSnapObjectsMap[s.layoutName].push(g))}}))}if(o.children.length===0)return;o.userData.layerName=e.layer;const l=s.layoutName;let c=r.children.find(u=>u.name===l);!c&&(c=new F,c.name=l,c.userData.isLayoutLevelObject=!0,r.add(c)),c.add(o),e.position&&o.matrix.setPosition(e.position.x,e.position.y,e.position.z||0)}convertEdgeToPoints(e){const i=[];if(!e)return i;switch(e.type){case Lt.Line:{const r=e;i.push(new d.Vector2(r.startPoint.x,r.startPoint.y)),i.push(new d.Vector2(r.endPoint.x,r.endPoint.y));break}case Lt.Arc:{const r=e;let n=r.startAngle*d.MathUtils.DEG2RAD,a=r.endAngle*d.MathUtils.DEG2RAD;!r.bCounterclockwise&&(n=Math.PI*2-n,a=Math.PI*2-a);const o=new d.ArcCurve(r.center.x,r.center.y,r.radius,n,a,!r.bCounterclockwise),l=this.getDivision(n,a,r.radius),c=o.getPoints(l);e.startPoint=c[0],e.endPoint=c[c.length-1],i.push(...c);break}case Lt.Ellipse:{const r=e,n=Math.sqrt(Math.pow(r.majorAxisEndPoint.x,2)+Math.pow(r.majorAxisEndPoint.y,2)),a=n*r.minorRatio,o=Math.atan2(r.majorAxisEndPoint.y,r.majorAxisEndPoint.x);let l=r.startAngle*d.MathUtils.DEG2RAD,c=r.endAngle*d.MathUtils.DEG2RAD;!r.bCounterclockwise&&(l=Math.PI*2-l,c=Math.PI*2-c);const u=new d.EllipseCurve(r.center.x,r.center.y,n,a,l,c,!r.bCounterclockwise,o),f=this.getDivision(l,c,Math.max(n,a)),m=u.getPoints(f);e.startPoint=m[0],e.endPoint=m[m.length-1],i.push(...m);break}case Lt.Spline:{const r=e,n=kr(r.controlPoints,r.degreeOfSplineCurve,r.knotValues);if(n.length===0)break;e.startPoint=n[0],e.endPoint=n[n.length-1],i.push(...n);break}case Lt.Polyline:{const r=e,n=us(r.points,r.isClosed);e.startPoint=n[0],e.endPoint=n[n.length-1],i.push(...n);break}}return i}loadHatch(e,i,s){const r=e;let n=[];function a(O,_){const{startPoint:C,endPoint:w}=O,{startPoint:M,endPoint:P}=_,A=w.x-C.x,I=w.y-C.y,k=P.x-M.x,B=P.y-M.y,L=A*B-I*k;if(Math.abs(L)<1e-10)return null;const q=C.x-M.x,me=C.y-M.y,ue=(k*me-B*q)/L,nt=(A*me-I*q)/L;return ue>=0&&ue<=1&&nt>=0&&nt<=1?{x:C.x+ue*A,y:C.y+ue*I}:null}function o(O){const{edges:_}=O,C=[],w=_.length;if({...O},w!==4)return[O];for(let M=0;M<w;M++)for(let P=M+2;P<w;P++){if(P===M+1||M===0&&P===w-1)continue;const A=a(_[M],_[P]);A&&C.push({edgeIndex1:M,edgeIndex2:P,point:{x:A.x,y:A.y}})}if(C.length&&C.length===1){const M={pathTypeFlag:O.pathTypeFlag,edges:[_[C[0].edgeIndex1-1],{startPoint:{..._[C[0].edgeIndex1].startPoint},endPoint:{x:C[0].point.x,y:C[0].point.y},type:_[C[0].edgeIndex1].type},{startPoint:{x:C[0].point.x,y:C[0].point.y},endPoint:{x:_[C[0].edgeIndex2].startPoint.x,y:_[C[0].edgeIndex2].startPoint.y},type:_[C[0].edgeIndex2].type}]},P={pathTypeFlag:O.pathTypeFlag,edges:[{startPoint:{x:C[0].point.x-1e-5,y:C[0].point.y-1e-5},endPoint:{..._[C[0].edgeIndex1].endPoint},type:_[C[0].edgeIndex1].type},{..._[C[0].edgeIndex2-1]},{startPoint:_[C[0].edgeIndex2].startPoint,endPoint:{x:C[0].point.x-1e-5,y:C[0].point.y-1e-5},type:_[C[0].edgeIndex2].type}]};return[M,P]}return[O]}if(r.boundaryPaths.length==0)return;for(let O=0;O<r.boundaryPaths.length;O++){const _=r.boundaryPaths[O],C=o(_);n=[...n,...C]}if(r.boundaryPaths=n,!r.solidFill&&!r.patternLines?.length){S.warn("[Dxf] Hatch entity(handle: '"+r.handle+"') doesn't have solid fill, nor patternLines, ignored!");return}const l=[],c=[],u=[],f=O=>{const _=[];let C=[];C.push(...this.convertEdgeToPoints(O[0]));for(let w=1;w<O.length;w++){const M=this.convertEdgeToPoints(O[w]);if(C.push(...M),C.length>2){const P=this.convertEdgeToPoints(O[w-1]);R.areVector2sEqual(P[P.length-1],M[0])?R.areVector2sEqual(C[0],M[M.length-1],1e-5)&&(_.push(C),C=[]):R.areVector2sEqual(P[0],M[M.length-1])?R.areVector2sEqual(C[1],M[0],1e-5)&&(_.push(C),C=[]):C=[]}}return _};if(r.boundaryPaths.forEach((O,_)=>{let C=[];if(this.IsfilteredByPathTypeFlag(O.pathTypeFlag)){S.info("[Dxf] The %d path type flag is filtered at the %dth boundrayPath (hatch handle '%s')",O.pathTypeFlag,_,r.handle);return}const w=O.edges;if(w.length===0)return;const M=[];for(let P=0;P<w.length;P++){const A=this.convertEdgeToPoints(w[P]);if(A.length<2){S.warn("[Dxf] The %dth edge of the %dth boundaryPath (hatch handle '%s') has less than 2 points, ignored!",P,_,r.handle);continue}M.push(...A)}if(M.length<3){S.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has less than 3 points, ignored!",_,r.handle);return}if(C.push(M),O.pathTypeFlag>Mn.MaxFlags&&(!(A=>{for(let I=1;I<A.length;++I){const k=A[I-1].endPoint,B=A[I].startPoint;if(!k||!B||!R.areVector2sEqual(k,B))return!1}return!0})(O.edges)||!r.associativity)&&(C=f(w),C.length<2)){S.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",_,r.handle);return}C.forEach(P=>{!R.areVector2sEqual(P[0],P[P.length-1])&&P.push(P[0]);const A=P.map(I=>new d.Vector2(z.roundNumber(I.x,7),z.roundNumber(I.y,7)));if(A?.length>0){l.push(A);const I=new d.Box2().setFromPoints(A);c.push(I);const k=I.getSize(Qt),B=k.x*k.y;u.push({area:B,index:l.length-1})}})}),l.length===0)return;const m=new d.Vector2,g=this.checkAndRebasePolygonsOnRTC(l,m);u.sort((O,_)=>O.area-_.area);const x=[];u.forEach(O=>{x.push(O.index)});const y=this.buildContainHierarchyTree(l,c,x),T=[];this.buildHatchGeometry(l,y,T);let v;if(T.length>0&&(v=xe.mergeGeometries(T)),!v||!v.getIndex()||v.getIndex()?.count===0)return S.warn("[Dxf] Failed to convert hatch boundaries!"),void 0;const b=new F(H.Mesh);b.geometry=v,b.material=_t,this.setHatchMaterial(b,r,i,m,s);const E=b;return g&&(this.setRTCUserData(E),E.matrix.setPosition(m.x,m.y,0)),E.traverse(O=>{O.layers.enableAll(),O.layers.disable(Ce)}),E}loadOle2frame(e,i){const{leftUpX:s,leftUpY:r,rightDownX:n,rightDownY:a}=e;if(!s||!r||!n||!a)return;const o=[new d.Vector2(s,r),new d.Vector2(s,a),new d.Vector2(n,a),new d.Vector2(n,r),new d.Vector2(s,r)],l=new d.Vector3;let c=!1;this.enableRTC&&(c=U.checkAndRebasePositionsOnRTC(o,l));const u=new d.BufferGeometry().setFromPoints(o),f=this.getLineBasicMaterial(16777215),m=new F(H.Line);m.geometry=u,m.material=f,m.layers.enableAll(),c&&(this.setRTCUserData(m),m.matrix.setPosition(l.x,l.y,0));const g=new F;g.add(m);let x;const y=i.objects.DICTIONARY;for(const v of y)for(const b in v.entries)if(v.entries[b]===e.handle){x=b;break}let T;if(x)if(this.meshTextureMaterials[x])T=this.meshTextureMaterials[x];else for(let v=0;v<i.objects.XRECORD.length;v++){const b=i.objects.XRECORD[v];if(b.handle===x){const E=b.binaryData,O=z.hexToBase64(E),_="data:image/jpg;base64,"+O,C=new d.TextureLoader(this.manager).load(_);C.colorSpace=d.SRGBColorSpace;const w=new d.MeshBasicMaterial({transparent:!0,map:C});this.meshTextureMaterials[x]=w,T=w;break}}if(T){const v=new d.Box2().setFromPoints(o),b=v.getSize(Qt),E=new d.PlaneGeometry(b.x,b.y),O=new F(H.Mesh);O.geometry=E,O.material=T;const _=v.getCenter(Qt);j.set(_.x,_.y,0),c&&(this.setRTCUserData(O),j.x+=l.x,j.y+=l.y),O.matrix.setPosition(j),O.layers.enableAll(),g.add(O)}return g.children.length>1?g:m}static getOcsMatrix(e){let i=Ae,s=ds,r=Et;const n=new d.Vector3(0,1,0),a=new d.Vector3(0,0,1);return R.areVectorsClose(e,a)?ne.identity():(r=e.clone().normalize(),!R.areVectorsClose(r,a)&&(Math.abs(r.x)<1/64&&Math.abs(r.y)<1/64?i=n.cross(r).normalize():i=a.cross(r).normalize(),s=r.clone().cross(i).normalize()),ne.set(i.x,i.y,i.z,0,s.x,s.y,s.z,0,r.x,r.y,r.z,0,0,0,0,1))}static getDcs2WcsMatrix(e,i){let s;ih(e)?s=e.viewDirectionFromTarget:s=e.viewDirection,s??(s={x:0,y:0,z:1});const r=e.viewTarget??{x:0,y:0,z:0},n=new d.Vector3(R.roundNumber(s.x,7),R.roundNumber(s.y,7),s.z),a=new d.Vector3(r.x,r.y,r.z),o=e.viewTwistAngle||0;let l,c,u;u=n.clone().normalize(),l=Et.clone().cross(n),l.length()>0?(l.normalize(),c=u.clone().cross(l)):u.z<0?(l=Ae.clone().negate(),c=ds,u=Et.clone().negate()):(l=Ae,c=ds,u=Et);const f=new d.Matrix4,m=ne.identity();return m.makeBasis(l,c,u),f.premultiply(m),f.premultiply(ne.identity().compose(a.clone(),new d.Quaternion().setFromAxisAngle(new d.Vector3(0,0,1),d.MathUtils.degToRad(i?o:-o)),new d.Vector3(1,1,1))),f}getViewportMsToPsMatrix(e){const i=e.centerPoint_dcs??{x:0,y:0},s=e.centerPoint??{x:0,y:0,z:0},r=new d.Vector3(i.x,i.y,0),n=new d.Vector3(s.x,s.y,s.z),a=e.viewHeight,o=e.height_paperSpace||1,l=(a||o)/o,c=V.getDcs2WcsMatrix(e,this.angDir),u=new d.Matrix4;u.setPosition(Cr.clone().sub(n));const f=Or.identity();f.scale(j.set(l,l,l));const m=Fe.identity().setPosition(Cr.clone().sub(n));f.premultiply(m.clone().invert()).multiply(m),u.multiply(f);const g=ne.identity();g.setPosition(r),c.multiply(g);const x=ne.identity();return u.invert().multiply(x).multiply(c.invert())}loadViewport(e,i,s){if(e.viewportId+""=="1"){e.psBBox=new d.Box3,e.msToPsMatrix=new d.Matrix4;return}const r=e.centerPoint;if(!r||!Number.isFinite(r.x)||!Number.isFinite(r.y)){e.psBBox=new d.Box3,e.msToPsMatrix=new d.Matrix4;return}const n=e.width_paperSpace/2,a=e.height_paperSpace/2,o=[new d.Vector3(r.x-n,r.y-a,0),new d.Vector3(r.x-n,r.y+a,0),new d.Vector3(r.x+n,r.y+a,0),new d.Vector3(r.x+n,r.y-a,0)];o.push(o[0]),e.psBBox=new d.Box3().setFromPoints([o[0],o[2]]),e.msToPsMatrix=this.getViewportMsToPsMatrix(e);let l=!1;const c=new d.Vector3;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(o,c));const u=new d.BufferGeometry().setFromPoints(o),f=new F(H.Line);f.geometry=u,f.material=le,f.userData.entityType=e.type,f.layers.enableAll(),l&&(this.setRTCUserData(f),f.matrix.setPosition(c.x,c.y,0));const m=e.psBBox.clone();m.applyMatrix4(e.msToPsMatrix.clone().invert()),m.min.z=0,m.max.z=0;const g=[m.min,new d.Vector3(m.min.x,m.max.y,0),m.max,new d.Vector3(m.max.x,m.min.y,0)];g.push(g[0]);let x=!1;const y=new d.Vector3;this.enableRTC&&(x=U.checkAndRebasePositionsOnRTC(g,y));const T=new d.BufferGeometry().setFromPoints(g),v=new F(H.Line);v.geometry=T,v.material=le,v.userData.entityType=e.type,v.userData.inPaperSpace=[],v.layers.enableAll(),x&&(this.setRTCUserData(v),v.matrix.setPosition(y.x,y.y,0));const b=new F;return b.add(f),b.add(v),f}getColor(e,i,s){if(this.compareContext)return Ue.ENTITY_COLOR_NO_CHANGE;if(this.overrideColor!=null)return this.overrideColor;const r=e;if(r&&r.isGradientColor){const n=r.gradientColors;if(n&&n.length>=2){if(n[0]!==n[1]){const a="[Dxf] Gradient colors are not supported for hatch '"+e.handle+"', will use the first color!";S.warn(a)}return n[0]}}if(e.isTrueColor||e.colorIndex>0&&e.colorIndex<256)return e.color;if(e.colorIndex===0)return s?this.getColor(s,i):i.tables?.layer?.layers[0].color;if(e.colorIndex===256){const n=i.tables?.layer?.layers,a=n&&n[e.layer],o=n&&s&&n[s.layer];let l=ct;return a&&a.name!=="0"?l=a.color:o?l=o.color:a?l=a.color:n&&n[0].color&&(l=n[0].color),l}return S.warn("[Dxf] Unknown colorIndex"),ct}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==Fs&&e.lineType!==mi)return e.lineType;if(e.lineType===mi)return s?this.getLineType(s,i):e.lineType;const r=i.tables?.layer?.layers,n=th;if(e.layer!=="0"){const a=r&&r[e.layer];if(a)return a.lineType}else if(s){const a=r&&r[s.layer];if(a)return a.lineType}return n}getLayerName(e,i,s){const r=c=>{n&&c&&!n[e.layer]&&(console.warn("[Dxf] Failed to find layer object for '"+c+"', adding a default one."),n[c]={name:c,handle:"",colorIndex:256,lineType:"",visible:!0})},n=i.tables?.layer?.layers;r(e.layer);const a=n&&n[e.layer];r(s?.layer);const o=n&&s&&n[s.layer];let l=a?.name||"";return a&&a.name==="0"&&o&&(l=o.name),l}setMaterial(e,i,s,r){const n=e;if(!n.geometry||(this.setRenderOrderByObjectType(e),i.type==="OLE2FRAME"))return;if(i.type==="MTEXT"){e.renderOrder=ge.Text;return}if(i.type==="HATCH"){Qt.set(0,0),this.setHatchMaterial(e,i,s,Qt,r);return}if(i.type==="IMAGE")return;let a;const o=this.getColor(i,s,r);if(i.type==="LWPOLYLINE"&&(n.isMesh?(a=this.getMeshBasicMaterial(o),e.renderOrder=ge.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=ge.LineWithPattern),a)){n.material=a;return}if(i.type==="SOLID")a=this.getMeshBasicMaterial(o);else if(i.type==="TEXT"||i.type==="ATTDEF"||i.type==="ATTRIB")a=this.getLineBasicMaterial(o),e.renderOrder=ge.Text;else if(i.type==="LEADER"||i.type==="MULTILEADER"||i.type==="VIEWPORT")a=this.getLineBasicMaterial(o);else if(i.type==="POINT")a=this.getPointsMaterial(o);else{if(e.material instanceof d.PointsMaterial){a=this.getPointsMaterial(o),n.material=a;return}const l=s.tables?.lineType?.lineTypes,c=l&&l[this.getLineType(i,s,r)];if(c&&c.pattern&&c.pattern.length!==0){const u=i.lineTypeScale||1;a=this.getLineShaderMaterial(c,o,u),e.renderOrder=ge.LineWithPattern}else a=this.getLineBasicMaterial(o)}n.material=a}setHatchMaterial(e,i,s,r,n){const a=e;if(!a.geometry)return;const o=this.getColor(i,s,n);if(a.type===H.Line||a.type===H.LineSegment){a.material=this.getLineBasicMaterial(o);return}let l=ge.Mesh,c;if(i.solidFill)c=this.getMeshBasicMaterial(o);else{if(a.material instanceof d.ShaderMaterial){c=a.material;const u=new d.Color(o);!a.material.uniforms.u_color.value.equals(u)&&(c=a.material.clone(),V.updateMaterialUniforms(c),c.uniforms.u_color.value.set(o))}else c=this.getHatchShaderMaterial(i,o,r);l=ge.MeshWithPattern}!c&&(c=this.getMeshBasicMaterial(o),l=ge.Mesh),a.material=c,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=ge.Mesh:i.isLine?s=ge.Line:i.isPoints&&(s=ge.Point),e.renderOrder=s}getPointsMaterial(e){return!this.pointsMaterials[e]&&(this.pointsMaterials[e]=new d.PointsMaterial({size:.2,color:e})),this.pointsMaterials[e]}getLineBasicMaterial(e){return!this.lineBasicMaterials[e]&&(this.lineBasicMaterials[e]=new d.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,i,s){const r=e.name+"_"+i+"_"+s;if(!this.lineShaderMaterials[r]){const n=this.getLineTypeScales(),a=n.ltScale*n.celtScale*s;this.lineShaderMaterials[r]=bn.createLineShaderMaterial(e.pattern,i,a,V.ViewportScaleUniform,V.CameraZoomUniform)}return this.lineShaderMaterials[r]}getMeshBasicMaterial(e){return!this.meshBasicMaterials[e]&&(this.meshBasicMaterials[e]=new d.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getHatchShaderMaterial(e,i,s){if(!e.patternLines||e.patternLines.length<1)return;const r=this.findMatchedHatchShaderMaterial(e,i);if(r)return r;const n=.005,a=.05;let o=2;e.patternLines.forEach(m=>{o=Math.max(m.dashPattern.length,o)});let l=0;const c=[],u=new d.Vector2;for(const m of e.patternLines){const g=new d.Vector2(m.origin.x,m.origin.y).sub(s).rotateAround(u,-d.MathUtils.degToRad(e.patternAngle)),x=new d.Vector2(m.delta.x,m.delta.y).rotateAround(u,-d.MathUtils.degToRad(m.angle));if(x.y===0)return S.warn("[Dxf] delta.y is equal to zero !"),void 0;const y=m.dashPattern.length;let T=!0,v=0;for(let w=0;w<y;++w){const M=m.dashPattern[w];M>0&&(T=!1),v+=Math.abs(M)}const b=T?a:n,E=[],O=[];let _=0;O[0]=_;for(let w=0;w<y;++w)E[w]=m.dashPattern[w],E[w]===0&&(E[w]=b*v),_+=Math.abs(E[w]),O[w+1]=_;for(let w=y;w<o;++w)E[w]=0;for(let w=O.length;w<o+1;++w)O[w]=_;const C={origin:g,delta:x,angle:m.angle-e.patternAngle,pattern:E,patternSum:O,patternLength:_};if(l+=4,l+=o,l+=o+1,l>V.MaxFragmentUniforms){S.warn("[Dxf] There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}c.push(C)}const f=vn(c,e.patternAngle,V.CameraZoomUniform,new d.Color(i),this.overrideHatchPatternLineThickness);return f.defines={MAX_PATTERN_SEGMENT_COUNT:o},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:i,material:f}),f}getDivision(e,i,s){let r=Math.round(5e4/this.entityCount);r=Math.max(r,2),r=Math.min(r,10);const n=r*5;let o=r*2;if(this.averageCurveSize){const u=Math.pow(s/this.averageCurveSize,.5);o*=u,o=Math.max(o,r),o=Math.min(o,n)}let l=i-e;l<0&&(l+=Math.PI*2),o=Math.ceil(o*(l/Math.PI));let c=8;return l<.087?c=2:l<.174?c=3:l<.52?c=4:l<1.57?c=5:l<3.14?c=6:l<4.71&&(c=7),o=Math.max(o,c),this.averageCurveSize=(this.averageCurveSize*this.curveCount+s)/(this.curveCount+1),this.curveCount++,Math.max(o,12)}getBSplineInterpolationsPerSplineSegment(e,i){let s=1;this.averageCurveSize&&(s=Math.pow(i/this.averageCurveSize,.5),s=Math.max(s,.5),s=Math.min(s,2)),this.averageCurveSize=(this.averageCurveSize*this.curveCount+i)/(this.curveCount+1),this.curveCount++;let r=e*2*s;if(e>20){const n=Math.log10(e);r/=n}return r}async setDxfDataToIndexedDb(e,i){const s={dxfDataId:e,dxf:i};return new Promise((r,n)=>{Yi.instance().add(s,()=>{S.info("[Dxf] Saved '"+e+"' to indexedDb"),r()},a=>{n(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{Yi.instance().query(e,r=>{r&&r.length>0&&i(r[0].dxf),i(void 0)},()=>s())})}buildContainHierarchyTree(e,i,s){const r=new Map,n=s.length;for(let o=0;o<n;o++)r.set(s[o],{index:s[o],children:[]});const a={index:-1,children:[]};for(let o=0;o<n;o++){const l=s[o],c=e[l],u=i[l];let f=o+1;for(;f<n;f++){const m=s[f],g=e[m];if(i[m].containsBox(u)&&U.isPointInPolygon(c[z.generateRandomInt(0,c.length-1)],g)){r.get(m)?.children.push(r.get(l));break}}f===n&&a.children.push(r.get(l))}return a}buildHatchGeometry(e,i,s){if(i.children.length===0)return;const r=[],n=new Map;i.children.forEach(l=>{l.children.length===0?r.push(l.index):n.set(l.index,l.children.map(c=>c.index))});const a=l=>{try{const c=new d.ShapeGeometry(l);c.hasAttribute("uv")&&c.deleteAttribute("uv"),c.hasAttribute("normal")&&c.deleteAttribute("normal"),s.push(c)}catch{S.warn("[Dxf] triangulate shape error: "+l.getPoints().map(u=>u.toArray()).toString())}};r.forEach(l=>{const c=e[l];if(c.length===0)return;const u=new d.Shape(c);a(u)});const o=l=>l.map(c=>c.toArray());for(const l of n){const c=new d.Shape(e[l[0]]);let u={regions:[],inverted:!1};const f=this.findIntersectHole(e,l[1]);f.forEach(g=>{let x={regions:[],inverted:!1};try{g.forEach((y,T)=>{if(yt.epsilon(R.getVector2RelativeEps(e[y][0]),1e-6),T===0)x=yt.segments({regions:[o(e[y])],inverted:!1});else{const v=yt.segments({regions:[o(e[y])],inverted:!1}),b=yt.combine(x,v);u=yt.polygon(yt.selectUnion(b)),u.regions.length>0?u.regions.forEach(E=>{if(E.length===0)return;const O=E.map(_=>new d.Vector2(_[0],_[1]));c.holes.push(new d.Path(O))}):S.warn("[Dxf] mergedHoles.regions is empty")}})}catch(y){S.warn("[Dxf] polybooljs has error: "+y+", epsilon is "+yt.epsilon())}});const m=f.flat(2);for(let g=0;g<l[1].length;g++){const x=l[1][g];!m.includes(x)&&c.holes.push(new d.Path(e[x]))}a(c)}i.children.forEach(l=>{l.children.forEach(c=>{this.buildHatchGeometry(e,c,s)})})}findIntersectHole(e,i){const s=i.length,r=[];for(let n=0;n<s;n++){const a=e[i[n]];let o=!1;const l=[];for(let c=n+1;c<s;c++){const u=e[i[c]];U.arePolygonsIntersect(a,u)&&(o=!0,l.push(i[c]))}o&&(l.push(i[n]),r.push(l))}return r}checkAndRebasePolygonsOnRTC(e,i){if(!this.enableRTC||e.length===0)return!1;let s=0;e.forEach(n=>{n.forEach(a=>{i.add(a),s++})}),i.divideScalar(s);let r=!1;if(this.enableRTC&&U.shouldRebasePositionOnRTC(i)){r=!0;for(let n=0;n<e.length;n++){const a=e[n];for(let o=0;o<a.length;o++){const l=a[o].x-i.x,c=a[o].y-i.y;a[o]=new d.Vector2(l,c)}}}else i.set(0,0);return r}setRTCUserData(e){e.userData.relativeToCenter=!0,this.statsInfo.rebasedEntityCount++}IsfilteredByPathTypeFlag(e){return e<0}findSpatialFilterByHandle(e,i){const s=i.objects.DICTIONARY;if(!s)return;if(!this.dictionaryOwnerHandleAndSpatialFilterHandlesCache){this.dictionaryOwnerHandleAndSpatialFilterHandlesCache={};for(const n of s){const a=n;let o="";for(const l in a.entries)if(a.entries[l]==="ACAD_FILTER"){o=l;break}o&&(this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[n.ownerHandle]&&S.warn("[Dxf] Why this.dictionaryObjectsCache[obj.ownerHandle] already exist?",n.ownerHandle),this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[n.ownerHandle]=o)}}const r=this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[e];if(r){if(!this.spatialFiltersCache){this.spatialFiltersCache={};const n=i.objects.SPATIAL_FILTER||[];for(const a of n){const o=a;o.numberOfPointsOnClipBoundary<2||(this.spatialFiltersCache[o.ownerHandle]&&S.warn("[Dxf] Why this.spatialFiltersCache[spatialFilterObj.ownerHandle] already exist?",r),this.spatialFiltersCache[o.ownerHandle]=o)}}return this.spatialFiltersCache[r]}}initRenderOrderInfo(e){const i=new Set,s=e.objects.DICTIONARY;for(const n of s){const a=n;Object.keys(a.entries).forEach(o=>{a.entries[o]&&a.entries[o]==="ACAD_SORTENTS"&&i.add(o)})}if(i.size===0)return;const r=e.objects.SORTENTSTABLE;if(r)for(let n=0;n<r.length;++n){const a=r[n];if(i.has(a.handle)){for(let o=0;o<a.sortEntsObject.entityHandles.length;++o){const l=a.sortEntsObject.entityHandles[o];l.length===2&&!this.entityHandlesWithRenderOrder[l[0]]?this.entityHandlesWithRenderOrder[l[0]]=l[1]:S.warn("[Dxf] Failed to handle sortEntsTable: "+a.handle+".")}break}}}findMatchedHatchShaderMaterial(e,i){const s=e.patternLines;if(!s||s.length<1)return;const r=(c,u)=>Math.abs(c-u)<1e-5,n=(c,u)=>{if(c.length!==u.length)return!1;for(let f=0;f<c.length;++f)if(!r(c[f],u[f]))return!1;return!0},a=(c,u)=>r(c.angle,u.angle)&&r(c.delta.x,u.delta.x)&&r(c.delta.y,u.delta.y)&&r(c.origin.x,u.origin.x)&&r(c.origin.y,u.origin.y)&&n(c.dashPattern,u.dashPattern),o=(c,u)=>{if(c.length!==u.length)return!1;for(let f=0;f<c.length;++f)if(!a(c[f],u[f]))return!1;return!0};return this.hatchShaderMaterials.find(c=>c.color===i&&c.patternAngle===e.patternAngle&&o(c.patternLines,s))?.material}getLayout(e,i){if(!this.blockRecordsCache){this.blockRecordsCache={};const n=this.blockRecordsCache,a=e.tables?.blockRecord?.blockRecords;a&&Object.values(a).forEach(o=>{n[o.handle]=o.layoutHandle})}const s=this.blockRecordsCache[i.ownerHandle];if(s){const n=e.objects.LAYOUT,a=n.find(o=>o.handle===s);if(a)return a}if(!this.entitiesCache){this.entitiesCache={};const n=this.entitiesCache;Object.values(e.entities).forEach(a=>{n[a.handle]=a})}const r=this.entitiesCache[i.ownerHandle];return r?this.getLayout(e,r):e.objects.LAYOUT.find(n=>n.layoutName===V.MODEL_LAYOUT_NAME)}getLayerVisible(e,i){const s=e.tables?.layer?.layers;return s&&s[i]?.visible}getLayerFrozen(e,i){const s=e.tables?.layer?.layers;return s&&s[i.layer]?.frozen}cloneMaterialsForSpatialFilter(e){const i=new Map,s=r=>{let n;if(Array.isArray(r)){const a=[];n=a,r.forEach(o=>{if(i.has(o.id))a.push(i.get(o.id));else{const l=o.clone();V.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else r&&(i.has(r.id)?n=i.get(r.id):(n=r.clone(),V.updateMaterialUniforms(n),i.set(r.id,n)));return n};e.traverse(r=>{r.material&&(r.material=s(r.material))})}getLineTypeScales(){const e={ltScale:1,celtScale:1};return this.header&&(e.ltScale=this.header.$LTSCALE||1,e.celtScale=this.header.$CELTSCALE||1),e}static getDxfUnits(e){switch(e||0){case 0:return De.Unitless;case 1:return De.Inches;case 2:return De.Feet;case 4:return De.Millimeters;case 5:return De.Centimeters;case 6:return De.Meters;default:S.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return De.Unitless}static computeLineDistance(e){const i=e.isLineSegments===!0;let s=e.geometry;const r=e.matrixWorld;if(s.index&&(S.debug("[Dxf] Line with id '"+e.id+"' contains index buffer, going to convert it to non-indexed."),s=U.convertGeometryWithIndexedToNonIndexed(s),e.userData.batches&&e.userData.batches.length>0)){S.debug("[Dxf] This line has been merged!");let n=0;e.userData.batches.forEach(a=>{a.positionStart=n,a.positionCount=a.indexCount,a.indexStart=0,a.indexCount=0,n+=a.positionCount})}if(s.index===null){const n=s.attributes.position;if(!n||n.count===0)return;const a=[];if(i)for(let o=0,l=n.count;o<l;o+=2)j.fromBufferAttribute(n,o).applyMatrix4(r),Z.fromBufferAttribute(n,o+1).applyMatrix4(r),a[o]=o===0?0:a[o-1],a[o+1]=a[o]+j.distanceTo(Z);else{a[0]=0;for(let o=1,l=n.count;o<l;o++)j.fromBufferAttribute(n,o-1).applyMatrix4(r),Z.fromBufferAttribute(n,o).applyMatrix4(r),a[o]=a[o-1],a[o]+=j.distanceTo(Z)}s.setAttribute("lineDistance",new d.Float32BufferAttribute(a,1)),e.geometry=s}else S.warn("[Dxf] computeLineDistances only possible with non-indexed BufferGeometry.")}static computeLineDistances(e){const i=Date.now();e.traverse(s=>{const r=s;r.isLine&&r.material instanceof d.ShaderMaterial&&V.computeLineDistance(r)}),S.debug("[Dxf] Computed line distances in "+(Date.now()-i)/1e3+"s")}static mergeDxfObjects(e){const i=Date.now(),s={},r={},n=15e3;let a=0,o=0;const l=()=>{const u=Date.now();for(const f in s){const m=s[f];V.removeEmptyObjectsFromRemovingMarkedObjects2(m.children,m.object),m.children=[]}a=0,o+=Date.now()-u};for(const u in e.layersAndObjects){const f=e.layersAndObjects[u];if(f.length<=1)continue;const m=Date.now(),g={},x=[];for(const y of f){if(y.userData.isSnapObject){x.push(y);continue}let T,v=y;for(;v;){if(v.userData.isLayoutLevelObject){T=v;break}v=v.parent}if(!T)continue;const b=T.name;!g[b]&&(g[b]={object:T,children:[]}),g[b].children.push(y)}for(const y in g){const T=g[y],v=et.deepMerge(T.children,T.object,!1,!1,!0),b=v.added,E=v.removed;!s[y]&&(s[y]={object:T.object,children:[]}),!r[y]&&(r[y]={object:T.object,children:[]});const O=E.length>n;if(O){const _=Date.now();V.removeEmptyObjectsFromRemovingMarkedObjects2(E,T.object),o+=Date.now()-_}else a+=E.length;if(E.length===T.children.length)!O&&E.forEach(_=>{s[y].children.push(_)});else{let _=E;E.length>=100&&(_=new Set(E));const C=w=>Array.isArray(_)?_.indexOf(w)>=0:_.has(w);for(let w=0;w<T.children.length;w++){const M=T.children[w];C(M)?!O&&s[y].children.push(M):x.push(M)}}for(let _=0;_<b.length;_++){const C=b[_];x.push(C),r[y].children.push(C)}a>n&&l()}e.layersAndObjects[u]=x,S.debug("[Dxf] Merged layer '"+u+"' in "+(Date.now()-m)/1e3+"s")}a>0&&l();for(const u in r){const f=r[u];!e.root.children.find(g=>g.name===u)&&e.root.add(f.object),f.children.forEach(g=>{f.object.add(g)}),f.children=[]}S.debug("[Dxf] MergeUtils.deepMerge took "+oe.MergeInfo.elapsedTime/1e3+"s"),S.debug("[Dxf] The remove operation of deep merge took "+o/1e3+"s"),S.debug("[Dxf] Deep merge totally took "+(Date.now()-i)/1e3+"s");const c=oe.MergeInfo;S.debug("[Dxf] Totally merged "+c.removedObjects+" objects to "+c.mergedMeshes+"meshes, "+c.mergedLines+"lines, "+c.mergedPoints+"points, "+(c.mergedUnknownTypeObjects?c.mergedUnknownTypeObjects+" unknown type,":" ")+" ")}static async merge(e,i){const s=z.getUpdateProgressFuncAsync(i),r={};e.objects.LAYOUT.forEach(y=>{const T=y;r[T.layoutName]=T,T.directAssociatedLeafObjectSet?.clear()});const n=Date.now(),a={},o={},l=15e3;let c=0,u=0;const f=()=>{const y=Date.now();for(const T in a){const v=a[T];V.removeEmptyObjectsFromRemovingMarkedObjects(v.children,v.object),v.children=[]}c=0,u+=Date.now()-y},m=Object.keys(e.layersAndThreejsObjects).length;let g=0;for(const y in e.layersAndThreejsObjects){const T=e.layersAndThreejsObjects[y];if(T.length<=1){await s(++g/m*100);continue}const v=Date.now(),b={},E=[];for(const C of T){if(C.userData.isSnapObject){E.push(C);continue}let w,M=C;for(;M;){if(M.userData.isLayoutLevelObject){w=M;break}M=M.parent}if(!w)continue;const P=w.name;!b[P]&&(b[P]={object:w,children:[]}),b[P].children.push(C)}const O=Object.keys(b).length;let _=0;for(const C in b){let w;if(C!==V.MODEL_LAYOUT_NAME){const B=r[C];!B.directAssociatedLeafObjectSet&&(B.directAssociatedLeafObjectSet=new Set),w=B.directAssociatedLeafObjectSet}const M=b[C],P=oe.deepMerge(M.children,M.object,!1,!1,!0),A=P.added,I=P.removed;!a[C]&&(a[C]={object:M.object,children:[]}),!o[C]&&(o[C]={object:M.object,children:[]});const k=I.length>l;if(k){const B=Date.now();V.removeEmptyObjectsFromRemovingMarkedObjects(I,M.object),u+=Date.now()-B}else c+=I.length;if(I.length===M.children.length)!k&&I.forEach(B=>{a[C].children.push(B)});else{let B=I;I.length>=100&&(B=new Set(I));const L=q=>Array.isArray(B)?B.indexOf(q)>=0:B.has(q);for(let q=0;q<M.children.length;q++){const me=M.children[q];L(me)?!k&&a[C].children.push(me):(E.push(me),w&&w.add(me))}}for(let B=0;B<A.length;B++){const L=A[B];$.setSharedVariablesOfObject(L),E.push(L),o[C].children.push(L),w&&w.add(L)}c>l&&f(),await s((g+ ++_/O)/m*100)}await s(++g/m*100),e.layersAndThreejsObjects[y]=E,S.debug("[Dxf] Merged layer '"+y+"' in "+(Date.now()-v)/1e3+"s")}c>0&&f();for(const y in o){const T=o[y],v=e.threejsObject.children.find(b=>b.name===y);if(v){const b=v.children.find(E=>E.name===V.SNAP_GROUP_NAME);if(b&&y!==V.MODEL_LAYOUT_NAME){const E=r[y];!E.directAssociatedLeafObjectSet&&(E.directAssociatedLeafObjectSet=new Set),b.children.forEach(O=>E.directAssociatedLeafObjectSet?.add(O))}}!v&&e.threejsObject.add(T.object),T.children.forEach(b=>{!b.visible&&(b.userData.layerVisible=!1),T.object.add(b),b.updateWorldMatrix(!1,!1)}),T.children=[]}S.debug("[Dxf] MergeUtils.deepMerge took "+oe.MergeInfo.elapsedTime/1e3+"s"),S.debug("[Dxf] The remove operation of deep merge took "+u/1e3+"s"),S.debug("[Dxf] Deep merge totally took "+(Date.now()-n)/1e3+"s");const x=oe.MergeInfo;S.debug("[Dxf] Totally merged "+x.removedObjects+" objects to "+x.mergedMeshes+"meshes, "+x.mergedLines+"lines, "+x.mergedPoints+"points, "+(x.mergedUnknownTypeObjects?x.mergedUnknownTypeObjects+" unknown type,":" ")+" "),s(100)}printStatsInfo(){const e=this.entityTypesAndTimes;for(const r in e)e[r].averageTime=e[r].totalTime/e[r].createCount;S.debug("[Dxf] Entity types and took how much time in ms:",e),S.debug("[Dxf] Entity types and mesh count:",this.statsInfo.entityTypesAndMeshCount);let i=0;if(Object.values(this.statsInfo.entityTypesAndMeshCount).forEach(r=>{i+=r}),this.enableRTC&&S.debug("[Dxf] Totally rebased "+this.statsInfo.rebasedEntityCount+"(out of "+i+") entities"),this.enableMerge){const r=oe.MergeInfo;S.debug("[Dxf] Inner merged "+r.removedObjects+" objects to "+r.mergedMeshes+"meshes, "+r.mergedLines+"lines, "+r.mergedPoints+"points, "+(r.mergedUnknownTypeObjects?r.mergedUnknownTypeObjects+" unknown type,":" ")+"in "+r.elapsedTime/1e3+"s")}const s=(r,n,...a)=>{Object.keys(n).length>0};s("[Dxf] Unsupported entity types and count:",this.statsInfo.unsupportedEntityTypes),s("[Dxf] Unsupported text style names and count:",this.statsInfo.unsupportedTextStyles,". Will use a default style."),s("[Dxf] Unsupported hatch pattern names and count:",this.statsInfo.unsupportedHatchPatterns,". Filling in solid lines instead."),this.statsInfo.unsupportedPolylineCount&&S.warn("[Dxf] Unsupported polyline (with both width and linetype) count: "+this.statsInfo.unsupportedPolylineCount+", linetype will be ignored."),s("[Dxf] Ignored invisible entity types and count:",this.statsInfo.invisibleEntities),s("[Dxf] Ignored frozen layers and entity count:",this.statsInfo.ignoredFrozenLayersAndEntityCount),s("[Dxf] Ignored inserts and count (may because they don't contain anything):",this.statsInfo.ignoredInserts),this.ignorePaperSpace&&s("[Dxf] Ignored paper space entity count:",this.statsInfo.ignoredPaperSpaceEntityTypesAndCount),this.font&&s("[Dxf] Unsupported chars and count:",this.font.getUnsupportedChar())}static statLayoutAndLayerObjects(e){const i=new WeakSet;let s=0;for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&(s++,i.has(l)?console.warn(l):i.add(l))});const r=new WeakSet;let n=0;if(e.threejsObject.traverse(a=>{a.geometry&&(n++,r.has(a)?console.warn(a):r.add(a))}),s!=n)for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&!r.has(l)&&console.warn(l)});S.info("[Dxf] The count of layer objects is "+s+",The count of layout objects is "+n+" ")}static removeEmptyObjectsFromRemovingMarkedObjects(e,i){if(e.length===0)return;const s=r=>{const n=[];for(const a of r){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&n.push(o))}n.length>0&&s(n)};s(e),this.removeEmptyObjectsFromMark(i)}static removeEmptyObjectsFromMark(e){if(e.userData.validCount===0||$.isEmptyObject(e))return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark(e.children[i])&&++i;return!1}static removeEmptyObjectsFromRemovingMarkedObjects2(e,i){if(e.length===0)return;const s=r=>{const n=[];for(const a of r){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&n.push(o))}n.length>0&&s(n)};s(e),this.removeEmptyObjectsFromMark2(i)}static removeEmptyObjectsFromMark2(e){if(e.userData.validCount===0||e.type===H.Object&&e.children.length===0)return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark2(e.children[i])&&++i;return!1}};p(V,"MODEL_LAYOUT_NAME","Model"),p(V,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),p(V,"SHOW_SNAP_OBJECT",!1),p(V,"REQUWSTHEADER"),p(V,"CameraZoomUniform",{value:1}),p(V,"ViewportScaleUniform",{value:1}),p(V,"TransformMatrixUniform",{value:new d.Matrix4}),p(V,"ResolutionUniform",{value:new d.Vector2}),p(V,"LOADLLDATA",!1),p(V,"MaxFragmentUniforms",1024);let Y=V;class As extends mt{constructor(e){super();p(this,"viewer");p(this,"overlayRender");p(this,"drawableList");this.drawableList=new bi("compare"),this.viewer=e,this.overlayRender=this.viewer.getOverlayRender(),this.overlayRender?.addDrawableList(this.drawableList)}drawCompareDrawable(e){const i=[],s=[],r=[];for(const l of Object.values(e)){const c=l.box;c&&(l.type===Te.Added?i.push(c):l.type===Te.Removed?s.push(c):r.push(c))}const n=U.mergeBBoxes(i),a=U.mergeBBoxes(s),o=U.mergeBBoxes(r);this.drawableList.addDrawable(new Je(z.guid(),n,[.1,.9,.2,1])),this.drawableList.addDrawable(new Je(z.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new Je(z.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class Ji{}const Pt=new d.Matrix4,fs=new d.Box3;class Wt extends Ji{constructor(e){super();p(this,"modelId");p(this,"modelData");p(this,"modelObject");p(this,"bbox");this.modelData=e,this.modelId=e.modelId,this.modelObject=e.dxfData?.threejsObject||e.pdfData?.threejsObject,this.modelObject.name=this.modelId,this.modelObject.userData.modelId=this.modelId}get pdfData(){return this.modelData.pdfData}get dxfData(){return this.modelData.dxfData}get msTransformMatrix(){return this.modelData.msTransformMatrix}set msTransformMatrix(e){this.modelData.msTransformMatrix=e}get loadedEntityCount(){return this.dxfData?.loadedEntityCount||this.pdfData?.loadedEntityCount||0}get header(){return this.dxfData?.header}get viewports(){return this.dxfData?.tables.viewport.viewports}get layers(){const e=this.dxfData||this.pdfData;return e.tables?.layer.layers||e.layers}get layoutViewportsMap(){return this.dxfData?.layoutViewportsMap}getModelObject(){const e=this.dxfData||this.pdfData;if(!e)throw new Error("Failed to find model by modelId '"+this.modelId+"'!");return e.threejsObject}getBBox(){if(!this.bbox){const e=new d.Box3,i=this.getModelObject();e.setFromObject(i),this.bbox=e}return this.bbox}getUnits(){if(!this.dxfData)return De.Unitless;const e=this.dxfData.header;if(!e)return S.warn("DxfData or its header is undefined!"),De.Unitless;const i=e.$INSUNITS;return Y.getDxfUnits(i)}getModelSpaceExtent(){const e=this.header,i=new d.Vector3,s=new d.Vector3;if(!e){S.error("Header is undefined in "+this.modelId+"!");return}const r=this.viewports;let n=e.$EXTMIN,a=e.$EXTMAX;const o=e.$ANGDIR;if(r&&r.length>0)for(let l=0;l<r.length;l++){const c=r[l];if(c.name.toLocaleUpperCase()==="*ACTIVE"){const{center:u,viewHeight:f,aspectRatio:m}=c,g=f*m,x=Y.getDcs2WcsMatrix(c,o),y=new d.Vector3(u.x,u.y,0);y.applyMatrix4(x),n={x:y.x-g/2,y:y.y-f/2,z:0},a={x:y.x+g/2,y:y.y+f/2,z:0};break}}return i.set(n.x,n.y,n.z),s.set(a.x,a.y,a.z),new d.Box3(i,s)}getLayer(e){if(this.layers)return this.layers[e]}getObjectsByLayer(e){const i=this.dxfData||this.pdfData;return i?.layersAndThreejsObjects&&i.layersAndThreejsObjects[e]}getLayouts(){const e=[];return this.dxfData?.objects.LAYOUT?.forEach(r=>{e.push(r)}),e}getLayoutByName(e){let i;const s=this.getLayouts();for(const r of s)if(r.layoutName===e){i=r;break}return i}getLayoutExtent(e){const i=this.header,s=new d.Vector3,r=new d.Vector3;if(!i)throw new Error("Header is undefined in "+this.modelId+"!");const n=this.getLayoutViewports(e);let a=i.$PEXTMIN,o=i.$PEXTMAX;const l=i.$ANGDIR;if(n&&n.length>0){const c=n.filter(T=>parseInt(T.viewportId)===1);let u;c.length>0?u=c[0]:u=n[0];const{centerPoint:f,width_paperSpace:m,height_paperSpace:g}=u,x=Y.getDcs2WcsMatrix(u,l),y=new d.Vector3(f.x,f.y,0);y.applyMatrix4(x),a={x:y.x-m/2,y:y.y-g/2,z:0},o={x:y.x+m/2,y:y.y+g/2,z:0}}return s.set(a.x,a.y,a.z),r.set(o.x,o.y,o.z),new d.Box3(s,r)}getLayoutViewports(e){const s=this.layoutViewportsMap[e.ownerHandle];return s||[]}getLayoutLevelObject(e){return this.getModelObject()?.children.find(s=>s.name===e)}setVisible(e){const i=this.getModelObject();i.visible=e}setLayerVisible(e,i,s,r){const n=this.getLayer(e);n?n.visible=i:S.warn("[Viewer] Layer '"+e+"' not found from modelData!");const a=this.getObjectsByLayer(e);if(a)for(let o=0;o<a.length;o++){const l=a[o];!(s&&i&&r&&l.userData.visibleMinZoom&&r<l.userData.visibleMinZoom)&&(l.visible=i),(i===!1||l.userData.layerVisible!=null)&&(l.userData.layerVisible=i),l.userData.isSnapObject&&(l.visible?Y.SHOW_SNAP_OBJECT?l.layers.enableAll():l.layers.set(Ce):Y.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(Ce))}else S.info("[Viewer] No object found for layer '"+e+"'")}setLayerOpacity(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const r=this.getObjectsByLayer(e);r?r.forEach(n=>{const a=n;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=de.cloneMaterial(a.material));const o=de.cloneMaterial(a.material);de.setMaterialOpacity(o,i),Y.updateMaterialUniforms(o),a.material=o}}):S.info("[Viewer] No object found for layer '"+e+"'")}setLayerColor(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const r=this.getObjectsByLayer(e);r?r.forEach(n=>{const a=n;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=de.cloneMaterial(a.material));const o=de.cloneMaterial(a.material);de.setMaterialColor(o,new d.Color(i)),Y.updateMaterialUniforms(o),a.material=o}}):S.info("[Viewer] No object found for layer '"+e+"'")}resetLayerColor(e){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const s=this.getObjectsByLayer(e);s?s.forEach(r=>{const n=r;n.material&&n.userData.originalMaterial&&(n.material.dispose(),n.material=n.userData.originalMaterial,delete n.userData.originalMaterial)}):S.info("[Viewer] No object found for layer '"+e+"'")}switchTransformMs(e){const i=this.msTransformMatrix;if(Pt.identity(),!i||!z.isMatrixValid(i)||i.equals(Pt))return;const s=this.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME);s&&(e===Y.MODEL_LAYOUT_NAME?s.applyMatrix4(i):s.applyMatrix4(i.clone().invert()),s.updateMatrixWorld(!0))}activateLayout(e=Y.MODEL_LAYOUT_NAME,i){this.switchTransformMs(e);const s=this.getLayoutByName(e);if(s){if(!i){const r=this.getLayoutViewports(s);let n=[];r.length>0&&(n=r[0].frozenLayerHandles);const a=e!==Y.MODEL_LAYOUT_NAME,o=this.getLayoutLevelObject(e);if(o){const u=[];o.traverse(f=>{this.addSpatialFilterSection(f,this.dxfData);const m=f;if(a&&m.material&&m.geometry){const g=m.userData.layerName;if(this.isLayerFrozenForViewport(g,n))return;u.push(m);let x=-1;const y=this.getObjectsByLayer(g);y&&(x=y.indexOf(m),x>=0&&y.splice(x,1)),x<0&&S.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+g+"', layout '"+e+"'")}}),u.forEach(f=>{f.removeFromParent()})}const l=this.getFilteredViewports(s);S.debug("[Viewer] Active layout:",e,", viewports:",l);const c=Date.now();l.forEach(u=>{this.generateObjectsByViewport(e,u,this)}),S.info("[Viewer] generateObjectsByViewport in "+(Date.now()-c)/1e3+"s")}this.showLayoutObjects(e)}}getFilteredViewports(e){const i=this.getLayoutViewports(e);let s=i.filter(r=>r.viewportId!=="1");return s.length===i.length&&(s=i.filter((r,n)=>n!==0)),s}generateObjectsByViewport(e,i,s,r=[]){const n=i;if(i.viewportId=="1")return;if(!n.psBBox||!n.msToPsMatrix)throw new Error("The bbox or matrix is invalid in the viewport!");Y.TransformMatrixUniform={value:n.msToPsMatrix},Y.ViewportScaleUniform={value:i.viewHeight/i.height_paperSpace};const a=n.psBBox.clone();a.applyMatrix4(n.msToPsMatrix.clone().invert()),a.min.setZ(-1),a.max.setZ(1);const o=this.getObjectsByBoundingBox(a);if(o.length===0)return;const l=n.psBBox.min,c=n.psBBox.max,u=new d.Box2(new d.Vector2(l.x,l.y),new d.Vector2(c.x,c.y)),f=dt.generateSectionPlanesByBox(u),m=[],g=M=>(!m[M.id]&&(m[M.id]=M.clone(),this.setMaterialUniforms(m[M.id],s.dxfData),dt.setMaterialSection(m[M.id],f)),m[M.id]),x=M=>{if(Array.isArray(M)){const P=[];return M.forEach(A=>{const I=g(A);P.push(I)}),P}else return g(M)},y=[...r,...i.frozenLayerHandles||[]];let T;if(e!==Y.MODEL_LAYOUT_NAME){const M=n;!M.associatedLeafObjectSet&&(M.associatedLeafObjectSet=new Set),T=M.associatedLeafObjectSet}const v=new d.Group;v.name=n.viewportId;const b=[];if(o.forEach(M=>{const P=M.clone();P.traverse(A=>{const I=A;if(I.material&&I.geometry){const k=I.userData.layerName;if(this.isLayerFrozenForViewport(k,y)){b.push(I);return}I.userData.layerVisible!==!1&&(I.visible=!0),I.material=x(I.material),T?.add(I);const B=s.getObjectsByLayer(k);B?B.push(I):S.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+k+"', layout '"+e+"'")}}),v.add(P)}),T&&T.size===0)return;const E=s.getModelObject();let O=s.getLayoutLevelObject(e);!O&&(O=new d.Group,$.setSharedVariablesOfObject(O),O.name=e,E?.add(O)),O.add(v),v.applyMatrix4(n.msToPsMatrix),v.updateMatrixWorld(!0);let _=O.children.find(M=>M.name===Y.SNAP_GROUP_NAME);!_&&(_=new d.Group,_.visible=Y.SHOW_SNAP_OBJECT,_.name=Y.SNAP_GROUP_NAME,O.add(_));const C=s.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME),w=C?.children.find(M=>M.name===Y.SNAP_GROUP_NAME);w&&w.traverse(M=>{if(!M.geometry)return;const P=M.userData.layerName;if(this.isLayerFrozenForViewport(P,y)||(fs.makeEmpty(),fs.expandByObject(M),!a.intersectsBox(fs)))return;const A=M.clone();$.setSharedVariablesOfObject(A);let I=A.parent;const k=Pt.identity();for(;I&&I.userData.isLayoutLevelObject!==!0;)k.premultiply(I.matrix),I=I.parent;k.premultiply(n.msToPsMatrix),A.applyMatrix4(k),_?.add(A),T?.add(A);const B=s.getObjectsByLayer(P);B&&B.push(A)}),b.length>0&&$.removeEmptyObjectsFromRemovingObjects(b,v),v.traverse(M=>{$.setSharedVariablesOfObject(M),this.addSpatialFilterSection(M,s.dxfData,!0)})}setMaterialUniforms(e,i){e instanceof d.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=Y.CameraZoomUniform),e.uniforms.u_viewportScale&&i?.header.$PSLTSCALE===1&&(e.uniforms.u_viewportScale=Y.ViewportScaleUniform))}getObjectsByBoundingBox(e){const i=[];if(e.isEmpty())return S.warn("[Viewer] bbox is empty !"),i;const s=n=>{const a=rt.getBoundingBox(n,!1);e.intersectsBox(a)&&i.push(n)},r=this.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME);return r&&r.children.forEach(n=>{n.name!==Y.SNAP_GROUP_NAME&&s(n)}),i}showLayoutObjects(e){let i=0,s=0;const r=this.getModelObject();r.children.forEach(n=>{const a=n.name===e;n.visible=a,a?i++:s++}),S.debug("[Viewer] showLayoutObjects('"+e+"') sets "+i+" layout level object(s) to visible and "+s+" to hidden for model '"+r?.name+"'")}isLayerFrozenForViewport(e,i){const s=this.getLayer(e);return s&&(s.flag&1)>0?!0:!i||i.length<=0?!1:s&&i.indexOf(s.handle)>=0}addSpatialFilterSection(e,i,s=!1){if(e.userData.entityType!=="INSERT"||!e.userData.spatialFilterHandle)return;const r=this.findSpatialFilter(e.userData.spatialFilterHandle,i);if(r){let n=s,a=!1;const o=this.getAnyMaterial(e);if(o&&(o.clippingPlanes&&(n=o.clippingPlanes.length>0),a=o.clipIntersection),n&&a!==r.clipPolylines[0].bReversed){S.warn("[Viewer] Material cannot set clipIntersection to different values at the same time. clipIntersection needs to be set to true here!");return}a=r.clipPolylines[0].bReversed;const l=this.generateSectionsBySpatialFilter(r,e.matrixWorld);if(l){const c=m=>{let g=0;return m.clippingPlanes&&(g=m.clippingPlanes.length),g+l.length>Y.MaxFragmentUniforms},u=new Set,f=m=>{u.has(m.id)||(u.add(m.id),!c(m)&&dt.setMaterialSection(m,l,n,a))};e.traverse(m=>{const g=m.material;Array.isArray(g)?g.forEach(x=>{f(x)}):g&&f(g)})}}}findSpatialFilter(e,i){const s=i.objects.SPATIAL_FILTER;if(!s)return;let r;for(const n of s)if(n.handle===e){r=n;break}return r}getAnyMaterial(e){const i=e;if(i.material)return Array.isArray(i.material)?i.material[0]:i.material;let s;for(let r=0;r<e.children.length&&(s=this.getAnyMaterial(e.children[r]),!s);r++);return s}generateSectionsBySpatialFilter(e,i){const s=e.clipPolylines[0];if(s.bConcave){S.warn("[Viewer] clipPolyline.bConcave = true is not supported yet in spatialFilter !");return}Pt.copy(i),e.localMatrix&&Pt.multiply(e.localMatrix);const r=s.polyline,n=[];r.forEach(l=>{const c=l.clone().applyMatrix4(Pt);n.push(new d.Vector2(c.x,c.y))});const a=d.ShapeUtils.isClockWise(n),o=!a&&!s.bReversed||a&&s.bReversed;return dt.generateSectionPlanesByPoints(n,o)}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}highlightObject(e){if(!this.hasObject(e))return;const i=de.clonedHighlightMaterials(e,{depthTest:!1});i&&(e.userData.originalMaterial=e.material,e.material=i)}unHighlightObject(e){if(!this.hasObject(e))return;const i=e.material;e.material=e.userData.originalMaterial,delete e.userData.originalMaterial,Array.isArray(i)?i.forEach(s=>s.dispose()):i instanceof d.Material&&i.dispose()}clearHighlight(){}}class zs extends Ji{constructor(e){super();p(this,"modelId");p(this,"bbox");p(this,"rootObject");p(this,"modelObject");p(this,"highlighUsage");p(this,"transparentUsage");p(this,"edges");p(this,"highlighedObject");this.modelId=e.modelId,this.bbox=e.bbox,this.modelObject=e.object,this.rootObject=new d.Group,this.rootObject.name="rootObject-"+this.modelId,this.rootObject.userData.modelId=this.modelId,this.highlighUsage=new d.Group,this.highlighUsage.name="highlighUsage-"+this.modelId,this.highlighUsage.layers.disable(ft),this.transparentUsage=new d.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(ft),this.rootObject.add(this.modelObject),this.rootObject.add(this.highlighUsage),this.rootObject.add(this.transparentUsage)}setDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&$.setDoubleSidedMaterialToObject(e)})}revertDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&$.revertDoubleSidedMaterialToObject(e)})}getModelObject(){return this.rootObject}getBBox(){return!this.bbox&&(this.bbox=new d.Box3,this.bbox.setFromObject(this.getModelObject())),this.bbox}async enableOutline(e,i){e&&!this.edges&&(this.edges=await $.createOutlines(this.getModelObject(),void 0,i)),this.edges&&this.edges.forEach(s=>s.visible=e)}setObjectColor(e,i){this.hasObject(e)&&e.material.color.set(i)}setObjectOpacity(e,i=.5,s,r){if(this.hasObject(e)){if(e instanceof d.InstancedMesh&&r){const n=this.createInstanceMeshById(e,r,{opacity:i});n.material.opacity*=i,e.userData.instanceId=r,e.userData.transparentedMesh=n,this.transparentUsage.add(n)}else if(oe.isMergedMesh(e)&&s){const n=this.createBatchMeshById(e,s,{opacity:i});n.material.opacity*=i,e.userData.batchId=s,e.userData.transparentedMesh=n,this.transparentUsage.add(n)}else{const n=new d.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});n&&(e.userData.originalMaterial=e.material,e.material=n)}e.userData.isTransparent=!0}}clearObjectOpacity(e,i,s){if(!this.isObjectTransparent(e))return;const{transparentedMesh:r,originalMaterial:n}=e.userData;r&&(this.transparentUsage.remove(r),delete e.userData.batchId,delete e.userData.instanceId,delete e.userData.transparentedMesh),n&&(e.material=n),delete e.userData.isTransparent}isObjectTransparent(e){const{isTransparent:i}=e.userData;return!!i}setOpacity(e=.5){this.getModelObject().traverse(i=>{i instanceof d.Mesh&&this.setObjectOpacity(i,e)})}clearOpacity(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&this.clearObjectOpacity(e)})}highlightObjectById(e,i,s){if(!this.hasObjectWithId(e))return;const r=this.getModelObject().getObjectById(e);r&&this.highlightObject(r,i,s)}highlightObject(e,i,s){if(!this.hasObject(e))return;const r=new d.Color(Bs);if(e instanceof d.InstancedMesh&&s){const n=this.createInstanceMeshById(e,s,{depthTest:!1});n.material.opacity=.7,de.setMaterialColor(n.material,r),e.userData.instanceId=s,e.userData.clonedMesh=n,this.highlighUsage.add(n)}else if(oe.isMergedMesh(e)&&i){const n=this.createBatchMeshById(e,i,{depthTest:!1});n.material.opacity=.7,de.setMaterialColor(n.material,r),e.userData.batchId=i,e.userData.clonedMesh=n,this.highlighUsage.add(n)}else{const n=de.clonedHighlightMaterials(e,{depthTest:!1});n&&(e.userData.originalMaterial=e.material,e.material=n)}e.userData.isHighlight=!0,this.highlighedObject=e}clearHighlight(){if(this.highlighedObject&&this.highlighedObject.userData){const e=this.highlighedObject.userData,{clonedMesh:i,originalMaterial:s,instanceId:r,originalMatrix:n}=e;i&&(i.removeFromParent(),i.geometry.dispose(),delete e.clonedMesh),r&&n&&(this.highlighedObject.setMatrixAt(r,n),delete e.instanceId,delete e.originalMatrix),s&&(this.highlighedObject.material=s,delete e.originalMaterial),delete e.isHighlight}this.highlighUsage.clear(),this.highlighedObject=void 0}setObjectVisible(e,i){this.hasObject(e)&&(e.visible=i)}setVisible(e){this.getModelObject().traverse(i=>{i instanceof d.Mesh&&(i.visible=e)})}hasVisibleObject(){let e=0;return this.modelObject.traverseVisible(i=>{i instanceof d.Mesh&&e++}),e>0}hasInvisibleObject(){let e=0;return this.modelObject.traverse(i=>{i instanceof d.Mesh&&e++}),this.modelObject.traverseVisible(i=>{i instanceof d.Mesh&&e--}),e>0}createBatchMeshById(e,i,{opacity:s=1,depthTest:r=!0}){const n=oe.getBatchByBatchId(e,i);let a="[Viewer] Clicked on merged mesh(id: "+e.id+").";a+=" batchId: "+i+", object name: "+n?.name,n?.userData&&(a+=`
797
797
  userData: `+JSON.stringify(n.userData)),n?.parentUserData&&(a+=`
798
- parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMaterial(e.material);o.opacity=s,o.transparent=s<1,!r&&(o.depthTest=r,o.depthWrite=r,o.side=d.DoubleSide);const l=oe.cloneGeometryForBatch(e,n),c=new d.Mesh(l,o);return c.applyMatrix4(e.matrixWorld),c.matrixWorldNeedsUpdate=!0,c.name="Cloned mesh for highlighting",c.layers.enableAll(),c}createInstanceMeshById(e,i,{opacity:s=1,depthTest:r=!0}){const n=e,a=new d.Matrix4,o=new d.Matrix4;o.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),n.getMatrixAt(i,a);const l=de.cloneMaterial(n.material);l.opacity=s,l.transparent=s<1,!r&&(l.depthTest=r,l.depthWrite=r,l.side=d.DoubleSide);const c=new d.Mesh(n.geometry.clone(),l);c.applyMatrix4(e.matrixWorld.multiply(a)),c.matrixWorldNeedsUpdate=!0,c.name="Cloned mesh for highlighting",c.layers.enableAll();const u=a.clone();return u.multiplyMatrices(a,o),n.setMatrixAt(i,u),n.instanceMatrix.needsUpdate=!0,n.updateMatrix(),e.userData.originalMatrix=a,c}setClipPlanes(e){this.getModelObject().traverse(i=>{const s=i.material;s&&(Array.isArray(s)?s.forEach(r=>{r.clippingPlanes=e,r.clipIntersection=!1}):(s.clippingPlanes=e,s.clipIntersection=!1))})}getObjectTree(){}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}}class Dr extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesMaterial");p(this,"type");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");p(this,"defaultOutlineColor");p(this,"useBCOutline");p(this,"outlineVisible");this.isBimTilesMaterial=!0,this.type="BimTilesMaterial",this.defaultOutlineColor=new d.Color(ji[0],ji[1],ji[2]),this.useBCOutline=!1,this.outlineVisible=!0;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},outlineColor:{value:this.defaultOutlineColor}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
798
+ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMaterial(e.material);o.opacity=s,o.transparent=s<1,!r&&(o.depthTest=r,o.depthWrite=r,o.side=d.DoubleSide);const l=oe.cloneGeometryForBatch(e,n),c=new d.Mesh(l,o);return c.applyMatrix4(e.matrixWorld),c.matrixWorldNeedsUpdate=!0,c.name="Cloned mesh for highlighting",c.layers.enableAll(),c}createInstanceMeshById(e,i,{opacity:s=1,depthTest:r=!0}){const n=e,a=new d.Matrix4,o=new d.Matrix4;o.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),n.getMatrixAt(i,a);const l=de.cloneMaterial(n.material);l.opacity=s,l.transparent=s<1,!r&&(l.depthTest=r,l.depthWrite=r,l.side=d.DoubleSide);const c=new d.Mesh(n.geometry.clone(),l);c.applyMatrix4(e.matrixWorld.multiply(a)),c.matrixWorldNeedsUpdate=!0,c.name="Cloned mesh for highlighting",c.layers.enableAll();const u=a.clone();return u.multiplyMatrices(a,o),n.setMatrixAt(i,u),n.instanceMatrix.needsUpdate=!0,n.updateMatrix(),e.userData.originalMatrix=a,c}setClipPlanes(e){this.getModelObject().traverse(i=>{const s=i.material;s&&(Array.isArray(s)?s.forEach(r=>{r.clippingPlanes=e,r.clipIntersection=!1}):(s.clippingPlanes=e,s.clipIntersection=!1))})}getObjectTree(){}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}}class Dr extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesMaterial");p(this,"type");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");p(this,"defaultOutlineColor");p(this,"useBCOutline");p(this,"outlineVisible");this.isBimTilesMaterial=!0,this.type="BimTilesMaterial",this.defaultOutlineColor=new d.Color(Vi[0],Vi[1],Vi[2]),this.useBCOutline=!1,this.outlineVisible=!0;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},outlineColor:{value:this.defaultOutlineColor}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
799
799
  #include <common>
800
800
  #include <id_pars_vertex>
801
801
  #include <outline_bc_pars_vertex>`).replace("#include <color_vertex>",`
@@ -809,7 +809,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
809
809
  #include <state_fragment>
810
810
  #include <logdepthbuf_fragment>`).replace("#include <dithering_fragment>",`
811
811
  #include <dithering_fragment>
812
- #include <outline_bc_fragment>`)}setOutlineVisible(e){this.outlineVisible=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}enableOutline(e){this.useBCOutline=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}setOutLineColor(e){const i=e||this.defaultOutlineColor;this.uniforms.outlineColor={value:i}}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}const ah=`
812
+ #include <outline_bc_fragment>`)}setOutlineVisible(e){this.outlineVisible=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}enableOutline(e){this.useBCOutline=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}setOutLineColor(e){const i=e||this.defaultOutlineColor;this.uniforms.outlineColor={value:i}}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}const oh=`
813
813
  // When an object is transparent, we'll change its alpha value,
814
814
  // but we should not assign a fixed value because it may already
815
815
  // has an alpha value that is lower than 1.
@@ -951,12 +951,12 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
951
951
  }
952
952
 
953
953
  // TODO: isHighlighted isOverride isHovered
954
- `,oh=`
954
+ `,lh=`
955
955
  attribute int tileObjectId;
956
956
  flat varying int vTileObjectId;
957
- `,lh=`
958
- vTileObjectId = tileObjectId;
959
957
  `,hh=`
958
+ vTileObjectId = tileObjectId;
959
+ `,ch=`
960
960
  #ifdef USE_BC_OUTLINE
961
961
  // Restore barycentric coordinates
962
962
  int barycentricX = int(barycentric) & 0x1;
@@ -964,14 +964,14 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
964
964
  int barycentricZ = int(barycentric) & 0x4;
965
965
  vBarycentric = vec3(float(barycentricX), float(barycentricY), float(barycentricZ));
966
966
  #endif
967
- `,ch=`
967
+ `,dh=`
968
968
  #ifdef USE_BC_OUTLINE
969
969
  vec3 finWireframeColor = outlineColor;
970
970
  vec3 tempColor = gl_FragColor.rgb;
971
971
 
972
972
  gl_FragColor.rgb = mix(finWireframeColor, tempColor, edgeFactor3());
973
973
  #endif
974
- `,dh=`
974
+ `,uh=`
975
975
  #ifdef USE_BC_OUTLINE
976
976
  varying vec3 vBarycentric;
977
977
  uniform vec3 outlineColor;
@@ -985,12 +985,12 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
985
985
  return min(min(a3.x, a3.y), a3.z);
986
986
  }
987
987
  #endif
988
- `,uh=`
988
+ `,fh=`
989
989
  #ifdef USE_BC_OUTLINE
990
990
  attribute float barycentric;
991
991
  varying vec3 vBarycentric;
992
992
  #endif
993
- `,fh=`
993
+ `,ph=`
994
994
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
995
995
  // if (uHoverId == tileObjectId) {
996
996
  // gl_FragColor = uHoverColor;
@@ -1027,7 +1027,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1027
1027
  // gl_FragColor = vec4(0.5, 0.5, 0.5, 0.8);
1028
1028
  // }
1029
1029
  // }
1030
- `,ph=`
1030
+ `,mh=`
1031
1031
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
1032
1032
  // State priority (high to low):
1033
1033
  // - Hidden
@@ -1045,7 +1045,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1045
1045
  gl_FragColor = HIGHLIGHT_COLOR;
1046
1046
  return;
1047
1047
  }
1048
- `,mh=`
1048
+ `,gh=`
1049
1049
  flat varying int vTileObjectId;
1050
1050
  uniform float uTextureWidth;
1051
1051
  uniform float uTextureHeight;
@@ -1054,7 +1054,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1054
1054
  // uniform int uHoverId;
1055
1055
  // uniform bool uIsIsolating;
1056
1056
  // uniform bool uTransparentOthersForIsolation;
1057
- `,gh=`
1057
+ `,yh=`
1058
1058
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
1059
1059
  // State priority (high to low):
1060
1060
  // - Hidden
@@ -1072,7 +1072,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1072
1072
  gl_FragColor = HIGHLIGHT_COLOR;
1073
1073
  return;
1074
1074
  }
1075
- `,En=`
1075
+ `,_n=`
1076
1076
  #include <clipping_planes_pars_vertex>
1077
1077
 
1078
1078
  attribute int tileObjectId;
@@ -1089,7 +1089,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1089
1089
  #endif
1090
1090
  gl_Position = projectionMatrix * modelViewMatrix * mvPosition;
1091
1091
  }
1092
- `,_n=`
1092
+ `,Pn=`
1093
1093
  #include <clipping_planes_pars_fragment>
1094
1094
 
1095
1095
  flat varying int vTileObjectId;
@@ -1116,7 +1116,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1116
1116
 
1117
1117
  gl_FragColor = tileObjectId2Color(vTileObjectId);
1118
1118
  }
1119
- `,yh=`
1119
+ `,xh=`
1120
1120
  #define STANDARD
1121
1121
 
1122
1122
  varying vec3 vViewPosition;
@@ -1176,7 +1176,7 @@ void main() {
1176
1176
 
1177
1177
  #endif
1178
1178
  }
1179
- `,xh=`
1179
+ `,bh=`
1180
1180
  #define STANDARD
1181
1181
 
1182
1182
  #ifdef PHYSICAL
@@ -1342,7 +1342,7 @@ void main() {
1342
1342
 
1343
1343
  #include <outline_bc_fragment>
1344
1344
  }
1345
- `;d.ShaderChunk.outline_bc_vertex=hh;d.ShaderChunk.outline_bc_fragment=ch;d.ShaderChunk.outline_bc_pars_fragment=dh;d.ShaderChunk.outline_bc_pars_vertex=uh;d.ShaderChunk.standard_ex_vertex=yh;d.ShaderChunk.standard_ex_fragment=xh;d.ShaderChunk.common_ex=ah;d.ShaderChunk.id_pars_vertex=oh;d.ShaderChunk.id_vertex=lh;d.ShaderChunk.state_pars_fragment=mh;d.ShaderChunk.state_fragment=fh;d.ShaderChunk.state_transparent_fragment=gh;d.ShaderChunk.state_highlight_fragment=ph;d.ShaderChunk.pick_ex_vertex=En;d.ShaderChunk.pick_ex_fragment=_n;class bh extends d.ShaderMaterial{constructor(e){super(e);p(this,"isBimTilesPickMaterial");p(this,"type");p(this,"stateTexture");this.isBimTilesPickMaterial=!0,this.type="BimTilesPickMaterial";const i=e.stateTexture;this.stateTexture=i,this.uniforms={uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},uStateTexture:{value:i}},this.vertexShader=En,this.fragmentShader=_n,this.clipping=!0}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class vh extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesHighlightMaterial");p(this,"type");p(this,"transparent");p(this,"opacity");p(this,"depthTest");p(this,"side");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");this.isBimTilesHighlightMaterial=!0,this.type="BimTilesHighlightMaterial",this.transparent=!0,this.opacity=Ls,this.depthTest=!1,this.side=d.DoubleSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
1345
+ `;d.ShaderChunk.outline_bc_vertex=ch;d.ShaderChunk.outline_bc_fragment=dh;d.ShaderChunk.outline_bc_pars_fragment=uh;d.ShaderChunk.outline_bc_pars_vertex=fh;d.ShaderChunk.standard_ex_vertex=xh;d.ShaderChunk.standard_ex_fragment=bh;d.ShaderChunk.common_ex=oh;d.ShaderChunk.id_pars_vertex=lh;d.ShaderChunk.id_vertex=hh;d.ShaderChunk.state_pars_fragment=gh;d.ShaderChunk.state_fragment=ph;d.ShaderChunk.state_transparent_fragment=yh;d.ShaderChunk.state_highlight_fragment=mh;d.ShaderChunk.pick_ex_vertex=_n;d.ShaderChunk.pick_ex_fragment=Pn;class vh extends d.ShaderMaterial{constructor(e){super(e);p(this,"isBimTilesPickMaterial");p(this,"type");p(this,"stateTexture");this.isBimTilesPickMaterial=!0,this.type="BimTilesPickMaterial";const i=e.stateTexture;this.stateTexture=i,this.uniforms={uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},uStateTexture:{value:i}},this.vertexShader=_n,this.fragmentShader=Pn,this.clipping=!0}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class wh extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesHighlightMaterial");p(this,"type");p(this,"transparent");p(this,"opacity");p(this,"depthTest");p(this,"side");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");this.isBimTilesHighlightMaterial=!0,this.type="BimTilesHighlightMaterial",this.transparent=!0,this.opacity=Ls,this.depthTest=!1,this.side=d.DoubleSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
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 wh extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesTransparentMaterial");p(this,"type");p(this,"transparent");p(this,"opacity");p(this,"side");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");this.isBimTilesTransparentMaterial=!0,this.type="BimTilesTransparentMaterial",this.transparent=!0,this.opacity=Ls,this.side=d.FrontSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
1355
+ #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class Mh extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesTransparentMaterial");p(this,"type");p(this,"transparent");p(this,"opacity");p(this,"side");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");this.isBimTilesTransparentMaterial=!0,this.type="BimTilesTransparentMaterial",this.transparent=!0,this.opacity=Ls,this.side=d.FrontSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
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 Mt=(h=>(h[h.Hidden=0]="Hidden",h[h.Transparent=1]="Transparent",h[h.Highlighted=2]="Highlighted",h[h.Hovered=3]="Hovered",h))(Mt||{});class Mh{constructor(t,e){p(this,"_pickMaterial");p(this,"_highlightMaterial");p(this,"_transparentMaterial");p(this,"stateTexture");p(this,"batchMaterialMap",new Map);p(this,"instanceMaterialMap",new Map);p(this,"tileRenderer");p(this,"highlightMesh");this.tileRenderer=t,this.stateTexture=this.createStateTexture(e.maxId)}createBatchMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.batchMaterialMap.get(s)){const r=new Dr(Object.assign(Object.assign({},e),{vertexColors:!0,stateTexture:this.stateTexture}));i&&r.enableOutline(!0),this.batchMaterialMap.set(s,r)}return this.batchMaterialMap.get(s)}createInstanceMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.instanceMaterialMap.get(s)){const r=new Dr(Object.assign(Object.assign({},e),{stateTexture:this.stateTexture}));i&&r.enableOutline(!0),this.instanceMaterialMap.set(s,r)}return this.instanceMaterialMap.get(s)}get highlightMaterial(){return this._highlightMaterial||(this._highlightMaterial=new vh({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new wh({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new bh({stateTexture:this.stateTexture})),this._pickMaterial}createStateTexture(t){t+=1;const e=d.MathUtils.ceilPowerOfTwo(Math.sqrt(t)),i=d.MathUtils.ceilPowerOfTwo(Math.ceil(t/e));return new d.DataTexture(new Uint8Array(e*i*4),e,i,d.RGBAFormat,d.UnsignedByteType)}updateState(t,e,i,s){const r=this.stateTexture.image.data;for(let n=0;n<e.length;n++){const a=e[n],o=a*4;switch(t){case 0:r[o]=this.setFlag(r[o],t,i);break;case 1:{r[o]=this.setFlag(r[o],t,i);let l=0;i&&s!=null&&(l=this.opacity2Int8(s)),r[o+1]=l,r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],2,!1)}break;case 2:r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],t,i);break;case 3:r[o]=this.setFlag(r[o],t,i);break}}switch(t){case 1:this.setHiddenForTransparent(e,i);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setHiddenForTransparent(t,e){if(t.length===0)return;const i=Date.now(),s=this.stateTexture.image,r=this.stateTexture.image.data;for(let n=0;n<s.width*s.height;n++){const a=n*4;this.getFlag(r[a],1)?r[a+2]=this.setFlag(r[a],0,!1):r[a+2]=this.setFlag(r[a],0,!0)}e?this.updateClonedTransparentMesh(t):this.clearClonedTransparentMesh(t),S.info("[BimTiles] setHiddenForTransparent took "+(Date.now()-i)/1e3+"s")}updateClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n],o=a.userData.userIds;if(!o||a.sourceMesh)continue;const l=a.clonedMesh;for(let c=0;c<t.length;c++){const u=t[c];if(o.indexOf(u)>-1){if(l){l.userData.handleUserIds.has(u)||l.userData.handleUserIds.add(u);continue}this.cloneMeshForTransparent(e,a),a.clonedMesh.userData.handleUserIds.clear(),a.clonedMesh.userData.handleUserIds.add(u)}}}})}clearClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n];if(!a||!a.userData.userIds||a.sourceMesh)continue;const l=a.clonedMesh;for(let c=0;c<t.length;c++){const u=t[c];l&&l.userData.handleUserIds.has(u)&&l.userData.handleUserIds.delete(u)}l&&l.userData.handleUserIds.size===0&&this.disposeClonedTransparentMesh(a)}})}cloneMeshForTransparent(t,e){if(e.clonedMesh)return;const i=e.clone();i.userData={},i.userData.handleUserIds=new Set(e.userData.userIds),i.sourceMesh=e;const s=new d.BufferGeometry,r=e.geometry.getAttribute("position"),n=e.geometry.index,a=e.geometry.getAttribute("tileObjectId");s.setAttribute("position",r),s.setAttribute("tileObjectId",a),n&&s.setIndex(n),i.geometry=s,i.material=this.transparentMaterial,e.clonedMesh=i,t.add(i)}disposeClonedTransparentMesh(t){t.clonedMesh&&(t.clonedMesh.removeFromParent(),t.clonedMesh=void 0)}updateAllClonedTransparentMesh(){this.tileRenderer.forEachLoadedModel((t,e)=>{const i=t.children,s=i.length;for(let r=0;r<s;r++){const n=i[r];if(!n)break;!n.userData.userIds||n.sourceMesh||n.clonedMesh||this.cloneMeshForTransparent(t,n)}})}clearAllClonedTransparentMesh(){const t=[];this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n];if(!a)break;!a.userData.userIds||a.sourceMesh||a.clonedMesh&&t.push(a)}});for(let e=0;e<t.length;e++)this.disposeClonedTransparentMesh(t[e])}setHidden(t){const e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const r=s*4;i[r]=this.setFlag(i[r],0,t)}this.updateMaterialStates(),this.updateHighlightMesh()}setOpacity(t){const e=Date.now(),i=this.opacity2Int8(t),s=t<1,r=this.stateTexture.image,n=this.stateTexture.image.data;for(let a=0;a<r.width*r.height;a++){const o=a*4;n[o]=this.setFlag(n[o],1,s),n[o]=this.setFlag(n[o],3,!1),n[o]=this.setFlag(n[o],2,!1),n[o+1]=i,n[o+2]=this.setFlag(n[o],0,!s)}s?this.updateAllClonedTransparentMesh():this.clearAllClonedTransparentMesh(),this.updateMaterialStates(),S.info("[BimTiles] setOpacity took "+(Date.now()-e)/1e3+"s")}clearHovered(){const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;e[s]=this.setFlag(e[s],3,!1)}this.updateMaterialStates()}updateHighlightMesh(){this.highlightMesh&&this.clearHighlightMesh();const t=this.getHighlightUserIds();if(t.length===0)return;const e=this.tileRenderer.getGeometryByUserIds(t);if(!e){S.warn("[BimTiles] Failed to get geometry by userIds:",t);return}this.highlightMesh=new d.Mesh(e,this.highlightMaterial),this.tileRenderer.highlighUsage.add(this.highlightMesh)}clearHighlightMesh(){this.disposeMesh(this.highlightMesh),this.highlightMesh=void 0}clearState(t){const e=this.stateTexture.image.data;for(let i=0;i<e.length;i+=4)e[i]=this.setFlag(e[i],t,!1);switch(t){case 1:this.setOpacity(1);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setDoubleSidedMaterials(){const t=e=>{e.side!==d.DoubleSide&&(e.userData.originalSide==null&&(e.userData.originalSide=e.side),e.side=d.DoubleSide)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}revertDoubleSidedMaterials(){const t=e=>{e.userData.originalSide!=null&&(e.side=e.userData.originalSide,e.userData.originalSide=void 0)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}setClipPlanes(t){const e=t.length>0;this.batchMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.instanceMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.highlightMaterial.clippingPlanes=e?t:[],this.highlightMaterial.clipIntersection=!1,this.highlightMaterial.clipShadows=!0,this.pickMaterial.clippingPlanes=e?t:[],this.pickMaterial.clipIntersection=!1,this.pickMaterial.clipShadows=!0}resetState(){this.clearAllClonedTransparentMesh(),this.clearHighlightMesh(),this.clearHovered(),this.stateTexture.image.data.fill(0),this.updateMaterialStates()}updateMaterialStates(){this.stateTexture.needsUpdate=!0}dispose(){this.stateTexture.dispose(),this.batchMaterialMap.forEach(t=>t.dispose()),this.instanceMaterialMap.forEach(t=>t.dispose()),this.pickMaterial.dispose(),this.highlightMaterial.dispose(),this.transparentMaterial.dispose()}disposeMesh(t){t&&(t.removeFromParent(),t.geometry.dispose(),t.geometry.attributes={},t.geometry.index=null)}hasVisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],0))return!0}return!1}hasInvisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(!this.getFlag(e[s],0))return!0}return!1}getTransparentUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const r=s*4;this.getFlag(i[r],1)&&t.push(s)}return t}getHighlightUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const r=s*4;this.getFlag(i[r],2)&&t.push(s)}return t}getHoveredObject(){if(!this.stateTexture)return;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],3)){const n=i;return{tilesetId:this.tileRenderer.tilesetId,userId:n}}}}opacity2Int8(t){let e=Math.floor(t*255);return e<=0?e=1:e>=255&&(e=0),e}setFlag(t,e,i){const s=Number(e);if(i){const r=1<<s;return t|r}else{const r=~(1<<s);return t&r}}getFlag(t,e){const i=Number(e);return(t&1<<i)!==0}}const Th={9728:d.NearestFilter,9729:d.LinearFilter},Ch={9984:d.NearestMipmapNearestFilter,9985:d.LinearMipmapNearestFilter,9986:d.NearestMipmapLinearFilter,9987:d.LinearMipmapLinearFilter},Br={33071:d.ClampToEdgeWrapping,33648:d.MirroredRepeatWrapping,10497:d.RepeatWrapping};var qi=(h=>(h.Opaque="OPAQUE",h.Mask="MASK",h.Blend="BLEND",h))(qi||{});const Pn={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var js=(h=>(h[h.scalar=1]="scalar",h[h.vec2=2]="vec2",h[h.vec3=3]="vec3",h[h.vec4=4]="vec4",h[h.mat2=4]="mat2",h[h.mat3=9]="mat3",h[h.mat4=16]="mat4",h))(js||{});class Sh{constructor(t,e){p(this,"baseUrl");p(this,"textureLoaderCache",new Map);p(this,"materialCache",new Map);p(this,"textureCache",new Map);p(this,"userDataCache",new Map);p(this,"familyInstanceIdCache",new Map);p(this,"familyInstanceAndUserIdsCache",new Map);p(this,"userIdAndUserDataCache",new Map);p(this,"userBoxCache",new Map);p(this,"protoRoot");p(this,"preprocessURL",null);this.baseUrl=t,this.protoRoot=e}async getProperty(t,e,i){return V.isBinaryFile(t)?this.getPropertyFromBinary(t,e,i):this.getPropertyFromJson(t,e)}async getPropertyFromJson(t,e){return await fetch(this.baseUrl+t,e).then(i=>{if(i.ok)return i.json();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+i.status+" : "+i.statusText)})}async getPropertyFromBinary(t,e,i){return await fetch(this.baseUrl+t,e).then(s=>{if(s.ok)return s.arrayBuffer();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+s.status+" : "+s.statusText)}).then(s=>{const r=new Uint8Array(s),n=Ds.inflate(r);return this.protoRoot.lookupType(i).decode(n)})}getTextureLoader(t){if(t!=="dds"&&(t="default"),this.textureLoaderCache.has(t))return this.textureLoaderCache.get(t);let e;return t==="dds"?e=new wa.DDSLoader:e=new d.TextureLoader,this.textureLoaderCache.set(t,e),e}loadTexture(t,e){const i=e.textures[t],s=e.images[i.image],r=s.uri+":"+i.sampler;if(this.textureCache.get(r))return this.textureCache.get(r);const n=this.getTextureLoader(s.type),a=new Promise((o,l)=>{n.load(this.baseUrl+s.uri,c=>{const u=e.samplers||{},f=u[c.sampler]||{};c.magFilter=Th[f.magFilter]||d.LinearFilter,c.minFilter=Ch[f.minFilter]||d.LinearMipmapLinearFilter,c.wrapS=Br[f.wrapS]||d.RepeatWrapping,c.wrapT=Br[f.wrapT]||d.RepeatWrapping,o(c)},void 0,c=>{throw S.error("[BimTiles] Couldn't load texture",s.uri),l(c),c})});return this.textureCache.set(r,a),a}assignTexture(t,e,i,s,r){return i.index?this.loadTexture(i.index,s).then(n=>n?(i.texCoord!==void 0&&i.texCoord>0&&(n=n.clone(),n.channel=i.texCoord),r!==void 0&&(n.colorSpace=r),n):null).catch(()=>null):Promise.resolve(null)}async parseMaterial(t){const e=Object.values(t.materials).map(async i=>{const s={};if(i.name&&(s.name=i.name),s.color=new d.Color(1,1,1),s.opacity=1,Array.isArray(i.baseColorFactor)){const n=i.baseColorFactor;s.color.setRGB(n[0],n[1],n[2],d.LinearSRGBColorSpace),s.opacity=n[3]}i.baseColorTexture&&(s.map=await this.assignTexture(s,"map",i.baseColorTexture,t,d.SRGBColorSpace)),s.metalness=i.metallicFactor!==void 0?i.metallicFactor:1,s.roughness=i.roughnessFactor!==void 0?i.roughnessFactor:1,i.metallicRoughnessTexture&&(s.metalnessMap=await this.assignTexture(s,"metalnessMap",i.metallicRoughnessTexture,t),s.roughnessMap=await this.assignTexture(s,"roughnessMap",i.metallicRoughnessTexture,t)),i.doubleSided===!0&&(s.side=d.DoubleSide);const r=i.alphaMode||qi.Opaque;if(r===qi.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,r===qi.Mask&&(s.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture&&(s.normalMap=await this.assignTexture(s,"normalMap",i.normalTexture,t),s.normalScale=new d.Vector2(1,1)),i.occlusionTexture&&(s.aoMap=await this.assignTexture(s,"aoMap",i.occlusionTexture,t)),i.emissiveFactor){const n=i.emissiveFactor;s.emissive=new d.Color().setRGB(n[0],n[1],n[2],d.LinearSRGBColorSpace)}return i.emissiveTexture&&(s.emissiveMap=await this.assignTexture(s,"emissiveMap",i.emissiveTexture,t,d.SRGBColorSpace)),this.materialCache.get(i.id)||this.materialCache.set(i.id,s),this.materialCache.get(i.id)});return Promise.all(e).then(()=>{S.info("[BimTilesPropertyParser] material parser complete.")})}parseUserData(t){const{userDataKeys:e,userDataValues:i,userDataItems:s}=t;s.forEach((r,n)=>{r.indexMap&&(r=r.indexMap);const a={};for(const o in r)a[e[o]]=i[r[o]];this.userDataCache.set(n,a)})}parseUserId(t){const{modelIds:e,familyInstanceIds:i,modelTable:s,userIdTable:r}=t;Object.keys(s).forEach(n=>{const a=Number(n),o=e[a],l=s[a].value||s[a],c=l.map(u=>i[u]);this.familyInstanceIdCache.set(o,c)}),Object.keys(r).forEach(n=>{const a=Number(n),o=r[a].value||r[a],l=e[o[0]],c=i[o[1]],u=l+"#"+c;this.familyInstanceAndUserIdsCache.has(u)||this.familyInstanceAndUserIdsCache.set(u,[]),this.familyInstanceAndUserIdsCache.get(u).push(a);const f=o[2];this.userIdAndUserDataCache.set(a,{modelId:l,familyInstanceId:c,userDataIndex:f})})}parseUserIdBox(t,e){t.boxMap&&(t=t.boxMap),Object.keys(t).forEach(i=>{const s=Number(i),r=t[s].value?t[s].value:t[s],n=new d.Box3().setFromArray(r);e&&n.applyMatrix4(e),this.userBoxCache.set(s,n)})}getMaterialParameters(t){return this.materialCache.get(t)}getUserData(t){if(this.userIdAndUserDataCache.size===0)return;const e=this.userIdAndUserDataCache.get(t);if(!e?.userDataIndex)return;let i=this.userDataCache.get(e.userDataIndex);return i||(i={}),i.modelId=e.modelId,i.familyInstanceId=e.familyInstanceId,i}getFamilyInstanceIdsByModelId(t){return this.familyInstanceIdCache.get(t)}getUserIdBox(t){return this.userBoxCache.get(t)}getUserIds(){return Array.from(this.userIdAndUserDataCache.keys())}getUserIdsByFamilyInstanceId(t,e){if(this.familyInstanceAndUserIdsCache.size===0)return[];const i=t+"#"+e;return this.familyInstanceAndUserIdsCache.get(i)||[]}getUserIdByUserDataIndex(t){if(this.userIdAndUserDataCache.size!==0){for(const[e,i]of this.userIdAndUserDataCache)if(i.userDataIndex===t)return e}}getUserIdByFilter(t){const e=[];return this.userDataCache.size===0||this.userDataCache.forEach((i,s)=>{if(t(i)){const r=this.getUserIdByUserDataIndex(s);r!==void 0&&e.push(r)}}),e}dispose(){this.textureLoaderCache.clear(),this.materialCache.clear(),this.textureCache.clear(),this.userDataCache.clear(),this.familyInstanceIdCache.clear(),this.familyInstanceAndUserIdsCache.clear(),this.userIdAndUserDataCache.clear(),this.userBoxCache.clear()}}function An(h){return new TextDecoder().decode(h)}function Lr(h,t){return((h&255)<<24)+(t&16777215)}function Oh(h){return h[3]}function Eh(h){return(h[0]<<16)+(h[1]<<8)+h[2]}function In(h){const t=h.BYTES_PER_ELEMENT,e=(1<<8*t-1)-1,i=2,s=h.length/i,r=new d.Vector2,n=new d.Vector3,a=new Float32Array(s*3);for(let o=0;o<s;o++)r.fromArray(h,o*i),R.OctDecode(r,n,e),n.toArray(a,o*3);return a}class Rr{parse(t,e){const i=[];for(let s=0;s<e.length;s++){const r=e[s],{byteOffset:n,byteLength:a,batchTable:o}=r,l=t.slice(n,n+a);i.push(this.parseMesh(l,r,o))}return i}parseMesh(t,e,i){const s=e.primitive,r=e.buffers,n=this.parseTypedArray(t,r[s.position]),a=s.color?this.parseTypedArray(t,r[s.color]):new Float32Array,o=s.indice?this.parseTypedArray(t,r[s.indice]):new Uint16Array;let l=s.normal?this.parseTypedArray(t,r[s.normal]):new Float32Array;s.normal>=0&&s.normalCompressed&&(l=In(l));const c=s.tangent?this.parseTypedArray(t,r[s.tangent]):new Float32Array,u=s.uv_0?this.parseTypedArray(t,r[s.uv_0]):new Float32Array,f=s.barycentric?this.parseTypedArray(t,r[s.barycentric]):new Uint8Array,m=new Array(n.length/3);return i.forEach(g=>{m.fill(g.userId,g.positionStart,g.positionStart+g.positionCount)}),{type:s.type,position:n,indice:o,color:a,normal:l,tangent:c,barycentric:f,uv:u,userIds:m,materialId:s.materialId||s.material,batchTable:e.batchTable}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:r,type:n,componentType:a}=e,o=Number(js[n]),l=Pn[a],c=t.slice(i,i+s);return new l(c,0,r*o)}}const St=class St{constructor(){p(this,"header")}async parse(t,e,i){const s=[];for(let r=0;r<t.length;r++){const{blobId:n,url:a,instances:o}=t[r],l=await this.getInstancedMeshByUrlAndBlobId(e+a,n,i);if(!l){S.warn("[BimTiles] Failed to get InstancedMesh by "+(e+a)+", bloblId '"+n+"'");continue}const c=[],u=[];o.forEach(m=>{c.push(m.userId),u.push(...m.transform)});const f=Object.assign(Object.assign({},l),{userIds:c,matrices:u});s.push(f)}return s}parseInstanceBuffer(t){const e=new xi(t);this.header={magic:e.readUtf8String(4),version:e.readUint32(),byteLength:e.readUint64()};const i=e.readUint32(),s=e.readUint32(),r=e.readUint32(),n=e.readUint64(),a=t.slice(i,i+s),o=An(new Uint8Array(a,0,s)),l=JSON.parse(o),c=t.slice(r,r+n);return this.parseMeshes(c,l.meshes)}parseInstanceProto(t,e){const i=Ds.inflate(t),s=e.lookupType("PBTileContent"),r=s.decode(i);return this.parseMeshes(r.binaries.slice().buffer,r.meshes)}parseMeshes(t,e){const i=[];for(let s=0;s<e.length;s++){const r=e[s],{byteOffset:n=0,byteLength:a}=r,o=t.slice(n,n+a);i.push(this.parseMesh(o,r))}return i}parseMesh(t,e){const i=e.primitive,s=e.buffers,r=this.parseTypedArray(t,s[i.position]),n=i.color?this.parseTypedArray(t,s[i.color]):new Float32Array,a=i.indice?this.parseTypedArray(t,s[i.indice]):new Uint16Array;let o=i.normal?this.parseTypedArray(t,s[i.normal]):new Float32Array;i.normal>=0&&i.normalCompressed&&(o=In(o));const l=i.tangent?this.parseTypedArray(t,s[i.tangent]):new Float32Array,c=i.uv_0?this.parseTypedArray(t,s[i.uv_0]):new Float32Array,u=i.barycentric?this.parseTypedArray(t,s[i.barycentric]):new Uint8Array,f=[],m=[];return{type:i.type,position:r,indice:a,color:n,normal:o,tangent:l,uv:c,barycentric:u,userIds:f,matrices:m,materialId:i.materialId||i.material}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:r,type:n,componentType:a}=e,o=Number(js[n]),l=Pn[a],c=t.slice(i,i+s);return new l(c,0,r*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!St.instanceDataMap[t]){const s=await fetch(t).then(n=>n.arrayBuffer()),r=new Uint8Array(s);V.isGzip(r)&&i?St.instanceDataMap[t]=this.parseInstanceProto(r,i):St.instanceDataMap[t]=this.parseInstanceBuffer(s)}return St.instanceDataMap[t][e]}};p(St,"instanceDataMap",{});let Yi=St;class _h{async parse(t,e,i){const s=new Uint8Array(t);return V.isGzip(s)?this.parseProto(s,e,i):this.parseBinary(t,e)}async parseBinary(t,e){const i=new xi(t),s=i.readUtf8String(4),r=i.readUint32(),n=i.readUint64(),a=i.readUint32(),o=i.readUint32(),l=i.readUint32(),c=i.readUint64(),u=t.slice(a,a+o),f=An(new Uint8Array(u,0,o)),m=JSON.parse(f);S.debug("[BimTiles] Tile, magic("+s+"), version("+r+"), byteLength("+n+"), tileJson:",m);const g=t.slice(l,l+c),x=new Rr().parse(g,m.batchedMeshes),y=await new Yi().parse(m.instancedMeshes,e);return{batchedMeshes:x,instancedMeshes:y}}async parseProto(t,e,i){const s=Ds.inflate(t),r=i.lookupType("PBTileContent").decode(s),n=r.header;S.debug("[BimTiles] Tile, magic("+n.magic+"), version("+n.version+"), byteLength("+s.byteLength+"), tileJson:",r);const a=r.binaries.slice().buffer,o=new Rr().parse(a,r.meshes),l=await new Yi().parse(r.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const Ph=`syntax = "proto3";\r
1365
+ #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}var Mt=(h=>(h[h.Hidden=0]="Hidden",h[h.Transparent=1]="Transparent",h[h.Highlighted=2]="Highlighted",h[h.Hovered=3]="Hovered",h))(Mt||{});class Th{constructor(t,e){p(this,"_pickMaterial");p(this,"_highlightMaterial");p(this,"_transparentMaterial");p(this,"stateTexture");p(this,"batchMaterialMap",new Map);p(this,"instanceMaterialMap",new Map);p(this,"tileRenderer");p(this,"highlightMesh");this.tileRenderer=t,this.stateTexture=this.createStateTexture(e.maxId)}createBatchMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.batchMaterialMap.get(s)){const r=new Dr(Object.assign(Object.assign({},e),{vertexColors:!0,stateTexture:this.stateTexture}));i&&r.enableOutline(!0),this.batchMaterialMap.set(s,r)}return this.batchMaterialMap.get(s)}createInstanceMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.instanceMaterialMap.get(s)){const r=new Dr(Object.assign(Object.assign({},e),{stateTexture:this.stateTexture}));i&&r.enableOutline(!0),this.instanceMaterialMap.set(s,r)}return this.instanceMaterialMap.get(s)}get highlightMaterial(){return this._highlightMaterial||(this._highlightMaterial=new wh({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new Mh({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new vh({stateTexture:this.stateTexture})),this._pickMaterial}createStateTexture(t){t+=1;const e=d.MathUtils.ceilPowerOfTwo(Math.sqrt(t)),i=d.MathUtils.ceilPowerOfTwo(Math.ceil(t/e));return new d.DataTexture(new Uint8Array(e*i*4),e,i,d.RGBAFormat,d.UnsignedByteType)}updateState(t,e,i,s){const r=this.stateTexture.image.data;for(let n=0;n<e.length;n++){const a=e[n],o=a*4;switch(t){case 0:r[o]=this.setFlag(r[o],t,i);break;case 1:{r[o]=this.setFlag(r[o],t,i);let l=0;i&&s!=null&&(l=this.opacity2Int8(s)),r[o+1]=l,r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],2,!1)}break;case 2:r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],t,i);break;case 3:r[o]=this.setFlag(r[o],t,i);break}}switch(t){case 1:this.setHiddenForTransparent(e,i);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setHiddenForTransparent(t,e){if(t.length===0)return;const i=Date.now(),s=this.stateTexture.image,r=this.stateTexture.image.data;for(let n=0;n<s.width*s.height;n++){const a=n*4;this.getFlag(r[a],1)?r[a+2]=this.setFlag(r[a],0,!1):r[a+2]=this.setFlag(r[a],0,!0)}e?this.updateClonedTransparentMesh(t):this.clearClonedTransparentMesh(t),S.info("[BimTiles] setHiddenForTransparent took "+(Date.now()-i)/1e3+"s")}updateClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n],o=a.userData.userIds;if(!o||a.sourceMesh)continue;const l=a.clonedMesh;for(let c=0;c<t.length;c++){const u=t[c];if(o.indexOf(u)>-1){if(l){l.userData.handleUserIds.has(u)||l.userData.handleUserIds.add(u);continue}this.cloneMeshForTransparent(e,a),a.clonedMesh.userData.handleUserIds.clear(),a.clonedMesh.userData.handleUserIds.add(u)}}}})}clearClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n];if(!a||!a.userData.userIds||a.sourceMesh)continue;const l=a.clonedMesh;for(let c=0;c<t.length;c++){const u=t[c];l&&l.userData.handleUserIds.has(u)&&l.userData.handleUserIds.delete(u)}l&&l.userData.handleUserIds.size===0&&this.disposeClonedTransparentMesh(a)}})}cloneMeshForTransparent(t,e){if(e.clonedMesh)return;const i=e.clone();i.userData={},i.userData.handleUserIds=new Set(e.userData.userIds),i.sourceMesh=e;const s=new d.BufferGeometry,r=e.geometry.getAttribute("position"),n=e.geometry.index,a=e.geometry.getAttribute("tileObjectId");s.setAttribute("position",r),s.setAttribute("tileObjectId",a),n&&s.setIndex(n),i.geometry=s,i.material=this.transparentMaterial,e.clonedMesh=i,t.add(i)}disposeClonedTransparentMesh(t){t.clonedMesh&&(t.clonedMesh.removeFromParent(),t.clonedMesh=void 0)}updateAllClonedTransparentMesh(){this.tileRenderer.forEachLoadedModel((t,e)=>{const i=t.children,s=i.length;for(let r=0;r<s;r++){const n=i[r];if(!n)break;!n.userData.userIds||n.sourceMesh||n.clonedMesh||this.cloneMeshForTransparent(t,n)}})}clearAllClonedTransparentMesh(){const t=[];this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n];if(!a)break;!a.userData.userIds||a.sourceMesh||a.clonedMesh&&t.push(a)}});for(let e=0;e<t.length;e++)this.disposeClonedTransparentMesh(t[e])}setHidden(t){const e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const r=s*4;i[r]=this.setFlag(i[r],0,t)}this.updateMaterialStates(),this.updateHighlightMesh()}setOpacity(t){const e=Date.now(),i=this.opacity2Int8(t),s=t<1,r=this.stateTexture.image,n=this.stateTexture.image.data;for(let a=0;a<r.width*r.height;a++){const o=a*4;n[o]=this.setFlag(n[o],1,s),n[o]=this.setFlag(n[o],3,!1),n[o]=this.setFlag(n[o],2,!1),n[o+1]=i,n[o+2]=this.setFlag(n[o],0,!s)}s?this.updateAllClonedTransparentMesh():this.clearAllClonedTransparentMesh(),this.updateMaterialStates(),S.info("[BimTiles] setOpacity took "+(Date.now()-e)/1e3+"s")}clearHovered(){const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;e[s]=this.setFlag(e[s],3,!1)}this.updateMaterialStates()}updateHighlightMesh(){this.highlightMesh&&this.clearHighlightMesh();const t=this.getHighlightUserIds();if(t.length===0)return;const e=this.tileRenderer.getGeometryByUserIds(t);if(!e){S.warn("[BimTiles] Failed to get geometry by userIds:",t);return}this.highlightMesh=new d.Mesh(e,this.highlightMaterial),this.tileRenderer.highlighUsage.add(this.highlightMesh)}clearHighlightMesh(){this.disposeMesh(this.highlightMesh),this.highlightMesh=void 0}clearState(t){const e=this.stateTexture.image.data;for(let i=0;i<e.length;i+=4)e[i]=this.setFlag(e[i],t,!1);switch(t){case 1:this.setOpacity(1);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setDoubleSidedMaterials(){const t=e=>{e.side!==d.DoubleSide&&(e.userData.originalSide==null&&(e.userData.originalSide=e.side),e.side=d.DoubleSide)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}revertDoubleSidedMaterials(){const t=e=>{e.userData.originalSide!=null&&(e.side=e.userData.originalSide,e.userData.originalSide=void 0)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}setClipPlanes(t){const e=t.length>0;this.batchMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.instanceMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.highlightMaterial.clippingPlanes=e?t:[],this.highlightMaterial.clipIntersection=!1,this.highlightMaterial.clipShadows=!0,this.pickMaterial.clippingPlanes=e?t:[],this.pickMaterial.clipIntersection=!1,this.pickMaterial.clipShadows=!0}resetState(){this.clearAllClonedTransparentMesh(),this.clearHighlightMesh(),this.clearHovered(),this.stateTexture.image.data.fill(0),this.updateMaterialStates()}updateMaterialStates(){this.stateTexture.needsUpdate=!0}dispose(){this.stateTexture.dispose(),this.batchMaterialMap.forEach(t=>t.dispose()),this.instanceMaterialMap.forEach(t=>t.dispose()),this.pickMaterial.dispose(),this.highlightMaterial.dispose(),this.transparentMaterial.dispose()}disposeMesh(t){t&&(t.removeFromParent(),t.geometry.dispose(),t.geometry.attributes={},t.geometry.index=null)}hasVisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],0))return!0}return!1}hasInvisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(!this.getFlag(e[s],0))return!0}return!1}getTransparentUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const r=s*4;this.getFlag(i[r],1)&&t.push(s)}return t}getHighlightUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const r=s*4;this.getFlag(i[r],2)&&t.push(s)}return t}getHoveredObject(){if(!this.stateTexture)return;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],3)){const n=i;return{tilesetId:this.tileRenderer.tilesetId,userId:n}}}}opacity2Int8(t){let e=Math.floor(t*255);return e<=0?e=1:e>=255&&(e=0),e}setFlag(t,e,i){const s=Number(e);if(i){const r=1<<s;return t|r}else{const r=~(1<<s);return t&r}}getFlag(t,e){const i=Number(e);return(t&1<<i)!==0}}const Ch={9728:d.NearestFilter,9729:d.LinearFilter},Sh={9984:d.NearestMipmapNearestFilter,9985:d.LinearMipmapNearestFilter,9986:d.NearestMipmapLinearFilter,9987:d.LinearMipmapLinearFilter},Br={33071:d.ClampToEdgeWrapping,33648:d.MirroredRepeatWrapping,10497:d.RepeatWrapping};var Wi=(h=>(h.Opaque="OPAQUE",h.Mask="MASK",h.Blend="BLEND",h))(Wi||{});const An={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var js=(h=>(h[h.scalar=1]="scalar",h[h.vec2=2]="vec2",h[h.vec3=3]="vec3",h[h.vec4=4]="vec4",h[h.mat2=4]="mat2",h[h.mat3=9]="mat3",h[h.mat4=16]="mat4",h))(js||{});class Oh{constructor(t,e){p(this,"baseUrl");p(this,"textureLoaderCache",new Map);p(this,"materialCache",new Map);p(this,"textureCache",new Map);p(this,"userDataCache",new Map);p(this,"familyInstanceIdCache",new Map);p(this,"familyInstanceAndUserIdsCache",new Map);p(this,"userIdAndUserDataCache",new Map);p(this,"userBoxCache",new Map);p(this,"protoRoot");p(this,"preprocessURL",null);this.baseUrl=t,this.protoRoot=e}async getProperty(t,e,i){return z.isBinaryFile(t)?this.getPropertyFromBinary(t,e,i):this.getPropertyFromJson(t,e)}async getPropertyFromJson(t,e){return await fetch(this.baseUrl+t,e).then(i=>{if(i.ok)return i.json();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+i.status+" : "+i.statusText)})}async getPropertyFromBinary(t,e,i){return await fetch(this.baseUrl+t,e).then(s=>{if(s.ok)return s.arrayBuffer();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+s.status+" : "+s.statusText)}).then(s=>{const r=new Uint8Array(s),n=Ds.inflate(r);return this.protoRoot.lookupType(i).decode(n)})}getTextureLoader(t){if(t!=="dds"&&(t="default"),this.textureLoaderCache.has(t))return this.textureLoaderCache.get(t);let e;return t==="dds"?e=new Ma.DDSLoader:e=new d.TextureLoader,this.textureLoaderCache.set(t,e),e}loadTexture(t,e){const i=e.textures[t],s=e.images[i.image],r=s.uri+":"+i.sampler;if(this.textureCache.get(r))return this.textureCache.get(r);const n=this.getTextureLoader(s.type),a=new Promise((o,l)=>{n.load(this.baseUrl+s.uri,c=>{const u=e.samplers||{},f=u[c.sampler]||{};c.magFilter=Ch[f.magFilter]||d.LinearFilter,c.minFilter=Sh[f.minFilter]||d.LinearMipmapLinearFilter,c.wrapS=Br[f.wrapS]||d.RepeatWrapping,c.wrapT=Br[f.wrapT]||d.RepeatWrapping,o(c)},void 0,c=>{throw S.error("[BimTiles] Couldn't load texture",s.uri),l(c),c})});return this.textureCache.set(r,a),a}assignTexture(t,e,i,s,r){return i.index?this.loadTexture(i.index,s).then(n=>n?(i.texCoord!==void 0&&i.texCoord>0&&(n=n.clone(),n.channel=i.texCoord),r!==void 0&&(n.colorSpace=r),n):null).catch(()=>null):Promise.resolve(null)}async parseMaterial(t){const e=Object.values(t.materials).map(async i=>{const s={};if(i.name&&(s.name=i.name),s.color=new d.Color(1,1,1),s.opacity=1,Array.isArray(i.baseColorFactor)){const n=i.baseColorFactor;s.color.setRGB(n[0],n[1],n[2],d.LinearSRGBColorSpace),s.opacity=n[3]}i.baseColorTexture&&(s.map=await this.assignTexture(s,"map",i.baseColorTexture,t,d.SRGBColorSpace)),s.metalness=i.metallicFactor!==void 0?i.metallicFactor:1,s.roughness=i.roughnessFactor!==void 0?i.roughnessFactor:1,i.metallicRoughnessTexture&&(s.metalnessMap=await this.assignTexture(s,"metalnessMap",i.metallicRoughnessTexture,t),s.roughnessMap=await this.assignTexture(s,"roughnessMap",i.metallicRoughnessTexture,t)),i.doubleSided===!0&&(s.side=d.DoubleSide);const r=i.alphaMode||Wi.Opaque;if(r===Wi.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,r===Wi.Mask&&(s.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture&&(s.normalMap=await this.assignTexture(s,"normalMap",i.normalTexture,t),s.normalScale=new d.Vector2(1,1)),i.occlusionTexture&&(s.aoMap=await this.assignTexture(s,"aoMap",i.occlusionTexture,t)),i.emissiveFactor){const n=i.emissiveFactor;s.emissive=new d.Color().setRGB(n[0],n[1],n[2],d.LinearSRGBColorSpace)}return i.emissiveTexture&&(s.emissiveMap=await this.assignTexture(s,"emissiveMap",i.emissiveTexture,t,d.SRGBColorSpace)),this.materialCache.get(i.id)||this.materialCache.set(i.id,s),this.materialCache.get(i.id)});return Promise.all(e).then(()=>{S.info("[BimTilesPropertyParser] material parser complete.")})}parseUserData(t){const{userDataKeys:e,userDataValues:i,userDataItems:s}=t;s.forEach((r,n)=>{r.indexMap&&(r=r.indexMap);const a={};for(const o in r)a[e[o]]=i[r[o]];this.userDataCache.set(n,a)})}parseUserId(t){const{modelIds:e,familyInstanceIds:i,modelTable:s,userIdTable:r}=t;Object.keys(s).forEach(n=>{const a=Number(n),o=e[a],l=s[a].value||s[a],c=l.map(u=>i[u]);this.familyInstanceIdCache.set(o,c)}),Object.keys(r).forEach(n=>{const a=Number(n),o=r[a].value||r[a],l=e[o[0]],c=i[o[1]],u=l+"#"+c;this.familyInstanceAndUserIdsCache.has(u)||this.familyInstanceAndUserIdsCache.set(u,[]),this.familyInstanceAndUserIdsCache.get(u).push(a);const f=o[2];this.userIdAndUserDataCache.set(a,{modelId:l,familyInstanceId:c,userDataIndex:f})})}parseUserIdBox(t,e){t.boxMap&&(t=t.boxMap),Object.keys(t).forEach(i=>{const s=Number(i),r=t[s].value?t[s].value:t[s],n=new d.Box3().setFromArray(r);e&&n.applyMatrix4(e),this.userBoxCache.set(s,n)})}getMaterialParameters(t){return this.materialCache.get(t)}getUserData(t){if(this.userIdAndUserDataCache.size===0)return;const e=this.userIdAndUserDataCache.get(t);if(!e?.userDataIndex)return;let i=this.userDataCache.get(e.userDataIndex);return i||(i={}),i.modelId=e.modelId,i.familyInstanceId=e.familyInstanceId,i}getFamilyInstanceIdsByModelId(t){return this.familyInstanceIdCache.get(t)}getUserIdBox(t){return this.userBoxCache.get(t)}getUserIds(){return Array.from(this.userIdAndUserDataCache.keys())}getUserIdsByFamilyInstanceId(t,e){if(this.familyInstanceAndUserIdsCache.size===0)return[];const i=t+"#"+e;return this.familyInstanceAndUserIdsCache.get(i)||[]}getUserIdByUserDataIndex(t){if(this.userIdAndUserDataCache.size!==0){for(const[e,i]of this.userIdAndUserDataCache)if(i.userDataIndex===t)return e}}getUserIdByFilter(t){const e=[];return this.userDataCache.size===0||this.userDataCache.forEach((i,s)=>{if(t(i)){const r=this.getUserIdByUserDataIndex(s);r!==void 0&&e.push(r)}}),e}dispose(){this.textureLoaderCache.clear(),this.materialCache.clear(),this.textureCache.clear(),this.userDataCache.clear(),this.familyInstanceIdCache.clear(),this.familyInstanceAndUserIdsCache.clear(),this.userIdAndUserDataCache.clear(),this.userBoxCache.clear()}}function In(h){return new TextDecoder().decode(h)}function Lr(h,t){return((h&255)<<24)+(t&16777215)}function Eh(h){return h[3]}function _h(h){return(h[0]<<16)+(h[1]<<8)+h[2]}function kn(h){const t=h.BYTES_PER_ELEMENT,e=(1<<8*t-1)-1,i=2,s=h.length/i,r=new d.Vector2,n=new d.Vector3,a=new Float32Array(s*3);for(let o=0;o<s;o++)r.fromArray(h,o*i),R.OctDecode(r,n,e),n.toArray(a,o*3);return a}class Rr{parse(t,e){const i=[];for(let s=0;s<e.length;s++){const r=e[s],{byteOffset:n,byteLength:a,batchTable:o}=r,l=t.slice(n,n+a);i.push(this.parseMesh(l,r,o))}return i}parseMesh(t,e,i){const s=e.primitive,r=e.buffers,n=this.parseTypedArray(t,r[s.position]),a=s.color?this.parseTypedArray(t,r[s.color]):new Float32Array,o=s.indice?this.parseTypedArray(t,r[s.indice]):new Uint16Array;let l=s.normal?this.parseTypedArray(t,r[s.normal]):new Float32Array;s.normal>=0&&s.normalCompressed&&(l=kn(l));const c=s.tangent?this.parseTypedArray(t,r[s.tangent]):new Float32Array,u=s.uv_0?this.parseTypedArray(t,r[s.uv_0]):new Float32Array,f=s.barycentric?this.parseTypedArray(t,r[s.barycentric]):new Uint8Array,m=new Array(n.length/3);return i.forEach(g=>{m.fill(g.userId,g.positionStart,g.positionStart+g.positionCount)}),{type:s.type,position:n,indice:o,color:a,normal:l,tangent:c,barycentric:f,uv:u,userIds:m,materialId:s.materialId||s.material,batchTable:e.batchTable}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:r,type:n,componentType:a}=e,o=Number(js[n]),l=An[a],c=t.slice(i,i+s);return new l(c,0,r*o)}}const St=class St{constructor(){p(this,"header")}async parse(t,e,i){const s=[];for(let r=0;r<t.length;r++){const{blobId:n,url:a,instances:o}=t[r],l=await this.getInstancedMeshByUrlAndBlobId(e+a,n,i);if(!l){S.warn("[BimTiles] Failed to get InstancedMesh by "+(e+a)+", bloblId '"+n+"'");continue}const c=[],u=[];o.forEach(m=>{c.push(m.userId),u.push(...m.transform)});const f=Object.assign(Object.assign({},l),{userIds:c,matrices:u});s.push(f)}return s}parseInstanceBuffer(t){const e=new vi(t);this.header={magic:e.readUtf8String(4),version:e.readUint32(),byteLength:e.readUint64()};const i=e.readUint32(),s=e.readUint32(),r=e.readUint32(),n=e.readUint64(),a=t.slice(i,i+s),o=In(new Uint8Array(a,0,s)),l=JSON.parse(o),c=t.slice(r,r+n);return this.parseMeshes(c,l.meshes)}parseInstanceProto(t,e){const i=Ds.inflate(t),s=e.lookupType("PBTileContent"),r=s.decode(i);return this.parseMeshes(r.binaries.slice().buffer,r.meshes)}parseMeshes(t,e){const i=[];for(let s=0;s<e.length;s++){const r=e[s],{byteOffset:n=0,byteLength:a}=r,o=t.slice(n,n+a);i.push(this.parseMesh(o,r))}return i}parseMesh(t,e){const i=e.primitive,s=e.buffers,r=this.parseTypedArray(t,s[i.position]),n=i.color?this.parseTypedArray(t,s[i.color]):new Float32Array,a=i.indice?this.parseTypedArray(t,s[i.indice]):new Uint16Array;let o=i.normal?this.parseTypedArray(t,s[i.normal]):new Float32Array;i.normal>=0&&i.normalCompressed&&(o=kn(o));const l=i.tangent?this.parseTypedArray(t,s[i.tangent]):new Float32Array,c=i.uv_0?this.parseTypedArray(t,s[i.uv_0]):new Float32Array,u=i.barycentric?this.parseTypedArray(t,s[i.barycentric]):new Uint8Array,f=[],m=[];return{type:i.type,position:r,indice:a,color:n,normal:o,tangent:l,uv:c,barycentric:u,userIds:f,matrices:m,materialId:i.materialId||i.material}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:r,type:n,componentType:a}=e,o=Number(js[n]),l=An[a],c=t.slice(i,i+s);return new l(c,0,r*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!St.instanceDataMap[t]){const s=await fetch(t).then(n=>n.arrayBuffer()),r=new Uint8Array(s);z.isGzip(r)&&i?St.instanceDataMap[t]=this.parseInstanceProto(r,i):St.instanceDataMap[t]=this.parseInstanceBuffer(s)}return St.instanceDataMap[t][e]}};p(St,"instanceDataMap",{});let Xi=St;class Ph{async parse(t,e,i){const s=new Uint8Array(t);return z.isGzip(s)?this.parseProto(s,e,i):this.parseBinary(t,e)}async parseBinary(t,e){const i=new vi(t),s=i.readUtf8String(4),r=i.readUint32(),n=i.readUint64(),a=i.readUint32(),o=i.readUint32(),l=i.readUint32(),c=i.readUint64(),u=t.slice(a,a+o),f=In(new Uint8Array(u,0,o)),m=JSON.parse(f);S.debug("[BimTiles] Tile, magic("+s+"), version("+r+"), byteLength("+n+"), tileJson:",m);const g=t.slice(l,l+c),x=new Rr().parse(g,m.batchedMeshes),y=await new Xi().parse(m.instancedMeshes,e);return{batchedMeshes:x,instancedMeshes:y}}async parseProto(t,e,i){const s=Ds.inflate(t),r=i.lookupType("PBTileContent").decode(s),n=r.header;S.debug("[BimTiles] Tile, magic("+n.magic+"), version("+n.version+"), byteLength("+s.byteLength+"), tileJson:",r);const a=r.binaries.slice().buffer,o=new Rr().parse(a,r.meshes),l=await new Xi().parse(r.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const Ah=`syntax = "proto3";\r
1366
1366
  \r
1367
1367
  package BimTiles;\r
1368
1368
  \r
@@ -1528,6 +1528,6 @@ message PBTileContent {\r
1528
1528
  repeated PBMesh meshes = 3;\r
1529
1529
  bytes binaries = 4;\r
1530
1530
  }\r
1531
- `,kn=Symbol("INITIAL_FRUSTUM_CULLED");function Ah(h,t){h.traverse(e=>{e.frustumCulled=e[kn]&&t})}const Ei=new d.Vector3,_i=new d.Vector3,ps=new d.Box3;class Dn extends ba.TilesRenderer{constructor(e,i){super(e);p(this,"highlighUsage");p(this,"transparentUsage");p(this,"pickUsage");p(this,"materialManager");p(this,"baseUrl");p(this,"propertyParser");p(this,"tilesetId");p(this,"onBeforeParseTile");p(this,"protoRoot");this.downloadQueue.maxJobs=6,this.parseQueue.maxJobs=4,this.optimizeRaycast=!1,this.errorTarget=8,this.loadSiblings=!1,this.tilesetId=i,this.baseUrl=e.replace(/\/[^\\/]*\/?$/,"/"),this.highlighUsage=new d.Group,this.highlighUsage.name="highlighUsage-"+this.tilesetId,this.group.add(this.highlighUsage),this.transparentUsage=new d.Group,this.transparentUsage.name="transparentUsage-"+this.tilesetId,this.group.add(this.transparentUsage),this.pickUsage=new d.Group,this.protoRoot=qa.parse(Ph).root,this.propertyParser=new Sh(this.baseUrl,this.protoRoot)}getVertexColorArray(e,i=new d.Color(16777215)){const s=[],{r,g:n,b:a}=i;for(let o=0;o<e;o+=3)s.push(r,n,a);return new Float32Array(s)}createBatchedMesh(e){const{position:i,uv:s,normal:r,indice:n,barycentric:a,userIds:o,materialId:l,batchTable:c}=e;let u=e.color;const f=o.map(b=>Lr(this.tilesetId,b)),m=new d.BufferGeometry;m.setAttribute("position",new d.Float32BufferAttribute(i,3)),m.setAttribute("normal",new d.Float32BufferAttribute(r,3)),m.setAttribute("uv",new d.Float32BufferAttribute(s,2)),m.setAttribute("tileObjectId",new d.Int32BufferAttribute(f,1)),m.setIndex(Array.from(n));const g=this.propertyParser.getMaterialParameters(l);u.length===0&&(u=this.getVertexColorArray(i.length,g?.color)),m.setAttribute("color",new d.Float32BufferAttribute(u,3));const x=a.length>0;x&&m.setAttribute("barycentric",new d.BufferAttribute(a,1));const y=this.materialManager?.createBatchMaterial(l,g,x),T=new d.Mesh(m,y),v=new d.Mesh(m,this.materialManager?.pickMaterial);return{mesh:T,pickMesh:v,batchTable:c}}createInstancedMesh(e){const{position:i,uv:s,color:r,normal:n,indice:a,barycentric:o,matrices:l,userIds:c,materialId:u}=e,f=c.map(O=>Lr(this.tilesetId,O)),m=c.length,g=new d.BufferGeometry;g.setIndex(Array.from(a)),g.setAttribute("position",new d.Float32BufferAttribute(i,3)),g.setAttribute("uv",new d.Float32BufferAttribute(s,2)),g.setAttribute("normal",new d.Float32BufferAttribute(n,3)),g.setAttribute("tileObjectId",new d.InstancedBufferAttribute(new Int32Array(f),1));const x=o.length>0;x&&g.setAttribute("barycentric",new d.BufferAttribute(o,1));const y=this.propertyParser.getMaterialParameters(u),T=this.materialManager?.createInstanceMaterial(u,y,x),v=new d.InstancedMesh(g,T,m);v.instanceMatrix=new d.InstancedBufferAttribute(new Float32Array(l),16);let b=r;b.length===0&&(b=this.getVertexColorArray(m*3,y?.color)),v.instanceColor=new d.InstancedBufferAttribute(b,3);const E=new d.InstancedMesh(g,this.materialManager?.pickMaterial,m);return E.instanceMatrix=new d.InstancedBufferAttribute(new Float32Array(l),16),{mesh:v,pickMesh:E,userIds:c}}getGeometryByUserIds(e){const i=Date.now(),s=[];return this.visibleTiles.forEach(r=>{const n=r.cached.scene.children;for(let a=0;a<n.length;a++){const o=n[a];if(!o||o.sourceMesh)continue;const l=o.userData.userIds;if(l)for(let c=0;c<e.length;c++){const u=e[c],f=l.indexOf(u);if(f>-1){const m=new d.BufferGeometry,g=o.geometry.getAttribute("position"),x=o.geometry.index,y=o.geometry.getAttribute("tileObjectId");if(o instanceof d.InstancedMesh){const T=new d.Matrix4;o.getMatrixAt(f,T),m.setAttribute("position",g.clone());const v=y.array[f*y.itemSize];m.setAttribute("tileObjectId",new d.Int32BufferAttribute(new Array(g.array.length/3).fill(v),1)),x&&m.setIndex(x),m.applyMatrix4(T)}else{const{indexStart:T,indexCount:v,positionStart:b,positionCount:E}=o.userData.batchTable.find(P=>P.userId===u),O=g.itemSize,_=g.array.slice(b*O,b*O+E*O),C=new d.Float32BufferAttribute(_,O);m.setAttribute("position",C);const w=y.array.slice(b,b+E),M=new d.Int32BufferAttribute(w,1);if(m.setAttribute("tileObjectId",M),x){const P=x.array.slice(T,T+v);for(let A=0;A<P.length;A++)P[A]-=b;m.setIndex(new d.BufferAttribute(P,1))}}m.applyMatrix4(o.matrixWorld),s.push(m)}}}}),S.info("[BimTiles] getGeometryByUserIds took "+(Date.now()-i)/1e3+"s"),s.length>1?xe.mergeGeometries(s):s[0]}parseTile(e,i,s){this.onBeforeParseTile&&this.onBeforeParseTile(i),i._loadIndex=i._loadIndex||0,i._loadIndex++;const r=i.cached,n=r.transform;return new _h().parse(e,this.baseUrl,this.protoRoot).then(({batchedMeshes:o,instancedMeshes:l})=>{S.debug("[BimTiles] batchedMeshes:",o),S.debug("[BimTiles] instancedMeshes:",l);const c=new d.Group;c.name="TileGroup";const u=new d.Group;u.name="TileGroup-pick",o.forEach(m=>{const{mesh:g,pickMesh:x,batchTable:y}=this.createBatchedMesh(m);c.add(g),g.userData.batchTable=y,g.userData.userIds=y.map(T=>T.userId),u.add(x)}),l.forEach(m=>{const{mesh:g,pickMesh:x,userIds:y}=this.createInstancedMesh(m);c.add(g),g.userData.userIds=y,u.add(x)});const f=m=>{m.applyMatrix4(n)};f(c),c.traverse(m=>{m[kn]=m.frustumCulled}),Ah(c,!this.autoDisableRendererCulling),f(u),r.scene=c,r.pickScene=u,this.onLoadModel&&this.onLoadModel(c,i)})}disposeTile(e){const i=e.cached;if(i.scene){const s=r=>{r.traverse(n=>{n.geometry&&n.geometry.dispose()}),r.removeFromParent()};s(i.scene),i.pickScene&&s(i.pickScene),this.onDisposeModel&&this.onDisposeModel(i.scene,e),i.scene=null,i.pickScene=null,i.materials=null,i.textures=null,i.geometry=null}this.activeTiles.delete(e),this.visibleTiles.delete(e),e._loadIndex++}preprocessNode(e,i,s){super.preprocessNode(e,i,s),Array.isArray(e.boundingVolume)&&(ps.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(ps.getCenter(Ei),ps.getSize(_i),e.cached.boundingVolume.setObbData([Ei.x,Ei.y,Ei.z,_i.x/2,0,0,0,_i.y/2,0,0,0,_i.z/2],e.cached.transform)))}async fetchTileSet(e,i,s){return fetch(e,i).then(r=>{if(r.ok)return r.json();throw new Error('BimTilesRenderer: Failed to load tileset "'+e+'" with status '+r.status+" : "+r.statusText)}).then(async r=>{const{material:n,userData:a,userId:o,userIdBox:l}=r.properties,c=[];if(n.url){const f=this.propertyParser.getProperty(n.url,i,"PBMaterials").then(m=>this.propertyParser.parseMaterial(m));c.push(f)}if(a.url){const f=this.propertyParser.getProperty(a.url,i,"PBUserData").then(m=>this.propertyParser.parseUserData(m));c.push(f)}if(o.url){const f=this.propertyParser.getProperty(o.url,i,"PBUserId").then(m=>this.propertyParser.parseUserId(m));c.push(f)}if(l.url){const f=this.propertyParser.getProperty(l.url,i,"PBUserIdBox").then(m=>this.propertyParser.parseUserIdBox(m,this.group.matrix));c.push(f)}await Promise.all(c);let u=e.replace(/\/[^\\/]*\/?$/,"");return u=new URL(u,window.location.href).toString(),this.preprocessNode(r.root,u,s),this.onLoadTileSet&&Promise.resolve().then(()=>{this.onLoadTileSet(r)}),r})}loadRootTileSet(e){const i=this.tileSets;if(e in i)return i[e]instanceof Error?Promise.reject(i[e]):Promise.resolve(i[e]);{const s=this.fetchTileSet(this.preprocessURL?this.preprocessURL(e):e,this.fetchOptions).then(r=>{i[e]=r,this.materialManager=new Mh(this,{maxId:r.properties.userId.maxUserIdIndex})});return s.catch(r=>{S.error("[BimTiles] loadRootTileSet error:",r),i[e]=r}),i[e]=s,s}}update(){super.update()}setTileVisible(e,i){const{scene:s,pickScene:r}=e.cached,n=this.visibleTiles,a=this.group;i?(n.add(e),a.add(s),this.pickUsage.add(r),s.updateMatrixWorld(!0),r.updateMatrixWorld(!0)):(n.delete(e),a.remove(s),this.pickUsage.remove(r)),this.onTileVisibilityChange&&this.onTileVisibilityChange(s,e,i)}calculateError(e){const i=e.cached,s=i.inFrustum,r=this.cameras,n=this.cameraInfo,a=i.boundingVolume;let o=-1/0,l=1/0;for(let c=0,u=r.length;c<u;c++){if(!s[c])continue;const f=n[c],m=f.invScale;let g;if(f.isOrthographic){const x=f.pixelSize;g=e.geometricError/(x*m)}else{const x=a.distanceToPoint(f.position),y=x*m,T=f.sseDenominator;g=e.geometricError/(y*T),l=Math.min(l,y)}o=Math.max(o,g)}e.__distanceFromCamera=l,e.__error=o}}class Vs extends Ji{constructor(e,i,s){super();p(this,"modelId");p(this,"_bbox");p(this,"tilesRenderer");p(this,"metadata");p(this,"statistics");this.modelId=e.modelId;const r=i+s.getMetadata().root;this.tilesRenderer=new Dn(r,Number(this.modelId)),this._bbox=e.bbox,this.metadata=s.getMetadata(),this.statistics=s.getStatistics()}getTilesRenderer(){return this.tilesRenderer}get materialManager(){return this.tilesRenderer.materialManager}get propertyParser(){return this.tilesRenderer.propertyParser}get highlighUsageGroup(){return this.tilesRenderer.highlighUsage}get transparentUsageGroup(){return this.tilesRenderer.transparentUsage}get pickUsageGroup(){return this.tilesRenderer.pickUsage}getModelObject(){return this.tilesRenderer.group}traverseObjectByUserId(e,i){if(i.userData.userIds){const r=i.userData.userIds;for(let n=0,a=r.length;n<a;n++)if(r[n]===e)return i}const s=i.children;for(let r=0,n=s.length;r<n;r++)if(this.traverseObjectByUserId(e,s[r]))return s[r]}getObjectByUserId(e){let i;return this.tilesRenderer.visibleTiles.forEach(s=>{i=this.traverseObjectByUserId(e,s.cached.scene)}),i}getBBox(){return this._bbox||(this._bbox=new d.Box3,this._bbox.setFromObject(this.getModelObject())),this._bbox}setObjectHoveredByUserId(e,i){this.materialManager.updateState(Mt.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(Mt.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(Mt.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(Mt.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(Mt.Transparent,e,!1)}setOpacity(e){this.materialManager.setOpacity(e)}clearOpacity(){this.materialManager.setOpacity(1)}setVisible(e){this.materialManager.setHidden(!e)}setObjectVisibleByUserIds(e,i){this.materialManager.updateState(Mt.Hidden,e,!i)}hasVisibleObject(){return this.materialManager.hasVisibleObject()}hasInvisibleObject(){return this.materialManager.hasInvisibleObject()}getHoveredObject(){return this.materialManager?.getHoveredObject()}getBBoxByUserId(e){return this.propertyParser.getUserIdBox(e)}getUserDataByUserId(e){return this.propertyParser.getUserData(e)}getUserIds(){return this.propertyParser.getUserIds()}getUserId(e,i){return this.propertyParser.getUserIdsByFamilyInstanceId(e,i)}getUserData(e,i){const s=this.getUserId(e,i);if(s.length>0)return this.getUserDataByUserId(s[0])}getUserIdByFilter(e){return this.propertyParser.getUserIdByFilter(e)}setClipPlanes(e){this.materialManager.setClipPlanes(e)}}function Ih(){let h=new Map;return{on(t,e){const i=h.get(t);i?i.push(e):h.set(t,[e])},off(t,e){const i=h.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):h.set(t,[]))},emit(t,e){const i=h.get(t);i&&i.slice().map(s=>s(e)),h.get("*")&&h.get("*").slice().map(s=>s(t,e))}}}class kh{constructor(t){p(this,"viewer");p(this,"element");p(this,"content");p(this,"itemList");p(this,"handleMouseWheel");this.viewer=t,this.itemList={},this.handleMouseWheel=e=>{e.preventDefault(),this.element&&(this.element.scrollLeft+=e.deltaY)},t.addEventListener(re.ModelLoad,()=>{this.init()})}init(){const t=document.createElement("div");t.classList.add("model-layout-switch-bar");const e=document.createElement("div");e.classList.add("model-layout-switch-bar-content"),e.addEventListener("wheel",this.handleMouseWheel),this.viewer.getLayoutNames().forEach((i,s)=>{const r=this.createItem(i,s);this.itemList[i]=r,r.resetActivate=()=>{for(const n in this.itemList)this.itemList[n].resetActive()},e?.appendChild(r.element)}),this.element=t,this.content=e,this.element.appendChild(this.content),this.viewer.widgetContainer?.appendChild(this.element)}createItem(t,e){const i=new Dh(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 Dh{constructor(t,e){p(this,"viewer");p(this,"eventBus");p(this,"element");p(this,"resetActivate");p(this,"active");this.viewer=t,this.eventBus=Ih(),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 Bn{constructor(t){p(this,"element");p(this,"jobCount");this.jobCount=0;const e=document.createElement("div");e.classList.add("x-spinner");for(let s=0;s<4;s++)e.appendChild(document.createElement("span"));const i=t?.widgetContainer;i&&i.appendChild(e),this.element=e,this.setSpinnerVisibility(this.jobCount>0)}setSpinnerVisibility(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){if(this.jobCount<=0){console.warn("[Viewer] jobCount should be at least 1 here!");return}this.setSpinnerVisibility(--this.jobCount>0)}destroy(){this.element.remove(),this.jobCount=0}}class Us{constructor(t){p(this,"width");p(this,"height");p(this,"container");p(this,"viewerContainer");p(this,"widgetContainer");this.width=0,this.height=0;let e=document.getElementById(t);e||(S.warn("[Container] containerId:",t,"is not found in dom tree! will append to document body"),e=document.body);const i=document.createElement("div");i.classList.add("x-container"),i.style.cssText="width: 100%; height: 100%; position: relative;",e.appendChild(i),this.container=i,this.width=e.clientWidth,this.height=e.clientHeight,this.initViewerContainer(),this.initWidgetContainer()}initViewerContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-viewer-container"),e.style.cssText="width: 100%; height: 100%; display: inline-block; position: relative; overflow: hidden;",t.appendChild(e),this.viewerContainer=e}initWidgetContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-widget-container"),t.appendChild(e),this.widgetContainer=e}get needResize(){const t=this.width!==this.container.clientWidth||this.height!==this.container.clientHeight;return t&&(this.width=this.container.clientWidth,this.height=this.container.clientHeight),t}destroy(){this.widgetContainer&&(this.widgetContainer.remove(),this.widgetContainer=void 0),this.viewerContainer&&(this.viewerContainer.remove(),this.viewerContainer=void 0),this.container.remove()}}class Ns{constructor(t){p(this,"element");p(this,"progressItems");p(this,"replaceReg");this.progressItems=new Map,this.replaceReg=new RegExp(/<em>[\s\S]*<\/em>/,"g");const e=document.createElement("div");e.classList.add("progress-bar"),t?.widgetContainer?.appendChild(e),this.element=e}addProgressItem(t,e="ProgressBar.Loading",i){this.progressItems.get(t)&&S.error("[Viewer] ProgressItem with id "+t+" already exists!");const s=document.createElement("div");s.classList.add("progress-bar-item"),s.innerHTML=Re.t(e)+": <em></em>",this.element.append(s),this.progressItems.set(t,{div:s,onProgress:i})}removeProgressItem(t){this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t),this.progressItems.size===0&&this.setVisible(!1)}updateProgress(t,e,i){const s=this.progressItems.get(t);if(!s)return;let r=e?""+e:"";e&&i!=null&&(r+=": "),i!=null&&(i<0||i>100?(console.warn("[ProgressBar] Invalid progress value: "+i),r+="--%"):r+=i.toFixed(2)+"%"),s.div.innerHTML=r}updateProgressBar(t,e,i=0,s=100){const r=this.progressItems.get(t);if(!r)return;const n=e instanceof ProgressEvent?e.loaded:e,a=e instanceof ProgressEvent?e.total:100,o=n*100/a*(s-i)/100+i;r.div.innerHTML=r.div.innerHTML.replace(this.replaceReg,"<em>"+(o<0||o>100?"--":o.toFixed(2))+"%</em>"),r.onProgress?.call(r,new ProgressEvent("LoadProgress",{loaded:n,total:100}))}setVisible(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}delayRemoveProgressItem(t,e=3e3){setTimeout(()=>{this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t)},e)}destroy(){this.progressItems.forEach(t=>{t.div.remove()}),this.progressItems.clear(),this.element.remove()}}var Be=(h=>(h.BaseViewer="BaseViewer",h.Viewer3d="Viewer3d",h.Viewer2d="Viewer2d",h.BimTilesViewer="BimTilesViewer",h))(Be||{}),$e=(h=>(h.Perspective="Perspective",h.Orthographic="Orthographic",h))($e||{});const Bh={enableSpinner:!0,containerId:"myCanvas"},G={LEFT:1,RIGHT:2,MIDDLE:4},D=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768});function Ve(h){return h.isPerspectiveCamera}function Oe(h){return h.isOrthographicCamera}class Lh{constructor(){p(this,"_listeners");this._listeners={}}addEventListener(t,e){const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners[t];if(s!==void 0){const r=s.indexOf(e);r!==-1&&s.splice(r,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const i=this._listeners[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let r=0,n=s.length;r<n;r++)s[r].call(this,t)}}}const At=Math.PI*2,Fr=Math.PI/2;function ms(h,t){t.set(0,0),h.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=h.length,t.y/=h.length}function gs(h,t){return Oe(h)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const Ln=1e-5,Qt=Math.PI/180;function Rt(h,t,e){return Math.max(t,Math.min(e,h))}function ie(h,t=Ln){return Math.abs(h)<t}function te(h,t,e=Ln){return ie(h-t,e)}function zr(h,t){return Math.round(h/t)*t}function ei(h){return isFinite(h)?h:h<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ti(h){return Math.abs(h)<Number.MAX_VALUE?h:h*(1/0)}function Pi(h,t,e,i,s=1/0,r){i=Math.max(1e-4,i);const n=2/i,a=n*r,o=1/(1+a+.48*a*a+.235*a*a*a);let l=h-t;const c=t,u=s*i;l=Rt(l,-u,u),t=h-l;const f=(e.value+n*l)*r;e.value=(e.value-n*f)*o;let m=t+(l+f)*o;return c-h>0==m>c&&(m=c,e.value=(m-c)/r),m}function jr(h,t,e,i,s=1/0,r,n){i=Math.max(1e-4,i);const a=2/i,o=a*r,l=1/(1+o+.48*o*o+.235*o*o*o);let c=t.x,u=t.y,f=t.z,m=h.x-c,g=h.y-u,x=h.z-f;const y=c,T=u,v=f,b=s*i,E=b*b,O=m*m+g*g+x*x;if(O>E){const L=Math.sqrt(O);m=m/L*b,g=g/L*b,x=x/L*b}c=h.x-m,u=h.y-g,f=h.z-x;const _=(e.x+a*m)*r,C=(e.y+a*g)*r,w=(e.z+a*x)*r;e.x=(e.x-a*_)*l,e.y=(e.y-a*C)*l,e.z=(e.z-a*w)*l,n.x=c+(m+_)*l,n.y=u+(g+C)*l,n.z=f+(x+w)*l;const M=y-h.x,P=T-h.y,A=v-h.z,I=n.x-y,k=n.y-T,B=n.z-v;return M*I+P*k+A*B>0&&(n.x=y,n.y=T,n.z=v,e.x=(n.x-y)/r,e.y=(n.y-T)/r,e.z=(n.z-v)/r),n}const Ai=1/8,Rh=be.isBrowser&&/Mac/.test(navigator.platform),Fh=!(be.isBrowser&&"PointerEvent"in window);let H,Vr,Ii,ys,Me,W,ee,It,Ye,Xe,bt,Ur,Nr,je,ii,kt,Hr,xs,Gr,bs,vs,ki;class K extends Lh{constructor(e,i){super();p(this,"minPolarAngle");p(this,"maxPolarAngle");p(this,"minAzimuthAngle");p(this,"maxAzimuthAngle");p(this,"minDistance");p(this,"maxDistance");p(this,"infinityDolly");p(this,"minZoom");p(this,"maxZoom");p(this,"smoothTime");p(this,"draggingSmoothTime");p(this,"maxSpeed");p(this,"azimuthRotateSpeed");p(this,"polarRotateSpeed");p(this,"dollySpeed");p(this,"truckSpeed");p(this,"dollyToCursor");p(this,"dragToOffset");p(this,"verticalDragToForward");p(this,"boundaryFriction");p(this,"restThreshold");p(this,"colliderMeshes");p(this,"mouseButtons");p(this,"touches");p(this,"cancel");p(this,"_enabled");p(this,"_camera");p(this,"_yAxisUpSpace");p(this,"_yAxisUpSpaceInverse");p(this,"_state");p(this,"_domElement");p(this,"_viewport");p(this,"_target");p(this,"_targetEnd");p(this,"_focalOffset");p(this,"_focalOffsetEnd");p(this,"_spherical");p(this,"_sphericalEnd");p(this,"_zoom");p(this,"_zoomEnd");p(this,"_target0");p(this,"_position0");p(this,"_zoom0");p(this,"_focalOffset0");p(this,"_dollyControlAmount");p(this,"_dollyControlCoord");p(this,"_nearPlaneCorners");p(this,"_hasRested");p(this,"_boundary");p(this,"_boundaryEnclosesCamera");p(this,"_needsUpdate");p(this,"_updatedLastTime");p(this,"_elementRect");p(this,"_activePointers");p(this,"_isUserControllingRotate");p(this,"_isUserControllingDolly");p(this,"_isUserControllingTruck");p(this,"_isUserControllingOffset");p(this,"_isUserControllingZoom");p(this,"_thetaVelocity");p(this,"_phiVelocity");p(this,"_radiusVelocity");p(this,"_targetVelocity");p(this,"_focalOffsetVelocity");p(this,"_zoomVelocity");p(this,"_truckInternal");p(this,"_rotateInternal");p(this,"_dollyInternal");p(this,"_zoomInternal");this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=0,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=D.NONE,this._viewport=null,this._dollyControlAmount=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=be.isBrowser?new DOMRect:{x:0,y:0,width:0,height:0,left:0,right:0,top:0,bottom:0},this._activePointers=[],this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new H.Vector3,this._focalOffsetVelocity=new H.Vector3,this._zoomVelocity={value:0},this._truckInternal=(b,E,O)=>{if(Ve(this._camera)){const _=W.copy(this._camera.position).sub(this._target),C=this._camera.getEffectiveFOV()*Qt,w=_.length()*Math.tan(C*.5),M=this.truckSpeed*b*w/this._elementRect.height,P=this.truckSpeed*E*w/this._elementRect.height;this.verticalDragToForward?(O?this.setFocalOffset(this._focalOffsetEnd.x+M,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(M,0,!0),this.forward(-P,!0)):O?this.setFocalOffset(this._focalOffsetEnd.x+M,this._focalOffsetEnd.y+P,this._focalOffsetEnd.z,!0):this.truck(M,P,!0)}else if(Oe(this._camera)){const _=this._camera,C=this.truckSpeed*b*(_.right-_.left)/_.zoom/this._elementRect.width,w=this.truckSpeed*E*(_.top-_.bottom)/_.zoom/this._elementRect.height;O?this.setFocalOffset(this._focalOffsetEnd.x+C,this._focalOffsetEnd.y+w,this._focalOffsetEnd.z,!0):this.truck(C,w,!0)}},this._rotateInternal=(b,E)=>{const O=At*this.azimuthRotateSpeed*b/this._elementRect.height,_=At*this.polarRotateSpeed*E/this._elementRect.height;this.rotate(O,_,!0)},this._dollyInternal=(b,E,O)=>{const _=Math.pow(.95,-b*this.dollySpeed),C=this._sphericalEnd.radius*_,w=this._sphericalEnd.radius,M=w*(b>=0?-1:1);this.dollyTo(C),this.infinityDolly&&(C<this.minDistance||this.maxDistance===this.minDistance)&&(this._camera.getWorldDirection(W),this._targetEnd.add(W.normalize().multiplyScalar(M)),this._target.add(W.normalize().multiplyScalar(M))),this.dollyToCursor&&(this._dollyControlAmount+=this._sphericalEnd.radius-w,this.infinityDolly&&(C<this.minDistance||this.maxDistance===this.minDistance)&&(this._dollyControlAmount-=M),this._dollyControlCoord.set(E,O))},this._zoomInternal=(b,E,O)=>{const _=Math.pow(.95,b*this.dollySpeed),C=this._zoomEnd;this.zoomTo(this._zoom*_),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-C,this._dollyControlCoord.set(E,O))},typeof H>"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 H.Quaternion().setFromUnitVectors(this._camera.up,Ii),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=D.NONE,this._target=new H.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new H.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new H.Spherical().setFromVector3(W.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._nearPlaneCorners=[new H.Vector3,new H.Vector3,new H.Vector3,new H.Vector3],this._updateNearPlaneCorners(),this._boundary=new H.Box3(new H.Vector3(-1/0,-1/0,-1/0),new H.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 H.Vector2,this.mouseButtons={left:D.ROTATE,middle:D.DOLLY,right:D.TRUCK,wheel:Ve(this._camera)?D.DOLLY:Oe(this._camera)?D.ZOOM:D.NONE},this.touches={one:D.TOUCH_ROTATE,two:Ve(this._camera)?D.TOUCH_DOLLY_TRUCK:Oe(this._camera)?D.TOUCH_ZOOM_TRUCK:D.NONE,three:D.TOUCH_TRUCK};const s=new H.Vector2,r=new H.Vector2,n=new H.Vector2,a=b=>{if(!this._enabled||!this._domElement)return;const E=b.pointerType!=="mouse"?null:(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.MIDDLE?G.MIDDLE:(b.buttons&G.RIGHT)===G.RIGHT?G.RIGHT:null;if(E!==null){const _=this._findPointerByMouseButton(E);_&&this._activePointers.splice(this._activePointers.indexOf(_),1)}const O={pointerId:b.pointerId,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:E};this._activePointers.push(O),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",u),this._domElement.addEventListener("pointermove",l),this._domElement.addEventListener("pointerup",u),y(b)},o=b=>{if(!this._enabled||!this._domElement)return;const E=(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.MIDDLE?G.MIDDLE:(b.buttons&G.RIGHT)===G.RIGHT?G.RIGHT:null;if(E!==null){const _=this._findPointerByMouseButton(E);_&&this._activePointers.splice(this._activePointers.indexOf(_),1)}const O={pointerId:0,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.LEFT?G.MIDDLE:(b.buttons&G.RIGHT)===G.LEFT?G.RIGHT:null};this._activePointers.push(O),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("mouseup",f),this._domElement.addEventListener("mousemove",c),this._domElement.addEventListener("mouseup",f),y(b)},l=b=>{const E=b.pointerId,O=this._findPointerById(E);if(O){if(O.clientX=b.clientX,O.clientY=b.clientY,O.deltaX=b.movementX,O.deltaY=b.movementY,b.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right);T()}},c=b=>{const E=this._findPointerById(0);E&&(E.clientX=b.clientX,E.clientY=b.clientY,E.deltaX=b.movementX,E.deltaY=b.movementY,this._state=0,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right),T())},u=b=>{const E=b.pointerId,O=this._findPointerById(E);if(O&&this._activePointers.splice(this._activePointers.indexOf(O),1),b.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=D.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=D.NONE;v()},f=()=>{const b=this._findPointerById(0);b&&this._activePointers.splice(this._activePointers.indexOf(b),1),this._state=D.NONE,v()};let m=-1;const g=b=>{if(!this._enabled||this.mouseButtons.wheel===D.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===D.ROTATE||this.mouseButtons.wheel===D.TRUCK){const w=performance.now();m-w<1e3&&this._getClientRect(this._elementRect),m=w}const E=Rh?-1:-3,O=b.deltaMode===1?b.deltaY/E:b.deltaY/(E*10),_=this.dollyToCursor?(b.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,C=this.dollyToCursor?(b.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case D.ROTATE:{this._rotateInternal(b.deltaX,b.deltaY),this._isUserControllingRotate=!0;break}case D.TRUCK:{this._truckInternal(b.deltaX,b.deltaY,!1),this._isUserControllingTruck=!0;break}case D.OFFSET:{this._truckInternal(b.deltaX,b.deltaY,!0),this._isUserControllingOffset=!0;break}case D.DOLLY:{this._dollyInternal(-O,_,C),this._isUserControllingDolly=!0;break}case D.ZOOM:{this._zoomInternal(-O,_,C),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},x=b=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===K.ACTION.NONE){const E=b instanceof PointerEvent?b.pointerId:(b instanceof MouseEvent,0),O=this._findPointerById(E);O&&this._activePointers.splice(this._activePointers.indexOf(O),1),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("mouseup",f);return}},y=b=>{if(!this._enabled)return;if(ms(this._activePointers,Me),this._getClientRect(this._elementRect),s.copy(Me),r.copy(Me),this._activePointers.length>=2){const O=Me.x-this._activePointers[1].clientX,_=Me.y-this._activePointers[1].clientY,C=Math.sqrt(O*O+_*_);n.set(0,C);const w=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,M=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;r.set(w,M)}if("pointerType"in b&&b.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&D.ROTATE)===D.ROTATE||(this._state&D.TOUCH_ROTATE)===D.TOUCH_ROTATE||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&D.TRUCK)===D.TRUCK||(this._state&D.TOUCH_TRUCK)===D.TOUCH_TRUCK||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&D.DOLLY)===D.DOLLY||(this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&D.ZOOM)===D.ZOOM||(this._state&D.TOUCH_ZOOM)===D.TOUCH_ZOOM||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&D.OFFSET)===D.OFFSET||(this._state&D.TOUCH_OFFSET)===D.TOUCH_OFFSET||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},T=()=>{if(!this._enabled)return;ms(this._activePointers,Me);const b=be.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,E=b?-this._activePointers[0].deltaX:r.x-Me.x,O=b?-this._activePointers[0].deltaY:r.y-Me.y;if(r.copy(Me),((this._state&D.ROTATE)===D.ROTATE||(this._state&D.TOUCH_ROTATE)===D.TOUCH_ROTATE||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(E,O),this._isUserControllingRotate=!0),(this._state&D.DOLLY)===D.DOLLY||(this._state&D.ZOOM)===D.ZOOM){const _=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,C=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&D.DOLLY)===D.DOLLY?(this._dollyInternal(O*Ai,_,C),this._isUserControllingDolly=!0):(this._zoomInternal(O*Ai,_,C),this._isUserControllingZoom=!0)}if((this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_ZOOM)===D.TOUCH_ZOOM||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE){const _=Me.x-this._activePointers[1].clientX,C=Me.y-this._activePointers[1].clientY,w=Math.sqrt(_*_+C*C),M=n.y-w;n.set(0,w);const P=this.dollyToCursor?(r.x-this._elementRect.x)/this._elementRect.width*2-1:0,A=this.dollyToCursor?(r.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET?(this._dollyInternal(M*Ai,P,A),this._isUserControllingDolly=!0):(this._zoomInternal(M*Ai,P,A),this._isUserControllingZoom=!0)}((this._state&D.TRUCK)===D.TRUCK||(this._state&D.TOUCH_TRUCK)===D.TOUCH_TRUCK||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(E,O,!1),this._isUserControllingTruck=!0),((this._state&D.OFFSET)===D.OFFSET||(this._state&D.TOUCH_OFFSET)===D.TOUCH_OFFSET||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(E,O,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},v=()=>{ms(this._activePointers,Me),r.copy(Me),this._activePointers.length===0&&this._domElement&&(this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mouseup",f),this.dispatchEvent({type:"controlend"}))};this._addAllEventListeners=b=>{this._domElement=b,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),Fh&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",u),this._domElement.addEventListener("wheel",g,{passive:!1}),this._domElement.addEventListener("contextmenu",x)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",a),this._domElement.removeEventListener("mousedown",o),this._domElement.removeEventListener("pointercancel",u),this._domElement.removeEventListener("wheel",g),this._domElement.removeEventListener("contextmenu",x),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mouseup",f))},this.cancel=()=>{this._state!==D.NONE&&(this._state=D.NONE,this._activePointers.length=0,v())},i&&this.connect(i),this.update(0)}static install(e){H=e.THREE,Vr=Object.freeze(new H.Vector3(0,0,0)),Ii=Object.freeze(new H.Vector3(0,1,0)),ys=Object.freeze(new H.Vector3(0,0,1)),Me=new H.Vector2,W=new H.Vector3,ee=new H.Vector3,It=new H.Vector3,Ye=new H.Vector3,Xe=new H.Vector3,bt=new H.Vector3,Ur=new H.Vector3,Nr=new H.Vector3,je=new H.Spherical,ii=new H.Spherical,kt=new H.Box3,Hr=new H.Box3,xs=new H.Sphere,Gr=new H.Quaternion,bs=new H.Quaternion,vs=new H.Matrix4,ki=new H.Raycaster}static get ACTION(){return D}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}addEventListener(e,i){super.addEventListener(e,i)}removeEventListener(e,i){super.removeEventListener(e,i)}rotate(e,i,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+i,s)}rotateAzimuthTo(e,i=!1){return this.rotateTo(e,this._sphericalEnd.phi,i)}rotatePolarTo(e,i=!1){return this.rotateTo(this._sphericalEnd.theta,e,i)}rotateTo(e,i,s=!1){this._isUserControllingRotate=!1;const r=Rt(e,this.minAzimuthAngle,this.maxAzimuthAngle),n=Rt(i,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=r,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,i=!1){return this.dollyTo(this._sphericalEnd.radius-e,i)}dollyTo(e,i=!1){this._isUserControllingDolly=!1;const s=this._sphericalEnd.radius,r=Rt(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=te(o,this._spherical.radius);if(!(s>r)&&l)return Promise.resolve();this._sphericalEnd.radius=Math.min(r,o)}else this._sphericalEnd.radius=r;this._needsUpdate=!0,i||(this._spherical.radius=this._sphericalEnd.radius);const a=!i||te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(a)}zoom(e,i=!1){return this.zoomTo(this._zoomEnd+e,i)}zoomTo(e,i=!1){this._isUserControllingZoom=!1,this._zoomEnd=Rt(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||te(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),Ye.setFromMatrixColumn(this._camera.matrix,0),Xe.setFromMatrixColumn(this._camera.matrix,1),Ye.multiplyScalar(e),Xe.multiplyScalar(-i);const r=W.copy(Ye).add(Xe),n=ee.copy(this._targetEnd).add(r);return this.moveTo(n.x,n.y,n.z,s)}forward(e,i=!1){W.setFromMatrixColumn(this._camera.matrix,0),W.crossVectors(this._camera.up,W),W.multiplyScalar(e);const s=ee.copy(this._targetEnd).add(W);return this.moveTo(s.x,s.y,s.z,i)}elevate(e,i=!1){return W.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+W.x,this._targetEnd.y+W.y,this._targetEnd.z+W.z,i)}moveTo(e,i,s,r=!1){this._isUserControllingTruck=!1;const n=W.set(e,i,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,r||this._target.copy(this._targetEnd);const a=!r||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,i,s,r=!1){const o=W.set(e,i,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,r)}fitToBox(e,i,{cover:s=!1,paddingLeft:r=0,paddingRight:n=0,paddingBottom:a=0,paddingTop:o=0}={}){const l=[],c=e.isBox3?kt.copy(e):kt.setFromObject(e);c.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const u=zr(this._sphericalEnd.theta,Fr),f=zr(this._sphericalEnd.phi,Fr);l.push(this.rotateTo(u,f,i));const m=W.setFromSpherical(this._sphericalEnd).normalize(),g=Gr.setFromUnitVectors(m,ys),x=te(Math.abs(m.y),1);x&&g.multiply(bs.setFromAxisAngle(Ii,u)),g.multiply(this._yAxisUpSpaceInverse);const y=Hr.makeEmpty();ee.copy(c.min).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setX(c.max.x).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setY(c.max.y).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setZ(c.min.z).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setZ(c.max.z).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setY(c.min.y).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setX(c.min.x).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).applyQuaternion(g),y.expandByPoint(ee),y.min.x-=r,y.min.y-=a,y.max.x+=n,y.max.y+=o,g.setFromUnitVectors(ys,m),x&&g.premultiply(bs.invert()),g.premultiply(this._yAxisUpSpace);const T=y.getSize(W),v=y.getCenter(ee).applyQuaternion(g);if(Ve(this._camera)){const b=this.getDistanceToFitBox(T.x,T.y,T.z,s);l.push(this.moveTo(v.x,v.y,v.z,i)),l.push(this.dollyTo(b,i)),l.push(this.setFocalOffset(0,0,0,i))}else if(Oe(this._camera)){const b=this._camera,E=b.right-b.left,O=b.top-b.bottom,_=s?Math.max(E/T.x,O/T.y):Math.min(E/T.x,O/T.y);l.push(this.moveTo(v.x,v.y,v.z,i)),l.push(this.zoomTo(_,i)),l.push(this.setFocalOffset(0,0,0,i))}return Promise.all(l)}fitToSphere(e,i){const s=[],n=e instanceof H.Sphere?xs.copy(e):K.createBoundingSphere(e,xs);if(s.push(this.moveTo(n.center.x,n.center.y,n.center.z,i)),Ve(this._camera)){const a=this.getDistanceToFitSphere(n.radius);s.push(this.dollyTo(a,i))}else if(Oe(this._camera)){const a=this._camera,o=a.right-a.left,l=a.top-a.bottom,c=2*n.radius,u=Math.min(o/c,l/c);s.push(this.zoomTo(u,i))}return s.push(this.setFocalOffset(0,0,0,i)),Promise.all(s)}setLookAt(e,i,s,r,n,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const l=ee.set(r,n,a),c=W.set(e,i,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(c.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const u=!o||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold)&&te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(u)}lerpLookAt(e,i,s,r,n,a,o,l,c,u,f,m,g,x=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const y=W.set(r,n,a),T=ee.set(e,i,s);je.setFromVector3(T.sub(y).applyQuaternion(this._yAxisUpSpace));const v=It.set(u,f,m),b=ee.set(o,l,c);ii.setFromVector3(b.sub(v).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(y.lerp(v,g));const E=ii.theta-je.theta,O=ii.phi-je.phi,_=ii.radius-je.radius;this._sphericalEnd.set(je.radius+_*g,je.phi+O*g,je.theta+E*g),this.normalizeRotations(),this._needsUpdate=!0,x||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const C=!x||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold)&&te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(C)}setPosition(e,i,s,r=!1){return this.setLookAt(e,i,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,r)}setTarget(e,i,s,r=!1){const n=this.getPosition(W),a=this.setLookAt(n.x,n.y,n.z,e,i,s,r);return this._sphericalEnd.phi=Rt(this.polarAngle,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,i,s,r=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,i,s),this._needsUpdate=!0,r||this._focalOffset.copy(this._focalOffsetEnd);const n=!r||te(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&te(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&te(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),Ye.setFromMatrixColumn(this._camera.matrixWorldInverse,0),Xe.setFromMatrixColumn(this._camera.matrixWorldInverse,1),bt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const r=W.set(e,i,s),n=r.distanceTo(this._camera.position),a=r.sub(this._camera.position);Ye.multiplyScalar(a.x),Xe.multiplyScalar(a.y),bt.multiplyScalar(a.z),W.copy(Ye).add(Xe).add(bt),W.z=W.z+n,this.dollyTo(n,!1),this.setFocalOffset(-W.x,W.y,-W.z,!1),this.moveTo(e,i,s,!1)}setBoundary(e){if(!e){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,i,s,r){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new H.Vector4,typeof e=="number"?this._viewport.set(e,i,s,r):this._viewport.copy(e)}getDistanceToFitBox(e,i,s,r=!1){if(gs(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=e/i,a=this._camera.getEffectiveFOV()*Qt,o=this._camera.aspect;return((r?n>o:n<o)?i:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if(gs(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const i=this._camera.getEffectiveFOV()*Qt,s=Math.atan(Math.tan(i*.5)*this._camera.aspect)*2,r=1<this._camera.aspect?i:s;return e/Math.sin(r*.5)}getTarget(e){return(e&&e.isVector3?e:new H.Vector3).copy(this._targetEnd)}getPosition(e){return(e&&e.isVector3?e:new H.Vector3).setFromSpherical(this._sphericalEnd).applyQuaternion(this._yAxisUpSpaceInverse).add(this._targetEnd)}getFocalOffset(e){return(e&&e.isVector3?e:new H.Vector3).copy(this._focalOffsetEnd)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%At,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=At),this._spherical.theta+=At*Math.round((this._sphericalEnd.theta-this._spherical.theta)/At)}reset(e=!1){const i=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,e),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,e),this.zoomTo(this._zoom0,e)];return Promise.all(i)}saveState(){this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Ii),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert}update(e){const i=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,r=this._sphericalEnd.radius-this._spherical.radius,n=Ur.subVectors(this._targetEnd,this._target),a=Nr.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ie(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const f=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Pi(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,f,1/0,e),this._needsUpdate=!0}if(ie(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const f=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Pi(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,f,1/0,e),this._needsUpdate=!0}if(ie(r))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const f=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Pi(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,f,this.maxSpeed,e),this._needsUpdate=!0}if(ie(n.x)&&ie(n.y)&&ie(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const f=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;jr(this._target,this._targetEnd,this._targetVelocity,f,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(ie(a.x)&&ie(a.y)&&ie(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const f=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;jr(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,f,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(Ve(this._camera)){const f=this._camera,m=W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),g=ee.copy(m).cross(f.up).normalize();g.lengthSq()===0&&(g.x=1);const x=It.crossVectors(g,m),y=this._sphericalEnd.radius*Math.tan(f.getEffectiveFOV()*Qt*.5),v=(this._sphericalEnd.radius-this._dollyControlAmount-this._sphericalEnd.radius)/this._sphericalEnd.radius,b=W.copy(this._targetEnd).add(g.multiplyScalar(this._dollyControlCoord.x*y*f.aspect)).add(x.multiplyScalar(this._dollyControlCoord.y*y));this._targetEnd.lerp(b,v)}else if(Oe(this._camera)){const f=this._camera,m=W.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(f.near+f.far)/(f.near-f.far)).unproject(f),g=ee.set(0,0,-1).applyQuaternion(f.quaternion),x=It.copy(m).add(g.multiplyScalar(-m.dot(f.up))),T=-(this._zoom-this._dollyControlAmount-this._zoomEnd)/this._zoom,v=W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),b=this._targetEnd.dot(v);this._targetEnd.lerp(x,T);const E=this._targetEnd.dot(v),O=v.multiplyScalar(E-b);this._targetEnd.sub(O)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(ie(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const f=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Pi(this._zoom,this._zoomEnd,this._zoomVelocity,f,1/0,e)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0);const l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!ie(this._focalOffset.x)||!ie(this._focalOffset.y)||!ie(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),Ye.setFromMatrixColumn(this._camera.matrix,0),Xe.setFromMatrixColumn(this._camera.matrix,1),bt.setFromMatrixColumn(this._camera.matrix,2),Ye.multiplyScalar(this._focalOffset.x),Xe.multiplyScalar(-this._focalOffset.y),bt.multiplyScalar(this._focalOffset.z),W.copy(Ye).add(Xe).add(bt),this._camera.position.add(W)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const u=this._needsUpdate;return u&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):u?(this.dispatchEvent({type:"update"}),ie(i,this.restThreshold)&&ie(s,this.restThreshold)&&ie(r,this.restThreshold)&&ie(n.x,this.restThreshold)&&ie(n.y,this.restThreshold)&&ie(n.z,this.restThreshold)&&ie(a.x,this.restThreshold)&&ie(a.y,this.restThreshold)&&ie(a.z,this.restThreshold)&&ie(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!u&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._updatedLastTime=u,this._needsUpdate=!1,u}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:ei(this.maxDistance),minZoom:this.minZoom,maxZoom:ei(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:ei(this.maxPolarAngle),minAzimuthAngle:ei(this.minAzimuthAngle),maxAzimuthAngle:ei(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:W.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(e,i=!1){const s=JSON.parse(e),r=W.fromArray(s.position);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=ti(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=ti(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=ti(s.maxPolarAngle),this.minAzimuthAngle=ti(s.minAzimuthAngle),this.maxAzimuthAngle=ti(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],i),je.setFromVector3(r.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(je.theta,je.phi,i),this.zoomTo(s.zoom,i),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],i),this._needsUpdate=!0}connect(e){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(e)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_findPointerById(e){return this._activePointers.find(i=>i.pointerId===e)}_findPointerByMouseButton(e){return this._activePointers.find(i=>i.mouseButton===e)}_encloseToBoundary(e,i,s){const r=i.lengthSq();if(r===0)return e;const n=ee.copy(i).add(e),o=this._boundary.clampPoint(n,It).sub(n),l=o.lengthSq();if(l===0)return e.add(i);if(l===r)return e;if(s===0)return e.add(i).add(o);{const c=1+s*l/i.dot(o);return e.add(ee.copy(i).multiplyScalar(c)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(Ve(this._camera)){const e=this._camera,i=e.near,s=e.getEffectiveFOV()*Qt,r=Math.tan(s*.5)*i,n=r*e.aspect;this._nearPlaneCorners[0].set(-n,-r,0),this._nearPlaneCorners[1].set(n,-r,0),this._nearPlaneCorners[2].set(n,r,0),this._nearPlaneCorners[3].set(-n,r,0)}else if(Oe(this._camera)){const e=this._camera,i=1/e.zoom,s=e.left*i,r=e.right*i,n=e.top*i,a=e.bottom*i;this._nearPlaneCorners[0].set(s,n,0),this._nearPlaneCorners[1].set(r,n,0),this._nearPlaneCorners[2].set(r,a,0),this._nearPlaneCorners[3].set(s,a,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||gs(this._camera,"_collisionTest"))return e;const s=W.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);vs.lookAt(Vr,s,this._camera.up);for(let r=0;r<4;r++){const n=ee.copy(this._nearPlaneCorners[r]);n.applyMatrix4(vs);const a=It.addVectors(this._target,n);ki.set(a,s),ki.far=this._spherical.radius+1;const o=ki.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 H.Sphere){const s=i,r=s.center;kt.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&kt.expandByObject(a)}),kt.getCenter(r);let n=0;return e.traverseVisible(a=>{if(!a.isMesh)return;const o=a,l=o.geometry.clone();if(l.applyMatrix4(o.matrixWorld),l.isBufferGeometry){const u=l.attributes.position;for(let f=0,m=u.count;f<m;f++)W.fromBufferAttribute(u,f),n=Math.max(n,r.distanceToSquared(W))}else{const u=l.attributes.position;for(let f=0,m=u.count;f<m;f++)W.fromBufferAttribute(u,f),n=Math.max(n,r.distanceToSquared(W))}}),s.radius=Math.sqrt(n),s}}var Ne=(h=>(h[h.Orbit=0]="Orbit",h[h.FirstPerson=1]="FirstPerson",h[h.Plan=2]="Plan",h))(Ne||{});class Rn{constructor(t){p(this,"mode");p(this,"cameraManager");this.mode=Ne.Orbit,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:K.ACTION.ROTATE,middle:K.ACTION.DOLLY,right:K.ACTION.TRUCK,wheel:Ve(t)?K.ACTION.DOLLY:Oe(t)?K.ACTION.ZOOM:K.ACTION.NONE},e.touches={one:K.ACTION.TOUCH_ROTATE,two:Ve(t)?K.ACTION.TOUCH_DOLLY_TRUCK:Oe(t)?K.ACTION.TOUCH_ZOOM_TRUCK:K.ACTION.NONE,three:K.ACTION.TOUCH_TRUCK},e.dollyToCursor=!0,e.azimuthRotateSpeed=1,e.polarRotateSpeed=1,e.minDistance=1,e.maxDistance=300,e.minZoom=3,this.cameraManager.cameraControls.truckSpeed=2}adjustCameraByBBox(t){const e=this.cameraManager.cameraControls,i=new d.Vector3;t.getSize(i);const s=i.length();e.minDistance=1,e.maxDistance=s*10,e.minZoom=3}}class Fn{constructor(t){p(this,"mode");p(this,"cameraManager");this.mode=Ne.Plan,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:K.ACTION.TRUCK,middle:K.ACTION.TRUCK,right:K.ACTION.TRUCK,wheel:Ve(t)?K.ACTION.DOLLY:Oe(t)?K.ACTION.ZOOM:K.ACTION.NONE},e.touches={one:K.ACTION.TOUCH_TRUCK,two:Ve(t)?K.ACTION.TOUCH_DOLLY_TRUCK:Oe(t)?K.ACTION.TOUCH_ZOOM_TRUCK:K.ACTION.NONE,three:K.ACTION.NONE},e.dollyToCursor=!0,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0,e.truckSpeed=1,e.maxZoom=1/0,e.minZoom=-1/0}adjustCameraByBBox(t){}}const Dt=50,ws=new d.Vector3;class zh{constructor(t){p(this,"viewer");p(this,"perspectiveCamera");p(this,"orthographicCamera");p(this,"activeCamera");p(this,"cameraControls");p(this,"previousDistance");p(this,"previousAzimuthRotateSpeed");p(this,"previousPolarRotateSpeed");p(this,"previousDollySpeed");p(this,"previousTruckSpeed");p(this,"previousMouseLeft");p(this,"enableKeyDown");p(this,"controlsMap");p(this,"activeControls");p(this,"projection");p(this,"anchor");p(this,"onKeyDown");p(this,"onChange");this.previousDistance=-1,this.previousAzimuthRotateSpeed=1,this.previousPolarRotateSpeed=1,this.previousDollySpeed=1,this.previousTruckSpeed=2,this.previousMouseLeft=K.ACTION.NONE,this.enableKeyDown=!0,this.projection=$e.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const r=this.cameraControls,n=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===Be.Viewer3d||this.viewer.name===Be.BimTilesViewer;switch(s.code){case"ArrowLeft":a?r.rotate(.1,0,!0):this.viewer.name===Be.Viewer2d&&r.truck(n,0,!0);break;case"ArrowRight":a?r.rotate(-.1,0,!0):this.viewer.name===Be.Viewer2d&&r.truck(-n,0,!0);break;case"ArrowUp":a?r.rotate(0,.1,!0):this.viewer.name===Be.Viewer2d&&r.truck(0,n,!0);break;case"ArrowDown":a?r.rotate(0,-.1,!0):this.viewer.name===Be.Viewer2d&&r.truck(0,-n,!0);break;case"KeyW":a&&(Oe(this.activeCamera)?r.zoom(.01,!0):r.dolly(1,!0));break;case"KeyA":a&&r.truck(-n,0,!0);break;case"KeyS":a&&(Oe(this.activeCamera)?r.zoom(-.01,!0):r.dolly(-1,!0));break;case"KeyD":a&&r.truck(n,0,!0);break;case"KeyQ":a&&r.truck(0,-n,!0);break;case"KeyE":a&&r.truck(0,n,!0);break}},this.onChange=()=>{this.viewer.enableRender()},this.viewer=t;const e=t.viewerContainer,i=e.clientWidth/e.clientHeight;this.perspectiveCamera=new d.PerspectiveCamera(ln,i,Vi,Ui),this.orthographicCamera=new d.OrthographicCamera(Dt*i/-2,Dt*i/2,Dt/2,Dt/-2,Vi,Ui),this.activeCamera=this.perspectiveCamera,this.setupCameras(),K.install({THREE:d}),this.cameraControls=new K(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[Ne.Orbit]:new Rn(this),[Ne.Plan]:new Fn(this)},this.activeControls=this.controlsMap[Ne.Orbit],this.setupControls(),this.setProjection($e.Perspective),this.anchor=this.createAnchor()}get viewerContainer(){return this.viewer.viewerContainer}get inputManager(){return this.viewer.getInputManager()}createAnchor(){const t=document.createElement("div");return t.className="anchor",this.viewerContainer?.appendChild(t),this.cameraControls.addEventListener("control",()=>{if(this.isOrbitPointVisible()){const e=this.getTarget(),i=pe.world2Screen(e,this.activeCamera,this.viewerContainer);this.setAnchorPosition(i.x,i.y)}}),t}setAnchorPosition(t,e){this.anchor.style.left=t+"px",this.anchor.style.top=e+"px"}setOrbitPointVisible(t){t?this.anchor.classList.add("active"):this.anchor.classList.remove("active")}isOrbitPointVisible(){return this.anchor.classList.contains("active")}setOrthoCameraAspect(t,e){const i=t/e;this.orthographicCamera.left=-50*i/2,this.orthographicCamera.right=Dt*i/2,this.orthographicCamera.top=Dt/2,this.orthographicCamera.bottom=-50/2,this.orthographicCamera.updateProjectionMatrix()}setupCameras(){this.setCameraPositionAndTarget(this.perspectiveCamera)}setCameraPositionAndTarget(t){t.position.z=10,t.position.y=10,t.position.x=10,t.lookAt(new d.Vector3(0,0,0))}setupControls(){const t=this.cameraControls;t.smoothTime=.1,t.draggingSmoothTime=0,t.infinityDolly=!0,t.setTarget(0,0,0),t.addEventListener("controlstart",()=>this.onChange),t.addEventListener("control",()=>this.onChange),t.addEventListener("update",()=>this.viewer.dispatchEvent(re.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===Ne.FirstPerson)return;this.previousDistance=this.cameraControls.distance,this.cameraControls.distance=200;const{width:t,height:e}=this.getDims();this.setupOrthoCamera(e,t),this.activeCamera=this.orthographicCamera,this.projection=$e.Orthographic}getDims(){const t=new d.Vector3;this.perspectiveCamera.getWorldDirection(t);const e=new d.Vector3;this.cameraControls.getTarget(e);const i=e.clone().sub(this.perspectiveCamera.position),s=i.dot(t),{clientWidth:r,clientHeight:n}=this.viewer.viewerContainer,a=r/n,o=this.perspectiveCamera.fov,l=s*2*Math.atan(o*(Math.PI/180)/2);return{width:l*a,height:l}}setupOrthoCamera(t,e){this.cameraControls.mouseButtons.wheel=K.ACTION.ZOOM;const i=this.perspectiveCamera,s=this.orthographicCamera;s.zoom=1,s.left=e/-2,s.right=e/2,s.top=t/2,s.bottom=t/-2,s.updateProjectionMatrix(),s.position.copy(i.position),s.quaternion.copy(i.quaternion),this.cameraControls.camera=s}setPerspectiveCamera(){const t=this.cameraControls;t.mouseButtons.wheel=K.ACTION.DOLLY;const e=this.perspectiveCamera,i=this.orthographicCamera;e.position.copy(i.position),e.quaternion.copy(i.quaternion),e.updateProjectionMatrix(),t.camera=e,t.mouseButtons.wheel=K.ACTION.DOLLY,this.activeCamera=e,this.projection=$e.Perspective,t.distance=this.previousDistance,t.zoomTo(1)}update(t){const e=this.cameraControls.update(t);return this.camera.updateMatrixWorld(),e}updateAspect(){const{clientWidth:t,clientHeight:e}=this.viewer.viewerContainer;this.perspectiveCamera.aspect=t/e,this.perspectiveCamera.updateProjectionMatrix(),this.setOrthoCameraAspect(t,e)}get camera(){return this.activeCamera}enableKeyControl(t){this.enableKeyDown=t}getTarget(){return this.cameraControls.getTarget(ws)}getPosition(){return this.cameraControls.getPosition(ws)}adjustCameraByBBox(t){const e=this.camera.near,i=this.camera.far,s=new d.Vector3;t.getSize(s);const r=s.length(),n=5,a=r/n,o=r*n;if(e>a||i<o){const l=c=>V.numberToString(c);S.info("[Viewer] BBox's longest side is: "+l(r)),e>a&&(S.warn("[Viewer] camera.near("+l(e)+") shouldn't bigger than "+l(a)+", will change it!"),this.camera.near=a),i<o&&(S.warn("[Viewer] camera.far("+l(i)+") shouldn't smaller than "+l(o)+", will change it!"),this.camera.far=o)}this.activeControls.adjustCameraByBBox(t),this.cameraControls.update(0)}enableControl(t){this.cameraControls.enabled=t}get enableRotate(){const t=this.cameraControls;return!!t.azimuthRotateSpeed||!!t.polarRotateSpeed}set enableRotate(t){const e=this.cameraControls;t?(e.azimuthRotateSpeed=this.previousAzimuthRotateSpeed,e.polarRotateSpeed=this.previousPolarRotateSpeed):(this.previousAzimuthRotateSpeed=e.azimuthRotateSpeed,this.previousPolarRotateSpeed=e.polarRotateSpeed,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0)}enableZoom(t){const e=this.cameraControls;t?e.dollySpeed=this.previousDollySpeed:(this.previousDollySpeed=e.dollySpeed,e.dollySpeed=0)}enablePan(t){const e=this.cameraControls;t?e.truckSpeed=this.previousTruckSpeed:(this.previousTruckSpeed=e.dollySpeed,e.truckSpeed=0)}enableMouseLeft(t){const e=this.cameraControls;t?e.mouseButtons.left=this.previousMouseLeft:(this.previousMouseLeft=e.mouseButtons.left,e.mouseButtons.left=K.ACTION.NONE)}setCameraPosition(t){this.cameraControls.setPosition(t.x,t.y,t.z)}setCameraTarget(t){this.cameraControls.setTarget(t.x,t.y,t.z)}flyTo(t,e,i=!0){const s=this.cameraControls;s.setLookAt(t.x,t.y,t.z,e.x,e.y,e.z,i),s.setFocalOffset(0,0,0,!0)}flyToPosition(t,e,i){this.cameraControls.moveTo(t,e,i,!0)}flyToBox(t,e){const i=new d.Sphere;t.getBoundingSphere(i),this.cameraControls.fitToBox(t,!0,e)}fitToSphere(t){this.cameraControls.fitToSphere(t,!0)}flyToObject(t){const e=new d.Box3().setFromObject(t),i=new d.Sphere;e.getBoundingSphere(i),this.cameraControls.fitToSphere(i,!0)}flyToViewpoint(t){this.flyTo(t.eye,t.look),t.zoom!=null&&(this.orthographicCamera.zoom=t.zoom)}getDistanceToFitSphere(t){return this.cameraControls.getDistanceToFitSphere(t)}setNavigationMode(t){this.activeControls.mode!==t&&(this.activeControls=this.controlsMap[t],this.activeControls.setupControl())}getProjection(){return this.projection}setProjection(t){this.projection!==t&&(this.projection=t,t===$e.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection(ws)}getCameraConfig(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,near:this.activeCamera.near,far:this.activeCamera.far,zoom:this.activeCamera.zoom}}getCurrentViewpoint(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,zoom:this.activeCamera.zoom}}setCameraConfig(t){const e=this.cameraControls,{near:i=Vi,far:s=Ui,up:r=new d.Vector3(0,1,0),zoom:n=1,eye:a,look:o}=t;this.activeCamera.near=i,this.activeCamera.far=s,this.activeCamera.up.set(r.x,r.y,r.z),this.activeCamera.updateProjectionMatrix(),e.updateCameraUp(),e.zoomTo(n),e.setLookAt(a.x,a.y,a.z,o.x,o.y,o.z,!0),e.setFocalOffset(0,0,0,!0)}destroy(){this.anchor.remove(),this.inputManager.removeEventListener("keydown",this.onKeyDown),this.perspectiveCamera.removeFromParent(),this.orthographicCamera.removeFromParent()}}const Ot=class Ot extends On{tableName(){return"fonts"}static instance(){return!Ot._instance&&(Ot._instance=new Ot),Ot._instance}query(t){let e;return new Promise((i,s)=>{super.query(r=>{if(!r){i(e);return}!r.value||r.value.fileName!==t||(e=r.value)},r=>{s(r)})})}queryAll(){const t=Object.create(null,{queryAll:{get:()=>super.queryAll}});return new Promise((e,i)=>{t.queryAll.call(this,s=>{e(s)},s=>{i(s)})})}};p(Ot,"_instance");let Wt=Ot;var zn=(h=>(h[h.Horizontal=0]="Horizontal",h[h.Vertical=1]="Vertical",h[h.All=2]="All",h))(zn||{}),Ee=(h=>(h[h.Shapes=0]="Shapes",h[h.Bigfont=1]="Bigfont",h[h.Unifont=2]="Unifont",h))(Ee||{});class jn extends Ca.Font{constructor(e,i){super(i);p(this,"info");p(this,"orientation");p(this,"baseUp");p(this,"baseDown");p(this,"fileHeader");p(this,"fileVersion");p(this,"fileName");p(this,"data");p(this,"order");p(this,"unsupportedChars");this.info="",this.orientation=zn.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)=>{Wt.instance().save(e,()=>{console.log("[FontFile] Saved '"+this.fileName+"' ("+this.fileHeader+") to indexedDb"),i()},r=>s("[FontFile] Failed to save '"+this.fileName+"' ("+this.fileHeader+") to indexedDb! "+r))})}async getFontDataByIndexedDb(){return Wt.instance().query(this.fileName)}releaseFontData(){this.data={}}}class vt extends jn{constructor(e,i){super(e,i);p(this,"reversed");this.reversed=!1,i instanceof ArrayBuffer?this.data=this.parseTTF(i):i.fileName?this.setFontFile(i):this.data=i,this.type="MeshFont"}generateShapes(e,i){return super.generateShapes(e,i)}getCharShape(e,i){const s=qr(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return qr("?",e,0,0,this.data)?.path}parseTTF(e){function i(r,n){const a=Math.round,o={},l=1e5/((r.unitsPerEm||2048)*72),c=r.encoding.cmap.glyphIndexMap,u=Object.keys(c);for(let f=0;f<u.length;f++){const m=u[f],g=r.glyphs.glyphs[c[m]];if(m!==void 0){const x={ha:a(g.advanceWidth*l),x_min:a(g.xMin*l),x_max:a(g.xMax*l),o:""};n&&(g.path.commands=s(g.path.commands)),g.path.commands.forEach(function(y){y.type.toLowerCase()==="c"&&(y.type="b"),x.o+=y.type.toLowerCase()+" ",y.x!==void 0&&y.y!==void 0&&(x.o+=a(y.x*l)+" "+a(y.y*l)+" "),y.x1!==void 0&&y.y1!==void 0&&(x.o+=a(y.x1*l)+" "+a(y.y1*l)+" "),y.x2!==void 0&&y.y2!==void 0&&(x.o+=a(y.x2*l)+" "+a(y.y2*l)+" ")}),o[String.fromCodePoint(g.unicode)]=x}}return{glyphs:o,familyName:r.getEnglishName("fullName"),ascender:a(r.ascender*l),descender:a(r.descender*l),underlinePosition:r.tables.post.underlinePosition,underlineThickness:r.tables.post.underlineThickness,boundingBox:{xMin:r.tables.head.xMin,xMax:r.tables.head.xMax,yMin:r.tables.head.yMin,yMax:r.tables.head.yMax},resolution:1e3,original_font_information:r.tables.name}}function s(r){const n=[];let a;r.forEach(function(l){l.type.toLowerCase()==="m"?(a=[l],n.push(a)):l.type.toLowerCase()!=="z"&&a.push(l)});const o=[];return n.forEach(function(l){const c={type:"m",x:l[l.length-1].x,y:l[l.length-1].y};o.push(c);for(let u=l.length-1;u>0;u--){const f=l[u],m={type:f.type};f.x2!==void 0&&f.y2!==void 0?(m.x1=f.x2,m.y1=f.y2,m.x2=f.x1,m.y2=f.y1):f.x1!==void 0&&f.y1!==void 0&&(m.x1=f.x1,m.y1=f.y1),m.x=l[u-1].x,m.y=l[u-1].y,o.push(m)}}),o}return i(Ta.parse(e),this.reversed)}}function qr(h,t,e,i,s){const r=s.glyphs[h];if(!r)return;const n=new d.ShapePath;let a,o,l,c,u,f,m,g;if(r.o){const x=r._cachedOutline||(r._cachedOutline=r.o.split(" "));for(let y=0,T=x.length;y<T;)switch(x[y++]){case"m":a=x[y++]*t+e,o=x[y++]*t+i,n.moveTo(a,o);break;case"l":a=x[y++]*t+e,o=x[y++]*t+i,n.lineTo(a,o);break;case"q":l=x[y++]*t+e,c=x[y++]*t+i,u=x[y++]*t+e,f=x[y++]*t+i,n.quadraticCurveTo(u,f,l,c);break;case"b":l=x[y++]*t+e,c=x[y++]*t+i,u=x[y++]*t+e,f=x[y++]*t+i,m=x[y++]*t+e,g=x[y++]*t+i,n.bezierCurveTo(u,f,m,g,l,c);break}}return{offsetX:r.ha*t,path:n}}class J{static GetBytes(t){switch(typeof t){case"string":{const e=new Uint16Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return new Uint8Array(e.buffer)}case"number":return t-Math.floor(t)==0?t>4294967295?(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Int32Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1));case"boolean":return(function(e){return e[0]=Number(t),e})(new Uint8Array(1));default:if(t instanceof Array){const e=[];for(let n=0;n<t.length;n++)e.push(J.GetBytes(t[n]));let i=0;for(let n=0;n<e.length;n++)i+=e[n].length;const s=new Uint8Array(i);let r=0;for(let n=0;n<e.length;n++)for(let a=0;a<e[n].length;a++)s[r++]=e[n][a];return s}throw"Can't Convert To Bytes!!"}}static Get1Bytes(t){switch(typeof t){case"number":case"boolean":return new Uint8Array([Number(t)]);default:if(t instanceof Array){const e=[];for(let n=0;n<t.length;n++)e.push(this.Get1Bytes(t[n]));let i=0;for(let n=0;n<e.length;n++)i+=e[n].length;const s=new Uint8Array(i);let r=0;for(let n=0;n<e.length;n++)for(let a=0;a<e[n].length;a++)s[r++]=e[n][a];return s}throw"Can't Convert To Bytes!!"}}static byteTosbyte(t){return(t&127)-(t&128?128:0)}static ToBoolean(t,e){return e=e||0,!!t[e]}static ToInt8(t,e){return e=e||0,t[e]&128?-((t[e]^255)+1):t[e]}static ToUInt8(t,e){return e=e||0,t[e]}static ToInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Int16Array(i.buffer,0,1)[0]}static ToInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Int32Array(i.buffer,0,1)[0]}static ToUInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Uint16Array(i.buffer,0,1)[0]}static ToUInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Uint32Array(i.buffer,0,1)[0]}static ToChar(t,e){e=e||0;const i=t.slice(e,e+2);return String.fromCharCode(new Uint16Array(i.buffer,0,1)[0])}static ToAscii(t,e){return e=e||0,String.fromCharCode(t[e])}static ToAsciiString(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);let s="";for(let r=0;r<i;r++)s+=String.fromCharCode(t[e+r]||0);return s}static ToUTF16String(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);const s=new Uint8Array(i);for(let r=0;r<i;r++)s[r]=t[e+r]||0;return String.fromCharCode.apply(null,Array.from(new Uint16Array(s.buffer,0,i/2)))}static ToFloat32(t,e){e=e||0;const i=t.slice(e,e+4);return new Float32Array(i.buffer,0,1)[0]}static ToFloat64(t,e){e=e||0;const i=t.slice(e,e+8);return new Float64Array(i.buffer,0,1)[0]}}let Xi;function jh(){const h=[[161,169,161,254],[176,247,161,254],[129,160,64,254],[170,254,64,160],[168,169,64,160],[170,175,161,254],[248,254,161,254],[161,167,64,160]],t=new Uint16Array(23940);let e=0;for(const[s,r,n,a]of h)for(let o=n;o<=a;o++)if(o!==127)for(let l=s;l<=r;l++)t[e++]=o<<8|l;const i=new TextDecoder("gbk").decode(t);for(Xi=new Uint16Array(65536),e=0;e<i.length;e++)Xi[i.charCodeAt(e)]=t[e]}function Vh(h){!Xi&&jh();const t=new Uint8Array(h.length*2);let e=0;for(let i=0;i<h.length;i++){const s=h.charCodeAt(i);if(s<128)t[e++]=s;else{const r=Xi[s];t[e++]=r&255,t[e++]=r>>8}}return t.subarray(0,e)}new d.Vector2;class mi extends d.Shape{constructor(e,i){super();p(this,"width");p(this,"lastPoint");p(this,"polylines");p(this,"bounds");this.width=0,this.bounds=new d.Box2,this.lastPoint=e,this.polylines=i,this.width=this.calcWidth(i)}offset(e){const i=[];for(let s=0;s<this.polylines.length;s++){const r=this.polylines[s],n=[];for(let a=0;a<r.length;a++){const o=r[a];n.push(o.clone().add(e))}i.push(n)}return new mi(this.lastPoint,i)}transform(e){const i=[];for(let s=0;s<this.polylines.length;s++){const r=this.polylines[s],n=[];for(let a=0;a<r.length;a++){const o=r[a];n.push(o.clone().applyMatrix3(e))}i.push(n)}return new mi(this.lastPoint.clone().applyMatrix3(e),i)}calcWidth(e){const i=this.bounds;for(let n=0;n<e.length;n++){const a=e[n];for(let o=0;o<a.length;o++){const l=a[o];i.expandByPoint(l)}}const s=i.min.x||0;return(i.max.x||0)-s}toThreeGeometry(){const e=this.polylines,i=[],s=[];let r=0;const n=new d.BufferGeometry;for(let a=0;a<e.length;a++){const o=e[a];for(let l=0;l<o.length;l++){const c=o[l];i.push(c.x,c.y,0),l===o.length-1||s.push(r,r+1),r++}}return n.userData={advanceWidth:this.width},n.setAttribute("position",new d.Float32BufferAttribute(i,3)),n.setIndex(s),n}}const Ze=class Ze{static parserHeader(t,e){let i="",s=!1,r=0;const n=!0;for(;n;){const a=t.readInt8(),o=String.fromCharCode(a);if(s)o===e[r]?r++:(s=!1,r=0);else{if(o===e[r]){s=!0,r++;continue}i+=o}if(s&&r===e.length)break}return i}static getCode(t){const e=Vh(t);return e.length<2?e[0]:e.length<4?J.ToUInt16(e,0):J.ToUInt32(e,0)}static parserCode(t,e,i){let s=new d.Vector2;const r=[];let n=[];const a=[];let o=!1;for(let l=0;l<e.length;l++){const c=e[l];switch(c){case 0:break;case 1:o=!0,n.push(s.clone());break;case 2:o=!1,n.length>1?(r.push(n.slice()),n=[]):s.set(0,0);break;case 3:l++,i/=e[l];break;case 4:l++,i*=e[l];break;case 5:if(a.length===4)throw"The position stack is only four locations deep";a.push(s.clone());break;case 6:if(a.length===0)break;s=a.pop(),n.length>1&&(r.push(n.slice()),n=[]),o&&n.push(s.clone());break;case 7:{let u=0,f,m=i*t.baseUp;const g=s.clone();switch(n.length>1&&(r.push(n.slice()),n=[]),t.fontType){case Ee.Shapes:l++,u=e[l];break;case Ee.Bigfont:l++,u=e[l],u==0&&(l++,u=J.ToUInt16(new Uint8Array([e[l++],e[l++]]),0),g.x=e[l++]*i,g.y=e[l++]*i,m=e[l]*i);break;case Ee.Unifont:l+=2,u=J.ToUInt16(new Uint8Array([e[l-1],e[l]]),0);break}u!==0&&(f=t.getGraphicDataByCodeWithOffset(u,m,g),f&&(r.push(...f.polylines.slice()),s=f.lastPoint.clone()))}break;case 8:{const u=new d.Vector2;u.x=J.byteTosbyte(e[++l]),u.y=J.byteTosbyte(e[++l]),s.add(u.multiplyScalar(i)),o&&n.push(s.clone())}break;case 9:for(;;){const f=new d.Vector2;if(f.x=J.byteTosbyte(e[++l]),f.y=J.byteTosbyte(e[++l]),!Number.isFinite(f.x)||!Number.isFinite(f.y)||f.x==0&&f.y==0)break;s.add(f.multiplyScalar(i)),o&&n.push(s.clone())}break;case 10:{const u=e[++l]*i,f=J.byteTosbyte(e[++l]),m=(f&112)>>4;let g=f&7;g==0&&(g=8);const x=Math.PI/4;let y=x*g,T=Ze.CIRCLE_SPAN;f<0&&(T=-T,y=-y);const v=x*m,b=v+y,E=s.clone().sub(new d.Vector2(Math.cos(v)*u,Math.sin(v)*u));if(s=E.clone().add(new d.Vector2(Math.cos(b)*u,Math.sin(b)*u)),o){let O=v;const _=!0;for(;_&&(O+=T,!!Number.isFinite(O));)if(f>=0&&O<b||f<0&&O>b)n.push(E.clone().add(new d.Vector2(u*Math.cos(O),u*Math.sin(O))));else break;n.push(s.clone())}}break;case 11:{const u=e[++l],f=e[++l],m=e[++l],g=e[++l],x=(m*255+g)*i,y=J.byteTosbyte(e[++l]),T=(y&112)>>4;let v=y&7;v==0&&(v=8),f!=0&&v--;const b=Math.PI/4;let E=b*v,O=Ze.CIRCLE_SPAN,_=1;y<0&&(O=-O,E=-E,_=-1);let C=b*T,w=C+E;C+=b*u/256*_,w+=b*f/256*_;const M=s.clone().sub(new d.Vector2(x*Math.cos(C),x*Math.sin(C)));if(s=M.clone().add(new d.Vector2(x*Math.cos(w),x*Math.sin(w))),o){let P=C;const A=!0;for(;A&&(P+=O,!!Number.isFinite(P));)if(y>0&&P<w||y<0&&P>w)n.push(M.clone().add(new d.Vector2(x*Math.cos(P),x*Math.sin(P))));else break;n.push(s.clone())}}break;case 12:{const u=new d.Vector2;u.x=J.byteTosbyte(e[++l])*i,u.y=J.byteTosbyte(e[++l])*i;let f=J.byteTosbyte(e[++l]);f<-127&&(f=-127),o&&(f==0?n.push(s.clone().add(u)):n.push(Ze.generateArcPoints(s,u,f/127))),s.add(u)}break;case 13:for(;;){const f=new d.Vector2;if(f.x=J.byteTosbyte(e[++l])*i,f.y=J.byteTosbyte(e[++l])*i,!Number.isFinite(f.x)||!Number.isFinite(f.y)||f.x==0&&f.y==0)break;let m=J.byteTosbyte(e[++l]);m<-127&&(m=-127),o&&(m==0?n.push(s.clone().add(f)):n.push(Ze.generateArcPoints(s.clone(),f,m/127))),s.add(f)}break;case 14:l=Ze.skipCode(t,e,++l);break;default:if(c>15){const u=(c&240)>>4,f=c&15,m=new d.Vector2;switch(f){case 0:m.x=1;break;case 1:m.x=1,m.y=.5;break;case 2:m.x=1,m.y=1;break;case 3:m.x=.5,m.y=1;break;case 4:m.y=1;break;case 5:m.x=-.5,m.y=1;break;case 6:m.x=-1,m.y=1;break;case 7:m.x=-1,m.y=.5;break;case 8:m.x=-1;break;case 9:m.x=-1,m.y=-.5;break;case 10:m.x=-1,m.y=-1;break;case 11:m.x=-.5,m.y=-1;break;case 12:m.y=-1;break;case 13:m.x=.5,m.y=-1;break;case 14:m.x=1,m.y=-1;break;case 15:m.x=1,m.y=-.5;break}s.add(m.multiplyScalar(u*i)),o&&n.push(s.clone())}break}}return new mi(s,r)}static skipCode(t,e,i){switch(e[i]){case 0:break;case 1:break;case 2:break;case 3:case 4:i++;break;case 5:break;case 6:break;case 7:switch(t.fontType){case Ee.Shapes:i++;break;case Ee.Bigfont:i++,e[i]==0&&(i+=6);break;case Ee.Unifont:i+=2;break}break;case 8:i+=2;break;case 9:for(;;){const n=e[++i],a=e[++i];if(n===void 0||a===void 0||n==0&&a==0)break}break;case 10:i+=2;break;case 11:i+=5;break;case 12:i+=3;break;case 13:for(;;){const n=e[++i],a=e[++i];if(n===void 0||a===void 0||n==0&&a==0)break;e[++i]}break}return i}static generateArcPoints(t,e,i){const s=t.clone().add(e),r=i<0,n=!1;i=Math.abs(i);const a=e.length()/2,o=a*i,l=2*Math.atan(1/i),c=new d.Vector2(e.y,-e.x);c.normalize(),c.multiplyScalar(o);const u=Math.abs(a/Math.sin(l/2)),f=t.add(e.divideScalar(2));n!==r?f.add(c):f.sub(c);const m=t.sub(f),g=s.sub(f);let x=Math.atan2(m.y,m.x);const y=Math.atan2(g.y,g.x);let T=Ze.CIRCLE_SPAN;r?(T=-T,x<y&&(x+=2*Math.PI)):x>y&&(x-=2*Math.PI);let v=x;const b=!0;for(;b;){if(v+=T,!r&&v<y||r&&v>y)return f.add(new d.Vector2(u*Math.cos(v),u*Math.sin(v)));break}return s}};p(Ze,"FILE_STOP_FLAG",["\r",`
1532
- `,""]),p(Ze,"CIRCLE_SPAN",Math.PI/18);let lt=Ze;const Ms={130:[[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],131:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],132:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],133:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]]],134:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],135:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],136:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],178:[[[1.142,9.285],[1.142,9.428],[1.285,9.714],[1.428,9.857],[1.714,10],[2.285,10],[2.571,9.857],[2.714,9.714],[2.857,9.428],[2.857,9.142],[2.714,8.857],[2.428,8.428],[1,7],[3,7]]],8960:[[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]],[[0,0],[8,8]]],20393:[[[0,0],[0,6.666]],[[0,4.761],[1.428,6.19],[2.38,6.666],[3.809,6.666],[4.761,6.19],[5.238,4.761],[5.238,0]],[[5.238,4.761],[6.666,6.19],[7.619,6.666],[9.047,6.666],[10,6.19],[10.476,4.761],[10.476,0]],[[11.142,9.285],[11.142,9.428],[11.285,9.714],[11.428,9.857],[11.714,10],[12.285,10],[12.571,9.857],[12.714,9.714],[12.857,9.428],[12.857,9.142],[12.714,8.857],[12.428,8.428],[11,7],[13,7]]],41123:[],55714:[[[2,5.9],[2.6,6.1],[3.4,7],[3.4,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],55970:[[[2.3,5.6],[2.3,5.9],[2.6,6.4],[2.9,6.7],[3.4,7],[4.6,7],[5.1,6.7],[5.4,6.4],[5.7,5.9],[5.7,5.3],[5.4,4.7],[4.9,3.9],[2,1],[6,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56226:[[[2.6,7],[5.7,7],[4,4.7],[4.9,4.7],[5.4,4.4],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56482:[[[4.9,7],[2,3],[6.3,3]],[[4.9,7],[4.9,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56738:[[[5.4,7],[2.6,7],[2.3,4.4],[2.6,4.7],[3.4,5],[4.3,5],[5.1,4.7],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56994:[[[5.4,6.1],[5.1,6.7],[4.3,7],[3.7,7],[2.9,6.7],[2.3,5.9],[2,4.4],[2,3],[2.3,1.9],[2.9,1.3],[3.7,1],[4,1],[4.9,1.3],[5.4,1.9],[5.7,2.7],[5.7,3],[5.4,3.9],[4.9,4.4],[4,4.7],[3.7,4.7],[2.9,4.4],[2.3,3.9],[2,3]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57250:[[[2,7],[6,7],[3.1,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57506:[[[3.4,7],[2.6,6.7],[2.3,6.1],[2.3,5.6],[2.6,5],[3.1,4.7],[4.3,4.4],[5.1,4.1],[5.7,3.6],[6,3],[6,2.1],[5.7,1.6],[5.4,1.3],[4.6,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1],[2,3],[2.3,3.6],[2.9,4.1],[3.7,4.4],[4.9,4.7],[5.4,5],[5.7,5.6],[5.7,6.1],[5.4,6.7],[4.6,7],[3.4,7]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57762:[[[5.7,5],[5.4,4.1],[4.9,3.6],[4,3.3],[3.7,3.3],[2.9,3.6],[2.3,4.1],[2,5],[2,5.3],[2.3,6.1],[2.9,6.7],[3.7,7],[4,7],[4.9,6.7],[5.4,6.1],[5.7,5],[5.7,3.6],[5.4,2.1],[4.9,1.3],[4,1],[3.4,1],[2.6,1.3],[2.3,1.9]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],60070:[[[0,6],[10,6],[10,4]]],60326:[[[0,7],[0,5],[10,5]]]},Wr=new d.Matrix3,di=class di extends jn{constructor(e,i){super(e,i);p(this,"isExtend");p(this,"isUniCode");p(this,"isEmbedded");p(this,"fontType");p(this,"textShapesCache");p(this,"graphicData");if(this.isExtend=!1,this.isUniCode=!0,this.isEmbedded=!1,this.fontType=Ee.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new xi(i),r=lt.parserHeader(s,lt.FILE_STOP_FLAG),n=r.split(" ");switch(n[1]){case"shapes":this.parseShapeFont(s),this.fontType=Ee.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=Ee.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=Ee.Unifont;break}this.fileHeader=n[0],this.fileVersion=n[2]}else this.setFontFile(i)}generateShapes(e,i){const s=[];let r=0;for(let n=0;n<e.length;n++){const a=e[n];if(a===" "){r+=i;continue}const o=this.getCharShape(a,i);if(!o){r+=i,this.addUnsupportedChar(a);continue}s.push(o.offset(new d.Vector2(r,0))),r+=o.width}return s}getCharShape(e,i){let s=lt.getCode(e);s===0&&(s=e.charCodeAt(0));const r=this.getGraphicDataByCode(s,i);if(!r)return this.addUnsupportedChar?.(e),null;if(r.polylines&&r.polylines.length===0&&(r.width=i*.8),typeof r.width!="number"||r.width<=0){const n=r,a=n.xMin!=null?n.xMin:0,o=n.xMax!=null?n.xMax:0;r.width=Math.max(.1,o-a)}return r}getGraphicDataByCode(e,i){const s=e+"_"+i;if(this.textShapesCache.has(s))return this.textShapesCache.get(s);if(e===0)return;const r=this.data;let n;if(!this.graphicData.has(e)){if(r[e]){const a=r[e],o=di.DEFAULT_SIZE/this.baseUp;n=lt.parserCode(this,a,o),this.graphicData.set(e,n)}else if(Ms[e]){const a=[];for(let o=0;o<Ms[e].length;o++)a.push(Ms[e][o].map(l=>new d.Vector2(l[0],l[1])));n=new mi(new d.Vector2,a),this.graphicData.set(e,n)}}if(this.graphicData.has(e)){const a=i/di.DEFAULT_SIZE;Wr.identity().scale(a,a),n=this.graphicData.get(e).transform(Wr)}return n}getGraphicDataByCodeWithOffset(e,i,s){return this.getGraphicDataByCode(e,i)?.offset(s)}parseBigFont(e){J.ToInt16(e.readBytes(2),0);const i=J.ToInt16(e.readBytes(2),0),s=J.ToInt16(e.readBytes(2),0);for(let l=0;l<s;l++)e.readBytes(2),e.readBytes(2);const r=[];for(let l=0;l<i;l++){const c=e.readBytes(8),u=J.ToUInt16(new Uint8Array([c[1],c[0]]),0),f=J.ToUInt16(c,2),m=J.ToUInt32(c,4);u===0&&f===0&&m===0||r.push({code:u,length:f,offset:m})}const n={};for(const l of r)e.setPosition(l.offset),n[l.code]=e.readBytes(l.length);const a=n[0];this.info=Uh(a);let o=this.info.indexOf("\0")+1;a.length-o===4?(this.baseUp=a[o++],this.baseDown=a[o++],this.orientation=a[o++]):(this.baseUp=a[o++],o++,this.orientation=a[o++],this.baseDown=a[o++],this.isExtend=!0),this.data=n}parseUniFont(e){const i=J.ToInt32(e.readBytes(4),0),s=J.ToInt16(e.readBytes(2),0),r=e.readBytes(s);this.info=new TextDecoder().decode(r);let n=this.info.indexOf("\0");this.baseUp=r[++n],this.baseDown=r[++n],this.orientation=r[++n],this.isUniCode=r[++n]==0,this.isEmbedded=r[++n]==0;const a={};for(let o=0;o<i-1;o++){const l=J.ToUInt16(e.readBytes(2),0),c=J.ToUInt16(e.readBytes(2),0);a[l]=e.readBytes(c)}this.data=a}parseShapeFont(e){e.readBytes(2),e.readBytes(2);const i=J.ToInt16(e.readBytes(2),0),s=[];for(let o=0;o<i;o++){const l=J.ToUInt16(e.readBytes(2),0),c=J.ToUInt16(e.readBytes(2),0);s.push({code:l,length:c})}const r={};for(const o of s)r[o.code]=e.readBytes(o.length);const n=r[0];this.info=new TextDecoder().decode(n);let a=this.info.indexOf("\0");this.baseUp=n[++a],this.baseDown=n[++a],this.orientation=n[++a],this.data=r}getNotFoundTextShape(e){let i=0;return this.fontType===Ee.Bigfont&&(i=lt.getCode("?")),this.fontType===Ee.Unifont&&(i=lt.getCode("?")),this.getGraphicDataByCode(i,e)}getFontFile(){return{fontType:this.fontType,order:this.order,data:this.data,info:this.info,orientation:this.orientation,baseUp:this.baseUp,baseDown:this.baseDown,fileName:this.fileName,fileHeader:this.fileHeader,fileVersion:this.fileVersion}}setFontFile(e){this.fileName=e.fileName,this.fontType=e.fontType||Ee.Unifont,this.data=e.data,this.info=e.info,this.order=e.order,this.orientation=e.orientation,this.baseUp=e.baseUp,this.baseDown=e.baseDown,this.fileHeader=e.fileHeader,this.fileVersion=e.fileVersion}releaseFontData(){super.releaseFontData(),this.graphicData.clear(),this.textShapesCache.clear()}};p(di,"DEFAULT_SIZE",12);let ht=di;function Uh(h){let t,e,i,s,r;t="";const n=h.length;for(e=0;e<n;)switch(i=h[e++],i>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(i);break;case 12:case 13:s=h[e++],t+=String.fromCharCode((i&31)<<6|s&63);break;case 14:s=h[e++],r=h[e++],t+=String.fromCharCode((i&15)<<12|(s&63)<<6|(r&63)<<0);break}return t}class Ke{constructor(){p(this,"loader");p(this,"fontMap");p(this,"fileNames");p(this,"unsupportedChars");p(this,"missingFonts");p(this,"enableFontCache");this.fontMap=new Map,this.unsupportedChars={},this.missingFonts={},this.enableFontCache=!0,this.loader=new d.FileLoader}async loadFonts(t){if(t=Array.isArray(t)?t:[t],this.fileNames=t.map(e=>typeof e=="object"?Object.keys(e)[0]:Ke.getFileName(e.toLowerCase())),!await this.checkAllFontsLoaded(t)){for(let e=0;e<t.length;e++){const i=t[e];let s=null,r=[],n=[];typeof i=="object"?(r=Object.keys(i),n=Object.values(i),s=r[0]):s=Ke.getFileName(i.toLowerCase());let a;if(r.length){const o=r[0];if(o.lastIndexOf(".json")>-1){this.loader.setResponseType("json");const l=await this.loader.loadAsync(n[0]);a=new vt(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(n[0]);a=new ht(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(n[0]);a=new vt(s,l)}}else if(Ke.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new vt(s,o)}else if(Ke.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new ht(s,o)}else if(Ke.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new vt(s,o)}a&&(a.order=e+1,this.fontMap.set(s,a))}this.enableFontCache&&be.isBrowser&&(this.fontMap.forEach(async e=>{await e.setFontDataToIndexedDb()}),this.releaseFontData())}}getTextShape(t,e,i){if(this.fontMap.size===0){S.warn("[FontManager] no font loaded.");return}let s=this.fontMap.get(e.toLowerCase());return!s&&(s=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++),s?.generateShapes(t,i)}getCharShape(t,e,i){if(this.fontMap.size===0){S.warn("[FontManager] no font loaded.");return}e==null&&(e="");let s=this.fontMap.get(e.toLowerCase());if(!s){!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++;for(const[,n]of this.fontMap)if(n.getCharShape(t,i)){s=n;break}}let r=s?.getCharShape(t,i);if(!r)for(const[,n]of this.fontMap){if(n===s)continue;const a=n.getCharShape(t,i);if(a){s=n,r=a;break}}if(r){if(s instanceof ht)return r.toThreeGeometry();if(s instanceof vt)return new Ma.TextGeometry(t,{font:s,depth:0,size:i||12,curveSegments:3,bevelSegments:3})}}getNotFoundTextShape(t){let e,i;for(const[,s]of this.fontMap){const r=s.getNotFoundTextShape(t);if(r){e=r,i=s;break}}if(i instanceof ht)return e.toThreeGeometry();if(i instanceof vt)return new d.ExtrudeGeometry(e.toShapes(!1),{curveSegments:3,bevelSegments:3})}async checkAllFontsLoaded(t){if(!be.isBrowser)return!1;let e=!1;for(let i=0;i<t.length;i++){const s=t[i];let r=null;typeof s=="object"?r=Object.keys(s)[0]:r=Ke.getFileName(s.toLowerCase());const n=await Wt.instance().query(r);if(n)e=!0;else{e=!1;break}if(n.codes!==void 0){e=!1;break}}return e}async getFontFromIndexeddb(){if(this.fontMap.size!==0)return;const t=(await Wt.instance().queryAll()).sort((e,i)=>e.order-i.order);for(let e=0;e<t.length;e++){const i=t[e],{fileName:s,fontType:r}=i;if(this.fileNames&&!this.fileNames.includes(s))continue;let n;r?n=new ht(s,i):n=new vt(s,i),this.fontMap.set(s,n)}S.debug("[FontManager] Loaded font data from cache.")}isShxFont(t){if(this.fontMap.size===0){S.warn("[FontManager] no font loaded.");return}let e=this.fontMap.get(t);return!e&&(e=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[t]&&(this.missingFonts[t]=0),this.missingFonts[t]++),e instanceof ht}getUnsupportedChar(){return this.fontMap.forEach(t=>{Object.assign(this.unsupportedChars,t.unsupportedChars)}),this.unsupportedChars}releaseFontData(){this.fontMap.forEach(t=>{t.releaseFontData()}),this.fontMap.clear()}destroy(){this.releaseFontData(),this.fontMap.clear()}static isShxFile(t){return V.getExtension(t)==="shx"}static isTtfFile(t){return["WOFF","OTF","TTF"].includes(V.getExtension(t).toUpperCase())}static isJsonFile(t){return V.getExtension(t)==="json"}static getFileName(t){const e=t.lastIndexOf("/");return t.substring(e+1)}}class Nh{constructor(t){p(this,"object");this.object=t}instantiate(){const t=Date.now();this.instantiateInner(this.object),console.log("[Inst] instantiate() took "+(Date.now()-t)/1e3+"s")}instantiateInner(t){if(!t.children||t.children.length===0)return;const e=t.children.length,i={},s=[];for(let a=0;a<e;++a){const o=t.children[a];if(this.instantiateInner(o),o.children&&o.children.length>0||!o.geometry)continue;let l=!1;const c=Object.values(i);for(let u=c.length-1;u>=0;--u){const f=c[u].indexes[0],m=t.children[f];if(this.geometryEquals(o.geometry,m.geometry)&&de.materialsEquals(o.material,m.material)){!i[f]&&(i[f]={indexes:[f]},this.removeFromArray(s,f)),i[f].indexes.push(a),l=!0;break}}for(let u=s.length-1;!l&&u>=0;--u){const f=s[u],m=t.children[f];if(this.geometryEquals(o.geometry,m.geometry)&&de.materialsEquals(o.material,m.material)){!i[f]&&(i[f]={indexes:[f]},this.removeFromArray(s,f)),i[f].indexes.push(a),l=!0;break}}!l&&s.push(a)}if(Object.keys(i).length<=0)return;const r=[],n=[];Object.values(i).forEach(a=>{const o=a.indexes;n.push(...o);const l=t.children[o[0]];let c=l.material;if(c instanceof d.Material)c=c.clone();else if(Array.isArray(c)){const f=[];c.forEach(m=>f.push(m.clone())),c=f}const u=new d.InstancedMesh(l.geometry,c,o.length);u.name="[Instanced] "+l.name;for(let f=0;f<o.length;++f){const m=o[f],g=t.children[m];g.updateMatrix(),u.setMatrixAt(f,g.matrix)}u.matrixAutoUpdate=He,u.updateMatrix(),r.push(u)}),n.sort((a,o)=>o-a),n.forEach(a=>t.remove(t.children[a])),r.forEach(a=>{a.parent=t,t.children.push(a)}),t.updateMatrix(),console.log("[Inst] "+n.length+"(out of "+e+") objects instanced to "+r.length+" InstancedMesh")}removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}geometryEquals(t,e){return U.geometriesEqual(t,e)}}class Vn{constructor(){p(this,"TIMEOUT","timeout");p(this,"INTERVAL","interval");p(this,"timeoutMap",{});p(this,"intervalMap",{})}run(t=this.INTERVAL,e,i=16.7){const s=Date.now;let r=s(),n=r;const a=Symbol(""),o=()=>{this.setIdMap(a,t,o),n=s(),n-r>=i&&(t===this.intervalMap&&(r=s(),n=r),e(),t===this.TIMEOUT&&this.clearTimeout(a))};return this.setIdMap(a,t,o),a}setIdMap(t,e,i){const s=requestAnimationFrame(i);e===this.INTERVAL?this.intervalMap[t]=s:e===this.TIMEOUT&&(this.timeoutMap[t]=s)}setTimeout(t,e){return this.run(this.TIMEOUT,t,e)}clearTimeout(t){cancelAnimationFrame(this.timeoutMap[t])}setInterval(t,e){return this.run(this.INTERVAL,t,e)}clearInterval(t){cancelAnimationFrame(this.intervalMap[t])}}class Zi{constructor(t){p(this,"buffer");p(this,"u8");this.buffer=t,this.u8=new Uint8Array(t)}getBit(t){var e=this.u8[t>>3],i=t&7;return(e&128>>i)>>7-i}setBit(t,e){var i=t>>3,s=this.u8[i],r=t&7;e?this.u8[i]=s|128>>r:this.u8[i]=s&~(128>>r)}getInt12(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],r=this.u8[e+2],n=t%8,a=8-n,o=Math.min(12-a,8),l=Math.max(12-a-o,0),c=~(255<<a),u=255<<8-o,f=255<<8-l;return i&=c,s&=u,r&=f,((i<<16)+(s<<8)+r>>12-n)-2048}setInt12(t,e){e+=2048;var i=t/8|0,s=t%8,r=e<<12-s,n=(r&16711680)>>16,a=(r&65280)>>8,o=r&255,l=8-s,c=Math.min(12-l,8),u=Math.max(12-l-c,0),f=255<<l;this.u8[i]=(this.u8[i]&f)+n;var m=~(255<<8-c);this.u8[i+1]=(this.u8[i+1]&m)+a;var g=~(255<<8-u);this.u8[i+2]=(this.u8[i+2]&g)+o}getInt6(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],r=t%8,n=8-r,a=Math.max(6-n,0),o=~((255<<n)+(255>>8-(2-r))),l=255<<8-a;return i&=o,s&=l,((i<<8)+s>>10-r)-32}setInt6(t,e){e+=32;var i=t/8|0,s=t%8,r=e<<10-s,n=(r&65280)>>8,a=r&255,o=8-s,l=Math.max(6-o,0),c=(255<<o)+(255>>8-(2-s));this.u8[i]=(this.u8[i]&c)+n;var u=~(255<<8-l);this.u8[i+1]=(this.u8[i+1]&u)+a}test(){var t=new ArrayBuffer(3),e=new Zi(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 ri=(h=>(h[h.NULL=0]="NULL",h[h.POINT=1]="POINT",h[h.POLYLINE=3]="POLYLINE",h[h.POLYGON=5]="POLYGON",h))(ri||{});class Hh{parse(t){var e={},i=new DataView(t),s=0;if(e.fileCode=i.getInt32(s,!1),e.fileCode!=9994)throw new Error("Unknown file code: "+e.fileCode);for(s+=24,e.wordLength=i.getInt32(s,!1),e.byteLength=e.wordLength*2,s+=4,e.version=i.getInt32(s,!0),s+=4,e.shapeType=i.getInt32(s,!0),s+=4,e.minX=i.getFloat64(s,!0),e.minY=i.getFloat64(s+8,!0),e.maxX=i.getFloat64(s+16,!0),e.maxY=i.getFloat64(s+24,!0),e.minZ=i.getFloat64(s+32,!0),e.maxZ=i.getFloat64(s+40,!0),e.minM=i.getFloat64(s+48,!0),e.maxM=i.getFloat64(s+56,!0),s+=64,e.records=[];s<e.byteLength;){var r={};r.number=i.getInt32(s,!1),s+=4,r.length=i.getInt32(s,!1),s+=4;try{r.shape=this.parseShape(i,s,r.length)}catch(n){console.log(n,r)}s+=r.length*2,e.records.push(r)}return e}parseShape(t,e,i){var s=0,r=null,n={};switch(n.type=t.getInt32(e,!0),e+=4,n.type){case 0:break;case 1:n.content={x:t.getFloat64(e,!0),y:t.getFloat64(e+8,!0)};break;case 3:case 5:for(r=n.content={minX:t.getFloat64(e,!0),minY:t.getFloat64(e+8,!0),maxX:t.getFloat64(e+16,!0),maxY:t.getFloat64(e+24,!0),parts:new Int32Array(t.getInt32(e+32,!0)),points:new Float64Array(t.getInt32(e+36,!0)*2)},e+=40,s=0;s<r.parts.length;s++)r.parts[s]=t.getInt32(e,!0),e+=4;for(s=0;s<r.points.length;s++)r.points[s]=t.getFloat64(e,!0),e+=8;break;case 8:case 11:case 13:case 15:case 18:case 21:case 23:case 25:case 28:case 31:throw new Error("Shape type not supported: "+n.type+":"+ +n.type);default:throw new Error("Unknown shape type at "+(e-4)+": "+n.type)}return n}}class Gh{constructor(){p(this,"LINE_MATERIAL");p(this,"MESH_MATERIAL");this.LINE_MATERIAL=new d.LineBasicMaterial({color:0,linewidth:2,opacity:.8,transparent:!0}),this.MESH_MATERIAL=new d.MeshBasicMaterial({color:1926655,opacity:.8,transparent:!0})}createModel(t){for(var e=[],i=[],s=0;s<t.records.length;s++){var r=t.records[s].shape;if(r.type===ri.POLYLINE||r.type===ri.POLYGON)for(var n=r.content.points,a=r.content.parts,o=0;o<a.length;o++){const g=[];for(var l=a[o],c=a[o+1]||n.length/2;l<c;l++){var u=n[l*2],f=n[l*2+1];g.push(new d.Vector3(u,f,0))}if(r.type===ri.POLYGON){const x=d.ShapeUtils.triangulateShape(g,[]),y=[];x.forEach(b=>y.push(...b));const T=new d.BufferGeometry;T.setFromPoints(g),T.setIndex(y),e.push(T);const v=new d.BufferGeometry;g.length>2&&!g[0].equals(g[g.length-1])&&g.push(g[0]),v.setFromPoints(g),i.push(v)}else{const x=new d.BufferGeometry;x.setFromPoints(g),i.push(x)}}}for(var m=new d.Object3D,s=0;s<i.length;s++)m.add(new d.Line(i[s],this.LINE_MATERIAL));for(var s=0;s<e.length;s++)m.add(new d.Mesh(e[s],this.MESH_MATERIAL));return console.log("parsed",e.length,i.length),m}loadCompressed(t){for(var e=this.deltaDecode6(t),i=[],s=[],r=0;r<e.length;r++){let u=[];if(e[r]===-32768){for(var n=[],a=1;a<u.length;a++)!(u[a-1].x==u[a].x&&u[a-1].y==u[a].y)&&n.push(u[a]);const f=new d.BufferGeometry;f.setFromPoints(n),i.push(f),u=[];continue}var o=e[r]*180/32767,l=e[r+1]*180/32767;r++,u.push(new d.Vector3(o,l,0))}for(var c=new d.Object3D,r=0;r<s.length;r++)c.add(new d.Line(s[r],this.LINE_MATERIAL));for(var r=0;r<i.length;r++)c.add(new d.Mesh(i[r],this.MESH_MATERIAL));return console.log("parsed compressed",i.length,s.length),c}compress(t){for(var e=[],i=0;i<t.records.length;i++){var s=t.records[i].shape;if(s.type===ri.POLYGON)for(var r=s.content.points,n=s.content.parts,a=0;a<n.length;a++){for(var o=n[a],l=n[a+1]||r.length/2;o<l;o++){var c=r[o*2],u=r[o*2+1];e.push(c/180*32767,u/180*32767)}e.push(-32768)}}var f=new Int16Array(e);console.log("16-bit quantized byteLength",f.buffer.byteLength);var m=this.deltaEncode6(f);return console.log("delta-encoded byteLength",m.byteLength),m}deltaEncode(t){for(var e=[],i=[],s=[],r=0,n=0,a=0,o=0;o<t.length;o++){if(t[o]==-32768){i.push(s),e.push(i),i=[],s=[],a+=3;continue}s.length==0?(r=t[o],n=t[o+1],s.push(r,n),a+=4,o++):Math.abs(r-t[o])>1023||Math.abs(n-t[o+1])>1023?(i.push(s),a+=1,s=[],r=t[o],n=t[o+1],s.push(r,n),a+=4,o++):(s.push((t[o]-r)/8,(t[o+1]-n)/8),r+=((t[o]-r)/8|0)*8,n+=((t[o+1]-n)/8|0)*8,a+=2,o++)}return this.storeDeltas(a,e)}deltaEncode6(t){var e=[],i=[],s=[],r=0,n=0,a=0,o=0;for(a=0;a<t.length;a++)t[a]=0|t[a]/16;for(a=0;a<t.length;a++){if(t[a]===-2048){i.push(s),e.push(i),i=[],s=[],o+=3;continue}s.length==0?(r=t[a],n=t[a+1],s.push(r,n),o+=4,a++):Math.abs(r-t[a])>31||Math.abs(n-t[a+1])>31?(i.push(s),o+=1,s=[],r=t[a],n=t[a+1],s.push(r,n),o+=4,a++):(s.push(t[a]-r,t[a+1]-n),r+=t[a]-r,n+=t[a+1]-n,o+=2,a++)}return this.storeDeltas6(o,e)}storeDeltas(t,e){for(var i=new ArrayBuffer(t),s=new DataView(i),r=0,n=0;n<e.length;n++){for(var a=e[n],o=0;o<a.length;o++){var l=a[o];s.setInt16(r,l[0]),r+=2,s.setInt16(r,l[1]),r+=2;for(var c=2;c<l.length;c++)s.setInt8(r++,l[c]);s.setInt8(r,-128),r+=1}s.setInt16(r,-32768),r+=2}return i}deltaDecode(t){for(var e=new DataView(t),i=0,s=[];i<t.byteLength;){var r=e.getInt16(i);if(i+=2,r===-32768){s.push(-32768);continue}var n=e.getInt16(i);for(i+=2,s.push(r,n);i<t.byteLength;){var a=e.getInt8(i);if(i++,a==-128)break;var o=e.getInt8(i);i++,r+=a*8,n+=o*8,s.push(r,n)}}return s}storeDeltas6(t,e){for(var i=new ArrayBuffer(Math.ceil(t*.75)+4),s=new Zi(i),r=32,n=0;n<e.length;n++){for(var a=e[n],o=0;o<a.length;o++){var l=a[o];s.setInt12(r,l[0]),r+=12,s.setInt12(r,l[1]),r+=12;for(var c=2;c<l.length;c++)s.setInt6(r,l[c]),r+=6;s.setInt6(r,-32),r+=6}s.setInt12(r,-2048),r+=12}return new DataView(i).setUint32(0,r),i}deltaDecode6(t){for(var e=new DataView(t).getUint32(0),i=new Zi(t),s=32,r=[];s<e;){var n=i.getInt12(s);if(s+=12,n===-2048){r.push(-2048);continue}var a=i.getInt12(s);for(s+=12,r.push(n,a);s<e;){var o=i.getInt6(s);if(s+=6,o===-32)break;var l=i.getInt6(s);s+=6,n+=o,a+=l,r.push(n,a)}}for(var c=0;c<r.length;c++)r[c]*=16;return r}}class qh{async load(t,e,i,s){this.updateProgress(i,0);const r=new XMLHttpRequest;r.responseType="arraybuffer",r.onload=()=>{this.updateProgress(i,50);const n=new Hh,a=n.parse(r.response),o=new Gh().createModel(a);this.updateProgress(i,100),e(o)},r.onerror=s,r.open("GET",t),r.send(null)}updateProgress(t,e){if(t){const i={lengthComputable:!0,loaded:e,total:100};t(new ProgressEvent("progress",i))}}}const ui=class ui{constructor(t){p(this,"gltfLoader");p(this,"font");p(this,"manager");this.manager=t}setLoadManager(t){this.manager=t}async loadLocalModel(t,e,i){const s=e.toLowerCase();return s.endsWith("fbx")?this.loadFbx(t,i):s.endsWith("obj")?this.loadObj(t,i):s.endsWith("stl")?this.loadStl(t,i):s.endsWith("ifc")?(S.warn("[LoadingHelper] IFC is not supported directly since three.js r150!"),Promise.reject("Not supported!")):s.endsWith("shp")?this.loadShp(t,i):s.endsWith("dae")?this.loadDae(t,i):s.endsWith("dxf")?this.loadDxf(t,i):s.endsWith("jpg")||s.endsWith("jpeg")||s.endsWith("png")?this.loadImage(t,i):this.loadGltf(t,i)}async loadModel(t,e,i){const s=t;if(!s)return Promise.resolve();let r=e?.toLowerCase()||"";if(!r){const n=s.split("?")[0].toLowerCase();if(n){const a=n.lastIndexOf(".");a!==-1&&(r=n.slice(a+1))}}if(r.endsWith("fbx"))return this.loadFbx(s,i);if(r.endsWith("obj"))return this.loadObj(s,i);if(r.endsWith("stl"))return this.loadStl(s,i);if(r.endsWith("ifc"))S.warn("[LoadingHelper] IFC is not supported directly since three.js r150!");else return r.endsWith("shp")?this.loadShp(s,i):r.endsWith("dae")?this.loadDae(s,i):r.endsWith("dxf")?this.loadDxf(s,i):r.endsWith("jpg")||r.endsWith("jpeg")||r.endsWith("png")?this.loadImage(s,i):this.loadGltf(s,i)}async loadGltf(t,e){const i=this.getGltfLoader();t.indexOf("#")!==-1&&console.warn("[LoadingHelper] '#' is not allowed in filename "+t),t=t.replace(/#/g,encodeURIComponent("#"));const s=n=>{n.total===0&&n.loaded>0||e&&e(n)},r=await i.loadAsync(t,s);return Promise.resolve(r.scene)}parseGltf(t,e,i,s){return this.getGltfLoader().parse(t,e,n=>i(n.scene),s)}async loadFbx(t,e){const i=new Ea.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new Aa.OBJLoader(this.manager),s=new Pa.MTLLoader(this.manager),r=t.replace(".obj",".mtl"),n=await s.loadAsync(r,e);n.preload(),i.setMaterials(n);const a=await i.loadAsync(t,e);return Promise.resolve(a)}async loadStl(t,e){const i=new ka.STLLoader(this.manager),s=await i.loadAsync(t,e),r=new d.MeshStandardMaterial({color:11184810,metalness:.1,roughness:.8}),n=new d.Mesh(s,r);return Promise.resolve(n)}async loadShp(t,e){const i=new qh;return new Promise((s,r)=>{i.load(t,n=>{s(n)},e,n=>{r(n)})})}async loadDae(t,e){const i=new Sa.ColladaLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s.scene)}async load3dm(t,e){return Promise.reject("3dm format is not supported since three.js r159 (Rhino3dmLoader removed)")}async loadDxf(t,e){this.font||console.warn("[LoadingHelper] Should set font first!");const i={ignorePaperSpace:!0,enableLocalCache:!1,overrideHatchPatternLineThickness:2},s=new Y(this.manager,i);s.setFont(this.font),await this.font?.getFontFromIndexeddb();try{const r=await s.loadAsync(t,e);return Promise.resolve(r.threejsObject)}catch{const n=new ErrorEvent("");return Promise.reject(n)}}async loadPly(t,e){const i=new Ia.PLYLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(new d.Mesh(s))}async loadImage(t,e){const i=new d.TextureLoader(this.manager),s=await i.loadAsync(t,e);if(!s)return Promise.reject("Failed to load image!");const r=10,n=s.image;let a=n&&n.height||r,o=n&&n.width||r;a=r/o*a,o=r;const l=new d.MeshBasicMaterial({map:s,side:d.DoubleSide,transparent:!0}),c=new d.PlaneGeometry(o,a),u=new d.Mesh(c,l);return Promise.resolve(u)}async loadDxfData(t,e,i,s,r){this.font||console.warn("[LoadingHelper] Should set font first!");const n=new Y(this.manager,r);return n.setFont(this.font),await this.font?.getFontFromIndexeddb(),n.manager.onLoad=()=>{s&&s()},n.loadEx(t,e,i)}setFont(t){this.font=t}static setDracoDecoderPath(t){this.DecoderPath=t}static setRhino3dmLibraryPath(t){this.Rhino3dmLibraryPath=t}getGltfLoader(){if(!this.gltfLoader){this.gltfLoader=new _a.GLTFLoader(this.manager);const t=new Oa.DRACOLoader(this.manager);t.setDecoderPath(ui.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};p(ui,"DecoderPath","libs/draco/gltf/"),p(ui,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let ut=ui;const Un=`(function(){"use strict";function Ks(f){for(let t=f.length-1;t>=0;--t)if(f[t]>=65535)return!0;return!1}function ms(f){return document.createElementNS("http://www.w3.org/1999/xhtml",f)}const ps={};function xs(f){const t=f[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=f[1];e&&e.isStackTrace?f[0]+=" "+e.getLocation():f[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return f}function yt(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...f)}}function Ut(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...f)}}function yi(...f){const t=f.join(" ");t in ps||(ps[t]=!0,yt(...f))}class Ve{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const s=i[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t);t.target=null}}}const $=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function Re(){const f=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return($[f&255]+$[f>>8&255]+$[f>>16&255]+$[f>>24&255]+"-"+$[t&255]+$[t>>8&255]+"-"+$[t>>16&15|64]+$[t>>24&255]+"-"+$[e&63|128]+$[e>>8&255]+"-"+$[e>>16&255]+$[e>>24&255]+$[i&255]+$[i>>8&255]+$[i>>16&255]+$[i>>24&255]).toLowerCase()}function V(f,t,e){return Math.max(t,Math.min(e,f))}function me(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return f/4294967295;case Uint16Array:return f/65535;case Uint8Array:case Uint8ClampedArray:return f/255;case Int32Array:return Math.max(f/2147483647,-1);case Int16Array:return Math.max(f/32767,-1);case Int8Array:return Math.max(f/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function K(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return Math.round(f*4294967295);case Uint16Array:return Math.round(f*65535);case Uint8Array:case Uint8ClampedArray:return Math.round(f*255);case Int32Array:return Math.round(f*2147483647);case Int16Array:return Math.round(f*32767);case Int8Array:return Math.round(f*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const hs=class hs{constructor(t=0,e=0){this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("THREE.Vector2: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};hs.prototype.isVector2=!0;let Y=hs;class pe{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],c=i[s+1],h=i[s+2],u=i[s+3],l=n[r+0],d=n[r+1],y=n[r+2],m=n[r+3];if(u!==m||o!==l||c!==d||h!==y){let z=o*l+c*d+h*y+u*m;z<0&&(l=-l,d=-d,y=-y,m=-m,z=-z);let b=1-a;if(z<.9995){const p=Math.acos(z),x=Math.sin(p);b=Math.sin(b*p)/x,a=Math.sin(a*p)/x,o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a}else{o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a;const p=1/Math.sqrt(o*o+c*c+h*h+u*u);o*=p,c*=p,h*=p,u*=p}}t[e]=o,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],c=i[s+2],h=i[s+3],u=n[r],l=n[r+1],d=n[r+2],y=n[r+3];return t[e]=a*y+h*u+o*d-c*l,t[e+1]=o*y+h*l+c*u-a*d,t[e+2]=c*y+h*d+a*l-o*u,t[e+3]=h*y-a*u-o*l-c*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,c=a(i/2),h=a(s/2),u=a(n/2),l=o(i/2),d=o(s/2),y=o(n/2);switch(r){case"XYZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"YXZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"ZXY":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"ZYX":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"YZX":this._x=l*h*u+c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u-l*d*y;break;case"XZY":this._x=l*h*u-c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u+l*d*y;break;default:yt("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],c=e[2],h=e[6],u=e[10],l=i+a+u;if(l>0){const d=.5/Math.sqrt(l+1);this._w=.25/d,this._x=(h-o)*d,this._y=(n-c)*d,this._z=(r-s)*d}else if(i>a&&i>u){const d=2*Math.sqrt(1+i-a-u);this._w=(h-o)/d,this._x=.25*d,this._y=(s+r)/d,this._z=(n+c)/d}else if(a>u){const d=2*Math.sqrt(1+a-i-u);this._w=(n-c)/d,this._x=(s+r)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+u-i-a);this._w=(r-s)/d,this._x=(n+c)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(V(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,c=e._z,h=e._w;return this._x=i*h+r*a+s*c-n*o,this._y=s*h+r*o+n*a-i*c,this._z=n*h+r*c+i*o-s*a,this._w=r*h-i*a-s*o-n*c,this._onChangeCallback(),this}slerp(t,e){let i=t._x,s=t._y,n=t._z,r=t._w,a=this.dot(t);a<0&&(i=-i,s=-s,n=-n,r=-r,a=-a);let o=1-e;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);o=Math.sin(o*c)/h,e=Math.sin(e*c)/h,this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this._onChangeCallback()}else this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}const ls=class ls{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("THREE.Vector3: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(gs.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(gs.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,c=2*(r*s-a*i),h=2*(a*e-n*s),u=2*(n*i-r*e);return this.x=e+o*c+r*u-a*h,this.y=i+o*h+a*c-n*u,this.z=s+o*u+n*h-r*c,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return mi.copy(this).projectOnVector(t),this.sub(mi)}reflect(t){return this.sub(mi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};ls.prototype.isVector3=!0;let S=ls;const mi=new S,gs=new pe,us=class us{constructor(t,e,i,s,n,r,a,o,c){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c)}set(t,e,i,s,n,r,a,o,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],c=i[1],h=i[4],u=i[7],l=i[2],d=i[5],y=i[8],m=s[0],z=s[3],b=s[6],p=s[1],x=s[4],g=s[7],w=s[2],B=s[5],_=s[8];return n[0]=r*m+a*p+o*w,n[3]=r*z+a*x+o*B,n[6]=r*b+a*g+o*_,n[1]=c*m+h*p+u*w,n[4]=c*z+h*x+u*B,n[7]=c*b+h*g+u*_,n[2]=l*m+d*p+y*w,n[5]=l*z+d*x+y*B,n[8]=l*b+d*g+y*_,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8];return e*r*h-e*a*c-i*n*h+i*a*o+s*n*c-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=h*r-a*c,l=a*o-h*n,d=c*n-r*o,y=e*u+i*l+s*d;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/y;return t[0]=u*m,t[1]=(s*c-h*i)*m,t[2]=(a*i-s*r)*m,t[3]=l*m,t[4]=(h*e-s*o)*m,t[5]=(s*n-a*e)*m,t[6]=d*m,t[7]=(i*o-c*e)*m,t[8]=(r*e-i*n)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const o=Math.cos(n),c=Math.sin(n);return this.set(i*o,i*c,-i*(o*r+c*a)+r+t,-s*c,s*o,-s*(-c*r+o*a)+a+e,0,0,1),this}scale(t,e){return yi("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(pi.makeScale(t,e)),this}rotate(t){return yi("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(pi.makeRotation(-t)),this}translate(t,e){return yi("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(pi.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}};us.prototype.isMatrix3=!0;let xt=us;const pi=new xt;function xi(f){return f<.04045?f*.0773993808:Math.pow(f*.9478672986+.0521327014,2.4)}let Zt;class tn{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{Zt===void 0&&(Zt=ms("canvas")),Zt.width=t.width,Zt.height=t.height;const s=Zt.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),i=Zt}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=ms("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r<n.length;r++)n[r]=xi(n[r]/255)*255;return i.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(xi(e[i]/255)*255):e[i]=xi(e[i]);return{data:e,width:t.width,height:t.height}}else return yt("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let en=0;class sn{constructor(t=null){this.isTextureSource=!0,Object.defineProperty(this,"id",{value:en++}),this.uuid=Re(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let n;if(Array.isArray(s)){n=[];for(let r=0,a=s.length;r<a;r++)s[r].isDataTexture?n.push(gi(s[r].image)):n.push(gi(s[r]))}else n=gi(s);i.url=n}return e||(t.images[this.uuid]=i),i}}function gi(f){return typeof HTMLImageElement<"u"&&f instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&f instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&f instanceof ImageBitmap?tn.getDataURL(f):f.data?{data:Array.from(f.data),width:f.width,height:f.height,type:f.data.constructor.name}:(yt("Texture: Unable to serialize Texture."),{})}let nn=0;const wi=new S;class Nt extends Ve{constructor(t=Nt.DEFAULT_IMAGE,e=Nt.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,c=Nt.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:nn++}),this.uuid=Re(),this.name="",this.source=new sn(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=o,this.offset=new Y(0,0),this.repeat=new Y(1,1),this.center=new Y(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new xt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(wi).x}get height(){return this.source.getSize(wi).y}get depth(){return this.source.getSize(wi).z}get image(){return this.source.data}set image(t){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.normalized=t.normalized,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){yt(\`Texture.setValues(): parameter '\${e}' has value of undefined.\`);continue}const s=this[e];if(s===void 0){yt(\`Texture.setValues(): property '\${e}' does not exist.\`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Nt.DEFAULT_IMAGE=null,Nt.DEFAULT_MAPPING=300,Nt.DEFAULT_ANISOTROPY=1;const fs=class fs{constructor(t=0,e=0,i=0,s=1){this.x=t,this.y=e,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("THREE.Vector4: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,s,n;const o=t.elements,c=o[0],h=o[4],u=o[8],l=o[1],d=o[5],y=o[9],m=o[2],z=o[6],b=o[10];if(Math.abs(h-l)<.01&&Math.abs(u-m)<.01&&Math.abs(y-z)<.01){if(Math.abs(h+l)<.1&&Math.abs(u+m)<.1&&Math.abs(y+z)<.1&&Math.abs(c+d+b-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,g=(d+1)/2,w=(b+1)/2,B=(h+l)/4,_=(u+m)/4,M=(y+z)/4;return x>g&&x>w?x<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(x),s=B/i,n=_/i):g>w?g<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(g),i=B/s,n=M/s):w<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(w),i=_/n,s=M/n),this.set(i,s,n,e),this}let p=Math.sqrt((z-y)*(z-y)+(u-m)*(u-m)+(l-h)*(l-h));return Math.abs(p)<.001&&(p=1),this.x=(z-y)/p,this.y=(u-m)/p,this.z=(l-h)/p,this.w=Math.acos((c+d+b-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this.w=V(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this.w=V(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};fs.prototype.isVector4=!0;let xe=fs;const ui=class ui{constructor(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z)}set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){const b=this.elements;return b[0]=t,b[4]=e,b[8]=i,b[12]=s,b[1]=n,b[5]=r,b[9]=a,b[13]=o,b[2]=c,b[6]=h,b[10]=u,b[14]=l,b[3]=d,b[7]=y,b[11]=m,b[15]=z,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new ui().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,s=1/$t.setFromMatrixColumn(t,0).length(),n=1/$t.setFromMatrixColumn(t,1).length(),r=1/$t.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),c=Math.sin(s),h=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=-o*u,e[8]=c,e[1]=d+y*c,e[5]=l-m*c,e[9]=-a*o,e[2]=m-l*c,e[6]=y+d*c,e[10]=r*o}else if(t.order==="YXZ"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l+m*a,e[4]=y*a-d,e[8]=r*c,e[1]=r*u,e[5]=r*h,e[9]=-a,e[2]=d*a-y,e[6]=m+l*a,e[10]=r*o}else if(t.order==="ZXY"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l-m*a,e[4]=-r*u,e[8]=y+d*a,e[1]=d+y*a,e[5]=r*h,e[9]=m-l*a,e[2]=-r*c,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=y*c-d,e[8]=l*c+m,e[1]=o*u,e[5]=m*c+l,e[9]=d*c-y,e[2]=-c,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=m-l*u,e[8]=y*u+d,e[1]=u,e[5]=r*h,e[9]=-a*h,e[2]=-c*h,e[6]=d*u+y,e[10]=l-m*u}else if(t.order==="XZY"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=-u,e[8]=c*h,e[1]=l*u+m,e[5]=r*h,e[9]=d*u-y,e[2]=y*u-d,e[6]=a*h,e[10]=m*u+l}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(rn,t,on)}lookAt(t,e,i){const s=this.elements;return et.subVectors(t,e),et.lengthSq()===0&&(et.z=1),et.normalize(),Pt.crossVectors(i,et),Pt.lengthSq()===0&&(Math.abs(i.z)===1?et.x+=1e-4:et.z+=1e-4,et.normalize(),Pt.crossVectors(i,et)),Pt.normalize(),ke.crossVectors(et,Pt),s[0]=Pt.x,s[4]=ke.x,s[8]=et.x,s[1]=Pt.y,s[5]=ke.y,s[9]=et.y,s[2]=Pt.z,s[6]=ke.z,s[10]=et.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],c=i[12],h=i[1],u=i[5],l=i[9],d=i[13],y=i[2],m=i[6],z=i[10],b=i[14],p=i[3],x=i[7],g=i[11],w=i[15],B=s[0],_=s[4],M=s[8],P=s[12],A=s[1],C=s[5],T=s[9],E=s[13],I=s[2],F=s[6],R=s[10],Z=s[14],tt=s[3],dt=s[7],at=s[11],pt=s[15];return n[0]=r*B+a*A+o*I+c*tt,n[4]=r*_+a*C+o*F+c*dt,n[8]=r*M+a*T+o*R+c*at,n[12]=r*P+a*E+o*Z+c*pt,n[1]=h*B+u*A+l*I+d*tt,n[5]=h*_+u*C+l*F+d*dt,n[9]=h*M+u*T+l*R+d*at,n[13]=h*P+u*E+l*Z+d*pt,n[2]=y*B+m*A+z*I+b*tt,n[6]=y*_+m*C+z*F+b*dt,n[10]=y*M+m*T+z*R+b*at,n[14]=y*P+m*E+z*Z+b*pt,n[3]=p*B+x*A+g*I+w*tt,n[7]=p*_+x*C+g*F+w*dt,n[11]=p*M+x*T+g*R+w*at,n[15]=p*P+x*E+g*Z+w*pt,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],c=t[13],h=t[2],u=t[6],l=t[10],d=t[14],y=t[3],m=t[7],z=t[11],b=t[15],p=o*d-c*l,x=a*d-c*u,g=a*l-o*u,w=r*d-c*h,B=r*l-o*h,_=r*u-a*h;return e*(m*p-z*x+b*g)-i*(y*p-z*w+b*B)+s*(y*x-m*w+b*_)-n*(y*g-m*B+z*_)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[1],r=t[5],a=t[9],o=t[2],c=t[6],h=t[10];return e*(r*h-a*c)-i*(n*h-a*o)+s*(n*c-r*o)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=t[9],l=t[10],d=t[11],y=t[12],m=t[13],z=t[14],b=t[15],p=e*a-i*r,x=e*o-s*r,g=e*c-n*r,w=i*o-s*a,B=i*c-n*a,_=s*c-n*o,M=h*m-u*y,P=h*z-l*y,A=h*b-d*y,C=u*z-l*m,T=u*b-d*m,E=l*b-d*z,I=p*E-x*T+g*C+w*A-B*P+_*M;if(I===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const F=1/I;return t[0]=(a*E-o*T+c*C)*F,t[1]=(s*T-i*E-n*C)*F,t[2]=(m*_-z*B+b*w)*F,t[3]=(l*B-u*_-d*w)*F,t[4]=(o*A-r*E-c*P)*F,t[5]=(e*E-s*A+n*P)*F,t[6]=(z*g-y*_-b*x)*F,t[7]=(h*_-l*g+d*x)*F,t[8]=(r*T-a*A+c*M)*F,t[9]=(i*A-e*T-n*M)*F,t[10]=(y*B-m*g+b*p)*F,t[11]=(u*g-h*B-d*p)*F,t[12]=(a*P-r*C-o*M)*F,t[13]=(e*C-i*P+s*M)*F,t[14]=(m*x-y*w-z*p)*F,t[15]=(h*w-u*x+l*p)*F,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,c=n*r,h=n*a;return this.set(c*r+i,c*a-s*o,c*o+s*a,0,c*a+s*o,h*a+i,h*o-s*r,0,c*o-s*a,h*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,c=n+n,h=r+r,u=a+a,l=n*c,d=n*h,y=n*u,m=r*h,z=r*u,b=a*u,p=o*c,x=o*h,g=o*u,w=i.x,B=i.y,_=i.z;return s[0]=(1-(m+b))*w,s[1]=(d+g)*w,s[2]=(y-x)*w,s[3]=0,s[4]=(d-g)*B,s[5]=(1-(l+b))*B,s[6]=(z+p)*B,s[7]=0,s[8]=(y+x)*_,s[9]=(z-p)*_,s[10]=(1-(l+m))*_,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;t.x=s[12],t.y=s[13],t.z=s[14];const n=this.determinantAffine();if(n===0)return i.set(1,1,1),e.identity(),this;let r=$t.set(s[0],s[1],s[2]).length();const a=$t.set(s[4],s[5],s[6]).length(),o=$t.set(s[8],s[9],s[10]).length();n<0&&(r=-r),ct.copy(this);const c=1/r,h=1/a,u=1/o;return ct.elements[0]*=c,ct.elements[1]*=c,ct.elements[2]*=c,ct.elements[4]*=h,ct.elements[5]*=h,ct.elements[6]*=h,ct.elements[8]*=u,ct.elements[9]*=u,ct.elements[10]*=u,e.setFromRotationMatrix(ct),i.x=r,i.y=a,i.z=o,this}makePerspective(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2*n/(e-t),u=2*n/(i-s),l=(e+t)/(e-t),d=(i+s)/(i-s);let y,m;if(o)y=n/(r-n),m=r*n/(r-n);else if(a===2e3)y=-(r+n)/(r-n),m=-2*r*n/(r-n);else if(a===2001)y=-r/(r-n),m=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=u,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2/(e-t),u=2/(i-s),l=-(e+t)/(e-t),d=-(i+s)/(i-s);let y,m;if(o)y=1/(r-n),m=r/(r-n);else if(a===2e3)y=-2/(r-n),m=-(r+n)/(r-n);else if(a===2001)y=-1/(r-n),m=-n/(r-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=l,c[1]=0,c[5]=u,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}};ui.prototype.isMatrix4=!0;let H=ui;const $t=new S,ct=new H,rn=new S(0,0,0),on=new S(1,1,1),Pt=new S,ke=new S,et=new S,ws=new H,bs=new pe;class Ue{constructor(t=0,e=0,i=0,s=Ue.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],c=s[5],h=s[9],u=s[2],l=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(V(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(l,c),this._z=0);break;case"YXZ":this._x=Math.asin(-V(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,c)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(V(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-V(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(l,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(V(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-V(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(l,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,d),this._y=0);break;default:yt("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return ws.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ws,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return bs.setFromEuler(this),this.setFromQuaternion(bs,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ue.DEFAULT_ORDER="XYZ";class an{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let cn=0;const zs=new S,Jt=new pe,gt=new H,Ne=new S,ge=new S,hn=new S,ln=new pe,_s=new S(1,0,0),Ms=new S(0,1,0),As=new S(0,0,1),Ss={type:"added"},un={type:"removed"},Gt={type:"childadded",child:null},bi={type:"childremoved",child:null};class Ct extends Ve{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:cn++}),this.uuid=Re(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ct.DEFAULT_UP.clone();const t=new S,e=new Ue,i=new pe,s=new S(1,1,1);function n(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(n),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new H},normalMatrix:{value:new xt}}),this.matrix=new H,this.matrixWorld=new H,this.matrixAutoUpdate=Ct.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new an,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.multiply(Jt),this}rotateOnWorldAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.premultiply(Jt),this}rotateX(t){return this.rotateOnAxis(_s,t)}rotateY(t){return this.rotateOnAxis(Ms,t)}rotateZ(t){return this.rotateOnAxis(As,t)}translateOnAxis(t,e){return zs.copy(t).applyQuaternion(this.quaternion),this.position.add(zs.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(_s,t)}translateY(t){return this.translateOnAxis(Ms,t)}translateZ(t){return this.translateOnAxis(As,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(gt.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ne.copy(t):Ne.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),ge.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?gt.lookAt(ge,Ne,this.up):gt.lookAt(Ne,ge,this.up),this.quaternion.setFromRotationMatrix(gt),s&&(gt.extractRotation(s.matrixWorld),Jt.setFromRotationMatrix(gt),this.quaternion.premultiply(Jt.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Ut("Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.child=null):Ut("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(un),bi.child=t,this.dispatchEvent(bi),bi.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),gt.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),gt.multiply(t.parent.matrixWorld)),t.applyMatrix4(gt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,s=this.children.length;i<s;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,t,hn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,ln,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}intersectsFrustum(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,s=t.z,n=this.matrix.elements;n[12]+=e-n[0]*e-n[4]*i-n[8]*s,n[13]+=i-n[1]*e-n[5]*i-n[9]*s,n[14]+=s-n[2]*e-n[6]*i-n[10]*s}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const s=this.parent;if(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),e===!0){const n=this.children;for(let r=0,a=n.length;r<a;r++)n[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,s.name=this.name,s.castShadow=this.castShadow,s.receiveShadow=this.receiveShadow,s.visible=this.visible,s.frustumCulled=this.frustumCulled,s.renderOrder=this.renderOrder,s.static=this.static,s.matrixAutoUpdate=this.matrixAutoUpdate,Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(a=>({...a})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(t),s.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let c=0,h=o.length;c<h;c++){const u=o[c];n(t.shapes,u)}else n(t.shapes,o)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let o=0,c=this.material.length;o<c;o++)a.push(n(t.materials,this.material[o]));s.material=a}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let a=0;a<this.children.length;a++)s.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let a=0;a<this.animations.length;a++){const o=this.animations[a];s.animations.push(n(t.animations,o))}}if(e){const a=r(t.geometries),o=r(t.materials),c=r(t.textures),h=r(t.images),u=r(t.shapes),l=r(t.skeletons),d=r(t.animations),y=r(t.nodes);a.length>0&&(i.geometries=a),o.length>0&&(i.materials=o),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),l.length>0&&(i.skeletons=l),d.length>0&&(i.animations=d),y.length>0&&(i.nodes=y)}return i.object=s,i;function r(a){const o=[];for(const c in a){const h=a[c];delete h.metadata,o.push(h)}return o}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.pivot=t.pivot!==null?t.pivot.clone():null,this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}dispose(){this.dispatchEvent({type:"dispose"})}}Ct.DEFAULT_UP=new S(0,1,0),Ct.DEFAULT_MATRIX_AUTO_UPDATE=!0,Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ht=new S,wt=new S,zi=new S,bt=new S,Qt=new S,jt=new S,Bs=new S,_i=new S,Mi=new S,Ai=new S,Si=new xe,Bi=new xe,Ti=new xe;class st{constructor(t=new S,e=new S,i=new S){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),ht.subVectors(t,e),s.cross(ht);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){ht.subVectors(s,e),wt.subVectors(i,e),zi.subVectors(t,e);const r=ht.dot(ht),a=ht.dot(wt),o=ht.dot(zi),c=wt.dot(wt),h=wt.dot(zi),u=r*c-a*a;if(u===0)return n.set(0,0,0),null;const l=1/u,d=(c*o-a*h)*l,y=(r*h-a*o)*l;return n.set(1-d-y,y,d)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,bt)===null?!1:bt.x>=0&&bt.y>=0&&bt.x+bt.y<=1}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,bt)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,bt.x),o.addScaledVector(r,bt.y),o.addScaledVector(a,bt.z),o)}static getInterpolatedAttribute(t,e,i,s,n,r){return Si.setScalar(0),Bi.setScalar(0),Ti.setScalar(0),Si.fromBufferAttribute(t,e),Bi.fromBufferAttribute(t,i),Ti.fromBufferAttribute(t,s),r.setScalar(0),r.addScaledVector(Si,n.x),r.addScaledVector(Bi,n.y),r.addScaledVector(Ti,n.z),r}static isFrontFacing(t,e,i,s){return ht.subVectors(i,e),wt.subVectors(t,e),ht.cross(wt).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return ht.subVectors(this.c,this.b),wt.subVectors(this.a,this.b),ht.cross(wt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return st.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return st.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,s,n){return st.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return st.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return st.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;Qt.subVectors(s,i),jt.subVectors(n,i),_i.subVectors(t,i);const o=Qt.dot(_i),c=jt.dot(_i);if(o<=0&&c<=0)return e.copy(i);Mi.subVectors(t,s);const h=Qt.dot(Mi),u=jt.dot(Mi);if(h>=0&&u<=h)return e.copy(s);const l=o*u-h*c;if(l<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(Qt,r);Ai.subVectors(t,n);const d=Qt.dot(Ai),y=jt.dot(Ai);if(y>=0&&d<=y)return e.copy(n);const m=d*c-o*y;if(m<=0&&c>=0&&y<=0)return a=c/(c-y),e.copy(i).addScaledVector(jt,a);const z=h*y-d*u;if(z<=0&&u-h>=0&&d-y>=0)return Bs.subVectors(n,s),a=(u-h)/(u-h+(d-y)),e.copy(s).addScaledVector(Bs,a);const b=1/(z+m+l);return r=m*b,a=l*b,e.copy(i).addScaledVector(Qt,r).addScaledVector(jt,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Q{constructor(t=new S(1/0,1/0,1/0),e=new S(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(lt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(lt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=lt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const i=t.geometry;if(i!==void 0){const n=i.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,lt):lt.fromBufferAttribute(n,r),lt.applyMatrix4(t.matrixWorld),this.expandByPoint(lt);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Le.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Le.copy(i.boundingBox)),Le.applyMatrix4(t.matrixWorld),this.union(Le)}const s=t.children;for(let n=0,r=s.length;n<r;n++)this.expandByObject(s[n],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,lt),lt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(we),De.subVectors(this.max,we),Kt.subVectors(t.a,we),te.subVectors(t.b,we),ee.subVectors(t.c,we),Et.subVectors(te,Kt),It.subVectors(ee,te),Lt.subVectors(Kt,ee);let e=[0,-Et.z,Et.y,0,-It.z,It.y,0,-Lt.z,Lt.y,Et.z,0,-Et.x,It.z,0,-It.x,Lt.z,0,-Lt.x,-Et.y,Et.x,0,-It.y,It.x,0,-Lt.y,Lt.x,0];return!Pi(e,Kt,te,ee,De)||(e=[1,0,0,0,1,0,0,0,1],!Pi(e,Kt,te,ee,De))?!1:(qe.crossVectors(Et,It),e=[qe.x,qe.y,qe.z],Pi(e,Kt,te,ee,De))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,lt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(lt).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(zt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),zt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),zt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),zt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),zt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),zt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),zt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),zt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(zt),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const zt=[new S,new S,new S,new S,new S,new S,new S,new S],lt=new S,Le=new Q,Kt=new S,te=new S,ee=new S,Et=new S,It=new S,Lt=new S,we=new S,De=new S,qe=new S,Dt=new S;function Pi(f,t,e,i,s){for(let n=0,r=f.length-3;n<=r;n+=3){Dt.fromArray(f,n);const a=s.x*Math.abs(Dt.x)+s.y*Math.abs(Dt.y)+s.z*Math.abs(Dt.z),o=t.dot(Dt),c=e.dot(Dt),h=i.dot(Dt);if(Math.max(-Math.max(o,c,h),Math.min(o,c,h))>a)return!1}return!0}const L=new S,ve=new Y;let fn=0;class mt extends Ve{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:fn++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)ve.fromBufferAttribute(this,e),ve.applyMatrix3(t),this.setXY(e,ve.x,ve.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix3(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix4(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyNormalMatrix(t),this.setXYZ(e,L.x,L.y,L.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.transformDirection(t),this.setXYZ(e,L.x,L.y,L.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=me(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=K(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=me(e,this.array)),e}setX(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=me(e,this.array)),e}setY(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=me(e,this.array)),e}setZ(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=me(e,this.array)),e}setW(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array),n=K(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return t.name=this.name,t.usage=this.usage,t.gpuType=this.gpuType,t}dispose(){this.dispatchEvent({type:"dispose"})}}class dn extends mt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class yn extends mt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class mn extends mt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const pn=new Q,be=new S,Ci=new S;class xn{constructor(t=new S,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;e!==void 0?i.copy(e):pn.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;n<r;n++)s=Math.max(s,i.distanceToSquared(t[n]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;be.subVectors(t,this.center);const e=be.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(be,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Ci.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(be.copy(t.center).add(Ci)),this.expandByPoint(be.copy(t.center).sub(Ci))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let gn=0;const nt=new H,Ei=new Ct,ie=new S,it=new Q,ze=new Q,W=new S;class Ii extends Ve{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:gn++}),this.uuid=Re(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Ks(t)?yn:dn)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const n=new xt().getNormalMatrix(t);i.applyNormalMatrix(n),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return nt.makeRotationFromQuaternion(t),this.applyMatrix4(nt),this}rotateX(t){return nt.makeRotationX(t),this.applyMatrix4(nt),this}rotateY(t){return nt.makeRotationY(t),this.applyMatrix4(nt),this}rotateZ(t){return nt.makeRotationZ(t),this.applyMatrix4(nt),this}translate(t,e,i){return nt.makeTranslation(t,e,i),this.applyMatrix4(nt),this}scale(t,e,i){return nt.makeScale(t,e,i),this.applyMatrix4(nt),this}lookAt(t){return Ei.lookAt(t),Ei.updateMatrix(),this.applyMatrix4(Ei.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ie).negate(),this.translate(ie.x,ie.y,ie.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let s=0,n=t.length;s<n;s++){const r=t[s];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new mn(i,3))}else{const i=Math.min(t.length,e.count);for(let s=0;s<i;s++){const n=t[s];e.setXYZ(s,n.x,n.y,n.z||0)}t.length>e.count&&yt("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Q);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new S(-1/0,-1/0,-1/0),new S(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i<s;i++){const n=e[i];it.setFromBufferAttribute(n),this.morphTargetsRelative?(W.addVectors(this.boundingBox.min,it.min),this.boundingBox.expandByPoint(W),W.addVectors(this.boundingBox.max,it.max),this.boundingBox.expandByPoint(W)):(this.boundingBox.expandByPoint(it.min),this.boundingBox.expandByPoint(it.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ut('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new xn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new S,1/0);return}if(t){const i=this.boundingSphere.center;if(it.setFromBufferAttribute(t),e)for(let n=0,r=e.length;n<r;n++){const a=e[n];ze.setFromBufferAttribute(a),this.morphTargetsRelative?(W.addVectors(it.min,ze.min),it.expandByPoint(W),W.addVectors(it.max,ze.max),it.expandByPoint(W)):(it.expandByPoint(ze.min),it.expandByPoint(ze.max))}it.getCenter(i);let s=0;for(let n=0,r=t.count;n<r;n++)W.fromBufferAttribute(t,n),s=Math.max(s,i.distanceToSquared(W));if(e)for(let n=0,r=e.length;n<r;n++){const a=e[n],o=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)W.fromBufferAttribute(a,c),o&&(ie.fromBufferAttribute(t,c),W.add(ie)),s=Math.max(s,i.distanceToSquared(W))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&Ut('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Ut("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,s=e.normal,n=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new mt(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const a=[],o=[];for(let M=0;M<i.count;M++)a[M]=new S,o[M]=new S;const c=new S,h=new S,u=new S,l=new Y,d=new Y,y=new Y,m=new S,z=new S;function b(M,P,A){c.fromBufferAttribute(i,M),h.fromBufferAttribute(i,P),u.fromBufferAttribute(i,A),l.fromBufferAttribute(n,M),d.fromBufferAttribute(n,P),y.fromBufferAttribute(n,A),h.sub(c),u.sub(c),d.sub(l),y.sub(l);const C=1/(d.x*y.y-y.x*d.y);isFinite(C)&&(m.copy(h).multiplyScalar(y.y).addScaledVector(u,-d.y).multiplyScalar(C),z.copy(u).multiplyScalar(d.x).addScaledVector(h,-y.x).multiplyScalar(C),a[M].add(m),a[P].add(m),a[A].add(m),o[M].add(z),o[P].add(z),o[A].add(z))}let p=this.groups;p.length===0&&(p=[{start:0,count:t.count}]);for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)b(t.getX(E+0),t.getX(E+1),t.getX(E+2))}const x=new S,g=new S,w=new S,B=new S;function _(M){w.fromBufferAttribute(s,M),B.copy(w);const P=a[M];x.copy(P),x.sub(w.multiplyScalar(w.dot(P))).normalize(),g.crossVectors(B,P);const C=g.dot(o[M])<0?-1:1;r.setXYZW(M,x.x,x.y,x.z,C)}for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)_(t.getX(E+0)),_(t.getX(E+1)),_(t.getX(E+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new mt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let l=0,d=i.count;l<d;l++)i.setXYZ(l,0,0,0);const s=new S,n=new S,r=new S,a=new S,o=new S,c=new S,h=new S,u=new S;if(t)for(let l=0,d=t.count;l<d;l+=3){const y=t.getX(l+0),m=t.getX(l+1),z=t.getX(l+2);s.fromBufferAttribute(e,y),n.fromBufferAttribute(e,m),r.fromBufferAttribute(e,z),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),a.fromBufferAttribute(i,y),o.fromBufferAttribute(i,m),c.fromBufferAttribute(i,z),a.add(h),o.add(h),c.add(h),i.setXYZ(y,a.x,a.y,a.z),i.setXYZ(m,o.x,o.y,o.z),i.setXYZ(z,c.x,c.y,c.z)}else for(let l=0,d=e.count;l<d;l+=3)s.fromBufferAttribute(e,l+0),n.fromBufferAttribute(e,l+1),r.fromBufferAttribute(e,l+2),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),i.setXYZ(l+0,h.x,h.y,h.z),i.setXYZ(l+1,h.x,h.y,h.z),i.setXYZ(l+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)W.fromBufferAttribute(t,e),W.normalize(),t.setXYZ(e,W.x,W.y,W.z)}toNonIndexed(){function t(a,o){const c=a.array,h=a.itemSize,u=a.normalized,l=new c.constructor(o.length*h);let d=0,y=0;for(let m=0,z=o.length;m<z;m++){a.isInterleavedBufferAttribute?d=o[m]*a.data.stride+a.offset:d=o[m]*h;for(let b=0;b<h;b++)l[y++]=c[d++]}return new mt(l,h,u)}if(this.index===null)return yt("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Ii,i=this.index.array,s=this.attributes;for(const a in s){const o=s[a],c=t(o,i);e.setAttribute(a,c)}const n=this.morphAttributes;for(const a in n){const o=[],c=n[a];for(let h=0,u=c.length;h<u;h++){const l=c[h],d=t(l,i);o.push(d)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,o=r.length;a<o;a++){const c=r[a];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,t.name=this.name,Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const o=this.parameters;for(const c in o)o[c]!==void 0&&(t[c]=o[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const c=i[o];t.data.attributes[o]=c.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const c=this.morphAttributes[o],h=[];for(let u=0,l=c.length;u<l;u++){const d=c[u];h.push(d.toJSON(t.data))}h.length>0&&(s[o]=h,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone());const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const n=t.morphAttributes;for(const c in n){const h=[],u=n[c];for(let l=0,d=u.length;l<d;l++)h.push(u[l].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let c=0,h=r.length;c<h;c++){const u=r[c];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Fi=new S,wn=new S,bn=new xt;class Ts{constructor(t=new S(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=Fi.subVectors(i,e).cross(wn.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e,i=!0){const s=t.delta(Fi),n=this.normal.dot(s);if(n===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/n;return i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||bn.getNormalMatrix(t),s=this.coplanarPoint(Fi).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}toJSON(){return{normal:this.normal.toArray(),constant:this.constant}}fromJSON(t){return this.normal.fromArray(t.normal),this.constant=t.constant,this}}const _t=new S,Vi=new S,Oe=new S,We=new S;class zn{constructor(t=new S,e=new S(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,_t)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=_t.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(_t.copy(this.origin).addScaledVector(this.direction,e),_t.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){Vi.copy(t).add(e).multiplyScalar(.5),Oe.copy(e).sub(t).normalize(),We.copy(this.origin).sub(Vi);const n=t.distanceTo(e)*.5,r=-this.direction.dot(Oe),a=We.dot(this.direction),o=-We.dot(Oe),c=We.lengthSq(),h=Math.abs(1-r*r);let u,l,d,y;if(h>0)if(u=r*o-a,l=r*a-o,y=n*h,u>=0)if(l>=-y)if(l<=y){const m=1/h;u*=m,l*=m,d=u*(u+r*l+2*a)+l*(r*u+l+2*o)+c}else l=n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l=-n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l<=-y?(u=Math.max(0,-(-r*n+a)),l=u>0?-n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c):l<=y?(u=0,l=Math.min(Math.max(-n,-o),n),d=l*(l+2*o)+c):(u=Math.max(0,-(r*n+a)),l=u>0?n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c);else l=r>0?-n:n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(Vi).addScaledVector(Oe,l),d}intersectSphere(t,e){if(t.radius<0)return null;_t.subVectors(t.center,this.origin);const i=_t.dot(this.direction),s=_t.dot(_t)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,s,n,r,a,o;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,l=this.origin;return c>=0?(i=(t.min.x-l.x)*c,s=(t.max.x-l.x)*c):(i=(t.max.x-l.x)*c,s=(t.min.x-l.x)*c),h>=0?(n=(t.min.y-l.y)*h,r=(t.max.y-l.y)*h):(n=(t.max.y-l.y)*h,r=(t.min.y-l.y)*h),i>r||n>s||((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),u>=0?(a=(t.min.z-l.z)*u,o=(t.max.z-l.z)*u):(a=(t.max.z-l.z)*u,o=(t.min.z-l.z)*u),i>o||a>s)||((a>i||i!==i)&&(i=a),(o<s||s!==s)&&(s=o),s<0)?null:this.at(i>=0?i:s,e)}intersectsBox(t){return this.intersectBox(t,_t)!==null}intersectTriangle(t,e,i,s,n){const r=this.origin,a=this.direction,o=a.x,c=a.y,h=a.z,u=t.x-r.x,l=t.y-r.y,d=t.z-r.z,y=e.x-r.x,m=e.y-r.y,z=e.z-r.z,b=i.x-r.x,p=i.y-r.y,x=i.z-r.z,g=Math.abs(o),w=Math.abs(c),B=Math.abs(h);let _,M,P,A,C,T,E,I,F,R,Z,tt;if(g>=w&&g>=B?(P=o,T=u,F=y,tt=b,o>=0?(_=c,M=h,A=l,C=d,E=m,I=z,R=p,Z=x):(_=h,M=c,A=d,C=l,E=z,I=m,R=x,Z=p)):w>=B?(P=c,T=l,F=m,tt=p,c>=0?(_=h,M=o,A=d,C=u,E=z,I=y,R=x,Z=b):(_=o,M=h,A=u,C=d,E=y,I=z,R=b,Z=x)):(P=h,T=d,F=z,tt=x,h>=0?(_=o,M=c,A=u,C=l,E=y,I=m,R=b,Z=p):(_=c,M=o,A=l,C=u,E=m,I=y,R=p,Z=b)),P===0)return null;const dt=_/P,at=M/P,pt=1/P,ye=A-dt*T,Ie=C-at*T,ys=E-dt*F,Tt=I-at*F,fi=R-dt*tt,di=Z-at*tt,Wt=fi*Tt-di*ys,Xt=ye*di-Ie*fi,Yt=ys*Ie-Tt*ye;if(s){if(Wt<0||Xt<0||Yt<0)return null}else if((Wt<0||Xt<0||Yt<0)&&(Wt>0||Xt>0||Yt>0))return null;const Fe=Wt+Xt+Yt;if(Fe===0)return null;const Ht=pt*(Wt*T+Xt*F+Yt*tt);return(Fe>0?Ht<0:Ht>0)?null:this.at(Ht/Fe,n)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}const ds=class ds{constructor(t,e,i,s){this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,i,s)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let i=0;i<4;i++)this.elements[i]=t[i+e];return this}set(t,e,i,s){const n=this.elements;return n[0]=t,n[2]=e,n[1]=i,n[3]=s,this}};ds.prototype.isMatrix2=!0;let Ps=ds;const Cs=new S,Xe=new S,se=new S,ne=new S,Ri=new S,_n=new S,Mn=new S;class Mt{constructor(t=new S,e=new S){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){Cs.subVectors(t,this.start),Xe.subVectors(this.end,this.start);const i=Xe.dot(Xe);if(i===0)return 0;let n=Xe.dot(Cs)/i;return e&&(n=V(n,0,1)),n}closestPointToPoint(t,e,i){const s=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(s).add(this.start)}distanceSqToLine3(t,e=_n,i=Mn){const s=10000000000000001e-32;let n,r;const a=this.start,o=t.start,c=this.end,h=t.end;se.subVectors(c,a),ne.subVectors(h,o),Ri.subVectors(a,o);const u=se.dot(se),l=ne.dot(ne),d=ne.dot(Ri);if(u<=s&&l<=s)return e.copy(a),i.copy(o),e.sub(i),e.dot(e);if(u<=s)n=0,r=d/l,r=V(r,0,1);else{const y=se.dot(Ri);if(l<=s)r=0,n=V(-y/u,0,1);else{const m=se.dot(ne),z=u*l-m*m;z!==0?n=V((m*d-y*l)/z,0,1):n=0,r=(m*n+d)/l,r<0?(r=0,n=V(-y/u,0,1)):r>1&&(r=1,n=V((m-y)/u,0,1))}}return e.copy(a).addScaledVector(se,n),i.copy(o).addScaledVector(ne,r),e.distanceToSquared(i)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"186"}})),typeof window<"u"&&(window.__THREE__?yt("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="186");new xt().set(-1,0,0,0,1,0,0,0,1),new xt().set(-1,0,0,0,1,0,0,0,1);const Es=0,An=1,Sn=2,Is=2,ki=1.25,Fs=1,J=32,q=J/4,Vs=65535,Ye=Math.pow(2,-24),Ui=Symbol("SKIP_GENERATION"),Rs={strategy:Es,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ui]:!1};function U(f,t,e){return e.min.x=t[f],e.min.y=t[f+1],e.min.z=t[f+2],e.max.x=t[f+3],e.max.y=t[f+4],e.max.z=t[f+5],e}function Ni(f){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=f[i+3]-f[i];s>e&&(e=s,t=i)}return t}function ks(f,t){t.set(f)}function Us(f,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=f[n],s=t[n],e[n]=i<s?i:s,i=f[r],s=t[r],e[r]=i>s?i:s}}function He(f,t,e){for(let i=0;i<3;i++){const s=t[f+2*i],n=t[f+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function _e(f){const t=f[3]-f[0],e=f[4]-f[1],i=f[5]-f[2];return 2*(t*e+e*i+i*t)}function N(f,t){return t[f+15]===Vs}function X(f,t){return t[f+6]}function G(f,t){return t[f+14]}function v(f){return f+q}function O(f,t){const e=t[f+6];return f+e*q}function Li(f,t){return t[f+7]}function Wr(f){return f}function Di(f,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0,u=1/0,l=1/0,d=1/0,y=-1/0,m=-1/0,z=-1/0;const b=f.offset||0;for(let p=(t-b)*6,x=(t+e-b)*6;p<x;p+=6){const g=f[p+0],w=f[p+1],B=g-w,_=g+w;B<n&&(n=B),_>o&&(o=_),g<u&&(u=g),g>y&&(y=g);const M=f[p+2],P=f[p+3],A=M-P,C=M+P;A<r&&(r=A),C>c&&(c=C),M<l&&(l=M),M>m&&(m=M);const T=f[p+4],E=f[p+5],I=T-E,F=T+E;I<a&&(a=I),F>h&&(h=F),T<d&&(d=T),T>z&&(z=T)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=c,i[5]=h,s[0]=u,s[1]=l,s[2]=d,s[3]=y,s[4]=m,s[5]=z}const At=32,Bn=(f,t)=>f.candidate-t.candidate,Ft=new Array(At).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ze=new Float32Array(6);function Tn(f,t,e,i,s,n){let r=-1,a=0;if(n===Es)r=Ni(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===An)r=Ni(f),r!==-1&&(a=Pn(e,i,s,r));else if(n===Sn){const o=_e(f);let c=ki*s;const h=e.offset||0,u=(i-h)*6,l=(i+s-h)*6;for(let d=0;d<3;d++){const y=t[d],b=(t[d+3]-y)/At;if(s<At/4){const p=[...Ft];p.length=s;let x=0;for(let w=u;w<l;w+=6,x++){const B=p[x];B.candidate=e[w+2*d],B.count=0;const{bounds:_,leftCacheBounds:M,rightCacheBounds:P}=B;for(let A=0;A<3;A++)P[A]=1/0,P[A+3]=-1/0,M[A]=1/0,M[A+3]=-1/0,_[A]=1/0,_[A+3]=-1/0;He(w,e,_)}p.sort(Bn);let g=s;for(let w=0;w<g;w++){const B=p[w];for(;w+1<g&&p[w+1].candidate===B.candidate;)p.splice(w+1,1),g--}for(let w=u;w<l;w+=6){const B=e[w+2*d];for(let _=0;_<g;_++){const M=p[_];B>=M.candidate?He(w,e,M.rightCacheBounds):(He(w,e,M.leftCacheBounds),M.count++)}}for(let w=0;w<g;w++){const B=p[w],_=B.count,M=s-B.count,P=B.leftCacheBounds,A=B.rightCacheBounds;let C=0;_!==0&&(C=_e(P)/o);let T=0;M!==0&&(T=_e(A)/o);const E=Fs+ki*(C*_+T*M);E<c&&(r=d,c=E,a=B.candidate)}}else{for(let g=0;g<At;g++){const w=Ft[g];w.count=0,w.candidate=y+b+g*b;const B=w.bounds;for(let _=0;_<3;_++)B[_]=1/0,B[_+3]=-1/0}for(let g=u;g<l;g+=6){let _=~~((e[g+2*d]-y)/b);_>=At&&(_=At-1);const M=Ft[_];M.count++,He(g,e,M.bounds)}const p=Ft[At-1];ks(p.bounds,p.rightCacheBounds);for(let g=At-2;g>=0;g--){const w=Ft[g],B=Ft[g+1];Us(w.bounds,B.rightCacheBounds,w.rightCacheBounds)}let x=0;for(let g=0;g<At-1;g++){const w=Ft[g],B=w.count,_=w.bounds,P=Ft[g+1].rightCacheBounds;B!==0&&(x===0?ks(_,Ze):Us(_,Ze,Ze)),x+=B;let A=0,C=0;x!==0&&(A=_e(Ze)/o);const T=s-x;T!==0&&(C=_e(P)/o);const E=Fs+ki*(A*x+C*T);E<c&&(r=d,c=E,a=w.candidate)}}}}else console.warn(\`BVH: Invalid build strategy value \${n} used.\`);return{axis:r,pos:a}}function Pn(f,t,e,i){let s=0;const n=f.offset;for(let r=t,a=t+e;r<a;r++)s+=f[(r-n)*6+i*2];return s/e}class qi{constructor(){this.boundingData=new Float32Array(6)}}function Cn(f,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,c=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+c]<o;)r++;for(;r<=a&&e[(a-h)*6+c]>=o;)a--;if(r<a){for(let u=0;u<t;u++){let l=f[r*t+u];f[r*t+u]=f[a*t+u],f[a*t+u]=l}for(let u=0;u<6;u++){const l=r-h,d=a-h,y=e[l*6+u];e[l*6+u]=e[d*6+u],e[d*6+u]=y}r++,a--}else return r}}let Ns,$e,vi,Ls;const En=Math.pow(2,32);function Oi(f){return"count"in f?1:1+Oi(f.left)+Oi(f.right)}function In(f,t,e){return Ns=new Float32Array(e),$e=new Uint32Array(e),vi=new Uint16Array(e),Ls=new Uint8Array(e),Wi(f,t)}function Wi(f,t){const e=f/4,i=f/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)Ns[e+r]=n[r];if(s)return t.buffer?(Ls.set(new Uint8Array(t.buffer),f),f+t.buffer.byteLength):($e[e+6]=t.offset,vi[i+14]=t.count,vi[i+15]=Vs,f+J);{const{left:r,right:a,splitAxis:o}=t,c=f+J;let h=Wi(c,r);const u=f/J,d=h/J-u;if(d>En)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return $e[e+6]=d,$e[e+7]=o,Wi(h,a)}}function Fn(f,t,e,i,s,n){const{maxDepth:r,verbose:a,targetLeafSize:o,_strictLeafSize:c=1/0,strategy:h,onProgress:u}=s,l=f.primitiveBuffer,d=f.primitiveBufferStride,y=new Float32Array(6);let m=!1;const z=new qi;return Di(t,e,i,z.boundingData,y),p(z,e,i,y),z;function b(x){u&&u((x-n.offset)/n.count)}function p(x,g,w,B=null,_=0){!m&&_>=r&&(m=!0,a&&console.warn(\`BVH: Max depth of \${r} reached when generating BVH. Consider increasing maxDepth.\`));const M=w>c;if(w<=o&&!M||_>=r)return b(g+w),x.offset=g,x.count=w,x;const P=Tn(x.boundingData,B,t,g,w,h);let A=P.axis===-1?-1:Cn(l,d,t,g,w,P);if(P.axis===-1||A===g||A===g+w){if(!M)return b(g+w),x.offset=g,x.count=w,x;P.axis=Math.max(0,Ni(x.boundingData)),A=g+Math.max(1,Math.floor(w/2))}x.splitAxis=P.axis;const C=new qi,T=g,E=A-g;x.left=C,Di(t,T,E,C.boundingData,y),p(C,T,E,y,_+1);const I=new qi,F=A,R=w-E;return x.right=I,Di(t,F,R,I.boundingData,y),p(I,F,R,y,_+1),x}}function Vn(f,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=f.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,f.computePrimitiveBounds(r.offset,r.count,a),f._roots=i.map(o=>{const c=Fn(f,a,o.offset,o.count,t,r),h=Oi(c),u=new e(J*h);return In(0,c,u),u})}class Xi{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Rn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const k=new Rn;let Vt,re;const oe=[],Je=new Xi(()=>new Q);function kn(f,t,e,i,s,n){Vt=Je.getPrimitive(),re=Je.getPrimitive(),oe.push(Vt,re),k.setBuffer(f._roots[t]);const r=Yi(0,f.geometry,e,i,s,n);k.clearBuffer(),Je.releasePrimitive(Vt),Je.releasePrimitive(re),oe.pop(),oe.pop();const a=oe.length;return a>0&&(re=oe[a-1],Vt=oe[a-2]),r}function Yi(f,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:c}=k;let h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);return U(f,a,Vt),i(l,d,!1,r,n+f/q,Vt)}else{let A=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=v(T),F=T*2;return X(T,I)},C=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=O(T,I),F=T*2;return X(T,I)+G(F,E)};const l=v(f),d=O(f,c);let y=l,m=d,z,b,p,x;if(s&&(p=Vt,x=re,U(y,a,p),U(m,a,x),z=s(p),b=s(x),b<z)){y=d,m=l;const T=z;z=b,b=T,p=x}p||(p=Vt,U(y,a,p));const g=N(y*2,o),w=e(p,g,z,r+1,n+y/q);let B;if(w===Is){const T=A(y),I=C(y)-T;B=i(T,I,!0,r+1,n+y/q,p)}else B=w&&Yi(y,t,e,i,s,n,r+1);if(B)return!0;x=re,U(m,a,x);const _=N(m*2,o),M=e(x,_,b,r+1,n+m/q);let P;if(M===Is){const T=A(m),I=C(m)-T;P=i(T,I,!0,r+1,n+m/q,x)}else P=M&&Yi(m,t,e,i,s,n,r+1);return!!P}}const Me=new k.constructor,Ge=new k.constructor,Rt=new Xi(()=>new Q),ae=new Q,ce=new Q,Hi=new Q,Zi=new Q;let $i=!1;function Un(f,t,e,i){if($i)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");$i=!0;const s=f._roots,n=t._roots;let r,a=0,o=0;const c=new H().copy(e).invert();for(let h=0,u=s.length;h<u;h++){Me.setBuffer(s[h]),o=0;const l=Rt.getPrimitive();U(0,Me.float32Array,l),l.applyMatrix4(c);for(let d=0,y=n.length;d<y&&(Ge.setBuffer(n[d]),r=ut(0,0,e,c,i,a,o,0,0,l),Ge.clearBuffer(),o+=n[d].byteLength/J,!r);d++);if(Rt.releasePrimitive(l),Me.clearBuffer(),a+=s[h].byteLength/J,r)break}return $i=!1,r}function ut(f,t,e,i,s,n=0,r=0,a=0,o=0,c=null,h=!1){let u,l;h?(u=Ge,l=Me):(u=Me,l=Ge);const d=u.float32Array,y=u.uint32Array,m=u.uint16Array,z=l.float32Array,b=l.uint32Array,p=l.uint16Array,x=f*2,g=t*2,w=N(x,m),B=N(g,p);let _=!1;if(B&&w)h?_=s(X(t,b),G(t*2,p),X(f,y),G(f*2,m),o,r+t/q,a,n+f/q):_=s(X(f,y),G(f*2,m),X(t,b),G(t*2,p),a,n+f/q,o,r+t/q);else if(B){const M=Rt.getPrimitive();U(t,z,M),M.applyMatrix4(e);const P=v(f),A=O(f,y);U(P,d,ae),U(A,d,ce);const C=M.intersectsBox(ae),T=M.intersectsBox(ce);_=C&&ut(t,P,i,e,s,r,n,o,a+1,M,!h)||T&&ut(t,A,i,e,s,r,n,o,a+1,M,!h),Rt.releasePrimitive(M)}else{const M=v(t),P=O(t,b);U(M,z,Hi),U(P,z,Zi);const A=c.intersectsBox(Hi),C=c.intersectsBox(Zi);if(A&&C)_=ut(f,M,e,i,s,n,r,a,o+1,c,h)||ut(f,P,e,i,s,n,r,a,o+1,c,h);else if(A)if(w)_=ut(f,M,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Hi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(M,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(M,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}else if(C)if(w)_=ut(f,P,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Zi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(P,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(P,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}}return _}const Ji=new class{constructor(){let f=null,t=null,e=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(n,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=f=n._roots[r],this.uint16Array=e=new Uint16Array(f),this.uint32Array=t=new Uint32Array(f)},this.reset=()=>{this.root=null,this.buffer=f=null,this.uint16Array=e=null,this.uint32Array=t=null},this.getRangeStart=n=>{let r=n*2;for(;!N(r,e);)n=v(n),r=n*2;return X(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!N(r,e);)n=O(n,t),r=n*2;return X(n,t)+G(r,e)};const s=(n,r,a)=>{const o=r*2,c=N(o,e);if(!n(a,c,r)&&!c){const u=v(r),l=O(r,t);s(n,u,a+1),s(n,l,a+1)}};this.traverseBuffer=n=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(n,0,0)}finally{i=!1}},this.traverse=n=>{this.traverseBuffer((r,a,o)=>{if(a){const c=o*2,h=t[o+6],u=e[c+14];return n(r,a,new Float32Array(f,o*4,6),h,u)}else{const c=Li(o,t);return n(r,a,new Float32Array(f,o*4,6),c)}})}}},Ds=new Q,he=new Float32Array(6);class Nn{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...Rs,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),Vn(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0;for(let u=t,l=t+e;u<l;u++){this.writePrimitiveBounds(u,he,0);const[d,y,m,z,b,p]=he;d<n&&(n=d),z>o&&(o=z),y<r&&(r=y),b>c&&(c=b),m<a&&(a=m),p>h&&(h=p)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=c,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,he,0);const[a,o,c,h,u,l]=he,d=(a+h)/2,y=(o+u)/2,m=(c+l)/2,z=(h-a)/2,b=(u-o)/2,p=(l-c)/2,x=(n-s)*6;i[x+0]=d,i[x+1]=z+(Math.abs(d)+z)*Ye,i[x+2]=y,i[x+3]=b+(Math.abs(y)+b)*Ye,i[x+4]=m,i[x+5]=p+(Math.abs(m)+p)*Ye}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/J;for(let c=0;c<o;c++){const h=q*c,u=2*h;N(u,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){Ji.setBVH(this,e),Ji.traverse(t),Ji.reset()}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/J;for(let c=o-1;c>=0;c--){const h=c*q,u=h*2;if(N(u,r)){const d=X(h,n),y=G(u,r);this.writePrimitiveRangeBounds(d,y,he,0),a.set(he,h)}else{const d=v(h),y=O(h,n);for(let m=0;m<3;m++){const z=a[d+m],b=a[d+m+3],p=a[y+m],x=a[y+m+3];a[h+m]=z<p?z:p,a[h+m+3]=b>x?b:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{U(0,new Float32Array(i),Ds),t.union(Ds)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const u=s;s=(l,d,y,m,z)=>u(l,d,y,m,z)?!0:a(l,d,this,n,y,m,r)}else s||(n?s=(u,l,d,y)=>a(u,l,this,n,d,y,r):s=(u,l,d)=>d);let o=!1,c=0;const h=this._roots;for(let u=0,l=h.length;u<l;u++){const d=h[u];if(o=kn(this,u,i,s,e,c),o)break;c+=d.byteLength/J}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return Un(this,t,e,s)}}function Ln(){return typeof SharedArrayBuffer<"u"}function Gi(f){return f.index?f.index.count:f.attributes.position.count}function Qe(f){return Gi(f)/3}function Dn(f,t=ArrayBuffer){return f>65535?new Uint32Array(new t(4*f)):new Uint16Array(new t(2*f))}function qn(f,t){if(!f.index){const e=f.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Dn(e,i);f.setIndex(new mt(s,1));for(let n=0;n<e;n++)s[n]=n}}function vn(f,t,e){const i=Gi(f)/e,s=t||f.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function On(f,t){return f.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function qs(f,t,e){const i=vn(f,t,e),s=On(f,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=Gi(f)/e,c=[];for(const l of s){const{offset:d,count:y}=l,m=d,z=isFinite(y)?y:o-d,b=d+z;m<a&&b>r&&(c.push({pos:Math.max(r,m),isStart:!0}),c.push({pos:Math.min(a,b),isStart:!1}))}c.sort((l,d)=>l.pos!==d.pos?l.pos-d.pos:l.type==="end"?-1:1);let h=0,u=null;for(const l of c){const d=l.pos;h!==0&&d!==u&&n.push({offset:u,count:d-u}),h+=l.isStart?1:-1,u=d}return n}function Wn(f,t){const e=f[f.length-1],i=e.offset+e.count>2**16,s=f.reduce((c,h)=>c+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let c=0;c<f.length;c++){const{offset:h,count:u}=f[c];for(let l=0;l<u;l++)a[o+l]=h+l;o+=u}return a}class Xn extends Nn{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Ln())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...Rs,...e},e[Ui]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=qs(e,t.range,i),n=Wn(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else qn(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Q))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:qs(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class St{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}St.prototype.setFromBox=(function(){const f=new S;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let h=0;h<=1;h++){f.x=s.x*o+n.x*(1-o),f.y=s.y*c+n.y*(1-c),f.z=s.z*h+n.z*(1-h);const u=e.dot(f);r=Math.min(u,r),a=Math.max(u,a)}this.min=r,this.max=a}})();const Yn=(function(){const f=new S,t=new S,e=new S;return function(s,n,r){const a=s.start,o=f,c=n.start,h=t;e.subVectors(a,c),f.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const u=e.dot(h),l=h.dot(o),d=h.dot(h),y=e.dot(o),z=o.dot(o)*d-l*l;let b,p;z!==0?b=(u*l-y*d)/z:b=0,p=(u+b*l)/d,r.x=b,r.y=p}})(),Qi=(function(){const f=new Y,t=new S,e=new S;return function(s,n,r,a){Yn(s,n,f);let o=f.x,c=f.y;if(o>=0&&o<=1&&c>=0&&c<=1){s.at(o,r),n.at(c,a);return}else if(o>=0&&o<=1){c<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(c>=0&&c<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let u;c<0?u=n.start:u=n.end;const l=t,d=e;if(s.closestPointToPoint(u,!0,t),n.closestPointToPoint(h,!0,e),l.distanceToSquared(u)<=d.distanceToSquared(h)){r.copy(l),a.copy(u);return}else{r.copy(h),a.copy(d);return}}}})(),Hn=(function(){const f=new S,t=new S,e=new Ts,i=new Mt;return function(n,r){const{radius:a,center:o}=n,{a:c,b:h,c:u}=r;if(i.start=c,i.end=h,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a||(i.start=c,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a)||(i.start=h,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a))return!0;const m=r.getPlane(e);if(Math.abs(m.distanceToPoint(o))<=a){const b=m.projectPoint(o,t);if(r.containsPoint(b))return!0}return!1}})(),Zn=["x","y","z"],Bt=1e-15,vs=Bt*Bt;function rt(f){return Math.abs(f)<Bt}class ft extends st{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new S),this.satBounds=new Array(4).fill().map(()=>new St),this.points=[this.a,this.b,this.c],this.plane=new Ts,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Mt,this.needsUpdate=!0}intersectsSphere(t){return Hn(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const c=n[1],h=r[1];c.subVectors(t,e),h.setFromPoints(c,s);const u=n[2],l=r[2];u.subVectors(e,i),l.setFromPoints(u,s);const d=n[3],y=r[3];d.subVectors(i,t),y.setFromPoints(d,s);const m=c.length(),z=u.length(),b=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<Bt?z<Bt||b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):z<Bt?b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):b<Bt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}ft.prototype.closestPointToSegment=(function(){const f=new S,t=new S,e=new Mt;return function(s,n=null,r=null){const{start:a,end:o}=s,c=this.points;let h,u=1/0;for(let l=0;l<3;l++){const d=(l+1)%3;e.start.copy(c[l]),e.end.copy(c[d]),Qi(e,s,f,t),h=f.distanceToSquared(t),h<u&&(u=h,n&&n.copy(f),r&&r.copy(t))}return this.closestPointToPoint(a,f),h=a.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(a)),this.closestPointToPoint(o,f),h=o.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(o)),Math.sqrt(u)}})(),ft.prototype.intersectsTriangle=(function(){const f=new ft,t=new St,e=new St,i=new S,s=new S,n=new S,r=new S,a=new Mt,o=new Mt,c=new S,h=new Y,u=new Y;function l(x,g,w,B){const _=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?_.copy(x.plane.normal):_.copy(g.plane.normal);const M=x.satBounds,P=x.satAxes;for(let T=1;T<4;T++){const E=M[T],I=P[T];if(t.setFromPoints(I,g.points),E.isSeparated(t)||(r.copy(_).cross(I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}const A=g.satBounds,C=g.satAxes;for(let T=1;T<4;T++){const E=A[T],I=C[T];if(t.setFromPoints(I,x.points),E.isSeparated(t)||(r.crossVectors(_,I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}return w&&(B||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),w.start.set(0,0,0),w.end.set(0,0,0)),!0}function d(x,g,w,B,_,M,P,A,C,T,E){let I=P/(P-A);T.x=B+(_-B)*I,E.start.subVectors(g,x).multiplyScalar(I).add(x),I=P/(P-C),T.y=B+(M-B)*I,E.end.subVectors(w,x).multiplyScalar(I).add(x)}function y(x,g,w,B,_,M,P,A,C,T,E){if(_>0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else if(M>0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(A*C>0||P!=0)d(x.a,x.b,x.c,g,w,B,P,A,C,T,E);else if(A!=0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(C!=0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else return!0;return!1}function m(x,g,w,B){const _=g.degenerateSegment,M=x.plane.distanceToPoint(_.start),P=x.plane.distanceToPoint(_.end);return rt(M)?rt(P)?l(x,g,w,B):(w&&(w.start.copy(_.start),w.end.copy(_.start)),x.containsPoint(_.start)):rt(P)?(w&&(w.start.copy(_.end),w.end.copy(_.end)),x.containsPoint(_.end)):x.plane.intersectLine(_,i)!=null?(w&&(w.start.copy(i),w.end.copy(i)),x.containsPoint(i)):!1}function z(x,g,w){const B=g.a;return rt(x.plane.distanceToPoint(B))&&x.containsPoint(B)?(w&&(w.start.copy(B),w.end.copy(B)),!0):!1}function b(x,g,w){const B=x.degenerateSegment,_=g.a;return B.closestPointToPoint(_,!0,i),_.distanceToSquared(i)<vs?(w&&(w.start.copy(_),w.end.copy(_)),!0):!1}function p(x,g,w,B){if(x.isDegenerateIntoSegment)if(g.isDegenerateIntoSegment){const _=x.degenerateSegment,M=g.degenerateSegment,P=s,A=n;_.delta(P),M.delta(A);const C=i.subVectors(M.start,_.start),T=P.x*A.y-P.y*A.x;if(rt(T))return!1;const E=(C.x*A.y-C.y*A.x)/T,I=-(P.x*C.y-P.y*C.x)/T;if(E<0||E>1||I<0||I>1)return!1;const F=_.start.z+P.z*E,R=M.start.z+A.z*I;return rt(F-R)?(w&&(w.start.copy(_.start).addScaledVector(P,E),w.end.copy(_.start).addScaledVector(P,E)),!0):!1}else return g.isDegenerateIntoPoint?b(x,g,w):m(g,x,w,B);else{if(x.isDegenerateIntoPoint)return g.isDegenerateIntoPoint?g.a.distanceToSquared(x.a)<vs?(w&&(w.start.copy(x.a),w.end.copy(x.a)),!0):!1:g.isDegenerateIntoSegment?b(g,x,w):z(g,x,w);if(g.isDegenerateIntoPoint)return z(x,g,w);if(g.isDegenerateIntoSegment)return m(x,g,w,B)}}return function(g,w=null,B=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(f.copy(g),f.update(),g=f);const _=p(this,g,w,B);if(_!==void 0)return _;const M=this.plane,P=g.plane;let A=P.distanceToPoint(this.a),C=P.distanceToPoint(this.b),T=P.distanceToPoint(this.c);rt(A)&&(A=0),rt(C)&&(C=0),rt(T)&&(T=0);const E=A*C,I=A*T;if(E>0&&I>0)return!1;let F=M.distanceToPoint(g.a),R=M.distanceToPoint(g.b),Z=M.distanceToPoint(g.c);rt(F)&&(F=0),rt(R)&&(R=0),rt(Z)&&(Z=0);const tt=F*R,dt=F*Z;if(tt>0&&dt>0)return!1;s.copy(M.normal),n.copy(P.normal);const at=s.cross(n);let pt=0,ye=Math.abs(at.x);const Ie=Math.abs(at.y);Ie>ye&&(ye=Ie,pt=1),Math.abs(at.z)>ye&&(pt=2);const Tt=Zn[pt],fi=this.a[Tt],di=this.b[Tt],Wt=this.c[Tt],Xt=g.a[Tt],Yt=g.b[Tt],Fe=g.c[Tt];if(y(this,fi,di,Wt,E,I,A,C,T,h,a))return l(this,g,w,B);if(y(g,Xt,Yt,Fe,tt,dt,F,R,Z,u,o))return l(this,g,w,B);if(h.y<h.x){const Ht=h.y;h.y=h.x,h.x=Ht,c.copy(a.start),a.start.copy(a.end),a.end.copy(c)}if(u.y<u.x){const Ht=u.y;u.y=u.x,u.x=Ht,c.copy(o.start),o.start.copy(o.end),o.end.copy(c)}return h.y<u.x||u.y<h.x?!1:(w&&(u.x>h.x?w.start.copy(o.start):w.start.copy(a.start),u.y<h.y?w.end.copy(o.end):w.end.copy(a.end)),!0)}})(),ft.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),ft.prototype.distanceToTriangle=(function(){const f=new S,t=new S,e=["a","b","c"],i=new Mt,s=new Mt;return function(r,a=null,o=null){const c=a||o?i:null;if(this.intersectsTriangle(r,c,!0))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let h=1/0;for(let u=0;u<3;u++){let l;const d=e[u],y=r[d];this.closestPointToPoint(y,f),l=y.distanceToSquared(f),l<h&&(h=l,a&&a.copy(f),o&&o.copy(y));const m=this[d];r.closestPointToPoint(m,f),l=m.distanceToSquared(f),l<h&&(h=l,a&&a.copy(m),o&&o.copy(f))}for(let u=0;u<3;u++){const l=e[u],d=e[(u+1)%3];i.set(this[l],this[d]);for(let y=0;y<3;y++){const m=e[y],z=e[(y+1)%3];s.set(r[m],r[z]),Qi(i,s,f,t);const b=f.distanceToSquared(t);b<h&&(h=b,a&&a.copy(f),o&&o.copy(t))}}return Math.sqrt(h)}})();class j{constructor(t,e,i){this.isOrientedBox=!0,this.min=new S,this.max=new S,this.matrix=new H,this.invMatrix=new H,this.points=new Array(8).fill().map(()=>new S),this.satAxes=new Array(3).fill().map(()=>new S),this.satBounds=new Array(3).fill().map(()=>new St),this.alignedSatBounds=new Array(3).fill().map(()=>new St),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}j.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let c=0;c<=1;c++)for(let h=0;h<=1;h++)for(let u=0;u<=1;u++){const l=1*c|2*h|4*u,d=s[l];d.x=c?i.x:e.x,d.y=h?i.y:e.y,d.z=u?i.z:e.z,d.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let c=0;c<3;c++){const h=r[c],u=n[c],l=1<<c,d=s[l];h.subVectors(a,d),u.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),j.prototype.intersectsBox=(function(){const f=new St;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(f.min=i.x,f.max=s.x,a[0].isSeparated(f)||(f.min=i.y,f.max=s.y,a[1].isSeparated(f))||(f.min=i.z,f.max=s.z,a[2].isSeparated(f)))return!1;for(let o=0;o<3;o++){const c=r[o],h=n[o];if(f.setFromBox(c,e),h.isSeparated(f))return!1}return!0}})(),j.prototype.intersectsTriangle=(function(){const f=new ft,t=new Array(3),e=new St,i=new St,s=new S;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(f.copy(r),f.update(),r=f);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let l=0;l<3;l++){const d=a[l],y=o[l];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const c=r.satBounds,h=r.satAxes,u=this.points;for(let l=0;l<3;l++){const d=c[l],y=h[l];if(e.setFromPoints(y,u),d.isSeparated(e))return!1}for(let l=0;l<3;l++){const d=o[l];for(let y=0;y<4;y++){const m=h[y];if(s.crossVectors(d,m),e.setFromPoints(s,t),i.setFromPoints(s,u),e.isSeparated(i))return!1}}return!0}})(),j.prototype.closestPointToPoint=(function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}})(),j.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),j.prototype.distanceToBox=(function(){const f=["x","y","z"],t=new Array(12).fill().map(()=>new Mt),e=new Array(12).fill().map(()=>new Mt),i=new S,s=new S;return function(r,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||c)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),c&&c.copy(s)),0;const h=a*a,u=r.min,l=r.max,d=this.points;let y=1/0;for(let z=0;z<8;z++){const b=d[z];s.copy(b).clamp(u,l);const p=b.distanceToSquared(s);if(p<y&&(y=p,o&&o.copy(b),c&&c.copy(s),p<h))return Math.sqrt(p)}let m=0;for(let z=0;z<3;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){const x=(z+1)%3,g=(z+2)%3,w=b<<x|p<<g,B=1<<z|b<<x|p<<g,_=d[w],M=d[B];t[m].set(_,M);const A=f[z],C=f[x],T=f[g],E=e[m],I=E.start,F=E.end;I[A]=u[A],I[C]=b?u[C]:l[C],I[T]=p?u[T]:l[C],F[A]=l[A],F[C]=b?u[C]:l[C],F[T]=p?u[T]:l[C],m++}for(let z=0;z<=1;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){s.x=z?l.x:u.x,s.y=b?l.y:u.y,s.z=p?l.z:u.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<y&&(y=x,o&&o.copy(i),c&&c.copy(s),x<h))return Math.sqrt(x)}for(let z=0;z<12;z++){const b=t[z];for(let p=0;p<12;p++){const x=e[p];Qi(b,x,i,s);const g=i.distanceToSquared(s);if(g<y&&(y=g,o&&o.copy(i),c&&c.copy(s),g<h))return Math.sqrt(g)}}return Math.sqrt(y)}})();class $n extends Xi{constructor(){super(()=>new ft)}}const ot=new $n,Ae=new S,ji=new S;function Jn(f,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(f.shapecast({boundsTraverseOrder:h=>(Ae.copy(t).clamp(h.min,h.max),Ae.distanceToSquared(t)),intersectsBounds:(h,u,l)=>l<a&&l<r,intersectsTriangle:(h,u)=>{h.closestPointToPoint(t,Ae);const l=t.distanceToSquared(Ae);return l<a&&(ji.copy(Ae),a=l,o=u),l<n}}),a===1/0)return null;const c=Math.sqrt(a);return e.point?e.point.copy(ji):e.point=ji.clone(),e.distance=c,e.faceIndex=o,e}const je=parseInt("186")>=169,Gn=parseInt("186")<=161,qt=new S,vt=new S,Ot=new S,Ke=new Y,ti=new Y,ei=new Y,Os=new S,Ws=new S,Xs=new S,Se=new S;function Qn(f,t,e,i,s,n,r,a){let o;if(n===1?o=f.intersectTriangle(i,e,t,!0,s):o=f.intersectTriangle(t,e,i,n!==2,s),o===null)return null;const c=f.origin.distanceTo(s);return c<r||c>a?null:{distance:c,point:s.clone()}}function Ys(f,t,e,i,s,n,r,a,o,c,h){qt.fromBufferAttribute(t,n),vt.fromBufferAttribute(t,r),Ot.fromBufferAttribute(t,a);const u=Qn(f,qt,vt,Ot,Se,o,c,h);if(u){if(i){Ke.fromBufferAttribute(i,n),ti.fromBufferAttribute(i,r),ei.fromBufferAttribute(i,a),u.uv=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv);je||(u.uv=d)}if(s){Ke.fromBufferAttribute(s,n),ti.fromBufferAttribute(s,r),ei.fromBufferAttribute(s,a),u.uv1=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv1);je||(u.uv1=d),Gn&&(u.uv2=u.uv1)}if(e){Os.fromBufferAttribute(e,n),Ws.fromBufferAttribute(e,r),Xs.fromBufferAttribute(e,a),u.normal=new S;const d=st.getInterpolation(Se,qt,vt,Ot,Os,Ws,Xs,u.normal);u.normal.dot(f.direction)>0&&u.normal.multiplyScalar(-1),je||(u.normal=d)}const l={a:n,b:r,c:a,normal:new S,materialIndex:0};if(st.getNormal(qt,vt,Ot,l.normal),u.face=l,u.faceIndex=n,je){const d=new S;st.getBarycoord(Se,qt,vt,Ot,d),u.barycoord=d}}return u}function Hs(f){return f&&f.isMaterial?f.side:f}function ii(f,t,e,i,s,n,r){const a=i*3;let o=a+0,c=a+1,h=a+2;const{index:u,groups:l}=f;f.index&&(o=u.getX(o),c=u.getX(c),h=u.getX(h));const{position:d,normal:y,uv:m,uv1:z}=f.attributes;if(Array.isArray(t)){const b=i*3;for(let p=0,x=l.length;p<x;p++){const{start:g,count:w,materialIndex:B}=l[p];if(b>=g&&b<g+w){const _=Hs(t[B]),M=Ys(e,d,y,m,z,o,c,h,_,n,r);if(M)if(M.faceIndex=i,M.face.materialIndex=B,s)s.push(M);else return M}}}else{const b=Hs(t),p=Ys(e,d,y,m,z,o,c,h,b,n,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function D(f,t,e,i){const s=f.a,n=f.b,r=f.c;let a=t,o=t+1,c=t+2;e&&(a=e.getX(a),o=e.getX(o),c=e.getX(c)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(c),r.y=i.getY(c),r.z=i.getZ(c)}function jn(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++)ii(o,t,e,h,n,r,a)}function Kn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function tr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=h,D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function er(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=3*z,P=3*(z+b);M<P;M++){let A=i[M];const C=s.getX(A),T=s.getY(A),E=s.getZ(A);C<p&&(p=C),C>w&&(w=C),T<x&&(x=T),T>B&&(B=T),E<g&&(g=E),E>_&&(_=E)}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function kt(f,t,e,i,s){let n,r,a,o,c,h;const u=1/e.direction.x,l=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,m=e.origin.y,z=e.origin.z;let b=t[f],p=t[f+3],x=t[f+1],g=t[f+3+1],w=t[f+2],B=t[f+3+2];return u>=0?(n=(b-y)*u,r=(p-y)*u):(n=(p-y)*u,r=(b-y)*u),l>=0?(a=(x-m)*l,o=(g-m)*l):(a=(g-m)*l,o=(x-m)*l),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),d>=0?(c=(w-z)*d,h=(B-z)*d):(c=(B-z)*d,h=(w-z)*d),n>h||c>r)?!1:((c>n||n!==n)&&(n=c),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function ir(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++){let l=c?c[h]:h;ii(o,t,e,l,n,r,a)}}function sr(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,o?o[u]:u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function nr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=e.resolveTriangleIndex(h),D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function rr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),Ki(0,f,e,i,s,n,r),k.clearBuffer()}function Ki(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);jn(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&Ki(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&Ki(d,t,e,i,s,n,r)}}const or=["x","y","z"];function ar(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ts(0,f,e,i,s,n);return k.clearBuffer(),r}function ts(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return Kn(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=or[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ts(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ts(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const si=new Q,le=new ft,ue=new ft,Be=new H,Zs=new j,ni=new j;function cr(f,t,e,i){k.setBuffer(f._roots[t]);const s=es(0,f,e,i);return k.clearBuffer(),s}function es(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Zs.set(e.boundingBox.min,e.boundingBox.max,i),s=Zs),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Be.copy(i).invert(),e.boundsTree)return U(f,n,ni),ni.matrix.copy(Be),ni.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ni.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m*3,g=(z+m)*3;x<g;x+=3)if(D(ue,x,u,l),ue.needsUpdate=!0,p.intersectsTriangle(ue))return!0;return!1}});{const b=Qe(e);for(let p=m*3,x=(z+m)*3;p<x;p+=3){D(le,p,u,l),le.a.applyMatrix4(Be),le.b.applyMatrix4(Be),le.c.applyMatrix4(Be),le.needsUpdate=!0;for(let g=0,w=b*3;g<w;g+=3)if(D(ue,g,d,y),ue.needsUpdate=!0,le.intersectsTriangle(ue))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,si),!!(s.intersectsBox(si)&&es(h,t,e,i,s)||(U(u,n,si),s.intersectsBox(si)&&es(u,t,e,i,s)))}}const ri=new H,is=new j,Te=new j,hr=new S,lr=new S,ur=new S,fr=new S;function dr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),is.set(t.boundingBox.min,t.boundingBox.max,e),is.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=hr,m=lr,z=null,b=null;s&&(z=ur,b=fr);let p=1/0,x=null,g=null;return ri.copy(e).invert(),Te.matrix.copy(ri),f.shapecast({boundsTraverseOrder:w=>is.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Te.min.copy(w.min),Te.max.copy(w.max),Te.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:M=>Te.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let T=w,E=w+B;T<E;T++){D(l,3*T,c,o),l.needsUpdate=!0;const I=l.distanceToTriangle(d,y,z);if(I<p&&(m.copy(y),b&&b.copy(z),p=I,x=T,g=A),I<n)return!0}}}});{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){D(l,3*A,c,o),l.needsUpdate=!0;const T=l.distanceToTriangle(d,y,z);if(T<p&&(m.copy(y),b&&b.copy(z),p=T,x=A,g=M),T<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ri),m.applyMatrix4(ri),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function yr(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=z,P=z+b;M<P;M++){const A=3*f.resolveTriangleIndex(M);for(let C=0;C<3;C++){let T=A+C;T=i?i[T]:T;const E=s.getX(T),I=s.getY(T),F=s.getZ(T);E<p&&(p=E),E>w&&(w=E),I<x&&(x=I),I>B&&(B=I),F<g&&(g=F),F>_&&(_=F)}}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function mr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),ss(0,f,e,i,s,n,r),k.clearBuffer()}function ss(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);ir(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&ss(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&ss(d,t,e,i,s,n,r)}}const pr=["x","y","z"];function xr(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ns(0,f,e,i,s,n);return k.clearBuffer(),r}function ns(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return sr(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=pr[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ns(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ns(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const oi=new Q,fe=new ft,de=new ft,Pe=new H,$s=new j,ai=new j;function gr(f,t,e,i){k.setBuffer(f._roots[t]);const s=rs(0,f,e,i);return k.clearBuffer(),s}function rs(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),$s.set(e.boundingBox.min,e.boundingBox.max,i),s=$s),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Pe.copy(i).invert(),e.boundsTree)return U(f,n,ai),ai.matrix.copy(Pe),ai.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ai.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m,g=z+m;x<g;x++)if(D(de,3*t.resolveTriangleIndex(x),u,l),de.needsUpdate=!0,p.intersectsTriangle(de))return!0;return!1}});{const b=Qe(e);for(let p=m,x=z+m;p<x;p++){const g=t.resolveTriangleIndex(p);D(fe,3*g,u,l),fe.a.applyMatrix4(Pe),fe.b.applyMatrix4(Pe),fe.c.applyMatrix4(Pe),fe.needsUpdate=!0;for(let w=0,B=b*3;w<B;w+=3)if(D(de,w,d,y),de.needsUpdate=!0,fe.intersectsTriangle(de))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,oi),!!(s.intersectsBox(oi)&&rs(h,t,e,i,s)||(U(u,n,oi),s.intersectsBox(oi)&&rs(u,t,e,i,s)))}}const ci=new H,os=new j,Ce=new j,wr=new S,br=new S,zr=new S,_r=new S;function Mr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),os.set(t.boundingBox.min,t.boundingBox.max,e),os.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=wr,m=br,z=null,b=null;s&&(z=zr,b=_r);let p=1/0,x=null,g=null;return ci.copy(e).invert(),Ce.matrix.copy(ci),f.shapecast({boundsTraverseOrder:w=>os.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Ce.min.copy(w.min),Ce.max.copy(w.max),Ce.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree){const _=t.boundsTree;return _.shapecast({boundsTraverseOrder:M=>Ce.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){const T=_.resolveTriangleIndex(A);D(d,3*T,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=w,I=w+B;E<I;E++){const F=f.resolveTriangleIndex(E);D(l,3*F,c,o),l.needsUpdate=!0;const R=l.distanceToTriangle(d,y,z);if(R<p&&(m.copy(y),b&&b.copy(z),p=R,x=E,g=A),R<n)return!0}}}})}else{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){const T=f.resolveTriangleIndex(A);D(l,3*T,c,o),l.needsUpdate=!0;const E=l.distanceToTriangle(d,y,z);if(E<p&&(m.copy(y),b&&b.copy(z),p=E,x=A,g=M),E<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ci),m.applyMatrix4(ci),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function Js(f,t,e){return f===null?null:(f.point.applyMatrix4(t.matrixWorld),f.distance=f.point.distanceTo(e.ray.origin),f.object=t,f)}const hi=new j,li=new zn,Gs=new S,Qs=new H,js=new S,as=["getX","getY","getZ"];class Ee extends Xn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new Ee(e,{...i,[Ui]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const h=new mt(t.index,1,!1);e.setIndex(h)}else c.array!==s&&(c.array.set(s),c.needsUpdate=!0)}return a;function o(c){for(let h=0;h<c.length;h++){const u=c[h],l=new Uint32Array(u),d=new Uint16Array(u);for(let y=0,m=u.byteLength/J;y<m;y++){const z=q*y,b=2*z;N(b,d)||(l[z+6]=l[z+6]/q-y)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,c=(n?n[t]:t)*3;let h=c+0,u=c+1,l=c+2;a&&(h=a[h],u=a[u],l=a[l]);for(let d=0;d<3;d++){const y=r[as[d]](h),m=r[as[d]](u),z=r[as[d]](l);let b=y;m<b&&(b=m),z<b&&(b=z);let p=y;m>p&&(p=m),z>p&&(p=z),e[i+d]=b,e[i+d+3]=p}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=r.array,h=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const l=["getX","getY","getZ"],d=i.offset;for(let y=t,m=t+e;y<m;y++){const b=(n?n[y]:y)*3,p=(y-d)*6;let x=b+0,g=b+1,w=b+2;a&&(x=a[x],g=a[g],w=a[w]),o||(x=x*u+h,g=g*u+h,w=w*u+h);for(let B=0;B<3;B++){let _,M,P;o?(_=r[l[B]](x),M=r[l[B]](g),P=r[l[B]](w)):(_=c[x+B],M=c[g+B],P=c[w+B]);let A=_;M<A&&(A=M),P<A&&(A=P);let C=_;M>C&&(C=M),P>C&&(C=P);const T=(C-A)/2,E=B*2;i[p+E+0]=A+T,i[p+E+1]=T+(Math.abs(A)+T)*Ye}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;Qs.copy(t.matrixWorld).invert(),li.copy(e.ray).applyMatrix4(Qs),js.setFromMatrixScale(t.matrixWorld),Gs.copy(li.direction).multiply(js);const n=Gs.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(li,s,r,a);o=Js(o,t,e),o&&i.push(o)}else{const o=this.raycast(li,s,r,a);for(let c=0,h=o.length;c<h;c++){const u=Js(o[c],t,e);u&&i.push(u)}}return i}refit(t=null){return(this.indirect?yr:er)(this,t)}raycast(t,e=0,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?mr:rr;for(let o=0,c=n.length;o<c;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=0,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?xr:ar;for(let o=0,c=n.length;o<c;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?gr:cr;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=ot.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?nr:tr});return ot.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=ot.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,c=this.indirect?y=>{const m=this.resolveTriangleIndex(y);D(r,m*3,a,o)}:y=>{D(r,y*3,a,o)},h=ot.getPrimitive(),u=t.geometry.index,l=t.geometry.attributes.position,d=t.indirect?y=>{const m=t.resolveTriangleIndex(y);D(h,m*3,u,l)}:y=>{D(h,y*3,u,l)};if(n){if(!(t instanceof Ee))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const y=(m,z,b,p,x,g,w,B)=>{for(let _=b,M=b+p;_<M;_++){d(_),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let P=m,A=m+z;P<A;P++)if(c(P),r.needsUpdate=!0,n(r,h,P,_,x,g,w,B))return!0}return!1};if(s){const m=s;s=function(z,b,p,x,g,w,B,_){return m(z,b,p,x,g,w,B,_)?!0:y(z,b,p,x,g,w,B,_)}}else s=y}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return hi.set(t.min,t.max,e),hi.needsUpdate=!0,this.shapecast({intersectsBounds:i=>hi.intersectsBox(i),intersectsTriangle:i=>hi.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?Mr:dr)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Jn(this,t,e,i,s)}}const cs=self;cs.addEventListener("message",async({data:f})=>{let t=performance.now();function e(a){const o=performance.now();(o-t>=10||a===1)&&(postMessage({error:void 0,serialized:void 0,position:void 0,progress:a}),t=o)}const{id:i,index:s,position:n,options:r}=f;try{const a=new Ii;if(a.setAttribute("position",new mt(n,3,!1)),s&&a.setIndex(new mt(s,1,!1)),r.includedProgressCallback&&(r.onProgress=e),r.groups){const h=r.groups;for(const u in h){const l=h[u];a.addGroup(l.start,l.count,l.materialIndex)}}const o=new Ee(a,r),c=Ee.serialize(o,{cloneBuffers:!1});cs.postMessage({id:i,error:void 0,serialized:c,position:n,progress:1},[c.index.buffer,n.buffer,...c.roots])}catch(a){cs.postMessage({id:i,error:a,serialized:void 0,position:void 0,progress:1})}})})();
1533
- `,Yr=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Un],{type:"text/javascript;charset=utf-8"});function Wh(h){let t;try{if(t=Yr&&(self.URL||self.webkitURL).createObjectURL(Yr),!t)throw"";const e=new Worker(t,{name:h?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Un),{name:h?.name})}}class Nn{constructor(){p(this,"running");p(this,"worker");this.running=!1,this.worker=new Wh,this.worker.onerror=t=>{throw t.message?new Error(`[GenerateMeshBVHWorker] Could not create Web Worker with error "${t.message}"`):new Error("[GenerateMeshBVHWorker] Could not create Web Worker.")}}isRunning(){return this.running}generate(t,e={}){if(this.running){S.warn("[GenerateMeshBVHWorker] Already running job.");return}if(!this.worker){S.warn("[GenerateMeshBVHWorker] Worker has been disposed.");return}const{worker:i}=this;this.running=!0;const s=new Map;t.forEach(n=>{s.set(n.id,n)});let r=0;return new Promise((n,a)=>{const o=()=>{++r===s.size&&(this.running=!1,i.onmessage=null,n())};i.onerror=l=>{S.warn("[GenerateMeshBVHWorker] "+l.message),a(new Error("[GenerateMeshBVHWorker] "+l.message)),this.running=!1},i.onmessage=l=>{this.running=!1;const{data:c}=l;if(c.error)S.warn(c.error),o();else if(c.serialized){const{serialized:u,position:f,id:m}=c,g=s.get(m),x=ks.MeshBVH.deserialize(u,g,{setIndex:!1}),y=Object.assign({setBoundingBox:!0},e);if(y.transferred&&(g.attributes.position.array=f),g.index)e.saveOriginalIndex&&!g.userData.originalIndex&&(g.userData.originalIndex=g.index.array),S.debug("before update, index:",g.index.array),g.index.array=u.index;else{const T=new Se.BufferAttribute(u.index,1,!1);g.setIndex(T)}g.index&&(S.debug("after update, index:",g.index.array),g.index.needsUpdate=!0),y.setBoundingBox&&!g.boundingBox&&(g.boundingBox=x.getBoundingBox(new Se.Box3)),g.boundsTree=x,o()}else e.onProgress&&e.onProgress(c.progress)};for(const[l,c]of s){const u=c.index?c.index.array:void 0,f=c.attributes.position,m=f.array;if(f.isInterleavedBufferAttribute||u&&u.isInterleavedBufferAttribute){S.warn("[GenerateMeshBVHWorker] InterleavedBufferAttribute are not supported for the geometry attributes."),o();continue}const g=[];e.transferred&&(g.push(m),u&&(g.push(u),e.saveOriginalIndex&&(c.userData.originalIndex=u.slice()))),i.postMessage({id:l,index:u,position:m,options:Object.assign(Object.assign({},e),{onProgress:null,includedProgressCallback:!!e.onProgress,groups:[...c.groups]})},g.length>0?g.map(x=>x.buffer):[])}})}dispose(){this.worker.terminate(),this.worker=void 0}}class Hs{constructor(t){p(this,"running");p(this,"workers");this.running=!1,this.workers=[];let e=1;t?e=t:window.navigator&&(e=Math.max(e,window.navigator.hardwareConcurrency-1));for(let i=0;i<e;i++)this.workers[i]=new Nn}isRunning(){return this.running}async generate(t,e={}){if(this.running){S.warn("[BVHHelper] Already running job.");return}if(this.workers.length===0){S.warn("[BVHHelper] Worker has been disposed.");return}return this.running=!0,new Promise(i=>{const s=this.workers.length,r=t.length,n=[],a=Math.floor(r/s),o=r%s;let l=0,c=0;for(let u=0;u<s;u++){const f=this.workers[u];if(u<o?(l=u*a+u,c=l+a+1):(l=u*a+o,c=l+a),l=Math.min(l,r),c=Math.min(c,r),l>=c)break;S.debug("startIndex: "+l+" endIndex: "+c),n.push(f.generate(t.slice(l,c),e))}Promise.allSettled(n).then(()=>{this.running=!1,i()})})}dispose(){for(let t=0;t<this.workers.length;t++)this.workers[t].dispose();this.workers=[]}static createMeshBvhSync(t,e={}){const i=new Set;t.forEach(s=>{s.traverse(r=>{const n=r;if(n.isMesh&&n.geometry&&oe.isMergedMesh(n)&&!(n instanceof d.InstancedMesh)){if(i.has(n.geometry.id))return;n.geometry.index&&e.saveOriginalIndex&&(n.geometry.userData.originalIndex=n.geometry.index.array.slice()),n.geometry.boundsTree=new ks.MeshBVH(n.geometry,e),i.add(n.geometry.id)}})})}static createMeshBvhAsync(t,e={}){const i=new Set,s=[];t.forEach(n=>{n.traverse(a=>{const o=a;if(o.isMesh&&o.geometry&&oe.isMergedMesh(o)&&!(o instanceof d.InstancedMesh)){if(i.has(o.geometry.id))return;s.push(o.geometry),i.add(o.geometry.id)}})});const r=new Hs;return r.generate(s,e).then(()=>{r.dispose()})}}class Yh{constructor(t,e,i,s,r){p(this,"object");p(this,"camera");p(this,"targetPixelHeight",100);p(this,"canvasHeight",800);this.camera=t,this.object=i,this.targetPixelHeight=s,this.canvasHeight=r,this.adjustSize(),e.addEventListener("update",()=>{this.adjustSize()})}adjustSize(){const t=new d.Box3;if(this.object.updateMatrix(),t.expandByObject(this.object),!t)return;const e=t.max.x-t.min.x,i=this.camera.position.distanceTo(this.object.position),s=Xh(e,i,this.canvasHeight);if(Math.abs(s-this.targetPixelHeight)<5)return;let n=this.object.scale.x;n*=this.targetPixelHeight/s,this.object.scale.set(n,n,n),this.object.updateMatrix()}}const Xh=(h,t,e=800,i=45)=>{const s=i*(Math.PI/180),r=2*Math.tan(s/2)*t,n=h/r;return e*n},Di=new d.Vector2,Bi=new d.Vector2,Li=new d.Vector2,Xr=new d.Vector2,Zh=new d.Vector2,Kh=new d.Vector2,ce=class ce extends pt{constructor(e){super(V.guid());p(this,"needsFrustumCulled");p(this,"renderOrder");p(this,"snapType");p(this,"osnapInfo");p(this,"drawSnapFunctions");p(this,"snapLineVisible");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.snapType=tt.TripleCross,this.snapLineVisible=!1,this.snapType=e,this.drawSnapFunctions={TripleCross:this.drawTripleCorss.bind(this),Square:this.drawSquare.bind(this),Triangle:this.drawTriangle.bind(this),CircleWithCross:this.drawCircleWithCross.bind(this),Cross:this.drawCross.bind(this),Perpendicular:this.drawPerpendicular.bind(this)}}setSnapLineVisible(e){this.snapLineVisible=e}draw(e,i){this.osnapInfo&&(this.snapLineVisible&&this.drawSnapLine(e,i),e.save(),e.fillStyle=ce.FILL_COLOR_NONE,e.strokeStyle=ce.lineColor,e.lineWidth=ce.lineWidth,e.beginPath(),this.drawSnapFunctions[this.snapType](e,i),e.closePath(),e.fill(),e.stroke(),e.restore())}drawDebug(e,i){}drawSelect(e,i){}isPointInPath(e){return!1}drawSnapLine(e,i){e.save(),e.strokeStyle=ce.SNAP_LINE_COLOR,e.lineWidth=ce.lineWidth;const s=this.osnapInfo.line;if(!s)return;const r=this.transToScreenCoord(s.start,i),n=this.transToScreenCoord(s.end,i);e.moveTo(r.x,r.y),e.lineTo(n.x,n.y),e.stroke(),e.restore()}drawTripleCorss(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/1.6,n=Di.set(s.x,s.y-r),a=Bi.set(s.x-.87*r,s.y+r/1.4),o=Li.set(s.x+.87*r,s.y+r/1.4);e.moveTo(s.x,s.y),e.lineTo(n.x,n.y),e.moveTo(s.x,s.y),e.lineTo(a.x,a.y),e.moveTo(s.x,s.y),e.lineTo(o.x,o.y)}drawSquare(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize,n=ce.iconSize;e.rect(s.x-r/2,s.y-n/2,r,n)}drawTriangle(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/1.6,n=Di.set(s.x,s.y-r),a=Bi.set(s.x-.87*r,s.y+r/2),o=Li.set(s.x+.87*r,s.y+r/2);e.moveTo(n.x,n.y),e.lineTo(a.x,a.y),e.lineTo(o.x,o.y)}drawCircleWithCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2;e.arc(s.x,s.y,r,0,Math.PI*2),e.moveTo(s.x-r/1.8,s.y),e.lineTo(s.x+r/1.8,s.y),e.moveTo(s.x,s.y-r/1.8),e.lineTo(s.x,s.y+r/1.8)}drawCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2,n=Di.set(s.x-r,s.y-r),a=Bi.set(s.x+r,s.y+r),o=Li.set(s.x+r,s.y-r),l=Xr.set(s.x-r,s.y+r);e.moveTo(n.x,n.y),e.lineTo(a.x,a.y),e.moveTo(o.x,o.y),e.lineTo(l.x,l.y)}drawPerpendicular(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2,n=Di.set(s.x,s.y),a=Bi.set(s.x-r,s.y),o=Li.set(s.x,s.y+r),l=Xr.set(s.x-r,s.y-r),c=Zh.set(s.x-r,s.y+r),u=Kh.set(s.x+r,s.y+r);e.moveTo(a.x,a.y),e.lineTo(n.x,n.y),e.lineTo(o.x,o.y),e.moveTo(l.x,l.y),e.lineTo(c.x,c.y),e.lineTo(u.x,u.y),e.lineTo(l.x,l.y)}update(e){this.osnapInfo=e}getClassType(){return"SnapDrawable"}};p(ce,"lineColor","rgba(255, 119, 0, 1)"),p(ce,"FILL_COLOR_NONE","rgba(0, 0, 0, 0)"),p(ce,"SNAP_LINE_COLOR","rgba(255, 240, 0, 0.3)"),p(ce,"lineWidth",2),p(ce,"iconSize",14);let ye=ce;yi._registerDrawableClass(ye);var Hn=(h=>(h[h.None=0]="None",h[h.Vertex=1]="Vertex",h[h.MiddlePoint=2]="MiddlePoint",h[h.Edge=4]="Edge",h[h.Face=8]="Face",h[h.FootOfPerpendicular=16]="FootOfPerpendicular",h[h.Intersection=32]="Intersection",h[h.CircleCenter=64]="CircleCenter",h))(Hn||{});const $h=1e-5,se=new d.Vector3,fe=new d.Vector3,Ht=new d.Vector3,li=new d.Vector3,wt=new d.Matrix4,hi=new d.Line3;function Jh(h,t){let e=Number.MAX_VALUE,i=0;for(let s=0;s<h.vertices.length;s++){const r=t.distanceTo(h.vertices[s]);r<e&&(i=s,e=r)}return{vertex:h.vertices[i],distance:e}}function Qh(h){if(!(h.object instanceof d.Mesh)||!h.face)return;const t=h.object,e=t.geometry.attributes.position;let i=t.geometry.index;if(e.count<3)return;const s=oe.getBatchByFaceIndex(t,h.faceIndex);t.geometry.boundsTree&&(i=new d.BufferAttribute(t.geometry.userData.originalIndex,1,!1)),wt.identity(),t instanceof d.InstancedMesh&&h.instanceId!==void 0&&t.getMatrixAt(h.instanceId,wt),wt.premultiply(t.matrixWorld);const r=t.geometry.drawRange;let n,a=e.array;if(i){let m=Math.max(0,r.start),g=Math.min(i.count,r.start+r.count);if(n=i.array,s){m=Math.max(m,s.indexStart),g=Math.min(g,s.indexStart+s.indexCount),n=i.array.slice(m,g),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3);for(let x=0;x<n.length;x++)n[x]=n[x]-s.positionStart}else(m!==0||g!==i.count)&&(n=i.array.slice(m,g))}else{let m=Math.max(0,r.start),g=Math.min(e.count,r.start+r.count);s?(m=Math.max(m,s.positionStart),g=Math.min(g,s.positionStart+s.positionCount),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3)):(m!==0||g!==e.count)&&(a=e.array.slice(m*3,g*3));const x=a.length/3;n=x>65535?new Uint32Array(x):new Uint16Array(x);for(let y=0,T=x;y<T;y++)n[y]=y}const o=hn.buildEdge(a,n,20);let l=Number.MAX_VALUE,c=0;for(let m=0;m<o.length;m+=2){const g=o[m],x=o[m+1];se.set(a[g*3],a[g*3+1],a[g*3+2]),se.applyMatrix4(wt),fe.set(a[x*3],a[x*3+1],a[x*3+2]),fe.applyMatrix4(wt),hi.set(se,fe),hi.closestPointToPoint(h.point,!0,Ht);const y=h.point.distanceTo(Ht);y<l&&(c=m,l=y,li.copy(Ht))}const u=o[c],f=o[c+1];return se.set(a[u*3],a[u*3+1],a[u*3+2]),se.applyMatrix4(wt),fe.set(a[f*3],a[f*3+1],a[f*3+2]),fe.applyMatrix4(wt),{vertices:[se.clone(),fe.clone()],vertex:li.clone(),distance:l}}class ec{constructor(t){p(this,"drawableList",new $i("snap"));p(this,"overlayRender");p(this,"markers",{});p(this,"activeOSnapType",0);p(this,"snapToleranceInWorldCoord",1);p(this,"intersectionLimit",10);p(this,"osnapTypePriorities",{1:0,2:1,64:2,32:3,16:4,4:5,8:6,0:100});p(this,"enabledOSnapTypes",127);this.overlayRender=t,this.overlayRender?.addDrawableList(this.drawableList),this.initOSnapMarkers()}initOSnapMarkers(){const t=new ye(tt.TripleCross),e=new ye(tt.Square),i=new ye(tt.Triangle),s=new ye(tt.CircleWithCross),r=new ye(tt.Cross),n=new ye(tt.Perpendicular);this.markers[1]=e,this.markers[2]=i,this.markers[4]=t,this.markers[32]=r,this.markers[64]=s,this.markers[16]=n,Object.values(this.markers).forEach(a=>{a.visible=!1,this.drawableList.addDrawable(a)})}isOSnapTypeEnabled(t){return!!(this.enabledOSnapTypes&t)}setOSnapTypeEnabled(t,e){if(e)this.enabledOSnapTypes|=t;else{const i=~t;this.enabledOSnapTypes&=i}}setSnapTolerance(t){this.snapToleranceInWorldCoord=t}getSnapTolerance(){return this.snapToleranceInWorldCoord}setIntersectionLimit(t){this.intersectionLimit=t}getIntersectionLimit(){return this.intersectionLimit}getMarkerLineColor(){return Gt.colorStr2Rgba(ye.lineColor)}setMarkerLineColor(t){ye.lineColor=Gt.rgba2Color(t)}getMarkerLineWidth(){return ye.lineWidth}setMarkerLineWidth(t){ye.lineWidth=t}getMarkerIconSize(){return ye.iconSize}setMarkerIconSize(t){ye.iconSize=t}getMarker(t){return this.markers[t]}setAllSnapLinesVisible(t){Object.values(this.markers).forEach(e=>{e.setSnapLineVisible(t)})}deactivate(){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1,this.overlayRender?.render()),this.activeOSnapType=0}destroy(){}handleSnap(t,e,i){if(!t||t.length<1){this.deactivate();return}S.debug("[OSnap] intersections before handleSnap:",t);const s=[];let r=!1,n;for(const o of t)o.object instanceof d.Mesh?(!n&&(n=o.point),!r&&o.object.name!=="groundPlane"&&(s.push(o),r=!0)):s.push(o);if(!e&&n){n.setZ(0);for(const l of s)l.point.z=0,l.distance=l.point.distanceTo(n);const o=l=>l instanceof d.Points?0:l instanceof d.LineSegments?2:l instanceof d.Line?1:3;s.sort((l,c)=>{const u=o(l.object),f=o(c.object);return u!==f?u-f:l.distance-c.distance})}return n||(S.warn("[OSnap] Potential to produce erroneous snap results"),n=s[0].point),S.debug("[OSnap] intersections:",s),S.debug("[OSnap] mousePosition:",n),this.getSnapPointAndUpdateMarker(n,s,e,i)?.clone()||n}getSnapPointAndUpdateMarker(t,e,i,s){if(!e.length){this.activateMarker(0);return}const r=this.getSnapInfo(t,e,i,s);if(!r||r.type===0){this.activateMarker(0);return}return this.activateMarker(r.type,r),r.point}activateMarker(t,e){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1),this.activeOSnapType=t;const i=this.markers[t];i&&e&&(i.update(e),i.visible=!0),this.overlayRender?.render()}getFootOfPerpendicular(t,e,i=$h){const{start:s,end:r}=e,n=s.x-r.x,a=s.y-r.y,o=s.z-r.z;if(s.distanceTo(r)<i)return s.clone();let l=(t.x-s.x)*(s.x-r.x)+(t.y-s.y)*(s.y-r.y)+(t.z-s.z)*(s.z-r.z);return l=l/(n*n+a*a+o*o),new d.Vector3(s.x+l*n,s.y+l*a,s.z+l*o)}getSnapInfo(t,e,i,s){const r=this.snapToleranceInWorldCoord*2;S.debug("[OSnap] snap radius:",r);const n=[],a={line:void 0};let o=this.osnapTypePriorities[0];for(let l=0;l<e.length&&l<this.intersectionLimit;++l){const c=e[l],u=c.object;let f;u instanceof d.Mesh?f=this.getOsnapInfoListFromMesh(t,c,r,o):u instanceof d.Line?f=this.getOsnapInfoListFromLine(t,c,i,r,a,o,s):u instanceof d.Points&&(f=this.getOsnapInfoListFromPoint(t,c,i,r,o)),f&&(o=this.osnapTypePriorities[f.type],n.push(f))}if(n.length!==0)return n.sort((l,c)=>{const u=this.osnapTypePriorities[l.type],f=this.osnapTypePriorities[c.type];return u!==f?u-f:l.distance-c.distance}),n[0]}getOsnapInfoListFromMesh(t,e,i,s){if(s<this.osnapTypePriorities[1])return;const r=Date.now(),n=Qh(e);if(!n){S.warn("[OSnap] Failed to get edge !");return}const a=Date.now();S.debug("[OSnap] getEdgeSnappingInfo took "+(a-r)/1e3+"s "),S.debug("[OSnap] edge:",n);const o=Jh(n,t);if(S.debug("[OSnap] vertex:",o),o.distance<=i&&this.isOSnapTypeEnabled(1))return{distance:o.distance,type:1,point:o.vertex};if(n.distance<=i){if(this.isOSnapTypeEnabled(2)&&s<this.osnapTypePriorities[2])return;se.copy(n.vertices[0]),se.add(n.vertices[1]),se.divideScalar(2);const l=se.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:se.clone()}:!this.isOSnapTypeEnabled(4)||s<this.osnapTypePriorities[4]?void 0:{distance:n.distance,type:4,point:n.vertex,line:{start:n.vertices[0],end:n.vertices[1]}}}else S.debug("[OSnap] Face")}getOsnapInfoFromSegment(t,e,i,s,r,n,a){const o={start:e,end:i};if(a&&n>=this.osnapTypePriorities[16]&&this.isOSnapTypeEnabled(16)){const m=this.getFootOfPerpendicular(a,o,s),g=t.distanceTo(m);if(g<=s)return{distance:R.floorNumber(g,7),type:16,point:m.clone()}}if(n<this.osnapTypePriorities[1])return;hi.set(e,i),hi.closestPointToPoint(t,!0,Ht);const l=t.distanceTo(Ht);if(l>s)return;const c=t.distanceTo(e),u=t.distanceTo(i);if(Math.min(c,u)<=s&&this.isOSnapTypeEnabled(1)){let m=c,g=e;return u<c&&(m=u,g=i),{distance:R.floorNumber(m,7),type:1,point:g.clone()}}if(n<this.osnapTypePriorities[2])return;hi.getCenter(li);const f=t.distanceTo(li);if(f<s&&this.isOSnapTypeEnabled(2))return{point:li.clone(),distance:R.floorNumber(f,7),type:2};if(!(n<this.osnapTypePriorities[4])){if(r.line&&this.isOSnapTypeEnabled(32)){const m=U.getLineSegmentsIntersectingPoint(r.line,o);if(!m)return;const g=t.distanceTo(m)/2;return g<s?(r.line=void 0,{point:m.clone(),distance:R.floorNumber(g,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return r.line={start:e.clone(),end:i.clone()},{point:Ht.clone(),distance:R.floorNumber(l,7),type:4,line:{start:e.clone(),end:i.clone()}}}}getOsnapInfoListFromLine(t,e,i,s,r,n,a){const o=[],l=e.object,c=l instanceof d.LineSegments?2:1,u=l.geometry.index,f=l.geometry.attributes.position,m=l.geometry.drawRange,g=oe.getBatchByLineIndex(l,e.index);if(u){let x=Math.max(0,m.start),y=Math.min(u.count,m.start+m.count);g&&(x=Math.max(x,g.indexStart),y=Math.min(y,g.indexStart+g.indexCount));for(let T=x,v=y;T<v-1;T+=c){const b=u.getX(T),E=u.getX(T+1);se.fromBufferAttribute(f,b),fe.fromBufferAttribute(f,E),se.applyMatrix4(l.matrixWorld),fe.applyMatrix4(l.matrixWorld),!i&&(se.setZ(0),fe.setZ(0));const O=this.getOsnapInfoFromSegment(t,se,fe,s,r,n,a);O&&(n=this.osnapTypePriorities[O.type],o.push(O))}}else{let x=Math.max(0,m.start),y=Math.min(f.count,m.start+m.count);g&&(x=Math.max(x,g.positionStart),y=Math.min(y,g.positionStart+g.positionCount));for(let T=x,v=y;T<v-1;T+=c){se.fromBufferAttribute(f,T),fe.fromBufferAttribute(f,T+1),se.applyMatrix4(l.matrixWorld),fe.applyMatrix4(l.matrixWorld),!i&&(se.setZ(0),fe.setZ(0));const b=this.getOsnapInfoFromSegment(t,se,fe,s,r,n,a);b&&(n=this.osnapTypePriorities[b.type],o.push(b))}}if(o.length!==0)return o.sort((x,y)=>{const T=this.osnapTypePriorities[x.type],v=this.osnapTypePriorities[y.type];return T!==v?T-v:x.distance-y.distance}),o[0]}getOsnapInfoListFromPoint(t,e,i,s,r){if(r<this.osnapTypePriorities[1])return;const n=e.object,a=n.geometry.getAttribute("position");se.fromBufferAttribute(a,e.index),se.applyMatrix4(n.matrixWorld),fe.copy(t),!i&&(se.setZ(0),fe.setZ(0));const o=fe.distanceTo(se);if(o>s)return;const l={distance:o,point:se.clone(),type:1};if(n.userData.type==="CircleCenter"){if(!this.isOSnapTypeEnabled(64))return;l.type=64}else if(S.debug("[OSnap] Other types of vertices !"),!this.isOSnapTypeEnabled(1))return;return l}getIntersectsIncludeOutline(t,e){const i=t.slice(),s=[];for(let n=0;n<t.length&&n<this.intersectionLimit;n++){const a=t[n].object;if(a.updateWorldMatrix(!0,!1),a instanceof d.Mesh&&!$.hasOutline(a,!1)){const o=$.createOutline(a.geometry);o.visible=!1,a.add(o),o.updateWorldMatrix(!0,!1),s.push(o)}}let r=[];return s.length>0&&(r=e.intersectObjects(s)||[],S.debug("[OSnap] Intersected with newly created edges: ",r),r.length>0&&i.push(...r)),i.sort((n,a)=>n.distance-a.distance),i}}class Gn{constructor(t,e,i){p(this,"node");p(this,"parentNode");p(this,"target");p(this,"childNode");p(this,"follow",t=>{this.node.style.left=t.offsetX+15+"px",this.node.style.top=t.offsetY-30+"px"});p(this,"show",()=>this.node.hasAttribute("hidden")&&this.node.removeAttribute("hidden"));p(this,"hide",()=>!this.node.hasAttribute("hidden")&&this.node.setAttribute("hidden",""));p(this,"destroy",()=>{this.target?this.target.removeEventListener("mousemove",this.follow):document.removeEventListener("mousemove",this.follow),this.parentNode.removeChild(this.node)});this.node=document.createElement("div"),this.node.id=t,e&&this.node.append(e),this.childNode=document.createElement("div"),this.target=i?.target,this.parentNode=i?.parentNode||document.body,i?.followPointer&&(this.node.classList.add("follow-tooltip"),this.target?this.target.addEventListener("mousemove",this.follow):document.addEventListener("mousemove",this.follow)),this.parentNode.appendChild(this.node),!i?.showOnCreate&&this.node.setAttribute("hidden","")}setContent(t){this.node.textContent&&(this.node.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.node.append(t),this.node.appendChild(this.childNode)}updateChildContent(t){this.childNode.textContent&&(this.childNode.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.childNode.append(t)}}class tc{constructor(t){p(this,"viewer");p(this,"active",!1);p(this,"tooltip");p(this,"resolve");p(this,"reject");p(this,"isResolvedOrRejected",!1);p(this,"mouseClicked",t=>{const e=t;if(e.markupData){const i=e.markupData.id,s=this.viewer.getOverlayRender().getDrawableById(i);if(s){let r=s.getBounds();r=r.clone().expandByScalar(20*this.viewer.getPixelSizeInWorldCoord());const n=pe.world2NormalizedScreen(r.min,this.camera,this.viewerContainer),a=pe.world2NormalizedScreen(r.max,this.camera,this.viewerContainer),o=new d.Box2(new d.Vector2(Math.min(n.x,a.x),Math.min(n.y,a.y)),new d.Vector2(Math.max(n.x,a.x),Math.max(n.y,a.y)));o.min.x=Math.max(o.min.x,0)*this.viewerContainer.clientWidth,o.min.y=Math.max(o.min.y,0)*this.viewerContainer.clientHeight,o.max.x=Math.min(o.max.x,1)*this.viewerContainer.clientWidth,o.max.y=Math.min(o.max.y,1)*this.viewerContainer.clientHeight,this.resolve&&(this.resolve(o),this.isResolvedOrRejected=!0),this.deactivate();const l=this.viewer;typeof l.clearSelection=="function"&&l.clearSelection()}}});p(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("PickMarkupHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.viewer.addEventListener(re.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new Gn("pick-markup-tooltip",Re.t("Tooltip.pickMarkup"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("pick-markup-tooltip");t&&(t.style.pointerEvents="none");const e=Re.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(re.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(re.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(re.PickMarkupDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}async pick(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),!this.isResolvedOrRejected&&this.reject&&this.reject("PickMarkupHelper is not done for some reason!")}}const Ut=class Ut{constructor(t){p(this,"viewer");p(this,"input");p(this,"mouseDown",!1);p(this,"mouseMove",!1);p(this,"mouseDownPositionX",-1);p(this,"mouseDownPositionY",-1);p(this,"tempKey");p(this,"tempTouch");p(this,"tempEnableRotate",!1);p(this,"rectDom");p(this,"tooltip");p(this,"active",!1);p(this,"resolve");p(this,"reject");p(this,"isResolvedOrRejected",!1);p(this,"mousedown",t=>{if(t.button===0){this.mouseDown=!0;const e=new d.Vector2(t.x,t.y);this.mouseDownPositionX=e.x,this.mouseDownPositionY=e.y,this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0}});p(this,"mousemove",t=>{if(!this.mouseDown)return;const e=new d.Vector2(t.x,t.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(e.x-this.mouseDownPositionX)>=5||Math.abs(e.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const s=new d.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),r=new d.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y));this.drawRect(s,r)}});p(this,"mouseup",t=>{if(this.mouseDown&&this.mouseMove){const e=new d.Vector2(t.x,t.y),i=new d.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),s=new d.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y)),r=new d.Box2(i,s);this.resolve&&(this.resolve(r),this.isResolvedOrRejected=!0),this.deactivate(),this.setRectDomVisible(!1)}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1});p(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t,this.input=t.getInputManager()}get viewerContainer(){return this.viewer.viewerContainer}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("BoxSelectHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.input.addEventListener("pointerdown",this.mousedown),this.input.addEventListener("pointermove",this.mousemove),this.input.addEventListener("pointerup",this.mouseup),this.input.addEventListener("keydown",this.keydown),this.viewer.getCameraManager().enableMouseLeft(!1),this.tooltip=new Gn("box-select-tooltip",Re.t("Tooltip.boxSelect"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("box-select-tooltip");t&&(t.style.pointerEvents="none");const e=Re.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(re.BoxSelectActivate)}deactivate(){this.active=!1,this.input.removeEventListener("pointerdown",this.mousedown),this.input.removeEventListener("pointermove",this.mousemove),this.input.removeEventListener("pointerup",this.mouseup),this.input.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.getCameraManager().enableMouseLeft(!0),this.viewer.dispatchEvent(re.BoxSelectDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}drawRect(t,e){!this.rectDom&&(this.rectDom=document.createElement("div"),this.rectDom.style.cssText=`position: absolute;border: ${Ut.BORDER_WIDTH} solid ${Ut.BORDER_COLOR};`,this.viewerContainer.appendChild(this.rectDom)),this.setRectDomVisible(!0),this.rectDom.style.left=t.x+"px",this.rectDom.style.top=t.y+"px";const i=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y);this.rectDom.style.width=i+"px",this.rectDom.style.height=s+"px"}setRectDomVisible(t){this.rectDom&&(this.rectDom.style.display=t?"inline-block":"none")}async select(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),this.rectDom?.remove(),this.rectDom=void 0,!this.isResolvedOrRejected&&this.reject&&this.reject("BoxSelectHelper is not done for some reason!")}};p(Ut,"BORDER_COLOR","#fff000"),p(Ut,"BORDER_WIDTH","2px");let Ki=Ut;class qn{constructor(t){p(this,"viewer");p(this,"boxSelectHelper");p(this,"active",!1);this.viewer=t,this.boxSelectHelper=new Ki(t)}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}isActive(){return this.active}activate(){this.active=!0,this.boxSelectHelper?.select().then(t=>{t&&this.handleZoomToRect(t.min,t.max)})}deactivate(){this.active=!1,this.boxSelectHelper?.deactivate()}pickPositionByScreenPoint(t){return this.viewer.pickObject(t)?.point}handleZoomToRect(t,e){const i=this.pickPositionByScreenPoint(t),s=this.pickPositionByScreenPoint(e);if(i&&s){const r=new d.Vector3(Math.min(i.x,s.x),Math.min(i.y,s.y),Math.min(i.z,s.z)),n=new d.Vector3(Math.max(i.x,s.x),Math.max(i.y,s.y),Math.max(i.z,s.z)),a=new d.Box3(r,n);this.viewer.zoomToBBox(a)}}destroy(){this.boxSelectHelper?.destroy(),this.boxSelectHelper=void 0}}function Zr(h){return h?h.replace(/%%[dD]/g,"°").replace(/%%[cC]/g,"⌀").replace(/%%[pP]/g,"±").replace(/%%(U|O)/gi,"").replace(/\\P/g," ").replace(/\\[A-Za-z][^;\\]*;/g,"").replace(/[{}]/g,"").replace(/\\\\/g,"\\").replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))).trim():""}const Ri=new d.Box3,ic=new d.Vector3;function sc(h,t){return h.trim().toLowerCase()===t?2e6:0}function rc(h,t){const e=h.toLowerCase(),i=e.indexOf(t);if(i>=0)return(e===t?2e6:1e6)+(1e3-i)-Math.min(e.length,500);let s=0,r=-1,n=-1,a=0;for(let l=0;l<t.length;l++){const c=t[l];let u=-1;for(;s<e.length;s++)if(e[s]===c){u=s;break}if(u<0)return 0;r<0?r=u:n>=0&&u-n>1&&(a+=u-n-1),n=u,s=u+1}const o=5e5-a*50-r*5-Math.min(e.length,500);return o>0?o:1}class Is{constructor(t){p(this,"viewer");p(this,"overlayRender");p(this,"drawableList");p(this,"indexedModelObject");p(this,"index",[]);this.viewer=t,this.overlayRender=this.viewer.getOverlayRender()}getMasterModel(){return this.viewer.loadedModels.find(t=>this.viewer.masterModelId===t.modelId)}buildIndex(){const t=this.getMasterModel();if(!t){this.index=[],this.indexedModelObject=void 0;return}const e=t.getModelObject();if(e===this.indexedModelObject&&this.index.length>0)return;this.indexedModelObject=e,this.index=[];const i=new d.Matrix4,s=new d.Vector3,r=new Map;e.updateWorldMatrix(!0,!0);const n=(a,o,l,c,u)=>{if(a&&r.has(a)){r.get(a).box.union(u);return}r.set(a||o+c,{text:o,layer:l,layoutName:c,box:u.clone()})};e.traverse(a=>{const o=a.userData;if(o){if(typeof o.textContent=="string"&&o.textContent.length){const l=Zr(o.textContent);if(!l||(Ri.makeEmpty(),Ri.setFromObject(a),Ri.isEmpty()))return;n(o.handle||"",l,o.layer||"0",this.findLayoutName(a),Ri);return}if(Array.isArray(o.batches)){const l=a.geometry?.getAttribute?.("position");if(!l)return;i.copy(a.matrixWorld);for(const c of o.batches){const u=c?.userData?.textContent;if(typeof u!="string"||!u.length)continue;const f=Zr(u);if(!f)continue;const m=new d.Box3,g=c.positionStart||0,x=c.positionCount||0;for(let y=g;y<g+x;y++)s.fromBufferAttribute(l,y).applyMatrix4(i),m.expandByPoint(s);m.isEmpty()||n(c.userData.handle||"",f,c.userData.layer||"0",this.findLayoutName(a),m)}}}}),r.forEach((a,o)=>{this.index.push({handle:o,layer:a.layer,layoutName:a.layoutName,text:a.text,box:a.box})})}findLayoutName(t){let e=t;for(;e;){if(e.userData?.isLayoutLevelObject===!0)return e.name||"Model";e=e.parent}return"Model"}search(t,e){const i=(t||"").trim().toLowerCase();if(!i)return[];this.buildIndex();const s=e?.mode??"fuzzy",r=e?.layer?.trim().toLowerCase(),n=e?.maxResults??200,a=[];for(const o of this.index){if(r&&o.layer.toLowerCase()!==r)continue;const l=s==="exact"?sc(o.text,i):rc(o.text,i);l>0&&a.push({item:o,score:l})}return a.sort((o,l)=>l.score-o.score),a.slice(0,n).map(o=>o.item)}focus(t){if(!t)return;this.viewer.activateLayout(t.layoutName),this.highlight(t);const e=t.box.clone();this.viewer.zoomToBBox(e.expandByScalar(Math.max(e.getSize(ic).length()*.5,1)))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new $i("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new rt(V.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 nc extends pt{constructor(e){super("MobileHelper");p(this,"position");p(this,"needsFrustumCulled");p(this,"renderOrder");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.position=e}setPosition(e){this.position=e}isPointInPath(e,i){return!1}draw(e,i){this.drawInnerCircle(e),this.drawOuterRing(e),this.drawSnapTriangle(e)}drawInnerCircle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(137, 137, 138, 0.8)",e.beginPath(),e.arc(i,s,25,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}drawOuterRing(e){const{x:i,y:s}=this.position;e.save(),e.strokeStyle="rgba(17, 17, 19, 0.8)",e.lineWidth=10,e.beginPath(),e.arc(i,s,30,0,Math.PI*2),e.closePath(),e.stroke(),e.restore(),e.save(),e.strokeStyle="rgba(173, 173, 174, 0.8)",e.lineWidth=3,e.beginPath(),e.arc(i,s,35,0,Math.PI*2),e.closePath(),e.stroke(),e.restore()}drawSnapTriangle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(17, 17, 19, 0.8)",e.strokeStyle="rgba(137, 137, 138, 0.8)",e.lineWidth=2,e.beginPath(),e.moveTo(i-35,s-35),e.lineTo(i-35+12,s-35),e.lineTo(i-35,s-35+12),e.closePath(),e.fill(),e.stroke(),e.restore()}translate(e,i){this.position.add(new d.Vector2(e,i))}getTouchPoint(){return{x:this.position.x-35,y:this.position.y-35}}isIntersect(e){return this.position.x-35<e.x&&this.position.y-35<e.y&&this.position.x+35>e.x&&this.position.y+35>e.y}drawSelect(e,i){}getClassType(){return"MobileTouchHelperDrawable"}}var Le=(h=>(h[h.Left=0]="Left",h[h.Middle=1]="Middle",h[h.Right=2]="Right",h[h.Back=3]="Back",h[h.Forward=4]="Forward",h))(Le||{});class Wn extends mt{constructor(e){super();p(this,"element");p(this,"enabled");p(this,"keyboardEnabled");p(this,"mouseDownPositionX");p(this,"mouseDownPositionY");p(this,"lastLeftPointerUpTime");p(this,"pointers");p(this,"handleClick");p(this,"handlePointerDown");p(this,"handlePointerMove");p(this,"handlePointerUp");p(this,"handlePointerCancel");p(this,"handleMouseWheel");p(this,"handleContextMenu");p(this,"handlePointerEnter");p(this,"handlePointerLeave");p(this,"handleResize");p(this,"handleKeydown");p(this,"handleKeyup");p(this,"style");this.enabled=!0,this.keyboardEnabled=!0,this.mouseDownPositionX=0,this.mouseDownPositionY=0,this.lastLeftPointerUpTime=0,this.pointers=[],this.handleClick=i=>{if(!this.enabled)return;const s=this.getBaseEvent(i);this.dispatchEvent("click",s)},this.handlePointerDown=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isDoubleClick(s)?(this.lastLeftPointerUpTime=0,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.dispatchEvent("dblclick",s)):(this.mouseDownPositionX=s.x,this.mouseDownPositionY=s.y),this.dispatchEvent("pointerdown",s),i.pointerType==="touch"?(this.pointers.push(s),s.pointers=this.pointers,this.dispatchEvent("touchstart",s)):this.dispatchEvent("mousedown",s)},this.handlePointerMove=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isCloseToLastPosition(s)||(this.dispatchEvent("pointermove",s),i.pointerType==="touch"?(this.updatePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchmove",s)):this.dispatchEvent("mousemove",s))},this.handlePointerUp=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);s.button===0&&(this.lastLeftPointerUpTime=s.timestamp),this.dispatchEvent("pointerup",s),i.pointerType==="touch"?(this.removePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchend",s)):this.dispatchEvent("mouseup",s)},this.handlePointerCancel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointercancel",this.getBaseEvent(i)))},this.handleMouseWheel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("wheel",this.getBaseEvent(i)))},this.handleContextMenu=i=>{if(this.enabled)return this.stop(i),this.dispatchEvent("contextmenu",this.getBaseEvent(i)),!1},this.handlePointerEnter=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerenter",this.getBaseEvent(i)))},this.handlePointerLeave=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerleave",this.getBaseEvent(i)))},this.handleResize=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("resize",this.getBaseEvent(i)))},this.handleKeydown=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keydown",this.getBaseEvent(i))},this.handleKeyup=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keyup",this.getBaseEvent(i))},this.style={},this.element=e,this.bindEvents()}getEnabled(){return this.enabled}setEnabled(e){this.enabled=e}getkKeyboardEnabled(){return this.keyboardEnabled}setkKeyboardEnabled(e){this.keyboardEnabled=e}setCursor(e){this.element.style&&(this.element.style.cursor=e||"default")}bindEvents(){this.element.style.touchAction="none",this.element.style.userSelect="none",this.element.style.webkitUserSelect="none",this.element.addEventListener("click",this.handleClick),this.element.addEventListener("pointerdown",this.handlePointerDown),this.element.addEventListener("pointermove",this.handlePointerMove),this.element.addEventListener("pointerup",this.handlePointerUp),this.element.addEventListener("pointercancel",this.handlePointerCancel),this.element.addEventListener("pointerenter",this.handlePointerEnter),this.element.addEventListener("pointerleave",this.handlePointerLeave),this.element.addEventListener("contextmenu",this.handleContextMenu),this.element.addEventListener("wheel",this.handleMouseWheel,{passive:!1}),window.addEventListener("resize",this.handleResize),window.addEventListener("keydown",this.handleKeydown),window.addEventListener("keyup",this.handleKeyup)}unBindEvents(){this.element.removeEventListener("pointerdown",this.handlePointerDown),this.element.removeEventListener("pointermove",this.handlePointerMove),this.element.removeEventListener("pointerup",this.handlePointerUp),this.element.removeEventListener("pointerenter",this.handlePointerEnter),this.element.removeEventListener("pointerleave",this.handlePointerLeave),this.element.removeEventListener("contextmenu",this.handleContextMenu),this.element.removeEventListener("wheel",this.handleMouseWheel),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),window.removeEventListener("keyup",this.handleKeyup),this.element.style.touchAction="",this.element.style.userSelect="",this.element.style.webkitUserSelect=""}getBaseEvent(e){const i=e,s={x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0,deltaX:0,deltaY:0,movementX:0,movementY:0,deltaMode:0,pointerId:0,timestamp:0,buttons:0,pointerType:"mouse",altKey:!1,ctrlKey:!1,shiftKey:!1,metaKey:!1,originalEvent:i};if(s.timestamp=i.timeStamp,Fi(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,Fi(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const r=pe.getScreenCoordinateByEvent(i,this.element);s.x=r.x,s.y=r.y,s.movementX=i.movementX,s.movementY=i.movementY}else Fi(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else Fi(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 Fi(h,t){return h[t]!==void 0}class ac{constructor(t){p(this,"CLEAR_COLOR");p(this,"CLEAR_COLOR_ALPHA");p(this,"EMPTY_MODEL_ID");p(this,"viewer");p(this,"raycaster");p(this,"pickingTexture");this.CLEAR_COLOR=new d.Color().setRGB(1,1,1),this.CLEAR_COLOR_ALPHA=1,this.EMPTY_MODEL_ID=255,this.viewer=t,this.raycaster=new d.Raycaster,this.pickingTexture=new d.WebGLRenderTarget(1,1)}get scene(){return this.viewer.scene}get camera(){return this.viewer.camera}get renderer(){return this.viewer.renderer}get overlayRender(){return this.viewer.getOverlayRender()}get viewerContainer(){return this.viewer.viewerContainer}getRaycaster(){return this.raycaster}pickObjectsByNdc(t,e,i){return!e||e.length===0?[]:(this.raycaster.setFromCamera(t,this.camera),this.setLayerChannels(i),this.raycaster.intersectObjects(e,!0)||[])}pickObject(t,e,i,s){const r=this.pickObjects(t,e,i,s);if(r.length!==0)return r[0]}pickObjects(t,e,i,s=0){const r=pe.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const n=[],a=new Map,o=pe.screen2Ndc(t,this.camera,this.viewerContainer),l=pe.screen2Ndc({x:t.x+s,y:t.y},this.camera,this.viewerContainer),c=new d.Vector3(o.x,o.y,0).unproject(this.camera),u=new d.Vector3(l.x,l.y,0).unproject(this.camera),f=c.distanceTo(u),m=this.raycaster.params.Line.threshold;this.raycaster.params.Line.threshold=f,this.setLayerChannels(i);const g=8;for(let y=0;y<g;y++){const T=y/g*Math.PI*2,v=Math.cos(T)*s,b=Math.sin(T)*s,E={x:t.x+v,y:t.y+b},O=pe.screen2Ndc(E,this.camera,this.viewerContainer);this.raycaster.setFromCamera(O,this.camera),this.raycaster.layers.enableAll();const _=this.raycaster.intersectObjects(e,!0)||[];for(const C of _)C.object&&!a.has(C.object.uuid)&&(a.set(C.object.uuid,C),n.push(C))}this.raycaster.setFromCamera(o,this.camera);const x=this.raycaster.intersectObjects(e,!0)||[];for(const y of x)y.object&&!a.has(y.object.uuid)&&(a.set(y.object.uuid,y),n.push(y));if(this.raycaster.params.Line.threshold=m,n.length>1){const y=this.raycaster.ray.origin.clone();n.sort((T,v)=>{const b=T.point||T.object.getWorldPosition(new d.Vector3),E=v.point||v.object.getWorldPosition(new d.Vector3);return b.distanceTo(y)-E.distanceTo(y)})}return n}return this.pickObjectsByNdc(r,e,i)}pickDrawable(t){return this.overlayRender.getDrawablesByPosition(t)}pick(t,e){const i=this.pickBuffer(t,e),s=[i[0],i[1],i[2],i[3]],r=Oh(s),n=Eh(s);if(r!==this.EMPTY_MODEL_ID)return S.info("[PickMgr] Picked: tilesetId("+r+"), userId("+n+")"),{tilesetId:r,userId:n}}setLayerChannels(t){t&&t.length>0?(this.raycaster.layers.disableAll(),t.forEach(e=>{this.raycaster.layers.enable(e)})):this.raycaster.layers.enableAll()}pickBuffer(t,e,i=1,s=1){const{pickingTexture:r,renderer:n,camera:a}=this;r.setSize(i,s);const o=n.getPixelRatio(),l=n.getContext().drawingBufferWidth,c=n.getContext().drawingBufferHeight,u=t.x*o|0,f=t.y*o|0;a.setViewOffset(l,c,u,f,i,s),n.setRenderTarget(r);const m=new d.Color;n.getClearColor(m);const g=n.getClearAlpha();n.setClearColor(this.CLEAR_COLOR,this.CLEAR_COLOR_ALPHA),n.render(e,a);const x=new Uint8Array(4*i*s);return n.readRenderTargetPixels(r,0,0,i,s,x),n.setRenderTarget(null),a.clearViewOffset(),n.setClearColor(m,g),x}}const Kr=new d.Vector3;class oc{constructor(t){p(this,"viewer");p(this,"scene");p(this,"renderer");p(this,"pmremGenerator");p(this,"lights");p(this,"modelGroup");this.viewer=t;const e=new d.Scene;e.matrixAutoUpdate=He,e.matrixWorldAutoUpdate=He,this.scene=e,this.modelGroup=new d.Group,this.modelGroup.name="models",this.scene.add(this.modelGroup);const{width:i,height:s,viewerContainer:r}=t.container,n=new d.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0});n.setPixelRatio(window.devicePixelRatio),n.setSize(i,s),n.outputColorSpace=d.SRGBColorSpace,n.toneMappingExposure=1,n.localClippingEnabled=!0,n.shadowMap.enabled=!1,n.shadowMap.type=d.PCFSoftShadowMap,n.shadowMap.autoUpdate=!1,n.domElement.style.outlineWidth="0",r?.appendChild(n.domElement),this.renderer=n,V.printGpuInfo(n.getContext())}initLights(){const t=new d.Group;t.name="lights";const e=1.5,i=16777215,s=new d.DirectionalLight(i,e);s.name="sun",s.castShadow=!0,s.position.set(-2,2,4),s.shadow.autoUpdate=!1,s.shadow.mapSize.width=1024,s.shadow.mapSize.height=1024;const r=new d.AmbientLight(i);r.name="ambient";const n=new d.HemisphereLight(i,14540253,.2);n.name="hemisphere",n.position.set(0,300,0);const a=new d.Group;a.name="lightHelpers",a.visible=!1;const o=new d.DirectionalLightHelper(s),l=new d.CameraHelper(s.shadow.camera);return a.add(o),a.add(l),t.add(s),t.add(s.target),t.add(r),t.add(n),t.add(a),this.scene.add(t),this.lights=t,t}initPMREMGenerator(){this.pmremGenerator=new d.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()}get maxFragmentUniforms(){return this.renderer.capabilities.maxFragmentUniforms-20}addModel(t){this.modelGroup.add(t.getModelObject())}enableShadow(t){this.renderer.shadowMap.enabled=t,this.directionalLight.castShadow=t,t&&(this.tryAdjustDirectionalLight(),this.updateDirectionalLightShadow()),this.modelGroup.traverse(e=>{e.isMesh&&(e.castShadow=t,e.receiveShadow=t)})}enableClipping(t){this.renderer.localClippingEnabled=t}setClipPlanes(t){this.renderer.clippingPlanes=t}enableLights(t){let e=this.lights;e||(e=this.initLights()),e.visible=t}debugLights(t){!this.lights||!this.lightHelpers||(this.lightHelpers.visible=t)}setBackground(t){this.scene.background=t}get directionalLight(){return this.lights?.getObjectByName("sun")}get ambientLight(){return this.lights?.getObjectByName("ambient")}get hemisphereLight(){return this.lights?.getObjectByName("hemisphere")}get lightHelpers(){return this.lights?.getObjectByName("lightHelpers")}get directionalLightHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];if(i instanceof d.DirectionalLightHelper){t=i;break}}return t}get cameraHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];i instanceof d.CameraHelper&&(t=i)}return t}async setEnvironmentFromData(t){this.pmremGenerator||this.initPMREMGenerator();const e=await fi.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await fi.createEnvTexture(this.pmremGenerator,t);this.scene.environment?.dispose(),this.scene.environment=e}resize(){const{width:t,height:e}=this.viewer.container;this.renderer.setSize(t,e)}getRaycastableObjects(){const t=[];return this.modelGroup.traverse(e=>{t.push(e)}),t}tryAdjustDirectionalLight(){const t=this.directionalLight;if(!t)return;const e=this.viewer.getBBox(),i=new d.Sphere;e.getBoundingSphere(i);const s=i.center,r=i.radius,n=t.shadow.camera;n.zoom=1,n.top=r,n.bottom=-r,n.right=r,n.left=-r,n.near=.1,n.far=2*r,n.updateProjectionMatrix();const a=new d.Vector3(-1,-.5,1);a.normalize().multiplyScalar(r),t.position.copy(s).addScaledVector(a,-1),t.target.position.copy(s),S.debug("[Scene] directionalLight.position",t.position),S.debug("[Scene] directionalLight.target.position",t.target.position),this.updateDirectionalLight(),this.viewer.enableRender()}updateDirectionalLight(){const t=this.directionalLight;if(t&&(t.updateMatrixWorld(),t.target.updateMatrixWorld(),this.directionalLightHelper&&(this.directionalLightHelper.update(),this.scene?.matrixAutoUpdate||this.directionalLightHelper.updateWorldMatrix(!1,!0)),t.shadow.needsUpdate=!0,t.shadow.camera.updateProjectionMatrix(),this.cameraHelper&&(this.cameraHelper.update(),!this.scene?.matrixAutoUpdate))){const e=t.shadow.camera;e.position.setFromMatrixPosition(t.matrixWorld),Kr.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Kr),e.updateMatrixWorld(),this.cameraHelper.updateWorldMatrix(!1,!0)}}updateDirectionalLightShadow(){this.directionalLight&&(this.directionalLight.shadow.needsUpdate=!0)}showDirectionalLightHelper(t){this.directionalLightHelper&&(this.directionalLightHelper.visible=t),this.cameraHelper&&(this.cameraHelper.visible=t)}destroy(){this.lightHelpers?.clear(),this.lightHelpers?.removeFromParent(),this.lightHelpers?.traverse(t=>{t.dispose?.call(t)}),this.lights?.clear(),this.lights?.removeFromParent(),this.lights?.traverse(t=>{t.dispose?.call(t)}),this.lights=void 0,this.pmremGenerator?.dispose(),this.renderer.domElement.remove(),this.renderer.clear(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.scene.clear()}}class lc{constructor(t){p(this,"history");p(this,"step");p(this,"maxCount");p(this,"isBatchCommand");p(this,"batchCommands");this.history=[],this.step=0,this.maxCount=50,this.isBatchCommand=!1,this.batchCommands=[],this.maxCount=t||this.maxCount}addCommand(t){this.isBatchCommand?this.batchCommands.push(t):(this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.history.push(t),this.step++)}startTransaction(){this.isBatchCommand=!0}endTransaction(){this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.batchCommands.length>0&&(this.history.push(this.batchCommands.slice()),this.step++),this.isBatchCommand=!1,this.batchCommands=[]}undo(){if(this.canUndo())return!1;this.step--;const t=this.history[this.step];return t&&(Array.isArray(t)?t.forEach(e=>e.undo()):t.undo()),!0}redo(){if(this.canRedo())return!1;this.step++;const t=this.history[this.step-1];return t&&(Array.isArray(t)?t.forEach(e=>e.redo()):t.redo()),!0}getCommands(){return this.history}canUndo(){return this.step<=0}canRedo(){return this.step>=this.history.length}clear(){this.history=[],this.step=0}destroy(){this.clear(),this.maxCount=0}}class Qi extends mt{constructor(e){super();p(this,"name");p(this,"viewerCfg");p(this,"clock");p(this,"targetMaxFps");p(this,"timeStamp");p(this,"renderEnabled");p(this,"requestAnimationFrameHandle");p(this,"container");p(this,"plugins");p(this,"loadedModels");p(this,"raf");p(this,"timeoutSymbol");p(this,"homeView");p(this,"inputManager");p(this,"cameraManager");p(this,"sceneManager");p(this,"fontManager");p(this,"pickManager");p(this,"undoManager");p(this,"overlayRender");p(this,"css2dRenderer");p(this,"spinner");p(this,"progressBar");p(this,"loaderHelper");p(this,"zoomToRectHelper");p(this,"_enableSelection");p(this,"enableRender");this.name=Be.BaseViewer,this.clock=new d.Clock,this.targetMaxFps=60,this.timeStamp=0,this.renderEnabled=!0,this.plugins=[],this.loadedModels=[],this.raf=new Vn,this._enableSelection=!0,this.enableRender=(i=1e3)=>{this.renderEnabled=!0,this.raf&&(this.timeoutSymbol&&this.raf.clearTimeout(this.timeoutSymbol),this.timeoutSymbol=this.raf.setTimeout(()=>{this.renderEnabled=!1},i))},this.viewerCfg=e,this.initLogLevel(),this.initLocalization(),this.container=new Us(e.containerId),e.enableProgressBar&&(this.progressBar=new Ns(this.container)),this.spinner=new Bn(this.container),this.sceneManager=new oc(this),this.pickManager=new ac(this),this.overlayRender=new yi(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new Wn(this.viewerContainer),this.cameraManager=new zh(this),this.loaderHelper=new ut,this.undoManager=new lc,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&rn(e)}initLocalization(){const e=this.viewerCfg.language||an;Re.changeLanguage(e)}get viewerContainer(){return this.container.viewerContainer}get widgetContainer(){return this.container.widgetContainer}getUndoManager(){return this.undoManager}getInputManager(){return this.inputManager}getCssRender(){return this.css2dRenderer}getCameraManager(){return this.cameraManager}getOverlayRender(){return this.overlayRender}getSceneManager(){return this.sceneManager}get renderer(){return this.sceneManager.renderer}get camera(){return this.cameraManager.camera}get scene(){return this.sceneManager.scene}getRaycaster(){return this.pickManager.getRaycaster()}getViewerConfig(){return this.viewerCfg}getSpinner(){return this.spinner}getFontManager(){return this.fontManager}initCSS2DRenderer(){const e=new sn.CSS2DRenderer,{width:i,height:s}=this.viewerContainer.getBoundingClientRect();return e.setSize(i,s),e.domElement.style.height="0",e.domElement.style.width="0",e.domElement.style.position="absolute",e.domElement.style.top="0",e.domElement.style.left="0",e.domElement.style.overflow="visible",e.domElement.classList.add("css2d-renderer"),this.viewerContainer?.appendChild(e.domElement),e}animate(){const e=Date.now()-this.timeStamp,i=1/this.targetMaxFps;if(e<i){this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this));return}const s=this.cameraManager.update(this.clock.getDelta());this.container.needResize&&(this.resize(),this.renderEnabled=!0),(this.renderEnabled||s)&&(this.dispatchEvent(re.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(re.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(re.OnAnimate)}resize(){this.sceneManager.resize(),this.cameraManager.updateAspect();const{clientWidth:e,clientHeight:i}=this.viewerContainer;this.css2dRenderer.setSize(e,i),this.overlayRender.setSize(e,i)}setDracoDecoderPath(e){ut.setDracoDecoderPath(e)}addModel(e){const i=e.getModelObject();i.name=e.modelId,this.sceneManager.addModel(e),i.matrixAutoUpdate=He,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new Ke),await this.fontManager.loadFonts(e)}is3d(){return!1}getPixelSizeInWorldCoord(){const e=this.camera,{clientWidth:i,clientHeight:s}=this.viewerContainer;let r=1;if(e.type==="OrthographicCamera"){const n=e;r=Math.max(n.right-n.left,n.top-n.bottom)/n.zoom/Math.max(i,s)}else if(e.type==="PerspectiveCamera"){const n=e,a=new d.Vector3;e.getWorldPosition(a);const o=this.cameraManager.getTarget();a&&o&&(r=2*(a.distanceTo(o)*Math.tan(n.fov/2*(Math.PI/180)))/s)}return r}zoomToRect(){!this.zoomToRectHelper&&(this.zoomToRectHelper=new qn(this)),this.zoomToRectHelper.activate()}deactivateZoomRect(){this.zoomToRectHelper?.deactivate()}getUniqueModelId(e){let i=e;const s=r=>!!this.loadedModels.find(n=>n.modelId===r);if(s(i)){let r=1;for(;s(i+"_"+r);)r++;i=i+"_"+r,S.warn("[Viewer] Model '"+i+"' is loaded more than once!")}return i}getBBox(){const e=new d.Box3;return this.loadedModels.forEach(i=>{e.union(i.getBBox())}),e}flyToObject(e){this.cameraManager.flyToObject(e)}flyToObjects(e){const i=new d.Box3;e.forEach(r=>{const n=new d.Box3().setFromObject(r);i.union(n)});const s=new d.Sphere;i.getBoundingSphere(s),this.cameraManager.fitToSphere(s)}flyTo(e,i,s=!0){const r=this.camera;if(e.equals(i)){S.error("[Viewer] camera position and lookAt cannot be the same!");return}else if(!V.isVectorValid(e)||!V.isVectorValid(i)){S.error("[Viewer] invalid position or lookAt!");return}const n=e.distanceTo(i);n<r.near?(e=e.clone().sub(i).normalize().multiplyScalar(r.near*1.1),S.warn("[Viewer] camera could be too close to see the object!")):n>r.far&&(e=e.clone().sub(i).normalize().multiplyScalar(r.far*.9),S.warn("[Viewer] camera could be too far to see the object!")),this.cameraManager.flyTo(e,i,s)}flyToDirection(e){const i=this.getBBox(),s=i.getSize(new d.Vector3);let r=Math.max(s.x,s.y,s.z)/2;r===0&&(r=1);const n=this.cameraManager.getDistanceToFitSphere(r),a=new d.Vector3;i.getCenter(a);const o=a.clone().add(e.clone().multiplyScalar(n));this.flyTo(o,a)}goToHomeView(){if(this.homeView)this.cameraManager.flyToViewpoint(this.homeView);else{const e=new d.Vector3(1,.5,1);this.flyToDirection(e)}}viewFitAll(){const e=this.getBBox(),i=new d.Sphere;e.getBoundingSphere(i),this.cameraManager.fitToSphere(i)}zoomToBBox(e){this.cameraManager.flyToBox(e)}pickObject(e,i,s){let r=this.pickManager.pickObject(e,this.getRaycastableObjects(),i,s);return this.renderer&&this.renderer.clippingPlanes.length>0&&this.renderer?.clippingPlanes?.every(a=>{r&&a.distanceToPoint(r.point)>0})&&(r=void 0),r}pickObjects(e,i){let s=this.pickManager.pickObjects(e,this.getRaycastableObjects(),i);return s&&this.renderer.clippingPlanes.length>0&&(s=s.filter(r=>this.renderer.clippingPlanes.every(n=>n.distanceToPoint(r.point)>0))),s}getRaycastableObjects(){return this.sceneManager.getRaycastableObjects()}setBackgroundColor(e,i,s){if(!this.scene.background&&(this.scene.background=new d.Color(e,i,s)),this.scene.background instanceof d.Color){const r=new d.Color;r.setRGB(e,i,s,this.renderer.outputColorSpace),this.scene.background.copy(r)}this.enableRender()}setGlobalClipPlanes(e){}getCameraProjection(){return this.cameraManager.getProjection()}setCameraProjection(e){this.cameraManager.setProjection(e)}enableControl(e){this.cameraManager.enableControl(e)}enableRotate(e){this.cameraManager.enableRotate=e}enableZoom(e){this.cameraManager.enableZoom(e)}enablePan(e){this.cameraManager.enablePan(e)}getHomeView(){return this.homeView}setHomeView(e){this.homeView=e}getCameraConfig(){return this.cameraManager.getCameraConfig()}setCameraConfig(e){return this.cameraManager.setCameraConfig(e)}getCameraDirection(){return this.cameraManager.getCameraDirection()}getRenderInfo(){const e=this.renderer.info;return{drawCalls:e.render.calls,lines:e.render.lines,points:e.render.points,triangles:e.render.triangles,geometries:e.memory.geometries,textures:e.memory.textures,materials:e.programs?.length||0}}destroy(){this.requestAnimationFrameHandle&&cancelAnimationFrame(this.requestAnimationFrameHandle),this.css2dRenderer.domElement.remove(),this.container.destroy(),this.sceneManager.destroy(),this.cameraManager.destroy(),this.overlayRender.destroy(),this.spinner.destroy(),this.progressBar?.destroy(),this.undoManager.destroy()}addPlugin(e){if(this.plugins.find(s=>s.id===e.id)){S.warn("[Viewer] Plugin already exist: "+e.id);return}this.plugins.push(e),S.debug("[Viewer] Added plugin: "+e.id)}removePlugin(e){for(let i=0,s=this.plugins.length;i<s;i++)if(this.plugins[i]===e){this.plugins.splice(i,1);return}}clearPlugins(){this.plugins=[]}findPlugin(e){return this.plugins.find(i=>i.id===e)}}const Yn=-1e3,zi=new d.Vector3,$r=new d.Matrix4,Jr=new d.Frustum,Ts=new d.Box3;class Gs extends Qi{constructor(e){super(e);p(this,"name");p(this,"loadedModels");p(this,"masterModelId");p(this,"activeLayoutName");p(this,"dxfLayoutBar");p(this,"layoutInfos");p(this,"units");p(this,"enableHideVisuallySmallObjects");p(this,"sortedHidableObjects");p(this,"lastCameraZoom");p(this,"groundPlane");p(this,"raycastableObjects");p(this,"selectedObject");p(this,"loadingDxfCount");p(this,"textSearchHelper");this.name=Be.Viewer2d,this.loadedModels=[],this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0,this.enableHideVisuallySmallObjects=e.enableHideVisuallySmallObjects!==!1,this.sortedHidableObjects={},this.lastCameraZoom=1/0,this.loadingDxfCount=0,e.enableLayoutBar&&(this.dxfLayoutBar=new kh(this)),this.cameraManager.setProjection($e.Orthographic),this.cameraManager.setNavigationMode(Ne.Plan);const i=new d.Vector3(0,0,100),s=new d.Vector3(0,0,0);this.cameraManager.setCameraConfig({eye:i,look:s}),this.resize(),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(re.BeforeRender,()=>{this.updateRaycasterThreshold(),this.updateCameraZoomUniform(this.camera.zoom),this.updateHidableObjectsVisibility()})}get camera(){return this.cameraManager.camera}setupDefaultEvents(){let e=!1,i=!1;this.inputManager.addEventListener("pointerdown",s=>{i=!1,e=!0,s.button===Le.Middle&&this.inputManager?.setCursor("move")}),this.inputManager.addEventListener("pointermove",()=>{e&&(i=!0,this.inputManager?.setCursor("move"))}),this.inputManager.addEventListener("pointerup",s=>{if(e=!1,this.inputManager?.setCursor("default"),i){i=!1;return}const r=new d.Vector2(s.x,s.y),n=this.getWorldPositionByMousePick(r),a={event:s,position:r,pooo:n,activatObj:null};this.dispatchEvent(re.MouseClick,a)})}handleMouseClick(e){if(!this.enableSelection)return;const i=new d.Vector2(e.x,e.y),s=this.getWorldPositionByMousePick(i);if(!s)return;const r=this.overlayRender.getDrawablesByPosition(s)[0];if(r){this.selectedObject===r?(this.selectedObject.selected=!1,this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=r,this.selectedObject.selected=!0),this.enableRender();return}const n=this.pickObject(i,[ft]);if(n){const a=n?.object;this.selectedObject===a?(this.setObjectUnHighlight(this.selectedObject),this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=a,this.setObjectHighlight(this.selectedObject)),this.enableRender();return}this.clearSelection(),this.enableRender()}setDefaultBackground(){this.setBackgroundColor(.0295,.0212,.0152)}async loadModel(e,i,s){const r=this.getUniqueModelId(e.modelId||e.src);this.spinner.increaseJobCount(),this.loaderHelper.setFont(this.fontManager),this.masterModelId||(this.masterModelId=r);const n=r,a=Re.t("ProgressBar.Loading"),o=x=>{this.progressBar?.updateProgress(n,a,x),i?.(new ProgressEvent("LoadProgress",{loaded:x,total:100}))},l=(x,y,T)=>{let v=x.loaded*100/x.total;v=v*(T-y)/100+y,this.progressBar?.updateProgress(n,a,v),i?.(new ProgressEvent("LoadProgress",{loaded:v,total:100}))},c=x=>l(x,0,90);this.progressBar?.addProgressItem(n),o(0);const u=this.viewerCfg,f=await this.loaderHelper.loadDxfData(e.src,e.modelId,c,void 0,{ignorePaperSpace:e.ignorePaperSpace,enableLocalCache:u.enableLocalCache,enableMerge:e.merge,encoding:e.encoding,overrideColor:e.overrideColor}).finally(()=>{this.loadingDxfCount--,this.loadingDxfCount===0&&this.fontManager?.releaseFontData()}),m=f.threejsObject;if(s&&s({threejsObject:m,llbMesh:f.llbMesh}),e.matrix&&e.matrix.length===16){const x=new d.Matrix4;x.elements=e.matrix,m.applyMatrix4(x)}const g=new qt({modelId:r,dxfData:f});this.addModel(g),this.spinner.decreaseJobCount(),o(100),this.progressBar?.delayRemoveProgressItem(n),this.dispatchEvent(re.ModelLoad)}addModel(e){super.addModel(e);const i=e.modelId;if(e.dxfData){this.masterModelId===i?this.activateLayout(Y.MODEL_LAYOUT_NAME):this.handleOverlayDxf(i);const s=e.getBBox(),r=new d.Vector3;s.getCenter(r),this.cameraManager.adjustCameraByBBox(s);const n=this.getDxfUnits(e);this.masterModelId===i&&(this.units=n)}else{const s=e.getModelObject();this.activeLayoutName=Y.MODEL_LAYOUT_NAME;const r=new d.Box3().setFromObject(s);this.layoutInfos[this.activeLayoutName]={homeViewExtent:r,extent:r},s.matrixAutoUpdate=He,this.scene.add(s);const n=r.max.z;n>this.camera.position.z&&(this.camera.position.z=n,this.camera.updateProjectionMatrix()),this.flyToObject(s)}this.updateGroundPlane()}getDxfUnits(e){return!e&&this.loadedModels.length>0&&(e=this.loadedModels.find(i=>this.masterModelId===i.modelId)),e?e.getUnits():De.Unitless}handleOverlayDxf(e){const i=this.loadedModels.find(r=>e===r.modelId);if(!i){S.warn("[Viewer] Can't find model for modelId '"+e+"'!");return}i.switchTransformMs(Y.MODEL_LAYOUT_NAME),i.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME)?.traverse(r=>{i.addSpatialFilterSection(r,i.dxfData)}),i.showLayoutObjects(Y.MODEL_LAYOUT_NAME)}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}setObjectUnHighlight(e){this.loadedModels.forEach(i=>i.unHighlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}clearSelection(){this.selectedObject instanceof d.Object3D&&this.setObjectUnHighlight(this.selectedObject),this.selectedObject instanceof pt&&(this.selectedObject.selected=!1),this.selectedObject=void 0}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}updateGroundPlane(){const e=this.getActiveLayoutInfo();if(!e.homeViewExtent)return;const i=e.homeViewExtent.clone(),s=[],r=(o,l,c)=>{s.push(new d.Vector3(o,l,c))},n=i.getSize(new d.Vector3),a=i.getCenter(new d.Vector3);if(r(-n.x/2,-n.y/2,0),r(n.x/2,-n.y/2,0),r(n.x/2,n.y/2,0),r(-n.x/2,n.y/2,0),this.groundPlane)this.groundPlane.position.set(a.x,a.y,-n.z),this.groundPlane.geometry.setFromPoints(s),this.groundPlane.geometry.computeBoundingSphere(),this.groundPlane.geometry.computeBoundingBox();else{const o=new d.BufferGeometry;o.setFromPoints(s),o.setIndex([0,3,2,0,2,1]);const l=new d.MeshBasicMaterial({color:"#888",side:d.DoubleSide});this.groundPlane=new d.Mesh(o,l),this.groundPlane.visible=!1,this.groundPlane.position.set(a.x,a.y,-n.z),this.groundPlane.scale.set(1e5,1e5,1),this.groundPlane.name="groundPlane",this.groundPlane.renderOrder=Yn,this.groundPlane.layers.enableAll(),$.disableLayerChannels(this.groundPlane,[ft]),this.scene.add(this.groundPlane)}this.groundPlane.updateMatrix(),this.groundPlane.updateMatrixWorld(!0)}getRaycastableObjects(){const e=[],i=Date.now();if(this.activeLayoutName===Y.MODEL_LAYOUT_NAME){if(this.raycastableObjects)return this.raycastableObjects;if(this.renderer?.renderLists){const s=this.renderer?.renderLists.get(this.scene,0);s&&(s.opaque.forEach(r=>{r.object&&r.object.geometry&&e.push(r.object)}),s.transparent.forEach(r=>{r.object&&r.object.geometry&&e.push(r.object)}))}$r.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),Jr.setFromProjectionMatrix($r);for(const s of this.loadedModels){const r=s.getModelObject(),n=r.children.find(a=>a.name===this.activeLayoutName);n&&n.children.find(o=>o.name===Y.SNAP_GROUP_NAME)?.traverse(o=>{if($.isLeafObject(o)){if(Ts.makeEmpty(),Ts.expandByObject(o),!Jr.intersectsBox(Ts))return;e.push(o)}})}this.groundPlane&&e.push(this.groundPlane),S.debug("[Viewer] getRaycastableObjectsByMouse() from modelSpace"),this.raycastableObjects=e}else{const s=new WeakSet,r=this.getLayoutByName(this.activeLayoutName);r&&r.directAssociatedLeafObjectSet?.forEach(o=>{o.visible&&!s.has(o)&&(e.push(o),s.add(o))});const n=this.getViewportByPoint(this.pickManager.getRaycaster().ray.origin);n&&n.associatedLeafObjectSet?(n.associatedLeafObjectSet?.forEach(a=>{!s.has(a)&&(a.visible||a.userData.isSnapObject)&&(e.push(a),s.add(a))}),S.debug("[Viewer] getRaycastableObjectsByMouse() from inside of viewport:",n.viewportId)):S.debug("[Viewer] getRaycastableObjectsByMouse() from out of viewport"),this.groundPlane&&e.push(this.groundPlane)}return S.debug("[Viewer] getRaycastableObjectsByMouse() took "+(Date.now()-i)/1e3+" s"),e}getViewportByPoint(e){if(this.activeLayoutName.length===0||this.activeLayoutName===Y.MODEL_LAYOUT_NAME)return;const i=this.getLayoutByName(this.activeLayoutName);if(!i)return;const s=a=>e.x<a.min.x||e.x>a.max.x||e.y<a.min.y||e.y>a.max.y,r=this.loadedModels.find(a=>this.masterModelId===a.modelId);if(!r)return;const n=r.getFilteredViewports(i);for(let a=0,o=n.length;a<o;a++){const l=n[a];if(!s(l.psBBox))return l}}getWorldPositionByMousePick(e){const i=[];this.groundPlane&&i.push(this.groundPlane);for(const r of this.loadedModels){const n=r.getModelObject();n&&(i.push(n),n.traverse(a=>{(a.isMesh||a.isLine)&&i.push(a)}))}return this.pickManager.pickObject(e,i)?.point}activateLayout(e=Y.MODEL_LAYOUT_NAME){if(this.activeLayoutName===e||!this.masterModelId)return;const i=this.loadedModels.find(u=>this.masterModelId===u.modelId);if(!i)return;const s=i.getLayoutByName(e);if(!s)return;const r=this.getActiveLayoutInfo();if(this.groundPlane){const u=this.getCurrentViewExtent(),f=this.camera.position.z;r.lastViewExtent=new d.Box3(new d.Vector3(u.min.x,u.min.y,0),new d.Vector3(u.max.x,u.max.y,f))}const n=u=>!!this.layoutInfos[u]?.lastViewExtent,a=n(e);i?.activateLayout(e,a),this.activeLayoutName=e;const o=i.getFilteredViewports(s);if(S.debug("[Viewer] Active layout:",e,", viewports:",o),!a){const u=this.camera.position.z;let f=0;o.forEach(g=>{const x=g?.msToPsMatrix?.elements[14];x&&x>f&&(f=x)});const m=this.cameraManager.getPosition();if(f>m.z+u){const g=Math.ceil(f+u);m.z=g,S.info("[Viewer] Changing camera's z value from "+m.z+" to "+g),this.cameraManager.setCameraPosition(m)}}const l=this.getActiveLayoutInfo();if(l.lastViewExtent)this.zoomToBBox(l.lastViewExtent);else{l.extent=this.getBBox();let u=this.getLayoutExtentEx(s);if(u){const g=u.max.x-u.min.x,x=u.max.y-u.min.y;(g<1e-16||x<1e-16||g>1e16||x>1e16)&&(S.warn("[Viewer] Got wired bbox, max: "+u.max.toArray()+", min: "+u.min.toArray()+", going to use the calculated one..."),u=l.extent)}else S.warn("[Viewer] Failed to get layout extent, going to use the calculated one..."),u=l.extent;l.homeViewExtent=u,this.zoomToBBox(u)}const c=i.getLayoutLevelObject(e);c&&this.setLayoutHidableObjectArray(c),this.enableRender()}getLayoutExtentEx(e){const i=this.loadedModels.find(s=>this.masterModelId===s.modelId);if(i)return e.layoutName===Y.MODEL_LAYOUT_NAME?i.getModelSpaceExtent():i.getLayoutExtent(e)}getActiveLayoutInfo(){return this.getLayoutInfo(this.activeLayoutName)}getLayoutByName(e){let i;const s=this.loadedModels.find(n=>this.masterModelId===n.modelId);if(!s)return;const r=s.getLayouts();for(const n of r)if(n.layoutName===e){i=n;break}return i}getEntityCount(){let e=0;return this.loadedModels.forEach(i=>{e+=i.loadedEntityCount}),e}getLayoutNames(){const e=[];return(this.loadedModels.find(r=>this.masterModelId===r.modelId)?.getLayouts()||[]).forEach(r=>{e.push(r.layoutName)}),e}getLayoutInfo(e){return this.layoutInfos[e]||(this.layoutInfos[e]={}),this.layoutInfos[e]}goToHomeView(){const e=this.getActiveLayoutInfo();e.homeViewExtent?this.zoomToBBox(e.homeViewExtent):S.error("[Viewer] Failed to find extent for "+this.activeLayoutName)}zoomToBBox(e){const i=e.getCenter(zi),s=e.max.x-e.min.x,r=e.max.y-e.min.y,n=this.camera.right-this.camera.left,a=this.camera.top-this.camera.bottom;let o=Math.min(n/s,a/r);o/=1.1,this.cameraManager.cameraControls.moveTo(i.x,i.y,i.z),this.cameraManager.cameraControls.zoomTo(o)}getCurrentViewExtent(){const e=this.getHitResultByNdcCoordinate(new d.Vector2(-1,-1)),i=this.getHitResultByNdcCoordinate(new d.Vector2(1,1));return new d.Box2(e,i)}getHitResultByNdcCoordinate(e){const i=[];this.groundPlane&&i.push(this.groundPlane);const s=this.pickManager.pickObjectsByNdc(e,i);if(s.length>0){const r=s[0].point;return new d.Vector2(r.x,r.y)}}getHitResult(e){const i=this.viewerContainer,s=pe.getScreenCoordinateByEvent(e,i),r=pe.screen2Ndc(s,this.camera,i);return this.getHitResultByNdcCoordinate(r)}getActiveLayoutName(){return this.activeLayoutName}searchText(e,i){return!this.textSearchHelper&&(this.textSearchHelper=new Is(this)),this.textSearchHelper.search(e,i)}focusText(e){!this.textSearchHelper&&(this.textSearchHelper=new Is(this)),this.textSearchHelper.focus(e)}clearTextHighlight(){this.textSearchHelper?.clearHighlight()}zoomIn(e=.01){this.cameraManager.cameraControls.zoom(e)}zoomOut(e=.01){this.cameraManager.cameraControls.zoom(-e)}getLayers(){const e=[];if(this.masterModelId){const i=this.loadedModels.find(r=>this.masterModelId===r.modelId),s=i?.layers;s&&e.push({modelId:this.masterModelId,layers:s})}for(const i of this.loadedModels){const s=i.modelId;if(s===this.masterModelId)continue;const r=i.layers;r&&e.push({modelId:s,layers:r})}return e}setModelVisibility(e,i){const s=this.loadedModels.find(r=>e===r.modelId);if(!s)throw new Error("Failed to find model by modelId '"+e+"'!");s.setVisible(i),this.enableRender()}setLayerVisibility(e,i,s){const r=this.camera;s=s||this.masterModelId;const n=this.loadedModels.find(a=>s===a.modelId);if(!n)throw new Error("Failed to find layer by modelId '"+s+"'!");n.setLayerVisible(e,i,this.enableHideVisuallySmallObjects,r.zoom),this.raycastableObjects=void 0,this.enableRender()}setLayerOpacity(e,i,s){s=s||this.masterModelId;const r=this.loadedModels.find(n=>s===n.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");r.setLayerOpacity(e,i),this.enableRender()}setLayerColor(e,i,s){s=s||this.masterModelId;const r=this.loadedModels.find(n=>s===n.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");this.clearSelection(),r.setLayerColor(e,i),this.enableRender()}resetLayerColor(e,i){i=i||this.masterModelId;const s=this.loadedModels.find(r=>i===r.modelId);if(!s)throw new Error("Failed to find model by modelId '"+i+"'!");this.clearSelection(),s.resetLayerColor(e),this.enableRender()}getVisiblePixelSize(e){const i=d.MathUtils.smoothstep(e,1e4,3e4)*6.5+.5;return S.debug("[Viewer] visiblePixelSize:",i),i}setLayoutHidableObjectArray(e){const i=this.camera;if(!this.enableHideVisuallySmallObjects||!i)return;const s=Date.now(),r=e.name;this.sortedHidableObjects[r]||(this.sortedHidableObjects[r]=[]);const n=this.sortedHidableObjects[r];this.cameraManager.update(0);const a=i.zoom;this.lastCameraZoom=a;let o=1;e.traverse(c=>{if(c.userData.isSnapObject||!$.isLeafObject(c))return;const u=c.geometry;u.boundingBox||u.computeBoundingBox();const f=u.boundingBox.clone();if(!f||!V.isBoxValid(f))return;f.applyMatrix4(c.matrixWorld),f.getSize(zi);const m=Math.max(zi.x,zi.y),g=o/m;g<1/0?n.push({visibleMinZoom:g,object:c}):c instanceof d.Points?n.push({visibleMinZoom:o,object:c}):S.warn("[Viewer] The size of bbox is 0 ! ",c)}),o=this.getVisiblePixelSize(n.length);let l=0;n.forEach(c=>{const u=c.visibleMinZoom*o;c.visibleMinZoom=u,c.object.userData.visibleMinZoom=u,u>a&&(c.object.visible=!1,l++)}),n.sort((c,u)=>c.visibleMinZoom-u.visibleMinZoom),S.debug("[Viewer] setLayoutHidableObjectArray took: "+(Date.now()-s)/1e3+"s, "+l+" objects changed to hidden")}updateRaycasterThreshold(){const e=this.getPixelSizeInWorldCoord()*3,i=this.getRaycaster().params;i.Line?i.Line.threshold=e:i.Line={threshold:e},i.Points?i.Points.threshold=e:i.Points={threshold:e}}updateHidableObjectsVisibility(){const e=this.camera,i=Date.now();this.cameraManager.update(0);const s=e.zoom;if(Math.abs(s-this.lastCameraZoom)<1e-5||(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,!this.sortedHidableObjects[this.activeLayoutName]))return;const r=this.sortedHidableObjects[this.activeLayoutName];if(r.length===0)return;const n=s>this.lastCameraZoom,a=Math.min(s,this.lastCameraZoom),o=Math.max(s,this.lastCameraZoom),l=[];let c=0;for(let u=0;u<r.length;++u)if(r[u].object.userData.layerVisible!==!1){if(r[u].visibleMinZoom<a){l.push(r[u].object);continue}else if(r[u].visibleMinZoom>o)break;r[u].object.visible=n,n&&l.push(r[u].object),c++}this.lastCameraZoom=s,S.debug("[Viewer] updateHidableObjectsVisibility took: "+(Date.now()-i)/1e3+"s, "+c+"(out of "+r.length+") objects changed to "+(n?"visible":"hidden"))}updateCameraZoomUniform(e){Y.CameraZoomUniform.value=e*this.container.height/50}}class Xn{constructor(t){p(this,"viewer");p(this,"fontManager");p(this,"loader");p(this,"loadingManager");p(this,"changes");p(this,"container");p(this,"spinner");p(this,"jobCount");p(this,"loadingProgressBar");this.jobCount=0,this.viewer=new Gs(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new Us(t.containerId);this.loadingProgressBar=new Ns(i);const s={ignorePaperSpace:!0};this.loader=new Y(this.loadingManager,s),this.initSpinner()}initSpinner(){const t=document.createElement("div");t.classList.add("x-spinner"),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),this.container.appendChild(t),this.spinner=t,this.setSpinnerVisibility(this.jobCount>0)}async setFont(t){const e=Date.now();!this.fontManager&&(this.fontManager=new Ke),await this.fontManager.loadFonts(t),S.info("[DxfCompareHelper] Font file(s) load time in "+(Date.now()-e)/1e3+"s")}async compare(t,e,i,s){const{src:r,modelId:n}=t,{src:a}=e;this.viewer.masterModelId=n||r;const o=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const l=r+a,c=Re.t("ProgressBar.Comparing"),u=k=>{this.loadingProgressBar?.updateProgress(l,c,k),s&&s(new ProgressEvent("CompareProgress",{loaded:k,total:100}))},f=(k,B,L)=>{let q=k.loaded*100/k.total;q=q*(L-B)/100+B,this.loadingProgressBar?.updateProgress(l,c,q),s&&s(new ProgressEvent("CompareProgress",{loaded:q,total:100}))},m=k=>f(k,0,15),g=k=>f(k,15,30),x=k=>f(k,30,60),y=k=>f(k,60,95);V.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(l),u(0);let T=Date.now();const v=this.loader.parse(r,m),b=this.loader.parse(a,g),[E,O]=await Promise.allSettled([v,b]);if(E.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+r);if(O.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+a);if(S.info("[DxfCompareHelper] loadFiles in "+(Date.now()-T)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const _=E.value,C=O.value;T=Date.now();const w=await new Ue(_,C,i).compare(x);if(S.info("[DxfCompareHelper] Compared in "+(Date.now()-T)/1e3+"s"),S.debug("[DxfCompareHelper] Compared results:",w),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");V.printMemory("After getting the comparison results"),T=Date.now(),await this.loader.loadEntitiesForCompare(_,C,w,!0,y),V.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=w,S.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-T)/1e3+"s");const M=_,P=C;if(this.decreaseJobCount(),!Object.keys(w).length&&S.info("[DxfCompareHelper] No change found"),M.threejsObject?.children.length===0&&P.threejsObject?.children.length===0){const k="[DxfCompareHelper] Nothing was loaded from "+r+" and "+a;return S.warn(k),Promise.reject(k)}const A=M.threejsObject,I=P.threejsObject;return A.name=r,I.name=a,T=Date.now(),this.viewer.addModel(new qt({modelId:t.modelId||t.src,dxfData:M})),this.viewer.flyToObject(A),V.printMemory("After adding first loaded Model to scene"),u(95),this.viewer.addModel(new qt({modelId:e.modelId||e.src,dxfData:P})),V.printMemory("After adding second loaded Model to scene"),S.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-T)/1e3+"s"),S.info("[DxfCompareHelper] The comparison between "+r+"' and '"+a+"' is completed in "+(Date.now()-o)/1e3+"s !"),u(100),this.loadingProgressBar?.delayRemoveProgressItem(l),Promise.resolve()}getChanges(){return this.changes}zoomToChange(t){if(this.changes){const e=this.changes[t];if(!e)return;const i=e.box;i&&this.viewer.zoomToBBox(i.clone().expandByScalar(1.2))}}setSpinnerVisibility(t){this.spinner&&(t?this.spinner.classList.remove("hidden"):this.spinner.classList.add("hidden"))}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){this.setSpinnerVisibility(--this.jobCount>0)}}class hc extends Xn{constructor(e,i){super(e);p(this,"viewer2");p(this,"syncCamera");p(this,"markupManager1");p(this,"markupManager2");p(this,"syncCameraControls");this.syncCamera=!1,this.syncCameraControls=(s,r,n)=>{const a=new d.Vector3,o=new d.Vector3,l=new d.Vector3;s.getPosition(o),s.getTarget(l),s.getFocalOffset(a),r.setLookAt(o.x,o.y,o.z,l.x,l.y,l.z),r.zoomTo(n),r.dispatchEvent({type:"control"})},this.viewer2=new Gs(i),this.initSyncCameraEvent()}initSyncCameraEvent(){const e=this.viewer.getCameraManager().cameraControls,i=this.viewer2.getCameraManager().cameraControls;let s=!1;e.addEventListener("control",()=>{s=!1}),e.addEventListener("update",()=>{!this.syncCamera||s||this.syncCameraControls(e,i,this.viewer.camera.zoom)}),i.addEventListener("control",()=>{s=!0}),i.addEventListener("update",()=>{!this.syncCamera||!s||this.syncCameraControls(i,e,this.viewer2.camera.zoom)})}enableSyncCamera(e){if(this.syncCamera=e,e){const i=this.viewer.getCameraManager().cameraControls,s=this.viewer2.getCameraManager().cameraControls;this.syncCameraControls(i,s,this.viewer.camera.zoom)}}async compare(e,i,s,r){const{src:n,modelId:a}=e,{src:o,modelId:l}=i;this.viewer.masterModelId=a||n,this.viewer2.masterModelId=l||o;const c=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const u=n+o,f=Re.t("ProgressBar.Comparing"),m=L=>{this.loadingProgressBar?.updateProgress(u,f,L),r&&r(new ProgressEvent("CompareProgress",{loaded:L,total:100}))},g=(L,q,me)=>{let ue=L.loaded*100/L.total;ue=ue*(me-q)/100+q,this.loadingProgressBar?.updateProgress(u,f,ue),r&&r(new ProgressEvent("CompareProgress",{loaded:ue,total:100}))},x=L=>g(L,0,15),y=L=>g(L,15,30),T=L=>g(L,30,60),v=L=>g(L,60,95);V.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(u),m(0);let b=Date.now();const E=this.loader.parse(n,x),O=this.loader.parse(o,y),[_,C]=await Promise.allSettled([E,O]);if(_.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+n);if(C.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+o);if(S.info("[DxfCompareHelper] loadFiles in "+(Date.now()-b)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const w=_.value,M=C.value;b=Date.now();const P=await new Ue(w,M,s).compare(T);if(S.info("[DxfCompareHelper] Compared in "+(Date.now()-b)/1e3+"s"),S.debug("Compared results:",P),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");V.printMemory("After getting the comparison results"),b=Date.now(),await this.loader.loadEntitiesForCompare(w,M,P,!1,v),V.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=P,S.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-b)/1e3+"s");const A=w,I=M;if(this.decreaseJobCount(),!Object.keys(P).length&&S.info("[DxfCompareHelper] No change found"),A.threejsObject?.children.length===0&&I.threejsObject?.children.length===0){const L="[DxfCompareHelper] Nothing was loaded from "+n+" and "+o;return S.warn(L),Promise.reject(L)}const k=A.threejsObject,B=I.threejsObject;return k.name=n,B.name=o,b=Date.now(),this.viewer.addModel(new qt({modelId:e.modelId||e.src,dxfData:A})),V.printMemory("After adding first loaded Model to scene"),m(95),this.viewer2.addModel(new qt({modelId:i.modelId||i.src,dxfData:I})),V.printMemory("After adding second loaded Model to scene"),this.drawCompareBoxes(),S.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-b)/1e3+"s"),S.info("[DxfCompareHelper] The comparison between "+n+"' and '"+o+"' is completed in "+(Date.now()-c)/1e3+"s !"),m(100),this.loadingProgressBar?.delayRemoveProgressItem(u),Promise.resolve()}drawCompareBoxes(){this.changes&&(this.markupManager1??(this.markupManager1=new As(this.viewer)),this.markupManager2??(this.markupManager2=new As(this.viewer2)),requestAnimationFrame(()=>{this.markupManager1?.drawCompareDrawable(this.changes),this.markupManager2?.drawCompareDrawable(this.changes),this.viewer.enableRender(),this.viewer2.enableRender()}))}zoomToChange(e){if(this.changes){const i=this.changes[e];if(!i)return;const s=i.box;s&&(this.viewer.zoomToBBox(s.clone().expandByScalar(1.2)),this.viewer2.zoomToBBox(s.clone().expandByScalar(1.2)))}}}class zt{constructor(t,e){p(this,"current");p(this,"next");p(this,"inNormal");p(this,"outNormal");this.current=t,this.next=e,this.inNormal=this.inwardsNormal(),this.outNormal=this.outwardsNormal()}outwardsNormal(){const t=this.inwardsNormal();return[-t[0],-t[1]]}inwardsNormal(){const t=this.next[0]-this.current[0],e=this.next[1]-this.current[1],i=Math.sqrt(t*t+e*e);if(i===0)throw new Error("Vertices overlap");return[-e/i,t/i]}offset(t,e){return zt.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return zt.offsetEdge(this.next,this.current,t,e)}inverse(){return new zt(this.next,this.current)}static offsetEdge(t,e,i,s){return new zt([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const si=Array.isArray,Qr=(h,t)=>h[0]===t[0]&&h[1]===t[1],Cs=h=>Array.isArray(h)&&h.length,Zn=(h,t=0,e=!1)=>{let i,s;if(Cs(h)&&typeof h[0][0]=="number"){let r=0;const n=h;for(i=0,s=n.length;i<s;i++){const a=n[i],o=n[(i+1)%s];r+=a[0]*o[1],r-=o[0]*a[1]}(!e&&r>0||e&&r<0)&&n.reverse()}else for(i=0,s=h.length;i<s;i++)Zn(h[i],t+1,i>0);if(t===0&&Cs(h)&&Cs(h[0])&&typeof h[0][0][0]=="number"){const r=h[0].slice(0,1)[0];h[0].pop(),h[0].push([r[0],r[1]])}return h};class cc{constructor(t,e=5){p(this,"vertices");p(this,"edges");p(this,"arcSegments");p(this,"distance");if(this.distance=0,this.arcSegments=e,!si(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],si(t)&&typeof t[0]=="number"?this.vertices=t:(this.vertices=Zn(t),this.processContour(this.vertices,this.edges))}processContour(t,e){let i,s;if(si(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,Qr(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new zt(t[i],t[(i+1)%s]));else for(t=t,e=e,i=0,s=t.length;i<s;i++)e.push([]),this.processContour(t[i],e[e.length-1])}setArcSegments(t){return this.arcSegments=t,this}createArc(t,e,i,s,r,n,a){const o=Math.PI*2;let l=Math.atan2(s[1]-e[1],s[0]-e[0]),c=Math.atan2(r[1]-e[1],r[0]-e[0]);n%2===0&&(n-=1),l<0&&(l+=o),c<0&&(c+=o);let u=l>c?l-c:l+o-c;const f=(a?-u:o-u)/n;t.push(s);for(let m=1;m<n;++m)u=l+f*m,t.push([e[0]+Math.cos(u)*i,e[1]+Math.sin(u)*i]);return t.push(r),t}setDistance(t){return this.distance=t,this}ensureLastPoint(t){return Qr(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t}offset(t){return this.setDistance(t),this.distance===0?this.vertices:this.distance>0?this.margin(this.distance):this.padding(-this.distance)}offsetSegment(t,e,i,s){const r=[i.offset(i.inNormal[0]*s,i.inNormal[1]*s),i.inverseOffset(i.outNormal[0]*s,i.outNormal[1]*s)],n=[];for(let a=0,o=2;a<o;a++){const l=r[a],c=r[(a+o-1)%o];this.createArc(n,a===0?t:e,s,c.next,l.current,this.arcSegments,!0)}return n}margin(t){if(this.setDistance(t),typeof this.vertices[0]=="number")return this.offsetPoint(this.distance);if(t===0)return this.vertices;let e=this.offsetLines(this.distance);return e=Xt.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 Xt.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(si(this.vertices[0])&&typeof this.vertices[0][0]!="number"){const i=[];for(let s=0,r=this.edges.length;s<r;s++){const n=this.offsetContour(this.vertices[s],this.edges[s]);n.length>0&&i.push(n)}i.length>0&&(e=i.length===1?i[0]:Xt.union(i[0],...i.slice(1)))}else e=this.vertices.length===1?this.offsetPoint(t):this.offsetContour(this.vertices,this.edges);return e}offsetContour(t,e){let i=[],s=0,r=0;if(si(t[0])&&typeof t[0][0]=="number"){for(s=0,r=t.length-1;s<r;s++){const n=this.ensureLastPoint(this.offsetSegment(t[s],t[s+1],e[s],this.distance)),a=[n];i.push(a)}i.length>0&&(i=i.length===1?[i[0]]:Xt.union(i[0],i.slice(1)))}else{const n=[];for(s=0,r=e.length;s<r;s++){const a=this.offsetContour(t[s],e[s]);a.length>0&&n.push(a)}n.length>0&&(i=n.length===1?n[0]:Xt.union(n[0],...n.slice(1)))}return i}offsetPoint(t){this.setDistance(t);let e=this.arcSegments*2;const i=[],s=this.vertices,r=this.distance;let n=0;e%2===0&&e++;for(let a=0;a<e;a++)n+=2*Math.PI/e,i.push([s[0]+r*Math.cos(n),s[1]+r*Math.sin(n)]);return[[this.ensureLastPoint(i)]]}}class Kn{constructor(t){p(this,"viewer");p(this,"composerEnabled");p(this,"composer");p(this,"renderPass");p(this,"effectFxaaPass");p(this,"saoPass");p(this,"ssaoPass");p(this,"outlinePass");p(this,"ssaaRenderPass");p(this,"bloomPass");p(this,"unrealBloomPass");p(this,"vertexNormalsHelpers");this.composerEnabled=!0,this.viewer=t,this.composer=new Da.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(re.AfterRender,()=>this.render())}get enabled(){return this.composerEnabled}set enabled(t){this.composerEnabled=t}get renderPassEnabled(){return!!this.renderPass?.enabled}set renderPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:r}=this.viewer.container;if(this.composer){if(t&&!this.renderPass){const n=new Ba.RenderPass(e,i);n.setSize(s,r),this.composer.addPass(n),this.renderPass=n}this.renderPass&&(this.renderPass.enabled=t),this.viewer.enableRender()}}get fxaaPassEnabled(){return!!this.effectFxaaPass?.enabled}set fxaaPassEnabled(t){if(!this.composer)return;const{width:e,height:i}=this.viewer.container;if(t&&!this.effectFxaaPass){const s=new La.ShaderPass(Na.FXAAShader);s.uniforms.resolution.value.set(1/e,1/i),s.renderToScreen=!0,s.setSize(e,i),this.composer.addPass(s),this.effectFxaaPass=s}this.effectFxaaPass&&(this.effectFxaaPass.enabled=t),this.viewer.enableRender()}get saoPassEnabled(){return!!this.saoPass?.enabled}set saoPassEnabled(t){const{width:e,height:i}=this.viewer.container,s=this.viewer.scene,r=this.viewer.camera;if(this.composer){if(t&&!this.saoPass){const n=new Ra.SAOPass(s,r,new d.Vector2(1/e,1/i));n.setSize(e,i),n.params.output=0,n.params.saoBias=.5,n.params.saoIntensity=3e-4,n.params.saoScale=8,n.params.saoKernelRadius=40,n.params.saoMinResolution=0,this.composer.addPass(n),this.saoPass=n}this.saoPass&&(this.saoPass.enabled=t),this.viewer.enableRender()}}get ssaoPassEnabled(){return!!this.ssaoPass?.enabled}set ssaoPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:r}=this.viewer.container;if(this.composer){if(t&&!this.ssaoPass){const n=new Fa.SSAOPass(e,i,s,r);n.kernelRadius=16,n.minDistance=1e-4,n.maxDistance=.3,this.composer.addPass(n),this.ssaoPass=n}this.ssaoPass&&(this.ssaoPass.enabled=t),this.viewer.enableRender()}}get outlinePassEnabled(){return!!this.outlinePass?.enabled}set outlinePassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:r}=this.viewer.container;if(this.composer){if(t&&!this.outlinePass){const n=new za.OutlinePass(new d.Vector2(s,r),e,i);n.edgeStrength=3,n.edgeGlow=0,n.edgeThickness=2,n.pulsePeriod=0,n.visibleEdgeColor.set(16711680),n.hiddenEdgeColor.set(16752768),this.composer.addPass(n),this.outlinePass=n}this.outlinePass&&(this.outlinePass.enabled=t),this.viewer.enableRender()}}get ssaaPassEnabled(){return!!this.ssaaRenderPass?.enabled}set ssaaPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera;if(this.composer){if(t&&!this.ssaaRenderPass){const s=new ja.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 Va.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 Ua.UnrealBloomPass(new d.Vector2(e,i),1,0,0);s.threshold=0,s.strength=.5,s.radius=0,this.composer.addPass(s),this.unrealBloomPass=s}this.unrealBloomPass&&(this.unrealBloomPass.enabled=t),this.viewer.enableRender()}}setOutlinePassSelectObjects(t){this.outlinePass&&(this.outlinePass.selectedObjects=t)}enableModelEdges(t){const e=this.viewer.loadedModels;for(let i=0;i<e.length;++i){const s=e[i];if(s instanceof zs)if(t&&!s.edges){const r=s.getModelObject();r&&(S.debug("[Viewer] Generating outlines for model '"+r.id+"'"),s.enableOutline(t))}else s.edges&&s.edges.forEach(r=>r.visible=t);else s instanceof Vs&&S.warn("[BimTiles] enableModelEdges() is not implemented for bimtiles yet.")}this.viewer.enableRender()}showVertexNormals(t,e=.1){t?(!this.vertexNormalsHelpers&&(this.vertexNormalsHelpers=new d.Group),this.viewer.scene.traverseVisible(i=>{const s=["SKYBOX","GROUND_GRID","GROUND_GRASS","BIM_VIEWER_BOX_HELPER"];if(i instanceof d.Mesh&&!s.includes(i.name)){if(!i.geometry.attributes.normal)return;const n=new Ha.VertexNormalsHelper(i,e,16711680);this.vertexNormalsHelpers?.add(n)}}),this.viewer.scene.add(this.vertexNormalsHelpers)):this.vertexNormalsHelpers&&(this.viewer.scene.remove(this.vertexNormalsHelpers),this.vertexNormalsHelpers=void 0)}render(){!this.composer||!this.enabled||this.composer.render()}destroy(){this.renderPass&&(this.composer?.removePass(this.renderPass),this.renderPass.dispose(),this.renderPass=void 0),this.effectFxaaPass&&(this.composer?.removePass(this.effectFxaaPass),this.effectFxaaPass.dispose(),this.effectFxaaPass=void 0),this.saoPass&&(this.composer?.removePass(this.saoPass),this.saoPass.dispose(),this.saoPass=void 0),this.ssaoPass&&(this.composer?.removePass(this.ssaoPass),this.ssaoPass.dispose(),this.ssaoPass=void 0),this.outlinePass&&(this.composer?.removePass(this.outlinePass),this.outlinePass.dispose(),this.outlinePass=void 0),this.ssaaRenderPass&&(this.composer?.removePass(this.ssaaRenderPass),this.ssaaRenderPass.dispose(),this.ssaaRenderPass=void 0),this.bloomPass&&(this.composer?.removePass(this.bloomPass),this.bloomPass.dispose(),this.bloomPass=void 0),this.unrealBloomPass&&(this.composer?.removePass(this.unrealBloomPass),this.unrealBloomPass.dispose(),this.unrealBloomPass=void 0),this.composer&&(this.composer?.dispose(),this.composer=void 0)}}class dc extends Qi{constructor(e,i){super(e);p(this,"name");p(this,"loadedModels");p(this,"distanceCullingFactor");p(this,"selectedObject");p(this,"effect");if(this.name=Be.Viewer3d,this.loadedModels=[],this.distanceCullingFactor=150,this.effect=new Kn(this),this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new d.Vector3(100,50,100),r=new d.Vector3(0,0,0),n={eye:s,look:r};this.cameraManager.flyToViewpoint(n)}this.cameraManager.setProjection($e.Perspective),this.cameraManager.setNavigationMode(Ne.Orbit),this.setupDefaultEvents(),this.setDefaultBackground()}setupDefaultEvents(){let e=!1,i,s=0,r=0,n=0;const a=300,o=f=>r===-1||n===-1?!1:Math.abs(f.x-r)<5&&Math.abs(f.y-n)<5,l=f=>{const m=f.timestamp-s;return!!(f.button===Le.Left&&m<a&&o(f))};let c,u=!1;this.inputManager.addEventListener("pointerdown",f=>{e=!1,i=f.button;const m=new d.Vector2(f.x,f.y);c=this.pickObject(m),u=c?.object===this.selectedObject,f.button===Le.Left&&this.handleAnchorPoint(c)}),this.inputManager.addEventListener("pointermove",f=>{i!==void 0&&(e=!o(f),i===Le.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0))}),this.inputManager.addEventListener("pointerup",f=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}f.button===Le.Left?l(f)?(c?.object?this.flyToObject(c.object):this.viewFitAll(),s=0,r=-1,n=-1):(this.selectedObject&&(this.selectedObject instanceof pt?this.selectedObject.selected=!1:this.clearHighlight(),this.selectedObject=void 0),s=f.timestamp,r=f.x,n=f.y,c?.object&&!u&&this.handleClickObject(c.object)):(f.button,Le.Right)})}setDefaultBackground(){this.sceneManager.renderer.setClearColor(11119017,1),this.sceneManager.setBackground(null),this.sceneManager.setEnvironmentFromData()}handleAnchorPoint(e){const i=new d.Vector3;this.selectedObject?new d.Box3().setFromObject(this.selectedObject).getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=n=>!n.userData.modelId&&n.parent?i(n.parent):n.userData.modelId,s=i(e);this.loadedModels.find(n=>n.modelId===s)?.highlightObject(e),this.selectedObject=e,this.enableRender()}is3d(){return!0}async loadLocalModel(e,i,s,r){return this.loadModelInternal(i,r,!0,e,s)}async loadModel(e,i){return this.loadModelInternal(e,i)}async loadModelInternal(e,i,s,r,n){this.spinner.increaseJobCount();const a=e.modelId||e.src,o=Re.t("ProgressBar.Loading"),l=b=>{this.progressBar?.updateProgress(a,o,b),i?.(new ProgressEvent("LoadProgress",{loaded:b,total:100}))};let c=!1;const u=(b,E,O)=>{let _=b.loaded*100/b.total;_=_*(O-E)/100+E,_>O&&(c||(S.warn("[Progress] Invalid ProgressEvent:",b),c=!0),_=O),this.progressBar?.updateProgress(a,o,_),i?.(new ProgressEvent("LoadProgress",{loaded:_,total:100}))},f=b=>u(b,0,50);this.progressBar?.addProgressItem(a),l(0);let m;if(s?(this.loaderHelper.setLoadManager(n),m=await this.loaderHelper.loadLocalModel(r,e.src,i)):m=await this.loaderHelper.loadModel(e.src,e.fileFormat,f),e.matrix&&e.matrix.length===16){const b=new d.Matrix4;b.elements=e.matrix,m.applyMatrix4(b)}const g=this.getUniqueModelId(e.modelId||e.src),x=new zs({modelId:g,object:m});this.addModel(x),l(90);const y=x.getBBox();this.loadedModels.length===1&&setTimeout(()=>this.goToHomeView(),0);const v=new d.Vector3;y.getCenter(v),this.cameraManager.setOrbitPoint(v),this.spinner.decreaseJobCount(),l(100),this.progressBar?.delayRemoveProgressItem(a),this.dispatchEvent(re.ModelLoad)}setDistanceCullingFactor(e){this.distanceCullingFactor=e}getDistanceCullingFactor(){return this.distanceCullingFactor}setObjectOpacity(e,i){this.loadedModels.forEach(s=>s.setObjectOpacity(e,i)),this.enableRender()}setOtherObjectsOpacity(e,i){this.loadedModels.forEach(s=>{s.setOpacity(i),s.clearObjectOpacity(e)}),this.enableRender()}clearObjectOpacity(e){this.loadedModels.forEach(i=>i.clearObjectOpacity(e)),this.enableRender()}setModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.setOpacity(),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}setObjectVisible(e,i){this.loadedModels.forEach(s=>s.setObjectVisible(e,i)),this.enableRender()}hideOtherObjects(e){this.loadedModels.forEach(i=>{i.setVisible(!1),i.setObjectVisible(e,!0)}),this.enableRender()}setModelVisible(e,i){this.loadedModels.find(r=>r.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}enableModelOutline(e,i){this.loadedModels.find(r=>r.modelId===e)?.enableOutline(i),this.enableRender()}enableModelsOutline(e){this.loadedModels.forEach(i=>i.enableOutline(e)),this.enableRender()}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof pt&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}enableSsao(e){this.effect.enabled=e,this.effect.renderPassEnabled=e,this.effect.ssaaPassEnabled=e,this.effect.ssaoPassEnabled=e}getSsaoEnabled(){return this.effect.enabled&&this.effect.ssaoPassEnabled}async setEnvironmentData(e){await this.sceneManager.setEnvironmentFromData(e),this.enableRender()}async setEnvironment(e){await this.sceneManager.setEnvironment(e),this.enableRender()}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}setModelClipPlanes(e,i){this.loadedModels.find(r=>r.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(i),this.sceneManager.setClipPlanes(e)}}function en(h){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),h)}function tn(h){return Object.assign(Object.assign({},{elementCount:0,batchElementCount:0,instanceElementCount:0,batchCount:0,instanceCount:0,tileCount:0,userDataCount:0,materialCount:0,meshVertexCount:0,meshFaceCount:0,textureCount:0,texturePixels:0}),h)}function uc(h){const t={transform:new d.Matrix4,boundingVolume:new d.Box3};return Object.assign(Object.assign({},t),h)}class fc{constructor(t){p(this,"url");p(this,"metadata");p(this,"statistics");p(this,"view");this.url=t,this.metadata=en(),this.statistics=tn(),this.view=uc()}async parse(){return await fetch(this.url).then(t=>t.ok?t.json():(S.error('[BimTiles] Failed to request "'+this.url+'", status '+t.status+" : "+t.statusText),Promise.reject(!1))).then(t=>(this.metadata=en(t.metadata),this.statistics=tn(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 pc=0;class mc extends Qi{constructor(e,i){super(e);p(this,"name");p(this,"pickUsageScene");p(this,"effect");p(this,"loadedModels");p(this,"selectedObject");p(this,"enableHoverEffect");if(this.name=Be.BimTilesViewer,this.loadedModels=[],this.enableHoverEffect=!1,this.effect=new Kn(this),this.pickUsageScene=new d.Scene,this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new d.Vector3(100,50,100),r=new d.Vector3(0,0,0),n={eye:s,look:r};this.cameraManager.flyToViewpoint(n)}this.cameraManager.setProjection($e.Perspective),this.cameraManager.setNavigationMode(Ne.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(re.BeforeRender,()=>{this.update3dTiles()})}setupDefaultEvents(){let e=!1,i,s=0,r=0,n=0;const a=300,o=f=>r===-1||n===-1?!1:Math.abs(f.x-r)<5&&Math.abs(f.y-n)<5,l=f=>{const m=f.timestamp-s;return!!(f.button===Le.Left&&m<a&&o(f))};let c,u=!1;this.inputManager.addEventListener("pointerdown",f=>{e=!1,i=f.button,this.renderImmediately();const m=new d.Vector2(f.x,f.y);if(c=this.pickManager.pick(m,this.pickUsageScene),u=!!this.selectedObject&&c?.tilesetId===this.selectedObject?.tilesetId&&c?.userId===this.selectedObject?.userId,f.button===Le.Left){let g=this.pickUsageScene;if(c){const y=this.loadedModels.find(T=>T.modelId===""+c?.tilesetId);if(y){const T=y.getObjectByUserId(c.userId);T&&(g=T)}}const x=this.pickManager.pickObject(m,[g]);this.handleAnchorPoint(x)}}),this.inputManager.addEventListener("pointermove",f=>{if(i!==void 0)e=!o(f),i===Le.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0);else if(this.enableHoverEffect){const m=new d.Vector2(f.x,f.y),g=this.pickManager.pick(m,this.pickUsageScene),x=this.getHoveredObject();g?(!x||x.tilesetId!==g.tilesetId||x.userId!==g.userId)&&this.setObjectHoveredByUserId(g.tilesetId,g.userId,!0):x&&this.clearHovered()}this.handleMouseMove(f)}),this.inputManager.addEventListener("pointerup",f=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}f.button===Le.Left?l(f)?(c?this.flyToUserId(c.tilesetId,c.userId):this.viewFitAll(),s=0,r=-1,n=-1):(this.selectedObject&&(this.clearHighlight(),this.selectedObject=void 0),s=f.timestamp,r=f.x,n=f.y,c&&!u&&this.handleClickObject(c)):(f.button,Le.Right)})}setDefaultBackground(){this.sceneManager.setBackground(new d.Color(11119017)),this.sceneManager.setEnvironmentFromData()}renderImmediately(){const{renderer:e,scene:i,camera:s}=this;!e||!i||!s||e.render(i,s)}handleAnchorPoint(e){const i=new d.Vector3;this.selectedObject?this.getBoxByUserId(this.selectedObject.tilesetId,this.selectedObject.userId)?.getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=this.loadedModels.find(s=>s.modelId===""+e.tilesetId);i&&(i?.setObjectHighlightedByUserIds([e.userId],!0),this.selectedObject=e),this.enableRender()}is3d(){return!0}setModelOpacity(e,i){this.loadedModels.find(r=>r.modelId===e)?.setOpacity(i),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}enableModelOutline(e,i){S.warn("Outline for bimtiles is not implemented yet.")}enableModelsOutline(e){S.warn("Outline for bimtiles is not implemented yet.")}setModelVisible(e,i){this.loadedModels.find(r=>r.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof pt&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}flyToUserId(e,i){const s=this.getBoxByUserId(e,i);s&&this.cameraManager.flyToBox(s)}getBoxByUserId(e,i){const s=this.loadedModels.find(r=>r.modelId===""+e);if(s)return s.getBBoxByUserId(i)}handleMouseMove(e){}update3dTiles(){if(!this.camera)return;const e=this.loadedModels.filter(i=>!!i.tilesRenderer);e.length!==0&&(this.camera.updateMatrixWorld(),e.forEach(i=>{i.tilesRenderer.update()}))}async loadModel(e,i){if(e.src.length===0)return Promise.reject();const s=new fc(e.src);if(!await s.parse())return Promise.reject();let n=e.src.replace(/\/[^\\/]*\/?$/,"/");n=new URL(n,window.location.href).toString(),this.spinner.increaseJobCount();const a=s.getView().boundingVolume.clone();a.applyMatrix4(s.getView().transform);const o=new Vs({modelId:""+pc++,bbox:a},n,s),l=o.getTilesRenderer(),c=l.group;if(l.onBeforeParseTile=()=>{this.spinner.increaseJobCount()},l.onLoadModel=u=>{u.traverse(f=>{f.matrixAutoUpdate&&(f.matrixAutoUpdate=He,f.updateMatrix()),f.isMesh&&(f.castShadow=!0,f.receiveShadow=!0),f.geometry&&f.layers.enableAll()}),this.enableRender(),setTimeout(()=>this.spinner.decreaseJobCount(),100)},l.setCamera(this.camera),l.setResolutionFromRenderer(this.camera,this.renderer),l.update(),c){c.applyMatrix4(s.getView().transform),o.pickUsageGroup.applyMatrix4(s.getView().transform),this.pickUsageScene.add(o.pickUsageGroup),this.addModel(o),this.cameraManager.adjustCameraByBBox(a);const u=new d.Vector3;return a.getCenter(u),this.cameraManager.setOrbitPoint(u),this.loadedModels.length===1&&this.goToHomeView(),this.spinner.decreaseJobCount(),this.dispatchEvent(re.ModelLoad),Promise.resolve()}return this.spinner.decreaseJobCount(),Promise.reject()}setObjectHighlightedByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectHighlightedByUserIds(i,s),this.enableRender()}setObjectOpacityByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectOpacityByUserIds(i,s),this.enableRender()}setOtherObjectOpacityByUserIds(e,i,s){this.loadedModels.forEach(a=>{a.setOpacity(s)});const r=""+e;this.loadedModels.find(a=>a.modelId===r)?.clearObjectOpacityByUserIds(i),this.enableRender()}setObjectVisibleByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectVisibleByUserIds(i,s),this.enableRender()}setOtherObjectVisibleByUserIds(e,i,s){this.loadedModels.forEach(n=>{n.setVisible(s)}),this.loadedModels.find(n=>n.modelId===""+e)?.setObjectVisibleByUserIds(i,!s),this.enableRender()}setObjectHoveredByUserId(e,i,s){if(!this.enableHoverEffect)return;this.clearHovered(),this.loadedModels.find(n=>n.modelId===""+e)?.setObjectHoveredByUserId(i,s),this.enableRender()}getHoveredObject(){for(const e of this.loadedModels){const i=e.getHoveredObject();if(i)return i}}clearHovered(){this.loadedModels.forEach(e=>e.clearHovered()),this.enableRender()}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}setModelClipPlanes(e,i){this.loadedModels.find(r=>r.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(!i),this.sceneManager.setClipPlanes(e)}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}pickObjects(e,i){const s=this.pickManager.pick(e,this.pickUsageScene);let r=this.pickUsageScene;if(s){const a=this.loadedModels.find(o=>o.modelId===""+s?.tilesetId);if(a){const o=a.getObjectByUserId(s.userId);o&&(r=o)}}let n=this.pickManager.pickObjects(e,[r],i);return n&&this.renderer.clippingPlanes.length>0&&(n=n.filter(a=>this.renderer.clippingPlanes.every(function(o){return o.distanceToPoint(a.point)>0}))),n}getErrorTarget(){return this.loadedModels.length>0?this.loadedModels[0].getTilesRenderer().errorTarget:8}setErrorTarget(e){this.loadedModels.forEach(i=>{i.getTilesRenderer().errorTarget=e})}}class gc extends mt{constructor(e,i){if(!i.id)throw new Error("[Plugin] Missing plugin id!");super();p(this,"id");p(this,"viewer");this.id=i.id,this.viewer=e,e.addPlugin(this)}destroy(){this.viewer.removePlugin(this)}}K.install({THREE:d});class yc extends K{constructor(e,i){super(e,i);p(this,"minZoom");p(this,"draggingSmoothTime");p(this,"dollySpeedBackup");p(this,"azimuthRotateSpeedBackup");p(this,"polarRotateSpeedBackup");p(this,"truckSpeedBackup");p(this,"onKeyDown");p(this,"onKeyUp");p(this,"keyTruckSpeed");p(this,"keys");this.minZoom=0,this.draggingSmoothTime=0,this.keyTruckSpeed=7,this.keys={left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",bottom:"ArrowDown"},this.onKeyDown=s=>{if(this.enabled){switch(s.code){case this.keys.up:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,1),this._isUserControllingRotate=!0):(this._truckInternal(0,this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.bottom:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,-1),this._isUserControllingRotate=!0):(this._truckInternal(0,-this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.left:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(1,0),this._isUserControllingRotate=!0):(this._truckInternal(this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break;case this.keys.right:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(-1,0),this._isUserControllingRotate=!0):(this._truckInternal(-this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break}this.dispatchEvent({type:"control"})}},this.onKeyUp=s=>{this.dispatchEvent({type:"controlend"})},this._getClientRect(this._elementRect),this.dollySpeedBackup=this.dollySpeed,this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.truckSpeedBackup=this.truckSpeed}get enableZoom(){return!!this.dollySpeed}set enableZoom(e){e?this.dollySpeed=this.dollySpeedBackup:(this.dollySpeedBackup=this.dollySpeed,this.dollySpeed=0)}get enableRotate(){return!!this.azimuthRotateSpeed||!!this.polarRotateSpeed}set enableRotate(e){e?(this.azimuthRotateSpeed=this.azimuthRotateSpeedBackup,this.polarRotateSpeed=this.polarRotateSpeedBackup):(this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.azimuthRotateSpeed=0,this.polarRotateSpeed=0)}get enableTruck(){return!!this.truckSpeed}set enableTruck(e){e?this.truckSpeed=this.truckSpeedBackup:(this.truckSpeedBackup=this.truckSpeed,this.truckSpeed=0)}listenToKeyEvents(){this._domElement?.addEventListener("keydown",this.onKeyDown),this._domElement?.addEventListener("keyup",this.onKeyUp)}stopListenToKeyEvents(){this._domElement?.removeEventListener("keydown",this.onKeyDown),this._domElement?.removeEventListener("keyup",this.onKeyUp)}dispose(){super.dispose(),this.stopListenToKeyEvents()}}var $n=(h=>(h[h.Browser=0]="Browser",h[h.Browserless=1]="Browserless",h[h.Headless=2]="Headless",h))($n||{});class xc{constructor(t,e,i){p(this,"containerOrCanvas");p(this,"glContext");p(this,"camera");p(this,"scene");p(this,"renderer");p(this,"renderTarget");p(this,"controls");p(this,"selectedObject");p(this,"loadedModels");p(this,"pmremGenerator");p(this,"clock");p(this,"viewerMode");p(this,"raycaster");p(this,"savedMaterialsForOpacity");p(this,"jobCount");p(this,"bbox");p(this,"outlineMaterial");p(this,"outlineRoot");p(this,"transparentObjectIds");p(this,"requestAnimationFrameHandle");p(this,"applyOptionsAndAddToScene");p(this,"getMeshes");if(this.scene=this.initScene(),this.selectedObject=void 0,this.loadedModels=[],this.clock=new d.Clock,this.viewerMode=0,this.raycaster=new d.Raycaster,this.savedMaterialsForOpacity=[],this.jobCount=0,this.bbox=new d.Box3,this.outlineMaterial=new d.LineBasicMaterial({color:1118481}),this.outlineRoot=new d.Group,this.transparentObjectIds=[],this.applyOptionsAndAddToScene=async(s,r,n,a)=>{if(S.info("[Viewer] '"+s+"' is loaded, adding to scene..."),n.matrix&&n.matrix.length===16){const f=new d.Matrix4;f.elements=n.matrix,r.applyMatrix4(f)}r.traverse(f=>{f.geometry&&f.layers.enableAll(),f instanceof d.Light&&(f.visible=!1)});let o;n.edges&&(o=await $.createOutlines(r,void 0,a));let l=n.modelId||n.src;const c=f=>!!this.loadedModels.find(m=>m.modelId===f);if(c(l)){let f=1;for(;c(l+"_"+f);)f++;l=l+"_"+f,S.warn("[Viewer] Model '"+l+"' is loaded more than once!")}const u={modelId:l,object:r,edges:o};this.addModel(u)},this.getMeshes=s=>{const r=[];return s instanceof d.Mesh?r.push(s):s.traverseVisible(n=>{n instanceof d.Mesh&&r.push(n)}),r},this.containerOrCanvas=t,e&&(this.viewerMode=e),this.glContext=i,this.viewerMode===1&&!(!(t instanceof HTMLDivElement)&&i))throw new Error("[Viewer] Parameters don't match Browserless viewerMode !");this.increaseJobCount(),this.init(),this.decreaseJobCount(),S.info("[Viewer] Initialized"),this.animate()}init(){this.initRenderer(),this.initCamera(),this.initControls(),this.initLights(),this.initPointerEvents(),this.scene.add(this.outlineRoot)}initScene(){const t=new d.Scene;return t.background=new d.Color(7112861),t.matrixAutoUpdate=!0,t}isBrowserlessMode(){return this.viewerMode===1}isBrowserMode(){return this.viewerMode===0}initRenderer(){const t={antialias:!0,preserveDrawingBuffer:!0},e=this.isBrowserlessMode();e&&Object.assign(t,{canvas:this.containerOrCanvas,context:this.glContext});const i=new d.WebGLRenderer(t);if(e){const s=this.containerOrCanvas.width,r=this.containerOrCanvas.height;S.info("[Viewer] Render target size: "+s+" x "+r),this.renderTarget=new d.WebGLRenderTarget(s,r,{minFilter:d.LinearFilter,magFilter:d.NearestFilter,format:d.RGBAFormat,type:d.UnsignedByteType}),i.setRenderTarget(this.renderTarget)}else{const s=this.containerOrCanvas.clientWidth,r=this.containerOrCanvas.clientHeight;this.containerOrCanvas.append(i.domElement),i.setPixelRatio(window.devicePixelRatio),i.setSize(s,r)}i.outputColorSpace=d.SRGBColorSpace,i.toneMappingExposure=1,i.setClearColor(11119017,1),i.shadowMap.enabled=!0,i.shadowMap.type=d.PCFSoftShadowMap,this.renderer=i,e||(this.pmremGenerator=new d.PMREMGenerator(i),this.pmremGenerator.compileEquirectangularShader(),this.setEnvironmentFromDataArray())}initCamera(){if(!this.scene)return;const t=this.containerOrCanvas.clientWidth||this.containerOrCanvas.width||0,e=this.containerOrCanvas.clientHeight||this.containerOrCanvas.height||0;let i=1;t&&e&&(i=t/e),this.camera=new d.PerspectiveCamera(68,i,.05,1e4),this.camera.position.set(10,10,10),this.camera.lookAt(0,0,0),this.scene.add(this.camera)}initControls(){if(!this.renderer)return;const t=this.camera;if(!t)return;const e=new yc(t,this.renderer.domElement);e.smoothTime=.05,e.enabled=!0,e.keyTruckSpeed=10,e.keys={left:"KeyD",up:"KeyE",right:"KeyA",bottom:"KeyQ"},e.update(0),this.controls=e,e.addEventListener("update",()=>{!this.isBrowserMode()&&this.renderer&&this.renderer.render(this.scene,t)})}initLights(){if(!this.scene)return;const t=16777215,e=.3,i=new d.DirectionalLight(t,e);i.position.set(-2,2,4);const s=new d.AmbientLight(3158064),r=new d.HemisphereLight(t,14540253,3);r.position.set(0,300,0),this.scene.add(i),this.scene.add(s),this.scene.add(r)}initPointerEvents(){if(!this.renderer||!this.camera||!this.controls)return;let t=!1,e=!1,i=-1,s=-1;this.renderer.domElement.addEventListener("pointerdown",r=>{i=r.x,s=r.y,t=!1}),this.renderer.domElement.addEventListener("pointermove",r=>{i>=0&&s>=0&&(Math.abs(r.x-i)>5||Math.abs(r.y-s)>5)&&(t=!0)}),this.renderer.domElement.addEventListener("pointerup",()=>{e&&setTimeout(()=>{e=!1},200),i=-1,s=-1}),this.renderer.domElement.addEventListener("dblclick",r=>{e=!0,t||(this.handleMouseClick(r),this.flyToSelectedObject())})}animate(){this.isBrowserMode()&&requestAnimationFrame(this.animate.bind(this));const t=this.clock.getDelta();this.controls&&this.controls.update(t),this.scene&&this.camera&&this.renderer?.render(this.scene,this.camera)}destroy(){this.camera=void 0,this.scene&&this.scene.clear(),this.requestAnimationFrameHandle&&(cancelAnimationFrame(this.requestAnimationFrameHandle),this.requestAnimationFrameHandle=void 0),this.renderer&&(this.containerOrCanvas.removeChild(this.renderer.domElement),this.renderer.clear(),this.renderer.dispose(),this.renderer=void 0),this.controls&&(this.controls.dispose(),this.controls=void 0),this.renderTarget&&(this.renderTarget.dispose(),this.renderTarget=void 0),this.raycaster=void 0,this.selectedObject=void 0,this.savedMaterialsForOpacity=void 0,this.loadedModels=[]}async loadLocalModel(t,e,i){const r=await new ut().loadLocalModel(t,e.src,i);return r?(await this.applyOptionsAndAddToScene(t,r,e),Promise.resolve()):Promise.reject()}async loadModel(t,e){this.increaseJobCount();const s=await new ut().loadModel(t.src,t.fileFormat,e);return s?(await this.applyOptionsAndAddToScene(t.src,s,t),Promise.resolve()):Promise.reject()}parseGltf(t,e,i,s){this.increaseJobCount(),new ut().parseGltf(t,e.src,r=>{this.applyOptionsAndAddToScene(e.src,r,e),i&&i(r)},r=>{s&&s(r)})}addModel(t){if(!this.scene||!this.renderer)return;this.increaseJobCount();const e=new d.Box3().setFromObject(t.object);t.bbox||(t.bbox=e),this.scene.add(t.object),this.loadedModels.push(t),this.computeBoundingBox(),this.loadedModels.length===1&&(this.tryAdjustCameraNearAndFar(),this.goToHomeView()),this.renderer.shadowMap.needsUpdate=!0,S.info("[Viewer] Added '"+t.modelId+"' to scene"),this.decreaseJobCount()}addOrRemoveObjectOpacity(t=!0,e=.3,i,s){if(this.savedMaterialsForOpacity||(this.savedMaterialsForOpacity=[]),!this.scene)return;const r=this.scene,n=[];this.loadedModels.forEach(a=>{const o=a.object.id;if(t){this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0&&$.revertObjectOpacityById(r,o,this.savedMaterialsForOpacity);const l=$.setObjectOpacityById(r,o,e,i,s);n.push(...l)}else this.savedMaterialsForOpacity&&$.revertObjectOpacityById(r,o,this.savedMaterialsForOpacity)}),t?this.savedMaterialsForOpacity=n:this.savedMaterialsForOpacity=[]}hasTransparentObject(){return!!(this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0)}getIntersections(t){if(!this.raycaster||!this.camera||!this.scene)return[];let e=new d.Vector2;t&&(e=pe.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=pe.screen2Ndc(e,this.camera,this.containerOrCanvas);this.raycaster.setFromCamera(i,this.camera);const s=[];return this.loadedModels.forEach(r=>{const n=r.object;n&&n.visible&&s.push(n)}),this.raycaster.intersectObjects(s,!0)||[]}handleMouseClick(t){this.raycaster&&this.raycaster.layers.set(ft);const i=this.getIntersections(t).find(r=>{const n=r.object;return n.visible&&n instanceof d.Mesh});let s=i&&i.object||void 0;s&&this.selectedObject&&this.selectedObject.id===s.id&&(s=void 0),s?this.selectObject(s):this.clearSelection()}selectObject(t){if(this.selectedObject){const i=this.selectedObject.userData;if(i.originalMaterial){if(this.selectedObject.material){const s=this.selectedObject.material;Array.isArray(s)?s.forEach(r=>r.dispose()):s instanceof d.Material&&s.dispose()}this.selectedObject.material=i.originalMaterial,delete i.originalMaterial}this.selectedObject=void 0}if(!this.scene||!t)return;const e=de.clonedHighlightMaterials(t);e&&(this.selectedObject=t,this.selectedObject.userData.originalMaterial=this.selectedObject.material,this.selectedObject.material=e)}clearSelection(){this.selectObject()}flyToObjects(t){if(!t||t.length===0||!this.camera)return;const e=new d.Box3;t.forEach(r=>{const n=st.getBoundingBox(r);e.union(n)});const i=new d.Sphere;e.getBoundingSphere(i),this.controls?.fitToSphere(i,!0)}flyToObject(t){this.flyToObjects([t])}flyToSelectedObject(){this.selectedObject&&this.flyToObject(this.selectedObject)}flyTo(t,e,i){const s=this.camera,r=this.controls;if(!s||!r)return;t=Array.isArray(t)?new d.Vector3(t[0],t[1],t[2]):t,e=Array.isArray(e)?new d.Vector3(e[0],e[1],e[2]):e;const n=t,a=e;S.info("[Viewer] flyTo: ",V.vectorToString(n)),r.setPosition(n.x,n.y,n.z),r.setTarget(a.x,a.y,a.z),this.isBrowserMode()||this.renderer?.render(this.scene,s),i&&i()}goToHomeView(){const t=new d.Sphere;this.bbox.getBoundingSphere(t),this.controls?.fitToSphere(t,!0)}setEnvironmentFromDataArray(t){fi.createEnvTextureFromDataArray(this.pmremGenerator,t).then(e=>{this.scene.environment=e,this.isBrowserMode()||this.animate()})}tryAdjustCameraNearAndFar(){const t=this.camera;if(!this.scene||!t)return;const e=this.bbox,i=t.near,s=t.far,r=e.max.x-e.min.x,n=e.max.y-e.min.y,a=e.max.z-e.min.z,o=Math.max(r,n,a),l=5,c=o/l,u=o*l;if(i>c||s<u){const f=m=>V.numberToString(m);S.info("[Viewer] BBox's longest side is: "+f(o)),i>c&&(S.warn("[Viewer] camera.near("+f(i)+") shouldn't bigger than "+f(c)+", will change it!"),t.near=c),s<u&&(S.warn("[Viewer] camera.far("+f(s)+") shouldn't smaller than "+f(u)+", will change it!"),t.far=u)}t.updateProjectionMatrix()}isolateObjects(t){const e=this.transparentObjectIds.length>0?void 0:this.transparentObjectIds,i=this.transparentObjectIds.length>0?this.transparentObjectIds:void 0,s=new d.MeshBasicMaterial({color:16777215,transparent:!0,opacity:.1});this.loadedModels.forEach(n=>{const a=n.object.id;$.applyMaterialToObjectById(this.scene,a,s,i,e)}),this.outlineRoot.clear();let r=[];if(t.forEach(n=>{const a=n.modelId;let l=this.loadedModels.find(c=>c.modelId===a)?.object;l||(S.warn("[Viewer] The ModelId of "+a+" has no corresponding model."),l=this.scene),l.traverse(c=>{if(qs.includes(n.id,qs.get(c.userData,"UniqueId"))){const u=this.getMeshes(c);r=r.concat(u)}})}),r.length>0){r.forEach(a=>{const o=$.createOutline(a.geometry,this.outlineMaterial);o.applyMatrix4(a.matrixWorld),this.outlineRoot.add(o),o.updateWorldMatrix(!0,!1)});const n=r.map(a=>a.id);this.loadedModels.forEach(a=>{const o=a.object.id;$.revertAppliedMaterialToObjectById(this.scene,o,n)}),this.transparentObjectIds=n,this.flyToObjects(r)}else S.warn("[Viewer] No object found with uniqueIds: "+t.map(n=>n.id));this.isBrowserMode()||this.animate()}increaseJobCount(){++this.jobCount}decreaseJobCount(){--this.jobCount}computeBoundingBox(){const t=new d.Box3;return this.loadedModels.forEach(e=>{e.bbox&&!e.bbox.isEmpty()&&t.union(e.bbox)}),this.bbox=t,t}getContext(){return this.renderer?.getContext()}getCameraDirection(){const t=new d.Vector3;return this.camera?.getWorldDirection(t),{x:t.x,y:t.y,z:t.z}}setFov(t){this.camera&&(this.camera.fov=t,this.camera.updateProjectionMatrix())}}const Jn="1.0.0",Qn="VERSION",ea=()=>window.localStorage.getItem(Qn),ta=()=>{window.localStorage.setItem(Qn,Jn)},bc=()=>ea()!==Jn?(ta(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>Se.Mesh});exports.BaseDxfCompareHelper=Xn;exports.BaseViewer=Qi;exports.BimTilesModel=Vs;exports.BimTilesRenderer=Dn;exports.BimTilesViewer=mc;exports.BinaryReader=xi;exports.BoxSelectHelper=Ki;exports.ByBlock=pi;exports.ByLayer=Fs;exports.CSS2DObjectUtils=po;exports.CameraProjection=$e;exports.CancelablePromise=co;exports.CanvasRender=yi;exports.ColorUtils=Gt;exports.CommonUtils=V;exports.CompareDrawable=rt;exports.Container=Us;exports.ControlsMode=Ne;exports.CoordinateUtils=pe;exports.DecimalPrecisionRange=nn;exports.DefaultCameraFar=Ui;exports.DefaultCameraFov=ln;exports.DefaultCameraNear=Vi;exports.DefaultLanguage=an;exports.DefaultOpacity=Ls;exports.DefaultViewer3dConfig=Bh;exports.DeviceUtils=be;exports.Drawable=pt;exports.DrawableList=$i;exports.DxfChangeType=Te;exports.DxfCompare=Ue;exports.DxfCompareHelper=hc;exports.DxfCompareMarkupManager=As;exports.DxfLoader=Y;exports.DxfParser=Mn;exports.DxfRenderOrder=ge;exports.DxfUtils=Qe;exports.EdgeUtils=hn;exports.Event=mt;exports.ExportUtils=Ss;exports.FontManager=Ke;exports.FpsUtils=Mo;exports.GenerateMeshBvhWorker=Nn;exports.GeometryUtils=U;exports.GroundPlaneRenderOrder=Yn;exports.HighlightColor=Bs;exports.HighlightColorRgba=go;exports.IconfontClass=yo;exports.IconfontClass2=xo;exports.InputManager=Wn;exports.InstantiateHelper=Nh;exports.LayerForHitableObjects=on;exports.LayerForSelectableObjects=ft;exports.LayerForSnapableObjects=Ce;exports.Line=Wa;exports.LinePatternShaders=xn;exports.LoadingHelper=ut;exports.MaterialUtils=de;exports.MathUtils=R;exports.MatrixAutoUpdate=He;exports.MergeUtils=oe;exports.MeshBvhHelper=Hs;exports.MobileTouchHelperDrawable=nc;exports.Model=Ji;exports.Model2d=qt;exports.Model3d=zs;exports.NestedCompareTypes=ai;exports.OSnapHelper=ec;exports.OSnapIconSize=Ao;exports.OSnapMarkerType=tt;exports.OSnapType=Hn;exports.ObjectPixelSizeHelper=Yh;exports.ObjectUtils=$;exports.Offset=cc;exports.OrbitControls=Rn;exports.OutlineColorRgba=ji;exports.PickMarkupHelper=tc;exports.PlanControls=Fn;exports.Plugin=gc;exports.Points=Ya;exports.PolygonUtils=_o;exports.ProgressBar=Ns;exports.RafHelper=Vn;exports.SVGObjectUtils=Io;exports.SceneUtils=st;exports.SectionUtils=dt;exports.ShaderChunk=ho;exports.SimplifyUtils=Po;exports.SnapDrawable=ye;exports.Spinner=Bn;exports.TextSearchHelper=Is;exports.TextureUtils=fi;exports.ThresholdAngleForEdge=Rs;exports.UnitConversionByMeter=Es;exports.UnitLabels=cn;exports.UnitScaleConversion=Wo;exports.UnitScaleToMeter=Ps;exports.Units=De;exports.Viewer2d=Gs;exports.Viewer3d=dc;exports.Viewer3dLite=xc;exports.Viewer3dUtils=Bo;exports.ViewerEvent=re;exports.ViewerMode=$n;exports.ViewerName=Be;exports.Views=un;exports.ZoomToRectHelper=qn;exports.bspline=pn;exports.checkIsNewVersion=bc;exports.cn=Os;exports.createHatchPatternShaderMaterial=bn;exports.decodeDxfTextCharacterCodes=mn;exports.decodeDxfTextMbcsCharacterCodes=yn;exports.decodeDxfTextUnicodeCodePoints=gn;exports.en=To;exports.getLengthValueByUnit=Do;exports.getUnitStr=_s;exports.getVersionFromLocalStorage=ea;exports.i18n=Re;exports.log=S;exports.parseDxfMTextContent=oi;exports.parseDxfTextContent=Ni;exports.round10=fn;exports.setIcon=fo;exports.setLogLevel=rn;exports.setVersionToLocalStorage=ta;exports.showPrecisionValue=mo;
1531
+ `,Dn=Symbol("INITIAL_FRUSTUM_CULLED");function Ih(h,t){h.traverse(e=>{e.frustumCulled=e[Dn]&&t})}const Pi=new d.Vector3,Ai=new d.Vector3,ps=new d.Box3;class Bn extends va.TilesRenderer{constructor(e,i){super(e);p(this,"highlighUsage");p(this,"transparentUsage");p(this,"pickUsage");p(this,"materialManager");p(this,"baseUrl");p(this,"propertyParser");p(this,"tilesetId");p(this,"onBeforeParseTile");p(this,"protoRoot");this.downloadQueue.maxJobs=6,this.parseQueue.maxJobs=4,this.optimizeRaycast=!1,this.errorTarget=8,this.loadSiblings=!1,this.tilesetId=i,this.baseUrl=e.replace(/\/[^\\/]*\/?$/,"/"),this.highlighUsage=new d.Group,this.highlighUsage.name="highlighUsage-"+this.tilesetId,this.group.add(this.highlighUsage),this.transparentUsage=new d.Group,this.transparentUsage.name="transparentUsage-"+this.tilesetId,this.group.add(this.transparentUsage),this.pickUsage=new d.Group,this.protoRoot=Wa.parse(Ah).root,this.propertyParser=new Oh(this.baseUrl,this.protoRoot)}getVertexColorArray(e,i=new d.Color(16777215)){const s=[],{r,g:n,b:a}=i;for(let o=0;o<e;o+=3)s.push(r,n,a);return new Float32Array(s)}createBatchedMesh(e){const{position:i,uv:s,normal:r,indice:n,barycentric:a,userIds:o,materialId:l,batchTable:c}=e;let u=e.color;const f=o.map(b=>Lr(this.tilesetId,b)),m=new d.BufferGeometry;m.setAttribute("position",new d.Float32BufferAttribute(i,3)),m.setAttribute("normal",new d.Float32BufferAttribute(r,3)),m.setAttribute("uv",new d.Float32BufferAttribute(s,2)),m.setAttribute("tileObjectId",new d.Int32BufferAttribute(f,1)),m.setIndex(Array.from(n));const g=this.propertyParser.getMaterialParameters(l);u.length===0&&(u=this.getVertexColorArray(i.length,g?.color)),m.setAttribute("color",new d.Float32BufferAttribute(u,3));const x=a.length>0;x&&m.setAttribute("barycentric",new d.BufferAttribute(a,1));const y=this.materialManager?.createBatchMaterial(l,g,x),T=new d.Mesh(m,y),v=new d.Mesh(m,this.materialManager?.pickMaterial);return{mesh:T,pickMesh:v,batchTable:c}}createInstancedMesh(e){const{position:i,uv:s,color:r,normal:n,indice:a,barycentric:o,matrices:l,userIds:c,materialId:u}=e,f=c.map(O=>Lr(this.tilesetId,O)),m=c.length,g=new d.BufferGeometry;g.setIndex(Array.from(a)),g.setAttribute("position",new d.Float32BufferAttribute(i,3)),g.setAttribute("uv",new d.Float32BufferAttribute(s,2)),g.setAttribute("normal",new d.Float32BufferAttribute(n,3)),g.setAttribute("tileObjectId",new d.InstancedBufferAttribute(new Int32Array(f),1));const x=o.length>0;x&&g.setAttribute("barycentric",new d.BufferAttribute(o,1));const y=this.propertyParser.getMaterialParameters(u),T=this.materialManager?.createInstanceMaterial(u,y,x),v=new d.InstancedMesh(g,T,m);v.instanceMatrix=new d.InstancedBufferAttribute(new Float32Array(l),16);let b=r;b.length===0&&(b=this.getVertexColorArray(m*3,y?.color)),v.instanceColor=new d.InstancedBufferAttribute(b,3);const E=new d.InstancedMesh(g,this.materialManager?.pickMaterial,m);return E.instanceMatrix=new d.InstancedBufferAttribute(new Float32Array(l),16),{mesh:v,pickMesh:E,userIds:c}}getGeometryByUserIds(e){const i=Date.now(),s=[];return this.visibleTiles.forEach(r=>{const n=r.cached.scene.children;for(let a=0;a<n.length;a++){const o=n[a];if(!o||o.sourceMesh)continue;const l=o.userData.userIds;if(l)for(let c=0;c<e.length;c++){const u=e[c],f=l.indexOf(u);if(f>-1){const m=new d.BufferGeometry,g=o.geometry.getAttribute("position"),x=o.geometry.index,y=o.geometry.getAttribute("tileObjectId");if(o instanceof d.InstancedMesh){const T=new d.Matrix4;o.getMatrixAt(f,T),m.setAttribute("position",g.clone());const v=y.array[f*y.itemSize];m.setAttribute("tileObjectId",new d.Int32BufferAttribute(new Array(g.array.length/3).fill(v),1)),x&&m.setIndex(x),m.applyMatrix4(T)}else{const{indexStart:T,indexCount:v,positionStart:b,positionCount:E}=o.userData.batchTable.find(P=>P.userId===u),O=g.itemSize,_=g.array.slice(b*O,b*O+E*O),C=new d.Float32BufferAttribute(_,O);m.setAttribute("position",C);const w=y.array.slice(b,b+E),M=new d.Int32BufferAttribute(w,1);if(m.setAttribute("tileObjectId",M),x){const P=x.array.slice(T,T+v);for(let A=0;A<P.length;A++)P[A]-=b;m.setIndex(new d.BufferAttribute(P,1))}}m.applyMatrix4(o.matrixWorld),s.push(m)}}}}),S.info("[BimTiles] getGeometryByUserIds took "+(Date.now()-i)/1e3+"s"),s.length>1?xe.mergeGeometries(s):s[0]}parseTile(e,i,s){this.onBeforeParseTile&&this.onBeforeParseTile(i),i._loadIndex=i._loadIndex||0,i._loadIndex++;const r=i.cached,n=r.transform;return new Ph().parse(e,this.baseUrl,this.protoRoot).then(({batchedMeshes:o,instancedMeshes:l})=>{S.debug("[BimTiles] batchedMeshes:",o),S.debug("[BimTiles] instancedMeshes:",l);const c=new d.Group;c.name="TileGroup";const u=new d.Group;u.name="TileGroup-pick",o.forEach(m=>{const{mesh:g,pickMesh:x,batchTable:y}=this.createBatchedMesh(m);c.add(g),g.userData.batchTable=y,g.userData.userIds=y.map(T=>T.userId),u.add(x)}),l.forEach(m=>{const{mesh:g,pickMesh:x,userIds:y}=this.createInstancedMesh(m);c.add(g),g.userData.userIds=y,u.add(x)});const f=m=>{m.applyMatrix4(n)};f(c),c.traverse(m=>{m[Dn]=m.frustumCulled}),Ih(c,!this.autoDisableRendererCulling),f(u),r.scene=c,r.pickScene=u,this.onLoadModel&&this.onLoadModel(c,i)})}disposeTile(e){const i=e.cached;if(i.scene){const s=r=>{r.traverse(n=>{n.geometry&&n.geometry.dispose()}),r.removeFromParent()};s(i.scene),i.pickScene&&s(i.pickScene),this.onDisposeModel&&this.onDisposeModel(i.scene,e),i.scene=null,i.pickScene=null,i.materials=null,i.textures=null,i.geometry=null}this.activeTiles.delete(e),this.visibleTiles.delete(e),e._loadIndex++}preprocessNode(e,i,s){super.preprocessNode(e,i,s),Array.isArray(e.boundingVolume)&&(ps.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(ps.getCenter(Pi),ps.getSize(Ai),e.cached.boundingVolume.setObbData([Pi.x,Pi.y,Pi.z,Ai.x/2,0,0,0,Ai.y/2,0,0,0,Ai.z/2],e.cached.transform)))}async fetchTileSet(e,i,s){return fetch(e,i).then(r=>{if(r.ok)return r.json();throw new Error('BimTilesRenderer: Failed to load tileset "'+e+'" with status '+r.status+" : "+r.statusText)}).then(async r=>{const{material:n,userData:a,userId:o,userIdBox:l}=r.properties,c=[];if(n.url){const f=this.propertyParser.getProperty(n.url,i,"PBMaterials").then(m=>this.propertyParser.parseMaterial(m));c.push(f)}if(a.url){const f=this.propertyParser.getProperty(a.url,i,"PBUserData").then(m=>this.propertyParser.parseUserData(m));c.push(f)}if(o.url){const f=this.propertyParser.getProperty(o.url,i,"PBUserId").then(m=>this.propertyParser.parseUserId(m));c.push(f)}if(l.url){const f=this.propertyParser.getProperty(l.url,i,"PBUserIdBox").then(m=>this.propertyParser.parseUserIdBox(m,this.group.matrix));c.push(f)}await Promise.all(c);let u=e.replace(/\/[^\\/]*\/?$/,"");return u=new URL(u,window.location.href).toString(),this.preprocessNode(r.root,u,s),this.onLoadTileSet&&Promise.resolve().then(()=>{this.onLoadTileSet(r)}),r})}loadRootTileSet(e){const i=this.tileSets;if(e in i)return i[e]instanceof Error?Promise.reject(i[e]):Promise.resolve(i[e]);{const s=this.fetchTileSet(this.preprocessURL?this.preprocessURL(e):e,this.fetchOptions).then(r=>{i[e]=r,this.materialManager=new Th(this,{maxId:r.properties.userId.maxUserIdIndex})});return s.catch(r=>{S.error("[BimTiles] loadRootTileSet error:",r),i[e]=r}),i[e]=s,s}}update(){super.update()}setTileVisible(e,i){const{scene:s,pickScene:r}=e.cached,n=this.visibleTiles,a=this.group;i?(n.add(e),a.add(s),this.pickUsage.add(r),s.updateMatrixWorld(!0),r.updateMatrixWorld(!0)):(n.delete(e),a.remove(s),this.pickUsage.remove(r)),this.onTileVisibilityChange&&this.onTileVisibilityChange(s,e,i)}calculateError(e){const i=e.cached,s=i.inFrustum,r=this.cameras,n=this.cameraInfo,a=i.boundingVolume;let o=-1/0,l=1/0;for(let c=0,u=r.length;c<u;c++){if(!s[c])continue;const f=n[c],m=f.invScale;let g;if(f.isOrthographic){const x=f.pixelSize;g=e.geometricError/(x*m)}else{const x=a.distanceToPoint(f.position),y=x*m,T=f.sseDenominator;g=e.geometricError/(y*T),l=Math.min(l,y)}o=Math.max(o,g)}e.__distanceFromCamera=l,e.__error=o}}class Vs extends Ji{constructor(e,i,s){super();p(this,"modelId");p(this,"_bbox");p(this,"tilesRenderer");p(this,"metadata");p(this,"statistics");this.modelId=e.modelId;const r=i+s.getMetadata().root;this.tilesRenderer=new Bn(r,Number(this.modelId)),this._bbox=e.bbox,this.metadata=s.getMetadata(),this.statistics=s.getStatistics()}getTilesRenderer(){return this.tilesRenderer}get materialManager(){return this.tilesRenderer.materialManager}get propertyParser(){return this.tilesRenderer.propertyParser}get highlighUsageGroup(){return this.tilesRenderer.highlighUsage}get transparentUsageGroup(){return this.tilesRenderer.transparentUsage}get pickUsageGroup(){return this.tilesRenderer.pickUsage}getModelObject(){return this.tilesRenderer.group}traverseObjectByUserId(e,i){if(i.userData.userIds){const r=i.userData.userIds;for(let n=0,a=r.length;n<a;n++)if(r[n]===e)return i}const s=i.children;for(let r=0,n=s.length;r<n;r++)if(this.traverseObjectByUserId(e,s[r]))return s[r]}getObjectByUserId(e){let i;return this.tilesRenderer.visibleTiles.forEach(s=>{i=this.traverseObjectByUserId(e,s.cached.scene)}),i}getBBox(){return this._bbox||(this._bbox=new d.Box3,this._bbox.setFromObject(this.getModelObject())),this._bbox}setObjectHoveredByUserId(e,i){this.materialManager.updateState(Mt.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(Mt.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(Mt.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(Mt.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(Mt.Transparent,e,!1)}setOpacity(e){this.materialManager.setOpacity(e)}clearOpacity(){this.materialManager.setOpacity(1)}setVisible(e){this.materialManager.setHidden(!e)}setObjectVisibleByUserIds(e,i){this.materialManager.updateState(Mt.Hidden,e,!i)}hasVisibleObject(){return this.materialManager.hasVisibleObject()}hasInvisibleObject(){return this.materialManager.hasInvisibleObject()}getHoveredObject(){return this.materialManager?.getHoveredObject()}getBBoxByUserId(e){return this.propertyParser.getUserIdBox(e)}getUserDataByUserId(e){return this.propertyParser.getUserData(e)}getUserIds(){return this.propertyParser.getUserIds()}getUserId(e,i){return this.propertyParser.getUserIdsByFamilyInstanceId(e,i)}getUserData(e,i){const s=this.getUserId(e,i);if(s.length>0)return this.getUserDataByUserId(s[0])}getUserIdByFilter(e){return this.propertyParser.getUserIdByFilter(e)}setClipPlanes(e){this.materialManager.setClipPlanes(e)}}function kh(){let h=new Map;return{on(t,e){const i=h.get(t);i?i.push(e):h.set(t,[e])},off(t,e){const i=h.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):h.set(t,[]))},emit(t,e){const i=h.get(t);i&&i.slice().map(s=>s(e)),h.get("*")&&h.get("*").slice().map(s=>s(t,e))}}}class Dh{constructor(t){p(this,"viewer");p(this,"element");p(this,"content");p(this,"itemList");p(this,"handleMouseWheel");this.viewer=t,this.itemList={},this.handleMouseWheel=e=>{e.preventDefault(),this.element&&(this.element.scrollLeft+=e.deltaY)},t.addEventListener(re.ModelLoad,()=>{this.init()})}init(){const t=document.createElement("div");t.classList.add("model-layout-switch-bar");const e=document.createElement("div");e.classList.add("model-layout-switch-bar-content"),e.addEventListener("wheel",this.handleMouseWheel),this.viewer.getLayoutNames().forEach((i,s)=>{const r=this.createItem(i,s);this.itemList[i]=r,r.resetActivate=()=>{for(const n in this.itemList)this.itemList[n].resetActive()},e?.appendChild(r.element)}),this.element=t,this.content=e,this.element.appendChild(this.content),this.viewer.widgetContainer?.appendChild(this.element)}createItem(t,e){const i=new Bh(this.viewer,t);return e===0&&i.setActive(!0),i}destroy(){for(const t in this.itemList){const e=this.itemList[t];e.destroy(),this.content?.removeChild(e.element)}this.itemList={},this.element&&this.content&&(this.element.removeChild(this.content),this.element.removeEventListener("wheel",this.handleMouseWheel),this.viewer.widgetContainer?.removeChild(this.element),this.element=void 0)}show(){this.element&&(this.element.style.display="block")}hide(){this.element&&(this.element.style.display="none")}}class Bh{constructor(t,e){p(this,"viewer");p(this,"eventBus");p(this,"element");p(this,"resetActivate");p(this,"active");this.viewer=t,this.eventBus=kh(),this.active=!1,this.element=this.createItem(e),this.eventBus.on("activechange",i=>{this.resetActivate&&this.resetActivate(),i?(this.element.classList.add("activate"),this.viewer.activateLayout(e)):this.element.classList.remove("activate")})}createItem(t){const e=document.createElement("div"),i=document.createElement("span");return e.classList.add("model-layout-switch-item"),e.onclick=()=>{this.active=!this.active,this.eventBus.emit("activechange",this.active)},i.innerText=t,e.appendChild(i),e}setActive(t){this.active!==t&&(this.active=t,this.eventBus.emit("activechange",t))}resetActive(){this.active=!1,this.element.classList.remove("activate")}destroy(){this.eventBus.off("activechange")}}class Ln{constructor(t){p(this,"element");p(this,"jobCount");this.jobCount=0;const e=document.createElement("div");e.classList.add("x-spinner");for(let s=0;s<4;s++)e.appendChild(document.createElement("span"));const i=t?.widgetContainer;i&&i.appendChild(e),this.element=e,this.setSpinnerVisibility(this.jobCount>0)}setSpinnerVisibility(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){if(this.jobCount<=0){console.warn("[Viewer] jobCount should be at least 1 here!");return}this.setSpinnerVisibility(--this.jobCount>0)}destroy(){this.element.remove(),this.jobCount=0}}class Us{constructor(t){p(this,"width");p(this,"height");p(this,"container");p(this,"viewerContainer");p(this,"widgetContainer");this.width=0,this.height=0;let e=document.getElementById(t);e||(S.warn("[Container] containerId:",t,"is not found in dom tree! will append to document body"),e=document.body);const i=document.createElement("div");i.classList.add("x-container"),i.style.cssText="width: 100%; height: 100%; position: relative;",e.appendChild(i),this.container=i,this.width=e.clientWidth,this.height=e.clientHeight,this.initViewerContainer(),this.initWidgetContainer()}initViewerContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-viewer-container"),e.style.cssText="width: 100%; height: 100%; display: inline-block; position: relative; overflow: hidden;",t.appendChild(e),this.viewerContainer=e}initWidgetContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-widget-container"),t.appendChild(e),this.widgetContainer=e}get needResize(){const t=this.width!==this.container.clientWidth||this.height!==this.container.clientHeight;return t&&(this.width=this.container.clientWidth,this.height=this.container.clientHeight),t}destroy(){this.widgetContainer&&(this.widgetContainer.remove(),this.widgetContainer=void 0),this.viewerContainer&&(this.viewerContainer.remove(),this.viewerContainer=void 0),this.container.remove()}}class Hs{constructor(t){p(this,"element");p(this,"progressItems");p(this,"replaceReg");this.progressItems=new Map,this.replaceReg=new RegExp(/<em>[\s\S]*<\/em>/,"g");const e=document.createElement("div");e.classList.add("progress-bar"),t?.widgetContainer?.appendChild(e),this.element=e}addProgressItem(t,e="ProgressBar.Loading",i){this.progressItems.get(t)&&S.error("[Viewer] ProgressItem with id "+t+" already exists!");const s=document.createElement("div");s.classList.add("progress-bar-item"),s.innerHTML=Re.t(e)+": <em></em>",this.element.append(s),this.progressItems.set(t,{div:s,onProgress:i})}removeProgressItem(t){this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t),this.progressItems.size===0&&this.setVisible(!1)}updateProgress(t,e,i){const s=this.progressItems.get(t);if(!s)return;let r=e?""+e:"";e&&i!=null&&(r+=": "),i!=null&&(i<0||i>100?(console.warn("[ProgressBar] Invalid progress value: "+i),r+="--%"):r+=i.toFixed(2)+"%"),s.div.innerHTML=r}updateProgressBar(t,e,i=0,s=100){const r=this.progressItems.get(t);if(!r)return;const n=e instanceof ProgressEvent?e.loaded:e,a=e instanceof ProgressEvent?e.total:100,o=n*100/a*(s-i)/100+i;r.div.innerHTML=r.div.innerHTML.replace(this.replaceReg,"<em>"+(o<0||o>100?"--":o.toFixed(2))+"%</em>"),r.onProgress?.call(r,new ProgressEvent("LoadProgress",{loaded:n,total:100}))}setVisible(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}delayRemoveProgressItem(t,e=3e3){setTimeout(()=>{this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t)},e)}destroy(){this.progressItems.forEach(t=>{t.div.remove()}),this.progressItems.clear(),this.element.remove()}}var Be=(h=>(h.BaseViewer="BaseViewer",h.Viewer3d="Viewer3d",h.Viewer2d="Viewer2d",h.BimTilesViewer="BimTilesViewer",h))(Be||{}),$e=(h=>(h.Perspective="Perspective",h.Orthographic="Orthographic",h))($e||{});const Lh={enableSpinner:!0,containerId:"myCanvas"},G={LEFT:1,RIGHT:2,MIDDLE:4},D=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768});function Ve(h){return h.isPerspectiveCamera}function Oe(h){return h.isOrthographicCamera}class Rh{constructor(){p(this,"_listeners");this._listeners={}}addEventListener(t,e){const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners[t];if(s!==void 0){const r=s.indexOf(e);r!==-1&&s.splice(r,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const i=this._listeners[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let r=0,n=s.length;r<n;r++)s[r].call(this,t)}}}const At=Math.PI*2,Fr=Math.PI/2;function ms(h,t){t.set(0,0),h.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=h.length,t.y/=h.length}function gs(h,t){return Oe(h)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const Rn=1e-5,ei=Math.PI/180;function Ft(h,t,e){return Math.max(t,Math.min(e,h))}function ie(h,t=Rn){return Math.abs(h)<t}function te(h,t,e=Rn){return ie(h-t,e)}function zr(h,t){return Math.round(h/t)*t}function ti(h){return isFinite(h)?h:h<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ii(h){return Math.abs(h)<Number.MAX_VALUE?h:h*(1/0)}function Ii(h,t,e,i,s=1/0,r){i=Math.max(1e-4,i);const n=2/i,a=n*r,o=1/(1+a+.48*a*a+.235*a*a*a);let l=h-t;const c=t,u=s*i;l=Ft(l,-u,u),t=h-l;const f=(e.value+n*l)*r;e.value=(e.value-n*f)*o;let m=t+(l+f)*o;return c-h>0==m>c&&(m=c,e.value=(m-c)/r),m}function jr(h,t,e,i,s=1/0,r,n){i=Math.max(1e-4,i);const a=2/i,o=a*r,l=1/(1+o+.48*o*o+.235*o*o*o);let c=t.x,u=t.y,f=t.z,m=h.x-c,g=h.y-u,x=h.z-f;const y=c,T=u,v=f,b=s*i,E=b*b,O=m*m+g*g+x*x;if(O>E){const L=Math.sqrt(O);m=m/L*b,g=g/L*b,x=x/L*b}c=h.x-m,u=h.y-g,f=h.z-x;const _=(e.x+a*m)*r,C=(e.y+a*g)*r,w=(e.z+a*x)*r;e.x=(e.x-a*_)*l,e.y=(e.y-a*C)*l,e.z=(e.z-a*w)*l,n.x=c+(m+_)*l,n.y=u+(g+C)*l,n.z=f+(x+w)*l;const M=y-h.x,P=T-h.y,A=v-h.z,I=n.x-y,k=n.y-T,B=n.z-v;return M*I+P*k+A*B>0&&(n.x=y,n.y=T,n.z=v,e.x=(n.x-y)/r,e.y=(n.y-T)/r,e.z=(n.z-v)/r),n}const ki=1/8,Fh=be.isBrowser&&/Mac/.test(navigator.platform),zh=!(be.isBrowser&&"PointerEvent"in window);let N,Vr,Di,ys,Me,W,ee,It,Ye,Xe,bt,Ur,Hr,je,si,kt,Nr,xs,Gr,bs,vs,Bi;class K extends Rh{constructor(e,i){super();p(this,"minPolarAngle");p(this,"maxPolarAngle");p(this,"minAzimuthAngle");p(this,"maxAzimuthAngle");p(this,"minDistance");p(this,"maxDistance");p(this,"infinityDolly");p(this,"minZoom");p(this,"maxZoom");p(this,"smoothTime");p(this,"draggingSmoothTime");p(this,"maxSpeed");p(this,"azimuthRotateSpeed");p(this,"polarRotateSpeed");p(this,"dollySpeed");p(this,"truckSpeed");p(this,"dollyToCursor");p(this,"dragToOffset");p(this,"verticalDragToForward");p(this,"boundaryFriction");p(this,"restThreshold");p(this,"colliderMeshes");p(this,"mouseButtons");p(this,"touches");p(this,"cancel");p(this,"_enabled");p(this,"_camera");p(this,"_yAxisUpSpace");p(this,"_yAxisUpSpaceInverse");p(this,"_state");p(this,"_domElement");p(this,"_viewport");p(this,"_target");p(this,"_targetEnd");p(this,"_focalOffset");p(this,"_focalOffsetEnd");p(this,"_spherical");p(this,"_sphericalEnd");p(this,"_zoom");p(this,"_zoomEnd");p(this,"_target0");p(this,"_position0");p(this,"_zoom0");p(this,"_focalOffset0");p(this,"_dollyControlAmount");p(this,"_dollyControlCoord");p(this,"_nearPlaneCorners");p(this,"_hasRested");p(this,"_boundary");p(this,"_boundaryEnclosesCamera");p(this,"_needsUpdate");p(this,"_updatedLastTime");p(this,"_elementRect");p(this,"_activePointers");p(this,"_isUserControllingRotate");p(this,"_isUserControllingDolly");p(this,"_isUserControllingTruck");p(this,"_isUserControllingOffset");p(this,"_isUserControllingZoom");p(this,"_thetaVelocity");p(this,"_phiVelocity");p(this,"_radiusVelocity");p(this,"_targetVelocity");p(this,"_focalOffsetVelocity");p(this,"_zoomVelocity");p(this,"_truckInternal");p(this,"_rotateInternal");p(this,"_dollyInternal");p(this,"_zoomInternal");this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=0,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=D.NONE,this._viewport=null,this._dollyControlAmount=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=be.isBrowser?new DOMRect:{x:0,y:0,width:0,height:0,left:0,right:0,top:0,bottom:0},this._activePointers=[],this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new N.Vector3,this._focalOffsetVelocity=new N.Vector3,this._zoomVelocity={value:0},this._truckInternal=(b,E,O)=>{if(Ve(this._camera)){const _=W.copy(this._camera.position).sub(this._target),C=this._camera.getEffectiveFOV()*ei,w=_.length()*Math.tan(C*.5),M=this.truckSpeed*b*w/this._elementRect.height,P=this.truckSpeed*E*w/this._elementRect.height;this.verticalDragToForward?(O?this.setFocalOffset(this._focalOffsetEnd.x+M,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(M,0,!0),this.forward(-P,!0)):O?this.setFocalOffset(this._focalOffsetEnd.x+M,this._focalOffsetEnd.y+P,this._focalOffsetEnd.z,!0):this.truck(M,P,!0)}else if(Oe(this._camera)){const _=this._camera,C=this.truckSpeed*b*(_.right-_.left)/_.zoom/this._elementRect.width,w=this.truckSpeed*E*(_.top-_.bottom)/_.zoom/this._elementRect.height;O?this.setFocalOffset(this._focalOffsetEnd.x+C,this._focalOffsetEnd.y+w,this._focalOffsetEnd.z,!0):this.truck(C,w,!0)}},this._rotateInternal=(b,E)=>{const O=At*this.azimuthRotateSpeed*b/this._elementRect.height,_=At*this.polarRotateSpeed*E/this._elementRect.height;this.rotate(O,_,!0)},this._dollyInternal=(b,E,O)=>{const _=Math.pow(.95,-b*this.dollySpeed),C=this._sphericalEnd.radius*_,w=this._sphericalEnd.radius,M=w*(b>=0?-1:1);this.dollyTo(C),this.infinityDolly&&(C<this.minDistance||this.maxDistance===this.minDistance)&&(this._camera.getWorldDirection(W),this._targetEnd.add(W.normalize().multiplyScalar(M)),this._target.add(W.normalize().multiplyScalar(M))),this.dollyToCursor&&(this._dollyControlAmount+=this._sphericalEnd.radius-w,this.infinityDolly&&(C<this.minDistance||this.maxDistance===this.minDistance)&&(this._dollyControlAmount-=M),this._dollyControlCoord.set(E,O))},this._zoomInternal=(b,E,O)=>{const _=Math.pow(.95,b*this.dollySpeed),C=this._zoomEnd;this.zoomTo(this._zoom*_),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-C,this._dollyControlCoord.set(E,O))},typeof N>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=e,this._yAxisUpSpace=new N.Quaternion().setFromUnitVectors(this._camera.up,Di),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=D.NONE,this._target=new N.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new N.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new N.Spherical().setFromVector3(W.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._nearPlaneCorners=[new N.Vector3,new N.Vector3,new N.Vector3,new N.Vector3],this._updateNearPlaneCorners(),this._boundary=new N.Box3(new N.Vector3(-1/0,-1/0,-1/0),new N.Vector3(1/0,1/0,1/0)),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlAmount=0,this._dollyControlCoord=new N.Vector2,this.mouseButtons={left:D.ROTATE,middle:D.DOLLY,right:D.TRUCK,wheel:Ve(this._camera)?D.DOLLY:Oe(this._camera)?D.ZOOM:D.NONE},this.touches={one:D.TOUCH_ROTATE,two:Ve(this._camera)?D.TOUCH_DOLLY_TRUCK:Oe(this._camera)?D.TOUCH_ZOOM_TRUCK:D.NONE,three:D.TOUCH_TRUCK};const s=new N.Vector2,r=new N.Vector2,n=new N.Vector2,a=b=>{if(!this._enabled||!this._domElement)return;const E=b.pointerType!=="mouse"?null:(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.MIDDLE?G.MIDDLE:(b.buttons&G.RIGHT)===G.RIGHT?G.RIGHT:null;if(E!==null){const _=this._findPointerByMouseButton(E);_&&this._activePointers.splice(this._activePointers.indexOf(_),1)}const O={pointerId:b.pointerId,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:E};this._activePointers.push(O),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",u),this._domElement.addEventListener("pointermove",l),this._domElement.addEventListener("pointerup",u),y(b)},o=b=>{if(!this._enabled||!this._domElement)return;const E=(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.MIDDLE?G.MIDDLE:(b.buttons&G.RIGHT)===G.RIGHT?G.RIGHT:null;if(E!==null){const _=this._findPointerByMouseButton(E);_&&this._activePointers.splice(this._activePointers.indexOf(_),1)}const O={pointerId:0,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.LEFT?G.MIDDLE:(b.buttons&G.RIGHT)===G.LEFT?G.RIGHT:null};this._activePointers.push(O),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("mouseup",f),this._domElement.addEventListener("mousemove",c),this._domElement.addEventListener("mouseup",f),y(b)},l=b=>{const E=b.pointerId,O=this._findPointerById(E);if(O){if(O.clientX=b.clientX,O.clientY=b.clientY,O.deltaX=b.movementX,O.deltaY=b.movementY,b.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right);T()}},c=b=>{const E=this._findPointerById(0);E&&(E.clientX=b.clientX,E.clientY=b.clientY,E.deltaX=b.movementX,E.deltaY=b.movementY,this._state=0,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right),T())},u=b=>{const E=b.pointerId,O=this._findPointerById(E);if(O&&this._activePointers.splice(this._activePointers.indexOf(O),1),b.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=D.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=D.NONE;v()},f=()=>{const b=this._findPointerById(0);b&&this._activePointers.splice(this._activePointers.indexOf(b),1),this._state=D.NONE,v()};let m=-1;const g=b=>{if(!this._enabled||this.mouseButtons.wheel===D.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===D.ROTATE||this.mouseButtons.wheel===D.TRUCK){const w=performance.now();m-w<1e3&&this._getClientRect(this._elementRect),m=w}const E=Fh?-1:-3,O=b.deltaMode===1?b.deltaY/E:b.deltaY/(E*10),_=this.dollyToCursor?(b.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,C=this.dollyToCursor?(b.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case D.ROTATE:{this._rotateInternal(b.deltaX,b.deltaY),this._isUserControllingRotate=!0;break}case D.TRUCK:{this._truckInternal(b.deltaX,b.deltaY,!1),this._isUserControllingTruck=!0;break}case D.OFFSET:{this._truckInternal(b.deltaX,b.deltaY,!0),this._isUserControllingOffset=!0;break}case D.DOLLY:{this._dollyInternal(-O,_,C),this._isUserControllingDolly=!0;break}case D.ZOOM:{this._zoomInternal(-O,_,C),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},x=b=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===K.ACTION.NONE){const E=b instanceof PointerEvent?b.pointerId:(b instanceof MouseEvent,0),O=this._findPointerById(E);O&&this._activePointers.splice(this._activePointers.indexOf(O),1),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("mouseup",f);return}},y=b=>{if(!this._enabled)return;if(ms(this._activePointers,Me),this._getClientRect(this._elementRect),s.copy(Me),r.copy(Me),this._activePointers.length>=2){const O=Me.x-this._activePointers[1].clientX,_=Me.y-this._activePointers[1].clientY,C=Math.sqrt(O*O+_*_);n.set(0,C);const w=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,M=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;r.set(w,M)}if("pointerType"in b&&b.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&D.ROTATE)===D.ROTATE||(this._state&D.TOUCH_ROTATE)===D.TOUCH_ROTATE||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&D.TRUCK)===D.TRUCK||(this._state&D.TOUCH_TRUCK)===D.TOUCH_TRUCK||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&D.DOLLY)===D.DOLLY||(this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&D.ZOOM)===D.ZOOM||(this._state&D.TOUCH_ZOOM)===D.TOUCH_ZOOM||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&D.OFFSET)===D.OFFSET||(this._state&D.TOUCH_OFFSET)===D.TOUCH_OFFSET||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},T=()=>{if(!this._enabled)return;ms(this._activePointers,Me);const b=be.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,E=b?-this._activePointers[0].deltaX:r.x-Me.x,O=b?-this._activePointers[0].deltaY:r.y-Me.y;if(r.copy(Me),((this._state&D.ROTATE)===D.ROTATE||(this._state&D.TOUCH_ROTATE)===D.TOUCH_ROTATE||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(E,O),this._isUserControllingRotate=!0),(this._state&D.DOLLY)===D.DOLLY||(this._state&D.ZOOM)===D.ZOOM){const _=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,C=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&D.DOLLY)===D.DOLLY?(this._dollyInternal(O*ki,_,C),this._isUserControllingDolly=!0):(this._zoomInternal(O*ki,_,C),this._isUserControllingZoom=!0)}if((this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_ZOOM)===D.TOUCH_ZOOM||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE){const _=Me.x-this._activePointers[1].clientX,C=Me.y-this._activePointers[1].clientY,w=Math.sqrt(_*_+C*C),M=n.y-w;n.set(0,w);const P=this.dollyToCursor?(r.x-this._elementRect.x)/this._elementRect.width*2-1:0,A=this.dollyToCursor?(r.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET?(this._dollyInternal(M*ki,P,A),this._isUserControllingDolly=!0):(this._zoomInternal(M*ki,P,A),this._isUserControllingZoom=!0)}((this._state&D.TRUCK)===D.TRUCK||(this._state&D.TOUCH_TRUCK)===D.TOUCH_TRUCK||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(E,O,!1),this._isUserControllingTruck=!0),((this._state&D.OFFSET)===D.OFFSET||(this._state&D.TOUCH_OFFSET)===D.TOUCH_OFFSET||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(E,O,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},v=()=>{ms(this._activePointers,Me),r.copy(Me),this._activePointers.length===0&&this._domElement&&(this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mouseup",f),this.dispatchEvent({type:"controlend"}))};this._addAllEventListeners=b=>{this._domElement=b,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),zh&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",u),this._domElement.addEventListener("wheel",g,{passive:!1}),this._domElement.addEventListener("contextmenu",x)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",a),this._domElement.removeEventListener("mousedown",o),this._domElement.removeEventListener("pointercancel",u),this._domElement.removeEventListener("wheel",g),this._domElement.removeEventListener("contextmenu",x),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mouseup",f))},this.cancel=()=>{this._state!==D.NONE&&(this._state=D.NONE,this._activePointers.length=0,v())},i&&this.connect(i),this.update(0)}static install(e){N=e.THREE,Vr=Object.freeze(new N.Vector3(0,0,0)),Di=Object.freeze(new N.Vector3(0,1,0)),ys=Object.freeze(new N.Vector3(0,0,1)),Me=new N.Vector2,W=new N.Vector3,ee=new N.Vector3,It=new N.Vector3,Ye=new N.Vector3,Xe=new N.Vector3,bt=new N.Vector3,Ur=new N.Vector3,Hr=new N.Vector3,je=new N.Spherical,si=new N.Spherical,kt=new N.Box3,Nr=new N.Box3,xs=new N.Sphere,Gr=new N.Quaternion,bs=new N.Quaternion,vs=new N.Matrix4,Bi=new N.Raycaster}static get ACTION(){return D}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}addEventListener(e,i){super.addEventListener(e,i)}removeEventListener(e,i){super.removeEventListener(e,i)}rotate(e,i,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+i,s)}rotateAzimuthTo(e,i=!1){return this.rotateTo(e,this._sphericalEnd.phi,i)}rotatePolarTo(e,i=!1){return this.rotateTo(this._sphericalEnd.theta,e,i)}rotateTo(e,i,s=!1){this._isUserControllingRotate=!1;const r=Ft(e,this.minAzimuthAngle,this.maxAzimuthAngle),n=Ft(i,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=r,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,i=!1){return this.dollyTo(this._sphericalEnd.radius-e,i)}dollyTo(e,i=!1){this._isUserControllingDolly=!1;const s=this._sphericalEnd.radius,r=Ft(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=te(o,this._spherical.radius);if(!(s>r)&&l)return Promise.resolve();this._sphericalEnd.radius=Math.min(r,o)}else this._sphericalEnd.radius=r;this._needsUpdate=!0,i||(this._spherical.radius=this._sphericalEnd.radius);const a=!i||te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(a)}zoom(e,i=!1){return this.zoomTo(this._zoomEnd+e,i)}zoomTo(e,i=!1){this._isUserControllingZoom=!1,this._zoomEnd=Ft(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||te(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),Ye.setFromMatrixColumn(this._camera.matrix,0),Xe.setFromMatrixColumn(this._camera.matrix,1),Ye.multiplyScalar(e),Xe.multiplyScalar(-i);const r=W.copy(Ye).add(Xe),n=ee.copy(this._targetEnd).add(r);return this.moveTo(n.x,n.y,n.z,s)}forward(e,i=!1){W.setFromMatrixColumn(this._camera.matrix,0),W.crossVectors(this._camera.up,W),W.multiplyScalar(e);const s=ee.copy(this._targetEnd).add(W);return this.moveTo(s.x,s.y,s.z,i)}elevate(e,i=!1){return W.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+W.x,this._targetEnd.y+W.y,this._targetEnd.z+W.z,i)}moveTo(e,i,s,r=!1){this._isUserControllingTruck=!1;const n=W.set(e,i,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,r||this._target.copy(this._targetEnd);const a=!r||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,i,s,r=!1){const o=W.set(e,i,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,r)}fitToBox(e,i,{cover:s=!1,paddingLeft:r=0,paddingRight:n=0,paddingBottom:a=0,paddingTop:o=0}={}){const l=[],c=e.isBox3?kt.copy(e):kt.setFromObject(e);c.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const u=zr(this._sphericalEnd.theta,Fr),f=zr(this._sphericalEnd.phi,Fr);l.push(this.rotateTo(u,f,i));const m=W.setFromSpherical(this._sphericalEnd).normalize(),g=Gr.setFromUnitVectors(m,ys),x=te(Math.abs(m.y),1);x&&g.multiply(bs.setFromAxisAngle(Di,u)),g.multiply(this._yAxisUpSpaceInverse);const y=Nr.makeEmpty();ee.copy(c.min).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setX(c.max.x).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setY(c.max.y).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setZ(c.min.z).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setZ(c.max.z).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setY(c.min.y).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setX(c.min.x).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).applyQuaternion(g),y.expandByPoint(ee),y.min.x-=r,y.min.y-=a,y.max.x+=n,y.max.y+=o,g.setFromUnitVectors(ys,m),x&&g.premultiply(bs.invert()),g.premultiply(this._yAxisUpSpace);const T=y.getSize(W),v=y.getCenter(ee).applyQuaternion(g);if(Ve(this._camera)){const b=this.getDistanceToFitBox(T.x,T.y,T.z,s);l.push(this.moveTo(v.x,v.y,v.z,i)),l.push(this.dollyTo(b,i)),l.push(this.setFocalOffset(0,0,0,i))}else if(Oe(this._camera)){const b=this._camera,E=b.right-b.left,O=b.top-b.bottom,_=s?Math.max(E/T.x,O/T.y):Math.min(E/T.x,O/T.y);l.push(this.moveTo(v.x,v.y,v.z,i)),l.push(this.zoomTo(_,i)),l.push(this.setFocalOffset(0,0,0,i))}return Promise.all(l)}fitToSphere(e,i){const s=[],n=e instanceof N.Sphere?xs.copy(e):K.createBoundingSphere(e,xs);if(s.push(this.moveTo(n.center.x,n.center.y,n.center.z,i)),Ve(this._camera)){const a=this.getDistanceToFitSphere(n.radius);s.push(this.dollyTo(a,i))}else if(Oe(this._camera)){const a=this._camera,o=a.right-a.left,l=a.top-a.bottom,c=2*n.radius,u=Math.min(o/c,l/c);s.push(this.zoomTo(u,i))}return s.push(this.setFocalOffset(0,0,0,i)),Promise.all(s)}setLookAt(e,i,s,r,n,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const l=ee.set(r,n,a),c=W.set(e,i,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(c.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const u=!o||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold)&&te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(u)}lerpLookAt(e,i,s,r,n,a,o,l,c,u,f,m,g,x=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const y=W.set(r,n,a),T=ee.set(e,i,s);je.setFromVector3(T.sub(y).applyQuaternion(this._yAxisUpSpace));const v=It.set(u,f,m),b=ee.set(o,l,c);si.setFromVector3(b.sub(v).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(y.lerp(v,g));const E=si.theta-je.theta,O=si.phi-je.phi,_=si.radius-je.radius;this._sphericalEnd.set(je.radius+_*g,je.phi+O*g,je.theta+E*g),this.normalizeRotations(),this._needsUpdate=!0,x||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const C=!x||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold)&&te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(C)}setPosition(e,i,s,r=!1){return this.setLookAt(e,i,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,r)}setTarget(e,i,s,r=!1){const n=this.getPosition(W),a=this.setLookAt(n.x,n.y,n.z,e,i,s,r);return this._sphericalEnd.phi=Ft(this.polarAngle,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,i,s,r=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,i,s),this._needsUpdate=!0,r||this._focalOffset.copy(this._focalOffsetEnd);const n=!r||te(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&te(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&te(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),Ye.setFromMatrixColumn(this._camera.matrixWorldInverse,0),Xe.setFromMatrixColumn(this._camera.matrixWorldInverse,1),bt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const r=W.set(e,i,s),n=r.distanceTo(this._camera.position),a=r.sub(this._camera.position);Ye.multiplyScalar(a.x),Xe.multiplyScalar(a.y),bt.multiplyScalar(a.z),W.copy(Ye).add(Xe).add(bt),W.z=W.z+n,this.dollyTo(n,!1),this.setFocalOffset(-W.x,W.y,-W.z,!1),this.moveTo(e,i,s,!1)}setBoundary(e){if(!e){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,i,s,r){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new N.Vector4,typeof e=="number"?this._viewport.set(e,i,s,r):this._viewport.copy(e)}getDistanceToFitBox(e,i,s,r=!1){if(gs(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=e/i,a=this._camera.getEffectiveFOV()*ei,o=this._camera.aspect;return((r?n>o:n<o)?i:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if(gs(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const i=this._camera.getEffectiveFOV()*ei,s=Math.atan(Math.tan(i*.5)*this._camera.aspect)*2,r=1<this._camera.aspect?i:s;return e/Math.sin(r*.5)}getTarget(e){return(e&&e.isVector3?e:new N.Vector3).copy(this._targetEnd)}getPosition(e){return(e&&e.isVector3?e:new N.Vector3).setFromSpherical(this._sphericalEnd).applyQuaternion(this._yAxisUpSpaceInverse).add(this._targetEnd)}getFocalOffset(e){return(e&&e.isVector3?e:new N.Vector3).copy(this._focalOffsetEnd)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%At,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=At),this._spherical.theta+=At*Math.round((this._sphericalEnd.theta-this._spherical.theta)/At)}reset(e=!1){const i=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,e),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,e),this.zoomTo(this._zoom0,e)];return Promise.all(i)}saveState(){this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Di),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert}update(e){const i=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,r=this._sphericalEnd.radius-this._spherical.radius,n=Ur.subVectors(this._targetEnd,this._target),a=Hr.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ie(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const f=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Ii(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,f,1/0,e),this._needsUpdate=!0}if(ie(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const f=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Ii(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,f,1/0,e),this._needsUpdate=!0}if(ie(r))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const f=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Ii(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,f,this.maxSpeed,e),this._needsUpdate=!0}if(ie(n.x)&&ie(n.y)&&ie(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const f=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;jr(this._target,this._targetEnd,this._targetVelocity,f,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(ie(a.x)&&ie(a.y)&&ie(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const f=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;jr(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,f,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(Ve(this._camera)){const f=this._camera,m=W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),g=ee.copy(m).cross(f.up).normalize();g.lengthSq()===0&&(g.x=1);const x=It.crossVectors(g,m),y=this._sphericalEnd.radius*Math.tan(f.getEffectiveFOV()*ei*.5),v=(this._sphericalEnd.radius-this._dollyControlAmount-this._sphericalEnd.radius)/this._sphericalEnd.radius,b=W.copy(this._targetEnd).add(g.multiplyScalar(this._dollyControlCoord.x*y*f.aspect)).add(x.multiplyScalar(this._dollyControlCoord.y*y));this._targetEnd.lerp(b,v)}else if(Oe(this._camera)){const f=this._camera,m=W.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(f.near+f.far)/(f.near-f.far)).unproject(f),g=ee.set(0,0,-1).applyQuaternion(f.quaternion),x=It.copy(m).add(g.multiplyScalar(-m.dot(f.up))),T=-(this._zoom-this._dollyControlAmount-this._zoomEnd)/this._zoom,v=W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),b=this._targetEnd.dot(v);this._targetEnd.lerp(x,T);const E=this._targetEnd.dot(v),O=v.multiplyScalar(E-b);this._targetEnd.sub(O)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(ie(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const f=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Ii(this._zoom,this._zoomEnd,this._zoomVelocity,f,1/0,e)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0);const l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!ie(this._focalOffset.x)||!ie(this._focalOffset.y)||!ie(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),Ye.setFromMatrixColumn(this._camera.matrix,0),Xe.setFromMatrixColumn(this._camera.matrix,1),bt.setFromMatrixColumn(this._camera.matrix,2),Ye.multiplyScalar(this._focalOffset.x),Xe.multiplyScalar(-this._focalOffset.y),bt.multiplyScalar(this._focalOffset.z),W.copy(Ye).add(Xe).add(bt),this._camera.position.add(W)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const u=this._needsUpdate;return u&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):u?(this.dispatchEvent({type:"update"}),ie(i,this.restThreshold)&&ie(s,this.restThreshold)&&ie(r,this.restThreshold)&&ie(n.x,this.restThreshold)&&ie(n.y,this.restThreshold)&&ie(n.z,this.restThreshold)&&ie(a.x,this.restThreshold)&&ie(a.y,this.restThreshold)&&ie(a.z,this.restThreshold)&&ie(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!u&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._updatedLastTime=u,this._needsUpdate=!1,u}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:ti(this.maxDistance),minZoom:this.minZoom,maxZoom:ti(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:ti(this.maxPolarAngle),minAzimuthAngle:ti(this.minAzimuthAngle),maxAzimuthAngle:ti(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:W.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(e,i=!1){const s=JSON.parse(e),r=W.fromArray(s.position);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=ii(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=ii(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=ii(s.maxPolarAngle),this.minAzimuthAngle=ii(s.minAzimuthAngle),this.maxAzimuthAngle=ii(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],i),je.setFromVector3(r.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(je.theta,je.phi,i),this.zoomTo(s.zoom,i),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],i),this._needsUpdate=!0}connect(e){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(e)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_findPointerById(e){return this._activePointers.find(i=>i.pointerId===e)}_findPointerByMouseButton(e){return this._activePointers.find(i=>i.mouseButton===e)}_encloseToBoundary(e,i,s){const r=i.lengthSq();if(r===0)return e;const n=ee.copy(i).add(e),o=this._boundary.clampPoint(n,It).sub(n),l=o.lengthSq();if(l===0)return e.add(i);if(l===r)return e;if(s===0)return e.add(i).add(o);{const c=1+s*l/i.dot(o);return e.add(ee.copy(i).multiplyScalar(c)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(Ve(this._camera)){const e=this._camera,i=e.near,s=e.getEffectiveFOV()*ei,r=Math.tan(s*.5)*i,n=r*e.aspect;this._nearPlaneCorners[0].set(-n,-r,0),this._nearPlaneCorners[1].set(n,-r,0),this._nearPlaneCorners[2].set(n,r,0),this._nearPlaneCorners[3].set(-n,r,0)}else if(Oe(this._camera)){const e=this._camera,i=1/e.zoom,s=e.left*i,r=e.right*i,n=e.top*i,a=e.bottom*i;this._nearPlaneCorners[0].set(s,n,0),this._nearPlaneCorners[1].set(r,n,0),this._nearPlaneCorners[2].set(r,a,0),this._nearPlaneCorners[3].set(s,a,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||gs(this._camera,"_collisionTest"))return e;const s=W.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);vs.lookAt(Vr,s,this._camera.up);for(let r=0;r<4;r++){const n=ee.copy(this._nearPlaneCorners[r]);n.applyMatrix4(vs);const a=It.addVectors(this._target,n);Bi.set(a,s),Bi.far=this._spherical.radius+1;const o=Bi.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance<e&&(e=o[0].distance)}return e}_getClientRect(e){if(!this._domElement)return;const i=this._domElement.getBoundingClientRect();return e.x=i.left,e.y=i.top,this._viewport?(e.x+=this._viewport.x,e.y+=i.height-this._viewport.w-this._viewport.y,e.width=this._viewport.z,e.height=this._viewport.w):(e.width=i.width,e.height=i.height),e}_createOnRestPromise(e){return e?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(i=>{const s=()=>{this.removeEventListener("rest",s),i()};this.addEventListener("rest",s)}))}_addAllEventListeners(e){}_removeAllEventListeners(){}static createBoundingSphere(e,i=new N.Sphere){const s=i,r=s.center;kt.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&kt.expandByObject(a)}),kt.getCenter(r);let n=0;return e.traverseVisible(a=>{if(!a.isMesh)return;const o=a,l=o.geometry.clone();if(l.applyMatrix4(o.matrixWorld),l.isBufferGeometry){const u=l.attributes.position;for(let f=0,m=u.count;f<m;f++)W.fromBufferAttribute(u,f),n=Math.max(n,r.distanceToSquared(W))}else{const u=l.attributes.position;for(let f=0,m=u.count;f<m;f++)W.fromBufferAttribute(u,f),n=Math.max(n,r.distanceToSquared(W))}}),s.radius=Math.sqrt(n),s}}var He=(h=>(h[h.Orbit=0]="Orbit",h[h.FirstPerson=1]="FirstPerson",h[h.Plan=2]="Plan",h))(He||{});class Fn{constructor(t){p(this,"mode");p(this,"cameraManager");this.mode=He.Orbit,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:K.ACTION.ROTATE,middle:K.ACTION.DOLLY,right:K.ACTION.TRUCK,wheel:Ve(t)?K.ACTION.DOLLY:Oe(t)?K.ACTION.ZOOM:K.ACTION.NONE},e.touches={one:K.ACTION.TOUCH_ROTATE,two:Ve(t)?K.ACTION.TOUCH_DOLLY_TRUCK:Oe(t)?K.ACTION.TOUCH_ZOOM_TRUCK:K.ACTION.NONE,three:K.ACTION.TOUCH_TRUCK},e.dollyToCursor=!0,e.azimuthRotateSpeed=1,e.polarRotateSpeed=1,e.minDistance=1,e.maxDistance=300,e.minZoom=3,this.cameraManager.cameraControls.truckSpeed=2}adjustCameraByBBox(t){const e=this.cameraManager.cameraControls,i=new d.Vector3;t.getSize(i);const s=i.length();e.minDistance=1,e.maxDistance=s*10,e.minZoom=3}}class zn{constructor(t){p(this,"mode");p(this,"cameraManager");this.mode=He.Plan,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:K.ACTION.TRUCK,middle:K.ACTION.TRUCK,right:K.ACTION.TRUCK,wheel:Ve(t)?K.ACTION.DOLLY:Oe(t)?K.ACTION.ZOOM:K.ACTION.NONE},e.touches={one:K.ACTION.TOUCH_TRUCK,two:Ve(t)?K.ACTION.TOUCH_DOLLY_TRUCK:Oe(t)?K.ACTION.TOUCH_ZOOM_TRUCK:K.ACTION.NONE,three:K.ACTION.NONE},e.dollyToCursor=!0,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0,e.truckSpeed=1,e.maxZoom=1/0,e.minZoom=-1/0}adjustCameraByBBox(t){}}const Dt=50,ws=new d.Vector3;class jh{constructor(t){p(this,"viewer");p(this,"perspectiveCamera");p(this,"orthographicCamera");p(this,"activeCamera");p(this,"cameraControls");p(this,"previousDistance");p(this,"previousAzimuthRotateSpeed");p(this,"previousPolarRotateSpeed");p(this,"previousDollySpeed");p(this,"previousTruckSpeed");p(this,"previousMouseLeft");p(this,"enableKeyDown");p(this,"controlsMap");p(this,"activeControls");p(this,"projection");p(this,"anchor");p(this,"onKeyDown");p(this,"onChange");this.previousDistance=-1,this.previousAzimuthRotateSpeed=1,this.previousPolarRotateSpeed=1,this.previousDollySpeed=1,this.previousTruckSpeed=2,this.previousMouseLeft=K.ACTION.NONE,this.enableKeyDown=!0,this.projection=$e.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const r=this.cameraControls,n=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===Be.Viewer3d||this.viewer.name===Be.BimTilesViewer;switch(s.code){case"ArrowLeft":a?r.rotate(.1,0,!0):this.viewer.name===Be.Viewer2d&&r.truck(n,0,!0);break;case"ArrowRight":a?r.rotate(-.1,0,!0):this.viewer.name===Be.Viewer2d&&r.truck(-n,0,!0);break;case"ArrowUp":a?r.rotate(0,.1,!0):this.viewer.name===Be.Viewer2d&&r.truck(0,n,!0);break;case"ArrowDown":a?r.rotate(0,-.1,!0):this.viewer.name===Be.Viewer2d&&r.truck(0,-n,!0);break;case"KeyW":a&&(Oe(this.activeCamera)?r.zoom(.01,!0):r.dolly(1,!0));break;case"KeyA":a&&r.truck(-n,0,!0);break;case"KeyS":a&&(Oe(this.activeCamera)?r.zoom(-.01,!0):r.dolly(-1,!0));break;case"KeyD":a&&r.truck(n,0,!0);break;case"KeyQ":a&&r.truck(0,-n,!0);break;case"KeyE":a&&r.truck(0,n,!0);break}},this.onChange=()=>{this.viewer.enableRender()},this.viewer=t;const e=t.viewerContainer,i=e.clientWidth/e.clientHeight;this.perspectiveCamera=new d.PerspectiveCamera(hn,i,Ui,Hi),this.orthographicCamera=new d.OrthographicCamera(Dt*i/-2,Dt*i/2,Dt/2,Dt/-2,Ui,Hi),this.activeCamera=this.perspectiveCamera,this.setupCameras(),K.install({THREE:d}),this.cameraControls=new K(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[He.Orbit]:new Fn(this),[He.Plan]:new zn(this)},this.activeControls=this.controlsMap[He.Orbit],this.setupControls(),this.setProjection($e.Perspective),this.anchor=this.createAnchor()}get viewerContainer(){return this.viewer.viewerContainer}get inputManager(){return this.viewer.getInputManager()}createAnchor(){const t=document.createElement("div");return t.className="anchor",this.viewerContainer?.appendChild(t),this.cameraControls.addEventListener("control",()=>{if(this.isOrbitPointVisible()){const e=this.getTarget(),i=pe.world2Screen(e,this.activeCamera,this.viewerContainer);this.setAnchorPosition(i.x,i.y)}}),t}setAnchorPosition(t,e){this.anchor.style.left=t+"px",this.anchor.style.top=e+"px"}setOrbitPointVisible(t){t?this.anchor.classList.add("active"):this.anchor.classList.remove("active")}isOrbitPointVisible(){return this.anchor.classList.contains("active")}setOrthoCameraAspect(t,e){const i=t/e;this.orthographicCamera.left=-50*i/2,this.orthographicCamera.right=Dt*i/2,this.orthographicCamera.top=Dt/2,this.orthographicCamera.bottom=-50/2,this.orthographicCamera.updateProjectionMatrix()}setupCameras(){this.setCameraPositionAndTarget(this.perspectiveCamera)}setCameraPositionAndTarget(t){t.position.z=10,t.position.y=10,t.position.x=10,t.lookAt(new d.Vector3(0,0,0))}setupControls(){const t=this.cameraControls;t.smoothTime=.1,t.draggingSmoothTime=0,t.infinityDolly=!0,t.setTarget(0,0,0),t.addEventListener("controlstart",()=>this.onChange),t.addEventListener("control",()=>this.onChange),t.addEventListener("update",()=>this.viewer.dispatchEvent(re.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===He.FirstPerson)return;this.previousDistance=this.cameraControls.distance,this.cameraControls.distance=200;const{width:t,height:e}=this.getDims();this.setupOrthoCamera(e,t),this.activeCamera=this.orthographicCamera,this.projection=$e.Orthographic}getDims(){const t=new d.Vector3;this.perspectiveCamera.getWorldDirection(t);const e=new d.Vector3;this.cameraControls.getTarget(e);const i=e.clone().sub(this.perspectiveCamera.position),s=i.dot(t),{clientWidth:r,clientHeight:n}=this.viewer.viewerContainer,a=r/n,o=this.perspectiveCamera.fov,l=s*2*Math.atan(o*(Math.PI/180)/2);return{width:l*a,height:l}}setupOrthoCamera(t,e){this.cameraControls.mouseButtons.wheel=K.ACTION.ZOOM;const i=this.perspectiveCamera,s=this.orthographicCamera;s.zoom=1,s.left=e/-2,s.right=e/2,s.top=t/2,s.bottom=t/-2,s.updateProjectionMatrix(),s.position.copy(i.position),s.quaternion.copy(i.quaternion),this.cameraControls.camera=s}setPerspectiveCamera(){const t=this.cameraControls;t.mouseButtons.wheel=K.ACTION.DOLLY;const e=this.perspectiveCamera,i=this.orthographicCamera;e.position.copy(i.position),e.quaternion.copy(i.quaternion),e.updateProjectionMatrix(),t.camera=e,t.mouseButtons.wheel=K.ACTION.DOLLY,this.activeCamera=e,this.projection=$e.Perspective,t.distance=this.previousDistance,t.zoomTo(1)}update(t){const e=this.cameraControls.update(t);return this.camera.updateMatrixWorld(),e}updateAspect(){const{clientWidth:t,clientHeight:e}=this.viewer.viewerContainer;this.perspectiveCamera.aspect=t/e,this.perspectiveCamera.updateProjectionMatrix(),this.setOrthoCameraAspect(t,e)}get camera(){return this.activeCamera}enableKeyControl(t){this.enableKeyDown=t}getTarget(){return this.cameraControls.getTarget(ws)}getPosition(){return this.cameraControls.getPosition(ws)}adjustCameraByBBox(t){const e=this.camera.near,i=this.camera.far,s=new d.Vector3;t.getSize(s);const r=s.length(),n=5,a=r/n,o=r*n;if(e>a||i<o){const l=c=>z.numberToString(c);S.info("[Viewer] BBox's longest side is: "+l(r)),e>a&&(S.warn("[Viewer] camera.near("+l(e)+") shouldn't bigger than "+l(a)+", will change it!"),this.camera.near=a),i<o&&(S.warn("[Viewer] camera.far("+l(i)+") shouldn't smaller than "+l(o)+", will change it!"),this.camera.far=o)}this.activeControls.adjustCameraByBBox(t),this.cameraControls.update(0)}enableControl(t){this.cameraControls.enabled=t}get enableRotate(){const t=this.cameraControls;return!!t.azimuthRotateSpeed||!!t.polarRotateSpeed}set enableRotate(t){const e=this.cameraControls;t?(e.azimuthRotateSpeed=this.previousAzimuthRotateSpeed,e.polarRotateSpeed=this.previousPolarRotateSpeed):(this.previousAzimuthRotateSpeed=e.azimuthRotateSpeed,this.previousPolarRotateSpeed=e.polarRotateSpeed,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0)}enableZoom(t){const e=this.cameraControls;t?e.dollySpeed=this.previousDollySpeed:(this.previousDollySpeed=e.dollySpeed,e.dollySpeed=0)}enablePan(t){const e=this.cameraControls;t?e.truckSpeed=this.previousTruckSpeed:(this.previousTruckSpeed=e.dollySpeed,e.truckSpeed=0)}enableMouseLeft(t){const e=this.cameraControls;t?e.mouseButtons.left=this.previousMouseLeft:(this.previousMouseLeft=e.mouseButtons.left,e.mouseButtons.left=K.ACTION.NONE)}setCameraPosition(t){this.cameraControls.setPosition(t.x,t.y,t.z)}setCameraTarget(t){this.cameraControls.setTarget(t.x,t.y,t.z)}flyTo(t,e,i=!0){const s=this.cameraControls;s.setLookAt(t.x,t.y,t.z,e.x,e.y,e.z,i),s.setFocalOffset(0,0,0,!0)}flyToPosition(t,e,i){this.cameraControls.moveTo(t,e,i,!0)}flyToBox(t,e){const i=new d.Sphere;t.getBoundingSphere(i),this.cameraControls.fitToBox(t,!0,e)}fitToSphere(t){this.cameraControls.fitToSphere(t,!0)}flyToObject(t){const e=new d.Box3().setFromObject(t),i=new d.Sphere;e.getBoundingSphere(i),this.cameraControls.fitToSphere(i,!0)}flyToViewpoint(t){this.flyTo(t.eye,t.look),t.zoom!=null&&(this.orthographicCamera.zoom=t.zoom)}getDistanceToFitSphere(t){return this.cameraControls.getDistanceToFitSphere(t)}setNavigationMode(t){this.activeControls.mode!==t&&(this.activeControls=this.controlsMap[t],this.activeControls.setupControl())}getProjection(){return this.projection}setProjection(t){this.projection!==t&&(this.projection=t,t===$e.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection(ws)}getCameraConfig(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,near:this.activeCamera.near,far:this.activeCamera.far,zoom:this.activeCamera.zoom}}getCurrentViewpoint(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,zoom:this.activeCamera.zoom}}setCameraConfig(t){const e=this.cameraControls,{near:i=Ui,far:s=Hi,up:r=new d.Vector3(0,1,0),zoom:n=1,eye:a,look:o}=t;this.activeCamera.near=i,this.activeCamera.far=s,this.activeCamera.up.set(r.x,r.y,r.z),this.activeCamera.updateProjectionMatrix(),e.updateCameraUp(),e.zoomTo(n),e.setLookAt(a.x,a.y,a.z,o.x,o.y,o.z,!0),e.setFocalOffset(0,0,0,!0)}destroy(){this.anchor.remove(),this.inputManager.removeEventListener("keydown",this.onKeyDown),this.perspectiveCamera.removeFromParent(),this.orthographicCamera.removeFromParent()}}const Ot=class Ot extends En{tableName(){return"fonts"}static instance(){return!Ot._instance&&(Ot._instance=new Ot),Ot._instance}query(t){let e;return new Promise((i,s)=>{super.query(r=>{if(!r){i(e);return}!r.value||r.value.fileName!==t||(e=r.value)},r=>{s(r)})})}queryAll(){const t=Object.create(null,{queryAll:{get:()=>super.queryAll}});return new Promise((e,i)=>{t.queryAll.call(this,s=>{e(s)},s=>{i(s)})})}};p(Ot,"_instance");let Yt=Ot;var jn=(h=>(h[h.Horizontal=0]="Horizontal",h[h.Vertical=1]="Vertical",h[h.All=2]="All",h))(jn||{}),Ee=(h=>(h[h.Shapes=0]="Shapes",h[h.Bigfont=1]="Bigfont",h[h.Unifont=2]="Unifont",h))(Ee||{});class Vn extends Sa.Font{constructor(e,i){super(i);p(this,"info");p(this,"orientation");p(this,"baseUp");p(this,"baseDown");p(this,"fileHeader");p(this,"fileVersion");p(this,"fileName");p(this,"data");p(this,"order");p(this,"unsupportedChars");this.info="",this.orientation=jn.Horizontal,this.baseUp=0,this.baseDown=0,this.fileHeader="",this.fileVersion="",this.order=0,this.unsupportedChars={},this.fileName=e}addUnsupportedChar(e){!this.unsupportedChars[e]&&(this.unsupportedChars[e]=0),this.unsupportedChars[e]++}getFontFile(){return{order:this.order,data:this.data,info:this.info,orientation:this.orientation,baseUp:this.baseUp,baseDown:this.baseDown,fileName:this.fileName,fileHeader:this.fileHeader,fileVersion:this.fileVersion}}setFontFile(e){this.fileName=e.fileName,this.data=e.data,this.info=e.info,this.order=e.order,this.orientation=e.orientation,this.baseUp=e.baseUp,this.baseDown=e.baseDown,this.fileHeader=e.fileHeader,this.fileVersion=e.fileVersion}async setFontDataToIndexedDb(){const e=this.getFontFile();return new Promise((i,s)=>{Yt.instance().save(e,()=>{console.log("[FontFile] Saved '"+this.fileName+"' ("+this.fileHeader+") to indexedDb"),i()},r=>s("[FontFile] Failed to save '"+this.fileName+"' ("+this.fileHeader+") to indexedDb! "+r))})}async getFontDataByIndexedDb(){return Yt.instance().query(this.fileName)}releaseFontData(){this.data={}}}class vt extends Vn{constructor(e,i){super(e,i);p(this,"reversed");this.reversed=!1,i instanceof ArrayBuffer?this.data=this.parseTTF(i):i.fileName?this.setFontFile(i):this.data=i,this.type="MeshFont"}generateShapes(e,i){return super.generateShapes(e,i)}getCharShape(e,i){const s=qr(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return qr("?",e,0,0,this.data)?.path}parseTTF(e){function i(r,n){const a=Math.round,o={},l=1e5/((r.unitsPerEm||2048)*72),c=r.encoding.cmap.glyphIndexMap,u=Object.keys(c);for(let f=0;f<u.length;f++){const m=u[f],g=r.glyphs.glyphs[c[m]];if(m!==void 0){const x={ha:a(g.advanceWidth*l),x_min:a(g.xMin*l),x_max:a(g.xMax*l),o:""};n&&(g.path.commands=s(g.path.commands)),g.path.commands.forEach(function(y){y.type.toLowerCase()==="c"&&(y.type="b"),x.o+=y.type.toLowerCase()+" ",y.x!==void 0&&y.y!==void 0&&(x.o+=a(y.x*l)+" "+a(y.y*l)+" "),y.x1!==void 0&&y.y1!==void 0&&(x.o+=a(y.x1*l)+" "+a(y.y1*l)+" "),y.x2!==void 0&&y.y2!==void 0&&(x.o+=a(y.x2*l)+" "+a(y.y2*l)+" ")}),o[String.fromCodePoint(g.unicode)]=x}}return{glyphs:o,familyName:r.getEnglishName("fullName"),ascender:a(r.ascender*l),descender:a(r.descender*l),underlinePosition:r.tables.post.underlinePosition,underlineThickness:r.tables.post.underlineThickness,boundingBox:{xMin:r.tables.head.xMin,xMax:r.tables.head.xMax,yMin:r.tables.head.yMin,yMax:r.tables.head.yMax},resolution:1e3,original_font_information:r.tables.name}}function s(r){const n=[];let a;r.forEach(function(l){l.type.toLowerCase()==="m"?(a=[l],n.push(a)):l.type.toLowerCase()!=="z"&&a.push(l)});const o=[];return n.forEach(function(l){const c={type:"m",x:l[l.length-1].x,y:l[l.length-1].y};o.push(c);for(let u=l.length-1;u>0;u--){const f=l[u],m={type:f.type};f.x2!==void 0&&f.y2!==void 0?(m.x1=f.x2,m.y1=f.y2,m.x2=f.x1,m.y2=f.y1):f.x1!==void 0&&f.y1!==void 0&&(m.x1=f.x1,m.y1=f.y1),m.x=l[u-1].x,m.y=l[u-1].y,o.push(m)}}),o}return i(Ca.parse(e),this.reversed)}}function qr(h,t,e,i,s){const r=s.glyphs[h];if(!r)return;const n=new d.ShapePath;let a,o,l,c,u,f,m,g;if(r.o){const x=r._cachedOutline||(r._cachedOutline=r.o.split(" "));for(let y=0,T=x.length;y<T;)switch(x[y++]){case"m":a=x[y++]*t+e,o=x[y++]*t+i,n.moveTo(a,o);break;case"l":a=x[y++]*t+e,o=x[y++]*t+i,n.lineTo(a,o);break;case"q":l=x[y++]*t+e,c=x[y++]*t+i,u=x[y++]*t+e,f=x[y++]*t+i,n.quadraticCurveTo(u,f,l,c);break;case"b":l=x[y++]*t+e,c=x[y++]*t+i,u=x[y++]*t+e,f=x[y++]*t+i,m=x[y++]*t+e,g=x[y++]*t+i,n.bezierCurveTo(u,f,m,g,l,c);break}}return{offsetX:r.ha*t,path:n}}class J{static GetBytes(t){switch(typeof t){case"string":{const e=new Uint16Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return new Uint8Array(e.buffer)}case"number":return t-Math.floor(t)==0?t>4294967295?(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Int32Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1));case"boolean":return(function(e){return e[0]=Number(t),e})(new Uint8Array(1));default:if(t instanceof Array){const e=[];for(let n=0;n<t.length;n++)e.push(J.GetBytes(t[n]));let i=0;for(let n=0;n<e.length;n++)i+=e[n].length;const s=new Uint8Array(i);let r=0;for(let n=0;n<e.length;n++)for(let a=0;a<e[n].length;a++)s[r++]=e[n][a];return s}throw"Can't Convert To Bytes!!"}}static Get1Bytes(t){switch(typeof t){case"number":case"boolean":return new Uint8Array([Number(t)]);default:if(t instanceof Array){const e=[];for(let n=0;n<t.length;n++)e.push(this.Get1Bytes(t[n]));let i=0;for(let n=0;n<e.length;n++)i+=e[n].length;const s=new Uint8Array(i);let r=0;for(let n=0;n<e.length;n++)for(let a=0;a<e[n].length;a++)s[r++]=e[n][a];return s}throw"Can't Convert To Bytes!!"}}static byteTosbyte(t){return(t&127)-(t&128?128:0)}static ToBoolean(t,e){return e=e||0,!!t[e]}static ToInt8(t,e){return e=e||0,t[e]&128?-((t[e]^255)+1):t[e]}static ToUInt8(t,e){return e=e||0,t[e]}static ToInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Int16Array(i.buffer,0,1)[0]}static ToInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Int32Array(i.buffer,0,1)[0]}static ToUInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Uint16Array(i.buffer,0,1)[0]}static ToUInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Uint32Array(i.buffer,0,1)[0]}static ToChar(t,e){e=e||0;const i=t.slice(e,e+2);return String.fromCharCode(new Uint16Array(i.buffer,0,1)[0])}static ToAscii(t,e){return e=e||0,String.fromCharCode(t[e])}static ToAsciiString(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);let s="";for(let r=0;r<i;r++)s+=String.fromCharCode(t[e+r]||0);return s}static ToUTF16String(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);const s=new Uint8Array(i);for(let r=0;r<i;r++)s[r]=t[e+r]||0;return String.fromCharCode.apply(null,Array.from(new Uint16Array(s.buffer,0,i/2)))}static ToFloat32(t,e){e=e||0;const i=t.slice(e,e+4);return new Float32Array(i.buffer,0,1)[0]}static ToFloat64(t,e){e=e||0;const i=t.slice(e,e+8);return new Float64Array(i.buffer,0,1)[0]}}let Zi;function Vh(){const h=[[161,169,161,254],[176,247,161,254],[129,160,64,254],[170,254,64,160],[168,169,64,160],[170,175,161,254],[248,254,161,254],[161,167,64,160]],t=new Uint16Array(23940);let e=0;for(const[s,r,n,a]of h)for(let o=n;o<=a;o++)if(o!==127)for(let l=s;l<=r;l++)t[e++]=o<<8|l;const i=new TextDecoder("gbk").decode(t);for(Zi=new Uint16Array(65536),e=0;e<i.length;e++)Zi[i.charCodeAt(e)]=t[e]}function Uh(h){!Zi&&Vh();const t=new Uint8Array(h.length*2);let e=0;for(let i=0;i<h.length;i++){const s=h.charCodeAt(i);if(s<128)t[e++]=s;else{const r=Zi[s];t[e++]=r&255,t[e++]=r>>8}}return t.subarray(0,e)}new d.Vector2;class gi extends d.Shape{constructor(e,i){super();p(this,"width");p(this,"lastPoint");p(this,"polylines");p(this,"bounds");this.width=0,this.bounds=new d.Box2,this.lastPoint=e,this.polylines=i,this.width=this.calcWidth(i)}offset(e){const i=[];for(let s=0;s<this.polylines.length;s++){const r=this.polylines[s],n=[];for(let a=0;a<r.length;a++){const o=r[a];n.push(o.clone().add(e))}i.push(n)}return new gi(this.lastPoint,i)}transform(e){const i=[];for(let s=0;s<this.polylines.length;s++){const r=this.polylines[s],n=[];for(let a=0;a<r.length;a++){const o=r[a];n.push(o.clone().applyMatrix3(e))}i.push(n)}return new gi(this.lastPoint.clone().applyMatrix3(e),i)}calcWidth(e){const i=this.bounds;for(let n=0;n<e.length;n++){const a=e[n];for(let o=0;o<a.length;o++){const l=a[o];i.expandByPoint(l)}}const s=i.min.x||0;return(i.max.x||0)-s}toThreeGeometry(){const e=this.polylines,i=[],s=[];let r=0;const n=new d.BufferGeometry;for(let a=0;a<e.length;a++){const o=e[a];for(let l=0;l<o.length;l++){const c=o[l];i.push(c.x,c.y,0),l===o.length-1||s.push(r,r+1),r++}}return n.userData={advanceWidth:this.width},n.setAttribute("position",new d.Float32BufferAttribute(i,3)),n.setIndex(s),n}}const Ze=class Ze{static parserHeader(t,e){let i="",s=!1,r=0;const n=!0;for(;n;){const a=t.readInt8(),o=String.fromCharCode(a);if(s)o===e[r]?r++:(s=!1,r=0);else{if(o===e[r]){s=!0,r++;continue}i+=o}if(s&&r===e.length)break}return i}static getCode(t){const e=Uh(t);return e.length<2?e[0]:e.length<4?J.ToUInt16(e,0):J.ToUInt32(e,0)}static parserCode(t,e,i){let s=new d.Vector2;const r=[];let n=[];const a=[];let o=!1;for(let l=0;l<e.length;l++){const c=e[l];switch(c){case 0:break;case 1:o=!0,n.push(s.clone());break;case 2:o=!1,n.length>1?(r.push(n.slice()),n=[]):s.set(0,0);break;case 3:l++,i/=e[l];break;case 4:l++,i*=e[l];break;case 5:if(a.length===4)throw"The position stack is only four locations deep";a.push(s.clone());break;case 6:if(a.length===0)break;s=a.pop(),n.length>1&&(r.push(n.slice()),n=[]),o&&n.push(s.clone());break;case 7:{let u=0,f,m=i*t.baseUp;const g=s.clone();switch(n.length>1&&(r.push(n.slice()),n=[]),t.fontType){case Ee.Shapes:l++,u=e[l];break;case Ee.Bigfont:l++,u=e[l],u==0&&(l++,u=J.ToUInt16(new Uint8Array([e[l++],e[l++]]),0),g.x=e[l++]*i,g.y=e[l++]*i,m=e[l]*i);break;case Ee.Unifont:l+=2,u=J.ToUInt16(new Uint8Array([e[l-1],e[l]]),0);break}u!==0&&(f=t.getGraphicDataByCodeWithOffset(u,m,g),f&&(r.push(...f.polylines.slice()),s=f.lastPoint.clone()))}break;case 8:{const u=new d.Vector2;u.x=J.byteTosbyte(e[++l]),u.y=J.byteTosbyte(e[++l]),s.add(u.multiplyScalar(i)),o&&n.push(s.clone())}break;case 9:for(;;){const f=new d.Vector2;if(f.x=J.byteTosbyte(e[++l]),f.y=J.byteTosbyte(e[++l]),!Number.isFinite(f.x)||!Number.isFinite(f.y)||f.x==0&&f.y==0)break;s.add(f.multiplyScalar(i)),o&&n.push(s.clone())}break;case 10:{const u=e[++l]*i,f=J.byteTosbyte(e[++l]),m=(f&112)>>4;let g=f&7;g==0&&(g=8);const x=Math.PI/4;let y=x*g,T=Ze.CIRCLE_SPAN;f<0&&(T=-T,y=-y);const v=x*m,b=v+y,E=s.clone().sub(new d.Vector2(Math.cos(v)*u,Math.sin(v)*u));if(s=E.clone().add(new d.Vector2(Math.cos(b)*u,Math.sin(b)*u)),o){let O=v;const _=!0;for(;_&&(O+=T,!!Number.isFinite(O));)if(f>=0&&O<b||f<0&&O>b)n.push(E.clone().add(new d.Vector2(u*Math.cos(O),u*Math.sin(O))));else break;n.push(s.clone())}}break;case 11:{const u=e[++l],f=e[++l],m=e[++l],g=e[++l],x=(m*255+g)*i,y=J.byteTosbyte(e[++l]),T=(y&112)>>4;let v=y&7;v==0&&(v=8),f!=0&&v--;const b=Math.PI/4;let E=b*v,O=Ze.CIRCLE_SPAN,_=1;y<0&&(O=-O,E=-E,_=-1);let C=b*T,w=C+E;C+=b*u/256*_,w+=b*f/256*_;const M=s.clone().sub(new d.Vector2(x*Math.cos(C),x*Math.sin(C)));if(s=M.clone().add(new d.Vector2(x*Math.cos(w),x*Math.sin(w))),o){let P=C;const A=!0;for(;A&&(P+=O,!!Number.isFinite(P));)if(y>0&&P<w||y<0&&P>w)n.push(M.clone().add(new d.Vector2(x*Math.cos(P),x*Math.sin(P))));else break;n.push(s.clone())}}break;case 12:{const u=new d.Vector2;u.x=J.byteTosbyte(e[++l])*i,u.y=J.byteTosbyte(e[++l])*i;let f=J.byteTosbyte(e[++l]);f<-127&&(f=-127),o&&(f==0?n.push(s.clone().add(u)):n.push(Ze.generateArcPoints(s,u,f/127))),s.add(u)}break;case 13:for(;;){const f=new d.Vector2;if(f.x=J.byteTosbyte(e[++l])*i,f.y=J.byteTosbyte(e[++l])*i,!Number.isFinite(f.x)||!Number.isFinite(f.y)||f.x==0&&f.y==0)break;let m=J.byteTosbyte(e[++l]);m<-127&&(m=-127),o&&(m==0?n.push(s.clone().add(f)):n.push(Ze.generateArcPoints(s.clone(),f,m/127))),s.add(f)}break;case 14:l=Ze.skipCode(t,e,++l);break;default:if(c>15){const u=(c&240)>>4,f=c&15,m=new d.Vector2;switch(f){case 0:m.x=1;break;case 1:m.x=1,m.y=.5;break;case 2:m.x=1,m.y=1;break;case 3:m.x=.5,m.y=1;break;case 4:m.y=1;break;case 5:m.x=-.5,m.y=1;break;case 6:m.x=-1,m.y=1;break;case 7:m.x=-1,m.y=.5;break;case 8:m.x=-1;break;case 9:m.x=-1,m.y=-.5;break;case 10:m.x=-1,m.y=-1;break;case 11:m.x=-.5,m.y=-1;break;case 12:m.y=-1;break;case 13:m.x=.5,m.y=-1;break;case 14:m.x=1,m.y=-1;break;case 15:m.x=1,m.y=-.5;break}s.add(m.multiplyScalar(u*i)),o&&n.push(s.clone())}break}}return new gi(s,r)}static skipCode(t,e,i){switch(e[i]){case 0:break;case 1:break;case 2:break;case 3:case 4:i++;break;case 5:break;case 6:break;case 7:switch(t.fontType){case Ee.Shapes:i++;break;case Ee.Bigfont:i++,e[i]==0&&(i+=6);break;case Ee.Unifont:i+=2;break}break;case 8:i+=2;break;case 9:for(;;){const n=e[++i],a=e[++i];if(n===void 0||a===void 0||n==0&&a==0)break}break;case 10:i+=2;break;case 11:i+=5;break;case 12:i+=3;break;case 13:for(;;){const n=e[++i],a=e[++i];if(n===void 0||a===void 0||n==0&&a==0)break;e[++i]}break}return i}static generateArcPoints(t,e,i){const s=t.clone().add(e),r=i<0,n=!1;i=Math.abs(i);const a=e.length()/2,o=a*i,l=2*Math.atan(1/i),c=new d.Vector2(e.y,-e.x);c.normalize(),c.multiplyScalar(o);const u=Math.abs(a/Math.sin(l/2)),f=t.add(e.divideScalar(2));n!==r?f.add(c):f.sub(c);const m=t.sub(f),g=s.sub(f);let x=Math.atan2(m.y,m.x);const y=Math.atan2(g.y,g.x);let T=Ze.CIRCLE_SPAN;r?(T=-T,x<y&&(x+=2*Math.PI)):x>y&&(x-=2*Math.PI);let v=x;const b=!0;for(;b;){if(v+=T,!r&&v<y||r&&v>y)return f.add(new d.Vector2(u*Math.cos(v),u*Math.sin(v)));break}return s}};p(Ze,"FILE_STOP_FLAG",["\r",`
1532
+ `,""]),p(Ze,"CIRCLE_SPAN",Math.PI/18);let lt=Ze;const Ms={130:[[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],131:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],132:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],133:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]]],134:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],135:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],136:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],178:[[[1.142,9.285],[1.142,9.428],[1.285,9.714],[1.428,9.857],[1.714,10],[2.285,10],[2.571,9.857],[2.714,9.714],[2.857,9.428],[2.857,9.142],[2.714,8.857],[2.428,8.428],[1,7],[3,7]]],8960:[[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]],[[0,0],[8,8]]],20393:[[[0,0],[0,6.666]],[[0,4.761],[1.428,6.19],[2.38,6.666],[3.809,6.666],[4.761,6.19],[5.238,4.761],[5.238,0]],[[5.238,4.761],[6.666,6.19],[7.619,6.666],[9.047,6.666],[10,6.19],[10.476,4.761],[10.476,0]],[[11.142,9.285],[11.142,9.428],[11.285,9.714],[11.428,9.857],[11.714,10],[12.285,10],[12.571,9.857],[12.714,9.714],[12.857,9.428],[12.857,9.142],[12.714,8.857],[12.428,8.428],[11,7],[13,7]]],41123:[],55714:[[[2,5.9],[2.6,6.1],[3.4,7],[3.4,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],55970:[[[2.3,5.6],[2.3,5.9],[2.6,6.4],[2.9,6.7],[3.4,7],[4.6,7],[5.1,6.7],[5.4,6.4],[5.7,5.9],[5.7,5.3],[5.4,4.7],[4.9,3.9],[2,1],[6,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56226:[[[2.6,7],[5.7,7],[4,4.7],[4.9,4.7],[5.4,4.4],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56482:[[[4.9,7],[2,3],[6.3,3]],[[4.9,7],[4.9,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56738:[[[5.4,7],[2.6,7],[2.3,4.4],[2.6,4.7],[3.4,5],[4.3,5],[5.1,4.7],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56994:[[[5.4,6.1],[5.1,6.7],[4.3,7],[3.7,7],[2.9,6.7],[2.3,5.9],[2,4.4],[2,3],[2.3,1.9],[2.9,1.3],[3.7,1],[4,1],[4.9,1.3],[5.4,1.9],[5.7,2.7],[5.7,3],[5.4,3.9],[4.9,4.4],[4,4.7],[3.7,4.7],[2.9,4.4],[2.3,3.9],[2,3]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57250:[[[2,7],[6,7],[3.1,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57506:[[[3.4,7],[2.6,6.7],[2.3,6.1],[2.3,5.6],[2.6,5],[3.1,4.7],[4.3,4.4],[5.1,4.1],[5.7,3.6],[6,3],[6,2.1],[5.7,1.6],[5.4,1.3],[4.6,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1],[2,3],[2.3,3.6],[2.9,4.1],[3.7,4.4],[4.9,4.7],[5.4,5],[5.7,5.6],[5.7,6.1],[5.4,6.7],[4.6,7],[3.4,7]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57762:[[[5.7,5],[5.4,4.1],[4.9,3.6],[4,3.3],[3.7,3.3],[2.9,3.6],[2.3,4.1],[2,5],[2,5.3],[2.3,6.1],[2.9,6.7],[3.7,7],[4,7],[4.9,6.7],[5.4,6.1],[5.7,5],[5.7,3.6],[5.4,2.1],[4.9,1.3],[4,1],[3.4,1],[2.6,1.3],[2.3,1.9]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],60070:[[[0,6],[10,6],[10,4]]],60326:[[[0,7],[0,5],[10,5]]]},Wr=new d.Matrix3,ui=class ui extends Vn{constructor(e,i){super(e,i);p(this,"isExtend");p(this,"isUniCode");p(this,"isEmbedded");p(this,"fontType");p(this,"textShapesCache");p(this,"graphicData");if(this.isExtend=!1,this.isUniCode=!0,this.isEmbedded=!1,this.fontType=Ee.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new vi(i),r=lt.parserHeader(s,lt.FILE_STOP_FLAG),n=r.split(" ");switch(n[1]){case"shapes":this.parseShapeFont(s),this.fontType=Ee.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=Ee.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=Ee.Unifont;break}this.fileHeader=n[0],this.fileVersion=n[2]}else this.setFontFile(i)}generateShapes(e,i){const s=[];let r=0;for(let n=0;n<e.length;n++){const a=e[n];if(a===" "){r+=i;continue}const o=this.getCharShape(a,i);if(!o){r+=i,this.addUnsupportedChar(a);continue}s.push(o.offset(new d.Vector2(r,0))),r+=o.width}return s}getCharShape(e,i){let s=lt.getCode(e);s===0&&(s=e.charCodeAt(0));const r=this.getGraphicDataByCode(s,i);if(!r)return this.addUnsupportedChar?.(e),null;if(r.polylines&&r.polylines.length===0&&(r.width=i*.8),typeof r.width!="number"||r.width<=0){const n=r,a=n.xMin!=null?n.xMin:0,o=n.xMax!=null?n.xMax:0;r.width=Math.max(.1,o-a)}return r}getGraphicDataByCode(e,i){const s=e+"_"+i;if(this.textShapesCache.has(s))return this.textShapesCache.get(s);if(e===0)return;const r=this.data;let n;if(!this.graphicData.has(e)){if(r[e]){const a=r[e],o=ui.DEFAULT_SIZE/this.baseUp;n=lt.parserCode(this,a,o),this.graphicData.set(e,n)}else if(Ms[e]){const a=[];for(let o=0;o<Ms[e].length;o++)a.push(Ms[e][o].map(l=>new d.Vector2(l[0],l[1])));n=new gi(new d.Vector2,a),this.graphicData.set(e,n)}}if(this.graphicData.has(e)){const a=i/ui.DEFAULT_SIZE;Wr.identity().scale(a,a),n=this.graphicData.get(e).transform(Wr)}return n}getGraphicDataByCodeWithOffset(e,i,s){return this.getGraphicDataByCode(e,i)?.offset(s)}parseBigFont(e){J.ToInt16(e.readBytes(2),0);const i=J.ToInt16(e.readBytes(2),0),s=J.ToInt16(e.readBytes(2),0);for(let l=0;l<s;l++)e.readBytes(2),e.readBytes(2);const r=[];for(let l=0;l<i;l++){const c=e.readBytes(8),u=J.ToUInt16(new Uint8Array([c[1],c[0]]),0),f=J.ToUInt16(c,2),m=J.ToUInt32(c,4);u===0&&f===0&&m===0||r.push({code:u,length:f,offset:m})}const n={};for(const l of r)e.setPosition(l.offset),n[l.code]=e.readBytes(l.length);const a=n[0];this.info=Hh(a);let o=this.info.indexOf("\0")+1;a.length-o===4?(this.baseUp=a[o++],this.baseDown=a[o++],this.orientation=a[o++]):(this.baseUp=a[o++],o++,this.orientation=a[o++],this.baseDown=a[o++],this.isExtend=!0),this.data=n}parseUniFont(e){const i=J.ToInt32(e.readBytes(4),0),s=J.ToInt16(e.readBytes(2),0),r=e.readBytes(s);this.info=new TextDecoder().decode(r);let n=this.info.indexOf("\0");this.baseUp=r[++n],this.baseDown=r[++n],this.orientation=r[++n],this.isUniCode=r[++n]==0,this.isEmbedded=r[++n]==0;const a={};for(let o=0;o<i-1;o++){const l=J.ToUInt16(e.readBytes(2),0),c=J.ToUInt16(e.readBytes(2),0);a[l]=e.readBytes(c)}this.data=a}parseShapeFont(e){e.readBytes(2),e.readBytes(2);const i=J.ToInt16(e.readBytes(2),0),s=[];for(let o=0;o<i;o++){const l=J.ToUInt16(e.readBytes(2),0),c=J.ToUInt16(e.readBytes(2),0);s.push({code:l,length:c})}const r={};for(const o of s)r[o.code]=e.readBytes(o.length);const n=r[0];this.info=new TextDecoder().decode(n);let a=this.info.indexOf("\0");this.baseUp=n[++a],this.baseDown=n[++a],this.orientation=n[++a],this.data=r}getNotFoundTextShape(e){let i=0;return this.fontType===Ee.Bigfont&&(i=lt.getCode("?")),this.fontType===Ee.Unifont&&(i=lt.getCode("?")),this.getGraphicDataByCode(i,e)}getFontFile(){return{fontType:this.fontType,order:this.order,data:this.data,info:this.info,orientation:this.orientation,baseUp:this.baseUp,baseDown:this.baseDown,fileName:this.fileName,fileHeader:this.fileHeader,fileVersion:this.fileVersion}}setFontFile(e){this.fileName=e.fileName,this.fontType=e.fontType||Ee.Unifont,this.data=e.data,this.info=e.info,this.order=e.order,this.orientation=e.orientation,this.baseUp=e.baseUp,this.baseDown=e.baseDown,this.fileHeader=e.fileHeader,this.fileVersion=e.fileVersion}releaseFontData(){super.releaseFontData(),this.graphicData.clear(),this.textShapesCache.clear()}};p(ui,"DEFAULT_SIZE",12);let ht=ui;function Hh(h){let t,e,i,s,r;t="";const n=h.length;for(e=0;e<n;)switch(i=h[e++],i>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(i);break;case 12:case 13:s=h[e++],t+=String.fromCharCode((i&31)<<6|s&63);break;case 14:s=h[e++],r=h[e++],t+=String.fromCharCode((i&15)<<12|(s&63)<<6|(r&63)<<0);break}return t}class Ke{constructor(){p(this,"loader");p(this,"fontMap");p(this,"fileNames");p(this,"unsupportedChars");p(this,"missingFonts");p(this,"enableFontCache");this.fontMap=new Map,this.unsupportedChars={},this.missingFonts={},this.enableFontCache=!0,this.loader=new d.FileLoader}async loadFonts(t){if(t=Array.isArray(t)?t:[t],this.fileNames=t.map(e=>typeof e=="object"?Object.keys(e)[0]:Ke.getFileName(e.toLowerCase())),!await this.checkAllFontsLoaded(t)){for(let e=0;e<t.length;e++){const i=t[e];let s=null,r=[],n=[];typeof i=="object"?(r=Object.keys(i),n=Object.values(i),s=r[0]):s=Ke.getFileName(i.toLowerCase());let a;if(r.length){const o=r[0];if(o.lastIndexOf(".json")>-1){this.loader.setResponseType("json");const l=await this.loader.loadAsync(n[0]);a=new vt(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(n[0]);a=new ht(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(n[0]);a=new vt(s,l)}}else if(Ke.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new vt(s,o)}else if(Ke.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new ht(s,o)}else if(Ke.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new vt(s,o)}a&&(a.order=e+1,this.fontMap.set(s,a))}this.enableFontCache&&be.isBrowser&&(this.fontMap.forEach(async e=>{await e.setFontDataToIndexedDb()}),this.releaseFontData())}}getTextShape(t,e,i){if(this.fontMap.size===0){S.warn("[FontManager] no font loaded.");return}let s=this.fontMap.get(e.toLowerCase());return!s&&(s=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++),s?.generateShapes(t,i)}getCharShape(t,e,i){if(this.fontMap.size===0){S.warn("[FontManager] no font loaded.");return}e==null&&(e="");let s=this.fontMap.get(e.toLowerCase());if(!s){!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++;for(const[,n]of this.fontMap)if(n.getCharShape(t,i)){s=n;break}}let r=s?.getCharShape(t,i);if(!r)for(const[,n]of this.fontMap){if(n===s)continue;const a=n.getCharShape(t,i);if(a){s=n,r=a;break}}if(r){if(s instanceof ht)return r.toThreeGeometry();if(s instanceof vt)return new Ta.TextGeometry(t,{font:s,depth:0,size:i||12,curveSegments:3,bevelSegments:3})}}getNotFoundTextShape(t){let e,i;for(const[,s]of this.fontMap){const r=s.getNotFoundTextShape(t);if(r){e=r,i=s;break}}if(i instanceof ht)return e.toThreeGeometry();if(i instanceof vt)return new d.ExtrudeGeometry(e.toShapes(!1),{curveSegments:3,bevelSegments:3})}async checkAllFontsLoaded(t){if(!be.isBrowser)return!1;let e=!1;for(let i=0;i<t.length;i++){const s=t[i];let r=null;typeof s=="object"?r=Object.keys(s)[0]:r=Ke.getFileName(s.toLowerCase());const n=await Yt.instance().query(r);if(n)e=!0;else{e=!1;break}if(n.codes!==void 0){e=!1;break}}return e}async getFontFromIndexeddb(){if(this.fontMap.size!==0)return;const t=(await Yt.instance().queryAll()).sort((e,i)=>e.order-i.order);for(let e=0;e<t.length;e++){const i=t[e],{fileName:s,fontType:r}=i;if(this.fileNames&&!this.fileNames.includes(s))continue;let n;r?n=new ht(s,i):n=new vt(s,i),this.fontMap.set(s,n)}S.debug("[FontManager] Loaded font data from cache.")}isShxFont(t){if(this.fontMap.size===0){S.warn("[FontManager] no font loaded.");return}let e=this.fontMap.get(t);return!e&&(e=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[t]&&(this.missingFonts[t]=0),this.missingFonts[t]++),e instanceof ht}getUnsupportedChar(){return this.fontMap.forEach(t=>{Object.assign(this.unsupportedChars,t.unsupportedChars)}),this.unsupportedChars}releaseFontData(){this.fontMap.forEach(t=>{t.releaseFontData()}),this.fontMap.clear()}destroy(){this.releaseFontData(),this.fontMap.clear()}static isShxFile(t){return z.getExtension(t)==="shx"}static isTtfFile(t){return["WOFF","OTF","TTF"].includes(z.getExtension(t).toUpperCase())}static isJsonFile(t){return z.getExtension(t)==="json"}static getFileName(t){const e=t.lastIndexOf("/");return t.substring(e+1)}}class Nh{constructor(t){p(this,"object");this.object=t}instantiate(){const t=Date.now();this.instantiateInner(this.object),console.log("[Inst] instantiate() took "+(Date.now()-t)/1e3+"s")}instantiateInner(t){if(!t.children||t.children.length===0)return;const e=t.children.length,i={},s=[];for(let a=0;a<e;++a){const o=t.children[a];if(this.instantiateInner(o),o.children&&o.children.length>0||!o.geometry)continue;let l=!1;const c=Object.values(i);for(let u=c.length-1;u>=0;--u){const f=c[u].indexes[0],m=t.children[f];if(this.geometryEquals(o.geometry,m.geometry)&&de.materialsEquals(o.material,m.material)){!i[f]&&(i[f]={indexes:[f]},this.removeFromArray(s,f)),i[f].indexes.push(a),l=!0;break}}for(let u=s.length-1;!l&&u>=0;--u){const f=s[u],m=t.children[f];if(this.geometryEquals(o.geometry,m.geometry)&&de.materialsEquals(o.material,m.material)){!i[f]&&(i[f]={indexes:[f]},this.removeFromArray(s,f)),i[f].indexes.push(a),l=!0;break}}!l&&s.push(a)}if(Object.keys(i).length<=0)return;const r=[],n=[];Object.values(i).forEach(a=>{const o=a.indexes;n.push(...o);const l=t.children[o[0]];let c=l.material;if(c instanceof d.Material)c=c.clone();else if(Array.isArray(c)){const f=[];c.forEach(m=>f.push(m.clone())),c=f}const u=new d.InstancedMesh(l.geometry,c,o.length);u.name="[Instanced] "+l.name;for(let f=0;f<o.length;++f){const m=o[f],g=t.children[m];g.updateMatrix(),u.setMatrixAt(f,g.matrix)}u.matrixAutoUpdate=Ne,u.updateMatrix(),r.push(u)}),n.sort((a,o)=>o-a),n.forEach(a=>t.remove(t.children[a])),r.forEach(a=>{a.parent=t,t.children.push(a)}),t.updateMatrix(),console.log("[Inst] "+n.length+"(out of "+e+") objects instanced to "+r.length+" InstancedMesh")}removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}geometryEquals(t,e){return U.geometriesEqual(t,e)}}class Un{constructor(){p(this,"TIMEOUT","timeout");p(this,"INTERVAL","interval");p(this,"timeoutMap",{});p(this,"intervalMap",{})}run(t=this.INTERVAL,e,i=16.7){const s=Date.now;let r=s(),n=r;const a=Symbol(""),o=()=>{this.setIdMap(a,t,o),n=s(),n-r>=i&&(t===this.intervalMap&&(r=s(),n=r),e(),t===this.TIMEOUT&&this.clearTimeout(a))};return this.setIdMap(a,t,o),a}setIdMap(t,e,i){const s=requestAnimationFrame(i);e===this.INTERVAL?this.intervalMap[t]=s:e===this.TIMEOUT&&(this.timeoutMap[t]=s)}setTimeout(t,e){return this.run(this.TIMEOUT,t,e)}clearTimeout(t){cancelAnimationFrame(this.timeoutMap[t])}setInterval(t,e){return this.run(this.INTERVAL,t,e)}clearInterval(t){cancelAnimationFrame(this.intervalMap[t])}}class Ki{constructor(t){p(this,"buffer");p(this,"u8");this.buffer=t,this.u8=new Uint8Array(t)}getBit(t){var e=this.u8[t>>3],i=t&7;return(e&128>>i)>>7-i}setBit(t,e){var i=t>>3,s=this.u8[i],r=t&7;e?this.u8[i]=s|128>>r:this.u8[i]=s&~(128>>r)}getInt12(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],r=this.u8[e+2],n=t%8,a=8-n,o=Math.min(12-a,8),l=Math.max(12-a-o,0),c=~(255<<a),u=255<<8-o,f=255<<8-l;return i&=c,s&=u,r&=f,((i<<16)+(s<<8)+r>>12-n)-2048}setInt12(t,e){e+=2048;var i=t/8|0,s=t%8,r=e<<12-s,n=(r&16711680)>>16,a=(r&65280)>>8,o=r&255,l=8-s,c=Math.min(12-l,8),u=Math.max(12-l-c,0),f=255<<l;this.u8[i]=(this.u8[i]&f)+n;var m=~(255<<8-c);this.u8[i+1]=(this.u8[i+1]&m)+a;var g=~(255<<8-u);this.u8[i+2]=(this.u8[i+2]&g)+o}getInt6(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],r=t%8,n=8-r,a=Math.max(6-n,0),o=~((255<<n)+(255>>8-(2-r))),l=255<<8-a;return i&=o,s&=l,((i<<8)+s>>10-r)-32}setInt6(t,e){e+=32;var i=t/8|0,s=t%8,r=e<<10-s,n=(r&65280)>>8,a=r&255,o=8-s,l=Math.max(6-o,0),c=(255<<o)+(255>>8-(2-s));this.u8[i]=(this.u8[i]&c)+n;var u=~(255<<8-l);this.u8[i+1]=(this.u8[i+1]&u)+a}test(){var t=new ArrayBuffer(3),e=new Ki(t),i,s;for(i=0;i<12;i++)for(s=-2048;s<2048;s++)if(e.setInt12(i,s),e.getInt12(i)!=s){console.log("12-bit prob at",i,s),console.log("expected",s,"got",e.getInt12(i));break}for(i=0;i<18;i++)for(s=-32;s<32;s++)if(e.setInt6(i,s),e.getInt6(i)!=s){console.log("6-bit prob at",i,s),console.log("expected",s,"got",e.getInt6(i));break}return e}}var ni=(h=>(h[h.NULL=0]="NULL",h[h.POINT=1]="POINT",h[h.POLYLINE=3]="POLYLINE",h[h.POLYGON=5]="POLYGON",h))(ni||{});class Gh{parse(t){var e={},i=new DataView(t),s=0;if(e.fileCode=i.getInt32(s,!1),e.fileCode!=9994)throw new Error("Unknown file code: "+e.fileCode);for(s+=24,e.wordLength=i.getInt32(s,!1),e.byteLength=e.wordLength*2,s+=4,e.version=i.getInt32(s,!0),s+=4,e.shapeType=i.getInt32(s,!0),s+=4,e.minX=i.getFloat64(s,!0),e.minY=i.getFloat64(s+8,!0),e.maxX=i.getFloat64(s+16,!0),e.maxY=i.getFloat64(s+24,!0),e.minZ=i.getFloat64(s+32,!0),e.maxZ=i.getFloat64(s+40,!0),e.minM=i.getFloat64(s+48,!0),e.maxM=i.getFloat64(s+56,!0),s+=64,e.records=[];s<e.byteLength;){var r={};r.number=i.getInt32(s,!1),s+=4,r.length=i.getInt32(s,!1),s+=4;try{r.shape=this.parseShape(i,s,r.length)}catch(n){console.log(n,r)}s+=r.length*2,e.records.push(r)}return e}parseShape(t,e,i){var s=0,r=null,n={};switch(n.type=t.getInt32(e,!0),e+=4,n.type){case 0:break;case 1:n.content={x:t.getFloat64(e,!0),y:t.getFloat64(e+8,!0)};break;case 3:case 5:for(r=n.content={minX:t.getFloat64(e,!0),minY:t.getFloat64(e+8,!0),maxX:t.getFloat64(e+16,!0),maxY:t.getFloat64(e+24,!0),parts:new Int32Array(t.getInt32(e+32,!0)),points:new Float64Array(t.getInt32(e+36,!0)*2)},e+=40,s=0;s<r.parts.length;s++)r.parts[s]=t.getInt32(e,!0),e+=4;for(s=0;s<r.points.length;s++)r.points[s]=t.getFloat64(e,!0),e+=8;break;case 8:case 11:case 13:case 15:case 18:case 21:case 23:case 25:case 28:case 31:throw new Error("Shape type not supported: "+n.type+":"+ +n.type);default:throw new Error("Unknown shape type at "+(e-4)+": "+n.type)}return n}}class qh{constructor(){p(this,"LINE_MATERIAL");p(this,"MESH_MATERIAL");this.LINE_MATERIAL=new d.LineBasicMaterial({color:0,linewidth:2,opacity:.8,transparent:!0}),this.MESH_MATERIAL=new d.MeshBasicMaterial({color:1926655,opacity:.8,transparent:!0})}createModel(t){for(var e=[],i=[],s=0;s<t.records.length;s++){var r=t.records[s].shape;if(r.type===ni.POLYLINE||r.type===ni.POLYGON)for(var n=r.content.points,a=r.content.parts,o=0;o<a.length;o++){const g=[];for(var l=a[o],c=a[o+1]||n.length/2;l<c;l++){var u=n[l*2],f=n[l*2+1];g.push(new d.Vector3(u,f,0))}if(r.type===ni.POLYGON){const x=d.ShapeUtils.triangulateShape(g,[]),y=[];x.forEach(b=>y.push(...b));const T=new d.BufferGeometry;T.setFromPoints(g),T.setIndex(y),e.push(T);const v=new d.BufferGeometry;g.length>2&&!g[0].equals(g[g.length-1])&&g.push(g[0]),v.setFromPoints(g),i.push(v)}else{const x=new d.BufferGeometry;x.setFromPoints(g),i.push(x)}}}for(var m=new d.Object3D,s=0;s<i.length;s++)m.add(new d.Line(i[s],this.LINE_MATERIAL));for(var s=0;s<e.length;s++)m.add(new d.Mesh(e[s],this.MESH_MATERIAL));return console.log("parsed",e.length,i.length),m}loadCompressed(t){for(var e=this.deltaDecode6(t),i=[],s=[],r=0;r<e.length;r++){let u=[];if(e[r]===-32768){for(var n=[],a=1;a<u.length;a++)!(u[a-1].x==u[a].x&&u[a-1].y==u[a].y)&&n.push(u[a]);const f=new d.BufferGeometry;f.setFromPoints(n),i.push(f),u=[];continue}var o=e[r]*180/32767,l=e[r+1]*180/32767;r++,u.push(new d.Vector3(o,l,0))}for(var c=new d.Object3D,r=0;r<s.length;r++)c.add(new d.Line(s[r],this.LINE_MATERIAL));for(var r=0;r<i.length;r++)c.add(new d.Mesh(i[r],this.MESH_MATERIAL));return console.log("parsed compressed",i.length,s.length),c}compress(t){for(var e=[],i=0;i<t.records.length;i++){var s=t.records[i].shape;if(s.type===ni.POLYGON)for(var r=s.content.points,n=s.content.parts,a=0;a<n.length;a++){for(var o=n[a],l=n[a+1]||r.length/2;o<l;o++){var c=r[o*2],u=r[o*2+1];e.push(c/180*32767,u/180*32767)}e.push(-32768)}}var f=new Int16Array(e);console.log("16-bit quantized byteLength",f.buffer.byteLength);var m=this.deltaEncode6(f);return console.log("delta-encoded byteLength",m.byteLength),m}deltaEncode(t){for(var e=[],i=[],s=[],r=0,n=0,a=0,o=0;o<t.length;o++){if(t[o]==-32768){i.push(s),e.push(i),i=[],s=[],a+=3;continue}s.length==0?(r=t[o],n=t[o+1],s.push(r,n),a+=4,o++):Math.abs(r-t[o])>1023||Math.abs(n-t[o+1])>1023?(i.push(s),a+=1,s=[],r=t[o],n=t[o+1],s.push(r,n),a+=4,o++):(s.push((t[o]-r)/8,(t[o+1]-n)/8),r+=((t[o]-r)/8|0)*8,n+=((t[o+1]-n)/8|0)*8,a+=2,o++)}return this.storeDeltas(a,e)}deltaEncode6(t){var e=[],i=[],s=[],r=0,n=0,a=0,o=0;for(a=0;a<t.length;a++)t[a]=0|t[a]/16;for(a=0;a<t.length;a++){if(t[a]===-2048){i.push(s),e.push(i),i=[],s=[],o+=3;continue}s.length==0?(r=t[a],n=t[a+1],s.push(r,n),o+=4,a++):Math.abs(r-t[a])>31||Math.abs(n-t[a+1])>31?(i.push(s),o+=1,s=[],r=t[a],n=t[a+1],s.push(r,n),o+=4,a++):(s.push(t[a]-r,t[a+1]-n),r+=t[a]-r,n+=t[a+1]-n,o+=2,a++)}return this.storeDeltas6(o,e)}storeDeltas(t,e){for(var i=new ArrayBuffer(t),s=new DataView(i),r=0,n=0;n<e.length;n++){for(var a=e[n],o=0;o<a.length;o++){var l=a[o];s.setInt16(r,l[0]),r+=2,s.setInt16(r,l[1]),r+=2;for(var c=2;c<l.length;c++)s.setInt8(r++,l[c]);s.setInt8(r,-128),r+=1}s.setInt16(r,-32768),r+=2}return i}deltaDecode(t){for(var e=new DataView(t),i=0,s=[];i<t.byteLength;){var r=e.getInt16(i);if(i+=2,r===-32768){s.push(-32768);continue}var n=e.getInt16(i);for(i+=2,s.push(r,n);i<t.byteLength;){var a=e.getInt8(i);if(i++,a==-128)break;var o=e.getInt8(i);i++,r+=a*8,n+=o*8,s.push(r,n)}}return s}storeDeltas6(t,e){for(var i=new ArrayBuffer(Math.ceil(t*.75)+4),s=new Ki(i),r=32,n=0;n<e.length;n++){for(var a=e[n],o=0;o<a.length;o++){var l=a[o];s.setInt12(r,l[0]),r+=12,s.setInt12(r,l[1]),r+=12;for(var c=2;c<l.length;c++)s.setInt6(r,l[c]),r+=6;s.setInt6(r,-32),r+=6}s.setInt12(r,-2048),r+=12}return new DataView(i).setUint32(0,r),i}deltaDecode6(t){for(var e=new DataView(t).getUint32(0),i=new Ki(t),s=32,r=[];s<e;){var n=i.getInt12(s);if(s+=12,n===-2048){r.push(-2048);continue}var a=i.getInt12(s);for(s+=12,r.push(n,a);s<e;){var o=i.getInt6(s);if(s+=6,o===-32)break;var l=i.getInt6(s);s+=6,n+=o,a+=l,r.push(n,a)}}for(var c=0;c<r.length;c++)r[c]*=16;return r}}class Wh{async load(t,e,i,s){this.updateProgress(i,0);const r=new XMLHttpRequest;r.responseType="arraybuffer",r.onload=()=>{this.updateProgress(i,50);const n=new Gh,a=n.parse(r.response),o=new qh().createModel(a);this.updateProgress(i,100),e(o)},r.onerror=s,r.open("GET",t),r.send(null)}updateProgress(t,e){if(t){const i={lengthComputable:!0,loaded:e,total:100};t(new ProgressEvent("progress",i))}}}const fi=class fi{constructor(t){p(this,"gltfLoader");p(this,"font");p(this,"manager");this.manager=t}setLoadManager(t){this.manager=t}async loadLocalModel(t,e,i){const s=e.toLowerCase();return s.endsWith("fbx")?this.loadFbx(t,i):s.endsWith("obj")?this.loadObj(t,i):s.endsWith("stl")?this.loadStl(t,i):s.endsWith("ifc")?(S.warn("[LoadingHelper] IFC is not supported directly since three.js r150!"),Promise.reject("Not supported!")):s.endsWith("shp")?this.loadShp(t,i):s.endsWith("dae")?this.loadDae(t,i):s.endsWith("dxf")?this.loadDxf(t,i):s.endsWith("jpg")||s.endsWith("jpeg")||s.endsWith("png")?this.loadImage(t,i):this.loadGltf(t,i)}async loadModel(t,e,i){const s=t;if(!s)return Promise.resolve();let r=e?.toLowerCase()||"";if(!r){const n=s.split("?")[0].toLowerCase();if(n){const a=n.lastIndexOf(".");a!==-1&&(r=n.slice(a+1))}}if(r.endsWith("fbx"))return this.loadFbx(s,i);if(r.endsWith("obj"))return this.loadObj(s,i);if(r.endsWith("stl"))return this.loadStl(s,i);if(r.endsWith("ifc"))S.warn("[LoadingHelper] IFC is not supported directly since three.js r150!");else return r.endsWith("shp")?this.loadShp(s,i):r.endsWith("dae")?this.loadDae(s,i):r.endsWith("dxf")?this.loadDxf(s,i):r.endsWith("jpg")||r.endsWith("jpeg")||r.endsWith("png")?this.loadImage(s,i):this.loadGltf(s,i)}async loadGltf(t,e){const i=this.getGltfLoader();t.indexOf("#")!==-1&&console.warn("[LoadingHelper] '#' is not allowed in filename "+t),t=t.replace(/#/g,encodeURIComponent("#"));const s=n=>{n.total===0&&n.loaded>0||e&&e(n)},r=await i.loadAsync(t,s);return Promise.resolve(r.scene)}parseGltf(t,e,i,s){return this.getGltfLoader().parse(t,e,n=>i(n.scene),s)}async loadFbx(t,e){const i=new _a.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new Ia.OBJLoader(this.manager),s=new Aa.MTLLoader(this.manager),r=t.replace(".obj",".mtl"),n=await s.loadAsync(r,e);n.preload(),i.setMaterials(n);const a=await i.loadAsync(t,e);return Promise.resolve(a)}async loadStl(t,e){const i=new Da.STLLoader(this.manager),s=await i.loadAsync(t,e),r=new d.MeshStandardMaterial({color:11184810,metalness:.1,roughness:.8}),n=new d.Mesh(s,r);return Promise.resolve(n)}async loadShp(t,e){const i=new Wh;return new Promise((s,r)=>{i.load(t,n=>{s(n)},e,n=>{r(n)})})}async loadDae(t,e){const i=new Oa.ColladaLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s.scene)}async load3dm(t,e){return Promise.reject("3dm format is not supported since three.js r159 (Rhino3dmLoader removed)")}async loadDxf(t,e){this.font||console.warn("[LoadingHelper] Should set font first!");const i={ignorePaperSpace:!0,enableLocalCache:!1,overrideHatchPatternLineThickness:2},s=new Y(this.manager,i);s.setFont(this.font),await this.font?.getFontFromIndexeddb();try{const r=await s.loadAsync(t,e);return Promise.resolve(r.threejsObject)}catch{const n=new ErrorEvent("");return Promise.reject(n)}}async loadPly(t,e){const i=new ka.PLYLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(new d.Mesh(s))}async loadImage(t,e){const i=new d.TextureLoader(this.manager),s=await i.loadAsync(t,e);if(!s)return Promise.reject("Failed to load image!");const r=10,n=s.image;let a=n&&n.height||r,o=n&&n.width||r;a=r/o*a,o=r;const l=new d.MeshBasicMaterial({map:s,side:d.DoubleSide,transparent:!0}),c=new d.PlaneGeometry(o,a),u=new d.Mesh(c,l);return Promise.resolve(u)}async loadDxfData(t,e,i,s,r){this.font||console.warn("[LoadingHelper] Should set font first!");const n=new Y(this.manager,r);return n.setFont(this.font),await this.font?.getFontFromIndexeddb(),n.manager.onLoad=()=>{s&&s()},n.loadEx(t,e,i)}setFont(t){this.font=t}static setDracoDecoderPath(t){this.DecoderPath=t}static setRhino3dmLibraryPath(t){this.Rhino3dmLibraryPath=t}getGltfLoader(){if(!this.gltfLoader){this.gltfLoader=new Pa.GLTFLoader(this.manager);const t=new Ea.DRACOLoader(this.manager);t.setDecoderPath(fi.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};p(fi,"DecoderPath","libs/draco/gltf/"),p(fi,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let ut=fi;const Hn=`(function(){"use strict";function Ks(f){for(let t=f.length-1;t>=0;--t)if(f[t]>=65535)return!0;return!1}function ms(f){return document.createElementNS("http://www.w3.org/1999/xhtml",f)}const ps={};function xs(f){const t=f[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=f[1];e&&e.isStackTrace?f[0]+=" "+e.getLocation():f[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return f}function yt(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...f)}}function Ut(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...f)}}function yi(...f){const t=f.join(" ");t in ps||(ps[t]=!0,yt(...f))}class Ve{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const s=i[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t);t.target=null}}}const $=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function Re(){const f=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return($[f&255]+$[f>>8&255]+$[f>>16&255]+$[f>>24&255]+"-"+$[t&255]+$[t>>8&255]+"-"+$[t>>16&15|64]+$[t>>24&255]+"-"+$[e&63|128]+$[e>>8&255]+"-"+$[e>>16&255]+$[e>>24&255]+$[i&255]+$[i>>8&255]+$[i>>16&255]+$[i>>24&255]).toLowerCase()}function V(f,t,e){return Math.max(t,Math.min(e,f))}function me(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return f/4294967295;case Uint16Array:return f/65535;case Uint8Array:case Uint8ClampedArray:return f/255;case Int32Array:return Math.max(f/2147483647,-1);case Int16Array:return Math.max(f/32767,-1);case Int8Array:return Math.max(f/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function K(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return Math.round(f*4294967295);case Uint16Array:return Math.round(f*65535);case Uint8Array:case Uint8ClampedArray:return Math.round(f*255);case Int32Array:return Math.round(f*2147483647);case Int16Array:return Math.round(f*32767);case Int8Array:return Math.round(f*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const hs=class hs{constructor(t=0,e=0){this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("THREE.Vector2: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};hs.prototype.isVector2=!0;let Y=hs;class pe{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],c=i[s+1],h=i[s+2],u=i[s+3],l=n[r+0],d=n[r+1],y=n[r+2],m=n[r+3];if(u!==m||o!==l||c!==d||h!==y){let z=o*l+c*d+h*y+u*m;z<0&&(l=-l,d=-d,y=-y,m=-m,z=-z);let b=1-a;if(z<.9995){const p=Math.acos(z),x=Math.sin(p);b=Math.sin(b*p)/x,a=Math.sin(a*p)/x,o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a}else{o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a;const p=1/Math.sqrt(o*o+c*c+h*h+u*u);o*=p,c*=p,h*=p,u*=p}}t[e]=o,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],c=i[s+2],h=i[s+3],u=n[r],l=n[r+1],d=n[r+2],y=n[r+3];return t[e]=a*y+h*u+o*d-c*l,t[e+1]=o*y+h*l+c*u-a*d,t[e+2]=c*y+h*d+a*l-o*u,t[e+3]=h*y-a*u-o*l-c*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,c=a(i/2),h=a(s/2),u=a(n/2),l=o(i/2),d=o(s/2),y=o(n/2);switch(r){case"XYZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"YXZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"ZXY":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"ZYX":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"YZX":this._x=l*h*u+c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u-l*d*y;break;case"XZY":this._x=l*h*u-c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u+l*d*y;break;default:yt("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],c=e[2],h=e[6],u=e[10],l=i+a+u;if(l>0){const d=.5/Math.sqrt(l+1);this._w=.25/d,this._x=(h-o)*d,this._y=(n-c)*d,this._z=(r-s)*d}else if(i>a&&i>u){const d=2*Math.sqrt(1+i-a-u);this._w=(h-o)/d,this._x=.25*d,this._y=(s+r)/d,this._z=(n+c)/d}else if(a>u){const d=2*Math.sqrt(1+a-i-u);this._w=(n-c)/d,this._x=(s+r)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+u-i-a);this._w=(r-s)/d,this._x=(n+c)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(V(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,c=e._z,h=e._w;return this._x=i*h+r*a+s*c-n*o,this._y=s*h+r*o+n*a-i*c,this._z=n*h+r*c+i*o-s*a,this._w=r*h-i*a-s*o-n*c,this._onChangeCallback(),this}slerp(t,e){let i=t._x,s=t._y,n=t._z,r=t._w,a=this.dot(t);a<0&&(i=-i,s=-s,n=-n,r=-r,a=-a);let o=1-e;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);o=Math.sin(o*c)/h,e=Math.sin(e*c)/h,this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this._onChangeCallback()}else this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}const ls=class ls{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("THREE.Vector3: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(gs.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(gs.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,c=2*(r*s-a*i),h=2*(a*e-n*s),u=2*(n*i-r*e);return this.x=e+o*c+r*u-a*h,this.y=i+o*h+a*c-n*u,this.z=s+o*u+n*h-r*c,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return mi.copy(this).projectOnVector(t),this.sub(mi)}reflect(t){return this.sub(mi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};ls.prototype.isVector3=!0;let S=ls;const mi=new S,gs=new pe,us=class us{constructor(t,e,i,s,n,r,a,o,c){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c)}set(t,e,i,s,n,r,a,o,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],c=i[1],h=i[4],u=i[7],l=i[2],d=i[5],y=i[8],m=s[0],z=s[3],b=s[6],p=s[1],x=s[4],g=s[7],w=s[2],B=s[5],_=s[8];return n[0]=r*m+a*p+o*w,n[3]=r*z+a*x+o*B,n[6]=r*b+a*g+o*_,n[1]=c*m+h*p+u*w,n[4]=c*z+h*x+u*B,n[7]=c*b+h*g+u*_,n[2]=l*m+d*p+y*w,n[5]=l*z+d*x+y*B,n[8]=l*b+d*g+y*_,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8];return e*r*h-e*a*c-i*n*h+i*a*o+s*n*c-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=h*r-a*c,l=a*o-h*n,d=c*n-r*o,y=e*u+i*l+s*d;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/y;return t[0]=u*m,t[1]=(s*c-h*i)*m,t[2]=(a*i-s*r)*m,t[3]=l*m,t[4]=(h*e-s*o)*m,t[5]=(s*n-a*e)*m,t[6]=d*m,t[7]=(i*o-c*e)*m,t[8]=(r*e-i*n)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const o=Math.cos(n),c=Math.sin(n);return this.set(i*o,i*c,-i*(o*r+c*a)+r+t,-s*c,s*o,-s*(-c*r+o*a)+a+e,0,0,1),this}scale(t,e){return yi("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(pi.makeScale(t,e)),this}rotate(t){return yi("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(pi.makeRotation(-t)),this}translate(t,e){return yi("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(pi.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}};us.prototype.isMatrix3=!0;let xt=us;const pi=new xt;function xi(f){return f<.04045?f*.0773993808:Math.pow(f*.9478672986+.0521327014,2.4)}let Zt;class tn{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{Zt===void 0&&(Zt=ms("canvas")),Zt.width=t.width,Zt.height=t.height;const s=Zt.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),i=Zt}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=ms("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r<n.length;r++)n[r]=xi(n[r]/255)*255;return i.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(xi(e[i]/255)*255):e[i]=xi(e[i]);return{data:e,width:t.width,height:t.height}}else return yt("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let en=0;class sn{constructor(t=null){this.isTextureSource=!0,Object.defineProperty(this,"id",{value:en++}),this.uuid=Re(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let n;if(Array.isArray(s)){n=[];for(let r=0,a=s.length;r<a;r++)s[r].isDataTexture?n.push(gi(s[r].image)):n.push(gi(s[r]))}else n=gi(s);i.url=n}return e||(t.images[this.uuid]=i),i}}function gi(f){return typeof HTMLImageElement<"u"&&f instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&f instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&f instanceof ImageBitmap?tn.getDataURL(f):f.data?{data:Array.from(f.data),width:f.width,height:f.height,type:f.data.constructor.name}:(yt("Texture: Unable to serialize Texture."),{})}let nn=0;const wi=new S;class Nt extends Ve{constructor(t=Nt.DEFAULT_IMAGE,e=Nt.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,c=Nt.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:nn++}),this.uuid=Re(),this.name="",this.source=new sn(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=o,this.offset=new Y(0,0),this.repeat=new Y(1,1),this.center=new Y(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new xt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(wi).x}get height(){return this.source.getSize(wi).y}get depth(){return this.source.getSize(wi).z}get image(){return this.source.data}set image(t){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.normalized=t.normalized,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){yt(\`Texture.setValues(): parameter '\${e}' has value of undefined.\`);continue}const s=this[e];if(s===void 0){yt(\`Texture.setValues(): property '\${e}' does not exist.\`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Nt.DEFAULT_IMAGE=null,Nt.DEFAULT_MAPPING=300,Nt.DEFAULT_ANISOTROPY=1;const fs=class fs{constructor(t=0,e=0,i=0,s=1){this.x=t,this.y=e,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("THREE.Vector4: index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,s,n;const o=t.elements,c=o[0],h=o[4],u=o[8],l=o[1],d=o[5],y=o[9],m=o[2],z=o[6],b=o[10];if(Math.abs(h-l)<.01&&Math.abs(u-m)<.01&&Math.abs(y-z)<.01){if(Math.abs(h+l)<.1&&Math.abs(u+m)<.1&&Math.abs(y+z)<.1&&Math.abs(c+d+b-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,g=(d+1)/2,w=(b+1)/2,B=(h+l)/4,_=(u+m)/4,M=(y+z)/4;return x>g&&x>w?x<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(x),s=B/i,n=_/i):g>w?g<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(g),i=B/s,n=M/s):w<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(w),i=_/n,s=M/n),this.set(i,s,n,e),this}let p=Math.sqrt((z-y)*(z-y)+(u-m)*(u-m)+(l-h)*(l-h));return Math.abs(p)<.001&&(p=1),this.x=(z-y)/p,this.y=(u-m)/p,this.z=(l-h)/p,this.w=Math.acos((c+d+b-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this.w=V(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this.w=V(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};fs.prototype.isVector4=!0;let xe=fs;const ui=class ui{constructor(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z)}set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){const b=this.elements;return b[0]=t,b[4]=e,b[8]=i,b[12]=s,b[1]=n,b[5]=r,b[9]=a,b[13]=o,b[2]=c,b[6]=h,b[10]=u,b[14]=l,b[3]=d,b[7]=y,b[11]=m,b[15]=z,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new ui().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,s=1/$t.setFromMatrixColumn(t,0).length(),n=1/$t.setFromMatrixColumn(t,1).length(),r=1/$t.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),c=Math.sin(s),h=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=-o*u,e[8]=c,e[1]=d+y*c,e[5]=l-m*c,e[9]=-a*o,e[2]=m-l*c,e[6]=y+d*c,e[10]=r*o}else if(t.order==="YXZ"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l+m*a,e[4]=y*a-d,e[8]=r*c,e[1]=r*u,e[5]=r*h,e[9]=-a,e[2]=d*a-y,e[6]=m+l*a,e[10]=r*o}else if(t.order==="ZXY"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l-m*a,e[4]=-r*u,e[8]=y+d*a,e[1]=d+y*a,e[5]=r*h,e[9]=m-l*a,e[2]=-r*c,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=y*c-d,e[8]=l*c+m,e[1]=o*u,e[5]=m*c+l,e[9]=d*c-y,e[2]=-c,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=m-l*u,e[8]=y*u+d,e[1]=u,e[5]=r*h,e[9]=-a*h,e[2]=-c*h,e[6]=d*u+y,e[10]=l-m*u}else if(t.order==="XZY"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=-u,e[8]=c*h,e[1]=l*u+m,e[5]=r*h,e[9]=d*u-y,e[2]=y*u-d,e[6]=a*h,e[10]=m*u+l}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(rn,t,on)}lookAt(t,e,i){const s=this.elements;return et.subVectors(t,e),et.lengthSq()===0&&(et.z=1),et.normalize(),Pt.crossVectors(i,et),Pt.lengthSq()===0&&(Math.abs(i.z)===1?et.x+=1e-4:et.z+=1e-4,et.normalize(),Pt.crossVectors(i,et)),Pt.normalize(),ke.crossVectors(et,Pt),s[0]=Pt.x,s[4]=ke.x,s[8]=et.x,s[1]=Pt.y,s[5]=ke.y,s[9]=et.y,s[2]=Pt.z,s[6]=ke.z,s[10]=et.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],c=i[12],h=i[1],u=i[5],l=i[9],d=i[13],y=i[2],m=i[6],z=i[10],b=i[14],p=i[3],x=i[7],g=i[11],w=i[15],B=s[0],_=s[4],M=s[8],P=s[12],A=s[1],C=s[5],T=s[9],E=s[13],I=s[2],F=s[6],R=s[10],Z=s[14],tt=s[3],dt=s[7],at=s[11],pt=s[15];return n[0]=r*B+a*A+o*I+c*tt,n[4]=r*_+a*C+o*F+c*dt,n[8]=r*M+a*T+o*R+c*at,n[12]=r*P+a*E+o*Z+c*pt,n[1]=h*B+u*A+l*I+d*tt,n[5]=h*_+u*C+l*F+d*dt,n[9]=h*M+u*T+l*R+d*at,n[13]=h*P+u*E+l*Z+d*pt,n[2]=y*B+m*A+z*I+b*tt,n[6]=y*_+m*C+z*F+b*dt,n[10]=y*M+m*T+z*R+b*at,n[14]=y*P+m*E+z*Z+b*pt,n[3]=p*B+x*A+g*I+w*tt,n[7]=p*_+x*C+g*F+w*dt,n[11]=p*M+x*T+g*R+w*at,n[15]=p*P+x*E+g*Z+w*pt,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],c=t[13],h=t[2],u=t[6],l=t[10],d=t[14],y=t[3],m=t[7],z=t[11],b=t[15],p=o*d-c*l,x=a*d-c*u,g=a*l-o*u,w=r*d-c*h,B=r*l-o*h,_=r*u-a*h;return e*(m*p-z*x+b*g)-i*(y*p-z*w+b*B)+s*(y*x-m*w+b*_)-n*(y*g-m*B+z*_)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[1],r=t[5],a=t[9],o=t[2],c=t[6],h=t[10];return e*(r*h-a*c)-i*(n*h-a*o)+s*(n*c-r*o)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=t[9],l=t[10],d=t[11],y=t[12],m=t[13],z=t[14],b=t[15],p=e*a-i*r,x=e*o-s*r,g=e*c-n*r,w=i*o-s*a,B=i*c-n*a,_=s*c-n*o,M=h*m-u*y,P=h*z-l*y,A=h*b-d*y,C=u*z-l*m,T=u*b-d*m,E=l*b-d*z,I=p*E-x*T+g*C+w*A-B*P+_*M;if(I===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const F=1/I;return t[0]=(a*E-o*T+c*C)*F,t[1]=(s*T-i*E-n*C)*F,t[2]=(m*_-z*B+b*w)*F,t[3]=(l*B-u*_-d*w)*F,t[4]=(o*A-r*E-c*P)*F,t[5]=(e*E-s*A+n*P)*F,t[6]=(z*g-y*_-b*x)*F,t[7]=(h*_-l*g+d*x)*F,t[8]=(r*T-a*A+c*M)*F,t[9]=(i*A-e*T-n*M)*F,t[10]=(y*B-m*g+b*p)*F,t[11]=(u*g-h*B-d*p)*F,t[12]=(a*P-r*C-o*M)*F,t[13]=(e*C-i*P+s*M)*F,t[14]=(m*x-y*w-z*p)*F,t[15]=(h*w-u*x+l*p)*F,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,c=n*r,h=n*a;return this.set(c*r+i,c*a-s*o,c*o+s*a,0,c*a+s*o,h*a+i,h*o-s*r,0,c*o-s*a,h*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,c=n+n,h=r+r,u=a+a,l=n*c,d=n*h,y=n*u,m=r*h,z=r*u,b=a*u,p=o*c,x=o*h,g=o*u,w=i.x,B=i.y,_=i.z;return s[0]=(1-(m+b))*w,s[1]=(d+g)*w,s[2]=(y-x)*w,s[3]=0,s[4]=(d-g)*B,s[5]=(1-(l+b))*B,s[6]=(z+p)*B,s[7]=0,s[8]=(y+x)*_,s[9]=(z-p)*_,s[10]=(1-(l+m))*_,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;t.x=s[12],t.y=s[13],t.z=s[14];const n=this.determinantAffine();if(n===0)return i.set(1,1,1),e.identity(),this;let r=$t.set(s[0],s[1],s[2]).length();const a=$t.set(s[4],s[5],s[6]).length(),o=$t.set(s[8],s[9],s[10]).length();n<0&&(r=-r),ct.copy(this);const c=1/r,h=1/a,u=1/o;return ct.elements[0]*=c,ct.elements[1]*=c,ct.elements[2]*=c,ct.elements[4]*=h,ct.elements[5]*=h,ct.elements[6]*=h,ct.elements[8]*=u,ct.elements[9]*=u,ct.elements[10]*=u,e.setFromRotationMatrix(ct),i.x=r,i.y=a,i.z=o,this}makePerspective(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2*n/(e-t),u=2*n/(i-s),l=(e+t)/(e-t),d=(i+s)/(i-s);let y,m;if(o)y=n/(r-n),m=r*n/(r-n);else if(a===2e3)y=-(r+n)/(r-n),m=-2*r*n/(r-n);else if(a===2001)y=-r/(r-n),m=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=u,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2/(e-t),u=2/(i-s),l=-(e+t)/(e-t),d=-(i+s)/(i-s);let y,m;if(o)y=1/(r-n),m=r/(r-n);else if(a===2e3)y=-2/(r-n),m=-(r+n)/(r-n);else if(a===2001)y=-1/(r-n),m=-n/(r-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=l,c[1]=0,c[5]=u,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}};ui.prototype.isMatrix4=!0;let H=ui;const $t=new S,ct=new H,rn=new S(0,0,0),on=new S(1,1,1),Pt=new S,ke=new S,et=new S,ws=new H,bs=new pe;class Ue{constructor(t=0,e=0,i=0,s=Ue.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],c=s[5],h=s[9],u=s[2],l=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(V(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(l,c),this._z=0);break;case"YXZ":this._x=Math.asin(-V(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,c)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(V(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-V(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(l,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(V(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-V(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(l,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,d),this._y=0);break;default:yt("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return ws.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ws,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return bs.setFromEuler(this),this.setFromQuaternion(bs,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ue.DEFAULT_ORDER="XYZ";class an{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let cn=0;const zs=new S,Jt=new pe,gt=new H,Ne=new S,ge=new S,hn=new S,ln=new pe,_s=new S(1,0,0),Ms=new S(0,1,0),As=new S(0,0,1),Ss={type:"added"},un={type:"removed"},Gt={type:"childadded",child:null},bi={type:"childremoved",child:null};class Ct extends Ve{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:cn++}),this.uuid=Re(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ct.DEFAULT_UP.clone();const t=new S,e=new Ue,i=new pe,s=new S(1,1,1);function n(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(n),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new H},normalMatrix:{value:new xt}}),this.matrix=new H,this.matrixWorld=new H,this.matrixAutoUpdate=Ct.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new an,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.multiply(Jt),this}rotateOnWorldAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.premultiply(Jt),this}rotateX(t){return this.rotateOnAxis(_s,t)}rotateY(t){return this.rotateOnAxis(Ms,t)}rotateZ(t){return this.rotateOnAxis(As,t)}translateOnAxis(t,e){return zs.copy(t).applyQuaternion(this.quaternion),this.position.add(zs.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(_s,t)}translateY(t){return this.translateOnAxis(Ms,t)}translateZ(t){return this.translateOnAxis(As,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(gt.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ne.copy(t):Ne.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),ge.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?gt.lookAt(ge,Ne,this.up):gt.lookAt(Ne,ge,this.up),this.quaternion.setFromRotationMatrix(gt),s&&(gt.extractRotation(s.matrixWorld),Jt.setFromRotationMatrix(gt),this.quaternion.premultiply(Jt.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Ut("Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.child=null):Ut("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(un),bi.child=t,this.dispatchEvent(bi),bi.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),gt.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),gt.multiply(t.parent.matrixWorld)),t.applyMatrix4(gt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,s=this.children.length;i<s;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,t,hn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,ln,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}intersectsFrustum(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,s=t.z,n=this.matrix.elements;n[12]+=e-n[0]*e-n[4]*i-n[8]*s,n[13]+=i-n[1]*e-n[5]*i-n[9]*s,n[14]+=s-n[2]*e-n[6]*i-n[10]*s}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const s=this.parent;if(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),e===!0){const n=this.children;for(let r=0,a=n.length;r<a;r++)n[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,s.name=this.name,s.castShadow=this.castShadow,s.receiveShadow=this.receiveShadow,s.visible=this.visible,s.frustumCulled=this.frustumCulled,s.renderOrder=this.renderOrder,s.static=this.static,s.matrixAutoUpdate=this.matrixAutoUpdate,Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(a=>({...a})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(t),s.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let c=0,h=o.length;c<h;c++){const u=o[c];n(t.shapes,u)}else n(t.shapes,o)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let o=0,c=this.material.length;o<c;o++)a.push(n(t.materials,this.material[o]));s.material=a}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let a=0;a<this.children.length;a++)s.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let a=0;a<this.animations.length;a++){const o=this.animations[a];s.animations.push(n(t.animations,o))}}if(e){const a=r(t.geometries),o=r(t.materials),c=r(t.textures),h=r(t.images),u=r(t.shapes),l=r(t.skeletons),d=r(t.animations),y=r(t.nodes);a.length>0&&(i.geometries=a),o.length>0&&(i.materials=o),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),l.length>0&&(i.skeletons=l),d.length>0&&(i.animations=d),y.length>0&&(i.nodes=y)}return i.object=s,i;function r(a){const o=[];for(const c in a){const h=a[c];delete h.metadata,o.push(h)}return o}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.pivot=t.pivot!==null?t.pivot.clone():null,this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}dispose(){this.dispatchEvent({type:"dispose"})}}Ct.DEFAULT_UP=new S(0,1,0),Ct.DEFAULT_MATRIX_AUTO_UPDATE=!0,Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ht=new S,wt=new S,zi=new S,bt=new S,Qt=new S,jt=new S,Bs=new S,_i=new S,Mi=new S,Ai=new S,Si=new xe,Bi=new xe,Ti=new xe;class st{constructor(t=new S,e=new S,i=new S){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),ht.subVectors(t,e),s.cross(ht);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){ht.subVectors(s,e),wt.subVectors(i,e),zi.subVectors(t,e);const r=ht.dot(ht),a=ht.dot(wt),o=ht.dot(zi),c=wt.dot(wt),h=wt.dot(zi),u=r*c-a*a;if(u===0)return n.set(0,0,0),null;const l=1/u,d=(c*o-a*h)*l,y=(r*h-a*o)*l;return n.set(1-d-y,y,d)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,bt)===null?!1:bt.x>=0&&bt.y>=0&&bt.x+bt.y<=1}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,bt)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,bt.x),o.addScaledVector(r,bt.y),o.addScaledVector(a,bt.z),o)}static getInterpolatedAttribute(t,e,i,s,n,r){return Si.setScalar(0),Bi.setScalar(0),Ti.setScalar(0),Si.fromBufferAttribute(t,e),Bi.fromBufferAttribute(t,i),Ti.fromBufferAttribute(t,s),r.setScalar(0),r.addScaledVector(Si,n.x),r.addScaledVector(Bi,n.y),r.addScaledVector(Ti,n.z),r}static isFrontFacing(t,e,i,s){return ht.subVectors(i,e),wt.subVectors(t,e),ht.cross(wt).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return ht.subVectors(this.c,this.b),wt.subVectors(this.a,this.b),ht.cross(wt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return st.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return st.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,s,n){return st.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return st.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return st.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;Qt.subVectors(s,i),jt.subVectors(n,i),_i.subVectors(t,i);const o=Qt.dot(_i),c=jt.dot(_i);if(o<=0&&c<=0)return e.copy(i);Mi.subVectors(t,s);const h=Qt.dot(Mi),u=jt.dot(Mi);if(h>=0&&u<=h)return e.copy(s);const l=o*u-h*c;if(l<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(Qt,r);Ai.subVectors(t,n);const d=Qt.dot(Ai),y=jt.dot(Ai);if(y>=0&&d<=y)return e.copy(n);const m=d*c-o*y;if(m<=0&&c>=0&&y<=0)return a=c/(c-y),e.copy(i).addScaledVector(jt,a);const z=h*y-d*u;if(z<=0&&u-h>=0&&d-y>=0)return Bs.subVectors(n,s),a=(u-h)/(u-h+(d-y)),e.copy(s).addScaledVector(Bs,a);const b=1/(z+m+l);return r=m*b,a=l*b,e.copy(i).addScaledVector(Qt,r).addScaledVector(jt,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Q{constructor(t=new S(1/0,1/0,1/0),e=new S(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(lt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(lt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=lt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const i=t.geometry;if(i!==void 0){const n=i.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,lt):lt.fromBufferAttribute(n,r),lt.applyMatrix4(t.matrixWorld),this.expandByPoint(lt);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Le.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Le.copy(i.boundingBox)),Le.applyMatrix4(t.matrixWorld),this.union(Le)}const s=t.children;for(let n=0,r=s.length;n<r;n++)this.expandByObject(s[n],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,lt),lt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(we),De.subVectors(this.max,we),Kt.subVectors(t.a,we),te.subVectors(t.b,we),ee.subVectors(t.c,we),Et.subVectors(te,Kt),It.subVectors(ee,te),Lt.subVectors(Kt,ee);let e=[0,-Et.z,Et.y,0,-It.z,It.y,0,-Lt.z,Lt.y,Et.z,0,-Et.x,It.z,0,-It.x,Lt.z,0,-Lt.x,-Et.y,Et.x,0,-It.y,It.x,0,-Lt.y,Lt.x,0];return!Pi(e,Kt,te,ee,De)||(e=[1,0,0,0,1,0,0,0,1],!Pi(e,Kt,te,ee,De))?!1:(qe.crossVectors(Et,It),e=[qe.x,qe.y,qe.z],Pi(e,Kt,te,ee,De))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,lt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(lt).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(zt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),zt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),zt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),zt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),zt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),zt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),zt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),zt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(zt),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const zt=[new S,new S,new S,new S,new S,new S,new S,new S],lt=new S,Le=new Q,Kt=new S,te=new S,ee=new S,Et=new S,It=new S,Lt=new S,we=new S,De=new S,qe=new S,Dt=new S;function Pi(f,t,e,i,s){for(let n=0,r=f.length-3;n<=r;n+=3){Dt.fromArray(f,n);const a=s.x*Math.abs(Dt.x)+s.y*Math.abs(Dt.y)+s.z*Math.abs(Dt.z),o=t.dot(Dt),c=e.dot(Dt),h=i.dot(Dt);if(Math.max(-Math.max(o,c,h),Math.min(o,c,h))>a)return!1}return!0}const L=new S,ve=new Y;let fn=0;class mt extends Ve{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:fn++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)ve.fromBufferAttribute(this,e),ve.applyMatrix3(t),this.setXY(e,ve.x,ve.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix3(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix4(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyNormalMatrix(t),this.setXYZ(e,L.x,L.y,L.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.transformDirection(t),this.setXYZ(e,L.x,L.y,L.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=me(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=K(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=me(e,this.array)),e}setX(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=me(e,this.array)),e}setY(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=me(e,this.array)),e}setZ(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=me(e,this.array)),e}setW(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array),n=K(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return t.name=this.name,t.usage=this.usage,t.gpuType=this.gpuType,t}dispose(){this.dispatchEvent({type:"dispose"})}}class dn extends mt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class yn extends mt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class mn extends mt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const pn=new Q,be=new S,Ci=new S;class xn{constructor(t=new S,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;e!==void 0?i.copy(e):pn.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;n<r;n++)s=Math.max(s,i.distanceToSquared(t[n]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;be.subVectors(t,this.center);const e=be.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(be,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Ci.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(be.copy(t.center).add(Ci)),this.expandByPoint(be.copy(t.center).sub(Ci))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let gn=0;const nt=new H,Ei=new Ct,ie=new S,it=new Q,ze=new Q,W=new S;class Ii extends Ve{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:gn++}),this.uuid=Re(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Ks(t)?yn:dn)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const n=new xt().getNormalMatrix(t);i.applyNormalMatrix(n),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return nt.makeRotationFromQuaternion(t),this.applyMatrix4(nt),this}rotateX(t){return nt.makeRotationX(t),this.applyMatrix4(nt),this}rotateY(t){return nt.makeRotationY(t),this.applyMatrix4(nt),this}rotateZ(t){return nt.makeRotationZ(t),this.applyMatrix4(nt),this}translate(t,e,i){return nt.makeTranslation(t,e,i),this.applyMatrix4(nt),this}scale(t,e,i){return nt.makeScale(t,e,i),this.applyMatrix4(nt),this}lookAt(t){return Ei.lookAt(t),Ei.updateMatrix(),this.applyMatrix4(Ei.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ie).negate(),this.translate(ie.x,ie.y,ie.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let s=0,n=t.length;s<n;s++){const r=t[s];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new mn(i,3))}else{const i=Math.min(t.length,e.count);for(let s=0;s<i;s++){const n=t[s];e.setXYZ(s,n.x,n.y,n.z||0)}t.length>e.count&&yt("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Q);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new S(-1/0,-1/0,-1/0),new S(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i<s;i++){const n=e[i];it.setFromBufferAttribute(n),this.morphTargetsRelative?(W.addVectors(this.boundingBox.min,it.min),this.boundingBox.expandByPoint(W),W.addVectors(this.boundingBox.max,it.max),this.boundingBox.expandByPoint(W)):(this.boundingBox.expandByPoint(it.min),this.boundingBox.expandByPoint(it.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ut('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new xn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new S,1/0);return}if(t){const i=this.boundingSphere.center;if(it.setFromBufferAttribute(t),e)for(let n=0,r=e.length;n<r;n++){const a=e[n];ze.setFromBufferAttribute(a),this.morphTargetsRelative?(W.addVectors(it.min,ze.min),it.expandByPoint(W),W.addVectors(it.max,ze.max),it.expandByPoint(W)):(it.expandByPoint(ze.min),it.expandByPoint(ze.max))}it.getCenter(i);let s=0;for(let n=0,r=t.count;n<r;n++)W.fromBufferAttribute(t,n),s=Math.max(s,i.distanceToSquared(W));if(e)for(let n=0,r=e.length;n<r;n++){const a=e[n],o=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)W.fromBufferAttribute(a,c),o&&(ie.fromBufferAttribute(t,c),W.add(ie)),s=Math.max(s,i.distanceToSquared(W))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&Ut('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Ut("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,s=e.normal,n=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new mt(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const a=[],o=[];for(let M=0;M<i.count;M++)a[M]=new S,o[M]=new S;const c=new S,h=new S,u=new S,l=new Y,d=new Y,y=new Y,m=new S,z=new S;function b(M,P,A){c.fromBufferAttribute(i,M),h.fromBufferAttribute(i,P),u.fromBufferAttribute(i,A),l.fromBufferAttribute(n,M),d.fromBufferAttribute(n,P),y.fromBufferAttribute(n,A),h.sub(c),u.sub(c),d.sub(l),y.sub(l);const C=1/(d.x*y.y-y.x*d.y);isFinite(C)&&(m.copy(h).multiplyScalar(y.y).addScaledVector(u,-d.y).multiplyScalar(C),z.copy(u).multiplyScalar(d.x).addScaledVector(h,-y.x).multiplyScalar(C),a[M].add(m),a[P].add(m),a[A].add(m),o[M].add(z),o[P].add(z),o[A].add(z))}let p=this.groups;p.length===0&&(p=[{start:0,count:t.count}]);for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)b(t.getX(E+0),t.getX(E+1),t.getX(E+2))}const x=new S,g=new S,w=new S,B=new S;function _(M){w.fromBufferAttribute(s,M),B.copy(w);const P=a[M];x.copy(P),x.sub(w.multiplyScalar(w.dot(P))).normalize(),g.crossVectors(B,P);const C=g.dot(o[M])<0?-1:1;r.setXYZW(M,x.x,x.y,x.z,C)}for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)_(t.getX(E+0)),_(t.getX(E+1)),_(t.getX(E+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new mt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let l=0,d=i.count;l<d;l++)i.setXYZ(l,0,0,0);const s=new S,n=new S,r=new S,a=new S,o=new S,c=new S,h=new S,u=new S;if(t)for(let l=0,d=t.count;l<d;l+=3){const y=t.getX(l+0),m=t.getX(l+1),z=t.getX(l+2);s.fromBufferAttribute(e,y),n.fromBufferAttribute(e,m),r.fromBufferAttribute(e,z),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),a.fromBufferAttribute(i,y),o.fromBufferAttribute(i,m),c.fromBufferAttribute(i,z),a.add(h),o.add(h),c.add(h),i.setXYZ(y,a.x,a.y,a.z),i.setXYZ(m,o.x,o.y,o.z),i.setXYZ(z,c.x,c.y,c.z)}else for(let l=0,d=e.count;l<d;l+=3)s.fromBufferAttribute(e,l+0),n.fromBufferAttribute(e,l+1),r.fromBufferAttribute(e,l+2),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),i.setXYZ(l+0,h.x,h.y,h.z),i.setXYZ(l+1,h.x,h.y,h.z),i.setXYZ(l+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)W.fromBufferAttribute(t,e),W.normalize(),t.setXYZ(e,W.x,W.y,W.z)}toNonIndexed(){function t(a,o){const c=a.array,h=a.itemSize,u=a.normalized,l=new c.constructor(o.length*h);let d=0,y=0;for(let m=0,z=o.length;m<z;m++){a.isInterleavedBufferAttribute?d=o[m]*a.data.stride+a.offset:d=o[m]*h;for(let b=0;b<h;b++)l[y++]=c[d++]}return new mt(l,h,u)}if(this.index===null)return yt("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Ii,i=this.index.array,s=this.attributes;for(const a in s){const o=s[a],c=t(o,i);e.setAttribute(a,c)}const n=this.morphAttributes;for(const a in n){const o=[],c=n[a];for(let h=0,u=c.length;h<u;h++){const l=c[h],d=t(l,i);o.push(d)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,o=r.length;a<o;a++){const c=r[a];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,t.name=this.name,Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const o=this.parameters;for(const c in o)o[c]!==void 0&&(t[c]=o[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const c=i[o];t.data.attributes[o]=c.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const c=this.morphAttributes[o],h=[];for(let u=0,l=c.length;u<l;u++){const d=c[u];h.push(d.toJSON(t.data))}h.length>0&&(s[o]=h,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone());const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const n=t.morphAttributes;for(const c in n){const h=[],u=n[c];for(let l=0,d=u.length;l<d;l++)h.push(u[l].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let c=0,h=r.length;c<h;c++){const u=r[c];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Fi=new S,wn=new S,bn=new xt;class Ts{constructor(t=new S(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=Fi.subVectors(i,e).cross(wn.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e,i=!0){const s=t.delta(Fi),n=this.normal.dot(s);if(n===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/n;return i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||bn.getNormalMatrix(t),s=this.coplanarPoint(Fi).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}toJSON(){return{normal:this.normal.toArray(),constant:this.constant}}fromJSON(t){return this.normal.fromArray(t.normal),this.constant=t.constant,this}}const _t=new S,Vi=new S,Oe=new S,We=new S;class zn{constructor(t=new S,e=new S(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,_t)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=_t.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(_t.copy(this.origin).addScaledVector(this.direction,e),_t.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){Vi.copy(t).add(e).multiplyScalar(.5),Oe.copy(e).sub(t).normalize(),We.copy(this.origin).sub(Vi);const n=t.distanceTo(e)*.5,r=-this.direction.dot(Oe),a=We.dot(this.direction),o=-We.dot(Oe),c=We.lengthSq(),h=Math.abs(1-r*r);let u,l,d,y;if(h>0)if(u=r*o-a,l=r*a-o,y=n*h,u>=0)if(l>=-y)if(l<=y){const m=1/h;u*=m,l*=m,d=u*(u+r*l+2*a)+l*(r*u+l+2*o)+c}else l=n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l=-n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l<=-y?(u=Math.max(0,-(-r*n+a)),l=u>0?-n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c):l<=y?(u=0,l=Math.min(Math.max(-n,-o),n),d=l*(l+2*o)+c):(u=Math.max(0,-(r*n+a)),l=u>0?n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c);else l=r>0?-n:n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(Vi).addScaledVector(Oe,l),d}intersectSphere(t,e){if(t.radius<0)return null;_t.subVectors(t.center,this.origin);const i=_t.dot(this.direction),s=_t.dot(_t)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,s,n,r,a,o;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,l=this.origin;return c>=0?(i=(t.min.x-l.x)*c,s=(t.max.x-l.x)*c):(i=(t.max.x-l.x)*c,s=(t.min.x-l.x)*c),h>=0?(n=(t.min.y-l.y)*h,r=(t.max.y-l.y)*h):(n=(t.max.y-l.y)*h,r=(t.min.y-l.y)*h),i>r||n>s||((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),u>=0?(a=(t.min.z-l.z)*u,o=(t.max.z-l.z)*u):(a=(t.max.z-l.z)*u,o=(t.min.z-l.z)*u),i>o||a>s)||((a>i||i!==i)&&(i=a),(o<s||s!==s)&&(s=o),s<0)?null:this.at(i>=0?i:s,e)}intersectsBox(t){return this.intersectBox(t,_t)!==null}intersectTriangle(t,e,i,s,n){const r=this.origin,a=this.direction,o=a.x,c=a.y,h=a.z,u=t.x-r.x,l=t.y-r.y,d=t.z-r.z,y=e.x-r.x,m=e.y-r.y,z=e.z-r.z,b=i.x-r.x,p=i.y-r.y,x=i.z-r.z,g=Math.abs(o),w=Math.abs(c),B=Math.abs(h);let _,M,P,A,C,T,E,I,F,R,Z,tt;if(g>=w&&g>=B?(P=o,T=u,F=y,tt=b,o>=0?(_=c,M=h,A=l,C=d,E=m,I=z,R=p,Z=x):(_=h,M=c,A=d,C=l,E=z,I=m,R=x,Z=p)):w>=B?(P=c,T=l,F=m,tt=p,c>=0?(_=h,M=o,A=d,C=u,E=z,I=y,R=x,Z=b):(_=o,M=h,A=u,C=d,E=y,I=z,R=b,Z=x)):(P=h,T=d,F=z,tt=x,h>=0?(_=o,M=c,A=u,C=l,E=y,I=m,R=b,Z=p):(_=c,M=o,A=l,C=u,E=m,I=y,R=p,Z=b)),P===0)return null;const dt=_/P,at=M/P,pt=1/P,ye=A-dt*T,Ie=C-at*T,ys=E-dt*F,Tt=I-at*F,fi=R-dt*tt,di=Z-at*tt,Wt=fi*Tt-di*ys,Xt=ye*di-Ie*fi,Yt=ys*Ie-Tt*ye;if(s){if(Wt<0||Xt<0||Yt<0)return null}else if((Wt<0||Xt<0||Yt<0)&&(Wt>0||Xt>0||Yt>0))return null;const Fe=Wt+Xt+Yt;if(Fe===0)return null;const Ht=pt*(Wt*T+Xt*F+Yt*tt);return(Fe>0?Ht<0:Ht>0)?null:this.at(Ht/Fe,n)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}const ds=class ds{constructor(t,e,i,s){this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,i,s)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let i=0;i<4;i++)this.elements[i]=t[i+e];return this}set(t,e,i,s){const n=this.elements;return n[0]=t,n[2]=e,n[1]=i,n[3]=s,this}};ds.prototype.isMatrix2=!0;let Ps=ds;const Cs=new S,Xe=new S,se=new S,ne=new S,Ri=new S,_n=new S,Mn=new S;class Mt{constructor(t=new S,e=new S){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){Cs.subVectors(t,this.start),Xe.subVectors(this.end,this.start);const i=Xe.dot(Xe);if(i===0)return 0;let n=Xe.dot(Cs)/i;return e&&(n=V(n,0,1)),n}closestPointToPoint(t,e,i){const s=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(s).add(this.start)}distanceSqToLine3(t,e=_n,i=Mn){const s=10000000000000001e-32;let n,r;const a=this.start,o=t.start,c=this.end,h=t.end;se.subVectors(c,a),ne.subVectors(h,o),Ri.subVectors(a,o);const u=se.dot(se),l=ne.dot(ne),d=ne.dot(Ri);if(u<=s&&l<=s)return e.copy(a),i.copy(o),e.sub(i),e.dot(e);if(u<=s)n=0,r=d/l,r=V(r,0,1);else{const y=se.dot(Ri);if(l<=s)r=0,n=V(-y/u,0,1);else{const m=se.dot(ne),z=u*l-m*m;z!==0?n=V((m*d-y*l)/z,0,1):n=0,r=(m*n+d)/l,r<0?(r=0,n=V(-y/u,0,1)):r>1&&(r=1,n=V((m-y)/u,0,1))}}return e.copy(a).addScaledVector(se,n),i.copy(o).addScaledVector(ne,r),e.distanceToSquared(i)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"186"}})),typeof window<"u"&&(window.__THREE__?yt("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="186");new xt().set(-1,0,0,0,1,0,0,0,1),new xt().set(-1,0,0,0,1,0,0,0,1);const Es=0,An=1,Sn=2,Is=2,ki=1.25,Fs=1,J=32,q=J/4,Vs=65535,Ye=Math.pow(2,-24),Ui=Symbol("SKIP_GENERATION"),Rs={strategy:Es,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ui]:!1};function U(f,t,e){return e.min.x=t[f],e.min.y=t[f+1],e.min.z=t[f+2],e.max.x=t[f+3],e.max.y=t[f+4],e.max.z=t[f+5],e}function Ni(f){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=f[i+3]-f[i];s>e&&(e=s,t=i)}return t}function ks(f,t){t.set(f)}function Us(f,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=f[n],s=t[n],e[n]=i<s?i:s,i=f[r],s=t[r],e[r]=i>s?i:s}}function He(f,t,e){for(let i=0;i<3;i++){const s=t[f+2*i],n=t[f+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function _e(f){const t=f[3]-f[0],e=f[4]-f[1],i=f[5]-f[2];return 2*(t*e+e*i+i*t)}function N(f,t){return t[f+15]===Vs}function X(f,t){return t[f+6]}function G(f,t){return t[f+14]}function v(f){return f+q}function O(f,t){const e=t[f+6];return f+e*q}function Li(f,t){return t[f+7]}function Wr(f){return f}function Di(f,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0,u=1/0,l=1/0,d=1/0,y=-1/0,m=-1/0,z=-1/0;const b=f.offset||0;for(let p=(t-b)*6,x=(t+e-b)*6;p<x;p+=6){const g=f[p+0],w=f[p+1],B=g-w,_=g+w;B<n&&(n=B),_>o&&(o=_),g<u&&(u=g),g>y&&(y=g);const M=f[p+2],P=f[p+3],A=M-P,C=M+P;A<r&&(r=A),C>c&&(c=C),M<l&&(l=M),M>m&&(m=M);const T=f[p+4],E=f[p+5],I=T-E,F=T+E;I<a&&(a=I),F>h&&(h=F),T<d&&(d=T),T>z&&(z=T)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=c,i[5]=h,s[0]=u,s[1]=l,s[2]=d,s[3]=y,s[4]=m,s[5]=z}const At=32,Bn=(f,t)=>f.candidate-t.candidate,Ft=new Array(At).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ze=new Float32Array(6);function Tn(f,t,e,i,s,n){let r=-1,a=0;if(n===Es)r=Ni(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===An)r=Ni(f),r!==-1&&(a=Pn(e,i,s,r));else if(n===Sn){const o=_e(f);let c=ki*s;const h=e.offset||0,u=(i-h)*6,l=(i+s-h)*6;for(let d=0;d<3;d++){const y=t[d],b=(t[d+3]-y)/At;if(s<At/4){const p=[...Ft];p.length=s;let x=0;for(let w=u;w<l;w+=6,x++){const B=p[x];B.candidate=e[w+2*d],B.count=0;const{bounds:_,leftCacheBounds:M,rightCacheBounds:P}=B;for(let A=0;A<3;A++)P[A]=1/0,P[A+3]=-1/0,M[A]=1/0,M[A+3]=-1/0,_[A]=1/0,_[A+3]=-1/0;He(w,e,_)}p.sort(Bn);let g=s;for(let w=0;w<g;w++){const B=p[w];for(;w+1<g&&p[w+1].candidate===B.candidate;)p.splice(w+1,1),g--}for(let w=u;w<l;w+=6){const B=e[w+2*d];for(let _=0;_<g;_++){const M=p[_];B>=M.candidate?He(w,e,M.rightCacheBounds):(He(w,e,M.leftCacheBounds),M.count++)}}for(let w=0;w<g;w++){const B=p[w],_=B.count,M=s-B.count,P=B.leftCacheBounds,A=B.rightCacheBounds;let C=0;_!==0&&(C=_e(P)/o);let T=0;M!==0&&(T=_e(A)/o);const E=Fs+ki*(C*_+T*M);E<c&&(r=d,c=E,a=B.candidate)}}else{for(let g=0;g<At;g++){const w=Ft[g];w.count=0,w.candidate=y+b+g*b;const B=w.bounds;for(let _=0;_<3;_++)B[_]=1/0,B[_+3]=-1/0}for(let g=u;g<l;g+=6){let _=~~((e[g+2*d]-y)/b);_>=At&&(_=At-1);const M=Ft[_];M.count++,He(g,e,M.bounds)}const p=Ft[At-1];ks(p.bounds,p.rightCacheBounds);for(let g=At-2;g>=0;g--){const w=Ft[g],B=Ft[g+1];Us(w.bounds,B.rightCacheBounds,w.rightCacheBounds)}let x=0;for(let g=0;g<At-1;g++){const w=Ft[g],B=w.count,_=w.bounds,P=Ft[g+1].rightCacheBounds;B!==0&&(x===0?ks(_,Ze):Us(_,Ze,Ze)),x+=B;let A=0,C=0;x!==0&&(A=_e(Ze)/o);const T=s-x;T!==0&&(C=_e(P)/o);const E=Fs+ki*(A*x+C*T);E<c&&(r=d,c=E,a=w.candidate)}}}}else console.warn(\`BVH: Invalid build strategy value \${n} used.\`);return{axis:r,pos:a}}function Pn(f,t,e,i){let s=0;const n=f.offset;for(let r=t,a=t+e;r<a;r++)s+=f[(r-n)*6+i*2];return s/e}class qi{constructor(){this.boundingData=new Float32Array(6)}}function Cn(f,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,c=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+c]<o;)r++;for(;r<=a&&e[(a-h)*6+c]>=o;)a--;if(r<a){for(let u=0;u<t;u++){let l=f[r*t+u];f[r*t+u]=f[a*t+u],f[a*t+u]=l}for(let u=0;u<6;u++){const l=r-h,d=a-h,y=e[l*6+u];e[l*6+u]=e[d*6+u],e[d*6+u]=y}r++,a--}else return r}}let Ns,$e,vi,Ls;const En=Math.pow(2,32);function Oi(f){return"count"in f?1:1+Oi(f.left)+Oi(f.right)}function In(f,t,e){return Ns=new Float32Array(e),$e=new Uint32Array(e),vi=new Uint16Array(e),Ls=new Uint8Array(e),Wi(f,t)}function Wi(f,t){const e=f/4,i=f/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)Ns[e+r]=n[r];if(s)return t.buffer?(Ls.set(new Uint8Array(t.buffer),f),f+t.buffer.byteLength):($e[e+6]=t.offset,vi[i+14]=t.count,vi[i+15]=Vs,f+J);{const{left:r,right:a,splitAxis:o}=t,c=f+J;let h=Wi(c,r);const u=f/J,d=h/J-u;if(d>En)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return $e[e+6]=d,$e[e+7]=o,Wi(h,a)}}function Fn(f,t,e,i,s,n){const{maxDepth:r,verbose:a,targetLeafSize:o,_strictLeafSize:c=1/0,strategy:h,onProgress:u}=s,l=f.primitiveBuffer,d=f.primitiveBufferStride,y=new Float32Array(6);let m=!1;const z=new qi;return Di(t,e,i,z.boundingData,y),p(z,e,i,y),z;function b(x){u&&u((x-n.offset)/n.count)}function p(x,g,w,B=null,_=0){!m&&_>=r&&(m=!0,a&&console.warn(\`BVH: Max depth of \${r} reached when generating BVH. Consider increasing maxDepth.\`));const M=w>c;if(w<=o&&!M||_>=r)return b(g+w),x.offset=g,x.count=w,x;const P=Tn(x.boundingData,B,t,g,w,h);let A=P.axis===-1?-1:Cn(l,d,t,g,w,P);if(P.axis===-1||A===g||A===g+w){if(!M)return b(g+w),x.offset=g,x.count=w,x;P.axis=Math.max(0,Ni(x.boundingData)),A=g+Math.max(1,Math.floor(w/2))}x.splitAxis=P.axis;const C=new qi,T=g,E=A-g;x.left=C,Di(t,T,E,C.boundingData,y),p(C,T,E,y,_+1);const I=new qi,F=A,R=w-E;return x.right=I,Di(t,F,R,I.boundingData,y),p(I,F,R,y,_+1),x}}function Vn(f,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=f.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,f.computePrimitiveBounds(r.offset,r.count,a),f._roots=i.map(o=>{const c=Fn(f,a,o.offset,o.count,t,r),h=Oi(c),u=new e(J*h);return In(0,c,u),u})}class Xi{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Rn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const k=new Rn;let Vt,re;const oe=[],Je=new Xi(()=>new Q);function kn(f,t,e,i,s,n){Vt=Je.getPrimitive(),re=Je.getPrimitive(),oe.push(Vt,re),k.setBuffer(f._roots[t]);const r=Yi(0,f.geometry,e,i,s,n);k.clearBuffer(),Je.releasePrimitive(Vt),Je.releasePrimitive(re),oe.pop(),oe.pop();const a=oe.length;return a>0&&(re=oe[a-1],Vt=oe[a-2]),r}function Yi(f,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:c}=k;let h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);return U(f,a,Vt),i(l,d,!1,r,n+f/q,Vt)}else{let A=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=v(T),F=T*2;return X(T,I)},C=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=O(T,I),F=T*2;return X(T,I)+G(F,E)};const l=v(f),d=O(f,c);let y=l,m=d,z,b,p,x;if(s&&(p=Vt,x=re,U(y,a,p),U(m,a,x),z=s(p),b=s(x),b<z)){y=d,m=l;const T=z;z=b,b=T,p=x}p||(p=Vt,U(y,a,p));const g=N(y*2,o),w=e(p,g,z,r+1,n+y/q);let B;if(w===Is){const T=A(y),I=C(y)-T;B=i(T,I,!0,r+1,n+y/q,p)}else B=w&&Yi(y,t,e,i,s,n,r+1);if(B)return!0;x=re,U(m,a,x);const _=N(m*2,o),M=e(x,_,b,r+1,n+m/q);let P;if(M===Is){const T=A(m),I=C(m)-T;P=i(T,I,!0,r+1,n+m/q,x)}else P=M&&Yi(m,t,e,i,s,n,r+1);return!!P}}const Me=new k.constructor,Ge=new k.constructor,Rt=new Xi(()=>new Q),ae=new Q,ce=new Q,Hi=new Q,Zi=new Q;let $i=!1;function Un(f,t,e,i){if($i)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");$i=!0;const s=f._roots,n=t._roots;let r,a=0,o=0;const c=new H().copy(e).invert();for(let h=0,u=s.length;h<u;h++){Me.setBuffer(s[h]),o=0;const l=Rt.getPrimitive();U(0,Me.float32Array,l),l.applyMatrix4(c);for(let d=0,y=n.length;d<y&&(Ge.setBuffer(n[d]),r=ut(0,0,e,c,i,a,o,0,0,l),Ge.clearBuffer(),o+=n[d].byteLength/J,!r);d++);if(Rt.releasePrimitive(l),Me.clearBuffer(),a+=s[h].byteLength/J,r)break}return $i=!1,r}function ut(f,t,e,i,s,n=0,r=0,a=0,o=0,c=null,h=!1){let u,l;h?(u=Ge,l=Me):(u=Me,l=Ge);const d=u.float32Array,y=u.uint32Array,m=u.uint16Array,z=l.float32Array,b=l.uint32Array,p=l.uint16Array,x=f*2,g=t*2,w=N(x,m),B=N(g,p);let _=!1;if(B&&w)h?_=s(X(t,b),G(t*2,p),X(f,y),G(f*2,m),o,r+t/q,a,n+f/q):_=s(X(f,y),G(f*2,m),X(t,b),G(t*2,p),a,n+f/q,o,r+t/q);else if(B){const M=Rt.getPrimitive();U(t,z,M),M.applyMatrix4(e);const P=v(f),A=O(f,y);U(P,d,ae),U(A,d,ce);const C=M.intersectsBox(ae),T=M.intersectsBox(ce);_=C&&ut(t,P,i,e,s,r,n,o,a+1,M,!h)||T&&ut(t,A,i,e,s,r,n,o,a+1,M,!h),Rt.releasePrimitive(M)}else{const M=v(t),P=O(t,b);U(M,z,Hi),U(P,z,Zi);const A=c.intersectsBox(Hi),C=c.intersectsBox(Zi);if(A&&C)_=ut(f,M,e,i,s,n,r,a,o+1,c,h)||ut(f,P,e,i,s,n,r,a,o+1,c,h);else if(A)if(w)_=ut(f,M,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Hi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(M,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(M,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}else if(C)if(w)_=ut(f,P,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Zi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(P,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(P,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}}return _}const Ji=new class{constructor(){let f=null,t=null,e=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(n,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=f=n._roots[r],this.uint16Array=e=new Uint16Array(f),this.uint32Array=t=new Uint32Array(f)},this.reset=()=>{this.root=null,this.buffer=f=null,this.uint16Array=e=null,this.uint32Array=t=null},this.getRangeStart=n=>{let r=n*2;for(;!N(r,e);)n=v(n),r=n*2;return X(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!N(r,e);)n=O(n,t),r=n*2;return X(n,t)+G(r,e)};const s=(n,r,a)=>{const o=r*2,c=N(o,e);if(!n(a,c,r)&&!c){const u=v(r),l=O(r,t);s(n,u,a+1),s(n,l,a+1)}};this.traverseBuffer=n=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(n,0,0)}finally{i=!1}},this.traverse=n=>{this.traverseBuffer((r,a,o)=>{if(a){const c=o*2,h=t[o+6],u=e[c+14];return n(r,a,new Float32Array(f,o*4,6),h,u)}else{const c=Li(o,t);return n(r,a,new Float32Array(f,o*4,6),c)}})}}},Ds=new Q,he=new Float32Array(6);class Nn{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...Rs,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),Vn(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0;for(let u=t,l=t+e;u<l;u++){this.writePrimitiveBounds(u,he,0);const[d,y,m,z,b,p]=he;d<n&&(n=d),z>o&&(o=z),y<r&&(r=y),b>c&&(c=b),m<a&&(a=m),p>h&&(h=p)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=c,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,he,0);const[a,o,c,h,u,l]=he,d=(a+h)/2,y=(o+u)/2,m=(c+l)/2,z=(h-a)/2,b=(u-o)/2,p=(l-c)/2,x=(n-s)*6;i[x+0]=d,i[x+1]=z+(Math.abs(d)+z)*Ye,i[x+2]=y,i[x+3]=b+(Math.abs(y)+b)*Ye,i[x+4]=m,i[x+5]=p+(Math.abs(m)+p)*Ye}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/J;for(let c=0;c<o;c++){const h=q*c,u=2*h;N(u,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){Ji.setBVH(this,e),Ji.traverse(t),Ji.reset()}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/J;for(let c=o-1;c>=0;c--){const h=c*q,u=h*2;if(N(u,r)){const d=X(h,n),y=G(u,r);this.writePrimitiveRangeBounds(d,y,he,0),a.set(he,h)}else{const d=v(h),y=O(h,n);for(let m=0;m<3;m++){const z=a[d+m],b=a[d+m+3],p=a[y+m],x=a[y+m+3];a[h+m]=z<p?z:p,a[h+m+3]=b>x?b:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{U(0,new Float32Array(i),Ds),t.union(Ds)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const u=s;s=(l,d,y,m,z)=>u(l,d,y,m,z)?!0:a(l,d,this,n,y,m,r)}else s||(n?s=(u,l,d,y)=>a(u,l,this,n,d,y,r):s=(u,l,d)=>d);let o=!1,c=0;const h=this._roots;for(let u=0,l=h.length;u<l;u++){const d=h[u];if(o=kn(this,u,i,s,e,c),o)break;c+=d.byteLength/J}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return Un(this,t,e,s)}}function Ln(){return typeof SharedArrayBuffer<"u"}function Gi(f){return f.index?f.index.count:f.attributes.position.count}function Qe(f){return Gi(f)/3}function Dn(f,t=ArrayBuffer){return f>65535?new Uint32Array(new t(4*f)):new Uint16Array(new t(2*f))}function qn(f,t){if(!f.index){const e=f.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Dn(e,i);f.setIndex(new mt(s,1));for(let n=0;n<e;n++)s[n]=n}}function vn(f,t,e){const i=Gi(f)/e,s=t||f.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function On(f,t){return f.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function qs(f,t,e){const i=vn(f,t,e),s=On(f,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=Gi(f)/e,c=[];for(const l of s){const{offset:d,count:y}=l,m=d,z=isFinite(y)?y:o-d,b=d+z;m<a&&b>r&&(c.push({pos:Math.max(r,m),isStart:!0}),c.push({pos:Math.min(a,b),isStart:!1}))}c.sort((l,d)=>l.pos!==d.pos?l.pos-d.pos:l.type==="end"?-1:1);let h=0,u=null;for(const l of c){const d=l.pos;h!==0&&d!==u&&n.push({offset:u,count:d-u}),h+=l.isStart?1:-1,u=d}return n}function Wn(f,t){const e=f[f.length-1],i=e.offset+e.count>2**16,s=f.reduce((c,h)=>c+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let c=0;c<f.length;c++){const{offset:h,count:u}=f[c];for(let l=0;l<u;l++)a[o+l]=h+l;o+=u}return a}class Xn extends Nn{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Ln())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...Rs,...e},e[Ui]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=qs(e,t.range,i),n=Wn(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else qn(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Q))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:qs(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class St{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}St.prototype.setFromBox=(function(){const f=new S;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let h=0;h<=1;h++){f.x=s.x*o+n.x*(1-o),f.y=s.y*c+n.y*(1-c),f.z=s.z*h+n.z*(1-h);const u=e.dot(f);r=Math.min(u,r),a=Math.max(u,a)}this.min=r,this.max=a}})();const Yn=(function(){const f=new S,t=new S,e=new S;return function(s,n,r){const a=s.start,o=f,c=n.start,h=t;e.subVectors(a,c),f.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const u=e.dot(h),l=h.dot(o),d=h.dot(h),y=e.dot(o),z=o.dot(o)*d-l*l;let b,p;z!==0?b=(u*l-y*d)/z:b=0,p=(u+b*l)/d,r.x=b,r.y=p}})(),Qi=(function(){const f=new Y,t=new S,e=new S;return function(s,n,r,a){Yn(s,n,f);let o=f.x,c=f.y;if(o>=0&&o<=1&&c>=0&&c<=1){s.at(o,r),n.at(c,a);return}else if(o>=0&&o<=1){c<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(c>=0&&c<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let u;c<0?u=n.start:u=n.end;const l=t,d=e;if(s.closestPointToPoint(u,!0,t),n.closestPointToPoint(h,!0,e),l.distanceToSquared(u)<=d.distanceToSquared(h)){r.copy(l),a.copy(u);return}else{r.copy(h),a.copy(d);return}}}})(),Hn=(function(){const f=new S,t=new S,e=new Ts,i=new Mt;return function(n,r){const{radius:a,center:o}=n,{a:c,b:h,c:u}=r;if(i.start=c,i.end=h,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a||(i.start=c,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a)||(i.start=h,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a))return!0;const m=r.getPlane(e);if(Math.abs(m.distanceToPoint(o))<=a){const b=m.projectPoint(o,t);if(r.containsPoint(b))return!0}return!1}})(),Zn=["x","y","z"],Bt=1e-15,vs=Bt*Bt;function rt(f){return Math.abs(f)<Bt}class ft extends st{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new S),this.satBounds=new Array(4).fill().map(()=>new St),this.points=[this.a,this.b,this.c],this.plane=new Ts,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Mt,this.needsUpdate=!0}intersectsSphere(t){return Hn(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const c=n[1],h=r[1];c.subVectors(t,e),h.setFromPoints(c,s);const u=n[2],l=r[2];u.subVectors(e,i),l.setFromPoints(u,s);const d=n[3],y=r[3];d.subVectors(i,t),y.setFromPoints(d,s);const m=c.length(),z=u.length(),b=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<Bt?z<Bt||b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):z<Bt?b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):b<Bt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}ft.prototype.closestPointToSegment=(function(){const f=new S,t=new S,e=new Mt;return function(s,n=null,r=null){const{start:a,end:o}=s,c=this.points;let h,u=1/0;for(let l=0;l<3;l++){const d=(l+1)%3;e.start.copy(c[l]),e.end.copy(c[d]),Qi(e,s,f,t),h=f.distanceToSquared(t),h<u&&(u=h,n&&n.copy(f),r&&r.copy(t))}return this.closestPointToPoint(a,f),h=a.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(a)),this.closestPointToPoint(o,f),h=o.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(o)),Math.sqrt(u)}})(),ft.prototype.intersectsTriangle=(function(){const f=new ft,t=new St,e=new St,i=new S,s=new S,n=new S,r=new S,a=new Mt,o=new Mt,c=new S,h=new Y,u=new Y;function l(x,g,w,B){const _=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?_.copy(x.plane.normal):_.copy(g.plane.normal);const M=x.satBounds,P=x.satAxes;for(let T=1;T<4;T++){const E=M[T],I=P[T];if(t.setFromPoints(I,g.points),E.isSeparated(t)||(r.copy(_).cross(I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}const A=g.satBounds,C=g.satAxes;for(let T=1;T<4;T++){const E=A[T],I=C[T];if(t.setFromPoints(I,x.points),E.isSeparated(t)||(r.crossVectors(_,I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}return w&&(B||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),w.start.set(0,0,0),w.end.set(0,0,0)),!0}function d(x,g,w,B,_,M,P,A,C,T,E){let I=P/(P-A);T.x=B+(_-B)*I,E.start.subVectors(g,x).multiplyScalar(I).add(x),I=P/(P-C),T.y=B+(M-B)*I,E.end.subVectors(w,x).multiplyScalar(I).add(x)}function y(x,g,w,B,_,M,P,A,C,T,E){if(_>0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else if(M>0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(A*C>0||P!=0)d(x.a,x.b,x.c,g,w,B,P,A,C,T,E);else if(A!=0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(C!=0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else return!0;return!1}function m(x,g,w,B){const _=g.degenerateSegment,M=x.plane.distanceToPoint(_.start),P=x.plane.distanceToPoint(_.end);return rt(M)?rt(P)?l(x,g,w,B):(w&&(w.start.copy(_.start),w.end.copy(_.start)),x.containsPoint(_.start)):rt(P)?(w&&(w.start.copy(_.end),w.end.copy(_.end)),x.containsPoint(_.end)):x.plane.intersectLine(_,i)!=null?(w&&(w.start.copy(i),w.end.copy(i)),x.containsPoint(i)):!1}function z(x,g,w){const B=g.a;return rt(x.plane.distanceToPoint(B))&&x.containsPoint(B)?(w&&(w.start.copy(B),w.end.copy(B)),!0):!1}function b(x,g,w){const B=x.degenerateSegment,_=g.a;return B.closestPointToPoint(_,!0,i),_.distanceToSquared(i)<vs?(w&&(w.start.copy(_),w.end.copy(_)),!0):!1}function p(x,g,w,B){if(x.isDegenerateIntoSegment)if(g.isDegenerateIntoSegment){const _=x.degenerateSegment,M=g.degenerateSegment,P=s,A=n;_.delta(P),M.delta(A);const C=i.subVectors(M.start,_.start),T=P.x*A.y-P.y*A.x;if(rt(T))return!1;const E=(C.x*A.y-C.y*A.x)/T,I=-(P.x*C.y-P.y*C.x)/T;if(E<0||E>1||I<0||I>1)return!1;const F=_.start.z+P.z*E,R=M.start.z+A.z*I;return rt(F-R)?(w&&(w.start.copy(_.start).addScaledVector(P,E),w.end.copy(_.start).addScaledVector(P,E)),!0):!1}else return g.isDegenerateIntoPoint?b(x,g,w):m(g,x,w,B);else{if(x.isDegenerateIntoPoint)return g.isDegenerateIntoPoint?g.a.distanceToSquared(x.a)<vs?(w&&(w.start.copy(x.a),w.end.copy(x.a)),!0):!1:g.isDegenerateIntoSegment?b(g,x,w):z(g,x,w);if(g.isDegenerateIntoPoint)return z(x,g,w);if(g.isDegenerateIntoSegment)return m(x,g,w,B)}}return function(g,w=null,B=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(f.copy(g),f.update(),g=f);const _=p(this,g,w,B);if(_!==void 0)return _;const M=this.plane,P=g.plane;let A=P.distanceToPoint(this.a),C=P.distanceToPoint(this.b),T=P.distanceToPoint(this.c);rt(A)&&(A=0),rt(C)&&(C=0),rt(T)&&(T=0);const E=A*C,I=A*T;if(E>0&&I>0)return!1;let F=M.distanceToPoint(g.a),R=M.distanceToPoint(g.b),Z=M.distanceToPoint(g.c);rt(F)&&(F=0),rt(R)&&(R=0),rt(Z)&&(Z=0);const tt=F*R,dt=F*Z;if(tt>0&&dt>0)return!1;s.copy(M.normal),n.copy(P.normal);const at=s.cross(n);let pt=0,ye=Math.abs(at.x);const Ie=Math.abs(at.y);Ie>ye&&(ye=Ie,pt=1),Math.abs(at.z)>ye&&(pt=2);const Tt=Zn[pt],fi=this.a[Tt],di=this.b[Tt],Wt=this.c[Tt],Xt=g.a[Tt],Yt=g.b[Tt],Fe=g.c[Tt];if(y(this,fi,di,Wt,E,I,A,C,T,h,a))return l(this,g,w,B);if(y(g,Xt,Yt,Fe,tt,dt,F,R,Z,u,o))return l(this,g,w,B);if(h.y<h.x){const Ht=h.y;h.y=h.x,h.x=Ht,c.copy(a.start),a.start.copy(a.end),a.end.copy(c)}if(u.y<u.x){const Ht=u.y;u.y=u.x,u.x=Ht,c.copy(o.start),o.start.copy(o.end),o.end.copy(c)}return h.y<u.x||u.y<h.x?!1:(w&&(u.x>h.x?w.start.copy(o.start):w.start.copy(a.start),u.y<h.y?w.end.copy(o.end):w.end.copy(a.end)),!0)}})(),ft.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),ft.prototype.distanceToTriangle=(function(){const f=new S,t=new S,e=["a","b","c"],i=new Mt,s=new Mt;return function(r,a=null,o=null){const c=a||o?i:null;if(this.intersectsTriangle(r,c,!0))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let h=1/0;for(let u=0;u<3;u++){let l;const d=e[u],y=r[d];this.closestPointToPoint(y,f),l=y.distanceToSquared(f),l<h&&(h=l,a&&a.copy(f),o&&o.copy(y));const m=this[d];r.closestPointToPoint(m,f),l=m.distanceToSquared(f),l<h&&(h=l,a&&a.copy(m),o&&o.copy(f))}for(let u=0;u<3;u++){const l=e[u],d=e[(u+1)%3];i.set(this[l],this[d]);for(let y=0;y<3;y++){const m=e[y],z=e[(y+1)%3];s.set(r[m],r[z]),Qi(i,s,f,t);const b=f.distanceToSquared(t);b<h&&(h=b,a&&a.copy(f),o&&o.copy(t))}}return Math.sqrt(h)}})();class j{constructor(t,e,i){this.isOrientedBox=!0,this.min=new S,this.max=new S,this.matrix=new H,this.invMatrix=new H,this.points=new Array(8).fill().map(()=>new S),this.satAxes=new Array(3).fill().map(()=>new S),this.satBounds=new Array(3).fill().map(()=>new St),this.alignedSatBounds=new Array(3).fill().map(()=>new St),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}j.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let c=0;c<=1;c++)for(let h=0;h<=1;h++)for(let u=0;u<=1;u++){const l=1*c|2*h|4*u,d=s[l];d.x=c?i.x:e.x,d.y=h?i.y:e.y,d.z=u?i.z:e.z,d.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let c=0;c<3;c++){const h=r[c],u=n[c],l=1<<c,d=s[l];h.subVectors(a,d),u.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),j.prototype.intersectsBox=(function(){const f=new St;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(f.min=i.x,f.max=s.x,a[0].isSeparated(f)||(f.min=i.y,f.max=s.y,a[1].isSeparated(f))||(f.min=i.z,f.max=s.z,a[2].isSeparated(f)))return!1;for(let o=0;o<3;o++){const c=r[o],h=n[o];if(f.setFromBox(c,e),h.isSeparated(f))return!1}return!0}})(),j.prototype.intersectsTriangle=(function(){const f=new ft,t=new Array(3),e=new St,i=new St,s=new S;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(f.copy(r),f.update(),r=f);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let l=0;l<3;l++){const d=a[l],y=o[l];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const c=r.satBounds,h=r.satAxes,u=this.points;for(let l=0;l<3;l++){const d=c[l],y=h[l];if(e.setFromPoints(y,u),d.isSeparated(e))return!1}for(let l=0;l<3;l++){const d=o[l];for(let y=0;y<4;y++){const m=h[y];if(s.crossVectors(d,m),e.setFromPoints(s,t),i.setFromPoints(s,u),e.isSeparated(i))return!1}}return!0}})(),j.prototype.closestPointToPoint=(function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}})(),j.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),j.prototype.distanceToBox=(function(){const f=["x","y","z"],t=new Array(12).fill().map(()=>new Mt),e=new Array(12).fill().map(()=>new Mt),i=new S,s=new S;return function(r,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||c)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),c&&c.copy(s)),0;const h=a*a,u=r.min,l=r.max,d=this.points;let y=1/0;for(let z=0;z<8;z++){const b=d[z];s.copy(b).clamp(u,l);const p=b.distanceToSquared(s);if(p<y&&(y=p,o&&o.copy(b),c&&c.copy(s),p<h))return Math.sqrt(p)}let m=0;for(let z=0;z<3;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){const x=(z+1)%3,g=(z+2)%3,w=b<<x|p<<g,B=1<<z|b<<x|p<<g,_=d[w],M=d[B];t[m].set(_,M);const A=f[z],C=f[x],T=f[g],E=e[m],I=E.start,F=E.end;I[A]=u[A],I[C]=b?u[C]:l[C],I[T]=p?u[T]:l[C],F[A]=l[A],F[C]=b?u[C]:l[C],F[T]=p?u[T]:l[C],m++}for(let z=0;z<=1;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){s.x=z?l.x:u.x,s.y=b?l.y:u.y,s.z=p?l.z:u.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<y&&(y=x,o&&o.copy(i),c&&c.copy(s),x<h))return Math.sqrt(x)}for(let z=0;z<12;z++){const b=t[z];for(let p=0;p<12;p++){const x=e[p];Qi(b,x,i,s);const g=i.distanceToSquared(s);if(g<y&&(y=g,o&&o.copy(i),c&&c.copy(s),g<h))return Math.sqrt(g)}}return Math.sqrt(y)}})();class $n extends Xi{constructor(){super(()=>new ft)}}const ot=new $n,Ae=new S,ji=new S;function Jn(f,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(f.shapecast({boundsTraverseOrder:h=>(Ae.copy(t).clamp(h.min,h.max),Ae.distanceToSquared(t)),intersectsBounds:(h,u,l)=>l<a&&l<r,intersectsTriangle:(h,u)=>{h.closestPointToPoint(t,Ae);const l=t.distanceToSquared(Ae);return l<a&&(ji.copy(Ae),a=l,o=u),l<n}}),a===1/0)return null;const c=Math.sqrt(a);return e.point?e.point.copy(ji):e.point=ji.clone(),e.distance=c,e.faceIndex=o,e}const je=parseInt("186")>=169,Gn=parseInt("186")<=161,qt=new S,vt=new S,Ot=new S,Ke=new Y,ti=new Y,ei=new Y,Os=new S,Ws=new S,Xs=new S,Se=new S;function Qn(f,t,e,i,s,n,r,a){let o;if(n===1?o=f.intersectTriangle(i,e,t,!0,s):o=f.intersectTriangle(t,e,i,n!==2,s),o===null)return null;const c=f.origin.distanceTo(s);return c<r||c>a?null:{distance:c,point:s.clone()}}function Ys(f,t,e,i,s,n,r,a,o,c,h){qt.fromBufferAttribute(t,n),vt.fromBufferAttribute(t,r),Ot.fromBufferAttribute(t,a);const u=Qn(f,qt,vt,Ot,Se,o,c,h);if(u){if(i){Ke.fromBufferAttribute(i,n),ti.fromBufferAttribute(i,r),ei.fromBufferAttribute(i,a),u.uv=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv);je||(u.uv=d)}if(s){Ke.fromBufferAttribute(s,n),ti.fromBufferAttribute(s,r),ei.fromBufferAttribute(s,a),u.uv1=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv1);je||(u.uv1=d),Gn&&(u.uv2=u.uv1)}if(e){Os.fromBufferAttribute(e,n),Ws.fromBufferAttribute(e,r),Xs.fromBufferAttribute(e,a),u.normal=new S;const d=st.getInterpolation(Se,qt,vt,Ot,Os,Ws,Xs,u.normal);u.normal.dot(f.direction)>0&&u.normal.multiplyScalar(-1),je||(u.normal=d)}const l={a:n,b:r,c:a,normal:new S,materialIndex:0};if(st.getNormal(qt,vt,Ot,l.normal),u.face=l,u.faceIndex=n,je){const d=new S;st.getBarycoord(Se,qt,vt,Ot,d),u.barycoord=d}}return u}function Hs(f){return f&&f.isMaterial?f.side:f}function ii(f,t,e,i,s,n,r){const a=i*3;let o=a+0,c=a+1,h=a+2;const{index:u,groups:l}=f;f.index&&(o=u.getX(o),c=u.getX(c),h=u.getX(h));const{position:d,normal:y,uv:m,uv1:z}=f.attributes;if(Array.isArray(t)){const b=i*3;for(let p=0,x=l.length;p<x;p++){const{start:g,count:w,materialIndex:B}=l[p];if(b>=g&&b<g+w){const _=Hs(t[B]),M=Ys(e,d,y,m,z,o,c,h,_,n,r);if(M)if(M.faceIndex=i,M.face.materialIndex=B,s)s.push(M);else return M}}}else{const b=Hs(t),p=Ys(e,d,y,m,z,o,c,h,b,n,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function D(f,t,e,i){const s=f.a,n=f.b,r=f.c;let a=t,o=t+1,c=t+2;e&&(a=e.getX(a),o=e.getX(o),c=e.getX(c)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(c),r.y=i.getY(c),r.z=i.getZ(c)}function jn(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++)ii(o,t,e,h,n,r,a)}function Kn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function tr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=h,D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function er(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=3*z,P=3*(z+b);M<P;M++){let A=i[M];const C=s.getX(A),T=s.getY(A),E=s.getZ(A);C<p&&(p=C),C>w&&(w=C),T<x&&(x=T),T>B&&(B=T),E<g&&(g=E),E>_&&(_=E)}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function kt(f,t,e,i,s){let n,r,a,o,c,h;const u=1/e.direction.x,l=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,m=e.origin.y,z=e.origin.z;let b=t[f],p=t[f+3],x=t[f+1],g=t[f+3+1],w=t[f+2],B=t[f+3+2];return u>=0?(n=(b-y)*u,r=(p-y)*u):(n=(p-y)*u,r=(b-y)*u),l>=0?(a=(x-m)*l,o=(g-m)*l):(a=(g-m)*l,o=(x-m)*l),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),d>=0?(c=(w-z)*d,h=(B-z)*d):(c=(B-z)*d,h=(w-z)*d),n>h||c>r)?!1:((c>n||n!==n)&&(n=c),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function ir(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++){let l=c?c[h]:h;ii(o,t,e,l,n,r,a)}}function sr(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,o?o[u]:u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function nr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=e.resolveTriangleIndex(h),D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function rr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),Ki(0,f,e,i,s,n,r),k.clearBuffer()}function Ki(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);jn(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&Ki(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&Ki(d,t,e,i,s,n,r)}}const or=["x","y","z"];function ar(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ts(0,f,e,i,s,n);return k.clearBuffer(),r}function ts(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return Kn(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=or[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ts(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ts(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const si=new Q,le=new ft,ue=new ft,Be=new H,Zs=new j,ni=new j;function cr(f,t,e,i){k.setBuffer(f._roots[t]);const s=es(0,f,e,i);return k.clearBuffer(),s}function es(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Zs.set(e.boundingBox.min,e.boundingBox.max,i),s=Zs),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Be.copy(i).invert(),e.boundsTree)return U(f,n,ni),ni.matrix.copy(Be),ni.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ni.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m*3,g=(z+m)*3;x<g;x+=3)if(D(ue,x,u,l),ue.needsUpdate=!0,p.intersectsTriangle(ue))return!0;return!1}});{const b=Qe(e);for(let p=m*3,x=(z+m)*3;p<x;p+=3){D(le,p,u,l),le.a.applyMatrix4(Be),le.b.applyMatrix4(Be),le.c.applyMatrix4(Be),le.needsUpdate=!0;for(let g=0,w=b*3;g<w;g+=3)if(D(ue,g,d,y),ue.needsUpdate=!0,le.intersectsTriangle(ue))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,si),!!(s.intersectsBox(si)&&es(h,t,e,i,s)||(U(u,n,si),s.intersectsBox(si)&&es(u,t,e,i,s)))}}const ri=new H,is=new j,Te=new j,hr=new S,lr=new S,ur=new S,fr=new S;function dr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),is.set(t.boundingBox.min,t.boundingBox.max,e),is.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=hr,m=lr,z=null,b=null;s&&(z=ur,b=fr);let p=1/0,x=null,g=null;return ri.copy(e).invert(),Te.matrix.copy(ri),f.shapecast({boundsTraverseOrder:w=>is.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Te.min.copy(w.min),Te.max.copy(w.max),Te.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:M=>Te.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let T=w,E=w+B;T<E;T++){D(l,3*T,c,o),l.needsUpdate=!0;const I=l.distanceToTriangle(d,y,z);if(I<p&&(m.copy(y),b&&b.copy(z),p=I,x=T,g=A),I<n)return!0}}}});{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){D(l,3*A,c,o),l.needsUpdate=!0;const T=l.distanceToTriangle(d,y,z);if(T<p&&(m.copy(y),b&&b.copy(z),p=T,x=A,g=M),T<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ri),m.applyMatrix4(ri),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function yr(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=z,P=z+b;M<P;M++){const A=3*f.resolveTriangleIndex(M);for(let C=0;C<3;C++){let T=A+C;T=i?i[T]:T;const E=s.getX(T),I=s.getY(T),F=s.getZ(T);E<p&&(p=E),E>w&&(w=E),I<x&&(x=I),I>B&&(B=I),F<g&&(g=F),F>_&&(_=F)}}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function mr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),ss(0,f,e,i,s,n,r),k.clearBuffer()}function ss(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);ir(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&ss(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&ss(d,t,e,i,s,n,r)}}const pr=["x","y","z"];function xr(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ns(0,f,e,i,s,n);return k.clearBuffer(),r}function ns(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return sr(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=pr[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ns(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ns(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const oi=new Q,fe=new ft,de=new ft,Pe=new H,$s=new j,ai=new j;function gr(f,t,e,i){k.setBuffer(f._roots[t]);const s=rs(0,f,e,i);return k.clearBuffer(),s}function rs(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),$s.set(e.boundingBox.min,e.boundingBox.max,i),s=$s),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Pe.copy(i).invert(),e.boundsTree)return U(f,n,ai),ai.matrix.copy(Pe),ai.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ai.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m,g=z+m;x<g;x++)if(D(de,3*t.resolveTriangleIndex(x),u,l),de.needsUpdate=!0,p.intersectsTriangle(de))return!0;return!1}});{const b=Qe(e);for(let p=m,x=z+m;p<x;p++){const g=t.resolveTriangleIndex(p);D(fe,3*g,u,l),fe.a.applyMatrix4(Pe),fe.b.applyMatrix4(Pe),fe.c.applyMatrix4(Pe),fe.needsUpdate=!0;for(let w=0,B=b*3;w<B;w+=3)if(D(de,w,d,y),de.needsUpdate=!0,fe.intersectsTriangle(de))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,oi),!!(s.intersectsBox(oi)&&rs(h,t,e,i,s)||(U(u,n,oi),s.intersectsBox(oi)&&rs(u,t,e,i,s)))}}const ci=new H,os=new j,Ce=new j,wr=new S,br=new S,zr=new S,_r=new S;function Mr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),os.set(t.boundingBox.min,t.boundingBox.max,e),os.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=wr,m=br,z=null,b=null;s&&(z=zr,b=_r);let p=1/0,x=null,g=null;return ci.copy(e).invert(),Ce.matrix.copy(ci),f.shapecast({boundsTraverseOrder:w=>os.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Ce.min.copy(w.min),Ce.max.copy(w.max),Ce.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree){const _=t.boundsTree;return _.shapecast({boundsTraverseOrder:M=>Ce.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){const T=_.resolveTriangleIndex(A);D(d,3*T,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=w,I=w+B;E<I;E++){const F=f.resolveTriangleIndex(E);D(l,3*F,c,o),l.needsUpdate=!0;const R=l.distanceToTriangle(d,y,z);if(R<p&&(m.copy(y),b&&b.copy(z),p=R,x=E,g=A),R<n)return!0}}}})}else{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){const T=f.resolveTriangleIndex(A);D(l,3*T,c,o),l.needsUpdate=!0;const E=l.distanceToTriangle(d,y,z);if(E<p&&(m.copy(y),b&&b.copy(z),p=E,x=A,g=M),E<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ci),m.applyMatrix4(ci),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function Js(f,t,e){return f===null?null:(f.point.applyMatrix4(t.matrixWorld),f.distance=f.point.distanceTo(e.ray.origin),f.object=t,f)}const hi=new j,li=new zn,Gs=new S,Qs=new H,js=new S,as=["getX","getY","getZ"];class Ee extends Xn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new Ee(e,{...i,[Ui]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const h=new mt(t.index,1,!1);e.setIndex(h)}else c.array!==s&&(c.array.set(s),c.needsUpdate=!0)}return a;function o(c){for(let h=0;h<c.length;h++){const u=c[h],l=new Uint32Array(u),d=new Uint16Array(u);for(let y=0,m=u.byteLength/J;y<m;y++){const z=q*y,b=2*z;N(b,d)||(l[z+6]=l[z+6]/q-y)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,c=(n?n[t]:t)*3;let h=c+0,u=c+1,l=c+2;a&&(h=a[h],u=a[u],l=a[l]);for(let d=0;d<3;d++){const y=r[as[d]](h),m=r[as[d]](u),z=r[as[d]](l);let b=y;m<b&&(b=m),z<b&&(b=z);let p=y;m>p&&(p=m),z>p&&(p=z),e[i+d]=b,e[i+d+3]=p}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=r.array,h=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const l=["getX","getY","getZ"],d=i.offset;for(let y=t,m=t+e;y<m;y++){const b=(n?n[y]:y)*3,p=(y-d)*6;let x=b+0,g=b+1,w=b+2;a&&(x=a[x],g=a[g],w=a[w]),o||(x=x*u+h,g=g*u+h,w=w*u+h);for(let B=0;B<3;B++){let _,M,P;o?(_=r[l[B]](x),M=r[l[B]](g),P=r[l[B]](w)):(_=c[x+B],M=c[g+B],P=c[w+B]);let A=_;M<A&&(A=M),P<A&&(A=P);let C=_;M>C&&(C=M),P>C&&(C=P);const T=(C-A)/2,E=B*2;i[p+E+0]=A+T,i[p+E+1]=T+(Math.abs(A)+T)*Ye}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;Qs.copy(t.matrixWorld).invert(),li.copy(e.ray).applyMatrix4(Qs),js.setFromMatrixScale(t.matrixWorld),Gs.copy(li.direction).multiply(js);const n=Gs.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(li,s,r,a);o=Js(o,t,e),o&&i.push(o)}else{const o=this.raycast(li,s,r,a);for(let c=0,h=o.length;c<h;c++){const u=Js(o[c],t,e);u&&i.push(u)}}return i}refit(t=null){return(this.indirect?yr:er)(this,t)}raycast(t,e=0,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?mr:rr;for(let o=0,c=n.length;o<c;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=0,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?xr:ar;for(let o=0,c=n.length;o<c;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?gr:cr;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=ot.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?nr:tr});return ot.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=ot.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,c=this.indirect?y=>{const m=this.resolveTriangleIndex(y);D(r,m*3,a,o)}:y=>{D(r,y*3,a,o)},h=ot.getPrimitive(),u=t.geometry.index,l=t.geometry.attributes.position,d=t.indirect?y=>{const m=t.resolveTriangleIndex(y);D(h,m*3,u,l)}:y=>{D(h,y*3,u,l)};if(n){if(!(t instanceof Ee))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const y=(m,z,b,p,x,g,w,B)=>{for(let _=b,M=b+p;_<M;_++){d(_),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let P=m,A=m+z;P<A;P++)if(c(P),r.needsUpdate=!0,n(r,h,P,_,x,g,w,B))return!0}return!1};if(s){const m=s;s=function(z,b,p,x,g,w,B,_){return m(z,b,p,x,g,w,B,_)?!0:y(z,b,p,x,g,w,B,_)}}else s=y}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return hi.set(t.min,t.max,e),hi.needsUpdate=!0,this.shapecast({intersectsBounds:i=>hi.intersectsBox(i),intersectsTriangle:i=>hi.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?Mr:dr)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Jn(this,t,e,i,s)}}const cs=self;cs.addEventListener("message",async({data:f})=>{let t=performance.now();function e(a){const o=performance.now();(o-t>=10||a===1)&&(postMessage({error:void 0,serialized:void 0,position:void 0,progress:a}),t=o)}const{id:i,index:s,position:n,options:r}=f;try{const a=new Ii;if(a.setAttribute("position",new mt(n,3,!1)),s&&a.setIndex(new mt(s,1,!1)),r.includedProgressCallback&&(r.onProgress=e),r.groups){const h=r.groups;for(const u in h){const l=h[u];a.addGroup(l.start,l.count,l.materialIndex)}}const o=new Ee(a,r),c=Ee.serialize(o,{cloneBuffers:!1});cs.postMessage({id:i,error:void 0,serialized:c,position:n,progress:1},[c.index.buffer,n.buffer,...c.roots])}catch(a){cs.postMessage({id:i,error:a,serialized:void 0,position:void 0,progress:1})}})})();
1533
+ `,Yr=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Hn],{type:"text/javascript;charset=utf-8"});function Yh(h){let t;try{if(t=Yr&&(self.URL||self.webkitURL).createObjectURL(Yr),!t)throw"";const e=new Worker(t,{name:h?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Hn),{name:h?.name})}}class Nn{constructor(){p(this,"running");p(this,"worker");this.running=!1,this.worker=new Yh,this.worker.onerror=t=>{throw t.message?new Error(`[GenerateMeshBVHWorker] Could not create Web Worker with error "${t.message}"`):new Error("[GenerateMeshBVHWorker] Could not create Web Worker.")}}isRunning(){return this.running}generate(t,e={}){if(this.running){S.warn("[GenerateMeshBVHWorker] Already running job.");return}if(!this.worker){S.warn("[GenerateMeshBVHWorker] Worker has been disposed.");return}const{worker:i}=this;this.running=!0;const s=new Map;t.forEach(n=>{s.set(n.id,n)});let r=0;return new Promise((n,a)=>{const o=()=>{++r===s.size&&(this.running=!1,i.onmessage=null,n())};i.onerror=l=>{S.warn("[GenerateMeshBVHWorker] "+l.message),a(new Error("[GenerateMeshBVHWorker] "+l.message)),this.running=!1},i.onmessage=l=>{this.running=!1;const{data:c}=l;if(c.error)S.warn(c.error),o();else if(c.serialized){const{serialized:u,position:f,id:m}=c,g=s.get(m),x=ks.MeshBVH.deserialize(u,g,{setIndex:!1}),y=Object.assign({setBoundingBox:!0},e);if(y.transferred&&(g.attributes.position.array=f),g.index)e.saveOriginalIndex&&!g.userData.originalIndex&&(g.userData.originalIndex=g.index.array),S.debug("before update, index:",g.index.array),g.index.array=u.index;else{const T=new Se.BufferAttribute(u.index,1,!1);g.setIndex(T)}g.index&&(S.debug("after update, index:",g.index.array),g.index.needsUpdate=!0),y.setBoundingBox&&!g.boundingBox&&(g.boundingBox=x.getBoundingBox(new Se.Box3)),g.boundsTree=x,o()}else e.onProgress&&e.onProgress(c.progress)};for(const[l,c]of s){const u=c.index?c.index.array:void 0,f=c.attributes.position,m=f.array;if(f.isInterleavedBufferAttribute||u&&u.isInterleavedBufferAttribute){S.warn("[GenerateMeshBVHWorker] InterleavedBufferAttribute are not supported for the geometry attributes."),o();continue}const g=[];e.transferred&&(g.push(m),u&&(g.push(u),e.saveOriginalIndex&&(c.userData.originalIndex=u.slice()))),i.postMessage({id:l,index:u,position:m,options:Object.assign(Object.assign({},e),{onProgress:null,includedProgressCallback:!!e.onProgress,groups:[...c.groups]})},g.length>0?g.map(x=>x.buffer):[])}})}dispose(){this.worker.terminate(),this.worker=void 0}}class Ns{constructor(t){p(this,"running");p(this,"workers");this.running=!1,this.workers=[];let e=1;t?e=t:window.navigator&&(e=Math.max(e,window.navigator.hardwareConcurrency-1));for(let i=0;i<e;i++)this.workers[i]=new Nn}isRunning(){return this.running}async generate(t,e={}){if(this.running){S.warn("[BVHHelper] Already running job.");return}if(this.workers.length===0){S.warn("[BVHHelper] Worker has been disposed.");return}return this.running=!0,new Promise(i=>{const s=this.workers.length,r=t.length,n=[],a=Math.floor(r/s),o=r%s;let l=0,c=0;for(let u=0;u<s;u++){const f=this.workers[u];if(u<o?(l=u*a+u,c=l+a+1):(l=u*a+o,c=l+a),l=Math.min(l,r),c=Math.min(c,r),l>=c)break;S.debug("startIndex: "+l+" endIndex: "+c),n.push(f.generate(t.slice(l,c),e))}Promise.allSettled(n).then(()=>{this.running=!1,i()})})}dispose(){for(let t=0;t<this.workers.length;t++)this.workers[t].dispose();this.workers=[]}static createMeshBvhSync(t,e={}){const i=new Set;t.forEach(s=>{s.traverse(r=>{const n=r;if(n.isMesh&&n.geometry&&oe.isMergedMesh(n)&&!(n instanceof d.InstancedMesh)){if(i.has(n.geometry.id))return;n.geometry.index&&e.saveOriginalIndex&&(n.geometry.userData.originalIndex=n.geometry.index.array.slice()),n.geometry.boundsTree=new ks.MeshBVH(n.geometry,e),i.add(n.geometry.id)}})})}static createMeshBvhAsync(t,e={}){const i=new Set,s=[];t.forEach(n=>{n.traverse(a=>{const o=a;if(o.isMesh&&o.geometry&&oe.isMergedMesh(o)&&!(o instanceof d.InstancedMesh)){if(i.has(o.geometry.id))return;s.push(o.geometry),i.add(o.geometry.id)}})});const r=new Ns;return r.generate(s,e).then(()=>{r.dispose()})}}class Xh{constructor(t,e,i,s,r){p(this,"object");p(this,"camera");p(this,"targetPixelHeight",100);p(this,"canvasHeight",800);this.camera=t,this.object=i,this.targetPixelHeight=s,this.canvasHeight=r,this.adjustSize(),e.addEventListener("update",()=>{this.adjustSize()})}adjustSize(){const t=new d.Box3;if(this.object.updateMatrix(),t.expandByObject(this.object),!t)return;const e=t.max.x-t.min.x,i=this.camera.position.distanceTo(this.object.position),s=Zh(e,i,this.canvasHeight);if(Math.abs(s-this.targetPixelHeight)<5)return;let n=this.object.scale.x;n*=this.targetPixelHeight/s,this.object.scale.set(n,n,n),this.object.updateMatrix()}}const Zh=(h,t,e=800,i=45)=>{const s=i*(Math.PI/180),r=2*Math.tan(s/2)*t,n=h/r;return e*n},Li=new d.Vector2,Ri=new d.Vector2,Fi=new d.Vector2,Xr=new d.Vector2,Kh=new d.Vector2,$h=new d.Vector2,ce=class ce extends pt{constructor(e){super(z.guid());p(this,"needsFrustumCulled");p(this,"renderOrder");p(this,"snapType");p(this,"osnapInfo");p(this,"drawSnapFunctions");p(this,"snapLineVisible");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.snapType=it.TripleCross,this.snapLineVisible=!1,this.snapType=e,this.drawSnapFunctions={TripleCross:this.drawTripleCorss.bind(this),Square:this.drawSquare.bind(this),Triangle:this.drawTriangle.bind(this),CircleWithCross:this.drawCircleWithCross.bind(this),Cross:this.drawCross.bind(this),Perpendicular:this.drawPerpendicular.bind(this)}}setSnapLineVisible(e){this.snapLineVisible=e}draw(e,i){this.osnapInfo&&(this.snapLineVisible&&this.drawSnapLine(e,i),e.save(),e.fillStyle=ce.FILL_COLOR_NONE,e.strokeStyle=ce.lineColor,e.lineWidth=ce.lineWidth,e.beginPath(),this.drawSnapFunctions[this.snapType](e,i),e.closePath(),e.fill(),e.stroke(),e.restore())}drawDebug(e,i){}drawSelect(e,i){}isPointInPath(e){return!1}drawSnapLine(e,i){e.save(),e.strokeStyle=ce.SNAP_LINE_COLOR,e.lineWidth=ce.lineWidth;const s=this.osnapInfo.line;if(!s)return;const r=this.transToScreenCoord(s.start,i),n=this.transToScreenCoord(s.end,i);e.moveTo(r.x,r.y),e.lineTo(n.x,n.y),e.stroke(),e.restore()}drawTripleCorss(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/1.6,n=Li.set(s.x,s.y-r),a=Ri.set(s.x-.87*r,s.y+r/1.4),o=Fi.set(s.x+.87*r,s.y+r/1.4);e.moveTo(s.x,s.y),e.lineTo(n.x,n.y),e.moveTo(s.x,s.y),e.lineTo(a.x,a.y),e.moveTo(s.x,s.y),e.lineTo(o.x,o.y)}drawSquare(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize,n=ce.iconSize;e.rect(s.x-r/2,s.y-n/2,r,n)}drawTriangle(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/1.6,n=Li.set(s.x,s.y-r),a=Ri.set(s.x-.87*r,s.y+r/2),o=Fi.set(s.x+.87*r,s.y+r/2);e.moveTo(n.x,n.y),e.lineTo(a.x,a.y),e.lineTo(o.x,o.y)}drawCircleWithCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2;e.arc(s.x,s.y,r,0,Math.PI*2),e.moveTo(s.x-r/1.8,s.y),e.lineTo(s.x+r/1.8,s.y),e.moveTo(s.x,s.y-r/1.8),e.lineTo(s.x,s.y+r/1.8)}drawCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2,n=Li.set(s.x-r,s.y-r),a=Ri.set(s.x+r,s.y+r),o=Fi.set(s.x+r,s.y-r),l=Xr.set(s.x-r,s.y+r);e.moveTo(n.x,n.y),e.lineTo(a.x,a.y),e.moveTo(o.x,o.y),e.lineTo(l.x,l.y)}drawPerpendicular(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2,n=Li.set(s.x,s.y),a=Ri.set(s.x-r,s.y),o=Fi.set(s.x,s.y+r),l=Xr.set(s.x-r,s.y-r),c=Kh.set(s.x-r,s.y+r),u=$h.set(s.x+r,s.y+r);e.moveTo(a.x,a.y),e.lineTo(n.x,n.y),e.lineTo(o.x,o.y),e.moveTo(l.x,l.y),e.lineTo(c.x,c.y),e.lineTo(u.x,u.y),e.lineTo(l.x,l.y)}update(e){this.osnapInfo=e}getClassType(){return"SnapDrawable"}};p(ce,"lineColor","rgba(255, 119, 0, 1)"),p(ce,"FILL_COLOR_NONE","rgba(0, 0, 0, 0)"),p(ce,"SNAP_LINE_COLOR","rgba(255, 240, 0, 0.3)"),p(ce,"lineWidth",2),p(ce,"iconSize",14);let ye=ce;xi._registerDrawableClass(ye);var Gn=(h=>(h[h.None=0]="None",h[h.Vertex=1]="Vertex",h[h.MiddlePoint=2]="MiddlePoint",h[h.Edge=4]="Edge",h[h.Face=8]="Face",h[h.FootOfPerpendicular=16]="FootOfPerpendicular",h[h.Intersection=32]="Intersection",h[h.CircleCenter=64]="CircleCenter",h))(Gn||{});const Jh=1e-5,se=new d.Vector3,fe=new d.Vector3,Gt=new d.Vector3,hi=new d.Vector3,wt=new d.Matrix4,ci=new d.Line3;function Qh(h,t){let e=Number.MAX_VALUE,i=0;for(let s=0;s<h.vertices.length;s++){const r=t.distanceTo(h.vertices[s]);r<e&&(i=s,e=r)}return{vertex:h.vertices[i],distance:e}}function ec(h){if(!(h.object instanceof d.Mesh)||!h.face)return;const t=h.object,e=t.geometry.attributes.position;let i=t.geometry.index;if(e.count<3)return;const s=oe.getBatchByFaceIndex(t,h.faceIndex);t.geometry.boundsTree&&(i=new d.BufferAttribute(t.geometry.userData.originalIndex,1,!1)),wt.identity(),t instanceof d.InstancedMesh&&h.instanceId!==void 0&&t.getMatrixAt(h.instanceId,wt),wt.premultiply(t.matrixWorld);const r=t.geometry.drawRange;let n,a=e.array;if(i){let m=Math.max(0,r.start),g=Math.min(i.count,r.start+r.count);if(n=i.array,s){m=Math.max(m,s.indexStart),g=Math.min(g,s.indexStart+s.indexCount),n=i.array.slice(m,g),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3);for(let x=0;x<n.length;x++)n[x]=n[x]-s.positionStart}else(m!==0||g!==i.count)&&(n=i.array.slice(m,g))}else{let m=Math.max(0,r.start),g=Math.min(e.count,r.start+r.count);s?(m=Math.max(m,s.positionStart),g=Math.min(g,s.positionStart+s.positionCount),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3)):(m!==0||g!==e.count)&&(a=e.array.slice(m*3,g*3));const x=a.length/3;n=x>65535?new Uint32Array(x):new Uint16Array(x);for(let y=0,T=x;y<T;y++)n[y]=y}const o=cn.buildEdge(a,n,20);let l=Number.MAX_VALUE,c=0;for(let m=0;m<o.length;m+=2){const g=o[m],x=o[m+1];se.set(a[g*3],a[g*3+1],a[g*3+2]),se.applyMatrix4(wt),fe.set(a[x*3],a[x*3+1],a[x*3+2]),fe.applyMatrix4(wt),ci.set(se,fe),ci.closestPointToPoint(h.point,!0,Gt);const y=h.point.distanceTo(Gt);y<l&&(c=m,l=y,hi.copy(Gt))}const u=o[c],f=o[c+1];return se.set(a[u*3],a[u*3+1],a[u*3+2]),se.applyMatrix4(wt),fe.set(a[f*3],a[f*3+1],a[f*3+2]),fe.applyMatrix4(wt),{vertices:[se.clone(),fe.clone()],vertex:hi.clone(),distance:l}}class tc{constructor(t){p(this,"drawableList",new bi("snap"));p(this,"overlayRender");p(this,"markers",{});p(this,"activeOSnapType",0);p(this,"snapToleranceInWorldCoord",1);p(this,"intersectionLimit",10);p(this,"osnapTypePriorities",{1:0,2:1,64:2,32:3,16:4,4:5,8:6,0:100});p(this,"enabledOSnapTypes",127);this.overlayRender=t,this.overlayRender?.addDrawableList(this.drawableList),this.initOSnapMarkers()}initOSnapMarkers(){const t=new ye(it.TripleCross),e=new ye(it.Square),i=new ye(it.Triangle),s=new ye(it.CircleWithCross),r=new ye(it.Cross),n=new ye(it.Perpendicular);this.markers[1]=e,this.markers[2]=i,this.markers[4]=t,this.markers[32]=r,this.markers[64]=s,this.markers[16]=n,Object.values(this.markers).forEach(a=>{a.visible=!1,this.drawableList.addDrawable(a)})}isOSnapTypeEnabled(t){return!!(this.enabledOSnapTypes&t)}setOSnapTypeEnabled(t,e){if(e)this.enabledOSnapTypes|=t;else{const i=~t;this.enabledOSnapTypes&=i}}setSnapTolerance(t){this.snapToleranceInWorldCoord=t}getSnapTolerance(){return this.snapToleranceInWorldCoord}setIntersectionLimit(t){this.intersectionLimit=t}getIntersectionLimit(){return this.intersectionLimit}getMarkerLineColor(){return qt.colorStr2Rgba(ye.lineColor)}setMarkerLineColor(t){ye.lineColor=qt.rgba2Color(t)}getMarkerLineWidth(){return ye.lineWidth}setMarkerLineWidth(t){ye.lineWidth=t}getMarkerIconSize(){return ye.iconSize}setMarkerIconSize(t){ye.iconSize=t}getMarker(t){return this.markers[t]}setAllSnapLinesVisible(t){Object.values(this.markers).forEach(e=>{e.setSnapLineVisible(t)})}deactivate(){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1,this.overlayRender?.render()),this.activeOSnapType=0}destroy(){}handleSnap(t,e,i){if(!t||t.length<1){this.deactivate();return}S.debug("[OSnap] intersections before handleSnap:",t);const s=[];let r=!1,n;for(const o of t)o.object instanceof d.Mesh?(!n&&(n=o.point),!r&&o.object.name!=="groundPlane"&&(s.push(o),r=!0)):s.push(o);if(!e&&n){n.setZ(0);for(const l of s)l.point.z=0,l.distance=l.point.distanceTo(n);const o=l=>l instanceof d.Points?0:l instanceof d.LineSegments?2:l instanceof d.Line?1:3;s.sort((l,c)=>{const u=o(l.object),f=o(c.object);return u!==f?u-f:l.distance-c.distance})}return n||(S.warn("[OSnap] Potential to produce erroneous snap results"),n=s[0].point),S.debug("[OSnap] intersections:",s),S.debug("[OSnap] mousePosition:",n),this.getSnapPointAndUpdateMarker(n,s,e,i)?.clone()||n}getSnapPointAndUpdateMarker(t,e,i,s){if(!e.length){this.activateMarker(0);return}const r=this.getSnapInfo(t,e,i,s);if(!r||r.type===0){this.activateMarker(0);return}return this.activateMarker(r.type,r),r.point}activateMarker(t,e){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1),this.activeOSnapType=t;const i=this.markers[t];i&&e&&(i.update(e),i.visible=!0),this.overlayRender?.render()}getFootOfPerpendicular(t,e,i=Jh){const{start:s,end:r}=e,n=s.x-r.x,a=s.y-r.y,o=s.z-r.z;if(s.distanceTo(r)<i)return s.clone();let l=(t.x-s.x)*(s.x-r.x)+(t.y-s.y)*(s.y-r.y)+(t.z-s.z)*(s.z-r.z);return l=l/(n*n+a*a+o*o),new d.Vector3(s.x+l*n,s.y+l*a,s.z+l*o)}getSnapInfo(t,e,i,s){const r=this.snapToleranceInWorldCoord*2;S.debug("[OSnap] snap radius:",r);const n=[],a={line:void 0};let o=this.osnapTypePriorities[0];for(let l=0;l<e.length&&l<this.intersectionLimit;++l){const c=e[l],u=c.object;let f;u instanceof d.Mesh?f=this.getOsnapInfoListFromMesh(t,c,r,o):u instanceof d.Line?f=this.getOsnapInfoListFromLine(t,c,i,r,a,o,s):u instanceof d.Points&&(f=this.getOsnapInfoListFromPoint(t,c,i,r,o)),f&&(o=this.osnapTypePriorities[f.type],n.push(f))}if(n.length!==0)return n.sort((l,c)=>{const u=this.osnapTypePriorities[l.type],f=this.osnapTypePriorities[c.type];return u!==f?u-f:l.distance-c.distance}),n[0]}getOsnapInfoListFromMesh(t,e,i,s){if(s<this.osnapTypePriorities[1])return;const r=Date.now(),n=ec(e);if(!n){S.warn("[OSnap] Failed to get edge !");return}const a=Date.now();S.debug("[OSnap] getEdgeSnappingInfo took "+(a-r)/1e3+"s "),S.debug("[OSnap] edge:",n);const o=Qh(n,t);if(S.debug("[OSnap] vertex:",o),o.distance<=i&&this.isOSnapTypeEnabled(1))return{distance:o.distance,type:1,point:o.vertex};if(n.distance<=i){if(this.isOSnapTypeEnabled(2)&&s<this.osnapTypePriorities[2])return;se.copy(n.vertices[0]),se.add(n.vertices[1]),se.divideScalar(2);const l=se.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:se.clone()}:!this.isOSnapTypeEnabled(4)||s<this.osnapTypePriorities[4]?void 0:{distance:n.distance,type:4,point:n.vertex,line:{start:n.vertices[0],end:n.vertices[1]}}}else S.debug("[OSnap] Face")}getOsnapInfoFromSegment(t,e,i,s,r,n,a){const o={start:e,end:i};if(a&&n>=this.osnapTypePriorities[16]&&this.isOSnapTypeEnabled(16)){const m=this.getFootOfPerpendicular(a,o,s),g=t.distanceTo(m);if(g<=s)return{distance:R.floorNumber(g,7),type:16,point:m.clone()}}if(n<this.osnapTypePriorities[1])return;ci.set(e,i),ci.closestPointToPoint(t,!0,Gt);const l=t.distanceTo(Gt);if(l>s)return;const c=t.distanceTo(e),u=t.distanceTo(i);if(Math.min(c,u)<=s&&this.isOSnapTypeEnabled(1)){let m=c,g=e;return u<c&&(m=u,g=i),{distance:R.floorNumber(m,7),type:1,point:g.clone()}}if(n<this.osnapTypePriorities[2])return;ci.getCenter(hi);const f=t.distanceTo(hi);if(f<s&&this.isOSnapTypeEnabled(2))return{point:hi.clone(),distance:R.floorNumber(f,7),type:2};if(!(n<this.osnapTypePriorities[4])){if(r.line&&this.isOSnapTypeEnabled(32)){const m=U.getLineSegmentsIntersectingPoint(r.line,o);if(!m)return;const g=t.distanceTo(m)/2;return g<s?(r.line=void 0,{point:m.clone(),distance:R.floorNumber(g,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return r.line={start:e.clone(),end:i.clone()},{point:Gt.clone(),distance:R.floorNumber(l,7),type:4,line:{start:e.clone(),end:i.clone()}}}}getOsnapInfoListFromLine(t,e,i,s,r,n,a){const o=[],l=e.object,c=l instanceof d.LineSegments?2:1,u=l.geometry.index,f=l.geometry.attributes.position,m=l.geometry.drawRange,g=oe.getBatchByLineIndex(l,e.index);if(u){let x=Math.max(0,m.start),y=Math.min(u.count,m.start+m.count);g&&(x=Math.max(x,g.indexStart),y=Math.min(y,g.indexStart+g.indexCount));for(let T=x,v=y;T<v-1;T+=c){const b=u.getX(T),E=u.getX(T+1);se.fromBufferAttribute(f,b),fe.fromBufferAttribute(f,E),se.applyMatrix4(l.matrixWorld),fe.applyMatrix4(l.matrixWorld),!i&&(se.setZ(0),fe.setZ(0));const O=this.getOsnapInfoFromSegment(t,se,fe,s,r,n,a);O&&(n=this.osnapTypePriorities[O.type],o.push(O))}}else{let x=Math.max(0,m.start),y=Math.min(f.count,m.start+m.count);g&&(x=Math.max(x,g.positionStart),y=Math.min(y,g.positionStart+g.positionCount));for(let T=x,v=y;T<v-1;T+=c){se.fromBufferAttribute(f,T),fe.fromBufferAttribute(f,T+1),se.applyMatrix4(l.matrixWorld),fe.applyMatrix4(l.matrixWorld),!i&&(se.setZ(0),fe.setZ(0));const b=this.getOsnapInfoFromSegment(t,se,fe,s,r,n,a);b&&(n=this.osnapTypePriorities[b.type],o.push(b))}}if(o.length!==0)return o.sort((x,y)=>{const T=this.osnapTypePriorities[x.type],v=this.osnapTypePriorities[y.type];return T!==v?T-v:x.distance-y.distance}),o[0]}getOsnapInfoListFromPoint(t,e,i,s,r){if(r<this.osnapTypePriorities[1])return;const n=e.object,a=n.geometry.getAttribute("position");se.fromBufferAttribute(a,e.index),se.applyMatrix4(n.matrixWorld),fe.copy(t),!i&&(se.setZ(0),fe.setZ(0));const o=fe.distanceTo(se);if(o>s)return;const l={distance:o,point:se.clone(),type:1};if(n.userData.type==="CircleCenter"){if(!this.isOSnapTypeEnabled(64))return;l.type=64}else if(S.debug("[OSnap] Other types of vertices !"),!this.isOSnapTypeEnabled(1))return;return l}getIntersectsIncludeOutline(t,e){const i=t.slice(),s=[];for(let n=0;n<t.length&&n<this.intersectionLimit;n++){const a=t[n].object;if(a.updateWorldMatrix(!0,!1),a instanceof d.Mesh&&!$.hasOutline(a,!1)){const o=$.createOutline(a.geometry);o.visible=!1,a.add(o),o.updateWorldMatrix(!0,!1),s.push(o)}}let r=[];return s.length>0&&(r=e.intersectObjects(s)||[],S.debug("[OSnap] Intersected with newly created edges: ",r),r.length>0&&i.push(...r)),i.sort((n,a)=>n.distance-a.distance),i}}class qn{constructor(t,e,i){p(this,"node");p(this,"parentNode");p(this,"target");p(this,"childNode");p(this,"follow",t=>{this.node.style.left=t.offsetX+15+"px",this.node.style.top=t.offsetY-30+"px"});p(this,"show",()=>this.node.hasAttribute("hidden")&&this.node.removeAttribute("hidden"));p(this,"hide",()=>!this.node.hasAttribute("hidden")&&this.node.setAttribute("hidden",""));p(this,"destroy",()=>{this.target?this.target.removeEventListener("mousemove",this.follow):document.removeEventListener("mousemove",this.follow),this.parentNode.removeChild(this.node)});this.node=document.createElement("div"),this.node.id=t,e&&this.node.append(e),this.childNode=document.createElement("div"),this.target=i?.target,this.parentNode=i?.parentNode||document.body,i?.followPointer&&(this.node.classList.add("follow-tooltip"),this.target?this.target.addEventListener("mousemove",this.follow):document.addEventListener("mousemove",this.follow)),this.parentNode.appendChild(this.node),!i?.showOnCreate&&this.node.setAttribute("hidden","")}setContent(t){this.node.textContent&&(this.node.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.node.append(t),this.node.appendChild(this.childNode)}updateChildContent(t){this.childNode.textContent&&(this.childNode.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.childNode.append(t)}}class ic{constructor(t){p(this,"viewer");p(this,"active",!1);p(this,"tooltip");p(this,"resolve");p(this,"reject");p(this,"isResolvedOrRejected",!1);p(this,"mouseClicked",t=>{const e=t;if(e.markupData){const i=e.markupData.id,s=this.viewer.getOverlayRender().getDrawableById(i);if(s){let r=s.getBounds();r=r.clone().expandByScalar(20*this.viewer.getPixelSizeInWorldCoord());const n=pe.world2NormalizedScreen(r.min,this.camera,this.viewerContainer),a=pe.world2NormalizedScreen(r.max,this.camera,this.viewerContainer),o=new d.Box2(new d.Vector2(Math.min(n.x,a.x),Math.min(n.y,a.y)),new d.Vector2(Math.max(n.x,a.x),Math.max(n.y,a.y)));o.min.x=Math.max(o.min.x,0)*this.viewerContainer.clientWidth,o.min.y=Math.max(o.min.y,0)*this.viewerContainer.clientHeight,o.max.x=Math.min(o.max.x,1)*this.viewerContainer.clientWidth,o.max.y=Math.min(o.max.y,1)*this.viewerContainer.clientHeight,this.resolve&&(this.resolve(o),this.isResolvedOrRejected=!0),this.deactivate();const l=this.viewer;typeof l.clearSelection=="function"&&l.clearSelection()}}});p(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("PickMarkupHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.viewer.addEventListener(re.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new qn("pick-markup-tooltip",Re.t("Tooltip.pickMarkup"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("pick-markup-tooltip");t&&(t.style.pointerEvents="none");const e=Re.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(re.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(re.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(re.PickMarkupDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}async pick(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),!this.isResolvedOrRejected&&this.reject&&this.reject("PickMarkupHelper is not done for some reason!")}}const Ht=class Ht{constructor(t){p(this,"viewer");p(this,"input");p(this,"mouseDown",!1);p(this,"mouseMove",!1);p(this,"mouseDownPositionX",-1);p(this,"mouseDownPositionY",-1);p(this,"tempKey");p(this,"tempTouch");p(this,"tempEnableRotate",!1);p(this,"rectDom");p(this,"tooltip");p(this,"active",!1);p(this,"resolve");p(this,"reject");p(this,"isResolvedOrRejected",!1);p(this,"mousedown",t=>{if(t.button===0){this.mouseDown=!0;const e=new d.Vector2(t.x,t.y);this.mouseDownPositionX=e.x,this.mouseDownPositionY=e.y,this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0}});p(this,"mousemove",t=>{if(!this.mouseDown)return;const e=new d.Vector2(t.x,t.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(e.x-this.mouseDownPositionX)>=5||Math.abs(e.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const s=new d.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),r=new d.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y));this.drawRect(s,r)}});p(this,"mouseup",t=>{if(this.mouseDown&&this.mouseMove){const e=new d.Vector2(t.x,t.y),i=new d.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),s=new d.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y)),r=new d.Box2(i,s);this.resolve&&(this.resolve(r),this.isResolvedOrRejected=!0),this.deactivate(),this.setRectDomVisible(!1)}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1});p(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t,this.input=t.getInputManager()}get viewerContainer(){return this.viewer.viewerContainer}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("BoxSelectHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.input.addEventListener("pointerdown",this.mousedown),this.input.addEventListener("pointermove",this.mousemove),this.input.addEventListener("pointerup",this.mouseup),this.input.addEventListener("keydown",this.keydown),this.viewer.getCameraManager().enableMouseLeft(!1),this.tooltip=new qn("box-select-tooltip",Re.t("Tooltip.boxSelect"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("box-select-tooltip");t&&(t.style.pointerEvents="none");const e=Re.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(re.BoxSelectActivate)}deactivate(){this.active=!1,this.input.removeEventListener("pointerdown",this.mousedown),this.input.removeEventListener("pointermove",this.mousemove),this.input.removeEventListener("pointerup",this.mouseup),this.input.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.getCameraManager().enableMouseLeft(!0),this.viewer.dispatchEvent(re.BoxSelectDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}drawRect(t,e){!this.rectDom&&(this.rectDom=document.createElement("div"),this.rectDom.style.cssText=`position: absolute;border: ${Ht.BORDER_WIDTH} solid ${Ht.BORDER_COLOR};`,this.viewerContainer.appendChild(this.rectDom)),this.setRectDomVisible(!0),this.rectDom.style.left=t.x+"px",this.rectDom.style.top=t.y+"px";const i=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y);this.rectDom.style.width=i+"px",this.rectDom.style.height=s+"px"}setRectDomVisible(t){this.rectDom&&(this.rectDom.style.display=t?"inline-block":"none")}async select(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),this.rectDom?.remove(),this.rectDom=void 0,!this.isResolvedOrRejected&&this.reject&&this.reject("BoxSelectHelper is not done for some reason!")}};p(Ht,"BORDER_COLOR","#fff000"),p(Ht,"BORDER_WIDTH","2px");let $i=Ht;class Wn{constructor(t){p(this,"viewer");p(this,"boxSelectHelper");p(this,"active",!1);this.viewer=t,this.boxSelectHelper=new $i(t)}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}isActive(){return this.active}activate(){this.active=!0,this.boxSelectHelper?.select().then(t=>{t&&this.handleZoomToRect(t.min,t.max)})}deactivate(){this.active=!1,this.boxSelectHelper?.deactivate()}pickPositionByScreenPoint(t){return this.viewer.pickObject(t)?.point}handleZoomToRect(t,e){const i=this.pickPositionByScreenPoint(t),s=this.pickPositionByScreenPoint(e);if(i&&s){const r=new d.Vector3(Math.min(i.x,s.x),Math.min(i.y,s.y),Math.min(i.z,s.z)),n=new d.Vector3(Math.max(i.x,s.x),Math.max(i.y,s.y),Math.max(i.z,s.z)),a=new d.Box3(r,n);this.viewer.zoomToBBox(a)}}destroy(){this.boxSelectHelper?.destroy(),this.boxSelectHelper=void 0}}function Zr(h){return h?h.replace(/%%[dD]/g,"°").replace(/%%[cC]/g,"⌀").replace(/%%[pP]/g,"±").replace(/%%(U|O)/gi,"").replace(/\\P/g," ").replace(/\\[A-Za-z][^;\\]*;/g,"").replace(/[{}]/g,"").replace(/\\\\/g,"\\").replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))).trim():""}const zi=new d.Box3,sc=new d.Vector3;function rc(h,t){return h.trim().toLowerCase()===t?2e6:0}function nc(h,t){const e=h.toLowerCase(),i=e.indexOf(t);if(i>=0)return(e===t?2e6:1e6)+(1e3-i)-Math.min(e.length,500);let s=0,r=-1,n=-1,a=0;for(let l=0;l<t.length;l++){const c=t[l];let u=-1;for(;s<e.length;s++)if(e[s]===c){u=s;break}if(u<0)return 0;r<0?r=u:n>=0&&u-n>1&&(a+=u-n-1),n=u,s=u+1}const o=5e5-a*50-r*5-Math.min(e.length,500);return o>0?o:1}class Is{constructor(t){p(this,"viewer");p(this,"overlayRender");p(this,"drawableList");p(this,"indexedModelObject");p(this,"index",[]);this.viewer=t,this.overlayRender=this.viewer.getOverlayRender()}getMasterModel(){return this.viewer.loadedModels.find(t=>this.viewer.masterModelId===t.modelId)}buildIndex(){const t=this.getMasterModel();if(!t){this.index=[],this.indexedModelObject=void 0;return}const e=t.getModelObject();if(e===this.indexedModelObject&&this.index.length>0)return;this.indexedModelObject=e,this.index=[];const i=new d.Matrix4,s=new d.Vector3,r=new Map;e.updateWorldMatrix(!0,!0);const n=(a,o,l,c,u)=>{if(a&&r.has(a)){r.get(a).box.union(u);return}r.set(a||o+c,{text:o,layer:l,layoutName:c,box:u.clone()})};e.traverse(a=>{const o=a.userData;if(o){if(typeof o.textContent=="string"&&o.textContent.length){const l=Zr(o.textContent);if(!l||(zi.makeEmpty(),zi.setFromObject(a),zi.isEmpty()))return;n(o.handle||"",l,o.layer||"0",this.findLayoutName(a),zi);return}if(Array.isArray(o.batches)){const l=a.geometry?.getAttribute?.("position");if(!l)return;i.copy(a.matrixWorld);for(const c of o.batches){const u=c?.userData?.textContent;if(typeof u!="string"||!u.length)continue;const f=Zr(u);if(!f)continue;const m=new d.Box3,g=c.positionStart||0,x=c.positionCount||0;for(let y=g;y<g+x;y++)s.fromBufferAttribute(l,y).applyMatrix4(i),m.expandByPoint(s);m.isEmpty()||n(c.userData.handle||"",f,c.userData.layer||"0",this.findLayoutName(a),m)}}}}),r.forEach((a,o)=>{this.index.push({handle:o,layer:a.layer,layoutName:a.layoutName,text:a.text,box:a.box})})}findLayoutName(t){let e=t;for(;e;){if(e.userData?.isLayoutLevelObject===!0)return e.name||"Model";e=e.parent}return"Model"}search(t,e){const i=(t||"").trim().toLowerCase();if(!i)return[];this.buildIndex();const s=e?.mode??"fuzzy",r=e?.layer?.trim().toLowerCase(),n=e?.maxResults??200,a=[];for(const o of this.index){if(r&&o.layer.toLowerCase()!==r)continue;const l=s==="exact"?rc(o.text,i):nc(o.text,i);l>0&&a.push({item:o,score:l})}return a.sort((o,l)=>l.score-o.score),a.slice(0,n).map(o=>o.item)}focus(t){if(!t)return;this.viewer.activateLayout(t.layoutName),this.highlight(t);const e=t.box.clone();this.viewer.zoomToBBox(e.expandByScalar(Math.max(e.getSize(sc).length()*.5,1)))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new bi("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new Je(z.guid(),[t.box.clone()],[1,.55,0,1],[1,.55,0,.15])),this.viewer.enableRender())}clearHighlight(){this.drawableList?.clear(),this.viewer.enableRender()}invalidate(){this.indexedModelObject=void 0,this.index=[]}destroy(){this.clearHighlight(),this.overlayRender=void 0,this.drawableList=void 0,this.index=[],this.indexedModelObject=void 0}}class ac extends pt{constructor(e){super("MobileHelper");p(this,"position");p(this,"needsFrustumCulled");p(this,"renderOrder");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.position=e}setPosition(e){this.position=e}isPointInPath(e,i){return!1}draw(e,i){this.drawInnerCircle(e),this.drawOuterRing(e),this.drawSnapTriangle(e)}drawInnerCircle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(137, 137, 138, 0.8)",e.beginPath(),e.arc(i,s,25,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}drawOuterRing(e){const{x:i,y:s}=this.position;e.save(),e.strokeStyle="rgba(17, 17, 19, 0.8)",e.lineWidth=10,e.beginPath(),e.arc(i,s,30,0,Math.PI*2),e.closePath(),e.stroke(),e.restore(),e.save(),e.strokeStyle="rgba(173, 173, 174, 0.8)",e.lineWidth=3,e.beginPath(),e.arc(i,s,35,0,Math.PI*2),e.closePath(),e.stroke(),e.restore()}drawSnapTriangle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(17, 17, 19, 0.8)",e.strokeStyle="rgba(137, 137, 138, 0.8)",e.lineWidth=2,e.beginPath(),e.moveTo(i-35,s-35),e.lineTo(i-35+12,s-35),e.lineTo(i-35,s-35+12),e.closePath(),e.fill(),e.stroke(),e.restore()}translate(e,i){this.position.add(new d.Vector2(e,i))}getTouchPoint(){return{x:this.position.x-35,y:this.position.y-35}}isIntersect(e){return this.position.x-35<e.x&&this.position.y-35<e.y&&this.position.x+35>e.x&&this.position.y+35>e.y}drawSelect(e,i){}getClassType(){return"MobileTouchHelperDrawable"}}var Le=(h=>(h[h.Left=0]="Left",h[h.Middle=1]="Middle",h[h.Right=2]="Right",h[h.Back=3]="Back",h[h.Forward=4]="Forward",h))(Le||{});class Yn extends mt{constructor(e){super();p(this,"element");p(this,"enabled");p(this,"keyboardEnabled");p(this,"mouseDownPositionX");p(this,"mouseDownPositionY");p(this,"lastLeftPointerUpTime");p(this,"pointers");p(this,"handleClick");p(this,"handlePointerDown");p(this,"handlePointerMove");p(this,"handlePointerUp");p(this,"handlePointerCancel");p(this,"handleMouseWheel");p(this,"handleContextMenu");p(this,"handlePointerEnter");p(this,"handlePointerLeave");p(this,"handleResize");p(this,"handleKeydown");p(this,"handleKeyup");p(this,"style");this.enabled=!0,this.keyboardEnabled=!0,this.mouseDownPositionX=0,this.mouseDownPositionY=0,this.lastLeftPointerUpTime=0,this.pointers=[],this.handleClick=i=>{if(!this.enabled)return;const s=this.getBaseEvent(i);this.dispatchEvent("click",s)},this.handlePointerDown=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isDoubleClick(s)?(this.lastLeftPointerUpTime=0,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.dispatchEvent("dblclick",s)):(this.mouseDownPositionX=s.x,this.mouseDownPositionY=s.y),this.dispatchEvent("pointerdown",s),i.pointerType==="touch"?(this.pointers.push(s),s.pointers=this.pointers,this.dispatchEvent("touchstart",s)):this.dispatchEvent("mousedown",s)},this.handlePointerMove=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isCloseToLastPosition(s)||(this.dispatchEvent("pointermove",s),i.pointerType==="touch"?(this.updatePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchmove",s)):this.dispatchEvent("mousemove",s))},this.handlePointerUp=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);s.button===0&&(this.lastLeftPointerUpTime=s.timestamp),this.dispatchEvent("pointerup",s),i.pointerType==="touch"?(this.removePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchend",s)):this.dispatchEvent("mouseup",s)},this.handlePointerCancel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointercancel",this.getBaseEvent(i)))},this.handleMouseWheel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("wheel",this.getBaseEvent(i)))},this.handleContextMenu=i=>{if(this.enabled)return this.stop(i),this.dispatchEvent("contextmenu",this.getBaseEvent(i)),!1},this.handlePointerEnter=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerenter",this.getBaseEvent(i)))},this.handlePointerLeave=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerleave",this.getBaseEvent(i)))},this.handleResize=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("resize",this.getBaseEvent(i)))},this.handleKeydown=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keydown",this.getBaseEvent(i))},this.handleKeyup=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keyup",this.getBaseEvent(i))},this.style={},this.element=e,this.bindEvents()}getEnabled(){return this.enabled}setEnabled(e){this.enabled=e}getkKeyboardEnabled(){return this.keyboardEnabled}setkKeyboardEnabled(e){this.keyboardEnabled=e}setCursor(e){this.element.style&&(this.element.style.cursor=e||"default")}bindEvents(){this.element.style.touchAction="none",this.element.style.userSelect="none",this.element.style.webkitUserSelect="none",this.element.addEventListener("click",this.handleClick),this.element.addEventListener("pointerdown",this.handlePointerDown),this.element.addEventListener("pointermove",this.handlePointerMove),this.element.addEventListener("pointerup",this.handlePointerUp),this.element.addEventListener("pointercancel",this.handlePointerCancel),this.element.addEventListener("pointerenter",this.handlePointerEnter),this.element.addEventListener("pointerleave",this.handlePointerLeave),this.element.addEventListener("contextmenu",this.handleContextMenu),this.element.addEventListener("wheel",this.handleMouseWheel,{passive:!1}),window.addEventListener("resize",this.handleResize),window.addEventListener("keydown",this.handleKeydown),window.addEventListener("keyup",this.handleKeyup)}unBindEvents(){this.element.removeEventListener("pointerdown",this.handlePointerDown),this.element.removeEventListener("pointermove",this.handlePointerMove),this.element.removeEventListener("pointerup",this.handlePointerUp),this.element.removeEventListener("pointerenter",this.handlePointerEnter),this.element.removeEventListener("pointerleave",this.handlePointerLeave),this.element.removeEventListener("contextmenu",this.handleContextMenu),this.element.removeEventListener("wheel",this.handleMouseWheel),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),window.removeEventListener("keyup",this.handleKeyup),this.element.style.touchAction="",this.element.style.userSelect="",this.element.style.webkitUserSelect=""}getBaseEvent(e){const i=e,s={x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0,deltaX:0,deltaY:0,movementX:0,movementY:0,deltaMode:0,pointerId:0,timestamp:0,buttons:0,pointerType:"mouse",altKey:!1,ctrlKey:!1,shiftKey:!1,metaKey:!1,originalEvent:i};if(s.timestamp=i.timeStamp,ji(i,"clientX"))if(s.altKey=i.altKey,s.ctrlKey=i.ctrlKey,s.shiftKey=i.shiftKey,s.clientX=i.clientX,s.clientY=i.clientY,s.button=i.button,ji(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const r=pe.getScreenCoordinateByEvent(i,this.element);s.x=r.x,s.y=r.y,s.movementX=i.movementX,s.movementY=i.movementY}else ji(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else ji(i,"code")&&(s.altKey=i.altKey,s.ctrlKey=i.ctrlKey,s.shiftKey=i.shiftKey,s.metaKey=i.metaKey,s.code=i.code);return s}stop(e){e.preventDefault()}updatePointers(e){for(let i=0;i<this.pointers.length;i++)if(e.pointerId==this.pointers[i].pointerId){this.pointers[i]=e;break}}removePointers(e){for(let i=0;i<this.pointers.length;i++)if(this.pointers[i].pointerId==e.pointerId){this.pointers.splice(i,1);break}}getBoundingClientRect(){return this.element.getBoundingClientRect()}isCloseToLastPosition(e){return this.mouseDownPositionX===-1||this.mouseDownPositionY===-1?!1:Math.abs(e.x-this.mouseDownPositionX)<5&&Math.abs(e.y-this.mouseDownPositionY)<5}isDoubleClick(e){const s=e.timestamp-this.lastLeftPointerUpTime;return!!(e.button===0&&s<300&&this.isCloseToLastPosition(e))}}function ji(h,t){return h[t]!==void 0}class oc{constructor(t){p(this,"CLEAR_COLOR");p(this,"CLEAR_COLOR_ALPHA");p(this,"EMPTY_MODEL_ID");p(this,"viewer");p(this,"raycaster");p(this,"pickingTexture");this.CLEAR_COLOR=new d.Color().setRGB(1,1,1),this.CLEAR_COLOR_ALPHA=1,this.EMPTY_MODEL_ID=255,this.viewer=t,this.raycaster=new d.Raycaster,this.pickingTexture=new d.WebGLRenderTarget(1,1)}get scene(){return this.viewer.scene}get camera(){return this.viewer.camera}get renderer(){return this.viewer.renderer}get overlayRender(){return this.viewer.getOverlayRender()}get viewerContainer(){return this.viewer.viewerContainer}getRaycaster(){return this.raycaster}pickObjectsByNdc(t,e,i){return!e||e.length===0?[]:(this.raycaster.setFromCamera(t,this.camera),this.setLayerChannels(i),this.raycaster.intersectObjects(e,!0)||[])}pickObject(t,e,i,s){const r=this.pickObjects(t,e,i,s);if(r.length!==0)return r[0]}pickObjects(t,e,i,s=0){const r=pe.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const n=[],a=new Map,o=pe.screen2Ndc(t,this.camera,this.viewerContainer),l=pe.screen2Ndc({x:t.x+s,y:t.y},this.camera,this.viewerContainer),c=new d.Vector3(o.x,o.y,0).unproject(this.camera),u=new d.Vector3(l.x,l.y,0).unproject(this.camera),f=c.distanceTo(u),m=this.raycaster.params.Line.threshold;this.raycaster.params.Line.threshold=f,this.setLayerChannels(i);const g=8;for(let y=0;y<g;y++){const T=y/g*Math.PI*2,v=Math.cos(T)*s,b=Math.sin(T)*s,E={x:t.x+v,y:t.y+b},O=pe.screen2Ndc(E,this.camera,this.viewerContainer);this.raycaster.setFromCamera(O,this.camera),this.raycaster.layers.enableAll();const _=this.raycaster.intersectObjects(e,!0)||[];for(const C of _)C.object&&!a.has(C.object.uuid)&&(a.set(C.object.uuid,C),n.push(C))}this.raycaster.setFromCamera(o,this.camera);const x=this.raycaster.intersectObjects(e,!0)||[];for(const y of x)y.object&&!a.has(y.object.uuid)&&(a.set(y.object.uuid,y),n.push(y));if(this.raycaster.params.Line.threshold=m,n.length>1){const y=this.raycaster.ray.origin.clone();n.sort((T,v)=>{const b=T.point||T.object.getWorldPosition(new d.Vector3),E=v.point||v.object.getWorldPosition(new d.Vector3);return b.distanceTo(y)-E.distanceTo(y)})}return n}return this.pickObjectsByNdc(r,e,i)}pickDrawable(t){return this.overlayRender.getDrawablesByPosition(t)}pick(t,e){const i=this.pickBuffer(t,e),s=[i[0],i[1],i[2],i[3]],r=Eh(s),n=_h(s);if(r!==this.EMPTY_MODEL_ID)return S.info("[PickMgr] Picked: tilesetId("+r+"), userId("+n+")"),{tilesetId:r,userId:n}}setLayerChannels(t){t&&t.length>0?(this.raycaster.layers.disableAll(),t.forEach(e=>{this.raycaster.layers.enable(e)})):this.raycaster.layers.enableAll()}pickBuffer(t,e,i=1,s=1){const{pickingTexture:r,renderer:n,camera:a}=this;r.setSize(i,s);const o=n.getPixelRatio(),l=n.getContext().drawingBufferWidth,c=n.getContext().drawingBufferHeight,u=t.x*o|0,f=t.y*o|0;a.setViewOffset(l,c,u,f,i,s),n.setRenderTarget(r);const m=new d.Color;n.getClearColor(m);const g=n.getClearAlpha();n.setClearColor(this.CLEAR_COLOR,this.CLEAR_COLOR_ALPHA),n.render(e,a);const x=new Uint8Array(4*i*s);return n.readRenderTargetPixels(r,0,0,i,s,x),n.setRenderTarget(null),a.clearViewOffset(),n.setClearColor(m,g),x}}const Kr=new d.Vector3;class lc{constructor(t){p(this,"viewer");p(this,"scene");p(this,"renderer");p(this,"pmremGenerator");p(this,"lights");p(this,"modelGroup");this.viewer=t;const e=new d.Scene;e.matrixAutoUpdate=Ne,e.matrixWorldAutoUpdate=Ne,this.scene=e,this.modelGroup=new d.Group,this.modelGroup.name="models",this.scene.add(this.modelGroup);const{width:i,height:s,viewerContainer:r}=t.container,n=new d.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0});n.setPixelRatio(window.devicePixelRatio),n.setSize(i,s),n.outputColorSpace=d.SRGBColorSpace,n.toneMappingExposure=1,n.localClippingEnabled=!0,n.shadowMap.enabled=!1,n.shadowMap.type=d.PCFSoftShadowMap,n.shadowMap.autoUpdate=!1,n.domElement.style.outlineWidth="0",r?.appendChild(n.domElement),this.renderer=n,z.printGpuInfo(n.getContext())}initLights(){const t=new d.Group;t.name="lights";const e=1.5,i=16777215,s=new d.DirectionalLight(i,e);s.name="sun",s.castShadow=!0,s.position.set(-2,2,4),s.shadow.autoUpdate=!1,s.shadow.mapSize.width=1024,s.shadow.mapSize.height=1024;const r=new d.AmbientLight(i);r.name="ambient";const n=new d.HemisphereLight(i,14540253,.2);n.name="hemisphere",n.position.set(0,300,0);const a=new d.Group;a.name="lightHelpers",a.visible=!1;const o=new d.DirectionalLightHelper(s),l=new d.CameraHelper(s.shadow.camera);return a.add(o),a.add(l),t.add(s),t.add(s.target),t.add(r),t.add(n),t.add(a),this.scene.add(t),this.lights=t,t}initPMREMGenerator(){this.pmremGenerator=new d.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()}get maxFragmentUniforms(){return this.renderer.capabilities.maxFragmentUniforms-20}addModel(t){this.modelGroup.add(t.getModelObject())}enableShadow(t){this.renderer.shadowMap.enabled=t,this.directionalLight.castShadow=t,t&&(this.tryAdjustDirectionalLight(),this.updateDirectionalLightShadow()),this.modelGroup.traverse(e=>{e.isMesh&&(e.castShadow=t,e.receiveShadow=t)})}enableClipping(t){this.renderer.localClippingEnabled=t}setClipPlanes(t){this.renderer.clippingPlanes=t}enableLights(t){let e=this.lights;e||(e=this.initLights()),e.visible=t}debugLights(t){!this.lights||!this.lightHelpers||(this.lightHelpers.visible=t)}setBackground(t){this.scene.background=t}get directionalLight(){return this.lights?.getObjectByName("sun")}get ambientLight(){return this.lights?.getObjectByName("ambient")}get hemisphereLight(){return this.lights?.getObjectByName("hemisphere")}get lightHelpers(){return this.lights?.getObjectByName("lightHelpers")}get directionalLightHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];if(i instanceof d.DirectionalLightHelper){t=i;break}}return t}get cameraHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];i instanceof d.CameraHelper&&(t=i)}return t}async setEnvironmentFromData(t){this.pmremGenerator||this.initPMREMGenerator();const e=await pi.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await pi.createEnvTexture(this.pmremGenerator,t);this.scene.environment?.dispose(),this.scene.environment=e}resize(){const{width:t,height:e}=this.viewer.container;this.renderer.setSize(t,e)}getRaycastableObjects(){const t=[];return this.modelGroup.traverse(e=>{t.push(e)}),t}tryAdjustDirectionalLight(){const t=this.directionalLight;if(!t)return;const e=this.viewer.getBBox(),i=new d.Sphere;e.getBoundingSphere(i);const s=i.center,r=i.radius,n=t.shadow.camera;n.zoom=1,n.top=r,n.bottom=-r,n.right=r,n.left=-r,n.near=.1,n.far=2*r,n.updateProjectionMatrix();const a=new d.Vector3(-1,-.5,1);a.normalize().multiplyScalar(r),t.position.copy(s).addScaledVector(a,-1),t.target.position.copy(s),S.debug("[Scene] directionalLight.position",t.position),S.debug("[Scene] directionalLight.target.position",t.target.position),this.updateDirectionalLight(),this.viewer.enableRender()}updateDirectionalLight(){const t=this.directionalLight;if(t&&(t.updateMatrixWorld(),t.target.updateMatrixWorld(),this.directionalLightHelper&&(this.directionalLightHelper.update(),this.scene?.matrixAutoUpdate||this.directionalLightHelper.updateWorldMatrix(!1,!0)),t.shadow.needsUpdate=!0,t.shadow.camera.updateProjectionMatrix(),this.cameraHelper&&(this.cameraHelper.update(),!this.scene?.matrixAutoUpdate))){const e=t.shadow.camera;e.position.setFromMatrixPosition(t.matrixWorld),Kr.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Kr),e.updateMatrixWorld(),this.cameraHelper.updateWorldMatrix(!1,!0)}}updateDirectionalLightShadow(){this.directionalLight&&(this.directionalLight.shadow.needsUpdate=!0)}showDirectionalLightHelper(t){this.directionalLightHelper&&(this.directionalLightHelper.visible=t),this.cameraHelper&&(this.cameraHelper.visible=t)}destroy(){this.lightHelpers?.clear(),this.lightHelpers?.removeFromParent(),this.lightHelpers?.traverse(t=>{t.dispose?.call(t)}),this.lights?.clear(),this.lights?.removeFromParent(),this.lights?.traverse(t=>{t.dispose?.call(t)}),this.lights=void 0,this.pmremGenerator?.dispose(),this.renderer.domElement.remove(),this.renderer.clear(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.scene.clear()}}class hc{constructor(t){p(this,"history");p(this,"step");p(this,"maxCount");p(this,"isBatchCommand");p(this,"batchCommands");this.history=[],this.step=0,this.maxCount=50,this.isBatchCommand=!1,this.batchCommands=[],this.maxCount=t||this.maxCount}addCommand(t){this.isBatchCommand?this.batchCommands.push(t):(this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.history.push(t),this.step++)}startTransaction(){this.isBatchCommand=!0}endTransaction(){this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.batchCommands.length>0&&(this.history.push(this.batchCommands.slice()),this.step++),this.isBatchCommand=!1,this.batchCommands=[]}undo(){if(this.canUndo())return!1;this.step--;const t=this.history[this.step];return t&&(Array.isArray(t)?t.forEach(e=>e.undo()):t.undo()),!0}redo(){if(this.canRedo())return!1;this.step++;const t=this.history[this.step-1];return t&&(Array.isArray(t)?t.forEach(e=>e.redo()):t.redo()),!0}getCommands(){return this.history}canUndo(){return this.step<=0}canRedo(){return this.step>=this.history.length}clear(){this.history=[],this.step=0}destroy(){this.clear(),this.maxCount=0}}class Qi extends mt{constructor(e){super();p(this,"name");p(this,"viewerCfg");p(this,"clock");p(this,"targetMaxFps");p(this,"timeStamp");p(this,"renderEnabled");p(this,"requestAnimationFrameHandle");p(this,"container");p(this,"plugins");p(this,"loadedModels");p(this,"raf");p(this,"timeoutSymbol");p(this,"homeView");p(this,"inputManager");p(this,"cameraManager");p(this,"sceneManager");p(this,"fontManager");p(this,"pickManager");p(this,"undoManager");p(this,"overlayRender");p(this,"css2dRenderer");p(this,"spinner");p(this,"progressBar");p(this,"loaderHelper");p(this,"zoomToRectHelper");p(this,"_enableSelection");p(this,"enableRender");this.name=Be.BaseViewer,this.clock=new d.Clock,this.targetMaxFps=60,this.timeStamp=0,this.renderEnabled=!0,this.plugins=[],this.loadedModels=[],this.raf=new Un,this._enableSelection=!0,this.enableRender=(i=1e3)=>{this.renderEnabled=!0,this.raf&&(this.timeoutSymbol&&this.raf.clearTimeout(this.timeoutSymbol),this.timeoutSymbol=this.raf.setTimeout(()=>{this.renderEnabled=!1},i))},this.viewerCfg=e,this.initLogLevel(),this.initLocalization(),this.container=new Us(e.containerId),e.enableProgressBar&&(this.progressBar=new Hs(this.container)),this.spinner=new Ln(this.container),this.sceneManager=new lc(this),this.pickManager=new oc(this),this.overlayRender=new xi(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new Yn(this.viewerContainer),this.cameraManager=new jh(this),this.loaderHelper=new ut,this.undoManager=new hc,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&nn(e)}initLocalization(){const e=this.viewerCfg.language||on;Re.changeLanguage(e)}get viewerContainer(){return this.container.viewerContainer}get widgetContainer(){return this.container.widgetContainer}getUndoManager(){return this.undoManager}getInputManager(){return this.inputManager}getCssRender(){return this.css2dRenderer}getCameraManager(){return this.cameraManager}getOverlayRender(){return this.overlayRender}getSceneManager(){return this.sceneManager}get renderer(){return this.sceneManager.renderer}get camera(){return this.cameraManager.camera}get scene(){return this.sceneManager.scene}getRaycaster(){return this.pickManager.getRaycaster()}getViewerConfig(){return this.viewerCfg}getSpinner(){return this.spinner}getFontManager(){return this.fontManager}initCSS2DRenderer(){const e=new rn.CSS2DRenderer,{width:i,height:s}=this.viewerContainer.getBoundingClientRect();return e.setSize(i,s),e.domElement.style.height="0",e.domElement.style.width="0",e.domElement.style.position="absolute",e.domElement.style.top="0",e.domElement.style.left="0",e.domElement.style.overflow="visible",e.domElement.classList.add("css2d-renderer"),this.viewerContainer?.appendChild(e.domElement),e}animate(){const e=Date.now()-this.timeStamp,i=1/this.targetMaxFps;if(e<i){this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this));return}const s=this.cameraManager.update(this.clock.getDelta());this.container.needResize&&(this.resize(),this.renderEnabled=!0),(this.renderEnabled||s)&&(this.dispatchEvent(re.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(re.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(re.OnAnimate)}resize(){this.sceneManager.resize(),this.cameraManager.updateAspect();const{clientWidth:e,clientHeight:i}=this.viewerContainer;this.css2dRenderer.setSize(e,i),this.overlayRender.setSize(e,i)}setDracoDecoderPath(e){ut.setDracoDecoderPath(e)}addModel(e){const i=e.getModelObject();i.name=e.modelId,this.sceneManager.addModel(e),i.matrixAutoUpdate=Ne,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new Ke),await this.fontManager.loadFonts(e)}is3d(){return!1}getPixelSizeInWorldCoord(){const e=this.camera,{clientWidth:i,clientHeight:s}=this.viewerContainer;let r=1;if(e.type==="OrthographicCamera"){const n=e;r=Math.max(n.right-n.left,n.top-n.bottom)/n.zoom/Math.max(i,s)}else if(e.type==="PerspectiveCamera"){const n=e,a=new d.Vector3;e.getWorldPosition(a);const o=this.cameraManager.getTarget();a&&o&&(r=2*(a.distanceTo(o)*Math.tan(n.fov/2*(Math.PI/180)))/s)}return r}zoomToRect(){!this.zoomToRectHelper&&(this.zoomToRectHelper=new Wn(this)),this.zoomToRectHelper.activate()}deactivateZoomRect(){this.zoomToRectHelper?.deactivate()}getUniqueModelId(e){let i=e;const s=r=>!!this.loadedModels.find(n=>n.modelId===r);if(s(i)){let r=1;for(;s(i+"_"+r);)r++;i=i+"_"+r,S.warn("[Viewer] Model '"+i+"' is loaded more than once!")}return i}getBBox(){const e=new d.Box3;return this.loadedModels.forEach(i=>{e.union(i.getBBox())}),e}flyToObject(e){this.cameraManager.flyToObject(e)}flyToObjects(e){const i=new d.Box3;e.forEach(r=>{const n=new d.Box3().setFromObject(r);i.union(n)});const s=new d.Sphere;i.getBoundingSphere(s),this.cameraManager.fitToSphere(s)}flyTo(e,i,s=!0){const r=this.camera;if(e.equals(i)){S.error("[Viewer] camera position and lookAt cannot be the same!");return}else if(!z.isVectorValid(e)||!z.isVectorValid(i)){S.error("[Viewer] invalid position or lookAt!");return}const n=e.distanceTo(i);n<r.near?(e=e.clone().sub(i).normalize().multiplyScalar(r.near*1.1),S.warn("[Viewer] camera could be too close to see the object!")):n>r.far&&(e=e.clone().sub(i).normalize().multiplyScalar(r.far*.9),S.warn("[Viewer] camera could be too far to see the object!")),this.cameraManager.flyTo(e,i,s)}flyToDirection(e){const i=this.getBBox(),s=i.getSize(new d.Vector3);let r=Math.max(s.x,s.y,s.z)/2;r===0&&(r=1);const n=this.cameraManager.getDistanceToFitSphere(r),a=new d.Vector3;i.getCenter(a);const o=a.clone().add(e.clone().multiplyScalar(n));this.flyTo(o,a)}goToHomeView(){if(this.homeView)this.cameraManager.flyToViewpoint(this.homeView);else{const e=new d.Vector3(1,.5,1);this.flyToDirection(e)}}viewFitAll(){const e=this.getBBox(),i=new d.Sphere;e.getBoundingSphere(i),this.cameraManager.fitToSphere(i)}zoomToBBox(e){this.cameraManager.flyToBox(e)}pickObject(e,i,s){let r=this.pickManager.pickObject(e,this.getRaycastableObjects(),i,s);return this.renderer&&this.renderer.clippingPlanes.length>0&&this.renderer?.clippingPlanes?.every(a=>{r&&a.distanceToPoint(r.point)>0})&&(r=void 0),r}pickObjects(e,i){let s=this.pickManager.pickObjects(e,this.getRaycastableObjects(),i);return s&&this.renderer.clippingPlanes.length>0&&(s=s.filter(r=>this.renderer.clippingPlanes.every(n=>n.distanceToPoint(r.point)>0))),s}getRaycastableObjects(){return this.sceneManager.getRaycastableObjects()}setBackgroundColor(e,i,s){if(!this.scene.background&&(this.scene.background=new d.Color(e,i,s)),this.scene.background instanceof d.Color){const r=new d.Color;r.setRGB(e,i,s,this.renderer.outputColorSpace),this.scene.background.copy(r)}this.enableRender()}setGlobalClipPlanes(e){}getCameraProjection(){return this.cameraManager.getProjection()}setCameraProjection(e){this.cameraManager.setProjection(e)}enableControl(e){this.cameraManager.enableControl(e)}enableRotate(e){this.cameraManager.enableRotate=e}enableZoom(e){this.cameraManager.enableZoom(e)}enablePan(e){this.cameraManager.enablePan(e)}getHomeView(){return this.homeView}setHomeView(e){this.homeView=e}getCameraConfig(){return this.cameraManager.getCameraConfig()}setCameraConfig(e){return this.cameraManager.setCameraConfig(e)}getCameraDirection(){return this.cameraManager.getCameraDirection()}getRenderInfo(){const e=this.renderer.info;return{drawCalls:e.render.calls,lines:e.render.lines,points:e.render.points,triangles:e.render.triangles,geometries:e.memory.geometries,textures:e.memory.textures,materials:e.programs?.length||0}}destroy(){this.requestAnimationFrameHandle&&cancelAnimationFrame(this.requestAnimationFrameHandle),this.css2dRenderer.domElement.remove(),this.container.destroy(),this.sceneManager.destroy(),this.cameraManager.destroy(),this.overlayRender.destroy(),this.spinner.destroy(),this.progressBar?.destroy(),this.undoManager.destroy()}addPlugin(e){if(this.plugins.find(s=>s.id===e.id)){S.warn("[Viewer] Plugin already exist: "+e.id);return}this.plugins.push(e),S.debug("[Viewer] Added plugin: "+e.id)}removePlugin(e){for(let i=0,s=this.plugins.length;i<s;i++)if(this.plugins[i]===e){this.plugins.splice(i,1);return}}clearPlugins(){this.plugins=[]}findPlugin(e){return this.plugins.find(i=>i.id===e)}}const Xn=-1e3,Bt=new d.Vector3,$r=new d.Matrix4,Jr=new d.Frustum,Ts=new d.Box3,Qr=new d.Matrix4;class Gs extends Qi{constructor(e){super(e);p(this,"name");p(this,"loadedModels");p(this,"masterModelId");p(this,"activeLayoutName");p(this,"dxfLayoutBar");p(this,"layoutInfos");p(this,"units");p(this,"enableHideVisuallySmallObjects");p(this,"sortedHidableObjects");p(this,"lastCameraZoom");p(this,"groundPlane");p(this,"raycastableObjects");p(this,"selectedObject");p(this,"loadingDxfCount");p(this,"textSearchHelper");p(this,"clickHighlightList");p(this,"_enableClickHighlight",!1);this.name=Be.Viewer2d,this.loadedModels=[],this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0,this.enableHideVisuallySmallObjects=e.enableHideVisuallySmallObjects!==!1,this.sortedHidableObjects={},this.lastCameraZoom=1/0,this.loadingDxfCount=0,e.enableLayoutBar&&(this.dxfLayoutBar=new Dh(this)),this.cameraManager.setProjection($e.Orthographic),this.cameraManager.setNavigationMode(He.Plan);const i=new d.Vector3(0,0,100),s=new d.Vector3(0,0,0);this.cameraManager.setCameraConfig({eye:i,look:s}),this.resize(),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(re.BeforeRender,()=>{this.updateRaycasterThreshold(),this.updateCameraZoomUniform(this.camera.zoom),this.updateHidableObjectsVisibility()})}get camera(){return this.cameraManager.camera}setupDefaultEvents(){let e=!1,i=!1;this.inputManager.addEventListener("pointerdown",s=>{i=!1,e=!0,s.button===Le.Middle&&this.inputManager?.setCursor("move")}),this.inputManager.addEventListener("pointermove",()=>{e&&(i=!0,this.inputManager?.setCursor("move"))}),this.inputManager.addEventListener("pointerup",s=>{if(e=!1,this.inputManager?.setCursor("default"),i){i=!1;return}const r=new d.Vector2(s.x,s.y),n=this.getWorldPositionByMousePick(r),a=this.pickManager.pickObjects(r,this.getRaycastableObjects(),void 0,3);let o;for(const u of a){const f=this.resolveEntityFromPick(u);if(f){f.hit=u,o=f;break}}const l=o?.userData;if(this._enableClickHighlight&&o){const u=this.getEntityBoundingBox(o);u&&this.highlightEntityBox(u)}else this.clearClickHighlight();const c={event:s,position:r,worldPosition:n,pooo:n,entity:l?o?.object:void 0,object:l?o?.object:void 0,point:l?o?.hit?.point:void 0,userData:l,handle:l?.handle};this.dispatchEvent(re.MouseClick,c)})}resolveEntityFromPick(e){if(!e)return;const i=e.object,s=i.userData?.batches;if(s&&s.length>0){const n=i.geometry,a=i.isMesh===!0,o=e.index;let l;a&&typeof e.faceIndex=="number"&&(l=n?.index?n.index.getX(e.faceIndex*3):e.faceIndex*3);const c=s.find(u=>{const f=typeof o=="number"&&o>=u.indexStart&&o<u.indexStart+(u.indexCount||1),m=typeof o=="number"&&o>=u.positionStart&&o<u.positionStart+u.positionCount||typeof l=="number"&&l>=u.positionStart&&l<u.positionStart+u.positionCount;return f||m});if(c?.userData)return{userData:c.userData,batch:c,object:i}}let r=i;for(;r;){if(r.userData?.handle)return{userData:r.userData,object:r};r=r.parent??void 0}}getEntityBoundingBox(e){const i=e.object,s=i.geometry?.getAttribute?.("position");if(e.batch&&s){const n=new d.Box3,a=e.batch.positionStart||0,o=e.batch.positionCount||0;if(o>0){i.updateWorldMatrix(!0,!1),Qr.copy(i.matrixWorld);for(let l=a;l<a+o&&l<s.count;l++)Bt.fromBufferAttribute(s,l).applyMatrix4(Qr),n.expandByPoint(Bt);if(!n.isEmpty())return n}}const r=new d.Box3;return r.setFromObject(i),r.isEmpty()?void 0:r}highlightEntityBox(e){const i=this.getOverlayRender();i&&(!this.clickHighlightList&&(this.clickHighlightList=new bi("entity-click-highlight"),i.addDrawableList(this.clickHighlightList)),this.clickHighlightList.clear(),this.clickHighlightList.addDrawable(new Je(z.guid(),[e.clone()],[.031,.906,.867,1],[.031,.906,.867,.15])),this.enableRender())}get enableClickHighlight(){return this._enableClickHighlight}set enableClickHighlight(e){this._enableClickHighlight=e,e||this.clearClickHighlight()}clearClickHighlight(){this.clickHighlightList?.clear(),this.enableRender()}handleMouseClick(e){if(!this.enableSelection)return;const i=new d.Vector2(e.x,e.y),s=this.getWorldPositionByMousePick(i);if(!s)return;const r=this.overlayRender.getDrawablesByPosition(s)[0];if(r){this.selectedObject===r?(this.selectedObject.selected=!1,this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=r,this.selectedObject.selected=!0),this.enableRender();return}const n=this.pickObject(i,[ft]);if(n){const a=n?.object;this.selectedObject===a?(this.setObjectUnHighlight(this.selectedObject),this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=a,this.setObjectHighlight(this.selectedObject)),this.enableRender();return}this.clearSelection(),this.enableRender()}setDefaultBackground(){this.setBackgroundColor(.0295,.0212,.0152)}async loadModel(e,i,s){const r=this.getUniqueModelId(e.modelId||e.src);this.spinner.increaseJobCount(),this.loaderHelper.setFont(this.fontManager),this.masterModelId||(this.masterModelId=r);const n=r,a=Re.t("ProgressBar.Loading"),o=x=>{this.progressBar?.updateProgress(n,a,x),i?.(new ProgressEvent("LoadProgress",{loaded:x,total:100}))},l=(x,y,T)=>{let v=x.loaded*100/x.total;v=v*(T-y)/100+y,this.progressBar?.updateProgress(n,a,v),i?.(new ProgressEvent("LoadProgress",{loaded:v,total:100}))},c=x=>l(x,0,90);this.progressBar?.addProgressItem(n),o(0);const u=this.viewerCfg,f=await this.loaderHelper.loadDxfData(e.src,e.modelId,c,void 0,{ignorePaperSpace:e.ignorePaperSpace,enableLocalCache:u.enableLocalCache,enableMerge:e.merge,encoding:e.encoding,overrideColor:e.overrideColor}).finally(()=>{this.loadingDxfCount--,this.loadingDxfCount===0&&this.fontManager?.releaseFontData()}),m=f.threejsObject;if(s&&s({threejsObject:m,llbMesh:f.llbMesh}),e.matrix&&e.matrix.length===16){const x=new d.Matrix4;x.elements=e.matrix,m.applyMatrix4(x)}const g=new Wt({modelId:r,dxfData:f});this.addModel(g),this.spinner.decreaseJobCount(),o(100),this.progressBar?.delayRemoveProgressItem(n),this.dispatchEvent(re.ModelLoad)}addModel(e){super.addModel(e);const i=e.modelId;if(e.dxfData){this.masterModelId===i?this.activateLayout(Y.MODEL_LAYOUT_NAME):this.handleOverlayDxf(i);const s=e.getBBox(),r=new d.Vector3;s.getCenter(r),this.cameraManager.adjustCameraByBBox(s);const n=this.getDxfUnits(e);this.masterModelId===i&&(this.units=n)}else{const s=e.getModelObject();this.activeLayoutName=Y.MODEL_LAYOUT_NAME;const r=new d.Box3().setFromObject(s);this.layoutInfos[this.activeLayoutName]={homeViewExtent:r,extent:r},s.matrixAutoUpdate=Ne,this.scene.add(s);const n=r.max.z;n>this.camera.position.z&&(this.camera.position.z=n,this.camera.updateProjectionMatrix()),this.flyToObject(s)}this.updateGroundPlane()}getDxfUnits(e){return!e&&this.loadedModels.length>0&&(e=this.loadedModels.find(i=>this.masterModelId===i.modelId)),e?e.getUnits():De.Unitless}handleOverlayDxf(e){const i=this.loadedModels.find(r=>e===r.modelId);if(!i){S.warn("[Viewer] Can't find model for modelId '"+e+"'!");return}i.switchTransformMs(Y.MODEL_LAYOUT_NAME),i.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME)?.traverse(r=>{i.addSpatialFilterSection(r,i.dxfData)}),i.showLayoutObjects(Y.MODEL_LAYOUT_NAME)}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}setObjectUnHighlight(e){this.loadedModels.forEach(i=>i.unHighlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}clearSelection(){this.selectedObject instanceof d.Object3D&&this.setObjectUnHighlight(this.selectedObject),this.selectedObject instanceof pt&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clickHighlightList?.clear()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}updateGroundPlane(){const e=this.getActiveLayoutInfo();if(!e.homeViewExtent)return;const i=e.homeViewExtent.clone(),s=[],r=(o,l,c)=>{s.push(new d.Vector3(o,l,c))},n=i.getSize(new d.Vector3),a=i.getCenter(new d.Vector3);if(r(-n.x/2,-n.y/2,0),r(n.x/2,-n.y/2,0),r(n.x/2,n.y/2,0),r(-n.x/2,n.y/2,0),this.groundPlane)this.groundPlane.position.set(a.x,a.y,-n.z),this.groundPlane.geometry.setFromPoints(s),this.groundPlane.geometry.computeBoundingSphere(),this.groundPlane.geometry.computeBoundingBox();else{const o=new d.BufferGeometry;o.setFromPoints(s),o.setIndex([0,3,2,0,2,1]);const l=new d.MeshBasicMaterial({color:"#888",side:d.DoubleSide});this.groundPlane=new d.Mesh(o,l),this.groundPlane.visible=!1,this.groundPlane.position.set(a.x,a.y,-n.z),this.groundPlane.scale.set(1e5,1e5,1),this.groundPlane.name="groundPlane",this.groundPlane.renderOrder=Xn,this.groundPlane.layers.enableAll(),$.disableLayerChannels(this.groundPlane,[ft]),this.scene.add(this.groundPlane)}this.groundPlane.updateMatrix(),this.groundPlane.updateMatrixWorld(!0)}getRaycastableObjects(){const e=[],i=Date.now();if(this.activeLayoutName===Y.MODEL_LAYOUT_NAME){if(this.raycastableObjects)return this.raycastableObjects;if(this.renderer?.renderLists){const s=this.renderer?.renderLists.get(this.scene,0);s&&(s.opaque.forEach(r=>{r.object&&r.object.geometry&&e.push(r.object)}),s.transparent.forEach(r=>{r.object&&r.object.geometry&&e.push(r.object)}))}$r.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),Jr.setFromProjectionMatrix($r);for(const s of this.loadedModels){const r=s.getModelObject(),n=r.children.find(a=>a.name===this.activeLayoutName);n&&n.children.find(o=>o.name===Y.SNAP_GROUP_NAME)?.traverse(o=>{if($.isLeafObject(o)){if(Ts.makeEmpty(),Ts.expandByObject(o),!Jr.intersectsBox(Ts))return;e.push(o)}})}this.groundPlane&&e.push(this.groundPlane),S.debug("[Viewer] getRaycastableObjectsByMouse() from modelSpace"),this.raycastableObjects=e}else{const s=new WeakSet,r=this.getLayoutByName(this.activeLayoutName);r&&r.directAssociatedLeafObjectSet?.forEach(o=>{o.visible&&!s.has(o)&&(e.push(o),s.add(o))});const n=this.getViewportByPoint(this.pickManager.getRaycaster().ray.origin);n&&n.associatedLeafObjectSet?(n.associatedLeafObjectSet?.forEach(a=>{!s.has(a)&&(a.visible||a.userData.isSnapObject)&&(e.push(a),s.add(a))}),S.debug("[Viewer] getRaycastableObjectsByMouse() from inside of viewport:",n.viewportId)):S.debug("[Viewer] getRaycastableObjectsByMouse() from out of viewport"),this.groundPlane&&e.push(this.groundPlane)}return S.debug("[Viewer] getRaycastableObjectsByMouse() took "+(Date.now()-i)/1e3+" s"),e}getViewportByPoint(e){if(this.activeLayoutName.length===0||this.activeLayoutName===Y.MODEL_LAYOUT_NAME)return;const i=this.getLayoutByName(this.activeLayoutName);if(!i)return;const s=a=>e.x<a.min.x||e.x>a.max.x||e.y<a.min.y||e.y>a.max.y,r=this.loadedModels.find(a=>this.masterModelId===a.modelId);if(!r)return;const n=r.getFilteredViewports(i);for(let a=0,o=n.length;a<o;a++){const l=n[a];if(!s(l.psBBox))return l}}getWorldPositionByMousePick(e){const i=[];this.groundPlane&&i.push(this.groundPlane);for(const r of this.loadedModels){const n=r.getModelObject();n&&(i.push(n),n.traverse(a=>{(a.isMesh||a.isLine)&&i.push(a)}))}return this.pickManager.pickObject(e,i)?.point}activateLayout(e=Y.MODEL_LAYOUT_NAME){if(this.activeLayoutName===e||!this.masterModelId)return;const i=this.loadedModels.find(u=>this.masterModelId===u.modelId);if(!i)return;const s=i.getLayoutByName(e);if(!s)return;const r=this.getActiveLayoutInfo();if(this.groundPlane){const u=this.getCurrentViewExtent(),f=this.camera.position.z;r.lastViewExtent=new d.Box3(new d.Vector3(u.min.x,u.min.y,0),new d.Vector3(u.max.x,u.max.y,f))}const n=u=>!!this.layoutInfos[u]?.lastViewExtent,a=n(e);i?.activateLayout(e,a),this.activeLayoutName=e;const o=i.getFilteredViewports(s);if(S.debug("[Viewer] Active layout:",e,", viewports:",o),!a){const u=this.camera.position.z;let f=0;o.forEach(g=>{const x=g?.msToPsMatrix?.elements[14];x&&x>f&&(f=x)});const m=this.cameraManager.getPosition();if(f>m.z+u){const g=Math.ceil(f+u);m.z=g,S.info("[Viewer] Changing camera's z value from "+m.z+" to "+g),this.cameraManager.setCameraPosition(m)}}const l=this.getActiveLayoutInfo();if(l.lastViewExtent)this.zoomToBBox(l.lastViewExtent);else{l.extent=this.getBBox();let u=this.getLayoutExtentEx(s);if(u){const g=u.max.x-u.min.x,x=u.max.y-u.min.y;(g<1e-16||x<1e-16||g>1e16||x>1e16)&&(S.warn("[Viewer] Got wired bbox, max: "+u.max.toArray()+", min: "+u.min.toArray()+", going to use the calculated one..."),u=l.extent)}else S.warn("[Viewer] Failed to get layout extent, going to use the calculated one..."),u=l.extent;l.homeViewExtent=u,this.zoomToBBox(u)}const c=i.getLayoutLevelObject(e);c&&this.setLayoutHidableObjectArray(c),this.enableRender()}getLayoutExtentEx(e){const i=this.loadedModels.find(s=>this.masterModelId===s.modelId);if(i)return e.layoutName===Y.MODEL_LAYOUT_NAME?i.getModelSpaceExtent():i.getLayoutExtent(e)}getActiveLayoutInfo(){return this.getLayoutInfo(this.activeLayoutName)}getLayoutByName(e){let i;const s=this.loadedModels.find(n=>this.masterModelId===n.modelId);if(!s)return;const r=s.getLayouts();for(const n of r)if(n.layoutName===e){i=n;break}return i}getEntityCount(){let e=0;return this.loadedModels.forEach(i=>{e+=i.loadedEntityCount}),e}getLayoutNames(){const e=[];return(this.loadedModels.find(r=>this.masterModelId===r.modelId)?.getLayouts()||[]).forEach(r=>{e.push(r.layoutName)}),e}getLayoutInfo(e){return this.layoutInfos[e]||(this.layoutInfos[e]={}),this.layoutInfos[e]}goToHomeView(){const e=this.getActiveLayoutInfo();e.homeViewExtent?this.zoomToBBox(e.homeViewExtent):S.error("[Viewer] Failed to find extent for "+this.activeLayoutName)}zoomToBBox(e){const i=e.getCenter(Bt),s=e.max.x-e.min.x,r=e.max.y-e.min.y,n=this.camera.right-this.camera.left,a=this.camera.top-this.camera.bottom;let o=Math.min(n/s,a/r);o/=1.1,this.cameraManager.cameraControls.moveTo(i.x,i.y,i.z),this.cameraManager.cameraControls.zoomTo(o)}getCurrentViewExtent(){const e=this.getHitResultByNdcCoordinate(new d.Vector2(-1,-1)),i=this.getHitResultByNdcCoordinate(new d.Vector2(1,1));return new d.Box2(e,i)}getHitResultByNdcCoordinate(e){const i=[];this.groundPlane&&i.push(this.groundPlane);const s=this.pickManager.pickObjectsByNdc(e,i);if(s.length>0){const r=s[0].point;return new d.Vector2(r.x,r.y)}}getHitResult(e){const i=this.viewerContainer,s=pe.getScreenCoordinateByEvent(e,i),r=pe.screen2Ndc(s,this.camera,i);return this.getHitResultByNdcCoordinate(r)}getActiveLayoutName(){return this.activeLayoutName}searchText(e,i){return!this.textSearchHelper&&(this.textSearchHelper=new Is(this)),this.textSearchHelper.search(e,i)}focusText(e){!this.textSearchHelper&&(this.textSearchHelper=new Is(this)),this.textSearchHelper.focus(e)}clearTextHighlight(){this.textSearchHelper?.clearHighlight()}zoomIn(e=.01){this.cameraManager.cameraControls.zoom(e)}zoomOut(e=.01){this.cameraManager.cameraControls.zoom(-e)}getLayers(){const e=[];if(this.masterModelId){const i=this.loadedModels.find(r=>this.masterModelId===r.modelId),s=i?.layers;s&&e.push({modelId:this.masterModelId,layers:s})}for(const i of this.loadedModels){const s=i.modelId;if(s===this.masterModelId)continue;const r=i.layers;r&&e.push({modelId:s,layers:r})}return e}setModelVisibility(e,i){const s=this.loadedModels.find(r=>e===r.modelId);if(!s)throw new Error("Failed to find model by modelId '"+e+"'!");s.setVisible(i),this.enableRender()}setLayerVisibility(e,i,s){const r=this.camera;s=s||this.masterModelId;const n=this.loadedModels.find(a=>s===a.modelId);if(!n)throw new Error("Failed to find layer by modelId '"+s+"'!");n.setLayerVisible(e,i,this.enableHideVisuallySmallObjects,r.zoom),this.raycastableObjects=void 0,this.enableRender()}setLayerOpacity(e,i,s){s=s||this.masterModelId;const r=this.loadedModels.find(n=>s===n.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");r.setLayerOpacity(e,i),this.enableRender()}setLayerColor(e,i,s){s=s||this.masterModelId;const r=this.loadedModels.find(n=>s===n.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");this.clearSelection(),r.setLayerColor(e,i),this.enableRender()}resetLayerColor(e,i){i=i||this.masterModelId;const s=this.loadedModels.find(r=>i===r.modelId);if(!s)throw new Error("Failed to find model by modelId '"+i+"'!");this.clearSelection(),s.resetLayerColor(e),this.enableRender()}getVisiblePixelSize(e){const i=d.MathUtils.smoothstep(e,1e4,3e4)*6.5+.5;return S.debug("[Viewer] visiblePixelSize:",i),i}setLayoutHidableObjectArray(e){const i=this.camera;if(!this.enableHideVisuallySmallObjects||!i)return;const s=Date.now(),r=e.name;this.sortedHidableObjects[r]||(this.sortedHidableObjects[r]=[]);const n=this.sortedHidableObjects[r];this.cameraManager.update(0);const a=i.zoom;this.lastCameraZoom=a;let o=1;e.traverse(c=>{if(c.userData.isSnapObject||!$.isLeafObject(c))return;const u=c.geometry;u.boundingBox||u.computeBoundingBox();const f=u.boundingBox.clone();if(!f||!z.isBoxValid(f))return;f.applyMatrix4(c.matrixWorld),f.getSize(Bt);const m=Math.max(Bt.x,Bt.y),g=o/m;g<1/0?n.push({visibleMinZoom:g,object:c}):c instanceof d.Points?n.push({visibleMinZoom:o,object:c}):S.warn("[Viewer] The size of bbox is 0 ! ",c)}),o=this.getVisiblePixelSize(n.length);let l=0;n.forEach(c=>{const u=c.visibleMinZoom*o;c.visibleMinZoom=u,c.object.userData.visibleMinZoom=u,u>a&&(c.object.visible=!1,l++)}),n.sort((c,u)=>c.visibleMinZoom-u.visibleMinZoom),S.debug("[Viewer] setLayoutHidableObjectArray took: "+(Date.now()-s)/1e3+"s, "+l+" objects changed to hidden")}updateRaycasterThreshold(){const e=this.getPixelSizeInWorldCoord()*3,i=this.getRaycaster().params;i.Line?i.Line.threshold=e:i.Line={threshold:e},i.Points?i.Points.threshold=e:i.Points={threshold:e}}updateHidableObjectsVisibility(){const e=this.camera,i=Date.now();this.cameraManager.update(0);const s=e.zoom;if(Math.abs(s-this.lastCameraZoom)<1e-5||(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,!this.sortedHidableObjects[this.activeLayoutName]))return;const r=this.sortedHidableObjects[this.activeLayoutName];if(r.length===0)return;const n=s>this.lastCameraZoom,a=Math.min(s,this.lastCameraZoom),o=Math.max(s,this.lastCameraZoom),l=[];let c=0;for(let u=0;u<r.length;++u)if(r[u].object.userData.layerVisible!==!1){if(r[u].visibleMinZoom<a){l.push(r[u].object);continue}else if(r[u].visibleMinZoom>o)break;r[u].object.visible=n,n&&l.push(r[u].object),c++}this.lastCameraZoom=s,S.debug("[Viewer] updateHidableObjectsVisibility took: "+(Date.now()-i)/1e3+"s, "+c+"(out of "+r.length+") objects changed to "+(n?"visible":"hidden"))}updateCameraZoomUniform(e){Y.CameraZoomUniform.value=e*this.container.height/50}}class Zn{constructor(t){p(this,"viewer");p(this,"fontManager");p(this,"loader");p(this,"loadingManager");p(this,"changes");p(this,"container");p(this,"spinner");p(this,"jobCount");p(this,"loadingProgressBar");this.jobCount=0,this.viewer=new Gs(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new Us(t.containerId);this.loadingProgressBar=new Hs(i);const s={ignorePaperSpace:!0};this.loader=new Y(this.loadingManager,s),this.initSpinner()}initSpinner(){const t=document.createElement("div");t.classList.add("x-spinner"),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),this.container.appendChild(t),this.spinner=t,this.setSpinnerVisibility(this.jobCount>0)}async setFont(t){const e=Date.now();!this.fontManager&&(this.fontManager=new Ke),await this.fontManager.loadFonts(t),S.info("[DxfCompareHelper] Font file(s) load time in "+(Date.now()-e)/1e3+"s")}async compare(t,e,i,s){const{src:r,modelId:n}=t,{src:a}=e;this.viewer.masterModelId=n||r;const o=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const l=r+a,c=Re.t("ProgressBar.Comparing"),u=k=>{this.loadingProgressBar?.updateProgress(l,c,k),s&&s(new ProgressEvent("CompareProgress",{loaded:k,total:100}))},f=(k,B,L)=>{let q=k.loaded*100/k.total;q=q*(L-B)/100+B,this.loadingProgressBar?.updateProgress(l,c,q),s&&s(new ProgressEvent("CompareProgress",{loaded:q,total:100}))},m=k=>f(k,0,15),g=k=>f(k,15,30),x=k=>f(k,30,60),y=k=>f(k,60,95);z.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(l),u(0);let T=Date.now();const v=this.loader.parse(r,m),b=this.loader.parse(a,g),[E,O]=await Promise.allSettled([v,b]);if(E.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+r);if(O.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+a);if(S.info("[DxfCompareHelper] loadFiles in "+(Date.now()-T)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const _=E.value,C=O.value;T=Date.now();const w=await new Ue(_,C,i).compare(x);if(S.info("[DxfCompareHelper] Compared in "+(Date.now()-T)/1e3+"s"),S.debug("[DxfCompareHelper] Compared results:",w),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");z.printMemory("After getting the comparison results"),T=Date.now(),await this.loader.loadEntitiesForCompare(_,C,w,!0,y),z.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=w,S.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-T)/1e3+"s");const M=_,P=C;if(this.decreaseJobCount(),!Object.keys(w).length&&S.info("[DxfCompareHelper] No change found"),M.threejsObject?.children.length===0&&P.threejsObject?.children.length===0){const k="[DxfCompareHelper] Nothing was loaded from "+r+" and "+a;return S.warn(k),Promise.reject(k)}const A=M.threejsObject,I=P.threejsObject;return A.name=r,I.name=a,T=Date.now(),this.viewer.addModel(new Wt({modelId:t.modelId||t.src,dxfData:M})),this.viewer.flyToObject(A),z.printMemory("After adding first loaded Model to scene"),u(95),this.viewer.addModel(new Wt({modelId:e.modelId||e.src,dxfData:P})),z.printMemory("After adding second loaded Model to scene"),S.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-T)/1e3+"s"),S.info("[DxfCompareHelper] The comparison between "+r+"' and '"+a+"' is completed in "+(Date.now()-o)/1e3+"s !"),u(100),this.loadingProgressBar?.delayRemoveProgressItem(l),Promise.resolve()}getChanges(){return this.changes}zoomToChange(t){if(this.changes){const e=this.changes[t];if(!e)return;const i=e.box;i&&this.viewer.zoomToBBox(i.clone().expandByScalar(1.2))}}setSpinnerVisibility(t){this.spinner&&(t?this.spinner.classList.remove("hidden"):this.spinner.classList.add("hidden"))}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){this.setSpinnerVisibility(--this.jobCount>0)}}class cc extends Zn{constructor(e,i){super(e);p(this,"viewer2");p(this,"syncCamera");p(this,"markupManager1");p(this,"markupManager2");p(this,"syncCameraControls");this.syncCamera=!1,this.syncCameraControls=(s,r,n)=>{const a=new d.Vector3,o=new d.Vector3,l=new d.Vector3;s.getPosition(o),s.getTarget(l),s.getFocalOffset(a),r.setLookAt(o.x,o.y,o.z,l.x,l.y,l.z),r.zoomTo(n),r.dispatchEvent({type:"control"})},this.viewer2=new Gs(i),this.initSyncCameraEvent()}initSyncCameraEvent(){const e=this.viewer.getCameraManager().cameraControls,i=this.viewer2.getCameraManager().cameraControls;let s=!1;e.addEventListener("control",()=>{s=!1}),e.addEventListener("update",()=>{!this.syncCamera||s||this.syncCameraControls(e,i,this.viewer.camera.zoom)}),i.addEventListener("control",()=>{s=!0}),i.addEventListener("update",()=>{!this.syncCamera||!s||this.syncCameraControls(i,e,this.viewer2.camera.zoom)})}enableSyncCamera(e){if(this.syncCamera=e,e){const i=this.viewer.getCameraManager().cameraControls,s=this.viewer2.getCameraManager().cameraControls;this.syncCameraControls(i,s,this.viewer.camera.zoom)}}async compare(e,i,s,r){const{src:n,modelId:a}=e,{src:o,modelId:l}=i;this.viewer.masterModelId=a||n,this.viewer2.masterModelId=l||o;const c=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const u=n+o,f=Re.t("ProgressBar.Comparing"),m=L=>{this.loadingProgressBar?.updateProgress(u,f,L),r&&r(new ProgressEvent("CompareProgress",{loaded:L,total:100}))},g=(L,q,me)=>{let ue=L.loaded*100/L.total;ue=ue*(me-q)/100+q,this.loadingProgressBar?.updateProgress(u,f,ue),r&&r(new ProgressEvent("CompareProgress",{loaded:ue,total:100}))},x=L=>g(L,0,15),y=L=>g(L,15,30),T=L=>g(L,30,60),v=L=>g(L,60,95);z.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(u),m(0);let b=Date.now();const E=this.loader.parse(n,x),O=this.loader.parse(o,y),[_,C]=await Promise.allSettled([E,O]);if(_.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+n);if(C.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+o);if(S.info("[DxfCompareHelper] loadFiles in "+(Date.now()-b)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const w=_.value,M=C.value;b=Date.now();const P=await new Ue(w,M,s).compare(T);if(S.info("[DxfCompareHelper] Compared in "+(Date.now()-b)/1e3+"s"),S.debug("Compared results:",P),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");z.printMemory("After getting the comparison results"),b=Date.now(),await this.loader.loadEntitiesForCompare(w,M,P,!1,v),z.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=P,S.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-b)/1e3+"s");const A=w,I=M;if(this.decreaseJobCount(),!Object.keys(P).length&&S.info("[DxfCompareHelper] No change found"),A.threejsObject?.children.length===0&&I.threejsObject?.children.length===0){const L="[DxfCompareHelper] Nothing was loaded from "+n+" and "+o;return S.warn(L),Promise.reject(L)}const k=A.threejsObject,B=I.threejsObject;return k.name=n,B.name=o,b=Date.now(),this.viewer.addModel(new Wt({modelId:e.modelId||e.src,dxfData:A})),z.printMemory("After adding first loaded Model to scene"),m(95),this.viewer2.addModel(new Wt({modelId:i.modelId||i.src,dxfData:I})),z.printMemory("After adding second loaded Model to scene"),this.drawCompareBoxes(),S.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-b)/1e3+"s"),S.info("[DxfCompareHelper] The comparison between "+n+"' and '"+o+"' is completed in "+(Date.now()-c)/1e3+"s !"),m(100),this.loadingProgressBar?.delayRemoveProgressItem(u),Promise.resolve()}drawCompareBoxes(){this.changes&&(this.markupManager1??(this.markupManager1=new As(this.viewer)),this.markupManager2??(this.markupManager2=new As(this.viewer2)),requestAnimationFrame(()=>{this.markupManager1?.drawCompareDrawable(this.changes),this.markupManager2?.drawCompareDrawable(this.changes),this.viewer.enableRender(),this.viewer2.enableRender()}))}zoomToChange(e){if(this.changes){const i=this.changes[e];if(!i)return;const s=i.box;s&&(this.viewer.zoomToBBox(s.clone().expandByScalar(1.2)),this.viewer2.zoomToBBox(s.clone().expandByScalar(1.2)))}}}class jt{constructor(t,e){p(this,"current");p(this,"next");p(this,"inNormal");p(this,"outNormal");this.current=t,this.next=e,this.inNormal=this.inwardsNormal(),this.outNormal=this.outwardsNormal()}outwardsNormal(){const t=this.inwardsNormal();return[-t[0],-t[1]]}inwardsNormal(){const t=this.next[0]-this.current[0],e=this.next[1]-this.current[1],i=Math.sqrt(t*t+e*e);if(i===0)throw new Error("Vertices overlap");return[-e/i,t/i]}offset(t,e){return jt.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return jt.offsetEdge(this.next,this.current,t,e)}inverse(){return new jt(this.next,this.current)}static offsetEdge(t,e,i,s){return new jt([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const ri=Array.isArray,en=(h,t)=>h[0]===t[0]&&h[1]===t[1],Cs=h=>Array.isArray(h)&&h.length,Kn=(h,t=0,e=!1)=>{let i,s;if(Cs(h)&&typeof h[0][0]=="number"){let r=0;const n=h;for(i=0,s=n.length;i<s;i++){const a=n[i],o=n[(i+1)%s];r+=a[0]*o[1],r-=o[0]*a[1]}(!e&&r>0||e&&r<0)&&n.reverse()}else for(i=0,s=h.length;i<s;i++)Kn(h[i],t+1,i>0);if(t===0&&Cs(h)&&Cs(h[0])&&typeof h[0][0][0]=="number"){const r=h[0].slice(0,1)[0];h[0].pop(),h[0].push([r[0],r[1]])}return h};class dc{constructor(t,e=5){p(this,"vertices");p(this,"edges");p(this,"arcSegments");p(this,"distance");if(this.distance=0,this.arcSegments=e,!ri(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],ri(t)&&typeof t[0]=="number"?this.vertices=t:(this.vertices=Kn(t),this.processContour(this.vertices,this.edges))}processContour(t,e){let i,s;if(ri(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,en(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new jt(t[i],t[(i+1)%s]));else for(t=t,e=e,i=0,s=t.length;i<s;i++)e.push([]),this.processContour(t[i],e[e.length-1])}setArcSegments(t){return this.arcSegments=t,this}createArc(t,e,i,s,r,n,a){const o=Math.PI*2;let l=Math.atan2(s[1]-e[1],s[0]-e[0]),c=Math.atan2(r[1]-e[1],r[0]-e[0]);n%2===0&&(n-=1),l<0&&(l+=o),c<0&&(c+=o);let u=l>c?l-c:l+o-c;const f=(a?-u:o-u)/n;t.push(s);for(let m=1;m<n;++m)u=l+f*m,t.push([e[0]+Math.cos(u)*i,e[1]+Math.sin(u)*i]);return t.push(r),t}setDistance(t){return this.distance=t,this}ensureLastPoint(t){return en(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t}offset(t){return this.setDistance(t),this.distance===0?this.vertices:this.distance>0?this.margin(this.distance):this.padding(-this.distance)}offsetSegment(t,e,i,s){const r=[i.offset(i.inNormal[0]*s,i.inNormal[1]*s),i.inverseOffset(i.outNormal[0]*s,i.outNormal[1]*s)],n=[];for(let a=0,o=2;a<o;a++){const l=r[a],c=r[(a+o-1)%o];this.createArc(n,a===0?t:e,s,c.next,l.current,this.arcSegments,!0)}return n}margin(t){if(this.setDistance(t),typeof this.vertices[0]=="number")return this.offsetPoint(this.distance);if(t===0)return this.vertices;let e=this.offsetLines(this.distance);return e=Zt.union(this.vertices,e),e}padding(t){if(this.setDistance(t),this.distance===0)return this.vertices;if(this.vertices.length===2&&typeof this.vertices[0]=="number")return this.vertices;const e=this.offsetLines(this.distance);return Zt.difference(this.vertices,e)}offsetLine(t){return t===0?this.vertices:this.offsetLines(t)}offsetLines(t){if(t<0)throw new Error("Cannot apply negative margin to the line");this.setDistance(t);let e=[];if(ri(this.vertices[0])&&typeof this.vertices[0][0]!="number"){const i=[];for(let s=0,r=this.edges.length;s<r;s++){const n=this.offsetContour(this.vertices[s],this.edges[s]);n.length>0&&i.push(n)}i.length>0&&(e=i.length===1?i[0]:Zt.union(i[0],...i.slice(1)))}else e=this.vertices.length===1?this.offsetPoint(t):this.offsetContour(this.vertices,this.edges);return e}offsetContour(t,e){let i=[],s=0,r=0;if(ri(t[0])&&typeof t[0][0]=="number"){for(s=0,r=t.length-1;s<r;s++){const n=this.ensureLastPoint(this.offsetSegment(t[s],t[s+1],e[s],this.distance)),a=[n];i.push(a)}i.length>0&&(i=i.length===1?[i[0]]:Zt.union(i[0],i.slice(1)))}else{const n=[];for(s=0,r=e.length;s<r;s++){const a=this.offsetContour(t[s],e[s]);a.length>0&&n.push(a)}n.length>0&&(i=n.length===1?n[0]:Zt.union(n[0],...n.slice(1)))}return i}offsetPoint(t){this.setDistance(t);let e=this.arcSegments*2;const i=[],s=this.vertices,r=this.distance;let n=0;e%2===0&&e++;for(let a=0;a<e;a++)n+=2*Math.PI/e,i.push([s[0]+r*Math.cos(n),s[1]+r*Math.sin(n)]);return[[this.ensureLastPoint(i)]]}}class $n{constructor(t){p(this,"viewer");p(this,"composerEnabled");p(this,"composer");p(this,"renderPass");p(this,"effectFxaaPass");p(this,"saoPass");p(this,"ssaoPass");p(this,"outlinePass");p(this,"ssaaRenderPass");p(this,"bloomPass");p(this,"unrealBloomPass");p(this,"vertexNormalsHelpers");this.composerEnabled=!0,this.viewer=t,this.composer=new Ba.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(re.AfterRender,()=>this.render())}get enabled(){return this.composerEnabled}set enabled(t){this.composerEnabled=t}get renderPassEnabled(){return!!this.renderPass?.enabled}set renderPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:r}=this.viewer.container;if(this.composer){if(t&&!this.renderPass){const n=new La.RenderPass(e,i);n.setSize(s,r),this.composer.addPass(n),this.renderPass=n}this.renderPass&&(this.renderPass.enabled=t),this.viewer.enableRender()}}get fxaaPassEnabled(){return!!this.effectFxaaPass?.enabled}set fxaaPassEnabled(t){if(!this.composer)return;const{width:e,height:i}=this.viewer.container;if(t&&!this.effectFxaaPass){const s=new Ra.ShaderPass(Na.FXAAShader);s.uniforms.resolution.value.set(1/e,1/i),s.renderToScreen=!0,s.setSize(e,i),this.composer.addPass(s),this.effectFxaaPass=s}this.effectFxaaPass&&(this.effectFxaaPass.enabled=t),this.viewer.enableRender()}get saoPassEnabled(){return!!this.saoPass?.enabled}set saoPassEnabled(t){const{width:e,height:i}=this.viewer.container,s=this.viewer.scene,r=this.viewer.camera;if(this.composer){if(t&&!this.saoPass){const n=new Fa.SAOPass(s,r,new d.Vector2(1/e,1/i));n.setSize(e,i),n.params.output=0,n.params.saoBias=.5,n.params.saoIntensity=3e-4,n.params.saoScale=8,n.params.saoKernelRadius=40,n.params.saoMinResolution=0,this.composer.addPass(n),this.saoPass=n}this.saoPass&&(this.saoPass.enabled=t),this.viewer.enableRender()}}get ssaoPassEnabled(){return!!this.ssaoPass?.enabled}set ssaoPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:r}=this.viewer.container;if(this.composer){if(t&&!this.ssaoPass){const n=new za.SSAOPass(e,i,s,r);n.kernelRadius=16,n.minDistance=1e-4,n.maxDistance=.3,this.composer.addPass(n),this.ssaoPass=n}this.ssaoPass&&(this.ssaoPass.enabled=t),this.viewer.enableRender()}}get outlinePassEnabled(){return!!this.outlinePass?.enabled}set outlinePassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:r}=this.viewer.container;if(this.composer){if(t&&!this.outlinePass){const n=new ja.OutlinePass(new d.Vector2(s,r),e,i);n.edgeStrength=3,n.edgeGlow=0,n.edgeThickness=2,n.pulsePeriod=0,n.visibleEdgeColor.set(16711680),n.hiddenEdgeColor.set(16752768),this.composer.addPass(n),this.outlinePass=n}this.outlinePass&&(this.outlinePass.enabled=t),this.viewer.enableRender()}}get ssaaPassEnabled(){return!!this.ssaaRenderPass?.enabled}set ssaaPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera;if(this.composer){if(t&&!this.ssaaRenderPass){const s=new Va.SSAARenderPass(e,i,16777215,0);this.composer.addPass(s),this.ssaaRenderPass=s,this.ssaaRenderPass=s}this.ssaaRenderPass&&(this.ssaaRenderPass.enabled=t),this.viewer.enableRender()}}get bloomPassEnabled(){return!!this.bloomPass?.enabled}set bloomPassEnabled(t){if(this.composer){if(t&&!this.bloomPass){const e=new Ua.BloomPass(1,25,4);e.renderToScreen=!0,this.composer.addPass(e),this.bloomPass=e}this.bloomPass&&(this.bloomPass.enabled=t),this.viewer.enableRender()}}get unrealBloomPassEnabled(){return!!this.unrealBloomPass?.enabled}set unrealBloomPassEnabled(t){const{width:e,height:i}=this.viewer.container;if(this.composer){if(t&&!this.unrealBloomPass){const s=new Ha.UnrealBloomPass(new d.Vector2(e,i),1,0,0);s.threshold=0,s.strength=.5,s.radius=0,this.composer.addPass(s),this.unrealBloomPass=s}this.unrealBloomPass&&(this.unrealBloomPass.enabled=t),this.viewer.enableRender()}}setOutlinePassSelectObjects(t){this.outlinePass&&(this.outlinePass.selectedObjects=t)}enableModelEdges(t){const e=this.viewer.loadedModels;for(let i=0;i<e.length;++i){const s=e[i];if(s instanceof zs)if(t&&!s.edges){const r=s.getModelObject();r&&(S.debug("[Viewer] Generating outlines for model '"+r.id+"'"),s.enableOutline(t))}else s.edges&&s.edges.forEach(r=>r.visible=t);else s instanceof Vs&&S.warn("[BimTiles] enableModelEdges() is not implemented for bimtiles yet.")}this.viewer.enableRender()}showVertexNormals(t,e=.1){t?(!this.vertexNormalsHelpers&&(this.vertexNormalsHelpers=new d.Group),this.viewer.scene.traverseVisible(i=>{const s=["SKYBOX","GROUND_GRID","GROUND_GRASS","BIM_VIEWER_BOX_HELPER"];if(i instanceof d.Mesh&&!s.includes(i.name)){if(!i.geometry.attributes.normal)return;const n=new Ga.VertexNormalsHelper(i,e,16711680);this.vertexNormalsHelpers?.add(n)}}),this.viewer.scene.add(this.vertexNormalsHelpers)):this.vertexNormalsHelpers&&(this.viewer.scene.remove(this.vertexNormalsHelpers),this.vertexNormalsHelpers=void 0)}render(){!this.composer||!this.enabled||this.composer.render()}destroy(){this.renderPass&&(this.composer?.removePass(this.renderPass),this.renderPass.dispose(),this.renderPass=void 0),this.effectFxaaPass&&(this.composer?.removePass(this.effectFxaaPass),this.effectFxaaPass.dispose(),this.effectFxaaPass=void 0),this.saoPass&&(this.composer?.removePass(this.saoPass),this.saoPass.dispose(),this.saoPass=void 0),this.ssaoPass&&(this.composer?.removePass(this.ssaoPass),this.ssaoPass.dispose(),this.ssaoPass=void 0),this.outlinePass&&(this.composer?.removePass(this.outlinePass),this.outlinePass.dispose(),this.outlinePass=void 0),this.ssaaRenderPass&&(this.composer?.removePass(this.ssaaRenderPass),this.ssaaRenderPass.dispose(),this.ssaaRenderPass=void 0),this.bloomPass&&(this.composer?.removePass(this.bloomPass),this.bloomPass.dispose(),this.bloomPass=void 0),this.unrealBloomPass&&(this.composer?.removePass(this.unrealBloomPass),this.unrealBloomPass.dispose(),this.unrealBloomPass=void 0),this.composer&&(this.composer?.dispose(),this.composer=void 0)}}class uc extends Qi{constructor(e,i){super(e);p(this,"name");p(this,"loadedModels");p(this,"distanceCullingFactor");p(this,"selectedObject");p(this,"effect");if(this.name=Be.Viewer3d,this.loadedModels=[],this.distanceCullingFactor=150,this.effect=new $n(this),this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new d.Vector3(100,50,100),r=new d.Vector3(0,0,0),n={eye:s,look:r};this.cameraManager.flyToViewpoint(n)}this.cameraManager.setProjection($e.Perspective),this.cameraManager.setNavigationMode(He.Orbit),this.setupDefaultEvents(),this.setDefaultBackground()}setupDefaultEvents(){let e=!1,i,s=0,r=0,n=0;const a=300,o=f=>r===-1||n===-1?!1:Math.abs(f.x-r)<5&&Math.abs(f.y-n)<5,l=f=>{const m=f.timestamp-s;return!!(f.button===Le.Left&&m<a&&o(f))};let c,u=!1;this.inputManager.addEventListener("pointerdown",f=>{e=!1,i=f.button;const m=new d.Vector2(f.x,f.y);c=this.pickObject(m),u=c?.object===this.selectedObject,f.button===Le.Left&&this.handleAnchorPoint(c)}),this.inputManager.addEventListener("pointermove",f=>{i!==void 0&&(e=!o(f),i===Le.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0))}),this.inputManager.addEventListener("pointerup",f=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}f.button===Le.Left?l(f)?(c?.object?this.flyToObject(c.object):this.viewFitAll(),s=0,r=-1,n=-1):(this.selectedObject&&(this.selectedObject instanceof pt?this.selectedObject.selected=!1:this.clearHighlight(),this.selectedObject=void 0),s=f.timestamp,r=f.x,n=f.y,c?.object&&!u&&this.handleClickObject(c.object)):(f.button,Le.Right)})}setDefaultBackground(){this.sceneManager.renderer.setClearColor(11119017,1),this.sceneManager.setBackground(null),this.sceneManager.setEnvironmentFromData()}handleAnchorPoint(e){const i=new d.Vector3;this.selectedObject?new d.Box3().setFromObject(this.selectedObject).getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=n=>!n.userData.modelId&&n.parent?i(n.parent):n.userData.modelId,s=i(e);this.loadedModels.find(n=>n.modelId===s)?.highlightObject(e),this.selectedObject=e,this.enableRender()}is3d(){return!0}async loadLocalModel(e,i,s,r){return this.loadModelInternal(i,r,!0,e,s)}async loadModel(e,i){return this.loadModelInternal(e,i)}async loadModelInternal(e,i,s,r,n){this.spinner.increaseJobCount();const a=e.modelId||e.src,o=Re.t("ProgressBar.Loading"),l=b=>{this.progressBar?.updateProgress(a,o,b),i?.(new ProgressEvent("LoadProgress",{loaded:b,total:100}))};let c=!1;const u=(b,E,O)=>{let _=b.loaded*100/b.total;_=_*(O-E)/100+E,_>O&&(c||(S.warn("[Progress] Invalid ProgressEvent:",b),c=!0),_=O),this.progressBar?.updateProgress(a,o,_),i?.(new ProgressEvent("LoadProgress",{loaded:_,total:100}))},f=b=>u(b,0,50);this.progressBar?.addProgressItem(a),l(0);let m;if(s?(this.loaderHelper.setLoadManager(n),m=await this.loaderHelper.loadLocalModel(r,e.src,i)):m=await this.loaderHelper.loadModel(e.src,e.fileFormat,f),e.matrix&&e.matrix.length===16){const b=new d.Matrix4;b.elements=e.matrix,m.applyMatrix4(b)}const g=this.getUniqueModelId(e.modelId||e.src),x=new zs({modelId:g,object:m});this.addModel(x),l(90);const y=x.getBBox();this.loadedModels.length===1&&setTimeout(()=>this.goToHomeView(),0);const v=new d.Vector3;y.getCenter(v),this.cameraManager.setOrbitPoint(v),this.spinner.decreaseJobCount(),l(100),this.progressBar?.delayRemoveProgressItem(a),this.dispatchEvent(re.ModelLoad)}setDistanceCullingFactor(e){this.distanceCullingFactor=e}getDistanceCullingFactor(){return this.distanceCullingFactor}setObjectOpacity(e,i){this.loadedModels.forEach(s=>s.setObjectOpacity(e,i)),this.enableRender()}setOtherObjectsOpacity(e,i){this.loadedModels.forEach(s=>{s.setOpacity(i),s.clearObjectOpacity(e)}),this.enableRender()}clearObjectOpacity(e){this.loadedModels.forEach(i=>i.clearObjectOpacity(e)),this.enableRender()}setModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.setOpacity(),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}setObjectVisible(e,i){this.loadedModels.forEach(s=>s.setObjectVisible(e,i)),this.enableRender()}hideOtherObjects(e){this.loadedModels.forEach(i=>{i.setVisible(!1),i.setObjectVisible(e,!0)}),this.enableRender()}setModelVisible(e,i){this.loadedModels.find(r=>r.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}enableModelOutline(e,i){this.loadedModels.find(r=>r.modelId===e)?.enableOutline(i),this.enableRender()}enableModelsOutline(e){this.loadedModels.forEach(i=>i.enableOutline(e)),this.enableRender()}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof pt&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}enableSsao(e){this.effect.enabled=e,this.effect.renderPassEnabled=e,this.effect.ssaaPassEnabled=e,this.effect.ssaoPassEnabled=e}getSsaoEnabled(){return this.effect.enabled&&this.effect.ssaoPassEnabled}async setEnvironmentData(e){await this.sceneManager.setEnvironmentFromData(e),this.enableRender()}async setEnvironment(e){await this.sceneManager.setEnvironment(e),this.enableRender()}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}setModelClipPlanes(e,i){this.loadedModels.find(r=>r.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(i),this.sceneManager.setClipPlanes(e)}}function tn(h){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),h)}function sn(h){return Object.assign(Object.assign({},{elementCount:0,batchElementCount:0,instanceElementCount:0,batchCount:0,instanceCount:0,tileCount:0,userDataCount:0,materialCount:0,meshVertexCount:0,meshFaceCount:0,textureCount:0,texturePixels:0}),h)}function fc(h){const t={transform:new d.Matrix4,boundingVolume:new d.Box3};return Object.assign(Object.assign({},t),h)}class pc{constructor(t){p(this,"url");p(this,"metadata");p(this,"statistics");p(this,"view");this.url=t,this.metadata=tn(),this.statistics=sn(),this.view=fc()}async parse(){return await fetch(this.url).then(t=>t.ok?t.json():(S.error('[BimTiles] Failed to request "'+this.url+'", status '+t.status+" : "+t.statusText),Promise.reject(!1))).then(t=>(this.metadata=tn(t.metadata),this.statistics=sn(t.statistics),t.view.transform&&t.view.transform.length===16&&this.view.transform.fromArray(t.view.transform),t.view.boundingVolume&&t.view.boundingVolume.length===6&&this.view.boundingVolume.setFromArray(t.view.boundingVolume),Promise.resolve(!0)))}getMetadata(){return this.metadata}getStatistics(){return this.statistics}getView(){return this.view}}let mc=0;class gc extends Qi{constructor(e,i){super(e);p(this,"name");p(this,"pickUsageScene");p(this,"effect");p(this,"loadedModels");p(this,"selectedObject");p(this,"enableHoverEffect");if(this.name=Be.BimTilesViewer,this.loadedModels=[],this.enableHoverEffect=!1,this.effect=new $n(this),this.pickUsageScene=new d.Scene,this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new d.Vector3(100,50,100),r=new d.Vector3(0,0,0),n={eye:s,look:r};this.cameraManager.flyToViewpoint(n)}this.cameraManager.setProjection($e.Perspective),this.cameraManager.setNavigationMode(He.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(re.BeforeRender,()=>{this.update3dTiles()})}setupDefaultEvents(){let e=!1,i,s=0,r=0,n=0;const a=300,o=f=>r===-1||n===-1?!1:Math.abs(f.x-r)<5&&Math.abs(f.y-n)<5,l=f=>{const m=f.timestamp-s;return!!(f.button===Le.Left&&m<a&&o(f))};let c,u=!1;this.inputManager.addEventListener("pointerdown",f=>{e=!1,i=f.button,this.renderImmediately();const m=new d.Vector2(f.x,f.y);if(c=this.pickManager.pick(m,this.pickUsageScene),u=!!this.selectedObject&&c?.tilesetId===this.selectedObject?.tilesetId&&c?.userId===this.selectedObject?.userId,f.button===Le.Left){let g=this.pickUsageScene;if(c){const y=this.loadedModels.find(T=>T.modelId===""+c?.tilesetId);if(y){const T=y.getObjectByUserId(c.userId);T&&(g=T)}}const x=this.pickManager.pickObject(m,[g]);this.handleAnchorPoint(x)}}),this.inputManager.addEventListener("pointermove",f=>{if(i!==void 0)e=!o(f),i===Le.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0);else if(this.enableHoverEffect){const m=new d.Vector2(f.x,f.y),g=this.pickManager.pick(m,this.pickUsageScene),x=this.getHoveredObject();g?(!x||x.tilesetId!==g.tilesetId||x.userId!==g.userId)&&this.setObjectHoveredByUserId(g.tilesetId,g.userId,!0):x&&this.clearHovered()}this.handleMouseMove(f)}),this.inputManager.addEventListener("pointerup",f=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}f.button===Le.Left?l(f)?(c?this.flyToUserId(c.tilesetId,c.userId):this.viewFitAll(),s=0,r=-1,n=-1):(this.selectedObject&&(this.clearHighlight(),this.selectedObject=void 0),s=f.timestamp,r=f.x,n=f.y,c&&!u&&this.handleClickObject(c)):(f.button,Le.Right)})}setDefaultBackground(){this.sceneManager.setBackground(new d.Color(11119017)),this.sceneManager.setEnvironmentFromData()}renderImmediately(){const{renderer:e,scene:i,camera:s}=this;!e||!i||!s||e.render(i,s)}handleAnchorPoint(e){const i=new d.Vector3;this.selectedObject?this.getBoxByUserId(this.selectedObject.tilesetId,this.selectedObject.userId)?.getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=this.loadedModels.find(s=>s.modelId===""+e.tilesetId);i&&(i?.setObjectHighlightedByUserIds([e.userId],!0),this.selectedObject=e),this.enableRender()}is3d(){return!0}setModelOpacity(e,i){this.loadedModels.find(r=>r.modelId===e)?.setOpacity(i),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}enableModelOutline(e,i){S.warn("Outline for bimtiles is not implemented yet.")}enableModelsOutline(e){S.warn("Outline for bimtiles is not implemented yet.")}setModelVisible(e,i){this.loadedModels.find(r=>r.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof pt&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}flyToUserId(e,i){const s=this.getBoxByUserId(e,i);s&&this.cameraManager.flyToBox(s)}getBoxByUserId(e,i){const s=this.loadedModels.find(r=>r.modelId===""+e);if(s)return s.getBBoxByUserId(i)}handleMouseMove(e){}update3dTiles(){if(!this.camera)return;const e=this.loadedModels.filter(i=>!!i.tilesRenderer);e.length!==0&&(this.camera.updateMatrixWorld(),e.forEach(i=>{i.tilesRenderer.update()}))}async loadModel(e,i){if(e.src.length===0)return Promise.reject();const s=new pc(e.src);if(!await s.parse())return Promise.reject();let n=e.src.replace(/\/[^\\/]*\/?$/,"/");n=new URL(n,window.location.href).toString(),this.spinner.increaseJobCount();const a=s.getView().boundingVolume.clone();a.applyMatrix4(s.getView().transform);const o=new Vs({modelId:""+mc++,bbox:a},n,s),l=o.getTilesRenderer(),c=l.group;if(l.onBeforeParseTile=()=>{this.spinner.increaseJobCount()},l.onLoadModel=u=>{u.traverse(f=>{f.matrixAutoUpdate&&(f.matrixAutoUpdate=Ne,f.updateMatrix()),f.isMesh&&(f.castShadow=!0,f.receiveShadow=!0),f.geometry&&f.layers.enableAll()}),this.enableRender(),setTimeout(()=>this.spinner.decreaseJobCount(),100)},l.setCamera(this.camera),l.setResolutionFromRenderer(this.camera,this.renderer),l.update(),c){c.applyMatrix4(s.getView().transform),o.pickUsageGroup.applyMatrix4(s.getView().transform),this.pickUsageScene.add(o.pickUsageGroup),this.addModel(o),this.cameraManager.adjustCameraByBBox(a);const u=new d.Vector3;return a.getCenter(u),this.cameraManager.setOrbitPoint(u),this.loadedModels.length===1&&this.goToHomeView(),this.spinner.decreaseJobCount(),this.dispatchEvent(re.ModelLoad),Promise.resolve()}return this.spinner.decreaseJobCount(),Promise.reject()}setObjectHighlightedByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectHighlightedByUserIds(i,s),this.enableRender()}setObjectOpacityByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectOpacityByUserIds(i,s),this.enableRender()}setOtherObjectOpacityByUserIds(e,i,s){this.loadedModels.forEach(a=>{a.setOpacity(s)});const r=""+e;this.loadedModels.find(a=>a.modelId===r)?.clearObjectOpacityByUserIds(i),this.enableRender()}setObjectVisibleByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectVisibleByUserIds(i,s),this.enableRender()}setOtherObjectVisibleByUserIds(e,i,s){this.loadedModels.forEach(n=>{n.setVisible(s)}),this.loadedModels.find(n=>n.modelId===""+e)?.setObjectVisibleByUserIds(i,!s),this.enableRender()}setObjectHoveredByUserId(e,i,s){if(!this.enableHoverEffect)return;this.clearHovered(),this.loadedModels.find(n=>n.modelId===""+e)?.setObjectHoveredByUserId(i,s),this.enableRender()}getHoveredObject(){for(const e of this.loadedModels){const i=e.getHoveredObject();if(i)return i}}clearHovered(){this.loadedModels.forEach(e=>e.clearHovered()),this.enableRender()}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}setModelClipPlanes(e,i){this.loadedModels.find(r=>r.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(!i),this.sceneManager.setClipPlanes(e)}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}pickObjects(e,i){const s=this.pickManager.pick(e,this.pickUsageScene);let r=this.pickUsageScene;if(s){const a=this.loadedModels.find(o=>o.modelId===""+s?.tilesetId);if(a){const o=a.getObjectByUserId(s.userId);o&&(r=o)}}let n=this.pickManager.pickObjects(e,[r],i);return n&&this.renderer.clippingPlanes.length>0&&(n=n.filter(a=>this.renderer.clippingPlanes.every(function(o){return o.distanceToPoint(a.point)>0}))),n}getErrorTarget(){return this.loadedModels.length>0?this.loadedModels[0].getTilesRenderer().errorTarget:8}setErrorTarget(e){this.loadedModels.forEach(i=>{i.getTilesRenderer().errorTarget=e})}}class yc extends mt{constructor(e,i){if(!i.id)throw new Error("[Plugin] Missing plugin id!");super();p(this,"id");p(this,"viewer");this.id=i.id,this.viewer=e,e.addPlugin(this)}destroy(){this.viewer.removePlugin(this)}}K.install({THREE:d});class xc extends K{constructor(e,i){super(e,i);p(this,"minZoom");p(this,"draggingSmoothTime");p(this,"dollySpeedBackup");p(this,"azimuthRotateSpeedBackup");p(this,"polarRotateSpeedBackup");p(this,"truckSpeedBackup");p(this,"onKeyDown");p(this,"onKeyUp");p(this,"keyTruckSpeed");p(this,"keys");this.minZoom=0,this.draggingSmoothTime=0,this.keyTruckSpeed=7,this.keys={left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",bottom:"ArrowDown"},this.onKeyDown=s=>{if(this.enabled){switch(s.code){case this.keys.up:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,1),this._isUserControllingRotate=!0):(this._truckInternal(0,this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.bottom:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,-1),this._isUserControllingRotate=!0):(this._truckInternal(0,-this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.left:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(1,0),this._isUserControllingRotate=!0):(this._truckInternal(this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break;case this.keys.right:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(-1,0),this._isUserControllingRotate=!0):(this._truckInternal(-this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break}this.dispatchEvent({type:"control"})}},this.onKeyUp=s=>{this.dispatchEvent({type:"controlend"})},this._getClientRect(this._elementRect),this.dollySpeedBackup=this.dollySpeed,this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.truckSpeedBackup=this.truckSpeed}get enableZoom(){return!!this.dollySpeed}set enableZoom(e){e?this.dollySpeed=this.dollySpeedBackup:(this.dollySpeedBackup=this.dollySpeed,this.dollySpeed=0)}get enableRotate(){return!!this.azimuthRotateSpeed||!!this.polarRotateSpeed}set enableRotate(e){e?(this.azimuthRotateSpeed=this.azimuthRotateSpeedBackup,this.polarRotateSpeed=this.polarRotateSpeedBackup):(this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.azimuthRotateSpeed=0,this.polarRotateSpeed=0)}get enableTruck(){return!!this.truckSpeed}set enableTruck(e){e?this.truckSpeed=this.truckSpeedBackup:(this.truckSpeedBackup=this.truckSpeed,this.truckSpeed=0)}listenToKeyEvents(){this._domElement?.addEventListener("keydown",this.onKeyDown),this._domElement?.addEventListener("keyup",this.onKeyUp)}stopListenToKeyEvents(){this._domElement?.removeEventListener("keydown",this.onKeyDown),this._domElement?.removeEventListener("keyup",this.onKeyUp)}dispose(){super.dispose(),this.stopListenToKeyEvents()}}var Jn=(h=>(h[h.Browser=0]="Browser",h[h.Browserless=1]="Browserless",h[h.Headless=2]="Headless",h))(Jn||{});class bc{constructor(t,e,i){p(this,"containerOrCanvas");p(this,"glContext");p(this,"camera");p(this,"scene");p(this,"renderer");p(this,"renderTarget");p(this,"controls");p(this,"selectedObject");p(this,"loadedModels");p(this,"pmremGenerator");p(this,"clock");p(this,"viewerMode");p(this,"raycaster");p(this,"savedMaterialsForOpacity");p(this,"jobCount");p(this,"bbox");p(this,"outlineMaterial");p(this,"outlineRoot");p(this,"transparentObjectIds");p(this,"requestAnimationFrameHandle");p(this,"applyOptionsAndAddToScene");p(this,"getMeshes");if(this.scene=this.initScene(),this.selectedObject=void 0,this.loadedModels=[],this.clock=new d.Clock,this.viewerMode=0,this.raycaster=new d.Raycaster,this.savedMaterialsForOpacity=[],this.jobCount=0,this.bbox=new d.Box3,this.outlineMaterial=new d.LineBasicMaterial({color:1118481}),this.outlineRoot=new d.Group,this.transparentObjectIds=[],this.applyOptionsAndAddToScene=async(s,r,n,a)=>{if(S.info("[Viewer] '"+s+"' is loaded, adding to scene..."),n.matrix&&n.matrix.length===16){const f=new d.Matrix4;f.elements=n.matrix,r.applyMatrix4(f)}r.traverse(f=>{f.geometry&&f.layers.enableAll(),f instanceof d.Light&&(f.visible=!1)});let o;n.edges&&(o=await $.createOutlines(r,void 0,a));let l=n.modelId||n.src;const c=f=>!!this.loadedModels.find(m=>m.modelId===f);if(c(l)){let f=1;for(;c(l+"_"+f);)f++;l=l+"_"+f,S.warn("[Viewer] Model '"+l+"' is loaded more than once!")}const u={modelId:l,object:r,edges:o};this.addModel(u)},this.getMeshes=s=>{const r=[];return s instanceof d.Mesh?r.push(s):s.traverseVisible(n=>{n instanceof d.Mesh&&r.push(n)}),r},this.containerOrCanvas=t,e&&(this.viewerMode=e),this.glContext=i,this.viewerMode===1&&!(!(t instanceof HTMLDivElement)&&i))throw new Error("[Viewer] Parameters don't match Browserless viewerMode !");this.increaseJobCount(),this.init(),this.decreaseJobCount(),S.info("[Viewer] Initialized"),this.animate()}init(){this.initRenderer(),this.initCamera(),this.initControls(),this.initLights(),this.initPointerEvents(),this.scene.add(this.outlineRoot)}initScene(){const t=new d.Scene;return t.background=new d.Color(7112861),t.matrixAutoUpdate=!0,t}isBrowserlessMode(){return this.viewerMode===1}isBrowserMode(){return this.viewerMode===0}initRenderer(){const t={antialias:!0,preserveDrawingBuffer:!0},e=this.isBrowserlessMode();e&&Object.assign(t,{canvas:this.containerOrCanvas,context:this.glContext});const i=new d.WebGLRenderer(t);if(e){const s=this.containerOrCanvas.width,r=this.containerOrCanvas.height;S.info("[Viewer] Render target size: "+s+" x "+r),this.renderTarget=new d.WebGLRenderTarget(s,r,{minFilter:d.LinearFilter,magFilter:d.NearestFilter,format:d.RGBAFormat,type:d.UnsignedByteType}),i.setRenderTarget(this.renderTarget)}else{const s=this.containerOrCanvas.clientWidth,r=this.containerOrCanvas.clientHeight;this.containerOrCanvas.append(i.domElement),i.setPixelRatio(window.devicePixelRatio),i.setSize(s,r)}i.outputColorSpace=d.SRGBColorSpace,i.toneMappingExposure=1,i.setClearColor(11119017,1),i.shadowMap.enabled=!0,i.shadowMap.type=d.PCFSoftShadowMap,this.renderer=i,e||(this.pmremGenerator=new d.PMREMGenerator(i),this.pmremGenerator.compileEquirectangularShader(),this.setEnvironmentFromDataArray())}initCamera(){if(!this.scene)return;const t=this.containerOrCanvas.clientWidth||this.containerOrCanvas.width||0,e=this.containerOrCanvas.clientHeight||this.containerOrCanvas.height||0;let i=1;t&&e&&(i=t/e),this.camera=new d.PerspectiveCamera(68,i,.05,1e4),this.camera.position.set(10,10,10),this.camera.lookAt(0,0,0),this.scene.add(this.camera)}initControls(){if(!this.renderer)return;const t=this.camera;if(!t)return;const e=new xc(t,this.renderer.domElement);e.smoothTime=.05,e.enabled=!0,e.keyTruckSpeed=10,e.keys={left:"KeyD",up:"KeyE",right:"KeyA",bottom:"KeyQ"},e.update(0),this.controls=e,e.addEventListener("update",()=>{!this.isBrowserMode()&&this.renderer&&this.renderer.render(this.scene,t)})}initLights(){if(!this.scene)return;const t=16777215,e=.3,i=new d.DirectionalLight(t,e);i.position.set(-2,2,4);const s=new d.AmbientLight(3158064),r=new d.HemisphereLight(t,14540253,3);r.position.set(0,300,0),this.scene.add(i),this.scene.add(s),this.scene.add(r)}initPointerEvents(){if(!this.renderer||!this.camera||!this.controls)return;let t=!1,e=!1,i=-1,s=-1;this.renderer.domElement.addEventListener("pointerdown",r=>{i=r.x,s=r.y,t=!1}),this.renderer.domElement.addEventListener("pointermove",r=>{i>=0&&s>=0&&(Math.abs(r.x-i)>5||Math.abs(r.y-s)>5)&&(t=!0)}),this.renderer.domElement.addEventListener("pointerup",()=>{e&&setTimeout(()=>{e=!1},200),i=-1,s=-1}),this.renderer.domElement.addEventListener("dblclick",r=>{e=!0,t||(this.handleMouseClick(r),this.flyToSelectedObject())})}animate(){this.isBrowserMode()&&requestAnimationFrame(this.animate.bind(this));const t=this.clock.getDelta();this.controls&&this.controls.update(t),this.scene&&this.camera&&this.renderer?.render(this.scene,this.camera)}destroy(){this.camera=void 0,this.scene&&this.scene.clear(),this.requestAnimationFrameHandle&&(cancelAnimationFrame(this.requestAnimationFrameHandle),this.requestAnimationFrameHandle=void 0),this.renderer&&(this.containerOrCanvas.removeChild(this.renderer.domElement),this.renderer.clear(),this.renderer.dispose(),this.renderer=void 0),this.controls&&(this.controls.dispose(),this.controls=void 0),this.renderTarget&&(this.renderTarget.dispose(),this.renderTarget=void 0),this.raycaster=void 0,this.selectedObject=void 0,this.savedMaterialsForOpacity=void 0,this.loadedModels=[]}async loadLocalModel(t,e,i){const r=await new ut().loadLocalModel(t,e.src,i);return r?(await this.applyOptionsAndAddToScene(t,r,e),Promise.resolve()):Promise.reject()}async loadModel(t,e){this.increaseJobCount();const s=await new ut().loadModel(t.src,t.fileFormat,e);return s?(await this.applyOptionsAndAddToScene(t.src,s,t),Promise.resolve()):Promise.reject()}parseGltf(t,e,i,s){this.increaseJobCount(),new ut().parseGltf(t,e.src,r=>{this.applyOptionsAndAddToScene(e.src,r,e),i&&i(r)},r=>{s&&s(r)})}addModel(t){if(!this.scene||!this.renderer)return;this.increaseJobCount();const e=new d.Box3().setFromObject(t.object);t.bbox||(t.bbox=e),this.scene.add(t.object),this.loadedModels.push(t),this.computeBoundingBox(),this.loadedModels.length===1&&(this.tryAdjustCameraNearAndFar(),this.goToHomeView()),this.renderer.shadowMap.needsUpdate=!0,S.info("[Viewer] Added '"+t.modelId+"' to scene"),this.decreaseJobCount()}addOrRemoveObjectOpacity(t=!0,e=.3,i,s){if(this.savedMaterialsForOpacity||(this.savedMaterialsForOpacity=[]),!this.scene)return;const r=this.scene,n=[];this.loadedModels.forEach(a=>{const o=a.object.id;if(t){this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0&&$.revertObjectOpacityById(r,o,this.savedMaterialsForOpacity);const l=$.setObjectOpacityById(r,o,e,i,s);n.push(...l)}else this.savedMaterialsForOpacity&&$.revertObjectOpacityById(r,o,this.savedMaterialsForOpacity)}),t?this.savedMaterialsForOpacity=n:this.savedMaterialsForOpacity=[]}hasTransparentObject(){return!!(this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0)}getIntersections(t){if(!this.raycaster||!this.camera||!this.scene)return[];let e=new d.Vector2;t&&(e=pe.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=pe.screen2Ndc(e,this.camera,this.containerOrCanvas);this.raycaster.setFromCamera(i,this.camera);const s=[];return this.loadedModels.forEach(r=>{const n=r.object;n&&n.visible&&s.push(n)}),this.raycaster.intersectObjects(s,!0)||[]}handleMouseClick(t){this.raycaster&&this.raycaster.layers.set(ft);const i=this.getIntersections(t).find(r=>{const n=r.object;return n.visible&&n instanceof d.Mesh});let s=i&&i.object||void 0;s&&this.selectedObject&&this.selectedObject.id===s.id&&(s=void 0),s?this.selectObject(s):this.clearSelection()}selectObject(t){if(this.selectedObject){const i=this.selectedObject.userData;if(i.originalMaterial){if(this.selectedObject.material){const s=this.selectedObject.material;Array.isArray(s)?s.forEach(r=>r.dispose()):s instanceof d.Material&&s.dispose()}this.selectedObject.material=i.originalMaterial,delete i.originalMaterial}this.selectedObject=void 0}if(!this.scene||!t)return;const e=de.clonedHighlightMaterials(t);e&&(this.selectedObject=t,this.selectedObject.userData.originalMaterial=this.selectedObject.material,this.selectedObject.material=e)}clearSelection(){this.selectObject()}flyToObjects(t){if(!t||t.length===0||!this.camera)return;const e=new d.Box3;t.forEach(r=>{const n=rt.getBoundingBox(r);e.union(n)});const i=new d.Sphere;e.getBoundingSphere(i),this.controls?.fitToSphere(i,!0)}flyToObject(t){this.flyToObjects([t])}flyToSelectedObject(){this.selectedObject&&this.flyToObject(this.selectedObject)}flyTo(t,e,i){const s=this.camera,r=this.controls;if(!s||!r)return;t=Array.isArray(t)?new d.Vector3(t[0],t[1],t[2]):t,e=Array.isArray(e)?new d.Vector3(e[0],e[1],e[2]):e;const n=t,a=e;S.info("[Viewer] flyTo: ",z.vectorToString(n)),r.setPosition(n.x,n.y,n.z),r.setTarget(a.x,a.y,a.z),this.isBrowserMode()||this.renderer?.render(this.scene,s),i&&i()}goToHomeView(){const t=new d.Sphere;this.bbox.getBoundingSphere(t),this.controls?.fitToSphere(t,!0)}setEnvironmentFromDataArray(t){pi.createEnvTextureFromDataArray(this.pmremGenerator,t).then(e=>{this.scene.environment=e,this.isBrowserMode()||this.animate()})}tryAdjustCameraNearAndFar(){const t=this.camera;if(!this.scene||!t)return;const e=this.bbox,i=t.near,s=t.far,r=e.max.x-e.min.x,n=e.max.y-e.min.y,a=e.max.z-e.min.z,o=Math.max(r,n,a),l=5,c=o/l,u=o*l;if(i>c||s<u){const f=m=>z.numberToString(m);S.info("[Viewer] BBox's longest side is: "+f(o)),i>c&&(S.warn("[Viewer] camera.near("+f(i)+") shouldn't bigger than "+f(c)+", will change it!"),t.near=c),s<u&&(S.warn("[Viewer] camera.far("+f(s)+") shouldn't smaller than "+f(u)+", will change it!"),t.far=u)}t.updateProjectionMatrix()}isolateObjects(t){const e=this.transparentObjectIds.length>0?void 0:this.transparentObjectIds,i=this.transparentObjectIds.length>0?this.transparentObjectIds:void 0,s=new d.MeshBasicMaterial({color:16777215,transparent:!0,opacity:.1});this.loadedModels.forEach(n=>{const a=n.object.id;$.applyMaterialToObjectById(this.scene,a,s,i,e)}),this.outlineRoot.clear();let r=[];if(t.forEach(n=>{const a=n.modelId;let l=this.loadedModels.find(c=>c.modelId===a)?.object;l||(S.warn("[Viewer] The ModelId of "+a+" has no corresponding model."),l=this.scene),l.traverse(c=>{if(qs.includes(n.id,qs.get(c.userData,"UniqueId"))){const u=this.getMeshes(c);r=r.concat(u)}})}),r.length>0){r.forEach(a=>{const o=$.createOutline(a.geometry,this.outlineMaterial);o.applyMatrix4(a.matrixWorld),this.outlineRoot.add(o),o.updateWorldMatrix(!0,!1)});const n=r.map(a=>a.id);this.loadedModels.forEach(a=>{const o=a.object.id;$.revertAppliedMaterialToObjectById(this.scene,o,n)}),this.transparentObjectIds=n,this.flyToObjects(r)}else S.warn("[Viewer] No object found with uniqueIds: "+t.map(n=>n.id));this.isBrowserMode()||this.animate()}increaseJobCount(){++this.jobCount}decreaseJobCount(){--this.jobCount}computeBoundingBox(){const t=new d.Box3;return this.loadedModels.forEach(e=>{e.bbox&&!e.bbox.isEmpty()&&t.union(e.bbox)}),this.bbox=t,t}getContext(){return this.renderer?.getContext()}getCameraDirection(){const t=new d.Vector3;return this.camera?.getWorldDirection(t),{x:t.x,y:t.y,z:t.z}}setFov(t){this.camera&&(this.camera.fov=t,this.camera.updateProjectionMatrix())}}const Qn="1.0.0",ea="VERSION",ta=()=>window.localStorage.getItem(ea),ia=()=>{window.localStorage.setItem(ea,Qn)},vc=()=>ta()!==Qn?(ia(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>Se.Mesh});exports.BaseDxfCompareHelper=Zn;exports.BaseViewer=Qi;exports.BimTilesModel=Vs;exports.BimTilesRenderer=Bn;exports.BimTilesViewer=gc;exports.BinaryReader=vi;exports.BoxSelectHelper=$i;exports.ByBlock=mi;exports.ByLayer=Fs;exports.CSS2DObjectUtils=mo;exports.CameraProjection=$e;exports.CancelablePromise=uo;exports.CanvasRender=xi;exports.ColorUtils=qt;exports.CommonUtils=z;exports.CompareDrawable=Je;exports.Container=Us;exports.ControlsMode=He;exports.CoordinateUtils=pe;exports.DecimalPrecisionRange=an;exports.DefaultCameraFar=Hi;exports.DefaultCameraFov=hn;exports.DefaultCameraNear=Ui;exports.DefaultLanguage=on;exports.DefaultOpacity=Ls;exports.DefaultViewer3dConfig=Lh;exports.DeviceUtils=be;exports.Drawable=pt;exports.DrawableList=bi;exports.DxfChangeType=Te;exports.DxfCompare=Ue;exports.DxfCompareHelper=cc;exports.DxfCompareMarkupManager=As;exports.DxfLoader=Y;exports.DxfParser=Tn;exports.DxfRenderOrder=ge;exports.DxfUtils=et;exports.EdgeUtils=cn;exports.Event=mt;exports.ExportUtils=Ss;exports.FontManager=Ke;exports.FpsUtils=To;exports.GenerateMeshBvhWorker=Nn;exports.GeometryUtils=U;exports.GroundPlaneRenderOrder=Xn;exports.HighlightColor=Bs;exports.HighlightColorRgba=yo;exports.IconfontClass=xo;exports.IconfontClass2=bo;exports.InputManager=Yn;exports.InstantiateHelper=Nh;exports.LayerForHitableObjects=ln;exports.LayerForSelectableObjects=ft;exports.LayerForSnapableObjects=Ce;exports.Line=Ya;exports.LinePatternShaders=bn;exports.LoadingHelper=ut;exports.MaterialUtils=de;exports.MathUtils=R;exports.MatrixAutoUpdate=Ne;exports.MergeUtils=oe;exports.MeshBvhHelper=Ns;exports.MobileTouchHelperDrawable=ac;exports.Model=Ji;exports.Model2d=Wt;exports.Model3d=zs;exports.NestedCompareTypes=oi;exports.OSnapHelper=tc;exports.OSnapIconSize=Io;exports.OSnapMarkerType=it;exports.OSnapType=Gn;exports.ObjectPixelSizeHelper=Xh;exports.ObjectUtils=$;exports.Offset=dc;exports.OrbitControls=Fn;exports.OutlineColorRgba=Vi;exports.PickMarkupHelper=ic;exports.PlanControls=zn;exports.Plugin=yc;exports.Points=Xa;exports.PolygonUtils=Po;exports.ProgressBar=Hs;exports.RafHelper=Un;exports.SVGObjectUtils=ko;exports.SceneUtils=rt;exports.SectionUtils=dt;exports.ShaderChunk=co;exports.SimplifyUtils=Ao;exports.SnapDrawable=ye;exports.Spinner=Ln;exports.TextSearchHelper=Is;exports.TextureUtils=pi;exports.ThresholdAngleForEdge=Rs;exports.UnitConversionByMeter=Es;exports.UnitLabels=dn;exports.UnitScaleConversion=Yo;exports.UnitScaleToMeter=Ps;exports.Units=De;exports.Viewer2d=Gs;exports.Viewer3d=uc;exports.Viewer3dLite=bc;exports.Viewer3dUtils=Lo;exports.ViewerEvent=re;exports.ViewerMode=Jn;exports.ViewerName=Be;exports.Views=fn;exports.ZoomToRectHelper=Wn;exports.bspline=mn;exports.checkIsNewVersion=vc;exports.cn=Os;exports.createHatchPatternShaderMaterial=vn;exports.decodeDxfTextCharacterCodes=gn;exports.decodeDxfTextMbcsCharacterCodes=xn;exports.decodeDxfTextUnicodeCodePoints=yn;exports.en=Co;exports.getLengthValueByUnit=Bo;exports.getUnitStr=_s;exports.getVersionFromLocalStorage=ta;exports.i18n=Re;exports.log=S;exports.parseDxfMTextContent=li;exports.parseDxfTextContent=Ni;exports.round10=pn;exports.setIcon=po;exports.setLogLevel=nn;exports.setVersionToLocalStorage=ia;exports.showPrecisionValue=go;