@layoutit/polycss-core 0.0.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -82
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1189 -15
- package/dist/index.d.ts +1189 -15
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var ct=Object.defineProperty;var Un=Object.getOwnPropertyDescriptor;var Nn=Object.getOwnPropertyNames;var _n=Object.prototype.hasOwnProperty;var $n=(e,t)=>{for(var r in t)ct(e,r,{get:t[r],enumerable:!0})},zn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Nn(t))!_n.call(e,o)&&o!==r&&ct(e,o,{get:()=>t[o],enumerable:!(n=Un(t,o))||n.enumerable});return e};var Fn=e=>zn(ct({},"__esModule",{value:!0}),e);var Ao={};$n(Ao,{BASE_TILE:()=>Jt,DEFAULT_CAMERA_STATE:()=>de,DEFAULT_PROJECTION:()=>kt,LoopOnce:()=>dn,LoopPingPong:()=>xn,LoopRepeat:()=>pn,arrowPolygons:()=>Vt,axesHelperPolygons:()=>At,bakeSolidTextureSampledPolygons:()=>En,bakeSolidTextureSamples:()=>Ze,buildSceneContext:()=>jt,clampChannel:()=>fe,computeSceneBbox:()=>mt,computeShapeLighting:()=>Ft,computeTexturePaintMetrics:()=>Yt,coverPlanarPolygons:()=>un,createIsometricCamera:()=>qt,createPolyAnimationMixer:()=>hn,cullInteriorPolygons:()=>Ge,formatColor:()=>Se,inverseRotateVec3:()=>Wt,loadMesh:()=>kn,mergePolygons:()=>Ve,normalizeInvertMultiplier:()=>Qt,normalizePolygons:()=>_e,octahedronPolygons:()=>Mt,parseColor:()=>ge,parseGltf:()=>We,parseHexColor:()=>at,parseMtl:()=>je,parseObj:()=>De,parsePureColor:()=>ke,parseRgbColor:()=>ft,parseVox:()=>Ke,polygonFaces:()=>Xt,ringPolygons:()=>vt,rotateVec3:()=>Ht,shadeColor:()=>zt});module.exports=Fn(Ao);var kt="cubic";function at(e){let t=e.replace("#","");if(t.length===3){let r=parseInt(t[0]+t[0],16),n=parseInt(t[1]+t[1],16),o=parseInt(t[2]+t[2],16);return Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(o)?null:{rgb:[r,n,o],alpha:1}}if(t.length===6){let r=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16);return Number.isNaN(r)||Number.isNaN(n)||Number.isNaN(o)?null:{rgb:[r,n,o],alpha:1}}return null}function ft(e){let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/i);return t?{rgb:[Number(t[1]),Number(t[2]),Number(t[3])],alpha:t[4]?Number(t[4]):1}:null}function ke(e){if(!e)return null;let t=e.trim(),r=at(t);return r||ft(t)}function fe(e){return Math.max(0,Math.min(255,Math.round(e)))}function Se(e){let[t,r,n]=e.rgb.map(fe);return e.alpha<1?`rgba(${t}, ${r}, ${n}, ${e.alpha})`:`rgb(${t}, ${r}, ${n})`}var ut={rgb:[204,204,204],alpha:1},Ut=new Map;function ge(e){if(!e)return null;let t=e.trim(),r=Ut.get(t);if(r)return r;let n=ke(t);return n?(Ut.set(t,n),n):null}function zt(e,t){let r=ge(e)??ut,n=[fe(r.rgb[0]+t),fe(r.rgb[1]+t),fe(r.rgb[2]+t)];return Se({rgb:n,alpha:r.alpha})}var lt={direction:[0,0,-1],color:"#ffffff",intensity:1},Nt={color:"#ffffff",intensity:.4};function _t(e){let t=Math.hypot(e[0],e[1],e[2]);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]}function $t(e,t,r){let n=ge(t)??ut;return e*(n.rgb[r]/255)}function Ft(e,t,r,n){let o=ge(t)??ut,i=_t(r?.direction??lt.direction),s=r?.color??lt.color,a=Math.max(0,r?.intensity??lt.intensity),c=n?.color??Nt.color,f=Math.max(0,n?.intensity??Nt.intensity),l=_t(e),u=Math.max(0,-(l[0]*i[0]+l[1]*i[1]+l[2]*i[2])),g=a*u,m=[0,0,0];for(let p=0;p<3;p=p+1){let h=o.rgb[p],b=$t(h,c,p)*f,y=$t(h,s,p)*g;m[p]=fe(b+y)}return Se({rgb:m,alpha:o.alpha})}var Gt="#cccccc",Ue=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Bt=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Dt=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Ne=e=>Math.hypot(e[0],e[1],e[2]);function Gn(e){let t=1/0,r=1/0,n=1/0,o=-1/0,i=-1/0,s=-1/0;for(let l of e)l[0]<t&&(t=l[0]),l[0]>o&&(o=l[0]),l[1]<r&&(r=l[1]),l[1]>i&&(i=l[1]),l[2]<n&&(n=l[2]),l[2]>s&&(s=l[2]);let a=o-t,c=i-r,f=s-n;return Math.hypot(a,c,f)}function Bn(){let e=globalThis;if(e.__POLYCSS_DEV__===!0)return!0;if(e.__POLYCSS_DEV__===!1)return!1;let t=e.process?.env?.NODE_ENV;return typeof t=="string"?t!=="production":!1}function _e(e){let t=[],r=[];if(!e||e.length===0)return{polygons:t,warnings:r};for(let n=0;n<e.length;n++){let o=e[n];if(!o||!Array.isArray(o.vertices)){r.push(`Polygon ${n}: missing vertices, dropped`);continue}let i=o.vertices;if(i.length<3){r.push(`Polygon ${n}: ${i.length} vertices (need >= 3), dropped`);continue}let s=Ue(i[1],i[0]),a=Ue(i[2],i[0]),c=Bt(s,a),f=Ne(c);if(i.length===3){if(f<1e-12){Ne(s)<1e-12||Ne(a)<1e-12?r.push(`Polygon ${n}: zero-area triangle (coincident vertices), dropped`):r.push(`Polygon ${n}: vertices collinear, dropped`);continue}}else if(f<1e-12){r.push(`Polygon ${n}: first 3 vertices collinear, dropped`);continue}let l=[{...o,vertices:i.slice()}];if(i.length>=4){let u=[c[0]/f,c[1]/f,c[2]/f],g=Dt(u,i[0]),m=Gn(i),p=Math.max(1e-6,m*.001),h=0;for(let b=3;b<i.length;b++){let y=Math.abs(Dt(u,i[b])-g);y>h&&(h=y)}if(h>p){let b=[],y=o.uvs&&o.uvs.length===i.length?o.uvs:void 0;for(let M=1;M<i.length-1;M++){let C=[i[0].slice(),i[M].slice(),i[M+1].slice()],v=Bt(Ue(C[1],C[0]),Ue(C[2],C[0]));if(Ne(v)<1e-12)continue;let x={...o,vertices:C};y&&(x.uvs=[y[0].slice(),y[M].slice(),y[M+1].slice()]),b.push(x)}if(b.length===0){r.push(`Polygon ${n}: ${i.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}r.push(`Polygon ${n}: ${i.length} non-coplanar vertices, fan-triangulated to ${b.length} triangles`),l=b}}for(let u of l){let g=Dn(u,n,r);g&&t.push(g)}}return{polygons:t,warnings:r}}function Dn(e,t,r){let n={vertices:e.vertices},o=e.texture;if(typeof o=="string"&&o===""&&(o=void 0),e.color!==void 0&&o!==void 0&&Bn()&&r.push(`Polygon ${t}: color and texture both set; texture wins`),e.color!==void 0&&(ge(e.color)?n.color=e.color:(r.push(`Polygon ${t}: invalid color "${e.color}", replaced with ${Gt}`),n.color=Gt)),o!==void 0&&(n.texture=o),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?r.push(`Polygon ${t}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):n.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let i={},s=!1;for(let a of Object.keys(e.data)){let c=e.data[a];typeof c=="string"||typeof c=="number"||typeof c=="boolean"?i[a]=c:(s=!0,r.push(`Polygon ${t}: data["${a}"] has non-primitive value, key dropped`))}Object.keys(i).length>0&&(n.data=i)}return n}function mt(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let t=1/0,r=1/0,n=1/0,o=-1/0,i=-1/0,s=-1/0,a=!1;for(let c of e)if(c?.vertices)for(let f of c.vertices)f&&(a=!0,f[0]<t&&(t=f[0]),f[0]>o&&(o=f[0]),f[1]<r&&(r=f[1]),f[1]>i&&(i=f[1]),f[2]<n&&(n=f[2]),f[2]>s&&(s=f[2]));return a?{min:[t,r,n],max:[o,i,s]}:{min:[0,0,0],max:[0,0,0]}}function jt(e){let t=e.polygons??[],r,n;if(e.skipNormalize)r=t,n=[];else{let a=_e(t);r=a.polygons,n=a.warnings}let o=mt(r),i=[o.max[0]-o.min[0],o.max[1]-o.min[1],o.max[2]-o.min[2]];return{context:{polygons:r,sceneBbox:o,warnings:n},dimensions:{sceneBbox:o,size:i},warnings:n}}function Xt(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(t=>[t[0],t[1],t[2]]),color:e.color}]}function jn(e){let t=e[0],r=e[1],n=e[2],o=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]],s=o[1]*i[2]-o[2]*i[1],a=o[2]*i[0]-o[0]*i[2],c=o[0]*i[1]-o[1]*i[0],f=Math.hypot(s,a,c);return f<=1e-9?null:[s/f,a/f,c/f]}function Xn(e){let t=0;for(let r=0;r<e.length;r++){let[n,o]=e[r],[i,s]=e[(r+1)%e.length];t+=n*s-i*o}return Math.abs(t)/2}function Yn(e,t,r){if(!e||e.length<3)return null;let n=e.map(a=>[a[1]*t,a[0]*t,a[2]*r]),o=jn(n);if(!o)return null;let i=1/0,s=0;for(let a=0;a<n.length;a++){let c=n[a],f=n[(a+1)%n.length],l=[f[0]-c[0],f[1]-c[1],f[2]-c[2]],u=l[0]*o[0]+l[1]*o[1]+l[2]*o[2],g=[l[0]-u*o[0],l[1]-u*o[1],l[2]-u*o[2]],m=Math.hypot(g[0],g[1],g[2]);if(m<=1e-9)continue;let p=[g[0]/m,g[1]/m,g[2]/m],h=[o[1]*p[2]-o[2]*p[1],o[2]*p[0]-o[0]*p[2],o[0]*p[1]-o[1]*p[0]],b=Math.hypot(h[0],h[1],h[2]);if(b<=1e-9)continue;let y=[h[0]/b,h[1]/b,h[2]/b],M=n.map(R=>{let F=R[0]-c[0],O=R[1]-c[1],z=R[2]-c[2];return[F*p[0]+O*p[1]+z*p[2],F*y[0]+O*y[1]+z*y[2]]}),C=1/0,v=1/0,x=-1/0,V=-1/0;for(let[R,F]of M)C=Math.min(C,R),v=Math.min(v,F),x=Math.max(x,R),V=Math.max(V,F);let I=x-C,S=V-v,E=Math.max(1,Math.ceil(I))*Math.max(1,Math.ceil(S)),U=Xn(M);U<=1e-9||E<i&&(i=E,s=U)}return!Number.isFinite(i)||s<=1e-9?null:{elementArea:i,polygonArea:s}}function Yt(e,t={}){let r=t.tileSize??100,n=t.layerElevation??r,o=t.texturedOnly??!0,i=0,s=0,a=0,c=0,f=0;for(let u of e){let g=!!u.texture;if(o&&!g)continue;let m=Yn(u.vertices,r,n);m&&(i+=1,g&&(s+=1),a+=m.elementArea,c+=m.polygonArea,f=Math.max(f,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let l=Math.max(0,a-c);return{totalPolygons:e.length,measuredPolygons:i,texturedPolygons:s,elementArea:a,polygonArea:c,transparentArea:l,transparentRatio:a>0?l/a:0,overdrawRatio:c>0?a/c:0,worstTransparentRatio:f}}function Ht(e,t,r,n){let o=t*Math.PI/180,i=r*Math.PI/180,s=n*Math.PI/180,[a,c,f]=e;if(s!==0){let l=Math.cos(s),u=Math.sin(s);[a,c]=[a*l-c*u,a*u+c*l]}if(i!==0){let l=Math.cos(i),u=Math.sin(i);[a,f]=[a*l+f*u,-a*u+f*l]}if(o!==0){let l=Math.cos(o),u=Math.sin(o);[c,f]=[c*l-f*u,c*u+f*l]}return[a,c,f]}function Wt(e,t){let r=-t[0]*Math.PI/180,n=-t[1]*Math.PI/180,o=-t[2]*Math.PI/180,[i,s,a]=e;if(r!==0){let c=Math.cos(r),f=Math.sin(r);[s,a]=[s*c-a*f,s*f+a*c]}if(n!==0){let c=Math.cos(n),f=Math.sin(n);[i,a]=[i*c+a*f,-i*f+a*c]}if(o!==0){let c=Math.cos(o),f=Math.sin(o);[i,s]=[i*c-s*f,i*f+s*c]}return[i,s,a]}var Jt=50;function Qt(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var de={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},Zt=100,Kt=1e4,Ae=e=>Math.round(e*Zt)/Zt,Hn=e=>Math.round(e*Kt)/Kt;function qt(e={}){let t={target:e.target??[...de.target],rotX:e.rotX??de.rotX,rotY:e.rotY??de.rotY,zoom:e.zoom??de.zoom,distance:e.distance??de.distance};function r(o){o.target!==void 0&&(t.target=[Ae(o.target[0]),Ae(o.target[1]),Ae(o.target[2])]),o.rotX!==void 0&&(t.rotX=Ae(o.rotX)),o.rotY!==void 0&&(t.rotY=Ae(o.rotY)),o.zoom!==void 0&&(t.zoom=Hn(o.zoom)),o.distance!==void 0&&(t.distance=Ae(o.distance))}function n(o={}){let s=(o.cols??0)*50,a=(o.rows??0)*50,[c,f,l]=t.target,u=f*50,g=c*50,m=l*50;return{transform:`${t.distance!==0?` translateZ(${-t.distance}px)`:""}scale(${t.zoom}) rotateX(${t.rotX}deg) rotate(${t.rotY}deg) translate3d(${-u}px, ${-g}px, ${-m}px)`,width:`${s}px`,height:`${a}px`}}return{state:t,update:r,getStyle:n}}var ue=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],$e=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Ie=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],gt=e=>Math.hypot(e[0],e[1],e[2]),le=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2];function Wn(e,t){let r=`${e[0]},${e[1]},${e[2]}`,n=`${t[0]},${t[1]},${t[2]}`;return r<n?`${r}|${n}`:`${n}|${r}`}function en(e){if(e.length<3)return null;let t=ue(e[1],e[0]),r=ue(e[2],e[0]),n=$e(t,r),o=gt(n);if(o<1e-12)return null;let i=[n[0]/o,n[1]/o,n[2]/o],s=Ie(i,e[0]);return{normal:i,d:s}}function Zn(e,t){return Ie(e.normal,t.normal)<1-.001?!1:Math.abs(e.d-t.d)<.05}function Kn(e,t){return Ie(e.normal,t.normal)<1-.001?!1:Math.abs(e.d-t.d)<.001}function Jn(e,t,r,n){let o=e.vertices.findIndex(S=>le(S,r)),i=e.vertices.findIndex(S=>le(S,n)),s=t.vertices.findIndex(S=>le(S,r)),a=t.vertices.findIndex(S=>le(S,n));if(o<0||i<0||s<0||a<0)return null;let c=e.vertices.length,f=t.vertices.length,l=(o+1)%c===i,u=(s+1)%f===a;if(l===u)return null;let g=l?i:o,m=l?o:i,p=u?a:s,h=u?s:a,b=!!(e.uvs&&t.uvs),y=[],M=b?[]:void 0,C=g;for(;y.push(e.vertices[C]),M&&M.push(e.uvs[C]),C!==m;)C=(C+1)%c;for(C=p;y.push(t.vertices[C]),M&&M.push(t.uvs[C]),C!==h;)C=(C+1)%f;let v=[],x=M?[]:void 0;for(let S=0;S<y.length;S++)(v.length===0||!le(y[S],v[v.length-1]))&&(v.push(y[S]),x&&M&&x.push(M[S]));if(v.length>1&&le(v[0],v[v.length-1])&&(v.pop(),x?.pop()),b)return nr(v,x);let V=[],I=x?[]:void 0;for(let S=0;S<v.length;S++){let E=v[(S-1+v.length)%v.length],U=v[S],R=v[(S+1)%v.length],F=$e(ue(U,E),ue(R,E));gt(F)>1e-9&&(V.push(U),I&&x&&I.push(x[S]))}return V.length<3?null:{vertices:V,uvs:I}}function Qn(e,t){let r=e.length,n=0;for(let o=0;o<r;o++){let i=e[o],s=e[(o+1)%r],a=e[(o+2)%r],c=ue(s,i),f=ue(a,s),l=Ie($e(c,f),t);if(Math.abs(l)<1e-9)continue;let u=l>0?1:-1;if(n===0)n=u;else if(u!==n)return!1}return!0}function qn(e){if(e.length<3)return!1;let t=en(e);if(!t)return!1;for(let r of e)if(Math.abs(Ie(t.normal,r)-t.d)>.001)return!1;return!0}function er(e){return e.map(t=>({vertices:t.vertices.map(r=>[...r]),uvs:t.uvs.map(r=>[...r])}))}function tr(e,t){let r=[];for(let n=1;n<e.length-1;n++)r.push({vertices:[[...e[0]],[...e[n]],[...e[n+1]]],uvs:[[...t[0]],[...t[n]],[...t[n+1]]]});return r}function nr(e,t){for(let r=0;r<e.length;r++){let n=e[r],o=e[(r+1)%e.length],i=e[(r+2)%e.length];if(!(gt($e(ue(o,n),ue(i,n)))<=1e-9))return r===0?{vertices:e,uvs:t}:{vertices:[...e.slice(r),...e.slice(0,r)],uvs:t?[...t.slice(r),...t.slice(0,r)]:void 0}}return{vertices:e,uvs:t}}function Ve(e){let t=[],r=[];for(let o of e??[]){if(!o||!o.vertices||o.vertices.length<3){o&&t.push(o);continue}let i=o.vertices.map(f=>[f[0],f[1],f[2]]),s=en(i);if(!s){t.push(o);continue}let a=o.texture&&o.uvs&&o.uvs.length===i.length?o.uvs.map(f=>[f[0],f[1]]):void 0,c=o.texture&&a?o.textureTriangles?.length?er(o.textureTriangles):tr(i,a):void 0;r.push({vertices:i,uvs:a,color:o.color??"#cccccc",texture:o.texture,textureTriangles:c,normal:s.normal,d:s.d,alive:!0,data:o.data})}let n=()=>{let o=new Map;for(let a=0;a<r.length;a++){let c=r[a];if(!c.alive)continue;let f=c.vertices.length;for(let l=0;l<f;l++){let u=c.vertices[l],g=c.vertices[(l+1)%f],m=Wn(u,g),p=o.get(m);p||(p=[],o.set(m,p)),p.push(a)}}let i=!1,s=(a,c)=>{for(let f=0;f<a.vertices.length;f++){let l=a.vertices[f],u=a.vertices[(f+1)%a.vertices.length];for(let g=0;g<c.vertices.length;g++){let m=c.vertices[g],p=c.vertices[(g+1)%c.vertices.length];if(le(l,p)&&le(u,m))return[l,u]}}return null};for(let[,a]of o){if(a.length<2)continue;let[c,f]=a;if(c===f)continue;let l=r[c],u=r[f];if(!l.alive||!u.alive||l.color!==u.color||l.texture!==u.texture)continue;let g=!!(l.texture||u.texture);if(g&&(!l.textureTriangles||!u.textureTriangles)||!!l.uvs!=!!u.uvs||(g?!Kn(l,u):!Zn(l,u)))continue;let m=s(l,u);if(!m)continue;let[p,h]=m,b=Jn(l,u,p,h);b&&(g&&!qn(b.vertices)||Qn(b.vertices,l.normal)&&(l.vertices=b.vertices,l.uvs=b.uvs,l.textureTriangles=g?[...l.textureTriangles??[],...u.textureTriangles??[]]:void 0,u.alive=!1,i=!0))}return i};for(;n(););for(let o of r){if(!o.alive)continue;let i={vertices:o.vertices,color:o.color};o.texture&&(i.texture=o.texture),o.uvs&&(i.uvs=o.uvs),o.textureTriangles?.length&&(i.textureTriangles=o.textureTriangles),o.data&&(i.data=o.data),t.push(i)}return t}var rr=4,or=8,ir=.001,sr=1e-9,cr=1e6,ar=1e6,pe=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],xt=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Ee=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],xe=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],sn=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],cn=e=>Math.hypot(e[0],e[1],e[2]);function Oe(e){let t=cn(e);return t<=sr?null:[e[0]/t,e[1]/t,e[2]/t]}function Te(e,t){return Math.round(e*t)/t}function se(e){return Te(e,cr)}function dt(e){return Te(e,ar)}function pt(e,t){return Math.abs(e[0]-t[0])<=1e-7&&Math.abs(e[1]-t[1])<=1e-7}function ce(e){return`${se(e[0])},${se(e[1])}`}function fr(e){let t=ce(e.a),r=ce(e.b);return t<r?`${t}|${r}`:`${r}|${t}`}function ve(e){return`${e[0]},${e[1]},${e[2]}`}function an(e,t){let r=ve(e),n=ve(t);return r<n?`${r}|${n}`:`${n}|${r}`}function ht(e){return e?Object.keys(e).sort().map(t=>`${t}:${String(e[t])}`).join("|"):""}function tn(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",ht(e.data)].join("|")}function fn(e){let t=e.vertices;if(!t||t.length<3)return null;let r=t[0],n=[0,0,0];for(let i=1;i<t.length-1;i++)n=xt(n,sn(pe(t[i],r),pe(t[i+1],r)));let o=Oe(n);return o?{normal:o,d:xe(o,r)}:null}function lr(e,t,r){return xe(e.normal,t.normal)>1-r&&Math.abs(e.d-t.d)<=r}function ur(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function mr(e,t){let r=t[e[0]]?.data,n=ht(r);for(let o of e)if(ht(t[o].data)!==n)return;return r?{...r}:void 0}function gr(e,t){let r=e.map(c=>ur(c)?fn(c):null),n=r.map(Boolean),o=new Map;for(let c=0;c<e.length;c++){if(!r[c])continue;let f=e[c].vertices;for(let l=0;l<f.length;l++){let u=an(f[l],f[(l+1)%f.length]),g=o.get(u),m={polygon:c,edge:l};g?g.push(m):o.set(u,[m])}}let i=e.map(()=>new Set);for(let c of o.values())if(!(c.length<2))for(let f=0;f<c.length;f++)for(let l=f+1;l<c.length;l++){let u=c[f].polygon,g=c[l].polygon,m=r[u],p=r[g];!m||!p||tn(e[u])===tn(e[g])&&lr(m,p,t)&&(i[u].add(g),i[g].add(u))}let s=new Set,a=[];for(let c=0;c<e.length;c++){if(!n[c]||s.has(c))continue;let f=[],l=[c];for(s.add(c);l.length>0;){let u=l.shift();f.push(u);for(let g of i[u])s.has(g)||(s.add(g),l.push(g))}a.push(f)}return{groups:a}}function dr(e,t){let r=new Set(e),n=new Map;for(let i of e){let s=t[i].vertices;for(let a=0;a<s.length;a++){let c=an(s[a],s[(a+1)%s.length]),f=n.get(c),l={polygon:i,edge:a};f?f.push(l):n.set(c,[l])}}let o=[];for(let i of n.values()){let s=i.filter(a=>r.has(a.polygon));if(s.length===1){let a=s[0],c=t[a.polygon].vertices;o.push({a:c[a.edge],b:c[(a.edge+1)%c.length]})}else if(s.length!==2)return null}return o}function pr(e){let t=new Map;for(let r of e)t.set(ve(r.a),(t.get(ve(r.a))??0)+1),t.set(ve(r.b),(t.get(ve(r.b))??0)+1);for(let r of t.values())if(r%2!==0)return!1;return!0}function ln(e){let t=[e[0],e[1],e[2]],r=Math.abs(t[0])>=Math.abs(t[1])&&Math.abs(t[0])>=Math.abs(t[2])?0:Math.abs(t[1])>=Math.abs(t[2])?1:2;return t[r]<0?[-t[0],-t[1],-t[2]]:t}function xr(e){let t=ln(e);return`${Te(t[0],1e3)},${Te(t[1],1e3)},${Te(t[2],1e3)}`}function hr(e){let t=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],r=pe(t,Ee(e,xe(t,e)));return Oe(r)??[1,0,0]}function br(e,t,r){let n=new Map;for(let i of e){let s=pe(i.b,i.a),a=pe(s,Ee(t,xe(s,t))),c=Oe(a);if(!c)continue;let f=ln(c),l=xr(f),u=cn(a),g=n.get(l);g?g.weight+=u:n.set(l,{axis:f,weight:u})}let o=[...n.values()].sort((i,s)=>s.weight-i.weight).slice(0,r).map(i=>i.axis);return o.length===0&&o.push(hr(t)),o}function nn(e,t,r,n){let o=pe(e,t);return[se(xe(o,r)),se(xe(o,n))]}function yr(e){let t=[...e].sort((n,o)=>n-o),r=[];for(let n of t)(r.length===0||Math.abs(n-r[r.length-1])>1e-7)&&r.push(n);return r}function Ce(e,t){let[r,n]=e.a,[o,i]=e.b,s=(t-r)/(o-r);return se(n+(i-n)*s)}function bt(e){let t=[];for(let n of e)(t.length===0||Math.abs(n[0]-t[t.length-1][0])>1e-7||Math.abs(n[1]-t[t.length-1][1])>1e-7)&&t.push(n);t.length>1&&Math.abs(t[0][0]-t[t.length-1][0])<=1e-7&&Math.abs(t[0][1]-t[t.length-1][1])<=1e-7&&t.pop();let r=[];for(let n=0;n<t.length;n++){let o=t[(n-1+t.length)%t.length],i=t[n],s=t[(n+1)%t.length],a=(i[0]-o[0])*(s[1]-i[1])-(i[1]-o[1])*(s[0]-i[0]);Math.abs(a)>1e-8&&r.push(i)}return r}function Fe(e){let t=0;for(let r=0;r<e.length;r++){let n=e[r],o=e[(r+1)%e.length];t+=n[0]*o[1]-o[0]*n[1]}return t/2}function rn(e){let t=1/0,r=1/0,n=-1/0,o=-1/0;for(let[i,s]of e)t=Math.min(t,i),r=Math.min(r,s),n=Math.max(n,i),o=Math.max(o,s);return{minX:t,minY:r,maxX:n,maxY:o}}function Pr(e,t){let r=rn(e),n=rn(t);return!(r.maxX<n.minX-1e-7||n.maxX<r.minX-1e-7||r.maxY<n.minY-1e-7||n.maxY<r.minY-1e-7)}function ze(e){return Math.abs(Fe(e))}function Ar(e){if(e.length<3)return!1;let t=0;for(let r=0;r<e.length;r++){let n=e[r],o=e[(r+1)%e.length],i=e[(r+2)%e.length],s=(o[0]-n[0])*(i[1]-o[1])-(o[1]-n[1])*(i[0]-o[0]);if(Math.abs(s)<=1e-8)continue;let a=s>0?1:-1;if(t===0)t=a;else if(t!==a)return!1}return!0}function Vr(e,t,r){let n=r[0]-t[0],o=r[1]-t[1],i=e[0]-t[0],s=e[1]-t[1],a=n*s-o*i,c=Math.hypot(n,o);if(c<=1e-9||Math.abs(a)>Math.max(1e-8,c*1e-8))return!1;let f=i*n+s*o;return f>=-1e-8&&f<=n*n+o*o+1e-8}function vr(e,t,r){let n=r[0]-t[0],o=r[1]-t[1],i=n*n+o*o;return i<=1e-12?0:((e[0]-t[0])*n+(e[1]-t[1])*o)/i}function on(e,t){let r=[];for(let n=0;n<e.length;n++){let o=e[n],i=e[(n+1)%e.length],s=[{t:0,point:o},{t:1,point:i}];for(let c of t)pt(c,o)||pt(c,i)||Vr(c,o,i)&&s.push({t:vr(c,o,i),point:c});s.sort((c,f)=>c.t-f.t);let a=[];for(let c of s)a.some(f=>Math.abs(f.t-c.t)<=1e-8||pt(f.point,c.point))||a.push(c);for(let c=0;c<a.length-1;c++){let f=a[c].point,l=a[c+1].point;Math.hypot(l[0]-f[0],l[1]-f[1])<=1e-8||r.push({a:[se(f[0]),se(f[1])],b:[se(l[0]),se(l[1])]})}}return r}function Mr(e,t){if(!Pr(e,t))return null;let r=[...on(e,t),...on(t,e)],n=new Map;for(let h of r){let b=fr(h),y=n.get(b);y?y.push(h):n.set(b,[h])}let o=!1,i=[];for(let h of n.values()){if(h.length===1){i.push(h[0]);continue}o=!0;let b=h.filter(M=>ce(M.a)<ce(M.b)).length,y=h.length-b;if(b!==y)return null}if(!o||i.length<3)return null;let s=new Map;for(let h of i){let b=ce(h.a);if(s.has(b))return null;s.set(b,h)}let a=i[0],c=ce(a.a),f=[],l=new Set,u=c;for(let h=0;h<=i.length;h++){let b=s.get(u);if(!b)return null;let y=`${ce(b.a)}>${ce(b.b)}`;if(l.has(y))return null;if(l.add(y),f.push(b.a),u=ce(b.b),u===c)break}if(u!==c||l.size!==i.length)return null;let g=bt(f);if(g.length<3||!Ar(g))return null;let m=ze(g),p=ze(e)+ze(t);return Math.abs(m-p)>Math.max(1e-5,p*1e-5)?null:Fe(g)>=0?g:[...g].reverse()}function wr(e){let t=e.map(bt).filter(n=>n.length>=3&&ze(n)>1e-8),r=!0;for(;r;){r=!1;for(let n=0;n<t.length;n++){for(let o=n+1;o<t.length;o++){let i=Mr(t[n],t[o]);if(i){t[n]=i,t.splice(o,1),r=!0;break}}if(r)break}}return t}function Sr(e,t,r){let n=new Map;return o=>{let i=se(o[0]),s=se(o[1]),a=`${i},${s}`,c=n.get(a);if(c)return[c[0],c[1],c[2]];let f=xt(e,xt(Ee(t,i),Ee(r,s))),l=[dt(f[0]),dt(f[1]),dt(f[2])];return n.set(a,l),[l[0],l[1],l[2]]}}function Ir(e,t,r,n,o){let i=r[0]?.a;if(!i)return null;let s=Oe(pe(o,Ee(n,xe(o,n))));if(!s)return null;let a=Oe(sn(n,s));if(!a)return null;let c=[],f=[];for(let b of r){let y=nn(b.a,i,s,a),M=nn(b.b,i,s,a);Math.hypot(y[0]-M[0],y[1]-M[1])<=1e-7||(c.push({a:y,b:M}),f.push(y[0],M[0]))}let l=yr(f);if(c.length<3||l.length<2)return null;let u=t[e[0]].color,g=mr(e,t),m=[];for(let b=0;b<l.length-1;b++){let y=l[b],M=l[b+1];if(M-y<=1e-7)continue;let C=(y+M)/2,v=c.filter(x=>{let V=Math.min(x.a[0],x.b[0]),I=Math.max(x.a[0],x.b[0]);return V<C&&C<I&&Math.abs(x.a[0]-x.b[0])>1e-7}).map(x=>({segment:x,yMid:Ce(x,C)})).sort((x,V)=>x.yMid-V.yMid);if(v.length!==0){if(v.length%2!==0)return null;for(let x=0;x<v.length;x+=2){let V=v[x].segment,I=v[x+1].segment,S=Ce(V,y),E=Ce(V,M),U=Ce(I,y),R=Ce(I,M),F=bt([[y,S],[M,E],[M,R],[y,U]]);if(F.length<3||Math.abs(Fe(F))<=1e-8)continue;let O=Fe(F)>0?F:[...F].reverse();m.push(O)}}}if(m.length===0)return null;let p=Sr(i,s,a),h=wr(m).map(b=>({vertices:b.map(p),...u?{color:u}:{},...g?{data:g}:{}}));return Ve(h)}function Cr(e,t,r){let n=dr(e,t);if(!n||n.length<3||!pr(n))return null;let o=fn(t[e[0]]);if(!o)return null;let i=null;for(let s of br(n,o.normal,r)){let a=Ir(e,t,n,o.normal,s);a&&(!i||a.length<i.length)&&(i=a)}return!i||i.length>=e.length?null:i}function un(e,t={}){let r=t.minGroupPolygons??rr,n=t.maxCandidateAxes??or,o=t.planeEpsilon??ir,i=e??[];if(i.length<r)return i;let{groups:s}=gr(i,o);if(s.length===0)return i;let a=new Map,c=new Set;for(let l of s){if(l.length<r)continue;let u=Cr(l,i,n);if(u){a.set(l[0],u);for(let g of l)c.add(g)}}if(a.size===0)return i;let f=[];for(let l=0;l<i.length;l++){let u=a.get(l);if(u){f.push(...u);continue}c.has(l)||f.push(i[l])}return f}function Tr(e){let t=e.vertices;if(!t||t.length<3)return null;let r=0,n=0,o=0;for(let[O,z,L]of t)r+=O,n+=z,o+=L;let i=1/t.length;r*=i,n*=i,o*=i;let s=t[0],a=t[1],c=t[2],f=a[0]-s[0],l=a[1]-s[1],u=a[2]-s[2],g=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],h=l*p-u*m,b=u*g-f*p,y=f*m-l*g,M=Math.hypot(h,b,y);if(M<1e-9)return null;h/=M,b/=M,y/=M;let C=t.length-2,v=new Float64Array(C*9),x=0;for(let O=1;O<t.length-1;O++){let z=t[0],L=t[O],_=t[O+1];v[x++]=z[0],v[x++]=z[1],v[x++]=z[2],v[x++]=L[0],v[x++]=L[1],v[x++]=L[2],v[x++]=_[0],v[x++]=_[1],v[x++]=_[2]}let V=0,I=1/0,S=1/0,E=1/0,U=-1/0,R=-1/0,F=-1/0;for(let[O,z,L]of t){let _=O-r,T=z-n,P=L-o,d=_*_+T*T+P*P;d>V&&(V=d),O<I&&(I=O),O>U&&(U=O),z<S&&(S=z),z>R&&(R=z),L<E&&(E=L),L>F&&(F=L)}return{centroid:[r,n,o],normal:[h,b,y],vertices:t,triFlat:v,bcx:r,bcy:n,bcz:o,br2:V,minX:I,minY:S,minZ:E,maxX:U,maxY:R,maxZ:F}}function Er(e,t,r,n,o,i,s,a){let c=s[a],f=s[a+1],l=s[a+2],u=s[a+3]-c,g=s[a+4]-f,m=s[a+5]-l,p=s[a+6]-c,h=s[a+7]-f,b=s[a+8]-l,y=o*b-i*h,M=i*p-n*b,C=n*h-o*p,v=u*y+g*M+m*C;if(v>-1e-9&&v<1e-9)return!1;let x=1/v,V=e-c,I=t-f,S=r-l,E=x*(V*y+I*M+S*C);if(E<0||E>1)return!1;let U=I*m-S*g,R=S*u-V*m,F=V*g-I*u,O=x*(n*U+o*R+i*F);return O<0||E+O>1?!1:x*(p*U+h*R+b*F)>.001}function Or(e,t,r,n,o,i,s){let a=s.bcx-e,c=s.bcy-t,f=s.bcz-r,l=a*n+c*o+f*i,u=a-l*n,g=c-l*o,m=f-l*i;if(u*u+g*g+m*m>s.br2)return!1;let p=s.triFlat,h=p.length;for(let b=0;b<h;b+=9)if(Er(e,t,r,n,o,i,p,b))return!0;return!1}var Re=9,Rr=6,ee=12;function yt(e,t,r,n,o,i){let s=n-e,a=o-t,c=i-r;return s*a+a*c+c*s}function Lr(e){let t=[];for(let V=0;V<e.length;V++)e[V]&&t.push(V);let r=t.length,n=new Int32Array(r);for(let V=0;V<r;V++)n[V]=t[V];let o=new Float64Array(r),i=new Float64Array(r),s=new Float64Array(r);for(let V=0;V<r;V++){let I=e[n[V]];o[V]=(I.minX+I.maxX)*.5,i[V]=(I.minY+I.maxY)*.5,s[V]=(I.minZ+I.maxZ)*.5}let a=2*Math.max(1,r)+1,c=new Float64Array(a*Re),f=0,l=new Float64Array(ee),u=new Float64Array(ee),g=new Float64Array(ee),m=new Float64Array(ee),p=new Float64Array(ee),h=new Float64Array(ee),b=new Int32Array(ee),y=new Float64Array(ee-1),M=new Int32Array(ee-1),C=new Float64Array(ee-1),v=new Int32Array(ee-1);function x(V,I){let S=f++,E=S*Re,U=I-V,R=1/0,F=1/0,O=1/0,z=-1/0,L=-1/0,_=-1/0;for(let B=V;B<I;B++){let Y=e[n[B]];Y.minX<R&&(R=Y.minX),Y.maxX>z&&(z=Y.maxX),Y.minY<F&&(F=Y.minY),Y.maxY>L&&(L=Y.maxY),Y.minZ<O&&(O=Y.minZ),Y.maxZ>_&&(_=Y.maxZ)}if(c[E]=R,c[E+1]=F,c[E+2]=O,c[E+3]=z,c[E+4]=L,c[E+5]=_,U<=Rr)return c[E+6]=1,c[E+7]=V,c[E+8]=I,S;let T=1/0,P=1/0,d=1/0,A=-1/0,w=-1/0,N=-1/0;for(let B=V;B<I;B++)o[B]<T&&(T=o[B]),o[B]>A&&(A=o[B]),i[B]<P&&(P=i[B]),i[B]>w&&(w=i[B]),s[B]<d&&(d=s[B]),s[B]>N&&(N=s[B]);let k=A-T,G=w-P,$=N-d;if(k===0&&G===0&&$===0)return c[E+6]=1,c[E+7]=V,c[E+8]=I,S;let X=yt(R,F,O,z,L,_),H=X>0?1/X:0,Z=U+1,K=0,q=0;for(let B=0;B<3;B++){let Y=B===0?T:B===1?P:d,re=B===0?k:B===1?G:$;if(re===0)continue;let ae=B===0?o:B===1?i:s,me=ee/re;l.fill(1/0),u.fill(1/0),g.fill(1/0),m.fill(-1/0),p.fill(-1/0),h.fill(-1/0),b.fill(0);for(let D=V;D<I;D++){let j=(ae[D]-Y)*me|0;j>=ee&&(j=ee-1);let oe=e[n[D]];oe.minX<l[j]&&(l[j]=oe.minX),oe.maxX>m[j]&&(m[j]=oe.maxX),oe.minY<u[j]&&(u[j]=oe.minY),oe.maxY>p[j]&&(p[j]=oe.maxY),oe.minZ<g[j]&&(g[j]=oe.minZ),oe.maxZ>h[j]&&(h[j]=oe.maxZ),b[j]++}let ye=1/0,Pe=1/0,Je=1/0,Qe=-1/0,qe=-1/0,et=-1/0,Rt=0;for(let D=0;D<ee-1;D++)l[D]<ye&&(ye=l[D]),m[D]>Qe&&(Qe=m[D]),u[D]<Pe&&(Pe=u[D]),p[D]>qe&&(qe=p[D]),g[D]<Je&&(Je=g[D]),h[D]>et&&(et=h[D]),Rt+=b[D],y[D]=yt(ye,Pe,Je,Qe,qe,et),M[D]=Rt;let tt=1/0,nt=1/0,rt=1/0,ot=-1/0,it=-1/0,st=-1/0,Lt=0;for(let D=ee-2;D>=0;D--){let j=D+1;l[j]<tt&&(tt=l[j]),m[j]>ot&&(ot=m[j]),u[j]<nt&&(nt=u[j]),p[j]>it&&(it=p[j]),g[j]<rt&&(rt=g[j]),h[j]>st&&(st=h[j]),Lt+=b[j],C[D]=yt(tt,nt,rt,ot,it,st),v[D]=Lt}for(let D=0;D<ee-1;D++){if(M[D]===0||v[D]===0)continue;let j=.125+(y[D]*M[D]+C[D]*v[D])*H;j<Z&&(Z=j,K=B,q=Y+(D+1)/me)}}let ne=K===0?o:K===1?i:s,J=V,Q=I-1;for(;J<=Q;)if(ne[J]<q)J++;else{let B=n[J];n[J]=n[Q],n[Q]=B;let Y=o[J];o[J]=o[Q],o[Q]=Y;let re=i[J];i[J]=i[Q],i[Q]=re;let ae=s[J];s[J]=s[Q],s[Q]=ae,Q--}let ie=J;(ie===V||ie===I)&&(ie=V+I>>1),c[E+6]=0;let te=x(V,ie),W=x(ie,I);return c[S*Re+7]=te,c[S*Re+8]=W,S}return r>0&&x(0,r),{data:c,nodeCount:f,polyIndices:n,meta:e}}function mn(e,t,r,n,o,i,s,a,c){if(a.nodeCount===0)return!1;let{data:f,polyIndices:l,meta:u}=a,g=n!==0?1/n:n>=0?1/0:-1/0,m=o!==0?1/o:o>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,h=0;for(c[h++]=0;h>0;){let y=c[--h]*Re,M=(f[y]-e)*g,C=(f[y+3]-e)*g,v=M<C?M:C,x=M<C?C:M,V=(f[y+1]-t)*m,I=(f[y+4]-t)*m,S=V<I?V:I,E=V<I?I:V;if(v>E||S>x)continue;S>v&&(v=S),E<x&&(x=E);let U=(f[y+2]-r)*p,R=(f[y+5]-r)*p,F=U<R?U:R,O=U<R?R:U;if(!(v>O||F>x)&&(O<x&&(x=O),!(x<.001)))if(f[y+6]===1){let z=f[y+7]|0,L=f[y+8]|0;for(let _=z;_<L;_++){let T=l[_];if(T===s)continue;let P=u[T];if(P&&Or(e,t,r,n,o,i,P))return!0}}else c[h++]=f[y+7]|0,c[h++]=f[y+8]|0}return!1}function kr(e){let t=(1+Math.sqrt(5))/2,r=new Float64Array(e*3);for(let n=0;n<e;n++){let o=(n+.5)/e,i=Math.sqrt(Math.max(0,1-o*o)),s=2*Math.PI*(n/t);r[n*3]=i*Math.cos(s),r[n*3+1]=i*Math.sin(s),r[n*3+2]=o}return r}function Ur(e){let t=Math.abs(e[0])>.9?0:1,r=Math.abs(e[0])>.9?1:0,n=r*e[2],o=-t*e[2],i=t*e[1]-r*e[0],s=Math.hypot(n,o,i);n/=s,o/=s,i/=s;let a=e[1]*i-e[2]*o,c=e[2]*n-e[0]*i,f=e[0]*o-e[1]*n;return{ux:n,uy:o,uz:i,vx:a,vy:c,vz:f}}function Ge(e,t){let r=t?.samples??8;if(e.length<4||r<1)return e;let n=e.map(Tr),o=kr(r),i=[],s=Lr(n),a=new Int32Array(Math.max(64,s.nodeCount)),c=192,f=new Float64Array(c);for(let l=0;l<e.length;l++){let u=n[l];if(!u){i.push(e[l]);continue}let g=u.normal[0],m=u.normal[1],p=u.normal[2],h=.001*g,b=.001*m,y=.001*p;{let L=u.centroid[0]+h,_=u.centroid[1]+b,T=u.centroid[2]+y;if(!mn(L,_,T,g,m,p,l,s,a)){i.push(e[l]);continue}}let{ux:M,uy:C,uz:v,vx:x,vy:V,vz:I}=Ur(u.normal),S=u.centroid[0],E=u.centroid[1],U=u.centroid[2],R=u.vertices,F=R.length,O=0;f[O++]=S+h,f[O++]=E+b,f[O++]=U+y;for(let L=0;L<F;L++){let _=R[L];f[O++]=_[0]+(S-_[0])*.08+h,f[O++]=_[1]+(E-_[1])*.08+b,f[O++]=_[2]+(U-_[2])*.08+y}for(let L=0;L<F;L++){let _=R[L],T=R[(L+1)%F],P=(_[0]+T[0])*.5,d=(_[1]+T[1])*.5,A=(_[2]+T[2])*.5;f[O++]=P+(S-P)*.08+h,f[O++]=d+(E-d)*.08+b,f[O++]=A+(U-A)*.08+y}let z=!1;e:for(let L=0;L<o.length;L+=3){let _=o[L],T=o[L+1],P=o[L+2],d=_*M+T*x+P*g,A=_*C+T*V+P*m,w=_*v+T*I+P*p;for(let N=0;N<O;N+=3){let k=f[N],G=f[N+1],$=f[N+2];if(!mn(k,G,$,d,A,w,l,s,a)){z=!0;break e}}}z&&i.push(e[l])}return i}function Pt(e,t,r,n,o){let i=(p,h,b)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=h,y[(e+2)%3]=b,y},s=i(t,-n,-n),a=i(t,n,-n),c=i(t,n,n),f=i(t,-n,n),l=i(r,-n,-n),u=i(r,n,-n),g=i(r,n,n),m=i(r,-n,n);return[{vertices:[s,a,c,f],color:o},{vertices:[l,u,g,m],color:o},{vertices:[s,a,u,l],color:o},{vertices:[a,c,g,u],color:o},{vertices:[c,f,m,g],color:o},{vertices:[f,s,l,m],color:o}]}function At(e={}){let t=e.size??5,r=e.thickness??.025,n=e.negative??!1,o=e.xColor??"#ff3a3a",i=e.yColor??"#3aff3a",s=e.zColor??"#3a8aff",a=t*r/2,c=n?-t:0;return[...Pt(0,c,t,a,o),...Pt(1,c,t,a,i),...Pt(2,c,t,a,s)]}function gn(e,t,r,n){let o=[0,0,0];return o[e]=t,o[(e+1)%3]=r,o[(e+2)%3]=n,o}function Nr(e,t,r,n,o){let i=(p,h,b)=>gn(e,p,h,b),s=i(t,-n,-n),a=i(t,n,-n),c=i(t,n,n),f=i(t,-n,n),l=i(r,-n,-n),u=i(r,n,-n),g=i(r,n,n),m=i(r,-n,n);return[{vertices:[s,a,c,f],color:o},{vertices:[l,u,g,m],color:o},{vertices:[s,a,u,l],color:o},{vertices:[a,c,g,u],color:o},{vertices:[c,f,m,g],color:o},{vertices:[f,s,l,m],color:o}]}function _r(e,t,r,n,o){let i=(u,g,m)=>gn(e,u,g,m),s=i(t,-n,-n),a=i(t,n,-n),c=i(t,n,n),f=i(t,-n,n),l=i(r,0,0);return[{vertices:[s,a,c,f],color:o},{vertices:[s,a,l],color:o},{vertices:[a,c,l],color:o},{vertices:[c,f,l],color:o},{vertices:[f,s,l],color:o}]}function $r(e){return e.map(t=>({...t,vertices:[...t.vertices].reverse()}))}function Vt(e){let t=e.axis,r=e.sign??1,n=e.shaftLength??4,o=e.shaftHalfThickness??.05,i=e.headLength??.8,s=e.headHalfThickness??.2,a=e.color??"#ffffff",c=n*r,f=Math.min(0,c),l=Math.max(0,c),u=c,g=(n+i)*r,m=_r(t,u,g,s,a);return[...Nr(t,f,l,o,a),...r===-1?$r(m):m]}function Be(e,t,r){let n=[0,0,0],o=(e+1)%3,i=(e+2)%3;return n[o]=Math.cos(r)*t,n[i]=Math.sin(r)*t,n}function vt(e){let t=e.axis,r=e.radius,n=e.halfThickness??Math.max(.05,r*.04),o=e.segments??32,i=e.color??"#ffffff",s=r-n,a=r+n,c=[];for(let f=0;f<o;f++){let l=f/o*Math.PI*2,u=(f+1)/o*Math.PI*2,g=Be(t,s,l),m=Be(t,s,u),p=Be(t,a,l),h=Be(t,a,u);c.push({vertices:[g,p,h,m],color:i})}return c}function Mt(e){let{center:t,size:r,color:n="#ffffff"}=e,[o,i,s]=t,a=[[o+r,i,s],[o-r,i,s],[o,i+r,s],[o,i-r,s],[o,i,s+r],[o,i,s-r]];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(f=>({vertices:[a[f[0]],a[f[1]],a[f[2]]],color:n}))}var dn=2200,pn=2201,xn=2202;function zr(e,t){let r=0,n=1,o=1,i=2201,s=1/0,a=0,c=!1,f=null,l=!0,u=!1,g={clampWhenFinished:!1,get timeScale(){return o},set timeScale(m){o=m},get weight(){return n},set weight(m){n=m},get time(){return r},set time(m){r=m},get isRunning(){return c},get enabled(){return l},set enabled(m){l=m},get paused(){return u},set paused(m){u=m},play(){return c=!0,g},stop(){return c=!1,r=0,a=0,f=null,g},reset(){return r=0,a=0,g},fadeIn(m){return f={from:0,to:1,elapsed:0,duration:m},n=0,g},fadeOut(m){return f={from:n,to:0,elapsed:0,duration:m},g},crossFadeTo(m,p){return g.fadeOut(p),m.fadeIn(p),g},crossFadeFrom(m,p){return m.fadeOut(p),g.fadeIn(p),g},setLoop(m,p){return i=m,s=p,g},setEffectiveTimeScale(m){return o=m,g},setEffectiveWeight(m){return n=m,g}};return g._internal={get clip(){return e},get time(){return r},get weight(){return n},get enabled(){return l},get paused(){return u},get running(){return c},get loopMode(){return i},get repetitions(){return s},get completedReps(){return a},set completedReps(m){a=m},get clampWhenFinished(){return g.clampWhenFinished},get timeScale(){return o},get fade(){return f},advance(m){if(!c)return;if(f){f.elapsed+=m;let h=f.duration>0?Math.min(f.elapsed/f.duration,1):1;if(n=f.from+(f.to-f.from)*h,h>=1&&(n=f.to,f=null,n<=0)){c=!1;return}}if(u)return;let p=e.duration;if(!(p<=0)){if(r+=m*o,i===2200)r>=p&&(r=g.clampWhenFinished?p:0,c=!1);else if(i===2201){if(r>=p){let h=r%p,b=Math.floor(r/p);a+=b,r=h,s!==1/0&&a>=s&&(r=g.clampWhenFinished?p:0,c=!1)}}else if(p>0){let h=p*2,b=r%h;if(r>=h){let y=Math.floor(r/h);a+=y,s!==1/0&&a>=s?(r=g.clampWhenFinished?p:0,c=!1):r=b}}}},sampleTime(){if(i===2202){let m=e.duration,p=m*2,h=r%p;return h<=m?h:p-h}return r}},g}function Fr(e){return e._internal}function wt(e,t){return typeof t=="number"?e[t]:e.find(r=>r.name===t)}function hn(e,t){let r=new Map;function n(f){let l=wt(t.clips,f);if(!l)throw new Error(`PolyAnimationMixer: no clip found for key "${f}". Available: ${t.clips.map(g=>g.name).join(", ")}`);let u=r.get(l.index);return u||(u=zr(l,t),r.set(l.index,u)),u}function o(f){let l=wt(t.clips,f);return l?r.get(l.index)??null:null}function i(f){let l=[];for(let h of r.values()){let b=Fr(h);b.advance(f),b.running&&b.enabled&&l.push({internal:b,clip:b.clip})}if(l.length===0)return;if(l.length===1){let{internal:h,clip:b}=l[0],y=t.sample(b.name,h.sampleTime());e.setPolygons(y);return}let u=0;for(let{internal:h}of l)u+=h.weight;if(u<=0)return;let g=l.map(({internal:h,clip:b})=>({polygons:t.sample(b.name,h.sampleTime()),weight:h.weight/u})),m=g[0].polygons;if(m.length===0)return;let p=m.map((h,b)=>{let y=h.vertices.map((M,C)=>{let v=0,x=0,V=0;for(let{polygons:I,weight:S}of g){let E=I[b];if(!E)continue;let U=E.vertices[C];U&&(v+=U[0]*S,x+=U[1]*S,V+=U[2]*S)}return[v,x,V]});return{...h,vertices:y}});e.setPolygons(p)}function s(){for(let f of r.values())f.stop()}function a(f){let l=wt(t.clips,f);l&&r.delete(l.index)}function c(){r.clear()}return{clipAction:n,existingAction:o,update:i,stopAllAction:s,uncacheClip:a,uncacheRoot:c}}var Gr=/^[0-9A-Fa-f]{6}$/,Br=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function De(e,t){let r=t?.targetSize??60,n=t?.gridShift??1,o=t?.defaultColor??"#888888",i=t?.palette??Br,s=t?.materialColors??{},a=t?.materialTextures??{},c=[],f=[],l=[],u=[],g=new Map,m=o,p,h=t?.includeObjects?new Set(t.includeObjects):null,b=t?.excludeObjects?new Set(t.excludeObjects):null,y=null,M=()=>y===null?h===null:!(h&&!h.has(y)||b&&b.has(y)),C=T=>T in s?s[T]:Gr.test(T)?`#${T}`:(g.has(T)||(g.set(T,i[u.length%i.length]),u.push(T)),g.get(T)),v=e.split(`
|
|
2
|
-
`);for(let
|
|
3
|
-
`)){let i=o.trim();if(!(i.length===0||i.charCodeAt(0)===35)){if(i.startsWith("newmtl ")){n=i.slice(7).trim();continue}if(n){if(i.startsWith("Kd ")){let s=i.split(/\s+/),a=parseFloat(s[1]),c=parseFloat(s[2]),f=parseFloat(s[3]);Number.isFinite(a)&&Number.isFinite(c)&&Number.isFinite(f)&&(t[n]=`#${St(a)}${St(c)}${St(f)}`)}else if(i.startsWith("map_Kd ")){let s=i.split(/\s+/),a=s[s.length-1]?.replace(/\\+/g,"/");a&&a!=="map_Kd"&&(r[n]=a)}}}}return{colors:t,textures:r}}var Vn={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},vn={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Mn(e){let t=globalThis.TextDecoder;return new t().decode(e)}function jr(e){let t=e.indexOf(",");if(t<0)throw new Error("parseGltf: malformed data: URI");let r=e.slice(5,t),n=e.slice(t+1);if(!r.includes(";base64")){let s=decodeURIComponent(n),a=new Uint8Array(s.length);for(let c=0;c<s.length;c++)a[c]=s.charCodeAt(c)&255;return a}let o=globalThis.atob(n),i=new Uint8Array(o.length);for(let s=0;s<o.length;s++)i[s]=o.charCodeAt(s);return i}function Xr(e,t){let r=e.buffers?.[0];if(!r)throw new Error("parseGltf: JSON doc has no buffers[0]");let n=r.uri;if(!n)throw new Error("parseGltf: JSON doc buffer has no uri (and there's no GLB BIN chunk)");if(n.startsWith("data:"))return jr(n);if(t){let o=t(n);if(o instanceof Uint8Array)return o;throw new Error("parseGltf: resolveBuffer returned a Promise; use parseGltf via async if your buffers are external")}throw new Error(`parseGltf: external buffer URI "${n}" \u2014 provide options.resolveBuffer`)}function Yr(e){let t=new DataView(e);if(t.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let r=t.getUint32(4,!0);if(r!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${r})`);let n=12,o=null,i=null;for(;n<e.byteLength;){let s=t.getUint32(n,!0),a=t.getUint32(n+4,!0),c=n+8;if(a===1313821514){let f=new Uint8Array(e,c,s);o=JSON.parse(Mn(f))}else a===5130562&&(i=new Uint8Array(e,c,s));n=c+s}if(!o)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:o,bin:i}}function It(e,t,r){let n=e.accessors?.[r],o=e.bufferViews?.[n?.bufferView??-1];if(!n||!o)throw new Error(`parseGltf: bad accessor/bufferView ${r}`);let i=Vn[n.componentType],s=vn[n.type];if(!i||!s)throw new Error(`parseGltf: unsupported accessor type ${n.type}/${n.componentType}`);let a=(o.byteOffset??0)+(n.byteOffset??0),c=n.count*s,f=t.buffer.slice(t.byteOffset+a,t.byteOffset+a+c*i),l;switch(n.componentType){case 5126:l=new Float32Array(f);break;case 5123:l=new Uint16Array(f);break;case 5125:l=new Uint32Array(f);break;case 5121:l=new Uint8Array(f);break;default:throw new Error(`parseGltf: unhandled componentType ${n.componentType}`)}return{array:l,count:n.count,componentCount:s}}function Hr(e,t,r){switch(r){case 5120:return e.getInt8(t);case 5121:return e.getUint8(t);case 5122:return e.getInt16(t,!0);case 5123:return e.getUint16(t,!0);case 5125:return e.getUint32(t,!0);case 5126:return e.getFloat32(t,!0);default:throw new Error(`parseGltf: unhandled componentType ${r}`)}}function Wr(e,t){switch(t){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 He(e,t,r){let n=e.accessors?.[r],o=e.bufferViews?.[n?.bufferView??-1];if(!n||!o)throw new Error(`parseGltf: bad accessor/bufferView ${r}`);let i=Vn[n.componentType],s=vn[n.type];if(!i||!s)throw new Error(`parseGltf: unsupported accessor type ${n.type}/${n.componentType}`);let a=t.byteOffset+(o.byteOffset??0)+(n.byteOffset??0),c=o.byteStride??i*s,f=new DataView(t.buffer),l=new Array(n.count*s),u=0;for(let g=0;g<n.count;g++){let m=a+g*c;for(let p=0;p<s;p++){let h=Hr(f,m+p*i,n.componentType);l[u++]=n.normalized?Wr(h,n.componentType):h}}return{values:l,count:n.count,componentCount:s}}function Zr(e,t,r){let n=[],o=[],i=globalThis;for(let s of e.images??[]){if(s.uri){if(r&&!s.uri.startsWith("data:"))try{n.push(new i.URL(s.uri,r).href)}catch{n.push(s.uri)}else n.push(s.uri);continue}if(s.bufferView!==void 0){let a=e.bufferViews?.[s.bufferView];if(!a){n.push("");continue}let c=a.byteOffset??0,f=t.subarray(c,c+a.byteLength),l=s.mimeType??"image/png",u=new i.Blob([f],{type:l}),g=i.URL.createObjectURL(u);n.push(g),o.push(g)}else n.push("")}return{urls:n,objectUrls:o}}function Kr(e,t){let r=new Map,n=e.materials??[];for(let o=0;o<n.length;o++){let i=n[o].pbrMetallicRoughness?.baseColorTexture?.index;if(i===void 0)continue;let s=e.textures?.[i]?.source;if(s===void 0)continue;let a=t[s];a&&r.set(o,a)}return r}function Jr(e,t){let r=e?.pbrMetallicRoughness?.baseColorFactor;if(!r||r.length<3)return t;let n=o=>Math.round(Math.max(0,Math.min(1,o))*255).toString(16).padStart(2,"0");return`#${n(r[0])}${n(r[1])}${n(r[2])}`}var Me=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Ct(e,t){let r=new Array(16);for(let n=0;n<4;n++)for(let o=0;o<4;o++)r[o*4+n]=e[0+n]*t[o*4+0]+e[4+n]*t[o*4+1]+e[8+n]*t[o*4+2]+e[12+n]*t[o*4+3];return r}function Ye(e,t){return[e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12],e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13],e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]]}function wn(e,t,r){let n=e?.[0]??0,o=e?.[1]??0,i=e?.[2]??0,s=t?.[0]??0,a=t?.[1]??0,c=t?.[2]??0,f=t?.[3]??1,l=r?.[0]??1,u=r?.[1]??1,g=r?.[2]??1,m=s+s,p=a+a,h=c+c,b=s*m,y=s*p,M=s*h,C=a*p,v=a*h,x=c*h,V=f*m,I=f*p,S=f*h;return[(1-(C+x))*l,(y+S)*l,(M-I)*l,0,(y-S)*u,(1-(b+x))*u,(v+V)*u,0,(M+I)*g,(v-V)*g,(1-(b+C))*g,0,n,o,i,1]}function Qr(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():wn(e.translation,e.rotation,e.scale)}function qr(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function bn(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function Sn(e,t,r){let n=new Array(Math.min(e.length,t.length));for(let o=0;o<n.length;o++)n[o]=e[o]+(t[o]-e[o])*r;return n}function Le(e){let t=Math.hypot(e[0]??0,e[1]??0,e[2]??0,e[3]??1)||1;return[(e[0]??0)/t,(e[1]??0)/t,(e[2]??0)/t,(e[3]??1)/t]}function eo(e,t,r){let n=Le(e),o=Le(t),i=n[0]*o[0]+n[1]*o[1]+n[2]*o[2]+n[3]*o[3];if(i<0&&(i=-i,o=[-o[0],-o[1],-o[2],-o[3]]),i>.9995)return Le(Sn(n,o,r));let s=Math.acos(Math.max(-1,Math.min(1,i))),a=Math.sin(s),c=Math.sin((1-r)*s)/a,f=Math.sin(r*s)/a;return Le([n[0]*c+o[0]*f,n[1]*c+o[1]*f,n[2]*c+o[2]*f,n[3]*c+o[3]*f])}function to(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 yn(e){return e.matrix?e.matrix.slice():wn(e.translation,e.rotation,e.scale)}function no(e){let t=e.scene??0,r=e.scenes?.[t]?.nodes;return r&&r.length>0?r:[]}function Pn(e,t){let r=e.nodes??[],n=new Array(r.length),o=new Set,i=(a,c)=>{if(a<0||a>=r.length)return;let f=Ct(c,t[a]??Me);n[a]=f,o.add(a);for(let l of r[a].children??[])i(l,f)},s=no(e);if(s.length>0)for(let a of s)i(a,Me);for(let a=0;a<r.length;a++)o.has(a)||i(a,Me);return n}function An(e,t,r,n,o){if(r===void 0)return;let{values:i,count:s,componentCount:a}=He(e,t,r);if(s!==o||a<1)return;let c=[];for(let f=0;f<s;f++){let l=[];for(let u=0;u<n;u++)l.push(i[f*a+u]??0);c.push(l)}return c}function ro(e,t,r,n){if(r===void 0)return Array.from({length:n},()=>Me.slice());let{values:o,componentCount:i,count:s}=He(e,t,r);if(i!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${r} is not MAT4`);let a=[];for(let c=0;c<n;c++){let f=Math.min(c,s-1);a.push(o.slice(f*16,f*16+16))}return a}function Xe(e,t){let r=e.componentCount,n=e.interpolation==="CUBICSPLINE"?(t*3+1)*r:t*r;return e.output.slice(n,n+r)}function oo(e,t,r){let n=e.input;if(n.length===0)return[];if(n.length===1||t<=n[0])return Xe(e,0);let o=n.length-1;if(t>=n[o])return Xe(e,o);let i=0,s=o;for(;i+1<s;){let g=i+s>>1;n[g]<=t?i=g:s=g}let a=n[i],c=n[i+1],f=c>a?(t-a)/(c-a):0,l=Xe(e,i),u=Xe(e,i+1);return e.interpolation==="STEP"?l:r==="rotation"?eo(l,u,f):Sn(l,u,f)}function io(e,t,r,n){let o=e.animations??[];if(o.length===0||r.length===0)return;let i=(e.nodes??[]).map(m=>to(m)),s=i.map(yn),a=Pn(e,s),c=(e.skins??[]).map(m=>({joints:m.joints??[],inverseBindMatrices:ro(e,t,m.inverseBindMatrices,m.joints?.length??0)})),f=[];for(let m=0;m<o.length;m++){let p=o[m],h=(p.samplers??[]).map(M=>{let C=He(e,t,M.input),v=He(e,t,M.output);return{input:C.values,output:v.values,componentCount:v.componentCount,interpolation:M.interpolation??"LINEAR"}}),b=[];for(let M of p.channels??[]){let C=M.target.node,v=M.target.path,x=h[M.sampler];C===void 0||!v||!x||v==="weights"||b.push({sampler:x,targetNode:C,path:v})}let y=b.reduce((M,C)=>{let v=C.sampler.input;return Math.max(M,v[v.length-1]??0)},0);f.push({info:{index:m,name:p.name??`animation_${m}`,duration:y,channelCount:b.length},channels:b})}let l=f.map(m=>m.info);if(l.length===0)return;let u=(m,p,h,b,y,M)=>{let C=n(m),v=n(p),x=n(h);if(C[0]===v[0]&&C[1]===v[1]&&C[2]===v[2]||C[0]===x[0]&&C[1]===x[1]&&C[2]===x[2]||v[0]===x[0]&&v[1]===x[1]&&v[2]===x[2])return null;let V={vertices:[C,v,x],color:b};return y&&(V.texture=y),M&&(V.uvs=M),V};return{clips:l,sample:(m,p)=>{let h=typeof m=="number"?f[m]:f.find(x=>x.info.name===m);if(!h)return[];let b=h.info.duration,y=b>0?(p%b+b)%b:Math.max(0,p),M=i.map(x=>({translation:x.translation.slice(),rotation:x.rotation.slice(),scale:x.scale.slice(),matrix:x.matrix?x.matrix.slice():void 0}));for(let x of h.channels){let V=M[x.targetNode];if(!V)continue;let I=oo(x.sampler,y,x.path);V.matrix=void 0,x.path==="translation"?V.translation=I.slice(0,3):x.path==="rotation"?V.rotation=Le(I.slice(0,4)):x.path==="scale"&&(V.scale=I.slice(0,3))}let C=Pn(e,M.map(yn)),v=[];for(let x of r){let V=[];if(x.skinIndex!==void 0&&x.joints&&x.weights&&c[x.skinIndex]){let I=c[x.skinIndex];for(let S=0;S<x.positions.length;S++){let E=x.positions[S],U=[0,0,0],R=0,F=x.joints[S]??[],O=x.weights[S]??[];for(let z=0;z<4;z++){let L=O[z]??0;if(L<=0)continue;let _=Math.round(F[z]??0),T=I.joints[_],P=C[T],d=I.inverseBindMatrices[_];if(!P||!d)continue;let A=Ct(P,d);U=qr(U,bn(Ye(A,E),L)),R+=L}V.push(R>0?bn(U,1/R):Ye(x.meshBindWorld,E))}}else{let I=x.meshNode!==null?C[x.meshNode]??x.meshBindWorld:x.meshBindWorld;for(let S of x.positions)V.push(Ye(I,S))}for(let I=0;I+2<x.indices.length;I+=3){let S=x.indices[I],E=x.indices[I+1],U=x.indices[I+2],R=V[S],F=V[E],O=V[U];if(!R||!F||!O)continue;let z;if(x.uvs&&x.texture){let _=x.uvs[S],T=x.uvs[E],P=x.uvs[U];_&&T&&P&&(z=[_,T,P])}let L=u(R,F,O,x.color,x.texture,z);L&&v.push(L)}}return v}}}function We(e,t){let r=t?.targetSize??60,n=t?.gridShift??1,o=t?.defaultColor??"#888888",i=t?.materialColors??{},s=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,a=s.byteLength,c,f;if(s.byteLength>=4&&new DataView(s).getUint32(0,!0)===1179937895){let d=Yr(s);if(c=d.doc,!d.bin)throw new Error("parseGltf: GLB has no binary chunk");f=d.bin}else c=JSON.parse(Mn(new Uint8Array(s))),f=Xr(c,t?.resolveBuffer);let{urls:l,objectUrls:u}=Zr(c,f,t?.baseUrl),g=Kr(c,l),m=[],p=[],h=(c.meshes??[]).map((d,A)=>d.name??`mesh_${A}`),b=(c.materials??[]).map((d,A)=>d.name??`material_${A}`);function y(d,A,w){let N=c.meshes?.[d];if(N)for(let k of N.primitives){if((k.mode??4)!==4)continue;let $=k.material!==void 0?c.materials?.[k.material]?.name:void 0,H=($?i[$]:void 0)??Jr(k.material!==void 0?c.materials?.[k.material]:void 0,o),Z=k.material!==void 0?g.get(k.material):void 0,{array:K,count:q}=It(c,f,k.attributes.POSITION);if(!(K instanceof Float32Array))continue;let ne=[],J=[];for(let W=0;W<q;W++){let B=[K[W*3],K[W*3+1],K[W*3+2]];ne.push(B),J.push(Ye(A,B))}let Q=null,ie=k.attributes.TEXCOORD_0;if(Z&&ie!==void 0){let{array:W,count:B}=It(c,f,ie);Q=[];let Y=1;W instanceof Uint8Array?Y=1/255:W instanceof Uint16Array&&(Y=1/65535);for(let re=0;re<B;re++){let ae=W[re*2]*Y,me=W[re*2+1]*Y;Q.push([ae,1-me])}}let te;if(k.indices!==void 0){let{array:W,count:B}=It(c,f,k.indices);te=[];for(let Y=0;Y<B;Y++)te.push(Number(W[Y]))}else te=J.map((W,B)=>B);if((c.animations?.length??0)>0){let W=An(c,f,k.attributes.JOINTS_0,4,q),B=An(c,f,k.attributes.WEIGHTS_0,4,q);p.push({meshNode:w,meshBindWorld:A,skinIndex:w!==null?c.nodes?.[w]?.skin:void 0,positions:ne,indices:te,color:H,texture:Z,uvs:Q??void 0,joints:W,weights:B})}for(let W=0;W+2<te.length;W+=3){let B=J[te[W]],Y=J[te[W+1]],re=J[te[W+2]];if(!B||!Y||!re)continue;let ae;if(Q&&Z){let me=Q[te[W]],ye=Q[te[W+1]],Pe=Q[te[W+2]];me&&ye&&Pe&&(ae=[me,ye,Pe])}m.push({v0:B,v1:Y,v2:re,color:H,texture:Z,uvs:ae})}}}function M(d,A){let w=c.nodes?.[d];if(!w)return;let N=Ct(A,Qr(w));typeof w.mesh=="number"&&y(w.mesh,N,d);for(let k of w.children??[])M(k,N)}let C=c.scene??0,v=c.scenes?.[C]?.nodes;if(v&&v.length>0)for(let d of v)M(d,Me);else for(let d=0;d<(c.meshes?.length??0);d++)y(d,Me,null);let x=so(u);if(m.length===0)return{polygons:[],objectUrls:u,dispose:x,warnings:[],metadata:{triangleCount:0,meshes:h,materials:b,sourceBytes:a}};let V=1/0,I=1/0,S=1/0,E=-1/0,U=-1/0,R=-1/0;for(let d of m)for(let A of[d.v0,d.v1,d.v2])A[0]<V&&(V=A[0]),A[0]>E&&(E=A[0]),A[1]<I&&(I=A[1]),A[1]>U&&(U=A[1]),A[2]<S&&(S=A[2]),A[2]>R&&(R=A[2]);let F=Math.max(E-V,U-I,R-S),O=F>0?r/F:1,z=d=>Math.round(d*1e3)/1e3,_=(t?.upAxis??"y")==="z"?([d,A,w])=>[z((d-V)*O+n),z((A-I)*O+n),z((w-S)*O+n)]:([d,A,w])=>[z((w-S)*O+n),z((d-V)*O+n),z((A-I)*O+n)],T=io(c,f,p,_),P=[];for(let d of m){let A=_(d.v0),w=_(d.v1),N=_(d.v2);if(A[0]===w[0]&&A[1]===w[1]&&A[2]===w[2]||A[0]===N[0]&&A[1]===N[1]&&A[2]===N[2]||w[0]===N[0]&&w[1]===N[1]&&w[2]===N[2])continue;let k={vertices:[A,w,N],color:d.color};d.texture&&(k.texture=d.texture),d.uvs&&(k.uvs=d.uvs),P.push(k)}return{polygons:P,animation:T,objectUrls:u,dispose:x,warnings:[],metadata:{triangleCount:P.length,meshes:h,materials:b,animations:T?.clips,sourceBytes:a}}}function so(e){let t=!1;return()=>{if(t)return;t=!0;let r=globalThis.URL;if(r?.revokeObjectURL)for(let n of e)try{r.revokeObjectURL(n)}catch{}}}function Tt(e){return e.material?.texture??e.texture}function co(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function ao(e,t){return new Promise((r,n)=>{let o=new t,i=!1,s=a=>{i||(i=!0,a())};o.decoding="async",o.onload=()=>s(()=>r(o)),o.onerror=()=>s(()=>n(new Error(`texture load failed: ${e}`))),o.src=e,typeof o.decode=="function"&&o.decode().then(()=>s(()=>r(o)),()=>{})})}async function fo(e,t,r){try{let n=await ao(e,t.Image),o=Math.max(0,Math.floor(n.naturalWidth||n.width||0)),i=Math.max(0,Math.floor(n.naturalHeight||n.height||0));if(o<=0||i<=0||o*i>r)return null;let s=t.createCanvas();s.width=o,s.height=i;let a=s.getContext("2d",{willReadFrequently:!0});return a?(a.drawImage(n,0,0,o,i),{width:o,height:i,data:a.getImageData(0,0,o,i).data}):null}catch{return null}}function In(e,t,r){return Math.max(t,Math.min(r,e))}function lo(e,t){let r=t[0],n=1-t[1];if(!Number.isFinite(r)||!Number.isFinite(n))return null;let o=In(Math.floor(r*e.width),0,e.width-1),s=(In(Math.floor(n*e.height),0,e.height-1)*e.width+o)*4;return{r:e.data[s]??0,g:e.data[s+1]??0,b:e.data[s+2]??0,a:e.data[s+3]??255}}function he(e,t,r,n,o,i){return[e[0]*n+t[0]*o+r[0]*i,e[1]*n+t[1]*o+r[1]*i]}function uo(e){let[t,r,n]=e;return[he(t,r,n,1/3,1/3,1/3),he(t,r,n,.8,.1,.1),he(t,r,n,.1,.8,.1),he(t,r,n,.1,.1,.8),he(t,r,n,.45,.45,.1),he(t,r,n,.45,.1,.45),he(t,r,n,.1,.45,.45)]}function Cn(e){if(e.textureTriangles?.length)return e.textureTriangles;let t=e.uvs;if(!t||t.length!==e.vertices.length||t.length<3)return[];let r=[];for(let n=1;n+1<t.length;n++)r.push({uvs:[t[0],t[n],t[n+1]]});return r}function mo(e,t,r){return Math.abs(e.r-t.r)<=r&&Math.abs(e.g-t.g)<=r&&Math.abs(e.b-t.b)<=r&&Math.abs(e.a-t.a)<=r}function go(e){let t=n=>Math.round(Math.max(0,Math.min(255,n))).toString(16).padStart(2,"0");if(e.a>=255)return`#${t(e.r)}${t(e.g)}${t(e.b)}`;let r=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)}, ${r})`}function po(e,t,r){let n=Cn(e);if(n.length===0)return null;let o=null;for(let i of n)for(let s of uo(i.uvs)){let a=lo(t,s);if(!a)return null;if(!o)o=a;else if(!mo(o,a,r))return null}return o?go(o):null}function xo(e,t){let{texture:r,material:n,uvs:o,textureTriangles:i,...s}=e;return{...s,color:t}}async function Tn(e,t={}){if(t.enabled===!1)return null;let r=co();if(!r)return null;let n=e.filter(a=>Tt(a)&&Cn(a).length>0);if(n.length===0)return null;let o=t.maxTexturePixels??16777216,i=new Map;await Promise.all(Array.from(new Set(n.map(a=>Tt(a)))).map(async a=>{i.set(a,await fo(a,r,o))}));let s=t.colorTolerance??2;return{bake(a){let c=!1,f=a.map(l=>{let u=Tt(l);if(!u)return l;let g=i.get(u);if(!g)return l;let m=po(l,g,s);return m?(c=!0,xo(l,m)):l});return{polygons:c?f:a,changed:c}}}}async function En(e,t={}){let r=await Tn(e,t);return r?r.bake(e).polygons:e}async function Ze(e,t={}){let r=await Tn(e.polygons,t);if(!r)return e;let n=r.bake(e.polygons);return!n.changed&&!e.animation?e:{...e,polygons:n.polygons,animation:e.animation?{...e.animation,sample(o,i){return r.bake(e.animation.sample(o,i)).polygons}}:e.animation}}var ho=[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 bo(e){let t=e>>0&255,r=e>>8&255,n=e>>16&255;return[t,r,n]}function Et(e){return(e&255).toString(16).padStart(2,"0")}function On(e,t,r){return`#${Et(e)}${Et(t)}${Et(r)}`}var yo=542658390;function Ke(e,t){let r=t?.targetSize??60,n=t?.gridShift??0,o=e.byteLength;if(e.byteLength<8)return we(o,["parseVox: buffer too small to be a valid .vox file"]);let i=new DataView(e);if(i.getUint32(0,!0)!==yo)return we(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return we(o,["parseVox: buffer too small for MAIN chunk"]);if(Rn(i,8)!=="MAIN")return we(o,["parseVox: expected MAIN chunk at offset 8"]);let f=20+i.getUint32(12,!0),l=f+i.getUint32(16,!0),u=[],g=[],m=null;for(;f<l&&f+12<=e.byteLength;){let P=Rn(i,f),d=i.getUint32(f+4,!0),A=i.getUint32(f+8,!0),w=f+12,N=w+d+A;if(P==="SIZE"){if(d>=12&&w+12<=e.byteLength){let k=i.getUint32(w,!0),G=i.getUint32(w+4,!0),$=i.getUint32(w+8,!0);u.push({sx:k,sy:G,sz:$})}}else if(P==="XYZI"){if(d>=4&&w+4<=e.byteLength){let k=i.getUint32(w,!0),G=[],$=Math.min(k,Math.floor((d-4)/4));for(let X=0;X<$;X++){let H=w+4+X*4;G.push({x:i.getUint8(H),y:i.getUint8(H+1),z:i.getUint8(H+2),colorIndex:i.getUint8(H+3)})}g.push(G)}}else if(P==="RGBA"&&d>=1024&&w+1024<=e.byteLength){m=[];for(let k=0;k<256;k++){let G=w+k*4,$=i.getUint8(G),X=i.getUint8(G+1),H=i.getUint8(G+2);m.push(On($,X,H))}}f=N}let p=[],h=new Set;for(let P of g)for(let d of P){if(d.colorIndex===0)continue;let A=`${d.x},${d.y},${d.z}`;h.has(A)||(h.add(A),p.push(d))}if(p.length===0)return we(o,[]);let b=P=>{let d=P-1;if(m!==null)return m[d]??"#888888";let A=ho[P]??0,[w,N,k]=bo(A);return On(w,N,k)},y=(P,d,A)=>h.has(`${P},${d},${A}`),M=new Map,C=(P,d,A,w,N)=>{let k=`${P}:${d}:${N}`,G=M.get(k);G||(G=new Set,M.set(k,G)),G.add(`${A},${w}`)};for(let P of p){let{x:d,y:A,z:w}=P,N=b(P.colorIndex);y(d+1,A,w)||C(0,d+1,A,w,N),y(d-1,A,w)||C(1,d,A,w,N),y(d,A+1,w)||C(2,A+1,d,w,N),y(d,A-1,w)||C(3,A,d,w,N),y(d,A,w+1)||C(4,w+1,d,A,N),y(d,A,w-1)||C(5,w,d,A,N)}function v(P){let d=new Set,A=[],w=1/0,N=-1/0,k=1/0,G=-1/0;for(let $ of P){let[X,H]=$.split(","),Z=+X,K=+H;Z<w&&(w=Z),Z>N&&(N=Z),K<k&&(k=K),K>G&&(G=K)}for(let $=k;$<=G;$++)for(let X=w;X<=N;X++){let H=`${X},${$}`;if(!P.has(H)||d.has(H))continue;let Z=1;for(;X+Z<=N;){let q=`${X+Z},${$}`;if(!P.has(q)||d.has(q))break;Z++}let K=1;e:for(;$+K<=G;){for(let q=0;q<Z;q++){let ne=`${X+q},${$+K}`;if(!P.has(ne)||d.has(ne))break e}K++}for(let q=0;q<K;q++)for(let ne=0;ne<Z;ne++)d.add(`${X+ne},${$+q}`);A.push({u:X,v:$,w:Z,h:K})}return A}let x=(P,d,A,w,N,k)=>{let G=A+N,$=w+k;switch(P){case 0:return[[d,A,w],[d,G,w],[d,G,$],[d,A,$]];case 1:return[[d,G,w],[d,A,w],[d,A,$],[d,G,$]];case 2:return[[A,d,w],[A,d,$],[G,d,$],[G,d,w]];case 3:return[[G,d,w],[G,d,$],[A,d,$],[A,d,w]];case 4:return[[A,w,d],[G,w,d],[G,$,d],[A,$,d]];default:return[[A,$,d],[G,$,d],[G,w,d],[A,w,d]]}},V=[];for(let[P,d]of M){let A=P.indexOf(":"),w=P.indexOf(":",A+1),N=+P.slice(0,A),k=+P.slice(A+1,w),G=P.slice(w+1);for(let{u:$,v:X,w:H,h:Z}of v(d))V.push({vertices:x(N,k,$,X,H,Z),color:G})}if(V.length===0)return we(o,[]);let I=1/0,S=1/0,E=1/0,U=-1/0,R=-1/0,F=-1/0;for(let P of V)for(let d of P.vertices)d[0]<I&&(I=d[0]),d[0]>U&&(U=d[0]),d[1]<S&&(S=d[1]),d[1]>R&&(R=d[1]),d[2]<E&&(E=d[2]),d[2]>F&&(F=d[2]);let O=Math.max(U-I,R-S,F-E),z=O>0?r/O:1,L=P=>Math.round(P*1e3)/1e3,_=P=>[L((P[0]-I)*z+n),L((P[1]-S)*z+n),L((P[2]-E)*z+n)],T=V.map(({vertices:P,color:d})=>({vertices:P.map(_),color:d}));return{polygons:T,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:T.length,sourceBytes:o,voxelCount:p.length}}}function Rn(e,t){return String.fromCharCode(e.getUint8(t))+String.fromCharCode(e.getUint8(t+1))+String.fromCharCode(e.getUint8(t+2))+String.fromCharCode(e.getUint8(t+3))}function we(e,t){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:t,metadata:{triangleCount:0,sourceBytes:e}}}var be="loadMesh";function Ot(e){let t=Ge(e.polygons),r=Ve(t);return r.length===e.polygons.length?e:{...e,polygons:r}}async function Ln(e,t){let r=t?.solidTextureSamples;return r===!1?e:Ze(e,typeof r=="object"?r:void 0)}function Po(e){let t=e.split("?")[0].split("#")[0],r=t.lastIndexOf(".");return r<0?"":t.slice(r+1).toLowerCase()}async function kn(e,t){let r=Po(e);if(r==="mtl")throw new Error(`${be}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let n=globalThis.fetch;if(!n)throw new Error(`${be}: no fetch() in this environment`);let o=t?.baseUrl??e;if(r==="obj"){let i=await n(e);if(!i.ok)throw new Error(`${be}: ${e} \u2192 ${i.status}`);let s=await i.text(),a=t?.objOptions;if(t?.mtlUrl){let f=await n(t.mtlUrl);if(!f.ok)throw new Error(`${be}: ${t.mtlUrl} \u2192 ${f.status}`);let l=await f.text(),{colors:u,textures:g}=je(l),m={},p=globalThis.URL,h=globalThis.document?.baseURI,b=t.mtlUrl;if(p&&h)try{b=new p(t.mtlUrl,h).toString()}catch{}for(let[y,M]of Object.entries(g)){if(p)try{m[y]=new p(M,b).toString();continue}catch{}let C=t.mtlUrl.lastIndexOf("/"),v=C>=0?t.mtlUrl.slice(0,C+1):"";m[y]=M.startsWith("/")||/^https?:\/\//.test(M)?M:v+M}a={...a??{},materialColors:{...u,...a?.materialColors??{}},materialTextures:{...m,...a?.materialTextures??{}}}}let c=De(s,a);return Ot(await Ln(c,t))}if(r==="glb"||r==="gltf"){let i=await n(e);if(!i.ok)throw new Error(`${be}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer(),a=We(s,{baseUrl:o,...t?.gltfOptions??{}});return Ot(await Ln(a,t))}if(r==="vox"){let i=await n(e);if(!i.ok)throw new Error(`${be}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer();return Ot(Ke(s,t?.voxOptions))}throw new Error(`${be}: unsupported extension ".${r}" (supported: obj, glb, gltf, vox)`)}0&&(module.exports={BASE_TILE,DEFAULT_CAMERA_STATE,DEFAULT_PROJECTION,LoopOnce,LoopPingPong,LoopRepeat,arrowPolygons,axesHelperPolygons,bakeSolidTextureSampledPolygons,bakeSolidTextureSamples,buildSceneContext,clampChannel,computeSceneBbox,computeShapeLighting,computeTexturePaintMetrics,coverPlanarPolygons,createIsometricCamera,createPolyAnimationMixer,cullInteriorPolygons,formatColor,inverseRotateVec3,loadMesh,mergePolygons,normalizeInvertMultiplier,normalizePolygons,octahedronPolygons,parseColor,parseGltf,parseHexColor,parseMtl,parseObj,parsePureColor,parseRgbColor,parseVox,polygonFaces,ringPolygons,rotateVec3,shadeColor});
|
|
1
|
+
"use strict";var Qr=Object.defineProperty;var Cl=Object.getOwnPropertyDescriptor;var _l=Object.getOwnPropertyNames;var vl=Object.prototype.hasOwnProperty;var Il=(e,n)=>{for(var t in n)Qr(e,t,{get:n[t],enumerable:!0})},Vl=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of _l(n))!vl.call(e,o)&&o!==t&&Qr(e,o,{get:()=>n[o],enumerable:!(r=Cl(n,o))||r.enumerable});return e};var Ol=e=>Vl(Qr({},"__esModule",{value:!0}),e);var Yd={};Il(Yd,{ASYNC_RENDER_BUDGET_MS:()=>Tc,ATLAS_CANONICAL_SIZE_AUTO_DESKTOP:()=>Pr,ATLAS_CANONICAL_SIZE_EXPLICIT:()=>Se,ATLAS_MAX_SIZE:()=>Ge,ATLAS_PADDING:()=>ct,AUTO_ATLAS_LOW_AREA:()=>lt,AUTO_ATLAS_MAX_BITMAP_SIDE:()=>vn,AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP:()=>fr,AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE:()=>ur,AUTO_ATLAS_MEDIUM_AREA:()=>lr,AUTO_ATLAS_SCALE_GUARD:()=>mr,BAKED_SHADOW_MIN_UP:()=>va,BAKED_SHADOW_Z_SQUASH:()=>_a,BASE_TILE:()=>Un,BASIS_EPS:()=>re,BORDER_SHAPE_BLEED:()=>In,BORDER_SHAPE_CANONICAL_SIZE:()=>Ne,BORDER_SHAPE_CENTER_PERCENT:()=>dt,BORDER_SHAPE_POINT_EPS:()=>gt,CAMERA_BACKFACE_CULL_EPS:()=>rt,COLOR_PARSE_CACHE_MAX:()=>dr,CORNER_SHAPE_DUPLICATE_EPS:()=>pt,CORNER_SHAPE_POINT_EPS:()=>Ee,DECIMAL_SCALES:()=>xr,DEFAULT_AMBIENT_COLOR:()=>ln,DEFAULT_AMBIENT_INTENSITY:()=>un,DEFAULT_ATLAS_CSS_DECIMALS:()=>mt,DEFAULT_BORDER_SHAPE_DECIMALS:()=>hr,DEFAULT_CAMERA_STATE:()=>en,DEFAULT_LIGHT_COLOR:()=>an,DEFAULT_LIGHT_DIR:()=>sn,DEFAULT_LIGHT_INTENSITY:()=>cn,DEFAULT_MATRIX_DECIMALS:()=>we,DEFAULT_PROJECTION:()=>ti,DEFAULT_SEAM_BLEED:()=>Rc,DEFAULT_SEAM_FACET_SPLIT_OPTIONS:()=>bo,DEFAULT_SEAM_OVERLAP_OPTIONS:()=>xo,DEFAULT_TILE:()=>Le,LoopOnce:()=>as,LoopPingPong:()=>cs,LoopRepeat:()=>Qt,MAX_ATLAS_SCALE:()=>cr,MIN_ATLAS_SCALE:()=>ar,PROJECTIVE_QUAD_BLEED:()=>Sr,PROJECTIVE_QUAD_DENOM_EPS:()=>Ar,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO:()=>Mr,QUAT_IDENTITY:()=>hi,RECT_EPS:()=>ie,SEAM_LIGHT_EPS:()=>ut,SOLID_QUAD_CANONICAL_SIZE:()=>fn,SOLID_TRIANGLE_BLEED:()=>ft,SOLID_TRIANGLE_CANONICAL_SIZE:()=>br,SOLID_TRIANGLE_CORNER_CLASS:()=>Vc,SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE:()=>yr,SOLID_TRIANGLE_LARGE_BORDER_CLASS:()=>Oc,SURFACE_DISTANCE_EPS:()=>pr,SURFACE_NORMAL_EPS:()=>gr,TEXTURE_EDGE_REPAIR_ALPHA_MIN:()=>_c,TEXTURE_EDGE_REPAIR_RADIUS:()=>Ic,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN:()=>vc,TEXTURE_TRIANGLE_BLEED:()=>Cc,VOXEL_CAMERA_CULL_AXIS_EPS:()=>Bo,VOXEL_CAMERA_CULL_NORMAL_LIMIT:()=>ko,applyPackedAtlasCanonicalSize:()=>Kr,arrowPolygons:()=>Ho,atlasArea:()=>qr,atlasBitmapMaxSide:()=>$s,atlasCanonicalSizeForEntry:()=>ul,atlasCanonicalSizeForTextureQuality:()=>js,atlasDecodedBytes:()=>zs,atlasPadding:()=>Ys,autoAtlasBudgetFactor:()=>Xs,autoAtlasMaxDecodedBytes:()=>Ws,autoAtlasScale:()=>Gs,autoAtlasScaleCap:()=>Us,axesHelperPolygons:()=>Wo,bakeSolidTextureSampledPolygons:()=>dc,bakeSolidTextureSamples:()=>rr,basisAxisKey:()=>ws,borderShapeBoundsFromPoints:()=>Ss,borderShapeGeometryForPlan:()=>wn,boxPolygons:()=>Yo,buildBakedShadowProjectionMatrix:()=>Ia,buildBasisHints:()=>cl,buildSceneContext:()=>mi,buildSeamBleedPolygonEdges:()=>Ps,buildSeamBleedPolygonSet:()=>zc,buildTextureEdgeRepairSets:()=>$c,cachedParsePureColor:()=>gn,cameraCullNormalGroups:()=>$o,cameraCullNormalGroupsFromPolygons:()=>Ma,cameraCullNormalKey:()=>Go,cameraCullVisibleSignature:()=>Ea,cameraFacingDepth:()=>Uo,chooseIslandXAxis:()=>Ds,chooseLocalBasis:()=>Wr,clampChannel:()=>je,clipPolygonToConvex2D:()=>wa,colorErrorScore:()=>Hc,compatibleBleedSurface:()=>jr,compatibleSurface:()=>Ls,computePlanSeamBleedEdgeAmounts:()=>Rr,computeProjectiveQuadCoefficients:()=>$r,computeProjectiveQuadMatrix:()=>Vs,computeSceneBbox:()=>ro,computeSeamBleedInsets:()=>wr,computeShapeLighting:()=>ci,computeSolidTriangleColorPlan:()=>rl,computeSolidTriangleColorPlanFromNormal:()=>Ur,computeSolidTrianglePlan:()=>ol,computeSolidTrianglePlanFromCssPoints:()=>Gr,computeSurfaceNormal:()=>qe,computeTextureAtlasPlan:()=>ks,computeTextureAtlasPlanPublic:()=>ll,computeTexturePaintMetrics:()=>gi,computeUvAffine:()=>Yr,computeUvSampleRect:()=>Hr,conePolygons:()=>rs,convexHull2D:()=>Oa,cornerShapeDiagonal:()=>_s,cornerShapeGeometryForPlan:()=>Qc,cornerShapePointSides:()=>Ts,coverPlanarPolygons:()=>Rt,createIsometricCamera:()=>Ei,createPolyAnimationMixer:()=>Na,crossVec:()=>il,cssBorderShapeForGeometry:()=>kr,cssBorderShapeForPlan:()=>Jc,cssPoints:()=>Xe,cullInteriorPolygons:()=>Be,cylinderPolygons:()=>ot,dedupeOverlappingPolygons:()=>Vi,dodecahedronPolygons:()=>ts,dominantCountKey:()=>Br,dotVec:()=>Et,ensureCcw2D:()=>Ra,eulerXYZFromQuat:()=>Pi,evaluateIslandAxis:()=>Ns,expandClipPoints:()=>mn,filterAtlasPlans:()=>qc,findOverlappingPolygonDuplicates:()=>$n,formatAffineMatrix3dColumns:()=>wc,formatAffineMatrix3dScalars:()=>Er,formatAffineMatrix3dTransformScalars:()=>Tr,formatAtlasMatrix:()=>Cr,formatBorderShapeElementStyle:()=>nl,formatBorderShapeEntryMatrix:()=>el,formatBorderShapeMatrix:()=>Nc,formatColor:()=>Fn,formatCornerShapeElementStyle:()=>tl,formatCssLength:()=>Lc,formatCssLengthPx:()=>Fc,formatMatrix3d:()=>Dc,formatMatrix3dValues:()=>$e,formatPercent:()=>ze,formatScaledMatrixFromPlan:()=>Vn,formatSolidQuadEntryMatrix:()=>Bc,formatSolidQuadMatrix:()=>bs,fullRectBounds:()=>As,getPolygonBasisInfo:()=>Rs,getSolidPaintDefaultsForPlansCore:()=>Zc,icosahedronPolygons:()=>ns,incrementCount:()=>Fr,intersect2DLines:()=>vr,intersect2DLinesRaw:()=>kc,inverseRotateVec3:()=>pi,isAxisAlignedSurfaceNormal:()=>zo,isBakedShadowCaster:()=>Va,isBasisOptimizable:()=>Os,isConvexPolygonPoints:()=>On,isFullRectBasis:()=>Fs,isFullRectSolid:()=>Ze,isProjectiveQuadPlan:()=>St,isSolidTrianglePlan:()=>pn,isVoxelCameraCullableNormalGroups:()=>Sa,loadMesh:()=>Ec,makeLocalBasis:()=>hn,mergePolygons:()=>Re,normalFacesCamera:()=>Kt,normalizeAtlasScale:()=>Dn,normalizeInvertMultiplier:()=>Si,normalizePolygons:()=>_t,normalizedSeamBleed:()=>Or,octahedronPolygons:()=>Qo,offsetConvexPolygonPoints:()=>dn,offsetConvexPolygonPointsByEdgeAmounts:()=>Rn,offsetStableTrianglePoints:()=>Ir,offsetTrianglePoints:()=>ht,optimizeAnimatedMeshPolygons:()=>pc,optimizeMeshPolygons:()=>jt,packTextureAtlasPlans:()=>Nn,packTextureAtlasPlansWithScaleCore:()=>fl,parseAlpha:()=>Pt,parseColor:()=>Je,parseGltf:()=>nr,parseHex:()=>De,parseHexColor:()=>Jr,parseMtl:()=>sr,parseObj:()=>or,parsePureColor:()=>Pn,parseRgbColor:()=>eo,parseVox:()=>ir,planePolygons:()=>Zo,polygonContainsPoint:()=>Ms,polygonCssSurfaceNormal:()=>Ht,polygonFaces:()=>di,polygonFacesCamera:()=>Aa,polygonSignedArea2D:()=>ss,projectCssVertexToGround:()=>La,projectTextureTriangle:()=>Bs,quantizeCssColor:()=>Dr,quatFromAxisAngle:()=>bi,quatFromEulerXYZ:()=>yi,quatMultiply:()=>xi,repairMeshSeams:()=>Ut,resolveProjectiveQuadGuards:()=>Is,resolveSeamBleed:()=>xt,rgbEqual:()=>Wc,rgbKey:()=>Nr,rgbToCss:()=>Yc,rgbToHex:()=>At,ringPolygons:()=>Ko,ringQuadPolygons:()=>qo,rotateVec3:()=>Bn,roundDecimal:()=>ue,safariCssProjectiveUnsupported:()=>Kc,safePlanSeamBleedAmount:()=>bt,seamBleedAmountArray:()=>Lr,seamFacetSplitPolygons:()=>Co,seamFacetSplitReport:()=>ra,seamLightBrightness:()=>zr,seamOverlapDiagnostics:()=>oa,seamOverlapPolygons:()=>_o,seamOverlapReport:()=>sa,shadeColor:()=>ai,shadePolygon:()=>Ln,sharedCornerShapeSide:()=>Cs,signedArea2D:()=>_r,simplifyCornerShapePoints:()=>Es,spherePolygons:()=>Jo,stableBasisFromPlan:()=>ys,stableTriangleMatrixDecimals:()=>Vr,stepRgbToward:()=>jc,tetrahedronPolygons:()=>es,textureTintFactors:()=>Mt,tintToCss:()=>Xc,torusPolygons:()=>os});module.exports=Ol(Yd);var ti="cubic";function Jr(e){let n=e.replace("#","");if(n.length===3){let t=parseInt(n[0]+n[0],16),r=parseInt(n[1]+n[1],16),o=parseInt(n[2]+n[2],16);return Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(o)?null:{rgb:[t,r,o],alpha:1}}if(n.length===6){let t=parseInt(n.slice(0,2),16),r=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16);return Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(o)?null:{rgb:[t,r,o],alpha:1}}return null}function eo(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 Pn(e){if(!e)return null;let n=e.trim(),t=Jr(n);return t||eo(n)}function je(e){return Math.max(0,Math.min(255,Math.round(e)))}function Fn(e){let[n,t,r]=e.rgb.map(je);return e.alpha<1?`rgba(${n}, ${t}, ${r}, ${e.alpha})`:`rgb(${n}, ${t}, ${r})`}var to={rgb:[204,204,204],alpha:1},ri=new Map;function Je(e){if(!e)return null;let n=e.trim(),t=ri.get(n);if(t)return t;let r=Pn(n);return r?(ri.set(n,r),r):null}function ai(e,n){let t=Je(e)??to,r=[je(t.rgb[0]+n),je(t.rgb[1]+n),je(t.rgb[2]+n)];return Fn({rgb:r,alpha:t.alpha})}var no={direction:[0,0,-1],color:"#ffffff",intensity:1},oi={color:"#ffffff",intensity:.4};function si(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 ii(e,n,t){let r=Je(n)??to;return e*(r.rgb[t]/255)}function ci(e,n,t,r){let o=Je(n)??to,s=si(t?.direction??no.direction),i=t?.color??no.color,a=Math.max(0,t?.intensity??no.intensity),c=r?.color??oi.color,l=Math.max(0,r?.intensity??oi.intensity),u=si(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),d=a*f,m=[0,0,0];for(let g=0;g<3;g=g+1){let h=o.rgb[g],p=ii(h,c,g)*l,x=ii(h,i,g)*d;m[g]=je(p+x)}return Fn({rgb:m,alpha:o.alpha})}var li="#cccccc",Tt=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],ui=(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,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Ct=e=>Math.hypot(e[0],e[1],e[2]);function Rl(e){let n=1/0,t=1/0,r=1/0,o=-1/0,s=-1/0,i=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>o&&(o=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<r&&(r=u[2]),u[2]>i&&(i=u[2]);let a=o-n,c=s-t,l=i-r;return Math.hypot(a,c,l)}function Ll(){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 _t(e){let n=[],t=[];if(!e||e.length===0)return{polygons:n,warnings:t};for(let r=0;r<e.length;r++){let o=e[r];if(!o||!Array.isArray(o.vertices)){t.push(`Polygon ${r}: missing vertices, dropped`);continue}let s=o.vertices;if(s.length<3){t.push(`Polygon ${r}: ${s.length} vertices (need >= 3), dropped`);continue}let i=Tt(s[1],s[0]),a=Tt(s[2],s[0]),c=ui(i,a),l=Ct(c);if(s.length===3){if(l<1e-12){Ct(i)<1e-12||Ct(a)<1e-12?t.push(`Polygon ${r}: zero-area triangle (coincident vertices), dropped`):t.push(`Polygon ${r}: vertices collinear, dropped`);continue}}else if(l<1e-12){t.push(`Polygon ${r}: first 3 vertices collinear, dropped`);continue}let u=[{...o,vertices:s.slice()}];if(s.length>=4){let f=[c[0]/l,c[1]/l,c[2]/l],d=fi(f,s[0]),m=Rl(s),g=Math.max(1e-6,m*.001),h=0;for(let p=3;p<s.length;p++){let x=Math.abs(fi(f,s[p])-d);x>h&&(h=x)}if(h>g){let p=[],x=o.uvs&&o.uvs.length===s.length?o.uvs:void 0;for(let b=1;b<s.length-1;b++){let P=[s[0].slice(),s[b].slice(),s[b+1].slice()],y=ui(Tt(P[1],P[0]),Tt(P[2],P[0]));if(Ct(y)<1e-12)continue;let M={...o,vertices:P};x&&(M.uvs=[x[0].slice(),x[b].slice(),x[b+1].slice()]),p.push(M)}if(p.length===0){t.push(`Polygon ${r}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${r}: ${s.length} non-coplanar vertices, fan-triangulated to ${p.length} triangles`),u=p}}for(let f of u){let d=wl(f,r,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function wl(e,n,t){let r={vertices:e.vertices},o=e.texture;if(typeof o=="string"&&o===""&&(o=void 0),e.color!==void 0&&o!==void 0&&Ll()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Je(e.color)?r.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${li}`),r.color=li)),o!==void 0&&(r.texture=o,e.textureWrap&&(r.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(r.textureAlphaMode=e.textureAlphaMode)),e.doubleSided===!0&&(r.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`):r.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let s={},i=!1;for(let a of Object.keys(e.data)){let c=e.data[a];typeof c=="string"||typeof c=="number"||typeof c=="boolean"?s[a]=c:(i=!0,t.push(`Polygon ${n}: data["${a}"] has non-primitive value, key dropped`))}Object.keys(s).length>0&&(r.data=s)}return r}function ro(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,t=1/0,r=1/0,o=-1/0,s=-1/0,i=-1/0,a=!1;for(let c of e)if(c?.vertices)for(let l of c.vertices)l&&(a=!0,l[0]<n&&(n=l[0]),l[0]>o&&(o=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<r&&(r=l[2]),l[2]>i&&(i=l[2]));return a?{min:[n,t,r],max:[o,s,i]}:{min:[0,0,0],max:[0,0,0]}}function mi(e){let n=e.polygons??[],t,r;if(e.skipNormalize)t=n,r=[];else{let a=_t(n);t=a.polygons,r=a.warnings}let o=ro(t),s=[o.max[0]-o.min[0],o.max[1]-o.min[1],o.max[2]-o.min[2]];return{context:{polygons:t,sceneBbox:o,warnings:r},dimensions:{sceneBbox:o,size:s},warnings:r}}function di(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function Nl(e){let n=e[0],t=e[1],r=e[2],o=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],s=[r[0]-n[0],r[1]-n[1],r[2]-n[2]],i=o[1]*s[2]-o[2]*s[1],a=o[2]*s[0]-o[0]*s[2],c=o[0]*s[1]-o[1]*s[0],l=Math.hypot(i,a,c);return l<=1e-9?null:[i/l,a/l,c/l]}function Dl(e){let n=0;for(let t=0;t<e.length;t++){let[r,o]=e[t],[s,i]=e[(t+1)%e.length];n+=r*i-s*o}return Math.abs(n)/2}function Fl(e,n,t){if(!e||e.length<3)return null;let r=e.map(a=>[a[1]*n,a[0]*n,a[2]*t]),o=Nl(r);if(!o)return null;let s=1/0,i=0;for(let a=0;a<r.length;a++){let c=r[a],l=r[(a+1)%r.length],u=[l[0]-c[0],l[1]-c[1],l[2]-c[2]],f=u[0]*o[0]+u[1]*o[1]+u[2]*o[2],d=[u[0]-f*o[0],u[1]-f*o[1],u[2]-f*o[2]],m=Math.hypot(d[0],d[1],d[2]);if(m<=1e-9)continue;let g=[d[0]/m,d[1]/m,d[2]/m],h=[o[1]*g[2]-o[2]*g[1],o[2]*g[0]-o[0]*g[2],o[0]*g[1]-o[1]*g[0]],p=Math.hypot(h[0],h[1],h[2]);if(p<=1e-9)continue;let x=[h[0]/p,h[1]/p,h[2]/p],b=r.map(_=>{let w=_[0]-c[0],V=_[1]-c[1],N=_[2]-c[2];return[w*g[0]+V*g[1]+N*g[2],w*x[0]+V*x[1]+N*x[2]]}),P=1/0,y=1/0,M=-1/0,S=-1/0;for(let[_,w]of b)P=Math.min(P,_),y=Math.min(y,w),M=Math.max(M,_),S=Math.max(S,w);let T=M-P,E=S-y,A=Math.max(1,Math.ceil(T))*Math.max(1,Math.ceil(E)),C=Dl(b);C<=1e-9||A<s&&(s=A,i=C)}return!Number.isFinite(s)||i<=1e-9?null:{elementArea:s,polygonArea:i}}function gi(e,n={}){let t=n.tileSize??100,r=n.layerElevation??t,o=n.texturedOnly??!0,s=0,i=0,a=0,c=0,l=0;for(let f of e){let d=!!f.texture;if(o&&!d)continue;let m=Fl(f.vertices,t,r);m&&(s+=1,d&&(i+=1),a+=m.elementArea,c+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,a-c);return{totalPolygons:e.length,measuredPolygons:s,texturedPolygons:i,elementArea:a,polygonArea:c,transparentArea:u,transparentRatio:a>0?u/a:0,overdrawRatio:c>0?a/c:0,worstTransparentRatio:l}}function Bn(e,n,t,r){let o=n*Math.PI/180,s=t*Math.PI/180,i=r*Math.PI/180,[a,c,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,c]=[a*u-c*f,a*f+c*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,l]=[a*u+l*f,-a*f+l*u]}if(o!==0){let u=Math.cos(o),f=Math.sin(o);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function pi(e,n){let t=-n[0]*Math.PI/180,r=-n[1]*Math.PI/180,o=-n[2]*Math.PI/180,[s,i,a]=e;if(t!==0){let c=Math.cos(t),l=Math.sin(t);[i,a]=[i*c-a*l,i*l+a*c]}if(r!==0){let c=Math.cos(r),l=Math.sin(r);[s,a]=[s*c+a*l,-s*l+a*c]}if(o!==0){let c=Math.cos(o),l=Math.sin(o);[s,i]=[s*c-i*l,s*l+i*c]}return[s,i,a]}var oo=Math.PI/180,kn=180/Math.PI,hi=[1,0,0,0];function xi(e,n){let[t,r,o,s]=e,[i,a,c,l]=n;return[t*i-r*a-o*c-s*l,t*a+r*i+o*l-s*c,t*c-r*l+o*i+s*a,t*l+r*c-o*a+s*i]}function bi(e,n){let t=n*.5,r=Math.sin(t);return[Math.cos(t),e[0]*r,e[1]*r,e[2]*r]}function yi(e){let n=e[0]*oo,t=e[1]*oo,r=e[2]*oo,o=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(t*.5),a=Math.sin(t*.5),c=Math.cos(r*.5),l=Math.sin(r*.5);return[o*i*c-s*a*l,s*i*c+o*a*l,o*a*c-s*i*l,o*i*l+s*a*c]}function Pi(e){let[n,t,r,o]=e,s=2*(t*o+n*r),i=2*(r*o-n*t),a=1-2*(t*t+r*r),c=2*(t*r-n*o),l=1-2*(r*r+o*o),u=Math.max(-1,Math.min(1,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,a)*kn,f*kn,Math.atan2(-c,l)*kn]:[Math.atan2(2*(r*o+n*t),1-2*(t*t+o*o))*kn,f*kn,0]}var Un=50;function Si(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var en={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},Ai=100,Mi=1e4,An=e=>Math.round(e*Ai)/Ai,Bl=e=>Math.round(e*Mi)/Mi;function Ei(e={}){let n={target:e.target??[...en.target],rotX:e.rotX??en.rotX,rotY:e.rotY??en.rotY,zoom:e.zoom??en.zoom,distance:e.distance??en.distance};function t(o){o.target!==void 0&&(n.target=[An(o.target[0]),An(o.target[1]),An(o.target[2])]),o.rotX!==void 0&&(n.rotX=An(o.rotX)),o.rotY!==void 0&&(n.rotY=An(o.rotY)),o.zoom!==void 0&&(n.zoom=Bl(o.zoom)),o.distance!==void 0&&(n.distance=An(o.distance))}function r(o={}){let i=(o.cols??0)*50,a=(o.rows??0)*50,[c,l,u]=n.target,f=l*50,d=c*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-d}px, ${-m}px)`,width:`${i}px`,height:`${a}px`}}return{state:n,update:t,getStyle:r}}var Ye=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],vt=(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]],Gn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],so=e=>Math.hypot(e[0],e[1],e[2]),Mn=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function kl(e){return`${e[0]},${e[1]},${e[2]}`}function Ci(e){if(e.length<3)return null;let n=Ye(e[1],e[0]),t=Ye(e[2],e[0]),r=vt(n,t),o=so(r);if(o<1e-12)return null;let s=[r[0]/o,r[1]/o,r[2]/o],i=Gn(s,e[0]);return{normal:s,d:i}}function Ul(e,n){return Gn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function Gl(e,n){return Gn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function $l(e,n,t,r){let o=e.vertices.findIndex(E=>Mn(E,t)),s=e.vertices.findIndex(E=>Mn(E,r)),i=n.vertices.findIndex(E=>Mn(E,t)),a=n.vertices.findIndex(E=>Mn(E,r));if(o<0||s<0||i<0||a<0)return null;let c=e.vertices.length,l=n.vertices.length,u=(o+1)%c===s,f=(i+1)%l===a;if(u===f)return null;let d=u?s:o,m=u?o:s,g=f?a:i,h=f?i:a,p=!!(e.uvs&&n.uvs),x=[],b=p?[]:void 0,P=d;for(;x.push(e.vertices[P]),b&&b.push(e.uvs[P]),P!==m;)P=(P+1)%c;for(P=g;x.push(n.vertices[P]),b&&b.push(n.uvs[P]),P!==h;)P=(P+1)%l;let y=[],M=b?[]:void 0;for(let E=0;E<x.length;E++)(y.length===0||!Mn(x[E],y[y.length-1]))&&(y.push(x[E]),M&&b&&M.push(b[E]));if(y.length>1&&Mn(y[0],y[y.length-1])&&(y.pop(),M?.pop()),p)return Ti(y,M);let S=[],T=M?[]:void 0;for(let E=0;E<y.length;E++){let A=y[(E-1+y.length)%y.length],C=y[E],_=y[(E+1)%y.length],w=vt(Ye(C,A),Ye(_,A));so(w)>1e-9&&(S.push(C),T&&M&&T.push(M[E]))}return S.length<3?null:Ti(S,T)}function zl(e,n){let t=e.length,r=0;for(let o=0;o<t;o++){let s=e[o],i=e[(o+1)%t],a=e[(o+2)%t],c=Ye(i,s),l=Ye(a,i),u=Gn(vt(c,l),n);if(Math.abs(u)<1e-9)continue;let f=u>0?1:-1;if(r===0)r=f;else if(f!==r)return!1}return!0}function Xl(e,n){if(e.length<3)return!1;let t=Ci(e);if(!t)return!1;for(let r of e)if(Math.abs(Gn(t.normal,r)-t.d)>n)return!1;return!0}function Wl(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function jl(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function Yl(e,n){return(e??"")===(n??"")}function Hl(e,n){let t=[];for(let r=1;r<e.length-1;r++)t.push({vertices:[[...e[0]],[...e[r]],[...e[r+1]]],uvs:[[...n[0]],[...n[r]],[...n[r+1]]]});return t}function Ti(e,n){for(let t=0;t<e.length;t++){let r=e[t],o=e[(t+1)%e.length],s=e[(t+2)%e.length];if(!(so(vt(Ye(o,r),Ye(s,r)))<=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 Re(e){let n=[],t=[],r=new WeakMap,o=m=>{let g=r.get(m);if(g)return g;let h=kl(m);return r.set(m,h),h},s=(m,g)=>{let h=o(m),p=o(g);return h<p?`${h}|${p}`:`${p}|${h}`},i=(m,g)=>`${o(m)}>${o(g)}`,a=m=>{let g=new Set;for(let h=0;h<m.length;h++)g.add(i(m[h],m[(h+1)%m.length]));return g},c=0,l=!1,u=m=>(c+=m,c<=8e6?!0:(l=!0,!1));for(let m of e??[]){if(!m||!m.vertices||m.vertices.length<3){m&&n.push(m);continue}let g=m.vertices,h=Ci(g);if(!h){n.push(m);continue}let p=m.texture&&m.uvs&&m.uvs.length===g.length?m.uvs.map(b=>[b[0],b[1]]):void 0,x=m.texture&&p?m.textureTriangles?.length?Wl(m.textureTriangles):Hl(g,p):void 0;t.push({vertices:g,uvs:p,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureTriangles:x,normal:h.normal,d:h.d,directedEdges:a(g),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let p=0;p<t.length;p++){let x=t[p];if(!x.alive)continue;let b=x.vertices.length;if(!u(b))return!1;for(let P=0;P<b;P++){let y=x.vertices[P],M=x.vertices[(P+1)%b],S=s(y,M),T=m.get(S);T?T.second<0&&(T.second=p):(T={a:y,b:M,first:p,second:-1},m.set(S,T))}}let g=!1,h=(p,x,b)=>p.directedEdges.has(i(x,b))?1:p.directedEdges.has(i(b,x))?-1:0;for(let p of m.values()){if(p.second<0)continue;let x=p.first,b=p.second;if(x===b)continue;let P=t[x],y=t[b];if(!P.alive||!y.alive||P.color!==y.color||P.texture!==y.texture||!jl(P.textureWrap,y.textureWrap)||!Yl(P.textureAlphaMode,y.textureAlphaMode)||P.doubleSided!==y.doubleSided)continue;let M=!!(P.texture||y.texture);if(M&&(!P.textureTriangles||!y.textureTriangles)||!!P.uvs!=!!y.uvs||(M?!Gl(P,y):!Ul(P,y)))continue;if(!u(P.vertices.length+y.vertices.length))return!1;let S=h(P,p.a,p.b);if(S===0)continue;let T=h(y,p.a,p.b);if(T===0||S===T)continue;let[E,A]=S===1?[p.a,p.b]:[p.b,p.a],C=$l(P,y,E,A);if(C){if(!u(C.vertices.length))return!1;C.vertices.length>96||Xl(C.vertices,.001)&&zl(C.vertices,P.normal)&&(P.vertices=C.vertices,P.uvs=C.uvs,P.directedEdges=a(C.vertices),P.textureTriangles=M?[...P.textureTriangles??[],...y.textureTriangles??[]]:void 0,y.alive=!1,g=!0)}}return g},d=0;for(;!l&&d<16&&f();)d++;for(let m of t){if(!m.alive)continue;let g={vertices:m.vertices.map(h=>[h[0],h[1],h[2]]),color:m.color};m.texture&&(g.texture=m.texture),m.texture&&m.textureWrap&&(g.textureWrap={...m.textureWrap}),m.texture&&m.textureAlphaMode&&(g.textureAlphaMode=m.textureAlphaMode),m.uvs&&(g.uvs=m.uvs.map(h=>[h[0],h[1]])),m.textureTriangles?.length&&(g.textureTriangles=m.textureTriangles),m.doubleSided&&(g.doubleSided=!0),m.data&&(g.data=m.data),n.push(g)}return n}var Kl=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],ql=(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]],Ie=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function Zl(e,n){let t=e.vertices;if(!t||t.length<3)return null;let r=0,o=0,s=0;for(let h=0;h<t.length;h++){let p=t[h],x=t[(h+1)%t.length];r+=(p[1]-x[1])*(p[2]+x[2]),o+=(p[2]-x[2])*(p[0]+x[0]),s+=(p[0]-x[0])*(p[1]+x[1])}let i=Math.hypot(r,o,s);if(i<1e-12)return null;let a=[r/i,o/i,s/i],c=0,l=0,u=0;for(let h of t)c+=h[0],l+=h[1],u+=h[2];let f=1/t.length,d=[c*f,l*f,u*f],m=Ie(a,d),g=i*.5;return{index:n,polygon:e,normal:a,d:m,centroid:d,area:g,local2D:null,bbox2D:null,basis:null}}function Ql(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&Ie(e.normal,n.normal)<0}function Jl(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*Ie(n,e),r=n[1]-e[1]*Ie(n,e),o=n[2]-e[2]*Ie(n,e),s=Math.hypot(t,r,o);t/=s,r/=s,o/=s;let i=[t,r,o],a=ql(e,i);return{u:i,v:a}}function eu(e){if(e.local2D)return;let n=Jl(e.normal),t=[],r=1/0,o=1/0,s=-1/0,i=-1/0;for(let a of e.polygon.vertices){let c=Ie(a,n.u),l=Ie(a,n.v);t.push([c,l]),c<r&&(r=c),c>s&&(s=c),l<o&&(o=l),l>i&&(i=l)}e.local2D=t,e.bbox2D={min:[r,o],max:[s,i]},e.basis=n}function nu(e,n){let t=[],r=1/0,o=1/0,s=-1/0,i=-1/0;for(let a of e.vertices){let c=Ie(a,n.u),l=Ie(a,n.v);t.push([c,l]),c<r&&(r=c),c>s&&(s=c),l<o&&(o=l),l>i&&(i=l)}return{local2D:t,bbox2D:{min:[r,o],max:[s,i]}}}function tu(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 _i(e,n){let t=!1;for(let r=0,o=n.length-1;r<n.length;o=r++){let s=n[r],i=n[o];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 r of e)n+=r[0],t+=r[1];return[n/e.length,t/e.length]}function ru(e,n){let t=vi(e),r=vi(n),o=1e-4,s=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*o,l[1]+(t[1]-l[1])*o];_i(u,n)&&s++}let i=0;for(let l of n){let u=[l[0]+(r[0]-l[0])*o,l[1]+(r[1]-l[1])*o];_i(u,e)&&i++}let a=s/e.length,c=i/n.length;return Math.max(a,c)}function ou(e,n){let t=e.normal[0],r=e.normal[1],o=e.normal[2],s=Math.abs(t),i=Math.abs(r),a=Math.abs(o),c=t;i>s&&i>a?c=r:a>s&&a>i&&(c=o),c<0&&(t=-t,r=-r,o=-o);let l=Math.round(t/.05),u=Math.round(r/.05),f=Math.round(o/.05),d=e.d*(e.normal[0]===t&&e.normal[1]===r&&e.normal[2]===o?1:-1),m=Math.round(d/(n*2));return`${l},${u},${f}|${m}`}function su(e,n,t,r){let o=Ie(e.normal,n.normal);if(Math.abs(o)<1-t)return!1;let s=o>0?1:-1;return Math.abs(e.d-s*n.d)<r}function Ii(e,n){let t=Kl(n,e.centroid);return Ie(e.normal,t)>0}function $n(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,r=n?.distanceTolerance??.05,o=n?.overlapFraction??.7,s=n?.preserveDoubleSidedBackfaces??!0,i=[];for(let g=0;g<e.length;g++){let h=Zl(e[g],g);h&&i.push(h)}if(i.length<2)return new Set;let a=0,c=0,l=0,u=0;for(let g of i)a+=g.centroid[0]*g.area,c+=g.centroid[1]*g.area,l+=g.centroid[2]*g.area,u+=g.area;let f=u>0?[a/u,c/u,l/u]:[0,0,0],d=new Map;for(let g of i){let h=ou(g,r),p=d.get(h);p||(p=[],d.set(h,p)),p.push(g)}let m=new Set;for(let g of d.values())if(!(g.length<2))for(let h=0;h<g.length;h++){let p=g[h];if(!m.has(p.index))for(let x=h+1;x<g.length;x++){let b=g[x];if(m.has(b.index)||!su(p,b,t,r)||s&&Ql(p,b))continue;eu(p);let P=nu(b.polygon,p.basis);if(!tu(p.bbox2D,P.bbox2D)||ru(p.local2D,P.local2D)<o)continue;let M=Ii(p,f),S=Ii(b,f),T;if(M&&!S?T=p:S&&!M?T=b:T=p.area<b.area?p:b,m.add(T.index),T===p)break}}return m}function Vi(e,n){if(!e||e.length<2)return e??[];let t=$n(e,n);if(t.size===0)return e;let r=[];for(let o=0;o<e.length;o++)t.has(o)||r.push(e[o]);return r}var iu=4,au=8,cu=.001,lu=1e-9,uu=1e6,fu=1e6,mu=8,nn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],co=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Wn=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],tn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],wi=(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]],Ni=e=>Math.hypot(e[0],e[1],e[2]);function jn(e){let n=Ni(e);return n<=lu?null:[e[0]/n,e[1]/n,e[2]/n]}function Xn(e,n){return Math.round(e*n)/n}function Ve(e){return Xn(e,uu)}function io(e){return Xn(e,fu)}function ao(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function Fe(e){return`${Ve(e[0])},${Ve(e[1])}`}function du(e){let n=Fe(e.a),t=Fe(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function Sn(e){return`${e[0]},${e[1]},${e[2]}`}function Di(e,n){let t=Sn(e),r=Sn(n);return t<r?`${t}|${r}`:`${r}|${t}`}function lo(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Oi(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",lo(e.data)].join("|")}function Fi(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],r=[0,0,0];for(let s=1;s<n.length-1;s++)r=co(r,wi(nn(n[s],t),nn(n[s+1],t)));let o=jn(r);return o?{normal:o,d:tn(o,t)}:null}function gu(e,n,t){return tn(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function pu(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function hu(e,n){let t=n[e[0]]?.data,r=lo(t);for(let o of e)if(lo(n[o].data)!==r)return;return t?{...t}:void 0}function xu(e,n){return e.every(t=>n[t].doubleSided===!0)}function bu(e,n){let t=e.map(c=>pu(c)?Fi(c):null),r=t.map(Boolean),o=new Map;for(let c=0;c<e.length;c++){if(!t[c])continue;let l=e[c].vertices;for(let u=0;u<l.length;u++){let f=Di(l[u],l[(u+1)%l.length]),d=o.get(f),m={polygon:c,edge:u};d?d.push(m):o.set(f,[m])}}let s=e.map(()=>new Set);for(let c of o.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l].polygon,d=c[u].polygon,m=t[f],g=t[d];!m||!g||Oi(e[f])===Oi(e[d])&&gu(m,g,n)&&(s[f].add(d),s[d].add(f))}let i=new Set,a=[];for(let c=0;c<e.length;c++){if(!r[c]||i.has(c))continue;let l=[],u=[c];for(i.add(c);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))}a.push(l)}return{groups:a}}function yu(e,n){let t=new Set(e),r=new Map;for(let s of e){let i=n[s].vertices;for(let a=0;a<i.length;a++){let c=Di(i[a],i[(a+1)%i.length]),l=r.get(c),u={polygon:s,edge:a};l?l.push(u):r.set(c,[u])}}let o=[];for(let s of r.values()){let i=s.filter(a=>t.has(a.polygon));if(i.length===1){let a=i[0],c=n[a.polygon].vertices;o.push({a:c[a.edge],b:c[(a.edge+1)%c.length]})}else if(i.length!==2)return null}return o}function Pu(e){let n=new Map;for(let t of e)n.set(Sn(t.a),(n.get(Sn(t.a))??0)+1),n.set(Sn(t.b),(n.get(Sn(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function Bi(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 Au(e){let n=Bi(e);return`${Xn(n[0],1e3)},${Xn(n[1],1e3)},${Xn(n[2],1e3)}`}function Mu(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=nn(n,Wn(e,tn(n,e)));return jn(t)??[1,0,0]}function Su(e,n,t){let r=new Map;for(let s of e){let i=nn(s.b,s.a),a=nn(i,Wn(n,tn(i,n))),c=jn(a);if(!c)continue;let l=Bi(c),u=Au(l),f=Ni(a),d=r.get(u);d?d.weight+=f:r.set(u,{axis:l,weight:f})}let o=[...r.values()].sort((s,i)=>i.weight-s.weight).slice(0,t).map(s=>s.axis);return o.length===0&&o.push(Mu(n)),o}function Ri(e,n,t,r){let o=nn(e,n);return[Ve(tn(o,t)),Ve(tn(o,r))]}function Eu(e){let n=[...e].sort((r,o)=>r-o),t=[];for(let r of n)(t.length===0||Math.abs(r-t[t.length-1])>1e-7)&&t.push(r);return t}function zn(e,n){let[t,r]=e.a,[o,s]=e.b,i=(n-t)/(o-t);return Ve(r+(s-r)*i)}function uo(e){let n=[];for(let r of e)(n.length===0||Math.abs(r[0]-n[n.length-1][0])>1e-7||Math.abs(r[1]-n[n.length-1][1])>1e-7)&&n.push(r);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 r=0;r<n.length;r++){let o=n[(r-1+n.length)%n.length],s=n[r],i=n[(r+1)%n.length],a=(s[0]-o[0])*(i[1]-s[1])-(s[1]-o[1])*(i[0]-s[0]);Math.abs(a)>1e-8&&t.push(s)}return t}function Vt(e){let n=0;for(let t=0;t<e.length;t++){let r=e[t],o=e[(t+1)%e.length];n+=r[0]*o[1]-o[0]*r[1]}return n/2}function Ot(e){let n=1/0,t=1/0,r=-1/0,o=-1/0;for(let[s,i]of e)n=Math.min(n,s),t=Math.min(t,i),r=Math.max(r,s),o=Math.max(o,i);return{minX:n,minY:t,maxX:r,maxY:o}}function ki(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 It(e){return Math.abs(Vt(e))}function Tu(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let r=e[t],o=e[(t+1)%e.length],s=e[(t+2)%e.length],i=(o[0]-r[0])*(s[1]-o[1])-(o[1]-r[1])*(s[0]-o[0]);if(Math.abs(i)<=1e-8)continue;let a=i>0?1:-1;if(n===0)n=a;else if(n!==a)return!1}return!0}function Cu(e,n,t){let r=t[0]-n[0],o=t[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],a=r*i-o*s,c=Math.hypot(r,o);if(c<=1e-9||Math.abs(a)>Math.max(1e-8,c*1e-8))return!1;let l=s*r+i*o;return l>=-1e-8&&l<=r*r+o*o+1e-8}function _u(e,n,t){let r=t[0]-n[0],o=t[1]-n[1],s=r*r+o*o;return s<=1e-12?0:((e[0]-n[0])*r+(e[1]-n[1])*o)/s}function vu(e,n,t,r){let o=n[0]-e[0],s=n[1]-e[1],i=r[0]-t[0],a=r[1]-t[1],c=Math.hypot(o,s),l=Math.hypot(i,a);if(c<=1e-9||l<=1e-9)return!1;let u=o*(t[1]-e[1])-s*(t[0]-e[0]),f=o*(r[1]-e[1])-s*(r[0]-e[0]),d=o*a-s*i,m=Math.max(1e-8,Math.max(c,l)*1e-8);if(Math.abs(u)>m||Math.abs(f)>m||Math.abs(d)>m)return!1;let g=Math.abs(o)>=Math.abs(s),h=Math.min(g?e[0]:e[1],g?n[0]:n[1]),p=Math.max(g?e[0]:e[1],g?n[0]:n[1]),x=Math.min(g?t[0]:t[1],g?r[0]:r[1]),b=Math.max(g?t[0]:t[1],g?r[0]:r[1]);return Math.min(p,b)-Math.max(h,x)>1e-8}function Iu(e,n){for(let t=0;t<e.length;t++){let r=e[t],o=e[(t+1)%e.length];for(let s=0;s<n.length;s++)if(vu(r,o,n[s],n[(s+1)%n.length]))return!0}return!1}function Li(e,n){let t=[];for(let r=0;r<e.length;r++){let o=e[r],s=e[(r+1)%e.length],i=[{t:0,point:o},{t:1,point:s}];for(let c of n)ao(c,o)||ao(c,s)||Cu(c,o,s)&&i.push({t:_u(c,o,s),point:c});i.sort((c,l)=>c.t-l.t);let a=[];for(let c of i)a.some(l=>Math.abs(l.t-c.t)<=1e-8||ao(l.point,c.point))||a.push(c);for(let c=0;c<a.length-1;c++){let l=a[c].point,u=a[c+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||t.push({a:[Ve(l[0]),Ve(l[1])],b:[Ve(u[0]),Ve(u[1])]})}}return t}function Vu(e,n,t=Ot(e),r=Ot(n)){if(!ki(t,r)||!Iu(e,n))return null;let o=[...Li(e,n),...Li(n,e)],s=new Map;for(let x of o){let b=du(x),P=s.get(b);P?P.push(x):s.set(b,[x])}let i=!1,a=[];for(let x of s.values()){if(x.length===1){a.push(x[0]);continue}i=!0;let b=x.filter(y=>Fe(y.a)<Fe(y.b)).length,P=x.length-b;if(b!==P)return null}if(!i||a.length<3)return null;let c=new Map;for(let x of a){let b=Fe(x.a);if(c.has(b))return null;c.set(b,x)}let l=a[0],u=Fe(l.a),f=[],d=new Set,m=u;for(let x=0;x<=a.length;x++){let b=c.get(m);if(!b)return null;let P=`${Fe(b.a)}>${Fe(b.b)}`;if(d.has(P))return null;if(d.add(P),f.push(b.a),m=Fe(b.b),m===u)break}if(m!==u||d.size!==a.length)return null;let g=uo(f);if(g.length<3||!Tu(g))return null;let h=It(g),p=It(e)+It(n);return Math.abs(h-p)>Math.max(1e-5,p*1e-5)?null:Vt(g)>=0?g:[...g].reverse()}function Ou(e){let n=e.map(uo).filter(o=>o.length>=3&&It(o)>1e-8),t=n.map(Ot),r=!0;for(;r;){r=!1;for(let o=0;o<n.length;o++){for(let s=o+1;s<n.length;s++){if(!ki(t[o],t[s]))continue;let i=Vu(n[o],n[s],t[o],t[s]);if(i){n[o]=i,t[o]=Ot(i),n.splice(s,1),t.splice(s,1),r=!0;break}}if(r)break}}return n}function Ru(e,n,t){let r=new Map;return o=>{let s=Ve(o[0]),i=Ve(o[1]),a=`${s},${i}`,c=r.get(a);if(c)return[c[0],c[1],c[2]];let l=co(e,co(Wn(n,s),Wn(t,i))),u=[io(l[0]),io(l[1]),io(l[2])];return r.set(a,u),[u[0],u[1],u[2]]}}function Lu(e,n,t,r,o){let s=t[0]?.a;if(!s)return null;let i=jn(nn(o,Wn(r,tn(o,r))));if(!i)return null;let a=jn(wi(r,i));if(!a)return null;let c=[],l=[];for(let x of t){let b=Ri(x.a,s,i,a),P=Ri(x.b,s,i,a);Math.hypot(b[0]-P[0],b[1]-P[1])<=1e-7||(c.push({a:b,b:P}),l.push(b[0],P[0]))}let u=Eu(l);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,d=hu(e,n),m=xu(e,n),g=[];for(let x=0;x<u.length-1;x++){let b=u[x],P=u[x+1];if(P-b<=1e-7)continue;let y=(b+P)/2,M=c.filter(S=>{let T=Math.min(S.a[0],S.b[0]),E=Math.max(S.a[0],S.b[0]);return T<y&&y<E&&Math.abs(S.a[0]-S.b[0])>1e-7}).map(S=>({segment:S,yMid:zn(S,y)})).sort((S,T)=>S.yMid-T.yMid);if(M.length!==0){if(M.length%2!==0)return null;for(let S=0;S<M.length;S+=2){let T=M[S].segment,E=M[S+1].segment,A=zn(T,b),C=zn(T,P),_=zn(E,b),w=zn(E,P),V=uo([[b,A],[P,C],[P,w],[b,_]]);if(V.length<3||Math.abs(Vt(V))<=1e-8)continue;let N=Vt(V)>0?V:[...V].reverse();g.push(N)}}}if(g.length===0||e.length>2&&g.length>e.length*mu)return null;let h=Ru(s,i,a),p=Ou(g).map(x=>({vertices:x.map(h),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return Re(p)}function wu(e,n,t){let r=yu(e,n);if(!r||r.length<3||!Pu(r))return null;let o=Fi(n[e[0]]);if(!o)return null;let s=null;for(let i of Su(r,o.normal,t)){let a=Lu(e,n,r,o.normal,i);a&&(!s||a.length<s.length)&&(s=a)}return!s||s.length>=e.length?null:s}function Rt(e,n={}){let t=n.minGroupPolygons??iu,r=n.maxCandidateAxes??au,o=n.planeEpsilon??cu,s=e??[];if(s.length<t)return s;let{groups:i}=bu(s,o);if(i.length===0)return s;let a=new Map,c=new Set;for(let u of i){if(u.length<t)continue;let f=wu(u,s,r);if(f){a.set(u[0],f);for(let d of u)c.add(d)}}if(a.size===0)return s;let l=[];for(let u=0;u<s.length;u++){let f=a.get(u);if(f){l.push(...f);continue}c.has(u)||l.push(s[u])}return l}function Nu(e,n){let t=`${e[0]},${e[1]},${e[2]}`,r=`${n[0]},${n[1]},${n[2]}`;return t<r?`${t}|${r}`:`${r}|${t}`}function Du(e){if(e.length<100)return!1;let n=new Map;for(let r of e){let o=r.vertices;for(let s=0;s<o.length;s++){let i=Nu(o[s],o[(s+1)%o.length]);n.set(i,(n.get(i)??0)+1)}}let t=0;for(let r of n.values())r===1&&(t+=1);return t>=128&&t/Math.max(1,n.size)>.2}function Fu(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,r=0,o=0;for(let[V,N,F]of n)t+=V,r+=N,o+=F;let s=1/n.length;t*=s,r*=s,o*=s;let i=n[0],a=n[1],c=n[2],l=a[0]-i[0],u=a[1]-i[1],f=a[2]-i[2],d=c[0]-i[0],m=c[1]-i[1],g=c[2]-i[2],h=u*g-f*m,p=f*d-l*g,x=l*m-u*d,b=Math.hypot(h,p,x);if(b<1e-9)return null;h/=b,p/=b,x/=b;let P=n.length-2,y=new Float64Array(P*9),M=0;for(let V=1;V<n.length-1;V++){let N=n[0],F=n[V],k=n[V+1];y[M++]=N[0],y[M++]=N[1],y[M++]=N[2],y[M++]=F[0],y[M++]=F[1],y[M++]=F[2],y[M++]=k[0],y[M++]=k[1],y[M++]=k[2]}let S=0,T=1/0,E=1/0,A=1/0,C=-1/0,_=-1/0,w=-1/0;for(let[V,N,F]of n){let k=V-t,$=N-r,R=F-o,B=k*k+$*$+R*R;B>S&&(S=B),V<T&&(T=V),V>C&&(C=V),N<E&&(E=N),N>_&&(_=N),F<A&&(A=F),F>w&&(w=F)}return{centroid:[t,r,o],normal:[h,p,x],vertices:n,triFlat:y,bcx:t,bcy:r,bcz:o,br2:S,minX:T,minY:E,minZ:A,maxX:C,maxY:_,maxZ:w}}function Bu(e,n,t,r,o,s,i,a){let c=i[a],l=i[a+1],u=i[a+2],f=i[a+3]-c,d=i[a+4]-l,m=i[a+5]-u,g=i[a+6]-c,h=i[a+7]-l,p=i[a+8]-u,x=o*p-s*h,b=s*g-r*p,P=r*h-o*g,y=f*x+d*b+m*P;if(y>-1e-9&&y<1e-9)return!1;let M=1/y,S=e-c,T=n-l,E=t-u,A=M*(S*x+T*b+E*P);if(A<0||A>1)return!1;let C=T*m-E*d,_=E*f-S*m,w=S*d-T*f,V=M*(r*C+o*_+s*w);return V<0||A+V>1?!1:M*(g*C+h*_+p*w)>.001}function ku(e,n,t,r,o,s,i){let a=i.bcx-e,c=i.bcy-n,l=i.bcz-t,u=a*r+c*o+l*s,f=a-u*r,d=c-u*o,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let g=i.triFlat,h=g.length;for(let p=0;p<h;p+=9)if(Bu(e,n,t,r,o,s,g,p))return!0;return!1}var Yn=9,Uu=6,ge=12;function fo(e,n,t,r,o,s){let i=r-e,a=o-n,c=s-t;return i*a+a*c+c*i}function Gu(e){let n=[];for(let S=0;S<e.length;S++)e[S]&&n.push(S);let t=n.length,r=new Int32Array(t);for(let S=0;S<t;S++)r[S]=n[S];let o=new Float64Array(t),s=new Float64Array(t),i=new Float64Array(t);for(let S=0;S<t;S++){let T=e[r[S]];o[S]=(T.minX+T.maxX)*.5,s[S]=(T.minY+T.maxY)*.5,i[S]=(T.minZ+T.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*Yn),l=0,u=new Float64Array(ge),f=new Float64Array(ge),d=new Float64Array(ge),m=new Float64Array(ge),g=new Float64Array(ge),h=new Float64Array(ge),p=new Int32Array(ge),x=new Float64Array(ge-1),b=new Int32Array(ge-1),P=new Float64Array(ge-1),y=new Int32Array(ge-1);function M(S,T){let E=l++,A=E*Yn,C=T-S,_=1/0,w=1/0,V=1/0,N=-1/0,F=-1/0,k=-1/0;for(let K=S;K<T;K++){let te=e[r[K]];te.minX<_&&(_=te.minX),te.maxX>N&&(N=te.maxX),te.minY<w&&(w=te.minY),te.maxY>F&&(F=te.maxY),te.minZ<V&&(V=te.minZ),te.maxZ>k&&(k=te.maxZ)}if(c[A]=_,c[A+1]=w,c[A+2]=V,c[A+3]=N,c[A+4]=F,c[A+5]=k,C<=Uu)return c[A+6]=1,c[A+7]=S,c[A+8]=T,E;let $=1/0,R=1/0,B=1/0,z=-1/0,ee=-1/0,Q=-1/0;for(let K=S;K<T;K++)o[K]<$&&($=o[K]),o[K]>z&&(z=o[K]),s[K]<R&&(R=s[K]),s[K]>ee&&(ee=s[K]),i[K]<B&&(B=i[K]),i[K]>Q&&(Q=i[K]);let Z=z-$,ne=ee-R,j=Q-B;if(Z===0&&ne===0&&j===0)return c[A+6]=1,c[A+7]=S,c[A+8]=T,E;let D=fo(_,w,V,N,F,k),I=D>0?1/D:0,U=C+1,G=0,q=0;for(let K=0;K<3;K++){let te=K===0?$:K===1?R:B,se=K===0?Z:K===1?ne:j;if(se===0)continue;let he=K===0?o:K===1?s:i,Te=ge/se;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),g.fill(-1/0),h.fill(-1/0),p.fill(0);for(let W=S;W<T;W++){let J=(he[W]-te)*Te|0;J>=ge&&(J=ge-1);let oe=e[r[W]];oe.minX<u[J]&&(u[J]=oe.minX),oe.maxX>m[J]&&(m[J]=oe.maxX),oe.minY<f[J]&&(f[J]=oe.minY),oe.maxY>g[J]&&(g[J]=oe.maxY),oe.minZ<d[J]&&(d[J]=oe.minZ),oe.maxZ>h[J]&&(h[J]=oe.maxZ),p[J]++}let le=1/0,me=1/0,pe=1/0,ve=-1/0,ye=-1/0,Ce=-1/0,xe=0;for(let W=0;W<ge-1;W++)u[W]<le&&(le=u[W]),m[W]>ve&&(ve=m[W]),f[W]<me&&(me=f[W]),g[W]>ye&&(ye=g[W]),d[W]<pe&&(pe=d[W]),h[W]>Ce&&(Ce=h[W]),xe+=p[W],x[W]=fo(le,me,pe,ve,ye,Ce),b[W]=xe;let Pe=1/0,Ae=1/0,ce=1/0,fe=-1/0,Me=-1/0,ae=-1/0,de=0;for(let W=ge-2;W>=0;W--){let J=W+1;u[J]<Pe&&(Pe=u[J]),m[J]>fe&&(fe=m[J]),f[J]<Ae&&(Ae=f[J]),g[J]>Me&&(Me=g[J]),d[J]<ce&&(ce=d[J]),h[J]>ae&&(ae=h[J]),de+=p[J],P[W]=fo(Pe,Ae,ce,fe,Me,ae),y[W]=de}for(let W=0;W<ge-1;W++){if(b[W]===0||y[W]===0)continue;let J=.125+(x[W]*b[W]+P[W]*y[W])*I;J<U&&(U=J,G=K,q=te+(W+1)/Te)}}let v=G===0?o:G===1?s:i,O=S,L=T-1;for(;O<=L;)if(v[O]<q)O++;else{let K=r[O];r[O]=r[L],r[L]=K;let te=o[O];o[O]=o[L],o[L]=te;let se=s[O];s[O]=s[L],s[L]=se;let he=i[O];i[O]=i[L],i[L]=he,L--}let X=O;(X===S||X===T)&&(X=S+T>>1),c[A+6]=0;let H=M(S,X),Y=M(X,T);return c[E*Yn+7]=H,c[E*Yn+8]=Y,E}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:r,meta:e}}function Ui(e,n,t,r,o,s,i,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=r!==0?1/r:r>=0?1/0:-1/0,m=o!==0?1/o:o>=0?1/0:-1/0,g=s!==0?1/s:s>=0?1/0:-1/0,h=0;for(c[h++]=0;h>0;){let x=c[--h]*Yn,b=(l[x]-e)*d,P=(l[x+3]-e)*d,y=b<P?b:P,M=b<P?P:b,S=(l[x+1]-n)*m,T=(l[x+4]-n)*m,E=S<T?S:T,A=S<T?T:S;if(y>A||E>M)continue;E>y&&(y=E),A<M&&(M=A);let C=(l[x+2]-t)*g,_=(l[x+5]-t)*g,w=C<_?C:_,V=C<_?_:C;if(!(y>V||w>M)&&(V<M&&(M=V),!(M<.001)))if(l[x+6]===1){let N=l[x+7]|0,F=l[x+8]|0;for(let k=N;k<F;k++){let $=u[k];if($===i)continue;let R=f[$];if(R&&ku(e,n,t,r,o,s,R))return!0}}else c[h++]=l[x+7]|0,c[h++]=l[x+8]|0}return!1}function $u(e){let n=(1+Math.sqrt(5))/2,t=new Float64Array(e*3);for(let r=0;r<e;r++){let o=(r+.5)/e,s=Math.sqrt(Math.max(0,1-o*o)),i=2*Math.PI*(r/n);t[r*3]=s*Math.cos(i),t[r*3+1]=s*Math.sin(i),t[r*3+2]=o}return t}function zu(e){let n=Math.abs(e[0])>.9?0:1,t=Math.abs(e[0])>.9?1:0,r=t*e[2],o=-n*e[2],s=n*e[1]-t*e[0],i=Math.hypot(r,o,s);r/=i,o/=i,s/=i;let a=e[1]*s-e[2]*o,c=e[2]*r-e[0]*s,l=e[0]*o-e[1]*r;return{ux:r,uy:o,uz:s,vx:a,vy:c,vz:l}}function Be(e,n){let t=n?.samples??8;if(e.length<4||t<1||Du(e))return e;let r=e.map(Fu),o=$u(t),s=[],i=Gu(r),a=new Int32Array(Math.max(64,i.nodeCount)),c=192,l=new Float64Array(c);for(let u=0;u<e.length;u++){let f=r[u];if(!f){s.push(e[u]);continue}let d=f.normal[0],m=f.normal[1],g=f.normal[2],h=.001*d,p=.001*m,x=.001*g;{let F=f.centroid[0]+h,k=f.centroid[1]+p,$=f.centroid[2]+x;if(!Ui(F,k,$,d,m,g,u,i,a)){s.push(e[u]);continue}}let{ux:b,uy:P,uz:y,vx:M,vy:S,vz:T}=zu(f.normal),E=f.centroid[0],A=f.centroid[1],C=f.centroid[2],_=f.vertices,w=_.length,V=0;l[V++]=E+h,l[V++]=A+p,l[V++]=C+x;for(let F=0;F<w;F++){let k=_[F];l[V++]=k[0]+(E-k[0])*.08+h,l[V++]=k[1]+(A-k[1])*.08+p,l[V++]=k[2]+(C-k[2])*.08+x}for(let F=0;F<w;F++){let k=_[F],$=_[(F+1)%w],R=(k[0]+$[0])*.5,B=(k[1]+$[1])*.5,z=(k[2]+$[2])*.5;l[V++]=R+(E-R)*.08+h,l[V++]=B+(A-B)*.08+p,l[V++]=z+(C-z)*.08+x}let N=!1;e:for(let F=0;F<o.length;F+=3){let k=o[F],$=o[F+1],R=o[F+2],B=k*b+$*M+R*d,z=k*P+$*S+R*m,ee=k*y+$*T+R*g;for(let Q=0;Q<V;Q+=3){let Z=l[Q],ne=l[Q+1],j=l[Q+2];if(!Ui(Z,ne,j,B,z,ee,u,i,a)){N=!0;break e}}}N&&s.push(e[u])}return s}var xo={overlapPx:1.25,maxGapPx:14,capacityScale:1},bo={budget:40};function rn(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,rn(e?.overlapPx,1.25)),maxGapPx:Math.max(0,rn(e?.maxGapPx,14)),capacityScale:Math.max(0,rn(e?.capacityScale,1))}}function Jn(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function Yi(e){return{rotX:rn(e?.rotX,65),rotY:rn(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(rn(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(rn(e?.budget,40))))}}function ke(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function Hi(e){return[e[1]/50,e[0]/50,e[2]/50]}function Bt(e){return`${e[0]},${e[1]},${e[2]}`}function Xu(e,n){let t=Bt(e),r=Bt(n);return t<r?`${t}|${r}`:`${r}|${t}`}function Ue(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function En(e){return Math.hypot(e[0],e[1],e[2])}function Zn(e){let n=En(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function qn(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Lt(e,n,t,r){let o=n*Math.PI/180,s=t*Math.PI/180,i=r*Math.PI/180,[a,c,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,c]=[a*u-c*f,a*f+c*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,l]=[a*u+l*f,-a*f+l*u]}if(o!==0){let u=Math.cos(o),f=Math.sin(o);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function yo(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 Wu(e){if(e.length<3)return null;let n=e[0],t=[0,0,0];for(let r=1;r+1<e.length;r+=1){let o=Ue(e[r],n),s=Ue(e[r+1],n),i=yo(o,s);t[0]-=i[0],t[1]-=i[1],t[2]-=i[2]}return Zn(t)}function Po(e){let n=e[0],t=Wu(e);if(!t)return null;let r=null;for(let u=0;u<e.length;u+=1){let f=Ue(e[(u+1)%e.length],e[u]);if(En(f)>1e-6){r=f;break}}if(!r)return null;let o=qn(r,t),s=[r[0]-o*t[0],r[1]-o*t[1],r[2]-o*t[2]],i=Zn(s);if(!i)return null;let a=Zn(yo(t,i));if(!a)return null;let c=e.map(u=>{let f=Ue(u,n);return[qn(f,i),qn(f,a)]}),l=kt(c);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:i,yAxis:a,local:c,area:l}:null}function kt(e){let n=0;for(let t=0;t<e.length;t+=1){let r=e[t],o=e[(t+1)%e.length];n+=r[0]*o[1]-r[1]*o[0]}return n/2}function Ao(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t+=1){let r=e[t],o=e[(t+1)%e.length],s=e[(t+2)%e.length],i=(o[0]-r[0])*(s[1]-o[1])-(o[1]-r[1])*(s[0]-o[0]);if(Math.abs(i)<=1e-6)continue;let a=Math.sign(i);if(n===0)n=a;else if(a!==n)return!1}return!0}function Ki(e,n,t){let r=e[t],o=e[(t+1)%e.length],s=o[0]-r[0],i=o[1]-r[1],a=Math.hypot(s,i);if(a<=1e-6)return null;let c=n>0?1:-1;return[c*(i/a),c*(-s/a)]}function ju(e,n){let t=Ki(e.local,e.area,n);return t?Zn([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 qi(e,n){let t=e.length,r=e[n],o=e[(n+1)%t],s=o[0]-r[0],i=o[1]-r[1],a=Math.hypot(s,i);if(a<=1e-6)return 0;let c=[a*.24],l=1/0;for(let f=0;f<t;f+=1){if(f===n||f===(n+1)%t)continue;let d=e[f],m=Math.abs((d[0]-r[0])*i-(d[1]-r[1])*s)/a;m>1e-6&&(l=Math.min(l,m))}Number.isFinite(l)&&c.push(l*.32);let u=[{origin:r,point:e[(n+t-1)%t]},{origin:o,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],g=Math.hypot(d,m);if(g<=1e-6)continue;let h=Math.abs(s*m-i*d)/(a*g);h>1e-6&&c.push(g*h*.32)}return Math.min(...c)}function Zi(e){return e.map(n=>{let t=ke(n.vertices),r=Po(t),o=!Mo(n)&&!!r&&Ao(r.local),s=o?r.local.map((i,a)=>qi(r.local,a)):[];return{basis:r,cssPoints:t,capacities:s,patchable:o}})}function Mo(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Yu(e){return e.material?.key??e.color??""}function Qi(e,n,t){let r=[];for(let o=0;o<n.length;o+=1){let s=n[o];if(!(!s.patchable||!s.basis))for(let i=0;i<s.cssPoints.length;i+=1){let a=s.cssPoints[i],c=s.cssPoints[(i+1)%s.cssPoints.length],l=Ue(c,a),u=En(l),f=Zn(l),d=ju(s.basis,i),m=(s.capacities[i]??0)*t;!f||!d||m<=1e-6||u<=1e-6||r.push({index:r.length,polygon:o,edge:i,key:Xu(a,c),a,b:c,minX:Math.min(a[0],c[0]),minY:Math.min(a[1],c[1]),minZ:Math.min(a[2],c[2]),maxX:Math.max(a[0],c[0]),maxY:Math.max(a[1],c[1]),maxZ:Math.max(a[2],c[2]),length:u,dir:f,normal:s.basis.normal,outward:d,capacity:m,materialKey:Yu(e[o]),color:e[o].color})}}return r}function So(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function wt(e,n){return En(Ue(e,n))<=1e-4}function Hu(e,n){return wt(e.a,n.a)||wt(e.a,n.b)||wt(e.b,n.a)||wt(e.b,n.b)}function Ku(e,n){return So(e,n)?Hu(e,n)?"connected-facet":"true-gap":"material-boundary"}function mo(e,n,t,r,o,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:r.gap,spanPx:r.aEnd-r.aStart,aStartPx:r.aStart,aEndPx:r.aEnd,bStartPx:r.bStart,bEndPx:r.bEnd,targetClosurePx:o,appliedClosurePx:s,residualGapPx:Math.max(0,r.gap-s),residualTargetPx:Math.max(0,o-s)}}function Gi(e,n,t,r,o){let s=Math.max(0,Math.min(n.length,Math.min(t,r))),i=Math.max(0,Math.min(n.length,Math.max(t,r)));if(o<=1e-6||i-s<=1e-6)return;let a=e[n.polygon].get(n.edge),c={start:s,end:i,amount:o};a?a.push(c):e[n.polygon].set(n.edge,[c])}function Eo(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function qu(e,n){let t=0,r=0,o=0;for(let s of e){s.size>0&&(o+=1),r+=s.size;for(let i of s.values())for(let a of i)t=Math.max(t,a.amount)}return{...n,patchedPolygons:o,patchedEdges:r,maxAppliedAmountPx:t}}function To(e,n,t=!1){let r=Zi(e),o=Qi(e,r,n.capacityScale),s=e.map(()=>new Map),i=Eo(),a=t?[]:void 0;if(o.length===0)return{edgeRepairs:s,diagnostics:i,candidates:a};let c=new Map;for(let l of o){let u=c.get(l.key);u?u.push(l):c.set(l.key,[l])}for(let l of c.values())l.length<2||(i.exactPairs+=l.length===2?1:l.length);return Zu(o,c,s,i,n,a),{edgeRepairs:s,diagnostics:qu(s,i),candidates:a}}function Zu(e,n,t,r,o,s){let i=o.maxGapPx,a=new Set;for(let[m,g]of n)g.length>1&&a.add(m);let c=(m,g)=>{let h=m.index<g.index?m:g,p=m.index<g.index?g:m;if(p.polygon===h.polygon||h.key===p.key&&a.has(h.key)||!s&&!So(h,p)||!Qu(h,p,i)||Math.abs(qn(h.dir,p.dir))<.985)return;let x=tf(h,p,i);if(!x)return;let b=Ku(h,p),P=x.gap+o.overlapPx;if(b==="material-boundary"){s?.push(mo(b,h,p,x,P,0));return}let y=P;if(y<=.25){s?.push(mo(b,h,p,x,P,0));return}let M=h.capacity*x.facingA,S=p.capacity*x.facingB,T=Math.min(M,y/2),E=Math.min(S,y/2);if(y-=T+E,y>1e-6){let A=Math.min(M-T,y);T+=A,y-=A}if(y>1e-6){let A=Math.min(S-E,y);E+=A,y-=A}s?.push(mo(b,h,p,x,P,T+E)),T>1e-6&&Gi(t,h,x.aStart,x.aEnd,T/x.facingA),E>1e-6&&Gi(t,p,x.bStart,x.bEnd,E/x.facingB),r.nearPairs+=1,r.maxMeasuredGapPx=Math.max(r.maxMeasuredGapPx,x.gap),y>.25&&(r.unclosedPairs+=1,r.maxResidualGapPx=Math.max(r.maxResidualGapPx,y))},l=Math.max(28,i*2);if(e.length<=1e4){let m=[...e].sort((p,x)=>p.minX-x.minX),g=new Int32Array(m.length),h=0;for(let p=0;p+1<m.length;p+=1){let b=m[p].maxX+i,P=p+1;for(;P<m.length&&m[P].minX<=b;)P+=1;if(g[p]=P,h+=P-p-1,h>25e6)break}if(h<=2e6||h<=25e6&&nf(e,l,i)){for(let p=0;p+1<m.length;p+=1)for(let x=p+1;x<g[p];x+=1)c(m[p],m[x]);return}}let u=new Map;for(let m of e)Ju(u,m,l,i);let f=new Set,d=e.length;for(let m of u.values())for(let g=0;g+1<m.length;g+=1)for(let h=g+1;h<m.length;h+=1){let p=m[g],x=m[h],b=p.index<x.index?p:x,P=p.index<x.index?x:p,y=b.index*d+P.index;f.has(y)||(f.add(y),c(b,P))}}function Qu(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 $i(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function Ju(e,n,t,r){let[o,s,i,a,c,l]=Ji(n,t,r);for(let u=o;u<=a;u+=1)for(let f=s;f<=c;f+=1)for(let d=i;d<=l;d+=1){let m=`${u},${f},${d}`,g=e.get(m);g?g.push(n):e.set(m,[n])}}function Ji(e,n,t){let[r,o,s]=$i([e.minX-t,e.minY-t,e.minZ-t],n),[i,a,c]=$i([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[r,o,s,i,a,c]}function ef(e,n,t){let[r,o,s,i,a,c]=Ji(e,n,t);return(i-r+1)*(a-o+1)*(c-s+1)}function nf(e,n,t){let r=0,o=0;for(let s of e){let i=ef(s,n,t);if(r+=i,i>o&&(o=i),o>8192)return!0}return r/Math.max(1,e.length)>256}function zi(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function Xi(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 tf(e,n,t){let r=zi(n.a,e.a,e.dir),o=zi(n.b,e.a,e.dir),s=Math.max(0,Math.min(r,o)),i=Math.min(e.length,Math.max(r,o)),a=i-s,c=Math.min(e.length,n.length);if(a<Math.max(.75,c*.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])),g=n.a[0]+n.dir[0]*m-u,h=n.a[1]+n.dir[1]*m-f,p=n.a[2]+n.dir[2]*m-d,x=Math.hypot(g,h,p);if(x<=1e-6||x>t||x>Math.min(t,Math.max(4,c*.28)))return null;let b=1/x,P=g*b,y=h*b,M=p*b,S=e.outward[0]*P+e.outward[1]*y+e.outward[2]*M,T=-(n.outward[0]*P+n.outward[1]*y+n.outward[2]*M);if(S<.5||T<.5)return null;let E=Math.max(0,Math.min(n.length,Xi(e,s,n))),A=Math.max(0,Math.min(n.length,Xi(e,i,n)));return{gap:x,facingA:S,facingB:T,aStart:s,aEnd:i,bStart:Math.min(E,A),bEnd:Math.max(E,A)}}function go(e,n,t,r){let o=t<=1e-6?0:Math.max(0,Math.min(1,r/t));return[e[0]+(n[0]-e[0])*o,e[1]+(n[1]-e[1])*o]}function Hn(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 rf(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let r=new Set([0,n]);for(let i of e){let a=Math.max(0,Math.min(n,i.start)),c=Math.max(0,Math.min(n,i.end));c-a<=1e-6||i.amount<=1e-6||(r.add(a),r.add(c))}let o=Array.from(r).sort((i,a)=>i-a),s=[];for(let i=0;i+1<o.length;i+=1){let a=o[i],c=o[i+1];if(c-a<=1e-6)continue;let l=(a+c)/2,u=0;for(let d of e)l+1e-6<d.start||l-1e-6>d.end||(u=Math.max(u,d.amount));let f=Math.min(t,u);f>1e-6&&s.push({start:a,end:c,amount:f})}return s}function of(e,n){if(n.length<3||!Ao(n))return!1;let t=kt(e),r=kt(n);return Math.sign(r)===Math.sign(t)&&Math.abs(r)>=Math.abs(t)-1e-6}function sf(e,n,t){if(n.size===0||e.vertices.length<3||Mo(e))return e;let r=ke(e.vertices),o=Po(r);if(!o||!Ao(o.local))return e;let s=[];for(let l=0;l<o.local.length;l+=1){let u=o.local[l],f=o.local[(l+1)%o.local.length],d=Math.hypot(f[0]-u[0],f[1]-u[1]),m=Ki(o.local,o.area,l);if(!m||d<=1e-6)return e;let g=rf(n.get(l),d,qi(o.local,l)*t);Hn(s,u);let h=0;for(let p of g){p.start>h+1e-6&&Hn(s,go(u,f,d,p.start));let x=go(u,f,d,p.start),b=go(u,f,d,p.end);Hn(s,[x[0]+m[0]*p.amount,x[1]+m[1]*p.amount]),Hn(s,[b[0]+m[0]*p.amount,b[1]+m[1]*p.amount]),p.end<d-1e-6&&Hn(s,b),h=p.end}}let i=s[0],a=s[s.length-1];if(i&&a&&Math.hypot(i[0]-a[0],i[1]-a[1])<=1e-6&&s.pop(),!of(o.local,s))return e;let c=s.map(([l,u])=>Hi([o.origin[0]+l*o.xAxis[0]+u*o.yAxis[0],o.origin[1]+l*o.xAxis[1]+u*o.yAxis[1],o.origin[2]+l*o.xAxis[2]+u*o.yAxis[2]]));return{...e,vertices:c}}function ea(e){return e.vertices.length===4&&!Mo(e)}function af(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let[c,l]of n)t=Math.min(t,c),r=Math.min(r,l),o=Math.max(o,c),s=Math.max(s,l);let i=Math.max(1e-6,(o-t)*(s-r));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/i)))*2.5}function po(e,n){return En(Ue(ke([e])[0],ke([n])[0]))}function Nt(e,n,t){let r=po(e,n),o=po(n,t),s=po(t,e),i=Math.max(r,o,s);return i<=1e-6?0:En(yo(Ue(ke([n])[0],ke([e])[0]),Ue(ke([t])[0],ke([e])[0])))*.5/(i*i)}function cf(e,n,t,r){let o=n[0]-e[0],s=n[1]-e[1],i=r[0]-t[0],a=r[1]-t[1],c=o*a-s*i;if(Math.abs(c)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*i)/c;return[e[0]+f*o,e[1]+f*s]}function lf(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 r=kt(e);if(Math.abs(r)<=1e-6)return null;let o=r>0?1:-1,s=[];for(let c=0;c<e.length;c+=1){let l=e[c],u=e[(c+1)%e.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=1e-6)return null;let g=Math.max(0,n[c]),h=o*(d/m)*g,p=o*(-f/m)*g;s.push({a:[l[0]+h,l[1]+p],b:[u[0]+h,u[1]+p]})}let i=[],a=Math.max(2,t*4);for(let c=0;c<e.length;c+=1){let l=s[(c+e.length-1)%e.length],u=s[c],f=cf(l.a,l.b,u.a,u.b);if(!f)return null;let d=e[c],m=f[0]-d[0],g=f[1]-d[1],h=Math.hypot(m,g);i.push(h>a?[d[0]+m/h*a,d[1]+g/h*a]:f)}return i}function uf(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 Dt(e,n){let t=Po(ke(e));if(!t)return e;let r=lf(t.local,n);return r?r.map(o=>Hi(uf(t,o))):e}function ff(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[r,o,s,i]=e.vertices,a=Math.min(Nt(r,o,s),Nt(r,s,i)),c=Math.min(Nt(r,o,i),Nt(o,s,i)),l=u=>n.has(u)?.75:0;return a>=c?[{...t,vertices:Dt([r,o,s],[l(0),l(1),1.25])},{...t,vertices:Dt([r,s,i],[1.25,l(2),l(3)])}]:[{...t,vertices:Dt([r,o,i],[l(0),1.25,l(3)])},{...t,vertices:Dt([o,s,i],[l(1),l(2),1.25])}]}function Wi(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((r,o)=>r-o),t=r=>n[Math.min(n.length-1,Math.floor((n.length-1)*r))]??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 Ft(e,n){let t=e[n];if(t===n)return n;let r=Ft(e,t);return e[n]=r,r}function mf(e){let n=new Set,t=new Set;for(let r of e)r.sel&&t.add(r.comp);for(let r of e)if(t.has(r.comp))for(let o of r.e)n.add(o);return{endpoints:n}}function df(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function gf(e,n,t,r){let o=[];for(let[c,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!So(u,f))continue;let d=l.filter(S=>ea(e[S.polygon]));if(d.length===0)continue;let m=d[0],g=1-Math.min(1,Math.abs(qn(u.normal,f.normal))),h=Math.max(u.length,f.length);if(g<.01&&h<64)continue;let p=Math.max(...d.map(S=>af(n[S.polygon]))),x=d.length===2?1.18:1,b=Math.max(.08,g),P=r.viewAware?pf(u,f,r.rotX,r.rotY):{proj:h,vr:1},y=r.viewAware?Math.max(P.proj,h*.12):h,M=r.viewAware?.18+P.vr*1.82:1;o.push({key:c,e:[Bt(m.a),Bt(m.b)],o:l,r:d,len:h,rank:y,proj:P.proj,s:y*(.58+b*2.8)*p*x*M,nr:g,sr:p,vr:P.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let s=Array.from({length:o.length},(c,l)=>l),i=new Map;for(let c=0;c<o.length;c+=1)for(let l of o[c].e){let u=i.get(l);if(u===void 0)i.set(l,c);else{let f=Ft(s,u),d=Ft(s,c);f!==d&&(s[d]=f)}}let a=new Map;for(let c=0;c<o.length;c+=1){let l=Ft(s,c),u=a.get(l);u===void 0&&(u=a.size,a.set(l,u)),o[c].comp=u}return o}function pf(e,n,t,r){let o=Lt(e.a,t,0,r),s=Lt(e.b,t,0,r),i=Math.hypot(s[0]-o[0],s[1]-o[1]),a=Lt(e.normal,t,0,r)[2],c=Lt(n.normal,t,0,r)[2],l=Math.max(0,a,c),u=Math.min(1,Math.abs(a-c));return{proj:i,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function hf(e){let n=new Map;for(let t of e){let r=n.get(t.comp);(!r||t.s>r.s||t.s===r.s&&t.len>r.len)&&n.set(t.comp,t)}return new Set(n.values())}function Kn(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+n*n*n*3.65,r=e.r.length===1?1.08:1;return e.rank*t*r/Math.sqrt(Math.max(1,e.r.length))}function ji(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+Math.min(1,e.vr)*1.65,r=.7+Math.min(2.6,e.sr)*.3,o=e.r.length===1?1.1:1,s=e.rank*(.6+n*n*1.4)*t*r*o/Math.sqrt(Math.max(1,e.r.length));return Math.max(s,Kn(e)*.75)}function ho(e){let n=new Set;for(let t of e)for(let r of t.r)n.add(r.polygon);return n.size}function na(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function xf(e,n,t){return e.s>=n||e.rank>=t}function bf(e,n,t,r,o,s,i){let a=Math.max(0,Math.floor(t));if(a<=0||e.length===0||n==="follow-up")return{budgetLimit:a,componentBudgets:null};let c=new Map;for(let m of e){let g=c.get(m.comp);g?g.push(m):c.set(m.comp,[m])}let l=new Map,u=Math.max(1e-6,r.q3-r.q1),f=Math.min(r.max,Math.max(r.p95,r.q3+u)),d=0;for(let[m,g]of c){let h=g.filter(M=>xf(M,s,i)||M.s>=f);if(h.length===0)continue;let p=g.filter(M=>na(M,o)),x=ho(h),b=ho(p),P=Math.ceil(Math.sqrt(Math.max(0,b-x))*3),y=Math.min(ho(g),x+P);y<=0||(l.set(m,y),d+=y)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(a,d),componentBudgets:l}}function yf(e,n,t){let r=new Map;if(e.length===0||t<=0)return{selected:r,budgetLimit:0};let o=Wi(e.map(A=>A.s)),s=Wi(e.map(A=>A.rank)),i=Math.max(1e-6,o.q3-o.q1),a=Math.min(o.max,Math.max(o.p95,o.q3+i*.85)),c=Math.min(o.max,Math.max(o.p80,o.q3+i*.15)),l=Math.min(o.max,Math.max(o.p70,o.q3)),u=Math.max(s.p97,s.median*1.8),f=Math.max(s.p88,s.median*1.35),d=bf(e,n,t,o,s,a,u),m=d.budgetLimit;if(m<=0)return{selected:r,budgetLimit:0};let g=hf(e),h=new Set,p=new Set,x=new Set,b=new Map,P=n==="primary"?Math.min(Math.max(0,d.budgetLimit-1),Math.max(2,Math.floor(d.budgetLimit*.28))):0,y=[...e].sort((A,C)=>Kn(C)-Kn(A)||C.s/Math.max(1,C.r.length)-A.s/Math.max(1,A.r.length)||C.len-A.len),M=[...e].sort((A,C)=>ji(C)-ji(A)||Kn(C)-Kn(A)||C.len-A.len),S=(A,C)=>{A.sel=!0,A.why=C,x.add(A.comp);for(let _ of A.e)p.add(_);for(let _ of A.r){h.add(_.polygon);let w=r.get(_.polygon);w?w.add(_.edge):r.set(_.polygon,new Set([_.edge]))}},T=(A,C)=>{let _=d.componentBudgets;if(C<=0||!_)return!0;let w=_.get(A.comp)??0;return(b.get(A.comp)??0)+C<=w},E=(A,C)=>{C<=0||!d.componentBudgets||b.set(A.comp,(b.get(A.comp)??0)+C)};for(let A of M){let C=A.r.reduce((w,V)=>w+(h.has(V.polygon)?0:1),0);if(A.cost=C,!(C>m||!T(A,C)||C>0&&m-C<P||!na(A,s))&&(S(A,"global-outlier"),E(A,C),m-=C,m<=0))return{selected:r,budgetLimit:d.budgetLimit}}for(let A of y){if(A.sel)continue;let C=A.r.reduce((F,k)=>F+(h.has(k.polygon)?0:1),0);if(A.cost=C,C>m||!T(A,C)||C>0&&m-C<P)continue;let _=A.r.length===2,w=g.has(A)&&(n==="primary"||n==="follow-up"&&A.s>=c*1.08&&A.rank>=f)&&(_?A.s>=c||A.rank>=f:A.s>=c*1.18||A.rank>=f*1.12),V=_?A.s>=a||A.rank>=u:A.s>=a*1.35||A.rank>=u*1.2,N=C===0&&(_?A.s>=l||A.rank>=f:A.s>=l*1.25||A.rank>=f*1.12);if(!(!w&&!V&&!N)&&(S(A,w?"component-anchor":V?"global-outlier":"shared-polygon"),E(A,C),m-=C,m<=0))return{selected:r,budgetLimit:d.budgetLimit}}for(let A of y){if(A.sel)continue;let C=A.r.reduce((k,$)=>k+(h.has($.polygon)?0:1),0);if(A.cost=C,C>1||C>m||!T(A,C))continue;let _=A.r.some(k=>h.has(k.polygon)),w=A.e.some(k=>p.has(k));if(n==="primary"&&A.r.length===1&&C===1&&(x.has(A.comp)||w||_)&&A.rank>=f*1.05&&A.nr>=.16&&A.vr<=.32){if(S(A,"local-follow-up"),E(A,C),m-=C,m<=0)return{selected:r,budgetLimit:d.budgetLimit};continue}if(A.r.length!==2)continue;let N=_&&C===1&&A.proj>=f*1.45&&A.vr<=.18;if(!w&&!N)continue;if((A.s>=l*.42||A.rank>=f*.62)&&A.s<=l*1.1&&A.proj>=24&&(S(A,"local-follow-up"),E(A,C),m-=C,m<=0))return{selected:r,budgetLimit:d.budgetLimit}}return{selected:r,budgetLimit:d.budgetLimit}}function ta(e,n,t,r,o){let s=Zi(e),i=Qi(e,s,n.capacityScale),a=new Map;for(let u of i){let f=a.get(u.key);f?f.push(u):a.set(u.key,[u])}let c=gf(e,s,a,t).filter(u=>df(u,o)),l=yf(c,o?"follow-up":"primary",r);return{selected:l.selected,candidates:c,budgetLimit:l.budgetLimit}}function Pf(e,n){let t=[];for(let r=0;r<e.length;r+=1){let o=e[r],s=n.get(r);s&&ea(o)?t.push(...ff(o,s)):t.push(o)}return t}function Af(e){let[n,t]=e.o,r=n??t,o=t??n;return{key:e.key,aPolygon:r?.polygon??-1,aEdge:r?.edge??-1,bPolygon:o?.polygon??-1,bEdge:o?.edge??-1,color:r?.color??o?.color,materialKey:r?.materialKey??o?.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 Co(e,n,t){let r=Qn(n),o=Yi(t);if(!Jn(r,n)||e.length===0)return e;let s=e,i,a=o.budget;for(let c=0;c<o.passes;c+=1){let l=ta(s,r,o,a,i);if(c===0&&(a=Math.min(a,l.budgetLimit)),l.selected.size===0)break;let u=Pf(s,l.selected);if(u.length===s.length)break;if(a-=l.selected.size,a<=0){s=u;break}i=mf(l.candidates),s=u}return s}function ra(e,n,t){let r=Qn(n),o=Yi(t);if(!Jn(r,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let s=ta(e,r,o,o.budget),i=0;for(let a of s.selected.values())i+=a.size;return{candidates:s.candidates.map(Af),selectedPolygons:s.selected.size,selectedEdges:i,addedPolygons:s.selected.size}}function _o(e,n){let t=Qn(n);if(!Jn(t,n)||e.length===0)return e;let{edgeRepairs:r}=To(e,t);return r.some(o=>o.size>0)?e.map((o,s)=>sf(o,r[s],t.capacityScale)):e}function Ut(e,n=xo,t=bo){if(e.length===0)return e;let r=Co(e,n,t);return _o(r,n)}function oa(e,n){let t=Qn(n);return!Jn(t,n)||e.length===0?Eo():To(e,t).diagnostics}function sa(e,n){let t=Qn(n);if(!Jn(t,n)||e.length===0)return{diagnostics:Eo(),candidates:[]};let r=To(e,t,!0);return{diagnostics:r.diagnostics,candidates:r.candidates??[]}}var Mf=3,Sf=.03,Ef=.02,et={maxAngleDeg:Mf,maxPlaneDisplacement:Sf,maxBoundaryDisplacement:Ef,isolatedPairs:!1},Tf={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},Cf=1800,_f=.65,vf=24,If=50,Vf=1e3,Of=1e3,nt={minGroupPolygons:2,maxCandidateAxes:24},Rf={...nt,maxCandidateAxes:1};function jt(e,n={}){let t=n.meshResolution??"lossy",r=f=>t==="lossy"?Ut(f):f,o={},s=ia(e,!1,o),i=s,a=$t(s),c=(f,d=$t(f))=>d>=a?!1:(i=f,a=d,!0),l=t==="lossy"&&n.rectCover===void 0?wf(s):n.rectCover,u=vo(s,l);if(u!==s&&c(u),t==="lossy"&&n.rectCover===void 0){let f=vo(s,void 0);f!==s&&c(f)}if(t==="lossy"&&(i.length<=1||a<=1+1e-9))return r(i);if(t==="lossy"){let f=ia(e,Tf,o);c(f),n.rectCover!==void 0&&n.rectCover!==!1&&c(vo(f,n.rectCover))}return r(i)}function $t(e){let n=0;for(let t of e){let r=t.vertices.length,o=r<=4?0:Math.min(4,r-4)*.12,s=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+o+s}return n}function vo(e,n){if(n===!1)return e;let t=Lf(e,n);if(!t)return e;let r=Rt(e,t);return r.length<e.length?r:e}function Lf(e,n){if(n&&n!==!0)return n;let t=n===!0,r=e.length;return r>2200||!t&&r>=vf&&r<If||!t&&r>Vf?null:!t&&r<=300?{...nt,maxCandidateAxes:1}:r>300?!t&&(Df(e)>12||Ff(e)>Of)?null:{...nt,maxCandidateAxes:Math.min(nt.maxCandidateAxes??24,2)}:nt}function wf(e){return e.length>Cf||e.length===0||Nf(e)/e.length<_f?!1:Rf}function Nf(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function Df(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function Ff(e){let n=new Map;for(let r of e)for(let o=0;o<r.vertices.length;o++){let s=r.vertices[o],i=r.vertices[(o+1)%r.vertices.length],a=Yt(s,i);n.set(a,(n.get(a)??0)+1)}let t=0;for(let r of n.values())r===1&&(t+=1);return t}function Oo(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function ca(e,n){if(n===e||n.length===e.length&&n.every((o,s)=>o===e[s]))return null;let t=new Set(n),r=[];for(let o=0;o<e.length;o++)t.has(e[o])&&r.push(o);return r.length===e.length?null:r}function Bf(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let o=$n(e);if(o.size===0)t=null;else{t=[];for(let s=0;s<e.length;s++)o.has(s)||t.push(s)}n&&(n.dedupedIndices=t)}let r=Oo(e,t);return n&&(n.deduped=r),r}function kf(e,n){if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let o=Be(e);t=ca(e,o),n&&(n.interiorIndices=t)}let r=Oo(e,t);return n&&(n.interior=r),r}function ia(e,n,t){let r=Bf(e,t),o=kf(r,t),s=t?.baseline??Re(o);if(t&&!t.baseline&&(t.baseline=s),!n)return s;let i=n===!0?et:Gf(n);if(i.isolatedPairs){let c=$f(Uf(r,t),i),l=Re(c);return l.length<s.length?l:s}let a=Re(Be(Qf(r,i,t)));return a.length<s.length?a:s}function la(e,n){return n?(n.snapped||(n.snapped=zt(e)),n.snapped):zt(e)}function Uf(e,n){if(!n)return Be(zt(e));if(!n.snappedInterior){let t=la(e,n);if(n.snappedInteriorIndices===void 0){let r=Be(t);n.snappedInteriorIndices=ca(t,r),n.snappedInterior=r}else n.snappedInterior=Oo(t,n.snappedInteriorIndices)}return n.snappedInterior}function Gf(e){return{maxAngleDeg:e.maxAngleDeg??et.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??et.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??et.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??et.isolatedPairs}}function $f(e,n){let t=e.map(i=>{let a=Lo(i);return a?{polygon:i,normal:a.normal,area:a.area,materialKey:pa(i)}:null}),r=new Map;for(let i=0;i<e.length;i++){let a=e[i];if(!(a.vertices.length!==3||!t[i]))for(let c=0;c<a.vertices.length;c++){let l=Yt(a.vertices[c],a.vertices[(c+1)%a.vertices.length]),u=r.get(l);u?u.push(i):r.set(l,[i])}}let o=[];for(let i of r.values()){if(i.length!==2)continue;let[a,c]=i,l=Kf(a,c,e,t,n);l&&o.push(l)}let s=Xf(o);return s.length===0?e:zf(e,s)}function zf(e,n){let t=new Map,r=new Set,o=ua(n.flatMap(i=>i.vertexMoves));for(let i of n){let a=Math.min(i.a,i.b);t.set(a,i.polygon),r.add(Math.max(i.a,i.b))}let s=[];for(let i=0;i<e.length;i++){let a=t.get(i);if(a){s.push(a);continue}r.has(i)||s.push(e[i])}return o.size>0?fa(s,o):s}function Xf(e){return e.length>3e3?Wf(e):jf(e)}function Wf(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 a=(n.get(s.a)??0)+(n.get(s.b)??0),c=(n.get(i.a)??0)+(n.get(i.b)??0);return a-c||s.score-i.score}),r=new Set,o=[];for(let s of t)r.has(s.a)||r.has(s.b)||(r.add(s.a),r.add(s.b),o.push(s));return o}function jf(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=[],r=new Array(e.length).fill(!0),o=new Map,s=new Vo;for(let[l,u]of n)o.set(l,u.length);let i=l=>(o.get(l.a)??0)+(o.get(l.b)??0),a=l=>{let u=e[l];s.push({degree:i(u),score:u.score,index:l})},c=(l,u)=>{if(!r[l])return;r[l]=!1;let f=e[l];for(let d of[f.a,f.b])o.set(d,(o.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)a(l);for(;s.size()>0;){let l=s.pop();if(!r[l.index])continue;let u=e[l.index];if(i(u)!==l.degree){a(l.index);continue}t.push(u);let d=new Set;for(let m of[u.a,u.b])for(let g of n.get(m)??[])c(g,d);for(let m of d)for(let g of n.get(m)??[])r[g]&&a(g)}return t}var Vo=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 r=t-1>>1;if(Io(this.items[r],this.items[t])<=0)break;[this.items[r],this.items[t]]=[this.items[t],this.items[r]],t=r}}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 r=0;for(;;){let o=r*2+1,s=o+1,i=r;if(o<this.items.length&&Io(this.items[o],this.items[i])<0&&(i=o),s<this.items.length&&Io(this.items[s],this.items[i])<0&&(i=s),i===r)break;[this.items[r],this.items[i]]=[this.items[i],this.items[r]],r=i}}return n}};function Io(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function ua(e){let n=new Map;for(let r of e){let o=n.get(r.key);o?(o.x+=r.target[0],o.y+=r.target[1],o.z+=r.target[2],o.count+=1):n.set(r.key,{x:r.target[0],y:r.target[1],z:r.target[2],count:1})}let t=new Map;for(let[r,o]of n)t.set(r,[o.x/o.count,o.y/o.count,o.z/o.count]);return t}function Yf(e,n){let t=[];for(let r=0;r<e.length;r++){let o=e[r].vertices,s=n[r]?.vertices;if(!s||s.length!==o.length)continue;for(let c=0;c<o.length;c++)t.push({key:Oe(o[c]),target:s[c]});let i=e[r].textureTriangles??[],a=n[r]?.textureTriangles??[];for(let c=0;c<i.length;c++){let l=a[c];if(l)for(let u=0;u<i[c].vertices.length;u++)t.push({key:Oe(i[c].vertices[u]),target:l.vertices[u]})}}return t}function Hf(e,n){let t=[];for(let r of e)for(let o of r.textureTriangles??[])for(let s of o.vertices)t.push({key:Oe(s),target:Fo(s,n)});return t}function fa(e,n){return e.map(t=>{let r=!1,o=a=>{let c=n.get(Oe(a));return c?(r=!0,c):a},s=t.vertices.map(o),i=Ro(t.textureTriangles,o);return r?{...t,vertices:s,...i?{textureTriangles:i}:{}}:t})}function Kf(e,n,t,r,o){let s=t[e],i=t[n],a=r[e],c=r[n];if(!a||!c||s.vertices.length!==3||i.vertices.length!==3||!um(s,i,a,c))return null;let l=No(s,i);if(!l)return null;let[u,f,d,m]=l;if((d+1)%i.vertices.length===m)return null;let h=Math.abs(He(a.normal,c.normal)),p=Math.cos(o.maxAngleDeg*Math.PI/180);if(h<p)return null;let x=(f+1)%s.vertices.length,b=3-d-m,P=[s.vertices[f],s.vertices[x],s.vertices[u],i.vertices[b]],y=qf(P);if(!y)return null;let M=0,S=0;for(let C of P){let _=Math.abs(Do(C,y));M=Math.max(M,_),S+=_*_}if(M>Math.min(o.maxPlaneDisplacement,o.maxBoundaryDisplacement))return null;let T=P.map(C=>Fo(C,y));if(!Zf(T,y.normal))return null;let E=Lo({vertices:T});if(!E||He(E.normal,a.normal)<.2||He(E.normal,c.normal)<.2)return null;let A={vertices:P,color:s.color,...s.doubleSided?{doubleSided:!0}:{},...s.data?{data:{...s.data}}:{}};if(wo(s,i)&&s.uvs&&i.uvs&&s.texture){A.texture=s.texture,s.textureWrap&&(A.textureWrap={...s.textureWrap}),s.textureAlphaMode&&(A.textureAlphaMode=s.textureAlphaMode),A.uvs=[[...s.uvs[f]],[...s.uvs[x]],[...s.uvs[u]],[...i.uvs[b]]];let C=Jf([s,i]);C?.length&&(A.textureTriangles=C)}return{a:e,b:n,polygon:A,vertexMoves:[...P.map((C,_)=>({key:Oe(C),target:T[_]})),...Hf([s,i],y)],score:S/P.length+M*.25+(1-h)*.1}}function qf(e){if(e.length<3)return null;let n=0,t=0,r=0,o=0,s=0,i=0;for(let c=0;c<e.length;c++){let l=e[c],u=e[(c+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),t+=(l[2]-u[2])*(l[0]+u[0]),r+=(l[0]-u[0])*(l[1]+u[1]),o+=l[0],s+=l[1],i+=l[2]}let a=Pa([n,t,r]);return a?{normal:a,point:[o/e.length,s/e.length,i/e.length]}:null}function Zf(e,n){let t=0;for(let r=0;r<e.length;r++){let o=e[r],s=e[(r+1)%e.length],i=e[(r+2)%e.length],a=He(ya(tt(s,o),tt(i,s)),n);if(Math.abs(a)<=1e-9)continue;let c=a>0?1:-1;if(t===0)t=c;else if(t!==c)return!1}return!0}function Qf(e,n,t){let r=la(e,t),o=sm(r,n);if(o<=0)return r;let s=r.map(m=>{let g=Lo(m);return g?{polygon:m,normal:g.normal,area:g.area,materialKey:pa(m)}:null}),i=cm(r,s),a=new Set,c=Array(r.length),l=[],u=(m,g)=>{c[m]=g};for(let m=0;m<r.length;m++){let g=s[m];if(a.has(m))continue;if(!g){u(m,r[m]);continue}let h=fm(m,s,i,a,o,n);for(let x of h)a.add(x);if(h.length<2){u(m,r[m]);continue}let p=tm(h,r,s,i,o,n);l.push(...p.vertexMoves);for(let x of h)u(x,p.polygons.get(x)??r[x])}let f=c.flatMap(m=>m?[m]:[]),d=l.length>0?fa(f,ua(l)):f;return zt(d)}function zt(e){let n=ga(e),t=1e-4;if(n<=0)return e;let r=im(n),o=am(t);return e.map(s=>{let i=f=>r.snap(f),a=s.vertices.map(i),c=s.uvs&&s.uvs.length===s.vertices.length?s.uvs.map(f=>o.snap(f)):void 0,l=Ro(s.textureTriangles,i),u={...s,vertices:a,...c?{uvs:c}:{},...l?{textureTriangles:l}:{}};return{...u,...u.texture?{textureTriangles:ma(u)}:{}}})}function ma(e){if(e.texture){if(e.textureTriangles?.length)return nm(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return em(e.vertices,e.uvs)}}function Jf(e){let n=e.flatMap(t=>ma(t)??[]);return n.length>0?n:void 0}function em(e,n){let t=[];for(let r=1;r<e.length-1;r++)t.push({vertices:[[...e[0]],[...e[r]],[...e[r+1]]],uvs:[[...n[0]],[...n[r]],[...n[r+1]]]});return t}function nm(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Ro(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(r=>[...r])}))}function tm(e,n,t,r,o,s){let i=da(e,n,t,o,s);return i?om(i):rm(e,n,t,r,o,s)}function rm(e,n,t,r,o,s){let i=new Set(e),a=[];for(let f of e)for(let d of r.get(f)??[]){if(f>=d||!i.has(d))continue;let m=da([f,d],n,t,o,s);m&&a.push(m)}a.sort((f,d)=>d.score-f.score);let c=new Set,l=new Map,u=[];for(let f of a)if(!f.indices.some(d=>c.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];c.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function om(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 da(e,n,t,r,o){let s=ha(e,t);if(!s||!xa(e,t,s,r,o))return null;let i=e.map(u=>n[u]),a=i.map(u=>gm(u,s)),c=$t(Re(i)),l=$t(Re(a));return l>=c?null:{indices:e,source:i,projected:a,vertexMoves:Yf(i,a),score:c-l}}function sm(e,n){return ga(e)<=0?0:n.maxPlaneDisplacement}function ga(e){let n=1/0,t=1/0,r=1/0,o=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let[l,u,f]of c.vertices)n=Math.min(n,l),t=Math.min(t,u),r=Math.min(r,f),o=Math.max(o,l),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let a=Math.hypot(o-n,s-t,i-r);return a<=0?0:Math.min(.025,Math.max(1e-4,a*25e-5))}function im(e){let n=new Map,t=o=>Math.floor(o/e),r=(o,s,i)=>`${o},${s},${i}`;return{snap(o){let s=t(o[0]),i=t(o[1]),a=t(o[2]);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)for(let m=-1;m<=1;m++){let g=n.get(r(s+f,i+d,a+m));if(g){for(let h of g)if(pm(o,h)<=e)return[h[0],h[1],h[2]]}}let c=[o[0],o[1],o[2]],l=r(s,i,a),u=n.get(l);return u?u.push(c):n.set(l,[c]),c}}}function am(e){let n=new Map,t=o=>Math.floor(o/e),r=(o,s)=>`${o},${s}`;return{snap(o){let s=t(o[0]),i=t(o[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(r(s+u,i+f));if(d){for(let m of d)if(Math.hypot(o[0]-m[0],o[1]-m[1])<=e)return[m[0],m[1]]}}let a=[o[0],o[1]],c=r(s,i),l=n.get(c);return l?l.push(a):n.set(c,[a]),a}}}function pa(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 Lo(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,r=0,o=0,s=n[0];for(let a=1;a<n.length-1;a++){let c=tt(n[a],s),l=tt(n[a+1],s),u=ya(c,l);t+=u[0],r+=u[1],o+=u[2]}let i=Math.hypot(t,r,o);return i<=1e-10?null:{normal:[t/i,r/i,o/i],area:i/2}}function cm(e,n){let t=new Map,r=new Map;for(let o=0;o<e.length;o++){let s=e[o];if(!(!n[o]||s.vertices.length<3))for(let i=0;i<s.vertices.length;i++){let a=Yt(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),c=t.get(a);c?c.push(o):t.set(a,[o])}}for(let o of t.values())for(let s=0;s<o.length;s++)for(let i=s+1;i<o.length;i++){let a=o[s],c=o[i];lm(e[a],e[c],n[a],n[c])&&(aa(r,a,c),aa(r,c,a))}return r}function lm(e,n,t,r){if(!t||!r||t.materialKey!==r.materialKey||!!e.uvs!=!!n.uvs)return!1;if(Xt(e)||Xt(n))return wo(e,n);if(!e.uvs||!n.uvs)return!0;let o=No(e,n);if(!o)return!1;let[s,i,a,c]=o;return Wt(e.uvs[s],n.uvs[a])&&Wt(e.uvs[i],n.uvs[c])}function um(e,n,t,r){return t.materialKey!==r.materialKey?!1:Xt(e)||Xt(n)?wo(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function Xt(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function wo(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=No(e,n);if(!t)return!1;let[r,o,s,i]=t;return Wt(e.uvs[r],n.uvs[s])&&Wt(e.uvs[o],n.uvs[i])}function aa(e,n,t){let r=e.get(n);r?r.add(t):e.set(n,new Set([t]))}function fm(e,n,t,r,o,s){let i=[e],a=new Set([e]),c=[e];for(;c.length>0;){let l=c.shift();for(let u of t.get(l)??[]){if(r.has(u)||a.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&mm([...i,u],n,o,s)&&(i.push(u),a.add(u),c.push(u))}}return i}function mm(e,n,t,r){let o=ha(e,n);return!!o&&xa(e,n,o,t,r)}function ha(e,n){let t=n[e[0]];if(!t)return null;let r=0,o=0,s=0,i=0,a=0,c=0,l=0;for(let m of e){let g=n[m];if(!g)return null;let h=He(t.normal,g.normal)<0?-1:1,p=Math.max(g.area,1e-6);r+=g.normal[0]*h*p,o+=g.normal[1]*h*p,s+=g.normal[2]*h*p;for(let x of g.polygon.vertices)i+=x[0],a+=x[1],c+=x[2],l+=1}let u=Pa([r,o,s]);if(!u||l===0)return null;let f=ba(e,n),d=dm(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,a/l,c/l],boundaryVertexKeys:f}}function dm(e,n,t,r){let o=1/0,s=-1/0;for(let i of e){let a=n[i];if(a)for(let c of a.polygon.vertices){if(!r.has(Oe(c)))continue;let l=He(c,t);o=Math.min(o,l),s=Math.max(s,l)}}return Number.isFinite(o)&&Number.isFinite(s)?{min:o,max:s}:null}function xa(e,n,t,r,o){let s=Math.cos(o.maxAngleDeg*Math.PI/180),i=t.boundaryVertexKeys??ba(e,n);for(let a of e){let c=n[a];if(!c||Math.abs(He(c.normal,t.normal))<s)return!1;for(let l of c.polygon.vertices){let u=i.has(Oe(l))?o.maxBoundaryDisplacement:r;if(Math.abs(Do(l,t))>u)return!1}}return!0}function ba(e,n){let t=new Map;for(let o of e){let s=n[o];if(!s)continue;let i=s.polygon.vertices;for(let a=0;a<i.length;a++){let c=i[a],l=i[(a+1)%i.length],u=Yt(c,l),f=t.get(u);f?f.count+=1:t.set(u,{count:1,a:c,b:l})}}let r=new Set;for(let o of t.values())o.count===1&&(r.add(Oe(o.a)),r.add(Oe(o.b)));return r}function gm(e,n){let t=o=>Fo(o,n),r=Ro(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...r?{textureTriangles:r}:{}}}function No(e,n){for(let t=0;t<e.vertices.length;t++){let r=(t+1)%e.vertices.length;for(let o=0;o<n.vertices.length;o++){let s=(o+1)%n.vertices.length;if(Gt(e.vertices[t],n.vertices[o])&&Gt(e.vertices[r],n.vertices[s]))return[t,r,o,s];if(Gt(e.vertices[t],n.vertices[s])&&Gt(e.vertices[r],n.vertices[o]))return[t,r,s,o]}}return null}function Yt(e,n){let t=Oe(e),r=Oe(n);return t<r?`${t}|${r}`:`${r}|${t}`}function Oe(e){return`${e[0]},${e[1]},${e[2]}`}function Gt(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Wt(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function tt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function ya(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 pm(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function Pa(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 Do(e,n){return He(tt(e,n.point),n.normal)}function Fo(e,n){let t=Do(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var rt=1e-5,Bo=.001,ko=6;function Ht(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],r=0,o=0,s=0;for(let a=1;a+1<n.length;a++){let c=n[a],l=n[a+1],u=c[1]-t[1],f=c[0]-t[0],d=c[2]-t[2],m=l[1]-t[1],g=l[0]-t[0],h=l[2]-t[2];r-=f*h-d*g,o-=d*m-u*h,s-=u*g-f*m}let i=Math.hypot(r,o,s);return i<1e-9?null:[r/i,o/i,s/i]}function Uo(e,n){let t=n.meshRotation,r=t?Bn(e,t[0]??0,t[1]??0,t[2]??0):e;return Bn(r,n.rotX,0,n.rotY)[2]}function Kt(e,n,t=rt){return Uo(e,n)>t}function Aa(e,n,t=rt){let r=Ht(e);return r===null||Kt(r,n,t)}function Go(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function $o(e){let n=new Map;for(let t of e){if(!t)continue;let r=Go(t);n.has(r)||n.set(r,t)}return Array.from(n,([t,r])=>({key:t,normal:r}))}function Ma(e){return $o(e.map(Ht))}function zo(e,n=Bo){let t=Math.abs(e[0]),r=Math.abs(e[1]),o=Math.abs(e[2]),s=Math.max(t,r,o);return s>1-n&&t+r+o-s<n}function Sa(e){return e.length<=ko&&e.every(({normal:n})=>zo(n))}function Ea(e,n,t=rt){let r=[];for(let{key:o,normal:s}of e)Kt(s,n,t)&&r.push(o);return r.sort(),r.join("|")}function Xo(e,n,t,r,o){let s=(g,h,p)=>{let x=[0,0,0];return x[e]=g,x[(e+1)%3]=h,x[(e+2)%3]=p,x},i=s(n,-r,-r),a=s(n,r,-r),c=s(n,r,r),l=s(n,-r,r),u=s(t,-r,-r),f=s(t,r,-r),d=s(t,r,r),m=s(t,-r,r);return[{vertices:[i,a,c,l],color:o},{vertices:[u,f,d,m],color:o},{vertices:[i,a,f,u],color:o},{vertices:[a,c,d,f],color:o},{vertices:[c,l,m,d],color:o},{vertices:[l,i,u,m],color:o}]}function Wo(e={}){let n=e.size??5,t=e.thickness??.025,r=e.negative??!1,o=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",a=n*t/2,c=r?-n:0;return[...Xo(0,c,n,a,o),...Xo(1,c,n,a,s),...Xo(2,c,n,a,i)]}var hm=["right","left","front","back","top","bottom"];function jo(e){return[e[0],e[1],e[2]]}function Ta(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 xm(e){if(e.min&&e.max)return Ta(e.min,e.max);let n=e.center?jo(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=jo(e.size):t=[1,1,1];let r=[t[0]/2,t[1]/2,t[2]/2];return Ta([n[0]-r[0],n[1]-r[1],n[2]-r[2]],[n[0]+r[0],n[1]+r[1],n[2]+r[2]])}function bm(e,n){let[t,r,o]=e,[s,i,a]=n;return[{name:"right",vertices:[[s,r,o],[s,i,o],[s,i,a],[s,r,a]]},{name:"left",vertices:[[t,i,o],[t,r,o],[t,r,a],[t,i,a]]},{name:"front",vertices:[[s,i,o],[t,i,o],[t,i,a],[s,i,a]]},{name:"back",vertices:[[t,r,o],[s,r,o],[s,r,a],[t,r,a]]},{name:"top",vertices:[[t,r,a],[s,r,a],[s,i,a],[t,i,a]]},{name:"bottom",vertices:[[t,i,o],[s,i,o],[s,r,o],[t,r,o]]}]}function ym(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function Pm(e,n){let t={vertices:e.vertices.map(jo)};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(r=>[r[0],r[1]])),n.data!==void 0&&(t.data={...n.data}),t}function Yo(e={}){let{min:n,max:t}=xm(e);if(n[0]===t[0]||n[1]===t[1]||n[2]===t[2])return[];let r={color:e.color??"#ffffff",texture:e.texture,material:e.material,uvs:e.uvs,data:e.data},o=bm(n,t),s=new Map(o.map(a=>[a.name,a])),i=[];for(let a of hm){let c=e.faces?.[a];if(c===!1)continue;let l=s.get(a);l&&i.push(Pm(l,ym(r,c)))}return i}function Ca(e,n,t,r){let o=[0,0,0];return o[e]=n,o[(e+1)%3]=t,o[(e+2)%3]=r,o}function Am(e,n,t,r,o){let s=(g,h,p)=>Ca(e,g,h,p),i=s(n,-r,-r),a=s(n,r,-r),c=s(n,r,r),l=s(n,-r,r),u=s(t,-r,-r),f=s(t,r,-r),d=s(t,r,r),m=s(t,-r,r);return[{vertices:[i,a,c,l],color:o},{vertices:[u,f,d,m],color:o},{vertices:[i,a,f,u],color:o},{vertices:[a,c,d,f],color:o},{vertices:[c,l,m,d],color:o},{vertices:[l,i,u,m],color:o}]}function Mm(e,n,t,r,o){let s=(f,d,m)=>Ca(e,f,d,m),i=s(n,-r,-r),a=s(n,r,-r),c=s(n,r,r),l=s(n,-r,r),u=s(t,0,0);return[{vertices:[i,a,c,l],color:o},{vertices:[i,a,u],color:o},{vertices:[a,c,u],color:o},{vertices:[c,l,u],color:o},{vertices:[l,i,u],color:o}]}function Sm(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function Ho(e){let n=e.axis,t=e.sign??1,r=e.shaftLength??4,o=e.shaftHalfThickness??.05,s=e.headLength??.8,i=e.headHalfThickness??.2,a=e.color??"#ffffff",c=e.shaft??!0,l=r*t,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(r+s)*t,g=Mm(n,d,m,i,a),h=t===-1?Sm(g):g;return c?[...Am(n,u,f,o,a),...h]:h}function qt(e,n,t){let r=[0,0,0],o=(e+1)%3,s=(e+2)%3;return r[o]=Math.cos(t)*n,r[s]=Math.sin(t)*n,r}function Ko(e){let n=e.axis,t=e.radius,r=e.halfThickness??Math.max(.05,t*.04),o=e.segments??32,s=e.color??"#ffffff",i=t-r,a=t+r,c=[];for(let l=0;l<o;l++){let u=l/o*Math.PI*2,f=(l+1)/o*Math.PI*2,d=qt(n,i,u),m=qt(n,i,f),g=qt(n,a,u),h=qt(n,a,f);c.push({vertices:[d,g,h,m],color:s})}return c}function qo(e){let n=e.axis,t=e.outerRadius,r=e.color??"#ffffff",o=(n+1)%3,s=(n+2)%3,i=(a,c)=>{let l=[0,0,0];return l[n]=0,l[o]=a,l[s]=c,l};return[{vertices:[i(-t,-t),i(t,-t),i(t,t),i(-t,t)],color:r}]}function Zo(e){let n=e.axis,t=e.size??.4,r=e.offset??t*2,o=typeof r=="number"?r:r[0],s=typeof r=="number"?r:r[1],i=e.along??0,a=e.color??"#ffffff",c=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=i,m[c]=o+f,m[l]=s+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:a}]}function Qo(e){let{center:n,size:t,color:r="#ffffff"}=e,[o,s,i]=n,a=[[o+t,s,i],[o-t,s,i],[o,s+t,i],[o,s-t,i],[o,s,i+t],[o,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:[a[l[0]],a[l[1]],a[l[2]]],color:r}))}function Jo(e={}){let{radius:n=50,color:t="#cccccc"}=e,r=Math.min(Math.max(0,Math.floor(e.subdivisions??1)),3),o=(1+Math.sqrt(5))/2,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,l,u])=>{let f=Math.sqrt(c*c+l*l+u*u);return[c/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 c=0;c<r;c++){let l=[...s],u=[],f=new Map,d=(m,g)=>{let h=m<g?`${m}-${g}`:`${g}-${m}`,p=f.get(h);if(p!==void 0)return p;let x=s[m],b=s[g],P=(x[0]+b[0])/2,y=(x[1]+b[1])/2,M=(x[2]+b[2])/2,S=Math.sqrt(P*P+y*y+M*M);P/=S,y/=S,M/=S;let T=l.length;return l.push([P,y,M]),f.set(h,T),T};for(let[m,g,h]of i){let p=d(m,g),x=d(g,h),b=d(h,m);u.push([m,p,b]),u.push([g,x,p]),u.push([h,b,x]),u.push([p,x,b])}s=l,i=u}let a=s.map(([c,l,u])=>[c*n,l*n,u*n]);return i.map(([c,l,u])=>({vertices:[a[c],a[l],a[u]],color:t}))}function es(e={}){let{size:n=100,color:t="#cccccc"}=e,r=n/Math.sqrt(3),o=[[r,r,r],[r,-r,-r],[-r,r,-r],[-r,-r,r]];return[[0,1,2],[0,3,1],[0,2,3],[1,3,2]].map(([i,a,c])=>({vertices:[o[i],o[a],o[c]],color:t}))}function ns(e={}){let{size:n=100,color:t="#cccccc"}=e,r=(1+Math.sqrt(5))/2,o=n/Math.sqrt(1+r*r),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,c,l])=>[a*o,c*o,l*o]);return[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]].map(([a,c,l])=>({vertices:[s[a],s[c],s[l]],color:t}))}function ts(e={}){let{size:n=100,color:t="#cccccc"}=e,r=(1+Math.sqrt(5))/2,o=1/r,s=n/Math.sqrt(3),a=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1],[0,o,r],[0,-o,r],[0,o,-r],[0,-o,-r],[o,r,0],[-o,r,0],[o,-r,0],[-o,-r,0],[r,0,o],[r,0,-o],[-r,0,o],[-r,0,-o]].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=>a[u]),color:t}))}function ot(e={}){let{radius:n=50,height:t=100,radialSegments:r=12,color:o="#cccccc"}=e,s=e.radiusTop??n,i=t/2,a=-i,c=i,l=Math.max(3,r),u=[],f=Array.from({length:l+1},(g,h)=>h/l*Math.PI*2),d=n<=1e-6,m=s<=1e-6;for(let g=0;g<l&&!(d&&m);g++){let h=f[g],p=f[g+1],x=Math.cos(h)*n,b=Math.sin(h)*n,P=Math.cos(p)*n,y=Math.sin(p)*n,M=Math.cos(h)*s,S=Math.sin(h)*s,T=Math.cos(p)*s,E=Math.sin(p)*s,A=[x,b,a],C=[P,y,a],_=[T,E,c],w=[M,S,c];if(m){let V=[0,0,c];u.push({vertices:[A,C,V],color:o})}else if(d){let V=[0,0,a];u.push({vertices:[V,_,w],color:o})}else u.push({vertices:[A,C,_,w],color:o})}if(n>1e-6){let g=[0,0,a];for(let h=0;h<l;h++){let p=f[h],x=f[h+1],b=[Math.cos(p)*n,Math.sin(p)*n,a],P=[Math.cos(x)*n,Math.sin(x)*n,a];u.push({vertices:[[...g],[...P],[...b]],color:o})}}if(s>1e-6){let g=[0,0,c];for(let h=0;h<l;h++){let p=f[h],x=f[h+1],b=[Math.cos(p)*s,Math.sin(p)*s,c],P=[Math.cos(x)*s,Math.sin(x)*s,c];u.push({vertices:[[...g],[...b],[...P]],color:o})}}return u}function rs(e={}){return ot({...e,radiusTop:0})}function Zt(e,n,t,r){let o=Math.sin(e),s=Math.cos(e),i=Math.sin(n),a=Math.cos(n);return[(t+r*a)*s,(t+r*a)*o,r*i]}function os(e={}){let{radius:n=50,tube:t=15,radialSegments:r=12,tubularSegments:o=16,color:s="#cccccc"}=e,i=Math.max(3,r),a=Math.max(3,o),c=[];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<a;d++){let m=d/a*Math.PI*2,g=(d+1)/a*Math.PI*2,h=Zt(u,m,n,t),p=Zt(f,m,n,t),x=Zt(f,g,n,t),b=Zt(u,g,n,t);c.push({vertices:[h,p,x,b],color:s})}}return c}var _a=.01,va=.01;function Ia(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,r=e[0]/t,o=e[1]/t,s=e[2]/t,i=Math.sign(s||1)*Math.max(Math.abs(s),.01),a=n,c=.01;return[1,0,0,0,0,1,0,0,-r/i,-o/i,c,0,a*r/i,a*o/i,a*(1-c),1]}function Va(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/t,o=n[1]/t,s=n[2]/t;return e[0]*r+e[1]*o+e[2]*s>0}function Oa(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,a)=>i[0]-a[0]||i[1]-a[1]);let r=(i,a,c)=>(a[0]-i[0])*(c[1]-i[1])-(a[1]-i[1])*(c[0]-i[0]),o=[];for(let i of t){for(;o.length>=2&&r(o[o.length-2],o[o.length-1],i)<=0;)o.pop();o.push(i)}let s=[];for(let i=t.length-1;i>=0;i--){let a=t[i];for(;s.length>=2&&r(s[s.length-2],s[s.length-1],a)<=0;)s.pop();s.push(a)}return o.pop(),s.pop(),o.concat(s)}function ss(e){let n=0,t=e.length;for(let r=0;r<t;r++){let o=e[r],s=e[(r+1)%t];n+=o[0]*s[1]-s[0]*o[1]}return n/2}function Ra(e){let n=e.map(t=>[t[0],t[1]]);return ss(n)<0&&n.reverse(),n}function La(e,n,t){let r=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/r,s=n[1]/r,i=n[2]/r,a=Math.sign(i||1)*Math.max(Math.abs(i),.01),c=e[2]-t;return[e[0]-o/a*c,e[1]-s/a*c]}function wa(e,n){if(e.length===0||n.length<3)return[];let t=e.map(o=>[o[0],o[1]]),r=n.length;for(let o=0;o<r;o++){if(t.length===0)return[];let s=t;t=[];let i=n[o],a=n[(o+1)%r],c=f=>(a[0]-i[0])*(f[1]-i[1])-(a[1]-i[1])*(f[0]-i[0])>=0,l=(f,d)=>{let m=i[0],g=i[1],h=a[0],p=a[1],x=f[0],b=f[1],P=d[0],y=d[1],M=(m-h)*(b-y)-(g-p)*(x-P);if(Math.abs(M)<1e-12)return[f[0],f[1]];let S=((m-x)*(b-y)-(g-b)*(x-P))/M;return[m+S*(h-m),g+S*(p-g)]},u=s.length;for(let f=0;f<u;f++){let d=s[f],m=s[(f+u-1)%u],g=c(d),h=c(m);g?(h||t.push(l(m,d)),t.push([d[0],d[1]])):h&&t.push(l(m,d))}}return t}var Em=Symbol.for("polycss.animation.triangleFrameSource"),Tm=Symbol.for("polycss.animation.triangleFrameTarget"),as=2200,Qt=2201,cs=2202;function Cm(e,n){let t=0,r=1,o=1,s=Qt,i=1/0,a=0,c=!1,l=null,u=!0,f=!1,d={clampWhenFinished:!1,get timeScale(){return o},set timeScale(m){o=m},get weight(){return r},set weight(m){r=m},get time(){return t},set time(m){t=m},get isRunning(){return c},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return c=!0,d},stop(){return c=!1,t=0,a=0,l=null,d},reset(){return t=0,a=0,d},fadeIn(m){return l={from:0,to:1,elapsed:0,duration:m},r=0,d},fadeOut(m){return l={from:r,to:0,elapsed:0,duration:m},d},crossFadeTo(m,g){return d.fadeOut(g),m.fadeIn(g),d},crossFadeFrom(m,g){return m.fadeOut(g),d.fadeIn(g),d},setLoop(m,g){return s=m,i=g,d},setEffectiveTimeScale(m){return o=m,d},setEffectiveWeight(m){return r=m,d}};return d._internal={get clip(){return e},get time(){return t},get weight(){return r},get enabled(){return u},get paused(){return f},get running(){return c},get loopMode(){return s},get repetitions(){return i},get completedReps(){return a},set completedReps(m){a=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return o},get fade(){return l},advance(m){if(!c)return;if(l){l.elapsed+=m;let h=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(r=l.from+(l.to-l.from)*h,h>=1&&(r=l.to,l=null,r<=0)){c=!1;return}}if(f)return;let g=e.duration;if(!(g<=0)){if(t+=m*o,s===as)t>=g&&(t=d.clampWhenFinished?g:0,c=!1);else if(s===Qt){if(t>=g){let h=t%g,p=Math.floor(t/g);a+=p,t=h,i!==1/0&&a>=i&&(t=d.clampWhenFinished?g:0,c=!1)}}else if(g>0){let h=g*2,p=t%h;if(t>=h){let x=Math.floor(t/h);a+=x,i!==1/0&&a>=i?(t=d.clampWhenFinished?g:0,c=!1):t=p}}}},sampleTime(){if(s===cs){let m=e.duration,g=m*2,h=t%g;return h<=m?h:g-h}return t}},d}function _m(e){return e._internal}function is(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function Na(e,n){let t=new Map,r=n,o=e;function s(f){let d=is(n.clips,f);if(!d)throw new Error(`PolyAnimationMixer: no clip found for key "${f}". Available: ${n.clips.map(g=>g.name).join(", ")}`);let m=t.get(d.index);return m||(m=Cm(d,n),t.set(d.index,m)),m}function i(f){let d=is(n.clips,f);return d?t.get(d.index)??null:null}function a(f){let d=[];for(let x of t.values()){let b=_m(x);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:x,clip:b}=d[0],P=x.sampleTime(),y=r[Em]?.(b.name,P);if(y&&o[Tm]?.(y))return;let M=n.sample(b.name,P);e.setPolygons(M);return}let m=0;for(let{internal:x}of d)m+=x.weight;if(m<=0)return;let g=d.map(({internal:x,clip:b})=>({polygons:n.sample(b.name,x.sampleTime()),weight:x.weight/m})),h=g[0].polygons;if(h.length===0)return;let p=h.map((x,b)=>{let P=x.vertices.map((y,M)=>{let S=0,T=0,E=0;for(let{polygons:A,weight:C}of g){let _=A[b];if(!_)continue;let w=_.vertices[M];w&&(S+=w[0]*C,T+=w[1]*C,E+=w[2]*C)}return[S,T,E]});return{...x,vertices:P}});e.setPolygons(p)}function c(){for(let f of t.values())f.stop()}function l(f){let d=is(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:s,existingAction:i,update:a,stopAllAction:c,uncacheClip:l,uncacheRoot:u}}var fs={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},$a={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},vm={0:"POINTS",1:"LINES",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN"};function za(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Im(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let t=e.slice(5,n),r=e.slice(n+1);if(!t.includes(";base64")){let i=decodeURIComponent(r),a=new Uint8Array(i.length);for(let c=0;c<i.length;c++)a[c]=i.charCodeAt(c)&255;return a}let o=globalThis.atob(r),s=new Uint8Array(o.length);for(let i=0;i<o.length;i++)s[i]=o.charCodeAt(i);return s}function Vm(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 r=12,o=null,s=null;for(;r<e.byteLength;){let i=n.getUint32(r,!0),a=n.getUint32(r+4,!0),c=r+8;if(a===1313821514){let l=new Uint8Array(e,c,i);o=JSON.parse(za(l))}else a===5130562&&(s=new Uint8Array(e,c,i));r=c+i}if(!o)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:o,bin:s}}function Da(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function Om(e){let n=Da(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=Da(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 Rm(e,n,t){let r=e.buffers??[],o=(e.extensionsRequired??[]).includes("EXT_meshopt_compression");return r.map((s,i)=>{let a=s.uri;if(a){if(a.startsWith("data:"))return Im(a);if(t){let c=t(a);if(c instanceof Uint8Array)return c;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(i===0&&n)return n;if(o&&s.extensions?.EXT_meshopt_compression)return new Uint8Array(0);throw new Error(`parseGltf: buffer[${i}] has no uri and no GLB BIN chunk`)})}function it(e,n,t){let r=e.bufferViews?.[t],o=r?n[r.buffer]:void 0;if(!r||!o)throw new Error(`parseGltf: bad bufferView ${t}`);let s=r.byteOffset??0;if(s<0||r.byteLength<0||s+r.byteLength>o.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${r.buffer}`);return{buffer:o,view:r}}function Xa(e,n,t,r){if(e.count<=0)return;let o=e.byteOffset??0,s=o+t*(e.count-1)+r;if(o<0||s>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function Wa(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function Lm(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 ls(e,n,t){let r=e.accessors?.[t];if(!r)throw new Error(`parseGltf: bad accessor ${t}`);let o=fs[r.componentType],s=$a[r.type];if(!o||!s)throw new Error(`parseGltf: unsupported accessor type ${r.type}/${r.componentType}`);if(r.sparse||r.normalized||r.bufferView===void 0){let{values:p}=at(e,n,t);return{array:Lm(r.componentType,p,r.normalized),count:r.count,componentCount:s}}let{buffer:i,view:a}=it(e,n,r.bufferView),c=(a.byteOffset??0)+(r.byteOffset??0),l=r.count*s,u=o*s,f=Wa(a,u);if(Xa(r,a,f,u),f===u){let p=i.buffer.slice(i.byteOffset+c,i.byteOffset+c+l*o),x;switch(r.componentType){case 5120:x=new Int8Array(p);break;case 5121:x=new Uint8Array(p);break;case 5122:x=new Int16Array(p);break;case 5123:x=new Uint16Array(p);break;case 5125:x=new Uint32Array(p);break;case 5126:x=new Float32Array(p);break;default:throw new Error(`parseGltf: unhandled componentType ${r.componentType}`)}return{array:x,count:r.count,componentCount:s}}let d;switch(r.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 ${r.componentType}`)}let m=new DataView(i.buffer),g=i.byteOffset+c,h=0;for(let p=0;p<r.count;p++){let x=g+p*f;for(let b=0;b<s;b++)d[h++]=er(m,x+b*o,r.componentType)}return{array:d,count:r.count,componentCount:s}}function er(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 Fa(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 at(e,n,t){let r=e.accessors?.[t];if(!r)throw new Error(`parseGltf: bad accessor ${t}`);let o=fs[r.componentType],s=$a[r.type];if(!o||!s)throw new Error(`parseGltf: unsupported accessor type ${r.type}/${r.componentType}`);let i=o*s,a=new Array(r.count*s).fill(0);if(r.bufferView!==void 0){let{buffer:c,view:l}=it(e,n,r.bufferView),u=c.byteOffset+(l.byteOffset??0)+(r.byteOffset??0),f=Wa(l,i);Xa(r,l,f,i);let d=new DataView(c.buffer),m=0;for(let g=0;g<r.count;g++){let h=u+g*f;for(let p=0;p<s;p++){let x=er(d,h+p*o,r.componentType);a[m++]=r.normalized?Fa(x,r.componentType):x}}}if(r.sparse){let c=r.sparse,l=c.indices,u=fs[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}=it(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),g=new DataView(f.buffer),{buffer:h,view:p}=it(e,n,c.values.bufferView),x=h.byteOffset+(p.byteOffset??0)+(c.values.byteOffset??0),b=new DataView(h.buffer);for(let P=0;P<c.count;P++){let y=er(g,m+P*u,l.componentType);for(let M=0;M<s;M++){let S=er(b,x+(P*s+M)*o,r.componentType);a[y*s+M]=r.normalized?Fa(S,r.componentType):S}}}return{values:a,count:r.count,componentCount:s}}function wm(e,n,t){let r=[],o=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(t&&!i.uri.startsWith("data:"))try{r.push(new s.URL(i.uri,t).href)}catch{r.push(i.uri)}else r.push(i.uri);continue}if(i.bufferView!==void 0){let a;try{let{buffer:f,view:d}=it(e,n,i.bufferView),m=d.byteOffset??0;a=f.subarray(m,m+d.byteLength)}catch{r.push("");continue}let c=i.mimeType??"image/png",l=new s.Blob([a],{type:c}),u=s.URL.createObjectURL(l);r.push(u),o.push(u)}else r.push("")}return{urls:r,objectUrls:o}}function Ba(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function Nm(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:Ba(t?.wrapS),t:Ba(t?.wrapT)}}function ja(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function Dm(e,n){let t=new Map,r=e.materials??[];for(let o=0;o<r.length;o++){let s=r[o].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s],a=i?.source;if(a===void 0)continue;let c=n[a];c&&t.set(o,{url:c,wrap:Nm(e,i),alphaMode:ja(r[o].alphaMode),texCoord:r[o].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function Fm(e,n,t){let r=e?.pbrMetallicRoughness?.baseColorFactor;if(!r||r.length<3)return n;let o=c=>Math.max(0,Math.min(1,c)),s=c=>Math.round(o(c)*255).toString(16).padStart(2,"0"),i=c=>Math.round(o(c)*255),a=t==="opaque"?1:o(r[3]??1);return a<1?`rgba(${i(r[0])}, ${i(r[1])}, ${i(r[2])}, ${Math.round(a*1e3)/1e3})`:`#${s(r[0])}${s(r[1])}${s(r[2])}`}var Tn=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Ya(e,n){let t=new Array(16);return Ha(t,e,n)}function Ha(e,n,t){for(let r=0;r<4;r++)for(let o=0;o<4;o++)e[o*4+r]=n[0+r]*t[o*4+0]+n[4+r]*t[o*4+1]+n[8+r]*t[o*4+2]+n[12+r]*t[o*4+3];return e}function Bm(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 Ka(e,n,t){let r=e?.[0]??0,o=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,a=n?.[1]??0,c=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=i+i,g=a+a,h=c+c,p=i*m,x=i*g,b=i*h,P=a*g,y=a*h,M=c*h,S=l*m,T=l*g,E=l*h;return[(1-(P+M))*u,(x+E)*u,(b-T)*u,0,(x-E)*f,(1-(p+M))*f,(y+S)*f,0,(b+T)*d,(y-S)*d,(1-(p+P))*d,0,r,o,s,1]}function km(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Ka(e.translation,e.rotation,e.scale)}function qa(e,n,t){let r=new Array(Math.min(e.length,n.length));for(let o=0;o<r.length;o++)r[o]=e[o]+(n[o]-e[o])*t;return r}function st(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 Um(e,n,t){let r=st(e),o=st(n),s=r[0]*o[0]+r[1]*o[1]+r[2]*o[2]+r[3]*o[3];if(s<0&&(s=-s,o=[-o[0],-o[1],-o[2],-o[3]]),s>.9995)return st(qa(r,o,t));let i=Math.acos(Math.max(-1,Math.min(1,s))),a=Math.sin(i),c=Math.sin((1-t)*i)/a,l=Math.sin(t*i)/a;return st([r[0]*c+o[0]*l,r[1]*c+o[1]*l,r[2]*c+o[2]*l,r[3]*c+o[3]*l])}function Gm(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 ka(e){return e.matrix?e.matrix.slice():Ka(e.translation,e.rotation,e.scale)}function $m(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function Ua(e,n){let t=e.nodes??[],r=new Array(t.length),o=new Set,s=(a,c)=>{if(a<0||a>=t.length)return;let l=Ya(c,n[a]??Tn);r[a]=l,o.add(a);for(let u of t[a].children??[])s(u,l)},i=$m(e);if(i.length>0)for(let a of i)s(a,Tn);for(let a=0;a<t.length;a++)o.has(a)||s(a,Tn);return r}var Za=Symbol("polycss.gltfAnimationRuntimeInfo"),zm=Symbol.for("polycss.animation.triangleFrameSource");function Qa(e,n){return e?e[Za]?.withPolygonFilter(n):void 0}function us(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Xm(e,n,t){return us(e,n)||us(e,t)||us(n,t)}function Ga(e,n,t,r,o){if(t===void 0)return;let{values:s,count:i,componentCount:a}=at(e,n,t);if(i!==o||a<1)return;let c=[];for(let l=0;l<i;l++){let u=[];for(let f=0;f<r;f++)u.push(s[l*a+f]??0);c.push(u)}return c}function Wm(e,n,t,r){if(t===void 0)return Array.from({length:r},()=>Tn.slice());let{values:o,componentCount:s,count:i}=at(e,n,t);if(s!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${t} is not MAT4`);let a=[];for(let c=0;c<r;c++){let l=Math.min(c,i-1);a.push(o.slice(l*16,l*16+16))}return a}function Jt(e,n){let t=e.componentCount,r=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(r,r+t)}function jm(e,n,t){let r=e.input;if(r.length===0)return[];if(r.length===1||n<=r[0])return Jt(e,0);let o=r.length-1;if(n>=r[o])return Jt(e,o);let s=0,i=o;for(;s+1<i;){let d=s+i>>1;r[d]<=n?s=d:i=d}let a=r[s],c=r[s+1],l=c>a?(n-a)/(c-a):0,u=Jt(e,s),f=Jt(e,s+1);return e.interpolation==="STEP"?u:t==="rotation"?Um(u,f,l):qa(u,f,l)}function Ym(e,n,t,r,o,s){let i=e.animations??[];if(i.length===0||t.length===0)return;let a=(e.nodes??[]).map(p=>Gm(p)),c=a.map(ka),l=Ua(e,c),u=(e.skins??[]).map(p=>({joints:p.joints??[],inverseBindMatrices:Wm(e,n,p.inverseBindMatrices,p.joints?.length??0)})),f=[];for(let p=0;p<i.length;p++){let x=i[p],b=(x.samplers??[]).map(M=>{let S=at(e,n,M.input),T=at(e,n,M.output);return{input:S.values,output:T.values,componentCount:T.componentCount,interpolation:M.interpolation??"LINEAR"}}),P=[];for(let M of x.channels??[]){let S=M.target.node,T=M.target.path,E=b[M.sampler];S===void 0||!T||!E||T==="weights"||P.push({sampler:E,targetNode:S,path:T})}let y=P.reduce((M,S)=>{let T=S.sampler.input;return Math.max(M,T[T.length-1]??0)},0);f.push({info:{index:p,name:x.name??`animation_${p}`,duration:y,channelCount:P.length},channels:P})}let d=f.map(p=>p.info);if(d.length===0)return;let m=p=>{let x=t.map(b=>new Array(b.triangleMask.length).fill(!1));for(let b of p){let P=r[b];if(!P)return;let y=x[P.sourceIndex];if(!y||P.triangleIndex<0||P.triangleIndex>=y.length)return;y[P.triangleIndex]=!0}return x.map((b,P)=>{let y=t[P],M=new Set,S=0;for(let T=0;T+2<y.indices.length;T+=3,S++)b[S]&&(M.add(y.indices[T]),M.add(y.indices[T+1]),M.add(y.indices[T+2]));return{triangleMask:b,activeVertices:Array.from(M).sort((T,E)=>T-E)}})},g=(p,x,b,P,y,M,S,T,E)=>{let A=o(p),C=o(x),_=o(b),w={vertices:[A,C,_],color:P};return y&&(w.texture=y),y&&M&&(w.textureWrap=M),y&&S&&(w.textureAlphaMode=S),T&&(w.doubleSided=!0),E&&(w.uvs=E),w},h=p=>{let x=t.reduce((V,N,F)=>{let k=p?.[F]?.triangleMask??N.triangleMask,$=0;for(let R=0;R<k.length;R++)k[R]&&$++;return V+$},0),b=new Float64Array(Math.max(0,x*9)),P=new Array(x),y=new Array(x).fill(!1),M={polygonCount:0,vertices:b,colors:P,textureFlags:y,solidTriangles:!0},S=t.map(V=>new Array(V.positions.length)),T=u.map(V=>V.joints.map(()=>new Array(16))),E=(V,N)=>{let F=typeof V=="number"?f[V]:f.find(B=>B.info.name===V);if(!F)return null;let k=F.info.duration,$=k>0?(N%k+k)%k:Math.max(0,N),R=a.map(B=>({translation:B.translation.slice(),rotation:B.rotation.slice(),scale:B.scale.slice(),matrix:B.matrix?B.matrix.slice():void 0}));for(let B of F.channels){let z=R[B.targetNode];if(!z)continue;let ee=jm(B.sampler,$,B.path);z.matrix=void 0,B.path==="translation"?z.translation=ee.slice(0,3):B.path==="rotation"?z.rotation=st(ee.slice(0,4)):B.path==="scale"&&(z.scale=ee.slice(0,3))}return Ua(e,R.map(ka))},A=(V,N,F,k)=>{let $=F?.activeVertices,R=S[V],B=(z,ee,Q,Z)=>{let ne=R[z];ne?(ne[0]=ee,ne[1]=Q,ne[2]=Z):R[z]=[ee,Q,Z]};if(N.skinIndex!==void 0&&N.joints&&N.weights&&u[N.skinIndex]){let z=u[N.skinIndex],ee=N.joints,Q=N.weights,Z=T[N.skinIndex]??[];for(let j=0;j<z.joints.length;j++){let D=z.joints[j],I=k[D],U=z.inverseBindMatrices[j],G=Z[j]??(Z[j]=new Array(16));Z[j]=I&&U?Ha(G,I,U):void 0}let ne=j=>{let D=N.positions[j],I=0,U=0,G=0,q=0,v=ee[j]??[],O=Q[j]??[];for(let L=0;L<4;L++){let X=O[L]??0;if(X<=0)continue;let H=Math.round(v[L]??0),Y=Z[H];if(!Y)continue;let K=Y[0]*D[0]+Y[4]*D[1]+Y[8]*D[2]+Y[12],te=Y[1]*D[0]+Y[5]*D[1]+Y[9]*D[2]+Y[13],se=Y[2]*D[0]+Y[6]*D[1]+Y[10]*D[2]+Y[14];I+=K*X,U+=te*X,G+=se*X,q+=X}if(q>0){let L=1/q;B(j,I*L,U*L,G*L)}else B(j,N.meshBindWorld[0]*D[0]+N.meshBindWorld[4]*D[1]+N.meshBindWorld[8]*D[2]+N.meshBindWorld[12],N.meshBindWorld[1]*D[0]+N.meshBindWorld[5]*D[1]+N.meshBindWorld[9]*D[2]+N.meshBindWorld[13],N.meshBindWorld[2]*D[0]+N.meshBindWorld[6]*D[1]+N.meshBindWorld[10]*D[2]+N.meshBindWorld[14])};if($)for(let j of $)ne(j);else for(let j=0;j<N.positions.length;j++)ne(j)}else{let z=N.meshNode!==null?k[N.meshNode]??N.meshBindWorld:N.meshBindWorld,ee=Q=>{let Z=N.positions[Q];B(Q,z[0]*Z[0]+z[4]*Z[1]+z[8]*Z[2]+z[12],z[1]*Z[0]+z[5]*Z[1]+z[9]*Z[2]+z[13],z[2]*Z[0]+z[6]*Z[1]+z[10]*Z[2]+z[14])};if($)for(let Q of $)ee(Q);else for(let Q=0;Q<N.positions.length;Q++)ee(Q)}return R},C=(V,N)=>{let F=E(V,N);if(!F)return[];let k=[];for(let $=0;$<t.length;$++){let R=t[$],B=p?.[$],z=B?.triangleMask??R.triangleMask,ee=A($,R,B,F),Q=0;for(let Z=0;Z+2<R.indices.length;Z+=3,Q++){if(!z[Q])continue;let ne=R.indices[Z],j=R.indices[Z+1],D=R.indices[Z+2],I=ee[ne],U=ee[j],G=ee[D];if(!I||!U||!G)continue;let q;if(R.uvs&&R.texture){let O=R.uvs[ne],L=R.uvs[j],X=R.uvs[D];O&&L&&X&&(q=[O,L,X])}let v=g(I,U,G,R.color,R.texture,R.textureWrap,R.textureAlphaMode,R.doubleSided,q);v&&k.push(v)}}return k},_=(V,N)=>{let F=E(V,N);if(!F)return null;b.length<x*9&&(b=new Float64Array(x*9),M.vertices=b),P.length<x&&(P=new Array(x),M.colors=P),y.length<x&&(y=new Array(x).fill(!1),M.textureFlags=y);let k=0,$=0,R=!1;for(let B=0;B<t.length;B++){let z=t[B],ee=p?.[B],Q=ee?.triangleMask??z.triangleMask,Z=A(B,z,ee,F),ne=0;for(let j=0;j+2<z.indices.length;j+=3,ne++){if(!Q[ne])continue;let D=z.indices[j],I=z.indices[j+1],U=z.indices[j+2],G=Z[D],q=Z[I],v=Z[U];if(!G||!q||!v)continue;s(G,b,$),s(q,b,$+3),s(v,b,$+6),P[k]=z.color;let O=!!z.texture;y[k]=O,O&&(R=!0),k++,$+=9}}return M.polygonCount=k,M.solidTriangles=!R,M},w={clips:d,sample:C};return w[zm]=_,w[Za]={withPolygonFilter(V){let N=m(V);return N?h(N):void 0}},w};return h()}function nr(e,n){let t=n?.targetSize??60,r=n?.gridShift??1,o=n?.defaultColor??"#888888",s=n?.materialColors??{},i=n?.materialTextures??{},a=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,c=a.byteLength,l,u=null;if(a.byteLength>=4&&new DataView(a).getUint32(0,!0)===1179937895){let v=Vm(a);l=v.doc,u=v.bin}else l=JSON.parse(za(new Uint8Array(a)));Om(l);let f=Rm(l,u,n?.resolveBuffer),{urls:d,objectUrls:m}=wm(l,f,n?.baseUrl),g=Dm(l,d),h=[],p=new Set,x=new Set(l.extensionsRequired??[]);function b(v,O){p.has(v)||(p.add(v),h.push(O))}function P(v,O){if(v===void 0)return!1;let L=l.accessors?.[v];if(!L)return!1;let X=H=>l.bufferViews?.[H]?.extensions?.[O]!==void 0;return!!(L.bufferView!==void 0&&X(L.bufferView)||L.sparse&&(X(L.sparse.indices.bufferView)||X(L.sparse.values.bufferView)))}function y(v){return x.has("EXT_meshopt_compression")?v.extensions?.EXT_meshopt_compression||P(v.indices,"EXT_meshopt_compression")?!0:Object.values(v.attributes??{}).some(O=>P(O,"EXT_meshopt_compression")):!1}let M=[],S=[],T=[],E=(l.meshes??[]).map((v,O)=>v.name??`mesh_${O}`),A=(l.materials??[]).map((v,O)=>v.name??`material_${O}`);function C(v,O){if(O===4)return v;let L=[];if(O===5)for(let X=0;X+2<v.length;X++)L.push(v[X],v[X+1+X%2],v[X+2-X%2]);else if(O===6)for(let X=0;X+2<v.length;X++)L.push(v[X+1],v[X+2],v[0]);return L}function _(v){let O=[];for(let L=0;L+2<v.length;L+=3){let X=v[L],H=v[L+1],Y=v[L+2];O.push(X,H,Y,X,Y,H)}return O}function w(v,O,L){let X=l.meshes?.[v];if(X)for(let H of X.primitives){let Y=H.mode??4;if(Y!==4&&Y!==5&&Y!==6){let W=vm[Y]??`mode ${Y}`;b(`unsupported-mode:${Y}`,`Skipped primitives with unsupported mode ${Y} (${W})`);continue}if(H.extensions?.KHR_draco_mesh_compression&&x.has("KHR_draco_mesh_compression")){b("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}if(y(H)){b("EXT_meshopt_compression","Skipped primitives with unsupported required extension EXT_meshopt_compression");continue}if(H.attributes.POSITION===void 0){b(`missing-position:${v}`,`Mesh ${X.name??v}: skipped primitive without POSITION attribute`);continue}let K=H.material!==void 0?l.materials?.[H.material]:void 0,te=ja(K?.alphaMode),se=K?.name,Te=(se?s[se]:void 0)??Fm(K,o,te),le=K?.doubleSided===!0,me=H.material!==void 0?g.get(H.material):void 0,pe=se&&i[se]?i[se]:H.material!==void 0?me?.url:void 0,ve=pe&&H.material!==void 0?me?.wrap:void 0,ye=pe?me?.alphaMode??te:void 0,Ce=pe?me?.texCoord??0:0,{array:xe,count:Pe}=ls(l,f,H.attributes.POSITION);if(!(xe instanceof Float32Array))continue;let Ae=[],ce=[];for(let W=0;W<Pe;W++){let J=[xe[W*3],xe[W*3+1],xe[W*3+2]];Ae.push(J),ce.push(Bm(O,J))}let fe=null,Me=H.attributes[`TEXCOORD_${Ce}`];if(pe&&Me!==void 0){let{array:W,count:J}=ls(l,f,Me);fe=[];let oe=1;W instanceof Uint8Array?oe=1/255:W instanceof Uint16Array&&(oe=1/65535);for(let be=0;be<J;be++){let _e=W[be*2]*oe,We=W[be*2+1]*oe;fe.push([_e,1-We])}}let ae;if(H.indices!==void 0){let{array:W,count:J}=ls(l,f,H.indices);ae=[];for(let oe=0;oe<J;oe++)ae.push(Number(W[oe]))}else ae=ce.map((W,J)=>J);ae=C(ae,Y),le&&(ae=_(ae));let de;if((l.animations?.length??0)>0){let W=Ga(l,f,H.attributes.JOINTS_0,4,Pe),J=Ga(l,f,H.attributes.WEIGHTS_0,4,Pe);de={sourceIndex:S.length,meshNode:L,meshBindWorld:O,skinIndex:L!==null?l.nodes?.[L]?.skin:void 0,positions:Ae,indices:ae,triangleMask:[],color:Te,texture:pe,textureWrap:ve,textureAlphaMode:ye,doubleSided:le,uvs:fe??void 0,joints:W,weights:J},S.push(de)}for(let W=0;W+2<ae.length;W+=3){let J=de?de.triangleMask.length:void 0;de&&de.triangleMask.push(!1);let oe=ce[ae[W]],be=ce[ae[W+1]],_e=ce[ae[W+2]];if(!oe||!be||!_e)continue;let We;if(fe&&pe){let xn=fe[ae[W]],bn=fe[ae[W+1]],yn=fe[ae[W+2]];xn&&bn&&yn&&(We=[xn,bn,yn])}M.push({v0:oe,v1:be,v2:_e,color:Te,texture:pe,textureWrap:ve,textureAlphaMode:ye,doubleSided:le,uvs:We,source:de,sourceIndex:de?.sourceIndex,sourceTriangleIndex:J})}}}function V(v,O){let L=l.nodes?.[v];if(!L)return;let X=Ya(O,km(L));typeof L.mesh=="number"&&w(L.mesh,X,v);for(let H of L.children??[])V(H,X)}let N=l.scene??0,F=l.scenes?.[N]?.nodes;if(F&&F.length>0)for(let v of F)V(v,Tn);else for(let v=0;v<(l.meshes?.length??0);v++)w(v,Tn,null);let k=Hm(m);if(M.length===0)return{polygons:[],objectUrls:m,dispose:k,warnings:h,metadata:{triangleCount:0,meshes:E,materials:A,sourceBytes:c}};let $=1/0,R=1/0,B=1/0,z=-1/0,ee=-1/0,Q=-1/0;for(let v of M)for(let O of[v.v0,v.v1,v.v2])O[0]<$&&($=O[0]),O[0]>z&&(z=O[0]),O[1]<R&&(R=O[1]),O[1]>ee&&(ee=O[1]),O[2]<B&&(B=O[2]),O[2]>Q&&(Q=O[2]);let Z=Math.max(z-$,ee-R,Q-B),ne=Z>0?t/Z:1,j=v=>Math.round(v*1e3)/1e3,D=n?.upAxis??"y",I=D==="z"?([v,O,L])=>[j((v-$)*ne+r),j((O-R)*ne+r),j((L-B)*ne+r)]:([v,O,L])=>[j((L-B)*ne+r),j((v-$)*ne+r),j((O-R)*ne+r)],U=D==="z"?(v,O,L)=>{O[L]=j((v[0]-$)*ne+r),O[L+1]=j((v[1]-R)*ne+r),O[L+2]=j((v[2]-B)*ne+r)}:(v,O,L)=>{O[L]=j((v[2]-B)*ne+r),O[L+1]=j((v[0]-$)*ne+r),O[L+2]=j((v[1]-R)*ne+r)},G=[];for(let v of M){let O=I(v.v0),L=I(v.v1),X=I(v.v2),H=Xm(O,L,X);if(v.source&&v.sourceTriangleIndex!==void 0&&(v.source.triangleMask[v.sourceTriangleIndex]=!H),H)continue;let Y={vertices:[O,L,X],color:v.color};v.texture&&(Y.texture=v.texture),v.texture&&v.textureWrap&&(Y.textureWrap=v.textureWrap),v.texture&&v.textureAlphaMode&&(Y.textureAlphaMode=v.textureAlphaMode),v.doubleSided&&(Y.doubleSided=!0),v.uvs&&(Y.uvs=v.uvs),G.push(Y),T.push(v.sourceIndex!==void 0&&v.sourceTriangleIndex!==void 0?{sourceIndex:v.sourceIndex,triangleIndex:v.sourceTriangleIndex}:void 0)}let q=Ym(l,f,S,T,I,U);return{polygons:G,animation:q,objectUrls:m,dispose:k,warnings:h,metadata:{triangleCount:G.length,meshes:E,materials:A,animations:q?.clips,sourceBytes:c}}}function Hm(e){let n=!1;return()=>{if(n)return;n=!0;let t=globalThis.URL;if(t?.revokeObjectURL)for(let r of e)try{t.revokeObjectURL(r)}catch{}}}var ic=Symbol("polycss.solidTextureBakedAnimationInfo"),Ja=Symbol.for("polycss.animation.triangleFrameSource"),Km=16*1024*1024,qm=2,Zm=32,Qm=2,Jm=.08,ed=8,nd=128,ec=32,td=.045,rd=10,Cn=6,od=16;function ms(e){return e.material?.texture??e.texture}function sd(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function id(e,n){return new Promise((t,r)=>{let o=new n,s=!1,i=a=>{s||(s=!0,a())};o.decoding="async",o.onload=()=>i(()=>t(o)),o.onerror=()=>i(()=>r(new Error(`texture load failed: ${e}`))),o.src=e})}async function ad(e,n,t){try{let r=await id(e,n.Image),o=Math.max(0,Math.floor(r.naturalWidth||r.width||0)),s=Math.max(0,Math.floor(r.naturalHeight||r.height||0));if(o<=0||s<=0||o*s>t)return null;let i=n.createCanvas();i.width=o,i.height=s;let a=i.getContext("2d",{willReadFrequently:!0});if(!a)return null;a.drawImage(r,0,0,o,s);let c=a.getImageData(0,0,o,s).data;return{width:o,height:s,data:c,lowDetail:cd(o,s,c)}}catch{return null}}function nc(e,n,t,r,o,s){let i=(r*n+t)*4,a=(s*n+o)*4;return Math.max(Math.abs((e[i]??0)-(e[a]??0)),Math.abs((e[i+1]??0)-(e[a+1]??0)),Math.abs((e[i+2]??0)-(e[a+2]??0)))}function cd(e,n,t){let r=Math.max(1,Math.floor(Math.max(e,n)/nd)),o=0,s=0,i=0;for(let a=0;a<n;a+=r)for(let c=0;c<e;c+=r){if(c+r<e){let l=nc(t,e,c,a,c+r,a);i+=l,o++,l>ec&&s++}if(a+r<n){let l=nc(t,e,c,a,c,a+r);i+=l,o++,l>ec&&s++}}return o>0&&s/o<=td&&i/o<=rd}function tc(e,n,t){return Math.max(n,Math.min(t,e))}function rc(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),r=e-t;return Math.abs(t%2)===1?1-r:r}default:return Math.max(0,Math.min(1,e))}}function ld(e,n,t){let r=n[0],o=1-n[1],s=rc(r,t?.s),i=rc(o,t?.t);if(s===null||i===null)return null;let a=tc(Math.floor(s*e.width),0,e.width-1),l=(tc(Math.floor(i*e.height),0,e.height-1)*e.width+a)*4;return{r:e.data[l]??0,g:e.data[l+1]??0,b:e.data[l+2]??0,a:e.data[l+3]??255}}function Ke(e,n,t,r,o,s){return[e[0]*r+n[0]*o+t[0]*s,e[1]*r+n[1]*o+t[1]*s]}function ud(e){let[n,t,r]=e;return[Ke(n,t,r,1/3,1/3,1/3),Ke(n,t,r,.8,.1,.1),Ke(n,t,r,.1,.8,.1),Ke(n,t,r,.1,.1,.8),Ke(n,t,r,.45,.45,.1),Ke(n,t,r,.45,.1,.45),Ke(n,t,r,.1,.45,.45)]}function fd(e){let[n,t,r]=e,o=ud(e);for(let s=1;s<Cn;s++)for(let i=1;i<Cn-s;i++){let a=Cn-s-i;a<=0||o.push(Ke(n,t,r,s/Cn,i/Cn,a/Cn))}return o}function ac(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 r=1;r+1<n.length;r++)t.push({uvs:[n[0],n[r],n[r+1]]});return t}function ds(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 tr(e){let n=r=>Math.round(Math.max(0,Math.min(255,r))).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 cc(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=a=>{let c=s.length<=4?s[a]+s[a]:s.slice(a*2,a*2+2);return parseInt(c,16)};return{r:i(0),g:i(1),b:i(2),a:s.length===4||s.length===8?i(3):255}}let r=n.match(/^rgba?\(\s*([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)(?:\s*,\s*([0-9.]+)\s*)?\)$/);if(!r)return null;let o=r[4]===void 0?255:Number(r[4])<=1?Number(r[4])*255:Number(r[4]);return{r:Number(r[1]),g:Number(r[2]),b:Number(r[3]),a:o}}function md(){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 lc(e){return`${e.r},${e.g},${e.b},${e.a}`}function oc(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=lc(n),r=e.colors.get(t);e.colors.set(t,{color:n,count:(r?.count??0)+1}),e.count++}function sc(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 dd(e){if(e.count<ed||e.colors.size<=1||e.colors.size>Qm)return null;let n=null;for(let o of e.colors.values())(!n||o.count>n.count)&&(n=o);if(!n)return null;let t=e.count-n.count,r=Math.max(1,Math.floor(e.count*Jm));return t<=r?n.color:null}function gd(e,n,t,r){let o=ac(e);if(o.length===0)return null;let s=md(),i=e.textureAlphaMode==="opaque"?cc(e.color):null;for(let a of o)for(let c of fd(a.uvs)){let l=ld(n,c,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){i&&oc(s,{...i,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),oc(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(ds(s.min,s.max,t))return tr(sc(s));if(!r){let a=dd(s);if(a)return tr(a)}return r||!n.lowDetail||!ds(s.min,s.max,Zm)?null:tr(sc(s))}function uc(e,n){let{texture:t,textureWrap:r,textureAlphaMode:o,material:s,uvs:i,textureTriangles:a,...c}=e;return{...c,color:n}}function pd(e,n){if(n.length<2)return e;let t=[],r=new Map;for(let l of n){let u=cc(e[l]?.color);if(!u||u.a<255)continue;let f=lc(u);t.push({index:l,key:f});let d=r.get(f);d?d.count+=1:r.set(f,{color:u,count:1})}if(r.size<2)return e;let o=[],s=new Map,i=[...r.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 o)if(ds(u.color,d,od)){f=d;break}f||(f=u.color,o.push(f)),s.set(l,tr(f))}let a=!1,c=e.slice();for(let l of t){let u=s.get(l.key),f=e[l.index];!u||!f||f.color===u||(c[l.index]={...f,color:u},a=!0)}return a?c:e}function hd(e,n){let t=e.slice();for(let r=0;r<n.length;r++){let o=n[r],s=e[o.index];s&&(t[o.index]=uc(s,o.color))}return t}function fc(e){return e?e[ic]:void 0}async function mc(e,n={}){if(n.enabled===!1)return null;let t=sd();if(!t)return null;let r=e.filter(c=>ms(c)&&ac(c).length>0);if(r.length===0)return null;let o=n.maxTexturePixels??Km,s=new Map;await Promise.all(Array.from(new Set(r.map(c=>ms(c)))).map(async c=>{s.set(c,await ad(c,t,o))}));let i=n.colorTolerance??qm,a=n.colorTolerance!==void 0;return{bake(c){let l=!1,u=[],f=c.map((d,m)=>{let g=ms(d);if(!g)return d;let h=s.get(g);if(!h)return d;let p=gd(d,h,i,a);return p?(l=!0,u.push(m),uc(d,p)):d});return l?{polygons:pd(f,u),changed:!0,bakedIndices:u}:{polygons:c,changed:!1,bakedIndices:u}}}}async function dc(e,n={}){let t=await mc(e,n);return t?t.bake(e).polygons:e}async function rr(e,n={}){let t=await mc(e.polygons,n);if(!t)return e;let r=t.bake(e.polygons);if(!r.changed)return e;let o=[];for(let a of r.bakedIndices){let l=r.polygons[a].color;l&&o.push({index:a,color:l})}let s=e.animation,i=s&&{...s,sample(a,c){return hd(s.sample(a,c),o)}};if(i&&s){let a=s[Ja];if(a){let c=new Map(o.map(f=>[f.index,f.color])),l=[],u={polygonCount:0,vertices:new Float64Array(0),colors:l,solidTriangles:!1};i[Ja]=(f,d)=>{let m=a(f,d);if(!m)return m;l.length<m.polygonCount&&(l=new Array(m.polygonCount),u.colors=l);let g=m.textureFlags,h=m.solidTriangles===!0||!!g;for(let p=0;p<m.polygonCount;p++){let x=c.get(p);l[p]=x??m.colors?.[p],g?.[p]&&!x&&(h=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=g,u.solidTriangles=h,u}}i[ic]={source:s,bakedColorEntries:o}}return{...e,polygons:r.polygons,animation:i}}var gc=Symbol.for("polycss.animation.triangleFrameSource");function xd(e,n){let t=e[n];if(!t)return null;let r=[];for(let o=0;o<t.vertices.length;o++)r.push(n,o);return{rest:t,originalIndex:n,sourceRefs:r}}function bd(e){let n=Be(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((o,s)=>t.set(o,s));let r=[];for(let o of n){let s=t.get(o);if(s===void 0)return[];let i=xd(e,s);if(!i)return[];r.push(i)}return r}function gs(e,n,t=!1){let r=new Array(n.length);for(let o=0;o<n.length;o++){let s=n[o],i=s.sourceRefs,a=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],g=d[1],h=d[2];if(!Number.isFinite(m)||!Number.isFinite(g)||!Number.isFinite(h))return e;a[u]=[m,g,h]}let c=t?s.rest.color:e[i[0]??-1]?.color??s.rest.color;r[o]={...s.rest,vertices:a,color:c}}return r}function yd(e,n){let t=new Map;return n.forEach((r,o)=>{t.set(r,o)}),e.map((r,o)=>({...r,sourceRefs:r.sourceRefs.map((s,i)=>i%2===0?t.get(s)??-1:s)}))}function Pd(e,n){if(e.length<n.length)return null;let t=new Array(n.length);for(let r=0;r<n.length;r++){let o=e[r],s=n[r];if(!o||o.vertices.length!==s.rest.vertices.length)return null;t[r]={...s.rest,vertices:o.vertices,color:s.rest.color}}return t}function Ad(e){return!!(e.texture||e.material?.texture)}function pc(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=bd(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let r=fc(e.animation),o=r?.source??e.animation,s=t.map(b=>b.originalIndex),i=Qa(o,s),a=i??o,c=i?yd(t,s):t,l=t.map(b=>b.rest.color),u=t.every(b=>b.rest.vertices.length===3&&!Ad(b.rest)),f=i&&!r&&t.length===s.length&&t.every((b,P)=>b.rest.vertices.length===3&&b.sourceRefs.length===6&&b.sourceRefs[0]===s[P]&&b.sourceRefs[2]===s[P]&&b.sourceRefs[4]===s[P]),d=a[gc],m=new Float64Array(t.length*9),g=l.slice(),h=new Array(t.length).fill(!1),p={polygonCount:t.length,vertices:m,colors:g,textureFlags:h,solidTriangles:u},x={...e.animation,sample(b,P){let y=a.sample(b,P);return f?y:i&&r?u&&t.length===s.length?Pd(y,t)??gs(y,c,!0):gs(y,c,!0):gs(y,c,!!r)}};return d&&u&&(x[gc]=(b,P)=>{let y=d(b,P);if(!y)return y;if(i)return y.polygonCount<t.length||y.vertices.length<t.length*9?null:(p.polygonCount=t.length,p.vertices=y.vertices,p.colors=r?l:y.colors,p.textureFlags=r?h:y.textureFlags,p.solidTriangles=r?u:y.solidTriangles===!0,p);m.length<t.length*9&&(m=new Float64Array(t.length*9),p.vertices=m),g.length<t.length&&(g=new Array(t.length),p.colors=g),h.length<t.length&&(h=new Array(t.length).fill(!1),p.textureFlags=h);let M=u&&y.solidTriangles!==!1;for(let S=0;S<c.length;S++){let T=c[S],E=T.sourceRefs;for(let _=0,w=0;_<E.length;_+=2,w++){let V=E[_],N=E[_+1];if(V<0||V>=y.polygonCount)return null;let F=V*9+N*3,k=S*9+w*3;if(F+2>=y.vertices.length)return null;m[k]=y.vertices[F],m[k+1]=y.vertices[F+1],m[k+2]=y.vertices[F+2]}let A=E[0],C=!!y.textureFlags?.[A];h[S]=C,g[S]=r?T.rest.color:y.colors?.[A]??T.rest.color,!r&&C&&(M=!1)}return p.polygonCount=t.length,p.vertices=m,p.colors=g,p.textureFlags=h,p.solidTriangles=r?u:M,p}),{...e,polygons:t.map(b=>b.rest),animation:x,metadata:{...e.metadata,triangleCount:t.length}}}var Md=/^[0-9A-Fa-f]{6}$/,Sd=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function or(e,n){let t=n?.targetSize??60,r=n?.gridShift??1,o=n?.defaultColor??"#888888",s=n?.palette??Sd,i=n?.materialColors??{},a=n?.materialTextures??{},c=[],l=[],u=[],f=[],d=new Map,m=o,g,h=n?.includeObjects?new Set(n.includeObjects):null,p=n?.excludeObjects?new Set(n.excludeObjects):null,x=null,b=()=>x===null?h===null:!(h&&!h.has(x)||p&&p.has(x)),P=R=>R in i?i[R]:Md.test(R)?`#${R}`:(d.has(R)||(d.set(R,s[f.length%s.length]),f.push(R)),d.get(R)),y=(R,B)=>{let z=parseInt(R,10);return Number.isFinite(z)?z<0?B+z:z-1:NaN},M=e.split(`
|
|
2
|
+
`);for(let R of M)if(!(R.length===0||R.charCodeAt(0)===35)){if(R.startsWith("v ")){let B=R.trim().split(/\s+/);c.push([parseFloat(B[1]),parseFloat(B[2]),parseFloat(B[3])])}else if(R.startsWith("vt ")){let B=R.trim().split(/\s+/);l.push([parseFloat(B[1]),parseFloat(B[2])])}else if(R.startsWith("o "))x=R.trim().slice(2).trim();else if(R.startsWith("usemtl ")){let B=R.trim().split(/\s+/)[1];m=P(B),g=a[B]}else if(R.startsWith("f ")){if(!b())continue;let B=R.trim().split(/\s+/).slice(1),z=[],ee=[];for(let Q of B){let Z=Q.split("/");z.push(y(Z[0],c.length));let ne=Z[1];if(ne&&ne.length>0){let j=y(ne,l.length);ee.push(Number.isFinite(j)?j:null)}else ee.push(null)}u.push({idx:z,uvIdx:ee,color:m,texture:g})}}if(c.length===0||u.length===0)return Ed(f,e.length);let S=new Set;for(let R of u)for(let B of R.idx)S.add(B);let T=1/0,E=1/0,A=1/0,C=-1/0,_=-1/0,w=-1/0;for(let R of S){let B=c[R];B&&(B[0]<T&&(T=B[0]),B[0]>C&&(C=B[0]),B[1]<E&&(E=B[1]),B[1]>_&&(_=B[1]),B[2]<A&&(A=B[2]),B[2]>w&&(w=B[2]))}let V=Math.max(C-T,_-E,w-A),N=V>0?t/V:1,F=R=>Math.round(R*1e3)/1e3,k=c.map(([R,B,z])=>[F((z-A)*N+r),F((R-T)*N+r),F((B-E)*N+r)]),$=[];for(let{idx:R,uvIdx:B,color:z,texture:ee}of u)for(let Q=1;Q<R.length-1;Q++){let Z=R[0],ne=R[Q],j=R[Q+1],D=k[Z],I=k[ne],U=k[j];if(!D||!I||!U||D[0]===I[0]&&D[1]===I[1]&&D[2]===I[2]||D[0]===U[0]&&D[1]===U[1]&&D[2]===U[2]||I[0]===U[0]&&I[1]===U[1]&&I[2]===U[2])continue;let G;if(ee){let v=B[0],O=B[Q],L=B[Q+1];if(v!=null&&O!=null&&L!=null){let X=l[v],H=l[O],Y=l[L];X&&H&&Y&&(G=[X,H,Y])}}let q={vertices:[D,I,U],color:z};ee&&(q.texture=ee),G&&(q.uvs=G),$.push(q)}return{polygons:$,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:$.length,materials:f,sourceBytes:e.length}}}function Ed(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var ps=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function sr(e){let n={},t={},r=null;for(let o of e.split(`
|
|
3
|
+
`)){let s=o.trim();if(!(s.length===0||s.charCodeAt(0)===35)){if(s.startsWith("newmtl ")){r=s.slice(7).trim();continue}if(r){if(s.startsWith("Kd ")){let i=s.split(/\s+/),a=parseFloat(i[1]),c=parseFloat(i[2]),l=parseFloat(i[3]);Number.isFinite(a)&&Number.isFinite(c)&&Number.isFinite(l)&&(n[r]=`#${ps(a)}${ps(c)}${ps(l)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),a=i[i.length-1]?.replace(/\\+/g,"/");a&&a!=="map_Kd"&&(t[r]=a)}}}}return{colors:n,textures:t}}var Td=[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 Cd(e){let n=e>>0&255,t=e>>8&255,r=e>>16&255;return[n,t,r]}function hs(e){return(e&255).toString(16).padStart(2,"0")}function bc(e,n,t){return`#${hs(e)}${hs(n)}${hs(t)}`}function _d(e,n,t,r){if(r>=255)return bc(e,n,t);let o=Math.round(Math.max(0,Math.min(255,r))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${o})`}function yc(e){let n=e.match(/^#([0-9a-f]{6})$/i);if(n){let r=n[1];return{rgb:[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.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 Pc(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function hc(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,r=e.rgb[2]/255,o=Math.max(n,t,r),s=Math.min(n,t,r),i=o-s,a=0;return i!==0&&(o===n?a=60*((t-r)/i%6):o===t?a=60*((r-n)/i+2):a=60*((n-t)/i+4)),a<0&&(a+=360),{hue:a,saturation:o===0?0:i/o,value:o}}function vd(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function Ac(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=hc(e),r=hc(n),o=t.saturation<.08,s=r.saturation<.08;if(o||s)return o===s;let i=Math.min(t.value,r.value)<.16?35:24;return vd(t.hue,r.hue)<=i}function Id(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return null;let r=new Map;for(let a of e.keys()){let c=yc(a);c&&r.set(a,c)}let o=[],s=new Map,i=Array.from(e.entries()).sort((a,c)=>c[1]-a[1]||a[0].localeCompare(c[0]));for(let[a]of i){let c=r.get(a);if(!c){s.set(a,a);continue}let l=null;for(let u of o){if(!Ac(c,u.parsed))continue;let f=Pc(c,u.parsed);f>t||(!l||f<l.distance)&&(l={color:u.color,distance:f})}l?s.set(a,l.color):(o.push({color:a,parsed:c}),s.set(a,a))}return s}var Vd=[[1,0],[-1,0],[0,1],[0,-1]];function Mc(e,n){return`${e},${n}`}function Od(e){let n=e.indexOf(",");return[Number(e.slice(0,n)),Number(e.slice(n+1))]}function Rd(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 Ld(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return;let r=new Map,o=s=>(r.has(s)||r.set(s,yc(s)),r.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 a=new Set,c=[];for(let[l,u]of s){if(a.has(l))continue;let f=[l],d=[],m=new Map,g=1/0,h=-1/0,p=1/0,x=-1/0;for(a.add(l);f.length>0;){let S=f.pop();d.push(S);let[T,E]=Od(S);g=Math.min(g,T),h=Math.max(h,T),p=Math.min(p,E),x=Math.max(x,E);for(let[A,C]of Vd){let _=Mc(T+A,E+C),w=s.get(_);if(w){if(w===u){a.has(_)||(a.add(_),f.push(_));continue}m.set(w,(m.get(w)??0)+1)}}}let b=h-g+1,P=x-p+1;if(!Rd(d.length,b,P)||m.size===0)continue;let y=o(u);if(!y)continue;let M=null;for(let[S,T]of m){let E=i.get(S)??0;if(E<=d.length)continue;let A=o(S);if(!A||!Ac(y,A))continue;let C=Pc(y,A);if(C>t)continue;let _={color:S,contacts:T,distance:C,count:E};(!M||_.contacts>M.contacts||_.contacts===M.contacts&&_.count>M.count||_.contacts===M.contacts&&_.count===M.count&&_.distance<M.distance||_.contacts===M.contacts&&_.count===M.count&&_.distance===M.distance&&_.color.localeCompare(M.color)<0)&&(M=_)}if(M)for(let S of d)c.push([S,M.color])}for(let[l,u]of c)s.set(l,u)}}var wd=542658390;function ir(e,n){let t=n?.targetSize??60,r=n?.gridShift??0,o=e.byteLength;if(e.byteLength<8)return _n(o,["parseVox: buffer too small to be a valid .vox file"]);let s=new DataView(e);if(s.getUint32(0,!0)!==wd)return _n(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return _n(o,["parseVox: buffer too small for MAIN chunk"]);if(xc(s,8)!=="MAIN")return _n(o,["parseVox: expected MAIN chunk at offset 8"]);let l=20+s.getUint32(12,!0),u=l+s.getUint32(16,!0),f=[],d=[],m=null;for(;l<u&&l+12<=e.byteLength;){let D=xc(s,l),I=s.getUint32(l+4,!0),U=s.getUint32(l+8,!0),G=l+12,q=G+I+U;if(D==="SIZE"){if(I>=12&&G+12<=e.byteLength){let v=s.getUint32(G,!0),O=s.getUint32(G+4,!0),L=s.getUint32(G+8,!0);f.push({sx:v,sy:O,sz:L})}}else if(D==="XYZI"){if(I>=4&&G+4<=e.byteLength){let v=s.getUint32(G,!0),O=[],L=Math.min(v,Math.floor((I-4)/4));for(let X=0;X<L;X++){let H=G+4+X*4;O.push({x:s.getUint8(H),y:s.getUint8(H+1),z:s.getUint8(H+2),colorIndex:s.getUint8(H+3)})}d.push(O)}}else if(D==="RGBA"&&I>=1024&&G+1024<=e.byteLength){m=[];for(let v=0;v<256;v++){let O=G+v*4,L=s.getUint8(O),X=s.getUint8(O+1),H=s.getUint8(O+2),Y=s.getUint8(O+3);m.push(_d(L,X,H,Y))}}l=q}let g=[],h=new Set;for(let D of d)for(let I of D){if(I.colorIndex===0)continue;let U=`${I.x},${I.y},${I.z}`;h.has(U)||(h.add(U),g.push(I))}if(g.length===0)return _n(o,[]);let p=new Map,x=D=>{let I=p.get(D);if(I)return I;let U=D-1,G;if(m!==null)G=m[U]??"#888888";else{let q=Td[D]??0,[v,O,L]=Cd(q);G=bc(v,O,L)}return p.set(D,G),G},b=new Map;for(let D of g){let I=x(D.colorIndex);b.set(I,(b.get(I)??0)+1)}let P=Id(b,n?.paletteMergeDistance),y=D=>{let I=x(D);return P?.get(I)??I},M=(D,I,U)=>h.has(`${D},${I},${U}`),S=new Map,T=(D,I,U,G,q)=>{let v=`${D}:${I}`,O=S.get(v);O||(O=new Map,S.set(v,O)),O.set(Mc(U,G),q)};for(let D of g){let{x:I,y:U,z:G}=D,q=y(D.colorIndex);M(I+1,U,G)||T(0,I+1,U,G,q),M(I-1,U,G)||T(1,I,U,G,q),M(I,U+1,G)||T(2,U+1,I,G,q),M(I,U-1,G)||T(3,U,I,G,q),M(I,U,G+1)||T(4,G+1,I,U,q),M(I,U,G-1)||T(5,G,I,U,q)}Ld(S,n?.colorRegionMergeDistance);let E=new Map;for(let[D,I]of S)for(let[U,G]of I){let q=`${D}:${G}`,v=E.get(q);v||(v=new Set,E.set(q,v)),v.add(U)}function A(D){let I=new Set,U=[],G=1/0,q=-1/0,v=1/0,O=-1/0;for(let L of D){let[X,H]=L.split(","),Y=+X,K=+H;Y<G&&(G=Y),Y>q&&(q=Y),K<v&&(v=K),K>O&&(O=K)}for(let L=v;L<=O;L++)for(let X=G;X<=q;X++){let H=`${X},${L}`;if(!D.has(H)||I.has(H))continue;let Y=1;for(;X+Y<=q;){let te=`${X+Y},${L}`;if(!D.has(te)||I.has(te))break;Y++}let K=1;e:for(;L+K<=O;){for(let te=0;te<Y;te++){let se=`${X+te},${L+K}`;if(!D.has(se)||I.has(se))break e}K++}for(let te=0;te<K;te++)for(let se=0;se<Y;se++)I.add(`${X+se},${L+te}`);U.push({u:X,v:L,w:Y,h:K})}return U}let C=(D,I,U,G,q,v)=>{let O=U+q,L=G+v;switch(D){case 0:return[[I,U,G],[I,O,G],[I,O,L],[I,U,L]];case 1:return[[I,O,G],[I,U,G],[I,U,L],[I,O,L]];case 2:return[[U,I,G],[U,I,L],[O,I,L],[O,I,G]];case 3:return[[O,I,G],[O,I,L],[U,I,L],[U,I,G]];case 4:return[[U,G,I],[O,G,I],[O,L,I],[U,L,I]];default:return[[U,L,I],[O,L,I],[O,G,I],[U,G,I]]}},_=[];for(let[D,I]of E){let U=D.indexOf(":"),G=D.indexOf(":",U+1),q=+D.slice(0,U),v=+D.slice(U+1,G),O=D.slice(G+1);for(let{u:L,v:X,w:H,h:Y}of A(I))_.push({vertices:C(q,v,L,X,H,Y),color:O})}if(_.length===0)return _n(o,[]);let w=1/0,V=1/0,N=1/0,F=-1/0,k=-1/0,$=-1/0;for(let D of _)for(let I of D.vertices)I[0]<w&&(w=I[0]),I[0]>F&&(F=I[0]),I[1]<V&&(V=I[1]),I[1]>k&&(k=I[1]),I[2]<N&&(N=I[2]),I[2]>$&&($=I[2]);let R=Math.max(F-w,k-V,$-N),B=R>0?t/R:1,z=B*50,ee=Number.isFinite(z)&&z>0?Math.max(1,Math.round(z))/50:B,Q={kind:"magica-vox",cells:g.map(D=>({x:D.x-w,y:D.y-V,z:D.z-N,color:y(D.colorIndex)})),rows:Math.max(0,F-w),cols:Math.max(0,k-V),depth:Math.max(0,$-N),scale:ee,gridShift:r,sourceBytes:o},Z=D=>Math.round(D*1e3)/1e3,ne=D=>[Z((D[0]-w)*ee+r),Z((D[1]-V)*ee+r),Z((D[2]-N)*ee+r)],j=_.map(({vertices:D,color:I})=>({vertices:D.map(ne),color:I}));return{polygons:j,voxelSource:Q,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:j.length,sourceBytes:o,voxelCount:g.length}}}function xc(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 _n(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var on="loadMesh";function xs(e,n){if(e.voxelSource)return e;let t=jt(e.polygons,{meshResolution:n?.meshResolution});return t===e.polygons?e:{...e,polygons:t}}async function Sc(e,n){let t=n?.solidTextureSamples;return t===!1?e:rr(e,typeof t=="object"?t:void 0)}function Nd(e){let n=e.split("?")[0].split("#")[0],t=n.lastIndexOf(".");return t<0?"":n.slice(t+1).toLowerCase()}async function Ec(e,n){let t=Nd(e);if(t==="mtl")throw new Error(`${on}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let r=globalThis.fetch;if(!r)throw new Error(`${on}: no fetch() in this environment`);let o=n?.baseUrl??e;if(t==="obj"){let s=await r(e);if(!s.ok)throw new Error(`${on}: ${e} \u2192 ${s.status}`);let i=await s.text(),a=n?.objOptions;if(n?.mtlUrl){let l=await r(n.mtlUrl);if(!l.ok)throw new Error(`${on}: ${n.mtlUrl} \u2192 ${l.status}`);let u=await l.text(),{colors:f,textures:d}=sr(u),m={},g=globalThis.URL,h=globalThis.document?.baseURI,p=n.mtlUrl;if(g&&h)try{p=new g(n.mtlUrl,h).toString()}catch{}for(let[x,b]of Object.entries(d)){if(g)try{m[x]=new g(b,p).toString();continue}catch{}let P=n.mtlUrl.lastIndexOf("/"),y=P>=0?n.mtlUrl.slice(0,P+1):"";m[x]=b.startsWith("/")||/^https?:\/\//.test(b)?b:y+b}a={...a??{},materialColors:{...f,...a?.materialColors??{}},materialTextures:{...m,...a?.materialTextures??{}}}}let c=or(i,a);return xs(await Sc(c,n),n)}if(t==="glb"||t==="gltf"){let s=await r(e);if(!s.ok)throw new Error(`${on}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),a=nr(i,{baseUrl:o,...n?.gltfOptions??{}});return xs(await Sc(a,n),n)}if(t==="vox"){let s=await r(e);if(!s.ok)throw new Error(`${on}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return xs(ir(i,n?.voxOptions),n)}throw new Error(`${on}: unsupported extension ".${t}" (supported: obj, glb, gltf, vox)`)}var Le=50,sn=[.4,-.7,.59],an="#ffffff",cn=1,ln="#ffffff",un=.4,Ge=4096,ct=1,ar=.1,cr=1,lt=Ge*Ge,lr=lt*3,vn=2048,ur=4*1024*1024,fr=16*1024*1024,mr=.995,dr=512,Tc=12,ie=.001,re=1e-9,gr=1e-4,pr=.1,ut=.01,Cc=.75,_c=1,vc=250,Ic=1.5,ft=.75,we=3,hr=2,mt=4,xr=[1,10,100,1e3,1e4,1e5,1e6],fn=64,br=32,yr=96,Vc="polycss-corner-triangle",Oc="polycss-large-border-triangle",Se=64,Pr=128,dt=50,gt=1e-7,Ne=16,In=.9,Ee=.75,pt=.2,Ar=.05,Mr=256,Sr=.6,Rc=1.5;function ue(e,n){if(Object.is(e,0)||Object.is(e,-0))return"0";if(e===1)return"1";if(e===-1)return"-1";let t=xr[n]??10**n,r=Math.round(e*t)/t;return Object.is(r,0)||Object.is(r,-0)?"0":String(r)}function Lc(e,n=mt){let t=ue(e,n);return t==="0"?"0":`${t}px`}function $e(e,n=we){if(e.length===0)return"";let t=ue(e[0],n);for(let r=1;r<e.length;r++)t+=`,${ue(e[r],n)}`;return t}function wc(e,n,t,r,o=we){return Er(e[0],e[1],e[2],n[0],n[1],n[2],t[0],t[1],t[2],r[0],r[1],r[2],o)}function Er(e,n,t,r,o,s,i,a,c,l,u,f,d=we){if(d===3){let m=Math.round(e*1e3)/1e3||0,g=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,p=Math.round(r*1e3)/1e3||0,x=Math.round(o*1e3)/1e3||0,b=Math.round(s*1e3)/1e3||0,P=Math.round(i*1e3)/1e3||0,y=Math.round(a*1e3)/1e3||0,M=Math.round(c*1e3)/1e3||0,S=Math.round(l*1e3)/1e3||0,T=Math.round(u*1e3)/1e3||0,E=Math.round(f*1e3)/1e3||0;return`${m},${g},${h},0,${p},${x},${b},0,${P},${y},${M},0,${S},${T},${E},1`}return`${ue(e,d)},${ue(n,d)},${ue(t,d)},0,${ue(r,d)},${ue(o,d)},${ue(s,d)},0,${ue(i,d)},${ue(a,d)},${ue(c,d)},0,${ue(l,d)},${ue(u,d)},${ue(f,d)},1`}function Tr(e,n,t,r,o,s,i,a,c,l,u,f,d=we){if(d!==3)return`matrix3d(${Er(e,n,t,r,o,s,i,a,c,l,u,f,d)})`;let m=Math.round(e*1e3)/1e3||0,g=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,p=Math.round(r*1e3)/1e3||0,x=Math.round(o*1e3)/1e3||0,b=Math.round(s*1e3)/1e3||0,P=Math.round(i*1e3)/1e3||0,y=Math.round(a*1e3)/1e3||0,M=Math.round(c*1e3)/1e3||0,S=Math.round(l*1e3)/1e3||0,T=Math.round(u*1e3)/1e3||0,E=Math.round(f*1e3)/1e3||0;return`matrix3d(${m},${g},${h},0,${p},${x},${b},0,${P},${y},${M},0,${S},${T},${E},1)`}function Vn(e,n,t,r=0,o=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],a=s[1],c=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]+=r*i+o*l,s[13]+=r*a+o*u,s[14]+=r*c+o*f,$e(s)}function Nc(e,n){return Vn(e,n.width/Ne,n.height/Ne,n.minX,n.minY)}function bs(e){let n=e.seamBleedInsets??{left:0,right:0,top:0,bottom:0},t=e.canvasW||1,r=e.canvasH||1;return Vn(e,(t+n.left+n.right)/fn,(r+n.top+n.bottom)/fn,-n.left,-n.top)}function Cr(e,n){let t=e.matrix.split(",").map(r=>Number(r));return t.length!==16||t.some(r=>!Number.isFinite(r))?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,$e(t))}function ze(e,n=hr){let t=ue(e,n);return Number(t)===0?"0":`${t}%`}function Dc(e,n=we){return`matrix3d(${e.split(",").map(t=>{let r=Number(t.trim());return Number.isFinite(r)?ue(r,n):t.trim()}).join(",")})`}function Fc(e,n=mt){let t=ue(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function Bc(e){return`matrix3d(${bs(e)})`}function Xe(e,n,t){return e.map(r=>[r[1]*n,r[0]*n,r[2]*t])}function qe(e){if(e.length<3)return null;let n=e[0],t=0,r=0,o=0;for(let i=1;i+1<e.length;i++){let a=e[i],c=e[i+1],l=[a[0]-n[0],a[1]-n[1],a[2]-n[2]],u=[c[0]-n[0],c[1]-n[1],c[2]-n[2]];t-=l[1]*u[2]-l[2]*u[1],r-=l[2]*u[0]-l[0]*u[2],o-=l[0]*u[1]-l[1]*u[0]}let s=Math.hypot(t,r,o);return s<=re?null:(t/=s,r/=s,o/=s,[t,r,o])}function On(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let r=e[t],o=e[(t+1)%e.length],s=e[(t+2)%e.length],i=(o[0]-r[0])*(s[1]-o[1])-(o[1]-r[1])*(s[0]-o[0]);if(Math.abs(i)<=re)return!1;let a=Math.sign(i);if(n===0)n=a;else if(a!==n)return!1}return!0}function _r(e){let n=0;for(let t=0;t<e.length;t++){let r=e[t],o=e[(t+1)%e.length];n+=r[0]*o[1]-r[1]*o[0]}return n/2}function vr(e,n,t,r){let o=n[0]-e[0],s=n[1]-e[1],i=r[0]-t[0],a=r[1]-t[1],c=o*a-s*i;if(Math.abs(c)<=re)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*i)/c;return[e[0]+f*o,e[1]+f*s]}function kc(e,n,t,r,o,s,i,a){let c=t-e,l=r-n,u=i-o,f=a-s,d=c*f-l*u;if(Math.abs(d)<=re)return null;let m=o-e,g=s-n,h=(m*f-g*u)/d;return[e+h*c,n+h*l]}function mn(e,n){if(e.length<6||n<=0)return e;let t=0,r=0,o=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],r+=e[i+1];t/=o,r/=o;let s=e.slice();for(let i=0;i<s.length;i+=2){let a=s[i]-t,c=s[i+1]-r,l=Math.hypot(a,c);l<=ie||(s[i]+=a/l*n,s[i+1]+=c/l*n)}return s}function dn(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let c=0;c<e.length;c+=2)t.push([e[c],e[c+1]]);if(!On(t))return mn(e,n);let r=_r(t);if(Math.abs(r)<=re)return mn(e,n);let o=r>0?1:-1,s=[];for(let c=0;c<t.length;c++){let l=t[c],u=t[(c+1)%t.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=re)return mn(e,n);let g=o*(d/m)*n,h=o*(-f/m)*n;s.push({a:[l[0]+g,l[1]+h],b:[u[0]+g,u[1]+h]})}let i=[],a=Math.max(2,n*4);for(let c=0;c<t.length;c++){let l=s[(c+t.length-1)%t.length],u=s[c],f=vr(l.a,l.b,u.a,u.b);if(!f)return mn(e,n);let d=t[c],m=f[0]-d[0],g=f[1]-d[1],h=Math.hypot(m,g);h>a?i.push(d[0]+m/h*a,d[1]+g/h*a):i.push(f[0],f[1])}return i}function Rn(e,n){if(e.length<6||e.length%2!==0)return e;let t=e.length/2;if(n.length!==t)return e;let r=n.map(f=>typeof f=="number"&&Number.isFinite(f)?Math.max(0,f):0),o=Math.max(0,...r);if(o<=0)return e;if(r.every(f=>Math.abs(f-r[0])<=re))return dn(e,r[0]);let s=[];for(let f=0;f<e.length;f+=2)s.push([e[f],e[f+1]]);if(!On(s))return e;let i=_r(s);if(Math.abs(i)<=re)return e;let a=i>0?1:-1,c=[];for(let f=0;f<s.length;f++){let d=s[f],m=s[(f+1)%s.length],g=m[0]-d[0],h=m[1]-d[1],p=Math.hypot(g,h);if(p<=re)return e;let x=r[f],b=a*(h/p)*x,P=a*(-g/p)*x;c.push({a:[d[0]+b,d[1]+P],b:[m[0]+b,m[1]+P]})}let l=[],u=Math.max(2,o*4);for(let f=0;f<s.length;f++){let d=c[(f+s.length-1)%s.length],m=c[f],g=vr(d.a,d.b,m.a,m.b);if(!g)return e;let h=s[f],p=g[0]-h[0],x=g[1]-h[1],b=Math.hypot(p,x);b>u?l.push(h[0]+p/b*u,h[1]+x/b*u):l.push(g[0],g[1])}return l}function ht(e,n,t,r,o,s,i){if(i<=0)return[e,n,t,r,o,s];let a=(e*r-n*t+t*s-r*o+o*n-s*e)/2,c=()=>mn([e,n,t,r,o,s],i);if(Math.abs(a)<=re)return c();let l=a>0?1:-1,u=t-e,f=r-n,d=Math.sqrt(u*u+f*f),m=o-t,g=s-r,h=Math.sqrt(m*m+g*g),p=e-o,x=n-s,b=Math.sqrt(p*p+x*x);if(d<=re||h<=re||b<=re)return c();let P=l*(f/d)*i,y=l*(-u/d)*i,M=e+P,S=n+y,T=t+P,E=r+y,A=l*(g/h)*i,C=l*(-m/h)*i,_=t+A,w=r+C,V=o+A,N=s+C,F=l*(x/b)*i,k=l*(-p/b)*i,$=o+F,R=s+k,B=e+F,z=n+k,ee=B-$,Q=z-R,Z=T-M,ne=E-S,j=ee*ne-Q*Z;if(Math.abs(j)<=re)return c();let D=M-$,I=S-R,U=(D*ne-I*Z)/j,G=$+U*ee,q=R+U*Q,v=T-M,O=E-S,L=V-_,X=N-w,H=v*X-O*L;if(Math.abs(H)<=re)return c();let Y=_-M,K=w-S,te=(Y*X-K*L)/H,se=M+te*v,he=S+te*O,Te=V-_,le=N-w,me=B-$,pe=z-R,ve=Te*pe-le*me;if(Math.abs(ve)<=re)return c();let ye=$-_,Ce=R-w,xe=(ye*pe-Ce*me)/ve,Pe=_+xe*Te,Ae=w+xe*le,ce=Math.max(2,i*4),fe=G-e,Me=q-n,ae=Math.sqrt(fe*fe+Me*Me);ae>ce&&(G=e+fe/ae*ce,q=n+Me/ae*ce);let de=se-t,W=he-r,J=Math.sqrt(de*de+W*W);J>ce&&(se=t+de/J*ce,he=r+W/J*ce);let oe=Pe-o,be=Ae-s,_e=Math.sqrt(oe*oe+be*be);return _e>ce&&(Pe=o+oe/_e*ce,Ae=s+be/_e*ce),[G,q,se,he,Pe,Ae]}function Ir(e,n,t,r){let o=e+n;if(r<=0||t<=re||o<=re||!Number.isFinite(e+n+t+r))return ht(e,0,0,t,o,t,r);let s=Math.sqrt(e*e+t*t),i=Math.sqrt(n*n+t*t);if(s<=re||i<=re)return ht(e,0,0,t,o,t,r);let a=-r*t/s,c=-r*e/s,l=r*t/i,u=-r*n/i,f=e+a,d=c,m=o+l,g=t+u,h=-t*o;if(Math.abs(h)<=re)return ht(e,0,0,t,o,t,r);let p=f-m,x=d-g,b=(p*t+x*e)/h,P=m-b*n,y=g-b*t,M=-r*(e+s)/t,S=t+r,T=o+r*(n+i)/t,E=S,A=Math.max(2,r*4),C=P-e,_=y,w=Math.sqrt(C*C+_*_);w>A&&(P=e+C/w*A,y=_/w*A);let V=Math.sqrt(M*M+r*r);V>A&&(M=M/V*A,S=t+r/V*A);let N=T-o,F=Math.sqrt(N*N+r*r);return F>A&&(T=o+N/F*A,E=t+r/F*A),[P,y,M,S,T,E]}function ys(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,r=e.layerElevation,o=Xe(n.vertices,t,r),s=qe(o);if(!s)return null;let i=e.screenPts[0],a=e.screenPts[1],c=e.screenPts[2],l=e.screenPts[3],u=e.screenPts[4],f=e.screenPts[5],d=c-i,m=l-a,g=u-i,h=f-a,p=d*h-m*g;if(Math.abs(p)<=re)return null;let x=o[0],b=o[1],P=o[2],y=[b[0]-x[0],b[1]-x[1],b[2]-x[2]],M=[P[0]-x[0],P[1]-x[1],P[2]-x[2]],S=[(y[0]*h-m*M[0])/p,(y[1]*h-m*M[1])/p,(y[2]*h-m*M[2])/p],T=[(d*M[0]-y[0]*g)/p,(d*M[1]-y[1]*g)/p,(d*M[2]-y[2]*g)/p],E=x[0]-S[0]*i-T[0]*a,A=x[1]-S[1]*i-T[1]*a,C=x[2]-S[2]*i-T[2]*a;return{normal:s,xAxis:S,yAxis:T,tx:E,ty:A,tz:C}}function Vr(e){return Math.max(0,Math.min(6,Math.floor(e??we)))}function Uc(e){return`${e[0]},${e[1]},${e[2]}`}function Gc(e,n){let t=Uc(e),r=Uc(n);return t<r?`${t}|${r}`:`${r}|${t}`}function $c(e){let n=new Map;for(let r=0;r<e.length;r++){let o=e[r].vertices;if(!(!o||o.length<3||!e[r].texture))for(let s=0;s<o.length;s++){let i=Gc(o[s],o[(s+1)%o.length]),a=n.get(i),c={polygon:r,edge:s};a?a.push(c):n.set(i,[c])}}let t=e.map(()=>new Set);for(let r of n.values())if(!(r.length<2))for(let o=0;o<r.length;o++)for(let s=o+1;s<r.length;s++)t[r[o].polygon].add(r[o].edge),t[r[s].polygon].add(r[s].edge);return t.map(r=>r.size>0?r:void 0)}function xt(e,n){return typeof e=="number"&&Number.isFinite(e)?Math.max(0,e):n}function Or(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function bt(e,n,t){if(t<=0||e.length<6||e.length%2!==0)return 0;let r=e.length/2;if(n<0||n>=r)return 0;let o=[];for(let E=0;E<e.length;E+=2)o.push([e[E],e[E+1]]);let[s,i]=o[n],[a,c]=o[(n+1)%r],l=a-s,u=c-i,f=Math.hypot(l,u);if(f<=ie)return 0;let d=[],m=Number.POSITIVE_INFINITY;for(let E=0;E<r;E+=1){if(E===n||E===(n+1)%r)continue;let[A,C]=o[E],_=Math.abs((A-s)*u-(C-i)*l)/f;_>ie&&(m=Math.min(m,_))}Number.isFinite(m)&&d.push(m*.5);let g=o[(n+r-1)%r],h=o[(n+2)%r],p=g[0]-s,x=g[1]-i,b=h[0]-a,P=h[1]-c,y=Math.hypot(p,x),M=Math.hypot(b,P);if(y>ie){let E=Math.abs(l*x-u*p)/(f*y);E>ie&&d.push(y*E)}if(M>ie){let E=Math.abs(-l*P- -u*b)/(f*M);E>ie&&d.push(M*E)}let S=d.filter(E=>Number.isFinite(E)&&E>0);if(S.length===0)return Number.isFinite(t)?Math.max(0,t):0;let T=Math.min(...S);return Math.max(0,Math.min(Number.isFinite(t)?t:T,T))}function Rr(e,n,t){if(!n?.size||t===void 0)return;let r=new Map;for(let o of n){let s=bt(e,o,t);s>0&&r.set(o,s)}return r.size>0?r:void 0}function Lr(e,n){return e<3||!n?.size?null:Array.from({length:e},(t,r)=>Math.max(0,n.get(r)??0))}function wr(e,n){if(!n?.size||e.length<6||e.length%2!==0)return;let t=e.length/2,r=Number.POSITIVE_INFINITY,o=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];r=Math.min(r,u),o=Math.min(o,f),s=Math.max(s,u),i=Math.max(i,f)}if(!Number.isFinite(r+o+s+i))return;let a=Math.max(ie*8,.25),c={left:0,right:0,top:0,bottom:0};for(let[l,u]of n){let f=Math.max(0,u);if(f<=0||l<0||l>=t)continue;let d=l*2,m=(l+1)%t*2,g=e[d],h=e[d+1],p=e[m],x=e[m+1];Math.abs(g-p)<=a?Math.abs(g-r)<=a&&Math.abs(p-r)<=a?c.left=Math.max(c.left,f):Math.abs(g-s)<=a&&Math.abs(p-s)<=a&&(c.right=Math.max(c.right,f)):Math.abs(h-x)<=a&&(Math.abs(h-o)<=a&&Math.abs(x-o)<=a?c.top=Math.max(c.top,f):Math.abs(h-i)<=a&&Math.abs(x-i)<=a&&(c.bottom=Math.max(c.bottom,f)))}return c.left||c.right||c.top||c.bottom?c:void 0}function Dd(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Fd(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let r=Xe(e.vertices,n,t),o=qe(r);return o?{normal:o,planeD:Dd(o,r[0])}:null}function Bd(e,n){return(e.material?.key??e.color??"")===(n.material?.key??n.color??"")&&e.color===n.color}function zc(e,n={}){return new Set(Ps(e,n).keys())}function Ps(e,n={}){let t=n.tileSize??50,r=n.layerElevation??t,o=e.map(c=>Fd(c,t,r)),s=new Map;for(let c=0;c<e.length;c++){let l=e[c].vertices;if(!(!l||l.length<3))for(let u=0;u<l.length;u++){let f=Gc(l[u],l[(u+1)%l.length]),d=s.get(f),m={polygon:c,edge:u};d?d.push(m):s.set(f,[m])}}let i=new Map,a=(c,l)=>{let u=i.get(c);u?u.add(l):i.set(c,new Set([l]))};for(let c of s.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l],d=c[u],m=f.polygon,g=d.polygon;!o[m]||!o[g]||Bd(e[m],e[g])&&(a(m,f.edge),a(g,d.edge))}return i}var yt=new Map;function gn(e){if(yt.has(e)){let t=yt.get(e);return t===void 0?null:t}let n=Pn(e);return yt.size>=dr&&yt.clear(),yt.set(e,n),n}function De(e){let n=gn(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Nr({r:e,g:n,b:t}){return`${e},${n},${t}`}function Pt(e){return gn(e)?.alpha??1}function At({r:e,g:n,b:t}){let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(n)}${r(t)}`}function Mt(e,n,t,r){let o=De(n),s=De(t);return{r:s.r/255*r+o.r/255*e,g:s.g/255*r+o.g/255*e,b:s.b/255*r+o.b/255*e}}function Xc({r:e,g:n,b:t}){let r=o=>Math.round(Math.max(0,Math.min(1,o))*255);return`rgb(${r(e)} ${r(n)} ${r(t)})`}function Ln(e,n,t,r,o){let s=De(e),i=De(t),a=De(r),c=a.r/255*o+i.r/255*n,l=a.g/255*o+i.g/255*n,u=a.b/255*o+i.b/255*n,f=Math.max(0,Math.min(255,Math.round(s.r*c))),d=Math.max(0,Math.min(255,Math.round(s.g*l))),m=Math.max(0,Math.min(255,Math.round(s.b*u))),g=Pt(e);return g<1?`rgba(${f}, ${d}, ${m}, ${g})`:At({r:f,g:d,b:m})}function Dr(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=gn(e);if(!t)return e;let r=255/Math.max(1,Math.round(n)-1),o=i=>Math.max(0,Math.min(255,Math.round(Math.round(i/r)*r))),s={r:o(t.rgb[0]),g:o(t.rgb[1]),b:o(t.rgb[2])};return t.alpha<1?`rgba(${s.r}, ${s.g}, ${s.b}, ${t.alpha})`:At(s)}function Wc(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function jc(e,n,t){let r=(o,s)=>{let i=s-o;return Math.abs(i)<=t?s:o+Math.sign(i)*t};return{r:r(e.r,n.r),g:r(e.g,n.g),b:r(e.b,n.b)}}function Yc(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:At(e)}function Hc(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=gn(e),r=gn(n);if(!t||!r)return 1;let o=t.rgb[0]-r.rgb[0],s=t.rgb[1]-r.rgb[1],i=t.rgb[2]-r.rgb[2],a=(t.alpha-r.alpha)*255;return Math.sqrt(o*o+s*s+i*i+a*a)/510}function As(e){if(e.screenPts.length!==8)return null;let n=[],t=[],r=.001,o=(s,i)=>{for(let a of s)if(Math.abs(a-i)<=r)return;s.push(i)};for(let s=0;s<e.screenPts.length;s+=2)o(n,e.screenPts[s]),o(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])>r||Math.abs(t[0])>r||n[1]-n[0]<=r||t[1]-t[0]<=r))return null;for(let s=0;s<e.screenPts.length;s+=2){let i=e.screenPts[s],a=e.screenPts[s+1],c=Math.abs(i-n[0])<=r||Math.abs(i-n[1])<=r,l=Math.abs(a-t[0])<=r||Math.abs(a-t[1])<=r;if(!c||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function Ze(e){return!!As(e)}function pn(e){return!e.texture&&e.polygon.vertices.length===3}function St(e){return!e.texture&&!!e.projectiveMatrix&&!Ze(e)}function Kc(e){let n=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(e);return/\bVersion\/[\d.]+.*\bSafari\//.test(e)&&!n}function Fr(e,n){e.set(n,(e.get(n)??0)+1)}function Br(e){let n,t=1;for(let[r,o]of e)o>t&&(n=r,t=o);return n}function qc(e,n,t,r){let o=!t.has("b"),s=o,i=!t.has("u")&&r.solidTriangleSupported,a=!t.has("i")&&n!=="dynamic"&&r.borderShapeSupported,c=t.has("b");return e.map(l=>{if(!l||l.texture)return l;if(i&&pn(l))return null;let u=Ze(l);return o&&u||s&&St(l)||n!=="dynamic"&&a&&(!u||c)?null:l})}function Zc(e,n,t,r,o,s,i){let a=new Map,c=new Map,l=new Map,u=!t.has("b"),f=u&&r.projectiveQuadSupported,d=!t.has("u")&&r.solidTriangleSupported,m=!t.has("i")&&r.cornerShapeSupported,g=!t.has("i")&&r.borderShapeSupported;for(let x of e){if(!x||x.texture)continue;let b=m&&!!i?.(x);if(n==="dynamic"){if(!(d&&pn(x))&&!(u&&Ze(x))&&!(f&&St(x))&&!b&&!g)continue;let P=o(x.polygon.color??"#cccccc"),y=s(P);Fr(c,y),l.has(y)||l.set(y,P);continue}!(d&&pn(x))&&!(u&&Ze(x))&&!(f&&St(x))&&!b&&!g||Fr(a,x.shadedColor)}let h=Br(a),p=Br(c);return{paintColor:h,dynamicColorKey:p,dynamicColor:p?l.get(p):void 0}}function kd(e,n,t,r,o,s){let i=(e-t)*(s-r)-(n-r)*(o-t);return Math.abs(i)>gt?!1:(e-t)*(e-o)+(n-r)*(n-s)<=gt}function Ms(e,n=dt,t=dt){let r=!1;for(let o=0,s=e.length-1;o<e.length;s=o++){let[i,a]=e[o],[c,l]=e[s];if(kd(n,t,i,a,c,l))return!0;a>t!=l>t&&n<(c-i)*(t-a)/(l-a)+i&&(r=!r)}return r}function Ss(e,n,t){let r=Number.POSITIVE_INFINITY,o=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)||(r=Math.min(r,u),o=Math.min(o,f),s=Math.max(s,u),i=Math.max(i,f))}let a=s-r,c=i-o;return!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(c)||a<=re||c<=re?{minX:0,minY:0,width:n,height:t}:{minX:r,minY:o,width:a,height:c}}function wn(e){let n=e.canvasW||1,t=e.canvasH||1,r=In>0?dn(e.screenPts,In):e.screenPts,o=In>0?Ss(r,n,t):{minX:0,minY:0,width:n,height:t},s=[];for(let i=0;i<r.length;i+=2){let a=Math.max(0,Math.min(100,(r[i]-o.minX)/o.width*100)),c=Math.max(0,Math.min(100,(r[i+1]-o.minY)/o.height*100));s.push([a,c])}return{bounds:o,points:s}}function Es(e){let n=[];for(let t of e){let r=n[n.length-1];r&&Math.hypot(r[0]-t[0],r[1]-t[1])<=pt||n.push(t)}if(n.length>1){let t=n[0],r=n[n.length-1];Math.hypot(t[0]-r[0],t[1]-r[1])<=pt&&n.pop()}return n}function Ts([e,n]){let t=new Set;return Math.abs(e)<=Ee&&t.add("left"),Math.abs(e-100)<=Ee&&t.add("right"),Math.abs(n)<=Ee&&t.add("top"),Math.abs(n-100)<=Ee&&t.add("bottom"),t.size>0?t:null}function Cs(e,n){for(let t of e)if(n.has(t))return!0;return!1}function _s(e,n,t,r){let o=(s,i,a)=>{let c=n.has(i)?e:r.has(i)?t:null,l=n.has(a)?e:r.has(a)?t:null;if(!c||!l)return null;let u=(()=>{switch(s){case"topLeft":return{x:c[0],y:l[1]};case"topRight":return{x:100-c[0],y:l[1]};case"bottomRight":return{x:100-c[0],y:100-l[1]};case"bottomLeft":return{x:c[0],y:100-l[1]}}})();return u.x>Ee&&u.y>Ee&&u.x<100-Ee&&u.y<100-Ee?[s,u]:null};return(n.has("top")||r.has("top"))&&(n.has("left")||r.has("left"))?o("topLeft","top","left"):(n.has("top")||r.has("top"))&&(n.has("right")||r.has("right"))?o("topRight","top","right"):(n.has("bottom")||r.has("bottom"))&&(n.has("right")||r.has("right"))?o("bottomRight","bottom","right"):(n.has("bottom")||r.has("bottom"))&&(n.has("left")||r.has("left"))?o("bottomLeft","bottom","left"):null}function Qc(e){if(e.texture||pn(e)||Ze(e))return null;let n=wn(e),t=Es(n.points);if(t.length<4)return null;let r=t.map(Ts);if(r.some(i=>!i))return null;let o={},s=0;for(let i=0;i<t.length;i+=1){let a=r[i],c=r[(i+1)%t.length];if(Cs(a,c))continue;let l=_s(t[i],a,t[(i+1)%t.length],c);if(!l)return null;let[u,f]=l,d=o[u];if(d&&(Math.abs(d.x-f.x)>Ee||Math.abs(d.y-f.y)>Ee))return null;o[u]=f,s+=1}return s>0?{bounds:n.bounds,radii:o}:null}function Ud([e,n]){return`${ze(e)} ${ze(n)}`}function Gd(e){return`polygon(${e.map(Ud).join(",")})`}function $d(e){if(Ms(e))return"circle(0)";let n=0,t=0,r=Math.max(1,e.length);for(let[i,a]of e)n+=i,t+=a;let o=ze(Math.max(0,Math.min(100,n/r))),s=ze(Math.max(0,Math.min(100,t/r)));return`circle(0 at ${o} ${s})`}function kr(e){return`${Gd(e)} ${$d(e)}`}function Jc(e){return kr(wn(e).points)}function vs(e,n){return Vn(e,n.width/Ne,n.height/Ne,n.minX,n.minY)}function el(e){let n=wn(e);return`matrix3d(${vs(e,n.bounds)})`}function nl(e){let n=wn(e);return[`transform:matrix3d(${vs(e,n.bounds)})`,`border-shape:${kr(n.points)}`].join(";")}function tl(e,n){let t=[`transform:matrix3d(${vs(e,n.bounds)})`,`width:${Ne}px`,`height:${Ne}px`,"border:0","box-sizing:border-box","background:currentColor"];for(let[r,o]of Object.entries(n.radii)){let s=r.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`);t.push(`border-${s}-radius:${ze(o.x)} ${ze(o.y)}`),t.push(`corner-${s}-shape:bevel`)}return t.join(";")}function zd(e,n){if((e+1)%3===n)return e;if((n+1)%3===e)return n}function Xd(e,n,t,r,o,s,i){if(!e?.size)return null;let a=xt(n,t);return[[s,r],[r,o],[o,s]].map(([l,u],f)=>{let d=zd(l,u),m=d!==void 0&&e.has(d)?a:0;return bt(i,f,m)})}function Ur(e,n,t,r,o,s,i,a){let c=s,l="",u,f,d="";if(i){let m=a??e.color??"#cccccc",g=s.directionalLight,h=s.ambientLight,p=g?.direction??sn,x=g?.color??an,b=Math.max(0,g?.intensity??cn),P=h?.color??ln,y=Math.max(0,h?.intensity??un),M=Math.hypot(p[0],p[1],p[2])||1,S=p[0]/M,T=p[1]/M,E=p[2]/M,A=b*Math.max(0,t*S+r*T+o*E),C=Ln(m,A,x,P,y),_=s.textureLighting??"baked",w=_==="baked"&&c.stableTriangleColorSteps?Dr(C,c.stableTriangleColorSteps):C,V=De(m),N=w===s.solidPaintDefaults?.paintColor,F=_==="dynamic"&&Nr(V)===s.solidPaintDefaults?.dynamicColorKey;l=_==="dynamic"||N?"":w,u=l?De(l):void 0,f=l?Pt(l):void 0,d=_==="dynamic"?`--pnx:${t.toFixed(4)};--pny:${r.toFixed(4)};--pnz:${o.toFixed(4)};`+(F?"":`--psr:${(V.r/255).toFixed(4)};--psg:${(V.g/255).toFixed(4)};--psb:${(V.b/255).toFixed(4)};`):""}return{index:n,polygon:e,colorComputed:i,bakedColor:l||void 0,bakedRgb:u,bakedAlpha:f,dynamicVars:d}}function rl(e,n,t){if(e.texture||e.vertices.length!==3)return null;let r=t.tileSize??50,o=t.layerElevation??r,s=e.vertices[0],i=e.vertices[1],a=e.vertices[2],c=[s[1]*r,s[0]*r,s[2]*o],l=[i[1]*r,i[0]*r,i[2]*o],u=[a[1]*r,a[0]*r,a[2]*o],f=l[0]-c[0],d=l[1]-c[1],m=l[2]-c[2],g=u[0]-c[0],h=u[1]-c[1],p=u[2]-c[2],x=-(d*p-m*h),b=-(m*g-f*p),P=-(f*h-d*g),y=Math.sqrt(x*x+b*b+P*P);return y<=re?null:(x/=y,b/=y,P/=y,Ur(e,n,x,b,P,t,!0))}function ol(e,n,t,r={}){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??50,s=t.layerElevation??o,i=e.vertices[0],a=e.vertices[1],c=e.vertices[2],l=i[1]*o,u=i[0]*o,f=i[2]*s,d=a[1]*o,m=a[0]*o,g=a[2]*s,h=c[1]*o,p=c[0]*o,x=c[2]*s;return Gr(e,n,t,r,l,u,f,d,m,g,h,p,x)}function Gr(e,n,t,r,o,s,i,a,c,l,u,f,d){let m=t,g=a-o,h=c-s,p=l-i,x=u-o,b=f-s,P=d-i,y=-(h*P-p*b),M=-(p*x-g*P),S=-(g*b-h*x),T=Math.sqrt(y*y+M*M+S*S);if(T<=re)return null;y/=T,M/=T,S/=T;let E=r.basis,A=E?.a??0,C=E?.b??1,_=E?.c??2;A<0||A>2||C<0||C>2||_<0||_>2||A===C||A===_||C===_?(E=void 0,A=0,C=1,_=2):A===0&&C===1&&_===2||A===1&&C===2&&_===0||A===2&&C===0&&_===1||(E=void 0,A=0,C=1,_=2);let w=()=>E?Gr(e,n,t,{...r,basis:void 0},o,s,i,a,c,l,u,f,d):null;if(!E){let Qe=g*g+h*h+p*p,Ks=u-a,qs=f-c,Zs=d-l,Qs=o-u,Js=s-f,ei=i-d,ni=Ks*Ks+qs*qs+Zs*Zs,Tl=Qs*Qs+Js*Js+ei*ei,Zr=Qe;ni>Zr&&(A=1,C=2,_=0,Zr=ni),Tl>Zr&&(A=2,C=0,_=1)}let V,N,F,k,$,R,B=_===0?o:_===1?a:u,z=_===0?s:_===1?c:f,ee=_===0?i:_===1?l:d;A===0?(V=o,N=s,F=i):A===1?(V=a,N=c,F=l):(V=u,N=f,F=d),C===0?(k=o,$=s,R=i):C===1?(k=a,$=c,R=l):(k=u,$=f,R=d);let Q=k-V,Z=$-N,ne=R-F,j=Math.sqrt(Q*Q+Z*Z+ne*ne);if(j<=re)return w();let D=Q/j,I=Z/j,U=ne/j,G=(B-V)*D+(z-N)*I+(ee-F)*U,q=M*U-S*I,v=S*D-y*U,O=y*I-M*D,L=T/j;if(L<=re)return w();let X=Math.max(0,Math.min(j,G)),H=Math.max(0,j-X),Y=[X,0,0,L,X+H,L],K=Xd(m.seamEdges,m.seamBleed,ft,A,C,_,Y),te=K?Rn(Y,K):Ir(X,H,L,xt(m.seamBleed,ft)),se=te[0],he=te[1],Te=te[2],le=te[3],me=te[4],pe=te[5],ve=(le+pe)/2,ye=se-Te,Ce=me-se,xe=ve-he;if(ye<=re||Ce<=re||xe<=re||!Number.isFinite(ye+Ce+xe))return w();let Pe=r.includeColor??!0,Ae=!1,ce,fe,Me,ae="";if(Pe){let Qe=Ur(e,n,y,M,S,t,!0,r.color);Ae=Qe.colorComputed,ce=Qe.bakedColor,fe=Qe.bakedRgb,Me=Qe.bakedAlpha,ae=Qe.dynamicVars??""}let de=ce?`color:${ce};`:"",W=r.primitive??r.resolvedPrimitive??"border",oe=1/(W==="border-large"?yr:br),be=ye+Ce,_e=be*oe,We=(Ce-ye)*.5*oe,xn=xe*oe,bn=se-X-be*.5,yn=he,ml=D*_e,dl=I*_e,gl=U*_e,pl=D*We+q*xn,hl=I*We+v*xn,xl=U*We+O*xn,bl=B+D*bn+q*yn,yl=z+I*bn+v*yn,Pl=ee+U*bn+O*yn,Al=r.matrixDecimals??Vr(m.stableTriangleMatrixDecimals),Hs=Tr(ml,dl,gl,pl,hl,xl,y,M,S,bl,yl,Pl,Al),Ml=t.textureLighting??"baked",Sl=m.optimizeStableTriangleStyle===!0&&Ml==="baked"?"":`transform:${Hs};`+de+ae,El=E&&E.a===A&&E.b===C&&E.c===_?E:{a:A,b:C,c:_};return{index:n,polygon:e,styleText:Sl,transformText:Hs,basis:El,primitive:W,colorComputed:Ae,bakedColor:ce,bakedRgb:fe,bakedAlpha:Me,dynamicVars:ae}}function sl(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function Is(e){let n=e?.maxWeightRatio,t=Math.max(0,sl(e?.denomEps,Ar)),r=typeof n=="number"&&Number.isFinite(n)&&n>0?Math.max(1,n):Mr,o=Math.max(0,sl(e?.bleed,Sr));return{denomEps:t,maxWeightRatio:r,bleed:o,disableGuards:e?.disableGuards===!0}}function $r(e,n){if(e.length!==4||!On(e))return null;let[t,r,o,s]=e,i=t[0]-r[0]+o[0]-s[0],a=t[1]-r[1]+o[1]-s[1],c=r[0]-o[0],l=s[0]-o[0],u=r[1]-o[1],f=s[1]-o[1],d=c*f-u*l;if(Math.abs(d)<=re)return null;let m=(i*f-a*l)/d,g=(c*a-u*i)/d,h=[1,1+m,1+m+g,1+g];if(h.some(b=>!Number.isFinite(b)))return null;let p=Math.min(...h),x=Math.max(...h);return!n.disableGuards&&(p<=n.denomEps||x/p>n.maxWeightRatio)?null:{g:m,h:g,w1:1+m,w3:1+g}}function Vs(e,n,t,r,o,s,i,a,c){if(e.length!==8)return null;let l=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!$r(l,a))return null;let u=Lr(4,c),f=u?Rn(e,u):dn(e,a.bleed),d=[[f[0],f[1]],[f[2],f[3]],[f[4],f[5]],[f[6],f[7]]],m=$r(d,a);if(!m)return null;let{g,h,w1:p,w3:x}=m,[b,P,,y]=d,M=[o+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]],S=([E,A],C)=>[(C-1)*o+(C*E-b[0])*n[0]+(C*A-b[1])*t[0],(C-1)*s+(C*E-b[0])*n[1]+(C*A-b[1])*t[1],(C-1)*i+(C*E-b[0])*n[2]+(C*A-b[1])*t[2]],T=[...S(P,p),g,...S(y,x),h,r[0],r[1],r[2],0,M[0],M[1],M[2],1];for(let E=0;E<8;E+=1)T[E]/=fn;return $e(T,6)}function Et(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function il(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 Os(e){return!e.texture}function Rs(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let r=Xe(e.vertices,n,t),o=qe(r);return o?{pts:r,normal:o,planeD:Et(o,r[0]),optimizable:Os(e)}:null}function Ls(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:jr(e,n)}function jr(e,n){return!e||!n||Et(e.normal,n.normal)<1-gr?!1:Math.abs(e.planeD-n.planeD)<=pr}function zr(e,n){if(!e)return null;let t=n.directionalLight,r=n.ambientLight,o=t?.direction??sn,s=t?.color??an,i=Math.max(0,t?.intensity??cn),a=r?.color??ln,c=Math.max(0,r?.intensity??un),l=Math.hypot(o[0],o[1],o[2])||1,u=o[0]/l,f=o[1]/l,d=o[2]/l,m=i*Math.max(0,e.normal[0]*u+e.normal[1]*f+e.normal[2]*d),g=Mt(m,s,a,c);return g.r*.2126+g.g*.7152+g.b*.0722}function ws(e){let n=[...e],t=Math.abs(n[0])>re?0:Math.abs(n[1])>re?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 hn(e,n,t,r,o={}){let s=Et(r,t),i=[r[0]-s*t[0],r[1]-s*t[1],r[2]-s*t[2]],a=Math.hypot(i[0],i[1],i[2]);if(a<=re)return null;let c=[i[0]/a,i[1]/a,i[2]/a],l=[t[1]*c[2]-t[2]*c[1],t[2]*c[0]-t[0]*c[2],t[0]*c[1]-t[1]*c[0]],u=Math.hypot(l[0],l[1],l[2]);if(u<=re)return null;let f=[l[0]/u,l[1]/u,l[2]/u],d=e.map(F=>{let k=F[0]-n[0],$=F[1]-n[1],R=F[2]-n[2];return[k*c[0]+$*c[1]+R*c[2],k*f[0]+$*f[1]+R*f[2]]}),m=o.boundsOrigin??n,g=n[0]-m[0],h=n[1]-m[1],p=n[2]-m[2],x=g*c[0]+h*c[1]+p*c[2],b=g*f[0]+h*f[1]+p*f[2],P=1/0,y=1/0,M=-1/0,S=-1/0;for(let[F,k]of d){let $=F+x,R=k+b;$<P&&(P=$),$>M&&(M=$),R<y&&(y=R),R>S&&(S=R)}let T=M-P,E=S-y;if(!Number.isFinite(T)||!Number.isFinite(E))return null;let A=o.snapBounds?Math.floor(P+ie):P,C=o.snapBounds?Math.floor(y+ie):y,_=o.snapBounds?Math.ceil(M-ie):M,w=o.snapBounds?Math.ceil(S-ie):S,V=Math.max(1,o.snapBounds?_-A:Math.ceil(T)),N=Math.max(1,o.snapBounds?w-C:Math.ceil(E));return{xAxis:c,yAxis:f,local2D:d,shiftX:x-A,shiftY:b-C,canvasW:V,canvasH:N,pixelArea:V*N,rawArea:T*E}}function Xr(e){return`${e[0]},${e[1]},${e[2]}`}function al(e,n){return Xr(e)<Xr(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 Wd(e,n){let t=Xr(e),r=Xr(n);return t<r?`${t}|${r}`:`${r}|${t}`}function Ns(e,n,t,r){let o=0,s=0;for(let i of e){let a=n[i];if(!a)return null;let c=hn(a.pts,a.pts[0],a.normal,t,{boundsOrigin:r,snapBounds:!0});if(!c)return null;o+=c.pixelArea,s+=c.rawArea}return{pixelArea:o,rawArea:s}}function Ds(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let r={pixelArea:0,rawArea:0},o=null,s=new Set;for(let i of e){let a=n[i];if(!a)continue;let c=[a.pts[1][0]-a.pts[0][0],a.pts[1][1]-a.pts[0][1],a.pts[1][2]-a.pts[0][2]],l=hn(a.pts,a.pts[0],a.normal,c);r&&l?(r.pixelArea+=l.pixelArea,r.rawArea+=l.rawArea):r=null;for(let u=0;u<a.pts.length;u++){let f=al(a.pts[u],a.pts[(u+1)%a.pts.length]),d=hn(a.pts,a.pts[0],a.normal,f);if(!d)continue;let m=ws(d.xAxis);if(s.has(m))continue;s.add(m);let g=Ns(e,n,d.xAxis,t);g&&(!o||g.pixelArea<o.pixelArea||g.pixelArea===o.pixelArea&&g.rawArea<o.rawArea-ie)&&(o={xAxis:d.xAxis,...g})}}return o&&r&&(o.pixelArea<r.pixelArea||o.pixelArea===r.pixelArea&&o.rawArea<=r.rawArea+ie)?{xAxis:o.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function cl(e,n){let t=n.tileSize??50,r=n.layerElevation??t,o=e.map(f=>Rs(f,t,r)),s=new Map,i=e.map(()=>new Set),a=e.map(()=>new Set);for(let f=0;f<e.length;f++){let d=e[f].vertices;if(!(!d||d.length<3))for(let m=0;m<d.length;m++){let g=Wd(d[m],d[(m+1)%d.length]),h=s.get(g),p={polygon:f,edge:m};h?h.push(p):s.set(g,[p])}}let c=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 g=f[d],h=f[m],p=g.polygon,x=h.polygon;if(e[p].texture&&e[x].texture&&(a[g.polygon].add(g.edge),a[h.polygon].add(h.edge)),jr(o[p],o[x]))i[g.polygon].add(g.edge),i[h.polygon].add(h.edge);else{let b=zr(o[p],n),P=zr(o[x],n);b!==null&&P!==null&&(b<=P+ut&&i[g.polygon].add(g.edge),P<=b+ut&&i[h.polygon].add(h.edge))}Ls(o[p],o[x])&&(c[p].add(x),c[x].add(p))}let l=Array(e.length).fill(void 0),u=new Set;for(let f=0;f<e.length;f++){if(u.has(f)||!o[f]?.optimizable)continue;let d=[],m=[f];for(u.add(f);m.length>0;){let h=m.pop();d.push(h);for(let p of c[h])u.has(p)||(u.add(p),m.push(p))}if(d.length<2)continue;let g=Ds(d,o);if(g)for(let h of d)l[h]={xAxis:g.xAxis,boundsOrigin:g.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:a[h]}}for(let f=0;f<e.length;f++)!l[f]&&(i[f].size>0||a[f].size>0)&&(l[f]={seamEdges:i[f],textureEdgeRepairEdges:a[f]});return l}function Wr(e,n,t,r){if(r.optimize&&r.fixedXAxis)return hn(e,n,t,r.fixedXAxis,{boundsOrigin:r.boundsOrigin,snapBounds:r.snapBounds});let o=null,s=r.optimize&&r.seamEdges&&r.seamEdges.size>0?Array.from(r.seamEdges):null,i=s??(r.optimize?e.map((a,c)=>c):[0]);for(let a of i){let c=(a+1)%e.length,l=s?al(e[a],e[c]):[e[c][0]-e[a][0],e[c][1]-e[a][1],e[c][2]-e[a][2]],u=hn(e,n,t,l,{boundsOrigin:r.boundsOrigin,snapBounds:r.snapBounds});u&&(!o||u.pixelArea<o.pixelArea||u.pixelArea===o.pixelArea&&u.rawArea<o.rawArea-ie)&&(o=u)}return o}function Fs(e){if(e.local2D.length!==4)return!1;let n=[],t=[],r=(o,s)=>{for(let i of o)if(Math.abs(i-s)<=ie)return;o.push(s)};for(let[o,s]of e.local2D)r(n,o+e.shiftX),r(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((o,s)=>o-s),t.sort((o,s)=>o-s),Math.abs(n[0])>ie||Math.abs(t[0])>ie||n[1]-n[0]<=ie||t[1]-t[0]<=ie))return!1;for(let[o,s]of e.local2D){let i=o+e.shiftX,a=s+e.shiftY,c=Math.abs(i-n[0])<=ie||Math.abs(i-n[1])<=ie,l=Math.abs(a-t[0])<=ie||Math.abs(a-t[1])<=ie;if(!c||!l)return!1}return!0}function Yr(e,n){if(e.length<3||n.length<3)return null;let[t,r,o]=e,[s,i,a]=n,c=t[0],l=t[1],u=r[0],f=r[1],d=o[0],m=o[1],g=s[0],h=1-s[1],p=i[0],x=1-i[1],b=a[0],P=1-a[1],y=p-g,M=x-h,S=b-g,T=P-h,E=y*T-S*M;if(Math.abs(E)<=1e-9)return null;let A=u-c,C=d-c,_=f-l,w=m-l,V={a:(A*T-C*M)/E,b:(y*C-S*A)/E,c:(_*T-w*M)/E,d:(y*w-S*_)/E,e:0,f:0};return V.e=c-V.a*g-V.b*h,V.f=l-V.c*g-V.d*h,V}function Hr(e){if(e.length===0)return null;let n=1/0,t=1/0,r=-1/0,o=-1/0;for(let s of e){let i=s[0],a=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(a))return null;n=Math.min(n,i),r=Math.max(r,i),t=Math.min(t,a),o=Math.max(o,a)}return{minU:n,minV:t,maxU:r,maxV:o}}function Bs(e,n,t,r,o,s,i,a){let l=Xe(e.vertices,n,t).map(d=>{let m=d[0]-r[0],g=d[1]-r[1],h=d[2]-r[2];return[m*o[0]+g*o[1]+h*o[2]+i,m*s[0]+g*s[1]+h*s[2]+a]}),u=Yr(l,e.uvs),f=Hr(e.uvs);return!u&&!f?null:{screenPts:l.flatMap(([d,m])=>[d,m]),uvAffine:u,uvSampleRect:f}}function ks(e,n,t,r,o){let s=t,{vertices:i,texture:a,uvs:c}=e;if(!i||i.length<3)return null;let l=t.tileSize??50,u=t.layerElevation??l,f=Xe(i,l,u),d=f[0],m=f[1],g=[m[0]-d[0],m[1]-d[1],m[2]-d[2]];if(Math.hypot(g[0],g[1],g[2])===0)return null;let p=qe(f);if(!p)return null;let x=Wr(f,d,p,{optimize:!1}),b=a||x&&Fs(x)?x:Wr(f,d,p,{optimize:!0,fixedXAxis:o?.xAxis,boundsOrigin:o?.boundsOrigin,snapBounds:!!o,seamEdges:o?.seamEdges});if(!b)return null;let{xAxis:P,yAxis:y,local2D:M}=b,S=a&&o?.textureEdgeRepairEdges?.size?o.textureEdgeRepairEdges:null,T=!!(a&&S),E=b.shiftX,A=b.shiftY,C=b.canvasW,_=b.canvasH,w=[];for(let[le,me]of M)w.push(le+E,me+A);let V=d[0]-E*P[0]-A*y[0],N=d[1]-E*P[1]-A*y[1],F=d[2]-E*P[2]-A*y[2],k=$e([P[0],P[1],P[2],0,y[0],y[1],y[2],0,p[0],p[1],p[2],0,V,N,F,1]),$=$e([P[0]*C,P[1]*C,P[2]*C,0,y[0]*_,y[1]*_,y[2]*_,0,p[0],p[1],p[2],0,V,N,F,1]),R=$e([P[0]*C/Se,P[1]*C/Se,P[2]*C/Se,0,y[0]*_/Se,y[1]*_/Se,y[2]*_/Se,0,p[0],p[1],p[2],0,V,N,F,1]),B=Or(s.seamBleed),z=Rr(w,s.seamEdges??o?.seamEdges,B),ee=z?new Set(z.keys()):void 0,Q=z?Math.max(...z.values()):void 0,Z=wr(w,z),ne=!a&&i.length===4?Vs(w,P,y,p,V,N,F,r,z):null,j=t.directionalLight,D=t.ambientLight,I=j?.direction??sn,U=j?.color??an,G=Math.max(0,j?.intensity??cn),q=D?.color??ln,v=Math.max(0,D?.intensity??un),O=Math.hypot(I[0],I[1],I[2])||1,L=I[0]/O,X=I[1]/O,H=I[2]/O,Y=G*Math.max(0,p[0]*L+p[1]*X+p[2]*H),K=Mt(Y,U,q,v),te=Ln(e.color??"#cccccc",Y,U,q,v),se=null,he=null;a&&c&&c.length>=3&&c.length===i.length&&(he=Hr(c),se=Yr(M.map(([le,me])=>[le+E,me+A]),c));let Te=a&&e.textureTriangles?.length?e.textureTriangles.map(le=>Bs(le,l,u,d,P,y,E,A)).filter(le=>!!le):null;return{index:n,polygon:e,texture:a,tileSize:l,layerElevation:u,matrix:k,canonicalMatrix:$,atlasMatrix:R,projectiveMatrix:ne,canvasW:C,canvasH:_,screenPts:w,uvAffine:se,uvSampleRect:he,textureTriangles:Te,textureEdgeRepairEdges:S,textureEdgeRepair:T,seamBleed:Q,seamBleedEdges:ee,seamBleedEdgeAmounts:z,seamBleedInsets:Z,normal:p,textureTint:K,shadedColor:te}}function ll(e,n,t={},r){let o=Is(r),s=t,i=t.textureEdgeRepairEdges?.size||s.seamEdges?.size?{seamEdges:s.seamEdges??new Set,textureEdgeRepairEdges:t.textureEdgeRepairEdges}:void 0;return ks(e,n,s,o,i)}function Dn(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(cr,Math.max(ar,n))}function qr(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function Us(e,n){let t=qr(e);if(t<=0)return 1;let r=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),o=vn/r,s=Math.sqrt(n/(t*4));return Dn(Math.min(o,s))}function Gs(e,n){let t=qr(e),r=.5;return t<=lt?r=1:t<=lr&&(r=.75),Dn(Math.min(r,Us(e,n)))}function $s(e,n){return e.reduce((t,r)=>Math.max(t,Math.ceil(r.width*n),Math.ceil(r.height*n)),0)}function zs(e,n){return e.reduce((t,r)=>t+Math.ceil(r.width*n)*Math.ceil(r.height*n)*4,0)}function Xs(e,n,t){let r=$s(e,n),o=zs(e,n),s=r>vn?vn/r:1,i=o>t?Math.sqrt(t/o):1;return Math.min(s,i)}function Ws(e){return e?ur:fr}function js(e,n){return e!==void 0&&e!=="auto"?Se:n?Se:Pr}function Kr(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=Cr(t,n));return e}function ul(e){return e.atlasCanonicalSize??Se}function Ys(e){return Math.max(ct,Math.ceil(ct/e))}function Nn(e,n=1){let t=Array(e.length).fill(null),r=[],o=Ys(n),s=e.filter(c=>!!c).sort((c,l)=>l.canvasH-c.canvasH||l.canvasW-c.canvasW||c.index-l.index),i=()=>({width:o,height:o,entries:[],shelves:[]}),a=(c,l,u)=>{if(c.sealed)return null;for(let m of c.shelves)if(l.canvasH<=m.height&&m.x+l.canvasW+o<=Ge){let g={...l,pageIndex:u,x:m.x,y:m.y};return m.x+=l.canvasW+o*2,c.entries.push(g),c.width=Math.max(c.width,g.x+l.canvasW+o),g}let f=c.shelves.length===0?o:c.height+o;if(f+l.canvasH+o>Ge)return null;let d={...l,pageIndex:u,x:o,y:f};return c.shelves.push({x:o+l.canvasW+o*2,y:f,height:l.canvasH}),c.entries.push(d),c.width=Math.max(c.width,d.x+l.canvasW+o),c.height=Math.max(c.height,f+l.canvasH+o),d};for(let c of s){if(c.canvasW+o*2>Ge||c.canvasH+o*2>Ge){let f=r.length,d={...c,pageIndex:f,x:o,y:o};t[c.index]=d,r.push({width:c.canvasW+o*2,height:c.canvasH+o*2,entries:[d],shelves:[],sealed:!0});continue}let u=null;for(let f=0;f<r.length&&(u=a(r[f],c,f),!u);f++);if(!u){let f=i(),d=r.length;r.push(f),u=a(f,c,d)}u&&(t[c.index]=u)}return{entries:t,pages:r.map(({width:c,height:l,entries:u})=>({width:c,height:l,entries:u}))}}function jd(e,n,t){let r=Gs(n.pages,t),o=r===1?n:Nn(e,r);for(let s=0;s<4;s++){let i=Xs(o.pages,r,t);if(i>=1)break;let a=Dn(r*i*mr);if(a>=r)break;r=a,o=Nn(e,r)}return{packed:o,atlasScale:r}}function fl(e,n,t){let r=js(n,t);if(n!==void 0&&n!=="auto"){let i=Dn(n);return{packed:Kr(Nn(e,i),r),atlasScale:i,atlasCanonicalSize:r}}let o=Nn(e,1),s=jd(e,o,Ws(t));return{packed:Kr(s.packed,r),atlasScale:s.atlasScale,atlasCanonicalSize:r}}0&&(module.exports={ASYNC_RENDER_BUDGET_MS,ATLAS_CANONICAL_SIZE_AUTO_DESKTOP,ATLAS_CANONICAL_SIZE_EXPLICIT,ATLAS_MAX_SIZE,ATLAS_PADDING,AUTO_ATLAS_LOW_AREA,AUTO_ATLAS_MAX_BITMAP_SIDE,AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP,AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE,AUTO_ATLAS_MEDIUM_AREA,AUTO_ATLAS_SCALE_GUARD,BAKED_SHADOW_MIN_UP,BAKED_SHADOW_Z_SQUASH,BASE_TILE,BASIS_EPS,BORDER_SHAPE_BLEED,BORDER_SHAPE_CANONICAL_SIZE,BORDER_SHAPE_CENTER_PERCENT,BORDER_SHAPE_POINT_EPS,CAMERA_BACKFACE_CULL_EPS,COLOR_PARSE_CACHE_MAX,CORNER_SHAPE_DUPLICATE_EPS,CORNER_SHAPE_POINT_EPS,DECIMAL_SCALES,DEFAULT_AMBIENT_COLOR,DEFAULT_AMBIENT_INTENSITY,DEFAULT_ATLAS_CSS_DECIMALS,DEFAULT_BORDER_SHAPE_DECIMALS,DEFAULT_CAMERA_STATE,DEFAULT_LIGHT_COLOR,DEFAULT_LIGHT_DIR,DEFAULT_LIGHT_INTENSITY,DEFAULT_MATRIX_DECIMALS,DEFAULT_PROJECTION,DEFAULT_SEAM_BLEED,DEFAULT_SEAM_FACET_SPLIT_OPTIONS,DEFAULT_SEAM_OVERLAP_OPTIONS,DEFAULT_TILE,LoopOnce,LoopPingPong,LoopRepeat,MAX_ATLAS_SCALE,MIN_ATLAS_SCALE,PROJECTIVE_QUAD_BLEED,PROJECTIVE_QUAD_DENOM_EPS,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,QUAT_IDENTITY,RECT_EPS,SEAM_LIGHT_EPS,SOLID_QUAD_CANONICAL_SIZE,SOLID_TRIANGLE_BLEED,SOLID_TRIANGLE_CANONICAL_SIZE,SOLID_TRIANGLE_CORNER_CLASS,SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE,SOLID_TRIANGLE_LARGE_BORDER_CLASS,SURFACE_DISTANCE_EPS,SURFACE_NORMAL_EPS,TEXTURE_EDGE_REPAIR_ALPHA_MIN,TEXTURE_EDGE_REPAIR_RADIUS,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN,TEXTURE_TRIANGLE_BLEED,VOXEL_CAMERA_CULL_AXIS_EPS,VOXEL_CAMERA_CULL_NORMAL_LIMIT,applyPackedAtlasCanonicalSize,arrowPolygons,atlasArea,atlasBitmapMaxSide,atlasCanonicalSizeForEntry,atlasCanonicalSizeForTextureQuality,atlasDecodedBytes,atlasPadding,autoAtlasBudgetFactor,autoAtlasMaxDecodedBytes,autoAtlasScale,autoAtlasScaleCap,axesHelperPolygons,bakeSolidTextureSampledPolygons,bakeSolidTextureSamples,basisAxisKey,borderShapeBoundsFromPoints,borderShapeGeometryForPlan,boxPolygons,buildBakedShadowProjectionMatrix,buildBasisHints,buildSceneContext,buildSeamBleedPolygonEdges,buildSeamBleedPolygonSet,buildTextureEdgeRepairSets,cachedParsePureColor,cameraCullNormalGroups,cameraCullNormalGroupsFromPolygons,cameraCullNormalKey,cameraCullVisibleSignature,cameraFacingDepth,chooseIslandXAxis,chooseLocalBasis,clampChannel,clipPolygonToConvex2D,colorErrorScore,compatibleBleedSurface,compatibleSurface,computePlanSeamBleedEdgeAmounts,computeProjectiveQuadCoefficients,computeProjectiveQuadMatrix,computeSceneBbox,computeSeamBleedInsets,computeShapeLighting,computeSolidTriangleColorPlan,computeSolidTriangleColorPlanFromNormal,computeSolidTrianglePlan,computeSolidTrianglePlanFromCssPoints,computeSurfaceNormal,computeTextureAtlasPlan,computeTextureAtlasPlanPublic,computeTexturePaintMetrics,computeUvAffine,computeUvSampleRect,conePolygons,convexHull2D,cornerShapeDiagonal,cornerShapeGeometryForPlan,cornerShapePointSides,coverPlanarPolygons,createIsometricCamera,createPolyAnimationMixer,crossVec,cssBorderShapeForGeometry,cssBorderShapeForPlan,cssPoints,cullInteriorPolygons,cylinderPolygons,dedupeOverlappingPolygons,dodecahedronPolygons,dominantCountKey,dotVec,ensureCcw2D,eulerXYZFromQuat,evaluateIslandAxis,expandClipPoints,filterAtlasPlans,findOverlappingPolygonDuplicates,formatAffineMatrix3dColumns,formatAffineMatrix3dScalars,formatAffineMatrix3dTransformScalars,formatAtlasMatrix,formatBorderShapeElementStyle,formatBorderShapeEntryMatrix,formatBorderShapeMatrix,formatColor,formatCornerShapeElementStyle,formatCssLength,formatCssLengthPx,formatMatrix3d,formatMatrix3dValues,formatPercent,formatScaledMatrixFromPlan,formatSolidQuadEntryMatrix,formatSolidQuadMatrix,fullRectBounds,getPolygonBasisInfo,getSolidPaintDefaultsForPlansCore,icosahedronPolygons,incrementCount,intersect2DLines,intersect2DLinesRaw,inverseRotateVec3,isAxisAlignedSurfaceNormal,isBakedShadowCaster,isBasisOptimizable,isConvexPolygonPoints,isFullRectBasis,isFullRectSolid,isProjectiveQuadPlan,isSolidTrianglePlan,isVoxelCameraCullableNormalGroups,loadMesh,makeLocalBasis,mergePolygons,normalFacesCamera,normalizeAtlasScale,normalizeInvertMultiplier,normalizePolygons,normalizedSeamBleed,octahedronPolygons,offsetConvexPolygonPoints,offsetConvexPolygonPointsByEdgeAmounts,offsetStableTrianglePoints,offsetTrianglePoints,optimizeAnimatedMeshPolygons,optimizeMeshPolygons,packTextureAtlasPlans,packTextureAtlasPlansWithScaleCore,parseAlpha,parseColor,parseGltf,parseHex,parseHexColor,parseMtl,parseObj,parsePureColor,parseRgbColor,parseVox,planePolygons,polygonContainsPoint,polygonCssSurfaceNormal,polygonFaces,polygonFacesCamera,polygonSignedArea2D,projectCssVertexToGround,projectTextureTriangle,quantizeCssColor,quatFromAxisAngle,quatFromEulerXYZ,quatMultiply,repairMeshSeams,resolveProjectiveQuadGuards,resolveSeamBleed,rgbEqual,rgbKey,rgbToCss,rgbToHex,ringPolygons,ringQuadPolygons,rotateVec3,roundDecimal,safariCssProjectiveUnsupported,safePlanSeamBleedAmount,seamBleedAmountArray,seamFacetSplitPolygons,seamFacetSplitReport,seamLightBrightness,seamOverlapDiagnostics,seamOverlapPolygons,seamOverlapReport,shadeColor,shadePolygon,sharedCornerShapeSide,signedArea2D,simplifyCornerShapePoints,spherePolygons,stableBasisFromPlan,stableTriangleMatrixDecimals,stepRgbToward,tetrahedronPolygons,textureTintFactors,tintToCss,torusPolygons});
|