@glyphcss/core 0.0.5 → 0.0.6

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.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var Bt=Object.defineProperty;var Ns=Object.getOwnPropertyDescriptor;var _s=Object.getOwnPropertyNames;var Gs=Object.prototype.hasOwnProperty;var $s=(e,n)=>{for(var o in n)Bt(e,o,{get:n[o],enumerable:!0})},Fs=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of _s(n))!Gs.call(e,r)&&r!==o&&Bt(e,r,{get:()=>n[r],enumerable:!(t=Ns(n,r))||t.enumerable});return e};var Us=e=>Fs(Bt({},"__esModule",{value:!0}),e);var gl={};$s(gl,{BASE_TILE:()=>or,CAMERA_BACKFACE_CULL_EPS:()=>yn,DEFAULT_CAMERA_STATE:()=>we,DEFAULT_PROJECTION:()=>No,LoopOnce:()=>Zr,LoopPingPong:()=>Jr,LoopRepeat:()=>Qr,QUAT_IDENTITY:()=>Ko,VOXEL_CAMERA_CULL_AXIS_EPS:()=>mo,VOXEL_CAMERA_CULL_NORMAL_LIMIT:()=>po,antiprismPolygons:()=>Tn,arrowPolygons:()=>Mo,axesHelperPolygons:()=>Po,bakeSolidTextureSampledPolygons:()=>Ps,bakeSolidTextureSamples:()=>At,bipyramidPolygons:()=>In,buildSceneContext:()=>Xo,buildTextureSamplers:()=>Ms,cameraCullNormalGroups:()=>ho,cameraCullNormalGroupsFromPolygons:()=>qr,cameraCullNormalKey:()=>yo,cameraCullVisibleSignature:()=>Wr,cameraFacingDepth:()=>go,clampChannel:()=>Me,computeSceneBbox:()=>Wt,computeShapeLighting:()=>Bo,conePolygons:()=>vn,coverPlanarPolygons:()=>rt,createGlyphAnimationMixer:()=>es,createIsometricCamera:()=>sr,cubePolygons:()=>xn,cuboctahedronPolygons:()=>ke,cullInteriorPolygons:()=>ve,cylinderPolygons:()=>Cn,dedupeOverlappingPolygons:()=>nt,deltoidalHexecontahedronPolygons:()=>Hn,deltoidalIcositetrahedronPolygons:()=>jn,disdyakisDodecahedronPolygons:()=>Un,disdyakisTriacontahedronPolygons:()=>Bn,dodecahedronPolygons:()=>Pn,eulerXYZFromQuat:()=>er,findOverlappingPolygonDuplicates:()=>Zt,formatColor:()=>on,greatDodecahedronPolygons:()=>En,greatIcosahedronPolygons:()=>kn,greatStellatedDodecahedronPolygons:()=>Rn,icosahedronPolygons:()=>Mn,icosidodecahedronPolygons:()=>De,inverseRotateVec3:()=>Yo,isAxisAlignedSurfaceNormal:()=>bo,isVoxelCameraCullableNormalGroups:()=>Xr,loadMesh:()=>Rs,mergePolygons:()=>ae,normalFacesCamera:()=>ht,normalizeInvertMultiplier:()=>rr,normalizePolygons:()=>Jn,octahedronPolygons:()=>hn,optimizeMeshPolygons:()=>ft,parseColor:()=>Ie,parseGltf:()=>vt,parseHexColor:()=>jt,parseMtl:()=>Pt,parseObj:()=>xt,parsePureColor:()=>Kn,parseRgbColor:()=>Ht,parseStl:()=>zt,parseVox:()=>St,pentagonalHexecontahedronPolygons:()=>Xn,pentagonalIcositetrahedronPolygons:()=>qn,pentakisDodecahedronPolygons:()=>Fn,planePolygons:()=>vo,polygonCssSurfaceNormal:()=>yt,polygonFaces:()=>Wo,polygonFacesCamera:()=>Hr,polygonTexture:()=>Cs,prismPolygons:()=>On,project:()=>ks,pyramidPolygons:()=>Sn,quatFromAxisAngle:()=>Qo,quatFromEulerXYZ:()=>Jo,quatMultiply:()=>Zo,resolveGeometry:()=>Ao,rhombicDodecahedronPolygons:()=>Dn,rhombicTriacontahedronPolygons:()=>Ln,rhombicosidodecahedronPolygons:()=>je,rhombicuboctahedronPolygons:()=>Be,ringPolygons:()=>Vo,ringQuadPolygons:()=>Co,rotateVec3:()=>rn,sampleTexel:()=>Vs,shadeColor:()=>Uo,smallStellatedDodecahedronPolygons:()=>zn,snubCubePolygons:()=>He,snubDodecahedronPolygons:()=>qe,spherePolygons:()=>Vn,tetrahedronPolygons:()=>bn,tetrakisHexahedronPolygons:()=>Gn,torusPolygons:()=>An,trapezohedronPolygons:()=>wn,triakisIcosahedronPolygons:()=>$n,triakisOctahedronPolygons:()=>_n,triakisTetrahedronPolygons:()=>Nn,trianglesToFeatureEdges:()=>Ls,truncatedCubePolygons:()=>Ne,truncatedCuboctahedronPolygons:()=>Fe,truncatedDodecahedronPolygons:()=>Ge,truncatedIcosahedronPolygons:()=>$e,truncatedIcosidodecahedronPolygons:()=>Ue,truncatedOctahedronPolygons:()=>_e,truncatedTetrahedronPolygons:()=>Le});module.exports=Us(gl);var No="cubic";function jt(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 Ht(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 Kn(e){if(!e)return null;let n=e.trim(),o=jt(n);return o||Ht(n)}function Me(e){return Math.max(0,Math.min(255,Math.round(e)))}function on(e){let[n,o,t]=e.rgb.map(Me);return e.alpha<1?`rgba(${n}, ${o}, ${t}, ${e.alpha})`:`rgb(${n}, ${o}, ${t})`}var Xt={rgb:[204,204,204],alpha:1},_o=new Map;function Ie(e){if(!e)return null;let n=e.trim(),o=_o.get(n);if(o)return o;let t=Kn(n);return t?(_o.set(n,t),t):null}function Uo(e,n){let o=Ie(e)??Xt,t=[Me(o.rgb[0]+n),Me(o.rgb[1]+n),Me(o.rgb[2]+n)];return on({rgb:t,alpha:o.alpha})}var qt={direction:[0,0,-1],color:"#ffffff",intensity:1},Go={color:"#ffffff",intensity:.4};function $o(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 Fo(e,n,o){let t=Ie(n)??Xt;return e*(t.rgb[o]/255)}function Bo(e,n,o,t){let r=Ie(n)??Xt,s=$o(o?.direction??qt.direction),i=o?.color??qt.color,c=Math.max(0,o?.intensity??qt.intensity),a=t?.color??Go.color,l=Math.max(0,t?.intensity??Go.intensity),u=$o(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),d=c*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],b=Fo(g,a,p)*l,P=Fo(g,i,p)*d;m[p]=Me(b+P)}return on({rgb:m,alpha:r.alpha})}var jo="#cccccc",Zn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Ho=(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]],qo=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Qn=e=>Math.hypot(e[0],e[1],e[2]);function Bs(e){let n=1/0,o=1/0,t=1/0,r=-1/0,s=-1/0,i=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<o&&(o=u[1]),u[1]>s&&(s=u[1]),u[2]<t&&(t=u[2]),u[2]>i&&(i=u[2]);let c=r-n,a=s-o,l=i-t;return Math.hypot(c,a,l)}function js(){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 Jn(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 s=r.vertices;if(s.length<3){o.push(`Polygon ${t}: ${s.length} vertices (need >= 3), dropped`);continue}let i=Zn(s[1],s[0]),c=Zn(s[2],s[0]),a=Ho(i,c),l=Qn(a);if(s.length===3){if(l<1e-12){Qn(i)<1e-12||Qn(c)<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:s.slice()}];if(s.length>=4){let f=[a[0]/l,a[1]/l,a[2]/l],d=qo(f,s[0]),m=Bs(s),p=Math.max(1e-6,m*.001),g=0;for(let b=3;b<s.length;b++){let P=Math.abs(qo(f,s[b])-d);P>g&&(g=P)}if(g>p){let b=[],P=r.uvs&&r.uvs.length===s.length?r.uvs:void 0;for(let C=1;C<s.length-1;C++){let v=[s[0].slice(),s[C].slice(),s[C+1].slice()],V=Ho(Zn(v[1],v[0]),Zn(v[2],v[0]));if(Qn(V)<1e-12)continue;let h={...r,vertices:v};P&&(h.uvs=[P[0].slice(),P[C].slice(),P[C+1].slice()]),b.push(h)}if(b.length===0){o.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}o.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulated to ${b.length} triangles`),u=b}}for(let f of u){let d=Hs(f,t,o);d&&n.push(d)}}return{polygons:n,warnings:o}}function Hs(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&&js()&&o.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Ie(e.color)?t.color=e.color:(o.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${jo}`),t.color=jo)),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 s={},i=!1;for(let c of Object.keys(e.data)){let a=e.data[c];typeof a=="string"||typeof a=="number"||typeof a=="boolean"?s[c]=a:(i=!0,o.push(`Polygon ${n}: data["${c}"] has non-primitive value, key dropped`))}Object.keys(s).length>0&&(t.data=s)}return t}function Wt(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,s=-1/0,i=-1/0,c=!1;for(let a of e)if(a?.vertices)for(let l of a.vertices)l&&(c=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<o&&(o=l[1]),l[1]>s&&(s=l[1]),l[2]<t&&(t=l[2]),l[2]>i&&(i=l[2]));return c?{min:[n,o,t],max:[r,s,i]}:{min:[0,0,0],max:[0,0,0]}}function Xo(e){let n=e.polygons??[],o,t;if(e.skipNormalize)o=n,t=[];else{let c=Jn(n);o=c.polygons,t=c.warnings}let r=Wt(o),s=[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:s},warnings:t}}function Wo(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function rn(e,n,o,t){let r=n*Math.PI/180,s=o*Math.PI/180,i=t*Math.PI/180,[c,a,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[c,a]=[c*u-a*f,c*f+a*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[c,l]=[c*u+l*f,-c*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[a,l]=[a*u-l*f,a*f+l*u]}return[c,a,l]}function Yo(e,n){let o=-n[0]*Math.PI/180,t=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[s,i,c]=e;if(o!==0){let a=Math.cos(o),l=Math.sin(o);[i,c]=[i*a-c*l,i*l+c*a]}if(t!==0){let a=Math.cos(t),l=Math.sin(t);[s,c]=[s*a+c*l,-s*l+c*a]}if(r!==0){let a=Math.cos(r),l=Math.sin(r);[s,i]=[s*a-i*l,s*l+i*a]}return[s,i,c]}var Yt=Math.PI/180,sn=180/Math.PI,Ko=[1,0,0,0];function Zo(e,n){let[o,t,r,s]=e,[i,c,a,l]=n;return[o*i-t*c-r*a-s*l,o*c+t*i+r*l-s*a,o*a-t*l+r*i+s*c,o*l+t*a-r*c+s*i]}function Qo(e,n){let o=n*.5,t=Math.sin(o);return[Math.cos(o),e[0]*t,e[1]*t,e[2]*t]}function Jo(e){let n=e[0]*Yt,o=e[1]*Yt,t=e[2]*Yt,r=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(o*.5),c=Math.sin(o*.5),a=Math.cos(t*.5),l=Math.sin(t*.5);return[r*i*a-s*c*l,s*i*a+r*c*l,r*c*a-s*i*l,r*i*l+s*c*a]}function er(e){let[n,o,t,r]=e,s=2*(o*r+n*t),i=2*(t*r-n*o),c=1-2*(o*o+t*t),a=2*(o*t-n*r),l=1-2*(t*t+r*r),u=Math.max(-1,Math.min(1,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,c)*sn,f*sn,Math.atan2(-a,l)*sn]:[Math.atan2(2*(t*r+n*o),1-2*(o*o+r*r))*sn,f*sn,0]}var or=50;function rr(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var we={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},nr=100,tr=1e4,Ke=e=>Math.round(e*nr)/nr,qs=e=>Math.round(e*tr)/tr;function sr(e={}){let n={target:e.target??[...we.target],rotX:e.rotX??we.rotX,rotY:e.rotY??we.rotY,zoom:e.zoom??we.zoom,distance:e.distance??we.distance};function o(r){r.target!==void 0&&(n.target=[Ke(r.target[0]),Ke(r.target[1]),Ke(r.target[2])]),r.rotX!==void 0&&(n.rotX=Ke(r.rotX)),r.rotY!==void 0&&(n.rotY=Ke(r.rotY)),r.zoom!==void 0&&(n.zoom=qs(r.zoom)),r.distance!==void 0&&(n.distance=Ke(r.distance))}function t(r={}){let i=(r.cols??0)*50,c=(r.rows??0)*50,[a,l,u]=n.target,f=l*50,d=a*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-d}px, ${-m}px)`,width:`${i}px`,height:`${c}px`}}return{state:n,update:o,getStyle:t}}var Ce=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],et=(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]],cn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Kt=e=>Math.hypot(e[0],e[1],e[2]),Ve=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function Xs(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 ir(e){if(e.length<3)return null;let n=Ce(e[1],e[0]),o=Ce(e[2],e[0]),t=et(n,o),r=Kt(t);if(r<1e-12)return null;let s=[t[0]/r,t[1]/r,t[2]/r],i=cn(s,e[0]);return{normal:s,d:i}}function Ws(e,n){return cn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function Ys(e,n){return cn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function Ks(e,n,o,t){let r=e.vertices.findIndex(y=>Ve(y,o)),s=e.vertices.findIndex(y=>Ve(y,t)),i=n.vertices.findIndex(y=>Ve(y,o)),c=n.vertices.findIndex(y=>Ve(y,t));if(r<0||s<0||i<0||c<0)return null;let a=e.vertices.length,l=n.vertices.length,u=(r+1)%a===s,f=(i+1)%l===c;if(u===f)return null;let d=u?s:r,m=u?r:s,p=f?c:i,g=f?i:c,b=!!(e.uvs&&n.uvs),P=[],C=b?[]:void 0,v=d;for(;P.push(e.vertices[v]),C&&C.push(e.uvs[v]),v!==m;)v=(v+1)%a;for(v=p;P.push(n.vertices[v]),C&&C.push(n.uvs[v]),v!==g;)v=(v+1)%l;let V=[],h=C?[]:void 0;for(let y=0;y<P.length;y++)(V.length===0||!Ve(P[y],V[V.length-1]))&&(V.push(P[y]),h&&C&&h.push(C[y]));if(V.length>1&&Ve(V[0],V[V.length-1])&&(V.pop(),h?.pop()),b)return cr(V,h);let M=[],S=h?[]:void 0;for(let y=0;y<V.length;y++){let x=V[(y-1+V.length)%V.length],A=V[y],I=V[(y+1)%V.length],R=et(Ce(A,x),Ce(I,x));Kt(R)>1e-9&&(M.push(A),S&&h&&S.push(h[y]))}return M.length<3?null:cr(M,S)}function Zs(e,n){let o=e.length,t=0;for(let r=0;r<o;r++){let s=e[r],i=e[(r+1)%o],c=e[(r+2)%o],a=Ce(i,s),l=Ce(c,i),u=cn(et(a,l),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 Qs(e,n){if(e.length<3)return!1;let o=ir(e);if(!o)return!1;for(let t of e)if(Math.abs(cn(o.normal,t)-o.d)>n)return!1;return!0}function Js(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function ec(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 cr(e,n){for(let o=0;o<e.length;o++){let t=e[o],r=e[(o+1)%e.length],s=e[(o+2)%e.length];if(!(Kt(et(Ce(r,t),Ce(s,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 ae(e){let n=[],o=[];for(let r of e??[]){if(!r||!r.vertices||r.vertices.length<3){r&&n.push(r);continue}let s=r.vertices.map(l=>[l[0],l[1],l[2]]),i=ir(s);if(!i){n.push(r);continue}let c=r.texture&&r.uvs&&r.uvs.length===s.length?r.uvs.map(l=>[l[0],l[1]]):void 0,a=r.texture&&c?r.textureTriangles?.length?Js(r.textureTriangles):ec(s,c):void 0;o.push({vertices:s,uvs:c,color:r.color??"#cccccc",texture:r.texture,textureTriangles:a,normal:i.normal,d:i.d,alive:!0,data:r.data})}let t=()=>{let r=new Map;for(let c=0;c<o.length;c++){let a=o[c];if(!a.alive)continue;let l=a.vertices.length;for(let u=0;u<l;u++){let f=a.vertices[u],d=a.vertices[(u+1)%l],m=Xs(f,d),p=r.get(m);p||(p=[],r.set(m,p)),p.push(c)}}let s=!1,i=(c,a)=>{for(let l=0;l<c.vertices.length;l++){let u=c.vertices[l],f=c.vertices[(l+1)%c.vertices.length];for(let d=0;d<a.vertices.length;d++){let m=a.vertices[d],p=a.vertices[(d+1)%a.vertices.length];if(Ve(u,p)&&Ve(f,m))return[u,f]}}return null};for(let[,c]of r){if(c.length<2)continue;let[a,l]=c;if(a===l)continue;let u=o[a],f=o[l];if(!u.alive||!f.alive||u.color!==f.color||u.texture!==f.texture)continue;let d=!!(u.texture||f.texture);if(d&&(!u.textureTriangles||!f.textureTriangles)||!!u.uvs!=!!f.uvs||(d?!Ys(u,f):!Ws(u,f)))continue;let m=i(u,f);if(!m)continue;let[p,g]=m,b=Ks(u,f,p,g);b&&Qs(b.vertices,.001)&&Zs(b.vertices,u.normal)&&(u.vertices=b.vertices,u.uvs=b.uvs,u.textureTriangles=d?[...u.textureTriangles??[],...f.textureTriangles??[]]:void 0,f.alive=!1,s=!0)}return s};for(;t(););for(let r of o){if(!r.alive)continue;let s={vertices:r.vertices,color:r.color};r.texture&&(s.texture=r.texture),r.uvs&&(s.uvs=r.uvs),r.textureTriangles?.length&&(s.textureTriangles=r.textureTriangles),r.data&&(s.data=r.data),n.push(s)}return n}var nc=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],tc=(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 oc(e,n){let o=e.vertices;if(!o||o.length<3)return null;let t=0,r=0,s=0;for(let g=0;g<o.length;g++){let b=o[g],P=o[(g+1)%o.length];t+=(b[1]-P[1])*(b[2]+P[2]),r+=(b[2]-P[2])*(b[0]+P[0]),s+=(b[0]-P[0])*(b[1]+P[1])}let i=Math.hypot(t,r,s);if(i<1e-12)return null;let c=[t/i,r/i,s/i],a=0,l=0,u=0;for(let g of o)a+=g[0],l+=g[1],u+=g[2];let f=1/o.length,d=[a*f,l*f,u*f],m=ye(c,d),p=i*.5;return{index:n,polygon:e,normal:c,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function rc(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),s=Math.hypot(o,t,r);o/=s,t/=s,r/=s;let i=[o,t,r],c=tc(e,i);return{u:i,v:c}}function sc(e){if(e.local2D)return;let n=rc(e.normal),o=[],t=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.polygon.vertices){let a=ye(c,n.u),l=ye(c,n.v);o.push([a,l]),a<t&&(t=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}e.local2D=o,e.bbox2D={min:[t,r],max:[s,i]},e.basis=n}function cc(e,n){let o=[],t=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.vertices){let a=ye(c,n.u),l=ye(c,n.v);o.push([a,l]),a<t&&(t=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}return{local2D:o,bbox2D:{min:[t,r],max:[s,i]}}}function ic(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 ar(e,n){let o=!1;for(let t=0,r=n.length-1;t<n.length;r=t++){let s=n[t],i=n[r];s[1]>e[1]!=i[1]>e[1]&&e[0]<(i[0]-s[0])*(e[1]-s[1])/(i[1]-s[1]+1e-30)+s[0]&&(o=!o)}return o}function lr(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 ac(e,n){let o=lr(e),t=lr(n),r=1e-4,s=0;for(let l of e){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];ar(u,n)&&s++}let i=0;for(let l of n){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];ar(u,e)&&i++}let c=s/e.length,a=i/n.length;return Math.max(c,a)}function lc(e,n){let o=e.normal[0],t=e.normal[1],r=e.normal[2],s=Math.abs(o),i=Math.abs(t),c=Math.abs(r),a=o;i>s&&i>c?a=t:c>s&&c>i&&(a=r),a<0&&(o=-o,t=-t,r=-r);let l=Math.round(o/.05),u=Math.round(t/.05),f=Math.round(r/.05),d=e.d*(e.normal[0]===o&&e.normal[1]===t&&e.normal[2]===r?1:-1),m=Math.round(d/(n*2));return`${l},${u},${f}|${m}`}function uc(e,n,o,t){let r=ye(e.normal,n.normal);if(Math.abs(r)<1-o)return!1;let s=r>0?1:-1;return Math.abs(e.d-s*n.d)<t}function ur(e,n){let o=nc(n,e.centroid);return ye(e.normal,o)>0}function Zt(e,n){if(!e||e.length<2)return new Set;let o=n?.normalTolerance??.001,t=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,s=[];for(let m=0;m<e.length;m++){let p=oc(e[m],m);p&&s.push(p)}if(s.length<2)return new Set;let i=0,c=0,a=0,l=0;for(let m of s)i+=m.centroid[0]*m.area,c+=m.centroid[1]*m.area,a+=m.centroid[2]*m.area,l+=m.area;let u=l>0?[i/l,c/l,a/l]:[0,0,0],f=new Map;for(let m of s){let p=lc(m,t),g=f.get(p);g||(g=[],f.set(p,g)),g.push(m)}let d=new Set;for(let m of f.values())if(!(m.length<2))for(let p=0;p<m.length;p++){let g=m[p];if(!d.has(g.index))for(let b=p+1;b<m.length;b++){let P=m[b];if(d.has(P.index)||!uc(g,P,o,t))continue;sc(g);let C=cc(P.polygon,g.basis);if(!ic(g.bbox2D,C.bbox2D)||ac(g.local2D,C.local2D)<r)continue;let V=ur(g,u),h=ur(P,u),M;if(V&&!h?M=g:h&&!V?M=P:M=g.area<P.area?g:P,d.add(M.index),M===g)break}}return d}function nt(e,n){if(!e||e.length<2)return e??[];let o=Zt(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 fc=4,mc=8,dc=.001,pc=1e-9,gc=1e6,yc=1e6,ze=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],eo=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],un=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],Ee=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],gr=(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]],yr=e=>Math.hypot(e[0],e[1],e[2]);function fn(e){let n=yr(e);return n<=pc?null:[e[0]/n,e[1]/n,e[2]/n]}function ln(e,n){return Math.round(e*n)/n}function pe(e){return ln(e,gc)}function Qt(e){return ln(e,yc)}function Jt(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 hc(e){let n=be(e.a),o=be(e.b);return n<o?`${n}|${o}`:`${o}|${n}`}function Ze(e){return`${e[0]},${e[1]},${e[2]}`}function hr(e,n){let o=Ze(e),t=Ze(n);return o<t?`${o}|${t}`:`${t}|${o}`}function no(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function fr(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",no(e.data)].join("|")}function br(e){let n=e.vertices;if(!n||n.length<3)return null;let o=n[0],t=[0,0,0];for(let s=1;s<n.length-1;s++)t=eo(t,gr(ze(n[s],o),ze(n[s+1],o)));let r=fn(t);return r?{normal:r,d:Ee(r,o)}:null}function bc(e,n,o){return Ee(e.normal,n.normal)>1-o&&Math.abs(e.d-n.d)<=o}function xc(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function Pc(e,n){let o=n[e[0]]?.data,t=no(o);for(let r of e)if(no(n[r].data)!==t)return;return o?{...o}:void 0}function Mc(e,n){let o=e.map(a=>xc(a)?br(a):null),t=o.map(Boolean),r=new Map;for(let a=0;a<e.length;a++){if(!o[a])continue;let l=e[a].vertices;for(let u=0;u<l.length;u++){let f=hr(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:a,edge:u};d?d.push(m):r.set(f,[m])}}let s=e.map(()=>new Set);for(let a of r.values())if(!(a.length<2))for(let l=0;l<a.length;l++)for(let u=l+1;u<a.length;u++){let f=a[l].polygon,d=a[u].polygon,m=o[f],p=o[d];!m||!p||fr(e[f])===fr(e[d])&&bc(m,p,n)&&(s[f].add(d),s[d].add(f))}let i=new Set,c=[];for(let a=0;a<e.length;a++){if(!t[a]||i.has(a))continue;let l=[],u=[a];for(i.add(a);u.length>0;){let f=u.shift();l.push(f);for(let d of s[f])i.has(d)||(i.add(d),u.push(d))}c.push(l)}return{groups:c}}function Vc(e,n){let o=new Set(e),t=new Map;for(let s of e){let i=n[s].vertices;for(let c=0;c<i.length;c++){let a=hr(i[c],i[(c+1)%i.length]),l=t.get(a),u={polygon:s,edge:c};l?l.push(u):t.set(a,[u])}}let r=[];for(let s of t.values()){let i=s.filter(c=>o.has(c.polygon));if(i.length===1){let c=i[0],a=n[c.polygon].vertices;r.push({a:a[c.edge],b:a[(c.edge+1)%a.length]})}else if(i.length!==2)return null}return r}function Cc(e){let n=new Map;for(let o of e)n.set(Ze(o.a),(n.get(Ze(o.a))??0)+1),n.set(Ze(o.b),(n.get(Ze(o.b))??0)+1);for(let o of n.values())if(o%2!==0)return!1;return!0}function xr(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 vc(e){let n=xr(e);return`${ln(n[0],1e3)},${ln(n[1],1e3)},${ln(n[2],1e3)}`}function Ac(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],o=ze(n,un(e,Ee(n,e)));return fn(o)??[1,0,0]}function Sc(e,n,o){let t=new Map;for(let s of e){let i=ze(s.b,s.a),c=ze(i,un(n,Ee(i,n))),a=fn(c);if(!a)continue;let l=xr(a),u=vc(l),f=yr(c),d=t.get(u);d?d.weight+=f:t.set(u,{axis:l,weight:f})}let r=[...t.values()].sort((s,i)=>i.weight-s.weight).slice(0,o).map(s=>s.axis);return r.length===0&&r.push(Ac(n)),r}function mr(e,n,o,t){let r=ze(e,n);return[pe(Ee(r,o)),pe(Ee(r,t))]}function Oc(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 an(e,n){let[o,t]=e.a,[r,s]=e.b,i=(n-o)/(r-o);return pe(t+(s-t)*i)}function to(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],s=n[t],i=n[(t+1)%n.length],c=(s[0]-r[0])*(i[1]-s[1])-(s[1]-r[1])*(i[0]-s[0]);Math.abs(c)>1e-8&&o.push(s)}return o}function ot(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 dr(e){let n=1/0,o=1/0,t=-1/0,r=-1/0;for(let[s,i]of e)n=Math.min(n,s),o=Math.min(o,i),t=Math.max(t,s),r=Math.max(r,i);return{minX:n,minY:o,maxX:t,maxY:r}}function Tc(e,n){let o=dr(e),t=dr(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 tt(e){return Math.abs(ot(e))}function Ic(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],s=e[(o+2)%e.length],i=(r[0]-t[0])*(s[1]-r[1])-(r[1]-t[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-8)continue;let c=i>0?1:-1;if(n===0)n=c;else if(n!==c)return!1}return!0}function wc(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],c=t*i-r*s,a=Math.hypot(t,r);if(a<=1e-9||Math.abs(c)>Math.max(1e-8,a*1e-8))return!1;let l=s*t+i*r;return l>=-1e-8&&l<=t*t+r*r+1e-8}function zc(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],s=t*t+r*r;return s<=1e-12?0:((e[0]-n[0])*t+(e[1]-n[1])*r)/s}function pr(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t],s=e[(t+1)%e.length],i=[{t:0,point:r},{t:1,point:s}];for(let a of n)Jt(a,r)||Jt(a,s)||wc(a,r,s)&&i.push({t:zc(a,r,s),point:a});i.sort((a,l)=>a.t-l.t);let c=[];for(let a of i)c.some(l=>Math.abs(l.t-a.t)<=1e-8||Jt(l.point,a.point))||c.push(a);for(let a=0;a<c.length-1;a++){let l=c[a].point,u=c[a+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||o.push({a:[pe(l[0]),pe(l[1])],b:[pe(u[0]),pe(u[1])]})}}return o}function Ec(e,n){if(!Tc(e,n))return null;let o=[...pr(e,n),...pr(n,e)],t=new Map;for(let g of o){let b=hc(g),P=t.get(b);P?P.push(g):t.set(b,[g])}let r=!1,s=[];for(let g of t.values()){if(g.length===1){s.push(g[0]);continue}r=!0;let b=g.filter(C=>be(C.a)<be(C.b)).length,P=g.length-b;if(b!==P)return null}if(!r||s.length<3)return null;let i=new Map;for(let g of s){let b=be(g.a);if(i.has(b))return null;i.set(b,g)}let c=s[0],a=be(c.a),l=[],u=new Set,f=a;for(let g=0;g<=s.length;g++){let b=i.get(f);if(!b)return null;let P=`${be(b.a)}>${be(b.b)}`;if(u.has(P))return null;if(u.add(P),l.push(b.a),f=be(b.b),f===a)break}if(f!==a||u.size!==s.length)return null;let d=to(l);if(d.length<3||!Ic(d))return null;let m=tt(d),p=tt(e)+tt(n);return Math.abs(m-p)>Math.max(1e-5,p*1e-5)?null:ot(d)>=0?d:[...d].reverse()}function Rc(e){let n=e.map(to).filter(t=>t.length>=3&&tt(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 s=Ec(n[t],n[r]);if(s){n[t]=s,n.splice(r,1),o=!0;break}}if(o)break}}return n}function kc(e,n,o){let t=new Map;return r=>{let s=pe(r[0]),i=pe(r[1]),c=`${s},${i}`,a=t.get(c);if(a)return[a[0],a[1],a[2]];let l=eo(e,eo(un(n,s),un(o,i))),u=[Qt(l[0]),Qt(l[1]),Qt(l[2])];return t.set(c,u),[u[0],u[1],u[2]]}}function Dc(e,n,o,t,r){let s=o[0]?.a;if(!s)return null;let i=fn(ze(r,un(t,Ee(r,t))));if(!i)return null;let c=fn(gr(t,i));if(!c)return null;let a=[],l=[];for(let b of o){let P=mr(b.a,s,i,c),C=mr(b.b,s,i,c);Math.hypot(P[0]-C[0],P[1]-C[1])<=1e-7||(a.push({a:P,b:C}),l.push(P[0],C[0]))}let u=Oc(l);if(a.length<3||u.length<2)return null;let f=n[e[0]].color,d=Pc(e,n),m=[];for(let b=0;b<u.length-1;b++){let P=u[b],C=u[b+1];if(C-P<=1e-7)continue;let v=(P+C)/2,V=a.filter(h=>{let M=Math.min(h.a[0],h.b[0]),S=Math.max(h.a[0],h.b[0]);return M<v&&v<S&&Math.abs(h.a[0]-h.b[0])>1e-7}).map(h=>({segment:h,yMid:an(h,v)})).sort((h,M)=>h.yMid-M.yMid);if(V.length!==0){if(V.length%2!==0)return null;for(let h=0;h<V.length;h+=2){let M=V[h].segment,S=V[h+1].segment,y=an(M,P),x=an(M,C),A=an(S,P),I=an(S,C),R=to([[P,y],[C,x],[C,I],[P,A]]);if(R.length<3||Math.abs(ot(R))<=1e-8)continue;let E=ot(R)>0?R:[...R].reverse();m.push(E)}}}if(m.length===0)return null;let p=kc(s,i,c),g=Rc(m).map(b=>({vertices:b.map(p),...f?{color:f}:{},...d?{data:d}:{}}));return ae(g)}function Lc(e,n,o){let t=Vc(e,n);if(!t||t.length<3||!Cc(t))return null;let r=br(n[e[0]]);if(!r)return null;let s=null;for(let i of Sc(t,r.normal,o)){let c=Dc(e,n,t,r.normal,i);c&&(!s||c.length<s.length)&&(s=c)}return!s||s.length>=e.length?null:s}function rt(e,n={}){let o=n.minGroupPolygons??fc,t=n.maxCandidateAxes??mc,r=n.planeEpsilon??dc,s=e??[];if(s.length<o)return s;let{groups:i}=Mc(s,r);if(i.length===0)return s;let c=new Map,a=new Set;for(let u of i){if(u.length<o)continue;let f=Lc(u,s,t);if(f){c.set(u[0],f);for(let d of u)a.add(d)}}if(c.size===0)return s;let l=[];for(let u=0;u<s.length;u++){let f=c.get(u);if(f){l.push(...f);continue}a.has(u)||l.push(s[u])}return l}function Nc(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0;for(let[E,O,w]of n)o+=E,t+=O,r+=w;let s=1/n.length;o*=s,t*=s,r*=s;let i=n[0],c=n[1],a=n[2],l=c[0]-i[0],u=c[1]-i[1],f=c[2]-i[2],d=a[0]-i[0],m=a[1]-i[1],p=a[2]-i[2],g=u*p-f*m,b=f*d-l*p,P=l*m-u*d,C=Math.hypot(g,b,P);if(C<1e-9)return null;g/=C,b/=C,P/=C;let v=n.length-2,V=new Float64Array(v*9),h=0;for(let E=1;E<n.length-1;E++){let O=n[0],w=n[E],D=n[E+1];V[h++]=O[0],V[h++]=O[1],V[h++]=O[2],V[h++]=w[0],V[h++]=w[1],V[h++]=w[2],V[h++]=D[0],V[h++]=D[1],V[h++]=D[2]}let M=0,S=1/0,y=1/0,x=1/0,A=-1/0,I=-1/0,R=-1/0;for(let[E,O,w]of n){let D=E-o,L=O-t,z=w-r,T=D*D+L*L+z*z;T>M&&(M=T),E<S&&(S=E),E>A&&(A=E),O<y&&(y=O),O>I&&(I=O),w<x&&(x=w),w>R&&(R=w)}return{centroid:[o,t,r],normal:[g,b,P],vertices:n,triFlat:V,bcx:o,bcy:t,bcz:r,br2:M,minX:S,minY:y,minZ:x,maxX:A,maxY:I,maxZ:R}}function _c(e,n,o,t,r,s,i,c){let a=i[c],l=i[c+1],u=i[c+2],f=i[c+3]-a,d=i[c+4]-l,m=i[c+5]-u,p=i[c+6]-a,g=i[c+7]-l,b=i[c+8]-u,P=r*b-s*g,C=s*p-t*b,v=t*g-r*p,V=f*P+d*C+m*v;if(V>-1e-9&&V<1e-9)return!1;let h=1/V,M=e-a,S=n-l,y=o-u,x=h*(M*P+S*C+y*v);if(x<0||x>1)return!1;let A=S*m-y*d,I=y*f-M*m,R=M*d-S*f,E=h*(t*A+r*I+s*R);return E<0||x+E>1?!1:h*(p*A+g*I+b*R)>.001}function Gc(e,n,o,t,r,s,i){let c=i.bcx-e,a=i.bcy-n,l=i.bcz-o,u=c*t+a*r+l*s,f=c-u*t,d=a-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,g=p.length;for(let b=0;b<g;b+=9)if(_c(e,n,o,t,r,s,p,b))return!0;return!1}var mn=9,$c=6,se=12;function oo(e,n,o,t,r,s){let i=t-e,c=r-n,a=s-o;return i*c+c*a+a*i}function Fc(e){let n=[];for(let M=0;M<e.length;M++)e[M]&&n.push(M);let o=n.length,t=new Int32Array(o);for(let M=0;M<o;M++)t[M]=n[M];let r=new Float64Array(o),s=new Float64Array(o),i=new Float64Array(o);for(let M=0;M<o;M++){let S=e[t[M]];r[M]=(S.minX+S.maxX)*.5,s[M]=(S.minY+S.maxY)*.5,i[M]=(S.minZ+S.maxZ)*.5}let c=2*Math.max(1,o)+1,a=new Float64Array(c*mn),l=0,u=new Float64Array(se),f=new Float64Array(se),d=new Float64Array(se),m=new Float64Array(se),p=new Float64Array(se),g=new Float64Array(se),b=new Int32Array(se),P=new Float64Array(se-1),C=new Int32Array(se-1),v=new Float64Array(se-1),V=new Int32Array(se-1);function h(M,S){let y=l++,x=y*mn,A=S-M,I=1/0,R=1/0,E=1/0,O=-1/0,w=-1/0,D=-1/0;for(let X=M;X<S;X++){let K=e[t[X]];K.minX<I&&(I=K.minX),K.maxX>O&&(O=K.maxX),K.minY<R&&(R=K.minY),K.maxY>w&&(w=K.maxY),K.minZ<E&&(E=K.minZ),K.maxZ>D&&(D=K.maxZ)}if(a[x]=I,a[x+1]=R,a[x+2]=E,a[x+3]=O,a[x+4]=w,a[x+5]=D,A<=$c)return a[x+6]=1,a[x+7]=M,a[x+8]=S,y;let L=1/0,z=1/0,T=1/0,k=-1/0,N=-1/0,G=-1/0;for(let X=M;X<S;X++)r[X]<L&&(L=r[X]),r[X]>k&&(k=r[X]),s[X]<z&&(z=s[X]),s[X]>N&&(N=s[X]),i[X]<T&&(T=i[X]),i[X]>G&&(G=i[X]);let _=k-L,$=N-z,F=G-T;if(_===0&&$===0&&F===0)return a[x+6]=1,a[x+7]=M,a[x+8]=S,y;let H=oo(I,R,E,O,w,D),j=H>0?1/H:0,U=A+1,B=0,q=0;for(let X=0;X<3;X++){let K=X===0?L:X===1?z:T,le=X===0?_:X===1?$:F;if(le===0)continue;let Pe=X===0?r:X===1?s:i,Te=se/le;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),g.fill(-1/0),b.fill(0);for(let W=M;W<S;W++){let Y=(Pe[W]-K)*Te|0;Y>=se&&(Y=se-1);let ue=e[t[W]];ue.minX<u[Y]&&(u[Y]=ue.minX),ue.maxX>m[Y]&&(m[Y]=ue.maxX),ue.minY<f[Y]&&(f[Y]=ue.minY),ue.maxY>p[Y]&&(p[Y]=ue.maxY),ue.minZ<d[Y]&&(d[Y]=ue.minZ),ue.maxZ>g[Y]&&(g[Y]=ue.maxZ),b[Y]++}let We=1/0,Ye=1/0,Rt=1/0,kt=-1/0,Dt=-1/0,Lt=-1/0,Do=0;for(let W=0;W<se-1;W++)u[W]<We&&(We=u[W]),m[W]>kt&&(kt=m[W]),f[W]<Ye&&(Ye=f[W]),p[W]>Dt&&(Dt=p[W]),d[W]<Rt&&(Rt=d[W]),g[W]>Lt&&(Lt=g[W]),Do+=b[W],P[W]=oo(We,Ye,Rt,kt,Dt,Lt),C[W]=Do;let Nt=1/0,_t=1/0,Gt=1/0,$t=-1/0,Ft=-1/0,Ut=-1/0,Lo=0;for(let W=se-2;W>=0;W--){let Y=W+1;u[Y]<Nt&&(Nt=u[Y]),m[Y]>$t&&($t=m[Y]),f[Y]<_t&&(_t=f[Y]),p[Y]>Ft&&(Ft=p[Y]),d[Y]<Gt&&(Gt=d[Y]),g[Y]>Ut&&(Ut=g[Y]),Lo+=b[Y],v[W]=oo(Nt,_t,Gt,$t,Ft,Ut),V[W]=Lo}for(let W=0;W<se-1;W++){if(C[W]===0||V[W]===0)continue;let Y=.125+(P[W]*C[W]+v[W]*V[W])*j;Y<U&&(U=Y,B=X,q=K+(W+1)/Te)}}let Z=B===0?r:B===1?s:i,J=M,ne=S-1;for(;J<=ne;)if(Z[J]<q)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 le=s[J];s[J]=s[ne],s[ne]=le;let Pe=i[J];i[J]=i[ne],i[ne]=Pe,ne--}let ie=J;(ie===M||ie===S)&&(ie=M+S>>1),a[x+6]=0;let oe=h(M,ie),Q=h(ie,S);return a[y*mn+7]=oe,a[y*mn+8]=Q,y}return o>0&&h(0,o),{data:a,nodeCount:l,polyIndices:t,meta:e}}function Pr(e,n,o,t,r,s,i,c,a){if(c.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=c,d=t!==0?1/t:t>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,g=0;for(a[g++]=0;g>0;){let P=a[--g]*mn,C=(l[P]-e)*d,v=(l[P+3]-e)*d,V=C<v?C:v,h=C<v?v:C,M=(l[P+1]-n)*m,S=(l[P+4]-n)*m,y=M<S?M:S,x=M<S?S:M;if(V>x||y>h)continue;y>V&&(V=y),x<h&&(h=x);let A=(l[P+2]-o)*p,I=(l[P+5]-o)*p,R=A<I?A:I,E=A<I?I:A;if(!(V>E||R>h)&&(E<h&&(h=E),!(h<.001)))if(l[P+6]===1){let O=l[P+7]|0,w=l[P+8]|0;for(let D=O;D<w;D++){let L=u[D];if(L===i)continue;let z=f[L];if(z&&Gc(e,n,o,t,r,s,z))return!0}}else a[g++]=l[P+7]|0,a[g++]=l[P+8]|0}return!1}function Uc(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,s=Math.sqrt(Math.max(0,1-r*r)),i=2*Math.PI*(t/n);o[t*3]=s*Math.cos(i),o[t*3+1]=s*Math.sin(i),o[t*3+2]=r}return o}function Bc(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],s=n*e[1]-o*e[0],i=Math.hypot(t,r,s);t/=i,r/=i,s/=i;let c=e[1]*s-e[2]*r,a=e[2]*t-e[0]*s,l=e[0]*r-e[1]*t;return{ux:t,uy:r,uz:s,vx:c,vy:a,vz:l}}function ve(e,n){let o=n?.samples??8;if(e.length<4||o<1)return e;let t=e.map(Nc),r=Uc(o),s=[],i=Fc(t),c=new Int32Array(Math.max(64,i.nodeCount)),a=192,l=new Float64Array(a);for(let u=0;u<e.length;u++){let f=t[u];if(!f){s.push(e[u]);continue}let d=f.normal[0],m=f.normal[1],p=f.normal[2],g=.001*d,b=.001*m,P=.001*p;{let w=f.centroid[0]+g,D=f.centroid[1]+b,L=f.centroid[2]+P;if(!Pr(w,D,L,d,m,p,u,i,c)){s.push(e[u]);continue}}let{ux:C,uy:v,uz:V,vx:h,vy:M,vz:S}=Bc(f.normal),y=f.centroid[0],x=f.centroid[1],A=f.centroid[2],I=f.vertices,R=I.length,E=0;l[E++]=y+g,l[E++]=x+b,l[E++]=A+P;for(let w=0;w<R;w++){let D=I[w];l[E++]=D[0]+(y-D[0])*.08+g,l[E++]=D[1]+(x-D[1])*.08+b,l[E++]=D[2]+(A-D[2])*.08+P}for(let w=0;w<R;w++){let D=I[w],L=I[(w+1)%R],z=(D[0]+L[0])*.5,T=(D[1]+L[1])*.5,k=(D[2]+L[2])*.5;l[E++]=z+(y-z)*.08+g,l[E++]=T+(x-T)*.08+b,l[E++]=k+(A-k)*.08+P}let O=!1;e:for(let w=0;w<r.length;w+=3){let D=r[w],L=r[w+1],z=r[w+2],T=D*C+L*h+z*d,k=D*v+L*M+z*m,N=D*V+L*S+z*p;for(let G=0;G<E;G+=3){let _=l[G],$=l[G+1],F=l[G+2];if(!Pr(_,$,F,T,k,N,u,i,c)){O=!0;break e}}}O&&s.push(e[u])}return s}var jc=3,Hc=.03,qc=.02,dn={maxAngleDeg:jc,maxPlaneDisplacement:Hc,maxBoundaryDisplacement:qc,isolatedPairs:!1},Qe={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725,isolatedPairs:!0},ct=[{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.02},{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725},{maxAngleDeg:45,maxPlaneDisplacement:1,maxBoundaryDisplacement:.0725}],Xc=[2,4,6,8,12],Wc=300,Yc=.3,Kc=300,Zc=16,Qc=.015,Mr=2.6,Jc=3,ei=96,Re={minGroupPolygons:2,maxCandidateAxes:24},ni={maxGap:0,internalBoundaryLength:0,excessBoundaryLength:0};function ft(e,n={}){let o=n.meshResolution??"lossy",t=ro(e,!1),r={baseline:t},s=t,i=ce(t),c=(l,u=ce(l))=>u>=i?!1:(s=l,i=u,!0),a=st(t,n.rectCover);if(a!==t&&c(a),o==="lossy"&&n.approximateMerge!==!1){let l=di(e),u=[],f=he(l,s,Qe.maxBoundaryDisplacement).metrics,d=n.approximateMerge===void 0||n.approximateMerge===!0,m=(C,v=!0)=>!fi(l,C.metrics,C.tolerance,v?f:null),p=(C,v)=>{c(C,v)},g=(C,v,V=Qe.maxBoundaryDisplacement)=>{!d||v>i+Sr(i)||u.push({polygons:C,cost:v,maxBoundaryDisplacement:V})},b=Vr(n.approximateMerge,d?t:void 0);for(let C=0;C<b.length;C++){let v=b[C],V=ro(e,v,r),h=ce(V),M=null,S=()=>(M??(M=he(l,V,v.maxBoundaryDisplacement)),M),y=!0;if(d||v.guard){let E=S();y=m(E,!!v.allowReferenceCracks)}if(!y&&h<i)continue;y&&(p(V,h),g(V,h,v.maxBoundaryDisplacement));let x=st(V,n.rectCover),A=ce(x),I=null,R=()=>(I??(I=he(l,x,v.maxBoundaryDisplacement)),I);if(x!==V&&A<i){let E=!0;(d||v.guard)&&(E=m(R(),!!v.allowReferenceCracks)),E&&(p(x,A),g(x,A,v.maxBoundaryDisplacement))}}if(d)for(let C of ti(e)){let v={baseline:ae(ve(C))},V=ce(v.baseline),h=!0,M=null,S=()=>(M??(M=he(l,v.baseline,Qe.maxBoundaryDisplacement)),M);V<i&&(h=m(S())),h&&(p(v.baseline,V),g(v.baseline,V));let y=st(v.baseline,n.rectCover);if(y!==v.baseline){let x=ce(y);(x>=i||m(he(l,y,Qe.maxBoundaryDisplacement)))&&(p(y,x),g(y,x))}for(let x of Vr(n.approximateMerge,v.baseline)){let A=ro(C,x,v),I=ce(A),R=null,E=()=>(R??(R=he(l,A,x.maxBoundaryDisplacement)),R),O=!0;if(d||x.guard){let T=E();O=m(T,!!x.allowReferenceCracks)}if(!O&&I<i)continue;O&&(p(A,I),g(A,I,x.maxBoundaryDisplacement));let w=st(A,n.rectCover),D=ce(w),L=null,z=()=>(L??(L=he(l,w,x.maxBoundaryDisplacement)),L);if(w!==A&&D<i){let T=!0;(d||x.guard)&&(T=m(z(),!!x.allowReferenceCracks)),T&&(p(w,D),g(w,D,x.maxBoundaryDisplacement))}}}if(d)for(let C of ct){let v=Er({...C,isolatedPairs:!0}),V=Si(s,v);if(V===s)continue;let h=ce(V);if(h>=i)continue;let M=he(l,V,v.maxBoundaryDisplacement);m(M)&&(p(V,h),g(V,h,v.maxBoundaryDisplacement))}let P=ai(u,s,i,C=>(C.metrics??(C.metrics=he(l,C.polygons,C.maxBoundaryDisplacement).metrics),C.metrics),()=>he(l,s,Qe.maxBoundaryDisplacement).metrics);P&&(s=P.polygons,i=P.cost)}return s}function ti(e){let n=oi(e);if(n.eligiblePolygons<24||n.colorCount<8)return[];let o=[],t=new Set;for(let r of Xc){let s=ri(e,r,n.colorCount);if(!s)continue;let i=ci(s);t.has(i)||(t.add(i),o.push(s))}return o}function oi(e){let n=new Set,o=0;for(let t of e)t.texture||t.material?.texture||t.uvs||t.textureTriangles?.length||Ar(t.color)&&(o+=1,n.add(t.color??"#cccccc"));return{eligiblePolygons:o,colorCount:n.size}}function ri(e,n,o){let t=!1,r=new Set,s=e.map(i=>{if(i.texture||i.material?.texture||i.uvs||i.textureTriangles?.length)return i;let c=Ar(i.color);if(!c)return i;let a=si([Math.round(c[0]/n)*n,Math.round(c[1]/n)*n,Math.round(c[2]/n)*n]);return r.add(a),a===i.color?i:(t=!0,{...i,color:a})});return!t||r.size>=o?null:s}function Ar(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 si(e){return`#${e.map(n=>Math.max(0,Math.min(255,Math.round(n))).toString(16).padStart(2,"0")).join("")}`}function ci(e){return e.map(n=>n.color??"").join("|")}function Vr(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&&ii(n))return[{...ct[0],isolatedPairs:!0,guard:!1,allowReferenceCracks:!0}];let o=[],t=new Set,r=n&&n.length>Kc?[!0]:[!0,!1];for(let s=0;s<ct.length;s++){let i=ct[s];for(let c of r){let a={...i,isolatedPairs:c,guard:s>0||c===!1,allowReferenceCracks:!0},l=[a.maxAngleDeg,a.maxPlaneDisplacement,a.maxBoundaryDisplacement,a.isolatedPairs].join("|");t.has(l)||(t.add(l),o.push(a))}}return o.length===0?[{...Qe,guard:!1}]:o}function ii(e){return e.length<Wc?!1:wr(e)/e.length<=Yc}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,s=o.texture||o.material?.texture||o.textureTriangles?.length?.15:0;n+=1+r+s}return n}function Sr(e){return Math.max(Zc,e*Qc)}function ai(e,n,o,t,r){if(e.length===0)return null;let s=Sr(o),i=e.find(u=>u.polygons===n),c=null,a=null,l=null;for(let u of e){if(u.polygons===n||u.cost>o+s)continue;let f=t(u);c??(c=i?t(i):r()),ui(f,c)&&(!a||!l||li(u,f,a,l)<0)&&(a=u,l=f)}return a}function li(e,n,o,t){return n.maxGap-t.maxGap||n.internalBoundaryLength-t.internalBoundaryLength||n.excessBoundaryLength-t.excessBoundaryLength||e.cost-o.cost}function ui(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 fi(e,n,o,t=null){if(!t)return n.internalBoundaryLength>0||n.excessBoundaryLength>o;let r=Math.max(o*.1,1e-6),s=t.maxGap+r,i=o<=.08?Math.max(s,Math.min(o*.75,.04)):s,c=Math.max(o*2,t.internalBoundaryLength*.15),a=Math.max(o*2,t.excessBoundaryLength*.15);return n.maxGap>i||n.internalBoundaryLength>t.internalBoundaryLength+c||n.excessBoundaryLength>t.excessBoundaryLength+a}function mi(e,n,o=0,t=co(e,o)){let r=e.edges,s=Or(n),i=co(e,o),c=t>0?gi(e,t):null,a={...ni,excessBoundaryLength:Math.max(0,s.boundaryLength-r.boundaryLength)};for(let l of s.boundarySegments){let u=Je(l.a,l.b);if(r.boundaryKeys.has(u))continue;if(r.internalKeys.has(u)){a.internalBoundaryLength+=xe(l.a,l.b);continue}let f=c?bi(l,c,t):null;f!==null&&(a.maxGap=Math.max(a.maxGap,f),a.internalBoundaryLength+=xe(l.a,l.b))}return{metrics:a,tolerance:i}}function he(e,n,o=0){return mi(e,n,o,pi(e,o))}function di(e){let n=yi(e),o=n>0?Math.min(.08,Math.max(.001,n*.001)):0;return{edges:Or(e),baseTolerance:o,polygonCount:e.length,indexes:new Map}}function co(e,n=0){return Math.max(e.baseTolerance,n*1.05)}function pi(e,n=0){return Math.max(co(e,n),e.baseTolerance*Mr,n*Mr)}function gi(e,n){let o=n.toFixed(6),t=e.indexes.get(o);if(t)return t;let r=hi(e.edges.internalSegments,n);return e.indexes.set(o,r),r}function Or(e){let n=new Map;for(let c of e)for(let a=0;a<c.vertices.length;a++){let l=c.vertices[a],u=c.vertices[(a+1)%c.vertices.length],f=Je(l,u),d=n.get(f);d?d.count+=1:n.set(f,{count:1,a:l,b:u})}let o=new Set,t=new Set,r=[],s=[],i=0;for(let[c,a]of n){let l={a:a.a,b:a.b};a.count===1?(o.add(c),r.push(l),i+=xe(l.a,l.b)):(t.add(c),s.push(l))}return{boundaryKeys:o,internalKeys:t,boundarySegments:r,internalSegments:s,boundaryLength:i}}function yi(e){let n=1/0,o=1/0,t=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let[a,l,u]of c.vertices)n=Math.min(n,a),o=Math.min(o,l),t=Math.min(t,u),r=Math.max(r,a),s=Math.max(s,l),i=Math.max(i,u);return Number.isFinite(n)?Math.hypot(r-n,s-o,i-t):0}function hi(e,n){let o=Math.max(n*2,1e-6),t=new Map;for(let r of e){let[s,i,c]=Tr(r,o),a=Ir(s,i,c),l=t.get(a);l?l.push(r):t.set(a,[r])}return{cellSize:o,cells:t}}function bi(e,n,o){let[t,r,s]=Tr(e,n.cellSize),i=null;for(let c=-1;c<=1;c++)for(let a=-1;a<=1;a++)for(let l=-1;l<=1;l++){let u=n.cells.get(Ir(t+c,r+a,s+l));if(u)for(let f of u){let d=xi(e,f);d<=o&&(i=i===null?d:Math.min(i,d))}}return i}function Tr(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 Ir(e,n,o){return`${e},${n},${o}`}function xi(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 st(e,n){if(n===!1)return e;let o=Pi(e,n);if(!o)return e;let t=rt(e,o);return t.length<e.length?t:e}function Pi(e,n){if(n&&n!==!0)return n;let o=e.length;return o>2200?null:o>1200?{...Re,maxCandidateAxes:Math.min(Re.maxCandidateAxes??24,2)}:o>300&&wr(e)<=ei?{...Re,maxCandidateAxes:Math.min(Re.maxCandidateAxes??24,2)}:o>900?{...Re,maxCandidateAxes:Math.min(Re.maxCandidateAxes??24,4)}:Re}function wr(e){let n=0;for(let o of e)o.vertices.length===3&&(n+=1);return n}function ro(e,n,o){let t=nt(e),r=o?.baseline??ae(ve(t));if(!n)return r;let s=n===!0?dn:Er(n);if(s.isolatedPairs){let c=Vi(Mi(t,o),s),a=ae(c);return a.length<r.length?a:r}let i=ae(ve(Li(t,s,o)));return i.length<r.length?i:r}function zr(e,n){return n?(n.snapped||(n.snapped=at(e)),n.snapped):at(e)}function Mi(e,n){return n?(n.snappedInterior||(n.snappedInterior=ve(zr(e,n))),n.snappedInterior):ve(at(e))}function Er(e){return{maxAngleDeg:e.maxAngleDeg??dn.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??dn.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??dn.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??dn.isolatedPairs}}function Vi(e,n){let o=e.map(f=>{let d=gn(f);return d?{polygon:f,normal:d.normal,area:d.area,materialKey:lo(f)}:null}),t=new Map;for(let f=0;f<e.length;f++){let d=e[f];if(!(d.vertices.length!==3||!o[f]))for(let m=0;m<d.vertices.length;m++){let p=Je(d.vertices[m],d.vertices[(m+1)%d.vertices.length]),g=t.get(p);g?g.push(f):t.set(p,[f])}}let r=[];for(let f of t.values()){if(f.length!==2)continue;let[d,m]=f,p=Di(d,m,e,o,n);p&&r.push(p)}let s=new Set,i=new Map,c=new Set,a=Ci(r),l=mt(a.flatMap(f=>f.vertexMoves));for(let f of a){s.add(f.a),s.add(f.b);let d=Math.min(f.a,f.b);i.set(d,f.polygon),c.add(Math.max(f.a,f.b))}let u=[];for(let f=0;f<e.length;f++){let d=i.get(f);if(d){u.push(d);continue}c.has(f)||u.push(e[f])}return l.size>0?dt(u,l):u}function Ci(e){return e.length>3e3?vi(e):Ai(e)}function vi(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 o=[...e].sort((s,i)=>{let c=(n.get(s.a)??0)+(n.get(s.b)??0),a=(n.get(i.a)??0)+(n.get(i.b)??0);return c-a||s.score-i.score}),t=new Set,r=[];for(let s of o)t.has(s.a)||t.has(s.b)||(t.add(s.a),t.add(s.b),r.push(s));return r}function Ai(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],f=n.get(u.a);f?f.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let o=[],t=new Array(e.length).fill(!0),r=new Map,s=new io;for(let[l,u]of n)r.set(l,u.length);let i=l=>(r.get(l.a)??0)+(r.get(l.b)??0),c=l=>{let u=e[l];s.push({degree:i(u),score:u.score,index:l})},a=(l,u)=>{if(!t[l])return;t[l]=!1;let f=e[l];for(let d of[f.a,f.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)c(l);for(;s.size()>0;){let l=s.pop();if(!t[l.index])continue;let u=e[l.index];if(i(u)!==l.degree){c(l.index);continue}o.push(u);let d=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])a(p,d);for(let m of d)for(let p of n.get(m)??[])t[p]&&c(p)}return o}var io=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(so(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,s=r+1,i=t;if(r<this.items.length&&so(this.items[r],this.items[i])<0&&(i=r),s<this.items.length&&so(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 so(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function Si(e,n){let o=e,t=ce(o),r=wi(o);for(let s=0;s<Jc;s++){let i=Oi(o,n,r);if(!i)break;let c=ce(i.polygons);if(c>=t)break;o=i.polygons,t=c,r=i.origins}return o===e?e:o}function Oi(e,n,o){let t=e.map(d=>{let m=gn(d);return m?{polygon:d,normal:m.normal,area:m.area,materialKey:lo(d)}:null}),r=new Map;for(let d=0;d<e.length;d++){let m=e[d];if(!(!t[d]||m.vertices.length<3))for(let p=0;p<m.vertices.length;p++){let g=Je(m.vertices[p],m.vertices[(p+1)%m.vertices.length]),b=r.get(g);b?b.push({polygon:d,edge:p}):r.set(g,[{polygon:d,edge:p}])}}let s=[];for(let d of r.values()){if(d.length!==2)continue;let[m,p]=d,g=Ti(m.polygon,m.edge,p.polygon,p.edge,e,t,n);g&&s.push(g)}if(s.length===0)return null;s.sort((d,m)=>m.score-d.score);let i=new Set,c=[];for(let d of s)i.has(d.a)||i.has(d.b)||(i.add(d.a),i.add(d.b),c.push(d));if(c.length===0)return null;let a=mt(c.flatMap(d=>d.vertexMoves));if(!Ii(a,o,n.maxBoundaryDisplacement))return null;let l=dt(e,a),u=zi(e,a,o),f=ae(l);return ce(f)<ce(e)?{polygons:f,origins:Ei(f,u)}:null}function Ti(e,n,o,t,r,s,i){let c=r[e],a=r[o],l=s[e],u=s[o];if(!l||!u||c.vertices.length===3&&a.vertices.length===3||!Gr(c,a,l,u))return null;let f=Math.abs(ge(l.normal,u.normal)),d=Math.cos(i.maxAngleDeg*Math.PI/180);if(f<d)return null;let m=Cr(c,a,n)??Cr(a,c,t);if(!m||m.length<4||m.length>10)return null;let p=kr(m);if(!p)return null;let g=0,b=0;for(let y of m){let x=Math.abs(pt(y,p));g=Math.max(g,x),b+=x*x}if(g>Math.min(i.maxPlaneDisplacement,i.maxBoundaryDisplacement))return null;let P=m.map(y=>gt(y,p));if(!Dr(P,p.normal))return null;let C=gn({vertices:P});if(!C||ge(C.normal,l.normal)<.2||ge(C.normal,u.normal)<.2)return null;let v=[...m.map((y,x)=>({key:re(y),target:P[x]})),...Rr([c,a],p)],V=dt([c,a],mt(v)),h=ce([c,a]),M=ce(ae(V));if(M>=h)return null;let S=h-M-(b/m.length+g*.25+(1-f)*.1);return S<=0?null:{a:e,b:o,vertexMoves:v,score:S}}function Cr(e,n,o){let t=e.vertices,r=n.vertices,s=t[o],i=t[(o+1)%t.length],c=-1;for(let u=0;u<r.length;u++)if(Ae(r[u],i)&&Ae(r[(u+1)%r.length],s)){c=u;break}if(c<0)return null;let a=[],l=(o+1)%t.length;for(a.push(t[l]);l!==o;)l=(l+1)%t.length,a.push(t[l]);for(l=(c+2)%r.length;l!==c;){let u=r[l];Ae(u,a[a.length-1])||a.push(u),l=(l+1)%r.length}return a.length>1&&Ae(a[0],a[a.length-1])&&a.pop(),a}function Ii(e,n,o){for(let[t,r]of e){let s=Ri(t),i=n.get(t)??(s?[s]:[]);if(i.length===0)return!1;for(let c of i)if(xe(c,r)>o+1e-6)return!1}return!0}function wi(e){let n=new Map;for(let o of e){for(let t of o.vertices)it(n,re(t),t);for(let t of o.textureTriangles??[])for(let r of t.vertices)it(n,re(r),r)}return n}function zi(e,n,o){let t=new Map;for(let r of e){let s=[...r.vertices,...(r.textureTriangles??[]).flatMap(i=>i.vertices)];for(let i of s){let c=re(i),a=n.get(c)??i,l=re(a);for(let u of o.get(c)??[i])it(t,l,u)}}return t}function Ei(e,n){let o=new Map;for(let t of e){let r=[...t.vertices,...(t.textureTriangles??[]).flatMap(s=>s.vertices)];for(let s of r){let i=re(s);for(let c of n.get(i)??[s])it(o,i,c)}}return o}function it(e,n,o){let t=e.get(n);if(!t){e.set(n,[o]);return}let r=re(o);t.some(s=>re(s)===r)||t.push(o)}function Ri(e){let n=e.split(",").map(Number);return n.length===3&&n.every(Number.isFinite)?[n[0],n[1],n[2]]:null}function mt(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 ki(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t].vertices,s=n[t]?.vertices;if(!s||s.length!==r.length)continue;for(let a=0;a<r.length;a++)o.push({key:re(r[a]),target:s[a]});let i=e[t].textureTriangles??[],c=n[t]?.textureTriangles??[];for(let a=0;a<i.length;a++){let l=c[a];if(l)for(let u=0;u<i[a].vertices.length;u++)o.push({key:re(i[a].vertices[u]),target:l.vertices[u]})}}return o}function Rr(e,n){let o=[];for(let t of e)for(let r of t.textureTriangles??[])for(let s of r.vertices)o.push({key:re(s),target:gt(s,n)});return o}function dt(e,n){return e.map(o=>{let t=!1,r=c=>{let a=n.get(re(c));return a?(t=!0,a):c},s=o.vertices.map(r),i=ao(o.textureTriangles,r);return t?{...o,vertices:s,...i?{textureTriangles:i}:{}}:o})}function Di(e,n,o,t,r){let s=o[e],i=o[n],c=t[e],a=t[n];if(!c||!a||s.vertices.length!==3||i.vertices.length!==3||!Gr(s,i,c,a))return null;let l=fo(s,i);if(!l)return null;let[u,f,d,m]=l;if((d+1)%i.vertices.length===m)return null;let g=Math.abs(ge(c.normal,a.normal)),b=Math.cos(r.maxAngleDeg*Math.PI/180);if(g<b)return null;let P=(f+1)%s.vertices.length,C=3-d-m,v=[s.vertices[f],s.vertices[P],s.vertices[u],i.vertices[C]],V=kr(v);if(!V)return null;let h=0,M=0;for(let A of v){let I=Math.abs(pt(A,V));h=Math.max(h,I),M+=I*I}if(h>Math.min(r.maxPlaneDisplacement,r.maxBoundaryDisplacement))return null;let S=v.map(A=>gt(A,V));if(!Dr(S,V.normal))return null;let y=gn({vertices:S});if(!y||ge(y.normal,c.normal)<.2||ge(y.normal,a.normal)<.2)return null;let x={vertices:v,color:s.color,...s.data?{data:{...s.data}}:{}};if(uo(s,i)&&s.uvs&&i.uvs&&s.texture){x.texture=s.texture,x.uvs=[[...s.uvs[f]],[...s.uvs[P]],[...s.uvs[u]],[...i.uvs[C]]];let A=Ni([s,i]);A?.length&&(x.textureTriangles=A)}return{a:e,b:n,polygon:x,vertexMoves:[...v.map((A,I)=>({key:re(A),target:S[I]})),...Rr([s,i],V)],score:M/v.length+h*.25+(1-g)*.1}}function kr(e){if(e.length<3)return null;let n=0,o=0,t=0,r=0,s=0,i=0;for(let a=0;a<e.length;a++){let l=e[a],u=e[(a+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),o+=(l[2]-u[2])*(l[0]+u[0]),t+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],s+=l[1],i+=l[2]}let c=jr([n,o,t]);return c?{normal:c,point:[r/e.length,s/e.length,i/e.length]}:null}function Dr(e,n){let o=0;for(let t=0;t<e.length;t++){let r=e[t],s=e[(t+1)%e.length],i=e[(t+2)%e.length],c=ge(Br(pn(s,r),pn(i,s)),n);if(Math.abs(c)<=1e-9)continue;let a=c>0?1:-1;if(o===0)o=a;else if(o!==a)return!1}return!0}function Li(e,n,o){let t=zr(e,o),r=Bi(t,n);if(r<=0)return t;let s=t.map(m=>{let p=gn(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:lo(m)}:null}),i=qi(t,s),c=new Set,a=Array(t.length),l=[],u=(m,p)=>{a[m]=p};for(let m=0;m<t.length;m++){let p=s[m];if(c.has(m))continue;if(!p){u(m,t[m]);continue}let g=Wi(m,s,i,c,r,n);for(let P of g)c.add(P);if(g.length<2){u(m,t[m]);continue}let b=$i(g,t,s,i,r,n);l.push(...b.vertexMoves);for(let P of g)u(P,b.polygons.get(P)??t[P])}let f=a.flatMap(m=>m?[m]:[]),d=l.length>0?dt(f,mt(l)):f;return at(d)}function at(e){let n=_r(e),o=1e-4;if(n<=0)return e;let t=ji(n),r=Hi(o);return e.map(s=>{let i=f=>t.snap(f),c=s.vertices.map(i),a=s.uvs&&s.uvs.length===s.vertices.length?s.uvs.map(f=>r.snap(f)):void 0,l=ao(s.textureTriangles,i),u={...s,vertices:c,...a?{uvs:a}:{},...l?{textureTriangles:l}:{}};return{...u,...u.texture?{textureTriangles:Lr(u)}:{}}})}function Lr(e){if(e.texture){if(e.textureTriangles?.length)return Gi(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return _i(e.vertices,e.uvs)}}function Ni(e){let n=e.flatMap(o=>Lr(o)??[]);return n.length>0?n:void 0}function _i(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 Gi(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function ao(e,n){if(e?.length)return e.map(o=>({vertices:o.vertices.map(n),uvs:o.uvs.map(t=>[...t])}))}function $i(e,n,o,t,r,s){let i=Nr(e,n,o,r,s);return i?Ui(i):Fi(e,n,o,t,r,s)}function Fi(e,n,o,t,r,s){let i=new Set(e),c=[];for(let f of e)for(let d of t.get(f)??[]){if(f>=d||!i.has(d))continue;let m=Nr([f,d],n,o,r,s);m&&c.push(m)}c.sort((f,d)=>d.score-f.score);let a=new Set,l=new Map,u=[];for(let f of c)if(!f.indices.some(d=>a.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];a.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function Ui(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 Nr(e,n,o,t,r){let s=$r(e,o);if(!s||!Fr(e,o,s,t,r))return null;let i=e.map(u=>n[u]),c=i.map(u=>Zi(u,s)),a=ce(ae(i)),l=ce(ae(c));return l>=a?null:{indices:e,source:i,projected:c,vertexMoves:ki(i,c),score:a-l}}function Bi(e,n){return _r(e)<=0?0:n.maxPlaneDisplacement}function _r(e){let n=1/0,o=1/0,t=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let[l,u,f]of a.vertices)n=Math.min(n,l),o=Math.min(o,u),t=Math.min(t,f),r=Math.max(r,l),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let c=Math.hypot(r-n,s-o,i-t);return c<=0?0:Math.min(.025,Math.max(1e-4,c*25e-5))}function ji(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,s,i)=>`${r},${s},${i}`;return{snap(r){let s=o(r[0]),i=o(r[1]),c=o(r[2]);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)for(let m=-1;m<=1;m++){let p=n.get(t(s+f,i+d,c+m));if(p){for(let g of p)if(xe(r,g)<=e)return[g[0],g[1],g[2]]}}let a=[r[0],r[1],r[2]],l=t(s,i,c),u=n.get(l);return u?u.push(a):n.set(l,[a]),a}}}function Hi(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,s)=>`${r},${s}`;return{snap(r){let s=o(r[0]),i=o(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(t(s+u,i+f));if(d){for(let m of d)if(Math.hypot(r[0]-m[0],r[1]-m[1])<=e)return[m[0],m[1]]}}let c=[r[0],r[1]],a=t(s,i),l=n.get(a);return l?l.push(c):n.set(a,[c]),c}}}function lo(e){return`${e.color??"#cccccc"}|${e.texture??""}|${e.uvs?"uv":"plain"}`}function gn(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0,s=n[0];for(let c=1;c<n.length-1;c++){let a=pn(n[c],s),l=pn(n[c+1],s),u=Br(a,l);o+=u[0],t+=u[1],r+=u[2]}let i=Math.hypot(o,t,r);return i<=1e-10?null:{normal:[o/i,t/i,r/i],area:i/2}}function qi(e,n){let o=new Map,t=new Map;for(let r=0;r<e.length;r++){let s=e[r];if(!(!n[r]||s.vertices.length<3))for(let i=0;i<s.vertices.length;i++){let c=Je(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),a=o.get(c);a?a.push(r):o.set(c,[r])}}for(let r of o.values())for(let s=0;s<r.length;s++)for(let i=s+1;i<r.length;i++){let c=r[s],a=r[i];Xi(e[c],e[a],n[c],n[a])&&(vr(t,c,a),vr(t,a,c))}return t}function Xi(e,n,o,t){if(!o||!t||o.materialKey!==t.materialKey||!!e.uvs!=!!n.uvs)return!1;if(lt(e)||lt(n))return uo(e,n);if(!e.uvs||!n.uvs)return!0;let r=fo(e,n);if(!r)return!1;let[s,i,c,a]=r;return ut(e.uvs[s],n.uvs[c])&&ut(e.uvs[i],n.uvs[a])}function Gr(e,n,o,t){return o.materialKey!==t.materialKey?!1:lt(e)||lt(n)?uo(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function lt(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function uo(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=fo(e,n);if(!o)return!1;let[t,r,s,i]=o;return ut(e.uvs[t],n.uvs[s])&&ut(e.uvs[r],n.uvs[i])}function vr(e,n,o){let t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}function Wi(e,n,o,t,r,s){let i=[e],c=new Set([e]),a=[e];for(;a.length>0;){let l=a.shift();for(let u of o.get(l)??[]){if(t.has(u)||c.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&Yi([...i,u],n,r,s)&&(i.push(u),c.add(u),a.push(u))}}return i}function Yi(e,n,o,t){let r=$r(e,n);return!!r&&Fr(e,n,r,o,t)}function $r(e,n){let o=n[e[0]];if(!o)return null;let t=0,r=0,s=0,i=0,c=0,a=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let g=ge(o.normal,p.normal)<0?-1:1,b=Math.max(p.area,1e-6);t+=p.normal[0]*g*b,r+=p.normal[1]*g*b,s+=p.normal[2]*g*b;for(let P of p.polygon.vertices)i+=P[0],c+=P[1],a+=P[2],l+=1}let u=jr([t,r,s]);if(!u||l===0)return null;let f=Ur(e,n),d=Ki(e,n,u,f);if(d){let m=(d.min+d.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m]}}return{normal:u,point:[i/l,c/l,a/l]}}function Ki(e,n,o,t){let r=1/0,s=-1/0;for(let i of e){let c=n[i];if(c)for(let a of c.polygon.vertices){if(!t.has(re(a)))continue;let l=ge(a,o);r=Math.min(r,l),s=Math.max(s,l)}}return Number.isFinite(r)&&Number.isFinite(s)?{min:r,max:s}:null}function Fr(e,n,o,t,r){let s=Math.cos(r.maxAngleDeg*Math.PI/180),i=Ur(e,n);for(let c of e){let a=n[c];if(!a||Math.abs(ge(a.normal,o.normal))<s)return!1;for(let l of a.polygon.vertices){let u=i.has(re(l))?r.maxBoundaryDisplacement:t;if(Math.abs(pt(l,o))>u)return!1}}return!0}function Ur(e,n){let o=new Map;for(let r of e){let s=n[r];if(!s)continue;let i=s.polygon.vertices;for(let c=0;c<i.length;c++){let a=i[c],l=i[(c+1)%i.length],u=Je(a,l),f=o.get(u);f?f.count+=1:o.set(u,{count:1,a,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 Zi(e,n){let o=r=>gt(r,n),t=ao(e.textureTriangles,o);return{...e,vertices:e.vertices.map(o),...t?{textureTriangles:t}:{}}}function fo(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 s=(r+1)%n.vertices.length;if(Ae(e.vertices[o],n.vertices[r])&&Ae(e.vertices[t],n.vertices[s]))return[o,t,r,s];if(Ae(e.vertices[o],n.vertices[s])&&Ae(e.vertices[t],n.vertices[r]))return[o,t,s,r]}}return null}function Je(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 Ae(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function ut(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function pn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Br(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 jr(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 pt(e,n){return ge(pn(e,n.point),n.normal)}function gt(e,n){let o=pt(e,n);return[e[0]-n.normal[0]*o,e[1]-n.normal[1]*o,e[2]-n.normal[2]*o]}var yn=1e-5,mo=.001,po=6;function yt(e){let n=e.vertices;if(n.length<3)return null;let o=n[0],t=0,r=0,s=0;for(let c=1;c+1<n.length;c++){let a=n[c],l=n[c+1],u=a[1]-o[1],f=a[0]-o[0],d=a[2]-o[2],m=l[1]-o[1],p=l[0]-o[0],g=l[2]-o[2];t-=f*g-d*p,r-=d*m-u*g,s-=u*p-f*m}let i=Math.hypot(t,r,s);return i<1e-9?null:[t/i,r/i,s/i]}function go(e,n){let o=n.meshRotation,t=o?rn(e,o[0]??0,o[1]??0,o[2]??0):e;return rn(t,n.rotX,0,n.rotY)[2]}function ht(e,n,o=yn){return go(e,n)>o}function Hr(e,n,o=yn){let t=yt(e);return t===null||ht(t,n,o)}function yo(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function ho(e){let n=new Map;for(let o of e){if(!o)continue;let t=yo(o);n.has(t)||n.set(t,o)}return Array.from(n,([o,t])=>({key:o,normal:t}))}function qr(e){return ho(e.map(yt))}function bo(e,n=mo){let o=Math.abs(e[0]),t=Math.abs(e[1]),r=Math.abs(e[2]),s=Math.max(o,t,r);return s>1-n&&o+t+r-s<n}function Xr(e){return e.length<=po&&e.every(({normal:n})=>bo(n))}function Wr(e,n,o=yn){let t=[];for(let{key:r,normal:s}of e)ht(s,n,o)&&t.push(r);return t.sort(),t.join("|")}function xo(e,n,o,t,r){let s=(p,g,b)=>{let P=[0,0,0];return P[e]=p,P[(e+1)%3]=g,P[(e+2)%3]=b,P},i=s(n,-t,-t),c=s(n,t,-t),a=s(n,t,t),l=s(n,-t,t),u=s(o,-t,-t),f=s(o,t,-t),d=s(o,t,t),m=s(o,-t,t);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function Po(e={}){let n=e.size??5,o=e.thickness??.025,t=e.negative??!1,r=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",c=n*o/2,a=t?-n:0;return[...xo(0,a,n,c,r),...xo(1,a,n,c,s),...xo(2,a,n,c,i)]}function Yr(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 Qi(e,n,o,t,r){let s=(p,g,b)=>Yr(e,p,g,b),i=s(n,-t,-t),c=s(n,t,-t),a=s(n,t,t),l=s(n,-t,t),u=s(o,-t,-t),f=s(o,t,-t),d=s(o,t,t),m=s(o,-t,t);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function Ji(e,n,o,t,r){let s=(f,d,m)=>Yr(e,f,d,m),i=s(n,-t,-t),c=s(n,t,-t),a=s(n,t,t),l=s(n,-t,t),u=s(o,0,0);return[{vertices:[i,c,a,l],color:r},{vertices:[i,c,u],color:r},{vertices:[c,a,u],color:r},{vertices:[a,l,u],color:r},{vertices:[l,i,u],color:r}]}function ea(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function Mo(e){let n=e.axis,o=e.sign??1,t=e.shaftLength??4,r=e.shaftHalfThickness??.05,s=e.headLength??.8,i=e.headHalfThickness??.2,c=e.color??"#ffffff",a=e.shaft??!0,l=t*o,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(t+s)*o,p=Ji(n,d,m,i,c),g=o===-1?ea(p):p;return a?[...Qi(n,u,f,r,c),...g]:g}function bt(e,n,o){let t=[0,0,0],r=(e+1)%3,s=(e+2)%3;return t[r]=Math.cos(o)*n,t[s]=Math.sin(o)*n,t}function Vo(e){let n=e.axis,o=e.radius,t=e.halfThickness??Math.max(.05,o*.04),r=e.segments??32,s=e.color??"#ffffff",i=o-t,c=o+t,a=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=bt(n,i,u),m=bt(n,i,f),p=bt(n,c,u),g=bt(n,c,f);a.push({vertices:[d,p,g,m],color:s})}return a}function Co(e){let n=e.axis,o=e.outerRadius,t=e.color??"#ffffff",r=(n+1)%3,s=(n+2)%3,i=(c,a)=>{let l=[0,0,0];return l[n]=0,l[r]=c,l[s]=a,l};return[{vertices:[i(-o,-o),i(o,-o),i(o,o),i(-o,o)],color:t}]}function vo(e){let n=e.axis,o=e.size??.4,t=e.offset??o*2,r=typeof t=="number"?t:t[0],s=typeof t=="number"?t:t[1],i=e.along??0,c=e.color??"#ffffff",a=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=i,m[a]=r+f,m[l]=s+d,m};return[{vertices:[u(-o,-o),u(o,-o),u(o,o),u(-o,o)],color:c}]}function hn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=[[r+o,s,i],[r-o,s,i],[r,s+o,i],[r,s-o,i],[r,s,i+o],[r,s,i-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:[c[l[0]],c[l[1]],c[l[2]]],color:t}))}function bn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=o/Math.sqrt(3),a=[[r+c,s+c,i+c],[r-c,s-c,i+c],[r-c,s+c,i-c],[r+c,s-c,i-c]];return[[0,2,1],[0,1,3],[0,3,2],[1,2,3]].map(u=>({vertices:[a[u[0]],a[u[1]],a[u[2]]],color:t}))}function xn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=o/2,a=[[r-c,s-c,i-c],[r+c,s-c,i-c],[r+c,s+c,i-c],[r-c,s+c,i-c],[r-c,s-c,i+c],[r+c,s-c,i+c],[r+c,s+c,i+c],[r-c,s+c,i+c]];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:[a[u[0]],a[u[1]],a[u[2]],a[u[3]]],color:t}))}function Pn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=1/c,l=o/Math.sqrt(3),f=[[-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,-c,-a],[0,-c,a],[0,c,-a],[0,c,a],[-a,0,-c],[a,0,-c],[-a,0,c],[a,0,c],[-c,-a,0],[-c,a,0],[c,-a,0],[c,a,0]].map(([m,p,g])=>[r+m*l,s+p*l,i+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(m=>({vertices:m.map(p=>f[p]),color:t}))}function Mn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),u=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]].map(([d,m,p])=>[r+d*a,s+m*a,i+p*a]);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 Kr(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 Vn(e){let{center:n,size:o,subdivisions:t=1,color:r="#ffffff"}=e,[s,i,c]=n,a=(1+Math.sqrt(5))/2,l=o/Math.sqrt(1+a*a),f=[[0,-1,-a],[0,-1,a],[0,1,-a],[0,1,a],[-1,-a,0],[-1,a,0],[1,-a,0],[1,a,0],[-a,0,-1],[a,0,-1],[-a,0,1],[a,0,1]].map(([m,p,g])=>Kr([m*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 m=0;m<t;m++){let p=new Map,g=[],b=(P,C)=>{let v=P<C?`${P}_${C}`:`${C}_${P}`,V=p.get(v);if(V!==void 0)return V;let h=f[P],M=f[C],S=[(h[0]+M[0])/2,(h[1]+M[1])/2,(h[2]+M[2])/2],y=f.length;return f.push(Kr(S,o)),p.set(v,y),y};for(let[P,C,v]of d){let V=b(P,C),h=b(C,v),M=b(v,P);g.push([P,V,M],[V,C,h],[M,h,v],[V,h,M])}d=g}return d.map(([m,p,g])=>({vertices:[[f[m][0]+s,f[m][1]+i,f[m][2]+c],[f[p][0]+s,f[p][1]+i,f[p][2]+c],[f[g][0]+s,f[g][1]+i,f[g][2]+c]],color:r}))}function Cn(e){let{center:n,radius:o,height:t,sides:r=16,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[],d=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r,g=i+o*Math.cos(p),b=a+o*Math.sin(p);f.push([g,c-l,b]),d.push([g,c+l,b])}for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d[m],d[p],f[p],f[m]],color:s})}return u.push({vertices:[...d].reverse(),color:s}),u.push({vertices:[...f],color:s}),u}function vn(e){let{center:n,radius:o,height:t,sides:r=16,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r;f.push([i+o*Math.cos(p),c-l,a+o*Math.sin(p)])}let d=[i,c+l,a];for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d,f[p],f[m]],color:s})}return u.push({vertices:[...f],color:s}),u}function An(e){let{center:n,majorRadius:o,minorRadius:t,segments:r=24,sides:s=12,color:i="#ffffff"}=e,[c,a,l]=n,u=[];for(let d=0;d<r;d++){let m=2*Math.PI*d/r,p=Math.cos(m),g=Math.sin(m),b=[];for(let P=0;P<s;P++){let C=2*Math.PI*P/s,v=o+t*Math.cos(C);b.push([c+v*p,a+t*Math.sin(C),l+v*g])}u.push(b)}let f=[];for(let d=0;d<r;d++){let m=(d+1)%r;for(let p=0;p<s;p++){let g=(p+1)%s;f.push({vertices:[u[d][p],u[m][p],u[m][g],u[d][g]],color:i})}}return f}function Sn(e){let{center:n,radius:o,height:t,sides:r=4,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r;f.push([i+o*Math.cos(p),c-l,a+o*Math.sin(p)])}let d=[i,c+l,a];for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d,f[p],f[m]],color:s})}return u.push({vertices:[...f],color:s}),u}function On(e){let{center:n,radius:o,height:t,sides:r=6,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[],d=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r,g=i+o*Math.cos(p),b=a+o*Math.sin(p);f.push([g,c-l,b]),d.push([g,c+l,b])}for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d[m],d[p],f[p],f[m]],color:s})}return u.push({vertices:[...d].reverse(),color:s}),u.push({vertices:[...f],color:s}),u}function Tn(e){let{center:n,radius:o,height:t,sides:r=6,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[],d=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r,g=p+Math.PI/r;f.push([i+o*Math.cos(p),c-l,a+o*Math.sin(p)]),d.push([i+o*Math.cos(g),c+l,a+o*Math.sin(g)])}for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d[m],f[p],f[m]],color:s}),u.push({vertices:[d[m],d[p],f[p]],color:s})}return u.push({vertices:[...d].reverse(),color:s}),u.push({vertices:[...f],color:s}),u}function In(e){let{center:n,radius:o,halfHeight:t,sides:r=6,color:s="#ffffff"}=e,[i,c,a]=n,l=[],u=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r;u.push([i+o*Math.cos(p),c,a+o*Math.sin(p)])}let f=[i,c+t,a],d=[i,c-t,a];for(let m=0;m<r;m++){let p=(m+1)%r;l.push({vertices:[f,u[p],u[m]],color:s})}for(let m=0;m<r;m++){let p=(m+1)%r;l.push({vertices:[d,u[m],u[p]],color:s})}return l}function wn(e){let{center:n,radius:o,halfHeight:t,sides:r=5,color:s="#ffffff"}=e,[i,c,a]=n,l=Math.cos(Math.PI/r),u=t*(1-l)/(1+l),f=[],d=[],m=[];for(let b=0;b<r;b++){let P=2*Math.PI*b/r,C=P+Math.PI/r;d.push([i+o*Math.cos(P),c+u,a+o*Math.sin(P)]),m.push([i+o*Math.cos(C),c-u,a+o*Math.sin(C)])}let p=[i,c+t,a],g=[i,c-t,a];for(let b=0;b<r;b++){let P=(b+1)%r;f.push({vertices:[p,d[P],m[b],d[b]],color:s})}for(let b=0;b<r;b++){let P=(b+1)%r;f.push({vertices:[g,m[b],d[P],m[P]],color:s})}return f}function zn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),l=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],u=l.map(([p,g,b])=>[r+p*a,s+g*a,i+b*a]);function f(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],b=f(g,p),P=g[0]-b*p[0],C=g[1]-b*p[1],v=g[2]-b*p[2],V=Math.sqrt(P*P+C*C+v*v),h=[P/V,C/V,v/V],M=[p[1]*h[2]-p[2]*h[1],p[2]*h[0]-p[0]*h[2],p[0]*h[1]-p[1]*h[0]];return{u:h,w:M}}let m=[];for(let p=0;p<12;p++){let g=l[p],b=f(g,g),P=-1,C=1/0;for(let O=0;O<12;O++){if(O===p)continue;let w=f(l[O],g);w<C&&(C=w,P=O)}let v=[];for(let O=0;O<12;O++)O===p||O===P||v.push({idx:O,d:f(l[O],g)});v.sort((O,w)=>w.d-O.d);let V=v.slice(0,5).map(O=>O.idx),h=[g[0]/Math.sqrt(b),g[1]/Math.sqrt(b),g[2]/Math.sqrt(b)],{u:M,w:S}=d(h);V.sort((O,w)=>{let D=l[O],L=l[w],z=Math.atan2(f(D,S),f(D,M)),T=Math.atan2(f(L,S),f(L,M));return z-T});let x=[0,2,4,1,3].map(O=>V[O]),A=0,I=0,R=0;for(let O of x)A+=u[O][0],I+=u[O][1],R+=u[O][2];let E=[A/5,I/5,R/5];for(let O=0;O<5;O++){let w=u[x[O]],D=u[x[(O+2)%5]],L=[w[0]-E[0],w[1]-E[1],w[2]-E[2]],z=[D[0]-E[0],D[1]-E[1],D[2]-E[2]],T=L[1]*z[2]-L[2]*z[1],k=L[2]*z[0]-L[0]*z[2],N=L[0]*z[1]-L[1]*z[0],G=E[0]-r,_=E[1]-s,$=E[2]-i,F=T*G+k*_+N*$<0;m.push({vertices:F?[E,D,w]:[E,w,D],color:t})}}return m}function En(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),l=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],u=l.map(([p,g,b])=>[r+p*a,s+g*a,i+b*a]);function f(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],b=f(g,p),P=g[0]-b*p[0],C=g[1]-b*p[1],v=g[2]-b*p[2],V=Math.sqrt(P*P+C*C+v*v),h=[P/V,C/V,v/V],M=[p[1]*h[2]-p[2]*h[1],p[2]*h[0]-p[0]*h[2],p[0]*h[1]-p[1]*h[0]];return{u:h,w:M}}let m=[];for(let p=0;p<12;p++){let g=l[p],b=f(g,g),P=-1,C=1/0;for(let U=0;U<12;U++){if(U===p)continue;let B=f(l[U],g);B<C&&(C=B,P=U)}let v=[];for(let U=0;U<12;U++)U===p||U===P||v.push({idx:U,d:f(l[U],g)});v.sort((U,B)=>B.d-U.d);let V=v.slice(0,5).map(U=>U.idx),h=[g[0]/Math.sqrt(b),g[1]/Math.sqrt(b),g[2]/Math.sqrt(b)],{u:M,w:S}=d(h);V.sort((U,B)=>{let q=l[U],Z=l[B];return Math.atan2(f(q,S),f(q,M))-Math.atan2(f(Z,S),f(Z,M))});let y=0,x=0,A=0;for(let U of V)y+=u[U][0],x+=u[U][1],A+=u[U][2];y/=5,x/=5,A/=5;let I=u[V[0]],R=u[V[1]],E=u[V[2]],O=R[0]-I[0],w=R[1]-I[1],D=R[2]-I[2],L=E[0]-I[0],z=E[1]-I[1],T=E[2]-I[2],k=w*T-D*z,N=D*L-O*T,G=O*z-w*L,_=y-r,$=x-s,F=A-i,j=k*_+N*$+G*F<0?[...V].reverse():V;m.push({vertices:j.map(U=>u[U]),color:t})}return m}function Rn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=1/c,l=o/Math.sqrt(3),f=[[-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,-c,-a],[0,-c,a],[0,c,-a],[0,c,a],[-a,0,-c],[a,0,-c],[-a,0,c],[a,0,c],[-c,-a,0],[-c,a,0],[c,-a,0],[c,a,0]].map(([g,b,P])=>[r+g*l,s+b*l,i+P*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]],m=[0,2,4,1,3],p=[];for(let g of d){let b=m.map(h=>g[h]),P=0,C=0,v=0;for(let h of b)P+=f[h][0],C+=f[h][1],v+=f[h][2];let V=[P/5,C/5,v/5];for(let h=0;h<5;h++){let M=f[b[h]],S=f[b[(h+2)%5]],y=[M[0]-V[0],M[1]-V[1],M[2]-V[2]],x=[S[0]-V[0],S[1]-V[1],S[2]-V[2]],A=y[1]*x[2]-y[2]*x[1],I=y[2]*x[0]-y[0]*x[2],R=y[0]*x[1]-y[1]*x[0],E=V[0]-r,O=V[1]-s,w=V[2]-i,D=A*E+I*O+R*w<0;p.push({vertices:D?[V,S,M]:[V,M,S],color:t})}}return p}function kn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),l=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],u=l.map(([m,p,g])=>[r+m*a,s+p*a,i+g*a]),f=[[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 m=0;m<12;m++){let p=1/0;for(let g=0;g<12;g++){if(g===m)continue;let b=l[m][0]*l[g][0]+l[m][1]*l[g][1]+l[m][2]*l[g][2];b<p&&(p=b,d[m]=g)}}return f.map(([m,p,g])=>({vertices:[u[d[m]],u[d[g]],u[d[p]]],color:t}))}function ke(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=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,m,p])=>[r+d*c,s+m*c,i+p*c]),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]],f=[[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})),...f.map(d=>({vertices:[l[d[0]],l[d[1]],l[d[2]],l[d[3]]],color:t}))]}function De(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,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,f=[];function d(x,A){return x<A?`${x},${A}`:`${A},${x}`}function m(x,A){let I=d(x,A);if(u.has(I))return u.get(I);let[R,E,O]=a[x],[w,D,L]=a[A],z=f.length;return f.push([(R+w)/2,(E+D)/2,(O+L)/2]),u.set(I,z),z}let p=Array.from({length:12},()=>[]),g=l.map(([x,A,I])=>{let R=m(x,A),E=m(A,I),O=m(I,x);return p[x].includes(R)||p[x].push(R),p[x].includes(O)||p[x].push(O),p[A].includes(R)||p[A].push(R),p[A].includes(E)||p[A].push(E),p[I].includes(E)||p[I].push(E),p[I].includes(O)||p[I].push(O),[R,E,O]}),[b,P,C]=f[0],v=Math.sqrt(b*b+P*P+C*C),V=o/v,h=f.map(([x,A,I])=>[r+x*V,s+A*V,i+I*V]);function M(x,A){let I=0,R=0,E=0;for(let q of x)I+=f[q][0],R+=f[q][1],E+=f[q][2];let O=x.length;I/=O,R/=O,E/=O;let[w,D,L]=A,[z,T,k]=f[x[0]],N=z-I,G=T-R,_=k-E,$=N*w+G*D+_*L;N-=$*w,G-=$*D,_-=$*L;let F=Math.sqrt(N*N+G*G+_*_);N/=F,G/=F,_/=F;let H=D*_-L*G,j=L*N-w*_,U=w*G-D*N,B=x.map(q=>{let[Z,J,ne]=f[q],ie=Z-I,oe=J-R,Q=ne-E,X=ie*N+oe*G+Q*_,K=ie*H+oe*j+Q*U;return{i:q,angle:Math.atan2(K,X)}});return B.sort((q,Z)=>q.angle-Z.angle),B.map(q=>q.i)}let S=g.map(([x,A,I])=>{let[R,E,O]=f[x],[w,D,L]=f[A],[z,T,k]=f[I],N=[(R+w+z)/3,(E+D+T)/3,(O+L+k)/3];return{vertices:M([x,A,I],N).map(_=>h[_]),color:t}}),y=a.map((x,A)=>{let I=p[A];return{vertices:M(I,x).map(O=>h[O]),color:t}});return[...S,...y]}function Le(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=1/Math.sqrt(3),a=[[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 V=0;V<4;V++){if(v===V)continue;let[h,M,S]=a[v],[y,x,A]=a[V],I=[2/3*h+1/3*y,2/3*M+1/3*x,2/3*S+1/3*A];l[v][V]=I,u.push(I)}let f=0;for(let[v,V,h]of u){let M=Math.sqrt(v*v+V*V+h*h);M>f&&(f=M)}let d=o/f,m=(v,V)=>{let[h,M,S]=l[v][V];return[r+h*d,s+M*d,i+S*d]};function p(v){let V=[0,1,2,3].filter(_=>_!==v),[h,M,S]=V,y=m(v,h),x=m(v,M),A=m(v,S),[I,R,E]=a[v],O=x[0]-y[0],w=x[1]-y[1],D=x[2]-y[2],L=A[0]-y[0],z=A[1]-y[1],T=A[2]-y[2],k=w*T-D*z,N=D*L-O*T,G=O*z-w*L;return k*I+N*R+G*E<0?[y,A,x]:[y,x,A]}function g(v,V,h){let M=[m(v,V),m(V,v),m(V,h),m(h,V),m(h,v),m(v,h)],[S,y,x]=a[v],[A,I,R]=a[V],[E,O,w]=a[h],D=(S+A+E)/3,L=(y+I+O)/3,z=(x+R+w)/3,T=M[0],k=M[1],N=M[2],G=k[0]-T[0],_=k[1]-T[1],$=k[2]-T[2],F=N[0]-T[0],H=N[1]-T[1],j=N[2]-T[2],U=_*j-$*H,B=$*F-G*j,q=G*H-_*F;return U*D+B*L+q*z<0&&M.reverse(),M}let b=[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,V,h])=>({vertices:g(v,V,h),color:t}));return[...b,...C]}function Ne(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(2-Math.sqrt(2))/2,a=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],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 f(h,M){let S=`${h},${M}`;if(u.has(S))return u.get(S);let[y,x,A]=a[h],[I,R,E]=a[M],O=[(1-c)*y+c*I,(1-c)*x+c*R,(1-c)*A+c*E];return u.set(S,O),O}for(let[h,M]of l)f(h,M),f(M,h);let d=0;for(let h of u.values()){let[M,S,y]=h,x=Math.sqrt(M*M+S*S+y*y);x>d&&(d=x)}let m=o/d,p=h=>[r+h[0]*m,s+h[1]*m,i+h[2]*m];function g(h,M){return p(f(h,M))}function b(h,M){let[S,y,x]=M,A=h[0],I=h[1],R=h[2],E=I[0]-A[0],O=I[1]-A[1],w=I[2]-A[2],D=R[0]-A[0],L=R[1]-A[1],z=R[2]-A[2],T=O*z-w*L,k=w*D-E*z,N=E*L-O*D;return T*S+k*y+N*x<0?[...h].reverse():h}let P=[[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=a.map(([h,M,S],y)=>{let[x,A,I]=P[y],R=[g(y,x),g(y,A),g(y,I)];return{vertices:b(R,[h,M,S]),color:t}}),V=[{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:h,normal:M})=>{let[S,y,x,A]=h,I=[g(S,y),g(y,S),g(y,x),g(x,y),g(x,A),g(A,x),g(A,S),g(S,A)];return{vertices:b(I,M),color:t}});return[...C,...V]}function _e(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=o/Math.sqrt(5),a=new Set,l=[];for(let C=0;C<3;C++){let v=(C+1)%3,V=(C+2)%3;for(let h of[-1,1])for(let M of[-1,1])for(let S of[!1,!0]){let y=[0,0,0];y[v]=S?h*2:h*1,y[V]=S?M*1:M*2;let x=`${y[0]},${y[1]},${y[2]}`;a.has(x)||(a.add(x),l.push(y))}}let u=l.map(([C,v,V])=>[r+C*c,s+v*c,i+V*c]),f=new Map;for(let C=0;C<l.length;C++){let[v,V,h]=l[C];f.set(`${v},${V},${h}`,C)}function d(C,v,V){let h=`${C},${v},${V}`,M=f.get(h);if(M===void 0)throw new Error(`Vertex not found: (${C},${v},${V})`);return M}function m(C,v){let V=0,h=0,M=0;for(let _ of C)V+=l[_][0],h+=l[_][1],M+=l[_][2];let S=C.length;V/=S,h/=S,M/=S;let[y,x,A]=v,[I,R,E]=l[C[0]],O=I-V,w=R-h,D=E-M,L=O*y+w*x+D*A;O-=L*y,w-=L*x,D-=L*A;let z=Math.sqrt(O*O+w*w+D*D);O/=z,w/=z,D/=z;let T=x*D-A*w,k=A*O-y*D,N=y*w-x*O,G=C.map(_=>{let[$,F,H]=l[_],j=$-V,U=F-h,B=H-M,q=j*O+U*w+B*D,Z=j*T+U*k+B*N;return{i:_,angle:Math.atan2(Z,q)}});return G.sort((_,$)=>_.angle-$.angle),G.map(_=>_.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:m(C,v).map(V=>u[V]),color:t})),P=[[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,V])=>{let h=[];for(let S=0;S<l.length;S++){let[y,x,A]=l[S];Math.abs(C*y+v*x+V*A-3)<1e-9&&h.push(S)}let M=[C/Math.sqrt(3),v/Math.sqrt(3),V/Math.sqrt(3)];return{vertices:m(h,M).map(S=>u[S]),color:t}});return[...g,...P]}function Ge(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=1/c,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,-c,-a],[0,-c,a],[0,c,-a],[0,c,a],[-a,0,-c],[a,0,-c],[-a,0,c],[a,0,c],[-c,-a,0],[-c,a,0],[c,-a,0],[c,a,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]],f=new Set,d=[];for(let y of u)for(let x=0;x<5;x++){let A=y[x],I=y[(x+1)%5],R=A<I?`${A},${I}`:`${I},${A}`;f.has(R)||(f.add(R),d.push([A,I]))}let m=(3-Math.sqrt(5))/4,p=new Map;function g(y,x){let A=`${y},${x}`;if(p.has(A))return p.get(A);let[I,R,E]=l[y],[O,w,D]=l[x],L=[(1-m)*I+m*O,(1-m)*R+m*w,(1-m)*E+m*D];return p.set(A,L),L}for(let[y,x]of d)g(y,x),g(x,y);let b=0;for(let y of p.values()){let[x,A,I]=y,R=Math.sqrt(x*x+A*A+I*I);R>b&&(b=R)}let P=o/b,C=Array.from({length:20},()=>[]);for(let[y,x]of d)C[y].push(x),C[x].push(y);function v(y,x){let[A,I,R]=g(y,x);return[r+A*P,s+I*P,i+R*P]}function V(y,x){let[A,I,R]=x,E=y[0],O=y[1],w=y[2],D=O[0]-E[0],L=O[1]-E[1],z=O[2]-E[2],T=w[0]-E[0],k=w[1]-E[1],N=w[2]-E[2],G=L*N-z*k,_=z*T-D*N,$=D*k-L*T;return G*A+_*I+$*R<0?[...y].reverse():y}function h(y,x){let A=0,I=0,R=0;for(let[B,q,Z]of y)A+=B,I+=q,R+=Z;let E=y.length;A/=E,I/=E,R/=E;let[O,w,D]=x,[L,z,T]=y[0],k=L-A,N=z-I,G=T-R,_=k*O+N*w+G*D;k-=_*O,N-=_*w,G-=_*D;let $=Math.sqrt(k*k+N*N+G*G);k/=$,N/=$,G/=$;let F=w*G-D*N,H=D*k-O*G,j=O*N-w*k,U=y.map(B=>{let q=B[0]-A,Z=B[1]-I,J=B[2]-R,ne=q*k+Z*N+J*G,ie=q*F+Z*H+J*j;return{pt:B,angle:Math.atan2(ie,ne)}});return U.sort((B,q)=>B.angle-q.angle),U.map(B=>B.pt)}let M=l.map(([y,x,A],I)=>{let[R,E,O]=C[I],w=[g(I,R),g(I,E),g(I,O)],L=h(w,[y,x,A]).map(([z,T,k])=>[r+z*P,s+T*P,i+k*P]);return{vertices:V(L,[y,x,A]),color:t}}),S=u.map(y=>{let[x,A,I,R,E]=y,O=[g(x,A),g(A,x),g(A,I),g(I,A),g(I,R),g(R,I),g(R,E),g(E,R),g(E,x),g(x,E)],[w,D,L,z,T]=y.map(H=>l[H]),k=(w[0]+D[0]+L[0]+z[0]+T[0])/5,N=(w[1]+D[1]+L[1]+z[1]+T[1])/5,G=(w[2]+D[2]+L[2]+z[2]+T[2])/5,_=[k,N,G],F=h(O,_).map(([H,j,U])=>[r+H*P,s+j*P,i+U*P]);return{vertices:V(F,_),color:t}});return[...M,...S]}function $e(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,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,f=[];for(let[M,S,y]of l)for(let[x,A]of[[M,S],[S,y],[y,M]]){let I=x<A?`${x},${A}`:`${A},${x}`;u.has(I)||(u.add(I),f.push([x,A]))}let d=1/3,m=new Map;function p(M,S){let y=`${M},${S}`;if(m.has(y))return m.get(y);let[x,A,I]=a[M],[R,E,O]=a[S],w=[(1-d)*x+d*R,(1-d)*A+d*E,(1-d)*I+d*O];return m.set(y,w),w}for(let[M,S]of f)p(M,S),p(S,M);let g=0;for(let M of m.values()){let[S,y,x]=M,A=Math.sqrt(S*S+y*y+x*x);A>g&&(g=A)}let b=o/g,P=Array.from({length:12},()=>[]);for(let[M,S]of f)P[M].push(S),P[S].push(M);function C(M,S){let[y,x,A]=S,I=M[0],R=M[1],E=M[2],O=R[0]-I[0],w=R[1]-I[1],D=R[2]-I[2],L=E[0]-I[0],z=E[1]-I[1],T=E[2]-I[2],k=w*T-D*z,N=D*L-O*T,G=O*z-w*L;return k*y+N*x+G*A<0?[...M].reverse():M}function v(M,S){let y=0,x=0,A=0;for(let[j,U,B]of M)y+=j,x+=U,A+=B;let I=M.length;y/=I,x/=I,A/=I;let[R,E,O]=S,[w,D,L]=M[0],z=w-y,T=D-x,k=L-A,N=z*R+T*E+k*O;z-=N*R,T-=N*E,k-=N*O;let G=Math.sqrt(z*z+T*T+k*k);z/=G,T/=G,k/=G;let _=E*k-O*T,$=O*z-R*k,F=R*T-E*z,H=M.map(j=>{let U=j[0]-y,B=j[1]-x,q=j[2]-A,Z=U*z+B*T+q*k,J=U*_+B*$+q*F;return{pt:j,angle:Math.atan2(J,Z)}});return H.sort((j,U)=>j.angle-U.angle),H.map(j=>j.pt)}let V=a.map(([M,S,y],x)=>{let A=P[x].map(E=>p(x,E)),R=v(A,[M,S,y]).map(([E,O,w])=>[r+E*b,s+O*b,i+w*b]);return{vertices:C(R,[M,S,y]),color:t}}),h=l.map(([M,S,y])=>{let x=[p(M,S),p(S,M),p(S,y),p(y,S),p(y,M),p(M,y)],A=a[M],I=a[S],R=a[y],E=[(A[0]+I[0]+R[0])/3,(A[1]+I[1]+R[1])/3,(A[2]+I[2]+R[2])/3],w=v(x,E).map(([D,L,z])=>[r+D*b,s+L*b,i+z*b]);return{vertices:C(w,E),color:t}});return[...V,...h]}function na(e,n){if(n.length<=3)return!0;let[o,t,r]=e[n[0]],[s,i,c]=e[n[1]],[a,l,u]=e[n[2]],f=s-o,d=i-t,m=c-r,p=a-o,g=l-t,b=u-r,P=d*b-m*g,C=m*p-f*b,v=f*g-d*p,V=Math.sqrt(P*P+C*C+v*v);if(V<1e-10)return!1;let h=1/V,M=(P*o+C*t+v*r)*h;for(let S=3;S<n.length;S++){let[y,x,A]=e[n[S]];if(Math.abs((P*y+C*x+v*A)*h-M)>1e-6)return!1}return!0}function ta(e,n){let o=0,t=0,r=0;for(let y of n)o+=e[y][0],t+=e[y][1],r+=e[y][2];let s=n.length;o/=s,t/=s,r/=s;let[i,c,a]=e[n[0]],[l,u,f]=e[n[1]],[d,m,p]=e[n[2]],g=l-i,b=u-c,P=f-a,C=d-i,v=m-c,V=p-a,h=b*V-P*v,M=P*C-g*V,S=g*v-b*C;return h*o+M*t+S*r>0}function oa(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,s=[];function i(c,a){let l=c[c.length-1];if(c.length===o){if(!n[l].includes(a)||!na(e,c)||!ta(e,c))return;let u=oa(c);r.has(u)||(r.add(u),s.push([...c]));return}for(let u of n[l])c.includes(u)||u<=a||i([...c,u],a)}for(let c=0;c<t;c++)i([c],c);return s}function fe(e,n=1e-6){let o=e.length,t=1/0;for(let s=0;s<o;s++)for(let i=s+1;i<o;i++){let c=e[s][0]-e[i][0],a=e[s][1]-e[i][1],l=e[s][2]-e[i][2],u=Math.sqrt(c*c+a*a+l*l);u>1e-10&&u<t&&(t=u)}let r=Array.from({length:o},()=>[]);for(let s=0;s<o;s++)for(let i=s+1;i<o;i++){let c=e[s][0]-e[i][0],a=e[s][1]-e[i][1],l=e[s][2]-e[i][2],u=Math.sqrt(c*c+a*a+l*l);Math.abs(u-t)<n&&(r[s].push(i),r[i].push(s))}return{adj:r,edgeLen:t}}function me(e,n,o){let t=0,r=0,s=0;for(let M of n)t+=e[M][0],r+=e[M][1],s+=e[M][2];let i=n.length;t/=i,r/=i,s/=i;let[c,a,l]=o,[u,f,d]=e[n[0]],m=u-t,p=f-r,g=d-s,b=m*c+p*a+g*l;m-=b*c,p-=b*a,g-=b*l;let P=Math.sqrt(m*m+p*p+g*g);m/=P,p/=P,g/=P;let C=a*g-l*p,v=l*m-c*g,V=c*p-a*m,h=n.map(M=>{let[S,y,x]=e[M],A=S-t,I=y-r,R=x-s,E=A*m+I*p+R*g,O=A*C+I*v+R*V;return{i:M,angle:Math.atan2(O,E)}});return h.sort((M,S)=>M.angle-S.angle),h.map(M=>M.i)}function de(e,n){let o=0,t=0,r=0;for(let c of n)o+=e[c][0],t+=e[c][1],r+=e[c][2];let s=n.length;o/=s,t/=s,r/=s;let i=Math.sqrt(o*o+t*t+r*r);return[o/i,t/i,r/i]}function Fe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=1,a=1+Math.sqrt(2),l=1+2*Math.sqrt(2),u=[[c,a,l],[c,l,a],[a,c,l],[a,l,c],[l,c,a],[l,a,c]],f=[];for(let[x,A,I]of u)for(let R of[-1,1])for(let E of[-1,1])for(let O of[-1,1])f.push([R*x,E*A,O*I]);let d=new Set,m=[];for(let x of f){let A=`${x[0].toFixed(9)},${x[1].toFixed(9)},${x[2].toFixed(9)}`;d.has(A)||(d.add(A),m.push(x))}let[p,g,b]=m[0],P=Math.sqrt(p*p+g*g+b*b),C=o/P,v=m.map(([x,A,I])=>[r+x*C,s+A*C,i+I*C]),{adj:V}=fe(m),h=te(m,V,4),M=te(m,V,6),S=te(m,V,8);function y(x){let A=de(m,x);return{vertices:me(m,x,A).map(R=>v[R]),color:t}}return[...h.map(y),...M.map(y),...S.map(y)]}function Ue(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[1/c,1/c,3+c],[2/c,c,1+2*c],[1/c,c*c,-1+3*c],[2*c-1,2,2+c],[c,3,2*c]],l=[];for(let[S,y,x]of a){let A=[[S,y,x],[y,x,S],[x,S,y]];for(let[I,R,E]of A)for(let O of[-1,1])for(let w of[-1,1])for(let D of[-1,1])l.push([O*I,w*R,D*E])}let u=new Set,f=[];for(let S of l){let y=`${S[0].toFixed(8)},${S[1].toFixed(8)},${S[2].toFixed(8)}`;u.has(y)||(u.add(y),f.push(S))}let[d,m,p]=f[0],g=Math.sqrt(d*d+m*m+p*p),b=o/g,P=f.map(([S,y,x])=>[r+S*b,s+y*b,i+x*b]),{adj:C}=fe(f),v=te(f,C,4),V=te(f,C,6),h=te(f,C,10);function M(S){let y=de(f,S);return{vertices:me(f,S,y).map(A=>P[A]),color:t}}return[...v.map(M),...V.map(M),...h.map(M)]}function Be(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=1+Math.sqrt(2),a=[],l=[[1,1,c],[1,c,1],[c,1,1]];for(let[V,h,M]of l)for(let S of[-1,1])for(let y of[-1,1])for(let x of[-1,1])a.push([S*V,y*h,x*M]);let[u,f,d]=a[0],m=Math.sqrt(u*u+f*f+d*d),p=o/m,g=a.map(([V,h,M])=>[r+V*p,s+h*p,i+M*p]),{adj:b}=fe(a),P=te(a,b,3),C=te(a,b,4);function v(V){let h=de(a,V);return{vertices:me(a,V,h).map(S=>g[S]),color:t}}return[...P.map(v),...C.map(v)]}function je(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=c*c,l=a*c,u=[];for(let[y,x,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 E of[-1,1])u.push([I*y,R*x,E*A]);for(let[y,x,A]of[[a,c,2*c],[c,2*c,a],[2*c,a,c]])for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])u.push([I*y,R*x,E*A]);for(let[y,x,A]of[[2+c,0,a],[0,a,2+c],[a,2+c,0]])for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])u.push([I*y,R*x,E*A]);let f=new Set,d=[];for(let y of u){let x=`${y[0].toFixed(8)},${y[1].toFixed(8)},${y[2].toFixed(8)}`;f.has(x)||(f.add(x),d.push(y))}let[m,p,g]=d[0],b=Math.sqrt(m*m+p*p+g*g),P=o/b,C=d.map(([y,x,A])=>[r+y*P,s+x*P,i+A*P]),{adj:v}=fe(d),V=te(d,v,3),h=te(d,v,4),M=te(d,v,5);function S(y){let x=de(d,y);return{vertices:me(d,y,x).map(I=>C[I]),color:t}}return[...V.map(S),...h.map(S),...M.map(S)]}function He(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.cbrt(19+3*Math.sqrt(33))+Math.cbrt(19-3*Math.sqrt(33)))/3,a=1,l=1/c,u=c,f=[[a,l,u],[l,u,a],[u,a,l]],d=[[u,l,a],[l,a,u],[a,u,l]],m=[];for(let[y,x,A]of f)for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(E===-1?1:0))%2===0&&m.push([I*y,R*x,E*A]);for(let[y,x,A]of d)for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(E===-1?1:0))%2===1&&m.push([I*y,R*x,E*A]);let[p,g,b]=m[0],P=Math.sqrt(p*p+g*g+b*b),C=o/P,v=m.map(([y,x,A])=>[r+y*C,s+x*C,i+A*C]),{adj:V}=fe(m),h=te(m,V,3),M=te(m,V,4);function S(y){let x=de(m,y);return{vertices:me(m,y,x).map(I=>v[I]),color:t}}return[...h.map(S),...M.map(S)]}function qe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],l=Math.sqrt(1+c*c),u=a.map(([O,w,D])=>[O/l,w/l,D/l]),f=[[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(O,w){return[O[1]*w[2]-O[2]*w[1],O[2]*w[0]-O[0]*w[2],O[0]*w[1]-O[1]*w[0]]}function m(O){return Math.sqrt(O[0]*O[0]+O[1]*O[1]+O[2]*O[2])}function p(O){let w=m(O);return[O[0]/w,O[1]/w,O[2]/w]}function g(O,w){return Math.sqrt((O[0]-w[0])**2+(O[1]-w[1])**2+(O[2]-w[2])**2)}function b(O,w,D,L){let[z,T,k]=u[O],[N,G,_]=u[w],$=[(1-D)*z+D*N,(1-D)*T+D*G,(1-D)*k+D*_],F=p(d(u[O],u[w]));return p([$[0]+L*F[0],$[1]+L*F[1],$[2]+L*F[2]])}function P(O,w){let D=b(0,2,O,w),L=b(2,9,O,w),z=b(2,0,O,w);return g(D,L)-g(D,z)}function C(O,w){let D=b(0,2,O,w),L=b(2,9,O,w),z=b(0,9,O,w);return g(D,L)-g(D,z)}let v=.35,V=.13,h=1e-7;for(let O=0;O<80;O++){let w=P(v,V),D=C(v,V);if(Math.abs(w)<1e-13&&Math.abs(D)<1e-13)break;let L=(P(v+h,V)-P(v-h,V))/(2*h),z=(P(v,V+h)-P(v,V-h))/(2*h),T=(C(v+h,V)-C(v-h,V))/(2*h),k=(C(v,V+h)-C(v,V-h))/(2*h),N=L*k-z*T;if(Math.abs(N)<1e-12)break;v-=(w*k-D*z)/N,V-=(D*L-w*T)/N}let M=new Set,S=[];for(let[O,w,D]of f)for(let[L,z]of[[O,w],[w,D],[D,O],[w,O],[D,w],[O,D]]){let T=`${L},${z}`;M.has(T)||(M.add(T),S.push(b(L,z,v,V)))}let y=S,x=y.map(([O,w,D])=>[r+O*o,s+w*o,i+D*o]),{adj:A}=fe(y),I=te(y,A,3),R=te(y,A,5);function E(O){let w=de(y,O);return{vertices:me(y,O,w).map(L=>x[L]),color:t}}return[...I.map(E),...R.map(E)]}function ra(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 sa(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function ca(e){let n=sa(e);return[e[0]/n,e[1]/n,e[2]/n]}function ia(e){let[n,o,t]=e[0],[r,s,i]=e[1],[c,a,l]=e[2],u=r-n,f=s-o,d=i-t,m=c-n,p=a-o,g=l-t,b=f*g-d*p,P=d*m-u*g,C=u*p-f*m,v=e.reduce((y,x)=>y+x[0],0)/e.length,V=e.reduce((y,x)=>y+x[1],0)/e.length,h=e.reduce((y,x)=>y+x[2],0)/e.length,M=b*v+P*V+C*h>0?1:-1,S=Math.sqrt(b*b+P*P+C*C);return[M*b/S,M*P/S,M*C/S]}function ee(e){let o=[],t=[];function r(f){for(let d=0;d<o.length;d++)if(ra(o[d],f)<1e-10)return d;return o.push(f),o.length-1}for(let f of e)t.push(f.vertices.map(d=>r(d)));let s=e.length,i=o.length,c=Math.max(...o.map(f=>f[0]*f[0]+f[1]*f[1]+f[2]*f[2])),a=e.map((f,d)=>{let m=f.vertices,p=ia(m),g=m[0],b=p[0]*g[0]+p[1]*g[1]+p[2]*g[2],P=c/b;return[p[0]*P,p[1]*P,p[2]*P]}),l=Array.from({length:i},()=>[]);for(let f=0;f<s;f++)for(let d of t[f])l[d].push(f);let u=[];for(let f=0;f<i;f++){let d=l[f];if(d.length<3)continue;let m=o[f],p=ca(m),g=a[d[0]],b=g[0]-m[0],P=g[1]-m[1],C=g[2]-m[2],v=b*p[0]+P*p[1]+C*p[2];b-=v*p[0],P-=v*p[1],C-=v*p[2];let V=Math.sqrt(b*b+P*P+C*C);if(V<1e-12)continue;let h=[b/V,P/V,C/V],M=[p[1]*h[2]-p[2]*h[1],p[2]*h[0]-p[0]*h[2],p[0]*h[1]-p[1]*h[0]],S=d.map(y=>{let x=a[y],A=x[0]-m[0],I=x[1]-m[1],R=x[2]-m[2],E=A*h[0]+I*h[1]+R*h[2],O=A*M[0]+I*M[1]+R*M[2];return{fi:y,angle:Math.atan2(O,E)}});S.sort((y,x)=>y.angle-x.angle),u.push(S.map(y=>y.fi))}return u.map(f=>({vertices:f.map(d=>a[d]),color:"#ffffff"}))}function Dn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=ke({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Ln(e){let{center:n,size:o,color:t="#ffffff"}=e,r=De({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Nn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Le({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function _n(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ne({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Gn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=_e({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function $n(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ge({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Fn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=$e({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Un(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Fe({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Bn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ue({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+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(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Hn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=je({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function qn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=He({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Xn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=qe({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Ao(e,n={}){let{center:o=[0,0,0],size:t=1,color:r}=n;switch(e){case"tetrahedron":return bn({center:o,size:t,color:r});case"cube":return xn({center:o,size:t,color:r});case"octahedron":return hn({center:o,size:t,color:r});case"dodecahedron":return Pn({center:o,size:t,color:r});case"icosahedron":return Mn({center:o,size:t,color:r});case"smallStellatedDodecahedron":return zn({center:o,size:t,color:r});case"greatDodecahedron":return En({center:o,size:t,color:r});case"greatStellatedDodecahedron":return Rn({center:o,size:t,color:r});case"greatIcosahedron":return kn({center:o,size:t,color:r});case"cuboctahedron":return ke({center:o,size:t,color:r});case"icosidodecahedron":return De({center:o,size:t,color:r});case"truncatedTetrahedron":return Le({center:o,size:t,color:r});case"truncatedCube":return Ne({center:o,size:t,color:r});case"truncatedOctahedron":return _e({center:o,size:t,color:r});case"truncatedDodecahedron":return Ge({center:o,size:t,color:r});case"truncatedIcosahedron":return $e({center:o,size:t,color:r});case"truncatedCuboctahedron":return Fe({center:o,size:t,color:r});case"truncatedIcosidodecahedron":return Ue({center:o,size:t,color:r});case"rhombicuboctahedron":return Be({center:o,size:t,color:r});case"rhombicosidodecahedron":return je({center:o,size:t,color:r});case"snubCube":return He({center:o,size:t,color:r});case"snubDodecahedron":return qe({center:o,size:t,color:r});case"rhombicDodecahedron":return Dn({center:o,size:t,color:r});case"rhombicTriacontahedron":return Ln({center:o,size:t,color:r});case"triakisTetrahedron":return Nn({center:o,size:t,color:r});case"triakisOctahedron":return _n({center:o,size:t,color:r});case"triakisIcosahedron":return $n({center:o,size:t,color:r});case"tetrakisHexahedron":return Gn({center:o,size:t,color:r});case"pentakisDodecahedron":return Fn({center:o,size:t,color:r});case"disdyakisDodecahedron":return Un({center:o,size:t,color:r});case"disdyakisTriacontahedron":return Bn({center:o,size:t,color:r});case"deltoidalIcositetrahedron":return jn({center:o,size:t,color:r});case"deltoidalHexecontahedron":return Hn({center:o,size:t,color:r});case"pentagonalIcositetrahedron":return qn({center:o,size:t,color:r});case"pentagonalHexecontahedron":return Xn({center:o,size:t,color:r});case"sphere":return Vn({center:o,size:t,color:r});case"cylinder":return Cn({center:o,radius:t,height:t*2,color:r});case"cone":return vn({center:o,radius:t,height:t*2,color:r});case"torus":return An({center:o,majorRadius:t,minorRadius:t*.3,color:r});case"pyramid":return Sn({center:o,radius:t,height:t*2,color:r});case"prism":return On({center:o,radius:t,height:t*2,color:r});case"antiprism":return Tn({center:o,radius:t,height:t*2,color:r});case"bipyramid":return In({center:o,radius:t,halfHeight:t,color:r});case"trapezohedron":return wn({center:o,radius:t,halfHeight:t,color:r});default:{let s=e;throw new Error(`Unknown geometry: ${String(s)}`)}}}var Zr=2200,Qr=2201,Jr=2202;function aa(e,n){let o=0,t=1,r=1,s=2201,i=1/0,c=0,a=!1,l=null,u=!0,f=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(m){r=m},get weight(){return t},set weight(m){t=m},get time(){return o},set time(m){o=m},get isRunning(){return a},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return a=!0,d},stop(){return a=!1,o=0,c=0,l=null,d},reset(){return o=0,c=0,d},fadeIn(m){return l={from:0,to:1,elapsed:0,duration:m},t=0,d},fadeOut(m){return l={from:t,to:0,elapsed:0,duration:m},d},crossFadeTo(m,p){return d.fadeOut(p),m.fadeIn(p),d},crossFadeFrom(m,p){return m.fadeOut(p),d.fadeIn(p),d},setLoop(m,p){return s=m,i=p,d},setEffectiveTimeScale(m){return r=m,d},setEffectiveWeight(m){return t=m,d}};return d._internal={get clip(){return e},get time(){return o},get weight(){return t},get enabled(){return u},get paused(){return f},get running(){return a},get loopMode(){return s},get repetitions(){return i},get completedReps(){return c},set completedReps(m){c=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!a)return;if(l){l.elapsed+=m;let 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)){a=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(o+=m*r,s===2200)o>=p&&(o=d.clampWhenFinished?p:0,a=!1);else if(s===2201){if(o>=p){let g=o%p,b=Math.floor(o/p);c+=b,o=g,i!==1/0&&c>=i&&(o=d.clampWhenFinished?p:0,a=!1)}}else if(p>0){let g=p*2,b=o%g;if(o>=g){let P=Math.floor(o/g);c+=P,i!==1/0&&c>=i?(o=d.clampWhenFinished?p:0,a=!1):o=b}}}},sampleTime(){if(s===2202){let m=e.duration,p=m*2,g=o%p;return g<=m?g:p-g}return o}},d}function la(e){return e._internal}function So(e,n){return typeof n=="number"?e[n]:e.find(o=>o.name===n)}function es(e,n){let o=new Map;function t(l){let u=So(n.clips,l);if(!u)throw new Error(`GlyphAnimationMixer: no clip found for key "${l}". Available: ${n.clips.map(d=>d.name).join(", ")}`);let f=o.get(u.index);return f||(f=aa(u,n),o.set(u.index,f)),f}function r(l){let u=So(n.clips,l);return u?o.get(u.index)??null:null}function s(l){let u=[];for(let g of o.values()){let b=la(g);b.advance(l),b.running&&b.enabled&&u.push({internal:b,clip:b.clip})}if(u.length===0)return;if(u.length===1){let{internal:g,clip:b}=u[0],P=n.sample(b.name,g.sampleTime());e.setPolygons(P);return}let f=0;for(let{internal:g}of u)f+=g.weight;if(f<=0)return;let d=u.map(({internal:g,clip:b})=>({polygons:n.sample(b.name,g.sampleTime()),weight:g.weight/f})),m=d[0].polygons;if(m.length===0)return;let p=m.map((g,b)=>{let P=g.vertices.map((C,v)=>{let V=0,h=0,M=0;for(let{polygons:S,weight:y}of d){let x=S[b];if(!x)continue;let A=x.vertices[v];A&&(V+=A[0]*y,h+=A[1]*y,M+=A[2]*y)}return[V,h,M]});return{...g,vertices:P}});e.setPolygons(p)}function i(){for(let l of o.values())l.stop()}function c(l){let u=So(n.clips,l);u&&o.delete(u.index)}function a(){o.clear()}return{clipAction:t,existingAction:r,update:s,stopAllAction:i,uncacheClip:c,uncacheRoot:a}}var ua=/^[0-9A-Fa-f]{6}$/,fa=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function xt(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",s=n?.palette??fa,i=n?.materialColors??{},c=n?.materialTextures??{},a=[],l=[],u=[],f=[],d=new Map,m=r,p,g=n?.includeObjects?new Set(n.includeObjects):null,b=n?.excludeObjects?new Set(n.excludeObjects):null,P=null,C=()=>P===null?g===null:!(g&&!g.has(P)||b&&b.has(P)),v=L=>L in i?i[L]:ua.test(L)?`#${L}`:(d.has(L)||(d.set(L,s[f.length%s.length]),f.push(L)),d.get(L)),V=e.split(`
2
- `);for(let L of V)if(!(L.length===0||L.charCodeAt(0)===35)){if(L.startsWith("v ")){let z=L.trim().split(/\s+/);a.push([parseFloat(z[1]),parseFloat(z[2]),parseFloat(z[3])])}else if(L.startsWith("vt ")){let z=L.trim().split(/\s+/);l.push([parseFloat(z[1]),parseFloat(z[2])])}else if(L.startsWith("o "))P=L.trim().slice(2).trim();else if(L.startsWith("usemtl ")){let z=L.trim().split(/\s+/)[1];m=v(z),p=c[z]}else if(L.startsWith("f ")){if(!C())continue;let z=L.trim().split(/\s+/).slice(1),T=[],k=[];for(let N of z){let G=N.split("/");T.push(parseInt(G[0],10)-1);let _=G[1];if(_&&_.length>0){let $=parseInt(_,10)-1;k.push(Number.isFinite($)?$:null)}else k.push(null)}u.push({idx:T,uvIdx:k,color:m,texture:p})}}if(a.length===0||u.length===0)return ma(f,e.length);let h=new Set;for(let L of u)for(let z of L.idx)h.add(z);let M=1/0,S=1/0,y=1/0,x=-1/0,A=-1/0,I=-1/0;for(let L of h){let z=a[L];z&&(z[0]<M&&(M=z[0]),z[0]>x&&(x=z[0]),z[1]<S&&(S=z[1]),z[1]>A&&(A=z[1]),z[2]<y&&(y=z[2]),z[2]>I&&(I=z[2]))}let R=Math.max(x-M,A-S,I-y),E=R>0?o/R:1,O=L=>Math.round(L*1e3)/1e3,w=a.map(([L,z,T])=>[O((T-y)*E+t),O((L-M)*E+t),O((z-S)*E+t)]),D=[];for(let{idx:L,uvIdx:z,color:T,texture:k}of u)for(let N=1;N<L.length-1;N++){let G=L[0],_=L[N],$=L[N+1],F=w[G],H=w[_],j=w[$];if(!F||!H||!j||F[0]===H[0]&&F[1]===H[1]&&F[2]===H[2]||F[0]===j[0]&&F[1]===j[1]&&F[2]===j[2]||H[0]===j[0]&&H[1]===j[1]&&H[2]===j[2])continue;let U;if(k){let q=z[0],Z=z[N],J=z[N+1];if(q!=null&&Z!=null&&J!=null){let ne=l[q],ie=l[Z],oe=l[J];ne&&ie&&oe&&(U=[ne,ie,oe])}}let B={vertices:[F,H,j],color:T};k&&(B.texture=k),U&&(B.uvs=U),D.push(B)}return{polygons:D,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:D.length,materials:f,sourceBytes:e.length}}}function ma(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var Oo=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function Pt(e){let n={},o={},t=null;for(let r of e.split(`
3
- `)){let s=r.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+/),c=parseFloat(i[1]),a=parseFloat(i[2]),l=parseFloat(i[3]);Number.isFinite(c)&&Number.isFinite(a)&&Number.isFinite(l)&&(n[t]=`#${Oo(c)}${Oo(a)}${Oo(l)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),c=i[i.length-1]?.replace(/\\+/g,"/");c&&c!=="map_Kd"&&(o[t]=c)}}}}return{colors:n,textures:o}}var ss={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},cs={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function is(e){let n=globalThis.TextDecoder;return new n().decode(e)}function da(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 i=decodeURIComponent(t),c=new Uint8Array(i.length);for(let a=0;a<i.length;a++)c[a]=i.charCodeAt(a)&255;return c}let r=globalThis.atob(t),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s}function pa(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 da(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 ga(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,s=null;for(;t<e.byteLength;){let i=n.getUint32(t,!0),c=n.getUint32(t+4,!0),a=t+8;if(c===1313821514){let l=new Uint8Array(e,a,i);r=JSON.parse(is(l))}else c===5130562&&(s=new Uint8Array(e,a,i));t=a+i}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:s}}function To(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 s=ss[t.componentType],i=cs[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let c=(r.byteOffset??0)+(t.byteOffset??0),a=t.count*i,l=n.buffer.slice(n.byteOffset+c,n.byteOffset+c+a*s),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:i}}function ya(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 ha(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 Ct(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 s=ss[t.componentType],i=cs[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let c=n.byteOffset+(r.byteOffset??0)+(t.byteOffset??0),a=r.byteStride??s*i,l=new DataView(n.buffer),u=new Array(t.count*i),f=0;for(let d=0;d<t.count;d++){let m=c+d*a;for(let p=0;p<i;p++){let g=ya(l,m+p*s,t.componentType);u[f++]=t.normalized?ha(g,t.componentType):g}}return{values:u,count:t.count,componentCount:i}}function ba(e,n,o){let t=[],r=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(o&&!i.uri.startsWith("data:"))try{t.push(new s.URL(i.uri,o).href)}catch{t.push(i.uri)}else t.push(i.uri);continue}if(i.bufferView!==void 0){let c=e.bufferViews?.[i.bufferView];if(!c){t.push("");continue}let a=c.byteOffset??0,l=n.subarray(a,a+c.byteLength),u=i.mimeType??"image/png",f=new s.Blob([l],{type:u}),d=s.URL.createObjectURL(f);t.push(d),r.push(d)}else t.push("")}return{urls:t,objectUrls:r}}function xa(e,n){let o=new Map,t=e.materials??[];for(let r=0;r<t.length;r++){let s=t[r].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s]?.source;if(i===void 0)continue;let c=n[i];c&&o.set(r,c)}return o}function Pa(e,n){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let t=c=>Math.max(0,Math.min(1,c)),r=c=>Math.round(t(c)*255).toString(16).padStart(2,"0"),s=c=>Math.round(t(c)*255),i=t(o[3]??1);return i<1?`rgba(${s(o[0])}, ${s(o[1])}, ${s(o[2])}, ${Math.round(i*1e3)/1e3})`:`#${r(o[0])}${r(o[1])}${r(o[2])}`}var en=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Io(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 Vt(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 as(e,n,o){let t=e?.[0]??0,r=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,c=n?.[1]??0,a=n?.[2]??0,l=n?.[3]??1,u=o?.[0]??1,f=o?.[1]??1,d=o?.[2]??1,m=i+i,p=c+c,g=a+a,b=i*m,P=i*p,C=i*g,v=c*p,V=c*g,h=a*g,M=l*m,S=l*p,y=l*g;return[(1-(v+h))*u,(P+y)*u,(C-S)*u,0,(P-y)*f,(1-(b+h))*f,(V+M)*f,0,(C+S)*d,(V-M)*d,(1-(b+v))*d,0,t,r,s,1]}function Ma(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():as(e.translation,e.rotation,e.scale)}function Va(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function ns(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function ls(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 Wn(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 Ca(e,n,o){let t=Wn(e),r=Wn(n),s=t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3];if(s<0&&(s=-s,r=[-r[0],-r[1],-r[2],-r[3]]),s>.9995)return Wn(ls(t,r,o));let i=Math.acos(Math.max(-1,Math.min(1,s))),c=Math.sin(i),a=Math.sin((1-o)*i)/c,l=Math.sin(o*i)/c;return Wn([t[0]*a+r[0]*l,t[1]*a+r[1]*l,t[2]*a+r[2]*l,t[3]*a+r[3]*l])}function va(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 ts(e){return e.matrix?e.matrix.slice():as(e.translation,e.rotation,e.scale)}function Aa(e){let n=e.scene??0,o=e.scenes?.[n]?.nodes;return o&&o.length>0?o:[]}function os(e,n){let o=e.nodes??[],t=new Array(o.length),r=new Set,s=(c,a)=>{if(c<0||c>=o.length)return;let l=Io(a,n[c]??en);t[c]=l,r.add(c);for(let u of o[c].children??[])s(u,l)},i=Aa(e);if(i.length>0)for(let c of i)s(c,en);for(let c=0;c<o.length;c++)r.has(c)||s(c,en);return t}function rs(e,n,o,t,r){if(o===void 0)return;let{values:s,count:i,componentCount:c}=Ct(e,n,o);if(i!==r||c<1)return;let a=[];for(let l=0;l<i;l++){let u=[];for(let f=0;f<t;f++)u.push(s[l*c+f]??0);a.push(u)}return a}function Sa(e,n,o,t){if(o===void 0)return Array.from({length:t},()=>en.slice());let{values:r,componentCount:s,count:i}=Ct(e,n,o);if(s!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${o} is not MAT4`);let c=[];for(let a=0;a<t;a++){let l=Math.min(a,i-1);c.push(r.slice(l*16,l*16+16))}return c}function Mt(e,n){let o=e.componentCount,t=e.interpolation==="CUBICSPLINE"?(n*3+1)*o:n*o;return e.output.slice(t,t+o)}function Oa(e,n,o){let t=e.input;if(t.length===0)return[];if(t.length===1||n<=t[0])return Mt(e,0);let r=t.length-1;if(n>=t[r])return Mt(e,r);let s=0,i=r;for(;s+1<i;){let d=s+i>>1;t[d]<=n?s=d:i=d}let c=t[s],a=t[s+1],l=a>c?(n-c)/(a-c):0,u=Mt(e,s),f=Mt(e,s+1);return e.interpolation==="STEP"?u:o==="rotation"?Ca(u,f,l):ls(u,f,l)}function Ta(e,n,o,t){let r=e.animations??[];if(r.length===0||o.length===0)return;let s=(e.nodes??[]).map(m=>va(m)),i=s.map(ts),c=os(e,i),a=(e.skins??[]).map(m=>({joints:m.joints??[],inverseBindMatrices:Sa(e,n,m.inverseBindMatrices,m.joints?.length??0)})),l=[];for(let m=0;m<r.length;m++){let p=r[m],g=(p.samplers??[]).map(C=>{let v=Ct(e,n,C.input),V=Ct(e,n,C.output);return{input:v.values,output:V.values,componentCount:V.componentCount,interpolation:C.interpolation??"LINEAR"}}),b=[];for(let C of p.channels??[]){let v=C.target.node,V=C.target.path,h=g[C.sampler];v===void 0||!V||!h||V==="weights"||b.push({sampler:h,targetNode:v,path:V})}let P=b.reduce((C,v)=>{let V=v.sampler.input;return Math.max(C,V[V.length-1]??0)},0);l.push({info:{index:m,name:p.name??`animation_${m}`,duration:P,channelCount:b.length},channels:b})}let u=l.map(m=>m.info);if(u.length===0)return;let f=(m,p,g,b,P,C)=>{let v=t(m),V=t(p),h=t(g);if(v[0]===V[0]&&v[1]===V[1]&&v[2]===V[2]||v[0]===h[0]&&v[1]===h[1]&&v[2]===h[2]||V[0]===h[0]&&V[1]===h[1]&&V[2]===h[2])return null;let M={vertices:[v,V,h],color:b};return P&&(M.texture=P),C&&(M.uvs=C),M};return{clips:u,sample:(m,p)=>{let g=typeof m=="number"?l[m]:l.find(h=>h.info.name===m);if(!g)return[];let b=g.info.duration,P=b>0?(p%b+b)%b:Math.max(0,p),C=s.map(h=>({translation:h.translation.slice(),rotation:h.rotation.slice(),scale:h.scale.slice(),matrix:h.matrix?h.matrix.slice():void 0}));for(let h of g.channels){let M=C[h.targetNode];if(!M)continue;let S=Oa(h.sampler,P,h.path);M.matrix=void 0,h.path==="translation"?M.translation=S.slice(0,3):h.path==="rotation"?M.rotation=Wn(S.slice(0,4)):h.path==="scale"&&(M.scale=S.slice(0,3))}let v=os(e,C.map(ts)),V=[];for(let h of o){let M=[];if(h.skinIndex!==void 0&&h.joints&&h.weights&&a[h.skinIndex]){let S=a[h.skinIndex];for(let y=0;y<h.positions.length;y++){let x=h.positions[y],A=[0,0,0],I=0,R=h.joints[y]??[],E=h.weights[y]??[];for(let O=0;O<4;O++){let w=E[O]??0;if(w<=0)continue;let D=Math.round(R[O]??0),L=S.joints[D],z=v[L],T=S.inverseBindMatrices[D];if(!z||!T)continue;let k=Io(z,T);A=Va(A,ns(Vt(k,x),w)),I+=w}M.push(I>0?ns(A,1/I):Vt(h.meshBindWorld,x))}}else{let S=h.meshNode!==null?v[h.meshNode]??h.meshBindWorld:h.meshBindWorld;for(let y of h.positions)M.push(Vt(S,y))}for(let S=0;S+2<h.indices.length;S+=3){let y=h.indices[S],x=h.indices[S+1],A=h.indices[S+2],I=M[y],R=M[x],E=M[A];if(!I||!R||!E)continue;let O;if(h.uvs&&h.texture){let D=h.uvs[y],L=h.uvs[x],z=h.uvs[A];D&&L&&z&&(O=[D,L,z])}let w=f(I,R,E,h.color,h.texture,O);w&&V.push(w)}}return V}}}function vt(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",s=n?.materialColors??{},i=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,c=i.byteLength,a,l;if(i.byteLength>=4&&new DataView(i).getUint32(0,!0)===1179937895){let T=ga(i);if(a=T.doc,!T.bin)throw new Error("parseGltf: GLB has no binary chunk");l=T.bin}else a=JSON.parse(is(new Uint8Array(i))),l=pa(a,n?.resolveBuffer);let{urls:u,objectUrls:f}=ba(a,l,n?.baseUrl),d=xa(a,u),m=[],p=[],g=(a.meshes??[]).map((T,k)=>T.name??`mesh_${k}`),b=(a.materials??[]).map((T,k)=>T.name??`material_${k}`);function P(T,k,N){let G=a.meshes?.[T];if(G)for(let _ of G.primitives){if((_.mode??4)!==4)continue;let F=_.material!==void 0?a.materials?.[_.material]?.name:void 0,j=(F?s[F]:void 0)??Pa(_.material!==void 0?a.materials?.[_.material]:void 0,r),U=_.material!==void 0?d.get(_.material):void 0,{array:B,count:q}=To(a,l,_.attributes.POSITION);if(!(B instanceof Float32Array))continue;let Z=[],J=[];for(let Q=0;Q<q;Q++){let X=[B[Q*3],B[Q*3+1],B[Q*3+2]];Z.push(X),J.push(Vt(k,X))}let ne=null,ie=_.attributes.TEXCOORD_0;if(U&&ie!==void 0){let{array:Q,count:X}=To(a,l,ie);ne=[];let K=1;Q instanceof Uint8Array?K=1/255:Q instanceof Uint16Array&&(K=1/65535);for(let le=0;le<X;le++){let Pe=Q[le*2]*K,Te=Q[le*2+1]*K;ne.push([Pe,1-Te])}}let oe;if(_.indices!==void 0){let{array:Q,count:X}=To(a,l,_.indices);oe=[];for(let K=0;K<X;K++)oe.push(Number(Q[K]))}else oe=J.map((Q,X)=>X);if((a.animations?.length??0)>0){let Q=rs(a,l,_.attributes.JOINTS_0,4,q),X=rs(a,l,_.attributes.WEIGHTS_0,4,q);p.push({meshNode:N,meshBindWorld:k,skinIndex:N!==null?a.nodes?.[N]?.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]],le=J[oe[Q+2]];if(!X||!K||!le)continue;let Pe;if(ne&&U){let Te=ne[oe[Q]],We=ne[oe[Q+1]],Ye=ne[oe[Q+2]];Te&&We&&Ye&&(Pe=[Te,We,Ye])}m.push({v0:X,v1:K,v2:le,color:j,texture:U,uvs:Pe})}}}function C(T,k){let N=a.nodes?.[T];if(!N)return;let G=Io(k,Ma(N));typeof N.mesh=="number"&&P(N.mesh,G,T);for(let _ of N.children??[])C(_,G)}let v=a.scene??0,V=a.scenes?.[v]?.nodes;if(V&&V.length>0)for(let T of V)C(T,en);else for(let T=0;T<(a.meshes?.length??0);T++)P(T,en,null);let h=Ia(f);if(m.length===0)return{polygons:[],objectUrls:f,dispose:h,warnings:[],metadata:{triangleCount:0,meshes:g,materials:b,sourceBytes:c}};let M=1/0,S=1/0,y=1/0,x=-1/0,A=-1/0,I=-1/0;for(let T of m)for(let k of[T.v0,T.v1,T.v2])k[0]<M&&(M=k[0]),k[0]>x&&(x=k[0]),k[1]<S&&(S=k[1]),k[1]>A&&(A=k[1]),k[2]<y&&(y=k[2]),k[2]>I&&(I=k[2]);let R=Math.max(x-M,A-S,I-y),E=R>0?o/R:1,O=T=>Math.round(T*1e3)/1e3,D=(n?.upAxis??"y")==="z"?([T,k,N])=>[O((T-M)*E+t),O((k-S)*E+t),O((N-y)*E+t)]:([T,k,N])=>[O((N-y)*E+t),O((T-M)*E+t),O((k-S)*E+t)],L=Ta(a,l,p,D),z=[];for(let T of m){let k=D(T.v0),N=D(T.v1),G=D(T.v2);if(k[0]===N[0]&&k[1]===N[1]&&k[2]===N[2]||k[0]===G[0]&&k[1]===G[1]&&k[2]===G[2]||N[0]===G[0]&&N[1]===G[1]&&N[2]===G[2])continue;let _={vertices:[k,N,G],color:T.color};T.texture&&(_.texture=T.texture),T.uvs&&(_.uvs=T.uvs),z.push(_)}return{polygons:z,animation:L,objectUrls:f,dispose:h,warnings:[],metadata:{triangleCount:z.length,meshes:g,materials:b,animations:L?.clips,sourceBytes:c}}}function Ia(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 Yn(e){return e.material?.texture??e.texture}function gs(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function wa(e,n){return new Promise((o,t)=>{let r=new n,s=!1,i=c=>{s||(s=!0,c())};r.decoding="async",r.onload=()=>i(()=>o(r)),r.onerror=()=>i(()=>t(new Error(`texture load failed: ${e}`))),r.src=e,typeof r.decode=="function"&&r.decode().then(()=>i(()=>o(r)),()=>{})})}async function ys(e,n,o){try{let t=await wa(e,n.Image),r=Math.max(0,Math.floor(t.naturalWidth||t.width||0)),s=Math.max(0,Math.floor(t.naturalHeight||t.height||0));if(r<=0||s<=0||r*s>o)return null;let i=n.createCanvas();i.width=r,i.height=s;let c=i.getContext("2d",{willReadFrequently:!0});if(!c)return null;c.drawImage(t,0,0,r,s);let a=c.getImageData(0,0,r,s).data;return{width:r,height:s,data:a,lowDetail:za(r,s,a)}}catch{return null}}function us(e,n,o,t,r,s){let i=(t*n+o)*4,c=(s*n+r)*4;return Math.max(Math.abs((e[i]??0)-(e[c]??0)),Math.abs((e[i+1]??0)-(e[c+1]??0)),Math.abs((e[i+2]??0)-(e[c+2]??0)))}function za(e,n,o){let t=Math.max(1,Math.floor(Math.max(e,n)/128)),r=0,s=0,i=0;for(let c=0;c<n;c+=t)for(let a=0;a<e;a+=t){if(a+t<e){let l=us(o,e,a,c,a+t,c);i+=l,r++,l>32&&s++}if(c+t<n){let l=us(o,e,a,c,a,c+t);i+=l,r++,l>32&&s++}}return r>0&&s/r<=.045&&i/r<=10}function fs(e,n,o){return Math.max(n,Math.min(o,e))}function hs(e,n){let o=n[0],t=1-n[1];if(!Number.isFinite(o)||!Number.isFinite(t))return null;let r=fs(Math.floor(o*e.width),0,e.width-1),i=(fs(Math.floor(t*e.height),0,e.height-1)*e.width+r)*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 Se(e,n,o,t,r,s){return[e[0]*t+n[0]*r+o[0]*s,e[1]*t+n[1]*r+o[1]*s]}function Ea(e){let[n,o,t]=e;return[Se(n,o,t,1/3,1/3,1/3),Se(n,o,t,.8,.1,.1),Se(n,o,t,.1,.8,.1),Se(n,o,t,.1,.1,.8),Se(n,o,t,.45,.45,.1),Se(n,o,t,.45,.1,.45),Se(n,o,t,.1,.45,.45)]}function Ra(e){let[n,o,t]=e,r=Ea(e);for(let s=1;s<6;s++)for(let i=1;i<6-s;i++){let c=6-s-i;c<=0||r.push(Se(n,o,t,s/6,i/6,c/6))}return r}function bs(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 ms(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 ds(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 ka(){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 Da(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 ps(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 La(e,n,o,t){let r=bs(e);if(r.length===0||!t&&!n.lowDetail)return null;let s=ka();for(let i of r)for(let c of Ra(i.uvs)){let a=hs(n,c);if(!a)return null;Da(s,a)}return s.count===0?null:ms(s.min,s.max,o)?ds(ps(s)):t||!ms(s.min,s.max,32)?null:ds(ps(s))}function Na(e,n){let{texture:o,material:t,uvs:r,textureTriangles:s,...i}=e;return{...i,color:n}}async function xs(e,n={}){if(n.enabled===!1)return null;let o=gs();if(!o)return null;let t=e.filter(a=>Yn(a)&&bs(a).length>0);if(t.length===0)return null;let r=n.maxTexturePixels??16777216,s=new Map;await Promise.all(Array.from(new Set(t.map(a=>Yn(a)))).map(async a=>{s.set(a,await ys(a,o,r))}));let i=n.colorTolerance??2,c=n.colorTolerance!==void 0;return{bake(a){let l=!1,u=a.map(f=>{let d=Yn(f);if(!d)return f;let m=s.get(d);if(!m)return f;let p=La(f,m,i,c);return p?(l=!0,Na(f,p)):f});return{polygons:l?u:a,changed:l}}}}async function Ps(e,n={}){let o=await xs(e,n);return o?o.bake(e).polygons:e}async function At(e,n={}){let o=await xs(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,s){return o.bake(e.animation.sample(r,s)).polygons}}:e.animation}}async function Ms(e,n={}){let o=new Map,t=gs();if(!t)return o;let r=n.maxTexturePixels??16777216,s=new Set;for(let i of e){let c=Yn(i);c&&s.add(c)}return await Promise.all([...s].map(async i=>{let c=await ys(i,t,r);c&&o.set(i,c)})),o}function Vs(e,n,o){return hs(e,[n,o])}function Cs(e){return Yn(e)}var _a=[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 Ga(e){let n=e>>0&255,o=e>>8&255,t=e>>16&255;return[n,o,t]}function wo(e){return(e&255).toString(16).padStart(2,"0")}function As(e,n,o){return`#${wo(e)}${wo(n)}${wo(o)}`}function $a(e,n,o,t){if(t>=255)return As(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 St(e,n){let o=n?.targetSize??60,t=n?.gridShift??0,r=e.byteLength;if(e.byteLength<8)return nn(r,["parseVox: buffer too small to be a valid .vox file"]);let s=new DataView(e);if(s.getUint32(0,!0)!==Fa)return nn(r,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return nn(r,["parseVox: buffer too small for MAIN chunk"]);if(vs(s,8)!=="MAIN")return nn(r,["parseVox: expected MAIN chunk at offset 8"]);let l=20+s.getUint32(12,!0),u=l+s.getUint32(16,!0),f=[],d=[],m=null;for(;l<u&&l+12<=e.byteLength;){let z=vs(s,l),T=s.getUint32(l+4,!0),k=s.getUint32(l+8,!0),N=l+12,G=N+T+k;if(z==="SIZE"){if(T>=12&&N+12<=e.byteLength){let _=s.getUint32(N,!0),$=s.getUint32(N+4,!0),F=s.getUint32(N+8,!0);f.push({sx:_,sy:$,sz:F})}}else if(z==="XYZI"){if(T>=4&&N+4<=e.byteLength){let _=s.getUint32(N,!0),$=[],F=Math.min(_,Math.floor((T-4)/4));for(let H=0;H<F;H++){let j=N+4+H*4;$.push({x:s.getUint8(j),y:s.getUint8(j+1),z:s.getUint8(j+2),colorIndex:s.getUint8(j+3)})}d.push($)}}else if(z==="RGBA"&&T>=1024&&N+1024<=e.byteLength){m=[];for(let _=0;_<256;_++){let $=N+_*4,F=s.getUint8($),H=s.getUint8($+1),j=s.getUint8($+2),U=s.getUint8($+3);m.push($a(F,H,j,U))}}l=G}let p=[],g=new Set;for(let z of d)for(let T of z){if(T.colorIndex===0)continue;let k=`${T.x},${T.y},${T.z}`;g.has(k)||(g.add(k),p.push(T))}if(p.length===0)return nn(r,[]);let b=z=>{let T=z-1;if(m!==null)return m[T]??"#888888";let k=_a[z]??0,[N,G,_]=Ga(k);return As(N,G,_)},P=(z,T,k)=>g.has(`${z},${T},${k}`),C=new Map,v=(z,T,k,N,G)=>{let _=`${z}:${T}:${G}`,$=C.get(_);$||($=new Set,C.set(_,$)),$.add(`${k},${N}`)};for(let z of p){let{x:T,y:k,z:N}=z,G=b(z.colorIndex);P(T+1,k,N)||v(0,T+1,k,N,G),P(T-1,k,N)||v(1,T,k,N,G),P(T,k+1,N)||v(2,k+1,T,N,G),P(T,k-1,N)||v(3,k,T,N,G),P(T,k,N+1)||v(4,N+1,T,k,G),P(T,k,N-1)||v(5,N,T,k,G)}function V(z){let T=new Set,k=[],N=1/0,G=-1/0,_=1/0,$=-1/0;for(let F of z){let[H,j]=F.split(","),U=+H,B=+j;U<N&&(N=U),U>G&&(G=U),B<_&&(_=B),B>$&&($=B)}for(let F=_;F<=$;F++)for(let H=N;H<=G;H++){let j=`${H},${F}`;if(!z.has(j)||T.has(j))continue;let U=1;for(;H+U<=G;){let q=`${H+U},${F}`;if(!z.has(q)||T.has(q))break;U++}let B=1;e:for(;F+B<=$;){for(let q=0;q<U;q++){let Z=`${H+q},${F+B}`;if(!z.has(Z)||T.has(Z))break e}B++}for(let q=0;q<B;q++)for(let Z=0;Z<U;Z++)T.add(`${H+Z},${F+q}`);k.push({u:H,v:F,w:U,h:B})}return k}let h=(z,T,k,N,G,_)=>{let $=k+G,F=N+_;switch(z){case 0:return[[T,k,N],[T,$,N],[T,$,F],[T,k,F]];case 1:return[[T,$,N],[T,k,N],[T,k,F],[T,$,F]];case 2:return[[k,T,N],[k,T,F],[$,T,F],[$,T,N]];case 3:return[[$,T,N],[$,T,F],[k,T,F],[k,T,N]];case 4:return[[k,N,T],[$,N,T],[$,F,T],[k,F,T]];default:return[[k,F,T],[$,F,T],[$,N,T],[k,N,T]]}},M=[];for(let[z,T]of C){let k=z.indexOf(":"),N=z.indexOf(":",k+1),G=+z.slice(0,k),_=+z.slice(k+1,N),$=z.slice(N+1);for(let{u:F,v:H,w:j,h:U}of V(T))M.push({vertices:h(G,_,F,H,j,U),color:$})}if(M.length===0)return nn(r,[]);let S=1/0,y=1/0,x=1/0,A=-1/0,I=-1/0,R=-1/0;for(let z of M)for(let T of z.vertices)T[0]<S&&(S=T[0]),T[0]>A&&(A=T[0]),T[1]<y&&(y=T[1]),T[1]>I&&(I=T[1]),T[2]<x&&(x=T[2]),T[2]>R&&(R=T[2]);let E=Math.max(A-S,I-y,R-x),O=E>0?o/E:1,w=z=>Math.round(z*1e3)/1e3,D=z=>[w((z[0]-S)*O+t),w((z[1]-y)*O+t),w((z[2]-x)*O+t)],L=M.map(({vertices:z,color:T})=>({vertices:z.map(D),color:T}));return{polygons:L,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:L.length,sourceBytes:r,voxelCount:p.length}}}function vs(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 nn(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var Ua="#888888";var Ba=/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/,Xe="COLOR=";function Ts(e,n,o){let t=n??o;if(!Number.isFinite(t))throw new Error(`parseStl: ${e} must be finite`);return t}function ja(e,n,o){let t=Ts(e,n,o);if(t<=0)throw new Error(`parseStl: ${e} must be greater than 0`);return t}function Ha(e){if(e===void 0||e==="z"||e==="y")return e??"z";throw new Error('parseStl: upAxis must be "z" or "y"')}function qa(e){let n=e??Ua;if(typeof n!="string"||n.trim().length===0)throw new Error("parseStl: defaultColor must be a non-empty string");return n}function Xa(e){if(typeof e=="string")return null;if(e instanceof Uint8Array)return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new Error("parseStl: source must be an ArrayBuffer, Uint8Array, or ASCII string")}function Is(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Ot(e,n){return[e.getFloat32(n,!0),e.getFloat32(n+4,!0),e.getFloat32(n+8,!0)]}function Tt(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Ss(e){let n=e.trim().split(/\s+/);if(n.length!==3||!n.every(t=>Ba.test(t)))return null;let o=[Number(n[0]),Number(n[1]),Number(n[2])];return Tt(o)?o:null}function Wa(e){let n="";for(let t of e)t!==0&&(n+=t>=32&&t<=126?String.fromCharCode(t):" ");return n.replace(/\s+/g," ").trim()||void 0}function zo(e){return Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")}function ws(e,n,o,t=255){if(t>=255)return`#${zo(e)}${zo(n)}${zo(o)}`;let r=Math.round(t/255*1e3)/1e3;return`rgba(${e}, ${n}, ${o}, ${r})`}function Eo(e){return Math.round(e/31*255)}function Ya(e){for(let n=0;n<80-Xe.length-4;n+=1){let o=!0;for(let c=0;c<Xe.length;c+=1)if(e.getUint8(n+c)!==Xe.charCodeAt(c)){o=!1;break}if(!o)continue;let t=e.getUint8(n+Xe.length),r=e.getUint8(n+Xe.length+1),s=e.getUint8(n+Xe.length+2),i=e.getUint8(n+Xe.length+3);return{defaultColor:ws(t,r,s,i),alpha:Math.round(i/255*1e3)/1e3,alphaByte:i}}return null}function Ka(e,n){if((e&32768)!==0)return{color:n.defaultColor,usesDefaultColor:!0};let o=Eo(e&31),t=Eo(e>>5&31),r=Eo(e>>10&31);return{color:ws(o,t,r,n.alphaByte),usesDefaultColor:!1}}function Za(e){let n=[],o=/^\s*solid(?:\s+([^\r\n]*?))?\s*$/gim,t=/^\s*endsolid\b[^\r\n]*$/gim,r;for(;r=o.exec(e);)n.push({index:r.index,kind:"start",name:(r[1]??"").trim()});for(;r=t.exec(e);)n.push({index:r.index,kind:"end"});return n.sort((s,i)=>s.index-i.index||(s.kind==="end"?-1:1))}function Qa(e){let n=Math.min(e.byteLength,1024);for(let o=84;o<n;o+=1){let t=e[o];if(t===0||t<9||t>13&&t<32||t>126)return!0}return!1}function Ja(e){let n=Is(e.subarray(0,Math.min(e.byteLength,512))).trimStart().toLowerCase();return!n.startsWith("solid")&&!n.startsWith("facet")?!1:!Qa(e)}function el(e){if(e.byteLength<84)return null;let o=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0),t=84+o*50;if(t===e.byteLength)return{triangleCount:o,declaredTriangleCount:o,trailingBytes:0};if(Ja(e))return null;if(t<e.byteLength)return{triangleCount:o,declaredTriangleCount:o,trailingBytes:e.byteLength-t};let r=e.byteLength-84;return r>0&&r%50===0?{triangleCount:r/50,declaredTriangleCount:o,trailingBytes:0}:null}function nl(e,n,o){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),{triangleCount:r,declaredTriangleCount:s,trailingBytes:i}=n;s!==r&&o.push(`parseStl: binary STL declared ${s} triangles but contains ${r} complete triangle record${r===1?"":"s"}`),i>0&&o.push(`parseStl: ignored ${i} trailing binary byte${i===1?"":"s"}`);let c=Wa(e.subarray(0,80)),a=Ya(t),l=0,u=0,f=[];for(let d=0,m=84;d<r;d+=1,m+=50){let p=Ot(t,m),g=[Ot(t,m+12),Ot(t,m+24),Ot(t,m+36)];if(!g.every(Tt))throw new Error(`parseStl: non-finite coordinate in binary triangle ${d}`);let b=t.getUint16(m+48,!0),P=a?Ka(b,a):null;P&&(P.usesDefaultColor?u+=1:l+=1),f.push({normal:Tt(p)?p:null,hasIgnoredNormal:!Tt(p),color:P?.color,vertices:g,hasIgnoredAttribute:!a&&b!==0})}return{format:"binary",facets:f,binaryHeader:c,color:a?{format:"magics",defaultColor:a.defaultColor,alpha:a.alpha,coloredTriangleCount:l,defaultColorTriangleCount:u}:void 0}}function Os(e,n){let o=[],t=/^\s*facet\s+normal\s+([^\r\n]+)([\s\S]*?)^\s*endfacet\b[^\r\n]*$/gim,r=/^\s*vertex\s+([^\r\n]+)/gim,s=/^\s*facet\s+normal\b/gim,i=Za(e),c=0,a,l=0;for(;s.exec(e);)l+=1;let u=0,f=0,d=0,m;for(;m=t.exec(e);){for(u+=1;c<i.length&&i[c].index<m.index;){let C=i[c];a=C.kind==="start"?C.name:void 0,c+=1}let p=Ss(m[1]);p||(d+=1);let g=[],b=!1;r.lastIndex=0;let P;for(;P=r.exec(m[2]);){let C=Ss(P[1]);if(!C){b=!0;break}g.push(C)}if(b||g.length!==3){f+=1;continue}o.push({normal:p,hasIgnoredNormal:!p,solidName:a,vertices:[g[0],g[1],g[2]]})}return f+=Math.max(0,l-u),f>0&&n.push(`parseStl: skipped ${f} malformed ASCII facet${f===1?"":"s"}`),d>0&&n.push(`parseStl: ignored ${d} malformed ASCII facet normal${d===1?"":"s"}`),{format:"ascii",facets:o}}function tn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function wt(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 Ro(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function zs(e){return Math.hypot(e[0],e[1],e[2])}function tl(e){let n=wt(tn(e[1],e[0]),tn(e[2],e[0]));return zs(n)<=1e-8}function It(e){let n=zs(e);return n<=1e-8?null:[e[0]/n,e[1]/n,e[2]/n]}function ol(e){let n=o=>Object.is(o,-0)?0:o;return`${n(e[0])},${n(e[1])},${n(e[2])}`}function rl(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function ko(e,n){return n?[e.vertices[0],e.vertices[2],e.vertices[1]]:e.vertices}function sl(e,n,o){let t=0;for(let r of n.facets){let[s,i,c]=ko(e[r],o[r]);t+=Ro(s,wt(i,c))/6}return t}function cl(e,n,o){if(n.facets.length<8)return null;let t=0,r=0;for(let i of n.facets){let c=e[i],a=c.normal?It(c.normal):null;if(!a)continue;let l=ko(c,o[i]),u=It(wt(tn(l[1],l[0]),tn(l[2],l[0])));if(!u)continue;let f=Ro(u,a);f>=.95?t+=1:f<=-.95&&(r+=1)}let s=t+r;return s/n.facets.length<.75?null:r/s>=.9?"opposed":t/s>=.9?"aligned":null}function il(e){let n=new Map,o=e.map(()=>[]);for(let u=0;u<e.length;u+=1){let f=e[u].vertices.map(ol);for(let d=0;d<3;d+=1){let m=f[d],p=f[(d+1)%3],g=rl(m,p),b=n.get(g),P={facetIndex:u,from:m,to:p};b?b.push(P):n.set(g,[P])}}let t=0;for(let u of n.values()){if(u.length>2&&(t+=1),u.length<2)continue;let[f,...d]=u;for(let m of d){let p=f.from===m.from&&f.to===m.to;o[f.facetIndex].push({to:m.facetIndex,flipDiffers:p}),o[m.facetIndex].push({to:f.facetIndex,flipDiffers:p})}}let r=new Array(e.length).fill(!1),s=new Array(e.length).fill(-1),i=[],c=0;for(let u=0;u<e.length;u+=1){if(s[u]>=0)continue;let f=i.length,d={facets:[],conflicts:0,boundaryEdges:0,nonManifoldEdges:0,flippedOutward:!1,flippedToSuppliedNormals:!1};i.push(d),s[u]=f;let m=[u];for(let p=0;p<m.length;p+=1){let g=m[p];d.facets.push(g);for(let b of o[g]){let P=r[g]!==b.flipDiffers;s[b.to]<0?(s[b.to]=f,r[b.to]=P,m.push(b.to)):r[b.to]!==P&&g<b.to&&(d.conflicts+=1,c+=1)}}}for(let u of n.values()){let f=i[s[u[0].facetIndex]];u.length===1?f.boundaryEdges+=1:u.length>2&&(f.nonManifoldEdges+=1)}for(let u of i){if(u.nonManifoldEdges>0||u.conflicts>0){for(let d of u.facets)r[d]=!1;continue}if(u.boundaryEdges>0){if(cl(e,u,r)==="opposed"){for(let d of u.facets)r[d]=!r[d];u.flippedToSuppliedNormals=!0}continue}if(sl(e,u,r)<-1e-10){for(let d of u.facets)r[d]=!r[d];u.flippedOutward=!0}}let a=0;return{facets:e.map((u,f)=>r[f]?(a+=1,{...u,vertices:ko(u,!0)}):u),repairedCount:a,componentCount:i.length,outwardComponentCount:i.filter(u=>u.flippedOutward).length,suppliedNormalComponentCount:i.filter(u=>u.flippedToSuppliedNormals).length,conflictCount:c,nonManifoldEdgeCount:t}}function al(e,n,o,t,r){let s=i=>Math.round(i*1e3)/1e3;return r==="y"?[s((e[2]-n[2])*o+t),s((e[0]-n[0])*o+t),s((e[1]-n[1])*o+t)]:[s((e[0]-n[0])*o+t),s((e[1]-n[1])*o+t),s((e[2]-n[2])*o+t)]}function ll(e){if(e.every(r=>r.solidName===void 0))return;let n=[],o=e[0]?.solidName??"",t=0;for(let r=1;r<=e.length;r+=1){let s=e[r]?.solidName??"";r<e.length&&s===o||(n.push({name:o,start:t,count:r-t}),o=s,t=r)}return n}function ul(e){if(!e)return;let n=[],o=new Set;for(let t of e)!t.name||o.has(t.name)||(o.add(t.name),n.push(t.name));return n.length>0?n:void 0}function zt(e,n){let o=ja("targetSize",n?.targetSize,60),t=Ts("gridShift",n?.gridShift,1),r=qa(n?.defaultColor),s=Ha(n?.upAxis),i=[],c=Xa(e),a=typeof e=="string"?e.length:c.byteLength;if(a===0||typeof e=="string"&&e.trim().length===0)throw new Error("parseStl: empty input");let l=c?el(c):null,u=typeof e=="string"?Os(e,i):l?nl(c,l,i):Os(Is(c),i),f=0,d=0,m=0,p=[];for(let y of u.facets){if(y.hasIgnoredAttribute&&(f+=1),y.hasIgnoredNormal&&u.format==="binary"&&(d+=1),tl(y.vertices)){m+=1;continue}p.push(y)}let g=il(p),b=0;for(let y of g.facets){let x=It(wt(tn(y.vertices[1],y.vertices[0]),tn(y.vertices[2],y.vertices[0]))),A=y.normal?It(y.normal):null;x&&A&&Ro(x,A)<.95&&(b+=1)}if(f>0&&i.push(`parseStl: ignored non-zero binary attribute byte count on ${f} triangle${f===1?"":"s"}`),d>0&&i.push(`parseStl: ignored ${d} non-finite binary normal${d===1?"":"s"}`),m>0&&i.push(`parseStl: skipped ${m} degenerate triangle${m===1?"":"s"}`),g.repairedCount>0&&i.push(`parseStl: repaired winding on ${g.repairedCount} triangle${g.repairedCount===1?"":"s"}`),g.outwardComponentCount>0&&i.push(`parseStl: oriented ${g.outwardComponentCount} closed component${g.outwardComponentCount===1?"":"s"} outward`),g.suppliedNormalComponentCount>0&&i.push(`parseStl: oriented ${g.suppliedNormalComponentCount} open component${g.suppliedNormalComponentCount===1?"":"s"} from supplied normals`),g.conflictCount>0&&i.push(`parseStl: found ${g.conflictCount} inconsistent shared-edge winding constraint${g.conflictCount===1?"":"s"}`),g.nonManifoldEdgeCount>0&&i.push(`parseStl: found ${g.nonManifoldEdgeCount} non-manifold shared edge${g.nonManifoldEdgeCount===1?"":"s"}`),b>0&&i.push(`parseStl: ${b} supplied normal${b===1?" disagrees":"s disagree"} with triangle winding`),p.length===0)throw u.facets.length===0?new Error(`parseStl: no valid ${u.format} facets`):new Error("parseStl: no valid facets after filtering");let P=[1/0,1/0,1/0],C=[-1/0,-1/0,-1/0];for(let y of g.facets)for(let x of y.vertices)for(let A=0;A<3;A+=1)x[A]<P[A]&&(P[A]=x[A]),x[A]>C[A]&&(C[A]=x[A]);let v=Math.max(C[0]-P[0],C[1]-P[1],C[2]-P[2]),V=v>0?o/v:1,h=ll(g.facets),M=ul(h),S=g.facets.map(y=>({vertices:y.vertices.map(x=>al(x,P,V,t,s)),color:y.color??r}));return{polygons:S,objectUrls:[],dispose:()=>{},warnings:i,metadata:{triangleCount:S.length,meshes:M,materials:[],sourceBytes:a,stlHeader:u.binaryHeader,stlColor:u.color,stlSolids:h,stlTopology:{componentCount:g.componentCount,repairedTriangleCount:g.repairedCount,outwardComponentCount:g.outwardComponentCount,suppliedNormalComponentCount:g.suppliedNormalComponentCount,inconsistentSharedEdgeCount:g.conflictCount,nonManifoldSharedEdgeCount:g.nonManifoldEdgeCount}}}}var Oe="loadMesh";function Et(e,n){let o=ft(e.polygons,{meshResolution:n?.meshResolution});return o.length===e.polygons.length?e:{...e,polygons:o}}async function Es(e,n){let o=n?.solidTextureSamples;return o===!1?e:At(e,typeof o=="object"?o:void 0)}function fl(e){let n=e.split("?")[0].split("#")[0],o=n.lastIndexOf(".");return o<0?"":n.slice(o+1).toLowerCase()}async function Rs(e,n){let o=fl(e);if(o==="mtl")throw new Error(`${Oe}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let t=globalThis.fetch;if(!t)throw new Error(`${Oe}: no fetch() in this environment`);let r=n?.baseUrl??e;if(o==="obj"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.text(),c=n?.objOptions;if(n?.mtlUrl){let l=await t(n.mtlUrl);if(!l.ok)throw new Error(`${Oe}: ${n.mtlUrl} \u2192 ${l.status}`);let u=await l.text(),{colors:f,textures:d}=Pt(u),m={},p=globalThis.URL,g=globalThis.document?.baseURI,b=n.mtlUrl;if(p&&g)try{b=new p(n.mtlUrl,g).toString()}catch{}for(let[P,C]of Object.entries(d)){if(p)try{m[P]=new p(C,b).toString();continue}catch{}let v=n.mtlUrl.lastIndexOf("/"),V=v>=0?n.mtlUrl.slice(0,v+1):"";m[P]=C.startsWith("/")||/^https?:\/\//.test(C)?C:V+C}c={...c??{},materialColors:{...f,...c?.materialColors??{}},materialTextures:{...m,...c?.materialTextures??{}}}}let a=xt(i,c);return Et(await Es(a,n),n)}if(o==="glb"||o==="gltf"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),c=vt(i,{baseUrl:r,...n?.gltfOptions??{}});return Et(await Es(c,n),n)}if(o==="vox"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return Et(St(i,n?.voxOptions),n)}if(o==="stl"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return Et(zt(i,n?.stlOptions),n)}throw new Error(`${Oe}: unsupported extension ".${o}" (supported: obj, glb, gltf, vox, stl)`)}function ks(e,n,o,t,r=.5,s=.5,i=.4){let c=4/(e[2]+3),a=Math.min(n,o)*i,l=n*r+e[0]*a*t*c,u=o*s-e[1]*a*c;return[l,u,e[2]]}function ml(e){let[n,o,t]=[e.vertices[0],e.vertices[1],e.vertices[2]],r=o[0]-n[0],s=o[1]-n[1],i=o[2]-n[2],c=t[0]-n[0],a=t[1]-n[1],l=t[2]-n[2];return[s*l-i*a,i*c-r*l,r*a-s*c]}function dl(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 Ds(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 pl(e,n=0){if(n<=0){let i=new Set,c=[];for(let a of e){let l=[[0,1],[1,2],[2,0]];for(let[u,f]of l){let d=a.vertices[u],m=a.vertices[f],p=Ds(d,m);if(i.has(p))continue;i.add(p);let g={from:d,to:m,weight:2};a.color&&(g.color=a.color),c.push(g)}}return c}let o=Math.cos(n*Math.PI/180),t=new Map,r=[[0,1],[1,2],[2,0]];for(let i of e){let c=ml(i);for(let[a,l]of r){let u=i.vertices[a],f=i.vertices[l],d=Ds(u,f),m=t.get(d);m?m.normals.push(c):t.set(d,{normals:[c],from:u,to:f,color:i.color})}}let s=[];for(let{normals:i,from:c,to:a,color:l}of t.values()){if(i.length<2){let f={from:c,to:a,weight:2};l&&(f.color=l),s.push(f);continue}let u=!1;e:for(let f=0;f<i.length;f++)for(let d=f+1;d<i.length;d++)if(dl(i[f],i[d])<o){u=!0;break e}if(u){let f={from:c,to:a,weight:2};l&&(f.color=l),s.push(f)}}return s}function Ls(e,n=0){return pl(e,n)}0&&(module.exports={BASE_TILE,CAMERA_BACKFACE_CULL_EPS,DEFAULT_CAMERA_STATE,DEFAULT_PROJECTION,LoopOnce,LoopPingPong,LoopRepeat,QUAT_IDENTITY,VOXEL_CAMERA_CULL_AXIS_EPS,VOXEL_CAMERA_CULL_NORMAL_LIMIT,antiprismPolygons,arrowPolygons,axesHelperPolygons,bakeSolidTextureSampledPolygons,bakeSolidTextureSamples,bipyramidPolygons,buildSceneContext,buildTextureSamplers,cameraCullNormalGroups,cameraCullNormalGroupsFromPolygons,cameraCullNormalKey,cameraCullVisibleSignature,cameraFacingDepth,clampChannel,computeSceneBbox,computeShapeLighting,conePolygons,coverPlanarPolygons,createGlyphAnimationMixer,createIsometricCamera,cubePolygons,cuboctahedronPolygons,cullInteriorPolygons,cylinderPolygons,dedupeOverlappingPolygons,deltoidalHexecontahedronPolygons,deltoidalIcositetrahedronPolygons,disdyakisDodecahedronPolygons,disdyakisTriacontahedronPolygons,dodecahedronPolygons,eulerXYZFromQuat,findOverlappingPolygonDuplicates,formatColor,greatDodecahedronPolygons,greatIcosahedronPolygons,greatStellatedDodecahedronPolygons,icosahedronPolygons,icosidodecahedronPolygons,inverseRotateVec3,isAxisAlignedSurfaceNormal,isVoxelCameraCullableNormalGroups,loadMesh,mergePolygons,normalFacesCamera,normalizeInvertMultiplier,normalizePolygons,octahedronPolygons,optimizeMeshPolygons,parseColor,parseGltf,parseHexColor,parseMtl,parseObj,parsePureColor,parseRgbColor,parseStl,parseVox,pentagonalHexecontahedronPolygons,pentagonalIcositetrahedronPolygons,pentakisDodecahedronPolygons,planePolygons,polygonCssSurfaceNormal,polygonFaces,polygonFacesCamera,polygonTexture,prismPolygons,project,pyramidPolygons,quatFromAxisAngle,quatFromEulerXYZ,quatMultiply,resolveGeometry,rhombicDodecahedronPolygons,rhombicTriacontahedronPolygons,rhombicosidodecahedronPolygons,rhombicuboctahedronPolygons,ringPolygons,ringQuadPolygons,rotateVec3,sampleTexel,shadeColor,smallStellatedDodecahedronPolygons,snubCubePolygons,snubDodecahedronPolygons,spherePolygons,tetrahedronPolygons,tetrakisHexahedronPolygons,torusPolygons,trapezohedronPolygons,triakisIcosahedronPolygons,triakisOctahedronPolygons,triakisTetrahedronPolygons,trianglesToFeatureEdges,truncatedCubePolygons,truncatedCuboctahedronPolygons,truncatedDodecahedronPolygons,truncatedIcosahedronPolygons,truncatedIcosidodecahedronPolygons,truncatedOctahedronPolygons,truncatedTetrahedronPolygons});
1
+ "use strict";var jt=Object.defineProperty;var _s=Object.getOwnPropertyDescriptor;var Gs=Object.getOwnPropertyNames;var $s=Object.prototype.hasOwnProperty;var Fs=(e,n)=>{for(var o in n)jt(e,o,{get:n[o],enumerable:!0})},Us=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Gs(n))!$s.call(e,r)&&r!==o&&jt(e,r,{get:()=>n[r],enumerable:!(t=_s(n,r))||t.enumerable});return e};var Bs=e=>Us(jt({},"__esModule",{value:!0}),e);var yl={};Fs(yl,{BASE_TILE:()=>rr,CAMERA_BACKFACE_CULL_EPS:()=>yn,DEFAULT_CAMERA_STATE:()=>we,DEFAULT_PROJECTION:()=>No,LoopOnce:()=>Qr,LoopPingPong:()=>es,LoopRepeat:()=>Jr,QUAT_IDENTITY:()=>Zo,VOXEL_CAMERA_CULL_AXIS_EPS:()=>mo,VOXEL_CAMERA_CULL_NORMAL_LIMIT:()=>po,antiprismPolygons:()=>Tn,arrowPolygons:()=>Mo,axesHelperPolygons:()=>Po,bakeSolidTextureSampledPolygons:()=>Ms,bakeSolidTextureSamples:()=>St,bipyramidPolygons:()=>In,buildSceneContext:()=>Wo,buildTextureSamplers:()=>Vs,cameraCullNormalGroups:()=>ho,cameraCullNormalGroupsFromPolygons:()=>Xr,cameraCullNormalKey:()=>yo,cameraCullVisibleSignature:()=>Yr,cameraFacingDepth:()=>go,clampChannel:()=>Me,computeSceneBbox:()=>et,computeShapeLighting:()=>Bo,conePolygons:()=>vn,coverPlanarPolygons:()=>st,createGlyphAnimationMixer:()=>ns,createIsometricCamera:()=>cr,cubePolygons:()=>xn,cuboctahedronPolygons:()=>ke,cullInteriorPolygons:()=>ve,cylinderPolygons:()=>Cn,dedupeOverlappingPolygons:()=>tt,deltoidalHexecontahedronPolygons:()=>Hn,deltoidalIcositetrahedronPolygons:()=>jn,disdyakisDodecahedronPolygons:()=>Un,disdyakisTriacontahedronPolygons:()=>Bn,dodecahedronPolygons:()=>Pn,eulerXYZFromQuat:()=>nr,findOverlappingPolygonDuplicates:()=>Zt,formatColor:()=>on,greatDodecahedronPolygons:()=>En,greatIcosahedronPolygons:()=>kn,greatStellatedDodecahedronPolygons:()=>Rn,icosahedronPolygons:()=>Mn,icosidodecahedronPolygons:()=>De,inverseRotateVec3:()=>Ko,isAxisAlignedSurfaceNormal:()=>bo,isVoxelCameraCullableNormalGroups:()=>Wr,loadMesh:()=>ks,mergePolygons:()=>ae,normalFacesCamera:()=>bt,normalizeInvertMultiplier:()=>sr,normalizePolygons:()=>Jn,octahedronPolygons:()=>hn,optimizeMeshPolygons:()=>mt,parseColor:()=>Ie,parseGltf:()=>At,parseHexColor:()=>Ht,parseMtl:()=>Mt,parseObj:()=>Pt,parsePureColor:()=>Kn,parseRgbColor:()=>qt,parseStl:()=>Et,parseVox:()=>Ot,pentagonalHexecontahedronPolygons:()=>Xn,pentagonalIcositetrahedronPolygons:()=>qn,pentakisDodecahedronPolygons:()=>Fn,planePolygons:()=>vo,polygonCssSurfaceNormal:()=>ht,polygonFaces:()=>Yo,polygonFacesCamera:()=>qr,polygonTexture:()=>vs,prismPolygons:()=>On,project:()=>Ds,pyramidPolygons:()=>Sn,quatFromAxisAngle:()=>Jo,quatFromEulerXYZ:()=>er,quatMultiply:()=>Qo,recenterPolygons:()=>Xo,resolveGeometry:()=>Ao,rhombicDodecahedronPolygons:()=>Dn,rhombicTriacontahedronPolygons:()=>Ln,rhombicosidodecahedronPolygons:()=>je,rhombicuboctahedronPolygons:()=>Be,ringPolygons:()=>Vo,ringQuadPolygons:()=>Co,rotateVec3:()=>rn,sampleTexel:()=>Cs,shadeColor:()=>Uo,smallStellatedDodecahedronPolygons:()=>zn,snubCubePolygons:()=>He,snubDodecahedronPolygons:()=>qe,spherePolygons:()=>Vn,tetrahedronPolygons:()=>bn,tetrakisHexahedronPolygons:()=>Gn,torusPolygons:()=>An,trapezohedronPolygons:()=>wn,triakisIcosahedronPolygons:()=>$n,triakisOctahedronPolygons:()=>_n,triakisTetrahedronPolygons:()=>Nn,trianglesToFeatureEdges:()=>Ns,truncatedCubePolygons:()=>Ne,truncatedCuboctahedronPolygons:()=>Fe,truncatedDodecahedronPolygons:()=>Ge,truncatedIcosahedronPolygons:()=>$e,truncatedIcosidodecahedronPolygons:()=>Ue,truncatedOctahedronPolygons:()=>_e,truncatedTetrahedronPolygons:()=>Le});module.exports=Bs(yl);var No="cubic";function Ht(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 qt(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 Kn(e){if(!e)return null;let n=e.trim(),o=Ht(n);return o||qt(n)}function Me(e){return Math.max(0,Math.min(255,Math.round(e)))}function on(e){let[n,o,t]=e.rgb.map(Me);return e.alpha<1?`rgba(${n}, ${o}, ${t}, ${e.alpha})`:`rgb(${n}, ${o}, ${t})`}var Wt={rgb:[204,204,204],alpha:1},_o=new Map;function Ie(e){if(!e)return null;let n=e.trim(),o=_o.get(n);if(o)return o;let t=Kn(n);return t?(_o.set(n,t),t):null}function Uo(e,n){let o=Ie(e)??Wt,t=[Me(o.rgb[0]+n),Me(o.rgb[1]+n),Me(o.rgb[2]+n)];return on({rgb:t,alpha:o.alpha})}var Xt={direction:[0,0,-1],color:"#ffffff",intensity:1},Go={color:"#ffffff",intensity:.4};function $o(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 Fo(e,n,o){let t=Ie(n)??Wt;return e*(t.rgb[o]/255)}function Bo(e,n,o,t){let r=Ie(n)??Wt,s=$o(o?.direction??Xt.direction),i=o?.color??Xt.color,c=Math.max(0,o?.intensity??Xt.intensity),a=t?.color??Go.color,l=Math.max(0,t?.intensity??Go.intensity),u=$o(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),d=c*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],b=Fo(g,a,p)*l,P=Fo(g,i,p)*d;m[p]=Me(b+P)}return on({rgb:m,alpha:r.alpha})}var jo="#cccccc",Zn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Ho=(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]],qo=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Qn=e=>Math.hypot(e[0],e[1],e[2]);function js(e){let n=1/0,o=1/0,t=1/0,r=-1/0,s=-1/0,i=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<o&&(o=u[1]),u[1]>s&&(s=u[1]),u[2]<t&&(t=u[2]),u[2]>i&&(i=u[2]);let c=r-n,a=s-o,l=i-t;return Math.hypot(c,a,l)}function Hs(){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 Jn(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 s=r.vertices;if(s.length<3){o.push(`Polygon ${t}: ${s.length} vertices (need >= 3), dropped`);continue}let i=Zn(s[1],s[0]),c=Zn(s[2],s[0]),a=Ho(i,c),l=Qn(a);if(s.length===3){if(l<1e-12){Qn(i)<1e-12||Qn(c)<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:s.slice()}];if(s.length>=4){let f=[a[0]/l,a[1]/l,a[2]/l],d=qo(f,s[0]),m=js(s),p=Math.max(1e-6,m*.001),g=0;for(let b=3;b<s.length;b++){let P=Math.abs(qo(f,s[b])-d);P>g&&(g=P)}if(g>p){let b=[],P=r.uvs&&r.uvs.length===s.length?r.uvs:void 0;for(let C=1;C<s.length-1;C++){let v=[s[0].slice(),s[C].slice(),s[C+1].slice()],V=Ho(Zn(v[1],v[0]),Zn(v[2],v[0]));if(Qn(V)<1e-12)continue;let h={...r,vertices:v};P&&(h.uvs=[P[0].slice(),P[C].slice(),P[C+1].slice()]),b.push(h)}if(b.length===0){o.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}o.push(`Polygon ${t}: ${s.length} non-coplanar vertices, fan-triangulated to ${b.length} triangles`),u=b}}for(let f of u){let d=qs(f,t,o);d&&n.push(d)}}return{polygons:n,warnings:o}}function qs(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&&Hs()&&o.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Ie(e.color)?t.color=e.color:(o.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${jo}`),t.color=jo)),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 s={},i=!1;for(let c of Object.keys(e.data)){let a=e.data[c];typeof a=="string"||typeof a=="number"||typeof a=="boolean"?s[c]=a:(i=!0,o.push(`Polygon ${n}: data["${c}"] has non-primitive value, key dropped`))}Object.keys(s).length>0&&(t.data=s)}return t}function et(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,s=-1/0,i=-1/0,c=!1;for(let a of e)if(a?.vertices)for(let l of a.vertices)l&&(c=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<o&&(o=l[1]),l[1]>s&&(s=l[1]),l[2]<t&&(t=l[2]),l[2]>i&&(i=l[2]));return c?{min:[n,o,t],max:[r,s,i]}:{min:[0,0,0],max:[0,0,0]}}function Xo(e){if(!e||e.length===0)return e;let n=et(e),o=(n.min[0]+n.max[0])/2,t=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;return o===0&&t===0&&r===0?e:e.map(s=>({...s,vertices:s.vertices.map(i=>[i[0]-o,i[1]-t,i[2]-r])}))}function Wo(e){let n=e.polygons??[],o,t;if(e.skipNormalize)o=n,t=[];else{let c=Jn(n);o=c.polygons,t=c.warnings}let r=et(o),s=[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:s},warnings:t}}function Yo(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function rn(e,n,o,t){let r=n*Math.PI/180,s=o*Math.PI/180,i=t*Math.PI/180,[c,a,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[c,a]=[c*u-a*f,c*f+a*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[c,l]=[c*u+l*f,-c*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[a,l]=[a*u-l*f,a*f+l*u]}return[c,a,l]}function Ko(e,n){let o=-n[0]*Math.PI/180,t=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[s,i,c]=e;if(o!==0){let a=Math.cos(o),l=Math.sin(o);[i,c]=[i*a-c*l,i*l+c*a]}if(t!==0){let a=Math.cos(t),l=Math.sin(t);[s,c]=[s*a+c*l,-s*l+c*a]}if(r!==0){let a=Math.cos(r),l=Math.sin(r);[s,i]=[s*a-i*l,s*l+i*a]}return[s,i,c]}var Yt=Math.PI/180,sn=180/Math.PI,Zo=[1,0,0,0];function Qo(e,n){let[o,t,r,s]=e,[i,c,a,l]=n;return[o*i-t*c-r*a-s*l,o*c+t*i+r*l-s*a,o*a-t*l+r*i+s*c,o*l+t*a-r*c+s*i]}function Jo(e,n){let o=n*.5,t=Math.sin(o);return[Math.cos(o),e[0]*t,e[1]*t,e[2]*t]}function er(e){let n=e[0]*Yt,o=e[1]*Yt,t=e[2]*Yt,r=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(o*.5),c=Math.sin(o*.5),a=Math.cos(t*.5),l=Math.sin(t*.5);return[r*i*a-s*c*l,s*i*a+r*c*l,r*c*a-s*i*l,r*i*l+s*c*a]}function nr(e){let[n,o,t,r]=e,s=2*(o*r+n*t),i=2*(t*r-n*o),c=1-2*(o*o+t*t),a=2*(o*t-n*r),l=1-2*(t*t+r*r),u=Math.max(-1,Math.min(1,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,c)*sn,f*sn,Math.atan2(-a,l)*sn]:[Math.atan2(2*(t*r+n*o),1-2*(o*o+r*r))*sn,f*sn,0]}var rr=50;function sr(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var we={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},tr=100,or=1e4,Ke=e=>Math.round(e*tr)/tr,Xs=e=>Math.round(e*or)/or;function cr(e={}){let n={target:e.target??[...we.target],rotX:e.rotX??we.rotX,rotY:e.rotY??we.rotY,zoom:e.zoom??we.zoom,distance:e.distance??we.distance};function o(r){r.target!==void 0&&(n.target=[Ke(r.target[0]),Ke(r.target[1]),Ke(r.target[2])]),r.rotX!==void 0&&(n.rotX=Ke(r.rotX)),r.rotY!==void 0&&(n.rotY=Ke(r.rotY)),r.zoom!==void 0&&(n.zoom=Xs(r.zoom)),r.distance!==void 0&&(n.distance=Ke(r.distance))}function t(r={}){let i=(r.cols??0)*50,c=(r.rows??0)*50,[a,l,u]=n.target,f=l*50,d=a*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-d}px, ${-m}px)`,width:`${i}px`,height:`${c}px`}}return{state:n,update:o,getStyle:t}}var Ce=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],nt=(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]],cn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Kt=e=>Math.hypot(e[0],e[1],e[2]),Ve=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function Ws(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 ar(e){if(e.length<3)return null;let n=Ce(e[1],e[0]),o=Ce(e[2],e[0]),t=nt(n,o),r=Kt(t);if(r<1e-12)return null;let s=[t[0]/r,t[1]/r,t[2]/r],i=cn(s,e[0]);return{normal:s,d:i}}function Ys(e,n){return cn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function Ks(e,n){return cn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function Zs(e,n,o,t){let r=e.vertices.findIndex(y=>Ve(y,o)),s=e.vertices.findIndex(y=>Ve(y,t)),i=n.vertices.findIndex(y=>Ve(y,o)),c=n.vertices.findIndex(y=>Ve(y,t));if(r<0||s<0||i<0||c<0)return null;let a=e.vertices.length,l=n.vertices.length,u=(r+1)%a===s,f=(i+1)%l===c;if(u===f)return null;let d=u?s:r,m=u?r:s,p=f?c:i,g=f?i:c,b=!!(e.uvs&&n.uvs),P=[],C=b?[]:void 0,v=d;for(;P.push(e.vertices[v]),C&&C.push(e.uvs[v]),v!==m;)v=(v+1)%a;for(v=p;P.push(n.vertices[v]),C&&C.push(n.uvs[v]),v!==g;)v=(v+1)%l;let V=[],h=C?[]:void 0;for(let y=0;y<P.length;y++)(V.length===0||!Ve(P[y],V[V.length-1]))&&(V.push(P[y]),h&&C&&h.push(C[y]));if(V.length>1&&Ve(V[0],V[V.length-1])&&(V.pop(),h?.pop()),b)return ir(V,h);let M=[],S=h?[]:void 0;for(let y=0;y<V.length;y++){let x=V[(y-1+V.length)%V.length],A=V[y],I=V[(y+1)%V.length],R=nt(Ce(A,x),Ce(I,x));Kt(R)>1e-9&&(M.push(A),S&&h&&S.push(h[y]))}return M.length<3?null:ir(M,S)}function Qs(e,n){let o=e.length,t=0;for(let r=0;r<o;r++){let s=e[r],i=e[(r+1)%o],c=e[(r+2)%o],a=Ce(i,s),l=Ce(c,i),u=cn(nt(a,l),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 Js(e,n){if(e.length<3)return!1;let o=ar(e);if(!o)return!1;for(let t of e)if(Math.abs(cn(o.normal,t)-o.d)>n)return!1;return!0}function ec(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function nc(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 ir(e,n){for(let o=0;o<e.length;o++){let t=e[o],r=e[(o+1)%e.length],s=e[(o+2)%e.length];if(!(Kt(nt(Ce(r,t),Ce(s,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 ae(e){let n=[],o=[];for(let r of e??[]){if(!r||!r.vertices||r.vertices.length<3){r&&n.push(r);continue}let s=r.vertices.map(l=>[l[0],l[1],l[2]]),i=ar(s);if(!i){n.push(r);continue}let c=r.texture&&r.uvs&&r.uvs.length===s.length?r.uvs.map(l=>[l[0],l[1]]):void 0,a=r.texture&&c?r.textureTriangles?.length?ec(r.textureTriangles):nc(s,c):void 0;o.push({vertices:s,uvs:c,color:r.color??"#cccccc",texture:r.texture,textureTriangles:a,normal:i.normal,d:i.d,alive:!0,data:r.data})}let t=()=>{let r=new Map;for(let c=0;c<o.length;c++){let a=o[c];if(!a.alive)continue;let l=a.vertices.length;for(let u=0;u<l;u++){let f=a.vertices[u],d=a.vertices[(u+1)%l],m=Ws(f,d),p=r.get(m);p||(p=[],r.set(m,p)),p.push(c)}}let s=!1,i=(c,a)=>{for(let l=0;l<c.vertices.length;l++){let u=c.vertices[l],f=c.vertices[(l+1)%c.vertices.length];for(let d=0;d<a.vertices.length;d++){let m=a.vertices[d],p=a.vertices[(d+1)%a.vertices.length];if(Ve(u,p)&&Ve(f,m))return[u,f]}}return null};for(let[,c]of r){if(c.length<2)continue;let[a,l]=c;if(a===l)continue;let u=o[a],f=o[l];if(!u.alive||!f.alive||u.color!==f.color||u.texture!==f.texture)continue;let d=!!(u.texture||f.texture);if(d&&(!u.textureTriangles||!f.textureTriangles)||!!u.uvs!=!!f.uvs||(d?!Ks(u,f):!Ys(u,f)))continue;let m=i(u,f);if(!m)continue;let[p,g]=m,b=Zs(u,f,p,g);b&&Js(b.vertices,.001)&&Qs(b.vertices,u.normal)&&(u.vertices=b.vertices,u.uvs=b.uvs,u.textureTriangles=d?[...u.textureTriangles??[],...f.textureTriangles??[]]:void 0,f.alive=!1,s=!0)}return s};for(;t(););for(let r of o){if(!r.alive)continue;let s={vertices:r.vertices,color:r.color};r.texture&&(s.texture=r.texture),r.uvs&&(s.uvs=r.uvs),r.textureTriangles?.length&&(s.textureTriangles=r.textureTriangles),r.data&&(s.data=r.data),n.push(s)}return n}var tc=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],oc=(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 rc(e,n){let o=e.vertices;if(!o||o.length<3)return null;let t=0,r=0,s=0;for(let g=0;g<o.length;g++){let b=o[g],P=o[(g+1)%o.length];t+=(b[1]-P[1])*(b[2]+P[2]),r+=(b[2]-P[2])*(b[0]+P[0]),s+=(b[0]-P[0])*(b[1]+P[1])}let i=Math.hypot(t,r,s);if(i<1e-12)return null;let c=[t/i,r/i,s/i],a=0,l=0,u=0;for(let g of o)a+=g[0],l+=g[1],u+=g[2];let f=1/o.length,d=[a*f,l*f,u*f],m=ye(c,d),p=i*.5;return{index:n,polygon:e,normal:c,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function sc(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),s=Math.hypot(o,t,r);o/=s,t/=s,r/=s;let i=[o,t,r],c=oc(e,i);return{u:i,v:c}}function cc(e){if(e.local2D)return;let n=sc(e.normal),o=[],t=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.polygon.vertices){let a=ye(c,n.u),l=ye(c,n.v);o.push([a,l]),a<t&&(t=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}e.local2D=o,e.bbox2D={min:[t,r],max:[s,i]},e.basis=n}function ic(e,n){let o=[],t=1/0,r=1/0,s=-1/0,i=-1/0;for(let c of e.vertices){let a=ye(c,n.u),l=ye(c,n.v);o.push([a,l]),a<t&&(t=a),a>s&&(s=a),l<r&&(r=l),l>i&&(i=l)}return{local2D:o,bbox2D:{min:[t,r],max:[s,i]}}}function ac(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 lr(e,n){let o=!1;for(let t=0,r=n.length-1;t<n.length;r=t++){let s=n[t],i=n[r];s[1]>e[1]!=i[1]>e[1]&&e[0]<(i[0]-s[0])*(e[1]-s[1])/(i[1]-s[1]+1e-30)+s[0]&&(o=!o)}return o}function ur(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 lc(e,n){let o=ur(e),t=ur(n),r=1e-4,s=0;for(let l of e){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];lr(u,n)&&s++}let i=0;for(let l of n){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];lr(u,e)&&i++}let c=s/e.length,a=i/n.length;return Math.max(c,a)}function uc(e,n){let o=e.normal[0],t=e.normal[1],r=e.normal[2],s=Math.abs(o),i=Math.abs(t),c=Math.abs(r),a=o;i>s&&i>c?a=t:c>s&&c>i&&(a=r),a<0&&(o=-o,t=-t,r=-r);let l=Math.round(o/.05),u=Math.round(t/.05),f=Math.round(r/.05),d=e.d*(e.normal[0]===o&&e.normal[1]===t&&e.normal[2]===r?1:-1),m=Math.round(d/(n*2));return`${l},${u},${f}|${m}`}function fc(e,n,o,t){let r=ye(e.normal,n.normal);if(Math.abs(r)<1-o)return!1;let s=r>0?1:-1;return Math.abs(e.d-s*n.d)<t}function fr(e,n){let o=tc(n,e.centroid);return ye(e.normal,o)>0}function Zt(e,n){if(!e||e.length<2)return new Set;let o=n?.normalTolerance??.001,t=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,s=[];for(let m=0;m<e.length;m++){let p=rc(e[m],m);p&&s.push(p)}if(s.length<2)return new Set;let i=0,c=0,a=0,l=0;for(let m of s)i+=m.centroid[0]*m.area,c+=m.centroid[1]*m.area,a+=m.centroid[2]*m.area,l+=m.area;let u=l>0?[i/l,c/l,a/l]:[0,0,0],f=new Map;for(let m of s){let p=uc(m,t),g=f.get(p);g||(g=[],f.set(p,g)),g.push(m)}let d=new Set;for(let m of f.values())if(!(m.length<2))for(let p=0;p<m.length;p++){let g=m[p];if(!d.has(g.index))for(let b=p+1;b<m.length;b++){let P=m[b];if(d.has(P.index)||!fc(g,P,o,t))continue;cc(g);let C=ic(P.polygon,g.basis);if(!ac(g.bbox2D,C.bbox2D)||lc(g.local2D,C.local2D)<r)continue;let V=fr(g,u),h=fr(P,u),M;if(V&&!h?M=g:h&&!V?M=P:M=g.area<P.area?g:P,d.add(M.index),M===g)break}}return d}function tt(e,n){if(!e||e.length<2)return e??[];let o=Zt(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 mc=4,dc=8,pc=.001,gc=1e-9,yc=1e6,hc=1e6,ze=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],eo=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],un=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],Ee=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],yr=(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]],hr=e=>Math.hypot(e[0],e[1],e[2]);function fn(e){let n=hr(e);return n<=gc?null:[e[0]/n,e[1]/n,e[2]/n]}function ln(e,n){return Math.round(e*n)/n}function pe(e){return ln(e,yc)}function Qt(e){return ln(e,hc)}function Jt(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 bc(e){let n=be(e.a),o=be(e.b);return n<o?`${n}|${o}`:`${o}|${n}`}function Ze(e){return`${e[0]},${e[1]},${e[2]}`}function br(e,n){let o=Ze(e),t=Ze(n);return o<t?`${o}|${t}`:`${t}|${o}`}function no(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function mr(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",no(e.data)].join("|")}function xr(e){let n=e.vertices;if(!n||n.length<3)return null;let o=n[0],t=[0,0,0];for(let s=1;s<n.length-1;s++)t=eo(t,yr(ze(n[s],o),ze(n[s+1],o)));let r=fn(t);return r?{normal:r,d:Ee(r,o)}:null}function xc(e,n,o){return Ee(e.normal,n.normal)>1-o&&Math.abs(e.d-n.d)<=o}function Pc(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function Mc(e,n){let o=n[e[0]]?.data,t=no(o);for(let r of e)if(no(n[r].data)!==t)return;return o?{...o}:void 0}function Vc(e,n){let o=e.map(a=>Pc(a)?xr(a):null),t=o.map(Boolean),r=new Map;for(let a=0;a<e.length;a++){if(!o[a])continue;let l=e[a].vertices;for(let u=0;u<l.length;u++){let f=br(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:a,edge:u};d?d.push(m):r.set(f,[m])}}let s=e.map(()=>new Set);for(let a of r.values())if(!(a.length<2))for(let l=0;l<a.length;l++)for(let u=l+1;u<a.length;u++){let f=a[l].polygon,d=a[u].polygon,m=o[f],p=o[d];!m||!p||mr(e[f])===mr(e[d])&&xc(m,p,n)&&(s[f].add(d),s[d].add(f))}let i=new Set,c=[];for(let a=0;a<e.length;a++){if(!t[a]||i.has(a))continue;let l=[],u=[a];for(i.add(a);u.length>0;){let f=u.shift();l.push(f);for(let d of s[f])i.has(d)||(i.add(d),u.push(d))}c.push(l)}return{groups:c}}function Cc(e,n){let o=new Set(e),t=new Map;for(let s of e){let i=n[s].vertices;for(let c=0;c<i.length;c++){let a=br(i[c],i[(c+1)%i.length]),l=t.get(a),u={polygon:s,edge:c};l?l.push(u):t.set(a,[u])}}let r=[];for(let s of t.values()){let i=s.filter(c=>o.has(c.polygon));if(i.length===1){let c=i[0],a=n[c.polygon].vertices;r.push({a:a[c.edge],b:a[(c.edge+1)%a.length]})}else if(i.length!==2)return null}return r}function vc(e){let n=new Map;for(let o of e)n.set(Ze(o.a),(n.get(Ze(o.a))??0)+1),n.set(Ze(o.b),(n.get(Ze(o.b))??0)+1);for(let o of n.values())if(o%2!==0)return!1;return!0}function Pr(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 Ac(e){let n=Pr(e);return`${ln(n[0],1e3)},${ln(n[1],1e3)},${ln(n[2],1e3)}`}function Sc(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],o=ze(n,un(e,Ee(n,e)));return fn(o)??[1,0,0]}function Oc(e,n,o){let t=new Map;for(let s of e){let i=ze(s.b,s.a),c=ze(i,un(n,Ee(i,n))),a=fn(c);if(!a)continue;let l=Pr(a),u=Ac(l),f=hr(c),d=t.get(u);d?d.weight+=f:t.set(u,{axis:l,weight:f})}let r=[...t.values()].sort((s,i)=>i.weight-s.weight).slice(0,o).map(s=>s.axis);return r.length===0&&r.push(Sc(n)),r}function dr(e,n,o,t){let r=ze(e,n);return[pe(Ee(r,o)),pe(Ee(r,t))]}function Tc(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 an(e,n){let[o,t]=e.a,[r,s]=e.b,i=(n-o)/(r-o);return pe(t+(s-t)*i)}function to(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],s=n[t],i=n[(t+1)%n.length],c=(s[0]-r[0])*(i[1]-s[1])-(s[1]-r[1])*(i[0]-s[0]);Math.abs(c)>1e-8&&o.push(s)}return o}function rt(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 pr(e){let n=1/0,o=1/0,t=-1/0,r=-1/0;for(let[s,i]of e)n=Math.min(n,s),o=Math.min(o,i),t=Math.max(t,s),r=Math.max(r,i);return{minX:n,minY:o,maxX:t,maxY:r}}function Ic(e,n){let o=pr(e),t=pr(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 ot(e){return Math.abs(rt(e))}function wc(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],s=e[(o+2)%e.length],i=(r[0]-t[0])*(s[1]-r[1])-(r[1]-t[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-8)continue;let c=i>0?1:-1;if(n===0)n=c;else if(n!==c)return!1}return!0}function zc(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],c=t*i-r*s,a=Math.hypot(t,r);if(a<=1e-9||Math.abs(c)>Math.max(1e-8,a*1e-8))return!1;let l=s*t+i*r;return l>=-1e-8&&l<=t*t+r*r+1e-8}function Ec(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],s=t*t+r*r;return s<=1e-12?0:((e[0]-n[0])*t+(e[1]-n[1])*r)/s}function gr(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t],s=e[(t+1)%e.length],i=[{t:0,point:r},{t:1,point:s}];for(let a of n)Jt(a,r)||Jt(a,s)||zc(a,r,s)&&i.push({t:Ec(a,r,s),point:a});i.sort((a,l)=>a.t-l.t);let c=[];for(let a of i)c.some(l=>Math.abs(l.t-a.t)<=1e-8||Jt(l.point,a.point))||c.push(a);for(let a=0;a<c.length-1;a++){let l=c[a].point,u=c[a+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||o.push({a:[pe(l[0]),pe(l[1])],b:[pe(u[0]),pe(u[1])]})}}return o}function Rc(e,n){if(!Ic(e,n))return null;let o=[...gr(e,n),...gr(n,e)],t=new Map;for(let g of o){let b=bc(g),P=t.get(b);P?P.push(g):t.set(b,[g])}let r=!1,s=[];for(let g of t.values()){if(g.length===1){s.push(g[0]);continue}r=!0;let b=g.filter(C=>be(C.a)<be(C.b)).length,P=g.length-b;if(b!==P)return null}if(!r||s.length<3)return null;let i=new Map;for(let g of s){let b=be(g.a);if(i.has(b))return null;i.set(b,g)}let c=s[0],a=be(c.a),l=[],u=new Set,f=a;for(let g=0;g<=s.length;g++){let b=i.get(f);if(!b)return null;let P=`${be(b.a)}>${be(b.b)}`;if(u.has(P))return null;if(u.add(P),l.push(b.a),f=be(b.b),f===a)break}if(f!==a||u.size!==s.length)return null;let d=to(l);if(d.length<3||!wc(d))return null;let m=ot(d),p=ot(e)+ot(n);return Math.abs(m-p)>Math.max(1e-5,p*1e-5)?null:rt(d)>=0?d:[...d].reverse()}function kc(e){let n=e.map(to).filter(t=>t.length>=3&&ot(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 s=Rc(n[t],n[r]);if(s){n[t]=s,n.splice(r,1),o=!0;break}}if(o)break}}return n}function Dc(e,n,o){let t=new Map;return r=>{let s=pe(r[0]),i=pe(r[1]),c=`${s},${i}`,a=t.get(c);if(a)return[a[0],a[1],a[2]];let l=eo(e,eo(un(n,s),un(o,i))),u=[Qt(l[0]),Qt(l[1]),Qt(l[2])];return t.set(c,u),[u[0],u[1],u[2]]}}function Lc(e,n,o,t,r){let s=o[0]?.a;if(!s)return null;let i=fn(ze(r,un(t,Ee(r,t))));if(!i)return null;let c=fn(yr(t,i));if(!c)return null;let a=[],l=[];for(let b of o){let P=dr(b.a,s,i,c),C=dr(b.b,s,i,c);Math.hypot(P[0]-C[0],P[1]-C[1])<=1e-7||(a.push({a:P,b:C}),l.push(P[0],C[0]))}let u=Tc(l);if(a.length<3||u.length<2)return null;let f=n[e[0]].color,d=Mc(e,n),m=[];for(let b=0;b<u.length-1;b++){let P=u[b],C=u[b+1];if(C-P<=1e-7)continue;let v=(P+C)/2,V=a.filter(h=>{let M=Math.min(h.a[0],h.b[0]),S=Math.max(h.a[0],h.b[0]);return M<v&&v<S&&Math.abs(h.a[0]-h.b[0])>1e-7}).map(h=>({segment:h,yMid:an(h,v)})).sort((h,M)=>h.yMid-M.yMid);if(V.length!==0){if(V.length%2!==0)return null;for(let h=0;h<V.length;h+=2){let M=V[h].segment,S=V[h+1].segment,y=an(M,P),x=an(M,C),A=an(S,P),I=an(S,C),R=to([[P,y],[C,x],[C,I],[P,A]]);if(R.length<3||Math.abs(rt(R))<=1e-8)continue;let E=rt(R)>0?R:[...R].reverse();m.push(E)}}}if(m.length===0)return null;let p=Dc(s,i,c),g=kc(m).map(b=>({vertices:b.map(p),...f?{color:f}:{},...d?{data:d}:{}}));return ae(g)}function Nc(e,n,o){let t=Cc(e,n);if(!t||t.length<3||!vc(t))return null;let r=xr(n[e[0]]);if(!r)return null;let s=null;for(let i of Oc(t,r.normal,o)){let c=Lc(e,n,t,r.normal,i);c&&(!s||c.length<s.length)&&(s=c)}return!s||s.length>=e.length?null:s}function st(e,n={}){let o=n.minGroupPolygons??mc,t=n.maxCandidateAxes??dc,r=n.planeEpsilon??pc,s=e??[];if(s.length<o)return s;let{groups:i}=Vc(s,r);if(i.length===0)return s;let c=new Map,a=new Set;for(let u of i){if(u.length<o)continue;let f=Nc(u,s,t);if(f){c.set(u[0],f);for(let d of u)a.add(d)}}if(c.size===0)return s;let l=[];for(let u=0;u<s.length;u++){let f=c.get(u);if(f){l.push(...f);continue}a.has(u)||l.push(s[u])}return l}function _c(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0;for(let[E,O,w]of n)o+=E,t+=O,r+=w;let s=1/n.length;o*=s,t*=s,r*=s;let i=n[0],c=n[1],a=n[2],l=c[0]-i[0],u=c[1]-i[1],f=c[2]-i[2],d=a[0]-i[0],m=a[1]-i[1],p=a[2]-i[2],g=u*p-f*m,b=f*d-l*p,P=l*m-u*d,C=Math.hypot(g,b,P);if(C<1e-9)return null;g/=C,b/=C,P/=C;let v=n.length-2,V=new Float64Array(v*9),h=0;for(let E=1;E<n.length-1;E++){let O=n[0],w=n[E],D=n[E+1];V[h++]=O[0],V[h++]=O[1],V[h++]=O[2],V[h++]=w[0],V[h++]=w[1],V[h++]=w[2],V[h++]=D[0],V[h++]=D[1],V[h++]=D[2]}let M=0,S=1/0,y=1/0,x=1/0,A=-1/0,I=-1/0,R=-1/0;for(let[E,O,w]of n){let D=E-o,L=O-t,z=w-r,T=D*D+L*L+z*z;T>M&&(M=T),E<S&&(S=E),E>A&&(A=E),O<y&&(y=O),O>I&&(I=O),w<x&&(x=w),w>R&&(R=w)}return{centroid:[o,t,r],normal:[g,b,P],vertices:n,triFlat:V,bcx:o,bcy:t,bcz:r,br2:M,minX:S,minY:y,minZ:x,maxX:A,maxY:I,maxZ:R}}function Gc(e,n,o,t,r,s,i,c){let a=i[c],l=i[c+1],u=i[c+2],f=i[c+3]-a,d=i[c+4]-l,m=i[c+5]-u,p=i[c+6]-a,g=i[c+7]-l,b=i[c+8]-u,P=r*b-s*g,C=s*p-t*b,v=t*g-r*p,V=f*P+d*C+m*v;if(V>-1e-9&&V<1e-9)return!1;let h=1/V,M=e-a,S=n-l,y=o-u,x=h*(M*P+S*C+y*v);if(x<0||x>1)return!1;let A=S*m-y*d,I=y*f-M*m,R=M*d-S*f,E=h*(t*A+r*I+s*R);return E<0||x+E>1?!1:h*(p*A+g*I+b*R)>.001}function $c(e,n,o,t,r,s,i){let c=i.bcx-e,a=i.bcy-n,l=i.bcz-o,u=c*t+a*r+l*s,f=c-u*t,d=a-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,g=p.length;for(let b=0;b<g;b+=9)if(Gc(e,n,o,t,r,s,p,b))return!0;return!1}var mn=9,Fc=6,se=12;function oo(e,n,o,t,r,s){let i=t-e,c=r-n,a=s-o;return i*c+c*a+a*i}function Uc(e){let n=[];for(let M=0;M<e.length;M++)e[M]&&n.push(M);let o=n.length,t=new Int32Array(o);for(let M=0;M<o;M++)t[M]=n[M];let r=new Float64Array(o),s=new Float64Array(o),i=new Float64Array(o);for(let M=0;M<o;M++){let S=e[t[M]];r[M]=(S.minX+S.maxX)*.5,s[M]=(S.minY+S.maxY)*.5,i[M]=(S.minZ+S.maxZ)*.5}let c=2*Math.max(1,o)+1,a=new Float64Array(c*mn),l=0,u=new Float64Array(se),f=new Float64Array(se),d=new Float64Array(se),m=new Float64Array(se),p=new Float64Array(se),g=new Float64Array(se),b=new Int32Array(se),P=new Float64Array(se-1),C=new Int32Array(se-1),v=new Float64Array(se-1),V=new Int32Array(se-1);function h(M,S){let y=l++,x=y*mn,A=S-M,I=1/0,R=1/0,E=1/0,O=-1/0,w=-1/0,D=-1/0;for(let X=M;X<S;X++){let K=e[t[X]];K.minX<I&&(I=K.minX),K.maxX>O&&(O=K.maxX),K.minY<R&&(R=K.minY),K.maxY>w&&(w=K.maxY),K.minZ<E&&(E=K.minZ),K.maxZ>D&&(D=K.maxZ)}if(a[x]=I,a[x+1]=R,a[x+2]=E,a[x+3]=O,a[x+4]=w,a[x+5]=D,A<=Fc)return a[x+6]=1,a[x+7]=M,a[x+8]=S,y;let L=1/0,z=1/0,T=1/0,k=-1/0,N=-1/0,G=-1/0;for(let X=M;X<S;X++)r[X]<L&&(L=r[X]),r[X]>k&&(k=r[X]),s[X]<z&&(z=s[X]),s[X]>N&&(N=s[X]),i[X]<T&&(T=i[X]),i[X]>G&&(G=i[X]);let _=k-L,$=N-z,F=G-T;if(_===0&&$===0&&F===0)return a[x+6]=1,a[x+7]=M,a[x+8]=S,y;let H=oo(I,R,E,O,w,D),j=H>0?1/H:0,U=A+1,B=0,q=0;for(let X=0;X<3;X++){let K=X===0?L:X===1?z:T,le=X===0?_:X===1?$:F;if(le===0)continue;let Pe=X===0?r:X===1?s:i,Te=se/le;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),g.fill(-1/0),b.fill(0);for(let W=M;W<S;W++){let Y=(Pe[W]-K)*Te|0;Y>=se&&(Y=se-1);let ue=e[t[W]];ue.minX<u[Y]&&(u[Y]=ue.minX),ue.maxX>m[Y]&&(m[Y]=ue.maxX),ue.minY<f[Y]&&(f[Y]=ue.minY),ue.maxY>p[Y]&&(p[Y]=ue.maxY),ue.minZ<d[Y]&&(d[Y]=ue.minZ),ue.maxZ>g[Y]&&(g[Y]=ue.maxZ),b[Y]++}let We=1/0,Ye=1/0,kt=1/0,Dt=-1/0,Lt=-1/0,Nt=-1/0,Do=0;for(let W=0;W<se-1;W++)u[W]<We&&(We=u[W]),m[W]>Dt&&(Dt=m[W]),f[W]<Ye&&(Ye=f[W]),p[W]>Lt&&(Lt=p[W]),d[W]<kt&&(kt=d[W]),g[W]>Nt&&(Nt=g[W]),Do+=b[W],P[W]=oo(We,Ye,kt,Dt,Lt,Nt),C[W]=Do;let _t=1/0,Gt=1/0,$t=1/0,Ft=-1/0,Ut=-1/0,Bt=-1/0,Lo=0;for(let W=se-2;W>=0;W--){let Y=W+1;u[Y]<_t&&(_t=u[Y]),m[Y]>Ft&&(Ft=m[Y]),f[Y]<Gt&&(Gt=f[Y]),p[Y]>Ut&&(Ut=p[Y]),d[Y]<$t&&($t=d[Y]),g[Y]>Bt&&(Bt=g[Y]),Lo+=b[Y],v[W]=oo(_t,Gt,$t,Ft,Ut,Bt),V[W]=Lo}for(let W=0;W<se-1;W++){if(C[W]===0||V[W]===0)continue;let Y=.125+(P[W]*C[W]+v[W]*V[W])*j;Y<U&&(U=Y,B=X,q=K+(W+1)/Te)}}let Z=B===0?r:B===1?s:i,J=M,ne=S-1;for(;J<=ne;)if(Z[J]<q)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 le=s[J];s[J]=s[ne],s[ne]=le;let Pe=i[J];i[J]=i[ne],i[ne]=Pe,ne--}let ie=J;(ie===M||ie===S)&&(ie=M+S>>1),a[x+6]=0;let oe=h(M,ie),Q=h(ie,S);return a[y*mn+7]=oe,a[y*mn+8]=Q,y}return o>0&&h(0,o),{data:a,nodeCount:l,polyIndices:t,meta:e}}function Mr(e,n,o,t,r,s,i,c,a){if(c.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=c,d=t!==0?1/t:t>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=s!==0?1/s:s>=0?1/0:-1/0,g=0;for(a[g++]=0;g>0;){let P=a[--g]*mn,C=(l[P]-e)*d,v=(l[P+3]-e)*d,V=C<v?C:v,h=C<v?v:C,M=(l[P+1]-n)*m,S=(l[P+4]-n)*m,y=M<S?M:S,x=M<S?S:M;if(V>x||y>h)continue;y>V&&(V=y),x<h&&(h=x);let A=(l[P+2]-o)*p,I=(l[P+5]-o)*p,R=A<I?A:I,E=A<I?I:A;if(!(V>E||R>h)&&(E<h&&(h=E),!(h<.001)))if(l[P+6]===1){let O=l[P+7]|0,w=l[P+8]|0;for(let D=O;D<w;D++){let L=u[D];if(L===i)continue;let z=f[L];if(z&&$c(e,n,o,t,r,s,z))return!0}}else a[g++]=l[P+7]|0,a[g++]=l[P+8]|0}return!1}function Bc(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,s=Math.sqrt(Math.max(0,1-r*r)),i=2*Math.PI*(t/n);o[t*3]=s*Math.cos(i),o[t*3+1]=s*Math.sin(i),o[t*3+2]=r}return o}function jc(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],s=n*e[1]-o*e[0],i=Math.hypot(t,r,s);t/=i,r/=i,s/=i;let c=e[1]*s-e[2]*r,a=e[2]*t-e[0]*s,l=e[0]*r-e[1]*t;return{ux:t,uy:r,uz:s,vx:c,vy:a,vz:l}}function ve(e,n){let o=n?.samples??8;if(e.length<4||o<1)return e;let t=e.map(_c),r=Bc(o),s=[],i=Uc(t),c=new Int32Array(Math.max(64,i.nodeCount)),a=192,l=new Float64Array(a);for(let u=0;u<e.length;u++){let f=t[u];if(!f){s.push(e[u]);continue}let d=f.normal[0],m=f.normal[1],p=f.normal[2],g=.001*d,b=.001*m,P=.001*p;{let w=f.centroid[0]+g,D=f.centroid[1]+b,L=f.centroid[2]+P;if(!Mr(w,D,L,d,m,p,u,i,c)){s.push(e[u]);continue}}let{ux:C,uy:v,uz:V,vx:h,vy:M,vz:S}=jc(f.normal),y=f.centroid[0],x=f.centroid[1],A=f.centroid[2],I=f.vertices,R=I.length,E=0;l[E++]=y+g,l[E++]=x+b,l[E++]=A+P;for(let w=0;w<R;w++){let D=I[w];l[E++]=D[0]+(y-D[0])*.08+g,l[E++]=D[1]+(x-D[1])*.08+b,l[E++]=D[2]+(A-D[2])*.08+P}for(let w=0;w<R;w++){let D=I[w],L=I[(w+1)%R],z=(D[0]+L[0])*.5,T=(D[1]+L[1])*.5,k=(D[2]+L[2])*.5;l[E++]=z+(y-z)*.08+g,l[E++]=T+(x-T)*.08+b,l[E++]=k+(A-k)*.08+P}let O=!1;e:for(let w=0;w<r.length;w+=3){let D=r[w],L=r[w+1],z=r[w+2],T=D*C+L*h+z*d,k=D*v+L*M+z*m,N=D*V+L*S+z*p;for(let G=0;G<E;G+=3){let _=l[G],$=l[G+1],F=l[G+2];if(!Mr(_,$,F,T,k,N,u,i,c)){O=!0;break e}}}O&&s.push(e[u])}return s}var Hc=3,qc=.03,Xc=.02,dn={maxAngleDeg:Hc,maxPlaneDisplacement:qc,maxBoundaryDisplacement:Xc,isolatedPairs:!1},Qe={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725,isolatedPairs:!0},it=[{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.02},{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725},{maxAngleDeg:45,maxPlaneDisplacement:1,maxBoundaryDisplacement:.0725}],Wc=[2,4,6,8,12],Yc=300,Kc=.3,Zc=300,Qc=16,Jc=.015,Vr=2.6,ei=3,ni=96,Re={minGroupPolygons:2,maxCandidateAxes:24},ti={maxGap:0,internalBoundaryLength:0,excessBoundaryLength:0};function mt(e,n={}){let o=n.meshResolution??"lossy",t=ro(e,!1),r={baseline:t},s=t,i=ce(t),c=(l,u=ce(l))=>u>=i?!1:(s=l,i=u,!0),a=ct(t,n.rectCover);if(a!==t&&c(a),o==="lossy"&&n.approximateMerge!==!1){let l=pi(e),u=[],f=he(l,s,Qe.maxBoundaryDisplacement).metrics,d=n.approximateMerge===void 0||n.approximateMerge===!0,m=(C,v=!0)=>!mi(l,C.metrics,C.tolerance,v?f:null),p=(C,v)=>{c(C,v)},g=(C,v,V=Qe.maxBoundaryDisplacement)=>{!d||v>i+Or(i)||u.push({polygons:C,cost:v,maxBoundaryDisplacement:V})},b=Cr(n.approximateMerge,d?t:void 0);for(let C=0;C<b.length;C++){let v=b[C],V=ro(e,v,r),h=ce(V),M=null,S=()=>(M??(M=he(l,V,v.maxBoundaryDisplacement)),M),y=!0;if(d||v.guard){let E=S();y=m(E,!!v.allowReferenceCracks)}if(!y&&h<i)continue;y&&(p(V,h),g(V,h,v.maxBoundaryDisplacement));let x=ct(V,n.rectCover),A=ce(x),I=null,R=()=>(I??(I=he(l,x,v.maxBoundaryDisplacement)),I);if(x!==V&&A<i){let E=!0;(d||v.guard)&&(E=m(R(),!!v.allowReferenceCracks)),E&&(p(x,A),g(x,A,v.maxBoundaryDisplacement))}}if(d)for(let C of oi(e)){let v={baseline:ae(ve(C))},V=ce(v.baseline),h=!0,M=null,S=()=>(M??(M=he(l,v.baseline,Qe.maxBoundaryDisplacement)),M);V<i&&(h=m(S())),h&&(p(v.baseline,V),g(v.baseline,V));let y=ct(v.baseline,n.rectCover);if(y!==v.baseline){let x=ce(y);(x>=i||m(he(l,y,Qe.maxBoundaryDisplacement)))&&(p(y,x),g(y,x))}for(let x of Cr(n.approximateMerge,v.baseline)){let A=ro(C,x,v),I=ce(A),R=null,E=()=>(R??(R=he(l,A,x.maxBoundaryDisplacement)),R),O=!0;if(d||x.guard){let T=E();O=m(T,!!x.allowReferenceCracks)}if(!O&&I<i)continue;O&&(p(A,I),g(A,I,x.maxBoundaryDisplacement));let w=ct(A,n.rectCover),D=ce(w),L=null,z=()=>(L??(L=he(l,w,x.maxBoundaryDisplacement)),L);if(w!==A&&D<i){let T=!0;(d||x.guard)&&(T=m(z(),!!x.allowReferenceCracks)),T&&(p(w,D),g(w,D,x.maxBoundaryDisplacement))}}}if(d)for(let C of it){let v=Rr({...C,isolatedPairs:!0}),V=Oi(s,v);if(V===s)continue;let h=ce(V);if(h>=i)continue;let M=he(l,V,v.maxBoundaryDisplacement);m(M)&&(p(V,h),g(V,h,v.maxBoundaryDisplacement))}let P=li(u,s,i,C=>(C.metrics??(C.metrics=he(l,C.polygons,C.maxBoundaryDisplacement).metrics),C.metrics),()=>he(l,s,Qe.maxBoundaryDisplacement).metrics);P&&(s=P.polygons,i=P.cost)}return s}function oi(e){let n=ri(e);if(n.eligiblePolygons<24||n.colorCount<8)return[];let o=[],t=new Set;for(let r of Wc){let s=si(e,r,n.colorCount);if(!s)continue;let i=ii(s);t.has(i)||(t.add(i),o.push(s))}return o}function ri(e){let n=new Set,o=0;for(let t of e)t.texture||t.material?.texture||t.uvs||t.textureTriangles?.length||Sr(t.color)&&(o+=1,n.add(t.color??"#cccccc"));return{eligiblePolygons:o,colorCount:n.size}}function si(e,n,o){let t=!1,r=new Set,s=e.map(i=>{if(i.texture||i.material?.texture||i.uvs||i.textureTriangles?.length)return i;let c=Sr(i.color);if(!c)return i;let a=ci([Math.round(c[0]/n)*n,Math.round(c[1]/n)*n,Math.round(c[2]/n)*n]);return r.add(a),a===i.color?i:(t=!0,{...i,color:a})});return!t||r.size>=o?null:s}function Sr(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 ci(e){return`#${e.map(n=>Math.max(0,Math.min(255,Math.round(n))).toString(16).padStart(2,"0")).join("")}`}function ii(e){return e.map(n=>n.color??"").join("|")}function Cr(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&&ai(n))return[{...it[0],isolatedPairs:!0,guard:!1,allowReferenceCracks:!0}];let o=[],t=new Set,r=n&&n.length>Zc?[!0]:[!0,!1];for(let s=0;s<it.length;s++){let i=it[s];for(let c of r){let a={...i,isolatedPairs:c,guard:s>0||c===!1,allowReferenceCracks:!0},l=[a.maxAngleDeg,a.maxPlaneDisplacement,a.maxBoundaryDisplacement,a.isolatedPairs].join("|");t.has(l)||(t.add(l),o.push(a))}}return o.length===0?[{...Qe,guard:!1}]:o}function ai(e){return e.length<Yc?!1:zr(e)/e.length<=Kc}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,s=o.texture||o.material?.texture||o.textureTriangles?.length?.15:0;n+=1+r+s}return n}function Or(e){return Math.max(Qc,e*Jc)}function li(e,n,o,t,r){if(e.length===0)return null;let s=Or(o),i=e.find(u=>u.polygons===n),c=null,a=null,l=null;for(let u of e){if(u.polygons===n||u.cost>o+s)continue;let f=t(u);c??(c=i?t(i):r()),fi(f,c)&&(!a||!l||ui(u,f,a,l)<0)&&(a=u,l=f)}return a}function ui(e,n,o,t){return n.maxGap-t.maxGap||n.internalBoundaryLength-t.internalBoundaryLength||n.excessBoundaryLength-t.excessBoundaryLength||e.cost-o.cost}function fi(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 mi(e,n,o,t=null){if(!t)return n.internalBoundaryLength>0||n.excessBoundaryLength>o;let r=Math.max(o*.1,1e-6),s=t.maxGap+r,i=o<=.08?Math.max(s,Math.min(o*.75,.04)):s,c=Math.max(o*2,t.internalBoundaryLength*.15),a=Math.max(o*2,t.excessBoundaryLength*.15);return n.maxGap>i||n.internalBoundaryLength>t.internalBoundaryLength+c||n.excessBoundaryLength>t.excessBoundaryLength+a}function di(e,n,o=0,t=co(e,o)){let r=e.edges,s=Tr(n),i=co(e,o),c=t>0?yi(e,t):null,a={...ti,excessBoundaryLength:Math.max(0,s.boundaryLength-r.boundaryLength)};for(let l of s.boundarySegments){let u=Je(l.a,l.b);if(r.boundaryKeys.has(u))continue;if(r.internalKeys.has(u)){a.internalBoundaryLength+=xe(l.a,l.b);continue}let f=c?xi(l,c,t):null;f!==null&&(a.maxGap=Math.max(a.maxGap,f),a.internalBoundaryLength+=xe(l.a,l.b))}return{metrics:a,tolerance:i}}function he(e,n,o=0){return di(e,n,o,gi(e,o))}function pi(e){let n=hi(e),o=n>0?Math.min(.08,Math.max(.001,n*.001)):0;return{edges:Tr(e),baseTolerance:o,polygonCount:e.length,indexes:new Map}}function co(e,n=0){return Math.max(e.baseTolerance,n*1.05)}function gi(e,n=0){return Math.max(co(e,n),e.baseTolerance*Vr,n*Vr)}function yi(e,n){let o=n.toFixed(6),t=e.indexes.get(o);if(t)return t;let r=bi(e.edges.internalSegments,n);return e.indexes.set(o,r),r}function Tr(e){let n=new Map;for(let c of e)for(let a=0;a<c.vertices.length;a++){let l=c.vertices[a],u=c.vertices[(a+1)%c.vertices.length],f=Je(l,u),d=n.get(f);d?d.count+=1:n.set(f,{count:1,a:l,b:u})}let o=new Set,t=new Set,r=[],s=[],i=0;for(let[c,a]of n){let l={a:a.a,b:a.b};a.count===1?(o.add(c),r.push(l),i+=xe(l.a,l.b)):(t.add(c),s.push(l))}return{boundaryKeys:o,internalKeys:t,boundarySegments:r,internalSegments:s,boundaryLength:i}}function hi(e){let n=1/0,o=1/0,t=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let[a,l,u]of c.vertices)n=Math.min(n,a),o=Math.min(o,l),t=Math.min(t,u),r=Math.max(r,a),s=Math.max(s,l),i=Math.max(i,u);return Number.isFinite(n)?Math.hypot(r-n,s-o,i-t):0}function bi(e,n){let o=Math.max(n*2,1e-6),t=new Map;for(let r of e){let[s,i,c]=Ir(r,o),a=wr(s,i,c),l=t.get(a);l?l.push(r):t.set(a,[r])}return{cellSize:o,cells:t}}function xi(e,n,o){let[t,r,s]=Ir(e,n.cellSize),i=null;for(let c=-1;c<=1;c++)for(let a=-1;a<=1;a++)for(let l=-1;l<=1;l++){let u=n.cells.get(wr(t+c,r+a,s+l));if(u)for(let f of u){let d=Pi(e,f);d<=o&&(i=i===null?d:Math.min(i,d))}}return i}function Ir(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 wr(e,n,o){return`${e},${n},${o}`}function Pi(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 ct(e,n){if(n===!1)return e;let o=Mi(e,n);if(!o)return e;let t=st(e,o);return t.length<e.length?t:e}function Mi(e,n){if(n&&n!==!0)return n;let o=e.length;return o>2200?null:o>1200?{...Re,maxCandidateAxes:Math.min(Re.maxCandidateAxes??24,2)}:o>300&&zr(e)<=ni?{...Re,maxCandidateAxes:Math.min(Re.maxCandidateAxes??24,2)}:o>900?{...Re,maxCandidateAxes:Math.min(Re.maxCandidateAxes??24,4)}:Re}function zr(e){let n=0;for(let o of e)o.vertices.length===3&&(n+=1);return n}function ro(e,n,o){let t=tt(e),r=o?.baseline??ae(ve(t));if(!n)return r;let s=n===!0?dn:Rr(n);if(s.isolatedPairs){let c=Ci(Vi(t,o),s),a=ae(c);return a.length<r.length?a:r}let i=ae(ve(Ni(t,s,o)));return i.length<r.length?i:r}function Er(e,n){return n?(n.snapped||(n.snapped=lt(e)),n.snapped):lt(e)}function Vi(e,n){return n?(n.snappedInterior||(n.snappedInterior=ve(Er(e,n))),n.snappedInterior):ve(lt(e))}function Rr(e){return{maxAngleDeg:e.maxAngleDeg??dn.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??dn.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??dn.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??dn.isolatedPairs}}function Ci(e,n){let o=e.map(f=>{let d=gn(f);return d?{polygon:f,normal:d.normal,area:d.area,materialKey:lo(f)}:null}),t=new Map;for(let f=0;f<e.length;f++){let d=e[f];if(!(d.vertices.length!==3||!o[f]))for(let m=0;m<d.vertices.length;m++){let p=Je(d.vertices[m],d.vertices[(m+1)%d.vertices.length]),g=t.get(p);g?g.push(f):t.set(p,[f])}}let r=[];for(let f of t.values()){if(f.length!==2)continue;let[d,m]=f,p=Li(d,m,e,o,n);p&&r.push(p)}let s=new Set,i=new Map,c=new Set,a=vi(r),l=dt(a.flatMap(f=>f.vertexMoves));for(let f of a){s.add(f.a),s.add(f.b);let d=Math.min(f.a,f.b);i.set(d,f.polygon),c.add(Math.max(f.a,f.b))}let u=[];for(let f=0;f<e.length;f++){let d=i.get(f);if(d){u.push(d);continue}c.has(f)||u.push(e[f])}return l.size>0?pt(u,l):u}function vi(e){return e.length>3e3?Ai(e):Si(e)}function Ai(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 o=[...e].sort((s,i)=>{let c=(n.get(s.a)??0)+(n.get(s.b)??0),a=(n.get(i.a)??0)+(n.get(i.b)??0);return c-a||s.score-i.score}),t=new Set,r=[];for(let s of o)t.has(s.a)||t.has(s.b)||(t.add(s.a),t.add(s.b),r.push(s));return r}function Si(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],f=n.get(u.a);f?f.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let o=[],t=new Array(e.length).fill(!0),r=new Map,s=new io;for(let[l,u]of n)r.set(l,u.length);let i=l=>(r.get(l.a)??0)+(r.get(l.b)??0),c=l=>{let u=e[l];s.push({degree:i(u),score:u.score,index:l})},a=(l,u)=>{if(!t[l])return;t[l]=!1;let f=e[l];for(let d of[f.a,f.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)c(l);for(;s.size()>0;){let l=s.pop();if(!t[l.index])continue;let u=e[l.index];if(i(u)!==l.degree){c(l.index);continue}o.push(u);let d=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])a(p,d);for(let m of d)for(let p of n.get(m)??[])t[p]&&c(p)}return o}var io=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(so(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,s=r+1,i=t;if(r<this.items.length&&so(this.items[r],this.items[i])<0&&(i=r),s<this.items.length&&so(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 so(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function Oi(e,n){let o=e,t=ce(o),r=zi(o);for(let s=0;s<ei;s++){let i=Ti(o,n,r);if(!i)break;let c=ce(i.polygons);if(c>=t)break;o=i.polygons,t=c,r=i.origins}return o===e?e:o}function Ti(e,n,o){let t=e.map(d=>{let m=gn(d);return m?{polygon:d,normal:m.normal,area:m.area,materialKey:lo(d)}:null}),r=new Map;for(let d=0;d<e.length;d++){let m=e[d];if(!(!t[d]||m.vertices.length<3))for(let p=0;p<m.vertices.length;p++){let g=Je(m.vertices[p],m.vertices[(p+1)%m.vertices.length]),b=r.get(g);b?b.push({polygon:d,edge:p}):r.set(g,[{polygon:d,edge:p}])}}let s=[];for(let d of r.values()){if(d.length!==2)continue;let[m,p]=d,g=Ii(m.polygon,m.edge,p.polygon,p.edge,e,t,n);g&&s.push(g)}if(s.length===0)return null;s.sort((d,m)=>m.score-d.score);let i=new Set,c=[];for(let d of s)i.has(d.a)||i.has(d.b)||(i.add(d.a),i.add(d.b),c.push(d));if(c.length===0)return null;let a=dt(c.flatMap(d=>d.vertexMoves));if(!wi(a,o,n.maxBoundaryDisplacement))return null;let l=pt(e,a),u=Ei(e,a,o),f=ae(l);return ce(f)<ce(e)?{polygons:f,origins:Ri(f,u)}:null}function Ii(e,n,o,t,r,s,i){let c=r[e],a=r[o],l=s[e],u=s[o];if(!l||!u||c.vertices.length===3&&a.vertices.length===3||!$r(c,a,l,u))return null;let f=Math.abs(ge(l.normal,u.normal)),d=Math.cos(i.maxAngleDeg*Math.PI/180);if(f<d)return null;let m=vr(c,a,n)??vr(a,c,t);if(!m||m.length<4||m.length>10)return null;let p=Dr(m);if(!p)return null;let g=0,b=0;for(let y of m){let x=Math.abs(gt(y,p));g=Math.max(g,x),b+=x*x}if(g>Math.min(i.maxPlaneDisplacement,i.maxBoundaryDisplacement))return null;let P=m.map(y=>yt(y,p));if(!Lr(P,p.normal))return null;let C=gn({vertices:P});if(!C||ge(C.normal,l.normal)<.2||ge(C.normal,u.normal)<.2)return null;let v=[...m.map((y,x)=>({key:re(y),target:P[x]})),...kr([c,a],p)],V=pt([c,a],dt(v)),h=ce([c,a]),M=ce(ae(V));if(M>=h)return null;let S=h-M-(b/m.length+g*.25+(1-f)*.1);return S<=0?null:{a:e,b:o,vertexMoves:v,score:S}}function vr(e,n,o){let t=e.vertices,r=n.vertices,s=t[o],i=t[(o+1)%t.length],c=-1;for(let u=0;u<r.length;u++)if(Ae(r[u],i)&&Ae(r[(u+1)%r.length],s)){c=u;break}if(c<0)return null;let a=[],l=(o+1)%t.length;for(a.push(t[l]);l!==o;)l=(l+1)%t.length,a.push(t[l]);for(l=(c+2)%r.length;l!==c;){let u=r[l];Ae(u,a[a.length-1])||a.push(u),l=(l+1)%r.length}return a.length>1&&Ae(a[0],a[a.length-1])&&a.pop(),a}function wi(e,n,o){for(let[t,r]of e){let s=ki(t),i=n.get(t)??(s?[s]:[]);if(i.length===0)return!1;for(let c of i)if(xe(c,r)>o+1e-6)return!1}return!0}function zi(e){let n=new Map;for(let o of e){for(let t of o.vertices)at(n,re(t),t);for(let t of o.textureTriangles??[])for(let r of t.vertices)at(n,re(r),r)}return n}function Ei(e,n,o){let t=new Map;for(let r of e){let s=[...r.vertices,...(r.textureTriangles??[]).flatMap(i=>i.vertices)];for(let i of s){let c=re(i),a=n.get(c)??i,l=re(a);for(let u of o.get(c)??[i])at(t,l,u)}}return t}function Ri(e,n){let o=new Map;for(let t of e){let r=[...t.vertices,...(t.textureTriangles??[]).flatMap(s=>s.vertices)];for(let s of r){let i=re(s);for(let c of n.get(i)??[s])at(o,i,c)}}return o}function at(e,n,o){let t=e.get(n);if(!t){e.set(n,[o]);return}let r=re(o);t.some(s=>re(s)===r)||t.push(o)}function ki(e){let n=e.split(",").map(Number);return n.length===3&&n.every(Number.isFinite)?[n[0],n[1],n[2]]:null}function dt(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 Di(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t].vertices,s=n[t]?.vertices;if(!s||s.length!==r.length)continue;for(let a=0;a<r.length;a++)o.push({key:re(r[a]),target:s[a]});let i=e[t].textureTriangles??[],c=n[t]?.textureTriangles??[];for(let a=0;a<i.length;a++){let l=c[a];if(l)for(let u=0;u<i[a].vertices.length;u++)o.push({key:re(i[a].vertices[u]),target:l.vertices[u]})}}return o}function kr(e,n){let o=[];for(let t of e)for(let r of t.textureTriangles??[])for(let s of r.vertices)o.push({key:re(s),target:yt(s,n)});return o}function pt(e,n){return e.map(o=>{let t=!1,r=c=>{let a=n.get(re(c));return a?(t=!0,a):c},s=o.vertices.map(r),i=ao(o.textureTriangles,r);return t?{...o,vertices:s,...i?{textureTriangles:i}:{}}:o})}function Li(e,n,o,t,r){let s=o[e],i=o[n],c=t[e],a=t[n];if(!c||!a||s.vertices.length!==3||i.vertices.length!==3||!$r(s,i,c,a))return null;let l=fo(s,i);if(!l)return null;let[u,f,d,m]=l;if((d+1)%i.vertices.length===m)return null;let g=Math.abs(ge(c.normal,a.normal)),b=Math.cos(r.maxAngleDeg*Math.PI/180);if(g<b)return null;let P=(f+1)%s.vertices.length,C=3-d-m,v=[s.vertices[f],s.vertices[P],s.vertices[u],i.vertices[C]],V=Dr(v);if(!V)return null;let h=0,M=0;for(let A of v){let I=Math.abs(gt(A,V));h=Math.max(h,I),M+=I*I}if(h>Math.min(r.maxPlaneDisplacement,r.maxBoundaryDisplacement))return null;let S=v.map(A=>yt(A,V));if(!Lr(S,V.normal))return null;let y=gn({vertices:S});if(!y||ge(y.normal,c.normal)<.2||ge(y.normal,a.normal)<.2)return null;let x={vertices:v,color:s.color,...s.data?{data:{...s.data}}:{}};if(uo(s,i)&&s.uvs&&i.uvs&&s.texture){x.texture=s.texture,x.uvs=[[...s.uvs[f]],[...s.uvs[P]],[...s.uvs[u]],[...i.uvs[C]]];let A=_i([s,i]);A?.length&&(x.textureTriangles=A)}return{a:e,b:n,polygon:x,vertexMoves:[...v.map((A,I)=>({key:re(A),target:S[I]})),...kr([s,i],V)],score:M/v.length+h*.25+(1-g)*.1}}function Dr(e){if(e.length<3)return null;let n=0,o=0,t=0,r=0,s=0,i=0;for(let a=0;a<e.length;a++){let l=e[a],u=e[(a+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),o+=(l[2]-u[2])*(l[0]+u[0]),t+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],s+=l[1],i+=l[2]}let c=Hr([n,o,t]);return c?{normal:c,point:[r/e.length,s/e.length,i/e.length]}:null}function Lr(e,n){let o=0;for(let t=0;t<e.length;t++){let r=e[t],s=e[(t+1)%e.length],i=e[(t+2)%e.length],c=ge(jr(pn(s,r),pn(i,s)),n);if(Math.abs(c)<=1e-9)continue;let a=c>0?1:-1;if(o===0)o=a;else if(o!==a)return!1}return!0}function Ni(e,n,o){let t=Er(e,o),r=ji(t,n);if(r<=0)return t;let s=t.map(m=>{let p=gn(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:lo(m)}:null}),i=Xi(t,s),c=new Set,a=Array(t.length),l=[],u=(m,p)=>{a[m]=p};for(let m=0;m<t.length;m++){let p=s[m];if(c.has(m))continue;if(!p){u(m,t[m]);continue}let g=Yi(m,s,i,c,r,n);for(let P of g)c.add(P);if(g.length<2){u(m,t[m]);continue}let b=Fi(g,t,s,i,r,n);l.push(...b.vertexMoves);for(let P of g)u(P,b.polygons.get(P)??t[P])}let f=a.flatMap(m=>m?[m]:[]),d=l.length>0?pt(f,dt(l)):f;return lt(d)}function lt(e){let n=Gr(e),o=1e-4;if(n<=0)return e;let t=Hi(n),r=qi(o);return e.map(s=>{let i=f=>t.snap(f),c=s.vertices.map(i),a=s.uvs&&s.uvs.length===s.vertices.length?s.uvs.map(f=>r.snap(f)):void 0,l=ao(s.textureTriangles,i),u={...s,vertices:c,...a?{uvs:a}:{},...l?{textureTriangles:l}:{}};return{...u,...u.texture?{textureTriangles:Nr(u)}:{}}})}function Nr(e){if(e.texture){if(e.textureTriangles?.length)return $i(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return Gi(e.vertices,e.uvs)}}function _i(e){let n=e.flatMap(o=>Nr(o)??[]);return n.length>0?n:void 0}function Gi(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 $i(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function ao(e,n){if(e?.length)return e.map(o=>({vertices:o.vertices.map(n),uvs:o.uvs.map(t=>[...t])}))}function Fi(e,n,o,t,r,s){let i=_r(e,n,o,r,s);return i?Bi(i):Ui(e,n,o,t,r,s)}function Ui(e,n,o,t,r,s){let i=new Set(e),c=[];for(let f of e)for(let d of t.get(f)??[]){if(f>=d||!i.has(d))continue;let m=_r([f,d],n,o,r,s);m&&c.push(m)}c.sort((f,d)=>d.score-f.score);let a=new Set,l=new Map,u=[];for(let f of c)if(!f.indices.some(d=>a.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];a.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function Bi(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 _r(e,n,o,t,r){let s=Fr(e,o);if(!s||!Ur(e,o,s,t,r))return null;let i=e.map(u=>n[u]),c=i.map(u=>Qi(u,s)),a=ce(ae(i)),l=ce(ae(c));return l>=a?null:{indices:e,source:i,projected:c,vertexMoves:Di(i,c),score:a-l}}function ji(e,n){return Gr(e)<=0?0:n.maxPlaneDisplacement}function Gr(e){let n=1/0,o=1/0,t=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let[l,u,f]of a.vertices)n=Math.min(n,l),o=Math.min(o,u),t=Math.min(t,f),r=Math.max(r,l),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let c=Math.hypot(r-n,s-o,i-t);return c<=0?0:Math.min(.025,Math.max(1e-4,c*25e-5))}function Hi(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,s,i)=>`${r},${s},${i}`;return{snap(r){let s=o(r[0]),i=o(r[1]),c=o(r[2]);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)for(let m=-1;m<=1;m++){let p=n.get(t(s+f,i+d,c+m));if(p){for(let g of p)if(xe(r,g)<=e)return[g[0],g[1],g[2]]}}let a=[r[0],r[1],r[2]],l=t(s,i,c),u=n.get(l);return u?u.push(a):n.set(l,[a]),a}}}function qi(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,s)=>`${r},${s}`;return{snap(r){let s=o(r[0]),i=o(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(t(s+u,i+f));if(d){for(let m of d)if(Math.hypot(r[0]-m[0],r[1]-m[1])<=e)return[m[0],m[1]]}}let c=[r[0],r[1]],a=t(s,i),l=n.get(a);return l?l.push(c):n.set(a,[c]),c}}}function lo(e){return`${e.color??"#cccccc"}|${e.texture??""}|${e.uvs?"uv":"plain"}`}function gn(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0,s=n[0];for(let c=1;c<n.length-1;c++){let a=pn(n[c],s),l=pn(n[c+1],s),u=jr(a,l);o+=u[0],t+=u[1],r+=u[2]}let i=Math.hypot(o,t,r);return i<=1e-10?null:{normal:[o/i,t/i,r/i],area:i/2}}function Xi(e,n){let o=new Map,t=new Map;for(let r=0;r<e.length;r++){let s=e[r];if(!(!n[r]||s.vertices.length<3))for(let i=0;i<s.vertices.length;i++){let c=Je(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),a=o.get(c);a?a.push(r):o.set(c,[r])}}for(let r of o.values())for(let s=0;s<r.length;s++)for(let i=s+1;i<r.length;i++){let c=r[s],a=r[i];Wi(e[c],e[a],n[c],n[a])&&(Ar(t,c,a),Ar(t,a,c))}return t}function Wi(e,n,o,t){if(!o||!t||o.materialKey!==t.materialKey||!!e.uvs!=!!n.uvs)return!1;if(ut(e)||ut(n))return uo(e,n);if(!e.uvs||!n.uvs)return!0;let r=fo(e,n);if(!r)return!1;let[s,i,c,a]=r;return ft(e.uvs[s],n.uvs[c])&&ft(e.uvs[i],n.uvs[a])}function $r(e,n,o,t){return o.materialKey!==t.materialKey?!1:ut(e)||ut(n)?uo(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function ut(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function uo(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=fo(e,n);if(!o)return!1;let[t,r,s,i]=o;return ft(e.uvs[t],n.uvs[s])&&ft(e.uvs[r],n.uvs[i])}function Ar(e,n,o){let t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}function Yi(e,n,o,t,r,s){let i=[e],c=new Set([e]),a=[e];for(;a.length>0;){let l=a.shift();for(let u of o.get(l)??[]){if(t.has(u)||c.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&Ki([...i,u],n,r,s)&&(i.push(u),c.add(u),a.push(u))}}return i}function Ki(e,n,o,t){let r=Fr(e,n);return!!r&&Ur(e,n,r,o,t)}function Fr(e,n){let o=n[e[0]];if(!o)return null;let t=0,r=0,s=0,i=0,c=0,a=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let g=ge(o.normal,p.normal)<0?-1:1,b=Math.max(p.area,1e-6);t+=p.normal[0]*g*b,r+=p.normal[1]*g*b,s+=p.normal[2]*g*b;for(let P of p.polygon.vertices)i+=P[0],c+=P[1],a+=P[2],l+=1}let u=Hr([t,r,s]);if(!u||l===0)return null;let f=Br(e,n),d=Zi(e,n,u,f);if(d){let m=(d.min+d.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m]}}return{normal:u,point:[i/l,c/l,a/l]}}function Zi(e,n,o,t){let r=1/0,s=-1/0;for(let i of e){let c=n[i];if(c)for(let a of c.polygon.vertices){if(!t.has(re(a)))continue;let l=ge(a,o);r=Math.min(r,l),s=Math.max(s,l)}}return Number.isFinite(r)&&Number.isFinite(s)?{min:r,max:s}:null}function Ur(e,n,o,t,r){let s=Math.cos(r.maxAngleDeg*Math.PI/180),i=Br(e,n);for(let c of e){let a=n[c];if(!a||Math.abs(ge(a.normal,o.normal))<s)return!1;for(let l of a.polygon.vertices){let u=i.has(re(l))?r.maxBoundaryDisplacement:t;if(Math.abs(gt(l,o))>u)return!1}}return!0}function Br(e,n){let o=new Map;for(let r of e){let s=n[r];if(!s)continue;let i=s.polygon.vertices;for(let c=0;c<i.length;c++){let a=i[c],l=i[(c+1)%i.length],u=Je(a,l),f=o.get(u);f?f.count+=1:o.set(u,{count:1,a,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 Qi(e,n){let o=r=>yt(r,n),t=ao(e.textureTriangles,o);return{...e,vertices:e.vertices.map(o),...t?{textureTriangles:t}:{}}}function fo(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 s=(r+1)%n.vertices.length;if(Ae(e.vertices[o],n.vertices[r])&&Ae(e.vertices[t],n.vertices[s]))return[o,t,r,s];if(Ae(e.vertices[o],n.vertices[s])&&Ae(e.vertices[t],n.vertices[r]))return[o,t,s,r]}}return null}function Je(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 Ae(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function ft(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function pn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function jr(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 Hr(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 gt(e,n){return ge(pn(e,n.point),n.normal)}function yt(e,n){let o=gt(e,n);return[e[0]-n.normal[0]*o,e[1]-n.normal[1]*o,e[2]-n.normal[2]*o]}var yn=1e-5,mo=.001,po=6;function ht(e){let n=e.vertices;if(n.length<3)return null;let o=n[0],t=0,r=0,s=0;for(let c=1;c+1<n.length;c++){let a=n[c],l=n[c+1],u=a[1]-o[1],f=a[0]-o[0],d=a[2]-o[2],m=l[1]-o[1],p=l[0]-o[0],g=l[2]-o[2];t-=f*g-d*p,r-=d*m-u*g,s-=u*p-f*m}let i=Math.hypot(t,r,s);return i<1e-9?null:[t/i,r/i,s/i]}function go(e,n){let o=n.meshRotation,t=o?rn(e,o[0]??0,o[1]??0,o[2]??0):e;return rn(t,n.rotX,0,n.rotY)[2]}function bt(e,n,o=yn){return go(e,n)>o}function qr(e,n,o=yn){let t=ht(e);return t===null||bt(t,n,o)}function yo(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function ho(e){let n=new Map;for(let o of e){if(!o)continue;let t=yo(o);n.has(t)||n.set(t,o)}return Array.from(n,([o,t])=>({key:o,normal:t}))}function Xr(e){return ho(e.map(ht))}function bo(e,n=mo){let o=Math.abs(e[0]),t=Math.abs(e[1]),r=Math.abs(e[2]),s=Math.max(o,t,r);return s>1-n&&o+t+r-s<n}function Wr(e){return e.length<=po&&e.every(({normal:n})=>bo(n))}function Yr(e,n,o=yn){let t=[];for(let{key:r,normal:s}of e)bt(s,n,o)&&t.push(r);return t.sort(),t.join("|")}function xo(e,n,o,t,r){let s=(p,g,b)=>{let P=[0,0,0];return P[e]=p,P[(e+1)%3]=g,P[(e+2)%3]=b,P},i=s(n,-t,-t),c=s(n,t,-t),a=s(n,t,t),l=s(n,-t,t),u=s(o,-t,-t),f=s(o,t,-t),d=s(o,t,t),m=s(o,-t,t);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function Po(e={}){let n=e.size??5,o=e.thickness??.025,t=e.negative??!1,r=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",c=n*o/2,a=t?-n:0;return[...xo(0,a,n,c,r),...xo(1,a,n,c,s),...xo(2,a,n,c,i)]}function Kr(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 Ji(e,n,o,t,r){let s=(p,g,b)=>Kr(e,p,g,b),i=s(n,-t,-t),c=s(n,t,-t),a=s(n,t,t),l=s(n,-t,t),u=s(o,-t,-t),f=s(o,t,-t),d=s(o,t,t),m=s(o,-t,t);return[{vertices:[i,c,a,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,c,f,u],color:r},{vertices:[c,a,d,f],color:r},{vertices:[a,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function ea(e,n,o,t,r){let s=(f,d,m)=>Kr(e,f,d,m),i=s(n,-t,-t),c=s(n,t,-t),a=s(n,t,t),l=s(n,-t,t),u=s(o,0,0);return[{vertices:[i,c,a,l],color:r},{vertices:[i,c,u],color:r},{vertices:[c,a,u],color:r},{vertices:[a,l,u],color:r},{vertices:[l,i,u],color:r}]}function na(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function Mo(e){let n=e.axis,o=e.sign??1,t=e.shaftLength??4,r=e.shaftHalfThickness??.05,s=e.headLength??.8,i=e.headHalfThickness??.2,c=e.color??"#ffffff",a=e.shaft??!0,l=t*o,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(t+s)*o,p=ea(n,d,m,i,c),g=o===-1?na(p):p;return a?[...Ji(n,u,f,r,c),...g]:g}function xt(e,n,o){let t=[0,0,0],r=(e+1)%3,s=(e+2)%3;return t[r]=Math.cos(o)*n,t[s]=Math.sin(o)*n,t}function Vo(e){let n=e.axis,o=e.radius,t=e.halfThickness??Math.max(.05,o*.04),r=e.segments??32,s=e.color??"#ffffff",i=o-t,c=o+t,a=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=xt(n,i,u),m=xt(n,i,f),p=xt(n,c,u),g=xt(n,c,f);a.push({vertices:[d,p,g,m],color:s})}return a}function Co(e){let n=e.axis,o=e.outerRadius,t=e.color??"#ffffff",r=(n+1)%3,s=(n+2)%3,i=(c,a)=>{let l=[0,0,0];return l[n]=0,l[r]=c,l[s]=a,l};return[{vertices:[i(-o,-o),i(o,-o),i(o,o),i(-o,o)],color:t}]}function vo(e){let n=e.axis,o=e.size??.4,t=e.offset??o*2,r=typeof t=="number"?t:t[0],s=typeof t=="number"?t:t[1],i=e.along??0,c=e.color??"#ffffff",a=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=i,m[a]=r+f,m[l]=s+d,m};return[{vertices:[u(-o,-o),u(o,-o),u(o,o),u(-o,o)],color:c}]}function hn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=[[r+o,s,i],[r-o,s,i],[r,s+o,i],[r,s-o,i],[r,s,i+o],[r,s,i-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:[c[l[0]],c[l[1]],c[l[2]]],color:t}))}function bn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=o/Math.sqrt(3),a=[[r+c,s+c,i+c],[r-c,s-c,i+c],[r-c,s+c,i-c],[r+c,s-c,i-c]];return[[0,2,1],[0,1,3],[0,3,2],[1,2,3]].map(u=>({vertices:[a[u[0]],a[u[1]],a[u[2]]],color:t}))}function xn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=o/2,a=[[r-c,s-c,i-c],[r+c,s-c,i-c],[r+c,s+c,i-c],[r-c,s+c,i-c],[r-c,s-c,i+c],[r+c,s-c,i+c],[r+c,s+c,i+c],[r-c,s+c,i+c]];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:[a[u[0]],a[u[1]],a[u[2]],a[u[3]]],color:t}))}function Pn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=1/c,l=o/Math.sqrt(3),f=[[-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,-c,-a],[0,-c,a],[0,c,-a],[0,c,a],[-a,0,-c],[a,0,-c],[-a,0,c],[a,0,c],[-c,-a,0],[-c,a,0],[c,-a,0],[c,a,0]].map(([m,p,g])=>[r+m*l,s+p*l,i+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(m=>({vertices:m.map(p=>f[p]),color:t}))}function Mn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),u=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]].map(([d,m,p])=>[r+d*a,s+m*a,i+p*a]);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 Zr(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 Vn(e){let{center:n,size:o,subdivisions:t=1,color:r="#ffffff"}=e,[s,i,c]=n,a=(1+Math.sqrt(5))/2,l=o/Math.sqrt(1+a*a),f=[[0,-1,-a],[0,-1,a],[0,1,-a],[0,1,a],[-1,-a,0],[-1,a,0],[1,-a,0],[1,a,0],[-a,0,-1],[a,0,-1],[-a,0,1],[a,0,1]].map(([m,p,g])=>Zr([m*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 m=0;m<t;m++){let p=new Map,g=[],b=(P,C)=>{let v=P<C?`${P}_${C}`:`${C}_${P}`,V=p.get(v);if(V!==void 0)return V;let h=f[P],M=f[C],S=[(h[0]+M[0])/2,(h[1]+M[1])/2,(h[2]+M[2])/2],y=f.length;return f.push(Zr(S,o)),p.set(v,y),y};for(let[P,C,v]of d){let V=b(P,C),h=b(C,v),M=b(v,P);g.push([P,V,M],[V,C,h],[M,h,v],[V,h,M])}d=g}return d.map(([m,p,g])=>({vertices:[[f[m][0]+s,f[m][1]+i,f[m][2]+c],[f[p][0]+s,f[p][1]+i,f[p][2]+c],[f[g][0]+s,f[g][1]+i,f[g][2]+c]],color:r}))}function Cn(e){let{center:n,radius:o,height:t,sides:r=16,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[],d=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r,g=i+o*Math.cos(p),b=a+o*Math.sin(p);f.push([g,c-l,b]),d.push([g,c+l,b])}for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d[m],d[p],f[p],f[m]],color:s})}return u.push({vertices:[...d].reverse(),color:s}),u.push({vertices:[...f],color:s}),u}function vn(e){let{center:n,radius:o,height:t,sides:r=16,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r;f.push([i+o*Math.cos(p),c-l,a+o*Math.sin(p)])}let d=[i,c+l,a];for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d,f[p],f[m]],color:s})}return u.push({vertices:[...f],color:s}),u}function An(e){let{center:n,majorRadius:o,minorRadius:t,segments:r=24,sides:s=12,color:i="#ffffff"}=e,[c,a,l]=n,u=[];for(let d=0;d<r;d++){let m=2*Math.PI*d/r,p=Math.cos(m),g=Math.sin(m),b=[];for(let P=0;P<s;P++){let C=2*Math.PI*P/s,v=o+t*Math.cos(C);b.push([c+v*p,a+t*Math.sin(C),l+v*g])}u.push(b)}let f=[];for(let d=0;d<r;d++){let m=(d+1)%r;for(let p=0;p<s;p++){let g=(p+1)%s;f.push({vertices:[u[d][p],u[m][p],u[m][g],u[d][g]],color:i})}}return f}function Sn(e){let{center:n,radius:o,height:t,sides:r=4,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r;f.push([i+o*Math.cos(p),c-l,a+o*Math.sin(p)])}let d=[i,c+l,a];for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d,f[p],f[m]],color:s})}return u.push({vertices:[...f],color:s}),u}function On(e){let{center:n,radius:o,height:t,sides:r=6,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[],d=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r,g=i+o*Math.cos(p),b=a+o*Math.sin(p);f.push([g,c-l,b]),d.push([g,c+l,b])}for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d[m],d[p],f[p],f[m]],color:s})}return u.push({vertices:[...d].reverse(),color:s}),u.push({vertices:[...f],color:s}),u}function Tn(e){let{center:n,radius:o,height:t,sides:r=6,color:s="#ffffff"}=e,[i,c,a]=n,l=t/2,u=[],f=[],d=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r,g=p+Math.PI/r;f.push([i+o*Math.cos(p),c-l,a+o*Math.sin(p)]),d.push([i+o*Math.cos(g),c+l,a+o*Math.sin(g)])}for(let m=0;m<r;m++){let p=(m+1)%r;u.push({vertices:[d[m],f[p],f[m]],color:s}),u.push({vertices:[d[m],d[p],f[p]],color:s})}return u.push({vertices:[...d].reverse(),color:s}),u.push({vertices:[...f],color:s}),u}function In(e){let{center:n,radius:o,halfHeight:t,sides:r=6,color:s="#ffffff"}=e,[i,c,a]=n,l=[],u=[];for(let m=0;m<r;m++){let p=2*Math.PI*m/r;u.push([i+o*Math.cos(p),c,a+o*Math.sin(p)])}let f=[i,c+t,a],d=[i,c-t,a];for(let m=0;m<r;m++){let p=(m+1)%r;l.push({vertices:[f,u[p],u[m]],color:s})}for(let m=0;m<r;m++){let p=(m+1)%r;l.push({vertices:[d,u[m],u[p]],color:s})}return l}function wn(e){let{center:n,radius:o,halfHeight:t,sides:r=5,color:s="#ffffff"}=e,[i,c,a]=n,l=Math.cos(Math.PI/r),u=t*(1-l)/(1+l),f=[],d=[],m=[];for(let b=0;b<r;b++){let P=2*Math.PI*b/r,C=P+Math.PI/r;d.push([i+o*Math.cos(P),c+u,a+o*Math.sin(P)]),m.push([i+o*Math.cos(C),c-u,a+o*Math.sin(C)])}let p=[i,c+t,a],g=[i,c-t,a];for(let b=0;b<r;b++){let P=(b+1)%r;f.push({vertices:[p,d[P],m[b],d[b]],color:s})}for(let b=0;b<r;b++){let P=(b+1)%r;f.push({vertices:[g,m[b],d[P],m[P]],color:s})}return f}function zn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),l=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],u=l.map(([p,g,b])=>[r+p*a,s+g*a,i+b*a]);function f(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],b=f(g,p),P=g[0]-b*p[0],C=g[1]-b*p[1],v=g[2]-b*p[2],V=Math.sqrt(P*P+C*C+v*v),h=[P/V,C/V,v/V],M=[p[1]*h[2]-p[2]*h[1],p[2]*h[0]-p[0]*h[2],p[0]*h[1]-p[1]*h[0]];return{u:h,w:M}}let m=[];for(let p=0;p<12;p++){let g=l[p],b=f(g,g),P=-1,C=1/0;for(let O=0;O<12;O++){if(O===p)continue;let w=f(l[O],g);w<C&&(C=w,P=O)}let v=[];for(let O=0;O<12;O++)O===p||O===P||v.push({idx:O,d:f(l[O],g)});v.sort((O,w)=>w.d-O.d);let V=v.slice(0,5).map(O=>O.idx),h=[g[0]/Math.sqrt(b),g[1]/Math.sqrt(b),g[2]/Math.sqrt(b)],{u:M,w:S}=d(h);V.sort((O,w)=>{let D=l[O],L=l[w],z=Math.atan2(f(D,S),f(D,M)),T=Math.atan2(f(L,S),f(L,M));return z-T});let x=[0,2,4,1,3].map(O=>V[O]),A=0,I=0,R=0;for(let O of x)A+=u[O][0],I+=u[O][1],R+=u[O][2];let E=[A/5,I/5,R/5];for(let O=0;O<5;O++){let w=u[x[O]],D=u[x[(O+2)%5]],L=[w[0]-E[0],w[1]-E[1],w[2]-E[2]],z=[D[0]-E[0],D[1]-E[1],D[2]-E[2]],T=L[1]*z[2]-L[2]*z[1],k=L[2]*z[0]-L[0]*z[2],N=L[0]*z[1]-L[1]*z[0],G=E[0]-r,_=E[1]-s,$=E[2]-i,F=T*G+k*_+N*$<0;m.push({vertices:F?[E,D,w]:[E,w,D],color:t})}}return m}function En(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),l=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],u=l.map(([p,g,b])=>[r+p*a,s+g*a,i+b*a]);function f(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],b=f(g,p),P=g[0]-b*p[0],C=g[1]-b*p[1],v=g[2]-b*p[2],V=Math.sqrt(P*P+C*C+v*v),h=[P/V,C/V,v/V],M=[p[1]*h[2]-p[2]*h[1],p[2]*h[0]-p[0]*h[2],p[0]*h[1]-p[1]*h[0]];return{u:h,w:M}}let m=[];for(let p=0;p<12;p++){let g=l[p],b=f(g,g),P=-1,C=1/0;for(let U=0;U<12;U++){if(U===p)continue;let B=f(l[U],g);B<C&&(C=B,P=U)}let v=[];for(let U=0;U<12;U++)U===p||U===P||v.push({idx:U,d:f(l[U],g)});v.sort((U,B)=>B.d-U.d);let V=v.slice(0,5).map(U=>U.idx),h=[g[0]/Math.sqrt(b),g[1]/Math.sqrt(b),g[2]/Math.sqrt(b)],{u:M,w:S}=d(h);V.sort((U,B)=>{let q=l[U],Z=l[B];return Math.atan2(f(q,S),f(q,M))-Math.atan2(f(Z,S),f(Z,M))});let y=0,x=0,A=0;for(let U of V)y+=u[U][0],x+=u[U][1],A+=u[U][2];y/=5,x/=5,A/=5;let I=u[V[0]],R=u[V[1]],E=u[V[2]],O=R[0]-I[0],w=R[1]-I[1],D=R[2]-I[2],L=E[0]-I[0],z=E[1]-I[1],T=E[2]-I[2],k=w*T-D*z,N=D*L-O*T,G=O*z-w*L,_=y-r,$=x-s,F=A-i,j=k*_+N*$+G*F<0?[...V].reverse():V;m.push({vertices:j.map(U=>u[U]),color:t})}return m}function Rn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=1/c,l=o/Math.sqrt(3),f=[[-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,-c,-a],[0,-c,a],[0,c,-a],[0,c,a],[-a,0,-c],[a,0,-c],[-a,0,c],[a,0,c],[-c,-a,0],[-c,a,0],[c,-a,0],[c,a,0]].map(([g,b,P])=>[r+g*l,s+b*l,i+P*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]],m=[0,2,4,1,3],p=[];for(let g of d){let b=m.map(h=>g[h]),P=0,C=0,v=0;for(let h of b)P+=f[h][0],C+=f[h][1],v+=f[h][2];let V=[P/5,C/5,v/5];for(let h=0;h<5;h++){let M=f[b[h]],S=f[b[(h+2)%5]],y=[M[0]-V[0],M[1]-V[1],M[2]-V[2]],x=[S[0]-V[0],S[1]-V[1],S[2]-V[2]],A=y[1]*x[2]-y[2]*x[1],I=y[2]*x[0]-y[0]*x[2],R=y[0]*x[1]-y[1]*x[0],E=V[0]-r,O=V[1]-s,w=V[2]-i,D=A*E+I*O+R*w<0;p.push({vertices:D?[V,S,M]:[V,M,S],color:t})}}return p}function kn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=o/Math.sqrt(1+c*c),l=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],u=l.map(([m,p,g])=>[r+m*a,s+p*a,i+g*a]),f=[[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 m=0;m<12;m++){let p=1/0;for(let g=0;g<12;g++){if(g===m)continue;let b=l[m][0]*l[g][0]+l[m][1]*l[g][1]+l[m][2]*l[g][2];b<p&&(p=b,d[m]=g)}}return f.map(([m,p,g])=>({vertices:[u[d[m]],u[d[g]],u[d[p]]],color:t}))}function ke(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=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,m,p])=>[r+d*c,s+m*c,i+p*c]),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]],f=[[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})),...f.map(d=>({vertices:[l[d[0]],l[d[1]],l[d[2]],l[d[3]]],color:t}))]}function De(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,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,f=[];function d(x,A){return x<A?`${x},${A}`:`${A},${x}`}function m(x,A){let I=d(x,A);if(u.has(I))return u.get(I);let[R,E,O]=a[x],[w,D,L]=a[A],z=f.length;return f.push([(R+w)/2,(E+D)/2,(O+L)/2]),u.set(I,z),z}let p=Array.from({length:12},()=>[]),g=l.map(([x,A,I])=>{let R=m(x,A),E=m(A,I),O=m(I,x);return p[x].includes(R)||p[x].push(R),p[x].includes(O)||p[x].push(O),p[A].includes(R)||p[A].push(R),p[A].includes(E)||p[A].push(E),p[I].includes(E)||p[I].push(E),p[I].includes(O)||p[I].push(O),[R,E,O]}),[b,P,C]=f[0],v=Math.sqrt(b*b+P*P+C*C),V=o/v,h=f.map(([x,A,I])=>[r+x*V,s+A*V,i+I*V]);function M(x,A){let I=0,R=0,E=0;for(let q of x)I+=f[q][0],R+=f[q][1],E+=f[q][2];let O=x.length;I/=O,R/=O,E/=O;let[w,D,L]=A,[z,T,k]=f[x[0]],N=z-I,G=T-R,_=k-E,$=N*w+G*D+_*L;N-=$*w,G-=$*D,_-=$*L;let F=Math.sqrt(N*N+G*G+_*_);N/=F,G/=F,_/=F;let H=D*_-L*G,j=L*N-w*_,U=w*G-D*N,B=x.map(q=>{let[Z,J,ne]=f[q],ie=Z-I,oe=J-R,Q=ne-E,X=ie*N+oe*G+Q*_,K=ie*H+oe*j+Q*U;return{i:q,angle:Math.atan2(K,X)}});return B.sort((q,Z)=>q.angle-Z.angle),B.map(q=>q.i)}let S=g.map(([x,A,I])=>{let[R,E,O]=f[x],[w,D,L]=f[A],[z,T,k]=f[I],N=[(R+w+z)/3,(E+D+T)/3,(O+L+k)/3];return{vertices:M([x,A,I],N).map(_=>h[_]),color:t}}),y=a.map((x,A)=>{let I=p[A];return{vertices:M(I,x).map(O=>h[O]),color:t}});return[...S,...y]}function Le(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=1/Math.sqrt(3),a=[[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 V=0;V<4;V++){if(v===V)continue;let[h,M,S]=a[v],[y,x,A]=a[V],I=[2/3*h+1/3*y,2/3*M+1/3*x,2/3*S+1/3*A];l[v][V]=I,u.push(I)}let f=0;for(let[v,V,h]of u){let M=Math.sqrt(v*v+V*V+h*h);M>f&&(f=M)}let d=o/f,m=(v,V)=>{let[h,M,S]=l[v][V];return[r+h*d,s+M*d,i+S*d]};function p(v){let V=[0,1,2,3].filter(_=>_!==v),[h,M,S]=V,y=m(v,h),x=m(v,M),A=m(v,S),[I,R,E]=a[v],O=x[0]-y[0],w=x[1]-y[1],D=x[2]-y[2],L=A[0]-y[0],z=A[1]-y[1],T=A[2]-y[2],k=w*T-D*z,N=D*L-O*T,G=O*z-w*L;return k*I+N*R+G*E<0?[y,A,x]:[y,x,A]}function g(v,V,h){let M=[m(v,V),m(V,v),m(V,h),m(h,V),m(h,v),m(v,h)],[S,y,x]=a[v],[A,I,R]=a[V],[E,O,w]=a[h],D=(S+A+E)/3,L=(y+I+O)/3,z=(x+R+w)/3,T=M[0],k=M[1],N=M[2],G=k[0]-T[0],_=k[1]-T[1],$=k[2]-T[2],F=N[0]-T[0],H=N[1]-T[1],j=N[2]-T[2],U=_*j-$*H,B=$*F-G*j,q=G*H-_*F;return U*D+B*L+q*z<0&&M.reverse(),M}let b=[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,V,h])=>({vertices:g(v,V,h),color:t}));return[...b,...C]}function Ne(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(2-Math.sqrt(2))/2,a=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],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 f(h,M){let S=`${h},${M}`;if(u.has(S))return u.get(S);let[y,x,A]=a[h],[I,R,E]=a[M],O=[(1-c)*y+c*I,(1-c)*x+c*R,(1-c)*A+c*E];return u.set(S,O),O}for(let[h,M]of l)f(h,M),f(M,h);let d=0;for(let h of u.values()){let[M,S,y]=h,x=Math.sqrt(M*M+S*S+y*y);x>d&&(d=x)}let m=o/d,p=h=>[r+h[0]*m,s+h[1]*m,i+h[2]*m];function g(h,M){return p(f(h,M))}function b(h,M){let[S,y,x]=M,A=h[0],I=h[1],R=h[2],E=I[0]-A[0],O=I[1]-A[1],w=I[2]-A[2],D=R[0]-A[0],L=R[1]-A[1],z=R[2]-A[2],T=O*z-w*L,k=w*D-E*z,N=E*L-O*D;return T*S+k*y+N*x<0?[...h].reverse():h}let P=[[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=a.map(([h,M,S],y)=>{let[x,A,I]=P[y],R=[g(y,x),g(y,A),g(y,I)];return{vertices:b(R,[h,M,S]),color:t}}),V=[{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:h,normal:M})=>{let[S,y,x,A]=h,I=[g(S,y),g(y,S),g(y,x),g(x,y),g(x,A),g(A,x),g(A,S),g(S,A)];return{vertices:b(I,M),color:t}});return[...C,...V]}function _e(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=o/Math.sqrt(5),a=new Set,l=[];for(let C=0;C<3;C++){let v=(C+1)%3,V=(C+2)%3;for(let h of[-1,1])for(let M of[-1,1])for(let S of[!1,!0]){let y=[0,0,0];y[v]=S?h*2:h*1,y[V]=S?M*1:M*2;let x=`${y[0]},${y[1]},${y[2]}`;a.has(x)||(a.add(x),l.push(y))}}let u=l.map(([C,v,V])=>[r+C*c,s+v*c,i+V*c]),f=new Map;for(let C=0;C<l.length;C++){let[v,V,h]=l[C];f.set(`${v},${V},${h}`,C)}function d(C,v,V){let h=`${C},${v},${V}`,M=f.get(h);if(M===void 0)throw new Error(`Vertex not found: (${C},${v},${V})`);return M}function m(C,v){let V=0,h=0,M=0;for(let _ of C)V+=l[_][0],h+=l[_][1],M+=l[_][2];let S=C.length;V/=S,h/=S,M/=S;let[y,x,A]=v,[I,R,E]=l[C[0]],O=I-V,w=R-h,D=E-M,L=O*y+w*x+D*A;O-=L*y,w-=L*x,D-=L*A;let z=Math.sqrt(O*O+w*w+D*D);O/=z,w/=z,D/=z;let T=x*D-A*w,k=A*O-y*D,N=y*w-x*O,G=C.map(_=>{let[$,F,H]=l[_],j=$-V,U=F-h,B=H-M,q=j*O+U*w+B*D,Z=j*T+U*k+B*N;return{i:_,angle:Math.atan2(Z,q)}});return G.sort((_,$)=>_.angle-$.angle),G.map(_=>_.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:m(C,v).map(V=>u[V]),color:t})),P=[[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,V])=>{let h=[];for(let S=0;S<l.length;S++){let[y,x,A]=l[S];Math.abs(C*y+v*x+V*A-3)<1e-9&&h.push(S)}let M=[C/Math.sqrt(3),v/Math.sqrt(3),V/Math.sqrt(3)];return{vertices:m(h,M).map(S=>u[S]),color:t}});return[...g,...P]}function Ge(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=1/c,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,-c,-a],[0,-c,a],[0,c,-a],[0,c,a],[-a,0,-c],[a,0,-c],[-a,0,c],[a,0,c],[-c,-a,0],[-c,a,0],[c,-a,0],[c,a,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]],f=new Set,d=[];for(let y of u)for(let x=0;x<5;x++){let A=y[x],I=y[(x+1)%5],R=A<I?`${A},${I}`:`${I},${A}`;f.has(R)||(f.add(R),d.push([A,I]))}let m=(3-Math.sqrt(5))/4,p=new Map;function g(y,x){let A=`${y},${x}`;if(p.has(A))return p.get(A);let[I,R,E]=l[y],[O,w,D]=l[x],L=[(1-m)*I+m*O,(1-m)*R+m*w,(1-m)*E+m*D];return p.set(A,L),L}for(let[y,x]of d)g(y,x),g(x,y);let b=0;for(let y of p.values()){let[x,A,I]=y,R=Math.sqrt(x*x+A*A+I*I);R>b&&(b=R)}let P=o/b,C=Array.from({length:20},()=>[]);for(let[y,x]of d)C[y].push(x),C[x].push(y);function v(y,x){let[A,I,R]=g(y,x);return[r+A*P,s+I*P,i+R*P]}function V(y,x){let[A,I,R]=x,E=y[0],O=y[1],w=y[2],D=O[0]-E[0],L=O[1]-E[1],z=O[2]-E[2],T=w[0]-E[0],k=w[1]-E[1],N=w[2]-E[2],G=L*N-z*k,_=z*T-D*N,$=D*k-L*T;return G*A+_*I+$*R<0?[...y].reverse():y}function h(y,x){let A=0,I=0,R=0;for(let[B,q,Z]of y)A+=B,I+=q,R+=Z;let E=y.length;A/=E,I/=E,R/=E;let[O,w,D]=x,[L,z,T]=y[0],k=L-A,N=z-I,G=T-R,_=k*O+N*w+G*D;k-=_*O,N-=_*w,G-=_*D;let $=Math.sqrt(k*k+N*N+G*G);k/=$,N/=$,G/=$;let F=w*G-D*N,H=D*k-O*G,j=O*N-w*k,U=y.map(B=>{let q=B[0]-A,Z=B[1]-I,J=B[2]-R,ne=q*k+Z*N+J*G,ie=q*F+Z*H+J*j;return{pt:B,angle:Math.atan2(ie,ne)}});return U.sort((B,q)=>B.angle-q.angle),U.map(B=>B.pt)}let M=l.map(([y,x,A],I)=>{let[R,E,O]=C[I],w=[g(I,R),g(I,E),g(I,O)],L=h(w,[y,x,A]).map(([z,T,k])=>[r+z*P,s+T*P,i+k*P]);return{vertices:V(L,[y,x,A]),color:t}}),S=u.map(y=>{let[x,A,I,R,E]=y,O=[g(x,A),g(A,x),g(A,I),g(I,A),g(I,R),g(R,I),g(R,E),g(E,R),g(E,x),g(x,E)],[w,D,L,z,T]=y.map(H=>l[H]),k=(w[0]+D[0]+L[0]+z[0]+T[0])/5,N=(w[1]+D[1]+L[1]+z[1]+T[1])/5,G=(w[2]+D[2]+L[2]+z[2]+T[2])/5,_=[k,N,G],F=h(O,_).map(([H,j,U])=>[r+H*P,s+j*P,i+U*P]);return{vertices:V(F,_),color:t}});return[...M,...S]}function $e(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,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,f=[];for(let[M,S,y]of l)for(let[x,A]of[[M,S],[S,y],[y,M]]){let I=x<A?`${x},${A}`:`${A},${x}`;u.has(I)||(u.add(I),f.push([x,A]))}let d=1/3,m=new Map;function p(M,S){let y=`${M},${S}`;if(m.has(y))return m.get(y);let[x,A,I]=a[M],[R,E,O]=a[S],w=[(1-d)*x+d*R,(1-d)*A+d*E,(1-d)*I+d*O];return m.set(y,w),w}for(let[M,S]of f)p(M,S),p(S,M);let g=0;for(let M of m.values()){let[S,y,x]=M,A=Math.sqrt(S*S+y*y+x*x);A>g&&(g=A)}let b=o/g,P=Array.from({length:12},()=>[]);for(let[M,S]of f)P[M].push(S),P[S].push(M);function C(M,S){let[y,x,A]=S,I=M[0],R=M[1],E=M[2],O=R[0]-I[0],w=R[1]-I[1],D=R[2]-I[2],L=E[0]-I[0],z=E[1]-I[1],T=E[2]-I[2],k=w*T-D*z,N=D*L-O*T,G=O*z-w*L;return k*y+N*x+G*A<0?[...M].reverse():M}function v(M,S){let y=0,x=0,A=0;for(let[j,U,B]of M)y+=j,x+=U,A+=B;let I=M.length;y/=I,x/=I,A/=I;let[R,E,O]=S,[w,D,L]=M[0],z=w-y,T=D-x,k=L-A,N=z*R+T*E+k*O;z-=N*R,T-=N*E,k-=N*O;let G=Math.sqrt(z*z+T*T+k*k);z/=G,T/=G,k/=G;let _=E*k-O*T,$=O*z-R*k,F=R*T-E*z,H=M.map(j=>{let U=j[0]-y,B=j[1]-x,q=j[2]-A,Z=U*z+B*T+q*k,J=U*_+B*$+q*F;return{pt:j,angle:Math.atan2(J,Z)}});return H.sort((j,U)=>j.angle-U.angle),H.map(j=>j.pt)}let V=a.map(([M,S,y],x)=>{let A=P[x].map(E=>p(x,E)),R=v(A,[M,S,y]).map(([E,O,w])=>[r+E*b,s+O*b,i+w*b]);return{vertices:C(R,[M,S,y]),color:t}}),h=l.map(([M,S,y])=>{let x=[p(M,S),p(S,M),p(S,y),p(y,S),p(y,M),p(M,y)],A=a[M],I=a[S],R=a[y],E=[(A[0]+I[0]+R[0])/3,(A[1]+I[1]+R[1])/3,(A[2]+I[2]+R[2])/3],w=v(x,E).map(([D,L,z])=>[r+D*b,s+L*b,i+z*b]);return{vertices:C(w,E),color:t}});return[...V,...h]}function ta(e,n){if(n.length<=3)return!0;let[o,t,r]=e[n[0]],[s,i,c]=e[n[1]],[a,l,u]=e[n[2]],f=s-o,d=i-t,m=c-r,p=a-o,g=l-t,b=u-r,P=d*b-m*g,C=m*p-f*b,v=f*g-d*p,V=Math.sqrt(P*P+C*C+v*v);if(V<1e-10)return!1;let h=1/V,M=(P*o+C*t+v*r)*h;for(let S=3;S<n.length;S++){let[y,x,A]=e[n[S]];if(Math.abs((P*y+C*x+v*A)*h-M)>1e-6)return!1}return!0}function oa(e,n){let o=0,t=0,r=0;for(let y of n)o+=e[y][0],t+=e[y][1],r+=e[y][2];let s=n.length;o/=s,t/=s,r/=s;let[i,c,a]=e[n[0]],[l,u,f]=e[n[1]],[d,m,p]=e[n[2]],g=l-i,b=u-c,P=f-a,C=d-i,v=m-c,V=p-a,h=b*V-P*v,M=P*C-g*V,S=g*v-b*C;return h*o+M*t+S*r>0}function ra(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,s=[];function i(c,a){let l=c[c.length-1];if(c.length===o){if(!n[l].includes(a)||!ta(e,c)||!oa(e,c))return;let u=ra(c);r.has(u)||(r.add(u),s.push([...c]));return}for(let u of n[l])c.includes(u)||u<=a||i([...c,u],a)}for(let c=0;c<t;c++)i([c],c);return s}function fe(e,n=1e-6){let o=e.length,t=1/0;for(let s=0;s<o;s++)for(let i=s+1;i<o;i++){let c=e[s][0]-e[i][0],a=e[s][1]-e[i][1],l=e[s][2]-e[i][2],u=Math.sqrt(c*c+a*a+l*l);u>1e-10&&u<t&&(t=u)}let r=Array.from({length:o},()=>[]);for(let s=0;s<o;s++)for(let i=s+1;i<o;i++){let c=e[s][0]-e[i][0],a=e[s][1]-e[i][1],l=e[s][2]-e[i][2],u=Math.sqrt(c*c+a*a+l*l);Math.abs(u-t)<n&&(r[s].push(i),r[i].push(s))}return{adj:r,edgeLen:t}}function me(e,n,o){let t=0,r=0,s=0;for(let M of n)t+=e[M][0],r+=e[M][1],s+=e[M][2];let i=n.length;t/=i,r/=i,s/=i;let[c,a,l]=o,[u,f,d]=e[n[0]],m=u-t,p=f-r,g=d-s,b=m*c+p*a+g*l;m-=b*c,p-=b*a,g-=b*l;let P=Math.sqrt(m*m+p*p+g*g);m/=P,p/=P,g/=P;let C=a*g-l*p,v=l*m-c*g,V=c*p-a*m,h=n.map(M=>{let[S,y,x]=e[M],A=S-t,I=y-r,R=x-s,E=A*m+I*p+R*g,O=A*C+I*v+R*V;return{i:M,angle:Math.atan2(O,E)}});return h.sort((M,S)=>M.angle-S.angle),h.map(M=>M.i)}function de(e,n){let o=0,t=0,r=0;for(let c of n)o+=e[c][0],t+=e[c][1],r+=e[c][2];let s=n.length;o/=s,t/=s,r/=s;let i=Math.sqrt(o*o+t*t+r*r);return[o/i,t/i,r/i]}function Fe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=1,a=1+Math.sqrt(2),l=1+2*Math.sqrt(2),u=[[c,a,l],[c,l,a],[a,c,l],[a,l,c],[l,c,a],[l,a,c]],f=[];for(let[x,A,I]of u)for(let R of[-1,1])for(let E of[-1,1])for(let O of[-1,1])f.push([R*x,E*A,O*I]);let d=new Set,m=[];for(let x of f){let A=`${x[0].toFixed(9)},${x[1].toFixed(9)},${x[2].toFixed(9)}`;d.has(A)||(d.add(A),m.push(x))}let[p,g,b]=m[0],P=Math.sqrt(p*p+g*g+b*b),C=o/P,v=m.map(([x,A,I])=>[r+x*C,s+A*C,i+I*C]),{adj:V}=fe(m),h=te(m,V,4),M=te(m,V,6),S=te(m,V,8);function y(x){let A=de(m,x);return{vertices:me(m,x,A).map(R=>v[R]),color:t}}return[...h.map(y),...M.map(y),...S.map(y)]}function Ue(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[1/c,1/c,3+c],[2/c,c,1+2*c],[1/c,c*c,-1+3*c],[2*c-1,2,2+c],[c,3,2*c]],l=[];for(let[S,y,x]of a){let A=[[S,y,x],[y,x,S],[x,S,y]];for(let[I,R,E]of A)for(let O of[-1,1])for(let w of[-1,1])for(let D of[-1,1])l.push([O*I,w*R,D*E])}let u=new Set,f=[];for(let S of l){let y=`${S[0].toFixed(8)},${S[1].toFixed(8)},${S[2].toFixed(8)}`;u.has(y)||(u.add(y),f.push(S))}let[d,m,p]=f[0],g=Math.sqrt(d*d+m*m+p*p),b=o/g,P=f.map(([S,y,x])=>[r+S*b,s+y*b,i+x*b]),{adj:C}=fe(f),v=te(f,C,4),V=te(f,C,6),h=te(f,C,10);function M(S){let y=de(f,S);return{vertices:me(f,S,y).map(A=>P[A]),color:t}}return[...v.map(M),...V.map(M),...h.map(M)]}function Be(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=1+Math.sqrt(2),a=[],l=[[1,1,c],[1,c,1],[c,1,1]];for(let[V,h,M]of l)for(let S of[-1,1])for(let y of[-1,1])for(let x of[-1,1])a.push([S*V,y*h,x*M]);let[u,f,d]=a[0],m=Math.sqrt(u*u+f*f+d*d),p=o/m,g=a.map(([V,h,M])=>[r+V*p,s+h*p,i+M*p]),{adj:b}=fe(a),P=te(a,b,3),C=te(a,b,4);function v(V){let h=de(a,V);return{vertices:me(a,V,h).map(S=>g[S]),color:t}}return[...P.map(v),...C.map(v)]}function je(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=c*c,l=a*c,u=[];for(let[y,x,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 E of[-1,1])u.push([I*y,R*x,E*A]);for(let[y,x,A]of[[a,c,2*c],[c,2*c,a],[2*c,a,c]])for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])u.push([I*y,R*x,E*A]);for(let[y,x,A]of[[2+c,0,a],[0,a,2+c],[a,2+c,0]])for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])u.push([I*y,R*x,E*A]);let f=new Set,d=[];for(let y of u){let x=`${y[0].toFixed(8)},${y[1].toFixed(8)},${y[2].toFixed(8)}`;f.has(x)||(f.add(x),d.push(y))}let[m,p,g]=d[0],b=Math.sqrt(m*m+p*p+g*g),P=o/b,C=d.map(([y,x,A])=>[r+y*P,s+x*P,i+A*P]),{adj:v}=fe(d),V=te(d,v,3),h=te(d,v,4),M=te(d,v,5);function S(y){let x=de(d,y);return{vertices:me(d,y,x).map(I=>C[I]),color:t}}return[...V.map(S),...h.map(S),...M.map(S)]}function He(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.cbrt(19+3*Math.sqrt(33))+Math.cbrt(19-3*Math.sqrt(33)))/3,a=1,l=1/c,u=c,f=[[a,l,u],[l,u,a],[u,a,l]],d=[[u,l,a],[l,a,u],[a,u,l]],m=[];for(let[y,x,A]of f)for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(E===-1?1:0))%2===0&&m.push([I*y,R*x,E*A]);for(let[y,x,A]of d)for(let I of[-1,1])for(let R of[-1,1])for(let E of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(E===-1?1:0))%2===1&&m.push([I*y,R*x,E*A]);let[p,g,b]=m[0],P=Math.sqrt(p*p+g*g+b*b),C=o/P,v=m.map(([y,x,A])=>[r+y*C,s+x*C,i+A*C]),{adj:V}=fe(m),h=te(m,V,3),M=te(m,V,4);function S(y){let x=de(m,y);return{vertices:me(m,y,x).map(I=>v[I]),color:t}}return[...h.map(S),...M.map(S)]}function qe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,s,i]=n,c=(1+Math.sqrt(5))/2,a=[[0,-1,-c],[0,-1,c],[0,1,-c],[0,1,c],[-1,-c,0],[-1,c,0],[1,-c,0],[1,c,0],[-c,0,-1],[c,0,-1],[-c,0,1],[c,0,1]],l=Math.sqrt(1+c*c),u=a.map(([O,w,D])=>[O/l,w/l,D/l]),f=[[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(O,w){return[O[1]*w[2]-O[2]*w[1],O[2]*w[0]-O[0]*w[2],O[0]*w[1]-O[1]*w[0]]}function m(O){return Math.sqrt(O[0]*O[0]+O[1]*O[1]+O[2]*O[2])}function p(O){let w=m(O);return[O[0]/w,O[1]/w,O[2]/w]}function g(O,w){return Math.sqrt((O[0]-w[0])**2+(O[1]-w[1])**2+(O[2]-w[2])**2)}function b(O,w,D,L){let[z,T,k]=u[O],[N,G,_]=u[w],$=[(1-D)*z+D*N,(1-D)*T+D*G,(1-D)*k+D*_],F=p(d(u[O],u[w]));return p([$[0]+L*F[0],$[1]+L*F[1],$[2]+L*F[2]])}function P(O,w){let D=b(0,2,O,w),L=b(2,9,O,w),z=b(2,0,O,w);return g(D,L)-g(D,z)}function C(O,w){let D=b(0,2,O,w),L=b(2,9,O,w),z=b(0,9,O,w);return g(D,L)-g(D,z)}let v=.35,V=.13,h=1e-7;for(let O=0;O<80;O++){let w=P(v,V),D=C(v,V);if(Math.abs(w)<1e-13&&Math.abs(D)<1e-13)break;let L=(P(v+h,V)-P(v-h,V))/(2*h),z=(P(v,V+h)-P(v,V-h))/(2*h),T=(C(v+h,V)-C(v-h,V))/(2*h),k=(C(v,V+h)-C(v,V-h))/(2*h),N=L*k-z*T;if(Math.abs(N)<1e-12)break;v-=(w*k-D*z)/N,V-=(D*L-w*T)/N}let M=new Set,S=[];for(let[O,w,D]of f)for(let[L,z]of[[O,w],[w,D],[D,O],[w,O],[D,w],[O,D]]){let T=`${L},${z}`;M.has(T)||(M.add(T),S.push(b(L,z,v,V)))}let y=S,x=y.map(([O,w,D])=>[r+O*o,s+w*o,i+D*o]),{adj:A}=fe(y),I=te(y,A,3),R=te(y,A,5);function E(O){let w=de(y,O);return{vertices:me(y,O,w).map(L=>x[L]),color:t}}return[...I.map(E),...R.map(E)]}function sa(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 ca(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function ia(e){let n=ca(e);return[e[0]/n,e[1]/n,e[2]/n]}function aa(e){let[n,o,t]=e[0],[r,s,i]=e[1],[c,a,l]=e[2],u=r-n,f=s-o,d=i-t,m=c-n,p=a-o,g=l-t,b=f*g-d*p,P=d*m-u*g,C=u*p-f*m,v=e.reduce((y,x)=>y+x[0],0)/e.length,V=e.reduce((y,x)=>y+x[1],0)/e.length,h=e.reduce((y,x)=>y+x[2],0)/e.length,M=b*v+P*V+C*h>0?1:-1,S=Math.sqrt(b*b+P*P+C*C);return[M*b/S,M*P/S,M*C/S]}function ee(e){let o=[],t=[];function r(f){for(let d=0;d<o.length;d++)if(sa(o[d],f)<1e-10)return d;return o.push(f),o.length-1}for(let f of e)t.push(f.vertices.map(d=>r(d)));let s=e.length,i=o.length,c=Math.max(...o.map(f=>f[0]*f[0]+f[1]*f[1]+f[2]*f[2])),a=e.map((f,d)=>{let m=f.vertices,p=aa(m),g=m[0],b=p[0]*g[0]+p[1]*g[1]+p[2]*g[2],P=c/b;return[p[0]*P,p[1]*P,p[2]*P]}),l=Array.from({length:i},()=>[]);for(let f=0;f<s;f++)for(let d of t[f])l[d].push(f);let u=[];for(let f=0;f<i;f++){let d=l[f];if(d.length<3)continue;let m=o[f],p=ia(m),g=a[d[0]],b=g[0]-m[0],P=g[1]-m[1],C=g[2]-m[2],v=b*p[0]+P*p[1]+C*p[2];b-=v*p[0],P-=v*p[1],C-=v*p[2];let V=Math.sqrt(b*b+P*P+C*C);if(V<1e-12)continue;let h=[b/V,P/V,C/V],M=[p[1]*h[2]-p[2]*h[1],p[2]*h[0]-p[0]*h[2],p[0]*h[1]-p[1]*h[0]],S=d.map(y=>{let x=a[y],A=x[0]-m[0],I=x[1]-m[1],R=x[2]-m[2],E=A*h[0]+I*h[1]+R*h[2],O=A*M[0]+I*M[1]+R*M[2];return{fi:y,angle:Math.atan2(O,E)}});S.sort((y,x)=>y.angle-x.angle),u.push(S.map(y=>y.fi))}return u.map(f=>({vertices:f.map(d=>a[d]),color:"#ffffff"}))}function Dn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=ke({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Ln(e){let{center:n,size:o,color:t="#ffffff"}=e,r=De({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Nn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Le({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function _n(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ne({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Gn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=_e({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function $n(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ge({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Fn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=$e({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Un(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Fe({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Bn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ue({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+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(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Hn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=je({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function qn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=He({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Xn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=qe({center:[0,0,0],size:o});return ee(r).map(i=>({vertices:i.vertices.map(([c,a,l])=>[c+n[0],a+n[1],l+n[2]]),color:t}))}function Ao(e,n={}){let{center:o=[0,0,0],size:t=1,color:r}=n;switch(e){case"tetrahedron":return bn({center:o,size:t,color:r});case"cube":return xn({center:o,size:t,color:r});case"octahedron":return hn({center:o,size:t,color:r});case"dodecahedron":return Pn({center:o,size:t,color:r});case"icosahedron":return Mn({center:o,size:t,color:r});case"smallStellatedDodecahedron":return zn({center:o,size:t,color:r});case"greatDodecahedron":return En({center:o,size:t,color:r});case"greatStellatedDodecahedron":return Rn({center:o,size:t,color:r});case"greatIcosahedron":return kn({center:o,size:t,color:r});case"cuboctahedron":return ke({center:o,size:t,color:r});case"icosidodecahedron":return De({center:o,size:t,color:r});case"truncatedTetrahedron":return Le({center:o,size:t,color:r});case"truncatedCube":return Ne({center:o,size:t,color:r});case"truncatedOctahedron":return _e({center:o,size:t,color:r});case"truncatedDodecahedron":return Ge({center:o,size:t,color:r});case"truncatedIcosahedron":return $e({center:o,size:t,color:r});case"truncatedCuboctahedron":return Fe({center:o,size:t,color:r});case"truncatedIcosidodecahedron":return Ue({center:o,size:t,color:r});case"rhombicuboctahedron":return Be({center:o,size:t,color:r});case"rhombicosidodecahedron":return je({center:o,size:t,color:r});case"snubCube":return He({center:o,size:t,color:r});case"snubDodecahedron":return qe({center:o,size:t,color:r});case"rhombicDodecahedron":return Dn({center:o,size:t,color:r});case"rhombicTriacontahedron":return Ln({center:o,size:t,color:r});case"triakisTetrahedron":return Nn({center:o,size:t,color:r});case"triakisOctahedron":return _n({center:o,size:t,color:r});case"triakisIcosahedron":return $n({center:o,size:t,color:r});case"tetrakisHexahedron":return Gn({center:o,size:t,color:r});case"pentakisDodecahedron":return Fn({center:o,size:t,color:r});case"disdyakisDodecahedron":return Un({center:o,size:t,color:r});case"disdyakisTriacontahedron":return Bn({center:o,size:t,color:r});case"deltoidalIcositetrahedron":return jn({center:o,size:t,color:r});case"deltoidalHexecontahedron":return Hn({center:o,size:t,color:r});case"pentagonalIcositetrahedron":return qn({center:o,size:t,color:r});case"pentagonalHexecontahedron":return Xn({center:o,size:t,color:r});case"sphere":return Vn({center:o,size:t,color:r});case"cylinder":return Cn({center:o,radius:t,height:t*2,color:r});case"cone":return vn({center:o,radius:t,height:t*2,color:r});case"torus":return An({center:o,majorRadius:t,minorRadius:t*.3,color:r});case"pyramid":return Sn({center:o,radius:t,height:t*2,color:r});case"prism":return On({center:o,radius:t,height:t*2,color:r});case"antiprism":return Tn({center:o,radius:t,height:t*2,color:r});case"bipyramid":return In({center:o,radius:t,halfHeight:t,color:r});case"trapezohedron":return wn({center:o,radius:t,halfHeight:t,color:r});default:{let s=e;throw new Error(`Unknown geometry: ${String(s)}`)}}}var Qr=2200,Jr=2201,es=2202;function la(e,n){let o=0,t=1,r=1,s=2201,i=1/0,c=0,a=!1,l=null,u=!0,f=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(m){r=m},get weight(){return t},set weight(m){t=m},get time(){return o},set time(m){o=m},get isRunning(){return a},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return a=!0,d},stop(){return a=!1,o=0,c=0,l=null,d},reset(){return o=0,c=0,d},fadeIn(m){return l={from:0,to:1,elapsed:0,duration:m},t=0,d},fadeOut(m){return l={from:t,to:0,elapsed:0,duration:m},d},crossFadeTo(m,p){return d.fadeOut(p),m.fadeIn(p),d},crossFadeFrom(m,p){return m.fadeOut(p),d.fadeIn(p),d},setLoop(m,p){return s=m,i=p,d},setEffectiveTimeScale(m){return r=m,d},setEffectiveWeight(m){return t=m,d}};return d._internal={get clip(){return e},get time(){return o},get weight(){return t},get enabled(){return u},get paused(){return f},get running(){return a},get loopMode(){return s},get repetitions(){return i},get completedReps(){return c},set completedReps(m){c=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!a)return;if(l){l.elapsed+=m;let 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)){a=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(o+=m*r,s===2200)o>=p&&(o=d.clampWhenFinished?p:0,a=!1);else if(s===2201){if(o>=p){let g=o%p,b=Math.floor(o/p);c+=b,o=g,i!==1/0&&c>=i&&(o=d.clampWhenFinished?p:0,a=!1)}}else if(p>0){let g=p*2,b=o%g;if(o>=g){let P=Math.floor(o/g);c+=P,i!==1/0&&c>=i?(o=d.clampWhenFinished?p:0,a=!1):o=b}}}},sampleTime(){if(s===2202){let m=e.duration,p=m*2,g=o%p;return g<=m?g:p-g}return o}},d}function ua(e){return e._internal}function So(e,n){return typeof n=="number"?e[n]:e.find(o=>o.name===n)}function ns(e,n){let o=new Map;function t(l){let u=So(n.clips,l);if(!u)throw new Error(`GlyphAnimationMixer: no clip found for key "${l}". Available: ${n.clips.map(d=>d.name).join(", ")}`);let f=o.get(u.index);return f||(f=la(u,n),o.set(u.index,f)),f}function r(l){let u=So(n.clips,l);return u?o.get(u.index)??null:null}function s(l){let u=[];for(let g of o.values()){let b=ua(g);b.advance(l),b.running&&b.enabled&&u.push({internal:b,clip:b.clip})}if(u.length===0)return;if(u.length===1){let{internal:g,clip:b}=u[0],P=n.sample(b.name,g.sampleTime());e.setPolygons(P);return}let f=0;for(let{internal:g}of u)f+=g.weight;if(f<=0)return;let d=u.map(({internal:g,clip:b})=>({polygons:n.sample(b.name,g.sampleTime()),weight:g.weight/f})),m=d[0].polygons;if(m.length===0)return;let p=m.map((g,b)=>{let P=g.vertices.map((C,v)=>{let V=0,h=0,M=0;for(let{polygons:S,weight:y}of d){let x=S[b];if(!x)continue;let A=x.vertices[v];A&&(V+=A[0]*y,h+=A[1]*y,M+=A[2]*y)}return[V,h,M]});return{...g,vertices:P}});e.setPolygons(p)}function i(){for(let l of o.values())l.stop()}function c(l){let u=So(n.clips,l);u&&o.delete(u.index)}function a(){o.clear()}return{clipAction:t,existingAction:r,update:s,stopAllAction:i,uncacheClip:c,uncacheRoot:a}}var fa=/^[0-9A-Fa-f]{6}$/,ma=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function Pt(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",s=n?.palette??ma,i=n?.materialColors??{},c=n?.materialTextures??{},a=[],l=[],u=[],f=[],d=new Map,m=r,p,g=n?.includeObjects?new Set(n.includeObjects):null,b=n?.excludeObjects?new Set(n.excludeObjects):null,P=null,C=()=>P===null?g===null:!(g&&!g.has(P)||b&&b.has(P)),v=L=>L in i?i[L]:fa.test(L)?`#${L}`:(d.has(L)||(d.set(L,s[f.length%s.length]),f.push(L)),d.get(L)),V=e.split(`
2
+ `);for(let L of V)if(!(L.length===0||L.charCodeAt(0)===35)){if(L.startsWith("v ")){let z=L.trim().split(/\s+/);a.push([parseFloat(z[1]),parseFloat(z[2]),parseFloat(z[3])])}else if(L.startsWith("vt ")){let z=L.trim().split(/\s+/);l.push([parseFloat(z[1]),parseFloat(z[2])])}else if(L.startsWith("o "))P=L.trim().slice(2).trim();else if(L.startsWith("usemtl ")){let z=L.trim().split(/\s+/)[1];m=v(z),p=c[z]}else if(L.startsWith("f ")){if(!C())continue;let z=L.trim().split(/\s+/).slice(1),T=[],k=[];for(let N of z){let G=N.split("/");T.push(parseInt(G[0],10)-1);let _=G[1];if(_&&_.length>0){let $=parseInt(_,10)-1;k.push(Number.isFinite($)?$:null)}else k.push(null)}u.push({idx:T,uvIdx:k,color:m,texture:p})}}if(a.length===0||u.length===0)return da(f,e.length);let h=new Set;for(let L of u)for(let z of L.idx)h.add(z);let M=1/0,S=1/0,y=1/0,x=-1/0,A=-1/0,I=-1/0;for(let L of h){let z=a[L];z&&(z[0]<M&&(M=z[0]),z[0]>x&&(x=z[0]),z[1]<S&&(S=z[1]),z[1]>A&&(A=z[1]),z[2]<y&&(y=z[2]),z[2]>I&&(I=z[2]))}let R=Math.max(x-M,A-S,I-y),E=R>0?o/R:1,O=L=>Math.round(L*1e3)/1e3,w=a.map(([L,z,T])=>[O((T-y)*E+t),O((L-M)*E+t),O((z-S)*E+t)]),D=[];for(let{idx:L,uvIdx:z,color:T,texture:k}of u)for(let N=1;N<L.length-1;N++){let G=L[0],_=L[N],$=L[N+1],F=w[G],H=w[_],j=w[$];if(!F||!H||!j||F[0]===H[0]&&F[1]===H[1]&&F[2]===H[2]||F[0]===j[0]&&F[1]===j[1]&&F[2]===j[2]||H[0]===j[0]&&H[1]===j[1]&&H[2]===j[2])continue;let U;if(k){let q=z[0],Z=z[N],J=z[N+1];if(q!=null&&Z!=null&&J!=null){let ne=l[q],ie=l[Z],oe=l[J];ne&&ie&&oe&&(U=[ne,ie,oe])}}let B={vertices:[F,H,j],color:T};k&&(B.texture=k),U&&(B.uvs=U),D.push(B)}return{polygons:D,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:D.length,materials:f,sourceBytes:e.length}}}function da(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var Oo=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function Mt(e){let n={},o={},t=null;for(let r of e.split(`
3
+ `)){let s=r.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+/),c=parseFloat(i[1]),a=parseFloat(i[2]),l=parseFloat(i[3]);Number.isFinite(c)&&Number.isFinite(a)&&Number.isFinite(l)&&(n[t]=`#${Oo(c)}${Oo(a)}${Oo(l)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),c=i[i.length-1]?.replace(/\\+/g,"/");c&&c!=="map_Kd"&&(o[t]=c)}}}}return{colors:n,textures:o}}var cs={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},is={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function as(e){let n=globalThis.TextDecoder;return new n().decode(e)}function pa(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 i=decodeURIComponent(t),c=new Uint8Array(i.length);for(let a=0;a<i.length;a++)c[a]=i.charCodeAt(a)&255;return c}let r=globalThis.atob(t),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s}function ga(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 pa(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 ya(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,s=null;for(;t<e.byteLength;){let i=n.getUint32(t,!0),c=n.getUint32(t+4,!0),a=t+8;if(c===1313821514){let l=new Uint8Array(e,a,i);r=JSON.parse(as(l))}else c===5130562&&(s=new Uint8Array(e,a,i));t=a+i}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:s}}function To(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 s=cs[t.componentType],i=is[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let c=(r.byteOffset??0)+(t.byteOffset??0),a=t.count*i,l=n.buffer.slice(n.byteOffset+c,n.byteOffset+c+a*s),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:i}}function ha(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 ba(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 vt(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 s=cs[t.componentType],i=is[t.type];if(!s||!i)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let c=n.byteOffset+(r.byteOffset??0)+(t.byteOffset??0),a=r.byteStride??s*i,l=new DataView(n.buffer),u=new Array(t.count*i),f=0;for(let d=0;d<t.count;d++){let m=c+d*a;for(let p=0;p<i;p++){let g=ha(l,m+p*s,t.componentType);u[f++]=t.normalized?ba(g,t.componentType):g}}return{values:u,count:t.count,componentCount:i}}function xa(e,n,o){let t=[],r=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(o&&!i.uri.startsWith("data:"))try{t.push(new s.URL(i.uri,o).href)}catch{t.push(i.uri)}else t.push(i.uri);continue}if(i.bufferView!==void 0){let c=e.bufferViews?.[i.bufferView];if(!c){t.push("");continue}let a=c.byteOffset??0,l=n.subarray(a,a+c.byteLength),u=i.mimeType??"image/png",f=new s.Blob([l],{type:u}),d=s.URL.createObjectURL(f);t.push(d),r.push(d)}else t.push("")}return{urls:t,objectUrls:r}}function Pa(e,n){let o=new Map,t=e.materials??[];for(let r=0;r<t.length;r++){let s=t[r].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s]?.source;if(i===void 0)continue;let c=n[i];c&&o.set(r,c)}return o}function Ma(e,n){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let t=c=>Math.max(0,Math.min(1,c)),r=c=>Math.round(t(c)*255).toString(16).padStart(2,"0"),s=c=>Math.round(t(c)*255),i=t(o[3]??1);return i<1?`rgba(${s(o[0])}, ${s(o[1])}, ${s(o[2])}, ${Math.round(i*1e3)/1e3})`:`#${r(o[0])}${r(o[1])}${r(o[2])}`}var en=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Io(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 Ct(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 ls(e,n,o){let t=e?.[0]??0,r=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,c=n?.[1]??0,a=n?.[2]??0,l=n?.[3]??1,u=o?.[0]??1,f=o?.[1]??1,d=o?.[2]??1,m=i+i,p=c+c,g=a+a,b=i*m,P=i*p,C=i*g,v=c*p,V=c*g,h=a*g,M=l*m,S=l*p,y=l*g;return[(1-(v+h))*u,(P+y)*u,(C-S)*u,0,(P-y)*f,(1-(b+h))*f,(V+M)*f,0,(C+S)*d,(V-M)*d,(1-(b+v))*d,0,t,r,s,1]}function Va(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():ls(e.translation,e.rotation,e.scale)}function Ca(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function ts(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function us(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 Wn(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 va(e,n,o){let t=Wn(e),r=Wn(n),s=t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3];if(s<0&&(s=-s,r=[-r[0],-r[1],-r[2],-r[3]]),s>.9995)return Wn(us(t,r,o));let i=Math.acos(Math.max(-1,Math.min(1,s))),c=Math.sin(i),a=Math.sin((1-o)*i)/c,l=Math.sin(o*i)/c;return Wn([t[0]*a+r[0]*l,t[1]*a+r[1]*l,t[2]*a+r[2]*l,t[3]*a+r[3]*l])}function Aa(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 os(e){return e.matrix?e.matrix.slice():ls(e.translation,e.rotation,e.scale)}function Sa(e){let n=e.scene??0,o=e.scenes?.[n]?.nodes;return o&&o.length>0?o:[]}function rs(e,n){let o=e.nodes??[],t=new Array(o.length),r=new Set,s=(c,a)=>{if(c<0||c>=o.length)return;let l=Io(a,n[c]??en);t[c]=l,r.add(c);for(let u of o[c].children??[])s(u,l)},i=Sa(e);if(i.length>0)for(let c of i)s(c,en);for(let c=0;c<o.length;c++)r.has(c)||s(c,en);return t}function ss(e,n,o,t,r){if(o===void 0)return;let{values:s,count:i,componentCount:c}=vt(e,n,o);if(i!==r||c<1)return;let a=[];for(let l=0;l<i;l++){let u=[];for(let f=0;f<t;f++)u.push(s[l*c+f]??0);a.push(u)}return a}function Oa(e,n,o,t){if(o===void 0)return Array.from({length:t},()=>en.slice());let{values:r,componentCount:s,count:i}=vt(e,n,o);if(s!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${o} is not MAT4`);let c=[];for(let a=0;a<t;a++){let l=Math.min(a,i-1);c.push(r.slice(l*16,l*16+16))}return c}function Vt(e,n){let o=e.componentCount,t=e.interpolation==="CUBICSPLINE"?(n*3+1)*o:n*o;return e.output.slice(t,t+o)}function Ta(e,n,o){let t=e.input;if(t.length===0)return[];if(t.length===1||n<=t[0])return Vt(e,0);let r=t.length-1;if(n>=t[r])return Vt(e,r);let s=0,i=r;for(;s+1<i;){let d=s+i>>1;t[d]<=n?s=d:i=d}let c=t[s],a=t[s+1],l=a>c?(n-c)/(a-c):0,u=Vt(e,s),f=Vt(e,s+1);return e.interpolation==="STEP"?u:o==="rotation"?va(u,f,l):us(u,f,l)}function Ia(e,n,o,t){let r=e.animations??[];if(r.length===0||o.length===0)return;let s=(e.nodes??[]).map(m=>Aa(m)),i=s.map(os),c=rs(e,i),a=(e.skins??[]).map(m=>({joints:m.joints??[],inverseBindMatrices:Oa(e,n,m.inverseBindMatrices,m.joints?.length??0)})),l=[];for(let m=0;m<r.length;m++){let p=r[m],g=(p.samplers??[]).map(C=>{let v=vt(e,n,C.input),V=vt(e,n,C.output);return{input:v.values,output:V.values,componentCount:V.componentCount,interpolation:C.interpolation??"LINEAR"}}),b=[];for(let C of p.channels??[]){let v=C.target.node,V=C.target.path,h=g[C.sampler];v===void 0||!V||!h||V==="weights"||b.push({sampler:h,targetNode:v,path:V})}let P=b.reduce((C,v)=>{let V=v.sampler.input;return Math.max(C,V[V.length-1]??0)},0);l.push({info:{index:m,name:p.name??`animation_${m}`,duration:P,channelCount:b.length},channels:b})}let u=l.map(m=>m.info);if(u.length===0)return;let f=(m,p,g,b,P,C)=>{let v=t(m),V=t(p),h=t(g);if(v[0]===V[0]&&v[1]===V[1]&&v[2]===V[2]||v[0]===h[0]&&v[1]===h[1]&&v[2]===h[2]||V[0]===h[0]&&V[1]===h[1]&&V[2]===h[2])return null;let M={vertices:[v,V,h],color:b};return P&&(M.texture=P),C&&(M.uvs=C),M};return{clips:u,sample:(m,p)=>{let g=typeof m=="number"?l[m]:l.find(h=>h.info.name===m);if(!g)return[];let b=g.info.duration,P=b>0?(p%b+b)%b:Math.max(0,p),C=s.map(h=>({translation:h.translation.slice(),rotation:h.rotation.slice(),scale:h.scale.slice(),matrix:h.matrix?h.matrix.slice():void 0}));for(let h of g.channels){let M=C[h.targetNode];if(!M)continue;let S=Ta(h.sampler,P,h.path);M.matrix=void 0,h.path==="translation"?M.translation=S.slice(0,3):h.path==="rotation"?M.rotation=Wn(S.slice(0,4)):h.path==="scale"&&(M.scale=S.slice(0,3))}let v=rs(e,C.map(os)),V=[];for(let h of o){let M=[];if(h.skinIndex!==void 0&&h.joints&&h.weights&&a[h.skinIndex]){let S=a[h.skinIndex];for(let y=0;y<h.positions.length;y++){let x=h.positions[y],A=[0,0,0],I=0,R=h.joints[y]??[],E=h.weights[y]??[];for(let O=0;O<4;O++){let w=E[O]??0;if(w<=0)continue;let D=Math.round(R[O]??0),L=S.joints[D],z=v[L],T=S.inverseBindMatrices[D];if(!z||!T)continue;let k=Io(z,T);A=Ca(A,ts(Ct(k,x),w)),I+=w}M.push(I>0?ts(A,1/I):Ct(h.meshBindWorld,x))}}else{let S=h.meshNode!==null?v[h.meshNode]??h.meshBindWorld:h.meshBindWorld;for(let y of h.positions)M.push(Ct(S,y))}for(let S=0;S+2<h.indices.length;S+=3){let y=h.indices[S],x=h.indices[S+1],A=h.indices[S+2],I=M[y],R=M[x],E=M[A];if(!I||!R||!E)continue;let O;if(h.uvs&&h.texture){let D=h.uvs[y],L=h.uvs[x],z=h.uvs[A];D&&L&&z&&(O=[D,L,z])}let w=f(I,R,E,h.color,h.texture,O);w&&V.push(w)}}return V}}}function At(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",s=n?.materialColors??{},i=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,c=i.byteLength,a,l;if(i.byteLength>=4&&new DataView(i).getUint32(0,!0)===1179937895){let T=ya(i);if(a=T.doc,!T.bin)throw new Error("parseGltf: GLB has no binary chunk");l=T.bin}else a=JSON.parse(as(new Uint8Array(i))),l=ga(a,n?.resolveBuffer);let{urls:u,objectUrls:f}=xa(a,l,n?.baseUrl),d=Pa(a,u),m=[],p=[],g=(a.meshes??[]).map((T,k)=>T.name??`mesh_${k}`),b=(a.materials??[]).map((T,k)=>T.name??`material_${k}`);function P(T,k,N){let G=a.meshes?.[T];if(G)for(let _ of G.primitives){if((_.mode??4)!==4)continue;let F=_.material!==void 0?a.materials?.[_.material]?.name:void 0,j=(F?s[F]:void 0)??Ma(_.material!==void 0?a.materials?.[_.material]:void 0,r),U=_.material!==void 0?d.get(_.material):void 0,{array:B,count:q}=To(a,l,_.attributes.POSITION);if(!(B instanceof Float32Array))continue;let Z=[],J=[];for(let Q=0;Q<q;Q++){let X=[B[Q*3],B[Q*3+1],B[Q*3+2]];Z.push(X),J.push(Ct(k,X))}let ne=null,ie=_.attributes.TEXCOORD_0;if(U&&ie!==void 0){let{array:Q,count:X}=To(a,l,ie);ne=[];let K=1;Q instanceof Uint8Array?K=1/255:Q instanceof Uint16Array&&(K=1/65535);for(let le=0;le<X;le++){let Pe=Q[le*2]*K,Te=Q[le*2+1]*K;ne.push([Pe,1-Te])}}let oe;if(_.indices!==void 0){let{array:Q,count:X}=To(a,l,_.indices);oe=[];for(let K=0;K<X;K++)oe.push(Number(Q[K]))}else oe=J.map((Q,X)=>X);if((a.animations?.length??0)>0){let Q=ss(a,l,_.attributes.JOINTS_0,4,q),X=ss(a,l,_.attributes.WEIGHTS_0,4,q);p.push({meshNode:N,meshBindWorld:k,skinIndex:N!==null?a.nodes?.[N]?.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]],le=J[oe[Q+2]];if(!X||!K||!le)continue;let Pe;if(ne&&U){let Te=ne[oe[Q]],We=ne[oe[Q+1]],Ye=ne[oe[Q+2]];Te&&We&&Ye&&(Pe=[Te,We,Ye])}m.push({v0:X,v1:K,v2:le,color:j,texture:U,uvs:Pe})}}}function C(T,k){let N=a.nodes?.[T];if(!N)return;let G=Io(k,Va(N));typeof N.mesh=="number"&&P(N.mesh,G,T);for(let _ of N.children??[])C(_,G)}let v=a.scene??0,V=a.scenes?.[v]?.nodes;if(V&&V.length>0)for(let T of V)C(T,en);else for(let T=0;T<(a.meshes?.length??0);T++)P(T,en,null);let h=wa(f);if(m.length===0)return{polygons:[],objectUrls:f,dispose:h,warnings:[],metadata:{triangleCount:0,meshes:g,materials:b,sourceBytes:c}};let M=1/0,S=1/0,y=1/0,x=-1/0,A=-1/0,I=-1/0;for(let T of m)for(let k of[T.v0,T.v1,T.v2])k[0]<M&&(M=k[0]),k[0]>x&&(x=k[0]),k[1]<S&&(S=k[1]),k[1]>A&&(A=k[1]),k[2]<y&&(y=k[2]),k[2]>I&&(I=k[2]);let R=Math.max(x-M,A-S,I-y),E=R>0?o/R:1,O=T=>Math.round(T*1e3)/1e3,D=(n?.upAxis??"y")==="z"?([T,k,N])=>[O((T-M)*E+t),O((k-S)*E+t),O((N-y)*E+t)]:([T,k,N])=>[O((N-y)*E+t),O((T-M)*E+t),O((k-S)*E+t)],L=Ia(a,l,p,D),z=[];for(let T of m){let k=D(T.v0),N=D(T.v1),G=D(T.v2);if(k[0]===N[0]&&k[1]===N[1]&&k[2]===N[2]||k[0]===G[0]&&k[1]===G[1]&&k[2]===G[2]||N[0]===G[0]&&N[1]===G[1]&&N[2]===G[2])continue;let _={vertices:[k,N,G],color:T.color};T.texture&&(_.texture=T.texture),T.uvs&&(_.uvs=T.uvs),z.push(_)}return{polygons:z,animation:L,objectUrls:f,dispose:h,warnings:[],metadata:{triangleCount:z.length,meshes:g,materials:b,animations:L?.clips,sourceBytes:c}}}function wa(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 Yn(e){return e.material?.texture??e.texture}function ys(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function za(e,n){return new Promise((o,t)=>{let r=new n,s=!1,i=c=>{s||(s=!0,c())};r.decoding="async",r.onload=()=>i(()=>o(r)),r.onerror=()=>i(()=>t(new Error(`texture load failed: ${e}`))),r.src=e,typeof r.decode=="function"&&r.decode().then(()=>i(()=>o(r)),()=>{})})}async function hs(e,n,o){try{let t=await za(e,n.Image),r=Math.max(0,Math.floor(t.naturalWidth||t.width||0)),s=Math.max(0,Math.floor(t.naturalHeight||t.height||0));if(r<=0||s<=0||r*s>o)return null;let i=n.createCanvas();i.width=r,i.height=s;let c=i.getContext("2d",{willReadFrequently:!0});if(!c)return null;c.drawImage(t,0,0,r,s);let a=c.getImageData(0,0,r,s).data;return{width:r,height:s,data:a,lowDetail:Ea(r,s,a)}}catch{return null}}function fs(e,n,o,t,r,s){let i=(t*n+o)*4,c=(s*n+r)*4;return Math.max(Math.abs((e[i]??0)-(e[c]??0)),Math.abs((e[i+1]??0)-(e[c+1]??0)),Math.abs((e[i+2]??0)-(e[c+2]??0)))}function Ea(e,n,o){let t=Math.max(1,Math.floor(Math.max(e,n)/128)),r=0,s=0,i=0;for(let c=0;c<n;c+=t)for(let a=0;a<e;a+=t){if(a+t<e){let l=fs(o,e,a,c,a+t,c);i+=l,r++,l>32&&s++}if(c+t<n){let l=fs(o,e,a,c,a,c+t);i+=l,r++,l>32&&s++}}return r>0&&s/r<=.045&&i/r<=10}function ms(e,n,o){return Math.max(n,Math.min(o,e))}function bs(e,n){let o=n[0],t=1-n[1];if(!Number.isFinite(o)||!Number.isFinite(t))return null;let r=ms(Math.floor(o*e.width),0,e.width-1),i=(ms(Math.floor(t*e.height),0,e.height-1)*e.width+r)*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 Se(e,n,o,t,r,s){return[e[0]*t+n[0]*r+o[0]*s,e[1]*t+n[1]*r+o[1]*s]}function Ra(e){let[n,o,t]=e;return[Se(n,o,t,1/3,1/3,1/3),Se(n,o,t,.8,.1,.1),Se(n,o,t,.1,.8,.1),Se(n,o,t,.1,.1,.8),Se(n,o,t,.45,.45,.1),Se(n,o,t,.45,.1,.45),Se(n,o,t,.1,.45,.45)]}function ka(e){let[n,o,t]=e,r=Ra(e);for(let s=1;s<6;s++)for(let i=1;i<6-s;i++){let c=6-s-i;c<=0||r.push(Se(n,o,t,s/6,i/6,c/6))}return r}function xs(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 ds(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 ps(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 Da(){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 La(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 gs(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 Na(e,n,o,t){let r=xs(e);if(r.length===0||!t&&!n.lowDetail)return null;let s=Da();for(let i of r)for(let c of ka(i.uvs)){let a=bs(n,c);if(!a)return null;La(s,a)}return s.count===0?null:ds(s.min,s.max,o)?ps(gs(s)):t||!ds(s.min,s.max,32)?null:ps(gs(s))}function _a(e,n){let{texture:o,material:t,uvs:r,textureTriangles:s,...i}=e;return{...i,color:n}}async function Ps(e,n={}){if(n.enabled===!1)return null;let o=ys();if(!o)return null;let t=e.filter(a=>Yn(a)&&xs(a).length>0);if(t.length===0)return null;let r=n.maxTexturePixels??16777216,s=new Map;await Promise.all(Array.from(new Set(t.map(a=>Yn(a)))).map(async a=>{s.set(a,await hs(a,o,r))}));let i=n.colorTolerance??2,c=n.colorTolerance!==void 0;return{bake(a){let l=!1,u=a.map(f=>{let d=Yn(f);if(!d)return f;let m=s.get(d);if(!m)return f;let p=Na(f,m,i,c);return p?(l=!0,_a(f,p)):f});return{polygons:l?u:a,changed:l}}}}async function Ms(e,n={}){let o=await Ps(e,n);return o?o.bake(e).polygons:e}async function St(e,n={}){let o=await Ps(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,s){return o.bake(e.animation.sample(r,s)).polygons}}:e.animation}}async function Vs(e,n={}){let o=new Map,t=ys();if(!t)return o;let r=n.maxTexturePixels??16777216,s=new Set;for(let i of e){let c=Yn(i);c&&s.add(c)}return await Promise.all([...s].map(async i=>{let c=await hs(i,t,r);c&&o.set(i,c)})),o}function Cs(e,n,o){return bs(e,[n,o])}function vs(e){return Yn(e)}var Ga=[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 $a(e){let n=e>>0&255,o=e>>8&255,t=e>>16&255;return[n,o,t]}function wo(e){return(e&255).toString(16).padStart(2,"0")}function Ss(e,n,o){return`#${wo(e)}${wo(n)}${wo(o)}`}function Fa(e,n,o,t){if(t>=255)return Ss(e,n,o);let r=Math.round(Math.max(0,Math.min(255,t))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${o}, ${r})`}var Ua=542658390;function Ot(e,n){let o=n?.targetSize??60,t=n?.gridShift??0,r=e.byteLength;if(e.byteLength<8)return nn(r,["parseVox: buffer too small to be a valid .vox file"]);let s=new DataView(e);if(s.getUint32(0,!0)!==Ua)return nn(r,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return nn(r,["parseVox: buffer too small for MAIN chunk"]);if(As(s,8)!=="MAIN")return nn(r,["parseVox: expected MAIN chunk at offset 8"]);let l=20+s.getUint32(12,!0),u=l+s.getUint32(16,!0),f=[],d=[],m=null;for(;l<u&&l+12<=e.byteLength;){let z=As(s,l),T=s.getUint32(l+4,!0),k=s.getUint32(l+8,!0),N=l+12,G=N+T+k;if(z==="SIZE"){if(T>=12&&N+12<=e.byteLength){let _=s.getUint32(N,!0),$=s.getUint32(N+4,!0),F=s.getUint32(N+8,!0);f.push({sx:_,sy:$,sz:F})}}else if(z==="XYZI"){if(T>=4&&N+4<=e.byteLength){let _=s.getUint32(N,!0),$=[],F=Math.min(_,Math.floor((T-4)/4));for(let H=0;H<F;H++){let j=N+4+H*4;$.push({x:s.getUint8(j),y:s.getUint8(j+1),z:s.getUint8(j+2),colorIndex:s.getUint8(j+3)})}d.push($)}}else if(z==="RGBA"&&T>=1024&&N+1024<=e.byteLength){m=[];for(let _=0;_<256;_++){let $=N+_*4,F=s.getUint8($),H=s.getUint8($+1),j=s.getUint8($+2),U=s.getUint8($+3);m.push(Fa(F,H,j,U))}}l=G}let p=[],g=new Set;for(let z of d)for(let T of z){if(T.colorIndex===0)continue;let k=`${T.x},${T.y},${T.z}`;g.has(k)||(g.add(k),p.push(T))}if(p.length===0)return nn(r,[]);let b=z=>{let T=z-1;if(m!==null)return m[T]??"#888888";let k=Ga[z]??0,[N,G,_]=$a(k);return Ss(N,G,_)},P=(z,T,k)=>g.has(`${z},${T},${k}`),C=new Map,v=(z,T,k,N,G)=>{let _=`${z}:${T}:${G}`,$=C.get(_);$||($=new Set,C.set(_,$)),$.add(`${k},${N}`)};for(let z of p){let{x:T,y:k,z:N}=z,G=b(z.colorIndex);P(T+1,k,N)||v(0,T+1,k,N,G),P(T-1,k,N)||v(1,T,k,N,G),P(T,k+1,N)||v(2,k+1,T,N,G),P(T,k-1,N)||v(3,k,T,N,G),P(T,k,N+1)||v(4,N+1,T,k,G),P(T,k,N-1)||v(5,N,T,k,G)}function V(z){let T=new Set,k=[],N=1/0,G=-1/0,_=1/0,$=-1/0;for(let F of z){let[H,j]=F.split(","),U=+H,B=+j;U<N&&(N=U),U>G&&(G=U),B<_&&(_=B),B>$&&($=B)}for(let F=_;F<=$;F++)for(let H=N;H<=G;H++){let j=`${H},${F}`;if(!z.has(j)||T.has(j))continue;let U=1;for(;H+U<=G;){let q=`${H+U},${F}`;if(!z.has(q)||T.has(q))break;U++}let B=1;e:for(;F+B<=$;){for(let q=0;q<U;q++){let Z=`${H+q},${F+B}`;if(!z.has(Z)||T.has(Z))break e}B++}for(let q=0;q<B;q++)for(let Z=0;Z<U;Z++)T.add(`${H+Z},${F+q}`);k.push({u:H,v:F,w:U,h:B})}return k}let h=(z,T,k,N,G,_)=>{let $=k+G,F=N+_;switch(z){case 0:return[[T,k,N],[T,$,N],[T,$,F],[T,k,F]];case 1:return[[T,$,N],[T,k,N],[T,k,F],[T,$,F]];case 2:return[[k,T,N],[k,T,F],[$,T,F],[$,T,N]];case 3:return[[$,T,N],[$,T,F],[k,T,F],[k,T,N]];case 4:return[[k,N,T],[$,N,T],[$,F,T],[k,F,T]];default:return[[k,F,T],[$,F,T],[$,N,T],[k,N,T]]}},M=[];for(let[z,T]of C){let k=z.indexOf(":"),N=z.indexOf(":",k+1),G=+z.slice(0,k),_=+z.slice(k+1,N),$=z.slice(N+1);for(let{u:F,v:H,w:j,h:U}of V(T))M.push({vertices:h(G,_,F,H,j,U),color:$})}if(M.length===0)return nn(r,[]);let S=1/0,y=1/0,x=1/0,A=-1/0,I=-1/0,R=-1/0;for(let z of M)for(let T of z.vertices)T[0]<S&&(S=T[0]),T[0]>A&&(A=T[0]),T[1]<y&&(y=T[1]),T[1]>I&&(I=T[1]),T[2]<x&&(x=T[2]),T[2]>R&&(R=T[2]);let E=Math.max(A-S,I-y,R-x),O=E>0?o/E:1,w=z=>Math.round(z*1e3)/1e3,D=z=>[w((z[0]-S)*O+t),w((z[1]-y)*O+t),w((z[2]-x)*O+t)],L=M.map(({vertices:z,color:T})=>({vertices:z.map(D),color:T}));return{polygons:L,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:L.length,sourceBytes:r,voxelCount:p.length}}}function As(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 nn(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var Ba="#888888";var ja=/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/,Xe="COLOR=";function Is(e,n,o){let t=n??o;if(!Number.isFinite(t))throw new Error(`parseStl: ${e} must be finite`);return t}function Ha(e,n,o){let t=Is(e,n,o);if(t<=0)throw new Error(`parseStl: ${e} must be greater than 0`);return t}function qa(e){if(e===void 0||e==="z"||e==="y")return e??"z";throw new Error('parseStl: upAxis must be "z" or "y"')}function Xa(e){let n=e??Ba;if(typeof n!="string"||n.trim().length===0)throw new Error("parseStl: defaultColor must be a non-empty string");return n}function Wa(e){if(typeof e=="string")return null;if(e instanceof Uint8Array)return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new Error("parseStl: source must be an ArrayBuffer, Uint8Array, or ASCII string")}function ws(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Tt(e,n){return[e.getFloat32(n,!0),e.getFloat32(n+4,!0),e.getFloat32(n+8,!0)]}function It(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Os(e){let n=e.trim().split(/\s+/);if(n.length!==3||!n.every(t=>ja.test(t)))return null;let o=[Number(n[0]),Number(n[1]),Number(n[2])];return It(o)?o:null}function Ya(e){let n="";for(let t of e)t!==0&&(n+=t>=32&&t<=126?String.fromCharCode(t):" ");return n.replace(/\s+/g," ").trim()||void 0}function zo(e){return Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")}function zs(e,n,o,t=255){if(t>=255)return`#${zo(e)}${zo(n)}${zo(o)}`;let r=Math.round(t/255*1e3)/1e3;return`rgba(${e}, ${n}, ${o}, ${r})`}function Eo(e){return Math.round(e/31*255)}function Ka(e){for(let n=0;n<80-Xe.length-4;n+=1){let o=!0;for(let c=0;c<Xe.length;c+=1)if(e.getUint8(n+c)!==Xe.charCodeAt(c)){o=!1;break}if(!o)continue;let t=e.getUint8(n+Xe.length),r=e.getUint8(n+Xe.length+1),s=e.getUint8(n+Xe.length+2),i=e.getUint8(n+Xe.length+3);return{defaultColor:zs(t,r,s,i),alpha:Math.round(i/255*1e3)/1e3,alphaByte:i}}return null}function Za(e,n){if((e&32768)!==0)return{color:n.defaultColor,usesDefaultColor:!0};let o=Eo(e&31),t=Eo(e>>5&31),r=Eo(e>>10&31);return{color:zs(o,t,r,n.alphaByte),usesDefaultColor:!1}}function Qa(e){let n=[],o=/^\s*solid(?:\s+([^\r\n]*?))?\s*$/gim,t=/^\s*endsolid\b[^\r\n]*$/gim,r;for(;r=o.exec(e);)n.push({index:r.index,kind:"start",name:(r[1]??"").trim()});for(;r=t.exec(e);)n.push({index:r.index,kind:"end"});return n.sort((s,i)=>s.index-i.index||(s.kind==="end"?-1:1))}function Ja(e){let n=Math.min(e.byteLength,1024);for(let o=84;o<n;o+=1){let t=e[o];if(t===0||t<9||t>13&&t<32||t>126)return!0}return!1}function el(e){let n=ws(e.subarray(0,Math.min(e.byteLength,512))).trimStart().toLowerCase();return!n.startsWith("solid")&&!n.startsWith("facet")?!1:!Ja(e)}function nl(e){if(e.byteLength<84)return null;let o=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0),t=84+o*50;if(t===e.byteLength)return{triangleCount:o,declaredTriangleCount:o,trailingBytes:0};if(el(e))return null;if(t<e.byteLength)return{triangleCount:o,declaredTriangleCount:o,trailingBytes:e.byteLength-t};let r=e.byteLength-84;return r>0&&r%50===0?{triangleCount:r/50,declaredTriangleCount:o,trailingBytes:0}:null}function tl(e,n,o){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),{triangleCount:r,declaredTriangleCount:s,trailingBytes:i}=n;s!==r&&o.push(`parseStl: binary STL declared ${s} triangles but contains ${r} complete triangle record${r===1?"":"s"}`),i>0&&o.push(`parseStl: ignored ${i} trailing binary byte${i===1?"":"s"}`);let c=Ya(e.subarray(0,80)),a=Ka(t),l=0,u=0,f=[];for(let d=0,m=84;d<r;d+=1,m+=50){let p=Tt(t,m),g=[Tt(t,m+12),Tt(t,m+24),Tt(t,m+36)];if(!g.every(It))throw new Error(`parseStl: non-finite coordinate in binary triangle ${d}`);let b=t.getUint16(m+48,!0),P=a?Za(b,a):null;P&&(P.usesDefaultColor?u+=1:l+=1),f.push({normal:It(p)?p:null,hasIgnoredNormal:!It(p),color:P?.color,vertices:g,hasIgnoredAttribute:!a&&b!==0})}return{format:"binary",facets:f,binaryHeader:c,color:a?{format:"magics",defaultColor:a.defaultColor,alpha:a.alpha,coloredTriangleCount:l,defaultColorTriangleCount:u}:void 0}}function Ts(e,n){let o=[],t=/^\s*facet\s+normal\s+([^\r\n]+)([\s\S]*?)^\s*endfacet\b[^\r\n]*$/gim,r=/^\s*vertex\s+([^\r\n]+)/gim,s=/^\s*facet\s+normal\b/gim,i=Qa(e),c=0,a,l=0;for(;s.exec(e);)l+=1;let u=0,f=0,d=0,m;for(;m=t.exec(e);){for(u+=1;c<i.length&&i[c].index<m.index;){let C=i[c];a=C.kind==="start"?C.name:void 0,c+=1}let p=Os(m[1]);p||(d+=1);let g=[],b=!1;r.lastIndex=0;let P;for(;P=r.exec(m[2]);){let C=Os(P[1]);if(!C){b=!0;break}g.push(C)}if(b||g.length!==3){f+=1;continue}o.push({normal:p,hasIgnoredNormal:!p,solidName:a,vertices:[g[0],g[1],g[2]]})}return f+=Math.max(0,l-u),f>0&&n.push(`parseStl: skipped ${f} malformed ASCII facet${f===1?"":"s"}`),d>0&&n.push(`parseStl: ignored ${d} malformed ASCII facet normal${d===1?"":"s"}`),{format:"ascii",facets:o}}function tn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function zt(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 Ro(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Es(e){return Math.hypot(e[0],e[1],e[2])}function ol(e){let n=zt(tn(e[1],e[0]),tn(e[2],e[0]));return Es(n)<=1e-8}function wt(e){let n=Es(e);return n<=1e-8?null:[e[0]/n,e[1]/n,e[2]/n]}function rl(e){let n=o=>Object.is(o,-0)?0:o;return`${n(e[0])},${n(e[1])},${n(e[2])}`}function sl(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function ko(e,n){return n?[e.vertices[0],e.vertices[2],e.vertices[1]]:e.vertices}function cl(e,n,o){let t=0;for(let r of n.facets){let[s,i,c]=ko(e[r],o[r]);t+=Ro(s,zt(i,c))/6}return t}function il(e,n,o){if(n.facets.length<8)return null;let t=0,r=0;for(let i of n.facets){let c=e[i],a=c.normal?wt(c.normal):null;if(!a)continue;let l=ko(c,o[i]),u=wt(zt(tn(l[1],l[0]),tn(l[2],l[0])));if(!u)continue;let f=Ro(u,a);f>=.95?t+=1:f<=-.95&&(r+=1)}let s=t+r;return s/n.facets.length<.75?null:r/s>=.9?"opposed":t/s>=.9?"aligned":null}function al(e){let n=new Map,o=e.map(()=>[]);for(let u=0;u<e.length;u+=1){let f=e[u].vertices.map(rl);for(let d=0;d<3;d+=1){let m=f[d],p=f[(d+1)%3],g=sl(m,p),b=n.get(g),P={facetIndex:u,from:m,to:p};b?b.push(P):n.set(g,[P])}}let t=0;for(let u of n.values()){if(u.length>2&&(t+=1),u.length<2)continue;let[f,...d]=u;for(let m of d){let p=f.from===m.from&&f.to===m.to;o[f.facetIndex].push({to:m.facetIndex,flipDiffers:p}),o[m.facetIndex].push({to:f.facetIndex,flipDiffers:p})}}let r=new Array(e.length).fill(!1),s=new Array(e.length).fill(-1),i=[],c=0;for(let u=0;u<e.length;u+=1){if(s[u]>=0)continue;let f=i.length,d={facets:[],conflicts:0,boundaryEdges:0,nonManifoldEdges:0,flippedOutward:!1,flippedToSuppliedNormals:!1};i.push(d),s[u]=f;let m=[u];for(let p=0;p<m.length;p+=1){let g=m[p];d.facets.push(g);for(let b of o[g]){let P=r[g]!==b.flipDiffers;s[b.to]<0?(s[b.to]=f,r[b.to]=P,m.push(b.to)):r[b.to]!==P&&g<b.to&&(d.conflicts+=1,c+=1)}}}for(let u of n.values()){let f=i[s[u[0].facetIndex]];u.length===1?f.boundaryEdges+=1:u.length>2&&(f.nonManifoldEdges+=1)}for(let u of i){if(u.nonManifoldEdges>0||u.conflicts>0){for(let d of u.facets)r[d]=!1;continue}if(u.boundaryEdges>0){if(il(e,u,r)==="opposed"){for(let d of u.facets)r[d]=!r[d];u.flippedToSuppliedNormals=!0}continue}if(cl(e,u,r)<-1e-10){for(let d of u.facets)r[d]=!r[d];u.flippedOutward=!0}}let a=0;return{facets:e.map((u,f)=>r[f]?(a+=1,{...u,vertices:ko(u,!0)}):u),repairedCount:a,componentCount:i.length,outwardComponentCount:i.filter(u=>u.flippedOutward).length,suppliedNormalComponentCount:i.filter(u=>u.flippedToSuppliedNormals).length,conflictCount:c,nonManifoldEdgeCount:t}}function ll(e,n,o,t,r){let s=i=>Math.round(i*1e3)/1e3;return r==="y"?[s((e[2]-n[2])*o+t),s((e[0]-n[0])*o+t),s((e[1]-n[1])*o+t)]:[s((e[0]-n[0])*o+t),s((e[1]-n[1])*o+t),s((e[2]-n[2])*o+t)]}function ul(e){if(e.every(r=>r.solidName===void 0))return;let n=[],o=e[0]?.solidName??"",t=0;for(let r=1;r<=e.length;r+=1){let s=e[r]?.solidName??"";r<e.length&&s===o||(n.push({name:o,start:t,count:r-t}),o=s,t=r)}return n}function fl(e){if(!e)return;let n=[],o=new Set;for(let t of e)!t.name||o.has(t.name)||(o.add(t.name),n.push(t.name));return n.length>0?n:void 0}function Et(e,n){let o=Ha("targetSize",n?.targetSize,60),t=Is("gridShift",n?.gridShift,1),r=Xa(n?.defaultColor),s=qa(n?.upAxis),i=[],c=Wa(e),a=typeof e=="string"?e.length:c.byteLength;if(a===0||typeof e=="string"&&e.trim().length===0)throw new Error("parseStl: empty input");let l=c?nl(c):null,u=typeof e=="string"?Ts(e,i):l?tl(c,l,i):Ts(ws(c),i),f=0,d=0,m=0,p=[];for(let y of u.facets){if(y.hasIgnoredAttribute&&(f+=1),y.hasIgnoredNormal&&u.format==="binary"&&(d+=1),ol(y.vertices)){m+=1;continue}p.push(y)}let g=al(p),b=0;for(let y of g.facets){let x=wt(zt(tn(y.vertices[1],y.vertices[0]),tn(y.vertices[2],y.vertices[0]))),A=y.normal?wt(y.normal):null;x&&A&&Ro(x,A)<.95&&(b+=1)}if(f>0&&i.push(`parseStl: ignored non-zero binary attribute byte count on ${f} triangle${f===1?"":"s"}`),d>0&&i.push(`parseStl: ignored ${d} non-finite binary normal${d===1?"":"s"}`),m>0&&i.push(`parseStl: skipped ${m} degenerate triangle${m===1?"":"s"}`),g.repairedCount>0&&i.push(`parseStl: repaired winding on ${g.repairedCount} triangle${g.repairedCount===1?"":"s"}`),g.outwardComponentCount>0&&i.push(`parseStl: oriented ${g.outwardComponentCount} closed component${g.outwardComponentCount===1?"":"s"} outward`),g.suppliedNormalComponentCount>0&&i.push(`parseStl: oriented ${g.suppliedNormalComponentCount} open component${g.suppliedNormalComponentCount===1?"":"s"} from supplied normals`),g.conflictCount>0&&i.push(`parseStl: found ${g.conflictCount} inconsistent shared-edge winding constraint${g.conflictCount===1?"":"s"}`),g.nonManifoldEdgeCount>0&&i.push(`parseStl: found ${g.nonManifoldEdgeCount} non-manifold shared edge${g.nonManifoldEdgeCount===1?"":"s"}`),b>0&&i.push(`parseStl: ${b} supplied normal${b===1?" disagrees":"s disagree"} with triangle winding`),p.length===0)throw u.facets.length===0?new Error(`parseStl: no valid ${u.format} facets`):new Error("parseStl: no valid facets after filtering");let P=[1/0,1/0,1/0],C=[-1/0,-1/0,-1/0];for(let y of g.facets)for(let x of y.vertices)for(let A=0;A<3;A+=1)x[A]<P[A]&&(P[A]=x[A]),x[A]>C[A]&&(C[A]=x[A]);let v=Math.max(C[0]-P[0],C[1]-P[1],C[2]-P[2]),V=v>0?o/v:1,h=ul(g.facets),M=fl(h),S=g.facets.map(y=>({vertices:y.vertices.map(x=>ll(x,P,V,t,s)),color:y.color??r}));return{polygons:S,objectUrls:[],dispose:()=>{},warnings:i,metadata:{triangleCount:S.length,meshes:M,materials:[],sourceBytes:a,stlHeader:u.binaryHeader,stlColor:u.color,stlSolids:h,stlTopology:{componentCount:g.componentCount,repairedTriangleCount:g.repairedCount,outwardComponentCount:g.outwardComponentCount,suppliedNormalComponentCount:g.suppliedNormalComponentCount,inconsistentSharedEdgeCount:g.conflictCount,nonManifoldSharedEdgeCount:g.nonManifoldEdgeCount}}}}var Oe="loadMesh";function Rt(e,n){let o=mt(e.polygons,{meshResolution:n?.meshResolution});return o.length===e.polygons.length?e:{...e,polygons:o}}async function Rs(e,n){let o=n?.solidTextureSamples;return o===!1?e:St(e,typeof o=="object"?o:void 0)}function ml(e){let n=e.split("?")[0].split("#")[0],o=n.lastIndexOf(".");return o<0?"":n.slice(o+1).toLowerCase()}async function ks(e,n){let o=ml(e);if(o==="mtl")throw new Error(`${Oe}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let t=globalThis.fetch;if(!t)throw new Error(`${Oe}: no fetch() in this environment`);let r=n?.baseUrl??e;if(o==="obj"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.text(),c=n?.objOptions;if(n?.mtlUrl){let l=await t(n.mtlUrl);if(!l.ok)throw new Error(`${Oe}: ${n.mtlUrl} \u2192 ${l.status}`);let u=await l.text(),{colors:f,textures:d}=Mt(u),m={},p=globalThis.URL,g=globalThis.document?.baseURI,b=n.mtlUrl;if(p&&g)try{b=new p(n.mtlUrl,g).toString()}catch{}for(let[P,C]of Object.entries(d)){if(p)try{m[P]=new p(C,b).toString();continue}catch{}let v=n.mtlUrl.lastIndexOf("/"),V=v>=0?n.mtlUrl.slice(0,v+1):"";m[P]=C.startsWith("/")||/^https?:\/\//.test(C)?C:V+C}c={...c??{},materialColors:{...f,...c?.materialColors??{}},materialTextures:{...m,...c?.materialTextures??{}}}}let a=Pt(i,c);return Rt(await Rs(a,n),n)}if(o==="glb"||o==="gltf"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),c=At(i,{baseUrl:r,...n?.gltfOptions??{}});return Rt(await Rs(c,n),n)}if(o==="vox"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return Rt(Ot(i,n?.voxOptions),n)}if(o==="stl"){let s=await t(e);if(!s.ok)throw new Error(`${Oe}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return Rt(Et(i,n?.stlOptions),n)}throw new Error(`${Oe}: unsupported extension ".${o}" (supported: obj, glb, gltf, vox, stl)`)}function Ds(e,n,o,t,r=.5,s=.5,i=.4){let c=4/(e[2]+3),a=Math.min(n,o)*i,l=n*r+e[0]*a*t*c,u=o*s-e[1]*a*c;return[l,u,e[2]]}function dl(e){let[n,o,t]=[e.vertices[0],e.vertices[1],e.vertices[2]],r=o[0]-n[0],s=o[1]-n[1],i=o[2]-n[2],c=t[0]-n[0],a=t[1]-n[1],l=t[2]-n[2];return[s*l-i*a,i*c-r*l,r*a-s*c]}function pl(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 Ls(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 gl(e,n=0){if(n<=0){let i=new Set,c=[];for(let a of e){let l=[[0,1],[1,2],[2,0]];for(let[u,f]of l){let d=a.vertices[u],m=a.vertices[f],p=Ls(d,m);if(i.has(p))continue;i.add(p);let g={from:d,to:m,weight:2};a.color&&(g.color=a.color),c.push(g)}}return c}let o=Math.cos(n*Math.PI/180),t=new Map,r=[[0,1],[1,2],[2,0]];for(let i of e){let c=dl(i);for(let[a,l]of r){let u=i.vertices[a],f=i.vertices[l],d=Ls(u,f),m=t.get(d);m?m.normals.push(c):t.set(d,{normals:[c],from:u,to:f,color:i.color})}}let s=[];for(let{normals:i,from:c,to:a,color:l}of t.values()){if(i.length<2){let f={from:c,to:a,weight:2};l&&(f.color=l),s.push(f);continue}let u=!1;e:for(let f=0;f<i.length;f++)for(let d=f+1;d<i.length;d++)if(pl(i[f],i[d])<o){u=!0;break e}if(u){let f={from:c,to:a,weight:2};l&&(f.color=l),s.push(f)}}return s}function Ns(e,n=0){return gl(e,n)}0&&(module.exports={BASE_TILE,CAMERA_BACKFACE_CULL_EPS,DEFAULT_CAMERA_STATE,DEFAULT_PROJECTION,LoopOnce,LoopPingPong,LoopRepeat,QUAT_IDENTITY,VOXEL_CAMERA_CULL_AXIS_EPS,VOXEL_CAMERA_CULL_NORMAL_LIMIT,antiprismPolygons,arrowPolygons,axesHelperPolygons,bakeSolidTextureSampledPolygons,bakeSolidTextureSamples,bipyramidPolygons,buildSceneContext,buildTextureSamplers,cameraCullNormalGroups,cameraCullNormalGroupsFromPolygons,cameraCullNormalKey,cameraCullVisibleSignature,cameraFacingDepth,clampChannel,computeSceneBbox,computeShapeLighting,conePolygons,coverPlanarPolygons,createGlyphAnimationMixer,createIsometricCamera,cubePolygons,cuboctahedronPolygons,cullInteriorPolygons,cylinderPolygons,dedupeOverlappingPolygons,deltoidalHexecontahedronPolygons,deltoidalIcositetrahedronPolygons,disdyakisDodecahedronPolygons,disdyakisTriacontahedronPolygons,dodecahedronPolygons,eulerXYZFromQuat,findOverlappingPolygonDuplicates,formatColor,greatDodecahedronPolygons,greatIcosahedronPolygons,greatStellatedDodecahedronPolygons,icosahedronPolygons,icosidodecahedronPolygons,inverseRotateVec3,isAxisAlignedSurfaceNormal,isVoxelCameraCullableNormalGroups,loadMesh,mergePolygons,normalFacesCamera,normalizeInvertMultiplier,normalizePolygons,octahedronPolygons,optimizeMeshPolygons,parseColor,parseGltf,parseHexColor,parseMtl,parseObj,parsePureColor,parseRgbColor,parseStl,parseVox,pentagonalHexecontahedronPolygons,pentagonalIcositetrahedronPolygons,pentakisDodecahedronPolygons,planePolygons,polygonCssSurfaceNormal,polygonFaces,polygonFacesCamera,polygonTexture,prismPolygons,project,pyramidPolygons,quatFromAxisAngle,quatFromEulerXYZ,quatMultiply,recenterPolygons,resolveGeometry,rhombicDodecahedronPolygons,rhombicTriacontahedronPolygons,rhombicosidodecahedronPolygons,rhombicuboctahedronPolygons,ringPolygons,ringQuadPolygons,rotateVec3,sampleTexel,shadeColor,smallStellatedDodecahedronPolygons,snubCubePolygons,snubDodecahedronPolygons,spherePolygons,tetrahedronPolygons,tetrakisHexahedronPolygons,torusPolygons,trapezohedronPolygons,triakisIcosahedronPolygons,triakisOctahedronPolygons,triakisTetrahedronPolygons,trianglesToFeatureEdges,truncatedCubePolygons,truncatedCuboctahedronPolygons,truncatedDodecahedronPolygons,truncatedIcosahedronPolygons,truncatedIcosidodecahedronPolygons,truncatedOctahedronPolygons,truncatedTetrahedronPolygons});