@layoutit/polycss-core 0.2.4 → 0.2.5
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 +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +28 -3
- package/dist/index.d.ts +28 -3
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var jl="cubic";function pi(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 gi(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 Mn(e){if(!e)return null;let n=e.trim(),t=pi(n);return t||gi(n)}function On(e){return Math.max(0,Math.min(255,Math.round(e)))}function Ht(e){let[n,t,o]=e.rgb.map(On);return e.alpha<1?`rgba(${n}, ${t}, ${o}, ${e.alpha})`:`rgb(${n}, ${t}, ${o})`}var Zo={rgb:[204,204,204],alpha:1},hi=new Map;function jn(e){if(!e)return null;let n=e.trim(),t=hi.get(n);if(t)return t;let o=Mn(n);return o?(hi.set(n,o),o):null}function Kl(e,n){let t=jn(e)??Zo,o=[On(t.rgb[0]+n),On(t.rgb[1]+n),On(t.rgb[2]+n)];return Ht({rgb:o,alpha:t.alpha})}var Ho={direction:[0,0,-1],color:"#ffffff",intensity:1},yi={color:"#ffffff",intensity:.4};function bi(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 xi(e,n,t){let o=jn(n)??Zo;return e*(o.rgb[t]/255)}function Hl(e,n,t,o){let r=jn(n)??Zo,s=bi(t?.direction??Ho.direction),i=t?.color??Ho.color,c=Math.max(0,t?.intensity??Ho.intensity),a=o?.color??yi.color,l=Math.max(0,o?.intensity??yi.intensity),u=bi(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),d=c*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let h=r.rgb[p],g=xi(h,a,p)*l,y=xi(h,i,p)*d;m[p]=On(g+y)}return Ht({rgb:m,alpha:r.alpha})}var Pi="#cccccc",Zt=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Mi=(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]],Ai=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],qt=e=>Math.hypot(e[0],e[1],e[2]);function Zl(e){let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-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]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);let c=r-n,a=s-t,l=i-o;return Math.hypot(c,a,l)}function ql(){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 qo(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 s=r.vertices;if(s.length<3){t.push(`Polygon ${o}: ${s.length} vertices (need >= 3), dropped`);continue}let i=Zt(s[1],s[0]),c=Zt(s[2],s[0]),a=Mi(i,c),l=qt(a);if(s.length===3){if(l<1e-12){qt(i)<1e-12||qt(c)<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:s.slice()}];if(s.length>=4){let f=[a[0]/l,a[1]/l,a[2]/l],d=Ai(f,s[0]),m=Zl(s),p=Math.max(1e-6,m*.001),h=0;for(let g=3;g<s.length;g++){let y=Math.abs(Ai(f,s[g])-d);y>h&&(h=y)}if(h>p){let g=[],y=r.uvs&&r.uvs.length===s.length?r.uvs:void 0;for(let b=1;b<s.length-1;b++){let x=[s[0].slice(),s[b].slice(),s[b+1].slice()],P=Mi(Zt(x[1],x[0]),Zt(x[2],x[0]));if(qt(P)<1e-12)continue;let S={...r,vertices:x};y&&(S.uvs=[y[0].slice(),y[b].slice(),y[b+1].slice()]),g.push(S)}if(g.length===0){t.push(`Polygon ${o}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${o}: ${s.length} non-coplanar vertices, fan-triangulated to ${g.length} triangles`),u=g}}for(let f of u){let d=Ql(f,o,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function Ql(e,n,t){let o={vertices:e.vertices},r=e.texture;if(typeof r=="string"&&r===""&&(r=void 0),e.color!==void 0&&r!==void 0&&ql()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(jn(e.color)?o.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${Pi}`),o.color=Pi)),r!==void 0&&(o.texture=r,e.textureWrap&&(o.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(o.textureAlphaMode=e.textureAlphaMode)),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 s={},i=!1;for(let c of Object.keys(e.data)){let a=e.data[c];typeof a=="string"||typeof a=="number"||typeof a=="boolean"?s[c]=a:(i=!0,t.push(`Polygon ${n}: data["${c}"] has non-primitive value, key dropped`))}Object.keys(s).length>0&&(o.data=s)}return o}function Si(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,s=-1/0,i=-1/0,c=!1;for(let a of e)if(a?.vertices)for(let l of a.vertices)l&&(c=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]));return c?{min:[n,t,o],max:[r,s,i]}:{min:[0,0,0],max:[0,0,0]}}function Jl(e){let n=e.polygons??[],t,o;if(e.skipNormalize)t=n,o=[];else{let c=qo(n);t=c.polygons,o=c.warnings}let r=Si(t),s=[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:s},warnings:o}}function eu(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function nu(e){let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],s=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],i=r[1]*s[2]-r[2]*s[1],c=r[2]*s[0]-r[0]*s[2],a=r[0]*s[1]-r[1]*s[0],l=Math.hypot(i,c,a);return l<=1e-9?null:[i/l,c/l,a/l]}function tu(e){let n=0;for(let t=0;t<e.length;t++){let[o,r]=e[t],[s,i]=e[(t+1)%e.length];n+=o*i-s*r}return Math.abs(n)/2}function ou(e,n,t){if(!e||e.length<3)return null;let o=e.map(c=>[c[1]*n,c[0]*n,c[2]*t]),r=nu(o);if(!r)return null;let s=1/0,i=0;for(let c=0;c<o.length;c++){let a=o[c],l=o[(c+1)%o.length],u=[l[0]-a[0],l[1]-a[1],l[2]-a[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],h=[r[1]*p[2]-r[2]*p[1],r[2]*p[0]-r[0]*p[2],r[0]*p[1]-r[1]*p[0]],g=Math.hypot(h[0],h[1],h[2]);if(g<=1e-9)continue;let y=[h[0]/g,h[1]/g,h[2]/g],b=o.map(v=>{let I=v[0]-a[0],_=v[1]-a[1],O=v[2]-a[2];return[I*p[0]+_*p[1]+O*p[2],I*y[0]+_*y[1]+O*y[2]]}),x=1/0,P=1/0,S=-1/0,C=-1/0;for(let[v,I]of b)x=Math.min(x,v),P=Math.min(P,I),S=Math.max(S,v),C=Math.max(C,I);let T=S-x,A=C-P,M=Math.max(1,Math.ceil(T))*Math.max(1,Math.ceil(A)),E=tu(b);E<=1e-9||M<s&&(s=M,i=E)}return!Number.isFinite(s)||i<=1e-9?null:{elementArea:s,polygonArea:i}}function ru(e,n={}){let t=n.tileSize??100,o=n.layerElevation??t,r=n.texturedOnly??!0,s=0,i=0,c=0,a=0,l=0;for(let f of e){let d=!!f.texture;if(r&&!d)continue;let m=ou(f.vertices,t,o);m&&(s+=1,d&&(i+=1),c+=m.elementArea,a+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,c-a);return{totalPolygons:e.length,measuredPolygons:s,texturedPolygons:i,elementArea:c,polygonArea:a,transparentArea:u,transparentRatio:c>0?u/c:0,overdrawRatio:a>0?c/a:0,worstTransparentRatio:l}}function Qo(e,n,t,o){let r=n*Math.PI/180,s=t*Math.PI/180,i=o*Math.PI/180,[c,a,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[c,a]=[c*u-a*f,c*f+a*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[c,l]=[c*u+l*f,-c*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[a,l]=[a*u-l*f,a*f+l*u]}return[c,a,l]}function su(e,n){let t=-n[0]*Math.PI/180,o=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[s,i,c]=e;if(t!==0){let a=Math.cos(t),l=Math.sin(t);[i,c]=[i*a-c*l,i*l+c*a]}if(o!==0){let a=Math.cos(o),l=Math.sin(o);[s,c]=[s*a+c*l,-s*l+c*a]}if(r!==0){let a=Math.cos(r),l=Math.sin(r);[s,i]=[s*a-i*l,s*l+i*a]}return[s,i,c]}function Vn(e,n){let[t,o,r]=e,s=-(n[2]??0)*Math.PI/180;if(s!==0){let a=Math.cos(s),l=Math.sin(s);[t,o]=[t*a-o*l,t*l+o*a]}let i=-(n[1]??0)*Math.PI/180;if(i!==0){let a=Math.cos(i),l=Math.sin(i);[o,r]=[o*a-r*l,o*l+r*a]}let c=-(n[0]??0)*Math.PI/180;if(c!==0){let a=Math.cos(c),l=Math.sin(c);[t,r]=[t*a+r*l,-t*l+r*a]}return[t,o,r]}var Jo=Math.PI/180,xt=180/Math.PI,iu=[1,0,0,0];function au(e,n){let[t,o,r,s]=e,[i,c,a,l]=n;return[t*i-o*c-r*a-s*l,t*c+o*i+r*l-s*a,t*a-o*l+r*i+s*c,t*l+o*a-r*c+s*i]}function cu(e,n){let t=n*.5,o=Math.sin(t);return[Math.cos(t),e[0]*o,e[1]*o,e[2]*o]}function lu(e){let n=e[0]*Jo,t=e[1]*Jo,o=e[2]*Jo,r=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(t*.5),c=Math.sin(t*.5),a=Math.cos(o*.5),l=Math.sin(o*.5);return[r*i*a-s*c*l,s*i*a+r*c*l,r*c*a-s*i*l,r*i*l+s*c*a]}function uu(e){let[n,t,o,r]=e,s=2*(t*r+n*o),i=2*(o*r-n*t),c=1-2*(t*t+o*o),a=2*(t*o-n*r),l=1-2*(o*o+r*r),u=Math.max(-1,Math.min(1,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,c)*xt,f*xt,Math.atan2(-a,l)*xt]:[Math.atan2(2*(o*r+n*t),1-2*(t*t+r*r))*xt,f*xt,0]}var ze=50;function fu(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Hn={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},Ci=100,Ei=1e4,Kn=e=>Math.round(e*Ci)/Ci,mu=e=>Math.round(e*Ei)/Ei;function du(e={}){let n={target:e.target??[...Hn.target],rotX:e.rotX??Hn.rotX,rotY:e.rotY??Hn.rotY,zoom:e.zoom??Hn.zoom,distance:e.distance??Hn.distance};function t(r){r.target!==void 0&&(n.target=[Kn(r.target[0]),Kn(r.target[1]),Kn(r.target[2])]),r.rotX!==void 0&&(n.rotX=Kn(r.rotX)),r.rotY!==void 0&&(n.rotY=Kn(r.rotY)),r.zoom!==void 0&&(n.zoom=mu(r.zoom)),r.distance!==void 0&&(n.distance=Kn(r.distance))}function o(r={}){let i=(r.cols??0)*50,c=(r.rows??0)*50,[a,l,u]=n.target,f=l*50,d=a*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:`${i}px`,height:`${c}px`}}return{state:n,update:t,getStyle:o}}var Ti=Math.PI/180;function vi(e){let{camera:n,tileSize:t,viewportCenterX:o,viewportCenterY:r,mouseX:s,mouseY:i}=e,c=n.rotX*Ti,a=n.rotY*Ti,l=n.zoom/t,u=n.target,f=s-o,d=i-r,m=f/l,p=d/l,h=Math.cos(c),g=Math.sin(c),y=m,b=p*h,x=-p*g,P=0,S=g,C=h,T=Math.cos(a),A=Math.sin(a),M=y*T+b*A,E=-y*A+b*T,v=x,I=P*T+S*A,_=-P*A+S*T,O=C,V=u[1]*t,w=u[0]*t,F=u[2]*t,D=M+V,H=E+w,K=v+F,Q=[H/t,D/t,K/t],ne=[_/t,I/t,O/t];return{origin:Q,direction:ne}}function pu(e){let{origin:n,direction:t}=vi(e),{sphereCenter:o,sphereRadius:r}=e,s=n[0]-o[0],i=n[1]-o[1],c=n[2]-o[2],a=t[0],l=t[1],u=t[2],f=a*a+l*l+u*u;if(f===0)return null;let d=2*(s*a+i*l+c*u),m=s*s+i*i+c*c-r*r,p=d*d-4*f*m;if(p>=0){let T=Math.sqrt(p),A=(-d-T)/(2*f),M=(-d+T)/(2*f),E=t[2]>=0?Math.max(A,M):Math.min(A,M);return[n[0]+E*t[0],n[1]+E*t[1],n[2]+E*t[2]]}let h=-(s*a+i*l+c*u)/f,g=n[0]+h*a,y=n[1]+h*l,b=n[2]+h*u,x=g-o[0],P=y-o[1],S=b-o[2],C=Math.hypot(x,P,S);return C===0?null:[o[0]+x/C*r,o[1]+P/C*r,o[2]+S/C*r]}var An=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Qt=(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]],Pt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],er=e=>Math.hypot(e[0],e[1],e[2]),Zn=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function gu(e){return`${e[0]},${e[1]},${e[2]}`}function _i(e){if(e.length<3)return null;let n=An(e[1],e[0]),t=An(e[2],e[0]),o=Qt(n,t),r=er(o);if(r<1e-12)return null;let s=[o[0]/r,o[1]/r,o[2]/r],i=Pt(s,e[0]);return{normal:s,d:i}}function hu(e,n){return Pt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function yu(e,n){return Pt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function bu(e,n,t,o){let r=e.vertices.findIndex(A=>Zn(A,t)),s=e.vertices.findIndex(A=>Zn(A,o)),i=n.vertices.findIndex(A=>Zn(A,t)),c=n.vertices.findIndex(A=>Zn(A,o));if(r<0||s<0||i<0||c<0)return null;let a=e.vertices.length,l=n.vertices.length,u=(r+1)%a===s,f=(i+1)%l===c;if(u===f)return null;let d=u?s:r,m=u?r:s,p=f?c:i,h=f?i:c,g=!!(e.uvs&&n.uvs),y=[],b=g?[]:void 0,x=d;for(;y.push(e.vertices[x]),b&&b.push(e.uvs[x]),x!==m;)x=(x+1)%a;for(x=p;y.push(n.vertices[x]),b&&b.push(n.uvs[x]),x!==h;)x=(x+1)%l;let P=[],S=b?[]:void 0;for(let A=0;A<y.length;A++)(P.length===0||!Zn(y[A],P[P.length-1]))&&(P.push(y[A]),S&&b&&S.push(b[A]));if(P.length>1&&Zn(P[0],P[P.length-1])&&(P.pop(),S?.pop()),g)return Ii(P,S);let C=[],T=S?[]:void 0;for(let A=0;A<P.length;A++){let M=P[(A-1+P.length)%P.length],E=P[A],v=P[(A+1)%P.length],I=Qt(An(E,M),An(v,M));er(I)>1e-9&&(C.push(E),T&&S&&T.push(S[A]))}return C.length<3?null:Ii(C,T)}function xu(e,n){let t=e.length,o=0;for(let r=0;r<t;r++){let s=e[r],i=e[(r+1)%t],c=e[(r+2)%t],a=An(i,s),l=An(c,i),u=Pt(Qt(a,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 Pu(e,n){if(e.length<3)return!1;let t=_i(e);if(!t)return!1;for(let o of e)if(Math.abs(Pt(t.normal,o)-t.d)>n)return!1;return!0}function Mu(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Au(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function Su(e,n){return(e??"")===(n??"")}function Cu(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 Ii(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],s=e[(t+2)%e.length];if(!(er(Qt(An(r,o),An(s,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 an(e){let n=[],t=[],o=new WeakMap,r=m=>{let p=o.get(m);if(p)return p;let h=gu(m);return o.set(m,h),h},s=(m,p)=>{let h=r(m),g=r(p);return h<g?`${h}|${g}`:`${g}|${h}`},i=(m,p)=>r(m)<r(p)?1:-1,c=m=>{let p=new Map;for(let h=0;h<m.length;h++){let g=m[h],y=m[(h+1)%m.length];p.set(s(g,y),i(g,y))}return p},a=0,l=!1,u=m=>(a+=m,a<=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,h=_i(p);if(!h){n.push(m);continue}let g=m.texture&&m.uvs&&m.uvs.length===p.length?m.uvs.map(b=>[b[0],b[1]]):void 0,y=m.texture&&g?m.textureTriangles?.length?Mu(m.textureTriangles):Cu(p,g):void 0;t.push({vertices:p,uvs:g,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureTriangles:y,normal:h.normal,d:h.d,edgeDirections:c(p),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let g=0;g<t.length;g++){let y=t[g];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],S=y.vertices[(x+1)%b],C=s(P,S),T=m.get(C);T?T.second<0&&(T.second=g):(T={a:P,b:S,first:g,second:-1},m.set(C,T))}}let p=!1,h=(g,y,b)=>{let x=g.edgeDirections.get(s(y,b));return x?x===i(y,b)?1:-1:0};for(let g of m.values()){if(g.second<0)continue;let y=g.first,b=g.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||!Au(x.textureWrap,P.textureWrap)||!Su(x.textureAlphaMode,P.textureAlphaMode)||x.doubleSided!==P.doubleSided)continue;let S=!!(x.texture||P.texture);if(S&&(!x.textureTriangles||!P.textureTriangles)||!!x.uvs!=!!P.uvs||(S?!yu(x,P):!hu(x,P)))continue;if(!u(x.vertices.length+P.vertices.length))return!1;let C=h(x,g.a,g.b);if(C===0)continue;let T=h(P,g.a,g.b);if(T===0||C===T)continue;let[A,M]=C===1?[g.a,g.b]:[g.b,g.a],E=bu(x,P,A,M);if(E){if(!u(E.vertices.length))return!1;E.vertices.length>96||Pu(E.vertices,.001)&&xu(E.vertices,x.normal)&&(x.vertices=E.vertices,x.uvs=E.uvs,x.edgeDirections=c(E.vertices),x.textureTriangles=S?[...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(h=>[h[0],h[1],h[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.uvs&&(p.uvs=m.uvs.map(h=>[h[0],h[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 Eu=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Tu=(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]],en=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function vu(e,n){let t=e.vertices;if(!t||t.length<3)return null;let o=0,r=0,s=0;for(let h=0;h<t.length;h++){let g=t[h],y=t[(h+1)%t.length];o+=(g[1]-y[1])*(g[2]+y[2]),r+=(g[2]-y[2])*(g[0]+y[0]),s+=(g[0]-y[0])*(g[1]+y[1])}let i=Math.hypot(o,r,s);if(i<1e-12)return null;let c=[o/i,r/i,s/i],a=0,l=0,u=0;for(let h of t)a+=h[0],l+=h[1],u+=h[2];let f=1/t.length,d=[a*f,l*f,u*f],m=en(c,d),p=i*.5;return{index:n,polygon:e,normal:c,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function Iu(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&en(e.normal,n.normal)<0}function _u(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*en(n,e),o=n[1]-e[1]*en(n,e),r=n[2]-e[2]*en(n,e),s=Math.hypot(t,o,r);t/=s,o/=s,r/=s;let i=[t,o,r],c=Tu(e,i);return{u:i,v:c}}function Ou(e){if(e.local2D)return;let n=_u(e.normal),t=[],o=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.polygon.vertices){let a=en(c,n.u),l=en(c,n.v);t.push([a,l]),a<o&&(o=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}e.local2D=t,e.bbox2D={min:[o,r],max:[s,i]},e.basis=n}function Vu(e,n){let t=[],o=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.vertices){let a=en(c,n.u),l=en(c,n.v);t.push([a,l]),a<o&&(o=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}return{local2D:t,bbox2D:{min:[o,r],max:[s,i]}}}function Ru(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 Oi(e,n){let t=!1;for(let o=0,r=n.length-1;o<n.length;r=o++){let s=n[o],i=n[r];s[1]>e[1]!=i[1]>e[1]&&e[0]<(i[0]-s[0])*(e[1]-s[1])/(i[1]-s[1]+1e-30)+s[0]&&(t=!t)}return t}function Vi(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 Lu(e,n){let t=Vi(e),o=Vi(n),r=1e-4,s=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];Oi(u,n)&&s++}let i=0;for(let l of n){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];Oi(u,e)&&i++}let c=s/e.length,a=i/n.length;return Math.max(c,a)}function wu(e,n){let t=e.normal[0],o=e.normal[1],r=e.normal[2],s=Math.abs(t),i=Math.abs(o),c=Math.abs(r),a=t;i>s&&i>c?a=o:c>s&&c>i&&(a=r),a<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 Nu(e,n,t,o){let r=en(e.normal,n.normal);if(Math.abs(r)<1-t)return!1;let s=r>0?1:-1;return Math.abs(e.d-s*n.d)<o}function Ri(e,n){let t=Eu(n,e.centroid);return en(e.normal,t)>0}function Jt(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,o=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,s=n?.preserveDoubleSidedBackfaces??!0,i=[];for(let p=0;p<e.length;p++){let h=vu(e[p],p);h&&i.push(h)}if(i.length<2)return new Set;let c=0,a=0,l=0,u=0;for(let p of i)c+=p.centroid[0]*p.area,a+=p.centroid[1]*p.area,l+=p.centroid[2]*p.area,u+=p.area;let f=u>0?[c/u,a/u,l/u]:[0,0,0],d=new Map;for(let p of i){let h=wu(p,o),g=d.get(h);g||(g=[],d.set(h,g)),g.push(p)}let m=new Set;for(let p of d.values())if(!(p.length<2))for(let h=0;h<p.length;h++){let g=p[h];if(!m.has(g.index))for(let y=h+1;y<p.length;y++){let b=p[y];if(m.has(b.index)||!Nu(g,b,t,o)||s&&Iu(g,b))continue;Ou(g);let x=Vu(b.polygon,g.basis);if(!Ru(g.bbox2D,x.bbox2D)||Lu(g.local2D,x.local2D)<r)continue;let S=Ri(g,f),C=Ri(b,f),T;if(S&&!C?T=g:C&&!S?T=b:T=g.area<b.area?g:b,m.add(T.index),T===g)break}}return m}function Du(e,n){if(!e||e.length<2)return e??[];let t=Jt(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 Fu=4,Bu=8,ku=.001,Uu=1e-9,Gu=1e6,zu=1e6,$u=8,Rn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],or=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],St=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],Ln=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Di=(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]],Fi=e=>Math.hypot(e[0],e[1],e[2]);function Ct(e){let n=Fi(e);return n<=Uu?null:[e[0]/n,e[1]/n,e[2]/n]}function At(e,n){return Math.round(e*n)/n}function nn(e){return At(e,Gu)}function nr(e){return At(e,zu)}function tr(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function un(e){return`${nn(e[0])},${nn(e[1])}`}function Xu(e){let n=un(e.a),t=un(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function qn(e){return`${e[0]},${e[1]},${e[2]}`}function Bi(e,n){let t=qn(e),o=qn(n);return t<o?`${t}|${o}`:`${o}|${t}`}function rr(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Li(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",rr(e.data)].join("|")}function ki(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],o=[0,0,0];for(let s=1;s<n.length-1;s++)o=or(o,Di(Rn(n[s],t),Rn(n[s+1],t)));let r=Ct(o);return r?{normal:r,d:Ln(r,t)}:null}function Yu(e,n,t){return Ln(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function Wu(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function ju(e,n){let t=n[e[0]]?.data,o=rr(t);for(let r of e)if(rr(n[r].data)!==o)return;return t?{...t}:void 0}function Ku(e,n){return e.every(t=>n[t].doubleSided===!0)}function Hu(e,n){let t=e.map(a=>Wu(a)?ki(a):null),o=t.map(Boolean),r=new Map;for(let a=0;a<e.length;a++){if(!t[a])continue;let l=e[a].vertices;for(let u=0;u<l.length;u++){let f=Bi(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:a,edge:u};d?d.push(m):r.set(f,[m])}}let s=e.map(()=>new Set);for(let a of r.values())if(!(a.length<2))for(let l=0;l<a.length;l++)for(let u=l+1;u<a.length;u++){let f=a[l].polygon,d=a[u].polygon,m=t[f],p=t[d];!m||!p||Li(e[f])===Li(e[d])&&Yu(m,p,n)&&(s[f].add(d),s[d].add(f))}let i=new Set,c=[];for(let a=0;a<e.length;a++){if(!o[a]||i.has(a))continue;let l=[],u=[a];for(i.add(a);u.length>0;){let f=u.shift();l.push(f);for(let d of s[f])i.has(d)||(i.add(d),u.push(d))}c.push(l)}return{groups:c}}function Zu(e,n){let t=new Set(e),o=new Map;for(let s of e){let i=n[s].vertices;for(let c=0;c<i.length;c++){let a=Bi(i[c],i[(c+1)%i.length]),l=o.get(a),u={polygon:s,edge:c};l?l.push(u):o.set(a,[u])}}let r=[];for(let s of o.values()){let i=s.filter(c=>t.has(c.polygon));if(i.length===1){let c=i[0],a=n[c.polygon].vertices;r.push({a:a[c.edge],b:a[(c.edge+1)%a.length]})}else if(i.length!==2)return null}return r}function qu(e){let n=new Map;for(let t of e)n.set(qn(t.a),(n.get(qn(t.a))??0)+1),n.set(qn(t.b),(n.get(qn(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function Ui(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 Qu(e){let n=Ui(e);return`${At(n[0],1e3)},${At(n[1],1e3)},${At(n[2],1e3)}`}function Ju(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=Rn(n,St(e,Ln(n,e)));return Ct(t)??[1,0,0]}function ef(e,n,t){let o=new Map;for(let s of e){let i=Rn(s.b,s.a),c=Rn(i,St(n,Ln(i,n))),a=Ct(c);if(!a)continue;let l=Ui(a),u=Qu(l),f=Fi(c),d=o.get(u);d?d.weight+=f:o.set(u,{axis:l,weight:f})}let r=[...o.values()].sort((s,i)=>i.weight-s.weight).slice(0,t).map(s=>s.axis);return r.length===0&&r.push(Ju(n)),r}function wi(e,n,t,o){let r=Rn(e,n);return[nn(Ln(r,t)),nn(Ln(r,o))]}function nf(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 Mt(e,n){let[t,o]=e.a,[r,s]=e.b,i=(n-t)/(r-t);return nn(o+(s-o)*i)}function sr(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],s=n[o],i=n[(o+1)%n.length],c=(s[0]-r[0])*(i[1]-s[1])-(s[1]-r[1])*(i[0]-s[0]);Math.abs(c)>1e-8&&t.push(s)}return t}function no(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 to(e){let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let[s,i]of e)n=Math.min(n,s),t=Math.min(t,i),o=Math.max(o,s),r=Math.max(r,i);return{minX:n,minY:t,maxX:o,maxY:r}}function Gi(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 eo(e){return Math.abs(no(e))}function tf(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-8)continue;let c=i>0?1:-1;if(n===0)n=c;else if(n!==c)return!1}return!0}function of(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],c=o*i-r*s,a=Math.hypot(o,r);if(a<=1e-9||Math.abs(c)>Math.max(1e-8,a*1e-8))return!1;let l=s*o+i*r;return l>=-1e-8&&l<=o*o+r*r+1e-8}function rf(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],s=o*o+r*r;return s<=1e-12?0:((e[0]-n[0])*o+(e[1]-n[1])*r)/s}function sf(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],c=o[1]-t[1],a=Math.hypot(r,s),l=Math.hypot(i,c);if(a<=1e-9||l<=1e-9)return!1;let u=r*(t[1]-e[1])-s*(t[0]-e[0]),f=r*(o[1]-e[1])-s*(o[0]-e[0]),d=r*c-s*i,m=Math.max(1e-8,Math.max(a,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(s),h=Math.min(p?e[0]:e[1],p?n[0]:n[1]),g=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(g,b)-Math.max(h,y)>1e-8}function af(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];for(let s=0;s<n.length;s++)if(sf(o,r,n[s],n[(s+1)%n.length]))return!0}return!1}function Ni(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],s=e[(o+1)%e.length],i=[{t:0,point:r},{t:1,point:s}];for(let a of n)tr(a,r)||tr(a,s)||of(a,r,s)&&i.push({t:rf(a,r,s),point:a});i.sort((a,l)=>a.t-l.t);let c=[];for(let a of i)c.some(l=>Math.abs(l.t-a.t)<=1e-8||tr(l.point,a.point))||c.push(a);for(let a=0;a<c.length-1;a++){let l=c[a].point,u=c[a+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||t.push({a:[nn(l[0]),nn(l[1])],b:[nn(u[0]),nn(u[1])]})}}return t}function cf(e,n,t=to(e),o=to(n)){if(!Gi(t,o)||!af(e,n))return null;let r=[...Ni(e,n),...Ni(n,e)],s=new Map;for(let y of r){let b=Xu(y),x=s.get(b);x?x.push(y):s.set(b,[y])}let i=!1,c=[];for(let y of s.values()){if(y.length===1){c.push(y[0]);continue}i=!0;let b=y.filter(P=>un(P.a)<un(P.b)).length,x=y.length-b;if(b!==x)return null}if(!i||c.length<3)return null;let a=new Map;for(let y of c){let b=un(y.a);if(a.has(b))return null;a.set(b,y)}let l=c[0],u=un(l.a),f=[],d=new Set,m=u;for(let y=0;y<=c.length;y++){let b=a.get(m);if(!b)return null;let x=`${un(b.a)}>${un(b.b)}`;if(d.has(x))return null;if(d.add(x),f.push(b.a),m=un(b.b),m===u)break}if(m!==u||d.size!==c.length)return null;let p=sr(f);if(p.length<3||!tf(p))return null;let h=eo(p),g=eo(e)+eo(n);return Math.abs(h-g)>Math.max(1e-5,g*1e-5)?null:no(p)>=0?p:[...p].reverse()}function lf(e){let n=e.map(sr).filter(r=>r.length>=3&&eo(r)>1e-8),t=n.map(to),o=!0;for(;o;){o=!1;for(let r=0;r<n.length;r++){for(let s=r+1;s<n.length;s++){if(!Gi(t[r],t[s]))continue;let i=cf(n[r],n[s],t[r],t[s]);if(i){n[r]=i,t[r]=to(i),n.splice(s,1),t.splice(s,1),o=!0;break}}if(o)break}}return n}function uf(e,n,t){let o=new Map;return r=>{let s=nn(r[0]),i=nn(r[1]),c=`${s},${i}`,a=o.get(c);if(a)return[a[0],a[1],a[2]];let l=or(e,or(St(n,s),St(t,i))),u=[nr(l[0]),nr(l[1]),nr(l[2])];return o.set(c,u),[u[0],u[1],u[2]]}}function ff(e,n,t,o,r){let s=t[0]?.a;if(!s)return null;let i=Ct(Rn(r,St(o,Ln(r,o))));if(!i)return null;let c=Ct(Di(o,i));if(!c)return null;let a=[],l=[];for(let y of t){let b=wi(y.a,s,i,c),x=wi(y.b,s,i,c);Math.hypot(b[0]-x[0],b[1]-x[1])<=1e-7||(a.push({a:b,b:x}),l.push(b[0],x[0]))}let u=nf(l);if(a.length<3||u.length<2)return null;let f=n[e[0]].color,d=ju(e,n),m=Ku(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,S=a.filter(C=>{let T=Math.min(C.a[0],C.b[0]),A=Math.max(C.a[0],C.b[0]);return T<P&&P<A&&Math.abs(C.a[0]-C.b[0])>1e-7}).map(C=>({segment:C,yMid:Mt(C,P)})).sort((C,T)=>C.yMid-T.yMid);if(S.length!==0){if(S.length%2!==0)return null;for(let C=0;C<S.length;C+=2){let T=S[C].segment,A=S[C+1].segment,M=Mt(T,b),E=Mt(T,x),v=Mt(A,b),I=Mt(A,x),_=sr([[b,M],[x,E],[x,I],[b,v]]);if(_.length<3||Math.abs(no(_))<=1e-8)continue;let O=no(_)>0?_:[..._].reverse();p.push(O)}}}if(p.length===0||e.length>2&&p.length>e.length*$u)return null;let h=uf(s,i,c),g=lf(p).map(y=>({vertices:y.map(h),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return an(g)}function mf(e,n,t){let o=Zu(e,n);if(!o||o.length<3||!qu(o))return null;let r=ki(n[e[0]]);if(!r)return null;let s=null;for(let i of ef(o,r.normal,t)){let c=ff(e,n,o,r.normal,i);c&&(!s||c.length<s.length)&&(s=c)}return!s||s.length>=e.length?null:s}function ir(e,n={}){let t=n.minGroupPolygons??Fu,o=n.maxCandidateAxes??Bu,r=n.planeEpsilon??ku,s=e??[];if(s.length<t)return s;let{groups:i}=Hu(s,r);if(i.length===0)return s;let c=new Map,a=new Set;for(let u of i){if(u.length<t)continue;let f=mf(u,s,o);if(f){c.set(u[0],f);for(let d of u)a.add(d)}}if(c.size===0)return s;let l=[];for(let u=0;u<s.length;u++){let f=c.get(u);if(f){l.push(...f);continue}a.has(u)||l.push(s[u])}return l}function df(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 pf(e){if(e.length<100)return!1;let n=new Map;for(let o of e){let r=o.vertices;for(let s=0;s<r.length;s++){let i=df(r[s],r[(s+1)%r.length]);n.set(i,(n.get(i)??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 gf(e,n,t){let o=Math.abs(e)>.9?0:1,r=Math.abs(e)>.9?1:0,s=r*t,i=-o*t,c=o*n-r*e,a=Math.hypot(s,i,c);return s/=a,i/=a,c/=a,{ux:s,uy:i,uz:c,vx:n*c-t*i,vy:t*s-e*c,vz:e*i-n*s}}function hf(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[H,K,Q]of n)t+=H,o+=K,r+=Q;let s=1/n.length;t*=s,o*=s,r*=s;let i=n[0],c=n[1],a=n[2],l=c[0]-i[0],u=c[1]-i[1],f=c[2]-i[2],d=a[0]-i[0],m=a[1]-i[1],p=a[2]-i[2],h=u*p-f*m,g=f*d-l*p,y=l*m-u*d,b=Math.hypot(h,g,y);if(b<1e-9)return null;h/=b,g/=b,y/=b;let{ux:x,uy:P,uz:S,vx:C,vy:T,vz:A}=gf(h,g,y),M=n.length-2,E=new Float64Array(M*9),v=0;for(let H=1;H<n.length-1;H++){let K=n[0],Q=n[H],ne=n[H+1];E[v++]=K[0],E[v++]=K[1],E[v++]=K[2],E[v++]=Q[0],E[v++]=Q[1],E[v++]=Q[2],E[v++]=ne[0],E[v++]=ne[1],E[v++]=ne[2]}let I=0,_=1/0,O=1/0,V=1/0,w=-1/0,F=-1/0,D=-1/0;for(let[H,K,Q]of n){let ne=H-t,ee=K-o,ue=Q-r,U=ne*ne+ee*ee+ue*ue;U>I&&(I=U),H<_&&(_=H),H>w&&(w=H),K<O&&(O=K),K>F&&(F=K),Q<V&&(V=Q),Q>D&&(D=Q)}return{centroid:[t,o,r],normal:[h,g,y],vertices:n,triFlat:E,bcx:t,bcy:o,bcz:r,br2:I,ux:x,uy:P,uz:S,vx:C,vy:T,vz:A,minX:_,minY:O,minZ:V,maxX:w,maxY:F,maxZ:D}}function yf(e,n,t,o,r,s,i,c){let a=i[c],l=i[c+1],u=i[c+2],f=i[c+3]-a,d=i[c+4]-l,m=i[c+5]-u,p=i[c+6]-a,h=i[c+7]-l,g=i[c+8]-u,y=r*g-s*h,b=s*p-o*g,x=o*h-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let S=1/P,C=e-a,T=n-l,A=t-u,M=S*(C*y+T*b+A*x);if(M<0||M>1)return!1;let E=T*m-A*d,v=A*f-C*m,I=C*d-T*f,_=S*(o*E+r*v+s*I);return _<0||M+_>1?!1:S*(p*E+h*v+g*I)>.001}function bf(e,n,t,o,r,s,i){let c=i.bcx-e,a=i.bcy-n,l=i.bcz-t,u=c*o+a*r+l*s,f=c-u*o,d=a-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,h=p.length;for(let g=0;g<h;g+=9)if(yf(e,n,t,o,r,s,p,g))return!0;return!1}var Et=9,xf=6,ke=8;function ar(e,n,t,o,r,s){let i=o-e,c=r-n,a=s-t;return i*c+c*a+a*i}function Pf(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),s=new Float64Array(t),i=new Float64Array(t);for(let C=0;C<t;C++){let T=e[o[C]];r[C]=(T.minX+T.maxX)*.5,s[C]=(T.minY+T.maxY)*.5,i[C]=(T.minZ+T.maxZ)*.5}let c=2*Math.max(1,t)+1,a=new Float64Array(c*Et),l=0,u=new Float64Array(ke),f=new Float64Array(ke),d=new Float64Array(ke),m=new Float64Array(ke),p=new Float64Array(ke),h=new Float64Array(ke),g=new Int32Array(ke),y=new Float64Array(ke-1),b=new Int32Array(ke-1),x=new Float64Array(ke-1),P=new Int32Array(ke-1);function S(C,T){let A=l++,M=A*Et,E=T-C,v=1/0,I=1/0,_=1/0,O=-1/0,V=-1/0,w=-1/0;for(let G=C;G<T;G++){let te=e[o[G]];te.minX<v&&(v=te.minX),te.maxX>O&&(O=te.maxX),te.minY<I&&(I=te.minY),te.maxY>V&&(V=te.maxY),te.minZ<_&&(_=te.minZ),te.maxZ>w&&(w=te.maxZ)}if(a[M]=v,a[M+1]=I,a[M+2]=_,a[M+3]=O,a[M+4]=V,a[M+5]=w,E<=xf)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let F=1/0,D=1/0,H=1/0,K=-1/0,Q=-1/0,ne=-1/0;for(let G=C;G<T;G++)r[G]<F&&(F=r[G]),r[G]>K&&(K=r[G]),s[G]<D&&(D=s[G]),s[G]>Q&&(Q=s[G]),i[G]<H&&(H=i[G]),i[G]>ne&&(ne=i[G]);let ee=K-F,ue=Q-D,U=ne-H;if(ee===0&&ue===0&&U===0)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let $=ar(v,I,_,O,V,w),k=$>0?1/$:0,L=E+1,W=0,Y=0;for(let G=0;G<3;G++){let te=G===0?F:G===1?D:H,ce=G===0?ee:G===1?ue:U;if(ce===0)continue;let ye=G===0?r:G===1?s:i,he=ke/ce;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),h.fill(-1/0),g.fill(0);for(let N=C;N<T;N++){let X=(ye[N]-te)*he|0;X>=ke&&(X=ke-1);let oe=e[o[N]];oe.minX<u[X]&&(u[X]=oe.minX),oe.maxX>m[X]&&(m[X]=oe.maxX),oe.minY<f[X]&&(f[X]=oe.minY),oe.maxY>p[X]&&(p[X]=oe.maxY),oe.minZ<d[X]&&(d[X]=oe.minZ),oe.maxZ>h[X]&&(h[X]=oe.maxZ),g[X]++}let be=1/0,ge=1/0,Se=1/0,De=-1/0,R=-1/0,z=-1/0,j=0;for(let N=0;N<ke-1;N++)u[N]<be&&(be=u[N]),m[N]>De&&(De=m[N]),f[N]<ge&&(ge=f[N]),p[N]>R&&(R=p[N]),d[N]<Se&&(Se=d[N]),h[N]>z&&(z=h[N]),j+=g[N],y[N]=ar(be,ge,Se,De,R,z),b[N]=j;let J=1/0,le=1/0,re=1/0,pe=-1/0,xe=-1/0,ie=-1/0,ae=0;for(let N=ke-2;N>=0;N--){let X=N+1;u[X]<J&&(J=u[X]),m[X]>pe&&(pe=m[X]),f[X]<le&&(le=f[X]),p[X]>xe&&(xe=p[X]),d[X]<re&&(re=d[X]),h[X]>ie&&(ie=h[X]),ae+=g[X],x[N]=ar(J,le,re,pe,xe,ie),P[N]=ae}for(let N=0;N<ke-1;N++){if(b[N]===0||P[N]===0)continue;let X=.125+(y[N]*b[N]+x[N]*P[N])*k;X<L&&(L=X,W=G,Y=te+(N+1)/he)}}let se=W===0?r:W===1?s:i,Z=C,B=T-1;for(;Z<=B;)if(se[Z]<Y)Z++;else{let G=o[Z];o[Z]=o[B],o[B]=G;let te=r[Z];r[Z]=r[B],r[B]=te;let ce=s[Z];s[Z]=s[B],s[B]=ce;let ye=i[Z];i[Z]=i[B],i[B]=ye,B--}let q=Z;(q===C||q===T)&&(q=C+T>>1),a[M+6]=0;let me=S(C,q),fe=S(q,T);return a[A*Et+7]=me,a[A*Et+8]=fe,A}return t>0&&S(0,t),{data:a,nodeCount:l,polyIndices:o,meta:e}}function cr(e,n,t,o,r,s,i,c,a){if(c.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=c,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,h=0;for(a[h++]=0;h>0;){let y=a[--h]*Et,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,S=b<x?x:b,C=(l[y+1]-n)*m,T=(l[y+4]-n)*m,A=C<T?C:T,M=C<T?T:C;if(P>M||A>S)continue;A>P&&(P=A),M<S&&(S=M);let E=(l[y+2]-t)*p,v=(l[y+5]-t)*p,I=E<v?E:v,_=E<v?v:E;if(!(P>_||I>S)&&(_<S&&(S=_),!(S<.001)))if(l[y+6]===1){let O=l[y+7]|0,V=l[y+8]|0;for(let w=O;w<V;w++){let F=u[w];if(F===i)continue;let D=f[F];if(D&&bf(e,n,t,o,r,s,D))return!0}}else a[h++]=l[y+7]|0,a[h++]=l[y+8]|0}return!1}function Mf(e){let n=zi.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 s=(r+.5)/e,i=Math.sqrt(Math.max(0,1-s*s)),c=2*Math.PI*(r/t);o[r*3]=i*Math.cos(c),o[r*3+1]=i*Math.sin(c),o[r*3+2]=s}return zi.set(e,o),o}var zi=new Map;function fn(e,n){let t=n?.samples??8;if(e.length<4||t<1||!n?.force&&pf(e))return e;let o=Math.max(1,Math.ceil(t*(n?.minEscapeRatio??1/t))),r=e.map(hf),s=Mf(t),i=[],c=Pf(r),a=new Int32Array(Math.max(64,c.nodeCount)),l=192,u=new Float64Array(l);for(let f=0;f<e.length;f++){let d=r[f];if(!d){i.push(e[f]);continue}let m=d.normal[0],p=d.normal[1],h=d.normal[2],g=.001*m,y=.001*p,b=.001*h;{let V=d.centroid[0]+g,w=d.centroid[1]+y,F=d.centroid[2]+b;if(!cr(V,w,F,m,p,h,f,c,a)){i.push(e[f]);continue}}let{ux:x,uy:P,uz:S,vx:C,vy:T,vz:A}=d,M=d.centroid[0],E=d.centroid[1],v=d.centroid[2],I=d.vertices,_=I.length,O=0;u[O++]=M+g,u[O++]=E+y,u[O++]=v+b;for(let V=0;V<_;V++){let w=I[V];u[O++]=w[0]+(M-w[0])*.08+g,u[O++]=w[1]+(E-w[1])*.08+y,u[O++]=w[2]+(v-w[2])*.08+b}for(let V=0;V<_;V++){let w=I[V],F=I[(V+1)%_],D=(w[0]+F[0])*.5,H=(w[1]+F[1])*.5,K=(w[2]+F[2])*.5;u[O++]=D+(M-D)*.08+g,u[O++]=H+(E-H)*.08+y,u[O++]=K+(v-K)*.08+b}if(o<=1){let V=!1;e:for(let w=0;w<s.length;w+=3){let F=s[w],D=s[w+1],H=s[w+2],K=F*x+D*C+H*m,Q=F*P+D*T+H*p,ne=F*S+D*A+H*h;for(let ee=0;ee<O;ee+=3){let ue=u[ee],U=u[ee+1],$=u[ee+2];if(!cr(ue,U,$,K,Q,ne,f,c,a)){V=!0;break e}}}V&&i.push(e[f])}else{let V=0;for(let w=0;w<s.length;w+=3){let F=s[w],D=s[w+1],H=s[w+2],K=F*x+D*C+H*m,Q=F*P+D*T+H*p,ne=F*S+D*A+H*h;for(let ee=0;ee<O;ee+=3){let ue=u[ee],U=u[ee+1],$=u[ee+2];if(!cr(ue,U,$,K,Q,ne,f,c,a)){V++;break}}}V>=o&&i.push(e[f])}}return i}var Hi={overlapPx:1.25,maxGapPx:14,capacityScale:1},Zi={budget:40};function wn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function Qn(e){return typeof e=="number"?{overlapPx:Math.max(0,e)*.175,maxGapPx:14,capacityScale:1}:{overlapPx:Math.max(0,wn(e?.overlapPx,1.25)),maxGapPx:Math.max(0,wn(e?.maxGapPx,14)),capacityScale:Math.max(0,wn(e?.capacityScale,1))}}function Jn(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function qi(e){return{rotX:wn(e?.rotX,65),rotY:wn(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(wn(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(wn(e?.budget,40))))}}function mn(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function Qi(e){return[e[1]/50,e[0]/50,e[2]/50]}function co(e){return`${e[0]},${e[1]},${e[2]}`}function Af(e,n){let t=co(e),o=co(n);return t<o?`${t}|${o}`:`${o}|${t}`}function dn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function et(e){return Math.hypot(e[0],e[1],e[2])}function _t(e){let n=et(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function It(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function oo(e,n,t,o){let r=n*Math.PI/180,s=t*Math.PI/180,i=o*Math.PI/180,[c,a,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[c,a]=[c*u-a*f,c*f+a*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[c,l]=[c*u+l*f,-c*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[a,l]=[a*u-l*f,a*f+l*u]}return[c,a,l]}function dr(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 Sf(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=dn(e[o],n),s=dn(e[o+1],n),i=dr(r,s);t[0]-=i[0],t[1]-=i[1],t[2]-=i[2]}return _t(t)}function pr(e){let n=e[0],t=Sf(e);if(!t)return null;let o=null;for(let u=0;u<e.length;u+=1){let f=dn(e[(u+1)%e.length],e[u]);if(et(f)>1e-6){o=f;break}}if(!o)return null;let r=It(o,t),s=[o[0]-r*t[0],o[1]-r*t[1],o[2]-r*t[2]],i=_t(s);if(!i)return null;let c=_t(dr(t,i));if(!c)return null;let a=e.map(u=>{let f=dn(u,n);return[It(f,i),It(f,c)]}),l=lo(a);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:i,yAxis:c,local:a,area:l}:null}function lo(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 gr(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-6)continue;let c=Math.sign(i);if(n===0)n=c;else if(c!==n)return!1}return!0}function Ji(e,n,t){let o=e[t],r=e[(t+1)%e.length],s=r[0]-o[0],i=r[1]-o[1],c=Math.hypot(s,i);if(c<=1e-6)return null;let a=n>0?1:-1;return[a*(i/c),a*(-s/c)]}function Cf(e,n){let t=Ji(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 ea(e,n){let t=e.length,o=e[n],r=e[(n+1)%t],s=r[0]-o[0],i=r[1]-o[1],c=Math.hypot(s,i);if(c<=1e-6)return 0;let a=[c*.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])*i-(d[1]-o[1])*s)/c;m>1e-6&&(l=Math.min(l,m))}Number.isFinite(l)&&a.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 h=Math.abs(s*m-i*d)/(c*p);h>1e-6&&a.push(p*h*.32)}return Math.min(...a)}function na(e){return e.map(n=>{let t=mn(n.vertices),o=pr(t),r=!hr(n)&&!!o&&gr(o.local),s=r?o.local.map((i,c)=>ea(o.local,c)):[];return{basis:o,cssPoints:t,capacities:s,patchable:r}})}function hr(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Ef(e){return e.material?.key??e.color??""}function ta(e,n,t){let o=[];for(let r=0;r<n.length;r+=1){let s=n[r];if(!(!s.patchable||!s.basis))for(let i=0;i<s.cssPoints.length;i+=1){let c=s.cssPoints[i],a=s.cssPoints[(i+1)%s.cssPoints.length],l=dn(a,c),u=et(l),f=_t(l),d=Cf(s.basis,i),m=(s.capacities[i]??0)*t;!f||!d||m<=1e-6||u<=1e-6||o.push({index:o.length,polygon:r,edge:i,key:Af(c,a),a:c,b:a,minX:Math.min(c[0],a[0]),minY:Math.min(c[1],a[1]),minZ:Math.min(c[2],a[2]),maxX:Math.max(c[0],a[0]),maxY:Math.max(c[1],a[1]),maxZ:Math.max(c[2],a[2]),length:u,dir:f,normal:s.basis.normal,outward:d,capacity:m,materialKey:Ef(e[r]),color:e[r].color})}}return o}function yr(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function ro(e,n){return et(dn(e,n))<=1e-4}function Tf(e,n){return ro(e.a,n.a)||ro(e.a,n.b)||ro(e.b,n.a)||ro(e.b,n.b)}function vf(e,n){return yr(e,n)?Tf(e,n)?"connected-facet":"true-gap":"material-boundary"}function lr(e,n,t,o,r,s){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:s,residualGapPx:Math.max(0,o.gap-s),residualTargetPx:Math.max(0,r-s)}}function $i(e,n,t,o,r){let s=Math.max(0,Math.min(n.length,Math.min(t,o))),i=Math.max(0,Math.min(n.length,Math.max(t,o)));if(r<=1e-6||i-s<=1e-6)return;let c=e[n.polygon].get(n.edge),a={start:s,end:i,amount:r};c?c.push(a):e[n.polygon].set(n.edge,[a])}function uo(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function If(e,n){let t=0,o=0,r=0;for(let s of e){s.size>0&&(r+=1),o+=s.size;for(let i of s.values())for(let c of i)t=Math.max(t,c.amount)}return{...n,patchedPolygons:r,patchedEdges:o,maxAppliedAmountPx:t}}function fo(e,n,t=!1,o=!1){let r=na(e),s=ta(e,r,n.capacityScale),i=o?[]:e.map(()=>new Map),c=uo(),a=t?[]:void 0;if(s.length===0)return{edgeRepairs:i,diagnostics:c,candidates:a};let l=new Map;for(let u of s){let f=l.get(u.key);f?f.push(u):l.set(u.key,[u])}for(let u of l.values())u.length<2||(c.exactPairs+=u.length===2?1:u.length);return _f(s,l,i,c,n,a),{edgeRepairs:i,diagnostics:o?c:If(i,c),candidates:a}}function _f(e,n,t,o,r,s){let i=r.maxGapPx,c=new Set;for(let[m,p]of n)p.length>1&&c.add(m);let a=(m,p)=>{let h=m.index<p.index?m:p,g=m.index<p.index?p:m;if(g.polygon===h.polygon||h.key===g.key&&c.has(h.key)||!s&&!yr(h,g)||!Of(h,g,i)||Math.abs(It(h.dir,g.dir))<.985)return;let y=wf(h,g,i);if(!y)return;let b=vf(h,g),x=y.gap+r.overlapPx;if(b==="material-boundary"){s?.push(lr(b,h,g,y,x,0));return}let P=x;if(P<=.25){s?.push(lr(b,h,g,y,x,0));return}let S=h.capacity*y.facingA,C=g.capacity*y.facingB,T=Math.min(S,P/2),A=Math.min(C,P/2);if(P-=T+A,P>1e-6){let M=Math.min(S-T,P);T+=M,P-=M}if(P>1e-6){let M=Math.min(C-A,P);A+=M,P-=M}s?.push(lr(b,h,g,y,x,T+A)),t.length>0&&T>1e-6&&$i(t,h,y.aStart,y.aEnd,T/y.facingA),t.length>0&&A>1e-6&&$i(t,g,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,i*2);if(e.length<=1e4){let m=[...e].sort((g,y)=>g.minX-y.minX),p=new Int32Array(m.length),h=0;for(let g=0;g+1<m.length;g+=1){let b=m[g].maxX+i,x=g+1;for(;x<m.length&&m[x].minX<=b;)x+=1;if(p[g]=x,h+=x-g-1,h>25e6)break}if(h<=2e6||h<=25e6&&Lf(e,l,i)){for(let g=0;g+1<m.length;g+=1)for(let y=g+1;y<p[g];y+=1)a(m[g],m[y]);return}}let u=new Map;for(let m of e)Vf(u,m,l,i);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 h=p+1;h<m.length;h+=1){let g=m[p],y=m[h],b=g.index<y.index?g:y,x=g.index<y.index?y:g,P=b.index*d+x.index;f.has(P)||(f.add(P),a(b,x))}}function Of(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 Xi(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function Vf(e,n,t,o){let[r,s,i,c,a,l]=oa(n,t,o);for(let u=r;u<=c;u+=1)for(let f=s;f<=a;f+=1)for(let d=i;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function oa(e,n,t){let[o,r,s]=Xi([e.minX-t,e.minY-t,e.minZ-t],n),[i,c,a]=Xi([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[o,r,s,i,c,a]}function Rf(e,n,t){let[o,r,s,i,c,a]=oa(e,n,t);return(i-o+1)*(c-r+1)*(a-s+1)}function Lf(e,n,t){let o=0,r=0;for(let s of e){let i=Rf(s,n,t);if(o+=i,i>r&&(r=i),r>8192)return!0}return o/Math.max(1,e.length)>256}function Yi(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function Wi(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 wf(e,n,t){let o=Yi(n.a,e.a,e.dir),r=Yi(n.b,e.a,e.dir),s=Math.max(0,Math.min(o,r)),i=Math.min(e.length,Math.max(o,r)),c=i-s,a=Math.min(e.length,n.length);if(c<Math.max(.75,a*.12))return null;let l=(s+i)/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,h=n.a[1]+n.dir[1]*m-f,g=n.a[2]+n.dir[2]*m-d,y=Math.hypot(p,h,g);if(y<=1e-6||y>t||y>Math.min(t,Math.max(4,a*.28)))return null;let b=1/y,x=p*b,P=h*b,S=g*b,C=e.outward[0]*x+e.outward[1]*P+e.outward[2]*S,T=-(n.outward[0]*x+n.outward[1]*P+n.outward[2]*S);if(C<.5||T<.5)return null;let A=Math.max(0,Math.min(n.length,Wi(e,s,n))),M=Math.max(0,Math.min(n.length,Wi(e,i,n)));return{gap:y,facingA:C,facingB:T,aStart:s,aEnd:i,bStart:Math.min(A,M),bEnd:Math.max(A,M)}}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 Tt(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 Nf(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let o=new Set([0,n]);for(let i of e){let c=Math.max(0,Math.min(n,i.start)),a=Math.max(0,Math.min(n,i.end));a-c<=1e-6||i.amount<=1e-6||(o.add(c),o.add(a))}let r=Array.from(o).sort((i,c)=>i-c),s=[];for(let i=0;i+1<r.length;i+=1){let c=r[i],a=r[i+1];if(a-c<=1e-6)continue;let l=(c+a)/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&&s.push({start:c,end:a,amount:f})}return s}function Df(e,n){if(n.length<3||!gr(n))return!1;let t=lo(e),o=lo(n);return Math.sign(o)===Math.sign(t)&&Math.abs(o)>=Math.abs(t)-1e-6}function Ff(e,n,t){if(n.size===0||e.vertices.length<3||hr(e))return e;let o=mn(e.vertices),r=pr(o);if(!r||!gr(r.local))return e;let s=[];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=Ji(r.local,r.area,l);if(!m||d<=1e-6)return e;let p=Nf(n.get(l),d,ea(r.local,l)*t);Tt(s,u);let h=0;for(let g of p){g.start>h+1e-6&&Tt(s,ur(u,f,d,g.start));let y=ur(u,f,d,g.start),b=ur(u,f,d,g.end);Tt(s,[y[0]+m[0]*g.amount,y[1]+m[1]*g.amount]),Tt(s,[b[0]+m[0]*g.amount,b[1]+m[1]*g.amount]),g.end<d-1e-6&&Tt(s,b),h=g.end}}let i=s[0],c=s[s.length-1];if(i&&c&&Math.hypot(i[0]-c[0],i[1]-c[1])<=1e-6&&s.pop(),!Df(r.local,s))return e;let a=s.map(([l,u])=>Qi([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:a}}function ra(e){return e.vertices.length===4&&!hr(e)}function Bf(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,o=1/0,r=-1/0,s=-1/0;for(let[a,l]of n)t=Math.min(t,a),o=Math.min(o,l),r=Math.max(r,a),s=Math.max(s,l);let i=Math.max(1e-6,(r-t)*(s-o));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/i)))*2.5}function fr(e,n){return et(dn(mn([e])[0],mn([n])[0]))}function so(e,n,t){let o=fr(e,n),r=fr(n,t),s=fr(t,e),i=Math.max(o,r,s);return i<=1e-6?0:et(dr(dn(mn([n])[0],mn([e])[0]),dn(mn([t])[0],mn([e])[0])))*.5/(i*i)}function kf(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],c=o[1]-t[1],a=r*c-s*i;if(Math.abs(a)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*c-u*i)/a;return[e[0]+f*r,e[1]+f*s]}function Uf(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=lo(e);if(Math.abs(o)<=1e-6)return null;let r=o>0?1:-1,s=[];for(let a=0;a<e.length;a+=1){let l=e[a],u=e[(a+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[a]),h=r*(d/m)*p,g=r*(-f/m)*p;s.push({a:[l[0]+h,l[1]+g],b:[u[0]+h,u[1]+g]})}let i=[],c=Math.max(2,t*4);for(let a=0;a<e.length;a+=1){let l=s[(a+e.length-1)%e.length],u=s[a],f=kf(l.a,l.b,u.a,u.b);if(!f)return null;let d=e[a],m=f[0]-d[0],p=f[1]-d[1],h=Math.hypot(m,p);i.push(h>c?[d[0]+m/h*c,d[1]+p/h*c]:f)}return i}function Gf(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=pr(mn(e));if(!t)return e;let o=Uf(t.local,n);return o?o.map(r=>Qi(Gf(t,r))):e}function zf(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[o,r,s,i]=e.vertices,c=Math.min(so(o,r,s),so(o,s,i)),a=Math.min(so(o,r,i),so(r,s,i)),l=u=>n.has(u)?.75:0;return c>=a?[{...t,vertices:io([o,r,s],[l(0),l(1),1.25])},{...t,vertices:io([o,s,i],[1.25,l(2),l(3)])}]:[{...t,vertices:io([o,r,i],[l(0),1.25,l(3)])},{...t,vertices:io([r,s,i],[l(1),l(2),1.25])}]}function ji(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 ao(e,n){let t=e[n];if(t===n)return n;let o=ao(e,t);return e[n]=o,o}function $f(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 Xf(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function Yf(e,n,t,o){let r=[];for(let[a,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!yr(u,f))continue;let d=l.filter(C=>ra(e[C.polygon]));if(d.length===0)continue;let m=d[0],p=1-Math.min(1,Math.abs(It(u.normal,f.normal))),h=Math.max(u.length,f.length);if(p<.01&&h<64)continue;let g=Math.max(...d.map(C=>Bf(n[C.polygon]))),y=d.length===2?1.18:1,b=Math.max(.08,p),x=o.viewAware?Wf(u,f,o.rotX,o.rotY):{proj:h,vr:1},P=o.viewAware?Math.max(x.proj,h*.12):h,S=o.viewAware?.18+x.vr*1.82:1;r.push({key:a,e:[co(m.a),co(m.b)],o:l,r:d,len:h,rank:P,proj:x.proj,s:P*(.58+b*2.8)*g*y*S,nr:p,sr:g,vr:x.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let s=Array.from({length:r.length},(a,l)=>l),i=new Map;for(let a=0;a<r.length;a+=1)for(let l of r[a].e){let u=i.get(l);if(u===void 0)i.set(l,a);else{let f=ao(s,u),d=ao(s,a);f!==d&&(s[d]=f)}}let c=new Map;for(let a=0;a<r.length;a+=1){let l=ao(s,a),u=c.get(l);u===void 0&&(u=c.size,c.set(l,u)),r[a].comp=u}return r}function Wf(e,n,t,o){let r=oo(e.a,t,0,o),s=oo(e.b,t,0,o),i=Math.hypot(s[0]-r[0],s[1]-r[1]),c=oo(e.normal,t,0,o)[2],a=oo(n.normal,t,0,o)[2],l=Math.max(0,c,a),u=Math.min(1,Math.abs(c-a));return{proj:i,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function jf(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 vt(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 Ki(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,s=e.rank*(.6+n*n*1.4)*t*o*r/Math.sqrt(Math.max(1,e.r.length));return Math.max(s,vt(e)*.75)}function mr(e){let n=new Set;for(let t of e)for(let o of t.r)n.add(o.polygon);return n.size}function sa(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function Kf(e,n,t){return e.s>=n||e.rank>=t}function Hf(e,n,t,o,r,s,i){let c=Math.max(0,Math.floor(t));if(c<=0||e.length===0||n==="follow-up")return{budgetLimit:c,componentBudgets:null};let a=new Map;for(let m of e){let p=a.get(m.comp);p?p.push(m):a.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 a){let h=p.filter(S=>Kf(S,s,i)||S.s>=f);if(h.length===0)continue;let g=p.filter(S=>sa(S,r)),y=mr(h),b=mr(g),x=Math.ceil(Math.sqrt(Math.max(0,b-y))*3),P=Math.min(mr(p),y+x);P<=0||(l.set(m,P),d+=P)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(c,d),componentBudgets:l}}function Zf(e,n,t){let o=new Map;if(e.length===0||t<=0)return{selected:o,budgetLimit:0};let r=ji(e.map(M=>M.s)),s=ji(e.map(M=>M.rank)),i=Math.max(1e-6,r.q3-r.q1),c=Math.min(r.max,Math.max(r.p95,r.q3+i*.85)),a=Math.min(r.max,Math.max(r.p80,r.q3+i*.15)),l=Math.min(r.max,Math.max(r.p70,r.q3)),u=Math.max(s.p97,s.median*1.8),f=Math.max(s.p88,s.median*1.35),d=Hf(e,n,t,r,s,c,u),m=d.budgetLimit;if(m<=0)return{selected:o,budgetLimit:0};let p=jf(e),h=new Set,g=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((M,E)=>vt(E)-vt(M)||E.s/Math.max(1,E.r.length)-M.s/Math.max(1,M.r.length)||E.len-M.len),S=[...e].sort((M,E)=>Ki(E)-Ki(M)||vt(E)-vt(M)||E.len-M.len),C=(M,E)=>{M.sel=!0,M.why=E,y.add(M.comp);for(let v of M.e)g.add(v);for(let v of M.r){h.add(v.polygon);let I=o.get(v.polygon);I?I.add(v.edge):o.set(v.polygon,new Set([v.edge]))}},T=(M,E)=>{let v=d.componentBudgets;if(E<=0||!v)return!0;let I=v.get(M.comp)??0;return(b.get(M.comp)??0)+E<=I},A=(M,E)=>{E<=0||!d.componentBudgets||b.set(M.comp,(b.get(M.comp)??0)+E)};for(let M of S){let E=M.r.reduce((I,_)=>I+(h.has(_.polygon)?0:1),0);if(M.cost=E,!(E>m||!T(M,E)||E>0&&m-E<x||!sa(M,s))&&(C(M,"global-outlier"),A(M,E),m-=E,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let M of P){if(M.sel)continue;let E=M.r.reduce((V,w)=>V+(h.has(w.polygon)?0:1),0);if(M.cost=E,E>m||!T(M,E)||E>0&&m-E<x)continue;let v=M.r.length===2,I=p.has(M)&&(n==="primary"||n==="follow-up"&&M.s>=a*1.08&&M.rank>=f)&&(v?M.s>=a||M.rank>=f:M.s>=a*1.18||M.rank>=f*1.12),_=v?M.s>=c||M.rank>=u:M.s>=c*1.35||M.rank>=u*1.2,O=E===0&&(v?M.s>=l||M.rank>=f:M.s>=l*1.25||M.rank>=f*1.12);if(!(!I&&!_&&!O)&&(C(M,I?"component-anchor":_?"global-outlier":"shared-polygon"),A(M,E),m-=E,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let M of P){if(M.sel)continue;let E=M.r.reduce((w,F)=>w+(h.has(F.polygon)?0:1),0);if(M.cost=E,E>1||E>m||!T(M,E))continue;let v=M.r.some(w=>h.has(w.polygon)),I=M.e.some(w=>g.has(w));if(n==="primary"&&M.r.length===1&&E===1&&(y.has(M.comp)||I||v)&&M.rank>=f*1.05&&M.nr>=.16&&M.vr<=.32){if(C(M,"local-follow-up"),A(M,E),m-=E,m<=0)return{selected:o,budgetLimit:d.budgetLimit};continue}if(M.r.length!==2)continue;let O=v&&E===1&&M.proj>=f*1.45&&M.vr<=.18;if(!I&&!O)continue;if((M.s>=l*.42||M.rank>=f*.62)&&M.s<=l*1.1&&M.proj>=24&&(C(M,"local-follow-up"),A(M,E),m-=E,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}return{selected:o,budgetLimit:d.budgetLimit}}function ia(e,n,t,o,r){let s=na(e),i=ta(e,s,n.capacityScale),c=new Map;for(let u of i){let f=c.get(u.key);f?f.push(u):c.set(u.key,[u])}let a=Yf(e,s,c,t).filter(u=>Xf(u,r)),l=Zf(a,r?"follow-up":"primary",o);return{selected:l.selected,candidates:a,budgetLimit:l.budgetLimit}}function qf(e,n){let t=[];for(let o=0;o<e.length;o+=1){let r=e[o],s=n.get(o);s&&ra(r)?t.push(...zf(r,s)):t.push(r)}return t}function Qf(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 aa(e,n,t){let o=Qn(n),r=qi(t);if(!Jn(o,n)||e.length===0)return e;let s=e,i,c=r.budget;for(let a=0;a<r.passes;a+=1){let l=ia(s,o,r,c,i);if(a===0&&(c=Math.min(c,l.budgetLimit)),l.selected.size===0)break;let u=qf(s,l.selected);if(u.length===s.length)break;if(c-=l.selected.size,c<=0){s=u;break}i=$f(l.candidates),s=u}return s}function Jf(e,n,t){let o=Qn(n),r=qi(t);if(!Jn(o,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let s=ia(e,o,r,r.budget),i=0;for(let c of s.selected.values())i+=c.size;return{candidates:s.candidates.map(Qf),selectedPolygons:s.selected.size,selectedEdges:i,addedPolygons:s.selected.size}}function ca(e,n){let t=Qn(n);if(!Jn(t,n)||e.length===0)return e;let{edgeRepairs:o}=fo(e,t);return o.some(r=>r.size>0)?e.map((r,s)=>Ff(r,o[s],t.capacityScale)):e}function em(e,n=Hi,t=Zi){if(e.length===0)return e;let o=aa(e,n,t);return ca(o,n)}function nm(e,n){let t=Qn(n);return!Jn(t,n)||e.length===0?uo():fo(e,t).diagnostics}function la(e,n){let t=Qn(n);return!Jn(t,n)||e.length===0?uo():fo(e,t,!1,!0).diagnostics}function tm(e,n){let t=Qn(n);if(!Jn(t,n)||e.length===0)return{diagnostics:uo(),candidates:[]};let o=fo(e,t,!0);return{diagnostics:o.diagnostics,candidates:o.candidates??[]}}var Nn={ratio:.7,maxError:.18,maxNormalDot:Math.cos(65*Math.PI/180),preserveVertices:!0,vertexKeyMode:"relaxed",lockBoundary:!0,minGroupTriangles:80,maxPasses:12};function om(e={}){let n=Number.isFinite(e.ratio)?Math.max(.05,Math.min(.98,e.ratio)):Nn.ratio,t=Number.isFinite(e.maxError)&&e.maxError>0?e.maxError:Nn.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??Nn.preserveVertices,vertexKeyMode:e.vertexKeyMode??Nn.vertexKeyMode,lockBoundary:e.lockBoundary??Nn.lockBoundary,minGroupTriangles:Math.max(3,Math.floor(e.minGroupTriangles??Nn.minGroupTriangles)),maxPasses:Math.max(1,Math.floor(e.maxPasses??Nn.maxPasses))}}function rm(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function sm(e){return e.vertices.length===3&&!rm(e)}function im(e){return[e.color??"",e.doubleSided===!0?"2":"1",e.material?.key??""].join("\0")}function ua(e){return`${Math.round(e[0]*1e5)},${Math.round(e[1]*1e5)},${Math.round(e[2]*1e5)}`}function am(e,n,t,o){let r=o.vertexKeyMode==="source"?e.simplifySourceVertexKeys?.[t]??e.simplifyVertexKeys?.[t]:e.simplifyVertexKeys?.[t];return r?`${ua(n)}|${r}`:ua(n)}function cm(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function nt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function lm(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function br(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function fa(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 Mr(e){return Math.hypot(e[0],e[1],e[2])}function xr(e,n){return Mr(nt(e,n))}function um(e){let n=Mr(e);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n]:[0,0,1]}function Ar(e,n,t,o){return um(fa(nt(e[t],e[n]),nt(e[o],e[n])))}function ma(e,n,t,o){return Mr(fa(nt(e[t],e[n]),nt(e[o],e[n])))/2}function fm(){return[0,0,0,0,0,0,0,0,0,0]}function mo(e,n){for(let t=0;t<e.length;t+=1)e[t]+=n[t]}function mm(e,n,t){let o=e[0],r=e[1],s=e[2],i=-br(e,n);return[o*o*t,o*r*t,o*s*t,o*i*t,r*r*t,r*s*t,r*i*t,s*s*t,s*i*t,i*i*t]}function Pr(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 dm(e,n,t,o,r,s,i,c,a,l,u,f){let d=e*(r*a-s*c)-n*(o*a-s*i)+t*(o*c-r*i);if(Math.abs(d)<1e-10)return null;let m=1/d,p=l*(r*a-s*c)-n*(u*a-s*f)+t*(u*c-r*f),h=e*(u*a-s*f)-l*(o*a-s*i)+t*(o*f-u*i),g=e*(r*f-u*c)-n*(o*f-u*i)+l*(o*c-r*i),y=[p*m,h*m,g*m];return y.every(Number.isFinite)?y:null}function pm(e,n,t,o){let r=dm(e[0],e[1],e[2],e[1],e[4],e[5],e[2],e[5],e[7],-e[3],-e[6],-e[8]),s=lm(cm(n,t),.5),i=xr(n,t)*1.35,c=o?[n,t]:[n,t,s,...r&&xr(r,s)<=i?[r]:[]],a=c[0],l=Pr(e,a);for(let u=1;u<c.length;u+=1){let f=c[u],d=Pr(e,f);d<l&&(a=f,l=d)}return a}function gm(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function hm(e,n,t){return`${e}|${n}|${t}`}function ym(e,n){let t=new Map,o=[],r=[];for(let s of e){let i=[];for(let u=0;u<s.vertices.length;u+=1){let f=s.vertices[u],d=am(s,f,u,n),m=t.get(d);m===void 0&&(m=o.length,t.set(d,m),o.push([...f])),i.push(m)}let[c,a,l]=i;c===void 0||a===void 0||l===void 0||c===a||c===l||a===l||r.push({a:c,b:a,c:l,polygon:s,normal:Ar(o,c,a,l)})}return{vertices:o,triangles:r}}function bm(e,n){let t=ym(e,n),o=Array.from({length:t.vertices.length},()=>new Set),r=Array.from({length:t.triangles.length},()=>!0);for(let s=0;s<t.triangles.length;s+=1){let i=t.triangles[s];o[i.a].add(s),o[i.b].add(s),o[i.c].add(s)}return{vertices:t.vertices,triangles:t.triangles,alive:r,vertexTriangles:o,activeCount:t.triangles.length}}function xm(e){let n=new Map,t=(o,r,s)=>{let i=gm(o,r),c=n.get(i);c?c.triangles.push(s):n.set(i,{a:Math.min(o,r),b:Math.max(o,r),triangles:[s]})};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 Pm(e){let n=Array.from({length:e.vertices.length},()=>fm());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,ma(e.vertices,o.a,o.b,o.c)),s=mm(o.normal,e.vertices[o.a],Math.sqrt(r));mo(n[o.a],s),mo(n[o.b],s),mo(n[o.c],s)}return n}function Mm(e,n,t){let o=new Set,r=s=>{let i=e.vertexTriangles[s];if(i)for(let c of i)e.alive[c]&&o.add(c)};return r(n),r(t),Array.from(o).sort((s,i)=>s-i)}function Am(e,n,t){let o=e.vertexTriangles[n],r=e.vertexTriangles[t];if(!o||!r)return 0;let[s,i]=o.size<=r.size?[o,r]:[r,o],c=0;for(let a of s)e.alive[a]&&i.has(a)&&(c+=1);return c}function da(e,n,t){return[e.a===t?n:e.a,e.b===t?n:e.b,e.c===t?n:e.c]}function Sm(e,n,t){if(Am(e,n.a,n.b)!==2)return null;let o=Mm(e,n.a,n.b);if(o.length===0)return null;let r=e.vertices[n.a];e.vertices[n.a]=n.target;let s=0,i=!0;for(let c of o){let a=e.triangles[c],[l,u,f]=da(a,n.a,n.b);if(l===u||l===f||u===f)continue;if(ma(e.vertices,l,u,f)<=1e-8){i=!1;break}let m=Ar(e.vertices,l,u,f);if(br(a.normal,m)<t.maxNormalDot){i=!1;break}let p=a.a===n.a?r:e.vertices[a.a];if(Math.abs(br(a.normal,nt(n.target,p)))>t.maxError){i=!1;break}s+=1}return e.vertices[n.a]=r,i&&s>0?o:null}function Cm(e,n,t){e.vertexTriangles[t.a]?.delete(n),e.vertexTriangles[t.b]?.delete(n),e.vertexTriangles[t.c]?.delete(n)}function Em(e,n,t){e.vertexTriangles[t.a].add(n),e.vertexTriangles[t.b].add(n),e.vertexTriangles[t.c].add(n)}function Tm(e,n,t){e.vertices[n.a]=n.target;let o=new Set;for(let r of t){if(!e.alive[r])continue;let s=e.triangles[r],[i,c,a]=da(s,n.a,n.b);if(Cm(e,r,s),i===c||i===a||c===a){e.alive[r]=!1,e.activeCount-=1;continue}let l=hm(i,c,a);if(o.has(l)){e.alive[r]=!1,e.activeCount-=1;continue}o.add(l);let u={...s,a:i,b:c,c:a,normal:Ar(e.vertices,i,c,a)};e.triangles[r]=u,Em(e,r,u)}}function vm(e,n){let t=xm(e),o=new Set;for(let c of t.values())c.triangles.length>2&&(o.add(c.a),o.add(c.b));if(n.lockBoundary)for(let c of t.values())c.triangles.length===1&&(o.add(c.a),o.add(c.b));let r=Pm(e),s=n.maxError*n.maxError,i=[];for(let c of t.values()){if(c.triangles.length!==2||o.has(c.a)||o.has(c.b))continue;let a=[...r[c.a]];mo(a,r[c.b]);let l=pm(a,e.vertices[c.a],e.vertices[c.b],n.preserveVertices),u=Math.max(0,Pr(a,l));if(u>s*Math.max(1,c.triangles.length))continue;let f=xr(e.vertices[c.a],e.vertices[c.b]);i.push({a:c.a,b:c.b,target:l,error:u,length:f})}return i.sort((c,a)=>c.error-a.error||c.length-a.length),i}function Im(e){let n=[];for(let t=0;t<e.triangles.length;t+=1)e.alive[t]&&n.push(e.triangles[t]);return n}function _m(e,n){if(e.length<n.minGroupTriangles)return e;let t=bm(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 s=0;for(let i=0;i<n.maxPasses&&t.activeCount>r;i+=1){let c=vm(t,n);if(c.length===0)break;let a=0;for(let l of c){if(t.activeCount<=r)break;let u=Sm(t,l,n);if(!u)continue;let f=t.activeCount;Tm(t,l,u),!(t.activeCount>=f)&&(s+=1,a+=1)}if(a===0)break}return s===0||t.activeCount>=o?e:Im(t).map(i=>({...i.polygon,vertices:[[...t.vertices[i.a]],[...t.vertices[i.b]],[...t.vertices[i.c]]]}))}function Om(e){let n=new Map;for(let t=0;t<e.length;t+=1){let o=e[t];if(!sm(o))continue;let r=im(o),s=n.get(r);s?(s.indices.push(t),s.polygons.push(o)):n.set(r,{indices:[t],polygons:[o]})}return n}function Sr(e,n){let t=om(n),o=Om(e);if(o.size===0)return e;let r=new Map,s=!1;for(let c of o.values()){let a=_m(c.polygons,t);if(!(a===c.polygons||a.length>=c.polygons.length)){r.set(c.indices[0],a);for(let l=1;l<c.indices.length;l+=1)r.set(c.indices[l],[]);s=!0}}if(!s)return e;let i=[];for(let c=0;c<e.length;c+=1){let a=r.get(c);a?i.push(...a):a===void 0&&i.push(e[c])}return i}var Vm=3,Rm=.03,Lm=.02,Ot={maxAngleDeg:Vm,maxPlaneDisplacement:Rm,maxBoundaryDisplacement:Lm,isolatedPairs:!1},po={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},Cr=[{...po,maxAngleDeg:30},{...po,maxAngleDeg:45},{...po,maxAngleDeg:60,maxBoundaryDisplacement:.06}],wm=1800,Nm=.65,pa=500,ga=2200,Dm=1e3,Fm=2200,Bm=350,km=700,Um=60,Gm=.06,zm=4,$m=.003,Xm=4e3,Ym=3e3,Wm=4500,jm=2400,Km=4200,Hm=1800,Zm=5e3,qm=.28,Qm=.15,Jm=.23,ed=2e3,nd=16,td=4e3,od=900,rd=16,sd=1.5,Tr=.045,id=.999,ad=1e-5,cd=24,ld=50,ud=1e3,fd=1e3,Fn={minGroupPolygons:2,maxCandidateAxes:24},md={...Fn,maxCandidateAxes:1},ha={...Fn,maxCandidateAxes:2},dd={...Fn,maxCandidateAxes:2},pd={steps:[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"},{kind:"finalLossyCandidates"}]};function gd(e,n={}){return hd(e,n).polygons}function Ma(e,n={}){let t={meshResolution:n.meshResolution,stopAtPolygonCount:n.stopAtPolygonCount,rectCover:n.rectCover},o=new go,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 hd(e,n={},t={}){return new go().workspaceFor(e,t).createRun(n,t).optimize()}var go=class{constructor(){this.workspaces=new Map}workspaceFor(n,t){let o=yd(t),r=this.workspaces.get(o);r||(r=new WeakMap,this.workspaces.set(o,r));let s=r.get(n);return s||(s=new vr(n,t,this),r.set(n,s)),s}};function yd(e){return[e.skipInteriorCull===!0?"skip-cull":"cull",e.simplifiedCandidate===!0?"simplified":"source"].join(":")}var vr=class{constructor(n,t,o){this.source=n,this.graph=o,this.preprocessCache={skipInteriorCull:t.skipInteriorCull===!0}}polygons(){return this.source}preprocess(n){return Gd(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<=Km:n.length<=Hm||n.length<=Zm&&o>=qm}visiblePolygons(){return this.preprocessCache.interior??this.preprocessCache.deduped??this.source}createRun(n,t){return new Ir(this,n,t)}workspaceFor(n,t){return this.graph.workspaceFor(n,t)}},Ir=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 _r(this.baseline,this.requiredMaxPolygonCount)}optimize(){return this.runPlan(pd)}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"||!Rd(this.source,this.best))return!1;let t=Sa(this.source,n);if(!t)return!1;for(let o of this.staticSimplificationPlans(t)){let r=Ld(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>=td&&r>=od&&(t<=rd||r>=t*sd)&&o.push({source:this.visiblePolygons,skipInteriorCull:!0}),this.best.length>=ed&&t<=nd&&Vd(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},s=this.workspace.workspaceFor(n,r),i=this.best;return new e(s,{meshResolution:"lossy",stopAtPolygonCount:Od(this.best.length,t)},r,{acceptor:this.acceptor,costCandidateMode:"dom",seamCandidateMode:"dom",offerBaseline:!0}).optimize(),this.best!==i}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?Nd(this.baseline):this.options.rectCover;if(this.shouldStop())return;let t=Dn(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=Dn(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(po);this.acceptCandidate(n),!this.shouldStop()&&(this.options.rectCover===void 0&&this.source.length>=pa&&this.source.length<=ga&&(this.acceptCandidate(Dn(n,ha)),this.shouldStop())||this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(this.acceptCandidate(Dn(n,this.options.rectCover)),this.shouldStop()))}runFinalLossyPipeline(){this.finalLossyCandidatesComplete||(this.finalLossyCandidatesComplete=!0,!(this.runOptions.simplifiedCandidate===!0&&this.source.length>Wm)&&(this.runAggressiveLossyVariants(),!this.shouldStop()&&this.runLargeRectCoverCandidate()))}runAggressiveLossyVariants(){let n=this.stopAtPolygonCount===void 0&&this.source.length>=Xm&&this.best.length<=Ym,t=!1;for(let o=n?Cr.length:0;o<Cr.length;o+=1){if(o===1&&!t||o===1&&this.runOptions.simplifiedCandidate===!0&&this.source.length<jm||o===2&&!Fd(this.source))continue;let r=this.preprocess(Cr[o]),s=r;this.options.rectCover===void 0&&this.source.length>=pa&&this.source.length<=ga&&(s=Dn(r,ha)),this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(s=Dn(r,this.options.rectCover));let i=this.acceptSeamSafeCandidate(s,this.source.length);if(o===0&&i&&(t=!0),this.shouldStop())return}}runLargeRectCoverCandidate(){if(this.options.rectCover!==void 0)return;let n=Dn(this.best,Dd(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=Bn(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})}},_r=class{constructor(n,t){this.best=n,this.bestCost=Bn(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=Bn(n)){return t>=this.bestCost?!1:(this.commit(n,t),!0)}acceptDomCandidate(n,t=Bn(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 s=_d(t);if(this.bestCost-n.length<s)return!1;let i=o??Bn(n),c=this.bestCost-i;if(c<=0||c<s)return!1;let a=ya(n);if(!a)return!1;let l=this.bestSeamDiagnostics();return!l||bd(a,l)||xd(this.bestTopologyEdges(),this.bestTopologySelfDiagnostics(),n)?!1:(this.commit(n,i,a),!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=ya(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=Aa(this.best)),this.bestDiagnostics.topologyEdges}bestTopologySelfDiagnostics(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologySelf||(this.bestDiagnostics.topologySelf=Sd(this.bestTopologyEdges(),Tr)),this.bestDiagnostics.topologySelf}};function Bn(e){let n=0;for(let t of e){let o=t.vertices.length,r=o<=4?0:Math.min(4,o-4)*.12,s=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+r+s}return n}function ya(e){try{return la(e)}catch(n){if(n instanceof RangeError&&n.message==="Set maximum size exceeded")return null;throw n}}function bd(e,n){return e.nearPairs>n.nearPairs||e.unclosedPairs>n.unclosedPairs||e.maxMeasuredGapPx>n.maxMeasuredGapPx+1e-9||e.maxResidualGapPx>n.maxResidualGapPx+1e-9}function xd(e,n,t){let o=Aa(t);return Pd(e,o,Tr)?!0:Ad(o.boundarySegments,Tr,n)}function Pd(e,n,t){if(e.internalSegments.length===0)return!1;let o=Md(e,t);for(let r of n.boundarySegments)if(!e.boundaryKeys.has(r.key)&&(e.internalKeys.has(r.key)||vd(r,o,t)))return!0;return!1}function Md(e,n){return(!e.internalIndex||e.internalIndexTolerance!==n)&&(e.internalIndex=Rr(e.internalSegments,n),e.internalIndexTolerance=n),e.internalIndex}function Ad(e,n,t){let o=Rr(e,n),r=new Set,s=0,i=0,c=0;for(let a of e)s=Math.max(s,a.index+1);for(let a of e)for(let l of Lr(a,o,n)){if(l===a||l.polygon===a.polygon||l.key===a.key)continue;let u=a.index<l.index?a.index*s+l.index:l.index*s+a.index;if(r.has(u))continue;r.add(u);let f=wr(a,l,n);if(f&&(i+=1,c+=f.overlapLength,i>t.tJunctionPairs||c>t.tJunctionLength+1e-9))return!0}return!1}function Sd(e,n){let t={tJunctionPairs:0,tJunctionLength:0};return Cd(t,e.boundarySegments,n),t}function Cd(e,n,t){let o=Rr(n,t),r=new Set,s=0;for(let i of n)s=Math.max(s,i.index+1);for(let i of n)for(let c of Lr(i,o,t)){if(c===i||c.polygon===i.polygon||c.key===i.key)continue;let a=i.index<c.index?i.index*s+c.index:c.index*s+i.index;if(r.has(a))continue;r.add(a);let l=wr(i,c,t);l&&(e.tJunctionPairs+=1,e.tJunctionLength+=l.overlapLength)}}function Aa(e){let n=new Map;for(let a=0;a<e.length;a+=1){let l=e[a].vertices;for(let u=0;u<l.length;u+=1){let f=l[u],d=l[(u+1)%l.length],m=Ed(Lt(f,d),a,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=[],s=[],i=0,c=0;for(let a of n.values()){let l={...a.segment,index:c};c+=1,a.count===1?(t.add(l.key),r.push(l),i+=l.length):(o.add(l.key),s.push(l))}return{boundaryKeys:t,internalKeys:o,boundarySegments:r,internalSegments:s,boundaryLength:i}}function Ed(e,n,t,o,r){let s=pn(r,o),i=Math.hypot(s[0],s[1],s[2]);if(i<=1e-10)return null;let c=[s[0]/i,s[1]/i,s[2]/i];return{index:-1,key:e,polygon:n,edge:t,a:o,b:r,dir:c,length:i,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 Rr(e,n){let t=Math.max(n*8,.5),o=new Map;for(let r of e)Td(o,r,t,n);return{cellSize:t,cells:o}}function Td(e,n,t,o){let[r,s,i]=ho([n.minX-o,n.minY-o,n.minZ-o],t),[c,a,l]=ho([n.maxX+o,n.maxY+o,n.maxZ+o],t);for(let u=r;u<=c;u+=1)for(let f=s;f<=a;f+=1)for(let d=i;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function ho(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function Lr(e,n,t){let o=[],r=new Set,[s,i,c]=ho([e.minX-t,e.minY-t,e.minZ-t],n.cellSize),[a,l,u]=ho([e.maxX+t,e.maxY+t,e.maxZ+t],n.cellSize);for(let f=s;f<=a;f+=1)for(let d=i;d<=l;d+=1)for(let m=c;m<=u;m+=1){let p=n.cells.get(`${f},${d},${m}`);if(p)for(let h of p)r.has(h)||(r.add(h),o.push(h))}return o}function vd(e,n,t){for(let o of Lr(e,n,t))if(wr(e,o,t))return!0;return!1}function wr(e,n,t){if(!Id(e,n,t)||Math.abs(Ke(e.dir,n.dir))<id)return null;let o=Ke(pn(n.a,e.a),e.dir),r=Ke(pn(n.b,e.a),e.dir),s=Math.max(0,Math.min(o,r)),i=Math.min(e.length,Math.max(o,r)),c=i-s;if(c<=Math.max(ad,Math.min(e.length,n.length)*1e-4))return null;let a=[e.a[0]+e.dir[0]*((s+i)/2),e.a[1]+e.dir[1]*((s+i)/2),e.a[2]+e.dir[2]*((s+i)/2)],l=Math.max(0,Math.min(n.length,Ke(pn(a,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=Fa(a,u);return f<=t?{overlapLength:c,offset:f}:null}function Id(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 _d(e){return Math.max(zm,e*$m)}function Od(e,n){let t=Number.isFinite(n.earlyStopDropRatio)?Math.max(0,n.earlyStopDropRatio):Qm;return Math.max(0,e-Math.max(1,Math.ceil(e*t)))}function Vd(e){return e.some(n=>n.simplifySourceVertexKeys?.length===n.vertices.length)}function Rd(e,n){return e.length===0||n.length/e.length>Jm}function Sa(e,n,t){let o=Sr(e,{...n.simplifyTriangleMeshOptions,...t?{vertexKeyMode:t}:{}});return o===e||o.length>=e.length?null:o}function Ld(e,n){return e.precomputed!==void 0?e.precomputed:Sa(e.source,n,e.vertexKeyMode)}function Dn(e,n){if(n===!1)return e;let t=wd(e,n);if(!t)return e;let o=ir(e,t);return o.length<e.length?o:e}function wd(e,n){if(n&&n!==!0)return n;let t=n===!0,o=e.length;return o>2200||!t&&o>=cd&&o<ld||!t&&o>ud?null:!t&&o<=300?{...Fn,maxCandidateAxes:1}:o>300?!t&&(Ca(e)>12||Ea(e)>fd)?null:{...Fn,maxCandidateAxes:Math.min(Fn.maxCandidateAxes??24,2)}:Fn}function Nd(e){return e.length>wm||e.length===0||Bd(e)/e.length<Nm?!1:md}function Dd(e){return e.length<Dm||e.length>Fm||Ca(e)<=12||Ea(e)>Bm?!1:dd}function Fd(e){return e.length<=km}function Bd(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function Ca(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function Ea(e){let n=new Map;for(let o of e)for(let r=0;r<o.vertices.length;r++){let s=o.vertices[r],i=o.vertices[(r+1)%o.vertices.length],c=Lt(s,i);n.set(c,(n.get(c)??0)+1)}let t=0;for(let o of n.values())o===1&&(t+=1);return t}function yo(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function Or(e,n){if(n===e||n.length===e.length&&n.every((r,s)=>r===e[s]))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 kd(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let r=Jt(e);if(r.size===0)t=null;else{t=[];for(let s=0;s<e.length;s++)r.has(s)||t.push(s)}n&&(n.dedupedIndices=t)}let o=yo(e,t);return n&&(n.deduped=o),o}function Ud(e,n){if(n?.skipInteriorCull)return e;if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let r=fn(e);t=Or(e,r),n&&(n.interiorIndices=t)}let o=yo(e,t);return n&&(n.interior=o),o}function Gd(e,n,t){let o=kd(e,t),r=Ud(o,t),s=t?.baseline??an(r);if(t&&!t.baseline&&(t.baseline=s),!n)return s;let i=n===!0?Ot:$d(n);if(i.isolatedPairs){let u=xa(ba(o,t),i,t),f=an(u);if(t?.snappedInteriorUsesBaselineFilter&&zd(s,f)){let d=xa(ba(o,t,!0),i,t),m=an(d);m.length<f.length&&(f=m)}return f.length<s.length?f:s}let c=tp(o,i,t),a=fn(c),l=an(a);return l.length<s.length?l:s}function Ta(e,n){return n?(n.snapped||(n.snapped=bo(e)),n.snapped):bo(e)}function ba(e,n,t=!1){if(!n)return fn(bo(e));if(t&&n.snappedInteriorExact)return n.snappedInteriorExact;if(!t&&n.snappedInterior)return n.snappedInterior;let o=Ta(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=fn(o);return n.snappedInteriorExactIndices=Or(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=yo(o,n.snappedInteriorIndices),n.snappedInteriorUsesBaselineFilter=!0,n.snappedInterior;if(n.snappedInteriorIndices===void 0){let r=fn(o);n.snappedInteriorIndices=Or(o,r),n.snappedInterior=r,n.snappedInteriorExactIndices=n.snappedInteriorIndices,n.snappedInteriorExact=r,n.snappedInteriorUsesBaselineFilter=!1}else n.snappedInterior=yo(o,n.snappedInteriorIndices)}return n.snappedInterior}function zd(e,n){return n.length>=e.length}function $d(e){return{maxAngleDeg:e.maxAngleDeg??Ot.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??Ot.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??Ot.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??Ot.isolatedPairs}}function xa(e,n,t){let o=Xd(e,t),r=[];for(let i of Yd(e,o))Wd(i,n)&&r.push(i.candidate);let s=Kd(r);return s.length===0?e:jd(e,s)}function Xd(e,n){if(n?.trianglePairSource?.polygons===e)return n.trianglePairSource;let t=e.map(i=>{let c=Dr(i);return c?{polygon:i,normal:c.normal,area:c.area,materialKey:Ra(i)}:null}),o=new Map;for(let i=0;i<e.length;i++){let c=e[i];if(!(c.vertices.length!==3||!t[i]))for(let a=0;a<c.vertices.length;a++){let l=Lt(c.vertices[a],c.vertices[(a+1)%c.vertices.length]),u=o.get(l);u?u.push(i):o.set(l,[i])}}let r=[];for(let i of o.values())i.length===2&&r.push([i[0],i[1]]);let s={polygons:e,metas:t,edgeOwnerPairs:r};return n&&(n.trianglePairSource=s),s}function Yd(e,n){if(n.preparedCandidates)return n.preparedCandidates;let t=[];for(let[o,r]of n.edgeOwnerPairs){let s=Jd(o,r,e,n.metas);s&&t.push(s)}return n.preparedCandidates=t,t}function Wd(e,n){let t=Math.cos(n.maxAngleDeg*Math.PI/180);return e.normalDot>=t&&e.maxDistance<=Math.min(n.maxPlaneDisplacement,n.maxBoundaryDisplacement)}function jd(e,n){let t=new Map,o=new Set,r=va(n.flatMap(i=>i.vertexMoves));for(let i of n){let c=Math.min(i.a,i.b);t.set(c,i.polygon),o.add(Math.max(i.a,i.b))}let s=[];for(let i=0;i<e.length;i++){let c=t.get(i);if(c){s.push(c);continue}o.has(i)||s.push(e[i])}return r.size>0?Ia(s,r):s}function Kd(e){return e.length>3e3?Hd(e):Zd(e)}function Hd(e){let n=new Map;for(let s of e)n.set(s.a,(n.get(s.a)??0)+1),n.set(s.b,(n.get(s.b)??0)+1);let t=[...e].sort((s,i)=>{let c=(n.get(s.a)??0)+(n.get(s.b)??0),a=(n.get(i.a)??0)+(n.get(i.b)??0);return c-a||s.score-i.score}),o=new Set,r=[];for(let s of t)o.has(s.a)||o.has(s.b)||(o.add(s.a),o.add(s.b),r.push(s));return r}function Zd(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,s=new Vr;for(let[l,u]of n)r.set(l,u.length);let i=l=>(r.get(l.a)??0)+(r.get(l.b)??0),c=l=>{let u=e[l];s.push({degree:i(u),score:u.score,index:l})},a=(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++)c(l);for(;s.size()>0;){let l=s.pop();if(!o[l.index])continue;let u=e[l.index];if(i(u)!==l.degree){c(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)??[])a(p,d);for(let m of d)for(let p of n.get(m)??[])o[p]&&c(p)}return t}var Vr=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(Er(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,s=r+1,i=o;if(r<this.items.length&&Er(this.items[r],this.items[i])<0&&(i=r),s<this.items.length&&Er(this.items[s],this.items[i])<0&&(i=s),i===o)break;[this.items[o],this.items[i]]=[this.items[i],this.items[o]],o=i}}return n}};function Er(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function va(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 qd(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o].vertices,s=n[o]?.vertices;if(!s||s.length!==r.length)continue;for(let a=0;a<r.length;a++)t.push({key:tn(r[a]),target:s[a]});let i=e[o].textureTriangles??[],c=n[o]?.textureTriangles??[];for(let a=0;a<i.length;a++){let l=c[a];if(l)for(let u=0;u<i[a].vertices.length;u++)t.push({key:tn(i[a].vertices[u]),target:l.vertices[u]})}}return t}function Qd(e,n){let t=[];for(let o of e)for(let r of o.textureTriangles??[])for(let s of r.vertices)t.push({key:tn(s),target:Ur(s,n)});return t}function Ia(e,n){return e.map(t=>{let o=!1,r=c=>{let a=n.get(tn(c));return a?(o=!0,a):c},s=t.vertices.map(r),i=Nr(t.textureTriangles,r);return o?{...t,vertices:s,...i?{textureTriangles:i}:{}}:t})}function Jd(e,n,t,o){let r=t[e],s=t[n],i=o[e],c=o[n];if(!i||!c||r.vertices.length!==3||s.vertices.length!==3||!pp(r,s,i,c))return null;let a=Br(r,s);if(!a)return null;let[l,u,f,d]=a;if((f+1)%s.vertices.length===d)return null;let p=Math.abs(Ke(i.normal,c.normal)),h=Math.cos(Um*Math.PI/180);if(p<h)return null;let g=(u+1)%r.vertices.length,y=3-f-d,b=[r.vertices[u],r.vertices[g],r.vertices[l],s.vertices[y]],x=ep(b);if(!x)return null;let P=0,S=0;for(let M of b){let E=Math.abs(kr(M,x));P=Math.max(P,E),S+=E*E}if(P>Gm)return null;let C=b.map(M=>Ur(M,x));if(!np(C,x.normal))return null;let T=Dr({vertices:C});if(!T||Ke(T.normal,i.normal)<.2||Ke(T.normal,c.normal)<.2)return null;let A={vertices:b,color:r.color,...r.doubleSided?{doubleSided:!0}:{},...r.data?{data:{...r.data}}:{}};if(Fr(r,s)&&r.uvs&&s.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[g]],[...r.uvs[l]],[...s.uvs[y]]];let M=op([r,s]);M?.length&&(A.textureTriangles=M)}return{normalDot:p,maxDistance:P,candidate:{a:e,b:n,polygon:A,vertexMoves:[...b.map((M,E)=>({key:tn(M),target:C[E]})),...Qd([r,s],x)],score:S/b.length+P*.25+(1-p)*.1}}}function ep(e){if(e.length<3)return null;let n=0,t=0,o=0,r=0,s=0,i=0;for(let a=0;a<e.length;a++){let l=e[a],u=e[(a+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],s+=l[1],i+=l[2]}let c=Ba([n,t,o]);return c?{normal:c,point:[r/e.length,s/e.length,i/e.length]}:null}function np(e,n){let t=0;for(let o=0;o<e.length;o++){let r=e[o],s=e[(o+1)%e.length],i=e[(o+2)%e.length],c=Ke(Da(pn(s,r),pn(i,s)),n);if(Math.abs(c)<=1e-9)continue;let a=c>0?1:-1;if(t===0)t=a;else if(t!==a)return!1}return!0}function tp(e,n,t){let o=Ta(e,t),r=lp(o,n);if(r<=0)return o;let s=o.map(m=>{let p=Dr(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Ra(m)}:null}),i=mp(o,s),c=new Set,a=Array(o.length),l=[],u=(m,p)=>{a[m]=p};for(let m=0;m<o.length;m++){let p=s[m];if(c.has(m))continue;if(!p){u(m,o[m]);continue}let h=gp(m,s,i,c,r,n);for(let y of h)c.add(y);if(h.length<2){u(m,o[m]);continue}let g=ip(h,o,s,i,r,n);l.push(...g.vertexMoves);for(let y of h)u(y,g.polygons.get(y)??o[y])}let f=a.flatMap(m=>m?[m]:[]),d=l.length>0?Ia(f,va(l)):f;return bo(d)}function bo(e){let n=Va(e),t=1e-4;if(n<=0)return e;let o=up(n),r=fp(t),s=!1,i=e.map(c=>{let a=!1,l=p=>{let h=o.snap(p);return Vt(h,p)||(a=!0),h},u=c.vertices.map(l),f=c.uvs&&c.uvs.length===c.vertices.length?c.uvs.map(p=>{let h=r.snap(p);return Rt(h,p)||(a=!0),h}):void 0,d=Nr(c.textureTriangles,l);if(!a&&!c.texture)return c;let m={...c,vertices:u,...f?{uvs:f}:{},...d?{textureTriangles:d}:{}};return s=!0,{...m,...m.texture?{textureTriangles:_a(m)}:{}}});return s?i:e}function _a(e){if(e.texture){if(e.textureTriangles?.length)return sp(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return rp(e.vertices,e.uvs)}}function op(e){let n=e.flatMap(t=>_a(t)??[]);return n.length>0?n:void 0}function rp(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 sp(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Nr(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(o=>[...o])}))}function ip(e,n,t,o,r,s){let i=Oa(e,n,t,r,s);return i?cp(i):ap(e,n,t,o,r,s)}function ap(e,n,t,o,r,s){let i=new Set(e),c=[];for(let f of e)for(let d of o.get(f)??[]){if(f>=d||!i.has(d))continue;let m=Oa([f,d],n,t,r,s);m&&c.push(m)}c.sort((f,d)=>d.score-f.score);let a=new Set,l=new Map,u=[];for(let f of c)if(!f.indices.some(d=>a.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];a.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function cp(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 Oa(e,n,t,o,r){let s=La(e,t);if(!s||!wa(e,t,s,o,r))return null;let i=e.map(u=>n[u]),c=i.map(u=>bp(u,s)),a=Bn(an(i)),l=Bn(an(c));return l>=a?null:{indices:e,source:i,projected:c,vertexMoves:qd(i,c),score:a-l}}function lp(e,n){return Va(e)<=0?0:n.maxPlaneDisplacement}function Va(e){let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let[l,u,f]of a.vertices)n=Math.min(n,l),t=Math.min(t,u),o=Math.min(o,f),r=Math.max(r,l),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let c=Math.hypot(r-n,s-t,i-o);return c<=0?0:Math.min(.025,Math.max(1e-4,c*25e-5))}function up(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,s,i)=>`${r},${s},${i}`;return{snap(r){let s=t(r[0]),i=t(r[1]),c=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(s+f,i+d,c+m));if(p){for(let h of p)if(Fa(r,h)<=e)return[h[0],h[1],h[2]]}}let a=[r[0],r[1],r[2]],l=o(s,i,c),u=n.get(l);return u?u.push(a):n.set(l,[a]),a}}}function fp(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,s)=>`${r},${s}`;return{snap(r){let s=t(r[0]),i=t(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(o(s+u,i+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 c=[r[0],r[1]],a=o(s,i),l=n.get(a);return l?l.push(c):n.set(a,[c]),c}}}function Ra(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 Dr(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0,s=n[0];for(let c=1;c<n.length-1;c++){let a=pn(n[c],s),l=pn(n[c+1],s),u=Da(a,l);t+=u[0],o+=u[1],r+=u[2]}let i=Math.hypot(t,o,r);return i<=1e-10?null:{normal:[t/i,o/i,r/i],area:i/2}}function mp(e,n){let t=new Map,o=new Map;for(let r=0;r<e.length;r++){let s=e[r];if(!(!n[r]||s.vertices.length<3))for(let i=0;i<s.vertices.length;i++){let c=Lt(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),a=t.get(c);a?a.push(r):t.set(c,[r])}}for(let r of t.values())for(let s=0;s<r.length;s++)for(let i=s+1;i<r.length;i++){let c=r[s],a=r[i];dp(e[c],e[a],n[c],n[a])&&(Pa(o,c,a),Pa(o,a,c))}return o}function dp(e,n,t,o){if(!t||!o||t.materialKey!==o.materialKey||!!e.uvs!=!!n.uvs)return!1;if(xo(e)||xo(n))return Fr(e,n);if(!e.uvs||!n.uvs)return!0;let r=Br(e,n);if(!r)return!1;let[s,i,c,a]=r;return Rt(e.uvs[s],n.uvs[c])&&Rt(e.uvs[i],n.uvs[a])}function pp(e,n,t,o){return t.materialKey!==o.materialKey?!1:xo(e)||xo(n)?Fr(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function xo(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Fr(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=Br(e,n);if(!t)return!1;let[o,r,s,i]=t;return Rt(e.uvs[o],n.uvs[s])&&Rt(e.uvs[r],n.uvs[i])}function Pa(e,n,t){let o=e.get(n);o?o.add(t):e.set(n,new Set([t]))}function gp(e,n,t,o,r,s){let i=[e],c=new Set([e]),a=[e];for(;a.length>0;){let l=a.shift();for(let u of t.get(l)??[]){if(o.has(u)||c.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&hp([...i,u],n,r,s)&&(i.push(u),c.add(u),a.push(u))}}return i}function hp(e,n,t,o){let r=La(e,n);return!!r&&wa(e,n,r,t,o)}function La(e,n){let t=n[e[0]];if(!t)return null;let o=0,r=0,s=0,i=0,c=0,a=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let h=Ke(t.normal,p.normal)<0?-1:1,g=Math.max(p.area,1e-6);o+=p.normal[0]*h*g,r+=p.normal[1]*h*g,s+=p.normal[2]*h*g;for(let y of p.polygon.vertices)i+=y[0],c+=y[1],a+=y[2],l+=1}let u=Ba([o,r,s]);if(!u||l===0)return null;let f=Na(e,n),d=yp(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:[i/l,c/l,a/l],boundaryVertexKeys:f}}function yp(e,n,t,o){let r=1/0,s=-1/0;for(let i of e){let c=n[i];if(c)for(let a of c.polygon.vertices){if(!o.has(tn(a)))continue;let l=Ke(a,t);r=Math.min(r,l),s=Math.max(s,l)}}return Number.isFinite(r)&&Number.isFinite(s)?{min:r,max:s}:null}function wa(e,n,t,o,r){let s=Math.cos(r.maxAngleDeg*Math.PI/180),i=t.boundaryVertexKeys??Na(e,n);for(let c of e){let a=n[c];if(!a||Math.abs(Ke(a.normal,t.normal))<s)return!1;for(let l of a.polygon.vertices){let u=i.has(tn(l))?r.maxBoundaryDisplacement:o;if(Math.abs(kr(l,t))>u)return!1}}return!0}function Na(e,n){let t=new Map;for(let r of e){let s=n[r];if(!s)continue;let i=s.polygon.vertices;for(let c=0;c<i.length;c++){let a=i[c],l=i[(c+1)%i.length],u=Lt(a,l),f=t.get(u);f?f.count+=1:t.set(u,{count:1,a,b:l})}}let o=new Set;for(let r of t.values())r.count===1&&(o.add(tn(r.a)),o.add(tn(r.b)));return o}function bp(e,n){let t=r=>Ur(r,n),o=Nr(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...o?{textureTriangles:o}:{}}}function Br(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 s=(r+1)%n.vertices.length;if(Vt(e.vertices[t],n.vertices[r])&&Vt(e.vertices[o],n.vertices[s]))return[t,o,r,s];if(Vt(e.vertices[t],n.vertices[s])&&Vt(e.vertices[o],n.vertices[r]))return[t,o,s,r]}}return null}function Lt(e,n){let t=tn(e),o=tn(n);return t<o?`${t}|${o}`:`${o}|${t}`}function tn(e){return`${e[0]},${e[1]},${e[2]}`}function Vt(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Rt(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function pn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Da(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 Ke(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Fa(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function Ba(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 kr(e,n){return Ke(pn(e,n.point),n.normal)}function Ur(e,n){let t=kr(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var xp=36,Pp=.15,Mp=.2,Ap=650,Sp=15e3,Cp=.25;function Gr(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function ka(e){let n=Mn(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 Ep(e){let n=Mn(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 Tp(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function Ua(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),s=Math.min(n,t,o),i=r-s,c=0;return i!==0&&(r===n?c=60*((t-o)/i%6):r===t?c=60*((o-n)/i+2):c=60*((n-t)/i+4)),c<0&&(c+=360),{hue:c,saturation:r===0?0:i/r,value:r}}function vp(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function Ip(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=Ua(e),o=Ua(n),r=t.saturation<.08,s=o.saturation<.08;if(r||s)return r===s;let i=Math.min(t.value,o.value)<.18?32:18;return vp(t.hue,o.hue)<=i}function _p(e,n){let t=new Map;for(let i of e.keys()){let c=Ep(i);c&&t.set(i,c)}let o=[],r=new Map,s=Array.from(e.entries()).sort((i,c)=>c[1]-i[1]||i[0].localeCompare(c[0]));for(let[i]of s){let c=t.get(i);if(!c){r.set(i,i);continue}let a=null;for(let l of o){if(!Ip(c,l.parsed))continue;let u=Tp(c,l.parsed);u>n||(!a||u<a.distance)&&(a={color:l.color,distance:u})}a?r.set(i,a.color):(o.push({color:i,parsed:c}),r.set(i,i))}return r}function Op(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??xp;if(!Number.isFinite(r)||r<=0)return e;let s=new Map,i=[];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||!Gr(f)||Gr(d))continue;let m=ka(d.color);i.push(u),s.set(m,(s.get(m)??0)+1)}if(s.size<2)return e;let c=_p(s,r),a=!1,l=e.polygons.slice();for(let u of i){let f=l[u],d=ka(f.color),m=c.get(d)??d;m!==d&&(l[u]={...f,color:m},a=!0)}return a?{...e,polygons:l}:e}function Vp(e){let n=0;for(let t of e)Gr(t)&&(n+=1);return e.length===0||n/e.length<=Cp}function Rp(e){return!!e.metadata?.stlTopology}function Lp(e,n){return n?Math.max(e.simplifyEarlyStopDropRatio??Pp,Mp):e.simplifyEarlyStopDropRatio}function tt(e,n={}){return new zr(e,n).optimize()}var zr=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=Op(this.result,this.options,this.meshResolution),t=Rp(n),o=t?"lossless":this.meshResolution,r=this.canSimplify(n.polygons,o),s=r&&n.polygons.length>=Ap&&n.polygons.length<=Sp,i=Ma(n.polygons,{meshResolution:o,useCandidateFirst:s,staticSimplification:r?{simplifyTriangleMeshOptions:this.options.simplifyTriangleMeshOptions,earlyStopDropRatio:Lp(this.options,s)}:!1,skipInteriorCull:t});return i===n.polygons?n:{...n,polygons:i}}canSimplify(n,t){return t==="lossy"&&this.options.simplifyTriangleMeshes!==!1&&Vp(n)}};function wp(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[_,O,V]of n)t+=_,o+=O,r+=V;let s=1/n.length;t*=s,o*=s,r*=s;let i=n[0],c=n[1],a=n[2],l=c[0]-i[0],u=c[1]-i[1],f=c[2]-i[2],d=a[0]-i[0],m=a[1]-i[1],p=a[2]-i[2],h=u*p-f*m,g=f*d-l*p,y=l*m-u*d,b=Math.hypot(h,g,y);if(b<1e-9)return null;h/=b,g/=b,y/=b;let x=n.length-2,P=new Float64Array(x*9),S=0;for(let _=1;_<n.length-1;_++){let O=n[0],V=n[_],w=n[_+1];P[S++]=O[0],P[S++]=O[1],P[S++]=O[2],P[S++]=V[0],P[S++]=V[1],P[S++]=V[2],P[S++]=w[0],P[S++]=w[1],P[S++]=w[2]}let C=0,T=1/0,A=1/0,M=1/0,E=-1/0,v=-1/0,I=-1/0;for(let[_,O,V]of n){let w=_-t,F=O-o,D=V-r,H=w*w+F*F+D*D;H>C&&(C=H),_<T&&(T=_),_>E&&(E=_),O<A&&(A=O),O>v&&(v=O),V<M&&(M=V),V>I&&(I=V)}return{centroid:[t,o,r],normal:[h,g,y],triFlat:P,bcx:t,bcy:o,bcz:r,br2:C,minX:T,minY:A,minZ:M,maxX:E,maxY:v,maxZ:I}}function Np(e,n,t,o,r,s,i,c){let a=i[c],l=i[c+1],u=i[c+2],f=i[c+3]-a,d=i[c+4]-l,m=i[c+5]-u,p=i[c+6]-a,h=i[c+7]-l,g=i[c+8]-u,y=r*g-s*h,b=s*p-o*g,x=o*h-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let S=1/P,C=e-a,T=n-l,A=t-u,M=S*(C*y+T*b+A*x);if(M<0||M>1)return!1;let E=T*m-A*d,v=A*f-C*m,I=C*d-T*f,_=S*(o*E+r*v+s*I);return _<0||M+_>1?!1:S*(p*E+h*v+g*I)>.001}function Dp(e,n,t,o,r,s,i){let c=i.bcx-e,a=i.bcy-n,l=i.bcz-t,u=c*o+a*r+l*s,f=c-u*o,d=a-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,h=p.length;for(let g=0;g<h;g+=9)if(Np(e,n,t,o,r,s,p,g))return!0;return!1}var wt=9,Fp=6,Ue=12;function $r(e,n,t,o,r,s){let i=o-e,c=r-n,a=s-t;return i*c+c*a+a*i}function Bp(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),s=new Float64Array(t),i=new Float64Array(t);for(let C=0;C<t;C++){let T=e[o[C]];r[C]=(T.minX+T.maxX)*.5,s[C]=(T.minY+T.maxY)*.5,i[C]=(T.minZ+T.maxZ)*.5}let c=2*Math.max(1,t)+1,a=new Float64Array(c*wt),l=0,u=new Float64Array(Ue),f=new Float64Array(Ue),d=new Float64Array(Ue),m=new Float64Array(Ue),p=new Float64Array(Ue),h=new Float64Array(Ue),g=new Int32Array(Ue),y=new Float64Array(Ue-1),b=new Int32Array(Ue-1),x=new Float64Array(Ue-1),P=new Int32Array(Ue-1);function S(C,T){let A=l++,M=A*wt,E=T-C,v=1/0,I=1/0,_=1/0,O=-1/0,V=-1/0,w=-1/0;for(let G=C;G<T;G++){let te=e[o[G]];te.minX<v&&(v=te.minX),te.maxX>O&&(O=te.maxX),te.minY<I&&(I=te.minY),te.maxY>V&&(V=te.maxY),te.minZ<_&&(_=te.minZ),te.maxZ>w&&(w=te.maxZ)}if(a[M]=v,a[M+1]=I,a[M+2]=_,a[M+3]=O,a[M+4]=V,a[M+5]=w,E<=Fp)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let F=1/0,D=1/0,H=1/0,K=-1/0,Q=-1/0,ne=-1/0;for(let G=C;G<T;G++)r[G]<F&&(F=r[G]),r[G]>K&&(K=r[G]),s[G]<D&&(D=s[G]),s[G]>Q&&(Q=s[G]),i[G]<H&&(H=i[G]),i[G]>ne&&(ne=i[G]);let ee=K-F,ue=Q-D,U=ne-H;if(ee===0&&ue===0&&U===0)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let $=$r(v,I,_,O,V,w),k=$>0?1/$:0,L=E+1,W=0,Y=0;for(let G=0;G<3;G++){let te=G===0?F:G===1?D:H,ce=G===0?ee:G===1?ue:U;if(ce===0)continue;let ye=G===0?r:G===1?s:i,he=Ue/ce;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),h.fill(-1/0),g.fill(0);for(let N=C;N<T;N++){let X=(ye[N]-te)*he|0;X>=Ue&&(X=Ue-1);let oe=e[o[N]];oe.minX<u[X]&&(u[X]=oe.minX),oe.maxX>m[X]&&(m[X]=oe.maxX),oe.minY<f[X]&&(f[X]=oe.minY),oe.maxY>p[X]&&(p[X]=oe.maxY),oe.minZ<d[X]&&(d[X]=oe.minZ),oe.maxZ>h[X]&&(h[X]=oe.maxZ),g[X]++}let be=1/0,ge=1/0,Se=1/0,De=-1/0,R=-1/0,z=-1/0,j=0;for(let N=0;N<Ue-1;N++)u[N]<be&&(be=u[N]),m[N]>De&&(De=m[N]),f[N]<ge&&(ge=f[N]),p[N]>R&&(R=p[N]),d[N]<Se&&(Se=d[N]),h[N]>z&&(z=h[N]),j+=g[N],y[N]=$r(be,ge,Se,De,R,z),b[N]=j;let J=1/0,le=1/0,re=1/0,pe=-1/0,xe=-1/0,ie=-1/0,ae=0;for(let N=Ue-2;N>=0;N--){let X=N+1;u[X]<J&&(J=u[X]),m[X]>pe&&(pe=m[X]),f[X]<le&&(le=f[X]),p[X]>xe&&(xe=p[X]),d[X]<re&&(re=d[X]),h[X]>ie&&(ie=h[X]),ae+=g[X],x[N]=$r(J,le,re,pe,xe,ie),P[N]=ae}for(let N=0;N<Ue-1;N++){if(b[N]===0||P[N]===0)continue;let X=.125+(y[N]*b[N]+x[N]*P[N])*k;X<L&&(L=X,W=G,Y=te+(N+1)/he)}}let se=W===0?r:W===1?s:i,Z=C,B=T-1;for(;Z<=B;)if(se[Z]<Y)Z++;else{let G=o[Z];o[Z]=o[B],o[B]=G;let te=r[Z];r[Z]=r[B],r[B]=te;let ce=s[Z];s[Z]=s[B],s[B]=ce;let ye=i[Z];i[Z]=i[B],i[B]=ye,B--}let q=Z;(q===C||q===T)&&(q=C+T>>1),a[M+6]=0;let me=S(C,q),fe=S(q,T);return a[A*wt+7]=me,a[A*wt+8]=fe,A}return t>0&&S(0,t),{data:a,nodeCount:l,polyIndices:o,meta:e}}function kp(e,n,t,o,r,s,i,c,a){if(c.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=c,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,h=0;for(a[h++]=0;h>0;){let y=a[--h]*wt,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,S=b<x?x:b,C=(l[y+1]-n)*m,T=(l[y+4]-n)*m,A=C<T?C:T,M=C<T?T:C;if(P>M||A>S)continue;A>P&&(P=A),M<S&&(S=M);let E=(l[y+2]-t)*p,v=(l[y+5]-t)*p,I=E<v?E:v,_=E<v?v:E;if(!(P>_||I>S)&&(_<S&&(S=_),!(S<.001)))if(l[y+6]===1){let O=l[y+7]|0,V=l[y+8]|0;for(let w=O;w<V;w++){let F=u[w];if(F===i)continue;let D=f[F];if(D&&Dp(e,n,t,o,r,s,D))return!0}}else a[h++]=l[y+7]|0,a[h++]=l[y+8]|0}return!1}function Up(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 s=n[0]/r,i=n[1]/r,c=n[2]/r,a=e.map(wp);if(t&&t.size>0)for(let f of t)a[f]=null;let l=Bp(a),u=new Int32Array(Math.max(64,l.nodeCount));for(let f=0;f<e.length;f++){let d=a[f];if(!d)continue;let m=d.centroid[0]+d.normal[0]*.001,p=d.centroid[1]+d.normal[1]*.001,h=d.centroid[2]+d.normal[2]*.001;d.normal[0]*s+d.normal[1]*i+d.normal[2]*c<=0||kp(m,p,h,s,i,c,f,l,u)&&o.add(f)}return o}var Po=1e-5,Ga=.001,za=6;function Xr(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let c=1;c+1<n.length;c++){let a=n[c],l=n[c+1],u=a[1]-t[1],f=a[0]-t[0],d=a[2]-t[2],m=l[1]-t[1],p=l[0]-t[0],h=l[2]-t[2];o-=f*h-d*p,r-=d*m-u*h,s-=u*p-f*m}let i=Math.hypot(o,r,s);return i<1e-9?null:[o/i,r/i,s/i]}function $a(e,n){let t=n.meshRotation,o=t?Vn(e,t):e;return Qo(o,n.rotX,0,n.rotY)[2]}function Nt(e,n,t=Po){return $a(e,n)>t}function Gp(e,n,t=Po){let o=Xr(e);return o===null||Nt(o,n,t)}function Xa(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function Ya(e){let n=new Map;for(let t of e){if(!t)continue;let o=Xa(t);n.has(o)||n.set(o,t)}return Array.from(n,([t,o])=>({key:t,normal:o}))}function zp(e){return Ya(e.map(Xr))}function Wa(e,n=Ga){let t=Math.abs(e[0]),o=Math.abs(e[1]),r=Math.abs(e[2]),s=Math.max(t,o,r);return s>1-n&&t+o+r-s<n}function $p(e){return e.length<=za&&e.every(({normal:n})=>Wa(n))}function Xp(e,n,t=Po){let o=[];for(let{key:r,normal:s}of e)Nt(s,n,t)&&o.push(r);return o.sort(),o.join("|")}function Yr(e,n,t,o,r){let s=(p,h,g)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=h,y[(e+2)%3]=g,y},i=s(n,-o,-o),c=s(n,o,-o),a=s(n,o,o),l=s(n,-o,o),u=s(t,-o,-o),f=s(t,o,-o),d=s(t,o,o),m=s(t,-o,o);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function ja(e={}){let n=e.size??5,t=e.thickness??.025,o=e.negative??!1,r=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",c=n*t/2,a=o?-n:0;return[...Yr(0,a,n,c,r),...Yr(1,a,n,c,s),...Yr(2,a,n,c,i)]}var Yp=["right","left","front","back","top","bottom"];function Wr(e){return[e[0],e[1],e[2]]}function Ka(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 Wp(e){if(e.min&&e.max)return Ka(e.min,e.max);let n=e.center?Wr(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=Wr(e.size):t=[1,1,1];let o=[t[0]/2,t[1]/2,t[2]/2];return Ka([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 jp(e,n){let[t,o,r]=e,[s,i,c]=n;return[{name:"right",vertices:[[s,o,r],[s,i,r],[s,i,c],[s,o,c]]},{name:"left",vertices:[[t,i,r],[t,o,r],[t,o,c],[t,i,c]]},{name:"front",vertices:[[s,i,r],[t,i,r],[t,i,c],[s,i,c]]},{name:"back",vertices:[[t,o,r],[s,o,r],[s,o,c],[t,o,c]]},{name:"top",vertices:[[t,o,c],[s,o,c],[s,i,c],[t,i,c]]},{name:"bottom",vertices:[[t,i,r],[s,i,r],[s,o,r],[t,o,r]]}]}function Kp(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function Hp(e,n){let t={vertices:e.vertices.map(Wr)};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 Ha(e={}){let{min:n,max:t}=Wp(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=jp(n,t),s=new Map(r.map(c=>[c.name,c])),i=[];for(let c of Yp){let a=e.faces?.[c];if(a===!1)continue;let l=s.get(c);l&&i.push(Hp(l,Kp(o,a)))}return i}function Za(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 Zp(e,n,t,o,r){let s=(p,h,g)=>Za(e,p,h,g),i=s(n,-o,-o),c=s(n,o,-o),a=s(n,o,o),l=s(n,-o,o),u=s(t,-o,-o),f=s(t,o,-o),d=s(t,o,o),m=s(t,-o,o);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function qp(e,n,t,o,r){let s=(f,d,m)=>Za(e,f,d,m),i=s(n,-o,-o),c=s(n,o,-o),a=s(n,o,o),l=s(n,-o,o),u=s(t,0,0);return[{vertices:[i,c,a,l],color:r},{vertices:[i,c,u],color:r},{vertices:[c,a,u],color:r},{vertices:[a,l,u],color:r},{vertices:[l,i,u],color:r}]}function Qp(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function qa(e){let n=e.axis,t=e.sign??1,o=e.shaftLength??4,r=e.shaftHalfThickness??.05,s=e.headLength??.8,i=e.headHalfThickness??.2,c=e.color??"#ffffff",a=e.shaft??!0,l=o*t,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(o+s)*t,p=qp(n,d,m,i,c),h=t===-1?Qp(p):p;return a?[...Zp(n,u,f,r,c),...h]:h}function Mo(e,n,t){let o=[0,0,0],r=(e+1)%3,s=(e+2)%3;return o[r]=Math.cos(t)*n,o[s]=Math.sin(t)*n,o}function Qa(e){let n=e.axis,t=e.radius,o=e.halfThickness??Math.max(.05,t*.04),r=e.segments??32,s=e.color??"#ffffff",i=t-o,c=t+o,a=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=Mo(n,i,u),m=Mo(n,i,f),p=Mo(n,c,u),h=Mo(n,c,f);a.push({vertices:[d,p,h,m],color:s})}return a}function Ja(e){let n=e.axis,t=e.outerRadius,o=e.color??"#ffffff",r=(n+1)%3,s=(n+2)%3,i=(c,a)=>{let l=[0,0,0];return l[n]=0,l[r]=c,l[s]=a,l};return[{vertices:[i(-t,-t),i(t,-t),i(t,t),i(-t,t)],color:o}]}function ec(e){let n=e.axis,t=e.size??.4,o=e.offset??t*2,r=typeof o=="number"?o:o[0],s=typeof o=="number"?o:o[1],i=e.along??0,c=e.color??"#ffffff",a=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=i,m[a]=r+f,m[l]=s+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:c}]}function nc(e){let{center:n,size:t,color:o="#ffffff"}=e,[r,s,i]=n,c=[[r+t,s,i],[r-t,s,i],[r,s+t,i],[r,s-t,i],[r,s,i+t],[r,s,i-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:[c[l[0]],c[l[1]],c[l[2]]],color:o}))}function tc(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,s=[[-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(([a,l,u])=>{let f=Math.sqrt(a*a+l*l+u*u);return[a/f,l/f,u/f]}),i=[[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 a=0;a<o;a++){let l=[...s],u=[],f=new Map,d=(m,p)=>{let h=m<p?`${m}-${p}`:`${p}-${m}`,g=f.get(h);if(g!==void 0)return g;let y=s[m],b=s[p],x=(y[0]+b[0])/2,P=(y[1]+b[1])/2,S=(y[2]+b[2])/2,C=Math.sqrt(x*x+P*P+S*S);x/=C,P/=C,S/=C;let T=l.length;return l.push([x,P,S]),f.set(h,T),T};for(let[m,p,h]of i){let g=d(m,p),y=d(p,h),b=d(h,m);u.push([m,g,b]),u.push([p,y,g]),u.push([h,b,y]),u.push([g,y,b])}s=l,i=u}let c=s.map(([a,l,u])=>[a*n,l*n,u*n]);return i.map(([a,l,u])=>({vertices:[c[a],c[l],c[u]],color:t}))}function oc(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(([i,c,a])=>({vertices:[r[i],r[c],r[a]],color:t}))}function rc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=n/Math.sqrt(1+o*o),s=[[-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(([c,a,l])=>[c*r,a*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(([c,a,l])=>({vertices:[s[c],s[a],s[l]],color:t}))}function sc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=1/o,s=n/Math.sqrt(3),c=[[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*s,u*s,f*s]);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=>c[u]),color:t}))}function Ao(e={}){let{radius:n=50,height:t=100,radialSegments:o=12,color:r="#cccccc"}=e,s=e.radiusTop??n,i=t/2,c=-i,a=i,l=Math.max(3,o),u=[],f=Array.from({length:l+1},(p,h)=>h/l*Math.PI*2),d=n<=1e-6,m=s<=1e-6;for(let p=0;p<l&&!(d&&m);p++){let h=f[p],g=f[p+1],y=Math.cos(h)*n,b=Math.sin(h)*n,x=Math.cos(g)*n,P=Math.sin(g)*n,S=Math.cos(h)*s,C=Math.sin(h)*s,T=Math.cos(g)*s,A=Math.sin(g)*s,M=[y,b,c],E=[x,P,c],v=[T,A,a],I=[S,C,a];if(m){let _=[0,0,a];u.push({vertices:[M,E,_],color:r})}else if(d){let _=[0,0,c];u.push({vertices:[_,v,I],color:r})}else u.push({vertices:[M,E,v,I],color:r})}if(n>1e-6){let p=[0,0,c];for(let h=0;h<l;h++){let g=f[h],y=f[h+1],b=[Math.cos(g)*n,Math.sin(g)*n,c],x=[Math.cos(y)*n,Math.sin(y)*n,c];u.push({vertices:[[...p],[...x],[...b]],color:r})}}if(s>1e-6){let p=[0,0,a];for(let h=0;h<l;h++){let g=f[h],y=f[h+1],b=[Math.cos(g)*s,Math.sin(g)*s,a],x=[Math.cos(y)*s,Math.sin(y)*s,a];u.push({vertices:[[...p],[...b],[...x]],color:r})}}return u}function ic(e={}){return Ao({...e,radiusTop:0})}function So(e,n,t,o){let r=Math.sin(e),s=Math.cos(e),i=Math.sin(n),c=Math.cos(n);return[(t+o*c)*s,(t+o*c)*r,o*i]}function ac(e={}){let{radius:n=50,tube:t=15,radialSegments:o=12,tubularSegments:r=16,color:s="#cccccc"}=e,i=Math.max(3,o),c=Math.max(3,r),a=[];for(let l=0;l<i;l++){let u=l/i*Math.PI*2,f=(l+1)/i*Math.PI*2;for(let d=0;d<c;d++){let m=d/c*Math.PI*2,p=(d+1)/c*Math.PI*2,h=So(u,m,n,t),g=So(f,m,n,t),y=So(f,p,n,t),b=So(u,p,n,t);a.push({vertices:[h,g,y,b],color:s})}}return a}var Jp=.01,eg=.01;function ng(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,o=e[0]/t,r=e[1]/t,s=e[2]/t,i=Math.sign(s||1)*Math.max(Math.abs(s),.01),c=n,a=.01;return[1,0,0,0,0,1,0,0,-o/i,-r/i,a,0,c*o/i,c*r/i,c*(1-a),1]}function tg(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,s=n[2]/t;return e[0]*o+e[1]*r+e[2]*s>0}function jr(e){if(e.length<=1)return e.map(i=>[i[0],i[1]]);let t=e.map(i=>[i[0],i[1]]);t.sort((i,c)=>i[0]-c[0]||i[1]-c[1]);let o=(i,c,a)=>(c[0]-i[0])*(a[1]-i[1])-(c[1]-i[1])*(a[0]-i[0]),r=[];for(let i of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],i)<=0;)r.pop();r.push(i)}let s=[];for(let i=t.length-1;i>=0;i--){let c=t[i];for(;s.length>=2&&o(s[s.length-2],s[s.length-1],c)<=0;)s.pop();s.push(c)}return r.pop(),s.pop(),r.concat(s)}function cc(e){let n=0,t=e.length;for(let o=0;o<t;o++){let r=e[o],s=e[(o+1)%t];n+=r[0]*s[1]-s[0]*r[1]}return n/2}function gn(e){let n=e.map(t=>[t[0],t[1]]);return cc(n)<0&&n.reverse(),n}function og(e,n,t){let o=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/o,s=n[1]/o,i=n[2]/o,c=Math.sign(i||1)*Math.max(Math.abs(i),.01),a=e[2]-t;return[e[0]-r/c*a,e[1]-s/c*a]}function Sn(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 s=t;t=[];let i=n[r],c=n[(r+1)%o],a=f=>(c[0]-i[0])*(f[1]-i[1])-(c[1]-i[1])*(f[0]-i[0])>=0,l=(f,d)=>{let m=i[0],p=i[1],h=c[0],g=c[1],y=f[0],b=f[1],x=d[0],P=d[1],S=(m-h)*(b-P)-(p-g)*(y-x);if(Math.abs(S)<1e-12)return[f[0],f[1]];let C=((m-y)*(b-P)-(p-b)*(y-x))/S;return[m+C*(h-m),p+C*(g-p)]},u=s.length;for(let f=0;f<u;f++){let d=s[f],m=s[(f+u-1)%u],p=a(d),h=a(m);p?(h||t.push(l(m,d)),t.push([d[0],d[1]])):h&&t.push(l(m,d))}}return t}function Co(e){if(!Number.isFinite(e)||e<=0)throw new Error("PolyCSS world unit size must be a positive finite number.");return e}function lc(e,n=50){return e*Co(n)}function uc(e,n=50){return e/Co(n)}function hn(e,n=50){let t=Co(n);return[e[1]*t,e[0]*t,e[2]*t]}function fc(e,n=50){let t=Co(n);return[e[1]/t,e[0]/t,e[2]/t]}function Kr(e){return[e[1],e[0],e[2]]}function rg(e){return e?.direction?{...e,direction:Kr(e.direction)}:e}function Hr(e){return e==null?[1,1,1]:typeof e=="number"?[e,e,e]:[e[0]??1,e[1]??1,e[2]??1]}function Dt(e){let n=Hr(e),t=n[0]===1&&n[1]===1&&n[2]===1;return(o,r)=>{let s=hn(r),i=o[1]*50,c=o[0]*50,a=o[2]*50,l=t?i:i*n[0],u=t?c:c*n[1],f=t?a:a*n[2];return[l+s[0],u+s[1],f+s[2]]}}function mc(e,n){if(e.length<3||n===0)return e;let t=[],o=e.length;for(let r=0;r<o;r++){let s=e[(r-1+o)%o],i=e[r],c=e[(r+1)%o],a=i[0]-s[0],l=i[1]-s[1],u=c[0]-i[0],f=c[1]-i[1],d=Math.hypot(a,l),m=Math.hypot(u,f);if(d<1e-9||m<1e-9){t.push(i);continue}let p=l/d,h=-a/d,g=f/m,y=-u/m,b=p+g,x=h+y,P=Math.hypot(b,x);if(P<1e-9){t.push(i);continue}let S=b/P,C=x/P,T=S*p+C*h;if(Math.abs(T)<1e-9){t.push(i);continue}let A=n/T;t.push([i[0]+S*A,i[1]+C*A])}return t}var dc=.5,pc=.001,gc=.5;function Zr(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,h=0,g=0;for(let A=1;A+1<d.length;A++){let M=d[A],E=d[A+1],v=M[0]-m[0],I=M[1]-m[1],_=M[2]-m[2],O=E[0]-m[0],V=E[1]-m[1],w=E[2]-m[2];p+=V*_-w*I,h+=w*v-O*_,g+=O*I-V*v}let y=Math.hypot(p,h,g);if(y<1e-9)continue;let b=[p/y,h/y,g/y],x=null;for(let A=1;A<d.length;A++){let M=d[A],E=M[0]-m[0],v=M[1]-m[1],I=M[2]-m[2],_=Math.hypot(E,v,I);if(_>1e-9){x=[E/_,v/_,I/_];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 S=Math.hypot(x[0],x[1],x[2]);if(S<1e-9)continue;x=[x[0]/S,x[1]/S,x[2]/S];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]],T=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:T,polyIndex:u})}let s=[];for(let u of r){let f=!1;for(let d of s){let m=d.rep;if(!(1-(u.n[0]*m.n[0]+u.n[1]*m.n[1]+u.n[2]*m.n[2])>pc)&&!(Math.abs(u.offset-m.offset)>gc)){d.faces.push(u),f=!0;break}}f||s.push({rep:u,faces:[u]})}let i=[],c=3,a=u=>`${u[0].toFixed(c)},${u[1].toFixed(c)},${u[2].toFixed(c)}`;for(let u of s){if(u.faces.length===1){l(u.faces);continue}let f=u.faces.map(g=>{let y=new Set;for(let b of g.face.vertices)y.add(a(t(b,n)));return y}),d=u.faces.map((g,y)=>y),m=g=>{for(;d[g]!==g;)d[g]=d[d[g]],g=d[g];return g},p=(g,y)=>{let b=m(g),x=m(y);b!==x&&(d[b]=x)};for(let g=0;g<u.faces.length;g++)for(let y=g+1;y<u.faces.length;y++){let b=f[g],x=f[y],P=0;for(let S of b)if(x.has(S)&&(P++,P>=2))break;P>=2&&p(g,y)}let h=new Map;for(let g=0;g<u.faces.length;g++){let y=m(g),b=h.get(y);b||(b=[],h.set(y,b)),b.push(u.faces[g])}for(let g of h.values())l(g)}function l(u){let f=u[0],{O:d,n:m,u:p,v:h}=f,g=[],y=[],b=[];for(let S of u){let C=[];for(let T of S.face.vertices){let A=t(T,n),M=A[0]-d[0],E=A[1]-d[1],v=A[2]-d[2],I=[M*p[0]+E*p[1]+v*p[2],M*h[0]+E*h[1]+v*h[2]];g.push(I),C.push(I)}C.length>=3&&(y.push(gn(C)),b.push(S.polyIndex))}if(g.length<3)return;let x=jr(g);if(x.length<3)return;let P=mc(gn(x),dc);i.push({O:d,n:m,u:p,v:h,outlineUv:P,memberPolysUv:y,memberPolyIndices:b})}return i}function sg(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,s=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),i=e.position?hn(e.position):[0,0,0],c=[];return(i[0]!==0||i[1]!==0||i[2]!==0)&&c.push(`translate3d(${i[0]}px, ${i[1]}px, ${i[2]}px)`),s&&(e.rotation[0]&&c.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&c.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&c.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&c.push(`scale3d(${n}, ${t}, ${o})`),c.length>0?c.join(" "):void 0}var yn=50,ot=[.4,-.7,.59],rt="#ffffff",st=1,it="#ffffff",at=.4,Cn=4096,Eo=1,qr=.1,Qr=1,To=Cn*Cn,Jr=To*3,Ft=2048,es=4*1024*1024,ns=16*1024*1024,ts=.995,os=512,ig=12,Ae=.001,de=1e-9,rs=1e-4,ss=.1,vo=.01,ag=.75,cg=1,lg=250,ug=1.5,is=.75,bn=3,as=2,Io=4,cs=[1,10,100,1e3,1e4,1e5,1e6],ct=64,ls=32,us=96,He=64,fs=128,_o=50,Oo=1e-7,xn=16,ms=.9,Ze=.75,Vo=.2,ds=.05,ps=256,gs=.6,fg=1.5;function hs(e){return e===void 0||e==="auto"||!Number.isFinite(e)?1:Math.max(0,Math.min(1,e))}var Bt=new Map;function ut(e){if(Bt.has(e)){let t=Bt.get(e);return t===void 0?null:t}let n=Mn(e);return Bt.size>=os&&Bt.clear(),Bt.set(e,n),n}function Pn(e){let n=ut(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function ys({r:e,g:n,b:t}){return`${e},${n},${t}`}function Ro(e){return ut(e)?.alpha??1}function Lo({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 wo(e,n,t,o){let r=Pn(n),s=Pn(t),i=Ge(r.r/255),c=Ge(r.g/255),a=Ge(r.b/255),l=Ge(s.r/255),u=Ge(s.g/255),f=Ge(s.b/255);return{r:(i*e+l*o)*lt,g:(c*e+u*o)*lt,b:(a*e+f*o)*lt}}function mg({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 Ge(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function dg(e){return e<=.0031308?e*12.92:1.055*Math.pow(e,1/2.4)-.055}var lt=1/Math.PI;function kn(e,n,t,o,r){let s=Pn(e),i=Pn(t),c=Pn(o),a=Ge(s.r/255),l=Ge(s.g/255),u=Ge(s.b/255),f=Ge(i.r/255),d=Ge(i.g/255),m=Ge(i.b/255),p=Ge(c.r/255),h=Ge(c.g/255),g=Ge(c.b/255),y=a*(f*n+p*r)*lt,b=l*(d*n+h*r)*lt,x=u*(m*n+g*r)*lt,P=M=>Math.max(0,Math.min(255,Math.round(dg(Math.max(0,Math.min(1,M)))*255))),S=P(y),C=P(b),T=P(x),A=Ro(e);return A<1?`rgba(${S}, ${C}, ${T}, ${A})`:Lo({r:S,g:C,b:T})}function bs(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=ut(e);if(!t)return e;let o=255/Math.max(1,Math.round(n)-1),r=i=>Math.max(0,Math.min(255,Math.round(Math.round(i/o)*o))),s={r:r(t.rgb[0]),g:r(t.rgb[1]),b:r(t.rgb[2])};return t.alpha<1?`rgba(${s.r}, ${s.g}, ${s.b}, ${t.alpha})`:Lo(s)}function pg(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function gg(e,n,t){let o=(r,s)=>{let i=s-r;return Math.abs(i)<=t?s:r+Math.sign(i)*t};return{r:o(e.r,n.r),g:o(e.g,n.g),b:o(e.b,n.b)}}function hg(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:Lo(e)}function yg(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=ut(e),o=ut(n);if(!t||!o)return 1;let r=t.rgb[0]-o.rgb[0],s=t.rgb[1]-o.rgb[1],i=t.rgb[2]-o.rgb[2],c=(t.alpha-o.alpha)*255;return Math.sqrt(r*r+s*s+i*i+c*c)/510}function xs(e){let t=c=>Math.round(c/1e-4).toString(36),o=c=>`${t(c[0])},${t(c[1])},${t(c[2])}`,r=(c,a)=>{let l=o(c),u=o(a);return l<u?`${l}|${u}`:`${u}|${l}`},s=new Map;for(let c=0;c<e.length;c++){let a=e[c];if(!a||a.vertices.length<2)continue;let l=a.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=s.get(m);p?(p.degree+=1,p.degree===2?p.polyB=c:p.polyB=null):s.set(m,{polyA:c,polyB:null,vertA:f,vertB:d,degree:1})}}let i=new Map;for(let[c,a]of s)i.set(c,{polyA:a.polyA,polyB:a.polyB,vertA:a.vertA,vertB:a.vertB});return i}function Ps(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,s=n[2]/t;return e.map(i=>i?i[0]*o+i[1]*r+i[2]*s<-1e-6:!0)}function Ms(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),s=l=>`${r(l[0])},${r(l[1])},${r(l[2])}`,i=t.map(([l,u])=>({a:l,b:u,aKey:s(l),bKey:s(u),used:!1})),c=new Map;for(let l of i){let u=c.get(l.aKey);u||(u=[],c.set(l.aKey,u)),u.push(l);let f=c.get(l.bKey);f||(f=[],c.set(l.bKey,f)),f.push(l)}let a=[];for(let l of i){if(l.used)continue;let u=[l.a],f=l,d=l.aKey,m=l.bKey;f.used=!0;for(let p=0;p<i.length+1;p++){u.push(f.bKey===m?f.b:f.a);let h=c.get(m)??[],g=null;for(let y of h)if(!(y===f||y.used)){g=y;break}if(!g||(g.used=!0,d=m,m=g.aKey===d?g.bKey:g.aKey,f=g,m===l.aKey))break}u.length>=3&&a.push(u)}return a}var hc=40;function bg(e){let t=c=>Math.round(c/1e-4).toString(36),o=c=>`${t(c[0])},${t(c[1])},${t(c[2])}`,r=(c,a)=>{let l=o(c),u=o(a);return l<u?`${l}|${u}`:`${u}|${l}`},s=new Map;for(let c=0;c<e.length;c++){let a=e[c];if(!a||a.vertices.length<2)continue;let l=a.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=s.get(m);p||(p=[],s.set(m,p)),p.push(c)}}let i=new Map;for(let c of s.values())if(!(c.length<2))for(let a of c)for(let l of c){if(a===l)continue;let u=i.get(a);u||(u=new Set,i.set(a,u)),u.add(l)}return i}function xg(e,n,t,o){let r=Dt(t),s=!!o&&(o[0]!==0||o[1]!==0||o[2]!==0),i=s?hn(n):null,c=e.map(a=>{if(!a)return{vertices:[],color:""};let l=a.vertices.map(u=>r(u,n));return s&&i&&o&&(l=l.map(u=>{let f=[u[0]-i[0],u[1]-i[1],u[2]-i[2]],d=Vn(f,o);return[d[0]+i[0],d[1]+i[1],d[2]+i[2]]})),{vertices:l,color:""}});return xs(c)}function Pg(e,n,t,o,r){let s=[],i=Dt(t),c=!!r&&(r[0]!==0||r[1]!==0||r[2]!==0),a=c?hn(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(S=>i(S,n));c&&a&&r&&(f=f.map(S=>{let C=[S[0]-a[0],S[1]-a[1],S[2]-a[2]],T=Vn(C,r);return[T[0]+a[0],T[1]+a[1],T[2]+a[2]]}));let d=1/0,m=1/0,p=1/0,h=-1/0,g=-1/0,y=-1/0;for(let S of f)S[0]<d&&(d=S[0]),S[0]>h&&(h=S[0]),S[1]<m&&(m=S[1]),S[1]>g&&(g=S[1]),S[2]<p&&(p=S[2]),S[2]>y&&(y=S[2]);let b=[[d,m,p],[h,m,p],[d,g,p],[h,g,p],[d,m,y],[h,m,y],[d,g,y],[h,g,y]],x=null,P=0;if(f.length>=3){let S=f[0],C=f[1],T=f[2],A=[C[0]-S[0],C[1]-S[1],C[2]-S[2]],M=[T[0]-S[0],T[1]-S[1],T[2]-S[2]],E=M[1]*A[2]-M[2]*A[1],v=M[2]*A[0]-M[0]*A[2],I=M[0]*A[1]-M[1]*A[0],_=Math.hypot(E,v,I);_>1e-9&&(x=[E/_,v/_,I/_],P=x[0]*S[0]+x[1]*S[1]+x[2]*S[2])}s.push({wv:f,bboxCorners:b,planeN:x,planeOffset:P,polygonIndex:l})}return s}function Mg(e,n,t,o,r,s){let i=Dt(t),c=!!s&&(s[0]!==0||s[1]!==0||s[2]!==0),a=c?hn(n):null,f=Zr(e,n,c&&a&&s?(g,y)=>{let b=i(g,y),x=[b[0]-a[0],b[1]-a[1],b[2]-a[2]],P=Vn(x,s);return[P[0]+a[0],P[1]+a[1],P[2]+a[2]]}:i,o).map((g,y)=>{let{O:b,n:x,u:P,v:S,outlineUv:C,memberPolysUv:T,memberPolyIndices:A}=g,M=1/0,E=1/0,v=-1/0,I=-1/0;for(let Q of C)Q[0]<M&&(M=Q[0]),Q[1]<E&&(E=Q[1]),Q[0]>v&&(v=Q[0]),Q[1]>I&&(I=Q[1]);let _=v-M,O=I-E,V=r*50,w=b[0]+M*P[0]+E*S[0]+V*x[0],F=b[1]+M*P[1]+E*S[1]+V*x[1],D=b[2]+M*P[2]+E*S[2]+V*x[2],K=`matrix3d(${[P[0],P[1],P[2],0,S[0],S[1],S[2],0,x[0],x[1],x[2],0,w,F,D,1].map(Q=>Q.toFixed(4)).join(",")})`;return{O:b,n:x,u:P,v:S,outlineUv:C,memberPolysUv:T,memberPolyIndices:A,minU:M,minV:E,width:_,height:O,matrixCss:K,faceIndex:y,lift:V}}),d=.015,m=.5,p=20,h=new Set;for(let g=0;g<f.length;g++){if(h.has(g))continue;let y=f[g],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,S=y.minU+y.width,C=y.minV+y.height;for(let T=0;T<f.length;T++){if(T===g||h.has(T))continue;let A=f[T];if(y.n[0]*A.n[0]+y.n[1]*A.n[1]+y.n[2]*A.n[2]<1-d)continue;let E=y.n[0]*A.O[0]+y.n[1]*A.O[1]+y.n[2]*A.O[2];if(E<=b+m||E-b>p)continue;let v=1/0,I=1/0,_=-1/0,O=-1/0;for(let V of A.outlineUv){let w=A.O[0]+V[0]*A.u[0]+V[1]*A.v[0],F=A.O[1]+V[0]*A.u[1]+V[1]*A.v[1],D=A.O[2]+V[0]*A.u[2]+V[1]*A.v[2],H=w-y.O[0],K=F-y.O[1],Q=D-y.O[2],ne=H*y.u[0]+K*y.u[1]+Q*y.u[2],ee=H*y.v[0]+K*y.v[1]+Q*y.v[2];ne<v&&(v=ne),ne>_&&(_=ne),ee<I&&(I=ee),ee>O&&(O=ee)}if(v<=x&&_>=S&&I<=P&&O>=C){let V=Math.max(0,S-x)*Math.max(0,C-P);if(Math.max(0,_-v)*Math.max(0,O-I)>V*2)continue;h.add(g);break}}}return f=f.filter((g,y)=>!h.has(y)),f}function Ag(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:s,cameraRot:i,ambientLight:c,directionalLight:a,shadow:l}=e,u=Math.hypot(s[0],s[1],s[2])||1,f=s[0]/u,d=s[1]/u,m=s[2]/u,p=c?.color??"#ffffff",h=c?.intensity??.4,g=a?.intensity??1,y=l?.color??"#000000",b=l?.opacity??.25,x=l?.maxExtend??2e3,P=[],S=r.map(A=>{let M=A.edgeOwners;if(!M||A.selfShadowEdgeMap)return null;let E=A.casterPolygonCount??0;if(E<hc||A.items.length<hc)return null;let v=0;for(let O of A.items)O.planeN&&v++;if(v*2<A.items.length)return null;let I=new Array(E).fill(null);for(let O of A.items)O.planeN&&O.polygonIndex<E&&(I[O.polygonIndex]=O.planeN);let _=Ps(I,s);return Ms(M,_)}),C=(A,M,E,v)=>{if(A.length<3)return[];let I=[],_=V=>(V[0]-M[0])*E[0]+(V[1]-M[1])*E[1]+(V[2]-M[2])*E[2],O=(V,w,F,D)=>{let H=(F-v)/(F-D);return[V[0]+H*(w[0]-V[0]),V[1]+H*(w[1]-V[1]),V[2]+H*(w[2]-V[2])]};for(let V=0;V<A.length;V++){let w=A[V],F=A[(V+A.length-1)%A.length],D=_(w),H=_(F),K=D>v,Q=H>v;K?(Q||I.push(O(F,w,H,D)),I.push(w)):Q&&I.push(O(F,w,H,D))}return I},T={rotX:i.rotX,rotY:i.rotY};for(let A of n){let{O:M,n:E,u:v,v:I,outlineUv:_,minU:O,minV:V,width:w,height:F}=A,D=f*E[0]+d*E[1]+m*E[2];if(D<=1e-6||!Nt(E,T))continue;let H=ie=>(ie[0]-M[0])*E[0]+(ie[1]-M[1])*E[1]+(ie[2]-M[2])*E[2],K=(ie,ae,N,X)=>{let oe=N/(N-X);return[ie[0]+oe*(ae[0]-ie[0]),ie[1]+oe*(ae[1]-ie[1]),ie[2]+oe*(ae[2]-ie[2])]},Q=ie=>{let ae=ie[0]-M[0],N=ie[1]-M[1],X=ie[2]-M[2],oe=(ae*E[0]+N*E[1]+X*E[2])/D,Te=ie[0]-oe*f,Ce=ie[1]-oe*d,Pe=ie[2]-oe*m,_e=Te-M[0],Oe=Ce-M[1],Ve=Pe-M[2];return[_e*v[0]+Oe*v[1]+Ve*v[2],_e*I[0]+Oe*I[1]+Ve*I[2]]},ne=new Map,ee=0,ue=O,U=V,$=A.minU+w,k=A.minV+F,L=1/0,W=1/0,Y=-1/0,se=-1/0;for(let ie of r)for(let ae of ie.items)for(let N of ae.wv){let X=N[0]-M[0],oe=N[1]-M[1],Te=N[2]-M[2],Ce=X*v[0]+oe*v[1]+Te*v[2],Pe=X*I[0]+oe*I[1]+Te*I[2];Ce<L&&(L=Ce),Ce>Y&&(Y=Ce),Pe<W&&(W=Pe),Pe>se&&(se=Pe)}let Z=Number.isFinite(L)?[[L-x,W-x],[Y+x,W-x],[Y+x,se+x],[L-x,se+x]]:[],B=.05,q=E[0]*M[0]+E[1]*M[1]+E[2]*M[2],me=.0025,fe=5;for(let ie=0;ie<r.length;ie++){let ae=r[ie],N=ae.selfShadowEdgeMap,X=S[ie];if(X!==null){if(X.length===0)continue;for(let oe of X){if(oe.length<3)continue;let Te=C(oe,M,E,B);if(Te.length<3)continue;let Ce=Te.map(Q),Pe=gn(Ce),_e=Z.length===4?Sn(Pe,Z):Pe;if(_e.length<3)continue;let Oe=Sn(_e,_);if(Oe.length<3)continue;let Ve;for(let $e of A.memberPolysUv){let Ee=Sn(Oe,gn($e));Ee.length<3||(Ve||(Ve=ne.get(ae.id),Ve||(Ve={id:ae.id,verts:[],subPolygonIndices:[]},ne.set(ae.id,Ve))),Ve.verts.push(Ee),Ve.subPolygonIndices.push(-1),ee++)}}continue}for(let oe of ae.items){if(N){let Ee=N.get(oe.polygonIndex);if(Ee){let Fe=!1;for(let we of A.memberPolyIndices)if(Ee.has(we)){Fe=!0;break}if(Fe)continue}}if(oe.planeN&&oe.planeN[0]*f+oe.planeN[1]*d+oe.planeN[2]*m>-1e-6)continue;if(oe.planeN){let Ee=oe.planeN,Fe=Ee[0]*E[0]+Ee[1]*E[1]+Ee[2]*E[2];if(Math.abs(Fe)>1-me){let we=Fe>0?1:-1;if(Math.abs(oe.planeOffset-we*q)<fe)continue}}let Te=oe.bboxCorners,Ce=!1,Pe=1/0,_e=1/0,Oe=-1/0,Ve=-1/0;for(let Ee=0;Ee<8;Ee++){let Fe=Te[Ee];H(Fe)>B&&(Ce=!0);let we=Q(Fe);we[0]<Pe&&(Pe=we[0]),we[0]>Oe&&(Oe=we[0]),we[1]<_e&&(_e=we[1]),we[1]>Ve&&(Ve=we[1])}if(!Ce||Oe<ue||Pe>$||Ve<U||_e>k)continue;let $e=oe.wv;for(let Ee=1;Ee<$e.length-1;Ee++){let Fe=$e[0],we=$e[Ee],$n=$e[Ee+1],Xn=H(Fe),cn=H(we),qe=H($n),ln=[],Be=[[Fe,Xn],[we,cn],[$n,qe]];for(let Ye=0;Ye<3;Ye++){let[ve,Qe]=Be[Ye],[on,Je]=Be[(Ye+1)%3],We=Qe>B,rn=Je>B;We&&ln.push(ve),We!==rn&&ln.push(K(ve,on,Qe,Je))}if(ln.length<3)continue;let Xe=ln.map(Q),Me=gn(Xe),Re=Z.length===4?Sn(Me,Z):Me;if(Re.length<3)continue;let Le=Sn(Re,_);if(Le.length<3)continue;let Ie;for(let Ye of A.memberPolysUv){let ve=Sn(Le,gn(Ye));if(!(ve.length<3)){if(N){let Qe=0,on=1/0,Je=-1/0,We=1/0,rn=-1/0;for(let sn=0;sn<ve.length;sn++){let je=ve[sn],Wn=ve[(sn+1)%ve.length];Qe+=je[0]*Wn[1]-Wn[0]*je[1],je[0]<on&&(on=je[0]),je[0]>Je&&(Je=je[0]),je[1]<We&&(We=je[1]),je[1]>rn&&(rn=je[1])}if(Math.abs(Qe)*.5<5)continue}Ie||(Ie=ne.get(ae.id),Ie||(Ie={id:ae.id,verts:[],subPolygonIndices:[]},ne.set(ae.id,Ie))),Ie.verts.push(ve),Ie.subPolygonIndices.push(oe.polygonIndex),ee++}}}}}if(ee===0||!(w>0)||!(F>0))continue;let G=b;if(o){let ae=g*Math.max(0,D)+Math.max(0,h);if(ae>0){let N=Math.max(0,h)/ae,X=Math.pow(N,1/2.4);G=b*(1-X)}else G=0}let te=A.memberPolyIndices[0]??0,ce=t[te]?.color??"#cccccc",ye=o?y:kn(ce,0,"#000000",p,h),he=1/0,be=1/0,ge=-1/0,Se=-1/0;for(let ie of ne.values())for(let ae of ie.verts)for(let N of ae)N[0]<he&&(he=N[0]),N[0]>ge&&(ge=N[0]),N[1]<be&&(be=N[1]),N[1]>Se&&(Se=N[1]);he=Math.floor(he-1),be=Math.floor(be-1),ge=Math.ceil(ge+1),Se=Math.ceil(Se+1),he<O&&(he=O),be<V&&(be=V),ge>O+w&&(ge=O+w),Se>V+F&&(Se=V+F);let De=ge-he,R=Se-be;if(!(De>0)||!(R>0))continue;let z=A.lift,j=M[0]+he*v[0]+be*I[0]+z*E[0],J=M[1]+he*v[1]+be*I[1]+z*E[1],le=M[2]+he*v[2]+be*I[2]+z*E[2],pe=`matrix3d(${[v[0],v[1],v[2],0,I[0],I[1],I[2],0,E[0],E[1],E[2],0,j,J,le,1].map(ie=>ie.toFixed(4)).join(",")})`,xe=[];for(let ie of ne.values()){let ae="";for(let N of ie.verts){ae+=`M${(N[0][0]-he).toFixed(1)},${(N[0][1]-be).toFixed(1)}`;for(let X=1;X<N.length;X++)ae+=`L${(N[X][0]-he).toFixed(1)},${(N[X][1]-be).toFixed(1)}`;ae+="Z"}xe.push({casterId:ie.id,d:ae,casterPolygonIndices:ie.subPolygonIndices})}P.push({faceIndex:A.faceIndex,memberPolyIndices:A.memberPolyIndices,matrixCss:pe,width:De,height:R,fill:ye,opacity:G,paths:xe})}return P}var Sg=Symbol.for("polycss.animation.triangleFrameSource"),Cg=Symbol.for("polycss.animation.triangleFrameTarget"),yc=2200,Ss=2201,bc=2202;function Eg(e,n){let t=0,o=1,r=1,s=Ss,i=1/0,c=0,a=!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 a},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return a=!0,d},stop(){return a=!1,t=0,c=0,l=null,d},reset(){return t=0,c=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 s=m,i=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 a},get loopMode(){return s},get repetitions(){return i},get completedReps(){return c},set completedReps(m){c=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!a)return;if(l){l.elapsed+=m;let h=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(o=l.from+(l.to-l.from)*h,h>=1&&(o=l.to,l=null,o<=0)){a=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(t+=m*r,s===yc)t>=p&&(t=d.clampWhenFinished?p:0,a=!1);else if(s===Ss){if(t>=p){let h=t%p,g=Math.floor(t/p);c+=g,t=h,i!==1/0&&c>=i&&(t=d.clampWhenFinished?p:0,a=!1)}}else if(p>0){let h=p*2,g=t%h;if(t>=h){let y=Math.floor(t/h);c+=y,i!==1/0&&c>=i?(t=d.clampWhenFinished?p:0,a=!1):t=g}}}},sampleTime(){if(s===bc){let m=e.duration,p=m*2,h=t%p;return h<=m?h:p-h}return t}},d}function Tg(e){return e._internal}function As(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function vg(e,n){let t=new Map,o=n,r=e;function s(f){let d=As(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=Eg(d,n),t.set(d.index,m)),m}function i(f){let d=As(n.clips,f);return d?t.get(d.index)??null:null}function c(f){let d=[];for(let y of t.values()){let b=Tg(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[Sg]?.(b.name,x);if(P&&r[Cg]?.(P))return;let S=n.sample(b.name,x);e.setPolygons(S);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})),h=p[0].polygons;if(h.length===0)return;let g=h.map((y,b)=>{let x=y.vertices.map((P,S)=>{let C=0,T=0,A=0;for(let{polygons:M,weight:E}of p){let v=M[b];if(!v)continue;let I=v.vertices[S];I&&(C+=I[0]*E,T+=I[1]*E,A+=I[2]*E)}return[C,T,A]});return{...y,vertices:x}});e.setPolygons(g)}function a(){for(let f of t.values())f.stop()}function l(f){let d=As(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:s,existingAction:i,update:c,stopAllAction:a,uncacheClip:l,uncacheRoot:u}}var Es={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Sc={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ig={0:"POINTS",1:"LINES",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN"},Ts=["EXT_meshopt_compression","KHR_meshopt_compression"];function _g(e){return e===5120||e===5121||e===5122||e===5123}function Cc(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Og(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 i=decodeURIComponent(o),c=new Uint8Array(i.length);for(let a=0;a<i.length;a++)c[a]=i.charCodeAt(a)&255;return c}let r=globalThis.atob(o),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s}function Vg(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,s=null;for(;o<e.byteLength;){let i=n.getUint32(o,!0),c=n.getUint32(o+4,!0),a=o+8;if(c===1313821514){let l=new Uint8Array(e,a,i);r=JSON.parse(Cc(l))}else c===5130562&&(s=new Uint8Array(e,a,i));o=a+i}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:s}}function xc(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function Rg(e){let n=xc(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=xc(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 Lg(e,n,t){let o=e.buffers??[],r=new Set(e.extensionsRequired??[]),s=Ts.some(i=>r.has(i));return o.map((i,c)=>{let a=i.uri;if(a){if(a.startsWith("data:"))return Og(a);if(t){let l=t(a);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 "${a}" \u2014 provide options.resolveBuffer`)}if(c===0&&n)return n;if(s&&Ts.some(l=>i.extensions?.[l]))return new Uint8Array(0);throw new Error(`parseGltf: buffer[${c}] has no uri and no GLB BIN chunk`)})}function Ut(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 s=o.byteOffset??0;if(s<0||o.byteLength<0||s+o.byteLength>r.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${o.buffer}`);return{buffer:r,view:o}}function Ec(e,n,t,o){if(e.count<=0)return;let r=e.byteOffset??0,s=r+t*(e.count-1)+o;if(r<0||s>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function Tc(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function wg(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 No(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Es[o.componentType],s=Sc[o.type];if(!r||!s)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);if(o.sparse||o.normalized||o.bufferView===void 0){let{values:g}=Gt(e,n,t);return{array:wg(o.componentType,g,o.normalized),count:o.count,componentCount:s}}let{buffer:i,view:c}=Ut(e,n,o.bufferView),a=(c.byteOffset??0)+(o.byteOffset??0),l=o.count*s,u=r*s,f=Tc(c,u);if(Ec(o,c,f,u),f===u){let g=i.buffer.slice(i.byteOffset+a,i.byteOffset+a+l*r),y;switch(o.componentType){case 5120:y=new Int8Array(g);break;case 5121:y=new Uint8Array(g);break;case 5122:y=new Int16Array(g);break;case 5123:y=new Uint16Array(g);break;case 5125:y=new Uint32Array(g);break;case 5126:y=new Float32Array(g);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}return{array:y,count:o.count,componentCount:s}}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(i.buffer),p=i.byteOffset+a,h=0;for(let g=0;g<o.count;g++){let y=p+g*f;for(let b=0;b<s;b++)d[h++]=Bo(m,y+b*r,o.componentType)}return{array:d,count:o.count,componentCount:s}}function Bo(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 Pc(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 Gt(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Es[o.componentType],s=Sc[o.type];if(!r||!s)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);let i=r*s,c=new Array(o.count*s).fill(0);if(o.bufferView!==void 0){let{buffer:a,view:l}=Ut(e,n,o.bufferView),u=a.byteOffset+(l.byteOffset??0)+(o.byteOffset??0),f=Tc(l,i);Ec(o,l,f,i);let d=new DataView(a.buffer),m=0;for(let p=0;p<o.count;p++){let h=u+p*f;for(let g=0;g<s;g++){let y=Bo(d,h+g*r,o.componentType);c[m++]=o.normalized?Pc(y,o.componentType):y}}}if(o.sparse){let a=o.sparse,l=a.indices,u=Es[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}=Ut(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),p=new DataView(f.buffer),{buffer:h,view:g}=Ut(e,n,a.values.bufferView),y=h.byteOffset+(g.byteOffset??0)+(a.values.byteOffset??0),b=new DataView(h.buffer);for(let x=0;x<a.count;x++){let P=Bo(p,m+x*u,l.componentType);for(let S=0;S<s;S++){let C=Bo(b,y+(x*s+S)*r,o.componentType);c[P*s+S]=o.normalized?Pc(C,o.componentType):C}}}return{values:c,count:o.count,componentCount:s}}function Ng(e,n,t){let o=[],r=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(t&&!i.uri.startsWith("data:"))try{o.push(new s.URL(i.uri,t).href)}catch{o.push(i.uri)}else o.push(i.uri);continue}if(i.bufferView!==void 0){let c;try{let{buffer:f,view:d}=Ut(e,n,i.bufferView),m=d.byteOffset??0;c=f.subarray(m,m+d.byteLength)}catch{o.push("");continue}let a=i.mimeType??"image/png",l=new s.Blob([c],{type:a}),u=s.URL.createObjectURL(l);o.push(u),r.push(u)}else o.push("")}return{urls:o,objectUrls:r}}function Mc(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function Dg(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:Mc(t?.wrapS),t:Mc(t?.wrapT)}}function vc(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function Fg(e,n){let t=new Map,o=e.materials??[];for(let r=0;r<o.length;r++){let s=o[r].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s],c=i?.source;if(c===void 0)continue;let a=n[c];a&&t.set(r,{url:a,wrap:Dg(e,i),alphaMode:vc(o[r].alphaMode),texCoord:o[r].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function Bg(e,n,t){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let r=a=>Math.max(0,Math.min(1,a)),s=a=>Math.round(r(a)*255).toString(16).padStart(2,"0"),i=a=>Math.round(r(a)*255),c=t==="opaque"?1:r(o[3]??1);return c<1?`rgba(${i(o[0])}, ${i(o[1])}, ${i(o[2])}, ${Math.round(c*1e3)/1e3})`:`#${s(o[0])}${s(o[1])}${s(o[2])}`}var ft=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Ic(e,n){let t=new Array(16);return _c(t,e,n)}function _c(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 Do(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 Oc(e,n,t){let o=e?.[0]??0,r=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,c=n?.[1]??0,a=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=i+i,p=c+c,h=a+a,g=i*m,y=i*p,b=i*h,x=c*p,P=c*h,S=a*h,C=l*m,T=l*p,A=l*h;return[(1-(x+S))*u,(y+A)*u,(b-T)*u,0,(y-A)*f,(1-(g+S))*f,(P+C)*f,0,(b+T)*d,(P-C)*d,(1-(g+x))*d,0,o,r,s,1]}function kg(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Oc(e.translation,e.rotation,e.scale)}function Vc(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 kt(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 Ug(e,n,t){let o=kt(e),r=kt(n),s=o[0]*r[0]+o[1]*r[1]+o[2]*r[2]+o[3]*r[3];if(s<0&&(s=-s,r=[-r[0],-r[1],-r[2],-r[3]]),s>.9995)return kt(Vc(o,r,t));let i=Math.acos(Math.max(-1,Math.min(1,s))),c=Math.sin(i),a=Math.sin((1-t)*i)/c,l=Math.sin(t*i)/c;return kt([o[0]*a+r[0]*l,o[1]*a+r[1]*l,o[2]*a+r[2]*l,o[3]*a+r[3]*l])}function Rc(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 Lc(e){return e.matrix?e.matrix.slice():Oc(e.translation,e.rotation,e.scale)}function Gg(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function wc(e,n){let t=e.nodes??[],o=new Array(t.length),r=new Set,s=new Set,i=(a,l)=>{if(a<0||a>=t.length||s.has(a))return;let u=Ic(l,n[a]??ft);o[a]=u,r.add(a),s.add(a);for(let f of t[a].children??[])i(f,u);s.delete(a)},c=Gg(e);if(c.length>0)for(let a of c)i(a,ft);for(let a=0;a<t.length;a++)r.has(a)||i(a,ft);return o}var Nc=Symbol("polycss.gltfAnimationRuntimeInfo"),zg=Symbol.for("polycss.animation.triangleFrameSource");function Dc(e,n){return e?e[Nc]?.withPolygonFilter(n):void 0}function Cs(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function $g(e,n,t){return Cs(e,n)||Cs(e,t)||Cs(n,t)}function Ac(e,n,t,o,r){if(t===void 0)return;let{values:s,count:i,componentCount:c}=Gt(e,n,t);if(i!==r||c<1)return;let a=[];for(let l=0;l<i;l++){let u=[];for(let f=0;f<o;f++)u.push(s[l*c+f]??0);a.push(u)}return a}function Xg(e,n,t,o){if(t===void 0)return Array.from({length:o},()=>ft.slice());let{values:r,componentCount:s,count:i}=Gt(e,n,t);if(s!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${t} is not MAT4`);let c=[];for(let a=0;a<o;a++){let l=Math.min(a,i-1);c.push(r.slice(l*16,l*16+16))}return c}function Fo(e,n){let t=e.componentCount,o=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(o,o+t)}function Yg(e,n,t){let o=e.input;if(o.length===0)return[];if(o.length===1||n<=o[0])return Fo(e,0);let r=o.length-1;if(n>=o[r])return Fo(e,r);let s=0,i=r;for(;s+1<i;){let d=s+i>>1;o[d]<=n?s=d:i=d}let c=o[s],a=o[s+1],l=a>c?(n-c)/(a-c):0,u=Fo(e,s),f=Fo(e,s+1);return e.interpolation==="STEP"?u:t==="rotation"?Ug(u,f,l):Vc(u,f,l)}function Fc(e,n){let t=[];for(let o=0;o<(e.animations?.length??0);o++){let r=e.animations[o],s=(r.samplers??[]).map(a=>{let l=Gt(e,n,a.input),u=Gt(e,n,a.output);return{input:l.values,output:u.values,componentCount:u.componentCount,interpolation:a.interpolation??"LINEAR"}}),i=[];for(let a of r.channels??[]){let l=a.target.node,u=a.target.path,f=s[a.sampler];l===void 0||!u||!f||u!=="translation"&&u!=="rotation"&&u!=="scale"||i.push({sampler:f,targetNode:l,path:u})}let c=i.reduce((a,l)=>{let u=l.sampler.input;return Math.max(a,u[u.length-1]??0)},0);t.push({info:{index:o,name:r.name??`animation_${o}`,duration:c,channelCount:i.length},channels:i})}return t}function Bc(e,n,t,o){let r=t.info.duration,s=r>0?(o%r+r)%r:Math.max(0,o),i=n.map(c=>({translation:c.translation.slice(),rotation:c.rotation.slice(),scale:c.scale.slice(),matrix:c.matrix?c.matrix.slice():void 0}));for(let c of t.channels){let a=i[c.targetNode];if(!a)continue;let l=Yg(c.sampler,s,c.path);a.matrix=void 0,c.path==="translation"?a.translation=l.slice(0,3):c.path==="rotation"?a.rotation=kt(l.slice(0,4)):c.path==="scale"&&(a.scale=l.slice(0,3))}return wc(e,i.map(Lc))}function Wg(e,n,t,o,r,s){if((e.animations??[]).length===0||t.length===0)return;let c=(e.nodes??[]).map(g=>Rc(g)),a=c.map(Lc),l=wc(e,a),u=(e.skins??[]).map(g=>({joints:g.joints??[],inverseBindMatrices:Xg(e,n,g.inverseBindMatrices,g.joints?.length??0)})),f=Fc(e,n),d=f.map(g=>g.info);if(d.length===0)return;let m=g=>{let y=t.map(b=>new Array(b.triangleMask.length).fill(!1));for(let b of g){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],S=new Set,C=0;for(let T=0;T+2<P.indices.length;T+=3,C++)b[C]&&(S.add(P.indices[T]),S.add(P.indices[T+1]),S.add(P.indices[T+2]));return{triangleMask:b,activeVertices:Array.from(S).sort((T,A)=>T-A)}})},p=(g,y,b,x,P,S,C,T,A)=>{let M=r(g),E=r(y),v=r(b),I={vertices:[M,E,v],color:x};return P&&(I.texture=P),P&&S&&(I.textureWrap=S),P&&C&&(I.textureAlphaMode=C),T&&(I.doubleSided=!0),A&&(I.uvs=A),I},h=g=>{let y=t.reduce((_,O,V)=>{let w=g?.[V]?.triangleMask??O.triangleMask,F=0;for(let D=0;D<w.length;D++)w[D]&&F++;return _+F},0),b=new Float64Array(Math.max(0,y*9)),x=new Array(y),P=new Array(y).fill(!1),S={polygonCount:0,vertices:b,colors:x,textureFlags:P,solidTriangles:!0},C=t.map(_=>new Array(_.positions.length)),T=u.map(_=>_.joints.map(()=>new Array(16))),A=(_,O)=>{let V=typeof _=="number"?f[_]:f.find(w=>w.info.name===_);return V?Bc(e,c,V,O):null},M=(_,O,V,w)=>{let F=V?.activeVertices,D=C[_],H=(K,Q,ne,ee)=>{let ue=D[K];ue?(ue[0]=Q,ue[1]=ne,ue[2]=ee):D[K]=[Q,ne,ee]};if(O.skinIndex!==void 0&&O.joints&&O.weights&&u[O.skinIndex]){let K=u[O.skinIndex],Q=O.joints,ne=O.weights,ee=T[O.skinIndex]??[];for(let U=0;U<K.joints.length;U++){let $=K.joints[U],k=w[$],L=K.inverseBindMatrices[U],W=ee[U]??(ee[U]=new Array(16));ee[U]=k&&L?_c(W,k,L):void 0}let ue=U=>{let $=O.positions[U],k=0,L=0,W=0,Y=0,se=Q[U]??[],Z=ne[U]??[];for(let B=0;B<4;B++){let q=Z[B]??0;if(q<=0)continue;let me=Math.round(se[B]??0),fe=ee[me];if(!fe)continue;let G=fe[0]*$[0]+fe[4]*$[1]+fe[8]*$[2]+fe[12],te=fe[1]*$[0]+fe[5]*$[1]+fe[9]*$[2]+fe[13],ce=fe[2]*$[0]+fe[6]*$[1]+fe[10]*$[2]+fe[14];k+=G*q,L+=te*q,W+=ce*q,Y+=q}if(Y>0){let B=1/Y;H(U,k*B,L*B,W*B)}else H(U,O.meshBindWorld[0]*$[0]+O.meshBindWorld[4]*$[1]+O.meshBindWorld[8]*$[2]+O.meshBindWorld[12],O.meshBindWorld[1]*$[0]+O.meshBindWorld[5]*$[1]+O.meshBindWorld[9]*$[2]+O.meshBindWorld[13],O.meshBindWorld[2]*$[0]+O.meshBindWorld[6]*$[1]+O.meshBindWorld[10]*$[2]+O.meshBindWorld[14])};if(F)for(let U of F)ue(U);else for(let U=0;U<O.positions.length;U++)ue(U)}else{let K=O.meshNode!==null?w[O.meshNode]??O.meshBindWorld:O.meshBindWorld,Q=ne=>{let ee=O.positions[ne];H(ne,K[0]*ee[0]+K[4]*ee[1]+K[8]*ee[2]+K[12],K[1]*ee[0]+K[5]*ee[1]+K[9]*ee[2]+K[13],K[2]*ee[0]+K[6]*ee[1]+K[10]*ee[2]+K[14])};if(F)for(let ne of F)Q(ne);else for(let ne=0;ne<O.positions.length;ne++)Q(ne)}return D},E=(_,O)=>{let V=A(_,O);if(!V)return[];let w=[];for(let F=0;F<t.length;F++){let D=t[F],H=g?.[F],K=H?.triangleMask??D.triangleMask,Q=M(F,D,H,V),ne=0;for(let ee=0;ee+2<D.indices.length;ee+=3,ne++){if(!K[ne])continue;let ue=D.indices[ee],U=D.indices[ee+1],$=D.indices[ee+2],k=Q[ue],L=Q[U],W=Q[$];if(!k||!L||!W)continue;let Y;if(D.uvs&&D.texture){let Z=D.uvs[ue],B=D.uvs[U],q=D.uvs[$];Z&&B&&q&&(Y=[Z,B,q])}let se=p(k,L,W,D.color,D.texture,D.textureWrap,D.textureAlphaMode,D.doubleSided,Y);se&&w.push(se)}}return w},v=(_,O)=>{let V=A(_,O);if(!V)return null;b.length<y*9&&(b=new Float64Array(y*9),S.vertices=b),x.length<y&&(x=new Array(y),S.colors=x),P.length<y&&(P=new Array(y).fill(!1),S.textureFlags=P);let w=0,F=0,D=!1;for(let H=0;H<t.length;H++){let K=t[H],Q=g?.[H],ne=Q?.triangleMask??K.triangleMask,ee=M(H,K,Q,V),ue=0;for(let U=0;U+2<K.indices.length;U+=3,ue++){if(!ne[ue])continue;let $=K.indices[U],k=K.indices[U+1],L=K.indices[U+2],W=ee[$],Y=ee[k],se=ee[L];if(!W||!Y||!se)continue;s(W,b,F),s(Y,b,F+3),s(se,b,F+6),x[w]=K.color;let Z=!!K.texture;P[w]=Z,Z&&(D=!0),w++,F+=9}}return S.polygonCount=w,S.solidTriangles=!D,S},I={clips:d,sample:E};return I[zg]=v,I[Nc]={withPolygonFilter(_){let O=m(_);return O?h(O):void 0}},I};return h()}function vs(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.materialColors??{},s=n?.materialTextures??{},i=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,c=i.byteLength,a,l=null;if(i.byteLength>=4&&new DataView(i).getUint32(0,!0)===1179937895){let R=Vg(i);a=R.doc,l=R.bin}else a=JSON.parse(Cc(new Uint8Array(i)));Rg(a);let u=Lg(a,l,n?.resolveBuffer),{urls:f,objectUrls:d}=Ng(a,u,n?.baseUrl),m=Fg(a,f),p=[],h=new Set,g=new Set(a.extensionsRequired??[]),y=g.has("KHR_mesh_quantization")||(a.extensionsUsed??[]).includes("KHR_mesh_quantization");function b(R,z){h.has(R)||(h.add(R),p.push(z))}function x(R,z){if(R===void 0)return!1;let j=a.accessors?.[R];if(!j)return!1;let J=le=>a.bufferViews?.[le]?.extensions?.[z]!==void 0;return!!(j.bufferView!==void 0&&J(j.bufferView)||j.sparse&&(J(j.sparse.indices.bufferView)||J(j.sparse.values.bufferView)))}function P(R){for(let z of Ts)if(g.has(z)&&(R.extensions?.[z]||x(R.indices,z)||Object.values(R.attributes??{}).some(j=>x(j,z))))return z}function S(R,z){if(z instanceof Float32Array)return!0;let j=a.accessors?.[R];return y&&j?.type==="VEC3"&&_g(j.componentType)}function C(R,z){return(z!==null?a.nodes?.[z]?.weights:void 0)??R.weights??[]}function T(R,z,j,J,le){let re=j.targets;if(!re||re.length===0)return;let pe=C(R,J);if(!pe.some(ae=>Number.isFinite(ae)&&ae!==0))return;let xe=Array.from({length:le},()=>[0,0,0]),ie=!1;for(let ae=0;ae<re.length;ae++){let N=pe[ae]??0;if(!Number.isFinite(N)||N===0)continue;let X=re[ae]?.POSITION;if(X===void 0)continue;let{array:oe,count:Te,componentCount:Ce}=No(a,u,X);if(Te!==le||Ce<3){b(`morph-position-count:${z}:${ae}`,`Mesh ${R.name??z}: skipped morph target ${ae} POSITION with mismatched count`);continue}if(!S(X,oe)){b(`morph-position-type:${z}:${ae}`,`Mesh ${R.name??z}: skipped morph target ${ae} POSITION with unsupported accessor type`);continue}ie=!0;for(let Pe=0;Pe<le;Pe++){let _e=Pe*Ce,Oe=xe[Pe];Oe[0]+=Number(oe[_e])*N,Oe[1]+=Number(oe[_e+1])*N,Oe[2]+=Number(oe[_e+2])*N}}return ie?xe:void 0}let A=[],M=[],E=[],v=(a.meshes??[]).map((R,z)=>R.name??`mesh_${z}`),I=(a.materials??[]).map((R,z)=>R.name??`material_${z}`);function _(R,z){if(z===4)return R;let j=[];if(z===5)for(let J=0;J+2<R.length;J++)j.push(R[J],R[J+1+J%2],R[J+2-J%2]);else if(z===6)for(let J=0;J+2<R.length;J++)j.push(R[J+1],R[J+2],R[0]);return j}function O(R){let z=[];for(let j=0;j+2<R.length;j+=3){let J=R[j],le=R[j+1],re=R[j+2];z.push(J,le,re,J,re,le)}return z}function V(R,z,j){let J=a.meshes?.[R];if(J){if(!Array.isArray(J.primitives)){b(`malformed-primitives:${R}`,`Mesh ${J.name??R}: skipped mesh with non-array primitives`);return}for(let le=0;le<J.primitives.length;le+=1){let re=J.primitives[le];if(!re)continue;let pe=re.mode??4;if(pe!==4&&pe!==5&&pe!==6){let Me=Ig[pe]??`mode ${pe}`;b(`unsupported-mode:${pe}`,`Skipped primitives with unsupported mode ${pe} (${Me})`);continue}if(re.extensions?.KHR_draco_mesh_compression&&g.has("KHR_draco_mesh_compression")){b("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}let xe=P(re);if(xe){b(xe,`Skipped primitives with unsupported required extension ${xe}`);continue}if(re.attributes.POSITION===void 0){b(`missing-position:${R}`,`Mesh ${J.name??R}: skipped primitive without POSITION attribute`);continue}let ie=re.material!==void 0?a.materials?.[re.material]:void 0,ae=vc(ie?.alphaMode),N=ie?.name,oe=(N?r[N]:void 0)??Bg(ie,o,ae),Te=ie?.doubleSided===!0,Ce=re.material!==void 0?m.get(re.material):void 0,Pe=N&&s[N]?s[N]:re.material!==void 0?Ce?.url:void 0,_e=Pe&&re.material!==void 0?Ce?.wrap:void 0,Oe=Pe?Ce?.alphaMode??ae:void 0,Ve=Pe?Ce?.texCoord??0:0,$e=re.attributes.POSITION,{array:Ee,count:Fe,componentCount:we}=No(a,u,$e);if(!S($e,Ee))continue;let $n=T(J,R,re,j,Fe),Xn=[],cn=[];for(let Me=0;Me<Fe;Me++){let Re=Me*we,Le=$n?.[Me],Ie=[Number(Ee[Re])+(Le?.[0]??0),Number(Ee[Re+1])+(Le?.[1]??0),Number(Ee[Re+2])+(Le?.[2]??0)];Xn.push(Ie),cn.push(Do(z,Ie))}let qe=null,ln=re.attributes[`TEXCOORD_${Ve}`];if(Pe&&ln!==void 0){let{array:Me,count:Re}=No(a,u,ln);qe=[];let Le=1;Me instanceof Uint8Array?Le=1/255:Me instanceof Uint16Array&&(Le=1/65535);for(let Ie=0;Ie<Re;Ie++){let Ye=Me[Ie*2]*Le,ve=Me[Ie*2+1]*Le;qe.push([Ye,1-ve])}}let Be;if(re.indices!==void 0){let{array:Me,count:Re}=No(a,u,re.indices);Be=[];for(let Le=0;Le<Re;Le++)Be.push(Number(Me[Le]))}else Be=cn.map((Me,Re)=>Re);Be=_(Be,pe),Te&&(Be=O(Be));let Xe;if((a.animations?.length??0)>0){let Me=Ac(a,u,re.attributes.JOINTS_0,4,Fe),Re=Ac(a,u,re.attributes.WEIGHTS_0,4,Fe);Xe={sourceIndex:M.length,meshNode:j,meshBindWorld:z,skinIndex:j!==null?a.nodes?.[j]?.skin:void 0,positions:Xn,indices:Be,triangleMask:[],color:oe,texture:Pe,textureWrap:_e,textureAlphaMode:Oe,doubleSided:Te,uvs:qe??void 0,joints:Me,weights:Re},M.push(Xe)}for(let Me=0;Me+2<Be.length;Me+=3){let Re=Be[Me],Le=Be[Me+1],Ie=Be[Me+2],Ye=Xe?Xe.triangleMask.length:void 0;Xe&&Xe.triangleMask.push(!1);let ve=cn[Re],Qe=cn[Le],on=cn[Ie];if(!ve||!Qe||!on)continue;let Je;if(qe&&Pe){let rn=qe[Re],Yn=qe[Le],sn=qe[Ie];rn&&Yn&&sn&&(Je=[rn,Yn,sn])}let We=`${R}:${le}:${j??"root"}`;A.push({v0:ve,v1:Qe,v2:on,color:oe,texture:Pe,textureWrap:_e,textureAlphaMode:Oe,doubleSided:Te,uvs:Je,simplifySourceVertexKeys:[`${We}:${Re}`,`${We}:${Le}`,`${We}:${Ie}`],source:Xe,sourceIndex:Xe?.sourceIndex,sourceTriangleIndex:Ye})}}}}function w(R,z,j){if(j.has(R)){b(`recursive-node:${R}`,`Skipped recursive node reference ${R} in glTF scene graph`);return}let J=a.nodes?.[R];if(!J)return;let le=Ic(z,kg(J));typeof J.mesh=="number"&&V(J.mesh,le,R),j.add(R);for(let re of J.children??[])w(re,le,j);j.delete(R)}function F(R){let z=new Set,j=R.info.duration;for(let J of R.channels)for(let le of J.sampler.input)!Number.isFinite(le)||le<=0||j>0&&le>=j||z.add(le);return j>0&&(z.add(j*.25),z.add(j*.5),z.add(j*.75)),Array.from(z).sort((J,le)=>J-le).slice(0,128)}function D(R,z){let j=R.source;if(!j||R.sourceTriangleIndex===void 0||j.skinIndex!==void 0)return;let J=R.sourceTriangleIndex*3,le=j.indices[J],re=j.indices[J+1],pe=j.indices[J+2],xe=le!==void 0?j.positions[le]:void 0,ie=re!==void 0?j.positions[re]:void 0,ae=pe!==void 0?j.positions[pe]:void 0;if(!xe||!ie||!ae)return;let N=j.meshNode!==null?z[j.meshNode]??j.meshBindWorld:j.meshBindWorld;return{v0:Do(N,xe),v1:Do(N,ie),v2:Do(N,ae)}}function H(R,z){return R[0]===z[0]&&R[1]===z[1]&&R[2]===z[2]}function K(R){return H(R.v0,R.v1)||H(R.v0,R.v2)||H(R.v1,R.v2)}function Q(){return A.some(R=>!K(R))}function ne(){if(A.length===0||(a.animations?.length??0)===0||Q())return;let R=Fc(a,u);if(R.length===0)return;let z=(a.nodes??[]).map(J=>Rc(J)),j=new Array(A.length);for(let J of R)for(let le of F(J)){let re=Bc(a,z,J,le);for(let pe=0;pe<A.length;pe++){if(j[pe])continue;let xe=D(A[pe],re);xe&&!K(xe)&&(j[pe]=xe)}}if(j.some(Boolean))for(let J=0;J<A.length;J++){let le=j[J];le&&(A[J].v0=le.v0,A[J].v1=le.v1,A[J].v2=le.v2)}}let ee=a.scene??0,ue=a.scenes?.[ee]?.nodes;if(ue&&ue.length>0)for(let R of ue)w(R,ft,new Set);else{(a.meshes?.length??0)===0&&b("no-gltf-meshes","No glTF meshes found");for(let R=0;R<(a.meshes?.length??0);R++)V(R,ft,null)}ne();let U=jg(d);if(A.length===0)return{polygons:[],objectUrls:d,dispose:U,warnings:p,metadata:{triangleCount:0,meshes:v,materials:I,sourceBytes:c}};let $=1/0,k=1/0,L=1/0,W=-1/0,Y=-1/0,se=-1/0;for(let R of A)for(let z of[R.v0,R.v1,R.v2])z[0]<$&&($=z[0]),z[0]>W&&(W=z[0]),z[1]<k&&(k=z[1]),z[1]>Y&&(Y=z[1]),z[2]<L&&(L=z[2]),z[2]>se&&(se=z[2]);let Z=Math.max(W-$,Y-k,se-L),B=Z>0?t/Z:1,q=n?.center,me=q===!0||q==="center",fe=me?($+W)*.5:$,G=me?(k+Y)*.5:k,te=me?(L+se)*.5:L,ce=R=>Math.round(R*1e3)/1e3,ye=n?.upAxis??"y",he=ye==="z"?([R,z,j])=>[ce((R-fe)*B),ce((z-G)*B),ce((j-te)*B)]:([R,z,j])=>[ce((j-te)*B),ce((R-fe)*B),ce((z-G)*B)],be=ye==="z"?(R,z,j)=>{z[j]=ce((R[0]-fe)*B),z[j+1]=ce((R[1]-G)*B),z[j+2]=ce((R[2]-te)*B)}:(R,z,j)=>{z[j]=ce((R[2]-te)*B),z[j+1]=ce((R[0]-fe)*B),z[j+2]=ce((R[1]-G)*B)},ge=[],Se=0;for(let R of A){let z=he(R.v0),j=he(R.v1),J=he(R.v2),le=$g(z,j,J);if(R.source&&R.sourceTriangleIndex!==void 0&&(R.source.triangleMask[R.sourceTriangleIndex]=!le),le){Se++;continue}let re={vertices:[z,j,J],color:R.color};R.texture&&(re.texture=R.texture),R.texture&&R.textureWrap&&(re.textureWrap=R.textureWrap),R.texture&&R.textureAlphaMode&&(re.textureAlphaMode=R.textureAlphaMode),R.doubleSided&&(re.doubleSided=!0),R.uvs&&(re.uvs=R.uvs),R.simplifySourceVertexKeys&&(re.simplifySourceVertexKeys=R.simplifySourceVertexKeys),ge.push(re),E.push(R.sourceIndex!==void 0&&R.sourceTriangleIndex!==void 0?{sourceIndex:R.sourceIndex,triangleIndex:R.sourceTriangleIndex}:void 0)}ge.length===0&&Se>0&&b("all-projected-triangles-degenerate","No non-degenerate glTF triangles remained after normalization");let De=Wg(a,u,M,E,he,be);return{polygons:ge,animation:De,objectUrls:d,dispose:U,warnings:p,metadata:{triangleCount:ge.length,meshes:v,materials:I,animations:De?.clips,sourceBytes:c}}}function jg(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 Wc=Symbol("polycss.solidTextureBakedAnimationInfo"),kc=Symbol.for("polycss.animation.triangleFrameSource"),Kg=16*1024*1024,Hg=2,Zg=32,qg=2,Qg=.08,Jg=8,e0=128,Uc=32,n0=.045,t0=10,mt=6,o0=16;function Is(e){return e.material?.texture??e.texture}function r0(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function s0(e,n){return new Promise((t,o)=>{let r=new n,s=!1,i=c=>{s||(s=!0,c())};r.decoding="async",r.onload=()=>i(()=>t(r)),r.onerror=()=>i(()=>o(new Error(`texture load failed: ${e}`))),r.src=e})}async function i0(e,n,t){try{let o=await s0(e,n.Image),r=Math.max(0,Math.floor(o.naturalWidth||o.width||0)),s=Math.max(0,Math.floor(o.naturalHeight||o.height||0));if(r<=0||s<=0||r*s>t)return null;let i=n.createCanvas();i.width=r,i.height=s;let c=i.getContext("2d",{willReadFrequently:!0});if(!c)return null;c.drawImage(o,0,0,r,s);let a=c.getImageData(0,0,r,s).data;return{width:r,height:s,data:a,lowDetail:a0(r,s,a)}}catch{return null}}function Gc(e,n,t,o,r,s){let i=(o*n+t)*4,c=(s*n+r)*4;return Math.max(Math.abs((e[i]??0)-(e[c]??0)),Math.abs((e[i+1]??0)-(e[c+1]??0)),Math.abs((e[i+2]??0)-(e[c+2]??0)))}function a0(e,n,t){let o=Math.max(1,Math.floor(Math.max(e,n)/e0)),r=0,s=0,i=0;for(let c=0;c<n;c+=o)for(let a=0;a<e;a+=o){if(a+o<e){let l=Gc(t,e,a,c,a+o,c);i+=l,r++,l>Uc&&s++}if(c+o<n){let l=Gc(t,e,a,c,a,c+o);i+=l,r++,l>Uc&&s++}}return r>0&&s/r<=n0&&i/r<=t0}function zc(e,n,t){return Math.max(n,Math.min(t,e))}function $c(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 c0(e,n,t){let o=n[0],r=1-n[1],s=$c(o,t?.s),i=$c(r,t?.t);if(s===null||i===null)return null;let c=zc(Math.floor(s*e.width),0,e.width-1),l=(zc(Math.floor(i*e.height),0,e.height-1)*e.width+c)*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 En(e,n,t,o,r,s){return[e[0]*o+n[0]*r+t[0]*s,e[1]*o+n[1]*r+t[1]*s]}function l0(e){let[n,t,o]=e;return[En(n,t,o,1/3,1/3,1/3),En(n,t,o,.8,.1,.1),En(n,t,o,.1,.8,.1),En(n,t,o,.1,.1,.8),En(n,t,o,.45,.45,.1),En(n,t,o,.45,.1,.45),En(n,t,o,.1,.45,.45)]}function u0(e){let[n,t,o]=e,r=l0(e);for(let s=1;s<mt;s++)for(let i=1;i<mt-s;i++){let c=mt-s-i;c<=0||r.push(En(n,t,o,s/mt,i/mt,c/mt))}return r}function jc(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 _s(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 ko(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 Kc(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 s=t[1],i=c=>{let a=s.length<=4?s[c]+s[c]:s.slice(c*2,c*2+2);return parseInt(a,16)};return{r:i(0),g:i(1),b:i(2),a:s.length===4||s.length===8?i(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 f0(){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 Hc(e){return`${e.r},${e.g},${e.b},${e.a}`}function Xc(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=Hc(n),o=e.colors.get(t);e.colors.set(t,{color:n,count:(o?.count??0)+1}),e.count++}function Yc(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 m0(e){if(e.count<Jg||e.colors.size<=1||e.colors.size>qg)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*Qg));return t<=o?n.color:null}function d0(e,n,t,o){let r=jc(e);if(r.length===0)return null;let s=f0(),i=e.textureAlphaMode==="opaque"?Kc(e.color):null;for(let c of r)for(let a of u0(c.uvs)){let l=c0(n,a,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){i&&Xc(s,{...i,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),Xc(s,l)}if(s.count===0)return e.textureAlphaMode==="opaque"&&e.color?e.color:null;if(e.textureAlphaMode==="opaque"&&s.max.a===0&&e.color)return e.color;if(_s(s.min,s.max,t))return ko(Yc(s));if(!o){let c=m0(s);if(c)return ko(c)}return o||!n.lowDetail||!_s(s.min,s.max,Zg)?null:ko(Yc(s))}function Zc(e,n){let{texture:t,textureWrap:o,textureAlphaMode:r,material:s,uvs:i,textureTriangles:c,...a}=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{...a,color:n,...u?{simplifyVertexKeys:u}:{},...f?{simplifySourceVertexKeys:f}:{}}}function p0(e,n){if(n.length<2)return e;let t=[],o=new Map;for(let l of n){let u=Kc(e[l]?.color);if(!u||u.a<255)continue;let f=Hc(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=[],s=new Map,i=[...o.entries()].sort((l,u)=>u[1].count-l[1].count||l[0].localeCompare(u[0]));for(let[l,u]of i){let f=null;for(let d of r)if(_s(u.color,d,o0)){f=d;break}f||(f=u.color,r.push(f)),s.set(l,ko(f))}let c=!1,a=e.slice();for(let l of t){let u=s.get(l.key),f=e[l.index];!u||!f||f.color===u||(a[l.index]={...f,color:u},c=!0)}return c?a:e}function g0(e,n){let t=e.slice();for(let o=0;o<n.length;o++){let r=n[o],s=e[r.index];s&&(t[r.index]=Zc(s,r.color))}return t}function qc(e){return e?e[Wc]:void 0}async function Qc(e,n={}){if(n.enabled===!1)return null;let t=r0();if(!t)return null;let o=e.filter(a=>Is(a)&&jc(a).length>0);if(o.length===0)return null;let r=n.maxTexturePixels??Kg,s=new Map;await Promise.all(Array.from(new Set(o.map(a=>Is(a)))).map(async a=>{s.set(a,await i0(a,t,r))}));let i=n.colorTolerance??Hg,c=n.colorTolerance!==void 0;return{bake(a){let l=!1,u=[],f=a.map((d,m)=>{let p=Is(d);if(!p)return d;let h=s.get(p);if(!h)return d;let g=d0(d,h,i,c);return g?(l=!0,u.push(m),Zc(d,g)):d});return l?{polygons:p0(f,u),changed:!0,bakedIndices:u}:{polygons:a,changed:!1,bakedIndices:u}}}}async function h0(e,n={}){let t=await Qc(e,n);return t?t.bake(e).polygons:e}async function Os(e,n={}){let t=await Qc(e.polygons,n);if(!t)return e;let o=t.bake(e.polygons);if(!o.changed)return e;let r=[];for(let c of o.bakedIndices){let l=o.polygons[c].color;l&&r.push({index:c,color:l})}let s=e.animation,i=s&&{...s,sample(c,a){return g0(s.sample(c,a),r)}};if(i&&s){let c=s[kc];if(c){let a=new Map(r.map(f=>[f.index,f.color])),l=[],u={polygonCount:0,vertices:new Float64Array(0),colors:l,solidTriangles:!1};i[kc]=(f,d)=>{let m=c(f,d);if(!m)return m;l.length<m.polygonCount&&(l=new Array(m.polygonCount),u.colors=l);let p=m.textureFlags,h=m.solidTriangles===!0||!!p;for(let g=0;g<m.polygonCount;g++){let y=a.get(g);l[g]=y??m.colors?.[g],p?.[g]&&!y&&(h=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=p,u.solidTriangles=h,u}}i[Wc]={source:s,bakedColorEntries:r}}return{...e,polygons:o.polygons,animation:i}}var Jc=Symbol.for("polycss.animation.triangleFrameSource");function y0(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 b0(e){let n=fn(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((r,s)=>t.set(r,s));let o=[];for(let r of n){let s=t.get(r);if(s===void 0)return[];let i=y0(e,s);if(!i)return[];o.push(i)}return o}function Vs(e,n,t=!1){let o=new Array(n.length);for(let r=0;r<n.length;r++){let s=n[r],i=s.sourceRefs,c=new Array(i.length/2);for(let l=0,u=0;l<i.length;l+=2,u++){let d=e[i[l]]?.vertices[i[l+1]];if(!d)return e;let m=d[0],p=d[1],h=d[2];if(!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(h))return e;c[u]=[m,p,h]}let a=t?s.rest.color:e[i[0]??-1]?.color??s.rest.color;o[r]={...s.rest,vertices:c,color:a}}return o}function x0(e,n){let t=new Map;return n.forEach((o,r)=>{t.set(o,r)}),e.map((o,r)=>({...o,sourceRefs:o.sourceRefs.map((s,i)=>i%2===0?t.get(s)??-1:s)}))}function P0(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],s=n[o];if(!r||r.vertices.length!==s.rest.vertices.length)return null;t[o]={...s.rest,vertices:r.vertices,color:s.rest.color}}return t}function M0(e){return!!(e.texture||e.material?.texture)}function A0(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=b0(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let o=qc(e.animation),r=o?.source??e.animation,s=t.map(b=>b.originalIndex),i=Dc(r,s),c=i??r,a=i?x0(t,s):t,l=t.map(b=>b.rest.color),u=t.every(b=>b.rest.vertices.length===3&&!M0(b.rest)),f=i&&!o&&t.length===s.length&&t.every((b,x)=>b.rest.vertices.length===3&&b.sourceRefs.length===6&&b.sourceRefs[0]===s[x]&&b.sourceRefs[2]===s[x]&&b.sourceRefs[4]===s[x]),d=c[Jc],m=new Float64Array(t.length*9),p=l.slice(),h=new Array(t.length).fill(!1),g={polygonCount:t.length,vertices:m,colors:p,textureFlags:h,solidTriangles:u},y={...e.animation,sample(b,x){let P=c.sample(b,x);return f?P:i&&o?u&&t.length===s.length?P0(P,t)??Vs(P,a,!0):Vs(P,a,!0):Vs(P,a,!!o)}};return d&&u&&(y[Jc]=(b,x)=>{let P=d(b,x);if(!P)return P;if(i)return P.polygonCount<t.length||P.vertices.length<t.length*9?null:(g.polygonCount=t.length,g.vertices=P.vertices,g.colors=o?l:P.colors,g.textureFlags=o?h:P.textureFlags,g.solidTriangles=o?u:P.solidTriangles===!0,g);m.length<t.length*9&&(m=new Float64Array(t.length*9),g.vertices=m),p.length<t.length&&(p=new Array(t.length),g.colors=p),h.length<t.length&&(h=new Array(t.length).fill(!1),g.textureFlags=h);let S=u&&P.solidTriangles!==!1;for(let C=0;C<a.length;C++){let T=a[C],A=T.sourceRefs;for(let v=0,I=0;v<A.length;v+=2,I++){let _=A[v],O=A[v+1];if(_<0||_>=P.polygonCount)return null;let V=_*9+O*3,w=C*9+I*3;if(V+2>=P.vertices.length)return null;m[w]=P.vertices[V],m[w+1]=P.vertices[V+1],m[w+2]=P.vertices[V+2]}let M=A[0],E=!!P.textureFlags?.[M];h[C]=E,p[C]=o?T.rest.color:P.colors?.[M]??T.rest.color,!o&&E&&(S=!1)}return g.polygonCount=t.length,g.vertices=m,g.colors=p,g.textureFlags=h,g.solidTriangles=o?u:S,g}),{...e,polygons:t.map(b=>b.rest),animation:y,metadata:{...e.metadata,triangleCount:t.length}}}var S0=/^[0-9A-Fa-f]{6}$/,C0=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function E0(e){let n=[],t="";for(let o of e.split(`
|
|
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 Rs(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.palette??
|
|
3
|
-
`)){let s=r.trim();if(!(s.length===0||s.charCodeAt(0)===35)){if(s.startsWith("newmtl ")){o=s.slice(7).trim();continue}if(o){if(s.startsWith("Kd ")){let i=s.split(/\s+/),c=parseFloat(i[1]),a=parseFloat(i[2]),l=parseFloat(i[3]);Number.isFinite(c)&&Number.isFinite(a)&&Number.isFinite(l)&&(n[o]=`#${Ls(c)}${Ls(a)}${Ls(l)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),c=i[i.length-1]?.replace(/\\+/g,"/");c&&c!=="map_Kd"&&(t[o]=c)}}}}return{colors:n,textures:t}}var v0=[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 I0(e){let n=e>>0&255,t=e>>8&255,o=e>>16&255;return[n,t,o]}function Ns(e){return(e&255).toString(16).padStart(2,"0")}function tl(e,n,t){return`#${Ns(e)}${Ns(n)}${Ns(t)}`}function _0(e,n,t,o){if(o>=255)return tl(e,n,t);let r=Math.round(Math.max(0,Math.min(255,o))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function ol(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 rl(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function el(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),s=Math.min(n,t,o),i=r-s,c=0;return i!==0&&(r===n?c=60*((t-o)/i%6):r===t?c=60*((o-n)/i+2):c=60*((n-t)/i+4)),c<0&&(c+=360),{hue:c,saturation:r===0?0:i/r,value:r}}function O0(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function sl(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=el(e),o=el(n),r=t.saturation<.08,s=o.saturation<.08;if(r||s)return r===s;let i=Math.min(t.value,o.value)<.16?35:24;return O0(t.hue,o.hue)<=i}function V0(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return null;let o=new Map;for(let c of e.keys()){let a=ol(c);a&&o.set(c,a)}let r=[],s=new Map,i=Array.from(e.entries()).sort((c,a)=>a[1]-c[1]||c[0].localeCompare(a[0]));for(let[c]of i){let a=o.get(c);if(!a){s.set(c,c);continue}let l=null;for(let u of r){if(!sl(a,u.parsed))continue;let f=rl(a,u.parsed);f>t||(!l||f<l.distance)&&(l={color:u.color,distance:f})}l?s.set(c,l.color):(r.push({color:c,parsed:a}),s.set(c,c))}return s}var R0=[[1,0],[-1,0],[0,1],[0,-1]];function il(e,n){return`${e},${n}`}function L0(e){let n=e.indexOf(",");return[Number(e.slice(0,n)),Number(e.slice(n+1))]}function w0(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 N0(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return;let o=new Map,r=s=>(o.has(s)||o.set(s,ol(s)),o.get(s)??null);for(let s of e.values()){if(s.size<3)continue;let i=new Map;for(let l of s.values())i.set(l,(i.get(l)??0)+1);let c=new Set,a=[];for(let[l,u]of s){if(c.has(l))continue;let f=[l],d=[],m=new Map,p=1/0,h=-1/0,g=1/0,y=-1/0;for(c.add(l);f.length>0;){let C=f.pop();d.push(C);let[T,A]=L0(C);p=Math.min(p,T),h=Math.max(h,T),g=Math.min(g,A),y=Math.max(y,A);for(let[M,E]of R0){let v=il(T+M,A+E),I=s.get(v);if(I){if(I===u){c.has(v)||(c.add(v),f.push(v));continue}m.set(I,(m.get(I)??0)+1)}}}let b=h-p+1,x=y-g+1;if(!w0(d.length,b,x)||m.size===0)continue;let P=r(u);if(!P)continue;let S=null;for(let[C,T]of m){let A=i.get(C)??0;if(A<=d.length)continue;let M=r(C);if(!M||!sl(P,M))continue;let E=rl(P,M);if(E>t)continue;let v={color:C,contacts:T,distance:E,count:A};(!S||v.contacts>S.contacts||v.contacts===S.contacts&&v.count>S.count||v.contacts===S.contacts&&v.count===S.count&&v.distance<S.distance||v.contacts===S.contacts&&v.count===S.count&&v.distance===S.distance&&v.color.localeCompare(S.color)<0)&&(S=v)}if(S)for(let C of d)a.push([C,S.color])}for(let[l,u]of a)s.set(l,u)}}var D0=542658390,F0=new Set(["nTRN","nGRP","nSHP"]),B0="Skipped MagicaVoxel scene graph transforms; models were flattened into one grid";function Ds(e,n){let t=n?.targetSize??60,o=e.byteLength;if(e.byteLength<8)return dt(o,["parseVox: buffer too small to be a valid .vox file"]);let r=new DataView(e);if(r.getUint32(0,!0)!==D0)return dt(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return dt(o,["parseVox: buffer too small for MAIN chunk"]);if(nl(r,8)!=="MAIN")return dt(o,["parseVox: expected MAIN chunk at offset 8"]);let a=20+r.getUint32(12,!0),l=a+r.getUint32(16,!0),u=[],f=[],d=[],m=null,p=k=>{d.includes(k)||d.push(k)};for(;a<l&&a+12<=e.byteLength;){let k=nl(r,a),L=r.getUint32(a+4,!0),W=r.getUint32(a+8,!0),Y=a+12,se=Y+L+W;if(k==="SIZE"){if(L>=12&&Y+12<=e.byteLength){let Z=r.getUint32(Y,!0),B=r.getUint32(Y+4,!0),q=r.getUint32(Y+8,!0);u.push({sx:Z,sy:B,sz:q})}}else if(k==="XYZI"){if(L>=4&&Y+4<=e.byteLength){let Z=r.getUint32(Y,!0),B=[],q=Math.min(Z,Math.floor((L-4)/4));for(let me=0;me<q;me++){let fe=Y+4+me*4;B.push({x:r.getUint8(fe),y:r.getUint8(fe+1),z:r.getUint8(fe+2),colorIndex:r.getUint8(fe+3)})}f.push(B)}}else if(k==="RGBA"&&L>=1024&&Y+1024<=e.byteLength){m=[];for(let Z=0;Z<256;Z++){let B=Y+Z*4,q=r.getUint8(B),me=r.getUint8(B+1),fe=r.getUint8(B+2),G=r.getUint8(B+3);m.push(_0(q,me,fe,G))}}F0.has(k)&&p(B0),a=se}let h=[],g=new Set;for(let k of f)for(let L of k){if(L.colorIndex===0)continue;let W=`${L.x},${L.y},${L.z}`;g.has(W)||(g.add(W),h.push(L))}if(h.length===0)return dt(o,d);let y=new Map,b=k=>{let L=y.get(k);if(L)return L;let W=k-1,Y;if(m!==null)Y=m[W]??"#888888";else{let se=v0[k]??0,[Z,B,q]=I0(se);Y=tl(Z,B,q)}return y.set(k,Y),Y},x=new Map;for(let k of h){let L=b(k.colorIndex);x.set(L,(x.get(L)??0)+1)}let P=V0(x,n?.paletteMergeDistance),S=k=>{let L=b(k);return P?.get(L)??L},C=(k,L,W)=>g.has(`${k},${L},${W}`),T=new Map,A=(k,L,W,Y,se)=>{let Z=`${k}:${L}`,B=T.get(Z);B||(B=new Map,T.set(Z,B)),B.set(il(W,Y),se)};for(let k of h){let{x:L,y:W,z:Y}=k,se=S(k.colorIndex);C(L+1,W,Y)||A(0,L+1,W,Y,se),C(L-1,W,Y)||A(1,L,W,Y,se),C(L,W+1,Y)||A(2,W+1,L,Y,se),C(L,W-1,Y)||A(3,W,L,Y,se),C(L,W,Y+1)||A(4,Y+1,L,W,se),C(L,W,Y-1)||A(5,Y,L,W,se)}N0(T,n?.colorRegionMergeDistance);let M=new Map;for(let[k,L]of T)for(let[W,Y]of L){let se=`${k}:${Y}`,Z=M.get(se);Z||(Z=new Set,M.set(se,Z)),Z.add(W)}function E(k){let L=new Set,W=[],Y=1/0,se=-1/0,Z=1/0,B=-1/0;for(let q of k){let[me,fe]=q.split(","),G=+me,te=+fe;G<Y&&(Y=G),G>se&&(se=G),te<Z&&(Z=te),te>B&&(B=te)}for(let q=Z;q<=B;q++)for(let me=Y;me<=se;me++){let fe=`${me},${q}`;if(!k.has(fe)||L.has(fe))continue;let G=1;for(;me+G<=se;){let ce=`${me+G},${q}`;if(!k.has(ce)||L.has(ce))break;G++}let te=1;e:for(;q+te<=B;){for(let ce=0;ce<G;ce++){let ye=`${me+ce},${q+te}`;if(!k.has(ye)||L.has(ye))break e}te++}for(let ce=0;ce<te;ce++)for(let ye=0;ye<G;ye++)L.add(`${me+ye},${q+ce}`);W.push({u:me,v:q,w:G,h:te})}return W}let v=(k,L,W,Y,se,Z)=>{let B=W+se,q=Y+Z;switch(k){case 0:return[[L,W,Y],[L,B,Y],[L,B,q],[L,W,q]];case 1:return[[L,B,Y],[L,W,Y],[L,W,q],[L,B,q]];case 2:return[[W,L,Y],[W,L,q],[B,L,q],[B,L,Y]];case 3:return[[B,L,Y],[B,L,q],[W,L,q],[W,L,Y]];case 4:return[[W,Y,L],[B,Y,L],[B,q,L],[W,q,L]];default:return[[W,q,L],[B,q,L],[B,Y,L],[W,Y,L]]}},I=[];for(let[k,L]of M){let W=k.indexOf(":"),Y=k.indexOf(":",W+1),se=+k.slice(0,W),Z=+k.slice(W+1,Y),B=k.slice(Y+1);for(let{u:q,v:me,w:fe,h:G}of E(L))I.push({vertices:v(se,Z,q,me,fe,G),color:B})}if(I.length===0)return dt(o,d);let _=1/0,O=1/0,V=1/0,w=-1/0,F=-1/0,D=-1/0;for(let k of I)for(let L of k.vertices)L[0]<_&&(_=L[0]),L[0]>w&&(w=L[0]),L[1]<O&&(O=L[1]),L[1]>F&&(F=L[1]),L[2]<V&&(V=L[2]),L[2]>D&&(D=L[2]);let H=Math.max(w-_,F-O,D-V),K=H>0?t/H:1,Q=K*50,ne=Number.isFinite(Q)&&Q>0?Math.max(1,Math.round(Q))/50:K,ee={kind:"magica-vox",cells:h.map(k=>({x:F-(k.y+1),y:k.x-_,z:k.z-V,color:S(k.colorIndex)})),rows:Math.max(0,F-O),cols:Math.max(0,w-_),depth:Math.max(0,D-V),scale:ne,sourceBytes:o},ue=k=>Math.round(k*1e3)/1e3,U=k=>[ue((k[0]-_)*ne),ue((k[1]-O)*ne),ue((k[2]-V)*ne)],$=I.map(({vertices:k,color:L})=>({vertices:k.map(U),color:L}));return{polygons:$,voxelSource:ee,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:$.length,sourceBytes:o,voxelCount:h.length}}}function nl(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 dt(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var k0="#888888";var U0=/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/,Un="COLOR=";function ll(e,n,t){let o=n??t;if(!Number.isFinite(o))throw new Error(`parseStl: ${e} must be finite`);return o}function G0(e,n,t){let o=ll(e,n,t);if(o<=0)throw new Error(`parseStl: ${e} must be greater than 0`);return o}function z0(e){if(e===void 0||e==="z"||e==="y")return e??"z";throw new Error('parseStl: upAxis must be "z" or "y"')}function $0(e){let n=e??k0;if(typeof n!="string"||n.trim().length===0)throw new Error("parseStl: defaultColor must be a non-empty string");return n}function X0(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 ul(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Uo(e,n){return[e.getFloat32(n,!0),e.getFloat32(n+4,!0),e.getFloat32(n+8,!0)]}function Go(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function al(e){let n=e.trim().split(/\s+/);if(n.length!==3||!n.every(o=>U0.test(o)))return null;let t=[Number(n[0]),Number(n[1]),Number(n[2])];return Go(t)?t:null}function Y0(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 Fs(e){return Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")}function fl(e,n,t,o=255){if(o>=255)return`#${Fs(e)}${Fs(n)}${Fs(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 W0(e){for(let n=0;n<80-Un.length-4;n+=1){let t=!0;for(let c=0;c<Un.length;c+=1)if(e.getUint8(n+c)!==Un.charCodeAt(c)){t=!1;break}if(!t)continue;let o=e.getUint8(n+Un.length),r=e.getUint8(n+Un.length+1),s=e.getUint8(n+Un.length+2),i=e.getUint8(n+Un.length+3);return{defaultColor:fl(o,r,s,i),alpha:Math.round(i/255*1e3)/1e3,alphaByte:i}}return null}function j0(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:fl(t,o,r,n.alphaByte),usesDefaultColor:!1}}function K0(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((s,i)=>s.index-i.index||(s.kind==="end"?-1:1))}function H0(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 Z0(e){let n=ul(e.subarray(0,Math.min(e.byteLength,512))).trimStart().toLowerCase();return!n.startsWith("solid")&&!n.startsWith("facet")?!1:!H0(e)}function q0(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(Z0(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 Q0(e,n,t){let o=new DataView(e.buffer,e.byteOffset,e.byteLength),{triangleCount:r,declaredTriangleCount:s,trailingBytes:i}=n;s!==r&&t.push(`parseStl: binary STL declared ${s} triangles but contains ${r} complete triangle record${r===1?"":"s"}`),i>0&&t.push(`parseStl: ignored ${i} trailing binary byte${i===1?"":"s"}`);let c=Y0(e.subarray(0,80)),a=W0(o),l=0,u=0,f=[];for(let d=0,m=84;d<r;d+=1,m+=50){let p=Uo(o,m),h=[Uo(o,m+12),Uo(o,m+24),Uo(o,m+36)];if(!h.every(Go))throw new Error(`parseStl: non-finite coordinate in binary triangle ${d}`);let g=o.getUint16(m+48,!0),y=a?j0(g,a):null;y&&(y.usesDefaultColor?u+=1:l+=1),f.push({normal:Go(p)?p:null,hasIgnoredNormal:!Go(p),color:y?.color,vertices:h,hasIgnoredAttribute:!a&&g!==0})}return{format:"binary",facets:f,binaryHeader:c,color:a?{format:"magics",defaultColor:a.defaultColor,alpha:a.alpha,coloredTriangleCount:l,defaultColorTriangleCount:u}:void 0}}function cl(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,s=/^\s*facet\s+normal\b/gim,i=K0(e),c=0,a,l=0;for(;s.exec(e);)l+=1;let u=0,f=0,d=0,m;for(;m=o.exec(e);){for(u+=1;c<i.length&&i[c].index<m.index;){let b=i[c];a=b.kind==="start"?b.name:void 0,c+=1}let p=al(m[1]);p||(d+=1);let h=[],g=!1;r.lastIndex=0;let y;for(;y=r.exec(m[2]);){let b=al(y[1]);if(!b){g=!0;break}h.push(b)}if(g||h.length!==3){f+=1;continue}t.push({normal:p,hasIgnoredNormal:!p,solidName:a,vertices:[h[0],h[1],h[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 pt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function $o(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 ks(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function ml(e){return Math.hypot(e[0],e[1],e[2])}function J0(e){let n=$o(pt(e[1],e[0]),pt(e[2],e[0]));return ml(n)<=1e-8}function zo(e){let n=ml(e);return n<=1e-8?null:[e[0]/n,e[1]/n,e[2]/n]}function eh(e){let n=t=>Object.is(t,-0)?0:t;return`${n(e[0])},${n(e[1])},${n(e[2])}`}function nh(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function Us(e,n){return n?[e.vertices[0],e.vertices[2],e.vertices[1]]:e.vertices}function th(e,n,t){let o=0;for(let r of n.facets){let[s,i,c]=Us(e[r],t[r]);o+=ks(s,$o(i,c))/6}return o}function oh(e,n,t){if(n.facets.length<8)return null;let o=0,r=0;for(let i of n.facets){let c=e[i],a=c.normal?zo(c.normal):null;if(!a)continue;let l=Us(c,t[i]),u=zo($o(pt(l[1],l[0]),pt(l[2],l[0])));if(!u)continue;let f=ks(u,a);f>=.95?o+=1:f<=-.95&&(r+=1)}let s=o+r;return s/n.facets.length<.75?null:r/s>=.9?"opposed":o/s>=.9?"aligned":null}function rh(e){let n=new Map,t=e.map(()=>[]);for(let u=0;u<e.length;u+=1){let f=e[u].vertices.map(eh);for(let d=0;d<3;d+=1){let m=f[d],p=f[(d+1)%3],h=nh(m,p),g=n.get(h),y={facetIndex:u,from:m,to:p};g?g.push(y):n.set(h,[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),s=new Array(e.length).fill(-1),i=[],c=0;for(let u=0;u<e.length;u+=1){if(s[u]>=0)continue;let f=i.length,d={facets:[],conflicts:0,boundaryEdges:0,nonManifoldEdges:0,flippedOutward:!1,flippedToSuppliedNormals:!1};i.push(d),s[u]=f;let m=[u];for(let p=0;p<m.length;p+=1){let h=m[p];d.facets.push(h);for(let g of t[h]){let y=r[h]!==g.flipDiffers;s[g.to]<0?(s[g.to]=f,r[g.to]=y,m.push(g.to)):r[g.to]!==y&&h<g.to&&(d.conflicts+=1,c+=1)}}}for(let u of n.values()){let f=i[s[u[0].facetIndex]];u.length===1?f.boundaryEdges+=1:u.length>2&&(f.nonManifoldEdges+=1)}for(let u of i){if(u.nonManifoldEdges>0||u.conflicts>0){for(let d of u.facets)r[d]=!1;continue}if(u.boundaryEdges>0){if(oh(e,u,r)==="opposed"){for(let d of u.facets)r[d]=!r[d];u.flippedToSuppliedNormals=!0}continue}if(th(e,u,r)<-1e-10){for(let d of u.facets)r[d]=!r[d];u.flippedOutward=!0}}let a=0;return{facets:e.map((u,f)=>r[f]?(a+=1,{...u,vertices:Us(u,!0)}):u),repairedCount:a,componentCount:i.length,outwardComponentCount:i.filter(u=>u.flippedOutward).length,suppliedNormalComponentCount:i.filter(u=>u.flippedToSuppliedNormals).length,conflictCount:c,nonManifoldEdgeCount:o}}function sh(e,n,t,o,r){let s=i=>Math.round(i*1e3)/1e3;return r==="y"?[s((e[2]-n[2])*t+o),s((e[0]-n[0])*t+o),s((e[1]-n[1])*t+o)]:[s((e[0]-n[0])*t+o),s((e[1]-n[1])*t+o),s((e[2]-n[2])*t+o)]}function ih(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 s=e[r]?.solidName??"";r<e.length&&s===t||(n.push({name:t,start:o,count:r-o}),t=s,o=r)}return n}function ah(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 Gs(e,n){let t=G0("targetSize",n?.targetSize,60),o=ll("gridShift",n?.gridShift,1),r=$0(n?.defaultColor),s=z0(n?.upAxis),i=[],c=X0(e),a=typeof e=="string"?e.length:c.byteLength;if(a===0||typeof e=="string"&&e.trim().length===0)throw new Error("parseStl: empty input");let l=c?q0(c):null,u=typeof e=="string"?cl(e,i):l?Q0(c,l,i):cl(ul(c),i),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),J0(A.vertices)){m+=1;continue}p.push(A)}let h=rh(p),g=0;for(let A of h.facets){let M=zo($o(pt(A.vertices[1],A.vertices[0]),pt(A.vertices[2],A.vertices[0]))),E=A.normal?zo(A.normal):null;M&&E&&ks(M,E)<.95&&(g+=1)}if(f>0&&i.push(`parseStl: ignored non-zero binary attribute byte count on ${f} triangle${f===1?"":"s"}`),d>0&&i.push(`parseStl: ignored ${d} non-finite binary normal${d===1?"":"s"}`),m>0&&i.push(`parseStl: skipped ${m} degenerate triangle${m===1?"":"s"}`),h.repairedCount>0&&i.push(`parseStl: repaired winding on ${h.repairedCount} triangle${h.repairedCount===1?"":"s"}`),h.outwardComponentCount>0&&i.push(`parseStl: oriented ${h.outwardComponentCount} closed component${h.outwardComponentCount===1?"":"s"} outward`),h.suppliedNormalComponentCount>0&&i.push(`parseStl: oriented ${h.suppliedNormalComponentCount} open component${h.suppliedNormalComponentCount===1?"":"s"} from supplied normals`),h.conflictCount>0&&i.push(`parseStl: found ${h.conflictCount} inconsistent shared-edge winding constraint${h.conflictCount===1?"":"s"}`),h.nonManifoldEdgeCount>0&&i.push(`parseStl: found ${h.nonManifoldEdgeCount} non-manifold shared edge${h.nonManifoldEdgeCount===1?"":"s"}`),g>0&&i.push(`parseStl: ${g} supplied normal${g===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 h.facets)for(let M of A.vertices)for(let E=0;E<3;E+=1)M[E]<y[E]&&(y[E]=M[E]),M[E]>b[E]&&(b[E]=M[E]);let x=Math.max(b[0]-y[0],b[1]-y[1],b[2]-y[2]),P=x>0?t/x:1,S=ih(h.facets),C=ah(S),T=h.facets.map(A=>({vertices:A.vertices.map(M=>sh(M,y,P,o,s)),color:A.color??r}));return{polygons:T,objectUrls:[],dispose:()=>{},warnings:i,metadata:{triangleCount:T.length,meshes:C,materials:[],sourceBytes:a,stlHeader:u.binaryHeader,stlColor:u.color,stlSolids:S,stlTopology:{componentCount:h.componentCount,repairedTriangleCount:h.repairedCount,outwardComponentCount:h.outwardComponentCount,suppliedNormalComponentCount:h.suppliedNormalComponentCount,inconsistentSharedEdgeCount:h.conflictCount,nonManifoldSharedEdgeCount:h.nonManifoldEdgeCount}}}}var Tn="loadMesh";async function dl(e,n){let t=n?.solidTextureSamples;return t===!1?e:Os(e,typeof t=="object"?t:void 0)}function ch(e){let n=e.split("?")[0].split("#")[0],t=n.lastIndexOf(".");return t<0?"":n.slice(t+1).toLowerCase()}async function lh(e,n){let t=ch(e);if(t==="mtl")throw new Error(`${Tn}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let o=globalThis.fetch;if(!o)throw new Error(`${Tn}: no fetch() in this environment`);let r=n?.baseUrl??e;if(t==="obj"){let s=await o(e);if(!s.ok)throw new Error(`${Tn}: ${e} \u2192 ${s.status}`);let i=await s.text(),c=n?.objOptions;if(n?.mtlUrl){let u=await o(n.mtlUrl);if(!u.ok)throw new Error(`${Tn}: ${n.mtlUrl} \u2192 ${u.status}`);let f=await u.text(),{colors:d,textures:m}=ws(f),p={},h=globalThis.URL,g=globalThis.document?.baseURI,y=n.mtlUrl;if(h&&g)try{y=new h(n.mtlUrl,g).toString()}catch{}for(let[b,x]of Object.entries(m)){if(h)try{p[b]=new h(x,y).toString();continue}catch{}let P=n.mtlUrl.lastIndexOf("/"),S=P>=0?n.mtlUrl.slice(0,P+1):"";p[b]=x.startsWith("/")||/^https?:\/\//.test(x)?x:S+x}c={...c??{},materialColors:{...d,...c?.materialColors??{}},materialTextures:{...p,...c?.materialTextures??{}}}}let a=Rs(i,c),l=await dl(a,n);return tt(l,{meshResolution:n?.meshResolution,source:a})}if(t==="glb"||t==="gltf"){let s=await o(e);if(!s.ok)throw new Error(`${Tn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),c=vs(i,{baseUrl:r,...n?.gltfOptions??{}}),a=await dl(c,n);return tt(a,{meshResolution:n?.meshResolution,source:c})}if(t==="vox"){let s=await o(e);if(!s.ok)throw new Error(`${Tn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return tt(Ds(i,n?.voxOptions),{meshResolution:n?.meshResolution})}if(t==="stl"){let s=await o(e);if(!s.ok)throw new Error(`${Tn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return tt(Gs(i,n?.stlOptions),{meshResolution:n?.meshResolution})}throw new Error(`${Tn}: unsupported extension ".${t}" (supported: obj, glb, gltf, vox, stl)`)}function Ne(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=cs[n]??10**n,o=Math.round(e*t)/t;return Object.is(o,0)||Object.is(o,-0)?"0":String(o)}function uh(e,n=Io){let t=Ne(e,n);return t==="0"?"0":`${t}px`}function vn(e,n=bn){if(e.length===0)return"";let t=Ne(e[0],n);for(let o=1;o<e.length;o++)t+=`,${Ne(e[o],n)}`;return t}function fh(e,n,t,o,r=bn){return zs(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 zs(e,n,t,o,r,s,i,c,a,l,u,f,d=bn){if(d===3){let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,g=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(s*1e3)/1e3||0,x=Math.round(i*1e3)/1e3||0,P=Math.round(c*1e3)/1e3||0,S=Math.round(a*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,T=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`${m},${p},${h},0,${g},${y},${b},0,${x},${P},${S},0,${C},${T},${A},1`}return`${Ne(e,d)},${Ne(n,d)},${Ne(t,d)},0,${Ne(o,d)},${Ne(r,d)},${Ne(s,d)},0,${Ne(i,d)},${Ne(c,d)},${Ne(a,d)},0,${Ne(l,d)},${Ne(u,d)},${Ne(f,d)},1`}function $s(e,n,t,o,r,s,i,c,a,l,u,f,d=bn){if(d!==3)return`matrix3d(${zs(e,n,t,o,r,s,i,c,a,l,u,f,d)})`;let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,g=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(s*1e3)/1e3||0,x=Math.round(i*1e3)/1e3||0,P=Math.round(c*1e3)/1e3||0,S=Math.round(a*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,T=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`matrix3d(${m},${p},${h},0,${g},${y},${b},0,${x},${P},${S},0,${C},${T},${A},1)`}function zt(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(d=>Number(d));if(s.length!==16||s.some(d=>!Number.isFinite(d)))return e.matrix;let i=s[0],c=s[1],a=s[2],l=s[4],u=s[5],f=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*l,s[13]+=o*c+r*u,s[14]+=o*a+r*f,vn(s)}function mh(e,n){return zt(e,n.width/xn,n.height/xn,n.minX,n.minY)}function pl(e){let n=e.seamBleedInsets??{left:0,right:0,top:0,bottom:0},t=e.canvasW||1,o=e.canvasH||1;return zt(e,(t+n.left+n.right)/ct,(o+n.top+n.bottom)/ct,-n.left,-n.top)}function Xs(e,n){let t=e.matrix.split(",").map(o=>Number(o));return t.length!==16||t.some(o=>!Number.isFinite(o))?e.canonicalMatrix:(t[0]*=e.canvasW/n,t[1]*=e.canvasW/n,t[2]*=e.canvasW/n,t[4]*=e.canvasH/n,t[5]*=e.canvasH/n,t[6]*=e.canvasH/n,vn(t))}function In(e,n=as){let t=Ne(e,n);return Number(t)===0?"0":`${t}%`}function dh(e,n=bn){return`matrix3d(${e.split(",").map(t=>{let o=Number(t.trim());return Number.isFinite(o)?Ne(o,n):t.trim()}).join(",")})`}function ph(e,n=Io){let t=Ne(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function gh(e){return`matrix3d(${pl(e)})`}function _n(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function Gn(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let i=1;i+1<e.length;i++){let c=e[i],a=e[i+1],l=[c[0]-n[0],c[1]-n[1],c[2]-n[2]],u=[a[0]-n[0],a[1]-n[1],a[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 s=Math.hypot(t,o,r);return s<=de?null:(t/=s,o/=s,r/=s,[t,o,r])}function $t(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=de)return!1;let c=Math.sign(i);if(n===0)n=c;else if(c!==n)return!1}return!0}function Ys(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 Ws(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],c=o[1]-t[1],a=r*c-s*i;if(Math.abs(a)<=de)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*c-u*i)/a;return[e[0]+f*r,e[1]+f*s]}function hh(e,n,t,o,r,s,i,c){let a=t-e,l=o-n,u=i-r,f=c-s,d=a*f-l*u;if(Math.abs(d)<=de)return null;let m=r-e,p=s-n,h=(m*f-p*u)/d;return[e+h*a,n+h*l]}function gt(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let c=s[i]-t,a=s[i+1]-o,l=Math.hypot(c,a);l<=Ae||(s[i]+=c/l*n,s[i+1]+=a/l*n)}return s}function ht(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let a=0;a<e.length;a+=2)t.push([e[a],e[a+1]]);if(!$t(t))return gt(e,n);let o=Ys(t);if(Math.abs(o)<=de)return gt(e,n);let r=o>0?1:-1,s=[];for(let a=0;a<t.length;a++){let l=t[a],u=t[(a+1)%t.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=de)return gt(e,n);let p=r*(d/m)*n,h=r*(-f/m)*n;s.push({a:[l[0]+p,l[1]+h],b:[u[0]+p,u[1]+h]})}let i=[],c=Math.max(2,n*4);for(let a=0;a<t.length;a++){let l=s[(a+t.length-1)%t.length],u=s[a],f=Ws(l.a,l.b,u.a,u.b);if(!f)return gt(e,n);let d=t[a],m=f[0]-d[0],p=f[1]-d[1],h=Math.hypot(m,p);h>c?i.push(d[0]+m/h*c,d[1]+p/h*c):i.push(f[0],f[1])}return i}function Xt(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])<=de))return ht(e,o[0]);let s=[];for(let f=0;f<e.length;f+=2)s.push([e[f],e[f+1]]);if(!$t(s))return e;let i=Ys(s);if(Math.abs(i)<=de)return e;let c=i>0?1:-1,a=[];for(let f=0;f<s.length;f++){let d=s[f],m=s[(f+1)%s.length],p=m[0]-d[0],h=m[1]-d[1],g=Math.hypot(p,h);if(g<=de)return e;let y=o[f],b=c*(h/g)*y,x=c*(-p/g)*y;a.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<s.length;f++){let d=a[(f+s.length-1)%s.length],m=a[f],p=Ws(d.a,d.b,m.a,m.b);if(!p)return e;let h=s[f],g=p[0]-h[0],y=p[1]-h[1],b=Math.hypot(g,y);b>u?l.push(h[0]+g/b*u,h[1]+y/b*u):l.push(p[0],p[1])}return l}function Xo(e,n,t,o,r,s,i){if(i<=0)return[e,n,t,o,r,s];let c=(e*o-n*t+t*s-o*r+r*n-s*e)/2,a=()=>gt([e,n,t,o,r,s],i);if(Math.abs(c)<=de)return a();let l=c>0?1:-1,u=t-e,f=o-n,d=Math.sqrt(u*u+f*f),m=r-t,p=s-o,h=Math.sqrt(m*m+p*p),g=e-r,y=n-s,b=Math.sqrt(g*g+y*y);if(d<=de||h<=de||b<=de)return a();let x=l*(f/d)*i,P=l*(-u/d)*i,S=e+x,C=n+P,T=t+x,A=o+P,M=l*(p/h)*i,E=l*(-m/h)*i,v=t+M,I=o+E,_=r+M,O=s+E,V=l*(y/b)*i,w=l*(-g/b)*i,F=r+V,D=s+w,H=e+V,K=n+w,Q=H-F,ne=K-D,ee=T-S,ue=A-C,U=Q*ue-ne*ee;if(Math.abs(U)<=de)return a();let $=S-F,k=C-D,L=($*ue-k*ee)/U,W=F+L*Q,Y=D+L*ne,se=T-S,Z=A-C,B=_-v,q=O-I,me=se*q-Z*B;if(Math.abs(me)<=de)return a();let fe=v-S,G=I-C,te=(fe*q-G*B)/me,ce=S+te*se,ye=C+te*Z,he=_-v,be=O-I,ge=H-F,Se=K-D,De=he*Se-be*ge;if(Math.abs(De)<=de)return a();let R=F-v,z=D-I,j=(R*Se-z*ge)/De,J=v+j*he,le=I+j*be,re=Math.max(2,i*4),pe=W-e,xe=Y-n,ie=Math.sqrt(pe*pe+xe*xe);ie>re&&(W=e+pe/ie*re,Y=n+xe/ie*re);let ae=ce-t,N=ye-o,X=Math.sqrt(ae*ae+N*N);X>re&&(ce=t+ae/X*re,ye=o+N/X*re);let oe=J-r,Te=le-s,Ce=Math.sqrt(oe*oe+Te*Te);return Ce>re&&(J=r+oe/Ce*re,le=s+Te/Ce*re),[W,Y,ce,ye,J,le]}function js(e,n,t,o){let r=e+n;if(o<=0||t<=de||r<=de||!Number.isFinite(e+n+t+o))return Xo(e,0,0,t,r,t,o);let s=Math.sqrt(e*e+t*t),i=Math.sqrt(n*n+t*t);if(s<=de||i<=de)return Xo(e,0,0,t,r,t,o);let c=-o*t/s,a=-o*e/s,l=o*t/i,u=-o*n/i,f=e+c,d=a,m=r+l,p=t+u,h=-t*r;if(Math.abs(h)<=de)return Xo(e,0,0,t,r,t,o);let g=f-m,y=d-p,b=(g*t+y*e)/h,x=m-b*n,P=p-b*t,S=-o*(e+s)/t,C=t+o,T=r+o*(n+i)/t,A=C,M=Math.max(2,o*4),E=x-e,v=P,I=Math.sqrt(E*E+v*v);I>M&&(x=e+E/I*M,P=v/I*M);let _=Math.sqrt(S*S+o*o);_>M&&(S=S/_*M,C=t+o/_*M);let O=T-r,V=Math.sqrt(O*O+o*o);return V>M&&(T=r+O/V*M,A=t+o/V*M),[x,P,S,C,T,A]}function gl(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=_n(n.vertices,t,o),s=Gn(r);if(!s)return null;let i=e.screenPts[0],c=e.screenPts[1],a=e.screenPts[2],l=e.screenPts[3],u=e.screenPts[4],f=e.screenPts[5],d=a-i,m=l-c,p=u-i,h=f-c,g=d*h-m*p;if(Math.abs(g)<=de)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]],S=[x[0]-y[0],x[1]-y[1],x[2]-y[2]],C=[(P[0]*h-m*S[0])/g,(P[1]*h-m*S[1])/g,(P[2]*h-m*S[2])/g],T=[(d*S[0]-P[0]*p)/g,(d*S[1]-P[1]*p)/g,(d*S[2]-P[2]*p)/g],A=y[0]-C[0]*i-T[0]*c,M=y[1]-C[1]*i-T[1]*c,E=y[2]-C[2]*i-T[2]*c;return{normal:s,xAxis:C,yAxis:T,tx:A,ty:M,tz:E}}function Ks(e){return Math.max(0,Math.min(6,Math.floor(e??bn)))}function hl(e){return`${e[0]},${e[1]},${e[2]}`}function yl(e,n){let t=hl(e),o=hl(n);return t<o?`${t}|${o}`:`${o}|${t}`}function yh(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 s=0;s<r.length;s++){let i=yl(r[s],r[(s+1)%r.length]),c=n.get(i),a={polygon:o,edge:s};c?c.push(a):n.set(i,[a])}}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 s=r+1;s<o.length;s++)t[o[r].polygon].add(o[r].edge),t[o[s].polygon].add(o[s].edge);return t.map(o=>o.size>0?o:void 0)}function Yo(e,n){return typeof e=="number"&&Number.isFinite(e)?Math.max(0,e):n}function Hs(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function Wo(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[s,i]=r[n],[c,a]=r[(n+1)%o],l=c-s,u=a-i,f=Math.hypot(l,u);if(f<=Ae)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[M,E]=r[A],v=Math.abs((M-s)*u-(E-i)*l)/f;v>Ae&&(m=Math.min(m,v))}Number.isFinite(m)&&d.push(m*.5);let p=r[(n+o-1)%o],h=r[(n+2)%o],g=p[0]-s,y=p[1]-i,b=h[0]-c,x=h[1]-a,P=Math.hypot(g,y),S=Math.hypot(b,x);if(P>Ae){let A=Math.abs(l*y-u*g)/(f*P);A>Ae&&d.push(P*A)}if(S>Ae){let A=Math.abs(-l*x- -u*b)/(f*S);A>Ae&&d.push(S*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 T=Math.min(...C);return Math.max(0,Math.min(Number.isFinite(t)?t:T,T))}function Zs(e,n,t){if(!n?.size||t===void 0)return;let o=new Map;for(let r of n){let s=Wo(e,r,t);s>0&&o.set(r,s)}return o.size>0?o:void 0}function qs(e,n){return e<3||!n?.size?null:Array.from({length:e},(t,o)=>Math.max(0,n.get(o)??0))}function Qs(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,s=Number.NEGATIVE_INFINITY,i=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),s=Math.max(s,u),i=Math.max(i,f)}if(!Number.isFinite(o+r+s+i))return;let c=Math.max(Ae*8,.25),a={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],h=e[d+1],g=e[m],y=e[m+1];Math.abs(p-g)<=c?Math.abs(p-o)<=c&&Math.abs(g-o)<=c?a.left=Math.max(a.left,f):Math.abs(p-s)<=c&&Math.abs(g-s)<=c&&(a.right=Math.max(a.right,f)):Math.abs(h-y)<=c&&(Math.abs(h-r)<=c&&Math.abs(y-r)<=c?a.top=Math.max(a.top,f):Math.abs(h-i)<=c&&Math.abs(y-i)<=c&&(a.bottom=Math.max(a.bottom,f)))}return a.left||a.right||a.top||a.bottom?a:void 0}function bh(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function xh(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=_n(e.vertices,n,t),r=Gn(o);return r?{normal:r,planeD:bh(r,o[0])}:null}function Ph(e,n){return(e.material?.key??e.color??"")===(n.material?.key??n.color??"")&&e.color===n.color}function Mh(e,n={}){return new Set(bl(e,n).keys())}function bl(e,n={}){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(a=>xh(a,t,o)),s=new Map;for(let a=0;a<e.length;a++){let l=e[a].vertices;if(!(!l||l.length<3))for(let u=0;u<l.length;u++){let f=yl(l[u],l[(u+1)%l.length]),d=s.get(f),m={polygon:a,edge:u};d?d.push(m):s.set(f,[m])}}let i=new Map,c=(a,l)=>{let u=i.get(a);u?u.add(l):i.set(a,new Set([l]))};for(let a of s.values())if(!(a.length<2))for(let l=0;l<a.length;l++)for(let u=l+1;u<a.length;u++){let f=a[l],d=a[u],m=f.polygon,p=d.polygon;!r[m]||!r[p]||Ph(e[m],e[p])&&(c(m,f.edge),c(p,d.edge))}return i}function Ah(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>Oo?!1:(e-t)*(e-r)+(n-o)*(n-s)<=Oo}function xl(e,n=_o,t=_o){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,c]=e[r],[a,l]=e[s];if(Ah(n,t,i,c,a,l))return!0;c>t!=l>t&&n<(a-i)*(t-c)/(l-c)+i&&(o=!o)}return o}function Pl(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=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),s=Math.max(s,u),i=Math.max(i,f))}let c=s-o,a=i-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(c)||!Number.isFinite(a)||c<=de||a<=de?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:c,height:a}}function Yt(e){let n=e.bleedRatio??1,t=ms*n,o=e.canvasW||1,r=e.canvasH||1,s=t>0?ht(e.screenPts,t):e.screenPts,i=t>0?Pl(s,o,r):{minX:0,minY:0,width:o,height:r},c=[];for(let a=0;a<s.length;a+=2){let l=Math.max(0,Math.min(100,(s[a]-i.minX)/i.width*100)),u=Math.max(0,Math.min(100,(s[a+1]-i.minY)/i.height*100));c.push([l,u])}return{bounds:i,points:c}}function Ml(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])<=Vo||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])<=Vo&&n.pop()}return n}function Al([e,n]){let t=new Set;return Math.abs(e)<=Ze&&t.add("left"),Math.abs(e-100)<=Ze&&t.add("right"),Math.abs(n)<=Ze&&t.add("top"),Math.abs(n-100)<=Ze&&t.add("bottom"),t.size>0?t:null}function Sl(e,n){for(let t of e)if(n.has(t))return!0;return!1}function Cl(e,n,t,o){let r=(s,i,c)=>{let a=n.has(i)?e:o.has(i)?t:null,l=n.has(c)?e:o.has(c)?t:null;if(!a||!l)return null;let u=(()=>{switch(s){case"topLeft":return{x:a[0],y:l[1]};case"topRight":return{x:100-a[0],y:l[1]};case"bottomRight":return{x:100-a[0],y:100-l[1]};case"bottomLeft":return{x:a[0],y:100-l[1]}}})();return u.x>Ze&&u.y>Ze&&u.x<100-Ze&&u.y<100-Ze?[s,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 Js(e){if(e.texture||yt(e)||zn(e))return null;let n=Yt(e),t=Ml(n.points);if(t.length<4)return null;let o=t.map(Al);if(o.some(i=>!i))return null;let r={},s=0;for(let i=0;i<t.length;i+=1){let c=o[i],a=o[(i+1)%t.length];if(Sl(c,a))continue;let l=Cl(t[i],c,t[(i+1)%t.length],a);if(!l)return null;let[u,f]=l,d=r[u];if(d&&(Math.abs(d.x-f.x)>Ze||Math.abs(d.y-f.y)>Ze))return null;r[u]=f,s+=1}return s>0?{bounds:n.bounds,radii:r}:null}function Sh([e,n]){return`${In(e)} ${In(n)}`}function Ch(e){return`polygon(${e.map(Sh).join(",")})`}function Eh(e){if(xl(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,c]of e)n+=i,t+=c;let r=In(Math.max(0,Math.min(100,n/o))),s=In(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function ei(e){return`${Ch(e)} ${Eh(e)}`}function Th(e){return ei(Yt(e).points)}function ni(e,n){return zt(e,n.width/xn,n.height/xn,n.minX,n.minY)}function vh(e){let n=Yt(e);return`matrix3d(${ni(e,n.bounds)})`}function Ih(e){let n=Yt(e);return[`transform:matrix3d(${ni(e,n.bounds)})`,`border-shape:${ei(n.points)}`].join(";")}function _h(e,n){let t=[`transform:matrix3d(${ni(e,n.bounds)})`,`width:${xn}px`,`height:${xn}px`,"border:0","box-sizing:border-box","background:currentColor"];for(let[o,r]of Object.entries(n.radii)){let s=o.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`);t.push(`border-${s}-radius:${In(r.x)} ${In(r.y)}`),t.push(`corner-${s}-shape:bevel`)}return t.join(";")}function El(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=.001,r=(s,i)=>{for(let c of s)if(Math.abs(c-i)<=o)return;s.push(i)};for(let s=0;s<e.screenPts.length;s+=2)r(n,e.screenPts[s]),r(t,e.screenPts[s+1]);if(n.length!==2||t.length!==2||(n.sort((s,i)=>s-i),t.sort((s,i)=>s-i),Math.abs(n[0])>o||Math.abs(t[0])>o||n[1]-n[0]<=o||t[1]-t[0]<=o))return null;for(let s=0;s<e.screenPts.length;s+=2){let i=e.screenPts[s],c=e.screenPts[s+1],a=Math.abs(i-n[0])<=o||Math.abs(i-n[1])<=o,l=Math.abs(c-t[0])<=o||Math.abs(c-t[1])<=o;if(!a||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function zn(e){return!!El(e)}function yt(e){return!e.texture&&e.polygon.vertices.length===3}function Wt(e){return!e.texture&&!!e.projectiveMatrix&&!zn(e)}function Oh(e){let n=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(e);return/\bVersion\/[\d.]+.*\bSafari\//.test(e)&&!n}function ti(e,n){e.set(n,(e.get(n)??0)+1)}function oi(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function Vh(e,n,t,o){let r=!t.has("b"),s=r&&o.projectiveQuadSupported,i=!t.has("u")&&o.solidTriangleSupported,c=!t.has("i")&&!!o.cornerShapeSupported,a=!t.has("i")&&o.borderShapeSupported,l=t.has("b");return e.map(u=>{if(!u||u.texture)return u;if(i&&yt(u))return null;let f=zn(u);return c&&!f&&!(s&&Wt(u))&&Js(u)!==null||r&&f||s&&Wt(u)||a&&(!f||l)?null:u})}function Rh(e,n,t,o,r,s,i){let c=new Map,a=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&&!!i?.(y);if(n==="dynamic"){if(!(d&&yt(y))&&!(u&&zn(y))&&!(f&&Wt(y))&&!b&&!p)continue;let x=r(y.polygon.color??"#cccccc"),P=s(x);ti(a,P),l.has(P)||l.set(P,x);continue}!(d&&yt(y))&&!(u&&zn(y))&&!(f&&Wt(y))&&!b&&!p||ti(c,y.shadedColor)}let h=oi(c),g=oi(a);return{paintColor:h,dynamicColorKey:g,dynamicColor:g?l.get(g):void 0}}function Lh(e,n){if((e+1)%3===n)return e;if((n+1)%3===e)return n}function wh(e,n,t,o,r,s,i){if(!e?.size)return null;let c=Yo(n,t);return[[s,o],[o,r],[r,s]].map(([l,u],f)=>{let d=Lh(l,u),m=d!==void 0&&e.has(d)?c:0;return Wo(i,f,m)})}function ri(e,n,t,o,r,s,i,c){let a=s,l="",u,f,d="";if(i){let m=c??e.color??"#cccccc",p=s.directionalLight,h=s.ambientLight,g=p?.direction??ot,y=p?.color??rt,b=Math.max(0,p?.intensity??st),x=h?.color??it,P=Math.max(0,h?.intensity??at),S=Math.hypot(g[0],g[1],g[2])||1,C=g[0]/S,T=g[1]/S,A=g[2]/S,E=s.lightOccludedPolyIndices?.has(n)??!1?0:b*Math.max(0,t*C+o*T+r*A),v=kn(m,E,y,x,P),I=s.textureLighting??"baked",_=I==="baked"&&a.stableTriangleColorSteps?bs(v,a.stableTriangleColorSteps):v,O=Pn(m),V=_===s.solidPaintDefaults?.paintColor,w=I==="dynamic"&&ys(O)===s.solidPaintDefaults?.dynamicColorKey;l=I==="dynamic"||V?"":_,u=l?Pn(l):void 0,f=l?Ro(l):void 0,d=I==="dynamic"?`--pnx:${t.toFixed(4)};--pny:${o.toFixed(4)};--pnz:${r.toFixed(4)};`+(w?"":`--psr:${(O.r/255).toFixed(4)};--psg:${(O.g/255).toFixed(4)};--psb:${(O.b/255).toFixed(4)};`):""}return{index:n,polygon:e,colorComputed:i,bakedColor:l||void 0,bakedRgb:u,bakedAlpha:f,dynamicVars:d}}function Nh(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??50,r=t.layerElevation??o,s=e.vertices[0],i=e.vertices[1],c=e.vertices[2],a=[s[1]*o,s[0]*o,s[2]*r],l=[i[1]*o,i[0]*o,i[2]*r],u=[c[1]*o,c[0]*o,c[2]*r],f=l[0]-a[0],d=l[1]-a[1],m=l[2]-a[2],p=u[0]-a[0],h=u[1]-a[1],g=u[2]-a[2],y=-(d*g-m*h),b=-(m*p-f*g),x=-(f*h-d*p),P=Math.sqrt(y*y+b*b+x*x);return P<=de?null:(y/=P,b/=P,x/=P,ri(e,n,y,b,x,t,!0))}function Dh(e,n,t,o={}){if(e.texture||e.vertices.length!==3)return null;let r=t.tileSize??50,s=t.layerElevation??r,i=e.vertices[0],c=e.vertices[1],a=e.vertices[2],l=i[1]*r,u=i[0]*r,f=i[2]*s,d=c[1]*r,m=c[0]*r,p=c[2]*s,h=a[1]*r,g=a[0]*r,y=a[2]*s;return si(e,n,t,o,l,u,f,d,m,p,h,g,y)}function si(e,n,t,o,r,s,i,c,a,l,u,f,d){let m=t,p=c-r,h=a-s,g=l-i,y=u-r,b=f-s,x=d-i,P=-(h*x-g*b),S=-(g*y-p*x),C=-(p*b-h*y),T=Math.sqrt(P*P+S*S+C*C);if(T<=de)return null;P/=T,S/=T,C/=T;let A=o.basis,M=A?.a??0,E=A?.b??1,v=A?.c??2;M<0||M>2||E<0||E>2||v<0||v>2||M===E||M===v||E===v?(A=void 0,M=0,E=1,v=2):M===0&&E===1&&v===2||M===1&&E===2&&v===0||M===2&&E===0&&v===1||(A=void 0,M=0,E=1,v=2);let I=()=>A?si(e,n,t,{...o,basis:void 0},r,s,i,c,a,l,u,f,d):null;if(!A){let ve=p*p+h*h+g*g,Qe=u-c,on=f-a,Je=d-l,We=r-u,rn=s-f,Yn=i-d,sn=Qe*Qe+on*on+Je*Je,je=We*We+rn*rn+Yn*Yn,Wn=ve;sn>Wn&&(M=1,E=2,v=0,Wn=sn),je>Wn&&(M=2,E=0,v=1)}let _,O,V,w,F,D,H=v===0?r:v===1?c:u,K=v===0?s:v===1?a:f,Q=v===0?i:v===1?l:d;M===0?(_=r,O=s,V=i):M===1?(_=c,O=a,V=l):(_=u,O=f,V=d),E===0?(w=r,F=s,D=i):E===1?(w=c,F=a,D=l):(w=u,F=f,D=d);let ne=w-_,ee=F-O,ue=D-V,U=Math.sqrt(ne*ne+ee*ee+ue*ue);if(U<=de)return I();let $=ne/U,k=ee/U,L=ue/U,W=(H-_)*$+(K-O)*k+(Q-V)*L,Y=S*L-C*k,se=C*$-P*L,Z=P*k-S*$,B=T/U;if(B<=de)return I();let q=Math.max(0,Math.min(U,W)),me=Math.max(0,U-q),fe=[q,0,0,B,q+me,B],G=is*(m.bleedRatio??1),te=wh(m.seamEdges,m.seamBleed,G,M,E,v,fe),ce=te?Xt(fe,te):js(q,me,B,Yo(m.seamBleed,G)),ye=ce[0],he=ce[1],be=ce[2],ge=ce[3],Se=ce[4],De=ce[5],R=(ge+De)/2,z=ye-be,j=Se-ye,J=R-he;if(z<=de||j<=de||J<=de||!Number.isFinite(z+j+J))return I();let le=o.includeColor??!0,re=!1,pe,xe,ie,ae="";if(le){let ve=ri(e,n,P,S,C,t,!0,o.color);re=ve.colorComputed,pe=ve.bakedColor,xe=ve.bakedRgb,ie=ve.bakedAlpha,ae=ve.dynamicVars??""}let N=pe?`color:${pe};`:"",X=o.primitive??o.resolvedPrimitive??"border",Te=1/(X==="border-large"?us:ls),Ce=z+j,Pe=Ce*Te,_e=(j-z)*.5*Te,Oe=J*Te,Ve=ye-q-Ce*.5,$e=he,Ee=$*Pe,Fe=k*Pe,we=L*Pe,$n=$*_e+Y*Oe,Xn=k*_e+se*Oe,cn=L*_e+Z*Oe,qe=H+$*Ve+Y*$e,ln=K+k*Ve+se*$e,Be=Q+L*Ve+Z*$e,Xe=o.matrixDecimals??Ks(m.stableTriangleMatrixDecimals),Me=$s(Ee,Fe,we,$n,Xn,cn,P,S,C,qe,ln,Be,Xe),Re=t.textureLighting??"baked",Ie=m.optimizeStableTriangleStyle===!0&&Re==="baked"?"":`transform:${Me};`+N+ae,Ye=A&&A.a===M&&A.b===E&&A.c===v?A:{a:M,b:E,c:v};return{index:n,polygon:e,styleText:Ie,transformText:Me,basis:Ye,primitive:X,colorComputed:re,bakedColor:pe,bakedRgb:xe,bakedAlpha:ie,dynamicVars:ae}}function Tl(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function vl(e){let n=e?.maxWeightRatio,t=Math.max(0,Tl(e?.denomEps,ds)),o=typeof n=="number"&&Number.isFinite(n)&&n>0?Math.max(1,n):ps,r=Math.max(0,Tl(e?.bleed,gs));return{denomEps:t,maxWeightRatio:o,bleed:r,disableGuards:e?.disableGuards===!0}}function ii(e,n){if(e.length!==4||!$t(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],c=t[1]-o[1]+r[1]-s[1],a=o[0]-r[0],l=s[0]-r[0],u=o[1]-r[1],f=s[1]-r[1],d=a*f-u*l;if(Math.abs(d)<=de)return null;let m=(i*f-c*l)/d,p=(a*c-u*i)/d,h=[1,1+m,1+m+p,1+p];if(h.some(b=>!Number.isFinite(b)))return null;let g=Math.min(...h),y=Math.max(...h);return!n.disableGuards&&(g<=n.denomEps||y/g>n.maxWeightRatio)?null:{g:m,h:p,w1:1+m,w3:1+p}}function Il(e,n,t,o,r,s,i,c,a){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(!ii(l,c))return null;let u=qs(4,a),f=u?Xt(e,u):ht(e,c.bleed),d=[[f[0],f[1]],[f[2],f[3]],[f[4],f[5]],[f[6],f[7]]],m=ii(d,c);if(!m)return null;let{g:p,h,w1:g,w3:y}=m,[b,x,,P]=d,S=[r+b[0]*n[0]+b[1]*t[0],s+b[0]*n[1]+b[1]*t[1],i+b[0]*n[2]+b[1]*t[2]],C=([A,M],E)=>[(E-1)*r+(E*A-b[0])*n[0]+(E*M-b[1])*t[0],(E-1)*s+(E*A-b[0])*n[1]+(E*M-b[1])*t[1],(E-1)*i+(E*A-b[0])*n[2]+(E*M-b[1])*t[2]],T=[...C(x,g),p,...C(P,y),h,o[0],o[1],o[2],0,S[0],S[1],S[2],1];for(let A=0;A<8;A+=1)T[A]/=ct;return vn(T,6)}function Ko(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Fh(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 _l(e){return!e.texture}function Ol(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=_n(e.vertices,n,t),r=Gn(o);return r?{pts:o,normal:r,planeD:Ko(r,o[0]),optimizable:_l(e)}:null}function Vl(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:li(e,n)}function li(e,n){return!e||!n||Ko(e.normal,n.normal)<1-rs?!1:Math.abs(e.planeD-n.planeD)<=ss}function ai(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??ot,s=t?.color??rt,i=Math.max(0,t?.intensity??st),c=o?.color??it,a=Math.max(0,o?.intensity??at),l=Math.hypot(r[0],r[1],r[2])||1,u=r[0]/l,f=r[1]/l,d=r[2]/l,m=i*Math.max(0,e.normal[0]*u+e.normal[1]*f+e.normal[2]*d),p=wo(m,s,c,a);return p.r*.2126+p.g*.7152+p.b*.0722}function Rl(e){let n=[...e],t=Math.abs(n[0])>de?0:Math.abs(n[1])>de?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 bt(e,n,t,o,r={}){let s=Ko(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],c=Math.hypot(i[0],i[1],i[2]);if(c<=de)return null;let a=[i[0]/c,i[1]/c,i[2]/c],l=[t[1]*a[2]-t[2]*a[1],t[2]*a[0]-t[0]*a[2],t[0]*a[1]-t[1]*a[0]],u=Math.hypot(l[0],l[1],l[2]);if(u<=de)return null;let f=[l[0]/u,l[1]/u,l[2]/u],d=e.map(V=>{let w=V[0]-n[0],F=V[1]-n[1],D=V[2]-n[2];return[w*a[0]+F*a[1]+D*a[2],w*f[0]+F*f[1]+D*f[2]]}),m=r.boundsOrigin??n,p=n[0]-m[0],h=n[1]-m[1],g=n[2]-m[2],y=p*a[0]+h*a[1]+g*a[2],b=p*f[0]+h*f[1]+g*f[2],x=1/0,P=1/0,S=-1/0,C=-1/0;for(let[V,w]of d){let F=V+y,D=w+b;F<x&&(x=F),F>S&&(S=F),D<P&&(P=D),D>C&&(C=D)}let T=S-x,A=C-P;if(!Number.isFinite(T)||!Number.isFinite(A))return null;let M=r.snapBounds?Math.floor(x+Ae):x,E=r.snapBounds?Math.floor(P+Ae):P,v=r.snapBounds?Math.ceil(S-Ae):S,I=r.snapBounds?Math.ceil(C-Ae):C,_=Math.max(1,r.snapBounds?v-M:Math.ceil(T)),O=Math.max(1,r.snapBounds?I-E:Math.ceil(A));return{xAxis:a,yAxis:f,local2D:d,shiftX:y-M,shiftY:b-E,canvasW:_,canvasH:O,pixelArea:_*O,rawArea:T*A}}function jo(e){return`${e[0]},${e[1]},${e[2]}`}function Ll(e,n){return jo(e)<jo(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 Bh(e,n){let t=jo(e),o=jo(n);return t<o?`${t}|${o}`:`${o}|${t}`}function wl(e,n,t,o){let r=0,s=0;for(let i of e){let c=n[i];if(!c)return null;let a=bt(c.pts,c.pts[0],c.normal,t,{boundsOrigin:o,snapBounds:!0});if(!a)return null;r+=a.pixelArea,s+=a.rawArea}return{pixelArea:r,rawArea:s}}function Nl(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let c=n[i];if(!c)continue;let a=[c.pts[1][0]-c.pts[0][0],c.pts[1][1]-c.pts[0][1],c.pts[1][2]-c.pts[0][2]],l=bt(c.pts,c.pts[0],c.normal,a);o&&l?(o.pixelArea+=l.pixelArea,o.rawArea+=l.rawArea):o=null;for(let u=0;u<c.pts.length;u++){let f=Ll(c.pts[u],c.pts[(u+1)%c.pts.length]),d=bt(c.pts,c.pts[0],c.normal,f);if(!d)continue;let m=Rl(d.xAxis);if(s.has(m))continue;s.add(m);let p=wl(e,n,d.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-Ae)&&(r={xAxis:d.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+Ae)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function kh(e,n){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(f=>Ol(f,t,o)),s=new Map,i=e.map(()=>new Set),c=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=Bh(d[m],d[(m+1)%d.length]),h=s.get(p),g={polygon:f,edge:m};h?h.push(g):s.set(p,[g])}}let a=e.map(()=>new Set);for(let f of s.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],h=f[m],g=p.polygon,y=h.polygon;if(e[g].texture&&e[y].texture&&(c[p.polygon].add(p.edge),c[h.polygon].add(h.edge)),li(r[g],r[y]))i[p.polygon].add(p.edge),i[h.polygon].add(h.edge);else{let b=ai(r[g],n),x=ai(r[y],n);b!==null&&x!==null&&(b<=x+vo&&i[p.polygon].add(p.edge),x<=b+vo&&i[h.polygon].add(h.edge))}Vl(r[g],r[y])&&(a[g].add(y),a[y].add(g))}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 h=m.pop();d.push(h);for(let g of a[h])u.has(g)||(u.add(g),m.push(g))}if(d.length<2)continue;let p=Nl(d,r);if(p)for(let h of d)l[h]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:c[h]}}for(let f=0;f<e.length;f++)!l[f]&&(i[f].size>0||c[f].size>0)&&(l[f]={seamEdges:i[f],textureEdgeRepairEdges:c[f]});return l}function ci(e,n,t,o){if(o.optimize&&o.fixedXAxis)return bt(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((c,a)=>a):[0]);for(let c of i){let a=(c+1)%e.length,l=s?Ll(e[c],e[a]):[e[a][0]-e[c][0],e[a][1]-e[c][1],e[a][2]-e[c][2]],u=bt(e,n,t,l,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-Ae)&&(r=u)}return r}function Dl(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=Ae)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>Ae||Math.abs(t[0])>Ae||n[1]-n[0]<=Ae||t[1]-t[0]<=Ae))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,c=s+e.shiftY,a=Math.abs(i-n[0])<=Ae||Math.abs(i-n[1])<=Ae,l=Math.abs(c-t[0])<=Ae||Math.abs(c-t[1])<=Ae;if(!a||!l)return!1}return!0}function ui(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,c]=n,a=t[0],l=t[1],u=o[0],f=o[1],d=r[0],m=r[1],p=s[0],h=1-s[1],g=i[0],y=1-i[1],b=c[0],x=1-c[1],P=g-p,S=y-h,C=b-p,T=x-h,A=P*T-C*S;if(Math.abs(A)<=1e-9)return null;let M=u-a,E=d-a,v=f-l,I=m-l,_={a:(M*T-E*S)/A,b:(P*E-C*M)/A,c:(v*T-I*S)/A,d:(P*I-C*v)/A,e:0,f:0};return _.e=a-_.a*p-_.b*h,_.f=l-_.c*p-_.d*h,_}function fi(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],c=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(c))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,c),r=Math.max(r,c)}return{minU:n,minV:t,maxU:o,maxV:r}}function Fl(e,n,t,o,r,s,i,c){let l=_n(e.vertices,n,t).map(d=>{let m=d[0]-o[0],p=d[1]-o[1],h=d[2]-o[2];return[m*r[0]+p*r[1]+h*r[2]+i,m*s[0]+p*s[1]+h*s[2]+c]}),u=ui(l,e.uvs),f=fi(e.uvs);return!u&&!f?null:{screenPts:l.flatMap(([d,m])=>[d,m]),uvAffine:u,uvSampleRect:f}}function Bl(e,n,t,o,r){let s=t,{vertices:i,texture:c,uvs:a}=e;if(!i||i.length<3)return null;let l=t.tileSize??50,u=t.layerElevation??l,f=_n(i,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 g=Gn(f);if(!g)return null;let y=ci(f,d,g,{optimize:!1}),b=c||y&&Dl(y)?y:ci(f,d,g,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:P,local2D:S}=b,C=c&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,T=!!(c&&C),A=b.shiftX,M=b.shiftY,E=b.canvasW,v=b.canvasH,I=[];for(let[ge,Se]of S)I.push(ge+A,Se+M);let _=d[0]-A*x[0]-M*P[0],O=d[1]-A*x[1]-M*P[1],V=d[2]-A*x[2]-M*P[2],w=vn([x[0],x[1],x[2],0,P[0],P[1],P[2],0,g[0],g[1],g[2],0,_,O,V,1]),F=vn([x[0]*E,x[1]*E,x[2]*E,0,P[0]*v,P[1]*v,P[2]*v,0,g[0],g[1],g[2],0,_,O,V,1]),D=vn([x[0]*E/He,x[1]*E/He,x[2]*E/He,0,P[0]*v/He,P[1]*v/He,P[2]*v/He,0,g[0],g[1],g[2],0,_,O,V,1]),H=Hs(s.seamBleed),K=Zs(I,s.seamEdges??r?.seamEdges,H),Q=K?new Set(K.keys()):void 0,ne=K?Math.max(...K.values()):void 0,ee=Qs(I,K),ue=!c&&i.length===4?Il(I,x,P,g,_,O,V,o,K):null,U=t.directionalLight,$=t.ambientLight,k=U?.direction??ot,L=U?.color??rt,W=Math.max(0,U?.intensity??st),Y=$?.color??it,se=Math.max(0,$?.intensity??at),Z=Math.hypot(k[0],k[1],k[2])||1,B=k[0]/Z,q=k[1]/Z,me=k[2]/Z,G=t.lightOccludedPolyIndices?.has(n)??!1?0:W*Math.max(0,g[0]*B+g[1]*q+g[2]*me),te=wo(G,L,Y,se),ce=kn(e.color??"#cccccc",G,L,Y,se),ye=null,he=null;c&&a&&a.length>=3&&a.length===i.length&&(he=fi(a),ye=ui(S.map(([ge,Se])=>[ge+A,Se+M]),a));let be=c&&e.textureTriangles?.length?e.textureTriangles.map(ge=>Fl(ge,l,u,d,x,P,A,M)).filter(ge=>!!ge):null;return{index:n,polygon:e,texture:c,tileSize:l,layerElevation:u,matrix:w,canonicalMatrix:F,atlasMatrix:D,projectiveMatrix:ue,canvasW:E,canvasH:v,screenPts:I,uvAffine:ye,uvSampleRect:he,textureTriangles:be,textureEdgeRepairEdges:C,textureEdgeRepair:T,seamBleed:ne,seamBleedEdges:Q,seamBleedEdgeAmounts:K,seamBleedInsets:ee,bleedRatio:hs(s.seamBleed),normal:g,textureTint:te,shadedColor:ce}}function Uh(e,n,t={},o,r){let s=vl(o),i=t,c=r??(t.textureEdgeRepairEdges?.size?{seamEdges:new Set,textureEdgeRepairEdges:t.textureEdgeRepairEdges}:void 0);return Bl(e,n,i,s,c)}function Kt(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Qr,Math.max(qr,n))}function di(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function kl(e,n){let t=di(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=Ft/o,s=Math.sqrt(n/(t*4));return Kt(Math.min(r,s))}function Ul(e,n){let t=di(e),o=.5;return t<=To?o=1:t<=Jr&&(o=.75),Kt(Math.min(o,kl(e,n)))}function Gl(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function zl(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function $l(e,n,t){let o=Gl(e,n),r=zl(e,n),s=o>Ft?Ft/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function Xl(e){return e?es:ns}function Yl(e,n){return e!==void 0&&e!=="auto"?He:n?He:fs}function mi(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=Xs(t,n));return e}function Gh(e){return e.atlasCanonicalSize??He}function Wl(e){return Math.max(Eo,Math.ceil(Eo/e))}function jt(e,n=1){let t=Array(e.length).fill(null),o=[],r=Wl(n),s=e.filter(a=>!!a).sort((a,l)=>l.canvasH-a.canvasH||l.canvasW-a.canvasW||a.index-l.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),c=(a,l,u)=>{if(a.sealed)return null;for(let m of a.shelves)if(l.canvasH<=m.height&&m.x+l.canvasW+r<=Cn){let p={...l,pageIndex:u,x:m.x,y:m.y};return m.x+=l.canvasW+r*2,a.entries.push(p),a.width=Math.max(a.width,p.x+l.canvasW+r),p}let f=a.shelves.length===0?r:a.height+r;if(f+l.canvasH+r>Cn)return null;let d={...l,pageIndex:u,x:r,y:f};return a.shelves.push({x:r+l.canvasW+r*2,y:f,height:l.canvasH}),a.entries.push(d),a.width=Math.max(a.width,d.x+l.canvasW+r),a.height=Math.max(a.height,f+l.canvasH+r),d};for(let a of s){if(a.canvasW+r*2>Cn||a.canvasH+r*2>Cn){let f=o.length,d={...a,pageIndex:f,x:r,y:r};t[a.index]=d,o.push({width:a.canvasW+r*2,height:a.canvasH+r*2,entries:[d],shelves:[],sealed:!0});continue}let u=null;for(let f=0;f<o.length&&(u=c(o[f],a,f),!u);f++);if(!u){let f=i(),d=o.length;o.push(f),u=c(f,a,d)}u&&(t[a.index]=u)}return{entries:t,pages:o.map(({width:a,height:l,entries:u})=>({width:a,height:l,entries:u}))}}function zh(e,n,t){let o=Ul(n.pages,t),r=o===1?n:jt(e,o);for(let s=0;s<4;s++){let i=$l(r.pages,o,t);if(i>=1)break;let c=Kt(o*i*ts);if(c>=o)break;o=c,r=jt(e,o)}return{packed:r,atlasScale:o}}function $h(e,n,t){let o=Yl(n,t);if(n!==void 0&&n!=="auto"){let i=Kt(n);return{packed:mi(jt(e,i),o),atlasScale:i,atlasCanonicalSize:o}}let r=jt(e,1),s=zh(e,r,Xl(t));return{packed:mi(s.packed,o),atlasScale:s.atlasScale,atlasCanonicalSize:o}}export{ig as ASYNC_RENDER_BUDGET_MS,fs as ATLAS_CANONICAL_SIZE_AUTO_DESKTOP,He as ATLAS_CANONICAL_SIZE_EXPLICIT,Cn as ATLAS_MAX_SIZE,Eo as ATLAS_PADDING,To as AUTO_ATLAS_LOW_AREA,Ft as AUTO_ATLAS_MAX_BITMAP_SIDE,ns as AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP,es as AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE,Jr as AUTO_ATLAS_MEDIUM_AREA,ts as AUTO_ATLAS_SCALE_GUARD,eg as BAKED_SHADOW_MIN_UP,Jp as BAKED_SHADOW_Z_SQUASH,ze as BASE_TILE,de as BASIS_EPS,ms as BORDER_SHAPE_BLEED,xn as BORDER_SHAPE_CANONICAL_SIZE,_o as BORDER_SHAPE_CENTER_PERCENT,Oo as BORDER_SHAPE_POINT_EPS,Po as CAMERA_BACKFACE_CULL_EPS,os as COLOR_PARSE_CACHE_MAX,Vo as CORNER_SHAPE_DUPLICATE_EPS,Ze as CORNER_SHAPE_POINT_EPS,cs as DECIMAL_SCALES,it as DEFAULT_AMBIENT_COLOR,at as DEFAULT_AMBIENT_INTENSITY,Io as DEFAULT_ATLAS_CSS_DECIMALS,as as DEFAULT_BORDER_SHAPE_DECIMALS,Hn as DEFAULT_CAMERA_STATE,rt as DEFAULT_LIGHT_COLOR,ot as DEFAULT_LIGHT_DIR,st as DEFAULT_LIGHT_INTENSITY,bn as DEFAULT_MATRIX_DECIMALS,jl as DEFAULT_PROJECTION,fg as DEFAULT_SEAM_BLEED,Zi as DEFAULT_SEAM_FACET_SPLIT_OPTIONS,Hi as DEFAULT_SEAM_OVERLAP_OPTIONS,yn as DEFAULT_TILE,yc as LoopOnce,bc as LoopPingPong,Ss as LoopRepeat,Qr as MAX_ATLAS_SCALE,qr as MIN_ATLAS_SCALE,gs as PROJECTIVE_QUAD_BLEED,ds as PROJECTIVE_QUAD_DENOM_EPS,ps as PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,iu as QUAT_IDENTITY,pc as RECEIVER_NORMAL_TOL,gc as RECEIVER_OFFSET_TOL,dc as RECEIVER_OUTLINE_EXPAND,Ae as RECT_EPS,vo as SEAM_LIGHT_EPS,ct as SOLID_QUAD_CANONICAL_SIZE,is as SOLID_TRIANGLE_BLEED,ls as SOLID_TRIANGLE_CANONICAL_SIZE,us as SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE,ss as SURFACE_DISTANCE_EPS,rs as SURFACE_NORMAL_EPS,cg as TEXTURE_EDGE_REPAIR_ALPHA_MIN,ug as TEXTURE_EDGE_REPAIR_RADIUS,lg as TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN,ag as TEXTURE_TRIANGLE_BLEED,Ga as VOXEL_CAMERA_CULL_AXIS_EPS,za as VOXEL_CAMERA_CULL_NORMAL_LIMIT,mi as applyPackedAtlasCanonicalSize,qa as arrowPolygons,di as atlasArea,Gl as atlasBitmapMaxSide,Gh as atlasCanonicalSizeForEntry,Yl as atlasCanonicalSizeForTextureQuality,zl as atlasDecodedBytes,Wl as atlasPadding,$l as autoAtlasBudgetFactor,Xl as autoAtlasMaxDecodedBytes,Ul as autoAtlasScale,kl as autoAtlasScaleCap,ja as axesHelperPolygons,h0 as bakeSolidTextureSampledPolygons,Os as bakeSolidTextureSamples,Rl as basisAxisKey,Pl as borderShapeBoundsFromPoints,Yt as borderShapeGeometryForPlan,Ha as boxPolygons,ng as buildBakedShadowProjectionMatrix,kh as buildBasisHints,xs as buildEdgeOwners,sg as buildPolyMeshTransform,Jl as buildSceneContext,bl as buildSeamBleedPolygonEdges,Mh as buildSeamBleedPolygonSet,bg as buildSharedEdgeMap,yh as buildTextureEdgeRepairSets,ut as cachedParsePureColor,Ya as cameraCullNormalGroups,zp as cameraCullNormalGroupsFromPolygons,Xa as cameraCullNormalKey,Xp as cameraCullVisibleSignature,$a as cameraFacingDepth,Nl as chooseIslandXAxis,ci as chooseLocalBasis,On as clampChannel,Ps as classifyFacing,Sn as clipPolygonToConvex2D,yg as colorErrorScore,li as compatibleBleedSurface,Vl as compatibleSurface,Up as computeLightVisibility,Zs as computePlanSeamBleedEdgeAmounts,ii as computeProjectiveQuadCoefficients,Il as computeProjectiveQuadMatrix,Ag as computeReceiverShadowFaces,Si as computeSceneBbox,Qs as computeSeamBleedInsets,Hl as computeShapeLighting,Nh as computeSolidTriangleColorPlan,ri as computeSolidTriangleColorPlanFromNormal,Dh as computeSolidTrianglePlan,si as computeSolidTrianglePlanFromCssPoints,Gn as computeSurfaceNormal,Bl as computeTextureAtlasPlan,Uh as computeTextureAtlasPlanPublic,ru as computeTexturePaintMetrics,ui as computeUvAffine,fi as computeUvSampleRect,ic as conePolygons,jr as convexHull2D,Cl as cornerShapeDiagonal,Js as cornerShapeGeometryForPlan,Al as cornerShapePointSides,ir as coverPlanarPolygons,du as createIsometricCamera,vg as createPolyAnimationMixer,Fh as crossVec,ei as cssBorderShapeForGeometry,Th as cssBorderShapeForPlan,uc as cssDistanceToWorld,_n as cssPoints,fc as cssPositionToWorld,fn as cullInteriorPolygons,Ao as cylinderPolygons,Du as dedupeOverlappingPolygons,sc as dodecahedronPolygons,oi as dominantCountKey,Ko as dotVec,gn as ensureCcw2D,uu as eulerXYZFromQuat,wl as evaluateIslandAxis,gt as expandClipPoints,mc as expandConvexHullOutward,Ms as extractSilhouetteLoops,Vh as filterAtlasPlans,Jt as findOverlappingPolygonDuplicates,fh as formatAffineMatrix3dColumns,zs as formatAffineMatrix3dScalars,$s as formatAffineMatrix3dTransformScalars,Xs as formatAtlasMatrix,Ih as formatBorderShapeElementStyle,vh as formatBorderShapeEntryMatrix,mh as formatBorderShapeMatrix,Ht as formatColor,_h as formatCornerShapeElementStyle,uh as formatCssLength,ph as formatCssLengthPx,dh as formatMatrix3d,vn as formatMatrix3dValues,In as formatPercent,zt as formatScaledMatrixFromPlan,gh as formatSolidQuadEntryMatrix,pl as formatSolidQuadMatrix,El as fullRectBounds,Ol as getPolygonBasisInfo,Rh as getSolidPaintDefaultsForPlansCore,Zr as groupReceiverFaceGroups,rc as icosahedronPolygons,ti as incrementCount,Ws as intersect2DLines,hh as intersect2DLinesRaw,su as inverseRotateVec3,Wa as isAxisAlignedSurfaceNormal,tg as isBakedShadowCaster,_l as isBasisOptimizable,$t as isConvexPolygonPoints,Dl as isFullRectBasis,zn as isFullRectSolid,Wt as isProjectiveQuadPlan,yt as isSolidTrianglePlan,$p as isVoxelCameraCullableNormalGroups,lh as loadMesh,bt as makeLocalBasis,an as mergePolygons,Hr as meshScaleVec3,Nt as normalFacesCamera,Kt as normalizeAtlasScale,fu as normalizeInvertMultiplier,qo as normalizePolygons,Hs as normalizedSeamBleed,nc as octahedronPolygons,ht as offsetConvexPolygonPoints,Xt as offsetConvexPolygonPointsByEdgeAmounts,js as offsetStableTrianglePoints,Xo as offsetTrianglePoints,A0 as optimizeAnimatedMeshPolygons,tt as optimizeMeshParseResult,gd as optimizeMeshPolygons,jt as packTextureAtlasPlans,$h as packTextureAtlasPlansWithScaleCore,Ro as parseAlpha,jn as parseColor,vs as parseGltf,Pn as parseHex,pi as parseHexColor,ws as parseMtl,Rs as parseObj,Mn as parsePureColor,gi as parseRgbColor,Gs as parseStl,Ds as parseVox,ec as planePolygons,uc as polyCssDistanceToWorld,fc as polyCssPositionToWorld,xl as polygonContainsPoint,Xr as polygonCssSurfaceNormal,eu as polygonFaces,Gp as polygonFacesCamera,cc as polygonSignedArea2D,xg as prepareCasterEdgeOwners,Pg as prepareCasterPolyItems,Mg as prepareReceiverFacePlanes,og as projectCssVertexToGround,Fl as projectTextureTriangle,bs as quantizeCssColor,cu as quatFromAxisAngle,lu as quatFromEulerXYZ,au as quatMultiply,em as repairMeshSeams,hs as resolveBleedRatio,vl as resolveProjectiveQuadGuards,Yo as resolveSeamBleed,pg as rgbEqual,ys as rgbKey,hg as rgbToCss,Lo as rgbToHex,Qa as ringPolygons,Ja as ringQuadPolygons,Qo as rotateVec3,Vn as rotateVec3InWrapperCssFrame,Ne as roundDecimal,Oh as safariCssProjectiveUnsupported,Wo as safePlanSeamBleedAmount,pu as screenToWorldOnSphere,vi as screenToWorldRay,qs as seamBleedAmountArray,aa as seamFacetSplitPolygons,Jf as seamFacetSplitReport,ai as seamLightBrightness,nm as seamOverlapDiagnostics,ca as seamOverlapPolygons,tm as seamOverlapReport,Kl as shadeColor,kn as shadePolygon,Sl as sharedCornerShapeSide,Ys as signedArea2D,Ml as simplifyCornerShapePoints,Sr as simplifyTriangleMeshPolygons,tc as spherePolygons,gl as stableBasisFromPlan,Ks as stableTriangleMatrixDecimals,gg as stepRgbToward,oc as tetrahedronPolygons,wo as textureTintFactors,mg as tintToCss,ac as torusPolygons,Dt as worldCssForMesh,Kr as worldDirectionToCss,Kr as worldDirectionToPolyCss,rg as worldDirectionalLightToCss,lc as worldDistanceToCss,lc as worldDistanceToPolyCss,hn as worldPositionToCss,hn as worldPositionToPolyCss};
|
|
1
|
+
var Kl="cubic";function pi(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 gi(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 An(e){if(!e)return null;let n=e.trim(),t=pi(n);return t||gi(n)}function Vn(e){return Math.max(0,Math.min(255,Math.round(e)))}function Ht(e){let[n,t,o]=e.rgb.map(Vn);return e.alpha<1?`rgba(${n}, ${t}, ${o}, ${e.alpha})`:`rgb(${n}, ${t}, ${o})`}var Zo={rgb:[204,204,204],alpha:1},hi=new Map;function Kn(e){if(!e)return null;let n=e.trim(),t=hi.get(n);if(t)return t;let o=An(n);return o?(hi.set(n,o),o):null}function Hl(e,n){let t=Kn(e)??Zo,o=[Vn(t.rgb[0]+n),Vn(t.rgb[1]+n),Vn(t.rgb[2]+n)];return Ht({rgb:o,alpha:t.alpha})}var Ho={direction:[0,0,-1],color:"#ffffff",intensity:1},yi={color:"#ffffff",intensity:.4};function bi(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 xi(e,n,t){let o=Kn(n)??Zo;return e*(o.rgb[t]/255)}function Zl(e,n,t,o){let r=Kn(n)??Zo,s=bi(t?.direction??Ho.direction),i=t?.color??Ho.color,c=Math.max(0,t?.intensity??Ho.intensity),a=o?.color??yi.color,l=Math.max(0,o?.intensity??yi.intensity),u=bi(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),d=c*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let h=r.rgb[p],g=xi(h,a,p)*l,y=xi(h,i,p)*d;m[p]=Vn(g+y)}return Ht({rgb:m,alpha:r.alpha})}var Pi="#cccccc",Zt=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Mi=(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]],Ai=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],qt=e=>Math.hypot(e[0],e[1],e[2]);function ql(e){let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-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]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);let c=r-n,a=s-t,l=i-o;return Math.hypot(c,a,l)}function Ql(){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 qo(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 s=r.vertices;if(s.length<3){t.push(`Polygon ${o}: ${s.length} vertices (need >= 3), dropped`);continue}let i=Zt(s[1],s[0]),c=Zt(s[2],s[0]),a=Mi(i,c),l=qt(a);if(s.length===3){if(l<1e-12){qt(i)<1e-12||qt(c)<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:s.slice()}];if(s.length>=4){let f=[a[0]/l,a[1]/l,a[2]/l],d=Ai(f,s[0]),m=ql(s),p=Math.max(1e-6,m*.001),h=0;for(let g=3;g<s.length;g++){let y=Math.abs(Ai(f,s[g])-d);y>h&&(h=y)}if(h>p){let g=[],y=r.uvs&&r.uvs.length===s.length?r.uvs:void 0;for(let b=1;b<s.length-1;b++){let x=[s[0].slice(),s[b].slice(),s[b+1].slice()],P=Mi(Zt(x[1],x[0]),Zt(x[2],x[0]));if(qt(P)<1e-12)continue;let S={...r,vertices:x};y&&(S.uvs=[y[0].slice(),y[b].slice(),y[b+1].slice()]),g.push(S)}if(g.length===0){t.push(`Polygon ${o}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${o}: ${s.length} non-coplanar vertices, fan-triangulated to ${g.length} triangles`),u=g}}for(let f of u){let d=Jl(f,o,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function Jl(e,n,t){let o={vertices:e.vertices},r=e.texture;if(typeof r=="string"&&r===""&&(r=void 0),e.color!==void 0&&r!==void 0&&Ql()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Kn(e.color)?o.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${Pi}`),o.color=Pi)),r!==void 0&&(o.texture=r,e.textureWrap&&(o.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(o.textureAlphaMode=e.textureAlphaMode)),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 s={},i=!1;for(let c of Object.keys(e.data)){let a=e.data[c];typeof a=="string"||typeof a=="number"||typeof a=="boolean"?s[c]=a:(i=!0,t.push(`Polygon ${n}: data["${c}"] has non-primitive value, key dropped`))}Object.keys(s).length>0&&(o.data=s)}return o}function Si(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,s=-1/0,i=-1/0,c=!1;for(let a of e)if(a?.vertices)for(let l of a.vertices)l&&(c=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]));return c?{min:[n,t,o],max:[r,s,i]}:{min:[0,0,0],max:[0,0,0]}}function eu(e){let n=e.polygons??[],t,o;if(e.skipNormalize)t=n,o=[];else{let c=qo(n);t=c.polygons,o=c.warnings}let r=Si(t),s=[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:s},warnings:o}}function nu(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function tu(e){let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],s=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],i=r[1]*s[2]-r[2]*s[1],c=r[2]*s[0]-r[0]*s[2],a=r[0]*s[1]-r[1]*s[0],l=Math.hypot(i,c,a);return l<=1e-9?null:[i/l,c/l,a/l]}function ou(e){let n=0;for(let t=0;t<e.length;t++){let[o,r]=e[t],[s,i]=e[(t+1)%e.length];n+=o*i-s*r}return Math.abs(n)/2}function ru(e,n,t){if(!e||e.length<3)return null;let o=e.map(c=>[c[1]*n,c[0]*n,c[2]*t]),r=tu(o);if(!r)return null;let s=1/0,i=0;for(let c=0;c<o.length;c++){let a=o[c],l=o[(c+1)%o.length],u=[l[0]-a[0],l[1]-a[1],l[2]-a[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],h=[r[1]*p[2]-r[2]*p[1],r[2]*p[0]-r[0]*p[2],r[0]*p[1]-r[1]*p[0]],g=Math.hypot(h[0],h[1],h[2]);if(g<=1e-9)continue;let y=[h[0]/g,h[1]/g,h[2]/g],b=o.map(v=>{let I=v[0]-a[0],_=v[1]-a[1],O=v[2]-a[2];return[I*p[0]+_*p[1]+O*p[2],I*y[0]+_*y[1]+O*y[2]]}),x=1/0,P=1/0,S=-1/0,C=-1/0;for(let[v,I]of b)x=Math.min(x,v),P=Math.min(P,I),S=Math.max(S,v),C=Math.max(C,I);let T=S-x,A=C-P,M=Math.max(1,Math.ceil(T))*Math.max(1,Math.ceil(A)),E=ou(b);E<=1e-9||M<s&&(s=M,i=E)}return!Number.isFinite(s)||i<=1e-9?null:{elementArea:s,polygonArea:i}}function su(e,n={}){let t=n.tileSize??100,o=n.layerElevation??t,r=n.texturedOnly??!0,s=0,i=0,c=0,a=0,l=0;for(let f of e){let d=!!f.texture;if(r&&!d)continue;let m=ru(f.vertices,t,o);m&&(s+=1,d&&(i+=1),c+=m.elementArea,a+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,c-a);return{totalPolygons:e.length,measuredPolygons:s,texturedPolygons:i,elementArea:c,polygonArea:a,transparentArea:u,transparentRatio:c>0?u/c:0,overdrawRatio:a>0?c/a:0,worstTransparentRatio:l}}function Qo(e,n,t,o){let r=n*Math.PI/180,s=t*Math.PI/180,i=o*Math.PI/180,[c,a,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[c,a]=[c*u-a*f,c*f+a*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[c,l]=[c*u+l*f,-c*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[a,l]=[a*u-l*f,a*f+l*u]}return[c,a,l]}function iu(e,n){let t=-n[0]*Math.PI/180,o=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[s,i,c]=e;if(t!==0){let a=Math.cos(t),l=Math.sin(t);[i,c]=[i*a-c*l,i*l+c*a]}if(o!==0){let a=Math.cos(o),l=Math.sin(o);[s,c]=[s*a+c*l,-s*l+c*a]}if(r!==0){let a=Math.cos(r),l=Math.sin(r);[s,i]=[s*a-i*l,s*l+i*a]}return[s,i,c]}function Rn(e,n){let[t,o,r]=e,s=-(n[2]??0)*Math.PI/180;if(s!==0){let a=Math.cos(s),l=Math.sin(s);[t,o]=[t*a-o*l,t*l+o*a]}let i=-(n[1]??0)*Math.PI/180;if(i!==0){let a=Math.cos(i),l=Math.sin(i);[o,r]=[o*a-r*l,o*l+r*a]}let c=-(n[0]??0)*Math.PI/180;if(c!==0){let a=Math.cos(c),l=Math.sin(c);[t,r]=[t*a+r*l,-t*l+r*a]}return[t,o,r]}var Jo=Math.PI/180,xt=180/Math.PI,au=[1,0,0,0];function cu(e,n){let[t,o,r,s]=e,[i,c,a,l]=n;return[t*i-o*c-r*a-s*l,t*c+o*i+r*l-s*a,t*a-o*l+r*i+s*c,t*l+o*a-r*c+s*i]}function lu(e,n){let t=n*.5,o=Math.sin(t);return[Math.cos(t),e[0]*o,e[1]*o,e[2]*o]}function uu(e){let n=e[0]*Jo,t=e[1]*Jo,o=e[2]*Jo,r=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(t*.5),c=Math.sin(t*.5),a=Math.cos(o*.5),l=Math.sin(o*.5);return[r*i*a-s*c*l,s*i*a+r*c*l,r*c*a-s*i*l,r*i*l+s*c*a]}function fu(e){let[n,t,o,r]=e,s=2*(t*r+n*o),i=2*(o*r-n*t),c=1-2*(t*t+o*o),a=2*(t*o-n*r),l=1-2*(o*o+r*r),u=Math.max(-1,Math.min(1,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,c)*xt,f*xt,Math.atan2(-a,l)*xt]:[Math.atan2(2*(o*r+n*t),1-2*(t*t+r*r))*xt,f*xt,0]}var Ge=50;function mu(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Ke={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},Ci=100,Ei=1e4,Hn=e=>Math.round(e*Ci)/Ci,du=e=>Math.round(e*Ei)/Ei;function pu(e={}){let n={target:e.target??[...Ke.target],rotX:e.rotX??Ke.rotX,rotY:e.rotY??Ke.rotY,zoom:e.zoom??Ke.zoom,distance:e.distance??Ke.distance};function t(r){r.target!==void 0&&(n.target=[Hn(r.target[0]),Hn(r.target[1]),Hn(r.target[2])]),r.rotX!==void 0&&(n.rotX=Hn(r.rotX)),r.rotY!==void 0&&(n.rotY=Hn(r.rotY)),r.zoom!==void 0&&(n.zoom=du(r.zoom)),r.distance!==void 0&&(n.distance=Hn(r.distance))}function o(r={}){let i=(r.cols??0)*50,c=(r.rows??0)*50,[a,l,u]=n.target,f=l*50,d=a*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:`${i}px`,height:`${c}px`}}return{state:n,update:t,getStyle:o}}var Ti=Math.PI/180;function vi(e){let{camera:n,tileSize:t,viewportCenterX:o,viewportCenterY:r,mouseX:s,mouseY:i}=e,c=n.rotX*Ti,a=n.rotY*Ti,l=n.zoom/t,u=n.target,f=s-o,d=i-r,m=f/l,p=d/l,h=Math.cos(c),g=Math.sin(c),y=m,b=p*h,x=-p*g,P=0,S=g,C=h,T=Math.cos(a),A=Math.sin(a),M=y*T+b*A,E=-y*A+b*T,v=x,I=P*T+S*A,_=-P*A+S*T,O=C,V=u[1]*t,w=u[0]*t,F=u[2]*t,D=M+V,H=E+w,K=v+F,Q=[H/t,D/t,K/t],ne=[_/t,I/t,O/t];return{origin:Q,direction:ne}}function gu(e){let{origin:n,direction:t}=vi(e),{sphereCenter:o,sphereRadius:r}=e,s=n[0]-o[0],i=n[1]-o[1],c=n[2]-o[2],a=t[0],l=t[1],u=t[2],f=a*a+l*l+u*u;if(f===0)return null;let d=2*(s*a+i*l+c*u),m=s*s+i*i+c*c-r*r,p=d*d-4*f*m;if(p>=0){let T=Math.sqrt(p),A=(-d-T)/(2*f),M=(-d+T)/(2*f),E=t[2]>=0?Math.max(A,M):Math.min(A,M);return[n[0]+E*t[0],n[1]+E*t[1],n[2]+E*t[2]]}let h=-(s*a+i*l+c*u)/f,g=n[0]+h*a,y=n[1]+h*l,b=n[2]+h*u,x=g-o[0],P=y-o[1],S=b-o[2],C=Math.hypot(x,P,S);return C===0?null:[o[0]+x/C*r,o[1]+P/C*r,o[2]+S/C*r]}var Sn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Qt=(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]],Pt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],er=e=>Math.hypot(e[0],e[1],e[2]),Zn=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function hu(e){return`${e[0]},${e[1]},${e[2]}`}function _i(e){if(e.length<3)return null;let n=Sn(e[1],e[0]),t=Sn(e[2],e[0]),o=Qt(n,t),r=er(o);if(r<1e-12)return null;let s=[o[0]/r,o[1]/r,o[2]/r],i=Pt(s,e[0]);return{normal:s,d:i}}function yu(e,n){return Pt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function bu(e,n){return Pt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function xu(e,n,t,o){let r=e.vertices.findIndex(A=>Zn(A,t)),s=e.vertices.findIndex(A=>Zn(A,o)),i=n.vertices.findIndex(A=>Zn(A,t)),c=n.vertices.findIndex(A=>Zn(A,o));if(r<0||s<0||i<0||c<0)return null;let a=e.vertices.length,l=n.vertices.length,u=(r+1)%a===s,f=(i+1)%l===c;if(u===f)return null;let d=u?s:r,m=u?r:s,p=f?c:i,h=f?i:c,g=!!(e.uvs&&n.uvs),y=[],b=g?[]:void 0,x=d;for(;y.push(e.vertices[x]),b&&b.push(e.uvs[x]),x!==m;)x=(x+1)%a;for(x=p;y.push(n.vertices[x]),b&&b.push(n.uvs[x]),x!==h;)x=(x+1)%l;let P=[],S=b?[]:void 0;for(let A=0;A<y.length;A++)(P.length===0||!Zn(y[A],P[P.length-1]))&&(P.push(y[A]),S&&b&&S.push(b[A]));if(P.length>1&&Zn(P[0],P[P.length-1])&&(P.pop(),S?.pop()),g)return Ii(P,S);let C=[],T=S?[]:void 0;for(let A=0;A<P.length;A++){let M=P[(A-1+P.length)%P.length],E=P[A],v=P[(A+1)%P.length],I=Qt(Sn(E,M),Sn(v,M));er(I)>1e-9&&(C.push(E),T&&S&&T.push(S[A]))}return C.length<3?null:Ii(C,T)}function Pu(e,n){let t=e.length,o=0;for(let r=0;r<t;r++){let s=e[r],i=e[(r+1)%t],c=e[(r+2)%t],a=Sn(i,s),l=Sn(c,i),u=Pt(Qt(a,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 Mu(e,n){if(e.length<3)return!1;let t=_i(e);if(!t)return!1;for(let o of e)if(Math.abs(Pt(t.normal,o)-t.d)>n)return!1;return!0}function Au(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Su(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function Cu(e,n){return(e??"")===(n??"")}function Eu(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 Ii(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],s=e[(t+2)%e.length];if(!(er(Qt(Sn(r,o),Sn(s,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 ln(e){let n=[],t=[],o=new WeakMap,r=m=>{let p=o.get(m);if(p)return p;let h=hu(m);return o.set(m,h),h},s=(m,p)=>{let h=r(m),g=r(p);return h<g?`${h}|${g}`:`${g}|${h}`},i=(m,p)=>r(m)<r(p)?1:-1,c=m=>{let p=new Map;for(let h=0;h<m.length;h++){let g=m[h],y=m[(h+1)%m.length];p.set(s(g,y),i(g,y))}return p},a=0,l=!1,u=m=>(a+=m,a<=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,h=_i(p);if(!h){n.push(m);continue}let g=m.texture&&m.uvs&&m.uvs.length===p.length?m.uvs.map(b=>[b[0],b[1]]):void 0,y=m.texture&&g?m.textureTriangles?.length?Au(m.textureTriangles):Eu(p,g):void 0;t.push({vertices:p,uvs:g,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureTriangles:y,normal:h.normal,d:h.d,edgeDirections:c(p),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let g=0;g<t.length;g++){let y=t[g];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],S=y.vertices[(x+1)%b],C=s(P,S),T=m.get(C);T?T.second<0&&(T.second=g):(T={a:P,b:S,first:g,second:-1},m.set(C,T))}}let p=!1,h=(g,y,b)=>{let x=g.edgeDirections.get(s(y,b));return x?x===i(y,b)?1:-1:0};for(let g of m.values()){if(g.second<0)continue;let y=g.first,b=g.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||!Su(x.textureWrap,P.textureWrap)||!Cu(x.textureAlphaMode,P.textureAlphaMode)||x.doubleSided!==P.doubleSided)continue;let S=!!(x.texture||P.texture);if(S&&(!x.textureTriangles||!P.textureTriangles)||!!x.uvs!=!!P.uvs||(S?!bu(x,P):!yu(x,P)))continue;if(!u(x.vertices.length+P.vertices.length))return!1;let C=h(x,g.a,g.b);if(C===0)continue;let T=h(P,g.a,g.b);if(T===0||C===T)continue;let[A,M]=C===1?[g.a,g.b]:[g.b,g.a],E=xu(x,P,A,M);if(E){if(!u(E.vertices.length))return!1;E.vertices.length>96||Mu(E.vertices,.001)&&Pu(E.vertices,x.normal)&&(x.vertices=E.vertices,x.uvs=E.uvs,x.edgeDirections=c(E.vertices),x.textureTriangles=S?[...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(h=>[h[0],h[1],h[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.uvs&&(p.uvs=m.uvs.map(h=>[h[0],h[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 Tu=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],vu=(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]],nn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function Iu(e,n){let t=e.vertices;if(!t||t.length<3)return null;let o=0,r=0,s=0;for(let h=0;h<t.length;h++){let g=t[h],y=t[(h+1)%t.length];o+=(g[1]-y[1])*(g[2]+y[2]),r+=(g[2]-y[2])*(g[0]+y[0]),s+=(g[0]-y[0])*(g[1]+y[1])}let i=Math.hypot(o,r,s);if(i<1e-12)return null;let c=[o/i,r/i,s/i],a=0,l=0,u=0;for(let h of t)a+=h[0],l+=h[1],u+=h[2];let f=1/t.length,d=[a*f,l*f,u*f],m=nn(c,d),p=i*.5;return{index:n,polygon:e,normal:c,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function _u(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&nn(e.normal,n.normal)<0}function Ou(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*nn(n,e),o=n[1]-e[1]*nn(n,e),r=n[2]-e[2]*nn(n,e),s=Math.hypot(t,o,r);t/=s,o/=s,r/=s;let i=[t,o,r],c=vu(e,i);return{u:i,v:c}}function Vu(e){if(e.local2D)return;let n=Ou(e.normal),t=[],o=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.polygon.vertices){let a=nn(c,n.u),l=nn(c,n.v);t.push([a,l]),a<o&&(o=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}e.local2D=t,e.bbox2D={min:[o,r],max:[s,i]},e.basis=n}function Ru(e,n){let t=[],o=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.vertices){let a=nn(c,n.u),l=nn(c,n.v);t.push([a,l]),a<o&&(o=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}return{local2D:t,bbox2D:{min:[o,r],max:[s,i]}}}function Lu(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 Oi(e,n){let t=!1;for(let o=0,r=n.length-1;o<n.length;r=o++){let s=n[o],i=n[r];s[1]>e[1]!=i[1]>e[1]&&e[0]<(i[0]-s[0])*(e[1]-s[1])/(i[1]-s[1]+1e-30)+s[0]&&(t=!t)}return t}function Vi(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 wu(e,n){let t=Vi(e),o=Vi(n),r=1e-4,s=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];Oi(u,n)&&s++}let i=0;for(let l of n){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];Oi(u,e)&&i++}let c=s/e.length,a=i/n.length;return Math.max(c,a)}function Nu(e,n){let t=e.normal[0],o=e.normal[1],r=e.normal[2],s=Math.abs(t),i=Math.abs(o),c=Math.abs(r),a=t;i>s&&i>c?a=o:c>s&&c>i&&(a=r),a<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 Du(e,n,t,o){let r=nn(e.normal,n.normal);if(Math.abs(r)<1-t)return!1;let s=r>0?1:-1;return Math.abs(e.d-s*n.d)<o}function Ri(e,n){let t=Tu(n,e.centroid);return nn(e.normal,t)>0}function Jt(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,o=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,s=n?.preserveDoubleSidedBackfaces??!0,i=[];for(let p=0;p<e.length;p++){let h=Iu(e[p],p);h&&i.push(h)}if(i.length<2)return new Set;let c=0,a=0,l=0,u=0;for(let p of i)c+=p.centroid[0]*p.area,a+=p.centroid[1]*p.area,l+=p.centroid[2]*p.area,u+=p.area;let f=u>0?[c/u,a/u,l/u]:[0,0,0],d=new Map;for(let p of i){let h=Nu(p,o),g=d.get(h);g||(g=[],d.set(h,g)),g.push(p)}let m=new Set;for(let p of d.values())if(!(p.length<2))for(let h=0;h<p.length;h++){let g=p[h];if(!m.has(g.index))for(let y=h+1;y<p.length;y++){let b=p[y];if(m.has(b.index)||!Du(g,b,t,o)||s&&_u(g,b))continue;Vu(g);let x=Ru(b.polygon,g.basis);if(!Lu(g.bbox2D,x.bbox2D)||wu(g.local2D,x.local2D)<r)continue;let S=Ri(g,f),C=Ri(b,f),T;if(S&&!C?T=g:C&&!S?T=b:T=g.area<b.area?g:b,m.add(T.index),T===g)break}}return m}function Fu(e,n){if(!e||e.length<2)return e??[];let t=Jt(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 Bu=4,ku=8,Uu=.001,Gu=1e-9,zu=1e6,$u=1e6,Xu=8,Ln=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],or=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],St=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],wn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Di=(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]],Fi=e=>Math.hypot(e[0],e[1],e[2]);function Ct(e){let n=Fi(e);return n<=Gu?null:[e[0]/n,e[1]/n,e[2]/n]}function At(e,n){return Math.round(e*n)/n}function tn(e){return At(e,zu)}function nr(e){return At(e,$u)}function tr(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function mn(e){return`${tn(e[0])},${tn(e[1])}`}function Yu(e){let n=mn(e.a),t=mn(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function qn(e){return`${e[0]},${e[1]},${e[2]}`}function Bi(e,n){let t=qn(e),o=qn(n);return t<o?`${t}|${o}`:`${o}|${t}`}function rr(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Li(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",rr(e.data)].join("|")}function ki(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],o=[0,0,0];for(let s=1;s<n.length-1;s++)o=or(o,Di(Ln(n[s],t),Ln(n[s+1],t)));let r=Ct(o);return r?{normal:r,d:wn(r,t)}:null}function Wu(e,n,t){return wn(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function ju(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function Ku(e,n){let t=n[e[0]]?.data,o=rr(t);for(let r of e)if(rr(n[r].data)!==o)return;return t?{...t}:void 0}function Hu(e,n){return e.every(t=>n[t].doubleSided===!0)}function Zu(e,n){let t=e.map(a=>ju(a)?ki(a):null),o=t.map(Boolean),r=new Map;for(let a=0;a<e.length;a++){if(!t[a])continue;let l=e[a].vertices;for(let u=0;u<l.length;u++){let f=Bi(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:a,edge:u};d?d.push(m):r.set(f,[m])}}let s=e.map(()=>new Set);for(let a of r.values())if(!(a.length<2))for(let l=0;l<a.length;l++)for(let u=l+1;u<a.length;u++){let f=a[l].polygon,d=a[u].polygon,m=t[f],p=t[d];!m||!p||Li(e[f])===Li(e[d])&&Wu(m,p,n)&&(s[f].add(d),s[d].add(f))}let i=new Set,c=[];for(let a=0;a<e.length;a++){if(!o[a]||i.has(a))continue;let l=[],u=[a];for(i.add(a);u.length>0;){let f=u.shift();l.push(f);for(let d of s[f])i.has(d)||(i.add(d),u.push(d))}c.push(l)}return{groups:c}}function qu(e,n){let t=new Set(e),o=new Map;for(let s of e){let i=n[s].vertices;for(let c=0;c<i.length;c++){let a=Bi(i[c],i[(c+1)%i.length]),l=o.get(a),u={polygon:s,edge:c};l?l.push(u):o.set(a,[u])}}let r=[];for(let s of o.values()){let i=s.filter(c=>t.has(c.polygon));if(i.length===1){let c=i[0],a=n[c.polygon].vertices;r.push({a:a[c.edge],b:a[(c.edge+1)%a.length]})}else if(i.length!==2)return null}return r}function Qu(e){let n=new Map;for(let t of e)n.set(qn(t.a),(n.get(qn(t.a))??0)+1),n.set(qn(t.b),(n.get(qn(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function Ui(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 Ju(e){let n=Ui(e);return`${At(n[0],1e3)},${At(n[1],1e3)},${At(n[2],1e3)}`}function ef(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=Ln(n,St(e,wn(n,e)));return Ct(t)??[1,0,0]}function nf(e,n,t){let o=new Map;for(let s of e){let i=Ln(s.b,s.a),c=Ln(i,St(n,wn(i,n))),a=Ct(c);if(!a)continue;let l=Ui(a),u=Ju(l),f=Fi(c),d=o.get(u);d?d.weight+=f:o.set(u,{axis:l,weight:f})}let r=[...o.values()].sort((s,i)=>i.weight-s.weight).slice(0,t).map(s=>s.axis);return r.length===0&&r.push(ef(n)),r}function wi(e,n,t,o){let r=Ln(e,n);return[tn(wn(r,t)),tn(wn(r,o))]}function tf(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 Mt(e,n){let[t,o]=e.a,[r,s]=e.b,i=(n-t)/(r-t);return tn(o+(s-o)*i)}function sr(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],s=n[o],i=n[(o+1)%n.length],c=(s[0]-r[0])*(i[1]-s[1])-(s[1]-r[1])*(i[0]-s[0]);Math.abs(c)>1e-8&&t.push(s)}return t}function no(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 to(e){let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let[s,i]of e)n=Math.min(n,s),t=Math.min(t,i),o=Math.max(o,s),r=Math.max(r,i);return{minX:n,minY:t,maxX:o,maxY:r}}function Gi(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 eo(e){return Math.abs(no(e))}function of(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-8)continue;let c=i>0?1:-1;if(n===0)n=c;else if(n!==c)return!1}return!0}function rf(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],c=o*i-r*s,a=Math.hypot(o,r);if(a<=1e-9||Math.abs(c)>Math.max(1e-8,a*1e-8))return!1;let l=s*o+i*r;return l>=-1e-8&&l<=o*o+r*r+1e-8}function sf(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],s=o*o+r*r;return s<=1e-12?0:((e[0]-n[0])*o+(e[1]-n[1])*r)/s}function af(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],c=o[1]-t[1],a=Math.hypot(r,s),l=Math.hypot(i,c);if(a<=1e-9||l<=1e-9)return!1;let u=r*(t[1]-e[1])-s*(t[0]-e[0]),f=r*(o[1]-e[1])-s*(o[0]-e[0]),d=r*c-s*i,m=Math.max(1e-8,Math.max(a,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(s),h=Math.min(p?e[0]:e[1],p?n[0]:n[1]),g=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(g,b)-Math.max(h,y)>1e-8}function cf(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];for(let s=0;s<n.length;s++)if(af(o,r,n[s],n[(s+1)%n.length]))return!0}return!1}function Ni(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],s=e[(o+1)%e.length],i=[{t:0,point:r},{t:1,point:s}];for(let a of n)tr(a,r)||tr(a,s)||rf(a,r,s)&&i.push({t:sf(a,r,s),point:a});i.sort((a,l)=>a.t-l.t);let c=[];for(let a of i)c.some(l=>Math.abs(l.t-a.t)<=1e-8||tr(l.point,a.point))||c.push(a);for(let a=0;a<c.length-1;a++){let l=c[a].point,u=c[a+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||t.push({a:[tn(l[0]),tn(l[1])],b:[tn(u[0]),tn(u[1])]})}}return t}function lf(e,n,t=to(e),o=to(n)){if(!Gi(t,o)||!cf(e,n))return null;let r=[...Ni(e,n),...Ni(n,e)],s=new Map;for(let y of r){let b=Yu(y),x=s.get(b);x?x.push(y):s.set(b,[y])}let i=!1,c=[];for(let y of s.values()){if(y.length===1){c.push(y[0]);continue}i=!0;let b=y.filter(P=>mn(P.a)<mn(P.b)).length,x=y.length-b;if(b!==x)return null}if(!i||c.length<3)return null;let a=new Map;for(let y of c){let b=mn(y.a);if(a.has(b))return null;a.set(b,y)}let l=c[0],u=mn(l.a),f=[],d=new Set,m=u;for(let y=0;y<=c.length;y++){let b=a.get(m);if(!b)return null;let x=`${mn(b.a)}>${mn(b.b)}`;if(d.has(x))return null;if(d.add(x),f.push(b.a),m=mn(b.b),m===u)break}if(m!==u||d.size!==c.length)return null;let p=sr(f);if(p.length<3||!of(p))return null;let h=eo(p),g=eo(e)+eo(n);return Math.abs(h-g)>Math.max(1e-5,g*1e-5)?null:no(p)>=0?p:[...p].reverse()}function uf(e){let n=e.map(sr).filter(r=>r.length>=3&&eo(r)>1e-8),t=n.map(to),o=!0;for(;o;){o=!1;for(let r=0;r<n.length;r++){for(let s=r+1;s<n.length;s++){if(!Gi(t[r],t[s]))continue;let i=lf(n[r],n[s],t[r],t[s]);if(i){n[r]=i,t[r]=to(i),n.splice(s,1),t.splice(s,1),o=!0;break}}if(o)break}}return n}function ff(e,n,t){let o=new Map;return r=>{let s=tn(r[0]),i=tn(r[1]),c=`${s},${i}`,a=o.get(c);if(a)return[a[0],a[1],a[2]];let l=or(e,or(St(n,s),St(t,i))),u=[nr(l[0]),nr(l[1]),nr(l[2])];return o.set(c,u),[u[0],u[1],u[2]]}}function mf(e,n,t,o,r){let s=t[0]?.a;if(!s)return null;let i=Ct(Ln(r,St(o,wn(r,o))));if(!i)return null;let c=Ct(Di(o,i));if(!c)return null;let a=[],l=[];for(let y of t){let b=wi(y.a,s,i,c),x=wi(y.b,s,i,c);Math.hypot(b[0]-x[0],b[1]-x[1])<=1e-7||(a.push({a:b,b:x}),l.push(b[0],x[0]))}let u=tf(l);if(a.length<3||u.length<2)return null;let f=n[e[0]].color,d=Ku(e,n),m=Hu(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,S=a.filter(C=>{let T=Math.min(C.a[0],C.b[0]),A=Math.max(C.a[0],C.b[0]);return T<P&&P<A&&Math.abs(C.a[0]-C.b[0])>1e-7}).map(C=>({segment:C,yMid:Mt(C,P)})).sort((C,T)=>C.yMid-T.yMid);if(S.length!==0){if(S.length%2!==0)return null;for(let C=0;C<S.length;C+=2){let T=S[C].segment,A=S[C+1].segment,M=Mt(T,b),E=Mt(T,x),v=Mt(A,b),I=Mt(A,x),_=sr([[b,M],[x,E],[x,I],[b,v]]);if(_.length<3||Math.abs(no(_))<=1e-8)continue;let O=no(_)>0?_:[..._].reverse();p.push(O)}}}if(p.length===0||e.length>2&&p.length>e.length*Xu)return null;let h=ff(s,i,c),g=uf(p).map(y=>({vertices:y.map(h),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return ln(g)}function df(e,n,t){let o=qu(e,n);if(!o||o.length<3||!Qu(o))return null;let r=ki(n[e[0]]);if(!r)return null;let s=null;for(let i of nf(o,r.normal,t)){let c=mf(e,n,o,r.normal,i);c&&(!s||c.length<s.length)&&(s=c)}return!s||s.length>=e.length?null:s}function ir(e,n={}){let t=n.minGroupPolygons??Bu,o=n.maxCandidateAxes??ku,r=n.planeEpsilon??Uu,s=e??[];if(s.length<t)return s;let{groups:i}=Zu(s,r);if(i.length===0)return s;let c=new Map,a=new Set;for(let u of i){if(u.length<t)continue;let f=df(u,s,o);if(f){c.set(u[0],f);for(let d of u)a.add(d)}}if(c.size===0)return s;let l=[];for(let u=0;u<s.length;u++){let f=c.get(u);if(f){l.push(...f);continue}a.has(u)||l.push(s[u])}return l}function pf(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 gf(e){if(e.length<100)return!1;let n=new Map;for(let o of e){let r=o.vertices;for(let s=0;s<r.length;s++){let i=pf(r[s],r[(s+1)%r.length]);n.set(i,(n.get(i)??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 hf(e,n,t){let o=Math.abs(e)>.9?0:1,r=Math.abs(e)>.9?1:0,s=r*t,i=-o*t,c=o*n-r*e,a=Math.hypot(s,i,c);return s/=a,i/=a,c/=a,{ux:s,uy:i,uz:c,vx:n*c-t*i,vy:t*s-e*c,vz:e*i-n*s}}function yf(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[H,K,Q]of n)t+=H,o+=K,r+=Q;let s=1/n.length;t*=s,o*=s,r*=s;let i=n[0],c=n[1],a=n[2],l=c[0]-i[0],u=c[1]-i[1],f=c[2]-i[2],d=a[0]-i[0],m=a[1]-i[1],p=a[2]-i[2],h=u*p-f*m,g=f*d-l*p,y=l*m-u*d,b=Math.hypot(h,g,y);if(b<1e-9)return null;h/=b,g/=b,y/=b;let{ux:x,uy:P,uz:S,vx:C,vy:T,vz:A}=hf(h,g,y),M=n.length-2,E=new Float64Array(M*9),v=0;for(let H=1;H<n.length-1;H++){let K=n[0],Q=n[H],ne=n[H+1];E[v++]=K[0],E[v++]=K[1],E[v++]=K[2],E[v++]=Q[0],E[v++]=Q[1],E[v++]=Q[2],E[v++]=ne[0],E[v++]=ne[1],E[v++]=ne[2]}let I=0,_=1/0,O=1/0,V=1/0,w=-1/0,F=-1/0,D=-1/0;for(let[H,K,Q]of n){let ne=H-t,ee=K-o,ue=Q-r,U=ne*ne+ee*ee+ue*ue;U>I&&(I=U),H<_&&(_=H),H>w&&(w=H),K<O&&(O=K),K>F&&(F=K),Q<V&&(V=Q),Q>D&&(D=Q)}return{centroid:[t,o,r],normal:[h,g,y],vertices:n,triFlat:E,bcx:t,bcy:o,bcz:r,br2:I,ux:x,uy:P,uz:S,vx:C,vy:T,vz:A,minX:_,minY:O,minZ:V,maxX:w,maxY:F,maxZ:D}}function bf(e,n,t,o,r,s,i,c){let a=i[c],l=i[c+1],u=i[c+2],f=i[c+3]-a,d=i[c+4]-l,m=i[c+5]-u,p=i[c+6]-a,h=i[c+7]-l,g=i[c+8]-u,y=r*g-s*h,b=s*p-o*g,x=o*h-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let S=1/P,C=e-a,T=n-l,A=t-u,M=S*(C*y+T*b+A*x);if(M<0||M>1)return!1;let E=T*m-A*d,v=A*f-C*m,I=C*d-T*f,_=S*(o*E+r*v+s*I);return _<0||M+_>1?!1:S*(p*E+h*v+g*I)>.001}function xf(e,n,t,o,r,s,i){let c=i.bcx-e,a=i.bcy-n,l=i.bcz-t,u=c*o+a*r+l*s,f=c-u*o,d=a-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,h=p.length;for(let g=0;g<h;g+=9)if(bf(e,n,t,o,r,s,p,g))return!0;return!1}var Et=9,Pf=6,ke=8;function ar(e,n,t,o,r,s){let i=o-e,c=r-n,a=s-t;return i*c+c*a+a*i}function Mf(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),s=new Float64Array(t),i=new Float64Array(t);for(let C=0;C<t;C++){let T=e[o[C]];r[C]=(T.minX+T.maxX)*.5,s[C]=(T.minY+T.maxY)*.5,i[C]=(T.minZ+T.maxZ)*.5}let c=2*Math.max(1,t)+1,a=new Float64Array(c*Et),l=0,u=new Float64Array(ke),f=new Float64Array(ke),d=new Float64Array(ke),m=new Float64Array(ke),p=new Float64Array(ke),h=new Float64Array(ke),g=new Int32Array(ke),y=new Float64Array(ke-1),b=new Int32Array(ke-1),x=new Float64Array(ke-1),P=new Int32Array(ke-1);function S(C,T){let A=l++,M=A*Et,E=T-C,v=1/0,I=1/0,_=1/0,O=-1/0,V=-1/0,w=-1/0;for(let G=C;G<T;G++){let te=e[o[G]];te.minX<v&&(v=te.minX),te.maxX>O&&(O=te.maxX),te.minY<I&&(I=te.minY),te.maxY>V&&(V=te.maxY),te.minZ<_&&(_=te.minZ),te.maxZ>w&&(w=te.maxZ)}if(a[M]=v,a[M+1]=I,a[M+2]=_,a[M+3]=O,a[M+4]=V,a[M+5]=w,E<=Pf)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let F=1/0,D=1/0,H=1/0,K=-1/0,Q=-1/0,ne=-1/0;for(let G=C;G<T;G++)r[G]<F&&(F=r[G]),r[G]>K&&(K=r[G]),s[G]<D&&(D=s[G]),s[G]>Q&&(Q=s[G]),i[G]<H&&(H=i[G]),i[G]>ne&&(ne=i[G]);let ee=K-F,ue=Q-D,U=ne-H;if(ee===0&&ue===0&&U===0)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let $=ar(v,I,_,O,V,w),k=$>0?1/$:0,L=E+1,W=0,Y=0;for(let G=0;G<3;G++){let te=G===0?F:G===1?D:H,ce=G===0?ee:G===1?ue:U;if(ce===0)continue;let ye=G===0?r:G===1?s:i,he=ke/ce;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),h.fill(-1/0),g.fill(0);for(let N=C;N<T;N++){let X=(ye[N]-te)*he|0;X>=ke&&(X=ke-1);let oe=e[o[N]];oe.minX<u[X]&&(u[X]=oe.minX),oe.maxX>m[X]&&(m[X]=oe.maxX),oe.minY<f[X]&&(f[X]=oe.minY),oe.maxY>p[X]&&(p[X]=oe.maxY),oe.minZ<d[X]&&(d[X]=oe.minZ),oe.maxZ>h[X]&&(h[X]=oe.maxZ),g[X]++}let be=1/0,ge=1/0,Se=1/0,De=-1/0,R=-1/0,z=-1/0,j=0;for(let N=0;N<ke-1;N++)u[N]<be&&(be=u[N]),m[N]>De&&(De=m[N]),f[N]<ge&&(ge=f[N]),p[N]>R&&(R=p[N]),d[N]<Se&&(Se=d[N]),h[N]>z&&(z=h[N]),j+=g[N],y[N]=ar(be,ge,Se,De,R,z),b[N]=j;let J=1/0,le=1/0,re=1/0,pe=-1/0,xe=-1/0,ie=-1/0,ae=0;for(let N=ke-2;N>=0;N--){let X=N+1;u[X]<J&&(J=u[X]),m[X]>pe&&(pe=m[X]),f[X]<le&&(le=f[X]),p[X]>xe&&(xe=p[X]),d[X]<re&&(re=d[X]),h[X]>ie&&(ie=h[X]),ae+=g[X],x[N]=ar(J,le,re,pe,xe,ie),P[N]=ae}for(let N=0;N<ke-1;N++){if(b[N]===0||P[N]===0)continue;let X=.125+(y[N]*b[N]+x[N]*P[N])*k;X<L&&(L=X,W=G,Y=te+(N+1)/he)}}let se=W===0?r:W===1?s:i,Z=C,B=T-1;for(;Z<=B;)if(se[Z]<Y)Z++;else{let G=o[Z];o[Z]=o[B],o[B]=G;let te=r[Z];r[Z]=r[B],r[B]=te;let ce=s[Z];s[Z]=s[B],s[B]=ce;let ye=i[Z];i[Z]=i[B],i[B]=ye,B--}let q=Z;(q===C||q===T)&&(q=C+T>>1),a[M+6]=0;let me=S(C,q),fe=S(q,T);return a[A*Et+7]=me,a[A*Et+8]=fe,A}return t>0&&S(0,t),{data:a,nodeCount:l,polyIndices:o,meta:e}}function cr(e,n,t,o,r,s,i,c,a){if(c.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=c,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,h=0;for(a[h++]=0;h>0;){let y=a[--h]*Et,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,S=b<x?x:b,C=(l[y+1]-n)*m,T=(l[y+4]-n)*m,A=C<T?C:T,M=C<T?T:C;if(P>M||A>S)continue;A>P&&(P=A),M<S&&(S=M);let E=(l[y+2]-t)*p,v=(l[y+5]-t)*p,I=E<v?E:v,_=E<v?v:E;if(!(P>_||I>S)&&(_<S&&(S=_),!(S<.001)))if(l[y+6]===1){let O=l[y+7]|0,V=l[y+8]|0;for(let w=O;w<V;w++){let F=u[w];if(F===i)continue;let D=f[F];if(D&&xf(e,n,t,o,r,s,D))return!0}}else a[h++]=l[y+7]|0,a[h++]=l[y+8]|0}return!1}function Af(e){let n=zi.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 s=(r+.5)/e,i=Math.sqrt(Math.max(0,1-s*s)),c=2*Math.PI*(r/t);o[r*3]=i*Math.cos(c),o[r*3+1]=i*Math.sin(c),o[r*3+2]=s}return zi.set(e,o),o}var zi=new Map;function dn(e,n){let t=n?.samples??8;if(e.length<4||t<1||!n?.force&&gf(e))return e;let o=Math.max(1,Math.ceil(t*(n?.minEscapeRatio??1/t))),r=e.map(yf),s=Af(t),i=[],c=Mf(r),a=new Int32Array(Math.max(64,c.nodeCount)),l=192,u=new Float64Array(l);for(let f=0;f<e.length;f++){let d=r[f];if(!d){i.push(e[f]);continue}let m=d.normal[0],p=d.normal[1],h=d.normal[2],g=.001*m,y=.001*p,b=.001*h;{let V=d.centroid[0]+g,w=d.centroid[1]+y,F=d.centroid[2]+b;if(!cr(V,w,F,m,p,h,f,c,a)){i.push(e[f]);continue}}let{ux:x,uy:P,uz:S,vx:C,vy:T,vz:A}=d,M=d.centroid[0],E=d.centroid[1],v=d.centroid[2],I=d.vertices,_=I.length,O=0;u[O++]=M+g,u[O++]=E+y,u[O++]=v+b;for(let V=0;V<_;V++){let w=I[V];u[O++]=w[0]+(M-w[0])*.08+g,u[O++]=w[1]+(E-w[1])*.08+y,u[O++]=w[2]+(v-w[2])*.08+b}for(let V=0;V<_;V++){let w=I[V],F=I[(V+1)%_],D=(w[0]+F[0])*.5,H=(w[1]+F[1])*.5,K=(w[2]+F[2])*.5;u[O++]=D+(M-D)*.08+g,u[O++]=H+(E-H)*.08+y,u[O++]=K+(v-K)*.08+b}if(o<=1){let V=!1;e:for(let w=0;w<s.length;w+=3){let F=s[w],D=s[w+1],H=s[w+2],K=F*x+D*C+H*m,Q=F*P+D*T+H*p,ne=F*S+D*A+H*h;for(let ee=0;ee<O;ee+=3){let ue=u[ee],U=u[ee+1],$=u[ee+2];if(!cr(ue,U,$,K,Q,ne,f,c,a)){V=!0;break e}}}V&&i.push(e[f])}else{let V=0;for(let w=0;w<s.length;w+=3){let F=s[w],D=s[w+1],H=s[w+2],K=F*x+D*C+H*m,Q=F*P+D*T+H*p,ne=F*S+D*A+H*h;for(let ee=0;ee<O;ee+=3){let ue=u[ee],U=u[ee+1],$=u[ee+2];if(!cr(ue,U,$,K,Q,ne,f,c,a)){V++;break}}}V>=o&&i.push(e[f])}}return i}var Hi={overlapPx:1.25,maxGapPx:14,capacityScale:1},Zi={budget:40};function Nn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function Qn(e){return typeof e=="number"?{overlapPx:Math.max(0,e)*.175,maxGapPx:14,capacityScale:1}:{overlapPx:Math.max(0,Nn(e?.overlapPx,1.25)),maxGapPx:Math.max(0,Nn(e?.maxGapPx,14)),capacityScale:Math.max(0,Nn(e?.capacityScale,1))}}function Jn(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function qi(e){return{rotX:Nn(e?.rotX,65),rotY:Nn(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(Nn(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(Nn(e?.budget,40))))}}function pn(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function Qi(e){return[e[1]/50,e[0]/50,e[2]/50]}function co(e){return`${e[0]},${e[1]},${e[2]}`}function Sf(e,n){let t=co(e),o=co(n);return t<o?`${t}|${o}`:`${o}|${t}`}function gn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function et(e){return Math.hypot(e[0],e[1],e[2])}function _t(e){let n=et(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function It(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function oo(e,n,t,o){let r=n*Math.PI/180,s=t*Math.PI/180,i=o*Math.PI/180,[c,a,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[c,a]=[c*u-a*f,c*f+a*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[c,l]=[c*u+l*f,-c*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[a,l]=[a*u-l*f,a*f+l*u]}return[c,a,l]}function dr(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 Cf(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=gn(e[o],n),s=gn(e[o+1],n),i=dr(r,s);t[0]-=i[0],t[1]-=i[1],t[2]-=i[2]}return _t(t)}function pr(e){let n=e[0],t=Cf(e);if(!t)return null;let o=null;for(let u=0;u<e.length;u+=1){let f=gn(e[(u+1)%e.length],e[u]);if(et(f)>1e-6){o=f;break}}if(!o)return null;let r=It(o,t),s=[o[0]-r*t[0],o[1]-r*t[1],o[2]-r*t[2]],i=_t(s);if(!i)return null;let c=_t(dr(t,i));if(!c)return null;let a=e.map(u=>{let f=gn(u,n);return[It(f,i),It(f,c)]}),l=lo(a);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:i,yAxis:c,local:a,area:l}:null}function lo(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 gr(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-6)continue;let c=Math.sign(i);if(n===0)n=c;else if(c!==n)return!1}return!0}function Ji(e,n,t){let o=e[t],r=e[(t+1)%e.length],s=r[0]-o[0],i=r[1]-o[1],c=Math.hypot(s,i);if(c<=1e-6)return null;let a=n>0?1:-1;return[a*(i/c),a*(-s/c)]}function Ef(e,n){let t=Ji(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 ea(e,n){let t=e.length,o=e[n],r=e[(n+1)%t],s=r[0]-o[0],i=r[1]-o[1],c=Math.hypot(s,i);if(c<=1e-6)return 0;let a=[c*.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])*i-(d[1]-o[1])*s)/c;m>1e-6&&(l=Math.min(l,m))}Number.isFinite(l)&&a.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 h=Math.abs(s*m-i*d)/(c*p);h>1e-6&&a.push(p*h*.32)}return Math.min(...a)}function na(e){return e.map(n=>{let t=pn(n.vertices),o=pr(t),r=!hr(n)&&!!o&&gr(o.local),s=r?o.local.map((i,c)=>ea(o.local,c)):[];return{basis:o,cssPoints:t,capacities:s,patchable:r}})}function hr(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Tf(e){return e.material?.key??e.color??""}function ta(e,n,t){let o=[];for(let r=0;r<n.length;r+=1){let s=n[r];if(!(!s.patchable||!s.basis))for(let i=0;i<s.cssPoints.length;i+=1){let c=s.cssPoints[i],a=s.cssPoints[(i+1)%s.cssPoints.length],l=gn(a,c),u=et(l),f=_t(l),d=Ef(s.basis,i),m=(s.capacities[i]??0)*t;!f||!d||m<=1e-6||u<=1e-6||o.push({index:o.length,polygon:r,edge:i,key:Sf(c,a),a:c,b:a,minX:Math.min(c[0],a[0]),minY:Math.min(c[1],a[1]),minZ:Math.min(c[2],a[2]),maxX:Math.max(c[0],a[0]),maxY:Math.max(c[1],a[1]),maxZ:Math.max(c[2],a[2]),length:u,dir:f,normal:s.basis.normal,outward:d,capacity:m,materialKey:Tf(e[r]),color:e[r].color})}}return o}function yr(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function ro(e,n){return et(gn(e,n))<=1e-4}function vf(e,n){return ro(e.a,n.a)||ro(e.a,n.b)||ro(e.b,n.a)||ro(e.b,n.b)}function If(e,n){return yr(e,n)?vf(e,n)?"connected-facet":"true-gap":"material-boundary"}function lr(e,n,t,o,r,s){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:s,residualGapPx:Math.max(0,o.gap-s),residualTargetPx:Math.max(0,r-s)}}function $i(e,n,t,o,r){let s=Math.max(0,Math.min(n.length,Math.min(t,o))),i=Math.max(0,Math.min(n.length,Math.max(t,o)));if(r<=1e-6||i-s<=1e-6)return;let c=e[n.polygon].get(n.edge),a={start:s,end:i,amount:r};c?c.push(a):e[n.polygon].set(n.edge,[a])}function uo(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function _f(e,n){let t=0,o=0,r=0;for(let s of e){s.size>0&&(r+=1),o+=s.size;for(let i of s.values())for(let c of i)t=Math.max(t,c.amount)}return{...n,patchedPolygons:r,patchedEdges:o,maxAppliedAmountPx:t}}function fo(e,n,t=!1,o=!1){let r=na(e),s=ta(e,r,n.capacityScale),i=o?[]:e.map(()=>new Map),c=uo(),a=t?[]:void 0;if(s.length===0)return{edgeRepairs:i,diagnostics:c,candidates:a};let l=new Map;for(let u of s){let f=l.get(u.key);f?f.push(u):l.set(u.key,[u])}for(let u of l.values())u.length<2||(c.exactPairs+=u.length===2?1:u.length);return Of(s,l,i,c,n,a),{edgeRepairs:i,diagnostics:o?c:_f(i,c),candidates:a}}function Of(e,n,t,o,r,s){let i=r.maxGapPx,c=new Set;for(let[m,p]of n)p.length>1&&c.add(m);let a=(m,p)=>{let h=m.index<p.index?m:p,g=m.index<p.index?p:m;if(g.polygon===h.polygon||h.key===g.key&&c.has(h.key)||!s&&!yr(h,g)||!Vf(h,g,i)||Math.abs(It(h.dir,g.dir))<.985)return;let y=Nf(h,g,i);if(!y)return;let b=If(h,g),x=y.gap+r.overlapPx;if(b==="material-boundary"){s?.push(lr(b,h,g,y,x,0));return}let P=x;if(P<=.25){s?.push(lr(b,h,g,y,x,0));return}let S=h.capacity*y.facingA,C=g.capacity*y.facingB,T=Math.min(S,P/2),A=Math.min(C,P/2);if(P-=T+A,P>1e-6){let M=Math.min(S-T,P);T+=M,P-=M}if(P>1e-6){let M=Math.min(C-A,P);A+=M,P-=M}s?.push(lr(b,h,g,y,x,T+A)),t.length>0&&T>1e-6&&$i(t,h,y.aStart,y.aEnd,T/y.facingA),t.length>0&&A>1e-6&&$i(t,g,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,i*2);if(e.length<=1e4){let m=[...e].sort((g,y)=>g.minX-y.minX),p=new Int32Array(m.length),h=0;for(let g=0;g+1<m.length;g+=1){let b=m[g].maxX+i,x=g+1;for(;x<m.length&&m[x].minX<=b;)x+=1;if(p[g]=x,h+=x-g-1,h>25e6)break}if(h<=2e6||h<=25e6&&wf(e,l,i)){for(let g=0;g+1<m.length;g+=1)for(let y=g+1;y<p[g];y+=1)a(m[g],m[y]);return}}let u=new Map;for(let m of e)Rf(u,m,l,i);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 h=p+1;h<m.length;h+=1){let g=m[p],y=m[h],b=g.index<y.index?g:y,x=g.index<y.index?y:g,P=b.index*d+x.index;f.has(P)||(f.add(P),a(b,x))}}function Vf(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 Xi(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function Rf(e,n,t,o){let[r,s,i,c,a,l]=oa(n,t,o);for(let u=r;u<=c;u+=1)for(let f=s;f<=a;f+=1)for(let d=i;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function oa(e,n,t){let[o,r,s]=Xi([e.minX-t,e.minY-t,e.minZ-t],n),[i,c,a]=Xi([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[o,r,s,i,c,a]}function Lf(e,n,t){let[o,r,s,i,c,a]=oa(e,n,t);return(i-o+1)*(c-r+1)*(a-s+1)}function wf(e,n,t){let o=0,r=0;for(let s of e){let i=Lf(s,n,t);if(o+=i,i>r&&(r=i),r>8192)return!0}return o/Math.max(1,e.length)>256}function Yi(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function Wi(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 Nf(e,n,t){let o=Yi(n.a,e.a,e.dir),r=Yi(n.b,e.a,e.dir),s=Math.max(0,Math.min(o,r)),i=Math.min(e.length,Math.max(o,r)),c=i-s,a=Math.min(e.length,n.length);if(c<Math.max(.75,a*.12))return null;let l=(s+i)/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,h=n.a[1]+n.dir[1]*m-f,g=n.a[2]+n.dir[2]*m-d,y=Math.hypot(p,h,g);if(y<=1e-6||y>t||y>Math.min(t,Math.max(4,a*.28)))return null;let b=1/y,x=p*b,P=h*b,S=g*b,C=e.outward[0]*x+e.outward[1]*P+e.outward[2]*S,T=-(n.outward[0]*x+n.outward[1]*P+n.outward[2]*S);if(C<.5||T<.5)return null;let A=Math.max(0,Math.min(n.length,Wi(e,s,n))),M=Math.max(0,Math.min(n.length,Wi(e,i,n)));return{gap:y,facingA:C,facingB:T,aStart:s,aEnd:i,bStart:Math.min(A,M),bEnd:Math.max(A,M)}}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 Tt(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 Df(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let o=new Set([0,n]);for(let i of e){let c=Math.max(0,Math.min(n,i.start)),a=Math.max(0,Math.min(n,i.end));a-c<=1e-6||i.amount<=1e-6||(o.add(c),o.add(a))}let r=Array.from(o).sort((i,c)=>i-c),s=[];for(let i=0;i+1<r.length;i+=1){let c=r[i],a=r[i+1];if(a-c<=1e-6)continue;let l=(c+a)/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&&s.push({start:c,end:a,amount:f})}return s}function Ff(e,n){if(n.length<3||!gr(n))return!1;let t=lo(e),o=lo(n);return Math.sign(o)===Math.sign(t)&&Math.abs(o)>=Math.abs(t)-1e-6}function Bf(e,n,t){if(n.size===0||e.vertices.length<3||hr(e))return e;let o=pn(e.vertices),r=pr(o);if(!r||!gr(r.local))return e;let s=[];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=Ji(r.local,r.area,l);if(!m||d<=1e-6)return e;let p=Df(n.get(l),d,ea(r.local,l)*t);Tt(s,u);let h=0;for(let g of p){g.start>h+1e-6&&Tt(s,ur(u,f,d,g.start));let y=ur(u,f,d,g.start),b=ur(u,f,d,g.end);Tt(s,[y[0]+m[0]*g.amount,y[1]+m[1]*g.amount]),Tt(s,[b[0]+m[0]*g.amount,b[1]+m[1]*g.amount]),g.end<d-1e-6&&Tt(s,b),h=g.end}}let i=s[0],c=s[s.length-1];if(i&&c&&Math.hypot(i[0]-c[0],i[1]-c[1])<=1e-6&&s.pop(),!Ff(r.local,s))return e;let a=s.map(([l,u])=>Qi([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:a}}function ra(e){return e.vertices.length===4&&!hr(e)}function kf(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,o=1/0,r=-1/0,s=-1/0;for(let[a,l]of n)t=Math.min(t,a),o=Math.min(o,l),r=Math.max(r,a),s=Math.max(s,l);let i=Math.max(1e-6,(r-t)*(s-o));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/i)))*2.5}function fr(e,n){return et(gn(pn([e])[0],pn([n])[0]))}function so(e,n,t){let o=fr(e,n),r=fr(n,t),s=fr(t,e),i=Math.max(o,r,s);return i<=1e-6?0:et(dr(gn(pn([n])[0],pn([e])[0]),gn(pn([t])[0],pn([e])[0])))*.5/(i*i)}function Uf(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],c=o[1]-t[1],a=r*c-s*i;if(Math.abs(a)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*c-u*i)/a;return[e[0]+f*r,e[1]+f*s]}function Gf(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=lo(e);if(Math.abs(o)<=1e-6)return null;let r=o>0?1:-1,s=[];for(let a=0;a<e.length;a+=1){let l=e[a],u=e[(a+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[a]),h=r*(d/m)*p,g=r*(-f/m)*p;s.push({a:[l[0]+h,l[1]+g],b:[u[0]+h,u[1]+g]})}let i=[],c=Math.max(2,t*4);for(let a=0;a<e.length;a+=1){let l=s[(a+e.length-1)%e.length],u=s[a],f=Uf(l.a,l.b,u.a,u.b);if(!f)return null;let d=e[a],m=f[0]-d[0],p=f[1]-d[1],h=Math.hypot(m,p);i.push(h>c?[d[0]+m/h*c,d[1]+p/h*c]:f)}return i}function zf(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=pr(pn(e));if(!t)return e;let o=Gf(t.local,n);return o?o.map(r=>Qi(zf(t,r))):e}function $f(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[o,r,s,i]=e.vertices,c=Math.min(so(o,r,s),so(o,s,i)),a=Math.min(so(o,r,i),so(r,s,i)),l=u=>n.has(u)?.75:0;return c>=a?[{...t,vertices:io([o,r,s],[l(0),l(1),1.25])},{...t,vertices:io([o,s,i],[1.25,l(2),l(3)])}]:[{...t,vertices:io([o,r,i],[l(0),1.25,l(3)])},{...t,vertices:io([r,s,i],[l(1),l(2),1.25])}]}function ji(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 ao(e,n){let t=e[n];if(t===n)return n;let o=ao(e,t);return e[n]=o,o}function Xf(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 Yf(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function Wf(e,n,t,o){let r=[];for(let[a,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!yr(u,f))continue;let d=l.filter(C=>ra(e[C.polygon]));if(d.length===0)continue;let m=d[0],p=1-Math.min(1,Math.abs(It(u.normal,f.normal))),h=Math.max(u.length,f.length);if(p<.01&&h<64)continue;let g=Math.max(...d.map(C=>kf(n[C.polygon]))),y=d.length===2?1.18:1,b=Math.max(.08,p),x=o.viewAware?jf(u,f,o.rotX,o.rotY):{proj:h,vr:1},P=o.viewAware?Math.max(x.proj,h*.12):h,S=o.viewAware?.18+x.vr*1.82:1;r.push({key:a,e:[co(m.a),co(m.b)],o:l,r:d,len:h,rank:P,proj:x.proj,s:P*(.58+b*2.8)*g*y*S,nr:p,sr:g,vr:x.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let s=Array.from({length:r.length},(a,l)=>l),i=new Map;for(let a=0;a<r.length;a+=1)for(let l of r[a].e){let u=i.get(l);if(u===void 0)i.set(l,a);else{let f=ao(s,u),d=ao(s,a);f!==d&&(s[d]=f)}}let c=new Map;for(let a=0;a<r.length;a+=1){let l=ao(s,a),u=c.get(l);u===void 0&&(u=c.size,c.set(l,u)),r[a].comp=u}return r}function jf(e,n,t,o){let r=oo(e.a,t,0,o),s=oo(e.b,t,0,o),i=Math.hypot(s[0]-r[0],s[1]-r[1]),c=oo(e.normal,t,0,o)[2],a=oo(n.normal,t,0,o)[2],l=Math.max(0,c,a),u=Math.min(1,Math.abs(c-a));return{proj:i,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function Kf(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 vt(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 Ki(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,s=e.rank*(.6+n*n*1.4)*t*o*r/Math.sqrt(Math.max(1,e.r.length));return Math.max(s,vt(e)*.75)}function mr(e){let n=new Set;for(let t of e)for(let o of t.r)n.add(o.polygon);return n.size}function sa(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function Hf(e,n,t){return e.s>=n||e.rank>=t}function Zf(e,n,t,o,r,s,i){let c=Math.max(0,Math.floor(t));if(c<=0||e.length===0||n==="follow-up")return{budgetLimit:c,componentBudgets:null};let a=new Map;for(let m of e){let p=a.get(m.comp);p?p.push(m):a.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 a){let h=p.filter(S=>Hf(S,s,i)||S.s>=f);if(h.length===0)continue;let g=p.filter(S=>sa(S,r)),y=mr(h),b=mr(g),x=Math.ceil(Math.sqrt(Math.max(0,b-y))*3),P=Math.min(mr(p),y+x);P<=0||(l.set(m,P),d+=P)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(c,d),componentBudgets:l}}function qf(e,n,t){let o=new Map;if(e.length===0||t<=0)return{selected:o,budgetLimit:0};let r=ji(e.map(M=>M.s)),s=ji(e.map(M=>M.rank)),i=Math.max(1e-6,r.q3-r.q1),c=Math.min(r.max,Math.max(r.p95,r.q3+i*.85)),a=Math.min(r.max,Math.max(r.p80,r.q3+i*.15)),l=Math.min(r.max,Math.max(r.p70,r.q3)),u=Math.max(s.p97,s.median*1.8),f=Math.max(s.p88,s.median*1.35),d=Zf(e,n,t,r,s,c,u),m=d.budgetLimit;if(m<=0)return{selected:o,budgetLimit:0};let p=Kf(e),h=new Set,g=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((M,E)=>vt(E)-vt(M)||E.s/Math.max(1,E.r.length)-M.s/Math.max(1,M.r.length)||E.len-M.len),S=[...e].sort((M,E)=>Ki(E)-Ki(M)||vt(E)-vt(M)||E.len-M.len),C=(M,E)=>{M.sel=!0,M.why=E,y.add(M.comp);for(let v of M.e)g.add(v);for(let v of M.r){h.add(v.polygon);let I=o.get(v.polygon);I?I.add(v.edge):o.set(v.polygon,new Set([v.edge]))}},T=(M,E)=>{let v=d.componentBudgets;if(E<=0||!v)return!0;let I=v.get(M.comp)??0;return(b.get(M.comp)??0)+E<=I},A=(M,E)=>{E<=0||!d.componentBudgets||b.set(M.comp,(b.get(M.comp)??0)+E)};for(let M of S){let E=M.r.reduce((I,_)=>I+(h.has(_.polygon)?0:1),0);if(M.cost=E,!(E>m||!T(M,E)||E>0&&m-E<x||!sa(M,s))&&(C(M,"global-outlier"),A(M,E),m-=E,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let M of P){if(M.sel)continue;let E=M.r.reduce((V,w)=>V+(h.has(w.polygon)?0:1),0);if(M.cost=E,E>m||!T(M,E)||E>0&&m-E<x)continue;let v=M.r.length===2,I=p.has(M)&&(n==="primary"||n==="follow-up"&&M.s>=a*1.08&&M.rank>=f)&&(v?M.s>=a||M.rank>=f:M.s>=a*1.18||M.rank>=f*1.12),_=v?M.s>=c||M.rank>=u:M.s>=c*1.35||M.rank>=u*1.2,O=E===0&&(v?M.s>=l||M.rank>=f:M.s>=l*1.25||M.rank>=f*1.12);if(!(!I&&!_&&!O)&&(C(M,I?"component-anchor":_?"global-outlier":"shared-polygon"),A(M,E),m-=E,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let M of P){if(M.sel)continue;let E=M.r.reduce((w,F)=>w+(h.has(F.polygon)?0:1),0);if(M.cost=E,E>1||E>m||!T(M,E))continue;let v=M.r.some(w=>h.has(w.polygon)),I=M.e.some(w=>g.has(w));if(n==="primary"&&M.r.length===1&&E===1&&(y.has(M.comp)||I||v)&&M.rank>=f*1.05&&M.nr>=.16&&M.vr<=.32){if(C(M,"local-follow-up"),A(M,E),m-=E,m<=0)return{selected:o,budgetLimit:d.budgetLimit};continue}if(M.r.length!==2)continue;let O=v&&E===1&&M.proj>=f*1.45&&M.vr<=.18;if(!I&&!O)continue;if((M.s>=l*.42||M.rank>=f*.62)&&M.s<=l*1.1&&M.proj>=24&&(C(M,"local-follow-up"),A(M,E),m-=E,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}return{selected:o,budgetLimit:d.budgetLimit}}function ia(e,n,t,o,r){let s=na(e),i=ta(e,s,n.capacityScale),c=new Map;for(let u of i){let f=c.get(u.key);f?f.push(u):c.set(u.key,[u])}let a=Wf(e,s,c,t).filter(u=>Yf(u,r)),l=qf(a,r?"follow-up":"primary",o);return{selected:l.selected,candidates:a,budgetLimit:l.budgetLimit}}function Qf(e,n){let t=[];for(let o=0;o<e.length;o+=1){let r=e[o],s=n.get(o);s&&ra(r)?t.push(...$f(r,s)):t.push(r)}return t}function Jf(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 aa(e,n,t){let o=Qn(n),r=qi(t);if(!Jn(o,n)||e.length===0)return e;let s=e,i,c=r.budget;for(let a=0;a<r.passes;a+=1){let l=ia(s,o,r,c,i);if(a===0&&(c=Math.min(c,l.budgetLimit)),l.selected.size===0)break;let u=Qf(s,l.selected);if(u.length===s.length)break;if(c-=l.selected.size,c<=0){s=u;break}i=Xf(l.candidates),s=u}return s}function em(e,n,t){let o=Qn(n),r=qi(t);if(!Jn(o,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let s=ia(e,o,r,r.budget),i=0;for(let c of s.selected.values())i+=c.size;return{candidates:s.candidates.map(Jf),selectedPolygons:s.selected.size,selectedEdges:i,addedPolygons:s.selected.size}}function ca(e,n){let t=Qn(n);if(!Jn(t,n)||e.length===0)return e;let{edgeRepairs:o}=fo(e,t);return o.some(r=>r.size>0)?e.map((r,s)=>Bf(r,o[s],t.capacityScale)):e}function nm(e,n=Hi,t=Zi){if(e.length===0)return e;let o=aa(e,n,t);return ca(o,n)}function tm(e,n){let t=Qn(n);return!Jn(t,n)||e.length===0?uo():fo(e,t).diagnostics}function la(e,n){let t=Qn(n);return!Jn(t,n)||e.length===0?uo():fo(e,t,!1,!0).diagnostics}function om(e,n){let t=Qn(n);if(!Jn(t,n)||e.length===0)return{diagnostics:uo(),candidates:[]};let o=fo(e,t,!0);return{diagnostics:o.diagnostics,candidates:o.candidates??[]}}var Dn={ratio:.7,maxError:.18,maxNormalDot:Math.cos(65*Math.PI/180),preserveVertices:!0,vertexKeyMode:"relaxed",lockBoundary:!0,minGroupTriangles:80,maxPasses:12};function rm(e={}){let n=Number.isFinite(e.ratio)?Math.max(.05,Math.min(.98,e.ratio)):Dn.ratio,t=Number.isFinite(e.maxError)&&e.maxError>0?e.maxError:Dn.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??Dn.preserveVertices,vertexKeyMode:e.vertexKeyMode??Dn.vertexKeyMode,lockBoundary:e.lockBoundary??Dn.lockBoundary,minGroupTriangles:Math.max(3,Math.floor(e.minGroupTriangles??Dn.minGroupTriangles)),maxPasses:Math.max(1,Math.floor(e.maxPasses??Dn.maxPasses))}}function sm(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function im(e){return e.vertices.length===3&&!sm(e)}function am(e){return[e.color??"",e.doubleSided===!0?"2":"1",e.material?.key??""].join("\0")}function ua(e){return`${Math.round(e[0]*1e5)},${Math.round(e[1]*1e5)},${Math.round(e[2]*1e5)}`}function cm(e,n,t,o){let r=o.vertexKeyMode==="source"?e.simplifySourceVertexKeys?.[t]??e.simplifyVertexKeys?.[t]:e.simplifyVertexKeys?.[t];return r?`${ua(n)}|${r}`:ua(n)}function lm(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function nt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function um(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function br(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function fa(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 Mr(e){return Math.hypot(e[0],e[1],e[2])}function xr(e,n){return Mr(nt(e,n))}function fm(e){let n=Mr(e);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n]:[0,0,1]}function Ar(e,n,t,o){return fm(fa(nt(e[t],e[n]),nt(e[o],e[n])))}function ma(e,n,t,o){return Mr(fa(nt(e[t],e[n]),nt(e[o],e[n])))/2}function mm(){return[0,0,0,0,0,0,0,0,0,0]}function mo(e,n){for(let t=0;t<e.length;t+=1)e[t]+=n[t]}function dm(e,n,t){let o=e[0],r=e[1],s=e[2],i=-br(e,n);return[o*o*t,o*r*t,o*s*t,o*i*t,r*r*t,r*s*t,r*i*t,s*s*t,s*i*t,i*i*t]}function Pr(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 pm(e,n,t,o,r,s,i,c,a,l,u,f){let d=e*(r*a-s*c)-n*(o*a-s*i)+t*(o*c-r*i);if(Math.abs(d)<1e-10)return null;let m=1/d,p=l*(r*a-s*c)-n*(u*a-s*f)+t*(u*c-r*f),h=e*(u*a-s*f)-l*(o*a-s*i)+t*(o*f-u*i),g=e*(r*f-u*c)-n*(o*f-u*i)+l*(o*c-r*i),y=[p*m,h*m,g*m];return y.every(Number.isFinite)?y:null}function gm(e,n,t,o){let r=pm(e[0],e[1],e[2],e[1],e[4],e[5],e[2],e[5],e[7],-e[3],-e[6],-e[8]),s=um(lm(n,t),.5),i=xr(n,t)*1.35,c=o?[n,t]:[n,t,s,...r&&xr(r,s)<=i?[r]:[]],a=c[0],l=Pr(e,a);for(let u=1;u<c.length;u+=1){let f=c[u],d=Pr(e,f);d<l&&(a=f,l=d)}return a}function hm(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function ym(e,n,t){return`${e}|${n}|${t}`}function bm(e,n){let t=new Map,o=[],r=[];for(let s of e){let i=[];for(let u=0;u<s.vertices.length;u+=1){let f=s.vertices[u],d=cm(s,f,u,n),m=t.get(d);m===void 0&&(m=o.length,t.set(d,m),o.push([...f])),i.push(m)}let[c,a,l]=i;c===void 0||a===void 0||l===void 0||c===a||c===l||a===l||r.push({a:c,b:a,c:l,polygon:s,normal:Ar(o,c,a,l)})}return{vertices:o,triangles:r}}function xm(e,n){let t=bm(e,n),o=Array.from({length:t.vertices.length},()=>new Set),r=Array.from({length:t.triangles.length},()=>!0);for(let s=0;s<t.triangles.length;s+=1){let i=t.triangles[s];o[i.a].add(s),o[i.b].add(s),o[i.c].add(s)}return{vertices:t.vertices,triangles:t.triangles,alive:r,vertexTriangles:o,activeCount:t.triangles.length}}function Pm(e){let n=new Map,t=(o,r,s)=>{let i=hm(o,r),c=n.get(i);c?c.triangles.push(s):n.set(i,{a:Math.min(o,r),b:Math.max(o,r),triangles:[s]})};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 Mm(e){let n=Array.from({length:e.vertices.length},()=>mm());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,ma(e.vertices,o.a,o.b,o.c)),s=dm(o.normal,e.vertices[o.a],Math.sqrt(r));mo(n[o.a],s),mo(n[o.b],s),mo(n[o.c],s)}return n}function Am(e,n,t){let o=new Set,r=s=>{let i=e.vertexTriangles[s];if(i)for(let c of i)e.alive[c]&&o.add(c)};return r(n),r(t),Array.from(o).sort((s,i)=>s-i)}function Sm(e,n,t){let o=e.vertexTriangles[n],r=e.vertexTriangles[t];if(!o||!r)return 0;let[s,i]=o.size<=r.size?[o,r]:[r,o],c=0;for(let a of s)e.alive[a]&&i.has(a)&&(c+=1);return c}function da(e,n,t){return[e.a===t?n:e.a,e.b===t?n:e.b,e.c===t?n:e.c]}function Cm(e,n,t){if(Sm(e,n.a,n.b)!==2)return null;let o=Am(e,n.a,n.b);if(o.length===0)return null;let r=e.vertices[n.a];e.vertices[n.a]=n.target;let s=0,i=!0;for(let c of o){let a=e.triangles[c],[l,u,f]=da(a,n.a,n.b);if(l===u||l===f||u===f)continue;if(ma(e.vertices,l,u,f)<=1e-8){i=!1;break}let m=Ar(e.vertices,l,u,f);if(br(a.normal,m)<t.maxNormalDot){i=!1;break}let p=a.a===n.a?r:e.vertices[a.a];if(Math.abs(br(a.normal,nt(n.target,p)))>t.maxError){i=!1;break}s+=1}return e.vertices[n.a]=r,i&&s>0?o:null}function Em(e,n,t){e.vertexTriangles[t.a]?.delete(n),e.vertexTriangles[t.b]?.delete(n),e.vertexTriangles[t.c]?.delete(n)}function Tm(e,n,t){e.vertexTriangles[t.a].add(n),e.vertexTriangles[t.b].add(n),e.vertexTriangles[t.c].add(n)}function vm(e,n,t){e.vertices[n.a]=n.target;let o=new Set;for(let r of t){if(!e.alive[r])continue;let s=e.triangles[r],[i,c,a]=da(s,n.a,n.b);if(Em(e,r,s),i===c||i===a||c===a){e.alive[r]=!1,e.activeCount-=1;continue}let l=ym(i,c,a);if(o.has(l)){e.alive[r]=!1,e.activeCount-=1;continue}o.add(l);let u={...s,a:i,b:c,c:a,normal:Ar(e.vertices,i,c,a)};e.triangles[r]=u,Tm(e,r,u)}}function Im(e,n){let t=Pm(e),o=new Set;for(let c of t.values())c.triangles.length>2&&(o.add(c.a),o.add(c.b));if(n.lockBoundary)for(let c of t.values())c.triangles.length===1&&(o.add(c.a),o.add(c.b));let r=Mm(e),s=n.maxError*n.maxError,i=[];for(let c of t.values()){if(c.triangles.length!==2||o.has(c.a)||o.has(c.b))continue;let a=[...r[c.a]];mo(a,r[c.b]);let l=gm(a,e.vertices[c.a],e.vertices[c.b],n.preserveVertices),u=Math.max(0,Pr(a,l));if(u>s*Math.max(1,c.triangles.length))continue;let f=xr(e.vertices[c.a],e.vertices[c.b]);i.push({a:c.a,b:c.b,target:l,error:u,length:f})}return i.sort((c,a)=>c.error-a.error||c.length-a.length),i}function _m(e){let n=[];for(let t=0;t<e.triangles.length;t+=1)e.alive[t]&&n.push(e.triangles[t]);return n}function Om(e,n){if(e.length<n.minGroupTriangles)return e;let t=xm(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 s=0;for(let i=0;i<n.maxPasses&&t.activeCount>r;i+=1){let c=Im(t,n);if(c.length===0)break;let a=0;for(let l of c){if(t.activeCount<=r)break;let u=Cm(t,l,n);if(!u)continue;let f=t.activeCount;vm(t,l,u),!(t.activeCount>=f)&&(s+=1,a+=1)}if(a===0)break}return s===0||t.activeCount>=o?e:_m(t).map(i=>({...i.polygon,vertices:[[...t.vertices[i.a]],[...t.vertices[i.b]],[...t.vertices[i.c]]]}))}function Vm(e){let n=new Map;for(let t=0;t<e.length;t+=1){let o=e[t];if(!im(o))continue;let r=am(o),s=n.get(r);s?(s.indices.push(t),s.polygons.push(o)):n.set(r,{indices:[t],polygons:[o]})}return n}function Sr(e,n){let t=rm(n),o=Vm(e);if(o.size===0)return e;let r=new Map,s=!1;for(let c of o.values()){let a=Om(c.polygons,t);if(!(a===c.polygons||a.length>=c.polygons.length)){r.set(c.indices[0],a);for(let l=1;l<c.indices.length;l+=1)r.set(c.indices[l],[]);s=!0}}if(!s)return e;let i=[];for(let c=0;c<e.length;c+=1){let a=r.get(c);a?i.push(...a):a===void 0&&i.push(e[c])}return i}var Rm=3,Lm=.03,wm=.02,Ot={maxAngleDeg:Rm,maxPlaneDisplacement:Lm,maxBoundaryDisplacement:wm,isolatedPairs:!1},po={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},Cr=[{...po,maxAngleDeg:30},{...po,maxAngleDeg:45},{...po,maxAngleDeg:60,maxBoundaryDisplacement:.06}],Nm=1800,Dm=.65,pa=500,ga=2200,Fm=1e3,Bm=2200,km=350,Um=700,Gm=60,zm=.06,$m=4,Xm=.003,Ym=4e3,Wm=3e3,jm=4500,Km=2400,Hm=4200,Zm=1800,qm=5e3,Qm=.28,Jm=.15,ed=.23,nd=2e3,td=16,od=4e3,rd=900,sd=16,id=1.5,Tr=.045,ad=.999,cd=1e-5,ld=24,ud=50,fd=1e3,md=1e3,Bn={minGroupPolygons:2,maxCandidateAxes:24},dd={...Bn,maxCandidateAxes:1},ha={...Bn,maxCandidateAxes:2},pd={...Bn,maxCandidateAxes:2},gd={steps:[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"},{kind:"finalLossyCandidates"}]};function hd(e,n={}){return yd(e,n).polygons}function Ma(e,n={}){let t={meshResolution:n.meshResolution,stopAtPolygonCount:n.stopAtPolygonCount,rectCover:n.rectCover},o=new go,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 yd(e,n={},t={}){return new go().workspaceFor(e,t).createRun(n,t).optimize()}var go=class{constructor(){this.workspaces=new Map}workspaceFor(n,t){let o=bd(t),r=this.workspaces.get(o);r||(r=new WeakMap,this.workspaces.set(o,r));let s=r.get(n);return s||(s=new vr(n,t,this),r.set(n,s)),s}};function bd(e){return[e.skipInteriorCull===!0?"skip-cull":"cull",e.simplifiedCandidate===!0?"simplified":"source"].join(":")}var vr=class{constructor(n,t,o){this.source=n,this.graph=o,this.preprocessCache={skipInteriorCull:t.skipInteriorCull===!0}}polygons(){return this.source}preprocess(n){return zd(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<=Hm:n.length<=Zm||n.length<=qm&&o>=Qm}visiblePolygons(){return this.preprocessCache.interior??this.preprocessCache.deduped??this.source}createRun(n,t){return new Ir(this,n,t)}workspaceFor(n,t){return this.graph.workspaceFor(n,t)}},Ir=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 _r(this.baseline,this.requiredMaxPolygonCount)}optimize(){return this.runPlan(gd)}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"||!Ld(this.source,this.best))return!1;let t=Sa(this.source,n);if(!t)return!1;for(let o of this.staticSimplificationPlans(t)){let r=wd(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>=od&&r>=rd&&(t<=sd||r>=t*id)&&o.push({source:this.visiblePolygons,skipInteriorCull:!0}),this.best.length>=nd&&t<=td&&Rd(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},s=this.workspace.workspaceFor(n,r),i=this.best;return new e(s,{meshResolution:"lossy",stopAtPolygonCount:Vd(this.best.length,t)},r,{acceptor:this.acceptor,costCandidateMode:"dom",seamCandidateMode:"dom",offerBaseline:!0}).optimize(),this.best!==i}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?Dd(this.baseline):this.options.rectCover;if(this.shouldStop())return;let t=Fn(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=Fn(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(po);this.acceptCandidate(n),!this.shouldStop()&&(this.options.rectCover===void 0&&this.source.length>=pa&&this.source.length<=ga&&(this.acceptCandidate(Fn(n,ha)),this.shouldStop())||this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(this.acceptCandidate(Fn(n,this.options.rectCover)),this.shouldStop()))}runFinalLossyPipeline(){this.finalLossyCandidatesComplete||(this.finalLossyCandidatesComplete=!0,!(this.runOptions.simplifiedCandidate===!0&&this.source.length>jm)&&(this.runAggressiveLossyVariants(),!this.shouldStop()&&this.runLargeRectCoverCandidate()))}runAggressiveLossyVariants(){let n=this.stopAtPolygonCount===void 0&&this.source.length>=Ym&&this.best.length<=Wm,t=!1;for(let o=n?Cr.length:0;o<Cr.length;o+=1){if(o===1&&!t||o===1&&this.runOptions.simplifiedCandidate===!0&&this.source.length<Km||o===2&&!Bd(this.source))continue;let r=this.preprocess(Cr[o]),s=r;this.options.rectCover===void 0&&this.source.length>=pa&&this.source.length<=ga&&(s=Fn(r,ha)),this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(s=Fn(r,this.options.rectCover));let i=this.acceptSeamSafeCandidate(s,this.source.length);if(o===0&&i&&(t=!0),this.shouldStop())return}}runLargeRectCoverCandidate(){if(this.options.rectCover!==void 0)return;let n=Fn(this.best,Fd(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=kn(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})}},_r=class{constructor(n,t){this.best=n,this.bestCost=kn(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=kn(n)){return t>=this.bestCost?!1:(this.commit(n,t),!0)}acceptDomCandidate(n,t=kn(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 s=Od(t);if(this.bestCost-n.length<s)return!1;let i=o??kn(n),c=this.bestCost-i;if(c<=0||c<s)return!1;let a=ya(n);if(!a)return!1;let l=this.bestSeamDiagnostics();return!l||xd(a,l)||Pd(this.bestTopologyEdges(),this.bestTopologySelfDiagnostics(),n)?!1:(this.commit(n,i,a),!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=ya(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=Aa(this.best)),this.bestDiagnostics.topologyEdges}bestTopologySelfDiagnostics(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologySelf||(this.bestDiagnostics.topologySelf=Cd(this.bestTopologyEdges(),Tr)),this.bestDiagnostics.topologySelf}};function kn(e){let n=0;for(let t of e){let o=t.vertices.length,r=o<=4?0:Math.min(4,o-4)*.12,s=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+r+s}return n}function ya(e){try{return la(e)}catch(n){if(n instanceof RangeError&&n.message==="Set maximum size exceeded")return null;throw n}}function xd(e,n){return e.nearPairs>n.nearPairs||e.unclosedPairs>n.unclosedPairs||e.maxMeasuredGapPx>n.maxMeasuredGapPx+1e-9||e.maxResidualGapPx>n.maxResidualGapPx+1e-9}function Pd(e,n,t){let o=Aa(t);return Md(e,o,Tr)?!0:Sd(o.boundarySegments,Tr,n)}function Md(e,n,t){if(e.internalSegments.length===0)return!1;let o=Ad(e,t);for(let r of n.boundarySegments)if(!e.boundaryKeys.has(r.key)&&(e.internalKeys.has(r.key)||Id(r,o,t)))return!0;return!1}function Ad(e,n){return(!e.internalIndex||e.internalIndexTolerance!==n)&&(e.internalIndex=Rr(e.internalSegments,n),e.internalIndexTolerance=n),e.internalIndex}function Sd(e,n,t){let o=Rr(e,n),r=new Set,s=0,i=0,c=0;for(let a of e)s=Math.max(s,a.index+1);for(let a of e)for(let l of Lr(a,o,n)){if(l===a||l.polygon===a.polygon||l.key===a.key)continue;let u=a.index<l.index?a.index*s+l.index:l.index*s+a.index;if(r.has(u))continue;r.add(u);let f=wr(a,l,n);if(f&&(i+=1,c+=f.overlapLength,i>t.tJunctionPairs||c>t.tJunctionLength+1e-9))return!0}return!1}function Cd(e,n){let t={tJunctionPairs:0,tJunctionLength:0};return Ed(t,e.boundarySegments,n),t}function Ed(e,n,t){let o=Rr(n,t),r=new Set,s=0;for(let i of n)s=Math.max(s,i.index+1);for(let i of n)for(let c of Lr(i,o,t)){if(c===i||c.polygon===i.polygon||c.key===i.key)continue;let a=i.index<c.index?i.index*s+c.index:c.index*s+i.index;if(r.has(a))continue;r.add(a);let l=wr(i,c,t);l&&(e.tJunctionPairs+=1,e.tJunctionLength+=l.overlapLength)}}function Aa(e){let n=new Map;for(let a=0;a<e.length;a+=1){let l=e[a].vertices;for(let u=0;u<l.length;u+=1){let f=l[u],d=l[(u+1)%l.length],m=Td(Lt(f,d),a,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=[],s=[],i=0,c=0;for(let a of n.values()){let l={...a.segment,index:c};c+=1,a.count===1?(t.add(l.key),r.push(l),i+=l.length):(o.add(l.key),s.push(l))}return{boundaryKeys:t,internalKeys:o,boundarySegments:r,internalSegments:s,boundaryLength:i}}function Td(e,n,t,o,r){let s=hn(r,o),i=Math.hypot(s[0],s[1],s[2]);if(i<=1e-10)return null;let c=[s[0]/i,s[1]/i,s[2]/i];return{index:-1,key:e,polygon:n,edge:t,a:o,b:r,dir:c,length:i,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 Rr(e,n){let t=Math.max(n*8,.5),o=new Map;for(let r of e)vd(o,r,t,n);return{cellSize:t,cells:o}}function vd(e,n,t,o){let[r,s,i]=ho([n.minX-o,n.minY-o,n.minZ-o],t),[c,a,l]=ho([n.maxX+o,n.maxY+o,n.maxZ+o],t);for(let u=r;u<=c;u+=1)for(let f=s;f<=a;f+=1)for(let d=i;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function ho(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function Lr(e,n,t){let o=[],r=new Set,[s,i,c]=ho([e.minX-t,e.minY-t,e.minZ-t],n.cellSize),[a,l,u]=ho([e.maxX+t,e.maxY+t,e.maxZ+t],n.cellSize);for(let f=s;f<=a;f+=1)for(let d=i;d<=l;d+=1)for(let m=c;m<=u;m+=1){let p=n.cells.get(`${f},${d},${m}`);if(p)for(let h of p)r.has(h)||(r.add(h),o.push(h))}return o}function Id(e,n,t){for(let o of Lr(e,n,t))if(wr(e,o,t))return!0;return!1}function wr(e,n,t){if(!_d(e,n,t)||Math.abs(He(e.dir,n.dir))<ad)return null;let o=He(hn(n.a,e.a),e.dir),r=He(hn(n.b,e.a),e.dir),s=Math.max(0,Math.min(o,r)),i=Math.min(e.length,Math.max(o,r)),c=i-s;if(c<=Math.max(cd,Math.min(e.length,n.length)*1e-4))return null;let a=[e.a[0]+e.dir[0]*((s+i)/2),e.a[1]+e.dir[1]*((s+i)/2),e.a[2]+e.dir[2]*((s+i)/2)],l=Math.max(0,Math.min(n.length,He(hn(a,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=Fa(a,u);return f<=t?{overlapLength:c,offset:f}:null}function _d(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 Od(e){return Math.max($m,e*Xm)}function Vd(e,n){let t=Number.isFinite(n.earlyStopDropRatio)?Math.max(0,n.earlyStopDropRatio):Jm;return Math.max(0,e-Math.max(1,Math.ceil(e*t)))}function Rd(e){return e.some(n=>n.simplifySourceVertexKeys?.length===n.vertices.length)}function Ld(e,n){return e.length===0||n.length/e.length>ed}function Sa(e,n,t){let o=Sr(e,{...n.simplifyTriangleMeshOptions,...t?{vertexKeyMode:t}:{}});return o===e||o.length>=e.length?null:o}function wd(e,n){return e.precomputed!==void 0?e.precomputed:Sa(e.source,n,e.vertexKeyMode)}function Fn(e,n){if(n===!1)return e;let t=Nd(e,n);if(!t)return e;let o=ir(e,t);return o.length<e.length?o:e}function Nd(e,n){if(n&&n!==!0)return n;let t=n===!0,o=e.length;return o>2200||!t&&o>=ld&&o<ud||!t&&o>fd?null:!t&&o<=300?{...Bn,maxCandidateAxes:1}:o>300?!t&&(Ca(e)>12||Ea(e)>md)?null:{...Bn,maxCandidateAxes:Math.min(Bn.maxCandidateAxes??24,2)}:Bn}function Dd(e){return e.length>Nm||e.length===0||kd(e)/e.length<Dm?!1:dd}function Fd(e){return e.length<Fm||e.length>Bm||Ca(e)<=12||Ea(e)>km?!1:pd}function Bd(e){return e.length<=Um}function kd(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function Ca(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function Ea(e){let n=new Map;for(let o of e)for(let r=0;r<o.vertices.length;r++){let s=o.vertices[r],i=o.vertices[(r+1)%o.vertices.length],c=Lt(s,i);n.set(c,(n.get(c)??0)+1)}let t=0;for(let o of n.values())o===1&&(t+=1);return t}function yo(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function Or(e,n){if(n===e||n.length===e.length&&n.every((r,s)=>r===e[s]))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 Ud(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let r=Jt(e);if(r.size===0)t=null;else{t=[];for(let s=0;s<e.length;s++)r.has(s)||t.push(s)}n&&(n.dedupedIndices=t)}let o=yo(e,t);return n&&(n.deduped=o),o}function Gd(e,n){if(n?.skipInteriorCull)return e;if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let r=dn(e);t=Or(e,r),n&&(n.interiorIndices=t)}let o=yo(e,t);return n&&(n.interior=o),o}function zd(e,n,t){let o=Ud(e,t),r=Gd(o,t),s=t?.baseline??ln(r);if(t&&!t.baseline&&(t.baseline=s),!n)return s;let i=n===!0?Ot:Xd(n);if(i.isolatedPairs){let u=xa(ba(o,t),i,t),f=ln(u);if(t?.snappedInteriorUsesBaselineFilter&&$d(s,f)){let d=xa(ba(o,t,!0),i,t),m=ln(d);m.length<f.length&&(f=m)}return f.length<s.length?f:s}let c=op(o,i,t),a=dn(c),l=ln(a);return l.length<s.length?l:s}function Ta(e,n){return n?(n.snapped||(n.snapped=bo(e)),n.snapped):bo(e)}function ba(e,n,t=!1){if(!n)return dn(bo(e));if(t&&n.snappedInteriorExact)return n.snappedInteriorExact;if(!t&&n.snappedInterior)return n.snappedInterior;let o=Ta(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=dn(o);return n.snappedInteriorExactIndices=Or(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=yo(o,n.snappedInteriorIndices),n.snappedInteriorUsesBaselineFilter=!0,n.snappedInterior;if(n.snappedInteriorIndices===void 0){let r=dn(o);n.snappedInteriorIndices=Or(o,r),n.snappedInterior=r,n.snappedInteriorExactIndices=n.snappedInteriorIndices,n.snappedInteriorExact=r,n.snappedInteriorUsesBaselineFilter=!1}else n.snappedInterior=yo(o,n.snappedInteriorIndices)}return n.snappedInterior}function $d(e,n){return n.length>=e.length}function Xd(e){return{maxAngleDeg:e.maxAngleDeg??Ot.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??Ot.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??Ot.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??Ot.isolatedPairs}}function xa(e,n,t){let o=Yd(e,t),r=[];for(let i of Wd(e,o))jd(i,n)&&r.push(i.candidate);let s=Hd(r);return s.length===0?e:Kd(e,s)}function Yd(e,n){if(n?.trianglePairSource?.polygons===e)return n.trianglePairSource;let t=e.map(i=>{let c=Dr(i);return c?{polygon:i,normal:c.normal,area:c.area,materialKey:Ra(i)}:null}),o=new Map;for(let i=0;i<e.length;i++){let c=e[i];if(!(c.vertices.length!==3||!t[i]))for(let a=0;a<c.vertices.length;a++){let l=Lt(c.vertices[a],c.vertices[(a+1)%c.vertices.length]),u=o.get(l);u?u.push(i):o.set(l,[i])}}let r=[];for(let i of o.values())i.length===2&&r.push([i[0],i[1]]);let s={polygons:e,metas:t,edgeOwnerPairs:r};return n&&(n.trianglePairSource=s),s}function Wd(e,n){if(n.preparedCandidates)return n.preparedCandidates;let t=[];for(let[o,r]of n.edgeOwnerPairs){let s=ep(o,r,e,n.metas);s&&t.push(s)}return n.preparedCandidates=t,t}function jd(e,n){let t=Math.cos(n.maxAngleDeg*Math.PI/180);return e.normalDot>=t&&e.maxDistance<=Math.min(n.maxPlaneDisplacement,n.maxBoundaryDisplacement)}function Kd(e,n){let t=new Map,o=new Set,r=va(n.flatMap(i=>i.vertexMoves));for(let i of n){let c=Math.min(i.a,i.b);t.set(c,i.polygon),o.add(Math.max(i.a,i.b))}let s=[];for(let i=0;i<e.length;i++){let c=t.get(i);if(c){s.push(c);continue}o.has(i)||s.push(e[i])}return r.size>0?Ia(s,r):s}function Hd(e){return e.length>3e3?Zd(e):qd(e)}function Zd(e){let n=new Map;for(let s of e)n.set(s.a,(n.get(s.a)??0)+1),n.set(s.b,(n.get(s.b)??0)+1);let t=[...e].sort((s,i)=>{let c=(n.get(s.a)??0)+(n.get(s.b)??0),a=(n.get(i.a)??0)+(n.get(i.b)??0);return c-a||s.score-i.score}),o=new Set,r=[];for(let s of t)o.has(s.a)||o.has(s.b)||(o.add(s.a),o.add(s.b),r.push(s));return r}function qd(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,s=new Vr;for(let[l,u]of n)r.set(l,u.length);let i=l=>(r.get(l.a)??0)+(r.get(l.b)??0),c=l=>{let u=e[l];s.push({degree:i(u),score:u.score,index:l})},a=(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++)c(l);for(;s.size()>0;){let l=s.pop();if(!o[l.index])continue;let u=e[l.index];if(i(u)!==l.degree){c(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)??[])a(p,d);for(let m of d)for(let p of n.get(m)??[])o[p]&&c(p)}return t}var Vr=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(Er(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,s=r+1,i=o;if(r<this.items.length&&Er(this.items[r],this.items[i])<0&&(i=r),s<this.items.length&&Er(this.items[s],this.items[i])<0&&(i=s),i===o)break;[this.items[o],this.items[i]]=[this.items[i],this.items[o]],o=i}}return n}};function Er(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function va(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 Qd(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o].vertices,s=n[o]?.vertices;if(!s||s.length!==r.length)continue;for(let a=0;a<r.length;a++)t.push({key:on(r[a]),target:s[a]});let i=e[o].textureTriangles??[],c=n[o]?.textureTriangles??[];for(let a=0;a<i.length;a++){let l=c[a];if(l)for(let u=0;u<i[a].vertices.length;u++)t.push({key:on(i[a].vertices[u]),target:l.vertices[u]})}}return t}function Jd(e,n){let t=[];for(let o of e)for(let r of o.textureTriangles??[])for(let s of r.vertices)t.push({key:on(s),target:Ur(s,n)});return t}function Ia(e,n){return e.map(t=>{let o=!1,r=c=>{let a=n.get(on(c));return a?(o=!0,a):c},s=t.vertices.map(r),i=Nr(t.textureTriangles,r);return o?{...t,vertices:s,...i?{textureTriangles:i}:{}}:t})}function ep(e,n,t,o){let r=t[e],s=t[n],i=o[e],c=o[n];if(!i||!c||r.vertices.length!==3||s.vertices.length!==3||!gp(r,s,i,c))return null;let a=Br(r,s);if(!a)return null;let[l,u,f,d]=a;if((f+1)%s.vertices.length===d)return null;let p=Math.abs(He(i.normal,c.normal)),h=Math.cos(Gm*Math.PI/180);if(p<h)return null;let g=(u+1)%r.vertices.length,y=3-f-d,b=[r.vertices[u],r.vertices[g],r.vertices[l],s.vertices[y]],x=np(b);if(!x)return null;let P=0,S=0;for(let M of b){let E=Math.abs(kr(M,x));P=Math.max(P,E),S+=E*E}if(P>zm)return null;let C=b.map(M=>Ur(M,x));if(!tp(C,x.normal))return null;let T=Dr({vertices:C});if(!T||He(T.normal,i.normal)<.2||He(T.normal,c.normal)<.2)return null;let A={vertices:b,color:r.color,...r.doubleSided?{doubleSided:!0}:{},...r.data?{data:{...r.data}}:{}};if(Fr(r,s)&&r.uvs&&s.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[g]],[...r.uvs[l]],[...s.uvs[y]]];let M=rp([r,s]);M?.length&&(A.textureTriangles=M)}return{normalDot:p,maxDistance:P,candidate:{a:e,b:n,polygon:A,vertexMoves:[...b.map((M,E)=>({key:on(M),target:C[E]})),...Jd([r,s],x)],score:S/b.length+P*.25+(1-p)*.1}}}function np(e){if(e.length<3)return null;let n=0,t=0,o=0,r=0,s=0,i=0;for(let a=0;a<e.length;a++){let l=e[a],u=e[(a+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],s+=l[1],i+=l[2]}let c=Ba([n,t,o]);return c?{normal:c,point:[r/e.length,s/e.length,i/e.length]}:null}function tp(e,n){let t=0;for(let o=0;o<e.length;o++){let r=e[o],s=e[(o+1)%e.length],i=e[(o+2)%e.length],c=He(Da(hn(s,r),hn(i,s)),n);if(Math.abs(c)<=1e-9)continue;let a=c>0?1:-1;if(t===0)t=a;else if(t!==a)return!1}return!0}function op(e,n,t){let o=Ta(e,t),r=up(o,n);if(r<=0)return o;let s=o.map(m=>{let p=Dr(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Ra(m)}:null}),i=dp(o,s),c=new Set,a=Array(o.length),l=[],u=(m,p)=>{a[m]=p};for(let m=0;m<o.length;m++){let p=s[m];if(c.has(m))continue;if(!p){u(m,o[m]);continue}let h=hp(m,s,i,c,r,n);for(let y of h)c.add(y);if(h.length<2){u(m,o[m]);continue}let g=ap(h,o,s,i,r,n);l.push(...g.vertexMoves);for(let y of h)u(y,g.polygons.get(y)??o[y])}let f=a.flatMap(m=>m?[m]:[]),d=l.length>0?Ia(f,va(l)):f;return bo(d)}function bo(e){let n=Va(e),t=1e-4;if(n<=0)return e;let o=fp(n),r=mp(t),s=!1,i=e.map(c=>{let a=!1,l=p=>{let h=o.snap(p);return Vt(h,p)||(a=!0),h},u=c.vertices.map(l),f=c.uvs&&c.uvs.length===c.vertices.length?c.uvs.map(p=>{let h=r.snap(p);return Rt(h,p)||(a=!0),h}):void 0,d=Nr(c.textureTriangles,l);if(!a&&!c.texture)return c;let m={...c,vertices:u,...f?{uvs:f}:{},...d?{textureTriangles:d}:{}};return s=!0,{...m,...m.texture?{textureTriangles:_a(m)}:{}}});return s?i:e}function _a(e){if(e.texture){if(e.textureTriangles?.length)return ip(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return sp(e.vertices,e.uvs)}}function rp(e){let n=e.flatMap(t=>_a(t)??[]);return n.length>0?n:void 0}function sp(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 ip(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Nr(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(o=>[...o])}))}function ap(e,n,t,o,r,s){let i=Oa(e,n,t,r,s);return i?lp(i):cp(e,n,t,o,r,s)}function cp(e,n,t,o,r,s){let i=new Set(e),c=[];for(let f of e)for(let d of o.get(f)??[]){if(f>=d||!i.has(d))continue;let m=Oa([f,d],n,t,r,s);m&&c.push(m)}c.sort((f,d)=>d.score-f.score);let a=new Set,l=new Map,u=[];for(let f of c)if(!f.indices.some(d=>a.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];a.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function lp(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 Oa(e,n,t,o,r){let s=La(e,t);if(!s||!wa(e,t,s,o,r))return null;let i=e.map(u=>n[u]),c=i.map(u=>xp(u,s)),a=kn(ln(i)),l=kn(ln(c));return l>=a?null:{indices:e,source:i,projected:c,vertexMoves:Qd(i,c),score:a-l}}function up(e,n){return Va(e)<=0?0:n.maxPlaneDisplacement}function Va(e){let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let[l,u,f]of a.vertices)n=Math.min(n,l),t=Math.min(t,u),o=Math.min(o,f),r=Math.max(r,l),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let c=Math.hypot(r-n,s-t,i-o);return c<=0?0:Math.min(.025,Math.max(1e-4,c*25e-5))}function fp(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,s,i)=>`${r},${s},${i}`;return{snap(r){let s=t(r[0]),i=t(r[1]),c=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(s+f,i+d,c+m));if(p){for(let h of p)if(Fa(r,h)<=e)return[h[0],h[1],h[2]]}}let a=[r[0],r[1],r[2]],l=o(s,i,c),u=n.get(l);return u?u.push(a):n.set(l,[a]),a}}}function mp(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,s)=>`${r},${s}`;return{snap(r){let s=t(r[0]),i=t(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(o(s+u,i+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 c=[r[0],r[1]],a=o(s,i),l=n.get(a);return l?l.push(c):n.set(a,[c]),c}}}function Ra(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 Dr(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0,s=n[0];for(let c=1;c<n.length-1;c++){let a=hn(n[c],s),l=hn(n[c+1],s),u=Da(a,l);t+=u[0],o+=u[1],r+=u[2]}let i=Math.hypot(t,o,r);return i<=1e-10?null:{normal:[t/i,o/i,r/i],area:i/2}}function dp(e,n){let t=new Map,o=new Map;for(let r=0;r<e.length;r++){let s=e[r];if(!(!n[r]||s.vertices.length<3))for(let i=0;i<s.vertices.length;i++){let c=Lt(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),a=t.get(c);a?a.push(r):t.set(c,[r])}}for(let r of t.values())for(let s=0;s<r.length;s++)for(let i=s+1;i<r.length;i++){let c=r[s],a=r[i];pp(e[c],e[a],n[c],n[a])&&(Pa(o,c,a),Pa(o,a,c))}return o}function pp(e,n,t,o){if(!t||!o||t.materialKey!==o.materialKey||!!e.uvs!=!!n.uvs)return!1;if(xo(e)||xo(n))return Fr(e,n);if(!e.uvs||!n.uvs)return!0;let r=Br(e,n);if(!r)return!1;let[s,i,c,a]=r;return Rt(e.uvs[s],n.uvs[c])&&Rt(e.uvs[i],n.uvs[a])}function gp(e,n,t,o){return t.materialKey!==o.materialKey?!1:xo(e)||xo(n)?Fr(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function xo(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Fr(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=Br(e,n);if(!t)return!1;let[o,r,s,i]=t;return Rt(e.uvs[o],n.uvs[s])&&Rt(e.uvs[r],n.uvs[i])}function Pa(e,n,t){let o=e.get(n);o?o.add(t):e.set(n,new Set([t]))}function hp(e,n,t,o,r,s){let i=[e],c=new Set([e]),a=[e];for(;a.length>0;){let l=a.shift();for(let u of t.get(l)??[]){if(o.has(u)||c.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&yp([...i,u],n,r,s)&&(i.push(u),c.add(u),a.push(u))}}return i}function yp(e,n,t,o){let r=La(e,n);return!!r&&wa(e,n,r,t,o)}function La(e,n){let t=n[e[0]];if(!t)return null;let o=0,r=0,s=0,i=0,c=0,a=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let h=He(t.normal,p.normal)<0?-1:1,g=Math.max(p.area,1e-6);o+=p.normal[0]*h*g,r+=p.normal[1]*h*g,s+=p.normal[2]*h*g;for(let y of p.polygon.vertices)i+=y[0],c+=y[1],a+=y[2],l+=1}let u=Ba([o,r,s]);if(!u||l===0)return null;let f=Na(e,n),d=bp(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:[i/l,c/l,a/l],boundaryVertexKeys:f}}function bp(e,n,t,o){let r=1/0,s=-1/0;for(let i of e){let c=n[i];if(c)for(let a of c.polygon.vertices){if(!o.has(on(a)))continue;let l=He(a,t);r=Math.min(r,l),s=Math.max(s,l)}}return Number.isFinite(r)&&Number.isFinite(s)?{min:r,max:s}:null}function wa(e,n,t,o,r){let s=Math.cos(r.maxAngleDeg*Math.PI/180),i=t.boundaryVertexKeys??Na(e,n);for(let c of e){let a=n[c];if(!a||Math.abs(He(a.normal,t.normal))<s)return!1;for(let l of a.polygon.vertices){let u=i.has(on(l))?r.maxBoundaryDisplacement:o;if(Math.abs(kr(l,t))>u)return!1}}return!0}function Na(e,n){let t=new Map;for(let r of e){let s=n[r];if(!s)continue;let i=s.polygon.vertices;for(let c=0;c<i.length;c++){let a=i[c],l=i[(c+1)%i.length],u=Lt(a,l),f=t.get(u);f?f.count+=1:t.set(u,{count:1,a,b:l})}}let o=new Set;for(let r of t.values())r.count===1&&(o.add(on(r.a)),o.add(on(r.b)));return o}function xp(e,n){let t=r=>Ur(r,n),o=Nr(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...o?{textureTriangles:o}:{}}}function Br(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 s=(r+1)%n.vertices.length;if(Vt(e.vertices[t],n.vertices[r])&&Vt(e.vertices[o],n.vertices[s]))return[t,o,r,s];if(Vt(e.vertices[t],n.vertices[s])&&Vt(e.vertices[o],n.vertices[r]))return[t,o,s,r]}}return null}function Lt(e,n){let t=on(e),o=on(n);return t<o?`${t}|${o}`:`${o}|${t}`}function on(e){return`${e[0]},${e[1]},${e[2]}`}function Vt(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Rt(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function hn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Da(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 He(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Fa(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function Ba(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 kr(e,n){return He(hn(e,n.point),n.normal)}function Ur(e,n){let t=kr(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var Pp=36,Mp=.15,Ap=.2,Sp=650,Cp=15e3,Ep=.25;function Gr(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function ka(e){let n=An(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 Tp(e){let n=An(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 vp(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function Ua(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),s=Math.min(n,t,o),i=r-s,c=0;return i!==0&&(r===n?c=60*((t-o)/i%6):r===t?c=60*((o-n)/i+2):c=60*((n-t)/i+4)),c<0&&(c+=360),{hue:c,saturation:r===0?0:i/r,value:r}}function Ip(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function _p(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=Ua(e),o=Ua(n),r=t.saturation<.08,s=o.saturation<.08;if(r||s)return r===s;let i=Math.min(t.value,o.value)<.18?32:18;return Ip(t.hue,o.hue)<=i}function Op(e,n){let t=new Map;for(let i of e.keys()){let c=Tp(i);c&&t.set(i,c)}let o=[],r=new Map,s=Array.from(e.entries()).sort((i,c)=>c[1]-i[1]||i[0].localeCompare(c[0]));for(let[i]of s){let c=t.get(i);if(!c){r.set(i,i);continue}let a=null;for(let l of o){if(!_p(c,l.parsed))continue;let u=vp(c,l.parsed);u>n||(!a||u<a.distance)&&(a={color:l.color,distance:u})}a?r.set(i,a.color):(o.push({color:i,parsed:c}),r.set(i,i))}return r}function Vp(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??Pp;if(!Number.isFinite(r)||r<=0)return e;let s=new Map,i=[];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||!Gr(f)||Gr(d))continue;let m=ka(d.color);i.push(u),s.set(m,(s.get(m)??0)+1)}if(s.size<2)return e;let c=Op(s,r),a=!1,l=e.polygons.slice();for(let u of i){let f=l[u],d=ka(f.color),m=c.get(d)??d;m!==d&&(l[u]={...f,color:m},a=!0)}return a?{...e,polygons:l}:e}function Rp(e){let n=0;for(let t of e)Gr(t)&&(n+=1);return e.length===0||n/e.length<=Ep}function Lp(e){return!!e.metadata?.stlTopology}function wp(e,n){return n?Math.max(e.simplifyEarlyStopDropRatio??Mp,Ap):e.simplifyEarlyStopDropRatio}function tt(e,n={}){return new zr(e,n).optimize()}var zr=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=Vp(this.result,this.options,this.meshResolution),t=Lp(n),o=t?"lossless":this.meshResolution,r=this.canSimplify(n.polygons,o),s=r&&n.polygons.length>=Sp&&n.polygons.length<=Cp,i=Ma(n.polygons,{meshResolution:o,useCandidateFirst:s,staticSimplification:r?{simplifyTriangleMeshOptions:this.options.simplifyTriangleMeshOptions,earlyStopDropRatio:wp(this.options,s)}:!1,skipInteriorCull:t});return i===n.polygons?n:{...n,polygons:i}}canSimplify(n,t){return t==="lossy"&&this.options.simplifyTriangleMeshes!==!1&&Rp(n)}};function Np(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[_,O,V]of n)t+=_,o+=O,r+=V;let s=1/n.length;t*=s,o*=s,r*=s;let i=n[0],c=n[1],a=n[2],l=c[0]-i[0],u=c[1]-i[1],f=c[2]-i[2],d=a[0]-i[0],m=a[1]-i[1],p=a[2]-i[2],h=u*p-f*m,g=f*d-l*p,y=l*m-u*d,b=Math.hypot(h,g,y);if(b<1e-9)return null;h/=b,g/=b,y/=b;let x=n.length-2,P=new Float64Array(x*9),S=0;for(let _=1;_<n.length-1;_++){let O=n[0],V=n[_],w=n[_+1];P[S++]=O[0],P[S++]=O[1],P[S++]=O[2],P[S++]=V[0],P[S++]=V[1],P[S++]=V[2],P[S++]=w[0],P[S++]=w[1],P[S++]=w[2]}let C=0,T=1/0,A=1/0,M=1/0,E=-1/0,v=-1/0,I=-1/0;for(let[_,O,V]of n){let w=_-t,F=O-o,D=V-r,H=w*w+F*F+D*D;H>C&&(C=H),_<T&&(T=_),_>E&&(E=_),O<A&&(A=O),O>v&&(v=O),V<M&&(M=V),V>I&&(I=V)}return{centroid:[t,o,r],normal:[h,g,y],triFlat:P,bcx:t,bcy:o,bcz:r,br2:C,minX:T,minY:A,minZ:M,maxX:E,maxY:v,maxZ:I}}function Dp(e,n,t,o,r,s,i,c){let a=i[c],l=i[c+1],u=i[c+2],f=i[c+3]-a,d=i[c+4]-l,m=i[c+5]-u,p=i[c+6]-a,h=i[c+7]-l,g=i[c+8]-u,y=r*g-s*h,b=s*p-o*g,x=o*h-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let S=1/P,C=e-a,T=n-l,A=t-u,M=S*(C*y+T*b+A*x);if(M<0||M>1)return!1;let E=T*m-A*d,v=A*f-C*m,I=C*d-T*f,_=S*(o*E+r*v+s*I);return _<0||M+_>1?!1:S*(p*E+h*v+g*I)>.001}function Fp(e,n,t,o,r,s,i){let c=i.bcx-e,a=i.bcy-n,l=i.bcz-t,u=c*o+a*r+l*s,f=c-u*o,d=a-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,h=p.length;for(let g=0;g<h;g+=9)if(Dp(e,n,t,o,r,s,p,g))return!0;return!1}var wt=9,Bp=6,Ue=12;function $r(e,n,t,o,r,s){let i=o-e,c=r-n,a=s-t;return i*c+c*a+a*i}function kp(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),s=new Float64Array(t),i=new Float64Array(t);for(let C=0;C<t;C++){let T=e[o[C]];r[C]=(T.minX+T.maxX)*.5,s[C]=(T.minY+T.maxY)*.5,i[C]=(T.minZ+T.maxZ)*.5}let c=2*Math.max(1,t)+1,a=new Float64Array(c*wt),l=0,u=new Float64Array(Ue),f=new Float64Array(Ue),d=new Float64Array(Ue),m=new Float64Array(Ue),p=new Float64Array(Ue),h=new Float64Array(Ue),g=new Int32Array(Ue),y=new Float64Array(Ue-1),b=new Int32Array(Ue-1),x=new Float64Array(Ue-1),P=new Int32Array(Ue-1);function S(C,T){let A=l++,M=A*wt,E=T-C,v=1/0,I=1/0,_=1/0,O=-1/0,V=-1/0,w=-1/0;for(let G=C;G<T;G++){let te=e[o[G]];te.minX<v&&(v=te.minX),te.maxX>O&&(O=te.maxX),te.minY<I&&(I=te.minY),te.maxY>V&&(V=te.maxY),te.minZ<_&&(_=te.minZ),te.maxZ>w&&(w=te.maxZ)}if(a[M]=v,a[M+1]=I,a[M+2]=_,a[M+3]=O,a[M+4]=V,a[M+5]=w,E<=Bp)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let F=1/0,D=1/0,H=1/0,K=-1/0,Q=-1/0,ne=-1/0;for(let G=C;G<T;G++)r[G]<F&&(F=r[G]),r[G]>K&&(K=r[G]),s[G]<D&&(D=s[G]),s[G]>Q&&(Q=s[G]),i[G]<H&&(H=i[G]),i[G]>ne&&(ne=i[G]);let ee=K-F,ue=Q-D,U=ne-H;if(ee===0&&ue===0&&U===0)return a[M+6]=1,a[M+7]=C,a[M+8]=T,A;let $=$r(v,I,_,O,V,w),k=$>0?1/$:0,L=E+1,W=0,Y=0;for(let G=0;G<3;G++){let te=G===0?F:G===1?D:H,ce=G===0?ee:G===1?ue:U;if(ce===0)continue;let ye=G===0?r:G===1?s:i,he=Ue/ce;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),h.fill(-1/0),g.fill(0);for(let N=C;N<T;N++){let X=(ye[N]-te)*he|0;X>=Ue&&(X=Ue-1);let oe=e[o[N]];oe.minX<u[X]&&(u[X]=oe.minX),oe.maxX>m[X]&&(m[X]=oe.maxX),oe.minY<f[X]&&(f[X]=oe.minY),oe.maxY>p[X]&&(p[X]=oe.maxY),oe.minZ<d[X]&&(d[X]=oe.minZ),oe.maxZ>h[X]&&(h[X]=oe.maxZ),g[X]++}let be=1/0,ge=1/0,Se=1/0,De=-1/0,R=-1/0,z=-1/0,j=0;for(let N=0;N<Ue-1;N++)u[N]<be&&(be=u[N]),m[N]>De&&(De=m[N]),f[N]<ge&&(ge=f[N]),p[N]>R&&(R=p[N]),d[N]<Se&&(Se=d[N]),h[N]>z&&(z=h[N]),j+=g[N],y[N]=$r(be,ge,Se,De,R,z),b[N]=j;let J=1/0,le=1/0,re=1/0,pe=-1/0,xe=-1/0,ie=-1/0,ae=0;for(let N=Ue-2;N>=0;N--){let X=N+1;u[X]<J&&(J=u[X]),m[X]>pe&&(pe=m[X]),f[X]<le&&(le=f[X]),p[X]>xe&&(xe=p[X]),d[X]<re&&(re=d[X]),h[X]>ie&&(ie=h[X]),ae+=g[X],x[N]=$r(J,le,re,pe,xe,ie),P[N]=ae}for(let N=0;N<Ue-1;N++){if(b[N]===0||P[N]===0)continue;let X=.125+(y[N]*b[N]+x[N]*P[N])*k;X<L&&(L=X,W=G,Y=te+(N+1)/he)}}let se=W===0?r:W===1?s:i,Z=C,B=T-1;for(;Z<=B;)if(se[Z]<Y)Z++;else{let G=o[Z];o[Z]=o[B],o[B]=G;let te=r[Z];r[Z]=r[B],r[B]=te;let ce=s[Z];s[Z]=s[B],s[B]=ce;let ye=i[Z];i[Z]=i[B],i[B]=ye,B--}let q=Z;(q===C||q===T)&&(q=C+T>>1),a[M+6]=0;let me=S(C,q),fe=S(q,T);return a[A*wt+7]=me,a[A*wt+8]=fe,A}return t>0&&S(0,t),{data:a,nodeCount:l,polyIndices:o,meta:e}}function Up(e,n,t,o,r,s,i,c,a){if(c.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=c,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,h=0;for(a[h++]=0;h>0;){let y=a[--h]*wt,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,S=b<x?x:b,C=(l[y+1]-n)*m,T=(l[y+4]-n)*m,A=C<T?C:T,M=C<T?T:C;if(P>M||A>S)continue;A>P&&(P=A),M<S&&(S=M);let E=(l[y+2]-t)*p,v=(l[y+5]-t)*p,I=E<v?E:v,_=E<v?v:E;if(!(P>_||I>S)&&(_<S&&(S=_),!(S<.001)))if(l[y+6]===1){let O=l[y+7]|0,V=l[y+8]|0;for(let w=O;w<V;w++){let F=u[w];if(F===i)continue;let D=f[F];if(D&&Fp(e,n,t,o,r,s,D))return!0}}else a[h++]=l[y+7]|0,a[h++]=l[y+8]|0}return!1}function Gp(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 s=n[0]/r,i=n[1]/r,c=n[2]/r,a=e.map(Np);if(t&&t.size>0)for(let f of t)a[f]=null;let l=kp(a),u=new Int32Array(Math.max(64,l.nodeCount));for(let f=0;f<e.length;f++){let d=a[f];if(!d)continue;let m=d.centroid[0]+d.normal[0]*.001,p=d.centroid[1]+d.normal[1]*.001,h=d.centroid[2]+d.normal[2]*.001;d.normal[0]*s+d.normal[1]*i+d.normal[2]*c<=0||Up(m,p,h,s,i,c,f,l,u)&&o.add(f)}return o}var Po=1e-5,Ga=.001,za=6;function Xr(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let c=1;c+1<n.length;c++){let a=n[c],l=n[c+1],u=a[1]-t[1],f=a[0]-t[0],d=a[2]-t[2],m=l[1]-t[1],p=l[0]-t[0],h=l[2]-t[2];o-=f*h-d*p,r-=d*m-u*h,s-=u*p-f*m}let i=Math.hypot(o,r,s);return i<1e-9?null:[o/i,r/i,s/i]}function $a(e,n){let t=n.meshRotation,o=t?Rn(e,t):e;return Qo(o,n.rotX,0,n.rotY)[2]}function Nt(e,n,t=Po){return $a(e,n)>t}function zp(e,n,t=Po){let o=Xr(e);return o===null||Nt(o,n,t)}function Xa(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function Ya(e){let n=new Map;for(let t of e){if(!t)continue;let o=Xa(t);n.has(o)||n.set(o,t)}return Array.from(n,([t,o])=>({key:t,normal:o}))}function $p(e){return Ya(e.map(Xr))}function Wa(e,n=Ga){let t=Math.abs(e[0]),o=Math.abs(e[1]),r=Math.abs(e[2]),s=Math.max(t,o,r);return s>1-n&&t+o+r-s<n}function Xp(e){return e.length<=za&&e.every(({normal:n})=>Wa(n))}function Yp(e,n,t=Po){let o=[];for(let{key:r,normal:s}of e)Nt(s,n,t)&&o.push(r);return o.sort(),o.join("|")}function Yr(e,n,t,o,r){let s=(p,h,g)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=h,y[(e+2)%3]=g,y},i=s(n,-o,-o),c=s(n,o,-o),a=s(n,o,o),l=s(n,-o,o),u=s(t,-o,-o),f=s(t,o,-o),d=s(t,o,o),m=s(t,-o,o);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function ja(e={}){let n=e.size??5,t=e.thickness??.025,o=e.negative??!1,r=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",c=n*t/2,a=o?-n:0;return[...Yr(0,a,n,c,r),...Yr(1,a,n,c,s),...Yr(2,a,n,c,i)]}var Wp=["right","left","front","back","top","bottom"];function Wr(e){return[e[0],e[1],e[2]]}function Ka(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 jp(e){if(e.min&&e.max)return Ka(e.min,e.max);let n=e.center?Wr(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=Wr(e.size):t=[1,1,1];let o=[t[0]/2,t[1]/2,t[2]/2];return Ka([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 Kp(e,n){let[t,o,r]=e,[s,i,c]=n;return[{name:"right",vertices:[[s,o,r],[s,i,r],[s,i,c],[s,o,c]]},{name:"left",vertices:[[t,i,r],[t,o,r],[t,o,c],[t,i,c]]},{name:"front",vertices:[[s,i,r],[t,i,r],[t,i,c],[s,i,c]]},{name:"back",vertices:[[t,o,r],[s,o,r],[s,o,c],[t,o,c]]},{name:"top",vertices:[[t,o,c],[s,o,c],[s,i,c],[t,i,c]]},{name:"bottom",vertices:[[t,i,r],[s,i,r],[s,o,r],[t,o,r]]}]}function Hp(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function Zp(e,n){let t={vertices:e.vertices.map(Wr)};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 Ha(e={}){let{min:n,max:t}=jp(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=Kp(n,t),s=new Map(r.map(c=>[c.name,c])),i=[];for(let c of Wp){let a=e.faces?.[c];if(a===!1)continue;let l=s.get(c);l&&i.push(Zp(l,Hp(o,a)))}return i}function Za(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 qp(e,n,t,o,r){let s=(p,h,g)=>Za(e,p,h,g),i=s(n,-o,-o),c=s(n,o,-o),a=s(n,o,o),l=s(n,-o,o),u=s(t,-o,-o),f=s(t,o,-o),d=s(t,o,o),m=s(t,-o,o);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function Qp(e,n,t,o,r){let s=(f,d,m)=>Za(e,f,d,m),i=s(n,-o,-o),c=s(n,o,-o),a=s(n,o,o),l=s(n,-o,o),u=s(t,0,0);return[{vertices:[i,c,a,l],color:r},{vertices:[i,c,u],color:r},{vertices:[c,a,u],color:r},{vertices:[a,l,u],color:r},{vertices:[l,i,u],color:r}]}function Jp(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function qa(e){let n=e.axis,t=e.sign??1,o=e.shaftLength??4,r=e.shaftHalfThickness??.05,s=e.headLength??.8,i=e.headHalfThickness??.2,c=e.color??"#ffffff",a=e.shaft??!0,l=o*t,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(o+s)*t,p=Qp(n,d,m,i,c),h=t===-1?Jp(p):p;return a?[...qp(n,u,f,r,c),...h]:h}function Mo(e,n,t){let o=[0,0,0],r=(e+1)%3,s=(e+2)%3;return o[r]=Math.cos(t)*n,o[s]=Math.sin(t)*n,o}function Qa(e){let n=e.axis,t=e.radius,o=e.halfThickness??Math.max(.05,t*.04),r=e.segments??32,s=e.color??"#ffffff",i=t-o,c=t+o,a=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=Mo(n,i,u),m=Mo(n,i,f),p=Mo(n,c,u),h=Mo(n,c,f);a.push({vertices:[d,p,h,m],color:s})}return a}function Ja(e){let n=e.axis,t=e.outerRadius,o=e.color??"#ffffff",r=(n+1)%3,s=(n+2)%3,i=(c,a)=>{let l=[0,0,0];return l[n]=0,l[r]=c,l[s]=a,l};return[{vertices:[i(-t,-t),i(t,-t),i(t,t),i(-t,t)],color:o}]}function ec(e){let n=e.axis,t=e.size??.4,o=e.offset??t*2,r=typeof o=="number"?o:o[0],s=typeof o=="number"?o:o[1],i=e.along??0,c=e.color??"#ffffff",a=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=i,m[a]=r+f,m[l]=s+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:c}]}function nc(e){let{center:n,size:t,color:o="#ffffff"}=e,[r,s,i]=n,c=[[r+t,s,i],[r-t,s,i],[r,s+t,i],[r,s-t,i],[r,s,i+t],[r,s,i-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:[c[l[0]],c[l[1]],c[l[2]]],color:o}))}function tc(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,s=[[-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(([a,l,u])=>{let f=Math.sqrt(a*a+l*l+u*u);return[a/f,l/f,u/f]}),i=[[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 a=0;a<o;a++){let l=[...s],u=[],f=new Map,d=(m,p)=>{let h=m<p?`${m}-${p}`:`${p}-${m}`,g=f.get(h);if(g!==void 0)return g;let y=s[m],b=s[p],x=(y[0]+b[0])/2,P=(y[1]+b[1])/2,S=(y[2]+b[2])/2,C=Math.sqrt(x*x+P*P+S*S);x/=C,P/=C,S/=C;let T=l.length;return l.push([x,P,S]),f.set(h,T),T};for(let[m,p,h]of i){let g=d(m,p),y=d(p,h),b=d(h,m);u.push([m,g,b]),u.push([p,y,g]),u.push([h,b,y]),u.push([g,y,b])}s=l,i=u}let c=s.map(([a,l,u])=>[a*n,l*n,u*n]);return i.map(([a,l,u])=>({vertices:[c[a],c[l],c[u]],color:t}))}function oc(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(([i,c,a])=>({vertices:[r[i],r[c],r[a]],color:t}))}function rc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=n/Math.sqrt(1+o*o),s=[[-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(([c,a,l])=>[c*r,a*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(([c,a,l])=>({vertices:[s[c],s[a],s[l]],color:t}))}function sc(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=1/o,s=n/Math.sqrt(3),c=[[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*s,u*s,f*s]);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=>c[u]),color:t}))}function Ao(e={}){let{radius:n=50,height:t=100,radialSegments:o=12,color:r="#cccccc"}=e,s=e.radiusTop??n,i=t/2,c=-i,a=i,l=Math.max(3,o),u=[],f=Array.from({length:l+1},(p,h)=>h/l*Math.PI*2),d=n<=1e-6,m=s<=1e-6;for(let p=0;p<l&&!(d&&m);p++){let h=f[p],g=f[p+1],y=Math.cos(h)*n,b=Math.sin(h)*n,x=Math.cos(g)*n,P=Math.sin(g)*n,S=Math.cos(h)*s,C=Math.sin(h)*s,T=Math.cos(g)*s,A=Math.sin(g)*s,M=[y,b,c],E=[x,P,c],v=[T,A,a],I=[S,C,a];if(m){let _=[0,0,a];u.push({vertices:[M,E,_],color:r})}else if(d){let _=[0,0,c];u.push({vertices:[_,v,I],color:r})}else u.push({vertices:[M,E,v,I],color:r})}if(n>1e-6){let p=[0,0,c];for(let h=0;h<l;h++){let g=f[h],y=f[h+1],b=[Math.cos(g)*n,Math.sin(g)*n,c],x=[Math.cos(y)*n,Math.sin(y)*n,c];u.push({vertices:[[...p],[...x],[...b]],color:r})}}if(s>1e-6){let p=[0,0,a];for(let h=0;h<l;h++){let g=f[h],y=f[h+1],b=[Math.cos(g)*s,Math.sin(g)*s,a],x=[Math.cos(y)*s,Math.sin(y)*s,a];u.push({vertices:[[...p],[...b],[...x]],color:r})}}return u}function ic(e={}){return Ao({...e,radiusTop:0})}function So(e,n,t,o){let r=Math.sin(e),s=Math.cos(e),i=Math.sin(n),c=Math.cos(n);return[(t+o*c)*s,(t+o*c)*r,o*i]}function ac(e={}){let{radius:n=50,tube:t=15,radialSegments:o=12,tubularSegments:r=16,color:s="#cccccc"}=e,i=Math.max(3,o),c=Math.max(3,r),a=[];for(let l=0;l<i;l++){let u=l/i*Math.PI*2,f=(l+1)/i*Math.PI*2;for(let d=0;d<c;d++){let m=d/c*Math.PI*2,p=(d+1)/c*Math.PI*2,h=So(u,m,n,t),g=So(f,m,n,t),y=So(f,p,n,t),b=So(u,p,n,t);a.push({vertices:[h,g,y,b],color:s})}}return a}var eg=.01,ng=.01;function tg(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,o=e[0]/t,r=e[1]/t,s=e[2]/t,i=Math.sign(s||1)*Math.max(Math.abs(s),.01),c=n,a=.01;return[1,0,0,0,0,1,0,0,-o/i,-r/i,a,0,c*o/i,c*r/i,c*(1-a),1]}function og(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,s=n[2]/t;return e[0]*o+e[1]*r+e[2]*s>0}function jr(e){if(e.length<=1)return e.map(i=>[i[0],i[1]]);let t=e.map(i=>[i[0],i[1]]);t.sort((i,c)=>i[0]-c[0]||i[1]-c[1]);let o=(i,c,a)=>(c[0]-i[0])*(a[1]-i[1])-(c[1]-i[1])*(a[0]-i[0]),r=[];for(let i of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],i)<=0;)r.pop();r.push(i)}let s=[];for(let i=t.length-1;i>=0;i--){let c=t[i];for(;s.length>=2&&o(s[s.length-2],s[s.length-1],c)<=0;)s.pop();s.push(c)}return r.pop(),s.pop(),r.concat(s)}function cc(e){let n=0,t=e.length;for(let o=0;o<t;o++){let r=e[o],s=e[(o+1)%t];n+=r[0]*s[1]-s[0]*r[1]}return n/2}function yn(e){let n=e.map(t=>[t[0],t[1]]);return cc(n)<0&&n.reverse(),n}function rg(e,n,t){let o=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/o,s=n[1]/o,i=n[2]/o,c=Math.sign(i||1)*Math.max(Math.abs(i),.01),a=e[2]-t;return[e[0]-r/c*a,e[1]-s/c*a]}function Cn(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 s=t;t=[];let i=n[r],c=n[(r+1)%o],a=f=>(c[0]-i[0])*(f[1]-i[1])-(c[1]-i[1])*(f[0]-i[0])>=0,l=(f,d)=>{let m=i[0],p=i[1],h=c[0],g=c[1],y=f[0],b=f[1],x=d[0],P=d[1],S=(m-h)*(b-P)-(p-g)*(y-x);if(Math.abs(S)<1e-12)return[f[0],f[1]];let C=((m-y)*(b-P)-(p-b)*(y-x))/S;return[m+C*(h-m),p+C*(g-p)]},u=s.length;for(let f=0;f<u;f++){let d=s[f],m=s[(f+u-1)%u],p=a(d),h=a(m);p?(h||t.push(l(m,d)),t.push([d[0],d[1]])):h&&t.push(l(m,d))}}return t}function Co(e){if(!Number.isFinite(e)||e<=0)throw new Error("PolyCSS world unit size must be a positive finite number.");return e}function lc(e,n=50){return e*Co(n)}function uc(e,n=50){return e/Co(n)}function rn(e,n=50){let t=Co(n);return[e[1]*t,e[0]*t,e[2]*t]}function fc(e,n=50){let t=Co(n);return[e[1]/t,e[0]/t,e[2]/t]}function Kr(e){return[e[1],e[0],e[2]]}function mc(e){return e?.direction?{...e,direction:Kr(e.direction)}:e}function Hr(e){return e==null?[1,1,1]:typeof e=="number"?[e,e,e]:[e[0]??1,e[1]??1,e[2]??1]}function Dt(e){let n=Hr(e),t=n[0]===1&&n[1]===1&&n[2]===1;return(o,r)=>{let s=rn(r),i=o[1]*50,c=o[0]*50,a=o[2]*50,l=t?i:i*n[0],u=t?c:c*n[1],f=t?a:a*n[2];return[l+s[0],u+s[1],f+s[2]]}}function dc(e,n){if(e.length<3||n===0)return e;let t=[],o=e.length;for(let r=0;r<o;r++){let s=e[(r-1+o)%o],i=e[r],c=e[(r+1)%o],a=i[0]-s[0],l=i[1]-s[1],u=c[0]-i[0],f=c[1]-i[1],d=Math.hypot(a,l),m=Math.hypot(u,f);if(d<1e-9||m<1e-9){t.push(i);continue}let p=l/d,h=-a/d,g=f/m,y=-u/m,b=p+g,x=h+y,P=Math.hypot(b,x);if(P<1e-9){t.push(i);continue}let S=b/P,C=x/P,T=S*p+C*h;if(Math.abs(T)<1e-9){t.push(i);continue}let A=n/T;t.push([i[0]+S*A,i[1]+C*A])}return t}var pc=.5,gc=.001,hc=.5;function Zr(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,h=0,g=0;for(let A=1;A+1<d.length;A++){let M=d[A],E=d[A+1],v=M[0]-m[0],I=M[1]-m[1],_=M[2]-m[2],O=E[0]-m[0],V=E[1]-m[1],w=E[2]-m[2];p+=V*_-w*I,h+=w*v-O*_,g+=O*I-V*v}let y=Math.hypot(p,h,g);if(y<1e-9)continue;let b=[p/y,h/y,g/y],x=null;for(let A=1;A<d.length;A++){let M=d[A],E=M[0]-m[0],v=M[1]-m[1],I=M[2]-m[2],_=Math.hypot(E,v,I);if(_>1e-9){x=[E/_,v/_,I/_];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 S=Math.hypot(x[0],x[1],x[2]);if(S<1e-9)continue;x=[x[0]/S,x[1]/S,x[2]/S];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]],T=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:T,polyIndex:u})}let s=[];for(let u of r){let f=!1;for(let d of s){let m=d.rep;if(!(1-(u.n[0]*m.n[0]+u.n[1]*m.n[1]+u.n[2]*m.n[2])>gc)&&!(Math.abs(u.offset-m.offset)>hc)){d.faces.push(u),f=!0;break}}f||s.push({rep:u,faces:[u]})}let i=[],c=3,a=u=>`${u[0].toFixed(c)},${u[1].toFixed(c)},${u[2].toFixed(c)}`;for(let u of s){if(u.faces.length===1){l(u.faces);continue}let f=u.faces.map(g=>{let y=new Set;for(let b of g.face.vertices)y.add(a(t(b,n)));return y}),d=u.faces.map((g,y)=>y),m=g=>{for(;d[g]!==g;)d[g]=d[d[g]],g=d[g];return g},p=(g,y)=>{let b=m(g),x=m(y);b!==x&&(d[b]=x)};for(let g=0;g<u.faces.length;g++)for(let y=g+1;y<u.faces.length;y++){let b=f[g],x=f[y],P=0;for(let S of b)if(x.has(S)&&(P++,P>=2))break;P>=2&&p(g,y)}let h=new Map;for(let g=0;g<u.faces.length;g++){let y=m(g),b=h.get(y);b||(b=[],h.set(y,b)),b.push(u.faces[g])}for(let g of h.values())l(g)}function l(u){let f=u[0],{O:d,n:m,u:p,v:h}=f,g=[],y=[],b=[];for(let S of u){let C=[];for(let T of S.face.vertices){let A=t(T,n),M=A[0]-d[0],E=A[1]-d[1],v=A[2]-d[2],I=[M*p[0]+E*p[1]+v*p[2],M*h[0]+E*h[1]+v*h[2]];g.push(I),C.push(I)}C.length>=3&&(y.push(yn(C)),b.push(S.polyIndex))}if(g.length<3)return;let x=jr(g);if(x.length<3)return;let P=dc(yn(x),pc);i.push({O:d,n:m,u:p,v:h,outlineUv:P,memberPolysUv:y,memberPolyIndices:b})}return i}function sg(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,s=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),i=e.position?rn(e.position):[0,0,0],c=[];return(i[0]!==0||i[1]!==0||i[2]!==0)&&c.push(`translate3d(${i[0]}px, ${i[1]}px, ${i[2]}px)`),s&&(e.rotation[0]&&c.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&c.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&c.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&c.push(`scale3d(${n}, ${t}, ${o})`),c.length>0?c.join(" "):void 0}function ig(e={}){let n=e.target??Ke.target,t=e.autoCenterOffset??[0,0,0],o=e.layoutScale??1,r=e.worldUnitPx??50,s=(e.zoom??Ke.zoom)/r*o,i=(e.distance??Ke.distance)*o,c=rn([n[0]+t[0],n[1]+t[1],n[2]+t[2]],r);return`${i!==0?`translateZ(${-i}px) `:""}scale(${s}) rotateX(${e.rotX??Ke.rotX}deg) rotate(${e.rotY??Ke.rotY}deg) translate3d(${-c[0]}px, ${-c[1]}px, ${-c[2]}px)`}var bn=50,ot=[.4,-.7,.59],rt="#ffffff",st=1,it="#ffffff",at=.4,En=4096,Eo=1,qr=.1,Qr=1,To=En*En,Jr=To*3,Ft=2048,es=4*1024*1024,ns=16*1024*1024,ts=.995,os=512,ag=12,Ae=.001,de=1e-9,rs=1e-4,ss=.1,vo=.01,cg=.75,lg=1,ug=250,fg=1.5,is=.75,xn=3,as=2,Io=4,cs=[1,10,100,1e3,1e4,1e5,1e6],ct=64,ls=32,us=96,Ze=64,fs=128,_o=50,Oo=1e-7,Pn=16,ms=.9,qe=.75,Vo=.2,ds=.05,ps=256,gs=.6,mg=1.5;function hs(e){return e===void 0||e==="auto"||!Number.isFinite(e)?1:Math.max(0,Math.min(1,e))}var Bt=new Map;function ut(e){if(Bt.has(e)){let t=Bt.get(e);return t===void 0?null:t}let n=An(e);return Bt.size>=os&&Bt.clear(),Bt.set(e,n),n}function Mn(e){let n=ut(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function ys({r:e,g:n,b:t}){return`${e},${n},${t}`}function Ro(e){return ut(e)?.alpha??1}function Lo({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 wo(e,n,t,o){let r=Mn(n),s=Mn(t),i=ze(r.r/255),c=ze(r.g/255),a=ze(r.b/255),l=ze(s.r/255),u=ze(s.g/255),f=ze(s.b/255);return{r:(i*e+l*o)*lt,g:(c*e+u*o)*lt,b:(a*e+f*o)*lt}}function dg({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 ze(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function pg(e){return e<=.0031308?e*12.92:1.055*Math.pow(e,1/2.4)-.055}var lt=1/Math.PI;function Un(e,n,t,o,r){let s=Mn(e),i=Mn(t),c=Mn(o),a=ze(s.r/255),l=ze(s.g/255),u=ze(s.b/255),f=ze(i.r/255),d=ze(i.g/255),m=ze(i.b/255),p=ze(c.r/255),h=ze(c.g/255),g=ze(c.b/255),y=a*(f*n+p*r)*lt,b=l*(d*n+h*r)*lt,x=u*(m*n+g*r)*lt,P=M=>Math.max(0,Math.min(255,Math.round(pg(Math.max(0,Math.min(1,M)))*255))),S=P(y),C=P(b),T=P(x),A=Ro(e);return A<1?`rgba(${S}, ${C}, ${T}, ${A})`:Lo({r:S,g:C,b:T})}function bs(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=ut(e);if(!t)return e;let o=255/Math.max(1,Math.round(n)-1),r=i=>Math.max(0,Math.min(255,Math.round(Math.round(i/o)*o))),s={r:r(t.rgb[0]),g:r(t.rgb[1]),b:r(t.rgb[2])};return t.alpha<1?`rgba(${s.r}, ${s.g}, ${s.b}, ${t.alpha})`:Lo(s)}function gg(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function hg(e,n,t){let o=(r,s)=>{let i=s-r;return Math.abs(i)<=t?s:r+Math.sign(i)*t};return{r:o(e.r,n.r),g:o(e.g,n.g),b:o(e.b,n.b)}}function yg(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:Lo(e)}function bg(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=ut(e),o=ut(n);if(!t||!o)return 1;let r=t.rgb[0]-o.rgb[0],s=t.rgb[1]-o.rgb[1],i=t.rgb[2]-o.rgb[2],c=(t.alpha-o.alpha)*255;return Math.sqrt(r*r+s*s+i*i+c*c)/510}function xs(e){let t=c=>Math.round(c/1e-4).toString(36),o=c=>`${t(c[0])},${t(c[1])},${t(c[2])}`,r=(c,a)=>{let l=o(c),u=o(a);return l<u?`${l}|${u}`:`${u}|${l}`},s=new Map;for(let c=0;c<e.length;c++){let a=e[c];if(!a||a.vertices.length<2)continue;let l=a.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=s.get(m);p?(p.degree+=1,p.degree===2?p.polyB=c:p.polyB=null):s.set(m,{polyA:c,polyB:null,vertA:f,vertB:d,degree:1})}}let i=new Map;for(let[c,a]of s)i.set(c,{polyA:a.polyA,polyB:a.polyB,vertA:a.vertA,vertB:a.vertB});return i}function Ps(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,s=n[2]/t;return e.map(i=>i?i[0]*o+i[1]*r+i[2]*s<-1e-6:!0)}function Ms(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),s=l=>`${r(l[0])},${r(l[1])},${r(l[2])}`,i=t.map(([l,u])=>({a:l,b:u,aKey:s(l),bKey:s(u),used:!1})),c=new Map;for(let l of i){let u=c.get(l.aKey);u||(u=[],c.set(l.aKey,u)),u.push(l);let f=c.get(l.bKey);f||(f=[],c.set(l.bKey,f)),f.push(l)}let a=[];for(let l of i){if(l.used)continue;let u=[l.a],f=l,d=l.aKey,m=l.bKey;f.used=!0;for(let p=0;p<i.length+1;p++){u.push(f.bKey===m?f.b:f.a);let h=c.get(m)??[],g=null;for(let y of h)if(!(y===f||y.used)){g=y;break}if(!g||(g.used=!0,d=m,m=g.aKey===d?g.bKey:g.aKey,f=g,m===l.aKey))break}u.length>=3&&a.push(u)}return a}var yc=40;function xg(e){let t=c=>Math.round(c/1e-4).toString(36),o=c=>`${t(c[0])},${t(c[1])},${t(c[2])}`,r=(c,a)=>{let l=o(c),u=o(a);return l<u?`${l}|${u}`:`${u}|${l}`},s=new Map;for(let c=0;c<e.length;c++){let a=e[c];if(!a||a.vertices.length<2)continue;let l=a.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=s.get(m);p||(p=[],s.set(m,p)),p.push(c)}}let i=new Map;for(let c of s.values())if(!(c.length<2))for(let a of c)for(let l of c){if(a===l)continue;let u=i.get(a);u||(u=new Set,i.set(a,u)),u.add(l)}return i}function Pg(e,n,t,o){let r=Dt(t),s=!!o&&(o[0]!==0||o[1]!==0||o[2]!==0),i=s?rn(n):null,c=e.map(a=>{if(!a)return{vertices:[],color:""};let l=a.vertices.map(u=>r(u,n));return s&&i&&o&&(l=l.map(u=>{let f=[u[0]-i[0],u[1]-i[1],u[2]-i[2]],d=Rn(f,o);return[d[0]+i[0],d[1]+i[1],d[2]+i[2]]})),{vertices:l,color:""}});return xs(c)}function Mg(e,n,t,o,r){let s=[],i=Dt(t),c=!!r&&(r[0]!==0||r[1]!==0||r[2]!==0),a=c?rn(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(S=>i(S,n));c&&a&&r&&(f=f.map(S=>{let C=[S[0]-a[0],S[1]-a[1],S[2]-a[2]],T=Rn(C,r);return[T[0]+a[0],T[1]+a[1],T[2]+a[2]]}));let d=1/0,m=1/0,p=1/0,h=-1/0,g=-1/0,y=-1/0;for(let S of f)S[0]<d&&(d=S[0]),S[0]>h&&(h=S[0]),S[1]<m&&(m=S[1]),S[1]>g&&(g=S[1]),S[2]<p&&(p=S[2]),S[2]>y&&(y=S[2]);let b=[[d,m,p],[h,m,p],[d,g,p],[h,g,p],[d,m,y],[h,m,y],[d,g,y],[h,g,y]],x=null,P=0;if(f.length>=3){let S=f[0],C=f[1],T=f[2],A=[C[0]-S[0],C[1]-S[1],C[2]-S[2]],M=[T[0]-S[0],T[1]-S[1],T[2]-S[2]],E=M[1]*A[2]-M[2]*A[1],v=M[2]*A[0]-M[0]*A[2],I=M[0]*A[1]-M[1]*A[0],_=Math.hypot(E,v,I);_>1e-9&&(x=[E/_,v/_,I/_],P=x[0]*S[0]+x[1]*S[1]+x[2]*S[2])}s.push({wv:f,bboxCorners:b,planeN:x,planeOffset:P,polygonIndex:l})}return s}function Ag(e,n,t,o,r,s){let i=Dt(t),c=!!s&&(s[0]!==0||s[1]!==0||s[2]!==0),a=c?rn(n):null,f=Zr(e,n,c&&a&&s?(g,y)=>{let b=i(g,y),x=[b[0]-a[0],b[1]-a[1],b[2]-a[2]],P=Rn(x,s);return[P[0]+a[0],P[1]+a[1],P[2]+a[2]]}:i,o).map((g,y)=>{let{O:b,n:x,u:P,v:S,outlineUv:C,memberPolysUv:T,memberPolyIndices:A}=g,M=1/0,E=1/0,v=-1/0,I=-1/0;for(let Q of C)Q[0]<M&&(M=Q[0]),Q[1]<E&&(E=Q[1]),Q[0]>v&&(v=Q[0]),Q[1]>I&&(I=Q[1]);let _=v-M,O=I-E,V=r*50,w=b[0]+M*P[0]+E*S[0]+V*x[0],F=b[1]+M*P[1]+E*S[1]+V*x[1],D=b[2]+M*P[2]+E*S[2]+V*x[2],K=`matrix3d(${[P[0],P[1],P[2],0,S[0],S[1],S[2],0,x[0],x[1],x[2],0,w,F,D,1].map(Q=>Q.toFixed(4)).join(",")})`;return{O:b,n:x,u:P,v:S,outlineUv:C,memberPolysUv:T,memberPolyIndices:A,minU:M,minV:E,width:_,height:O,matrixCss:K,faceIndex:y,lift:V}}),d=.015,m=.5,p=20,h=new Set;for(let g=0;g<f.length;g++){if(h.has(g))continue;let y=f[g],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,S=y.minU+y.width,C=y.minV+y.height;for(let T=0;T<f.length;T++){if(T===g||h.has(T))continue;let A=f[T];if(y.n[0]*A.n[0]+y.n[1]*A.n[1]+y.n[2]*A.n[2]<1-d)continue;let E=y.n[0]*A.O[0]+y.n[1]*A.O[1]+y.n[2]*A.O[2];if(E<=b+m||E-b>p)continue;let v=1/0,I=1/0,_=-1/0,O=-1/0;for(let V of A.outlineUv){let w=A.O[0]+V[0]*A.u[0]+V[1]*A.v[0],F=A.O[1]+V[0]*A.u[1]+V[1]*A.v[1],D=A.O[2]+V[0]*A.u[2]+V[1]*A.v[2],H=w-y.O[0],K=F-y.O[1],Q=D-y.O[2],ne=H*y.u[0]+K*y.u[1]+Q*y.u[2],ee=H*y.v[0]+K*y.v[1]+Q*y.v[2];ne<v&&(v=ne),ne>_&&(_=ne),ee<I&&(I=ee),ee>O&&(O=ee)}if(v<=x&&_>=S&&I<=P&&O>=C){let V=Math.max(0,S-x)*Math.max(0,C-P);if(Math.max(0,_-v)*Math.max(0,O-I)>V*2)continue;h.add(g);break}}}return f=f.filter((g,y)=>!h.has(y)),f}function Sg(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:s,cameraRot:i,ambientLight:c,directionalLight:a,shadow:l}=e,u=Math.hypot(s[0],s[1],s[2])||1,f=s[0]/u,d=s[1]/u,m=s[2]/u,p=c?.color??"#ffffff",h=c?.intensity??.4,g=a?.intensity??1,y=l?.color??"#000000",b=l?.opacity??.25,x=l?.maxExtend??2e3,P=[],S=r.map(A=>{let M=A.edgeOwners;if(!M||A.selfShadowEdgeMap)return null;let E=A.casterPolygonCount??0;if(E<yc||A.items.length<yc)return null;let v=0;for(let O of A.items)O.planeN&&v++;if(v*2<A.items.length)return null;let I=new Array(E).fill(null);for(let O of A.items)O.planeN&&O.polygonIndex<E&&(I[O.polygonIndex]=O.planeN);let _=Ps(I,s);return Ms(M,_)}),C=(A,M,E,v)=>{if(A.length<3)return[];let I=[],_=V=>(V[0]-M[0])*E[0]+(V[1]-M[1])*E[1]+(V[2]-M[2])*E[2],O=(V,w,F,D)=>{let H=(F-v)/(F-D);return[V[0]+H*(w[0]-V[0]),V[1]+H*(w[1]-V[1]),V[2]+H*(w[2]-V[2])]};for(let V=0;V<A.length;V++){let w=A[V],F=A[(V+A.length-1)%A.length],D=_(w),H=_(F),K=D>v,Q=H>v;K?(Q||I.push(O(F,w,H,D)),I.push(w)):Q&&I.push(O(F,w,H,D))}return I},T={rotX:i.rotX,rotY:i.rotY};for(let A of n){let{O:M,n:E,u:v,v:I,outlineUv:_,minU:O,minV:V,width:w,height:F}=A,D=f*E[0]+d*E[1]+m*E[2];if(D<=1e-6||!Nt(E,T))continue;let H=ie=>(ie[0]-M[0])*E[0]+(ie[1]-M[1])*E[1]+(ie[2]-M[2])*E[2],K=(ie,ae,N,X)=>{let oe=N/(N-X);return[ie[0]+oe*(ae[0]-ie[0]),ie[1]+oe*(ae[1]-ie[1]),ie[2]+oe*(ae[2]-ie[2])]},Q=ie=>{let ae=ie[0]-M[0],N=ie[1]-M[1],X=ie[2]-M[2],oe=(ae*E[0]+N*E[1]+X*E[2])/D,Te=ie[0]-oe*f,Ce=ie[1]-oe*d,Pe=ie[2]-oe*m,_e=Te-M[0],Oe=Ce-M[1],Ve=Pe-M[2];return[_e*v[0]+Oe*v[1]+Ve*v[2],_e*I[0]+Oe*I[1]+Ve*I[2]]},ne=new Map,ee=0,ue=O,U=V,$=A.minU+w,k=A.minV+F,L=1/0,W=1/0,Y=-1/0,se=-1/0;for(let ie of r)for(let ae of ie.items)for(let N of ae.wv){let X=N[0]-M[0],oe=N[1]-M[1],Te=N[2]-M[2],Ce=X*v[0]+oe*v[1]+Te*v[2],Pe=X*I[0]+oe*I[1]+Te*I[2];Ce<L&&(L=Ce),Ce>Y&&(Y=Ce),Pe<W&&(W=Pe),Pe>se&&(se=Pe)}let Z=Number.isFinite(L)?[[L-x,W-x],[Y+x,W-x],[Y+x,se+x],[L-x,se+x]]:[],B=.05,q=E[0]*M[0]+E[1]*M[1]+E[2]*M[2],me=.0025,fe=5;for(let ie=0;ie<r.length;ie++){let ae=r[ie],N=ae.selfShadowEdgeMap,X=S[ie];if(X!==null){if(X.length===0)continue;for(let oe of X){if(oe.length<3)continue;let Te=C(oe,M,E,B);if(Te.length<3)continue;let Ce=Te.map(Q),Pe=yn(Ce),_e=Z.length===4?Cn(Pe,Z):Pe;if(_e.length<3)continue;let Oe=Cn(_e,_);if(Oe.length<3)continue;let Ve;for(let $e of A.memberPolysUv){let Ee=Cn(Oe,yn($e));Ee.length<3||(Ve||(Ve=ne.get(ae.id),Ve||(Ve={id:ae.id,verts:[],subPolygonIndices:[]},ne.set(ae.id,Ve))),Ve.verts.push(Ee),Ve.subPolygonIndices.push(-1),ee++)}}continue}for(let oe of ae.items){if(N){let Ee=N.get(oe.polygonIndex);if(Ee){let Fe=!1;for(let we of A.memberPolyIndices)if(Ee.has(we)){Fe=!0;break}if(Fe)continue}}if(oe.planeN&&oe.planeN[0]*f+oe.planeN[1]*d+oe.planeN[2]*m>-1e-6)continue;if(oe.planeN){let Ee=oe.planeN,Fe=Ee[0]*E[0]+Ee[1]*E[1]+Ee[2]*E[2];if(Math.abs(Fe)>1-me){let we=Fe>0?1:-1;if(Math.abs(oe.planeOffset-we*q)<fe)continue}}let Te=oe.bboxCorners,Ce=!1,Pe=1/0,_e=1/0,Oe=-1/0,Ve=-1/0;for(let Ee=0;Ee<8;Ee++){let Fe=Te[Ee];H(Fe)>B&&(Ce=!0);let we=Q(Fe);we[0]<Pe&&(Pe=we[0]),we[0]>Oe&&(Oe=we[0]),we[1]<_e&&(_e=we[1]),we[1]>Ve&&(Ve=we[1])}if(!Ce||Oe<ue||Pe>$||Ve<U||_e>k)continue;let $e=oe.wv;for(let Ee=1;Ee<$e.length-1;Ee++){let Fe=$e[0],we=$e[Ee],Xn=$e[Ee+1],Yn=H(Fe),un=H(we),Qe=H(Xn),fn=[],Be=[[Fe,Yn],[we,un],[Xn,Qe]];for(let Ye=0;Ye<3;Ye++){let[ve,Je]=Be[Ye],[sn,en]=Be[(Ye+1)%3],We=Je>B,an=en>B;We&&fn.push(ve),We!==an&&fn.push(K(ve,sn,Je,en))}if(fn.length<3)continue;let Xe=fn.map(Q),Me=yn(Xe),Re=Z.length===4?Cn(Me,Z):Me;if(Re.length<3)continue;let Le=Cn(Re,_);if(Le.length<3)continue;let Ie;for(let Ye of A.memberPolysUv){let ve=Cn(Le,yn(Ye));if(!(ve.length<3)){if(N){let Je=0,sn=1/0,en=-1/0,We=1/0,an=-1/0;for(let cn=0;cn<ve.length;cn++){let je=ve[cn],jn=ve[(cn+1)%ve.length];Je+=je[0]*jn[1]-jn[0]*je[1],je[0]<sn&&(sn=je[0]),je[0]>en&&(en=je[0]),je[1]<We&&(We=je[1]),je[1]>an&&(an=je[1])}if(Math.abs(Je)*.5<5)continue}Ie||(Ie=ne.get(ae.id),Ie||(Ie={id:ae.id,verts:[],subPolygonIndices:[]},ne.set(ae.id,Ie))),Ie.verts.push(ve),Ie.subPolygonIndices.push(oe.polygonIndex),ee++}}}}}if(ee===0||!(w>0)||!(F>0))continue;let G=b;if(o){let ae=g*Math.max(0,D)+Math.max(0,h);if(ae>0){let N=Math.max(0,h)/ae,X=Math.pow(N,1/2.4);G=b*(1-X)}else G=0}let te=A.memberPolyIndices[0]??0,ce=t[te]?.color??"#cccccc",ye=o?y:Un(ce,0,"#000000",p,h),he=1/0,be=1/0,ge=-1/0,Se=-1/0;for(let ie of ne.values())for(let ae of ie.verts)for(let N of ae)N[0]<he&&(he=N[0]),N[0]>ge&&(ge=N[0]),N[1]<be&&(be=N[1]),N[1]>Se&&(Se=N[1]);he=Math.floor(he-1),be=Math.floor(be-1),ge=Math.ceil(ge+1),Se=Math.ceil(Se+1),he<O&&(he=O),be<V&&(be=V),ge>O+w&&(ge=O+w),Se>V+F&&(Se=V+F);let De=ge-he,R=Se-be;if(!(De>0)||!(R>0))continue;let z=A.lift,j=M[0]+he*v[0]+be*I[0]+z*E[0],J=M[1]+he*v[1]+be*I[1]+z*E[1],le=M[2]+he*v[2]+be*I[2]+z*E[2],pe=`matrix3d(${[v[0],v[1],v[2],0,I[0],I[1],I[2],0,E[0],E[1],E[2],0,j,J,le,1].map(ie=>ie.toFixed(4)).join(",")})`,xe=[];for(let ie of ne.values()){let ae="";for(let N of ie.verts){ae+=`M${(N[0][0]-he).toFixed(1)},${(N[0][1]-be).toFixed(1)}`;for(let X=1;X<N.length;X++)ae+=`L${(N[X][0]-he).toFixed(1)},${(N[X][1]-be).toFixed(1)}`;ae+="Z"}xe.push({casterId:ie.id,d:ae,casterPolygonIndices:ie.subPolygonIndices})}P.push({faceIndex:A.faceIndex,memberPolyIndices:A.memberPolyIndices,matrixCss:pe,width:De,height:R,fill:ye,opacity:G,paths:xe})}return P}var Cg=Symbol.for("polycss.animation.triangleFrameSource"),Eg=Symbol.for("polycss.animation.triangleFrameTarget"),bc=2200,Ss=2201,xc=2202;function Tg(e,n){let t=0,o=1,r=1,s=Ss,i=1/0,c=0,a=!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 a},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return a=!0,d},stop(){return a=!1,t=0,c=0,l=null,d},reset(){return t=0,c=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 s=m,i=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 a},get loopMode(){return s},get repetitions(){return i},get completedReps(){return c},set completedReps(m){c=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!a)return;if(l){l.elapsed+=m;let h=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(o=l.from+(l.to-l.from)*h,h>=1&&(o=l.to,l=null,o<=0)){a=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(t+=m*r,s===bc)t>=p&&(t=d.clampWhenFinished?p:0,a=!1);else if(s===Ss){if(t>=p){let h=t%p,g=Math.floor(t/p);c+=g,t=h,i!==1/0&&c>=i&&(t=d.clampWhenFinished?p:0,a=!1)}}else if(p>0){let h=p*2,g=t%h;if(t>=h){let y=Math.floor(t/h);c+=y,i!==1/0&&c>=i?(t=d.clampWhenFinished?p:0,a=!1):t=g}}}},sampleTime(){if(s===xc){let m=e.duration,p=m*2,h=t%p;return h<=m?h:p-h}return t}},d}function vg(e){return e._internal}function As(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function Ig(e,n){let t=new Map,o=n,r=e;function s(f){let d=As(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=Tg(d,n),t.set(d.index,m)),m}function i(f){let d=As(n.clips,f);return d?t.get(d.index)??null:null}function c(f){let d=[];for(let y of t.values()){let b=vg(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[Cg]?.(b.name,x);if(P&&r[Eg]?.(P))return;let S=n.sample(b.name,x);e.setPolygons(S);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})),h=p[0].polygons;if(h.length===0)return;let g=h.map((y,b)=>{let x=y.vertices.map((P,S)=>{let C=0,T=0,A=0;for(let{polygons:M,weight:E}of p){let v=M[b];if(!v)continue;let I=v.vertices[S];I&&(C+=I[0]*E,T+=I[1]*E,A+=I[2]*E)}return[C,T,A]});return{...y,vertices:x}});e.setPolygons(g)}function a(){for(let f of t.values())f.stop()}function l(f){let d=As(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:s,existingAction:i,update:c,stopAllAction:a,uncacheClip:l,uncacheRoot:u}}var Es={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Cc={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},_g={0:"POINTS",1:"LINES",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN"},Ts=["EXT_meshopt_compression","KHR_meshopt_compression"];function Og(e){return e===5120||e===5121||e===5122||e===5123}function Ec(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Vg(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 i=decodeURIComponent(o),c=new Uint8Array(i.length);for(let a=0;a<i.length;a++)c[a]=i.charCodeAt(a)&255;return c}let r=globalThis.atob(o),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s}function Rg(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,s=null;for(;o<e.byteLength;){let i=n.getUint32(o,!0),c=n.getUint32(o+4,!0),a=o+8;if(c===1313821514){let l=new Uint8Array(e,a,i);r=JSON.parse(Ec(l))}else c===5130562&&(s=new Uint8Array(e,a,i));o=a+i}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:s}}function Pc(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function Lg(e){let n=Pc(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=Pc(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 wg(e,n,t){let o=e.buffers??[],r=new Set(e.extensionsRequired??[]),s=Ts.some(i=>r.has(i));return o.map((i,c)=>{let a=i.uri;if(a){if(a.startsWith("data:"))return Vg(a);if(t){let l=t(a);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 "${a}" \u2014 provide options.resolveBuffer`)}if(c===0&&n)return n;if(s&&Ts.some(l=>i.extensions?.[l]))return new Uint8Array(0);throw new Error(`parseGltf: buffer[${c}] has no uri and no GLB BIN chunk`)})}function Ut(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 s=o.byteOffset??0;if(s<0||o.byteLength<0||s+o.byteLength>r.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${o.buffer}`);return{buffer:r,view:o}}function Tc(e,n,t,o){if(e.count<=0)return;let r=e.byteOffset??0,s=r+t*(e.count-1)+o;if(r<0||s>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function vc(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function Ng(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 No(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Es[o.componentType],s=Cc[o.type];if(!r||!s)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);if(o.sparse||o.normalized||o.bufferView===void 0){let{values:g}=Gt(e,n,t);return{array:Ng(o.componentType,g,o.normalized),count:o.count,componentCount:s}}let{buffer:i,view:c}=Ut(e,n,o.bufferView),a=(c.byteOffset??0)+(o.byteOffset??0),l=o.count*s,u=r*s,f=vc(c,u);if(Tc(o,c,f,u),f===u){let g=i.buffer.slice(i.byteOffset+a,i.byteOffset+a+l*r),y;switch(o.componentType){case 5120:y=new Int8Array(g);break;case 5121:y=new Uint8Array(g);break;case 5122:y=new Int16Array(g);break;case 5123:y=new Uint16Array(g);break;case 5125:y=new Uint32Array(g);break;case 5126:y=new Float32Array(g);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}return{array:y,count:o.count,componentCount:s}}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(i.buffer),p=i.byteOffset+a,h=0;for(let g=0;g<o.count;g++){let y=p+g*f;for(let b=0;b<s;b++)d[h++]=Bo(m,y+b*r,o.componentType)}return{array:d,count:o.count,componentCount:s}}function Bo(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 Mc(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 Gt(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Es[o.componentType],s=Cc[o.type];if(!r||!s)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);let i=r*s,c=new Array(o.count*s).fill(0);if(o.bufferView!==void 0){let{buffer:a,view:l}=Ut(e,n,o.bufferView),u=a.byteOffset+(l.byteOffset??0)+(o.byteOffset??0),f=vc(l,i);Tc(o,l,f,i);let d=new DataView(a.buffer),m=0;for(let p=0;p<o.count;p++){let h=u+p*f;for(let g=0;g<s;g++){let y=Bo(d,h+g*r,o.componentType);c[m++]=o.normalized?Mc(y,o.componentType):y}}}if(o.sparse){let a=o.sparse,l=a.indices,u=Es[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}=Ut(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),p=new DataView(f.buffer),{buffer:h,view:g}=Ut(e,n,a.values.bufferView),y=h.byteOffset+(g.byteOffset??0)+(a.values.byteOffset??0),b=new DataView(h.buffer);for(let x=0;x<a.count;x++){let P=Bo(p,m+x*u,l.componentType);for(let S=0;S<s;S++){let C=Bo(b,y+(x*s+S)*r,o.componentType);c[P*s+S]=o.normalized?Mc(C,o.componentType):C}}}return{values:c,count:o.count,componentCount:s}}function Dg(e,n,t){let o=[],r=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(t&&!i.uri.startsWith("data:"))try{o.push(new s.URL(i.uri,t).href)}catch{o.push(i.uri)}else o.push(i.uri);continue}if(i.bufferView!==void 0){let c;try{let{buffer:f,view:d}=Ut(e,n,i.bufferView),m=d.byteOffset??0;c=f.subarray(m,m+d.byteLength)}catch{o.push("");continue}let a=i.mimeType??"image/png",l=new s.Blob([c],{type:a}),u=s.URL.createObjectURL(l);o.push(u),r.push(u)}else o.push("")}return{urls:o,objectUrls:r}}function Ac(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function Fg(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:Ac(t?.wrapS),t:Ac(t?.wrapT)}}function Ic(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function Bg(e,n){let t=new Map,o=e.materials??[];for(let r=0;r<o.length;r++){let s=o[r].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s],c=i?.source;if(c===void 0)continue;let a=n[c];a&&t.set(r,{url:a,wrap:Fg(e,i),alphaMode:Ic(o[r].alphaMode),texCoord:o[r].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function kg(e,n,t){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let r=a=>Math.max(0,Math.min(1,a)),s=a=>Math.round(r(a)*255).toString(16).padStart(2,"0"),i=a=>Math.round(r(a)*255),c=t==="opaque"?1:r(o[3]??1);return c<1?`rgba(${i(o[0])}, ${i(o[1])}, ${i(o[2])}, ${Math.round(c*1e3)/1e3})`:`#${s(o[0])}${s(o[1])}${s(o[2])}`}var ft=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function _c(e,n){let t=new Array(16);return Oc(t,e,n)}function Oc(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 Do(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 Vc(e,n,t){let o=e?.[0]??0,r=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,c=n?.[1]??0,a=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=i+i,p=c+c,h=a+a,g=i*m,y=i*p,b=i*h,x=c*p,P=c*h,S=a*h,C=l*m,T=l*p,A=l*h;return[(1-(x+S))*u,(y+A)*u,(b-T)*u,0,(y-A)*f,(1-(g+S))*f,(P+C)*f,0,(b+T)*d,(P-C)*d,(1-(g+x))*d,0,o,r,s,1]}function Ug(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Vc(e.translation,e.rotation,e.scale)}function Rc(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 kt(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 Gg(e,n,t){let o=kt(e),r=kt(n),s=o[0]*r[0]+o[1]*r[1]+o[2]*r[2]+o[3]*r[3];if(s<0&&(s=-s,r=[-r[0],-r[1],-r[2],-r[3]]),s>.9995)return kt(Rc(o,r,t));let i=Math.acos(Math.max(-1,Math.min(1,s))),c=Math.sin(i),a=Math.sin((1-t)*i)/c,l=Math.sin(t*i)/c;return kt([o[0]*a+r[0]*l,o[1]*a+r[1]*l,o[2]*a+r[2]*l,o[3]*a+r[3]*l])}function Lc(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 wc(e){return e.matrix?e.matrix.slice():Vc(e.translation,e.rotation,e.scale)}function zg(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function Nc(e,n){let t=e.nodes??[],o=new Array(t.length),r=new Set,s=new Set,i=(a,l)=>{if(a<0||a>=t.length||s.has(a))return;let u=_c(l,n[a]??ft);o[a]=u,r.add(a),s.add(a);for(let f of t[a].children??[])i(f,u);s.delete(a)},c=zg(e);if(c.length>0)for(let a of c)i(a,ft);for(let a=0;a<t.length;a++)r.has(a)||i(a,ft);return o}var Dc=Symbol("polycss.gltfAnimationRuntimeInfo"),$g=Symbol.for("polycss.animation.triangleFrameSource");function Fc(e,n){return e?e[Dc]?.withPolygonFilter(n):void 0}function Cs(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Xg(e,n,t){return Cs(e,n)||Cs(e,t)||Cs(n,t)}function Sc(e,n,t,o,r){if(t===void 0)return;let{values:s,count:i,componentCount:c}=Gt(e,n,t);if(i!==r||c<1)return;let a=[];for(let l=0;l<i;l++){let u=[];for(let f=0;f<o;f++)u.push(s[l*c+f]??0);a.push(u)}return a}function Yg(e,n,t,o){if(t===void 0)return Array.from({length:o},()=>ft.slice());let{values:r,componentCount:s,count:i}=Gt(e,n,t);if(s!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${t} is not MAT4`);let c=[];for(let a=0;a<o;a++){let l=Math.min(a,i-1);c.push(r.slice(l*16,l*16+16))}return c}function Fo(e,n){let t=e.componentCount,o=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(o,o+t)}function Wg(e,n,t){let o=e.input;if(o.length===0)return[];if(o.length===1||n<=o[0])return Fo(e,0);let r=o.length-1;if(n>=o[r])return Fo(e,r);let s=0,i=r;for(;s+1<i;){let d=s+i>>1;o[d]<=n?s=d:i=d}let c=o[s],a=o[s+1],l=a>c?(n-c)/(a-c):0,u=Fo(e,s),f=Fo(e,s+1);return e.interpolation==="STEP"?u:t==="rotation"?Gg(u,f,l):Rc(u,f,l)}function Bc(e,n){let t=[];for(let o=0;o<(e.animations?.length??0);o++){let r=e.animations[o],s=(r.samplers??[]).map(a=>{let l=Gt(e,n,a.input),u=Gt(e,n,a.output);return{input:l.values,output:u.values,componentCount:u.componentCount,interpolation:a.interpolation??"LINEAR"}}),i=[];for(let a of r.channels??[]){let l=a.target.node,u=a.target.path,f=s[a.sampler];l===void 0||!u||!f||u!=="translation"&&u!=="rotation"&&u!=="scale"||i.push({sampler:f,targetNode:l,path:u})}let c=i.reduce((a,l)=>{let u=l.sampler.input;return Math.max(a,u[u.length-1]??0)},0);t.push({info:{index:o,name:r.name??`animation_${o}`,duration:c,channelCount:i.length},channels:i})}return t}function kc(e,n,t,o){let r=t.info.duration,s=r>0?(o%r+r)%r:Math.max(0,o),i=n.map(c=>({translation:c.translation.slice(),rotation:c.rotation.slice(),scale:c.scale.slice(),matrix:c.matrix?c.matrix.slice():void 0}));for(let c of t.channels){let a=i[c.targetNode];if(!a)continue;let l=Wg(c.sampler,s,c.path);a.matrix=void 0,c.path==="translation"?a.translation=l.slice(0,3):c.path==="rotation"?a.rotation=kt(l.slice(0,4)):c.path==="scale"&&(a.scale=l.slice(0,3))}return Nc(e,i.map(wc))}function jg(e,n,t,o,r,s){if((e.animations??[]).length===0||t.length===0)return;let c=(e.nodes??[]).map(g=>Lc(g)),a=c.map(wc),l=Nc(e,a),u=(e.skins??[]).map(g=>({joints:g.joints??[],inverseBindMatrices:Yg(e,n,g.inverseBindMatrices,g.joints?.length??0)})),f=Bc(e,n),d=f.map(g=>g.info);if(d.length===0)return;let m=g=>{let y=t.map(b=>new Array(b.triangleMask.length).fill(!1));for(let b of g){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],S=new Set,C=0;for(let T=0;T+2<P.indices.length;T+=3,C++)b[C]&&(S.add(P.indices[T]),S.add(P.indices[T+1]),S.add(P.indices[T+2]));return{triangleMask:b,activeVertices:Array.from(S).sort((T,A)=>T-A)}})},p=(g,y,b,x,P,S,C,T,A)=>{let M=r(g),E=r(y),v=r(b),I={vertices:[M,E,v],color:x};return P&&(I.texture=P),P&&S&&(I.textureWrap=S),P&&C&&(I.textureAlphaMode=C),T&&(I.doubleSided=!0),A&&(I.uvs=A),I},h=g=>{let y=t.reduce((_,O,V)=>{let w=g?.[V]?.triangleMask??O.triangleMask,F=0;for(let D=0;D<w.length;D++)w[D]&&F++;return _+F},0),b=new Float64Array(Math.max(0,y*9)),x=new Array(y),P=new Array(y).fill(!1),S={polygonCount:0,vertices:b,colors:x,textureFlags:P,solidTriangles:!0},C=t.map(_=>new Array(_.positions.length)),T=u.map(_=>_.joints.map(()=>new Array(16))),A=(_,O)=>{let V=typeof _=="number"?f[_]:f.find(w=>w.info.name===_);return V?kc(e,c,V,O):null},M=(_,O,V,w)=>{let F=V?.activeVertices,D=C[_],H=(K,Q,ne,ee)=>{let ue=D[K];ue?(ue[0]=Q,ue[1]=ne,ue[2]=ee):D[K]=[Q,ne,ee]};if(O.skinIndex!==void 0&&O.joints&&O.weights&&u[O.skinIndex]){let K=u[O.skinIndex],Q=O.joints,ne=O.weights,ee=T[O.skinIndex]??[];for(let U=0;U<K.joints.length;U++){let $=K.joints[U],k=w[$],L=K.inverseBindMatrices[U],W=ee[U]??(ee[U]=new Array(16));ee[U]=k&&L?Oc(W,k,L):void 0}let ue=U=>{let $=O.positions[U],k=0,L=0,W=0,Y=0,se=Q[U]??[],Z=ne[U]??[];for(let B=0;B<4;B++){let q=Z[B]??0;if(q<=0)continue;let me=Math.round(se[B]??0),fe=ee[me];if(!fe)continue;let G=fe[0]*$[0]+fe[4]*$[1]+fe[8]*$[2]+fe[12],te=fe[1]*$[0]+fe[5]*$[1]+fe[9]*$[2]+fe[13],ce=fe[2]*$[0]+fe[6]*$[1]+fe[10]*$[2]+fe[14];k+=G*q,L+=te*q,W+=ce*q,Y+=q}if(Y>0){let B=1/Y;H(U,k*B,L*B,W*B)}else H(U,O.meshBindWorld[0]*$[0]+O.meshBindWorld[4]*$[1]+O.meshBindWorld[8]*$[2]+O.meshBindWorld[12],O.meshBindWorld[1]*$[0]+O.meshBindWorld[5]*$[1]+O.meshBindWorld[9]*$[2]+O.meshBindWorld[13],O.meshBindWorld[2]*$[0]+O.meshBindWorld[6]*$[1]+O.meshBindWorld[10]*$[2]+O.meshBindWorld[14])};if(F)for(let U of F)ue(U);else for(let U=0;U<O.positions.length;U++)ue(U)}else{let K=O.meshNode!==null?w[O.meshNode]??O.meshBindWorld:O.meshBindWorld,Q=ne=>{let ee=O.positions[ne];H(ne,K[0]*ee[0]+K[4]*ee[1]+K[8]*ee[2]+K[12],K[1]*ee[0]+K[5]*ee[1]+K[9]*ee[2]+K[13],K[2]*ee[0]+K[6]*ee[1]+K[10]*ee[2]+K[14])};if(F)for(let ne of F)Q(ne);else for(let ne=0;ne<O.positions.length;ne++)Q(ne)}return D},E=(_,O)=>{let V=A(_,O);if(!V)return[];let w=[];for(let F=0;F<t.length;F++){let D=t[F],H=g?.[F],K=H?.triangleMask??D.triangleMask,Q=M(F,D,H,V),ne=0;for(let ee=0;ee+2<D.indices.length;ee+=3,ne++){if(!K[ne])continue;let ue=D.indices[ee],U=D.indices[ee+1],$=D.indices[ee+2],k=Q[ue],L=Q[U],W=Q[$];if(!k||!L||!W)continue;let Y;if(D.uvs&&D.texture){let Z=D.uvs[ue],B=D.uvs[U],q=D.uvs[$];Z&&B&&q&&(Y=[Z,B,q])}let se=p(k,L,W,D.color,D.texture,D.textureWrap,D.textureAlphaMode,D.doubleSided,Y);se&&w.push(se)}}return w},v=(_,O)=>{let V=A(_,O);if(!V)return null;b.length<y*9&&(b=new Float64Array(y*9),S.vertices=b),x.length<y&&(x=new Array(y),S.colors=x),P.length<y&&(P=new Array(y).fill(!1),S.textureFlags=P);let w=0,F=0,D=!1;for(let H=0;H<t.length;H++){let K=t[H],Q=g?.[H],ne=Q?.triangleMask??K.triangleMask,ee=M(H,K,Q,V),ue=0;for(let U=0;U+2<K.indices.length;U+=3,ue++){if(!ne[ue])continue;let $=K.indices[U],k=K.indices[U+1],L=K.indices[U+2],W=ee[$],Y=ee[k],se=ee[L];if(!W||!Y||!se)continue;s(W,b,F),s(Y,b,F+3),s(se,b,F+6),x[w]=K.color;let Z=!!K.texture;P[w]=Z,Z&&(D=!0),w++,F+=9}}return S.polygonCount=w,S.solidTriangles=!D,S},I={clips:d,sample:E};return I[$g]=v,I[Dc]={withPolygonFilter(_){let O=m(_);return O?h(O):void 0}},I};return h()}function vs(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.materialColors??{},s=n?.materialTextures??{},i=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,c=i.byteLength,a,l=null;if(i.byteLength>=4&&new DataView(i).getUint32(0,!0)===1179937895){let R=Rg(i);a=R.doc,l=R.bin}else a=JSON.parse(Ec(new Uint8Array(i)));Lg(a);let u=wg(a,l,n?.resolveBuffer),{urls:f,objectUrls:d}=Dg(a,u,n?.baseUrl),m=Bg(a,f),p=[],h=new Set,g=new Set(a.extensionsRequired??[]),y=g.has("KHR_mesh_quantization")||(a.extensionsUsed??[]).includes("KHR_mesh_quantization");function b(R,z){h.has(R)||(h.add(R),p.push(z))}function x(R,z){if(R===void 0)return!1;let j=a.accessors?.[R];if(!j)return!1;let J=le=>a.bufferViews?.[le]?.extensions?.[z]!==void 0;return!!(j.bufferView!==void 0&&J(j.bufferView)||j.sparse&&(J(j.sparse.indices.bufferView)||J(j.sparse.values.bufferView)))}function P(R){for(let z of Ts)if(g.has(z)&&(R.extensions?.[z]||x(R.indices,z)||Object.values(R.attributes??{}).some(j=>x(j,z))))return z}function S(R,z){if(z instanceof Float32Array)return!0;let j=a.accessors?.[R];return y&&j?.type==="VEC3"&&Og(j.componentType)}function C(R,z){return(z!==null?a.nodes?.[z]?.weights:void 0)??R.weights??[]}function T(R,z,j,J,le){let re=j.targets;if(!re||re.length===0)return;let pe=C(R,J);if(!pe.some(ae=>Number.isFinite(ae)&&ae!==0))return;let xe=Array.from({length:le},()=>[0,0,0]),ie=!1;for(let ae=0;ae<re.length;ae++){let N=pe[ae]??0;if(!Number.isFinite(N)||N===0)continue;let X=re[ae]?.POSITION;if(X===void 0)continue;let{array:oe,count:Te,componentCount:Ce}=No(a,u,X);if(Te!==le||Ce<3){b(`morph-position-count:${z}:${ae}`,`Mesh ${R.name??z}: skipped morph target ${ae} POSITION with mismatched count`);continue}if(!S(X,oe)){b(`morph-position-type:${z}:${ae}`,`Mesh ${R.name??z}: skipped morph target ${ae} POSITION with unsupported accessor type`);continue}ie=!0;for(let Pe=0;Pe<le;Pe++){let _e=Pe*Ce,Oe=xe[Pe];Oe[0]+=Number(oe[_e])*N,Oe[1]+=Number(oe[_e+1])*N,Oe[2]+=Number(oe[_e+2])*N}}return ie?xe:void 0}let A=[],M=[],E=[],v=(a.meshes??[]).map((R,z)=>R.name??`mesh_${z}`),I=(a.materials??[]).map((R,z)=>R.name??`material_${z}`);function _(R,z){if(z===4)return R;let j=[];if(z===5)for(let J=0;J+2<R.length;J++)j.push(R[J],R[J+1+J%2],R[J+2-J%2]);else if(z===6)for(let J=0;J+2<R.length;J++)j.push(R[J+1],R[J+2],R[0]);return j}function O(R){let z=[];for(let j=0;j+2<R.length;j+=3){let J=R[j],le=R[j+1],re=R[j+2];z.push(J,le,re,J,re,le)}return z}function V(R,z,j){let J=a.meshes?.[R];if(J){if(!Array.isArray(J.primitives)){b(`malformed-primitives:${R}`,`Mesh ${J.name??R}: skipped mesh with non-array primitives`);return}for(let le=0;le<J.primitives.length;le+=1){let re=J.primitives[le];if(!re)continue;let pe=re.mode??4;if(pe!==4&&pe!==5&&pe!==6){let Me=_g[pe]??`mode ${pe}`;b(`unsupported-mode:${pe}`,`Skipped primitives with unsupported mode ${pe} (${Me})`);continue}if(re.extensions?.KHR_draco_mesh_compression&&g.has("KHR_draco_mesh_compression")){b("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}let xe=P(re);if(xe){b(xe,`Skipped primitives with unsupported required extension ${xe}`);continue}if(re.attributes.POSITION===void 0){b(`missing-position:${R}`,`Mesh ${J.name??R}: skipped primitive without POSITION attribute`);continue}let ie=re.material!==void 0?a.materials?.[re.material]:void 0,ae=Ic(ie?.alphaMode),N=ie?.name,oe=(N?r[N]:void 0)??kg(ie,o,ae),Te=ie?.doubleSided===!0,Ce=re.material!==void 0?m.get(re.material):void 0,Pe=N&&s[N]?s[N]:re.material!==void 0?Ce?.url:void 0,_e=Pe&&re.material!==void 0?Ce?.wrap:void 0,Oe=Pe?Ce?.alphaMode??ae:void 0,Ve=Pe?Ce?.texCoord??0:0,$e=re.attributes.POSITION,{array:Ee,count:Fe,componentCount:we}=No(a,u,$e);if(!S($e,Ee))continue;let Xn=T(J,R,re,j,Fe),Yn=[],un=[];for(let Me=0;Me<Fe;Me++){let Re=Me*we,Le=Xn?.[Me],Ie=[Number(Ee[Re])+(Le?.[0]??0),Number(Ee[Re+1])+(Le?.[1]??0),Number(Ee[Re+2])+(Le?.[2]??0)];Yn.push(Ie),un.push(Do(z,Ie))}let Qe=null,fn=re.attributes[`TEXCOORD_${Ve}`];if(Pe&&fn!==void 0){let{array:Me,count:Re}=No(a,u,fn);Qe=[];let Le=1;Me instanceof Uint8Array?Le=1/255:Me instanceof Uint16Array&&(Le=1/65535);for(let Ie=0;Ie<Re;Ie++){let Ye=Me[Ie*2]*Le,ve=Me[Ie*2+1]*Le;Qe.push([Ye,1-ve])}}let Be;if(re.indices!==void 0){let{array:Me,count:Re}=No(a,u,re.indices);Be=[];for(let Le=0;Le<Re;Le++)Be.push(Number(Me[Le]))}else Be=un.map((Me,Re)=>Re);Be=_(Be,pe),Te&&(Be=O(Be));let Xe;if((a.animations?.length??0)>0){let Me=Sc(a,u,re.attributes.JOINTS_0,4,Fe),Re=Sc(a,u,re.attributes.WEIGHTS_0,4,Fe);Xe={sourceIndex:M.length,meshNode:j,meshBindWorld:z,skinIndex:j!==null?a.nodes?.[j]?.skin:void 0,positions:Yn,indices:Be,triangleMask:[],color:oe,texture:Pe,textureWrap:_e,textureAlphaMode:Oe,doubleSided:Te,uvs:Qe??void 0,joints:Me,weights:Re},M.push(Xe)}for(let Me=0;Me+2<Be.length;Me+=3){let Re=Be[Me],Le=Be[Me+1],Ie=Be[Me+2],Ye=Xe?Xe.triangleMask.length:void 0;Xe&&Xe.triangleMask.push(!1);let ve=un[Re],Je=un[Le],sn=un[Ie];if(!ve||!Je||!sn)continue;let en;if(Qe&&Pe){let an=Qe[Re],Wn=Qe[Le],cn=Qe[Ie];an&&Wn&&cn&&(en=[an,Wn,cn])}let We=`${R}:${le}:${j??"root"}`;A.push({v0:ve,v1:Je,v2:sn,color:oe,texture:Pe,textureWrap:_e,textureAlphaMode:Oe,doubleSided:Te,uvs:en,simplifySourceVertexKeys:[`${We}:${Re}`,`${We}:${Le}`,`${We}:${Ie}`],source:Xe,sourceIndex:Xe?.sourceIndex,sourceTriangleIndex:Ye})}}}}function w(R,z,j){if(j.has(R)){b(`recursive-node:${R}`,`Skipped recursive node reference ${R} in glTF scene graph`);return}let J=a.nodes?.[R];if(!J)return;let le=_c(z,Ug(J));typeof J.mesh=="number"&&V(J.mesh,le,R),j.add(R);for(let re of J.children??[])w(re,le,j);j.delete(R)}function F(R){let z=new Set,j=R.info.duration;for(let J of R.channels)for(let le of J.sampler.input)!Number.isFinite(le)||le<=0||j>0&&le>=j||z.add(le);return j>0&&(z.add(j*.25),z.add(j*.5),z.add(j*.75)),Array.from(z).sort((J,le)=>J-le).slice(0,128)}function D(R,z){let j=R.source;if(!j||R.sourceTriangleIndex===void 0||j.skinIndex!==void 0)return;let J=R.sourceTriangleIndex*3,le=j.indices[J],re=j.indices[J+1],pe=j.indices[J+2],xe=le!==void 0?j.positions[le]:void 0,ie=re!==void 0?j.positions[re]:void 0,ae=pe!==void 0?j.positions[pe]:void 0;if(!xe||!ie||!ae)return;let N=j.meshNode!==null?z[j.meshNode]??j.meshBindWorld:j.meshBindWorld;return{v0:Do(N,xe),v1:Do(N,ie),v2:Do(N,ae)}}function H(R,z){return R[0]===z[0]&&R[1]===z[1]&&R[2]===z[2]}function K(R){return H(R.v0,R.v1)||H(R.v0,R.v2)||H(R.v1,R.v2)}function Q(){return A.some(R=>!K(R))}function ne(){if(A.length===0||(a.animations?.length??0)===0||Q())return;let R=Bc(a,u);if(R.length===0)return;let z=(a.nodes??[]).map(J=>Lc(J)),j=new Array(A.length);for(let J of R)for(let le of F(J)){let re=kc(a,z,J,le);for(let pe=0;pe<A.length;pe++){if(j[pe])continue;let xe=D(A[pe],re);xe&&!K(xe)&&(j[pe]=xe)}}if(j.some(Boolean))for(let J=0;J<A.length;J++){let le=j[J];le&&(A[J].v0=le.v0,A[J].v1=le.v1,A[J].v2=le.v2)}}let ee=a.scene??0,ue=a.scenes?.[ee]?.nodes;if(ue&&ue.length>0)for(let R of ue)w(R,ft,new Set);else{(a.meshes?.length??0)===0&&b("no-gltf-meshes","No glTF meshes found");for(let R=0;R<(a.meshes?.length??0);R++)V(R,ft,null)}ne();let U=Kg(d);if(A.length===0)return{polygons:[],objectUrls:d,dispose:U,warnings:p,metadata:{triangleCount:0,meshes:v,materials:I,sourceBytes:c}};let $=1/0,k=1/0,L=1/0,W=-1/0,Y=-1/0,se=-1/0;for(let R of A)for(let z of[R.v0,R.v1,R.v2])z[0]<$&&($=z[0]),z[0]>W&&(W=z[0]),z[1]<k&&(k=z[1]),z[1]>Y&&(Y=z[1]),z[2]<L&&(L=z[2]),z[2]>se&&(se=z[2]);let Z=Math.max(W-$,Y-k,se-L),B=Z>0?t/Z:1,q=n?.center,me=q===!0||q==="center",fe=me?($+W)*.5:$,G=me?(k+Y)*.5:k,te=me?(L+se)*.5:L,ce=R=>Math.round(R*1e3)/1e3,ye=n?.upAxis??"y",he=ye==="z"?([R,z,j])=>[ce((R-fe)*B),ce((z-G)*B),ce((j-te)*B)]:([R,z,j])=>[ce((j-te)*B),ce((R-fe)*B),ce((z-G)*B)],be=ye==="z"?(R,z,j)=>{z[j]=ce((R[0]-fe)*B),z[j+1]=ce((R[1]-G)*B),z[j+2]=ce((R[2]-te)*B)}:(R,z,j)=>{z[j]=ce((R[2]-te)*B),z[j+1]=ce((R[0]-fe)*B),z[j+2]=ce((R[1]-G)*B)},ge=[],Se=0;for(let R of A){let z=he(R.v0),j=he(R.v1),J=he(R.v2),le=Xg(z,j,J);if(R.source&&R.sourceTriangleIndex!==void 0&&(R.source.triangleMask[R.sourceTriangleIndex]=!le),le){Se++;continue}let re={vertices:[z,j,J],color:R.color};R.texture&&(re.texture=R.texture),R.texture&&R.textureWrap&&(re.textureWrap=R.textureWrap),R.texture&&R.textureAlphaMode&&(re.textureAlphaMode=R.textureAlphaMode),R.doubleSided&&(re.doubleSided=!0),R.uvs&&(re.uvs=R.uvs),R.simplifySourceVertexKeys&&(re.simplifySourceVertexKeys=R.simplifySourceVertexKeys),ge.push(re),E.push(R.sourceIndex!==void 0&&R.sourceTriangleIndex!==void 0?{sourceIndex:R.sourceIndex,triangleIndex:R.sourceTriangleIndex}:void 0)}ge.length===0&&Se>0&&b("all-projected-triangles-degenerate","No non-degenerate glTF triangles remained after normalization");let De=jg(a,u,M,E,he,be);return{polygons:ge,animation:De,objectUrls:d,dispose:U,warnings:p,metadata:{triangleCount:ge.length,meshes:v,materials:I,animations:De?.clips,sourceBytes:c}}}function Kg(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 jc=Symbol("polycss.solidTextureBakedAnimationInfo"),Uc=Symbol.for("polycss.animation.triangleFrameSource"),Hg=16*1024*1024,Zg=2,qg=32,Qg=2,Jg=.08,e0=8,n0=128,Gc=32,t0=.045,o0=10,mt=6,r0=16;function Is(e){return e.material?.texture??e.texture}function s0(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function i0(e,n){return new Promise((t,o)=>{let r=new n,s=!1,i=c=>{s||(s=!0,c())};r.decoding="async",r.onload=()=>i(()=>t(r)),r.onerror=()=>i(()=>o(new Error(`texture load failed: ${e}`))),r.src=e})}async function a0(e,n,t){try{let o=await i0(e,n.Image),r=Math.max(0,Math.floor(o.naturalWidth||o.width||0)),s=Math.max(0,Math.floor(o.naturalHeight||o.height||0));if(r<=0||s<=0||r*s>t)return null;let i=n.createCanvas();i.width=r,i.height=s;let c=i.getContext("2d",{willReadFrequently:!0});if(!c)return null;c.drawImage(o,0,0,r,s);let a=c.getImageData(0,0,r,s).data;return{width:r,height:s,data:a,lowDetail:c0(r,s,a)}}catch{return null}}function zc(e,n,t,o,r,s){let i=(o*n+t)*4,c=(s*n+r)*4;return Math.max(Math.abs((e[i]??0)-(e[c]??0)),Math.abs((e[i+1]??0)-(e[c+1]??0)),Math.abs((e[i+2]??0)-(e[c+2]??0)))}function c0(e,n,t){let o=Math.max(1,Math.floor(Math.max(e,n)/n0)),r=0,s=0,i=0;for(let c=0;c<n;c+=o)for(let a=0;a<e;a+=o){if(a+o<e){let l=zc(t,e,a,c,a+o,c);i+=l,r++,l>Gc&&s++}if(c+o<n){let l=zc(t,e,a,c,a,c+o);i+=l,r++,l>Gc&&s++}}return r>0&&s/r<=t0&&i/r<=o0}function $c(e,n,t){return Math.max(n,Math.min(t,e))}function Xc(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 l0(e,n,t){let o=n[0],r=1-n[1],s=Xc(o,t?.s),i=Xc(r,t?.t);if(s===null||i===null)return null;let c=$c(Math.floor(s*e.width),0,e.width-1),l=($c(Math.floor(i*e.height),0,e.height-1)*e.width+c)*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 Tn(e,n,t,o,r,s){return[e[0]*o+n[0]*r+t[0]*s,e[1]*o+n[1]*r+t[1]*s]}function u0(e){let[n,t,o]=e;return[Tn(n,t,o,1/3,1/3,1/3),Tn(n,t,o,.8,.1,.1),Tn(n,t,o,.1,.8,.1),Tn(n,t,o,.1,.1,.8),Tn(n,t,o,.45,.45,.1),Tn(n,t,o,.45,.1,.45),Tn(n,t,o,.1,.45,.45)]}function f0(e){let[n,t,o]=e,r=u0(e);for(let s=1;s<mt;s++)for(let i=1;i<mt-s;i++){let c=mt-s-i;c<=0||r.push(Tn(n,t,o,s/mt,i/mt,c/mt))}return r}function Kc(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 _s(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 ko(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 Hc(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 s=t[1],i=c=>{let a=s.length<=4?s[c]+s[c]:s.slice(c*2,c*2+2);return parseInt(a,16)};return{r:i(0),g:i(1),b:i(2),a:s.length===4||s.length===8?i(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 m0(){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 Zc(e){return`${e.r},${e.g},${e.b},${e.a}`}function Yc(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=Zc(n),o=e.colors.get(t);e.colors.set(t,{color:n,count:(o?.count??0)+1}),e.count++}function Wc(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 d0(e){if(e.count<e0||e.colors.size<=1||e.colors.size>Qg)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*Jg));return t<=o?n.color:null}function p0(e,n,t,o){let r=Kc(e);if(r.length===0)return null;let s=m0(),i=e.textureAlphaMode==="opaque"?Hc(e.color):null;for(let c of r)for(let a of f0(c.uvs)){let l=l0(n,a,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){i&&Yc(s,{...i,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),Yc(s,l)}if(s.count===0)return e.textureAlphaMode==="opaque"&&e.color?e.color:null;if(e.textureAlphaMode==="opaque"&&s.max.a===0&&e.color)return e.color;if(_s(s.min,s.max,t))return ko(Wc(s));if(!o){let c=d0(s);if(c)return ko(c)}return o||!n.lowDetail||!_s(s.min,s.max,qg)?null:ko(Wc(s))}function qc(e,n){let{texture:t,textureWrap:o,textureAlphaMode:r,material:s,uvs:i,textureTriangles:c,...a}=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{...a,color:n,...u?{simplifyVertexKeys:u}:{},...f?{simplifySourceVertexKeys:f}:{}}}function g0(e,n){if(n.length<2)return e;let t=[],o=new Map;for(let l of n){let u=Hc(e[l]?.color);if(!u||u.a<255)continue;let f=Zc(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=[],s=new Map,i=[...o.entries()].sort((l,u)=>u[1].count-l[1].count||l[0].localeCompare(u[0]));for(let[l,u]of i){let f=null;for(let d of r)if(_s(u.color,d,r0)){f=d;break}f||(f=u.color,r.push(f)),s.set(l,ko(f))}let c=!1,a=e.slice();for(let l of t){let u=s.get(l.key),f=e[l.index];!u||!f||f.color===u||(a[l.index]={...f,color:u},c=!0)}return c?a:e}function h0(e,n){let t=e.slice();for(let o=0;o<n.length;o++){let r=n[o],s=e[r.index];s&&(t[r.index]=qc(s,r.color))}return t}function Qc(e){return e?e[jc]:void 0}async function Jc(e,n={}){if(n.enabled===!1)return null;let t=s0();if(!t)return null;let o=e.filter(a=>Is(a)&&Kc(a).length>0);if(o.length===0)return null;let r=n.maxTexturePixels??Hg,s=new Map;await Promise.all(Array.from(new Set(o.map(a=>Is(a)))).map(async a=>{s.set(a,await a0(a,t,r))}));let i=n.colorTolerance??Zg,c=n.colorTolerance!==void 0;return{bake(a){let l=!1,u=[],f=a.map((d,m)=>{let p=Is(d);if(!p)return d;let h=s.get(p);if(!h)return d;let g=p0(d,h,i,c);return g?(l=!0,u.push(m),qc(d,g)):d});return l?{polygons:g0(f,u),changed:!0,bakedIndices:u}:{polygons:a,changed:!1,bakedIndices:u}}}}async function y0(e,n={}){let t=await Jc(e,n);return t?t.bake(e).polygons:e}async function Os(e,n={}){let t=await Jc(e.polygons,n);if(!t)return e;let o=t.bake(e.polygons);if(!o.changed)return e;let r=[];for(let c of o.bakedIndices){let l=o.polygons[c].color;l&&r.push({index:c,color:l})}let s=e.animation,i=s&&{...s,sample(c,a){return h0(s.sample(c,a),r)}};if(i&&s){let c=s[Uc];if(c){let a=new Map(r.map(f=>[f.index,f.color])),l=[],u={polygonCount:0,vertices:new Float64Array(0),colors:l,solidTriangles:!1};i[Uc]=(f,d)=>{let m=c(f,d);if(!m)return m;l.length<m.polygonCount&&(l=new Array(m.polygonCount),u.colors=l);let p=m.textureFlags,h=m.solidTriangles===!0||!!p;for(let g=0;g<m.polygonCount;g++){let y=a.get(g);l[g]=y??m.colors?.[g],p?.[g]&&!y&&(h=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=p,u.solidTriangles=h,u}}i[jc]={source:s,bakedColorEntries:r}}return{...e,polygons:o.polygons,animation:i}}var el=Symbol.for("polycss.animation.triangleFrameSource");function b0(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 x0(e){let n=dn(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((r,s)=>t.set(r,s));let o=[];for(let r of n){let s=t.get(r);if(s===void 0)return[];let i=b0(e,s);if(!i)return[];o.push(i)}return o}function Vs(e,n,t=!1){let o=new Array(n.length);for(let r=0;r<n.length;r++){let s=n[r],i=s.sourceRefs,c=new Array(i.length/2);for(let l=0,u=0;l<i.length;l+=2,u++){let d=e[i[l]]?.vertices[i[l+1]];if(!d)return e;let m=d[0],p=d[1],h=d[2];if(!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(h))return e;c[u]=[m,p,h]}let a=t?s.rest.color:e[i[0]??-1]?.color??s.rest.color;o[r]={...s.rest,vertices:c,color:a}}return o}function P0(e,n){let t=new Map;return n.forEach((o,r)=>{t.set(o,r)}),e.map((o,r)=>({...o,sourceRefs:o.sourceRefs.map((s,i)=>i%2===0?t.get(s)??-1:s)}))}function M0(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],s=n[o];if(!r||r.vertices.length!==s.rest.vertices.length)return null;t[o]={...s.rest,vertices:r.vertices,color:s.rest.color}}return t}function A0(e){return!!(e.texture||e.material?.texture)}function S0(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=x0(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let o=Qc(e.animation),r=o?.source??e.animation,s=t.map(b=>b.originalIndex),i=Fc(r,s),c=i??r,a=i?P0(t,s):t,l=t.map(b=>b.rest.color),u=t.every(b=>b.rest.vertices.length===3&&!A0(b.rest)),f=i&&!o&&t.length===s.length&&t.every((b,x)=>b.rest.vertices.length===3&&b.sourceRefs.length===6&&b.sourceRefs[0]===s[x]&&b.sourceRefs[2]===s[x]&&b.sourceRefs[4]===s[x]),d=c[el],m=new Float64Array(t.length*9),p=l.slice(),h=new Array(t.length).fill(!1),g={polygonCount:t.length,vertices:m,colors:p,textureFlags:h,solidTriangles:u},y={...e.animation,sample(b,x){let P=c.sample(b,x);return f?P:i&&o?u&&t.length===s.length?M0(P,t)??Vs(P,a,!0):Vs(P,a,!0):Vs(P,a,!!o)}};return d&&u&&(y[el]=(b,x)=>{let P=d(b,x);if(!P)return P;if(i)return P.polygonCount<t.length||P.vertices.length<t.length*9?null:(g.polygonCount=t.length,g.vertices=P.vertices,g.colors=o?l:P.colors,g.textureFlags=o?h:P.textureFlags,g.solidTriangles=o?u:P.solidTriangles===!0,g);m.length<t.length*9&&(m=new Float64Array(t.length*9),g.vertices=m),p.length<t.length&&(p=new Array(t.length),g.colors=p),h.length<t.length&&(h=new Array(t.length).fill(!1),g.textureFlags=h);let S=u&&P.solidTriangles!==!1;for(let C=0;C<a.length;C++){let T=a[C],A=T.sourceRefs;for(let v=0,I=0;v<A.length;v+=2,I++){let _=A[v],O=A[v+1];if(_<0||_>=P.polygonCount)return null;let V=_*9+O*3,w=C*9+I*3;if(V+2>=P.vertices.length)return null;m[w]=P.vertices[V],m[w+1]=P.vertices[V+1],m[w+2]=P.vertices[V+2]}let M=A[0],E=!!P.textureFlags?.[M];h[C]=E,p[C]=o?T.rest.color:P.colors?.[M]??T.rest.color,!o&&E&&(S=!1)}return g.polygonCount=t.length,g.vertices=m,g.colors=p,g.textureFlags=h,g.solidTriangles=o?u:S,g}),{...e,polygons:t.map(b=>b.rest),animation:y,metadata:{...e.metadata,triangleCount:t.length}}}var C0=/^[0-9A-Fa-f]{6}$/,E0=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function T0(e){let n=[],t="";for(let o of e.split(`
|
|
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 Rs(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.palette??E0,s=n?.materialColors??{},i=n?.materialTextures??{},c=[],a=[],l=[],u=[],f=new Map,d=[],m=new Set,p=o,h,g=n?.includeObjects?new Set(n.includeObjects):null,y=n?.excludeObjects?new Set(n.excludeObjects):null,b=null,x=()=>b===null?g===null:!(g&&!g.has(b)||y&&y.has(b)),P=U=>U in s?s[U]:C0.test(U)?`#${U}`:(f.has(U)||(f.set(U,r[u.length%r.length]),u.push(U)),f.get(U)),S=(U,$)=>{m.has(U)||(m.add(U),d.push($))},C=(U,$)=>{let k=parseInt(U,10);return Number.isFinite(k)?k<0?$+k:k-1:NaN},T=T0(e);for(let U of T)if(!(U.length===0||U.charCodeAt(0)===35)){if(U.startsWith("v ")){let $=U.trim().split(/\s+/);c.push([parseFloat($[1]),parseFloat($[2]),parseFloat($[3])])}else if(U.startsWith("vt ")){let $=U.trim().split(/\s+/);a.push([parseFloat($[1]),parseFloat($[2])])}else if(U.startsWith("o "))b=U.trim().slice(2).trim();else if(U.startsWith("usemtl ")){let $=U.trim().split(/\s+/)[1];p=P($),h=i[$]}else if(U.startsWith("p "))x()&&S("unsupported-point-elements","Skipped OBJ point elements; PolyCSS only renders face polygons");else if(U.startsWith("l "))x()&&S("unsupported-line-elements","Skipped OBJ line elements; PolyCSS only renders face polygons");else if(U.startsWith("f ")){if(!x())continue;let $=U.trim().split(/\s+/).slice(1),k=[],L=[];for(let W of $){let Y=W.split("/");k.push(C(Y[0],c.length));let se=Y[1];if(se&&se.length>0){let Z=C(se,a.length);L.push(Number.isFinite(Z)?Z:null)}else L.push(null)}l.push({idx:k,uvIdx:L,color:p,texture:h})}}if(c.length===0||l.length===0)return v0(u,e.length,d);let A=new Set;for(let U of l)for(let $ of U.idx)A.add($);let M=1/0,E=1/0,v=1/0,I=-1/0,_=-1/0,O=-1/0;for(let U of A){let $=c[U];$&&($[0]<M&&(M=$[0]),$[0]>I&&(I=$[0]),$[1]<E&&(E=$[1]),$[1]>_&&(_=$[1]),$[2]<v&&(v=$[2]),$[2]>O&&(O=$[2]))}let V=Math.max(I-M,_-E,O-v),w=V>0?t/V:1,F=n?.center,D=F===!0||F==="center",H=D?(M+I)*.5:M,K=D?(E+_)*.5:E,Q=D?(v+O)*.5:v,ne=U=>Math.round(U*1e3)/1e3,ee=c.map(([U,$,k])=>[ne((k-Q)*w),ne((U-H)*w),ne(($-K)*w)]),ue=[];for(let{idx:U,uvIdx:$,color:k,texture:L}of l)for(let W=1;W<U.length-1;W++){let Y=U[0],se=U[W],Z=U[W+1],B=ee[Y],q=ee[se],me=ee[Z];if(!B||!q||!me||B[0]===q[0]&&B[1]===q[1]&&B[2]===q[2]||B[0]===me[0]&&B[1]===me[1]&&B[2]===me[2]||q[0]===me[0]&&q[1]===me[1]&&q[2]===me[2])continue;let fe;if(L){let te=$[0],ce=$[W],ye=$[W+1];if(te!=null&&ce!=null&&ye!=null){let he=a[te],be=a[ce],ge=a[ye];he&&be&&ge&&(fe=[he,be,ge])}}let G={vertices:[B,q,me],color:k};L&&(G.texture=L),fe&&(G.uvs=fe),ue.push(G)}return{polygons:ue,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:ue.length,materials:u,sourceBytes:e.length}}}function v0(e,n,t=[]){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:t,metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var Ls=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function ws(e){let n={},t={},o=null;for(let r of e.split(`
|
|
3
|
+
`)){let s=r.trim();if(!(s.length===0||s.charCodeAt(0)===35)){if(s.startsWith("newmtl ")){o=s.slice(7).trim();continue}if(o){if(s.startsWith("Kd ")){let i=s.split(/\s+/),c=parseFloat(i[1]),a=parseFloat(i[2]),l=parseFloat(i[3]);Number.isFinite(c)&&Number.isFinite(a)&&Number.isFinite(l)&&(n[o]=`#${Ls(c)}${Ls(a)}${Ls(l)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),c=i[i.length-1]?.replace(/\\+/g,"/");c&&c!=="map_Kd"&&(t[o]=c)}}}}return{colors:n,textures:t}}var I0=[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 _0(e){let n=e>>0&255,t=e>>8&255,o=e>>16&255;return[n,t,o]}function Ns(e){return(e&255).toString(16).padStart(2,"0")}function ol(e,n,t){return`#${Ns(e)}${Ns(n)}${Ns(t)}`}function O0(e,n,t,o){if(o>=255)return ol(e,n,t);let r=Math.round(Math.max(0,Math.min(255,o))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function rl(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 sl(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function nl(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),s=Math.min(n,t,o),i=r-s,c=0;return i!==0&&(r===n?c=60*((t-o)/i%6):r===t?c=60*((o-n)/i+2):c=60*((n-t)/i+4)),c<0&&(c+=360),{hue:c,saturation:r===0?0:i/r,value:r}}function V0(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function il(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=nl(e),o=nl(n),r=t.saturation<.08,s=o.saturation<.08;if(r||s)return r===s;let i=Math.min(t.value,o.value)<.16?35:24;return V0(t.hue,o.hue)<=i}function R0(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return null;let o=new Map;for(let c of e.keys()){let a=rl(c);a&&o.set(c,a)}let r=[],s=new Map,i=Array.from(e.entries()).sort((c,a)=>a[1]-c[1]||c[0].localeCompare(a[0]));for(let[c]of i){let a=o.get(c);if(!a){s.set(c,c);continue}let l=null;for(let u of r){if(!il(a,u.parsed))continue;let f=sl(a,u.parsed);f>t||(!l||f<l.distance)&&(l={color:u.color,distance:f})}l?s.set(c,l.color):(r.push({color:c,parsed:a}),s.set(c,c))}return s}var L0=[[1,0],[-1,0],[0,1],[0,-1]];function al(e,n){return`${e},${n}`}function w0(e){let n=e.indexOf(",");return[Number(e.slice(0,n)),Number(e.slice(n+1))]}function N0(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 D0(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return;let o=new Map,r=s=>(o.has(s)||o.set(s,rl(s)),o.get(s)??null);for(let s of e.values()){if(s.size<3)continue;let i=new Map;for(let l of s.values())i.set(l,(i.get(l)??0)+1);let c=new Set,a=[];for(let[l,u]of s){if(c.has(l))continue;let f=[l],d=[],m=new Map,p=1/0,h=-1/0,g=1/0,y=-1/0;for(c.add(l);f.length>0;){let C=f.pop();d.push(C);let[T,A]=w0(C);p=Math.min(p,T),h=Math.max(h,T),g=Math.min(g,A),y=Math.max(y,A);for(let[M,E]of L0){let v=al(T+M,A+E),I=s.get(v);if(I){if(I===u){c.has(v)||(c.add(v),f.push(v));continue}m.set(I,(m.get(I)??0)+1)}}}let b=h-p+1,x=y-g+1;if(!N0(d.length,b,x)||m.size===0)continue;let P=r(u);if(!P)continue;let S=null;for(let[C,T]of m){let A=i.get(C)??0;if(A<=d.length)continue;let M=r(C);if(!M||!il(P,M))continue;let E=sl(P,M);if(E>t)continue;let v={color:C,contacts:T,distance:E,count:A};(!S||v.contacts>S.contacts||v.contacts===S.contacts&&v.count>S.count||v.contacts===S.contacts&&v.count===S.count&&v.distance<S.distance||v.contacts===S.contacts&&v.count===S.count&&v.distance===S.distance&&v.color.localeCompare(S.color)<0)&&(S=v)}if(S)for(let C of d)a.push([C,S.color])}for(let[l,u]of a)s.set(l,u)}}var F0=542658390,B0=new Set(["nTRN","nGRP","nSHP"]),k0="Skipped MagicaVoxel scene graph transforms; models were flattened into one grid";function Ds(e,n){let t=n?.targetSize??60,o=e.byteLength;if(e.byteLength<8)return dt(o,["parseVox: buffer too small to be a valid .vox file"]);let r=new DataView(e);if(r.getUint32(0,!0)!==F0)return dt(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return dt(o,["parseVox: buffer too small for MAIN chunk"]);if(tl(r,8)!=="MAIN")return dt(o,["parseVox: expected MAIN chunk at offset 8"]);let a=20+r.getUint32(12,!0),l=a+r.getUint32(16,!0),u=[],f=[],d=[],m=null,p=k=>{d.includes(k)||d.push(k)};for(;a<l&&a+12<=e.byteLength;){let k=tl(r,a),L=r.getUint32(a+4,!0),W=r.getUint32(a+8,!0),Y=a+12,se=Y+L+W;if(k==="SIZE"){if(L>=12&&Y+12<=e.byteLength){let Z=r.getUint32(Y,!0),B=r.getUint32(Y+4,!0),q=r.getUint32(Y+8,!0);u.push({sx:Z,sy:B,sz:q})}}else if(k==="XYZI"){if(L>=4&&Y+4<=e.byteLength){let Z=r.getUint32(Y,!0),B=[],q=Math.min(Z,Math.floor((L-4)/4));for(let me=0;me<q;me++){let fe=Y+4+me*4;B.push({x:r.getUint8(fe),y:r.getUint8(fe+1),z:r.getUint8(fe+2),colorIndex:r.getUint8(fe+3)})}f.push(B)}}else if(k==="RGBA"&&L>=1024&&Y+1024<=e.byteLength){m=[];for(let Z=0;Z<256;Z++){let B=Y+Z*4,q=r.getUint8(B),me=r.getUint8(B+1),fe=r.getUint8(B+2),G=r.getUint8(B+3);m.push(O0(q,me,fe,G))}}B0.has(k)&&p(k0),a=se}let h=[],g=new Set;for(let k of f)for(let L of k){if(L.colorIndex===0)continue;let W=`${L.x},${L.y},${L.z}`;g.has(W)||(g.add(W),h.push(L))}if(h.length===0)return dt(o,d);let y=new Map,b=k=>{let L=y.get(k);if(L)return L;let W=k-1,Y;if(m!==null)Y=m[W]??"#888888";else{let se=I0[k]??0,[Z,B,q]=_0(se);Y=ol(Z,B,q)}return y.set(k,Y),Y},x=new Map;for(let k of h){let L=b(k.colorIndex);x.set(L,(x.get(L)??0)+1)}let P=R0(x,n?.paletteMergeDistance),S=k=>{let L=b(k);return P?.get(L)??L},C=(k,L,W)=>g.has(`${k},${L},${W}`),T=new Map,A=(k,L,W,Y,se)=>{let Z=`${k}:${L}`,B=T.get(Z);B||(B=new Map,T.set(Z,B)),B.set(al(W,Y),se)};for(let k of h){let{x:L,y:W,z:Y}=k,se=S(k.colorIndex);C(L+1,W,Y)||A(0,L+1,W,Y,se),C(L-1,W,Y)||A(1,L,W,Y,se),C(L,W+1,Y)||A(2,W+1,L,Y,se),C(L,W-1,Y)||A(3,W,L,Y,se),C(L,W,Y+1)||A(4,Y+1,L,W,se),C(L,W,Y-1)||A(5,Y,L,W,se)}D0(T,n?.colorRegionMergeDistance);let M=new Map;for(let[k,L]of T)for(let[W,Y]of L){let se=`${k}:${Y}`,Z=M.get(se);Z||(Z=new Set,M.set(se,Z)),Z.add(W)}function E(k){let L=new Set,W=[],Y=1/0,se=-1/0,Z=1/0,B=-1/0;for(let q of k){let[me,fe]=q.split(","),G=+me,te=+fe;G<Y&&(Y=G),G>se&&(se=G),te<Z&&(Z=te),te>B&&(B=te)}for(let q=Z;q<=B;q++)for(let me=Y;me<=se;me++){let fe=`${me},${q}`;if(!k.has(fe)||L.has(fe))continue;let G=1;for(;me+G<=se;){let ce=`${me+G},${q}`;if(!k.has(ce)||L.has(ce))break;G++}let te=1;e:for(;q+te<=B;){for(let ce=0;ce<G;ce++){let ye=`${me+ce},${q+te}`;if(!k.has(ye)||L.has(ye))break e}te++}for(let ce=0;ce<te;ce++)for(let ye=0;ye<G;ye++)L.add(`${me+ye},${q+ce}`);W.push({u:me,v:q,w:G,h:te})}return W}let v=(k,L,W,Y,se,Z)=>{let B=W+se,q=Y+Z;switch(k){case 0:return[[L,W,Y],[L,B,Y],[L,B,q],[L,W,q]];case 1:return[[L,B,Y],[L,W,Y],[L,W,q],[L,B,q]];case 2:return[[W,L,Y],[W,L,q],[B,L,q],[B,L,Y]];case 3:return[[B,L,Y],[B,L,q],[W,L,q],[W,L,Y]];case 4:return[[W,Y,L],[B,Y,L],[B,q,L],[W,q,L]];default:return[[W,q,L],[B,q,L],[B,Y,L],[W,Y,L]]}},I=[];for(let[k,L]of M){let W=k.indexOf(":"),Y=k.indexOf(":",W+1),se=+k.slice(0,W),Z=+k.slice(W+1,Y),B=k.slice(Y+1);for(let{u:q,v:me,w:fe,h:G}of E(L))I.push({vertices:v(se,Z,q,me,fe,G),color:B})}if(I.length===0)return dt(o,d);let _=1/0,O=1/0,V=1/0,w=-1/0,F=-1/0,D=-1/0;for(let k of I)for(let L of k.vertices)L[0]<_&&(_=L[0]),L[0]>w&&(w=L[0]),L[1]<O&&(O=L[1]),L[1]>F&&(F=L[1]),L[2]<V&&(V=L[2]),L[2]>D&&(D=L[2]);let H=Math.max(w-_,F-O,D-V),K=H>0?t/H:1,Q=K*50,ne=Number.isFinite(Q)&&Q>0?Math.max(1,Math.round(Q))/50:K,ee={kind:"magica-vox",cells:h.map(k=>({x:F-(k.y+1),y:k.x-_,z:k.z-V,color:S(k.colorIndex)})),rows:Math.max(0,F-O),cols:Math.max(0,w-_),depth:Math.max(0,D-V),scale:ne,sourceBytes:o},ue=k=>Math.round(k*1e3)/1e3,U=k=>[ue((k[0]-_)*ne),ue((k[1]-O)*ne),ue((k[2]-V)*ne)],$=I.map(({vertices:k,color:L})=>({vertices:k.map(U),color:L}));return{polygons:$,voxelSource:ee,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:$.length,sourceBytes:o,voxelCount:h.length}}}function tl(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 dt(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var U0="#888888";var G0=/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/,Gn="COLOR=";function ul(e,n,t){let o=n??t;if(!Number.isFinite(o))throw new Error(`parseStl: ${e} must be finite`);return o}function z0(e,n,t){let o=ul(e,n,t);if(o<=0)throw new Error(`parseStl: ${e} must be greater than 0`);return o}function $0(e){if(e===void 0||e==="z"||e==="y")return e??"z";throw new Error('parseStl: upAxis must be "z" or "y"')}function X0(e){let n=e??U0;if(typeof n!="string"||n.trim().length===0)throw new Error("parseStl: defaultColor must be a non-empty string");return n}function Y0(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 fl(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Uo(e,n){return[e.getFloat32(n,!0),e.getFloat32(n+4,!0),e.getFloat32(n+8,!0)]}function Go(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function cl(e){let n=e.trim().split(/\s+/);if(n.length!==3||!n.every(o=>G0.test(o)))return null;let t=[Number(n[0]),Number(n[1]),Number(n[2])];return Go(t)?t:null}function W0(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 Fs(e){return Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")}function ml(e,n,t,o=255){if(o>=255)return`#${Fs(e)}${Fs(n)}${Fs(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 j0(e){for(let n=0;n<80-Gn.length-4;n+=1){let t=!0;for(let c=0;c<Gn.length;c+=1)if(e.getUint8(n+c)!==Gn.charCodeAt(c)){t=!1;break}if(!t)continue;let o=e.getUint8(n+Gn.length),r=e.getUint8(n+Gn.length+1),s=e.getUint8(n+Gn.length+2),i=e.getUint8(n+Gn.length+3);return{defaultColor:ml(o,r,s,i),alpha:Math.round(i/255*1e3)/1e3,alphaByte:i}}return null}function K0(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:ml(t,o,r,n.alphaByte),usesDefaultColor:!1}}function H0(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((s,i)=>s.index-i.index||(s.kind==="end"?-1:1))}function Z0(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 q0(e){let n=fl(e.subarray(0,Math.min(e.byteLength,512))).trimStart().toLowerCase();return!n.startsWith("solid")&&!n.startsWith("facet")?!1:!Z0(e)}function Q0(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(q0(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 J0(e,n,t){let o=new DataView(e.buffer,e.byteOffset,e.byteLength),{triangleCount:r,declaredTriangleCount:s,trailingBytes:i}=n;s!==r&&t.push(`parseStl: binary STL declared ${s} triangles but contains ${r} complete triangle record${r===1?"":"s"}`),i>0&&t.push(`parseStl: ignored ${i} trailing binary byte${i===1?"":"s"}`);let c=W0(e.subarray(0,80)),a=j0(o),l=0,u=0,f=[];for(let d=0,m=84;d<r;d+=1,m+=50){let p=Uo(o,m),h=[Uo(o,m+12),Uo(o,m+24),Uo(o,m+36)];if(!h.every(Go))throw new Error(`parseStl: non-finite coordinate in binary triangle ${d}`);let g=o.getUint16(m+48,!0),y=a?K0(g,a):null;y&&(y.usesDefaultColor?u+=1:l+=1),f.push({normal:Go(p)?p:null,hasIgnoredNormal:!Go(p),color:y?.color,vertices:h,hasIgnoredAttribute:!a&&g!==0})}return{format:"binary",facets:f,binaryHeader:c,color:a?{format:"magics",defaultColor:a.defaultColor,alpha:a.alpha,coloredTriangleCount:l,defaultColorTriangleCount:u}:void 0}}function ll(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,s=/^\s*facet\s+normal\b/gim,i=H0(e),c=0,a,l=0;for(;s.exec(e);)l+=1;let u=0,f=0,d=0,m;for(;m=o.exec(e);){for(u+=1;c<i.length&&i[c].index<m.index;){let b=i[c];a=b.kind==="start"?b.name:void 0,c+=1}let p=cl(m[1]);p||(d+=1);let h=[],g=!1;r.lastIndex=0;let y;for(;y=r.exec(m[2]);){let b=cl(y[1]);if(!b){g=!0;break}h.push(b)}if(g||h.length!==3){f+=1;continue}t.push({normal:p,hasIgnoredNormal:!p,solidName:a,vertices:[h[0],h[1],h[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 pt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function $o(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 ks(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function dl(e){return Math.hypot(e[0],e[1],e[2])}function eh(e){let n=$o(pt(e[1],e[0]),pt(e[2],e[0]));return dl(n)<=1e-8}function zo(e){let n=dl(e);return n<=1e-8?null:[e[0]/n,e[1]/n,e[2]/n]}function nh(e){let n=t=>Object.is(t,-0)?0:t;return`${n(e[0])},${n(e[1])},${n(e[2])}`}function th(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function Us(e,n){return n?[e.vertices[0],e.vertices[2],e.vertices[1]]:e.vertices}function oh(e,n,t){let o=0;for(let r of n.facets){let[s,i,c]=Us(e[r],t[r]);o+=ks(s,$o(i,c))/6}return o}function rh(e,n,t){if(n.facets.length<8)return null;let o=0,r=0;for(let i of n.facets){let c=e[i],a=c.normal?zo(c.normal):null;if(!a)continue;let l=Us(c,t[i]),u=zo($o(pt(l[1],l[0]),pt(l[2],l[0])));if(!u)continue;let f=ks(u,a);f>=.95?o+=1:f<=-.95&&(r+=1)}let s=o+r;return s/n.facets.length<.75?null:r/s>=.9?"opposed":o/s>=.9?"aligned":null}function sh(e){let n=new Map,t=e.map(()=>[]);for(let u=0;u<e.length;u+=1){let f=e[u].vertices.map(nh);for(let d=0;d<3;d+=1){let m=f[d],p=f[(d+1)%3],h=th(m,p),g=n.get(h),y={facetIndex:u,from:m,to:p};g?g.push(y):n.set(h,[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),s=new Array(e.length).fill(-1),i=[],c=0;for(let u=0;u<e.length;u+=1){if(s[u]>=0)continue;let f=i.length,d={facets:[],conflicts:0,boundaryEdges:0,nonManifoldEdges:0,flippedOutward:!1,flippedToSuppliedNormals:!1};i.push(d),s[u]=f;let m=[u];for(let p=0;p<m.length;p+=1){let h=m[p];d.facets.push(h);for(let g of t[h]){let y=r[h]!==g.flipDiffers;s[g.to]<0?(s[g.to]=f,r[g.to]=y,m.push(g.to)):r[g.to]!==y&&h<g.to&&(d.conflicts+=1,c+=1)}}}for(let u of n.values()){let f=i[s[u[0].facetIndex]];u.length===1?f.boundaryEdges+=1:u.length>2&&(f.nonManifoldEdges+=1)}for(let u of i){if(u.nonManifoldEdges>0||u.conflicts>0){for(let d of u.facets)r[d]=!1;continue}if(u.boundaryEdges>0){if(rh(e,u,r)==="opposed"){for(let d of u.facets)r[d]=!r[d];u.flippedToSuppliedNormals=!0}continue}if(oh(e,u,r)<-1e-10){for(let d of u.facets)r[d]=!r[d];u.flippedOutward=!0}}let a=0;return{facets:e.map((u,f)=>r[f]?(a+=1,{...u,vertices:Us(u,!0)}):u),repairedCount:a,componentCount:i.length,outwardComponentCount:i.filter(u=>u.flippedOutward).length,suppliedNormalComponentCount:i.filter(u=>u.flippedToSuppliedNormals).length,conflictCount:c,nonManifoldEdgeCount:o}}function ih(e,n,t,o,r){let s=i=>Math.round(i*1e3)/1e3;return r==="y"?[s((e[2]-n[2])*t+o),s((e[0]-n[0])*t+o),s((e[1]-n[1])*t+o)]:[s((e[0]-n[0])*t+o),s((e[1]-n[1])*t+o),s((e[2]-n[2])*t+o)]}function ah(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 s=e[r]?.solidName??"";r<e.length&&s===t||(n.push({name:t,start:o,count:r-o}),t=s,o=r)}return n}function ch(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 Gs(e,n){let t=z0("targetSize",n?.targetSize,60),o=ul("gridShift",n?.gridShift,1),r=X0(n?.defaultColor),s=$0(n?.upAxis),i=[],c=Y0(e),a=typeof e=="string"?e.length:c.byteLength;if(a===0||typeof e=="string"&&e.trim().length===0)throw new Error("parseStl: empty input");let l=c?Q0(c):null,u=typeof e=="string"?ll(e,i):l?J0(c,l,i):ll(fl(c),i),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),eh(A.vertices)){m+=1;continue}p.push(A)}let h=sh(p),g=0;for(let A of h.facets){let M=zo($o(pt(A.vertices[1],A.vertices[0]),pt(A.vertices[2],A.vertices[0]))),E=A.normal?zo(A.normal):null;M&&E&&ks(M,E)<.95&&(g+=1)}if(f>0&&i.push(`parseStl: ignored non-zero binary attribute byte count on ${f} triangle${f===1?"":"s"}`),d>0&&i.push(`parseStl: ignored ${d} non-finite binary normal${d===1?"":"s"}`),m>0&&i.push(`parseStl: skipped ${m} degenerate triangle${m===1?"":"s"}`),h.repairedCount>0&&i.push(`parseStl: repaired winding on ${h.repairedCount} triangle${h.repairedCount===1?"":"s"}`),h.outwardComponentCount>0&&i.push(`parseStl: oriented ${h.outwardComponentCount} closed component${h.outwardComponentCount===1?"":"s"} outward`),h.suppliedNormalComponentCount>0&&i.push(`parseStl: oriented ${h.suppliedNormalComponentCount} open component${h.suppliedNormalComponentCount===1?"":"s"} from supplied normals`),h.conflictCount>0&&i.push(`parseStl: found ${h.conflictCount} inconsistent shared-edge winding constraint${h.conflictCount===1?"":"s"}`),h.nonManifoldEdgeCount>0&&i.push(`parseStl: found ${h.nonManifoldEdgeCount} non-manifold shared edge${h.nonManifoldEdgeCount===1?"":"s"}`),g>0&&i.push(`parseStl: ${g} supplied normal${g===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 h.facets)for(let M of A.vertices)for(let E=0;E<3;E+=1)M[E]<y[E]&&(y[E]=M[E]),M[E]>b[E]&&(b[E]=M[E]);let x=Math.max(b[0]-y[0],b[1]-y[1],b[2]-y[2]),P=x>0?t/x:1,S=ah(h.facets),C=ch(S),T=h.facets.map(A=>({vertices:A.vertices.map(M=>ih(M,y,P,o,s)),color:A.color??r}));return{polygons:T,objectUrls:[],dispose:()=>{},warnings:i,metadata:{triangleCount:T.length,meshes:C,materials:[],sourceBytes:a,stlHeader:u.binaryHeader,stlColor:u.color,stlSolids:S,stlTopology:{componentCount:h.componentCount,repairedTriangleCount:h.repairedCount,outwardComponentCount:h.outwardComponentCount,suppliedNormalComponentCount:h.suppliedNormalComponentCount,inconsistentSharedEdgeCount:h.conflictCount,nonManifoldSharedEdgeCount:h.nonManifoldEdgeCount}}}}var vn="loadMesh";async function pl(e,n){let t=n?.solidTextureSamples;return t===!1?e:Os(e,typeof t=="object"?t:void 0)}function lh(e){let n=e.split("?")[0].split("#")[0],t=n.lastIndexOf(".");return t<0?"":n.slice(t+1).toLowerCase()}async function uh(e,n){let t=lh(e);if(t==="mtl")throw new Error(`${vn}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let o=globalThis.fetch;if(!o)throw new Error(`${vn}: no fetch() in this environment`);let r=n?.baseUrl??e;if(t==="obj"){let s=await o(e);if(!s.ok)throw new Error(`${vn}: ${e} \u2192 ${s.status}`);let i=await s.text(),c=n?.objOptions;if(n?.mtlUrl){let u=await o(n.mtlUrl);if(!u.ok)throw new Error(`${vn}: ${n.mtlUrl} \u2192 ${u.status}`);let f=await u.text(),{colors:d,textures:m}=ws(f),p={},h=globalThis.URL,g=globalThis.document?.baseURI,y=n.mtlUrl;if(h&&g)try{y=new h(n.mtlUrl,g).toString()}catch{}for(let[b,x]of Object.entries(m)){if(h)try{p[b]=new h(x,y).toString();continue}catch{}let P=n.mtlUrl.lastIndexOf("/"),S=P>=0?n.mtlUrl.slice(0,P+1):"";p[b]=x.startsWith("/")||/^https?:\/\//.test(x)?x:S+x}c={...c??{},materialColors:{...d,...c?.materialColors??{}},materialTextures:{...p,...c?.materialTextures??{}}}}let a=Rs(i,c),l=await pl(a,n);return tt(l,{meshResolution:n?.meshResolution,source:a})}if(t==="glb"||t==="gltf"){let s=await o(e);if(!s.ok)throw new Error(`${vn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),c=vs(i,{baseUrl:r,...n?.gltfOptions??{}}),a=await pl(c,n);return tt(a,{meshResolution:n?.meshResolution,source:c})}if(t==="vox"){let s=await o(e);if(!s.ok)throw new Error(`${vn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return tt(Ds(i,n?.voxOptions),{meshResolution:n?.meshResolution})}if(t==="stl"){let s=await o(e);if(!s.ok)throw new Error(`${vn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return tt(Gs(i,n?.stlOptions),{meshResolution:n?.meshResolution})}throw new Error(`${vn}: unsupported extension ".${t}" (supported: obj, glb, gltf, vox, stl)`)}function Ne(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=cs[n]??10**n,o=Math.round(e*t)/t;return Object.is(o,0)||Object.is(o,-0)?"0":String(o)}function fh(e,n=Io){let t=Ne(e,n);return t==="0"?"0":`${t}px`}function In(e,n=xn){if(e.length===0)return"";let t=Ne(e[0],n);for(let o=1;o<e.length;o++)t+=`,${Ne(e[o],n)}`;return t}function mh(e,n,t,o,r=xn){return zs(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 zs(e,n,t,o,r,s,i,c,a,l,u,f,d=xn){if(d===3){let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,g=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(s*1e3)/1e3||0,x=Math.round(i*1e3)/1e3||0,P=Math.round(c*1e3)/1e3||0,S=Math.round(a*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,T=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`${m},${p},${h},0,${g},${y},${b},0,${x},${P},${S},0,${C},${T},${A},1`}return`${Ne(e,d)},${Ne(n,d)},${Ne(t,d)},0,${Ne(o,d)},${Ne(r,d)},${Ne(s,d)},0,${Ne(i,d)},${Ne(c,d)},${Ne(a,d)},0,${Ne(l,d)},${Ne(u,d)},${Ne(f,d)},1`}function $s(e,n,t,o,r,s,i,c,a,l,u,f,d=xn){if(d!==3)return`matrix3d(${zs(e,n,t,o,r,s,i,c,a,l,u,f,d)})`;let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,g=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(s*1e3)/1e3||0,x=Math.round(i*1e3)/1e3||0,P=Math.round(c*1e3)/1e3||0,S=Math.round(a*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,T=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`matrix3d(${m},${p},${h},0,${g},${y},${b},0,${x},${P},${S},0,${C},${T},${A},1)`}function zt(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(d=>Number(d));if(s.length!==16||s.some(d=>!Number.isFinite(d)))return e.matrix;let i=s[0],c=s[1],a=s[2],l=s[4],u=s[5],f=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*l,s[13]+=o*c+r*u,s[14]+=o*a+r*f,In(s)}function dh(e,n){return zt(e,n.width/Pn,n.height/Pn,n.minX,n.minY)}function gl(e){let n=e.seamBleedInsets??{left:0,right:0,top:0,bottom:0},t=e.canvasW||1,o=e.canvasH||1;return zt(e,(t+n.left+n.right)/ct,(o+n.top+n.bottom)/ct,-n.left,-n.top)}function Xs(e,n){let t=e.matrix.split(",").map(o=>Number(o));return t.length!==16||t.some(o=>!Number.isFinite(o))?e.canonicalMatrix:(t[0]*=e.canvasW/n,t[1]*=e.canvasW/n,t[2]*=e.canvasW/n,t[4]*=e.canvasH/n,t[5]*=e.canvasH/n,t[6]*=e.canvasH/n,In(t))}function _n(e,n=as){let t=Ne(e,n);return Number(t)===0?"0":`${t}%`}function ph(e,n=xn){return`matrix3d(${e.split(",").map(t=>{let o=Number(t.trim());return Number.isFinite(o)?Ne(o,n):t.trim()}).join(",")})`}function gh(e,n=Io){let t=Ne(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function hh(e){return`matrix3d(${gl(e)})`}function On(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 i=1;i+1<e.length;i++){let c=e[i],a=e[i+1],l=[c[0]-n[0],c[1]-n[1],c[2]-n[2]],u=[a[0]-n[0],a[1]-n[1],a[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 s=Math.hypot(t,o,r);return s<=de?null:(t/=s,o/=s,r/=s,[t,o,r])}function $t(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=de)return!1;let c=Math.sign(i);if(n===0)n=c;else if(c!==n)return!1}return!0}function Ys(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 Ws(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],c=o[1]-t[1],a=r*c-s*i;if(Math.abs(a)<=de)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*c-u*i)/a;return[e[0]+f*r,e[1]+f*s]}function yh(e,n,t,o,r,s,i,c){let a=t-e,l=o-n,u=i-r,f=c-s,d=a*f-l*u;if(Math.abs(d)<=de)return null;let m=r-e,p=s-n,h=(m*f-p*u)/d;return[e+h*a,n+h*l]}function gt(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let c=s[i]-t,a=s[i+1]-o,l=Math.hypot(c,a);l<=Ae||(s[i]+=c/l*n,s[i+1]+=a/l*n)}return s}function ht(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let a=0;a<e.length;a+=2)t.push([e[a],e[a+1]]);if(!$t(t))return gt(e,n);let o=Ys(t);if(Math.abs(o)<=de)return gt(e,n);let r=o>0?1:-1,s=[];for(let a=0;a<t.length;a++){let l=t[a],u=t[(a+1)%t.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=de)return gt(e,n);let p=r*(d/m)*n,h=r*(-f/m)*n;s.push({a:[l[0]+p,l[1]+h],b:[u[0]+p,u[1]+h]})}let i=[],c=Math.max(2,n*4);for(let a=0;a<t.length;a++){let l=s[(a+t.length-1)%t.length],u=s[a],f=Ws(l.a,l.b,u.a,u.b);if(!f)return gt(e,n);let d=t[a],m=f[0]-d[0],p=f[1]-d[1],h=Math.hypot(m,p);h>c?i.push(d[0]+m/h*c,d[1]+p/h*c):i.push(f[0],f[1])}return i}function Xt(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])<=de))return ht(e,o[0]);let s=[];for(let f=0;f<e.length;f+=2)s.push([e[f],e[f+1]]);if(!$t(s))return e;let i=Ys(s);if(Math.abs(i)<=de)return e;let c=i>0?1:-1,a=[];for(let f=0;f<s.length;f++){let d=s[f],m=s[(f+1)%s.length],p=m[0]-d[0],h=m[1]-d[1],g=Math.hypot(p,h);if(g<=de)return e;let y=o[f],b=c*(h/g)*y,x=c*(-p/g)*y;a.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<s.length;f++){let d=a[(f+s.length-1)%s.length],m=a[f],p=Ws(d.a,d.b,m.a,m.b);if(!p)return e;let h=s[f],g=p[0]-h[0],y=p[1]-h[1],b=Math.hypot(g,y);b>u?l.push(h[0]+g/b*u,h[1]+y/b*u):l.push(p[0],p[1])}return l}function Xo(e,n,t,o,r,s,i){if(i<=0)return[e,n,t,o,r,s];let c=(e*o-n*t+t*s-o*r+r*n-s*e)/2,a=()=>gt([e,n,t,o,r,s],i);if(Math.abs(c)<=de)return a();let l=c>0?1:-1,u=t-e,f=o-n,d=Math.sqrt(u*u+f*f),m=r-t,p=s-o,h=Math.sqrt(m*m+p*p),g=e-r,y=n-s,b=Math.sqrt(g*g+y*y);if(d<=de||h<=de||b<=de)return a();let x=l*(f/d)*i,P=l*(-u/d)*i,S=e+x,C=n+P,T=t+x,A=o+P,M=l*(p/h)*i,E=l*(-m/h)*i,v=t+M,I=o+E,_=r+M,O=s+E,V=l*(y/b)*i,w=l*(-g/b)*i,F=r+V,D=s+w,H=e+V,K=n+w,Q=H-F,ne=K-D,ee=T-S,ue=A-C,U=Q*ue-ne*ee;if(Math.abs(U)<=de)return a();let $=S-F,k=C-D,L=($*ue-k*ee)/U,W=F+L*Q,Y=D+L*ne,se=T-S,Z=A-C,B=_-v,q=O-I,me=se*q-Z*B;if(Math.abs(me)<=de)return a();let fe=v-S,G=I-C,te=(fe*q-G*B)/me,ce=S+te*se,ye=C+te*Z,he=_-v,be=O-I,ge=H-F,Se=K-D,De=he*Se-be*ge;if(Math.abs(De)<=de)return a();let R=F-v,z=D-I,j=(R*Se-z*ge)/De,J=v+j*he,le=I+j*be,re=Math.max(2,i*4),pe=W-e,xe=Y-n,ie=Math.sqrt(pe*pe+xe*xe);ie>re&&(W=e+pe/ie*re,Y=n+xe/ie*re);let ae=ce-t,N=ye-o,X=Math.sqrt(ae*ae+N*N);X>re&&(ce=t+ae/X*re,ye=o+N/X*re);let oe=J-r,Te=le-s,Ce=Math.sqrt(oe*oe+Te*Te);return Ce>re&&(J=r+oe/Ce*re,le=s+Te/Ce*re),[W,Y,ce,ye,J,le]}function js(e,n,t,o){let r=e+n;if(o<=0||t<=de||r<=de||!Number.isFinite(e+n+t+o))return Xo(e,0,0,t,r,t,o);let s=Math.sqrt(e*e+t*t),i=Math.sqrt(n*n+t*t);if(s<=de||i<=de)return Xo(e,0,0,t,r,t,o);let c=-o*t/s,a=-o*e/s,l=o*t/i,u=-o*n/i,f=e+c,d=a,m=r+l,p=t+u,h=-t*r;if(Math.abs(h)<=de)return Xo(e,0,0,t,r,t,o);let g=f-m,y=d-p,b=(g*t+y*e)/h,x=m-b*n,P=p-b*t,S=-o*(e+s)/t,C=t+o,T=r+o*(n+i)/t,A=C,M=Math.max(2,o*4),E=x-e,v=P,I=Math.sqrt(E*E+v*v);I>M&&(x=e+E/I*M,P=v/I*M);let _=Math.sqrt(S*S+o*o);_>M&&(S=S/_*M,C=t+o/_*M);let O=T-r,V=Math.sqrt(O*O+o*o);return V>M&&(T=r+O/V*M,A=t+o/V*M),[x,P,S,C,T,A]}function hl(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=On(n.vertices,t,o),s=zn(r);if(!s)return null;let i=e.screenPts[0],c=e.screenPts[1],a=e.screenPts[2],l=e.screenPts[3],u=e.screenPts[4],f=e.screenPts[5],d=a-i,m=l-c,p=u-i,h=f-c,g=d*h-m*p;if(Math.abs(g)<=de)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]],S=[x[0]-y[0],x[1]-y[1],x[2]-y[2]],C=[(P[0]*h-m*S[0])/g,(P[1]*h-m*S[1])/g,(P[2]*h-m*S[2])/g],T=[(d*S[0]-P[0]*p)/g,(d*S[1]-P[1]*p)/g,(d*S[2]-P[2]*p)/g],A=y[0]-C[0]*i-T[0]*c,M=y[1]-C[1]*i-T[1]*c,E=y[2]-C[2]*i-T[2]*c;return{normal:s,xAxis:C,yAxis:T,tx:A,ty:M,tz:E}}function Ks(e){return Math.max(0,Math.min(6,Math.floor(e??xn)))}function yl(e){return`${e[0]},${e[1]},${e[2]}`}function bl(e,n){let t=yl(e),o=yl(n);return t<o?`${t}|${o}`:`${o}|${t}`}function bh(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 s=0;s<r.length;s++){let i=bl(r[s],r[(s+1)%r.length]),c=n.get(i),a={polygon:o,edge:s};c?c.push(a):n.set(i,[a])}}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 s=r+1;s<o.length;s++)t[o[r].polygon].add(o[r].edge),t[o[s].polygon].add(o[s].edge);return t.map(o=>o.size>0?o:void 0)}function Yo(e,n){return typeof e=="number"&&Number.isFinite(e)?Math.max(0,e):n}function Hs(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function Wo(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[s,i]=r[n],[c,a]=r[(n+1)%o],l=c-s,u=a-i,f=Math.hypot(l,u);if(f<=Ae)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[M,E]=r[A],v=Math.abs((M-s)*u-(E-i)*l)/f;v>Ae&&(m=Math.min(m,v))}Number.isFinite(m)&&d.push(m*.5);let p=r[(n+o-1)%o],h=r[(n+2)%o],g=p[0]-s,y=p[1]-i,b=h[0]-c,x=h[1]-a,P=Math.hypot(g,y),S=Math.hypot(b,x);if(P>Ae){let A=Math.abs(l*y-u*g)/(f*P);A>Ae&&d.push(P*A)}if(S>Ae){let A=Math.abs(-l*x- -u*b)/(f*S);A>Ae&&d.push(S*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 T=Math.min(...C);return Math.max(0,Math.min(Number.isFinite(t)?t:T,T))}function Zs(e,n,t){if(!n?.size||t===void 0)return;let o=new Map;for(let r of n){let s=Wo(e,r,t);s>0&&o.set(r,s)}return o.size>0?o:void 0}function qs(e,n){return e<3||!n?.size?null:Array.from({length:e},(t,o)=>Math.max(0,n.get(o)??0))}function Qs(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,s=Number.NEGATIVE_INFINITY,i=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),s=Math.max(s,u),i=Math.max(i,f)}if(!Number.isFinite(o+r+s+i))return;let c=Math.max(Ae*8,.25),a={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],h=e[d+1],g=e[m],y=e[m+1];Math.abs(p-g)<=c?Math.abs(p-o)<=c&&Math.abs(g-o)<=c?a.left=Math.max(a.left,f):Math.abs(p-s)<=c&&Math.abs(g-s)<=c&&(a.right=Math.max(a.right,f)):Math.abs(h-y)<=c&&(Math.abs(h-r)<=c&&Math.abs(y-r)<=c?a.top=Math.max(a.top,f):Math.abs(h-i)<=c&&Math.abs(y-i)<=c&&(a.bottom=Math.max(a.bottom,f)))}return a.left||a.right||a.top||a.bottom?a:void 0}function xh(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Ph(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=On(e.vertices,n,t),r=zn(o);return r?{normal:r,planeD:xh(r,o[0])}:null}function Mh(e,n){return(e.material?.key??e.color??"")===(n.material?.key??n.color??"")&&e.color===n.color}function Ah(e,n={}){return new Set(xl(e,n).keys())}function xl(e,n={}){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(a=>Ph(a,t,o)),s=new Map;for(let a=0;a<e.length;a++){let l=e[a].vertices;if(!(!l||l.length<3))for(let u=0;u<l.length;u++){let f=bl(l[u],l[(u+1)%l.length]),d=s.get(f),m={polygon:a,edge:u};d?d.push(m):s.set(f,[m])}}let i=new Map,c=(a,l)=>{let u=i.get(a);u?u.add(l):i.set(a,new Set([l]))};for(let a of s.values())if(!(a.length<2))for(let l=0;l<a.length;l++)for(let u=l+1;u<a.length;u++){let f=a[l],d=a[u],m=f.polygon,p=d.polygon;!r[m]||!r[p]||Mh(e[m],e[p])&&(c(m,f.edge),c(p,d.edge))}return i}function Sh(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>Oo?!1:(e-t)*(e-r)+(n-o)*(n-s)<=Oo}function Pl(e,n=_o,t=_o){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,c]=e[r],[a,l]=e[s];if(Sh(n,t,i,c,a,l))return!0;c>t!=l>t&&n<(a-i)*(t-c)/(l-c)+i&&(o=!o)}return o}function Ml(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=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),s=Math.max(s,u),i=Math.max(i,f))}let c=s-o,a=i-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(c)||!Number.isFinite(a)||c<=de||a<=de?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:c,height:a}}function Yt(e){let n=e.bleedRatio??1,t=ms*n,o=e.canvasW||1,r=e.canvasH||1,s=t>0?ht(e.screenPts,t):e.screenPts,i=t>0?Ml(s,o,r):{minX:0,minY:0,width:o,height:r},c=[];for(let a=0;a<s.length;a+=2){let l=Math.max(0,Math.min(100,(s[a]-i.minX)/i.width*100)),u=Math.max(0,Math.min(100,(s[a+1]-i.minY)/i.height*100));c.push([l,u])}return{bounds:i,points:c}}function Al(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])<=Vo||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])<=Vo&&n.pop()}return n}function Sl([e,n]){let t=new Set;return Math.abs(e)<=qe&&t.add("left"),Math.abs(e-100)<=qe&&t.add("right"),Math.abs(n)<=qe&&t.add("top"),Math.abs(n-100)<=qe&&t.add("bottom"),t.size>0?t:null}function Cl(e,n){for(let t of e)if(n.has(t))return!0;return!1}function El(e,n,t,o){let r=(s,i,c)=>{let a=n.has(i)?e:o.has(i)?t:null,l=n.has(c)?e:o.has(c)?t:null;if(!a||!l)return null;let u=(()=>{switch(s){case"topLeft":return{x:a[0],y:l[1]};case"topRight":return{x:100-a[0],y:l[1]};case"bottomRight":return{x:100-a[0],y:100-l[1]};case"bottomLeft":return{x:a[0],y:100-l[1]}}})();return u.x>qe&&u.y>qe&&u.x<100-qe&&u.y<100-qe?[s,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 Js(e){if(e.texture||yt(e)||$n(e))return null;let n=Yt(e),t=Al(n.points);if(t.length<4)return null;let o=t.map(Sl);if(o.some(i=>!i))return null;let r={},s=0;for(let i=0;i<t.length;i+=1){let c=o[i],a=o[(i+1)%t.length];if(Cl(c,a))continue;let l=El(t[i],c,t[(i+1)%t.length],a);if(!l)return null;let[u,f]=l,d=r[u];if(d&&(Math.abs(d.x-f.x)>qe||Math.abs(d.y-f.y)>qe))return null;r[u]=f,s+=1}return s>0?{bounds:n.bounds,radii:r}:null}function Ch([e,n]){return`${_n(e)} ${_n(n)}`}function Eh(e){return`polygon(${e.map(Ch).join(",")})`}function Th(e){if(Pl(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,c]of e)n+=i,t+=c;let r=_n(Math.max(0,Math.min(100,n/o))),s=_n(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function ei(e){return`${Eh(e)} ${Th(e)}`}function vh(e){return ei(Yt(e).points)}function ni(e,n){return zt(e,n.width/Pn,n.height/Pn,n.minX,n.minY)}function Ih(e){let n=Yt(e);return`matrix3d(${ni(e,n.bounds)})`}function _h(e){let n=Yt(e);return[`transform:matrix3d(${ni(e,n.bounds)})`,`border-shape:${ei(n.points)}`].join(";")}function Oh(e,n){let t=[`transform:matrix3d(${ni(e,n.bounds)})`,`width:${Pn}px`,`height:${Pn}px`,"border:0","box-sizing:border-box","background:currentColor"];for(let[o,r]of Object.entries(n.radii)){let s=o.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`);t.push(`border-${s}-radius:${_n(r.x)} ${_n(r.y)}`),t.push(`corner-${s}-shape:bevel`)}return t.join(";")}function Tl(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=.001,r=(s,i)=>{for(let c of s)if(Math.abs(c-i)<=o)return;s.push(i)};for(let s=0;s<e.screenPts.length;s+=2)r(n,e.screenPts[s]),r(t,e.screenPts[s+1]);if(n.length!==2||t.length!==2||(n.sort((s,i)=>s-i),t.sort((s,i)=>s-i),Math.abs(n[0])>o||Math.abs(t[0])>o||n[1]-n[0]<=o||t[1]-t[0]<=o))return null;for(let s=0;s<e.screenPts.length;s+=2){let i=e.screenPts[s],c=e.screenPts[s+1],a=Math.abs(i-n[0])<=o||Math.abs(i-n[1])<=o,l=Math.abs(c-t[0])<=o||Math.abs(c-t[1])<=o;if(!a||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function $n(e){return!!Tl(e)}function yt(e){return!e.texture&&e.polygon.vertices.length===3}function Wt(e){return!e.texture&&!!e.projectiveMatrix&&!$n(e)}function Vh(e){let n=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(e);return/\bVersion\/[\d.]+.*\bSafari\//.test(e)&&!n}function ti(e,n){e.set(n,(e.get(n)??0)+1)}function oi(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function Rh(e,n,t,o){let r=!t.has("b"),s=r&&o.projectiveQuadSupported,i=!t.has("u")&&o.solidTriangleSupported,c=!t.has("i")&&!!o.cornerShapeSupported,a=!t.has("i")&&o.borderShapeSupported,l=t.has("b");return e.map(u=>{if(!u||u.texture)return u;if(i&&yt(u))return null;let f=$n(u);return c&&!f&&!(s&&Wt(u))&&Js(u)!==null||r&&f||s&&Wt(u)||a&&(!f||l)?null:u})}function Lh(e,n,t,o,r,s,i){let c=new Map,a=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&&!!i?.(y);if(n==="dynamic"){if(!(d&&yt(y))&&!(u&&$n(y))&&!(f&&Wt(y))&&!b&&!p)continue;let x=r(y.polygon.color??"#cccccc"),P=s(x);ti(a,P),l.has(P)||l.set(P,x);continue}!(d&&yt(y))&&!(u&&$n(y))&&!(f&&Wt(y))&&!b&&!p||ti(c,y.shadedColor)}let h=oi(c),g=oi(a);return{paintColor:h,dynamicColorKey:g,dynamicColor:g?l.get(g):void 0}}function wh(e,n){if((e+1)%3===n)return e;if((n+1)%3===e)return n}function Nh(e,n,t,o,r,s,i){if(!e?.size)return null;let c=Yo(n,t);return[[s,o],[o,r],[r,s]].map(([l,u],f)=>{let d=wh(l,u),m=d!==void 0&&e.has(d)?c:0;return Wo(i,f,m)})}function ri(e,n,t,o,r,s,i,c){let a=s,l="",u,f,d="";if(i){let m=c??e.color??"#cccccc",p=s.directionalLight,h=s.ambientLight,g=p?.direction??ot,y=p?.color??rt,b=Math.max(0,p?.intensity??st),x=h?.color??it,P=Math.max(0,h?.intensity??at),S=Math.hypot(g[0],g[1],g[2])||1,C=g[0]/S,T=g[1]/S,A=g[2]/S,E=s.lightOccludedPolyIndices?.has(n)??!1?0:b*Math.max(0,t*C+o*T+r*A),v=Un(m,E,y,x,P),I=s.textureLighting??"baked",_=I==="baked"&&a.stableTriangleColorSteps?bs(v,a.stableTriangleColorSteps):v,O=Mn(m),V=_===s.solidPaintDefaults?.paintColor,w=I==="dynamic"&&ys(O)===s.solidPaintDefaults?.dynamicColorKey;l=I==="dynamic"||V?"":_,u=l?Mn(l):void 0,f=l?Ro(l):void 0,d=I==="dynamic"?`--pnx:${t.toFixed(4)};--pny:${o.toFixed(4)};--pnz:${r.toFixed(4)};`+(w?"":`--psr:${(O.r/255).toFixed(4)};--psg:${(O.g/255).toFixed(4)};--psb:${(O.b/255).toFixed(4)};`):""}return{index:n,polygon:e,colorComputed:i,bakedColor:l||void 0,bakedRgb:u,bakedAlpha:f,dynamicVars:d}}function Dh(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??50,r=t.layerElevation??o,s=e.vertices[0],i=e.vertices[1],c=e.vertices[2],a=[s[1]*o,s[0]*o,s[2]*r],l=[i[1]*o,i[0]*o,i[2]*r],u=[c[1]*o,c[0]*o,c[2]*r],f=l[0]-a[0],d=l[1]-a[1],m=l[2]-a[2],p=u[0]-a[0],h=u[1]-a[1],g=u[2]-a[2],y=-(d*g-m*h),b=-(m*p-f*g),x=-(f*h-d*p),P=Math.sqrt(y*y+b*b+x*x);return P<=de?null:(y/=P,b/=P,x/=P,ri(e,n,y,b,x,t,!0))}function Fh(e,n,t,o={}){if(e.texture||e.vertices.length!==3)return null;let r=t.tileSize??50,s=t.layerElevation??r,i=e.vertices[0],c=e.vertices[1],a=e.vertices[2],l=i[1]*r,u=i[0]*r,f=i[2]*s,d=c[1]*r,m=c[0]*r,p=c[2]*s,h=a[1]*r,g=a[0]*r,y=a[2]*s;return si(e,n,t,o,l,u,f,d,m,p,h,g,y)}function si(e,n,t,o,r,s,i,c,a,l,u,f,d){let m=t,p=c-r,h=a-s,g=l-i,y=u-r,b=f-s,x=d-i,P=-(h*x-g*b),S=-(g*y-p*x),C=-(p*b-h*y),T=Math.sqrt(P*P+S*S+C*C);if(T<=de)return null;P/=T,S/=T,C/=T;let A=o.basis,M=A?.a??0,E=A?.b??1,v=A?.c??2;M<0||M>2||E<0||E>2||v<0||v>2||M===E||M===v||E===v?(A=void 0,M=0,E=1,v=2):M===0&&E===1&&v===2||M===1&&E===2&&v===0||M===2&&E===0&&v===1||(A=void 0,M=0,E=1,v=2);let I=()=>A?si(e,n,t,{...o,basis:void 0},r,s,i,c,a,l,u,f,d):null;if(!A){let ve=p*p+h*h+g*g,Je=u-c,sn=f-a,en=d-l,We=r-u,an=s-f,Wn=i-d,cn=Je*Je+sn*sn+en*en,je=We*We+an*an+Wn*Wn,jn=ve;cn>jn&&(M=1,E=2,v=0,jn=cn),je>jn&&(M=2,E=0,v=1)}let _,O,V,w,F,D,H=v===0?r:v===1?c:u,K=v===0?s:v===1?a:f,Q=v===0?i:v===1?l:d;M===0?(_=r,O=s,V=i):M===1?(_=c,O=a,V=l):(_=u,O=f,V=d),E===0?(w=r,F=s,D=i):E===1?(w=c,F=a,D=l):(w=u,F=f,D=d);let ne=w-_,ee=F-O,ue=D-V,U=Math.sqrt(ne*ne+ee*ee+ue*ue);if(U<=de)return I();let $=ne/U,k=ee/U,L=ue/U,W=(H-_)*$+(K-O)*k+(Q-V)*L,Y=S*L-C*k,se=C*$-P*L,Z=P*k-S*$,B=T/U;if(B<=de)return I();let q=Math.max(0,Math.min(U,W)),me=Math.max(0,U-q),fe=[q,0,0,B,q+me,B],G=is*(m.bleedRatio??1),te=Nh(m.seamEdges,m.seamBleed,G,M,E,v,fe),ce=te?Xt(fe,te):js(q,me,B,Yo(m.seamBleed,G)),ye=ce[0],he=ce[1],be=ce[2],ge=ce[3],Se=ce[4],De=ce[5],R=(ge+De)/2,z=ye-be,j=Se-ye,J=R-he;if(z<=de||j<=de||J<=de||!Number.isFinite(z+j+J))return I();let le=o.includeColor??!0,re=!1,pe,xe,ie,ae="";if(le){let ve=ri(e,n,P,S,C,t,!0,o.color);re=ve.colorComputed,pe=ve.bakedColor,xe=ve.bakedRgb,ie=ve.bakedAlpha,ae=ve.dynamicVars??""}let N=pe?`color:${pe};`:"",X=o.primitive??o.resolvedPrimitive??"border",Te=1/(X==="border-large"?us:ls),Ce=z+j,Pe=Ce*Te,_e=(j-z)*.5*Te,Oe=J*Te,Ve=ye-q-Ce*.5,$e=he,Ee=$*Pe,Fe=k*Pe,we=L*Pe,Xn=$*_e+Y*Oe,Yn=k*_e+se*Oe,un=L*_e+Z*Oe,Qe=H+$*Ve+Y*$e,fn=K+k*Ve+se*$e,Be=Q+L*Ve+Z*$e,Xe=o.matrixDecimals??Ks(m.stableTriangleMatrixDecimals),Me=$s(Ee,Fe,we,Xn,Yn,un,P,S,C,Qe,fn,Be,Xe),Re=t.textureLighting??"baked",Ie=m.optimizeStableTriangleStyle===!0&&Re==="baked"?"":`transform:${Me};`+N+ae,Ye=A&&A.a===M&&A.b===E&&A.c===v?A:{a:M,b:E,c:v};return{index:n,polygon:e,styleText:Ie,transformText:Me,basis:Ye,primitive:X,colorComputed:re,bakedColor:pe,bakedRgb:xe,bakedAlpha:ie,dynamicVars:ae}}function vl(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function Il(e){let n=e?.maxWeightRatio,t=Math.max(0,vl(e?.denomEps,ds)),o=typeof n=="number"&&Number.isFinite(n)&&n>0?Math.max(1,n):ps,r=Math.max(0,vl(e?.bleed,gs));return{denomEps:t,maxWeightRatio:o,bleed:r,disableGuards:e?.disableGuards===!0}}function ii(e,n){if(e.length!==4||!$t(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],c=t[1]-o[1]+r[1]-s[1],a=o[0]-r[0],l=s[0]-r[0],u=o[1]-r[1],f=s[1]-r[1],d=a*f-u*l;if(Math.abs(d)<=de)return null;let m=(i*f-c*l)/d,p=(a*c-u*i)/d,h=[1,1+m,1+m+p,1+p];if(h.some(b=>!Number.isFinite(b)))return null;let g=Math.min(...h),y=Math.max(...h);return!n.disableGuards&&(g<=n.denomEps||y/g>n.maxWeightRatio)?null:{g:m,h:p,w1:1+m,w3:1+p}}function _l(e,n,t,o,r,s,i,c,a){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(!ii(l,c))return null;let u=qs(4,a),f=u?Xt(e,u):ht(e,c.bleed),d=[[f[0],f[1]],[f[2],f[3]],[f[4],f[5]],[f[6],f[7]]],m=ii(d,c);if(!m)return null;let{g:p,h,w1:g,w3:y}=m,[b,x,,P]=d,S=[r+b[0]*n[0]+b[1]*t[0],s+b[0]*n[1]+b[1]*t[1],i+b[0]*n[2]+b[1]*t[2]],C=([A,M],E)=>[(E-1)*r+(E*A-b[0])*n[0]+(E*M-b[1])*t[0],(E-1)*s+(E*A-b[0])*n[1]+(E*M-b[1])*t[1],(E-1)*i+(E*A-b[0])*n[2]+(E*M-b[1])*t[2]],T=[...C(x,g),p,...C(P,y),h,o[0],o[1],o[2],0,S[0],S[1],S[2],1];for(let A=0;A<8;A+=1)T[A]/=ct;return In(T,6)}function Ko(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Bh(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 Ol(e){return!e.texture}function Vl(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=On(e.vertices,n,t),r=zn(o);return r?{pts:o,normal:r,planeD:Ko(r,o[0]),optimizable:Ol(e)}:null}function Rl(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:li(e,n)}function li(e,n){return!e||!n||Ko(e.normal,n.normal)<1-rs?!1:Math.abs(e.planeD-n.planeD)<=ss}function ai(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??ot,s=t?.color??rt,i=Math.max(0,t?.intensity??st),c=o?.color??it,a=Math.max(0,o?.intensity??at),l=Math.hypot(r[0],r[1],r[2])||1,u=r[0]/l,f=r[1]/l,d=r[2]/l,m=i*Math.max(0,e.normal[0]*u+e.normal[1]*f+e.normal[2]*d),p=wo(m,s,c,a);return p.r*.2126+p.g*.7152+p.b*.0722}function Ll(e){let n=[...e],t=Math.abs(n[0])>de?0:Math.abs(n[1])>de?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 bt(e,n,t,o,r={}){let s=Ko(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],c=Math.hypot(i[0],i[1],i[2]);if(c<=de)return null;let a=[i[0]/c,i[1]/c,i[2]/c],l=[t[1]*a[2]-t[2]*a[1],t[2]*a[0]-t[0]*a[2],t[0]*a[1]-t[1]*a[0]],u=Math.hypot(l[0],l[1],l[2]);if(u<=de)return null;let f=[l[0]/u,l[1]/u,l[2]/u],d=e.map(V=>{let w=V[0]-n[0],F=V[1]-n[1],D=V[2]-n[2];return[w*a[0]+F*a[1]+D*a[2],w*f[0]+F*f[1]+D*f[2]]}),m=r.boundsOrigin??n,p=n[0]-m[0],h=n[1]-m[1],g=n[2]-m[2],y=p*a[0]+h*a[1]+g*a[2],b=p*f[0]+h*f[1]+g*f[2],x=1/0,P=1/0,S=-1/0,C=-1/0;for(let[V,w]of d){let F=V+y,D=w+b;F<x&&(x=F),F>S&&(S=F),D<P&&(P=D),D>C&&(C=D)}let T=S-x,A=C-P;if(!Number.isFinite(T)||!Number.isFinite(A))return null;let M=r.snapBounds?Math.floor(x+Ae):x,E=r.snapBounds?Math.floor(P+Ae):P,v=r.snapBounds?Math.ceil(S-Ae):S,I=r.snapBounds?Math.ceil(C-Ae):C,_=Math.max(1,r.snapBounds?v-M:Math.ceil(T)),O=Math.max(1,r.snapBounds?I-E:Math.ceil(A));return{xAxis:a,yAxis:f,local2D:d,shiftX:y-M,shiftY:b-E,canvasW:_,canvasH:O,pixelArea:_*O,rawArea:T*A}}function jo(e){return`${e[0]},${e[1]},${e[2]}`}function wl(e,n){return jo(e)<jo(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 kh(e,n){let t=jo(e),o=jo(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Nl(e,n,t,o){let r=0,s=0;for(let i of e){let c=n[i];if(!c)return null;let a=bt(c.pts,c.pts[0],c.normal,t,{boundsOrigin:o,snapBounds:!0});if(!a)return null;r+=a.pixelArea,s+=a.rawArea}return{pixelArea:r,rawArea:s}}function Dl(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let c=n[i];if(!c)continue;let a=[c.pts[1][0]-c.pts[0][0],c.pts[1][1]-c.pts[0][1],c.pts[1][2]-c.pts[0][2]],l=bt(c.pts,c.pts[0],c.normal,a);o&&l?(o.pixelArea+=l.pixelArea,o.rawArea+=l.rawArea):o=null;for(let u=0;u<c.pts.length;u++){let f=wl(c.pts[u],c.pts[(u+1)%c.pts.length]),d=bt(c.pts,c.pts[0],c.normal,f);if(!d)continue;let m=Ll(d.xAxis);if(s.has(m))continue;s.add(m);let p=Nl(e,n,d.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-Ae)&&(r={xAxis:d.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+Ae)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function Uh(e,n){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(f=>Vl(f,t,o)),s=new Map,i=e.map(()=>new Set),c=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=kh(d[m],d[(m+1)%d.length]),h=s.get(p),g={polygon:f,edge:m};h?h.push(g):s.set(p,[g])}}let a=e.map(()=>new Set);for(let f of s.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],h=f[m],g=p.polygon,y=h.polygon;if(e[g].texture&&e[y].texture&&(c[p.polygon].add(p.edge),c[h.polygon].add(h.edge)),li(r[g],r[y]))i[p.polygon].add(p.edge),i[h.polygon].add(h.edge);else{let b=ai(r[g],n),x=ai(r[y],n);b!==null&&x!==null&&(b<=x+vo&&i[p.polygon].add(p.edge),x<=b+vo&&i[h.polygon].add(h.edge))}Rl(r[g],r[y])&&(a[g].add(y),a[y].add(g))}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 h=m.pop();d.push(h);for(let g of a[h])u.has(g)||(u.add(g),m.push(g))}if(d.length<2)continue;let p=Dl(d,r);if(p)for(let h of d)l[h]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:c[h]}}for(let f=0;f<e.length;f++)!l[f]&&(i[f].size>0||c[f].size>0)&&(l[f]={seamEdges:i[f],textureEdgeRepairEdges:c[f]});return l}function ci(e,n,t,o){if(o.optimize&&o.fixedXAxis)return bt(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((c,a)=>a):[0]);for(let c of i){let a=(c+1)%e.length,l=s?wl(e[c],e[a]):[e[a][0]-e[c][0],e[a][1]-e[c][1],e[a][2]-e[c][2]],u=bt(e,n,t,l,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-Ae)&&(r=u)}return r}function Fl(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=Ae)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>Ae||Math.abs(t[0])>Ae||n[1]-n[0]<=Ae||t[1]-t[0]<=Ae))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,c=s+e.shiftY,a=Math.abs(i-n[0])<=Ae||Math.abs(i-n[1])<=Ae,l=Math.abs(c-t[0])<=Ae||Math.abs(c-t[1])<=Ae;if(!a||!l)return!1}return!0}function ui(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,c]=n,a=t[0],l=t[1],u=o[0],f=o[1],d=r[0],m=r[1],p=s[0],h=1-s[1],g=i[0],y=1-i[1],b=c[0],x=1-c[1],P=g-p,S=y-h,C=b-p,T=x-h,A=P*T-C*S;if(Math.abs(A)<=1e-9)return null;let M=u-a,E=d-a,v=f-l,I=m-l,_={a:(M*T-E*S)/A,b:(P*E-C*M)/A,c:(v*T-I*S)/A,d:(P*I-C*v)/A,e:0,f:0};return _.e=a-_.a*p-_.b*h,_.f=l-_.c*p-_.d*h,_}function fi(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],c=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(c))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,c),r=Math.max(r,c)}return{minU:n,minV:t,maxU:o,maxV:r}}function Bl(e,n,t,o,r,s,i,c){let l=On(e.vertices,n,t).map(d=>{let m=d[0]-o[0],p=d[1]-o[1],h=d[2]-o[2];return[m*r[0]+p*r[1]+h*r[2]+i,m*s[0]+p*s[1]+h*s[2]+c]}),u=ui(l,e.uvs),f=fi(e.uvs);return!u&&!f?null:{screenPts:l.flatMap(([d,m])=>[d,m]),uvAffine:u,uvSampleRect:f}}function kl(e,n,t,o,r){let s=t,{vertices:i,texture:c,uvs:a}=e;if(!i||i.length<3)return null;let l=t.tileSize??50,u=t.layerElevation??l,f=On(i,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 g=zn(f);if(!g)return null;let y=ci(f,d,g,{optimize:!1}),b=c||y&&Fl(y)?y:ci(f,d,g,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:P,local2D:S}=b,C=c&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,T=!!(c&&C),A=b.shiftX,M=b.shiftY,E=b.canvasW,v=b.canvasH,I=[];for(let[ge,Se]of S)I.push(ge+A,Se+M);let _=d[0]-A*x[0]-M*P[0],O=d[1]-A*x[1]-M*P[1],V=d[2]-A*x[2]-M*P[2],w=In([x[0],x[1],x[2],0,P[0],P[1],P[2],0,g[0],g[1],g[2],0,_,O,V,1]),F=In([x[0]*E,x[1]*E,x[2]*E,0,P[0]*v,P[1]*v,P[2]*v,0,g[0],g[1],g[2],0,_,O,V,1]),D=In([x[0]*E/Ze,x[1]*E/Ze,x[2]*E/Ze,0,P[0]*v/Ze,P[1]*v/Ze,P[2]*v/Ze,0,g[0],g[1],g[2],0,_,O,V,1]),H=Hs(s.seamBleed),K=Zs(I,s.seamEdges??r?.seamEdges,H),Q=K?new Set(K.keys()):void 0,ne=K?Math.max(...K.values()):void 0,ee=Qs(I,K),ue=!c&&i.length===4?_l(I,x,P,g,_,O,V,o,K):null,U=t.directionalLight,$=t.ambientLight,k=U?.direction??ot,L=U?.color??rt,W=Math.max(0,U?.intensity??st),Y=$?.color??it,se=Math.max(0,$?.intensity??at),Z=Math.hypot(k[0],k[1],k[2])||1,B=k[0]/Z,q=k[1]/Z,me=k[2]/Z,G=t.lightOccludedPolyIndices?.has(n)??!1?0:W*Math.max(0,g[0]*B+g[1]*q+g[2]*me),te=wo(G,L,Y,se),ce=Un(e.color??"#cccccc",G,L,Y,se),ye=null,he=null;c&&a&&a.length>=3&&a.length===i.length&&(he=fi(a),ye=ui(S.map(([ge,Se])=>[ge+A,Se+M]),a));let be=c&&e.textureTriangles?.length?e.textureTriangles.map(ge=>Bl(ge,l,u,d,x,P,A,M)).filter(ge=>!!ge):null;return{index:n,polygon:e,texture:c,tileSize:l,layerElevation:u,matrix:w,canonicalMatrix:F,atlasMatrix:D,projectiveMatrix:ue,canvasW:E,canvasH:v,screenPts:I,uvAffine:ye,uvSampleRect:he,textureTriangles:be,textureEdgeRepairEdges:C,textureEdgeRepair:T,seamBleed:ne,seamBleedEdges:Q,seamBleedEdgeAmounts:K,seamBleedInsets:ee,bleedRatio:hs(s.seamBleed),normal:g,textureTint:te,shadedColor:ce}}function Gh(e,n,t={},o,r){let s=Il(o),i=t,c=r??(t.textureEdgeRepairEdges?.size?{seamEdges:new Set,textureEdgeRepairEdges:t.textureEdgeRepairEdges}:void 0);return kl(e,n,i,s,c)}function Kt(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Qr,Math.max(qr,n))}function di(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function Ul(e,n){let t=di(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=Ft/o,s=Math.sqrt(n/(t*4));return Kt(Math.min(r,s))}function Gl(e,n){let t=di(e),o=.5;return t<=To?o=1:t<=Jr&&(o=.75),Kt(Math.min(o,Ul(e,n)))}function zl(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function $l(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function Xl(e,n,t){let o=zl(e,n),r=$l(e,n),s=o>Ft?Ft/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function Yl(e){return e?es:ns}function Wl(e,n){return e!==void 0&&e!=="auto"?Ze:n?Ze:fs}function mi(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=Xs(t,n));return e}function zh(e){return e.atlasCanonicalSize??Ze}function jl(e){return Math.max(Eo,Math.ceil(Eo/e))}function jt(e,n=1){let t=Array(e.length).fill(null),o=[],r=jl(n),s=e.filter(a=>!!a).sort((a,l)=>l.canvasH-a.canvasH||l.canvasW-a.canvasW||a.index-l.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),c=(a,l,u)=>{if(a.sealed)return null;for(let m of a.shelves)if(l.canvasH<=m.height&&m.x+l.canvasW+r<=En){let p={...l,pageIndex:u,x:m.x,y:m.y};return m.x+=l.canvasW+r*2,a.entries.push(p),a.width=Math.max(a.width,p.x+l.canvasW+r),p}let f=a.shelves.length===0?r:a.height+r;if(f+l.canvasH+r>En)return null;let d={...l,pageIndex:u,x:r,y:f};return a.shelves.push({x:r+l.canvasW+r*2,y:f,height:l.canvasH}),a.entries.push(d),a.width=Math.max(a.width,d.x+l.canvasW+r),a.height=Math.max(a.height,f+l.canvasH+r),d};for(let a of s){if(a.canvasW+r*2>En||a.canvasH+r*2>En){let f=o.length,d={...a,pageIndex:f,x:r,y:r};t[a.index]=d,o.push({width:a.canvasW+r*2,height:a.canvasH+r*2,entries:[d],shelves:[],sealed:!0});continue}let u=null;for(let f=0;f<o.length&&(u=c(o[f],a,f),!u);f++);if(!u){let f=i(),d=o.length;o.push(f),u=c(f,a,d)}u&&(t[a.index]=u)}return{entries:t,pages:o.map(({width:a,height:l,entries:u})=>({width:a,height:l,entries:u}))}}function $h(e,n,t){let o=Gl(n.pages,t),r=o===1?n:jt(e,o);for(let s=0;s<4;s++){let i=Xl(r.pages,o,t);if(i>=1)break;let c=Kt(o*i*ts);if(c>=o)break;o=c,r=jt(e,o)}return{packed:r,atlasScale:o}}function Xh(e,n,t){let o=Wl(n,t);if(n!==void 0&&n!=="auto"){let i=Kt(n);return{packed:mi(jt(e,i),o),atlasScale:i,atlasCanonicalSize:o}}let r=jt(e,1),s=$h(e,r,Yl(t));return{packed:mi(s.packed,o),atlasScale:s.atlasScale,atlasCanonicalSize:o}}export{ag as ASYNC_RENDER_BUDGET_MS,fs as ATLAS_CANONICAL_SIZE_AUTO_DESKTOP,Ze as ATLAS_CANONICAL_SIZE_EXPLICIT,En as ATLAS_MAX_SIZE,Eo as ATLAS_PADDING,To as AUTO_ATLAS_LOW_AREA,Ft as AUTO_ATLAS_MAX_BITMAP_SIDE,ns as AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP,es as AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE,Jr as AUTO_ATLAS_MEDIUM_AREA,ts as AUTO_ATLAS_SCALE_GUARD,ng as BAKED_SHADOW_MIN_UP,eg as BAKED_SHADOW_Z_SQUASH,Ge as BASE_TILE,de as BASIS_EPS,ms as BORDER_SHAPE_BLEED,Pn as BORDER_SHAPE_CANONICAL_SIZE,_o as BORDER_SHAPE_CENTER_PERCENT,Oo as BORDER_SHAPE_POINT_EPS,Po as CAMERA_BACKFACE_CULL_EPS,os as COLOR_PARSE_CACHE_MAX,Vo as CORNER_SHAPE_DUPLICATE_EPS,qe as CORNER_SHAPE_POINT_EPS,cs as DECIMAL_SCALES,it as DEFAULT_AMBIENT_COLOR,at as DEFAULT_AMBIENT_INTENSITY,Io as DEFAULT_ATLAS_CSS_DECIMALS,as as DEFAULT_BORDER_SHAPE_DECIMALS,Ke as DEFAULT_CAMERA_STATE,rt as DEFAULT_LIGHT_COLOR,ot as DEFAULT_LIGHT_DIR,st as DEFAULT_LIGHT_INTENSITY,xn as DEFAULT_MATRIX_DECIMALS,Kl as DEFAULT_PROJECTION,mg as DEFAULT_SEAM_BLEED,Zi as DEFAULT_SEAM_FACET_SPLIT_OPTIONS,Hi as DEFAULT_SEAM_OVERLAP_OPTIONS,bn as DEFAULT_TILE,bc as LoopOnce,xc as LoopPingPong,Ss as LoopRepeat,Qr as MAX_ATLAS_SCALE,qr as MIN_ATLAS_SCALE,gs as PROJECTIVE_QUAD_BLEED,ds as PROJECTIVE_QUAD_DENOM_EPS,ps as PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,au as QUAT_IDENTITY,gc as RECEIVER_NORMAL_TOL,hc as RECEIVER_OFFSET_TOL,pc as RECEIVER_OUTLINE_EXPAND,Ae as RECT_EPS,vo as SEAM_LIGHT_EPS,ct as SOLID_QUAD_CANONICAL_SIZE,is as SOLID_TRIANGLE_BLEED,ls as SOLID_TRIANGLE_CANONICAL_SIZE,us as SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE,ss as SURFACE_DISTANCE_EPS,rs as SURFACE_NORMAL_EPS,lg as TEXTURE_EDGE_REPAIR_ALPHA_MIN,fg as TEXTURE_EDGE_REPAIR_RADIUS,ug as TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN,cg as TEXTURE_TRIANGLE_BLEED,Ga as VOXEL_CAMERA_CULL_AXIS_EPS,za as VOXEL_CAMERA_CULL_NORMAL_LIMIT,mi as applyPackedAtlasCanonicalSize,qa as arrowPolygons,di as atlasArea,zl as atlasBitmapMaxSide,zh as atlasCanonicalSizeForEntry,Wl as atlasCanonicalSizeForTextureQuality,$l as atlasDecodedBytes,jl as atlasPadding,Xl as autoAtlasBudgetFactor,Yl as autoAtlasMaxDecodedBytes,Gl as autoAtlasScale,Ul as autoAtlasScaleCap,ja as axesHelperPolygons,y0 as bakeSolidTextureSampledPolygons,Os as bakeSolidTextureSamples,Ll as basisAxisKey,Ml as borderShapeBoundsFromPoints,Yt as borderShapeGeometryForPlan,Ha as boxPolygons,tg as buildBakedShadowProjectionMatrix,Uh as buildBasisHints,xs as buildEdgeOwners,sg as buildPolyMeshTransform,ig as buildPolySceneTransform,eu as buildSceneContext,xl as buildSeamBleedPolygonEdges,Ah as buildSeamBleedPolygonSet,xg as buildSharedEdgeMap,bh as buildTextureEdgeRepairSets,ut as cachedParsePureColor,Ya as cameraCullNormalGroups,$p as cameraCullNormalGroupsFromPolygons,Xa as cameraCullNormalKey,Yp as cameraCullVisibleSignature,$a as cameraFacingDepth,Dl as chooseIslandXAxis,ci as chooseLocalBasis,Vn as clampChannel,Ps as classifyFacing,Cn as clipPolygonToConvex2D,bg as colorErrorScore,li as compatibleBleedSurface,Rl as compatibleSurface,Gp as computeLightVisibility,Zs as computePlanSeamBleedEdgeAmounts,ii as computeProjectiveQuadCoefficients,_l as computeProjectiveQuadMatrix,Sg as computeReceiverShadowFaces,Si as computeSceneBbox,Qs as computeSeamBleedInsets,Zl as computeShapeLighting,Dh as computeSolidTriangleColorPlan,ri as computeSolidTriangleColorPlanFromNormal,Fh as computeSolidTrianglePlan,si as computeSolidTrianglePlanFromCssPoints,zn as computeSurfaceNormal,kl as computeTextureAtlasPlan,Gh as computeTextureAtlasPlanPublic,su as computeTexturePaintMetrics,ui as computeUvAffine,fi as computeUvSampleRect,ic as conePolygons,jr as convexHull2D,El as cornerShapeDiagonal,Js as cornerShapeGeometryForPlan,Sl as cornerShapePointSides,ir as coverPlanarPolygons,pu as createIsometricCamera,Ig as createPolyAnimationMixer,Bh as crossVec,ei as cssBorderShapeForGeometry,vh as cssBorderShapeForPlan,uc as cssDistanceToWorld,On as cssPoints,fc as cssPositionToWorld,dn as cullInteriorPolygons,Ao as cylinderPolygons,Fu as dedupeOverlappingPolygons,sc as dodecahedronPolygons,oi as dominantCountKey,Ko as dotVec,yn as ensureCcw2D,fu as eulerXYZFromQuat,Nl as evaluateIslandAxis,gt as expandClipPoints,dc as expandConvexHullOutward,Ms as extractSilhouetteLoops,Rh as filterAtlasPlans,Jt as findOverlappingPolygonDuplicates,mh as formatAffineMatrix3dColumns,zs as formatAffineMatrix3dScalars,$s as formatAffineMatrix3dTransformScalars,Xs as formatAtlasMatrix,_h as formatBorderShapeElementStyle,Ih as formatBorderShapeEntryMatrix,dh as formatBorderShapeMatrix,Ht as formatColor,Oh as formatCornerShapeElementStyle,fh as formatCssLength,gh as formatCssLengthPx,ph as formatMatrix3d,In as formatMatrix3dValues,_n as formatPercent,zt as formatScaledMatrixFromPlan,hh as formatSolidQuadEntryMatrix,gl as formatSolidQuadMatrix,Tl as fullRectBounds,Vl as getPolygonBasisInfo,Lh as getSolidPaintDefaultsForPlansCore,Zr as groupReceiverFaceGroups,rc as icosahedronPolygons,ti as incrementCount,Ws as intersect2DLines,yh as intersect2DLinesRaw,iu as inverseRotateVec3,Wa as isAxisAlignedSurfaceNormal,og as isBakedShadowCaster,Ol as isBasisOptimizable,$t as isConvexPolygonPoints,Fl as isFullRectBasis,$n as isFullRectSolid,Wt as isProjectiveQuadPlan,yt as isSolidTrianglePlan,Xp as isVoxelCameraCullableNormalGroups,uh as loadMesh,bt as makeLocalBasis,ln as mergePolygons,Hr as meshScaleVec3,Nt as normalFacesCamera,Kt as normalizeAtlasScale,mu as normalizeInvertMultiplier,qo as normalizePolygons,Hs as normalizedSeamBleed,nc as octahedronPolygons,ht as offsetConvexPolygonPoints,Xt as offsetConvexPolygonPointsByEdgeAmounts,js as offsetStableTrianglePoints,Xo as offsetTrianglePoints,S0 as optimizeAnimatedMeshPolygons,tt as optimizeMeshParseResult,hd as optimizeMeshPolygons,jt as packTextureAtlasPlans,Xh as packTextureAtlasPlansWithScaleCore,Ro as parseAlpha,Kn as parseColor,vs as parseGltf,Mn as parseHex,pi as parseHexColor,ws as parseMtl,Rs as parseObj,An as parsePureColor,gi as parseRgbColor,Gs as parseStl,Ds as parseVox,ec as planePolygons,uc as polyCssDistanceToWorld,fc as polyCssPositionToWorld,Pl as polygonContainsPoint,Xr as polygonCssSurfaceNormal,nu as polygonFaces,zp as polygonFacesCamera,cc as polygonSignedArea2D,Pg as prepareCasterEdgeOwners,Mg as prepareCasterPolyItems,Ag as prepareReceiverFacePlanes,rg as projectCssVertexToGround,Bl as projectTextureTriangle,bs as quantizeCssColor,lu as quatFromAxisAngle,uu as quatFromEulerXYZ,cu as quatMultiply,nm as repairMeshSeams,hs as resolveBleedRatio,Il as resolveProjectiveQuadGuards,Yo as resolveSeamBleed,gg as rgbEqual,ys as rgbKey,yg as rgbToCss,Lo as rgbToHex,Qa as ringPolygons,Ja as ringQuadPolygons,Qo as rotateVec3,Rn as rotateVec3InWrapperCssFrame,Ne as roundDecimal,Vh as safariCssProjectiveUnsupported,Wo as safePlanSeamBleedAmount,gu as screenToWorldOnSphere,vi as screenToWorldRay,qs as seamBleedAmountArray,aa as seamFacetSplitPolygons,em as seamFacetSplitReport,ai as seamLightBrightness,tm as seamOverlapDiagnostics,ca as seamOverlapPolygons,om as seamOverlapReport,Hl as shadeColor,Un as shadePolygon,Cl as sharedCornerShapeSide,Ys as signedArea2D,Al as simplifyCornerShapePoints,Sr as simplifyTriangleMeshPolygons,tc as spherePolygons,hl as stableBasisFromPlan,Ks as stableTriangleMatrixDecimals,hg as stepRgbToward,oc as tetrahedronPolygons,wo as textureTintFactors,dg as tintToCss,ac as torusPolygons,Dt as worldCssForMesh,Kr as worldDirectionToCss,Kr as worldDirectionToPolyCss,mc as worldDirectionalLightToCss,mc as worldDirectionalLightToPolyCss,lc as worldDistanceToCss,lc as worldDistanceToPolyCss,rn as worldPositionToCss,rn as worldPositionToPolyCss};
|