@glyphcss/core 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +94 -3
- package/dist/index.d.ts +94 -3
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var Et=Object.defineProperty;var ps=Object.getOwnPropertyDescriptor;var gs=Object.getOwnPropertyNames;var ys=Object.prototype.hasOwnProperty;var hs=(e,n)=>{for(var o in n)Et(e,o,{get:n[o],enumerable:!0})},bs=(e,n,o,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of gs(n))!ys.call(e,r)&&r!==o&&Et(e,r,{get:()=>n[r],enumerable:!(t=ps(n,r))||t.enumerable});return e};var xs=e=>bs(Et({},"__esModule",{value:!0}),e);var Sa={};hs(Sa,{BASE_TILE:()=>Ho,CAMERA_BACKFACE_CULL_EPS:()=>pn,DEFAULT_CAMERA_STATE:()=>Ie,DEFAULT_PROJECTION:()=>So,LoopOnce:()=>$r,LoopPingPong:()=>Ur,LoopRepeat:()=>Fr,QUAT_IDENTITY:()=>No,VOXEL_CAMERA_CULL_AXIS_EPS:()=>oo,VOXEL_CAMERA_CULL_NORMAL_LIMIT:()=>ro,antiprismPolygons:()=>Sn,arrowPolygons:()=>fo,axesHelperPolygons:()=>uo,bakeSolidTextureSampledPolygons:()=>cs,bakeSolidTextureSamples:()=>Vt,bipyramidPolygons:()=>Tn,buildSceneContext:()=>Lo,cameraCullNormalGroups:()=>io,cameraCullNormalGroupsFromPolygons:()=>Dr,cameraCullNormalKey:()=>co,cameraCullVisibleSignature:()=>_r,cameraFacingDepth:()=>so,clampChannel:()=>Me,computeSceneBbox:()=>Nt,computeShapeLighting:()=>ko,conePolygons:()=>Vn,coverPlanarPolygons:()=>nt,createGlyphAnimationMixer:()=>Br,createIsometricCamera:()=>Yo,cubePolygons:()=>hn,cuboctahedronPolygons:()=>Re,cullInteriorPolygons:()=>Ce,cylinderPolygons:()=>Mn,dedupeOverlappingPolygons:()=>Qn,deltoidalHexecontahedronPolygons:()=>Bn,deltoidalIcositetrahedronPolygons:()=>Un,disdyakisDodecahedronPolygons:()=>$n,disdyakisTriacontahedronPolygons:()=>Fn,dodecahedronPolygons:()=>bn,eulerXYZFromQuat:()=>Bo,findOverlappingPolygonDuplicates:()=>Ut,formatColor:()=>nn,greatDodecahedronPolygons:()=>zn,greatIcosahedronPolygons:()=>kn,greatStellatedDodecahedronPolygons:()=>wn,icosahedronPolygons:()=>xn,icosidodecahedronPolygons:()=>Ee,inverseRotateVec3:()=>Go,isAxisAlignedSurfaceNormal:()=>ao,isVoxelCameraCullableNormalGroups:()=>Lr,loadMesh:()=>us,mergePolygons:()=>ae,normalFacesCamera:()=>pt,normalizeInvertMultiplier:()=>Xo,normalizePolygons:()=>Kn,octahedronPolygons:()=>gn,optimizeMeshPolygons:()=>at,parseColor:()=>Oe,parseGltf:()=>Mt,parseHexColor:()=>Dt,parseMtl:()=>ht,parseObj:()=>yt,parsePureColor:()=>Xn,parseRgbColor:()=>Lt,parseVox:()=>vt,pentagonalHexecontahedronPolygons:()=>qn,pentagonalIcositetrahedronPolygons:()=>jn,pentakisDodecahedronPolygons:()=>Nn,planePolygons:()=>go,polygonCssSurfaceNormal:()=>dt,polygonFaces:()=>_o,polygonFacesCamera:()=>Er,prismPolygons:()=>An,project:()=>fs,pyramidPolygons:()=>Cn,quatFromAxisAngle:()=>Fo,quatFromEulerXYZ:()=>Uo,quatMultiply:()=>$o,resolveGeometry:()=>yo,rhombicDodecahedronPolygons:()=>Rn,rhombicTriacontahedronPolygons:()=>En,rhombicosidodecahedronPolygons:()=>Be,rhombicuboctahedronPolygons:()=>Ue,ringPolygons:()=>mo,ringQuadPolygons:()=>po,rotateVec3:()=>tn,shadeColor:()=>wo,smallStellatedDodecahedronPolygons:()=>In,snubCubePolygons:()=>je,snubDodecahedronPolygons:()=>qe,spherePolygons:()=>Pn,tetrahedronPolygons:()=>yn,tetrakisHexahedronPolygons:()=>_n,torusPolygons:()=>vn,trapezohedronPolygons:()=>On,triakisIcosahedronPolygons:()=>Gn,triakisOctahedronPolygons:()=>Ln,triakisTetrahedronPolygons:()=>Dn,trianglesToFeatureEdges:()=>ds,truncatedCubePolygons:()=>Le,truncatedCuboctahedronPolygons:()=>$e,truncatedDodecahedronPolygons:()=>Ge,truncatedIcosahedronPolygons:()=>Ne,truncatedIcosidodecahedronPolygons:()=>Fe,truncatedOctahedronPolygons:()=>_e,truncatedTetrahedronPolygons:()=>De});module.exports=xs(Sa);var So="cubic";function Dt(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 Lt(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 Xn(e){if(!e)return null;let n=e.trim(),o=Dt(n);return o||Lt(n)}function Me(e){return Math.max(0,Math.min(255,Math.round(e)))}function nn(e){let[n,o,t]=e.rgb.map(Me);return e.alpha<1?`rgba(${n}, ${o}, ${t}, ${e.alpha})`:`rgb(${n}, ${o}, ${t})`}var Gt={rgb:[204,204,204],alpha:1},To=new Map;function Oe(e){if(!e)return null;let n=e.trim(),o=To.get(n);if(o)return o;let t=Xn(n);return t?(To.set(n,t),t):null}function wo(e,n){let o=Oe(e)??Gt,t=[Me(o.rgb[0]+n),Me(o.rgb[1]+n),Me(o.rgb[2]+n)];return nn({rgb:t,alpha:o.alpha})}var _t={direction:[0,0,-1],color:"#ffffff",intensity:1},Oo={color:"#ffffff",intensity:.4};function Io(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 zo(e,n,o){let t=Oe(n)??Gt;return e*(t.rgb[o]/255)}function ko(e,n,o,t){let r=Oe(n)??Gt,c=Io(o?.direction??_t.direction),a=o?.color??_t.color,s=Math.max(0,o?.intensity??_t.intensity),i=t?.color??Oo.color,l=Math.max(0,t?.intensity??Oo.intensity),u=Io(e),m=Math.max(0,-(u[0]*c[0]+u[1]*c[1]+u[2]*c[2])),d=s*m,f=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],x=zo(g,i,p)*l,V=zo(g,a,p)*d;f[p]=Me(x+V)}return nn({rgb:f,alpha:r.alpha})}var Ro="#cccccc",Yn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Eo=(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]],Do=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Wn=e=>Math.hypot(e[0],e[1],e[2]);function Ps(e){let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<o&&(o=u[1]),u[1]>c&&(c=u[1]),u[2]<t&&(t=u[2]),u[2]>a&&(a=u[2]);let s=r-n,i=c-o,l=a-t;return Math.hypot(s,i,l)}function Ms(){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 Kn(e){let n=[],o=[];if(!e||e.length===0)return{polygons:n,warnings:o};for(let t=0;t<e.length;t++){let r=e[t];if(!r||!Array.isArray(r.vertices)){o.push(`Polygon ${t}: missing vertices, dropped`);continue}let c=r.vertices;if(c.length<3){o.push(`Polygon ${t}: ${c.length} vertices (need >= 3), dropped`);continue}let a=Yn(c[1],c[0]),s=Yn(c[2],c[0]),i=Eo(a,s),l=Wn(i);if(c.length===3){if(l<1e-12){Wn(a)<1e-12||Wn(s)<1e-12?o.push(`Polygon ${t}: zero-area triangle (coincident vertices), dropped`):o.push(`Polygon ${t}: vertices collinear, dropped`);continue}}else if(l<1e-12){o.push(`Polygon ${t}: first 3 vertices collinear, dropped`);continue}let u=[{...r,vertices:c.slice()}];if(c.length>=4){let m=[i[0]/l,i[1]/l,i[2]/l],d=Do(m,c[0]),f=Ps(c),p=Math.max(1e-6,f*.001),g=0;for(let x=3;x<c.length;x++){let V=Math.abs(Do(m,c[x])-d);V>g&&(g=V)}if(g>p){let x=[],V=r.uvs&&r.uvs.length===c.length?r.uvs:void 0;for(let C=1;C<c.length-1;C++){let v=[c[0].slice(),c[C].slice(),c[C+1].slice()],M=Eo(Yn(v[1],v[0]),Yn(v[2],v[0]));if(Wn(M)<1e-12)continue;let y={...r,vertices:v};V&&(y.uvs=[V[0].slice(),V[C].slice(),V[C+1].slice()]),x.push(y)}if(x.length===0){o.push(`Polygon ${t}: ${c.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}o.push(`Polygon ${t}: ${c.length} non-coplanar vertices, fan-triangulated to ${x.length} triangles`),u=x}}for(let m of u){let d=Vs(m,t,o);d&&n.push(d)}}return{polygons:n,warnings:o}}function Vs(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&&Ms()&&o.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Oe(e.color)?t.color=e.color:(o.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${Ro}`),t.color=Ro)),r!==void 0&&(t.texture=r),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?o.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):t.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let c={},a=!1;for(let s of Object.keys(e.data)){let i=e.data[s];typeof i=="string"||typeof i=="number"||typeof i=="boolean"?c[s]=i:(a=!0,o.push(`Polygon ${n}: data["${s}"] has non-primitive value, key dropped`))}Object.keys(c).length>0&&(t.data=c)}return t}function Nt(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0,s=!1;for(let i of e)if(i?.vertices)for(let l of i.vertices)l&&(s=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<o&&(o=l[1]),l[1]>c&&(c=l[1]),l[2]<t&&(t=l[2]),l[2]>a&&(a=l[2]));return s?{min:[n,o,t],max:[r,c,a]}:{min:[0,0,0],max:[0,0,0]}}function Lo(e){let n=e.polygons??[],o,t;if(e.skipNormalize)o=n,t=[];else{let s=Kn(n);o=s.polygons,t=s.warnings}let r=Nt(o),c=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]];return{context:{polygons:o,sceneBbox:r,warnings:t},dimensions:{sceneBbox:r,size:c},warnings:t}}function _o(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function tn(e,n,o,t){let r=n*Math.PI/180,c=o*Math.PI/180,a=t*Math.PI/180,[s,i,l]=e;if(a!==0){let u=Math.cos(a),m=Math.sin(a);[s,i]=[s*u-i*m,s*m+i*u]}if(c!==0){let u=Math.cos(c),m=Math.sin(c);[s,l]=[s*u+l*m,-s*m+l*u]}if(r!==0){let u=Math.cos(r),m=Math.sin(r);[i,l]=[i*u-l*m,i*m+l*u]}return[s,i,l]}function Go(e,n){let o=-n[0]*Math.PI/180,t=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[c,a,s]=e;if(o!==0){let i=Math.cos(o),l=Math.sin(o);[a,s]=[a*i-s*l,a*l+s*i]}if(t!==0){let i=Math.cos(t),l=Math.sin(t);[c,s]=[c*i+s*l,-c*l+s*i]}if(r!==0){let i=Math.cos(r),l=Math.sin(r);[c,a]=[c*i-a*l,c*l+a*i]}return[c,a,s]}var $t=Math.PI/180,on=180/Math.PI,No=[1,0,0,0];function $o(e,n){let[o,t,r,c]=e,[a,s,i,l]=n;return[o*a-t*s-r*i-c*l,o*s+t*a+r*l-c*i,o*i-t*l+r*a+c*s,o*l+t*i-r*s+c*a]}function Fo(e,n){let o=n*.5,t=Math.sin(o);return[Math.cos(o),e[0]*t,e[1]*t,e[2]*t]}function Uo(e){let n=e[0]*$t,o=e[1]*$t,t=e[2]*$t,r=Math.cos(n*.5),c=Math.sin(n*.5),a=Math.cos(o*.5),s=Math.sin(o*.5),i=Math.cos(t*.5),l=Math.sin(t*.5);return[r*a*i-c*s*l,c*a*i+r*s*l,r*s*i-c*a*l,r*a*l+c*s*i]}function Bo(e){let[n,o,t,r]=e,c=2*(o*r+n*t),a=2*(t*r-n*o),s=1-2*(o*o+t*t),i=2*(o*t-n*r),l=1-2*(t*t+r*r),u=Math.max(-1,Math.min(1,c)),m=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-a,s)*on,m*on,Math.atan2(-i,l)*on]:[Math.atan2(2*(t*r+n*o),1-2*(o*o+r*r))*on,m*on,0]}var Ho=50;function Xo(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Ie={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0},jo=100,qo=1e4,We=e=>Math.round(e*jo)/jo,vs=e=>Math.round(e*qo)/qo;function Yo(e={}){let n={target:e.target??[...Ie.target],rotX:e.rotX??Ie.rotX,rotY:e.rotY??Ie.rotY,zoom:e.zoom??Ie.zoom,distance:e.distance??Ie.distance};function o(r){r.target!==void 0&&(n.target=[We(r.target[0]),We(r.target[1]),We(r.target[2])]),r.rotX!==void 0&&(n.rotX=We(r.rotX)),r.rotY!==void 0&&(n.rotY=We(r.rotY)),r.zoom!==void 0&&(n.zoom=vs(r.zoom)),r.distance!==void 0&&(n.distance=We(r.distance))}function t(r={}){let a=(r.cols??0)*50,s=(r.rows??0)*50,[i,l,u]=n.target,m=l*50,d=i*50,f=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-m}px, ${-d}px, ${-f}px)`,width:`${a}px`,height:`${s}px`}}return{state:n,update:o,getStyle:t}}var ve=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Zn=(e,n)=>[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]],rn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Ft=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 Cs(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 Ko(e){if(e.length<3)return null;let n=ve(e[1],e[0]),o=ve(e[2],e[0]),t=Zn(n,o),r=Ft(t);if(r<1e-12)return null;let c=[t[0]/r,t[1]/r,t[2]/r],a=rn(c,e[0]);return{normal:c,d:a}}function As(e,n){return rn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function Ss(e,n){return rn(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function Ts(e,n,o,t){let r=e.vertices.findIndex(h=>Ve(h,o)),c=e.vertices.findIndex(h=>Ve(h,t)),a=n.vertices.findIndex(h=>Ve(h,o)),s=n.vertices.findIndex(h=>Ve(h,t));if(r<0||c<0||a<0||s<0)return null;let i=e.vertices.length,l=n.vertices.length,u=(r+1)%i===c,m=(a+1)%l===s;if(u===m)return null;let d=u?c:r,f=u?r:c,p=m?s:a,g=m?a:s,x=!!(e.uvs&&n.uvs),V=[],C=x?[]:void 0,v=d;for(;V.push(e.vertices[v]),C&&C.push(e.uvs[v]),v!==f;)v=(v+1)%i;for(v=p;V.push(n.vertices[v]),C&&C.push(n.uvs[v]),v!==g;)v=(v+1)%l;let M=[],y=C?[]:void 0;for(let h=0;h<V.length;h++)(M.length===0||!Ve(V[h],M[M.length-1]))&&(M.push(V[h]),y&&C&&y.push(C[h]));if(M.length>1&&Ve(M[0],M[M.length-1])&&(M.pop(),y?.pop()),x)return Wo(M,y);let P=[],S=y?[]:void 0;for(let h=0;h<M.length;h++){let b=M[(h-1+M.length)%M.length],A=M[h],I=M[(h+1)%M.length],R=Zn(ve(A,b),ve(I,b));Ft(R)>1e-9&&(P.push(A),S&&y&&S.push(y[h]))}return P.length<3?null:Wo(P,S)}function Os(e,n){let o=e.length,t=0;for(let r=0;r<o;r++){let c=e[r],a=e[(r+1)%o],s=e[(r+2)%o],i=ve(a,c),l=ve(s,a),u=rn(Zn(i,l),n);if(Math.abs(u)<1e-9)continue;let m=u>0?1:-1;if(t===0)t=m;else if(m!==t)return!1}return!0}function Is(e,n){if(e.length<3)return!1;let o=Ko(e);if(!o)return!1;for(let t of e)if(Math.abs(rn(o.normal,t)-o.d)>n)return!1;return!0}function zs(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function ws(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 Wo(e,n){for(let o=0;o<e.length;o++){let t=e[o],r=e[(o+1)%e.length],c=e[(o+2)%e.length];if(!(Ft(Zn(ve(r,t),ve(c,t)))<=1e-9))return o===0?{vertices:e,uvs:n}:{vertices:[...e.slice(o),...e.slice(0,o)],uvs:n?[...n.slice(o),...n.slice(0,o)]:void 0}}return{vertices:e,uvs:n}}function ae(e){let n=[],o=[];for(let r of e??[]){if(!r||!r.vertices||r.vertices.length<3){r&&n.push(r);continue}let c=r.vertices.map(l=>[l[0],l[1],l[2]]),a=Ko(c);if(!a){n.push(r);continue}let s=r.texture&&r.uvs&&r.uvs.length===c.length?r.uvs.map(l=>[l[0],l[1]]):void 0,i=r.texture&&s?r.textureTriangles?.length?zs(r.textureTriangles):ws(c,s):void 0;o.push({vertices:c,uvs:s,color:r.color??"#cccccc",texture:r.texture,textureTriangles:i,normal:a.normal,d:a.d,alive:!0,data:r.data})}let t=()=>{let r=new Map;for(let s=0;s<o.length;s++){let i=o[s];if(!i.alive)continue;let l=i.vertices.length;for(let u=0;u<l;u++){let m=i.vertices[u],d=i.vertices[(u+1)%l],f=Cs(m,d),p=r.get(f);p||(p=[],r.set(f,p)),p.push(s)}}let c=!1,a=(s,i)=>{for(let l=0;l<s.vertices.length;l++){let u=s.vertices[l],m=s.vertices[(l+1)%s.vertices.length];for(let d=0;d<i.vertices.length;d++){let f=i.vertices[d],p=i.vertices[(d+1)%i.vertices.length];if(Ve(u,p)&&Ve(m,f))return[u,m]}}return null};for(let[,s]of r){if(s.length<2)continue;let[i,l]=s;if(i===l)continue;let u=o[i],m=o[l];if(!u.alive||!m.alive||u.color!==m.color||u.texture!==m.texture)continue;let d=!!(u.texture||m.texture);if(d&&(!u.textureTriangles||!m.textureTriangles)||!!u.uvs!=!!m.uvs||(d?!Ss(u,m):!As(u,m)))continue;let f=a(u,m);if(!f)continue;let[p,g]=f,x=Ts(u,m,p,g);x&&Is(x.vertices,.001)&&Os(x.vertices,u.normal)&&(u.vertices=x.vertices,u.uvs=x.uvs,u.textureTriangles=d?[...u.textureTriangles??[],...m.textureTriangles??[]]:void 0,m.alive=!1,c=!0)}return c};for(;t(););for(let r of o){if(!r.alive)continue;let c={vertices:r.vertices,color:r.color};r.texture&&(c.texture=r.texture),r.uvs&&(c.uvs=r.uvs),r.textureTriangles?.length&&(c.textureTriangles=r.textureTriangles),r.data&&(c.data=r.data),n.push(c)}return n}var ks=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Rs=(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 Es(e,n){let o=e.vertices;if(!o||o.length<3)return null;let t=0,r=0,c=0;for(let g=0;g<o.length;g++){let x=o[g],V=o[(g+1)%o.length];t+=(x[1]-V[1])*(x[2]+V[2]),r+=(x[2]-V[2])*(x[0]+V[0]),c+=(x[0]-V[0])*(x[1]+V[1])}let a=Math.hypot(t,r,c);if(a<1e-12)return null;let s=[t/a,r/a,c/a],i=0,l=0,u=0;for(let g of o)i+=g[0],l+=g[1],u+=g[2];let m=1/o.length,d=[i*m,l*m,u*m],f=ye(s,d),p=a*.5;return{index:n,polygon:e,normal:s,d:f,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function Ds(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],o=n[0]-e[0]*ye(n,e),t=n[1]-e[1]*ye(n,e),r=n[2]-e[2]*ye(n,e),c=Math.hypot(o,t,r);o/=c,t/=c,r/=c;let a=[o,t,r],s=Rs(e,a);return{u:a,v:s}}function Ls(e){if(e.local2D)return;let n=Ds(e.normal),o=[],t=1/0,r=1/0,c=-1/0,a=-1/0;for(let s of e.polygon.vertices){let i=ye(s,n.u),l=ye(s,n.v);o.push([i,l]),i<t&&(t=i),i>c&&(c=i),l<r&&(r=l),l>a&&(a=l)}e.local2D=o,e.bbox2D={min:[t,r],max:[c,a]},e.basis=n}function _s(e,n){let o=[],t=1/0,r=1/0,c=-1/0,a=-1/0;for(let s of e.vertices){let i=ye(s,n.u),l=ye(s,n.v);o.push([i,l]),i<t&&(t=i),i>c&&(c=i),l<r&&(r=l),l>a&&(a=l)}return{local2D:o,bbox2D:{min:[t,r],max:[c,a]}}}function Gs(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 Zo(e,n){let o=!1;for(let t=0,r=n.length-1;t<n.length;r=t++){let c=n[t],a=n[r];c[1]>e[1]!=a[1]>e[1]&&e[0]<(a[0]-c[0])*(e[1]-c[1])/(a[1]-c[1]+1e-30)+c[0]&&(o=!o)}return o}function Qo(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 Ns(e,n){let o=Qo(e),t=Qo(n),r=1e-4,c=0;for(let l of e){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];Zo(u,n)&&c++}let a=0;for(let l of n){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];Zo(u,e)&&a++}let s=c/e.length,i=a/n.length;return Math.max(s,i)}function $s(e,n){let o=e.normal[0],t=e.normal[1],r=e.normal[2],c=Math.abs(o),a=Math.abs(t),s=Math.abs(r),i=o;a>c&&a>s?i=t:s>c&&s>a&&(i=r),i<0&&(o=-o,t=-t,r=-r);let l=Math.round(o/.05),u=Math.round(t/.05),m=Math.round(r/.05),d=e.d*(e.normal[0]===o&&e.normal[1]===t&&e.normal[2]===r?1:-1),f=Math.round(d/(n*2));return`${l},${u},${m}|${f}`}function Fs(e,n,o,t){let r=ye(e.normal,n.normal);if(Math.abs(r)<1-o)return!1;let c=r>0?1:-1;return Math.abs(e.d-c*n.d)<t}function Jo(e,n){let o=ks(n,e.centroid);return ye(e.normal,o)>0}function Ut(e,n){if(!e||e.length<2)return new Set;let o=n?.normalTolerance??.001,t=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,c=[];for(let f=0;f<e.length;f++){let p=Es(e[f],f);p&&c.push(p)}if(c.length<2)return new Set;let a=0,s=0,i=0,l=0;for(let f of c)a+=f.centroid[0]*f.area,s+=f.centroid[1]*f.area,i+=f.centroid[2]*f.area,l+=f.area;let u=l>0?[a/l,s/l,i/l]:[0,0,0],m=new Map;for(let f of c){let p=$s(f,t),g=m.get(p);g||(g=[],m.set(p,g)),g.push(f)}let d=new Set;for(let f of m.values())if(!(f.length<2))for(let p=0;p<f.length;p++){let g=f[p];if(!d.has(g.index))for(let x=p+1;x<f.length;x++){let V=f[x];if(d.has(V.index)||!Fs(g,V,o,t))continue;Ls(g);let C=_s(V.polygon,g.basis);if(!Gs(g.bbox2D,C.bbox2D)||Ns(g.local2D,C.local2D)<r)continue;let M=Jo(g,u),y=Jo(V,u),P;if(M&&!y?P=g:y&&!M?P=V:P=g.area<V.area?g:V,d.add(P.index),P===g)break}}return d}function Qn(e,n){if(!e||e.length<2)return e??[];let o=Ut(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 Us=4,Bs=8,js=.001,qs=1e-9,Hs=1e6,Xs=1e6,ze=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],qt=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],an=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],we=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],rr=(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]],sr=e=>Math.hypot(e[0],e[1],e[2]);function ln(e){let n=sr(e);return n<=qs?null:[e[0]/n,e[1]/n,e[2]/n]}function cn(e,n){return Math.round(e*n)/n}function pe(e){return cn(e,Hs)}function Bt(e){return cn(e,Xs)}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 Ys(e){let n=be(e.a),o=be(e.b);return n<o?`${n}|${o}`:`${o}|${n}`}function Ke(e){return`${e[0]},${e[1]},${e[2]}`}function cr(e,n){let o=Ke(e),t=Ke(n);return o<t?`${o}|${t}`:`${t}|${o}`}function Ht(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function er(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",Ht(e.data)].join("|")}function ir(e){let n=e.vertices;if(!n||n.length<3)return null;let o=n[0],t=[0,0,0];for(let c=1;c<n.length-1;c++)t=qt(t,rr(ze(n[c],o),ze(n[c+1],o)));let r=ln(t);return r?{normal:r,d:we(r,o)}:null}function Ws(e,n,o){return we(e.normal,n.normal)>1-o&&Math.abs(e.d-n.d)<=o}function Ks(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function Zs(e,n){let o=n[e[0]]?.data,t=Ht(o);for(let r of e)if(Ht(n[r].data)!==t)return;return o?{...o}:void 0}function Qs(e,n){let o=e.map(i=>Ks(i)?ir(i):null),t=o.map(Boolean),r=new Map;for(let i=0;i<e.length;i++){if(!o[i])continue;let l=e[i].vertices;for(let u=0;u<l.length;u++){let m=cr(l[u],l[(u+1)%l.length]),d=r.get(m),f={polygon:i,edge:u};d?d.push(f):r.set(m,[f])}}let c=e.map(()=>new Set);for(let i of r.values())if(!(i.length<2))for(let l=0;l<i.length;l++)for(let u=l+1;u<i.length;u++){let m=i[l].polygon,d=i[u].polygon,f=o[m],p=o[d];!f||!p||er(e[m])===er(e[d])&&Ws(f,p,n)&&(c[m].add(d),c[d].add(m))}let a=new Set,s=[];for(let i=0;i<e.length;i++){if(!t[i]||a.has(i))continue;let l=[],u=[i];for(a.add(i);u.length>0;){let m=u.shift();l.push(m);for(let d of c[m])a.has(d)||(a.add(d),u.push(d))}s.push(l)}return{groups:s}}function Js(e,n){let o=new Set(e),t=new Map;for(let c of e){let a=n[c].vertices;for(let s=0;s<a.length;s++){let i=cr(a[s],a[(s+1)%a.length]),l=t.get(i),u={polygon:c,edge:s};l?l.push(u):t.set(i,[u])}}let r=[];for(let c of t.values()){let a=c.filter(s=>o.has(s.polygon));if(a.length===1){let s=a[0],i=n[s.polygon].vertices;r.push({a:i[s.edge],b:i[(s.edge+1)%i.length]})}else if(a.length!==2)return null}return r}function ec(e){let n=new Map;for(let o of e)n.set(Ke(o.a),(n.get(Ke(o.a))??0)+1),n.set(Ke(o.b),(n.get(Ke(o.b))??0)+1);for(let o of n.values())if(o%2!==0)return!1;return!0}function ar(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 nc(e){let n=ar(e);return`${cn(n[0],1e3)},${cn(n[1],1e3)},${cn(n[2],1e3)}`}function tc(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],o=ze(n,an(e,we(n,e)));return ln(o)??[1,0,0]}function oc(e,n,o){let t=new Map;for(let c of e){let a=ze(c.b,c.a),s=ze(a,an(n,we(a,n))),i=ln(s);if(!i)continue;let l=ar(i),u=nc(l),m=sr(s),d=t.get(u);d?d.weight+=m:t.set(u,{axis:l,weight:m})}let r=[...t.values()].sort((c,a)=>a.weight-c.weight).slice(0,o).map(c=>c.axis);return r.length===0&&r.push(tc(n)),r}function nr(e,n,o,t){let r=ze(e,n);return[pe(we(r,o)),pe(we(r,t))]}function rc(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 sn(e,n){let[o,t]=e.a,[r,c]=e.b,a=(n-o)/(r-o);return pe(t+(c-t)*a)}function Xt(e){let n=[];for(let t of e)(n.length===0||Math.abs(t[0]-n[n.length-1][0])>1e-7||Math.abs(t[1]-n[n.length-1][1])>1e-7)&&n.push(t);n.length>1&&Math.abs(n[0][0]-n[n.length-1][0])<=1e-7&&Math.abs(n[0][1]-n[n.length-1][1])<=1e-7&&n.pop();let o=[];for(let t=0;t<n.length;t++){let r=n[(t-1+n.length)%n.length],c=n[t],a=n[(t+1)%n.length],s=(c[0]-r[0])*(a[1]-c[1])-(c[1]-r[1])*(a[0]-c[0]);Math.abs(s)>1e-8&&o.push(c)}return o}function et(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 tr(e){let n=1/0,o=1/0,t=-1/0,r=-1/0;for(let[c,a]of e)n=Math.min(n,c),o=Math.min(o,a),t=Math.max(t,c),r=Math.max(r,a);return{minX:n,minY:o,maxX:t,maxY:r}}function sc(e,n){let o=tr(e),t=tr(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 Jn(e){return Math.abs(et(e))}function cc(e){if(e.length<3)return!1;let n=0;for(let o=0;o<e.length;o++){let t=e[o],r=e[(o+1)%e.length],c=e[(o+2)%e.length],a=(r[0]-t[0])*(c[1]-r[1])-(r[1]-t[1])*(c[0]-r[0]);if(Math.abs(a)<=1e-8)continue;let s=a>0?1:-1;if(n===0)n=s;else if(n!==s)return!1}return!0}function ic(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],c=e[0]-n[0],a=e[1]-n[1],s=t*a-r*c,i=Math.hypot(t,r);if(i<=1e-9||Math.abs(s)>Math.max(1e-8,i*1e-8))return!1;let l=c*t+a*r;return l>=-1e-8&&l<=t*t+r*r+1e-8}function ac(e,n,o){let t=o[0]-n[0],r=o[1]-n[1],c=t*t+r*r;return c<=1e-12?0:((e[0]-n[0])*t+(e[1]-n[1])*r)/c}function or(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t],c=e[(t+1)%e.length],a=[{t:0,point:r},{t:1,point:c}];for(let i of n)jt(i,r)||jt(i,c)||ic(i,r,c)&&a.push({t:ac(i,r,c),point:i});a.sort((i,l)=>i.t-l.t);let s=[];for(let i of a)s.some(l=>Math.abs(l.t-i.t)<=1e-8||jt(l.point,i.point))||s.push(i);for(let i=0;i<s.length-1;i++){let l=s[i].point,u=s[i+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||o.push({a:[pe(l[0]),pe(l[1])],b:[pe(u[0]),pe(u[1])]})}}return o}function lc(e,n){if(!sc(e,n))return null;let o=[...or(e,n),...or(n,e)],t=new Map;for(let g of o){let x=Ys(g),V=t.get(x);V?V.push(g):t.set(x,[g])}let r=!1,c=[];for(let g of t.values()){if(g.length===1){c.push(g[0]);continue}r=!0;let x=g.filter(C=>be(C.a)<be(C.b)).length,V=g.length-x;if(x!==V)return null}if(!r||c.length<3)return null;let a=new Map;for(let g of c){let x=be(g.a);if(a.has(x))return null;a.set(x,g)}let s=c[0],i=be(s.a),l=[],u=new Set,m=i;for(let g=0;g<=c.length;g++){let x=a.get(m);if(!x)return null;let V=`${be(x.a)}>${be(x.b)}`;if(u.has(V))return null;if(u.add(V),l.push(x.a),m=be(x.b),m===i)break}if(m!==i||u.size!==c.length)return null;let d=Xt(l);if(d.length<3||!cc(d))return null;let f=Jn(d),p=Jn(e)+Jn(n);return Math.abs(f-p)>Math.max(1e-5,p*1e-5)?null:et(d)>=0?d:[...d].reverse()}function uc(e){let n=e.map(Xt).filter(t=>t.length>=3&&Jn(t)>1e-8),o=!0;for(;o;){o=!1;for(let t=0;t<n.length;t++){for(let r=t+1;r<n.length;r++){let c=lc(n[t],n[r]);if(c){n[t]=c,n.splice(r,1),o=!0;break}}if(o)break}}return n}function fc(e,n,o){let t=new Map;return r=>{let c=pe(r[0]),a=pe(r[1]),s=`${c},${a}`,i=t.get(s);if(i)return[i[0],i[1],i[2]];let l=qt(e,qt(an(n,c),an(o,a))),u=[Bt(l[0]),Bt(l[1]),Bt(l[2])];return t.set(s,u),[u[0],u[1],u[2]]}}function mc(e,n,o,t,r){let c=o[0]?.a;if(!c)return null;let a=ln(ze(r,an(t,we(r,t))));if(!a)return null;let s=ln(rr(t,a));if(!s)return null;let i=[],l=[];for(let x of o){let V=nr(x.a,c,a,s),C=nr(x.b,c,a,s);Math.hypot(V[0]-C[0],V[1]-C[1])<=1e-7||(i.push({a:V,b:C}),l.push(V[0],C[0]))}let u=rc(l);if(i.length<3||u.length<2)return null;let m=n[e[0]].color,d=Zs(e,n),f=[];for(let x=0;x<u.length-1;x++){let V=u[x],C=u[x+1];if(C-V<=1e-7)continue;let v=(V+C)/2,M=i.filter(y=>{let P=Math.min(y.a[0],y.b[0]),S=Math.max(y.a[0],y.b[0]);return P<v&&v<S&&Math.abs(y.a[0]-y.b[0])>1e-7}).map(y=>({segment:y,yMid:sn(y,v)})).sort((y,P)=>y.yMid-P.yMid);if(M.length!==0){if(M.length%2!==0)return null;for(let y=0;y<M.length;y+=2){let P=M[y].segment,S=M[y+1].segment,h=sn(P,V),b=sn(P,C),A=sn(S,V),I=sn(S,C),R=Xt([[V,h],[C,b],[C,I],[V,A]]);if(R.length<3||Math.abs(et(R))<=1e-8)continue;let k=et(R)>0?R:[...R].reverse();f.push(k)}}}if(f.length===0)return null;let p=fc(c,a,s),g=uc(f).map(x=>({vertices:x.map(p),...m?{color:m}:{},...d?{data:d}:{}}));return ae(g)}function dc(e,n,o){let t=Js(e,n);if(!t||t.length<3||!ec(t))return null;let r=ir(n[e[0]]);if(!r)return null;let c=null;for(let a of oc(t,r.normal,o)){let s=mc(e,n,t,r.normal,a);s&&(!c||s.length<c.length)&&(c=s)}return!c||c.length>=e.length?null:c}function nt(e,n={}){let o=n.minGroupPolygons??Us,t=n.maxCandidateAxes??Bs,r=n.planeEpsilon??js,c=e??[];if(c.length<o)return c;let{groups:a}=Qs(c,r);if(a.length===0)return c;let s=new Map,i=new Set;for(let u of a){if(u.length<o)continue;let m=dc(u,c,t);if(m){s.set(u[0],m);for(let d of u)i.add(d)}}if(s.size===0)return c;let l=[];for(let u=0;u<c.length;u++){let m=s.get(u);if(m){l.push(...m);continue}i.has(u)||l.push(c[u])}return l}function pc(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0;for(let[k,T,z]of n)o+=k,t+=T,r+=z;let c=1/n.length;o*=c,t*=c,r*=c;let a=n[0],s=n[1],i=n[2],l=s[0]-a[0],u=s[1]-a[1],m=s[2]-a[2],d=i[0]-a[0],f=i[1]-a[1],p=i[2]-a[2],g=u*p-m*f,x=m*d-l*p,V=l*f-u*d,C=Math.hypot(g,x,V);if(C<1e-9)return null;g/=C,x/=C,V/=C;let v=n.length-2,M=new Float64Array(v*9),y=0;for(let k=1;k<n.length-1;k++){let T=n[0],z=n[k],D=n[k+1];M[y++]=T[0],M[y++]=T[1],M[y++]=T[2],M[y++]=z[0],M[y++]=z[1],M[y++]=z[2],M[y++]=D[0],M[y++]=D[1],M[y++]=D[2]}let P=0,S=1/0,h=1/0,b=1/0,A=-1/0,I=-1/0,R=-1/0;for(let[k,T,z]of n){let D=k-o,L=T-t,w=z-r,O=D*D+L*L+w*w;O>P&&(P=O),k<S&&(S=k),k>A&&(A=k),T<h&&(h=T),T>I&&(I=T),z<b&&(b=z),z>R&&(R=z)}return{centroid:[o,t,r],normal:[g,x,V],vertices:n,triFlat:M,bcx:o,bcy:t,bcz:r,br2:P,minX:S,minY:h,minZ:b,maxX:A,maxY:I,maxZ:R}}function gc(e,n,o,t,r,c,a,s){let i=a[s],l=a[s+1],u=a[s+2],m=a[s+3]-i,d=a[s+4]-l,f=a[s+5]-u,p=a[s+6]-i,g=a[s+7]-l,x=a[s+8]-u,V=r*x-c*g,C=c*p-t*x,v=t*g-r*p,M=m*V+d*C+f*v;if(M>-1e-9&&M<1e-9)return!1;let y=1/M,P=e-i,S=n-l,h=o-u,b=y*(P*V+S*C+h*v);if(b<0||b>1)return!1;let A=S*f-h*d,I=h*m-P*f,R=P*d-S*m,k=y*(t*A+r*I+c*R);return k<0||b+k>1?!1:y*(p*A+g*I+x*R)>.001}function yc(e,n,o,t,r,c,a){let s=a.bcx-e,i=a.bcy-n,l=a.bcz-o,u=s*t+i*r+l*c,m=s-u*t,d=i-u*r,f=l-u*c;if(m*m+d*d+f*f>a.br2)return!1;let p=a.triFlat,g=p.length;for(let x=0;x<g;x+=9)if(gc(e,n,o,t,r,c,p,x))return!0;return!1}var un=9,hc=6,se=12;function Yt(e,n,o,t,r,c){let a=t-e,s=r-n,i=c-o;return a*s+s*i+i*a}function bc(e){let n=[];for(let P=0;P<e.length;P++)e[P]&&n.push(P);let o=n.length,t=new Int32Array(o);for(let P=0;P<o;P++)t[P]=n[P];let r=new Float64Array(o),c=new Float64Array(o),a=new Float64Array(o);for(let P=0;P<o;P++){let S=e[t[P]];r[P]=(S.minX+S.maxX)*.5,c[P]=(S.minY+S.maxY)*.5,a[P]=(S.minZ+S.maxZ)*.5}let s=2*Math.max(1,o)+1,i=new Float64Array(s*un),l=0,u=new Float64Array(se),m=new Float64Array(se),d=new Float64Array(se),f=new Float64Array(se),p=new Float64Array(se),g=new Float64Array(se),x=new Int32Array(se),V=new Float64Array(se-1),C=new Int32Array(se-1),v=new Float64Array(se-1),M=new Int32Array(se-1);function y(P,S){let h=l++,b=h*un,A=S-P,I=1/0,R=1/0,k=1/0,T=-1/0,z=-1/0,D=-1/0;for(let X=P;X<S;X++){let K=e[t[X]];K.minX<I&&(I=K.minX),K.maxX>T&&(T=K.maxX),K.minY<R&&(R=K.minY),K.maxY>z&&(z=K.maxY),K.minZ<k&&(k=K.minZ),K.maxZ>D&&(D=K.maxZ)}if(i[b]=I,i[b+1]=R,i[b+2]=k,i[b+3]=T,i[b+4]=z,i[b+5]=D,A<=hc)return i[b+6]=1,i[b+7]=P,i[b+8]=S,h;let L=1/0,w=1/0,O=1/0,E=-1/0,_=-1/0,N=-1/0;for(let X=P;X<S;X++)r[X]<L&&(L=r[X]),r[X]>E&&(E=r[X]),c[X]<w&&(w=c[X]),c[X]>_&&(_=c[X]),a[X]<O&&(O=a[X]),a[X]>N&&(N=a[X]);let G=E-L,$=_-w,F=N-O;if(G===0&&$===0&&F===0)return i[b+6]=1,i[b+7]=P,i[b+8]=S,h;let q=Yt(I,R,k,T,z,D),j=q>0?1/q:0,U=A+1,B=0,H=0;for(let X=0;X<3;X++){let K=X===0?L:X===1?w:O,le=X===0?G:X===1?$:F;if(le===0)continue;let Pe=X===0?r:X===1?c:a,Te=se/le;u.fill(1/0),m.fill(1/0),d.fill(1/0),f.fill(-1/0),p.fill(-1/0),g.fill(-1/0),x.fill(0);for(let Y=P;Y<S;Y++){let W=(Pe[Y]-K)*Te|0;W>=se&&(W=se-1);let ue=e[t[Y]];ue.minX<u[W]&&(u[W]=ue.minX),ue.maxX>f[W]&&(f[W]=ue.maxX),ue.minY<m[W]&&(m[W]=ue.minY),ue.maxY>p[W]&&(p[W]=ue.maxY),ue.minZ<d[W]&&(d[W]=ue.minZ),ue.maxZ>g[W]&&(g[W]=ue.maxZ),x[W]++}let Xe=1/0,Ye=1/0,Ct=1/0,At=-1/0,St=-1/0,Tt=-1/0,Co=0;for(let Y=0;Y<se-1;Y++)u[Y]<Xe&&(Xe=u[Y]),f[Y]>At&&(At=f[Y]),m[Y]<Ye&&(Ye=m[Y]),p[Y]>St&&(St=p[Y]),d[Y]<Ct&&(Ct=d[Y]),g[Y]>Tt&&(Tt=g[Y]),Co+=x[Y],V[Y]=Yt(Xe,Ye,Ct,At,St,Tt),C[Y]=Co;let Ot=1/0,It=1/0,zt=1/0,wt=-1/0,kt=-1/0,Rt=-1/0,Ao=0;for(let Y=se-2;Y>=0;Y--){let W=Y+1;u[W]<Ot&&(Ot=u[W]),f[W]>wt&&(wt=f[W]),m[W]<It&&(It=m[W]),p[W]>kt&&(kt=p[W]),d[W]<zt&&(zt=d[W]),g[W]>Rt&&(Rt=g[W]),Ao+=x[W],v[Y]=Yt(Ot,It,zt,wt,kt,Rt),M[Y]=Ao}for(let Y=0;Y<se-1;Y++){if(C[Y]===0||M[Y]===0)continue;let W=.125+(V[Y]*C[Y]+v[Y]*M[Y])*j;W<U&&(U=W,B=X,H=K+(Y+1)/Te)}}let Z=B===0?r:B===1?c:a,J=P,ne=S-1;for(;J<=ne;)if(Z[J]<H)J++;else{let X=t[J];t[J]=t[ne],t[ne]=X;let K=r[J];r[J]=r[ne],r[ne]=K;let le=c[J];c[J]=c[ne],c[ne]=le;let Pe=a[J];a[J]=a[ne],a[ne]=Pe,ne--}let ie=J;(ie===P||ie===S)&&(ie=P+S>>1),i[b+6]=0;let oe=y(P,ie),Q=y(ie,S);return i[h*un+7]=oe,i[h*un+8]=Q,h}return o>0&&y(0,o),{data:i,nodeCount:l,polyIndices:t,meta:e}}function lr(e,n,o,t,r,c,a,s,i){if(s.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:m}=s,d=t!==0?1/t:t>=0?1/0:-1/0,f=r!==0?1/r:r>=0?1/0:-1/0,p=c!==0?1/c:c>=0?1/0:-1/0,g=0;for(i[g++]=0;g>0;){let V=i[--g]*un,C=(l[V]-e)*d,v=(l[V+3]-e)*d,M=C<v?C:v,y=C<v?v:C,P=(l[V+1]-n)*f,S=(l[V+4]-n)*f,h=P<S?P:S,b=P<S?S:P;if(M>b||h>y)continue;h>M&&(M=h),b<y&&(y=b);let A=(l[V+2]-o)*p,I=(l[V+5]-o)*p,R=A<I?A:I,k=A<I?I:A;if(!(M>k||R>y)&&(k<y&&(y=k),!(y<.001)))if(l[V+6]===1){let T=l[V+7]|0,z=l[V+8]|0;for(let D=T;D<z;D++){let L=u[D];if(L===a)continue;let w=m[L];if(w&&yc(e,n,o,t,r,c,w))return!0}}else i[g++]=l[V+7]|0,i[g++]=l[V+8]|0}return!1}function xc(e){let n=(1+Math.sqrt(5))/2,o=new Float64Array(e*3);for(let t=0;t<e;t++){let r=(t+.5)/e,c=Math.sqrt(Math.max(0,1-r*r)),a=2*Math.PI*(t/n);o[t*3]=c*Math.cos(a),o[t*3+1]=c*Math.sin(a),o[t*3+2]=r}return o}function Pc(e){let n=Math.abs(e[0])>.9?0:1,o=Math.abs(e[0])>.9?1:0,t=o*e[2],r=-n*e[2],c=n*e[1]-o*e[0],a=Math.hypot(t,r,c);t/=a,r/=a,c/=a;let s=e[1]*c-e[2]*r,i=e[2]*t-e[0]*c,l=e[0]*r-e[1]*t;return{ux:t,uy:r,uz:c,vx:s,vy:i,vz:l}}function Ce(e,n){let o=n?.samples??8;if(e.length<4||o<1)return e;let t=e.map(pc),r=xc(o),c=[],a=bc(t),s=new Int32Array(Math.max(64,a.nodeCount)),i=192,l=new Float64Array(i);for(let u=0;u<e.length;u++){let m=t[u];if(!m){c.push(e[u]);continue}let d=m.normal[0],f=m.normal[1],p=m.normal[2],g=.001*d,x=.001*f,V=.001*p;{let z=m.centroid[0]+g,D=m.centroid[1]+x,L=m.centroid[2]+V;if(!lr(z,D,L,d,f,p,u,a,s)){c.push(e[u]);continue}}let{ux:C,uy:v,uz:M,vx:y,vy:P,vz:S}=Pc(m.normal),h=m.centroid[0],b=m.centroid[1],A=m.centroid[2],I=m.vertices,R=I.length,k=0;l[k++]=h+g,l[k++]=b+x,l[k++]=A+V;for(let z=0;z<R;z++){let D=I[z];l[k++]=D[0]+(h-D[0])*.08+g,l[k++]=D[1]+(b-D[1])*.08+x,l[k++]=D[2]+(A-D[2])*.08+V}for(let z=0;z<R;z++){let D=I[z],L=I[(z+1)%R],w=(D[0]+L[0])*.5,O=(D[1]+L[1])*.5,E=(D[2]+L[2])*.5;l[k++]=w+(h-w)*.08+g,l[k++]=O+(b-O)*.08+x,l[k++]=E+(A-E)*.08+V}let T=!1;e:for(let z=0;z<r.length;z+=3){let D=r[z],L=r[z+1],w=r[z+2],O=D*C+L*y+w*d,E=D*v+L*P+w*f,_=D*M+L*S+w*p;for(let N=0;N<k;N+=3){let G=l[N],$=l[N+1],F=l[N+2];if(!lr(G,$,F,O,E,_,u,a,s)){T=!0;break e}}}T&&c.push(e[u])}return c}var Mc=3,Vc=.03,vc=.02,fn={maxAngleDeg:Mc,maxPlaneDisplacement:Vc,maxBoundaryDisplacement:vc,isolatedPairs:!1},Ze={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725,isolatedPairs:!0},ot=[{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.02},{maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.0725},{maxAngleDeg:45,maxPlaneDisplacement:1,maxBoundaryDisplacement:.0725}],Cc=[2,4,6,8,12],Ac=300,Sc=.3,Tc=300,Oc=16,Ic=.015,ur=2.6,zc=3,wc=96,ke={minGroupPolygons:2,maxCandidateAxes:24},kc={maxGap:0,internalBoundaryLength:0,excessBoundaryLength:0};function at(e,n={}){let o=n.meshResolution??"lossy",t=Wt(e,!1),r={baseline:t},c=t,a=ce(t),s=(l,u=ce(l))=>u>=a?!1:(c=l,a=u,!0),i=tt(t,n.rectCover);if(i!==t&&s(i),o==="lossy"&&n.approximateMerge!==!1){let l=jc(e),u=[],m=he(l,c,Ze.maxBoundaryDisplacement).metrics,d=n.approximateMerge===void 0||n.approximateMerge===!0,f=(C,v=!0)=>!Uc(l,C.metrics,C.tolerance,v?m:null),p=(C,v)=>{s(C,v)},g=(C,v,M=Ze.maxBoundaryDisplacement)=>{!d||v>a+gr(a)||u.push({polygons:C,cost:v,maxBoundaryDisplacement:M})},x=fr(n.approximateMerge,d?t:void 0);for(let C=0;C<x.length;C++){let v=x[C],M=Wt(e,v,r),y=ce(M),P=null,S=()=>(P??(P=he(l,M,v.maxBoundaryDisplacement)),P),h=!0;if(d||v.guard){let k=S();h=f(k,!!v.allowReferenceCracks)}if(!h&&y<a)continue;h&&(p(M,y),g(M,y,v.maxBoundaryDisplacement));let b=tt(M,n.rectCover),A=ce(b),I=null,R=()=>(I??(I=he(l,b,v.maxBoundaryDisplacement)),I);if(b!==M&&A<a){let k=!0;(d||v.guard)&&(k=f(R(),!!v.allowReferenceCracks)),k&&(p(b,A),g(b,A,v.maxBoundaryDisplacement))}}if(d)for(let C of Rc(e)){let v={baseline:ae(Ce(C))},M=ce(v.baseline),y=!0,P=null,S=()=>(P??(P=he(l,v.baseline,Ze.maxBoundaryDisplacement)),P);M<a&&(y=f(S())),y&&(p(v.baseline,M),g(v.baseline,M));let h=tt(v.baseline,n.rectCover);if(h!==v.baseline){let b=ce(h);(b>=a||f(he(l,h,Ze.maxBoundaryDisplacement)))&&(p(h,b),g(h,b))}for(let b of fr(n.approximateMerge,v.baseline)){let A=Wt(C,b,v),I=ce(A),R=null,k=()=>(R??(R=he(l,A,b.maxBoundaryDisplacement)),R),T=!0;if(d||b.guard){let O=k();T=f(O,!!b.allowReferenceCracks)}if(!T&&I<a)continue;T&&(p(A,I),g(A,I,b.maxBoundaryDisplacement));let z=tt(A,n.rectCover),D=ce(z),L=null,w=()=>(L??(L=he(l,z,b.maxBoundaryDisplacement)),L);if(z!==A&&D<a){let O=!0;(d||b.guard)&&(O=f(w(),!!b.allowReferenceCracks)),O&&(p(z,D),g(z,D,b.maxBoundaryDisplacement))}}}if(d)for(let C of ot){let v=Mr({...C,isolatedPairs:!0}),M=oi(c,v);if(M===c)continue;let y=ce(M);if(y>=a)continue;let P=he(l,M,v.maxBoundaryDisplacement);f(P)&&(p(M,y),g(M,y,v.maxBoundaryDisplacement))}let V=Nc(u,c,a,C=>(C.metrics??(C.metrics=he(l,C.polygons,C.maxBoundaryDisplacement).metrics),C.metrics),()=>he(l,c,Ze.maxBoundaryDisplacement).metrics);V&&(c=V.polygons,a=V.cost)}return c}function Rc(e){let n=Ec(e);if(n.eligiblePolygons<24||n.colorCount<8)return[];let o=[],t=new Set;for(let r of Cc){let c=Dc(e,r,n.colorCount);if(!c)continue;let a=_c(c);t.has(a)||(t.add(a),o.push(c))}return o}function Ec(e){let n=new Set,o=0;for(let t of e)t.texture||t.material?.texture||t.uvs||t.textureTriangles?.length||pr(t.color)&&(o+=1,n.add(t.color??"#cccccc"));return{eligiblePolygons:o,colorCount:n.size}}function Dc(e,n,o){let t=!1,r=new Set,c=e.map(a=>{if(a.texture||a.material?.texture||a.uvs||a.textureTriangles?.length)return a;let s=pr(a.color);if(!s)return a;let i=Lc([Math.round(s[0]/n)*n,Math.round(s[1]/n)*n,Math.round(s[2]/n)*n]);return r.add(i),i===a.color?a:(t=!0,{...a,color:i})});return!t||r.size>=o?null:c}function pr(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 Lc(e){return`#${e.map(n=>Math.max(0,Math.min(255,Math.round(n))).toString(16).padStart(2,"0")).join("")}`}function _c(e){return e.map(n=>n.color??"").join("|")}function fr(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&&Gc(n))return[{...ot[0],isolatedPairs:!0,guard:!1,allowReferenceCracks:!0}];let o=[],t=new Set,r=n&&n.length>Tc?[!0]:[!0,!1];for(let c=0;c<ot.length;c++){let a=ot[c];for(let s of r){let i={...a,isolatedPairs:s,guard:c>0||s===!1,allowReferenceCracks:!0},l=[i.maxAngleDeg,i.maxPlaneDisplacement,i.maxBoundaryDisplacement,i.isolatedPairs].join("|");t.has(l)||(t.add(l),o.push(i))}}return o.length===0?[{...Ze,guard:!1}]:o}function Gc(e){return e.length<Ac?!1:xr(e)/e.length<=Sc}function ce(e){let n=0;for(let o of e){let t=o.vertices.length,r=t<=4?0:Math.min(4,t-4)*.12,c=o.texture||o.material?.texture||o.textureTriangles?.length?.15:0;n+=1+r+c}return n}function gr(e){return Math.max(Oc,e*Ic)}function Nc(e,n,o,t,r){if(e.length===0)return null;let c=gr(o),a=e.find(u=>u.polygons===n),s=null,i=null,l=null;for(let u of e){if(u.polygons===n||u.cost>o+c)continue;let m=t(u);s??(s=a?t(a):r()),Fc(m,s)&&(!i||!l||$c(u,m,i,l)<0)&&(i=u,l=m)}return i}function $c(e,n,o,t){return n.maxGap-t.maxGap||n.internalBoundaryLength-t.internalBoundaryLength||n.excessBoundaryLength-t.excessBoundaryLength||e.cost-o.cost}function Fc(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 Uc(e,n,o,t=null){if(!t)return n.internalBoundaryLength>0||n.excessBoundaryLength>o;let r=Math.max(o*.1,1e-6),c=t.maxGap+r,a=o<=.08?Math.max(c,Math.min(o*.75,.04)):c,s=Math.max(o*2,t.internalBoundaryLength*.15),i=Math.max(o*2,t.excessBoundaryLength*.15);return n.maxGap>a||n.internalBoundaryLength>t.internalBoundaryLength+s||n.excessBoundaryLength>t.excessBoundaryLength+i}function Bc(e,n,o=0,t=Zt(e,o)){let r=e.edges,c=yr(n),a=Zt(e,o),s=t>0?Hc(e,t):null,i={...kc,excessBoundaryLength:Math.max(0,c.boundaryLength-r.boundaryLength)};for(let l of c.boundarySegments){let u=Qe(l.a,l.b);if(r.boundaryKeys.has(u))continue;if(r.internalKeys.has(u)){i.internalBoundaryLength+=xe(l.a,l.b);continue}let m=s?Wc(l,s,t):null;m!==null&&(i.maxGap=Math.max(i.maxGap,m),i.internalBoundaryLength+=xe(l.a,l.b))}return{metrics:i,tolerance:a}}function he(e,n,o=0){return Bc(e,n,o,qc(e,o))}function jc(e){let n=Xc(e),o=n>0?Math.min(.08,Math.max(.001,n*.001)):0;return{edges:yr(e),baseTolerance:o,polygonCount:e.length,indexes:new Map}}function Zt(e,n=0){return Math.max(e.baseTolerance,n*1.05)}function qc(e,n=0){return Math.max(Zt(e,n),e.baseTolerance*ur,n*ur)}function Hc(e,n){let o=n.toFixed(6),t=e.indexes.get(o);if(t)return t;let r=Yc(e.edges.internalSegments,n);return e.indexes.set(o,r),r}function yr(e){let n=new Map;for(let s of e)for(let i=0;i<s.vertices.length;i++){let l=s.vertices[i],u=s.vertices[(i+1)%s.vertices.length],m=Qe(l,u),d=n.get(m);d?d.count+=1:n.set(m,{count:1,a:l,b:u})}let o=new Set,t=new Set,r=[],c=[],a=0;for(let[s,i]of n){let l={a:i.a,b:i.b};i.count===1?(o.add(s),r.push(l),a+=xe(l.a,l.b)):(t.add(s),c.push(l))}return{boundaryKeys:o,internalKeys:t,boundarySegments:r,internalSegments:c,boundaryLength:a}}function Xc(e){let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0;for(let s of e)for(let[i,l,u]of s.vertices)n=Math.min(n,i),o=Math.min(o,l),t=Math.min(t,u),r=Math.max(r,i),c=Math.max(c,l),a=Math.max(a,u);return Number.isFinite(n)?Math.hypot(r-n,c-o,a-t):0}function Yc(e,n){let o=Math.max(n*2,1e-6),t=new Map;for(let r of e){let[c,a,s]=hr(r,o),i=br(c,a,s),l=t.get(i);l?l.push(r):t.set(i,[r])}return{cellSize:o,cells:t}}function Wc(e,n,o){let[t,r,c]=hr(e,n.cellSize),a=null;for(let s=-1;s<=1;s++)for(let i=-1;i<=1;i++)for(let l=-1;l<=1;l++){let u=n.cells.get(br(t+s,r+i,c+l));if(u)for(let m of u){let d=Kc(e,m);d<=o&&(a=a===null?d:Math.min(a,d))}}return a}function hr(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 br(e,n,o){return`${e},${n},${o}`}function Kc(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 tt(e,n){if(n===!1)return e;let o=Zc(e,n);if(!o)return e;let t=nt(e,o);return t.length<e.length?t:e}function Zc(e,n){if(n&&n!==!0)return n;let o=e.length;return o>2200?null:o>1200?{...ke,maxCandidateAxes:Math.min(ke.maxCandidateAxes??24,2)}:o>300&&xr(e)<=wc?{...ke,maxCandidateAxes:Math.min(ke.maxCandidateAxes??24,2)}:o>900?{...ke,maxCandidateAxes:Math.min(ke.maxCandidateAxes??24,4)}:ke}function xr(e){let n=0;for(let o of e)o.vertices.length===3&&(n+=1);return n}function Wt(e,n,o){let t=Qn(e),r=o?.baseline??ae(Ce(t));if(!n)return r;let c=n===!0?fn:Mr(n);if(c.isolatedPairs){let s=Jc(Qc(t,o),c),i=ae(s);return i.length<r.length?i:r}let a=ae(Ce(di(t,c,o)));return a.length<r.length?a:r}function Pr(e,n){return n?(n.snapped||(n.snapped=st(e)),n.snapped):st(e)}function Qc(e,n){return n?(n.snappedInterior||(n.snappedInterior=Ce(Pr(e,n))),n.snappedInterior):Ce(st(e))}function Mr(e){return{maxAngleDeg:e.maxAngleDeg??fn.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??fn.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??fn.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??fn.isolatedPairs}}function Jc(e,n){let o=e.map(m=>{let d=dn(m);return d?{polygon:m,normal:d.normal,area:d.area,materialKey:eo(m)}:null}),t=new Map;for(let m=0;m<e.length;m++){let d=e[m];if(!(d.vertices.length!==3||!o[m]))for(let f=0;f<d.vertices.length;f++){let p=Qe(d.vertices[f],d.vertices[(f+1)%d.vertices.length]),g=t.get(p);g?g.push(m):t.set(p,[m])}}let r=[];for(let m of t.values()){if(m.length!==2)continue;let[d,f]=m,p=mi(d,f,e,o,n);p&&r.push(p)}let c=new Set,a=new Map,s=new Set,i=ei(r),l=lt(i.flatMap(m=>m.vertexMoves));for(let m of i){c.add(m.a),c.add(m.b);let d=Math.min(m.a,m.b);a.set(d,m.polygon),s.add(Math.max(m.a,m.b))}let u=[];for(let m=0;m<e.length;m++){let d=a.get(m);if(d){u.push(d);continue}s.has(m)||u.push(e[m])}return l.size>0?ut(u,l):u}function ei(e){return e.length>3e3?ni(e):ti(e)}function ni(e){let n=new Map;for(let c of e)n.set(c.a,(n.get(c.a)??0)+1),n.set(c.b,(n.get(c.b)??0)+1);let o=[...e].sort((c,a)=>{let s=(n.get(c.a)??0)+(n.get(c.b)??0),i=(n.get(a.a)??0)+(n.get(a.b)??0);return s-i||c.score-a.score}),t=new Set,r=[];for(let c of o)t.has(c.a)||t.has(c.b)||(t.add(c.a),t.add(c.b),r.push(c));return r}function ti(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],m=n.get(u.a);m?m.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let o=[],t=new Array(e.length).fill(!0),r=new Map,c=new Qt;for(let[l,u]of n)r.set(l,u.length);let a=l=>(r.get(l.a)??0)+(r.get(l.b)??0),s=l=>{let u=e[l];c.push({degree:a(u),score:u.score,index:l})},i=(l,u)=>{if(!t[l])return;t[l]=!1;let m=e[l];for(let d of[m.a,m.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)s(l);for(;c.size()>0;){let l=c.pop();if(!t[l.index])continue;let u=e[l.index];if(a(u)!==l.degree){s(l.index);continue}o.push(u);let d=new Set;for(let f of[u.a,u.b])for(let p of n.get(f)??[])i(p,d);for(let f of d)for(let p of n.get(f)??[])t[p]&&s(p)}return o}var Qt=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(Kt(this.items[t],this.items[o])<=0)break;[this.items[t],this.items[o]]=[this.items[o],this.items[t]],o=t}}pop(){if(this.items.length===0)return null;let n=this.items[0],o=this.items.pop();if(this.items.length>0){this.items[0]=o;let t=0;for(;;){let r=t*2+1,c=r+1,a=t;if(r<this.items.length&&Kt(this.items[r],this.items[a])<0&&(a=r),c<this.items.length&&Kt(this.items[c],this.items[a])<0&&(a=c),a===t)break;[this.items[t],this.items[a]]=[this.items[a],this.items[t]],t=a}}return n}};function Kt(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=ii(o);for(let c=0;c<zc;c++){let a=ri(o,n,r);if(!a)break;let s=ce(a.polygons);if(s>=t)break;o=a.polygons,t=s,r=a.origins}return o===e?e:o}function ri(e,n,o){let t=e.map(d=>{let f=dn(d);return f?{polygon:d,normal:f.normal,area:f.area,materialKey:eo(d)}:null}),r=new Map;for(let d=0;d<e.length;d++){let f=e[d];if(!(!t[d]||f.vertices.length<3))for(let p=0;p<f.vertices.length;p++){let g=Qe(f.vertices[p],f.vertices[(p+1)%f.vertices.length]),x=r.get(g);x?x.push({polygon:d,edge:p}):r.set(g,[{polygon:d,edge:p}])}}let c=[];for(let d of r.values()){if(d.length!==2)continue;let[f,p]=d,g=si(f.polygon,f.edge,p.polygon,p.edge,e,t,n);g&&c.push(g)}if(c.length===0)return null;c.sort((d,f)=>f.score-d.score);let a=new Set,s=[];for(let d of c)a.has(d.a)||a.has(d.b)||(a.add(d.a),a.add(d.b),s.push(d));if(s.length===0)return null;let i=lt(s.flatMap(d=>d.vertexMoves));if(!ci(i,o,n.maxBoundaryDisplacement))return null;let l=ut(e,i),u=ai(e,i,o),m=ae(l);return ce(m)<ce(e)?{polygons:m,origins:li(m,u)}:null}function si(e,n,o,t,r,c,a){let s=r[e],i=r[o],l=c[e],u=c[o];if(!l||!u||s.vertices.length===3&&i.vertices.length===3||!Or(s,i,l,u))return null;let m=Math.abs(ge(l.normal,u.normal)),d=Math.cos(a.maxAngleDeg*Math.PI/180);if(m<d)return null;let f=mr(s,i,n)??mr(i,s,t);if(!f||f.length<4||f.length>10)return null;let p=vr(f);if(!p)return null;let g=0,x=0;for(let h of f){let b=Math.abs(ft(h,p));g=Math.max(g,b),x+=b*b}if(g>Math.min(a.maxPlaneDisplacement,a.maxBoundaryDisplacement))return null;let V=f.map(h=>mt(h,p));if(!Cr(V,p.normal))return null;let C=dn({vertices:V});if(!C||ge(C.normal,l.normal)<.2||ge(C.normal,u.normal)<.2)return null;let v=[...f.map((h,b)=>({key:re(h),target:V[b]})),...Vr([s,i],p)],M=ut([s,i],lt(v)),y=ce([s,i]),P=ce(ae(M));if(P>=y)return null;let S=y-P-(x/f.length+g*.25+(1-m)*.1);return S<=0?null:{a:e,b:o,vertexMoves:v,score:S}}function mr(e,n,o){let t=e.vertices,r=n.vertices,c=t[o],a=t[(o+1)%t.length],s=-1;for(let u=0;u<r.length;u++)if(Ae(r[u],a)&&Ae(r[(u+1)%r.length],c)){s=u;break}if(s<0)return null;let i=[],l=(o+1)%t.length;for(i.push(t[l]);l!==o;)l=(l+1)%t.length,i.push(t[l]);for(l=(s+2)%r.length;l!==s;){let u=r[l];Ae(u,i[i.length-1])||i.push(u),l=(l+1)%r.length}return i.length>1&&Ae(i[0],i[i.length-1])&&i.pop(),i}function ci(e,n,o){for(let[t,r]of e){let c=ui(t),a=n.get(t)??(c?[c]:[]);if(a.length===0)return!1;for(let s of a)if(xe(s,r)>o+1e-6)return!1}return!0}function ii(e){let n=new Map;for(let o of e){for(let t of o.vertices)rt(n,re(t),t);for(let t of o.textureTriangles??[])for(let r of t.vertices)rt(n,re(r),r)}return n}function ai(e,n,o){let t=new Map;for(let r of e){let c=[...r.vertices,...(r.textureTriangles??[]).flatMap(a=>a.vertices)];for(let a of c){let s=re(a),i=n.get(s)??a,l=re(i);for(let u of o.get(s)??[a])rt(t,l,u)}}return t}function li(e,n){let o=new Map;for(let t of e){let r=[...t.vertices,...(t.textureTriangles??[]).flatMap(c=>c.vertices)];for(let c of r){let a=re(c);for(let s of n.get(a)??[c])rt(o,a,s)}}return o}function rt(e,n,o){let t=e.get(n);if(!t){e.set(n,[o]);return}let r=re(o);t.some(c=>re(c)===r)||t.push(o)}function ui(e){let n=e.split(",").map(Number);return n.length===3&&n.every(Number.isFinite)?[n[0],n[1],n[2]]:null}function lt(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 fi(e,n){let o=[];for(let t=0;t<e.length;t++){let r=e[t].vertices,c=n[t]?.vertices;if(!c||c.length!==r.length)continue;for(let i=0;i<r.length;i++)o.push({key:re(r[i]),target:c[i]});let a=e[t].textureTriangles??[],s=n[t]?.textureTriangles??[];for(let i=0;i<a.length;i++){let l=s[i];if(l)for(let u=0;u<a[i].vertices.length;u++)o.push({key:re(a[i].vertices[u]),target:l.vertices[u]})}}return o}function Vr(e,n){let o=[];for(let t of e)for(let r of t.textureTriangles??[])for(let c of r.vertices)o.push({key:re(c),target:mt(c,n)});return o}function ut(e,n){return e.map(o=>{let t=!1,r=s=>{let i=n.get(re(s));return i?(t=!0,i):s},c=o.vertices.map(r),a=Jt(o.textureTriangles,r);return t?{...o,vertices:c,...a?{textureTriangles:a}:{}}:o})}function mi(e,n,o,t,r){let c=o[e],a=o[n],s=t[e],i=t[n];if(!s||!i||c.vertices.length!==3||a.vertices.length!==3||!Or(c,a,s,i))return null;let l=to(c,a);if(!l)return null;let[u,m,d,f]=l;if((d+1)%a.vertices.length===f)return null;let g=Math.abs(ge(s.normal,i.normal)),x=Math.cos(r.maxAngleDeg*Math.PI/180);if(g<x)return null;let V=(m+1)%c.vertices.length,C=3-d-f,v=[c.vertices[m],c.vertices[V],c.vertices[u],a.vertices[C]],M=vr(v);if(!M)return null;let y=0,P=0;for(let A of v){let I=Math.abs(ft(A,M));y=Math.max(y,I),P+=I*I}if(y>Math.min(r.maxPlaneDisplacement,r.maxBoundaryDisplacement))return null;let S=v.map(A=>mt(A,M));if(!Cr(S,M.normal))return null;let h=dn({vertices:S});if(!h||ge(h.normal,s.normal)<.2||ge(h.normal,i.normal)<.2)return null;let b={vertices:v,color:c.color,...c.data?{data:{...c.data}}:{}};if(no(c,a)&&c.uvs&&a.uvs&&c.texture){b.texture=c.texture,b.uvs=[[...c.uvs[m]],[...c.uvs[V]],[...c.uvs[u]],[...a.uvs[C]]];let A=pi([c,a]);A?.length&&(b.textureTriangles=A)}return{a:e,b:n,polygon:b,vertexMoves:[...v.map((A,I)=>({key:re(A),target:S[I]})),...Vr([c,a],M)],score:P/v.length+y*.25+(1-g)*.1}}function vr(e){if(e.length<3)return null;let n=0,o=0,t=0,r=0,c=0,a=0;for(let i=0;i<e.length;i++){let l=e[i],u=e[(i+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),o+=(l[2]-u[2])*(l[0]+u[0]),t+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],c+=l[1],a+=l[2]}let s=Rr([n,o,t]);return s?{normal:s,point:[r/e.length,c/e.length,a/e.length]}:null}function Cr(e,n){let o=0;for(let t=0;t<e.length;t++){let r=e[t],c=e[(t+1)%e.length],a=e[(t+2)%e.length],s=ge(kr(mn(c,r),mn(a,c)),n);if(Math.abs(s)<=1e-9)continue;let i=s>0?1:-1;if(o===0)o=i;else if(o!==i)return!1}return!0}function di(e,n,o){let t=Pr(e,o),r=Pi(t,n);if(r<=0)return t;let c=t.map(f=>{let p=dn(f);return p?{polygon:f,normal:p.normal,area:p.area,materialKey:eo(f)}:null}),a=vi(t,c),s=new Set,i=Array(t.length),l=[],u=(f,p)=>{i[f]=p};for(let f=0;f<t.length;f++){let p=c[f];if(s.has(f))continue;if(!p){u(f,t[f]);continue}let g=Ai(f,c,a,s,r,n);for(let V of g)s.add(V);if(g.length<2){u(f,t[f]);continue}let x=hi(g,t,c,a,r,n);l.push(...x.vertexMoves);for(let V of g)u(V,x.polygons.get(V)??t[V])}let m=i.flatMap(f=>f?[f]:[]),d=l.length>0?ut(m,lt(l)):m;return st(d)}function st(e){let n=Tr(e),o=1e-4;if(n<=0)return e;let t=Mi(n),r=Vi(o);return e.map(c=>{let a=m=>t.snap(m),s=c.vertices.map(a),i=c.uvs&&c.uvs.length===c.vertices.length?c.uvs.map(m=>r.snap(m)):void 0,l=Jt(c.textureTriangles,a),u={...c,vertices:s,...i?{uvs:i}:{},...l?{textureTriangles:l}:{}};return{...u,...u.texture?{textureTriangles:Ar(u)}:{}}})}function Ar(e){if(e.texture){if(e.textureTriangles?.length)return yi(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return gi(e.vertices,e.uvs)}}function pi(e){let n=e.flatMap(o=>Ar(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 yi(e){return e.map(n=>({vertices:n.vertices.map(o=>[...o]),uvs:n.uvs.map(o=>[...o])}))}function Jt(e,n){if(e?.length)return e.map(o=>({vertices:o.vertices.map(n),uvs:o.uvs.map(t=>[...t])}))}function hi(e,n,o,t,r,c){let a=Sr(e,n,o,r,c);return a?xi(a):bi(e,n,o,t,r,c)}function bi(e,n,o,t,r,c){let a=new Set(e),s=[];for(let m of e)for(let d of t.get(m)??[]){if(m>=d||!a.has(d))continue;let f=Sr([m,d],n,o,r,c);f&&s.push(f)}s.sort((m,d)=>d.score-m.score);let i=new Set,l=new Map,u=[];for(let m of s)if(!m.indices.some(d=>i.has(d))){u.push(...m.vertexMoves);for(let d=0;d<m.indices.length;d++){let f=m.indices[d];i.add(f),l.set(f,n[f])}}return{polygons:l,vertexMoves:u}}function xi(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 Sr(e,n,o,t,r){let c=Ir(e,o);if(!c||!zr(e,o,c,t,r))return null;let a=e.map(u=>n[u]),s=a.map(u=>Oi(u,c)),i=ce(ae(a)),l=ce(ae(s));return l>=i?null:{indices:e,source:a,projected:s,vertexMoves:fi(a,s),score:i-l}}function Pi(e,n){return Tr(e)<=0?0:n.maxPlaneDisplacement}function Tr(e){let n=1/0,o=1/0,t=1/0,r=-1/0,c=-1/0,a=-1/0;for(let i of e)for(let[l,u,m]of i.vertices)n=Math.min(n,l),o=Math.min(o,u),t=Math.min(t,m),r=Math.max(r,l),c=Math.max(c,u),a=Math.max(a,m);if(!Number.isFinite(n))return 0;let s=Math.hypot(r-n,c-o,a-t);return s<=0?0:Math.min(.025,Math.max(1e-4,s*25e-5))}function Mi(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,c,a)=>`${r},${c},${a}`;return{snap(r){let c=o(r[0]),a=o(r[1]),s=o(r[2]);for(let m=-1;m<=1;m++)for(let d=-1;d<=1;d++)for(let f=-1;f<=1;f++){let p=n.get(t(c+m,a+d,s+f));if(p){for(let g of p)if(xe(r,g)<=e)return[g[0],g[1],g[2]]}}let i=[r[0],r[1],r[2]],l=t(c,a,s),u=n.get(l);return u?u.push(i):n.set(l,[i]),i}}}function Vi(e){let n=new Map,o=r=>Math.floor(r/e),t=(r,c)=>`${r},${c}`;return{snap(r){let c=o(r[0]),a=o(r[1]);for(let u=-1;u<=1;u++)for(let m=-1;m<=1;m++){let d=n.get(t(c+u,a+m));if(d){for(let f of d)if(Math.hypot(r[0]-f[0],r[1]-f[1])<=e)return[f[0],f[1]]}}let s=[r[0],r[1]],i=t(c,a),l=n.get(i);return l?l.push(s):n.set(i,[s]),s}}}function eo(e){return`${e.color??"#cccccc"}|${e.texture??""}|${e.uvs?"uv":"plain"}`}function dn(e){let n=e.vertices;if(!n||n.length<3)return null;let o=0,t=0,r=0,c=n[0];for(let s=1;s<n.length-1;s++){let i=mn(n[s],c),l=mn(n[s+1],c),u=kr(i,l);o+=u[0],t+=u[1],r+=u[2]}let a=Math.hypot(o,t,r);return a<=1e-10?null:{normal:[o/a,t/a,r/a],area:a/2}}function vi(e,n){let o=new Map,t=new Map;for(let r=0;r<e.length;r++){let c=e[r];if(!(!n[r]||c.vertices.length<3))for(let a=0;a<c.vertices.length;a++){let s=Qe(c.vertices[a],c.vertices[(a+1)%c.vertices.length]),i=o.get(s);i?i.push(r):o.set(s,[r])}}for(let r of o.values())for(let c=0;c<r.length;c++)for(let a=c+1;a<r.length;a++){let s=r[c],i=r[a];Ci(e[s],e[i],n[s],n[i])&&(dr(t,s,i),dr(t,i,s))}return t}function Ci(e,n,o,t){if(!o||!t||o.materialKey!==t.materialKey||!!e.uvs!=!!n.uvs)return!1;if(ct(e)||ct(n))return no(e,n);if(!e.uvs||!n.uvs)return!0;let r=to(e,n);if(!r)return!1;let[c,a,s,i]=r;return it(e.uvs[c],n.uvs[s])&&it(e.uvs[a],n.uvs[i])}function Or(e,n,o,t){return o.materialKey!==t.materialKey?!1:ct(e)||ct(n)?no(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function ct(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function no(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=to(e,n);if(!o)return!1;let[t,r,c,a]=o;return it(e.uvs[t],n.uvs[c])&&it(e.uvs[r],n.uvs[a])}function dr(e,n,o){let t=e.get(n);t?t.add(o):e.set(n,new Set([o]))}function Ai(e,n,o,t,r,c){let a=[e],s=new Set([e]),i=[e];for(;i.length>0;){let l=i.shift();for(let u of o.get(l)??[]){if(t.has(u)||s.has(u))continue;let m=n[u],d=n[e];!m||!d||m.materialKey===d.materialKey&&Si([...a,u],n,r,c)&&(a.push(u),s.add(u),i.push(u))}}return a}function Si(e,n,o,t){let r=Ir(e,n);return!!r&&zr(e,n,r,o,t)}function Ir(e,n){let o=n[e[0]];if(!o)return null;let t=0,r=0,c=0,a=0,s=0,i=0,l=0;for(let f of e){let p=n[f];if(!p)return null;let g=ge(o.normal,p.normal)<0?-1:1,x=Math.max(p.area,1e-6);t+=p.normal[0]*g*x,r+=p.normal[1]*g*x,c+=p.normal[2]*g*x;for(let V of p.polygon.vertices)a+=V[0],s+=V[1],i+=V[2],l+=1}let u=Rr([t,r,c]);if(!u||l===0)return null;let m=wr(e,n),d=Ti(e,n,u,m);if(d){let f=(d.min+d.max)/2;return{normal:u,point:[u[0]*f,u[1]*f,u[2]*f]}}return{normal:u,point:[a/l,s/l,i/l]}}function Ti(e,n,o,t){let r=1/0,c=-1/0;for(let a of e){let s=n[a];if(s)for(let i of s.polygon.vertices){if(!t.has(re(i)))continue;let l=ge(i,o);r=Math.min(r,l),c=Math.max(c,l)}}return Number.isFinite(r)&&Number.isFinite(c)?{min:r,max:c}:null}function zr(e,n,o,t,r){let c=Math.cos(r.maxAngleDeg*Math.PI/180),a=wr(e,n);for(let s of e){let i=n[s];if(!i||Math.abs(ge(i.normal,o.normal))<c)return!1;for(let l of i.polygon.vertices){let u=a.has(re(l))?r.maxBoundaryDisplacement:t;if(Math.abs(ft(l,o))>u)return!1}}return!0}function wr(e,n){let o=new Map;for(let r of e){let c=n[r];if(!c)continue;let a=c.polygon.vertices;for(let s=0;s<a.length;s++){let i=a[s],l=a[(s+1)%a.length],u=Qe(i,l),m=o.get(u);m?m.count+=1:o.set(u,{count:1,a:i,b:l})}}let t=new Set;for(let r of o.values())r.count===1&&(t.add(re(r.a)),t.add(re(r.b)));return t}function Oi(e,n){let o=r=>mt(r,n),t=Jt(e.textureTriangles,o);return{...e,vertices:e.vertices.map(o),...t?{textureTriangles:t}:{}}}function to(e,n){for(let o=0;o<e.vertices.length;o++){let t=(o+1)%e.vertices.length;for(let r=0;r<n.vertices.length;r++){let c=(r+1)%n.vertices.length;if(Ae(e.vertices[o],n.vertices[r])&&Ae(e.vertices[t],n.vertices[c]))return[o,t,r,c];if(Ae(e.vertices[o],n.vertices[c])&&Ae(e.vertices[t],n.vertices[r]))return[o,t,c,r]}}return null}function Qe(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 it(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function mn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function kr(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 Rr(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 ft(e,n){return ge(mn(e,n.point),n.normal)}function mt(e,n){let o=ft(e,n);return[e[0]-n.normal[0]*o,e[1]-n.normal[1]*o,e[2]-n.normal[2]*o]}var pn=1e-5,oo=.001,ro=6;function dt(e){let n=e.vertices;if(n.length<3)return null;let o=n[0],t=0,r=0,c=0;for(let s=1;s+1<n.length;s++){let i=n[s],l=n[s+1],u=i[1]-o[1],m=i[0]-o[0],d=i[2]-o[2],f=l[1]-o[1],p=l[0]-o[0],g=l[2]-o[2];t-=m*g-d*p,r-=d*f-u*g,c-=u*p-m*f}let a=Math.hypot(t,r,c);return a<1e-9?null:[t/a,r/a,c/a]}function so(e,n){let o=n.meshRotation,t=o?tn(e,o[0]??0,o[1]??0,o[2]??0):e;return tn(t,n.rotX,0,n.rotY)[2]}function pt(e,n,o=pn){return so(e,n)>o}function Er(e,n,o=pn){let t=dt(e);return t===null||pt(t,n,o)}function co(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function io(e){let n=new Map;for(let o of e){if(!o)continue;let t=co(o);n.has(t)||n.set(t,o)}return Array.from(n,([o,t])=>({key:o,normal:t}))}function Dr(e){return io(e.map(dt))}function ao(e,n=oo){let o=Math.abs(e[0]),t=Math.abs(e[1]),r=Math.abs(e[2]),c=Math.max(o,t,r);return c>1-n&&o+t+r-c<n}function Lr(e){return e.length<=ro&&e.every(({normal:n})=>ao(n))}function _r(e,n,o=pn){let t=[];for(let{key:r,normal:c}of e)pt(c,n,o)&&t.push(r);return t.sort(),t.join("|")}function lo(e,n,o,t,r){let c=(p,g,x)=>{let V=[0,0,0];return V[e]=p,V[(e+1)%3]=g,V[(e+2)%3]=x,V},a=c(n,-t,-t),s=c(n,t,-t),i=c(n,t,t),l=c(n,-t,t),u=c(o,-t,-t),m=c(o,t,-t),d=c(o,t,t),f=c(o,-t,t);return[{vertices:[a,s,i,l],color:r},{vertices:[u,m,d,f],color:r},{vertices:[a,s,m,u],color:r},{vertices:[s,i,d,m],color:r},{vertices:[i,l,f,d],color:r},{vertices:[l,a,u,f],color:r}]}function uo(e={}){let n=e.size??5,o=e.thickness??.025,t=e.negative??!1,r=e.xColor??"#ff3a3a",c=e.yColor??"#3aff3a",a=e.zColor??"#3a8aff",s=n*o/2,i=t?-n:0;return[...lo(0,i,n,s,r),...lo(1,i,n,s,c),...lo(2,i,n,s,a)]}function Gr(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 Ii(e,n,o,t,r){let c=(p,g,x)=>Gr(e,p,g,x),a=c(n,-t,-t),s=c(n,t,-t),i=c(n,t,t),l=c(n,-t,t),u=c(o,-t,-t),m=c(o,t,-t),d=c(o,t,t),f=c(o,-t,t);return[{vertices:[a,s,i,l],color:r},{vertices:[u,m,d,f],color:r},{vertices:[a,s,m,u],color:r},{vertices:[s,i,d,m],color:r},{vertices:[i,l,f,d],color:r},{vertices:[l,a,u,f],color:r}]}function zi(e,n,o,t,r){let c=(m,d,f)=>Gr(e,m,d,f),a=c(n,-t,-t),s=c(n,t,-t),i=c(n,t,t),l=c(n,-t,t),u=c(o,0,0);return[{vertices:[a,s,i,l],color:r},{vertices:[a,s,u],color:r},{vertices:[s,i,u],color:r},{vertices:[i,l,u],color:r},{vertices:[l,a,u],color:r}]}function wi(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function fo(e){let n=e.axis,o=e.sign??1,t=e.shaftLength??4,r=e.shaftHalfThickness??.05,c=e.headLength??.8,a=e.headHalfThickness??.2,s=e.color??"#ffffff",i=e.shaft??!0,l=t*o,u=Math.min(0,l),m=Math.max(0,l),d=l,f=(t+c)*o,p=zi(n,d,f,a,s),g=o===-1?wi(p):p;return i?[...Ii(n,u,m,r,s),...g]:g}function gt(e,n,o){let t=[0,0,0],r=(e+1)%3,c=(e+2)%3;return t[r]=Math.cos(o)*n,t[c]=Math.sin(o)*n,t}function mo(e){let n=e.axis,o=e.radius,t=e.halfThickness??Math.max(.05,o*.04),r=e.segments??32,c=e.color??"#ffffff",a=o-t,s=o+t,i=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,m=(l+1)/r*Math.PI*2,d=gt(n,a,u),f=gt(n,a,m),p=gt(n,s,u),g=gt(n,s,m);i.push({vertices:[d,p,g,f],color:c})}return i}function po(e){let n=e.axis,o=e.outerRadius,t=e.color??"#ffffff",r=(n+1)%3,c=(n+2)%3,a=(s,i)=>{let l=[0,0,0];return l[n]=0,l[r]=s,l[c]=i,l};return[{vertices:[a(-o,-o),a(o,-o),a(o,o),a(-o,o)],color:t}]}function go(e){let n=e.axis,o=e.size??.4,t=e.offset??o*2,r=typeof t=="number"?t:t[0],c=typeof t=="number"?t:t[1],a=e.along??0,s=e.color??"#ffffff",i=(n+1)%3,l=(n+2)%3,u=(m,d)=>{let f=[0,0,0];return f[n]=a,f[i]=r+m,f[l]=c+d,f};return[{vertices:[u(-o,-o),u(o,-o),u(o,o),u(-o,o)],color:s}]}function gn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=[[r+o,c,a],[r-o,c,a],[r,c+o,a],[r,c-o,a],[r,c,a+o],[r,c,a-o]];return[[0,2,4],[2,1,4],[1,3,4],[3,0,4],[2,0,5],[1,2,5],[3,1,5],[0,3,5]].map(l=>({vertices:[s[l[0]],s[l[1]],s[l[2]]],color:t}))}function yn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/Math.sqrt(3),i=[[r+s,c+s,a+s],[r-s,c-s,a+s],[r-s,c+s,a-s],[r+s,c-s,a-s]];return[[0,2,1],[0,1,3],[0,3,2],[1,2,3]].map(u=>({vertices:[i[u[0]],i[u[1]],i[u[2]]],color:t}))}function hn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/2,i=[[r-s,c-s,a-s],[r+s,c-s,a-s],[r+s,c+s,a-s],[r-s,c+s,a-s],[r-s,c-s,a+s],[r+s,c-s,a+s],[r+s,c+s,a+s],[r-s,c+s,a+s]];return[[4,5,6,7],[1,0,3,2],[5,1,2,6],[0,4,7,3],[7,6,2,3],[0,1,5,4]].map(u=>({vertices:[i[u[0]],i[u[1]],i[u[2]],i[u[3]]],color:t}))}function bn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=1/s,l=o/Math.sqrt(3),m=[[-1,-1,-1],[-1,-1,1],[-1,1,-1],[-1,1,1],[1,-1,-1],[1,-1,1],[1,1,-1],[1,1,1],[0,-s,-i],[0,-s,i],[0,s,-i],[0,s,i],[-i,0,-s],[i,0,-s],[-i,0,s],[i,0,s],[-s,-i,0],[-s,i,0],[s,-i,0],[s,i,0]].map(([f,p,g])=>[r+f*l,c+p*l,a+g*l]);return[[0,8,9,1,16],[0,12,13,4,8],[0,16,17,2,12],[1,9,5,15,14],[1,14,3,17,16],[2,10,6,13,12],[2,17,3,11,10],[3,14,15,7,11],[4,13,6,19,18],[4,18,5,9,8],[5,18,19,7,15],[6,10,11,7,19]].map(f=>({vertices:f.map(p=>m[p]),color:t}))}function xn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),u=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]].map(([d,f,p])=>[r+d*i,c+f*i,a+p*i]);return[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]].map(d=>({vertices:[u[d[0]],u[d[1]],u[d[2]]],color:t}))}function Nr(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 Pn(e){let{center:n,size:o,subdivisions:t=1,color:r="#ffffff"}=e,[c,a,s]=n,i=(1+Math.sqrt(5))/2,l=o/Math.sqrt(1+i*i),m=[[0,-1,-i],[0,-1,i],[0,1,-i],[0,1,i],[-1,-i,0],[-1,i,0],[1,-i,0],[1,i,0],[-i,0,-1],[i,0,-1],[-i,0,1],[i,0,1]].map(([f,p,g])=>Nr([f*l,p*l,g*l],o)),d=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]];for(let f=0;f<t;f++){let p=new Map,g=[],x=(V,C)=>{let v=V<C?`${V}_${C}`:`${C}_${V}`,M=p.get(v);if(M!==void 0)return M;let y=m[V],P=m[C],S=[(y[0]+P[0])/2,(y[1]+P[1])/2,(y[2]+P[2])/2],h=m.length;return m.push(Nr(S,o)),p.set(v,h),h};for(let[V,C,v]of d){let M=x(V,C),y=x(C,v),P=x(v,V);g.push([V,M,P],[M,C,y],[P,y,v],[M,y,P])}d=g}return d.map(([f,p,g])=>({vertices:[[m[f][0]+c,m[f][1]+a,m[f][2]+s],[m[p][0]+c,m[p][1]+a,m[p][2]+s],[m[g][0]+c,m[g][1]+a,m[g][2]+s]],color:r}))}function Mn(e){let{center:n,radius:o,height:t,sides:r=16,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[],d=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r,g=a+o*Math.cos(p),x=i+o*Math.sin(p);m.push([g,s-l,x]),d.push([g,s+l,x])}for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d[f],d[p],m[p],m[f]],color:c})}return u.push({vertices:[...d].reverse(),color:c}),u.push({vertices:[...m],color:c}),u}function Vn(e){let{center:n,radius:o,height:t,sides:r=16,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r;m.push([a+o*Math.cos(p),s-l,i+o*Math.sin(p)])}let d=[a,s+l,i];for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d,m[p],m[f]],color:c})}return u.push({vertices:[...m],color:c}),u}function vn(e){let{center:n,majorRadius:o,minorRadius:t,segments:r=24,sides:c=12,color:a="#ffffff"}=e,[s,i,l]=n,u=[];for(let d=0;d<r;d++){let f=2*Math.PI*d/r,p=Math.cos(f),g=Math.sin(f),x=[];for(let V=0;V<c;V++){let C=2*Math.PI*V/c,v=o+t*Math.cos(C);x.push([s+v*p,i+t*Math.sin(C),l+v*g])}u.push(x)}let m=[];for(let d=0;d<r;d++){let f=(d+1)%r;for(let p=0;p<c;p++){let g=(p+1)%c;m.push({vertices:[u[d][p],u[f][p],u[f][g],u[d][g]],color:a})}}return m}function Cn(e){let{center:n,radius:o,height:t,sides:r=4,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r;m.push([a+o*Math.cos(p),s-l,i+o*Math.sin(p)])}let d=[a,s+l,i];for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d,m[p],m[f]],color:c})}return u.push({vertices:[...m],color:c}),u}function An(e){let{center:n,radius:o,height:t,sides:r=6,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[],d=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r,g=a+o*Math.cos(p),x=i+o*Math.sin(p);m.push([g,s-l,x]),d.push([g,s+l,x])}for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d[f],d[p],m[p],m[f]],color:c})}return u.push({vertices:[...d].reverse(),color:c}),u.push({vertices:[...m],color:c}),u}function Sn(e){let{center:n,radius:o,height:t,sides:r=6,color:c="#ffffff"}=e,[a,s,i]=n,l=t/2,u=[],m=[],d=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r,g=p+Math.PI/r;m.push([a+o*Math.cos(p),s-l,i+o*Math.sin(p)]),d.push([a+o*Math.cos(g),s+l,i+o*Math.sin(g)])}for(let f=0;f<r;f++){let p=(f+1)%r;u.push({vertices:[d[f],m[p],m[f]],color:c}),u.push({vertices:[d[f],d[p],m[p]],color:c})}return u.push({vertices:[...d].reverse(),color:c}),u.push({vertices:[...m],color:c}),u}function Tn(e){let{center:n,radius:o,halfHeight:t,sides:r=6,color:c="#ffffff"}=e,[a,s,i]=n,l=[],u=[];for(let f=0;f<r;f++){let p=2*Math.PI*f/r;u.push([a+o*Math.cos(p),s,i+o*Math.sin(p)])}let m=[a,s+t,i],d=[a,s-t,i];for(let f=0;f<r;f++){let p=(f+1)%r;l.push({vertices:[m,u[p],u[f]],color:c})}for(let f=0;f<r;f++){let p=(f+1)%r;l.push({vertices:[d,u[f],u[p]],color:c})}return l}function On(e){let{center:n,radius:o,halfHeight:t,sides:r=5,color:c="#ffffff"}=e,[a,s,i]=n,l=Math.cos(Math.PI/r),u=t*(1-l)/(1+l),m=[],d=[],f=[];for(let x=0;x<r;x++){let V=2*Math.PI*x/r,C=V+Math.PI/r;d.push([a+o*Math.cos(V),s+u,i+o*Math.sin(V)]),f.push([a+o*Math.cos(C),s-u,i+o*Math.sin(C)])}let p=[a,s+t,i],g=[a,s-t,i];for(let x=0;x<r;x++){let V=(x+1)%r;m.push({vertices:[p,d[V],f[x],d[x]],color:c})}for(let x=0;x<r;x++){let V=(x+1)%r;m.push({vertices:[g,f[x],d[V],f[V]],color:c})}return m}function In(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),l=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],u=l.map(([p,g,x])=>[r+p*i,c+g*i,a+x*i]);function m(p,g){return p[0]*g[0]+p[1]*g[1]+p[2]*g[2]}function d(p){let g=Math.abs(p[0])<.9?[1,0,0]:[0,1,0],x=m(g,p),V=g[0]-x*p[0],C=g[1]-x*p[1],v=g[2]-x*p[2],M=Math.sqrt(V*V+C*C+v*v),y=[V/M,C/M,v/M],P=[p[1]*y[2]-p[2]*y[1],p[2]*y[0]-p[0]*y[2],p[0]*y[1]-p[1]*y[0]];return{u:y,w:P}}let f=[];for(let p=0;p<12;p++){let g=l[p],x=m(g,g),V=-1,C=1/0;for(let T=0;T<12;T++){if(T===p)continue;let z=m(l[T],g);z<C&&(C=z,V=T)}let v=[];for(let T=0;T<12;T++)T===p||T===V||v.push({idx:T,d:m(l[T],g)});v.sort((T,z)=>z.d-T.d);let M=v.slice(0,5).map(T=>T.idx),y=[g[0]/Math.sqrt(x),g[1]/Math.sqrt(x),g[2]/Math.sqrt(x)],{u:P,w:S}=d(y);M.sort((T,z)=>{let D=l[T],L=l[z],w=Math.atan2(m(D,S),m(D,P)),O=Math.atan2(m(L,S),m(L,P));return w-O});let b=[0,2,4,1,3].map(T=>M[T]),A=0,I=0,R=0;for(let T of b)A+=u[T][0],I+=u[T][1],R+=u[T][2];let k=[A/5,I/5,R/5];for(let T=0;T<5;T++){let z=u[b[T]],D=u[b[(T+2)%5]],L=[z[0]-k[0],z[1]-k[1],z[2]-k[2]],w=[D[0]-k[0],D[1]-k[1],D[2]-k[2]],O=L[1]*w[2]-L[2]*w[1],E=L[2]*w[0]-L[0]*w[2],_=L[0]*w[1]-L[1]*w[0],N=k[0]-r,G=k[1]-c,$=k[2]-a,F=O*N+E*G+_*$<0;f.push({vertices:F?[k,D,z]:[k,z,D],color:t})}}return f}function zn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),l=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],u=l.map(([p,g,x])=>[r+p*i,c+g*i,a+x*i]);function m(p,g){return p[0]*g[0]+p[1]*g[1]+p[2]*g[2]}function d(p){let g=Math.abs(p[0])<.9?[1,0,0]:[0,1,0],x=m(g,p),V=g[0]-x*p[0],C=g[1]-x*p[1],v=g[2]-x*p[2],M=Math.sqrt(V*V+C*C+v*v),y=[V/M,C/M,v/M],P=[p[1]*y[2]-p[2]*y[1],p[2]*y[0]-p[0]*y[2],p[0]*y[1]-p[1]*y[0]];return{u:y,w:P}}let f=[];for(let p=0;p<12;p++){let g=l[p],x=m(g,g),V=-1,C=1/0;for(let U=0;U<12;U++){if(U===p)continue;let B=m(l[U],g);B<C&&(C=B,V=U)}let v=[];for(let U=0;U<12;U++)U===p||U===V||v.push({idx:U,d:m(l[U],g)});v.sort((U,B)=>B.d-U.d);let M=v.slice(0,5).map(U=>U.idx),y=[g[0]/Math.sqrt(x),g[1]/Math.sqrt(x),g[2]/Math.sqrt(x)],{u:P,w:S}=d(y);M.sort((U,B)=>{let H=l[U],Z=l[B];return Math.atan2(m(H,S),m(H,P))-Math.atan2(m(Z,S),m(Z,P))});let h=0,b=0,A=0;for(let U of M)h+=u[U][0],b+=u[U][1],A+=u[U][2];h/=5,b/=5,A/=5;let I=u[M[0]],R=u[M[1]],k=u[M[2]],T=R[0]-I[0],z=R[1]-I[1],D=R[2]-I[2],L=k[0]-I[0],w=k[1]-I[1],O=k[2]-I[2],E=z*O-D*w,_=D*L-T*O,N=T*w-z*L,G=h-r,$=b-c,F=A-a,j=E*G+_*$+N*F<0?[...M].reverse():M;f.push({vertices:j.map(U=>u[U]),color:t})}return f}function wn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=1/s,l=o/Math.sqrt(3),m=[[-1,-1,-1],[-1,-1,1],[-1,1,-1],[-1,1,1],[1,-1,-1],[1,-1,1],[1,1,-1],[1,1,1],[0,-s,-i],[0,-s,i],[0,s,-i],[0,s,i],[-i,0,-s],[i,0,-s],[-i,0,s],[i,0,s],[-s,-i,0],[-s,i,0],[s,-i,0],[s,i,0]].map(([g,x,V])=>[r+g*l,c+x*l,a+V*l]),d=[[0,8,9,1,16],[0,12,13,4,8],[0,16,17,2,12],[1,9,5,15,14],[1,14,3,17,16],[2,10,6,13,12],[2,17,3,11,10],[3,14,15,7,11],[4,13,6,19,18],[4,18,5,9,8],[5,18,19,7,15],[6,10,11,7,19]],f=[0,2,4,1,3],p=[];for(let g of d){let x=f.map(y=>g[y]),V=0,C=0,v=0;for(let y of x)V+=m[y][0],C+=m[y][1],v+=m[y][2];let M=[V/5,C/5,v/5];for(let y=0;y<5;y++){let P=m[x[y]],S=m[x[(y+2)%5]],h=[P[0]-M[0],P[1]-M[1],P[2]-M[2]],b=[S[0]-M[0],S[1]-M[1],S[2]-M[2]],A=h[1]*b[2]-h[2]*b[1],I=h[2]*b[0]-h[0]*b[2],R=h[0]*b[1]-h[1]*b[0],k=M[0]-r,T=M[1]-c,z=M[2]-a,D=A*k+I*T+R*z<0;p.push({vertices:D?[M,S,P]:[M,P,S],color:t})}}return p}function kn(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=o/Math.sqrt(1+s*s),l=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],u=l.map(([f,p,g])=>[r+f*i,c+p*i,a+g*i]),m=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]],d=Array(12).fill(-1);for(let f=0;f<12;f++){let p=1/0;for(let g=0;g<12;g++){if(g===f)continue;let x=l[f][0]*l[g][0]+l[f][1]*l[g][1]+l[f][2]*l[g][2];x<p&&(p=x,d[f]=g)}}return m.map(([f,p,g])=>({vertices:[u[d[f]],u[d[g]],u[d[p]]],color:t}))}function Re(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/Math.sqrt(2),l=[[1,1,0],[1,-1,0],[-1,1,0],[-1,-1,0],[1,0,1],[1,0,-1],[-1,0,1],[-1,0,-1],[0,1,1],[0,1,-1],[0,-1,1],[0,-1,-1]].map(([d,f,p])=>[r+d*s,c+f*s,a+p*s]),u=[[0,8,4],[0,5,9],[1,4,10],[1,11,5],[2,6,8],[2,9,7],[3,10,6],[3,7,11]],m=[[8,6,10,4],[9,5,11,7],[0,4,1,5],[2,7,3,6],[0,9,2,8],[1,10,3,11]];return[...u.map(d=>({vertices:[l[d[0]],l[d[1]],l[d[2]]],color:t})),...m.map(d=>({vertices:[l[d[0]],l[d[1]],l[d[2]],l[d[3]]],color:t}))]}function Ee(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],l=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]],u=new Map,m=[];function d(b,A){return b<A?`${b},${A}`:`${A},${b}`}function f(b,A){let I=d(b,A);if(u.has(I))return u.get(I);let[R,k,T]=i[b],[z,D,L]=i[A],w=m.length;return m.push([(R+z)/2,(k+D)/2,(T+L)/2]),u.set(I,w),w}let p=Array.from({length:12},()=>[]),g=l.map(([b,A,I])=>{let R=f(b,A),k=f(A,I),T=f(I,b);return p[b].includes(R)||p[b].push(R),p[b].includes(T)||p[b].push(T),p[A].includes(R)||p[A].push(R),p[A].includes(k)||p[A].push(k),p[I].includes(k)||p[I].push(k),p[I].includes(T)||p[I].push(T),[R,k,T]}),[x,V,C]=m[0],v=Math.sqrt(x*x+V*V+C*C),M=o/v,y=m.map(([b,A,I])=>[r+b*M,c+A*M,a+I*M]);function P(b,A){let I=0,R=0,k=0;for(let H of b)I+=m[H][0],R+=m[H][1],k+=m[H][2];let T=b.length;I/=T,R/=T,k/=T;let[z,D,L]=A,[w,O,E]=m[b[0]],_=w-I,N=O-R,G=E-k,$=_*z+N*D+G*L;_-=$*z,N-=$*D,G-=$*L;let F=Math.sqrt(_*_+N*N+G*G);_/=F,N/=F,G/=F;let q=D*G-L*N,j=L*_-z*G,U=z*N-D*_,B=b.map(H=>{let[Z,J,ne]=m[H],ie=Z-I,oe=J-R,Q=ne-k,X=ie*_+oe*N+Q*G,K=ie*q+oe*j+Q*U;return{i:H,angle:Math.atan2(K,X)}});return B.sort((H,Z)=>H.angle-Z.angle),B.map(H=>H.i)}let S=g.map(([b,A,I])=>{let[R,k,T]=m[b],[z,D,L]=m[A],[w,O,E]=m[I],_=[(R+z+w)/3,(k+D+O)/3,(T+L+E)/3];return{vertices:P([b,A,I],_).map(G=>y[G]),color:t}}),h=i.map((b,A)=>{let I=p[A];return{vertices:P(I,b).map(T=>y[T]),color:t}});return[...S,...h]}function De(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=1/Math.sqrt(3),i=[[1,1,1],[-1,-1,1],[-1,1,-1],[1,-1,-1]],l=Array.from({length:4},()=>new Array(4)),u=[];for(let v=0;v<4;v++)for(let M=0;M<4;M++){if(v===M)continue;let[y,P,S]=i[v],[h,b,A]=i[M],I=[2/3*y+1/3*h,2/3*P+1/3*b,2/3*S+1/3*A];l[v][M]=I,u.push(I)}let m=0;for(let[v,M,y]of u){let P=Math.sqrt(v*v+M*M+y*y);P>m&&(m=P)}let d=o/m,f=(v,M)=>{let[y,P,S]=l[v][M];return[r+y*d,c+P*d,a+S*d]};function p(v){let M=[0,1,2,3].filter(G=>G!==v),[y,P,S]=M,h=f(v,y),b=f(v,P),A=f(v,S),[I,R,k]=i[v],T=b[0]-h[0],z=b[1]-h[1],D=b[2]-h[2],L=A[0]-h[0],w=A[1]-h[1],O=A[2]-h[2],E=z*O-D*w,_=D*L-T*O,N=T*w-z*L;return E*I+_*R+N*k<0?[h,A,b]:[h,b,A]}function g(v,M,y){let P=[f(v,M),f(M,v),f(M,y),f(y,M),f(y,v),f(v,y)],[S,h,b]=i[v],[A,I,R]=i[M],[k,T,z]=i[y],D=(S+A+k)/3,L=(h+I+T)/3,w=(b+R+z)/3,O=P[0],E=P[1],_=P[2],N=E[0]-O[0],G=E[1]-O[1],$=E[2]-O[2],F=_[0]-O[0],q=_[1]-O[1],j=_[2]-O[2],U=G*j-$*q,B=$*F-N*j,H=N*q-G*F;return U*D+B*L+H*w<0&&P.reverse(),P}let x=[0,1,2,3].map(v=>({vertices:p(v),color:t})),C=[[0,2,1],[0,1,3],[0,3,2],[1,2,3]].map(([v,M,y])=>({vertices:g(v,M,y),color:t}));return[...x,...C]}function Le(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(2-Math.sqrt(2))/2,i=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],l=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]],u=new Map;function m(y,P){let S=`${y},${P}`;if(u.has(S))return u.get(S);let[h,b,A]=i[y],[I,R,k]=i[P],T=[(1-s)*h+s*I,(1-s)*b+s*R,(1-s)*A+s*k];return u.set(S,T),T}for(let[y,P]of l)m(y,P),m(P,y);let d=0;for(let y of u.values()){let[P,S,h]=y,b=Math.sqrt(P*P+S*S+h*h);b>d&&(d=b)}let f=o/d,p=y=>[r+y[0]*f,c+y[1]*f,a+y[2]*f];function g(y,P){return p(m(y,P))}function x(y,P){let[S,h,b]=P,A=y[0],I=y[1],R=y[2],k=I[0]-A[0],T=I[1]-A[1],z=I[2]-A[2],D=R[0]-A[0],L=R[1]-A[1],w=R[2]-A[2],O=T*w-z*L,E=z*D-k*w,_=k*L-T*D;return O*S+E*h+_*b<0?[...y].reverse():y}let V=[[1,3,4],[0,2,5],[1,3,6],[0,2,7],[0,5,7],[1,4,6],[2,5,7],[3,4,6]],C=i.map(([y,P,S],h)=>{let[b,A,I]=V[h],R=[g(h,b),g(h,A),g(h,I)];return{vertices:x(R,[y,P,S]),color:t}}),M=[{corners:[4,5,6,7],normal:[0,0,1]},{corners:[1,0,3,2],normal:[0,0,-1]},{corners:[5,1,2,6],normal:[1,0,0]},{corners:[0,4,7,3],normal:[-1,0,0]},{corners:[7,6,2,3],normal:[0,1,0]},{corners:[0,1,5,4],normal:[0,-1,0]}].map(({corners:y,normal:P})=>{let[S,h,b,A]=y,I=[g(S,h),g(h,S),g(h,b),g(b,h),g(b,A),g(A,b),g(A,S),g(S,A)];return{vertices:x(I,P),color:t}});return[...C,...M]}function _e(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=o/Math.sqrt(5),i=new Set,l=[];for(let C=0;C<3;C++){let v=(C+1)%3,M=(C+2)%3;for(let y of[-1,1])for(let P of[-1,1])for(let S of[!1,!0]){let h=[0,0,0];h[v]=S?y*2:y*1,h[M]=S?P*1:P*2;let b=`${h[0]},${h[1]},${h[2]}`;i.has(b)||(i.add(b),l.push(h))}}let u=l.map(([C,v,M])=>[r+C*s,c+v*s,a+M*s]),m=new Map;for(let C=0;C<l.length;C++){let[v,M,y]=l[C];m.set(`${v},${M},${y}`,C)}function d(C,v,M){let y=`${C},${v},${M}`,P=m.get(y);if(P===void 0)throw new Error(`Vertex not found: (${C},${v},${M})`);return P}function f(C,v){let M=0,y=0,P=0;for(let G of C)M+=l[G][0],y+=l[G][1],P+=l[G][2];let S=C.length;M/=S,y/=S,P/=S;let[h,b,A]=v,[I,R,k]=l[C[0]],T=I-M,z=R-y,D=k-P,L=T*h+z*b+D*A;T-=L*h,z-=L*b,D-=L*A;let w=Math.sqrt(T*T+z*z+D*D);T/=w,z/=w,D/=w;let O=b*D-A*z,E=A*T-h*D,_=h*z-b*T,N=C.map(G=>{let[$,F,q]=l[G],j=$-M,U=F-y,B=q-P,H=j*T+U*z+B*D,Z=j*O+U*E+B*_;return{i:G,angle:Math.atan2(Z,H)}});return N.sort((G,$)=>G.angle-$.angle),N.map(G=>G.i)}let g=[{indices:[d(2,0,1),d(2,1,0),d(2,0,-1),d(2,-1,0)],normal:[1,0,0]},{indices:[d(-2,0,1),d(-2,1,0),d(-2,0,-1),d(-2,-1,0)],normal:[-1,0,0]},{indices:[d(0,2,1),d(1,2,0),d(0,2,-1),d(-1,2,0)],normal:[0,1,0]},{indices:[d(0,-2,1),d(1,-2,0),d(0,-2,-1),d(-1,-2,0)],normal:[0,-1,0]},{indices:[d(1,0,2),d(0,1,2),d(-1,0,2),d(0,-1,2)],normal:[0,0,1]},{indices:[d(1,0,-2),d(0,1,-2),d(-1,0,-2),d(0,-1,-2)],normal:[0,0,-1]}].map(({indices:C,normal:v})=>({vertices:f(C,v).map(M=>u[M]),color:t})),V=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]].map(([C,v,M])=>{let y=[];for(let S=0;S<l.length;S++){let[h,b,A]=l[S];Math.abs(C*h+v*b+M*A-3)<1e-9&&y.push(S)}let P=[C/Math.sqrt(3),v/Math.sqrt(3),M/Math.sqrt(3)];return{vertices:f(y,P).map(S=>u[S]),color:t}});return[...g,...V]}function Ge(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=1/s,l=[[-1,-1,-1],[-1,-1,1],[-1,1,-1],[-1,1,1],[1,-1,-1],[1,-1,1],[1,1,-1],[1,1,1],[0,-s,-i],[0,-s,i],[0,s,-i],[0,s,i],[-i,0,-s],[i,0,-s],[-i,0,s],[i,0,s],[-s,-i,0],[-s,i,0],[s,-i,0],[s,i,0]],u=[[0,8,9,1,16],[0,12,13,4,8],[0,16,17,2,12],[1,9,5,15,14],[1,14,3,17,16],[2,10,6,13,12],[2,17,3,11,10],[3,14,15,7,11],[4,13,6,19,18],[4,18,5,9,8],[5,18,19,7,15],[6,10,11,7,19]],m=new Set,d=[];for(let h of u)for(let b=0;b<5;b++){let A=h[b],I=h[(b+1)%5],R=A<I?`${A},${I}`:`${I},${A}`;m.has(R)||(m.add(R),d.push([A,I]))}let f=(3-Math.sqrt(5))/4,p=new Map;function g(h,b){let A=`${h},${b}`;if(p.has(A))return p.get(A);let[I,R,k]=l[h],[T,z,D]=l[b],L=[(1-f)*I+f*T,(1-f)*R+f*z,(1-f)*k+f*D];return p.set(A,L),L}for(let[h,b]of d)g(h,b),g(b,h);let x=0;for(let h of p.values()){let[b,A,I]=h,R=Math.sqrt(b*b+A*A+I*I);R>x&&(x=R)}let V=o/x,C=Array.from({length:20},()=>[]);for(let[h,b]of d)C[h].push(b),C[b].push(h);function v(h,b){let[A,I,R]=g(h,b);return[r+A*V,c+I*V,a+R*V]}function M(h,b){let[A,I,R]=b,k=h[0],T=h[1],z=h[2],D=T[0]-k[0],L=T[1]-k[1],w=T[2]-k[2],O=z[0]-k[0],E=z[1]-k[1],_=z[2]-k[2],N=L*_-w*E,G=w*O-D*_,$=D*E-L*O;return N*A+G*I+$*R<0?[...h].reverse():h}function y(h,b){let A=0,I=0,R=0;for(let[B,H,Z]of h)A+=B,I+=H,R+=Z;let k=h.length;A/=k,I/=k,R/=k;let[T,z,D]=b,[L,w,O]=h[0],E=L-A,_=w-I,N=O-R,G=E*T+_*z+N*D;E-=G*T,_-=G*z,N-=G*D;let $=Math.sqrt(E*E+_*_+N*N);E/=$,_/=$,N/=$;let F=z*N-D*_,q=D*E-T*N,j=T*_-z*E,U=h.map(B=>{let H=B[0]-A,Z=B[1]-I,J=B[2]-R,ne=H*E+Z*_+J*N,ie=H*F+Z*q+J*j;return{pt:B,angle:Math.atan2(ie,ne)}});return U.sort((B,H)=>B.angle-H.angle),U.map(B=>B.pt)}let P=l.map(([h,b,A],I)=>{let[R,k,T]=C[I],z=[g(I,R),g(I,k),g(I,T)],L=y(z,[h,b,A]).map(([w,O,E])=>[r+w*V,c+O*V,a+E*V]);return{vertices:M(L,[h,b,A]),color:t}}),S=u.map(h=>{let[b,A,I,R,k]=h,T=[g(b,A),g(A,b),g(A,I),g(I,A),g(I,R),g(R,I),g(R,k),g(k,R),g(k,b),g(b,k)],[z,D,L,w,O]=h.map(q=>l[q]),E=(z[0]+D[0]+L[0]+w[0]+O[0])/5,_=(z[1]+D[1]+L[1]+w[1]+O[1])/5,N=(z[2]+D[2]+L[2]+w[2]+O[2])/5,G=[E,_,N],F=y(T,G).map(([q,j,U])=>[r+q*V,c+j*V,a+U*V]);return{vertices:M(F,G),color:t}});return[...P,...S]}function Ne(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],l=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]],u=new Set,m=[];for(let[P,S,h]of l)for(let[b,A]of[[P,S],[S,h],[h,P]]){let I=b<A?`${b},${A}`:`${A},${b}`;u.has(I)||(u.add(I),m.push([b,A]))}let d=1/3,f=new Map;function p(P,S){let h=`${P},${S}`;if(f.has(h))return f.get(h);let[b,A,I]=i[P],[R,k,T]=i[S],z=[(1-d)*b+d*R,(1-d)*A+d*k,(1-d)*I+d*T];return f.set(h,z),z}for(let[P,S]of m)p(P,S),p(S,P);let g=0;for(let P of f.values()){let[S,h,b]=P,A=Math.sqrt(S*S+h*h+b*b);A>g&&(g=A)}let x=o/g,V=Array.from({length:12},()=>[]);for(let[P,S]of m)V[P].push(S),V[S].push(P);function C(P,S){let[h,b,A]=S,I=P[0],R=P[1],k=P[2],T=R[0]-I[0],z=R[1]-I[1],D=R[2]-I[2],L=k[0]-I[0],w=k[1]-I[1],O=k[2]-I[2],E=z*O-D*w,_=D*L-T*O,N=T*w-z*L;return E*h+_*b+N*A<0?[...P].reverse():P}function v(P,S){let h=0,b=0,A=0;for(let[j,U,B]of P)h+=j,b+=U,A+=B;let I=P.length;h/=I,b/=I,A/=I;let[R,k,T]=S,[z,D,L]=P[0],w=z-h,O=D-b,E=L-A,_=w*R+O*k+E*T;w-=_*R,O-=_*k,E-=_*T;let N=Math.sqrt(w*w+O*O+E*E);w/=N,O/=N,E/=N;let G=k*E-T*O,$=T*w-R*E,F=R*O-k*w,q=P.map(j=>{let U=j[0]-h,B=j[1]-b,H=j[2]-A,Z=U*w+B*O+H*E,J=U*G+B*$+H*F;return{pt:j,angle:Math.atan2(J,Z)}});return q.sort((j,U)=>j.angle-U.angle),q.map(j=>j.pt)}let M=i.map(([P,S,h],b)=>{let A=V[b].map(k=>p(b,k)),R=v(A,[P,S,h]).map(([k,T,z])=>[r+k*x,c+T*x,a+z*x]);return{vertices:C(R,[P,S,h]),color:t}}),y=l.map(([P,S,h])=>{let b=[p(P,S),p(S,P),p(S,h),p(h,S),p(h,P),p(P,h)],A=i[P],I=i[S],R=i[h],k=[(A[0]+I[0]+R[0])/3,(A[1]+I[1]+R[1])/3,(A[2]+I[2]+R[2])/3],z=v(b,k).map(([D,L,w])=>[r+D*x,c+L*x,a+w*x]);return{vertices:C(z,k),color:t}});return[...M,...y]}function ki(e,n){if(n.length<=3)return!0;let[o,t,r]=e[n[0]],[c,a,s]=e[n[1]],[i,l,u]=e[n[2]],m=c-o,d=a-t,f=s-r,p=i-o,g=l-t,x=u-r,V=d*x-f*g,C=f*p-m*x,v=m*g-d*p,M=Math.sqrt(V*V+C*C+v*v);if(M<1e-10)return!1;let y=1/M,P=(V*o+C*t+v*r)*y;for(let S=3;S<n.length;S++){let[h,b,A]=e[n[S]];if(Math.abs((V*h+C*b+v*A)*y-P)>1e-6)return!1}return!0}function Ri(e,n){let o=0,t=0,r=0;for(let h of n)o+=e[h][0],t+=e[h][1],r+=e[h][2];let c=n.length;o/=c,t/=c,r/=c;let[a,s,i]=e[n[0]],[l,u,m]=e[n[1]],[d,f,p]=e[n[2]],g=l-a,x=u-s,V=m-i,C=d-a,v=f-s,M=p-i,y=x*M-V*v,P=V*C-g*M,S=g*v-x*C;return y*o+P*t+S*r>0}function Ei(e){let n=e.indexOf(Math.min(...e));return[...e.slice(n),...e.slice(0,n)].join(",")}function te(e,n,o){let t=e.length,r=new Set,c=[];function a(s,i){let l=s[s.length-1];if(s.length===o){if(!n[l].includes(i)||!ki(e,s)||!Ri(e,s))return;let u=Ei(s);r.has(u)||(r.add(u),c.push([...s]));return}for(let u of n[l])s.includes(u)||u<=i||a([...s,u],i)}for(let s=0;s<t;s++)a([s],s);return c}function fe(e,n=1e-6){let o=e.length,t=1/0;for(let c=0;c<o;c++)for(let a=c+1;a<o;a++){let s=e[c][0]-e[a][0],i=e[c][1]-e[a][1],l=e[c][2]-e[a][2],u=Math.sqrt(s*s+i*i+l*l);u>1e-10&&u<t&&(t=u)}let r=Array.from({length:o},()=>[]);for(let c=0;c<o;c++)for(let a=c+1;a<o;a++){let s=e[c][0]-e[a][0],i=e[c][1]-e[a][1],l=e[c][2]-e[a][2],u=Math.sqrt(s*s+i*i+l*l);Math.abs(u-t)<n&&(r[c].push(a),r[a].push(c))}return{adj:r,edgeLen:t}}function me(e,n,o){let t=0,r=0,c=0;for(let P of n)t+=e[P][0],r+=e[P][1],c+=e[P][2];let a=n.length;t/=a,r/=a,c/=a;let[s,i,l]=o,[u,m,d]=e[n[0]],f=u-t,p=m-r,g=d-c,x=f*s+p*i+g*l;f-=x*s,p-=x*i,g-=x*l;let V=Math.sqrt(f*f+p*p+g*g);f/=V,p/=V,g/=V;let C=i*g-l*p,v=l*f-s*g,M=s*p-i*f,y=n.map(P=>{let[S,h,b]=e[P],A=S-t,I=h-r,R=b-c,k=A*f+I*p+R*g,T=A*C+I*v+R*M;return{i:P,angle:Math.atan2(T,k)}});return y.sort((P,S)=>P.angle-S.angle),y.map(P=>P.i)}function de(e,n){let o=0,t=0,r=0;for(let s of n)o+=e[s][0],t+=e[s][1],r+=e[s][2];let c=n.length;o/=c,t/=c,r/=c;let a=Math.sqrt(o*o+t*t+r*r);return[o/a,t/a,r/a]}function $e(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=1,i=1+Math.sqrt(2),l=1+2*Math.sqrt(2),u=[[s,i,l],[s,l,i],[i,s,l],[i,l,s],[l,s,i],[l,i,s]],m=[];for(let[b,A,I]of u)for(let R of[-1,1])for(let k of[-1,1])for(let T of[-1,1])m.push([R*b,k*A,T*I]);let d=new Set,f=[];for(let b of m){let A=`${b[0].toFixed(9)},${b[1].toFixed(9)},${b[2].toFixed(9)}`;d.has(A)||(d.add(A),f.push(b))}let[p,g,x]=f[0],V=Math.sqrt(p*p+g*g+x*x),C=o/V,v=f.map(([b,A,I])=>[r+b*C,c+A*C,a+I*C]),{adj:M}=fe(f),y=te(f,M,4),P=te(f,M,6),S=te(f,M,8);function h(b){let A=de(f,b);return{vertices:me(f,b,A).map(R=>v[R]),color:t}}return[...y.map(h),...P.map(h),...S.map(h)]}function Fe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[1/s,1/s,3+s],[2/s,s,1+2*s],[1/s,s*s,-1+3*s],[2*s-1,2,2+s],[s,3,2*s]],l=[];for(let[S,h,b]of i){let A=[[S,h,b],[h,b,S],[b,S,h]];for(let[I,R,k]of A)for(let T of[-1,1])for(let z of[-1,1])for(let D of[-1,1])l.push([T*I,z*R,D*k])}let u=new Set,m=[];for(let S of l){let h=`${S[0].toFixed(8)},${S[1].toFixed(8)},${S[2].toFixed(8)}`;u.has(h)||(u.add(h),m.push(S))}let[d,f,p]=m[0],g=Math.sqrt(d*d+f*f+p*p),x=o/g,V=m.map(([S,h,b])=>[r+S*x,c+h*x,a+b*x]),{adj:C}=fe(m),v=te(m,C,4),M=te(m,C,6),y=te(m,C,10);function P(S){let h=de(m,S);return{vertices:me(m,S,h).map(A=>V[A]),color:t}}return[...v.map(P),...M.map(P),...y.map(P)]}function Ue(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=1+Math.sqrt(2),i=[],l=[[1,1,s],[1,s,1],[s,1,1]];for(let[M,y,P]of l)for(let S of[-1,1])for(let h of[-1,1])for(let b of[-1,1])i.push([S*M,h*y,b*P]);let[u,m,d]=i[0],f=Math.sqrt(u*u+m*m+d*d),p=o/f,g=i.map(([M,y,P])=>[r+M*p,c+y*p,a+P*p]),{adj:x}=fe(i),V=te(i,x,3),C=te(i,x,4);function v(M){let y=de(i,M);return{vertices:me(i,M,y).map(S=>g[S]),color:t}}return[...V.map(v),...C.map(v)]}function Be(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=s*s,l=i*s,u=[];for(let[h,b,A]of[[1,1,l],[1,l,1],[l,1,1]])for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])u.push([I*h,R*b,k*A]);for(let[h,b,A]of[[i,s,2*s],[s,2*s,i],[2*s,i,s]])for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])u.push([I*h,R*b,k*A]);for(let[h,b,A]of[[2+s,0,i],[0,i,2+s],[i,2+s,0]])for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])u.push([I*h,R*b,k*A]);let m=new Set,d=[];for(let h of u){let b=`${h[0].toFixed(8)},${h[1].toFixed(8)},${h[2].toFixed(8)}`;m.has(b)||(m.add(b),d.push(h))}let[f,p,g]=d[0],x=Math.sqrt(f*f+p*p+g*g),V=o/x,C=d.map(([h,b,A])=>[r+h*V,c+b*V,a+A*V]),{adj:v}=fe(d),M=te(d,v,3),y=te(d,v,4),P=te(d,v,5);function S(h){let b=de(d,h);return{vertices:me(d,h,b).map(I=>C[I]),color:t}}return[...M.map(S),...y.map(S),...P.map(S)]}function je(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.cbrt(19+3*Math.sqrt(33))+Math.cbrt(19-3*Math.sqrt(33)))/3,i=1,l=1/s,u=s,m=[[i,l,u],[l,u,i],[u,i,l]],d=[[u,l,i],[l,i,u],[i,u,l]],f=[];for(let[h,b,A]of m)for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(k===-1?1:0))%2===0&&f.push([I*h,R*b,k*A]);for(let[h,b,A]of d)for(let I of[-1,1])for(let R of[-1,1])for(let k of[-1,1])((I===-1?1:0)+(R===-1?1:0)+(k===-1?1:0))%2===1&&f.push([I*h,R*b,k*A]);let[p,g,x]=f[0],V=Math.sqrt(p*p+g*g+x*x),C=o/V,v=f.map(([h,b,A])=>[r+h*C,c+b*C,a+A*C]),{adj:M}=fe(f),y=te(f,M,3),P=te(f,M,4);function S(h){let b=de(f,h);return{vertices:me(f,h,b).map(I=>v[I]),color:t}}return[...y.map(S),...P.map(S)]}function qe(e){let{center:n,size:o,color:t="#ffffff"}=e,[r,c,a]=n,s=(1+Math.sqrt(5))/2,i=[[0,-1,-s],[0,-1,s],[0,1,-s],[0,1,s],[-1,-s,0],[-1,s,0],[1,-s,0],[1,s,0],[-s,0,-1],[s,0,-1],[-s,0,1],[s,0,1]],l=Math.sqrt(1+s*s),u=i.map(([T,z,D])=>[T/l,z/l,D/l]),m=[[0,2,9],[0,4,8],[0,6,4],[0,8,2],[0,9,6],[1,3,10],[1,4,6],[1,6,11],[1,10,4],[1,11,3],[2,5,7],[2,7,9],[2,8,5],[3,5,10],[3,7,5],[3,11,7],[4,10,8],[5,8,10],[6,9,11],[7,11,9]];function d(T,z){return[T[1]*z[2]-T[2]*z[1],T[2]*z[0]-T[0]*z[2],T[0]*z[1]-T[1]*z[0]]}function f(T){return Math.sqrt(T[0]*T[0]+T[1]*T[1]+T[2]*T[2])}function p(T){let z=f(T);return[T[0]/z,T[1]/z,T[2]/z]}function g(T,z){return Math.sqrt((T[0]-z[0])**2+(T[1]-z[1])**2+(T[2]-z[2])**2)}function x(T,z,D,L){let[w,O,E]=u[T],[_,N,G]=u[z],$=[(1-D)*w+D*_,(1-D)*O+D*N,(1-D)*E+D*G],F=p(d(u[T],u[z]));return p([$[0]+L*F[0],$[1]+L*F[1],$[2]+L*F[2]])}function V(T,z){let D=x(0,2,T,z),L=x(2,9,T,z),w=x(2,0,T,z);return g(D,L)-g(D,w)}function C(T,z){let D=x(0,2,T,z),L=x(2,9,T,z),w=x(0,9,T,z);return g(D,L)-g(D,w)}let v=.35,M=.13,y=1e-7;for(let T=0;T<80;T++){let z=V(v,M),D=C(v,M);if(Math.abs(z)<1e-13&&Math.abs(D)<1e-13)break;let L=(V(v+y,M)-V(v-y,M))/(2*y),w=(V(v,M+y)-V(v,M-y))/(2*y),O=(C(v+y,M)-C(v-y,M))/(2*y),E=(C(v,M+y)-C(v,M-y))/(2*y),_=L*E-w*O;if(Math.abs(_)<1e-12)break;v-=(z*E-D*w)/_,M-=(D*L-z*O)/_}let P=new Set,S=[];for(let[T,z,D]of m)for(let[L,w]of[[T,z],[z,D],[D,T],[z,T],[D,z],[T,D]]){let O=`${L},${w}`;P.has(O)||(P.add(O),S.push(x(L,w,v,M)))}let h=S,b=h.map(([T,z,D])=>[r+T*o,c+z*o,a+D*o]),{adj:A}=fe(h),I=te(h,A,3),R=te(h,A,5);function k(T){let z=de(h,T);return{vertices:me(h,T,z).map(L=>b[L]),color:t}}return[...I.map(k),...R.map(k)]}function Di(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 Li(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function _i(e){let n=Li(e);return[e[0]/n,e[1]/n,e[2]/n]}function Gi(e){let[n,o,t]=e[0],[r,c,a]=e[1],[s,i,l]=e[2],u=r-n,m=c-o,d=a-t,f=s-n,p=i-o,g=l-t,x=m*g-d*p,V=d*f-u*g,C=u*p-m*f,v=e.reduce((h,b)=>h+b[0],0)/e.length,M=e.reduce((h,b)=>h+b[1],0)/e.length,y=e.reduce((h,b)=>h+b[2],0)/e.length,P=x*v+V*M+C*y>0?1:-1,S=Math.sqrt(x*x+V*V+C*C);return[P*x/S,P*V/S,P*C/S]}function ee(e){let o=[],t=[];function r(m){for(let d=0;d<o.length;d++)if(Di(o[d],m)<1e-10)return d;return o.push(m),o.length-1}for(let m of e)t.push(m.vertices.map(d=>r(d)));let c=e.length,a=o.length,s=Math.max(...o.map(m=>m[0]*m[0]+m[1]*m[1]+m[2]*m[2])),i=e.map((m,d)=>{let f=m.vertices,p=Gi(f),g=f[0],x=p[0]*g[0]+p[1]*g[1]+p[2]*g[2],V=s/x;return[p[0]*V,p[1]*V,p[2]*V]}),l=Array.from({length:a},()=>[]);for(let m=0;m<c;m++)for(let d of t[m])l[d].push(m);let u=[];for(let m=0;m<a;m++){let d=l[m];if(d.length<3)continue;let f=o[m],p=_i(f),g=i[d[0]],x=g[0]-f[0],V=g[1]-f[1],C=g[2]-f[2],v=x*p[0]+V*p[1]+C*p[2];x-=v*p[0],V-=v*p[1],C-=v*p[2];let M=Math.sqrt(x*x+V*V+C*C);if(M<1e-12)continue;let y=[x/M,V/M,C/M],P=[p[1]*y[2]-p[2]*y[1],p[2]*y[0]-p[0]*y[2],p[0]*y[1]-p[1]*y[0]],S=d.map(h=>{let b=i[h],A=b[0]-f[0],I=b[1]-f[1],R=b[2]-f[2],k=A*y[0]+I*y[1]+R*y[2],T=A*P[0]+I*P[1]+R*P[2];return{fi:h,angle:Math.atan2(T,k)}});S.sort((h,b)=>h.angle-b.angle),u.push(S.map(h=>h.fi))}return u.map(m=>({vertices:m.map(d=>i[d]),color:"#ffffff"}))}function Rn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Re({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function En(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ee({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Dn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=De({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Ln(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Le({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function _n(e){let{center:n,size:o,color:t="#ffffff"}=e,r=_e({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Gn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ge({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Nn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ne({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function $n(e){let{center:n,size:o,color:t="#ffffff"}=e,r=$e({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Fn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Fe({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Un(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Ue({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function Bn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=Be({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function jn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=je({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function qn(e){let{center:n,size:o,color:t="#ffffff"}=e,r=qe({center:[0,0,0],size:o});return ee(r).map(a=>({vertices:a.vertices.map(([s,i,l])=>[s+n[0],i+n[1],l+n[2]]),color:t}))}function yo(e,n={}){let{center:o=[0,0,0],size:t=1,color:r}=n;switch(e){case"tetrahedron":return yn({center:o,size:t,color:r});case"cube":return hn({center:o,size:t,color:r});case"octahedron":return gn({center:o,size:t,color:r});case"dodecahedron":return bn({center:o,size:t,color:r});case"icosahedron":return xn({center:o,size:t,color:r});case"smallStellatedDodecahedron":return In({center:o,size:t,color:r});case"greatDodecahedron":return zn({center:o,size:t,color:r});case"greatStellatedDodecahedron":return wn({center:o,size:t,color:r});case"greatIcosahedron":return kn({center:o,size:t,color:r});case"cuboctahedron":return Re({center:o,size:t,color:r});case"icosidodecahedron":return Ee({center:o,size:t,color:r});case"truncatedTetrahedron":return De({center:o,size:t,color:r});case"truncatedCube":return Le({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 Ne({center:o,size:t,color:r});case"truncatedCuboctahedron":return $e({center:o,size:t,color:r});case"truncatedIcosidodecahedron":return Fe({center:o,size:t,color:r});case"rhombicuboctahedron":return Ue({center:o,size:t,color:r});case"rhombicosidodecahedron":return Be({center:o,size:t,color:r});case"snubCube":return je({center:o,size:t,color:r});case"snubDodecahedron":return qe({center:o,size:t,color:r});case"rhombicDodecahedron":return Rn({center:o,size:t,color:r});case"rhombicTriacontahedron":return En({center:o,size:t,color:r});case"triakisTetrahedron":return Dn({center:o,size:t,color:r});case"triakisOctahedron":return Ln({center:o,size:t,color:r});case"triakisIcosahedron":return Gn({center:o,size:t,color:r});case"tetrakisHexahedron":return _n({center:o,size:t,color:r});case"pentakisDodecahedron":return Nn({center:o,size:t,color:r});case"disdyakisDodecahedron":return $n({center:o,size:t,color:r});case"disdyakisTriacontahedron":return Fn({center:o,size:t,color:r});case"deltoidalIcositetrahedron":return Un({center:o,size:t,color:r});case"deltoidalHexecontahedron":return Bn({center:o,size:t,color:r});case"pentagonalIcositetrahedron":return jn({center:o,size:t,color:r});case"pentagonalHexecontahedron":return qn({center:o,size:t,color:r});case"sphere":return Pn({center:o,size:t,color:r});case"cylinder":return Mn({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 vn({center:o,majorRadius:t,minorRadius:t*.3,color:r});case"pyramid":return Cn({center:o,radius:t,height:t*2,color:r});case"prism":return An({center:o,radius:t,height:t*2,color:r});case"antiprism":return Sn({center:o,radius:t,height:t*2,color:r});case"bipyramid":return Tn({center:o,radius:t,halfHeight:t,color:r});case"trapezohedron":return On({center:o,radius:t,halfHeight:t,color:r});default:{let c=e;throw new Error(`Unknown geometry: ${String(c)}`)}}}var $r=2200,Fr=2201,Ur=2202;function Ni(e,n){let o=0,t=1,r=1,c=2201,a=1/0,s=0,i=!1,l=null,u=!0,m=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(f){r=f},get weight(){return t},set weight(f){t=f},get time(){return o},set time(f){o=f},get isRunning(){return i},get enabled(){return u},set enabled(f){u=f},get paused(){return m},set paused(f){m=f},play(){return i=!0,d},stop(){return i=!1,o=0,s=0,l=null,d},reset(){return o=0,s=0,d},fadeIn(f){return l={from:0,to:1,elapsed:0,duration:f},t=0,d},fadeOut(f){return l={from:t,to:0,elapsed:0,duration:f},d},crossFadeTo(f,p){return d.fadeOut(p),f.fadeIn(p),d},crossFadeFrom(f,p){return f.fadeOut(p),d.fadeIn(p),d},setLoop(f,p){return c=f,a=p,d},setEffectiveTimeScale(f){return r=f,d},setEffectiveWeight(f){return t=f,d}};return d._internal={get clip(){return e},get time(){return o},get weight(){return t},get enabled(){return u},get paused(){return m},get running(){return i},get loopMode(){return c},get repetitions(){return a},get completedReps(){return s},set completedReps(f){s=f},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(f){if(!i)return;if(l){l.elapsed+=f;let g=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(t=l.from+(l.to-l.from)*g,g>=1&&(t=l.to,l=null,t<=0)){i=!1;return}}if(m)return;let p=e.duration;if(!(p<=0)){if(o+=f*r,c===2200)o>=p&&(o=d.clampWhenFinished?p:0,i=!1);else if(c===2201){if(o>=p){let g=o%p,x=Math.floor(o/p);s+=x,o=g,a!==1/0&&s>=a&&(o=d.clampWhenFinished?p:0,i=!1)}}else if(p>0){let g=p*2,x=o%g;if(o>=g){let V=Math.floor(o/g);s+=V,a!==1/0&&s>=a?(o=d.clampWhenFinished?p:0,i=!1):o=x}}}},sampleTime(){if(c===2202){let f=e.duration,p=f*2,g=o%p;return g<=f?g:p-g}return o}},d}function $i(e){return e._internal}function ho(e,n){return typeof n=="number"?e[n]:e.find(o=>o.name===n)}function Br(e,n){let o=new Map;function t(l){let u=ho(n.clips,l);if(!u)throw new Error(`GlyphAnimationMixer: no clip found for key "${l}". Available: ${n.clips.map(d=>d.name).join(", ")}`);let m=o.get(u.index);return m||(m=Ni(u,n),o.set(u.index,m)),m}function r(l){let u=ho(n.clips,l);return u?o.get(u.index)??null:null}function c(l){let u=[];for(let g of o.values()){let x=$i(g);x.advance(l),x.running&&x.enabled&&u.push({internal:x,clip:x.clip})}if(u.length===0)return;if(u.length===1){let{internal:g,clip:x}=u[0],V=n.sample(x.name,g.sampleTime());e.setPolygons(V);return}let m=0;for(let{internal:g}of u)m+=g.weight;if(m<=0)return;let d=u.map(({internal:g,clip:x})=>({polygons:n.sample(x.name,g.sampleTime()),weight:g.weight/m})),f=d[0].polygons;if(f.length===0)return;let p=f.map((g,x)=>{let V=g.vertices.map((C,v)=>{let M=0,y=0,P=0;for(let{polygons:S,weight:h}of d){let b=S[x];if(!b)continue;let A=b.vertices[v];A&&(M+=A[0]*h,y+=A[1]*h,P+=A[2]*h)}return[M,y,P]});return{...g,vertices:V}});e.setPolygons(p)}function a(){for(let l of o.values())l.stop()}function s(l){let u=ho(n.clips,l);u&&o.delete(u.index)}function i(){o.clear()}return{clipAction:t,existingAction:r,update:c,stopAllAction:a,uncacheClip:s,uncacheRoot:i}}var Fi=/^[0-9A-Fa-f]{6}$/,Ui=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function yt(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",c=n?.palette??Ui,a=n?.materialColors??{},s=n?.materialTextures??{},i=[],l=[],u=[],m=[],d=new Map,f=r,p,g=n?.includeObjects?new Set(n.includeObjects):null,x=n?.excludeObjects?new Set(n.excludeObjects):null,V=null,C=()=>V===null?g===null:!(g&&!g.has(V)||x&&x.has(V)),v=L=>L in a?a[L]:Fi.test(L)?`#${L}`:(d.has(L)||(d.set(L,c[m.length%c.length]),m.push(L)),d.get(L)),M=e.split(`
|
|
2
|
-
`);for(let L of
|
|
3
|
-
`)){let c=r.trim();if(!(c.length===0||c.charCodeAt(0)===35)){if(c.startsWith("newmtl ")){t=c.slice(7).trim();continue}if(t){if(c.startsWith("Kd ")){let a=c.split(/\s+/),s=parseFloat(a[1]),i=parseFloat(a[2]),l=parseFloat(a[3]);Number.isFinite(s)&&Number.isFinite(i)&&Number.isFinite(l)&&(n[t]=`#${bo(s)}${bo(i)}${bo(l)}`)}else if(c.startsWith("map_Kd ")){let a=c.split(/\s+/),s=a[a.length-1]?.replace(/\\+/g,"/");s&&s!=="map_Kd"&&(o[t]=s)}}}}return{colors:n,textures:o}}var Yr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Wr={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Kr(e){let n=globalThis.TextDecoder;return new n().decode(e)}function ji(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let o=e.slice(5,n),t=e.slice(n+1);if(!o.includes(";base64")){let a=decodeURIComponent(t),s=new Uint8Array(a.length);for(let i=0;i<a.length;i++)s[i]=a.charCodeAt(i)&255;return s}let r=globalThis.atob(t),c=new Uint8Array(r.length);for(let a=0;a<r.length;a++)c[a]=r.charCodeAt(a);return c}function qi(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 ji(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 Hi(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let o=n.getUint32(4,!0);if(o!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${o})`);let t=12,r=null,c=null;for(;t<e.byteLength;){let a=n.getUint32(t,!0),s=n.getUint32(t+4,!0),i=t+8;if(s===1313821514){let l=new Uint8Array(e,i,a);r=JSON.parse(Kr(l))}else s===5130562&&(c=new Uint8Array(e,i,a));t=i+a}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:c}}function xo(e,n,o){let t=e.accessors?.[o],r=e.bufferViews?.[t?.bufferView??-1];if(!t||!r)throw new Error(`parseGltf: bad accessor/bufferView ${o}`);let c=Yr[t.componentType],a=Wr[t.type];if(!c||!a)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let s=(r.byteOffset??0)+(t.byteOffset??0),i=t.count*a,l=n.buffer.slice(n.byteOffset+s,n.byteOffset+s+i*c),u;switch(t.componentType){case 5126:u=new Float32Array(l);break;case 5123:u=new Uint16Array(l);break;case 5125:u=new Uint32Array(l);break;case 5121:u=new Uint8Array(l);break;default:throw new Error(`parseGltf: unhandled componentType ${t.componentType}`)}return{array:u,count:t.count,componentCount:a}}function Xi(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 Yi(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 Pt(e,n,o){let t=e.accessors?.[o],r=e.bufferViews?.[t?.bufferView??-1];if(!t||!r)throw new Error(`parseGltf: bad accessor/bufferView ${o}`);let c=Yr[t.componentType],a=Wr[t.type];if(!c||!a)throw new Error(`parseGltf: unsupported accessor type ${t.type}/${t.componentType}`);let s=n.byteOffset+(r.byteOffset??0)+(t.byteOffset??0),i=r.byteStride??c*a,l=new DataView(n.buffer),u=new Array(t.count*a),m=0;for(let d=0;d<t.count;d++){let f=s+d*i;for(let p=0;p<a;p++){let g=Xi(l,f+p*c,t.componentType);u[m++]=t.normalized?Yi(g,t.componentType):g}}return{values:u,count:t.count,componentCount:a}}function Wi(e,n,o){let t=[],r=[],c=globalThis;for(let a of e.images??[]){if(a.uri){if(o&&!a.uri.startsWith("data:"))try{t.push(new c.URL(a.uri,o).href)}catch{t.push(a.uri)}else t.push(a.uri);continue}if(a.bufferView!==void 0){let s=e.bufferViews?.[a.bufferView];if(!s){t.push("");continue}let i=s.byteOffset??0,l=n.subarray(i,i+s.byteLength),u=a.mimeType??"image/png",m=new c.Blob([l],{type:u}),d=c.URL.createObjectURL(m);t.push(d),r.push(d)}else t.push("")}return{urls:t,objectUrls:r}}function Ki(e,n){let o=new Map,t=e.materials??[];for(let r=0;r<t.length;r++){let c=t[r].pbrMetallicRoughness?.baseColorTexture?.index;if(c===void 0)continue;let a=e.textures?.[c]?.source;if(a===void 0)continue;let s=n[a];s&&o.set(r,s)}return o}function Zi(e,n){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let t=s=>Math.max(0,Math.min(1,s)),r=s=>Math.round(t(s)*255).toString(16).padStart(2,"0"),c=s=>Math.round(t(s)*255),a=t(o[3]??1);return a<1?`rgba(${c(o[0])}, ${c(o[1])}, ${c(o[2])}, ${Math.round(a*1e3)/1e3})`:`#${r(o[0])}${r(o[1])}${r(o[2])}`}var Je=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Po(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 xt(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 Zr(e,n,o){let t=e?.[0]??0,r=e?.[1]??0,c=e?.[2]??0,a=n?.[0]??0,s=n?.[1]??0,i=n?.[2]??0,l=n?.[3]??1,u=o?.[0]??1,m=o?.[1]??1,d=o?.[2]??1,f=a+a,p=s+s,g=i+i,x=a*f,V=a*p,C=a*g,v=s*p,M=s*g,y=i*g,P=l*f,S=l*p,h=l*g;return[(1-(v+y))*u,(V+h)*u,(C-S)*u,0,(V-h)*m,(1-(x+y))*m,(M+P)*m,0,(C+S)*d,(M-P)*d,(1-(x+v))*d,0,t,r,c,1]}function Qi(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Zr(e.translation,e.rotation,e.scale)}function Ji(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function jr(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function Qr(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 Hn(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 ea(e,n,o){let t=Hn(e),r=Hn(n),c=t[0]*r[0]+t[1]*r[1]+t[2]*r[2]+t[3]*r[3];if(c<0&&(c=-c,r=[-r[0],-r[1],-r[2],-r[3]]),c>.9995)return Hn(Qr(t,r,o));let a=Math.acos(Math.max(-1,Math.min(1,c))),s=Math.sin(a),i=Math.sin((1-o)*a)/s,l=Math.sin(o*a)/s;return Hn([t[0]*i+r[0]*l,t[1]*i+r[1]*l,t[2]*i+r[2]*l,t[3]*i+r[3]*l])}function na(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 qr(e){return e.matrix?e.matrix.slice():Zr(e.translation,e.rotation,e.scale)}function ta(e){let n=e.scene??0,o=e.scenes?.[n]?.nodes;return o&&o.length>0?o:[]}function Hr(e,n){let o=e.nodes??[],t=new Array(o.length),r=new Set,c=(s,i)=>{if(s<0||s>=o.length)return;let l=Po(i,n[s]??Je);t[s]=l,r.add(s);for(let u of o[s].children??[])c(u,l)},a=ta(e);if(a.length>0)for(let s of a)c(s,Je);for(let s=0;s<o.length;s++)r.has(s)||c(s,Je);return t}function Xr(e,n,o,t,r){if(o===void 0)return;let{values:c,count:a,componentCount:s}=Pt(e,n,o);if(a!==r||s<1)return;let i=[];for(let l=0;l<a;l++){let u=[];for(let m=0;m<t;m++)u.push(c[l*s+m]??0);i.push(u)}return i}function oa(e,n,o,t){if(o===void 0)return Array.from({length:t},()=>Je.slice());let{values:r,componentCount:c,count:a}=Pt(e,n,o);if(c!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${o} is not MAT4`);let s=[];for(let i=0;i<t;i++){let l=Math.min(i,a-1);s.push(r.slice(l*16,l*16+16))}return s}function bt(e,n){let o=e.componentCount,t=e.interpolation==="CUBICSPLINE"?(n*3+1)*o:n*o;return e.output.slice(t,t+o)}function ra(e,n,o){let t=e.input;if(t.length===0)return[];if(t.length===1||n<=t[0])return bt(e,0);let r=t.length-1;if(n>=t[r])return bt(e,r);let c=0,a=r;for(;c+1<a;){let d=c+a>>1;t[d]<=n?c=d:a=d}let s=t[c],i=t[c+1],l=i>s?(n-s)/(i-s):0,u=bt(e,c),m=bt(e,c+1);return e.interpolation==="STEP"?u:o==="rotation"?ea(u,m,l):Qr(u,m,l)}function sa(e,n,o,t){let r=e.animations??[];if(r.length===0||o.length===0)return;let c=(e.nodes??[]).map(f=>na(f)),a=c.map(qr),s=Hr(e,a),i=(e.skins??[]).map(f=>({joints:f.joints??[],inverseBindMatrices:oa(e,n,f.inverseBindMatrices,f.joints?.length??0)})),l=[];for(let f=0;f<r.length;f++){let p=r[f],g=(p.samplers??[]).map(C=>{let v=Pt(e,n,C.input),M=Pt(e,n,C.output);return{input:v.values,output:M.values,componentCount:M.componentCount,interpolation:C.interpolation??"LINEAR"}}),x=[];for(let C of p.channels??[]){let v=C.target.node,M=C.target.path,y=g[C.sampler];v===void 0||!M||!y||M==="weights"||x.push({sampler:y,targetNode:v,path:M})}let V=x.reduce((C,v)=>{let M=v.sampler.input;return Math.max(C,M[M.length-1]??0)},0);l.push({info:{index:f,name:p.name??`animation_${f}`,duration:V,channelCount:x.length},channels:x})}let u=l.map(f=>f.info);if(u.length===0)return;let m=(f,p,g,x,V,C)=>{let v=t(f),M=t(p),y=t(g);if(v[0]===M[0]&&v[1]===M[1]&&v[2]===M[2]||v[0]===y[0]&&v[1]===y[1]&&v[2]===y[2]||M[0]===y[0]&&M[1]===y[1]&&M[2]===y[2])return null;let P={vertices:[v,M,y],color:x};return V&&(P.texture=V),C&&(P.uvs=C),P};return{clips:u,sample:(f,p)=>{let g=typeof f=="number"?l[f]:l.find(y=>y.info.name===f);if(!g)return[];let x=g.info.duration,V=x>0?(p%x+x)%x:Math.max(0,p),C=c.map(y=>({translation:y.translation.slice(),rotation:y.rotation.slice(),scale:y.scale.slice(),matrix:y.matrix?y.matrix.slice():void 0}));for(let y of g.channels){let P=C[y.targetNode];if(!P)continue;let S=ra(y.sampler,V,y.path);P.matrix=void 0,y.path==="translation"?P.translation=S.slice(0,3):y.path==="rotation"?P.rotation=Hn(S.slice(0,4)):y.path==="scale"&&(P.scale=S.slice(0,3))}let v=Hr(e,C.map(qr)),M=[];for(let y of o){let P=[];if(y.skinIndex!==void 0&&y.joints&&y.weights&&i[y.skinIndex]){let S=i[y.skinIndex];for(let h=0;h<y.positions.length;h++){let b=y.positions[h],A=[0,0,0],I=0,R=y.joints[h]??[],k=y.weights[h]??[];for(let T=0;T<4;T++){let z=k[T]??0;if(z<=0)continue;let D=Math.round(R[T]??0),L=S.joints[D],w=v[L],O=S.inverseBindMatrices[D];if(!w||!O)continue;let E=Po(w,O);A=Ji(A,jr(xt(E,b),z)),I+=z}P.push(I>0?jr(A,1/I):xt(y.meshBindWorld,b))}}else{let S=y.meshNode!==null?v[y.meshNode]??y.meshBindWorld:y.meshBindWorld;for(let h of y.positions)P.push(xt(S,h))}for(let S=0;S+2<y.indices.length;S+=3){let h=y.indices[S],b=y.indices[S+1],A=y.indices[S+2],I=P[h],R=P[b],k=P[A];if(!I||!R||!k)continue;let T;if(y.uvs&&y.texture){let D=y.uvs[h],L=y.uvs[b],w=y.uvs[A];D&&L&&w&&(T=[D,L,w])}let z=m(I,R,k,y.color,y.texture,T);z&&M.push(z)}}return M}}}function Mt(e,n){let o=n?.targetSize??60,t=n?.gridShift??1,r=n?.defaultColor??"#888888",c=n?.materialColors??{},a=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,s=a.byteLength,i,l;if(a.byteLength>=4&&new DataView(a).getUint32(0,!0)===1179937895){let O=Hi(a);if(i=O.doc,!O.bin)throw new Error("parseGltf: GLB has no binary chunk");l=O.bin}else i=JSON.parse(Kr(new Uint8Array(a))),l=qi(i,n?.resolveBuffer);let{urls:u,objectUrls:m}=Wi(i,l,n?.baseUrl),d=Ki(i,u),f=[],p=[],g=(i.meshes??[]).map((O,E)=>O.name??`mesh_${E}`),x=(i.materials??[]).map((O,E)=>O.name??`material_${E}`);function V(O,E,_){let N=i.meshes?.[O];if(N)for(let G of N.primitives){if((G.mode??4)!==4)continue;let F=G.material!==void 0?i.materials?.[G.material]?.name:void 0,j=(F?c[F]:void 0)??Zi(G.material!==void 0?i.materials?.[G.material]:void 0,r),U=G.material!==void 0?d.get(G.material):void 0,{array:B,count:H}=xo(i,l,G.attributes.POSITION);if(!(B instanceof Float32Array))continue;let Z=[],J=[];for(let Q=0;Q<H;Q++){let X=[B[Q*3],B[Q*3+1],B[Q*3+2]];Z.push(X),J.push(xt(E,X))}let ne=null,ie=G.attributes.TEXCOORD_0;if(U&&ie!==void 0){let{array:Q,count:X}=xo(i,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(G.indices!==void 0){let{array:Q,count:X}=xo(i,l,G.indices);oe=[];for(let K=0;K<X;K++)oe.push(Number(Q[K]))}else oe=J.map((Q,X)=>X);if((i.animations?.length??0)>0){let Q=Xr(i,l,G.attributes.JOINTS_0,4,H),X=Xr(i,l,G.attributes.WEIGHTS_0,4,H);p.push({meshNode:_,meshBindWorld:E,skinIndex:_!==null?i.nodes?.[_]?.skin:void 0,positions:Z,indices:oe,color:j,texture:U,uvs:ne??void 0,joints:Q,weights:X})}for(let Q=0;Q+2<oe.length;Q+=3){let X=J[oe[Q]],K=J[oe[Q+1]],le=J[oe[Q+2]];if(!X||!K||!le)continue;let Pe;if(ne&&U){let Te=ne[oe[Q]],Xe=ne[oe[Q+1]],Ye=ne[oe[Q+2]];Te&&Xe&&Ye&&(Pe=[Te,Xe,Ye])}f.push({v0:X,v1:K,v2:le,color:j,texture:U,uvs:Pe})}}}function C(O,E){let _=i.nodes?.[O];if(!_)return;let N=Po(E,Qi(_));typeof _.mesh=="number"&&V(_.mesh,N,O);for(let G of _.children??[])C(G,N)}let v=i.scene??0,M=i.scenes?.[v]?.nodes;if(M&&M.length>0)for(let O of M)C(O,Je);else for(let O=0;O<(i.meshes?.length??0);O++)V(O,Je,null);let y=ca(m);if(f.length===0)return{polygons:[],objectUrls:m,dispose:y,warnings:[],metadata:{triangleCount:0,meshes:g,materials:x,sourceBytes:s}};let P=1/0,S=1/0,h=1/0,b=-1/0,A=-1/0,I=-1/0;for(let O of f)for(let E of[O.v0,O.v1,O.v2])E[0]<P&&(P=E[0]),E[0]>b&&(b=E[0]),E[1]<S&&(S=E[1]),E[1]>A&&(A=E[1]),E[2]<h&&(h=E[2]),E[2]>I&&(I=E[2]);let R=Math.max(b-P,A-S,I-h),k=R>0?o/R:1,T=O=>Math.round(O*1e3)/1e3,D=(n?.upAxis??"y")==="z"?([O,E,_])=>[T((O-P)*k+t),T((E-S)*k+t),T((_-h)*k+t)]:([O,E,_])=>[T((_-h)*k+t),T((O-P)*k+t),T((E-S)*k+t)],L=sa(i,l,p,D),w=[];for(let O of f){let E=D(O.v0),_=D(O.v1),N=D(O.v2);if(E[0]===_[0]&&E[1]===_[1]&&E[2]===_[2]||E[0]===N[0]&&E[1]===N[1]&&E[2]===N[2]||_[0]===N[0]&&_[1]===N[1]&&_[2]===N[2])continue;let G={vertices:[E,_,N],color:O.color};O.texture&&(G.texture=O.texture),O.uvs&&(G.uvs=O.uvs),w.push(G)}return{polygons:w,animation:L,objectUrls:m,dispose:y,warnings:[],metadata:{triangleCount:w.length,meshes:g,materials:x,animations:L?.clips,sourceBytes:s}}}function ca(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 Mo(e){return e.material?.texture??e.texture}function ia(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function aa(e,n){return new Promise((o,t)=>{let r=new n,c=!1,a=s=>{c||(c=!0,s())};r.decoding="async",r.onload=()=>a(()=>o(r)),r.onerror=()=>a(()=>t(new Error(`texture load failed: ${e}`))),r.src=e,typeof r.decode=="function"&&r.decode().then(()=>a(()=>o(r)),()=>{})})}async function la(e,n,o){try{let t=await aa(e,n.Image),r=Math.max(0,Math.floor(t.naturalWidth||t.width||0)),c=Math.max(0,Math.floor(t.naturalHeight||t.height||0));if(r<=0||c<=0||r*c>o)return null;let a=n.createCanvas();a.width=r,a.height=c;let s=a.getContext("2d",{willReadFrequently:!0});if(!s)return null;s.drawImage(t,0,0,r,c);let i=s.getImageData(0,0,r,c).data;return{width:r,height:c,data:i,lowDetail:ua(r,c,i)}}catch{return null}}function Jr(e,n,o,t,r,c){let a=(t*n+o)*4,s=(c*n+r)*4;return Math.max(Math.abs((e[a]??0)-(e[s]??0)),Math.abs((e[a+1]??0)-(e[s+1]??0)),Math.abs((e[a+2]??0)-(e[s+2]??0)))}function ua(e,n,o){let t=Math.max(1,Math.floor(Math.max(e,n)/128)),r=0,c=0,a=0;for(let s=0;s<n;s+=t)for(let i=0;i<e;i+=t){if(i+t<e){let l=Jr(o,e,i,s,i+t,s);a+=l,r++,l>32&&c++}if(s+t<n){let l=Jr(o,e,i,s,i,s+t);a+=l,r++,l>32&&c++}}return r>0&&c/r<=.045&&a/r<=10}function es(e,n,o){return Math.max(n,Math.min(o,e))}function fa(e,n){let o=n[0],t=1-n[1];if(!Number.isFinite(o)||!Number.isFinite(t))return null;let r=es(Math.floor(o*e.width),0,e.width-1),a=(es(Math.floor(t*e.height),0,e.height-1)*e.width+r)*4;return{r:e.data[a]??0,g:e.data[a+1]??0,b:e.data[a+2]??0,a:e.data[a+3]??255}}function Se(e,n,o,t,r,c){return[e[0]*t+n[0]*r+o[0]*c,e[1]*t+n[1]*r+o[1]*c]}function ma(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 da(e){let[n,o,t]=e,r=ma(e);for(let c=1;c<6;c++)for(let a=1;a<6-c;a++){let s=6-c-a;s<=0||r.push(Se(n,o,t,c/6,a/6,s/6))}return r}function rs(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 ns(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 ts(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 pa(){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 ga(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 os(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 ya(e,n,o,t){let r=rs(e);if(r.length===0||!t&&!n.lowDetail)return null;let c=pa();for(let a of r)for(let s of da(a.uvs)){let i=fa(n,s);if(!i)return null;ga(c,i)}return c.count===0?null:ns(c.min,c.max,o)?ts(os(c)):t||!ns(c.min,c.max,32)?null:ts(os(c))}function ha(e,n){let{texture:o,material:t,uvs:r,textureTriangles:c,...a}=e;return{...a,color:n}}async function ss(e,n={}){if(n.enabled===!1)return null;let o=ia();if(!o)return null;let t=e.filter(i=>Mo(i)&&rs(i).length>0);if(t.length===0)return null;let r=n.maxTexturePixels??16777216,c=new Map;await Promise.all(Array.from(new Set(t.map(i=>Mo(i)))).map(async i=>{c.set(i,await la(i,o,r))}));let a=n.colorTolerance??2,s=n.colorTolerance!==void 0;return{bake(i){let l=!1,u=i.map(m=>{let d=Mo(m);if(!d)return m;let f=c.get(d);if(!f)return m;let p=ya(m,f,a,s);return p?(l=!0,ha(m,p)):m});return{polygons:l?u:i,changed:l}}}}async function cs(e,n={}){let o=await ss(e,n);return o?o.bake(e).polygons:e}async function Vt(e,n={}){let o=await ss(e.polygons,n);if(!o)return e;let t=o.bake(e.polygons);return!t.changed&&!e.animation?e:{...e,polygons:t.polygons,animation:e.animation?{...e.animation,sample(r,c){return o.bake(e.animation.sample(r,c)).polygons}}:e.animation}}var ba=[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 xa(e){let n=e>>0&255,o=e>>8&255,t=e>>16&255;return[n,o,t]}function Vo(e){return(e&255).toString(16).padStart(2,"0")}function as(e,n,o){return`#${Vo(e)}${Vo(n)}${Vo(o)}`}function Pa(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 Ma=542658390;function vt(e,n){let o=n?.targetSize??60,t=n?.gridShift??0,r=e.byteLength;if(e.byteLength<8)return en(r,["parseVox: buffer too small to be a valid .vox file"]);let c=new DataView(e);if(c.getUint32(0,!0)!==Ma)return en(r,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return en(r,["parseVox: buffer too small for MAIN chunk"]);if(is(c,8)!=="MAIN")return en(r,["parseVox: expected MAIN chunk at offset 8"]);let l=20+c.getUint32(12,!0),u=l+c.getUint32(16,!0),m=[],d=[],f=null;for(;l<u&&l+12<=e.byteLength;){let w=is(c,l),O=c.getUint32(l+4,!0),E=c.getUint32(l+8,!0),_=l+12,N=_+O+E;if(w==="SIZE"){if(O>=12&&_+12<=e.byteLength){let G=c.getUint32(_,!0),$=c.getUint32(_+4,!0),F=c.getUint32(_+8,!0);m.push({sx:G,sy:$,sz:F})}}else if(w==="XYZI"){if(O>=4&&_+4<=e.byteLength){let G=c.getUint32(_,!0),$=[],F=Math.min(G,Math.floor((O-4)/4));for(let q=0;q<F;q++){let j=_+4+q*4;$.push({x:c.getUint8(j),y:c.getUint8(j+1),z:c.getUint8(j+2),colorIndex:c.getUint8(j+3)})}d.push($)}}else if(w==="RGBA"&&O>=1024&&_+1024<=e.byteLength){f=[];for(let G=0;G<256;G++){let $=_+G*4,F=c.getUint8($),q=c.getUint8($+1),j=c.getUint8($+2),U=c.getUint8($+3);f.push(Pa(F,q,j,U))}}l=N}let p=[],g=new Set;for(let w of d)for(let O of w){if(O.colorIndex===0)continue;let E=`${O.x},${O.y},${O.z}`;g.has(E)||(g.add(E),p.push(O))}if(p.length===0)return en(r,[]);let x=w=>{let O=w-1;if(f!==null)return f[O]??"#888888";let E=ba[w]??0,[_,N,G]=xa(E);return as(_,N,G)},V=(w,O,E)=>g.has(`${w},${O},${E}`),C=new Map,v=(w,O,E,_,N)=>{let G=`${w}:${O}:${N}`,$=C.get(G);$||($=new Set,C.set(G,$)),$.add(`${E},${_}`)};for(let w of p){let{x:O,y:E,z:_}=w,N=x(w.colorIndex);V(O+1,E,_)||v(0,O+1,E,_,N),V(O-1,E,_)||v(1,O,E,_,N),V(O,E+1,_)||v(2,E+1,O,_,N),V(O,E-1,_)||v(3,E,O,_,N),V(O,E,_+1)||v(4,_+1,O,E,N),V(O,E,_-1)||v(5,_,O,E,N)}function M(w){let O=new Set,E=[],_=1/0,N=-1/0,G=1/0,$=-1/0;for(let F of w){let[q,j]=F.split(","),U=+q,B=+j;U<_&&(_=U),U>N&&(N=U),B<G&&(G=B),B>$&&($=B)}for(let F=G;F<=$;F++)for(let q=_;q<=N;q++){let j=`${q},${F}`;if(!w.has(j)||O.has(j))continue;let U=1;for(;q+U<=N;){let H=`${q+U},${F}`;if(!w.has(H)||O.has(H))break;U++}let B=1;e:for(;F+B<=$;){for(let H=0;H<U;H++){let Z=`${q+H},${F+B}`;if(!w.has(Z)||O.has(Z))break e}B++}for(let H=0;H<B;H++)for(let Z=0;Z<U;Z++)O.add(`${q+Z},${F+H}`);E.push({u:q,v:F,w:U,h:B})}return E}let y=(w,O,E,_,N,G)=>{let $=E+N,F=_+G;switch(w){case 0:return[[O,E,_],[O,$,_],[O,$,F],[O,E,F]];case 1:return[[O,$,_],[O,E,_],[O,E,F],[O,$,F]];case 2:return[[E,O,_],[E,O,F],[$,O,F],[$,O,_]];case 3:return[[$,O,_],[$,O,F],[E,O,F],[E,O,_]];case 4:return[[E,_,O],[$,_,O],[$,F,O],[E,F,O]];default:return[[E,F,O],[$,F,O],[$,_,O],[E,_,O]]}},P=[];for(let[w,O]of C){let E=w.indexOf(":"),_=w.indexOf(":",E+1),N=+w.slice(0,E),G=+w.slice(E+1,_),$=w.slice(_+1);for(let{u:F,v:q,w:j,h:U}of M(O))P.push({vertices:y(N,G,F,q,j,U),color:$})}if(P.length===0)return en(r,[]);let S=1/0,h=1/0,b=1/0,A=-1/0,I=-1/0,R=-1/0;for(let w of P)for(let O of w.vertices)O[0]<S&&(S=O[0]),O[0]>A&&(A=O[0]),O[1]<h&&(h=O[1]),O[1]>I&&(I=O[1]),O[2]<b&&(b=O[2]),O[2]>R&&(R=O[2]);let k=Math.max(A-S,I-h,R-b),T=k>0?o/k:1,z=w=>Math.round(w*1e3)/1e3,D=w=>[z((w[0]-S)*T+t),z((w[1]-h)*T+t),z((w[2]-b)*T+t)],L=P.map(({vertices:w,color:O})=>({vertices:w.map(D),color:O}));return{polygons:L,objectUrls:[],dispose:()=>{},warnings:[],metadata:{triangleCount:L.length,sourceBytes:r,voxelCount:p.length}}}function is(e,n){return String.fromCharCode(e.getUint8(n))+String.fromCharCode(e.getUint8(n+1))+String.fromCharCode(e.getUint8(n+2))+String.fromCharCode(e.getUint8(n+3))}function en(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var He="loadMesh";function vo(e,n){let o=at(e.polygons,{meshResolution:n?.meshResolution});return o.length===e.polygons.length?e:{...e,polygons:o}}async function ls(e,n){let o=n?.solidTextureSamples;return o===!1?e:Vt(e,typeof o=="object"?o:void 0)}function Va(e){let n=e.split("?")[0].split("#")[0],o=n.lastIndexOf(".");return o<0?"":n.slice(o+1).toLowerCase()}async function us(e,n){let o=Va(e);if(o==="mtl")throw new Error(`${He}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let t=globalThis.fetch;if(!t)throw new Error(`${He}: no fetch() in this environment`);let r=n?.baseUrl??e;if(o==="obj"){let c=await t(e);if(!c.ok)throw new Error(`${He}: ${e} \u2192 ${c.status}`);let a=await c.text(),s=n?.objOptions;if(n?.mtlUrl){let l=await t(n.mtlUrl);if(!l.ok)throw new Error(`${He}: ${n.mtlUrl} \u2192 ${l.status}`);let u=await l.text(),{colors:m,textures:d}=ht(u),f={},p=globalThis.URL,g=globalThis.document?.baseURI,x=n.mtlUrl;if(p&&g)try{x=new p(n.mtlUrl,g).toString()}catch{}for(let[V,C]of Object.entries(d)){if(p)try{f[V]=new p(C,x).toString();continue}catch{}let v=n.mtlUrl.lastIndexOf("/"),M=v>=0?n.mtlUrl.slice(0,v+1):"";f[V]=C.startsWith("/")||/^https?:\/\//.test(C)?C:M+C}s={...s??{},materialColors:{...m,...s?.materialColors??{}},materialTextures:{...f,...s?.materialTextures??{}}}}let i=yt(a,s);return vo(await ls(i,n),n)}if(o==="glb"||o==="gltf"){let c=await t(e);if(!c.ok)throw new Error(`${He}: ${e} \u2192 ${c.status}`);let a=await c.arrayBuffer(),s=Mt(a,{baseUrl:r,...n?.gltfOptions??{}});return vo(await ls(s,n),n)}if(o==="vox"){let c=await t(e);if(!c.ok)throw new Error(`${He}: ${e} \u2192 ${c.status}`);let a=await c.arrayBuffer();return vo(vt(a,n?.voxOptions),n)}throw new Error(`${He}: unsupported extension ".${o}" (supported: obj, glb, gltf, vox)`)}function fs(e,n,o,t,r=.5,c=.5,a=.4){let s=4/(e[2]+3),i=Math.min(n,o)*a,l=n*r+e[0]*i*t*s,u=o*c-e[1]*i*s;return[l,u,e[2]]}function va(e){let[n,o,t]=[e.vertices[0],e.vertices[1],e.vertices[2]],r=o[0]-n[0],c=o[1]-n[1],a=o[2]-n[2],s=t[0]-n[0],i=t[1]-n[1],l=t[2]-n[2];return[c*l-a*i,a*s-r*l,r*i-c*s]}function Ca(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 ms(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 Aa(e,n=0){if(n<=0){let a=new Set,s=[];for(let i of e){let l=[[0,1],[1,2],[2,0]];for(let[u,m]of l){let d=i.vertices[u],f=i.vertices[m],p=ms(d,f);if(a.has(p))continue;a.add(p);let g={from:d,to:f,weight:2};i.color&&(g.color=i.color),s.push(g)}}return s}let o=Math.cos(n*Math.PI/180),t=new Map,r=[[0,1],[1,2],[2,0]];for(let a of e){let s=va(a);for(let[i,l]of r){let u=a.vertices[i],m=a.vertices[l],d=ms(u,m),f=t.get(d);f?f.normals.push(s):t.set(d,{normals:[s],from:u,to:m,color:a.color})}}let c=[];for(let{normals:a,from:s,to:i,color:l}of t.values()){if(a.length<2){let m={from:s,to:i,weight:2};l&&(m.color=l),c.push(m);continue}let u=!1;e:for(let m=0;m<a.length;m++)for(let d=m+1;d<a.length;d++)if(Ca(a[m],a[d])<o){u=!0;break e}if(u){let m={from:s,to:i,weight:2};l&&(m.color=l),c.push(m)}}return c}function ds(e,n=0){return Aa(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,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,parseVox,pentagonalHexecontahedronPolygons,pentagonalIcositetrahedronPolygons,pentakisDodecahedronPolygons,planePolygons,polygonCssSurfaceNormal,polygonFaces,polygonFacesCamera,prismPolygons,project,pyramidPolygons,quatFromAxisAngle,quatFromEulerXYZ,quatMultiply,resolveGeometry,rhombicDodecahedronPolygons,rhombicTriacontahedronPolygons,rhombicosidodecahedronPolygons,rhombicuboctahedronPolygons,ringPolygons,ringQuadPolygons,rotateVec3,shadeColor,smallStellatedDodecahedronPolygons,snubCubePolygons,snubDodecahedronPolygons,spherePolygons,tetrahedronPolygons,tetrakisHexahedronPolygons,torusPolygons,trapezohedronPolygons,triakisIcosahedronPolygons,triakisOctahedronPolygons,triakisTetrahedronPolygons,trianglesToFeatureEdges,truncatedCubePolygons,truncatedCuboctahedronPolygons,truncatedDodecahedronPolygons,truncatedIcosahedronPolygons,truncatedIcosidodecahedronPolygons,truncatedOctahedronPolygons,truncatedTetrahedronPolygons});
|
|
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});
|