@layoutit/polycss-core 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -5
- package/dist/camera-VU-yix11.d.cts +304 -0
- package/dist/camera-VU-yix11.d.ts +304 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -304
- package/dist/index.d.ts +4 -304
- package/dist/index.js +1 -1
- package/dist/three.cjs +1 -0
- package/dist/three.d.cts +108 -0
- package/dist/three.d.ts +108 -0
- package/dist/three.js +1 -0
- package/package.json +13 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var Gu="cubic";function Rt(e){let n=e.replace("#","");if(n.length===3){let t=parseInt(n[0]+n[0],16),o=parseInt(n[1]+n[1],16),r=parseInt(n[2]+n[2],16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}if(n.length===6){let t=parseInt(n.slice(0,2),16),o=parseInt(n.slice(2,4),16),r=parseInt(n.slice(4,6),16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}return null}function Js(e){let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/i);return n?{rgb:[Number(n[1]),Number(n[2]),Number(n[3])],alpha:n[4]?Number(n[4]):1}:null}function Vn(e){if(!e)return null;let n=e.trim(),t=Rt(n);return t||Js(n)}function zn(e){return Math.max(0,Math.min(255,Math.round(e)))}function yo(e){let[n,t,o]=e.rgb.map(zn);return e.alpha<1?`rgba(${n}, ${t}, ${o}, ${e.alpha})`:`rgb(${n}, ${t}, ${o})`}var Tr={rgb:[204,204,204],alpha:1},ea=new Map;function tt(e){if(!e)return null;let n=e.trim(),t=ea.get(n);if(t)return t;let o=Vn(n);return o?(ea.set(n,o),o):null}function $u(e,n){let t=tt(e)??Tr,o=[zn(t.rgb[0]+n),zn(t.rgb[1]+n),zn(t.rgb[2]+n)];return yo({rgb:o,alpha:t.alpha})}var Cr={direction:[0,0,-1],color:"#ffffff",intensity:1},na={color:"#ffffff",intensity:.4};function ta(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-12?[0,0,0]:[e[0]/n,e[1]/n,e[2]/n]}function oa(e,n,t){let o=tt(n)??Tr;return e*(o.rgb[t]/255)}function Xu(e,n,t,o){let r=tt(n)??Tr,i=ta(t?.direction??Cr.direction),s=t?.color??Cr.color,a=Math.max(0,t?.intensity??Cr.intensity),c=o?.color??na.color,l=Math.max(0,o?.intensity??na.intensity),u=ta(e),f=Math.max(0,-(u[0]*i[0]+u[1]*i[1]+u[2]*i[2])),d=a*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],h=oa(g,c,p)*l,y=oa(g,s,p)*d;m[p]=zn(h+y)}return yo({rgb:m,alpha:r.alpha})}var ra="#cccccc",bo=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],ia=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],sa=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],xo=e=>Math.hypot(e[0],e[1],e[2]);function Yu(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>i&&(i=u[1]),u[2]<o&&(o=u[2]),u[2]>s&&(s=u[2]);let a=r-n,c=i-t,l=s-o;return Math.hypot(a,c,l)}function ju(){let e=globalThis;if(e.__POLYCSS_DEV__===!0)return!0;if(e.__POLYCSS_DEV__===!1)return!1;let n=e.process?.env?.NODE_ENV;return typeof n=="string"?n!=="production":!1}function aa(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function ca(e){return e?{...e}:void 0}function Wu(e){if(e)return{...e,imageSource:aa(e.imageSource),presentation:ca(e.presentation)}}function Er(e){let n=[],t=[];if(!e||e.length===0)return{polygons:n,warnings:t};for(let o=0;o<e.length;o++){let r=e[o];if(!r||!Array.isArray(r.vertices)){t.push(`Polygon ${o}: missing vertices, dropped`);continue}let i=r.vertices;if(i.length<3){t.push(`Polygon ${o}: ${i.length} vertices (need >= 3), dropped`);continue}let s=bo(i[1],i[0]),a=bo(i[2],i[0]),c=ia(s,a),l=xo(c);if(i.length===3){if(l<1e-12){xo(s)<1e-12||xo(a)<1e-12?t.push(`Polygon ${o}: zero-area triangle (coincident vertices), dropped`):t.push(`Polygon ${o}: vertices collinear, dropped`);continue}}else if(l<1e-12){t.push(`Polygon ${o}: first 3 vertices collinear, dropped`);continue}let u=[{...r,vertices:i.slice()}];if(i.length>=4){let f=[c[0]/l,c[1]/l,c[2]/l],d=sa(f,i[0]),m=Yu(i),p=Math.max(1e-6,m*.001),g=0;for(let h=3;h<i.length;h++){let y=Math.abs(sa(f,i[h])-d);y>g&&(g=y)}if(g>p){let h=[],y=r.uvs&&r.uvs.length===i.length?r.uvs:void 0;for(let b=1;b<i.length-1;b++){let x=[i[0].slice(),i[b].slice(),i[b+1].slice()],P=ia(bo(x[1],x[0]),bo(x[2],x[0]));if(xo(P)<1e-12)continue;let M={...r,vertices:x};y&&(M.uvs=[y[0].slice(),y[b].slice(),y[b+1].slice()]),h.push(M)}if(h.length===0){t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulated to ${h.length} triangles`),u=h}}for(let f of u){let d=Hu(f,o,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function Hu(e,n,t){let o={vertices:e.vertices},r=Wu(e.material),i=aa(e.textureImageSource),s=ca(e.texturePresentation),a=r?.texture??e.texture??i?.url??r?.imageSource?.url;if(typeof a=="string"&&a===""&&(a=void 0),e.color!==void 0&&a!==void 0&&ju()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(tt(e.color)?o.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${ra}`),o.color=ra)),a!==void 0&&(o.texture=a,e.textureWrap&&(o.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(o.textureAlphaMode=e.textureAlphaMode)),r&&(o.material=r),i&&(o.textureImageSource=i),s&&(o.texturePresentation=s),Array.isArray(e.textureTriangles)&&e.textureTriangles.length>0&&(o.textureTriangles=e.textureTriangles.map(c=>({vertices:c.vertices.map(l=>l.slice()),uvs:c.uvs.map(l=>l.slice())}))),e.doubleSided===!0&&(o.doubleSided=!0),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?t.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):o.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let c={},l=!1;for(let u of Object.keys(e.data)){let f=e.data[u];typeof f=="string"||typeof f=="number"||typeof f=="boolean"?c[u]=f:(l=!0,t.push(`Polygon ${n}: data["${u}"] has non-primitive value, key dropped`))}Object.keys(c).length>0&&(o.data=c)}return o}function la(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0,a=!1;for(let c of e)if(c?.vertices)for(let l of c.vertices)l&&(a=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>i&&(i=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]));return a?{min:[n,t,o],max:[r,i,s]}:{min:[0,0,0],max:[0,0,0]}}function Ku(e){let n=e.polygons??[],t,o;if(e.skipNormalize)t=n,o=[];else{let a=Er(n);t=a.polygons,o=a.warnings}let r=la(t),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]];return{context:{polygons:t,sceneBbox:r,warnings:o},dimensions:{sceneBbox:r,size:i},warnings:o}}function Zu(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function qu(e){let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],i=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],s=r[1]*i[2]-r[2]*i[1],a=r[2]*i[0]-r[0]*i[2],c=r[0]*i[1]-r[1]*i[0],l=Math.hypot(s,a,c);return l<=1e-9?null:[s/l,a/l,c/l]}function Qu(e){let n=0;for(let t=0;t<e.length;t++){let[o,r]=e[t],[i,s]=e[(t+1)%e.length];n+=o*s-i*r}return Math.abs(n)/2}function Ju(e,n,t){if(!e||e.length<3)return null;let o=e.map(a=>[a[1]*n,a[0]*n,a[2]*t]),r=qu(o);if(!r)return null;let i=1/0,s=0;for(let a=0;a<o.length;a++){let c=o[a],l=o[(a+1)%o.length],u=[l[0]-c[0],l[1]-c[1],l[2]-c[2]],f=u[0]*r[0]+u[1]*r[1]+u[2]*r[2],d=[u[0]-f*r[0],u[1]-f*r[1],u[2]-f*r[2]],m=Math.hypot(d[0],d[1],d[2]);if(m<=1e-9)continue;let p=[d[0]/m,d[1]/m,d[2]/m],g=[r[1]*p[2]-r[2]*p[1],r[2]*p[0]-r[0]*p[2],r[0]*p[1]-r[1]*p[0]],h=Math.hypot(g[0],g[1],g[2]);if(h<=1e-9)continue;let y=[g[0]/h,g[1]/h,g[2]/h],b=o.map(v=>{let R=v[0]-c[0],O=v[1]-c[1],L=v[2]-c[2];return[R*p[0]+O*p[1]+L*p[2],R*y[0]+O*y[1]+L*y[2]]}),x=1/0,P=1/0,M=-1/0,C=-1/0;for(let[v,R]of b)x=Math.min(x,v),P=Math.min(P,R),M=Math.max(M,v),C=Math.max(C,R);let E=M-x,A=C-P,S=Math.max(1,Math.ceil(E))*Math.max(1,Math.ceil(A)),T=Qu(b);T<=1e-9||S<i&&(i=S,s=T)}return!Number.isFinite(i)||s<=1e-9?null:{elementArea:i,polygonArea:s}}function ef(e,n={}){let t=n.tileSize??100,o=n.layerElevation??t,r=n.texturedOnly??!0,i=0,s=0,a=0,c=0,l=0;for(let f of e){let d=!!f.texture;if(r&&!d)continue;let m=Ju(f.vertices,t,o);m&&(i+=1,d&&(s+=1),a+=m.elementArea,c+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,a-c);return{totalPolygons:e.length,measuredPolygons:i,texturedPolygons:s,elementArea:a,polygonArea:c,transparentArea:u,transparentRatio:a>0?u/a:0,overdrawRatio:c>0?a/c:0,worstTransparentRatio:l}}function vr(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function nf(e,n){let t=-n[0]*Math.PI/180,o=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[i,s,a]=e;if(t!==0){let c=Math.cos(t),l=Math.sin(t);[s,a]=[s*c-a*l,s*l+a*c]}if(o!==0){let c=Math.cos(o),l=Math.sin(o);[i,a]=[i*c+a*l,-i*l+a*c]}if(r!==0){let c=Math.cos(r),l=Math.sin(r);[i,s]=[i*c-s*l,i*l+s*c]}return[i,s,a]}function Un(e,n){let[t,o,r]=e,i=-(n[2]??0)*Math.PI/180;if(i!==0){let c=Math.cos(i),l=Math.sin(i);[t,o]=[t*c-o*l,t*l+o*c]}let s=-(n[1]??0)*Math.PI/180;if(s!==0){let c=Math.cos(s),l=Math.sin(s);[o,r]=[o*c-r*l,o*l+r*c]}let a=-(n[0]??0)*Math.PI/180;if(a!==0){let c=Math.cos(a),l=Math.sin(a);[t,r]=[t*c+r*l,-t*l+r*c]}return[t,o,r]}var Ir=Math.PI/180,Lt=180/Math.PI,tf=[1,0,0,0];function of(e,n){let[t,o,r,i]=e,[s,a,c,l]=n;return[t*s-o*a-r*c-i*l,t*a+o*s+r*l-i*c,t*c-o*l+r*s+i*a,t*l+o*c-r*a+i*s]}function rf(e,n){let t=n*.5,o=Math.sin(t);return[Math.cos(t),e[0]*o,e[1]*o,e[2]*o]}function sf(e){let n=e[0]*Ir,t=e[1]*Ir,o=e[2]*Ir,r=Math.cos(n*.5),i=Math.sin(n*.5),s=Math.cos(t*.5),a=Math.sin(t*.5),c=Math.cos(o*.5),l=Math.sin(o*.5);return[r*s*c-i*a*l,i*s*c+r*a*l,r*a*c-i*s*l,r*s*l+i*a*c]}function af(e){let[n,t,o,r]=e,i=2*(t*r+n*o),s=2*(o*r-n*t),a=1-2*(t*t+o*o),c=2*(t*o-n*r),l=1-2*(o*o+r*r),u=Math.max(-1,Math.min(1,i)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-s,a)*Lt,f*Lt,Math.atan2(-c,l)*Lt]:[Math.atan2(2*(o*r+n*t),1-2*(t*t+r*r))*Lt,f*Lt,0]}var Ze=50;function cf(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Oe={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0};function ma(e=Oe.target,n=[0,0,0],t=50){let o=e[0]+n[0],r=e[1]+n[1],i=e[2]+n[2];return[r*t,o*t,i*t]}function lf(e=Oe,n={}){let t=n.tileSize??50,o=n.layoutScale??1,r=e.target??Oe.target,[i,s,a]=ma(r,n.autoCenterOffset,t),c=(e.zoom??Oe.zoom)/t*o,l=(e.distance??Oe.distance)*o,u=e.rotX??Oe.rotX,f=e.rotY??Oe.rotY;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${u}deg) rotate(${f}deg) translate3d(${-i}px, ${-s}px, ${-a}px)`}function da(e="none"){if(e==="none")return"1000000px";let n=Number.parseFloat(e);return Number.isFinite(n)?`${n}px`:e}function uf(e,n={}){let t=n.perspectiveStyle??e.perspectiveStyle??"none",o=n.projection??e.type??(t==="none"?"orthographic":"perspective"),r=e.state??Oe;return{projection:o,perspectiveStyle:t,appliedPerspectiveStyle:da(t),state:{target:[...r.target??Oe.target],rotX:r.rotX??Oe.rotX,rotY:r.rotY??Oe.rotY,zoom:r.zoom??Oe.zoom,distance:r.distance??Oe.distance}}}var ua=100,fa=1e4,ot=e=>Math.round(e*ua)/ua,ff=e=>Math.round(e*fa)/fa;function mf(e={}){let n={target:e.target??[...Oe.target],rotX:e.rotX??Oe.rotX,rotY:e.rotY??Oe.rotY,zoom:e.zoom??Oe.zoom,distance:e.distance??Oe.distance};function t(r){r.target!==void 0&&(n.target=[ot(r.target[0]),ot(r.target[1]),ot(r.target[2])]),r.rotX!==void 0&&(n.rotX=ot(r.rotX)),r.rotY!==void 0&&(n.rotY=ot(r.rotY)),r.zoom!==void 0&&(n.zoom=ff(r.zoom)),r.distance!==void 0&&(n.distance=ot(r.distance))}function o(r={}){let s=(r.cols??0)*50,a=(r.rows??0)*50,[c,l,u]=n.target,f=l*50,d=c*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-d}px, ${-m}px)`,width:`${s}px`,height:`${a}px`}}return{state:n,update:t,getStyle:o}}var pa=Math.PI/180;function ga(e){let{camera:n,tileSize:t,viewportCenterX:o,viewportCenterY:r,mouseX:i,mouseY:s}=e,a=n.rotX*pa,c=n.rotY*pa,l=n.zoom/t,u=n.target,f=i-o,d=s-r,m=f/l,p=d/l,g=Math.cos(a),h=Math.sin(a),y=m,b=p*g,x=-p*h,P=0,M=h,C=g,E=Math.cos(c),A=Math.sin(c),S=y*E+b*A,T=-y*A+b*E,v=x,R=P*E+M*A,O=-P*A+M*E,L=C,D=u[1]*t,_=u[0]*t,w=u[2]*t,V=S+D,j=T+_,G=v+w,Z=[j/t,V/t,G/t],ee=[O/t,R/t,L/t];return{origin:Z,direction:ee}}function df(e){let{origin:n,direction:t}=ga(e),{sphereCenter:o,sphereRadius:r}=e,i=n[0]-o[0],s=n[1]-o[1],a=n[2]-o[2],c=t[0],l=t[1],u=t[2],f=c*c+l*l+u*u;if(f===0)return null;let d=2*(i*c+s*l+a*u),m=i*i+s*s+a*a-r*r,p=d*d-4*f*m;if(p>=0){let E=Math.sqrt(p),A=(-d-E)/(2*f),S=(-d+E)/(2*f),T=t[2]>=0?Math.max(A,S):Math.min(A,S);return[n[0]+T*t[0],n[1]+T*t[1],n[2]+T*t[2]]}let g=-(i*c+s*l+a*u)/f,h=n[0]+g*c,y=n[1]+g*l,b=n[2]+g*u,x=h-o[0],P=y-o[1],M=b-o[2],C=Math.hypot(x,P,M);return C===0?null:[o[0]+x/C*r,o[1]+P/C*r,o[2]+M/C*r]}var On=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Po=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],wt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Or=e=>Math.hypot(e[0],e[1],e[2]),rt=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function pf(e){return`${e[0]},${e[1]},${e[2]}`}function ba(e){if(e.length<3)return null;let n=On(e[1],e[0]),t=On(e[2],e[0]),o=Po(n,t),r=Or(o);if(r<1e-12)return null;let i=[o[0]/r,o[1]/r,o[2]/r],s=wt(i,e[0]);return{normal:i,d:s}}function gf(e,n){return wt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function hf(e,n){return wt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function yf(e,n,t,o){let r=e.vertices.findIndex(A=>rt(A,t)),i=e.vertices.findIndex(A=>rt(A,o)),s=n.vertices.findIndex(A=>rt(A,t)),a=n.vertices.findIndex(A=>rt(A,o));if(r<0||i<0||s<0||a<0)return null;let c=e.vertices.length,l=n.vertices.length,u=(r+1)%c===i,f=(s+1)%l===a;if(u===f)return null;let d=u?i:r,m=u?r:i,p=f?a:s,g=f?s:a,h=!!(e.uvs&&n.uvs),y=[],b=h?[]:void 0,x=d;for(;y.push(e.vertices[x]),b&&b.push(e.uvs[x]),x!==m;)x=(x+1)%c;for(x=p;y.push(n.vertices[x]),b&&b.push(n.uvs[x]),x!==g;)x=(x+1)%l;let P=[],M=b?[]:void 0;for(let A=0;A<y.length;A++)(P.length===0||!rt(y[A],P[P.length-1]))&&(P.push(y[A]),M&&b&&M.push(b[A]));if(P.length>1&&rt(P[0],P[P.length-1])&&(P.pop(),M?.pop()),h)return ya(P,M);let C=[],E=M?[]:void 0;for(let A=0;A<P.length;A++){let S=P[(A-1+P.length)%P.length],T=P[A],v=P[(A+1)%P.length],R=Po(On(T,S),On(v,S));Or(R)>1e-9&&(C.push(T),E&&M&&E.push(M[A]))}return C.length<3?null:ya(C,E)}function bf(e,n){let t=e.length,o=0;for(let r=0;r<t;r++){let i=e[r],s=e[(r+1)%t],a=e[(r+2)%t],c=On(s,i),l=On(a,s),u=wt(Po(c,l),n);if(Math.abs(u)<1e-9)continue;let f=u>0?1:-1;if(o===0)o=f;else if(f!==o)return!1}return!0}function xf(e,n){if(e.length<3)return!1;let t=ba(e);if(!t)return!1;for(let o of e)if(Math.abs(wt(t.normal,o)-t.d)>n)return!1;return!0}function Pf(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function _r(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function Vr(e){return e?{...e}:void 0}function ha(e){if(e)return{...e,imageSource:_r(e.imageSource),presentation:Vr(e.presentation)}}function Mf(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function Sf(e,n){return(e??"")===(n??"")}function Af(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function ya(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length];if(!(Or(Po(On(r,o),On(i,o)))<=1e-9))return t===0?{vertices:e,uvs:n}:{vertices:[...e.slice(t),...e.slice(0,t)],uvs:n?[...n.slice(t),...n.slice(0,t)]:void 0}}return{vertices:e,uvs:n}}function fn(e){let n=[],t=[],o=new WeakMap,r=m=>{let p=o.get(m);if(p)return p;let g=pf(m);return o.set(m,g),g},i=(m,p)=>{let g=r(m),h=r(p);return g<h?`${g}|${h}`:`${h}|${g}`},s=(m,p)=>r(m)<r(p)?1:-1,a=m=>{let p=new Map;for(let g=0;g<m.length;g++){let h=m[g],y=m[(g+1)%m.length];p.set(i(h,y),s(h,y))}return p},c=0,l=!1,u=m=>(c+=m,c<=8e6?!0:(l=!0,!1));for(let m of e??[]){if(!m||!m.vertices||m.vertices.length<3){m&&n.push(m);continue}let p=m.vertices,g=ba(p);if(!g){n.push(m);continue}let h=m.texture&&m.uvs&&m.uvs.length===p.length?m.uvs.map(b=>[b[0],b[1]]):void 0,y=m.texture&&h?m.textureTriangles?.length?Pf(m.textureTriangles):Af(p,h):void 0;t.push({vertices:p,uvs:h,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureImageSource:_r(m.textureImageSource),texturePresentation:Vr(m.texturePresentation),material:ha(m.material),textureTriangles:y,normal:g.normal,d:g.d,edgeDirections:a(p),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let h=0;h<t.length;h++){let y=t[h];if(!y.alive)continue;let b=y.vertices.length;if(!u(b))return!1;for(let x=0;x<b;x++){let P=y.vertices[x],M=y.vertices[(x+1)%b],C=i(P,M),E=m.get(C);E?E.second<0&&(E.second=h):(E={a:P,b:M,first:h,second:-1},m.set(C,E))}}let p=!1,g=(h,y,b)=>{let x=h.edgeDirections.get(i(y,b));return x?x===s(y,b)?1:-1:0};for(let h of m.values()){if(h.second<0)continue;let y=h.first,b=h.second;if(y===b)continue;let x=t[y],P=t[b];if(!x.alive||!P.alive||x.color!==P.color||x.texture!==P.texture||!Mf(x.textureWrap,P.textureWrap)||!Sf(x.textureAlphaMode,P.textureAlphaMode)||x.doubleSided!==P.doubleSided)continue;let M=!!(x.texture||P.texture);if(M&&(!x.textureTriangles||!P.textureTriangles)||!!x.uvs!=!!P.uvs||(M?!hf(x,P):!gf(x,P)))continue;if(!u(x.vertices.length+P.vertices.length))return!1;let C=g(x,h.a,h.b);if(C===0)continue;let E=g(P,h.a,h.b);if(E===0||C===E)continue;let[A,S]=C===1?[h.a,h.b]:[h.b,h.a],T=yf(x,P,A,S);if(T){if(!u(T.vertices.length))return!1;T.vertices.length>96||xf(T.vertices,.001)&&bf(T.vertices,x.normal)&&(x.vertices=T.vertices,x.uvs=T.uvs,x.edgeDirections=a(T.vertices),x.textureTriangles=M?[...x.textureTriangles??[],...P.textureTriangles??[]]:void 0,P.alive=!1,p=!0)}}return p},d=0;for(;!l&&d<16&&f();)d++;for(let m of t){if(!m.alive)continue;let p={vertices:m.vertices.map(g=>[g[0],g[1],g[2]]),color:m.color};m.texture&&(p.texture=m.texture),m.texture&&m.textureWrap&&(p.textureWrap={...m.textureWrap}),m.texture&&m.textureAlphaMode&&(p.textureAlphaMode=m.textureAlphaMode),m.textureImageSource&&(p.textureImageSource=_r(m.textureImageSource)),m.texturePresentation&&(p.texturePresentation=Vr(m.texturePresentation)),m.material&&(p.material=ha(m.material)),m.uvs&&(p.uvs=m.uvs.map(g=>[g[0],g[1]])),m.textureTriangles?.length&&(p.textureTriangles=m.textureTriangles),m.doubleSided&&(p.doubleSided=!0),m.data&&(p.data=m.data),n.push(p)}return n}var Cf=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Tf=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],rn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function Ef(e,n){let t=e.vertices;if(!t||t.length<3)return null;let o=0,r=0,i=0;for(let g=0;g<t.length;g++){let h=t[g],y=t[(g+1)%t.length];o+=(h[1]-y[1])*(h[2]+y[2]),r+=(h[2]-y[2])*(h[0]+y[0]),i+=(h[0]-y[0])*(h[1]+y[1])}let s=Math.hypot(o,r,i);if(s<1e-12)return null;let a=[o/s,r/s,i/s],c=0,l=0,u=0;for(let g of t)c+=g[0],l+=g[1],u+=g[2];let f=1/t.length,d=[c*f,l*f,u*f],m=rn(a,d),p=s*.5;return{index:n,polygon:e,normal:a,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function vf(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&rn(e.normal,n.normal)<0}function If(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*rn(n,e),o=n[1]-e[1]*rn(n,e),r=n[2]-e[2]*rn(n,e),i=Math.hypot(t,o,r);t/=i,o/=i,r/=i;let s=[t,o,r],a=Tf(e,s);return{u:s,v:a}}function _f(e){if(e.local2D)return;let n=If(e.normal),t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.polygon.vertices){let c=rn(a,n.u),l=rn(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}e.local2D=t,e.bbox2D={min:[o,r],max:[i,s]},e.basis=n}function Vf(e,n){let t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.vertices){let c=rn(a,n.u),l=rn(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}return{local2D:t,bbox2D:{min:[o,r],max:[i,s]}}}function Of(e,n){return e.max[0]>=n.min[0]&&e.min[0]<=n.max[0]&&e.max[1]>=n.min[1]&&e.min[1]<=n.max[1]}function xa(e,n){let t=!1;for(let o=0,r=n.length-1;o<n.length;r=o++){let i=n[o],s=n[r];i[1]>e[1]!=s[1]>e[1]&&e[0]<(s[0]-i[0])*(e[1]-i[1])/(s[1]-i[1]+1e-30)+i[0]&&(t=!t)}return t}function Pa(e){let n=0,t=0;for(let o of e)n+=o[0],t+=o[1];return[n/e.length,t/e.length]}function Rf(e,n){let t=Pa(e),o=Pa(n),r=1e-4,i=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];xa(u,n)&&i++}let s=0;for(let l of n){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];xa(u,e)&&s++}let a=i/e.length,c=s/n.length;return Math.max(a,c)}function Lf(e,n){let t=e.normal[0],o=e.normal[1],r=e.normal[2],i=Math.abs(t),s=Math.abs(o),a=Math.abs(r),c=t;s>i&&s>a?c=o:a>i&&a>s&&(c=r),c<0&&(t=-t,o=-o,r=-r);let l=Math.round(t/.05),u=Math.round(o/.05),f=Math.round(r/.05),d=e.d*(e.normal[0]===t&&e.normal[1]===o&&e.normal[2]===r?1:-1),m=Math.round(d/(n*2));return`${l},${u},${f}|${m}`}function wf(e,n,t,o){let r=rn(e.normal,n.normal);if(Math.abs(r)<1-t)return!1;let i=r>0?1:-1;return Math.abs(e.d-i*n.d)<o}function Ma(e,n){let t=Cf(n,e.centroid);return rn(e.normal,t)>0}function Mo(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,o=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,i=n?.preserveDoubleSidedBackfaces??!0,s=[];for(let p=0;p<e.length;p++){let g=Ef(e[p],p);g&&s.push(g)}if(s.length<2)return new Set;let a=0,c=0,l=0,u=0;for(let p of s)a+=p.centroid[0]*p.area,c+=p.centroid[1]*p.area,l+=p.centroid[2]*p.area,u+=p.area;let f=u>0?[a/u,c/u,l/u]:[0,0,0],d=new Map;for(let p of s){let g=Lf(p,o),h=d.get(g);h||(h=[],d.set(g,h)),h.push(p)}let m=new Set;for(let p of d.values())if(!(p.length<2))for(let g=0;g<p.length;g++){let h=p[g];if(!m.has(h.index))for(let y=g+1;y<p.length;y++){let b=p[y];if(m.has(b.index)||!wf(h,b,t,o)||i&&vf(h,b))continue;_f(h);let x=Vf(b.polygon,h.basis);if(!Of(h.bbox2D,x.bbox2D)||Rf(h.local2D,x.local2D)<r)continue;let M=Ma(h,f),C=Ma(b,f),E;if(M&&!C?E=h:C&&!M?E=b:E=h.area<b.area?h:b,m.add(E.index),E===h)break}}return m}function Nf(e,n){if(!e||e.length<2)return e??[];let t=Mo(e,n);if(t.size===0)return e;let o=[];for(let r=0;r<e.length;r++)t.has(r)||o.push(e[r]);return o}var Df=4,Ff=8,Bf=.001,kf=1e-9,zf=1e6,Uf=1e6,Gf=8,Gn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],wr=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Ft=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],$n=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Ta=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],Ea=e=>Math.hypot(e[0],e[1],e[2]);function Bt(e){let n=Ea(e);return n<=kf?null:[e[0]/n,e[1]/n,e[2]/n]}function Dt(e,n){return Math.round(e*n)/n}function sn(e){return Dt(e,zf)}function Rr(e){return Dt(e,Uf)}function Lr(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function Pn(e){return`${sn(e[0])},${sn(e[1])}`}function $f(e){let n=Pn(e.a),t=Pn(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function it(e){return`${e[0]},${e[1]},${e[2]}`}function va(e,n){let t=it(e),o=it(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Nr(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Sa(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",Nr(e.data)].join("|")}function Ia(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],o=[0,0,0];for(let i=1;i<n.length-1;i++)o=wr(o,Ta(Gn(n[i],t),Gn(n[i+1],t)));let r=Bt(o);return r?{normal:r,d:$n(r,t)}:null}function Xf(e,n,t){return $n(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function Yf(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function jf(e,n){let t=n[e[0]]?.data,o=Nr(t);for(let r of e)if(Nr(n[r].data)!==o)return;return t?{...t}:void 0}function Wf(e,n){return e.every(t=>n[t].doubleSided===!0)}function Hf(e,n){let t=e.map(c=>Yf(c)?Ia(c):null),o=t.map(Boolean),r=new Map;for(let c=0;c<e.length;c++){if(!t[c])continue;let l=e[c].vertices;for(let u=0;u<l.length;u++){let f=va(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:c,edge:u};d?d.push(m):r.set(f,[m])}}let i=e.map(()=>new Set);for(let c of r.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l].polygon,d=c[u].polygon,m=t[f],p=t[d];!m||!p||Sa(e[f])===Sa(e[d])&&Xf(m,p,n)&&(i[f].add(d),i[d].add(f))}let s=new Set,a=[];for(let c=0;c<e.length;c++){if(!o[c]||s.has(c))continue;let l=[],u=[c];for(s.add(c);u.length>0;){let f=u.shift();l.push(f);for(let d of i[f])s.has(d)||(s.add(d),u.push(d))}a.push(l)}return{groups:a}}function Kf(e,n){let t=new Set(e),o=new Map;for(let i of e){let s=n[i].vertices;for(let a=0;a<s.length;a++){let c=va(s[a],s[(a+1)%s.length]),l=o.get(c),u={polygon:i,edge:a};l?l.push(u):o.set(c,[u])}}let r=[];for(let i of o.values()){let s=i.filter(a=>t.has(a.polygon));if(s.length===1){let a=s[0],c=n[a.polygon].vertices;r.push({a:c[a.edge],b:c[(a.edge+1)%c.length]})}else if(s.length!==2)return null}return r}function Zf(e){let n=new Map;for(let t of e)n.set(it(t.a),(n.get(it(t.a))??0)+1),n.set(it(t.b),(n.get(it(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function _a(e){let n=[e[0],e[1],e[2]],t=Math.abs(n[0])>=Math.abs(n[1])&&Math.abs(n[0])>=Math.abs(n[2])?0:Math.abs(n[1])>=Math.abs(n[2])?1:2;return n[t]<0?[-n[0],-n[1],-n[2]]:n}function qf(e){let n=_a(e);return`${Dt(n[0],1e3)},${Dt(n[1],1e3)},${Dt(n[2],1e3)}`}function Qf(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=Gn(n,Ft(e,$n(n,e)));return Bt(t)??[1,0,0]}function Jf(e,n,t){let o=new Map;for(let i of e){let s=Gn(i.b,i.a),a=Gn(s,Ft(n,$n(s,n))),c=Bt(a);if(!c)continue;let l=_a(c),u=qf(l),f=Ea(a),d=o.get(u);d?d.weight+=f:o.set(u,{axis:l,weight:f})}let r=[...o.values()].sort((i,s)=>s.weight-i.weight).slice(0,t).map(i=>i.axis);return r.length===0&&r.push(Qf(n)),r}function Aa(e,n,t,o){let r=Gn(e,n);return[sn($n(r,t)),sn($n(r,o))]}function em(e){let n=[...e].sort((o,r)=>o-r),t=[];for(let o of n)(t.length===0||Math.abs(o-t[t.length-1])>1e-7)&&t.push(o);return t}function Nt(e,n){let[t,o]=e.a,[r,i]=e.b,s=(n-t)/(r-t);return sn(o+(i-o)*s)}function Dr(e){let n=[];for(let o of e)(n.length===0||Math.abs(o[0]-n[n.length-1][0])>1e-7||Math.abs(o[1]-n[n.length-1][1])>1e-7)&&n.push(o);n.length>1&&Math.abs(n[0][0]-n[n.length-1][0])<=1e-7&&Math.abs(n[0][1]-n[n.length-1][1])<=1e-7&&n.pop();let t=[];for(let o=0;o<n.length;o++){let r=n[(o-1+n.length)%n.length],i=n[o],s=n[(o+1)%n.length],a=(i[0]-r[0])*(s[1]-i[1])-(i[1]-r[1])*(s[0]-i[0]);Math.abs(a)>1e-8&&t.push(i)}return t}function Ao(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-r[0]*o[1]}return n/2}function Co(e){let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let[i,s]of e)n=Math.min(n,i),t=Math.min(t,s),o=Math.max(o,i),r=Math.max(r,s);return{minX:n,minY:t,maxX:o,maxY:r}}function Va(e,n){return!(e.maxX<n.minX-1e-7||n.maxX<e.minX-1e-7||e.maxY<n.minY-1e-7||n.maxY<e.minY-1e-7)}function So(e){return Math.abs(Ao(e))}function nm(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-8)continue;let a=s>0?1:-1;if(n===0)n=a;else if(n!==a)return!1}return!0}function tm(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=e[0]-n[0],s=e[1]-n[1],a=o*s-r*i,c=Math.hypot(o,r);if(c<=1e-9||Math.abs(a)>Math.max(1e-8,c*1e-8))return!1;let l=i*o+s*r;return l>=-1e-8&&l<=o*o+r*r+1e-8}function om(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=o*o+r*r;return i<=1e-12?0:((e[0]-n[0])*o+(e[1]-n[1])*r)/i}function rm(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=Math.hypot(r,i),l=Math.hypot(s,a);if(c<=1e-9||l<=1e-9)return!1;let u=r*(t[1]-e[1])-i*(t[0]-e[0]),f=r*(o[1]-e[1])-i*(o[0]-e[0]),d=r*a-i*s,m=Math.max(1e-8,Math.max(c,l)*1e-8);if(Math.abs(u)>m||Math.abs(f)>m||Math.abs(d)>m)return!1;let p=Math.abs(r)>=Math.abs(i),g=Math.min(p?e[0]:e[1],p?n[0]:n[1]),h=Math.max(p?e[0]:e[1],p?n[0]:n[1]),y=Math.min(p?t[0]:t[1],p?o[0]:o[1]),b=Math.max(p?t[0]:t[1],p?o[0]:o[1]);return Math.min(h,b)-Math.max(g,y)>1e-8}function im(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];for(let i=0;i<n.length;i++)if(rm(o,r,n[i],n[(i+1)%n.length]))return!0}return!1}function Ca(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=[{t:0,point:r},{t:1,point:i}];for(let c of n)Lr(c,r)||Lr(c,i)||tm(c,r,i)&&s.push({t:om(c,r,i),point:c});s.sort((c,l)=>c.t-l.t);let a=[];for(let c of s)a.some(l=>Math.abs(l.t-c.t)<=1e-8||Lr(l.point,c.point))||a.push(c);for(let c=0;c<a.length-1;c++){let l=a[c].point,u=a[c+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||t.push({a:[sn(l[0]),sn(l[1])],b:[sn(u[0]),sn(u[1])]})}}return t}function sm(e,n,t=Co(e),o=Co(n)){if(!Va(t,o)||!im(e,n))return null;let r=[...Ca(e,n),...Ca(n,e)],i=new Map;for(let y of r){let b=$f(y),x=i.get(b);x?x.push(y):i.set(b,[y])}let s=!1,a=[];for(let y of i.values()){if(y.length===1){a.push(y[0]);continue}s=!0;let b=y.filter(P=>Pn(P.a)<Pn(P.b)).length,x=y.length-b;if(b!==x)return null}if(!s||a.length<3)return null;let c=new Map;for(let y of a){let b=Pn(y.a);if(c.has(b))return null;c.set(b,y)}let l=a[0],u=Pn(l.a),f=[],d=new Set,m=u;for(let y=0;y<=a.length;y++){let b=c.get(m);if(!b)return null;let x=`${Pn(b.a)}>${Pn(b.b)}`;if(d.has(x))return null;if(d.add(x),f.push(b.a),m=Pn(b.b),m===u)break}if(m!==u||d.size!==a.length)return null;let p=Dr(f);if(p.length<3||!nm(p))return null;let g=So(p),h=So(e)+So(n);return Math.abs(g-h)>Math.max(1e-5,h*1e-5)?null:Ao(p)>=0?p:[...p].reverse()}function am(e){let n=e.map(Dr).filter(r=>r.length>=3&&So(r)>1e-8),t=n.map(Co),o=!0;for(;o;){o=!1;for(let r=0;r<n.length;r++){for(let i=r+1;i<n.length;i++){if(!Va(t[r],t[i]))continue;let s=sm(n[r],n[i],t[r],t[i]);if(s){n[r]=s,t[r]=Co(s),n.splice(i,1),t.splice(i,1),o=!0;break}}if(o)break}}return n}function cm(e,n,t){let o=new Map;return r=>{let i=sn(r[0]),s=sn(r[1]),a=`${i},${s}`,c=o.get(a);if(c)return[c[0],c[1],c[2]];let l=wr(e,wr(Ft(n,i),Ft(t,s))),u=[Rr(l[0]),Rr(l[1]),Rr(l[2])];return o.set(a,u),[u[0],u[1],u[2]]}}function lm(e,n,t,o,r){let i=t[0]?.a;if(!i)return null;let s=Bt(Gn(r,Ft(o,$n(r,o))));if(!s)return null;let a=Bt(Ta(o,s));if(!a)return null;let c=[],l=[];for(let y of t){let b=Aa(y.a,i,s,a),x=Aa(y.b,i,s,a);Math.hypot(b[0]-x[0],b[1]-x[1])<=1e-7||(c.push({a:b,b:x}),l.push(b[0],x[0]))}let u=em(l);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,d=jf(e,n),m=Wf(e,n),p=[];for(let y=0;y<u.length-1;y++){let b=u[y],x=u[y+1];if(x-b<=1e-7)continue;let P=(b+x)/2,M=c.filter(C=>{let E=Math.min(C.a[0],C.b[0]),A=Math.max(C.a[0],C.b[0]);return E<P&&P<A&&Math.abs(C.a[0]-C.b[0])>1e-7}).map(C=>({segment:C,yMid:Nt(C,P)})).sort((C,E)=>C.yMid-E.yMid);if(M.length!==0){if(M.length%2!==0)return null;for(let C=0;C<M.length;C+=2){let E=M[C].segment,A=M[C+1].segment,S=Nt(E,b),T=Nt(E,x),v=Nt(A,b),R=Nt(A,x),O=Dr([[b,S],[x,T],[x,R],[b,v]]);if(O.length<3||Math.abs(Ao(O))<=1e-8)continue;let L=Ao(O)>0?O:[...O].reverse();p.push(L)}}}if(p.length===0||e.length>2&&p.length>e.length*Gf)return null;let g=cm(i,s,a),h=am(p).map(y=>({vertices:y.map(g),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return fn(h)}function um(e,n,t){let o=Kf(e,n);if(!o||o.length<3||!Zf(o))return null;let r=Ia(n[e[0]]);if(!r)return null;let i=null;for(let s of Jf(o,r.normal,t)){let a=lm(e,n,o,r.normal,s);a&&(!i||a.length<i.length)&&(i=a)}return!i||i.length>=e.length?null:i}function Fr(e,n={}){let t=n.minGroupPolygons??Df,o=n.maxCandidateAxes??Ff,r=n.planeEpsilon??Bf,i=e??[];if(i.length<t)return i;let{groups:s}=Hf(i,r);if(s.length===0)return i;let a=new Map,c=new Set;for(let u of s){if(u.length<t)continue;let f=um(u,i,o);if(f){a.set(u[0],f);for(let d of u)c.add(d)}}if(a.size===0)return i;let l=[];for(let u=0;u<i.length;u++){let f=a.get(u);if(f){l.push(...f);continue}c.has(u)||l.push(i[u])}return l}function fm(e,n){let t=`${e[0]},${e[1]},${e[2]}`,o=`${n[0]},${n[1]},${n[2]}`;return t<o?`${t}|${o}`:`${o}|${t}`}function mm(e){if(e.length<100)return!1;let n=new Map;for(let o of e){let r=o.vertices;for(let i=0;i<r.length;i++){let s=fm(r[i],r[(i+1)%r.length]);n.set(s,(n.get(s)??0)+1)}}let t=0;for(let o of n.values())o===1&&(t+=1);return t>=128&&t/Math.max(1,n.size)>.2}function dm(e,n,t){let o=Math.abs(e)>.9?0:1,r=Math.abs(e)>.9?1:0,i=r*t,s=-o*t,a=o*n-r*e,c=Math.hypot(i,s,a);return i/=c,s/=c,a/=c,{ux:i,uy:s,uz:a,vx:n*a-t*s,vy:t*i-e*a,vz:e*s-n*i}}function pm(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[j,G,Z]of n)t+=j,o+=G,r+=Z;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=dm(g,h,y),S=n.length-2,T=new Float64Array(S*9),v=0;for(let j=1;j<n.length-1;j++){let G=n[0],Z=n[j],ee=n[j+1];T[v++]=G[0],T[v++]=G[1],T[v++]=G[2],T[v++]=Z[0],T[v++]=Z[1],T[v++]=Z[2],T[v++]=ee[0],T[v++]=ee[1],T[v++]=ee[2]}let R=0,O=1/0,L=1/0,D=1/0,_=-1/0,w=-1/0,V=-1/0;for(let[j,G,Z]of n){let ee=j-t,W=G-o,ie=Z-r,z=ee*ee+W*W+ie*ie;z>R&&(R=z),j<O&&(O=j),j>_&&(_=j),G<L&&(L=G),G>w&&(w=G),Z<D&&(D=Z),Z>V&&(V=Z)}return{centroid:[t,o,r],normal:[g,h,y],vertices:n,triFlat:T,bcx:t,bcy:o,bcz:r,br2:R,ux:x,uy:P,uz:M,vx:C,vy:E,vz:A,minX:O,minY:L,minZ:D,maxX:_,maxY:w,maxZ:V}}function gm(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function hm(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(gm(e,n,t,o,r,i,p,h))return!0;return!1}var kt=9,ym=6,He=8;function Br(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function bm(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*kt),l=0,u=new Float64Array(He),f=new Float64Array(He),d=new Float64Array(He),m=new Float64Array(He),p=new Float64Array(He),g=new Float64Array(He),h=new Int32Array(He),y=new Float64Array(He-1),b=new Int32Array(He-1),x=new Float64Array(He-1),P=new Int32Array(He-1);function M(C,E){let A=l++,S=A*kt,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=ym)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=Br(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ae=He/le;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),g.fill(-1/0),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ae|0;oe>=He&&(oe=He-1);let de=e[o[K]];de.minX<u[oe]&&(u[oe]=de.minX),de.maxX>m[oe]&&(m[oe]=de.maxX),de.minY<f[oe]&&(f[oe]=de.minY),de.maxY>p[oe]&&(p[oe]=de.maxY),de.minZ<d[oe]&&(d[oe]=de.minZ),de.maxZ>g[oe]&&(g[oe]=de.maxZ),h[oe]++}let _e=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<He-1;K++)u[K]<_e&&(_e=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=Br(_e,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=He-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=Br(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<He-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ae)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*kt+7]=ae,c[A*kt+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function kr(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*kt,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&hm(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function xm(e){let n=Oa.get(e);if(n)return n;let t=(1+Math.sqrt(5))/2,o=new Float64Array(e*3);for(let r=0;r<e;r++){let i=(r+.5)/e,s=Math.sqrt(Math.max(0,1-i*i)),a=2*Math.PI*(r/t);o[r*3]=s*Math.cos(a),o[r*3+1]=s*Math.sin(a),o[r*3+2]=i}return Oa.set(e,o),o}var Oa=new Map;function Mn(e,n){let t=n?.samples??8;if(e.length<4||t<1||!n?.force&&mm(e))return e;let o=Math.max(1,Math.ceil(t*(n?.minEscapeRatio??1/t))),r=e.map(pm),i=xm(t),s=[],a=bm(r),c=new Int32Array(Math.max(64,a.nodeCount)),l=192,u=new Float64Array(l);for(let f=0;f<e.length;f++){let d=r[f];if(!d){s.push(e[f]);continue}let m=d.normal[0],p=d.normal[1],g=d.normal[2],h=.001*m,y=.001*p,b=.001*g;{let D=d.centroid[0]+h,_=d.centroid[1]+y,w=d.centroid[2]+b;if(!kr(D,_,w,m,p,g,f,a,c)){s.push(e[f]);continue}}let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=d,S=d.centroid[0],T=d.centroid[1],v=d.centroid[2],R=d.vertices,O=R.length,L=0;u[L++]=S+h,u[L++]=T+y,u[L++]=v+b;for(let D=0;D<O;D++){let _=R[D];u[L++]=_[0]+(S-_[0])*.08+h,u[L++]=_[1]+(T-_[1])*.08+y,u[L++]=_[2]+(v-_[2])*.08+b}for(let D=0;D<O;D++){let _=R[D],w=R[(D+1)%O],V=(_[0]+w[0])*.5,j=(_[1]+w[1])*.5,G=(_[2]+w[2])*.5;u[L++]=V+(S-V)*.08+h,u[L++]=j+(T-j)*.08+y,u[L++]=G+(v-G)*.08+b}if(o<=1){let D=!1;e:for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!kr(ie,z,X,G,Z,ee,f,a,c)){D=!0;break e}}}D&&s.push(e[f])}else{let D=0;for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!kr(ie,z,X,G,Z,ee,f,a,c)){D++;break}}}D>=o&&s.push(e[f])}}return s}var Ba={overlapPx:1.25,maxGapPx:14,capacityScale:1},ka={budget:40};function Xn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function st(e){return typeof e=="number"?{overlapPx:Math.max(0,e)*.175,maxGapPx:14,capacityScale:1}:{overlapPx:Math.max(0,Xn(e?.overlapPx,1.25)),maxGapPx:Math.max(0,Xn(e?.maxGapPx,14)),capacityScale:Math.max(0,Xn(e?.capacityScale,1))}}function at(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function za(e){return{rotX:Xn(e?.rotX,65),rotY:Xn(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(Xn(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(Xn(e?.budget,40))))}}function Sn(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function Ua(e){return[e[1]/50,e[0]/50,e[2]/50]}function Vo(e){return`${e[0]},${e[1]},${e[2]}`}function Pm(e,n){let t=Vo(e),o=Vo(n);return t<o?`${t}|${o}`:`${o}|${t}`}function An(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function ct(e){return Math.hypot(e[0],e[1],e[2])}function $t(e){let n=ct(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function Gt(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function To(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function Xr(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Mm(e){if(e.length<3)return null;let n=e[0],t=[0,0,0];for(let o=1;o+1<e.length;o+=1){let r=An(e[o],n),i=An(e[o+1],n),s=Xr(r,i);t[0]-=s[0],t[1]-=s[1],t[2]-=s[2]}return $t(t)}function Yr(e){let n=e[0],t=Mm(e);if(!t)return null;let o=null;for(let u=0;u<e.length;u+=1){let f=An(e[(u+1)%e.length],e[u]);if(ct(f)>1e-6){o=f;break}}if(!o)return null;let r=Gt(o,t),i=[o[0]-r*t[0],o[1]-r*t[1],o[2]-r*t[2]],s=$t(i);if(!s)return null;let a=$t(Xr(t,s));if(!a)return null;let c=e.map(u=>{let f=An(u,n);return[Gt(f,s),Gt(f,a)]}),l=Oo(c);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:s,yAxis:a,local:c,area:l}:null}function Oo(e){let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function jr(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-6)continue;let a=Math.sign(s);if(n===0)n=a;else if(a!==n)return!1}return!0}function Ga(e,n,t){let o=e[t],r=e[(t+1)%e.length],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return null;let c=n>0?1:-1;return[c*(s/a),c*(-i/a)]}function Sm(e,n){let t=Ga(e.local,e.area,n);return t?$t([e.xAxis[0]*t[0]+e.yAxis[0]*t[1],e.xAxis[1]*t[0]+e.yAxis[1]*t[1],e.xAxis[2]*t[0]+e.yAxis[2]*t[1]]):null}function $a(e,n){let t=e.length,o=e[n],r=e[(n+1)%t],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return 0;let c=[a*.24],l=1/0;for(let f=0;f<t;f+=1){if(f===n||f===(n+1)%t)continue;let d=e[f],m=Math.abs((d[0]-o[0])*s-(d[1]-o[1])*i)/a;m>1e-6&&(l=Math.min(l,m))}Number.isFinite(l)&&c.push(l*.32);let u=[{origin:o,point:e[(n+t-1)%t]},{origin:r,point:e[(n+2)%t]}];for(let f of u){let d=f.point[0]-f.origin[0],m=f.point[1]-f.origin[1],p=Math.hypot(d,m);if(p<=1e-6)continue;let g=Math.abs(i*m-s*d)/(a*p);g>1e-6&&c.push(p*g*.32)}return Math.min(...c)}function Xa(e){return e.map(n=>{let t=Sn(n.vertices),o=Yr(t),r=!Wr(n)&&!!o&&jr(o.local),i=r?o.local.map((s,a)=>$a(o.local,a)):[];return{basis:o,cssPoints:t,capacities:i,patchable:r}})}function Wr(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Am(e){return e.material?.key??e.color??""}function Ya(e,n,t){let o=[];for(let r=0;r<n.length;r+=1){let i=n[r];if(!(!i.patchable||!i.basis))for(let s=0;s<i.cssPoints.length;s+=1){let a=i.cssPoints[s],c=i.cssPoints[(s+1)%i.cssPoints.length],l=An(c,a),u=ct(l),f=$t(l),d=Sm(i.basis,s),m=(i.capacities[s]??0)*t;!f||!d||m<=1e-6||u<=1e-6||o.push({index:o.length,polygon:r,edge:s,key:Pm(a,c),a,b:c,minX:Math.min(a[0],c[0]),minY:Math.min(a[1],c[1]),minZ:Math.min(a[2],c[2]),maxX:Math.max(a[0],c[0]),maxY:Math.max(a[1],c[1]),maxZ:Math.max(a[2],c[2]),length:u,dir:f,normal:i.basis.normal,outward:d,capacity:m,materialKey:Am(e[r]),color:e[r].color})}}return o}function Hr(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function Eo(e,n){return ct(An(e,n))<=1e-4}function Cm(e,n){return Eo(e.a,n.a)||Eo(e.a,n.b)||Eo(e.b,n.a)||Eo(e.b,n.b)}function Tm(e,n){return Hr(e,n)?Cm(e,n)?"connected-facet":"true-gap":"material-boundary"}function zr(e,n,t,o,r,i){return{kind:e,aPolygon:n.polygon,aEdge:n.edge,bPolygon:t.polygon,bEdge:t.edge,aColor:n.color,bColor:t.color,aMaterialKey:n.materialKey,bMaterialKey:t.materialKey,gapPx:o.gap,spanPx:o.aEnd-o.aStart,aStartPx:o.aStart,aEndPx:o.aEnd,bStartPx:o.bStart,bEndPx:o.bEnd,targetClosurePx:r,appliedClosurePx:i,residualGapPx:Math.max(0,o.gap-i),residualTargetPx:Math.max(0,r-i)}}function Ra(e,n,t,o,r){let i=Math.max(0,Math.min(n.length,Math.min(t,o))),s=Math.max(0,Math.min(n.length,Math.max(t,o)));if(r<=1e-6||s-i<=1e-6)return;let a=e[n.polygon].get(n.edge),c={start:i,end:s,amount:r};a?a.push(c):e[n.polygon].set(n.edge,[c])}function Ro(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function Em(e,n){let t=0,o=0,r=0;for(let i of e){i.size>0&&(r+=1),o+=i.size;for(let s of i.values())for(let a of s)t=Math.max(t,a.amount)}return{...n,patchedPolygons:r,patchedEdges:o,maxAppliedAmountPx:t}}function Lo(e,n,t=!1,o=!1){let r=Xa(e),i=Ya(e,r,n.capacityScale),s=o?[]:e.map(()=>new Map),a=Ro(),c=t?[]:void 0;if(i.length===0)return{edgeRepairs:s,diagnostics:a,candidates:c};let l=new Map;for(let u of i){let f=l.get(u.key);f?f.push(u):l.set(u.key,[u])}for(let u of l.values())u.length<2||(a.exactPairs+=u.length===2?1:u.length);return vm(i,l,s,a,n,c),{edgeRepairs:s,diagnostics:o?a:Em(s,a),candidates:c}}function vm(e,n,t,o,r,i){let s=r.maxGapPx,a=new Set;for(let[m,p]of n)p.length>1&&a.add(m);let c=(m,p)=>{let g=m.index<p.index?m:p,h=m.index<p.index?p:m;if(h.polygon===g.polygon||g.key===h.key&&a.has(g.key)||!i&&!Hr(g,h)||!Im(g,h,s)||Math.abs(Gt(g.dir,h.dir))<.985)return;let y=Rm(g,h,s);if(!y)return;let b=Tm(g,h),x=y.gap+r.overlapPx;if(b==="material-boundary"){i?.push(zr(b,g,h,y,x,0));return}let P=x;if(P<=.25){i?.push(zr(b,g,h,y,x,0));return}let M=g.capacity*y.facingA,C=h.capacity*y.facingB,E=Math.min(M,P/2),A=Math.min(C,P/2);if(P-=E+A,P>1e-6){let S=Math.min(M-E,P);E+=S,P-=S}if(P>1e-6){let S=Math.min(C-A,P);A+=S,P-=S}i?.push(zr(b,g,h,y,x,E+A)),t.length>0&&E>1e-6&&Ra(t,g,y.aStart,y.aEnd,E/y.facingA),t.length>0&&A>1e-6&&Ra(t,h,y.bStart,y.bEnd,A/y.facingB),o.nearPairs+=1,o.maxMeasuredGapPx=Math.max(o.maxMeasuredGapPx,y.gap),P>.25&&(o.unclosedPairs+=1,o.maxResidualGapPx=Math.max(o.maxResidualGapPx,P))},l=Math.max(28,s*2);if(e.length<=1e4){let m=[...e].sort((h,y)=>h.minX-y.minX),p=new Int32Array(m.length),g=0;for(let h=0;h+1<m.length;h+=1){let b=m[h].maxX+s,x=h+1;for(;x<m.length&&m[x].minX<=b;)x+=1;if(p[h]=x,g+=x-h-1,g>25e6)break}if(g<=2e6||g<=25e6&&Om(e,l,s)){for(let h=0;h+1<m.length;h+=1)for(let y=h+1;y<p[h];y+=1)c(m[h],m[y]);return}}let u=new Map;for(let m of e)_m(u,m,l,s);let f=new Set,d=e.length;for(let m of u.values())for(let p=0;p+1<m.length;p+=1)for(let g=p+1;g<m.length;g+=1){let h=m[p],y=m[g],b=h.index<y.index?h:y,x=h.index<y.index?y:h,P=b.index*d+x.index;f.has(P)||(f.add(P),c(b,x))}}function Im(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function La(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function _m(e,n,t,o){let[r,i,s,a,c,l]=ja(n,t,o);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function ja(e,n,t){let[o,r,i]=La([e.minX-t,e.minY-t,e.minZ-t],n),[s,a,c]=La([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[o,r,i,s,a,c]}function Vm(e,n,t){let[o,r,i,s,a,c]=ja(e,n,t);return(s-o+1)*(a-r+1)*(c-i+1)}function Om(e,n,t){let o=0,r=0;for(let i of e){let s=Vm(i,n,t);if(o+=s,s>r&&(r=s),r>8192)return!0}return o/Math.max(1,e.length)>256}function wa(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function Na(e,n,t){return(e.a[0]+e.dir[0]*n-t.a[0])*t.dir[0]+(e.a[1]+e.dir[1]*n-t.a[1])*t.dir[1]+(e.a[2]+e.dir[2]*n-t.a[2])*t.dir[2]}function Rm(e,n,t){let o=wa(n.a,e.a,e.dir),r=wa(n.b,e.a,e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i,c=Math.min(e.length,n.length);if(a<Math.max(.75,c*.12))return null;let l=(i+s)/2,u=e.a[0]+e.dir[0]*l,f=e.a[1]+e.dir[1]*l,d=e.a[2]+e.dir[2]*l,m=Math.max(0,Math.min(n.length,(u-n.a[0])*n.dir[0]+(f-n.a[1])*n.dir[1]+(d-n.a[2])*n.dir[2])),p=n.a[0]+n.dir[0]*m-u,g=n.a[1]+n.dir[1]*m-f,h=n.a[2]+n.dir[2]*m-d,y=Math.hypot(p,g,h);if(y<=1e-6||y>t||y>Math.min(t,Math.max(4,c*.28)))return null;let b=1/y,x=p*b,P=g*b,M=h*b,C=e.outward[0]*x+e.outward[1]*P+e.outward[2]*M,E=-(n.outward[0]*x+n.outward[1]*P+n.outward[2]*M);if(C<.5||E<.5)return null;let A=Math.max(0,Math.min(n.length,Na(e,i,n))),S=Math.max(0,Math.min(n.length,Na(e,s,n)));return{gap:y,facingA:C,facingB:E,aStart:i,aEnd:s,bStart:Math.min(A,S),bEnd:Math.max(A,S)}}function Ur(e,n,t,o){let r=t<=1e-6?0:Math.max(0,Math.min(1,o/t));return[e[0]+(n[0]-e[0])*r,e[1]+(n[1]-e[1])*r]}function zt(e,n){let t=e[e.length-1];t&&Math.hypot(t[0]-n[0],t[1]-n[1])<=1e-6||e.push(n)}function Lm(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let o=new Set([0,n]);for(let s of e){let a=Math.max(0,Math.min(n,s.start)),c=Math.max(0,Math.min(n,s.end));c-a<=1e-6||s.amount<=1e-6||(o.add(a),o.add(c))}let r=Array.from(o).sort((s,a)=>s-a),i=[];for(let s=0;s+1<r.length;s+=1){let a=r[s],c=r[s+1];if(c-a<=1e-6)continue;let l=(a+c)/2,u=0;for(let d of e)l+1e-6<d.start||l-1e-6>d.end||(u=Math.max(u,d.amount));let f=Math.min(t,u);f>1e-6&&i.push({start:a,end:c,amount:f})}return i}function wm(e,n){if(n.length<3||!jr(n))return!1;let t=Oo(e),o=Oo(n);return Math.sign(o)===Math.sign(t)&&Math.abs(o)>=Math.abs(t)-1e-6}function Nm(e,n,t){if(n.size===0||e.vertices.length<3||Wr(e))return e;let o=Sn(e.vertices),r=Yr(o);if(!r||!jr(r.local))return e;let i=[];for(let l=0;l<r.local.length;l+=1){let u=r.local[l],f=r.local[(l+1)%r.local.length],d=Math.hypot(f[0]-u[0],f[1]-u[1]),m=Ga(r.local,r.area,l);if(!m||d<=1e-6)return e;let p=Lm(n.get(l),d,$a(r.local,l)*t);zt(i,u);let g=0;for(let h of p){h.start>g+1e-6&&zt(i,Ur(u,f,d,h.start));let y=Ur(u,f,d,h.start),b=Ur(u,f,d,h.end);zt(i,[y[0]+m[0]*h.amount,y[1]+m[1]*h.amount]),zt(i,[b[0]+m[0]*h.amount,b[1]+m[1]*h.amount]),h.end<d-1e-6&&zt(i,b),g=h.end}}let s=i[0],a=i[i.length-1];if(s&&a&&Math.hypot(s[0]-a[0],s[1]-a[1])<=1e-6&&i.pop(),!wm(r.local,i))return e;let c=i.map(([l,u])=>Ua([r.origin[0]+l*r.xAxis[0]+u*r.yAxis[0],r.origin[1]+l*r.xAxis[1]+u*r.yAxis[1],r.origin[2]+l*r.xAxis[2]+u*r.yAxis[2]]));return{...e,vertices:c}}function Wa(e){return e.vertices.length===4&&!Wr(e)}function Dm(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let[c,l]of n)t=Math.min(t,c),o=Math.min(o,l),r=Math.max(r,c),i=Math.max(i,l);let s=Math.max(1e-6,(r-t)*(i-o));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/s)))*2.5}function Gr(e,n){return ct(An(Sn([e])[0],Sn([n])[0]))}function vo(e,n,t){let o=Gr(e,n),r=Gr(n,t),i=Gr(t,e),s=Math.max(o,r,i);return s<=1e-6?0:ct(Xr(An(Sn([n])[0],Sn([e])[0]),An(Sn([t])[0],Sn([e])[0])))*.5/(s*s)}function Fm(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=r*a-i*s;if(Math.abs(c)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*s)/c;return[e[0]+f*r,e[1]+f*i]}function Bm(e,n){if(e.length<3||e.length!==n.length)return null;let t=Math.max(0,...n);if(t<=1e-6)return e;let o=Oo(e);if(Math.abs(o)<=1e-6)return null;let r=o>0?1:-1,i=[];for(let c=0;c<e.length;c+=1){let l=e[c],u=e[(c+1)%e.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=1e-6)return null;let p=Math.max(0,n[c]),g=r*(d/m)*p,h=r*(-f/m)*p;i.push({a:[l[0]+g,l[1]+h],b:[u[0]+g,u[1]+h]})}let s=[],a=Math.max(2,t*4);for(let c=0;c<e.length;c+=1){let l=i[(c+e.length-1)%e.length],u=i[c],f=Fm(l.a,l.b,u.a,u.b);if(!f)return null;let d=e[c],m=f[0]-d[0],p=f[1]-d[1],g=Math.hypot(m,p);s.push(g>a?[d[0]+m/g*a,d[1]+p/g*a]:f)}return s}function km(e,n){return[e.origin[0]+e.xAxis[0]*n[0]+e.yAxis[0]*n[1],e.origin[1]+e.xAxis[1]*n[0]+e.yAxis[1]*n[1],e.origin[2]+e.xAxis[2]*n[0]+e.yAxis[2]*n[1]]}function Io(e,n){let t=Yr(Sn(e));if(!t)return e;let o=Bm(t.local,n);return o?o.map(r=>Ua(km(t,r))):e}function zm(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[o,r,i,s]=e.vertices,a=Math.min(vo(o,r,i),vo(o,i,s)),c=Math.min(vo(o,r,s),vo(r,i,s)),l=u=>n.has(u)?.75:0;return a>=c?[{...t,vertices:Io([o,r,i],[l(0),l(1),1.25])},{...t,vertices:Io([o,i,s],[1.25,l(2),l(3)])}]:[{...t,vertices:Io([o,r,s],[l(0),1.25,l(3)])},{...t,vertices:Io([r,i,s],[l(1),l(2),1.25])}]}function Da(e){if(e.length===0)return{q1:1/0,median:1/0,q3:1/0,p70:1/0,p80:1/0,p88:1/0,p95:1/0,p97:1/0,max:1/0};let n=[...e].sort((o,r)=>o-r),t=o=>n[Math.min(n.length-1,Math.floor((n.length-1)*o))]??0;return{q1:t(.25),median:t(.5),q3:t(.75),p70:t(.7),p80:t(.8),p88:t(.88),p95:t(.95),p97:t(.97),max:n[n.length-1]??0}}function _o(e,n){let t=e[n];if(t===n)return n;let o=_o(e,t);return e[n]=o,o}function Um(e){let n=new Set,t=new Set;for(let o of e)o.sel&&t.add(o.comp);for(let o of e)if(t.has(o.comp))for(let r of o.e)n.add(r);return{endpoints:n}}function Gm(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function $m(e,n,t,o){let r=[];for(let[c,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!Hr(u,f))continue;let d=l.filter(C=>Wa(e[C.polygon]));if(d.length===0)continue;let m=d[0],p=1-Math.min(1,Math.abs(Gt(u.normal,f.normal))),g=Math.max(u.length,f.length);if(p<.01&&g<64)continue;let h=Math.max(...d.map(C=>Dm(n[C.polygon]))),y=d.length===2?1.18:1,b=Math.max(.08,p),x=o.viewAware?Xm(u,f,o.rotX,o.rotY):{proj:g,vr:1},P=o.viewAware?Math.max(x.proj,g*.12):g,M=o.viewAware?.18+x.vr*1.82:1;r.push({key:c,e:[Vo(m.a),Vo(m.b)],o:l,r:d,len:g,rank:P,proj:x.proj,s:P*(.58+b*2.8)*h*y*M,nr:p,sr:h,vr:x.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let i=Array.from({length:r.length},(c,l)=>l),s=new Map;for(let c=0;c<r.length;c+=1)for(let l of r[c].e){let u=s.get(l);if(u===void 0)s.set(l,c);else{let f=_o(i,u),d=_o(i,c);f!==d&&(i[d]=f)}}let a=new Map;for(let c=0;c<r.length;c+=1){let l=_o(i,c),u=a.get(l);u===void 0&&(u=a.size,a.set(l,u)),r[c].comp=u}return r}function Xm(e,n,t,o){let r=To(e.a,t,0,o),i=To(e.b,t,0,o),s=Math.hypot(i[0]-r[0],i[1]-r[1]),a=To(e.normal,t,0,o)[2],c=To(n.normal,t,0,o)[2],l=Math.max(0,a,c),u=Math.min(1,Math.abs(a-c));return{proj:s,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function Ym(e){let n=new Map;for(let t of e){let o=n.get(t.comp);(!o||t.s>o.s||t.s===o.s&&t.len>o.len)&&n.set(t.comp,t)}return new Set(n.values())}function Ut(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+n*n*n*3.65,o=e.r.length===1?1.08:1;return e.rank*t*o/Math.sqrt(Math.max(1,e.r.length))}function Fa(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+Math.min(1,e.vr)*1.65,o=.7+Math.min(2.6,e.sr)*.3,r=e.r.length===1?1.1:1,i=e.rank*(.6+n*n*1.4)*t*o*r/Math.sqrt(Math.max(1,e.r.length));return Math.max(i,Ut(e)*.75)}function $r(e){let n=new Set;for(let t of e)for(let o of t.r)n.add(o.polygon);return n.size}function Ha(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function jm(e,n,t){return e.s>=n||e.rank>=t}function Wm(e,n,t,o,r,i,s){let a=Math.max(0,Math.floor(t));if(a<=0||e.length===0||n==="follow-up")return{budgetLimit:a,componentBudgets:null};let c=new Map;for(let m of e){let p=c.get(m.comp);p?p.push(m):c.set(m.comp,[m])}let l=new Map,u=Math.max(1e-6,o.q3-o.q1),f=Math.min(o.max,Math.max(o.p95,o.q3+u)),d=0;for(let[m,p]of c){let g=p.filter(M=>jm(M,i,s)||M.s>=f);if(g.length===0)continue;let h=p.filter(M=>Ha(M,r)),y=$r(g),b=$r(h),x=Math.ceil(Math.sqrt(Math.max(0,b-y))*3),P=Math.min($r(p),y+x);P<=0||(l.set(m,P),d+=P)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(a,d),componentBudgets:l}}function Hm(e,n,t){let o=new Map;if(e.length===0||t<=0)return{selected:o,budgetLimit:0};let r=Da(e.map(S=>S.s)),i=Da(e.map(S=>S.rank)),s=Math.max(1e-6,r.q3-r.q1),a=Math.min(r.max,Math.max(r.p95,r.q3+s*.85)),c=Math.min(r.max,Math.max(r.p80,r.q3+s*.15)),l=Math.min(r.max,Math.max(r.p70,r.q3)),u=Math.max(i.p97,i.median*1.8),f=Math.max(i.p88,i.median*1.35),d=Wm(e,n,t,r,i,a,u),m=d.budgetLimit;if(m<=0)return{selected:o,budgetLimit:0};let p=Ym(e),g=new Set,h=new Set,y=new Set,b=new Map,x=n==="primary"?Math.min(Math.max(0,d.budgetLimit-1),Math.max(2,Math.floor(d.budgetLimit*.28))):0,P=[...e].sort((S,T)=>Ut(T)-Ut(S)||T.s/Math.max(1,T.r.length)-S.s/Math.max(1,S.r.length)||T.len-S.len),M=[...e].sort((S,T)=>Fa(T)-Fa(S)||Ut(T)-Ut(S)||T.len-S.len),C=(S,T)=>{S.sel=!0,S.why=T,y.add(S.comp);for(let v of S.e)h.add(v);for(let v of S.r){g.add(v.polygon);let R=o.get(v.polygon);R?R.add(v.edge):o.set(v.polygon,new Set([v.edge]))}},E=(S,T)=>{let v=d.componentBudgets;if(T<=0||!v)return!0;let R=v.get(S.comp)??0;return(b.get(S.comp)??0)+T<=R},A=(S,T)=>{T<=0||!d.componentBudgets||b.set(S.comp,(b.get(S.comp)??0)+T)};for(let S of M){let T=S.r.reduce((R,O)=>R+(g.has(O.polygon)?0:1),0);if(S.cost=T,!(T>m||!E(S,T)||T>0&&m-T<x||!Ha(S,i))&&(C(S,"global-outlier"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((D,_)=>D+(g.has(_.polygon)?0:1),0);if(S.cost=T,T>m||!E(S,T)||T>0&&m-T<x)continue;let v=S.r.length===2,R=p.has(S)&&(n==="primary"||n==="follow-up"&&S.s>=c*1.08&&S.rank>=f)&&(v?S.s>=c||S.rank>=f:S.s>=c*1.18||S.rank>=f*1.12),O=v?S.s>=a||S.rank>=u:S.s>=a*1.35||S.rank>=u*1.2,L=T===0&&(v?S.s>=l||S.rank>=f:S.s>=l*1.25||S.rank>=f*1.12);if(!(!R&&!O&&!L)&&(C(S,R?"component-anchor":O?"global-outlier":"shared-polygon"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((_,w)=>_+(g.has(w.polygon)?0:1),0);if(S.cost=T,T>1||T>m||!E(S,T))continue;let v=S.r.some(_=>g.has(_.polygon)),R=S.e.some(_=>h.has(_));if(n==="primary"&&S.r.length===1&&T===1&&(y.has(S.comp)||R||v)&&S.rank>=f*1.05&&S.nr>=.16&&S.vr<=.32){if(C(S,"local-follow-up"),A(S,T),m-=T,m<=0)return{selected:o,budgetLimit:d.budgetLimit};continue}if(S.r.length!==2)continue;let L=v&&T===1&&S.proj>=f*1.45&&S.vr<=.18;if(!R&&!L)continue;if((S.s>=l*.42||S.rank>=f*.62)&&S.s<=l*1.1&&S.proj>=24&&(C(S,"local-follow-up"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}return{selected:o,budgetLimit:d.budgetLimit}}function Ka(e,n,t,o,r){let i=Xa(e),s=Ya(e,i,n.capacityScale),a=new Map;for(let u of s){let f=a.get(u.key);f?f.push(u):a.set(u.key,[u])}let c=$m(e,i,a,t).filter(u=>Gm(u,r)),l=Hm(c,r?"follow-up":"primary",o);return{selected:l.selected,candidates:c,budgetLimit:l.budgetLimit}}function Km(e,n){let t=[];for(let o=0;o<e.length;o+=1){let r=e[o],i=n.get(o);i&&Wa(r)?t.push(...zm(r,i)):t.push(r)}return t}function Zm(e){let[n,t]=e.o,o=n??t,r=t??n;return{key:e.key,aPolygon:o?.polygon??-1,aEdge:o?.edge??-1,bPolygon:r?.polygon??-1,bEdge:r?.edge??-1,color:o?.color??r?.color,materialKey:o?.materialKey??r?.materialKey??"",lengthPx:e.len,projectedLengthPx:e.proj,score:e.s,normalRisk:e.nr,shapeRisk:e.sr,viewRisk:e.vr,component:e.comp,marginalCost:e.cost,selected:e.sel,reason:e.why}}function Za(e,n,t){let o=st(n),r=za(t);if(!at(o,n)||e.length===0)return e;let i=e,s,a=r.budget;for(let c=0;c<r.passes;c+=1){let l=Ka(i,o,r,a,s);if(c===0&&(a=Math.min(a,l.budgetLimit)),l.selected.size===0)break;let u=Km(i,l.selected);if(u.length===i.length)break;if(a-=l.selected.size,a<=0){i=u;break}s=Um(l.candidates),i=u}return i}function qm(e,n,t){let o=st(n),r=za(t);if(!at(o,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let i=Ka(e,o,r,r.budget),s=0;for(let a of i.selected.values())s+=a.size;return{candidates:i.candidates.map(Zm),selectedPolygons:i.selected.size,selectedEdges:s,addedPolygons:i.selected.size}}function qa(e,n){let t=st(n);if(!at(t,n)||e.length===0)return e;let{edgeRepairs:o}=Lo(e,t);return o.some(r=>r.size>0)?e.map((r,i)=>Nm(r,o[i],t.capacityScale)):e}function Qm(e,n=Ba,t=ka){if(e.length===0)return e;let o=Za(e,n,t);return qa(o,n)}function Jm(e,n){let t=st(n);return!at(t,n)||e.length===0?Ro():Lo(e,t).diagnostics}function Qa(e,n){let t=st(n);return!at(t,n)||e.length===0?Ro():Lo(e,t,!1,!0).diagnostics}function ed(e,n){let t=st(n);if(!at(t,n)||e.length===0)return{diagnostics:Ro(),candidates:[]};let o=Lo(e,t,!0);return{diagnostics:o.diagnostics,candidates:o.candidates??[]}}var Yn={ratio:.7,maxError:.18,maxNormalDot:Math.cos(65*Math.PI/180),preserveVertices:!0,vertexKeyMode:"relaxed",lockBoundary:!0,minGroupTriangles:80,maxPasses:12};function nd(e={}){let n=Number.isFinite(e.ratio)?Math.max(.05,Math.min(.98,e.ratio)):Yn.ratio,t=Number.isFinite(e.maxError)&&e.maxError>0?e.maxError:Yn.maxError,o=Number.isFinite(e.maxNormalAngleDeg)?Math.max(0,Math.min(89,e.maxNormalAngleDeg)):65;return{ratio:n,maxError:t,maxNormalDot:Math.cos(o*Math.PI/180),preserveVertices:e.preserveVertices??Yn.preserveVertices,vertexKeyMode:e.vertexKeyMode??Yn.vertexKeyMode,lockBoundary:e.lockBoundary??Yn.lockBoundary,minGroupTriangles:Math.max(3,Math.floor(e.minGroupTriangles??Yn.minGroupTriangles)),maxPasses:Math.max(1,Math.floor(e.maxPasses??Yn.maxPasses))}}function td(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function od(e){return e.vertices.length===3&&!td(e)}function rd(e){return[e.color??"",e.doubleSided===!0?"2":"1",e.material?.key??""].join("\0")}function Ja(e){return`${Math.round(e[0]*1e5)},${Math.round(e[1]*1e5)},${Math.round(e[2]*1e5)}`}function id(e,n,t,o){let r=o.vertexKeyMode==="source"?e.simplifySourceVertexKeys?.[t]??e.simplifyVertexKeys?.[t]:e.simplifyVertexKeys?.[t];return r?`${Ja(n)}|${r}`:Ja(n)}function sd(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function lt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function ad(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function Kr(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function ec(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Qr(e){return Math.hypot(e[0],e[1],e[2])}function Zr(e,n){return Qr(lt(e,n))}function cd(e){let n=Qr(e);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n]:[0,0,1]}function Jr(e,n,t,o){return cd(ec(lt(e[t],e[n]),lt(e[o],e[n])))}function nc(e,n,t,o){return Qr(ec(lt(e[t],e[n]),lt(e[o],e[n])))/2}function ld(){return[0,0,0,0,0,0,0,0,0,0]}function wo(e,n){for(let t=0;t<e.length;t+=1)e[t]+=n[t]}function ud(e,n,t){let o=e[0],r=e[1],i=e[2],s=-Kr(e,n);return[o*o*t,o*r*t,o*i*t,o*s*t,r*r*t,r*i*t,r*s*t,i*i*t,i*s*t,s*s*t]}function qr(e,n){let t=n[0],o=n[1],r=n[2];return e[0]*t*t+2*e[1]*t*o+2*e[2]*t*r+2*e[3]*t+e[4]*o*o+2*e[5]*o*r+2*e[6]*o+e[7]*r*r+2*e[8]*r+e[9]}function fd(e,n,t,o,r,i,s,a,c,l,u,f){let d=e*(r*c-i*a)-n*(o*c-i*s)+t*(o*a-r*s);if(Math.abs(d)<1e-10)return null;let m=1/d,p=l*(r*c-i*a)-n*(u*c-i*f)+t*(u*a-r*f),g=e*(u*c-i*f)-l*(o*c-i*s)+t*(o*f-u*s),h=e*(r*f-u*a)-n*(o*f-u*s)+l*(o*a-r*s),y=[p*m,g*m,h*m];return y.every(Number.isFinite)?y:null}function md(e,n,t,o){let r=fd(e[0],e[1],e[2],e[1],e[4],e[5],e[2],e[5],e[7],-e[3],-e[6],-e[8]),i=ad(sd(n,t),.5),s=Zr(n,t)*1.35,a=o?[n,t]:[n,t,i,...r&&Zr(r,i)<=s?[r]:[]],c=a[0],l=qr(e,c);for(let u=1;u<a.length;u+=1){let f=a[u],d=qr(e,f);d<l&&(c=f,l=d)}return c}function dd(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function pd(e,n,t){return`${e}|${n}|${t}`}function gd(e,n){let t=new Map,o=[],r=[];for(let i of e){let s=[];for(let u=0;u<i.vertices.length;u+=1){let f=i.vertices[u],d=id(i,f,u,n),m=t.get(d);m===void 0&&(m=o.length,t.set(d,m),o.push([...f])),s.push(m)}let[a,c,l]=s;a===void 0||c===void 0||l===void 0||a===c||a===l||c===l||r.push({a,b:c,c:l,polygon:i,normal:Jr(o,a,c,l)})}return{vertices:o,triangles:r}}function hd(e,n){let t=gd(e,n),o=Array.from({length:t.vertices.length},()=>new Set),r=Array.from({length:t.triangles.length},()=>!0);for(let i=0;i<t.triangles.length;i+=1){let s=t.triangles[i];o[s.a].add(i),o[s.b].add(i),o[s.c].add(i)}return{vertices:t.vertices,triangles:t.triangles,alive:r,vertexTriangles:o,activeCount:t.triangles.length}}function yd(e){let n=new Map,t=(o,r,i)=>{let s=dd(o,r),a=n.get(s);a?a.triangles.push(i):n.set(s,{a:Math.min(o,r),b:Math.max(o,r),triangles:[i]})};for(let o=0;o<e.triangles.length;o+=1){if(!e.alive[o])continue;let r=e.triangles[o];t(r.a,r.b,o),t(r.b,r.c,o),t(r.c,r.a,o)}return n}function bd(e){let n=Array.from({length:e.vertices.length},()=>ld());for(let t=0;t<e.triangles.length;t+=1){if(!e.alive[t])continue;let o=e.triangles[t],r=Math.max(1e-6,nc(e.vertices,o.a,o.b,o.c)),i=ud(o.normal,e.vertices[o.a],Math.sqrt(r));wo(n[o.a],i),wo(n[o.b],i),wo(n[o.c],i)}return n}function xd(e,n,t){let o=new Set,r=i=>{let s=e.vertexTriangles[i];if(s)for(let a of s)e.alive[a]&&o.add(a)};return r(n),r(t),Array.from(o).sort((i,s)=>i-s)}function Pd(e,n,t){let o=e.vertexTriangles[n],r=e.vertexTriangles[t];if(!o||!r)return 0;let[i,s]=o.size<=r.size?[o,r]:[r,o],a=0;for(let c of i)e.alive[c]&&s.has(c)&&(a+=1);return a}function tc(e,n,t){return[e.a===t?n:e.a,e.b===t?n:e.b,e.c===t?n:e.c]}function Md(e,n,t){if(Pd(e,n.a,n.b)!==2)return null;let o=xd(e,n.a,n.b);if(o.length===0)return null;let r=e.vertices[n.a];e.vertices[n.a]=n.target;let i=0,s=!0;for(let a of o){let c=e.triangles[a],[l,u,f]=tc(c,n.a,n.b);if(l===u||l===f||u===f)continue;if(nc(e.vertices,l,u,f)<=1e-8){s=!1;break}let m=Jr(e.vertices,l,u,f);if(Kr(c.normal,m)<t.maxNormalDot){s=!1;break}let p=c.a===n.a?r:e.vertices[c.a];if(Math.abs(Kr(c.normal,lt(n.target,p)))>t.maxError){s=!1;break}i+=1}return e.vertices[n.a]=r,s&&i>0?o:null}function Sd(e,n,t){e.vertexTriangles[t.a]?.delete(n),e.vertexTriangles[t.b]?.delete(n),e.vertexTriangles[t.c]?.delete(n)}function Ad(e,n,t){e.vertexTriangles[t.a].add(n),e.vertexTriangles[t.b].add(n),e.vertexTriangles[t.c].add(n)}function Cd(e,n,t){e.vertices[n.a]=n.target;let o=new Set;for(let r of t){if(!e.alive[r])continue;let i=e.triangles[r],[s,a,c]=tc(i,n.a,n.b);if(Sd(e,r,i),s===a||s===c||a===c){e.alive[r]=!1,e.activeCount-=1;continue}let l=pd(s,a,c);if(o.has(l)){e.alive[r]=!1,e.activeCount-=1;continue}o.add(l);let u={...i,a:s,b:a,c,normal:Jr(e.vertices,s,a,c)};e.triangles[r]=u,Ad(e,r,u)}}function Td(e,n){let t=yd(e),o=new Set;for(let a of t.values())a.triangles.length>2&&(o.add(a.a),o.add(a.b));if(n.lockBoundary)for(let a of t.values())a.triangles.length===1&&(o.add(a.a),o.add(a.b));let r=bd(e),i=n.maxError*n.maxError,s=[];for(let a of t.values()){if(a.triangles.length!==2||o.has(a.a)||o.has(a.b))continue;let c=[...r[a.a]];wo(c,r[a.b]);let l=md(c,e.vertices[a.a],e.vertices[a.b],n.preserveVertices),u=Math.max(0,qr(c,l));if(u>i*Math.max(1,a.triangles.length))continue;let f=Zr(e.vertices[a.a],e.vertices[a.b]);s.push({a:a.a,b:a.b,target:l,error:u,length:f})}return s.sort((a,c)=>a.error-c.error||a.length-c.length),s}function Ed(e){let n=[];for(let t=0;t<e.triangles.length;t+=1)e.alive[t]&&n.push(e.triangles[t]);return n}function vd(e,n){if(e.length<n.minGroupTriangles)return e;let t=hd(e,n),o=t.activeCount;if(o<n.minGroupTriangles)return e;let r=Math.max(1,Math.floor(o*n.ratio));if(r>=o)return e;let i=0;for(let s=0;s<n.maxPasses&&t.activeCount>r;s+=1){let a=Td(t,n);if(a.length===0)break;let c=0;for(let l of a){if(t.activeCount<=r)break;let u=Md(t,l,n);if(!u)continue;let f=t.activeCount;Cd(t,l,u),!(t.activeCount>=f)&&(i+=1,c+=1)}if(c===0)break}return i===0||t.activeCount>=o?e:Ed(t).map(s=>({...s.polygon,vertices:[[...t.vertices[s.a]],[...t.vertices[s.b]],[...t.vertices[s.c]]]}))}function Id(e){let n=new Map;for(let t=0;t<e.length;t+=1){let o=e[t];if(!od(o))continue;let r=rd(o),i=n.get(r);i?(i.indices.push(t),i.polygons.push(o)):n.set(r,{indices:[t],polygons:[o]})}return n}function ei(e,n){let t=nd(n),o=Id(e);if(o.size===0)return e;let r=new Map,i=!1;for(let a of o.values()){let c=vd(a.polygons,t);if(!(c===a.polygons||c.length>=a.polygons.length)){r.set(a.indices[0],c);for(let l=1;l<a.indices.length;l+=1)r.set(a.indices[l],[]);i=!0}}if(!i)return e;let s=[];for(let a=0;a<e.length;a+=1){let c=r.get(a);c?s.push(...c):c===void 0&&s.push(e[a])}return s}var _d=3,Vd=.03,Od=.02,Xt={maxAngleDeg:_d,maxPlaneDisplacement:Vd,maxBoundaryDisplacement:Od,isolatedPairs:!1},No={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},ni=[{...No,maxAngleDeg:30},{...No,maxAngleDeg:45},{...No,maxAngleDeg:60,maxBoundaryDisplacement:.06}],Rd=1800,Ld=.65,oc=500,rc=2200,wd=1e3,Nd=2200,Dd=350,Fd=700,Bd=60,kd=.06,zd=4,Ud=.003,Gd=4e3,$d=3e3,Xd=4500,Yd=2400,jd=4200,Wd=1800,Hd=5e3,Kd=.28,Zd=.15,qd=.23,Qd=2e3,Jd=16,ep=4e3,np=900,tp=16,op=1.5,oi=.045,rp=.999,ip=1e-5,sp=24,ap=50,cp=1e3,lp=1e3,Wn={minGroupPolygons:2,maxCandidateAxes:24},up={...Wn,maxCandidateAxes:1},ic={...Wn,maxCandidateAxes:2},fp={...Wn,maxCandidateAxes:2},mp={steps:[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"},{kind:"finalLossyCandidates"}]};function dp(e,n={}){return pp(e,n).polygons}function uc(e,n={}){let t={meshResolution:n.meshResolution,stopAtPolygonCount:n.stopAtPolygonCount,rectCover:n.rectCover},o=new Do,r={captureVisiblePolygons:!0,skipInteriorCull:n.skipInteriorCull===!0};return o.workspaceFor(e,r).createRun(t,r).optimizeParse({staticSimplification:n.staticSimplification,useCandidateFirst:n.useCandidateFirst===!0}).polygons}function pp(e,n={},t={}){return new Do().workspaceFor(e,t).createRun(n,t).optimize()}var Do=class{constructor(){this.workspaces=new Map}workspaceFor(n,t){let o=gp(t),r=this.workspaces.get(o);r||(r=new WeakMap,this.workspaces.set(o,r));let i=r.get(n);return i||(i=new ri(n,t,this),r.set(n,i)),i}};function gp(e){return[e.skipInteriorCull===!0?"skip-cull":"cull",e.simplifiedCandidate===!0?"simplified":"source"].join(":")}var ri=class{constructor(n,t,o){this.source=n,this.graph=o,this.preprocessCache={skipInteriorCull:t.skipInteriorCull===!0}}polygons(){return this.source}preprocess(n){return kp(this.source,n,this.preprocessCache)}configureSnappedCullReuse(n,t){let o=n.length/Math.max(1,this.source.length);this.preprocessCache.reuseSnappedInteriorCull=t.simplifiedCandidate===!0?this.source.length<=jd:n.length<=Wd||n.length<=Hd&&o>=Kd}visiblePolygons(){return this.preprocessCache.interior??this.preprocessCache.deduped??this.source}createRun(n,t){return new ii(this,n,t)}workspaceFor(n,t){return this.graph.workspaceFor(n,t)}},ii=class e{constructor(n,t,o,r={}){this.baselineCandidatesComplete=!1;this.initialLossyCandidatesComplete=!1;this.finalLossyCandidatesComplete=!1;this.workspace=n,this.source=n.polygons(),this.options=t,this.runOptions=o,this.costCandidateMode=r.costCandidateMode??"cost",this.seamCandidateMode=r.seamCandidateMode??"seamSafe",this.offerBaseline=r.offerBaseline===!0,this.meshResolution=t.meshResolution??"lossy",this.stopAtPolygonCount=Number.isFinite(t.stopAtPolygonCount)?Math.max(0,Math.floor(t.stopAtPolygonCount)):void 0,this.requiredMaxPolygonCount=Number.isFinite(o.requiredMaxPolygonCount)?Math.max(0,Math.floor(o.requiredMaxPolygonCount)):void 0,this.baseline=this.preprocess(!1),this.workspace.configureSnappedCullReuse(this.baseline,o),this.visiblePolygons=o.captureVisiblePolygons?this.workspace.visiblePolygons():void 0,this.acceptor=r.acceptor??new si(this.baseline,this.requiredMaxPolygonCount)}optimize(){return this.runPlan(mp)}optimizeParse(n){let t=n.staticSimplification===!1?null:n.staticSimplification??{},o=[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"}];return n.useCandidateFirst||o.push({kind:"finalLossyCandidates"}),t&&o.push({kind:"staticSimplificationCandidates",options:t,stopOnAccept:n.useCandidateFirst}),n.useCandidateFirst&&o.push({kind:"finalLossyCandidates"}),this.runPlan({steps:o})}get best(){return this.acceptor.polygons}get bestCost(){return this.acceptor.cost}runStaticSimplificationCandidates(n={}){if(this.meshResolution!=="lossy"||!Vp(this.source,this.best))return!1;let t=mc(this.source,n);if(!t)return!1;for(let o of this.staticSimplificationPlans(t)){let r=Op(o,n);if(r&&this.generateStaticSimplificationCandidate(r,n,o.skipInteriorCull))return!0}return!1}staticSimplificationPlans(n){let t=this.source.length-n.length,o=[],r=this.visiblePolygons&&this.visiblePolygons!==this.source?this.source.length-this.visiblePolygons.length:0;return this.visiblePolygons&&this.visiblePolygons!==this.source&&this.source.length>=ep&&r>=np&&(t<=tp||r>=t*op)&&o.push({source:this.visiblePolygons,skipInteriorCull:!0}),this.best.length>=Qd&&t<=Jd&&_p(this.source)&&o.push({source:this.source,vertexKeyMode:"source"}),o.push({source:this.source,precomputed:n}),o}generateStaticSimplificationCandidate(n,t,o=!1){let r={requiredMaxPolygonCount:this.best.length-1,skipExactRectCover:!0,skipInteriorCull:o,simplifiedCandidate:!0},i=this.workspace.workspaceFor(n,r),s=this.best;return new e(i,{meshResolution:"lossy",stopAtPolygonCount:Ip(this.best.length,t)},r,{acceptor:this.acceptor,costCandidateMode:"dom",seamCandidateMode:"dom",offerBaseline:!0}).optimize(),this.best!==s}runPlan(n){for(let t of n.steps){let o=!1;if(t.kind==="baselineCandidates")this.runBaselineCandidates();else if(t.kind==="staticSimplificationCandidates")o=this.runStaticSimplificationCandidates(t.options)&&t.stopOnAccept;else{if(!this.shouldRunLossyPipeline())break;t.kind==="initialLossyCandidates"?this.runInitialLossyPipeline():this.runFinalLossyPipeline()}if(o||this.shouldStop())break}return this.result()}runBaselineCandidates(){if(this.baselineCandidatesComplete||(this.baselineCandidatesComplete=!0,this.offerBaseline&&(this.acceptCandidate(this.baseline),this.shouldStop())))return;let n=this.runOptions.skipExactRectCover===!0?!1:this.meshResolution==="lossy"&&this.options.rectCover===void 0?Lp(this.baseline):this.options.rectCover;if(this.shouldStop())return;let t=jn(this.baseline,n);if(t!==this.baseline&&this.acceptCandidate(t),!this.shouldStop()&&this.meshResolution==="lossy"&&this.options.rectCover===void 0&&this.runOptions.skipExactRectCover!==!0){let o=jn(this.baseline,void 0);o!==this.baseline&&this.acceptCandidate(o)}}shouldRunLossyPipeline(){return this.meshResolution==="lossy"&&!this.shouldStop()&&this.best.length>1&&this.bestCost>1+1e-9}runInitialLossyPipeline(){if(this.initialLossyCandidatesComplete)return;this.initialLossyCandidatesComplete=!0;let n=this.preprocess(No);this.acceptCandidate(n),!this.shouldStop()&&(this.options.rectCover===void 0&&this.source.length>=oc&&this.source.length<=rc&&(this.acceptCandidate(jn(n,ic)),this.shouldStop())||this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(this.acceptCandidate(jn(n,this.options.rectCover)),this.shouldStop()))}runFinalLossyPipeline(){this.finalLossyCandidatesComplete||(this.finalLossyCandidatesComplete=!0,!(this.runOptions.simplifiedCandidate===!0&&this.source.length>Xd)&&(this.runAggressiveLossyVariants(),!this.shouldStop()&&this.runLargeRectCoverCandidate()))}runAggressiveLossyVariants(){let n=this.stopAtPolygonCount===void 0&&this.source.length>=Gd&&this.best.length<=$d,t=!1;for(let o=n?ni.length:0;o<ni.length;o+=1){if(o===1&&!t||o===1&&this.runOptions.simplifiedCandidate===!0&&this.source.length<Yd||o===2&&!Np(this.source))continue;let r=this.preprocess(ni[o]),i=r;this.options.rectCover===void 0&&this.source.length>=oc&&this.source.length<=rc&&(i=jn(r,ic)),this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(i=jn(r,this.options.rectCover));let s=this.acceptSeamSafeCandidate(i,this.source.length);if(o===0&&s&&(t=!0),this.shouldStop())return}}runLargeRectCoverCandidate(){if(this.options.rectCover!==void 0)return;let n=jn(this.best,wp(this.best));n!==this.best&&this.acceptSeamSafeCandidate(n,this.best.length)}preprocess(n){return this.workspace.preprocess(n)}result(){return{polygons:this.best,visiblePolygons:this.visiblePolygons}}shouldStop(){return this.stopAtPolygonCount!==void 0&&this.best.length<=this.stopAtPolygonCount}acceptCandidate(n,t=Hn(n)){return this.emitCandidate({mode:this.costCandidateMode,polygons:n,cost:t})}acceptDomCandidate(n){return this.emitCandidate({mode:"dom",polygons:n})}acceptSeamSafeCandidate(n,t,o){return this.emitCandidate({mode:this.seamCandidateMode,polygons:n,sourcePolygonCount:t,cost:o})}emitCandidate(n){return this.acceptor.accept({...n,maxPolygonCount:n.maxPolygonCount??this.requiredMaxPolygonCount})}},si=class{constructor(n,t){this.best=n,this.bestCost=Hn(n),this.bestDiagnostics={polygons:n},this.requiredMaxPolygonCount=t}get polygons(){return this.best}get cost(){return this.bestCost}accept(n){return n.mode==="cost"?this.acceptCostCandidate(n.polygons,n.cost):n.mode==="dom"?this.acceptDomCandidate(n.polygons,n.cost,n.maxPolygonCount):this.acceptSeamSafeCandidate(n.polygons,n.sourcePolygonCount??n.polygons.length,n.cost,n.maxPolygonCount)}acceptCostCandidate(n,t=Hn(n)){return t>=this.bestCost?!1:(this.commit(n,t),!0)}acceptDomCandidate(n,t=Hn(n),o){return n.length>=this.best.length||!this.withinMaxPolygonCount(n,o)?!1:(this.commit(n,t),!0)}acceptSeamSafeCandidate(n,t,o,r){if(n.length>=this.best.length||!this.withinMaxPolygonCount(n,r))return!1;let i=vp(t);if(this.bestCost-n.length<i)return!1;let s=o??Hn(n),a=this.bestCost-s;if(a<=0||a<i)return!1;let c=sc(n);if(!c)return!1;let l=this.bestSeamDiagnostics();return!l||hp(c,l)||yp(this.bestTopologyEdges(),this.bestTopologySelfDiagnostics(),n)?!1:(this.commit(n,s,c),!0)}withinMaxPolygonCount(n,t){let o=t??this.requiredMaxPolygonCount;return o===void 0||n.length<=o}commit(n,t,o){this.best=n,this.bestCost=t,this.bestDiagnostics={polygons:n,seam:o}}resetBestDiagnostics(n){this.bestDiagnostics={polygons:this.best,seam:n}}bestSeamDiagnostics(){if(this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),!this.bestDiagnostics.seam){let n=sc(this.best);if(!n)return null;this.bestDiagnostics.seam=n}return this.bestDiagnostics.seam}bestTopologyEdges(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologyEdges||(this.bestDiagnostics.topologyEdges=fc(this.best)),this.bestDiagnostics.topologyEdges}bestTopologySelfDiagnostics(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologySelf||(this.bestDiagnostics.topologySelf=Mp(this.bestTopologyEdges(),oi)),this.bestDiagnostics.topologySelf}};function Hn(e){let n=0;for(let t of e){let o=t.vertices.length,r=o<=4?0:Math.min(4,o-4)*.12,i=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+r+i}return n}function sc(e){try{return Qa(e)}catch(n){if(n instanceof RangeError&&n.message==="Set maximum size exceeded")return null;throw n}}function hp(e,n){return e.nearPairs>n.nearPairs||e.unclosedPairs>n.unclosedPairs||e.maxMeasuredGapPx>n.maxMeasuredGapPx+1e-9||e.maxResidualGapPx>n.maxResidualGapPx+1e-9}function yp(e,n,t){let o=fc(t);return bp(e,o,oi)?!0:Pp(o.boundarySegments,oi,n)}function bp(e,n,t){if(e.internalSegments.length===0)return!1;let o=xp(e,t);for(let r of n.boundarySegments)if(!e.boundaryKeys.has(r.key)&&(e.internalKeys.has(r.key)||Tp(r,o,t)))return!0;return!1}function xp(e,n){return(!e.internalIndex||e.internalIndexTolerance!==n)&&(e.internalIndex=li(e.internalSegments,n),e.internalIndexTolerance=n),e.internalIndex}function Pp(e,n,t){let o=li(e,n),r=new Set,i=0,s=0,a=0;for(let c of e)i=Math.max(i,c.index+1);for(let c of e)for(let l of ui(c,o,n)){if(l===c||l.polygon===c.polygon||l.key===c.key)continue;let u=c.index<l.index?c.index*i+l.index:l.index*i+c.index;if(r.has(u))continue;r.add(u);let f=fi(c,l,n);if(f&&(s+=1,a+=f.overlapLength,s>t.tJunctionPairs||a>t.tJunctionLength+1e-9))return!0}return!1}function Mp(e,n){let t={tJunctionPairs:0,tJunctionLength:0};return Sp(t,e.boundarySegments,n),t}function Sp(e,n,t){let o=li(n,t),r=new Set,i=0;for(let s of n)i=Math.max(i,s.index+1);for(let s of n)for(let a of ui(s,o,t)){if(a===s||a.polygon===s.polygon||a.key===s.key)continue;let c=s.index<a.index?s.index*i+a.index:a.index*i+s.index;if(r.has(c))continue;r.add(c);let l=fi(s,a,t);l&&(e.tJunctionPairs+=1,e.tJunctionLength+=l.overlapLength)}}function fc(e){let n=new Map;for(let c=0;c<e.length;c+=1){let l=e[c].vertices;for(let u=0;u<l.length;u+=1){let f=l[u],d=l[(u+1)%l.length],m=Ap(Wt(f,d),c,u,f,d);if(!m)continue;let p=n.get(m.key);p?p.count+=1:n.set(m.key,{count:1,segment:m})}}let t=new Set,o=new Set,r=[],i=[],s=0,a=0;for(let c of n.values()){let l={...c.segment,index:a};a+=1,c.count===1?(t.add(l.key),r.push(l),s+=l.length):(o.add(l.key),i.push(l))}return{boundaryKeys:t,internalKeys:o,boundarySegments:r,internalSegments:i,boundaryLength:s}}function Ap(e,n,t,o,r){let i=Cn(r,o),s=Math.hypot(i[0],i[1],i[2]);if(s<=1e-10)return null;let a=[i[0]/s,i[1]/s,i[2]/s];return{index:-1,key:e,polygon:n,edge:t,a:o,b:r,dir:a,length:s,minX:Math.min(o[0],r[0]),minY:Math.min(o[1],r[1]),minZ:Math.min(o[2],r[2]),maxX:Math.max(o[0],r[0]),maxY:Math.max(o[1],r[1]),maxZ:Math.max(o[2],r[2])}}function li(e,n){let t=Math.max(n*8,.5),o=new Map;for(let r of e)Cp(o,r,t,n);return{cellSize:t,cells:o}}function Cp(e,n,t,o){let[r,i,s]=Fo([n.minX-o,n.minY-o,n.minZ-o],t),[a,c,l]=Fo([n.maxX+o,n.maxY+o,n.maxZ+o],t);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function Fo(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function ui(e,n,t){let o=[],r=new Set,[i,s,a]=Fo([e.minX-t,e.minY-t,e.minZ-t],n.cellSize),[c,l,u]=Fo([e.maxX+t,e.maxY+t,e.maxZ+t],n.cellSize);for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1)for(let m=a;m<=u;m+=1){let p=n.cells.get(`${f},${d},${m}`);if(p)for(let g of p)r.has(g)||(r.add(g),o.push(g))}return o}function Tp(e,n,t){for(let o of ui(e,n,t))if(fi(e,o,t))return!0;return!1}function fi(e,n,t){if(!Ep(e,n,t)||Math.abs(nn(e.dir,n.dir))<rp)return null;let o=nn(Cn(n.a,e.a),e.dir),r=nn(Cn(n.b,e.a),e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i;if(a<=Math.max(ip,Math.min(e.length,n.length)*1e-4))return null;let c=[e.a[0]+e.dir[0]*((i+s)/2),e.a[1]+e.dir[1]*((i+s)/2),e.a[2]+e.dir[2]*((i+s)/2)],l=Math.max(0,Math.min(n.length,nn(Cn(c,n.a),n.dir))),u=[n.a[0]+n.dir[0]*l,n.a[1]+n.dir[1]*l,n.a[2]+n.dir[2]*l],f=Ec(c,u);return f<=t?{overlapLength:a,offset:f}:null}function Ep(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function vp(e){return Math.max(zd,e*Ud)}function Ip(e,n){let t=Number.isFinite(n.earlyStopDropRatio)?Math.max(0,n.earlyStopDropRatio):Zd;return Math.max(0,e-Math.max(1,Math.ceil(e*t)))}function _p(e){return e.some(n=>n.simplifySourceVertexKeys?.length===n.vertices.length)}function Vp(e,n){return e.length===0||n.length/e.length>qd}function mc(e,n,t){let o=ei(e,{...n.simplifyTriangleMeshOptions,...t?{vertexKeyMode:t}:{}});return o===e||o.length>=e.length?null:o}function Op(e,n){return e.precomputed!==void 0?e.precomputed:mc(e.source,n,e.vertexKeyMode)}function jn(e,n){if(n===!1)return e;let t=Rp(e,n);if(!t)return e;let o=Fr(e,t);return o.length<e.length?o:e}function Rp(e,n){if(n&&n!==!0)return n;let t=n===!0,o=e.length;return o>2200||!t&&o>=sp&&o<ap||!t&&o>cp?null:!t&&o<=300?{...Wn,maxCandidateAxes:1}:o>300?!t&&(dc(e)>12||pc(e)>lp)?null:{...Wn,maxCandidateAxes:Math.min(Wn.maxCandidateAxes??24,2)}:Wn}function Lp(e){return e.length>Rd||e.length===0||Dp(e)/e.length<Ld?!1:up}function wp(e){return e.length<wd||e.length>Nd||dc(e)<=12||pc(e)>Dd?!1:fp}function Np(e){return e.length<=Fd}function Dp(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function dc(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function pc(e){let n=new Map;for(let o of e)for(let r=0;r<o.vertices.length;r++){let i=o.vertices[r],s=o.vertices[(r+1)%o.vertices.length],a=Wt(i,s);n.set(a,(n.get(a)??0)+1)}let t=0;for(let o of n.values())o===1&&(t+=1);return t}function Bo(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function ai(e,n){if(n===e||n.length===e.length&&n.every((r,i)=>r===e[i]))return null;let t=new Set(n),o=[];for(let r=0;r<e.length;r++)t.has(e[r])&&o.push(r);return o.length===e.length?null:o}function Fp(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let r=Mo(e);if(r.size===0)t=null;else{t=[];for(let i=0;i<e.length;i++)r.has(i)||t.push(i)}n&&(n.dedupedIndices=t)}let o=Bo(e,t);return n&&(n.deduped=o),o}function Bp(e,n){if(n?.skipInteriorCull)return e;if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let r=Mn(e);t=ai(e,r),n&&(n.interiorIndices=t)}let o=Bo(e,t);return n&&(n.interior=o),o}function kp(e,n,t){let o=Fp(e,t),r=Bp(o,t),i=t?.baseline??fn(r);if(t&&!t.baseline&&(t.baseline=i),!n)return i;let s=n===!0?Xt:Up(n);if(s.isolatedPairs){let u=cc(ac(o,t),s,t),f=fn(u);if(t?.snappedInteriorUsesBaselineFilter&&zp(i,f)){let d=cc(ac(o,t,!0),s,t),m=fn(d);m.length<f.length&&(f=m)}return f.length<i.length?f:i}let a=eg(o,s,t),c=Mn(a),l=fn(c);return l.length<i.length?l:i}function gc(e,n){return n?(n.snapped||(n.snapped=ko(e)),n.snapped):ko(e)}function ac(e,n,t=!1){if(!n)return Mn(ko(e));if(t&&n.snappedInteriorExact)return n.snappedInteriorExact;if(!t&&n.snappedInterior)return n.snappedInterior;let o=gc(e,n);if(t){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorExactIndices=n.interiorIndices,n.snappedInteriorExact=n.interior,n.snappedInteriorExact;let r=Mn(o);return n.snappedInteriorExactIndices=ai(o,r),n.snappedInteriorExact=r,n.snappedInteriorExact}if(!n.snappedInterior){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=n.interior,n.snappedInteriorUsesBaselineFilter=!1,n.snappedInterior;if(n.reuseSnappedInteriorCull!==!1&&n.interiorIndices!==void 0)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=Bo(o,n.snappedInteriorIndices),n.snappedInteriorUsesBaselineFilter=!0,n.snappedInterior;if(n.snappedInteriorIndices===void 0){let r=Mn(o);n.snappedInteriorIndices=ai(o,r),n.snappedInterior=r,n.snappedInteriorExactIndices=n.snappedInteriorIndices,n.snappedInteriorExact=r,n.snappedInteriorUsesBaselineFilter=!1}else n.snappedInterior=Bo(o,n.snappedInteriorIndices)}return n.snappedInterior}function zp(e,n){return n.length>=e.length}function Up(e){return{maxAngleDeg:e.maxAngleDeg??Xt.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??Xt.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??Xt.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??Xt.isolatedPairs}}function cc(e,n,t){let o=Gp(e,t),r=[];for(let s of $p(e,o))Xp(s,n)&&r.push(s.candidate);let i=jp(r);return i.length===0?e:Yp(e,i)}function Gp(e,n){if(n?.trianglePairSource?.polygons===e)return n.trianglePairSource;let t=e.map(s=>{let a=di(s);return a?{polygon:s,normal:a.normal,area:a.area,materialKey:Mc(s)}:null}),o=new Map;for(let s=0;s<e.length;s++){let a=e[s];if(!(a.vertices.length!==3||!t[s]))for(let c=0;c<a.vertices.length;c++){let l=Wt(a.vertices[c],a.vertices[(c+1)%a.vertices.length]),u=o.get(l);u?u.push(s):o.set(l,[s])}}let r=[];for(let s of o.values())s.length===2&&r.push([s[0],s[1]]);let i={polygons:e,metas:t,edgeOwnerPairs:r};return n&&(n.trianglePairSource=i),i}function $p(e,n){if(n.preparedCandidates)return n.preparedCandidates;let t=[];for(let[o,r]of n.edgeOwnerPairs){let i=qp(o,r,e,n.metas);i&&t.push(i)}return n.preparedCandidates=t,t}function Xp(e,n){let t=Math.cos(n.maxAngleDeg*Math.PI/180);return e.normalDot>=t&&e.maxDistance<=Math.min(n.maxPlaneDisplacement,n.maxBoundaryDisplacement)}function Yp(e,n){let t=new Map,o=new Set,r=hc(n.flatMap(s=>s.vertexMoves));for(let s of n){let a=Math.min(s.a,s.b);t.set(a,s.polygon),o.add(Math.max(s.a,s.b))}let i=[];for(let s=0;s<e.length;s++){let a=t.get(s);if(a){i.push(a);continue}o.has(s)||i.push(e[s])}return r.size>0?yc(i,r):i}function jp(e){return e.length>3e3?Wp(e):Hp(e)}function Wp(e){let n=new Map;for(let i of e)n.set(i.a,(n.get(i.a)??0)+1),n.set(i.b,(n.get(i.b)??0)+1);let t=[...e].sort((i,s)=>{let a=(n.get(i.a)??0)+(n.get(i.b)??0),c=(n.get(s.a)??0)+(n.get(s.b)??0);return a-c||i.score-s.score}),o=new Set,r=[];for(let i of t)o.has(i.a)||o.has(i.b)||(o.add(i.a),o.add(i.b),r.push(i));return r}function Hp(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],f=n.get(u.a);f?f.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let t=[],o=new Array(e.length).fill(!0),r=new Map,i=new ci;for(let[l,u]of n)r.set(l,u.length);let s=l=>(r.get(l.a)??0)+(r.get(l.b)??0),a=l=>{let u=e[l];i.push({degree:s(u),score:u.score,index:l})},c=(l,u)=>{if(!o[l])return;o[l]=!1;let f=e[l];for(let d of[f.a,f.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)a(l);for(;i.size()>0;){let l=i.pop();if(!o[l.index])continue;let u=e[l.index];if(s(u)!==l.degree){a(l.index);continue}t.push(u);let d=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])c(p,d);for(let m of d)for(let p of n.get(m)??[])o[p]&&a(p)}return t}var ci=class{constructor(){this.items=[]}size(){return this.items.length}push(n){this.items.push(n);let t=this.items.length-1;for(;t>0;){let o=t-1>>1;if(ti(this.items[o],this.items[t])<=0)break;[this.items[o],this.items[t]]=[this.items[t],this.items[o]],t=o}}pop(){if(this.items.length===0)return null;let n=this.items[0],t=this.items.pop();if(this.items.length>0){this.items[0]=t;let o=0;for(;;){let r=o*2+1,i=r+1,s=o;if(r<this.items.length&&ti(this.items[r],this.items[s])<0&&(s=r),i<this.items.length&&ti(this.items[i],this.items[s])<0&&(s=i),s===o)break;[this.items[o],this.items[s]]=[this.items[s],this.items[o]],o=s}}return n}};function ti(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function hc(e){let n=new Map;for(let o of e){let r=n.get(o.key);r?(r.x+=o.target[0],r.y+=o.target[1],r.z+=o.target[2],r.count+=1):n.set(o.key,{x:o.target[0],y:o.target[1],z:o.target[2],count:1})}let t=new Map;for(let[o,r]of n)t.set(o,[r.x/r.count,r.y/r.count,r.z/r.count]);return t}function Kp(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o].vertices,i=n[o]?.vertices;if(!i||i.length!==r.length)continue;for(let c=0;c<r.length;c++)t.push({key:an(r[c]),target:i[c]});let s=e[o].textureTriangles??[],a=n[o]?.textureTriangles??[];for(let c=0;c<s.length;c++){let l=a[c];if(l)for(let u=0;u<s[c].vertices.length;u++)t.push({key:an(s[c].vertices[u]),target:l.vertices[u]})}}return t}function Zp(e,n){let t=[];for(let o of e)for(let r of o.textureTriangles??[])for(let i of r.vertices)t.push({key:an(i),target:yi(i,n)});return t}function yc(e,n){return e.map(t=>{let o=!1,r=a=>{let c=n.get(an(a));return c?(o=!0,c):a},i=t.vertices.map(r),s=mi(t.textureTriangles,r);return o?{...t,vertices:i,...s?{textureTriangles:s}:{}}:t})}function qp(e,n,t,o){let r=t[e],i=t[n],s=o[e],a=o[n];if(!s||!a||r.vertices.length!==3||i.vertices.length!==3||!mg(r,i,s,a))return null;let c=gi(r,i);if(!c)return null;let[l,u,f,d]=c;if((f+1)%i.vertices.length===d)return null;let p=Math.abs(nn(s.normal,a.normal)),g=Math.cos(Bd*Math.PI/180);if(p<g)return null;let h=(u+1)%r.vertices.length,y=3-f-d,b=[r.vertices[u],r.vertices[h],r.vertices[l],i.vertices[y]],x=Qp(b);if(!x)return null;let P=0,M=0;for(let S of b){let T=Math.abs(hi(S,x));P=Math.max(P,T),M+=T*T}if(P>kd)return null;let C=b.map(S=>yi(S,x));if(!Jp(C,x.normal))return null;let E=di({vertices:C});if(!E||nn(E.normal,s.normal)<.2||nn(E.normal,a.normal)<.2)return null;let A={vertices:b,color:r.color,...r.doubleSided?{doubleSided:!0}:{},...r.data?{data:{...r.data}}:{}};if(pi(r,i)&&r.uvs&&i.uvs&&r.texture){A.texture=r.texture,r.textureWrap&&(A.textureWrap={...r.textureWrap}),r.textureAlphaMode&&(A.textureAlphaMode=r.textureAlphaMode),A.uvs=[[...r.uvs[u]],[...r.uvs[h]],[...r.uvs[l]],[...i.uvs[y]]];let S=ng([r,i]);S?.length&&(A.textureTriangles=S)}return{normalDot:p,maxDistance:P,candidate:{a:e,b:n,polygon:A,vertexMoves:[...b.map((S,T)=>({key:an(S),target:C[T]})),...Zp([r,i],x)],score:M/b.length+P*.25+(1-p)*.1}}}function Qp(e){if(e.length<3)return null;let n=0,t=0,o=0,r=0,i=0,s=0;for(let c=0;c<e.length;c++){let l=e[c],u=e[(c+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),t+=(l[2]-u[2])*(l[0]+u[0]),o+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],i+=l[1],s+=l[2]}let a=vc([n,t,o]);return a?{normal:a,point:[r/e.length,i/e.length,s/e.length]}:null}function Jp(e,n){let t=0;for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=e[(o+2)%e.length],a=nn(Tc(Cn(i,r),Cn(s,i)),n);if(Math.abs(a)<=1e-9)continue;let c=a>0?1:-1;if(t===0)t=c;else if(t!==c)return!1}return!0}function eg(e,n,t){let o=gc(e,t),r=ag(o,n);if(r<=0)return o;let i=o.map(m=>{let p=di(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Mc(m)}:null}),s=ug(o,i),a=new Set,c=Array(o.length),l=[],u=(m,p)=>{c[m]=p};for(let m=0;m<o.length;m++){let p=i[m];if(a.has(m))continue;if(!p){u(m,o[m]);continue}let g=dg(m,i,s,a,r,n);for(let y of g)a.add(y);if(g.length<2){u(m,o[m]);continue}let h=rg(g,o,i,s,r,n);l.push(...h.vertexMoves);for(let y of g)u(y,h.polygons.get(y)??o[y])}let f=c.flatMap(m=>m?[m]:[]),d=l.length>0?yc(f,hc(l)):f;return ko(d)}function ko(e){let n=Pc(e),t=1e-4;if(n<=0)return e;let o=cg(n),r=lg(t),i=!1,s=e.map(a=>{let c=!1,l=p=>{let g=o.snap(p);return Yt(g,p)||(c=!0),g},u=a.vertices.map(l),f=a.uvs&&a.uvs.length===a.vertices.length?a.uvs.map(p=>{let g=r.snap(p);return jt(g,p)||(c=!0),g}):void 0,d=mi(a.textureTriangles,l);if(!c&&!a.texture)return a;let m={...a,vertices:u,...f?{uvs:f}:{},...d?{textureTriangles:d}:{}};return i=!0,{...m,...m.texture?{textureTriangles:bc(m)}:{}}});return i?s:e}function bc(e){if(e.texture){if(e.textureTriangles?.length)return og(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return tg(e.vertices,e.uvs)}}function ng(e){let n=e.flatMap(t=>bc(t)??[]);return n.length>0?n:void 0}function tg(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function og(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function mi(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(o=>[...o])}))}function rg(e,n,t,o,r,i){let s=xc(e,n,t,r,i);return s?sg(s):ig(e,n,t,o,r,i)}function ig(e,n,t,o,r,i){let s=new Set(e),a=[];for(let f of e)for(let d of o.get(f)??[]){if(f>=d||!s.has(d))continue;let m=xc([f,d],n,t,r,i);m&&a.push(m)}a.sort((f,d)=>d.score-f.score);let c=new Set,l=new Map,u=[];for(let f of a)if(!f.indices.some(d=>c.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];c.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function sg(e){let n=new Map;for(let t=0;t<e.indices.length;t++)n.set(e.indices[t],e.source[t]);return{polygons:n,vertexMoves:e.vertexMoves}}function xc(e,n,t,o,r){let i=Sc(e,t);if(!i||!Ac(e,t,i,o,r))return null;let s=e.map(u=>n[u]),a=s.map(u=>hg(u,i)),c=Hn(fn(s)),l=Hn(fn(a));return l>=c?null:{indices:e,source:s,projected:a,vertexMoves:Kp(s,a),score:c-l}}function ag(e,n){return Pc(e)<=0?0:n.maxPlaneDisplacement}function Pc(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let c of e)for(let[l,u,f]of c.vertices)n=Math.min(n,l),t=Math.min(t,u),o=Math.min(o,f),r=Math.max(r,l),i=Math.max(i,u),s=Math.max(s,f);if(!Number.isFinite(n))return 0;let a=Math.hypot(r-n,i-t,s-o);return a<=0?0:Math.min(.025,Math.max(1e-4,a*25e-5))}function cg(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i,s)=>`${r},${i},${s}`;return{snap(r){let i=t(r[0]),s=t(r[1]),a=t(r[2]);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)for(let m=-1;m<=1;m++){let p=n.get(o(i+f,s+d,a+m));if(p){for(let g of p)if(Ec(r,g)<=e)return[g[0],g[1],g[2]]}}let c=[r[0],r[1],r[2]],l=o(i,s,a),u=n.get(l);return u?u.push(c):n.set(l,[c]),c}}}function lg(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i)=>`${r},${i}`;return{snap(r){let i=t(r[0]),s=t(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(o(i+u,s+f));if(d){for(let m of d)if(Math.hypot(r[0]-m[0],r[1]-m[1])<=e)return[m[0],m[1]]}}let a=[r[0],r[1]],c=o(i,s),l=n.get(c);return l?l.push(a):n.set(c,[a]),a}}}function Mc(e){return[e.color??"#cccccc",e.texture??"",e.texture&&e.textureWrap?`${e.textureWrap.s}/${e.textureWrap.t}`:"",e.texture&&e.textureAlphaMode?e.textureAlphaMode:"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided"].join("|")}function di(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0,i=n[0];for(let a=1;a<n.length-1;a++){let c=Cn(n[a],i),l=Cn(n[a+1],i),u=Tc(c,l);t+=u[0],o+=u[1],r+=u[2]}let s=Math.hypot(t,o,r);return s<=1e-10?null:{normal:[t/s,o/s,r/s],area:s/2}}function ug(e,n){let t=new Map,o=new Map;for(let r=0;r<e.length;r++){let i=e[r];if(!(!n[r]||i.vertices.length<3))for(let s=0;s<i.vertices.length;s++){let a=Wt(i.vertices[s],i.vertices[(s+1)%i.vertices.length]),c=t.get(a);c?c.push(r):t.set(a,[r])}}for(let r of t.values())for(let i=0;i<r.length;i++)for(let s=i+1;s<r.length;s++){let a=r[i],c=r[s];fg(e[a],e[c],n[a],n[c])&&(lc(o,a,c),lc(o,c,a))}return o}function fg(e,n,t,o){if(!t||!o||t.materialKey!==o.materialKey||!!e.uvs!=!!n.uvs)return!1;if(zo(e)||zo(n))return pi(e,n);if(!e.uvs||!n.uvs)return!0;let r=gi(e,n);if(!r)return!1;let[i,s,a,c]=r;return jt(e.uvs[i],n.uvs[a])&&jt(e.uvs[s],n.uvs[c])}function mg(e,n,t,o){return t.materialKey!==o.materialKey?!1:zo(e)||zo(n)?pi(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function zo(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function pi(e,n){if(!e.texture||!n.texture||e.texture!==n.texture||(e.textureWrap?.s??"")!==(n.textureWrap?.s??"")||(e.textureWrap?.t??"")!==(n.textureWrap?.t??"")||(e.textureAlphaMode??"")!==(n.textureAlphaMode??"")||e.material?.texture||n.material?.texture||!e.uvs||!n.uvs||e.uvs.length!==e.vertices.length||n.uvs.length!==n.vertices.length)return!1;let t=gi(e,n);if(!t)return!1;let[o,r,i,s]=t;return jt(e.uvs[o],n.uvs[i])&&jt(e.uvs[r],n.uvs[s])}function lc(e,n,t){let o=e.get(n);o?o.add(t):e.set(n,new Set([t]))}function dg(e,n,t,o,r,i){let s=[e],a=new Set([e]),c=[e];for(;c.length>0;){let l=c.shift();for(let u of t.get(l)??[]){if(o.has(u)||a.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&pg([...s,u],n,r,i)&&(s.push(u),a.add(u),c.push(u))}}return s}function pg(e,n,t,o){let r=Sc(e,n);return!!r&&Ac(e,n,r,t,o)}function Sc(e,n){let t=n[e[0]];if(!t)return null;let o=0,r=0,i=0,s=0,a=0,c=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let g=nn(t.normal,p.normal)<0?-1:1,h=Math.max(p.area,1e-6);o+=p.normal[0]*g*h,r+=p.normal[1]*g*h,i+=p.normal[2]*g*h;for(let y of p.polygon.vertices)s+=y[0],a+=y[1],c+=y[2],l+=1}let u=vc([o,r,i]);if(!u||l===0)return null;let f=Cc(e,n),d=gg(e,n,u,f);if(d){let m=(d.min+d.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m],boundaryVertexKeys:f}}return{normal:u,point:[s/l,a/l,c/l],boundaryVertexKeys:f}}function gg(e,n,t,o){let r=1/0,i=-1/0;for(let s of e){let a=n[s];if(a)for(let c of a.polygon.vertices){if(!o.has(an(c)))continue;let l=nn(c,t);r=Math.min(r,l),i=Math.max(i,l)}}return Number.isFinite(r)&&Number.isFinite(i)?{min:r,max:i}:null}function Ac(e,n,t,o,r){let i=Math.cos(r.maxAngleDeg*Math.PI/180),s=t.boundaryVertexKeys??Cc(e,n);for(let a of e){let c=n[a];if(!c||Math.abs(nn(c.normal,t.normal))<i)return!1;for(let l of c.polygon.vertices){let u=s.has(an(l))?r.maxBoundaryDisplacement:o;if(Math.abs(hi(l,t))>u)return!1}}return!0}function Cc(e,n){let t=new Map;for(let r of e){let i=n[r];if(!i)continue;let s=i.polygon.vertices;for(let a=0;a<s.length;a++){let c=s[a],l=s[(a+1)%s.length],u=Wt(c,l),f=t.get(u);f?f.count+=1:t.set(u,{count:1,a:c,b:l})}}let o=new Set;for(let r of t.values())r.count===1&&(o.add(an(r.a)),o.add(an(r.b)));return o}function hg(e,n){let t=r=>yi(r,n),o=mi(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...o?{textureTriangles:o}:{}}}function gi(e,n){for(let t=0;t<e.vertices.length;t++){let o=(t+1)%e.vertices.length;for(let r=0;r<n.vertices.length;r++){let i=(r+1)%n.vertices.length;if(Yt(e.vertices[t],n.vertices[r])&&Yt(e.vertices[o],n.vertices[i]))return[t,o,r,i];if(Yt(e.vertices[t],n.vertices[i])&&Yt(e.vertices[o],n.vertices[r]))return[t,o,i,r]}}return null}function Wt(e,n){let t=an(e),o=an(n);return t<o?`${t}|${o}`:`${o}|${t}`}function an(e){return`${e[0]},${e[1]},${e[2]}`}function Yt(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function jt(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function Cn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Tc(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function nn(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Ec(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function vc(e){let n=Math.hypot(e[0],e[1],e[2]);return n<=1e-10?null:[e[0]/n,e[1]/n,e[2]/n]}function hi(e,n){return nn(Cn(e,n.point),n.normal)}function yi(e,n){let t=hi(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var yg=36,bg=.15,xg=.2,Pg=650,Mg=15e3,Sg=.25;function bi(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function Ic(e){let n=Vn(e);return!n||n.alpha<1?e.trim().toLowerCase():`#${n.rgb.map(t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")).join("")}`}function Ag(e){let n=Vn(e);return n?{rgb:[Math.max(0,Math.min(255,Math.round(n.rgb[0]))),Math.max(0,Math.min(255,Math.round(n.rgb[1]))),Math.max(0,Math.min(255,Math.round(n.rgb[2])))],alpha:n.alpha}:null}function Cg(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function _c(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),i=Math.min(n,t,o),s=r-i,a=0;return s!==0&&(r===n?a=60*((t-o)/s%6):r===t?a=60*((o-n)/s+2):a=60*((n-t)/s+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:s/r,value:r}}function Tg(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function Eg(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=_c(e),o=_c(n),r=t.saturation<.08,i=o.saturation<.08;if(r||i)return r===i;let s=Math.min(t.value,o.value)<.18?32:18;return Tg(t.hue,o.hue)<=s}function vg(e,n){let t=new Map;for(let s of e.keys()){let a=Ag(s);a&&t.set(s,a)}let o=[],r=new Map,i=Array.from(e.entries()).sort((s,a)=>a[1]-s[1]||s[0].localeCompare(a[0]));for(let[s]of i){let a=t.get(s);if(!a){r.set(s,s);continue}let c=null;for(let l of o){if(!Eg(a,l.parsed))continue;let u=Cg(a,l.parsed);u>n||(!c||u<c.distance)&&(c={color:l.color,distance:u})}c?r.set(s,c.color):(o.push({color:s,parsed:a}),r.set(s,s))}return r}function Ig(e,n,t){if(t!=="lossy"||e.animation)return e;let o=n.source;if(!o||o.polygons===e.polygons)return e;let r=n.bakedTextureColorMergeDistance??yg;if(!Number.isFinite(r)||r<=0)return e;let i=new Map,s=[];for(let u=0;u<e.polygons.length;u+=1){let f=o.polygons[u],d=e.polygons[u];if(!f||!d||f===d||!d.color||!bi(f)||bi(d))continue;let m=Ic(d.color);s.push(u),i.set(m,(i.get(m)??0)+1)}if(i.size<2)return e;let a=vg(i,r),c=!1,l=e.polygons.slice();for(let u of s){let f=l[u],d=Ic(f.color),m=a.get(d)??d;m!==d&&(l[u]={...f,color:m},c=!0)}return c?{...e,polygons:l}:e}function _g(e){let n=0;for(let t of e)bi(t)&&(n+=1);return e.length===0||n/e.length<=Sg}function Vg(e){return!!e.metadata?.stlTopology}function Og(e,n){return n?Math.max(e.simplifyEarlyStopDropRatio??bg,xg):e.simplifyEarlyStopDropRatio}function ut(e,n={}){return new xi(e,n).optimize()}var xi=class{constructor(n,t){this.result=n,this.options=t,this.meshResolution=t.meshResolution??"lossy"}optimize(){if(this.result.voxelSource||this.result.animation)return this.result;let n=Ig(this.result,this.options,this.meshResolution),t=Vg(n),o=t?"lossless":this.meshResolution,r=this.canSimplify(n.polygons,o),i=r&&n.polygons.length>=Pg&&n.polygons.length<=Mg,s=uc(n.polygons,{meshResolution:o,useCandidateFirst:i,staticSimplification:r?{simplifyTriangleMeshOptions:this.options.simplifyTriangleMeshOptions,earlyStopDropRatio:Og(this.options,i)}:!1,skipInteriorCull:t});return s===n.polygons?n:{...n,polygons:s}}canSimplify(n,t){return t==="lossy"&&this.options.simplifyTriangleMeshes!==!1&&_g(n)}};function Rg(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[O,L,D]of n)t+=O,o+=L,r+=D;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let x=n.length-2,P=new Float64Array(x*9),M=0;for(let O=1;O<n.length-1;O++){let L=n[0],D=n[O],_=n[O+1];P[M++]=L[0],P[M++]=L[1],P[M++]=L[2],P[M++]=D[0],P[M++]=D[1],P[M++]=D[2],P[M++]=_[0],P[M++]=_[1],P[M++]=_[2]}let C=0,E=1/0,A=1/0,S=1/0,T=-1/0,v=-1/0,R=-1/0;for(let[O,L,D]of n){let _=O-t,w=L-o,V=D-r,j=_*_+w*w+V*V;j>C&&(C=j),O<E&&(E=O),O>T&&(T=O),L<A&&(A=L),L>v&&(v=L),D<S&&(S=D),D>R&&(R=D)}return{centroid:[t,o,r],normal:[g,h,y],triFlat:P,bcx:t,bcy:o,bcz:r,br2:C,minX:E,minY:A,minZ:S,maxX:T,maxY:v,maxZ:R}}function Lg(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function wg(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(Lg(e,n,t,o,r,i,p,h))return!0;return!1}var Ht=9,Ng=6,Ke=12;function Pi(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function Dg(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*Ht),l=0,u=new Float64Array(Ke),f=new Float64Array(Ke),d=new Float64Array(Ke),m=new Float64Array(Ke),p=new Float64Array(Ke),g=new Float64Array(Ke),h=new Int32Array(Ke),y=new Float64Array(Ke-1),b=new Int32Array(Ke-1),x=new Float64Array(Ke-1),P=new Int32Array(Ke-1);function M(C,E){let A=l++,S=A*Ht,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=Ng)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=Pi(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ae=Ke/le;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),g.fill(-1/0),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ae|0;oe>=Ke&&(oe=Ke-1);let de=e[o[K]];de.minX<u[oe]&&(u[oe]=de.minX),de.maxX>m[oe]&&(m[oe]=de.maxX),de.minY<f[oe]&&(f[oe]=de.minY),de.maxY>p[oe]&&(p[oe]=de.maxY),de.minZ<d[oe]&&(d[oe]=de.minZ),de.maxZ>g[oe]&&(g[oe]=de.maxZ),h[oe]++}let _e=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<Ke-1;K++)u[K]<_e&&(_e=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=Pi(_e,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=Ke-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=Pi(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<Ke-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ae)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*Ht+7]=ae,c[A*Ht+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function Fg(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*Ht,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&wg(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function Bg(e,n,t){let o=new Set;if(e.length<2)return o;let r=Math.hypot(n[0],n[1],n[2]);if(r<1e-9)return o;let i=n[0]/r,s=n[1]/r,a=n[2]/r,c=e.map(Rg);if(t&&t.size>0)for(let f of t)c[f]=null;let l=Dg(c),u=new Int32Array(Math.max(64,l.nodeCount));for(let f=0;f<e.length;f++){let d=c[f];if(!d)continue;let m=d.centroid[0]+d.normal[0]*.001,p=d.centroid[1]+d.normal[1]*.001,g=d.centroid[2]+d.normal[2]*.001;d.normal[0]*i+d.normal[1]*s+d.normal[2]*a<=0||Fg(m,p,g,i,s,a,f,l,u)&&o.add(f)}return o}var Uo=1e-5,Vc=.001,Oc=6;function Mi(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let a=1;a+1<n.length;a++){let c=n[a],l=n[a+1],u=c[1]-t[1],f=c[0]-t[0],d=c[2]-t[2],m=l[1]-t[1],p=l[0]-t[0],g=l[2]-t[2];o-=f*g-d*p,r-=d*m-u*g,i-=u*p-f*m}let s=Math.hypot(o,r,i);return s<1e-9?null:[o/s,r/s,i/s]}function Rc(e,n){let t=n.meshRotation,o=t?Un(e,t):e;return vr(o,n.rotX,0,n.rotY)[2]}function Kt(e,n,t=Uo){return Rc(e,n)>t}function kg(e,n,t=Uo){let o=Mi(e);return o===null||Kt(o,n,t)}function Lc(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function wc(e){let n=new Map;for(let t of e){if(!t)continue;let o=Lc(t);n.has(o)||n.set(o,t)}return Array.from(n,([t,o])=>({key:t,normal:o}))}function zg(e){return wc(e.map(Mi))}function Nc(e,n=Vc){let t=Math.abs(e[0]),o=Math.abs(e[1]),r=Math.abs(e[2]),i=Math.max(t,o,r);return i>1-n&&t+o+r-i<n}function Ug(e){return e.length<=Oc&&e.every(({normal:n})=>Nc(n))}function Gg(e,n,t=Uo){let o=[];for(let{key:r,normal:i}of e)Kt(i,n,t)&&o.push(r);return o.sort(),o.join("|")}function Si(e,n,t,o,r){let i=(p,g,h)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=g,y[(e+2)%3]=h,y},s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function Dc(e={}){let n=e.size??5,t=e.thickness??.025,o=e.negative??!1,r=e.xColor??"#ff3a3a",i=e.yColor??"#3aff3a",s=e.zColor??"#3a8aff",a=n*t/2,c=o?-n:0;return[...Si(0,c,n,a,r),...Si(1,c,n,a,i),...Si(2,c,n,a,s)]}var $g=["right","left","front","back","top","bottom"];function Ai(e){return[e[0],e[1],e[2]]}function Fc(e,n){return{min:[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.min(e[2],n[2])],max:[Math.max(e[0],n[0]),Math.max(e[1],n[1]),Math.max(e[2],n[2])]}}function Xg(e){if(e.min&&e.max)return Fc(e.min,e.max);let n=e.center?Ai(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=Ai(e.size):t=[1,1,1];let o=[t[0]/2,t[1]/2,t[2]/2];return Fc([n[0]-o[0],n[1]-o[1],n[2]-o[2]],[n[0]+o[0],n[1]+o[1],n[2]+o[2]])}function Yg(e,n){let[t,o,r]=e,[i,s,a]=n;return[{name:"right",vertices:[[i,o,r],[i,s,r],[i,s,a],[i,o,a]]},{name:"left",vertices:[[t,s,r],[t,o,r],[t,o,a],[t,s,a]]},{name:"front",vertices:[[i,s,r],[t,s,r],[t,s,a],[i,s,a]]},{name:"back",vertices:[[t,o,r],[i,o,r],[i,o,a],[t,o,a]]},{name:"top",vertices:[[t,o,a],[i,o,a],[i,s,a],[t,s,a]]},{name:"bottom",vertices:[[t,s,r],[i,s,r],[i,o,r],[t,o,r]]}]}function jg(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function Wg(e,n){let t={vertices:e.vertices.map(Ai)};return n.color!==void 0&&(t.color=n.color),n.texture!==void 0&&(t.texture=n.texture),n.material!==void 0&&(t.material=n.material),n.uvs!==void 0&&(t.uvs=n.uvs.map(o=>[o[0],o[1]])),n.data!==void 0&&(t.data={...n.data}),t}function Bc(e={}){let{min:n,max:t}=Xg(e);if(n[0]===t[0]||n[1]===t[1]||n[2]===t[2])return[];let o={color:e.color??"#ffffff",texture:e.texture,material:e.material,uvs:e.uvs,data:e.data},r=Yg(n,t),i=new Map(r.map(a=>[a.name,a])),s=[];for(let a of $g){let c=e.faces?.[a];if(c===!1)continue;let l=i.get(a);l&&s.push(Wg(l,jg(o,c)))}return s}function kc(e,n,t,o){let r=[0,0,0];return r[e]=n,r[(e+1)%3]=t,r[(e+2)%3]=o,r}function Hg(e,n,t,o,r){let i=(p,g,h)=>kc(e,p,g,h),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function Kg(e,n,t,o,r){let i=(f,d,m)=>kc(e,f,d,m),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,0,0);return[{vertices:[s,a,c,l],color:r},{vertices:[s,a,u],color:r},{vertices:[a,c,u],color:r},{vertices:[c,l,u],color:r},{vertices:[l,s,u],color:r}]}function Zg(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function zc(e){let n=e.axis,t=e.sign??1,o=e.shaftLength??4,r=e.shaftHalfThickness??.05,i=e.headLength??.8,s=e.headHalfThickness??.2,a=e.color??"#ffffff",c=e.shaft??!0,l=o*t,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(o+i)*t,p=Kg(n,d,m,s,a),g=t===-1?Zg(p):p;return c?[...Hg(n,u,f,r,a),...g]:g}function Go(e,n,t){let o=[0,0,0],r=(e+1)%3,i=(e+2)%3;return o[r]=Math.cos(t)*n,o[i]=Math.sin(t)*n,o}function Uc(e){let n=e.axis,t=e.radius,o=e.halfThickness??Math.max(.05,t*.04),r=e.segments??32,i=e.color??"#ffffff",s=t-o,a=t+o,c=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=Go(n,s,u),m=Go(n,s,f),p=Go(n,a,u),g=Go(n,a,f);c.push({vertices:[d,p,g,m],color:i})}return c}function Gc(e){let n=e.axis,t=e.outerRadius,o=e.color??"#ffffff",r=(n+1)%3,i=(n+2)%3,s=(a,c)=>{let l=[0,0,0];return l[n]=0,l[r]=a,l[i]=c,l};return[{vertices:[s(-t,-t),s(t,-t),s(t,t),s(-t,t)],color:o}]}function $c(e){let n=e.axis,t=e.size??.4,o=e.offset??t*2,r=typeof o=="number"?o:o[0],i=typeof o=="number"?o:o[1],s=e.along??0,a=e.color??"#ffffff",c=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=s,m[c]=r+f,m[l]=i+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:a}]}function Xc(e){let{center:n,size:t,color:o="#ffffff"}=e,[r,i,s]=n,a=[[r+t,i,s],[r-t,i,s],[r,i+t,s],[r,i-t,s],[r,i,s+t],[r,i,s-t]];return[[0,2,4],[2,1,4],[1,3,4],[3,0,4],[2,0,5],[1,2,5],[3,1,5],[0,3,5]].map(l=>({vertices:[a[l[0]],a[l[1]],a[l[2]]],color:o}))}function Yc(e={}){let{radius:n=50,color:t="#cccccc"}=e,o=Math.min(Math.max(0,Math.floor(e.subdivisions??1)),3),r=(1+Math.sqrt(5))/2,i=[[-1,r,0],[1,r,0],[-1,-r,0],[1,-r,0],[0,-1,r],[0,1,r],[0,-1,-r],[0,1,-r],[r,0,-1],[r,0,1],[-r,0,-1],[-r,0,1]].map(([c,l,u])=>{let f=Math.sqrt(c*c+l*l+u*u);return[c/f,l/f,u/f]}),s=[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]];for(let c=0;c<o;c++){let l=[...i],u=[],f=new Map,d=(m,p)=>{let g=m<p?`${m}-${p}`:`${p}-${m}`,h=f.get(g);if(h!==void 0)return h;let y=i[m],b=i[p],x=(y[0]+b[0])/2,P=(y[1]+b[1])/2,M=(y[2]+b[2])/2,C=Math.sqrt(x*x+P*P+M*M);x/=C,P/=C,M/=C;let E=l.length;return l.push([x,P,M]),f.set(g,E),E};for(let[m,p,g]of s){let h=d(m,p),y=d(p,g),b=d(g,m);u.push([m,h,b]),u.push([p,y,h]),u.push([g,b,y]),u.push([h,y,b])}i=l,s=u}let a=i.map(([c,l,u])=>[c*n,l*n,u*n]);return s.map(([c,l,u])=>({vertices:[a[c],a[l],a[u]],color:t}))}function jc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=n/Math.sqrt(3),r=[[o,o,o],[o,-o,-o],[-o,o,-o],[-o,-o,o]];return[[0,1,2],[0,3,1],[0,2,3],[1,3,2]].map(([s,a,c])=>({vertices:[r[s],r[a],r[c]],color:t}))}function Wc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=n/Math.sqrt(1+o*o),i=[[-1,o,0],[1,o,0],[-1,-o,0],[1,-o,0],[0,-1,o],[0,1,o],[0,-1,-o],[0,1,-o],[o,0,-1],[o,0,1],[-o,0,-1],[-o,0,1]].map(([a,c,l])=>[a*r,c*r,l*r]);return[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]].map(([a,c,l])=>({vertices:[i[a],i[c],i[l]],color:t}))}function Hc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=1/o,i=n/Math.sqrt(3),a=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1],[0,r,o],[0,-r,o],[0,r,-o],[0,-r,-o],[r,o,0],[-r,o,0],[r,-o,0],[-r,-o,0],[o,0,r],[o,0,-r],[-o,0,r],[-o,0,-r]].map(([l,u,f])=>[l*i,u*i,f*i]);return[[12,13,4,8,0],[0,8,9,2,16],[16,17,1,12,0],[1,10,5,13,12],[17,3,11,10,1],[2,9,6,15,14],[2,14,3,17,16],[14,15,7,11,3],[18,6,9,8,4],[4,13,5,19,18],[5,10,11,7,19],[18,19,7,15,6]].map(l=>({vertices:l.map(u=>a[u]),color:t}))}function $o(e={}){let{radius:n=50,height:t=100,radialSegments:o=12,color:r="#cccccc"}=e,i=e.radiusTop??n,s=t/2,a=-s,c=s,l=Math.max(3,o),u=[],f=Array.from({length:l+1},(p,g)=>g/l*Math.PI*2),d=n<=1e-6,m=i<=1e-6;for(let p=0;p<l&&!(d&&m);p++){let g=f[p],h=f[p+1],y=Math.cos(g)*n,b=Math.sin(g)*n,x=Math.cos(h)*n,P=Math.sin(h)*n,M=Math.cos(g)*i,C=Math.sin(g)*i,E=Math.cos(h)*i,A=Math.sin(h)*i,S=[y,b,a],T=[x,P,a],v=[E,A,c],R=[M,C,c];if(m){let O=[0,0,c];u.push({vertices:[S,T,O],color:r})}else if(d){let O=[0,0,a];u.push({vertices:[O,v,R],color:r})}else u.push({vertices:[S,T,v,R],color:r})}if(n>1e-6){let p=[0,0,a];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*n,Math.sin(h)*n,a],x=[Math.cos(y)*n,Math.sin(y)*n,a];u.push({vertices:[[...p],[...x],[...b]],color:r})}}if(i>1e-6){let p=[0,0,c];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*i,Math.sin(h)*i,c],x=[Math.cos(y)*i,Math.sin(y)*i,c];u.push({vertices:[[...p],[...b],[...x]],color:r})}}return u}function Kc(e={}){return $o({...e,radiusTop:0})}function Xo(e,n,t,o){let r=Math.sin(e),i=Math.cos(e),s=Math.sin(n),a=Math.cos(n);return[(t+o*a)*i,(t+o*a)*r,o*s]}function Zc(e={}){let{radius:n=50,tube:t=15,radialSegments:o=12,tubularSegments:r=16,color:i="#cccccc"}=e,s=Math.max(3,o),a=Math.max(3,r),c=[];for(let l=0;l<s;l++){let u=l/s*Math.PI*2,f=(l+1)/s*Math.PI*2;for(let d=0;d<a;d++){let m=d/a*Math.PI*2,p=(d+1)/a*Math.PI*2,g=Xo(u,m,n,t),h=Xo(f,m,n,t),y=Xo(f,p,n,t),b=Xo(u,p,n,t);c.push({vertices:[g,h,y,b],color:i})}}return c}var qg=.01,Qg=.01;function Jg(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,o=e[0]/t,r=e[1]/t,i=e[2]/t,s=Math.sign(i||1)*Math.max(Math.abs(i),.01),a=n,c=.01;return[1,0,0,0,0,1,0,0,-o/s,-r/s,c,0,a*o/s,a*r/s,a*(1-c),1]}function e0(e,n,t){let o=e[2]-n[2];if(Math.abs(o)<1e-9)return null;let r=(t-e[2])/o;return r<0?null:[e[0]+r*(e[0]-n[0]),e[1]+r*(e[1]-n[1])]}function n0(e,n,t){let o=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],s=Math.hypot(o,r,i)||1;return(n[0]*o+n[1]*r+n[2]*i)/s>0}function t0(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e[0]*o+e[1]*r+e[2]*i>0}function Ci(e){if(e.length<=1)return e.map(s=>[s[0],s[1]]);let t=e.map(s=>[s[0],s[1]]);t.sort((s,a)=>s[0]-a[0]||s[1]-a[1]);let o=(s,a,c)=>(a[0]-s[0])*(c[1]-s[1])-(a[1]-s[1])*(c[0]-s[0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function qc(e){let n=0,t=e.length;for(let o=0;o<t;o++){let r=e[o],i=e[(o+1)%t];n+=r[0]*i[1]-i[0]*r[1]}return n/2}function Tn(e){let n=e.map(t=>[t[0],t[1]]);return qc(n)<0&&n.reverse(),n}function o0(e,n,t){let o=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/o,i=n[1]/o,s=n[2]/o,a=Math.sign(s||1)*Math.max(Math.abs(s),.01),c=e[2]-t;return[e[0]-r/a*c,e[1]-i/a*c]}function Qc(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}function r0(e){if(e.length<3)return e.map((s,a)=>a);let t=e.map((s,a)=>a).sort((s,a)=>e[s][0]-e[a][0]||e[s][1]-e[a][1]),o=(s,a,c)=>(e[a][0]-e[s][0])*(e[c][1]-e[s][1])-(e[a][1]-e[s][1])*(e[c][0]-e[s][0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function Ti(e,n,t){if(e.length<3)return null;let o=Qc(n),r=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],i=r[0]*o[0]+r[1]*o[1]+r[2]*o[2],s=Qc([r[0]-i*o[0],r[1]-i*o[1],r[2]-i*o[2]]),a=[o[1]*s[2]-o[2]*s[1],o[2]*s[0]-o[0]*s[2],o[0]*s[1]-o[1]*s[0]],c=e.map(f=>[f[0]*s[0]+f[1]*s[1]+f[2]*s[2],f[0]*a[0]+f[1]*a[1]+f[2]*a[2]]),l=r0(c);if(l.length<3)return null;let u=Math.max(3,Math.floor(t));if(l.length>u){let f=(d,m,p)=>{let g=c[d][0],h=c[d][1];return Math.abs((c[m][0]-g)*(c[p][1]-h)-(c[p][0]-g)*(c[m][1]-h))*.5};for(;l.length>u;){let d=1/0,m=0;for(let p=0;p<l.length;p++){let g=f(l[(p-1+l.length)%l.length],l[p],l[(p+1)%l.length]);g<d&&(d=g,m=p)}l.splice(m,1)}}return l.map(f=>[e[f][0],e[f][1],e[f][2]])}function Jc(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}var i0=[[],[3,0],[0,1],[3,1],[1,2],[3,0,1,2],[0,2],[3,2],[2,3],[2,0],[0,1,2,3],[2,1],[1,3],[1,0],[0,3],[]];function s0(e,n){if(e.length<4)return e;let t=1,o=-1;for(let u=0;u<e.length;u++){let f=e[u][0]-e[0][0],d=e[u][1]-e[0][1],m=f*f+d*d;m>o&&(o=m,t=u)}let r=u=>{if(u.length<3)return u;let f=u[0],d=u[u.length-1],m=-1,p=n,g=d[0]-f[0],h=d[1]-f[1],y=Math.hypot(g,h)||1;for(let b=1;b<u.length-1;b++){let x=Math.abs((u[b][0]-f[0])*h-(u[b][1]-f[1])*g)/y;x>p&&(p=x,m=b)}return m<0?[f,d]:[...r(u.slice(0,m+1)).slice(0,-1),...r(u.slice(m))]},i=e.slice(0,t+1),s=[...e.slice(t),e[0]],a=r(i),c=r(s),l=[...a.slice(0,-1),...c.slice(0,-1)];return l.length>=3?l:e}function a0(e,n,t){let o=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let s=t[r][0],a=t[r][1],c=t[i][0],l=t[i][1];a>n!=l>n&&e<(c-s)*(n-a)/(l-a)+s&&(o=!o)}return o}function Ei(e,n,t,o=1,r="contour"){let i=Jc(n),s=Math.abs(i[0])<.9?[1,0,0]:[0,1,0],a=s[0]*i[0]+s[1]*i[1]+s[2]*i[2],c=Jc([s[0]-a*i[0],s[1]-a*i[1],s[2]-a*i[2]]),l=[i[1]*c[2]-i[2]*c[1],i[2]*c[0]-i[0]*c[2],i[0]*c[1]-i[1]*c[0]],u=1/0,f=1/0,d=-1/0,m=-1/0,p=1/0,g=-1/0,h=[];for(let D of e){if(D.length<3)continue;let _=[],w=0;for(let V of D){let j=V[0]*c[0]+V[1]*c[1]+V[2]*c[2],G=V[0]*l[0]+V[1]*l[1]+V[2]*l[2],Z=V[0]*i[0]+V[1]*i[1]+V[2]*i[2];_.push([j,G]),w+=Z,j<u&&(u=j),j>d&&(d=j),G<f&&(f=G),G>m&&(m=G),Z<p&&(p=Z),Z>g&&(g=Z)}h.push({pts:_,depth:w/D.length})}if(!Number.isFinite(u)||h.length===0)return null;let y=d-u,b=m-f,x=Math.max(y,b);if(x<1e-6)return null;let P=Math.max(r==="pixel"?3:8,Math.min(384,Math.round(t*(r==="pixel"?1:2)))),M=x/P,C=1,E=u-C*M,A=f-C*M,S=Math.ceil(y/M)+2*C+1,T=Math.ceil(b/M)+2*C+1;if(S*T>4e5)return null;let v=.6,R=(D,_,w)=>{let V=new Uint8Array(S*T),j=(I,B)=>I<0||B<0||I>=S||B>=T?0:V[B*S+I],G=(I,B,N,H,$,k)=>(N-I)*(k-B)-(H-B)*($-I);for(let I of D){let B=I.pts;for(let N=1;N<B.length-1;N++){let H=B[0],$=B[N],k=B[N+1],Q=Math.floor((Math.min(H[0],$[0],k[0])-E)/M),ae=Math.ceil((Math.max(H[0],$[0],k[0])-E)/M),se=Math.floor((Math.min(H[1],$[1],k[1])-A)/M),Y=Math.ceil((Math.max(H[1],$[1],k[1])-A)/M);if(Q<0&&(Q=0),ae>S-1&&(ae=S-1),se<0&&(se=0),Y>T-1&&(Y=T-1),!(Math.abs(G(H[0],H[1],$[0],$[1],k[0],k[1]))<1e-12))for(let ne=se;ne<=Y;ne++){let le=A+(ne+.5)*M;for(let ye=Q;ye<=ae;ye++){if(V[ne*S+ye])continue;let Ae=E+(ye+.5)*M,_e=G($[0],$[1],k[0],k[1],Ae,le),Ee=G(k[0],k[1],H[0],H[1],Ae,le),Me=G(H[0],H[1],$[0],$[1],Ae,le);(_e>=0&&Ee>=0&&Me>=0||_e<=0&&Ee<=0&&Me<=0)&&(V[ne*S+ye]=1)}}}}if(r==="pixel"){let I=new Uint8Array(S*T),B=(N,H)=>{let $=E+N*M,k=A+H*M;return[$*c[0]+k*l[0]+_*i[0],$*c[1]+k*l[1]+_*i[1],$*c[2]+k*l[2]+_*i[2]]};for(let N=0;N<T;N++)for(let H=0;H<S;H++){if(!V[N*S+H]||I[N*S+H])continue;let $=1;for(;H+$<S&&V[N*S+H+$]&&!I[N*S+H+$];)$++;let k=1;e:for(;N+k<T;){for(let Q=0;Q<$;Q++)if(!V[(N+k)*S+H+Q]||I[(N+k)*S+H+Q])break e;k++}for(let Q=N;Q<N+k;Q++)for(let ae=H;ae<H+$;ae++)I[Q*S+ae]=1;w.push([B(H,N),B(H+$,N),B(H+$,N+k),B(H,N+k)])}return}let Z=(I,B)=>`${Math.round(I*2)},${Math.round(B*2)}`,ee=new Map,W=new Map,ie=(I,B,N)=>I===0?[B+.5,N]:I===1?[B+1,N+.5]:I===2?[B+.5,N+1]:[B,N+.5],z=(I,B)=>{let N=Z(I[0],I[1]),H=Z(B[0],B[1]);N!==H&&(ee.has(N)||ee.set(N,[]),ee.has(H)||ee.set(H,[]),ee.get(N).push(B),ee.get(H).push(I),W.set(N,I),W.set(H,B))};for(let I=0;I<T-1;I++)for(let B=0;B<S-1;B++){let N=j(B,I)|j(B+1,I)<<1|j(B+1,I+1)<<2|j(B,I+1)<<3,H=i0[N];for(let $=0;$<H.length;$+=2)z(ie(H[$],B,I),ie(H[$+1],B,I))}if(ee.size===0)return;let X=new Set,U=[];for(let I of ee.keys()){if(X.has(I))continue;let B=[],N=I,H="",$=0;for(;N&&!X.has(N)&&$++<1e6;){X.add(N),B.push(W.get(N));let Q=ee.get(N)??[],ae="";for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H&&!X.has(Y)){ae=Y;break}}if(!ae)for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H){ae=Y;break}}if(H=N,N=ae,N===I)break}if(B.length<3)continue;let k=s0(B,v);k.length>=3&&U.push(k)}for(let I of U){let B=0,N=I[0][0],H=I[0][1];for(let se of U)se!==I&&a0(N,H,se)&&B++;let $=B%2===0,k=0;for(let se=0;se<I.length;se++){let Y=I[se],ne=I[(se+1)%I.length];k+=Y[0]*ne[1]-ne[0]*Y[1]}let ae=k>0===$?I:[...I].reverse();w.push(ae.map(se=>{let Y=E+se[0]*M,ne=A+se[1]*M;return[Y*c[0]+ne*l[0]+_*i[0],Y*c[1]+ne*l[1]+_*i[1],Y*c[2]+ne*l[2]+_*i[2]]}))}},O=[],L=Math.max(1,Math.floor(o));if(L<=1||g-p<1e-6){let D=g+(g-p)+x;R(h,D,O)}else{let D=g-p,_=D/L,w=D*.05;for(let V=0;V<L;V++){let j=p+V*_,G=V===L-1?1/0:p+(V+1)*_,Z=h.filter(ee=>ee.depth>=j&&ee.depth<G);Z.length&&R(Z,j-w,O)}}return O.length?O:null}function el(e){let n=0,t=0,o=0,r=0,i=0,s=0,a=0,c=0,l=0,u=!1;for(let y of e)if(y.length>=3&&!u){let b=y[0],x=y[1],P=y[2];n=x[0]-b[0],t=x[1]-b[1],o=x[2]-b[2],r=P[0]-b[0],i=P[1]-b[1],s=P[2]-b[2],a=b[0],c=b[1],l=b[2],u=!0}if(!u)return!0;let f=t*s-o*i,d=o*r-n*s,m=n*i-t*r,p=Math.hypot(f,d,m);if(p<1e-9)return!0;f/=p,d/=p,m/=p;let g=0;for(let y of e)for(let b of y)g=Math.max(g,Math.abs(b[0]-a)+Math.abs(b[1]-c)+Math.abs(b[2]-l));let h=Math.max(.001,g*.001);for(let y of e)for(let b of y){let x=(b[0]-a)*f+(b[1]-c)*d+(b[2]-l)*m;if(Math.abs(x)>h)return!1}return!0}function nl(e,n=300){if(e.length===0||e.length>n)return!1;let t=0,o=0,r=0,i=0,s=!1;for(let c of e)for(let l of c)s||(o=l[0],r=l[1],i=l[2],s=!0),t=Math.max(t,Math.abs(l[0]-o)+Math.abs(l[1]-r)+Math.abs(l[2]-i));let a=Math.max(.001,t*.005);for(let c of e){if(c.length<3)continue;let l=c[0],u=c[1],f=c[2],d=(u[1]-l[1])*(f[2]-l[2])-(u[2]-l[2])*(f[1]-l[1]),m=(u[2]-l[2])*(f[0]-l[0])-(u[0]-l[0])*(f[2]-l[2]),p=(u[0]-l[0])*(f[1]-l[1])-(u[1]-l[1])*(f[0]-l[0]),g=Math.hypot(d,m,p);if(g<1e-9)continue;d/=g,m/=g,p/=g;let h=!1,y=!1;for(let b of e)for(let x of b){let P=(x[0]-l[0])*d+(x[1]-l[1])*m+(x[2]-l[2])*p;if(P>a?h=!0:P<-a&&(y=!0),h&&y)return!1}}return!0}function c0(e){let{polysWorldVerts:n,lightDir:t,definition:o,isSelf:r,style:i,pointLights:s}=e,a=el(n),c=r&&nl(n);if(a||c)return{};let l=r?Math.max(2,Math.min(6,Math.round(o/8))):1,u=i==="pixel"?"pixel":"contour",f=p=>{let g=Ei(n,p,o,l,u);if(g&&g.length)return g;if(!r){let h=[];for(let b of n)for(let x of b)h.push(x);let y=Ti(h,p,o);if(y&&y.length>=3)return[y]}},d=f(t),m;if(s&&s.length>0){let p=0,g=0,h=0,y=0;for(let b of n)for(let x of b)p+=x[0],g+=x[1],h+=x[2],y++;y>0&&(p/=y,g/=y,h/=y),m=[];for(let b of s){let x=[b.position[0]-p,b.position[1]-g,b.position[2]-h];m[b.index]=f(x)}}return{overrideSilhouette:d,overridePointSilhouettes:m}}function Rn(e,n){if(e.length===0||n.length<3)return[];let t=e.map(r=>[r[0],r[1]]),o=n.length;for(let r=0;r<o;r++){if(t.length===0)return[];let i=t;t=[];let s=n[r],a=n[(r+1)%o],c=f=>(a[0]-s[0])*(f[1]-s[1])-(a[1]-s[1])*(f[0]-s[0])>=0,l=(f,d)=>{let m=s[0],p=s[1],g=a[0],h=a[1],y=f[0],b=f[1],x=d[0],P=d[1],M=(m-g)*(b-P)-(p-h)*(y-x);if(Math.abs(M)<1e-12)return[f[0],f[1]];let C=((m-y)*(b-P)-(p-b)*(y-x))/M;return[m+C*(g-m),p+C*(h-p)]},u=i.length;for(let f=0;f<u;f++){let d=i[f],m=i[(f+u-1)%u],p=c(d),g=c(m);p?(g||t.push(l(m,d)),t.push([d[0],d[1]])):g&&t.push(l(m,d))}}return t}function Yo(e){if(!Number.isFinite(e)||e<=0)throw new Error("PolyCSS world unit size must be a positive finite number.");return e}function tl(e,n=50){return e*Yo(n)}function ol(e,n=50){return e/Yo(n)}function cn(e,n=50){let t=Yo(n);return[e[1]*t,e[0]*t,e[2]*t]}function rl(e,n=50){let t=Yo(n);return[e[1]/t,e[0]/t,e[2]/t]}function vi(e){return[e[1],e[0],e[2]]}function il(e){return e?.direction?{...e,direction:vi(e.direction)}:e}var l0=tl,u0=ol,f0=cn,m0=rl,d0=vi,p0=il;function Ii(e){return e==null?[1,1,1]:typeof e=="number"?[e,e,e]:[e[0]??1,e[1]??1,e[2]??1]}function Zt(e){let n=Ii(e),t=n[0]===1&&n[1]===1&&n[2]===1;return(o,r)=>{let i=cn(r),s=o[1]*50,a=o[0]*50,c=o[2]*50,l=t?s:s*n[0],u=t?a:a*n[1],f=t?c:c*n[2];return[l+i[0],u+i[1],f+i[2]]}}function sl(e,n){if(e.length<3||n===0)return e;let t=[],o=e.length;for(let r=0;r<o;r++){let i=e[(r-1+o)%o],s=e[r],a=e[(r+1)%o],c=s[0]-i[0],l=s[1]-i[1],u=a[0]-s[0],f=a[1]-s[1],d=Math.hypot(c,l),m=Math.hypot(u,f);if(d<1e-9||m<1e-9){t.push(s);continue}let p=l/d,g=-c/d,h=f/m,y=-u/m,b=p+h,x=g+y,P=Math.hypot(b,x);if(P<1e-9){t.push(s);continue}let M=b/P,C=x/P,E=M*p+C*g;if(Math.abs(E)<1e-9){t.push(s);continue}let A=n/E;t.push([s[0]+M*A,s[1]+C*A])}return t}var al=.5,cl=.001,ll=.5;function _i(e,n,t,o){let r=[];for(let u=0;u<e.length;u++){if(o.has(u))continue;let f=e[u];if(f.vertices.length<3)continue;let d=f.vertices.map(A=>t(A,n)),m=d[0],p=0,g=0,h=0;for(let A=1;A+1<d.length;A++){let S=d[A],T=d[A+1],v=S[0]-m[0],R=S[1]-m[1],O=S[2]-m[2],L=T[0]-m[0],D=T[1]-m[1],_=T[2]-m[2];p+=D*O-_*R,g+=_*v-L*O,h+=L*R-D*v}let y=Math.hypot(p,g,h);if(y<1e-9)continue;let b=[p/y,g/y,h/y],x=null;for(let A=1;A<d.length;A++){let S=d[A],T=S[0]-m[0],v=S[1]-m[1],R=S[2]-m[2],O=Math.hypot(T,v,R);if(O>1e-9){x=[T/O,v/O,R/O];break}}if(!x)continue;let P=x[0]*b[0]+x[1]*b[1]+x[2]*b[2];x=[x[0]-P*b[0],x[1]-P*b[1],x[2]-P*b[2]];let M=Math.hypot(x[0],x[1],x[2]);if(M<1e-9)continue;x=[x[0]/M,x[1]/M,x[2]/M];let C=[b[1]*x[2]-b[2]*x[1],b[2]*x[0]-b[0]*x[2],b[0]*x[1]-b[1]*x[0]],E=b[0]*m[0]+b[1]*m[1]+b[2]*m[2];r.push({face:f,O:m,n:b,u:x,v:C,offset:E,polyIndex:u})}let i=[];for(let u of r){let f=!1;for(let d of i){let m=d.rep;if(!(1-(u.n[0]*m.n[0]+u.n[1]*m.n[1]+u.n[2]*m.n[2])>cl)&&!(Math.abs(u.offset-m.offset)>ll)){d.faces.push(u),f=!0;break}}f||i.push({rep:u,faces:[u]})}let s=[],a=3,c=u=>`${u[0].toFixed(a)},${u[1].toFixed(a)},${u[2].toFixed(a)}`;for(let u of i){if(u.faces.length===1){l(u.faces);continue}let f=u.faces.map(h=>{let y=new Set;for(let b of h.face.vertices)y.add(c(t(b,n)));return y}),d=u.faces.map((h,y)=>y),m=h=>{for(;d[h]!==h;)d[h]=d[d[h]],h=d[h];return h},p=(h,y)=>{let b=m(h),x=m(y);b!==x&&(d[b]=x)};for(let h=0;h<u.faces.length;h++)for(let y=h+1;y<u.faces.length;y++){let b=f[h],x=f[y],P=0;for(let M of b)if(x.has(M)&&(P++,P>=2))break;P>=2&&p(h,y)}let g=new Map;for(let h=0;h<u.faces.length;h++){let y=m(h),b=g.get(y);b||(b=[],g.set(y,b)),b.push(u.faces[h])}for(let h of g.values())l(h)}function l(u){let f=u[0],{O:d,n:m,u:p,v:g}=f,h=[],y=[],b=[];for(let M of u){let C=[];for(let E of M.face.vertices){let A=t(E,n),S=A[0]-d[0],T=A[1]-d[1],v=A[2]-d[2],R=[S*p[0]+T*p[1]+v*p[2],S*g[0]+T*g[1]+v*g[2]];h.push(R),C.push(R)}C.length>=3&&(y.push(Tn(C)),b.push(M.polyIndex))}if(h.length<3)return;let x=Ci(h);if(x.length<3)return;let P=sl(Tn(x),al);s.push({O:d,n:m,u:p,v:g,outlineUv:P,memberPolysUv:y,memberPolyIndices:b})}return s}function g0(e){let n=typeof e.scale=="number"?e.scale:e.scale?.[0]??1,t=typeof e.scale=="number"?e.scale:e.scale?.[1]??1,o=typeof e.scale=="number"?e.scale:e.scale?.[2]??1,r=n!==1||t!==1||o!==1,i=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),s=e.position?cn(e.position):[0,0,0],a=[];return(s[0]!==0||s[1]!==0||s[2]!==0)&&a.push(`translate3d(${s[0]}px, ${s[1]}px, ${s[2]}px)`),i&&(e.rotation[0]&&a.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&a.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&a.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&a.push(`scale3d(${n}, ${t}, ${o})`),a.length>0?a.join(" "):void 0}function h0(e={}){let n=e.target??Oe.target,t=e.autoCenterOffset??[0,0,0],o=e.layoutScale??1,r=e.worldUnitPx??50,i=(e.zoom??Oe.zoom)/r*o,s=(e.distance??Oe.distance)*o,a=cn([n[0]+t[0],n[1]+t[1],n[2]+t[2]],r);return`${s!==0?`translateZ(${-s}px) `:""}scale(${i}) rotateX(${e.rotX??Oe.rotX}deg) rotate(${e.rotY??Oe.rotY}deg) translate3d(${-a[0]}px, ${-a[1]}px, ${-a[2]}px)`}var mn=50,ft=[.4,-.7,.59],mt="#ffffff",dt=1,pt="#ffffff",gt=.4,Ln=4096,jo=1,Vi=.1,Oi=1,Wo=Ln*Ln,Ri=Wo*3,qt=2048,Li=4*1024*1024,wi=16*1024*1024,Ni=.995,Di=512,y0=12,Te=.001,ge=1e-9,Fi=1e-4,Bi=.1,Ho=.01,b0=.75,x0=1,P0=250,M0=1.5,ki=.75,En=3,zi=2,Ko=4,Ui=[1,10,100,1e3,1e4,1e5,1e6],vn=64,Gi=32,$i=96,tn=64,Xi=128,Zo=50,qo=1e-7,In=16,Yi=.9,on=.75,Qo=.2,ji=.05,Wi=256,Hi=.6,S0=1.5;function Ki(e){return e===void 0||e==="auto"||!Number.isFinite(e)?1:Math.max(0,Math.min(1,e))}var Qt=new Map;function yt(e){if(Qt.has(e)){let t=Qt.get(e);return t===void 0?null:t}let n=Vn(e);return Qt.size>=Di&&Qt.clear(),Qt.set(e,n),n}function dn(e){let n=yt(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Zi({r:e,g:n,b:t}){return`${e},${n},${t}`}function Jo(e){return yt(e)?.alpha??1}function er({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function ul(e,n){if(n)for(let t of n){if(t.scale<=0)continue;let o=dn(t.color);e[0]+=Xe(o.r/255)*t.scale,e[1]+=Xe(o.g/255)*t.scale,e[2]+=Xe(o.b/255)*t.scale}}function nr(e,n,t,o,r){let i=dn(n),s=dn(t),a=Xe(i.r/255),c=Xe(i.g/255),l=Xe(i.b/255),u=Xe(s.r/255),f=Xe(s.g/255),d=Xe(s.b/255),m=[a*e,c*e,l*e];return ul(m,r),{r:(m[0]+u*o)*ht,g:(m[1]+f*o)*ht,b:(m[2]+d*o)*ht}}function A0({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Xe(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function C0(e){return e<=.0031308?e*12.92:1.055*Math.pow(e,1/2.4)-.055}var ht=1/Math.PI;function wn(e,n,t,o,r,i){let s=dn(e),a=dn(t),c=dn(o),l=Xe(s.r/255),u=Xe(s.g/255),f=Xe(s.b/255),d=Xe(a.r/255),m=Xe(a.g/255),p=Xe(a.b/255),g=Xe(c.r/255),h=Xe(c.g/255),y=Xe(c.b/255),b=[d*n,m*n,p*n];ul(b,i);let x=l*(b[0]+g*r)*ht,P=u*(b[1]+h*r)*ht,M=f*(b[2]+y*r)*ht,C=v=>Math.max(0,Math.min(255,Math.round(C0(Math.max(0,Math.min(1,v)))*255))),E=C(x),A=C(P),S=C(M),T=Jo(e);return T<1?`rgba(${E}, ${A}, ${S}, ${T})`:er({r:E,g:A,b:S})}function qi(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=yt(e);if(!t)return e;let o=255/Math.max(1,Math.round(n)-1),r=s=>Math.max(0,Math.min(255,Math.round(Math.round(s/o)*o))),i={r:r(t.rgb[0]),g:r(t.rgb[1]),b:r(t.rgb[2])};return t.alpha<1?`rgba(${i.r}, ${i.g}, ${i.b}, ${t.alpha})`:er(i)}function T0(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function E0(e,n,t){let o=(r,i)=>{let s=i-r;return Math.abs(s)<=t?i:r+Math.sign(s)*t};return{r:o(e.r,n.r),g:o(e.g,n.g),b:o(e.b,n.b)}}function v0(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:er(e)}function I0(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=yt(e),o=yt(n);if(!t||!o)return 1;let r=t.rgb[0]-o.rgb[0],i=t.rgb[1]-o.rgb[1],s=t.rgb[2]-o.rgb[2],a=(t.alpha-o.alpha)*255;return Math.sqrt(r*r+i*i+s*s+a*a)/510}function Qi(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p?(p.degree+=1,p.degree===2?p.polyB=a:p.polyB=null):i.set(m,{polyA:a,polyB:null,vertA:f,vertB:d,degree:1})}}let s=new Map;for(let[a,c]of i)s.set(a,{polyA:c.polyA,polyB:c.polyB,vertA:c.vertA,vertB:c.vertB});return s}function Ji(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e.map(s=>s?s[0]*o+s[1]*r+s[2]*i<-1e-6:!0)}function es(e,n){let o=a=>Math.round(a/1e-4).toString(36),r=a=>`${o(a[0])},${o(a[1])},${o(a[2])}`,i=new Map,s=a=>{let c=r(a);i.set(c,(i.get(c)??0)+1)};for(let a of e.values()){let c=n[a.polyA]??!1,l;a.polyB===null?l=c:l=c!==(n[a.polyB]??!1),l&&(s(a.vertA),s(a.vertB))}for(let a of i.values())if(a!==2)return!1;return!0}function tr(e,n){let t=[];for(let l of e.values()){let u=n[l.polyA]??!1;if(l.polyB===null)u&&t.push([l.vertA,l.vertB]);else{let f=n[l.polyB]??!1;u!==f&&t.push([l.vertA,l.vertB])}}if(t.length===0)return[];let o=1e-4,r=l=>Math.round(l/o).toString(36),i=l=>`${r(l[0])},${r(l[1])},${r(l[2])}`,s=t.map(([l,u])=>({a:l,b:u,aKey:i(l),bKey:i(u),used:!1})),a=new Map;for(let l of s){let u=a.get(l.aKey);u||(u=[],a.set(l.aKey,u)),u.push(l);let f=a.get(l.bKey);f||(f=[],a.set(l.bKey,f)),f.push(l)}let c=[];for(let l of s){if(l.used)continue;let u=[l.a],f=l,d=l.aKey,m=l.bKey;f.used=!0;for(let p=0;p<s.length+1;p++){u.push(f.bKey===m?f.b:f.a);let g=a.get(m)??[],h=null;for(let y of g)if(!(y===f||y.used)){h=y;break}if(!h||(h.used=!0,d=m,m=h.aKey===d?h.bKey:h.aKey,f=h,m===l.aKey))break}u.length>=3&&c.push(u)}return c}var fl=40;function _0(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p||(p=[],i.set(m,p)),p.push(a)}}let s=new Map;for(let a of i.values())if(!(a.length<2))for(let c of a)for(let l of a){if(c===l)continue;let u=s.get(c);u||(u=new Set,s.set(c,u)),u.add(l)}return s}function V0(e,n,t,o){let r=Zt(t),i=!!o&&(o[0]!==0||o[1]!==0||o[2]!==0),s=i?cn(n):null,a=e.map(c=>{if(!c)return{vertices:[],color:""};let l=c.vertices.map(u=>r(u,n));return i&&s&&o&&(l=l.map(u=>{let f=[u[0]-s[0],u[1]-s[1],u[2]-s[2]],d=Un(f,o);return[d[0]+s[0],d[1]+s[1],d[2]+s[2]]})),{vertices:l,color:""}});return Qi(a)}function O0(e,n,t,o,r){let i=[],s=Zt(t),a=!!r&&(r[0]!==0||r[1]!==0||r[2]!==0),c=a?cn(n):null;for(let l=0;l<e.length;l++){if(!o(l))continue;let u=e[l];if(!u)continue;let f=u.vertices.map(M=>s(M,n));a&&c&&r&&(f=f.map(M=>{let C=[M[0]-c[0],M[1]-c[1],M[2]-c[2]],E=Un(C,r);return[E[0]+c[0],E[1]+c[1],E[2]+c[2]]}));let d=1/0,m=1/0,p=1/0,g=-1/0,h=-1/0,y=-1/0;for(let M of f)M[0]<d&&(d=M[0]),M[0]>g&&(g=M[0]),M[1]<m&&(m=M[1]),M[1]>h&&(h=M[1]),M[2]<p&&(p=M[2]),M[2]>y&&(y=M[2]);let b=[[d,m,p],[g,m,p],[d,h,p],[g,h,p],[d,m,y],[g,m,y],[d,h,y],[g,h,y]],x=null,P=0;if(f.length>=3){let M=f[0],C=f[1],E=f[2],A=[C[0]-M[0],C[1]-M[1],C[2]-M[2]],S=[E[0]-M[0],E[1]-M[1],E[2]-M[2]],T=S[1]*A[2]-S[2]*A[1],v=S[2]*A[0]-S[0]*A[2],R=S[0]*A[1]-S[1]*A[0],O=Math.hypot(T,v,R);O>1e-9&&(x=[T/O,v/O,R/O],P=x[0]*M[0]+x[1]*M[1]+x[2]*M[2])}i.push({wv:f,bboxCorners:b,planeN:x,planeOffset:P,polygonIndex:l})}return i}function R0(e,n,t,o,r,i){let s=Zt(t),a=!!i&&(i[0]!==0||i[1]!==0||i[2]!==0),c=a?cn(n):null,f=_i(e,n,a&&c&&i?(h,y)=>{let b=s(h,y),x=[b[0]-c[0],b[1]-c[1],b[2]-c[2]],P=Un(x,i);return[P[0]+c[0],P[1]+c[1],P[2]+c[2]]}:s,o).map((h,y)=>{let{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A}=h,S=1/0,T=1/0,v=-1/0,R=-1/0;for(let Z of C)Z[0]<S&&(S=Z[0]),Z[1]<T&&(T=Z[1]),Z[0]>v&&(v=Z[0]),Z[1]>R&&(R=Z[1]);let O=v-S,L=R-T,D=r*50,_=b[0]+S*P[0]+T*M[0]+D*x[0],w=b[1]+S*P[1]+T*M[1]+D*x[1],V=b[2]+S*P[2]+T*M[2]+D*x[2],G=`matrix3d(${[P[0],P[1],P[2],0,M[0],M[1],M[2],0,x[0],x[1],x[2],0,_,w,V,1].map(Z=>Z.toFixed(4)).join(",")})`;return{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A,minU:S,minV:T,width:O,height:L,matrixCss:G,faceIndex:y,lift:D}}),d=.015,m=.5,p=20,g=new Set;for(let h=0;h<f.length;h++){if(g.has(h))continue;let y=f[h],b=y.n[0]*y.O[0]+y.n[1]*y.O[1]+y.n[2]*y.O[2],x=y.minU,P=y.minV,M=y.minU+y.width,C=y.minV+y.height;for(let E=0;E<f.length;E++){if(E===h||g.has(E))continue;let A=f[E];if(y.n[0]*A.n[0]+y.n[1]*A.n[1]+y.n[2]*A.n[2]<1-d)continue;let T=y.n[0]*A.O[0]+y.n[1]*A.O[1]+y.n[2]*A.O[2];if(T<=b+m||T-b>p)continue;let v=1/0,R=1/0,O=-1/0,L=-1/0;for(let D of A.outlineUv){let _=A.O[0]+D[0]*A.u[0]+D[1]*A.v[0],w=A.O[1]+D[0]*A.u[1]+D[1]*A.v[1],V=A.O[2]+D[0]*A.u[2]+D[1]*A.v[2],j=_-y.O[0],G=w-y.O[1],Z=V-y.O[2],ee=j*y.u[0]+G*y.u[1]+Z*y.u[2],W=j*y.v[0]+G*y.v[1]+Z*y.v[2];ee<v&&(v=ee),ee>O&&(O=ee),W<R&&(R=W),W>L&&(L=W)}if(v<=x&&O>=M&&R<=P&&L>=C){let D=Math.max(0,M-x)*Math.max(0,C-P);if(Math.max(0,O-v)*Math.max(0,L-R)>D*2)continue;g.add(h);break}}}return f=f.filter((h,y)=>!g.has(y)),f}function ml(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:s,allPointLights:a,thisPointIndex:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=Math.hypot(i[0],i[1],i[2])||1,p=i[0]/m,g=i[1]/m,h=i[2]/m,y=!!s,b=y?_=>{let w=s[0]-_[0],V=s[1]-_[1],j=s[2]-_[2],G=Math.hypot(w,V,j)||1;return[w/G,V/G,j/G]}:_=>[p,g,h],x=u?.color??"#ffffff",P=u?.intensity??.4,M=f?.intensity??1,C=f?.color??"#ffffff",E=d?.color??"#000000",A=d?.opacity??.25,S=!y,T=d?.maxExtend??2e3,v=[],R=new Array(r.length).fill(!1),O=r.map((_,w)=>{if(y){if(_.overridePointSilhouettes){let W=_.overridePointSilhouettes[c??-1];if(W)return W}else if(_.overrideSilhouette)return _.overrideSilhouette}else if(_.overrideSilhouette)return _.overrideSilhouette;if(y){if(_.selfShadowEdgeMap)return R[w]=!0,null;let W=_.edgeOwners;if(!W)return null;let ie=_.casterPolygonCount??0;if(ie===0)return null;let z=new Array(ie).fill(!0);for(let X of _.items){if(X.polygonIndex>=ie)continue;let U=X.planeN;if(!U){z[X.polygonIndex]=!0;continue}let I=0,B=0,N=0;for(let k of X.wv)I+=k[0],B+=k[1],N+=k[2];let H=X.wv.length>0?1/X.wv.length:0,$=b([I*H,B*H,N*H]);z[X.polygonIndex]=U[0]*$[0]+U[1]*$[1]+U[2]*$[2]<-1e-6}return es(W,z)?tr(W,z):(R[w]=!0,null)}let V=_.edgeOwners;if(_.selfShadowEdgeMap)return R[w]=!0,null;if(!V)return null;let j=_.casterPolygonCount??0;if(j<fl||_.items.length<fl)return null;let G=0;for(let W of _.items)W.planeN&&G++;if(G*2<_.items.length)return null;let Z=new Array(j).fill(null);for(let W of _.items)W.planeN&&W.polygonIndex<j&&(Z[W.polygonIndex]=W.planeN);let ee=Ji(Z,i);return es(V,ee)?tr(V,ee):(R[w]=!0,null)}),L=(_,w,V,j)=>{if(_.length<3)return[];let G=[],Z=W=>(W[0]-w[0])*V[0]+(W[1]-w[1])*V[1]+(W[2]-w[2])*V[2],ee=(W,ie,z,X)=>{let U=(z-j)/(z-X);return[W[0]+U*(ie[0]-W[0]),W[1]+U*(ie[1]-W[1]),W[2]+U*(ie[2]-W[2])]};for(let W=0;W<_.length;W++){let ie=_[W],z=_[(W+_.length-1)%_.length],X=Z(ie),U=Z(z),I=X>j,B=U>j;I?(B||G.push(ee(z,ie,U,X)),G.push(ie)):B&&G.push(ee(z,ie,U,X))}return G},D={rotX:l.rotX,rotY:l.rotY};for(let _ of n){let{O:w,n:V,u:j,v:G,outlineUv:Z,minU:ee,minV:W,width:ie,height:z}=_,X=b(w),U=X[0]*V[0]+X[1]*V[1]+X[2]*V[2];if(U<=1e-6||!Kt(V,D))continue;let I=Math.max(0,p*V[0]+g*V[1]+h*V[2]),B=0,N=0;for(let re of Z)B+=re[0],N+=re[1];let H=Z.length>0?1/Z.length:0;B*=H,N*=H;let $=[w[0]+B*j[0]+N*G[0],w[1]+B*j[1]+N*G[1],w[2]+B*j[2]+N*G[2]],k=[],Q=0;if(a)for(let re=0;re<a.length;re++){let fe=a[re],me=fe.position[0]-$[0],Pe=fe.position[1]-$[1],pe=fe.position[2]-$[2],Fe=Math.hypot(me,Pe,pe)||1,Le=Math.max(0,me/Fe*V[0]+Pe/Fe*V[1]+pe/Fe*V[2]);k[re]=Le,Q+=(fe.intensity??1)*Le}let ae=re=>(re[0]-w[0])*V[0]+(re[1]-w[1])*V[1]+(re[2]-w[2])*V[2],se=(re,fe,me,Pe)=>{let pe=me/(me-Pe);return[re[0]+pe*(fe[0]-re[0]),re[1]+pe*(fe[1]-re[1]),re[2]+pe*(fe[2]-re[2])]},Y=re=>{let fe=re[0]-w[0],me=re[1]-w[1],Pe=re[2]-w[2],pe=y?b(re):[p,g,h],Fe=y?pe[0]*V[0]+pe[1]*V[1]+pe[2]*V[2]:U,Le=Fe>.001?Fe:.001,Ve=(fe*V[0]+me*V[1]+Pe*V[2])/Le,$e=re[0]-Ve*pe[0],ke=re[1]-Ve*pe[1],ze=re[2]-Ve*pe[2],We=$e-w[0],be=ke-w[1],De=ze-w[2];return[We*j[0]+be*j[1]+De*j[2],We*G[0]+be*G[1]+De*G[2]]},ne=new Map,le=0,ye=ee,Ae=W,_e=_.minU+ie,Ee=_.minV+z,Me=1/0,Re=1/0,F=-1/0,q=-1/0;for(let re of r)for(let fe of re.items)for(let me of fe.wv){let Pe=me[0]-w[0],pe=me[1]-w[1],Fe=me[2]-w[2],Le=Pe*j[0]+pe*j[1]+Fe*j[2],Ve=Pe*G[0]+pe*G[1]+Fe*G[2];Le<Me&&(Me=Le),Le>F&&(F=Le),Ve<Re&&(Re=Ve),Ve>q&&(q=Ve)}let J=Number.isFinite(Me)?[[Me-T,Re-T],[F+T,Re-T],[F+T,q+T],[Me-T,q+T]]:[],te=.05,ue=V[0]*w[0]+V[1]*w[1]+V[2]*w[2],ce=.0025,he=5,Se=.94;for(let re=0;re<r.length;re++){let fe=r[re],me=fe.selfShadowEdgeMap,Pe=O[re];if(Pe!==null){if(Pe.length===0)continue;let pe=!!fe.overrideSilhouette,Fe=!1;if(pe){let Le=0;for(let Ve of Pe){if(Ve.length<3)continue;let $e=L(Ve,w,V,te);if($e.length<3)continue;let ke=$e.map(Y),ze=0;for(let We=0;We<ke.length;We++){let be=ke[We],De=ke[(We+1)%ke.length];ze+=be[0]*De[1]-De[0]*be[1]}Math.abs(ze)>Le&&(Le=Math.abs(ze),Fe=ze<0)}}for(let Le of Pe){if(Le.length<3)continue;let Ve=L(Le,w,V,te);if(Ve.length<3)continue;let $e=Ve.map(Y),ke=pe?Fe?[...$e].reverse():$e:Tn($e),ze=J.length===4?Rn(ke,J):ke;if(ze.length<3)continue;let We=Rn(ze,Z);if(We.length<3)continue;let be;for(let De of _.memberPolysUv){let Ie=Rn(We,Tn(De));Ie.length<3||(be||(be=ne.get(fe.id),be||(be={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,be))),be.verts.push(Ie),be.subPolygonIndices.push(-1),le++)}}continue}for(let pe of fe.items){if(me){let be=me.get(pe.polygonIndex);if(be){let De=!1;for(let Ie of _.memberPolyIndices)if(be.has(Ie)){De=!0;break}if(De){let Ie=pe.planeN;if(!Ie||Math.abs(Ie[0]*V[0]+Ie[1]*V[1]+Ie[2]*V[2])>Se)continue}}}if(pe.planeN&&!R[re]){let be=p,De=g,Ie=h;if(y){let uo=0,fo=0,mo=0;for(let It of pe.wv)uo+=It[0],fo+=It[1],mo+=It[2];let _n=pe.wv.length>0?1/pe.wv.length:0,et=b([uo*_n,fo*_n,mo*_n]);be=et[0],De=et[1],Ie=et[2]}if(pe.planeN[0]*be+pe.planeN[1]*De+pe.planeN[2]*Ie>-1e-6)continue}if(pe.planeN){let be=pe.planeN,De=be[0]*V[0]+be[1]*V[1]+be[2]*V[2];if(Math.abs(De)>1-ce){let Ie=De>0?1:-1;if(Math.abs(pe.planeOffset-Ie*ue)<he)continue}}let Fe=pe.bboxCorners,Le=!1,Ve=1/0,$e=1/0,ke=-1/0,ze=-1/0;for(let be=0;be<8;be++){let De=Fe[be];ae(De)>te&&(Le=!0);let Ie=Y(De);Ie[0]<Ve&&(Ve=Ie[0]),Ie[0]>ke&&(ke=Ie[0]),Ie[1]<$e&&($e=Ie[1]),Ie[1]>ze&&(ze=Ie[1])}if(!Le||ke<ye||Ve>_e||ze<Ae||$e>Ee)continue;let We=pe.wv;for(let be=1;be<We.length-1;be++){let De=We[0],Ie=We[be],lo=We[be+1],uo=ae(De),fo=ae(Ie),mo=ae(lo),_n=[],et=[[De,uo],[Ie,fo],[lo,mo]];for(let nt=0;nt<3;nt++){let[xn,_t]=et[nt],[po,Vt]=et[(nt+1)%3],Ot=_t>te,go=Vt>te;Ot&&_n.push(xn),Ot!==go&&_n.push(se(xn,po,_t,Vt))}if(_n.length<3)continue;let It=_n.map(Y),Ks=Tn(It),Zs=J.length===4?Rn(Ks,J):Ks;if(Zs.length<3)continue;let qs=Rn(Zs,Z);if(qs.length<3)continue;let kn;for(let nt of _.memberPolysUv){let xn=Rn(qs,Tn(nt));if(!(xn.length<3)){if(me){let _t=0,po=1/0,Vt=-1/0,Ot=1/0,go=-1/0;for(let ho=0;ho<xn.length;ho++){let un=xn[ho],Qs=xn[(ho+1)%xn.length];_t+=un[0]*Qs[1]-Qs[0]*un[1],un[0]<po&&(po=un[0]),un[0]>Vt&&(Vt=un[0]),un[1]<Ot&&(Ot=un[1]),un[1]>go&&(go=un[1])}if(Math.abs(_t)*.5<5)continue}kn||(kn=ne.get(fe.id),kn||(kn={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,kn))),kn.verts.push(xn),kn.subPolygonIndices.push(pe.polygonIndex),le++}}}}}if(le===0||!(ie>0)||!(z>0))continue;let ve=S?M*I:(a?.[c??-1]?.intensity??1)*(k[c??-1]??0),xe=M*I+Q+Math.max(0,P),K=A;if(o)if(xe>0){let re=Math.max(0,(xe-ve)/xe);K=A*(1-Math.pow(re,1/2.4))}else K=0;let oe=_.memberPolyIndices[0]??0,de=t[oe]?.color??"#cccccc",qe=S?0:M*I,Ye=[];if(a)for(let re=0;re<a.length;re++){if(y&&re===c)continue;let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Ye.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let Ge=o?E:wn(de,qe,C,x,P,Ye),we=1/0,Ne=1/0,Je=-1/0,Qe=-1/0;for(let re of ne.values())for(let fe of re.verts)for(let me of fe)me[0]<we&&(we=me[0]),me[0]>Je&&(Je=me[0]),me[1]<Ne&&(Ne=me[1]),me[1]>Qe&&(Qe=me[1]);we=Math.floor(we-1),Ne=Math.floor(Ne-1),Je=Math.ceil(Je+1),Qe=Math.ceil(Qe+1),we<ee&&(we=ee),Ne<W&&(Ne=W),Je>ee+ie&&(Je=ee+ie),Qe>W+z&&(Qe=W+z);let hn=Je-we,yn=Qe-Ne;if(!(hn>0)||!(yn>0))continue;let Bn=_.lift,vt=w[0]+we*j[0]+Ne*G[0]+Bn*V[0],Qn=w[1]+we*j[1]+Ne*G[1]+Bn*V[1],bn=w[2]+we*j[2]+Ne*G[2]+Bn*V[2],Jn=`matrix3d(${[j[0],j[1],j[2],0,G[0],G[1],G[2],0,V[0],V[1],V[2],0,vt,Qn,bn,1].map(re=>re.toFixed(4)).join(",")})`,je=[],en=[];for(let re of ne.values()){let fe="";for(let me of re.verts){fe+=`M${(me[0][0]-we).toFixed(1)},${(me[0][1]-Ne).toFixed(1)}`;for(let Pe=1;Pe<me.length;Pe++)fe+=`L${(me[Pe][0]-we).toFixed(1)},${(me[Pe][1]-Ne).toFixed(1)}`;fe+="Z",en.push(me.map(Pe=>[Pe[0],Pe[1]]))}je.push({casterId:re.id,d:fe,casterPolygonIndices:re.subPolygonIndices})}let Ce=[];if(a)for(let re=0;re<a.length;re++){let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Ce.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let Be=o?"":wn(de,M*I,C,x,P,Ce);v.push({faceIndex:_.faceIndex,memberPolyIndices:_.memberPolyIndices,matrixCss:Jn,width:hn,height:yn,fill:Ge,opacity:K,paths:je,fullLitFill:Be,facePolysUv:en})}return v}function L0(e,n){let t=Rt(e)?.rgb??[0,0,0],o=Rt(n)?.rgb??[255,255,255],r=i=>{let s=o[i]??0;return s<=0?255:Math.max(0,Math.min(255,Math.round(t[i]/s*255)))};return`rgb(${r(0)},${r(1)},${r(2)})`}function ns(e,n,t){let o="";for(let r of e)if(!(r.length<3)){o+=`M${(r[0][0]-n).toFixed(1)},${(r[0][1]-t).toFixed(1)}`;for(let i=1;i<r.length;i++)o+=`L${(r[i][0]-n).toFixed(1)},${(r[i][1]-t).toFixed(1)}`;o+="Z"}return o}function w0(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,runDirectional:s,pointPasses:a,allPointLights:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=d?.opacity??.25,p=new Map;for(let b of n)p.set(b.faceIndex,b);let g=new Map,h=(b,x)=>{let P=ml({receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:b,allPointLights:c,thisPointIndex:x,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d});for(let M of P){if(M.facePolysUv.length===0)continue;let C=M.fullLitFill!=="",E=g.get(M.faceIndex);E||(E={memberPolyIndices:M.memberPolyIndices,base:M.fullLitFill,solid:C,layers:[]},g.set(M.faceIndex,E)),E.layers.push({polys:M.facePolysUv,fill:M.fill,opacity:M.opacity})}};s&&h(void 0,void 0);for(let b of a)h(b.lightPos,b.index);let y=[];for(let[b,x]of g){let P=p.get(b);if(!P||x.layers.length===0)continue;let M=1/0,C=1/0,E=-1/0,A=-1/0;for(let z of x.layers)for(let X of z.polys)for(let U of X)U[0]<M&&(M=U[0]),U[0]>E&&(E=U[0]),U[1]<C&&(C=U[1]),U[1]>A&&(A=U[1]);if(!Number.isFinite(M))continue;M=Math.floor(M-1),C=Math.floor(C-1),E=Math.ceil(E+1),A=Math.ceil(A+1);let S=E-M,T=A-C;if(!(S>0)||!(T>0))continue;let{O:v,u:R,v:O,n:L,lift:D}=P,_=v[0]+M*R[0]+C*O[0]+D*L[0],w=v[1]+M*R[1]+C*O[1]+D*L[1],V=v[2]+M*R[2]+C*O[2]+D*L[2],G=`matrix3d(${[R[0],R[1],R[2],0,O[0],O[1],O[2],0,L[0],L[1],L[2],0,_,w,V,1].map(z=>z.toFixed(4)).join(",")})`,Z=x.solid&&x.layers.length>1,ee=null,W=null,ie=[];if(Z){ee=x.base,W="";for(let z of x.layers)W+=ns(z.polys,M,C);for(let z of x.layers)ie.push({d:ns(z.polys,M,C),fill:L0(z.fill,x.base),multiply:!0,opacity:1})}else for(let z of x.layers)ie.push({d:ns(z.polys,M,C),fill:z.fill,multiply:!1,opacity:z.opacity});y.push({faceIndex:b,memberPolyIndices:x.memberPolyIndices,matrixCss:G,width:S,height:T,svgOpacity:Z?m:1,baseFill:ee,baseD:W,layers:ie})}return y}var N0=Symbol.for("polycss.animation.triangleFrameSource"),D0=Symbol.for("polycss.animation.triangleFrameTarget"),dl=2200,os=2201,pl=2202;function F0(e,n){let t=0,o=1,r=1,i=os,s=1/0,a=0,c=!1,l=null,u=!0,f=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(m){r=m},get weight(){return o},set weight(m){o=m},get time(){return t},set time(m){t=m},get isRunning(){return c},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return c=!0,d},stop(){return c=!1,t=0,a=0,l=null,d},reset(){return t=0,a=0,d},fadeIn(m){return l={from:0,to:1,elapsed:0,duration:m},o=0,d},fadeOut(m){return l={from:o,to:0,elapsed:0,duration:m},d},crossFadeTo(m,p){return d.fadeOut(p),m.fadeIn(p),d},crossFadeFrom(m,p){return m.fadeOut(p),d.fadeIn(p),d},setLoop(m,p){return i=m,s=p,d},setEffectiveTimeScale(m){return r=m,d},setEffectiveWeight(m){return o=m,d}};return d._internal={get clip(){return e},get time(){return t},get weight(){return o},get enabled(){return u},get paused(){return f},get running(){return c},get loopMode(){return i},get repetitions(){return s},get completedReps(){return a},set completedReps(m){a=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!c)return;if(l){l.elapsed+=m;let g=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(o=l.from+(l.to-l.from)*g,g>=1&&(o=l.to,l=null,o<=0)){c=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(t+=m*r,i===dl)t>=p&&(t=d.clampWhenFinished?p:0,c=!1);else if(i===os){if(t>=p){let g=t%p,h=Math.floor(t/p);a+=h,t=g,s!==1/0&&a>=s&&(t=d.clampWhenFinished?p:0,c=!1)}}else if(p>0){let g=p*2,h=t%g;if(t>=g){let y=Math.floor(t/g);a+=y,s!==1/0&&a>=s?(t=d.clampWhenFinished?p:0,c=!1):t=h}}}},sampleTime(){if(i===pl){let m=e.duration,p=m*2,g=t%p;return g<=m?g:p-g}return t}},d}function B0(e){return e._internal}function ts(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function k0(e,n){let t=new Map,o=n,r=e;function i(f){let d=ts(n.clips,f);if(!d)throw new Error(`PolyAnimationMixer: no clip found for key "${f}". Available: ${n.clips.map(p=>p.name).join(", ")}`);let m=t.get(d.index);return m||(m=F0(d,n),t.set(d.index,m)),m}function s(f){let d=ts(n.clips,f);return d?t.get(d.index)??null:null}function a(f){let d=[];for(let y of t.values()){let b=B0(y);b.advance(f),b.running&&b.enabled&&d.push({internal:b,clip:b.clip})}if(d.length===0)return;if(d.length===1){let{internal:y,clip:b}=d[0],x=y.sampleTime(),P=o[N0]?.(b.name,x);if(P&&r[D0]?.(P))return;let M=n.sample(b.name,x);e.setPolygons(M);return}let m=0;for(let{internal:y}of d)m+=y.weight;if(m<=0)return;let p=d.map(({internal:y,clip:b})=>({polygons:n.sample(b.name,y.sampleTime()),weight:y.weight/m})),g=p[0].polygons;if(g.length===0)return;let h=g.map((y,b)=>{let x=y.vertices.map((P,M)=>{let C=0,E=0,A=0;for(let{polygons:S,weight:T}of p){let v=S[b];if(!v)continue;let R=v.vertices[M];R&&(C+=R[0]*T,E+=R[1]*T,A+=R[2]*T)}return[C,E,A]});return{...y,vertices:x}});e.setPolygons(h)}function c(){for(let f of t.values())f.stop()}function l(f){let d=ts(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:i,existingAction:s,update:a,stopAllAction:c,uncacheClip:l,uncacheRoot:u}}var is={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},xl={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},z0={0:"POINTS",1:"LINES",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN"},ss=["EXT_meshopt_compression","KHR_meshopt_compression"];function U0(e){return e===5120||e===5121||e===5122||e===5123}function Pl(e){let n=globalThis.TextDecoder;return new n().decode(e)}function G0(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let t=e.slice(5,n),o=e.slice(n+1);if(!t.includes(";base64")){let s=decodeURIComponent(o),a=new Uint8Array(s.length);for(let c=0;c<s.length;c++)a[c]=s.charCodeAt(c)&255;return a}let r=globalThis.atob(o),i=new Uint8Array(r.length);for(let s=0;s<r.length;s++)i[s]=r.charCodeAt(s);return i}function $0(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let t=n.getUint32(4,!0);if(t!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${t})`);let o=12,r=null,i=null;for(;o<e.byteLength;){let s=n.getUint32(o,!0),a=n.getUint32(o+4,!0),c=o+8;if(a===1313821514){let l=new Uint8Array(e,c,s);r=JSON.parse(Pl(l))}else a===5130562&&(i=new Uint8Array(e,c,s));o=c+s}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:i}}function gl(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function X0(e){let n=gl(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=gl(e.asset?.minVersion);if(e.asset?.minVersion&&(!t||t[0]>2||t[0]===2&&t[1]>0))throw new Error(`parseGltf: glTF asset requires minVersion ${e.asset.minVersion}`)}function Y0(e,n,t){let o=e.buffers??[],r=new Set(e.extensionsRequired??[]),i=ss.some(s=>r.has(s));return o.map((s,a)=>{let c=s.uri;if(c){if(c.startsWith("data:"))return G0(c);if(t){let l=t(c);if(l instanceof Uint8Array)return l;throw new Error("parseGltf: resolveBuffer returned a Promise; use parseGltf via async if your buffers are external")}throw new Error(`parseGltf: external buffer URI "${c}" \u2014 provide options.resolveBuffer`)}if(a===0&&n)return n;if(i&&ss.some(l=>s.extensions?.[l]))return new Uint8Array(0);throw new Error(`parseGltf: buffer[${a}] has no uri and no GLB BIN chunk`)})}function eo(e,n,t){let o=e.bufferViews?.[t],r=o?n[o.buffer]:void 0;if(!o||!r)throw new Error(`parseGltf: bad bufferView ${t}`);let i=o.byteOffset??0;if(i<0||o.byteLength<0||i+o.byteLength>r.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${o.buffer}`);return{buffer:r,view:o}}function Ml(e,n,t,o){if(e.count<=0)return;let r=e.byteOffset??0,i=r+t*(e.count-1)+o;if(r<0||i>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function Sl(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function j0(e,n,t){if(t||e===5126)return new Float32Array(n);switch(e){case 5120:return new Int8Array(n);case 5121:return new Uint8Array(n);case 5122:return new Int16Array(n);case 5123:return new Uint16Array(n);case 5125:return new Uint32Array(n);default:throw new Error(`parseGltf: unhandled componentType ${e}`)}}function or(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=is[o.componentType],i=xl[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);if(o.sparse||o.normalized||o.bufferView===void 0){let{values:h}=no(e,n,t);return{array:j0(o.componentType,h,o.normalized),count:o.count,componentCount:i}}let{buffer:s,view:a}=eo(e,n,o.bufferView),c=(a.byteOffset??0)+(o.byteOffset??0),l=o.count*i,u=r*i,f=Sl(a,u);if(Ml(o,a,f,u),f===u){let h=s.buffer.slice(s.byteOffset+c,s.byteOffset+c+l*r),y;switch(o.componentType){case 5120:y=new Int8Array(h);break;case 5121:y=new Uint8Array(h);break;case 5122:y=new Int16Array(h);break;case 5123:y=new Uint16Array(h);break;case 5125:y=new Uint32Array(h);break;case 5126:y=new Float32Array(h);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}return{array:y,count:o.count,componentCount:i}}let d;switch(o.componentType){case 5120:d=new Int8Array(l);break;case 5121:d=new Uint8Array(l);break;case 5122:d=new Int16Array(l);break;case 5123:d=new Uint16Array(l);break;case 5125:d=new Uint32Array(l);break;case 5126:d=new Float32Array(l);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}let m=new DataView(s.buffer),p=s.byteOffset+c,g=0;for(let h=0;h<o.count;h++){let y=p+h*f;for(let b=0;b<i;b++)d[g++]=sr(m,y+b*r,o.componentType)}return{array:d,count:o.count,componentCount:i}}function sr(e,n,t){switch(t){case 5120:return e.getInt8(n);case 5121:return e.getUint8(n);case 5122:return e.getInt16(n,!0);case 5123:return e.getUint16(n,!0);case 5125:return e.getUint32(n,!0);case 5126:return e.getFloat32(n,!0);default:throw new Error(`parseGltf: unhandled componentType ${t}`)}}function hl(e,n){switch(n){case 5120:return Math.max(e/127,-1);case 5121:return e/255;case 5122:return Math.max(e/32767,-1);case 5123:return e/65535;default:return e}}function no(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=is[o.componentType],i=xl[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);let s=r*i,a=new Array(o.count*i).fill(0);if(o.bufferView!==void 0){let{buffer:c,view:l}=eo(e,n,o.bufferView),u=c.byteOffset+(l.byteOffset??0)+(o.byteOffset??0),f=Sl(l,s);Ml(o,l,f,s);let d=new DataView(c.buffer),m=0;for(let p=0;p<o.count;p++){let g=u+p*f;for(let h=0;h<i;h++){let y=sr(d,g+h*r,o.componentType);a[m++]=o.normalized?hl(y,o.componentType):y}}}if(o.sparse){let c=o.sparse,l=c.indices,u=is[l.componentType];if(l.componentType!==5121&&l.componentType!==5123&&l.componentType!==5125)throw new Error(`parseGltf: unhandled sparse index componentType ${l.componentType}`);let{buffer:f,view:d}=eo(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),p=new DataView(f.buffer),{buffer:g,view:h}=eo(e,n,c.values.bufferView),y=g.byteOffset+(h.byteOffset??0)+(c.values.byteOffset??0),b=new DataView(g.buffer);for(let x=0;x<c.count;x++){let P=sr(p,m+x*u,l.componentType);for(let M=0;M<i;M++){let C=sr(b,y+(x*i+M)*r,o.componentType);a[P*i+M]=o.normalized?hl(C,o.componentType):C}}}return{values:a,count:o.count,componentCount:i}}function W0(e,n,t){let o=[],r=[],i=globalThis;for(let s of e.images??[]){if(s.uri){if(t&&!s.uri.startsWith("data:"))try{o.push(new i.URL(s.uri,t).href)}catch{o.push(s.uri)}else o.push(s.uri);continue}if(s.bufferView!==void 0){let a;try{let{buffer:f,view:d}=eo(e,n,s.bufferView),m=d.byteOffset??0;a=f.subarray(m,m+d.byteLength)}catch{o.push("");continue}let c=s.mimeType??"image/png",l=new i.Blob([a],{type:c}),u=i.URL.createObjectURL(l);o.push(u),r.push(u)}else o.push("")}return{urls:o,objectUrls:r}}function yl(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function H0(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:yl(t?.wrapS),t:yl(t?.wrapT)}}function Al(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function K0(e,n){let t=new Map,o=e.materials??[];for(let r=0;r<o.length;r++){let i=o[r].pbrMetallicRoughness?.baseColorTexture?.index;if(i===void 0)continue;let s=e.textures?.[i],a=s?.source;if(a===void 0)continue;let c=n[a];c&&t.set(r,{url:c,wrap:H0(e,s),alphaMode:Al(o[r].alphaMode),texCoord:o[r].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function Z0(e,n,t){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let r=c=>Math.max(0,Math.min(1,c)),i=c=>Math.round(r(c)*255).toString(16).padStart(2,"0"),s=c=>Math.round(r(c)*255),a=t==="opaque"?1:r(o[3]??1);return a<1?`rgba(${s(o[0])}, ${s(o[1])}, ${s(o[2])}, ${Math.round(a*1e3)/1e3})`:`#${i(o[0])}${i(o[1])}${i(o[2])}`}var bt=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Cl(e,n){let t=new Array(16);return Tl(t,e,n)}function Tl(e,n,t){for(let o=0;o<4;o++)for(let r=0;r<4;r++)e[r*4+o]=n[0+o]*t[r*4+0]+n[4+o]*t[r*4+1]+n[8+o]*t[r*4+2]+n[12+o]*t[r*4+3];return e}function rr(e,n){return[e[0]*n[0]+e[4]*n[1]+e[8]*n[2]+e[12],e[1]*n[0]+e[5]*n[1]+e[9]*n[2]+e[13],e[2]*n[0]+e[6]*n[1]+e[10]*n[2]+e[14]]}function El(e,n,t){let o=e?.[0]??0,r=e?.[1]??0,i=e?.[2]??0,s=n?.[0]??0,a=n?.[1]??0,c=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=s+s,p=a+a,g=c+c,h=s*m,y=s*p,b=s*g,x=a*p,P=a*g,M=c*g,C=l*m,E=l*p,A=l*g;return[(1-(x+M))*u,(y+A)*u,(b-E)*u,0,(y-A)*f,(1-(h+M))*f,(P+C)*f,0,(b+E)*d,(P-C)*d,(1-(h+x))*d,0,o,r,i,1]}function q0(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():El(e.translation,e.rotation,e.scale)}function vl(e,n,t){let o=new Array(Math.min(e.length,n.length));for(let r=0;r<o.length;r++)o[r]=e[r]+(n[r]-e[r])*t;return o}function Jt(e){let n=Math.hypot(e[0]??0,e[1]??0,e[2]??0,e[3]??1)||1;return[(e[0]??0)/n,(e[1]??0)/n,(e[2]??0)/n,(e[3]??1)/n]}function Q0(e,n,t){let o=Jt(e),r=Jt(n),i=o[0]*r[0]+o[1]*r[1]+o[2]*r[2]+o[3]*r[3];if(i<0&&(i=-i,r=[-r[0],-r[1],-r[2],-r[3]]),i>.9995)return Jt(vl(o,r,t));let s=Math.acos(Math.max(-1,Math.min(1,i))),a=Math.sin(s),c=Math.sin((1-t)*s)/a,l=Math.sin(t*s)/a;return Jt([o[0]*c+r[0]*l,o[1]*c+r[1]*l,o[2]*c+r[2]*l,o[3]*c+r[3]*l])}function Il(e){return{translation:e?.translation?.slice()??[0,0,0],rotation:e?.rotation?.slice()??[0,0,0,1],scale:e?.scale?.slice()??[1,1,1],matrix:e?.matrix&&e.matrix.length===16?e.matrix.slice():void 0}}function _l(e){return e.matrix?e.matrix.slice():El(e.translation,e.rotation,e.scale)}function J0(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function Vl(e,n){let t=e.nodes??[],o=new Array(t.length),r=new Set,i=new Set,s=(c,l)=>{if(c<0||c>=t.length||i.has(c))return;let u=Cl(l,n[c]??bt);o[c]=u,r.add(c),i.add(c);for(let f of t[c].children??[])s(f,u);i.delete(c)},a=J0(e);if(a.length>0)for(let c of a)s(c,bt);for(let c=0;c<t.length;c++)r.has(c)||s(c,bt);return o}var Ol=Symbol("polycss.gltfAnimationRuntimeInfo"),eh=Symbol.for("polycss.animation.triangleFrameSource");function Rl(e,n){return e?e[Ol]?.withPolygonFilter(n):void 0}function rs(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function nh(e,n,t){return rs(e,n)||rs(e,t)||rs(n,t)}function bl(e,n,t,o,r){if(t===void 0)return;let{values:i,count:s,componentCount:a}=no(e,n,t);if(s!==r||a<1)return;let c=[];for(let l=0;l<s;l++){let u=[];for(let f=0;f<o;f++)u.push(i[l*a+f]??0);c.push(u)}return c}function th(e,n,t,o){if(t===void 0)return Array.from({length:o},()=>bt.slice());let{values:r,componentCount:i,count:s}=no(e,n,t);if(i!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${t} is not MAT4`);let a=[];for(let c=0;c<o;c++){let l=Math.min(c,s-1);a.push(r.slice(l*16,l*16+16))}return a}function ir(e,n){let t=e.componentCount,o=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(o,o+t)}function oh(e,n,t){let o=e.input;if(o.length===0)return[];if(o.length===1||n<=o[0])return ir(e,0);let r=o.length-1;if(n>=o[r])return ir(e,r);let i=0,s=r;for(;i+1<s;){let d=i+s>>1;o[d]<=n?i=d:s=d}let a=o[i],c=o[i+1],l=c>a?(n-a)/(c-a):0,u=ir(e,i),f=ir(e,i+1);return e.interpolation==="STEP"?u:t==="rotation"?Q0(u,f,l):vl(u,f,l)}function Ll(e,n){let t=[];for(let o=0;o<(e.animations?.length??0);o++){let r=e.animations[o],i=(r.samplers??[]).map(c=>{let l=no(e,n,c.input),u=no(e,n,c.output);return{input:l.values,output:u.values,componentCount:u.componentCount,interpolation:c.interpolation??"LINEAR"}}),s=[];for(let c of r.channels??[]){let l=c.target.node,u=c.target.path,f=i[c.sampler];l===void 0||!u||!f||u!=="translation"&&u!=="rotation"&&u!=="scale"||s.push({sampler:f,targetNode:l,path:u})}let a=s.reduce((c,l)=>{let u=l.sampler.input;return Math.max(c,u[u.length-1]??0)},0);t.push({info:{index:o,name:r.name??`animation_${o}`,duration:a,channelCount:s.length},channels:s})}return t}function wl(e,n,t,o){let r=t.info.duration,i=r>0?(o%r+r)%r:Math.max(0,o),s=n.map(a=>({translation:a.translation.slice(),rotation:a.rotation.slice(),scale:a.scale.slice(),matrix:a.matrix?a.matrix.slice():void 0}));for(let a of t.channels){let c=s[a.targetNode];if(!c)continue;let l=oh(a.sampler,i,a.path);c.matrix=void 0,a.path==="translation"?c.translation=l.slice(0,3):a.path==="rotation"?c.rotation=Jt(l.slice(0,4)):a.path==="scale"&&(c.scale=l.slice(0,3))}return Vl(e,s.map(_l))}function rh(e,n,t,o,r,i){if((e.animations??[]).length===0||t.length===0)return;let a=(e.nodes??[]).map(h=>Il(h)),c=a.map(_l),l=Vl(e,c),u=(e.skins??[]).map(h=>({joints:h.joints??[],inverseBindMatrices:th(e,n,h.inverseBindMatrices,h.joints?.length??0)})),f=Ll(e,n),d=f.map(h=>h.info);if(d.length===0)return;let m=h=>{let y=t.map(b=>new Array(b.triangleMask.length).fill(!1));for(let b of h){let x=o[b];if(!x)return;let P=y[x.sourceIndex];if(!P||x.triangleIndex<0||x.triangleIndex>=P.length)return;P[x.triangleIndex]=!0}return y.map((b,x)=>{let P=t[x],M=new Set,C=0;for(let E=0;E+2<P.indices.length;E+=3,C++)b[C]&&(M.add(P.indices[E]),M.add(P.indices[E+1]),M.add(P.indices[E+2]));return{triangleMask:b,activeVertices:Array.from(M).sort((E,A)=>E-A)}})},p=(h,y,b,x,P,M,C,E,A)=>{let S=r(h),T=r(y),v=r(b),R={vertices:[S,T,v],color:x};return P&&(R.texture=P),P&&M&&(R.textureWrap=M),P&&C&&(R.textureAlphaMode=C),E&&(R.doubleSided=!0),A&&(R.uvs=A),R},g=h=>{let y=t.reduce((O,L,D)=>{let _=h?.[D]?.triangleMask??L.triangleMask,w=0;for(let V=0;V<_.length;V++)_[V]&&w++;return O+w},0),b=new Float64Array(Math.max(0,y*9)),x=new Array(y),P=new Array(y).fill(!1),M={polygonCount:0,vertices:b,colors:x,textureFlags:P,solidTriangles:!0},C=t.map(O=>new Array(O.positions.length)),E=u.map(O=>O.joints.map(()=>new Array(16))),A=(O,L)=>{let D=typeof O=="number"?f[O]:f.find(_=>_.info.name===O);return D?wl(e,a,D,L):null},S=(O,L,D,_)=>{let w=D?.activeVertices,V=C[O],j=(G,Z,ee,W)=>{let ie=V[G];ie?(ie[0]=Z,ie[1]=ee,ie[2]=W):V[G]=[Z,ee,W]};if(L.skinIndex!==void 0&&L.joints&&L.weights&&u[L.skinIndex]){let G=u[L.skinIndex],Z=L.joints,ee=L.weights,W=E[L.skinIndex]??[];for(let z=0;z<G.joints.length;z++){let X=G.joints[z],U=_[X],I=G.inverseBindMatrices[z],B=W[z]??(W[z]=new Array(16));W[z]=U&&I?Tl(B,U,I):void 0}let ie=z=>{let X=L.positions[z],U=0,I=0,B=0,N=0,H=Z[z]??[],$=ee[z]??[];for(let k=0;k<4;k++){let Q=$[k]??0;if(Q<=0)continue;let ae=Math.round(H[k]??0),se=W[ae];if(!se)continue;let Y=se[0]*X[0]+se[4]*X[1]+se[8]*X[2]+se[12],ne=se[1]*X[0]+se[5]*X[1]+se[9]*X[2]+se[13],le=se[2]*X[0]+se[6]*X[1]+se[10]*X[2]+se[14];U+=Y*Q,I+=ne*Q,B+=le*Q,N+=Q}if(N>0){let k=1/N;j(z,U*k,I*k,B*k)}else j(z,L.meshBindWorld[0]*X[0]+L.meshBindWorld[4]*X[1]+L.meshBindWorld[8]*X[2]+L.meshBindWorld[12],L.meshBindWorld[1]*X[0]+L.meshBindWorld[5]*X[1]+L.meshBindWorld[9]*X[2]+L.meshBindWorld[13],L.meshBindWorld[2]*X[0]+L.meshBindWorld[6]*X[1]+L.meshBindWorld[10]*X[2]+L.meshBindWorld[14])};if(w)for(let z of w)ie(z);else for(let z=0;z<L.positions.length;z++)ie(z)}else{let G=L.meshNode!==null?_[L.meshNode]??L.meshBindWorld:L.meshBindWorld,Z=ee=>{let W=L.positions[ee];j(ee,G[0]*W[0]+G[4]*W[1]+G[8]*W[2]+G[12],G[1]*W[0]+G[5]*W[1]+G[9]*W[2]+G[13],G[2]*W[0]+G[6]*W[1]+G[10]*W[2]+G[14])};if(w)for(let ee of w)Z(ee);else for(let ee=0;ee<L.positions.length;ee++)Z(ee)}return V},T=(O,L)=>{let D=A(O,L);if(!D)return[];let _=[];for(let w=0;w<t.length;w++){let V=t[w],j=h?.[w],G=j?.triangleMask??V.triangleMask,Z=S(w,V,j,D),ee=0;for(let W=0;W+2<V.indices.length;W+=3,ee++){if(!G[ee])continue;let ie=V.indices[W],z=V.indices[W+1],X=V.indices[W+2],U=Z[ie],I=Z[z],B=Z[X];if(!U||!I||!B)continue;let N;if(V.uvs&&V.texture){let $=V.uvs[ie],k=V.uvs[z],Q=V.uvs[X];$&&k&&Q&&(N=[$,k,Q])}let H=p(U,I,B,V.color,V.texture,V.textureWrap,V.textureAlphaMode,V.doubleSided,N);H&&_.push(H)}}return _},v=(O,L)=>{let D=A(O,L);if(!D)return null;b.length<y*9&&(b=new Float64Array(y*9),M.vertices=b),x.length<y&&(x=new Array(y),M.colors=x),P.length<y&&(P=new Array(y).fill(!1),M.textureFlags=P);let _=0,w=0,V=!1;for(let j=0;j<t.length;j++){let G=t[j],Z=h?.[j],ee=Z?.triangleMask??G.triangleMask,W=S(j,G,Z,D),ie=0;for(let z=0;z+2<G.indices.length;z+=3,ie++){if(!ee[ie])continue;let X=G.indices[z],U=G.indices[z+1],I=G.indices[z+2],B=W[X],N=W[U],H=W[I];if(!B||!N||!H)continue;i(B,b,w),i(N,b,w+3),i(H,b,w+6),x[_]=G.color;let $=!!G.texture;P[_]=$,$&&(V=!0),_++,w+=9}}return M.polygonCount=_,M.solidTriangles=!V,M},R={clips:d,sample:T};return R[eh]=v,R[Ol]={withPolygonFilter(O){let L=m(O);return L?g(L):void 0}},R};return g()}function as(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.materialColors??{},i=n?.materialTextures??{},s=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,a=s.byteLength,c,l=null;if(s.byteLength>=4&&new DataView(s).getUint32(0,!0)===1179937895){let F=$0(s);c=F.doc,l=F.bin}else c=JSON.parse(Pl(new Uint8Array(s)));X0(c);let u=Y0(c,l,n?.resolveBuffer),{urls:f,objectUrls:d}=W0(c,u,n?.baseUrl),m=K0(c,f),p=[],g=new Set,h=new Set(c.extensionsRequired??[]),y=h.has("KHR_mesh_quantization")||(c.extensionsUsed??[]).includes("KHR_mesh_quantization");function b(F,q){g.has(F)||(g.add(F),p.push(q))}function x(F,q){if(F===void 0)return!1;let J=c.accessors?.[F];if(!J)return!1;let te=ue=>c.bufferViews?.[ue]?.extensions?.[q]!==void 0;return!!(J.bufferView!==void 0&&te(J.bufferView)||J.sparse&&(te(J.sparse.indices.bufferView)||te(J.sparse.values.bufferView)))}function P(F){for(let q of ss)if(h.has(q)&&(F.extensions?.[q]||x(F.indices,q)||Object.values(F.attributes??{}).some(J=>x(J,q))))return q}function M(F,q){if(q instanceof Float32Array)return!0;let J=c.accessors?.[F];return y&&J?.type==="VEC3"&&U0(J.componentType)}function C(F,q){return(q!==null?c.nodes?.[q]?.weights:void 0)??F.weights??[]}function E(F,q,J,te,ue){let ce=J.targets;if(!ce||ce.length===0)return;let he=C(F,te);if(!he.some(xe=>Number.isFinite(xe)&&xe!==0))return;let Se=Array.from({length:ue},()=>[0,0,0]),ve=!1;for(let xe=0;xe<ce.length;xe++){let K=he[xe]??0;if(!Number.isFinite(K)||K===0)continue;let oe=ce[xe]?.POSITION;if(oe===void 0)continue;let{array:de,count:qe,componentCount:Ye}=or(c,u,oe);if(qe!==ue||Ye<3){b(`morph-position-count:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with mismatched count`);continue}if(!M(oe,de)){b(`morph-position-type:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with unsupported accessor type`);continue}ve=!0;for(let Ge=0;Ge<ue;Ge++){let we=Ge*Ye,Ne=Se[Ge];Ne[0]+=Number(de[we])*K,Ne[1]+=Number(de[we+1])*K,Ne[2]+=Number(de[we+2])*K}}return ve?Se:void 0}let A=[],S=[],T=[],v=(c.meshes??[]).map((F,q)=>F.name??`mesh_${q}`),R=(c.materials??[]).map((F,q)=>F.name??`material_${q}`);function O(F,q){if(q===4)return F;let J=[];if(q===5)for(let te=0;te+2<F.length;te++)J.push(F[te],F[te+1+te%2],F[te+2-te%2]);else if(q===6)for(let te=0;te+2<F.length;te++)J.push(F[te+1],F[te+2],F[0]);return J}function L(F){let q=[];for(let J=0;J+2<F.length;J+=3){let te=F[J],ue=F[J+1],ce=F[J+2];q.push(te,ue,ce,te,ce,ue)}return q}function D(F,q,J){let te=c.meshes?.[F];if(te){if(!Array.isArray(te.primitives)){b(`malformed-primitives:${F}`,`Mesh ${te.name??F}: skipped mesh with non-array primitives`);return}for(let ue=0;ue<te.primitives.length;ue+=1){let ce=te.primitives[ue];if(!ce)continue;let he=ce.mode??4;if(he!==4&&he!==5&&he!==6){let Ce=z0[he]??`mode ${he}`;b(`unsupported-mode:${he}`,`Skipped primitives with unsupported mode ${he} (${Ce})`);continue}if(ce.extensions?.KHR_draco_mesh_compression&&h.has("KHR_draco_mesh_compression")){b("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}let Se=P(ce);if(Se){b(Se,`Skipped primitives with unsupported required extension ${Se}`);continue}if(ce.attributes.POSITION===void 0){b(`missing-position:${F}`,`Mesh ${te.name??F}: skipped primitive without POSITION attribute`);continue}let ve=ce.material!==void 0?c.materials?.[ce.material]:void 0,xe=Al(ve?.alphaMode),K=ve?.name,de=(K?r[K]:void 0)??Z0(ve,o,xe),qe=ve?.doubleSided===!0,Ye=ce.material!==void 0?m.get(ce.material):void 0,Ge=K&&i[K]?i[K]:ce.material!==void 0?Ye?.url:void 0,we=Ge&&ce.material!==void 0?Ye?.wrap:void 0,Ne=Ge?Ye?.alphaMode??xe:void 0,Je=Ge?Ye?.texCoord??0:0,Qe=ce.attributes.POSITION,{array:hn,count:yn,componentCount:Bn}=or(c,u,Qe);if(!M(Qe,hn))continue;let vt=E(te,F,ce,J,yn),Qn=[],bn=[];for(let Ce=0;Ce<yn;Ce++){let Be=Ce*Bn,re=vt?.[Ce],fe=[Number(hn[Be])+(re?.[0]??0),Number(hn[Be+1])+(re?.[1]??0),Number(hn[Be+2])+(re?.[2]??0)];Qn.push(fe),bn.push(rr(q,fe))}let ln=null,Jn=ce.attributes[`TEXCOORD_${Je}`];if(Ge&&Jn!==void 0){let{array:Ce,count:Be}=or(c,u,Jn);ln=[];let re=1;Ce instanceof Uint8Array?re=1/255:Ce instanceof Uint16Array&&(re=1/65535);for(let fe=0;fe<Be;fe++){let me=Ce[fe*2]*re,Pe=Ce[fe*2+1]*re;ln.push([me,1-Pe])}}let je;if(ce.indices!==void 0){let{array:Ce,count:Be}=or(c,u,ce.indices);je=[];for(let re=0;re<Be;re++)je.push(Number(Ce[re]))}else je=bn.map((Ce,Be)=>Be);je=O(je,he),qe&&(je=L(je));let en;if((c.animations?.length??0)>0){let Ce=bl(c,u,ce.attributes.JOINTS_0,4,yn),Be=bl(c,u,ce.attributes.WEIGHTS_0,4,yn);en={sourceIndex:S.length,meshNode:J,meshBindWorld:q,skinIndex:J!==null?c.nodes?.[J]?.skin:void 0,positions:Qn,indices:je,triangleMask:[],color:de,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:ln??void 0,joints:Ce,weights:Be},S.push(en)}for(let Ce=0;Ce+2<je.length;Ce+=3){let Be=je[Ce],re=je[Ce+1],fe=je[Ce+2],me=en?en.triangleMask.length:void 0;en&&en.triangleMask.push(!1);let Pe=bn[Be],pe=bn[re],Fe=bn[fe];if(!Pe||!pe||!Fe)continue;let Le;if(ln&&Ge){let $e=ln[Be],ke=ln[re],ze=ln[fe];$e&&ke&&ze&&(Le=[$e,ke,ze])}let Ve=`${F}:${ue}:${J??"root"}`;A.push({v0:Pe,v1:pe,v2:Fe,color:de,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:Le,simplifySourceVertexKeys:[`${Ve}:${Be}`,`${Ve}:${re}`,`${Ve}:${fe}`],source:en,sourceIndex:en?.sourceIndex,sourceTriangleIndex:me})}}}}function _(F,q,J){if(J.has(F)){b(`recursive-node:${F}`,`Skipped recursive node reference ${F} in glTF scene graph`);return}let te=c.nodes?.[F];if(!te)return;let ue=Cl(q,q0(te));typeof te.mesh=="number"&&D(te.mesh,ue,F),J.add(F);for(let ce of te.children??[])_(ce,ue,J);J.delete(F)}function w(F){let q=new Set,J=F.info.duration;for(let te of F.channels)for(let ue of te.sampler.input)!Number.isFinite(ue)||ue<=0||J>0&&ue>=J||q.add(ue);return J>0&&(q.add(J*.25),q.add(J*.5),q.add(J*.75)),Array.from(q).sort((te,ue)=>te-ue).slice(0,128)}function V(F,q){let J=F.source;if(!J||F.sourceTriangleIndex===void 0||J.skinIndex!==void 0)return;let te=F.sourceTriangleIndex*3,ue=J.indices[te],ce=J.indices[te+1],he=J.indices[te+2],Se=ue!==void 0?J.positions[ue]:void 0,ve=ce!==void 0?J.positions[ce]:void 0,xe=he!==void 0?J.positions[he]:void 0;if(!Se||!ve||!xe)return;let K=J.meshNode!==null?q[J.meshNode]??J.meshBindWorld:J.meshBindWorld;return{v0:rr(K,Se),v1:rr(K,ve),v2:rr(K,xe)}}function j(F,q){return F[0]===q[0]&&F[1]===q[1]&&F[2]===q[2]}function G(F){return j(F.v0,F.v1)||j(F.v0,F.v2)||j(F.v1,F.v2)}function Z(){return A.some(F=>!G(F))}function ee(){if(A.length===0||(c.animations?.length??0)===0||Z())return;let F=Ll(c,u);if(F.length===0)return;let q=(c.nodes??[]).map(te=>Il(te)),J=new Array(A.length);for(let te of F)for(let ue of w(te)){let ce=wl(c,q,te,ue);for(let he=0;he<A.length;he++){if(J[he])continue;let Se=V(A[he],ce);Se&&!G(Se)&&(J[he]=Se)}}if(J.some(Boolean))for(let te=0;te<A.length;te++){let ue=J[te];ue&&(A[te].v0=ue.v0,A[te].v1=ue.v1,A[te].v2=ue.v2)}}let W=c.scene??0,ie=c.scenes?.[W]?.nodes;if(ie&&ie.length>0)for(let F of ie)_(F,bt,new Set);else{(c.meshes?.length??0)===0&&b("no-gltf-meshes","No glTF meshes found");for(let F=0;F<(c.meshes?.length??0);F++)D(F,bt,null)}ee();let z=ih(d);if(A.length===0)return{polygons:[],objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:0,meshes:v,materials:R,sourceBytes:a}};let X=1/0,U=1/0,I=1/0,B=-1/0,N=-1/0,H=-1/0;for(let F of A)for(let q of[F.v0,F.v1,F.v2])q[0]<X&&(X=q[0]),q[0]>B&&(B=q[0]),q[1]<U&&(U=q[1]),q[1]>N&&(N=q[1]),q[2]<I&&(I=q[2]),q[2]>H&&(H=q[2]);let $=Math.max(B-X,N-U,H-I),k=$>0?t/$:1,Q=n?.center,ae=Q===!0||Q==="center",se=ae?(X+B)*.5:X,Y=ae?(U+N)*.5:U,ne=ae?(I+H)*.5:I,le=F=>Math.round(F*1e3)/1e3,ye=n?.upAxis??"y",Ae=ye==="z"?([F,q,J])=>[le((F-se)*k),le((q-Y)*k),le((J-ne)*k)]:([F,q,J])=>[le((J-ne)*k),le((F-se)*k),le((q-Y)*k)],_e=ye==="z"?(F,q,J)=>{q[J]=le((F[0]-se)*k),q[J+1]=le((F[1]-Y)*k),q[J+2]=le((F[2]-ne)*k)}:(F,q,J)=>{q[J]=le((F[2]-ne)*k),q[J+1]=le((F[0]-se)*k),q[J+2]=le((F[1]-Y)*k)},Ee=[],Me=0;for(let F of A){let q=Ae(F.v0),J=Ae(F.v1),te=Ae(F.v2),ue=nh(q,J,te);if(F.source&&F.sourceTriangleIndex!==void 0&&(F.source.triangleMask[F.sourceTriangleIndex]=!ue),ue){Me++;continue}let ce={vertices:[q,J,te],color:F.color};F.texture&&(ce.texture=F.texture),F.texture&&F.textureWrap&&(ce.textureWrap=F.textureWrap),F.texture&&F.textureAlphaMode&&(ce.textureAlphaMode=F.textureAlphaMode),F.doubleSided&&(ce.doubleSided=!0),F.uvs&&(ce.uvs=F.uvs),F.simplifySourceVertexKeys&&(ce.simplifySourceVertexKeys=F.simplifySourceVertexKeys),Ee.push(ce),T.push(F.sourceIndex!==void 0&&F.sourceTriangleIndex!==void 0?{sourceIndex:F.sourceIndex,triangleIndex:F.sourceTriangleIndex}:void 0)}Ee.length===0&&Me>0&&b("all-projected-triangles-degenerate","No non-degenerate glTF triangles remained after normalization");let Re=rh(c,u,S,T,Ae,_e);return{polygons:Ee,animation:Re,objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:Ee.length,meshes:v,materials:R,animations:Re?.clips,sourceBytes:a}}}function ih(e){let n=!1;return()=>{if(n)return;n=!0;let t=globalThis.URL;if(t?.revokeObjectURL)for(let o of e)try{t.revokeObjectURL(o)}catch{}}}var Gl=Symbol("polycss.solidTextureBakedAnimationInfo"),Nl=Symbol.for("polycss.animation.triangleFrameSource"),sh=16*1024*1024,ah=2,ch=32,lh=2,uh=.08,fh=8,mh=128,Dl=32,dh=.045,ph=10,xt=6,gh=16;function cs(e){return e.material?.texture??e.texture}function hh(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function yh(e,n){return new Promise((t,o)=>{let r=new n,i=!1,s=a=>{i||(i=!0,a())};r.decoding="async",r.onload=()=>s(()=>t(r)),r.onerror=()=>s(()=>o(new Error(`texture load failed: ${e}`))),r.src=e})}async function bh(e,n,t){try{let o=await yh(e,n.Image),r=Math.max(0,Math.floor(o.naturalWidth||o.width||0)),i=Math.max(0,Math.floor(o.naturalHeight||o.height||0));if(r<=0||i<=0||r*i>t)return null;let s=n.createCanvas();s.width=r,s.height=i;let a=s.getContext("2d",{willReadFrequently:!0});if(!a)return null;a.drawImage(o,0,0,r,i);let c=a.getImageData(0,0,r,i).data;return{width:r,height:i,data:c,lowDetail:xh(r,i,c)}}catch{return null}}function Fl(e,n,t,o,r,i){let s=(o*n+t)*4,a=(i*n+r)*4;return Math.max(Math.abs((e[s]??0)-(e[a]??0)),Math.abs((e[s+1]??0)-(e[a+1]??0)),Math.abs((e[s+2]??0)-(e[a+2]??0)))}function xh(e,n,t){let o=Math.max(1,Math.floor(Math.max(e,n)/mh)),r=0,i=0,s=0;for(let a=0;a<n;a+=o)for(let c=0;c<e;c+=o){if(c+o<e){let l=Fl(t,e,c,a,c+o,a);s+=l,r++,l>Dl&&i++}if(a+o<n){let l=Fl(t,e,c,a,c,a+o);s+=l,r++,l>Dl&&i++}}return r>0&&i/r<=dh&&s/r<=ph}function Bl(e,n,t){return Math.max(n,Math.min(t,e))}function kl(e,n){if(!Number.isFinite(e))return null;switch(n){case"repeat":return e-Math.floor(e);case"mirrored-repeat":{let t=Math.floor(e),o=e-t;return Math.abs(t%2)===1?1-o:o}default:return Math.max(0,Math.min(1,e))}}function Ph(e,n,t){let o=n[0],r=1-n[1],i=kl(o,t?.s),s=kl(r,t?.t);if(i===null||s===null)return null;let a=Bl(Math.floor(i*e.width),0,e.width-1),l=(Bl(Math.floor(s*e.height),0,e.height-1)*e.width+a)*4;return{r:e.data[l]??0,g:e.data[l+1]??0,b:e.data[l+2]??0,a:e.data[l+3]??255}}function Nn(e,n,t,o,r,i){return[e[0]*o+n[0]*r+t[0]*i,e[1]*o+n[1]*r+t[1]*i]}function Mh(e){let[n,t,o]=e;return[Nn(n,t,o,1/3,1/3,1/3),Nn(n,t,o,.8,.1,.1),Nn(n,t,o,.1,.8,.1),Nn(n,t,o,.1,.1,.8),Nn(n,t,o,.45,.45,.1),Nn(n,t,o,.45,.1,.45),Nn(n,t,o,.1,.45,.45)]}function Sh(e){let[n,t,o]=e,r=Mh(e);for(let i=1;i<xt;i++)for(let s=1;s<xt-i;s++){let a=xt-i-s;a<=0||r.push(Nn(n,t,o,i/xt,s/xt,a/xt))}return r}function $l(e){if(e.textureTriangles?.length)return e.textureTriangles;let n=e.uvs;if(!n||n.length!==e.vertices.length||n.length<3)return[];let t=[];for(let o=1;o+1<n.length;o++)t.push({uvs:[n[0],n[o],n[o+1]]});return t}function ls(e,n,t){return Math.abs(e.r-n.r)<=t&&Math.abs(e.g-n.g)<=t&&Math.abs(e.b-n.b)<=t&&Math.abs(e.a-n.a)<=t}function ar(e){let n=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");if(e.a>=255)return`#${n(e.r)}${n(e.g)}${n(e.b)}`;let t=Math.round(Math.max(0,Math.min(255,e.a))/255*1e3)/1e3;return`rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`}function Xl(e){if(!e)return null;let n=e.trim().toLowerCase(),t=n.match(/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(t){let i=t[1],s=a=>{let c=i.length<=4?i[a]+i[a]:i.slice(a*2,a*2+2);return parseInt(c,16)};return{r:s(0),g:s(1),b:s(2),a:i.length===4||i.length===8?s(3):255}}let o=n.match(/^rgba?\(\s*([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)(?:\s*,\s*([0-9.]+)\s*)?\)$/);if(!o)return null;let r=o[4]===void 0?255:Number(o[4])<=1?Number(o[4])*255:Number(o[4]);return{r:Number(o[1]),g:Number(o[2]),b:Number(o[3]),a:r}}function Ah(){return{min:{r:255,g:255,b:255,a:255},max:{r:0,g:0,b:0,a:0},sum:{r:0,g:0,b:0,a:0},colors:new Map,count:0}}function Yl(e){return`${e.r},${e.g},${e.b},${e.a}`}function zl(e,n){e.min.r=Math.min(e.min.r,n.r),e.min.g=Math.min(e.min.g,n.g),e.min.b=Math.min(e.min.b,n.b),e.min.a=Math.min(e.min.a,n.a),e.max.r=Math.max(e.max.r,n.r),e.max.g=Math.max(e.max.g,n.g),e.max.b=Math.max(e.max.b,n.b),e.max.a=Math.max(e.max.a,n.a),e.sum.r+=n.r,e.sum.g+=n.g,e.sum.b+=n.b,e.sum.a+=n.a;let t=Yl(n),o=e.colors.get(t);e.colors.set(t,{color:n,count:(o?.count??0)+1}),e.count++}function Ul(e){return{r:e.sum.r/e.count,g:e.sum.g/e.count,b:e.sum.b/e.count,a:e.sum.a/e.count}}function Ch(e){if(e.count<fh||e.colors.size<=1||e.colors.size>lh)return null;let n=null;for(let r of e.colors.values())(!n||r.count>n.count)&&(n=r);if(!n)return null;let t=e.count-n.count,o=Math.max(1,Math.floor(e.count*uh));return t<=o?n.color:null}function Th(e,n,t,o){let r=$l(e);if(r.length===0)return null;let i=Ah(),s=e.textureAlphaMode==="opaque"?Xl(e.color):null;for(let a of r)for(let c of Sh(a.uvs)){let l=Ph(n,c,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){s&&zl(i,{...s,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),zl(i,l)}if(i.count===0)return e.textureAlphaMode==="opaque"&&e.color?e.color:null;if(e.textureAlphaMode==="opaque"&&i.max.a===0&&e.color)return e.color;if(ls(i.min,i.max,t))return ar(Ul(i));if(!o){let a=Ch(i);if(a)return ar(a)}return o||!n.lowDetail||!ls(i.min,i.max,ch)?null:ar(Ul(i))}function jl(e,n){let{texture:t,textureWrap:o,textureAlphaMode:r,material:i,uvs:s,textureTriangles:a,...c}=e,l=e.uvs?.length===e.vertices.length?e.uvs.map(d=>`uv:${Math.round(d[0]*1e5)},${Math.round(d[1]*1e5)}`):void 0,u=l??e.simplifyVertexKeys,f=e.simplifySourceVertexKeys?.length===e.vertices.length?e.simplifySourceVertexKeys.map((d,m)=>l?`${d}|${l[m]}`:d):e.simplifySourceVertexKeys;return{...c,color:n,...u?{simplifyVertexKeys:u}:{},...f?{simplifySourceVertexKeys:f}:{}}}function Eh(e,n){if(n.length<2)return e;let t=[],o=new Map;for(let l of n){let u=Xl(e[l]?.color);if(!u||u.a<255)continue;let f=Yl(u);t.push({index:l,key:f});let d=o.get(f);d?d.count+=1:o.set(f,{color:u,count:1})}if(o.size<2)return e;let r=[],i=new Map,s=[...o.entries()].sort((l,u)=>u[1].count-l[1].count||l[0].localeCompare(u[0]));for(let[l,u]of s){let f=null;for(let d of r)if(ls(u.color,d,gh)){f=d;break}f||(f=u.color,r.push(f)),i.set(l,ar(f))}let a=!1,c=e.slice();for(let l of t){let u=i.get(l.key),f=e[l.index];!u||!f||f.color===u||(c[l.index]={...f,color:u},a=!0)}return a?c:e}function vh(e,n){let t=e.slice();for(let o=0;o<n.length;o++){let r=n[o],i=e[r.index];i&&(t[r.index]=jl(i,r.color))}return t}function Wl(e){return e?e[Gl]:void 0}async function Hl(e,n={}){if(n.enabled===!1)return null;let t=hh();if(!t)return null;let o=e.filter(c=>cs(c)&&$l(c).length>0);if(o.length===0)return null;let r=n.maxTexturePixels??sh,i=new Map;await Promise.all(Array.from(new Set(o.map(c=>cs(c)))).map(async c=>{i.set(c,await bh(c,t,r))}));let s=n.colorTolerance??ah,a=n.colorTolerance!==void 0;return{bake(c){let l=!1,u=[],f=c.map((d,m)=>{let p=cs(d);if(!p)return d;let g=i.get(p);if(!g)return d;let h=Th(d,g,s,a);return h?(l=!0,u.push(m),jl(d,h)):d});return l?{polygons:Eh(f,u),changed:!0,bakedIndices:u}:{polygons:c,changed:!1,bakedIndices:u}}}}async function Ih(e,n={}){let t=await Hl(e,n);return t?t.bake(e).polygons:e}async function us(e,n={}){let t=await Hl(e.polygons,n);if(!t)return e;let o=t.bake(e.polygons);if(!o.changed)return e;let r=[];for(let a of o.bakedIndices){let l=o.polygons[a].color;l&&r.push({index:a,color:l})}let i=e.animation,s=i&&{...i,sample(a,c){return vh(i.sample(a,c),r)}};if(s&&i){let a=i[Nl];if(a){let c=new Map(r.map(f=>[f.index,f.color])),l=[],u={polygonCount:0,vertices:new Float64Array(0),colors:l,solidTriangles:!1};s[Nl]=(f,d)=>{let m=a(f,d);if(!m)return m;l.length<m.polygonCount&&(l=new Array(m.polygonCount),u.colors=l);let p=m.textureFlags,g=m.solidTriangles===!0||!!p;for(let h=0;h<m.polygonCount;h++){let y=c.get(h);l[h]=y??m.colors?.[h],p?.[h]&&!y&&(g=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=p,u.solidTriangles=g,u}}s[Gl]={source:i,bakedColorEntries:r}}return{...e,polygons:o.polygons,animation:s}}var Kl=Symbol.for("polycss.animation.triangleFrameSource");function _h(e,n){let t=e[n];if(!t)return null;let o=[];for(let r=0;r<t.vertices.length;r++)o.push(n,r);return{rest:t,originalIndex:n,sourceRefs:o}}function Vh(e){let n=Mn(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((r,i)=>t.set(r,i));let o=[];for(let r of n){let i=t.get(r);if(i===void 0)return[];let s=_h(e,i);if(!s)return[];o.push(s)}return o}function fs(e,n,t=!1){let o=new Array(n.length);for(let r=0;r<n.length;r++){let i=n[r],s=i.sourceRefs,a=new Array(s.length/2);for(let l=0,u=0;l<s.length;l+=2,u++){let d=e[s[l]]?.vertices[s[l+1]];if(!d)return e;let m=d[0],p=d[1],g=d[2];if(!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(g))return e;a[u]=[m,p,g]}let c=t?i.rest.color:e[s[0]??-1]?.color??i.rest.color;o[r]={...i.rest,vertices:a,color:c}}return o}function Oh(e,n){let t=new Map;return n.forEach((o,r)=>{t.set(o,r)}),e.map((o,r)=>({...o,sourceRefs:o.sourceRefs.map((i,s)=>s%2===0?t.get(i)??-1:i)}))}function Rh(e,n){if(e.length<n.length)return null;let t=new Array(n.length);for(let o=0;o<n.length;o++){let r=e[o],i=n[o];if(!r||r.vertices.length!==i.rest.vertices.length)return null;t[o]={...i.rest,vertices:r.vertices,color:i.rest.color}}return t}function Lh(e){return!!(e.texture||e.material?.texture)}function wh(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=Vh(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let o=Wl(e.animation),r=o?.source??e.animation,i=t.map(b=>b.originalIndex),s=Rl(r,i),a=s??r,c=s?Oh(t,i):t,l=t.map(b=>b.rest.color),u=t.every(b=>b.rest.vertices.length===3&&!Lh(b.rest)),f=s&&!o&&t.length===i.length&&t.every((b,x)=>b.rest.vertices.length===3&&b.sourceRefs.length===6&&b.sourceRefs[0]===i[x]&&b.sourceRefs[2]===i[x]&&b.sourceRefs[4]===i[x]),d=a[Kl],m=new Float64Array(t.length*9),p=l.slice(),g=new Array(t.length).fill(!1),h={polygonCount:t.length,vertices:m,colors:p,textureFlags:g,solidTriangles:u},y={...e.animation,sample(b,x){let P=a.sample(b,x);return f?P:s&&o?u&&t.length===i.length?Rh(P,t)??fs(P,c,!0):fs(P,c,!0):fs(P,c,!!o)}};return d&&u&&(y[Kl]=(b,x)=>{let P=d(b,x);if(!P)return P;if(s)return P.polygonCount<t.length||P.vertices.length<t.length*9?null:(h.polygonCount=t.length,h.vertices=P.vertices,h.colors=o?l:P.colors,h.textureFlags=o?g:P.textureFlags,h.solidTriangles=o?u:P.solidTriangles===!0,h);m.length<t.length*9&&(m=new Float64Array(t.length*9),h.vertices=m),p.length<t.length&&(p=new Array(t.length),h.colors=p),g.length<t.length&&(g=new Array(t.length).fill(!1),h.textureFlags=g);let M=u&&P.solidTriangles!==!1;for(let C=0;C<c.length;C++){let E=c[C],A=E.sourceRefs;for(let v=0,R=0;v<A.length;v+=2,R++){let O=A[v],L=A[v+1];if(O<0||O>=P.polygonCount)return null;let D=O*9+L*3,_=C*9+R*3;if(D+2>=P.vertices.length)return null;m[_]=P.vertices[D],m[_+1]=P.vertices[D+1],m[_+2]=P.vertices[D+2]}let S=A[0],T=!!P.textureFlags?.[S];g[C]=T,p[C]=o?E.rest.color:P.colors?.[S]??E.rest.color,!o&&T&&(M=!1)}return h.polygonCount=t.length,h.vertices=m,h.colors=p,h.textureFlags=g,h.solidTriangles=o?u:M,h}),{...e,polygons:t.map(b=>b.rest),animation:y,metadata:{...e.metadata,triangleCount:t.length}}}var Nh=/^[0-9A-Fa-f]{6}$/,Dh=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function Fh(e){let n=[],t="";for(let o of e.split(`
|
|
1
|
+
var Gu="cubic";function Rt(e){let n=e.replace("#","");if(n.length===3){let t=parseInt(n[0]+n[0],16),o=parseInt(n[1]+n[1],16),r=parseInt(n[2]+n[2],16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}if(n.length===6){let t=parseInt(n.slice(0,2),16),o=parseInt(n.slice(2,4),16),r=parseInt(n.slice(4,6),16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}return null}function Js(e){let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/i);return n?{rgb:[Number(n[1]),Number(n[2]),Number(n[3])],alpha:n[4]?Number(n[4]):1}:null}function Vn(e){if(!e)return null;let n=e.trim(),t=Rt(n);return t||Js(n)}function zn(e){return Math.max(0,Math.min(255,Math.round(e)))}function yo(e){let[n,t,o]=e.rgb.map(zn);return e.alpha<1?`rgba(${n}, ${t}, ${o}, ${e.alpha})`:`rgb(${n}, ${t}, ${o})`}var Tr={rgb:[204,204,204],alpha:1},ea=new Map;function tt(e){if(!e)return null;let n=e.trim(),t=ea.get(n);if(t)return t;let o=Vn(n);return o?(ea.set(n,o),o):null}function $u(e,n){let t=tt(e)??Tr,o=[zn(t.rgb[0]+n),zn(t.rgb[1]+n),zn(t.rgb[2]+n)];return yo({rgb:o,alpha:t.alpha})}var Cr={direction:[0,0,1],color:"#ffffff",intensity:1},na={color:"#ffffff",intensity:.4};function ta(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-12?[0,0,0]:[e[0]/n,e[1]/n,e[2]/n]}function oa(e,n,t){let o=tt(n)??Tr;return e*(o.rgb[t]/255)}function Xu(e,n,t,o){let r=tt(n)??Tr,i=ta(t?.direction??Cr.direction),s=t?.color??Cr.color,a=Math.max(0,t?.intensity??Cr.intensity),c=o?.color??na.color,l=Math.max(0,o?.intensity??na.intensity),u=ta(e),f=Math.max(0,u[0]*i[0]+u[1]*i[1]+u[2]*i[2]),d=a*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],h=oa(g,c,p)*l,y=oa(g,s,p)*d;m[p]=zn(h+y)}return yo({rgb:m,alpha:r.alpha})}var ra="#cccccc",bo=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],ia=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],sa=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],xo=e=>Math.hypot(e[0],e[1],e[2]);function Yu(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>i&&(i=u[1]),u[2]<o&&(o=u[2]),u[2]>s&&(s=u[2]);let a=r-n,c=i-t,l=s-o;return Math.hypot(a,c,l)}function ju(){let e=globalThis;if(e.__POLYCSS_DEV__===!0)return!0;if(e.__POLYCSS_DEV__===!1)return!1;let n=e.process?.env?.NODE_ENV;return typeof n=="string"?n!=="production":!1}function aa(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function ca(e){return e?{...e}:void 0}function Wu(e){if(e)return{...e,imageSource:aa(e.imageSource),presentation:ca(e.presentation)}}function Er(e){let n=[],t=[];if(!e||e.length===0)return{polygons:n,warnings:t};for(let o=0;o<e.length;o++){let r=e[o];if(!r||!Array.isArray(r.vertices)){t.push(`Polygon ${o}: missing vertices, dropped`);continue}let i=r.vertices;if(i.length<3){t.push(`Polygon ${o}: ${i.length} vertices (need >= 3), dropped`);continue}let s=bo(i[1],i[0]),a=bo(i[2],i[0]),c=ia(s,a),l=xo(c);if(i.length===3){if(l<1e-12){xo(s)<1e-12||xo(a)<1e-12?t.push(`Polygon ${o}: zero-area triangle (coincident vertices), dropped`):t.push(`Polygon ${o}: vertices collinear, dropped`);continue}}else if(l<1e-12){t.push(`Polygon ${o}: first 3 vertices collinear, dropped`);continue}let u=[{...r,vertices:i.slice()}];if(i.length>=4){let f=[c[0]/l,c[1]/l,c[2]/l],d=sa(f,i[0]),m=Yu(i),p=Math.max(1e-6,m*.001),g=0;for(let h=3;h<i.length;h++){let y=Math.abs(sa(f,i[h])-d);y>g&&(g=y)}if(g>p){let h=[],y=r.uvs&&r.uvs.length===i.length?r.uvs:void 0;for(let b=1;b<i.length-1;b++){let x=[i[0].slice(),i[b].slice(),i[b+1].slice()],P=ia(bo(x[1],x[0]),bo(x[2],x[0]));if(xo(P)<1e-12)continue;let M={...r,vertices:x};y&&(M.uvs=[y[0].slice(),y[b].slice(),y[b+1].slice()]),h.push(M)}if(h.length===0){t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulated to ${h.length} triangles`),u=h}}for(let f of u){let d=Hu(f,o,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function Hu(e,n,t){let o={vertices:e.vertices},r=Wu(e.material),i=aa(e.textureImageSource),s=ca(e.texturePresentation),a=r?.texture??e.texture??i?.url??r?.imageSource?.url;if(typeof a=="string"&&a===""&&(a=void 0),e.color!==void 0&&a!==void 0&&ju()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(tt(e.color)?o.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${ra}`),o.color=ra)),a!==void 0&&(o.texture=a,e.textureWrap&&(o.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(o.textureAlphaMode=e.textureAlphaMode)),r&&(o.material=r),i&&(o.textureImageSource=i),s&&(o.texturePresentation=s),Array.isArray(e.textureTriangles)&&e.textureTriangles.length>0&&(o.textureTriangles=e.textureTriangles.map(c=>({vertices:c.vertices.map(l=>l.slice()),uvs:c.uvs.map(l=>l.slice())}))),e.doubleSided===!0&&(o.doubleSided=!0),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?t.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):o.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let c={},l=!1;for(let u of Object.keys(e.data)){let f=e.data[u];typeof f=="string"||typeof f=="number"||typeof f=="boolean"?c[u]=f:(l=!0,t.push(`Polygon ${n}: data["${u}"] has non-primitive value, key dropped`))}Object.keys(c).length>0&&(o.data=c)}return o}function la(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0,a=!1;for(let c of e)if(c?.vertices)for(let l of c.vertices)l&&(a=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>i&&(i=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]));return a?{min:[n,t,o],max:[r,i,s]}:{min:[0,0,0],max:[0,0,0]}}function Ku(e){let n=e.polygons??[],t,o;if(e.skipNormalize)t=n,o=[];else{let a=Er(n);t=a.polygons,o=a.warnings}let r=la(t),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]];return{context:{polygons:t,sceneBbox:r,warnings:o},dimensions:{sceneBbox:r,size:i},warnings:o}}function Zu(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function qu(e){let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],i=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],s=r[1]*i[2]-r[2]*i[1],a=r[2]*i[0]-r[0]*i[2],c=r[0]*i[1]-r[1]*i[0],l=Math.hypot(s,a,c);return l<=1e-9?null:[s/l,a/l,c/l]}function Qu(e){let n=0;for(let t=0;t<e.length;t++){let[o,r]=e[t],[i,s]=e[(t+1)%e.length];n+=o*s-i*r}return Math.abs(n)/2}function Ju(e,n,t){if(!e||e.length<3)return null;let o=e.map(a=>[a[1]*n,a[0]*n,a[2]*t]),r=qu(o);if(!r)return null;let i=1/0,s=0;for(let a=0;a<o.length;a++){let c=o[a],l=o[(a+1)%o.length],u=[l[0]-c[0],l[1]-c[1],l[2]-c[2]],f=u[0]*r[0]+u[1]*r[1]+u[2]*r[2],d=[u[0]-f*r[0],u[1]-f*r[1],u[2]-f*r[2]],m=Math.hypot(d[0],d[1],d[2]);if(m<=1e-9)continue;let p=[d[0]/m,d[1]/m,d[2]/m],g=[r[1]*p[2]-r[2]*p[1],r[2]*p[0]-r[0]*p[2],r[0]*p[1]-r[1]*p[0]],h=Math.hypot(g[0],g[1],g[2]);if(h<=1e-9)continue;let y=[g[0]/h,g[1]/h,g[2]/h],b=o.map(v=>{let R=v[0]-c[0],O=v[1]-c[1],L=v[2]-c[2];return[R*p[0]+O*p[1]+L*p[2],R*y[0]+O*y[1]+L*y[2]]}),x=1/0,P=1/0,M=-1/0,C=-1/0;for(let[v,R]of b)x=Math.min(x,v),P=Math.min(P,R),M=Math.max(M,v),C=Math.max(C,R);let E=M-x,A=C-P,S=Math.max(1,Math.ceil(E))*Math.max(1,Math.ceil(A)),T=Qu(b);T<=1e-9||S<i&&(i=S,s=T)}return!Number.isFinite(i)||s<=1e-9?null:{elementArea:i,polygonArea:s}}function ef(e,n={}){let t=n.tileSize??100,o=n.layerElevation??t,r=n.texturedOnly??!0,i=0,s=0,a=0,c=0,l=0;for(let f of e){let d=!!f.texture;if(r&&!d)continue;let m=Ju(f.vertices,t,o);m&&(i+=1,d&&(s+=1),a+=m.elementArea,c+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,a-c);return{totalPolygons:e.length,measuredPolygons:i,texturedPolygons:s,elementArea:a,polygonArea:c,transparentArea:u,transparentRatio:a>0?u/a:0,overdrawRatio:c>0?a/c:0,worstTransparentRatio:l}}function vr(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function nf(e,n){let t=-n[0]*Math.PI/180,o=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[i,s,a]=e;if(t!==0){let c=Math.cos(t),l=Math.sin(t);[s,a]=[s*c-a*l,s*l+a*c]}if(o!==0){let c=Math.cos(o),l=Math.sin(o);[i,a]=[i*c+a*l,-i*l+a*c]}if(r!==0){let c=Math.cos(r),l=Math.sin(r);[i,s]=[i*c-s*l,i*l+s*c]}return[i,s,a]}function Un(e,n){let[t,o,r]=e,i=-(n[2]??0)*Math.PI/180;if(i!==0){let c=Math.cos(i),l=Math.sin(i);[t,o]=[t*c-o*l,t*l+o*c]}let s=-(n[1]??0)*Math.PI/180;if(s!==0){let c=Math.cos(s),l=Math.sin(s);[o,r]=[o*c-r*l,o*l+r*c]}let a=-(n[0]??0)*Math.PI/180;if(a!==0){let c=Math.cos(a),l=Math.sin(a);[t,r]=[t*c+r*l,-t*l+r*c]}return[t,o,r]}var Ir=Math.PI/180,Lt=180/Math.PI,tf=[1,0,0,0];function of(e,n){let[t,o,r,i]=e,[s,a,c,l]=n;return[t*s-o*a-r*c-i*l,t*a+o*s+r*l-i*c,t*c-o*l+r*s+i*a,t*l+o*c-r*a+i*s]}function rf(e,n){let t=n*.5,o=Math.sin(t);return[Math.cos(t),e[0]*o,e[1]*o,e[2]*o]}function sf(e){let n=e[0]*Ir,t=e[1]*Ir,o=e[2]*Ir,r=Math.cos(n*.5),i=Math.sin(n*.5),s=Math.cos(t*.5),a=Math.sin(t*.5),c=Math.cos(o*.5),l=Math.sin(o*.5);return[r*s*c-i*a*l,i*s*c+r*a*l,r*a*c-i*s*l,r*s*l+i*a*c]}function af(e){let[n,t,o,r]=e,i=2*(t*r+n*o),s=2*(o*r-n*t),a=1-2*(t*t+o*o),c=2*(t*o-n*r),l=1-2*(o*o+r*r),u=Math.max(-1,Math.min(1,i)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-s,a)*Lt,f*Lt,Math.atan2(-c,l)*Lt]:[Math.atan2(2*(o*r+n*t),1-2*(t*t+r*r))*Lt,f*Lt,0]}var Ze=50;function cf(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Oe={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0};function ma(e=Oe.target,n=[0,0,0],t=50){let o=e[0]+n[0],r=e[1]+n[1],i=e[2]+n[2];return[r*t,o*t,i*t]}function lf(e=Oe,n={}){let t=n.tileSize??50,o=n.layoutScale??1,r=e.target??Oe.target,[i,s,a]=ma(r,n.autoCenterOffset,t),c=(e.zoom??Oe.zoom)/t*o,l=(e.distance??Oe.distance)*o,u=e.rotX??Oe.rotX,f=e.rotY??Oe.rotY;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${u}deg) rotate(${f}deg) translate3d(${-i}px, ${-s}px, ${-a}px)`}function da(e="none"){if(e==="none")return"1000000px";let n=Number.parseFloat(e);return Number.isFinite(n)?`${n}px`:e}function uf(e,n={}){let t=n.perspectiveStyle??e.perspectiveStyle??"none",o=n.projection??e.type??(t==="none"?"orthographic":"perspective"),r=e.state??Oe;return{projection:o,perspectiveStyle:t,appliedPerspectiveStyle:da(t),state:{target:[...r.target??Oe.target],rotX:r.rotX??Oe.rotX,rotY:r.rotY??Oe.rotY,zoom:r.zoom??Oe.zoom,distance:r.distance??Oe.distance}}}var ua=100,fa=1e4,ot=e=>Math.round(e*ua)/ua,ff=e=>Math.round(e*fa)/fa;function mf(e={}){let n={target:e.target??[...Oe.target],rotX:e.rotX??Oe.rotX,rotY:e.rotY??Oe.rotY,zoom:e.zoom??Oe.zoom,distance:e.distance??Oe.distance};function t(r){r.target!==void 0&&(n.target=[ot(r.target[0]),ot(r.target[1]),ot(r.target[2])]),r.rotX!==void 0&&(n.rotX=ot(r.rotX)),r.rotY!==void 0&&(n.rotY=ot(r.rotY)),r.zoom!==void 0&&(n.zoom=ff(r.zoom)),r.distance!==void 0&&(n.distance=ot(r.distance))}function o(r={}){let s=(r.cols??0)*50,a=(r.rows??0)*50,[c,l,u]=n.target,f=l*50,d=c*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-d}px, ${-m}px)`,width:`${s}px`,height:`${a}px`}}return{state:n,update:t,getStyle:o}}var pa=Math.PI/180;function ga(e){let{camera:n,tileSize:t,viewportCenterX:o,viewportCenterY:r,mouseX:i,mouseY:s}=e,a=n.rotX*pa,c=n.rotY*pa,l=n.zoom/t,u=n.target,f=i-o,d=s-r,m=f/l,p=d/l,g=Math.cos(a),h=Math.sin(a),y=m,b=p*g,x=-p*h,P=0,M=h,C=g,E=Math.cos(c),A=Math.sin(c),S=y*E+b*A,T=-y*A+b*E,v=x,R=P*E+M*A,O=-P*A+M*E,L=C,D=u[1]*t,_=u[0]*t,w=u[2]*t,V=S+D,j=T+_,G=v+w,Z=[j/t,V/t,G/t],ee=[O/t,R/t,L/t];return{origin:Z,direction:ee}}function df(e){let{origin:n,direction:t}=ga(e),{sphereCenter:o,sphereRadius:r}=e,i=n[0]-o[0],s=n[1]-o[1],a=n[2]-o[2],c=t[0],l=t[1],u=t[2],f=c*c+l*l+u*u;if(f===0)return null;let d=2*(i*c+s*l+a*u),m=i*i+s*s+a*a-r*r,p=d*d-4*f*m;if(p>=0){let E=Math.sqrt(p),A=(-d-E)/(2*f),S=(-d+E)/(2*f),T=t[2]>=0?Math.max(A,S):Math.min(A,S);return[n[0]+T*t[0],n[1]+T*t[1],n[2]+T*t[2]]}let g=-(i*c+s*l+a*u)/f,h=n[0]+g*c,y=n[1]+g*l,b=n[2]+g*u,x=h-o[0],P=y-o[1],M=b-o[2],C=Math.hypot(x,P,M);return C===0?null:[o[0]+x/C*r,o[1]+P/C*r,o[2]+M/C*r]}var On=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Po=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],wt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Or=e=>Math.hypot(e[0],e[1],e[2]),rt=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function pf(e){return`${e[0]},${e[1]},${e[2]}`}function ba(e){if(e.length<3)return null;let n=On(e[1],e[0]),t=On(e[2],e[0]),o=Po(n,t),r=Or(o);if(r<1e-12)return null;let i=[o[0]/r,o[1]/r,o[2]/r],s=wt(i,e[0]);return{normal:i,d:s}}function gf(e,n){return wt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function hf(e,n){return wt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function yf(e,n,t,o){let r=e.vertices.findIndex(A=>rt(A,t)),i=e.vertices.findIndex(A=>rt(A,o)),s=n.vertices.findIndex(A=>rt(A,t)),a=n.vertices.findIndex(A=>rt(A,o));if(r<0||i<0||s<0||a<0)return null;let c=e.vertices.length,l=n.vertices.length,u=(r+1)%c===i,f=(s+1)%l===a;if(u===f)return null;let d=u?i:r,m=u?r:i,p=f?a:s,g=f?s:a,h=!!(e.uvs&&n.uvs),y=[],b=h?[]:void 0,x=d;for(;y.push(e.vertices[x]),b&&b.push(e.uvs[x]),x!==m;)x=(x+1)%c;for(x=p;y.push(n.vertices[x]),b&&b.push(n.uvs[x]),x!==g;)x=(x+1)%l;let P=[],M=b?[]:void 0;for(let A=0;A<y.length;A++)(P.length===0||!rt(y[A],P[P.length-1]))&&(P.push(y[A]),M&&b&&M.push(b[A]));if(P.length>1&&rt(P[0],P[P.length-1])&&(P.pop(),M?.pop()),h)return ya(P,M);let C=[],E=M?[]:void 0;for(let A=0;A<P.length;A++){let S=P[(A-1+P.length)%P.length],T=P[A],v=P[(A+1)%P.length],R=Po(On(T,S),On(v,S));Or(R)>1e-9&&(C.push(T),E&&M&&E.push(M[A]))}return C.length<3?null:ya(C,E)}function bf(e,n){let t=e.length,o=0;for(let r=0;r<t;r++){let i=e[r],s=e[(r+1)%t],a=e[(r+2)%t],c=On(s,i),l=On(a,s),u=wt(Po(c,l),n);if(Math.abs(u)<1e-9)continue;let f=u>0?1:-1;if(o===0)o=f;else if(f!==o)return!1}return!0}function xf(e,n){if(e.length<3)return!1;let t=ba(e);if(!t)return!1;for(let o of e)if(Math.abs(wt(t.normal,o)-t.d)>n)return!1;return!0}function Pf(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function _r(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function Vr(e){return e?{...e}:void 0}function ha(e){if(e)return{...e,imageSource:_r(e.imageSource),presentation:Vr(e.presentation)}}function Mf(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function Sf(e,n){return(e??"")===(n??"")}function Af(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function ya(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length];if(!(Or(Po(On(r,o),On(i,o)))<=1e-9))return t===0?{vertices:e,uvs:n}:{vertices:[...e.slice(t),...e.slice(0,t)],uvs:n?[...n.slice(t),...n.slice(0,t)]:void 0}}return{vertices:e,uvs:n}}function fn(e){let n=[],t=[],o=new WeakMap,r=m=>{let p=o.get(m);if(p)return p;let g=pf(m);return o.set(m,g),g},i=(m,p)=>{let g=r(m),h=r(p);return g<h?`${g}|${h}`:`${h}|${g}`},s=(m,p)=>r(m)<r(p)?1:-1,a=m=>{let p=new Map;for(let g=0;g<m.length;g++){let h=m[g],y=m[(g+1)%m.length];p.set(i(h,y),s(h,y))}return p},c=0,l=!1,u=m=>(c+=m,c<=8e6?!0:(l=!0,!1));for(let m of e??[]){if(!m||!m.vertices||m.vertices.length<3){m&&n.push(m);continue}let p=m.vertices,g=ba(p);if(!g){n.push(m);continue}let h=m.texture&&m.uvs&&m.uvs.length===p.length?m.uvs.map(b=>[b[0],b[1]]):void 0,y=m.texture&&h?m.textureTriangles?.length?Pf(m.textureTriangles):Af(p,h):void 0;t.push({vertices:p,uvs:h,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureImageSource:_r(m.textureImageSource),texturePresentation:Vr(m.texturePresentation),material:ha(m.material),textureTriangles:y,normal:g.normal,d:g.d,edgeDirections:a(p),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let h=0;h<t.length;h++){let y=t[h];if(!y.alive)continue;let b=y.vertices.length;if(!u(b))return!1;for(let x=0;x<b;x++){let P=y.vertices[x],M=y.vertices[(x+1)%b],C=i(P,M),E=m.get(C);E?E.second<0&&(E.second=h):(E={a:P,b:M,first:h,second:-1},m.set(C,E))}}let p=!1,g=(h,y,b)=>{let x=h.edgeDirections.get(i(y,b));return x?x===s(y,b)?1:-1:0};for(let h of m.values()){if(h.second<0)continue;let y=h.first,b=h.second;if(y===b)continue;let x=t[y],P=t[b];if(!x.alive||!P.alive||x.color!==P.color||x.texture!==P.texture||!Mf(x.textureWrap,P.textureWrap)||!Sf(x.textureAlphaMode,P.textureAlphaMode)||x.doubleSided!==P.doubleSided)continue;let M=!!(x.texture||P.texture);if(M&&(!x.textureTriangles||!P.textureTriangles)||!!x.uvs!=!!P.uvs||(M?!hf(x,P):!gf(x,P)))continue;if(!u(x.vertices.length+P.vertices.length))return!1;let C=g(x,h.a,h.b);if(C===0)continue;let E=g(P,h.a,h.b);if(E===0||C===E)continue;let[A,S]=C===1?[h.a,h.b]:[h.b,h.a],T=yf(x,P,A,S);if(T){if(!u(T.vertices.length))return!1;T.vertices.length>96||xf(T.vertices,.001)&&bf(T.vertices,x.normal)&&(x.vertices=T.vertices,x.uvs=T.uvs,x.edgeDirections=a(T.vertices),x.textureTriangles=M?[...x.textureTriangles??[],...P.textureTriangles??[]]:void 0,P.alive=!1,p=!0)}}return p},d=0;for(;!l&&d<16&&f();)d++;for(let m of t){if(!m.alive)continue;let p={vertices:m.vertices.map(g=>[g[0],g[1],g[2]]),color:m.color};m.texture&&(p.texture=m.texture),m.texture&&m.textureWrap&&(p.textureWrap={...m.textureWrap}),m.texture&&m.textureAlphaMode&&(p.textureAlphaMode=m.textureAlphaMode),m.textureImageSource&&(p.textureImageSource=_r(m.textureImageSource)),m.texturePresentation&&(p.texturePresentation=Vr(m.texturePresentation)),m.material&&(p.material=ha(m.material)),m.uvs&&(p.uvs=m.uvs.map(g=>[g[0],g[1]])),m.textureTriangles?.length&&(p.textureTriangles=m.textureTriangles),m.doubleSided&&(p.doubleSided=!0),m.data&&(p.data=m.data),n.push(p)}return n}var Cf=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Tf=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],rn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function Ef(e,n){let t=e.vertices;if(!t||t.length<3)return null;let o=0,r=0,i=0;for(let g=0;g<t.length;g++){let h=t[g],y=t[(g+1)%t.length];o+=(h[1]-y[1])*(h[2]+y[2]),r+=(h[2]-y[2])*(h[0]+y[0]),i+=(h[0]-y[0])*(h[1]+y[1])}let s=Math.hypot(o,r,i);if(s<1e-12)return null;let a=[o/s,r/s,i/s],c=0,l=0,u=0;for(let g of t)c+=g[0],l+=g[1],u+=g[2];let f=1/t.length,d=[c*f,l*f,u*f],m=rn(a,d),p=s*.5;return{index:n,polygon:e,normal:a,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function vf(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&rn(e.normal,n.normal)<0}function If(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*rn(n,e),o=n[1]-e[1]*rn(n,e),r=n[2]-e[2]*rn(n,e),i=Math.hypot(t,o,r);t/=i,o/=i,r/=i;let s=[t,o,r],a=Tf(e,s);return{u:s,v:a}}function _f(e){if(e.local2D)return;let n=If(e.normal),t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.polygon.vertices){let c=rn(a,n.u),l=rn(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}e.local2D=t,e.bbox2D={min:[o,r],max:[i,s]},e.basis=n}function Vf(e,n){let t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.vertices){let c=rn(a,n.u),l=rn(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}return{local2D:t,bbox2D:{min:[o,r],max:[i,s]}}}function Of(e,n){return e.max[0]>=n.min[0]&&e.min[0]<=n.max[0]&&e.max[1]>=n.min[1]&&e.min[1]<=n.max[1]}function xa(e,n){let t=!1;for(let o=0,r=n.length-1;o<n.length;r=o++){let i=n[o],s=n[r];i[1]>e[1]!=s[1]>e[1]&&e[0]<(s[0]-i[0])*(e[1]-i[1])/(s[1]-i[1]+1e-30)+i[0]&&(t=!t)}return t}function Pa(e){let n=0,t=0;for(let o of e)n+=o[0],t+=o[1];return[n/e.length,t/e.length]}function Rf(e,n){let t=Pa(e),o=Pa(n),r=1e-4,i=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];xa(u,n)&&i++}let s=0;for(let l of n){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];xa(u,e)&&s++}let a=i/e.length,c=s/n.length;return Math.max(a,c)}function Lf(e,n){let t=e.normal[0],o=e.normal[1],r=e.normal[2],i=Math.abs(t),s=Math.abs(o),a=Math.abs(r),c=t;s>i&&s>a?c=o:a>i&&a>s&&(c=r),c<0&&(t=-t,o=-o,r=-r);let l=Math.round(t/.05),u=Math.round(o/.05),f=Math.round(r/.05),d=e.d*(e.normal[0]===t&&e.normal[1]===o&&e.normal[2]===r?1:-1),m=Math.round(d/(n*2));return`${l},${u},${f}|${m}`}function wf(e,n,t,o){let r=rn(e.normal,n.normal);if(Math.abs(r)<1-t)return!1;let i=r>0?1:-1;return Math.abs(e.d-i*n.d)<o}function Ma(e,n){let t=Cf(n,e.centroid);return rn(e.normal,t)>0}function Mo(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,o=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,i=n?.preserveDoubleSidedBackfaces??!0,s=[];for(let p=0;p<e.length;p++){let g=Ef(e[p],p);g&&s.push(g)}if(s.length<2)return new Set;let a=0,c=0,l=0,u=0;for(let p of s)a+=p.centroid[0]*p.area,c+=p.centroid[1]*p.area,l+=p.centroid[2]*p.area,u+=p.area;let f=u>0?[a/u,c/u,l/u]:[0,0,0],d=new Map;for(let p of s){let g=Lf(p,o),h=d.get(g);h||(h=[],d.set(g,h)),h.push(p)}let m=new Set;for(let p of d.values())if(!(p.length<2))for(let g=0;g<p.length;g++){let h=p[g];if(!m.has(h.index))for(let y=g+1;y<p.length;y++){let b=p[y];if(m.has(b.index)||!wf(h,b,t,o)||i&&vf(h,b))continue;_f(h);let x=Vf(b.polygon,h.basis);if(!Of(h.bbox2D,x.bbox2D)||Rf(h.local2D,x.local2D)<r)continue;let M=Ma(h,f),C=Ma(b,f),E;if(M&&!C?E=h:C&&!M?E=b:E=h.area<b.area?h:b,m.add(E.index),E===h)break}}return m}function Nf(e,n){if(!e||e.length<2)return e??[];let t=Mo(e,n);if(t.size===0)return e;let o=[];for(let r=0;r<e.length;r++)t.has(r)||o.push(e[r]);return o}var Df=4,Ff=8,Bf=.001,kf=1e-9,zf=1e6,Uf=1e6,Gf=8,Gn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],wr=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Ft=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],$n=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Ta=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],Ea=e=>Math.hypot(e[0],e[1],e[2]);function Bt(e){let n=Ea(e);return n<=kf?null:[e[0]/n,e[1]/n,e[2]/n]}function Dt(e,n){return Math.round(e*n)/n}function sn(e){return Dt(e,zf)}function Rr(e){return Dt(e,Uf)}function Lr(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function Pn(e){return`${sn(e[0])},${sn(e[1])}`}function $f(e){let n=Pn(e.a),t=Pn(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function it(e){return`${e[0]},${e[1]},${e[2]}`}function va(e,n){let t=it(e),o=it(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Nr(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Sa(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",Nr(e.data)].join("|")}function Ia(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],o=[0,0,0];for(let i=1;i<n.length-1;i++)o=wr(o,Ta(Gn(n[i],t),Gn(n[i+1],t)));let r=Bt(o);return r?{normal:r,d:$n(r,t)}:null}function Xf(e,n,t){return $n(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function Yf(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function jf(e,n){let t=n[e[0]]?.data,o=Nr(t);for(let r of e)if(Nr(n[r].data)!==o)return;return t?{...t}:void 0}function Wf(e,n){return e.every(t=>n[t].doubleSided===!0)}function Hf(e,n){let t=e.map(c=>Yf(c)?Ia(c):null),o=t.map(Boolean),r=new Map;for(let c=0;c<e.length;c++){if(!t[c])continue;let l=e[c].vertices;for(let u=0;u<l.length;u++){let f=va(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:c,edge:u};d?d.push(m):r.set(f,[m])}}let i=e.map(()=>new Set);for(let c of r.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l].polygon,d=c[u].polygon,m=t[f],p=t[d];!m||!p||Sa(e[f])===Sa(e[d])&&Xf(m,p,n)&&(i[f].add(d),i[d].add(f))}let s=new Set,a=[];for(let c=0;c<e.length;c++){if(!o[c]||s.has(c))continue;let l=[],u=[c];for(s.add(c);u.length>0;){let f=u.shift();l.push(f);for(let d of i[f])s.has(d)||(s.add(d),u.push(d))}a.push(l)}return{groups:a}}function Kf(e,n){let t=new Set(e),o=new Map;for(let i of e){let s=n[i].vertices;for(let a=0;a<s.length;a++){let c=va(s[a],s[(a+1)%s.length]),l=o.get(c),u={polygon:i,edge:a};l?l.push(u):o.set(c,[u])}}let r=[];for(let i of o.values()){let s=i.filter(a=>t.has(a.polygon));if(s.length===1){let a=s[0],c=n[a.polygon].vertices;r.push({a:c[a.edge],b:c[(a.edge+1)%c.length]})}else if(s.length!==2)return null}return r}function Zf(e){let n=new Map;for(let t of e)n.set(it(t.a),(n.get(it(t.a))??0)+1),n.set(it(t.b),(n.get(it(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function _a(e){let n=[e[0],e[1],e[2]],t=Math.abs(n[0])>=Math.abs(n[1])&&Math.abs(n[0])>=Math.abs(n[2])?0:Math.abs(n[1])>=Math.abs(n[2])?1:2;return n[t]<0?[-n[0],-n[1],-n[2]]:n}function qf(e){let n=_a(e);return`${Dt(n[0],1e3)},${Dt(n[1],1e3)},${Dt(n[2],1e3)}`}function Qf(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=Gn(n,Ft(e,$n(n,e)));return Bt(t)??[1,0,0]}function Jf(e,n,t){let o=new Map;for(let i of e){let s=Gn(i.b,i.a),a=Gn(s,Ft(n,$n(s,n))),c=Bt(a);if(!c)continue;let l=_a(c),u=qf(l),f=Ea(a),d=o.get(u);d?d.weight+=f:o.set(u,{axis:l,weight:f})}let r=[...o.values()].sort((i,s)=>s.weight-i.weight).slice(0,t).map(i=>i.axis);return r.length===0&&r.push(Qf(n)),r}function Aa(e,n,t,o){let r=Gn(e,n);return[sn($n(r,t)),sn($n(r,o))]}function em(e){let n=[...e].sort((o,r)=>o-r),t=[];for(let o of n)(t.length===0||Math.abs(o-t[t.length-1])>1e-7)&&t.push(o);return t}function Nt(e,n){let[t,o]=e.a,[r,i]=e.b,s=(n-t)/(r-t);return sn(o+(i-o)*s)}function Dr(e){let n=[];for(let o of e)(n.length===0||Math.abs(o[0]-n[n.length-1][0])>1e-7||Math.abs(o[1]-n[n.length-1][1])>1e-7)&&n.push(o);n.length>1&&Math.abs(n[0][0]-n[n.length-1][0])<=1e-7&&Math.abs(n[0][1]-n[n.length-1][1])<=1e-7&&n.pop();let t=[];for(let o=0;o<n.length;o++){let r=n[(o-1+n.length)%n.length],i=n[o],s=n[(o+1)%n.length],a=(i[0]-r[0])*(s[1]-i[1])-(i[1]-r[1])*(s[0]-i[0]);Math.abs(a)>1e-8&&t.push(i)}return t}function Ao(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-r[0]*o[1]}return n/2}function Co(e){let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let[i,s]of e)n=Math.min(n,i),t=Math.min(t,s),o=Math.max(o,i),r=Math.max(r,s);return{minX:n,minY:t,maxX:o,maxY:r}}function Va(e,n){return!(e.maxX<n.minX-1e-7||n.maxX<e.minX-1e-7||e.maxY<n.minY-1e-7||n.maxY<e.minY-1e-7)}function So(e){return Math.abs(Ao(e))}function nm(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-8)continue;let a=s>0?1:-1;if(n===0)n=a;else if(n!==a)return!1}return!0}function tm(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=e[0]-n[0],s=e[1]-n[1],a=o*s-r*i,c=Math.hypot(o,r);if(c<=1e-9||Math.abs(a)>Math.max(1e-8,c*1e-8))return!1;let l=i*o+s*r;return l>=-1e-8&&l<=o*o+r*r+1e-8}function om(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=o*o+r*r;return i<=1e-12?0:((e[0]-n[0])*o+(e[1]-n[1])*r)/i}function rm(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=Math.hypot(r,i),l=Math.hypot(s,a);if(c<=1e-9||l<=1e-9)return!1;let u=r*(t[1]-e[1])-i*(t[0]-e[0]),f=r*(o[1]-e[1])-i*(o[0]-e[0]),d=r*a-i*s,m=Math.max(1e-8,Math.max(c,l)*1e-8);if(Math.abs(u)>m||Math.abs(f)>m||Math.abs(d)>m)return!1;let p=Math.abs(r)>=Math.abs(i),g=Math.min(p?e[0]:e[1],p?n[0]:n[1]),h=Math.max(p?e[0]:e[1],p?n[0]:n[1]),y=Math.min(p?t[0]:t[1],p?o[0]:o[1]),b=Math.max(p?t[0]:t[1],p?o[0]:o[1]);return Math.min(h,b)-Math.max(g,y)>1e-8}function im(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];for(let i=0;i<n.length;i++)if(rm(o,r,n[i],n[(i+1)%n.length]))return!0}return!1}function Ca(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=[{t:0,point:r},{t:1,point:i}];for(let c of n)Lr(c,r)||Lr(c,i)||tm(c,r,i)&&s.push({t:om(c,r,i),point:c});s.sort((c,l)=>c.t-l.t);let a=[];for(let c of s)a.some(l=>Math.abs(l.t-c.t)<=1e-8||Lr(l.point,c.point))||a.push(c);for(let c=0;c<a.length-1;c++){let l=a[c].point,u=a[c+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||t.push({a:[sn(l[0]),sn(l[1])],b:[sn(u[0]),sn(u[1])]})}}return t}function sm(e,n,t=Co(e),o=Co(n)){if(!Va(t,o)||!im(e,n))return null;let r=[...Ca(e,n),...Ca(n,e)],i=new Map;for(let y of r){let b=$f(y),x=i.get(b);x?x.push(y):i.set(b,[y])}let s=!1,a=[];for(let y of i.values()){if(y.length===1){a.push(y[0]);continue}s=!0;let b=y.filter(P=>Pn(P.a)<Pn(P.b)).length,x=y.length-b;if(b!==x)return null}if(!s||a.length<3)return null;let c=new Map;for(let y of a){let b=Pn(y.a);if(c.has(b))return null;c.set(b,y)}let l=a[0],u=Pn(l.a),f=[],d=new Set,m=u;for(let y=0;y<=a.length;y++){let b=c.get(m);if(!b)return null;let x=`${Pn(b.a)}>${Pn(b.b)}`;if(d.has(x))return null;if(d.add(x),f.push(b.a),m=Pn(b.b),m===u)break}if(m!==u||d.size!==a.length)return null;let p=Dr(f);if(p.length<3||!nm(p))return null;let g=So(p),h=So(e)+So(n);return Math.abs(g-h)>Math.max(1e-5,h*1e-5)?null:Ao(p)>=0?p:[...p].reverse()}function am(e){let n=e.map(Dr).filter(r=>r.length>=3&&So(r)>1e-8),t=n.map(Co),o=!0;for(;o;){o=!1;for(let r=0;r<n.length;r++){for(let i=r+1;i<n.length;i++){if(!Va(t[r],t[i]))continue;let s=sm(n[r],n[i],t[r],t[i]);if(s){n[r]=s,t[r]=Co(s),n.splice(i,1),t.splice(i,1),o=!0;break}}if(o)break}}return n}function cm(e,n,t){let o=new Map;return r=>{let i=sn(r[0]),s=sn(r[1]),a=`${i},${s}`,c=o.get(a);if(c)return[c[0],c[1],c[2]];let l=wr(e,wr(Ft(n,i),Ft(t,s))),u=[Rr(l[0]),Rr(l[1]),Rr(l[2])];return o.set(a,u),[u[0],u[1],u[2]]}}function lm(e,n,t,o,r){let i=t[0]?.a;if(!i)return null;let s=Bt(Gn(r,Ft(o,$n(r,o))));if(!s)return null;let a=Bt(Ta(o,s));if(!a)return null;let c=[],l=[];for(let y of t){let b=Aa(y.a,i,s,a),x=Aa(y.b,i,s,a);Math.hypot(b[0]-x[0],b[1]-x[1])<=1e-7||(c.push({a:b,b:x}),l.push(b[0],x[0]))}let u=em(l);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,d=jf(e,n),m=Wf(e,n),p=[];for(let y=0;y<u.length-1;y++){let b=u[y],x=u[y+1];if(x-b<=1e-7)continue;let P=(b+x)/2,M=c.filter(C=>{let E=Math.min(C.a[0],C.b[0]),A=Math.max(C.a[0],C.b[0]);return E<P&&P<A&&Math.abs(C.a[0]-C.b[0])>1e-7}).map(C=>({segment:C,yMid:Nt(C,P)})).sort((C,E)=>C.yMid-E.yMid);if(M.length!==0){if(M.length%2!==0)return null;for(let C=0;C<M.length;C+=2){let E=M[C].segment,A=M[C+1].segment,S=Nt(E,b),T=Nt(E,x),v=Nt(A,b),R=Nt(A,x),O=Dr([[b,S],[x,T],[x,R],[b,v]]);if(O.length<3||Math.abs(Ao(O))<=1e-8)continue;let L=Ao(O)>0?O:[...O].reverse();p.push(L)}}}if(p.length===0||e.length>2&&p.length>e.length*Gf)return null;let g=cm(i,s,a),h=am(p).map(y=>({vertices:y.map(g),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return fn(h)}function um(e,n,t){let o=Kf(e,n);if(!o||o.length<3||!Zf(o))return null;let r=Ia(n[e[0]]);if(!r)return null;let i=null;for(let s of Jf(o,r.normal,t)){let a=lm(e,n,o,r.normal,s);a&&(!i||a.length<i.length)&&(i=a)}return!i||i.length>=e.length?null:i}function Fr(e,n={}){let t=n.minGroupPolygons??Df,o=n.maxCandidateAxes??Ff,r=n.planeEpsilon??Bf,i=e??[];if(i.length<t)return i;let{groups:s}=Hf(i,r);if(s.length===0)return i;let a=new Map,c=new Set;for(let u of s){if(u.length<t)continue;let f=um(u,i,o);if(f){a.set(u[0],f);for(let d of u)c.add(d)}}if(a.size===0)return i;let l=[];for(let u=0;u<i.length;u++){let f=a.get(u);if(f){l.push(...f);continue}c.has(u)||l.push(i[u])}return l}function fm(e,n){let t=`${e[0]},${e[1]},${e[2]}`,o=`${n[0]},${n[1]},${n[2]}`;return t<o?`${t}|${o}`:`${o}|${t}`}function mm(e){if(e.length<100)return!1;let n=new Map;for(let o of e){let r=o.vertices;for(let i=0;i<r.length;i++){let s=fm(r[i],r[(i+1)%r.length]);n.set(s,(n.get(s)??0)+1)}}let t=0;for(let o of n.values())o===1&&(t+=1);return t>=128&&t/Math.max(1,n.size)>.2}function dm(e,n,t){let o=Math.abs(e)>.9?0:1,r=Math.abs(e)>.9?1:0,i=r*t,s=-o*t,a=o*n-r*e,c=Math.hypot(i,s,a);return i/=c,s/=c,a/=c,{ux:i,uy:s,uz:a,vx:n*a-t*s,vy:t*i-e*a,vz:e*s-n*i}}function pm(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[j,G,Z]of n)t+=j,o+=G,r+=Z;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=dm(g,h,y),S=n.length-2,T=new Float64Array(S*9),v=0;for(let j=1;j<n.length-1;j++){let G=n[0],Z=n[j],ee=n[j+1];T[v++]=G[0],T[v++]=G[1],T[v++]=G[2],T[v++]=Z[0],T[v++]=Z[1],T[v++]=Z[2],T[v++]=ee[0],T[v++]=ee[1],T[v++]=ee[2]}let R=0,O=1/0,L=1/0,D=1/0,_=-1/0,w=-1/0,V=-1/0;for(let[j,G,Z]of n){let ee=j-t,W=G-o,ie=Z-r,z=ee*ee+W*W+ie*ie;z>R&&(R=z),j<O&&(O=j),j>_&&(_=j),G<L&&(L=G),G>w&&(w=G),Z<D&&(D=Z),Z>V&&(V=Z)}return{centroid:[t,o,r],normal:[g,h,y],vertices:n,triFlat:T,bcx:t,bcy:o,bcz:r,br2:R,ux:x,uy:P,uz:M,vx:C,vy:E,vz:A,minX:O,minY:L,minZ:D,maxX:_,maxY:w,maxZ:V}}function gm(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function hm(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(gm(e,n,t,o,r,i,p,h))return!0;return!1}var kt=9,ym=6,He=8;function Br(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function bm(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*kt),l=0,u=new Float64Array(He),f=new Float64Array(He),d=new Float64Array(He),m=new Float64Array(He),p=new Float64Array(He),g=new Float64Array(He),h=new Int32Array(He),y=new Float64Array(He-1),b=new Int32Array(He-1),x=new Float64Array(He-1),P=new Int32Array(He-1);function M(C,E){let A=l++,S=A*kt,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=ym)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=Br(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ae=He/le;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),g.fill(-1/0),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ae|0;oe>=He&&(oe=He-1);let de=e[o[K]];de.minX<u[oe]&&(u[oe]=de.minX),de.maxX>m[oe]&&(m[oe]=de.maxX),de.minY<f[oe]&&(f[oe]=de.minY),de.maxY>p[oe]&&(p[oe]=de.maxY),de.minZ<d[oe]&&(d[oe]=de.minZ),de.maxZ>g[oe]&&(g[oe]=de.maxZ),h[oe]++}let _e=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<He-1;K++)u[K]<_e&&(_e=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=Br(_e,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=He-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=Br(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<He-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ae)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*kt+7]=ae,c[A*kt+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function kr(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*kt,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&hm(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function xm(e){let n=Oa.get(e);if(n)return n;let t=(1+Math.sqrt(5))/2,o=new Float64Array(e*3);for(let r=0;r<e;r++){let i=(r+.5)/e,s=Math.sqrt(Math.max(0,1-i*i)),a=2*Math.PI*(r/t);o[r*3]=s*Math.cos(a),o[r*3+1]=s*Math.sin(a),o[r*3+2]=i}return Oa.set(e,o),o}var Oa=new Map;function Mn(e,n){let t=n?.samples??8;if(e.length<4||t<1||!n?.force&&mm(e))return e;let o=Math.max(1,Math.ceil(t*(n?.minEscapeRatio??1/t))),r=e.map(pm),i=xm(t),s=[],a=bm(r),c=new Int32Array(Math.max(64,a.nodeCount)),l=192,u=new Float64Array(l);for(let f=0;f<e.length;f++){let d=r[f];if(!d){s.push(e[f]);continue}let m=d.normal[0],p=d.normal[1],g=d.normal[2],h=.001*m,y=.001*p,b=.001*g;{let D=d.centroid[0]+h,_=d.centroid[1]+y,w=d.centroid[2]+b;if(!kr(D,_,w,m,p,g,f,a,c)){s.push(e[f]);continue}}let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=d,S=d.centroid[0],T=d.centroid[1],v=d.centroid[2],R=d.vertices,O=R.length,L=0;u[L++]=S+h,u[L++]=T+y,u[L++]=v+b;for(let D=0;D<O;D++){let _=R[D];u[L++]=_[0]+(S-_[0])*.08+h,u[L++]=_[1]+(T-_[1])*.08+y,u[L++]=_[2]+(v-_[2])*.08+b}for(let D=0;D<O;D++){let _=R[D],w=R[(D+1)%O],V=(_[0]+w[0])*.5,j=(_[1]+w[1])*.5,G=(_[2]+w[2])*.5;u[L++]=V+(S-V)*.08+h,u[L++]=j+(T-j)*.08+y,u[L++]=G+(v-G)*.08+b}if(o<=1){let D=!1;e:for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!kr(ie,z,X,G,Z,ee,f,a,c)){D=!0;break e}}}D&&s.push(e[f])}else{let D=0;for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!kr(ie,z,X,G,Z,ee,f,a,c)){D++;break}}}D>=o&&s.push(e[f])}}return s}var Ba={overlapPx:1.25,maxGapPx:14,capacityScale:1},ka={budget:40};function Xn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function st(e){return typeof e=="number"?{overlapPx:Math.max(0,e)*.175,maxGapPx:14,capacityScale:1}:{overlapPx:Math.max(0,Xn(e?.overlapPx,1.25)),maxGapPx:Math.max(0,Xn(e?.maxGapPx,14)),capacityScale:Math.max(0,Xn(e?.capacityScale,1))}}function at(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function za(e){return{rotX:Xn(e?.rotX,65),rotY:Xn(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(Xn(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(Xn(e?.budget,40))))}}function Sn(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function Ua(e){return[e[1]/50,e[0]/50,e[2]/50]}function Vo(e){return`${e[0]},${e[1]},${e[2]}`}function Pm(e,n){let t=Vo(e),o=Vo(n);return t<o?`${t}|${o}`:`${o}|${t}`}function An(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function ct(e){return Math.hypot(e[0],e[1],e[2])}function $t(e){let n=ct(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function Gt(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function To(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function Xr(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Mm(e){if(e.length<3)return null;let n=e[0],t=[0,0,0];for(let o=1;o+1<e.length;o+=1){let r=An(e[o],n),i=An(e[o+1],n),s=Xr(r,i);t[0]-=s[0],t[1]-=s[1],t[2]-=s[2]}return $t(t)}function Yr(e){let n=e[0],t=Mm(e);if(!t)return null;let o=null;for(let u=0;u<e.length;u+=1){let f=An(e[(u+1)%e.length],e[u]);if(ct(f)>1e-6){o=f;break}}if(!o)return null;let r=Gt(o,t),i=[o[0]-r*t[0],o[1]-r*t[1],o[2]-r*t[2]],s=$t(i);if(!s)return null;let a=$t(Xr(t,s));if(!a)return null;let c=e.map(u=>{let f=An(u,n);return[Gt(f,s),Gt(f,a)]}),l=Oo(c);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:s,yAxis:a,local:c,area:l}:null}function Oo(e){let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function jr(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-6)continue;let a=Math.sign(s);if(n===0)n=a;else if(a!==n)return!1}return!0}function Ga(e,n,t){let o=e[t],r=e[(t+1)%e.length],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return null;let c=n>0?1:-1;return[c*(s/a),c*(-i/a)]}function Sm(e,n){let t=Ga(e.local,e.area,n);return t?$t([e.xAxis[0]*t[0]+e.yAxis[0]*t[1],e.xAxis[1]*t[0]+e.yAxis[1]*t[1],e.xAxis[2]*t[0]+e.yAxis[2]*t[1]]):null}function $a(e,n){let t=e.length,o=e[n],r=e[(n+1)%t],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return 0;let c=[a*.24],l=1/0;for(let f=0;f<t;f+=1){if(f===n||f===(n+1)%t)continue;let d=e[f],m=Math.abs((d[0]-o[0])*s-(d[1]-o[1])*i)/a;m>1e-6&&(l=Math.min(l,m))}Number.isFinite(l)&&c.push(l*.32);let u=[{origin:o,point:e[(n+t-1)%t]},{origin:r,point:e[(n+2)%t]}];for(let f of u){let d=f.point[0]-f.origin[0],m=f.point[1]-f.origin[1],p=Math.hypot(d,m);if(p<=1e-6)continue;let g=Math.abs(i*m-s*d)/(a*p);g>1e-6&&c.push(p*g*.32)}return Math.min(...c)}function Xa(e){return e.map(n=>{let t=Sn(n.vertices),o=Yr(t),r=!Wr(n)&&!!o&&jr(o.local),i=r?o.local.map((s,a)=>$a(o.local,a)):[];return{basis:o,cssPoints:t,capacities:i,patchable:r}})}function Wr(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Am(e){return e.material?.key??e.color??""}function Ya(e,n,t){let o=[];for(let r=0;r<n.length;r+=1){let i=n[r];if(!(!i.patchable||!i.basis))for(let s=0;s<i.cssPoints.length;s+=1){let a=i.cssPoints[s],c=i.cssPoints[(s+1)%i.cssPoints.length],l=An(c,a),u=ct(l),f=$t(l),d=Sm(i.basis,s),m=(i.capacities[s]??0)*t;!f||!d||m<=1e-6||u<=1e-6||o.push({index:o.length,polygon:r,edge:s,key:Pm(a,c),a,b:c,minX:Math.min(a[0],c[0]),minY:Math.min(a[1],c[1]),minZ:Math.min(a[2],c[2]),maxX:Math.max(a[0],c[0]),maxY:Math.max(a[1],c[1]),maxZ:Math.max(a[2],c[2]),length:u,dir:f,normal:i.basis.normal,outward:d,capacity:m,materialKey:Am(e[r]),color:e[r].color})}}return o}function Hr(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function Eo(e,n){return ct(An(e,n))<=1e-4}function Cm(e,n){return Eo(e.a,n.a)||Eo(e.a,n.b)||Eo(e.b,n.a)||Eo(e.b,n.b)}function Tm(e,n){return Hr(e,n)?Cm(e,n)?"connected-facet":"true-gap":"material-boundary"}function zr(e,n,t,o,r,i){return{kind:e,aPolygon:n.polygon,aEdge:n.edge,bPolygon:t.polygon,bEdge:t.edge,aColor:n.color,bColor:t.color,aMaterialKey:n.materialKey,bMaterialKey:t.materialKey,gapPx:o.gap,spanPx:o.aEnd-o.aStart,aStartPx:o.aStart,aEndPx:o.aEnd,bStartPx:o.bStart,bEndPx:o.bEnd,targetClosurePx:r,appliedClosurePx:i,residualGapPx:Math.max(0,o.gap-i),residualTargetPx:Math.max(0,r-i)}}function Ra(e,n,t,o,r){let i=Math.max(0,Math.min(n.length,Math.min(t,o))),s=Math.max(0,Math.min(n.length,Math.max(t,o)));if(r<=1e-6||s-i<=1e-6)return;let a=e[n.polygon].get(n.edge),c={start:i,end:s,amount:r};a?a.push(c):e[n.polygon].set(n.edge,[c])}function Ro(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function Em(e,n){let t=0,o=0,r=0;for(let i of e){i.size>0&&(r+=1),o+=i.size;for(let s of i.values())for(let a of s)t=Math.max(t,a.amount)}return{...n,patchedPolygons:r,patchedEdges:o,maxAppliedAmountPx:t}}function Lo(e,n,t=!1,o=!1){let r=Xa(e),i=Ya(e,r,n.capacityScale),s=o?[]:e.map(()=>new Map),a=Ro(),c=t?[]:void 0;if(i.length===0)return{edgeRepairs:s,diagnostics:a,candidates:c};let l=new Map;for(let u of i){let f=l.get(u.key);f?f.push(u):l.set(u.key,[u])}for(let u of l.values())u.length<2||(a.exactPairs+=u.length===2?1:u.length);return vm(i,l,s,a,n,c),{edgeRepairs:s,diagnostics:o?a:Em(s,a),candidates:c}}function vm(e,n,t,o,r,i){let s=r.maxGapPx,a=new Set;for(let[m,p]of n)p.length>1&&a.add(m);let c=(m,p)=>{let g=m.index<p.index?m:p,h=m.index<p.index?p:m;if(h.polygon===g.polygon||g.key===h.key&&a.has(g.key)||!i&&!Hr(g,h)||!Im(g,h,s)||Math.abs(Gt(g.dir,h.dir))<.985)return;let y=Rm(g,h,s);if(!y)return;let b=Tm(g,h),x=y.gap+r.overlapPx;if(b==="material-boundary"){i?.push(zr(b,g,h,y,x,0));return}let P=x;if(P<=.25){i?.push(zr(b,g,h,y,x,0));return}let M=g.capacity*y.facingA,C=h.capacity*y.facingB,E=Math.min(M,P/2),A=Math.min(C,P/2);if(P-=E+A,P>1e-6){let S=Math.min(M-E,P);E+=S,P-=S}if(P>1e-6){let S=Math.min(C-A,P);A+=S,P-=S}i?.push(zr(b,g,h,y,x,E+A)),t.length>0&&E>1e-6&&Ra(t,g,y.aStart,y.aEnd,E/y.facingA),t.length>0&&A>1e-6&&Ra(t,h,y.bStart,y.bEnd,A/y.facingB),o.nearPairs+=1,o.maxMeasuredGapPx=Math.max(o.maxMeasuredGapPx,y.gap),P>.25&&(o.unclosedPairs+=1,o.maxResidualGapPx=Math.max(o.maxResidualGapPx,P))},l=Math.max(28,s*2);if(e.length<=1e4){let m=[...e].sort((h,y)=>h.minX-y.minX),p=new Int32Array(m.length),g=0;for(let h=0;h+1<m.length;h+=1){let b=m[h].maxX+s,x=h+1;for(;x<m.length&&m[x].minX<=b;)x+=1;if(p[h]=x,g+=x-h-1,g>25e6)break}if(g<=2e6||g<=25e6&&Om(e,l,s)){for(let h=0;h+1<m.length;h+=1)for(let y=h+1;y<p[h];y+=1)c(m[h],m[y]);return}}let u=new Map;for(let m of e)_m(u,m,l,s);let f=new Set,d=e.length;for(let m of u.values())for(let p=0;p+1<m.length;p+=1)for(let g=p+1;g<m.length;g+=1){let h=m[p],y=m[g],b=h.index<y.index?h:y,x=h.index<y.index?y:h,P=b.index*d+x.index;f.has(P)||(f.add(P),c(b,x))}}function Im(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function La(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function _m(e,n,t,o){let[r,i,s,a,c,l]=ja(n,t,o);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function ja(e,n,t){let[o,r,i]=La([e.minX-t,e.minY-t,e.minZ-t],n),[s,a,c]=La([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[o,r,i,s,a,c]}function Vm(e,n,t){let[o,r,i,s,a,c]=ja(e,n,t);return(s-o+1)*(a-r+1)*(c-i+1)}function Om(e,n,t){let o=0,r=0;for(let i of e){let s=Vm(i,n,t);if(o+=s,s>r&&(r=s),r>8192)return!0}return o/Math.max(1,e.length)>256}function wa(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function Na(e,n,t){return(e.a[0]+e.dir[0]*n-t.a[0])*t.dir[0]+(e.a[1]+e.dir[1]*n-t.a[1])*t.dir[1]+(e.a[2]+e.dir[2]*n-t.a[2])*t.dir[2]}function Rm(e,n,t){let o=wa(n.a,e.a,e.dir),r=wa(n.b,e.a,e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i,c=Math.min(e.length,n.length);if(a<Math.max(.75,c*.12))return null;let l=(i+s)/2,u=e.a[0]+e.dir[0]*l,f=e.a[1]+e.dir[1]*l,d=e.a[2]+e.dir[2]*l,m=Math.max(0,Math.min(n.length,(u-n.a[0])*n.dir[0]+(f-n.a[1])*n.dir[1]+(d-n.a[2])*n.dir[2])),p=n.a[0]+n.dir[0]*m-u,g=n.a[1]+n.dir[1]*m-f,h=n.a[2]+n.dir[2]*m-d,y=Math.hypot(p,g,h);if(y<=1e-6||y>t||y>Math.min(t,Math.max(4,c*.28)))return null;let b=1/y,x=p*b,P=g*b,M=h*b,C=e.outward[0]*x+e.outward[1]*P+e.outward[2]*M,E=-(n.outward[0]*x+n.outward[1]*P+n.outward[2]*M);if(C<.5||E<.5)return null;let A=Math.max(0,Math.min(n.length,Na(e,i,n))),S=Math.max(0,Math.min(n.length,Na(e,s,n)));return{gap:y,facingA:C,facingB:E,aStart:i,aEnd:s,bStart:Math.min(A,S),bEnd:Math.max(A,S)}}function Ur(e,n,t,o){let r=t<=1e-6?0:Math.max(0,Math.min(1,o/t));return[e[0]+(n[0]-e[0])*r,e[1]+(n[1]-e[1])*r]}function zt(e,n){let t=e[e.length-1];t&&Math.hypot(t[0]-n[0],t[1]-n[1])<=1e-6||e.push(n)}function Lm(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let o=new Set([0,n]);for(let s of e){let a=Math.max(0,Math.min(n,s.start)),c=Math.max(0,Math.min(n,s.end));c-a<=1e-6||s.amount<=1e-6||(o.add(a),o.add(c))}let r=Array.from(o).sort((s,a)=>s-a),i=[];for(let s=0;s+1<r.length;s+=1){let a=r[s],c=r[s+1];if(c-a<=1e-6)continue;let l=(a+c)/2,u=0;for(let d of e)l+1e-6<d.start||l-1e-6>d.end||(u=Math.max(u,d.amount));let f=Math.min(t,u);f>1e-6&&i.push({start:a,end:c,amount:f})}return i}function wm(e,n){if(n.length<3||!jr(n))return!1;let t=Oo(e),o=Oo(n);return Math.sign(o)===Math.sign(t)&&Math.abs(o)>=Math.abs(t)-1e-6}function Nm(e,n,t){if(n.size===0||e.vertices.length<3||Wr(e))return e;let o=Sn(e.vertices),r=Yr(o);if(!r||!jr(r.local))return e;let i=[];for(let l=0;l<r.local.length;l+=1){let u=r.local[l],f=r.local[(l+1)%r.local.length],d=Math.hypot(f[0]-u[0],f[1]-u[1]),m=Ga(r.local,r.area,l);if(!m||d<=1e-6)return e;let p=Lm(n.get(l),d,$a(r.local,l)*t);zt(i,u);let g=0;for(let h of p){h.start>g+1e-6&&zt(i,Ur(u,f,d,h.start));let y=Ur(u,f,d,h.start),b=Ur(u,f,d,h.end);zt(i,[y[0]+m[0]*h.amount,y[1]+m[1]*h.amount]),zt(i,[b[0]+m[0]*h.amount,b[1]+m[1]*h.amount]),h.end<d-1e-6&&zt(i,b),g=h.end}}let s=i[0],a=i[i.length-1];if(s&&a&&Math.hypot(s[0]-a[0],s[1]-a[1])<=1e-6&&i.pop(),!wm(r.local,i))return e;let c=i.map(([l,u])=>Ua([r.origin[0]+l*r.xAxis[0]+u*r.yAxis[0],r.origin[1]+l*r.xAxis[1]+u*r.yAxis[1],r.origin[2]+l*r.xAxis[2]+u*r.yAxis[2]]));return{...e,vertices:c}}function Wa(e){return e.vertices.length===4&&!Wr(e)}function Dm(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let[c,l]of n)t=Math.min(t,c),o=Math.min(o,l),r=Math.max(r,c),i=Math.max(i,l);let s=Math.max(1e-6,(r-t)*(i-o));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/s)))*2.5}function Gr(e,n){return ct(An(Sn([e])[0],Sn([n])[0]))}function vo(e,n,t){let o=Gr(e,n),r=Gr(n,t),i=Gr(t,e),s=Math.max(o,r,i);return s<=1e-6?0:ct(Xr(An(Sn([n])[0],Sn([e])[0]),An(Sn([t])[0],Sn([e])[0])))*.5/(s*s)}function Fm(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=r*a-i*s;if(Math.abs(c)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*s)/c;return[e[0]+f*r,e[1]+f*i]}function Bm(e,n){if(e.length<3||e.length!==n.length)return null;let t=Math.max(0,...n);if(t<=1e-6)return e;let o=Oo(e);if(Math.abs(o)<=1e-6)return null;let r=o>0?1:-1,i=[];for(let c=0;c<e.length;c+=1){let l=e[c],u=e[(c+1)%e.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=1e-6)return null;let p=Math.max(0,n[c]),g=r*(d/m)*p,h=r*(-f/m)*p;i.push({a:[l[0]+g,l[1]+h],b:[u[0]+g,u[1]+h]})}let s=[],a=Math.max(2,t*4);for(let c=0;c<e.length;c+=1){let l=i[(c+e.length-1)%e.length],u=i[c],f=Fm(l.a,l.b,u.a,u.b);if(!f)return null;let d=e[c],m=f[0]-d[0],p=f[1]-d[1],g=Math.hypot(m,p);s.push(g>a?[d[0]+m/g*a,d[1]+p/g*a]:f)}return s}function km(e,n){return[e.origin[0]+e.xAxis[0]*n[0]+e.yAxis[0]*n[1],e.origin[1]+e.xAxis[1]*n[0]+e.yAxis[1]*n[1],e.origin[2]+e.xAxis[2]*n[0]+e.yAxis[2]*n[1]]}function Io(e,n){let t=Yr(Sn(e));if(!t)return e;let o=Bm(t.local,n);return o?o.map(r=>Ua(km(t,r))):e}function zm(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[o,r,i,s]=e.vertices,a=Math.min(vo(o,r,i),vo(o,i,s)),c=Math.min(vo(o,r,s),vo(r,i,s)),l=u=>n.has(u)?.75:0;return a>=c?[{...t,vertices:Io([o,r,i],[l(0),l(1),1.25])},{...t,vertices:Io([o,i,s],[1.25,l(2),l(3)])}]:[{...t,vertices:Io([o,r,s],[l(0),1.25,l(3)])},{...t,vertices:Io([r,i,s],[l(1),l(2),1.25])}]}function Da(e){if(e.length===0)return{q1:1/0,median:1/0,q3:1/0,p70:1/0,p80:1/0,p88:1/0,p95:1/0,p97:1/0,max:1/0};let n=[...e].sort((o,r)=>o-r),t=o=>n[Math.min(n.length-1,Math.floor((n.length-1)*o))]??0;return{q1:t(.25),median:t(.5),q3:t(.75),p70:t(.7),p80:t(.8),p88:t(.88),p95:t(.95),p97:t(.97),max:n[n.length-1]??0}}function _o(e,n){let t=e[n];if(t===n)return n;let o=_o(e,t);return e[n]=o,o}function Um(e){let n=new Set,t=new Set;for(let o of e)o.sel&&t.add(o.comp);for(let o of e)if(t.has(o.comp))for(let r of o.e)n.add(r);return{endpoints:n}}function Gm(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function $m(e,n,t,o){let r=[];for(let[c,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!Hr(u,f))continue;let d=l.filter(C=>Wa(e[C.polygon]));if(d.length===0)continue;let m=d[0],p=1-Math.min(1,Math.abs(Gt(u.normal,f.normal))),g=Math.max(u.length,f.length);if(p<.01&&g<64)continue;let h=Math.max(...d.map(C=>Dm(n[C.polygon]))),y=d.length===2?1.18:1,b=Math.max(.08,p),x=o.viewAware?Xm(u,f,o.rotX,o.rotY):{proj:g,vr:1},P=o.viewAware?Math.max(x.proj,g*.12):g,M=o.viewAware?.18+x.vr*1.82:1;r.push({key:c,e:[Vo(m.a),Vo(m.b)],o:l,r:d,len:g,rank:P,proj:x.proj,s:P*(.58+b*2.8)*h*y*M,nr:p,sr:h,vr:x.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let i=Array.from({length:r.length},(c,l)=>l),s=new Map;for(let c=0;c<r.length;c+=1)for(let l of r[c].e){let u=s.get(l);if(u===void 0)s.set(l,c);else{let f=_o(i,u),d=_o(i,c);f!==d&&(i[d]=f)}}let a=new Map;for(let c=0;c<r.length;c+=1){let l=_o(i,c),u=a.get(l);u===void 0&&(u=a.size,a.set(l,u)),r[c].comp=u}return r}function Xm(e,n,t,o){let r=To(e.a,t,0,o),i=To(e.b,t,0,o),s=Math.hypot(i[0]-r[0],i[1]-r[1]),a=To(e.normal,t,0,o)[2],c=To(n.normal,t,0,o)[2],l=Math.max(0,a,c),u=Math.min(1,Math.abs(a-c));return{proj:s,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function Ym(e){let n=new Map;for(let t of e){let o=n.get(t.comp);(!o||t.s>o.s||t.s===o.s&&t.len>o.len)&&n.set(t.comp,t)}return new Set(n.values())}function Ut(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+n*n*n*3.65,o=e.r.length===1?1.08:1;return e.rank*t*o/Math.sqrt(Math.max(1,e.r.length))}function Fa(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+Math.min(1,e.vr)*1.65,o=.7+Math.min(2.6,e.sr)*.3,r=e.r.length===1?1.1:1,i=e.rank*(.6+n*n*1.4)*t*o*r/Math.sqrt(Math.max(1,e.r.length));return Math.max(i,Ut(e)*.75)}function $r(e){let n=new Set;for(let t of e)for(let o of t.r)n.add(o.polygon);return n.size}function Ha(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function jm(e,n,t){return e.s>=n||e.rank>=t}function Wm(e,n,t,o,r,i,s){let a=Math.max(0,Math.floor(t));if(a<=0||e.length===0||n==="follow-up")return{budgetLimit:a,componentBudgets:null};let c=new Map;for(let m of e){let p=c.get(m.comp);p?p.push(m):c.set(m.comp,[m])}let l=new Map,u=Math.max(1e-6,o.q3-o.q1),f=Math.min(o.max,Math.max(o.p95,o.q3+u)),d=0;for(let[m,p]of c){let g=p.filter(M=>jm(M,i,s)||M.s>=f);if(g.length===0)continue;let h=p.filter(M=>Ha(M,r)),y=$r(g),b=$r(h),x=Math.ceil(Math.sqrt(Math.max(0,b-y))*3),P=Math.min($r(p),y+x);P<=0||(l.set(m,P),d+=P)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(a,d),componentBudgets:l}}function Hm(e,n,t){let o=new Map;if(e.length===0||t<=0)return{selected:o,budgetLimit:0};let r=Da(e.map(S=>S.s)),i=Da(e.map(S=>S.rank)),s=Math.max(1e-6,r.q3-r.q1),a=Math.min(r.max,Math.max(r.p95,r.q3+s*.85)),c=Math.min(r.max,Math.max(r.p80,r.q3+s*.15)),l=Math.min(r.max,Math.max(r.p70,r.q3)),u=Math.max(i.p97,i.median*1.8),f=Math.max(i.p88,i.median*1.35),d=Wm(e,n,t,r,i,a,u),m=d.budgetLimit;if(m<=0)return{selected:o,budgetLimit:0};let p=Ym(e),g=new Set,h=new Set,y=new Set,b=new Map,x=n==="primary"?Math.min(Math.max(0,d.budgetLimit-1),Math.max(2,Math.floor(d.budgetLimit*.28))):0,P=[...e].sort((S,T)=>Ut(T)-Ut(S)||T.s/Math.max(1,T.r.length)-S.s/Math.max(1,S.r.length)||T.len-S.len),M=[...e].sort((S,T)=>Fa(T)-Fa(S)||Ut(T)-Ut(S)||T.len-S.len),C=(S,T)=>{S.sel=!0,S.why=T,y.add(S.comp);for(let v of S.e)h.add(v);for(let v of S.r){g.add(v.polygon);let R=o.get(v.polygon);R?R.add(v.edge):o.set(v.polygon,new Set([v.edge]))}},E=(S,T)=>{let v=d.componentBudgets;if(T<=0||!v)return!0;let R=v.get(S.comp)??0;return(b.get(S.comp)??0)+T<=R},A=(S,T)=>{T<=0||!d.componentBudgets||b.set(S.comp,(b.get(S.comp)??0)+T)};for(let S of M){let T=S.r.reduce((R,O)=>R+(g.has(O.polygon)?0:1),0);if(S.cost=T,!(T>m||!E(S,T)||T>0&&m-T<x||!Ha(S,i))&&(C(S,"global-outlier"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((D,_)=>D+(g.has(_.polygon)?0:1),0);if(S.cost=T,T>m||!E(S,T)||T>0&&m-T<x)continue;let v=S.r.length===2,R=p.has(S)&&(n==="primary"||n==="follow-up"&&S.s>=c*1.08&&S.rank>=f)&&(v?S.s>=c||S.rank>=f:S.s>=c*1.18||S.rank>=f*1.12),O=v?S.s>=a||S.rank>=u:S.s>=a*1.35||S.rank>=u*1.2,L=T===0&&(v?S.s>=l||S.rank>=f:S.s>=l*1.25||S.rank>=f*1.12);if(!(!R&&!O&&!L)&&(C(S,R?"component-anchor":O?"global-outlier":"shared-polygon"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((_,w)=>_+(g.has(w.polygon)?0:1),0);if(S.cost=T,T>1||T>m||!E(S,T))continue;let v=S.r.some(_=>g.has(_.polygon)),R=S.e.some(_=>h.has(_));if(n==="primary"&&S.r.length===1&&T===1&&(y.has(S.comp)||R||v)&&S.rank>=f*1.05&&S.nr>=.16&&S.vr<=.32){if(C(S,"local-follow-up"),A(S,T),m-=T,m<=0)return{selected:o,budgetLimit:d.budgetLimit};continue}if(S.r.length!==2)continue;let L=v&&T===1&&S.proj>=f*1.45&&S.vr<=.18;if(!R&&!L)continue;if((S.s>=l*.42||S.rank>=f*.62)&&S.s<=l*1.1&&S.proj>=24&&(C(S,"local-follow-up"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}return{selected:o,budgetLimit:d.budgetLimit}}function Ka(e,n,t,o,r){let i=Xa(e),s=Ya(e,i,n.capacityScale),a=new Map;for(let u of s){let f=a.get(u.key);f?f.push(u):a.set(u.key,[u])}let c=$m(e,i,a,t).filter(u=>Gm(u,r)),l=Hm(c,r?"follow-up":"primary",o);return{selected:l.selected,candidates:c,budgetLimit:l.budgetLimit}}function Km(e,n){let t=[];for(let o=0;o<e.length;o+=1){let r=e[o],i=n.get(o);i&&Wa(r)?t.push(...zm(r,i)):t.push(r)}return t}function Zm(e){let[n,t]=e.o,o=n??t,r=t??n;return{key:e.key,aPolygon:o?.polygon??-1,aEdge:o?.edge??-1,bPolygon:r?.polygon??-1,bEdge:r?.edge??-1,color:o?.color??r?.color,materialKey:o?.materialKey??r?.materialKey??"",lengthPx:e.len,projectedLengthPx:e.proj,score:e.s,normalRisk:e.nr,shapeRisk:e.sr,viewRisk:e.vr,component:e.comp,marginalCost:e.cost,selected:e.sel,reason:e.why}}function Za(e,n,t){let o=st(n),r=za(t);if(!at(o,n)||e.length===0)return e;let i=e,s,a=r.budget;for(let c=0;c<r.passes;c+=1){let l=Ka(i,o,r,a,s);if(c===0&&(a=Math.min(a,l.budgetLimit)),l.selected.size===0)break;let u=Km(i,l.selected);if(u.length===i.length)break;if(a-=l.selected.size,a<=0){i=u;break}s=Um(l.candidates),i=u}return i}function qm(e,n,t){let o=st(n),r=za(t);if(!at(o,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let i=Ka(e,o,r,r.budget),s=0;for(let a of i.selected.values())s+=a.size;return{candidates:i.candidates.map(Zm),selectedPolygons:i.selected.size,selectedEdges:s,addedPolygons:i.selected.size}}function qa(e,n){let t=st(n);if(!at(t,n)||e.length===0)return e;let{edgeRepairs:o}=Lo(e,t);return o.some(r=>r.size>0)?e.map((r,i)=>Nm(r,o[i],t.capacityScale)):e}function Qm(e,n=Ba,t=ka){if(e.length===0)return e;let o=Za(e,n,t);return qa(o,n)}function Jm(e,n){let t=st(n);return!at(t,n)||e.length===0?Ro():Lo(e,t).diagnostics}function Qa(e,n){let t=st(n);return!at(t,n)||e.length===0?Ro():Lo(e,t,!1,!0).diagnostics}function ed(e,n){let t=st(n);if(!at(t,n)||e.length===0)return{diagnostics:Ro(),candidates:[]};let o=Lo(e,t,!0);return{diagnostics:o.diagnostics,candidates:o.candidates??[]}}var Yn={ratio:.7,maxError:.18,maxNormalDot:Math.cos(65*Math.PI/180),preserveVertices:!0,vertexKeyMode:"relaxed",lockBoundary:!0,minGroupTriangles:80,maxPasses:12};function nd(e={}){let n=Number.isFinite(e.ratio)?Math.max(.05,Math.min(.98,e.ratio)):Yn.ratio,t=Number.isFinite(e.maxError)&&e.maxError>0?e.maxError:Yn.maxError,o=Number.isFinite(e.maxNormalAngleDeg)?Math.max(0,Math.min(89,e.maxNormalAngleDeg)):65;return{ratio:n,maxError:t,maxNormalDot:Math.cos(o*Math.PI/180),preserveVertices:e.preserveVertices??Yn.preserveVertices,vertexKeyMode:e.vertexKeyMode??Yn.vertexKeyMode,lockBoundary:e.lockBoundary??Yn.lockBoundary,minGroupTriangles:Math.max(3,Math.floor(e.minGroupTriangles??Yn.minGroupTriangles)),maxPasses:Math.max(1,Math.floor(e.maxPasses??Yn.maxPasses))}}function td(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function od(e){return e.vertices.length===3&&!td(e)}function rd(e){return[e.color??"",e.doubleSided===!0?"2":"1",e.material?.key??""].join("\0")}function Ja(e){return`${Math.round(e[0]*1e5)},${Math.round(e[1]*1e5)},${Math.round(e[2]*1e5)}`}function id(e,n,t,o){let r=o.vertexKeyMode==="source"?e.simplifySourceVertexKeys?.[t]??e.simplifyVertexKeys?.[t]:e.simplifyVertexKeys?.[t];return r?`${Ja(n)}|${r}`:Ja(n)}function sd(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function lt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function ad(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function Kr(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function ec(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Qr(e){return Math.hypot(e[0],e[1],e[2])}function Zr(e,n){return Qr(lt(e,n))}function cd(e){let n=Qr(e);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n]:[0,0,1]}function Jr(e,n,t,o){return cd(ec(lt(e[t],e[n]),lt(e[o],e[n])))}function nc(e,n,t,o){return Qr(ec(lt(e[t],e[n]),lt(e[o],e[n])))/2}function ld(){return[0,0,0,0,0,0,0,0,0,0]}function wo(e,n){for(let t=0;t<e.length;t+=1)e[t]+=n[t]}function ud(e,n,t){let o=e[0],r=e[1],i=e[2],s=-Kr(e,n);return[o*o*t,o*r*t,o*i*t,o*s*t,r*r*t,r*i*t,r*s*t,i*i*t,i*s*t,s*s*t]}function qr(e,n){let t=n[0],o=n[1],r=n[2];return e[0]*t*t+2*e[1]*t*o+2*e[2]*t*r+2*e[3]*t+e[4]*o*o+2*e[5]*o*r+2*e[6]*o+e[7]*r*r+2*e[8]*r+e[9]}function fd(e,n,t,o,r,i,s,a,c,l,u,f){let d=e*(r*c-i*a)-n*(o*c-i*s)+t*(o*a-r*s);if(Math.abs(d)<1e-10)return null;let m=1/d,p=l*(r*c-i*a)-n*(u*c-i*f)+t*(u*a-r*f),g=e*(u*c-i*f)-l*(o*c-i*s)+t*(o*f-u*s),h=e*(r*f-u*a)-n*(o*f-u*s)+l*(o*a-r*s),y=[p*m,g*m,h*m];return y.every(Number.isFinite)?y:null}function md(e,n,t,o){let r=fd(e[0],e[1],e[2],e[1],e[4],e[5],e[2],e[5],e[7],-e[3],-e[6],-e[8]),i=ad(sd(n,t),.5),s=Zr(n,t)*1.35,a=o?[n,t]:[n,t,i,...r&&Zr(r,i)<=s?[r]:[]],c=a[0],l=qr(e,c);for(let u=1;u<a.length;u+=1){let f=a[u],d=qr(e,f);d<l&&(c=f,l=d)}return c}function dd(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function pd(e,n,t){return`${e}|${n}|${t}`}function gd(e,n){let t=new Map,o=[],r=[];for(let i of e){let s=[];for(let u=0;u<i.vertices.length;u+=1){let f=i.vertices[u],d=id(i,f,u,n),m=t.get(d);m===void 0&&(m=o.length,t.set(d,m),o.push([...f])),s.push(m)}let[a,c,l]=s;a===void 0||c===void 0||l===void 0||a===c||a===l||c===l||r.push({a,b:c,c:l,polygon:i,normal:Jr(o,a,c,l)})}return{vertices:o,triangles:r}}function hd(e,n){let t=gd(e,n),o=Array.from({length:t.vertices.length},()=>new Set),r=Array.from({length:t.triangles.length},()=>!0);for(let i=0;i<t.triangles.length;i+=1){let s=t.triangles[i];o[s.a].add(i),o[s.b].add(i),o[s.c].add(i)}return{vertices:t.vertices,triangles:t.triangles,alive:r,vertexTriangles:o,activeCount:t.triangles.length}}function yd(e){let n=new Map,t=(o,r,i)=>{let s=dd(o,r),a=n.get(s);a?a.triangles.push(i):n.set(s,{a:Math.min(o,r),b:Math.max(o,r),triangles:[i]})};for(let o=0;o<e.triangles.length;o+=1){if(!e.alive[o])continue;let r=e.triangles[o];t(r.a,r.b,o),t(r.b,r.c,o),t(r.c,r.a,o)}return n}function bd(e){let n=Array.from({length:e.vertices.length},()=>ld());for(let t=0;t<e.triangles.length;t+=1){if(!e.alive[t])continue;let o=e.triangles[t],r=Math.max(1e-6,nc(e.vertices,o.a,o.b,o.c)),i=ud(o.normal,e.vertices[o.a],Math.sqrt(r));wo(n[o.a],i),wo(n[o.b],i),wo(n[o.c],i)}return n}function xd(e,n,t){let o=new Set,r=i=>{let s=e.vertexTriangles[i];if(s)for(let a of s)e.alive[a]&&o.add(a)};return r(n),r(t),Array.from(o).sort((i,s)=>i-s)}function Pd(e,n,t){let o=e.vertexTriangles[n],r=e.vertexTriangles[t];if(!o||!r)return 0;let[i,s]=o.size<=r.size?[o,r]:[r,o],a=0;for(let c of i)e.alive[c]&&s.has(c)&&(a+=1);return a}function tc(e,n,t){return[e.a===t?n:e.a,e.b===t?n:e.b,e.c===t?n:e.c]}function Md(e,n,t){if(Pd(e,n.a,n.b)!==2)return null;let o=xd(e,n.a,n.b);if(o.length===0)return null;let r=e.vertices[n.a];e.vertices[n.a]=n.target;let i=0,s=!0;for(let a of o){let c=e.triangles[a],[l,u,f]=tc(c,n.a,n.b);if(l===u||l===f||u===f)continue;if(nc(e.vertices,l,u,f)<=1e-8){s=!1;break}let m=Jr(e.vertices,l,u,f);if(Kr(c.normal,m)<t.maxNormalDot){s=!1;break}let p=c.a===n.a?r:e.vertices[c.a];if(Math.abs(Kr(c.normal,lt(n.target,p)))>t.maxError){s=!1;break}i+=1}return e.vertices[n.a]=r,s&&i>0?o:null}function Sd(e,n,t){e.vertexTriangles[t.a]?.delete(n),e.vertexTriangles[t.b]?.delete(n),e.vertexTriangles[t.c]?.delete(n)}function Ad(e,n,t){e.vertexTriangles[t.a].add(n),e.vertexTriangles[t.b].add(n),e.vertexTriangles[t.c].add(n)}function Cd(e,n,t){e.vertices[n.a]=n.target;let o=new Set;for(let r of t){if(!e.alive[r])continue;let i=e.triangles[r],[s,a,c]=tc(i,n.a,n.b);if(Sd(e,r,i),s===a||s===c||a===c){e.alive[r]=!1,e.activeCount-=1;continue}let l=pd(s,a,c);if(o.has(l)){e.alive[r]=!1,e.activeCount-=1;continue}o.add(l);let u={...i,a:s,b:a,c,normal:Jr(e.vertices,s,a,c)};e.triangles[r]=u,Ad(e,r,u)}}function Td(e,n){let t=yd(e),o=new Set;for(let a of t.values())a.triangles.length>2&&(o.add(a.a),o.add(a.b));if(n.lockBoundary)for(let a of t.values())a.triangles.length===1&&(o.add(a.a),o.add(a.b));let r=bd(e),i=n.maxError*n.maxError,s=[];for(let a of t.values()){if(a.triangles.length!==2||o.has(a.a)||o.has(a.b))continue;let c=[...r[a.a]];wo(c,r[a.b]);let l=md(c,e.vertices[a.a],e.vertices[a.b],n.preserveVertices),u=Math.max(0,qr(c,l));if(u>i*Math.max(1,a.triangles.length))continue;let f=Zr(e.vertices[a.a],e.vertices[a.b]);s.push({a:a.a,b:a.b,target:l,error:u,length:f})}return s.sort((a,c)=>a.error-c.error||a.length-c.length),s}function Ed(e){let n=[];for(let t=0;t<e.triangles.length;t+=1)e.alive[t]&&n.push(e.triangles[t]);return n}function vd(e,n){if(e.length<n.minGroupTriangles)return e;let t=hd(e,n),o=t.activeCount;if(o<n.minGroupTriangles)return e;let r=Math.max(1,Math.floor(o*n.ratio));if(r>=o)return e;let i=0;for(let s=0;s<n.maxPasses&&t.activeCount>r;s+=1){let a=Td(t,n);if(a.length===0)break;let c=0;for(let l of a){if(t.activeCount<=r)break;let u=Md(t,l,n);if(!u)continue;let f=t.activeCount;Cd(t,l,u),!(t.activeCount>=f)&&(i+=1,c+=1)}if(c===0)break}return i===0||t.activeCount>=o?e:Ed(t).map(s=>({...s.polygon,vertices:[[...t.vertices[s.a]],[...t.vertices[s.b]],[...t.vertices[s.c]]]}))}function Id(e){let n=new Map;for(let t=0;t<e.length;t+=1){let o=e[t];if(!od(o))continue;let r=rd(o),i=n.get(r);i?(i.indices.push(t),i.polygons.push(o)):n.set(r,{indices:[t],polygons:[o]})}return n}function ei(e,n){let t=nd(n),o=Id(e);if(o.size===0)return e;let r=new Map,i=!1;for(let a of o.values()){let c=vd(a.polygons,t);if(!(c===a.polygons||c.length>=a.polygons.length)){r.set(a.indices[0],c);for(let l=1;l<a.indices.length;l+=1)r.set(a.indices[l],[]);i=!0}}if(!i)return e;let s=[];for(let a=0;a<e.length;a+=1){let c=r.get(a);c?s.push(...c):c===void 0&&s.push(e[a])}return s}var _d=3,Vd=.03,Od=.02,Xt={maxAngleDeg:_d,maxPlaneDisplacement:Vd,maxBoundaryDisplacement:Od,isolatedPairs:!1},No={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},ni=[{...No,maxAngleDeg:30},{...No,maxAngleDeg:45},{...No,maxAngleDeg:60,maxBoundaryDisplacement:.06}],Rd=1800,Ld=.65,oc=500,rc=2200,wd=1e3,Nd=2200,Dd=350,Fd=700,Bd=60,kd=.06,zd=4,Ud=.003,Gd=4e3,$d=3e3,Xd=4500,Yd=2400,jd=4200,Wd=1800,Hd=5e3,Kd=.28,Zd=.15,qd=.23,Qd=2e3,Jd=16,ep=4e3,np=900,tp=16,op=1.5,oi=.045,rp=.999,ip=1e-5,sp=24,ap=50,cp=1e3,lp=1e3,Wn={minGroupPolygons:2,maxCandidateAxes:24},up={...Wn,maxCandidateAxes:1},ic={...Wn,maxCandidateAxes:2},fp={...Wn,maxCandidateAxes:2},mp={steps:[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"},{kind:"finalLossyCandidates"}]};function dp(e,n={}){return pp(e,n).polygons}function uc(e,n={}){let t={meshResolution:n.meshResolution,stopAtPolygonCount:n.stopAtPolygonCount,rectCover:n.rectCover},o=new Do,r={captureVisiblePolygons:!0,skipInteriorCull:n.skipInteriorCull===!0};return o.workspaceFor(e,r).createRun(t,r).optimizeParse({staticSimplification:n.staticSimplification,useCandidateFirst:n.useCandidateFirst===!0}).polygons}function pp(e,n={},t={}){return new Do().workspaceFor(e,t).createRun(n,t).optimize()}var Do=class{constructor(){this.workspaces=new Map}workspaceFor(n,t){let o=gp(t),r=this.workspaces.get(o);r||(r=new WeakMap,this.workspaces.set(o,r));let i=r.get(n);return i||(i=new ri(n,t,this),r.set(n,i)),i}};function gp(e){return[e.skipInteriorCull===!0?"skip-cull":"cull",e.simplifiedCandidate===!0?"simplified":"source"].join(":")}var ri=class{constructor(n,t,o){this.source=n,this.graph=o,this.preprocessCache={skipInteriorCull:t.skipInteriorCull===!0}}polygons(){return this.source}preprocess(n){return kp(this.source,n,this.preprocessCache)}configureSnappedCullReuse(n,t){let o=n.length/Math.max(1,this.source.length);this.preprocessCache.reuseSnappedInteriorCull=t.simplifiedCandidate===!0?this.source.length<=jd:n.length<=Wd||n.length<=Hd&&o>=Kd}visiblePolygons(){return this.preprocessCache.interior??this.preprocessCache.deduped??this.source}createRun(n,t){return new ii(this,n,t)}workspaceFor(n,t){return this.graph.workspaceFor(n,t)}},ii=class e{constructor(n,t,o,r={}){this.baselineCandidatesComplete=!1;this.initialLossyCandidatesComplete=!1;this.finalLossyCandidatesComplete=!1;this.workspace=n,this.source=n.polygons(),this.options=t,this.runOptions=o,this.costCandidateMode=r.costCandidateMode??"cost",this.seamCandidateMode=r.seamCandidateMode??"seamSafe",this.offerBaseline=r.offerBaseline===!0,this.meshResolution=t.meshResolution??"lossy",this.stopAtPolygonCount=Number.isFinite(t.stopAtPolygonCount)?Math.max(0,Math.floor(t.stopAtPolygonCount)):void 0,this.requiredMaxPolygonCount=Number.isFinite(o.requiredMaxPolygonCount)?Math.max(0,Math.floor(o.requiredMaxPolygonCount)):void 0,this.baseline=this.preprocess(!1),this.workspace.configureSnappedCullReuse(this.baseline,o),this.visiblePolygons=o.captureVisiblePolygons?this.workspace.visiblePolygons():void 0,this.acceptor=r.acceptor??new si(this.baseline,this.requiredMaxPolygonCount)}optimize(){return this.runPlan(mp)}optimizeParse(n){let t=n.staticSimplification===!1?null:n.staticSimplification??{},o=[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"}];return n.useCandidateFirst||o.push({kind:"finalLossyCandidates"}),t&&o.push({kind:"staticSimplificationCandidates",options:t,stopOnAccept:n.useCandidateFirst}),n.useCandidateFirst&&o.push({kind:"finalLossyCandidates"}),this.runPlan({steps:o})}get best(){return this.acceptor.polygons}get bestCost(){return this.acceptor.cost}runStaticSimplificationCandidates(n={}){if(this.meshResolution!=="lossy"||!Vp(this.source,this.best))return!1;let t=mc(this.source,n);if(!t)return!1;for(let o of this.staticSimplificationPlans(t)){let r=Op(o,n);if(r&&this.generateStaticSimplificationCandidate(r,n,o.skipInteriorCull))return!0}return!1}staticSimplificationPlans(n){let t=this.source.length-n.length,o=[],r=this.visiblePolygons&&this.visiblePolygons!==this.source?this.source.length-this.visiblePolygons.length:0;return this.visiblePolygons&&this.visiblePolygons!==this.source&&this.source.length>=ep&&r>=np&&(t<=tp||r>=t*op)&&o.push({source:this.visiblePolygons,skipInteriorCull:!0}),this.best.length>=Qd&&t<=Jd&&_p(this.source)&&o.push({source:this.source,vertexKeyMode:"source"}),o.push({source:this.source,precomputed:n}),o}generateStaticSimplificationCandidate(n,t,o=!1){let r={requiredMaxPolygonCount:this.best.length-1,skipExactRectCover:!0,skipInteriorCull:o,simplifiedCandidate:!0},i=this.workspace.workspaceFor(n,r),s=this.best;return new e(i,{meshResolution:"lossy",stopAtPolygonCount:Ip(this.best.length,t)},r,{acceptor:this.acceptor,costCandidateMode:"dom",seamCandidateMode:"dom",offerBaseline:!0}).optimize(),this.best!==s}runPlan(n){for(let t of n.steps){let o=!1;if(t.kind==="baselineCandidates")this.runBaselineCandidates();else if(t.kind==="staticSimplificationCandidates")o=this.runStaticSimplificationCandidates(t.options)&&t.stopOnAccept;else{if(!this.shouldRunLossyPipeline())break;t.kind==="initialLossyCandidates"?this.runInitialLossyPipeline():this.runFinalLossyPipeline()}if(o||this.shouldStop())break}return this.result()}runBaselineCandidates(){if(this.baselineCandidatesComplete||(this.baselineCandidatesComplete=!0,this.offerBaseline&&(this.acceptCandidate(this.baseline),this.shouldStop())))return;let n=this.runOptions.skipExactRectCover===!0?!1:this.meshResolution==="lossy"&&this.options.rectCover===void 0?Lp(this.baseline):this.options.rectCover;if(this.shouldStop())return;let t=jn(this.baseline,n);if(t!==this.baseline&&this.acceptCandidate(t),!this.shouldStop()&&this.meshResolution==="lossy"&&this.options.rectCover===void 0&&this.runOptions.skipExactRectCover!==!0){let o=jn(this.baseline,void 0);o!==this.baseline&&this.acceptCandidate(o)}}shouldRunLossyPipeline(){return this.meshResolution==="lossy"&&!this.shouldStop()&&this.best.length>1&&this.bestCost>1+1e-9}runInitialLossyPipeline(){if(this.initialLossyCandidatesComplete)return;this.initialLossyCandidatesComplete=!0;let n=this.preprocess(No);this.acceptCandidate(n),!this.shouldStop()&&(this.options.rectCover===void 0&&this.source.length>=oc&&this.source.length<=rc&&(this.acceptCandidate(jn(n,ic)),this.shouldStop())||this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(this.acceptCandidate(jn(n,this.options.rectCover)),this.shouldStop()))}runFinalLossyPipeline(){this.finalLossyCandidatesComplete||(this.finalLossyCandidatesComplete=!0,!(this.runOptions.simplifiedCandidate===!0&&this.source.length>Xd)&&(this.runAggressiveLossyVariants(),!this.shouldStop()&&this.runLargeRectCoverCandidate()))}runAggressiveLossyVariants(){let n=this.stopAtPolygonCount===void 0&&this.source.length>=Gd&&this.best.length<=$d,t=!1;for(let o=n?ni.length:0;o<ni.length;o+=1){if(o===1&&!t||o===1&&this.runOptions.simplifiedCandidate===!0&&this.source.length<Yd||o===2&&!Np(this.source))continue;let r=this.preprocess(ni[o]),i=r;this.options.rectCover===void 0&&this.source.length>=oc&&this.source.length<=rc&&(i=jn(r,ic)),this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(i=jn(r,this.options.rectCover));let s=this.acceptSeamSafeCandidate(i,this.source.length);if(o===0&&s&&(t=!0),this.shouldStop())return}}runLargeRectCoverCandidate(){if(this.options.rectCover!==void 0)return;let n=jn(this.best,wp(this.best));n!==this.best&&this.acceptSeamSafeCandidate(n,this.best.length)}preprocess(n){return this.workspace.preprocess(n)}result(){return{polygons:this.best,visiblePolygons:this.visiblePolygons}}shouldStop(){return this.stopAtPolygonCount!==void 0&&this.best.length<=this.stopAtPolygonCount}acceptCandidate(n,t=Hn(n)){return this.emitCandidate({mode:this.costCandidateMode,polygons:n,cost:t})}acceptDomCandidate(n){return this.emitCandidate({mode:"dom",polygons:n})}acceptSeamSafeCandidate(n,t,o){return this.emitCandidate({mode:this.seamCandidateMode,polygons:n,sourcePolygonCount:t,cost:o})}emitCandidate(n){return this.acceptor.accept({...n,maxPolygonCount:n.maxPolygonCount??this.requiredMaxPolygonCount})}},si=class{constructor(n,t){this.best=n,this.bestCost=Hn(n),this.bestDiagnostics={polygons:n},this.requiredMaxPolygonCount=t}get polygons(){return this.best}get cost(){return this.bestCost}accept(n){return n.mode==="cost"?this.acceptCostCandidate(n.polygons,n.cost):n.mode==="dom"?this.acceptDomCandidate(n.polygons,n.cost,n.maxPolygonCount):this.acceptSeamSafeCandidate(n.polygons,n.sourcePolygonCount??n.polygons.length,n.cost,n.maxPolygonCount)}acceptCostCandidate(n,t=Hn(n)){return t>=this.bestCost?!1:(this.commit(n,t),!0)}acceptDomCandidate(n,t=Hn(n),o){return n.length>=this.best.length||!this.withinMaxPolygonCount(n,o)?!1:(this.commit(n,t),!0)}acceptSeamSafeCandidate(n,t,o,r){if(n.length>=this.best.length||!this.withinMaxPolygonCount(n,r))return!1;let i=vp(t);if(this.bestCost-n.length<i)return!1;let s=o??Hn(n),a=this.bestCost-s;if(a<=0||a<i)return!1;let c=sc(n);if(!c)return!1;let l=this.bestSeamDiagnostics();return!l||hp(c,l)||yp(this.bestTopologyEdges(),this.bestTopologySelfDiagnostics(),n)?!1:(this.commit(n,s,c),!0)}withinMaxPolygonCount(n,t){let o=t??this.requiredMaxPolygonCount;return o===void 0||n.length<=o}commit(n,t,o){this.best=n,this.bestCost=t,this.bestDiagnostics={polygons:n,seam:o}}resetBestDiagnostics(n){this.bestDiagnostics={polygons:this.best,seam:n}}bestSeamDiagnostics(){if(this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),!this.bestDiagnostics.seam){let n=sc(this.best);if(!n)return null;this.bestDiagnostics.seam=n}return this.bestDiagnostics.seam}bestTopologyEdges(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologyEdges||(this.bestDiagnostics.topologyEdges=fc(this.best)),this.bestDiagnostics.topologyEdges}bestTopologySelfDiagnostics(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologySelf||(this.bestDiagnostics.topologySelf=Mp(this.bestTopologyEdges(),oi)),this.bestDiagnostics.topologySelf}};function Hn(e){let n=0;for(let t of e){let o=t.vertices.length,r=o<=4?0:Math.min(4,o-4)*.12,i=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+r+i}return n}function sc(e){try{return Qa(e)}catch(n){if(n instanceof RangeError&&n.message==="Set maximum size exceeded")return null;throw n}}function hp(e,n){return e.nearPairs>n.nearPairs||e.unclosedPairs>n.unclosedPairs||e.maxMeasuredGapPx>n.maxMeasuredGapPx+1e-9||e.maxResidualGapPx>n.maxResidualGapPx+1e-9}function yp(e,n,t){let o=fc(t);return bp(e,o,oi)?!0:Pp(o.boundarySegments,oi,n)}function bp(e,n,t){if(e.internalSegments.length===0)return!1;let o=xp(e,t);for(let r of n.boundarySegments)if(!e.boundaryKeys.has(r.key)&&(e.internalKeys.has(r.key)||Tp(r,o,t)))return!0;return!1}function xp(e,n){return(!e.internalIndex||e.internalIndexTolerance!==n)&&(e.internalIndex=li(e.internalSegments,n),e.internalIndexTolerance=n),e.internalIndex}function Pp(e,n,t){let o=li(e,n),r=new Set,i=0,s=0,a=0;for(let c of e)i=Math.max(i,c.index+1);for(let c of e)for(let l of ui(c,o,n)){if(l===c||l.polygon===c.polygon||l.key===c.key)continue;let u=c.index<l.index?c.index*i+l.index:l.index*i+c.index;if(r.has(u))continue;r.add(u);let f=fi(c,l,n);if(f&&(s+=1,a+=f.overlapLength,s>t.tJunctionPairs||a>t.tJunctionLength+1e-9))return!0}return!1}function Mp(e,n){let t={tJunctionPairs:0,tJunctionLength:0};return Sp(t,e.boundarySegments,n),t}function Sp(e,n,t){let o=li(n,t),r=new Set,i=0;for(let s of n)i=Math.max(i,s.index+1);for(let s of n)for(let a of ui(s,o,t)){if(a===s||a.polygon===s.polygon||a.key===s.key)continue;let c=s.index<a.index?s.index*i+a.index:a.index*i+s.index;if(r.has(c))continue;r.add(c);let l=fi(s,a,t);l&&(e.tJunctionPairs+=1,e.tJunctionLength+=l.overlapLength)}}function fc(e){let n=new Map;for(let c=0;c<e.length;c+=1){let l=e[c].vertices;for(let u=0;u<l.length;u+=1){let f=l[u],d=l[(u+1)%l.length],m=Ap(Wt(f,d),c,u,f,d);if(!m)continue;let p=n.get(m.key);p?p.count+=1:n.set(m.key,{count:1,segment:m})}}let t=new Set,o=new Set,r=[],i=[],s=0,a=0;for(let c of n.values()){let l={...c.segment,index:a};a+=1,c.count===1?(t.add(l.key),r.push(l),s+=l.length):(o.add(l.key),i.push(l))}return{boundaryKeys:t,internalKeys:o,boundarySegments:r,internalSegments:i,boundaryLength:s}}function Ap(e,n,t,o,r){let i=Cn(r,o),s=Math.hypot(i[0],i[1],i[2]);if(s<=1e-10)return null;let a=[i[0]/s,i[1]/s,i[2]/s];return{index:-1,key:e,polygon:n,edge:t,a:o,b:r,dir:a,length:s,minX:Math.min(o[0],r[0]),minY:Math.min(o[1],r[1]),minZ:Math.min(o[2],r[2]),maxX:Math.max(o[0],r[0]),maxY:Math.max(o[1],r[1]),maxZ:Math.max(o[2],r[2])}}function li(e,n){let t=Math.max(n*8,.5),o=new Map;for(let r of e)Cp(o,r,t,n);return{cellSize:t,cells:o}}function Cp(e,n,t,o){let[r,i,s]=Fo([n.minX-o,n.minY-o,n.minZ-o],t),[a,c,l]=Fo([n.maxX+o,n.maxY+o,n.maxZ+o],t);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function Fo(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function ui(e,n,t){let o=[],r=new Set,[i,s,a]=Fo([e.minX-t,e.minY-t,e.minZ-t],n.cellSize),[c,l,u]=Fo([e.maxX+t,e.maxY+t,e.maxZ+t],n.cellSize);for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1)for(let m=a;m<=u;m+=1){let p=n.cells.get(`${f},${d},${m}`);if(p)for(let g of p)r.has(g)||(r.add(g),o.push(g))}return o}function Tp(e,n,t){for(let o of ui(e,n,t))if(fi(e,o,t))return!0;return!1}function fi(e,n,t){if(!Ep(e,n,t)||Math.abs(nn(e.dir,n.dir))<rp)return null;let o=nn(Cn(n.a,e.a),e.dir),r=nn(Cn(n.b,e.a),e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i;if(a<=Math.max(ip,Math.min(e.length,n.length)*1e-4))return null;let c=[e.a[0]+e.dir[0]*((i+s)/2),e.a[1]+e.dir[1]*((i+s)/2),e.a[2]+e.dir[2]*((i+s)/2)],l=Math.max(0,Math.min(n.length,nn(Cn(c,n.a),n.dir))),u=[n.a[0]+n.dir[0]*l,n.a[1]+n.dir[1]*l,n.a[2]+n.dir[2]*l],f=Ec(c,u);return f<=t?{overlapLength:a,offset:f}:null}function Ep(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function vp(e){return Math.max(zd,e*Ud)}function Ip(e,n){let t=Number.isFinite(n.earlyStopDropRatio)?Math.max(0,n.earlyStopDropRatio):Zd;return Math.max(0,e-Math.max(1,Math.ceil(e*t)))}function _p(e){return e.some(n=>n.simplifySourceVertexKeys?.length===n.vertices.length)}function Vp(e,n){return e.length===0||n.length/e.length>qd}function mc(e,n,t){let o=ei(e,{...n.simplifyTriangleMeshOptions,...t?{vertexKeyMode:t}:{}});return o===e||o.length>=e.length?null:o}function Op(e,n){return e.precomputed!==void 0?e.precomputed:mc(e.source,n,e.vertexKeyMode)}function jn(e,n){if(n===!1)return e;let t=Rp(e,n);if(!t)return e;let o=Fr(e,t);return o.length<e.length?o:e}function Rp(e,n){if(n&&n!==!0)return n;let t=n===!0,o=e.length;return o>2200||!t&&o>=sp&&o<ap||!t&&o>cp?null:!t&&o<=300?{...Wn,maxCandidateAxes:1}:o>300?!t&&(dc(e)>12||pc(e)>lp)?null:{...Wn,maxCandidateAxes:Math.min(Wn.maxCandidateAxes??24,2)}:Wn}function Lp(e){return e.length>Rd||e.length===0||Dp(e)/e.length<Ld?!1:up}function wp(e){return e.length<wd||e.length>Nd||dc(e)<=12||pc(e)>Dd?!1:fp}function Np(e){return e.length<=Fd}function Dp(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function dc(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function pc(e){let n=new Map;for(let o of e)for(let r=0;r<o.vertices.length;r++){let i=o.vertices[r],s=o.vertices[(r+1)%o.vertices.length],a=Wt(i,s);n.set(a,(n.get(a)??0)+1)}let t=0;for(let o of n.values())o===1&&(t+=1);return t}function Bo(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function ai(e,n){if(n===e||n.length===e.length&&n.every((r,i)=>r===e[i]))return null;let t=new Set(n),o=[];for(let r=0;r<e.length;r++)t.has(e[r])&&o.push(r);return o.length===e.length?null:o}function Fp(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let r=Mo(e);if(r.size===0)t=null;else{t=[];for(let i=0;i<e.length;i++)r.has(i)||t.push(i)}n&&(n.dedupedIndices=t)}let o=Bo(e,t);return n&&(n.deduped=o),o}function Bp(e,n){if(n?.skipInteriorCull)return e;if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let r=Mn(e);t=ai(e,r),n&&(n.interiorIndices=t)}let o=Bo(e,t);return n&&(n.interior=o),o}function kp(e,n,t){let o=Fp(e,t),r=Bp(o,t),i=t?.baseline??fn(r);if(t&&!t.baseline&&(t.baseline=i),!n)return i;let s=n===!0?Xt:Up(n);if(s.isolatedPairs){let u=cc(ac(o,t),s,t),f=fn(u);if(t?.snappedInteriorUsesBaselineFilter&&zp(i,f)){let d=cc(ac(o,t,!0),s,t),m=fn(d);m.length<f.length&&(f=m)}return f.length<i.length?f:i}let a=eg(o,s,t),c=Mn(a),l=fn(c);return l.length<i.length?l:i}function gc(e,n){return n?(n.snapped||(n.snapped=ko(e)),n.snapped):ko(e)}function ac(e,n,t=!1){if(!n)return Mn(ko(e));if(t&&n.snappedInteriorExact)return n.snappedInteriorExact;if(!t&&n.snappedInterior)return n.snappedInterior;let o=gc(e,n);if(t){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorExactIndices=n.interiorIndices,n.snappedInteriorExact=n.interior,n.snappedInteriorExact;let r=Mn(o);return n.snappedInteriorExactIndices=ai(o,r),n.snappedInteriorExact=r,n.snappedInteriorExact}if(!n.snappedInterior){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=n.interior,n.snappedInteriorUsesBaselineFilter=!1,n.snappedInterior;if(n.reuseSnappedInteriorCull!==!1&&n.interiorIndices!==void 0)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=Bo(o,n.snappedInteriorIndices),n.snappedInteriorUsesBaselineFilter=!0,n.snappedInterior;if(n.snappedInteriorIndices===void 0){let r=Mn(o);n.snappedInteriorIndices=ai(o,r),n.snappedInterior=r,n.snappedInteriorExactIndices=n.snappedInteriorIndices,n.snappedInteriorExact=r,n.snappedInteriorUsesBaselineFilter=!1}else n.snappedInterior=Bo(o,n.snappedInteriorIndices)}return n.snappedInterior}function zp(e,n){return n.length>=e.length}function Up(e){return{maxAngleDeg:e.maxAngleDeg??Xt.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??Xt.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??Xt.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??Xt.isolatedPairs}}function cc(e,n,t){let o=Gp(e,t),r=[];for(let s of $p(e,o))Xp(s,n)&&r.push(s.candidate);let i=jp(r);return i.length===0?e:Yp(e,i)}function Gp(e,n){if(n?.trianglePairSource?.polygons===e)return n.trianglePairSource;let t=e.map(s=>{let a=di(s);return a?{polygon:s,normal:a.normal,area:a.area,materialKey:Mc(s)}:null}),o=new Map;for(let s=0;s<e.length;s++){let a=e[s];if(!(a.vertices.length!==3||!t[s]))for(let c=0;c<a.vertices.length;c++){let l=Wt(a.vertices[c],a.vertices[(c+1)%a.vertices.length]),u=o.get(l);u?u.push(s):o.set(l,[s])}}let r=[];for(let s of o.values())s.length===2&&r.push([s[0],s[1]]);let i={polygons:e,metas:t,edgeOwnerPairs:r};return n&&(n.trianglePairSource=i),i}function $p(e,n){if(n.preparedCandidates)return n.preparedCandidates;let t=[];for(let[o,r]of n.edgeOwnerPairs){let i=qp(o,r,e,n.metas);i&&t.push(i)}return n.preparedCandidates=t,t}function Xp(e,n){let t=Math.cos(n.maxAngleDeg*Math.PI/180);return e.normalDot>=t&&e.maxDistance<=Math.min(n.maxPlaneDisplacement,n.maxBoundaryDisplacement)}function Yp(e,n){let t=new Map,o=new Set,r=hc(n.flatMap(s=>s.vertexMoves));for(let s of n){let a=Math.min(s.a,s.b);t.set(a,s.polygon),o.add(Math.max(s.a,s.b))}let i=[];for(let s=0;s<e.length;s++){let a=t.get(s);if(a){i.push(a);continue}o.has(s)||i.push(e[s])}return r.size>0?yc(i,r):i}function jp(e){return e.length>3e3?Wp(e):Hp(e)}function Wp(e){let n=new Map;for(let i of e)n.set(i.a,(n.get(i.a)??0)+1),n.set(i.b,(n.get(i.b)??0)+1);let t=[...e].sort((i,s)=>{let a=(n.get(i.a)??0)+(n.get(i.b)??0),c=(n.get(s.a)??0)+(n.get(s.b)??0);return a-c||i.score-s.score}),o=new Set,r=[];for(let i of t)o.has(i.a)||o.has(i.b)||(o.add(i.a),o.add(i.b),r.push(i));return r}function Hp(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],f=n.get(u.a);f?f.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let t=[],o=new Array(e.length).fill(!0),r=new Map,i=new ci;for(let[l,u]of n)r.set(l,u.length);let s=l=>(r.get(l.a)??0)+(r.get(l.b)??0),a=l=>{let u=e[l];i.push({degree:s(u),score:u.score,index:l})},c=(l,u)=>{if(!o[l])return;o[l]=!1;let f=e[l];for(let d of[f.a,f.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)a(l);for(;i.size()>0;){let l=i.pop();if(!o[l.index])continue;let u=e[l.index];if(s(u)!==l.degree){a(l.index);continue}t.push(u);let d=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])c(p,d);for(let m of d)for(let p of n.get(m)??[])o[p]&&a(p)}return t}var ci=class{constructor(){this.items=[]}size(){return this.items.length}push(n){this.items.push(n);let t=this.items.length-1;for(;t>0;){let o=t-1>>1;if(ti(this.items[o],this.items[t])<=0)break;[this.items[o],this.items[t]]=[this.items[t],this.items[o]],t=o}}pop(){if(this.items.length===0)return null;let n=this.items[0],t=this.items.pop();if(this.items.length>0){this.items[0]=t;let o=0;for(;;){let r=o*2+1,i=r+1,s=o;if(r<this.items.length&&ti(this.items[r],this.items[s])<0&&(s=r),i<this.items.length&&ti(this.items[i],this.items[s])<0&&(s=i),s===o)break;[this.items[o],this.items[s]]=[this.items[s],this.items[o]],o=s}}return n}};function ti(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function hc(e){let n=new Map;for(let o of e){let r=n.get(o.key);r?(r.x+=o.target[0],r.y+=o.target[1],r.z+=o.target[2],r.count+=1):n.set(o.key,{x:o.target[0],y:o.target[1],z:o.target[2],count:1})}let t=new Map;for(let[o,r]of n)t.set(o,[r.x/r.count,r.y/r.count,r.z/r.count]);return t}function Kp(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o].vertices,i=n[o]?.vertices;if(!i||i.length!==r.length)continue;for(let c=0;c<r.length;c++)t.push({key:an(r[c]),target:i[c]});let s=e[o].textureTriangles??[],a=n[o]?.textureTriangles??[];for(let c=0;c<s.length;c++){let l=a[c];if(l)for(let u=0;u<s[c].vertices.length;u++)t.push({key:an(s[c].vertices[u]),target:l.vertices[u]})}}return t}function Zp(e,n){let t=[];for(let o of e)for(let r of o.textureTriangles??[])for(let i of r.vertices)t.push({key:an(i),target:yi(i,n)});return t}function yc(e,n){return e.map(t=>{let o=!1,r=a=>{let c=n.get(an(a));return c?(o=!0,c):a},i=t.vertices.map(r),s=mi(t.textureTriangles,r);return o?{...t,vertices:i,...s?{textureTriangles:s}:{}}:t})}function qp(e,n,t,o){let r=t[e],i=t[n],s=o[e],a=o[n];if(!s||!a||r.vertices.length!==3||i.vertices.length!==3||!mg(r,i,s,a))return null;let c=gi(r,i);if(!c)return null;let[l,u,f,d]=c;if((f+1)%i.vertices.length===d)return null;let p=Math.abs(nn(s.normal,a.normal)),g=Math.cos(Bd*Math.PI/180);if(p<g)return null;let h=(u+1)%r.vertices.length,y=3-f-d,b=[r.vertices[u],r.vertices[h],r.vertices[l],i.vertices[y]],x=Qp(b);if(!x)return null;let P=0,M=0;for(let S of b){let T=Math.abs(hi(S,x));P=Math.max(P,T),M+=T*T}if(P>kd)return null;let C=b.map(S=>yi(S,x));if(!Jp(C,x.normal))return null;let E=di({vertices:C});if(!E||nn(E.normal,s.normal)<.2||nn(E.normal,a.normal)<.2)return null;let A={vertices:b,color:r.color,...r.doubleSided?{doubleSided:!0}:{},...r.data?{data:{...r.data}}:{}};if(pi(r,i)&&r.uvs&&i.uvs&&r.texture){A.texture=r.texture,r.textureWrap&&(A.textureWrap={...r.textureWrap}),r.textureAlphaMode&&(A.textureAlphaMode=r.textureAlphaMode),A.uvs=[[...r.uvs[u]],[...r.uvs[h]],[...r.uvs[l]],[...i.uvs[y]]];let S=ng([r,i]);S?.length&&(A.textureTriangles=S)}return{normalDot:p,maxDistance:P,candidate:{a:e,b:n,polygon:A,vertexMoves:[...b.map((S,T)=>({key:an(S),target:C[T]})),...Zp([r,i],x)],score:M/b.length+P*.25+(1-p)*.1}}}function Qp(e){if(e.length<3)return null;let n=0,t=0,o=0,r=0,i=0,s=0;for(let c=0;c<e.length;c++){let l=e[c],u=e[(c+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),t+=(l[2]-u[2])*(l[0]+u[0]),o+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],i+=l[1],s+=l[2]}let a=vc([n,t,o]);return a?{normal:a,point:[r/e.length,i/e.length,s/e.length]}:null}function Jp(e,n){let t=0;for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=e[(o+2)%e.length],a=nn(Tc(Cn(i,r),Cn(s,i)),n);if(Math.abs(a)<=1e-9)continue;let c=a>0?1:-1;if(t===0)t=c;else if(t!==c)return!1}return!0}function eg(e,n,t){let o=gc(e,t),r=ag(o,n);if(r<=0)return o;let i=o.map(m=>{let p=di(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Mc(m)}:null}),s=ug(o,i),a=new Set,c=Array(o.length),l=[],u=(m,p)=>{c[m]=p};for(let m=0;m<o.length;m++){let p=i[m];if(a.has(m))continue;if(!p){u(m,o[m]);continue}let g=dg(m,i,s,a,r,n);for(let y of g)a.add(y);if(g.length<2){u(m,o[m]);continue}let h=rg(g,o,i,s,r,n);l.push(...h.vertexMoves);for(let y of g)u(y,h.polygons.get(y)??o[y])}let f=c.flatMap(m=>m?[m]:[]),d=l.length>0?yc(f,hc(l)):f;return ko(d)}function ko(e){let n=Pc(e),t=1e-4;if(n<=0)return e;let o=cg(n),r=lg(t),i=!1,s=e.map(a=>{let c=!1,l=p=>{let g=o.snap(p);return Yt(g,p)||(c=!0),g},u=a.vertices.map(l),f=a.uvs&&a.uvs.length===a.vertices.length?a.uvs.map(p=>{let g=r.snap(p);return jt(g,p)||(c=!0),g}):void 0,d=mi(a.textureTriangles,l);if(!c&&!a.texture)return a;let m={...a,vertices:u,...f?{uvs:f}:{},...d?{textureTriangles:d}:{}};return i=!0,{...m,...m.texture?{textureTriangles:bc(m)}:{}}});return i?s:e}function bc(e){if(e.texture){if(e.textureTriangles?.length)return og(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return tg(e.vertices,e.uvs)}}function ng(e){let n=e.flatMap(t=>bc(t)??[]);return n.length>0?n:void 0}function tg(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function og(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function mi(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(o=>[...o])}))}function rg(e,n,t,o,r,i){let s=xc(e,n,t,r,i);return s?sg(s):ig(e,n,t,o,r,i)}function ig(e,n,t,o,r,i){let s=new Set(e),a=[];for(let f of e)for(let d of o.get(f)??[]){if(f>=d||!s.has(d))continue;let m=xc([f,d],n,t,r,i);m&&a.push(m)}a.sort((f,d)=>d.score-f.score);let c=new Set,l=new Map,u=[];for(let f of a)if(!f.indices.some(d=>c.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];c.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function sg(e){let n=new Map;for(let t=0;t<e.indices.length;t++)n.set(e.indices[t],e.source[t]);return{polygons:n,vertexMoves:e.vertexMoves}}function xc(e,n,t,o,r){let i=Sc(e,t);if(!i||!Ac(e,t,i,o,r))return null;let s=e.map(u=>n[u]),a=s.map(u=>hg(u,i)),c=Hn(fn(s)),l=Hn(fn(a));return l>=c?null:{indices:e,source:s,projected:a,vertexMoves:Kp(s,a),score:c-l}}function ag(e,n){return Pc(e)<=0?0:n.maxPlaneDisplacement}function Pc(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let c of e)for(let[l,u,f]of c.vertices)n=Math.min(n,l),t=Math.min(t,u),o=Math.min(o,f),r=Math.max(r,l),i=Math.max(i,u),s=Math.max(s,f);if(!Number.isFinite(n))return 0;let a=Math.hypot(r-n,i-t,s-o);return a<=0?0:Math.min(.025,Math.max(1e-4,a*25e-5))}function cg(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i,s)=>`${r},${i},${s}`;return{snap(r){let i=t(r[0]),s=t(r[1]),a=t(r[2]);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)for(let m=-1;m<=1;m++){let p=n.get(o(i+f,s+d,a+m));if(p){for(let g of p)if(Ec(r,g)<=e)return[g[0],g[1],g[2]]}}let c=[r[0],r[1],r[2]],l=o(i,s,a),u=n.get(l);return u?u.push(c):n.set(l,[c]),c}}}function lg(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i)=>`${r},${i}`;return{snap(r){let i=t(r[0]),s=t(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(o(i+u,s+f));if(d){for(let m of d)if(Math.hypot(r[0]-m[0],r[1]-m[1])<=e)return[m[0],m[1]]}}let a=[r[0],r[1]],c=o(i,s),l=n.get(c);return l?l.push(a):n.set(c,[a]),a}}}function Mc(e){return[e.color??"#cccccc",e.texture??"",e.texture&&e.textureWrap?`${e.textureWrap.s}/${e.textureWrap.t}`:"",e.texture&&e.textureAlphaMode?e.textureAlphaMode:"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided"].join("|")}function di(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0,i=n[0];for(let a=1;a<n.length-1;a++){let c=Cn(n[a],i),l=Cn(n[a+1],i),u=Tc(c,l);t+=u[0],o+=u[1],r+=u[2]}let s=Math.hypot(t,o,r);return s<=1e-10?null:{normal:[t/s,o/s,r/s],area:s/2}}function ug(e,n){let t=new Map,o=new Map;for(let r=0;r<e.length;r++){let i=e[r];if(!(!n[r]||i.vertices.length<3))for(let s=0;s<i.vertices.length;s++){let a=Wt(i.vertices[s],i.vertices[(s+1)%i.vertices.length]),c=t.get(a);c?c.push(r):t.set(a,[r])}}for(let r of t.values())for(let i=0;i<r.length;i++)for(let s=i+1;s<r.length;s++){let a=r[i],c=r[s];fg(e[a],e[c],n[a],n[c])&&(lc(o,a,c),lc(o,c,a))}return o}function fg(e,n,t,o){if(!t||!o||t.materialKey!==o.materialKey||!!e.uvs!=!!n.uvs)return!1;if(zo(e)||zo(n))return pi(e,n);if(!e.uvs||!n.uvs)return!0;let r=gi(e,n);if(!r)return!1;let[i,s,a,c]=r;return jt(e.uvs[i],n.uvs[a])&&jt(e.uvs[s],n.uvs[c])}function mg(e,n,t,o){return t.materialKey!==o.materialKey?!1:zo(e)||zo(n)?pi(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function zo(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function pi(e,n){if(!e.texture||!n.texture||e.texture!==n.texture||(e.textureWrap?.s??"")!==(n.textureWrap?.s??"")||(e.textureWrap?.t??"")!==(n.textureWrap?.t??"")||(e.textureAlphaMode??"")!==(n.textureAlphaMode??"")||e.material?.texture||n.material?.texture||!e.uvs||!n.uvs||e.uvs.length!==e.vertices.length||n.uvs.length!==n.vertices.length)return!1;let t=gi(e,n);if(!t)return!1;let[o,r,i,s]=t;return jt(e.uvs[o],n.uvs[i])&&jt(e.uvs[r],n.uvs[s])}function lc(e,n,t){let o=e.get(n);o?o.add(t):e.set(n,new Set([t]))}function dg(e,n,t,o,r,i){let s=[e],a=new Set([e]),c=[e];for(;c.length>0;){let l=c.shift();for(let u of t.get(l)??[]){if(o.has(u)||a.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&pg([...s,u],n,r,i)&&(s.push(u),a.add(u),c.push(u))}}return s}function pg(e,n,t,o){let r=Sc(e,n);return!!r&&Ac(e,n,r,t,o)}function Sc(e,n){let t=n[e[0]];if(!t)return null;let o=0,r=0,i=0,s=0,a=0,c=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let g=nn(t.normal,p.normal)<0?-1:1,h=Math.max(p.area,1e-6);o+=p.normal[0]*g*h,r+=p.normal[1]*g*h,i+=p.normal[2]*g*h;for(let y of p.polygon.vertices)s+=y[0],a+=y[1],c+=y[2],l+=1}let u=vc([o,r,i]);if(!u||l===0)return null;let f=Cc(e,n),d=gg(e,n,u,f);if(d){let m=(d.min+d.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m],boundaryVertexKeys:f}}return{normal:u,point:[s/l,a/l,c/l],boundaryVertexKeys:f}}function gg(e,n,t,o){let r=1/0,i=-1/0;for(let s of e){let a=n[s];if(a)for(let c of a.polygon.vertices){if(!o.has(an(c)))continue;let l=nn(c,t);r=Math.min(r,l),i=Math.max(i,l)}}return Number.isFinite(r)&&Number.isFinite(i)?{min:r,max:i}:null}function Ac(e,n,t,o,r){let i=Math.cos(r.maxAngleDeg*Math.PI/180),s=t.boundaryVertexKeys??Cc(e,n);for(let a of e){let c=n[a];if(!c||Math.abs(nn(c.normal,t.normal))<i)return!1;for(let l of c.polygon.vertices){let u=s.has(an(l))?r.maxBoundaryDisplacement:o;if(Math.abs(hi(l,t))>u)return!1}}return!0}function Cc(e,n){let t=new Map;for(let r of e){let i=n[r];if(!i)continue;let s=i.polygon.vertices;for(let a=0;a<s.length;a++){let c=s[a],l=s[(a+1)%s.length],u=Wt(c,l),f=t.get(u);f?f.count+=1:t.set(u,{count:1,a:c,b:l})}}let o=new Set;for(let r of t.values())r.count===1&&(o.add(an(r.a)),o.add(an(r.b)));return o}function hg(e,n){let t=r=>yi(r,n),o=mi(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...o?{textureTriangles:o}:{}}}function gi(e,n){for(let t=0;t<e.vertices.length;t++){let o=(t+1)%e.vertices.length;for(let r=0;r<n.vertices.length;r++){let i=(r+1)%n.vertices.length;if(Yt(e.vertices[t],n.vertices[r])&&Yt(e.vertices[o],n.vertices[i]))return[t,o,r,i];if(Yt(e.vertices[t],n.vertices[i])&&Yt(e.vertices[o],n.vertices[r]))return[t,o,i,r]}}return null}function Wt(e,n){let t=an(e),o=an(n);return t<o?`${t}|${o}`:`${o}|${t}`}function an(e){return`${e[0]},${e[1]},${e[2]}`}function Yt(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function jt(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function Cn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Tc(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function nn(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Ec(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function vc(e){let n=Math.hypot(e[0],e[1],e[2]);return n<=1e-10?null:[e[0]/n,e[1]/n,e[2]/n]}function hi(e,n){return nn(Cn(e,n.point),n.normal)}function yi(e,n){let t=hi(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var yg=36,bg=.15,xg=.2,Pg=650,Mg=15e3,Sg=.25;function bi(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function Ic(e){let n=Vn(e);return!n||n.alpha<1?e.trim().toLowerCase():`#${n.rgb.map(t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")).join("")}`}function Ag(e){let n=Vn(e);return n?{rgb:[Math.max(0,Math.min(255,Math.round(n.rgb[0]))),Math.max(0,Math.min(255,Math.round(n.rgb[1]))),Math.max(0,Math.min(255,Math.round(n.rgb[2])))],alpha:n.alpha}:null}function Cg(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function _c(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),i=Math.min(n,t,o),s=r-i,a=0;return s!==0&&(r===n?a=60*((t-o)/s%6):r===t?a=60*((o-n)/s+2):a=60*((n-t)/s+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:s/r,value:r}}function Tg(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function Eg(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=_c(e),o=_c(n),r=t.saturation<.08,i=o.saturation<.08;if(r||i)return r===i;let s=Math.min(t.value,o.value)<.18?32:18;return Tg(t.hue,o.hue)<=s}function vg(e,n){let t=new Map;for(let s of e.keys()){let a=Ag(s);a&&t.set(s,a)}let o=[],r=new Map,i=Array.from(e.entries()).sort((s,a)=>a[1]-s[1]||s[0].localeCompare(a[0]));for(let[s]of i){let a=t.get(s);if(!a){r.set(s,s);continue}let c=null;for(let l of o){if(!Eg(a,l.parsed))continue;let u=Cg(a,l.parsed);u>n||(!c||u<c.distance)&&(c={color:l.color,distance:u})}c?r.set(s,c.color):(o.push({color:s,parsed:a}),r.set(s,s))}return r}function Ig(e,n,t){if(t!=="lossy"||e.animation)return e;let o=n.source;if(!o||o.polygons===e.polygons)return e;let r=n.bakedTextureColorMergeDistance??yg;if(!Number.isFinite(r)||r<=0)return e;let i=new Map,s=[];for(let u=0;u<e.polygons.length;u+=1){let f=o.polygons[u],d=e.polygons[u];if(!f||!d||f===d||!d.color||!bi(f)||bi(d))continue;let m=Ic(d.color);s.push(u),i.set(m,(i.get(m)??0)+1)}if(i.size<2)return e;let a=vg(i,r),c=!1,l=e.polygons.slice();for(let u of s){let f=l[u],d=Ic(f.color),m=a.get(d)??d;m!==d&&(l[u]={...f,color:m},c=!0)}return c?{...e,polygons:l}:e}function _g(e){let n=0;for(let t of e)bi(t)&&(n+=1);return e.length===0||n/e.length<=Sg}function Vg(e){return!!e.metadata?.stlTopology}function Og(e,n){return n?Math.max(e.simplifyEarlyStopDropRatio??bg,xg):e.simplifyEarlyStopDropRatio}function ut(e,n={}){return new xi(e,n).optimize()}var xi=class{constructor(n,t){this.result=n,this.options=t,this.meshResolution=t.meshResolution??"lossy"}optimize(){if(this.result.voxelSource||this.result.animation)return this.result;let n=Ig(this.result,this.options,this.meshResolution),t=Vg(n),o=t?"lossless":this.meshResolution,r=this.canSimplify(n.polygons,o),i=r&&n.polygons.length>=Pg&&n.polygons.length<=Mg,s=uc(n.polygons,{meshResolution:o,useCandidateFirst:i,staticSimplification:r?{simplifyTriangleMeshOptions:this.options.simplifyTriangleMeshOptions,earlyStopDropRatio:Og(this.options,i)}:!1,skipInteriorCull:t});return s===n.polygons?n:{...n,polygons:s}}canSimplify(n,t){return t==="lossy"&&this.options.simplifyTriangleMeshes!==!1&&_g(n)}};function Rg(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[O,L,D]of n)t+=O,o+=L,r+=D;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let x=n.length-2,P=new Float64Array(x*9),M=0;for(let O=1;O<n.length-1;O++){let L=n[0],D=n[O],_=n[O+1];P[M++]=L[0],P[M++]=L[1],P[M++]=L[2],P[M++]=D[0],P[M++]=D[1],P[M++]=D[2],P[M++]=_[0],P[M++]=_[1],P[M++]=_[2]}let C=0,E=1/0,A=1/0,S=1/0,T=-1/0,v=-1/0,R=-1/0;for(let[O,L,D]of n){let _=O-t,w=L-o,V=D-r,j=_*_+w*w+V*V;j>C&&(C=j),O<E&&(E=O),O>T&&(T=O),L<A&&(A=L),L>v&&(v=L),D<S&&(S=D),D>R&&(R=D)}return{centroid:[t,o,r],normal:[g,h,y],triFlat:P,bcx:t,bcy:o,bcz:r,br2:C,minX:E,minY:A,minZ:S,maxX:T,maxY:v,maxZ:R}}function Lg(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function wg(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(Lg(e,n,t,o,r,i,p,h))return!0;return!1}var Ht=9,Ng=6,Ke=12;function Pi(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function Dg(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*Ht),l=0,u=new Float64Array(Ke),f=new Float64Array(Ke),d=new Float64Array(Ke),m=new Float64Array(Ke),p=new Float64Array(Ke),g=new Float64Array(Ke),h=new Int32Array(Ke),y=new Float64Array(Ke-1),b=new Int32Array(Ke-1),x=new Float64Array(Ke-1),P=new Int32Array(Ke-1);function M(C,E){let A=l++,S=A*Ht,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=Ng)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=Pi(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ae=Ke/le;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),g.fill(-1/0),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ae|0;oe>=Ke&&(oe=Ke-1);let de=e[o[K]];de.minX<u[oe]&&(u[oe]=de.minX),de.maxX>m[oe]&&(m[oe]=de.maxX),de.minY<f[oe]&&(f[oe]=de.minY),de.maxY>p[oe]&&(p[oe]=de.maxY),de.minZ<d[oe]&&(d[oe]=de.minZ),de.maxZ>g[oe]&&(g[oe]=de.maxZ),h[oe]++}let _e=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<Ke-1;K++)u[K]<_e&&(_e=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=Pi(_e,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=Ke-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=Pi(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<Ke-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ae)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*Ht+7]=ae,c[A*Ht+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function Fg(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*Ht,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&wg(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function Bg(e,n,t){let o=new Set;if(e.length<2)return o;let r=Math.hypot(n[0],n[1],n[2]);if(r<1e-9)return o;let i=n[0]/r,s=n[1]/r,a=n[2]/r,c=e.map(Rg);if(t&&t.size>0)for(let f of t)c[f]=null;let l=Dg(c),u=new Int32Array(Math.max(64,l.nodeCount));for(let f=0;f<e.length;f++){let d=c[f];if(!d)continue;let m=d.centroid[0]+d.normal[0]*.001,p=d.centroid[1]+d.normal[1]*.001,g=d.centroid[2]+d.normal[2]*.001;d.normal[0]*i+d.normal[1]*s+d.normal[2]*a<=0||Fg(m,p,g,i,s,a,f,l,u)&&o.add(f)}return o}var Uo=1e-5,Vc=.001,Oc=6;function Mi(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let a=1;a+1<n.length;a++){let c=n[a],l=n[a+1],u=c[1]-t[1],f=c[0]-t[0],d=c[2]-t[2],m=l[1]-t[1],p=l[0]-t[0],g=l[2]-t[2];o-=f*g-d*p,r-=d*m-u*g,i-=u*p-f*m}let s=Math.hypot(o,r,i);return s<1e-9?null:[o/s,r/s,i/s]}function Rc(e,n){let t=n.meshRotation,o=t?Un(e,t):e;return vr(o,n.rotX,0,n.rotY)[2]}function Kt(e,n,t=Uo){return Rc(e,n)>t}function kg(e,n,t=Uo){let o=Mi(e);return o===null||Kt(o,n,t)}function Lc(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function wc(e){let n=new Map;for(let t of e){if(!t)continue;let o=Lc(t);n.has(o)||n.set(o,t)}return Array.from(n,([t,o])=>({key:t,normal:o}))}function zg(e){return wc(e.map(Mi))}function Nc(e,n=Vc){let t=Math.abs(e[0]),o=Math.abs(e[1]),r=Math.abs(e[2]),i=Math.max(t,o,r);return i>1-n&&t+o+r-i<n}function Ug(e){return e.length<=Oc&&e.every(({normal:n})=>Nc(n))}function Gg(e,n,t=Uo){let o=[];for(let{key:r,normal:i}of e)Kt(i,n,t)&&o.push(r);return o.sort(),o.join("|")}function Si(e,n,t,o,r){let i=(p,g,h)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=g,y[(e+2)%3]=h,y},s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function Dc(e={}){let n=e.size??5,t=e.thickness??.025,o=e.negative??!1,r=e.xColor??"#ff3a3a",i=e.yColor??"#3aff3a",s=e.zColor??"#3a8aff",a=n*t/2,c=o?-n:0;return[...Si(0,c,n,a,r),...Si(1,c,n,a,i),...Si(2,c,n,a,s)]}var $g=["right","left","front","back","top","bottom"];function Ai(e){return[e[0],e[1],e[2]]}function Fc(e,n){return{min:[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.min(e[2],n[2])],max:[Math.max(e[0],n[0]),Math.max(e[1],n[1]),Math.max(e[2],n[2])]}}function Xg(e){if(e.min&&e.max)return Fc(e.min,e.max);let n=e.center?Ai(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=Ai(e.size):t=[1,1,1];let o=[t[0]/2,t[1]/2,t[2]/2];return Fc([n[0]-o[0],n[1]-o[1],n[2]-o[2]],[n[0]+o[0],n[1]+o[1],n[2]+o[2]])}function Yg(e,n){let[t,o,r]=e,[i,s,a]=n;return[{name:"right",vertices:[[i,o,r],[i,s,r],[i,s,a],[i,o,a]]},{name:"left",vertices:[[t,s,r],[t,o,r],[t,o,a],[t,s,a]]},{name:"front",vertices:[[i,s,r],[t,s,r],[t,s,a],[i,s,a]]},{name:"back",vertices:[[t,o,r],[i,o,r],[i,o,a],[t,o,a]]},{name:"top",vertices:[[t,o,a],[i,o,a],[i,s,a],[t,s,a]]},{name:"bottom",vertices:[[t,s,r],[i,s,r],[i,o,r],[t,o,r]]}]}function jg(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function Wg(e,n){let t={vertices:e.vertices.map(Ai)};return n.color!==void 0&&(t.color=n.color),n.texture!==void 0&&(t.texture=n.texture),n.material!==void 0&&(t.material=n.material),n.uvs!==void 0&&(t.uvs=n.uvs.map(o=>[o[0],o[1]])),n.data!==void 0&&(t.data={...n.data}),t}function Bc(e={}){let{min:n,max:t}=Xg(e);if(n[0]===t[0]||n[1]===t[1]||n[2]===t[2])return[];let o={color:e.color??"#ffffff",texture:e.texture,material:e.material,uvs:e.uvs,data:e.data},r=Yg(n,t),i=new Map(r.map(a=>[a.name,a])),s=[];for(let a of $g){let c=e.faces?.[a];if(c===!1)continue;let l=i.get(a);l&&s.push(Wg(l,jg(o,c)))}return s}function kc(e,n,t,o){let r=[0,0,0];return r[e]=n,r[(e+1)%3]=t,r[(e+2)%3]=o,r}function Hg(e,n,t,o,r){let i=(p,g,h)=>kc(e,p,g,h),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function Kg(e,n,t,o,r){let i=(f,d,m)=>kc(e,f,d,m),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,0,0);return[{vertices:[s,a,c,l],color:r},{vertices:[s,a,u],color:r},{vertices:[a,c,u],color:r},{vertices:[c,l,u],color:r},{vertices:[l,s,u],color:r}]}function Zg(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function zc(e){let n=e.axis,t=e.sign??1,o=e.shaftLength??4,r=e.shaftHalfThickness??.05,i=e.headLength??.8,s=e.headHalfThickness??.2,a=e.color??"#ffffff",c=e.shaft??!0,l=o*t,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(o+i)*t,p=Kg(n,d,m,s,a),g=t===-1?Zg(p):p;return c?[...Hg(n,u,f,r,a),...g]:g}function Go(e,n,t){let o=[0,0,0],r=(e+1)%3,i=(e+2)%3;return o[r]=Math.cos(t)*n,o[i]=Math.sin(t)*n,o}function Uc(e){let n=e.axis,t=e.radius,o=e.halfThickness??Math.max(.05,t*.04),r=e.segments??32,i=e.color??"#ffffff",s=t-o,a=t+o,c=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=Go(n,s,u),m=Go(n,s,f),p=Go(n,a,u),g=Go(n,a,f);c.push({vertices:[d,p,g,m],color:i})}return c}function Gc(e){let n=e.axis,t=e.outerRadius,o=e.color??"#ffffff",r=(n+1)%3,i=(n+2)%3,s=(a,c)=>{let l=[0,0,0];return l[n]=0,l[r]=a,l[i]=c,l};return[{vertices:[s(-t,-t),s(t,-t),s(t,t),s(-t,t)],color:o}]}function $c(e){let n=e.axis,t=e.size??.4,o=e.offset??t*2,r=typeof o=="number"?o:o[0],i=typeof o=="number"?o:o[1],s=e.along??0,a=e.color??"#ffffff",c=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=s,m[c]=r+f,m[l]=i+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:a}]}function Xc(e){let{center:n,size:t,color:o="#ffffff"}=e,[r,i,s]=n,a=[[r+t,i,s],[r-t,i,s],[r,i+t,s],[r,i-t,s],[r,i,s+t],[r,i,s-t]];return[[0,2,4],[2,1,4],[1,3,4],[3,0,4],[2,0,5],[1,2,5],[3,1,5],[0,3,5]].map(l=>({vertices:[a[l[0]],a[l[1]],a[l[2]]],color:o}))}function Yc(e={}){let{radius:n=50,color:t="#cccccc"}=e,o=Math.min(Math.max(0,Math.floor(e.subdivisions??1)),3),r=(1+Math.sqrt(5))/2,i=[[-1,r,0],[1,r,0],[-1,-r,0],[1,-r,0],[0,-1,r],[0,1,r],[0,-1,-r],[0,1,-r],[r,0,-1],[r,0,1],[-r,0,-1],[-r,0,1]].map(([c,l,u])=>{let f=Math.sqrt(c*c+l*l+u*u);return[c/f,l/f,u/f]}),s=[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]];for(let c=0;c<o;c++){let l=[...i],u=[],f=new Map,d=(m,p)=>{let g=m<p?`${m}-${p}`:`${p}-${m}`,h=f.get(g);if(h!==void 0)return h;let y=i[m],b=i[p],x=(y[0]+b[0])/2,P=(y[1]+b[1])/2,M=(y[2]+b[2])/2,C=Math.sqrt(x*x+P*P+M*M);x/=C,P/=C,M/=C;let E=l.length;return l.push([x,P,M]),f.set(g,E),E};for(let[m,p,g]of s){let h=d(m,p),y=d(p,g),b=d(g,m);u.push([m,h,b]),u.push([p,y,h]),u.push([g,b,y]),u.push([h,y,b])}i=l,s=u}let a=i.map(([c,l,u])=>[c*n,l*n,u*n]);return s.map(([c,l,u])=>({vertices:[a[c],a[l],a[u]],color:t}))}function jc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=n/Math.sqrt(3),r=[[o,o,o],[o,-o,-o],[-o,o,-o],[-o,-o,o]];return[[0,1,2],[0,3,1],[0,2,3],[1,3,2]].map(([s,a,c])=>({vertices:[r[s],r[a],r[c]],color:t}))}function Wc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=n/Math.sqrt(1+o*o),i=[[-1,o,0],[1,o,0],[-1,-o,0],[1,-o,0],[0,-1,o],[0,1,o],[0,-1,-o],[0,1,-o],[o,0,-1],[o,0,1],[-o,0,-1],[-o,0,1]].map(([a,c,l])=>[a*r,c*r,l*r]);return[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]].map(([a,c,l])=>({vertices:[i[a],i[c],i[l]],color:t}))}function Hc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=1/o,i=n/Math.sqrt(3),a=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1],[0,r,o],[0,-r,o],[0,r,-o],[0,-r,-o],[r,o,0],[-r,o,0],[r,-o,0],[-r,-o,0],[o,0,r],[o,0,-r],[-o,0,r],[-o,0,-r]].map(([l,u,f])=>[l*i,u*i,f*i]);return[[12,13,4,8,0],[0,8,9,2,16],[16,17,1,12,0],[1,10,5,13,12],[17,3,11,10,1],[2,9,6,15,14],[2,14,3,17,16],[14,15,7,11,3],[18,6,9,8,4],[4,13,5,19,18],[5,10,11,7,19],[18,19,7,15,6]].map(l=>({vertices:l.map(u=>a[u]),color:t}))}function $o(e={}){let{radius:n=50,height:t=100,radialSegments:o=12,color:r="#cccccc"}=e,i=e.radiusTop??n,s=t/2,a=-s,c=s,l=Math.max(3,o),u=[],f=Array.from({length:l+1},(p,g)=>g/l*Math.PI*2),d=n<=1e-6,m=i<=1e-6;for(let p=0;p<l&&!(d&&m);p++){let g=f[p],h=f[p+1],y=Math.cos(g)*n,b=Math.sin(g)*n,x=Math.cos(h)*n,P=Math.sin(h)*n,M=Math.cos(g)*i,C=Math.sin(g)*i,E=Math.cos(h)*i,A=Math.sin(h)*i,S=[y,b,a],T=[x,P,a],v=[E,A,c],R=[M,C,c];if(m){let O=[0,0,c];u.push({vertices:[S,T,O],color:r})}else if(d){let O=[0,0,a];u.push({vertices:[O,v,R],color:r})}else u.push({vertices:[S,T,v,R],color:r})}if(n>1e-6){let p=[0,0,a];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*n,Math.sin(h)*n,a],x=[Math.cos(y)*n,Math.sin(y)*n,a];u.push({vertices:[[...p],[...x],[...b]],color:r})}}if(i>1e-6){let p=[0,0,c];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*i,Math.sin(h)*i,c],x=[Math.cos(y)*i,Math.sin(y)*i,c];u.push({vertices:[[...p],[...b],[...x]],color:r})}}return u}function Kc(e={}){return $o({...e,radiusTop:0})}function Xo(e,n,t,o){let r=Math.sin(e),i=Math.cos(e),s=Math.sin(n),a=Math.cos(n);return[(t+o*a)*i,(t+o*a)*r,o*s]}function Zc(e={}){let{radius:n=50,tube:t=15,radialSegments:o=12,tubularSegments:r=16,color:i="#cccccc"}=e,s=Math.max(3,o),a=Math.max(3,r),c=[];for(let l=0;l<s;l++){let u=l/s*Math.PI*2,f=(l+1)/s*Math.PI*2;for(let d=0;d<a;d++){let m=d/a*Math.PI*2,p=(d+1)/a*Math.PI*2,g=Xo(u,m,n,t),h=Xo(f,m,n,t),y=Xo(f,p,n,t),b=Xo(u,p,n,t);c.push({vertices:[g,h,y,b],color:i})}}return c}var qg=.01,Qg=.01;function Jg(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,o=e[0]/t,r=e[1]/t,i=e[2]/t,s=Math.sign(i||1)*Math.max(Math.abs(i),.01),a=n,c=.01;return[1,0,0,0,0,1,0,0,-o/s,-r/s,c,0,a*o/s,a*r/s,a*(1-c),1]}function e0(e,n,t){let o=e[2]-n[2];if(Math.abs(o)<1e-9)return null;let r=(t-e[2])/o;return r<0?null:[e[0]+r*(e[0]-n[0]),e[1]+r*(e[1]-n[1])]}function n0(e,n,t){let o=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],s=Math.hypot(o,r,i)||1;return(n[0]*o+n[1]*r+n[2]*i)/s>0}function t0(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e[0]*o+e[1]*r+e[2]*i>0}function Ci(e){if(e.length<=1)return e.map(s=>[s[0],s[1]]);let t=e.map(s=>[s[0],s[1]]);t.sort((s,a)=>s[0]-a[0]||s[1]-a[1]);let o=(s,a,c)=>(a[0]-s[0])*(c[1]-s[1])-(a[1]-s[1])*(c[0]-s[0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function qc(e){let n=0,t=e.length;for(let o=0;o<t;o++){let r=e[o],i=e[(o+1)%t];n+=r[0]*i[1]-i[0]*r[1]}return n/2}function Tn(e){let n=e.map(t=>[t[0],t[1]]);return qc(n)<0&&n.reverse(),n}function o0(e,n,t){let o=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/o,i=n[1]/o,s=n[2]/o,a=Math.sign(s||1)*Math.max(Math.abs(s),.01),c=e[2]-t;return[e[0]-r/a*c,e[1]-i/a*c]}function Qc(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}function r0(e){if(e.length<3)return e.map((s,a)=>a);let t=e.map((s,a)=>a).sort((s,a)=>e[s][0]-e[a][0]||e[s][1]-e[a][1]),o=(s,a,c)=>(e[a][0]-e[s][0])*(e[c][1]-e[s][1])-(e[a][1]-e[s][1])*(e[c][0]-e[s][0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function Ti(e,n,t){if(e.length<3)return null;let o=Qc(n),r=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],i=r[0]*o[0]+r[1]*o[1]+r[2]*o[2],s=Qc([r[0]-i*o[0],r[1]-i*o[1],r[2]-i*o[2]]),a=[o[1]*s[2]-o[2]*s[1],o[2]*s[0]-o[0]*s[2],o[0]*s[1]-o[1]*s[0]],c=e.map(f=>[f[0]*s[0]+f[1]*s[1]+f[2]*s[2],f[0]*a[0]+f[1]*a[1]+f[2]*a[2]]),l=r0(c);if(l.length<3)return null;let u=Math.max(3,Math.floor(t));if(l.length>u){let f=(d,m,p)=>{let g=c[d][0],h=c[d][1];return Math.abs((c[m][0]-g)*(c[p][1]-h)-(c[p][0]-g)*(c[m][1]-h))*.5};for(;l.length>u;){let d=1/0,m=0;for(let p=0;p<l.length;p++){let g=f(l[(p-1+l.length)%l.length],l[p],l[(p+1)%l.length]);g<d&&(d=g,m=p)}l.splice(m,1)}}return l.map(f=>[e[f][0],e[f][1],e[f][2]])}function Jc(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}var i0=[[],[3,0],[0,1],[3,1],[1,2],[3,0,1,2],[0,2],[3,2],[2,3],[2,0],[0,1,2,3],[2,1],[1,3],[1,0],[0,3],[]];function s0(e,n){if(e.length<4)return e;let t=1,o=-1;for(let u=0;u<e.length;u++){let f=e[u][0]-e[0][0],d=e[u][1]-e[0][1],m=f*f+d*d;m>o&&(o=m,t=u)}let r=u=>{if(u.length<3)return u;let f=u[0],d=u[u.length-1],m=-1,p=n,g=d[0]-f[0],h=d[1]-f[1],y=Math.hypot(g,h)||1;for(let b=1;b<u.length-1;b++){let x=Math.abs((u[b][0]-f[0])*h-(u[b][1]-f[1])*g)/y;x>p&&(p=x,m=b)}return m<0?[f,d]:[...r(u.slice(0,m+1)).slice(0,-1),...r(u.slice(m))]},i=e.slice(0,t+1),s=[...e.slice(t),e[0]],a=r(i),c=r(s),l=[...a.slice(0,-1),...c.slice(0,-1)];return l.length>=3?l:e}function a0(e,n,t){let o=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let s=t[r][0],a=t[r][1],c=t[i][0],l=t[i][1];a>n!=l>n&&e<(c-s)*(n-a)/(l-a)+s&&(o=!o)}return o}function Ei(e,n,t,o=1,r="contour"){let i=Jc(n),s=Math.abs(i[0])<.9?[1,0,0]:[0,1,0],a=s[0]*i[0]+s[1]*i[1]+s[2]*i[2],c=Jc([s[0]-a*i[0],s[1]-a*i[1],s[2]-a*i[2]]),l=[i[1]*c[2]-i[2]*c[1],i[2]*c[0]-i[0]*c[2],i[0]*c[1]-i[1]*c[0]],u=1/0,f=1/0,d=-1/0,m=-1/0,p=1/0,g=-1/0,h=[];for(let D of e){if(D.length<3)continue;let _=[],w=0;for(let V of D){let j=V[0]*c[0]+V[1]*c[1]+V[2]*c[2],G=V[0]*l[0]+V[1]*l[1]+V[2]*l[2],Z=V[0]*i[0]+V[1]*i[1]+V[2]*i[2];_.push([j,G]),w+=Z,j<u&&(u=j),j>d&&(d=j),G<f&&(f=G),G>m&&(m=G),Z<p&&(p=Z),Z>g&&(g=Z)}h.push({pts:_,depth:w/D.length})}if(!Number.isFinite(u)||h.length===0)return null;let y=d-u,b=m-f,x=Math.max(y,b);if(x<1e-6)return null;let P=Math.max(r==="pixel"?3:8,Math.min(384,Math.round(t*(r==="pixel"?1:2)))),M=x/P,C=1,E=u-C*M,A=f-C*M,S=Math.ceil(y/M)+2*C+1,T=Math.ceil(b/M)+2*C+1;if(S*T>4e5)return null;let v=.6,R=(D,_,w)=>{let V=new Uint8Array(S*T),j=(I,B)=>I<0||B<0||I>=S||B>=T?0:V[B*S+I],G=(I,B,N,H,$,k)=>(N-I)*(k-B)-(H-B)*($-I);for(let I of D){let B=I.pts;for(let N=1;N<B.length-1;N++){let H=B[0],$=B[N],k=B[N+1],Q=Math.floor((Math.min(H[0],$[0],k[0])-E)/M),ae=Math.ceil((Math.max(H[0],$[0],k[0])-E)/M),se=Math.floor((Math.min(H[1],$[1],k[1])-A)/M),Y=Math.ceil((Math.max(H[1],$[1],k[1])-A)/M);if(Q<0&&(Q=0),ae>S-1&&(ae=S-1),se<0&&(se=0),Y>T-1&&(Y=T-1),!(Math.abs(G(H[0],H[1],$[0],$[1],k[0],k[1]))<1e-12))for(let ne=se;ne<=Y;ne++){let le=A+(ne+.5)*M;for(let ye=Q;ye<=ae;ye++){if(V[ne*S+ye])continue;let Ae=E+(ye+.5)*M,_e=G($[0],$[1],k[0],k[1],Ae,le),Ee=G(k[0],k[1],H[0],H[1],Ae,le),Me=G(H[0],H[1],$[0],$[1],Ae,le);(_e>=0&&Ee>=0&&Me>=0||_e<=0&&Ee<=0&&Me<=0)&&(V[ne*S+ye]=1)}}}}if(r==="pixel"){let I=new Uint8Array(S*T),B=(N,H)=>{let $=E+N*M,k=A+H*M;return[$*c[0]+k*l[0]+_*i[0],$*c[1]+k*l[1]+_*i[1],$*c[2]+k*l[2]+_*i[2]]};for(let N=0;N<T;N++)for(let H=0;H<S;H++){if(!V[N*S+H]||I[N*S+H])continue;let $=1;for(;H+$<S&&V[N*S+H+$]&&!I[N*S+H+$];)$++;let k=1;e:for(;N+k<T;){for(let Q=0;Q<$;Q++)if(!V[(N+k)*S+H+Q]||I[(N+k)*S+H+Q])break e;k++}for(let Q=N;Q<N+k;Q++)for(let ae=H;ae<H+$;ae++)I[Q*S+ae]=1;w.push([B(H,N),B(H+$,N),B(H+$,N+k),B(H,N+k)])}return}let Z=(I,B)=>`${Math.round(I*2)},${Math.round(B*2)}`,ee=new Map,W=new Map,ie=(I,B,N)=>I===0?[B+.5,N]:I===1?[B+1,N+.5]:I===2?[B+.5,N+1]:[B,N+.5],z=(I,B)=>{let N=Z(I[0],I[1]),H=Z(B[0],B[1]);N!==H&&(ee.has(N)||ee.set(N,[]),ee.has(H)||ee.set(H,[]),ee.get(N).push(B),ee.get(H).push(I),W.set(N,I),W.set(H,B))};for(let I=0;I<T-1;I++)for(let B=0;B<S-1;B++){let N=j(B,I)|j(B+1,I)<<1|j(B+1,I+1)<<2|j(B,I+1)<<3,H=i0[N];for(let $=0;$<H.length;$+=2)z(ie(H[$],B,I),ie(H[$+1],B,I))}if(ee.size===0)return;let X=new Set,U=[];for(let I of ee.keys()){if(X.has(I))continue;let B=[],N=I,H="",$=0;for(;N&&!X.has(N)&&$++<1e6;){X.add(N),B.push(W.get(N));let Q=ee.get(N)??[],ae="";for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H&&!X.has(Y)){ae=Y;break}}if(!ae)for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H){ae=Y;break}}if(H=N,N=ae,N===I)break}if(B.length<3)continue;let k=s0(B,v);k.length>=3&&U.push(k)}for(let I of U){let B=0,N=I[0][0],H=I[0][1];for(let se of U)se!==I&&a0(N,H,se)&&B++;let $=B%2===0,k=0;for(let se=0;se<I.length;se++){let Y=I[se],ne=I[(se+1)%I.length];k+=Y[0]*ne[1]-ne[0]*Y[1]}let ae=k>0===$?I:[...I].reverse();w.push(ae.map(se=>{let Y=E+se[0]*M,ne=A+se[1]*M;return[Y*c[0]+ne*l[0]+_*i[0],Y*c[1]+ne*l[1]+_*i[1],Y*c[2]+ne*l[2]+_*i[2]]}))}},O=[],L=Math.max(1,Math.floor(o));if(L<=1||g-p<1e-6){let D=g+(g-p)+x;R(h,D,O)}else{let D=g-p,_=D/L,w=D*.05;for(let V=0;V<L;V++){let j=p+V*_,G=V===L-1?1/0:p+(V+1)*_,Z=h.filter(ee=>ee.depth>=j&&ee.depth<G);Z.length&&R(Z,j-w,O)}}return O.length?O:null}function el(e){let n=0,t=0,o=0,r=0,i=0,s=0,a=0,c=0,l=0,u=!1;for(let y of e)if(y.length>=3&&!u){let b=y[0],x=y[1],P=y[2];n=x[0]-b[0],t=x[1]-b[1],o=x[2]-b[2],r=P[0]-b[0],i=P[1]-b[1],s=P[2]-b[2],a=b[0],c=b[1],l=b[2],u=!0}if(!u)return!0;let f=t*s-o*i,d=o*r-n*s,m=n*i-t*r,p=Math.hypot(f,d,m);if(p<1e-9)return!0;f/=p,d/=p,m/=p;let g=0;for(let y of e)for(let b of y)g=Math.max(g,Math.abs(b[0]-a)+Math.abs(b[1]-c)+Math.abs(b[2]-l));let h=Math.max(.001,g*.001);for(let y of e)for(let b of y){let x=(b[0]-a)*f+(b[1]-c)*d+(b[2]-l)*m;if(Math.abs(x)>h)return!1}return!0}function nl(e,n=300){if(e.length===0||e.length>n)return!1;let t=0,o=0,r=0,i=0,s=!1;for(let c of e)for(let l of c)s||(o=l[0],r=l[1],i=l[2],s=!0),t=Math.max(t,Math.abs(l[0]-o)+Math.abs(l[1]-r)+Math.abs(l[2]-i));let a=Math.max(.001,t*.005);for(let c of e){if(c.length<3)continue;let l=c[0],u=c[1],f=c[2],d=(u[1]-l[1])*(f[2]-l[2])-(u[2]-l[2])*(f[1]-l[1]),m=(u[2]-l[2])*(f[0]-l[0])-(u[0]-l[0])*(f[2]-l[2]),p=(u[0]-l[0])*(f[1]-l[1])-(u[1]-l[1])*(f[0]-l[0]),g=Math.hypot(d,m,p);if(g<1e-9)continue;d/=g,m/=g,p/=g;let h=!1,y=!1;for(let b of e)for(let x of b){let P=(x[0]-l[0])*d+(x[1]-l[1])*m+(x[2]-l[2])*p;if(P>a?h=!0:P<-a&&(y=!0),h&&y)return!1}}return!0}function c0(e){let{polysWorldVerts:n,lightDir:t,definition:o,isSelf:r,style:i,pointLights:s}=e,a=el(n),c=r&&nl(n);if(a||c)return{};let l=r?Math.max(2,Math.min(6,Math.round(o/8))):1,u=i==="pixel"?"pixel":"contour",f=p=>{let g=Ei(n,p,o,l,u);if(g&&g.length)return g;if(!r){let h=[];for(let b of n)for(let x of b)h.push(x);let y=Ti(h,p,o);if(y&&y.length>=3)return[y]}},d=f(t),m;if(s&&s.length>0){let p=0,g=0,h=0,y=0;for(let b of n)for(let x of b)p+=x[0],g+=x[1],h+=x[2],y++;y>0&&(p/=y,g/=y,h/=y),m=[];for(let b of s){let x=[b.position[0]-p,b.position[1]-g,b.position[2]-h];m[b.index]=f(x)}}return{overrideSilhouette:d,overridePointSilhouettes:m}}function Rn(e,n){if(e.length===0||n.length<3)return[];let t=e.map(r=>[r[0],r[1]]),o=n.length;for(let r=0;r<o;r++){if(t.length===0)return[];let i=t;t=[];let s=n[r],a=n[(r+1)%o],c=f=>(a[0]-s[0])*(f[1]-s[1])-(a[1]-s[1])*(f[0]-s[0])>=0,l=(f,d)=>{let m=s[0],p=s[1],g=a[0],h=a[1],y=f[0],b=f[1],x=d[0],P=d[1],M=(m-g)*(b-P)-(p-h)*(y-x);if(Math.abs(M)<1e-12)return[f[0],f[1]];let C=((m-y)*(b-P)-(p-b)*(y-x))/M;return[m+C*(g-m),p+C*(h-p)]},u=i.length;for(let f=0;f<u;f++){let d=i[f],m=i[(f+u-1)%u],p=c(d),g=c(m);p?(g||t.push(l(m,d)),t.push([d[0],d[1]])):g&&t.push(l(m,d))}}return t}function Yo(e){if(!Number.isFinite(e)||e<=0)throw new Error("PolyCSS world unit size must be a positive finite number.");return e}function tl(e,n=50){return e*Yo(n)}function ol(e,n=50){return e/Yo(n)}function cn(e,n=50){let t=Yo(n);return[e[1]*t,e[0]*t,e[2]*t]}function rl(e,n=50){let t=Yo(n);return[e[1]/t,e[0]/t,e[2]/t]}function vi(e){return[e[1],e[0],e[2]]}function il(e){return e?.direction?{...e,direction:vi(e.direction)}:e}var l0=tl,u0=ol,f0=cn,m0=rl,d0=vi,p0=il;function Ii(e){return e==null?[1,1,1]:typeof e=="number"?[e,e,e]:[e[0]??1,e[1]??1,e[2]??1]}function Zt(e){let n=Ii(e),t=n[0]===1&&n[1]===1&&n[2]===1;return(o,r)=>{let i=cn(r),s=o[1]*50,a=o[0]*50,c=o[2]*50,l=t?s:s*n[0],u=t?a:a*n[1],f=t?c:c*n[2];return[l+i[0],u+i[1],f+i[2]]}}function sl(e,n){if(e.length<3||n===0)return e;let t=[],o=e.length;for(let r=0;r<o;r++){let i=e[(r-1+o)%o],s=e[r],a=e[(r+1)%o],c=s[0]-i[0],l=s[1]-i[1],u=a[0]-s[0],f=a[1]-s[1],d=Math.hypot(c,l),m=Math.hypot(u,f);if(d<1e-9||m<1e-9){t.push(s);continue}let p=l/d,g=-c/d,h=f/m,y=-u/m,b=p+h,x=g+y,P=Math.hypot(b,x);if(P<1e-9){t.push(s);continue}let M=b/P,C=x/P,E=M*p+C*g;if(Math.abs(E)<1e-9){t.push(s);continue}let A=n/E;t.push([s[0]+M*A,s[1]+C*A])}return t}var al=.5,cl=.001,ll=.5;function _i(e,n,t,o){let r=[];for(let u=0;u<e.length;u++){if(o.has(u))continue;let f=e[u];if(f.vertices.length<3)continue;let d=f.vertices.map(A=>t(A,n)),m=d[0],p=0,g=0,h=0;for(let A=1;A+1<d.length;A++){let S=d[A],T=d[A+1],v=S[0]-m[0],R=S[1]-m[1],O=S[2]-m[2],L=T[0]-m[0],D=T[1]-m[1],_=T[2]-m[2];p+=D*O-_*R,g+=_*v-L*O,h+=L*R-D*v}let y=Math.hypot(p,g,h);if(y<1e-9)continue;let b=[p/y,g/y,h/y],x=null;for(let A=1;A<d.length;A++){let S=d[A],T=S[0]-m[0],v=S[1]-m[1],R=S[2]-m[2],O=Math.hypot(T,v,R);if(O>1e-9){x=[T/O,v/O,R/O];break}}if(!x)continue;let P=x[0]*b[0]+x[1]*b[1]+x[2]*b[2];x=[x[0]-P*b[0],x[1]-P*b[1],x[2]-P*b[2]];let M=Math.hypot(x[0],x[1],x[2]);if(M<1e-9)continue;x=[x[0]/M,x[1]/M,x[2]/M];let C=[b[1]*x[2]-b[2]*x[1],b[2]*x[0]-b[0]*x[2],b[0]*x[1]-b[1]*x[0]],E=b[0]*m[0]+b[1]*m[1]+b[2]*m[2];r.push({face:f,O:m,n:b,u:x,v:C,offset:E,polyIndex:u})}let i=[];for(let u of r){let f=!1;for(let d of i){let m=d.rep;if(!(1-(u.n[0]*m.n[0]+u.n[1]*m.n[1]+u.n[2]*m.n[2])>cl)&&!(Math.abs(u.offset-m.offset)>ll)){d.faces.push(u),f=!0;break}}f||i.push({rep:u,faces:[u]})}let s=[],a=3,c=u=>`${u[0].toFixed(a)},${u[1].toFixed(a)},${u[2].toFixed(a)}`;for(let u of i){if(u.faces.length===1){l(u.faces);continue}let f=u.faces.map(h=>{let y=new Set;for(let b of h.face.vertices)y.add(c(t(b,n)));return y}),d=u.faces.map((h,y)=>y),m=h=>{for(;d[h]!==h;)d[h]=d[d[h]],h=d[h];return h},p=(h,y)=>{let b=m(h),x=m(y);b!==x&&(d[b]=x)};for(let h=0;h<u.faces.length;h++)for(let y=h+1;y<u.faces.length;y++){let b=f[h],x=f[y],P=0;for(let M of b)if(x.has(M)&&(P++,P>=2))break;P>=2&&p(h,y)}let g=new Map;for(let h=0;h<u.faces.length;h++){let y=m(h),b=g.get(y);b||(b=[],g.set(y,b)),b.push(u.faces[h])}for(let h of g.values())l(h)}function l(u){let f=u[0],{O:d,n:m,u:p,v:g}=f,h=[],y=[],b=[];for(let M of u){let C=[];for(let E of M.face.vertices){let A=t(E,n),S=A[0]-d[0],T=A[1]-d[1],v=A[2]-d[2],R=[S*p[0]+T*p[1]+v*p[2],S*g[0]+T*g[1]+v*g[2]];h.push(R),C.push(R)}C.length>=3&&(y.push(Tn(C)),b.push(M.polyIndex))}if(h.length<3)return;let x=Ci(h);if(x.length<3)return;let P=sl(Tn(x),al);s.push({O:d,n:m,u:p,v:g,outlineUv:P,memberPolysUv:y,memberPolyIndices:b})}return s}function g0(e){let n=typeof e.scale=="number"?e.scale:e.scale?.[0]??1,t=typeof e.scale=="number"?e.scale:e.scale?.[1]??1,o=typeof e.scale=="number"?e.scale:e.scale?.[2]??1,r=n!==1||t!==1||o!==1,i=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),s=e.position?cn(e.position):[0,0,0],a=[];return(s[0]!==0||s[1]!==0||s[2]!==0)&&a.push(`translate3d(${s[0]}px, ${s[1]}px, ${s[2]}px)`),i&&(e.rotation[0]&&a.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&a.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&a.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&a.push(`scale3d(${n}, ${t}, ${o})`),a.length>0?a.join(" "):void 0}function h0(e={}){let n=e.target??Oe.target,t=e.autoCenterOffset??[0,0,0],o=e.layoutScale??1,r=e.worldUnitPx??50,i=(e.zoom??Oe.zoom)/r*o,s=(e.distance??Oe.distance)*o,a=cn([n[0]+t[0],n[1]+t[1],n[2]+t[2]],r);return`${s!==0?`translateZ(${-s}px) `:""}scale(${i}) rotateX(${e.rotX??Oe.rotX}deg) rotate(${e.rotY??Oe.rotY}deg) translate3d(${-a[0]}px, ${-a[1]}px, ${-a[2]}px)`}var mn=50,ft=[.4,-.7,.59],mt="#ffffff",dt=1,pt="#ffffff",gt=.4,Ln=4096,jo=1,Vi=.1,Oi=1,Wo=Ln*Ln,Ri=Wo*3,qt=2048,Li=4*1024*1024,wi=16*1024*1024,Ni=.995,Di=512,y0=12,Te=.001,ge=1e-9,Fi=1e-4,Bi=.1,Ho=.01,b0=.75,x0=1,P0=250,M0=1.5,ki=.75,En=3,zi=2,Ko=4,Ui=[1,10,100,1e3,1e4,1e5,1e6],vn=64,Gi=32,$i=96,tn=64,Xi=128,Zo=50,qo=1e-7,In=16,Yi=.9,on=.75,Qo=.2,ji=.05,Wi=256,Hi=.6,S0=1.5;function Ki(e){return e===void 0||e==="auto"||!Number.isFinite(e)?1:Math.max(0,Math.min(1,e))}var Qt=new Map;function yt(e){if(Qt.has(e)){let t=Qt.get(e);return t===void 0?null:t}let n=Vn(e);return Qt.size>=Di&&Qt.clear(),Qt.set(e,n),n}function dn(e){let n=yt(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Zi({r:e,g:n,b:t}){return`${e},${n},${t}`}function Jo(e){return yt(e)?.alpha??1}function er({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function ul(e,n){if(n)for(let t of n){if(t.scale<=0)continue;let o=dn(t.color);e[0]+=Xe(o.r/255)*t.scale,e[1]+=Xe(o.g/255)*t.scale,e[2]+=Xe(o.b/255)*t.scale}}function nr(e,n,t,o,r){let i=dn(n),s=dn(t),a=Xe(i.r/255),c=Xe(i.g/255),l=Xe(i.b/255),u=Xe(s.r/255),f=Xe(s.g/255),d=Xe(s.b/255),m=[a*e,c*e,l*e];return ul(m,r),{r:(m[0]+u*o)*ht,g:(m[1]+f*o)*ht,b:(m[2]+d*o)*ht}}function A0({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Xe(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function C0(e){return e<=.0031308?e*12.92:1.055*Math.pow(e,1/2.4)-.055}var ht=1/Math.PI;function wn(e,n,t,o,r,i){let s=dn(e),a=dn(t),c=dn(o),l=Xe(s.r/255),u=Xe(s.g/255),f=Xe(s.b/255),d=Xe(a.r/255),m=Xe(a.g/255),p=Xe(a.b/255),g=Xe(c.r/255),h=Xe(c.g/255),y=Xe(c.b/255),b=[d*n,m*n,p*n];ul(b,i);let x=l*(b[0]+g*r)*ht,P=u*(b[1]+h*r)*ht,M=f*(b[2]+y*r)*ht,C=v=>Math.max(0,Math.min(255,Math.round(C0(Math.max(0,Math.min(1,v)))*255))),E=C(x),A=C(P),S=C(M),T=Jo(e);return T<1?`rgba(${E}, ${A}, ${S}, ${T})`:er({r:E,g:A,b:S})}function qi(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=yt(e);if(!t)return e;let o=255/Math.max(1,Math.round(n)-1),r=s=>Math.max(0,Math.min(255,Math.round(Math.round(s/o)*o))),i={r:r(t.rgb[0]),g:r(t.rgb[1]),b:r(t.rgb[2])};return t.alpha<1?`rgba(${i.r}, ${i.g}, ${i.b}, ${t.alpha})`:er(i)}function T0(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function E0(e,n,t){let o=(r,i)=>{let s=i-r;return Math.abs(s)<=t?i:r+Math.sign(s)*t};return{r:o(e.r,n.r),g:o(e.g,n.g),b:o(e.b,n.b)}}function v0(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:er(e)}function I0(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=yt(e),o=yt(n);if(!t||!o)return 1;let r=t.rgb[0]-o.rgb[0],i=t.rgb[1]-o.rgb[1],s=t.rgb[2]-o.rgb[2],a=(t.alpha-o.alpha)*255;return Math.sqrt(r*r+i*i+s*s+a*a)/510}function Qi(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p?(p.degree+=1,p.degree===2?p.polyB=a:p.polyB=null):i.set(m,{polyA:a,polyB:null,vertA:f,vertB:d,degree:1})}}let s=new Map;for(let[a,c]of i)s.set(a,{polyA:c.polyA,polyB:c.polyB,vertA:c.vertA,vertB:c.vertB});return s}function Ji(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e.map(s=>s?s[0]*o+s[1]*r+s[2]*i<-1e-6:!0)}function es(e,n){let o=a=>Math.round(a/1e-4).toString(36),r=a=>`${o(a[0])},${o(a[1])},${o(a[2])}`,i=new Map,s=a=>{let c=r(a);i.set(c,(i.get(c)??0)+1)};for(let a of e.values()){let c=n[a.polyA]??!1,l;a.polyB===null?l=c:l=c!==(n[a.polyB]??!1),l&&(s(a.vertA),s(a.vertB))}for(let a of i.values())if(a!==2)return!1;return!0}function tr(e,n){let t=[];for(let l of e.values()){let u=n[l.polyA]??!1;if(l.polyB===null)u&&t.push([l.vertA,l.vertB]);else{let f=n[l.polyB]??!1;u!==f&&t.push([l.vertA,l.vertB])}}if(t.length===0)return[];let o=1e-4,r=l=>Math.round(l/o).toString(36),i=l=>`${r(l[0])},${r(l[1])},${r(l[2])}`,s=t.map(([l,u])=>({a:l,b:u,aKey:i(l),bKey:i(u),used:!1})),a=new Map;for(let l of s){let u=a.get(l.aKey);u||(u=[],a.set(l.aKey,u)),u.push(l);let f=a.get(l.bKey);f||(f=[],a.set(l.bKey,f)),f.push(l)}let c=[];for(let l of s){if(l.used)continue;let u=[l.a],f=l,d=l.aKey,m=l.bKey;f.used=!0;for(let p=0;p<s.length+1;p++){u.push(f.bKey===m?f.b:f.a);let g=a.get(m)??[],h=null;for(let y of g)if(!(y===f||y.used)){h=y;break}if(!h||(h.used=!0,d=m,m=h.aKey===d?h.bKey:h.aKey,f=h,m===l.aKey))break}u.length>=3&&c.push(u)}return c}var fl=40;function _0(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p||(p=[],i.set(m,p)),p.push(a)}}let s=new Map;for(let a of i.values())if(!(a.length<2))for(let c of a)for(let l of a){if(c===l)continue;let u=s.get(c);u||(u=new Set,s.set(c,u)),u.add(l)}return s}function V0(e,n,t,o){let r=Zt(t),i=!!o&&(o[0]!==0||o[1]!==0||o[2]!==0),s=i?cn(n):null,a=e.map(c=>{if(!c)return{vertices:[],color:""};let l=c.vertices.map(u=>r(u,n));return i&&s&&o&&(l=l.map(u=>{let f=[u[0]-s[0],u[1]-s[1],u[2]-s[2]],d=Un(f,o);return[d[0]+s[0],d[1]+s[1],d[2]+s[2]]})),{vertices:l,color:""}});return Qi(a)}function O0(e,n,t,o,r){let i=[],s=Zt(t),a=!!r&&(r[0]!==0||r[1]!==0||r[2]!==0),c=a?cn(n):null;for(let l=0;l<e.length;l++){if(!o(l))continue;let u=e[l];if(!u)continue;let f=u.vertices.map(M=>s(M,n));a&&c&&r&&(f=f.map(M=>{let C=[M[0]-c[0],M[1]-c[1],M[2]-c[2]],E=Un(C,r);return[E[0]+c[0],E[1]+c[1],E[2]+c[2]]}));let d=1/0,m=1/0,p=1/0,g=-1/0,h=-1/0,y=-1/0;for(let M of f)M[0]<d&&(d=M[0]),M[0]>g&&(g=M[0]),M[1]<m&&(m=M[1]),M[1]>h&&(h=M[1]),M[2]<p&&(p=M[2]),M[2]>y&&(y=M[2]);let b=[[d,m,p],[g,m,p],[d,h,p],[g,h,p],[d,m,y],[g,m,y],[d,h,y],[g,h,y]],x=null,P=0;if(f.length>=3){let M=f[0],C=f[1],E=f[2],A=[C[0]-M[0],C[1]-M[1],C[2]-M[2]],S=[E[0]-M[0],E[1]-M[1],E[2]-M[2]],T=S[1]*A[2]-S[2]*A[1],v=S[2]*A[0]-S[0]*A[2],R=S[0]*A[1]-S[1]*A[0],O=Math.hypot(T,v,R);O>1e-9&&(x=[T/O,v/O,R/O],P=x[0]*M[0]+x[1]*M[1]+x[2]*M[2])}i.push({wv:f,bboxCorners:b,planeN:x,planeOffset:P,polygonIndex:l})}return i}function R0(e,n,t,o,r,i){let s=Zt(t),a=!!i&&(i[0]!==0||i[1]!==0||i[2]!==0),c=a?cn(n):null,f=_i(e,n,a&&c&&i?(h,y)=>{let b=s(h,y),x=[b[0]-c[0],b[1]-c[1],b[2]-c[2]],P=Un(x,i);return[P[0]+c[0],P[1]+c[1],P[2]+c[2]]}:s,o).map((h,y)=>{let{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A}=h,S=1/0,T=1/0,v=-1/0,R=-1/0;for(let Z of C)Z[0]<S&&(S=Z[0]),Z[1]<T&&(T=Z[1]),Z[0]>v&&(v=Z[0]),Z[1]>R&&(R=Z[1]);let O=v-S,L=R-T,D=r*50,_=b[0]+S*P[0]+T*M[0]+D*x[0],w=b[1]+S*P[1]+T*M[1]+D*x[1],V=b[2]+S*P[2]+T*M[2]+D*x[2],G=`matrix3d(${[P[0],P[1],P[2],0,M[0],M[1],M[2],0,x[0],x[1],x[2],0,_,w,V,1].map(Z=>Z.toFixed(4)).join(",")})`;return{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A,minU:S,minV:T,width:O,height:L,matrixCss:G,faceIndex:y,lift:D}}),d=.015,m=.5,p=20,g=new Set;for(let h=0;h<f.length;h++){if(g.has(h))continue;let y=f[h],b=y.n[0]*y.O[0]+y.n[1]*y.O[1]+y.n[2]*y.O[2],x=y.minU,P=y.minV,M=y.minU+y.width,C=y.minV+y.height;for(let E=0;E<f.length;E++){if(E===h||g.has(E))continue;let A=f[E];if(y.n[0]*A.n[0]+y.n[1]*A.n[1]+y.n[2]*A.n[2]<1-d)continue;let T=y.n[0]*A.O[0]+y.n[1]*A.O[1]+y.n[2]*A.O[2];if(T<=b+m||T-b>p)continue;let v=1/0,R=1/0,O=-1/0,L=-1/0;for(let D of A.outlineUv){let _=A.O[0]+D[0]*A.u[0]+D[1]*A.v[0],w=A.O[1]+D[0]*A.u[1]+D[1]*A.v[1],V=A.O[2]+D[0]*A.u[2]+D[1]*A.v[2],j=_-y.O[0],G=w-y.O[1],Z=V-y.O[2],ee=j*y.u[0]+G*y.u[1]+Z*y.u[2],W=j*y.v[0]+G*y.v[1]+Z*y.v[2];ee<v&&(v=ee),ee>O&&(O=ee),W<R&&(R=W),W>L&&(L=W)}if(v<=x&&O>=M&&R<=P&&L>=C){let D=Math.max(0,M-x)*Math.max(0,C-P);if(Math.max(0,O-v)*Math.max(0,L-R)>D*2)continue;g.add(h);break}}}return f=f.filter((h,y)=>!g.has(y)),f}function ml(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:s,allPointLights:a,thisPointIndex:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=Math.hypot(i[0],i[1],i[2])||1,p=i[0]/m,g=i[1]/m,h=i[2]/m,y=!!s,b=y?_=>{let w=s[0]-_[0],V=s[1]-_[1],j=s[2]-_[2],G=Math.hypot(w,V,j)||1;return[w/G,V/G,j/G]}:_=>[p,g,h],x=u?.color??"#ffffff",P=u?.intensity??.4,M=f?.intensity??1,C=f?.color??"#ffffff",E=d?.color??"#000000",A=d?.opacity??.25,S=!y,T=d?.maxExtend??2e3,v=[],R=new Array(r.length).fill(!1),O=r.map((_,w)=>{if(y){if(_.overridePointSilhouettes){let W=_.overridePointSilhouettes[c??-1];if(W)return W}else if(_.overrideSilhouette)return _.overrideSilhouette}else if(_.overrideSilhouette)return _.overrideSilhouette;if(y){if(_.selfShadowEdgeMap)return R[w]=!0,null;let W=_.edgeOwners;if(!W)return null;let ie=_.casterPolygonCount??0;if(ie===0)return null;let z=new Array(ie).fill(!0);for(let X of _.items){if(X.polygonIndex>=ie)continue;let U=X.planeN;if(!U){z[X.polygonIndex]=!0;continue}let I=0,B=0,N=0;for(let k of X.wv)I+=k[0],B+=k[1],N+=k[2];let H=X.wv.length>0?1/X.wv.length:0,$=b([I*H,B*H,N*H]);z[X.polygonIndex]=U[0]*$[0]+U[1]*$[1]+U[2]*$[2]<-1e-6}return es(W,z)?tr(W,z):(R[w]=!0,null)}let V=_.edgeOwners;if(_.selfShadowEdgeMap)return R[w]=!0,null;if(!V)return null;let j=_.casterPolygonCount??0;if(j<fl||_.items.length<fl)return null;let G=0;for(let W of _.items)W.planeN&&G++;if(G*2<_.items.length)return null;let Z=new Array(j).fill(null);for(let W of _.items)W.planeN&&W.polygonIndex<j&&(Z[W.polygonIndex]=W.planeN);let ee=Ji(Z,i);return es(V,ee)?tr(V,ee):(R[w]=!0,null)}),L=(_,w,V,j)=>{if(_.length<3)return[];let G=[],Z=W=>(W[0]-w[0])*V[0]+(W[1]-w[1])*V[1]+(W[2]-w[2])*V[2],ee=(W,ie,z,X)=>{let U=(z-j)/(z-X);return[W[0]+U*(ie[0]-W[0]),W[1]+U*(ie[1]-W[1]),W[2]+U*(ie[2]-W[2])]};for(let W=0;W<_.length;W++){let ie=_[W],z=_[(W+_.length-1)%_.length],X=Z(ie),U=Z(z),I=X>j,B=U>j;I?(B||G.push(ee(z,ie,U,X)),G.push(ie)):B&&G.push(ee(z,ie,U,X))}return G},D={rotX:l.rotX,rotY:l.rotY};for(let _ of n){let{O:w,n:V,u:j,v:G,outlineUv:Z,minU:ee,minV:W,width:ie,height:z}=_,X=b(w),U=X[0]*V[0]+X[1]*V[1]+X[2]*V[2];if(U<=1e-6||!Kt(V,D))continue;let I=Math.max(0,p*V[0]+g*V[1]+h*V[2]),B=0,N=0;for(let re of Z)B+=re[0],N+=re[1];let H=Z.length>0?1/Z.length:0;B*=H,N*=H;let $=[w[0]+B*j[0]+N*G[0],w[1]+B*j[1]+N*G[1],w[2]+B*j[2]+N*G[2]],k=[],Q=0;if(a)for(let re=0;re<a.length;re++){let fe=a[re],me=fe.position[0]-$[0],Pe=fe.position[1]-$[1],pe=fe.position[2]-$[2],Fe=Math.hypot(me,Pe,pe)||1,Le=Math.max(0,me/Fe*V[0]+Pe/Fe*V[1]+pe/Fe*V[2]);k[re]=Le,Q+=(fe.intensity??1)*Le}let ae=re=>(re[0]-w[0])*V[0]+(re[1]-w[1])*V[1]+(re[2]-w[2])*V[2],se=(re,fe,me,Pe)=>{let pe=me/(me-Pe);return[re[0]+pe*(fe[0]-re[0]),re[1]+pe*(fe[1]-re[1]),re[2]+pe*(fe[2]-re[2])]},Y=re=>{let fe=re[0]-w[0],me=re[1]-w[1],Pe=re[2]-w[2],pe=y?b(re):[p,g,h],Fe=y?pe[0]*V[0]+pe[1]*V[1]+pe[2]*V[2]:U,Le=Fe>.001?Fe:.001,Ve=(fe*V[0]+me*V[1]+Pe*V[2])/Le,$e=re[0]-Ve*pe[0],ke=re[1]-Ve*pe[1],ze=re[2]-Ve*pe[2],We=$e-w[0],be=ke-w[1],De=ze-w[2];return[We*j[0]+be*j[1]+De*j[2],We*G[0]+be*G[1]+De*G[2]]},ne=new Map,le=0,ye=ee,Ae=W,_e=_.minU+ie,Ee=_.minV+z,Me=1/0,Re=1/0,F=-1/0,q=-1/0;for(let re of r)for(let fe of re.items)for(let me of fe.wv){let Pe=me[0]-w[0],pe=me[1]-w[1],Fe=me[2]-w[2],Le=Pe*j[0]+pe*j[1]+Fe*j[2],Ve=Pe*G[0]+pe*G[1]+Fe*G[2];Le<Me&&(Me=Le),Le>F&&(F=Le),Ve<Re&&(Re=Ve),Ve>q&&(q=Ve)}let J=Number.isFinite(Me)?[[Me-T,Re-T],[F+T,Re-T],[F+T,q+T],[Me-T,q+T]]:[],te=.05,ue=V[0]*w[0]+V[1]*w[1]+V[2]*w[2],ce=.0025,he=5,Se=.94;for(let re=0;re<r.length;re++){let fe=r[re],me=fe.selfShadowEdgeMap,Pe=O[re];if(Pe!==null){if(Pe.length===0)continue;let pe=!!fe.overrideSilhouette,Fe=!1;if(pe){let Le=0;for(let Ve of Pe){if(Ve.length<3)continue;let $e=L(Ve,w,V,te);if($e.length<3)continue;let ke=$e.map(Y),ze=0;for(let We=0;We<ke.length;We++){let be=ke[We],De=ke[(We+1)%ke.length];ze+=be[0]*De[1]-De[0]*be[1]}Math.abs(ze)>Le&&(Le=Math.abs(ze),Fe=ze<0)}}for(let Le of Pe){if(Le.length<3)continue;let Ve=L(Le,w,V,te);if(Ve.length<3)continue;let $e=Ve.map(Y),ke=pe?Fe?[...$e].reverse():$e:Tn($e),ze=J.length===4?Rn(ke,J):ke;if(ze.length<3)continue;let We=Rn(ze,Z);if(We.length<3)continue;let be;for(let De of _.memberPolysUv){let Ie=Rn(We,Tn(De));Ie.length<3||(be||(be=ne.get(fe.id),be||(be={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,be))),be.verts.push(Ie),be.subPolygonIndices.push(-1),le++)}}continue}for(let pe of fe.items){if(me){let be=me.get(pe.polygonIndex);if(be){let De=!1;for(let Ie of _.memberPolyIndices)if(be.has(Ie)){De=!0;break}if(De){let Ie=pe.planeN;if(!Ie||Math.abs(Ie[0]*V[0]+Ie[1]*V[1]+Ie[2]*V[2])>Se)continue}}}if(pe.planeN&&!R[re]){let be=p,De=g,Ie=h;if(y){let uo=0,fo=0,mo=0;for(let It of pe.wv)uo+=It[0],fo+=It[1],mo+=It[2];let _n=pe.wv.length>0?1/pe.wv.length:0,et=b([uo*_n,fo*_n,mo*_n]);be=et[0],De=et[1],Ie=et[2]}if(pe.planeN[0]*be+pe.planeN[1]*De+pe.planeN[2]*Ie>-1e-6)continue}if(pe.planeN){let be=pe.planeN,De=be[0]*V[0]+be[1]*V[1]+be[2]*V[2];if(Math.abs(De)>1-ce){let Ie=De>0?1:-1;if(Math.abs(pe.planeOffset-Ie*ue)<he)continue}}let Fe=pe.bboxCorners,Le=!1,Ve=1/0,$e=1/0,ke=-1/0,ze=-1/0;for(let be=0;be<8;be++){let De=Fe[be];ae(De)>te&&(Le=!0);let Ie=Y(De);Ie[0]<Ve&&(Ve=Ie[0]),Ie[0]>ke&&(ke=Ie[0]),Ie[1]<$e&&($e=Ie[1]),Ie[1]>ze&&(ze=Ie[1])}if(!Le||ke<ye||Ve>_e||ze<Ae||$e>Ee)continue;let We=pe.wv;for(let be=1;be<We.length-1;be++){let De=We[0],Ie=We[be],lo=We[be+1],uo=ae(De),fo=ae(Ie),mo=ae(lo),_n=[],et=[[De,uo],[Ie,fo],[lo,mo]];for(let nt=0;nt<3;nt++){let[xn,_t]=et[nt],[po,Vt]=et[(nt+1)%3],Ot=_t>te,go=Vt>te;Ot&&_n.push(xn),Ot!==go&&_n.push(se(xn,po,_t,Vt))}if(_n.length<3)continue;let It=_n.map(Y),Ks=Tn(It),Zs=J.length===4?Rn(Ks,J):Ks;if(Zs.length<3)continue;let qs=Rn(Zs,Z);if(qs.length<3)continue;let kn;for(let nt of _.memberPolysUv){let xn=Rn(qs,Tn(nt));if(!(xn.length<3)){if(me){let _t=0,po=1/0,Vt=-1/0,Ot=1/0,go=-1/0;for(let ho=0;ho<xn.length;ho++){let un=xn[ho],Qs=xn[(ho+1)%xn.length];_t+=un[0]*Qs[1]-Qs[0]*un[1],un[0]<po&&(po=un[0]),un[0]>Vt&&(Vt=un[0]),un[1]<Ot&&(Ot=un[1]),un[1]>go&&(go=un[1])}if(Math.abs(_t)*.5<5)continue}kn||(kn=ne.get(fe.id),kn||(kn={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,kn))),kn.verts.push(xn),kn.subPolygonIndices.push(pe.polygonIndex),le++}}}}}if(le===0||!(ie>0)||!(z>0))continue;let ve=S?M*I:(a?.[c??-1]?.intensity??1)*(k[c??-1]??0),xe=M*I+Q+Math.max(0,P),K=A;if(o)if(xe>0){let re=Math.max(0,(xe-ve)/xe);K=A*(1-Math.pow(re,1/2.4))}else K=0;let oe=_.memberPolyIndices[0]??0,de=t[oe]?.color??"#cccccc",qe=S?0:M*I,Ye=[];if(a)for(let re=0;re<a.length;re++){if(y&&re===c)continue;let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Ye.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let Ge=o?E:wn(de,qe,C,x,P,Ye),we=1/0,Ne=1/0,Je=-1/0,Qe=-1/0;for(let re of ne.values())for(let fe of re.verts)for(let me of fe)me[0]<we&&(we=me[0]),me[0]>Je&&(Je=me[0]),me[1]<Ne&&(Ne=me[1]),me[1]>Qe&&(Qe=me[1]);we=Math.floor(we-1),Ne=Math.floor(Ne-1),Je=Math.ceil(Je+1),Qe=Math.ceil(Qe+1),we<ee&&(we=ee),Ne<W&&(Ne=W),Je>ee+ie&&(Je=ee+ie),Qe>W+z&&(Qe=W+z);let hn=Je-we,yn=Qe-Ne;if(!(hn>0)||!(yn>0))continue;let Bn=_.lift,vt=w[0]+we*j[0]+Ne*G[0]+Bn*V[0],Qn=w[1]+we*j[1]+Ne*G[1]+Bn*V[1],bn=w[2]+we*j[2]+Ne*G[2]+Bn*V[2],Jn=`matrix3d(${[j[0],j[1],j[2],0,G[0],G[1],G[2],0,V[0],V[1],V[2],0,vt,Qn,bn,1].map(re=>re.toFixed(4)).join(",")})`,je=[],en=[];for(let re of ne.values()){let fe="";for(let me of re.verts){fe+=`M${(me[0][0]-we).toFixed(1)},${(me[0][1]-Ne).toFixed(1)}`;for(let Pe=1;Pe<me.length;Pe++)fe+=`L${(me[Pe][0]-we).toFixed(1)},${(me[Pe][1]-Ne).toFixed(1)}`;fe+="Z",en.push(me.map(Pe=>[Pe[0],Pe[1]]))}je.push({casterId:re.id,d:fe,casterPolygonIndices:re.subPolygonIndices})}let Ce=[];if(a)for(let re=0;re<a.length;re++){let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Ce.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let Be=o?"":wn(de,M*I,C,x,P,Ce);v.push({faceIndex:_.faceIndex,memberPolyIndices:_.memberPolyIndices,matrixCss:Jn,width:hn,height:yn,fill:Ge,opacity:K,paths:je,fullLitFill:Be,facePolysUv:en})}return v}function L0(e,n){let t=Rt(e)?.rgb??[0,0,0],o=Rt(n)?.rgb??[255,255,255],r=i=>{let s=o[i]??0;return s<=0?255:Math.max(0,Math.min(255,Math.round(t[i]/s*255)))};return`rgb(${r(0)},${r(1)},${r(2)})`}function ns(e,n,t){let o="";for(let r of e)if(!(r.length<3)){o+=`M${(r[0][0]-n).toFixed(1)},${(r[0][1]-t).toFixed(1)}`;for(let i=1;i<r.length;i++)o+=`L${(r[i][0]-n).toFixed(1)},${(r[i][1]-t).toFixed(1)}`;o+="Z"}return o}function w0(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,runDirectional:s,pointPasses:a,allPointLights:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=d?.opacity??.25,p=new Map;for(let b of n)p.set(b.faceIndex,b);let g=new Map,h=(b,x)=>{let P=ml({receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:b,allPointLights:c,thisPointIndex:x,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d});for(let M of P){if(M.facePolysUv.length===0)continue;let C=M.fullLitFill!=="",E=g.get(M.faceIndex);E||(E={memberPolyIndices:M.memberPolyIndices,base:M.fullLitFill,solid:C,layers:[]},g.set(M.faceIndex,E)),E.layers.push({polys:M.facePolysUv,fill:M.fill,opacity:M.opacity})}};s&&h(void 0,void 0);for(let b of a)h(b.lightPos,b.index);let y=[];for(let[b,x]of g){let P=p.get(b);if(!P||x.layers.length===0)continue;let M=1/0,C=1/0,E=-1/0,A=-1/0;for(let z of x.layers)for(let X of z.polys)for(let U of X)U[0]<M&&(M=U[0]),U[0]>E&&(E=U[0]),U[1]<C&&(C=U[1]),U[1]>A&&(A=U[1]);if(!Number.isFinite(M))continue;M=Math.floor(M-1),C=Math.floor(C-1),E=Math.ceil(E+1),A=Math.ceil(A+1);let S=E-M,T=A-C;if(!(S>0)||!(T>0))continue;let{O:v,u:R,v:O,n:L,lift:D}=P,_=v[0]+M*R[0]+C*O[0]+D*L[0],w=v[1]+M*R[1]+C*O[1]+D*L[1],V=v[2]+M*R[2]+C*O[2]+D*L[2],G=`matrix3d(${[R[0],R[1],R[2],0,O[0],O[1],O[2],0,L[0],L[1],L[2],0,_,w,V,1].map(z=>z.toFixed(4)).join(",")})`,Z=x.solid&&x.layers.length>1,ee=null,W=null,ie=[];if(Z){ee=x.base,W="";for(let z of x.layers)W+=ns(z.polys,M,C);for(let z of x.layers)ie.push({d:ns(z.polys,M,C),fill:L0(z.fill,x.base),multiply:!0,opacity:1})}else for(let z of x.layers)ie.push({d:ns(z.polys,M,C),fill:z.fill,multiply:!1,opacity:z.opacity});y.push({faceIndex:b,memberPolyIndices:x.memberPolyIndices,matrixCss:G,width:S,height:T,svgOpacity:Z?m:1,baseFill:ee,baseD:W,layers:ie})}return y}var N0=Symbol.for("polycss.animation.triangleFrameSource"),D0=Symbol.for("polycss.animation.triangleFrameTarget"),dl=2200,os=2201,pl=2202;function F0(e,n){let t=0,o=1,r=1,i=os,s=1/0,a=0,c=!1,l=null,u=!0,f=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(m){r=m},get weight(){return o},set weight(m){o=m},get time(){return t},set time(m){t=m},get isRunning(){return c},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return c=!0,d},stop(){return c=!1,t=0,a=0,l=null,d},reset(){return t=0,a=0,d},fadeIn(m){return l={from:0,to:1,elapsed:0,duration:m},o=0,d},fadeOut(m){return l={from:o,to:0,elapsed:0,duration:m},d},crossFadeTo(m,p){return d.fadeOut(p),m.fadeIn(p),d},crossFadeFrom(m,p){return m.fadeOut(p),d.fadeIn(p),d},setLoop(m,p){return i=m,s=p,d},setEffectiveTimeScale(m){return r=m,d},setEffectiveWeight(m){return o=m,d}};return d._internal={get clip(){return e},get time(){return t},get weight(){return o},get enabled(){return u},get paused(){return f},get running(){return c},get loopMode(){return i},get repetitions(){return s},get completedReps(){return a},set completedReps(m){a=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!c)return;if(l){l.elapsed+=m;let g=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(o=l.from+(l.to-l.from)*g,g>=1&&(o=l.to,l=null,o<=0)){c=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(t+=m*r,i===dl)t>=p&&(t=d.clampWhenFinished?p:0,c=!1);else if(i===os){if(t>=p){let g=t%p,h=Math.floor(t/p);a+=h,t=g,s!==1/0&&a>=s&&(t=d.clampWhenFinished?p:0,c=!1)}}else if(p>0){let g=p*2,h=t%g;if(t>=g){let y=Math.floor(t/g);a+=y,s!==1/0&&a>=s?(t=d.clampWhenFinished?p:0,c=!1):t=h}}}},sampleTime(){if(i===pl){let m=e.duration,p=m*2,g=t%p;return g<=m?g:p-g}return t}},d}function B0(e){return e._internal}function ts(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function k0(e,n){let t=new Map,o=n,r=e;function i(f){let d=ts(n.clips,f);if(!d)throw new Error(`PolyAnimationMixer: no clip found for key "${f}". Available: ${n.clips.map(p=>p.name).join(", ")}`);let m=t.get(d.index);return m||(m=F0(d,n),t.set(d.index,m)),m}function s(f){let d=ts(n.clips,f);return d?t.get(d.index)??null:null}function a(f){let d=[];for(let y of t.values()){let b=B0(y);b.advance(f),b.running&&b.enabled&&d.push({internal:b,clip:b.clip})}if(d.length===0)return;if(d.length===1){let{internal:y,clip:b}=d[0],x=y.sampleTime(),P=o[N0]?.(b.name,x);if(P&&r[D0]?.(P))return;let M=n.sample(b.name,x);e.setPolygons(M);return}let m=0;for(let{internal:y}of d)m+=y.weight;if(m<=0)return;let p=d.map(({internal:y,clip:b})=>({polygons:n.sample(b.name,y.sampleTime()),weight:y.weight/m})),g=p[0].polygons;if(g.length===0)return;let h=g.map((y,b)=>{let x=y.vertices.map((P,M)=>{let C=0,E=0,A=0;for(let{polygons:S,weight:T}of p){let v=S[b];if(!v)continue;let R=v.vertices[M];R&&(C+=R[0]*T,E+=R[1]*T,A+=R[2]*T)}return[C,E,A]});return{...y,vertices:x}});e.setPolygons(h)}function c(){for(let f of t.values())f.stop()}function l(f){let d=ts(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:i,existingAction:s,update:a,stopAllAction:c,uncacheClip:l,uncacheRoot:u}}var is={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},xl={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},z0={0:"POINTS",1:"LINES",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN"},ss=["EXT_meshopt_compression","KHR_meshopt_compression"];function U0(e){return e===5120||e===5121||e===5122||e===5123}function Pl(e){let n=globalThis.TextDecoder;return new n().decode(e)}function G0(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let t=e.slice(5,n),o=e.slice(n+1);if(!t.includes(";base64")){let s=decodeURIComponent(o),a=new Uint8Array(s.length);for(let c=0;c<s.length;c++)a[c]=s.charCodeAt(c)&255;return a}let r=globalThis.atob(o),i=new Uint8Array(r.length);for(let s=0;s<r.length;s++)i[s]=r.charCodeAt(s);return i}function $0(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let t=n.getUint32(4,!0);if(t!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${t})`);let o=12,r=null,i=null;for(;o<e.byteLength;){let s=n.getUint32(o,!0),a=n.getUint32(o+4,!0),c=o+8;if(a===1313821514){let l=new Uint8Array(e,c,s);r=JSON.parse(Pl(l))}else a===5130562&&(i=new Uint8Array(e,c,s));o=c+s}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:i}}function gl(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function X0(e){let n=gl(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=gl(e.asset?.minVersion);if(e.asset?.minVersion&&(!t||t[0]>2||t[0]===2&&t[1]>0))throw new Error(`parseGltf: glTF asset requires minVersion ${e.asset.minVersion}`)}function Y0(e,n,t){let o=e.buffers??[],r=new Set(e.extensionsRequired??[]),i=ss.some(s=>r.has(s));return o.map((s,a)=>{let c=s.uri;if(c){if(c.startsWith("data:"))return G0(c);if(t){let l=t(c);if(l instanceof Uint8Array)return l;throw new Error("parseGltf: resolveBuffer returned a Promise; use parseGltf via async if your buffers are external")}throw new Error(`parseGltf: external buffer URI "${c}" \u2014 provide options.resolveBuffer`)}if(a===0&&n)return n;if(i&&ss.some(l=>s.extensions?.[l]))return new Uint8Array(0);throw new Error(`parseGltf: buffer[${a}] has no uri and no GLB BIN chunk`)})}function eo(e,n,t){let o=e.bufferViews?.[t],r=o?n[o.buffer]:void 0;if(!o||!r)throw new Error(`parseGltf: bad bufferView ${t}`);let i=o.byteOffset??0;if(i<0||o.byteLength<0||i+o.byteLength>r.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${o.buffer}`);return{buffer:r,view:o}}function Ml(e,n,t,o){if(e.count<=0)return;let r=e.byteOffset??0,i=r+t*(e.count-1)+o;if(r<0||i>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function Sl(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function j0(e,n,t){if(t||e===5126)return new Float32Array(n);switch(e){case 5120:return new Int8Array(n);case 5121:return new Uint8Array(n);case 5122:return new Int16Array(n);case 5123:return new Uint16Array(n);case 5125:return new Uint32Array(n);default:throw new Error(`parseGltf: unhandled componentType ${e}`)}}function or(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=is[o.componentType],i=xl[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);if(o.sparse||o.normalized||o.bufferView===void 0){let{values:h}=no(e,n,t);return{array:j0(o.componentType,h,o.normalized),count:o.count,componentCount:i}}let{buffer:s,view:a}=eo(e,n,o.bufferView),c=(a.byteOffset??0)+(o.byteOffset??0),l=o.count*i,u=r*i,f=Sl(a,u);if(Ml(o,a,f,u),f===u){let h=s.buffer.slice(s.byteOffset+c,s.byteOffset+c+l*r),y;switch(o.componentType){case 5120:y=new Int8Array(h);break;case 5121:y=new Uint8Array(h);break;case 5122:y=new Int16Array(h);break;case 5123:y=new Uint16Array(h);break;case 5125:y=new Uint32Array(h);break;case 5126:y=new Float32Array(h);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}return{array:y,count:o.count,componentCount:i}}let d;switch(o.componentType){case 5120:d=new Int8Array(l);break;case 5121:d=new Uint8Array(l);break;case 5122:d=new Int16Array(l);break;case 5123:d=new Uint16Array(l);break;case 5125:d=new Uint32Array(l);break;case 5126:d=new Float32Array(l);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}let m=new DataView(s.buffer),p=s.byteOffset+c,g=0;for(let h=0;h<o.count;h++){let y=p+h*f;for(let b=0;b<i;b++)d[g++]=sr(m,y+b*r,o.componentType)}return{array:d,count:o.count,componentCount:i}}function sr(e,n,t){switch(t){case 5120:return e.getInt8(n);case 5121:return e.getUint8(n);case 5122:return e.getInt16(n,!0);case 5123:return e.getUint16(n,!0);case 5125:return e.getUint32(n,!0);case 5126:return e.getFloat32(n,!0);default:throw new Error(`parseGltf: unhandled componentType ${t}`)}}function hl(e,n){switch(n){case 5120:return Math.max(e/127,-1);case 5121:return e/255;case 5122:return Math.max(e/32767,-1);case 5123:return e/65535;default:return e}}function no(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=is[o.componentType],i=xl[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);let s=r*i,a=new Array(o.count*i).fill(0);if(o.bufferView!==void 0){let{buffer:c,view:l}=eo(e,n,o.bufferView),u=c.byteOffset+(l.byteOffset??0)+(o.byteOffset??0),f=Sl(l,s);Ml(o,l,f,s);let d=new DataView(c.buffer),m=0;for(let p=0;p<o.count;p++){let g=u+p*f;for(let h=0;h<i;h++){let y=sr(d,g+h*r,o.componentType);a[m++]=o.normalized?hl(y,o.componentType):y}}}if(o.sparse){let c=o.sparse,l=c.indices,u=is[l.componentType];if(l.componentType!==5121&&l.componentType!==5123&&l.componentType!==5125)throw new Error(`parseGltf: unhandled sparse index componentType ${l.componentType}`);let{buffer:f,view:d}=eo(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),p=new DataView(f.buffer),{buffer:g,view:h}=eo(e,n,c.values.bufferView),y=g.byteOffset+(h.byteOffset??0)+(c.values.byteOffset??0),b=new DataView(g.buffer);for(let x=0;x<c.count;x++){let P=sr(p,m+x*u,l.componentType);for(let M=0;M<i;M++){let C=sr(b,y+(x*i+M)*r,o.componentType);a[P*i+M]=o.normalized?hl(C,o.componentType):C}}}return{values:a,count:o.count,componentCount:i}}function W0(e,n,t){let o=[],r=[],i=globalThis;for(let s of e.images??[]){if(s.uri){if(t&&!s.uri.startsWith("data:"))try{o.push(new i.URL(s.uri,t).href)}catch{o.push(s.uri)}else o.push(s.uri);continue}if(s.bufferView!==void 0){let a;try{let{buffer:f,view:d}=eo(e,n,s.bufferView),m=d.byteOffset??0;a=f.subarray(m,m+d.byteLength)}catch{o.push("");continue}let c=s.mimeType??"image/png",l=new i.Blob([a],{type:c}),u=i.URL.createObjectURL(l);o.push(u),r.push(u)}else o.push("")}return{urls:o,objectUrls:r}}function yl(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function H0(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:yl(t?.wrapS),t:yl(t?.wrapT)}}function Al(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function K0(e,n){let t=new Map,o=e.materials??[];for(let r=0;r<o.length;r++){let i=o[r].pbrMetallicRoughness?.baseColorTexture?.index;if(i===void 0)continue;let s=e.textures?.[i],a=s?.source;if(a===void 0)continue;let c=n[a];c&&t.set(r,{url:c,wrap:H0(e,s),alphaMode:Al(o[r].alphaMode),texCoord:o[r].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function Z0(e,n,t){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let r=c=>Math.max(0,Math.min(1,c)),i=c=>Math.round(r(c)*255).toString(16).padStart(2,"0"),s=c=>Math.round(r(c)*255),a=t==="opaque"?1:r(o[3]??1);return a<1?`rgba(${s(o[0])}, ${s(o[1])}, ${s(o[2])}, ${Math.round(a*1e3)/1e3})`:`#${i(o[0])}${i(o[1])}${i(o[2])}`}var bt=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Cl(e,n){let t=new Array(16);return Tl(t,e,n)}function Tl(e,n,t){for(let o=0;o<4;o++)for(let r=0;r<4;r++)e[r*4+o]=n[0+o]*t[r*4+0]+n[4+o]*t[r*4+1]+n[8+o]*t[r*4+2]+n[12+o]*t[r*4+3];return e}function rr(e,n){return[e[0]*n[0]+e[4]*n[1]+e[8]*n[2]+e[12],e[1]*n[0]+e[5]*n[1]+e[9]*n[2]+e[13],e[2]*n[0]+e[6]*n[1]+e[10]*n[2]+e[14]]}function El(e,n,t){let o=e?.[0]??0,r=e?.[1]??0,i=e?.[2]??0,s=n?.[0]??0,a=n?.[1]??0,c=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=s+s,p=a+a,g=c+c,h=s*m,y=s*p,b=s*g,x=a*p,P=a*g,M=c*g,C=l*m,E=l*p,A=l*g;return[(1-(x+M))*u,(y+A)*u,(b-E)*u,0,(y-A)*f,(1-(h+M))*f,(P+C)*f,0,(b+E)*d,(P-C)*d,(1-(h+x))*d,0,o,r,i,1]}function q0(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():El(e.translation,e.rotation,e.scale)}function vl(e,n,t){let o=new Array(Math.min(e.length,n.length));for(let r=0;r<o.length;r++)o[r]=e[r]+(n[r]-e[r])*t;return o}function Jt(e){let n=Math.hypot(e[0]??0,e[1]??0,e[2]??0,e[3]??1)||1;return[(e[0]??0)/n,(e[1]??0)/n,(e[2]??0)/n,(e[3]??1)/n]}function Q0(e,n,t){let o=Jt(e),r=Jt(n),i=o[0]*r[0]+o[1]*r[1]+o[2]*r[2]+o[3]*r[3];if(i<0&&(i=-i,r=[-r[0],-r[1],-r[2],-r[3]]),i>.9995)return Jt(vl(o,r,t));let s=Math.acos(Math.max(-1,Math.min(1,i))),a=Math.sin(s),c=Math.sin((1-t)*s)/a,l=Math.sin(t*s)/a;return Jt([o[0]*c+r[0]*l,o[1]*c+r[1]*l,o[2]*c+r[2]*l,o[3]*c+r[3]*l])}function Il(e){return{translation:e?.translation?.slice()??[0,0,0],rotation:e?.rotation?.slice()??[0,0,0,1],scale:e?.scale?.slice()??[1,1,1],matrix:e?.matrix&&e.matrix.length===16?e.matrix.slice():void 0}}function _l(e){return e.matrix?e.matrix.slice():El(e.translation,e.rotation,e.scale)}function J0(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function Vl(e,n){let t=e.nodes??[],o=new Array(t.length),r=new Set,i=new Set,s=(c,l)=>{if(c<0||c>=t.length||i.has(c))return;let u=Cl(l,n[c]??bt);o[c]=u,r.add(c),i.add(c);for(let f of t[c].children??[])s(f,u);i.delete(c)},a=J0(e);if(a.length>0)for(let c of a)s(c,bt);for(let c=0;c<t.length;c++)r.has(c)||s(c,bt);return o}var Ol=Symbol("polycss.gltfAnimationRuntimeInfo"),eh=Symbol.for("polycss.animation.triangleFrameSource");function Rl(e,n){return e?e[Ol]?.withPolygonFilter(n):void 0}function rs(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function nh(e,n,t){return rs(e,n)||rs(e,t)||rs(n,t)}function bl(e,n,t,o,r){if(t===void 0)return;let{values:i,count:s,componentCount:a}=no(e,n,t);if(s!==r||a<1)return;let c=[];for(let l=0;l<s;l++){let u=[];for(let f=0;f<o;f++)u.push(i[l*a+f]??0);c.push(u)}return c}function th(e,n,t,o){if(t===void 0)return Array.from({length:o},()=>bt.slice());let{values:r,componentCount:i,count:s}=no(e,n,t);if(i!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${t} is not MAT4`);let a=[];for(let c=0;c<o;c++){let l=Math.min(c,s-1);a.push(r.slice(l*16,l*16+16))}return a}function ir(e,n){let t=e.componentCount,o=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(o,o+t)}function oh(e,n,t){let o=e.input;if(o.length===0)return[];if(o.length===1||n<=o[0])return ir(e,0);let r=o.length-1;if(n>=o[r])return ir(e,r);let i=0,s=r;for(;i+1<s;){let d=i+s>>1;o[d]<=n?i=d:s=d}let a=o[i],c=o[i+1],l=c>a?(n-a)/(c-a):0,u=ir(e,i),f=ir(e,i+1);return e.interpolation==="STEP"?u:t==="rotation"?Q0(u,f,l):vl(u,f,l)}function Ll(e,n){let t=[];for(let o=0;o<(e.animations?.length??0);o++){let r=e.animations[o],i=(r.samplers??[]).map(c=>{let l=no(e,n,c.input),u=no(e,n,c.output);return{input:l.values,output:u.values,componentCount:u.componentCount,interpolation:c.interpolation??"LINEAR"}}),s=[];for(let c of r.channels??[]){let l=c.target.node,u=c.target.path,f=i[c.sampler];l===void 0||!u||!f||u!=="translation"&&u!=="rotation"&&u!=="scale"||s.push({sampler:f,targetNode:l,path:u})}let a=s.reduce((c,l)=>{let u=l.sampler.input;return Math.max(c,u[u.length-1]??0)},0);t.push({info:{index:o,name:r.name??`animation_${o}`,duration:a,channelCount:s.length},channels:s})}return t}function wl(e,n,t,o){let r=t.info.duration,i=r>0?(o%r+r)%r:Math.max(0,o),s=n.map(a=>({translation:a.translation.slice(),rotation:a.rotation.slice(),scale:a.scale.slice(),matrix:a.matrix?a.matrix.slice():void 0}));for(let a of t.channels){let c=s[a.targetNode];if(!c)continue;let l=oh(a.sampler,i,a.path);c.matrix=void 0,a.path==="translation"?c.translation=l.slice(0,3):a.path==="rotation"?c.rotation=Jt(l.slice(0,4)):a.path==="scale"&&(c.scale=l.slice(0,3))}return Vl(e,s.map(_l))}function rh(e,n,t,o,r,i){if((e.animations??[]).length===0||t.length===0)return;let a=(e.nodes??[]).map(h=>Il(h)),c=a.map(_l),l=Vl(e,c),u=(e.skins??[]).map(h=>({joints:h.joints??[],inverseBindMatrices:th(e,n,h.inverseBindMatrices,h.joints?.length??0)})),f=Ll(e,n),d=f.map(h=>h.info);if(d.length===0)return;let m=h=>{let y=t.map(b=>new Array(b.triangleMask.length).fill(!1));for(let b of h){let x=o[b];if(!x)return;let P=y[x.sourceIndex];if(!P||x.triangleIndex<0||x.triangleIndex>=P.length)return;P[x.triangleIndex]=!0}return y.map((b,x)=>{let P=t[x],M=new Set,C=0;for(let E=0;E+2<P.indices.length;E+=3,C++)b[C]&&(M.add(P.indices[E]),M.add(P.indices[E+1]),M.add(P.indices[E+2]));return{triangleMask:b,activeVertices:Array.from(M).sort((E,A)=>E-A)}})},p=(h,y,b,x,P,M,C,E,A)=>{let S=r(h),T=r(y),v=r(b),R={vertices:[S,T,v],color:x};return P&&(R.texture=P),P&&M&&(R.textureWrap=M),P&&C&&(R.textureAlphaMode=C),E&&(R.doubleSided=!0),A&&(R.uvs=A),R},g=h=>{let y=t.reduce((O,L,D)=>{let _=h?.[D]?.triangleMask??L.triangleMask,w=0;for(let V=0;V<_.length;V++)_[V]&&w++;return O+w},0),b=new Float64Array(Math.max(0,y*9)),x=new Array(y),P=new Array(y).fill(!1),M={polygonCount:0,vertices:b,colors:x,textureFlags:P,solidTriangles:!0},C=t.map(O=>new Array(O.positions.length)),E=u.map(O=>O.joints.map(()=>new Array(16))),A=(O,L)=>{let D=typeof O=="number"?f[O]:f.find(_=>_.info.name===O);return D?wl(e,a,D,L):null},S=(O,L,D,_)=>{let w=D?.activeVertices,V=C[O],j=(G,Z,ee,W)=>{let ie=V[G];ie?(ie[0]=Z,ie[1]=ee,ie[2]=W):V[G]=[Z,ee,W]};if(L.skinIndex!==void 0&&L.joints&&L.weights&&u[L.skinIndex]){let G=u[L.skinIndex],Z=L.joints,ee=L.weights,W=E[L.skinIndex]??[];for(let z=0;z<G.joints.length;z++){let X=G.joints[z],U=_[X],I=G.inverseBindMatrices[z],B=W[z]??(W[z]=new Array(16));W[z]=U&&I?Tl(B,U,I):void 0}let ie=z=>{let X=L.positions[z],U=0,I=0,B=0,N=0,H=Z[z]??[],$=ee[z]??[];for(let k=0;k<4;k++){let Q=$[k]??0;if(Q<=0)continue;let ae=Math.round(H[k]??0),se=W[ae];if(!se)continue;let Y=se[0]*X[0]+se[4]*X[1]+se[8]*X[2]+se[12],ne=se[1]*X[0]+se[5]*X[1]+se[9]*X[2]+se[13],le=se[2]*X[0]+se[6]*X[1]+se[10]*X[2]+se[14];U+=Y*Q,I+=ne*Q,B+=le*Q,N+=Q}if(N>0){let k=1/N;j(z,U*k,I*k,B*k)}else j(z,L.meshBindWorld[0]*X[0]+L.meshBindWorld[4]*X[1]+L.meshBindWorld[8]*X[2]+L.meshBindWorld[12],L.meshBindWorld[1]*X[0]+L.meshBindWorld[5]*X[1]+L.meshBindWorld[9]*X[2]+L.meshBindWorld[13],L.meshBindWorld[2]*X[0]+L.meshBindWorld[6]*X[1]+L.meshBindWorld[10]*X[2]+L.meshBindWorld[14])};if(w)for(let z of w)ie(z);else for(let z=0;z<L.positions.length;z++)ie(z)}else{let G=L.meshNode!==null?_[L.meshNode]??L.meshBindWorld:L.meshBindWorld,Z=ee=>{let W=L.positions[ee];j(ee,G[0]*W[0]+G[4]*W[1]+G[8]*W[2]+G[12],G[1]*W[0]+G[5]*W[1]+G[9]*W[2]+G[13],G[2]*W[0]+G[6]*W[1]+G[10]*W[2]+G[14])};if(w)for(let ee of w)Z(ee);else for(let ee=0;ee<L.positions.length;ee++)Z(ee)}return V},T=(O,L)=>{let D=A(O,L);if(!D)return[];let _=[];for(let w=0;w<t.length;w++){let V=t[w],j=h?.[w],G=j?.triangleMask??V.triangleMask,Z=S(w,V,j,D),ee=0;for(let W=0;W+2<V.indices.length;W+=3,ee++){if(!G[ee])continue;let ie=V.indices[W],z=V.indices[W+1],X=V.indices[W+2],U=Z[ie],I=Z[z],B=Z[X];if(!U||!I||!B)continue;let N;if(V.uvs&&V.texture){let $=V.uvs[ie],k=V.uvs[z],Q=V.uvs[X];$&&k&&Q&&(N=[$,k,Q])}let H=p(U,I,B,V.color,V.texture,V.textureWrap,V.textureAlphaMode,V.doubleSided,N);H&&_.push(H)}}return _},v=(O,L)=>{let D=A(O,L);if(!D)return null;b.length<y*9&&(b=new Float64Array(y*9),M.vertices=b),x.length<y&&(x=new Array(y),M.colors=x),P.length<y&&(P=new Array(y).fill(!1),M.textureFlags=P);let _=0,w=0,V=!1;for(let j=0;j<t.length;j++){let G=t[j],Z=h?.[j],ee=Z?.triangleMask??G.triangleMask,W=S(j,G,Z,D),ie=0;for(let z=0;z+2<G.indices.length;z+=3,ie++){if(!ee[ie])continue;let X=G.indices[z],U=G.indices[z+1],I=G.indices[z+2],B=W[X],N=W[U],H=W[I];if(!B||!N||!H)continue;i(B,b,w),i(N,b,w+3),i(H,b,w+6),x[_]=G.color;let $=!!G.texture;P[_]=$,$&&(V=!0),_++,w+=9}}return M.polygonCount=_,M.solidTriangles=!V,M},R={clips:d,sample:T};return R[eh]=v,R[Ol]={withPolygonFilter(O){let L=m(O);return L?g(L):void 0}},R};return g()}function as(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.materialColors??{},i=n?.materialTextures??{},s=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,a=s.byteLength,c,l=null;if(s.byteLength>=4&&new DataView(s).getUint32(0,!0)===1179937895){let F=$0(s);c=F.doc,l=F.bin}else c=JSON.parse(Pl(new Uint8Array(s)));X0(c);let u=Y0(c,l,n?.resolveBuffer),{urls:f,objectUrls:d}=W0(c,u,n?.baseUrl),m=K0(c,f),p=[],g=new Set,h=new Set(c.extensionsRequired??[]),y=h.has("KHR_mesh_quantization")||(c.extensionsUsed??[]).includes("KHR_mesh_quantization");function b(F,q){g.has(F)||(g.add(F),p.push(q))}function x(F,q){if(F===void 0)return!1;let J=c.accessors?.[F];if(!J)return!1;let te=ue=>c.bufferViews?.[ue]?.extensions?.[q]!==void 0;return!!(J.bufferView!==void 0&&te(J.bufferView)||J.sparse&&(te(J.sparse.indices.bufferView)||te(J.sparse.values.bufferView)))}function P(F){for(let q of ss)if(h.has(q)&&(F.extensions?.[q]||x(F.indices,q)||Object.values(F.attributes??{}).some(J=>x(J,q))))return q}function M(F,q){if(q instanceof Float32Array)return!0;let J=c.accessors?.[F];return y&&J?.type==="VEC3"&&U0(J.componentType)}function C(F,q){return(q!==null?c.nodes?.[q]?.weights:void 0)??F.weights??[]}function E(F,q,J,te,ue){let ce=J.targets;if(!ce||ce.length===0)return;let he=C(F,te);if(!he.some(xe=>Number.isFinite(xe)&&xe!==0))return;let Se=Array.from({length:ue},()=>[0,0,0]),ve=!1;for(let xe=0;xe<ce.length;xe++){let K=he[xe]??0;if(!Number.isFinite(K)||K===0)continue;let oe=ce[xe]?.POSITION;if(oe===void 0)continue;let{array:de,count:qe,componentCount:Ye}=or(c,u,oe);if(qe!==ue||Ye<3){b(`morph-position-count:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with mismatched count`);continue}if(!M(oe,de)){b(`morph-position-type:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with unsupported accessor type`);continue}ve=!0;for(let Ge=0;Ge<ue;Ge++){let we=Ge*Ye,Ne=Se[Ge];Ne[0]+=Number(de[we])*K,Ne[1]+=Number(de[we+1])*K,Ne[2]+=Number(de[we+2])*K}}return ve?Se:void 0}let A=[],S=[],T=[],v=(c.meshes??[]).map((F,q)=>F.name??`mesh_${q}`),R=(c.materials??[]).map((F,q)=>F.name??`material_${q}`);function O(F,q){if(q===4)return F;let J=[];if(q===5)for(let te=0;te+2<F.length;te++)J.push(F[te],F[te+1+te%2],F[te+2-te%2]);else if(q===6)for(let te=0;te+2<F.length;te++)J.push(F[te+1],F[te+2],F[0]);return J}function L(F){let q=[];for(let J=0;J+2<F.length;J+=3){let te=F[J],ue=F[J+1],ce=F[J+2];q.push(te,ue,ce,te,ce,ue)}return q}function D(F,q,J){let te=c.meshes?.[F];if(te){if(!Array.isArray(te.primitives)){b(`malformed-primitives:${F}`,`Mesh ${te.name??F}: skipped mesh with non-array primitives`);return}for(let ue=0;ue<te.primitives.length;ue+=1){let ce=te.primitives[ue];if(!ce)continue;let he=ce.mode??4;if(he!==4&&he!==5&&he!==6){let Ce=z0[he]??`mode ${he}`;b(`unsupported-mode:${he}`,`Skipped primitives with unsupported mode ${he} (${Ce})`);continue}if(ce.extensions?.KHR_draco_mesh_compression&&h.has("KHR_draco_mesh_compression")){b("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}let Se=P(ce);if(Se){b(Se,`Skipped primitives with unsupported required extension ${Se}`);continue}if(ce.attributes.POSITION===void 0){b(`missing-position:${F}`,`Mesh ${te.name??F}: skipped primitive without POSITION attribute`);continue}let ve=ce.material!==void 0?c.materials?.[ce.material]:void 0,xe=Al(ve?.alphaMode),K=ve?.name,de=(K?r[K]:void 0)??Z0(ve,o,xe),qe=ve?.doubleSided===!0,Ye=ce.material!==void 0?m.get(ce.material):void 0,Ge=K&&i[K]?i[K]:ce.material!==void 0?Ye?.url:void 0,we=Ge&&ce.material!==void 0?Ye?.wrap:void 0,Ne=Ge?Ye?.alphaMode??xe:void 0,Je=Ge?Ye?.texCoord??0:0,Qe=ce.attributes.POSITION,{array:hn,count:yn,componentCount:Bn}=or(c,u,Qe);if(!M(Qe,hn))continue;let vt=E(te,F,ce,J,yn),Qn=[],bn=[];for(let Ce=0;Ce<yn;Ce++){let Be=Ce*Bn,re=vt?.[Ce],fe=[Number(hn[Be])+(re?.[0]??0),Number(hn[Be+1])+(re?.[1]??0),Number(hn[Be+2])+(re?.[2]??0)];Qn.push(fe),bn.push(rr(q,fe))}let ln=null,Jn=ce.attributes[`TEXCOORD_${Je}`];if(Ge&&Jn!==void 0){let{array:Ce,count:Be}=or(c,u,Jn);ln=[];let re=1;Ce instanceof Uint8Array?re=1/255:Ce instanceof Uint16Array&&(re=1/65535);for(let fe=0;fe<Be;fe++){let me=Ce[fe*2]*re,Pe=Ce[fe*2+1]*re;ln.push([me,1-Pe])}}let je;if(ce.indices!==void 0){let{array:Ce,count:Be}=or(c,u,ce.indices);je=[];for(let re=0;re<Be;re++)je.push(Number(Ce[re]))}else je=bn.map((Ce,Be)=>Be);je=O(je,he),qe&&(je=L(je));let en;if((c.animations?.length??0)>0){let Ce=bl(c,u,ce.attributes.JOINTS_0,4,yn),Be=bl(c,u,ce.attributes.WEIGHTS_0,4,yn);en={sourceIndex:S.length,meshNode:J,meshBindWorld:q,skinIndex:J!==null?c.nodes?.[J]?.skin:void 0,positions:Qn,indices:je,triangleMask:[],color:de,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:ln??void 0,joints:Ce,weights:Be},S.push(en)}for(let Ce=0;Ce+2<je.length;Ce+=3){let Be=je[Ce],re=je[Ce+1],fe=je[Ce+2],me=en?en.triangleMask.length:void 0;en&&en.triangleMask.push(!1);let Pe=bn[Be],pe=bn[re],Fe=bn[fe];if(!Pe||!pe||!Fe)continue;let Le;if(ln&&Ge){let $e=ln[Be],ke=ln[re],ze=ln[fe];$e&&ke&&ze&&(Le=[$e,ke,ze])}let Ve=`${F}:${ue}:${J??"root"}`;A.push({v0:Pe,v1:pe,v2:Fe,color:de,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:Le,simplifySourceVertexKeys:[`${Ve}:${Be}`,`${Ve}:${re}`,`${Ve}:${fe}`],source:en,sourceIndex:en?.sourceIndex,sourceTriangleIndex:me})}}}}function _(F,q,J){if(J.has(F)){b(`recursive-node:${F}`,`Skipped recursive node reference ${F} in glTF scene graph`);return}let te=c.nodes?.[F];if(!te)return;let ue=Cl(q,q0(te));typeof te.mesh=="number"&&D(te.mesh,ue,F),J.add(F);for(let ce of te.children??[])_(ce,ue,J);J.delete(F)}function w(F){let q=new Set,J=F.info.duration;for(let te of F.channels)for(let ue of te.sampler.input)!Number.isFinite(ue)||ue<=0||J>0&&ue>=J||q.add(ue);return J>0&&(q.add(J*.25),q.add(J*.5),q.add(J*.75)),Array.from(q).sort((te,ue)=>te-ue).slice(0,128)}function V(F,q){let J=F.source;if(!J||F.sourceTriangleIndex===void 0||J.skinIndex!==void 0)return;let te=F.sourceTriangleIndex*3,ue=J.indices[te],ce=J.indices[te+1],he=J.indices[te+2],Se=ue!==void 0?J.positions[ue]:void 0,ve=ce!==void 0?J.positions[ce]:void 0,xe=he!==void 0?J.positions[he]:void 0;if(!Se||!ve||!xe)return;let K=J.meshNode!==null?q[J.meshNode]??J.meshBindWorld:J.meshBindWorld;return{v0:rr(K,Se),v1:rr(K,ve),v2:rr(K,xe)}}function j(F,q){return F[0]===q[0]&&F[1]===q[1]&&F[2]===q[2]}function G(F){return j(F.v0,F.v1)||j(F.v0,F.v2)||j(F.v1,F.v2)}function Z(){return A.some(F=>!G(F))}function ee(){if(A.length===0||(c.animations?.length??0)===0||Z())return;let F=Ll(c,u);if(F.length===0)return;let q=(c.nodes??[]).map(te=>Il(te)),J=new Array(A.length);for(let te of F)for(let ue of w(te)){let ce=wl(c,q,te,ue);for(let he=0;he<A.length;he++){if(J[he])continue;let Se=V(A[he],ce);Se&&!G(Se)&&(J[he]=Se)}}if(J.some(Boolean))for(let te=0;te<A.length;te++){let ue=J[te];ue&&(A[te].v0=ue.v0,A[te].v1=ue.v1,A[te].v2=ue.v2)}}let W=c.scene??0,ie=c.scenes?.[W]?.nodes;if(ie&&ie.length>0)for(let F of ie)_(F,bt,new Set);else{(c.meshes?.length??0)===0&&b("no-gltf-meshes","No glTF meshes found");for(let F=0;F<(c.meshes?.length??0);F++)D(F,bt,null)}ee();let z=ih(d);if(A.length===0)return{polygons:[],objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:0,meshes:v,materials:R,sourceBytes:a}};let X=1/0,U=1/0,I=1/0,B=-1/0,N=-1/0,H=-1/0;for(let F of A)for(let q of[F.v0,F.v1,F.v2])q[0]<X&&(X=q[0]),q[0]>B&&(B=q[0]),q[1]<U&&(U=q[1]),q[1]>N&&(N=q[1]),q[2]<I&&(I=q[2]),q[2]>H&&(H=q[2]);let $=Math.max(B-X,N-U,H-I),k=$>0?t/$:1,Q=n?.center,ae=Q===!0||Q==="center",se=ae?(X+B)*.5:X,Y=ae?(U+N)*.5:U,ne=ae?(I+H)*.5:I,le=F=>Math.round(F*1e3)/1e3,ye=n?.upAxis??"y",Ae=ye==="z"?([F,q,J])=>[le((F-se)*k),le((q-Y)*k),le((J-ne)*k)]:([F,q,J])=>[le((J-ne)*k),le((F-se)*k),le((q-Y)*k)],_e=ye==="z"?(F,q,J)=>{q[J]=le((F[0]-se)*k),q[J+1]=le((F[1]-Y)*k),q[J+2]=le((F[2]-ne)*k)}:(F,q,J)=>{q[J]=le((F[2]-ne)*k),q[J+1]=le((F[0]-se)*k),q[J+2]=le((F[1]-Y)*k)},Ee=[],Me=0;for(let F of A){let q=Ae(F.v0),J=Ae(F.v1),te=Ae(F.v2),ue=nh(q,J,te);if(F.source&&F.sourceTriangleIndex!==void 0&&(F.source.triangleMask[F.sourceTriangleIndex]=!ue),ue){Me++;continue}let ce={vertices:[q,J,te],color:F.color};F.texture&&(ce.texture=F.texture),F.texture&&F.textureWrap&&(ce.textureWrap=F.textureWrap),F.texture&&F.textureAlphaMode&&(ce.textureAlphaMode=F.textureAlphaMode),F.doubleSided&&(ce.doubleSided=!0),F.uvs&&(ce.uvs=F.uvs),F.simplifySourceVertexKeys&&(ce.simplifySourceVertexKeys=F.simplifySourceVertexKeys),Ee.push(ce),T.push(F.sourceIndex!==void 0&&F.sourceTriangleIndex!==void 0?{sourceIndex:F.sourceIndex,triangleIndex:F.sourceTriangleIndex}:void 0)}Ee.length===0&&Me>0&&b("all-projected-triangles-degenerate","No non-degenerate glTF triangles remained after normalization");let Re=rh(c,u,S,T,Ae,_e);return{polygons:Ee,animation:Re,objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:Ee.length,meshes:v,materials:R,animations:Re?.clips,sourceBytes:a}}}function ih(e){let n=!1;return()=>{if(n)return;n=!0;let t=globalThis.URL;if(t?.revokeObjectURL)for(let o of e)try{t.revokeObjectURL(o)}catch{}}}var Gl=Symbol("polycss.solidTextureBakedAnimationInfo"),Nl=Symbol.for("polycss.animation.triangleFrameSource"),sh=16*1024*1024,ah=2,ch=32,lh=2,uh=.08,fh=8,mh=128,Dl=32,dh=.045,ph=10,xt=6,gh=16;function cs(e){return e.material?.texture??e.texture}function hh(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function yh(e,n){return new Promise((t,o)=>{let r=new n,i=!1,s=a=>{i||(i=!0,a())};r.decoding="async",r.onload=()=>s(()=>t(r)),r.onerror=()=>s(()=>o(new Error(`texture load failed: ${e}`))),r.src=e})}async function bh(e,n,t){try{let o=await yh(e,n.Image),r=Math.max(0,Math.floor(o.naturalWidth||o.width||0)),i=Math.max(0,Math.floor(o.naturalHeight||o.height||0));if(r<=0||i<=0||r*i>t)return null;let s=n.createCanvas();s.width=r,s.height=i;let a=s.getContext("2d",{willReadFrequently:!0});if(!a)return null;a.drawImage(o,0,0,r,i);let c=a.getImageData(0,0,r,i).data;return{width:r,height:i,data:c,lowDetail:xh(r,i,c)}}catch{return null}}function Fl(e,n,t,o,r,i){let s=(o*n+t)*4,a=(i*n+r)*4;return Math.max(Math.abs((e[s]??0)-(e[a]??0)),Math.abs((e[s+1]??0)-(e[a+1]??0)),Math.abs((e[s+2]??0)-(e[a+2]??0)))}function xh(e,n,t){let o=Math.max(1,Math.floor(Math.max(e,n)/mh)),r=0,i=0,s=0;for(let a=0;a<n;a+=o)for(let c=0;c<e;c+=o){if(c+o<e){let l=Fl(t,e,c,a,c+o,a);s+=l,r++,l>Dl&&i++}if(a+o<n){let l=Fl(t,e,c,a,c,a+o);s+=l,r++,l>Dl&&i++}}return r>0&&i/r<=dh&&s/r<=ph}function Bl(e,n,t){return Math.max(n,Math.min(t,e))}function kl(e,n){if(!Number.isFinite(e))return null;switch(n){case"repeat":return e-Math.floor(e);case"mirrored-repeat":{let t=Math.floor(e),o=e-t;return Math.abs(t%2)===1?1-o:o}default:return Math.max(0,Math.min(1,e))}}function Ph(e,n,t){let o=n[0],r=1-n[1],i=kl(o,t?.s),s=kl(r,t?.t);if(i===null||s===null)return null;let a=Bl(Math.floor(i*e.width),0,e.width-1),l=(Bl(Math.floor(s*e.height),0,e.height-1)*e.width+a)*4;return{r:e.data[l]??0,g:e.data[l+1]??0,b:e.data[l+2]??0,a:e.data[l+3]??255}}function Nn(e,n,t,o,r,i){return[e[0]*o+n[0]*r+t[0]*i,e[1]*o+n[1]*r+t[1]*i]}function Mh(e){let[n,t,o]=e;return[Nn(n,t,o,1/3,1/3,1/3),Nn(n,t,o,.8,.1,.1),Nn(n,t,o,.1,.8,.1),Nn(n,t,o,.1,.1,.8),Nn(n,t,o,.45,.45,.1),Nn(n,t,o,.45,.1,.45),Nn(n,t,o,.1,.45,.45)]}function Sh(e){let[n,t,o]=e,r=Mh(e);for(let i=1;i<xt;i++)for(let s=1;s<xt-i;s++){let a=xt-i-s;a<=0||r.push(Nn(n,t,o,i/xt,s/xt,a/xt))}return r}function $l(e){if(e.textureTriangles?.length)return e.textureTriangles;let n=e.uvs;if(!n||n.length!==e.vertices.length||n.length<3)return[];let t=[];for(let o=1;o+1<n.length;o++)t.push({uvs:[n[0],n[o],n[o+1]]});return t}function ls(e,n,t){return Math.abs(e.r-n.r)<=t&&Math.abs(e.g-n.g)<=t&&Math.abs(e.b-n.b)<=t&&Math.abs(e.a-n.a)<=t}function ar(e){let n=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");if(e.a>=255)return`#${n(e.r)}${n(e.g)}${n(e.b)}`;let t=Math.round(Math.max(0,Math.min(255,e.a))/255*1e3)/1e3;return`rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`}function Xl(e){if(!e)return null;let n=e.trim().toLowerCase(),t=n.match(/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(t){let i=t[1],s=a=>{let c=i.length<=4?i[a]+i[a]:i.slice(a*2,a*2+2);return parseInt(c,16)};return{r:s(0),g:s(1),b:s(2),a:i.length===4||i.length===8?s(3):255}}let o=n.match(/^rgba?\(\s*([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)(?:\s*,\s*([0-9.]+)\s*)?\)$/);if(!o)return null;let r=o[4]===void 0?255:Number(o[4])<=1?Number(o[4])*255:Number(o[4]);return{r:Number(o[1]),g:Number(o[2]),b:Number(o[3]),a:r}}function Ah(){return{min:{r:255,g:255,b:255,a:255},max:{r:0,g:0,b:0,a:0},sum:{r:0,g:0,b:0,a:0},colors:new Map,count:0}}function Yl(e){return`${e.r},${e.g},${e.b},${e.a}`}function zl(e,n){e.min.r=Math.min(e.min.r,n.r),e.min.g=Math.min(e.min.g,n.g),e.min.b=Math.min(e.min.b,n.b),e.min.a=Math.min(e.min.a,n.a),e.max.r=Math.max(e.max.r,n.r),e.max.g=Math.max(e.max.g,n.g),e.max.b=Math.max(e.max.b,n.b),e.max.a=Math.max(e.max.a,n.a),e.sum.r+=n.r,e.sum.g+=n.g,e.sum.b+=n.b,e.sum.a+=n.a;let t=Yl(n),o=e.colors.get(t);e.colors.set(t,{color:n,count:(o?.count??0)+1}),e.count++}function Ul(e){return{r:e.sum.r/e.count,g:e.sum.g/e.count,b:e.sum.b/e.count,a:e.sum.a/e.count}}function Ch(e){if(e.count<fh||e.colors.size<=1||e.colors.size>lh)return null;let n=null;for(let r of e.colors.values())(!n||r.count>n.count)&&(n=r);if(!n)return null;let t=e.count-n.count,o=Math.max(1,Math.floor(e.count*uh));return t<=o?n.color:null}function Th(e,n,t,o){let r=$l(e);if(r.length===0)return null;let i=Ah(),s=e.textureAlphaMode==="opaque"?Xl(e.color):null;for(let a of r)for(let c of Sh(a.uvs)){let l=Ph(n,c,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){s&&zl(i,{...s,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),zl(i,l)}if(i.count===0)return e.textureAlphaMode==="opaque"&&e.color?e.color:null;if(e.textureAlphaMode==="opaque"&&i.max.a===0&&e.color)return e.color;if(ls(i.min,i.max,t))return ar(Ul(i));if(!o){let a=Ch(i);if(a)return ar(a)}return o||!n.lowDetail||!ls(i.min,i.max,ch)?null:ar(Ul(i))}function jl(e,n){let{texture:t,textureWrap:o,textureAlphaMode:r,material:i,uvs:s,textureTriangles:a,...c}=e,l=e.uvs?.length===e.vertices.length?e.uvs.map(d=>`uv:${Math.round(d[0]*1e5)},${Math.round(d[1]*1e5)}`):void 0,u=l??e.simplifyVertexKeys,f=e.simplifySourceVertexKeys?.length===e.vertices.length?e.simplifySourceVertexKeys.map((d,m)=>l?`${d}|${l[m]}`:d):e.simplifySourceVertexKeys;return{...c,color:n,...u?{simplifyVertexKeys:u}:{},...f?{simplifySourceVertexKeys:f}:{}}}function Eh(e,n){if(n.length<2)return e;let t=[],o=new Map;for(let l of n){let u=Xl(e[l]?.color);if(!u||u.a<255)continue;let f=Yl(u);t.push({index:l,key:f});let d=o.get(f);d?d.count+=1:o.set(f,{color:u,count:1})}if(o.size<2)return e;let r=[],i=new Map,s=[...o.entries()].sort((l,u)=>u[1].count-l[1].count||l[0].localeCompare(u[0]));for(let[l,u]of s){let f=null;for(let d of r)if(ls(u.color,d,gh)){f=d;break}f||(f=u.color,r.push(f)),i.set(l,ar(f))}let a=!1,c=e.slice();for(let l of t){let u=i.get(l.key),f=e[l.index];!u||!f||f.color===u||(c[l.index]={...f,color:u},a=!0)}return a?c:e}function vh(e,n){let t=e.slice();for(let o=0;o<n.length;o++){let r=n[o],i=e[r.index];i&&(t[r.index]=jl(i,r.color))}return t}function Wl(e){return e?e[Gl]:void 0}async function Hl(e,n={}){if(n.enabled===!1)return null;let t=hh();if(!t)return null;let o=e.filter(c=>cs(c)&&$l(c).length>0);if(o.length===0)return null;let r=n.maxTexturePixels??sh,i=new Map;await Promise.all(Array.from(new Set(o.map(c=>cs(c)))).map(async c=>{i.set(c,await bh(c,t,r))}));let s=n.colorTolerance??ah,a=n.colorTolerance!==void 0;return{bake(c){let l=!1,u=[],f=c.map((d,m)=>{let p=cs(d);if(!p)return d;let g=i.get(p);if(!g)return d;let h=Th(d,g,s,a);return h?(l=!0,u.push(m),jl(d,h)):d});return l?{polygons:Eh(f,u),changed:!0,bakedIndices:u}:{polygons:c,changed:!1,bakedIndices:u}}}}async function Ih(e,n={}){let t=await Hl(e,n);return t?t.bake(e).polygons:e}async function us(e,n={}){let t=await Hl(e.polygons,n);if(!t)return e;let o=t.bake(e.polygons);if(!o.changed)return e;let r=[];for(let a of o.bakedIndices){let l=o.polygons[a].color;l&&r.push({index:a,color:l})}let i=e.animation,s=i&&{...i,sample(a,c){return vh(i.sample(a,c),r)}};if(s&&i){let a=i[Nl];if(a){let c=new Map(r.map(f=>[f.index,f.color])),l=[],u={polygonCount:0,vertices:new Float64Array(0),colors:l,solidTriangles:!1};s[Nl]=(f,d)=>{let m=a(f,d);if(!m)return m;l.length<m.polygonCount&&(l=new Array(m.polygonCount),u.colors=l);let p=m.textureFlags,g=m.solidTriangles===!0||!!p;for(let h=0;h<m.polygonCount;h++){let y=c.get(h);l[h]=y??m.colors?.[h],p?.[h]&&!y&&(g=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=p,u.solidTriangles=g,u}}s[Gl]={source:i,bakedColorEntries:r}}return{...e,polygons:o.polygons,animation:s}}var Kl=Symbol.for("polycss.animation.triangleFrameSource");function _h(e,n){let t=e[n];if(!t)return null;let o=[];for(let r=0;r<t.vertices.length;r++)o.push(n,r);return{rest:t,originalIndex:n,sourceRefs:o}}function Vh(e){let n=Mn(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((r,i)=>t.set(r,i));let o=[];for(let r of n){let i=t.get(r);if(i===void 0)return[];let s=_h(e,i);if(!s)return[];o.push(s)}return o}function fs(e,n,t=!1){let o=new Array(n.length);for(let r=0;r<n.length;r++){let i=n[r],s=i.sourceRefs,a=new Array(s.length/2);for(let l=0,u=0;l<s.length;l+=2,u++){let d=e[s[l]]?.vertices[s[l+1]];if(!d)return e;let m=d[0],p=d[1],g=d[2];if(!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(g))return e;a[u]=[m,p,g]}let c=t?i.rest.color:e[s[0]??-1]?.color??i.rest.color;o[r]={...i.rest,vertices:a,color:c}}return o}function Oh(e,n){let t=new Map;return n.forEach((o,r)=>{t.set(o,r)}),e.map((o,r)=>({...o,sourceRefs:o.sourceRefs.map((i,s)=>s%2===0?t.get(i)??-1:i)}))}function Rh(e,n){if(e.length<n.length)return null;let t=new Array(n.length);for(let o=0;o<n.length;o++){let r=e[o],i=n[o];if(!r||r.vertices.length!==i.rest.vertices.length)return null;t[o]={...i.rest,vertices:r.vertices,color:i.rest.color}}return t}function Lh(e){return!!(e.texture||e.material?.texture)}function wh(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=Vh(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let o=Wl(e.animation),r=o?.source??e.animation,i=t.map(b=>b.originalIndex),s=Rl(r,i),a=s??r,c=s?Oh(t,i):t,l=t.map(b=>b.rest.color),u=t.every(b=>b.rest.vertices.length===3&&!Lh(b.rest)),f=s&&!o&&t.length===i.length&&t.every((b,x)=>b.rest.vertices.length===3&&b.sourceRefs.length===6&&b.sourceRefs[0]===i[x]&&b.sourceRefs[2]===i[x]&&b.sourceRefs[4]===i[x]),d=a[Kl],m=new Float64Array(t.length*9),p=l.slice(),g=new Array(t.length).fill(!1),h={polygonCount:t.length,vertices:m,colors:p,textureFlags:g,solidTriangles:u},y={...e.animation,sample(b,x){let P=a.sample(b,x);return f?P:s&&o?u&&t.length===i.length?Rh(P,t)??fs(P,c,!0):fs(P,c,!0):fs(P,c,!!o)}};return d&&u&&(y[Kl]=(b,x)=>{let P=d(b,x);if(!P)return P;if(s)return P.polygonCount<t.length||P.vertices.length<t.length*9?null:(h.polygonCount=t.length,h.vertices=P.vertices,h.colors=o?l:P.colors,h.textureFlags=o?g:P.textureFlags,h.solidTriangles=o?u:P.solidTriangles===!0,h);m.length<t.length*9&&(m=new Float64Array(t.length*9),h.vertices=m),p.length<t.length&&(p=new Array(t.length),h.colors=p),g.length<t.length&&(g=new Array(t.length).fill(!1),h.textureFlags=g);let M=u&&P.solidTriangles!==!1;for(let C=0;C<c.length;C++){let E=c[C],A=E.sourceRefs;for(let v=0,R=0;v<A.length;v+=2,R++){let O=A[v],L=A[v+1];if(O<0||O>=P.polygonCount)return null;let D=O*9+L*3,_=C*9+R*3;if(D+2>=P.vertices.length)return null;m[_]=P.vertices[D],m[_+1]=P.vertices[D+1],m[_+2]=P.vertices[D+2]}let S=A[0],T=!!P.textureFlags?.[S];g[C]=T,p[C]=o?E.rest.color:P.colors?.[S]??E.rest.color,!o&&T&&(M=!1)}return h.polygonCount=t.length,h.vertices=m,h.colors=p,h.textureFlags=g,h.solidTriangles=o?u:M,h}),{...e,polygons:t.map(b=>b.rest),animation:y,metadata:{...e.metadata,triangleCount:t.length}}}var Nh=/^[0-9A-Fa-f]{6}$/,Dh=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function Fh(e){let n=[],t="";for(let o of e.split(`
|
|
2
2
|
`)){let r=o.endsWith("\r")?o.slice(0,-1):o;if(r.endsWith("\\")){t+=`${r.slice(0,-1).trimEnd()} `;continue}n.push(t+r),t=""}return t&&n.push(t.trimEnd()),n}function ms(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.palette??Dh,i=n?.materialColors??{},s=n?.materialTextures??{},a=[],c=[],l=[],u=[],f=new Map,d=[],m=new Set,p=o,g,h=n?.includeObjects?new Set(n.includeObjects):null,y=n?.excludeObjects?new Set(n.excludeObjects):null,b=null,x=()=>b===null?h===null:!(h&&!h.has(b)||y&&y.has(b)),P=z=>z in i?i[z]:Nh.test(z)?`#${z}`:(f.has(z)||(f.set(z,r[u.length%r.length]),u.push(z)),f.get(z)),M=(z,X)=>{m.has(z)||(m.add(z),d.push(X))},C=(z,X)=>{let U=parseInt(z,10);return Number.isFinite(U)?U<0?X+U:U-1:NaN},E=Fh(e);for(let z of E)if(!(z.length===0||z.charCodeAt(0)===35)){if(z.startsWith("v ")){let X=z.trim().split(/\s+/);a.push([parseFloat(X[1]),parseFloat(X[2]),parseFloat(X[3])])}else if(z.startsWith("vt ")){let X=z.trim().split(/\s+/);c.push([parseFloat(X[1]),parseFloat(X[2])])}else if(z.startsWith("o "))b=z.trim().slice(2).trim();else if(z.startsWith("usemtl ")){let X=z.trim().split(/\s+/)[1];p=P(X),g=s[X]}else if(z.startsWith("p "))x()&&M("unsupported-point-elements","Skipped OBJ point elements; PolyCSS only renders face polygons");else if(z.startsWith("l "))x()&&M("unsupported-line-elements","Skipped OBJ line elements; PolyCSS only renders face polygons");else if(z.startsWith("f ")){if(!x())continue;let X=z.trim().split(/\s+/).slice(1),U=[],I=[];for(let B of X){let N=B.split("/");U.push(C(N[0],a.length));let H=N[1];if(H&&H.length>0){let $=C(H,c.length);I.push(Number.isFinite($)?$:null)}else I.push(null)}l.push({idx:U,uvIdx:I,color:p,texture:g})}}if(a.length===0||l.length===0)return Bh(u,e.length,d);let A=new Set;for(let z of l)for(let X of z.idx)A.add(X);let S=1/0,T=1/0,v=1/0,R=-1/0,O=-1/0,L=-1/0;for(let z of A){let X=a[z];X&&(X[0]<S&&(S=X[0]),X[0]>R&&(R=X[0]),X[1]<T&&(T=X[1]),X[1]>O&&(O=X[1]),X[2]<v&&(v=X[2]),X[2]>L&&(L=X[2]))}let D=Math.max(R-S,O-T,L-v),_=D>0?t/D:1,w=n?.center,V=w===!0||w==="center",j=V?(S+R)*.5:S,G=V?(T+O)*.5:T,Z=V?(v+L)*.5:v,ee=z=>Math.round(z*1e3)/1e3,W=a.map(([z,X,U])=>[ee((U-Z)*_),ee((z-j)*_),ee((X-G)*_)]),ie=[];for(let{idx:z,uvIdx:X,color:U,texture:I}of l)for(let B=1;B<z.length-1;B++){let N=z[0],H=z[B],$=z[B+1],k=W[N],Q=W[H],ae=W[$];if(!k||!Q||!ae||k[0]===Q[0]&&k[1]===Q[1]&&k[2]===Q[2]||k[0]===ae[0]&&k[1]===ae[1]&&k[2]===ae[2]||Q[0]===ae[0]&&Q[1]===ae[1]&&Q[2]===ae[2])continue;let se;if(I){let ne=X[0],le=X[B],ye=X[B+1];if(ne!=null&&le!=null&&ye!=null){let Ae=c[ne],_e=c[le],Ee=c[ye];Ae&&_e&&Ee&&(se=[Ae,_e,Ee])}}let Y={vertices:[k,Q,ae],color:U};I&&(Y.texture=I),se&&(Y.uvs=se),ie.push(Y)}return{polygons:ie,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:ie.length,materials:u,sourceBytes:e.length}}}function Bh(e,n,t=[]){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:t,metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var ds=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function ps(e){let n={},t={},o=null;for(let r of e.split(`
|
|
3
3
|
`)){let i=r.trim();if(!(i.length===0||i.charCodeAt(0)===35)){if(i.startsWith("newmtl ")){o=i.slice(7).trim();continue}if(o){if(i.startsWith("Kd ")){let s=i.split(/\s+/),a=parseFloat(s[1]),c=parseFloat(s[2]),l=parseFloat(s[3]);Number.isFinite(a)&&Number.isFinite(c)&&Number.isFinite(l)&&(n[o]=`#${ds(a)}${ds(c)}${ds(l)}`)}else if(i.startsWith("map_Kd ")){let s=i.split(/\s+/),a=s[s.length-1]?.replace(/\\+/g,"/");a&&a!=="map_Kd"&&(t[o]=a)}}}}return{colors:n,textures:t}}var kh=[0,4294967295,4291624959,4288282623,4284940287,4281597951,4278255615,4294954239,4291611903,4288269567,4284927231,4281584895,4278242559,4294941183,4291598847,4288256511,4284914175,4281571839,4278229503,4294928127,4291585791,4288243455,4284901119,4281558783,4278216447,4294915071,4291572735,4288230399,4284888063,4281545727,4278203391,4294902015,4291559679,4288217343,4284875007,4281532671,4278190335,4294967244,4291624908,4288282572,4284940236,4281597900,4278255564,4294954188,4291611852,4288269516,4284927180,4281584844,4278242508,4294941132,4291598796,4288256460,4284914124,4281571788,4278229452,4294928076,4291585740,4288243404,4284901068,4281558732,4278216396,4294915020,4291572684,4288230348,4284888012,4281545676,4278203340,4294901964,4291559628,4288217292,4284874956,4281532620,4278190284,4294967193,4291624857,4288282521,4284940185,4281597849,4278255513,4294954137,4291611801,4288269465,4284927129,4281584793,4278242457,4294941081,4291598745,4288256409,4284914073,4281571737,4278229401,4294928025,4291585689,4288243353,4284901017,4281558681,4278216345,4294914969,4291572633,4288230297,4284887961,4281545625,4278203289,4294901913,4291559577,4288217241,4284874905,4281532569,4278190233,4294967142,4291624806,4288282470,4284940134,4281597798,4278255462,4294954086,4291611750,4288269414,4284927078,4281584742,4278242406,4294941030,4291598694,4288256358,4284914022,4281571686,4278229350,4294927974,4291585638,4288243302,4284900966,4281558630,4278216294,4294914918,4291572582,4288230246,4284887910,4281545574,4278203238,4294901862,4291559526,4288217190,4284874854,4281532518,4278190182,4294967091,4291624755,4288282419,4284940083,4281597747,4278255411,4294954035,4291611699,4288269363,4284927027,4281584691,4278242355,4294940979,4291598643,4288256307,4284913971,4281571635,4278229299,4294927923,4291585587,4288243251,4284900915,4281558579,4278216243,4294914867,4291572531,4288230195,4284887859,4281545523,4278203187,4294901811,4291559475,4288217139,4284874803,4281532467,4278190131,4294967040,4291624704,4288282368,4284940032,4281597696,4278255360,4294953984,4291611648,4288269312,4284926976,4281584640,4278242304,4294940928,4291598592,4288256256,4284913920,4281571584,4278229248,4294927872,4291585536,4288243200,4284900864,4281558528,4278216192,4294914816,4291572480,4288230144,4284887808,4281545472,4278203136,4294901760,4291559424,4288217088,4284874752,4281532416,4278190318,4278190301,4278190267,4278190250,4278190216,4278190199,4278190165,4278190148,4278190114,4278190097,4278251008,4278246656,4278237952,4278233600,4278224896,4278220544,4278211840,4278207488,4278198784,4278194432,4293787648,4292673536,4290445312,4289331200,4287102976,4285988864,4283760640,4282646528,4280418304,4279304192,4293848814,4292730333,4290493371,4289374890,4287137928,4286019447,4283782485,4282664004,4280427042,4279308561];function zh(e){let n=e>>0&255,t=e>>8&255,o=e>>16&255;return[n,t,o]}function gs(e){return(e&255).toString(16).padStart(2,"0")}function Ql(e,n,t){return`#${gs(e)}${gs(n)}${gs(t)}`}function Uh(e,n,t,o){if(o>=255)return Ql(e,n,t);let r=Math.round(Math.max(0,Math.min(255,o))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function Jl(e){let n=e.match(/^#([0-9a-f]{6})$/i);if(n){let o=n[1];return{rgb:[parseInt(o.slice(0,2),16),parseInt(o.slice(2,4),16),parseInt(o.slice(4,6),16)],alpha:1}}let t=e.match(/^rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)$/i);return t?{rgb:[Number(t[1]),Number(t[2]),Number(t[3])],alpha:Number(t[4])}:null}function eu(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function Zl(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),i=Math.min(n,t,o),s=r-i,a=0;return s!==0&&(r===n?a=60*((t-o)/s%6):r===t?a=60*((o-n)/s+2):a=60*((n-t)/s+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:s/r,value:r}}function Gh(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function nu(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=Zl(e),o=Zl(n),r=t.saturation<.08,i=o.saturation<.08;if(r||i)return r===i;let s=Math.min(t.value,o.value)<.16?35:24;return Gh(t.hue,o.hue)<=s}function $h(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return null;let o=new Map;for(let a of e.keys()){let c=Jl(a);c&&o.set(a,c)}let r=[],i=new Map,s=Array.from(e.entries()).sort((a,c)=>c[1]-a[1]||a[0].localeCompare(c[0]));for(let[a]of s){let c=o.get(a);if(!c){i.set(a,a);continue}let l=null;for(let u of r){if(!nu(c,u.parsed))continue;let f=eu(c,u.parsed);f>t||(!l||f<l.distance)&&(l={color:u.color,distance:f})}l?i.set(a,l.color):(r.push({color:a,parsed:c}),i.set(a,a))}return i}var Xh=[[1,0],[-1,0],[0,1],[0,-1]];function tu(e,n){return`${e},${n}`}function Yh(e){let n=e.indexOf(",");return[Number(e.slice(0,n)),Number(e.slice(n+1))]}function jh(e,n,t){return e<=4||(n===1||t===1)&&e<=12?!0:Math.min(n,t)<=2&&Math.max(n,t)>=4&&e<=18}function Wh(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return;let o=new Map,r=i=>(o.has(i)||o.set(i,Jl(i)),o.get(i)??null);for(let i of e.values()){if(i.size<3)continue;let s=new Map;for(let l of i.values())s.set(l,(s.get(l)??0)+1);let a=new Set,c=[];for(let[l,u]of i){if(a.has(l))continue;let f=[l],d=[],m=new Map,p=1/0,g=-1/0,h=1/0,y=-1/0;for(a.add(l);f.length>0;){let C=f.pop();d.push(C);let[E,A]=Yh(C);p=Math.min(p,E),g=Math.max(g,E),h=Math.min(h,A),y=Math.max(y,A);for(let[S,T]of Xh){let v=tu(E+S,A+T),R=i.get(v);if(R){if(R===u){a.has(v)||(a.add(v),f.push(v));continue}m.set(R,(m.get(R)??0)+1)}}}let b=g-p+1,x=y-h+1;if(!jh(d.length,b,x)||m.size===0)continue;let P=r(u);if(!P)continue;let M=null;for(let[C,E]of m){let A=s.get(C)??0;if(A<=d.length)continue;let S=r(C);if(!S||!nu(P,S))continue;let T=eu(P,S);if(T>t)continue;let v={color:C,contacts:E,distance:T,count:A};(!M||v.contacts>M.contacts||v.contacts===M.contacts&&v.count>M.count||v.contacts===M.contacts&&v.count===M.count&&v.distance<M.distance||v.contacts===M.contacts&&v.count===M.count&&v.distance===M.distance&&v.color.localeCompare(M.color)<0)&&(M=v)}if(M)for(let C of d)c.push([C,M.color])}for(let[l,u]of c)i.set(l,u)}}var Hh=542658390,Kh=new Set(["nTRN","nGRP","nSHP"]),Zh="Skipped MagicaVoxel scene graph transforms; models were flattened into one grid";function hs(e,n){let t=n?.targetSize??60,o=e.byteLength;if(e.byteLength<8)return Pt(o,["parseVox: buffer too small to be a valid .vox file"]);let r=new DataView(e);if(r.getUint32(0,!0)!==Hh)return Pt(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return Pt(o,["parseVox: buffer too small for MAIN chunk"]);if(ql(r,8)!=="MAIN")return Pt(o,["parseVox: expected MAIN chunk at offset 8"]);let c=20+r.getUint32(12,!0),l=c+r.getUint32(16,!0),u=[],f=[],d=[],m=null,p=U=>{d.includes(U)||d.push(U)};for(;c<l&&c+12<=e.byteLength;){let U=ql(r,c),I=r.getUint32(c+4,!0),B=r.getUint32(c+8,!0),N=c+12,H=N+I+B;if(U==="SIZE"){if(I>=12&&N+12<=e.byteLength){let $=r.getUint32(N,!0),k=r.getUint32(N+4,!0),Q=r.getUint32(N+8,!0);u.push({sx:$,sy:k,sz:Q})}}else if(U==="XYZI"){if(I>=4&&N+4<=e.byteLength){let $=r.getUint32(N,!0),k=[],Q=Math.min($,Math.floor((I-4)/4));for(let ae=0;ae<Q;ae++){let se=N+4+ae*4;k.push({x:r.getUint8(se),y:r.getUint8(se+1),z:r.getUint8(se+2),colorIndex:r.getUint8(se+3)})}f.push(k)}}else if(U==="RGBA"&&I>=1024&&N+1024<=e.byteLength){m=[];for(let $=0;$<256;$++){let k=N+$*4,Q=r.getUint8(k),ae=r.getUint8(k+1),se=r.getUint8(k+2),Y=r.getUint8(k+3);m.push(Uh(Q,ae,se,Y))}}Kh.has(U)&&p(Zh),c=H}let g=[],h=new Set;for(let U of f)for(let I of U){if(I.colorIndex===0)continue;let B=`${I.x},${I.y},${I.z}`;h.has(B)||(h.add(B),g.push(I))}if(g.length===0)return Pt(o,d);let y=new Map,b=U=>{let I=y.get(U);if(I)return I;let B=U-1,N;if(m!==null)N=m[B]??"#888888";else{let H=kh[U]??0,[$,k,Q]=zh(H);N=Ql($,k,Q)}return y.set(U,N),N},x=new Map;for(let U of g){let I=b(U.colorIndex);x.set(I,(x.get(I)??0)+1)}let P=$h(x,n?.paletteMergeDistance),M=U=>{let I=b(U);return P?.get(I)??I},C=(U,I,B)=>h.has(`${U},${I},${B}`),E=new Map,A=(U,I,B,N,H)=>{let $=`${U}:${I}`,k=E.get($);k||(k=new Map,E.set($,k)),k.set(tu(B,N),H)};for(let U of g){let{x:I,y:B,z:N}=U,H=M(U.colorIndex);C(I+1,B,N)||A(0,I+1,B,N,H),C(I-1,B,N)||A(1,I,B,N,H),C(I,B+1,N)||A(2,B+1,I,N,H),C(I,B-1,N)||A(3,B,I,N,H),C(I,B,N+1)||A(4,N+1,I,B,H),C(I,B,N-1)||A(5,N,I,B,H)}Wh(E,n?.colorRegionMergeDistance);let S=new Map;for(let[U,I]of E)for(let[B,N]of I){let H=`${U}:${N}`,$=S.get(H);$||($=new Set,S.set(H,$)),$.add(B)}function T(U){let I=new Set,B=[],N=1/0,H=-1/0,$=1/0,k=-1/0;for(let Q of U){let[ae,se]=Q.split(","),Y=+ae,ne=+se;Y<N&&(N=Y),Y>H&&(H=Y),ne<$&&($=ne),ne>k&&(k=ne)}for(let Q=$;Q<=k;Q++)for(let ae=N;ae<=H;ae++){let se=`${ae},${Q}`;if(!U.has(se)||I.has(se))continue;let Y=1;for(;ae+Y<=H;){let le=`${ae+Y},${Q}`;if(!U.has(le)||I.has(le))break;Y++}let ne=1;e:for(;Q+ne<=k;){for(let le=0;le<Y;le++){let ye=`${ae+le},${Q+ne}`;if(!U.has(ye)||I.has(ye))break e}ne++}for(let le=0;le<ne;le++)for(let ye=0;ye<Y;ye++)I.add(`${ae+ye},${Q+le}`);B.push({u:ae,v:Q,w:Y,h:ne})}return B}let v=(U,I,B,N,H,$)=>{let k=B+H,Q=N+$;switch(U){case 0:return[[I,B,N],[I,k,N],[I,k,Q],[I,B,Q]];case 1:return[[I,k,N],[I,B,N],[I,B,Q],[I,k,Q]];case 2:return[[B,I,N],[B,I,Q],[k,I,Q],[k,I,N]];case 3:return[[k,I,N],[k,I,Q],[B,I,Q],[B,I,N]];case 4:return[[B,N,I],[k,N,I],[k,Q,I],[B,Q,I]];default:return[[B,Q,I],[k,Q,I],[k,N,I],[B,N,I]]}},R=[];for(let[U,I]of S){let B=U.indexOf(":"),N=U.indexOf(":",B+1),H=+U.slice(0,B),$=+U.slice(B+1,N),k=U.slice(N+1);for(let{u:Q,v:ae,w:se,h:Y}of T(I))R.push({vertices:v(H,$,Q,ae,se,Y),color:k})}if(R.length===0)return Pt(o,d);let O=1/0,L=1/0,D=1/0,_=-1/0,w=-1/0,V=-1/0;for(let U of R)for(let I of U.vertices)I[0]<O&&(O=I[0]),I[0]>_&&(_=I[0]),I[1]<L&&(L=I[1]),I[1]>w&&(w=I[1]),I[2]<D&&(D=I[2]),I[2]>V&&(V=I[2]);let j=Math.max(_-O,w-L,V-D),G=j>0?t/j:1,Z=G*50,ee=Number.isFinite(Z)&&Z>0?Math.max(1,Math.round(Z))/50:G,W={kind:"magica-vox",cells:g.map(U=>({x:w-(U.y+1),y:U.x-O,z:U.z-D,color:M(U.colorIndex)})),rows:Math.max(0,w-L),cols:Math.max(0,_-O),depth:Math.max(0,V-D),scale:ee,sourceBytes:o},ie=U=>Math.round(U*1e3)/1e3,z=U=>[ie((U[0]-O)*ee),ie((U[1]-L)*ee),ie((U[2]-D)*ee)],X=R.map(({vertices:U,color:I})=>({vertices:U.map(z),color:I}));return{polygons:X,voxelSource:W,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:X.length,sourceBytes:o,voxelCount:g.length}}}function ql(e,n){return String.fromCharCode(e.getUint8(n))+String.fromCharCode(e.getUint8(n+1))+String.fromCharCode(e.getUint8(n+2))+String.fromCharCode(e.getUint8(n+3))}function Pt(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var qh="#888888";var Qh=/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/,Kn="COLOR=";function iu(e,n,t){let o=n??t;if(!Number.isFinite(o))throw new Error(`parseStl: ${e} must be finite`);return o}function Jh(e,n,t){let o=iu(e,n,t);if(o<=0)throw new Error(`parseStl: ${e} must be greater than 0`);return o}function ey(e){if(e===void 0||e==="z"||e==="y")return e??"z";throw new Error('parseStl: upAxis must be "z" or "y"')}function ny(e){let n=e??qh;if(typeof n!="string"||n.trim().length===0)throw new Error("parseStl: defaultColor must be a non-empty string");return n}function ty(e){if(typeof e=="string")return null;if(e instanceof Uint8Array)return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new Error("parseStl: source must be an ArrayBuffer, Uint8Array, or ASCII string")}function su(e){let n=globalThis.TextDecoder;return new n().decode(e)}function cr(e,n){return[e.getFloat32(n,!0),e.getFloat32(n+4,!0),e.getFloat32(n+8,!0)]}function lr(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function ou(e){let n=e.trim().split(/\s+/);if(n.length!==3||!n.every(o=>Qh.test(o)))return null;let t=[Number(n[0]),Number(n[1]),Number(n[2])];return lr(t)?t:null}function oy(e){let n="";for(let o of e)o!==0&&(n+=o>=32&&o<=126?String.fromCharCode(o):" ");return n.replace(/\s+/g," ").trim()||void 0}function ys(e){return Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")}function au(e,n,t,o=255){if(o>=255)return`#${ys(e)}${ys(n)}${ys(t)}`;let r=Math.round(o/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function bs(e){return Math.round(e/31*255)}function ry(e){for(let n=0;n<80-Kn.length-4;n+=1){let t=!0;for(let a=0;a<Kn.length;a+=1)if(e.getUint8(n+a)!==Kn.charCodeAt(a)){t=!1;break}if(!t)continue;let o=e.getUint8(n+Kn.length),r=e.getUint8(n+Kn.length+1),i=e.getUint8(n+Kn.length+2),s=e.getUint8(n+Kn.length+3);return{defaultColor:au(o,r,i,s),alpha:Math.round(s/255*1e3)/1e3,alphaByte:s}}return null}function iy(e,n){if((e&32768)!==0)return{color:n.defaultColor,usesDefaultColor:!0};let t=bs(e&31),o=bs(e>>5&31),r=bs(e>>10&31);return{color:au(t,o,r,n.alphaByte),usesDefaultColor:!1}}function sy(e){let n=[],t=/^\s*solid(?:\s+([^\r\n]*?))?\s*$/gim,o=/^\s*endsolid\b[^\r\n]*$/gim,r;for(;r=t.exec(e);)n.push({index:r.index,kind:"start",name:(r[1]??"").trim()});for(;r=o.exec(e);)n.push({index:r.index,kind:"end"});return n.sort((i,s)=>i.index-s.index||(i.kind==="end"?-1:1))}function ay(e){let n=Math.min(e.byteLength,1024);for(let t=84;t<n;t+=1){let o=e[t];if(o===0||o<9||o>13&&o<32||o>126)return!0}return!1}function cy(e){let n=su(e.subarray(0,Math.min(e.byteLength,512))).trimStart().toLowerCase();return!n.startsWith("solid")&&!n.startsWith("facet")?!1:!ay(e)}function ly(e){if(e.byteLength<84)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0),o=84+t*50;if(o===e.byteLength)return{triangleCount:t,declaredTriangleCount:t,trailingBytes:0};if(cy(e))return null;if(o<e.byteLength)return{triangleCount:t,declaredTriangleCount:t,trailingBytes:e.byteLength-o};let r=e.byteLength-84;return r>0&&r%50===0?{triangleCount:r/50,declaredTriangleCount:t,trailingBytes:0}:null}function uy(e,n,t){let o=new DataView(e.buffer,e.byteOffset,e.byteLength),{triangleCount:r,declaredTriangleCount:i,trailingBytes:s}=n;i!==r&&t.push(`parseStl: binary STL declared ${i} triangles but contains ${r} complete triangle record${r===1?"":"s"}`),s>0&&t.push(`parseStl: ignored ${s} trailing binary byte${s===1?"":"s"}`);let a=oy(e.subarray(0,80)),c=ry(o),l=0,u=0,f=[];for(let d=0,m=84;d<r;d+=1,m+=50){let p=cr(o,m),g=[cr(o,m+12),cr(o,m+24),cr(o,m+36)];if(!g.every(lr))throw new Error(`parseStl: non-finite coordinate in binary triangle ${d}`);let h=o.getUint16(m+48,!0),y=c?iy(h,c):null;y&&(y.usesDefaultColor?u+=1:l+=1),f.push({normal:lr(p)?p:null,hasIgnoredNormal:!lr(p),color:y?.color,vertices:g,hasIgnoredAttribute:!c&&h!==0})}return{format:"binary",facets:f,binaryHeader:a,color:c?{format:"magics",defaultColor:c.defaultColor,alpha:c.alpha,coloredTriangleCount:l,defaultColorTriangleCount:u}:void 0}}function ru(e,n){let t=[],o=/^\s*facet\s+normal\s+([^\r\n]+)([\s\S]*?)^\s*endfacet\b[^\r\n]*$/gim,r=/^\s*vertex\s+([^\r\n]+)/gim,i=/^\s*facet\s+normal\b/gim,s=sy(e),a=0,c,l=0;for(;i.exec(e);)l+=1;let u=0,f=0,d=0,m;for(;m=o.exec(e);){for(u+=1;a<s.length&&s[a].index<m.index;){let b=s[a];c=b.kind==="start"?b.name:void 0,a+=1}let p=ou(m[1]);p||(d+=1);let g=[],h=!1;r.lastIndex=0;let y;for(;y=r.exec(m[2]);){let b=ou(y[1]);if(!b){h=!0;break}g.push(b)}if(h||g.length!==3){f+=1;continue}t.push({normal:p,hasIgnoredNormal:!p,solidName:c,vertices:[g[0],g[1],g[2]]})}return f+=Math.max(0,l-u),f>0&&n.push(`parseStl: skipped ${f} malformed ASCII facet${f===1?"":"s"}`),d>0&&n.push(`parseStl: ignored ${d} malformed ASCII facet normal${d===1?"":"s"}`),{format:"ascii",facets:t}}function Mt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function fr(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function xs(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function cu(e){return Math.hypot(e[0],e[1],e[2])}function fy(e){let n=fr(Mt(e[1],e[0]),Mt(e[2],e[0]));return cu(n)<=1e-8}function ur(e){let n=cu(e);return n<=1e-8?null:[e[0]/n,e[1]/n,e[2]/n]}function my(e){let n=t=>Object.is(t,-0)?0:t;return`${n(e[0])},${n(e[1])},${n(e[2])}`}function dy(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function Ps(e,n){return n?[e.vertices[0],e.vertices[2],e.vertices[1]]:e.vertices}function py(e,n,t){let o=0;for(let r of n.facets){let[i,s,a]=Ps(e[r],t[r]);o+=xs(i,fr(s,a))/6}return o}function gy(e,n,t){if(n.facets.length<8)return null;let o=0,r=0;for(let s of n.facets){let a=e[s],c=a.normal?ur(a.normal):null;if(!c)continue;let l=Ps(a,t[s]),u=ur(fr(Mt(l[1],l[0]),Mt(l[2],l[0])));if(!u)continue;let f=xs(u,c);f>=.95?o+=1:f<=-.95&&(r+=1)}let i=o+r;return i/n.facets.length<.75?null:r/i>=.9?"opposed":o/i>=.9?"aligned":null}function hy(e){let n=new Map,t=e.map(()=>[]);for(let u=0;u<e.length;u+=1){let f=e[u].vertices.map(my);for(let d=0;d<3;d+=1){let m=f[d],p=f[(d+1)%3],g=dy(m,p),h=n.get(g),y={facetIndex:u,from:m,to:p};h?h.push(y):n.set(g,[y])}}let o=0;for(let u of n.values()){if(u.length>2&&(o+=1),u.length<2)continue;let[f,...d]=u;for(let m of d){let p=f.from===m.from&&f.to===m.to;t[f.facetIndex].push({to:m.facetIndex,flipDiffers:p}),t[m.facetIndex].push({to:f.facetIndex,flipDiffers:p})}}let r=new Array(e.length).fill(!1),i=new Array(e.length).fill(-1),s=[],a=0;for(let u=0;u<e.length;u+=1){if(i[u]>=0)continue;let f=s.length,d={facets:[],conflicts:0,boundaryEdges:0,nonManifoldEdges:0,flippedOutward:!1,flippedToSuppliedNormals:!1};s.push(d),i[u]=f;let m=[u];for(let p=0;p<m.length;p+=1){let g=m[p];d.facets.push(g);for(let h of t[g]){let y=r[g]!==h.flipDiffers;i[h.to]<0?(i[h.to]=f,r[h.to]=y,m.push(h.to)):r[h.to]!==y&&g<h.to&&(d.conflicts+=1,a+=1)}}}for(let u of n.values()){let f=s[i[u[0].facetIndex]];u.length===1?f.boundaryEdges+=1:u.length>2&&(f.nonManifoldEdges+=1)}for(let u of s){if(u.nonManifoldEdges>0||u.conflicts>0){for(let d of u.facets)r[d]=!1;continue}if(u.boundaryEdges>0){if(gy(e,u,r)==="opposed"){for(let d of u.facets)r[d]=!r[d];u.flippedToSuppliedNormals=!0}continue}if(py(e,u,r)<-1e-10){for(let d of u.facets)r[d]=!r[d];u.flippedOutward=!0}}let c=0;return{facets:e.map((u,f)=>r[f]?(c+=1,{...u,vertices:Ps(u,!0)}):u),repairedCount:c,componentCount:s.length,outwardComponentCount:s.filter(u=>u.flippedOutward).length,suppliedNormalComponentCount:s.filter(u=>u.flippedToSuppliedNormals).length,conflictCount:a,nonManifoldEdgeCount:o}}function yy(e,n,t,o,r){let i=s=>Math.round(s*1e3)/1e3;return r==="y"?[i((e[2]-n[2])*t+o),i((e[0]-n[0])*t+o),i((e[1]-n[1])*t+o)]:[i((e[0]-n[0])*t+o),i((e[1]-n[1])*t+o),i((e[2]-n[2])*t+o)]}function by(e){if(e.every(r=>r.solidName===void 0))return;let n=[],t=e[0]?.solidName??"",o=0;for(let r=1;r<=e.length;r+=1){let i=e[r]?.solidName??"";r<e.length&&i===t||(n.push({name:t,start:o,count:r-o}),t=i,o=r)}return n}function xy(e){if(!e)return;let n=[],t=new Set;for(let o of e)!o.name||t.has(o.name)||(t.add(o.name),n.push(o.name));return n.length>0?n:void 0}function Ms(e,n){let t=Jh("targetSize",n?.targetSize,60),o=iu("gridShift",n?.gridShift,1),r=ny(n?.defaultColor),i=ey(n?.upAxis),s=[],a=ty(e),c=typeof e=="string"?e.length:a.byteLength;if(c===0||typeof e=="string"&&e.trim().length===0)throw new Error("parseStl: empty input");let l=a?ly(a):null,u=typeof e=="string"?ru(e,s):l?uy(a,l,s):ru(su(a),s),f=0,d=0,m=0,p=[];for(let A of u.facets){if(A.hasIgnoredAttribute&&(f+=1),A.hasIgnoredNormal&&u.format==="binary"&&(d+=1),fy(A.vertices)){m+=1;continue}p.push(A)}let g=hy(p),h=0;for(let A of g.facets){let S=ur(fr(Mt(A.vertices[1],A.vertices[0]),Mt(A.vertices[2],A.vertices[0]))),T=A.normal?ur(A.normal):null;S&&T&&xs(S,T)<.95&&(h+=1)}if(f>0&&s.push(`parseStl: ignored non-zero binary attribute byte count on ${f} triangle${f===1?"":"s"}`),d>0&&s.push(`parseStl: ignored ${d} non-finite binary normal${d===1?"":"s"}`),m>0&&s.push(`parseStl: skipped ${m} degenerate triangle${m===1?"":"s"}`),g.repairedCount>0&&s.push(`parseStl: repaired winding on ${g.repairedCount} triangle${g.repairedCount===1?"":"s"}`),g.outwardComponentCount>0&&s.push(`parseStl: oriented ${g.outwardComponentCount} closed component${g.outwardComponentCount===1?"":"s"} outward`),g.suppliedNormalComponentCount>0&&s.push(`parseStl: oriented ${g.suppliedNormalComponentCount} open component${g.suppliedNormalComponentCount===1?"":"s"} from supplied normals`),g.conflictCount>0&&s.push(`parseStl: found ${g.conflictCount} inconsistent shared-edge winding constraint${g.conflictCount===1?"":"s"}`),g.nonManifoldEdgeCount>0&&s.push(`parseStl: found ${g.nonManifoldEdgeCount} non-manifold shared edge${g.nonManifoldEdgeCount===1?"":"s"}`),h>0&&s.push(`parseStl: ${h} supplied normal${h===1?" disagrees":"s disagree"} with triangle winding`),p.length===0)throw u.facets.length===0?new Error(`parseStl: no valid ${u.format} facets`):new Error("parseStl: no valid facets after filtering");let y=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0];for(let A of g.facets)for(let S of A.vertices)for(let T=0;T<3;T+=1)S[T]<y[T]&&(y[T]=S[T]),S[T]>b[T]&&(b[T]=S[T]);let x=Math.max(b[0]-y[0],b[1]-y[1],b[2]-y[2]),P=x>0?t/x:1,M=by(g.facets),C=xy(M),E=g.facets.map(A=>({vertices:A.vertices.map(S=>yy(S,y,P,o,i)),color:A.color??r}));return{polygons:E,objectUrls:[],dispose:()=>{},warnings:s,metadata:{triangleCount:E.length,meshes:C,materials:[],sourceBytes:c,stlHeader:u.binaryHeader,stlColor:u.color,stlSolids:M,stlTopology:{componentCount:g.componentCount,repairedTriangleCount:g.repairedCount,outwardComponentCount:g.outwardComponentCount,suppliedNormalComponentCount:g.suppliedNormalComponentCount,inconsistentSharedEdgeCount:g.conflictCount,nonManifoldSharedEdgeCount:g.nonManifoldEdgeCount}}}}var Dn="loadMesh";async function lu(e,n){let t=n?.solidTextureSamples;return t===!1?e:us(e,typeof t=="object"?t:void 0)}function Py(e){let n=e.split("?")[0].split("#")[0],t=n.lastIndexOf(".");return t<0?"":n.slice(t+1).toLowerCase()}async function My(e,n){let t=Py(e);if(t==="mtl")throw new Error(`${Dn}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let o=globalThis.fetch;if(!o)throw new Error(`${Dn}: no fetch() in this environment`);let r=n?.baseUrl??e;if(t==="obj"){let i=await o(e);if(!i.ok)throw new Error(`${Dn}: ${e} \u2192 ${i.status}`);let s=await i.text(),a=n?.objOptions;if(n?.mtlUrl){let u=await o(n.mtlUrl);if(!u.ok)throw new Error(`${Dn}: ${n.mtlUrl} \u2192 ${u.status}`);let f=await u.text(),{colors:d,textures:m}=ps(f),p={},g=globalThis.URL,h=globalThis.document?.baseURI,y=n.mtlUrl;if(g&&h)try{y=new g(n.mtlUrl,h).toString()}catch{}for(let[b,x]of Object.entries(m)){if(g)try{p[b]=new g(x,y).toString();continue}catch{}let P=n.mtlUrl.lastIndexOf("/"),M=P>=0?n.mtlUrl.slice(0,P+1):"";p[b]=x.startsWith("/")||/^https?:\/\//.test(x)?x:M+x}a={...a??{},materialColors:{...d,...a?.materialColors??{}},materialTextures:{...p,...a?.materialTextures??{}}}}let c=ms(s,a),l=await lu(c,n);return ut(l,{meshResolution:n?.meshResolution,source:c})}if(t==="glb"||t==="gltf"){let i=await o(e);if(!i.ok)throw new Error(`${Dn}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer(),a=as(s,{baseUrl:r,...n?.gltfOptions??{}}),c=await lu(a,n);return ut(c,{meshResolution:n?.meshResolution,source:a})}if(t==="vox"){let i=await o(e);if(!i.ok)throw new Error(`${Dn}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer();return ut(hs(s,n?.voxOptions),{meshResolution:n?.meshResolution})}if(t==="stl"){let i=await o(e);if(!i.ok)throw new Error(`${Dn}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer();return ut(Ms(s,n?.stlOptions),{meshResolution:n?.meshResolution})}throw new Error(`${Dn}: unsupported extension ".${t}" (supported: obj, glb, gltf, vox, stl)`)}function Ue(e,n){if(Object.is(e,0)||Object.is(e,-0))return"0";if(e===1)return"1";if(e===-1)return"-1";let t=Ui[n]??10**n,o=Math.round(e*t)/t;return Object.is(o,0)||Object.is(o,-0)?"0":String(o)}function Sy(e,n=Ko){let t=Ue(e,n);return t==="0"?"0":`${t}px`}function pn(e,n=En){if(e.length===0)return"";let t=Ue(e[0],n);for(let o=1;o<e.length;o++)t+=`,${Ue(e[o],n)}`;return t}function Ay(e,n,t,o,r=En){return Ss(e[0],e[1],e[2],n[0],n[1],n[2],t[0],t[1],t[2],o[0],o[1],o[2],r)}function Ss(e,n,t,o,r,i,s,a,c,l,u,f,d=En){if(d===3){let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,g=Math.round(t*1e3)/1e3||0,h=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(i*1e3)/1e3||0,x=Math.round(s*1e3)/1e3||0,P=Math.round(a*1e3)/1e3||0,M=Math.round(c*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,E=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`${m},${p},${g},0,${h},${y},${b},0,${x},${P},${M},0,${C},${E},${A},1`}return`${Ue(e,d)},${Ue(n,d)},${Ue(t,d)},0,${Ue(o,d)},${Ue(r,d)},${Ue(i,d)},0,${Ue(s,d)},${Ue(a,d)},${Ue(c,d)},0,${Ue(l,d)},${Ue(u,d)},${Ue(f,d)},1`}function As(e,n,t,o,r,i,s,a,c,l,u,f,d=En){if(d!==3)return`matrix3d(${Ss(e,n,t,o,r,i,s,a,c,l,u,f,d)})`;let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,g=Math.round(t*1e3)/1e3||0,h=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(i*1e3)/1e3||0,x=Math.round(s*1e3)/1e3||0,P=Math.round(a*1e3)/1e3||0,M=Math.round(c*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,E=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`matrix3d(${m},${p},${g},0,${h},${y},${b},0,${x},${P},${M},0,${C},${E},${A},1)`}function to(e,n,t,o=0,r=0){let i=e.matrix.split(",").map(d=>Number(d));if(i.length!==16||i.some(d=>!Number.isFinite(d)))return e.matrix;let s=i[0],a=i[1],c=i[2],l=i[4],u=i[5],f=i[6];return i[0]*=n,i[1]*=n,i[2]*=n,i[4]*=t,i[5]*=t,i[6]*=t,i[12]+=o*s+r*l,i[13]+=o*a+r*u,i[14]+=o*c+r*f,pn(i)}function Cy(e,n){return to(e,n.width/In,n.height/In,n.minX,n.minY)}function uu(e){let n=e.seamBleedInsets??{left:0,right:0,top:0,bottom:0},t=e.canvasW||1,o=e.canvasH||1;return to(e,(t+n.left+n.right)/vn,(o+n.top+n.bottom)/vn,-n.left,-n.top)}function oo(e,n,t=n){let o=e.matrix.split(",").map(r=>Number(r));return o.length!==16||o.some(r=>!Number.isFinite(r))?e.canonicalMatrix:(o[0]*=e.canvasW/n,o[1]*=e.canvasW/n,o[2]*=e.canvasW/n,o[4]*=e.canvasH/t,o[5]*=e.canvasH/t,o[6]*=e.canvasH/t,pn(o))}function Fn(e,n=zi){let t=Ue(e,n);return Number(t)===0?"0":`${t}%`}function Ty(e,n=En){return`matrix3d(${e.split(",").map(t=>{let o=Number(t.trim());return Number.isFinite(o)?Ue(o,n):t.trim()}).join(",")})`}function Ey(e,n=Ko){let t=Ue(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function vy(e){return`matrix3d(${uu(e)})`}function gn(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function Zn(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let s=1;s+1<e.length;s++){let a=e[s],c=e[s+1],l=[a[0]-n[0],a[1]-n[1],a[2]-n[2]],u=[c[0]-n[0],c[1]-n[1],c[2]-n[2]];t-=l[1]*u[2]-l[2]*u[1],o-=l[2]*u[0]-l[0]*u[2],r-=l[0]*u[1]-l[1]*u[0]}let i=Math.hypot(t,o,r);return i<=ge?null:(t/=i,o/=i,r/=i,[t,o,r])}function ro(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=ge)return!1;let a=Math.sign(s);if(n===0)n=a;else if(a!==n)return!1}return!0}function Cs(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function Ts(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=r*a-i*s;if(Math.abs(c)<=ge)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*s)/c;return[e[0]+f*r,e[1]+f*i]}function Iy(e,n,t,o,r,i,s,a){let c=t-e,l=o-n,u=s-r,f=a-i,d=c*f-l*u;if(Math.abs(d)<=ge)return null;let m=r-e,p=i-n,g=(m*f-p*u)/d;return[e+g*c,n+g*l]}function St(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let s=0;s<e.length;s+=2)t+=e[s],o+=e[s+1];t/=r,o/=r;let i=e.slice();for(let s=0;s<i.length;s+=2){let a=i[s]-t,c=i[s+1]-o,l=Math.hypot(a,c);l<=Te||(i[s]+=a/l*n,i[s+1]+=c/l*n)}return i}function At(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let c=0;c<e.length;c+=2)t.push([e[c],e[c+1]]);if(!ro(t))return St(e,n);let o=Cs(t);if(Math.abs(o)<=ge)return St(e,n);let r=o>0?1:-1,i=[];for(let c=0;c<t.length;c++){let l=t[c],u=t[(c+1)%t.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=ge)return St(e,n);let p=r*(d/m)*n,g=r*(-f/m)*n;i.push({a:[l[0]+p,l[1]+g],b:[u[0]+p,u[1]+g]})}let s=[],a=Math.max(2,n*4);for(let c=0;c<t.length;c++){let l=i[(c+t.length-1)%t.length],u=i[c],f=Ts(l.a,l.b,u.a,u.b);if(!f)return St(e,n);let d=t[c],m=f[0]-d[0],p=f[1]-d[1],g=Math.hypot(m,p);g>a?s.push(d[0]+m/g*a,d[1]+p/g*a):s.push(f[0],f[1])}return s}function io(e,n){if(e.length<6||e.length%2!==0)return e;let t=e.length/2;if(n.length!==t)return e;let o=n.map(f=>typeof f=="number"&&Number.isFinite(f)?Math.max(0,f):0),r=Math.max(0,...o);if(r<=0)return e;if(o.every(f=>Math.abs(f-o[0])<=ge))return At(e,o[0]);let i=[];for(let f=0;f<e.length;f+=2)i.push([e[f],e[f+1]]);if(!ro(i))return e;let s=Cs(i);if(Math.abs(s)<=ge)return e;let a=s>0?1:-1,c=[];for(let f=0;f<i.length;f++){let d=i[f],m=i[(f+1)%i.length],p=m[0]-d[0],g=m[1]-d[1],h=Math.hypot(p,g);if(h<=ge)return e;let y=o[f],b=a*(g/h)*y,x=a*(-p/h)*y;c.push({a:[d[0]+b,d[1]+x],b:[m[0]+b,m[1]+x]})}let l=[],u=Math.max(2,r*4);for(let f=0;f<i.length;f++){let d=c[(f+i.length-1)%i.length],m=c[f],p=Ts(d.a,d.b,m.a,m.b);if(!p)return e;let g=i[f],h=p[0]-g[0],y=p[1]-g[1],b=Math.hypot(h,y);b>u?l.push(g[0]+h/b*u,g[1]+y/b*u):l.push(p[0],p[1])}return l}function mr(e,n,t,o,r,i,s){if(s<=0)return[e,n,t,o,r,i];let a=(e*o-n*t+t*i-o*r+r*n-i*e)/2,c=()=>St([e,n,t,o,r,i],s);if(Math.abs(a)<=ge)return c();let l=a>0?1:-1,u=t-e,f=o-n,d=Math.sqrt(u*u+f*f),m=r-t,p=i-o,g=Math.sqrt(m*m+p*p),h=e-r,y=n-i,b=Math.sqrt(h*h+y*y);if(d<=ge||g<=ge||b<=ge)return c();let x=l*(f/d)*s,P=l*(-u/d)*s,M=e+x,C=n+P,E=t+x,A=o+P,S=l*(p/g)*s,T=l*(-m/g)*s,v=t+S,R=o+T,O=r+S,L=i+T,D=l*(y/b)*s,_=l*(-h/b)*s,w=r+D,V=i+_,j=e+D,G=n+_,Z=j-w,ee=G-V,W=E-M,ie=A-C,z=Z*ie-ee*W;if(Math.abs(z)<=ge)return c();let X=M-w,U=C-V,I=(X*ie-U*W)/z,B=w+I*Z,N=V+I*ee,H=E-M,$=A-C,k=O-v,Q=L-R,ae=H*Q-$*k;if(Math.abs(ae)<=ge)return c();let se=v-M,Y=R-C,ne=(se*Q-Y*k)/ae,le=M+ne*H,ye=C+ne*$,Ae=O-v,_e=L-R,Ee=j-w,Me=G-V,Re=Ae*Me-_e*Ee;if(Math.abs(Re)<=ge)return c();let F=w-v,q=V-R,J=(F*Me-q*Ee)/Re,te=v+J*Ae,ue=R+J*_e,ce=Math.max(2,s*4),he=B-e,Se=N-n,ve=Math.sqrt(he*he+Se*Se);ve>ce&&(B=e+he/ve*ce,N=n+Se/ve*ce);let xe=le-t,K=ye-o,oe=Math.sqrt(xe*xe+K*K);oe>ce&&(le=t+xe/oe*ce,ye=o+K/oe*ce);let de=te-r,qe=ue-i,Ye=Math.sqrt(de*de+qe*qe);return Ye>ce&&(te=r+de/Ye*ce,ue=i+qe/Ye*ce),[B,N,le,ye,te,ue]}function Es(e,n,t,o){let r=e+n;if(o<=0||t<=ge||r<=ge||!Number.isFinite(e+n+t+o))return mr(e,0,0,t,r,t,o);let i=Math.sqrt(e*e+t*t),s=Math.sqrt(n*n+t*t);if(i<=ge||s<=ge)return mr(e,0,0,t,r,t,o);let a=-o*t/i,c=-o*e/i,l=o*t/s,u=-o*n/s,f=e+a,d=c,m=r+l,p=t+u,g=-t*r;if(Math.abs(g)<=ge)return mr(e,0,0,t,r,t,o);let h=f-m,y=d-p,b=(h*t+y*e)/g,x=m-b*n,P=p-b*t,M=-o*(e+i)/t,C=t+o,E=r+o*(n+s)/t,A=C,S=Math.max(2,o*4),T=x-e,v=P,R=Math.sqrt(T*T+v*v);R>S&&(x=e+T/R*S,P=v/R*S);let O=Math.sqrt(M*M+o*o);O>S&&(M=M/O*S,C=t+o/O*S);let L=E-r,D=Math.sqrt(L*L+o*o);return D>S&&(E=r+L/D*S,A=t+o/D*S),[x,P,M,C,E,A]}function dr(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=gn(n.vertices,t,o),i=Zn(r);if(!i)return null;let s=e.screenPts[0],a=e.screenPts[1],c=e.screenPts[2],l=e.screenPts[3],u=e.screenPts[4],f=e.screenPts[5],d=c-s,m=l-a,p=u-s,g=f-a,h=d*g-m*p;if(Math.abs(h)<=ge)return null;let y=r[0],b=r[1],x=r[2],P=[b[0]-y[0],b[1]-y[1],b[2]-y[2]],M=[x[0]-y[0],x[1]-y[1],x[2]-y[2]],C=[(P[0]*g-m*M[0])/h,(P[1]*g-m*M[1])/h,(P[2]*g-m*M[2])/h],E=[(d*M[0]-P[0]*p)/h,(d*M[1]-P[1]*p)/h,(d*M[2]-P[2]*p)/h],A=y[0]-C[0]*s-E[0]*a,S=y[1]-C[1]*s-E[1]*a,T=y[2]-C[2]*s-E[2]*a;return{normal:i,xAxis:C,yAxis:E,tx:A,ty:S,tz:T}}function vs(e){return Math.max(0,Math.min(6,Math.floor(e??En)))}function fu(e){return`${e[0]},${e[1]},${e[2]}`}function mu(e,n){let t=fu(e),o=fu(n);return t<o?`${t}|${o}`:`${o}|${t}`}function _y(e){let n=new Map;for(let o=0;o<e.length;o++){let r=e[o].vertices;if(!(!r||r.length<3||!e[o].texture))for(let i=0;i<r.length;i++){let s=mu(r[i],r[(i+1)%r.length]),a=n.get(s),c={polygon:o,edge:i};a?a.push(c):n.set(s,[c])}}let t=e.map(()=>new Set);for(let o of n.values())if(!(o.length<2))for(let r=0;r<o.length;r++)for(let i=r+1;i<o.length;i++)t[o[r].polygon].add(o[r].edge),t[o[i].polygon].add(o[i].edge);return t.map(o=>o.size>0?o:void 0)}function pr(e,n){return typeof e=="number"&&Number.isFinite(e)?Math.max(0,e):n}function Is(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function gr(e,n,t){if(t<=0||e.length<6||e.length%2!==0)return 0;let o=e.length/2;if(n<0||n>=o)return 0;let r=[];for(let A=0;A<e.length;A+=2)r.push([e[A],e[A+1]]);let[i,s]=r[n],[a,c]=r[(n+1)%o],l=a-i,u=c-s,f=Math.hypot(l,u);if(f<=Te)return 0;let d=[],m=Number.POSITIVE_INFINITY;for(let A=0;A<o;A+=1){if(A===n||A===(n+1)%o)continue;let[S,T]=r[A],v=Math.abs((S-i)*u-(T-s)*l)/f;v>Te&&(m=Math.min(m,v))}Number.isFinite(m)&&d.push(m*.5);let p=r[(n+o-1)%o],g=r[(n+2)%o],h=p[0]-i,y=p[1]-s,b=g[0]-a,x=g[1]-c,P=Math.hypot(h,y),M=Math.hypot(b,x);if(P>Te){let A=Math.abs(l*y-u*h)/(f*P);A>Te&&d.push(P*A)}if(M>Te){let A=Math.abs(-l*x- -u*b)/(f*M);A>Te&&d.push(M*A)}let C=d.filter(A=>Number.isFinite(A)&&A>0);if(C.length===0)return Number.isFinite(t)?Math.max(0,t):0;let E=Math.min(...C);return Math.max(0,Math.min(Number.isFinite(t)?t:E,E))}function _s(e,n,t){if(!n?.size||t===void 0)return;let o=new Map;for(let r of n){let i=gr(e,r,t);i>0&&o.set(r,i)}return o.size>0?o:void 0}function Vs(e,n){return e<3||!n?.size?null:Array.from({length:e},(t,o)=>Math.max(0,n.get(o)??0))}function Os(e,n){if(!n?.size||e.length<6||e.length%2!==0)return;let t=e.length/2,o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(let l=0;l<e.length;l+=2){let u=e[l],f=e[l+1];o=Math.min(o,u),r=Math.min(r,f),i=Math.max(i,u),s=Math.max(s,f)}if(!Number.isFinite(o+r+i+s))return;let a=Math.max(Te*8,.25),c={left:0,right:0,top:0,bottom:0};for(let[l,u]of n){let f=Math.max(0,u);if(f<=0||l<0||l>=t)continue;let d=l*2,m=(l+1)%t*2,p=e[d],g=e[d+1],h=e[m],y=e[m+1];Math.abs(p-h)<=a?Math.abs(p-o)<=a&&Math.abs(h-o)<=a?c.left=Math.max(c.left,f):Math.abs(p-i)<=a&&Math.abs(h-i)<=a&&(c.right=Math.max(c.right,f)):Math.abs(g-y)<=a&&(Math.abs(g-r)<=a&&Math.abs(y-r)<=a?c.top=Math.max(c.top,f):Math.abs(g-s)<=a&&Math.abs(y-s)<=a&&(c.bottom=Math.max(c.bottom,f)))}return c.left||c.right||c.top||c.bottom?c:void 0}function Vy(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Oy(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=gn(e.vertices,n,t),r=Zn(o);return r?{normal:r,planeD:Vy(r,o[0])}:null}function Ry(e,n){return(e.material?.key??e.color??"")===(n.material?.key??n.color??"")&&e.color===n.color}function Ly(e,n={}){return new Set(du(e,n).keys())}function du(e,n={}){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(c=>Oy(c,t,o)),i=new Map;for(let c=0;c<e.length;c++){let l=e[c].vertices;if(!(!l||l.length<3))for(let u=0;u<l.length;u++){let f=mu(l[u],l[(u+1)%l.length]),d=i.get(f),m={polygon:c,edge:u};d?d.push(m):i.set(f,[m])}}let s=new Map,a=(c,l)=>{let u=s.get(c);u?u.add(l):s.set(c,new Set([l]))};for(let c of i.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l],d=c[u],m=f.polygon,p=d.polygon;!r[m]||!r[p]||Ry(e[m],e[p])&&(a(m,f.edge),a(p,d.edge))}return s}function wy(e,n,t,o,r,i){let s=(e-t)*(i-o)-(n-o)*(r-t);return Math.abs(s)>qo?!1:(e-t)*(e-r)+(n-o)*(n-i)<=qo}function pu(e,n=Zo,t=Zo){let o=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){let[s,a]=e[r],[c,l]=e[i];if(wy(n,t,s,a,c,l))return!0;a>t!=l>t&&n<(c-s)*(t-a)/(l-a)+s&&(o=!o)}return o}function gu(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(let l=0;l<e.length;l+=2){let u=e[l],f=e[l+1];!Number.isFinite(u)||!Number.isFinite(f)||(o=Math.min(o,u),r=Math.min(r,f),i=Math.max(i,u),s=Math.max(s,f))}let a=i-o,c=s-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(a)||!Number.isFinite(c)||a<=ge||c<=ge?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:a,height:c}}function so(e){let n=e.bleedRatio??1,t=Yi*n,o=e.canvasW||1,r=e.canvasH||1,i=t>0?At(e.screenPts,t):e.screenPts,s=t>0?gu(i,o,r):{minX:0,minY:0,width:o,height:r},a=[];for(let c=0;c<i.length;c+=2){let l=Math.max(0,Math.min(100,(i[c]-s.minX)/s.width*100)),u=Math.max(0,Math.min(100,(i[c+1]-s.minY)/s.height*100));a.push([l,u])}return{bounds:s,points:a}}function hu(e){let n=[];for(let t of e){let o=n[n.length-1];o&&Math.hypot(o[0]-t[0],o[1]-t[1])<=Qo||n.push(t)}if(n.length>1){let t=n[0],o=n[n.length-1];Math.hypot(t[0]-o[0],t[1]-o[1])<=Qo&&n.pop()}return n}function yu([e,n]){let t=new Set;return Math.abs(e)<=on&&t.add("left"),Math.abs(e-100)<=on&&t.add("right"),Math.abs(n)<=on&&t.add("top"),Math.abs(n-100)<=on&&t.add("bottom"),t.size>0?t:null}function bu(e,n){for(let t of e)if(n.has(t))return!0;return!1}function xu(e,n,t,o){let r=(i,s,a)=>{let c=n.has(s)?e:o.has(s)?t:null,l=n.has(a)?e:o.has(a)?t:null;if(!c||!l)return null;let u=(()=>{switch(i){case"topLeft":return{x:c[0],y:l[1]};case"topRight":return{x:100-c[0],y:l[1]};case"bottomRight":return{x:100-c[0],y:100-l[1]};case"bottomLeft":return{x:c[0],y:100-l[1]}}})();return u.x>on&&u.y>on&&u.x<100-on&&u.y<100-on?[i,u]:null};return(n.has("top")||o.has("top"))&&(n.has("left")||o.has("left"))?r("topLeft","top","left"):(n.has("top")||o.has("top"))&&(n.has("right")||o.has("right"))?r("topRight","top","right"):(n.has("bottom")||o.has("bottom"))&&(n.has("right")||o.has("right"))?r("bottomRight","bottom","right"):(n.has("bottom")||o.has("bottom"))&&(n.has("left")||o.has("left"))?r("bottomLeft","bottom","left"):null}function Rs(e){if(e.texture||Ct(e)||qn(e))return null;let n=so(e),t=hu(n.points);if(t.length<4)return null;let o=t.map(yu);if(o.some(s=>!s))return null;let r={},i=0;for(let s=0;s<t.length;s+=1){let a=o[s],c=o[(s+1)%t.length];if(bu(a,c))continue;let l=xu(t[s],a,t[(s+1)%t.length],c);if(!l)return null;let[u,f]=l,d=r[u];if(d&&(Math.abs(d.x-f.x)>on||Math.abs(d.y-f.y)>on))return null;r[u]=f,i+=1}return i>0?{bounds:n.bounds,radii:r}:null}function Ny([e,n]){return`${Fn(e)} ${Fn(n)}`}function Dy(e){return`polygon(${e.map(Ny).join(",")})`}function Fy(e){if(pu(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[s,a]of e)n+=s,t+=a;let r=Fn(Math.max(0,Math.min(100,n/o))),i=Fn(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${i})`}function Ls(e){return`${Dy(e)} ${Fy(e)}`}function By(e){return Ls(so(e).points)}function ws(e,n){return to(e,n.width/In,n.height/In,n.minX,n.minY)}function ky(e){let n=so(e);return`matrix3d(${ws(e,n.bounds)})`}function zy(e){let n=so(e);return[`transform:matrix3d(${ws(e,n.bounds)})`,`border-shape:${Ls(n.points)}`].join(";")}function Uy(e,n){let t=[`transform:matrix3d(${ws(e,n.bounds)})`,`width:${In}px`,`height:${In}px`,"border:0","box-sizing:border-box","background:currentColor"];for(let[o,r]of Object.entries(n.radii)){let i=o.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);t.push(`border-${i}-radius:${Fn(r.x)} ${Fn(r.y)}`),t.push(`corner-${i}-shape:bevel`)}return t.join(";")}function hr(e){return e.textureImageSource??e.material?.imageSource}function Ns(e){return e.material?.texture??e.texture??e.textureImageSource?.url??e.material?.imageSource?.url}function yr(e,n={}){let t=hr(e);return{...n,...e.material?.presentation,...t?.imageRendering?{imageRendering:t.imageRendering}:null,...e.texturePresentation}}function Gy(e,n){return yr(e,{imageRendering:n}).imageRendering??"auto"}function Pu(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function xr(e){let n=e?.maxWeightRatio,t=Math.max(0,Pu(e?.denomEps,ji)),o=typeof n=="number"&&Number.isFinite(n)&&n>0?Math.max(1,n):Wi,r=Math.max(0,Pu(e?.bleed,Hi));return{denomEps:t,maxWeightRatio:o,bleed:r,disableGuards:e?.disableGuards===!0}}function Ds(e,n){if(e.length!==4||!ro(e))return null;let[t,o,r,i]=e,s=t[0]-o[0]+r[0]-i[0],a=t[1]-o[1]+r[1]-i[1],c=o[0]-r[0],l=i[0]-r[0],u=o[1]-r[1],f=i[1]-r[1],d=c*f-u*l;if(Math.abs(d)<=ge)return null;let m=(s*f-a*l)/d,p=(c*a-u*s)/d,g=[1,1+m,1+m+p,1+p];if(g.some(b=>!Number.isFinite(b)))return null;let h=Math.min(...g),y=Math.max(...g);return!n.disableGuards&&(h<=n.denomEps||y/h>n.maxWeightRatio)?null:{g:m,h:p,w1:1+m,w3:1+p}}function Pr(e,n,t,o,r,i,s,a,c){if(e.length!==8)return null;let l=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!Ds(l,a))return null;let u=Vs(4,c),f=u?io(e,u):At(e,a.bleed),d=[[f[0],f[1]],[f[2],f[3]],[f[4],f[5]],[f[6],f[7]]],m=Ds(d,a);if(!m)return null;let{g:p,h:g,w1:h,w3:y}=m,[b,x,,P]=d,M=[r+b[0]*n[0]+b[1]*t[0],i+b[0]*n[1]+b[1]*t[1],s+b[0]*n[2]+b[1]*t[2]],C=([A,S],T)=>[(T-1)*r+(T*A-b[0])*n[0]+(T*S-b[1])*t[0],(T-1)*i+(T*A-b[0])*n[1]+(T*S-b[1])*t[1],(T-1)*s+(T*A-b[0])*n[2]+(T*S-b[1])*t[2]],E=[...C(x,h),p,...C(P,y),g,o[0],o[1],o[2],0,M[0],M[1],M[2],1];for(let A=0;A<8;A+=1)E[A]/=vn;return pn(E,6)}function Mr(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function $y(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Mu(e){return!e.texture}function Su(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=gn(e.vertices,n,t),r=Zn(o);return r?{pts:o,normal:r,planeD:Mr(r,o[0]),optimizable:Mu(e)}:null}function Au(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:ks(e,n)}function ks(e,n){return!e||!n||Mr(e.normal,n.normal)<1-Fi?!1:Math.abs(e.planeD-n.planeD)<=Bi}function Fs(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??ft,i=t?.color??mt,s=Math.max(0,t?.intensity??dt),a=o?.color??pt,c=Math.max(0,o?.intensity??gt),l=Math.hypot(r[0],r[1],r[2])||1,u=r[0]/l,f=r[1]/l,d=r[2]/l,m=s*Math.max(0,e.normal[0]*u+e.normal[1]*f+e.normal[2]*d),p=nr(m,i,a,c);return p.r*.2126+p.g*.7152+p.b*.0722}function zs(e,n,t,o,r){if(!e||e.length===0)return;let i=0,s=0,a=0;for(let u of n)i+=u[0],s+=u[1],a+=u[2];let c=1/n.length;i*=c,s*=c,a*=c;let l=[];for(let u of e){let f=u.position[1]*o,d=u.position[0]*o,m=u.position[2]*r,p=f-i,g=d-s,h=m-a,y=Math.hypot(p,g,h)||1;p/=y,g/=y,h/=y;let b=t[0]*p+t[1]*g+t[2]*h;b<=0||l.push({color:u.color??"#ffffff",scale:Math.max(0,u.intensity??1)*b})}return l.length?l:void 0}function Cu(e){let n=[...e],t=Math.abs(n[0])>ge?0:Math.abs(n[1])>ge?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function Tt(e,n,t,o,r={}){let i=Mr(o,t),s=[o[0]-i*t[0],o[1]-i*t[1],o[2]-i*t[2]],a=Math.hypot(s[0],s[1],s[2]);if(a<=ge)return null;let c=[s[0]/a,s[1]/a,s[2]/a],l=[t[1]*c[2]-t[2]*c[1],t[2]*c[0]-t[0]*c[2],t[0]*c[1]-t[1]*c[0]],u=Math.hypot(l[0],l[1],l[2]);if(u<=ge)return null;let f=[l[0]/u,l[1]/u,l[2]/u],d=e.map(D=>{let _=D[0]-n[0],w=D[1]-n[1],V=D[2]-n[2];return[_*c[0]+w*c[1]+V*c[2],_*f[0]+w*f[1]+V*f[2]]}),m=r.boundsOrigin??n,p=n[0]-m[0],g=n[1]-m[1],h=n[2]-m[2],y=p*c[0]+g*c[1]+h*c[2],b=p*f[0]+g*f[1]+h*f[2],x=1/0,P=1/0,M=-1/0,C=-1/0;for(let[D,_]of d){let w=D+y,V=_+b;w<x&&(x=w),w>M&&(M=w),V<P&&(P=V),V>C&&(C=V)}let E=M-x,A=C-P;if(!Number.isFinite(E)||!Number.isFinite(A))return null;let S=r.snapBounds?Math.floor(x+Te):x,T=r.snapBounds?Math.floor(P+Te):P,v=r.snapBounds?Math.ceil(M-Te):M,R=r.snapBounds?Math.ceil(C-Te):C,O=Math.max(1,r.snapBounds?v-S:Math.ceil(E)),L=Math.max(1,r.snapBounds?R-T:Math.ceil(A));return{xAxis:c,yAxis:f,local2D:d,shiftX:y-S,shiftY:b-T,canvasW:O,canvasH:L,pixelArea:O*L,rawArea:E*A}}function br(e){return`${e[0]},${e[1]},${e[2]}`}function Tu(e,n){return br(e)<br(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Xy(e,n){let t=br(e),o=br(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Eu(e,n,t,o){let r=0,i=0;for(let s of e){let a=n[s];if(!a)return null;let c=Tt(a.pts,a.pts[0],a.normal,t,{boundsOrigin:o,snapBounds:!0});if(!c)return null;r+=c.pixelArea,i+=c.rawArea}return{pixelArea:r,rawArea:i}}function vu(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,i=new Set;for(let s of e){let a=n[s];if(!a)continue;let c=[a.pts[1][0]-a.pts[0][0],a.pts[1][1]-a.pts[0][1],a.pts[1][2]-a.pts[0][2]],l=Tt(a.pts,a.pts[0],a.normal,c);o&&l?(o.pixelArea+=l.pixelArea,o.rawArea+=l.rawArea):o=null;for(let u=0;u<a.pts.length;u++){let f=Tu(a.pts[u],a.pts[(u+1)%a.pts.length]),d=Tt(a.pts,a.pts[0],a.normal,f);if(!d)continue;let m=Cu(d.xAxis);if(i.has(m))continue;i.add(m);let p=Eu(e,n,d.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-Te)&&(r={xAxis:d.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+Te)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function Yy(e,n){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(f=>Su(f,t,o)),i=new Map,s=e.map(()=>new Set),a=e.map(()=>new Set);for(let f=0;f<e.length;f++){let d=e[f].vertices;if(!(!d||d.length<3))for(let m=0;m<d.length;m++){let p=Xy(d[m],d[(m+1)%d.length]),g=i.get(p),h={polygon:f,edge:m};g?g.push(h):i.set(p,[h])}}let c=e.map(()=>new Set);for(let f of i.values())if(!(f.length<2))for(let d=0;d<f.length;d++)for(let m=d+1;m<f.length;m++){let p=f[d],g=f[m],h=p.polygon,y=g.polygon;if(e[h].texture&&e[y].texture&&(a[p.polygon].add(p.edge),a[g.polygon].add(g.edge)),ks(r[h],r[y]))s[p.polygon].add(p.edge),s[g.polygon].add(g.edge);else{let b=Fs(r[h],n),x=Fs(r[y],n);b!==null&&x!==null&&(b<=x+Ho&&s[p.polygon].add(p.edge),x<=b+Ho&&s[g.polygon].add(g.edge))}Au(r[h],r[y])&&(c[h].add(y),c[y].add(h))}let l=Array(e.length).fill(void 0),u=new Set;for(let f=0;f<e.length;f++){if(u.has(f)||!r[f]?.optimizable)continue;let d=[],m=[f];for(u.add(f);m.length>0;){let g=m.pop();d.push(g);for(let h of c[g])u.has(h)||(u.add(h),m.push(h))}if(d.length<2)continue;let p=vu(d,r);if(p)for(let g of d)l[g]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:s[g],textureEdgeRepairEdges:a[g]}}for(let f=0;f<e.length;f++)!l[f]&&(s[f].size>0||a[f].size>0)&&(l[f]={seamEdges:s[f],textureEdgeRepairEdges:a[f]});return l}function Bs(e,n,t,o){if(o.optimize&&o.fixedXAxis)return Tt(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,i=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,s=i??(o.optimize?e.map((a,c)=>c):[0]);for(let a of s){let c=(a+1)%e.length,l=i?Tu(e[a],e[c]):[e[c][0]-e[a][0],e[c][1]-e[a][1],e[c][2]-e[a][2]],u=Tt(e,n,t,l,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-Te)&&(r=u)}return r}function Iu(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,i)=>{for(let s of r)if(Math.abs(s-i)<=Te)return;r.push(i)};for(let[r,i]of e.local2D)o(n,r+e.shiftX),o(t,i+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,i)=>r-i),t.sort((r,i)=>r-i),Math.abs(n[0])>Te||Math.abs(t[0])>Te||n[1]-n[0]<=Te||t[1]-t[0]<=Te))return!1;for(let[r,i]of e.local2D){let s=r+e.shiftX,a=i+e.shiftY,c=Math.abs(s-n[0])<=Te||Math.abs(s-n[1])<=Te,l=Math.abs(a-t[0])<=Te||Math.abs(a-t[1])<=Te;if(!c||!l)return!1}return!0}function Us(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[i,s,a]=n,c=t[0],l=t[1],u=o[0],f=o[1],d=r[0],m=r[1],p=i[0],g=1-i[1],h=s[0],y=1-s[1],b=a[0],x=1-a[1],P=h-p,M=y-g,C=b-p,E=x-g,A=P*E-C*M;if(Math.abs(A)<=1e-9)return null;let S=u-c,T=d-c,v=f-l,R=m-l,O={a:(S*E-T*M)/A,b:(P*T-C*S)/A,c:(v*E-R*M)/A,d:(P*R-C*v)/A,e:0,f:0};return O.e=c-O.a*p-O.b*g,O.f=l-O.c*p-O.d*g,O}function Gs(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let i of e){let s=i[0],a=1-i[1];if(!Number.isFinite(s)||!Number.isFinite(a))return null;n=Math.min(n,s),o=Math.max(o,s),t=Math.min(t,a),r=Math.max(r,a)}return{minU:n,minV:t,maxU:o,maxV:r}}function _u(e,n,t,o,r,i,s,a){let l=gn(e.vertices,n,t).map(d=>{let m=d[0]-o[0],p=d[1]-o[1],g=d[2]-o[2];return[m*r[0]+p*r[1]+g*r[2]+s,m*i[0]+p*i[1]+g*i[2]+a]}),u=Us(l,e.uvs),f=Gs(e.uvs);return!u&&!f?null:{screenPts:l.flatMap(([d,m])=>[d,m]),uvAffine:u,uvSampleRect:f}}function Vu(e,n,t,o,r){let i=t,{vertices:s,uvs:a}=e,c=Ns(e);if(!s||s.length<3)return null;let l=t.tileSize??50,u=t.layerElevation??l,f=gn(s,l,u),d=f[0],m=f[1],p=[m[0]-d[0],m[1]-d[1],m[2]-d[2]];if(Math.hypot(p[0],p[1],p[2])===0)return null;let h=Zn(f);if(!h)return null;let y=Bs(f,d,h,{optimize:!1}),b=c||y&&Iu(y)?y:Bs(f,d,h,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:P,local2D:M}=b,C=c&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,E=!!(c&&C),A=b.shiftX,S=b.shiftY,T=b.canvasW,v=b.canvasH,R=[];for(let[Me,Re]of M)R.push(Me+A,Re+S);let O=d[0]-A*x[0]-S*P[0],L=d[1]-A*x[1]-S*P[1],D=d[2]-A*x[2]-S*P[2],_=pn([x[0],x[1],x[2],0,P[0],P[1],P[2],0,h[0],h[1],h[2],0,O,L,D,1]),w=pn([x[0]*T,x[1]*T,x[2]*T,0,P[0]*v,P[1]*v,P[2]*v,0,h[0],h[1],h[2],0,O,L,D,1]),V=pn([x[0]*T/tn,x[1]*T/tn,x[2]*T/tn,0,P[0]*v/tn,P[1]*v/tn,P[2]*v/tn,0,h[0],h[1],h[2],0,O,L,D,1]),j=Is(i.seamBleed),G=_s(R,i.seamEdges??r?.seamEdges,j),Z=G?new Set(G.keys()):void 0,ee=G?Math.max(...G.values()):void 0,W=Os(R,G),ie=!c&&s.length===4?Pr(R,x,P,h,O,L,D,o,G):null,z=t.directionalLight,X=t.ambientLight,U=z?.direction??ft,I=z?.color??mt,B=Math.max(0,z?.intensity??dt),N=X?.color??pt,H=Math.max(0,X?.intensity??gt),$=Math.hypot(U[0],U[1],U[2])||1,k=U[0]/$,Q=U[1]/$,ae=U[2]/$,Y=t.lightOccludedPolyIndices?.has(n)??!1?0:B*Math.max(0,h[0]*k+h[1]*Q+h[2]*ae),ne=zs(t.pointLights,f,h,l,u),le=nr(Y,I,N,H,ne),ye=wn(e.color??"#cccccc",Y,I,N,H,ne),Ae=null,_e=null;c&&a&&a.length>=3&&a.length===s.length&&(_e=Gs(a),Ae=Us(M.map(([Me,Re])=>[Me+A,Re+S]),a));let Ee=c&&e.textureTriangles?.length?e.textureTriangles.map(Me=>_u(Me,l,u,d,x,P,A,S)).filter(Me=>!!Me):null;return{index:n,polygon:e,texture:c,tileSize:l,layerElevation:u,matrix:_,canonicalMatrix:w,atlasMatrix:V,projectiveMatrix:ie,canvasW:T,canvasH:v,screenPts:R,uvAffine:Ae,uvSampleRect:_e,textureTriangles:Ee,textureEdgeRepairEdges:C,textureEdgeRepair:E,seamBleed:ee,seamBleedEdges:Z,seamBleedEdgeAmounts:G,seamBleedInsets:W,bleedRatio:Ki(i.seamBleed),normal:h,textureTint:le,shadedColor:ye}}function jy(e,n,t={},o,r){let i=xr(o),s=t,a=r??(t.textureEdgeRepairEdges?.size?{seamEdges:new Set,textureEdgeRepairEdges:t.textureEdgeRepairEdges}:void 0);return Vu(e,n,s,i,a)}function Sr(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function Wy(e){return!!e&&typeof e.url=="string"&&e.url.length>0&&Sr(e.width)&&Sr(e.height)}function Hy(e){let n=e.sourceRect;return n?!Number.isFinite(n.x)||!Number.isFinite(n.y)||!Sr(n.width)||!Sr(n.height)?null:{x:n.x,y:n.y,width:n.width,height:n.height}:{x:0,y:0,width:e.width,height:e.height}}function Ky(e,n,t){let o=e.split(",").map(Number);if(o.length!==16||o.some(s=>!Number.isFinite(s)))return null;let r=vn/n,i=vn/t;for(let s=0;s<4;s+=1)o[s]*=r;for(let s=4;s<8;s+=1)o[s]*=i;return pn(o,6)}function $s(e,n={}){let t=hr(e.polygon);if(!Wy(t))return null;let o=yr(e.polygon,{imageRendering:n.imageRendering,backend:n.backend,lighting:n.lighting,projection:n.projection});if(o.backend!=="image")return null;let r=o.lighting??"source";if(r!=="source")return null;let i=Hy(t);if(!i)return null;let s=Math.max(1,i.width),a=Math.max(1,i.height),c=o.projection??"affine",l=c,u=null;if(c==="projective"){if(n.allowProjective===!1||e.screenPts.length!==8||e.polygon.vertices.length!==4)return null;let f=n.projectiveQuadGuards??xr(void 0),d=dr(e,e.polygon);if(!d)return null;let m=Pr(e.screenPts,d.xAxis,d.yAxis,d.normal,d.tx,d.ty,d.tz,f,e.seamBleedEdgeAmounts);if(u=m?Ky(m,s,a):null,!u)return null}else l="affine",u=oo(e,s,a);return{source:t,url:t.url,sourceRect:i,leafWidth:s,leafHeight:a,matrix:u,backgroundPosition:[-i.x,-i.y],backgroundSize:[t.width,t.height],imageRendering:o.imageRendering??"auto",lighting:r,projection:l}}function Ou(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=.001,r=(i,s)=>{for(let a of i)if(Math.abs(a-s)<=o)return;i.push(s)};for(let i=0;i<e.screenPts.length;i+=2)r(n,e.screenPts[i]),r(t,e.screenPts[i+1]);if(n.length!==2||t.length!==2||(n.sort((i,s)=>i-s),t.sort((i,s)=>i-s),Math.abs(n[0])>o||Math.abs(t[0])>o||n[1]-n[0]<=o||t[1]-t[0]<=o))return null;for(let i=0;i<e.screenPts.length;i+=2){let s=e.screenPts[i],a=e.screenPts[i+1],c=Math.abs(s-n[0])<=o||Math.abs(s-n[1])<=o,l=Math.abs(a-t[0])<=o||Math.abs(a-t[1])<=o;if(!c||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function qn(e){return!!Ou(e)}function Ct(e){return!e.texture&&e.polygon.vertices.length===3}function ao(e){return!e.texture&&!!e.projectiveMatrix&&!qn(e)}function Zy(e){let n=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(e);return/\bVersion\/[\d.]+.*\bSafari\//.test(e)&&!n}function Xs(e,n){e.set(n,(e.get(n)??0)+1)}function Ys(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function qy(e,n,t,o){let r=!t.has("b"),i=r&&o.projectiveQuadSupported,s=!t.has("u")&&o.solidTriangleSupported,a=!t.has("i")&&!!o.cornerShapeSupported,c=!t.has("i")&&o.borderShapeSupported,l=t.has("b");return e.map(u=>{if(u?.texture&&$s(u,{allowProjective:o.projectiveQuadSupported,backend:o.textureBackend,imageRendering:o.textureImageRendering,lighting:o.textureImageLighting,projection:o.textureProjection}))return null;if(!u||u.texture)return u;if(s&&Ct(u))return null;let f=qn(u);return a&&!f&&!(i&&ao(u))&&Rs(u)!==null||r&&f||i&&ao(u)||c&&(!f||l)?null:u})}function Qy(e,n,t,o,r,i,s){let a=new Map,c=new Map,l=new Map,u=!t.has("b"),f=u&&o.projectiveQuadSupported,d=!t.has("u")&&o.solidTriangleSupported,m=!t.has("i")&&o.cornerShapeSupported,p=!t.has("i")&&o.borderShapeSupported;for(let y of e){if(!y||y.texture)continue;let b=m&&!!s?.(y);if(n==="dynamic"){if(!(d&&Ct(y))&&!(u&&qn(y))&&!(f&&ao(y))&&!b&&!p)continue;let x=r(y.polygon.color??"#cccccc"),P=i(x);Xs(c,P),l.has(P)||l.set(P,x);continue}!(d&&Ct(y))&&!(u&&qn(y))&&!(f&&ao(y))&&!b&&!p||Xs(a,y.shadedColor)}let g=Ys(a),h=Ys(c);return{paintColor:g,dynamicColorKey:h,dynamicColor:h?l.get(h):void 0}}function Jy(e,n){if((e+1)%3===n)return e;if((n+1)%3===e)return n}function eb(e,n,t,o,r,i,s){if(!e?.size)return null;let a=pr(n,t);return[[i,o],[o,r],[r,i]].map(([l,u],f)=>{let d=Jy(l,u),m=d!==void 0&&e.has(d)?a:0;return gr(s,f,m)})}function js(e,n,t,o,r,i,s,a){let c=i,l="",u,f,d="";if(s){let m=a??e.color??"#cccccc",p=i.directionalLight,g=i.ambientLight,h=p?.direction??ft,y=p?.color??mt,b=Math.max(0,p?.intensity??dt),x=g?.color??pt,P=Math.max(0,g?.intensity??gt),M=Math.hypot(h[0],h[1],h[2])||1,C=h[0]/M,E=h[1]/M,A=h[2]/M,T=i.lightOccludedPolyIndices?.has(n)??!1?0:b*Math.max(0,t*C+o*E+r*A),v=i.tileSize??50,R=i.layerElevation??v,O=zs(i.pointLights,gn(e.vertices,v,R),[t,o,r],v,R),L=wn(m,T,y,x,P,O),D=i.textureLighting??"baked",_=D==="baked"&&c.stableTriangleColorSteps?qi(L,c.stableTriangleColorSteps):L,w=dn(m),V=_===i.solidPaintDefaults?.paintColor,j=D==="dynamic"&&Zi(w)===i.solidPaintDefaults?.dynamicColorKey;l=D==="dynamic"||V?"":_,u=l?dn(l):void 0,f=l?Jo(l):void 0,d=D==="dynamic"?`--pnx:${t.toFixed(4)};--pny:${o.toFixed(4)};--pnz:${r.toFixed(4)};`+(j?"":`--psr:${(w.r/255).toFixed(4)};--psg:${(w.g/255).toFixed(4)};--psb:${(w.b/255).toFixed(4)};`):""}return{index:n,polygon:e,colorComputed:s,bakedColor:l||void 0,bakedRgb:u,bakedAlpha:f,dynamicVars:d}}function nb(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??50,r=t.layerElevation??o,i=e.vertices[0],s=e.vertices[1],a=e.vertices[2],c=[i[1]*o,i[0]*o,i[2]*r],l=[s[1]*o,s[0]*o,s[2]*r],u=[a[1]*o,a[0]*o,a[2]*r],f=l[0]-c[0],d=l[1]-c[1],m=l[2]-c[2],p=u[0]-c[0],g=u[1]-c[1],h=u[2]-c[2],y=-(d*h-m*g),b=-(m*p-f*h),x=-(f*g-d*p),P=Math.sqrt(y*y+b*b+x*x);return P<=ge?null:(y/=P,b/=P,x/=P,js(e,n,y,b,x,t,!0))}function tb(e,n,t,o={}){if(e.texture||e.vertices.length!==3)return null;let r=t.tileSize??50,i=t.layerElevation??r,s=e.vertices[0],a=e.vertices[1],c=e.vertices[2],l=s[1]*r,u=s[0]*r,f=s[2]*i,d=a[1]*r,m=a[0]*r,p=a[2]*i,g=c[1]*r,h=c[0]*r,y=c[2]*i;return Ws(e,n,t,o,l,u,f,d,m,p,g,h,y)}function Ws(e,n,t,o,r,i,s,a,c,l,u,f,d){let m=t,p=a-r,g=c-i,h=l-s,y=u-r,b=f-i,x=d-s,P=-(g*x-h*b),M=-(h*y-p*x),C=-(p*b-g*y),E=Math.sqrt(P*P+M*M+C*C);if(E<=ge)return null;P/=E,M/=E,C/=E;let A=o.basis,S=A?.a??0,T=A?.b??1,v=A?.c??2;S<0||S>2||T<0||T>2||v<0||v>2||S===T||S===v||T===v?(A=void 0,S=0,T=1,v=2):S===0&&T===1&&v===2||S===1&&T===2&&v===0||S===2&&T===0&&v===1||(A=void 0,S=0,T=1,v=2);let R=()=>A?Ws(e,n,t,{...o,basis:void 0},r,i,s,a,c,l,u,f,d):null;if(!A){let Pe=p*p+g*g+h*h,pe=u-a,Fe=f-c,Le=d-l,Ve=r-u,$e=i-f,ke=s-d,ze=pe*pe+Fe*Fe+Le*Le,We=Ve*Ve+$e*$e+ke*ke,be=Pe;ze>be&&(S=1,T=2,v=0,be=ze),We>be&&(S=2,T=0,v=1)}let O,L,D,_,w,V,j=v===0?r:v===1?a:u,G=v===0?i:v===1?c:f,Z=v===0?s:v===1?l:d;S===0?(O=r,L=i,D=s):S===1?(O=a,L=c,D=l):(O=u,L=f,D=d),T===0?(_=r,w=i,V=s):T===1?(_=a,w=c,V=l):(_=u,w=f,V=d);let ee=_-O,W=w-L,ie=V-D,z=Math.sqrt(ee*ee+W*W+ie*ie);if(z<=ge)return R();let X=ee/z,U=W/z,I=ie/z,B=(j-O)*X+(G-L)*U+(Z-D)*I,N=M*I-C*U,H=C*X-P*I,$=P*U-M*X,k=E/z;if(k<=ge)return R();let Q=Math.max(0,Math.min(z,B)),ae=Math.max(0,z-Q),se=[Q,0,0,k,Q+ae,k],Y=ki*(m.bleedRatio??1),ne=eb(m.seamEdges,m.seamBleed,Y,S,T,v,se),le=ne?io(se,ne):Es(Q,ae,k,pr(m.seamBleed,Y)),ye=le[0],Ae=le[1],_e=le[2],Ee=le[3],Me=le[4],Re=le[5],F=(Ee+Re)/2,q=ye-_e,J=Me-ye,te=F-Ae;if(q<=ge||J<=ge||te<=ge||!Number.isFinite(q+J+te))return R();let ue=o.includeColor??!0,ce=!1,he,Se,ve,xe="";if(ue){let Pe=js(e,n,P,M,C,t,!0,o.color);ce=Pe.colorComputed,he=Pe.bakedColor,Se=Pe.bakedRgb,ve=Pe.bakedAlpha,xe=Pe.dynamicVars??""}let K=he?`color:${he};`:"",oe=o.primitive??o.resolvedPrimitive??"border",qe=1/(oe==="border-large"?$i:Gi),Ye=q+J,Ge=Ye*qe,we=(J-q)*.5*qe,Ne=te*qe,Je=ye-Q-Ye*.5,Qe=Ae,hn=X*Ge,yn=U*Ge,Bn=I*Ge,vt=X*we+N*Ne,Qn=U*we+H*Ne,bn=I*we+$*Ne,ln=j+X*Je+N*Qe,Jn=G+U*Je+H*Qe,je=Z+I*Je+$*Qe,en=o.matrixDecimals??vs(m.stableTriangleMatrixDecimals),Ce=As(hn,yn,Bn,vt,Qn,bn,P,M,C,ln,Jn,je,en),Be=t.textureLighting??"baked",fe=m.optimizeStableTriangleStyle===!0&&Be==="baked"?"":`transform:${Ce};`+K+xe,me=A&&A.a===S&&A.b===T&&A.c===v?A:{a:S,b:T,c:v};return{index:n,polygon:e,styleText:fe,transformText:Ce,basis:me,primitive:oe,colorComputed:ce,bakedColor:he,bakedRgb:Se,bakedAlpha:ve,dynamicVars:xe}}function Et(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Oi,Math.max(Vi,n))}function Hs(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function Ru(e,n){let t=Hs(e);if(t<=0)return 1;let o=Math.max(1,...e.map(s=>Math.max(s.width,s.height))),r=qt/o,i=Math.sqrt(n/(t*4));return Et(Math.min(r,i))}function Lu(e,n){let t=Hs(e),o=.5;return t<=Wo?o=1:t<=Ri&&(o=.75),Et(Math.min(o,Ru(e,n)))}function wu(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function Nu(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function Du(e,n,t){let o=wu(e,n),r=Nu(e,n),i=o>qt?qt/o:1,s=r>t?Math.sqrt(t/r):1;return Math.min(i,s)}function Fu(e){return e?Li:wi}function Bu(e,n){return e!==void 0&&e!=="auto"?tn:n?tn:Xi}function ob(e,n){return Ar(e,n,1,"canonical")}function ku(e,n,t,o=zu(e)){let r=t??"canonical";if(r==="local")return{width:Math.max(1,e.canvasW||1),height:Math.max(1,e.canvasH||1),sizing:r};if(r==="raster"){let i=Et(n);return{width:Math.max(1,(e.canvasW||1)*i),height:Math.max(1,(e.canvasH||1)*i),sizing:r}}return{width:o,height:o,sizing:"canonical"}}function Ar(e,n,t,o="canonical"){for(let r of e.entries){if(!r)continue;let i=ku(r,t,o,n);r.atlasCanonicalSize=n,r.atlasLeafSizing=i.sizing,r.atlasLeafWidth=i.width,r.atlasLeafHeight=i.height,r.atlasMatrix=oo(r,i.width,i.height)}return e}function zu(e){return e.atlasCanonicalSize??tn}function Uu(e){return Math.max(jo,Math.ceil(jo/e))}function co(e,n=1){let t=Array(e.length).fill(null),o=[],r=Uu(n),i=e.filter(c=>!!c).sort((c,l)=>l.canvasH-c.canvasH||l.canvasW-c.canvasW||c.index-l.index),s=()=>({width:r,height:r,entries:[],shelves:[]}),a=(c,l,u)=>{if(c.sealed)return null;for(let m of c.shelves)if(l.canvasH<=m.height&&m.x+l.canvasW+r<=Ln){let p={...l,pageIndex:u,x:m.x,y:m.y};return m.x+=l.canvasW+r*2,c.entries.push(p),c.width=Math.max(c.width,p.x+l.canvasW+r),p}let f=c.shelves.length===0?r:c.height+r;if(f+l.canvasH+r>Ln)return null;let d={...l,pageIndex:u,x:r,y:f};return c.shelves.push({x:r+l.canvasW+r*2,y:f,height:l.canvasH}),c.entries.push(d),c.width=Math.max(c.width,d.x+l.canvasW+r),c.height=Math.max(c.height,f+l.canvasH+r),d};for(let c of i){if(c.canvasW+r*2>Ln||c.canvasH+r*2>Ln){let f=o.length,d={...c,pageIndex:f,x:r,y:r};t[c.index]=d,o.push({width:c.canvasW+r*2,height:c.canvasH+r*2,entries:[d],shelves:[],sealed:!0});continue}let u=null;for(let f=0;f<o.length&&(u=a(o[f],c,f),!u);f++);if(!u){let f=s(),d=o.length;o.push(f),u=a(f,c,d)}u&&(t[c.index]=u)}return{entries:t,pages:o.map(({width:c,height:l,entries:u})=>({width:c,height:l,entries:u}))}}function rb(e,n,t){let o=Lu(n.pages,t),r=o===1?n:co(e,o);for(let i=0;i<4;i++){let s=Du(r.pages,o,t);if(s>=1)break;let a=Et(o*s*Ni);if(a>=o)break;o=a,r=co(e,o)}return{packed:r,atlasScale:o}}function ib(e,n,t,o="canonical"){let r=Bu(n,t);if(n!==void 0&&n!=="auto"){let a=Et(n);return{packed:Ar(co(e,a),r,a,o),atlasScale:a,atlasCanonicalSize:r}}let i=co(e,1),s=rb(e,i,Fu(t));return{packed:Ar(s.packed,r,s.atlasScale,o),atlasScale:s.atlasScale,atlasCanonicalSize:r}}export{y0 as ASYNC_RENDER_BUDGET_MS,Xi as ATLAS_CANONICAL_SIZE_AUTO_DESKTOP,tn as ATLAS_CANONICAL_SIZE_EXPLICIT,Ln as ATLAS_MAX_SIZE,jo as ATLAS_PADDING,Wo as AUTO_ATLAS_LOW_AREA,qt as AUTO_ATLAS_MAX_BITMAP_SIDE,wi as AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP,Li as AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE,Ri as AUTO_ATLAS_MEDIUM_AREA,Ni as AUTO_ATLAS_SCALE_GUARD,Qg as BAKED_SHADOW_MIN_UP,qg as BAKED_SHADOW_Z_SQUASH,Ze as BASE_TILE,ge as BASIS_EPS,Yi as BORDER_SHAPE_BLEED,In as BORDER_SHAPE_CANONICAL_SIZE,Zo as BORDER_SHAPE_CENTER_PERCENT,qo as BORDER_SHAPE_POINT_EPS,Uo as CAMERA_BACKFACE_CULL_EPS,Di as COLOR_PARSE_CACHE_MAX,Qo as CORNER_SHAPE_DUPLICATE_EPS,on as CORNER_SHAPE_POINT_EPS,Ui as DECIMAL_SCALES,pt as DEFAULT_AMBIENT_COLOR,gt as DEFAULT_AMBIENT_INTENSITY,Ko as DEFAULT_ATLAS_CSS_DECIMALS,zi as DEFAULT_BORDER_SHAPE_DECIMALS,Oe as DEFAULT_CAMERA_STATE,mt as DEFAULT_LIGHT_COLOR,ft as DEFAULT_LIGHT_DIR,dt as DEFAULT_LIGHT_INTENSITY,En as DEFAULT_MATRIX_DECIMALS,Gu as DEFAULT_PROJECTION,S0 as DEFAULT_SEAM_BLEED,ka as DEFAULT_SEAM_FACET_SPLIT_OPTIONS,Ba as DEFAULT_SEAM_OVERLAP_OPTIONS,mn as DEFAULT_TILE,dl as LoopOnce,pl as LoopPingPong,os as LoopRepeat,Oi as MAX_ATLAS_SCALE,Vi as MIN_ATLAS_SCALE,Hi as PROJECTIVE_QUAD_BLEED,ji as PROJECTIVE_QUAD_DENOM_EPS,Wi as PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,tf as QUAT_IDENTITY,cl as RECEIVER_NORMAL_TOL,ll as RECEIVER_OFFSET_TOL,al as RECEIVER_OUTLINE_EXPAND,Te as RECT_EPS,Ho as SEAM_LIGHT_EPS,vn as SOLID_QUAD_CANONICAL_SIZE,ki as SOLID_TRIANGLE_BLEED,Gi as SOLID_TRIANGLE_CANONICAL_SIZE,$i as SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE,Bi as SURFACE_DISTANCE_EPS,Fi as SURFACE_NORMAL_EPS,x0 as TEXTURE_EDGE_REPAIR_ALPHA_MIN,M0 as TEXTURE_EDGE_REPAIR_RADIUS,P0 as TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN,b0 as TEXTURE_TRIANGLE_BLEED,Vc as VOXEL_CAMERA_CULL_AXIS_EPS,Oc as VOXEL_CAMERA_CULL_NORMAL_LIMIT,ob as applyPackedAtlasCanonicalSize,Ar as applyPackedAtlasLeafSizing,zc as arrowPolygons,Hs as atlasArea,wu as atlasBitmapMaxSide,zu as atlasCanonicalSizeForEntry,Bu as atlasCanonicalSizeForTextureQuality,Nu as atlasDecodedBytes,Uu as atlasPadding,Du as autoAtlasBudgetFactor,Fu as autoAtlasMaxDecodedBytes,Lu as autoAtlasScale,Ru as autoAtlasScaleCap,Dc as axesHelperPolygons,Ih as bakeSolidTextureSampledPolygons,us as bakeSolidTextureSamples,Cu as basisAxisKey,gu as borderShapeBoundsFromPoints,so as borderShapeGeometryForPlan,Bc as boxPolygons,Jg as buildBakedShadowProjectionMatrix,Yy as buildBasisHints,Qi as buildEdgeOwners,c0 as buildParametricCasterOverride,lf as buildPolyCameraSceneTransform,g0 as buildPolyMeshTransform,h0 as buildPolySceneTransform,Ku as buildSceneContext,du as buildSeamBleedPolygonEdges,Ly as buildSeamBleedPolygonSet,_0 as buildSharedEdgeMap,_y as buildTextureEdgeRepairSets,yt as cachedParsePureColor,wc as cameraCullNormalGroups,zg as cameraCullNormalGroupsFromPolygons,Lc as cameraCullNormalKey,Gg as cameraCullVisibleSignature,Rc as cameraFacingDepth,uf as capturePolyCameraSnapshot,vu as chooseIslandXAxis,Bs as chooseLocalBasis,zn as clampChannel,Ji as classifyFacing,Rn as clipPolygonToConvex2D,I0 as colorErrorScore,ks as compatibleBleedSurface,Au as compatibleSurface,Ei as computeCoverageShadowSilhouette,Bg as computeLightVisibility,w0 as computeMergedReceiverShadows,Ti as computeParametricShadowSilhouette,_s as computePlanSeamBleedEdgeAmounts,Ds as computeProjectiveQuadCoefficients,Pr as computeProjectiveQuadMatrix,ml as computeReceiverShadowFaces,la as computeSceneBbox,Os as computeSeamBleedInsets,Xu as computeShapeLighting,nb as computeSolidTriangleColorPlan,js as computeSolidTriangleColorPlanFromNormal,tb as computeSolidTrianglePlan,Ws as computeSolidTrianglePlanFromCssPoints,Zn as computeSurfaceNormal,Vu as computeTextureAtlasPlan,jy as computeTextureAtlasPlanPublic,ef as computeTexturePaintMetrics,Us as computeUvAffine,Gs as computeUvSampleRect,Kc as conePolygons,Ci as convexHull2D,xu as cornerShapeDiagonal,Rs as cornerShapeGeometryForPlan,yu as cornerShapePointSides,Fr as coverPlanarPolygons,mf as createIsometricCamera,k0 as createPolyAnimationMixer,$y as crossVec,Ls as cssBorderShapeForGeometry,By as cssBorderShapeForPlan,ol as cssDistanceToWorld,gn as cssPoints,rl as cssPositionToWorld,Mn as cullInteriorPolygons,$o as cylinderPolygons,Nf as dedupeOverlappingPolygons,Hc as dodecahedronPolygons,Ys as dominantCountKey,Mr as dotVec,Tn as ensureCcw2D,af as eulerXYZFromQuat,Eu as evaluateIslandAxis,St as expandClipPoints,sl as expandConvexHullOutward,tr as extractSilhouetteLoops,qy as filterAtlasPlans,Mo as findOverlappingPolygonDuplicates,Ay as formatAffineMatrix3dColumns,Ss as formatAffineMatrix3dScalars,As as formatAffineMatrix3dTransformScalars,oo as formatAtlasMatrix,zy as formatBorderShapeElementStyle,ky as formatBorderShapeEntryMatrix,Cy as formatBorderShapeMatrix,yo as formatColor,Uy as formatCornerShapeElementStyle,Sy as formatCssLength,Ey as formatCssLengthPx,Ty as formatMatrix3d,pn as formatMatrix3dValues,Fn as formatPercent,to as formatScaledMatrixFromPlan,vy as formatSolidQuadEntryMatrix,uu as formatSolidQuadMatrix,Ou as fullRectBounds,Su as getPolygonBasisInfo,Qy as getSolidPaintDefaultsForPlansCore,_i as groupReceiverFaceGroups,Wc as icosahedronPolygons,Xs as incrementCount,Ts as intersect2DLines,Iy as intersect2DLinesRaw,nf as inverseRotateVec3,Nc as isAxisAlignedSurfaceNormal,t0 as isBakedShadowCaster,Mu as isBasisOptimizable,nl as isConvexCaster,ro as isConvexPolygonPoints,el as isFlatCaster,Iu as isFullRectBasis,qn as isFullRectSolid,n0 as isPointShadowCaster,ao as isProjectiveQuadPlan,Ct as isSolidTrianglePlan,Ug as isVoxelCameraCullableNormalGroups,My as loadMesh,Tt as makeLocalBasis,fn as mergePolygons,Ii as meshScaleVec3,Kt as normalFacesCamera,Et as normalizeAtlasScale,cf as normalizeInvertMultiplier,Er as normalizePolygons,Is as normalizedSeamBleed,Xc as octahedronPolygons,At as offsetConvexPolygonPoints,io as offsetConvexPolygonPointsByEdgeAmounts,Es as offsetStableTrianglePoints,mr as offsetTrianglePoints,wh as optimizeAnimatedMeshPolygons,ut as optimizeMeshParseResult,dp as optimizeMeshPolygons,co as packTextureAtlasPlans,ib as packTextureAtlasPlansWithScaleCore,Jo as parseAlpha,tt as parseColor,as as parseGltf,dn as parseHex,Rt as parseHexColor,ps as parseMtl,ms as parseObj,Vn as parsePureColor,Js as parseRgbColor,Ms as parseStl,hs as parseVox,$c as planePolygons,ma as polyCameraTargetToCss,u0 as polyCssDistanceToWorld,m0 as polyCssPositionToWorld,pu as polygonContainsPoint,Mi as polygonCssSurfaceNormal,Zu as polygonFaces,kg as polygonFacesCamera,qc as polygonSignedArea2D,V0 as prepareCasterEdgeOwners,O0 as prepareCasterPolyItems,R0 as prepareReceiverFacePlanes,o0 as projectCssVertexToGround,e0 as projectCssVertexToGroundFromPoint,_u as projectTextureTriangle,qi as quantizeCssColor,rf as quatFromAxisAngle,sf as quatFromEulerXYZ,of as quatMultiply,Qm as repairMeshSeams,ku as resolveAtlasLeafBox,Ki as resolveBleedRatio,da as resolvePolyCameraAppliedPerspectiveStyle,Gy as resolvePolyTextureImageRendering,hr as resolvePolyTextureImageSource,$s as resolvePolyTextureLeafGeometry,yr as resolvePolyTexturePresentation,Ns as resolvePolyTextureUrl,xr as resolveProjectiveQuadGuards,pr as resolveSeamBleed,T0 as rgbEqual,Zi as rgbKey,v0 as rgbToCss,er as rgbToHex,Uc as ringPolygons,Gc as ringQuadPolygons,vr as rotateVec3,Un as rotateVec3InWrapperCssFrame,Ue as roundDecimal,Zy as safariCssProjectiveUnsupported,gr as safePlanSeamBleedAmount,df as screenToWorldOnSphere,ga as screenToWorldRay,Vs as seamBleedAmountArray,Za as seamFacetSplitPolygons,qm as seamFacetSplitReport,Fs as seamLightBrightness,Jm as seamOverlapDiagnostics,qa as seamOverlapPolygons,ed as seamOverlapReport,$u as shadeColor,wn as shadePolygon,bu as sharedCornerShapeSide,Cs as signedArea2D,hu as simplifyCornerShapePoints,ei as simplifyTriangleMeshPolygons,Yc as spherePolygons,dr as stableBasisFromPlan,vs as stableTriangleMatrixDecimals,E0 as stepRgbToward,jc as tetrahedronPolygons,nr as textureTintFactors,A0 as tintToCss,Zc as torusPolygons,Zt as worldCssForMesh,vi as worldDirectionToCss,d0 as worldDirectionToPolyCss,il as worldDirectionalLightToCss,p0 as worldDirectionalLightToPolyCss,tl as worldDistanceToCss,l0 as worldDistanceToPolyCss,cn as worldPositionToCss,f0 as worldPositionToPolyCss};
|