@glyphcss/core 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- var jr="cubic";function gt(e){let n=e.replace("#","");if(n.length===3){let r=parseInt(n[0]+n[0],16),t=parseInt(n[1]+n[1],16),o=parseInt(n[2]+n[2],16);return Number.isNaN(r)||Number.isNaN(t)||Number.isNaN(o)?null:{rgb:[r,t,o],alpha:1}}if(n.length===6){let r=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16);return Number.isNaN(r)||Number.isNaN(t)||Number.isNaN(o)?null:{rgb:[r,t,o],alpha:1}}return null}function pt(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 Tn(e){if(!e)return null;let n=e.trim(),r=gt(n);return r||pt(n)}function Me(e){return Math.max(0,Math.min(255,Math.round(e)))}function Ke(e){let[n,r,t]=e.rgb.map(Me);return e.alpha<1?`rgba(${n}, ${r}, ${t}, ${e.alpha})`:`rgb(${n}, ${r}, ${t})`}var In={rgb:[204,204,204],alpha:1},dt=new Map;function Ie(e){if(!e)return null;let n=e.trim(),r=dt.get(n);if(r)return r;let t=Tn(n);return t?(dt.set(n,t),t):null}function Xr(e,n){let r=Ie(e)??In,t=[Me(r.rgb[0]+n),Me(r.rgb[1]+n),Me(r.rgb[2]+n)];return Ke({rgb:t,alpha:r.alpha})}var wn={direction:[0,0,-1],color:"#ffffff",intensity:1},xt={color:"#ffffff",intensity:.4};function ht(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 yt(e,n,r){let t=Ie(n)??In;return e*(t.rgb[r]/255)}function Yr(e,n,r,t){let o=Ie(n)??In,s=ht(r?.direction??wn.direction),i=r?.color??wn.color,l=Math.max(0,r?.intensity??wn.intensity),c=t?.color??xt.color,a=Math.max(0,t?.intensity??xt.intensity),u=ht(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),g=l*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let d=o.rgb[p],y=yt(d,c,p)*a,b=yt(d,i,p)*g;m[p]=Me(y+b)}return Ke({rgb:m,alpha:o.alpha})}var bt="#cccccc",We=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Pt=(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]],Mt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Ze=e=>Math.hypot(e[0],e[1],e[2]);function Hr(e){let n=1/0,r=1/0,t=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]<r&&(r=u[1]),u[1]>s&&(s=u[1]),u[2]<t&&(t=u[2]),u[2]>i&&(i=u[2]);let l=o-n,c=s-r,a=i-t;return Math.hypot(l,c,a)}function Kr(){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 En(e){let n=[],r=[];if(!e||e.length===0)return{polygons:n,warnings:r};for(let t=0;t<e.length;t++){let o=e[t];if(!o||!Array.isArray(o.vertices)){r.push(`Polygon ${t}: missing vertices, dropped`);continue}let s=o.vertices;if(s.length<3){r.push(`Polygon ${t}: ${s.length} vertices (need >= 3), dropped`);continue}let i=We(s[1],s[0]),l=We(s[2],s[0]),c=Pt(i,l),a=Ze(c);if(s.length===3){if(a<1e-12){Ze(i)<1e-12||Ze(l)<1e-12?r.push(`Polygon ${t}: zero-area triangle (coincident vertices), dropped`):r.push(`Polygon ${t}: vertices collinear, dropped`);continue}}else if(a<1e-12){r.push(`Polygon ${t}: first 3 vertices collinear, dropped`);continue}let u=[{...o,vertices:s.slice()}];if(s.length>=4){let f=[c[0]/a,c[1]/a,c[2]/a],g=Mt(f,s[0]),m=Hr(s),p=Math.max(1e-6,m*.001),d=0;for(let y=3;y<s.length;y++){let b=Math.abs(Mt(f,s[y])-g);b>d&&(d=b)}if(d>p){let y=[],b=o.uvs&&o.uvs.length===s.length?o.uvs:void 0;for(let M=1;M<s.length-1;M++){let v=[s[0].slice(),s[M].slice(),s[M+1].slice()],P=Pt(We(v[1],v[0]),We(v[2],v[0]));if(Ze(P)<1e-12)continue;let x={...o,vertices:v};b&&(x.uvs=[b[0].slice(),b[M].slice(),b[M+1].slice()]),y.push(x)}if(y.length===0){r.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}r.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulated to ${y.length} triangles`),u=y}}for(let f of u){let g=Wr(f,t,r);g&&n.push(g)}}return{polygons:n,warnings:r}}function Wr(e,n,r){let t={vertices:e.vertices},o=e.texture;if(typeof o=="string"&&o===""&&(o=void 0),e.color!==void 0&&o!==void 0&&Kr()&&r.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Ie(e.color)?t.color=e.color:(r.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${bt}`),t.color=bt)),o!==void 0&&(t.texture=o),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?r.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):t.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let s={},i=!1;for(let l of Object.keys(e.data)){let c=e.data[l];typeof c=="string"||typeof c=="number"||typeof c=="boolean"?s[l]=c:(i=!0,r.push(`Polygon ${n}: data["${l}"] has non-primitive value, key dropped`))}Object.keys(s).length>0&&(t.data=s)}return t}function vt(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,r=1/0,t=1/0,o=-1/0,s=-1/0,i=-1/0,l=!1;for(let c of e)if(c?.vertices)for(let a of c.vertices)a&&(l=!0,a[0]<n&&(n=a[0]),a[0]>o&&(o=a[0]),a[1]<r&&(r=a[1]),a[1]>s&&(s=a[1]),a[2]<t&&(t=a[2]),a[2]>i&&(i=a[2]));return l?{min:[n,r,t],max:[o,s,i]}:{min:[0,0,0],max:[0,0,0]}}function Zr(e){let n=e.polygons??[],r,t;if(e.skipNormalize)r=n,t=[];else{let l=En(n);r=l.polygons,t=l.warnings}let o=vt(r),s=[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:t},dimensions:{sceneBbox:o,size:s},warnings:t}}function Qr(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function Qe(e,n,r,t){let o=n*Math.PI/180,s=r*Math.PI/180,i=t*Math.PI/180,[l,c,a]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[l,c]=[l*u-c*f,l*f+c*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[l,a]=[l*u+a*f,-l*f+a*u]}if(o!==0){let u=Math.cos(o),f=Math.sin(o);[c,a]=[c*u-a*f,c*f+a*u]}return[l,c,a]}function qr(e,n){let r=-n[0]*Math.PI/180,t=-n[1]*Math.PI/180,o=-n[2]*Math.PI/180,[s,i,l]=e;if(r!==0){let c=Math.cos(r),a=Math.sin(r);[i,l]=[i*c-l*a,i*a+l*c]}if(t!==0){let c=Math.cos(t),a=Math.sin(t);[s,l]=[s*c+l*a,-s*a+l*c]}if(o!==0){let c=Math.cos(o),a=Math.sin(o);[s,i]=[s*c-i*a,s*a+i*c]}return[s,i,l]}var On=Math.PI/180,Ge=180/Math.PI,Jr=[1,0,0,0];function eo(e,n){let[r,t,o,s]=e,[i,l,c,a]=n;return[r*i-t*l-o*c-s*a,r*l+t*i+o*a-s*c,r*c-t*a+o*i+s*l,r*a+t*c-o*l+s*i]}function no(e,n){let r=n*.5,t=Math.sin(r);return[Math.cos(r),e[0]*t,e[1]*t,e[2]*t]}function to(e){let n=e[0]*On,r=e[1]*On,t=e[2]*On,o=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(r*.5),l=Math.sin(r*.5),c=Math.cos(t*.5),a=Math.sin(t*.5);return[o*i*c-s*l*a,s*i*c+o*l*a,o*l*c-s*i*a,o*i*a+s*l*c]}function ro(e){let[n,r,t,o]=e,s=2*(r*o+n*t),i=2*(t*o-n*r),l=1-2*(r*r+t*t),c=2*(r*t-n*o),a=1-2*(t*t+o*o),u=Math.max(-1,Math.min(1,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,l)*Ge,f*Ge,Math.atan2(-c,a)*Ge]:[Math.atan2(2*(t*o+n*r),1-2*(r*r+o*o))*Ge,f*Ge,0]}var oo=50;function so(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Oe={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},At=100,Ct=1e4,Ee=e=>Math.round(e*At)/At,io=e=>Math.round(e*Ct)/Ct;function co(e={}){let n={target:e.target??[...Oe.target],rotX:e.rotX??Oe.rotX,rotY:e.rotY??Oe.rotY,zoom:e.zoom??Oe.zoom,distance:e.distance??Oe.distance};function r(o){o.target!==void 0&&(n.target=[Ee(o.target[0]),Ee(o.target[1]),Ee(o.target[2])]),o.rotX!==void 0&&(n.rotX=Ee(o.rotX)),o.rotY!==void 0&&(n.rotY=Ee(o.rotY)),o.zoom!==void 0&&(n.zoom=io(o.zoom)),o.distance!==void 0&&(n.distance=Ee(o.distance))}function t(o={}){let i=(o.cols??0)*50,l=(o.rows??0)*50,[c,a,u]=n.target,f=a*50,g=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, ${-g}px, ${-m}px)`,width:`${i}px`,height:`${l}px`}}return{state:n,update:r,getStyle:t}}var he=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],qe=(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]],De=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Rn=e=>Math.hypot(e[0],e[1],e[2]),xe=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function ao(e,n){let r=`${e[0]},${e[1]},${e[2]}`,t=`${n[0]},${n[1]},${n[2]}`;return r<t?`${r}|${t}`:`${t}|${r}`}function St(e){if(e.length<3)return null;let n=he(e[1],e[0]),r=he(e[2],e[0]),t=qe(n,r),o=Rn(t);if(o<1e-12)return null;let s=[t[0]/o,t[1]/o,t[2]/o],i=De(s,e[0]);return{normal:s,d:i}}function lo(e,n){return De(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function uo(e,n){return De(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function fo(e,n,r,t){let o=e.vertices.findIndex(V=>xe(V,r)),s=e.vertices.findIndex(V=>xe(V,t)),i=n.vertices.findIndex(V=>xe(V,r)),l=n.vertices.findIndex(V=>xe(V,t));if(o<0||s<0||i<0||l<0)return null;let c=e.vertices.length,a=n.vertices.length,u=(o+1)%c===s,f=(i+1)%a===l;if(u===f)return null;let g=u?s:o,m=u?o:s,p=f?l:i,d=f?i:l,y=!!(e.uvs&&n.uvs),b=[],M=y?[]:void 0,v=g;for(;b.push(e.vertices[v]),M&&M.push(e.uvs[v]),v!==m;)v=(v+1)%c;for(v=p;b.push(n.vertices[v]),M&&M.push(n.uvs[v]),v!==d;)v=(v+1)%a;let P=[],x=M?[]:void 0;for(let V=0;V<b.length;V++)(P.length===0||!xe(b[V],P[P.length-1]))&&(P.push(b[V]),x&&M&&x.push(M[V]));if(P.length>1&&xe(P[0],P[P.length-1])&&(P.pop(),x?.pop()),y)return Vt(P,x);let A=[],T=x?[]:void 0;for(let V=0;V<P.length;V++){let w=P[(V-1+P.length)%P.length],O=P[V],L=P[(V+1)%P.length],U=qe(he(O,w),he(L,w));Rn(U)>1e-9&&(A.push(O),T&&x&&T.push(x[V]))}return A.length<3?null:Vt(A,T)}function mo(e,n){let r=e.length,t=0;for(let o=0;o<r;o++){let s=e[o],i=e[(o+1)%r],l=e[(o+2)%r],c=he(i,s),a=he(l,i),u=De(qe(c,a),n);if(Math.abs(u)<1e-9)continue;let f=u>0?1:-1;if(t===0)t=f;else if(f!==t)return!1}return!0}function go(e,n){if(e.length<3)return!1;let r=St(e);if(!r)return!1;for(let t of e)if(Math.abs(De(r.normal,t)-r.d)>n)return!1;return!0}function po(e){return e.map(n=>({vertices:n.vertices.map(r=>[...r]),uvs:n.uvs.map(r=>[...r])}))}function xo(e,n){let r=[];for(let t=1;t<e.length-1;t++)r.push({vertices:[[...e[0]],[...e[t]],[...e[t+1]]],uvs:[[...n[0]],[...n[t]],[...n[t+1]]]});return r}function Vt(e,n){for(let r=0;r<e.length;r++){let t=e[r],o=e[(r+1)%e.length],s=e[(r+2)%e.length];if(!(Rn(qe(he(o,t),he(s,t)))<=1e-9))return r===0?{vertices:e,uvs:n}:{vertices:[...e.slice(r),...e.slice(0,r)],uvs:n?[...n.slice(r),...n.slice(0,r)]:void 0}}return{vertices:e,uvs:n}}function ce(e){let n=[],r=[];for(let o of e??[]){if(!o||!o.vertices||o.vertices.length<3){o&&n.push(o);continue}let s=o.vertices.map(a=>[a[0],a[1],a[2]]),i=St(s);if(!i){n.push(o);continue}let l=o.texture&&o.uvs&&o.uvs.length===s.length?o.uvs.map(a=>[a[0],a[1]]):void 0,c=o.texture&&l?o.textureTriangles?.length?po(o.textureTriangles):xo(s,l):void 0;r.push({vertices:s,uvs:l,color:o.color??"#cccccc",texture:o.texture,textureTriangles:c,normal:i.normal,d:i.d,alive:!0,data:o.data})}let t=()=>{let o=new Map;for(let l=0;l<r.length;l++){let c=r[l];if(!c.alive)continue;let a=c.vertices.length;for(let u=0;u<a;u++){let f=c.vertices[u],g=c.vertices[(u+1)%a],m=ao(f,g),p=o.get(m);p||(p=[],o.set(m,p)),p.push(l)}}let s=!1,i=(l,c)=>{for(let a=0;a<l.vertices.length;a++){let u=l.vertices[a],f=l.vertices[(a+1)%l.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(xe(u,p)&&xe(f,m))return[u,f]}}return null};for(let[,l]of o){if(l.length<2)continue;let[c,a]=l;if(c===a)continue;let u=r[c],f=r[a];if(!u.alive||!f.alive||u.color!==f.color||u.texture!==f.texture)continue;let g=!!(u.texture||f.texture);if(g&&(!u.textureTriangles||!f.textureTriangles)||!!u.uvs!=!!f.uvs||(g?!uo(u,f):!lo(u,f)))continue;let m=i(u,f);if(!m)continue;let[p,d]=m,y=fo(u,f,p,d);y&&go(y.vertices,.001)&&mo(y.vertices,u.normal)&&(u.vertices=y.vertices,u.uvs=y.uvs,u.textureTriangles=g?[...u.textureTriangles??[],...f.textureTriangles??[]]:void 0,f.alive=!1,s=!0)}return s};for(;t(););for(let o of r){if(!o.alive)continue;let s={vertices:o.vertices,color:o.color};o.texture&&(s.texture=o.texture),o.uvs&&(s.uvs=o.uvs),o.textureTriangles?.length&&(s.textureTriangles=o.textureTriangles),o.data&&(s.data=o.data),n.push(s)}return n}var ho=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],yo=(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]],fe=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function bo(e,n){let r=e.vertices;if(!r||r.length<3)return null;let t=0,o=0,s=0;for(let d=0;d<r.length;d++){let y=r[d],b=r[(d+1)%r.length];t+=(y[1]-b[1])*(y[2]+b[2]),o+=(y[2]-b[2])*(y[0]+b[0]),s+=(y[0]-b[0])*(y[1]+b[1])}let i=Math.hypot(t,o,s);if(i<1e-12)return null;let l=[t/i,o/i,s/i],c=0,a=0,u=0;for(let d of r)c+=d[0],a+=d[1],u+=d[2];let f=1/r.length,g=[c*f,a*f,u*f],m=fe(l,g),p=i*.5;return{index:n,polygon:e,normal:l,d:m,centroid:g,area:p,local2D:null,bbox2D:null,basis:null}}function Po(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],r=n[0]-e[0]*fe(n,e),t=n[1]-e[1]*fe(n,e),o=n[2]-e[2]*fe(n,e),s=Math.hypot(r,t,o);r/=s,t/=s,o/=s;let i=[r,t,o],l=yo(e,i);return{u:i,v:l}}function Mo(e){if(e.local2D)return;let n=Po(e.normal),r=[],t=1/0,o=1/0,s=-1/0,i=-1/0;for(let l of e.polygon.vertices){let c=fe(l,n.u),a=fe(l,n.v);r.push([c,a]),c<t&&(t=c),c>s&&(s=c),a<o&&(o=a),a>i&&(i=a)}e.local2D=r,e.bbox2D={min:[t,o],max:[s,i]},e.basis=n}function vo(e,n){let r=[],t=1/0,o=1/0,s=-1/0,i=-1/0;for(let l of e.vertices){let c=fe(l,n.u),a=fe(l,n.v);r.push([c,a]),c<t&&(t=c),c>s&&(s=c),a<o&&(o=a),a>i&&(i=a)}return{local2D:r,bbox2D:{min:[t,o],max:[s,i]}}}function Ao(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 Tt(e,n){let r=!1;for(let t=0,o=n.length-1;t<n.length;o=t++){let s=n[t],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]&&(r=!r)}return r}function wt(e){let n=0,r=0;for(let t of e)n+=t[0],r+=t[1];return[n/e.length,r/e.length]}function Co(e,n){let r=wt(e),t=wt(n),o=1e-4,s=0;for(let a of e){let u=[a[0]+(r[0]-a[0])*o,a[1]+(r[1]-a[1])*o];Tt(u,n)&&s++}let i=0;for(let a of n){let u=[a[0]+(t[0]-a[0])*o,a[1]+(t[1]-a[1])*o];Tt(u,e)&&i++}let l=s/e.length,c=i/n.length;return Math.max(l,c)}function Vo(e,n){let r=e.normal[0],t=e.normal[1],o=e.normal[2],s=Math.abs(r),i=Math.abs(t),l=Math.abs(o),c=r;i>s&&i>l?c=t:l>s&&l>i&&(c=o),c<0&&(r=-r,t=-t,o=-o);let a=Math.round(r/.05),u=Math.round(t/.05),f=Math.round(o/.05),g=e.d*(e.normal[0]===r&&e.normal[1]===t&&e.normal[2]===o?1:-1),m=Math.round(g/(n*2));return`${a},${u},${f}|${m}`}function So(e,n,r,t){let o=fe(e.normal,n.normal);if(Math.abs(o)<1-r)return!1;let s=o>0?1:-1;return Math.abs(e.d-s*n.d)<t}function It(e,n){let r=ho(n,e.centroid);return fe(e.normal,r)>0}function Et(e,n){if(!e||e.length<2)return new Set;let r=n?.normalTolerance??.001,t=n?.distanceTolerance??.05,o=n?.overlapFraction??.7,s=[];for(let m=0;m<e.length;m++){let p=bo(e[m],m);p&&s.push(p)}if(s.length<2)return new Set;let i=0,l=0,c=0,a=0;for(let m of s)i+=m.centroid[0]*m.area,l+=m.centroid[1]*m.area,c+=m.centroid[2]*m.area,a+=m.area;let u=a>0?[i/a,l/a,c/a]:[0,0,0],f=new Map;for(let m of s){let p=Vo(m,t),d=f.get(p);d||(d=[],f.set(p,d)),d.push(m)}let g=new Set;for(let m of f.values())if(!(m.length<2))for(let p=0;p<m.length;p++){let d=m[p];if(!g.has(d.index))for(let y=p+1;y<m.length;y++){let b=m[y];if(g.has(b.index)||!So(d,b,r,t))continue;Mo(d);let M=vo(b.polygon,d.basis);if(!Ao(d.bbox2D,M.bbox2D)||Co(d.local2D,M.local2D)<o)continue;let P=It(d,u),x=It(b,u),A;if(P&&!x?A=d:x&&!P?A=b:A=d.area<b.area?d:b,g.add(A.index),A===d)break}}return g}function Ln(e,n){if(!e||e.length<2)return e??[];let r=Et(e,n);if(r.size===0)return e;let t=[];for(let o=0;o<e.length;o++)r.has(o)||t.push(e[o]);return t}var To=4,wo=8,Io=.001,Eo=1e-9,Oo=1e6,Ro=1e6,ve=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Nn=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Fe=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],Ae=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],_t=(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]],Nt=e=>Math.hypot(e[0],e[1],e[2]);function $e(e){let n=Nt(e);return n<=Eo?null:[e[0]/n,e[1]/n,e[2]/n]}function Ue(e,n){return Math.round(e*n)/n}function le(e){return Ue(e,Oo)}function kn(e){return Ue(e,Ro)}function _n(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function ge(e){return`${le(e[0])},${le(e[1])}`}function Lo(e){let n=ge(e.a),r=ge(e.b);return n<r?`${n}|${r}`:`${r}|${n}`}function Re(e){return`${e[0]},${e[1]},${e[2]}`}function Gt(e,n){let r=Re(e),t=Re(n);return r<t?`${r}|${t}`:`${t}|${r}`}function Gn(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Ot(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",Gn(e.data)].join("|")}function Dt(e){let n=e.vertices;if(!n||n.length<3)return null;let r=n[0],t=[0,0,0];for(let s=1;s<n.length-1;s++)t=Nn(t,_t(ve(n[s],r),ve(n[s+1],r)));let o=$e(t);return o?{normal:o,d:Ae(o,r)}:null}function ko(e,n,r){return Ae(e.normal,n.normal)>1-r&&Math.abs(e.d-n.d)<=r}function _o(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function No(e,n){let r=n[e[0]]?.data,t=Gn(r);for(let o of e)if(Gn(n[o].data)!==t)return;return r?{...r}:void 0}function Go(e,n){let r=e.map(c=>_o(c)?Dt(c):null),t=r.map(Boolean),o=new Map;for(let c=0;c<e.length;c++){if(!r[c])continue;let a=e[c].vertices;for(let u=0;u<a.length;u++){let f=Gt(a[u],a[(u+1)%a.length]),g=o.get(f),m={polygon:c,edge:u};g?g.push(m):o.set(f,[m])}}let s=e.map(()=>new Set);for(let c of o.values())if(!(c.length<2))for(let a=0;a<c.length;a++)for(let u=a+1;u<c.length;u++){let f=c[a].polygon,g=c[u].polygon,m=r[f],p=r[g];!m||!p||Ot(e[f])===Ot(e[g])&&ko(m,p,n)&&(s[f].add(g),s[g].add(f))}let i=new Set,l=[];for(let c=0;c<e.length;c++){if(!t[c]||i.has(c))continue;let a=[],u=[c];for(i.add(c);u.length>0;){let f=u.shift();a.push(f);for(let g of s[f])i.has(g)||(i.add(g),u.push(g))}l.push(a)}return{groups:l}}function Do(e,n){let r=new Set(e),t=new Map;for(let s of e){let i=n[s].vertices;for(let l=0;l<i.length;l++){let c=Gt(i[l],i[(l+1)%i.length]),a=t.get(c),u={polygon:s,edge:l};a?a.push(u):t.set(c,[u])}}let o=[];for(let s of t.values()){let i=s.filter(l=>r.has(l.polygon));if(i.length===1){let l=i[0],c=n[l.polygon].vertices;o.push({a:c[l.edge],b:c[(l.edge+1)%c.length]})}else if(i.length!==2)return null}return o}function zo(e){let n=new Map;for(let r of e)n.set(Re(r.a),(n.get(Re(r.a))??0)+1),n.set(Re(r.b),(n.get(Re(r.b))??0)+1);for(let r of n.values())if(r%2!==0)return!1;return!0}function zt(e){let n=[e[0],e[1],e[2]],r=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[r]<0?[-n[0],-n[1],-n[2]]:n}function Uo(e){let n=zt(e);return`${Ue(n[0],1e3)},${Ue(n[1],1e3)},${Ue(n[2],1e3)}`}function Fo(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],r=ve(n,Fe(e,Ae(n,e)));return $e(r)??[1,0,0]}function $o(e,n,r){let t=new Map;for(let s of e){let i=ve(s.b,s.a),l=ve(i,Fe(n,Ae(i,n))),c=$e(l);if(!c)continue;let a=zt(c),u=Uo(a),f=Nt(l),g=t.get(u);g?g.weight+=f:t.set(u,{axis:a,weight:f})}let o=[...t.values()].sort((s,i)=>i.weight-s.weight).slice(0,r).map(s=>s.axis);return o.length===0&&o.push(Fo(n)),o}function Rt(e,n,r,t){let o=ve(e,n);return[le(Ae(o,r)),le(Ae(o,t))]}function Bo(e){let n=[...e].sort((t,o)=>t-o),r=[];for(let t of n)(r.length===0||Math.abs(t-r[r.length-1])>1e-7)&&r.push(t);return r}function ze(e,n){let[r,t]=e.a,[o,s]=e.b,i=(n-r)/(o-r);return le(t+(s-t)*i)}function Dn(e){let n=[];for(let t of e)(n.length===0||Math.abs(t[0]-n[n.length-1][0])>1e-7||Math.abs(t[1]-n[n.length-1][1])>1e-7)&&n.push(t);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 r=[];for(let t=0;t<n.length;t++){let o=n[(t-1+n.length)%n.length],s=n[t],i=n[(t+1)%n.length],l=(s[0]-o[0])*(i[1]-s[1])-(s[1]-o[1])*(i[0]-s[0]);Math.abs(l)>1e-8&&r.push(s)}return r}function en(e){let n=0;for(let r=0;r<e.length;r++){let t=e[r],o=e[(r+1)%e.length];n+=t[0]*o[1]-o[0]*t[1]}return n/2}function Lt(e){let n=1/0,r=1/0,t=-1/0,o=-1/0;for(let[s,i]of e)n=Math.min(n,s),r=Math.min(r,i),t=Math.max(t,s),o=Math.max(o,i);return{minX:n,minY:r,maxX:t,maxY:o}}function jo(e,n){let r=Lt(e),t=Lt(n);return!(r.maxX<t.minX-1e-7||t.maxX<r.minX-1e-7||r.maxY<t.minY-1e-7||t.maxY<r.minY-1e-7)}function Je(e){return Math.abs(en(e))}function Xo(e){if(e.length<3)return!1;let n=0;for(let r=0;r<e.length;r++){let t=e[r],o=e[(r+1)%e.length],s=e[(r+2)%e.length],i=(o[0]-t[0])*(s[1]-o[1])-(o[1]-t[1])*(s[0]-o[0]);if(Math.abs(i)<=1e-8)continue;let l=i>0?1:-1;if(n===0)n=l;else if(n!==l)return!1}return!0}function Yo(e,n,r){let t=r[0]-n[0],o=r[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],l=t*i-o*s,c=Math.hypot(t,o);if(c<=1e-9||Math.abs(l)>Math.max(1e-8,c*1e-8))return!1;let a=s*t+i*o;return a>=-1e-8&&a<=t*t+o*o+1e-8}function Ho(e,n,r){let t=r[0]-n[0],o=r[1]-n[1],s=t*t+o*o;return s<=1e-12?0:((e[0]-n[0])*t+(e[1]-n[1])*o)/s}function kt(e,n){let r=[];for(let t=0;t<e.length;t++){let o=e[t],s=e[(t+1)%e.length],i=[{t:0,point:o},{t:1,point:s}];for(let c of n)_n(c,o)||_n(c,s)||Yo(c,o,s)&&i.push({t:Ho(c,o,s),point:c});i.sort((c,a)=>c.t-a.t);let l=[];for(let c of i)l.some(a=>Math.abs(a.t-c.t)<=1e-8||_n(a.point,c.point))||l.push(c);for(let c=0;c<l.length-1;c++){let a=l[c].point,u=l[c+1].point;Math.hypot(u[0]-a[0],u[1]-a[1])<=1e-8||r.push({a:[le(a[0]),le(a[1])],b:[le(u[0]),le(u[1])]})}}return r}function Ko(e,n){if(!jo(e,n))return null;let r=[...kt(e,n),...kt(n,e)],t=new Map;for(let d of r){let y=Lo(d),b=t.get(y);b?b.push(d):t.set(y,[d])}let o=!1,s=[];for(let d of t.values()){if(d.length===1){s.push(d[0]);continue}o=!0;let y=d.filter(M=>ge(M.a)<ge(M.b)).length,b=d.length-y;if(y!==b)return null}if(!o||s.length<3)return null;let i=new Map;for(let d of s){let y=ge(d.a);if(i.has(y))return null;i.set(y,d)}let l=s[0],c=ge(l.a),a=[],u=new Set,f=c;for(let d=0;d<=s.length;d++){let y=i.get(f);if(!y)return null;let b=`${ge(y.a)}>${ge(y.b)}`;if(u.has(b))return null;if(u.add(b),a.push(y.a),f=ge(y.b),f===c)break}if(f!==c||u.size!==s.length)return null;let g=Dn(a);if(g.length<3||!Xo(g))return null;let m=Je(g),p=Je(e)+Je(n);return Math.abs(m-p)>Math.max(1e-5,p*1e-5)?null:en(g)>=0?g:[...g].reverse()}function Wo(e){let n=e.map(Dn).filter(t=>t.length>=3&&Je(t)>1e-8),r=!0;for(;r;){r=!1;for(let t=0;t<n.length;t++){for(let o=t+1;o<n.length;o++){let s=Ko(n[t],n[o]);if(s){n[t]=s,n.splice(o,1),r=!0;break}}if(r)break}}return n}function Zo(e,n,r){let t=new Map;return o=>{let s=le(o[0]),i=le(o[1]),l=`${s},${i}`,c=t.get(l);if(c)return[c[0],c[1],c[2]];let a=Nn(e,Nn(Fe(n,s),Fe(r,i))),u=[kn(a[0]),kn(a[1]),kn(a[2])];return t.set(l,u),[u[0],u[1],u[2]]}}function Qo(e,n,r,t,o){let s=r[0]?.a;if(!s)return null;let i=$e(ve(o,Fe(t,Ae(o,t))));if(!i)return null;let l=$e(_t(t,i));if(!l)return null;let c=[],a=[];for(let y of r){let b=Rt(y.a,s,i,l),M=Rt(y.b,s,i,l);Math.hypot(b[0]-M[0],b[1]-M[1])<=1e-7||(c.push({a:b,b:M}),a.push(b[0],M[0]))}let u=Bo(a);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,g=No(e,n),m=[];for(let y=0;y<u.length-1;y++){let b=u[y],M=u[y+1];if(M-b<=1e-7)continue;let v=(b+M)/2,P=c.filter(x=>{let A=Math.min(x.a[0],x.b[0]),T=Math.max(x.a[0],x.b[0]);return A<v&&v<T&&Math.abs(x.a[0]-x.b[0])>1e-7}).map(x=>({segment:x,yMid:ze(x,v)})).sort((x,A)=>x.yMid-A.yMid);if(P.length!==0){if(P.length%2!==0)return null;for(let x=0;x<P.length;x+=2){let A=P[x].segment,T=P[x+1].segment,V=ze(A,b),w=ze(A,M),O=ze(T,b),L=ze(T,M),U=Dn([[b,V],[M,w],[M,L],[b,O]]);if(U.length<3||Math.abs(en(U))<=1e-8)continue;let R=en(U)>0?U:[...U].reverse();m.push(R)}}}if(m.length===0)return null;let p=Zo(s,i,l),d=Wo(m).map(y=>({vertices:y.map(p),...f?{color:f}:{},...g?{data:g}:{}}));return ce(d)}function qo(e,n,r){let t=Do(e,n);if(!t||t.length<3||!zo(t))return null;let o=Dt(n[e[0]]);if(!o)return null;let s=null;for(let i of $o(t,o.normal,r)){let l=Qo(e,n,t,o.normal,i);l&&(!s||l.length<s.length)&&(s=l)}return!s||s.length>=e.length?null:s}function zn(e,n={}){let r=n.minGroupPolygons??To,t=n.maxCandidateAxes??wo,o=n.planeEpsilon??Io,s=e??[];if(s.length<r)return s;let{groups:i}=Go(s,o);if(i.length===0)return s;let l=new Map,c=new Set;for(let u of i){if(u.length<r)continue;let f=qo(u,s,t);if(f){l.set(u[0],f);for(let g of u)c.add(g)}}if(l.size===0)return s;let a=[];for(let u=0;u<s.length;u++){let f=l.get(u);if(f){a.push(...f);continue}c.has(u)||a.push(s[u])}return a}function Jo(e){let n=e.vertices;if(!n||n.length<3)return null;let r=0,t=0,o=0;for(let[R,D,k]of n)r+=R,t+=D,o+=k;let s=1/n.length;r*=s,t*=s,o*=s;let i=n[0],l=n[1],c=n[2],a=l[0]-i[0],u=l[1]-i[1],f=l[2]-i[2],g=c[0]-i[0],m=c[1]-i[1],p=c[2]-i[2],d=u*p-f*m,y=f*g-a*p,b=a*m-u*g,M=Math.hypot(d,y,b);if(M<1e-9)return null;d/=M,y/=M,b/=M;let v=n.length-2,P=new Float64Array(v*9),x=0;for(let R=1;R<n.length-1;R++){let D=n[0],k=n[R],_=n[R+1];P[x++]=D[0],P[x++]=D[1],P[x++]=D[2],P[x++]=k[0],P[x++]=k[1],P[x++]=k[2],P[x++]=_[0],P[x++]=_[1],P[x++]=_[2]}let A=0,T=1/0,V=1/0,w=1/0,O=-1/0,L=-1/0,U=-1/0;for(let[R,D,k]of n){let _=R-r,E=D-t,C=k-o,h=_*_+E*E+C*C;h>A&&(A=h),R<T&&(T=R),R>O&&(O=R),D<V&&(V=D),D>L&&(L=D),k<w&&(w=k),k>U&&(U=k)}return{centroid:[r,t,o],normal:[d,y,b],vertices:n,triFlat:P,bcx:r,bcy:t,bcz:o,br2:A,minX:T,minY:V,minZ:w,maxX:O,maxY:L,maxZ:U}}function es(e,n,r,t,o,s,i,l){let c=i[l],a=i[l+1],u=i[l+2],f=i[l+3]-c,g=i[l+4]-a,m=i[l+5]-u,p=i[l+6]-c,d=i[l+7]-a,y=i[l+8]-u,b=o*y-s*d,M=s*p-t*y,v=t*d-o*p,P=f*b+g*M+m*v;if(P>-1e-9&&P<1e-9)return!1;let x=1/P,A=e-c,T=n-a,V=r-u,w=x*(A*b+T*M+V*v);if(w<0||w>1)return!1;let O=T*m-V*g,L=V*f-A*m,U=A*g-T*f,R=x*(t*O+o*L+s*U);return R<0||w+R>1?!1:x*(p*O+d*L+y*U)>.001}function ns(e,n,r,t,o,s,i){let l=i.bcx-e,c=i.bcy-n,a=i.bcz-r,u=l*t+c*o+a*s,f=l-u*t,g=c-u*o,m=a-u*s;if(f*f+g*g+m*m>i.br2)return!1;let p=i.triFlat,d=p.length;for(let y=0;y<d;y+=9)if(es(e,n,r,t,o,s,p,y))return!0;return!1}var Be=9,ts=6,ne=12;function Un(e,n,r,t,o,s){let i=t-e,l=o-n,c=s-r;return i*l+l*c+c*i}function rs(e){let n=[];for(let A=0;A<e.length;A++)e[A]&&n.push(A);let r=n.length,t=new Int32Array(r);for(let A=0;A<r;A++)t[A]=n[A];let o=new Float64Array(r),s=new Float64Array(r),i=new Float64Array(r);for(let A=0;A<r;A++){let T=e[t[A]];o[A]=(T.minX+T.maxX)*.5,s[A]=(T.minY+T.maxY)*.5,i[A]=(T.minZ+T.maxZ)*.5}let l=2*Math.max(1,r)+1,c=new Float64Array(l*Be),a=0,u=new Float64Array(ne),f=new Float64Array(ne),g=new Float64Array(ne),m=new Float64Array(ne),p=new Float64Array(ne),d=new Float64Array(ne),y=new Int32Array(ne),b=new Float64Array(ne-1),M=new Int32Array(ne-1),v=new Float64Array(ne-1),P=new Int32Array(ne-1);function x(A,T){let V=a++,w=V*Be,O=T-A,L=1/0,U=1/0,R=1/0,D=-1/0,k=-1/0,_=-1/0;for(let $=A;$<T;$++){let Y=e[t[$]];Y.minX<L&&(L=Y.minX),Y.maxX>D&&(D=Y.maxX),Y.minY<U&&(U=Y.minY),Y.maxY>k&&(k=Y.maxY),Y.minZ<R&&(R=Y.minZ),Y.maxZ>_&&(_=Y.maxZ)}if(c[w]=L,c[w+1]=U,c[w+2]=R,c[w+3]=D,c[w+4]=k,c[w+5]=_,O<=ts)return c[w+6]=1,c[w+7]=A,c[w+8]=T,V;let E=1/0,C=1/0,h=1/0,S=-1/0,I=-1/0,G=-1/0;for(let $=A;$<T;$++)o[$]<E&&(E=o[$]),o[$]>S&&(S=o[$]),s[$]<C&&(C=s[$]),s[$]>I&&(I=s[$]),i[$]<h&&(h=i[$]),i[$]>G&&(G=i[$]);let N=S-E,F=I-C,z=G-h;if(N===0&&F===0&&z===0)return c[w+6]=1,c[w+7]=A,c[w+8]=T,V;let X=Un(L,U,R,D,k,_),H=X>0?1/X:0,K=O+1,Z=0,J=0;for(let $=0;$<3;$++){let Y=$===0?E:$===1?C:h,se=$===0?N:$===1?F:z;if(se===0)continue;let de=$===0?o:$===1?s:i,Pe=ne/se;u.fill(1/0),f.fill(1/0),g.fill(1/0),m.fill(-1/0),p.fill(-1/0),d.fill(-1/0),y.fill(0);for(let B=A;B<T;B++){let j=(de[B]-Y)*Pe|0;j>=ne&&(j=ne-1);let ie=e[t[B]];ie.minX<u[j]&&(u[j]=ie.minX),ie.maxX>m[j]&&(m[j]=ie.maxX),ie.minY<f[j]&&(f[j]=ie.minY),ie.maxY>p[j]&&(p[j]=ie.maxY),ie.minZ<g[j]&&(g[j]=ie.minZ),ie.maxZ>d[j]&&(d[j]=ie.maxZ),y[j]++}let Te=1/0,we=1/0,hn=1/0,yn=-1/0,bn=-1/0,Pn=-1/0,ft=0;for(let B=0;B<ne-1;B++)u[B]<Te&&(Te=u[B]),m[B]>yn&&(yn=m[B]),f[B]<we&&(we=f[B]),p[B]>bn&&(bn=p[B]),g[B]<hn&&(hn=g[B]),d[B]>Pn&&(Pn=d[B]),ft+=y[B],b[B]=Un(Te,we,hn,yn,bn,Pn),M[B]=ft;let Mn=1/0,vn=1/0,An=1/0,Cn=-1/0,Vn=-1/0,Sn=-1/0,mt=0;for(let B=ne-2;B>=0;B--){let j=B+1;u[j]<Mn&&(Mn=u[j]),m[j]>Cn&&(Cn=m[j]),f[j]<vn&&(vn=f[j]),p[j]>Vn&&(Vn=p[j]),g[j]<An&&(An=g[j]),d[j]>Sn&&(Sn=d[j]),mt+=y[j],v[B]=Un(Mn,vn,An,Cn,Vn,Sn),P[B]=mt}for(let B=0;B<ne-1;B++){if(M[B]===0||P[B]===0)continue;let j=.125+(b[B]*M[B]+v[B]*P[B])*H;j<K&&(K=j,Z=$,J=Y+(B+1)/Pe)}}let oe=Z===0?o:Z===1?s:i,Q=A,q=T-1;for(;Q<=q;)if(oe[Q]<J)Q++;else{let $=t[Q];t[Q]=t[q],t[q]=$;let Y=o[Q];o[Q]=o[q],o[q]=Y;let se=s[Q];s[Q]=s[q],s[q]=se;let de=i[Q];i[Q]=i[q],i[q]=de,q--}let ae=Q;(ae===A||ae===T)&&(ae=A+T>>1),c[w+6]=0;let re=x(A,ae),W=x(ae,T);return c[V*Be+7]=re,c[V*Be+8]=W,V}return r>0&&x(0,r),{data:c,nodeCount:a,polyIndices:t,meta:e}}function Ut(e,n,r,t,o,s,i,l,c){if(l.nodeCount===0)return!1;let{data:a,polyIndices:u,meta:f}=l,g=t!==0?1/t:t>=0?1/0:-1/0,m=o!==0?1/o:o>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,d=0;for(c[d++]=0;d>0;){let b=c[--d]*Be,M=(a[b]-e)*g,v=(a[b+3]-e)*g,P=M<v?M:v,x=M<v?v:M,A=(a[b+1]-n)*m,T=(a[b+4]-n)*m,V=A<T?A:T,w=A<T?T:A;if(P>w||V>x)continue;V>P&&(P=V),w<x&&(x=w);let O=(a[b+2]-r)*p,L=(a[b+5]-r)*p,U=O<L?O:L,R=O<L?L:O;if(!(P>R||U>x)&&(R<x&&(x=R),!(x<.001)))if(a[b+6]===1){let D=a[b+7]|0,k=a[b+8]|0;for(let _=D;_<k;_++){let E=u[_];if(E===i)continue;let C=f[E];if(C&&ns(e,n,r,t,o,s,C))return!0}}else c[d++]=a[b+7]|0,c[d++]=a[b+8]|0}return!1}function os(e){let n=(1+Math.sqrt(5))/2,r=new Float64Array(e*3);for(let t=0;t<e;t++){let o=(t+.5)/e,s=Math.sqrt(Math.max(0,1-o*o)),i=2*Math.PI*(t/n);r[t*3]=s*Math.cos(i),r[t*3+1]=s*Math.sin(i),r[t*3+2]=o}return r}function ss(e){let n=Math.abs(e[0])>.9?0:1,r=Math.abs(e[0])>.9?1:0,t=r*e[2],o=-n*e[2],s=n*e[1]-r*e[0],i=Math.hypot(t,o,s);t/=i,o/=i,s/=i;let l=e[1]*s-e[2]*o,c=e[2]*t-e[0]*s,a=e[0]*o-e[1]*t;return{ux:t,uy:o,uz:s,vx:l,vy:c,vz:a}}function Ce(e,n){let r=n?.samples??8;if(e.length<4||r<1)return e;let t=e.map(Jo),o=os(r),s=[],i=rs(t),l=new Int32Array(Math.max(64,i.nodeCount)),c=192,a=new Float64Array(c);for(let u=0;u<e.length;u++){let f=t[u];if(!f){s.push(e[u]);continue}let g=f.normal[0],m=f.normal[1],p=f.normal[2],d=.001*g,y=.001*m,b=.001*p;{let k=f.centroid[0]+d,_=f.centroid[1]+y,E=f.centroid[2]+b;if(!Ut(k,_,E,g,m,p,u,i,l)){s.push(e[u]);continue}}let{ux:M,uy:v,uz:P,vx:x,vy:A,vz:T}=ss(f.normal),V=f.centroid[0],w=f.centroid[1],O=f.centroid[2],L=f.vertices,U=L.length,R=0;a[R++]=V+d,a[R++]=w+y,a[R++]=O+b;for(let k=0;k<U;k++){let _=L[k];a[R++]=_[0]+(V-_[0])*.08+d,a[R++]=_[1]+(w-_[1])*.08+y,a[R++]=_[2]+(O-_[2])*.08+b}for(let k=0;k<U;k++){let _=L[k],E=L[(k+1)%U],C=(_[0]+E[0])*.5,h=(_[1]+E[1])*.5,S=(_[2]+E[2])*.5;a[R++]=C+(V-C)*.08+d,a[R++]=h+(w-h)*.08+y,a[R++]=S+(O-S)*.08+b}let D=!1;e:for(let k=0;k<o.length;k+=3){let _=o[k],E=o[k+1],C=o[k+2],h=_*M+E*x+C*g,S=_*v+E*A+C*m,I=_*P+E*T+C*p;for(let G=0;G<R;G+=3){let N=a[G],F=a[G+1],z=a[G+2];if(!Ut(N,F,z,h,S,I,u,i,l)){D=!0;break e}}}D&&s.push(e[u])}return s}var is=3,cs=.03,as=.02,je={maxAngleDeg:is,maxPlaneDisplacement:cs,maxBoundaryDisplacement:as,isolatedPairs:!1},Le={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725,isolatedPairs:!0},tn=[{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.02},{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725},{maxAngleDeg:45,maxPlaneDisplacement:1,maxBoundaryDisplacement:.0725}],ls=[2,4,6,8,12],us=300,fs=.3,ms=300,gs=16,ps=.015,Ft=2.6,ds=3,xs=96,Ve={minGroupPolygons:2,maxCandidateAxes:24},hs={maxGap:0,internalBoundaryLength:0,excessBoundaryLength:0};function Xn(e,n={}){let r=n.meshResolution??"lossy",t=Fn(e,!1),o={baseline:t},s=t,i=te(t),l=(a,u=te(a))=>u>=i?!1:(s=a,i=u,!0),c=nn(t,n.rectCover);if(c!==t&&l(c),r==="lossy"&&n.approximateMerge!==!1){let a=Is(e),u=[],f=me(a,s,Le.maxBoundaryDisplacement).metrics,g=n.approximateMerge===void 0||n.approximateMerge===!0,m=(M,v=!0)=>!Ts(a,M.metrics,M.tolerance,v?f:null),p=(M,v)=>{l(M,v)},d=(M,v,P=Le.maxBoundaryDisplacement)=>{!g||v>i+Yt(i)||u.push({polygons:M,cost:v,maxBoundaryDisplacement:P})},y=$t(n.approximateMerge,g?t:void 0);for(let M=0;M<y.length;M++){let v=y[M],P=Fn(e,v,o),x=te(P),A=null,T=()=>(A??(A=me(a,P,v.maxBoundaryDisplacement)),A),V=!0;if(g||v.guard){let R=T();V=m(R,!!v.allowReferenceCracks)}if(!V&&x<i)continue;V&&(p(P,x),d(P,x,v.maxBoundaryDisplacement));let w=nn(P,n.rectCover),O=te(w),L=null,U=()=>(L??(L=me(a,w,v.maxBoundaryDisplacement)),L);if(w!==P&&O<i){let R=!0;(g||v.guard)&&(R=m(U(),!!v.allowReferenceCracks)),R&&(p(w,O),d(w,O,v.maxBoundaryDisplacement))}}if(g)for(let M of ys(e)){let v={baseline:ce(Ce(M))},P=te(v.baseline),x=!0,A=null,T=()=>(A??(A=me(a,v.baseline,Le.maxBoundaryDisplacement)),A);P<i&&(x=m(T())),x&&(p(v.baseline,P),d(v.baseline,P));let V=nn(v.baseline,n.rectCover);if(V!==v.baseline){let w=te(V);(w>=i||m(me(a,V,Le.maxBoundaryDisplacement)))&&(p(V,w),d(V,w))}for(let w of $t(n.approximateMerge,v.baseline)){let O=Fn(M,w,v),L=te(O),U=null,R=()=>(U??(U=me(a,O,w.maxBoundaryDisplacement)),U),D=!0;if(g||w.guard){let h=R();D=m(h,!!w.allowReferenceCracks)}if(!D&&L<i)continue;D&&(p(O,L),d(O,L,w.maxBoundaryDisplacement));let k=nn(O,n.rectCover),_=te(k),E=null,C=()=>(E??(E=me(a,k,w.maxBoundaryDisplacement)),E);if(k!==O&&_<i){let h=!0;(g||w.guard)&&(h=m(C(),!!w.allowReferenceCracks)),h&&(p(k,_),d(k,_,w.maxBoundaryDisplacement))}}}if(g)for(let M of tn){let v=qt({...M,isolatedPairs:!0}),P=$s(s,v);if(P===s)continue;let x=te(P);if(x>=i)continue;let A=me(a,P,v.maxBoundaryDisplacement);m(A)&&(p(P,x),d(P,x,v.maxBoundaryDisplacement))}let b=Cs(u,s,i,M=>(M.metrics??(M.metrics=me(a,M.polygons,M.maxBoundaryDisplacement).metrics),M.metrics),()=>me(a,s,Le.maxBoundaryDisplacement).metrics);b&&(s=b.polygons,i=b.cost)}return s}function ys(e){let n=bs(e);if(n.eligiblePolygons<24||n.colorCount<8)return[];let r=[],t=new Set;for(let o of ls){let s=Ps(e,o,n.colorCount);if(!s)continue;let i=vs(s);t.has(i)||(t.add(i),r.push(s))}return r}function bs(e){let n=new Set,r=0;for(let t of e)t.texture||t.material?.texture||t.uvs||t.textureTriangles?.length||Xt(t.color)&&(r+=1,n.add(t.color??"#cccccc"));return{eligiblePolygons:r,colorCount:n.size}}function Ps(e,n,r){let t=!1,o=new Set,s=e.map(i=>{if(i.texture||i.material?.texture||i.uvs||i.textureTriangles?.length)return i;let l=Xt(i.color);if(!l)return i;let c=Ms([Math.round(l[0]/n)*n,Math.round(l[1]/n)*n,Math.round(l[2]/n)*n]);return o.add(c),c===i.color?i:(t=!0,{...i,color:c})});return!t||o.size>=r?null:s}function Xt(e){let n=e??"#cccccc",r=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(n);if(r)return[parseInt(r[1]+r[1],16),parseInt(r[2]+r[2],16),parseInt(r[3]+r[3],16)];let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(n);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null}function Ms(e){return`#${e.map(n=>Math.max(0,Math.min(255,Math.round(n))).toString(16).padStart(2,"0")).join("")}`}function vs(e){return e.map(n=>n.color??"").join("|")}function $t(e,n){if(e&&e!==!0)return typeof e.isolatedPairs=="boolean"?[{...e,guard:e.isolatedPairs===!1}]:[{...e,isolatedPairs:!0,guard:!1},{...e,isolatedPairs:!1,guard:!0}];if(n&&As(n))return[{...tn[0],isolatedPairs:!0,guard:!1,allowReferenceCracks:!0}];let r=[],t=new Set,o=n&&n.length>ms?[!0]:[!0,!1];for(let s=0;s<tn.length;s++){let i=tn[s];for(let l of o){let c={...i,isolatedPairs:l,guard:s>0||l===!1,allowReferenceCracks:!0},a=[c.maxAngleDeg,c.maxPlaneDisplacement,c.maxBoundaryDisplacement,c.isolatedPairs].join("|");t.has(a)||(t.add(a),r.push(c))}}return r.length===0?[{...Le,guard:!1}]:r}function As(e){return e.length<us?!1:Zt(e)/e.length<=fs}function te(e){let n=0;for(let r of e){let t=r.vertices.length,o=t<=4?0:Math.min(4,t-4)*.12,s=r.texture||r.material?.texture||r.textureTriangles?.length?.15:0;n+=1+o+s}return n}function Yt(e){return Math.max(gs,e*ps)}function Cs(e,n,r,t,o){if(e.length===0)return null;let s=Yt(r),i=e.find(u=>u.polygons===n),l=null,c=null,a=null;for(let u of e){if(u.polygons===n||u.cost>r+s)continue;let f=t(u);l??(l=i?t(i):o()),Ss(f,l)&&(!c||!a||Vs(u,f,c,a)<0)&&(c=u,a=f)}return c}function Vs(e,n,r,t){return n.maxGap-t.maxGap||n.internalBoundaryLength-t.internalBoundaryLength||n.excessBoundaryLength-t.excessBoundaryLength||e.cost-r.cost}function Ss(e,n){let r=Math.max(5e-4,n.maxGap*.02);if(e.maxGap<n.maxGap-r)return!0;if(e.maxGap>n.maxGap+r)return!1;let t=Math.max(8,n.internalBoundaryLength*.01);if(e.internalBoundaryLength<n.internalBoundaryLength-t)return!0;if(e.internalBoundaryLength>n.internalBoundaryLength+t)return!1;let o=Math.max(8,n.excessBoundaryLength*.01);return e.excessBoundaryLength<n.excessBoundaryLength-o}function Ts(e,n,r,t=null){if(!t)return n.internalBoundaryLength>0||n.excessBoundaryLength>r;let o=Math.max(r*.1,1e-6),s=t.maxGap+o,i=r<=.08?Math.max(s,Math.min(r*.75,.04)):s,l=Math.max(r*2,t.internalBoundaryLength*.15),c=Math.max(r*2,t.excessBoundaryLength*.15);return n.maxGap>i||n.internalBoundaryLength>t.internalBoundaryLength+l||n.excessBoundaryLength>t.excessBoundaryLength+c}function ws(e,n,r=0,t=Bn(e,r)){let o=e.edges,s=Ht(n),i=Bn(e,r),l=t>0?Os(e,t):null,c={...hs,excessBoundaryLength:Math.max(0,s.boundaryLength-o.boundaryLength)};for(let a of s.boundarySegments){let u=ke(a.a,a.b);if(o.boundaryKeys.has(u))continue;if(o.internalKeys.has(u)){c.internalBoundaryLength+=pe(a.a,a.b);continue}let f=l?ks(a,l,t):null;f!==null&&(c.maxGap=Math.max(c.maxGap,f),c.internalBoundaryLength+=pe(a.a,a.b))}return{metrics:c,tolerance:i}}function me(e,n,r=0){return ws(e,n,r,Es(e,r))}function Is(e){let n=Rs(e),r=n>0?Math.min(.08,Math.max(.001,n*.001)):0;return{edges:Ht(e),baseTolerance:r,polygonCount:e.length,indexes:new Map}}function Bn(e,n=0){return Math.max(e.baseTolerance,n*1.05)}function Es(e,n=0){return Math.max(Bn(e,n),e.baseTolerance*Ft,n*Ft)}function Os(e,n){let r=n.toFixed(6),t=e.indexes.get(r);if(t)return t;let o=Ls(e.edges.internalSegments,n);return e.indexes.set(r,o),o}function Ht(e){let n=new Map;for(let l of e)for(let c=0;c<l.vertices.length;c++){let a=l.vertices[c],u=l.vertices[(c+1)%l.vertices.length],f=ke(a,u),g=n.get(f);g?g.count+=1:n.set(f,{count:1,a,b:u})}let r=new Set,t=new Set,o=[],s=[],i=0;for(let[l,c]of n){let a={a:c.a,b:c.b};c.count===1?(r.add(l),o.push(a),i+=pe(a.a,a.b)):(t.add(l),s.push(a))}return{boundaryKeys:r,internalKeys:t,boundarySegments:o,internalSegments:s,boundaryLength:i}}function Rs(e){let n=1/0,r=1/0,t=1/0,o=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let[c,a,u]of l.vertices)n=Math.min(n,c),r=Math.min(r,a),t=Math.min(t,u),o=Math.max(o,c),s=Math.max(s,a),i=Math.max(i,u);return Number.isFinite(n)?Math.hypot(o-n,s-r,i-t):0}function Ls(e,n){let r=Math.max(n*2,1e-6),t=new Map;for(let o of e){let[s,i,l]=Kt(o,r),c=Wt(s,i,l),a=t.get(c);a?a.push(o):t.set(c,[o])}return{cellSize:r,cells:t}}function ks(e,n,r){let[t,o,s]=Kt(e,n.cellSize),i=null;for(let l=-1;l<=1;l++)for(let c=-1;c<=1;c++)for(let a=-1;a<=1;a++){let u=n.cells.get(Wt(t+l,o+c,s+a));if(u)for(let f of u){let g=_s(e,f);g<=r&&(i=i===null?g:Math.min(i,g))}}return i}function Kt(e,n){return[Math.floor((e.a[0]+e.b[0])/2/n),Math.floor((e.a[1]+e.b[1])/2/n),Math.floor((e.a[2]+e.b[2])/2/n)]}function Wt(e,n,r){return`${e},${n},${r}`}function _s(e,n){return Math.min(Math.max(pe(e.a,n.a),pe(e.b,n.b)),Math.max(pe(e.a,n.b),pe(e.b,n.a)))}function nn(e,n){if(n===!1)return e;let r=Ns(e,n);if(!r)return e;let t=zn(e,r);return t.length<e.length?t:e}function Ns(e,n){if(n&&n!==!0)return n;let r=e.length;return r>2200?null:r>1200?{...Ve,maxCandidateAxes:Math.min(Ve.maxCandidateAxes??24,2)}:r>300&&Zt(e)<=xs?{...Ve,maxCandidateAxes:Math.min(Ve.maxCandidateAxes??24,2)}:r>900?{...Ve,maxCandidateAxes:Math.min(Ve.maxCandidateAxes??24,4)}:Ve}function Zt(e){let n=0;for(let r of e)r.vertices.length===3&&(n+=1);return n}function Fn(e,n,r){let t=Ln(e),o=r?.baseline??ce(Ce(t));if(!n)return o;let s=n===!0?je:qt(n);if(s.isolatedPairs){let l=Ds(Gs(t,r),s),c=ce(l);return c.length<o.length?c:o}let i=ce(Ce(qs(t,s,r)));return i.length<o.length?i:o}function Qt(e,n){return n?(n.snapped||(n.snapped=on(e)),n.snapped):on(e)}function Gs(e,n){return n?(n.snappedInterior||(n.snappedInterior=Ce(Qt(e,n))),n.snappedInterior):Ce(on(e))}function qt(e){return{maxAngleDeg:e.maxAngleDeg??je.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??je.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??je.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??je.isolatedPairs}}function Ds(e,n){let r=e.map(f=>{let g=Ye(f);return g?{polygon:f,normal:g.normal,area:g.area,materialKey:Hn(f)}:null}),t=new Map;for(let f=0;f<e.length;f++){let g=e[f];if(!(g.vertices.length!==3||!r[f]))for(let m=0;m<g.vertices.length;m++){let p=ke(g.vertices[m],g.vertices[(m+1)%g.vertices.length]),d=t.get(p);d?d.push(f):t.set(p,[f])}}let o=[];for(let f of t.values()){if(f.length!==2)continue;let[g,m]=f,p=Qs(g,m,e,r,n);p&&o.push(p)}let s=new Set,i=new Map,l=new Set,c=zs(o),a=an(c.flatMap(f=>f.vertexMoves));for(let f of c){s.add(f.a),s.add(f.b);let g=Math.min(f.a,f.b);i.set(g,f.polygon),l.add(Math.max(f.a,f.b))}let u=[];for(let f=0;f<e.length;f++){let g=i.get(f);if(g){u.push(g);continue}l.has(f)||u.push(e[f])}return a.size>0?ln(u,a):u}function zs(e){return e.length>3e3?Us(e):Fs(e)}function Us(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 r=[...e].sort((s,i)=>{let l=(n.get(s.a)??0)+(n.get(s.b)??0),c=(n.get(i.a)??0)+(n.get(i.b)??0);return l-c||s.score-i.score}),t=new Set,o=[];for(let s of r)t.has(s.a)||t.has(s.b)||(t.add(s.a),t.add(s.b),o.push(s));return o}function Fs(e){let n=new Map;for(let a=0;a<e.length;a++){let u=e[a],f=n.get(u.a);f?f.push(a):n.set(u.a,[a]);let g=n.get(u.b);g?g.push(a):n.set(u.b,[a])}let r=[],t=new Array(e.length).fill(!0),o=new Map,s=new jn;for(let[a,u]of n)o.set(a,u.length);let i=a=>(o.get(a.a)??0)+(o.get(a.b)??0),l=a=>{let u=e[a];s.push({degree:i(u),score:u.score,index:a})},c=(a,u)=>{if(!t[a])return;t[a]=!1;let f=e[a];for(let g of[f.a,f.b])o.set(g,(o.get(g)??0)-1),u.add(g)};for(let a=0;a<e.length;a++)l(a);for(;s.size()>0;){let a=s.pop();if(!t[a.index])continue;let u=e[a.index];if(i(u)!==a.degree){l(a.index);continue}r.push(u);let g=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])c(p,g);for(let m of g)for(let p of n.get(m)??[])t[p]&&l(p)}return r}var jn=class{constructor(){this.items=[]}size(){return this.items.length}push(n){this.items.push(n);let r=this.items.length-1;for(;r>0;){let t=r-1>>1;if($n(this.items[t],this.items[r])<=0)break;[this.items[t],this.items[r]]=[this.items[r],this.items[t]],r=t}}pop(){if(this.items.length===0)return null;let n=this.items[0],r=this.items.pop();if(this.items.length>0){this.items[0]=r;let t=0;for(;;){let o=t*2+1,s=o+1,i=t;if(o<this.items.length&&$n(this.items[o],this.items[i])<0&&(i=o),s<this.items.length&&$n(this.items[s],this.items[i])<0&&(i=s),i===t)break;[this.items[t],this.items[i]]=[this.items[i],this.items[t]],t=i}}return n}};function $n(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function $s(e,n){let r=e,t=te(r),o=Ys(r);for(let s=0;s<ds;s++){let i=Bs(r,n,o);if(!i)break;let l=te(i.polygons);if(l>=t)break;r=i.polygons,t=l,o=i.origins}return r===e?e:r}function Bs(e,n,r){let t=e.map(g=>{let m=Ye(g);return m?{polygon:g,normal:m.normal,area:m.area,materialKey:Hn(g)}:null}),o=new Map;for(let g=0;g<e.length;g++){let m=e[g];if(!(!t[g]||m.vertices.length<3))for(let p=0;p<m.vertices.length;p++){let d=ke(m.vertices[p],m.vertices[(p+1)%m.vertices.length]),y=o.get(d);y?y.push({polygon:g,edge:p}):o.set(d,[{polygon:g,edge:p}])}}let s=[];for(let g of o.values()){if(g.length!==2)continue;let[m,p]=g,d=js(m.polygon,m.edge,p.polygon,p.edge,e,t,n);d&&s.push(d)}if(s.length===0)return null;s.sort((g,m)=>m.score-g.score);let i=new Set,l=[];for(let g of s)i.has(g.a)||i.has(g.b)||(i.add(g.a),i.add(g.b),l.push(g));if(l.length===0)return null;let c=an(l.flatMap(g=>g.vertexMoves));if(!Xs(c,r,n.maxBoundaryDisplacement))return null;let a=ln(e,c),u=Hs(e,c,r),f=ce(a);return te(f)<te(e)?{polygons:f,origins:Ks(f,u)}:null}function js(e,n,r,t,o,s,i){let l=o[e],c=o[r],a=s[e],u=s[r];if(!a||!u||l.vertices.length===3&&c.vertices.length===3||!sr(l,c,a,u))return null;let f=Math.abs(ue(a.normal,u.normal)),g=Math.cos(i.maxAngleDeg*Math.PI/180);if(f<g)return null;let m=Bt(l,c,n)??Bt(c,l,t);if(!m||m.length<4||m.length>10)return null;let p=er(m);if(!p)return null;let d=0,y=0;for(let V of m){let w=Math.abs(un(V,p));d=Math.max(d,w),y+=w*w}if(d>Math.min(i.maxPlaneDisplacement,i.maxBoundaryDisplacement))return null;let b=m.map(V=>fn(V,p));if(!nr(b,p.normal))return null;let M=Ye({vertices:b});if(!M||ue(M.normal,a.normal)<.2||ue(M.normal,u.normal)<.2)return null;let v=[...m.map((V,w)=>({key:ee(V),target:b[w]})),...Jt([l,c],p)],P=ln([l,c],an(v)),x=te([l,c]),A=te(ce(P));if(A>=x)return null;let T=x-A-(y/m.length+d*.25+(1-f)*.1);return T<=0?null:{a:e,b:r,vertexMoves:v,score:T}}function Bt(e,n,r){let t=e.vertices,o=n.vertices,s=t[r],i=t[(r+1)%t.length],l=-1;for(let u=0;u<o.length;u++)if(ye(o[u],i)&&ye(o[(u+1)%o.length],s)){l=u;break}if(l<0)return null;let c=[],a=(r+1)%t.length;for(c.push(t[a]);a!==r;)a=(a+1)%t.length,c.push(t[a]);for(a=(l+2)%o.length;a!==l;){let u=o[a];ye(u,c[c.length-1])||c.push(u),a=(a+1)%o.length}return c.length>1&&ye(c[0],c[c.length-1])&&c.pop(),c}function Xs(e,n,r){for(let[t,o]of e){let s=Ws(t),i=n.get(t)??(s?[s]:[]);if(i.length===0)return!1;for(let l of i)if(pe(l,o)>r+1e-6)return!1}return!0}function Ys(e){let n=new Map;for(let r of e){for(let t of r.vertices)rn(n,ee(t),t);for(let t of r.textureTriangles??[])for(let o of t.vertices)rn(n,ee(o),o)}return n}function Hs(e,n,r){let t=new Map;for(let o of e){let s=[...o.vertices,...(o.textureTriangles??[]).flatMap(i=>i.vertices)];for(let i of s){let l=ee(i),c=n.get(l)??i,a=ee(c);for(let u of r.get(l)??[i])rn(t,a,u)}}return t}function Ks(e,n){let r=new Map;for(let t of e){let o=[...t.vertices,...(t.textureTriangles??[]).flatMap(s=>s.vertices)];for(let s of o){let i=ee(s);for(let l of n.get(i)??[s])rn(r,i,l)}}return r}function rn(e,n,r){let t=e.get(n);if(!t){e.set(n,[r]);return}let o=ee(r);t.some(s=>ee(s)===o)||t.push(r)}function Ws(e){let n=e.split(",").map(Number);return n.length===3&&n.every(Number.isFinite)?[n[0],n[1],n[2]]:null}function an(e){let n=new Map;for(let t of e){let o=n.get(t.key);o?(o.x+=t.target[0],o.y+=t.target[1],o.z+=t.target[2],o.count+=1):n.set(t.key,{x:t.target[0],y:t.target[1],z:t.target[2],count:1})}let r=new Map;for(let[t,o]of n)r.set(t,[o.x/o.count,o.y/o.count,o.z/o.count]);return r}function Zs(e,n){let r=[];for(let t=0;t<e.length;t++){let o=e[t].vertices,s=n[t]?.vertices;if(!s||s.length!==o.length)continue;for(let c=0;c<o.length;c++)r.push({key:ee(o[c]),target:s[c]});let i=e[t].textureTriangles??[],l=n[t]?.textureTriangles??[];for(let c=0;c<i.length;c++){let a=l[c];if(a)for(let u=0;u<i[c].vertices.length;u++)r.push({key:ee(i[c].vertices[u]),target:a.vertices[u]})}}return r}function Jt(e,n){let r=[];for(let t of e)for(let o of t.textureTriangles??[])for(let s of o.vertices)r.push({key:ee(s),target:fn(s,n)});return r}function ln(e,n){return e.map(r=>{let t=!1,o=l=>{let c=n.get(ee(l));return c?(t=!0,c):l},s=r.vertices.map(o),i=Yn(r.textureTriangles,o);return t?{...r,vertices:s,...i?{textureTriangles:i}:{}}:r})}function Qs(e,n,r,t,o){let s=r[e],i=r[n],l=t[e],c=t[n];if(!l||!c||s.vertices.length!==3||i.vertices.length!==3||!sr(s,i,l,c))return null;let a=Wn(s,i);if(!a)return null;let[u,f,g,m]=a;if((g+1)%i.vertices.length===m)return null;let d=Math.abs(ue(l.normal,c.normal)),y=Math.cos(o.maxAngleDeg*Math.PI/180);if(d<y)return null;let b=(f+1)%s.vertices.length,M=3-g-m,v=[s.vertices[f],s.vertices[b],s.vertices[u],i.vertices[M]],P=er(v);if(!P)return null;let x=0,A=0;for(let O of v){let L=Math.abs(un(O,P));x=Math.max(x,L),A+=L*L}if(x>Math.min(o.maxPlaneDisplacement,o.maxBoundaryDisplacement))return null;let T=v.map(O=>fn(O,P));if(!nr(T,P.normal))return null;let V=Ye({vertices:T});if(!V||ue(V.normal,l.normal)<.2||ue(V.normal,c.normal)<.2)return null;let w={vertices:v,color:s.color,...s.data?{data:{...s.data}}:{}};if(Kn(s,i)&&s.uvs&&i.uvs&&s.texture){w.texture=s.texture,w.uvs=[[...s.uvs[f]],[...s.uvs[b]],[...s.uvs[u]],[...i.uvs[M]]];let O=Js([s,i]);O?.length&&(w.textureTriangles=O)}return{a:e,b:n,polygon:w,vertexMoves:[...v.map((O,L)=>({key:ee(O),target:T[L]})),...Jt([s,i],P)],score:A/v.length+x*.25+(1-d)*.1}}function er(e){if(e.length<3)return null;let n=0,r=0,t=0,o=0,s=0,i=0;for(let c=0;c<e.length;c++){let a=e[c],u=e[(c+1)%e.length];n+=(a[1]-u[1])*(a[2]+u[2]),r+=(a[2]-u[2])*(a[0]+u[0]),t+=(a[0]-u[0])*(a[1]+u[1]),o+=a[0],s+=a[1],i+=a[2]}let l=ur([n,r,t]);return l?{normal:l,point:[o/e.length,s/e.length,i/e.length]}:null}function nr(e,n){let r=0;for(let t=0;t<e.length;t++){let o=e[t],s=e[(t+1)%e.length],i=e[(t+2)%e.length],l=ue(lr(Xe(s,o),Xe(i,s)),n);if(Math.abs(l)<=1e-9)continue;let c=l>0?1:-1;if(r===0)r=c;else if(r!==c)return!1}return!0}function qs(e,n,r){let t=Qt(e,r),o=si(t,n);if(o<=0)return t;let s=t.map(m=>{let p=Ye(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Hn(m)}:null}),i=ai(t,s),l=new Set,c=Array(t.length),a=[],u=(m,p)=>{c[m]=p};for(let m=0;m<t.length;m++){let p=s[m];if(l.has(m))continue;if(!p){u(m,t[m]);continue}let d=ui(m,s,i,l,o,n);for(let b of d)l.add(b);if(d.length<2){u(m,t[m]);continue}let y=ti(d,t,s,i,o,n);a.push(...y.vertexMoves);for(let b of d)u(b,y.polygons.get(b)??t[b])}let f=c.flatMap(m=>m?[m]:[]),g=a.length>0?ln(f,an(a)):f;return on(g)}function on(e){let n=or(e),r=1e-4;if(n<=0)return e;let t=ii(n),o=ci(r);return e.map(s=>{let i=f=>t.snap(f),l=s.vertices.map(i),c=s.uvs&&s.uvs.length===s.vertices.length?s.uvs.map(f=>o.snap(f)):void 0,a=Yn(s.textureTriangles,i),u={...s,vertices:l,...c?{uvs:c}:{},...a?{textureTriangles:a}:{}};return{...u,...u.texture?{textureTriangles:tr(u)}:{}}})}function tr(e){if(e.texture){if(e.textureTriangles?.length)return ni(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return ei(e.vertices,e.uvs)}}function Js(e){let n=e.flatMap(r=>tr(r)??[]);return n.length>0?n:void 0}function ei(e,n){let r=[];for(let t=1;t<e.length-1;t++)r.push({vertices:[[...e[0]],[...e[t]],[...e[t+1]]],uvs:[[...n[0]],[...n[t]],[...n[t+1]]]});return r}function ni(e){return e.map(n=>({vertices:n.vertices.map(r=>[...r]),uvs:n.uvs.map(r=>[...r])}))}function Yn(e,n){if(e?.length)return e.map(r=>({vertices:r.vertices.map(n),uvs:r.uvs.map(t=>[...t])}))}function ti(e,n,r,t,o,s){let i=rr(e,n,r,o,s);return i?oi(i):ri(e,n,r,t,o,s)}function ri(e,n,r,t,o,s){let i=new Set(e),l=[];for(let f of e)for(let g of t.get(f)??[]){if(f>=g||!i.has(g))continue;let m=rr([f,g],n,r,o,s);m&&l.push(m)}l.sort((f,g)=>g.score-f.score);let c=new Set,a=new Map,u=[];for(let f of l)if(!f.indices.some(g=>c.has(g))){u.push(...f.vertexMoves);for(let g=0;g<f.indices.length;g++){let m=f.indices[g];c.add(m),a.set(m,n[m])}}return{polygons:a,vertexMoves:u}}function oi(e){let n=new Map;for(let r=0;r<e.indices.length;r++)n.set(e.indices[r],e.source[r]);return{polygons:n,vertexMoves:e.vertexMoves}}function rr(e,n,r,t,o){let s=ir(e,r);if(!s||!cr(e,r,s,t,o))return null;let i=e.map(u=>n[u]),l=i.map(u=>gi(u,s)),c=te(ce(i)),a=te(ce(l));return a>=c?null:{indices:e,source:i,projected:l,vertexMoves:Zs(i,l),score:c-a}}function si(e,n){return or(e)<=0?0:n.maxPlaneDisplacement}function or(e){let n=1/0,r=1/0,t=1/0,o=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let[a,u,f]of c.vertices)n=Math.min(n,a),r=Math.min(r,u),t=Math.min(t,f),o=Math.max(o,a),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let l=Math.hypot(o-n,s-r,i-t);return l<=0?0:Math.min(.025,Math.max(1e-4,l*25e-5))}function ii(e){let n=new Map,r=o=>Math.floor(o/e),t=(o,s,i)=>`${o},${s},${i}`;return{snap(o){let s=r(o[0]),i=r(o[1]),l=r(o[2]);for(let f=-1;f<=1;f++)for(let g=-1;g<=1;g++)for(let m=-1;m<=1;m++){let p=n.get(t(s+f,i+g,l+m));if(p){for(let d of p)if(pe(o,d)<=e)return[d[0],d[1],d[2]]}}let c=[o[0],o[1],o[2]],a=t(s,i,l),u=n.get(a);return u?u.push(c):n.set(a,[c]),c}}}function ci(e){let n=new Map,r=o=>Math.floor(o/e),t=(o,s)=>`${o},${s}`;return{snap(o){let s=r(o[0]),i=r(o[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let g=n.get(t(s+u,i+f));if(g){for(let m of g)if(Math.hypot(o[0]-m[0],o[1]-m[1])<=e)return[m[0],m[1]]}}let l=[o[0],o[1]],c=t(s,i),a=n.get(c);return a?a.push(l):n.set(c,[l]),l}}}function Hn(e){return`${e.color??"#cccccc"}|${e.texture??""}|${e.uvs?"uv":"plain"}`}function Ye(e){let n=e.vertices;if(!n||n.length<3)return null;let r=0,t=0,o=0,s=n[0];for(let l=1;l<n.length-1;l++){let c=Xe(n[l],s),a=Xe(n[l+1],s),u=lr(c,a);r+=u[0],t+=u[1],o+=u[2]}let i=Math.hypot(r,t,o);return i<=1e-10?null:{normal:[r/i,t/i,o/i],area:i/2}}function ai(e,n){let r=new Map,t=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 l=ke(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),c=r.get(l);c?c.push(o):r.set(l,[o])}}for(let o of r.values())for(let s=0;s<o.length;s++)for(let i=s+1;i<o.length;i++){let l=o[s],c=o[i];li(e[l],e[c],n[l],n[c])&&(jt(t,l,c),jt(t,c,l))}return t}function li(e,n,r,t){if(!r||!t||r.materialKey!==t.materialKey||!!e.uvs!=!!n.uvs)return!1;if(sn(e)||sn(n))return Kn(e,n);if(!e.uvs||!n.uvs)return!0;let o=Wn(e,n);if(!o)return!1;let[s,i,l,c]=o;return cn(e.uvs[s],n.uvs[l])&&cn(e.uvs[i],n.uvs[c])}function sr(e,n,r,t){return r.materialKey!==t.materialKey?!1:sn(e)||sn(n)?Kn(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function sn(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Kn(e,n){if(!e.texture||!n.texture||e.texture!==n.texture||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 r=Wn(e,n);if(!r)return!1;let[t,o,s,i]=r;return cn(e.uvs[t],n.uvs[s])&&cn(e.uvs[o],n.uvs[i])}function jt(e,n,r){let t=e.get(n);t?t.add(r):e.set(n,new Set([r]))}function ui(e,n,r,t,o,s){let i=[e],l=new Set([e]),c=[e];for(;c.length>0;){let a=c.shift();for(let u of r.get(a)??[]){if(t.has(u)||l.has(u))continue;let f=n[u],g=n[e];!f||!g||f.materialKey===g.materialKey&&fi([...i,u],n,o,s)&&(i.push(u),l.add(u),c.push(u))}}return i}function fi(e,n,r,t){let o=ir(e,n);return!!o&&cr(e,n,o,r,t)}function ir(e,n){let r=n[e[0]];if(!r)return null;let t=0,o=0,s=0,i=0,l=0,c=0,a=0;for(let m of e){let p=n[m];if(!p)return null;let d=ue(r.normal,p.normal)<0?-1:1,y=Math.max(p.area,1e-6);t+=p.normal[0]*d*y,o+=p.normal[1]*d*y,s+=p.normal[2]*d*y;for(let b of p.polygon.vertices)i+=b[0],l+=b[1],c+=b[2],a+=1}let u=ur([t,o,s]);if(!u||a===0)return null;let f=ar(e,n),g=mi(e,n,u,f);if(g){let m=(g.min+g.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m]}}return{normal:u,point:[i/a,l/a,c/a]}}function mi(e,n,r,t){let o=1/0,s=-1/0;for(let i of e){let l=n[i];if(l)for(let c of l.polygon.vertices){if(!t.has(ee(c)))continue;let a=ue(c,r);o=Math.min(o,a),s=Math.max(s,a)}}return Number.isFinite(o)&&Number.isFinite(s)?{min:o,max:s}:null}function cr(e,n,r,t,o){let s=Math.cos(o.maxAngleDeg*Math.PI/180),i=ar(e,n);for(let l of e){let c=n[l];if(!c||Math.abs(ue(c.normal,r.normal))<s)return!1;for(let a of c.polygon.vertices){let u=i.has(ee(a))?o.maxBoundaryDisplacement:t;if(Math.abs(un(a,r))>u)return!1}}return!0}function ar(e,n){let r=new Map;for(let o of e){let s=n[o];if(!s)continue;let i=s.polygon.vertices;for(let l=0;l<i.length;l++){let c=i[l],a=i[(l+1)%i.length],u=ke(c,a),f=r.get(u);f?f.count+=1:r.set(u,{count:1,a:c,b:a})}}let t=new Set;for(let o of r.values())o.count===1&&(t.add(ee(o.a)),t.add(ee(o.b)));return t}function gi(e,n){let r=o=>fn(o,n),t=Yn(e.textureTriangles,r);return{...e,vertices:e.vertices.map(r),...t?{textureTriangles:t}:{}}}function Wn(e,n){for(let r=0;r<e.vertices.length;r++){let t=(r+1)%e.vertices.length;for(let o=0;o<n.vertices.length;o++){let s=(o+1)%n.vertices.length;if(ye(e.vertices[r],n.vertices[o])&&ye(e.vertices[t],n.vertices[s]))return[r,t,o,s];if(ye(e.vertices[r],n.vertices[s])&&ye(e.vertices[t],n.vertices[o]))return[r,t,s,o]}}return null}function ke(e,n){let r=ee(e),t=ee(n);return r<t?`${r}|${t}`:`${t}|${r}`}function ee(e){return`${e[0]},${e[1]},${e[2]}`}function ye(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function cn(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function Xe(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function lr(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 ue(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function pe(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function ur(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 un(e,n){return ue(Xe(e,n.point),n.normal)}function fn(e,n){let r=un(e,n);return[e[0]-n.normal[0]*r,e[1]-n.normal[1]*r,e[2]-n.normal[2]*r]}var mn=1e-5,fr=.001,mr=6;function Zn(e){let n=e.vertices;if(n.length<3)return null;let r=n[0],t=0,o=0,s=0;for(let l=1;l+1<n.length;l++){let c=n[l],a=n[l+1],u=c[1]-r[1],f=c[0]-r[0],g=c[2]-r[2],m=a[1]-r[1],p=a[0]-r[0],d=a[2]-r[2];t-=f*d-g*p,o-=g*m-u*d,s-=u*p-f*m}let i=Math.hypot(t,o,s);return i<1e-9?null:[t/i,o/i,s/i]}function gr(e,n){let r=n.meshRotation,t=r?Qe(e,r[0]??0,r[1]??0,r[2]??0):e;return Qe(t,n.rotX,0,n.rotY)[2]}function Qn(e,n,r=mn){return gr(e,n)>r}function pi(e,n,r=mn){let t=Zn(e);return t===null||Qn(t,n,r)}function pr(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function dr(e){let n=new Map;for(let r of e){if(!r)continue;let t=pr(r);n.has(t)||n.set(t,r)}return Array.from(n,([r,t])=>({key:r,normal:t}))}function di(e){return dr(e.map(Zn))}function xr(e,n=fr){let r=Math.abs(e[0]),t=Math.abs(e[1]),o=Math.abs(e[2]),s=Math.max(r,t,o);return s>1-n&&r+t+o-s<n}function xi(e){return e.length<=mr&&e.every(({normal:n})=>xr(n))}function hi(e,n,r=mn){let t=[];for(let{key:o,normal:s}of e)Qn(s,n,r)&&t.push(o);return t.sort(),t.join("|")}function qn(e,n,r,t,o){let s=(p,d,y)=>{let b=[0,0,0];return b[e]=p,b[(e+1)%3]=d,b[(e+2)%3]=y,b},i=s(n,-t,-t),l=s(n,t,-t),c=s(n,t,t),a=s(n,-t,t),u=s(r,-t,-t),f=s(r,t,-t),g=s(r,t,t),m=s(r,-t,t);return[{vertices:[i,l,c,a],color:o},{vertices:[u,f,g,m],color:o},{vertices:[i,l,f,u],color:o},{vertices:[l,c,g,f],color:o},{vertices:[c,a,m,g],color:o},{vertices:[a,i,u,m],color:o}]}function hr(e={}){let n=e.size??5,r=e.thickness??.025,t=e.negative??!1,o=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",l=n*r/2,c=t?-n:0;return[...qn(0,c,n,l,o),...qn(1,c,n,l,s),...qn(2,c,n,l,i)]}function yr(e,n,r,t){let o=[0,0,0];return o[e]=n,o[(e+1)%3]=r,o[(e+2)%3]=t,o}function yi(e,n,r,t,o){let s=(p,d,y)=>yr(e,p,d,y),i=s(n,-t,-t),l=s(n,t,-t),c=s(n,t,t),a=s(n,-t,t),u=s(r,-t,-t),f=s(r,t,-t),g=s(r,t,t),m=s(r,-t,t);return[{vertices:[i,l,c,a],color:o},{vertices:[u,f,g,m],color:o},{vertices:[i,l,f,u],color:o},{vertices:[l,c,g,f],color:o},{vertices:[c,a,m,g],color:o},{vertices:[a,i,u,m],color:o}]}function bi(e,n,r,t,o){let s=(f,g,m)=>yr(e,f,g,m),i=s(n,-t,-t),l=s(n,t,-t),c=s(n,t,t),a=s(n,-t,t),u=s(r,0,0);return[{vertices:[i,l,c,a],color:o},{vertices:[i,l,u],color:o},{vertices:[l,c,u],color:o},{vertices:[c,a,u],color:o},{vertices:[a,i,u],color:o}]}function Pi(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function br(e){let n=e.axis,r=e.sign??1,t=e.shaftLength??4,o=e.shaftHalfThickness??.05,s=e.headLength??.8,i=e.headHalfThickness??.2,l=e.color??"#ffffff",c=e.shaft??!0,a=t*r,u=Math.min(0,a),f=Math.max(0,a),g=a,m=(t+s)*r,p=bi(n,g,m,i,l),d=r===-1?Pi(p):p;return c?[...yi(n,u,f,o,l),...d]:d}function gn(e,n,r){let t=[0,0,0],o=(e+1)%3,s=(e+2)%3;return t[o]=Math.cos(r)*n,t[s]=Math.sin(r)*n,t}function Pr(e){let n=e.axis,r=e.radius,t=e.halfThickness??Math.max(.05,r*.04),o=e.segments??32,s=e.color??"#ffffff",i=r-t,l=r+t,c=[];for(let a=0;a<o;a++){let u=a/o*Math.PI*2,f=(a+1)/o*Math.PI*2,g=gn(n,i,u),m=gn(n,i,f),p=gn(n,l,u),d=gn(n,l,f);c.push({vertices:[g,p,d,m],color:s})}return c}function Mr(e){let n=e.axis,r=e.outerRadius,t=e.color??"#ffffff",o=(n+1)%3,s=(n+2)%3,i=(l,c)=>{let a=[0,0,0];return a[n]=0,a[o]=l,a[s]=c,a};return[{vertices:[i(-r,-r),i(r,-r),i(r,r),i(-r,r)],color:t}]}function vr(e){let n=e.axis,r=e.size??.4,t=e.offset??r*2,o=typeof t=="number"?t:t[0],s=typeof t=="number"?t:t[1],i=e.along??0,l=e.color??"#ffffff",c=(n+1)%3,a=(n+2)%3,u=(f,g)=>{let m=[0,0,0];return m[n]=i,m[c]=o+f,m[a]=s+g,m};return[{vertices:[u(-r,-r),u(r,-r),u(r,r),u(-r,r)],color:l}]}function Ar(e){let{center:n,size:r,color:t="#ffffff"}=e,[o,s,i]=n,l=[[o+r,s,i],[o-r,s,i],[o,s+r,i],[o,s-r,i],[o,s,i+r],[o,s,i-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(a=>({vertices:[l[a[0]],l[a[1]],l[a[2]]],color:t}))}var Mi=2200,vi=2201,Ai=2202;function Ci(e,n){let r=0,t=1,o=1,s=2201,i=1/0,l=0,c=!1,a=null,u=!0,f=!1,g={clampWhenFinished:!1,get timeScale(){return o},set timeScale(m){o=m},get weight(){return t},set weight(m){t=m},get time(){return r},set time(m){r=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,g},stop(){return c=!1,r=0,l=0,a=null,g},reset(){return r=0,l=0,g},fadeIn(m){return a={from:0,to:1,elapsed:0,duration:m},t=0,g},fadeOut(m){return a={from:t,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 s=m,i=p,g},setEffectiveTimeScale(m){return o=m,g},setEffectiveWeight(m){return t=m,g}};return g._internal={get clip(){return e},get time(){return r},get weight(){return t},get enabled(){return u},get paused(){return f},get running(){return c},get loopMode(){return s},get repetitions(){return i},get completedReps(){return l},set completedReps(m){l=m},get clampWhenFinished(){return g.clampWhenFinished},get timeScale(){return o},get fade(){return a},advance(m){if(!c)return;if(a){a.elapsed+=m;let d=a.duration>0?Math.min(a.elapsed/a.duration,1):1;if(t=a.from+(a.to-a.from)*d,d>=1&&(t=a.to,a=null,t<=0)){c=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(r+=m*o,s===2200)r>=p&&(r=g.clampWhenFinished?p:0,c=!1);else if(s===2201){if(r>=p){let d=r%p,y=Math.floor(r/p);l+=y,r=d,i!==1/0&&l>=i&&(r=g.clampWhenFinished?p:0,c=!1)}}else if(p>0){let d=p*2,y=r%d;if(r>=d){let b=Math.floor(r/d);l+=b,i!==1/0&&l>=i?(r=g.clampWhenFinished?p:0,c=!1):r=y}}}},sampleTime(){if(s===2202){let m=e.duration,p=m*2,d=r%p;return d<=m?d:p-d}return r}},g}function Vi(e){return e._internal}function Jn(e,n){return typeof n=="number"?e[n]:e.find(r=>r.name===n)}function Si(e,n){let r=new Map;function t(a){let u=Jn(n.clips,a);if(!u)throw new Error(`GlyphcssAnimationMixer: no clip found for key "${a}". Available: ${n.clips.map(g=>g.name).join(", ")}`);let f=r.get(u.index);return f||(f=Ci(u,n),r.set(u.index,f)),f}function o(a){let u=Jn(n.clips,a);return u?r.get(u.index)??null:null}function s(a){let u=[];for(let d of r.values()){let y=Vi(d);y.advance(a),y.running&&y.enabled&&u.push({internal:y,clip:y.clip})}if(u.length===0)return;if(u.length===1){let{internal:d,clip:y}=u[0],b=n.sample(y.name,d.sampleTime());e.setPolygons(b);return}let f=0;for(let{internal:d}of u)f+=d.weight;if(f<=0)return;let g=u.map(({internal:d,clip:y})=>({polygons:n.sample(y.name,d.sampleTime()),weight:d.weight/f})),m=g[0].polygons;if(m.length===0)return;let p=m.map((d,y)=>{let b=d.vertices.map((M,v)=>{let P=0,x=0,A=0;for(let{polygons:T,weight:V}of g){let w=T[y];if(!w)continue;let O=w.vertices[v];O&&(P+=O[0]*V,x+=O[1]*V,A+=O[2]*V)}return[P,x,A]});return{...d,vertices:b}});e.setPolygons(p)}function i(){for(let a of r.values())a.stop()}function l(a){let u=Jn(n.clips,a);u&&r.delete(u.index)}function c(){r.clear()}return{clipAction:t,existingAction:o,update:s,stopAllAction:i,uncacheClip:l,uncacheRoot:c}}var Ti=/^[0-9A-Fa-f]{6}$/,wi=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function et(e,n){let r=n?.targetSize??60,t=n?.gridShift??1,o=n?.defaultColor??"#888888",s=n?.palette??wi,i=n?.materialColors??{},l=n?.materialTextures??{},c=[],a=[],u=[],f=[],g=new Map,m=o,p,d=n?.includeObjects?new Set(n.includeObjects):null,y=n?.excludeObjects?new Set(n.excludeObjects):null,b=null,M=()=>b===null?d===null:!(d&&!d.has(b)||y&&y.has(b)),v=E=>E in i?i[E]:Ti.test(E)?`#${E}`:(g.has(E)||(g.set(E,s[f.length%s.length]),f.push(E)),g.get(E)),P=e.split(`
2
- `);for(let E of P)if(!(E.length===0||E.charCodeAt(0)===35)){if(E.startsWith("v ")){let C=E.trim().split(/\s+/);c.push([parseFloat(C[1]),parseFloat(C[2]),parseFloat(C[3])])}else if(E.startsWith("vt ")){let C=E.trim().split(/\s+/);a.push([parseFloat(C[1]),parseFloat(C[2])])}else if(E.startsWith("o "))b=E.trim().slice(2).trim();else if(E.startsWith("usemtl ")){let C=E.trim().split(/\s+/)[1];m=v(C),p=l[C]}else if(E.startsWith("f ")){if(!M())continue;let C=E.trim().split(/\s+/).slice(1),h=[],S=[];for(let I of C){let G=I.split("/");h.push(parseInt(G[0],10)-1);let N=G[1];if(N&&N.length>0){let F=parseInt(N,10)-1;S.push(Number.isFinite(F)?F:null)}else S.push(null)}u.push({idx:h,uvIdx:S,color:m,texture:p})}}if(c.length===0||u.length===0)return Ii(f,e.length);let x=new Set;for(let E of u)for(let C of E.idx)x.add(C);let A=1/0,T=1/0,V=1/0,w=-1/0,O=-1/0,L=-1/0;for(let E of x){let C=c[E];C&&(C[0]<A&&(A=C[0]),C[0]>w&&(w=C[0]),C[1]<T&&(T=C[1]),C[1]>O&&(O=C[1]),C[2]<V&&(V=C[2]),C[2]>L&&(L=C[2]))}let U=Math.max(w-A,O-T,L-V),R=U>0?r/U:1,D=E=>Math.round(E*1e3)/1e3,k=c.map(([E,C,h])=>[D((h-V)*R+t),D((E-A)*R+t),D((C-T)*R+t)]),_=[];for(let{idx:E,uvIdx:C,color:h,texture:S}of u)for(let I=1;I<E.length-1;I++){let G=E[0],N=E[I],F=E[I+1],z=k[G],X=k[N],H=k[F];if(!z||!X||!H||z[0]===X[0]&&z[1]===X[1]&&z[2]===X[2]||z[0]===H[0]&&z[1]===H[1]&&z[2]===H[2]||X[0]===H[0]&&X[1]===H[1]&&X[2]===H[2])continue;let K;if(S){let J=C[0],oe=C[I],Q=C[I+1];if(J!=null&&oe!=null&&Q!=null){let q=a[J],ae=a[oe],re=a[Q];q&&ae&&re&&(K=[q,ae,re])}}let Z={vertices:[z,X,H],color:h};S&&(Z.texture=S),K&&(Z.uvs=K),_.push(Z)}return{polygons:_,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:_.length,materials:f,sourceBytes:e.length}}}function Ii(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var nt=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function tt(e){let n={},r={},t=null;for(let o of e.split(`
3
- `)){let s=o.trim();if(!(s.length===0||s.charCodeAt(0)===35)){if(s.startsWith("newmtl ")){t=s.slice(7).trim();continue}if(t){if(s.startsWith("Kd ")){let i=s.split(/\s+/),l=parseFloat(i[1]),c=parseFloat(i[2]),a=parseFloat(i[3]);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(a)&&(n[t]=`#${nt(l)}${nt(c)}${nt(a)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),l=i[i.length-1]?.replace(/\\+/g,"/");l&&l!=="map_Kd"&&(r[t]=l)}}}}return{colors:n,textures:r}}var wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Ir={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Er(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Ei(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let r=e.slice(5,n),t=e.slice(n+1);if(!r.includes(";base64")){let i=decodeURIComponent(t),l=new Uint8Array(i.length);for(let c=0;c<i.length;c++)l[c]=i.charCodeAt(c)&255;return l}let o=globalThis.atob(t),s=new Uint8Array(o.length);for(let i=0;i<o.length;i++)s[i]=o.charCodeAt(i);return s}function Oi(e,n){let r=e.buffers?.[0];if(!r)throw new Error("parseGltf: JSON doc has no buffers[0]");let t=r.uri;if(!t)throw new Error("parseGltf: JSON doc buffer has no uri (and there's no GLB BIN chunk)");if(t.startsWith("data:"))return Ei(t);if(n){let o=n(t);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 "${t}" \u2014 provide options.resolveBuffer`)}function Ri(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let r=n.getUint32(4,!0);if(r!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${r})`);let t=12,o=null,s=null;for(;t<e.byteLength;){let i=n.getUint32(t,!0),l=n.getUint32(t+4,!0),c=t+8;if(l===1313821514){let a=new Uint8Array(e,c,i);o=JSON.parse(Er(a))}else l===5130562&&(s=new Uint8Array(e,c,i));t=c+i}if(!o)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:o,bin:s}}function rt(e,n,r){let t=e.accessors?.[r],o=e.bufferViews?.[t?.bufferView??-1];if(!t||!o)throw new Error(`parseGltf: bad accessor/bufferView ${r}`);let s=wr[t.componentType],i=Ir[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let l=(o.byteOffset??0)+(t.byteOffset??0),c=t.count*i,a=n.buffer.slice(n.byteOffset+l,n.byteOffset+l+c*s),u;switch(t.componentType){case 5126:u=new Float32Array(a);break;case 5123:u=new Uint16Array(a);break;case 5125:u=new Uint32Array(a);break;case 5121:u=new Uint8Array(a);break;default:throw new Error(`parseGltf: unhandled componentType ${t.componentType}`)}return{array:u,count:t.count,componentCount:i}}function Li(e,n,r){switch(r){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 ${r}`)}}function ki(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 xn(e,n,r){let t=e.accessors?.[r],o=e.bufferViews?.[t?.bufferView??-1];if(!t||!o)throw new Error(`parseGltf: bad accessor/bufferView ${r}`);let s=wr[t.componentType],i=Ir[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let l=n.byteOffset+(o.byteOffset??0)+(t.byteOffset??0),c=o.byteStride??s*i,a=new DataView(n.buffer),u=new Array(t.count*i),f=0;for(let g=0;g<t.count;g++){let m=l+g*c;for(let p=0;p<i;p++){let d=Li(a,m+p*s,t.componentType);u[f++]=t.normalized?ki(d,t.componentType):d}}return{values:u,count:t.count,componentCount:i}}function _i(e,n,r){let t=[],o=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(r&&!i.uri.startsWith("data:"))try{t.push(new s.URL(i.uri,r).href)}catch{t.push(i.uri)}else t.push(i.uri);continue}if(i.bufferView!==void 0){let l=e.bufferViews?.[i.bufferView];if(!l){t.push("");continue}let c=l.byteOffset??0,a=n.subarray(c,c+l.byteLength),u=i.mimeType??"image/png",f=new s.Blob([a],{type:u}),g=s.URL.createObjectURL(f);t.push(g),o.push(g)}else t.push("")}return{urls:t,objectUrls:o}}function Ni(e,n){let r=new Map,t=e.materials??[];for(let o=0;o<t.length;o++){let s=t[o].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s]?.source;if(i===void 0)continue;let l=n[i];l&&r.set(o,l)}return r}function Gi(e,n){let r=e?.pbrMetallicRoughness?.baseColorFactor;if(!r||r.length<3)return n;let t=l=>Math.max(0,Math.min(1,l)),o=l=>Math.round(t(l)*255).toString(16).padStart(2,"0"),s=l=>Math.round(t(l)*255),i=t(r[3]??1);return i<1?`rgba(${s(r[0])}, ${s(r[1])}, ${s(r[2])}, ${Math.round(i*1e3)/1e3})`:`#${o(r[0])}${o(r[1])}${o(r[2])}`}var _e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function ot(e,n){let r=new Array(16);for(let t=0;t<4;t++)for(let o=0;o<4;o++)r[o*4+t]=e[0+t]*n[o*4+0]+e[4+t]*n[o*4+1]+e[8+t]*n[o*4+2]+e[12+t]*n[o*4+3];return r}function dn(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 Or(e,n,r){let t=e?.[0]??0,o=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,l=n?.[1]??0,c=n?.[2]??0,a=n?.[3]??1,u=r?.[0]??1,f=r?.[1]??1,g=r?.[2]??1,m=i+i,p=l+l,d=c+c,y=i*m,b=i*p,M=i*d,v=l*p,P=l*d,x=c*d,A=a*m,T=a*p,V=a*d;return[(1-(v+x))*u,(b+V)*u,(M-T)*u,0,(b-V)*f,(1-(y+x))*f,(P+A)*f,0,(M+T)*g,(P-A)*g,(1-(y+v))*g,0,t,o,s,1]}function Di(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Or(e.translation,e.rotation,e.scale)}function zi(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function Cr(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function Rr(e,n,r){let t=new Array(Math.min(e.length,n.length));for(let o=0;o<t.length;o++)t[o]=e[o]+(n[o]-e[o])*r;return t}function He(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 Ui(e,n,r){let t=He(e),o=He(n),s=t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3];if(s<0&&(s=-s,o=[-o[0],-o[1],-o[2],-o[3]]),s>.9995)return He(Rr(t,o,r));let i=Math.acos(Math.max(-1,Math.min(1,s))),l=Math.sin(i),c=Math.sin((1-r)*i)/l,a=Math.sin(r*i)/l;return He([t[0]*c+o[0]*a,t[1]*c+o[1]*a,t[2]*c+o[2]*a,t[3]*c+o[3]*a])}function Fi(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 Vr(e){return e.matrix?e.matrix.slice():Or(e.translation,e.rotation,e.scale)}function $i(e){let n=e.scene??0,r=e.scenes?.[n]?.nodes;return r&&r.length>0?r:[]}function Sr(e,n){let r=e.nodes??[],t=new Array(r.length),o=new Set,s=(l,c)=>{if(l<0||l>=r.length)return;let a=ot(c,n[l]??_e);t[l]=a,o.add(l);for(let u of r[l].children??[])s(u,a)},i=$i(e);if(i.length>0)for(let l of i)s(l,_e);for(let l=0;l<r.length;l++)o.has(l)||s(l,_e);return t}function Tr(e,n,r,t,o){if(r===void 0)return;let{values:s,count:i,componentCount:l}=xn(e,n,r);if(i!==o||l<1)return;let c=[];for(let a=0;a<i;a++){let u=[];for(let f=0;f<t;f++)u.push(s[a*l+f]??0);c.push(u)}return c}function Bi(e,n,r,t){if(r===void 0)return Array.from({length:t},()=>_e.slice());let{values:o,componentCount:s,count:i}=xn(e,n,r);if(s!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${r} is not MAT4`);let l=[];for(let c=0;c<t;c++){let a=Math.min(c,i-1);l.push(o.slice(a*16,a*16+16))}return l}function pn(e,n){let r=e.componentCount,t=e.interpolation==="CUBICSPLINE"?(n*3+1)*r:n*r;return e.output.slice(t,t+r)}function ji(e,n,r){let t=e.input;if(t.length===0)return[];if(t.length===1||n<=t[0])return pn(e,0);let o=t.length-1;if(n>=t[o])return pn(e,o);let s=0,i=o;for(;s+1<i;){let g=s+i>>1;t[g]<=n?s=g:i=g}let l=t[s],c=t[s+1],a=c>l?(n-l)/(c-l):0,u=pn(e,s),f=pn(e,s+1);return e.interpolation==="STEP"?u:r==="rotation"?Ui(u,f,a):Rr(u,f,a)}function Xi(e,n,r,t){let o=e.animations??[];if(o.length===0||r.length===0)return;let s=(e.nodes??[]).map(m=>Fi(m)),i=s.map(Vr),l=Sr(e,i),c=(e.skins??[]).map(m=>({joints:m.joints??[],inverseBindMatrices:Bi(e,n,m.inverseBindMatrices,m.joints?.length??0)})),a=[];for(let m=0;m<o.length;m++){let p=o[m],d=(p.samplers??[]).map(M=>{let v=xn(e,n,M.input),P=xn(e,n,M.output);return{input:v.values,output:P.values,componentCount:P.componentCount,interpolation:M.interpolation??"LINEAR"}}),y=[];for(let M of p.channels??[]){let v=M.target.node,P=M.target.path,x=d[M.sampler];v===void 0||!P||!x||P==="weights"||y.push({sampler:x,targetNode:v,path:P})}let b=y.reduce((M,v)=>{let P=v.sampler.input;return Math.max(M,P[P.length-1]??0)},0);a.push({info:{index:m,name:p.name??`animation_${m}`,duration:b,channelCount:y.length},channels:y})}let u=a.map(m=>m.info);if(u.length===0)return;let f=(m,p,d,y,b,M)=>{let v=t(m),P=t(p),x=t(d);if(v[0]===P[0]&&v[1]===P[1]&&v[2]===P[2]||v[0]===x[0]&&v[1]===x[1]&&v[2]===x[2]||P[0]===x[0]&&P[1]===x[1]&&P[2]===x[2])return null;let A={vertices:[v,P,x],color:y};return b&&(A.texture=b),M&&(A.uvs=M),A};return{clips:u,sample:(m,p)=>{let d=typeof m=="number"?a[m]:a.find(x=>x.info.name===m);if(!d)return[];let y=d.info.duration,b=y>0?(p%y+y)%y:Math.max(0,p),M=s.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 d.channels){let A=M[x.targetNode];if(!A)continue;let T=ji(x.sampler,b,x.path);A.matrix=void 0,x.path==="translation"?A.translation=T.slice(0,3):x.path==="rotation"?A.rotation=He(T.slice(0,4)):x.path==="scale"&&(A.scale=T.slice(0,3))}let v=Sr(e,M.map(Vr)),P=[];for(let x of r){let A=[];if(x.skinIndex!==void 0&&x.joints&&x.weights&&c[x.skinIndex]){let T=c[x.skinIndex];for(let V=0;V<x.positions.length;V++){let w=x.positions[V],O=[0,0,0],L=0,U=x.joints[V]??[],R=x.weights[V]??[];for(let D=0;D<4;D++){let k=R[D]??0;if(k<=0)continue;let _=Math.round(U[D]??0),E=T.joints[_],C=v[E],h=T.inverseBindMatrices[_];if(!C||!h)continue;let S=ot(C,h);O=zi(O,Cr(dn(S,w),k)),L+=k}A.push(L>0?Cr(O,1/L):dn(x.meshBindWorld,w))}}else{let T=x.meshNode!==null?v[x.meshNode]??x.meshBindWorld:x.meshBindWorld;for(let V of x.positions)A.push(dn(T,V))}for(let T=0;T+2<x.indices.length;T+=3){let V=x.indices[T],w=x.indices[T+1],O=x.indices[T+2],L=A[V],U=A[w],R=A[O];if(!L||!U||!R)continue;let D;if(x.uvs&&x.texture){let _=x.uvs[V],E=x.uvs[w],C=x.uvs[O];_&&E&&C&&(D=[_,E,C])}let k=f(L,U,R,x.color,x.texture,D);k&&P.push(k)}}return P}}}function st(e,n){let r=n?.targetSize??60,t=n?.gridShift??1,o=n?.defaultColor??"#888888",s=n?.materialColors??{},i=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,l=i.byteLength,c,a;if(i.byteLength>=4&&new DataView(i).getUint32(0,!0)===1179937895){let h=Ri(i);if(c=h.doc,!h.bin)throw new Error("parseGltf: GLB has no binary chunk");a=h.bin}else c=JSON.parse(Er(new Uint8Array(i))),a=Oi(c,n?.resolveBuffer);let{urls:u,objectUrls:f}=_i(c,a,n?.baseUrl),g=Ni(c,u),m=[],p=[],d=(c.meshes??[]).map((h,S)=>h.name??`mesh_${S}`),y=(c.materials??[]).map((h,S)=>h.name??`material_${S}`);function b(h,S,I){let G=c.meshes?.[h];if(G)for(let N of G.primitives){if((N.mode??4)!==4)continue;let z=N.material!==void 0?c.materials?.[N.material]?.name:void 0,H=(z?s[z]:void 0)??Gi(N.material!==void 0?c.materials?.[N.material]:void 0,o),K=N.material!==void 0?g.get(N.material):void 0,{array:Z,count:J}=rt(c,a,N.attributes.POSITION);if(!(Z instanceof Float32Array))continue;let oe=[],Q=[];for(let W=0;W<J;W++){let $=[Z[W*3],Z[W*3+1],Z[W*3+2]];oe.push($),Q.push(dn(S,$))}let q=null,ae=N.attributes.TEXCOORD_0;if(K&&ae!==void 0){let{array:W,count:$}=rt(c,a,ae);q=[];let Y=1;W instanceof Uint8Array?Y=1/255:W instanceof Uint16Array&&(Y=1/65535);for(let se=0;se<$;se++){let de=W[se*2]*Y,Pe=W[se*2+1]*Y;q.push([de,1-Pe])}}let re;if(N.indices!==void 0){let{array:W,count:$}=rt(c,a,N.indices);re=[];for(let Y=0;Y<$;Y++)re.push(Number(W[Y]))}else re=Q.map((W,$)=>$);if((c.animations?.length??0)>0){let W=Tr(c,a,N.attributes.JOINTS_0,4,J),$=Tr(c,a,N.attributes.WEIGHTS_0,4,J);p.push({meshNode:I,meshBindWorld:S,skinIndex:I!==null?c.nodes?.[I]?.skin:void 0,positions:oe,indices:re,color:H,texture:K,uvs:q??void 0,joints:W,weights:$})}for(let W=0;W+2<re.length;W+=3){let $=Q[re[W]],Y=Q[re[W+1]],se=Q[re[W+2]];if(!$||!Y||!se)continue;let de;if(q&&K){let Pe=q[re[W]],Te=q[re[W+1]],we=q[re[W+2]];Pe&&Te&&we&&(de=[Pe,Te,we])}m.push({v0:$,v1:Y,v2:se,color:H,texture:K,uvs:de})}}}function M(h,S){let I=c.nodes?.[h];if(!I)return;let G=ot(S,Di(I));typeof I.mesh=="number"&&b(I.mesh,G,h);for(let N of I.children??[])M(N,G)}let v=c.scene??0,P=c.scenes?.[v]?.nodes;if(P&&P.length>0)for(let h of P)M(h,_e);else for(let h=0;h<(c.meshes?.length??0);h++)b(h,_e,null);let x=Yi(f);if(m.length===0)return{polygons:[],objectUrls:f,dispose:x,warnings:[],metadata:{triangleCount:0,meshes:d,materials:y,sourceBytes:l}};let A=1/0,T=1/0,V=1/0,w=-1/0,O=-1/0,L=-1/0;for(let h of m)for(let S of[h.v0,h.v1,h.v2])S[0]<A&&(A=S[0]),S[0]>w&&(w=S[0]),S[1]<T&&(T=S[1]),S[1]>O&&(O=S[1]),S[2]<V&&(V=S[2]),S[2]>L&&(L=S[2]);let U=Math.max(w-A,O-T,L-V),R=U>0?r/U:1,D=h=>Math.round(h*1e3)/1e3,_=(n?.upAxis??"y")==="z"?([h,S,I])=>[D((h-A)*R+t),D((S-T)*R+t),D((I-V)*R+t)]:([h,S,I])=>[D((I-V)*R+t),D((h-A)*R+t),D((S-T)*R+t)],E=Xi(c,a,p,_),C=[];for(let h of m){let S=_(h.v0),I=_(h.v1),G=_(h.v2);if(S[0]===I[0]&&S[1]===I[1]&&S[2]===I[2]||S[0]===G[0]&&S[1]===G[1]&&S[2]===G[2]||I[0]===G[0]&&I[1]===G[1]&&I[2]===G[2])continue;let N={vertices:[S,I,G],color:h.color};h.texture&&(N.texture=h.texture),h.uvs&&(N.uvs=h.uvs),C.push(N)}return{polygons:C,animation:E,objectUrls:f,dispose:x,warnings:[],metadata:{triangleCount:C.length,meshes:d,materials:y,animations:E?.clips,sourceBytes:l}}}function Yi(e){let n=!1;return()=>{if(n)return;n=!0;let r=globalThis.URL;if(r?.revokeObjectURL)for(let t of e)try{r.revokeObjectURL(t)}catch{}}}function it(e){return e.material?.texture??e.texture}function Hi(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function Ki(e,n){return new Promise((r,t)=>{let o=new n,s=!1,i=l=>{s||(s=!0,l())};o.decoding="async",o.onload=()=>i(()=>r(o)),o.onerror=()=>i(()=>t(new Error(`texture load failed: ${e}`))),o.src=e,typeof o.decode=="function"&&o.decode().then(()=>i(()=>r(o)),()=>{})})}async function Wi(e,n,r){try{let t=await Ki(e,n.Image),o=Math.max(0,Math.floor(t.naturalWidth||t.width||0)),s=Math.max(0,Math.floor(t.naturalHeight||t.height||0));if(o<=0||s<=0||o*s>r)return null;let i=n.createCanvas();i.width=o,i.height=s;let l=i.getContext("2d",{willReadFrequently:!0});if(!l)return null;l.drawImage(t,0,0,o,s);let c=l.getImageData(0,0,o,s).data;return{width:o,height:s,data:c,lowDetail:Zi(o,s,c)}}catch{return null}}function Lr(e,n,r,t,o,s){let i=(t*n+r)*4,l=(s*n+o)*4;return Math.max(Math.abs((e[i]??0)-(e[l]??0)),Math.abs((e[i+1]??0)-(e[l+1]??0)),Math.abs((e[i+2]??0)-(e[l+2]??0)))}function Zi(e,n,r){let t=Math.max(1,Math.floor(Math.max(e,n)/128)),o=0,s=0,i=0;for(let l=0;l<n;l+=t)for(let c=0;c<e;c+=t){if(c+t<e){let a=Lr(r,e,c,l,c+t,l);i+=a,o++,a>32&&s++}if(l+t<n){let a=Lr(r,e,c,l,c,l+t);i+=a,o++,a>32&&s++}}return o>0&&s/o<=.045&&i/o<=10}function kr(e,n,r){return Math.max(n,Math.min(r,e))}function Qi(e,n){let r=n[0],t=1-n[1];if(!Number.isFinite(r)||!Number.isFinite(t))return null;let o=kr(Math.floor(r*e.width),0,e.width-1),i=(kr(Math.floor(t*e.height),0,e.height-1)*e.width+o)*4;return{r:e.data[i]??0,g:e.data[i+1]??0,b:e.data[i+2]??0,a:e.data[i+3]??255}}function be(e,n,r,t,o,s){return[e[0]*t+n[0]*o+r[0]*s,e[1]*t+n[1]*o+r[1]*s]}function qi(e){let[n,r,t]=e;return[be(n,r,t,1/3,1/3,1/3),be(n,r,t,.8,.1,.1),be(n,r,t,.1,.8,.1),be(n,r,t,.1,.1,.8),be(n,r,t,.45,.45,.1),be(n,r,t,.45,.1,.45),be(n,r,t,.1,.45,.45)]}function Ji(e){let[n,r,t]=e,o=qi(e);for(let s=1;s<6;s++)for(let i=1;i<6-s;i++){let l=6-s-i;l<=0||o.push(be(n,r,t,s/6,i/6,l/6))}return o}function Dr(e){if(e.textureTriangles?.length)return e.textureTriangles;let n=e.uvs;if(!n||n.length!==e.vertices.length||n.length<3)return[];let r=[];for(let t=1;t+1<n.length;t++)r.push({uvs:[n[0],n[t],n[t+1]]});return r}function _r(e,n,r){return Math.abs(e.r-n.r)<=r&&Math.abs(e.g-n.g)<=r&&Math.abs(e.b-n.b)<=r&&Math.abs(e.a-n.a)<=r}function Nr(e){let n=t=>Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0");if(e.a>=255)return`#${n(e.r)}${n(e.g)}${n(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 ec(){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},count:0}}function nc(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,e.count++}function Gr(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 tc(e,n,r,t){let o=Dr(e);if(o.length===0||!t&&!n.lowDetail)return null;let s=ec();for(let i of o)for(let l of Ji(i.uvs)){let c=Qi(n,l);if(!c)return null;nc(s,c)}return s.count===0?null:_r(s.min,s.max,r)?Nr(Gr(s)):t||!_r(s.min,s.max,32)?null:Nr(Gr(s))}function rc(e,n){let{texture:r,material:t,uvs:o,textureTriangles:s,...i}=e;return{...i,color:n}}async function zr(e,n={}){if(n.enabled===!1)return null;let r=Hi();if(!r)return null;let t=e.filter(c=>it(c)&&Dr(c).length>0);if(t.length===0)return null;let o=n.maxTexturePixels??16777216,s=new Map;await Promise.all(Array.from(new Set(t.map(c=>it(c)))).map(async c=>{s.set(c,await Wi(c,r,o))}));let i=n.colorTolerance??2,l=n.colorTolerance!==void 0;return{bake(c){let a=!1,u=c.map(f=>{let g=it(f);if(!g)return f;let m=s.get(g);if(!m)return f;let p=tc(f,m,i,l);return p?(a=!0,rc(f,p)):f});return{polygons:a?u:c,changed:a}}}}async function oc(e,n={}){let r=await zr(e,n);return r?r.bake(e).polygons:e}async function ct(e,n={}){let r=await zr(e.polygons,n);if(!r)return e;let t=r.bake(e.polygons);return!t.changed&&!e.animation?e:{...e,polygons:t.polygons,animation:e.animation?{...e.animation,sample(o,s){return r.bake(e.animation.sample(o,s)).polygons}}:e.animation}}var sc=[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 ic(e){let n=e>>0&255,r=e>>8&255,t=e>>16&255;return[n,r,t]}function at(e){return(e&255).toString(16).padStart(2,"0")}function Fr(e,n,r){return`#${at(e)}${at(n)}${at(r)}`}function cc(e,n,r,t){if(t>=255)return Fr(e,n,r);let o=Math.round(Math.max(0,Math.min(255,t))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${r}, ${o})`}var ac=542658390;function lt(e,n){let r=n?.targetSize??60,t=n?.gridShift??0,o=e.byteLength;if(e.byteLength<8)return Ne(o,["parseVox: buffer too small to be a valid .vox file"]);let s=new DataView(e);if(s.getUint32(0,!0)!==ac)return Ne(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return Ne(o,["parseVox: buffer too small for MAIN chunk"]);if(Ur(s,8)!=="MAIN")return Ne(o,["parseVox: expected MAIN chunk at offset 8"]);let a=20+s.getUint32(12,!0),u=a+s.getUint32(16,!0),f=[],g=[],m=null;for(;a<u&&a+12<=e.byteLength;){let C=Ur(s,a),h=s.getUint32(a+4,!0),S=s.getUint32(a+8,!0),I=a+12,G=I+h+S;if(C==="SIZE"){if(h>=12&&I+12<=e.byteLength){let N=s.getUint32(I,!0),F=s.getUint32(I+4,!0),z=s.getUint32(I+8,!0);f.push({sx:N,sy:F,sz:z})}}else if(C==="XYZI"){if(h>=4&&I+4<=e.byteLength){let N=s.getUint32(I,!0),F=[],z=Math.min(N,Math.floor((h-4)/4));for(let X=0;X<z;X++){let H=I+4+X*4;F.push({x:s.getUint8(H),y:s.getUint8(H+1),z:s.getUint8(H+2),colorIndex:s.getUint8(H+3)})}g.push(F)}}else if(C==="RGBA"&&h>=1024&&I+1024<=e.byteLength){m=[];for(let N=0;N<256;N++){let F=I+N*4,z=s.getUint8(F),X=s.getUint8(F+1),H=s.getUint8(F+2),K=s.getUint8(F+3);m.push(cc(z,X,H,K))}}a=G}let p=[],d=new Set;for(let C of g)for(let h of C){if(h.colorIndex===0)continue;let S=`${h.x},${h.y},${h.z}`;d.has(S)||(d.add(S),p.push(h))}if(p.length===0)return Ne(o,[]);let y=C=>{let h=C-1;if(m!==null)return m[h]??"#888888";let S=sc[C]??0,[I,G,N]=ic(S);return Fr(I,G,N)},b=(C,h,S)=>d.has(`${C},${h},${S}`),M=new Map,v=(C,h,S,I,G)=>{let N=`${C}:${h}:${G}`,F=M.get(N);F||(F=new Set,M.set(N,F)),F.add(`${S},${I}`)};for(let C of p){let{x:h,y:S,z:I}=C,G=y(C.colorIndex);b(h+1,S,I)||v(0,h+1,S,I,G),b(h-1,S,I)||v(1,h,S,I,G),b(h,S+1,I)||v(2,S+1,h,I,G),b(h,S-1,I)||v(3,S,h,I,G),b(h,S,I+1)||v(4,I+1,h,S,G),b(h,S,I-1)||v(5,I,h,S,G)}function P(C){let h=new Set,S=[],I=1/0,G=-1/0,N=1/0,F=-1/0;for(let z of C){let[X,H]=z.split(","),K=+X,Z=+H;K<I&&(I=K),K>G&&(G=K),Z<N&&(N=Z),Z>F&&(F=Z)}for(let z=N;z<=F;z++)for(let X=I;X<=G;X++){let H=`${X},${z}`;if(!C.has(H)||h.has(H))continue;let K=1;for(;X+K<=G;){let J=`${X+K},${z}`;if(!C.has(J)||h.has(J))break;K++}let Z=1;e:for(;z+Z<=F;){for(let J=0;J<K;J++){let oe=`${X+J},${z+Z}`;if(!C.has(oe)||h.has(oe))break e}Z++}for(let J=0;J<Z;J++)for(let oe=0;oe<K;oe++)h.add(`${X+oe},${z+J}`);S.push({u:X,v:z,w:K,h:Z})}return S}let x=(C,h,S,I,G,N)=>{let F=S+G,z=I+N;switch(C){case 0:return[[h,S,I],[h,F,I],[h,F,z],[h,S,z]];case 1:return[[h,F,I],[h,S,I],[h,S,z],[h,F,z]];case 2:return[[S,h,I],[S,h,z],[F,h,z],[F,h,I]];case 3:return[[F,h,I],[F,h,z],[S,h,z],[S,h,I]];case 4:return[[S,I,h],[F,I,h],[F,z,h],[S,z,h]];default:return[[S,z,h],[F,z,h],[F,I,h],[S,I,h]]}},A=[];for(let[C,h]of M){let S=C.indexOf(":"),I=C.indexOf(":",S+1),G=+C.slice(0,S),N=+C.slice(S+1,I),F=C.slice(I+1);for(let{u:z,v:X,w:H,h:K}of P(h))A.push({vertices:x(G,N,z,X,H,K),color:F})}if(A.length===0)return Ne(o,[]);let T=1/0,V=1/0,w=1/0,O=-1/0,L=-1/0,U=-1/0;for(let C of A)for(let h of C.vertices)h[0]<T&&(T=h[0]),h[0]>O&&(O=h[0]),h[1]<V&&(V=h[1]),h[1]>L&&(L=h[1]),h[2]<w&&(w=h[2]),h[2]>U&&(U=h[2]);let R=Math.max(O-T,L-V,U-w),D=R>0?r/R:1,k=C=>Math.round(C*1e3)/1e3,_=C=>[k((C[0]-T)*D+t),k((C[1]-V)*D+t),k((C[2]-w)*D+t)],E=A.map(({vertices:C,color:h})=>({vertices:C.map(_),color:h}));return{polygons:E,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:E.length,sourceBytes:o,voxelCount:p.length}}}function Ur(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 Ne(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var Se="loadMesh";function ut(e,n){let r=Xn(e.polygons,{meshResolution:n?.meshResolution});return r.length===e.polygons.length?e:{...e,polygons:r}}async function $r(e,n){let r=n?.solidTextureSamples;return r===!1?e:ct(e,typeof r=="object"?r:void 0)}function lc(e){let n=e.split("?")[0].split("#")[0],r=n.lastIndexOf(".");return r<0?"":n.slice(r+1).toLowerCase()}async function uc(e,n){let r=lc(e);if(r==="mtl")throw new Error(`${Se}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let t=globalThis.fetch;if(!t)throw new Error(`${Se}: no fetch() in this environment`);let o=n?.baseUrl??e;if(r==="obj"){let s=await t(e);if(!s.ok)throw new Error(`${Se}: ${e} \u2192 ${s.status}`);let i=await s.text(),l=n?.objOptions;if(n?.mtlUrl){let a=await t(n.mtlUrl);if(!a.ok)throw new Error(`${Se}: ${n.mtlUrl} \u2192 ${a.status}`);let u=await a.text(),{colors:f,textures:g}=tt(u),m={},p=globalThis.URL,d=globalThis.document?.baseURI,y=n.mtlUrl;if(p&&d)try{y=new p(n.mtlUrl,d).toString()}catch{}for(let[b,M]of Object.entries(g)){if(p)try{m[b]=new p(M,y).toString();continue}catch{}let v=n.mtlUrl.lastIndexOf("/"),P=v>=0?n.mtlUrl.slice(0,v+1):"";m[b]=M.startsWith("/")||/^https?:\/\//.test(M)?M:P+M}l={...l??{},materialColors:{...f,...l?.materialColors??{}},materialTextures:{...m,...l?.materialTextures??{}}}}let c=et(i,l);return ut(await $r(c,n),n)}if(r==="glb"||r==="gltf"){let s=await t(e);if(!s.ok)throw new Error(`${Se}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),l=st(i,{baseUrl:o,...n?.gltfOptions??{}});return ut(await $r(l,n),n)}if(r==="vox"){let s=await t(e);if(!s.ok)throw new Error(`${Se}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return ut(lt(i,n?.voxOptions),n)}throw new Error(`${Se}: unsupported extension ".${r}" (supported: obj, glb, gltf, vox)`)}function fc(e,n,r,t,o=.5,s=.5,i=.4){let l=4/(e[2]+3),c=Math.min(n,r)*i,a=n*o+e[0]*c*t*l,u=r*s-e[1]*c*l;return[a,u,e[2]]}function mc(e){let[n,r,t]=[e.vertices[0],e.vertices[1],e.vertices[2]],o=r[0]-n[0],s=r[1]-n[1],i=r[2]-n[2],l=t[0]-n[0],c=t[1]-n[1],a=t[2]-n[2];return[s*a-i*c,i*l-o*a,o*c-s*l]}function gc(e,n){let r=Math.hypot(e[0],e[1],e[2]),t=Math.hypot(n[0],n[1],n[2]);return r===0||t===0?1:(e[0]*n[0]+e[1]*n[1]+e[2]*n[2])/(r*t)}function Br(e,n){let r=`${e[0]},${e[1]},${e[2]}`,t=`${n[0]},${n[1]},${n[2]}`;return r<t?`${r}|${t}`:`${t}|${r}`}function pc(e,n=0){if(n<=0){let i=new Set,l=[];for(let c of e){let a=[[0,1],[1,2],[2,0]];for(let[u,f]of a){let g=c.vertices[u],m=c.vertices[f],p=Br(g,m);if(i.has(p))continue;i.add(p);let d={from:g,to:m,weight:2};c.color&&(d.color=c.color),l.push(d)}}return l}let r=Math.cos(n*Math.PI/180),t=new Map,o=[[0,1],[1,2],[2,0]];for(let i of e){let l=mc(i);for(let[c,a]of o){let u=i.vertices[c],f=i.vertices[a],g=Br(u,f),m=t.get(g);m?m.normals.push(l):t.set(g,{normals:[l],from:u,to:f,color:i.color})}}let s=[];for(let{normals:i,from:l,to:c,color:a}of t.values()){if(i.length<2){let f={from:l,to:c,weight:2};a&&(f.color=a),s.push(f);continue}let u=!1;e:for(let f=0;f<i.length;f++)for(let g=f+1;g<i.length;g++)if(gc(i[f],i[g])<r){u=!0;break e}if(u){let f={from:l,to:c,weight:2};a&&(f.color=a),s.push(f)}}return s}function dc(e,n=0){return pc(e,n)}export{oo as BASE_TILE,mn as CAMERA_BACKFACE_CULL_EPS,Oe as DEFAULT_CAMERA_STATE,jr as DEFAULT_PROJECTION,Mi as LoopOnce,Ai as LoopPingPong,vi as LoopRepeat,Jr as QUAT_IDENTITY,fr as VOXEL_CAMERA_CULL_AXIS_EPS,mr as VOXEL_CAMERA_CULL_NORMAL_LIMIT,br as arrowPolygons,hr as axesHelperPolygons,oc as bakeSolidTextureSampledPolygons,ct as bakeSolidTextureSamples,Zr as buildSceneContext,dr as cameraCullNormalGroups,di as cameraCullNormalGroupsFromPolygons,pr as cameraCullNormalKey,hi as cameraCullVisibleSignature,gr as cameraFacingDepth,Me as clampChannel,vt as computeSceneBbox,Yr as computeShapeLighting,zn as coverPlanarPolygons,Si as createGlyphcssAnimationMixer,co as createIsometricCamera,Ce as cullInteriorPolygons,Ln as dedupeOverlappingPolygons,ro as eulerXYZFromQuat,Et as findOverlappingPolygonDuplicates,Ke as formatColor,qr as inverseRotateVec3,xr as isAxisAlignedSurfaceNormal,xi as isVoxelCameraCullableNormalGroups,uc as loadMesh,ce as mergePolygons,Qn as normalFacesCamera,so as normalizeInvertMultiplier,En as normalizePolygons,Ar as octahedronPolygons,Xn as optimizeMeshPolygons,Ie as parseColor,st as parseGltf,gt as parseHexColor,tt as parseMtl,et as parseObj,Tn as parsePureColor,pt as parseRgbColor,lt as parseVox,vr as planePolygons,Zn as polygonCssSurfaceNormal,Qr as polygonFaces,pi as polygonFacesCamera,fc as project,no as quatFromAxisAngle,to as quatFromEulerXYZ,eo as quatMultiply,Pr as ringPolygons,Mr as ringQuadPolygons,Qe as rotateVec3,Xr as shadeColor,dc as trianglesToFeatureEdges};
1
+ var Fr="cubic";function ao(e){let n=e.replace("#","");if(n.length===3){let o=parseInt(n[0]+n[0],16),t=parseInt(n[1]+n[1],16),r=parseInt(n[2]+n[2],16);return Number.isNaN(o)||Number.isNaN(t)||Number.isNaN(r)?null:{rgb:[o,t,r],alpha:1}}if(n.length===6){let o=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),r=parseInt(n.slice(4,6),16);return Number.isNaN(o)||Number.isNaN(t)||Number.isNaN(r)?null:{rgb:[o,t,r],alpha:1}}return null}function lo(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 Vt(e){if(!e)return null;let n=e.trim(),o=ao(n);return o||lo(n)}function Se(e){return Math.max(0,Math.min(255,Math.round(e)))}function dn(e){let[n,o,t]=e.rgb.map(Se);return e.alpha<1?`rgba(${n}, ${o}, ${t}, ${e.alpha})`:`rgb(${n}, ${o}, ${t})`}var Ct={rgb:[204,204,204],alpha:1},uo=new Map;function Ee(e){if(!e)return null;let n=e.trim(),o=uo.get(n);if(o)return o;let t=Vt(n);return t?(uo.set(n,t),t):null}function Ur(e,n){let o=Ee(e)??Ct,t=[Se(o.rgb[0]+n),Se(o.rgb[1]+n),Se(o.rgb[2]+n)];return dn({rgb:t,alpha:o.alpha})}var vt={direction:[0,0,-1],color:"#ffffff",intensity:1},fo={color:"#ffffff",intensity:.4};function mo(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 po(e,n,o){let t=Ee(n)??Ct;return e*(t.rgb[o]/255)}function Br(e,n,o,t){let r=Ee(n)??Ct,c=mo(o?.direction??vt.direction),a=o?.color??vt.color,s=Math.max(0,o?.intensity??vt.intensity),i=t?.color??fo.color,l=Math.max(0,t?.intensity??fo.intensity),u=mo(e),m=Math.max(0,-(u[0]*c[0]+u[1]*c[1]+u[2]*c[2])),d=s*m,f=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],x=po(g,i,p)*l,V=po(g,a,p)*d;f[p]=Se(x+V)}return dn({rgb:f,alpha:r.alpha})}var go="#cccccc",pn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],yo=(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]],ho=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],gn=e=>Math.hypot(e[0],e[1],e[2]);function jr(e){let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<o&&(o=u[1]),u[1]>c&&(c=u[1]),u[2]<t&&(t=u[2]),u[2]>a&&(a=u[2]);let s=r-n,i=c-o,l=a-t;return Math.hypot(s,i,l)}function qr(){let e=globalThis;if(e.__GLYPH_DEV__===!0)return!0;if(e.__GLYPH_DEV__===!1)return!1;let n=e.process?.env?.NODE_ENV;return typeof n=="string"?n!=="production":!1}function At(e){let n=[],o=[];if(!e||e.length===0)return{polygons:n,warnings:o};for(let t=0;t<e.length;t++){let r=e[t];if(!r||!Array.isArray(r.vertices)){o.push(`Polygon ${t}: missing vertices, dropped`);continue}let c=r.vertices;if(c.length<3){o.push(`Polygon ${t}: ${c.length} vertices (need >= 3), dropped`);continue}let a=pn(c[1],c[0]),s=pn(c[2],c[0]),i=yo(a,s),l=gn(i);if(c.length===3){if(l<1e-12){gn(a)<1e-12||gn(s)<1e-12?o.push(`Polygon ${t}: zero-area triangle (coincident vertices), dropped`):o.push(`Polygon ${t}: vertices collinear, dropped`);continue}}else if(l<1e-12){o.push(`Polygon ${t}: first 3 vertices collinear, dropped`);continue}let u=[{...r,vertices:c.slice()}];if(c.length>=4){let m=[i[0]/l,i[1]/l,i[2]/l],d=ho(m,c[0]),f=jr(c),p=Math.max(1e-6,f*.001),g=0;for(let x=3;x<c.length;x++){let V=Math.abs(ho(m,c[x])-d);V>g&&(g=V)}if(g>p){let x=[],V=r.uvs&&r.uvs.length===c.length?r.uvs:void 0;for(let C=1;C<c.length-1;C++){let v=[c[0].slice(),c[C].slice(),c[C+1].slice()],M=yo(pn(v[1],v[0]),pn(v[2],v[0]));if(gn(M)<1e-12)continue;let y={...r,vertices:v};V&&(y.uvs=[V[0].slice(),V[C].slice(),V[C+1].slice()]),x.push(y)}if(x.length===0){o.push(`Polygon ${t}: ${c.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}o.push(`Polygon ${t}: ${c.length} non-coplanar vertices, fan-triangulated to ${x.length} triangles`),u=x}}for(let m of u){let d=Hr(m,t,o);d&&n.push(d)}}return{polygons:n,warnings:o}}function Hr(e,n,o){let t={vertices:e.vertices},r=e.texture;if(typeof r=="string"&&r===""&&(r=void 0),e.color!==void 0&&r!==void 0&&qr()&&o.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Ee(e.color)?t.color=e.color:(o.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${go}`),t.color=go)),r!==void 0&&(t.texture=r),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?o.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):t.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let c={},a=!1;for(let s of Object.keys(e.data)){let i=e.data[s];typeof i=="string"||typeof i=="number"||typeof i=="boolean"?c[s]=i:(a=!0,o.push(`Polygon ${n}: data["${s}"] has non-primitive value, key dropped`))}Object.keys(c).length>0&&(t.data=c)}return t}function bo(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0,s=!1;for(let i of e)if(i?.vertices)for(let l of i.vertices)l&&(s=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<o&&(o=l[1]),l[1]>c&&(c=l[1]),l[2]<t&&(t=l[2]),l[2]>a&&(a=l[2]));return s?{min:[n,o,t],max:[r,c,a]}:{min:[0,0,0],max:[0,0,0]}}function Xr(e){let n=e.polygons??[],o,t;if(e.skipNormalize)o=n,t=[];else{let s=At(n);o=s.polygons,t=s.warnings}let r=bo(o),c=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]];return{context:{polygons:o,sceneBbox:r,warnings:t},dimensions:{sceneBbox:r,size:c},warnings:t}}function Yr(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function yn(e,n,o,t){let r=n*Math.PI/180,c=o*Math.PI/180,a=t*Math.PI/180,[s,i,l]=e;if(a!==0){let u=Math.cos(a),m=Math.sin(a);[s,i]=[s*u-i*m,s*m+i*u]}if(c!==0){let u=Math.cos(c),m=Math.sin(c);[s,l]=[s*u+l*m,-s*m+l*u]}if(r!==0){let u=Math.cos(r),m=Math.sin(r);[i,l]=[i*u-l*m,i*m+l*u]}return[s,i,l]}function Wr(e,n){let o=-n[0]*Math.PI/180,t=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[c,a,s]=e;if(o!==0){let i=Math.cos(o),l=Math.sin(o);[a,s]=[a*i-s*l,a*l+s*i]}if(t!==0){let i=Math.cos(t),l=Math.sin(t);[c,s]=[c*i+s*l,-c*l+s*i]}if(r!==0){let i=Math.cos(r),l=Math.sin(r);[c,a]=[c*i-a*l,c*l+a*i]}return[c,a,s]}var St=Math.PI/180,nn=180/Math.PI,Kr=[1,0,0,0];function Zr(e,n){let[o,t,r,c]=e,[a,s,i,l]=n;return[o*a-t*s-r*i-c*l,o*s+t*a+r*l-c*i,o*i-t*l+r*a+c*s,o*l+t*i-r*s+c*a]}function Qr(e,n){let o=n*.5,t=Math.sin(o);return[Math.cos(o),e[0]*t,e[1]*t,e[2]*t]}function Jr(e){let n=e[0]*St,o=e[1]*St,t=e[2]*St,r=Math.cos(n*.5),c=Math.sin(n*.5),a=Math.cos(o*.5),s=Math.sin(o*.5),i=Math.cos(t*.5),l=Math.sin(t*.5);return[r*a*i-c*s*l,c*a*i+r*s*l,r*s*i-c*a*l,r*a*l+c*s*i]}function es(e){let[n,o,t,r]=e,c=2*(o*r+n*t),a=2*(t*r-n*o),s=1-2*(o*o+t*t),i=2*(o*t-n*r),l=1-2*(t*t+r*r),u=Math.max(-1,Math.min(1,c)),m=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-a,s)*nn,m*nn,Math.atan2(-i,l)*nn]:[Math.atan2(2*(t*r+n*o),1-2*(o*o+r*r))*nn,m*nn,0]}var ns=50;function ts(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Le={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},xo=100,Po=1e4,De=e=>Math.round(e*xo)/xo,os=e=>Math.round(e*Po)/Po;function rs(e={}){let n={target:e.target??[...Le.target],rotX:e.rotX??Le.rotX,rotY:e.rotY??Le.rotY,zoom:e.zoom??Le.zoom,distance:e.distance??Le.distance};function o(r){r.target!==void 0&&(n.target=[De(r.target[0]),De(r.target[1]),De(r.target[2])]),r.rotX!==void 0&&(n.rotX=De(r.rotX)),r.rotY!==void 0&&(n.rotY=De(r.rotY)),r.zoom!==void 0&&(n.zoom=os(r.zoom)),r.distance!==void 0&&(n.distance=De(r.distance))}function t(r={}){let a=(r.cols??0)*50,s=(r.rows??0)*50,[i,l,u]=n.target,m=l*50,d=i*50,f=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-m}px, ${-d}px, ${-f}px)`,width:`${a}px`,height:`${s}px`}}return{state:n,update:o,getStyle:t}}var Ve=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],hn=(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]],tn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Tt=e=>Math.hypot(e[0],e[1],e[2]),Me=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function ss(e,n){let o=`${e[0]},${e[1]},${e[2]}`,t=`${n[0]},${n[1]},${n[2]}`;return o<t?`${o}|${t}`:`${t}|${o}`}function Vo(e){if(e.length<3)return null;let n=Ve(e[1],e[0]),o=Ve(e[2],e[0]),t=hn(n,o),r=Tt(t);if(r<1e-12)return null;let c=[t[0]/r,t[1]/r,t[2]/r],a=tn(c,e[0]);return{normal:c,d:a}}function cs(e,n){return tn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function is(e,n){return tn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function as(e,n,o,t){let r=e.vertices.findIndex(h=>Me(h,o)),c=e.vertices.findIndex(h=>Me(h,t)),a=n.vertices.findIndex(h=>Me(h,o)),s=n.vertices.findIndex(h=>Me(h,t));if(r<0||c<0||a<0||s<0)return null;let i=e.vertices.length,l=n.vertices.length,u=(r+1)%i===c,m=(a+1)%l===s;if(u===m)return null;let d=u?c:r,f=u?r:c,p=m?s:a,g=m?a:s,x=!!(e.uvs&&n.uvs),V=[],C=x?[]:void 0,v=d;for(;V.push(e.vertices[v]),C&&C.push(e.uvs[v]),v!==f;)v=(v+1)%i;for(v=p;V.push(n.vertices[v]),C&&C.push(n.uvs[v]),v!==g;)v=(v+1)%l;let M=[],y=C?[]:void 0;for(let h=0;h<V.length;h++)(M.length===0||!Me(V[h],M[M.length-1]))&&(M.push(V[h]),y&&C&&y.push(C[h]));if(M.length>1&&Me(M[0],M[M.length-1])&&(M.pop(),y?.pop()),x)return Mo(M,y);let P=[],S=y?[]:void 0;for(let h=0;h<M.length;h++){let b=M[(h-1+M.length)%M.length],A=M[h],I=M[(h+1)%M.length],R=hn(Ve(A,b),Ve(I,b));Tt(R)>1e-9&&(P.push(A),S&&y&&S.push(y[h]))}return P.length<3?null:Mo(P,S)}function ls(e,n){let o=e.length,t=0;for(let r=0;r<o;r++){let c=e[r],a=e[(r+1)%o],s=e[(r+2)%o],i=Ve(a,c),l=Ve(s,a),u=tn(hn(i,l),n);if(Math.abs(u)<1e-9)continue;let m=u>0?1:-1;if(t===0)t=m;else if(m!==t)return!1}return!0}function us(e,n){if(e.length<3)return!1;let o=Vo(e);if(!o)return!1;for(let t of e)if(Math.abs(tn(o.normal,t)-o.d)>n)return!1;return!0}function fs(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function ms(e,n){let o=[];for(let t=1;t<e.length-1;t++)o.push({vertices:[[...e[0]],[...e[t]],[...e[t+1]]],uvs:[[...n[0]],[...n[t]],[...n[t+1]]]});return o}function Mo(e,n){for(let o=0;o<e.length;o++){let t=e[o],r=e[(o+1)%e.length],c=e[(o+2)%e.length];if(!(Tt(hn(Ve(r,t),Ve(c,t)))<=1e-9))return o===0?{vertices:e,uvs:n}:{vertices:[...e.slice(o),...e.slice(0,o)],uvs:n?[...n.slice(o),...n.slice(0,o)]:void 0}}return{vertices:e,uvs:n}}function ue(e){let n=[],o=[];for(let r of e??[]){if(!r||!r.vertices||r.vertices.length<3){r&&n.push(r);continue}let c=r.vertices.map(l=>[l[0],l[1],l[2]]),a=Vo(c);if(!a){n.push(r);continue}let s=r.texture&&r.uvs&&r.uvs.length===c.length?r.uvs.map(l=>[l[0],l[1]]):void 0,i=r.texture&&s?r.textureTriangles?.length?fs(r.textureTriangles):ms(c,s):void 0;o.push({vertices:c,uvs:s,color:r.color??"#cccccc",texture:r.texture,textureTriangles:i,normal:a.normal,d:a.d,alive:!0,data:r.data})}let t=()=>{let r=new Map;for(let s=0;s<o.length;s++){let i=o[s];if(!i.alive)continue;let l=i.vertices.length;for(let u=0;u<l;u++){let m=i.vertices[u],d=i.vertices[(u+1)%l],f=ss(m,d),p=r.get(f);p||(p=[],r.set(f,p)),p.push(s)}}let c=!1,a=(s,i)=>{for(let l=0;l<s.vertices.length;l++){let u=s.vertices[l],m=s.vertices[(l+1)%s.vertices.length];for(let d=0;d<i.vertices.length;d++){let f=i.vertices[d],p=i.vertices[(d+1)%i.vertices.length];if(Me(u,p)&&Me(m,f))return[u,m]}}return null};for(let[,s]of r){if(s.length<2)continue;let[i,l]=s;if(i===l)continue;let u=o[i],m=o[l];if(!u.alive||!m.alive||u.color!==m.color||u.texture!==m.texture)continue;let d=!!(u.texture||m.texture);if(d&&(!u.textureTriangles||!m.textureTriangles)||!!u.uvs!=!!m.uvs||(d?!is(u,m):!cs(u,m)))continue;let f=a(u,m);if(!f)continue;let[p,g]=f,x=as(u,m,p,g);x&&us(x.vertices,.001)&&ls(x.vertices,u.normal)&&(u.vertices=x.vertices,u.uvs=x.uvs,u.textureTriangles=d?[...u.textureTriangles??[],...m.textureTriangles??[]]:void 0,m.alive=!1,c=!0)}return c};for(;t(););for(let r of o){if(!r.alive)continue;let c={vertices:r.vertices,color:r.color};r.texture&&(c.texture=r.texture),r.uvs&&(c.uvs=r.uvs),r.textureTriangles?.length&&(c.textureTriangles=r.textureTriangles),r.data&&(c.data=r.data),n.push(c)}return n}var ds=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],ps=(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]],ye=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function gs(e,n){let o=e.vertices;if(!o||o.length<3)return null;let t=0,r=0,c=0;for(let g=0;g<o.length;g++){let x=o[g],V=o[(g+1)%o.length];t+=(x[1]-V[1])*(x[2]+V[2]),r+=(x[2]-V[2])*(x[0]+V[0]),c+=(x[0]-V[0])*(x[1]+V[1])}let a=Math.hypot(t,r,c);if(a<1e-12)return null;let s=[t/a,r/a,c/a],i=0,l=0,u=0;for(let g of o)i+=g[0],l+=g[1],u+=g[2];let m=1/o.length,d=[i*m,l*m,u*m],f=ye(s,d),p=a*.5;return{index:n,polygon:e,normal:s,d:f,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function ys(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],o=n[0]-e[0]*ye(n,e),t=n[1]-e[1]*ye(n,e),r=n[2]-e[2]*ye(n,e),c=Math.hypot(o,t,r);o/=c,t/=c,r/=c;let a=[o,t,r],s=ps(e,a);return{u:a,v:s}}function hs(e){if(e.local2D)return;let n=ys(e.normal),o=[],t=1/0,r=1/0,c=-1/0,a=-1/0;for(let s of e.polygon.vertices){let i=ye(s,n.u),l=ye(s,n.v);o.push([i,l]),i<t&&(t=i),i>c&&(c=i),l<r&&(r=l),l>a&&(a=l)}e.local2D=o,e.bbox2D={min:[t,r],max:[c,a]},e.basis=n}function bs(e,n){let o=[],t=1/0,r=1/0,c=-1/0,a=-1/0;for(let s of e.vertices){let i=ye(s,n.u),l=ye(s,n.v);o.push([i,l]),i<t&&(t=i),i>c&&(c=i),l<r&&(r=l),l>a&&(a=l)}return{local2D:o,bbox2D:{min:[t,r],max:[c,a]}}}function xs(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 vo(e,n){let o=!1;for(let t=0,r=n.length-1;t<n.length;r=t++){let c=n[t],a=n[r];c[1]>e[1]!=a[1]>e[1]&&e[0]<(a[0]-c[0])*(e[1]-c[1])/(a[1]-c[1]+1e-30)+c[0]&&(o=!o)}return o}function Co(e){let n=0,o=0;for(let t of e)n+=t[0],o+=t[1];return[n/e.length,o/e.length]}function Ps(e,n){let o=Co(e),t=Co(n),r=1e-4,c=0;for(let l of e){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];vo(u,n)&&c++}let a=0;for(let l of n){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];vo(u,e)&&a++}let s=c/e.length,i=a/n.length;return Math.max(s,i)}function Ms(e,n){let o=e.normal[0],t=e.normal[1],r=e.normal[2],c=Math.abs(o),a=Math.abs(t),s=Math.abs(r),i=o;a>c&&a>s?i=t:s>c&&s>a&&(i=r),i<0&&(o=-o,t=-t,r=-r);let l=Math.round(o/.05),u=Math.round(t/.05),m=Math.round(r/.05),d=e.d*(e.normal[0]===o&&e.normal[1]===t&&e.normal[2]===r?1:-1),f=Math.round(d/(n*2));return`${l},${u},${m}|${f}`}function Vs(e,n,o,t){let r=ye(e.normal,n.normal);if(Math.abs(r)<1-o)return!1;let c=r>0?1:-1;return Math.abs(e.d-c*n.d)<t}function Ao(e,n){let o=ds(n,e.centroid);return ye(e.normal,o)>0}function So(e,n){if(!e||e.length<2)return new Set;let o=n?.normalTolerance??.001,t=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,c=[];for(let f=0;f<e.length;f++){let p=gs(e[f],f);p&&c.push(p)}if(c.length<2)return new Set;let a=0,s=0,i=0,l=0;for(let f of c)a+=f.centroid[0]*f.area,s+=f.centroid[1]*f.area,i+=f.centroid[2]*f.area,l+=f.area;let u=l>0?[a/l,s/l,i/l]:[0,0,0],m=new Map;for(let f of c){let p=Ms(f,t),g=m.get(p);g||(g=[],m.set(p,g)),g.push(f)}let d=new Set;for(let f of m.values())if(!(f.length<2))for(let p=0;p<f.length;p++){let g=f[p];if(!d.has(g.index))for(let x=p+1;x<f.length;x++){let V=f[x];if(d.has(V.index)||!Vs(g,V,o,t))continue;hs(g);let C=bs(V.polygon,g.basis);if(!xs(g.bbox2D,C.bbox2D)||Ps(g.local2D,C.local2D)<r)continue;let M=Ao(g,u),y=Ao(V,u),P;if(M&&!y?P=g:y&&!M?P=V:P=g.area<V.area?g:V,d.add(P.index),P===g)break}}return d}function Ot(e,n){if(!e||e.length<2)return e??[];let o=So(e,n);if(o.size===0)return e;let t=[];for(let r=0;r<e.length;r++)o.has(r)||t.push(e[r]);return t}var vs=4,Cs=8,As=.001,Ss=1e-9,Ts=1e6,Os=1e6,Te=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],wt=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],sn=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],Oe=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],wo=(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]],ko=e=>Math.hypot(e[0],e[1],e[2]);function cn(e){let n=ko(e);return n<=Ss?null:[e[0]/n,e[1]/n,e[2]/n]}function rn(e,n){return Math.round(e*n)/n}function pe(e){return rn(e,Ts)}function It(e){return rn(e,Os)}function zt(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function be(e){return`${pe(e[0])},${pe(e[1])}`}function Is(e){let n=be(e.a),o=be(e.b);return n<o?`${n}|${o}`:`${o}|${n}`}function _e(e){return`${e[0]},${e[1]},${e[2]}`}function Ro(e,n){let o=_e(e),t=_e(n);return o<t?`${o}|${t}`:`${t}|${o}`}function kt(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function To(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",kt(e.data)].join("|")}function Eo(e){let n=e.vertices;if(!n||n.length<3)return null;let o=n[0],t=[0,0,0];for(let c=1;c<n.length-1;c++)t=wt(t,wo(Te(n[c],o),Te(n[c+1],o)));let r=cn(t);return r?{normal:r,d:Oe(r,o)}:null}function zs(e,n,o){return Oe(e.normal,n.normal)>1-o&&Math.abs(e.d-n.d)<=o}function ws(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function ks(e,n){let o=n[e[0]]?.data,t=kt(o);for(let r of e)if(kt(n[r].data)!==t)return;return o?{...o}:void 0}function Rs(e,n){let o=e.map(i=>ws(i)?Eo(i):null),t=o.map(Boolean),r=new Map;for(let i=0;i<e.length;i++){if(!o[i])continue;let l=e[i].vertices;for(let u=0;u<l.length;u++){let m=Ro(l[u],l[(u+1)%l.length]),d=r.get(m),f={polygon:i,edge:u};d?d.push(f):r.set(m,[f])}}let c=e.map(()=>new Set);for(let i of r.values())if(!(i.length<2))for(let l=0;l<i.length;l++)for(let u=l+1;u<i.length;u++){let m=i[l].polygon,d=i[u].polygon,f=o[m],p=o[d];!f||!p||To(e[m])===To(e[d])&&zs(f,p,n)&&(c[m].add(d),c[d].add(m))}let a=new Set,s=[];for(let i=0;i<e.length;i++){if(!t[i]||a.has(i))continue;let l=[],u=[i];for(a.add(i);u.length>0;){let m=u.shift();l.push(m);for(let d of c[m])a.has(d)||(a.add(d),u.push(d))}s.push(l)}return{groups:s}}function Es(e,n){let o=new Set(e),t=new Map;for(let c of e){let a=n[c].vertices;for(let s=0;s<a.length;s++){let i=Ro(a[s],a[(s+1)%a.length]),l=t.get(i),u={polygon:c,edge:s};l?l.push(u):t.set(i,[u])}}let r=[];for(let c of t.values()){let a=c.filter(s=>o.has(s.polygon));if(a.length===1){let s=a[0],i=n[s.polygon].vertices;r.push({a:i[s.edge],b:i[(s.edge+1)%i.length]})}else if(a.length!==2)return null}return r}function Ds(e){let n=new Map;for(let o of e)n.set(_e(o.a),(n.get(_e(o.a))??0)+1),n.set(_e(o.b),(n.get(_e(o.b))??0)+1);for(let o of n.values())if(o%2!==0)return!1;return!0}function Do(e){let n=[e[0],e[1],e[2]],o=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[o]<0?[-n[0],-n[1],-n[2]]:n}function Ls(e){let n=Do(e);return`${rn(n[0],1e3)},${rn(n[1],1e3)},${rn(n[2],1e3)}`}function _s(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],o=Te(n,sn(e,Oe(n,e)));return cn(o)??[1,0,0]}function Gs(e,n,o){let t=new Map;for(let c of e){let a=Te(c.b,c.a),s=Te(a,sn(n,Oe(a,n))),i=cn(s);if(!i)continue;let l=Do(i),u=Ls(l),m=ko(s),d=t.get(u);d?d.weight+=m:t.set(u,{axis:l,weight:m})}let r=[...t.values()].sort((c,a)=>a.weight-c.weight).slice(0,o).map(c=>c.axis);return r.length===0&&r.push(_s(n)),r}function Oo(e,n,o,t){let r=Te(e,n);return[pe(Oe(r,o)),pe(Oe(r,t))]}function Ns(e){let n=[...e].sort((t,r)=>t-r),o=[];for(let t of n)(o.length===0||Math.abs(t-o[o.length-1])>1e-7)&&o.push(t);return o}function on(e,n){let[o,t]=e.a,[r,c]=e.b,a=(n-o)/(r-o);return pe(t+(c-t)*a)}function Rt(e){let n=[];for(let t of e)(n.length===0||Math.abs(t[0]-n[n.length-1][0])>1e-7||Math.abs(t[1]-n[n.length-1][1])>1e-7)&&n.push(t);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 o=[];for(let t=0;t<n.length;t++){let r=n[(t-1+n.length)%n.length],c=n[t],a=n[(t+1)%n.length],s=(c[0]-r[0])*(a[1]-c[1])-(c[1]-r[1])*(a[0]-c[0]);Math.abs(s)>1e-8&&o.push(c)}return o}function xn(e){let n=0;for(let o=0;o<e.length;o++){let t=e[o],r=e[(o+1)%e.length];n+=t[0]*r[1]-r[0]*t[1]}return n/2}function Io(e){let n=1/0,o=1/0,t=-1/0,r=-1/0;for(let[c,a]of e)n=Math.min(n,c),o=Math.min(o,a),t=Math.max(t,c),r=Math.max(r,a);return{minX:n,minY:o,maxX:t,maxY:r}}function $s(e,n){let o=Io(e),t=Io(n);return!(o.maxX<t.minX-1e-7||t.maxX<o.minX-1e-7||o.maxY<t.minY-1e-7||t.maxY<o.minY-1e-7)}function bn(e){return Math.abs(xn(e))}function Fs(e){if(e.length<3)return!1;let n=0;for(let o=0;o<e.length;o++){let t=e[o],r=e[(o+1)%e.length],c=e[(o+2)%e.length],a=(r[0]-t[0])*(c[1]-r[1])-(r[1]-t[1])*(c[0]-r[0]);if(Math.abs(a)<=1e-8)continue;let s=a>0?1:-1;if(n===0)n=s;else if(n!==s)return!1}return!0}function Us(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],c=e[0]-n[0],a=e[1]-n[1],s=t*a-r*c,i=Math.hypot(t,r);if(i<=1e-9||Math.abs(s)>Math.max(1e-8,i*1e-8))return!1;let l=c*t+a*r;return l>=-1e-8&&l<=t*t+r*r+1e-8}function Bs(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],c=t*t+r*r;return c<=1e-12?0:((e[0]-n[0])*t+(e[1]-n[1])*r)/c}function zo(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t],c=e[(t+1)%e.length],a=[{t:0,point:r},{t:1,point:c}];for(let i of n)zt(i,r)||zt(i,c)||Us(i,r,c)&&a.push({t:Bs(i,r,c),point:i});a.sort((i,l)=>i.t-l.t);let s=[];for(let i of a)s.some(l=>Math.abs(l.t-i.t)<=1e-8||zt(l.point,i.point))||s.push(i);for(let i=0;i<s.length-1;i++){let l=s[i].point,u=s[i+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||o.push({a:[pe(l[0]),pe(l[1])],b:[pe(u[0]),pe(u[1])]})}}return o}function js(e,n){if(!$s(e,n))return null;let o=[...zo(e,n),...zo(n,e)],t=new Map;for(let g of o){let x=Is(g),V=t.get(x);V?V.push(g):t.set(x,[g])}let r=!1,c=[];for(let g of t.values()){if(g.length===1){c.push(g[0]);continue}r=!0;let x=g.filter(C=>be(C.a)<be(C.b)).length,V=g.length-x;if(x!==V)return null}if(!r||c.length<3)return null;let a=new Map;for(let g of c){let x=be(g.a);if(a.has(x))return null;a.set(x,g)}let s=c[0],i=be(s.a),l=[],u=new Set,m=i;for(let g=0;g<=c.length;g++){let x=a.get(m);if(!x)return null;let V=`${be(x.a)}>${be(x.b)}`;if(u.has(V))return null;if(u.add(V),l.push(x.a),m=be(x.b),m===i)break}if(m!==i||u.size!==c.length)return null;let d=Rt(l);if(d.length<3||!Fs(d))return null;let f=bn(d),p=bn(e)+bn(n);return Math.abs(f-p)>Math.max(1e-5,p*1e-5)?null:xn(d)>=0?d:[...d].reverse()}function qs(e){let n=e.map(Rt).filter(t=>t.length>=3&&bn(t)>1e-8),o=!0;for(;o;){o=!1;for(let t=0;t<n.length;t++){for(let r=t+1;r<n.length;r++){let c=js(n[t],n[r]);if(c){n[t]=c,n.splice(r,1),o=!0;break}}if(o)break}}return n}function Hs(e,n,o){let t=new Map;return r=>{let c=pe(r[0]),a=pe(r[1]),s=`${c},${a}`,i=t.get(s);if(i)return[i[0],i[1],i[2]];let l=wt(e,wt(sn(n,c),sn(o,a))),u=[It(l[0]),It(l[1]),It(l[2])];return t.set(s,u),[u[0],u[1],u[2]]}}function Xs(e,n,o,t,r){let c=o[0]?.a;if(!c)return null;let a=cn(Te(r,sn(t,Oe(r,t))));if(!a)return null;let s=cn(wo(t,a));if(!s)return null;let i=[],l=[];for(let x of o){let V=Oo(x.a,c,a,s),C=Oo(x.b,c,a,s);Math.hypot(V[0]-C[0],V[1]-C[1])<=1e-7||(i.push({a:V,b:C}),l.push(V[0],C[0]))}let u=Ns(l);if(i.length<3||u.length<2)return null;let m=n[e[0]].color,d=ks(e,n),f=[];for(let x=0;x<u.length-1;x++){let V=u[x],C=u[x+1];if(C-V<=1e-7)continue;let v=(V+C)/2,M=i.filter(y=>{let P=Math.min(y.a[0],y.b[0]),S=Math.max(y.a[0],y.b[0]);return P<v&&v<S&&Math.abs(y.a[0]-y.b[0])>1e-7}).map(y=>({segment:y,yMid:on(y,v)})).sort((y,P)=>y.yMid-P.yMid);if(M.length!==0){if(M.length%2!==0)return null;for(let y=0;y<M.length;y+=2){let P=M[y].segment,S=M[y+1].segment,h=on(P,V),b=on(P,C),A=on(S,V),I=on(S,C),R=Rt([[V,h],[C,b],[C,I],[V,A]]);if(R.length<3||Math.abs(xn(R))<=1e-8)continue;let k=xn(R)>0?R:[...R].reverse();f.push(k)}}}if(f.length===0)return null;let p=Hs(c,a,s),g=qs(f).map(x=>({vertices:x.map(p),...m?{color:m}:{},...d?{data:d}:{}}));return ue(g)}function Ys(e,n,o){let t=Es(e,n);if(!t||t.length<3||!Ds(t))return null;let r=Eo(n[e[0]]);if(!r)return null;let c=null;for(let a of Gs(t,r.normal,o)){let s=Xs(e,n,t,r.normal,a);s&&(!c||s.length<c.length)&&(c=s)}return!c||c.length>=e.length?null:c}function Et(e,n={}){let o=n.minGroupPolygons??vs,t=n.maxCandidateAxes??Cs,r=n.planeEpsilon??As,c=e??[];if(c.length<o)return c;let{groups:a}=Rs(c,r);if(a.length===0)return c;let s=new Map,i=new Set;for(let u of a){if(u.length<o)continue;let m=Ys(u,c,t);if(m){s.set(u[0],m);for(let d of u)i.add(d)}}if(s.size===0)return c;let l=[];for(let u=0;u<c.length;u++){let m=s.get(u);if(m){l.push(...m);continue}i.has(u)||l.push(c[u])}return l}function Ws(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0;for(let[k,T,z]of n)o+=k,t+=T,r+=z;let c=1/n.length;o*=c,t*=c,r*=c;let a=n[0],s=n[1],i=n[2],l=s[0]-a[0],u=s[1]-a[1],m=s[2]-a[2],d=i[0]-a[0],f=i[1]-a[1],p=i[2]-a[2],g=u*p-m*f,x=m*d-l*p,V=l*f-u*d,C=Math.hypot(g,x,V);if(C<1e-9)return null;g/=C,x/=C,V/=C;let v=n.length-2,M=new Float64Array(v*9),y=0;for(let k=1;k<n.length-1;k++){let T=n[0],z=n[k],D=n[k+1];M[y++]=T[0],M[y++]=T[1],M[y++]=T[2],M[y++]=z[0],M[y++]=z[1],M[y++]=z[2],M[y++]=D[0],M[y++]=D[1],M[y++]=D[2]}let P=0,S=1/0,h=1/0,b=1/0,A=-1/0,I=-1/0,R=-1/0;for(let[k,T,z]of n){let D=k-o,L=T-t,w=z-r,O=D*D+L*L+w*w;O>P&&(P=O),k<S&&(S=k),k>A&&(A=k),T<h&&(h=T),T>I&&(I=T),z<b&&(b=z),z>R&&(R=z)}return{centroid:[o,t,r],normal:[g,x,V],vertices:n,triFlat:M,bcx:o,bcy:t,bcz:r,br2:P,minX:S,minY:h,minZ:b,maxX:A,maxY:I,maxZ:R}}function Ks(e,n,o,t,r,c,a,s){let i=a[s],l=a[s+1],u=a[s+2],m=a[s+3]-i,d=a[s+4]-l,f=a[s+5]-u,p=a[s+6]-i,g=a[s+7]-l,x=a[s+8]-u,V=r*x-c*g,C=c*p-t*x,v=t*g-r*p,M=m*V+d*C+f*v;if(M>-1e-9&&M<1e-9)return!1;let y=1/M,P=e-i,S=n-l,h=o-u,b=y*(P*V+S*C+h*v);if(b<0||b>1)return!1;let A=S*f-h*d,I=h*m-P*f,R=P*d-S*m,k=y*(t*A+r*I+c*R);return k<0||b+k>1?!1:y*(p*A+g*I+x*R)>.001}function Zs(e,n,o,t,r,c,a){let s=a.bcx-e,i=a.bcy-n,l=a.bcz-o,u=s*t+i*r+l*c,m=s-u*t,d=i-u*r,f=l-u*c;if(m*m+d*d+f*f>a.br2)return!1;let p=a.triFlat,g=p.length;for(let x=0;x<g;x+=9)if(Ks(e,n,o,t,r,c,p,x))return!0;return!1}var an=9,Qs=6,se=12;function Dt(e,n,o,t,r,c){let a=t-e,s=r-n,i=c-o;return a*s+s*i+i*a}function Js(e){let n=[];for(let P=0;P<e.length;P++)e[P]&&n.push(P);let o=n.length,t=new Int32Array(o);for(let P=0;P<o;P++)t[P]=n[P];let r=new Float64Array(o),c=new Float64Array(o),a=new Float64Array(o);for(let P=0;P<o;P++){let S=e[t[P]];r[P]=(S.minX+S.maxX)*.5,c[P]=(S.minY+S.maxY)*.5,a[P]=(S.minZ+S.maxZ)*.5}let s=2*Math.max(1,o)+1,i=new Float64Array(s*an),l=0,u=new Float64Array(se),m=new Float64Array(se),d=new Float64Array(se),f=new Float64Array(se),p=new Float64Array(se),g=new Float64Array(se),x=new Int32Array(se),V=new Float64Array(se-1),C=new Int32Array(se-1),v=new Float64Array(se-1),M=new Int32Array(se-1);function y(P,S){let h=l++,b=h*an,A=S-P,I=1/0,R=1/0,k=1/0,T=-1/0,z=-1/0,D=-1/0;for(let X=P;X<S;X++){let K=e[t[X]];K.minX<I&&(I=K.minX),K.maxX>T&&(T=K.maxX),K.minY<R&&(R=K.minY),K.maxY>z&&(z=K.maxY),K.minZ<k&&(k=K.minZ),K.maxZ>D&&(D=K.maxZ)}if(i[b]=I,i[b+1]=R,i[b+2]=k,i[b+3]=T,i[b+4]=z,i[b+5]=D,A<=Qs)return i[b+6]=1,i[b+7]=P,i[b+8]=S,h;let L=1/0,w=1/0,O=1/0,E=-1/0,_=-1/0,N=-1/0;for(let X=P;X<S;X++)r[X]<L&&(L=r[X]),r[X]>E&&(E=r[X]),c[X]<w&&(w=c[X]),c[X]>_&&(_=c[X]),a[X]<O&&(O=a[X]),a[X]>N&&(N=a[X]);let G=E-L,$=_-w,F=N-O;if(G===0&&$===0&&F===0)return i[b+6]=1,i[b+7]=P,i[b+8]=S,h;let q=Dt(I,R,k,T,z,D),j=q>0?1/q:0,U=A+1,B=0,H=0;for(let X=0;X<3;X++){let K=X===0?L:X===1?w:O,ae=X===0?G:X===1?$:F;if(ae===0)continue;let Pe=X===0?r:X===1?c:a,Ae=se/ae;u.fill(1/0),m.fill(1/0),d.fill(1/0),f.fill(-1/0),p.fill(-1/0),g.fill(-1/0),x.fill(0);for(let Y=P;Y<S;Y++){let W=(Pe[Y]-K)*Ae|0;W>=se&&(W=se-1);let le=e[t[Y]];le.minX<u[W]&&(u[W]=le.minX),le.maxX>f[W]&&(f[W]=le.maxX),le.minY<m[W]&&(m[W]=le.minY),le.maxY>p[W]&&(p[W]=le.maxY),le.minZ<d[W]&&(d[W]=le.minZ),le.maxZ>g[W]&&(g[W]=le.maxZ),x[W]++}let ke=1/0,Re=1/0,mt=1/0,dt=-1/0,pt=-1/0,gt=-1/0,co=0;for(let Y=0;Y<se-1;Y++)u[Y]<ke&&(ke=u[Y]),f[Y]>dt&&(dt=f[Y]),m[Y]<Re&&(Re=m[Y]),p[Y]>pt&&(pt=p[Y]),d[Y]<mt&&(mt=d[Y]),g[Y]>gt&&(gt=g[Y]),co+=x[Y],V[Y]=Dt(ke,Re,mt,dt,pt,gt),C[Y]=co;let yt=1/0,ht=1/0,bt=1/0,xt=-1/0,Pt=-1/0,Mt=-1/0,io=0;for(let Y=se-2;Y>=0;Y--){let W=Y+1;u[W]<yt&&(yt=u[W]),f[W]>xt&&(xt=f[W]),m[W]<ht&&(ht=m[W]),p[W]>Pt&&(Pt=p[W]),d[W]<bt&&(bt=d[W]),g[W]>Mt&&(Mt=g[W]),io+=x[W],v[Y]=Dt(yt,ht,bt,xt,Pt,Mt),M[Y]=io}for(let Y=0;Y<se-1;Y++){if(C[Y]===0||M[Y]===0)continue;let W=.125+(V[Y]*C[Y]+v[Y]*M[Y])*j;W<U&&(U=W,B=X,H=K+(Y+1)/Ae)}}let Z=B===0?r:B===1?c:a,J=P,ne=S-1;for(;J<=ne;)if(Z[J]<H)J++;else{let X=t[J];t[J]=t[ne],t[ne]=X;let K=r[J];r[J]=r[ne],r[ne]=K;let ae=c[J];c[J]=c[ne],c[ne]=ae;let Pe=a[J];a[J]=a[ne],a[ne]=Pe,ne--}let ie=J;(ie===P||ie===S)&&(ie=P+S>>1),i[b+6]=0;let oe=y(P,ie),Q=y(ie,S);return i[h*an+7]=oe,i[h*an+8]=Q,h}return o>0&&y(0,o),{data:i,nodeCount:l,polyIndices:t,meta:e}}function Lo(e,n,o,t,r,c,a,s,i){if(s.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:m}=s,d=t!==0?1/t:t>=0?1/0:-1/0,f=r!==0?1/r:r>=0?1/0:-1/0,p=c!==0?1/c:c>=0?1/0:-1/0,g=0;for(i[g++]=0;g>0;){let V=i[--g]*an,C=(l[V]-e)*d,v=(l[V+3]-e)*d,M=C<v?C:v,y=C<v?v:C,P=(l[V+1]-n)*f,S=(l[V+4]-n)*f,h=P<S?P:S,b=P<S?S:P;if(M>b||h>y)continue;h>M&&(M=h),b<y&&(y=b);let A=(l[V+2]-o)*p,I=(l[V+5]-o)*p,R=A<I?A:I,k=A<I?I:A;if(!(M>k||R>y)&&(k<y&&(y=k),!(y<.001)))if(l[V+6]===1){let T=l[V+7]|0,z=l[V+8]|0;for(let D=T;D<z;D++){let L=u[D];if(L===a)continue;let w=m[L];if(w&&Zs(e,n,o,t,r,c,w))return!0}}else i[g++]=l[V+7]|0,i[g++]=l[V+8]|0}return!1}function ec(e){let n=(1+Math.sqrt(5))/2,o=new Float64Array(e*3);for(let t=0;t<e;t++){let r=(t+.5)/e,c=Math.sqrt(Math.max(0,1-r*r)),a=2*Math.PI*(t/n);o[t*3]=c*Math.cos(a),o[t*3+1]=c*Math.sin(a),o[t*3+2]=r}return o}function nc(e){let n=Math.abs(e[0])>.9?0:1,o=Math.abs(e[0])>.9?1:0,t=o*e[2],r=-n*e[2],c=n*e[1]-o*e[0],a=Math.hypot(t,r,c);t/=a,r/=a,c/=a;let s=e[1]*c-e[2]*r,i=e[2]*t-e[0]*c,l=e[0]*r-e[1]*t;return{ux:t,uy:r,uz:c,vx:s,vy:i,vz:l}}function Ie(e,n){let o=n?.samples??8;if(e.length<4||o<1)return e;let t=e.map(Ws),r=ec(o),c=[],a=Js(t),s=new Int32Array(Math.max(64,a.nodeCount)),i=192,l=new Float64Array(i);for(let u=0;u<e.length;u++){let m=t[u];if(!m){c.push(e[u]);continue}let d=m.normal[0],f=m.normal[1],p=m.normal[2],g=.001*d,x=.001*f,V=.001*p;{let z=m.centroid[0]+g,D=m.centroid[1]+x,L=m.centroid[2]+V;if(!Lo(z,D,L,d,f,p,u,a,s)){c.push(e[u]);continue}}let{ux:C,uy:v,uz:M,vx:y,vy:P,vz:S}=nc(m.normal),h=m.centroid[0],b=m.centroid[1],A=m.centroid[2],I=m.vertices,R=I.length,k=0;l[k++]=h+g,l[k++]=b+x,l[k++]=A+V;for(let z=0;z<R;z++){let D=I[z];l[k++]=D[0]+(h-D[0])*.08+g,l[k++]=D[1]+(b-D[1])*.08+x,l[k++]=D[2]+(A-D[2])*.08+V}for(let z=0;z<R;z++){let D=I[z],L=I[(z+1)%R],w=(D[0]+L[0])*.5,O=(D[1]+L[1])*.5,E=(D[2]+L[2])*.5;l[k++]=w+(h-w)*.08+g,l[k++]=O+(b-O)*.08+x,l[k++]=E+(A-E)*.08+V}let T=!1;e:for(let z=0;z<r.length;z+=3){let D=r[z],L=r[z+1],w=r[z+2],O=D*C+L*y+w*d,E=D*v+L*P+w*f,_=D*M+L*S+w*p;for(let N=0;N<k;N+=3){let G=l[N],$=l[N+1],F=l[N+2];if(!Lo(G,$,F,O,E,_,u,a,s)){T=!0;break e}}}T&&c.push(e[u])}return c}var tc=3,oc=.03,rc=.02,ln={maxAngleDeg:tc,maxPlaneDisplacement:oc,maxBoundaryDisplacement:rc,isolatedPairs:!1},Ge={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725,isolatedPairs:!0},Mn=[{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.02},{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725},{maxAngleDeg:45,maxPlaneDisplacement:1,maxBoundaryDisplacement:.0725}],sc=[2,4,6,8,12],cc=300,ic=.3,ac=300,lc=16,uc=.015,_o=2.6,fc=3,mc=96,ze={minGroupPolygons:2,maxCandidateAxes:24},dc={maxGap:0,internalBoundaryLength:0,excessBoundaryLength:0};function $t(e,n={}){let o=n.meshResolution??"lossy",t=Lt(e,!1),r={baseline:t},c=t,a=ce(t),s=(l,u=ce(l))=>u>=a?!1:(c=l,a=u,!0),i=Pn(t,n.rectCover);if(i!==t&&s(i),o==="lossy"&&n.approximateMerge!==!1){let l=Ac(e),u=[],m=he(l,c,Ge.maxBoundaryDisplacement).metrics,d=n.approximateMerge===void 0||n.approximateMerge===!0,f=(C,v=!0)=>!vc(l,C.metrics,C.tolerance,v?m:null),p=(C,v)=>{s(C,v)},g=(C,v,M=Ge.maxBoundaryDisplacement)=>{!d||v>a+Uo(a)||u.push({polygons:C,cost:v,maxBoundaryDisplacement:M})},x=Go(n.approximateMerge,d?t:void 0);for(let C=0;C<x.length;C++){let v=x[C],M=Lt(e,v,r),y=ce(M),P=null,S=()=>(P??(P=he(l,M,v.maxBoundaryDisplacement)),P),h=!0;if(d||v.guard){let k=S();h=f(k,!!v.allowReferenceCracks)}if(!h&&y<a)continue;h&&(p(M,y),g(M,y,v.maxBoundaryDisplacement));let b=Pn(M,n.rectCover),A=ce(b),I=null,R=()=>(I??(I=he(l,b,v.maxBoundaryDisplacement)),I);if(b!==M&&A<a){let k=!0;(d||v.guard)&&(k=f(R(),!!v.allowReferenceCracks)),k&&(p(b,A),g(b,A,v.maxBoundaryDisplacement))}}if(d)for(let C of pc(e)){let v={baseline:ue(Ie(C))},M=ce(v.baseline),y=!0,P=null,S=()=>(P??(P=he(l,v.baseline,Ge.maxBoundaryDisplacement)),P);M<a&&(y=f(S())),y&&(p(v.baseline,M),g(v.baseline,M));let h=Pn(v.baseline,n.rectCover);if(h!==v.baseline){let b=ce(h);(b>=a||f(he(l,h,Ge.maxBoundaryDisplacement)))&&(p(h,b),g(h,b))}for(let b of Go(n.approximateMerge,v.baseline)){let A=Lt(C,b,v),I=ce(A),R=null,k=()=>(R??(R=he(l,A,b.maxBoundaryDisplacement)),R),T=!0;if(d||b.guard){let O=k();T=f(O,!!b.allowReferenceCracks)}if(!T&&I<a)continue;T&&(p(A,I),g(A,I,b.maxBoundaryDisplacement));let z=Pn(A,n.rectCover),D=ce(z),L=null,w=()=>(L??(L=he(l,z,b.maxBoundaryDisplacement)),L);if(z!==A&&D<a){let O=!0;(d||b.guard)&&(O=f(w(),!!b.allowReferenceCracks)),O&&(p(z,D),g(z,D,b.maxBoundaryDisplacement))}}}if(d)for(let C of Mn){let v=Yo({...C,isolatedPairs:!0}),M=Gc(c,v);if(M===c)continue;let y=ce(M);if(y>=a)continue;let P=he(l,M,v.maxBoundaryDisplacement);f(P)&&(p(M,y),g(M,y,v.maxBoundaryDisplacement))}let V=Pc(u,c,a,C=>(C.metrics??(C.metrics=he(l,C.polygons,C.maxBoundaryDisplacement).metrics),C.metrics),()=>he(l,c,Ge.maxBoundaryDisplacement).metrics);V&&(c=V.polygons,a=V.cost)}return c}function pc(e){let n=gc(e);if(n.eligiblePolygons<24||n.colorCount<8)return[];let o=[],t=new Set;for(let r of sc){let c=yc(e,r,n.colorCount);if(!c)continue;let a=bc(c);t.has(a)||(t.add(a),o.push(c))}return o}function gc(e){let n=new Set,o=0;for(let t of e)t.texture||t.material?.texture||t.uvs||t.textureTriangles?.length||Fo(t.color)&&(o+=1,n.add(t.color??"#cccccc"));return{eligiblePolygons:o,colorCount:n.size}}function yc(e,n,o){let t=!1,r=new Set,c=e.map(a=>{if(a.texture||a.material?.texture||a.uvs||a.textureTriangles?.length)return a;let s=Fo(a.color);if(!s)return a;let i=hc([Math.round(s[0]/n)*n,Math.round(s[1]/n)*n,Math.round(s[2]/n)*n]);return r.add(i),i===a.color?a:(t=!0,{...a,color:i})});return!t||r.size>=o?null:c}function Fo(e){let n=e??"#cccccc",o=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(n);if(o)return[parseInt(o[1]+o[1],16),parseInt(o[2]+o[2],16),parseInt(o[3]+o[3],16)];let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(n);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null}function hc(e){return`#${e.map(n=>Math.max(0,Math.min(255,Math.round(n))).toString(16).padStart(2,"0")).join("")}`}function bc(e){return e.map(n=>n.color??"").join("|")}function Go(e,n){if(e&&e!==!0)return typeof e.isolatedPairs=="boolean"?[{...e,guard:e.isolatedPairs===!1}]:[{...e,isolatedPairs:!0,guard:!1},{...e,isolatedPairs:!1,guard:!0}];if(n&&xc(n))return[{...Mn[0],isolatedPairs:!0,guard:!1,allowReferenceCracks:!0}];let o=[],t=new Set,r=n&&n.length>ac?[!0]:[!0,!1];for(let c=0;c<Mn.length;c++){let a=Mn[c];for(let s of r){let i={...a,isolatedPairs:s,guard:c>0||s===!1,allowReferenceCracks:!0},l=[i.maxAngleDeg,i.maxPlaneDisplacement,i.maxBoundaryDisplacement,i.isolatedPairs].join("|");t.has(l)||(t.add(l),o.push(i))}}return o.length===0?[{...Ge,guard:!1}]:o}function xc(e){return e.length<cc?!1:Ho(e)/e.length<=ic}function ce(e){let n=0;for(let o of e){let t=o.vertices.length,r=t<=4?0:Math.min(4,t-4)*.12,c=o.texture||o.material?.texture||o.textureTriangles?.length?.15:0;n+=1+r+c}return n}function Uo(e){return Math.max(lc,e*uc)}function Pc(e,n,o,t,r){if(e.length===0)return null;let c=Uo(o),a=e.find(u=>u.polygons===n),s=null,i=null,l=null;for(let u of e){if(u.polygons===n||u.cost>o+c)continue;let m=t(u);s??(s=a?t(a):r()),Vc(m,s)&&(!i||!l||Mc(u,m,i,l)<0)&&(i=u,l=m)}return i}function Mc(e,n,o,t){return n.maxGap-t.maxGap||n.internalBoundaryLength-t.internalBoundaryLength||n.excessBoundaryLength-t.excessBoundaryLength||e.cost-o.cost}function Vc(e,n){let o=Math.max(5e-4,n.maxGap*.02);if(e.maxGap<n.maxGap-o)return!0;if(e.maxGap>n.maxGap+o)return!1;let t=Math.max(8,n.internalBoundaryLength*.01);if(e.internalBoundaryLength<n.internalBoundaryLength-t)return!0;if(e.internalBoundaryLength>n.internalBoundaryLength+t)return!1;let r=Math.max(8,n.excessBoundaryLength*.01);return e.excessBoundaryLength<n.excessBoundaryLength-r}function vc(e,n,o,t=null){if(!t)return n.internalBoundaryLength>0||n.excessBoundaryLength>o;let r=Math.max(o*.1,1e-6),c=t.maxGap+r,a=o<=.08?Math.max(c,Math.min(o*.75,.04)):c,s=Math.max(o*2,t.internalBoundaryLength*.15),i=Math.max(o*2,t.excessBoundaryLength*.15);return n.maxGap>a||n.internalBoundaryLength>t.internalBoundaryLength+s||n.excessBoundaryLength>t.excessBoundaryLength+i}function Cc(e,n,o=0,t=Gt(e,o)){let r=e.edges,c=Bo(n),a=Gt(e,o),s=t>0?Tc(e,t):null,i={...dc,excessBoundaryLength:Math.max(0,c.boundaryLength-r.boundaryLength)};for(let l of c.boundarySegments){let u=Ne(l.a,l.b);if(r.boundaryKeys.has(u))continue;if(r.internalKeys.has(u)){i.internalBoundaryLength+=xe(l.a,l.b);continue}let m=s?zc(l,s,t):null;m!==null&&(i.maxGap=Math.max(i.maxGap,m),i.internalBoundaryLength+=xe(l.a,l.b))}return{metrics:i,tolerance:a}}function he(e,n,o=0){return Cc(e,n,o,Sc(e,o))}function Ac(e){let n=Oc(e),o=n>0?Math.min(.08,Math.max(.001,n*.001)):0;return{edges:Bo(e),baseTolerance:o,polygonCount:e.length,indexes:new Map}}function Gt(e,n=0){return Math.max(e.baseTolerance,n*1.05)}function Sc(e,n=0){return Math.max(Gt(e,n),e.baseTolerance*_o,n*_o)}function Tc(e,n){let o=n.toFixed(6),t=e.indexes.get(o);if(t)return t;let r=Ic(e.edges.internalSegments,n);return e.indexes.set(o,r),r}function Bo(e){let n=new Map;for(let s of e)for(let i=0;i<s.vertices.length;i++){let l=s.vertices[i],u=s.vertices[(i+1)%s.vertices.length],m=Ne(l,u),d=n.get(m);d?d.count+=1:n.set(m,{count:1,a:l,b:u})}let o=new Set,t=new Set,r=[],c=[],a=0;for(let[s,i]of n){let l={a:i.a,b:i.b};i.count===1?(o.add(s),r.push(l),a+=xe(l.a,l.b)):(t.add(s),c.push(l))}return{boundaryKeys:o,internalKeys:t,boundarySegments:r,internalSegments:c,boundaryLength:a}}function Oc(e){let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0;for(let s of e)for(let[i,l,u]of s.vertices)n=Math.min(n,i),o=Math.min(o,l),t=Math.min(t,u),r=Math.max(r,i),c=Math.max(c,l),a=Math.max(a,u);return Number.isFinite(n)?Math.hypot(r-n,c-o,a-t):0}function Ic(e,n){let o=Math.max(n*2,1e-6),t=new Map;for(let r of e){let[c,a,s]=jo(r,o),i=qo(c,a,s),l=t.get(i);l?l.push(r):t.set(i,[r])}return{cellSize:o,cells:t}}function zc(e,n,o){let[t,r,c]=jo(e,n.cellSize),a=null;for(let s=-1;s<=1;s++)for(let i=-1;i<=1;i++)for(let l=-1;l<=1;l++){let u=n.cells.get(qo(t+s,r+i,c+l));if(u)for(let m of u){let d=wc(e,m);d<=o&&(a=a===null?d:Math.min(a,d))}}return a}function jo(e,n){return[Math.floor((e.a[0]+e.b[0])/2/n),Math.floor((e.a[1]+e.b[1])/2/n),Math.floor((e.a[2]+e.b[2])/2/n)]}function qo(e,n,o){return`${e},${n},${o}`}function wc(e,n){return Math.min(Math.max(xe(e.a,n.a),xe(e.b,n.b)),Math.max(xe(e.a,n.b),xe(e.b,n.a)))}function Pn(e,n){if(n===!1)return e;let o=kc(e,n);if(!o)return e;let t=Et(e,o);return t.length<e.length?t:e}function kc(e,n){if(n&&n!==!0)return n;let o=e.length;return o>2200?null:o>1200?{...ze,maxCandidateAxes:Math.min(ze.maxCandidateAxes??24,2)}:o>300&&Ho(e)<=mc?{...ze,maxCandidateAxes:Math.min(ze.maxCandidateAxes??24,2)}:o>900?{...ze,maxCandidateAxes:Math.min(ze.maxCandidateAxes??24,4)}:ze}function Ho(e){let n=0;for(let o of e)o.vertices.length===3&&(n+=1);return n}function Lt(e,n,o){let t=Ot(e),r=o?.baseline??ue(Ie(t));if(!n)return r;let c=n===!0?ln:Yo(n);if(c.isolatedPairs){let s=Ec(Rc(t,o),c),i=ue(s);return i.length<r.length?i:r}let a=ue(Ie(Yc(t,c,o)));return a.length<r.length?a:r}function Xo(e,n){return n?(n.snapped||(n.snapped=vn(e)),n.snapped):vn(e)}function Rc(e,n){return n?(n.snappedInterior||(n.snappedInterior=Ie(Xo(e,n))),n.snappedInterior):Ie(vn(e))}function Yo(e){return{maxAngleDeg:e.maxAngleDeg??ln.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??ln.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??ln.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??ln.isolatedPairs}}function Ec(e,n){let o=e.map(m=>{let d=fn(m);return d?{polygon:m,normal:d.normal,area:d.area,materialKey:Ut(m)}:null}),t=new Map;for(let m=0;m<e.length;m++){let d=e[m];if(!(d.vertices.length!==3||!o[m]))for(let f=0;f<d.vertices.length;f++){let p=Ne(d.vertices[f],d.vertices[(f+1)%d.vertices.length]),g=t.get(p);g?g.push(m):t.set(p,[m])}}let r=[];for(let m of t.values()){if(m.length!==2)continue;let[d,f]=m,p=Xc(d,f,e,o,n);p&&r.push(p)}let c=new Set,a=new Map,s=new Set,i=Dc(r),l=Sn(i.flatMap(m=>m.vertexMoves));for(let m of i){c.add(m.a),c.add(m.b);let d=Math.min(m.a,m.b);a.set(d,m.polygon),s.add(Math.max(m.a,m.b))}let u=[];for(let m=0;m<e.length;m++){let d=a.get(m);if(d){u.push(d);continue}s.has(m)||u.push(e[m])}return l.size>0?Tn(u,l):u}function Dc(e){return e.length>3e3?Lc(e):_c(e)}function Lc(e){let n=new Map;for(let c of e)n.set(c.a,(n.get(c.a)??0)+1),n.set(c.b,(n.get(c.b)??0)+1);let o=[...e].sort((c,a)=>{let s=(n.get(c.a)??0)+(n.get(c.b)??0),i=(n.get(a.a)??0)+(n.get(a.b)??0);return s-i||c.score-a.score}),t=new Set,r=[];for(let c of o)t.has(c.a)||t.has(c.b)||(t.add(c.a),t.add(c.b),r.push(c));return r}function _c(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],m=n.get(u.a);m?m.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let o=[],t=new Array(e.length).fill(!0),r=new Map,c=new Nt;for(let[l,u]of n)r.set(l,u.length);let a=l=>(r.get(l.a)??0)+(r.get(l.b)??0),s=l=>{let u=e[l];c.push({degree:a(u),score:u.score,index:l})},i=(l,u)=>{if(!t[l])return;t[l]=!1;let m=e[l];for(let d of[m.a,m.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)s(l);for(;c.size()>0;){let l=c.pop();if(!t[l.index])continue;let u=e[l.index];if(a(u)!==l.degree){s(l.index);continue}o.push(u);let d=new Set;for(let f of[u.a,u.b])for(let p of n.get(f)??[])i(p,d);for(let f of d)for(let p of n.get(f)??[])t[p]&&s(p)}return o}var Nt=class{constructor(){this.items=[]}size(){return this.items.length}push(n){this.items.push(n);let o=this.items.length-1;for(;o>0;){let t=o-1>>1;if(_t(this.items[t],this.items[o])<=0)break;[this.items[t],this.items[o]]=[this.items[o],this.items[t]],o=t}}pop(){if(this.items.length===0)return null;let n=this.items[0],o=this.items.pop();if(this.items.length>0){this.items[0]=o;let t=0;for(;;){let r=t*2+1,c=r+1,a=t;if(r<this.items.length&&_t(this.items[r],this.items[a])<0&&(a=r),c<this.items.length&&_t(this.items[c],this.items[a])<0&&(a=c),a===t)break;[this.items[t],this.items[a]]=[this.items[a],this.items[t]],t=a}}return n}};function _t(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function Gc(e,n){let o=e,t=ce(o),r=Uc(o);for(let c=0;c<fc;c++){let a=Nc(o,n,r);if(!a)break;let s=ce(a.polygons);if(s>=t)break;o=a.polygons,t=s,r=a.origins}return o===e?e:o}function Nc(e,n,o){let t=e.map(d=>{let f=fn(d);return f?{polygon:d,normal:f.normal,area:f.area,materialKey:Ut(d)}:null}),r=new Map;for(let d=0;d<e.length;d++){let f=e[d];if(!(!t[d]||f.vertices.length<3))for(let p=0;p<f.vertices.length;p++){let g=Ne(f.vertices[p],f.vertices[(p+1)%f.vertices.length]),x=r.get(g);x?x.push({polygon:d,edge:p}):r.set(g,[{polygon:d,edge:p}])}}let c=[];for(let d of r.values()){if(d.length!==2)continue;let[f,p]=d,g=$c(f.polygon,f.edge,p.polygon,p.edge,e,t,n);g&&c.push(g)}if(c.length===0)return null;c.sort((d,f)=>f.score-d.score);let a=new Set,s=[];for(let d of c)a.has(d.a)||a.has(d.b)||(a.add(d.a),a.add(d.b),s.push(d));if(s.length===0)return null;let i=Sn(s.flatMap(d=>d.vertexMoves));if(!Fc(i,o,n.maxBoundaryDisplacement))return null;let l=Tn(e,i),u=Bc(e,i,o),m=ue(l);return ce(m)<ce(e)?{polygons:m,origins:jc(m,u)}:null}function $c(e,n,o,t,r,c,a){let s=r[e],i=r[o],l=c[e],u=c[o];if(!l||!u||s.vertices.length===3&&i.vertices.length===3||!nr(s,i,l,u))return null;let m=Math.abs(ge(l.normal,u.normal)),d=Math.cos(a.maxAngleDeg*Math.PI/180);if(m<d)return null;let f=No(s,i,n)??No(i,s,t);if(!f||f.length<4||f.length>10)return null;let p=Ko(f);if(!p)return null;let g=0,x=0;for(let h of f){let b=Math.abs(On(h,p));g=Math.max(g,b),x+=b*b}if(g>Math.min(a.maxPlaneDisplacement,a.maxBoundaryDisplacement))return null;let V=f.map(h=>In(h,p));if(!Zo(V,p.normal))return null;let C=fn({vertices:V});if(!C||ge(C.normal,l.normal)<.2||ge(C.normal,u.normal)<.2)return null;let v=[...f.map((h,b)=>({key:re(h),target:V[b]})),...Wo([s,i],p)],M=Tn([s,i],Sn(v)),y=ce([s,i]),P=ce(ue(M));if(P>=y)return null;let S=y-P-(x/f.length+g*.25+(1-m)*.1);return S<=0?null:{a:e,b:o,vertexMoves:v,score:S}}function No(e,n,o){let t=e.vertices,r=n.vertices,c=t[o],a=t[(o+1)%t.length],s=-1;for(let u=0;u<r.length;u++)if(ve(r[u],a)&&ve(r[(u+1)%r.length],c)){s=u;break}if(s<0)return null;let i=[],l=(o+1)%t.length;for(i.push(t[l]);l!==o;)l=(l+1)%t.length,i.push(t[l]);for(l=(s+2)%r.length;l!==s;){let u=r[l];ve(u,i[i.length-1])||i.push(u),l=(l+1)%r.length}return i.length>1&&ve(i[0],i[i.length-1])&&i.pop(),i}function Fc(e,n,o){for(let[t,r]of e){let c=qc(t),a=n.get(t)??(c?[c]:[]);if(a.length===0)return!1;for(let s of a)if(xe(s,r)>o+1e-6)return!1}return!0}function Uc(e){let n=new Map;for(let o of e){for(let t of o.vertices)Vn(n,re(t),t);for(let t of o.textureTriangles??[])for(let r of t.vertices)Vn(n,re(r),r)}return n}function Bc(e,n,o){let t=new Map;for(let r of e){let c=[...r.vertices,...(r.textureTriangles??[]).flatMap(a=>a.vertices)];for(let a of c){let s=re(a),i=n.get(s)??a,l=re(i);for(let u of o.get(s)??[a])Vn(t,l,u)}}return t}function jc(e,n){let o=new Map;for(let t of e){let r=[...t.vertices,...(t.textureTriangles??[]).flatMap(c=>c.vertices)];for(let c of r){let a=re(c);for(let s of n.get(a)??[c])Vn(o,a,s)}}return o}function Vn(e,n,o){let t=e.get(n);if(!t){e.set(n,[o]);return}let r=re(o);t.some(c=>re(c)===r)||t.push(o)}function qc(e){let n=e.split(",").map(Number);return n.length===3&&n.every(Number.isFinite)?[n[0],n[1],n[2]]:null}function Sn(e){let n=new Map;for(let t of e){let r=n.get(t.key);r?(r.x+=t.target[0],r.y+=t.target[1],r.z+=t.target[2],r.count+=1):n.set(t.key,{x:t.target[0],y:t.target[1],z:t.target[2],count:1})}let o=new Map;for(let[t,r]of n)o.set(t,[r.x/r.count,r.y/r.count,r.z/r.count]);return o}function Hc(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t].vertices,c=n[t]?.vertices;if(!c||c.length!==r.length)continue;for(let i=0;i<r.length;i++)o.push({key:re(r[i]),target:c[i]});let a=e[t].textureTriangles??[],s=n[t]?.textureTriangles??[];for(let i=0;i<a.length;i++){let l=s[i];if(l)for(let u=0;u<a[i].vertices.length;u++)o.push({key:re(a[i].vertices[u]),target:l.vertices[u]})}}return o}function Wo(e,n){let o=[];for(let t of e)for(let r of t.textureTriangles??[])for(let c of r.vertices)o.push({key:re(c),target:In(c,n)});return o}function Tn(e,n){return e.map(o=>{let t=!1,r=s=>{let i=n.get(re(s));return i?(t=!0,i):s},c=o.vertices.map(r),a=Ft(o.textureTriangles,r);return t?{...o,vertices:c,...a?{textureTriangles:a}:{}}:o})}function Xc(e,n,o,t,r){let c=o[e],a=o[n],s=t[e],i=t[n];if(!s||!i||c.vertices.length!==3||a.vertices.length!==3||!nr(c,a,s,i))return null;let l=jt(c,a);if(!l)return null;let[u,m,d,f]=l;if((d+1)%a.vertices.length===f)return null;let g=Math.abs(ge(s.normal,i.normal)),x=Math.cos(r.maxAngleDeg*Math.PI/180);if(g<x)return null;let V=(m+1)%c.vertices.length,C=3-d-f,v=[c.vertices[m],c.vertices[V],c.vertices[u],a.vertices[C]],M=Ko(v);if(!M)return null;let y=0,P=0;for(let A of v){let I=Math.abs(On(A,M));y=Math.max(y,I),P+=I*I}if(y>Math.min(r.maxPlaneDisplacement,r.maxBoundaryDisplacement))return null;let S=v.map(A=>In(A,M));if(!Zo(S,M.normal))return null;let h=fn({vertices:S});if(!h||ge(h.normal,s.normal)<.2||ge(h.normal,i.normal)<.2)return null;let b={vertices:v,color:c.color,...c.data?{data:{...c.data}}:{}};if(Bt(c,a)&&c.uvs&&a.uvs&&c.texture){b.texture=c.texture,b.uvs=[[...c.uvs[m]],[...c.uvs[V]],[...c.uvs[u]],[...a.uvs[C]]];let A=Wc([c,a]);A?.length&&(b.textureTriangles=A)}return{a:e,b:n,polygon:b,vertexMoves:[...v.map((A,I)=>({key:re(A),target:S[I]})),...Wo([c,a],M)],score:P/v.length+y*.25+(1-g)*.1}}function Ko(e){if(e.length<3)return null;let n=0,o=0,t=0,r=0,c=0,a=0;for(let i=0;i<e.length;i++){let l=e[i],u=e[(i+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),o+=(l[2]-u[2])*(l[0]+u[0]),t+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],c+=l[1],a+=l[2]}let s=cr([n,o,t]);return s?{normal:s,point:[r/e.length,c/e.length,a/e.length]}:null}function Zo(e,n){let o=0;for(let t=0;t<e.length;t++){let r=e[t],c=e[(t+1)%e.length],a=e[(t+2)%e.length],s=ge(sr(un(c,r),un(a,c)),n);if(Math.abs(s)<=1e-9)continue;let i=s>0?1:-1;if(o===0)o=i;else if(o!==i)return!1}return!0}function Yc(e,n,o){let t=Xo(e,o),r=ni(t,n);if(r<=0)return t;let c=t.map(f=>{let p=fn(f);return p?{polygon:f,normal:p.normal,area:p.area,materialKey:Ut(f)}:null}),a=ri(t,c),s=new Set,i=Array(t.length),l=[],u=(f,p)=>{i[f]=p};for(let f=0;f<t.length;f++){let p=c[f];if(s.has(f))continue;if(!p){u(f,t[f]);continue}let g=ci(f,c,a,s,r,n);for(let V of g)s.add(V);if(g.length<2){u(f,t[f]);continue}let x=Qc(g,t,c,a,r,n);l.push(...x.vertexMoves);for(let V of g)u(V,x.polygons.get(V)??t[V])}let m=i.flatMap(f=>f?[f]:[]),d=l.length>0?Tn(m,Sn(l)):m;return vn(d)}function vn(e){let n=er(e),o=1e-4;if(n<=0)return e;let t=ti(n),r=oi(o);return e.map(c=>{let a=m=>t.snap(m),s=c.vertices.map(a),i=c.uvs&&c.uvs.length===c.vertices.length?c.uvs.map(m=>r.snap(m)):void 0,l=Ft(c.textureTriangles,a),u={...c,vertices:s,...i?{uvs:i}:{},...l?{textureTriangles:l}:{}};return{...u,...u.texture?{textureTriangles:Qo(u)}:{}}})}function Qo(e){if(e.texture){if(e.textureTriangles?.length)return Zc(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return Kc(e.vertices,e.uvs)}}function Wc(e){let n=e.flatMap(o=>Qo(o)??[]);return n.length>0?n:void 0}function Kc(e,n){let o=[];for(let t=1;t<e.length-1;t++)o.push({vertices:[[...e[0]],[...e[t]],[...e[t+1]]],uvs:[[...n[0]],[...n[t]],[...n[t+1]]]});return o}function Zc(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function Ft(e,n){if(e?.length)return e.map(o=>({vertices:o.vertices.map(n),uvs:o.uvs.map(t=>[...t])}))}function Qc(e,n,o,t,r,c){let a=Jo(e,n,o,r,c);return a?ei(a):Jc(e,n,o,t,r,c)}function Jc(e,n,o,t,r,c){let a=new Set(e),s=[];for(let m of e)for(let d of t.get(m)??[]){if(m>=d||!a.has(d))continue;let f=Jo([m,d],n,o,r,c);f&&s.push(f)}s.sort((m,d)=>d.score-m.score);let i=new Set,l=new Map,u=[];for(let m of s)if(!m.indices.some(d=>i.has(d))){u.push(...m.vertexMoves);for(let d=0;d<m.indices.length;d++){let f=m.indices[d];i.add(f),l.set(f,n[f])}}return{polygons:l,vertexMoves:u}}function ei(e){let n=new Map;for(let o=0;o<e.indices.length;o++)n.set(e.indices[o],e.source[o]);return{polygons:n,vertexMoves:e.vertexMoves}}function Jo(e,n,o,t,r){let c=tr(e,o);if(!c||!or(e,o,c,t,r))return null;let a=e.map(u=>n[u]),s=a.map(u=>li(u,c)),i=ce(ue(a)),l=ce(ue(s));return l>=i?null:{indices:e,source:a,projected:s,vertexMoves:Hc(a,s),score:i-l}}function ni(e,n){return er(e)<=0?0:n.maxPlaneDisplacement}function er(e){let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0;for(let i of e)for(let[l,u,m]of i.vertices)n=Math.min(n,l),o=Math.min(o,u),t=Math.min(t,m),r=Math.max(r,l),c=Math.max(c,u),a=Math.max(a,m);if(!Number.isFinite(n))return 0;let s=Math.hypot(r-n,c-o,a-t);return s<=0?0:Math.min(.025,Math.max(1e-4,s*25e-5))}function ti(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,c,a)=>`${r},${c},${a}`;return{snap(r){let c=o(r[0]),a=o(r[1]),s=o(r[2]);for(let m=-1;m<=1;m++)for(let d=-1;d<=1;d++)for(let f=-1;f<=1;f++){let p=n.get(t(c+m,a+d,s+f));if(p){for(let g of p)if(xe(r,g)<=e)return[g[0],g[1],g[2]]}}let i=[r[0],r[1],r[2]],l=t(c,a,s),u=n.get(l);return u?u.push(i):n.set(l,[i]),i}}}function oi(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,c)=>`${r},${c}`;return{snap(r){let c=o(r[0]),a=o(r[1]);for(let u=-1;u<=1;u++)for(let m=-1;m<=1;m++){let d=n.get(t(c+u,a+m));if(d){for(let f of d)if(Math.hypot(r[0]-f[0],r[1]-f[1])<=e)return[f[0],f[1]]}}let s=[r[0],r[1]],i=t(c,a),l=n.get(i);return l?l.push(s):n.set(i,[s]),s}}}function Ut(e){return`${e.color??"#cccccc"}|${e.texture??""}|${e.uvs?"uv":"plain"}`}function fn(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0,c=n[0];for(let s=1;s<n.length-1;s++){let i=un(n[s],c),l=un(n[s+1],c),u=sr(i,l);o+=u[0],t+=u[1],r+=u[2]}let a=Math.hypot(o,t,r);return a<=1e-10?null:{normal:[o/a,t/a,r/a],area:a/2}}function ri(e,n){let o=new Map,t=new Map;for(let r=0;r<e.length;r++){let c=e[r];if(!(!n[r]||c.vertices.length<3))for(let a=0;a<c.vertices.length;a++){let s=Ne(c.vertices[a],c.vertices[(a+1)%c.vertices.length]),i=o.get(s);i?i.push(r):o.set(s,[r])}}for(let r of o.values())for(let c=0;c<r.length;c++)for(let a=c+1;a<r.length;a++){let s=r[c],i=r[a];si(e[s],e[i],n[s],n[i])&&($o(t,s,i),$o(t,i,s))}return t}function si(e,n,o,t){if(!o||!t||o.materialKey!==t.materialKey||!!e.uvs!=!!n.uvs)return!1;if(Cn(e)||Cn(n))return Bt(e,n);if(!e.uvs||!n.uvs)return!0;let r=jt(e,n);if(!r)return!1;let[c,a,s,i]=r;return An(e.uvs[c],n.uvs[s])&&An(e.uvs[a],n.uvs[i])}function nr(e,n,o,t){return o.materialKey!==t.materialKey?!1:Cn(e)||Cn(n)?Bt(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function Cn(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Bt(e,n){if(!e.texture||!n.texture||e.texture!==n.texture||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 o=jt(e,n);if(!o)return!1;let[t,r,c,a]=o;return An(e.uvs[t],n.uvs[c])&&An(e.uvs[r],n.uvs[a])}function $o(e,n,o){let t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}function ci(e,n,o,t,r,c){let a=[e],s=new Set([e]),i=[e];for(;i.length>0;){let l=i.shift();for(let u of o.get(l)??[]){if(t.has(u)||s.has(u))continue;let m=n[u],d=n[e];!m||!d||m.materialKey===d.materialKey&&ii([...a,u],n,r,c)&&(a.push(u),s.add(u),i.push(u))}}return a}function ii(e,n,o,t){let r=tr(e,n);return!!r&&or(e,n,r,o,t)}function tr(e,n){let o=n[e[0]];if(!o)return null;let t=0,r=0,c=0,a=0,s=0,i=0,l=0;for(let f of e){let p=n[f];if(!p)return null;let g=ge(o.normal,p.normal)<0?-1:1,x=Math.max(p.area,1e-6);t+=p.normal[0]*g*x,r+=p.normal[1]*g*x,c+=p.normal[2]*g*x;for(let V of p.polygon.vertices)a+=V[0],s+=V[1],i+=V[2],l+=1}let u=cr([t,r,c]);if(!u||l===0)return null;let m=rr(e,n),d=ai(e,n,u,m);if(d){let f=(d.min+d.max)/2;return{normal:u,point:[u[0]*f,u[1]*f,u[2]*f]}}return{normal:u,point:[a/l,s/l,i/l]}}function ai(e,n,o,t){let r=1/0,c=-1/0;for(let a of e){let s=n[a];if(s)for(let i of s.polygon.vertices){if(!t.has(re(i)))continue;let l=ge(i,o);r=Math.min(r,l),c=Math.max(c,l)}}return Number.isFinite(r)&&Number.isFinite(c)?{min:r,max:c}:null}function or(e,n,o,t,r){let c=Math.cos(r.maxAngleDeg*Math.PI/180),a=rr(e,n);for(let s of e){let i=n[s];if(!i||Math.abs(ge(i.normal,o.normal))<c)return!1;for(let l of i.polygon.vertices){let u=a.has(re(l))?r.maxBoundaryDisplacement:t;if(Math.abs(On(l,o))>u)return!1}}return!0}function rr(e,n){let o=new Map;for(let r of e){let c=n[r];if(!c)continue;let a=c.polygon.vertices;for(let s=0;s<a.length;s++){let i=a[s],l=a[(s+1)%a.length],u=Ne(i,l),m=o.get(u);m?m.count+=1:o.set(u,{count:1,a:i,b:l})}}let t=new Set;for(let r of o.values())r.count===1&&(t.add(re(r.a)),t.add(re(r.b)));return t}function li(e,n){let o=r=>In(r,n),t=Ft(e.textureTriangles,o);return{...e,vertices:e.vertices.map(o),...t?{textureTriangles:t}:{}}}function jt(e,n){for(let o=0;o<e.vertices.length;o++){let t=(o+1)%e.vertices.length;for(let r=0;r<n.vertices.length;r++){let c=(r+1)%n.vertices.length;if(ve(e.vertices[o],n.vertices[r])&&ve(e.vertices[t],n.vertices[c]))return[o,t,r,c];if(ve(e.vertices[o],n.vertices[c])&&ve(e.vertices[t],n.vertices[r]))return[o,t,c,r]}}return null}function Ne(e,n){let o=re(e),t=re(n);return o<t?`${o}|${t}`:`${t}|${o}`}function re(e){return`${e[0]},${e[1]},${e[2]}`}function ve(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function An(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function un(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function sr(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 ge(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function xe(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function cr(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 On(e,n){return ge(un(e,n.point),n.normal)}function In(e,n){let o=On(e,n);return[e[0]-n.normal[0]*o,e[1]-n.normal[1]*o,e[2]-n.normal[2]*o]}var zn=1e-5,ir=.001,ar=6;function qt(e){let n=e.vertices;if(n.length<3)return null;let o=n[0],t=0,r=0,c=0;for(let s=1;s+1<n.length;s++){let i=n[s],l=n[s+1],u=i[1]-o[1],m=i[0]-o[0],d=i[2]-o[2],f=l[1]-o[1],p=l[0]-o[0],g=l[2]-o[2];t-=m*g-d*p,r-=d*f-u*g,c-=u*p-m*f}let a=Math.hypot(t,r,c);return a<1e-9?null:[t/a,r/a,c/a]}function lr(e,n){let o=n.meshRotation,t=o?yn(e,o[0]??0,o[1]??0,o[2]??0):e;return yn(t,n.rotX,0,n.rotY)[2]}function Ht(e,n,o=zn){return lr(e,n)>o}function ui(e,n,o=zn){let t=qt(e);return t===null||Ht(t,n,o)}function ur(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function fr(e){let n=new Map;for(let o of e){if(!o)continue;let t=ur(o);n.has(t)||n.set(t,o)}return Array.from(n,([o,t])=>({key:o,normal:t}))}function fi(e){return fr(e.map(qt))}function mr(e,n=ir){let o=Math.abs(e[0]),t=Math.abs(e[1]),r=Math.abs(e[2]),c=Math.max(o,t,r);return c>1-n&&o+t+r-c<n}function mi(e){return e.length<=ar&&e.every(({normal:n})=>mr(n))}function di(e,n,o=zn){let t=[];for(let{key:r,normal:c}of e)Ht(c,n,o)&&t.push(r);return t.sort(),t.join("|")}function Xt(e,n,o,t,r){let c=(p,g,x)=>{let V=[0,0,0];return V[e]=p,V[(e+1)%3]=g,V[(e+2)%3]=x,V},a=c(n,-t,-t),s=c(n,t,-t),i=c(n,t,t),l=c(n,-t,t),u=c(o,-t,-t),m=c(o,t,-t),d=c(o,t,t),f=c(o,-t,t);return[{vertices:[a,s,i,l],color:r},{vertices:[u,m,d,f],color:r},{vertices:[a,s,m,u],color:r},{vertices:[s,i,d,m],color:r},{vertices:[i,l,f,d],color:r},{vertices:[l,a,u,f],color:r}]}function dr(e={}){let n=e.size??5,o=e.thickness??.025,t=e.negative??!1,r=e.xColor??"#ff3a3a",c=e.yColor??"#3aff3a",a=e.zColor??"#3a8aff",s=n*o/2,i=t?-n:0;return[...Xt(0,i,n,s,r),...Xt(1,i,n,s,c),...Xt(2,i,n,s,a)]}function pr(e,n,o,t){let r=[0,0,0];return r[e]=n,r[(e+1)%3]=o,r[(e+2)%3]=t,r}function pi(e,n,o,t,r){let c=(p,g,x)=>pr(e,p,g,x),a=c(n,-t,-t),s=c(n,t,-t),i=c(n,t,t),l=c(n,-t,t),u=c(o,-t,-t),m=c(o,t,-t),d=c(o,t,t),f=c(o,-t,t);return[{vertices:[a,s,i,l],color:r},{vertices:[u,m,d,f],color:r},{vertices:[a,s,m,u],color:r},{vertices:[s,i,d,m],color:r},{vertices:[i,l,f,d],color:r},{vertices:[l,a,u,f],color:r}]}function gi(e,n,o,t,r){let c=(m,d,f)=>pr(e,m,d,f),a=c(n,-t,-t),s=c(n,t,-t),i=c(n,t,t),l=c(n,-t,t),u=c(o,0,0);return[{vertices:[a,s,i,l],color:r},{vertices:[a,s,u],color:r},{vertices:[s,i,u],color:r},{vertices:[i,l,u],color:r},{vertices:[l,a,u],color:r}]}function yi(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function gr(e){let n=e.axis,o=e.sign??1,t=e.shaftLength??4,r=e.shaftHalfThickness??.05,c=e.headLength??.8,a=e.headHalfThickness??.2,s=e.color??"#ffffff",i=e.shaft??!0,l=t*o,u=Math.min(0,l),m=Math.max(0,l),d=l,f=(t+c)*o,p=gi(n,d,f,a,s),g=o===-1?yi(p):p;return i?[...pi(n,u,m,r,s),...g]:g}function wn(e,n,o){let t=[0,0,0],r=(e+1)%3,c=(e+2)%3;return t[r]=Math.cos(o)*n,t[c]=Math.sin(o)*n,t}function yr(e){let n=e.axis,o=e.radius,t=e.halfThickness??Math.max(.05,o*.04),r=e.segments??32,c=e.color??"#ffffff",a=o-t,s=o+t,i=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,m=(l+1)/r*Math.PI*2,d=wn(n,a,u),f=wn(n,a,m),p=wn(n,s,u),g=wn(n,s,m);i.push({vertices:[d,p,g,f],color:c})}return i}function hr(e){let n=e.axis,o=e.outerRadius,t=e.color??"#ffffff",r=(n+1)%3,c=(n+2)%3,a=(s,i)=>{let l=[0,0,0];return l[n]=0,l[r]=s,l[c]=i,l};return[{vertices:[a(-o,-o),a(o,-o),a(o,o),a(-o,o)],color:t}]}function br(e){let n=e.axis,o=e.size??.4,t=e.offset??o*2,r=typeof t=="number"?t:t[0],c=typeof t=="number"?t:t[1],a=e.along??0,s=e.color??"#ffffff",i=(n+1)%3,l=(n+2)%3,u=(m,d)=>{let f=[0,0,0];return f[n]=a,f[i]=r+m,f[l]=c+d,f};return[{vertices:[u(-o,-o),u(o,-o),u(o,o),u(-o,o)],color:s}]}function kn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=[[r+o,c,a],[r-o,c,a],[r,c+o,a],[r,c-o,a],[r,c,a+o],[r,c,a-o]];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:[s[l[0]],s[l[1]],s[l[2]]],color:t}))}function Rn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/Math.sqrt(3),i=[[r+s,c+s,a+s],[r-s,c-s,a+s],[r-s,c+s,a-s],[r+s,c-s,a-s]];return[[0,2,1],[0,1,3],[0,3,2],[1,2,3]].map(u=>({vertices:[i[u[0]],i[u[1]],i[u[2]]],color:t}))}function En(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/2,i=[[r-s,c-s,a-s],[r+s,c-s,a-s],[r+s,c+s,a-s],[r-s,c+s,a-s],[r-s,c-s,a+s],[r+s,c-s,a+s],[r+s,c+s,a+s],[r-s,c+s,a+s]];return[[4,5,6,7],[1,0,3,2],[5,1,2,6],[0,4,7,3],[7,6,2,3],[0,1,5,4]].map(u=>({vertices:[i[u[0]],i[u[1]],i[u[2]],i[u[3]]],color:t}))}function Dn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=1/s,l=o/Math.sqrt(3),m=[[-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,-s,-i],[0,-s,i],[0,s,-i],[0,s,i],[-i,0,-s],[i,0,-s],[-i,0,s],[i,0,s],[-s,-i,0],[-s,i,0],[s,-i,0],[s,i,0]].map(([f,p,g])=>[r+f*l,c+p*l,a+g*l]);return[[0,8,9,1,16],[0,12,13,4,8],[0,16,17,2,12],[1,9,5,15,14],[1,14,3,17,16],[2,10,6,13,12],[2,17,3,11,10],[3,14,15,7,11],[4,13,6,19,18],[4,18,5,9,8],[5,18,19,7,15],[6,10,11,7,19]].map(f=>({vertices:f.map(p=>m[p]),color:t}))}function Ln(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),u=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]].map(([d,f,p])=>[r+d*i,c+f*i,a+p*i]);return[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]].map(d=>({vertices:[u[d[0]],u[d[1]],u[d[2]]],color:t}))}function xr(e,n){let o=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);return[e[0]/o*n,e[1]/o*n,e[2]/o*n]}function _n(e){let{center:n,size:o,subdivisions:t=1,color:r="#ffffff"}=e,[c,a,s]=n,i=(1+Math.sqrt(5))/2,l=o/Math.sqrt(1+i*i),m=[[0,-1,-i],[0,-1,i],[0,1,-i],[0,1,i],[-1,-i,0],[-1,i,0],[1,-i,0],[1,i,0],[-i,0,-1],[i,0,-1],[-i,0,1],[i,0,1]].map(([f,p,g])=>xr([f*l,p*l,g*l],o)),d=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]];for(let f=0;f<t;f++){let p=new Map,g=[],x=(V,C)=>{let v=V<C?`${V}_${C}`:`${C}_${V}`,M=p.get(v);if(M!==void 0)return M;let y=m[V],P=m[C],S=[(y[0]+P[0])/2,(y[1]+P[1])/2,(y[2]+P[2])/2],h=m.length;return m.push(xr(S,o)),p.set(v,h),h};for(let[V,C,v]of d){let M=x(V,C),y=x(C,v),P=x(v,V);g.push([V,M,P],[M,C,y],[P,y,v],[M,y,P])}d=g}return d.map(([f,p,g])=>({vertices:[[m[f][0]+c,m[f][1]+a,m[f][2]+s],[m[p][0]+c,m[p][1]+a,m[p][2]+s],[m[g][0]+c,m[g][1]+a,m[g][2]+s]],color:r}))}function Gn(e){let{center:n,radius:o,height:t,sides:r=16,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[],d=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r,g=a+o*Math.cos(p),x=i+o*Math.sin(p);m.push([g,s-l,x]),d.push([g,s+l,x])}for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d[f],d[p],m[p],m[f]],color:c})}return u.push({vertices:[...d].reverse(),color:c}),u.push({vertices:[...m],color:c}),u}function Nn(e){let{center:n,radius:o,height:t,sides:r=16,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r;m.push([a+o*Math.cos(p),s-l,i+o*Math.sin(p)])}let d=[a,s+l,i];for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d,m[p],m[f]],color:c})}return u.push({vertices:[...m],color:c}),u}function $n(e){let{center:n,majorRadius:o,minorRadius:t,segments:r=24,sides:c=12,color:a="#ffffff"}=e,[s,i,l]=n,u=[];for(let d=0;d<r;d++){let f=2*Math.PI*d/r,p=Math.cos(f),g=Math.sin(f),x=[];for(let V=0;V<c;V++){let C=2*Math.PI*V/c,v=o+t*Math.cos(C);x.push([s+v*p,i+t*Math.sin(C),l+v*g])}u.push(x)}let m=[];for(let d=0;d<r;d++){let f=(d+1)%r;for(let p=0;p<c;p++){let g=(p+1)%c;m.push({vertices:[u[d][p],u[f][p],u[f][g],u[d][g]],color:a})}}return m}function Fn(e){let{center:n,radius:o,height:t,sides:r=4,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r;m.push([a+o*Math.cos(p),s-l,i+o*Math.sin(p)])}let d=[a,s+l,i];for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d,m[p],m[f]],color:c})}return u.push({vertices:[...m],color:c}),u}function Un(e){let{center:n,radius:o,height:t,sides:r=6,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[],d=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r,g=a+o*Math.cos(p),x=i+o*Math.sin(p);m.push([g,s-l,x]),d.push([g,s+l,x])}for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d[f],d[p],m[p],m[f]],color:c})}return u.push({vertices:[...d].reverse(),color:c}),u.push({vertices:[...m],color:c}),u}function Bn(e){let{center:n,radius:o,height:t,sides:r=6,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[],d=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r,g=p+Math.PI/r;m.push([a+o*Math.cos(p),s-l,i+o*Math.sin(p)]),d.push([a+o*Math.cos(g),s+l,i+o*Math.sin(g)])}for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d[f],m[p],m[f]],color:c}),u.push({vertices:[d[f],d[p],m[p]],color:c})}return u.push({vertices:[...d].reverse(),color:c}),u.push({vertices:[...m],color:c}),u}function jn(e){let{center:n,radius:o,halfHeight:t,sides:r=6,color:c="#ffffff"}=e,[a,s,i]=n,l=[],u=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r;u.push([a+o*Math.cos(p),s,i+o*Math.sin(p)])}let m=[a,s+t,i],d=[a,s-t,i];for(let f=0;f<r;f++){let p=(f+1)%r;l.push({vertices:[m,u[p],u[f]],color:c})}for(let f=0;f<r;f++){let p=(f+1)%r;l.push({vertices:[d,u[f],u[p]],color:c})}return l}function qn(e){let{center:n,radius:o,halfHeight:t,sides:r=5,color:c="#ffffff"}=e,[a,s,i]=n,l=Math.cos(Math.PI/r),u=t*(1-l)/(1+l),m=[],d=[],f=[];for(let x=0;x<r;x++){let V=2*Math.PI*x/r,C=V+Math.PI/r;d.push([a+o*Math.cos(V),s+u,i+o*Math.sin(V)]),f.push([a+o*Math.cos(C),s-u,i+o*Math.sin(C)])}let p=[a,s+t,i],g=[a,s-t,i];for(let x=0;x<r;x++){let V=(x+1)%r;m.push({vertices:[p,d[V],f[x],d[x]],color:c})}for(let x=0;x<r;x++){let V=(x+1)%r;m.push({vertices:[g,f[x],d[V],f[V]],color:c})}return m}function Hn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),l=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],u=l.map(([p,g,x])=>[r+p*i,c+g*i,a+x*i]);function m(p,g){return p[0]*g[0]+p[1]*g[1]+p[2]*g[2]}function d(p){let g=Math.abs(p[0])<.9?[1,0,0]:[0,1,0],x=m(g,p),V=g[0]-x*p[0],C=g[1]-x*p[1],v=g[2]-x*p[2],M=Math.sqrt(V*V+C*C+v*v),y=[V/M,C/M,v/M],P=[p[1]*y[2]-p[2]*y[1],p[2]*y[0]-p[0]*y[2],p[0]*y[1]-p[1]*y[0]];return{u:y,w:P}}let f=[];for(let p=0;p<12;p++){let g=l[p],x=m(g,g),V=-1,C=1/0;for(let T=0;T<12;T++){if(T===p)continue;let z=m(l[T],g);z<C&&(C=z,V=T)}let v=[];for(let T=0;T<12;T++)T===p||T===V||v.push({idx:T,d:m(l[T],g)});v.sort((T,z)=>z.d-T.d);let M=v.slice(0,5).map(T=>T.idx),y=[g[0]/Math.sqrt(x),g[1]/Math.sqrt(x),g[2]/Math.sqrt(x)],{u:P,w:S}=d(y);M.sort((T,z)=>{let D=l[T],L=l[z],w=Math.atan2(m(D,S),m(D,P)),O=Math.atan2(m(L,S),m(L,P));return w-O});let b=[0,2,4,1,3].map(T=>M[T]),A=0,I=0,R=0;for(let T of b)A+=u[T][0],I+=u[T][1],R+=u[T][2];let k=[A/5,I/5,R/5];for(let T=0;T<5;T++){let z=u[b[T]],D=u[b[(T+2)%5]],L=[z[0]-k[0],z[1]-k[1],z[2]-k[2]],w=[D[0]-k[0],D[1]-k[1],D[2]-k[2]],O=L[1]*w[2]-L[2]*w[1],E=L[2]*w[0]-L[0]*w[2],_=L[0]*w[1]-L[1]*w[0],N=k[0]-r,G=k[1]-c,$=k[2]-a,F=O*N+E*G+_*$<0;f.push({vertices:F?[k,D,z]:[k,z,D],color:t})}}return f}function Xn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),l=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],u=l.map(([p,g,x])=>[r+p*i,c+g*i,a+x*i]);function m(p,g){return p[0]*g[0]+p[1]*g[1]+p[2]*g[2]}function d(p){let g=Math.abs(p[0])<.9?[1,0,0]:[0,1,0],x=m(g,p),V=g[0]-x*p[0],C=g[1]-x*p[1],v=g[2]-x*p[2],M=Math.sqrt(V*V+C*C+v*v),y=[V/M,C/M,v/M],P=[p[1]*y[2]-p[2]*y[1],p[2]*y[0]-p[0]*y[2],p[0]*y[1]-p[1]*y[0]];return{u:y,w:P}}let f=[];for(let p=0;p<12;p++){let g=l[p],x=m(g,g),V=-1,C=1/0;for(let U=0;U<12;U++){if(U===p)continue;let B=m(l[U],g);B<C&&(C=B,V=U)}let v=[];for(let U=0;U<12;U++)U===p||U===V||v.push({idx:U,d:m(l[U],g)});v.sort((U,B)=>B.d-U.d);let M=v.slice(0,5).map(U=>U.idx),y=[g[0]/Math.sqrt(x),g[1]/Math.sqrt(x),g[2]/Math.sqrt(x)],{u:P,w:S}=d(y);M.sort((U,B)=>{let H=l[U],Z=l[B];return Math.atan2(m(H,S),m(H,P))-Math.atan2(m(Z,S),m(Z,P))});let h=0,b=0,A=0;for(let U of M)h+=u[U][0],b+=u[U][1],A+=u[U][2];h/=5,b/=5,A/=5;let I=u[M[0]],R=u[M[1]],k=u[M[2]],T=R[0]-I[0],z=R[1]-I[1],D=R[2]-I[2],L=k[0]-I[0],w=k[1]-I[1],O=k[2]-I[2],E=z*O-D*w,_=D*L-T*O,N=T*w-z*L,G=h-r,$=b-c,F=A-a,j=E*G+_*$+N*F<0?[...M].reverse():M;f.push({vertices:j.map(U=>u[U]),color:t})}return f}function Yn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=1/s,l=o/Math.sqrt(3),m=[[-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,-s,-i],[0,-s,i],[0,s,-i],[0,s,i],[-i,0,-s],[i,0,-s],[-i,0,s],[i,0,s],[-s,-i,0],[-s,i,0],[s,-i,0],[s,i,0]].map(([g,x,V])=>[r+g*l,c+x*l,a+V*l]),d=[[0,8,9,1,16],[0,12,13,4,8],[0,16,17,2,12],[1,9,5,15,14],[1,14,3,17,16],[2,10,6,13,12],[2,17,3,11,10],[3,14,15,7,11],[4,13,6,19,18],[4,18,5,9,8],[5,18,19,7,15],[6,10,11,7,19]],f=[0,2,4,1,3],p=[];for(let g of d){let x=f.map(y=>g[y]),V=0,C=0,v=0;for(let y of x)V+=m[y][0],C+=m[y][1],v+=m[y][2];let M=[V/5,C/5,v/5];for(let y=0;y<5;y++){let P=m[x[y]],S=m[x[(y+2)%5]],h=[P[0]-M[0],P[1]-M[1],P[2]-M[2]],b=[S[0]-M[0],S[1]-M[1],S[2]-M[2]],A=h[1]*b[2]-h[2]*b[1],I=h[2]*b[0]-h[0]*b[2],R=h[0]*b[1]-h[1]*b[0],k=M[0]-r,T=M[1]-c,z=M[2]-a,D=A*k+I*T+R*z<0;p.push({vertices:D?[M,S,P]:[M,P,S],color:t})}}return p}function Wn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),l=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],u=l.map(([f,p,g])=>[r+f*i,c+p*i,a+g*i]),m=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]],d=Array(12).fill(-1);for(let f=0;f<12;f++){let p=1/0;for(let g=0;g<12;g++){if(g===f)continue;let x=l[f][0]*l[g][0]+l[f][1]*l[g][1]+l[f][2]*l[g][2];x<p&&(p=x,d[f]=g)}}return m.map(([f,p,g])=>({vertices:[u[d[f]],u[d[g]],u[d[p]]],color:t}))}function $e(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/Math.sqrt(2),l=[[1,1,0],[1,-1,0],[-1,1,0],[-1,-1,0],[1,0,1],[1,0,-1],[-1,0,1],[-1,0,-1],[0,1,1],[0,1,-1],[0,-1,1],[0,-1,-1]].map(([d,f,p])=>[r+d*s,c+f*s,a+p*s]),u=[[0,8,4],[0,5,9],[1,4,10],[1,11,5],[2,6,8],[2,9,7],[3,10,6],[3,7,11]],m=[[8,6,10,4],[9,5,11,7],[0,4,1,5],[2,7,3,6],[0,9,2,8],[1,10,3,11]];return[...u.map(d=>({vertices:[l[d[0]],l[d[1]],l[d[2]]],color:t})),...m.map(d=>({vertices:[l[d[0]],l[d[1]],l[d[2]],l[d[3]]],color:t}))]}function Fe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],l=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]],u=new Map,m=[];function d(b,A){return b<A?`${b},${A}`:`${A},${b}`}function f(b,A){let I=d(b,A);if(u.has(I))return u.get(I);let[R,k,T]=i[b],[z,D,L]=i[A],w=m.length;return m.push([(R+z)/2,(k+D)/2,(T+L)/2]),u.set(I,w),w}let p=Array.from({length:12},()=>[]),g=l.map(([b,A,I])=>{let R=f(b,A),k=f(A,I),T=f(I,b);return p[b].includes(R)||p[b].push(R),p[b].includes(T)||p[b].push(T),p[A].includes(R)||p[A].push(R),p[A].includes(k)||p[A].push(k),p[I].includes(k)||p[I].push(k),p[I].includes(T)||p[I].push(T),[R,k,T]}),[x,V,C]=m[0],v=Math.sqrt(x*x+V*V+C*C),M=o/v,y=m.map(([b,A,I])=>[r+b*M,c+A*M,a+I*M]);function P(b,A){let I=0,R=0,k=0;for(let H of b)I+=m[H][0],R+=m[H][1],k+=m[H][2];let T=b.length;I/=T,R/=T,k/=T;let[z,D,L]=A,[w,O,E]=m[b[0]],_=w-I,N=O-R,G=E-k,$=_*z+N*D+G*L;_-=$*z,N-=$*D,G-=$*L;let F=Math.sqrt(_*_+N*N+G*G);_/=F,N/=F,G/=F;let q=D*G-L*N,j=L*_-z*G,U=z*N-D*_,B=b.map(H=>{let[Z,J,ne]=m[H],ie=Z-I,oe=J-R,Q=ne-k,X=ie*_+oe*N+Q*G,K=ie*q+oe*j+Q*U;return{i:H,angle:Math.atan2(K,X)}});return B.sort((H,Z)=>H.angle-Z.angle),B.map(H=>H.i)}let S=g.map(([b,A,I])=>{let[R,k,T]=m[b],[z,D,L]=m[A],[w,O,E]=m[I],_=[(R+z+w)/3,(k+D+O)/3,(T+L+E)/3];return{vertices:P([b,A,I],_).map(G=>y[G]),color:t}}),h=i.map((b,A)=>{let I=p[A];return{vertices:P(I,b).map(T=>y[T]),color:t}});return[...S,...h]}function Ue(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=1/Math.sqrt(3),i=[[1,1,1],[-1,-1,1],[-1,1,-1],[1,-1,-1]],l=Array.from({length:4},()=>new Array(4)),u=[];for(let v=0;v<4;v++)for(let M=0;M<4;M++){if(v===M)continue;let[y,P,S]=i[v],[h,b,A]=i[M],I=[2/3*y+1/3*h,2/3*P+1/3*b,2/3*S+1/3*A];l[v][M]=I,u.push(I)}let m=0;for(let[v,M,y]of u){let P=Math.sqrt(v*v+M*M+y*y);P>m&&(m=P)}let d=o/m,f=(v,M)=>{let[y,P,S]=l[v][M];return[r+y*d,c+P*d,a+S*d]};function p(v){let M=[0,1,2,3].filter(G=>G!==v),[y,P,S]=M,h=f(v,y),b=f(v,P),A=f(v,S),[I,R,k]=i[v],T=b[0]-h[0],z=b[1]-h[1],D=b[2]-h[2],L=A[0]-h[0],w=A[1]-h[1],O=A[2]-h[2],E=z*O-D*w,_=D*L-T*O,N=T*w-z*L;return E*I+_*R+N*k<0?[h,A,b]:[h,b,A]}function g(v,M,y){let P=[f(v,M),f(M,v),f(M,y),f(y,M),f(y,v),f(v,y)],[S,h,b]=i[v],[A,I,R]=i[M],[k,T,z]=i[y],D=(S+A+k)/3,L=(h+I+T)/3,w=(b+R+z)/3,O=P[0],E=P[1],_=P[2],N=E[0]-O[0],G=E[1]-O[1],$=E[2]-O[2],F=_[0]-O[0],q=_[1]-O[1],j=_[2]-O[2],U=G*j-$*q,B=$*F-N*j,H=N*q-G*F;return U*D+B*L+H*w<0&&P.reverse(),P}let x=[0,1,2,3].map(v=>({vertices:p(v),color:t})),C=[[0,2,1],[0,1,3],[0,3,2],[1,2,3]].map(([v,M,y])=>({vertices:g(v,M,y),color:t}));return[...x,...C]}function Be(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(2-Math.sqrt(2))/2,i=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],l=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],u=new Map;function m(y,P){let S=`${y},${P}`;if(u.has(S))return u.get(S);let[h,b,A]=i[y],[I,R,k]=i[P],T=[(1-s)*h+s*I,(1-s)*b+s*R,(1-s)*A+s*k];return u.set(S,T),T}for(let[y,P]of l)m(y,P),m(P,y);let d=0;for(let y of u.values()){let[P,S,h]=y,b=Math.sqrt(P*P+S*S+h*h);b>d&&(d=b)}let f=o/d,p=y=>[r+y[0]*f,c+y[1]*f,a+y[2]*f];function g(y,P){return p(m(y,P))}function x(y,P){let[S,h,b]=P,A=y[0],I=y[1],R=y[2],k=I[0]-A[0],T=I[1]-A[1],z=I[2]-A[2],D=R[0]-A[0],L=R[1]-A[1],w=R[2]-A[2],O=T*w-z*L,E=z*D-k*w,_=k*L-T*D;return O*S+E*h+_*b<0?[...y].reverse():y}let V=[[1,3,4],[0,2,5],[1,3,6],[0,2,7],[0,5,7],[1,4,6],[2,5,7],[3,4,6]],C=i.map(([y,P,S],h)=>{let[b,A,I]=V[h],R=[g(h,b),g(h,A),g(h,I)];return{vertices:x(R,[y,P,S]),color:t}}),M=[{corners:[4,5,6,7],normal:[0,0,1]},{corners:[1,0,3,2],normal:[0,0,-1]},{corners:[5,1,2,6],normal:[1,0,0]},{corners:[0,4,7,3],normal:[-1,0,0]},{corners:[7,6,2,3],normal:[0,1,0]},{corners:[0,1,5,4],normal:[0,-1,0]}].map(({corners:y,normal:P})=>{let[S,h,b,A]=y,I=[g(S,h),g(h,S),g(h,b),g(b,h),g(b,A),g(A,b),g(A,S),g(S,A)];return{vertices:x(I,P),color:t}});return[...C,...M]}function je(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/Math.sqrt(5),i=new Set,l=[];for(let C=0;C<3;C++){let v=(C+1)%3,M=(C+2)%3;for(let y of[-1,1])for(let P of[-1,1])for(let S of[!1,!0]){let h=[0,0,0];h[v]=S?y*2:y*1,h[M]=S?P*1:P*2;let b=`${h[0]},${h[1]},${h[2]}`;i.has(b)||(i.add(b),l.push(h))}}let u=l.map(([C,v,M])=>[r+C*s,c+v*s,a+M*s]),m=new Map;for(let C=0;C<l.length;C++){let[v,M,y]=l[C];m.set(`${v},${M},${y}`,C)}function d(C,v,M){let y=`${C},${v},${M}`,P=m.get(y);if(P===void 0)throw new Error(`Vertex not found: (${C},${v},${M})`);return P}function f(C,v){let M=0,y=0,P=0;for(let G of C)M+=l[G][0],y+=l[G][1],P+=l[G][2];let S=C.length;M/=S,y/=S,P/=S;let[h,b,A]=v,[I,R,k]=l[C[0]],T=I-M,z=R-y,D=k-P,L=T*h+z*b+D*A;T-=L*h,z-=L*b,D-=L*A;let w=Math.sqrt(T*T+z*z+D*D);T/=w,z/=w,D/=w;let O=b*D-A*z,E=A*T-h*D,_=h*z-b*T,N=C.map(G=>{let[$,F,q]=l[G],j=$-M,U=F-y,B=q-P,H=j*T+U*z+B*D,Z=j*O+U*E+B*_;return{i:G,angle:Math.atan2(Z,H)}});return N.sort((G,$)=>G.angle-$.angle),N.map(G=>G.i)}let g=[{indices:[d(2,0,1),d(2,1,0),d(2,0,-1),d(2,-1,0)],normal:[1,0,0]},{indices:[d(-2,0,1),d(-2,1,0),d(-2,0,-1),d(-2,-1,0)],normal:[-1,0,0]},{indices:[d(0,2,1),d(1,2,0),d(0,2,-1),d(-1,2,0)],normal:[0,1,0]},{indices:[d(0,-2,1),d(1,-2,0),d(0,-2,-1),d(-1,-2,0)],normal:[0,-1,0]},{indices:[d(1,0,2),d(0,1,2),d(-1,0,2),d(0,-1,2)],normal:[0,0,1]},{indices:[d(1,0,-2),d(0,1,-2),d(-1,0,-2),d(0,-1,-2)],normal:[0,0,-1]}].map(({indices:C,normal:v})=>({vertices:f(C,v).map(M=>u[M]),color:t})),V=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]].map(([C,v,M])=>{let y=[];for(let S=0;S<l.length;S++){let[h,b,A]=l[S];Math.abs(C*h+v*b+M*A-3)<1e-9&&y.push(S)}let P=[C/Math.sqrt(3),v/Math.sqrt(3),M/Math.sqrt(3)];return{vertices:f(y,P).map(S=>u[S]),color:t}});return[...g,...V]}function qe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=1/s,l=[[-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,-s,-i],[0,-s,i],[0,s,-i],[0,s,i],[-i,0,-s],[i,0,-s],[-i,0,s],[i,0,s],[-s,-i,0],[-s,i,0],[s,-i,0],[s,i,0]],u=[[0,8,9,1,16],[0,12,13,4,8],[0,16,17,2,12],[1,9,5,15,14],[1,14,3,17,16],[2,10,6,13,12],[2,17,3,11,10],[3,14,15,7,11],[4,13,6,19,18],[4,18,5,9,8],[5,18,19,7,15],[6,10,11,7,19]],m=new Set,d=[];for(let h of u)for(let b=0;b<5;b++){let A=h[b],I=h[(b+1)%5],R=A<I?`${A},${I}`:`${I},${A}`;m.has(R)||(m.add(R),d.push([A,I]))}let f=(3-Math.sqrt(5))/4,p=new Map;function g(h,b){let A=`${h},${b}`;if(p.has(A))return p.get(A);let[I,R,k]=l[h],[T,z,D]=l[b],L=[(1-f)*I+f*T,(1-f)*R+f*z,(1-f)*k+f*D];return p.set(A,L),L}for(let[h,b]of d)g(h,b),g(b,h);let x=0;for(let h of p.values()){let[b,A,I]=h,R=Math.sqrt(b*b+A*A+I*I);R>x&&(x=R)}let V=o/x,C=Array.from({length:20},()=>[]);for(let[h,b]of d)C[h].push(b),C[b].push(h);function v(h,b){let[A,I,R]=g(h,b);return[r+A*V,c+I*V,a+R*V]}function M(h,b){let[A,I,R]=b,k=h[0],T=h[1],z=h[2],D=T[0]-k[0],L=T[1]-k[1],w=T[2]-k[2],O=z[0]-k[0],E=z[1]-k[1],_=z[2]-k[2],N=L*_-w*E,G=w*O-D*_,$=D*E-L*O;return N*A+G*I+$*R<0?[...h].reverse():h}function y(h,b){let A=0,I=0,R=0;for(let[B,H,Z]of h)A+=B,I+=H,R+=Z;let k=h.length;A/=k,I/=k,R/=k;let[T,z,D]=b,[L,w,O]=h[0],E=L-A,_=w-I,N=O-R,G=E*T+_*z+N*D;E-=G*T,_-=G*z,N-=G*D;let $=Math.sqrt(E*E+_*_+N*N);E/=$,_/=$,N/=$;let F=z*N-D*_,q=D*E-T*N,j=T*_-z*E,U=h.map(B=>{let H=B[0]-A,Z=B[1]-I,J=B[2]-R,ne=H*E+Z*_+J*N,ie=H*F+Z*q+J*j;return{pt:B,angle:Math.atan2(ie,ne)}});return U.sort((B,H)=>B.angle-H.angle),U.map(B=>B.pt)}let P=l.map(([h,b,A],I)=>{let[R,k,T]=C[I],z=[g(I,R),g(I,k),g(I,T)],L=y(z,[h,b,A]).map(([w,O,E])=>[r+w*V,c+O*V,a+E*V]);return{vertices:M(L,[h,b,A]),color:t}}),S=u.map(h=>{let[b,A,I,R,k]=h,T=[g(b,A),g(A,b),g(A,I),g(I,A),g(I,R),g(R,I),g(R,k),g(k,R),g(k,b),g(b,k)],[z,D,L,w,O]=h.map(q=>l[q]),E=(z[0]+D[0]+L[0]+w[0]+O[0])/5,_=(z[1]+D[1]+L[1]+w[1]+O[1])/5,N=(z[2]+D[2]+L[2]+w[2]+O[2])/5,G=[E,_,N],F=y(T,G).map(([q,j,U])=>[r+q*V,c+j*V,a+U*V]);return{vertices:M(F,G),color:t}});return[...P,...S]}function He(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],l=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]],u=new Set,m=[];for(let[P,S,h]of l)for(let[b,A]of[[P,S],[S,h],[h,P]]){let I=b<A?`${b},${A}`:`${A},${b}`;u.has(I)||(u.add(I),m.push([b,A]))}let d=1/3,f=new Map;function p(P,S){let h=`${P},${S}`;if(f.has(h))return f.get(h);let[b,A,I]=i[P],[R,k,T]=i[S],z=[(1-d)*b+d*R,(1-d)*A+d*k,(1-d)*I+d*T];return f.set(h,z),z}for(let[P,S]of m)p(P,S),p(S,P);let g=0;for(let P of f.values()){let[S,h,b]=P,A=Math.sqrt(S*S+h*h+b*b);A>g&&(g=A)}let x=o/g,V=Array.from({length:12},()=>[]);for(let[P,S]of m)V[P].push(S),V[S].push(P);function C(P,S){let[h,b,A]=S,I=P[0],R=P[1],k=P[2],T=R[0]-I[0],z=R[1]-I[1],D=R[2]-I[2],L=k[0]-I[0],w=k[1]-I[1],O=k[2]-I[2],E=z*O-D*w,_=D*L-T*O,N=T*w-z*L;return E*h+_*b+N*A<0?[...P].reverse():P}function v(P,S){let h=0,b=0,A=0;for(let[j,U,B]of P)h+=j,b+=U,A+=B;let I=P.length;h/=I,b/=I,A/=I;let[R,k,T]=S,[z,D,L]=P[0],w=z-h,O=D-b,E=L-A,_=w*R+O*k+E*T;w-=_*R,O-=_*k,E-=_*T;let N=Math.sqrt(w*w+O*O+E*E);w/=N,O/=N,E/=N;let G=k*E-T*O,$=T*w-R*E,F=R*O-k*w,q=P.map(j=>{let U=j[0]-h,B=j[1]-b,H=j[2]-A,Z=U*w+B*O+H*E,J=U*G+B*$+H*F;return{pt:j,angle:Math.atan2(J,Z)}});return q.sort((j,U)=>j.angle-U.angle),q.map(j=>j.pt)}let M=i.map(([P,S,h],b)=>{let A=V[b].map(k=>p(b,k)),R=v(A,[P,S,h]).map(([k,T,z])=>[r+k*x,c+T*x,a+z*x]);return{vertices:C(R,[P,S,h]),color:t}}),y=l.map(([P,S,h])=>{let b=[p(P,S),p(S,P),p(S,h),p(h,S),p(h,P),p(P,h)],A=i[P],I=i[S],R=i[h],k=[(A[0]+I[0]+R[0])/3,(A[1]+I[1]+R[1])/3,(A[2]+I[2]+R[2])/3],z=v(b,k).map(([D,L,w])=>[r+D*x,c+L*x,a+w*x]);return{vertices:C(z,k),color:t}});return[...M,...y]}function hi(e,n){if(n.length<=3)return!0;let[o,t,r]=e[n[0]],[c,a,s]=e[n[1]],[i,l,u]=e[n[2]],m=c-o,d=a-t,f=s-r,p=i-o,g=l-t,x=u-r,V=d*x-f*g,C=f*p-m*x,v=m*g-d*p,M=Math.sqrt(V*V+C*C+v*v);if(M<1e-10)return!1;let y=1/M,P=(V*o+C*t+v*r)*y;for(let S=3;S<n.length;S++){let[h,b,A]=e[n[S]];if(Math.abs((V*h+C*b+v*A)*y-P)>1e-6)return!1}return!0}function bi(e,n){let o=0,t=0,r=0;for(let h of n)o+=e[h][0],t+=e[h][1],r+=e[h][2];let c=n.length;o/=c,t/=c,r/=c;let[a,s,i]=e[n[0]],[l,u,m]=e[n[1]],[d,f,p]=e[n[2]],g=l-a,x=u-s,V=m-i,C=d-a,v=f-s,M=p-i,y=x*M-V*v,P=V*C-g*M,S=g*v-x*C;return y*o+P*t+S*r>0}function xi(e){let n=e.indexOf(Math.min(...e));return[...e.slice(n),...e.slice(0,n)].join(",")}function te(e,n,o){let t=e.length,r=new Set,c=[];function a(s,i){let l=s[s.length-1];if(s.length===o){if(!n[l].includes(i)||!hi(e,s)||!bi(e,s))return;let u=xi(s);r.has(u)||(r.add(u),c.push([...s]));return}for(let u of n[l])s.includes(u)||u<=i||a([...s,u],i)}for(let s=0;s<t;s++)a([s],s);return c}function fe(e,n=1e-6){let o=e.length,t=1/0;for(let c=0;c<o;c++)for(let a=c+1;a<o;a++){let s=e[c][0]-e[a][0],i=e[c][1]-e[a][1],l=e[c][2]-e[a][2],u=Math.sqrt(s*s+i*i+l*l);u>1e-10&&u<t&&(t=u)}let r=Array.from({length:o},()=>[]);for(let c=0;c<o;c++)for(let a=c+1;a<o;a++){let s=e[c][0]-e[a][0],i=e[c][1]-e[a][1],l=e[c][2]-e[a][2],u=Math.sqrt(s*s+i*i+l*l);Math.abs(u-t)<n&&(r[c].push(a),r[a].push(c))}return{adj:r,edgeLen:t}}function me(e,n,o){let t=0,r=0,c=0;for(let P of n)t+=e[P][0],r+=e[P][1],c+=e[P][2];let a=n.length;t/=a,r/=a,c/=a;let[s,i,l]=o,[u,m,d]=e[n[0]],f=u-t,p=m-r,g=d-c,x=f*s+p*i+g*l;f-=x*s,p-=x*i,g-=x*l;let V=Math.sqrt(f*f+p*p+g*g);f/=V,p/=V,g/=V;let C=i*g-l*p,v=l*f-s*g,M=s*p-i*f,y=n.map(P=>{let[S,h,b]=e[P],A=S-t,I=h-r,R=b-c,k=A*f+I*p+R*g,T=A*C+I*v+R*M;return{i:P,angle:Math.atan2(T,k)}});return y.sort((P,S)=>P.angle-S.angle),y.map(P=>P.i)}function de(e,n){let o=0,t=0,r=0;for(let s of n)o+=e[s][0],t+=e[s][1],r+=e[s][2];let c=n.length;o/=c,t/=c,r/=c;let a=Math.sqrt(o*o+t*t+r*r);return[o/a,t/a,r/a]}function Xe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=1,i=1+Math.sqrt(2),l=1+2*Math.sqrt(2),u=[[s,i,l],[s,l,i],[i,s,l],[i,l,s],[l,s,i],[l,i,s]],m=[];for(let[b,A,I]of u)for(let R of[-1,1])for(let k of[-1,1])for(let T of[-1,1])m.push([R*b,k*A,T*I]);let d=new Set,f=[];for(let b of m){let A=`${b[0].toFixed(9)},${b[1].toFixed(9)},${b[2].toFixed(9)}`;d.has(A)||(d.add(A),f.push(b))}let[p,g,x]=f[0],V=Math.sqrt(p*p+g*g+x*x),C=o/V,v=f.map(([b,A,I])=>[r+b*C,c+A*C,a+I*C]),{adj:M}=fe(f),y=te(f,M,4),P=te(f,M,6),S=te(f,M,8);function h(b){let A=de(f,b);return{vertices:me(f,b,A).map(R=>v[R]),color:t}}return[...y.map(h),...P.map(h),...S.map(h)]}function Ye(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[1/s,1/s,3+s],[2/s,s,1+2*s],[1/s,s*s,-1+3*s],[2*s-1,2,2+s],[s,3,2*s]],l=[];for(let[S,h,b]of i){let A=[[S,h,b],[h,b,S],[b,S,h]];for(let[I,R,k]of A)for(let T of[-1,1])for(let z of[-1,1])for(let D of[-1,1])l.push([T*I,z*R,D*k])}let u=new Set,m=[];for(let S of l){let h=`${S[0].toFixed(8)},${S[1].toFixed(8)},${S[2].toFixed(8)}`;u.has(h)||(u.add(h),m.push(S))}let[d,f,p]=m[0],g=Math.sqrt(d*d+f*f+p*p),x=o/g,V=m.map(([S,h,b])=>[r+S*x,c+h*x,a+b*x]),{adj:C}=fe(m),v=te(m,C,4),M=te(m,C,6),y=te(m,C,10);function P(S){let h=de(m,S);return{vertices:me(m,S,h).map(A=>V[A]),color:t}}return[...v.map(P),...M.map(P),...y.map(P)]}function We(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=1+Math.sqrt(2),i=[],l=[[1,1,s],[1,s,1],[s,1,1]];for(let[M,y,P]of l)for(let S of[-1,1])for(let h of[-1,1])for(let b of[-1,1])i.push([S*M,h*y,b*P]);let[u,m,d]=i[0],f=Math.sqrt(u*u+m*m+d*d),p=o/f,g=i.map(([M,y,P])=>[r+M*p,c+y*p,a+P*p]),{adj:x}=fe(i),V=te(i,x,3),C=te(i,x,4);function v(M){let y=de(i,M);return{vertices:me(i,M,y).map(S=>g[S]),color:t}}return[...V.map(v),...C.map(v)]}function Ke(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=s*s,l=i*s,u=[];for(let[h,b,A]of[[1,1,l],[1,l,1],[l,1,1]])for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])u.push([I*h,R*b,k*A]);for(let[h,b,A]of[[i,s,2*s],[s,2*s,i],[2*s,i,s]])for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])u.push([I*h,R*b,k*A]);for(let[h,b,A]of[[2+s,0,i],[0,i,2+s],[i,2+s,0]])for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])u.push([I*h,R*b,k*A]);let m=new Set,d=[];for(let h of u){let b=`${h[0].toFixed(8)},${h[1].toFixed(8)},${h[2].toFixed(8)}`;m.has(b)||(m.add(b),d.push(h))}let[f,p,g]=d[0],x=Math.sqrt(f*f+p*p+g*g),V=o/x,C=d.map(([h,b,A])=>[r+h*V,c+b*V,a+A*V]),{adj:v}=fe(d),M=te(d,v,3),y=te(d,v,4),P=te(d,v,5);function S(h){let b=de(d,h);return{vertices:me(d,h,b).map(I=>C[I]),color:t}}return[...M.map(S),...y.map(S),...P.map(S)]}function Ze(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.cbrt(19+3*Math.sqrt(33))+Math.cbrt(19-3*Math.sqrt(33)))/3,i=1,l=1/s,u=s,m=[[i,l,u],[l,u,i],[u,i,l]],d=[[u,l,i],[l,i,u],[i,u,l]],f=[];for(let[h,b,A]of m)for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(k===-1?1:0))%2===0&&f.push([I*h,R*b,k*A]);for(let[h,b,A]of d)for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(k===-1?1:0))%2===1&&f.push([I*h,R*b,k*A]);let[p,g,x]=f[0],V=Math.sqrt(p*p+g*g+x*x),C=o/V,v=f.map(([h,b,A])=>[r+h*C,c+b*C,a+A*C]),{adj:M}=fe(f),y=te(f,M,3),P=te(f,M,4);function S(h){let b=de(f,h);return{vertices:me(f,h,b).map(I=>v[I]),color:t}}return[...y.map(S),...P.map(S)]}function Qe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],l=Math.sqrt(1+s*s),u=i.map(([T,z,D])=>[T/l,z/l,D/l]),m=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]];function d(T,z){return[T[1]*z[2]-T[2]*z[1],T[2]*z[0]-T[0]*z[2],T[0]*z[1]-T[1]*z[0]]}function f(T){return Math.sqrt(T[0]*T[0]+T[1]*T[1]+T[2]*T[2])}function p(T){let z=f(T);return[T[0]/z,T[1]/z,T[2]/z]}function g(T,z){return Math.sqrt((T[0]-z[0])**2+(T[1]-z[1])**2+(T[2]-z[2])**2)}function x(T,z,D,L){let[w,O,E]=u[T],[_,N,G]=u[z],$=[(1-D)*w+D*_,(1-D)*O+D*N,(1-D)*E+D*G],F=p(d(u[T],u[z]));return p([$[0]+L*F[0],$[1]+L*F[1],$[2]+L*F[2]])}function V(T,z){let D=x(0,2,T,z),L=x(2,9,T,z),w=x(2,0,T,z);return g(D,L)-g(D,w)}function C(T,z){let D=x(0,2,T,z),L=x(2,9,T,z),w=x(0,9,T,z);return g(D,L)-g(D,w)}let v=.35,M=.13,y=1e-7;for(let T=0;T<80;T++){let z=V(v,M),D=C(v,M);if(Math.abs(z)<1e-13&&Math.abs(D)<1e-13)break;let L=(V(v+y,M)-V(v-y,M))/(2*y),w=(V(v,M+y)-V(v,M-y))/(2*y),O=(C(v+y,M)-C(v-y,M))/(2*y),E=(C(v,M+y)-C(v,M-y))/(2*y),_=L*E-w*O;if(Math.abs(_)<1e-12)break;v-=(z*E-D*w)/_,M-=(D*L-z*O)/_}let P=new Set,S=[];for(let[T,z,D]of m)for(let[L,w]of[[T,z],[z,D],[D,T],[z,T],[D,z],[T,D]]){let O=`${L},${w}`;P.has(O)||(P.add(O),S.push(x(L,w,v,M)))}let h=S,b=h.map(([T,z,D])=>[r+T*o,c+z*o,a+D*o]),{adj:A}=fe(h),I=te(h,A,3),R=te(h,A,5);function k(T){let z=de(h,T);return{vertices:me(h,T,z).map(L=>b[L]),color:t}}return[...I.map(k),...R.map(k)]}function Pi(e,n){let o=e[0]-n[0],t=e[1]-n[1],r=e[2]-n[2];return o*o+t*t+r*r}function Mi(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function Vi(e){let n=Mi(e);return[e[0]/n,e[1]/n,e[2]/n]}function vi(e){let[n,o,t]=e[0],[r,c,a]=e[1],[s,i,l]=e[2],u=r-n,m=c-o,d=a-t,f=s-n,p=i-o,g=l-t,x=m*g-d*p,V=d*f-u*g,C=u*p-m*f,v=e.reduce((h,b)=>h+b[0],0)/e.length,M=e.reduce((h,b)=>h+b[1],0)/e.length,y=e.reduce((h,b)=>h+b[2],0)/e.length,P=x*v+V*M+C*y>0?1:-1,S=Math.sqrt(x*x+V*V+C*C);return[P*x/S,P*V/S,P*C/S]}function ee(e){let o=[],t=[];function r(m){for(let d=0;d<o.length;d++)if(Pi(o[d],m)<1e-10)return d;return o.push(m),o.length-1}for(let m of e)t.push(m.vertices.map(d=>r(d)));let c=e.length,a=o.length,s=Math.max(...o.map(m=>m[0]*m[0]+m[1]*m[1]+m[2]*m[2])),i=e.map((m,d)=>{let f=m.vertices,p=vi(f),g=f[0],x=p[0]*g[0]+p[1]*g[1]+p[2]*g[2],V=s/x;return[p[0]*V,p[1]*V,p[2]*V]}),l=Array.from({length:a},()=>[]);for(let m=0;m<c;m++)for(let d of t[m])l[d].push(m);let u=[];for(let m=0;m<a;m++){let d=l[m];if(d.length<3)continue;let f=o[m],p=Vi(f),g=i[d[0]],x=g[0]-f[0],V=g[1]-f[1],C=g[2]-f[2],v=x*p[0]+V*p[1]+C*p[2];x-=v*p[0],V-=v*p[1],C-=v*p[2];let M=Math.sqrt(x*x+V*V+C*C);if(M<1e-12)continue;let y=[x/M,V/M,C/M],P=[p[1]*y[2]-p[2]*y[1],p[2]*y[0]-p[0]*y[2],p[0]*y[1]-p[1]*y[0]],S=d.map(h=>{let b=i[h],A=b[0]-f[0],I=b[1]-f[1],R=b[2]-f[2],k=A*y[0]+I*y[1]+R*y[2],T=A*P[0]+I*P[1]+R*P[2];return{fi:h,angle:Math.atan2(T,k)}});S.sort((h,b)=>h.angle-b.angle),u.push(S.map(h=>h.fi))}return u.map(m=>({vertices:m.map(d=>i[d]),color:"#ffffff"}))}function Kn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=$e({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Zn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Fe({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Qn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ue({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Jn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Be({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function et(e){let{center:n,size:o,color:t="#ffffff"}=e,r=je({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function nt(e){let{center:n,size:o,color:t="#ffffff"}=e,r=qe({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function tt(e){let{center:n,size:o,color:t="#ffffff"}=e,r=He({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function ot(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Xe({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function rt(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ye({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function st(e){let{center:n,size:o,color:t="#ffffff"}=e,r=We({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function ct(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ke({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function it(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ze({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function at(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Qe({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Pr(e,n={}){let{center:o=[0,0,0],size:t=1,color:r}=n;switch(e){case"tetrahedron":return Rn({center:o,size:t,color:r});case"cube":return En({center:o,size:t,color:r});case"octahedron":return kn({center:o,size:t,color:r});case"dodecahedron":return Dn({center:o,size:t,color:r});case"icosahedron":return Ln({center:o,size:t,color:r});case"smallStellatedDodecahedron":return Hn({center:o,size:t,color:r});case"greatDodecahedron":return Xn({center:o,size:t,color:r});case"greatStellatedDodecahedron":return Yn({center:o,size:t,color:r});case"greatIcosahedron":return Wn({center:o,size:t,color:r});case"cuboctahedron":return $e({center:o,size:t,color:r});case"icosidodecahedron":return Fe({center:o,size:t,color:r});case"truncatedTetrahedron":return Ue({center:o,size:t,color:r});case"truncatedCube":return Be({center:o,size:t,color:r});case"truncatedOctahedron":return je({center:o,size:t,color:r});case"truncatedDodecahedron":return qe({center:o,size:t,color:r});case"truncatedIcosahedron":return He({center:o,size:t,color:r});case"truncatedCuboctahedron":return Xe({center:o,size:t,color:r});case"truncatedIcosidodecahedron":return Ye({center:o,size:t,color:r});case"rhombicuboctahedron":return We({center:o,size:t,color:r});case"rhombicosidodecahedron":return Ke({center:o,size:t,color:r});case"snubCube":return Ze({center:o,size:t,color:r});case"snubDodecahedron":return Qe({center:o,size:t,color:r});case"rhombicDodecahedron":return Kn({center:o,size:t,color:r});case"rhombicTriacontahedron":return Zn({center:o,size:t,color:r});case"triakisTetrahedron":return Qn({center:o,size:t,color:r});case"triakisOctahedron":return Jn({center:o,size:t,color:r});case"triakisIcosahedron":return nt({center:o,size:t,color:r});case"tetrakisHexahedron":return et({center:o,size:t,color:r});case"pentakisDodecahedron":return tt({center:o,size:t,color:r});case"disdyakisDodecahedron":return ot({center:o,size:t,color:r});case"disdyakisTriacontahedron":return rt({center:o,size:t,color:r});case"deltoidalIcositetrahedron":return st({center:o,size:t,color:r});case"deltoidalHexecontahedron":return ct({center:o,size:t,color:r});case"pentagonalIcositetrahedron":return it({center:o,size:t,color:r});case"pentagonalHexecontahedron":return at({center:o,size:t,color:r});case"sphere":return _n({center:o,size:t,color:r});case"cylinder":return Gn({center:o,radius:t,height:t*2,color:r});case"cone":return Nn({center:o,radius:t,height:t*2,color:r});case"torus":return $n({center:o,majorRadius:t,minorRadius:t*.3,color:r});case"pyramid":return Fn({center:o,radius:t,height:t*2,color:r});case"prism":return Un({center:o,radius:t,height:t*2,color:r});case"antiprism":return Bn({center:o,radius:t,height:t*2,color:r});case"bipyramid":return jn({center:o,radius:t,halfHeight:t,color:r});case"trapezohedron":return qn({center:o,radius:t,halfHeight:t,color:r});default:{let c=e;throw new Error(`Unknown geometry: ${String(c)}`)}}}var Ci=2200,Ai=2201,Si=2202;function Ti(e,n){let o=0,t=1,r=1,c=2201,a=1/0,s=0,i=!1,l=null,u=!0,m=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(f){r=f},get weight(){return t},set weight(f){t=f},get time(){return o},set time(f){o=f},get isRunning(){return i},get enabled(){return u},set enabled(f){u=f},get paused(){return m},set paused(f){m=f},play(){return i=!0,d},stop(){return i=!1,o=0,s=0,l=null,d},reset(){return o=0,s=0,d},fadeIn(f){return l={from:0,to:1,elapsed:0,duration:f},t=0,d},fadeOut(f){return l={from:t,to:0,elapsed:0,duration:f},d},crossFadeTo(f,p){return d.fadeOut(p),f.fadeIn(p),d},crossFadeFrom(f,p){return f.fadeOut(p),d.fadeIn(p),d},setLoop(f,p){return c=f,a=p,d},setEffectiveTimeScale(f){return r=f,d},setEffectiveWeight(f){return t=f,d}};return d._internal={get clip(){return e},get time(){return o},get weight(){return t},get enabled(){return u},get paused(){return m},get running(){return i},get loopMode(){return c},get repetitions(){return a},get completedReps(){return s},set completedReps(f){s=f},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(f){if(!i)return;if(l){l.elapsed+=f;let g=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(t=l.from+(l.to-l.from)*g,g>=1&&(t=l.to,l=null,t<=0)){i=!1;return}}if(m)return;let p=e.duration;if(!(p<=0)){if(o+=f*r,c===2200)o>=p&&(o=d.clampWhenFinished?p:0,i=!1);else if(c===2201){if(o>=p){let g=o%p,x=Math.floor(o/p);s+=x,o=g,a!==1/0&&s>=a&&(o=d.clampWhenFinished?p:0,i=!1)}}else if(p>0){let g=p*2,x=o%g;if(o>=g){let V=Math.floor(o/g);s+=V,a!==1/0&&s>=a?(o=d.clampWhenFinished?p:0,i=!1):o=x}}}},sampleTime(){if(c===2202){let f=e.duration,p=f*2,g=o%p;return g<=f?g:p-g}return o}},d}function Oi(e){return e._internal}function Yt(e,n){return typeof n=="number"?e[n]:e.find(o=>o.name===n)}function Ii(e,n){let o=new Map;function t(l){let u=Yt(n.clips,l);if(!u)throw new Error(`GlyphAnimationMixer: no clip found for key "${l}". Available: ${n.clips.map(d=>d.name).join(", ")}`);let m=o.get(u.index);return m||(m=Ti(u,n),o.set(u.index,m)),m}function r(l){let u=Yt(n.clips,l);return u?o.get(u.index)??null:null}function c(l){let u=[];for(let g of o.values()){let x=Oi(g);x.advance(l),x.running&&x.enabled&&u.push({internal:x,clip:x.clip})}if(u.length===0)return;if(u.length===1){let{internal:g,clip:x}=u[0],V=n.sample(x.name,g.sampleTime());e.setPolygons(V);return}let m=0;for(let{internal:g}of u)m+=g.weight;if(m<=0)return;let d=u.map(({internal:g,clip:x})=>({polygons:n.sample(x.name,g.sampleTime()),weight:g.weight/m})),f=d[0].polygons;if(f.length===0)return;let p=f.map((g,x)=>{let V=g.vertices.map((C,v)=>{let M=0,y=0,P=0;for(let{polygons:S,weight:h}of d){let b=S[x];if(!b)continue;let A=b.vertices[v];A&&(M+=A[0]*h,y+=A[1]*h,P+=A[2]*h)}return[M,y,P]});return{...g,vertices:V}});e.setPolygons(p)}function a(){for(let l of o.values())l.stop()}function s(l){let u=Yt(n.clips,l);u&&o.delete(u.index)}function i(){o.clear()}return{clipAction:t,existingAction:r,update:c,stopAllAction:a,uncacheClip:s,uncacheRoot:i}}var zi=/^[0-9A-Fa-f]{6}$/,wi=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function Wt(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",c=n?.palette??wi,a=n?.materialColors??{},s=n?.materialTextures??{},i=[],l=[],u=[],m=[],d=new Map,f=r,p,g=n?.includeObjects?new Set(n.includeObjects):null,x=n?.excludeObjects?new Set(n.excludeObjects):null,V=null,C=()=>V===null?g===null:!(g&&!g.has(V)||x&&x.has(V)),v=L=>L in a?a[L]:zi.test(L)?`#${L}`:(d.has(L)||(d.set(L,c[m.length%c.length]),m.push(L)),d.get(L)),M=e.split(`
2
+ `);for(let L of M)if(!(L.length===0||L.charCodeAt(0)===35)){if(L.startsWith("v ")){let w=L.trim().split(/\s+/);i.push([parseFloat(w[1]),parseFloat(w[2]),parseFloat(w[3])])}else if(L.startsWith("vt ")){let w=L.trim().split(/\s+/);l.push([parseFloat(w[1]),parseFloat(w[2])])}else if(L.startsWith("o "))V=L.trim().slice(2).trim();else if(L.startsWith("usemtl ")){let w=L.trim().split(/\s+/)[1];f=v(w),p=s[w]}else if(L.startsWith("f ")){if(!C())continue;let w=L.trim().split(/\s+/).slice(1),O=[],E=[];for(let _ of w){let N=_.split("/");O.push(parseInt(N[0],10)-1);let G=N[1];if(G&&G.length>0){let $=parseInt(G,10)-1;E.push(Number.isFinite($)?$:null)}else E.push(null)}u.push({idx:O,uvIdx:E,color:f,texture:p})}}if(i.length===0||u.length===0)return ki(m,e.length);let y=new Set;for(let L of u)for(let w of L.idx)y.add(w);let P=1/0,S=1/0,h=1/0,b=-1/0,A=-1/0,I=-1/0;for(let L of y){let w=i[L];w&&(w[0]<P&&(P=w[0]),w[0]>b&&(b=w[0]),w[1]<S&&(S=w[1]),w[1]>A&&(A=w[1]),w[2]<h&&(h=w[2]),w[2]>I&&(I=w[2]))}let R=Math.max(b-P,A-S,I-h),k=R>0?o/R:1,T=L=>Math.round(L*1e3)/1e3,z=i.map(([L,w,O])=>[T((O-h)*k+t),T((L-P)*k+t),T((w-S)*k+t)]),D=[];for(let{idx:L,uvIdx:w,color:O,texture:E}of u)for(let _=1;_<L.length-1;_++){let N=L[0],G=L[_],$=L[_+1],F=z[N],q=z[G],j=z[$];if(!F||!q||!j||F[0]===q[0]&&F[1]===q[1]&&F[2]===q[2]||F[0]===j[0]&&F[1]===j[1]&&F[2]===j[2]||q[0]===j[0]&&q[1]===j[1]&&q[2]===j[2])continue;let U;if(E){let H=w[0],Z=w[_],J=w[_+1];if(H!=null&&Z!=null&&J!=null){let ne=l[H],ie=l[Z],oe=l[J];ne&&ie&&oe&&(U=[ne,ie,oe])}}let B={vertices:[F,q,j],color:O};E&&(B.texture=E),U&&(B.uvs=U),D.push(B)}return{polygons:D,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:D.length,materials:m,sourceBytes:e.length}}}function ki(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var Kt=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function Zt(e){let n={},o={},t=null;for(let r of e.split(`
3
+ `)){let c=r.trim();if(!(c.length===0||c.charCodeAt(0)===35)){if(c.startsWith("newmtl ")){t=c.slice(7).trim();continue}if(t){if(c.startsWith("Kd ")){let a=c.split(/\s+/),s=parseFloat(a[1]),i=parseFloat(a[2]),l=parseFloat(a[3]);Number.isFinite(s)&&Number.isFinite(i)&&Number.isFinite(l)&&(n[t]=`#${Kt(s)}${Kt(i)}${Kt(l)}`)}else if(c.startsWith("map_Kd ")){let a=c.split(/\s+/),s=a[a.length-1]?.replace(/\\+/g,"/");s&&s!=="map_Kd"&&(o[t]=s)}}}}return{colors:n,textures:o}}var Ar={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Sr={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Tr(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Ri(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let o=e.slice(5,n),t=e.slice(n+1);if(!o.includes(";base64")){let a=decodeURIComponent(t),s=new Uint8Array(a.length);for(let i=0;i<a.length;i++)s[i]=a.charCodeAt(i)&255;return s}let r=globalThis.atob(t),c=new Uint8Array(r.length);for(let a=0;a<r.length;a++)c[a]=r.charCodeAt(a);return c}function Ei(e,n){let o=e.buffers?.[0];if(!o)throw new Error("parseGltf: JSON doc has no buffers[0]");let t=o.uri;if(!t)throw new Error("parseGltf: JSON doc buffer has no uri (and there's no GLB BIN chunk)");if(t.startsWith("data:"))return Ri(t);if(n){let r=n(t);if(r instanceof Uint8Array)return r;throw new Error("parseGltf: resolveBuffer returned a Promise; use parseGltf via async if your buffers are external")}throw new Error(`parseGltf: external buffer URI "${t}" \u2014 provide options.resolveBuffer`)}function Di(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let o=n.getUint32(4,!0);if(o!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${o})`);let t=12,r=null,c=null;for(;t<e.byteLength;){let a=n.getUint32(t,!0),s=n.getUint32(t+4,!0),i=t+8;if(s===1313821514){let l=new Uint8Array(e,i,a);r=JSON.parse(Tr(l))}else s===5130562&&(c=new Uint8Array(e,i,a));t=i+a}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:c}}function Qt(e,n,o){let t=e.accessors?.[o],r=e.bufferViews?.[t?.bufferView??-1];if(!t||!r)throw new Error(`parseGltf: bad accessor/bufferView ${o}`);let c=Ar[t.componentType],a=Sr[t.type];if(!c||!a)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let s=(r.byteOffset??0)+(t.byteOffset??0),i=t.count*a,l=n.buffer.slice(n.byteOffset+s,n.byteOffset+s+i*c),u;switch(t.componentType){case 5126:u=new Float32Array(l);break;case 5123:u=new Uint16Array(l);break;case 5125:u=new Uint32Array(l);break;case 5121:u=new Uint8Array(l);break;default:throw new Error(`parseGltf: unhandled componentType ${t.componentType}`)}return{array:u,count:t.count,componentCount:a}}function Li(e,n,o){switch(o){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 ${o}`)}}function _i(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 ft(e,n,o){let t=e.accessors?.[o],r=e.bufferViews?.[t?.bufferView??-1];if(!t||!r)throw new Error(`parseGltf: bad accessor/bufferView ${o}`);let c=Ar[t.componentType],a=Sr[t.type];if(!c||!a)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let s=n.byteOffset+(r.byteOffset??0)+(t.byteOffset??0),i=r.byteStride??c*a,l=new DataView(n.buffer),u=new Array(t.count*a),m=0;for(let d=0;d<t.count;d++){let f=s+d*i;for(let p=0;p<a;p++){let g=Li(l,f+p*c,t.componentType);u[m++]=t.normalized?_i(g,t.componentType):g}}return{values:u,count:t.count,componentCount:a}}function Gi(e,n,o){let t=[],r=[],c=globalThis;for(let a of e.images??[]){if(a.uri){if(o&&!a.uri.startsWith("data:"))try{t.push(new c.URL(a.uri,o).href)}catch{t.push(a.uri)}else t.push(a.uri);continue}if(a.bufferView!==void 0){let s=e.bufferViews?.[a.bufferView];if(!s){t.push("");continue}let i=s.byteOffset??0,l=n.subarray(i,i+s.byteLength),u=a.mimeType??"image/png",m=new c.Blob([l],{type:u}),d=c.URL.createObjectURL(m);t.push(d),r.push(d)}else t.push("")}return{urls:t,objectUrls:r}}function Ni(e,n){let o=new Map,t=e.materials??[];for(let r=0;r<t.length;r++){let c=t[r].pbrMetallicRoughness?.baseColorTexture?.index;if(c===void 0)continue;let a=e.textures?.[c]?.source;if(a===void 0)continue;let s=n[a];s&&o.set(r,s)}return o}function $i(e,n){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let t=s=>Math.max(0,Math.min(1,s)),r=s=>Math.round(t(s)*255).toString(16).padStart(2,"0"),c=s=>Math.round(t(s)*255),a=t(o[3]??1);return a<1?`rgba(${c(o[0])}, ${c(o[1])}, ${c(o[2])}, ${Math.round(a*1e3)/1e3})`:`#${r(o[0])}${r(o[1])}${r(o[2])}`}var Je=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Jt(e,n){let o=new Array(16);for(let t=0;t<4;t++)for(let r=0;r<4;r++)o[r*4+t]=e[0+t]*n[r*4+0]+e[4+t]*n[r*4+1]+e[8+t]*n[r*4+2]+e[12+t]*n[r*4+3];return o}function ut(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 Or(e,n,o){let t=e?.[0]??0,r=e?.[1]??0,c=e?.[2]??0,a=n?.[0]??0,s=n?.[1]??0,i=n?.[2]??0,l=n?.[3]??1,u=o?.[0]??1,m=o?.[1]??1,d=o?.[2]??1,f=a+a,p=s+s,g=i+i,x=a*f,V=a*p,C=a*g,v=s*p,M=s*g,y=i*g,P=l*f,S=l*p,h=l*g;return[(1-(v+y))*u,(V+h)*u,(C-S)*u,0,(V-h)*m,(1-(x+y))*m,(M+P)*m,0,(C+S)*d,(M-P)*d,(1-(x+v))*d,0,t,r,c,1]}function Fi(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Or(e.translation,e.rotation,e.scale)}function Ui(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function Mr(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function Ir(e,n,o){let t=new Array(Math.min(e.length,n.length));for(let r=0;r<t.length;r++)t[r]=e[r]+(n[r]-e[r])*o;return t}function mn(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 Bi(e,n,o){let t=mn(e),r=mn(n),c=t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3];if(c<0&&(c=-c,r=[-r[0],-r[1],-r[2],-r[3]]),c>.9995)return mn(Ir(t,r,o));let a=Math.acos(Math.max(-1,Math.min(1,c))),s=Math.sin(a),i=Math.sin((1-o)*a)/s,l=Math.sin(o*a)/s;return mn([t[0]*i+r[0]*l,t[1]*i+r[1]*l,t[2]*i+r[2]*l,t[3]*i+r[3]*l])}function ji(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 Vr(e){return e.matrix?e.matrix.slice():Or(e.translation,e.rotation,e.scale)}function qi(e){let n=e.scene??0,o=e.scenes?.[n]?.nodes;return o&&o.length>0?o:[]}function vr(e,n){let o=e.nodes??[],t=new Array(o.length),r=new Set,c=(s,i)=>{if(s<0||s>=o.length)return;let l=Jt(i,n[s]??Je);t[s]=l,r.add(s);for(let u of o[s].children??[])c(u,l)},a=qi(e);if(a.length>0)for(let s of a)c(s,Je);for(let s=0;s<o.length;s++)r.has(s)||c(s,Je);return t}function Cr(e,n,o,t,r){if(o===void 0)return;let{values:c,count:a,componentCount:s}=ft(e,n,o);if(a!==r||s<1)return;let i=[];for(let l=0;l<a;l++){let u=[];for(let m=0;m<t;m++)u.push(c[l*s+m]??0);i.push(u)}return i}function Hi(e,n,o,t){if(o===void 0)return Array.from({length:t},()=>Je.slice());let{values:r,componentCount:c,count:a}=ft(e,n,o);if(c!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${o} is not MAT4`);let s=[];for(let i=0;i<t;i++){let l=Math.min(i,a-1);s.push(r.slice(l*16,l*16+16))}return s}function lt(e,n){let o=e.componentCount,t=e.interpolation==="CUBICSPLINE"?(n*3+1)*o:n*o;return e.output.slice(t,t+o)}function Xi(e,n,o){let t=e.input;if(t.length===0)return[];if(t.length===1||n<=t[0])return lt(e,0);let r=t.length-1;if(n>=t[r])return lt(e,r);let c=0,a=r;for(;c+1<a;){let d=c+a>>1;t[d]<=n?c=d:a=d}let s=t[c],i=t[c+1],l=i>s?(n-s)/(i-s):0,u=lt(e,c),m=lt(e,c+1);return e.interpolation==="STEP"?u:o==="rotation"?Bi(u,m,l):Ir(u,m,l)}function Yi(e,n,o,t){let r=e.animations??[];if(r.length===0||o.length===0)return;let c=(e.nodes??[]).map(f=>ji(f)),a=c.map(Vr),s=vr(e,a),i=(e.skins??[]).map(f=>({joints:f.joints??[],inverseBindMatrices:Hi(e,n,f.inverseBindMatrices,f.joints?.length??0)})),l=[];for(let f=0;f<r.length;f++){let p=r[f],g=(p.samplers??[]).map(C=>{let v=ft(e,n,C.input),M=ft(e,n,C.output);return{input:v.values,output:M.values,componentCount:M.componentCount,interpolation:C.interpolation??"LINEAR"}}),x=[];for(let C of p.channels??[]){let v=C.target.node,M=C.target.path,y=g[C.sampler];v===void 0||!M||!y||M==="weights"||x.push({sampler:y,targetNode:v,path:M})}let V=x.reduce((C,v)=>{let M=v.sampler.input;return Math.max(C,M[M.length-1]??0)},0);l.push({info:{index:f,name:p.name??`animation_${f}`,duration:V,channelCount:x.length},channels:x})}let u=l.map(f=>f.info);if(u.length===0)return;let m=(f,p,g,x,V,C)=>{let v=t(f),M=t(p),y=t(g);if(v[0]===M[0]&&v[1]===M[1]&&v[2]===M[2]||v[0]===y[0]&&v[1]===y[1]&&v[2]===y[2]||M[0]===y[0]&&M[1]===y[1]&&M[2]===y[2])return null;let P={vertices:[v,M,y],color:x};return V&&(P.texture=V),C&&(P.uvs=C),P};return{clips:u,sample:(f,p)=>{let g=typeof f=="number"?l[f]:l.find(y=>y.info.name===f);if(!g)return[];let x=g.info.duration,V=x>0?(p%x+x)%x:Math.max(0,p),C=c.map(y=>({translation:y.translation.slice(),rotation:y.rotation.slice(),scale:y.scale.slice(),matrix:y.matrix?y.matrix.slice():void 0}));for(let y of g.channels){let P=C[y.targetNode];if(!P)continue;let S=Xi(y.sampler,V,y.path);P.matrix=void 0,y.path==="translation"?P.translation=S.slice(0,3):y.path==="rotation"?P.rotation=mn(S.slice(0,4)):y.path==="scale"&&(P.scale=S.slice(0,3))}let v=vr(e,C.map(Vr)),M=[];for(let y of o){let P=[];if(y.skinIndex!==void 0&&y.joints&&y.weights&&i[y.skinIndex]){let S=i[y.skinIndex];for(let h=0;h<y.positions.length;h++){let b=y.positions[h],A=[0,0,0],I=0,R=y.joints[h]??[],k=y.weights[h]??[];for(let T=0;T<4;T++){let z=k[T]??0;if(z<=0)continue;let D=Math.round(R[T]??0),L=S.joints[D],w=v[L],O=S.inverseBindMatrices[D];if(!w||!O)continue;let E=Jt(w,O);A=Ui(A,Mr(ut(E,b),z)),I+=z}P.push(I>0?Mr(A,1/I):ut(y.meshBindWorld,b))}}else{let S=y.meshNode!==null?v[y.meshNode]??y.meshBindWorld:y.meshBindWorld;for(let h of y.positions)P.push(ut(S,h))}for(let S=0;S+2<y.indices.length;S+=3){let h=y.indices[S],b=y.indices[S+1],A=y.indices[S+2],I=P[h],R=P[b],k=P[A];if(!I||!R||!k)continue;let T;if(y.uvs&&y.texture){let D=y.uvs[h],L=y.uvs[b],w=y.uvs[A];D&&L&&w&&(T=[D,L,w])}let z=m(I,R,k,y.color,y.texture,T);z&&M.push(z)}}return M}}}function eo(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",c=n?.materialColors??{},a=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,s=a.byteLength,i,l;if(a.byteLength>=4&&new DataView(a).getUint32(0,!0)===1179937895){let O=Di(a);if(i=O.doc,!O.bin)throw new Error("parseGltf: GLB has no binary chunk");l=O.bin}else i=JSON.parse(Tr(new Uint8Array(a))),l=Ei(i,n?.resolveBuffer);let{urls:u,objectUrls:m}=Gi(i,l,n?.baseUrl),d=Ni(i,u),f=[],p=[],g=(i.meshes??[]).map((O,E)=>O.name??`mesh_${E}`),x=(i.materials??[]).map((O,E)=>O.name??`material_${E}`);function V(O,E,_){let N=i.meshes?.[O];if(N)for(let G of N.primitives){if((G.mode??4)!==4)continue;let F=G.material!==void 0?i.materials?.[G.material]?.name:void 0,j=(F?c[F]:void 0)??$i(G.material!==void 0?i.materials?.[G.material]:void 0,r),U=G.material!==void 0?d.get(G.material):void 0,{array:B,count:H}=Qt(i,l,G.attributes.POSITION);if(!(B instanceof Float32Array))continue;let Z=[],J=[];for(let Q=0;Q<H;Q++){let X=[B[Q*3],B[Q*3+1],B[Q*3+2]];Z.push(X),J.push(ut(E,X))}let ne=null,ie=G.attributes.TEXCOORD_0;if(U&&ie!==void 0){let{array:Q,count:X}=Qt(i,l,ie);ne=[];let K=1;Q instanceof Uint8Array?K=1/255:Q instanceof Uint16Array&&(K=1/65535);for(let ae=0;ae<X;ae++){let Pe=Q[ae*2]*K,Ae=Q[ae*2+1]*K;ne.push([Pe,1-Ae])}}let oe;if(G.indices!==void 0){let{array:Q,count:X}=Qt(i,l,G.indices);oe=[];for(let K=0;K<X;K++)oe.push(Number(Q[K]))}else oe=J.map((Q,X)=>X);if((i.animations?.length??0)>0){let Q=Cr(i,l,G.attributes.JOINTS_0,4,H),X=Cr(i,l,G.attributes.WEIGHTS_0,4,H);p.push({meshNode:_,meshBindWorld:E,skinIndex:_!==null?i.nodes?.[_]?.skin:void 0,positions:Z,indices:oe,color:j,texture:U,uvs:ne??void 0,joints:Q,weights:X})}for(let Q=0;Q+2<oe.length;Q+=3){let X=J[oe[Q]],K=J[oe[Q+1]],ae=J[oe[Q+2]];if(!X||!K||!ae)continue;let Pe;if(ne&&U){let Ae=ne[oe[Q]],ke=ne[oe[Q+1]],Re=ne[oe[Q+2]];Ae&&ke&&Re&&(Pe=[Ae,ke,Re])}f.push({v0:X,v1:K,v2:ae,color:j,texture:U,uvs:Pe})}}}function C(O,E){let _=i.nodes?.[O];if(!_)return;let N=Jt(E,Fi(_));typeof _.mesh=="number"&&V(_.mesh,N,O);for(let G of _.children??[])C(G,N)}let v=i.scene??0,M=i.scenes?.[v]?.nodes;if(M&&M.length>0)for(let O of M)C(O,Je);else for(let O=0;O<(i.meshes?.length??0);O++)V(O,Je,null);let y=Wi(m);if(f.length===0)return{polygons:[],objectUrls:m,dispose:y,warnings:[],metadata:{triangleCount:0,meshes:g,materials:x,sourceBytes:s}};let P=1/0,S=1/0,h=1/0,b=-1/0,A=-1/0,I=-1/0;for(let O of f)for(let E of[O.v0,O.v1,O.v2])E[0]<P&&(P=E[0]),E[0]>b&&(b=E[0]),E[1]<S&&(S=E[1]),E[1]>A&&(A=E[1]),E[2]<h&&(h=E[2]),E[2]>I&&(I=E[2]);let R=Math.max(b-P,A-S,I-h),k=R>0?o/R:1,T=O=>Math.round(O*1e3)/1e3,D=(n?.upAxis??"y")==="z"?([O,E,_])=>[T((O-P)*k+t),T((E-S)*k+t),T((_-h)*k+t)]:([O,E,_])=>[T((_-h)*k+t),T((O-P)*k+t),T((E-S)*k+t)],L=Yi(i,l,p,D),w=[];for(let O of f){let E=D(O.v0),_=D(O.v1),N=D(O.v2);if(E[0]===_[0]&&E[1]===_[1]&&E[2]===_[2]||E[0]===N[0]&&E[1]===N[1]&&E[2]===N[2]||_[0]===N[0]&&_[1]===N[1]&&_[2]===N[2])continue;let G={vertices:[E,_,N],color:O.color};O.texture&&(G.texture=O.texture),O.uvs&&(G.uvs=O.uvs),w.push(G)}return{polygons:w,animation:L,objectUrls:m,dispose:y,warnings:[],metadata:{triangleCount:w.length,meshes:g,materials:x,animations:L?.clips,sourceBytes:s}}}function Wi(e){let n=!1;return()=>{if(n)return;n=!0;let o=globalThis.URL;if(o?.revokeObjectURL)for(let t of e)try{o.revokeObjectURL(t)}catch{}}}function no(e){return e.material?.texture??e.texture}function Ki(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function Zi(e,n){return new Promise((o,t)=>{let r=new n,c=!1,a=s=>{c||(c=!0,s())};r.decoding="async",r.onload=()=>a(()=>o(r)),r.onerror=()=>a(()=>t(new Error(`texture load failed: ${e}`))),r.src=e,typeof r.decode=="function"&&r.decode().then(()=>a(()=>o(r)),()=>{})})}async function Qi(e,n,o){try{let t=await Zi(e,n.Image),r=Math.max(0,Math.floor(t.naturalWidth||t.width||0)),c=Math.max(0,Math.floor(t.naturalHeight||t.height||0));if(r<=0||c<=0||r*c>o)return null;let a=n.createCanvas();a.width=r,a.height=c;let s=a.getContext("2d",{willReadFrequently:!0});if(!s)return null;s.drawImage(t,0,0,r,c);let i=s.getImageData(0,0,r,c).data;return{width:r,height:c,data:i,lowDetail:Ji(r,c,i)}}catch{return null}}function zr(e,n,o,t,r,c){let a=(t*n+o)*4,s=(c*n+r)*4;return Math.max(Math.abs((e[a]??0)-(e[s]??0)),Math.abs((e[a+1]??0)-(e[s+1]??0)),Math.abs((e[a+2]??0)-(e[s+2]??0)))}function Ji(e,n,o){let t=Math.max(1,Math.floor(Math.max(e,n)/128)),r=0,c=0,a=0;for(let s=0;s<n;s+=t)for(let i=0;i<e;i+=t){if(i+t<e){let l=zr(o,e,i,s,i+t,s);a+=l,r++,l>32&&c++}if(s+t<n){let l=zr(o,e,i,s,i,s+t);a+=l,r++,l>32&&c++}}return r>0&&c/r<=.045&&a/r<=10}function wr(e,n,o){return Math.max(n,Math.min(o,e))}function ea(e,n){let o=n[0],t=1-n[1];if(!Number.isFinite(o)||!Number.isFinite(t))return null;let r=wr(Math.floor(o*e.width),0,e.width-1),a=(wr(Math.floor(t*e.height),0,e.height-1)*e.width+r)*4;return{r:e.data[a]??0,g:e.data[a+1]??0,b:e.data[a+2]??0,a:e.data[a+3]??255}}function Ce(e,n,o,t,r,c){return[e[0]*t+n[0]*r+o[0]*c,e[1]*t+n[1]*r+o[1]*c]}function na(e){let[n,o,t]=e;return[Ce(n,o,t,1/3,1/3,1/3),Ce(n,o,t,.8,.1,.1),Ce(n,o,t,.1,.8,.1),Ce(n,o,t,.1,.1,.8),Ce(n,o,t,.45,.45,.1),Ce(n,o,t,.45,.1,.45),Ce(n,o,t,.1,.45,.45)]}function ta(e){let[n,o,t]=e,r=na(e);for(let c=1;c<6;c++)for(let a=1;a<6-c;a++){let s=6-c-a;s<=0||r.push(Ce(n,o,t,c/6,a/6,s/6))}return r}function Dr(e){if(e.textureTriangles?.length)return e.textureTriangles;let n=e.uvs;if(!n||n.length!==e.vertices.length||n.length<3)return[];let o=[];for(let t=1;t+1<n.length;t++)o.push({uvs:[n[0],n[t],n[t+1]]});return o}function kr(e,n,o){return Math.abs(e.r-n.r)<=o&&Math.abs(e.g-n.g)<=o&&Math.abs(e.b-n.b)<=o&&Math.abs(e.a-n.a)<=o}function Rr(e){let n=t=>Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0");if(e.a>=255)return`#${n(e.r)}${n(e.g)}${n(e.b)}`;let o=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)}, ${o})`}function oa(){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},count:0}}function ra(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,e.count++}function Er(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 sa(e,n,o,t){let r=Dr(e);if(r.length===0||!t&&!n.lowDetail)return null;let c=oa();for(let a of r)for(let s of ta(a.uvs)){let i=ea(n,s);if(!i)return null;ra(c,i)}return c.count===0?null:kr(c.min,c.max,o)?Rr(Er(c)):t||!kr(c.min,c.max,32)?null:Rr(Er(c))}function ca(e,n){let{texture:o,material:t,uvs:r,textureTriangles:c,...a}=e;return{...a,color:n}}async function Lr(e,n={}){if(n.enabled===!1)return null;let o=Ki();if(!o)return null;let t=e.filter(i=>no(i)&&Dr(i).length>0);if(t.length===0)return null;let r=n.maxTexturePixels??16777216,c=new Map;await Promise.all(Array.from(new Set(t.map(i=>no(i)))).map(async i=>{c.set(i,await Qi(i,o,r))}));let a=n.colorTolerance??2,s=n.colorTolerance!==void 0;return{bake(i){let l=!1,u=i.map(m=>{let d=no(m);if(!d)return m;let f=c.get(d);if(!f)return m;let p=sa(m,f,a,s);return p?(l=!0,ca(m,p)):m});return{polygons:l?u:i,changed:l}}}}async function ia(e,n={}){let o=await Lr(e,n);return o?o.bake(e).polygons:e}async function to(e,n={}){let o=await Lr(e.polygons,n);if(!o)return e;let t=o.bake(e.polygons);return!t.changed&&!e.animation?e:{...e,polygons:t.polygons,animation:e.animation?{...e.animation,sample(r,c){return o.bake(e.animation.sample(r,c)).polygons}}:e.animation}}var aa=[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 la(e){let n=e>>0&255,o=e>>8&255,t=e>>16&255;return[n,o,t]}function oo(e){return(e&255).toString(16).padStart(2,"0")}function Gr(e,n,o){return`#${oo(e)}${oo(n)}${oo(o)}`}function ua(e,n,o,t){if(t>=255)return Gr(e,n,o);let r=Math.round(Math.max(0,Math.min(255,t))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${o}, ${r})`}var fa=542658390;function ro(e,n){let o=n?.targetSize??60,t=n?.gridShift??0,r=e.byteLength;if(e.byteLength<8)return en(r,["parseVox: buffer too small to be a valid .vox file"]);let c=new DataView(e);if(c.getUint32(0,!0)!==fa)return en(r,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return en(r,["parseVox: buffer too small for MAIN chunk"]);if(_r(c,8)!=="MAIN")return en(r,["parseVox: expected MAIN chunk at offset 8"]);let l=20+c.getUint32(12,!0),u=l+c.getUint32(16,!0),m=[],d=[],f=null;for(;l<u&&l+12<=e.byteLength;){let w=_r(c,l),O=c.getUint32(l+4,!0),E=c.getUint32(l+8,!0),_=l+12,N=_+O+E;if(w==="SIZE"){if(O>=12&&_+12<=e.byteLength){let G=c.getUint32(_,!0),$=c.getUint32(_+4,!0),F=c.getUint32(_+8,!0);m.push({sx:G,sy:$,sz:F})}}else if(w==="XYZI"){if(O>=4&&_+4<=e.byteLength){let G=c.getUint32(_,!0),$=[],F=Math.min(G,Math.floor((O-4)/4));for(let q=0;q<F;q++){let j=_+4+q*4;$.push({x:c.getUint8(j),y:c.getUint8(j+1),z:c.getUint8(j+2),colorIndex:c.getUint8(j+3)})}d.push($)}}else if(w==="RGBA"&&O>=1024&&_+1024<=e.byteLength){f=[];for(let G=0;G<256;G++){let $=_+G*4,F=c.getUint8($),q=c.getUint8($+1),j=c.getUint8($+2),U=c.getUint8($+3);f.push(ua(F,q,j,U))}}l=N}let p=[],g=new Set;for(let w of d)for(let O of w){if(O.colorIndex===0)continue;let E=`${O.x},${O.y},${O.z}`;g.has(E)||(g.add(E),p.push(O))}if(p.length===0)return en(r,[]);let x=w=>{let O=w-1;if(f!==null)return f[O]??"#888888";let E=aa[w]??0,[_,N,G]=la(E);return Gr(_,N,G)},V=(w,O,E)=>g.has(`${w},${O},${E}`),C=new Map,v=(w,O,E,_,N)=>{let G=`${w}:${O}:${N}`,$=C.get(G);$||($=new Set,C.set(G,$)),$.add(`${E},${_}`)};for(let w of p){let{x:O,y:E,z:_}=w,N=x(w.colorIndex);V(O+1,E,_)||v(0,O+1,E,_,N),V(O-1,E,_)||v(1,O,E,_,N),V(O,E+1,_)||v(2,E+1,O,_,N),V(O,E-1,_)||v(3,E,O,_,N),V(O,E,_+1)||v(4,_+1,O,E,N),V(O,E,_-1)||v(5,_,O,E,N)}function M(w){let O=new Set,E=[],_=1/0,N=-1/0,G=1/0,$=-1/0;for(let F of w){let[q,j]=F.split(","),U=+q,B=+j;U<_&&(_=U),U>N&&(N=U),B<G&&(G=B),B>$&&($=B)}for(let F=G;F<=$;F++)for(let q=_;q<=N;q++){let j=`${q},${F}`;if(!w.has(j)||O.has(j))continue;let U=1;for(;q+U<=N;){let H=`${q+U},${F}`;if(!w.has(H)||O.has(H))break;U++}let B=1;e:for(;F+B<=$;){for(let H=0;H<U;H++){let Z=`${q+H},${F+B}`;if(!w.has(Z)||O.has(Z))break e}B++}for(let H=0;H<B;H++)for(let Z=0;Z<U;Z++)O.add(`${q+Z},${F+H}`);E.push({u:q,v:F,w:U,h:B})}return E}let y=(w,O,E,_,N,G)=>{let $=E+N,F=_+G;switch(w){case 0:return[[O,E,_],[O,$,_],[O,$,F],[O,E,F]];case 1:return[[O,$,_],[O,E,_],[O,E,F],[O,$,F]];case 2:return[[E,O,_],[E,O,F],[$,O,F],[$,O,_]];case 3:return[[$,O,_],[$,O,F],[E,O,F],[E,O,_]];case 4:return[[E,_,O],[$,_,O],[$,F,O],[E,F,O]];default:return[[E,F,O],[$,F,O],[$,_,O],[E,_,O]]}},P=[];for(let[w,O]of C){let E=w.indexOf(":"),_=w.indexOf(":",E+1),N=+w.slice(0,E),G=+w.slice(E+1,_),$=w.slice(_+1);for(let{u:F,v:q,w:j,h:U}of M(O))P.push({vertices:y(N,G,F,q,j,U),color:$})}if(P.length===0)return en(r,[]);let S=1/0,h=1/0,b=1/0,A=-1/0,I=-1/0,R=-1/0;for(let w of P)for(let O of w.vertices)O[0]<S&&(S=O[0]),O[0]>A&&(A=O[0]),O[1]<h&&(h=O[1]),O[1]>I&&(I=O[1]),O[2]<b&&(b=O[2]),O[2]>R&&(R=O[2]);let k=Math.max(A-S,I-h,R-b),T=k>0?o/k:1,z=w=>Math.round(w*1e3)/1e3,D=w=>[z((w[0]-S)*T+t),z((w[1]-h)*T+t),z((w[2]-b)*T+t)],L=P.map(({vertices:w,color:O})=>({vertices:w.map(D),color:O}));return{polygons:L,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:L.length,sourceBytes:r,voxelCount:p.length}}}function _r(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 en(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var we="loadMesh";function so(e,n){let o=$t(e.polygons,{meshResolution:n?.meshResolution});return o.length===e.polygons.length?e:{...e,polygons:o}}async function Nr(e,n){let o=n?.solidTextureSamples;return o===!1?e:to(e,typeof o=="object"?o:void 0)}function ma(e){let n=e.split("?")[0].split("#")[0],o=n.lastIndexOf(".");return o<0?"":n.slice(o+1).toLowerCase()}async function da(e,n){let o=ma(e);if(o==="mtl")throw new Error(`${we}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let t=globalThis.fetch;if(!t)throw new Error(`${we}: no fetch() in this environment`);let r=n?.baseUrl??e;if(o==="obj"){let c=await t(e);if(!c.ok)throw new Error(`${we}: ${e} \u2192 ${c.status}`);let a=await c.text(),s=n?.objOptions;if(n?.mtlUrl){let l=await t(n.mtlUrl);if(!l.ok)throw new Error(`${we}: ${n.mtlUrl} \u2192 ${l.status}`);let u=await l.text(),{colors:m,textures:d}=Zt(u),f={},p=globalThis.URL,g=globalThis.document?.baseURI,x=n.mtlUrl;if(p&&g)try{x=new p(n.mtlUrl,g).toString()}catch{}for(let[V,C]of Object.entries(d)){if(p)try{f[V]=new p(C,x).toString();continue}catch{}let v=n.mtlUrl.lastIndexOf("/"),M=v>=0?n.mtlUrl.slice(0,v+1):"";f[V]=C.startsWith("/")||/^https?:\/\//.test(C)?C:M+C}s={...s??{},materialColors:{...m,...s?.materialColors??{}},materialTextures:{...f,...s?.materialTextures??{}}}}let i=Wt(a,s);return so(await Nr(i,n),n)}if(o==="glb"||o==="gltf"){let c=await t(e);if(!c.ok)throw new Error(`${we}: ${e} \u2192 ${c.status}`);let a=await c.arrayBuffer(),s=eo(a,{baseUrl:r,...n?.gltfOptions??{}});return so(await Nr(s,n),n)}if(o==="vox"){let c=await t(e);if(!c.ok)throw new Error(`${we}: ${e} \u2192 ${c.status}`);let a=await c.arrayBuffer();return so(ro(a,n?.voxOptions),n)}throw new Error(`${we}: unsupported extension ".${o}" (supported: obj, glb, gltf, vox)`)}function pa(e,n,o,t,r=.5,c=.5,a=.4){let s=4/(e[2]+3),i=Math.min(n,o)*a,l=n*r+e[0]*i*t*s,u=o*c-e[1]*i*s;return[l,u,e[2]]}function ga(e){let[n,o,t]=[e.vertices[0],e.vertices[1],e.vertices[2]],r=o[0]-n[0],c=o[1]-n[1],a=o[2]-n[2],s=t[0]-n[0],i=t[1]-n[1],l=t[2]-n[2];return[c*l-a*i,a*s-r*l,r*i-c*s]}function ya(e,n){let o=Math.hypot(e[0],e[1],e[2]),t=Math.hypot(n[0],n[1],n[2]);return o===0||t===0?1:(e[0]*n[0]+e[1]*n[1]+e[2]*n[2])/(o*t)}function $r(e,n){let o=`${e[0]},${e[1]},${e[2]}`,t=`${n[0]},${n[1]},${n[2]}`;return o<t?`${o}|${t}`:`${t}|${o}`}function ha(e,n=0){if(n<=0){let a=new Set,s=[];for(let i of e){let l=[[0,1],[1,2],[2,0]];for(let[u,m]of l){let d=i.vertices[u],f=i.vertices[m],p=$r(d,f);if(a.has(p))continue;a.add(p);let g={from:d,to:f,weight:2};i.color&&(g.color=i.color),s.push(g)}}return s}let o=Math.cos(n*Math.PI/180),t=new Map,r=[[0,1],[1,2],[2,0]];for(let a of e){let s=ga(a);for(let[i,l]of r){let u=a.vertices[i],m=a.vertices[l],d=$r(u,m),f=t.get(d);f?f.normals.push(s):t.set(d,{normals:[s],from:u,to:m,color:a.color})}}let c=[];for(let{normals:a,from:s,to:i,color:l}of t.values()){if(a.length<2){let m={from:s,to:i,weight:2};l&&(m.color=l),c.push(m);continue}let u=!1;e:for(let m=0;m<a.length;m++)for(let d=m+1;d<a.length;d++)if(ya(a[m],a[d])<o){u=!0;break e}if(u){let m={from:s,to:i,weight:2};l&&(m.color=l),c.push(m)}}return c}function ba(e,n=0){return ha(e,n)}export{ns as BASE_TILE,zn as CAMERA_BACKFACE_CULL_EPS,Le as DEFAULT_CAMERA_STATE,Fr as DEFAULT_PROJECTION,Ci as LoopOnce,Si as LoopPingPong,Ai as LoopRepeat,Kr as QUAT_IDENTITY,ir as VOXEL_CAMERA_CULL_AXIS_EPS,ar as VOXEL_CAMERA_CULL_NORMAL_LIMIT,Bn as antiprismPolygons,gr as arrowPolygons,dr as axesHelperPolygons,ia as bakeSolidTextureSampledPolygons,to as bakeSolidTextureSamples,jn as bipyramidPolygons,Xr as buildSceneContext,fr as cameraCullNormalGroups,fi as cameraCullNormalGroupsFromPolygons,ur as cameraCullNormalKey,di as cameraCullVisibleSignature,lr as cameraFacingDepth,Se as clampChannel,bo as computeSceneBbox,Br as computeShapeLighting,Nn as conePolygons,Et as coverPlanarPolygons,Ii as createGlyphAnimationMixer,rs as createIsometricCamera,En as cubePolygons,$e as cuboctahedronPolygons,Ie as cullInteriorPolygons,Gn as cylinderPolygons,Ot as dedupeOverlappingPolygons,ct as deltoidalHexecontahedronPolygons,st as deltoidalIcositetrahedronPolygons,ot as disdyakisDodecahedronPolygons,rt as disdyakisTriacontahedronPolygons,Dn as dodecahedronPolygons,es as eulerXYZFromQuat,So as findOverlappingPolygonDuplicates,dn as formatColor,Xn as greatDodecahedronPolygons,Wn as greatIcosahedronPolygons,Yn as greatStellatedDodecahedronPolygons,Ln as icosahedronPolygons,Fe as icosidodecahedronPolygons,Wr as inverseRotateVec3,mr as isAxisAlignedSurfaceNormal,mi as isVoxelCameraCullableNormalGroups,da as loadMesh,ue as mergePolygons,Ht as normalFacesCamera,ts as normalizeInvertMultiplier,At as normalizePolygons,kn as octahedronPolygons,$t as optimizeMeshPolygons,Ee as parseColor,eo as parseGltf,ao as parseHexColor,Zt as parseMtl,Wt as parseObj,Vt as parsePureColor,lo as parseRgbColor,ro as parseVox,at as pentagonalHexecontahedronPolygons,it as pentagonalIcositetrahedronPolygons,tt as pentakisDodecahedronPolygons,br as planePolygons,qt as polygonCssSurfaceNormal,Yr as polygonFaces,ui as polygonFacesCamera,Un as prismPolygons,pa as project,Fn as pyramidPolygons,Qr as quatFromAxisAngle,Jr as quatFromEulerXYZ,Zr as quatMultiply,Pr as resolveGeometry,Kn as rhombicDodecahedronPolygons,Zn as rhombicTriacontahedronPolygons,Ke as rhombicosidodecahedronPolygons,We as rhombicuboctahedronPolygons,yr as ringPolygons,hr as ringQuadPolygons,yn as rotateVec3,Ur as shadeColor,Hn as smallStellatedDodecahedronPolygons,Ze as snubCubePolygons,Qe as snubDodecahedronPolygons,_n as spherePolygons,Rn as tetrahedronPolygons,et as tetrakisHexahedronPolygons,$n as torusPolygons,qn as trapezohedronPolygons,nt as triakisIcosahedronPolygons,Jn as triakisOctahedronPolygons,Qn as triakisTetrahedronPolygons,ba as trianglesToFeatureEdges,Be as truncatedCubePolygons,Xe as truncatedCuboctahedronPolygons,qe as truncatedDodecahedronPolygons,He as truncatedIcosahedronPolygons,Ye as truncatedIcosidodecahedronPolygons,je as truncatedOctahedronPolygons,Ue as truncatedTetrahedronPolygons};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glyphcss/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Pure math engine for ASCII polygon mesh rendering. Zero browser globals.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",