@layoutit/polycss-core 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -5
- package/dist/camera-VU-yix11.d.cts +304 -0
- package/dist/camera-VU-yix11.d.ts +304 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -304
- package/dist/index.d.ts +4 -304
- package/dist/index.js +1 -1
- package/dist/three.cjs +1 -0
- package/dist/three.d.cts +108 -0
- package/dist/three.d.ts +108 -0
- package/dist/three.js +1 -0
- package/package.json +13 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var Fi=Object.defineProperty;var Cm=Object.getOwnPropertyDescriptor;var Tm=Object.getOwnPropertyNames;var Em=Object.prototype.hasOwnProperty;var vm=(e,n)=>{for(var t in n)Fi(e,t,{get:n[t],enumerable:!0})},Im=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Tm(n))!Em.call(e,r)&&r!==t&&Fi(e,r,{get:()=>n[r],enumerable:!(o=Cm(n,r))||o.enumerable});return e};var _m=e=>Im(Fi({},"__esModule",{value:!0}),e);var db={};vm(db,{ASYNC_RENDER_BUDGET_MS:()=>Ru,ATLAS_CANONICAL_SIZE_AUTO_DESKTOP:()=>Br,ATLAS_CANONICAL_SIZE_EXPLICIT:()=>nn,ATLAS_MAX_SIZE:()=>On,ATLAS_PADDING:()=>lo,AUTO_ATLAS_LOW_AREA:()=>uo,AUTO_ATLAS_MAX_BITMAP_SIDE:()=>Tt,AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP:()=>Ir,AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE:()=>vr,AUTO_ATLAS_MEDIUM_AREA:()=>Er,AUTO_ATLAS_SCALE_GUARD:()=>_r,BAKED_SHADOW_MIN_UP:()=>gu,BAKED_SHADOW_Z_SQUASH:()=>pu,BASE_TILE:()=>He,BASIS_EPS:()=>de,BORDER_SHAPE_BLEED:()=>kr,BORDER_SHAPE_CANONICAL_SIZE:()=>Pn,BORDER_SHAPE_CENTER_PERCENT:()=>po,BORDER_SHAPE_POINT_EPS:()=>go,CAMERA_BACKFACE_CULL_EPS:()=>ao,COLOR_PARSE_CACHE_MAX:()=>Vr,CORNER_SHAPE_DUPLICATE_EPS:()=>ho,CORNER_SHAPE_POINT_EPS:()=>tn,DECIMAL_SCALES:()=>Nr,DEFAULT_AMBIENT_COLOR:()=>tt,DEFAULT_AMBIENT_INTENSITY:()=>ot,DEFAULT_ATLAS_CSS_DECIMALS:()=>mo,DEFAULT_BORDER_SHAPE_DECIMALS:()=>wr,DEFAULT_CAMERA_STATE:()=>_e,DEFAULT_LIGHT_COLOR:()=>et,DEFAULT_LIGHT_DIR:()=>Jn,DEFAULT_LIGHT_INTENSITY:()=>nt,DEFAULT_MATRIX_DECIMALS:()=>bn,DEFAULT_PROJECTION:()=>hc,DEFAULT_SEAM_BLEED:()=>Fu,DEFAULT_SEAM_FACET_SPLIT_OPTIONS:()=>as,DEFAULT_SEAM_OVERLAP_OPTIONS:()=>ss,DEFAULT_TILE:()=>un,LoopOnce:()=>Sa,LoopPingPong:()=>Aa,LoopRepeat:()=>Hr,MAX_ATLAS_SCALE:()=>Tr,MIN_ATLAS_SCALE:()=>Cr,PROJECTIVE_QUAD_BLEED:()=>Gr,PROJECTIVE_QUAD_DENOM_EPS:()=>zr,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO:()=>Ur,QUAT_IDENTITY:()=>Rc,RECEIVER_NORMAL_TOL:()=>ha,RECEIVER_OFFSET_TOL:()=>ya,RECEIVER_OUTLINE_EXPAND:()=>ga,RECT_EPS:()=>Ae,SEAM_LIGHT_EPS:()=>fo,SOLID_QUAD_CANONICAL_SIZE:()=>xn,SOLID_TRIANGLE_BLEED:()=>Lr,SOLID_TRIANGLE_CANONICAL_SIZE:()=>Dr,SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE:()=>Fr,SURFACE_DISTANCE_EPS:()=>Rr,SURFACE_NORMAL_EPS:()=>Or,TEXTURE_EDGE_REPAIR_ALPHA_MIN:()=>wu,TEXTURE_EDGE_REPAIR_RADIUS:()=>Du,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN:()=>Nu,TEXTURE_TRIANGLE_BLEED:()=>Lu,VOXEL_CAMERA_CULL_AXIS_EPS:()=>zs,VOXEL_CAMERA_CULL_NORMAL_LIMIT:()=>Us,applyPackedAtlasCanonicalSize:()=>Sm,applyPackedAtlasLeafSizing:()=>wo,arrowPolygons:()=>Zs,atlasArea:()=>Di,atlasBitmapMaxSide:()=>rc,atlasCanonicalSizeForEntry:()=>uc,atlasCanonicalSizeForTextureQuality:()=>cc,atlasDecodedBytes:()=>ic,atlasPadding:()=>fc,autoAtlasBudgetFactor:()=>sc,autoAtlasMaxDecodedBytes:()=>ac,autoAtlasScale:()=>oc,autoAtlasScaleCap:()=>tc,axesHelperPolygons:()=>Ws,bakeSolidTextureSampledPolygons:()=>Rf,bakeSolidTextureSamples:()=>ni,basisAxisKey:()=>Ka,borderShapeBoundsFromPoints:()=>ka,borderShapeGeometryForPlan:()=>Nt,boxPolygons:()=>Ks,buildBakedShadowProjectionMatrix:()=>hu,buildBasisHints:()=>gm,buildEdgeOwners:()=>jr,buildParametricCasterOverride:()=>Au,buildPolyCameraSceneTransform:()=>zc,buildPolyMeshTransform:()=>Vu,buildPolySceneTransform:()=>Ou,buildSceneContext:()=>Ic,buildSeamBleedPolygonEdges:()=>Fa,buildSeamBleedPolygonSet:()=>sm,buildSharedEdgeMap:()=>Yu,buildTextureEdgeRepairSets:()=>im,cachedParsePureColor:()=>rt,cameraCullNormalGroups:()=>Xs,cameraCullNormalGroupsFromPolygons:()=>lu,cameraCullNormalKey:()=>$s,cameraCullVisibleSignature:()=>fu,cameraFacingDepth:()=>Gs,capturePolyCameraSnapshot:()=>Uc,chooseIslandXAxis:()=>qa,chooseLocalBasis:()=>Ei,clampChannel:()=>Nn,classifyFacing:()=>Wr,clipPolygonToConvex2D:()=>Vn,colorErrorScore:()=>$u,compatibleBleedSurface:()=>vi,compatibleSurface:()=>Wa,computeCoverageShadowSilhouette:()=>xr,computeLightVisibility:()=>au,computeMergedReceiverShadows:()=>Ku,computeParametricShadowSilhouette:()=>br,computePlanSeamBleedEdgeAmounts:()=>yi,computeProjectiveQuadCoefficients:()=>Ai,computeProjectiveQuadMatrix:()=>Ro,computeReceiverShadowFaces:()=>Pa,computeSceneBbox:()=>Ui,computeSeamBleedInsets:()=>xi,computeShapeLighting:()=>Sc,computeSolidTriangleColorPlan:()=>Pm,computeSolidTriangleColorPlanFromNormal:()=>wi,computeSolidTrianglePlan:()=>Mm,computeSolidTrianglePlanFromCssPoints:()=>Ni,computeSurfaceNormal:()=>zn,computeTextureAtlasPlan:()=>ec,computeTextureAtlasPlanPublic:()=>hm,computeTexturePaintMetrics:()=>Vc,computeUvAffine:()=>Ii,computeUvSampleRect:()=>_i,conePolygons:()=>ia,convexHull2D:()=>yr,cornerShapeDiagonal:()=>$a,cornerShapeGeometryForPlan:()=>Pi,cornerShapePointSides:()=>Ua,coverPlanarPolygons:()=>Zo,createIsometricCamera:()=>Gc,createPolyAnimationMixer:()=>Zu,crossVec:()=>dm,cssBorderShapeForGeometry:()=>Mi,cssBorderShapeForPlan:()=>am,cssDistanceToWorld:()=>fa,cssPoints:()=>dn,cssPositionToWorld:()=>ma,cullInteriorPolygons:()=>hn,cylinderPolygons:()=>co,dedupeOverlappingPolygons:()=>qc,dodecahedronPolygons:()=>ra,dominantCountKey:()=>Li,dotVec:()=>Lo,ensureCcw2D:()=>yn,eulerXYZFromQuat:()=>Dc,evaluateIslandAxis:()=>Za,expandClipPoints:()=>st,expandConvexHullOutward:()=>pa,extractSilhouetteLoops:()=>Mo,filterAtlasPlans:()=>bm,findOverlappingPolygonDuplicates:()=>jt,formatAffineMatrix3dColumns:()=>qf,formatAffineMatrix3dScalars:()=>ui,formatAffineMatrix3dTransformScalars:()=>fi,formatAtlasMatrix:()=>Rt,formatBorderShapeElementStyle:()=>lm,formatBorderShapeEntryMatrix:()=>cm,formatBorderShapeMatrix:()=>Qf,formatColor:()=>$t,formatCornerShapeElementStyle:()=>um,formatCssLength:()=>Zf,formatCssLengthPx:()=>em,formatMatrix3d:()=>Jf,formatMatrix3dValues:()=>mn,formatPercent:()=>Ln,formatScaledMatrixFromPlan:()=>Ot,formatSolidQuadEntryMatrix:()=>nm,formatSolidQuadMatrix:()=>Da,fullRectBounds:()=>nc,getPolygonBasisInfo:()=>ja,getSolidPaintDefaultsForPlansCore:()=>xm,groupReceiverFaceGroups:()=>Ar,icosahedronPolygons:()=>oa,incrementCount:()=>Ri,intersect2DLines:()=>di,intersect2DLinesRaw:()=>tm,inverseRotateVec3:()=>Oc,isAxisAlignedSurfaceNormal:()=>Ys,isBakedShadowCaster:()=>xu,isBasisOptimizable:()=>Ya,isConvexCaster:()=>la,isConvexPolygonPoints:()=>Lt,isFlatCaster:()=>ca,isFullRectBasis:()=>Qa,isFullRectSolid:()=>Un,isPointShadowCaster:()=>bu,isProjectiveQuadPlan:()=>Dt,isSolidTrianglePlan:()=>ct,isVoxelCameraCullableNormalGroups:()=>uu,loadMesh:()=>Kf,makeLocalBasis:()=>lt,mergePolygons:()=>sn,meshScaleVec3:()=>Sr,normalFacesCamera:()=>At,normalizeAtlasScale:()=>ut,normalizeInvertMultiplier:()=>kc,normalizePolygons:()=>Xo,normalizedSeamBleed:()=>hi,octahedronPolygons:()=>ea,offsetConvexPolygonPoints:()=>at,offsetConvexPolygonPointsByEdgeAmounts:()=>wt,offsetStableTrianglePoints:()=>pi,offsetTrianglePoints:()=>To,optimizeAnimatedMeshPolygons:()=>wf,optimizeMeshParseResult:()=>Qn,optimizeMeshPolygons:()=>zl,packTextureAtlasPlans:()=>Ft,packTextureAtlasPlansWithScaleCore:()=>Am,parseAlpha:()=>bo,parseColor:()=>Xn,parseGltf:()=>Jr,parseHex:()=>fn,parseHexColor:()=>gt,parseMtl:()=>oi,parseObj:()=>ti,parsePureColor:()=>Tn,parseRgbColor:()=>Bi,parseStl:()=>li,parseVox:()=>ri,planePolygons:()=>Js,polyCameraTargetToCss:()=>$i,polyCssDistanceToWorld:()=>Tu,polyCssPositionToWorld:()=>vu,polygonContainsPoint:()=>Ba,polygonCssSurfaceNormal:()=>pr,polygonFaces:()=>_c,polygonFacesCamera:()=>cu,polygonSignedArea2D:()=>aa,prepareCasterEdgeOwners:()=>ju,prepareCasterPolyItems:()=>Wu,prepareReceiverFacePlanes:()=>Hu,projectCssVertexToGround:()=>Pu,projectCssVertexToGroundFromPoint:()=>yu,projectTextureTriangle:()=>Ja,quantizeCssColor:()=>Yr,quatFromAxisAngle:()=>wc,quatFromEulerXYZ:()=>Nc,quatMultiply:()=>Lc,repairMeshSeams:()=>Tl,resolveAtlasLeafBox:()=>lc,resolveBleedRatio:()=>$r,resolvePolyCameraAppliedPerspectiveStyle:()=>Xi,resolvePolyTextureImageRendering:()=>fm,resolvePolyTextureImageSource:()=>_o,resolvePolyTextureLeafGeometry:()=>Oi,resolvePolyTexturePresentation:()=>Vo,resolvePolyTextureUrl:()=>Si,resolveProjectiveQuadGuards:()=>Oo,resolveSeamBleed:()=>vo,rgbEqual:()=>zu,rgbKey:()=>Xr,rgbToCss:()=>Gu,rgbToHex:()=>xo,ringPolygons:()=>qs,ringQuadPolygons:()=>Qs,rotateVec3:()=>Yo,rotateVec3InWrapperCssFrame:()=>Dn,roundDecimal:()=>Be,safariCssProjectiveUnsupported:()=>ym,safePlanSeamBleedAmount:()=>Io,screenToWorldOnSphere:()=>Xc,screenToWorldRay:()=>Yi,seamBleedAmountArray:()=>bi,seamFacetSplitPolygons:()=>ds,seamFacetSplitReport:()=>Cl,seamLightBrightness:()=>Ci,seamOverlapDiagnostics:()=>El,seamOverlapPolygons:()=>ps,seamOverlapReport:()=>Il,shadeColor:()=>Mc,shadePolygon:()=>Rn,sharedCornerShapeSide:()=>Ga,signedArea2D:()=>mi,simplifyCornerShapePoints:()=>za,simplifyTriangleMeshPolygons:()=>ar,spherePolygons:()=>na,stableBasisFromPlan:()=>Eo,stableTriangleMatrixDecimals:()=>gi,stepRgbToward:()=>Uu,tetrahedronPolygons:()=>ta,textureTintFactors:()=>Po,tintToCss:()=>ku,torusPolygons:()=>sa,worldCssForMesh:()=>Ct,worldDirectionToCss:()=>Mr,worldDirectionToPolyCss:()=>Iu,worldDirectionalLightToCss:()=>da,worldDirectionalLightToPolyCss:()=>_u,worldDistanceToCss:()=>ua,worldDistanceToPolyCss:()=>Cu,worldPositionToCss:()=>rn,worldPositionToPolyCss:()=>Eu});module.exports=_m(db);var hc="cubic";function gt(e){let n=e.replace("#","");if(n.length===3){let t=parseInt(n[0]+n[0],16),o=parseInt(n[1]+n[1],16),r=parseInt(n[2]+n[2],16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}if(n.length===6){let t=parseInt(n.slice(0,2),16),o=parseInt(n.slice(2,4),16),r=parseInt(n.slice(4,6),16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}return null}function Bi(e){let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/i);return n?{rgb:[Number(n[1]),Number(n[2]),Number(n[3])],alpha:n[4]?Number(n[4]):1}:null}function Tn(e){if(!e)return null;let n=e.trim(),t=gt(n);return t||Bi(n)}function Nn(e){return Math.max(0,Math.min(255,Math.round(e)))}function $t(e){let[n,t,o]=e.rgb.map(Nn);return e.alpha<1?`rgba(${n}, ${t}, ${o}, ${e.alpha})`:`rgb(${n}, ${t}, ${o})`}var zi={rgb:[204,204,204],alpha:1},yc=new Map;function Xn(e){if(!e)return null;let n=e.trim(),t=yc.get(n);if(t)return t;let o=Tn(n);return o?(yc.set(n,o),o):null}function Mc(e,n){let t=Xn(e)??zi,o=[Nn(t.rgb[0]+n),Nn(t.rgb[1]+n),Nn(t.rgb[2]+n)];return $t({rgb:o,alpha:t.alpha})}var ki={direction:[0,0,-1],color:"#ffffff",intensity:1},bc={color:"#ffffff",intensity:.4};function xc(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 Pc(e,n,t){let o=Xn(n)??zi;return e*(o.rgb[t]/255)}function Sc(e,n,t,o){let r=Xn(n)??zi,i=xc(t?.direction??ki.direction),s=t?.color??ki.color,a=Math.max(0,t?.intensity??ki.intensity),c=o?.color??bc.color,l=Math.max(0,o?.intensity??bc.intensity),u=xc(e),f=Math.max(0,-(u[0]*i[0]+u[1]*i[1]+u[2]*i[2])),d=a*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],h=Pc(g,c,p)*l,y=Pc(g,s,p)*d;m[p]=Nn(h+y)}return $t({rgb:m,alpha:r.alpha})}var Ac="#cccccc",Go=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Cc=(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]],Tc=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],$o=e=>Math.hypot(e[0],e[1],e[2]);function Vm(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>i&&(i=u[1]),u[2]<o&&(o=u[2]),u[2]>s&&(s=u[2]);let a=r-n,c=i-t,l=s-o;return Math.hypot(a,c,l)}function Om(){let e=globalThis;if(e.__POLYCSS_DEV__===!0)return!0;if(e.__POLYCSS_DEV__===!1)return!1;let n=e.process?.env?.NODE_ENV;return typeof n=="string"?n!=="production":!1}function Ec(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function vc(e){return e?{...e}:void 0}function Rm(e){if(e)return{...e,imageSource:Ec(e.imageSource),presentation:vc(e.presentation)}}function Xo(e){let n=[],t=[];if(!e||e.length===0)return{polygons:n,warnings:t};for(let o=0;o<e.length;o++){let r=e[o];if(!r||!Array.isArray(r.vertices)){t.push(`Polygon ${o}: missing vertices, dropped`);continue}let i=r.vertices;if(i.length<3){t.push(`Polygon ${o}: ${i.length} vertices (need >= 3), dropped`);continue}let s=Go(i[1],i[0]),a=Go(i[2],i[0]),c=Cc(s,a),l=$o(c);if(i.length===3){if(l<1e-12){$o(s)<1e-12||$o(a)<1e-12?t.push(`Polygon ${o}: zero-area triangle (coincident vertices), dropped`):t.push(`Polygon ${o}: vertices collinear, dropped`);continue}}else if(l<1e-12){t.push(`Polygon ${o}: first 3 vertices collinear, dropped`);continue}let u=[{...r,vertices:i.slice()}];if(i.length>=4){let f=[c[0]/l,c[1]/l,c[2]/l],d=Tc(f,i[0]),m=Vm(i),p=Math.max(1e-6,m*.001),g=0;for(let h=3;h<i.length;h++){let y=Math.abs(Tc(f,i[h])-d);y>g&&(g=y)}if(g>p){let h=[],y=r.uvs&&r.uvs.length===i.length?r.uvs:void 0;for(let b=1;b<i.length-1;b++){let x=[i[0].slice(),i[b].slice(),i[b+1].slice()],P=Cc(Go(x[1],x[0]),Go(x[2],x[0]));if($o(P)<1e-12)continue;let M={...r,vertices:x};y&&(M.uvs=[y[0].slice(),y[b].slice(),y[b+1].slice()]),h.push(M)}if(h.length===0){t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulated to ${h.length} triangles`),u=h}}for(let f of u){let d=Lm(f,o,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function Lm(e,n,t){let o={vertices:e.vertices},r=Rm(e.material),i=Ec(e.textureImageSource),s=vc(e.texturePresentation),a=r?.texture??e.texture??i?.url??r?.imageSource?.url;if(typeof a=="string"&&a===""&&(a=void 0),e.color!==void 0&&a!==void 0&&Om()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Xn(e.color)?o.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${Ac}`),o.color=Ac)),a!==void 0&&(o.texture=a,e.textureWrap&&(o.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(o.textureAlphaMode=e.textureAlphaMode)),r&&(o.material=r),i&&(o.textureImageSource=i),s&&(o.texturePresentation=s),Array.isArray(e.textureTriangles)&&e.textureTriangles.length>0&&(o.textureTriangles=e.textureTriangles.map(c=>({vertices:c.vertices.map(l=>l.slice()),uvs:c.uvs.map(l=>l.slice())}))),e.doubleSided===!0&&(o.doubleSided=!0),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?t.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):o.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let c={},l=!1;for(let u of Object.keys(e.data)){let f=e.data[u];typeof f=="string"||typeof f=="number"||typeof f=="boolean"?c[u]=f:(l=!0,t.push(`Polygon ${n}: data["${u}"] has non-primitive value, key dropped`))}Object.keys(c).length>0&&(o.data=c)}return o}function Ui(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0,a=!1;for(let c of e)if(c?.vertices)for(let l of c.vertices)l&&(a=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>i&&(i=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]));return a?{min:[n,t,o],max:[r,i,s]}:{min:[0,0,0],max:[0,0,0]}}function Ic(e){let n=e.polygons??[],t,o;if(e.skipNormalize)t=n,o=[];else{let a=Xo(n);t=a.polygons,o=a.warnings}let r=Ui(t),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]];return{context:{polygons:t,sceneBbox:r,warnings:o},dimensions:{sceneBbox:r,size:i},warnings:o}}function _c(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function wm(e){let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],i=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],s=r[1]*i[2]-r[2]*i[1],a=r[2]*i[0]-r[0]*i[2],c=r[0]*i[1]-r[1]*i[0],l=Math.hypot(s,a,c);return l<=1e-9?null:[s/l,a/l,c/l]}function Nm(e){let n=0;for(let t=0;t<e.length;t++){let[o,r]=e[t],[i,s]=e[(t+1)%e.length];n+=o*s-i*r}return Math.abs(n)/2}function Dm(e,n,t){if(!e||e.length<3)return null;let o=e.map(a=>[a[1]*n,a[0]*n,a[2]*t]),r=wm(o);if(!r)return null;let i=1/0,s=0;for(let a=0;a<o.length;a++){let c=o[a],l=o[(a+1)%o.length],u=[l[0]-c[0],l[1]-c[1],l[2]-c[2]],f=u[0]*r[0]+u[1]*r[1]+u[2]*r[2],d=[u[0]-f*r[0],u[1]-f*r[1],u[2]-f*r[2]],m=Math.hypot(d[0],d[1],d[2]);if(m<=1e-9)continue;let p=[d[0]/m,d[1]/m,d[2]/m],g=[r[1]*p[2]-r[2]*p[1],r[2]*p[0]-r[0]*p[2],r[0]*p[1]-r[1]*p[0]],h=Math.hypot(g[0],g[1],g[2]);if(h<=1e-9)continue;let y=[g[0]/h,g[1]/h,g[2]/h],b=o.map(v=>{let R=v[0]-c[0],O=v[1]-c[1],L=v[2]-c[2];return[R*p[0]+O*p[1]+L*p[2],R*y[0]+O*y[1]+L*y[2]]}),x=1/0,P=1/0,M=-1/0,C=-1/0;for(let[v,R]of b)x=Math.min(x,v),P=Math.min(P,R),M=Math.max(M,v),C=Math.max(C,R);let E=M-x,A=C-P,S=Math.max(1,Math.ceil(E))*Math.max(1,Math.ceil(A)),T=Nm(b);T<=1e-9||S<i&&(i=S,s=T)}return!Number.isFinite(i)||s<=1e-9?null:{elementArea:i,polygonArea:s}}function Vc(e,n={}){let t=n.tileSize??100,o=n.layerElevation??t,r=n.texturedOnly??!0,i=0,s=0,a=0,c=0,l=0;for(let f of e){let d=!!f.texture;if(r&&!d)continue;let m=Dm(f.vertices,t,o);m&&(i+=1,d&&(s+=1),a+=m.elementArea,c+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,a-c);return{totalPolygons:e.length,measuredPolygons:i,texturedPolygons:s,elementArea:a,polygonArea:c,transparentArea:u,transparentRatio:a>0?u/a:0,overdrawRatio:c>0?a/c:0,worstTransparentRatio:l}}function Yo(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function Oc(e,n){let t=-n[0]*Math.PI/180,o=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[i,s,a]=e;if(t!==0){let c=Math.cos(t),l=Math.sin(t);[s,a]=[s*c-a*l,s*l+a*c]}if(o!==0){let c=Math.cos(o),l=Math.sin(o);[i,a]=[i*c+a*l,-i*l+a*c]}if(r!==0){let c=Math.cos(r),l=Math.sin(r);[i,s]=[i*c-s*l,i*l+s*c]}return[i,s,a]}function Dn(e,n){let[t,o,r]=e,i=-(n[2]??0)*Math.PI/180;if(i!==0){let c=Math.cos(i),l=Math.sin(i);[t,o]=[t*c-o*l,t*l+o*c]}let s=-(n[1]??0)*Math.PI/180;if(s!==0){let c=Math.cos(s),l=Math.sin(s);[o,r]=[o*c-r*l,o*l+r*c]}let a=-(n[0]??0)*Math.PI/180;if(a!==0){let c=Math.cos(a),l=Math.sin(a);[t,r]=[t*c+r*l,-t*l+r*c]}return[t,o,r]}var Gi=Math.PI/180,Xt=180/Math.PI,Rc=[1,0,0,0];function Lc(e,n){let[t,o,r,i]=e,[s,a,c,l]=n;return[t*s-o*a-r*c-i*l,t*a+o*s+r*l-i*c,t*c-o*l+r*s+i*a,t*l+o*c-r*a+i*s]}function wc(e,n){let t=n*.5,o=Math.sin(t);return[Math.cos(t),e[0]*o,e[1]*o,e[2]*o]}function Nc(e){let n=e[0]*Gi,t=e[1]*Gi,o=e[2]*Gi,r=Math.cos(n*.5),i=Math.sin(n*.5),s=Math.cos(t*.5),a=Math.sin(t*.5),c=Math.cos(o*.5),l=Math.sin(o*.5);return[r*s*c-i*a*l,i*s*c+r*a*l,r*a*c-i*s*l,r*s*l+i*a*c]}function Dc(e){let[n,t,o,r]=e,i=2*(t*r+n*o),s=2*(o*r-n*t),a=1-2*(t*t+o*o),c=2*(t*o-n*r),l=1-2*(o*o+r*r),u=Math.max(-1,Math.min(1,i)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-s,a)*Xt,f*Xt,Math.atan2(-c,l)*Xt]:[Math.atan2(2*(o*r+n*t),1-2*(t*t+r*r))*Xt,f*Xt,0]}var He=50;function kc(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var _e={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0};function $i(e=_e.target,n=[0,0,0],t=50){let o=e[0]+n[0],r=e[1]+n[1],i=e[2]+n[2];return[r*t,o*t,i*t]}function zc(e=_e,n={}){let t=n.tileSize??50,o=n.layoutScale??1,r=e.target??_e.target,[i,s,a]=$i(r,n.autoCenterOffset,t),c=(e.zoom??_e.zoom)/t*o,l=(e.distance??_e.distance)*o,u=e.rotX??_e.rotX,f=e.rotY??_e.rotY;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${u}deg) rotate(${f}deg) translate3d(${-i}px, ${-s}px, ${-a}px)`}function Xi(e="none"){if(e==="none")return"1000000px";let n=Number.parseFloat(e);return Number.isFinite(n)?`${n}px`:e}function Uc(e,n={}){let t=n.perspectiveStyle??e.perspectiveStyle??"none",o=n.projection??e.type??(t==="none"?"orthographic":"perspective"),r=e.state??_e;return{projection:o,perspectiveStyle:t,appliedPerspectiveStyle:Xi(t),state:{target:[...r.target??_e.target],rotX:r.rotX??_e.rotX,rotY:r.rotY??_e.rotY,zoom:r.zoom??_e.zoom,distance:r.distance??_e.distance}}}var Fc=100,Bc=1e4,ht=e=>Math.round(e*Fc)/Fc,Fm=e=>Math.round(e*Bc)/Bc;function Gc(e={}){let n={target:e.target??[..._e.target],rotX:e.rotX??_e.rotX,rotY:e.rotY??_e.rotY,zoom:e.zoom??_e.zoom,distance:e.distance??_e.distance};function t(r){r.target!==void 0&&(n.target=[ht(r.target[0]),ht(r.target[1]),ht(r.target[2])]),r.rotX!==void 0&&(n.rotX=ht(r.rotX)),r.rotY!==void 0&&(n.rotY=ht(r.rotY)),r.zoom!==void 0&&(n.zoom=Fm(r.zoom)),r.distance!==void 0&&(n.distance=ht(r.distance))}function o(r={}){let s=(r.cols??0)*50,a=(r.rows??0)*50,[c,l,u]=n.target,f=l*50,d=c*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-d}px, ${-m}px)`,width:`${s}px`,height:`${a}px`}}return{state:n,update:t,getStyle:o}}var $c=Math.PI/180;function Yi(e){let{camera:n,tileSize:t,viewportCenterX:o,viewportCenterY:r,mouseX:i,mouseY:s}=e,a=n.rotX*$c,c=n.rotY*$c,l=n.zoom/t,u=n.target,f=i-o,d=s-r,m=f/l,p=d/l,g=Math.cos(a),h=Math.sin(a),y=m,b=p*g,x=-p*h,P=0,M=h,C=g,E=Math.cos(c),A=Math.sin(c),S=y*E+b*A,T=-y*A+b*E,v=x,R=P*E+M*A,O=-P*A+M*E,L=C,D=u[1]*t,_=u[0]*t,w=u[2]*t,V=S+D,j=T+_,G=v+w,Z=[j/t,V/t,G/t],ee=[O/t,R/t,L/t];return{origin:Z,direction:ee}}function Xc(e){let{origin:n,direction:t}=Yi(e),{sphereCenter:o,sphereRadius:r}=e,i=n[0]-o[0],s=n[1]-o[1],a=n[2]-o[2],c=t[0],l=t[1],u=t[2],f=c*c+l*l+u*u;if(f===0)return null;let d=2*(i*c+s*l+a*u),m=i*i+s*s+a*a-r*r,p=d*d-4*f*m;if(p>=0){let E=Math.sqrt(p),A=(-d-E)/(2*f),S=(-d+E)/(2*f),T=t[2]>=0?Math.max(A,S):Math.min(A,S);return[n[0]+T*t[0],n[1]+T*t[1],n[2]+T*t[2]]}let g=-(i*c+s*l+a*u)/f,h=n[0]+g*c,y=n[1]+g*l,b=n[2]+g*u,x=h-o[0],P=y-o[1],M=b-o[2],C=Math.hypot(x,P,M);return C===0?null:[o[0]+x/C*r,o[1]+P/C*r,o[2]+M/C*r]}var Fn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],jo=(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]],Yt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Hi=e=>Math.hypot(e[0],e[1],e[2]),yt=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function Bm(e){return`${e[0]},${e[1]},${e[2]}`}function Wc(e){if(e.length<3)return null;let n=Fn(e[1],e[0]),t=Fn(e[2],e[0]),o=jo(n,t),r=Hi(o);if(r<1e-12)return null;let i=[o[0]/r,o[1]/r,o[2]/r],s=Yt(i,e[0]);return{normal:i,d:s}}function km(e,n){return Yt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function zm(e,n){return Yt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function Um(e,n,t,o){let r=e.vertices.findIndex(A=>yt(A,t)),i=e.vertices.findIndex(A=>yt(A,o)),s=n.vertices.findIndex(A=>yt(A,t)),a=n.vertices.findIndex(A=>yt(A,o));if(r<0||i<0||s<0||a<0)return null;let c=e.vertices.length,l=n.vertices.length,u=(r+1)%c===i,f=(s+1)%l===a;if(u===f)return null;let d=u?i:r,m=u?r:i,p=f?a:s,g=f?s:a,h=!!(e.uvs&&n.uvs),y=[],b=h?[]:void 0,x=d;for(;y.push(e.vertices[x]),b&&b.push(e.uvs[x]),x!==m;)x=(x+1)%c;for(x=p;y.push(n.vertices[x]),b&&b.push(n.uvs[x]),x!==g;)x=(x+1)%l;let P=[],M=b?[]:void 0;for(let A=0;A<y.length;A++)(P.length===0||!yt(y[A],P[P.length-1]))&&(P.push(y[A]),M&&b&&M.push(b[A]));if(P.length>1&&yt(P[0],P[P.length-1])&&(P.pop(),M?.pop()),h)return jc(P,M);let C=[],E=M?[]:void 0;for(let A=0;A<P.length;A++){let S=P[(A-1+P.length)%P.length],T=P[A],v=P[(A+1)%P.length],R=jo(Fn(T,S),Fn(v,S));Hi(R)>1e-9&&(C.push(T),E&&M&&E.push(M[A]))}return C.length<3?null:jc(C,E)}function Gm(e,n){let t=e.length,o=0;for(let r=0;r<t;r++){let i=e[r],s=e[(r+1)%t],a=e[(r+2)%t],c=Fn(s,i),l=Fn(a,s),u=Yt(jo(c,l),n);if(Math.abs(u)<1e-9)continue;let f=u>0?1:-1;if(o===0)o=f;else if(f!==o)return!1}return!0}function $m(e,n){if(e.length<3)return!1;let t=Wc(e);if(!t)return!1;for(let o of e)if(Math.abs(Yt(t.normal,o)-t.d)>n)return!1;return!0}function Xm(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function ji(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function Wi(e){return e?{...e}:void 0}function Yc(e){if(e)return{...e,imageSource:ji(e.imageSource),presentation:Wi(e.presentation)}}function Ym(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function jm(e,n){return(e??"")===(n??"")}function Wm(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function jc(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length];if(!(Hi(jo(Fn(r,o),Fn(i,o)))<=1e-9))return t===0?{vertices:e,uvs:n}:{vertices:[...e.slice(t),...e.slice(0,t)],uvs:n?[...n.slice(t),...n.slice(0,t)]:void 0}}return{vertices:e,uvs:n}}function sn(e){let n=[],t=[],o=new WeakMap,r=m=>{let p=o.get(m);if(p)return p;let g=Bm(m);return o.set(m,g),g},i=(m,p)=>{let g=r(m),h=r(p);return g<h?`${g}|${h}`:`${h}|${g}`},s=(m,p)=>r(m)<r(p)?1:-1,a=m=>{let p=new Map;for(let g=0;g<m.length;g++){let h=m[g],y=m[(g+1)%m.length];p.set(i(h,y),s(h,y))}return p},c=0,l=!1,u=m=>(c+=m,c<=8e6?!0:(l=!0,!1));for(let m of e??[]){if(!m||!m.vertices||m.vertices.length<3){m&&n.push(m);continue}let p=m.vertices,g=Wc(p);if(!g){n.push(m);continue}let h=m.texture&&m.uvs&&m.uvs.length===p.length?m.uvs.map(b=>[b[0],b[1]]):void 0,y=m.texture&&h?m.textureTriangles?.length?Xm(m.textureTriangles):Wm(p,h):void 0;t.push({vertices:p,uvs:h,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureImageSource:ji(m.textureImageSource),texturePresentation:Wi(m.texturePresentation),material:Yc(m.material),textureTriangles:y,normal:g.normal,d:g.d,edgeDirections:a(p),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let h=0;h<t.length;h++){let y=t[h];if(!y.alive)continue;let b=y.vertices.length;if(!u(b))return!1;for(let x=0;x<b;x++){let P=y.vertices[x],M=y.vertices[(x+1)%b],C=i(P,M),E=m.get(C);E?E.second<0&&(E.second=h):(E={a:P,b:M,first:h,second:-1},m.set(C,E))}}let p=!1,g=(h,y,b)=>{let x=h.edgeDirections.get(i(y,b));return x?x===s(y,b)?1:-1:0};for(let h of m.values()){if(h.second<0)continue;let y=h.first,b=h.second;if(y===b)continue;let x=t[y],P=t[b];if(!x.alive||!P.alive||x.color!==P.color||x.texture!==P.texture||!Ym(x.textureWrap,P.textureWrap)||!jm(x.textureAlphaMode,P.textureAlphaMode)||x.doubleSided!==P.doubleSided)continue;let M=!!(x.texture||P.texture);if(M&&(!x.textureTriangles||!P.textureTriangles)||!!x.uvs!=!!P.uvs||(M?!zm(x,P):!km(x,P)))continue;if(!u(x.vertices.length+P.vertices.length))return!1;let C=g(x,h.a,h.b);if(C===0)continue;let E=g(P,h.a,h.b);if(E===0||C===E)continue;let[A,S]=C===1?[h.a,h.b]:[h.b,h.a],T=Um(x,P,A,S);if(T){if(!u(T.vertices.length))return!1;T.vertices.length>96||$m(T.vertices,.001)&&Gm(T.vertices,x.normal)&&(x.vertices=T.vertices,x.uvs=T.uvs,x.edgeDirections=a(T.vertices),x.textureTriangles=M?[...x.textureTriangles??[],...P.textureTriangles??[]]:void 0,P.alive=!1,p=!0)}}return p},d=0;for(;!l&&d<16&&f();)d++;for(let m of t){if(!m.alive)continue;let p={vertices:m.vertices.map(g=>[g[0],g[1],g[2]]),color:m.color};m.texture&&(p.texture=m.texture),m.texture&&m.textureWrap&&(p.textureWrap={...m.textureWrap}),m.texture&&m.textureAlphaMode&&(p.textureAlphaMode=m.textureAlphaMode),m.textureImageSource&&(p.textureImageSource=ji(m.textureImageSource)),m.texturePresentation&&(p.texturePresentation=Wi(m.texturePresentation)),m.material&&(p.material=Yc(m.material)),m.uvs&&(p.uvs=m.uvs.map(g=>[g[0],g[1]])),m.textureTriangles?.length&&(p.textureTriangles=m.textureTriangles),m.doubleSided&&(p.doubleSided=!0),m.data&&(p.data=m.data),n.push(p)}return n}var Hm=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Km=(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]],an=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function Zm(e,n){let t=e.vertices;if(!t||t.length<3)return null;let o=0,r=0,i=0;for(let g=0;g<t.length;g++){let h=t[g],y=t[(g+1)%t.length];o+=(h[1]-y[1])*(h[2]+y[2]),r+=(h[2]-y[2])*(h[0]+y[0]),i+=(h[0]-y[0])*(h[1]+y[1])}let s=Math.hypot(o,r,i);if(s<1e-12)return null;let a=[o/s,r/s,i/s],c=0,l=0,u=0;for(let g of t)c+=g[0],l+=g[1],u+=g[2];let f=1/t.length,d=[c*f,l*f,u*f],m=an(a,d),p=s*.5;return{index:n,polygon:e,normal:a,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function qm(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&an(e.normal,n.normal)<0}function Qm(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*an(n,e),o=n[1]-e[1]*an(n,e),r=n[2]-e[2]*an(n,e),i=Math.hypot(t,o,r);t/=i,o/=i,r/=i;let s=[t,o,r],a=Km(e,s);return{u:s,v:a}}function Jm(e){if(e.local2D)return;let n=Qm(e.normal),t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.polygon.vertices){let c=an(a,n.u),l=an(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}e.local2D=t,e.bbox2D={min:[o,r],max:[i,s]},e.basis=n}function ed(e,n){let t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.vertices){let c=an(a,n.u),l=an(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}return{local2D:t,bbox2D:{min:[o,r],max:[i,s]}}}function nd(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 Hc(e,n){let t=!1;for(let o=0,r=n.length-1;o<n.length;r=o++){let i=n[o],s=n[r];i[1]>e[1]!=s[1]>e[1]&&e[0]<(s[0]-i[0])*(e[1]-i[1])/(s[1]-i[1]+1e-30)+i[0]&&(t=!t)}return t}function Kc(e){let n=0,t=0;for(let o of e)n+=o[0],t+=o[1];return[n/e.length,t/e.length]}function td(e,n){let t=Kc(e),o=Kc(n),r=1e-4,i=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];Hc(u,n)&&i++}let s=0;for(let l of n){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];Hc(u,e)&&s++}let a=i/e.length,c=s/n.length;return Math.max(a,c)}function od(e,n){let t=e.normal[0],o=e.normal[1],r=e.normal[2],i=Math.abs(t),s=Math.abs(o),a=Math.abs(r),c=t;s>i&&s>a?c=o:a>i&&a>s&&(c=r),c<0&&(t=-t,o=-o,r=-r);let l=Math.round(t/.05),u=Math.round(o/.05),f=Math.round(r/.05),d=e.d*(e.normal[0]===t&&e.normal[1]===o&&e.normal[2]===r?1:-1),m=Math.round(d/(n*2));return`${l},${u},${f}|${m}`}function rd(e,n,t,o){let r=an(e.normal,n.normal);if(Math.abs(r)<1-t)return!1;let i=r>0?1:-1;return Math.abs(e.d-i*n.d)<o}function Zc(e,n){let t=Hm(n,e.centroid);return an(e.normal,t)>0}function jt(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,o=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,i=n?.preserveDoubleSidedBackfaces??!0,s=[];for(let p=0;p<e.length;p++){let g=Zm(e[p],p);g&&s.push(g)}if(s.length<2)return new Set;let a=0,c=0,l=0,u=0;for(let p of s)a+=p.centroid[0]*p.area,c+=p.centroid[1]*p.area,l+=p.centroid[2]*p.area,u+=p.area;let f=u>0?[a/u,c/u,l/u]:[0,0,0],d=new Map;for(let p of s){let g=od(p,o),h=d.get(g);h||(h=[],d.set(g,h)),h.push(p)}let m=new Set;for(let p of d.values())if(!(p.length<2))for(let g=0;g<p.length;g++){let h=p[g];if(!m.has(h.index))for(let y=g+1;y<p.length;y++){let b=p[y];if(m.has(b.index)||!rd(h,b,t,o)||i&&qm(h,b))continue;Jm(h);let x=ed(b.polygon,h.basis);if(!nd(h.bbox2D,x.bbox2D)||td(h.local2D,x.local2D)<r)continue;let M=Zc(h,f),C=Zc(b,f),E;if(M&&!C?E=h:C&&!M?E=b:E=h.area<b.area?h:b,m.add(E.index),E===h)break}}return m}function qc(e,n){if(!e||e.length<2)return e??[];let t=jt(e,n);if(t.size===0)return e;let o=[];for(let r=0;r<e.length;r++)t.has(r)||o.push(e[r]);return o}var id=4,sd=8,ad=.001,cd=1e-9,ld=1e6,ud=1e6,fd=8,Yn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],qi=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Kt=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],jn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],nl=(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]],tl=e=>Math.hypot(e[0],e[1],e[2]);function Zt(e){let n=tl(e);return n<=cd?null:[e[0]/n,e[1]/n,e[2]/n]}function Ht(e,n){return Math.round(e*n)/n}function cn(e){return Ht(e,ld)}function Ki(e){return Ht(e,ud)}function Zi(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function En(e){return`${cn(e[0])},${cn(e[1])}`}function md(e){let n=En(e.a),t=En(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function bt(e){return`${e[0]},${e[1]},${e[2]}`}function ol(e,n){let t=bt(e),o=bt(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Qi(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Qc(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",Qi(e.data)].join("|")}function rl(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],o=[0,0,0];for(let i=1;i<n.length-1;i++)o=qi(o,nl(Yn(n[i],t),Yn(n[i+1],t)));let r=Zt(o);return r?{normal:r,d:jn(r,t)}:null}function dd(e,n,t){return jn(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function pd(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function gd(e,n){let t=n[e[0]]?.data,o=Qi(t);for(let r of e)if(Qi(n[r].data)!==o)return;return t?{...t}:void 0}function hd(e,n){return e.every(t=>n[t].doubleSided===!0)}function yd(e,n){let t=e.map(c=>pd(c)?rl(c):null),o=t.map(Boolean),r=new Map;for(let c=0;c<e.length;c++){if(!t[c])continue;let l=e[c].vertices;for(let u=0;u<l.length;u++){let f=ol(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:c,edge:u};d?d.push(m):r.set(f,[m])}}let i=e.map(()=>new Set);for(let c of r.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l].polygon,d=c[u].polygon,m=t[f],p=t[d];!m||!p||Qc(e[f])===Qc(e[d])&&dd(m,p,n)&&(i[f].add(d),i[d].add(f))}let s=new Set,a=[];for(let c=0;c<e.length;c++){if(!o[c]||s.has(c))continue;let l=[],u=[c];for(s.add(c);u.length>0;){let f=u.shift();l.push(f);for(let d of i[f])s.has(d)||(s.add(d),u.push(d))}a.push(l)}return{groups:a}}function bd(e,n){let t=new Set(e),o=new Map;for(let i of e){let s=n[i].vertices;for(let a=0;a<s.length;a++){let c=ol(s[a],s[(a+1)%s.length]),l=o.get(c),u={polygon:i,edge:a};l?l.push(u):o.set(c,[u])}}let r=[];for(let i of o.values()){let s=i.filter(a=>t.has(a.polygon));if(s.length===1){let a=s[0],c=n[a.polygon].vertices;r.push({a:c[a.edge],b:c[(a.edge+1)%c.length]})}else if(s.length!==2)return null}return r}function xd(e){let n=new Map;for(let t of e)n.set(bt(t.a),(n.get(bt(t.a))??0)+1),n.set(bt(t.b),(n.get(bt(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function il(e){let n=[e[0],e[1],e[2]],t=Math.abs(n[0])>=Math.abs(n[1])&&Math.abs(n[0])>=Math.abs(n[2])?0:Math.abs(n[1])>=Math.abs(n[2])?1:2;return n[t]<0?[-n[0],-n[1],-n[2]]:n}function Pd(e){let n=il(e);return`${Ht(n[0],1e3)},${Ht(n[1],1e3)},${Ht(n[2],1e3)}`}function Md(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=Yn(n,Kt(e,jn(n,e)));return Zt(t)??[1,0,0]}function Sd(e,n,t){let o=new Map;for(let i of e){let s=Yn(i.b,i.a),a=Yn(s,Kt(n,jn(s,n))),c=Zt(a);if(!c)continue;let l=il(c),u=Pd(l),f=tl(a),d=o.get(u);d?d.weight+=f:o.set(u,{axis:l,weight:f})}let r=[...o.values()].sort((i,s)=>s.weight-i.weight).slice(0,t).map(i=>i.axis);return r.length===0&&r.push(Md(n)),r}function Jc(e,n,t,o){let r=Yn(e,n);return[cn(jn(r,t)),cn(jn(r,o))]}function Ad(e){let n=[...e].sort((o,r)=>o-r),t=[];for(let o of n)(t.length===0||Math.abs(o-t[t.length-1])>1e-7)&&t.push(o);return t}function Wt(e,n){let[t,o]=e.a,[r,i]=e.b,s=(n-t)/(r-t);return cn(o+(i-o)*s)}function Ji(e){let n=[];for(let o of e)(n.length===0||Math.abs(o[0]-n[n.length-1][0])>1e-7||Math.abs(o[1]-n[n.length-1][1])>1e-7)&&n.push(o);n.length>1&&Math.abs(n[0][0]-n[n.length-1][0])<=1e-7&&Math.abs(n[0][1]-n[n.length-1][1])<=1e-7&&n.pop();let t=[];for(let o=0;o<n.length;o++){let r=n[(o-1+n.length)%n.length],i=n[o],s=n[(o+1)%n.length],a=(i[0]-r[0])*(s[1]-i[1])-(i[1]-r[1])*(s[0]-i[0]);Math.abs(a)>1e-8&&t.push(i)}return t}function Ho(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-r[0]*o[1]}return n/2}function Ko(e){let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let[i,s]of e)n=Math.min(n,i),t=Math.min(t,s),o=Math.max(o,i),r=Math.max(r,s);return{minX:n,minY:t,maxX:o,maxY:r}}function sl(e,n){return!(e.maxX<n.minX-1e-7||n.maxX<e.minX-1e-7||e.maxY<n.minY-1e-7||n.maxY<e.minY-1e-7)}function Wo(e){return Math.abs(Ho(e))}function Cd(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-8)continue;let a=s>0?1:-1;if(n===0)n=a;else if(n!==a)return!1}return!0}function Td(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=e[0]-n[0],s=e[1]-n[1],a=o*s-r*i,c=Math.hypot(o,r);if(c<=1e-9||Math.abs(a)>Math.max(1e-8,c*1e-8))return!1;let l=i*o+s*r;return l>=-1e-8&&l<=o*o+r*r+1e-8}function Ed(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=o*o+r*r;return i<=1e-12?0:((e[0]-n[0])*o+(e[1]-n[1])*r)/i}function vd(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=Math.hypot(r,i),l=Math.hypot(s,a);if(c<=1e-9||l<=1e-9)return!1;let u=r*(t[1]-e[1])-i*(t[0]-e[0]),f=r*(o[1]-e[1])-i*(o[0]-e[0]),d=r*a-i*s,m=Math.max(1e-8,Math.max(c,l)*1e-8);if(Math.abs(u)>m||Math.abs(f)>m||Math.abs(d)>m)return!1;let p=Math.abs(r)>=Math.abs(i),g=Math.min(p?e[0]:e[1],p?n[0]:n[1]),h=Math.max(p?e[0]:e[1],p?n[0]:n[1]),y=Math.min(p?t[0]:t[1],p?o[0]:o[1]),b=Math.max(p?t[0]:t[1],p?o[0]:o[1]);return Math.min(h,b)-Math.max(g,y)>1e-8}function Id(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];for(let i=0;i<n.length;i++)if(vd(o,r,n[i],n[(i+1)%n.length]))return!0}return!1}function el(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=[{t:0,point:r},{t:1,point:i}];for(let c of n)Zi(c,r)||Zi(c,i)||Td(c,r,i)&&s.push({t:Ed(c,r,i),point:c});s.sort((c,l)=>c.t-l.t);let a=[];for(let c of s)a.some(l=>Math.abs(l.t-c.t)<=1e-8||Zi(l.point,c.point))||a.push(c);for(let c=0;c<a.length-1;c++){let l=a[c].point,u=a[c+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||t.push({a:[cn(l[0]),cn(l[1])],b:[cn(u[0]),cn(u[1])]})}}return t}function _d(e,n,t=Ko(e),o=Ko(n)){if(!sl(t,o)||!Id(e,n))return null;let r=[...el(e,n),...el(n,e)],i=new Map;for(let y of r){let b=md(y),x=i.get(b);x?x.push(y):i.set(b,[y])}let s=!1,a=[];for(let y of i.values()){if(y.length===1){a.push(y[0]);continue}s=!0;let b=y.filter(P=>En(P.a)<En(P.b)).length,x=y.length-b;if(b!==x)return null}if(!s||a.length<3)return null;let c=new Map;for(let y of a){let b=En(y.a);if(c.has(b))return null;c.set(b,y)}let l=a[0],u=En(l.a),f=[],d=new Set,m=u;for(let y=0;y<=a.length;y++){let b=c.get(m);if(!b)return null;let x=`${En(b.a)}>${En(b.b)}`;if(d.has(x))return null;if(d.add(x),f.push(b.a),m=En(b.b),m===u)break}if(m!==u||d.size!==a.length)return null;let p=Ji(f);if(p.length<3||!Cd(p))return null;let g=Wo(p),h=Wo(e)+Wo(n);return Math.abs(g-h)>Math.max(1e-5,h*1e-5)?null:Ho(p)>=0?p:[...p].reverse()}function Vd(e){let n=e.map(Ji).filter(r=>r.length>=3&&Wo(r)>1e-8),t=n.map(Ko),o=!0;for(;o;){o=!1;for(let r=0;r<n.length;r++){for(let i=r+1;i<n.length;i++){if(!sl(t[r],t[i]))continue;let s=_d(n[r],n[i],t[r],t[i]);if(s){n[r]=s,t[r]=Ko(s),n.splice(i,1),t.splice(i,1),o=!0;break}}if(o)break}}return n}function Od(e,n,t){let o=new Map;return r=>{let i=cn(r[0]),s=cn(r[1]),a=`${i},${s}`,c=o.get(a);if(c)return[c[0],c[1],c[2]];let l=qi(e,qi(Kt(n,i),Kt(t,s))),u=[Ki(l[0]),Ki(l[1]),Ki(l[2])];return o.set(a,u),[u[0],u[1],u[2]]}}function Rd(e,n,t,o,r){let i=t[0]?.a;if(!i)return null;let s=Zt(Yn(r,Kt(o,jn(r,o))));if(!s)return null;let a=Zt(nl(o,s));if(!a)return null;let c=[],l=[];for(let y of t){let b=Jc(y.a,i,s,a),x=Jc(y.b,i,s,a);Math.hypot(b[0]-x[0],b[1]-x[1])<=1e-7||(c.push({a:b,b:x}),l.push(b[0],x[0]))}let u=Ad(l);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,d=gd(e,n),m=hd(e,n),p=[];for(let y=0;y<u.length-1;y++){let b=u[y],x=u[y+1];if(x-b<=1e-7)continue;let P=(b+x)/2,M=c.filter(C=>{let E=Math.min(C.a[0],C.b[0]),A=Math.max(C.a[0],C.b[0]);return E<P&&P<A&&Math.abs(C.a[0]-C.b[0])>1e-7}).map(C=>({segment:C,yMid:Wt(C,P)})).sort((C,E)=>C.yMid-E.yMid);if(M.length!==0){if(M.length%2!==0)return null;for(let C=0;C<M.length;C+=2){let E=M[C].segment,A=M[C+1].segment,S=Wt(E,b),T=Wt(E,x),v=Wt(A,b),R=Wt(A,x),O=Ji([[b,S],[x,T],[x,R],[b,v]]);if(O.length<3||Math.abs(Ho(O))<=1e-8)continue;let L=Ho(O)>0?O:[...O].reverse();p.push(L)}}}if(p.length===0||e.length>2&&p.length>e.length*fd)return null;let g=Od(i,s,a),h=Vd(p).map(y=>({vertices:y.map(g),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return sn(h)}function Ld(e,n,t){let o=bd(e,n);if(!o||o.length<3||!xd(o))return null;let r=rl(n[e[0]]);if(!r)return null;let i=null;for(let s of Sd(o,r.normal,t)){let a=Rd(e,n,o,r.normal,s);a&&(!i||a.length<i.length)&&(i=a)}return!i||i.length>=e.length?null:i}function Zo(e,n={}){let t=n.minGroupPolygons??id,o=n.maxCandidateAxes??sd,r=n.planeEpsilon??ad,i=e??[];if(i.length<t)return i;let{groups:s}=yd(i,r);if(s.length===0)return i;let a=new Map,c=new Set;for(let u of s){if(u.length<t)continue;let f=Ld(u,i,o);if(f){a.set(u[0],f);for(let d of u)c.add(d)}}if(a.size===0)return i;let l=[];for(let u=0;u<i.length;u++){let f=a.get(u);if(f){l.push(...f);continue}c.has(u)||l.push(i[u])}return l}function wd(e,n){let t=`${e[0]},${e[1]},${e[2]}`,o=`${n[0]},${n[1]},${n[2]}`;return t<o?`${t}|${o}`:`${o}|${t}`}function Nd(e){if(e.length<100)return!1;let n=new Map;for(let o of e){let r=o.vertices;for(let i=0;i<r.length;i++){let s=wd(r[i],r[(i+1)%r.length]);n.set(s,(n.get(s)??0)+1)}}let t=0;for(let o of n.values())o===1&&(t+=1);return t>=128&&t/Math.max(1,n.size)>.2}function Dd(e,n,t){let o=Math.abs(e)>.9?0:1,r=Math.abs(e)>.9?1:0,i=r*t,s=-o*t,a=o*n-r*e,c=Math.hypot(i,s,a);return i/=c,s/=c,a/=c,{ux:i,uy:s,uz:a,vx:n*a-t*s,vy:t*i-e*a,vz:e*s-n*i}}function Fd(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[j,G,Z]of n)t+=j,o+=G,r+=Z;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=Dd(g,h,y),S=n.length-2,T=new Float64Array(S*9),v=0;for(let j=1;j<n.length-1;j++){let G=n[0],Z=n[j],ee=n[j+1];T[v++]=G[0],T[v++]=G[1],T[v++]=G[2],T[v++]=Z[0],T[v++]=Z[1],T[v++]=Z[2],T[v++]=ee[0],T[v++]=ee[1],T[v++]=ee[2]}let R=0,O=1/0,L=1/0,D=1/0,_=-1/0,w=-1/0,V=-1/0;for(let[j,G,Z]of n){let ee=j-t,W=G-o,ie=Z-r,z=ee*ee+W*W+ie*ie;z>R&&(R=z),j<O&&(O=j),j>_&&(_=j),G<L&&(L=G),G>w&&(w=G),Z<D&&(D=Z),Z>V&&(V=Z)}return{centroid:[t,o,r],normal:[g,h,y],vertices:n,triFlat:T,bcx:t,bcy:o,bcz:r,br2:R,ux:x,uy:P,uz:M,vx:C,vy:E,vz:A,minX:O,minY:L,minZ:D,maxX:_,maxY:w,maxZ:V}}function Bd(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function kd(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(Bd(e,n,t,o,r,i,p,h))return!0;return!1}var qt=9,zd=6,Ke=8;function es(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function Ud(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*qt),l=0,u=new Float64Array(Ke),f=new Float64Array(Ke),d=new Float64Array(Ke),m=new Float64Array(Ke),p=new Float64Array(Ke),g=new Float64Array(Ke),h=new Int32Array(Ke),y=new Float64Array(Ke-1),b=new Int32Array(Ke-1),x=new Float64Array(Ke-1),P=new Int32Array(Ke-1);function M(C,E){let A=l++,S=A*qt,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=zd)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=es(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ce=Ke/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),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ce|0;oe>=Ke&&(oe=Ke-1);let pe=e[o[K]];pe.minX<u[oe]&&(u[oe]=pe.minX),pe.maxX>m[oe]&&(m[oe]=pe.maxX),pe.minY<f[oe]&&(f[oe]=pe.minY),pe.maxY>p[oe]&&(p[oe]=pe.maxY),pe.minZ<d[oe]&&(d[oe]=pe.minZ),pe.maxZ>g[oe]&&(g[oe]=pe.maxZ),h[oe]++}let Ve=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<Ke-1;K++)u[K]<Ve&&(Ve=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=es(Ve,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=Ke-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=es(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<Ke-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ce)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*qt+7]=ae,c[A*qt+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function ns(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*qt,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&kd(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function Gd(e){let n=al.get(e);if(n)return n;let t=(1+Math.sqrt(5))/2,o=new Float64Array(e*3);for(let r=0;r<e;r++){let i=(r+.5)/e,s=Math.sqrt(Math.max(0,1-i*i)),a=2*Math.PI*(r/t);o[r*3]=s*Math.cos(a),o[r*3+1]=s*Math.sin(a),o[r*3+2]=i}return al.set(e,o),o}var al=new Map;function hn(e,n){let t=n?.samples??8;if(e.length<4||t<1||!n?.force&&Nd(e))return e;let o=Math.max(1,Math.ceil(t*(n?.minEscapeRatio??1/t))),r=e.map(Fd),i=Gd(t),s=[],a=Ud(r),c=new Int32Array(Math.max(64,a.nodeCount)),l=192,u=new Float64Array(l);for(let f=0;f<e.length;f++){let d=r[f];if(!d){s.push(e[f]);continue}let m=d.normal[0],p=d.normal[1],g=d.normal[2],h=.001*m,y=.001*p,b=.001*g;{let D=d.centroid[0]+h,_=d.centroid[1]+y,w=d.centroid[2]+b;if(!ns(D,_,w,m,p,g,f,a,c)){s.push(e[f]);continue}}let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=d,S=d.centroid[0],T=d.centroid[1],v=d.centroid[2],R=d.vertices,O=R.length,L=0;u[L++]=S+h,u[L++]=T+y,u[L++]=v+b;for(let D=0;D<O;D++){let _=R[D];u[L++]=_[0]+(S-_[0])*.08+h,u[L++]=_[1]+(T-_[1])*.08+y,u[L++]=_[2]+(v-_[2])*.08+b}for(let D=0;D<O;D++){let _=R[D],w=R[(D+1)%O],V=(_[0]+w[0])*.5,j=(_[1]+w[1])*.5,G=(_[2]+w[2])*.5;u[L++]=V+(S-V)*.08+h,u[L++]=j+(T-j)*.08+y,u[L++]=G+(v-G)*.08+b}if(o<=1){let D=!1;e:for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!ns(ie,z,X,G,Z,ee,f,a,c)){D=!0;break e}}}D&&s.push(e[f])}else{let D=0;for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!ns(ie,z,X,G,Z,ee,f,a,c)){D++;break}}}D>=o&&s.push(e[f])}}return s}var ss={overlapPx:1.25,maxGapPx:14,capacityScale:1},as={budget:40};function Wn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function xt(e){return typeof e=="number"?{overlapPx:Math.max(0,e)*.175,maxGapPx:14,capacityScale:1}:{overlapPx:Math.max(0,Wn(e?.overlapPx,1.25)),maxGapPx:Math.max(0,Wn(e?.maxGapPx,14)),capacityScale:Math.max(0,Wn(e?.capacityScale,1))}}function Pt(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function pl(e){return{rotX:Wn(e?.rotX,65),rotY:Wn(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(Wn(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(Wn(e?.budget,40))))}}function vn(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function gl(e){return[e[1]/50,e[0]/50,e[2]/50]}function tr(e){return`${e[0]},${e[1]},${e[2]}`}function $d(e,n){let t=tr(e),o=tr(n);return t<o?`${t}|${o}`:`${o}|${t}`}function In(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Mt(e){return Math.hypot(e[0],e[1],e[2])}function no(e){let n=Mt(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function eo(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function qo(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function cs(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 Xd(e){if(e.length<3)return null;let n=e[0],t=[0,0,0];for(let o=1;o+1<e.length;o+=1){let r=In(e[o],n),i=In(e[o+1],n),s=cs(r,i);t[0]-=s[0],t[1]-=s[1],t[2]-=s[2]}return no(t)}function ls(e){let n=e[0],t=Xd(e);if(!t)return null;let o=null;for(let u=0;u<e.length;u+=1){let f=In(e[(u+1)%e.length],e[u]);if(Mt(f)>1e-6){o=f;break}}if(!o)return null;let r=eo(o,t),i=[o[0]-r*t[0],o[1]-r*t[1],o[2]-r*t[2]],s=no(i);if(!s)return null;let a=no(cs(t,s));if(!a)return null;let c=e.map(u=>{let f=In(u,n);return[eo(f,s),eo(f,a)]}),l=or(c);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:s,yAxis:a,local:c,area:l}:null}function or(e){let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function us(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-6)continue;let a=Math.sign(s);if(n===0)n=a;else if(a!==n)return!1}return!0}function hl(e,n,t){let o=e[t],r=e[(t+1)%e.length],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return null;let c=n>0?1:-1;return[c*(s/a),c*(-i/a)]}function Yd(e,n){let t=hl(e.local,e.area,n);return t?no([e.xAxis[0]*t[0]+e.yAxis[0]*t[1],e.xAxis[1]*t[0]+e.yAxis[1]*t[1],e.xAxis[2]*t[0]+e.yAxis[2]*t[1]]):null}function yl(e,n){let t=e.length,o=e[n],r=e[(n+1)%t],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return 0;let c=[a*.24],l=1/0;for(let f=0;f<t;f+=1){if(f===n||f===(n+1)%t)continue;let d=e[f],m=Math.abs((d[0]-o[0])*s-(d[1]-o[1])*i)/a;m>1e-6&&(l=Math.min(l,m))}Number.isFinite(l)&&c.push(l*.32);let u=[{origin:o,point:e[(n+t-1)%t]},{origin:r,point:e[(n+2)%t]}];for(let f of u){let d=f.point[0]-f.origin[0],m=f.point[1]-f.origin[1],p=Math.hypot(d,m);if(p<=1e-6)continue;let g=Math.abs(i*m-s*d)/(a*p);g>1e-6&&c.push(p*g*.32)}return Math.min(...c)}function bl(e){return e.map(n=>{let t=vn(n.vertices),o=ls(t),r=!fs(n)&&!!o&&us(o.local),i=r?o.local.map((s,a)=>yl(o.local,a)):[];return{basis:o,cssPoints:t,capacities:i,patchable:r}})}function fs(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function jd(e){return e.material?.key??e.color??""}function xl(e,n,t){let o=[];for(let r=0;r<n.length;r+=1){let i=n[r];if(!(!i.patchable||!i.basis))for(let s=0;s<i.cssPoints.length;s+=1){let a=i.cssPoints[s],c=i.cssPoints[(s+1)%i.cssPoints.length],l=In(c,a),u=Mt(l),f=no(l),d=Yd(i.basis,s),m=(i.capacities[s]??0)*t;!f||!d||m<=1e-6||u<=1e-6||o.push({index:o.length,polygon:r,edge:s,key:$d(a,c),a,b:c,minX:Math.min(a[0],c[0]),minY:Math.min(a[1],c[1]),minZ:Math.min(a[2],c[2]),maxX:Math.max(a[0],c[0]),maxY:Math.max(a[1],c[1]),maxZ:Math.max(a[2],c[2]),length:u,dir:f,normal:i.basis.normal,outward:d,capacity:m,materialKey:jd(e[r]),color:e[r].color})}}return o}function ms(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function Qo(e,n){return Mt(In(e,n))<=1e-4}function Wd(e,n){return Qo(e.a,n.a)||Qo(e.a,n.b)||Qo(e.b,n.a)||Qo(e.b,n.b)}function Hd(e,n){return ms(e,n)?Wd(e,n)?"connected-facet":"true-gap":"material-boundary"}function ts(e,n,t,o,r,i){return{kind:e,aPolygon:n.polygon,aEdge:n.edge,bPolygon:t.polygon,bEdge:t.edge,aColor:n.color,bColor:t.color,aMaterialKey:n.materialKey,bMaterialKey:t.materialKey,gapPx:o.gap,spanPx:o.aEnd-o.aStart,aStartPx:o.aStart,aEndPx:o.aEnd,bStartPx:o.bStart,bEndPx:o.bEnd,targetClosurePx:r,appliedClosurePx:i,residualGapPx:Math.max(0,o.gap-i),residualTargetPx:Math.max(0,r-i)}}function cl(e,n,t,o,r){let i=Math.max(0,Math.min(n.length,Math.min(t,o))),s=Math.max(0,Math.min(n.length,Math.max(t,o)));if(r<=1e-6||s-i<=1e-6)return;let a=e[n.polygon].get(n.edge),c={start:i,end:s,amount:r};a?a.push(c):e[n.polygon].set(n.edge,[c])}function rr(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function Kd(e,n){let t=0,o=0,r=0;for(let i of e){i.size>0&&(r+=1),o+=i.size;for(let s of i.values())for(let a of s)t=Math.max(t,a.amount)}return{...n,patchedPolygons:r,patchedEdges:o,maxAppliedAmountPx:t}}function ir(e,n,t=!1,o=!1){let r=bl(e),i=xl(e,r,n.capacityScale),s=o?[]:e.map(()=>new Map),a=rr(),c=t?[]:void 0;if(i.length===0)return{edgeRepairs:s,diagnostics:a,candidates:c};let l=new Map;for(let u of i){let f=l.get(u.key);f?f.push(u):l.set(u.key,[u])}for(let u of l.values())u.length<2||(a.exactPairs+=u.length===2?1:u.length);return Zd(i,l,s,a,n,c),{edgeRepairs:s,diagnostics:o?a:Kd(s,a),candidates:c}}function Zd(e,n,t,o,r,i){let s=r.maxGapPx,a=new Set;for(let[m,p]of n)p.length>1&&a.add(m);let c=(m,p)=>{let g=m.index<p.index?m:p,h=m.index<p.index?p:m;if(h.polygon===g.polygon||g.key===h.key&&a.has(g.key)||!i&&!ms(g,h)||!qd(g,h,s)||Math.abs(eo(g.dir,h.dir))<.985)return;let y=np(g,h,s);if(!y)return;let b=Hd(g,h),x=y.gap+r.overlapPx;if(b==="material-boundary"){i?.push(ts(b,g,h,y,x,0));return}let P=x;if(P<=.25){i?.push(ts(b,g,h,y,x,0));return}let M=g.capacity*y.facingA,C=h.capacity*y.facingB,E=Math.min(M,P/2),A=Math.min(C,P/2);if(P-=E+A,P>1e-6){let S=Math.min(M-E,P);E+=S,P-=S}if(P>1e-6){let S=Math.min(C-A,P);A+=S,P-=S}i?.push(ts(b,g,h,y,x,E+A)),t.length>0&&E>1e-6&&cl(t,g,y.aStart,y.aEnd,E/y.facingA),t.length>0&&A>1e-6&&cl(t,h,y.bStart,y.bEnd,A/y.facingB),o.nearPairs+=1,o.maxMeasuredGapPx=Math.max(o.maxMeasuredGapPx,y.gap),P>.25&&(o.unclosedPairs+=1,o.maxResidualGapPx=Math.max(o.maxResidualGapPx,P))},l=Math.max(28,s*2);if(e.length<=1e4){let m=[...e].sort((h,y)=>h.minX-y.minX),p=new Int32Array(m.length),g=0;for(let h=0;h+1<m.length;h+=1){let b=m[h].maxX+s,x=h+1;for(;x<m.length&&m[x].minX<=b;)x+=1;if(p[h]=x,g+=x-h-1,g>25e6)break}if(g<=2e6||g<=25e6&&ep(e,l,s)){for(let h=0;h+1<m.length;h+=1)for(let y=h+1;y<p[h];y+=1)c(m[h],m[y]);return}}let u=new Map;for(let m of e)Qd(u,m,l,s);let f=new Set,d=e.length;for(let m of u.values())for(let p=0;p+1<m.length;p+=1)for(let g=p+1;g<m.length;g+=1){let h=m[p],y=m[g],b=h.index<y.index?h:y,x=h.index<y.index?y:h,P=b.index*d+x.index;f.has(P)||(f.add(P),c(b,x))}}function qd(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function ll(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function Qd(e,n,t,o){let[r,i,s,a,c,l]=Pl(n,t,o);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function Pl(e,n,t){let[o,r,i]=ll([e.minX-t,e.minY-t,e.minZ-t],n),[s,a,c]=ll([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[o,r,i,s,a,c]}function Jd(e,n,t){let[o,r,i,s,a,c]=Pl(e,n,t);return(s-o+1)*(a-r+1)*(c-i+1)}function ep(e,n,t){let o=0,r=0;for(let i of e){let s=Jd(i,n,t);if(o+=s,s>r&&(r=s),r>8192)return!0}return o/Math.max(1,e.length)>256}function ul(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function fl(e,n,t){return(e.a[0]+e.dir[0]*n-t.a[0])*t.dir[0]+(e.a[1]+e.dir[1]*n-t.a[1])*t.dir[1]+(e.a[2]+e.dir[2]*n-t.a[2])*t.dir[2]}function np(e,n,t){let o=ul(n.a,e.a,e.dir),r=ul(n.b,e.a,e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i,c=Math.min(e.length,n.length);if(a<Math.max(.75,c*.12))return null;let l=(i+s)/2,u=e.a[0]+e.dir[0]*l,f=e.a[1]+e.dir[1]*l,d=e.a[2]+e.dir[2]*l,m=Math.max(0,Math.min(n.length,(u-n.a[0])*n.dir[0]+(f-n.a[1])*n.dir[1]+(d-n.a[2])*n.dir[2])),p=n.a[0]+n.dir[0]*m-u,g=n.a[1]+n.dir[1]*m-f,h=n.a[2]+n.dir[2]*m-d,y=Math.hypot(p,g,h);if(y<=1e-6||y>t||y>Math.min(t,Math.max(4,c*.28)))return null;let b=1/y,x=p*b,P=g*b,M=h*b,C=e.outward[0]*x+e.outward[1]*P+e.outward[2]*M,E=-(n.outward[0]*x+n.outward[1]*P+n.outward[2]*M);if(C<.5||E<.5)return null;let A=Math.max(0,Math.min(n.length,fl(e,i,n))),S=Math.max(0,Math.min(n.length,fl(e,s,n)));return{gap:y,facingA:C,facingB:E,aStart:i,aEnd:s,bStart:Math.min(A,S),bEnd:Math.max(A,S)}}function os(e,n,t,o){let r=t<=1e-6?0:Math.max(0,Math.min(1,o/t));return[e[0]+(n[0]-e[0])*r,e[1]+(n[1]-e[1])*r]}function Qt(e,n){let t=e[e.length-1];t&&Math.hypot(t[0]-n[0],t[1]-n[1])<=1e-6||e.push(n)}function tp(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let o=new Set([0,n]);for(let s of e){let a=Math.max(0,Math.min(n,s.start)),c=Math.max(0,Math.min(n,s.end));c-a<=1e-6||s.amount<=1e-6||(o.add(a),o.add(c))}let r=Array.from(o).sort((s,a)=>s-a),i=[];for(let s=0;s+1<r.length;s+=1){let a=r[s],c=r[s+1];if(c-a<=1e-6)continue;let l=(a+c)/2,u=0;for(let d of e)l+1e-6<d.start||l-1e-6>d.end||(u=Math.max(u,d.amount));let f=Math.min(t,u);f>1e-6&&i.push({start:a,end:c,amount:f})}return i}function op(e,n){if(n.length<3||!us(n))return!1;let t=or(e),o=or(n);return Math.sign(o)===Math.sign(t)&&Math.abs(o)>=Math.abs(t)-1e-6}function rp(e,n,t){if(n.size===0||e.vertices.length<3||fs(e))return e;let o=vn(e.vertices),r=ls(o);if(!r||!us(r.local))return e;let i=[];for(let l=0;l<r.local.length;l+=1){let u=r.local[l],f=r.local[(l+1)%r.local.length],d=Math.hypot(f[0]-u[0],f[1]-u[1]),m=hl(r.local,r.area,l);if(!m||d<=1e-6)return e;let p=tp(n.get(l),d,yl(r.local,l)*t);Qt(i,u);let g=0;for(let h of p){h.start>g+1e-6&&Qt(i,os(u,f,d,h.start));let y=os(u,f,d,h.start),b=os(u,f,d,h.end);Qt(i,[y[0]+m[0]*h.amount,y[1]+m[1]*h.amount]),Qt(i,[b[0]+m[0]*h.amount,b[1]+m[1]*h.amount]),h.end<d-1e-6&&Qt(i,b),g=h.end}}let s=i[0],a=i[i.length-1];if(s&&a&&Math.hypot(s[0]-a[0],s[1]-a[1])<=1e-6&&i.pop(),!op(r.local,i))return e;let c=i.map(([l,u])=>gl([r.origin[0]+l*r.xAxis[0]+u*r.yAxis[0],r.origin[1]+l*r.xAxis[1]+u*r.yAxis[1],r.origin[2]+l*r.xAxis[2]+u*r.yAxis[2]]));return{...e,vertices:c}}function Ml(e){return e.vertices.length===4&&!fs(e)}function ip(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let[c,l]of n)t=Math.min(t,c),o=Math.min(o,l),r=Math.max(r,c),i=Math.max(i,l);let s=Math.max(1e-6,(r-t)*(i-o));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/s)))*2.5}function rs(e,n){return Mt(In(vn([e])[0],vn([n])[0]))}function Jo(e,n,t){let o=rs(e,n),r=rs(n,t),i=rs(t,e),s=Math.max(o,r,i);return s<=1e-6?0:Mt(cs(In(vn([n])[0],vn([e])[0]),In(vn([t])[0],vn([e])[0])))*.5/(s*s)}function sp(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=r*a-i*s;if(Math.abs(c)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*s)/c;return[e[0]+f*r,e[1]+f*i]}function ap(e,n){if(e.length<3||e.length!==n.length)return null;let t=Math.max(0,...n);if(t<=1e-6)return e;let o=or(e);if(Math.abs(o)<=1e-6)return null;let r=o>0?1:-1,i=[];for(let c=0;c<e.length;c+=1){let l=e[c],u=e[(c+1)%e.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=1e-6)return null;let p=Math.max(0,n[c]),g=r*(d/m)*p,h=r*(-f/m)*p;i.push({a:[l[0]+g,l[1]+h],b:[u[0]+g,u[1]+h]})}let s=[],a=Math.max(2,t*4);for(let c=0;c<e.length;c+=1){let l=i[(c+e.length-1)%e.length],u=i[c],f=sp(l.a,l.b,u.a,u.b);if(!f)return null;let d=e[c],m=f[0]-d[0],p=f[1]-d[1],g=Math.hypot(m,p);s.push(g>a?[d[0]+m/g*a,d[1]+p/g*a]:f)}return s}function cp(e,n){return[e.origin[0]+e.xAxis[0]*n[0]+e.yAxis[0]*n[1],e.origin[1]+e.xAxis[1]*n[0]+e.yAxis[1]*n[1],e.origin[2]+e.xAxis[2]*n[0]+e.yAxis[2]*n[1]]}function er(e,n){let t=ls(vn(e));if(!t)return e;let o=ap(t.local,n);return o?o.map(r=>gl(cp(t,r))):e}function lp(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[o,r,i,s]=e.vertices,a=Math.min(Jo(o,r,i),Jo(o,i,s)),c=Math.min(Jo(o,r,s),Jo(r,i,s)),l=u=>n.has(u)?.75:0;return a>=c?[{...t,vertices:er([o,r,i],[l(0),l(1),1.25])},{...t,vertices:er([o,i,s],[1.25,l(2),l(3)])}]:[{...t,vertices:er([o,r,s],[l(0),1.25,l(3)])},{...t,vertices:er([r,i,s],[l(1),l(2),1.25])}]}function ml(e){if(e.length===0)return{q1:1/0,median:1/0,q3:1/0,p70:1/0,p80:1/0,p88:1/0,p95:1/0,p97:1/0,max:1/0};let n=[...e].sort((o,r)=>o-r),t=o=>n[Math.min(n.length-1,Math.floor((n.length-1)*o))]??0;return{q1:t(.25),median:t(.5),q3:t(.75),p70:t(.7),p80:t(.8),p88:t(.88),p95:t(.95),p97:t(.97),max:n[n.length-1]??0}}function nr(e,n){let t=e[n];if(t===n)return n;let o=nr(e,t);return e[n]=o,o}function up(e){let n=new Set,t=new Set;for(let o of e)o.sel&&t.add(o.comp);for(let o of e)if(t.has(o.comp))for(let r of o.e)n.add(r);return{endpoints:n}}function fp(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function mp(e,n,t,o){let r=[];for(let[c,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!ms(u,f))continue;let d=l.filter(C=>Ml(e[C.polygon]));if(d.length===0)continue;let m=d[0],p=1-Math.min(1,Math.abs(eo(u.normal,f.normal))),g=Math.max(u.length,f.length);if(p<.01&&g<64)continue;let h=Math.max(...d.map(C=>ip(n[C.polygon]))),y=d.length===2?1.18:1,b=Math.max(.08,p),x=o.viewAware?dp(u,f,o.rotX,o.rotY):{proj:g,vr:1},P=o.viewAware?Math.max(x.proj,g*.12):g,M=o.viewAware?.18+x.vr*1.82:1;r.push({key:c,e:[tr(m.a),tr(m.b)],o:l,r:d,len:g,rank:P,proj:x.proj,s:P*(.58+b*2.8)*h*y*M,nr:p,sr:h,vr:x.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let i=Array.from({length:r.length},(c,l)=>l),s=new Map;for(let c=0;c<r.length;c+=1)for(let l of r[c].e){let u=s.get(l);if(u===void 0)s.set(l,c);else{let f=nr(i,u),d=nr(i,c);f!==d&&(i[d]=f)}}let a=new Map;for(let c=0;c<r.length;c+=1){let l=nr(i,c),u=a.get(l);u===void 0&&(u=a.size,a.set(l,u)),r[c].comp=u}return r}function dp(e,n,t,o){let r=qo(e.a,t,0,o),i=qo(e.b,t,0,o),s=Math.hypot(i[0]-r[0],i[1]-r[1]),a=qo(e.normal,t,0,o)[2],c=qo(n.normal,t,0,o)[2],l=Math.max(0,a,c),u=Math.min(1,Math.abs(a-c));return{proj:s,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function pp(e){let n=new Map;for(let t of e){let o=n.get(t.comp);(!o||t.s>o.s||t.s===o.s&&t.len>o.len)&&n.set(t.comp,t)}return new Set(n.values())}function Jt(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+n*n*n*3.65,o=e.r.length===1?1.08:1;return e.rank*t*o/Math.sqrt(Math.max(1,e.r.length))}function dl(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+Math.min(1,e.vr)*1.65,o=.7+Math.min(2.6,e.sr)*.3,r=e.r.length===1?1.1:1,i=e.rank*(.6+n*n*1.4)*t*o*r/Math.sqrt(Math.max(1,e.r.length));return Math.max(i,Jt(e)*.75)}function is(e){let n=new Set;for(let t of e)for(let o of t.r)n.add(o.polygon);return n.size}function Sl(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function gp(e,n,t){return e.s>=n||e.rank>=t}function hp(e,n,t,o,r,i,s){let a=Math.max(0,Math.floor(t));if(a<=0||e.length===0||n==="follow-up")return{budgetLimit:a,componentBudgets:null};let c=new Map;for(let m of e){let p=c.get(m.comp);p?p.push(m):c.set(m.comp,[m])}let l=new Map,u=Math.max(1e-6,o.q3-o.q1),f=Math.min(o.max,Math.max(o.p95,o.q3+u)),d=0;for(let[m,p]of c){let g=p.filter(M=>gp(M,i,s)||M.s>=f);if(g.length===0)continue;let h=p.filter(M=>Sl(M,r)),y=is(g),b=is(h),x=Math.ceil(Math.sqrt(Math.max(0,b-y))*3),P=Math.min(is(p),y+x);P<=0||(l.set(m,P),d+=P)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(a,d),componentBudgets:l}}function yp(e,n,t){let o=new Map;if(e.length===0||t<=0)return{selected:o,budgetLimit:0};let r=ml(e.map(S=>S.s)),i=ml(e.map(S=>S.rank)),s=Math.max(1e-6,r.q3-r.q1),a=Math.min(r.max,Math.max(r.p95,r.q3+s*.85)),c=Math.min(r.max,Math.max(r.p80,r.q3+s*.15)),l=Math.min(r.max,Math.max(r.p70,r.q3)),u=Math.max(i.p97,i.median*1.8),f=Math.max(i.p88,i.median*1.35),d=hp(e,n,t,r,i,a,u),m=d.budgetLimit;if(m<=0)return{selected:o,budgetLimit:0};let p=pp(e),g=new Set,h=new Set,y=new Set,b=new Map,x=n==="primary"?Math.min(Math.max(0,d.budgetLimit-1),Math.max(2,Math.floor(d.budgetLimit*.28))):0,P=[...e].sort((S,T)=>Jt(T)-Jt(S)||T.s/Math.max(1,T.r.length)-S.s/Math.max(1,S.r.length)||T.len-S.len),M=[...e].sort((S,T)=>dl(T)-dl(S)||Jt(T)-Jt(S)||T.len-S.len),C=(S,T)=>{S.sel=!0,S.why=T,y.add(S.comp);for(let v of S.e)h.add(v);for(let v of S.r){g.add(v.polygon);let R=o.get(v.polygon);R?R.add(v.edge):o.set(v.polygon,new Set([v.edge]))}},E=(S,T)=>{let v=d.componentBudgets;if(T<=0||!v)return!0;let R=v.get(S.comp)??0;return(b.get(S.comp)??0)+T<=R},A=(S,T)=>{T<=0||!d.componentBudgets||b.set(S.comp,(b.get(S.comp)??0)+T)};for(let S of M){let T=S.r.reduce((R,O)=>R+(g.has(O.polygon)?0:1),0);if(S.cost=T,!(T>m||!E(S,T)||T>0&&m-T<x||!Sl(S,i))&&(C(S,"global-outlier"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((D,_)=>D+(g.has(_.polygon)?0:1),0);if(S.cost=T,T>m||!E(S,T)||T>0&&m-T<x)continue;let v=S.r.length===2,R=p.has(S)&&(n==="primary"||n==="follow-up"&&S.s>=c*1.08&&S.rank>=f)&&(v?S.s>=c||S.rank>=f:S.s>=c*1.18||S.rank>=f*1.12),O=v?S.s>=a||S.rank>=u:S.s>=a*1.35||S.rank>=u*1.2,L=T===0&&(v?S.s>=l||S.rank>=f:S.s>=l*1.25||S.rank>=f*1.12);if(!(!R&&!O&&!L)&&(C(S,R?"component-anchor":O?"global-outlier":"shared-polygon"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((_,w)=>_+(g.has(w.polygon)?0:1),0);if(S.cost=T,T>1||T>m||!E(S,T))continue;let v=S.r.some(_=>g.has(_.polygon)),R=S.e.some(_=>h.has(_));if(n==="primary"&&S.r.length===1&&T===1&&(y.has(S.comp)||R||v)&&S.rank>=f*1.05&&S.nr>=.16&&S.vr<=.32){if(C(S,"local-follow-up"),A(S,T),m-=T,m<=0)return{selected:o,budgetLimit:d.budgetLimit};continue}if(S.r.length!==2)continue;let L=v&&T===1&&S.proj>=f*1.45&&S.vr<=.18;if(!R&&!L)continue;if((S.s>=l*.42||S.rank>=f*.62)&&S.s<=l*1.1&&S.proj>=24&&(C(S,"local-follow-up"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}return{selected:o,budgetLimit:d.budgetLimit}}function Al(e,n,t,o,r){let i=bl(e),s=xl(e,i,n.capacityScale),a=new Map;for(let u of s){let f=a.get(u.key);f?f.push(u):a.set(u.key,[u])}let c=mp(e,i,a,t).filter(u=>fp(u,r)),l=yp(c,r?"follow-up":"primary",o);return{selected:l.selected,candidates:c,budgetLimit:l.budgetLimit}}function bp(e,n){let t=[];for(let o=0;o<e.length;o+=1){let r=e[o],i=n.get(o);i&&Ml(r)?t.push(...lp(r,i)):t.push(r)}return t}function xp(e){let[n,t]=e.o,o=n??t,r=t??n;return{key:e.key,aPolygon:o?.polygon??-1,aEdge:o?.edge??-1,bPolygon:r?.polygon??-1,bEdge:r?.edge??-1,color:o?.color??r?.color,materialKey:o?.materialKey??r?.materialKey??"",lengthPx:e.len,projectedLengthPx:e.proj,score:e.s,normalRisk:e.nr,shapeRisk:e.sr,viewRisk:e.vr,component:e.comp,marginalCost:e.cost,selected:e.sel,reason:e.why}}function ds(e,n,t){let o=xt(n),r=pl(t);if(!Pt(o,n)||e.length===0)return e;let i=e,s,a=r.budget;for(let c=0;c<r.passes;c+=1){let l=Al(i,o,r,a,s);if(c===0&&(a=Math.min(a,l.budgetLimit)),l.selected.size===0)break;let u=bp(i,l.selected);if(u.length===i.length)break;if(a-=l.selected.size,a<=0){i=u;break}s=up(l.candidates),i=u}return i}function Cl(e,n,t){let o=xt(n),r=pl(t);if(!Pt(o,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let i=Al(e,o,r,r.budget),s=0;for(let a of i.selected.values())s+=a.size;return{candidates:i.candidates.map(xp),selectedPolygons:i.selected.size,selectedEdges:s,addedPolygons:i.selected.size}}function ps(e,n){let t=xt(n);if(!Pt(t,n)||e.length===0)return e;let{edgeRepairs:o}=ir(e,t);return o.some(r=>r.size>0)?e.map((r,i)=>rp(r,o[i],t.capacityScale)):e}function Tl(e,n=ss,t=as){if(e.length===0)return e;let o=ds(e,n,t);return ps(o,n)}function El(e,n){let t=xt(n);return!Pt(t,n)||e.length===0?rr():ir(e,t).diagnostics}function vl(e,n){let t=xt(n);return!Pt(t,n)||e.length===0?rr():ir(e,t,!1,!0).diagnostics}function Il(e,n){let t=xt(n);if(!Pt(t,n)||e.length===0)return{diagnostics:rr(),candidates:[]};let o=ir(e,t,!0);return{diagnostics:o.diagnostics,candidates:o.candidates??[]}}var Hn={ratio:.7,maxError:.18,maxNormalDot:Math.cos(65*Math.PI/180),preserveVertices:!0,vertexKeyMode:"relaxed",lockBoundary:!0,minGroupTriangles:80,maxPasses:12};function Pp(e={}){let n=Number.isFinite(e.ratio)?Math.max(.05,Math.min(.98,e.ratio)):Hn.ratio,t=Number.isFinite(e.maxError)&&e.maxError>0?e.maxError:Hn.maxError,o=Number.isFinite(e.maxNormalAngleDeg)?Math.max(0,Math.min(89,e.maxNormalAngleDeg)):65;return{ratio:n,maxError:t,maxNormalDot:Math.cos(o*Math.PI/180),preserveVertices:e.preserveVertices??Hn.preserveVertices,vertexKeyMode:e.vertexKeyMode??Hn.vertexKeyMode,lockBoundary:e.lockBoundary??Hn.lockBoundary,minGroupTriangles:Math.max(3,Math.floor(e.minGroupTriangles??Hn.minGroupTriangles)),maxPasses:Math.max(1,Math.floor(e.maxPasses??Hn.maxPasses))}}function Mp(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function Sp(e){return e.vertices.length===3&&!Mp(e)}function Ap(e){return[e.color??"",e.doubleSided===!0?"2":"1",e.material?.key??""].join("\0")}function _l(e){return`${Math.round(e[0]*1e5)},${Math.round(e[1]*1e5)},${Math.round(e[2]*1e5)}`}function Cp(e,n,t,o){let r=o.vertexKeyMode==="source"?e.simplifySourceVertexKeys?.[t]??e.simplifyVertexKeys?.[t]:e.simplifyVertexKeys?.[t];return r?`${_l(n)}|${r}`:_l(n)}function Tp(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function St(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Ep(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function gs(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Vl(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 bs(e){return Math.hypot(e[0],e[1],e[2])}function hs(e,n){return bs(St(e,n))}function vp(e){let n=bs(e);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n]:[0,0,1]}function xs(e,n,t,o){return vp(Vl(St(e[t],e[n]),St(e[o],e[n])))}function Ol(e,n,t,o){return bs(Vl(St(e[t],e[n]),St(e[o],e[n])))/2}function Ip(){return[0,0,0,0,0,0,0,0,0,0]}function sr(e,n){for(let t=0;t<e.length;t+=1)e[t]+=n[t]}function _p(e,n,t){let o=e[0],r=e[1],i=e[2],s=-gs(e,n);return[o*o*t,o*r*t,o*i*t,o*s*t,r*r*t,r*i*t,r*s*t,i*i*t,i*s*t,s*s*t]}function ys(e,n){let t=n[0],o=n[1],r=n[2];return e[0]*t*t+2*e[1]*t*o+2*e[2]*t*r+2*e[3]*t+e[4]*o*o+2*e[5]*o*r+2*e[6]*o+e[7]*r*r+2*e[8]*r+e[9]}function Vp(e,n,t,o,r,i,s,a,c,l,u,f){let d=e*(r*c-i*a)-n*(o*c-i*s)+t*(o*a-r*s);if(Math.abs(d)<1e-10)return null;let m=1/d,p=l*(r*c-i*a)-n*(u*c-i*f)+t*(u*a-r*f),g=e*(u*c-i*f)-l*(o*c-i*s)+t*(o*f-u*s),h=e*(r*f-u*a)-n*(o*f-u*s)+l*(o*a-r*s),y=[p*m,g*m,h*m];return y.every(Number.isFinite)?y:null}function Op(e,n,t,o){let r=Vp(e[0],e[1],e[2],e[1],e[4],e[5],e[2],e[5],e[7],-e[3],-e[6],-e[8]),i=Ep(Tp(n,t),.5),s=hs(n,t)*1.35,a=o?[n,t]:[n,t,i,...r&&hs(r,i)<=s?[r]:[]],c=a[0],l=ys(e,c);for(let u=1;u<a.length;u+=1){let f=a[u],d=ys(e,f);d<l&&(c=f,l=d)}return c}function Rp(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function Lp(e,n,t){return`${e}|${n}|${t}`}function wp(e,n){let t=new Map,o=[],r=[];for(let i of e){let s=[];for(let u=0;u<i.vertices.length;u+=1){let f=i.vertices[u],d=Cp(i,f,u,n),m=t.get(d);m===void 0&&(m=o.length,t.set(d,m),o.push([...f])),s.push(m)}let[a,c,l]=s;a===void 0||c===void 0||l===void 0||a===c||a===l||c===l||r.push({a,b:c,c:l,polygon:i,normal:xs(o,a,c,l)})}return{vertices:o,triangles:r}}function Np(e,n){let t=wp(e,n),o=Array.from({length:t.vertices.length},()=>new Set),r=Array.from({length:t.triangles.length},()=>!0);for(let i=0;i<t.triangles.length;i+=1){let s=t.triangles[i];o[s.a].add(i),o[s.b].add(i),o[s.c].add(i)}return{vertices:t.vertices,triangles:t.triangles,alive:r,vertexTriangles:o,activeCount:t.triangles.length}}function Dp(e){let n=new Map,t=(o,r,i)=>{let s=Rp(o,r),a=n.get(s);a?a.triangles.push(i):n.set(s,{a:Math.min(o,r),b:Math.max(o,r),triangles:[i]})};for(let o=0;o<e.triangles.length;o+=1){if(!e.alive[o])continue;let r=e.triangles[o];t(r.a,r.b,o),t(r.b,r.c,o),t(r.c,r.a,o)}return n}function Fp(e){let n=Array.from({length:e.vertices.length},()=>Ip());for(let t=0;t<e.triangles.length;t+=1){if(!e.alive[t])continue;let o=e.triangles[t],r=Math.max(1e-6,Ol(e.vertices,o.a,o.b,o.c)),i=_p(o.normal,e.vertices[o.a],Math.sqrt(r));sr(n[o.a],i),sr(n[o.b],i),sr(n[o.c],i)}return n}function Bp(e,n,t){let o=new Set,r=i=>{let s=e.vertexTriangles[i];if(s)for(let a of s)e.alive[a]&&o.add(a)};return r(n),r(t),Array.from(o).sort((i,s)=>i-s)}function kp(e,n,t){let o=e.vertexTriangles[n],r=e.vertexTriangles[t];if(!o||!r)return 0;let[i,s]=o.size<=r.size?[o,r]:[r,o],a=0;for(let c of i)e.alive[c]&&s.has(c)&&(a+=1);return a}function Rl(e,n,t){return[e.a===t?n:e.a,e.b===t?n:e.b,e.c===t?n:e.c]}function zp(e,n,t){if(kp(e,n.a,n.b)!==2)return null;let o=Bp(e,n.a,n.b);if(o.length===0)return null;let r=e.vertices[n.a];e.vertices[n.a]=n.target;let i=0,s=!0;for(let a of o){let c=e.triangles[a],[l,u,f]=Rl(c,n.a,n.b);if(l===u||l===f||u===f)continue;if(Ol(e.vertices,l,u,f)<=1e-8){s=!1;break}let m=xs(e.vertices,l,u,f);if(gs(c.normal,m)<t.maxNormalDot){s=!1;break}let p=c.a===n.a?r:e.vertices[c.a];if(Math.abs(gs(c.normal,St(n.target,p)))>t.maxError){s=!1;break}i+=1}return e.vertices[n.a]=r,s&&i>0?o:null}function Up(e,n,t){e.vertexTriangles[t.a]?.delete(n),e.vertexTriangles[t.b]?.delete(n),e.vertexTriangles[t.c]?.delete(n)}function Gp(e,n,t){e.vertexTriangles[t.a].add(n),e.vertexTriangles[t.b].add(n),e.vertexTriangles[t.c].add(n)}function $p(e,n,t){e.vertices[n.a]=n.target;let o=new Set;for(let r of t){if(!e.alive[r])continue;let i=e.triangles[r],[s,a,c]=Rl(i,n.a,n.b);if(Up(e,r,i),s===a||s===c||a===c){e.alive[r]=!1,e.activeCount-=1;continue}let l=Lp(s,a,c);if(o.has(l)){e.alive[r]=!1,e.activeCount-=1;continue}o.add(l);let u={...i,a:s,b:a,c,normal:xs(e.vertices,s,a,c)};e.triangles[r]=u,Gp(e,r,u)}}function Xp(e,n){let t=Dp(e),o=new Set;for(let a of t.values())a.triangles.length>2&&(o.add(a.a),o.add(a.b));if(n.lockBoundary)for(let a of t.values())a.triangles.length===1&&(o.add(a.a),o.add(a.b));let r=Fp(e),i=n.maxError*n.maxError,s=[];for(let a of t.values()){if(a.triangles.length!==2||o.has(a.a)||o.has(a.b))continue;let c=[...r[a.a]];sr(c,r[a.b]);let l=Op(c,e.vertices[a.a],e.vertices[a.b],n.preserveVertices),u=Math.max(0,ys(c,l));if(u>i*Math.max(1,a.triangles.length))continue;let f=hs(e.vertices[a.a],e.vertices[a.b]);s.push({a:a.a,b:a.b,target:l,error:u,length:f})}return s.sort((a,c)=>a.error-c.error||a.length-c.length),s}function Yp(e){let n=[];for(let t=0;t<e.triangles.length;t+=1)e.alive[t]&&n.push(e.triangles[t]);return n}function jp(e,n){if(e.length<n.minGroupTriangles)return e;let t=Np(e,n),o=t.activeCount;if(o<n.minGroupTriangles)return e;let r=Math.max(1,Math.floor(o*n.ratio));if(r>=o)return e;let i=0;for(let s=0;s<n.maxPasses&&t.activeCount>r;s+=1){let a=Xp(t,n);if(a.length===0)break;let c=0;for(let l of a){if(t.activeCount<=r)break;let u=zp(t,l,n);if(!u)continue;let f=t.activeCount;$p(t,l,u),!(t.activeCount>=f)&&(i+=1,c+=1)}if(c===0)break}return i===0||t.activeCount>=o?e:Yp(t).map(s=>({...s.polygon,vertices:[[...t.vertices[s.a]],[...t.vertices[s.b]],[...t.vertices[s.c]]]}))}function Wp(e){let n=new Map;for(let t=0;t<e.length;t+=1){let o=e[t];if(!Sp(o))continue;let r=Ap(o),i=n.get(r);i?(i.indices.push(t),i.polygons.push(o)):n.set(r,{indices:[t],polygons:[o]})}return n}function ar(e,n){let t=Pp(n),o=Wp(e);if(o.size===0)return e;let r=new Map,i=!1;for(let a of o.values()){let c=jp(a.polygons,t);if(!(c===a.polygons||c.length>=a.polygons.length)){r.set(a.indices[0],c);for(let l=1;l<a.indices.length;l+=1)r.set(a.indices[l],[]);i=!0}}if(!i)return e;let s=[];for(let a=0;a<e.length;a+=1){let c=r.get(a);c?s.push(...c):c===void 0&&s.push(e[a])}return s}var Hp=3,Kp=.03,Zp=.02,to={maxAngleDeg:Hp,maxPlaneDisplacement:Kp,maxBoundaryDisplacement:Zp,isolatedPairs:!1},cr={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},Ps=[{...cr,maxAngleDeg:30},{...cr,maxAngleDeg:45},{...cr,maxAngleDeg:60,maxBoundaryDisplacement:.06}],qp=1800,Qp=.65,Ll=500,wl=2200,Jp=1e3,eg=2200,ng=350,tg=700,og=60,rg=.06,ig=4,sg=.003,ag=4e3,cg=3e3,lg=4500,ug=2400,fg=4200,mg=1800,dg=5e3,pg=.28,gg=.15,hg=.23,yg=2e3,bg=16,xg=4e3,Pg=900,Mg=16,Sg=1.5,Ss=.045,Ag=.999,Cg=1e-5,Tg=24,Eg=50,vg=1e3,Ig=1e3,Zn={minGroupPolygons:2,maxCandidateAxes:24},_g={...Zn,maxCandidateAxes:1},Nl={...Zn,maxCandidateAxes:2},Vg={...Zn,maxCandidateAxes:2},Og={steps:[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"},{kind:"finalLossyCandidates"}]};function zl(e,n={}){return Rg(e,n).polygons}function Ul(e,n={}){let t={meshResolution:n.meshResolution,stopAtPolygonCount:n.stopAtPolygonCount,rectCover:n.rectCover},o=new lr,r={captureVisiblePolygons:!0,skipInteriorCull:n.skipInteriorCull===!0};return o.workspaceFor(e,r).createRun(t,r).optimizeParse({staticSimplification:n.staticSimplification,useCandidateFirst:n.useCandidateFirst===!0}).polygons}function Rg(e,n={},t={}){return new lr().workspaceFor(e,t).createRun(n,t).optimize()}var lr=class{constructor(){this.workspaces=new Map}workspaceFor(n,t){let o=Lg(t),r=this.workspaces.get(o);r||(r=new WeakMap,this.workspaces.set(o,r));let i=r.get(n);return i||(i=new As(n,t,this),r.set(n,i)),i}};function Lg(e){return[e.skipInteriorCull===!0?"skip-cull":"cull",e.simplifiedCandidate===!0?"simplified":"source"].join(":")}var As=class{constructor(n,t,o){this.source=n,this.graph=o,this.preprocessCache={skipInteriorCull:t.skipInteriorCull===!0}}polygons(){return this.source}preprocess(n){return o0(this.source,n,this.preprocessCache)}configureSnappedCullReuse(n,t){let o=n.length/Math.max(1,this.source.length);this.preprocessCache.reuseSnappedInteriorCull=t.simplifiedCandidate===!0?this.source.length<=fg:n.length<=mg||n.length<=dg&&o>=pg}visiblePolygons(){return this.preprocessCache.interior??this.preprocessCache.deduped??this.source}createRun(n,t){return new Cs(this,n,t)}workspaceFor(n,t){return this.graph.workspaceFor(n,t)}},Cs=class e{constructor(n,t,o,r={}){this.baselineCandidatesComplete=!1;this.initialLossyCandidatesComplete=!1;this.finalLossyCandidatesComplete=!1;this.workspace=n,this.source=n.polygons(),this.options=t,this.runOptions=o,this.costCandidateMode=r.costCandidateMode??"cost",this.seamCandidateMode=r.seamCandidateMode??"seamSafe",this.offerBaseline=r.offerBaseline===!0,this.meshResolution=t.meshResolution??"lossy",this.stopAtPolygonCount=Number.isFinite(t.stopAtPolygonCount)?Math.max(0,Math.floor(t.stopAtPolygonCount)):void 0,this.requiredMaxPolygonCount=Number.isFinite(o.requiredMaxPolygonCount)?Math.max(0,Math.floor(o.requiredMaxPolygonCount)):void 0,this.baseline=this.preprocess(!1),this.workspace.configureSnappedCullReuse(this.baseline,o),this.visiblePolygons=o.captureVisiblePolygons?this.workspace.visiblePolygons():void 0,this.acceptor=r.acceptor??new Ts(this.baseline,this.requiredMaxPolygonCount)}optimize(){return this.runPlan(Og)}optimizeParse(n){let t=n.staticSimplification===!1?null:n.staticSimplification??{},o=[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"}];return n.useCandidateFirst||o.push({kind:"finalLossyCandidates"}),t&&o.push({kind:"staticSimplificationCandidates",options:t,stopOnAccept:n.useCandidateFirst}),n.useCandidateFirst&&o.push({kind:"finalLossyCandidates"}),this.runPlan({steps:o})}get best(){return this.acceptor.polygons}get bestCost(){return this.acceptor.cost}runStaticSimplificationCandidates(n={}){if(this.meshResolution!=="lossy"||!Hg(this.source,this.best))return!1;let t=$l(this.source,n);if(!t)return!1;for(let o of this.staticSimplificationPlans(t)){let r=Kg(o,n);if(r&&this.generateStaticSimplificationCandidate(r,n,o.skipInteriorCull))return!0}return!1}staticSimplificationPlans(n){let t=this.source.length-n.length,o=[],r=this.visiblePolygons&&this.visiblePolygons!==this.source?this.source.length-this.visiblePolygons.length:0;return this.visiblePolygons&&this.visiblePolygons!==this.source&&this.source.length>=xg&&r>=Pg&&(t<=Mg||r>=t*Sg)&&o.push({source:this.visiblePolygons,skipInteriorCull:!0}),this.best.length>=yg&&t<=bg&&Wg(this.source)&&o.push({source:this.source,vertexKeyMode:"source"}),o.push({source:this.source,precomputed:n}),o}generateStaticSimplificationCandidate(n,t,o=!1){let r={requiredMaxPolygonCount:this.best.length-1,skipExactRectCover:!0,skipInteriorCull:o,simplifiedCandidate:!0},i=this.workspace.workspaceFor(n,r),s=this.best;return new e(i,{meshResolution:"lossy",stopAtPolygonCount:jg(this.best.length,t)},r,{acceptor:this.acceptor,costCandidateMode:"dom",seamCandidateMode:"dom",offerBaseline:!0}).optimize(),this.best!==s}runPlan(n){for(let t of n.steps){let o=!1;if(t.kind==="baselineCandidates")this.runBaselineCandidates();else if(t.kind==="staticSimplificationCandidates")o=this.runStaticSimplificationCandidates(t.options)&&t.stopOnAccept;else{if(!this.shouldRunLossyPipeline())break;t.kind==="initialLossyCandidates"?this.runInitialLossyPipeline():this.runFinalLossyPipeline()}if(o||this.shouldStop())break}return this.result()}runBaselineCandidates(){if(this.baselineCandidatesComplete||(this.baselineCandidatesComplete=!0,this.offerBaseline&&(this.acceptCandidate(this.baseline),this.shouldStop())))return;let n=this.runOptions.skipExactRectCover===!0?!1:this.meshResolution==="lossy"&&this.options.rectCover===void 0?qg(this.baseline):this.options.rectCover;if(this.shouldStop())return;let t=Kn(this.baseline,n);if(t!==this.baseline&&this.acceptCandidate(t),!this.shouldStop()&&this.meshResolution==="lossy"&&this.options.rectCover===void 0&&this.runOptions.skipExactRectCover!==!0){let o=Kn(this.baseline,void 0);o!==this.baseline&&this.acceptCandidate(o)}}shouldRunLossyPipeline(){return this.meshResolution==="lossy"&&!this.shouldStop()&&this.best.length>1&&this.bestCost>1+1e-9}runInitialLossyPipeline(){if(this.initialLossyCandidatesComplete)return;this.initialLossyCandidatesComplete=!0;let n=this.preprocess(cr);this.acceptCandidate(n),!this.shouldStop()&&(this.options.rectCover===void 0&&this.source.length>=Ll&&this.source.length<=wl&&(this.acceptCandidate(Kn(n,Nl)),this.shouldStop())||this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(this.acceptCandidate(Kn(n,this.options.rectCover)),this.shouldStop()))}runFinalLossyPipeline(){this.finalLossyCandidatesComplete||(this.finalLossyCandidatesComplete=!0,!(this.runOptions.simplifiedCandidate===!0&&this.source.length>lg)&&(this.runAggressiveLossyVariants(),!this.shouldStop()&&this.runLargeRectCoverCandidate()))}runAggressiveLossyVariants(){let n=this.stopAtPolygonCount===void 0&&this.source.length>=ag&&this.best.length<=cg,t=!1;for(let o=n?Ps.length:0;o<Ps.length;o+=1){if(o===1&&!t||o===1&&this.runOptions.simplifiedCandidate===!0&&this.source.length<ug||o===2&&!Jg(this.source))continue;let r=this.preprocess(Ps[o]),i=r;this.options.rectCover===void 0&&this.source.length>=Ll&&this.source.length<=wl&&(i=Kn(r,Nl)),this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(i=Kn(r,this.options.rectCover));let s=this.acceptSeamSafeCandidate(i,this.source.length);if(o===0&&s&&(t=!0),this.shouldStop())return}}runLargeRectCoverCandidate(){if(this.options.rectCover!==void 0)return;let n=Kn(this.best,Qg(this.best));n!==this.best&&this.acceptSeamSafeCandidate(n,this.best.length)}preprocess(n){return this.workspace.preprocess(n)}result(){return{polygons:this.best,visiblePolygons:this.visiblePolygons}}shouldStop(){return this.stopAtPolygonCount!==void 0&&this.best.length<=this.stopAtPolygonCount}acceptCandidate(n,t=qn(n)){return this.emitCandidate({mode:this.costCandidateMode,polygons:n,cost:t})}acceptDomCandidate(n){return this.emitCandidate({mode:"dom",polygons:n})}acceptSeamSafeCandidate(n,t,o){return this.emitCandidate({mode:this.seamCandidateMode,polygons:n,sourcePolygonCount:t,cost:o})}emitCandidate(n){return this.acceptor.accept({...n,maxPolygonCount:n.maxPolygonCount??this.requiredMaxPolygonCount})}},Ts=class{constructor(n,t){this.best=n,this.bestCost=qn(n),this.bestDiagnostics={polygons:n},this.requiredMaxPolygonCount=t}get polygons(){return this.best}get cost(){return this.bestCost}accept(n){return n.mode==="cost"?this.acceptCostCandidate(n.polygons,n.cost):n.mode==="dom"?this.acceptDomCandidate(n.polygons,n.cost,n.maxPolygonCount):this.acceptSeamSafeCandidate(n.polygons,n.sourcePolygonCount??n.polygons.length,n.cost,n.maxPolygonCount)}acceptCostCandidate(n,t=qn(n)){return t>=this.bestCost?!1:(this.commit(n,t),!0)}acceptDomCandidate(n,t=qn(n),o){return n.length>=this.best.length||!this.withinMaxPolygonCount(n,o)?!1:(this.commit(n,t),!0)}acceptSeamSafeCandidate(n,t,o,r){if(n.length>=this.best.length||!this.withinMaxPolygonCount(n,r))return!1;let i=Yg(t);if(this.bestCost-n.length<i)return!1;let s=o??qn(n),a=this.bestCost-s;if(a<=0||a<i)return!1;let c=Dl(n);if(!c)return!1;let l=this.bestSeamDiagnostics();return!l||wg(c,l)||Ng(this.bestTopologyEdges(),this.bestTopologySelfDiagnostics(),n)?!1:(this.commit(n,s,c),!0)}withinMaxPolygonCount(n,t){let o=t??this.requiredMaxPolygonCount;return o===void 0||n.length<=o}commit(n,t,o){this.best=n,this.bestCost=t,this.bestDiagnostics={polygons:n,seam:o}}resetBestDiagnostics(n){this.bestDiagnostics={polygons:this.best,seam:n}}bestSeamDiagnostics(){if(this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),!this.bestDiagnostics.seam){let n=Dl(this.best);if(!n)return null;this.bestDiagnostics.seam=n}return this.bestDiagnostics.seam}bestTopologyEdges(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologyEdges||(this.bestDiagnostics.topologyEdges=Gl(this.best)),this.bestDiagnostics.topologyEdges}bestTopologySelfDiagnostics(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologySelf||(this.bestDiagnostics.topologySelf=kg(this.bestTopologyEdges(),Ss)),this.bestDiagnostics.topologySelf}};function qn(e){let n=0;for(let t of e){let o=t.vertices.length,r=o<=4?0:Math.min(4,o-4)*.12,i=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+r+i}return n}function Dl(e){try{return vl(e)}catch(n){if(n instanceof RangeError&&n.message==="Set maximum size exceeded")return null;throw n}}function wg(e,n){return e.nearPairs>n.nearPairs||e.unclosedPairs>n.unclosedPairs||e.maxMeasuredGapPx>n.maxMeasuredGapPx+1e-9||e.maxResidualGapPx>n.maxResidualGapPx+1e-9}function Ng(e,n,t){let o=Gl(t);return Dg(e,o,Ss)?!0:Bg(o.boundarySegments,Ss,n)}function Dg(e,n,t){if(e.internalSegments.length===0)return!1;let o=Fg(e,t);for(let r of n.boundarySegments)if(!e.boundaryKeys.has(r.key)&&(e.internalKeys.has(r.key)||$g(r,o,t)))return!0;return!1}function Fg(e,n){return(!e.internalIndex||e.internalIndexTolerance!==n)&&(e.internalIndex=Is(e.internalSegments,n),e.internalIndexTolerance=n),e.internalIndex}function Bg(e,n,t){let o=Is(e,n),r=new Set,i=0,s=0,a=0;for(let c of e)i=Math.max(i,c.index+1);for(let c of e)for(let l of _s(c,o,n)){if(l===c||l.polygon===c.polygon||l.key===c.key)continue;let u=c.index<l.index?c.index*i+l.index:l.index*i+c.index;if(r.has(u))continue;r.add(u);let f=Vs(c,l,n);if(f&&(s+=1,a+=f.overlapLength,s>t.tJunctionPairs||a>t.tJunctionLength+1e-9))return!0}return!1}function kg(e,n){let t={tJunctionPairs:0,tJunctionLength:0};return zg(t,e.boundarySegments,n),t}function zg(e,n,t){let o=Is(n,t),r=new Set,i=0;for(let s of n)i=Math.max(i,s.index+1);for(let s of n)for(let a of _s(s,o,t)){if(a===s||a.polygon===s.polygon||a.key===s.key)continue;let c=s.index<a.index?s.index*i+a.index:a.index*i+s.index;if(r.has(c))continue;r.add(c);let l=Vs(s,a,t);l&&(e.tJunctionPairs+=1,e.tJunctionLength+=l.overlapLength)}}function Gl(e){let n=new Map;for(let c=0;c<e.length;c+=1){let l=e[c].vertices;for(let u=0;u<l.length;u+=1){let f=l[u],d=l[(u+1)%l.length],m=Ug(io(f,d),c,u,f,d);if(!m)continue;let p=n.get(m.key);p?p.count+=1:n.set(m.key,{count:1,segment:m})}}let t=new Set,o=new Set,r=[],i=[],s=0,a=0;for(let c of n.values()){let l={...c.segment,index:a};a+=1,c.count===1?(t.add(l.key),r.push(l),s+=l.length):(o.add(l.key),i.push(l))}return{boundaryKeys:t,internalKeys:o,boundarySegments:r,internalSegments:i,boundaryLength:s}}function Ug(e,n,t,o,r){let i=_n(r,o),s=Math.hypot(i[0],i[1],i[2]);if(s<=1e-10)return null;let a=[i[0]/s,i[1]/s,i[2]/s];return{index:-1,key:e,polygon:n,edge:t,a:o,b:r,dir:a,length:s,minX:Math.min(o[0],r[0]),minY:Math.min(o[1],r[1]),minZ:Math.min(o[2],r[2]),maxX:Math.max(o[0],r[0]),maxY:Math.max(o[1],r[1]),maxZ:Math.max(o[2],r[2])}}function Is(e,n){let t=Math.max(n*8,.5),o=new Map;for(let r of e)Gg(o,r,t,n);return{cellSize:t,cells:o}}function Gg(e,n,t,o){let[r,i,s]=ur([n.minX-o,n.minY-o,n.minZ-o],t),[a,c,l]=ur([n.maxX+o,n.maxY+o,n.maxZ+o],t);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function ur(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function _s(e,n,t){let o=[],r=new Set,[i,s,a]=ur([e.minX-t,e.minY-t,e.minZ-t],n.cellSize),[c,l,u]=ur([e.maxX+t,e.maxY+t,e.maxZ+t],n.cellSize);for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1)for(let m=a;m<=u;m+=1){let p=n.cells.get(`${f},${d},${m}`);if(p)for(let g of p)r.has(g)||(r.add(g),o.push(g))}return o}function $g(e,n,t){for(let o of _s(e,n,t))if(Vs(e,o,t))return!0;return!1}function Vs(e,n,t){if(!Xg(e,n,t)||Math.abs(on(e.dir,n.dir))<Ag)return null;let o=on(_n(n.a,e.a),e.dir),r=on(_n(n.b,e.a),e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i;if(a<=Math.max(Cg,Math.min(e.length,n.length)*1e-4))return null;let c=[e.a[0]+e.dir[0]*((i+s)/2),e.a[1]+e.dir[1]*((i+s)/2),e.a[2]+e.dir[2]*((i+s)/2)],l=Math.max(0,Math.min(n.length,on(_n(c,n.a),n.dir))),u=[n.a[0]+n.dir[0]*l,n.a[1]+n.dir[1]*l,n.a[2]+n.dir[2]*l],f=ou(c,u);return f<=t?{overlapLength:a,offset:f}:null}function Xg(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function Yg(e){return Math.max(ig,e*sg)}function jg(e,n){let t=Number.isFinite(n.earlyStopDropRatio)?Math.max(0,n.earlyStopDropRatio):gg;return Math.max(0,e-Math.max(1,Math.ceil(e*t)))}function Wg(e){return e.some(n=>n.simplifySourceVertexKeys?.length===n.vertices.length)}function Hg(e,n){return e.length===0||n.length/e.length>hg}function $l(e,n,t){let o=ar(e,{...n.simplifyTriangleMeshOptions,...t?{vertexKeyMode:t}:{}});return o===e||o.length>=e.length?null:o}function Kg(e,n){return e.precomputed!==void 0?e.precomputed:$l(e.source,n,e.vertexKeyMode)}function Kn(e,n){if(n===!1)return e;let t=Zg(e,n);if(!t)return e;let o=Zo(e,t);return o.length<e.length?o:e}function Zg(e,n){if(n&&n!==!0)return n;let t=n===!0,o=e.length;return o>2200||!t&&o>=Tg&&o<Eg||!t&&o>vg?null:!t&&o<=300?{...Zn,maxCandidateAxes:1}:o>300?!t&&(Xl(e)>12||Yl(e)>Ig)?null:{...Zn,maxCandidateAxes:Math.min(Zn.maxCandidateAxes??24,2)}:Zn}function qg(e){return e.length>qp||e.length===0||e0(e)/e.length<Qp?!1:_g}function Qg(e){return e.length<Jp||e.length>eg||Xl(e)<=12||Yl(e)>ng?!1:Vg}function Jg(e){return e.length<=tg}function e0(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function Xl(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function Yl(e){let n=new Map;for(let o of e)for(let r=0;r<o.vertices.length;r++){let i=o.vertices[r],s=o.vertices[(r+1)%o.vertices.length],a=io(i,s);n.set(a,(n.get(a)??0)+1)}let t=0;for(let o of n.values())o===1&&(t+=1);return t}function fr(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function Es(e,n){if(n===e||n.length===e.length&&n.every((r,i)=>r===e[i]))return null;let t=new Set(n),o=[];for(let r=0;r<e.length;r++)t.has(e[r])&&o.push(r);return o.length===e.length?null:o}function n0(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let r=jt(e);if(r.size===0)t=null;else{t=[];for(let i=0;i<e.length;i++)r.has(i)||t.push(i)}n&&(n.dedupedIndices=t)}let o=fr(e,t);return n&&(n.deduped=o),o}function t0(e,n){if(n?.skipInteriorCull)return e;if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let r=hn(e);t=Es(e,r),n&&(n.interiorIndices=t)}let o=fr(e,t);return n&&(n.interior=o),o}function o0(e,n,t){let o=n0(e,t),r=t0(o,t),i=t?.baseline??sn(r);if(t&&!t.baseline&&(t.baseline=i),!n)return i;let s=n===!0?to:i0(n);if(s.isolatedPairs){let u=Bl(Fl(o,t),s,t),f=sn(u);if(t?.snappedInteriorUsesBaselineFilter&&r0(i,f)){let d=Bl(Fl(o,t,!0),s,t),m=sn(d);m.length<f.length&&(f=m)}return f.length<i.length?f:i}let a=b0(o,s,t),c=hn(a),l=sn(c);return l.length<i.length?l:i}function jl(e,n){return n?(n.snapped||(n.snapped=mr(e)),n.snapped):mr(e)}function Fl(e,n,t=!1){if(!n)return hn(mr(e));if(t&&n.snappedInteriorExact)return n.snappedInteriorExact;if(!t&&n.snappedInterior)return n.snappedInterior;let o=jl(e,n);if(t){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorExactIndices=n.interiorIndices,n.snappedInteriorExact=n.interior,n.snappedInteriorExact;let r=hn(o);return n.snappedInteriorExactIndices=Es(o,r),n.snappedInteriorExact=r,n.snappedInteriorExact}if(!n.snappedInterior){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=n.interior,n.snappedInteriorUsesBaselineFilter=!1,n.snappedInterior;if(n.reuseSnappedInteriorCull!==!1&&n.interiorIndices!==void 0)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=fr(o,n.snappedInteriorIndices),n.snappedInteriorUsesBaselineFilter=!0,n.snappedInterior;if(n.snappedInteriorIndices===void 0){let r=hn(o);n.snappedInteriorIndices=Es(o,r),n.snappedInterior=r,n.snappedInteriorExactIndices=n.snappedInteriorIndices,n.snappedInteriorExact=r,n.snappedInteriorUsesBaselineFilter=!1}else n.snappedInterior=fr(o,n.snappedInteriorIndices)}return n.snappedInterior}function r0(e,n){return n.length>=e.length}function i0(e){return{maxAngleDeg:e.maxAngleDeg??to.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??to.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??to.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??to.isolatedPairs}}function Bl(e,n,t){let o=s0(e,t),r=[];for(let s of a0(e,o))c0(s,n)&&r.push(s.candidate);let i=u0(r);return i.length===0?e:l0(e,i)}function s0(e,n){if(n?.trianglePairSource?.polygons===e)return n.trianglePairSource;let t=e.map(s=>{let a=Rs(s);return a?{polygon:s,normal:a.normal,area:a.area,materialKey:Ql(s)}:null}),o=new Map;for(let s=0;s<e.length;s++){let a=e[s];if(!(a.vertices.length!==3||!t[s]))for(let c=0;c<a.vertices.length;c++){let l=io(a.vertices[c],a.vertices[(c+1)%a.vertices.length]),u=o.get(l);u?u.push(s):o.set(l,[s])}}let r=[];for(let s of o.values())s.length===2&&r.push([s[0],s[1]]);let i={polygons:e,metas:t,edgeOwnerPairs:r};return n&&(n.trianglePairSource=i),i}function a0(e,n){if(n.preparedCandidates)return n.preparedCandidates;let t=[];for(let[o,r]of n.edgeOwnerPairs){let i=g0(o,r,e,n.metas);i&&t.push(i)}return n.preparedCandidates=t,t}function c0(e,n){let t=Math.cos(n.maxAngleDeg*Math.PI/180);return e.normalDot>=t&&e.maxDistance<=Math.min(n.maxPlaneDisplacement,n.maxBoundaryDisplacement)}function l0(e,n){let t=new Map,o=new Set,r=Wl(n.flatMap(s=>s.vertexMoves));for(let s of n){let a=Math.min(s.a,s.b);t.set(a,s.polygon),o.add(Math.max(s.a,s.b))}let i=[];for(let s=0;s<e.length;s++){let a=t.get(s);if(a){i.push(a);continue}o.has(s)||i.push(e[s])}return r.size>0?Hl(i,r):i}function u0(e){return e.length>3e3?f0(e):m0(e)}function f0(e){let n=new Map;for(let i of e)n.set(i.a,(n.get(i.a)??0)+1),n.set(i.b,(n.get(i.b)??0)+1);let t=[...e].sort((i,s)=>{let a=(n.get(i.a)??0)+(n.get(i.b)??0),c=(n.get(s.a)??0)+(n.get(s.b)??0);return a-c||i.score-s.score}),o=new Set,r=[];for(let i of t)o.has(i.a)||o.has(i.b)||(o.add(i.a),o.add(i.b),r.push(i));return r}function m0(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],f=n.get(u.a);f?f.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let t=[],o=new Array(e.length).fill(!0),r=new Map,i=new vs;for(let[l,u]of n)r.set(l,u.length);let s=l=>(r.get(l.a)??0)+(r.get(l.b)??0),a=l=>{let u=e[l];i.push({degree:s(u),score:u.score,index:l})},c=(l,u)=>{if(!o[l])return;o[l]=!1;let f=e[l];for(let d of[f.a,f.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)a(l);for(;i.size()>0;){let l=i.pop();if(!o[l.index])continue;let u=e[l.index];if(s(u)!==l.degree){a(l.index);continue}t.push(u);let d=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])c(p,d);for(let m of d)for(let p of n.get(m)??[])o[p]&&a(p)}return t}var vs=class{constructor(){this.items=[]}size(){return this.items.length}push(n){this.items.push(n);let t=this.items.length-1;for(;t>0;){let o=t-1>>1;if(Ms(this.items[o],this.items[t])<=0)break;[this.items[o],this.items[t]]=[this.items[t],this.items[o]],t=o}}pop(){if(this.items.length===0)return null;let n=this.items[0],t=this.items.pop();if(this.items.length>0){this.items[0]=t;let o=0;for(;;){let r=o*2+1,i=r+1,s=o;if(r<this.items.length&&Ms(this.items[r],this.items[s])<0&&(s=r),i<this.items.length&&Ms(this.items[i],this.items[s])<0&&(s=i),s===o)break;[this.items[o],this.items[s]]=[this.items[s],this.items[o]],o=s}}return n}};function Ms(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function Wl(e){let n=new Map;for(let o of e){let r=n.get(o.key);r?(r.x+=o.target[0],r.y+=o.target[1],r.z+=o.target[2],r.count+=1):n.set(o.key,{x:o.target[0],y:o.target[1],z:o.target[2],count:1})}let t=new Map;for(let[o,r]of n)t.set(o,[r.x/r.count,r.y/r.count,r.z/r.count]);return t}function d0(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o].vertices,i=n[o]?.vertices;if(!i||i.length!==r.length)continue;for(let c=0;c<r.length;c++)t.push({key:ln(r[c]),target:i[c]});let s=e[o].textureTriangles??[],a=n[o]?.textureTriangles??[];for(let c=0;c<s.length;c++){let l=a[c];if(l)for(let u=0;u<s[c].vertices.length;u++)t.push({key:ln(s[c].vertices[u]),target:l.vertices[u]})}}return t}function p0(e,n){let t=[];for(let o of e)for(let r of o.textureTriangles??[])for(let i of r.vertices)t.push({key:ln(i),target:Ds(i,n)});return t}function Hl(e,n){return e.map(t=>{let o=!1,r=a=>{let c=n.get(ln(a));return c?(o=!0,c):a},i=t.vertices.map(r),s=Os(t.textureTriangles,r);return o?{...t,vertices:i,...s?{textureTriangles:s}:{}}:t})}function g0(e,n,t,o){let r=t[e],i=t[n],s=o[e],a=o[n];if(!s||!a||r.vertices.length!==3||i.vertices.length!==3||!V0(r,i,s,a))return null;let c=ws(r,i);if(!c)return null;let[l,u,f,d]=c;if((f+1)%i.vertices.length===d)return null;let p=Math.abs(on(s.normal,a.normal)),g=Math.cos(og*Math.PI/180);if(p<g)return null;let h=(u+1)%r.vertices.length,y=3-f-d,b=[r.vertices[u],r.vertices[h],r.vertices[l],i.vertices[y]],x=h0(b);if(!x)return null;let P=0,M=0;for(let S of b){let T=Math.abs(Ns(S,x));P=Math.max(P,T),M+=T*T}if(P>rg)return null;let C=b.map(S=>Ds(S,x));if(!y0(C,x.normal))return null;let E=Rs({vertices:C});if(!E||on(E.normal,s.normal)<.2||on(E.normal,a.normal)<.2)return null;let A={vertices:b,color:r.color,...r.doubleSided?{doubleSided:!0}:{},...r.data?{data:{...r.data}}:{}};if(Ls(r,i)&&r.uvs&&i.uvs&&r.texture){A.texture=r.texture,r.textureWrap&&(A.textureWrap={...r.textureWrap}),r.textureAlphaMode&&(A.textureAlphaMode=r.textureAlphaMode),A.uvs=[[...r.uvs[u]],[...r.uvs[h]],[...r.uvs[l]],[...i.uvs[y]]];let S=x0([r,i]);S?.length&&(A.textureTriangles=S)}return{normalDot:p,maxDistance:P,candidate:{a:e,b:n,polygon:A,vertexMoves:[...b.map((S,T)=>({key:ln(S),target:C[T]})),...p0([r,i],x)],score:M/b.length+P*.25+(1-p)*.1}}}function h0(e){if(e.length<3)return null;let n=0,t=0,o=0,r=0,i=0,s=0;for(let c=0;c<e.length;c++){let l=e[c],u=e[(c+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),t+=(l[2]-u[2])*(l[0]+u[0]),o+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],i+=l[1],s+=l[2]}let a=ru([n,t,o]);return a?{normal:a,point:[r/e.length,i/e.length,s/e.length]}:null}function y0(e,n){let t=0;for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=e[(o+2)%e.length],a=on(tu(_n(i,r),_n(s,i)),n);if(Math.abs(a)<=1e-9)continue;let c=a>0?1:-1;if(t===0)t=c;else if(t!==c)return!1}return!0}function b0(e,n,t){let o=jl(e,t),r=T0(o,n);if(r<=0)return o;let i=o.map(m=>{let p=Rs(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Ql(m)}:null}),s=I0(o,i),a=new Set,c=Array(o.length),l=[],u=(m,p)=>{c[m]=p};for(let m=0;m<o.length;m++){let p=i[m];if(a.has(m))continue;if(!p){u(m,o[m]);continue}let g=O0(m,i,s,a,r,n);for(let y of g)a.add(y);if(g.length<2){u(m,o[m]);continue}let h=S0(g,o,i,s,r,n);l.push(...h.vertexMoves);for(let y of g)u(y,h.polygons.get(y)??o[y])}let f=c.flatMap(m=>m?[m]:[]),d=l.length>0?Hl(f,Wl(l)):f;return mr(d)}function mr(e){let n=ql(e),t=1e-4;if(n<=0)return e;let o=E0(n),r=v0(t),i=!1,s=e.map(a=>{let c=!1,l=p=>{let g=o.snap(p);return oo(g,p)||(c=!0),g},u=a.vertices.map(l),f=a.uvs&&a.uvs.length===a.vertices.length?a.uvs.map(p=>{let g=r.snap(p);return ro(g,p)||(c=!0),g}):void 0,d=Os(a.textureTriangles,l);if(!c&&!a.texture)return a;let m={...a,vertices:u,...f?{uvs:f}:{},...d?{textureTriangles:d}:{}};return i=!0,{...m,...m.texture?{textureTriangles:Kl(m)}:{}}});return i?s:e}function Kl(e){if(e.texture){if(e.textureTriangles?.length)return M0(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return P0(e.vertices,e.uvs)}}function x0(e){let n=e.flatMap(t=>Kl(t)??[]);return n.length>0?n:void 0}function P0(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function M0(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Os(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(o=>[...o])}))}function S0(e,n,t,o,r,i){let s=Zl(e,n,t,r,i);return s?C0(s):A0(e,n,t,o,r,i)}function A0(e,n,t,o,r,i){let s=new Set(e),a=[];for(let f of e)for(let d of o.get(f)??[]){if(f>=d||!s.has(d))continue;let m=Zl([f,d],n,t,r,i);m&&a.push(m)}a.sort((f,d)=>d.score-f.score);let c=new Set,l=new Map,u=[];for(let f of a)if(!f.indices.some(d=>c.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];c.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function C0(e){let n=new Map;for(let t=0;t<e.indices.length;t++)n.set(e.indices[t],e.source[t]);return{polygons:n,vertexMoves:e.vertexMoves}}function Zl(e,n,t,o,r){let i=Jl(e,t);if(!i||!eu(e,t,i,o,r))return null;let s=e.map(u=>n[u]),a=s.map(u=>w0(u,i)),c=qn(sn(s)),l=qn(sn(a));return l>=c?null:{indices:e,source:s,projected:a,vertexMoves:d0(s,a),score:c-l}}function T0(e,n){return ql(e)<=0?0:n.maxPlaneDisplacement}function ql(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let c of e)for(let[l,u,f]of c.vertices)n=Math.min(n,l),t=Math.min(t,u),o=Math.min(o,f),r=Math.max(r,l),i=Math.max(i,u),s=Math.max(s,f);if(!Number.isFinite(n))return 0;let a=Math.hypot(r-n,i-t,s-o);return a<=0?0:Math.min(.025,Math.max(1e-4,a*25e-5))}function E0(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i,s)=>`${r},${i},${s}`;return{snap(r){let i=t(r[0]),s=t(r[1]),a=t(r[2]);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)for(let m=-1;m<=1;m++){let p=n.get(o(i+f,s+d,a+m));if(p){for(let g of p)if(ou(r,g)<=e)return[g[0],g[1],g[2]]}}let c=[r[0],r[1],r[2]],l=o(i,s,a),u=n.get(l);return u?u.push(c):n.set(l,[c]),c}}}function v0(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i)=>`${r},${i}`;return{snap(r){let i=t(r[0]),s=t(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(o(i+u,s+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 a=[r[0],r[1]],c=o(i,s),l=n.get(c);return l?l.push(a):n.set(c,[a]),a}}}function Ql(e){return[e.color??"#cccccc",e.texture??"",e.texture&&e.textureWrap?`${e.textureWrap.s}/${e.textureWrap.t}`:"",e.texture&&e.textureAlphaMode?e.textureAlphaMode:"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided"].join("|")}function Rs(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0,i=n[0];for(let a=1;a<n.length-1;a++){let c=_n(n[a],i),l=_n(n[a+1],i),u=tu(c,l);t+=u[0],o+=u[1],r+=u[2]}let s=Math.hypot(t,o,r);return s<=1e-10?null:{normal:[t/s,o/s,r/s],area:s/2}}function I0(e,n){let t=new Map,o=new Map;for(let r=0;r<e.length;r++){let i=e[r];if(!(!n[r]||i.vertices.length<3))for(let s=0;s<i.vertices.length;s++){let a=io(i.vertices[s],i.vertices[(s+1)%i.vertices.length]),c=t.get(a);c?c.push(r):t.set(a,[r])}}for(let r of t.values())for(let i=0;i<r.length;i++)for(let s=i+1;s<r.length;s++){let a=r[i],c=r[s];_0(e[a],e[c],n[a],n[c])&&(kl(o,a,c),kl(o,c,a))}return o}function _0(e,n,t,o){if(!t||!o||t.materialKey!==o.materialKey||!!e.uvs!=!!n.uvs)return!1;if(dr(e)||dr(n))return Ls(e,n);if(!e.uvs||!n.uvs)return!0;let r=ws(e,n);if(!r)return!1;let[i,s,a,c]=r;return ro(e.uvs[i],n.uvs[a])&&ro(e.uvs[s],n.uvs[c])}function V0(e,n,t,o){return t.materialKey!==o.materialKey?!1:dr(e)||dr(n)?Ls(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function dr(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Ls(e,n){if(!e.texture||!n.texture||e.texture!==n.texture||(e.textureWrap?.s??"")!==(n.textureWrap?.s??"")||(e.textureWrap?.t??"")!==(n.textureWrap?.t??"")||(e.textureAlphaMode??"")!==(n.textureAlphaMode??"")||e.material?.texture||n.material?.texture||!e.uvs||!n.uvs||e.uvs.length!==e.vertices.length||n.uvs.length!==n.vertices.length)return!1;let t=ws(e,n);if(!t)return!1;let[o,r,i,s]=t;return ro(e.uvs[o],n.uvs[i])&&ro(e.uvs[r],n.uvs[s])}function kl(e,n,t){let o=e.get(n);o?o.add(t):e.set(n,new Set([t]))}function O0(e,n,t,o,r,i){let s=[e],a=new Set([e]),c=[e];for(;c.length>0;){let l=c.shift();for(let u of t.get(l)??[]){if(o.has(u)||a.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&R0([...s,u],n,r,i)&&(s.push(u),a.add(u),c.push(u))}}return s}function R0(e,n,t,o){let r=Jl(e,n);return!!r&&eu(e,n,r,t,o)}function Jl(e,n){let t=n[e[0]];if(!t)return null;let o=0,r=0,i=0,s=0,a=0,c=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let g=on(t.normal,p.normal)<0?-1:1,h=Math.max(p.area,1e-6);o+=p.normal[0]*g*h,r+=p.normal[1]*g*h,i+=p.normal[2]*g*h;for(let y of p.polygon.vertices)s+=y[0],a+=y[1],c+=y[2],l+=1}let u=ru([o,r,i]);if(!u||l===0)return null;let f=nu(e,n),d=L0(e,n,u,f);if(d){let m=(d.min+d.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m],boundaryVertexKeys:f}}return{normal:u,point:[s/l,a/l,c/l],boundaryVertexKeys:f}}function L0(e,n,t,o){let r=1/0,i=-1/0;for(let s of e){let a=n[s];if(a)for(let c of a.polygon.vertices){if(!o.has(ln(c)))continue;let l=on(c,t);r=Math.min(r,l),i=Math.max(i,l)}}return Number.isFinite(r)&&Number.isFinite(i)?{min:r,max:i}:null}function eu(e,n,t,o,r){let i=Math.cos(r.maxAngleDeg*Math.PI/180),s=t.boundaryVertexKeys??nu(e,n);for(let a of e){let c=n[a];if(!c||Math.abs(on(c.normal,t.normal))<i)return!1;for(let l of c.polygon.vertices){let u=s.has(ln(l))?r.maxBoundaryDisplacement:o;if(Math.abs(Ns(l,t))>u)return!1}}return!0}function nu(e,n){let t=new Map;for(let r of e){let i=n[r];if(!i)continue;let s=i.polygon.vertices;for(let a=0;a<s.length;a++){let c=s[a],l=s[(a+1)%s.length],u=io(c,l),f=t.get(u);f?f.count+=1:t.set(u,{count:1,a:c,b:l})}}let o=new Set;for(let r of t.values())r.count===1&&(o.add(ln(r.a)),o.add(ln(r.b)));return o}function w0(e,n){let t=r=>Ds(r,n),o=Os(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...o?{textureTriangles:o}:{}}}function ws(e,n){for(let t=0;t<e.vertices.length;t++){let o=(t+1)%e.vertices.length;for(let r=0;r<n.vertices.length;r++){let i=(r+1)%n.vertices.length;if(oo(e.vertices[t],n.vertices[r])&&oo(e.vertices[o],n.vertices[i]))return[t,o,r,i];if(oo(e.vertices[t],n.vertices[i])&&oo(e.vertices[o],n.vertices[r]))return[t,o,i,r]}}return null}function io(e,n){let t=ln(e),o=ln(n);return t<o?`${t}|${o}`:`${o}|${t}`}function ln(e){return`${e[0]},${e[1]},${e[2]}`}function oo(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function ro(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function _n(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function tu(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 on(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function ou(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function ru(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 Ns(e,n){return on(_n(e,n.point),n.normal)}function Ds(e,n){let t=Ns(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var N0=36,D0=.15,F0=.2,B0=650,k0=15e3,z0=.25;function Fs(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function iu(e){let n=Tn(e);return!n||n.alpha<1?e.trim().toLowerCase():`#${n.rgb.map(t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")).join("")}`}function U0(e){let n=Tn(e);return n?{rgb:[Math.max(0,Math.min(255,Math.round(n.rgb[0]))),Math.max(0,Math.min(255,Math.round(n.rgb[1]))),Math.max(0,Math.min(255,Math.round(n.rgb[2])))],alpha:n.alpha}:null}function G0(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function su(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),i=Math.min(n,t,o),s=r-i,a=0;return s!==0&&(r===n?a=60*((t-o)/s%6):r===t?a=60*((o-n)/s+2):a=60*((n-t)/s+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:s/r,value:r}}function $0(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function X0(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=su(e),o=su(n),r=t.saturation<.08,i=o.saturation<.08;if(r||i)return r===i;let s=Math.min(t.value,o.value)<.18?32:18;return $0(t.hue,o.hue)<=s}function Y0(e,n){let t=new Map;for(let s of e.keys()){let a=U0(s);a&&t.set(s,a)}let o=[],r=new Map,i=Array.from(e.entries()).sort((s,a)=>a[1]-s[1]||s[0].localeCompare(a[0]));for(let[s]of i){let a=t.get(s);if(!a){r.set(s,s);continue}let c=null;for(let l of o){if(!X0(a,l.parsed))continue;let u=G0(a,l.parsed);u>n||(!c||u<c.distance)&&(c={color:l.color,distance:u})}c?r.set(s,c.color):(o.push({color:s,parsed:a}),r.set(s,s))}return r}function j0(e,n,t){if(t!=="lossy"||e.animation)return e;let o=n.source;if(!o||o.polygons===e.polygons)return e;let r=n.bakedTextureColorMergeDistance??N0;if(!Number.isFinite(r)||r<=0)return e;let i=new Map,s=[];for(let u=0;u<e.polygons.length;u+=1){let f=o.polygons[u],d=e.polygons[u];if(!f||!d||f===d||!d.color||!Fs(f)||Fs(d))continue;let m=iu(d.color);s.push(u),i.set(m,(i.get(m)??0)+1)}if(i.size<2)return e;let a=Y0(i,r),c=!1,l=e.polygons.slice();for(let u of s){let f=l[u],d=iu(f.color),m=a.get(d)??d;m!==d&&(l[u]={...f,color:m},c=!0)}return c?{...e,polygons:l}:e}function W0(e){let n=0;for(let t of e)Fs(t)&&(n+=1);return e.length===0||n/e.length<=z0}function H0(e){return!!e.metadata?.stlTopology}function K0(e,n){return n?Math.max(e.simplifyEarlyStopDropRatio??D0,F0):e.simplifyEarlyStopDropRatio}function Qn(e,n={}){return new Bs(e,n).optimize()}var Bs=class{constructor(n,t){this.result=n,this.options=t,this.meshResolution=t.meshResolution??"lossy"}optimize(){if(this.result.voxelSource||this.result.animation)return this.result;let n=j0(this.result,this.options,this.meshResolution),t=H0(n),o=t?"lossless":this.meshResolution,r=this.canSimplify(n.polygons,o),i=r&&n.polygons.length>=B0&&n.polygons.length<=k0,s=Ul(n.polygons,{meshResolution:o,useCandidateFirst:i,staticSimplification:r?{simplifyTriangleMeshOptions:this.options.simplifyTriangleMeshOptions,earlyStopDropRatio:K0(this.options,i)}:!1,skipInteriorCull:t});return s===n.polygons?n:{...n,polygons:s}}canSimplify(n,t){return t==="lossy"&&this.options.simplifyTriangleMeshes!==!1&&W0(n)}};function Z0(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[O,L,D]of n)t+=O,o+=L,r+=D;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let x=n.length-2,P=new Float64Array(x*9),M=0;for(let O=1;O<n.length-1;O++){let L=n[0],D=n[O],_=n[O+1];P[M++]=L[0],P[M++]=L[1],P[M++]=L[2],P[M++]=D[0],P[M++]=D[1],P[M++]=D[2],P[M++]=_[0],P[M++]=_[1],P[M++]=_[2]}let C=0,E=1/0,A=1/0,S=1/0,T=-1/0,v=-1/0,R=-1/0;for(let[O,L,D]of n){let _=O-t,w=L-o,V=D-r,j=_*_+w*w+V*V;j>C&&(C=j),O<E&&(E=O),O>T&&(T=O),L<A&&(A=L),L>v&&(v=L),D<S&&(S=D),D>R&&(R=D)}return{centroid:[t,o,r],normal:[g,h,y],triFlat:P,bcx:t,bcy:o,bcz:r,br2:C,minX:E,minY:A,minZ:S,maxX:T,maxY:v,maxZ:R}}function q0(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function Q0(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(q0(e,n,t,o,r,i,p,h))return!0;return!1}var so=9,J0=6,Ze=12;function ks(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function eh(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*so),l=0,u=new Float64Array(Ze),f=new Float64Array(Ze),d=new Float64Array(Ze),m=new Float64Array(Ze),p=new Float64Array(Ze),g=new Float64Array(Ze),h=new Int32Array(Ze),y=new Float64Array(Ze-1),b=new Int32Array(Ze-1),x=new Float64Array(Ze-1),P=new Int32Array(Ze-1);function M(C,E){let A=l++,S=A*so,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=J0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=ks(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ce=Ze/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),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ce|0;oe>=Ze&&(oe=Ze-1);let pe=e[o[K]];pe.minX<u[oe]&&(u[oe]=pe.minX),pe.maxX>m[oe]&&(m[oe]=pe.maxX),pe.minY<f[oe]&&(f[oe]=pe.minY),pe.maxY>p[oe]&&(p[oe]=pe.maxY),pe.minZ<d[oe]&&(d[oe]=pe.minZ),pe.maxZ>g[oe]&&(g[oe]=pe.maxZ),h[oe]++}let Ve=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<Ze-1;K++)u[K]<Ve&&(Ve=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=ks(Ve,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=Ze-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=ks(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<Ze-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ce)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*so+7]=ae,c[A*so+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function nh(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*so,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&Q0(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function au(e,n,t){let o=new Set;if(e.length<2)return o;let r=Math.hypot(n[0],n[1],n[2]);if(r<1e-9)return o;let i=n[0]/r,s=n[1]/r,a=n[2]/r,c=e.map(Z0);if(t&&t.size>0)for(let f of t)c[f]=null;let l=eh(c),u=new Int32Array(Math.max(64,l.nodeCount));for(let f=0;f<e.length;f++){let d=c[f];if(!d)continue;let m=d.centroid[0]+d.normal[0]*.001,p=d.centroid[1]+d.normal[1]*.001,g=d.centroid[2]+d.normal[2]*.001;d.normal[0]*i+d.normal[1]*s+d.normal[2]*a<=0||nh(m,p,g,i,s,a,f,l,u)&&o.add(f)}return o}var ao=1e-5,zs=.001,Us=6;function pr(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let a=1;a+1<n.length;a++){let c=n[a],l=n[a+1],u=c[1]-t[1],f=c[0]-t[0],d=c[2]-t[2],m=l[1]-t[1],p=l[0]-t[0],g=l[2]-t[2];o-=f*g-d*p,r-=d*m-u*g,i-=u*p-f*m}let s=Math.hypot(o,r,i);return s<1e-9?null:[o/s,r/s,i/s]}function Gs(e,n){let t=n.meshRotation,o=t?Dn(e,t):e;return Yo(o,n.rotX,0,n.rotY)[2]}function At(e,n,t=ao){return Gs(e,n)>t}function cu(e,n,t=ao){let o=pr(e);return o===null||At(o,n,t)}function $s(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function Xs(e){let n=new Map;for(let t of e){if(!t)continue;let o=$s(t);n.has(o)||n.set(o,t)}return Array.from(n,([t,o])=>({key:t,normal:o}))}function lu(e){return Xs(e.map(pr))}function Ys(e,n=zs){let t=Math.abs(e[0]),o=Math.abs(e[1]),r=Math.abs(e[2]),i=Math.max(t,o,r);return i>1-n&&t+o+r-i<n}function uu(e){return e.length<=Us&&e.every(({normal:n})=>Ys(n))}function fu(e,n,t=ao){let o=[];for(let{key:r,normal:i}of e)At(i,n,t)&&o.push(r);return o.sort(),o.join("|")}function js(e,n,t,o,r){let i=(p,g,h)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=g,y[(e+2)%3]=h,y},s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function Ws(e={}){let n=e.size??5,t=e.thickness??.025,o=e.negative??!1,r=e.xColor??"#ff3a3a",i=e.yColor??"#3aff3a",s=e.zColor??"#3a8aff",a=n*t/2,c=o?-n:0;return[...js(0,c,n,a,r),...js(1,c,n,a,i),...js(2,c,n,a,s)]}var th=["right","left","front","back","top","bottom"];function Hs(e){return[e[0],e[1],e[2]]}function mu(e,n){return{min:[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.min(e[2],n[2])],max:[Math.max(e[0],n[0]),Math.max(e[1],n[1]),Math.max(e[2],n[2])]}}function oh(e){if(e.min&&e.max)return mu(e.min,e.max);let n=e.center?Hs(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=Hs(e.size):t=[1,1,1];let o=[t[0]/2,t[1]/2,t[2]/2];return mu([n[0]-o[0],n[1]-o[1],n[2]-o[2]],[n[0]+o[0],n[1]+o[1],n[2]+o[2]])}function rh(e,n){let[t,o,r]=e,[i,s,a]=n;return[{name:"right",vertices:[[i,o,r],[i,s,r],[i,s,a],[i,o,a]]},{name:"left",vertices:[[t,s,r],[t,o,r],[t,o,a],[t,s,a]]},{name:"front",vertices:[[i,s,r],[t,s,r],[t,s,a],[i,s,a]]},{name:"back",vertices:[[t,o,r],[i,o,r],[i,o,a],[t,o,a]]},{name:"top",vertices:[[t,o,a],[i,o,a],[i,s,a],[t,s,a]]},{name:"bottom",vertices:[[t,s,r],[i,s,r],[i,o,r],[t,o,r]]}]}function ih(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function sh(e,n){let t={vertices:e.vertices.map(Hs)};return n.color!==void 0&&(t.color=n.color),n.texture!==void 0&&(t.texture=n.texture),n.material!==void 0&&(t.material=n.material),n.uvs!==void 0&&(t.uvs=n.uvs.map(o=>[o[0],o[1]])),n.data!==void 0&&(t.data={...n.data}),t}function Ks(e={}){let{min:n,max:t}=oh(e);if(n[0]===t[0]||n[1]===t[1]||n[2]===t[2])return[];let o={color:e.color??"#ffffff",texture:e.texture,material:e.material,uvs:e.uvs,data:e.data},r=rh(n,t),i=new Map(r.map(a=>[a.name,a])),s=[];for(let a of th){let c=e.faces?.[a];if(c===!1)continue;let l=i.get(a);l&&s.push(sh(l,ih(o,c)))}return s}function du(e,n,t,o){let r=[0,0,0];return r[e]=n,r[(e+1)%3]=t,r[(e+2)%3]=o,r}function ah(e,n,t,o,r){let i=(p,g,h)=>du(e,p,g,h),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function ch(e,n,t,o,r){let i=(f,d,m)=>du(e,f,d,m),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,0,0);return[{vertices:[s,a,c,l],color:r},{vertices:[s,a,u],color:r},{vertices:[a,c,u],color:r},{vertices:[c,l,u],color:r},{vertices:[l,s,u],color:r}]}function lh(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function Zs(e){let n=e.axis,t=e.sign??1,o=e.shaftLength??4,r=e.shaftHalfThickness??.05,i=e.headLength??.8,s=e.headHalfThickness??.2,a=e.color??"#ffffff",c=e.shaft??!0,l=o*t,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(o+i)*t,p=ch(n,d,m,s,a),g=t===-1?lh(p):p;return c?[...ah(n,u,f,r,a),...g]:g}function gr(e,n,t){let o=[0,0,0],r=(e+1)%3,i=(e+2)%3;return o[r]=Math.cos(t)*n,o[i]=Math.sin(t)*n,o}function qs(e){let n=e.axis,t=e.radius,o=e.halfThickness??Math.max(.05,t*.04),r=e.segments??32,i=e.color??"#ffffff",s=t-o,a=t+o,c=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=gr(n,s,u),m=gr(n,s,f),p=gr(n,a,u),g=gr(n,a,f);c.push({vertices:[d,p,g,m],color:i})}return c}function Qs(e){let n=e.axis,t=e.outerRadius,o=e.color??"#ffffff",r=(n+1)%3,i=(n+2)%3,s=(a,c)=>{let l=[0,0,0];return l[n]=0,l[r]=a,l[i]=c,l};return[{vertices:[s(-t,-t),s(t,-t),s(t,t),s(-t,t)],color:o}]}function Js(e){let n=e.axis,t=e.size??.4,o=e.offset??t*2,r=typeof o=="number"?o:o[0],i=typeof o=="number"?o:o[1],s=e.along??0,a=e.color??"#ffffff",c=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=s,m[c]=r+f,m[l]=i+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:a}]}function ea(e){let{center:n,size:t,color:o="#ffffff"}=e,[r,i,s]=n,a=[[r+t,i,s],[r-t,i,s],[r,i+t,s],[r,i-t,s],[r,i,s+t],[r,i,s-t]];return[[0,2,4],[2,1,4],[1,3,4],[3,0,4],[2,0,5],[1,2,5],[3,1,5],[0,3,5]].map(l=>({vertices:[a[l[0]],a[l[1]],a[l[2]]],color:o}))}function na(e={}){let{radius:n=50,color:t="#cccccc"}=e,o=Math.min(Math.max(0,Math.floor(e.subdivisions??1)),3),r=(1+Math.sqrt(5))/2,i=[[-1,r,0],[1,r,0],[-1,-r,0],[1,-r,0],[0,-1,r],[0,1,r],[0,-1,-r],[0,1,-r],[r,0,-1],[r,0,1],[-r,0,-1],[-r,0,1]].map(([c,l,u])=>{let f=Math.sqrt(c*c+l*l+u*u);return[c/f,l/f,u/f]}),s=[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]];for(let c=0;c<o;c++){let l=[...i],u=[],f=new Map,d=(m,p)=>{let g=m<p?`${m}-${p}`:`${p}-${m}`,h=f.get(g);if(h!==void 0)return h;let y=i[m],b=i[p],x=(y[0]+b[0])/2,P=(y[1]+b[1])/2,M=(y[2]+b[2])/2,C=Math.sqrt(x*x+P*P+M*M);x/=C,P/=C,M/=C;let E=l.length;return l.push([x,P,M]),f.set(g,E),E};for(let[m,p,g]of s){let h=d(m,p),y=d(p,g),b=d(g,m);u.push([m,h,b]),u.push([p,y,h]),u.push([g,b,y]),u.push([h,y,b])}i=l,s=u}let a=i.map(([c,l,u])=>[c*n,l*n,u*n]);return s.map(([c,l,u])=>({vertices:[a[c],a[l],a[u]],color:t}))}function ta(e={}){let{size:n=100,color:t="#cccccc"}=e,o=n/Math.sqrt(3),r=[[o,o,o],[o,-o,-o],[-o,o,-o],[-o,-o,o]];return[[0,1,2],[0,3,1],[0,2,3],[1,3,2]].map(([s,a,c])=>({vertices:[r[s],r[a],r[c]],color:t}))}function oa(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=n/Math.sqrt(1+o*o),i=[[-1,o,0],[1,o,0],[-1,-o,0],[1,-o,0],[0,-1,o],[0,1,o],[0,-1,-o],[0,1,-o],[o,0,-1],[o,0,1],[-o,0,-1],[-o,0,1]].map(([a,c,l])=>[a*r,c*r,l*r]);return[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]].map(([a,c,l])=>({vertices:[i[a],i[c],i[l]],color:t}))}function ra(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=1/o,i=n/Math.sqrt(3),a=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1],[0,r,o],[0,-r,o],[0,r,-o],[0,-r,-o],[r,o,0],[-r,o,0],[r,-o,0],[-r,-o,0],[o,0,r],[o,0,-r],[-o,0,r],[-o,0,-r]].map(([l,u,f])=>[l*i,u*i,f*i]);return[[12,13,4,8,0],[0,8,9,2,16],[16,17,1,12,0],[1,10,5,13,12],[17,3,11,10,1],[2,9,6,15,14],[2,14,3,17,16],[14,15,7,11,3],[18,6,9,8,4],[4,13,5,19,18],[5,10,11,7,19],[18,19,7,15,6]].map(l=>({vertices:l.map(u=>a[u]),color:t}))}function co(e={}){let{radius:n=50,height:t=100,radialSegments:o=12,color:r="#cccccc"}=e,i=e.radiusTop??n,s=t/2,a=-s,c=s,l=Math.max(3,o),u=[],f=Array.from({length:l+1},(p,g)=>g/l*Math.PI*2),d=n<=1e-6,m=i<=1e-6;for(let p=0;p<l&&!(d&&m);p++){let g=f[p],h=f[p+1],y=Math.cos(g)*n,b=Math.sin(g)*n,x=Math.cos(h)*n,P=Math.sin(h)*n,M=Math.cos(g)*i,C=Math.sin(g)*i,E=Math.cos(h)*i,A=Math.sin(h)*i,S=[y,b,a],T=[x,P,a],v=[E,A,c],R=[M,C,c];if(m){let O=[0,0,c];u.push({vertices:[S,T,O],color:r})}else if(d){let O=[0,0,a];u.push({vertices:[O,v,R],color:r})}else u.push({vertices:[S,T,v,R],color:r})}if(n>1e-6){let p=[0,0,a];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*n,Math.sin(h)*n,a],x=[Math.cos(y)*n,Math.sin(y)*n,a];u.push({vertices:[[...p],[...x],[...b]],color:r})}}if(i>1e-6){let p=[0,0,c];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*i,Math.sin(h)*i,c],x=[Math.cos(y)*i,Math.sin(y)*i,c];u.push({vertices:[[...p],[...b],[...x]],color:r})}}return u}function ia(e={}){return co({...e,radiusTop:0})}function hr(e,n,t,o){let r=Math.sin(e),i=Math.cos(e),s=Math.sin(n),a=Math.cos(n);return[(t+o*a)*i,(t+o*a)*r,o*s]}function sa(e={}){let{radius:n=50,tube:t=15,radialSegments:o=12,tubularSegments:r=16,color:i="#cccccc"}=e,s=Math.max(3,o),a=Math.max(3,r),c=[];for(let l=0;l<s;l++){let u=l/s*Math.PI*2,f=(l+1)/s*Math.PI*2;for(let d=0;d<a;d++){let m=d/a*Math.PI*2,p=(d+1)/a*Math.PI*2,g=hr(u,m,n,t),h=hr(f,m,n,t),y=hr(f,p,n,t),b=hr(u,p,n,t);c.push({vertices:[g,h,y,b],color:i})}}return c}var pu=.01,gu=.01;function hu(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,o=e[0]/t,r=e[1]/t,i=e[2]/t,s=Math.sign(i||1)*Math.max(Math.abs(i),.01),a=n,c=.01;return[1,0,0,0,0,1,0,0,-o/s,-r/s,c,0,a*o/s,a*r/s,a*(1-c),1]}function yu(e,n,t){let o=e[2]-n[2];if(Math.abs(o)<1e-9)return null;let r=(t-e[2])/o;return r<0?null:[e[0]+r*(e[0]-n[0]),e[1]+r*(e[1]-n[1])]}function bu(e,n,t){let o=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],s=Math.hypot(o,r,i)||1;return(n[0]*o+n[1]*r+n[2]*i)/s>0}function xu(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e[0]*o+e[1]*r+e[2]*i>0}function yr(e){if(e.length<=1)return e.map(s=>[s[0],s[1]]);let t=e.map(s=>[s[0],s[1]]);t.sort((s,a)=>s[0]-a[0]||s[1]-a[1]);let o=(s,a,c)=>(a[0]-s[0])*(c[1]-s[1])-(a[1]-s[1])*(c[0]-s[0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function aa(e){let n=0,t=e.length;for(let o=0;o<t;o++){let r=e[o],i=e[(o+1)%t];n+=r[0]*i[1]-i[0]*r[1]}return n/2}function yn(e){let n=e.map(t=>[t[0],t[1]]);return aa(n)<0&&n.reverse(),n}function Pu(e,n,t){let o=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/o,i=n[1]/o,s=n[2]/o,a=Math.sign(s||1)*Math.max(Math.abs(s),.01),c=e[2]-t;return[e[0]-r/a*c,e[1]-i/a*c]}function Mu(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}function uh(e){if(e.length<3)return e.map((s,a)=>a);let t=e.map((s,a)=>a).sort((s,a)=>e[s][0]-e[a][0]||e[s][1]-e[a][1]),o=(s,a,c)=>(e[a][0]-e[s][0])*(e[c][1]-e[s][1])-(e[a][1]-e[s][1])*(e[c][0]-e[s][0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function br(e,n,t){if(e.length<3)return null;let o=Mu(n),r=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],i=r[0]*o[0]+r[1]*o[1]+r[2]*o[2],s=Mu([r[0]-i*o[0],r[1]-i*o[1],r[2]-i*o[2]]),a=[o[1]*s[2]-o[2]*s[1],o[2]*s[0]-o[0]*s[2],o[0]*s[1]-o[1]*s[0]],c=e.map(f=>[f[0]*s[0]+f[1]*s[1]+f[2]*s[2],f[0]*a[0]+f[1]*a[1]+f[2]*a[2]]),l=uh(c);if(l.length<3)return null;let u=Math.max(3,Math.floor(t));if(l.length>u){let f=(d,m,p)=>{let g=c[d][0],h=c[d][1];return Math.abs((c[m][0]-g)*(c[p][1]-h)-(c[p][0]-g)*(c[m][1]-h))*.5};for(;l.length>u;){let d=1/0,m=0;for(let p=0;p<l.length;p++){let g=f(l[(p-1+l.length)%l.length],l[p],l[(p+1)%l.length]);g<d&&(d=g,m=p)}l.splice(m,1)}}return l.map(f=>[e[f][0],e[f][1],e[f][2]])}function Su(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}var fh=[[],[3,0],[0,1],[3,1],[1,2],[3,0,1,2],[0,2],[3,2],[2,3],[2,0],[0,1,2,3],[2,1],[1,3],[1,0],[0,3],[]];function mh(e,n){if(e.length<4)return e;let t=1,o=-1;for(let u=0;u<e.length;u++){let f=e[u][0]-e[0][0],d=e[u][1]-e[0][1],m=f*f+d*d;m>o&&(o=m,t=u)}let r=u=>{if(u.length<3)return u;let f=u[0],d=u[u.length-1],m=-1,p=n,g=d[0]-f[0],h=d[1]-f[1],y=Math.hypot(g,h)||1;for(let b=1;b<u.length-1;b++){let x=Math.abs((u[b][0]-f[0])*h-(u[b][1]-f[1])*g)/y;x>p&&(p=x,m=b)}return m<0?[f,d]:[...r(u.slice(0,m+1)).slice(0,-1),...r(u.slice(m))]},i=e.slice(0,t+1),s=[...e.slice(t),e[0]],a=r(i),c=r(s),l=[...a.slice(0,-1),...c.slice(0,-1)];return l.length>=3?l:e}function dh(e,n,t){let o=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let s=t[r][0],a=t[r][1],c=t[i][0],l=t[i][1];a>n!=l>n&&e<(c-s)*(n-a)/(l-a)+s&&(o=!o)}return o}function xr(e,n,t,o=1,r="contour"){let i=Su(n),s=Math.abs(i[0])<.9?[1,0,0]:[0,1,0],a=s[0]*i[0]+s[1]*i[1]+s[2]*i[2],c=Su([s[0]-a*i[0],s[1]-a*i[1],s[2]-a*i[2]]),l=[i[1]*c[2]-i[2]*c[1],i[2]*c[0]-i[0]*c[2],i[0]*c[1]-i[1]*c[0]],u=1/0,f=1/0,d=-1/0,m=-1/0,p=1/0,g=-1/0,h=[];for(let D of e){if(D.length<3)continue;let _=[],w=0;for(let V of D){let j=V[0]*c[0]+V[1]*c[1]+V[2]*c[2],G=V[0]*l[0]+V[1]*l[1]+V[2]*l[2],Z=V[0]*i[0]+V[1]*i[1]+V[2]*i[2];_.push([j,G]),w+=Z,j<u&&(u=j),j>d&&(d=j),G<f&&(f=G),G>m&&(m=G),Z<p&&(p=Z),Z>g&&(g=Z)}h.push({pts:_,depth:w/D.length})}if(!Number.isFinite(u)||h.length===0)return null;let y=d-u,b=m-f,x=Math.max(y,b);if(x<1e-6)return null;let P=Math.max(r==="pixel"?3:8,Math.min(384,Math.round(t*(r==="pixel"?1:2)))),M=x/P,C=1,E=u-C*M,A=f-C*M,S=Math.ceil(y/M)+2*C+1,T=Math.ceil(b/M)+2*C+1;if(S*T>4e5)return null;let v=.6,R=(D,_,w)=>{let V=new Uint8Array(S*T),j=(I,B)=>I<0||B<0||I>=S||B>=T?0:V[B*S+I],G=(I,B,N,H,$,k)=>(N-I)*(k-B)-(H-B)*($-I);for(let I of D){let B=I.pts;for(let N=1;N<B.length-1;N++){let H=B[0],$=B[N],k=B[N+1],Q=Math.floor((Math.min(H[0],$[0],k[0])-E)/M),ae=Math.ceil((Math.max(H[0],$[0],k[0])-E)/M),se=Math.floor((Math.min(H[1],$[1],k[1])-A)/M),Y=Math.ceil((Math.max(H[1],$[1],k[1])-A)/M);if(Q<0&&(Q=0),ae>S-1&&(ae=S-1),se<0&&(se=0),Y>T-1&&(Y=T-1),!(Math.abs(G(H[0],H[1],$[0],$[1],k[0],k[1]))<1e-12))for(let ne=se;ne<=Y;ne++){let le=A+(ne+.5)*M;for(let ye=Q;ye<=ae;ye++){if(V[ne*S+ye])continue;let Ce=E+(ye+.5)*M,Ve=G($[0],$[1],k[0],k[1],Ce,le),Ee=G(k[0],k[1],H[0],H[1],Ce,le),Me=G(H[0],H[1],$[0],$[1],Ce,le);(Ve>=0&&Ee>=0&&Me>=0||Ve<=0&&Ee<=0&&Me<=0)&&(V[ne*S+ye]=1)}}}}if(r==="pixel"){let I=new Uint8Array(S*T),B=(N,H)=>{let $=E+N*M,k=A+H*M;return[$*c[0]+k*l[0]+_*i[0],$*c[1]+k*l[1]+_*i[1],$*c[2]+k*l[2]+_*i[2]]};for(let N=0;N<T;N++)for(let H=0;H<S;H++){if(!V[N*S+H]||I[N*S+H])continue;let $=1;for(;H+$<S&&V[N*S+H+$]&&!I[N*S+H+$];)$++;let k=1;e:for(;N+k<T;){for(let Q=0;Q<$;Q++)if(!V[(N+k)*S+H+Q]||I[(N+k)*S+H+Q])break e;k++}for(let Q=N;Q<N+k;Q++)for(let ae=H;ae<H+$;ae++)I[Q*S+ae]=1;w.push([B(H,N),B(H+$,N),B(H+$,N+k),B(H,N+k)])}return}let Z=(I,B)=>`${Math.round(I*2)},${Math.round(B*2)}`,ee=new Map,W=new Map,ie=(I,B,N)=>I===0?[B+.5,N]:I===1?[B+1,N+.5]:I===2?[B+.5,N+1]:[B,N+.5],z=(I,B)=>{let N=Z(I[0],I[1]),H=Z(B[0],B[1]);N!==H&&(ee.has(N)||ee.set(N,[]),ee.has(H)||ee.set(H,[]),ee.get(N).push(B),ee.get(H).push(I),W.set(N,I),W.set(H,B))};for(let I=0;I<T-1;I++)for(let B=0;B<S-1;B++){let N=j(B,I)|j(B+1,I)<<1|j(B+1,I+1)<<2|j(B,I+1)<<3,H=fh[N];for(let $=0;$<H.length;$+=2)z(ie(H[$],B,I),ie(H[$+1],B,I))}if(ee.size===0)return;let X=new Set,U=[];for(let I of ee.keys()){if(X.has(I))continue;let B=[],N=I,H="",$=0;for(;N&&!X.has(N)&&$++<1e6;){X.add(N),B.push(W.get(N));let Q=ee.get(N)??[],ae="";for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H&&!X.has(Y)){ae=Y;break}}if(!ae)for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H){ae=Y;break}}if(H=N,N=ae,N===I)break}if(B.length<3)continue;let k=mh(B,v);k.length>=3&&U.push(k)}for(let I of U){let B=0,N=I[0][0],H=I[0][1];for(let se of U)se!==I&&dh(N,H,se)&&B++;let $=B%2===0,k=0;for(let se=0;se<I.length;se++){let Y=I[se],ne=I[(se+1)%I.length];k+=Y[0]*ne[1]-ne[0]*Y[1]}let ae=k>0===$?I:[...I].reverse();w.push(ae.map(se=>{let Y=E+se[0]*M,ne=A+se[1]*M;return[Y*c[0]+ne*l[0]+_*i[0],Y*c[1]+ne*l[1]+_*i[1],Y*c[2]+ne*l[2]+_*i[2]]}))}},O=[],L=Math.max(1,Math.floor(o));if(L<=1||g-p<1e-6){let D=g+(g-p)+x;R(h,D,O)}else{let D=g-p,_=D/L,w=D*.05;for(let V=0;V<L;V++){let j=p+V*_,G=V===L-1?1/0:p+(V+1)*_,Z=h.filter(ee=>ee.depth>=j&&ee.depth<G);Z.length&&R(Z,j-w,O)}}return O.length?O:null}function ca(e){let n=0,t=0,o=0,r=0,i=0,s=0,a=0,c=0,l=0,u=!1;for(let y of e)if(y.length>=3&&!u){let b=y[0],x=y[1],P=y[2];n=x[0]-b[0],t=x[1]-b[1],o=x[2]-b[2],r=P[0]-b[0],i=P[1]-b[1],s=P[2]-b[2],a=b[0],c=b[1],l=b[2],u=!0}if(!u)return!0;let f=t*s-o*i,d=o*r-n*s,m=n*i-t*r,p=Math.hypot(f,d,m);if(p<1e-9)return!0;f/=p,d/=p,m/=p;let g=0;for(let y of e)for(let b of y)g=Math.max(g,Math.abs(b[0]-a)+Math.abs(b[1]-c)+Math.abs(b[2]-l));let h=Math.max(.001,g*.001);for(let y of e)for(let b of y){let x=(b[0]-a)*f+(b[1]-c)*d+(b[2]-l)*m;if(Math.abs(x)>h)return!1}return!0}function la(e,n=300){if(e.length===0||e.length>n)return!1;let t=0,o=0,r=0,i=0,s=!1;for(let c of e)for(let l of c)s||(o=l[0],r=l[1],i=l[2],s=!0),t=Math.max(t,Math.abs(l[0]-o)+Math.abs(l[1]-r)+Math.abs(l[2]-i));let a=Math.max(.001,t*.005);for(let c of e){if(c.length<3)continue;let l=c[0],u=c[1],f=c[2],d=(u[1]-l[1])*(f[2]-l[2])-(u[2]-l[2])*(f[1]-l[1]),m=(u[2]-l[2])*(f[0]-l[0])-(u[0]-l[0])*(f[2]-l[2]),p=(u[0]-l[0])*(f[1]-l[1])-(u[1]-l[1])*(f[0]-l[0]),g=Math.hypot(d,m,p);if(g<1e-9)continue;d/=g,m/=g,p/=g;let h=!1,y=!1;for(let b of e)for(let x of b){let P=(x[0]-l[0])*d+(x[1]-l[1])*m+(x[2]-l[2])*p;if(P>a?h=!0:P<-a&&(y=!0),h&&y)return!1}}return!0}function Au(e){let{polysWorldVerts:n,lightDir:t,definition:o,isSelf:r,style:i,pointLights:s}=e,a=ca(n),c=r&&la(n);if(a||c)return{};let l=r?Math.max(2,Math.min(6,Math.round(o/8))):1,u=i==="pixel"?"pixel":"contour",f=p=>{let g=xr(n,p,o,l,u);if(g&&g.length)return g;if(!r){let h=[];for(let b of n)for(let x of b)h.push(x);let y=br(h,p,o);if(y&&y.length>=3)return[y]}},d=f(t),m;if(s&&s.length>0){let p=0,g=0,h=0,y=0;for(let b of n)for(let x of b)p+=x[0],g+=x[1],h+=x[2],y++;y>0&&(p/=y,g/=y,h/=y),m=[];for(let b of s){let x=[b.position[0]-p,b.position[1]-g,b.position[2]-h];m[b.index]=f(x)}}return{overrideSilhouette:d,overridePointSilhouettes:m}}function Vn(e,n){if(e.length===0||n.length<3)return[];let t=e.map(r=>[r[0],r[1]]),o=n.length;for(let r=0;r<o;r++){if(t.length===0)return[];let i=t;t=[];let s=n[r],a=n[(r+1)%o],c=f=>(a[0]-s[0])*(f[1]-s[1])-(a[1]-s[1])*(f[0]-s[0])>=0,l=(f,d)=>{let m=s[0],p=s[1],g=a[0],h=a[1],y=f[0],b=f[1],x=d[0],P=d[1],M=(m-g)*(b-P)-(p-h)*(y-x);if(Math.abs(M)<1e-12)return[f[0],f[1]];let C=((m-y)*(b-P)-(p-b)*(y-x))/M;return[m+C*(g-m),p+C*(h-p)]},u=i.length;for(let f=0;f<u;f++){let d=i[f],m=i[(f+u-1)%u],p=c(d),g=c(m);p?(g||t.push(l(m,d)),t.push([d[0],d[1]])):g&&t.push(l(m,d))}}return t}function Pr(e){if(!Number.isFinite(e)||e<=0)throw new Error("PolyCSS world unit size must be a positive finite number.");return e}function ua(e,n=50){return e*Pr(n)}function fa(e,n=50){return e/Pr(n)}function rn(e,n=50){let t=Pr(n);return[e[1]*t,e[0]*t,e[2]*t]}function ma(e,n=50){let t=Pr(n);return[e[1]/t,e[0]/t,e[2]/t]}function Mr(e){return[e[1],e[0],e[2]]}function da(e){return e?.direction?{...e,direction:Mr(e.direction)}:e}var Cu=ua,Tu=fa,Eu=rn,vu=ma,Iu=Mr,_u=da;function Sr(e){return e==null?[1,1,1]:typeof e=="number"?[e,e,e]:[e[0]??1,e[1]??1,e[2]??1]}function Ct(e){let n=Sr(e),t=n[0]===1&&n[1]===1&&n[2]===1;return(o,r)=>{let i=rn(r),s=o[1]*50,a=o[0]*50,c=o[2]*50,l=t?s:s*n[0],u=t?a:a*n[1],f=t?c:c*n[2];return[l+i[0],u+i[1],f+i[2]]}}function pa(e,n){if(e.length<3||n===0)return e;let t=[],o=e.length;for(let r=0;r<o;r++){let i=e[(r-1+o)%o],s=e[r],a=e[(r+1)%o],c=s[0]-i[0],l=s[1]-i[1],u=a[0]-s[0],f=a[1]-s[1],d=Math.hypot(c,l),m=Math.hypot(u,f);if(d<1e-9||m<1e-9){t.push(s);continue}let p=l/d,g=-c/d,h=f/m,y=-u/m,b=p+h,x=g+y,P=Math.hypot(b,x);if(P<1e-9){t.push(s);continue}let M=b/P,C=x/P,E=M*p+C*g;if(Math.abs(E)<1e-9){t.push(s);continue}let A=n/E;t.push([s[0]+M*A,s[1]+C*A])}return t}var ga=.5,ha=.001,ya=.5;function Ar(e,n,t,o){let r=[];for(let u=0;u<e.length;u++){if(o.has(u))continue;let f=e[u];if(f.vertices.length<3)continue;let d=f.vertices.map(A=>t(A,n)),m=d[0],p=0,g=0,h=0;for(let A=1;A+1<d.length;A++){let S=d[A],T=d[A+1],v=S[0]-m[0],R=S[1]-m[1],O=S[2]-m[2],L=T[0]-m[0],D=T[1]-m[1],_=T[2]-m[2];p+=D*O-_*R,g+=_*v-L*O,h+=L*R-D*v}let y=Math.hypot(p,g,h);if(y<1e-9)continue;let b=[p/y,g/y,h/y],x=null;for(let A=1;A<d.length;A++){let S=d[A],T=S[0]-m[0],v=S[1]-m[1],R=S[2]-m[2],O=Math.hypot(T,v,R);if(O>1e-9){x=[T/O,v/O,R/O];break}}if(!x)continue;let P=x[0]*b[0]+x[1]*b[1]+x[2]*b[2];x=[x[0]-P*b[0],x[1]-P*b[1],x[2]-P*b[2]];let M=Math.hypot(x[0],x[1],x[2]);if(M<1e-9)continue;x=[x[0]/M,x[1]/M,x[2]/M];let C=[b[1]*x[2]-b[2]*x[1],b[2]*x[0]-b[0]*x[2],b[0]*x[1]-b[1]*x[0]],E=b[0]*m[0]+b[1]*m[1]+b[2]*m[2];r.push({face:f,O:m,n:b,u:x,v:C,offset:E,polyIndex:u})}let i=[];for(let u of r){let f=!1;for(let d of i){let m=d.rep;if(!(1-(u.n[0]*m.n[0]+u.n[1]*m.n[1]+u.n[2]*m.n[2])>ha)&&!(Math.abs(u.offset-m.offset)>ya)){d.faces.push(u),f=!0;break}}f||i.push({rep:u,faces:[u]})}let s=[],a=3,c=u=>`${u[0].toFixed(a)},${u[1].toFixed(a)},${u[2].toFixed(a)}`;for(let u of i){if(u.faces.length===1){l(u.faces);continue}let f=u.faces.map(h=>{let y=new Set;for(let b of h.face.vertices)y.add(c(t(b,n)));return y}),d=u.faces.map((h,y)=>y),m=h=>{for(;d[h]!==h;)d[h]=d[d[h]],h=d[h];return h},p=(h,y)=>{let b=m(h),x=m(y);b!==x&&(d[b]=x)};for(let h=0;h<u.faces.length;h++)for(let y=h+1;y<u.faces.length;y++){let b=f[h],x=f[y],P=0;for(let M of b)if(x.has(M)&&(P++,P>=2))break;P>=2&&p(h,y)}let g=new Map;for(let h=0;h<u.faces.length;h++){let y=m(h),b=g.get(y);b||(b=[],g.set(y,b)),b.push(u.faces[h])}for(let h of g.values())l(h)}function l(u){let f=u[0],{O:d,n:m,u:p,v:g}=f,h=[],y=[],b=[];for(let M of u){let C=[];for(let E of M.face.vertices){let A=t(E,n),S=A[0]-d[0],T=A[1]-d[1],v=A[2]-d[2],R=[S*p[0]+T*p[1]+v*p[2],S*g[0]+T*g[1]+v*g[2]];h.push(R),C.push(R)}C.length>=3&&(y.push(yn(C)),b.push(M.polyIndex))}if(h.length<3)return;let x=yr(h);if(x.length<3)return;let P=pa(yn(x),ga);s.push({O:d,n:m,u:p,v:g,outlineUv:P,memberPolysUv:y,memberPolyIndices:b})}return s}function Vu(e){let n=typeof e.scale=="number"?e.scale:e.scale?.[0]??1,t=typeof e.scale=="number"?e.scale:e.scale?.[1]??1,o=typeof e.scale=="number"?e.scale:e.scale?.[2]??1,r=n!==1||t!==1||o!==1,i=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),s=e.position?rn(e.position):[0,0,0],a=[];return(s[0]!==0||s[1]!==0||s[2]!==0)&&a.push(`translate3d(${s[0]}px, ${s[1]}px, ${s[2]}px)`),i&&(e.rotation[0]&&a.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&a.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&a.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&a.push(`scale3d(${n}, ${t}, ${o})`),a.length>0?a.join(" "):void 0}function Ou(e={}){let n=e.target??_e.target,t=e.autoCenterOffset??[0,0,0],o=e.layoutScale??1,r=e.worldUnitPx??50,i=(e.zoom??_e.zoom)/r*o,s=(e.distance??_e.distance)*o,a=rn([n[0]+t[0],n[1]+t[1],n[2]+t[2]],r);return`${s!==0?`translateZ(${-s}px) `:""}scale(${i}) rotateX(${e.rotX??_e.rotX}deg) rotate(${e.rotY??_e.rotY}deg) translate3d(${-a[0]}px, ${-a[1]}px, ${-a[2]}px)`}var un=50,Jn=[.4,-.7,.59],et="#ffffff",nt=1,tt="#ffffff",ot=.4,On=4096,lo=1,Cr=.1,Tr=1,uo=On*On,Er=uo*3,Tt=2048,vr=4*1024*1024,Ir=16*1024*1024,_r=.995,Vr=512,Ru=12,Ae=.001,de=1e-9,Or=1e-4,Rr=.1,fo=.01,Lu=.75,wu=1,Nu=250,Du=1.5,Lr=.75,bn=3,wr=2,mo=4,Nr=[1,10,100,1e3,1e4,1e5,1e6],xn=64,Dr=32,Fr=96,nn=64,Br=128,po=50,go=1e-7,Pn=16,kr=.9,tn=.75,ho=.2,zr=.05,Ur=256,Gr=.6,Fu=1.5;function $r(e){return e===void 0||e==="auto"||!Number.isFinite(e)?1:Math.max(0,Math.min(1,e))}var yo=new Map;function rt(e){if(yo.has(e)){let t=yo.get(e);return t===void 0?null:t}let n=Tn(e);return yo.size>=Vr&&yo.clear(),yo.set(e,n),n}function fn(e){let n=rt(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Xr({r:e,g:n,b:t}){return`${e},${n},${t}`}function bo(e){return rt(e)?.alpha??1}function xo({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function Bu(e,n){if(n)for(let t of n){if(t.scale<=0)continue;let o=fn(t.color);e[0]+=Xe(o.r/255)*t.scale,e[1]+=Xe(o.g/255)*t.scale,e[2]+=Xe(o.b/255)*t.scale}}function Po(e,n,t,o,r){let i=fn(n),s=fn(t),a=Xe(i.r/255),c=Xe(i.g/255),l=Xe(i.b/255),u=Xe(s.r/255),f=Xe(s.g/255),d=Xe(s.b/255),m=[a*e,c*e,l*e];return Bu(m,r),{r:(m[0]+u*o)*Et,g:(m[1]+f*o)*Et,b:(m[2]+d*o)*Et}}function ku({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Xe(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function ph(e){return e<=.0031308?e*12.92:1.055*Math.pow(e,1/2.4)-.055}var Et=1/Math.PI;function Rn(e,n,t,o,r,i){let s=fn(e),a=fn(t),c=fn(o),l=Xe(s.r/255),u=Xe(s.g/255),f=Xe(s.b/255),d=Xe(a.r/255),m=Xe(a.g/255),p=Xe(a.b/255),g=Xe(c.r/255),h=Xe(c.g/255),y=Xe(c.b/255),b=[d*n,m*n,p*n];Bu(b,i);let x=l*(b[0]+g*r)*Et,P=u*(b[1]+h*r)*Et,M=f*(b[2]+y*r)*Et,C=v=>Math.max(0,Math.min(255,Math.round(ph(Math.max(0,Math.min(1,v)))*255))),E=C(x),A=C(P),S=C(M),T=bo(e);return T<1?`rgba(${E}, ${A}, ${S}, ${T})`:xo({r:E,g:A,b:S})}function Yr(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=rt(e);if(!t)return e;let o=255/Math.max(1,Math.round(n)-1),r=s=>Math.max(0,Math.min(255,Math.round(Math.round(s/o)*o))),i={r:r(t.rgb[0]),g:r(t.rgb[1]),b:r(t.rgb[2])};return t.alpha<1?`rgba(${i.r}, ${i.g}, ${i.b}, ${t.alpha})`:xo(i)}function zu(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function Uu(e,n,t){let o=(r,i)=>{let s=i-r;return Math.abs(s)<=t?i:r+Math.sign(s)*t};return{r:o(e.r,n.r),g:o(e.g,n.g),b:o(e.b,n.b)}}function Gu(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:xo(e)}function $u(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=rt(e),o=rt(n);if(!t||!o)return 1;let r=t.rgb[0]-o.rgb[0],i=t.rgb[1]-o.rgb[1],s=t.rgb[2]-o.rgb[2],a=(t.alpha-o.alpha)*255;return Math.sqrt(r*r+i*i+s*s+a*a)/510}function jr(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p?(p.degree+=1,p.degree===2?p.polyB=a:p.polyB=null):i.set(m,{polyA:a,polyB:null,vertA:f,vertB:d,degree:1})}}let s=new Map;for(let[a,c]of i)s.set(a,{polyA:c.polyA,polyB:c.polyB,vertA:c.vertA,vertB:c.vertB});return s}function Wr(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e.map(s=>s?s[0]*o+s[1]*r+s[2]*i<-1e-6:!0)}function ba(e,n){let o=a=>Math.round(a/1e-4).toString(36),r=a=>`${o(a[0])},${o(a[1])},${o(a[2])}`,i=new Map,s=a=>{let c=r(a);i.set(c,(i.get(c)??0)+1)};for(let a of e.values()){let c=n[a.polyA]??!1,l;a.polyB===null?l=c:l=c!==(n[a.polyB]??!1),l&&(s(a.vertA),s(a.vertB))}for(let a of i.values())if(a!==2)return!1;return!0}function Mo(e,n){let t=[];for(let l of e.values()){let u=n[l.polyA]??!1;if(l.polyB===null)u&&t.push([l.vertA,l.vertB]);else{let f=n[l.polyB]??!1;u!==f&&t.push([l.vertA,l.vertB])}}if(t.length===0)return[];let o=1e-4,r=l=>Math.round(l/o).toString(36),i=l=>`${r(l[0])},${r(l[1])},${r(l[2])}`,s=t.map(([l,u])=>({a:l,b:u,aKey:i(l),bKey:i(u),used:!1})),a=new Map;for(let l of s){let u=a.get(l.aKey);u||(u=[],a.set(l.aKey,u)),u.push(l);let f=a.get(l.bKey);f||(f=[],a.set(l.bKey,f)),f.push(l)}let c=[];for(let l of s){if(l.used)continue;let u=[l.a],f=l,d=l.aKey,m=l.bKey;f.used=!0;for(let p=0;p<s.length+1;p++){u.push(f.bKey===m?f.b:f.a);let g=a.get(m)??[],h=null;for(let y of g)if(!(y===f||y.used)){h=y;break}if(!h||(h.used=!0,d=m,m=h.aKey===d?h.bKey:h.aKey,f=h,m===l.aKey))break}u.length>=3&&c.push(u)}return c}var Xu=40;function Yu(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p||(p=[],i.set(m,p)),p.push(a)}}let s=new Map;for(let a of i.values())if(!(a.length<2))for(let c of a)for(let l of a){if(c===l)continue;let u=s.get(c);u||(u=new Set,s.set(c,u)),u.add(l)}return s}function ju(e,n,t,o){let r=Ct(t),i=!!o&&(o[0]!==0||o[1]!==0||o[2]!==0),s=i?rn(n):null,a=e.map(c=>{if(!c)return{vertices:[],color:""};let l=c.vertices.map(u=>r(u,n));return i&&s&&o&&(l=l.map(u=>{let f=[u[0]-s[0],u[1]-s[1],u[2]-s[2]],d=Dn(f,o);return[d[0]+s[0],d[1]+s[1],d[2]+s[2]]})),{vertices:l,color:""}});return jr(a)}function Wu(e,n,t,o,r){let i=[],s=Ct(t),a=!!r&&(r[0]!==0||r[1]!==0||r[2]!==0),c=a?rn(n):null;for(let l=0;l<e.length;l++){if(!o(l))continue;let u=e[l];if(!u)continue;let f=u.vertices.map(M=>s(M,n));a&&c&&r&&(f=f.map(M=>{let C=[M[0]-c[0],M[1]-c[1],M[2]-c[2]],E=Dn(C,r);return[E[0]+c[0],E[1]+c[1],E[2]+c[2]]}));let d=1/0,m=1/0,p=1/0,g=-1/0,h=-1/0,y=-1/0;for(let M of f)M[0]<d&&(d=M[0]),M[0]>g&&(g=M[0]),M[1]<m&&(m=M[1]),M[1]>h&&(h=M[1]),M[2]<p&&(p=M[2]),M[2]>y&&(y=M[2]);let b=[[d,m,p],[g,m,p],[d,h,p],[g,h,p],[d,m,y],[g,m,y],[d,h,y],[g,h,y]],x=null,P=0;if(f.length>=3){let M=f[0],C=f[1],E=f[2],A=[C[0]-M[0],C[1]-M[1],C[2]-M[2]],S=[E[0]-M[0],E[1]-M[1],E[2]-M[2]],T=S[1]*A[2]-S[2]*A[1],v=S[2]*A[0]-S[0]*A[2],R=S[0]*A[1]-S[1]*A[0],O=Math.hypot(T,v,R);O>1e-9&&(x=[T/O,v/O,R/O],P=x[0]*M[0]+x[1]*M[1]+x[2]*M[2])}i.push({wv:f,bboxCorners:b,planeN:x,planeOffset:P,polygonIndex:l})}return i}function Hu(e,n,t,o,r,i){let s=Ct(t),a=!!i&&(i[0]!==0||i[1]!==0||i[2]!==0),c=a?rn(n):null,f=Ar(e,n,a&&c&&i?(h,y)=>{let b=s(h,y),x=[b[0]-c[0],b[1]-c[1],b[2]-c[2]],P=Dn(x,i);return[P[0]+c[0],P[1]+c[1],P[2]+c[2]]}:s,o).map((h,y)=>{let{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A}=h,S=1/0,T=1/0,v=-1/0,R=-1/0;for(let Z of C)Z[0]<S&&(S=Z[0]),Z[1]<T&&(T=Z[1]),Z[0]>v&&(v=Z[0]),Z[1]>R&&(R=Z[1]);let O=v-S,L=R-T,D=r*50,_=b[0]+S*P[0]+T*M[0]+D*x[0],w=b[1]+S*P[1]+T*M[1]+D*x[1],V=b[2]+S*P[2]+T*M[2]+D*x[2],G=`matrix3d(${[P[0],P[1],P[2],0,M[0],M[1],M[2],0,x[0],x[1],x[2],0,_,w,V,1].map(Z=>Z.toFixed(4)).join(",")})`;return{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A,minU:S,minV:T,width:O,height:L,matrixCss:G,faceIndex:y,lift:D}}),d=.015,m=.5,p=20,g=new Set;for(let h=0;h<f.length;h++){if(g.has(h))continue;let y=f[h],b=y.n[0]*y.O[0]+y.n[1]*y.O[1]+y.n[2]*y.O[2],x=y.minU,P=y.minV,M=y.minU+y.width,C=y.minV+y.height;for(let E=0;E<f.length;E++){if(E===h||g.has(E))continue;let A=f[E];if(y.n[0]*A.n[0]+y.n[1]*A.n[1]+y.n[2]*A.n[2]<1-d)continue;let T=y.n[0]*A.O[0]+y.n[1]*A.O[1]+y.n[2]*A.O[2];if(T<=b+m||T-b>p)continue;let v=1/0,R=1/0,O=-1/0,L=-1/0;for(let D of A.outlineUv){let _=A.O[0]+D[0]*A.u[0]+D[1]*A.v[0],w=A.O[1]+D[0]*A.u[1]+D[1]*A.v[1],V=A.O[2]+D[0]*A.u[2]+D[1]*A.v[2],j=_-y.O[0],G=w-y.O[1],Z=V-y.O[2],ee=j*y.u[0]+G*y.u[1]+Z*y.u[2],W=j*y.v[0]+G*y.v[1]+Z*y.v[2];ee<v&&(v=ee),ee>O&&(O=ee),W<R&&(R=W),W>L&&(L=W)}if(v<=x&&O>=M&&R<=P&&L>=C){let D=Math.max(0,M-x)*Math.max(0,C-P);if(Math.max(0,O-v)*Math.max(0,L-R)>D*2)continue;g.add(h);break}}}return f=f.filter((h,y)=>!g.has(y)),f}function Pa(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:s,allPointLights:a,thisPointIndex:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=Math.hypot(i[0],i[1],i[2])||1,p=i[0]/m,g=i[1]/m,h=i[2]/m,y=!!s,b=y?_=>{let w=s[0]-_[0],V=s[1]-_[1],j=s[2]-_[2],G=Math.hypot(w,V,j)||1;return[w/G,V/G,j/G]}:_=>[p,g,h],x=u?.color??"#ffffff",P=u?.intensity??.4,M=f?.intensity??1,C=f?.color??"#ffffff",E=d?.color??"#000000",A=d?.opacity??.25,S=!y,T=d?.maxExtend??2e3,v=[],R=new Array(r.length).fill(!1),O=r.map((_,w)=>{if(y){if(_.overridePointSilhouettes){let W=_.overridePointSilhouettes[c??-1];if(W)return W}else if(_.overrideSilhouette)return _.overrideSilhouette}else if(_.overrideSilhouette)return _.overrideSilhouette;if(y){if(_.selfShadowEdgeMap)return R[w]=!0,null;let W=_.edgeOwners;if(!W)return null;let ie=_.casterPolygonCount??0;if(ie===0)return null;let z=new Array(ie).fill(!0);for(let X of _.items){if(X.polygonIndex>=ie)continue;let U=X.planeN;if(!U){z[X.polygonIndex]=!0;continue}let I=0,B=0,N=0;for(let k of X.wv)I+=k[0],B+=k[1],N+=k[2];let H=X.wv.length>0?1/X.wv.length:0,$=b([I*H,B*H,N*H]);z[X.polygonIndex]=U[0]*$[0]+U[1]*$[1]+U[2]*$[2]<-1e-6}return ba(W,z)?Mo(W,z):(R[w]=!0,null)}let V=_.edgeOwners;if(_.selfShadowEdgeMap)return R[w]=!0,null;if(!V)return null;let j=_.casterPolygonCount??0;if(j<Xu||_.items.length<Xu)return null;let G=0;for(let W of _.items)W.planeN&&G++;if(G*2<_.items.length)return null;let Z=new Array(j).fill(null);for(let W of _.items)W.planeN&&W.polygonIndex<j&&(Z[W.polygonIndex]=W.planeN);let ee=Wr(Z,i);return ba(V,ee)?Mo(V,ee):(R[w]=!0,null)}),L=(_,w,V,j)=>{if(_.length<3)return[];let G=[],Z=W=>(W[0]-w[0])*V[0]+(W[1]-w[1])*V[1]+(W[2]-w[2])*V[2],ee=(W,ie,z,X)=>{let U=(z-j)/(z-X);return[W[0]+U*(ie[0]-W[0]),W[1]+U*(ie[1]-W[1]),W[2]+U*(ie[2]-W[2])]};for(let W=0;W<_.length;W++){let ie=_[W],z=_[(W+_.length-1)%_.length],X=Z(ie),U=Z(z),I=X>j,B=U>j;I?(B||G.push(ee(z,ie,U,X)),G.push(ie)):B&&G.push(ee(z,ie,U,X))}return G},D={rotX:l.rotX,rotY:l.rotY};for(let _ of n){let{O:w,n:V,u:j,v:G,outlineUv:Z,minU:ee,minV:W,width:ie,height:z}=_,X=b(w),U=X[0]*V[0]+X[1]*V[1]+X[2]*V[2];if(U<=1e-6||!At(V,D))continue;let I=Math.max(0,p*V[0]+g*V[1]+h*V[2]),B=0,N=0;for(let re of Z)B+=re[0],N+=re[1];let H=Z.length>0?1/Z.length:0;B*=H,N*=H;let $=[w[0]+B*j[0]+N*G[0],w[1]+B*j[1]+N*G[1],w[2]+B*j[2]+N*G[2]],k=[],Q=0;if(a)for(let re=0;re<a.length;re++){let fe=a[re],me=fe.position[0]-$[0],Pe=fe.position[1]-$[1],ge=fe.position[2]-$[2],Fe=Math.hypot(me,Pe,ge)||1,Le=Math.max(0,me/Fe*V[0]+Pe/Fe*V[1]+ge/Fe*V[2]);k[re]=Le,Q+=(fe.intensity??1)*Le}let ae=re=>(re[0]-w[0])*V[0]+(re[1]-w[1])*V[1]+(re[2]-w[2])*V[2],se=(re,fe,me,Pe)=>{let ge=me/(me-Pe);return[re[0]+ge*(fe[0]-re[0]),re[1]+ge*(fe[1]-re[1]),re[2]+ge*(fe[2]-re[2])]},Y=re=>{let fe=re[0]-w[0],me=re[1]-w[1],Pe=re[2]-w[2],ge=y?b(re):[p,g,h],Fe=y?ge[0]*V[0]+ge[1]*V[1]+ge[2]*V[2]:U,Le=Fe>.001?Fe:.001,Oe=(fe*V[0]+me*V[1]+Pe*V[2])/Le,$e=re[0]-Oe*ge[0],ze=re[1]-Oe*ge[1],Ue=re[2]-Oe*ge[2],We=$e-w[0],be=ze-w[1],De=Ue-w[2];return[We*j[0]+be*j[1]+De*j[2],We*G[0]+be*G[1]+De*G[2]]},ne=new Map,le=0,ye=ee,Ce=W,Ve=_.minU+ie,Ee=_.minV+z,Me=1/0,Re=1/0,F=-1/0,q=-1/0;for(let re of r)for(let fe of re.items)for(let me of fe.wv){let Pe=me[0]-w[0],ge=me[1]-w[1],Fe=me[2]-w[2],Le=Pe*j[0]+ge*j[1]+Fe*j[2],Oe=Pe*G[0]+ge*G[1]+Fe*G[2];Le<Me&&(Me=Le),Le>F&&(F=Le),Oe<Re&&(Re=Oe),Oe>q&&(q=Oe)}let J=Number.isFinite(Me)?[[Me-T,Re-T],[F+T,Re-T],[F+T,q+T],[Me-T,q+T]]:[],te=.05,ue=V[0]*w[0]+V[1]*w[1]+V[2]*w[2],ce=.0025,he=5,Se=.94;for(let re=0;re<r.length;re++){let fe=r[re],me=fe.selfShadowEdgeMap,Pe=O[re];if(Pe!==null){if(Pe.length===0)continue;let ge=!!fe.overrideSilhouette,Fe=!1;if(ge){let Le=0;for(let Oe of Pe){if(Oe.length<3)continue;let $e=L(Oe,w,V,te);if($e.length<3)continue;let ze=$e.map(Y),Ue=0;for(let We=0;We<ze.length;We++){let be=ze[We],De=ze[(We+1)%ze.length];Ue+=be[0]*De[1]-De[0]*be[1]}Math.abs(Ue)>Le&&(Le=Math.abs(Ue),Fe=Ue<0)}}for(let Le of Pe){if(Le.length<3)continue;let Oe=L(Le,w,V,te);if(Oe.length<3)continue;let $e=Oe.map(Y),ze=ge?Fe?[...$e].reverse():$e:yn($e),Ue=J.length===4?Vn(ze,J):ze;if(Ue.length<3)continue;let We=Vn(Ue,Z);if(We.length<3)continue;let be;for(let De of _.memberPolysUv){let Ie=Vn(We,yn(De));Ie.length<3||(be||(be=ne.get(fe.id),be||(be={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,be))),be.verts.push(Ie),be.subPolygonIndices.push(-1),le++)}}continue}for(let ge of fe.items){if(me){let be=me.get(ge.polygonIndex);if(be){let De=!1;for(let Ie of _.memberPolyIndices)if(be.has(Ie)){De=!0;break}if(De){let Ie=ge.planeN;if(!Ie||Math.abs(Ie[0]*V[0]+Ie[1]*V[1]+Ie[2]*V[2])>Se)continue}}}if(ge.planeN&&!R[re]){let be=p,De=g,Ie=h;if(y){let Do=0,Fo=0,Bo=0;for(let kt of ge.wv)Do+=kt[0],Fo+=kt[1],Bo+=kt[2];let wn=ge.wv.length>0?1/ge.wv.length:0,dt=b([Do*wn,Fo*wn,Bo*wn]);be=dt[0],De=dt[1],Ie=dt[2]}if(ge.planeN[0]*be+ge.planeN[1]*De+ge.planeN[2]*Ie>-1e-6)continue}if(ge.planeN){let be=ge.planeN,De=be[0]*V[0]+be[1]*V[1]+be[2]*V[2];if(Math.abs(De)>1-ce){let Ie=De>0?1:-1;if(Math.abs(ge.planeOffset-Ie*ue)<he)continue}}let Fe=ge.bboxCorners,Le=!1,Oe=1/0,$e=1/0,ze=-1/0,Ue=-1/0;for(let be=0;be<8;be++){let De=Fe[be];ae(De)>te&&(Le=!0);let Ie=Y(De);Ie[0]<Oe&&(Oe=Ie[0]),Ie[0]>ze&&(ze=Ie[0]),Ie[1]<$e&&($e=Ie[1]),Ie[1]>Ue&&(Ue=Ie[1])}if(!Le||ze<ye||Oe>Ve||Ue<Ce||$e>Ee)continue;let We=ge.wv;for(let be=1;be<We.length-1;be++){let De=We[0],Ie=We[be],No=We[be+1],Do=ae(De),Fo=ae(Ie),Bo=ae(No),wn=[],dt=[[De,Do],[Ie,Fo],[No,Bo]];for(let pt=0;pt<3;pt++){let[Cn,zt]=dt[pt],[ko,Ut]=dt[(pt+1)%3],Gt=zt>te,zo=Ut>te;Gt&&wn.push(Cn),Gt!==zo&&wn.push(se(Cn,ko,zt,Ut))}if(wn.length<3)continue;let kt=wn.map(Y),mc=yn(kt),dc=J.length===4?Vn(mc,J):mc;if(dc.length<3)continue;let pc=Vn(dc,Z);if(pc.length<3)continue;let $n;for(let pt of _.memberPolysUv){let Cn=Vn(pc,yn(pt));if(!(Cn.length<3)){if(me){let zt=0,ko=1/0,Ut=-1/0,Gt=1/0,zo=-1/0;for(let Uo=0;Uo<Cn.length;Uo++){let gn=Cn[Uo],gc=Cn[(Uo+1)%Cn.length];zt+=gn[0]*gc[1]-gc[0]*gn[1],gn[0]<ko&&(ko=gn[0]),gn[0]>Ut&&(Ut=gn[0]),gn[1]<Gt&&(Gt=gn[1]),gn[1]>zo&&(zo=gn[1])}if(Math.abs(zt)*.5<5)continue}$n||($n=ne.get(fe.id),$n||($n={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,$n))),$n.verts.push(Cn),$n.subPolygonIndices.push(ge.polygonIndex),le++}}}}}if(le===0||!(ie>0)||!(z>0))continue;let ve=S?M*I:(a?.[c??-1]?.intensity??1)*(k[c??-1]??0),xe=M*I+Q+Math.max(0,P),K=A;if(o)if(xe>0){let re=Math.max(0,(xe-ve)/xe);K=A*(1-Math.pow(re,1/2.4))}else K=0;let oe=_.memberPolyIndices[0]??0,pe=t[oe]?.color??"#cccccc",qe=S?0:M*I,Ye=[];if(a)for(let re=0;re<a.length;re++){if(y&&re===c)continue;let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Ye.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let Ge=o?E:Rn(pe,qe,C,x,P,Ye),we=1/0,Ne=1/0,Je=-1/0,Qe=-1/0;for(let re of ne.values())for(let fe of re.verts)for(let me of fe)me[0]<we&&(we=me[0]),me[0]>Je&&(Je=me[0]),me[1]<Ne&&(Ne=me[1]),me[1]>Qe&&(Qe=me[1]);we=Math.floor(we-1),Ne=Math.floor(Ne-1),Je=Math.ceil(Je+1),Qe=Math.ceil(Qe+1),we<ee&&(we=ee),Ne<W&&(Ne=W),Je>ee+ie&&(Je=ee+ie),Qe>W+z&&(Qe=W+z);let Mn=Je-we,Sn=Qe-Ne;if(!(Mn>0)||!(Sn>0))continue;let Gn=_.lift,Bt=w[0]+we*j[0]+Ne*G[0]+Gn*V[0],ft=w[1]+we*j[1]+Ne*G[1]+Gn*V[1],An=w[2]+we*j[2]+Ne*G[2]+Gn*V[2],mt=`matrix3d(${[j[0],j[1],j[2],0,G[0],G[1],G[2],0,V[0],V[1],V[2],0,Bt,ft,An,1].map(re=>re.toFixed(4)).join(",")})`,je=[],en=[];for(let re of ne.values()){let fe="";for(let me of re.verts){fe+=`M${(me[0][0]-we).toFixed(1)},${(me[0][1]-Ne).toFixed(1)}`;for(let Pe=1;Pe<me.length;Pe++)fe+=`L${(me[Pe][0]-we).toFixed(1)},${(me[Pe][1]-Ne).toFixed(1)}`;fe+="Z",en.push(me.map(Pe=>[Pe[0],Pe[1]]))}je.push({casterId:re.id,d:fe,casterPolygonIndices:re.subPolygonIndices})}let Te=[];if(a)for(let re=0;re<a.length;re++){let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Te.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let ke=o?"":Rn(pe,M*I,C,x,P,Te);v.push({faceIndex:_.faceIndex,memberPolyIndices:_.memberPolyIndices,matrixCss:mt,width:Mn,height:Sn,fill:Ge,opacity:K,paths:je,fullLitFill:ke,facePolysUv:en})}return v}function gh(e,n){let t=gt(e)?.rgb??[0,0,0],o=gt(n)?.rgb??[255,255,255],r=i=>{let s=o[i]??0;return s<=0?255:Math.max(0,Math.min(255,Math.round(t[i]/s*255)))};return`rgb(${r(0)},${r(1)},${r(2)})`}function xa(e,n,t){let o="";for(let r of e)if(!(r.length<3)){o+=`M${(r[0][0]-n).toFixed(1)},${(r[0][1]-t).toFixed(1)}`;for(let i=1;i<r.length;i++)o+=`L${(r[i][0]-n).toFixed(1)},${(r[i][1]-t).toFixed(1)}`;o+="Z"}return o}function Ku(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,runDirectional:s,pointPasses:a,allPointLights:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=d?.opacity??.25,p=new Map;for(let b of n)p.set(b.faceIndex,b);let g=new Map,h=(b,x)=>{let P=Pa({receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:b,allPointLights:c,thisPointIndex:x,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d});for(let M of P){if(M.facePolysUv.length===0)continue;let C=M.fullLitFill!=="",E=g.get(M.faceIndex);E||(E={memberPolyIndices:M.memberPolyIndices,base:M.fullLitFill,solid:C,layers:[]},g.set(M.faceIndex,E)),E.layers.push({polys:M.facePolysUv,fill:M.fill,opacity:M.opacity})}};s&&h(void 0,void 0);for(let b of a)h(b.lightPos,b.index);let y=[];for(let[b,x]of g){let P=p.get(b);if(!P||x.layers.length===0)continue;let M=1/0,C=1/0,E=-1/0,A=-1/0;for(let z of x.layers)for(let X of z.polys)for(let U of X)U[0]<M&&(M=U[0]),U[0]>E&&(E=U[0]),U[1]<C&&(C=U[1]),U[1]>A&&(A=U[1]);if(!Number.isFinite(M))continue;M=Math.floor(M-1),C=Math.floor(C-1),E=Math.ceil(E+1),A=Math.ceil(A+1);let S=E-M,T=A-C;if(!(S>0)||!(T>0))continue;let{O:v,u:R,v:O,n:L,lift:D}=P,_=v[0]+M*R[0]+C*O[0]+D*L[0],w=v[1]+M*R[1]+C*O[1]+D*L[1],V=v[2]+M*R[2]+C*O[2]+D*L[2],G=`matrix3d(${[R[0],R[1],R[2],0,O[0],O[1],O[2],0,L[0],L[1],L[2],0,_,w,V,1].map(z=>z.toFixed(4)).join(",")})`,Z=x.solid&&x.layers.length>1,ee=null,W=null,ie=[];if(Z){ee=x.base,W="";for(let z of x.layers)W+=xa(z.polys,M,C);for(let z of x.layers)ie.push({d:xa(z.polys,M,C),fill:gh(z.fill,x.base),multiply:!0,opacity:1})}else for(let z of x.layers)ie.push({d:xa(z.polys,M,C),fill:z.fill,multiply:!1,opacity:z.opacity});y.push({faceIndex:b,memberPolyIndices:x.memberPolyIndices,matrixCss:G,width:S,height:T,svgOpacity:Z?m:1,baseFill:ee,baseD:W,layers:ie})}return y}var hh=Symbol.for("polycss.animation.triangleFrameSource"),yh=Symbol.for("polycss.animation.triangleFrameTarget"),Sa=2200,Hr=2201,Aa=2202;function bh(e,n){let t=0,o=1,r=1,i=Hr,s=1/0,a=0,c=!1,l=null,u=!0,f=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(m){r=m},get weight(){return o},set weight(m){o=m},get time(){return t},set time(m){t=m},get isRunning(){return c},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return c=!0,d},stop(){return c=!1,t=0,a=0,l=null,d},reset(){return t=0,a=0,d},fadeIn(m){return l={from:0,to:1,elapsed:0,duration:m},o=0,d},fadeOut(m){return l={from:o,to:0,elapsed:0,duration:m},d},crossFadeTo(m,p){return d.fadeOut(p),m.fadeIn(p),d},crossFadeFrom(m,p){return m.fadeOut(p),d.fadeIn(p),d},setLoop(m,p){return i=m,s=p,d},setEffectiveTimeScale(m){return r=m,d},setEffectiveWeight(m){return o=m,d}};return d._internal={get clip(){return e},get time(){return t},get weight(){return o},get enabled(){return u},get paused(){return f},get running(){return c},get loopMode(){return i},get repetitions(){return s},get completedReps(){return a},set completedReps(m){a=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!c)return;if(l){l.elapsed+=m;let g=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(o=l.from+(l.to-l.from)*g,g>=1&&(o=l.to,l=null,o<=0)){c=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(t+=m*r,i===Sa)t>=p&&(t=d.clampWhenFinished?p:0,c=!1);else if(i===Hr){if(t>=p){let g=t%p,h=Math.floor(t/p);a+=h,t=g,s!==1/0&&a>=s&&(t=d.clampWhenFinished?p:0,c=!1)}}else if(p>0){let g=p*2,h=t%g;if(t>=g){let y=Math.floor(t/g);a+=y,s!==1/0&&a>=s?(t=d.clampWhenFinished?p:0,c=!1):t=h}}}},sampleTime(){if(i===Aa){let m=e.duration,p=m*2,g=t%p;return g<=m?g:p-g}return t}},d}function xh(e){return e._internal}function Ma(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function Zu(e,n){let t=new Map,o=n,r=e;function i(f){let d=Ma(n.clips,f);if(!d)throw new Error(`PolyAnimationMixer: no clip found for key "${f}". Available: ${n.clips.map(p=>p.name).join(", ")}`);let m=t.get(d.index);return m||(m=bh(d,n),t.set(d.index,m)),m}function s(f){let d=Ma(n.clips,f);return d?t.get(d.index)??null:null}function a(f){let d=[];for(let y of t.values()){let b=xh(y);b.advance(f),b.running&&b.enabled&&d.push({internal:b,clip:b.clip})}if(d.length===0)return;if(d.length===1){let{internal:y,clip:b}=d[0],x=y.sampleTime(),P=o[hh]?.(b.name,x);if(P&&r[yh]?.(P))return;let M=n.sample(b.name,x);e.setPolygons(M);return}let m=0;for(let{internal:y}of d)m+=y.weight;if(m<=0)return;let p=d.map(({internal:y,clip:b})=>({polygons:n.sample(b.name,y.sampleTime()),weight:y.weight/m})),g=p[0].polygons;if(g.length===0)return;let h=g.map((y,b)=>{let x=y.vertices.map((P,M)=>{let C=0,E=0,A=0;for(let{polygons:S,weight:T}of p){let v=S[b];if(!v)continue;let R=v.vertices[M];R&&(C+=R[0]*T,E+=R[1]*T,A+=R[2]*T)}return[C,E,A]});return{...y,vertices:x}});e.setPolygons(h)}function c(){for(let f of t.values())f.stop()}function l(f){let d=Ma(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:i,existingAction:s,update:a,stopAllAction:c,uncacheClip:l,uncacheRoot:u}}var Ta={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},nf={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ph={0:"POINTS",1:"LINES",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN"},Ea=["EXT_meshopt_compression","KHR_meshopt_compression"];function Mh(e){return e===5120||e===5121||e===5122||e===5123}function tf(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Sh(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let t=e.slice(5,n),o=e.slice(n+1);if(!t.includes(";base64")){let s=decodeURIComponent(o),a=new Uint8Array(s.length);for(let c=0;c<s.length;c++)a[c]=s.charCodeAt(c)&255;return a}let r=globalThis.atob(o),i=new Uint8Array(r.length);for(let s=0;s<r.length;s++)i[s]=r.charCodeAt(s);return i}function Ah(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let t=n.getUint32(4,!0);if(t!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${t})`);let o=12,r=null,i=null;for(;o<e.byteLength;){let s=n.getUint32(o,!0),a=n.getUint32(o+4,!0),c=o+8;if(a===1313821514){let l=new Uint8Array(e,c,s);r=JSON.parse(tf(l))}else a===5130562&&(i=new Uint8Array(e,c,s));o=c+s}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:i}}function qu(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function Ch(e){let n=qu(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=qu(e.asset?.minVersion);if(e.asset?.minVersion&&(!t||t[0]>2||t[0]===2&&t[1]>0))throw new Error(`parseGltf: glTF asset requires minVersion ${e.asset.minVersion}`)}function Th(e,n,t){let o=e.buffers??[],r=new Set(e.extensionsRequired??[]),i=Ea.some(s=>r.has(s));return o.map((s,a)=>{let c=s.uri;if(c){if(c.startsWith("data:"))return Sh(c);if(t){let l=t(c);if(l instanceof Uint8Array)return l;throw new Error("parseGltf: resolveBuffer returned a Promise; use parseGltf via async if your buffers are external")}throw new Error(`parseGltf: external buffer URI "${c}" \u2014 provide options.resolveBuffer`)}if(a===0&&n)return n;if(i&&Ea.some(l=>s.extensions?.[l]))return new Uint8Array(0);throw new Error(`parseGltf: buffer[${a}] has no uri and no GLB BIN chunk`)})}function Ao(e,n,t){let o=e.bufferViews?.[t],r=o?n[o.buffer]:void 0;if(!o||!r)throw new Error(`parseGltf: bad bufferView ${t}`);let i=o.byteOffset??0;if(i<0||o.byteLength<0||i+o.byteLength>r.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${o.buffer}`);return{buffer:r,view:o}}function of(e,n,t,o){if(e.count<=0)return;let r=e.byteOffset??0,i=r+t*(e.count-1)+o;if(r<0||i>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function rf(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function Eh(e,n,t){if(t||e===5126)return new Float32Array(n);switch(e){case 5120:return new Int8Array(n);case 5121:return new Uint8Array(n);case 5122:return new Int16Array(n);case 5123:return new Uint16Array(n);case 5125:return new Uint32Array(n);default:throw new Error(`parseGltf: unhandled componentType ${e}`)}}function Kr(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Ta[o.componentType],i=nf[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);if(o.sparse||o.normalized||o.bufferView===void 0){let{values:h}=Co(e,n,t);return{array:Eh(o.componentType,h,o.normalized),count:o.count,componentCount:i}}let{buffer:s,view:a}=Ao(e,n,o.bufferView),c=(a.byteOffset??0)+(o.byteOffset??0),l=o.count*i,u=r*i,f=rf(a,u);if(of(o,a,f,u),f===u){let h=s.buffer.slice(s.byteOffset+c,s.byteOffset+c+l*r),y;switch(o.componentType){case 5120:y=new Int8Array(h);break;case 5121:y=new Uint8Array(h);break;case 5122:y=new Int16Array(h);break;case 5123:y=new Uint16Array(h);break;case 5125:y=new Uint32Array(h);break;case 5126:y=new Float32Array(h);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}return{array:y,count:o.count,componentCount:i}}let d;switch(o.componentType){case 5120:d=new Int8Array(l);break;case 5121:d=new Uint8Array(l);break;case 5122:d=new Int16Array(l);break;case 5123:d=new Uint16Array(l);break;case 5125:d=new Uint32Array(l);break;case 5126:d=new Float32Array(l);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}let m=new DataView(s.buffer),p=s.byteOffset+c,g=0;for(let h=0;h<o.count;h++){let y=p+h*f;for(let b=0;b<i;b++)d[g++]=Qr(m,y+b*r,o.componentType)}return{array:d,count:o.count,componentCount:i}}function Qr(e,n,t){switch(t){case 5120:return e.getInt8(n);case 5121:return e.getUint8(n);case 5122:return e.getInt16(n,!0);case 5123:return e.getUint16(n,!0);case 5125:return e.getUint32(n,!0);case 5126:return e.getFloat32(n,!0);default:throw new Error(`parseGltf: unhandled componentType ${t}`)}}function Qu(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 Co(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Ta[o.componentType],i=nf[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);let s=r*i,a=new Array(o.count*i).fill(0);if(o.bufferView!==void 0){let{buffer:c,view:l}=Ao(e,n,o.bufferView),u=c.byteOffset+(l.byteOffset??0)+(o.byteOffset??0),f=rf(l,s);of(o,l,f,s);let d=new DataView(c.buffer),m=0;for(let p=0;p<o.count;p++){let g=u+p*f;for(let h=0;h<i;h++){let y=Qr(d,g+h*r,o.componentType);a[m++]=o.normalized?Qu(y,o.componentType):y}}}if(o.sparse){let c=o.sparse,l=c.indices,u=Ta[l.componentType];if(l.componentType!==5121&&l.componentType!==5123&&l.componentType!==5125)throw new Error(`parseGltf: unhandled sparse index componentType ${l.componentType}`);let{buffer:f,view:d}=Ao(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),p=new DataView(f.buffer),{buffer:g,view:h}=Ao(e,n,c.values.bufferView),y=g.byteOffset+(h.byteOffset??0)+(c.values.byteOffset??0),b=new DataView(g.buffer);for(let x=0;x<c.count;x++){let P=Qr(p,m+x*u,l.componentType);for(let M=0;M<i;M++){let C=Qr(b,y+(x*i+M)*r,o.componentType);a[P*i+M]=o.normalized?Qu(C,o.componentType):C}}}return{values:a,count:o.count,componentCount:i}}function vh(e,n,t){let o=[],r=[],i=globalThis;for(let s of e.images??[]){if(s.uri){if(t&&!s.uri.startsWith("data:"))try{o.push(new i.URL(s.uri,t).href)}catch{o.push(s.uri)}else o.push(s.uri);continue}if(s.bufferView!==void 0){let a;try{let{buffer:f,view:d}=Ao(e,n,s.bufferView),m=d.byteOffset??0;a=f.subarray(m,m+d.byteLength)}catch{o.push("");continue}let c=s.mimeType??"image/png",l=new i.Blob([a],{type:c}),u=i.URL.createObjectURL(l);o.push(u),r.push(u)}else o.push("")}return{urls:o,objectUrls:r}}function Ju(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function Ih(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:Ju(t?.wrapS),t:Ju(t?.wrapT)}}function sf(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function _h(e,n){let t=new Map,o=e.materials??[];for(let r=0;r<o.length;r++){let i=o[r].pbrMetallicRoughness?.baseColorTexture?.index;if(i===void 0)continue;let s=e.textures?.[i],a=s?.source;if(a===void 0)continue;let c=n[a];c&&t.set(r,{url:c,wrap:Ih(e,s),alphaMode:sf(o[r].alphaMode),texCoord:o[r].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function Vh(e,n,t){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let r=c=>Math.max(0,Math.min(1,c)),i=c=>Math.round(r(c)*255).toString(16).padStart(2,"0"),s=c=>Math.round(r(c)*255),a=t==="opaque"?1:r(o[3]??1);return a<1?`rgba(${s(o[0])}, ${s(o[1])}, ${s(o[2])}, ${Math.round(a*1e3)/1e3})`:`#${i(o[0])}${i(o[1])}${i(o[2])}`}var vt=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function af(e,n){let t=new Array(16);return cf(t,e,n)}function cf(e,n,t){for(let o=0;o<4;o++)for(let r=0;r<4;r++)e[r*4+o]=n[0+o]*t[r*4+0]+n[4+o]*t[r*4+1]+n[8+o]*t[r*4+2]+n[12+o]*t[r*4+3];return e}function Zr(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 lf(e,n,t){let o=e?.[0]??0,r=e?.[1]??0,i=e?.[2]??0,s=n?.[0]??0,a=n?.[1]??0,c=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=s+s,p=a+a,g=c+c,h=s*m,y=s*p,b=s*g,x=a*p,P=a*g,M=c*g,C=l*m,E=l*p,A=l*g;return[(1-(x+M))*u,(y+A)*u,(b-E)*u,0,(y-A)*f,(1-(h+M))*f,(P+C)*f,0,(b+E)*d,(P-C)*d,(1-(h+x))*d,0,o,r,i,1]}function Oh(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():lf(e.translation,e.rotation,e.scale)}function uf(e,n,t){let o=new Array(Math.min(e.length,n.length));for(let r=0;r<o.length;r++)o[r]=e[r]+(n[r]-e[r])*t;return o}function So(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 Rh(e,n,t){let o=So(e),r=So(n),i=o[0]*r[0]+o[1]*r[1]+o[2]*r[2]+o[3]*r[3];if(i<0&&(i=-i,r=[-r[0],-r[1],-r[2],-r[3]]),i>.9995)return So(uf(o,r,t));let s=Math.acos(Math.max(-1,Math.min(1,i))),a=Math.sin(s),c=Math.sin((1-t)*s)/a,l=Math.sin(t*s)/a;return So([o[0]*c+r[0]*l,o[1]*c+r[1]*l,o[2]*c+r[2]*l,o[3]*c+r[3]*l])}function ff(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 mf(e){return e.matrix?e.matrix.slice():lf(e.translation,e.rotation,e.scale)}function Lh(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function df(e,n){let t=e.nodes??[],o=new Array(t.length),r=new Set,i=new Set,s=(c,l)=>{if(c<0||c>=t.length||i.has(c))return;let u=af(l,n[c]??vt);o[c]=u,r.add(c),i.add(c);for(let f of t[c].children??[])s(f,u);i.delete(c)},a=Lh(e);if(a.length>0)for(let c of a)s(c,vt);for(let c=0;c<t.length;c++)r.has(c)||s(c,vt);return o}var pf=Symbol("polycss.gltfAnimationRuntimeInfo"),wh=Symbol.for("polycss.animation.triangleFrameSource");function gf(e,n){return e?e[pf]?.withPolygonFilter(n):void 0}function Ca(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Nh(e,n,t){return Ca(e,n)||Ca(e,t)||Ca(n,t)}function ef(e,n,t,o,r){if(t===void 0)return;let{values:i,count:s,componentCount:a}=Co(e,n,t);if(s!==r||a<1)return;let c=[];for(let l=0;l<s;l++){let u=[];for(let f=0;f<o;f++)u.push(i[l*a+f]??0);c.push(u)}return c}function Dh(e,n,t,o){if(t===void 0)return Array.from({length:o},()=>vt.slice());let{values:r,componentCount:i,count:s}=Co(e,n,t);if(i!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${t} is not MAT4`);let a=[];for(let c=0;c<o;c++){let l=Math.min(c,s-1);a.push(r.slice(l*16,l*16+16))}return a}function qr(e,n){let t=e.componentCount,o=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(o,o+t)}function Fh(e,n,t){let o=e.input;if(o.length===0)return[];if(o.length===1||n<=o[0])return qr(e,0);let r=o.length-1;if(n>=o[r])return qr(e,r);let i=0,s=r;for(;i+1<s;){let d=i+s>>1;o[d]<=n?i=d:s=d}let a=o[i],c=o[i+1],l=c>a?(n-a)/(c-a):0,u=qr(e,i),f=qr(e,i+1);return e.interpolation==="STEP"?u:t==="rotation"?Rh(u,f,l):uf(u,f,l)}function hf(e,n){let t=[];for(let o=0;o<(e.animations?.length??0);o++){let r=e.animations[o],i=(r.samplers??[]).map(c=>{let l=Co(e,n,c.input),u=Co(e,n,c.output);return{input:l.values,output:u.values,componentCount:u.componentCount,interpolation:c.interpolation??"LINEAR"}}),s=[];for(let c of r.channels??[]){let l=c.target.node,u=c.target.path,f=i[c.sampler];l===void 0||!u||!f||u!=="translation"&&u!=="rotation"&&u!=="scale"||s.push({sampler:f,targetNode:l,path:u})}let a=s.reduce((c,l)=>{let u=l.sampler.input;return Math.max(c,u[u.length-1]??0)},0);t.push({info:{index:o,name:r.name??`animation_${o}`,duration:a,channelCount:s.length},channels:s})}return t}function yf(e,n,t,o){let r=t.info.duration,i=r>0?(o%r+r)%r:Math.max(0,o),s=n.map(a=>({translation:a.translation.slice(),rotation:a.rotation.slice(),scale:a.scale.slice(),matrix:a.matrix?a.matrix.slice():void 0}));for(let a of t.channels){let c=s[a.targetNode];if(!c)continue;let l=Fh(a.sampler,i,a.path);c.matrix=void 0,a.path==="translation"?c.translation=l.slice(0,3):a.path==="rotation"?c.rotation=So(l.slice(0,4)):a.path==="scale"&&(c.scale=l.slice(0,3))}return df(e,s.map(mf))}function Bh(e,n,t,o,r,i){if((e.animations??[]).length===0||t.length===0)return;let a=(e.nodes??[]).map(h=>ff(h)),c=a.map(mf),l=df(e,c),u=(e.skins??[]).map(h=>({joints:h.joints??[],inverseBindMatrices:Dh(e,n,h.inverseBindMatrices,h.joints?.length??0)})),f=hf(e,n),d=f.map(h=>h.info);if(d.length===0)return;let m=h=>{let y=t.map(b=>new Array(b.triangleMask.length).fill(!1));for(let b of h){let x=o[b];if(!x)return;let P=y[x.sourceIndex];if(!P||x.triangleIndex<0||x.triangleIndex>=P.length)return;P[x.triangleIndex]=!0}return y.map((b,x)=>{let P=t[x],M=new Set,C=0;for(let E=0;E+2<P.indices.length;E+=3,C++)b[C]&&(M.add(P.indices[E]),M.add(P.indices[E+1]),M.add(P.indices[E+2]));return{triangleMask:b,activeVertices:Array.from(M).sort((E,A)=>E-A)}})},p=(h,y,b,x,P,M,C,E,A)=>{let S=r(h),T=r(y),v=r(b),R={vertices:[S,T,v],color:x};return P&&(R.texture=P),P&&M&&(R.textureWrap=M),P&&C&&(R.textureAlphaMode=C),E&&(R.doubleSided=!0),A&&(R.uvs=A),R},g=h=>{let y=t.reduce((O,L,D)=>{let _=h?.[D]?.triangleMask??L.triangleMask,w=0;for(let V=0;V<_.length;V++)_[V]&&w++;return O+w},0),b=new Float64Array(Math.max(0,y*9)),x=new Array(y),P=new Array(y).fill(!1),M={polygonCount:0,vertices:b,colors:x,textureFlags:P,solidTriangles:!0},C=t.map(O=>new Array(O.positions.length)),E=u.map(O=>O.joints.map(()=>new Array(16))),A=(O,L)=>{let D=typeof O=="number"?f[O]:f.find(_=>_.info.name===O);return D?yf(e,a,D,L):null},S=(O,L,D,_)=>{let w=D?.activeVertices,V=C[O],j=(G,Z,ee,W)=>{let ie=V[G];ie?(ie[0]=Z,ie[1]=ee,ie[2]=W):V[G]=[Z,ee,W]};if(L.skinIndex!==void 0&&L.joints&&L.weights&&u[L.skinIndex]){let G=u[L.skinIndex],Z=L.joints,ee=L.weights,W=E[L.skinIndex]??[];for(let z=0;z<G.joints.length;z++){let X=G.joints[z],U=_[X],I=G.inverseBindMatrices[z],B=W[z]??(W[z]=new Array(16));W[z]=U&&I?cf(B,U,I):void 0}let ie=z=>{let X=L.positions[z],U=0,I=0,B=0,N=0,H=Z[z]??[],$=ee[z]??[];for(let k=0;k<4;k++){let Q=$[k]??0;if(Q<=0)continue;let ae=Math.round(H[k]??0),se=W[ae];if(!se)continue;let Y=se[0]*X[0]+se[4]*X[1]+se[8]*X[2]+se[12],ne=se[1]*X[0]+se[5]*X[1]+se[9]*X[2]+se[13],le=se[2]*X[0]+se[6]*X[1]+se[10]*X[2]+se[14];U+=Y*Q,I+=ne*Q,B+=le*Q,N+=Q}if(N>0){let k=1/N;j(z,U*k,I*k,B*k)}else j(z,L.meshBindWorld[0]*X[0]+L.meshBindWorld[4]*X[1]+L.meshBindWorld[8]*X[2]+L.meshBindWorld[12],L.meshBindWorld[1]*X[0]+L.meshBindWorld[5]*X[1]+L.meshBindWorld[9]*X[2]+L.meshBindWorld[13],L.meshBindWorld[2]*X[0]+L.meshBindWorld[6]*X[1]+L.meshBindWorld[10]*X[2]+L.meshBindWorld[14])};if(w)for(let z of w)ie(z);else for(let z=0;z<L.positions.length;z++)ie(z)}else{let G=L.meshNode!==null?_[L.meshNode]??L.meshBindWorld:L.meshBindWorld,Z=ee=>{let W=L.positions[ee];j(ee,G[0]*W[0]+G[4]*W[1]+G[8]*W[2]+G[12],G[1]*W[0]+G[5]*W[1]+G[9]*W[2]+G[13],G[2]*W[0]+G[6]*W[1]+G[10]*W[2]+G[14])};if(w)for(let ee of w)Z(ee);else for(let ee=0;ee<L.positions.length;ee++)Z(ee)}return V},T=(O,L)=>{let D=A(O,L);if(!D)return[];let _=[];for(let w=0;w<t.length;w++){let V=t[w],j=h?.[w],G=j?.triangleMask??V.triangleMask,Z=S(w,V,j,D),ee=0;for(let W=0;W+2<V.indices.length;W+=3,ee++){if(!G[ee])continue;let ie=V.indices[W],z=V.indices[W+1],X=V.indices[W+2],U=Z[ie],I=Z[z],B=Z[X];if(!U||!I||!B)continue;let N;if(V.uvs&&V.texture){let $=V.uvs[ie],k=V.uvs[z],Q=V.uvs[X];$&&k&&Q&&(N=[$,k,Q])}let H=p(U,I,B,V.color,V.texture,V.textureWrap,V.textureAlphaMode,V.doubleSided,N);H&&_.push(H)}}return _},v=(O,L)=>{let D=A(O,L);if(!D)return null;b.length<y*9&&(b=new Float64Array(y*9),M.vertices=b),x.length<y&&(x=new Array(y),M.colors=x),P.length<y&&(P=new Array(y).fill(!1),M.textureFlags=P);let _=0,w=0,V=!1;for(let j=0;j<t.length;j++){let G=t[j],Z=h?.[j],ee=Z?.triangleMask??G.triangleMask,W=S(j,G,Z,D),ie=0;for(let z=0;z+2<G.indices.length;z+=3,ie++){if(!ee[ie])continue;let X=G.indices[z],U=G.indices[z+1],I=G.indices[z+2],B=W[X],N=W[U],H=W[I];if(!B||!N||!H)continue;i(B,b,w),i(N,b,w+3),i(H,b,w+6),x[_]=G.color;let $=!!G.texture;P[_]=$,$&&(V=!0),_++,w+=9}}return M.polygonCount=_,M.solidTriangles=!V,M},R={clips:d,sample:T};return R[wh]=v,R[pf]={withPolygonFilter(O){let L=m(O);return L?g(L):void 0}},R};return g()}function Jr(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.materialColors??{},i=n?.materialTextures??{},s=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,a=s.byteLength,c,l=null;if(s.byteLength>=4&&new DataView(s).getUint32(0,!0)===1179937895){let F=Ah(s);c=F.doc,l=F.bin}else c=JSON.parse(tf(new Uint8Array(s)));Ch(c);let u=Th(c,l,n?.resolveBuffer),{urls:f,objectUrls:d}=vh(c,u,n?.baseUrl),m=_h(c,f),p=[],g=new Set,h=new Set(c.extensionsRequired??[]),y=h.has("KHR_mesh_quantization")||(c.extensionsUsed??[]).includes("KHR_mesh_quantization");function b(F,q){g.has(F)||(g.add(F),p.push(q))}function x(F,q){if(F===void 0)return!1;let J=c.accessors?.[F];if(!J)return!1;let te=ue=>c.bufferViews?.[ue]?.extensions?.[q]!==void 0;return!!(J.bufferView!==void 0&&te(J.bufferView)||J.sparse&&(te(J.sparse.indices.bufferView)||te(J.sparse.values.bufferView)))}function P(F){for(let q of Ea)if(h.has(q)&&(F.extensions?.[q]||x(F.indices,q)||Object.values(F.attributes??{}).some(J=>x(J,q))))return q}function M(F,q){if(q instanceof Float32Array)return!0;let J=c.accessors?.[F];return y&&J?.type==="VEC3"&&Mh(J.componentType)}function C(F,q){return(q!==null?c.nodes?.[q]?.weights:void 0)??F.weights??[]}function E(F,q,J,te,ue){let ce=J.targets;if(!ce||ce.length===0)return;let he=C(F,te);if(!he.some(xe=>Number.isFinite(xe)&&xe!==0))return;let Se=Array.from({length:ue},()=>[0,0,0]),ve=!1;for(let xe=0;xe<ce.length;xe++){let K=he[xe]??0;if(!Number.isFinite(K)||K===0)continue;let oe=ce[xe]?.POSITION;if(oe===void 0)continue;let{array:pe,count:qe,componentCount:Ye}=Kr(c,u,oe);if(qe!==ue||Ye<3){b(`morph-position-count:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with mismatched count`);continue}if(!M(oe,pe)){b(`morph-position-type:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with unsupported accessor type`);continue}ve=!0;for(let Ge=0;Ge<ue;Ge++){let we=Ge*Ye,Ne=Se[Ge];Ne[0]+=Number(pe[we])*K,Ne[1]+=Number(pe[we+1])*K,Ne[2]+=Number(pe[we+2])*K}}return ve?Se:void 0}let A=[],S=[],T=[],v=(c.meshes??[]).map((F,q)=>F.name??`mesh_${q}`),R=(c.materials??[]).map((F,q)=>F.name??`material_${q}`);function O(F,q){if(q===4)return F;let J=[];if(q===5)for(let te=0;te+2<F.length;te++)J.push(F[te],F[te+1+te%2],F[te+2-te%2]);else if(q===6)for(let te=0;te+2<F.length;te++)J.push(F[te+1],F[te+2],F[0]);return J}function L(F){let q=[];for(let J=0;J+2<F.length;J+=3){let te=F[J],ue=F[J+1],ce=F[J+2];q.push(te,ue,ce,te,ce,ue)}return q}function D(F,q,J){let te=c.meshes?.[F];if(te){if(!Array.isArray(te.primitives)){b(`malformed-primitives:${F}`,`Mesh ${te.name??F}: skipped mesh with non-array primitives`);return}for(let ue=0;ue<te.primitives.length;ue+=1){let ce=te.primitives[ue];if(!ce)continue;let he=ce.mode??4;if(he!==4&&he!==5&&he!==6){let Te=Ph[he]??`mode ${he}`;b(`unsupported-mode:${he}`,`Skipped primitives with unsupported mode ${he} (${Te})`);continue}if(ce.extensions?.KHR_draco_mesh_compression&&h.has("KHR_draco_mesh_compression")){b("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}let Se=P(ce);if(Se){b(Se,`Skipped primitives with unsupported required extension ${Se}`);continue}if(ce.attributes.POSITION===void 0){b(`missing-position:${F}`,`Mesh ${te.name??F}: skipped primitive without POSITION attribute`);continue}let ve=ce.material!==void 0?c.materials?.[ce.material]:void 0,xe=sf(ve?.alphaMode),K=ve?.name,pe=(K?r[K]:void 0)??Vh(ve,o,xe),qe=ve?.doubleSided===!0,Ye=ce.material!==void 0?m.get(ce.material):void 0,Ge=K&&i[K]?i[K]:ce.material!==void 0?Ye?.url:void 0,we=Ge&&ce.material!==void 0?Ye?.wrap:void 0,Ne=Ge?Ye?.alphaMode??xe:void 0,Je=Ge?Ye?.texCoord??0:0,Qe=ce.attributes.POSITION,{array:Mn,count:Sn,componentCount:Gn}=Kr(c,u,Qe);if(!M(Qe,Mn))continue;let Bt=E(te,F,ce,J,Sn),ft=[],An=[];for(let Te=0;Te<Sn;Te++){let ke=Te*Gn,re=Bt?.[Te],fe=[Number(Mn[ke])+(re?.[0]??0),Number(Mn[ke+1])+(re?.[1]??0),Number(Mn[ke+2])+(re?.[2]??0)];ft.push(fe),An.push(Zr(q,fe))}let pn=null,mt=ce.attributes[`TEXCOORD_${Je}`];if(Ge&&mt!==void 0){let{array:Te,count:ke}=Kr(c,u,mt);pn=[];let re=1;Te instanceof Uint8Array?re=1/255:Te instanceof Uint16Array&&(re=1/65535);for(let fe=0;fe<ke;fe++){let me=Te[fe*2]*re,Pe=Te[fe*2+1]*re;pn.push([me,1-Pe])}}let je;if(ce.indices!==void 0){let{array:Te,count:ke}=Kr(c,u,ce.indices);je=[];for(let re=0;re<ke;re++)je.push(Number(Te[re]))}else je=An.map((Te,ke)=>ke);je=O(je,he),qe&&(je=L(je));let en;if((c.animations?.length??0)>0){let Te=ef(c,u,ce.attributes.JOINTS_0,4,Sn),ke=ef(c,u,ce.attributes.WEIGHTS_0,4,Sn);en={sourceIndex:S.length,meshNode:J,meshBindWorld:q,skinIndex:J!==null?c.nodes?.[J]?.skin:void 0,positions:ft,indices:je,triangleMask:[],color:pe,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:pn??void 0,joints:Te,weights:ke},S.push(en)}for(let Te=0;Te+2<je.length;Te+=3){let ke=je[Te],re=je[Te+1],fe=je[Te+2],me=en?en.triangleMask.length:void 0;en&&en.triangleMask.push(!1);let Pe=An[ke],ge=An[re],Fe=An[fe];if(!Pe||!ge||!Fe)continue;let Le;if(pn&&Ge){let $e=pn[ke],ze=pn[re],Ue=pn[fe];$e&&ze&&Ue&&(Le=[$e,ze,Ue])}let Oe=`${F}:${ue}:${J??"root"}`;A.push({v0:Pe,v1:ge,v2:Fe,color:pe,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:Le,simplifySourceVertexKeys:[`${Oe}:${ke}`,`${Oe}:${re}`,`${Oe}:${fe}`],source:en,sourceIndex:en?.sourceIndex,sourceTriangleIndex:me})}}}}function _(F,q,J){if(J.has(F)){b(`recursive-node:${F}`,`Skipped recursive node reference ${F} in glTF scene graph`);return}let te=c.nodes?.[F];if(!te)return;let ue=af(q,Oh(te));typeof te.mesh=="number"&&D(te.mesh,ue,F),J.add(F);for(let ce of te.children??[])_(ce,ue,J);J.delete(F)}function w(F){let q=new Set,J=F.info.duration;for(let te of F.channels)for(let ue of te.sampler.input)!Number.isFinite(ue)||ue<=0||J>0&&ue>=J||q.add(ue);return J>0&&(q.add(J*.25),q.add(J*.5),q.add(J*.75)),Array.from(q).sort((te,ue)=>te-ue).slice(0,128)}function V(F,q){let J=F.source;if(!J||F.sourceTriangleIndex===void 0||J.skinIndex!==void 0)return;let te=F.sourceTriangleIndex*3,ue=J.indices[te],ce=J.indices[te+1],he=J.indices[te+2],Se=ue!==void 0?J.positions[ue]:void 0,ve=ce!==void 0?J.positions[ce]:void 0,xe=he!==void 0?J.positions[he]:void 0;if(!Se||!ve||!xe)return;let K=J.meshNode!==null?q[J.meshNode]??J.meshBindWorld:J.meshBindWorld;return{v0:Zr(K,Se),v1:Zr(K,ve),v2:Zr(K,xe)}}function j(F,q){return F[0]===q[0]&&F[1]===q[1]&&F[2]===q[2]}function G(F){return j(F.v0,F.v1)||j(F.v0,F.v2)||j(F.v1,F.v2)}function Z(){return A.some(F=>!G(F))}function ee(){if(A.length===0||(c.animations?.length??0)===0||Z())return;let F=hf(c,u);if(F.length===0)return;let q=(c.nodes??[]).map(te=>ff(te)),J=new Array(A.length);for(let te of F)for(let ue of w(te)){let ce=yf(c,q,te,ue);for(let he=0;he<A.length;he++){if(J[he])continue;let Se=V(A[he],ce);Se&&!G(Se)&&(J[he]=Se)}}if(J.some(Boolean))for(let te=0;te<A.length;te++){let ue=J[te];ue&&(A[te].v0=ue.v0,A[te].v1=ue.v1,A[te].v2=ue.v2)}}let W=c.scene??0,ie=c.scenes?.[W]?.nodes;if(ie&&ie.length>0)for(let F of ie)_(F,vt,new Set);else{(c.meshes?.length??0)===0&&b("no-gltf-meshes","No glTF meshes found");for(let F=0;F<(c.meshes?.length??0);F++)D(F,vt,null)}ee();let z=kh(d);if(A.length===0)return{polygons:[],objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:0,meshes:v,materials:R,sourceBytes:a}};let X=1/0,U=1/0,I=1/0,B=-1/0,N=-1/0,H=-1/0;for(let F of A)for(let q of[F.v0,F.v1,F.v2])q[0]<X&&(X=q[0]),q[0]>B&&(B=q[0]),q[1]<U&&(U=q[1]),q[1]>N&&(N=q[1]),q[2]<I&&(I=q[2]),q[2]>H&&(H=q[2]);let $=Math.max(B-X,N-U,H-I),k=$>0?t/$:1,Q=n?.center,ae=Q===!0||Q==="center",se=ae?(X+B)*.5:X,Y=ae?(U+N)*.5:U,ne=ae?(I+H)*.5:I,le=F=>Math.round(F*1e3)/1e3,ye=n?.upAxis??"y",Ce=ye==="z"?([F,q,J])=>[le((F-se)*k),le((q-Y)*k),le((J-ne)*k)]:([F,q,J])=>[le((J-ne)*k),le((F-se)*k),le((q-Y)*k)],Ve=ye==="z"?(F,q,J)=>{q[J]=le((F[0]-se)*k),q[J+1]=le((F[1]-Y)*k),q[J+2]=le((F[2]-ne)*k)}:(F,q,J)=>{q[J]=le((F[2]-ne)*k),q[J+1]=le((F[0]-se)*k),q[J+2]=le((F[1]-Y)*k)},Ee=[],Me=0;for(let F of A){let q=Ce(F.v0),J=Ce(F.v1),te=Ce(F.v2),ue=Nh(q,J,te);if(F.source&&F.sourceTriangleIndex!==void 0&&(F.source.triangleMask[F.sourceTriangleIndex]=!ue),ue){Me++;continue}let ce={vertices:[q,J,te],color:F.color};F.texture&&(ce.texture=F.texture),F.texture&&F.textureWrap&&(ce.textureWrap=F.textureWrap),F.texture&&F.textureAlphaMode&&(ce.textureAlphaMode=F.textureAlphaMode),F.doubleSided&&(ce.doubleSided=!0),F.uvs&&(ce.uvs=F.uvs),F.simplifySourceVertexKeys&&(ce.simplifySourceVertexKeys=F.simplifySourceVertexKeys),Ee.push(ce),T.push(F.sourceIndex!==void 0&&F.sourceTriangleIndex!==void 0?{sourceIndex:F.sourceIndex,triangleIndex:F.sourceTriangleIndex}:void 0)}Ee.length===0&&Me>0&&b("all-projected-triangles-degenerate","No non-degenerate glTF triangles remained after normalization");let Re=Bh(c,u,S,T,Ce,Ve);return{polygons:Ee,animation:Re,objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:Ee.length,meshes:v,materials:R,animations:Re?.clips,sourceBytes:a}}}function kh(e){let n=!1;return()=>{if(n)return;n=!0;let t=globalThis.URL;if(t?.revokeObjectURL)for(let o of e)try{t.revokeObjectURL(o)}catch{}}}var Tf=Symbol("polycss.solidTextureBakedAnimationInfo"),bf=Symbol.for("polycss.animation.triangleFrameSource"),zh=16*1024*1024,Uh=2,Gh=32,$h=2,Xh=.08,Yh=8,jh=128,xf=32,Wh=.045,Hh=10,It=6,Kh=16;function va(e){return e.material?.texture??e.texture}function Zh(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function qh(e,n){return new Promise((t,o)=>{let r=new n,i=!1,s=a=>{i||(i=!0,a())};r.decoding="async",r.onload=()=>s(()=>t(r)),r.onerror=()=>s(()=>o(new Error(`texture load failed: ${e}`))),r.src=e})}async function Qh(e,n,t){try{let o=await qh(e,n.Image),r=Math.max(0,Math.floor(o.naturalWidth||o.width||0)),i=Math.max(0,Math.floor(o.naturalHeight||o.height||0));if(r<=0||i<=0||r*i>t)return null;let s=n.createCanvas();s.width=r,s.height=i;let a=s.getContext("2d",{willReadFrequently:!0});if(!a)return null;a.drawImage(o,0,0,r,i);let c=a.getImageData(0,0,r,i).data;return{width:r,height:i,data:c,lowDetail:Jh(r,i,c)}}catch{return null}}function Pf(e,n,t,o,r,i){let s=(o*n+t)*4,a=(i*n+r)*4;return Math.max(Math.abs((e[s]??0)-(e[a]??0)),Math.abs((e[s+1]??0)-(e[a+1]??0)),Math.abs((e[s+2]??0)-(e[a+2]??0)))}function Jh(e,n,t){let o=Math.max(1,Math.floor(Math.max(e,n)/jh)),r=0,i=0,s=0;for(let a=0;a<n;a+=o)for(let c=0;c<e;c+=o){if(c+o<e){let l=Pf(t,e,c,a,c+o,a);s+=l,r++,l>xf&&i++}if(a+o<n){let l=Pf(t,e,c,a,c,a+o);s+=l,r++,l>xf&&i++}}return r>0&&i/r<=Wh&&s/r<=Hh}function Mf(e,n,t){return Math.max(n,Math.min(t,e))}function Sf(e,n){if(!Number.isFinite(e))return null;switch(n){case"repeat":return e-Math.floor(e);case"mirrored-repeat":{let t=Math.floor(e),o=e-t;return Math.abs(t%2)===1?1-o:o}default:return Math.max(0,Math.min(1,e))}}function ey(e,n,t){let o=n[0],r=1-n[1],i=Sf(o,t?.s),s=Sf(r,t?.t);if(i===null||s===null)return null;let a=Mf(Math.floor(i*e.width),0,e.width-1),l=(Mf(Math.floor(s*e.height),0,e.height-1)*e.width+a)*4;return{r:e.data[l]??0,g:e.data[l+1]??0,b:e.data[l+2]??0,a:e.data[l+3]??255}}function Bn(e,n,t,o,r,i){return[e[0]*o+n[0]*r+t[0]*i,e[1]*o+n[1]*r+t[1]*i]}function ny(e){let[n,t,o]=e;return[Bn(n,t,o,1/3,1/3,1/3),Bn(n,t,o,.8,.1,.1),Bn(n,t,o,.1,.8,.1),Bn(n,t,o,.1,.1,.8),Bn(n,t,o,.45,.45,.1),Bn(n,t,o,.45,.1,.45),Bn(n,t,o,.1,.45,.45)]}function ty(e){let[n,t,o]=e,r=ny(e);for(let i=1;i<It;i++)for(let s=1;s<It-i;s++){let a=It-i-s;a<=0||r.push(Bn(n,t,o,i/It,s/It,a/It))}return r}function Ef(e){if(e.textureTriangles?.length)return e.textureTriangles;let n=e.uvs;if(!n||n.length!==e.vertices.length||n.length<3)return[];let t=[];for(let o=1;o+1<n.length;o++)t.push({uvs:[n[0],n[o],n[o+1]]});return t}function Ia(e,n,t){return Math.abs(e.r-n.r)<=t&&Math.abs(e.g-n.g)<=t&&Math.abs(e.b-n.b)<=t&&Math.abs(e.a-n.a)<=t}function ei(e){let n=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");if(e.a>=255)return`#${n(e.r)}${n(e.g)}${n(e.b)}`;let t=Math.round(Math.max(0,Math.min(255,e.a))/255*1e3)/1e3;return`rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`}function vf(e){if(!e)return null;let n=e.trim().toLowerCase(),t=n.match(/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(t){let i=t[1],s=a=>{let c=i.length<=4?i[a]+i[a]:i.slice(a*2,a*2+2);return parseInt(c,16)};return{r:s(0),g:s(1),b:s(2),a:i.length===4||i.length===8?s(3):255}}let o=n.match(/^rgba?\(\s*([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)(?:\s*,\s*([0-9.]+)\s*)?\)$/);if(!o)return null;let r=o[4]===void 0?255:Number(o[4])<=1?Number(o[4])*255:Number(o[4]);return{r:Number(o[1]),g:Number(o[2]),b:Number(o[3]),a:r}}function oy(){return{min:{r:255,g:255,b:255,a:255},max:{r:0,g:0,b:0,a:0},sum:{r:0,g:0,b:0,a:0},colors:new Map,count:0}}function If(e){return`${e.r},${e.g},${e.b},${e.a}`}function Af(e,n){e.min.r=Math.min(e.min.r,n.r),e.min.g=Math.min(e.min.g,n.g),e.min.b=Math.min(e.min.b,n.b),e.min.a=Math.min(e.min.a,n.a),e.max.r=Math.max(e.max.r,n.r),e.max.g=Math.max(e.max.g,n.g),e.max.b=Math.max(e.max.b,n.b),e.max.a=Math.max(e.max.a,n.a),e.sum.r+=n.r,e.sum.g+=n.g,e.sum.b+=n.b,e.sum.a+=n.a;let t=If(n),o=e.colors.get(t);e.colors.set(t,{color:n,count:(o?.count??0)+1}),e.count++}function Cf(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 ry(e){if(e.count<Yh||e.colors.size<=1||e.colors.size>$h)return null;let n=null;for(let r of e.colors.values())(!n||r.count>n.count)&&(n=r);if(!n)return null;let t=e.count-n.count,o=Math.max(1,Math.floor(e.count*Xh));return t<=o?n.color:null}function iy(e,n,t,o){let r=Ef(e);if(r.length===0)return null;let i=oy(),s=e.textureAlphaMode==="opaque"?vf(e.color):null;for(let a of r)for(let c of ty(a.uvs)){let l=ey(n,c,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){s&&Af(i,{...s,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),Af(i,l)}if(i.count===0)return e.textureAlphaMode==="opaque"&&e.color?e.color:null;if(e.textureAlphaMode==="opaque"&&i.max.a===0&&e.color)return e.color;if(Ia(i.min,i.max,t))return ei(Cf(i));if(!o){let a=ry(i);if(a)return ei(a)}return o||!n.lowDetail||!Ia(i.min,i.max,Gh)?null:ei(Cf(i))}function _f(e,n){let{texture:t,textureWrap:o,textureAlphaMode:r,material:i,uvs:s,textureTriangles:a,...c}=e,l=e.uvs?.length===e.vertices.length?e.uvs.map(d=>`uv:${Math.round(d[0]*1e5)},${Math.round(d[1]*1e5)}`):void 0,u=l??e.simplifyVertexKeys,f=e.simplifySourceVertexKeys?.length===e.vertices.length?e.simplifySourceVertexKeys.map((d,m)=>l?`${d}|${l[m]}`:d):e.simplifySourceVertexKeys;return{...c,color:n,...u?{simplifyVertexKeys:u}:{},...f?{simplifySourceVertexKeys:f}:{}}}function sy(e,n){if(n.length<2)return e;let t=[],o=new Map;for(let l of n){let u=vf(e[l]?.color);if(!u||u.a<255)continue;let f=If(u);t.push({index:l,key:f});let d=o.get(f);d?d.count+=1:o.set(f,{color:u,count:1})}if(o.size<2)return e;let r=[],i=new Map,s=[...o.entries()].sort((l,u)=>u[1].count-l[1].count||l[0].localeCompare(u[0]));for(let[l,u]of s){let f=null;for(let d of r)if(Ia(u.color,d,Kh)){f=d;break}f||(f=u.color,r.push(f)),i.set(l,ei(f))}let a=!1,c=e.slice();for(let l of t){let u=i.get(l.key),f=e[l.index];!u||!f||f.color===u||(c[l.index]={...f,color:u},a=!0)}return a?c:e}function ay(e,n){let t=e.slice();for(let o=0;o<n.length;o++){let r=n[o],i=e[r.index];i&&(t[r.index]=_f(i,r.color))}return t}function Vf(e){return e?e[Tf]:void 0}async function Of(e,n={}){if(n.enabled===!1)return null;let t=Zh();if(!t)return null;let o=e.filter(c=>va(c)&&Ef(c).length>0);if(o.length===0)return null;let r=n.maxTexturePixels??zh,i=new Map;await Promise.all(Array.from(new Set(o.map(c=>va(c)))).map(async c=>{i.set(c,await Qh(c,t,r))}));let s=n.colorTolerance??Uh,a=n.colorTolerance!==void 0;return{bake(c){let l=!1,u=[],f=c.map((d,m)=>{let p=va(d);if(!p)return d;let g=i.get(p);if(!g)return d;let h=iy(d,g,s,a);return h?(l=!0,u.push(m),_f(d,h)):d});return l?{polygons:sy(f,u),changed:!0,bakedIndices:u}:{polygons:c,changed:!1,bakedIndices:u}}}}async function Rf(e,n={}){let t=await Of(e,n);return t?t.bake(e).polygons:e}async function ni(e,n={}){let t=await Of(e.polygons,n);if(!t)return e;let o=t.bake(e.polygons);if(!o.changed)return e;let r=[];for(let a of o.bakedIndices){let l=o.polygons[a].color;l&&r.push({index:a,color:l})}let i=e.animation,s=i&&{...i,sample(a,c){return ay(i.sample(a,c),r)}};if(s&&i){let a=i[bf];if(a){let c=new Map(r.map(f=>[f.index,f.color])),l=[],u={polygonCount:0,vertices:new Float64Array(0),colors:l,solidTriangles:!1};s[bf]=(f,d)=>{let m=a(f,d);if(!m)return m;l.length<m.polygonCount&&(l=new Array(m.polygonCount),u.colors=l);let p=m.textureFlags,g=m.solidTriangles===!0||!!p;for(let h=0;h<m.polygonCount;h++){let y=c.get(h);l[h]=y??m.colors?.[h],p?.[h]&&!y&&(g=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=p,u.solidTriangles=g,u}}s[Tf]={source:i,bakedColorEntries:r}}return{...e,polygons:o.polygons,animation:s}}var Lf=Symbol.for("polycss.animation.triangleFrameSource");function cy(e,n){let t=e[n];if(!t)return null;let o=[];for(let r=0;r<t.vertices.length;r++)o.push(n,r);return{rest:t,originalIndex:n,sourceRefs:o}}function ly(e){let n=hn(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((r,i)=>t.set(r,i));let o=[];for(let r of n){let i=t.get(r);if(i===void 0)return[];let s=cy(e,i);if(!s)return[];o.push(s)}return o}function _a(e,n,t=!1){let o=new Array(n.length);for(let r=0;r<n.length;r++){let i=n[r],s=i.sourceRefs,a=new Array(s.length/2);for(let l=0,u=0;l<s.length;l+=2,u++){let d=e[s[l]]?.vertices[s[l+1]];if(!d)return e;let m=d[0],p=d[1],g=d[2];if(!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(g))return e;a[u]=[m,p,g]}let c=t?i.rest.color:e[s[0]??-1]?.color??i.rest.color;o[r]={...i.rest,vertices:a,color:c}}return o}function uy(e,n){let t=new Map;return n.forEach((o,r)=>{t.set(o,r)}),e.map((o,r)=>({...o,sourceRefs:o.sourceRefs.map((i,s)=>s%2===0?t.get(i)??-1:i)}))}function fy(e,n){if(e.length<n.length)return null;let t=new Array(n.length);for(let o=0;o<n.length;o++){let r=e[o],i=n[o];if(!r||r.vertices.length!==i.rest.vertices.length)return null;t[o]={...i.rest,vertices:r.vertices,color:i.rest.color}}return t}function my(e){return!!(e.texture||e.material?.texture)}function wf(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=ly(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let o=Vf(e.animation),r=o?.source??e.animation,i=t.map(b=>b.originalIndex),s=gf(r,i),a=s??r,c=s?uy(t,i):t,l=t.map(b=>b.rest.color),u=t.every(b=>b.rest.vertices.length===3&&!my(b.rest)),f=s&&!o&&t.length===i.length&&t.every((b,x)=>b.rest.vertices.length===3&&b.sourceRefs.length===6&&b.sourceRefs[0]===i[x]&&b.sourceRefs[2]===i[x]&&b.sourceRefs[4]===i[x]),d=a[Lf],m=new Float64Array(t.length*9),p=l.slice(),g=new Array(t.length).fill(!1),h={polygonCount:t.length,vertices:m,colors:p,textureFlags:g,solidTriangles:u},y={...e.animation,sample(b,x){let P=a.sample(b,x);return f?P:s&&o?u&&t.length===i.length?fy(P,t)??_a(P,c,!0):_a(P,c,!0):_a(P,c,!!o)}};return d&&u&&(y[Lf]=(b,x)=>{let P=d(b,x);if(!P)return P;if(s)return P.polygonCount<t.length||P.vertices.length<t.length*9?null:(h.polygonCount=t.length,h.vertices=P.vertices,h.colors=o?l:P.colors,h.textureFlags=o?g:P.textureFlags,h.solidTriangles=o?u:P.solidTriangles===!0,h);m.length<t.length*9&&(m=new Float64Array(t.length*9),h.vertices=m),p.length<t.length&&(p=new Array(t.length),h.colors=p),g.length<t.length&&(g=new Array(t.length).fill(!1),h.textureFlags=g);let M=u&&P.solidTriangles!==!1;for(let C=0;C<c.length;C++){let E=c[C],A=E.sourceRefs;for(let v=0,R=0;v<A.length;v+=2,R++){let O=A[v],L=A[v+1];if(O<0||O>=P.polygonCount)return null;let D=O*9+L*3,_=C*9+R*3;if(D+2>=P.vertices.length)return null;m[_]=P.vertices[D],m[_+1]=P.vertices[D+1],m[_+2]=P.vertices[D+2]}let S=A[0],T=!!P.textureFlags?.[S];g[C]=T,p[C]=o?E.rest.color:P.colors?.[S]??E.rest.color,!o&&T&&(M=!1)}return h.polygonCount=t.length,h.vertices=m,h.colors=p,h.textureFlags=g,h.solidTriangles=o?u:M,h}),{...e,polygons:t.map(b=>b.rest),animation:y,metadata:{...e.metadata,triangleCount:t.length}}}var dy=/^[0-9A-Fa-f]{6}$/,py=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function gy(e){let n=[],t="";for(let o of e.split(`
|
|
1
|
+
"use strict";var Fi=Object.defineProperty;var Cm=Object.getOwnPropertyDescriptor;var Tm=Object.getOwnPropertyNames;var Em=Object.prototype.hasOwnProperty;var vm=(e,n)=>{for(var t in n)Fi(e,t,{get:n[t],enumerable:!0})},Im=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Tm(n))!Em.call(e,r)&&r!==t&&Fi(e,r,{get:()=>n[r],enumerable:!(o=Cm(n,r))||o.enumerable});return e};var _m=e=>Im(Fi({},"__esModule",{value:!0}),e);var db={};vm(db,{ASYNC_RENDER_BUDGET_MS:()=>Ru,ATLAS_CANONICAL_SIZE_AUTO_DESKTOP:()=>Br,ATLAS_CANONICAL_SIZE_EXPLICIT:()=>nn,ATLAS_MAX_SIZE:()=>On,ATLAS_PADDING:()=>lo,AUTO_ATLAS_LOW_AREA:()=>uo,AUTO_ATLAS_MAX_BITMAP_SIDE:()=>Tt,AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP:()=>Ir,AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE:()=>vr,AUTO_ATLAS_MEDIUM_AREA:()=>Er,AUTO_ATLAS_SCALE_GUARD:()=>_r,BAKED_SHADOW_MIN_UP:()=>gu,BAKED_SHADOW_Z_SQUASH:()=>pu,BASE_TILE:()=>He,BASIS_EPS:()=>de,BORDER_SHAPE_BLEED:()=>kr,BORDER_SHAPE_CANONICAL_SIZE:()=>Pn,BORDER_SHAPE_CENTER_PERCENT:()=>po,BORDER_SHAPE_POINT_EPS:()=>go,CAMERA_BACKFACE_CULL_EPS:()=>ao,COLOR_PARSE_CACHE_MAX:()=>Vr,CORNER_SHAPE_DUPLICATE_EPS:()=>ho,CORNER_SHAPE_POINT_EPS:()=>tn,DECIMAL_SCALES:()=>Nr,DEFAULT_AMBIENT_COLOR:()=>tt,DEFAULT_AMBIENT_INTENSITY:()=>ot,DEFAULT_ATLAS_CSS_DECIMALS:()=>mo,DEFAULT_BORDER_SHAPE_DECIMALS:()=>wr,DEFAULT_CAMERA_STATE:()=>_e,DEFAULT_LIGHT_COLOR:()=>et,DEFAULT_LIGHT_DIR:()=>Jn,DEFAULT_LIGHT_INTENSITY:()=>nt,DEFAULT_MATRIX_DECIMALS:()=>bn,DEFAULT_PROJECTION:()=>hc,DEFAULT_SEAM_BLEED:()=>Fu,DEFAULT_SEAM_FACET_SPLIT_OPTIONS:()=>as,DEFAULT_SEAM_OVERLAP_OPTIONS:()=>ss,DEFAULT_TILE:()=>un,LoopOnce:()=>Sa,LoopPingPong:()=>Aa,LoopRepeat:()=>Hr,MAX_ATLAS_SCALE:()=>Tr,MIN_ATLAS_SCALE:()=>Cr,PROJECTIVE_QUAD_BLEED:()=>Gr,PROJECTIVE_QUAD_DENOM_EPS:()=>zr,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO:()=>Ur,QUAT_IDENTITY:()=>Rc,RECEIVER_NORMAL_TOL:()=>ha,RECEIVER_OFFSET_TOL:()=>ya,RECEIVER_OUTLINE_EXPAND:()=>ga,RECT_EPS:()=>Ae,SEAM_LIGHT_EPS:()=>fo,SOLID_QUAD_CANONICAL_SIZE:()=>xn,SOLID_TRIANGLE_BLEED:()=>Lr,SOLID_TRIANGLE_CANONICAL_SIZE:()=>Dr,SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE:()=>Fr,SURFACE_DISTANCE_EPS:()=>Rr,SURFACE_NORMAL_EPS:()=>Or,TEXTURE_EDGE_REPAIR_ALPHA_MIN:()=>wu,TEXTURE_EDGE_REPAIR_RADIUS:()=>Du,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN:()=>Nu,TEXTURE_TRIANGLE_BLEED:()=>Lu,VOXEL_CAMERA_CULL_AXIS_EPS:()=>zs,VOXEL_CAMERA_CULL_NORMAL_LIMIT:()=>Us,applyPackedAtlasCanonicalSize:()=>Sm,applyPackedAtlasLeafSizing:()=>wo,arrowPolygons:()=>Zs,atlasArea:()=>Di,atlasBitmapMaxSide:()=>rc,atlasCanonicalSizeForEntry:()=>uc,atlasCanonicalSizeForTextureQuality:()=>cc,atlasDecodedBytes:()=>ic,atlasPadding:()=>fc,autoAtlasBudgetFactor:()=>sc,autoAtlasMaxDecodedBytes:()=>ac,autoAtlasScale:()=>oc,autoAtlasScaleCap:()=>tc,axesHelperPolygons:()=>Ws,bakeSolidTextureSampledPolygons:()=>Rf,bakeSolidTextureSamples:()=>ni,basisAxisKey:()=>Ka,borderShapeBoundsFromPoints:()=>ka,borderShapeGeometryForPlan:()=>Nt,boxPolygons:()=>Ks,buildBakedShadowProjectionMatrix:()=>hu,buildBasisHints:()=>gm,buildEdgeOwners:()=>jr,buildParametricCasterOverride:()=>Au,buildPolyCameraSceneTransform:()=>zc,buildPolyMeshTransform:()=>Vu,buildPolySceneTransform:()=>Ou,buildSceneContext:()=>Ic,buildSeamBleedPolygonEdges:()=>Fa,buildSeamBleedPolygonSet:()=>sm,buildSharedEdgeMap:()=>Yu,buildTextureEdgeRepairSets:()=>im,cachedParsePureColor:()=>rt,cameraCullNormalGroups:()=>Xs,cameraCullNormalGroupsFromPolygons:()=>lu,cameraCullNormalKey:()=>$s,cameraCullVisibleSignature:()=>fu,cameraFacingDepth:()=>Gs,capturePolyCameraSnapshot:()=>Uc,chooseIslandXAxis:()=>qa,chooseLocalBasis:()=>Ei,clampChannel:()=>Nn,classifyFacing:()=>Wr,clipPolygonToConvex2D:()=>Vn,colorErrorScore:()=>$u,compatibleBleedSurface:()=>vi,compatibleSurface:()=>Wa,computeCoverageShadowSilhouette:()=>xr,computeLightVisibility:()=>au,computeMergedReceiverShadows:()=>Ku,computeParametricShadowSilhouette:()=>br,computePlanSeamBleedEdgeAmounts:()=>yi,computeProjectiveQuadCoefficients:()=>Ai,computeProjectiveQuadMatrix:()=>Ro,computeReceiverShadowFaces:()=>Pa,computeSceneBbox:()=>Ui,computeSeamBleedInsets:()=>xi,computeShapeLighting:()=>Sc,computeSolidTriangleColorPlan:()=>Pm,computeSolidTriangleColorPlanFromNormal:()=>wi,computeSolidTrianglePlan:()=>Mm,computeSolidTrianglePlanFromCssPoints:()=>Ni,computeSurfaceNormal:()=>zn,computeTextureAtlasPlan:()=>ec,computeTextureAtlasPlanPublic:()=>hm,computeTexturePaintMetrics:()=>Vc,computeUvAffine:()=>Ii,computeUvSampleRect:()=>_i,conePolygons:()=>ia,convexHull2D:()=>yr,cornerShapeDiagonal:()=>$a,cornerShapeGeometryForPlan:()=>Pi,cornerShapePointSides:()=>Ua,coverPlanarPolygons:()=>Zo,createIsometricCamera:()=>Gc,createPolyAnimationMixer:()=>Zu,crossVec:()=>dm,cssBorderShapeForGeometry:()=>Mi,cssBorderShapeForPlan:()=>am,cssDistanceToWorld:()=>fa,cssPoints:()=>dn,cssPositionToWorld:()=>ma,cullInteriorPolygons:()=>hn,cylinderPolygons:()=>co,dedupeOverlappingPolygons:()=>qc,dodecahedronPolygons:()=>ra,dominantCountKey:()=>Li,dotVec:()=>Lo,ensureCcw2D:()=>yn,eulerXYZFromQuat:()=>Dc,evaluateIslandAxis:()=>Za,expandClipPoints:()=>st,expandConvexHullOutward:()=>pa,extractSilhouetteLoops:()=>Mo,filterAtlasPlans:()=>bm,findOverlappingPolygonDuplicates:()=>jt,formatAffineMatrix3dColumns:()=>qf,formatAffineMatrix3dScalars:()=>ui,formatAffineMatrix3dTransformScalars:()=>fi,formatAtlasMatrix:()=>Rt,formatBorderShapeElementStyle:()=>lm,formatBorderShapeEntryMatrix:()=>cm,formatBorderShapeMatrix:()=>Qf,formatColor:()=>$t,formatCornerShapeElementStyle:()=>um,formatCssLength:()=>Zf,formatCssLengthPx:()=>em,formatMatrix3d:()=>Jf,formatMatrix3dValues:()=>mn,formatPercent:()=>Ln,formatScaledMatrixFromPlan:()=>Ot,formatSolidQuadEntryMatrix:()=>nm,formatSolidQuadMatrix:()=>Da,fullRectBounds:()=>nc,getPolygonBasisInfo:()=>ja,getSolidPaintDefaultsForPlansCore:()=>xm,groupReceiverFaceGroups:()=>Ar,icosahedronPolygons:()=>oa,incrementCount:()=>Ri,intersect2DLines:()=>di,intersect2DLinesRaw:()=>tm,inverseRotateVec3:()=>Oc,isAxisAlignedSurfaceNormal:()=>Ys,isBakedShadowCaster:()=>xu,isBasisOptimizable:()=>Ya,isConvexCaster:()=>la,isConvexPolygonPoints:()=>Lt,isFlatCaster:()=>ca,isFullRectBasis:()=>Qa,isFullRectSolid:()=>Un,isPointShadowCaster:()=>bu,isProjectiveQuadPlan:()=>Dt,isSolidTrianglePlan:()=>ct,isVoxelCameraCullableNormalGroups:()=>uu,loadMesh:()=>Kf,makeLocalBasis:()=>lt,mergePolygons:()=>sn,meshScaleVec3:()=>Sr,normalFacesCamera:()=>At,normalizeAtlasScale:()=>ut,normalizeInvertMultiplier:()=>kc,normalizePolygons:()=>Xo,normalizedSeamBleed:()=>hi,octahedronPolygons:()=>ea,offsetConvexPolygonPoints:()=>at,offsetConvexPolygonPointsByEdgeAmounts:()=>wt,offsetStableTrianglePoints:()=>pi,offsetTrianglePoints:()=>To,optimizeAnimatedMeshPolygons:()=>wf,optimizeMeshParseResult:()=>Qn,optimizeMeshPolygons:()=>zl,packTextureAtlasPlans:()=>Ft,packTextureAtlasPlansWithScaleCore:()=>Am,parseAlpha:()=>bo,parseColor:()=>Xn,parseGltf:()=>Jr,parseHex:()=>fn,parseHexColor:()=>gt,parseMtl:()=>oi,parseObj:()=>ti,parsePureColor:()=>Tn,parseRgbColor:()=>Bi,parseStl:()=>li,parseVox:()=>ri,planePolygons:()=>Js,polyCameraTargetToCss:()=>$i,polyCssDistanceToWorld:()=>Tu,polyCssPositionToWorld:()=>vu,polygonContainsPoint:()=>Ba,polygonCssSurfaceNormal:()=>pr,polygonFaces:()=>_c,polygonFacesCamera:()=>cu,polygonSignedArea2D:()=>aa,prepareCasterEdgeOwners:()=>ju,prepareCasterPolyItems:()=>Wu,prepareReceiverFacePlanes:()=>Hu,projectCssVertexToGround:()=>Pu,projectCssVertexToGroundFromPoint:()=>yu,projectTextureTriangle:()=>Ja,quantizeCssColor:()=>Yr,quatFromAxisAngle:()=>wc,quatFromEulerXYZ:()=>Nc,quatMultiply:()=>Lc,repairMeshSeams:()=>Tl,resolveAtlasLeafBox:()=>lc,resolveBleedRatio:()=>$r,resolvePolyCameraAppliedPerspectiveStyle:()=>Xi,resolvePolyTextureImageRendering:()=>fm,resolvePolyTextureImageSource:()=>_o,resolvePolyTextureLeafGeometry:()=>Oi,resolvePolyTexturePresentation:()=>Vo,resolvePolyTextureUrl:()=>Si,resolveProjectiveQuadGuards:()=>Oo,resolveSeamBleed:()=>vo,rgbEqual:()=>zu,rgbKey:()=>Xr,rgbToCss:()=>Gu,rgbToHex:()=>xo,ringPolygons:()=>qs,ringQuadPolygons:()=>Qs,rotateVec3:()=>Yo,rotateVec3InWrapperCssFrame:()=>Dn,roundDecimal:()=>Be,safariCssProjectiveUnsupported:()=>ym,safePlanSeamBleedAmount:()=>Io,screenToWorldOnSphere:()=>Xc,screenToWorldRay:()=>Yi,seamBleedAmountArray:()=>bi,seamFacetSplitPolygons:()=>ds,seamFacetSplitReport:()=>Cl,seamLightBrightness:()=>Ci,seamOverlapDiagnostics:()=>El,seamOverlapPolygons:()=>ps,seamOverlapReport:()=>Il,shadeColor:()=>Mc,shadePolygon:()=>Rn,sharedCornerShapeSide:()=>Ga,signedArea2D:()=>mi,simplifyCornerShapePoints:()=>za,simplifyTriangleMeshPolygons:()=>ar,spherePolygons:()=>na,stableBasisFromPlan:()=>Eo,stableTriangleMatrixDecimals:()=>gi,stepRgbToward:()=>Uu,tetrahedronPolygons:()=>ta,textureTintFactors:()=>Po,tintToCss:()=>ku,torusPolygons:()=>sa,worldCssForMesh:()=>Ct,worldDirectionToCss:()=>Mr,worldDirectionToPolyCss:()=>Iu,worldDirectionalLightToCss:()=>da,worldDirectionalLightToPolyCss:()=>_u,worldDistanceToCss:()=>ua,worldDistanceToPolyCss:()=>Cu,worldPositionToCss:()=>rn,worldPositionToPolyCss:()=>Eu});module.exports=_m(db);var hc="cubic";function gt(e){let n=e.replace("#","");if(n.length===3){let t=parseInt(n[0]+n[0],16),o=parseInt(n[1]+n[1],16),r=parseInt(n[2]+n[2],16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}if(n.length===6){let t=parseInt(n.slice(0,2),16),o=parseInt(n.slice(2,4),16),r=parseInt(n.slice(4,6),16);return Number.isNaN(t)||Number.isNaN(o)||Number.isNaN(r)?null:{rgb:[t,o,r],alpha:1}}return null}function Bi(e){let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/i);return n?{rgb:[Number(n[1]),Number(n[2]),Number(n[3])],alpha:n[4]?Number(n[4]):1}:null}function Tn(e){if(!e)return null;let n=e.trim(),t=gt(n);return t||Bi(n)}function Nn(e){return Math.max(0,Math.min(255,Math.round(e)))}function $t(e){let[n,t,o]=e.rgb.map(Nn);return e.alpha<1?`rgba(${n}, ${t}, ${o}, ${e.alpha})`:`rgb(${n}, ${t}, ${o})`}var zi={rgb:[204,204,204],alpha:1},yc=new Map;function Xn(e){if(!e)return null;let n=e.trim(),t=yc.get(n);if(t)return t;let o=Tn(n);return o?(yc.set(n,o),o):null}function Mc(e,n){let t=Xn(e)??zi,o=[Nn(t.rgb[0]+n),Nn(t.rgb[1]+n),Nn(t.rgb[2]+n)];return $t({rgb:o,alpha:t.alpha})}var ki={direction:[0,0,1],color:"#ffffff",intensity:1},bc={color:"#ffffff",intensity:.4};function xc(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 Pc(e,n,t){let o=Xn(n)??zi;return e*(o.rgb[t]/255)}function Sc(e,n,t,o){let r=Xn(n)??zi,i=xc(t?.direction??ki.direction),s=t?.color??ki.color,a=Math.max(0,t?.intensity??ki.intensity),c=o?.color??bc.color,l=Math.max(0,o?.intensity??bc.intensity),u=xc(e),f=Math.max(0,u[0]*i[0]+u[1]*i[1]+u[2]*i[2]),d=a*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let g=r.rgb[p],h=Pc(g,c,p)*l,y=Pc(g,s,p)*d;m[p]=Nn(h+y)}return $t({rgb:m,alpha:r.alpha})}var Ac="#cccccc",Go=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Cc=(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]],Tc=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],$o=e=>Math.hypot(e[0],e[1],e[2]);function Vm(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>i&&(i=u[1]),u[2]<o&&(o=u[2]),u[2]>s&&(s=u[2]);let a=r-n,c=i-t,l=s-o;return Math.hypot(a,c,l)}function Om(){let e=globalThis;if(e.__POLYCSS_DEV__===!0)return!0;if(e.__POLYCSS_DEV__===!1)return!1;let n=e.process?.env?.NODE_ENV;return typeof n=="string"?n!=="production":!1}function Ec(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function vc(e){return e?{...e}:void 0}function Rm(e){if(e)return{...e,imageSource:Ec(e.imageSource),presentation:vc(e.presentation)}}function Xo(e){let n=[],t=[];if(!e||e.length===0)return{polygons:n,warnings:t};for(let o=0;o<e.length;o++){let r=e[o];if(!r||!Array.isArray(r.vertices)){t.push(`Polygon ${o}: missing vertices, dropped`);continue}let i=r.vertices;if(i.length<3){t.push(`Polygon ${o}: ${i.length} vertices (need >= 3), dropped`);continue}let s=Go(i[1],i[0]),a=Go(i[2],i[0]),c=Cc(s,a),l=$o(c);if(i.length===3){if(l<1e-12){$o(s)<1e-12||$o(a)<1e-12?t.push(`Polygon ${o}: zero-area triangle (coincident vertices), dropped`):t.push(`Polygon ${o}: vertices collinear, dropped`);continue}}else if(l<1e-12){t.push(`Polygon ${o}: first 3 vertices collinear, dropped`);continue}let u=[{...r,vertices:i.slice()}];if(i.length>=4){let f=[c[0]/l,c[1]/l,c[2]/l],d=Tc(f,i[0]),m=Vm(i),p=Math.max(1e-6,m*.001),g=0;for(let h=3;h<i.length;h++){let y=Math.abs(Tc(f,i[h])-d);y>g&&(g=y)}if(g>p){let h=[],y=r.uvs&&r.uvs.length===i.length?r.uvs:void 0;for(let b=1;b<i.length-1;b++){let x=[i[0].slice(),i[b].slice(),i[b+1].slice()],P=Cc(Go(x[1],x[0]),Go(x[2],x[0]));if($o(P)<1e-12)continue;let M={...r,vertices:x};y&&(M.uvs=[y[0].slice(),y[b].slice(),y[b+1].slice()]),h.push(M)}if(h.length===0){t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${o}: ${i.length} non-coplanar vertices, fan-triangulated to ${h.length} triangles`),u=h}}for(let f of u){let d=Lm(f,o,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function Lm(e,n,t){let o={vertices:e.vertices},r=Rm(e.material),i=Ec(e.textureImageSource),s=vc(e.texturePresentation),a=r?.texture??e.texture??i?.url??r?.imageSource?.url;if(typeof a=="string"&&a===""&&(a=void 0),e.color!==void 0&&a!==void 0&&Om()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Xn(e.color)?o.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${Ac}`),o.color=Ac)),a!==void 0&&(o.texture=a,e.textureWrap&&(o.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(o.textureAlphaMode=e.textureAlphaMode)),r&&(o.material=r),i&&(o.textureImageSource=i),s&&(o.texturePresentation=s),Array.isArray(e.textureTriangles)&&e.textureTriangles.length>0&&(o.textureTriangles=e.textureTriangles.map(c=>({vertices:c.vertices.map(l=>l.slice()),uvs:c.uvs.map(l=>l.slice())}))),e.doubleSided===!0&&(o.doubleSided=!0),e.uvs!==void 0&&(!Array.isArray(e.uvs)||e.uvs.length!==e.vertices.length?t.push(`Polygon ${n}: uvs length ${Array.isArray(e.uvs)?e.uvs.length:"?"} != vertices length ${e.vertices.length}, uvs stripped`):o.uvs=e.uvs),e.data!==void 0&&e.data!==null&&typeof e.data=="object"){let c={},l=!1;for(let u of Object.keys(e.data)){let f=e.data[u];typeof f=="string"||typeof f=="number"||typeof f=="boolean"?c[u]=f:(l=!0,t.push(`Polygon ${n}: data["${u}"] has non-primitive value, key dropped`))}Object.keys(c).length>0&&(o.data=c)}return o}function Ui(e){if(!e||e.length===0)return{min:[0,0,0],max:[0,0,0]};let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0,a=!1;for(let c of e)if(c?.vertices)for(let l of c.vertices)l&&(a=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>i&&(i=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]));return a?{min:[n,t,o],max:[r,i,s]}:{min:[0,0,0],max:[0,0,0]}}function Ic(e){let n=e.polygons??[],t,o;if(e.skipNormalize)t=n,o=[];else{let a=Xo(n);t=a.polygons,o=a.warnings}let r=Ui(t),i=[r.max[0]-r.min[0],r.max[1]-r.min[1],r.max[2]-r.min[2]];return{context:{polygons:t,sceneBbox:r,warnings:o},dimensions:{sceneBbox:r,size:i},warnings:o}}function _c(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function wm(e){let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],i=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],s=r[1]*i[2]-r[2]*i[1],a=r[2]*i[0]-r[0]*i[2],c=r[0]*i[1]-r[1]*i[0],l=Math.hypot(s,a,c);return l<=1e-9?null:[s/l,a/l,c/l]}function Nm(e){let n=0;for(let t=0;t<e.length;t++){let[o,r]=e[t],[i,s]=e[(t+1)%e.length];n+=o*s-i*r}return Math.abs(n)/2}function Dm(e,n,t){if(!e||e.length<3)return null;let o=e.map(a=>[a[1]*n,a[0]*n,a[2]*t]),r=wm(o);if(!r)return null;let i=1/0,s=0;for(let a=0;a<o.length;a++){let c=o[a],l=o[(a+1)%o.length],u=[l[0]-c[0],l[1]-c[1],l[2]-c[2]],f=u[0]*r[0]+u[1]*r[1]+u[2]*r[2],d=[u[0]-f*r[0],u[1]-f*r[1],u[2]-f*r[2]],m=Math.hypot(d[0],d[1],d[2]);if(m<=1e-9)continue;let p=[d[0]/m,d[1]/m,d[2]/m],g=[r[1]*p[2]-r[2]*p[1],r[2]*p[0]-r[0]*p[2],r[0]*p[1]-r[1]*p[0]],h=Math.hypot(g[0],g[1],g[2]);if(h<=1e-9)continue;let y=[g[0]/h,g[1]/h,g[2]/h],b=o.map(v=>{let R=v[0]-c[0],O=v[1]-c[1],L=v[2]-c[2];return[R*p[0]+O*p[1]+L*p[2],R*y[0]+O*y[1]+L*y[2]]}),x=1/0,P=1/0,M=-1/0,C=-1/0;for(let[v,R]of b)x=Math.min(x,v),P=Math.min(P,R),M=Math.max(M,v),C=Math.max(C,R);let E=M-x,A=C-P,S=Math.max(1,Math.ceil(E))*Math.max(1,Math.ceil(A)),T=Nm(b);T<=1e-9||S<i&&(i=S,s=T)}return!Number.isFinite(i)||s<=1e-9?null:{elementArea:i,polygonArea:s}}function Vc(e,n={}){let t=n.tileSize??100,o=n.layerElevation??t,r=n.texturedOnly??!0,i=0,s=0,a=0,c=0,l=0;for(let f of e){let d=!!f.texture;if(r&&!d)continue;let m=Dm(f.vertices,t,o);m&&(i+=1,d&&(s+=1),a+=m.elementArea,c+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,a-c);return{totalPolygons:e.length,measuredPolygons:i,texturedPolygons:s,elementArea:a,polygonArea:c,transparentArea:u,transparentRatio:a>0?u/a:0,overdrawRatio:c>0?a/c:0,worstTransparentRatio:l}}function Yo(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function Oc(e,n){let t=-n[0]*Math.PI/180,o=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[i,s,a]=e;if(t!==0){let c=Math.cos(t),l=Math.sin(t);[s,a]=[s*c-a*l,s*l+a*c]}if(o!==0){let c=Math.cos(o),l=Math.sin(o);[i,a]=[i*c+a*l,-i*l+a*c]}if(r!==0){let c=Math.cos(r),l=Math.sin(r);[i,s]=[i*c-s*l,i*l+s*c]}return[i,s,a]}function Dn(e,n){let[t,o,r]=e,i=-(n[2]??0)*Math.PI/180;if(i!==0){let c=Math.cos(i),l=Math.sin(i);[t,o]=[t*c-o*l,t*l+o*c]}let s=-(n[1]??0)*Math.PI/180;if(s!==0){let c=Math.cos(s),l=Math.sin(s);[o,r]=[o*c-r*l,o*l+r*c]}let a=-(n[0]??0)*Math.PI/180;if(a!==0){let c=Math.cos(a),l=Math.sin(a);[t,r]=[t*c+r*l,-t*l+r*c]}return[t,o,r]}var Gi=Math.PI/180,Xt=180/Math.PI,Rc=[1,0,0,0];function Lc(e,n){let[t,o,r,i]=e,[s,a,c,l]=n;return[t*s-o*a-r*c-i*l,t*a+o*s+r*l-i*c,t*c-o*l+r*s+i*a,t*l+o*c-r*a+i*s]}function wc(e,n){let t=n*.5,o=Math.sin(t);return[Math.cos(t),e[0]*o,e[1]*o,e[2]*o]}function Nc(e){let n=e[0]*Gi,t=e[1]*Gi,o=e[2]*Gi,r=Math.cos(n*.5),i=Math.sin(n*.5),s=Math.cos(t*.5),a=Math.sin(t*.5),c=Math.cos(o*.5),l=Math.sin(o*.5);return[r*s*c-i*a*l,i*s*c+r*a*l,r*a*c-i*s*l,r*s*l+i*a*c]}function Dc(e){let[n,t,o,r]=e,i=2*(t*r+n*o),s=2*(o*r-n*t),a=1-2*(t*t+o*o),c=2*(t*o-n*r),l=1-2*(o*o+r*r),u=Math.max(-1,Math.min(1,i)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-s,a)*Xt,f*Xt,Math.atan2(-c,l)*Xt]:[Math.atan2(2*(o*r+n*t),1-2*(t*t+r*r))*Xt,f*Xt,0]}var He=50;function kc(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var _e={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0};function $i(e=_e.target,n=[0,0,0],t=50){let o=e[0]+n[0],r=e[1]+n[1],i=e[2]+n[2];return[r*t,o*t,i*t]}function zc(e=_e,n={}){let t=n.tileSize??50,o=n.layoutScale??1,r=e.target??_e.target,[i,s,a]=$i(r,n.autoCenterOffset,t),c=(e.zoom??_e.zoom)/t*o,l=(e.distance??_e.distance)*o,u=e.rotX??_e.rotX,f=e.rotY??_e.rotY;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${u}deg) rotate(${f}deg) translate3d(${-i}px, ${-s}px, ${-a}px)`}function Xi(e="none"){if(e==="none")return"1000000px";let n=Number.parseFloat(e);return Number.isFinite(n)?`${n}px`:e}function Uc(e,n={}){let t=n.perspectiveStyle??e.perspectiveStyle??"none",o=n.projection??e.type??(t==="none"?"orthographic":"perspective"),r=e.state??_e;return{projection:o,perspectiveStyle:t,appliedPerspectiveStyle:Xi(t),state:{target:[...r.target??_e.target],rotX:r.rotX??_e.rotX,rotY:r.rotY??_e.rotY,zoom:r.zoom??_e.zoom,distance:r.distance??_e.distance}}}var Fc=100,Bc=1e4,ht=e=>Math.round(e*Fc)/Fc,Fm=e=>Math.round(e*Bc)/Bc;function Gc(e={}){let n={target:e.target??[..._e.target],rotX:e.rotX??_e.rotX,rotY:e.rotY??_e.rotY,zoom:e.zoom??_e.zoom,distance:e.distance??_e.distance};function t(r){r.target!==void 0&&(n.target=[ht(r.target[0]),ht(r.target[1]),ht(r.target[2])]),r.rotX!==void 0&&(n.rotX=ht(r.rotX)),r.rotY!==void 0&&(n.rotY=ht(r.rotY)),r.zoom!==void 0&&(n.zoom=Fm(r.zoom)),r.distance!==void 0&&(n.distance=ht(r.distance))}function o(r={}){let s=(r.cols??0)*50,a=(r.rows??0)*50,[c,l,u]=n.target,f=l*50,d=c*50,m=u*50;return{transform:`${n.distance!==0?` translateZ(${-n.distance}px)`:""}scale(${n.zoom}) rotateX(${n.rotX}deg) rotate(${n.rotY}deg) translate3d(${-f}px, ${-d}px, ${-m}px)`,width:`${s}px`,height:`${a}px`}}return{state:n,update:t,getStyle:o}}var $c=Math.PI/180;function Yi(e){let{camera:n,tileSize:t,viewportCenterX:o,viewportCenterY:r,mouseX:i,mouseY:s}=e,a=n.rotX*$c,c=n.rotY*$c,l=n.zoom/t,u=n.target,f=i-o,d=s-r,m=f/l,p=d/l,g=Math.cos(a),h=Math.sin(a),y=m,b=p*g,x=-p*h,P=0,M=h,C=g,E=Math.cos(c),A=Math.sin(c),S=y*E+b*A,T=-y*A+b*E,v=x,R=P*E+M*A,O=-P*A+M*E,L=C,D=u[1]*t,_=u[0]*t,w=u[2]*t,V=S+D,j=T+_,G=v+w,Z=[j/t,V/t,G/t],ee=[O/t,R/t,L/t];return{origin:Z,direction:ee}}function Xc(e){let{origin:n,direction:t}=Yi(e),{sphereCenter:o,sphereRadius:r}=e,i=n[0]-o[0],s=n[1]-o[1],a=n[2]-o[2],c=t[0],l=t[1],u=t[2],f=c*c+l*l+u*u;if(f===0)return null;let d=2*(i*c+s*l+a*u),m=i*i+s*s+a*a-r*r,p=d*d-4*f*m;if(p>=0){let E=Math.sqrt(p),A=(-d-E)/(2*f),S=(-d+E)/(2*f),T=t[2]>=0?Math.max(A,S):Math.min(A,S);return[n[0]+T*t[0],n[1]+T*t[1],n[2]+T*t[2]]}let g=-(i*c+s*l+a*u)/f,h=n[0]+g*c,y=n[1]+g*l,b=n[2]+g*u,x=h-o[0],P=y-o[1],M=b-o[2],C=Math.hypot(x,P,M);return C===0?null:[o[0]+x/C*r,o[1]+P/C*r,o[2]+M/C*r]}var Fn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],jo=(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]],Yt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],Hi=e=>Math.hypot(e[0],e[1],e[2]),yt=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function Bm(e){return`${e[0]},${e[1]},${e[2]}`}function Wc(e){if(e.length<3)return null;let n=Fn(e[1],e[0]),t=Fn(e[2],e[0]),o=jo(n,t),r=Hi(o);if(r<1e-12)return null;let i=[o[0]/r,o[1]/r,o[2]/r],s=Yt(i,e[0]);return{normal:i,d:s}}function km(e,n){return Yt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function zm(e,n){return Yt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function Um(e,n,t,o){let r=e.vertices.findIndex(A=>yt(A,t)),i=e.vertices.findIndex(A=>yt(A,o)),s=n.vertices.findIndex(A=>yt(A,t)),a=n.vertices.findIndex(A=>yt(A,o));if(r<0||i<0||s<0||a<0)return null;let c=e.vertices.length,l=n.vertices.length,u=(r+1)%c===i,f=(s+1)%l===a;if(u===f)return null;let d=u?i:r,m=u?r:i,p=f?a:s,g=f?s:a,h=!!(e.uvs&&n.uvs),y=[],b=h?[]:void 0,x=d;for(;y.push(e.vertices[x]),b&&b.push(e.uvs[x]),x!==m;)x=(x+1)%c;for(x=p;y.push(n.vertices[x]),b&&b.push(n.uvs[x]),x!==g;)x=(x+1)%l;let P=[],M=b?[]:void 0;for(let A=0;A<y.length;A++)(P.length===0||!yt(y[A],P[P.length-1]))&&(P.push(y[A]),M&&b&&M.push(b[A]));if(P.length>1&&yt(P[0],P[P.length-1])&&(P.pop(),M?.pop()),h)return jc(P,M);let C=[],E=M?[]:void 0;for(let A=0;A<P.length;A++){let S=P[(A-1+P.length)%P.length],T=P[A],v=P[(A+1)%P.length],R=jo(Fn(T,S),Fn(v,S));Hi(R)>1e-9&&(C.push(T),E&&M&&E.push(M[A]))}return C.length<3?null:jc(C,E)}function Gm(e,n){let t=e.length,o=0;for(let r=0;r<t;r++){let i=e[r],s=e[(r+1)%t],a=e[(r+2)%t],c=Fn(s,i),l=Fn(a,s),u=Yt(jo(c,l),n);if(Math.abs(u)<1e-9)continue;let f=u>0?1:-1;if(o===0)o=f;else if(f!==o)return!1}return!0}function $m(e,n){if(e.length<3)return!1;let t=Wc(e);if(!t)return!1;for(let o of e)if(Math.abs(Yt(t.normal,o)-t.d)>n)return!1;return!0}function Xm(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function ji(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function Wi(e){return e?{...e}:void 0}function Yc(e){if(e)return{...e,imageSource:ji(e.imageSource),presentation:Wi(e.presentation)}}function Ym(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function jm(e,n){return(e??"")===(n??"")}function Wm(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function jc(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length];if(!(Hi(jo(Fn(r,o),Fn(i,o)))<=1e-9))return t===0?{vertices:e,uvs:n}:{vertices:[...e.slice(t),...e.slice(0,t)],uvs:n?[...n.slice(t),...n.slice(0,t)]:void 0}}return{vertices:e,uvs:n}}function sn(e){let n=[],t=[],o=new WeakMap,r=m=>{let p=o.get(m);if(p)return p;let g=Bm(m);return o.set(m,g),g},i=(m,p)=>{let g=r(m),h=r(p);return g<h?`${g}|${h}`:`${h}|${g}`},s=(m,p)=>r(m)<r(p)?1:-1,a=m=>{let p=new Map;for(let g=0;g<m.length;g++){let h=m[g],y=m[(g+1)%m.length];p.set(i(h,y),s(h,y))}return p},c=0,l=!1,u=m=>(c+=m,c<=8e6?!0:(l=!0,!1));for(let m of e??[]){if(!m||!m.vertices||m.vertices.length<3){m&&n.push(m);continue}let p=m.vertices,g=Wc(p);if(!g){n.push(m);continue}let h=m.texture&&m.uvs&&m.uvs.length===p.length?m.uvs.map(b=>[b[0],b[1]]):void 0,y=m.texture&&h?m.textureTriangles?.length?Xm(m.textureTriangles):Wm(p,h):void 0;t.push({vertices:p,uvs:h,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureImageSource:ji(m.textureImageSource),texturePresentation:Wi(m.texturePresentation),material:Yc(m.material),textureTriangles:y,normal:g.normal,d:g.d,edgeDirections:a(p),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let h=0;h<t.length;h++){let y=t[h];if(!y.alive)continue;let b=y.vertices.length;if(!u(b))return!1;for(let x=0;x<b;x++){let P=y.vertices[x],M=y.vertices[(x+1)%b],C=i(P,M),E=m.get(C);E?E.second<0&&(E.second=h):(E={a:P,b:M,first:h,second:-1},m.set(C,E))}}let p=!1,g=(h,y,b)=>{let x=h.edgeDirections.get(i(y,b));return x?x===s(y,b)?1:-1:0};for(let h of m.values()){if(h.second<0)continue;let y=h.first,b=h.second;if(y===b)continue;let x=t[y],P=t[b];if(!x.alive||!P.alive||x.color!==P.color||x.texture!==P.texture||!Ym(x.textureWrap,P.textureWrap)||!jm(x.textureAlphaMode,P.textureAlphaMode)||x.doubleSided!==P.doubleSided)continue;let M=!!(x.texture||P.texture);if(M&&(!x.textureTriangles||!P.textureTriangles)||!!x.uvs!=!!P.uvs||(M?!zm(x,P):!km(x,P)))continue;if(!u(x.vertices.length+P.vertices.length))return!1;let C=g(x,h.a,h.b);if(C===0)continue;let E=g(P,h.a,h.b);if(E===0||C===E)continue;let[A,S]=C===1?[h.a,h.b]:[h.b,h.a],T=Um(x,P,A,S);if(T){if(!u(T.vertices.length))return!1;T.vertices.length>96||$m(T.vertices,.001)&&Gm(T.vertices,x.normal)&&(x.vertices=T.vertices,x.uvs=T.uvs,x.edgeDirections=a(T.vertices),x.textureTriangles=M?[...x.textureTriangles??[],...P.textureTriangles??[]]:void 0,P.alive=!1,p=!0)}}return p},d=0;for(;!l&&d<16&&f();)d++;for(let m of t){if(!m.alive)continue;let p={vertices:m.vertices.map(g=>[g[0],g[1],g[2]]),color:m.color};m.texture&&(p.texture=m.texture),m.texture&&m.textureWrap&&(p.textureWrap={...m.textureWrap}),m.texture&&m.textureAlphaMode&&(p.textureAlphaMode=m.textureAlphaMode),m.textureImageSource&&(p.textureImageSource=ji(m.textureImageSource)),m.texturePresentation&&(p.texturePresentation=Wi(m.texturePresentation)),m.material&&(p.material=Yc(m.material)),m.uvs&&(p.uvs=m.uvs.map(g=>[g[0],g[1]])),m.textureTriangles?.length&&(p.textureTriangles=m.textureTriangles),m.doubleSided&&(p.doubleSided=!0),m.data&&(p.data=m.data),n.push(p)}return n}var Hm=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Km=(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]],an=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function Zm(e,n){let t=e.vertices;if(!t||t.length<3)return null;let o=0,r=0,i=0;for(let g=0;g<t.length;g++){let h=t[g],y=t[(g+1)%t.length];o+=(h[1]-y[1])*(h[2]+y[2]),r+=(h[2]-y[2])*(h[0]+y[0]),i+=(h[0]-y[0])*(h[1]+y[1])}let s=Math.hypot(o,r,i);if(s<1e-12)return null;let a=[o/s,r/s,i/s],c=0,l=0,u=0;for(let g of t)c+=g[0],l+=g[1],u+=g[2];let f=1/t.length,d=[c*f,l*f,u*f],m=an(a,d),p=s*.5;return{index:n,polygon:e,normal:a,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function qm(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&an(e.normal,n.normal)<0}function Qm(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*an(n,e),o=n[1]-e[1]*an(n,e),r=n[2]-e[2]*an(n,e),i=Math.hypot(t,o,r);t/=i,o/=i,r/=i;let s=[t,o,r],a=Km(e,s);return{u:s,v:a}}function Jm(e){if(e.local2D)return;let n=Qm(e.normal),t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.polygon.vertices){let c=an(a,n.u),l=an(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}e.local2D=t,e.bbox2D={min:[o,r],max:[i,s]},e.basis=n}function ed(e,n){let t=[],o=1/0,r=1/0,i=-1/0,s=-1/0;for(let a of e.vertices){let c=an(a,n.u),l=an(a,n.v);t.push([c,l]),c<o&&(o=c),c>i&&(i=c),l<r&&(r=l),l>s&&(s=l)}return{local2D:t,bbox2D:{min:[o,r],max:[i,s]}}}function nd(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 Hc(e,n){let t=!1;for(let o=0,r=n.length-1;o<n.length;r=o++){let i=n[o],s=n[r];i[1]>e[1]!=s[1]>e[1]&&e[0]<(s[0]-i[0])*(e[1]-i[1])/(s[1]-i[1]+1e-30)+i[0]&&(t=!t)}return t}function Kc(e){let n=0,t=0;for(let o of e)n+=o[0],t+=o[1];return[n/e.length,t/e.length]}function td(e,n){let t=Kc(e),o=Kc(n),r=1e-4,i=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];Hc(u,n)&&i++}let s=0;for(let l of n){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];Hc(u,e)&&s++}let a=i/e.length,c=s/n.length;return Math.max(a,c)}function od(e,n){let t=e.normal[0],o=e.normal[1],r=e.normal[2],i=Math.abs(t),s=Math.abs(o),a=Math.abs(r),c=t;s>i&&s>a?c=o:a>i&&a>s&&(c=r),c<0&&(t=-t,o=-o,r=-r);let l=Math.round(t/.05),u=Math.round(o/.05),f=Math.round(r/.05),d=e.d*(e.normal[0]===t&&e.normal[1]===o&&e.normal[2]===r?1:-1),m=Math.round(d/(n*2));return`${l},${u},${f}|${m}`}function rd(e,n,t,o){let r=an(e.normal,n.normal);if(Math.abs(r)<1-t)return!1;let i=r>0?1:-1;return Math.abs(e.d-i*n.d)<o}function Zc(e,n){let t=Hm(n,e.centroid);return an(e.normal,t)>0}function jt(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,o=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,i=n?.preserveDoubleSidedBackfaces??!0,s=[];for(let p=0;p<e.length;p++){let g=Zm(e[p],p);g&&s.push(g)}if(s.length<2)return new Set;let a=0,c=0,l=0,u=0;for(let p of s)a+=p.centroid[0]*p.area,c+=p.centroid[1]*p.area,l+=p.centroid[2]*p.area,u+=p.area;let f=u>0?[a/u,c/u,l/u]:[0,0,0],d=new Map;for(let p of s){let g=od(p,o),h=d.get(g);h||(h=[],d.set(g,h)),h.push(p)}let m=new Set;for(let p of d.values())if(!(p.length<2))for(let g=0;g<p.length;g++){let h=p[g];if(!m.has(h.index))for(let y=g+1;y<p.length;y++){let b=p[y];if(m.has(b.index)||!rd(h,b,t,o)||i&&qm(h,b))continue;Jm(h);let x=ed(b.polygon,h.basis);if(!nd(h.bbox2D,x.bbox2D)||td(h.local2D,x.local2D)<r)continue;let M=Zc(h,f),C=Zc(b,f),E;if(M&&!C?E=h:C&&!M?E=b:E=h.area<b.area?h:b,m.add(E.index),E===h)break}}return m}function qc(e,n){if(!e||e.length<2)return e??[];let t=jt(e,n);if(t.size===0)return e;let o=[];for(let r=0;r<e.length;r++)t.has(r)||o.push(e[r]);return o}var id=4,sd=8,ad=.001,cd=1e-9,ld=1e6,ud=1e6,fd=8,Yn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],qi=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Kt=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],jn=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],nl=(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]],tl=e=>Math.hypot(e[0],e[1],e[2]);function Zt(e){let n=tl(e);return n<=cd?null:[e[0]/n,e[1]/n,e[2]/n]}function Ht(e,n){return Math.round(e*n)/n}function cn(e){return Ht(e,ld)}function Ki(e){return Ht(e,ud)}function Zi(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function En(e){return`${cn(e[0])},${cn(e[1])}`}function md(e){let n=En(e.a),t=En(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function bt(e){return`${e[0]},${e[1]},${e[2]}`}function ol(e,n){let t=bt(e),o=bt(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Qi(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Qc(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",Qi(e.data)].join("|")}function rl(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],o=[0,0,0];for(let i=1;i<n.length-1;i++)o=qi(o,nl(Yn(n[i],t),Yn(n[i+1],t)));let r=Zt(o);return r?{normal:r,d:jn(r,t)}:null}function dd(e,n,t){return jn(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function pd(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function gd(e,n){let t=n[e[0]]?.data,o=Qi(t);for(let r of e)if(Qi(n[r].data)!==o)return;return t?{...t}:void 0}function hd(e,n){return e.every(t=>n[t].doubleSided===!0)}function yd(e,n){let t=e.map(c=>pd(c)?rl(c):null),o=t.map(Boolean),r=new Map;for(let c=0;c<e.length;c++){if(!t[c])continue;let l=e[c].vertices;for(let u=0;u<l.length;u++){let f=ol(l[u],l[(u+1)%l.length]),d=r.get(f),m={polygon:c,edge:u};d?d.push(m):r.set(f,[m])}}let i=e.map(()=>new Set);for(let c of r.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l].polygon,d=c[u].polygon,m=t[f],p=t[d];!m||!p||Qc(e[f])===Qc(e[d])&&dd(m,p,n)&&(i[f].add(d),i[d].add(f))}let s=new Set,a=[];for(let c=0;c<e.length;c++){if(!o[c]||s.has(c))continue;let l=[],u=[c];for(s.add(c);u.length>0;){let f=u.shift();l.push(f);for(let d of i[f])s.has(d)||(s.add(d),u.push(d))}a.push(l)}return{groups:a}}function bd(e,n){let t=new Set(e),o=new Map;for(let i of e){let s=n[i].vertices;for(let a=0;a<s.length;a++){let c=ol(s[a],s[(a+1)%s.length]),l=o.get(c),u={polygon:i,edge:a};l?l.push(u):o.set(c,[u])}}let r=[];for(let i of o.values()){let s=i.filter(a=>t.has(a.polygon));if(s.length===1){let a=s[0],c=n[a.polygon].vertices;r.push({a:c[a.edge],b:c[(a.edge+1)%c.length]})}else if(s.length!==2)return null}return r}function xd(e){let n=new Map;for(let t of e)n.set(bt(t.a),(n.get(bt(t.a))??0)+1),n.set(bt(t.b),(n.get(bt(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function il(e){let n=[e[0],e[1],e[2]],t=Math.abs(n[0])>=Math.abs(n[1])&&Math.abs(n[0])>=Math.abs(n[2])?0:Math.abs(n[1])>=Math.abs(n[2])?1:2;return n[t]<0?[-n[0],-n[1],-n[2]]:n}function Pd(e){let n=il(e);return`${Ht(n[0],1e3)},${Ht(n[1],1e3)},${Ht(n[2],1e3)}`}function Md(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=Yn(n,Kt(e,jn(n,e)));return Zt(t)??[1,0,0]}function Sd(e,n,t){let o=new Map;for(let i of e){let s=Yn(i.b,i.a),a=Yn(s,Kt(n,jn(s,n))),c=Zt(a);if(!c)continue;let l=il(c),u=Pd(l),f=tl(a),d=o.get(u);d?d.weight+=f:o.set(u,{axis:l,weight:f})}let r=[...o.values()].sort((i,s)=>s.weight-i.weight).slice(0,t).map(i=>i.axis);return r.length===0&&r.push(Md(n)),r}function Jc(e,n,t,o){let r=Yn(e,n);return[cn(jn(r,t)),cn(jn(r,o))]}function Ad(e){let n=[...e].sort((o,r)=>o-r),t=[];for(let o of n)(t.length===0||Math.abs(o-t[t.length-1])>1e-7)&&t.push(o);return t}function Wt(e,n){let[t,o]=e.a,[r,i]=e.b,s=(n-t)/(r-t);return cn(o+(i-o)*s)}function Ji(e){let n=[];for(let o of e)(n.length===0||Math.abs(o[0]-n[n.length-1][0])>1e-7||Math.abs(o[1]-n[n.length-1][1])>1e-7)&&n.push(o);n.length>1&&Math.abs(n[0][0]-n[n.length-1][0])<=1e-7&&Math.abs(n[0][1]-n[n.length-1][1])<=1e-7&&n.pop();let t=[];for(let o=0;o<n.length;o++){let r=n[(o-1+n.length)%n.length],i=n[o],s=n[(o+1)%n.length],a=(i[0]-r[0])*(s[1]-i[1])-(i[1]-r[1])*(s[0]-i[0]);Math.abs(a)>1e-8&&t.push(i)}return t}function Ho(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-r[0]*o[1]}return n/2}function Ko(e){let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let[i,s]of e)n=Math.min(n,i),t=Math.min(t,s),o=Math.max(o,i),r=Math.max(r,s);return{minX:n,minY:t,maxX:o,maxY:r}}function sl(e,n){return!(e.maxX<n.minX-1e-7||n.maxX<e.minX-1e-7||e.maxY<n.minY-1e-7||n.maxY<e.minY-1e-7)}function Wo(e){return Math.abs(Ho(e))}function Cd(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-8)continue;let a=s>0?1:-1;if(n===0)n=a;else if(n!==a)return!1}return!0}function Td(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=e[0]-n[0],s=e[1]-n[1],a=o*s-r*i,c=Math.hypot(o,r);if(c<=1e-9||Math.abs(a)>Math.max(1e-8,c*1e-8))return!1;let l=i*o+s*r;return l>=-1e-8&&l<=o*o+r*r+1e-8}function Ed(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],i=o*o+r*r;return i<=1e-12?0:((e[0]-n[0])*o+(e[1]-n[1])*r)/i}function vd(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=Math.hypot(r,i),l=Math.hypot(s,a);if(c<=1e-9||l<=1e-9)return!1;let u=r*(t[1]-e[1])-i*(t[0]-e[0]),f=r*(o[1]-e[1])-i*(o[0]-e[0]),d=r*a-i*s,m=Math.max(1e-8,Math.max(c,l)*1e-8);if(Math.abs(u)>m||Math.abs(f)>m||Math.abs(d)>m)return!1;let p=Math.abs(r)>=Math.abs(i),g=Math.min(p?e[0]:e[1],p?n[0]:n[1]),h=Math.max(p?e[0]:e[1],p?n[0]:n[1]),y=Math.min(p?t[0]:t[1],p?o[0]:o[1]),b=Math.max(p?t[0]:t[1],p?o[0]:o[1]);return Math.min(h,b)-Math.max(g,y)>1e-8}function Id(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];for(let i=0;i<n.length;i++)if(vd(o,r,n[i],n[(i+1)%n.length]))return!0}return!1}function el(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=[{t:0,point:r},{t:1,point:i}];for(let c of n)Zi(c,r)||Zi(c,i)||Td(c,r,i)&&s.push({t:Ed(c,r,i),point:c});s.sort((c,l)=>c.t-l.t);let a=[];for(let c of s)a.some(l=>Math.abs(l.t-c.t)<=1e-8||Zi(l.point,c.point))||a.push(c);for(let c=0;c<a.length-1;c++){let l=a[c].point,u=a[c+1].point;Math.hypot(u[0]-l[0],u[1]-l[1])<=1e-8||t.push({a:[cn(l[0]),cn(l[1])],b:[cn(u[0]),cn(u[1])]})}}return t}function _d(e,n,t=Ko(e),o=Ko(n)){if(!sl(t,o)||!Id(e,n))return null;let r=[...el(e,n),...el(n,e)],i=new Map;for(let y of r){let b=md(y),x=i.get(b);x?x.push(y):i.set(b,[y])}let s=!1,a=[];for(let y of i.values()){if(y.length===1){a.push(y[0]);continue}s=!0;let b=y.filter(P=>En(P.a)<En(P.b)).length,x=y.length-b;if(b!==x)return null}if(!s||a.length<3)return null;let c=new Map;for(let y of a){let b=En(y.a);if(c.has(b))return null;c.set(b,y)}let l=a[0],u=En(l.a),f=[],d=new Set,m=u;for(let y=0;y<=a.length;y++){let b=c.get(m);if(!b)return null;let x=`${En(b.a)}>${En(b.b)}`;if(d.has(x))return null;if(d.add(x),f.push(b.a),m=En(b.b),m===u)break}if(m!==u||d.size!==a.length)return null;let p=Ji(f);if(p.length<3||!Cd(p))return null;let g=Wo(p),h=Wo(e)+Wo(n);return Math.abs(g-h)>Math.max(1e-5,h*1e-5)?null:Ho(p)>=0?p:[...p].reverse()}function Vd(e){let n=e.map(Ji).filter(r=>r.length>=3&&Wo(r)>1e-8),t=n.map(Ko),o=!0;for(;o;){o=!1;for(let r=0;r<n.length;r++){for(let i=r+1;i<n.length;i++){if(!sl(t[r],t[i]))continue;let s=_d(n[r],n[i],t[r],t[i]);if(s){n[r]=s,t[r]=Ko(s),n.splice(i,1),t.splice(i,1),o=!0;break}}if(o)break}}return n}function Od(e,n,t){let o=new Map;return r=>{let i=cn(r[0]),s=cn(r[1]),a=`${i},${s}`,c=o.get(a);if(c)return[c[0],c[1],c[2]];let l=qi(e,qi(Kt(n,i),Kt(t,s))),u=[Ki(l[0]),Ki(l[1]),Ki(l[2])];return o.set(a,u),[u[0],u[1],u[2]]}}function Rd(e,n,t,o,r){let i=t[0]?.a;if(!i)return null;let s=Zt(Yn(r,Kt(o,jn(r,o))));if(!s)return null;let a=Zt(nl(o,s));if(!a)return null;let c=[],l=[];for(let y of t){let b=Jc(y.a,i,s,a),x=Jc(y.b,i,s,a);Math.hypot(b[0]-x[0],b[1]-x[1])<=1e-7||(c.push({a:b,b:x}),l.push(b[0],x[0]))}let u=Ad(l);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,d=gd(e,n),m=hd(e,n),p=[];for(let y=0;y<u.length-1;y++){let b=u[y],x=u[y+1];if(x-b<=1e-7)continue;let P=(b+x)/2,M=c.filter(C=>{let E=Math.min(C.a[0],C.b[0]),A=Math.max(C.a[0],C.b[0]);return E<P&&P<A&&Math.abs(C.a[0]-C.b[0])>1e-7}).map(C=>({segment:C,yMid:Wt(C,P)})).sort((C,E)=>C.yMid-E.yMid);if(M.length!==0){if(M.length%2!==0)return null;for(let C=0;C<M.length;C+=2){let E=M[C].segment,A=M[C+1].segment,S=Wt(E,b),T=Wt(E,x),v=Wt(A,b),R=Wt(A,x),O=Ji([[b,S],[x,T],[x,R],[b,v]]);if(O.length<3||Math.abs(Ho(O))<=1e-8)continue;let L=Ho(O)>0?O:[...O].reverse();p.push(L)}}}if(p.length===0||e.length>2&&p.length>e.length*fd)return null;let g=Od(i,s,a),h=Vd(p).map(y=>({vertices:y.map(g),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return sn(h)}function Ld(e,n,t){let o=bd(e,n);if(!o||o.length<3||!xd(o))return null;let r=rl(n[e[0]]);if(!r)return null;let i=null;for(let s of Sd(o,r.normal,t)){let a=Rd(e,n,o,r.normal,s);a&&(!i||a.length<i.length)&&(i=a)}return!i||i.length>=e.length?null:i}function Zo(e,n={}){let t=n.minGroupPolygons??id,o=n.maxCandidateAxes??sd,r=n.planeEpsilon??ad,i=e??[];if(i.length<t)return i;let{groups:s}=yd(i,r);if(s.length===0)return i;let a=new Map,c=new Set;for(let u of s){if(u.length<t)continue;let f=Ld(u,i,o);if(f){a.set(u[0],f);for(let d of u)c.add(d)}}if(a.size===0)return i;let l=[];for(let u=0;u<i.length;u++){let f=a.get(u);if(f){l.push(...f);continue}c.has(u)||l.push(i[u])}return l}function wd(e,n){let t=`${e[0]},${e[1]},${e[2]}`,o=`${n[0]},${n[1]},${n[2]}`;return t<o?`${t}|${o}`:`${o}|${t}`}function Nd(e){if(e.length<100)return!1;let n=new Map;for(let o of e){let r=o.vertices;for(let i=0;i<r.length;i++){let s=wd(r[i],r[(i+1)%r.length]);n.set(s,(n.get(s)??0)+1)}}let t=0;for(let o of n.values())o===1&&(t+=1);return t>=128&&t/Math.max(1,n.size)>.2}function Dd(e,n,t){let o=Math.abs(e)>.9?0:1,r=Math.abs(e)>.9?1:0,i=r*t,s=-o*t,a=o*n-r*e,c=Math.hypot(i,s,a);return i/=c,s/=c,a/=c,{ux:i,uy:s,uz:a,vx:n*a-t*s,vy:t*i-e*a,vz:e*s-n*i}}function Fd(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[j,G,Z]of n)t+=j,o+=G,r+=Z;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=Dd(g,h,y),S=n.length-2,T=new Float64Array(S*9),v=0;for(let j=1;j<n.length-1;j++){let G=n[0],Z=n[j],ee=n[j+1];T[v++]=G[0],T[v++]=G[1],T[v++]=G[2],T[v++]=Z[0],T[v++]=Z[1],T[v++]=Z[2],T[v++]=ee[0],T[v++]=ee[1],T[v++]=ee[2]}let R=0,O=1/0,L=1/0,D=1/0,_=-1/0,w=-1/0,V=-1/0;for(let[j,G,Z]of n){let ee=j-t,W=G-o,ie=Z-r,z=ee*ee+W*W+ie*ie;z>R&&(R=z),j<O&&(O=j),j>_&&(_=j),G<L&&(L=G),G>w&&(w=G),Z<D&&(D=Z),Z>V&&(V=Z)}return{centroid:[t,o,r],normal:[g,h,y],vertices:n,triFlat:T,bcx:t,bcy:o,bcz:r,br2:R,ux:x,uy:P,uz:M,vx:C,vy:E,vz:A,minX:O,minY:L,minZ:D,maxX:_,maxY:w,maxZ:V}}function Bd(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function kd(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(Bd(e,n,t,o,r,i,p,h))return!0;return!1}var qt=9,zd=6,Ke=8;function es(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function Ud(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*qt),l=0,u=new Float64Array(Ke),f=new Float64Array(Ke),d=new Float64Array(Ke),m=new Float64Array(Ke),p=new Float64Array(Ke),g=new Float64Array(Ke),h=new Int32Array(Ke),y=new Float64Array(Ke-1),b=new Int32Array(Ke-1),x=new Float64Array(Ke-1),P=new Int32Array(Ke-1);function M(C,E){let A=l++,S=A*qt,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=zd)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=es(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ce=Ke/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),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ce|0;oe>=Ke&&(oe=Ke-1);let pe=e[o[K]];pe.minX<u[oe]&&(u[oe]=pe.minX),pe.maxX>m[oe]&&(m[oe]=pe.maxX),pe.minY<f[oe]&&(f[oe]=pe.minY),pe.maxY>p[oe]&&(p[oe]=pe.maxY),pe.minZ<d[oe]&&(d[oe]=pe.minZ),pe.maxZ>g[oe]&&(g[oe]=pe.maxZ),h[oe]++}let Ve=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<Ke-1;K++)u[K]<Ve&&(Ve=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=es(Ve,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=Ke-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=es(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<Ke-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ce)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*qt+7]=ae,c[A*qt+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function ns(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*qt,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&kd(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function Gd(e){let n=al.get(e);if(n)return n;let t=(1+Math.sqrt(5))/2,o=new Float64Array(e*3);for(let r=0;r<e;r++){let i=(r+.5)/e,s=Math.sqrt(Math.max(0,1-i*i)),a=2*Math.PI*(r/t);o[r*3]=s*Math.cos(a),o[r*3+1]=s*Math.sin(a),o[r*3+2]=i}return al.set(e,o),o}var al=new Map;function hn(e,n){let t=n?.samples??8;if(e.length<4||t<1||!n?.force&&Nd(e))return e;let o=Math.max(1,Math.ceil(t*(n?.minEscapeRatio??1/t))),r=e.map(Fd),i=Gd(t),s=[],a=Ud(r),c=new Int32Array(Math.max(64,a.nodeCount)),l=192,u=new Float64Array(l);for(let f=0;f<e.length;f++){let d=r[f];if(!d){s.push(e[f]);continue}let m=d.normal[0],p=d.normal[1],g=d.normal[2],h=.001*m,y=.001*p,b=.001*g;{let D=d.centroid[0]+h,_=d.centroid[1]+y,w=d.centroid[2]+b;if(!ns(D,_,w,m,p,g,f,a,c)){s.push(e[f]);continue}}let{ux:x,uy:P,uz:M,vx:C,vy:E,vz:A}=d,S=d.centroid[0],T=d.centroid[1],v=d.centroid[2],R=d.vertices,O=R.length,L=0;u[L++]=S+h,u[L++]=T+y,u[L++]=v+b;for(let D=0;D<O;D++){let _=R[D];u[L++]=_[0]+(S-_[0])*.08+h,u[L++]=_[1]+(T-_[1])*.08+y,u[L++]=_[2]+(v-_[2])*.08+b}for(let D=0;D<O;D++){let _=R[D],w=R[(D+1)%O],V=(_[0]+w[0])*.5,j=(_[1]+w[1])*.5,G=(_[2]+w[2])*.5;u[L++]=V+(S-V)*.08+h,u[L++]=j+(T-j)*.08+y,u[L++]=G+(v-G)*.08+b}if(o<=1){let D=!1;e:for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!ns(ie,z,X,G,Z,ee,f,a,c)){D=!0;break e}}}D&&s.push(e[f])}else{let D=0;for(let _=0;_<i.length;_+=3){let w=i[_],V=i[_+1],j=i[_+2],G=w*x+V*C+j*m,Z=w*P+V*E+j*p,ee=w*M+V*A+j*g;for(let W=0;W<L;W+=3){let ie=u[W],z=u[W+1],X=u[W+2];if(!ns(ie,z,X,G,Z,ee,f,a,c)){D++;break}}}D>=o&&s.push(e[f])}}return s}var ss={overlapPx:1.25,maxGapPx:14,capacityScale:1},as={budget:40};function Wn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function xt(e){return typeof e=="number"?{overlapPx:Math.max(0,e)*.175,maxGapPx:14,capacityScale:1}:{overlapPx:Math.max(0,Wn(e?.overlapPx,1.25)),maxGapPx:Math.max(0,Wn(e?.maxGapPx,14)),capacityScale:Math.max(0,Wn(e?.capacityScale,1))}}function Pt(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function pl(e){return{rotX:Wn(e?.rotX,65),rotY:Wn(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(Wn(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(Wn(e?.budget,40))))}}function vn(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function gl(e){return[e[1]/50,e[0]/50,e[2]/50]}function tr(e){return`${e[0]},${e[1]},${e[2]}`}function $d(e,n){let t=tr(e),o=tr(n);return t<o?`${t}|${o}`:`${o}|${t}`}function In(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Mt(e){return Math.hypot(e[0],e[1],e[2])}function no(e){let n=Mt(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function eo(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function qo(e,n,t,o){let r=n*Math.PI/180,i=t*Math.PI/180,s=o*Math.PI/180,[a,c,l]=e;if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,c]=[a*u-c*f,a*f+c*u]}if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,l]=[a*u+l*f,-a*f+l*u]}if(r!==0){let u=Math.cos(r),f=Math.sin(r);[c,l]=[c*u-l*f,c*f+l*u]}return[a,c,l]}function cs(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 Xd(e){if(e.length<3)return null;let n=e[0],t=[0,0,0];for(let o=1;o+1<e.length;o+=1){let r=In(e[o],n),i=In(e[o+1],n),s=cs(r,i);t[0]-=s[0],t[1]-=s[1],t[2]-=s[2]}return no(t)}function ls(e){let n=e[0],t=Xd(e);if(!t)return null;let o=null;for(let u=0;u<e.length;u+=1){let f=In(e[(u+1)%e.length],e[u]);if(Mt(f)>1e-6){o=f;break}}if(!o)return null;let r=eo(o,t),i=[o[0]-r*t[0],o[1]-r*t[1],o[2]-r*t[2]],s=no(i);if(!s)return null;let a=no(cs(t,s));if(!a)return null;let c=e.map(u=>{let f=In(u,n);return[eo(f,s),eo(f,a)]}),l=or(c);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:s,yAxis:a,local:c,area:l}:null}function or(e){let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function us(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t+=1){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=1e-6)continue;let a=Math.sign(s);if(n===0)n=a;else if(a!==n)return!1}return!0}function hl(e,n,t){let o=e[t],r=e[(t+1)%e.length],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return null;let c=n>0?1:-1;return[c*(s/a),c*(-i/a)]}function Yd(e,n){let t=hl(e.local,e.area,n);return t?no([e.xAxis[0]*t[0]+e.yAxis[0]*t[1],e.xAxis[1]*t[0]+e.yAxis[1]*t[1],e.xAxis[2]*t[0]+e.yAxis[2]*t[1]]):null}function yl(e,n){let t=e.length,o=e[n],r=e[(n+1)%t],i=r[0]-o[0],s=r[1]-o[1],a=Math.hypot(i,s);if(a<=1e-6)return 0;let c=[a*.24],l=1/0;for(let f=0;f<t;f+=1){if(f===n||f===(n+1)%t)continue;let d=e[f],m=Math.abs((d[0]-o[0])*s-(d[1]-o[1])*i)/a;m>1e-6&&(l=Math.min(l,m))}Number.isFinite(l)&&c.push(l*.32);let u=[{origin:o,point:e[(n+t-1)%t]},{origin:r,point:e[(n+2)%t]}];for(let f of u){let d=f.point[0]-f.origin[0],m=f.point[1]-f.origin[1],p=Math.hypot(d,m);if(p<=1e-6)continue;let g=Math.abs(i*m-s*d)/(a*p);g>1e-6&&c.push(p*g*.32)}return Math.min(...c)}function bl(e){return e.map(n=>{let t=vn(n.vertices),o=ls(t),r=!fs(n)&&!!o&&us(o.local),i=r?o.local.map((s,a)=>yl(o.local,a)):[];return{basis:o,cssPoints:t,capacities:i,patchable:r}})}function fs(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function jd(e){return e.material?.key??e.color??""}function xl(e,n,t){let o=[];for(let r=0;r<n.length;r+=1){let i=n[r];if(!(!i.patchable||!i.basis))for(let s=0;s<i.cssPoints.length;s+=1){let a=i.cssPoints[s],c=i.cssPoints[(s+1)%i.cssPoints.length],l=In(c,a),u=Mt(l),f=no(l),d=Yd(i.basis,s),m=(i.capacities[s]??0)*t;!f||!d||m<=1e-6||u<=1e-6||o.push({index:o.length,polygon:r,edge:s,key:$d(a,c),a,b:c,minX:Math.min(a[0],c[0]),minY:Math.min(a[1],c[1]),minZ:Math.min(a[2],c[2]),maxX:Math.max(a[0],c[0]),maxY:Math.max(a[1],c[1]),maxZ:Math.max(a[2],c[2]),length:u,dir:f,normal:i.basis.normal,outward:d,capacity:m,materialKey:jd(e[r]),color:e[r].color})}}return o}function ms(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function Qo(e,n){return Mt(In(e,n))<=1e-4}function Wd(e,n){return Qo(e.a,n.a)||Qo(e.a,n.b)||Qo(e.b,n.a)||Qo(e.b,n.b)}function Hd(e,n){return ms(e,n)?Wd(e,n)?"connected-facet":"true-gap":"material-boundary"}function ts(e,n,t,o,r,i){return{kind:e,aPolygon:n.polygon,aEdge:n.edge,bPolygon:t.polygon,bEdge:t.edge,aColor:n.color,bColor:t.color,aMaterialKey:n.materialKey,bMaterialKey:t.materialKey,gapPx:o.gap,spanPx:o.aEnd-o.aStart,aStartPx:o.aStart,aEndPx:o.aEnd,bStartPx:o.bStart,bEndPx:o.bEnd,targetClosurePx:r,appliedClosurePx:i,residualGapPx:Math.max(0,o.gap-i),residualTargetPx:Math.max(0,r-i)}}function cl(e,n,t,o,r){let i=Math.max(0,Math.min(n.length,Math.min(t,o))),s=Math.max(0,Math.min(n.length,Math.max(t,o)));if(r<=1e-6||s-i<=1e-6)return;let a=e[n.polygon].get(n.edge),c={start:i,end:s,amount:r};a?a.push(c):e[n.polygon].set(n.edge,[c])}function rr(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function Kd(e,n){let t=0,o=0,r=0;for(let i of e){i.size>0&&(r+=1),o+=i.size;for(let s of i.values())for(let a of s)t=Math.max(t,a.amount)}return{...n,patchedPolygons:r,patchedEdges:o,maxAppliedAmountPx:t}}function ir(e,n,t=!1,o=!1){let r=bl(e),i=xl(e,r,n.capacityScale),s=o?[]:e.map(()=>new Map),a=rr(),c=t?[]:void 0;if(i.length===0)return{edgeRepairs:s,diagnostics:a,candidates:c};let l=new Map;for(let u of i){let f=l.get(u.key);f?f.push(u):l.set(u.key,[u])}for(let u of l.values())u.length<2||(a.exactPairs+=u.length===2?1:u.length);return Zd(i,l,s,a,n,c),{edgeRepairs:s,diagnostics:o?a:Kd(s,a),candidates:c}}function Zd(e,n,t,o,r,i){let s=r.maxGapPx,a=new Set;for(let[m,p]of n)p.length>1&&a.add(m);let c=(m,p)=>{let g=m.index<p.index?m:p,h=m.index<p.index?p:m;if(h.polygon===g.polygon||g.key===h.key&&a.has(g.key)||!i&&!ms(g,h)||!qd(g,h,s)||Math.abs(eo(g.dir,h.dir))<.985)return;let y=np(g,h,s);if(!y)return;let b=Hd(g,h),x=y.gap+r.overlapPx;if(b==="material-boundary"){i?.push(ts(b,g,h,y,x,0));return}let P=x;if(P<=.25){i?.push(ts(b,g,h,y,x,0));return}let M=g.capacity*y.facingA,C=h.capacity*y.facingB,E=Math.min(M,P/2),A=Math.min(C,P/2);if(P-=E+A,P>1e-6){let S=Math.min(M-E,P);E+=S,P-=S}if(P>1e-6){let S=Math.min(C-A,P);A+=S,P-=S}i?.push(ts(b,g,h,y,x,E+A)),t.length>0&&E>1e-6&&cl(t,g,y.aStart,y.aEnd,E/y.facingA),t.length>0&&A>1e-6&&cl(t,h,y.bStart,y.bEnd,A/y.facingB),o.nearPairs+=1,o.maxMeasuredGapPx=Math.max(o.maxMeasuredGapPx,y.gap),P>.25&&(o.unclosedPairs+=1,o.maxResidualGapPx=Math.max(o.maxResidualGapPx,P))},l=Math.max(28,s*2);if(e.length<=1e4){let m=[...e].sort((h,y)=>h.minX-y.minX),p=new Int32Array(m.length),g=0;for(let h=0;h+1<m.length;h+=1){let b=m[h].maxX+s,x=h+1;for(;x<m.length&&m[x].minX<=b;)x+=1;if(p[h]=x,g+=x-h-1,g>25e6)break}if(g<=2e6||g<=25e6&&ep(e,l,s)){for(let h=0;h+1<m.length;h+=1)for(let y=h+1;y<p[h];y+=1)c(m[h],m[y]);return}}let u=new Map;for(let m of e)Qd(u,m,l,s);let f=new Set,d=e.length;for(let m of u.values())for(let p=0;p+1<m.length;p+=1)for(let g=p+1;g<m.length;g+=1){let h=m[p],y=m[g],b=h.index<y.index?h:y,x=h.index<y.index?y:h,P=b.index*d+x.index;f.has(P)||(f.add(P),c(b,x))}}function qd(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function ll(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function Qd(e,n,t,o){let[r,i,s,a,c,l]=Pl(n,t,o);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function Pl(e,n,t){let[o,r,i]=ll([e.minX-t,e.minY-t,e.minZ-t],n),[s,a,c]=ll([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[o,r,i,s,a,c]}function Jd(e,n,t){let[o,r,i,s,a,c]=Pl(e,n,t);return(s-o+1)*(a-r+1)*(c-i+1)}function ep(e,n,t){let o=0,r=0;for(let i of e){let s=Jd(i,n,t);if(o+=s,s>r&&(r=s),r>8192)return!0}return o/Math.max(1,e.length)>256}function ul(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function fl(e,n,t){return(e.a[0]+e.dir[0]*n-t.a[0])*t.dir[0]+(e.a[1]+e.dir[1]*n-t.a[1])*t.dir[1]+(e.a[2]+e.dir[2]*n-t.a[2])*t.dir[2]}function np(e,n,t){let o=ul(n.a,e.a,e.dir),r=ul(n.b,e.a,e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i,c=Math.min(e.length,n.length);if(a<Math.max(.75,c*.12))return null;let l=(i+s)/2,u=e.a[0]+e.dir[0]*l,f=e.a[1]+e.dir[1]*l,d=e.a[2]+e.dir[2]*l,m=Math.max(0,Math.min(n.length,(u-n.a[0])*n.dir[0]+(f-n.a[1])*n.dir[1]+(d-n.a[2])*n.dir[2])),p=n.a[0]+n.dir[0]*m-u,g=n.a[1]+n.dir[1]*m-f,h=n.a[2]+n.dir[2]*m-d,y=Math.hypot(p,g,h);if(y<=1e-6||y>t||y>Math.min(t,Math.max(4,c*.28)))return null;let b=1/y,x=p*b,P=g*b,M=h*b,C=e.outward[0]*x+e.outward[1]*P+e.outward[2]*M,E=-(n.outward[0]*x+n.outward[1]*P+n.outward[2]*M);if(C<.5||E<.5)return null;let A=Math.max(0,Math.min(n.length,fl(e,i,n))),S=Math.max(0,Math.min(n.length,fl(e,s,n)));return{gap:y,facingA:C,facingB:E,aStart:i,aEnd:s,bStart:Math.min(A,S),bEnd:Math.max(A,S)}}function os(e,n,t,o){let r=t<=1e-6?0:Math.max(0,Math.min(1,o/t));return[e[0]+(n[0]-e[0])*r,e[1]+(n[1]-e[1])*r]}function Qt(e,n){let t=e[e.length-1];t&&Math.hypot(t[0]-n[0],t[1]-n[1])<=1e-6||e.push(n)}function tp(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let o=new Set([0,n]);for(let s of e){let a=Math.max(0,Math.min(n,s.start)),c=Math.max(0,Math.min(n,s.end));c-a<=1e-6||s.amount<=1e-6||(o.add(a),o.add(c))}let r=Array.from(o).sort((s,a)=>s-a),i=[];for(let s=0;s+1<r.length;s+=1){let a=r[s],c=r[s+1];if(c-a<=1e-6)continue;let l=(a+c)/2,u=0;for(let d of e)l+1e-6<d.start||l-1e-6>d.end||(u=Math.max(u,d.amount));let f=Math.min(t,u);f>1e-6&&i.push({start:a,end:c,amount:f})}return i}function op(e,n){if(n.length<3||!us(n))return!1;let t=or(e),o=or(n);return Math.sign(o)===Math.sign(t)&&Math.abs(o)>=Math.abs(t)-1e-6}function rp(e,n,t){if(n.size===0||e.vertices.length<3||fs(e))return e;let o=vn(e.vertices),r=ls(o);if(!r||!us(r.local))return e;let i=[];for(let l=0;l<r.local.length;l+=1){let u=r.local[l],f=r.local[(l+1)%r.local.length],d=Math.hypot(f[0]-u[0],f[1]-u[1]),m=hl(r.local,r.area,l);if(!m||d<=1e-6)return e;let p=tp(n.get(l),d,yl(r.local,l)*t);Qt(i,u);let g=0;for(let h of p){h.start>g+1e-6&&Qt(i,os(u,f,d,h.start));let y=os(u,f,d,h.start),b=os(u,f,d,h.end);Qt(i,[y[0]+m[0]*h.amount,y[1]+m[1]*h.amount]),Qt(i,[b[0]+m[0]*h.amount,b[1]+m[1]*h.amount]),h.end<d-1e-6&&Qt(i,b),g=h.end}}let s=i[0],a=i[i.length-1];if(s&&a&&Math.hypot(s[0]-a[0],s[1]-a[1])<=1e-6&&i.pop(),!op(r.local,i))return e;let c=i.map(([l,u])=>gl([r.origin[0]+l*r.xAxis[0]+u*r.yAxis[0],r.origin[1]+l*r.xAxis[1]+u*r.yAxis[1],r.origin[2]+l*r.xAxis[2]+u*r.yAxis[2]]));return{...e,vertices:c}}function Ml(e){return e.vertices.length===4&&!fs(e)}function ip(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,o=1/0,r=-1/0,i=-1/0;for(let[c,l]of n)t=Math.min(t,c),o=Math.min(o,l),r=Math.max(r,c),i=Math.max(i,l);let s=Math.max(1e-6,(r-t)*(i-o));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/s)))*2.5}function rs(e,n){return Mt(In(vn([e])[0],vn([n])[0]))}function Jo(e,n,t){let o=rs(e,n),r=rs(n,t),i=rs(t,e),s=Math.max(o,r,i);return s<=1e-6?0:Mt(cs(In(vn([n])[0],vn([e])[0]),In(vn([t])[0],vn([e])[0])))*.5/(s*s)}function sp(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=r*a-i*s;if(Math.abs(c)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*s)/c;return[e[0]+f*r,e[1]+f*i]}function ap(e,n){if(e.length<3||e.length!==n.length)return null;let t=Math.max(0,...n);if(t<=1e-6)return e;let o=or(e);if(Math.abs(o)<=1e-6)return null;let r=o>0?1:-1,i=[];for(let c=0;c<e.length;c+=1){let l=e[c],u=e[(c+1)%e.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=1e-6)return null;let p=Math.max(0,n[c]),g=r*(d/m)*p,h=r*(-f/m)*p;i.push({a:[l[0]+g,l[1]+h],b:[u[0]+g,u[1]+h]})}let s=[],a=Math.max(2,t*4);for(let c=0;c<e.length;c+=1){let l=i[(c+e.length-1)%e.length],u=i[c],f=sp(l.a,l.b,u.a,u.b);if(!f)return null;let d=e[c],m=f[0]-d[0],p=f[1]-d[1],g=Math.hypot(m,p);s.push(g>a?[d[0]+m/g*a,d[1]+p/g*a]:f)}return s}function cp(e,n){return[e.origin[0]+e.xAxis[0]*n[0]+e.yAxis[0]*n[1],e.origin[1]+e.xAxis[1]*n[0]+e.yAxis[1]*n[1],e.origin[2]+e.xAxis[2]*n[0]+e.yAxis[2]*n[1]]}function er(e,n){let t=ls(vn(e));if(!t)return e;let o=ap(t.local,n);return o?o.map(r=>gl(cp(t,r))):e}function lp(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[o,r,i,s]=e.vertices,a=Math.min(Jo(o,r,i),Jo(o,i,s)),c=Math.min(Jo(o,r,s),Jo(r,i,s)),l=u=>n.has(u)?.75:0;return a>=c?[{...t,vertices:er([o,r,i],[l(0),l(1),1.25])},{...t,vertices:er([o,i,s],[1.25,l(2),l(3)])}]:[{...t,vertices:er([o,r,s],[l(0),1.25,l(3)])},{...t,vertices:er([r,i,s],[l(1),l(2),1.25])}]}function ml(e){if(e.length===0)return{q1:1/0,median:1/0,q3:1/0,p70:1/0,p80:1/0,p88:1/0,p95:1/0,p97:1/0,max:1/0};let n=[...e].sort((o,r)=>o-r),t=o=>n[Math.min(n.length-1,Math.floor((n.length-1)*o))]??0;return{q1:t(.25),median:t(.5),q3:t(.75),p70:t(.7),p80:t(.8),p88:t(.88),p95:t(.95),p97:t(.97),max:n[n.length-1]??0}}function nr(e,n){let t=e[n];if(t===n)return n;let o=nr(e,t);return e[n]=o,o}function up(e){let n=new Set,t=new Set;for(let o of e)o.sel&&t.add(o.comp);for(let o of e)if(t.has(o.comp))for(let r of o.e)n.add(r);return{endpoints:n}}function fp(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function mp(e,n,t,o){let r=[];for(let[c,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!ms(u,f))continue;let d=l.filter(C=>Ml(e[C.polygon]));if(d.length===0)continue;let m=d[0],p=1-Math.min(1,Math.abs(eo(u.normal,f.normal))),g=Math.max(u.length,f.length);if(p<.01&&g<64)continue;let h=Math.max(...d.map(C=>ip(n[C.polygon]))),y=d.length===2?1.18:1,b=Math.max(.08,p),x=o.viewAware?dp(u,f,o.rotX,o.rotY):{proj:g,vr:1},P=o.viewAware?Math.max(x.proj,g*.12):g,M=o.viewAware?.18+x.vr*1.82:1;r.push({key:c,e:[tr(m.a),tr(m.b)],o:l,r:d,len:g,rank:P,proj:x.proj,s:P*(.58+b*2.8)*h*y*M,nr:p,sr:h,vr:x.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let i=Array.from({length:r.length},(c,l)=>l),s=new Map;for(let c=0;c<r.length;c+=1)for(let l of r[c].e){let u=s.get(l);if(u===void 0)s.set(l,c);else{let f=nr(i,u),d=nr(i,c);f!==d&&(i[d]=f)}}let a=new Map;for(let c=0;c<r.length;c+=1){let l=nr(i,c),u=a.get(l);u===void 0&&(u=a.size,a.set(l,u)),r[c].comp=u}return r}function dp(e,n,t,o){let r=qo(e.a,t,0,o),i=qo(e.b,t,0,o),s=Math.hypot(i[0]-r[0],i[1]-r[1]),a=qo(e.normal,t,0,o)[2],c=qo(n.normal,t,0,o)[2],l=Math.max(0,a,c),u=Math.min(1,Math.abs(a-c));return{proj:s,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function pp(e){let n=new Map;for(let t of e){let o=n.get(t.comp);(!o||t.s>o.s||t.s===o.s&&t.len>o.len)&&n.set(t.comp,t)}return new Set(n.values())}function Jt(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+n*n*n*3.65,o=e.r.length===1?1.08:1;return e.rank*t*o/Math.sqrt(Math.max(1,e.r.length))}function dl(e){let n=Math.max(0,1-Math.min(1,e.nr)),t=.35+Math.min(1,e.vr)*1.65,o=.7+Math.min(2.6,e.sr)*.3,r=e.r.length===1?1.1:1,i=e.rank*(.6+n*n*1.4)*t*o*r/Math.sqrt(Math.max(1,e.r.length));return Math.max(i,Jt(e)*.75)}function is(e){let n=new Set;for(let t of e)for(let o of t.r)n.add(o.polygon);return n.size}function Sl(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function gp(e,n,t){return e.s>=n||e.rank>=t}function hp(e,n,t,o,r,i,s){let a=Math.max(0,Math.floor(t));if(a<=0||e.length===0||n==="follow-up")return{budgetLimit:a,componentBudgets:null};let c=new Map;for(let m of e){let p=c.get(m.comp);p?p.push(m):c.set(m.comp,[m])}let l=new Map,u=Math.max(1e-6,o.q3-o.q1),f=Math.min(o.max,Math.max(o.p95,o.q3+u)),d=0;for(let[m,p]of c){let g=p.filter(M=>gp(M,i,s)||M.s>=f);if(g.length===0)continue;let h=p.filter(M=>Sl(M,r)),y=is(g),b=is(h),x=Math.ceil(Math.sqrt(Math.max(0,b-y))*3),P=Math.min(is(p),y+x);P<=0||(l.set(m,P),d+=P)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(a,d),componentBudgets:l}}function yp(e,n,t){let o=new Map;if(e.length===0||t<=0)return{selected:o,budgetLimit:0};let r=ml(e.map(S=>S.s)),i=ml(e.map(S=>S.rank)),s=Math.max(1e-6,r.q3-r.q1),a=Math.min(r.max,Math.max(r.p95,r.q3+s*.85)),c=Math.min(r.max,Math.max(r.p80,r.q3+s*.15)),l=Math.min(r.max,Math.max(r.p70,r.q3)),u=Math.max(i.p97,i.median*1.8),f=Math.max(i.p88,i.median*1.35),d=hp(e,n,t,r,i,a,u),m=d.budgetLimit;if(m<=0)return{selected:o,budgetLimit:0};let p=pp(e),g=new Set,h=new Set,y=new Set,b=new Map,x=n==="primary"?Math.min(Math.max(0,d.budgetLimit-1),Math.max(2,Math.floor(d.budgetLimit*.28))):0,P=[...e].sort((S,T)=>Jt(T)-Jt(S)||T.s/Math.max(1,T.r.length)-S.s/Math.max(1,S.r.length)||T.len-S.len),M=[...e].sort((S,T)=>dl(T)-dl(S)||Jt(T)-Jt(S)||T.len-S.len),C=(S,T)=>{S.sel=!0,S.why=T,y.add(S.comp);for(let v of S.e)h.add(v);for(let v of S.r){g.add(v.polygon);let R=o.get(v.polygon);R?R.add(v.edge):o.set(v.polygon,new Set([v.edge]))}},E=(S,T)=>{let v=d.componentBudgets;if(T<=0||!v)return!0;let R=v.get(S.comp)??0;return(b.get(S.comp)??0)+T<=R},A=(S,T)=>{T<=0||!d.componentBudgets||b.set(S.comp,(b.get(S.comp)??0)+T)};for(let S of M){let T=S.r.reduce((R,O)=>R+(g.has(O.polygon)?0:1),0);if(S.cost=T,!(T>m||!E(S,T)||T>0&&m-T<x||!Sl(S,i))&&(C(S,"global-outlier"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((D,_)=>D+(g.has(_.polygon)?0:1),0);if(S.cost=T,T>m||!E(S,T)||T>0&&m-T<x)continue;let v=S.r.length===2,R=p.has(S)&&(n==="primary"||n==="follow-up"&&S.s>=c*1.08&&S.rank>=f)&&(v?S.s>=c||S.rank>=f:S.s>=c*1.18||S.rank>=f*1.12),O=v?S.s>=a||S.rank>=u:S.s>=a*1.35||S.rank>=u*1.2,L=T===0&&(v?S.s>=l||S.rank>=f:S.s>=l*1.25||S.rank>=f*1.12);if(!(!R&&!O&&!L)&&(C(S,R?"component-anchor":O?"global-outlier":"shared-polygon"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let S of P){if(S.sel)continue;let T=S.r.reduce((_,w)=>_+(g.has(w.polygon)?0:1),0);if(S.cost=T,T>1||T>m||!E(S,T))continue;let v=S.r.some(_=>g.has(_.polygon)),R=S.e.some(_=>h.has(_));if(n==="primary"&&S.r.length===1&&T===1&&(y.has(S.comp)||R||v)&&S.rank>=f*1.05&&S.nr>=.16&&S.vr<=.32){if(C(S,"local-follow-up"),A(S,T),m-=T,m<=0)return{selected:o,budgetLimit:d.budgetLimit};continue}if(S.r.length!==2)continue;let L=v&&T===1&&S.proj>=f*1.45&&S.vr<=.18;if(!R&&!L)continue;if((S.s>=l*.42||S.rank>=f*.62)&&S.s<=l*1.1&&S.proj>=24&&(C(S,"local-follow-up"),A(S,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}return{selected:o,budgetLimit:d.budgetLimit}}function Al(e,n,t,o,r){let i=bl(e),s=xl(e,i,n.capacityScale),a=new Map;for(let u of s){let f=a.get(u.key);f?f.push(u):a.set(u.key,[u])}let c=mp(e,i,a,t).filter(u=>fp(u,r)),l=yp(c,r?"follow-up":"primary",o);return{selected:l.selected,candidates:c,budgetLimit:l.budgetLimit}}function bp(e,n){let t=[];for(let o=0;o<e.length;o+=1){let r=e[o],i=n.get(o);i&&Ml(r)?t.push(...lp(r,i)):t.push(r)}return t}function xp(e){let[n,t]=e.o,o=n??t,r=t??n;return{key:e.key,aPolygon:o?.polygon??-1,aEdge:o?.edge??-1,bPolygon:r?.polygon??-1,bEdge:r?.edge??-1,color:o?.color??r?.color,materialKey:o?.materialKey??r?.materialKey??"",lengthPx:e.len,projectedLengthPx:e.proj,score:e.s,normalRisk:e.nr,shapeRisk:e.sr,viewRisk:e.vr,component:e.comp,marginalCost:e.cost,selected:e.sel,reason:e.why}}function ds(e,n,t){let o=xt(n),r=pl(t);if(!Pt(o,n)||e.length===0)return e;let i=e,s,a=r.budget;for(let c=0;c<r.passes;c+=1){let l=Al(i,o,r,a,s);if(c===0&&(a=Math.min(a,l.budgetLimit)),l.selected.size===0)break;let u=bp(i,l.selected);if(u.length===i.length)break;if(a-=l.selected.size,a<=0){i=u;break}s=up(l.candidates),i=u}return i}function Cl(e,n,t){let o=xt(n),r=pl(t);if(!Pt(o,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let i=Al(e,o,r,r.budget),s=0;for(let a of i.selected.values())s+=a.size;return{candidates:i.candidates.map(xp),selectedPolygons:i.selected.size,selectedEdges:s,addedPolygons:i.selected.size}}function ps(e,n){let t=xt(n);if(!Pt(t,n)||e.length===0)return e;let{edgeRepairs:o}=ir(e,t);return o.some(r=>r.size>0)?e.map((r,i)=>rp(r,o[i],t.capacityScale)):e}function Tl(e,n=ss,t=as){if(e.length===0)return e;let o=ds(e,n,t);return ps(o,n)}function El(e,n){let t=xt(n);return!Pt(t,n)||e.length===0?rr():ir(e,t).diagnostics}function vl(e,n){let t=xt(n);return!Pt(t,n)||e.length===0?rr():ir(e,t,!1,!0).diagnostics}function Il(e,n){let t=xt(n);if(!Pt(t,n)||e.length===0)return{diagnostics:rr(),candidates:[]};let o=ir(e,t,!0);return{diagnostics:o.diagnostics,candidates:o.candidates??[]}}var Hn={ratio:.7,maxError:.18,maxNormalDot:Math.cos(65*Math.PI/180),preserveVertices:!0,vertexKeyMode:"relaxed",lockBoundary:!0,minGroupTriangles:80,maxPasses:12};function Pp(e={}){let n=Number.isFinite(e.ratio)?Math.max(.05,Math.min(.98,e.ratio)):Hn.ratio,t=Number.isFinite(e.maxError)&&e.maxError>0?e.maxError:Hn.maxError,o=Number.isFinite(e.maxNormalAngleDeg)?Math.max(0,Math.min(89,e.maxNormalAngleDeg)):65;return{ratio:n,maxError:t,maxNormalDot:Math.cos(o*Math.PI/180),preserveVertices:e.preserveVertices??Hn.preserveVertices,vertexKeyMode:e.vertexKeyMode??Hn.vertexKeyMode,lockBoundary:e.lockBoundary??Hn.lockBoundary,minGroupTriangles:Math.max(3,Math.floor(e.minGroupTriangles??Hn.minGroupTriangles)),maxPasses:Math.max(1,Math.floor(e.maxPasses??Hn.maxPasses))}}function Mp(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function Sp(e){return e.vertices.length===3&&!Mp(e)}function Ap(e){return[e.color??"",e.doubleSided===!0?"2":"1",e.material?.key??""].join("\0")}function _l(e){return`${Math.round(e[0]*1e5)},${Math.round(e[1]*1e5)},${Math.round(e[2]*1e5)}`}function Cp(e,n,t,o){let r=o.vertexKeyMode==="source"?e.simplifySourceVertexKeys?.[t]??e.simplifyVertexKeys?.[t]:e.simplifyVertexKeys?.[t];return r?`${_l(n)}|${r}`:_l(n)}function Tp(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function St(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Ep(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function gs(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Vl(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 bs(e){return Math.hypot(e[0],e[1],e[2])}function hs(e,n){return bs(St(e,n))}function vp(e){let n=bs(e);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n]:[0,0,1]}function xs(e,n,t,o){return vp(Vl(St(e[t],e[n]),St(e[o],e[n])))}function Ol(e,n,t,o){return bs(Vl(St(e[t],e[n]),St(e[o],e[n])))/2}function Ip(){return[0,0,0,0,0,0,0,0,0,0]}function sr(e,n){for(let t=0;t<e.length;t+=1)e[t]+=n[t]}function _p(e,n,t){let o=e[0],r=e[1],i=e[2],s=-gs(e,n);return[o*o*t,o*r*t,o*i*t,o*s*t,r*r*t,r*i*t,r*s*t,i*i*t,i*s*t,s*s*t]}function ys(e,n){let t=n[0],o=n[1],r=n[2];return e[0]*t*t+2*e[1]*t*o+2*e[2]*t*r+2*e[3]*t+e[4]*o*o+2*e[5]*o*r+2*e[6]*o+e[7]*r*r+2*e[8]*r+e[9]}function Vp(e,n,t,o,r,i,s,a,c,l,u,f){let d=e*(r*c-i*a)-n*(o*c-i*s)+t*(o*a-r*s);if(Math.abs(d)<1e-10)return null;let m=1/d,p=l*(r*c-i*a)-n*(u*c-i*f)+t*(u*a-r*f),g=e*(u*c-i*f)-l*(o*c-i*s)+t*(o*f-u*s),h=e*(r*f-u*a)-n*(o*f-u*s)+l*(o*a-r*s),y=[p*m,g*m,h*m];return y.every(Number.isFinite)?y:null}function Op(e,n,t,o){let r=Vp(e[0],e[1],e[2],e[1],e[4],e[5],e[2],e[5],e[7],-e[3],-e[6],-e[8]),i=Ep(Tp(n,t),.5),s=hs(n,t)*1.35,a=o?[n,t]:[n,t,i,...r&&hs(r,i)<=s?[r]:[]],c=a[0],l=ys(e,c);for(let u=1;u<a.length;u+=1){let f=a[u],d=ys(e,f);d<l&&(c=f,l=d)}return c}function Rp(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function Lp(e,n,t){return`${e}|${n}|${t}`}function wp(e,n){let t=new Map,o=[],r=[];for(let i of e){let s=[];for(let u=0;u<i.vertices.length;u+=1){let f=i.vertices[u],d=Cp(i,f,u,n),m=t.get(d);m===void 0&&(m=o.length,t.set(d,m),o.push([...f])),s.push(m)}let[a,c,l]=s;a===void 0||c===void 0||l===void 0||a===c||a===l||c===l||r.push({a,b:c,c:l,polygon:i,normal:xs(o,a,c,l)})}return{vertices:o,triangles:r}}function Np(e,n){let t=wp(e,n),o=Array.from({length:t.vertices.length},()=>new Set),r=Array.from({length:t.triangles.length},()=>!0);for(let i=0;i<t.triangles.length;i+=1){let s=t.triangles[i];o[s.a].add(i),o[s.b].add(i),o[s.c].add(i)}return{vertices:t.vertices,triangles:t.triangles,alive:r,vertexTriangles:o,activeCount:t.triangles.length}}function Dp(e){let n=new Map,t=(o,r,i)=>{let s=Rp(o,r),a=n.get(s);a?a.triangles.push(i):n.set(s,{a:Math.min(o,r),b:Math.max(o,r),triangles:[i]})};for(let o=0;o<e.triangles.length;o+=1){if(!e.alive[o])continue;let r=e.triangles[o];t(r.a,r.b,o),t(r.b,r.c,o),t(r.c,r.a,o)}return n}function Fp(e){let n=Array.from({length:e.vertices.length},()=>Ip());for(let t=0;t<e.triangles.length;t+=1){if(!e.alive[t])continue;let o=e.triangles[t],r=Math.max(1e-6,Ol(e.vertices,o.a,o.b,o.c)),i=_p(o.normal,e.vertices[o.a],Math.sqrt(r));sr(n[o.a],i),sr(n[o.b],i),sr(n[o.c],i)}return n}function Bp(e,n,t){let o=new Set,r=i=>{let s=e.vertexTriangles[i];if(s)for(let a of s)e.alive[a]&&o.add(a)};return r(n),r(t),Array.from(o).sort((i,s)=>i-s)}function kp(e,n,t){let o=e.vertexTriangles[n],r=e.vertexTriangles[t];if(!o||!r)return 0;let[i,s]=o.size<=r.size?[o,r]:[r,o],a=0;for(let c of i)e.alive[c]&&s.has(c)&&(a+=1);return a}function Rl(e,n,t){return[e.a===t?n:e.a,e.b===t?n:e.b,e.c===t?n:e.c]}function zp(e,n,t){if(kp(e,n.a,n.b)!==2)return null;let o=Bp(e,n.a,n.b);if(o.length===0)return null;let r=e.vertices[n.a];e.vertices[n.a]=n.target;let i=0,s=!0;for(let a of o){let c=e.triangles[a],[l,u,f]=Rl(c,n.a,n.b);if(l===u||l===f||u===f)continue;if(Ol(e.vertices,l,u,f)<=1e-8){s=!1;break}let m=xs(e.vertices,l,u,f);if(gs(c.normal,m)<t.maxNormalDot){s=!1;break}let p=c.a===n.a?r:e.vertices[c.a];if(Math.abs(gs(c.normal,St(n.target,p)))>t.maxError){s=!1;break}i+=1}return e.vertices[n.a]=r,s&&i>0?o:null}function Up(e,n,t){e.vertexTriangles[t.a]?.delete(n),e.vertexTriangles[t.b]?.delete(n),e.vertexTriangles[t.c]?.delete(n)}function Gp(e,n,t){e.vertexTriangles[t.a].add(n),e.vertexTriangles[t.b].add(n),e.vertexTriangles[t.c].add(n)}function $p(e,n,t){e.vertices[n.a]=n.target;let o=new Set;for(let r of t){if(!e.alive[r])continue;let i=e.triangles[r],[s,a,c]=Rl(i,n.a,n.b);if(Up(e,r,i),s===a||s===c||a===c){e.alive[r]=!1,e.activeCount-=1;continue}let l=Lp(s,a,c);if(o.has(l)){e.alive[r]=!1,e.activeCount-=1;continue}o.add(l);let u={...i,a:s,b:a,c,normal:xs(e.vertices,s,a,c)};e.triangles[r]=u,Gp(e,r,u)}}function Xp(e,n){let t=Dp(e),o=new Set;for(let a of t.values())a.triangles.length>2&&(o.add(a.a),o.add(a.b));if(n.lockBoundary)for(let a of t.values())a.triangles.length===1&&(o.add(a.a),o.add(a.b));let r=Fp(e),i=n.maxError*n.maxError,s=[];for(let a of t.values()){if(a.triangles.length!==2||o.has(a.a)||o.has(a.b))continue;let c=[...r[a.a]];sr(c,r[a.b]);let l=Op(c,e.vertices[a.a],e.vertices[a.b],n.preserveVertices),u=Math.max(0,ys(c,l));if(u>i*Math.max(1,a.triangles.length))continue;let f=hs(e.vertices[a.a],e.vertices[a.b]);s.push({a:a.a,b:a.b,target:l,error:u,length:f})}return s.sort((a,c)=>a.error-c.error||a.length-c.length),s}function Yp(e){let n=[];for(let t=0;t<e.triangles.length;t+=1)e.alive[t]&&n.push(e.triangles[t]);return n}function jp(e,n){if(e.length<n.minGroupTriangles)return e;let t=Np(e,n),o=t.activeCount;if(o<n.minGroupTriangles)return e;let r=Math.max(1,Math.floor(o*n.ratio));if(r>=o)return e;let i=0;for(let s=0;s<n.maxPasses&&t.activeCount>r;s+=1){let a=Xp(t,n);if(a.length===0)break;let c=0;for(let l of a){if(t.activeCount<=r)break;let u=zp(t,l,n);if(!u)continue;let f=t.activeCount;$p(t,l,u),!(t.activeCount>=f)&&(i+=1,c+=1)}if(c===0)break}return i===0||t.activeCount>=o?e:Yp(t).map(s=>({...s.polygon,vertices:[[...t.vertices[s.a]],[...t.vertices[s.b]],[...t.vertices[s.c]]]}))}function Wp(e){let n=new Map;for(let t=0;t<e.length;t+=1){let o=e[t];if(!Sp(o))continue;let r=Ap(o),i=n.get(r);i?(i.indices.push(t),i.polygons.push(o)):n.set(r,{indices:[t],polygons:[o]})}return n}function ar(e,n){let t=Pp(n),o=Wp(e);if(o.size===0)return e;let r=new Map,i=!1;for(let a of o.values()){let c=jp(a.polygons,t);if(!(c===a.polygons||c.length>=a.polygons.length)){r.set(a.indices[0],c);for(let l=1;l<a.indices.length;l+=1)r.set(a.indices[l],[]);i=!0}}if(!i)return e;let s=[];for(let a=0;a<e.length;a+=1){let c=r.get(a);c?s.push(...c):c===void 0&&s.push(e[a])}return s}var Hp=3,Kp=.03,Zp=.02,to={maxAngleDeg:Hp,maxPlaneDisplacement:Kp,maxBoundaryDisplacement:Zp,isolatedPairs:!1},cr={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},Ps=[{...cr,maxAngleDeg:30},{...cr,maxAngleDeg:45},{...cr,maxAngleDeg:60,maxBoundaryDisplacement:.06}],qp=1800,Qp=.65,Ll=500,wl=2200,Jp=1e3,eg=2200,ng=350,tg=700,og=60,rg=.06,ig=4,sg=.003,ag=4e3,cg=3e3,lg=4500,ug=2400,fg=4200,mg=1800,dg=5e3,pg=.28,gg=.15,hg=.23,yg=2e3,bg=16,xg=4e3,Pg=900,Mg=16,Sg=1.5,Ss=.045,Ag=.999,Cg=1e-5,Tg=24,Eg=50,vg=1e3,Ig=1e3,Zn={minGroupPolygons:2,maxCandidateAxes:24},_g={...Zn,maxCandidateAxes:1},Nl={...Zn,maxCandidateAxes:2},Vg={...Zn,maxCandidateAxes:2},Og={steps:[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"},{kind:"finalLossyCandidates"}]};function zl(e,n={}){return Rg(e,n).polygons}function Ul(e,n={}){let t={meshResolution:n.meshResolution,stopAtPolygonCount:n.stopAtPolygonCount,rectCover:n.rectCover},o=new lr,r={captureVisiblePolygons:!0,skipInteriorCull:n.skipInteriorCull===!0};return o.workspaceFor(e,r).createRun(t,r).optimizeParse({staticSimplification:n.staticSimplification,useCandidateFirst:n.useCandidateFirst===!0}).polygons}function Rg(e,n={},t={}){return new lr().workspaceFor(e,t).createRun(n,t).optimize()}var lr=class{constructor(){this.workspaces=new Map}workspaceFor(n,t){let o=Lg(t),r=this.workspaces.get(o);r||(r=new WeakMap,this.workspaces.set(o,r));let i=r.get(n);return i||(i=new As(n,t,this),r.set(n,i)),i}};function Lg(e){return[e.skipInteriorCull===!0?"skip-cull":"cull",e.simplifiedCandidate===!0?"simplified":"source"].join(":")}var As=class{constructor(n,t,o){this.source=n,this.graph=o,this.preprocessCache={skipInteriorCull:t.skipInteriorCull===!0}}polygons(){return this.source}preprocess(n){return o0(this.source,n,this.preprocessCache)}configureSnappedCullReuse(n,t){let o=n.length/Math.max(1,this.source.length);this.preprocessCache.reuseSnappedInteriorCull=t.simplifiedCandidate===!0?this.source.length<=fg:n.length<=mg||n.length<=dg&&o>=pg}visiblePolygons(){return this.preprocessCache.interior??this.preprocessCache.deduped??this.source}createRun(n,t){return new Cs(this,n,t)}workspaceFor(n,t){return this.graph.workspaceFor(n,t)}},Cs=class e{constructor(n,t,o,r={}){this.baselineCandidatesComplete=!1;this.initialLossyCandidatesComplete=!1;this.finalLossyCandidatesComplete=!1;this.workspace=n,this.source=n.polygons(),this.options=t,this.runOptions=o,this.costCandidateMode=r.costCandidateMode??"cost",this.seamCandidateMode=r.seamCandidateMode??"seamSafe",this.offerBaseline=r.offerBaseline===!0,this.meshResolution=t.meshResolution??"lossy",this.stopAtPolygonCount=Number.isFinite(t.stopAtPolygonCount)?Math.max(0,Math.floor(t.stopAtPolygonCount)):void 0,this.requiredMaxPolygonCount=Number.isFinite(o.requiredMaxPolygonCount)?Math.max(0,Math.floor(o.requiredMaxPolygonCount)):void 0,this.baseline=this.preprocess(!1),this.workspace.configureSnappedCullReuse(this.baseline,o),this.visiblePolygons=o.captureVisiblePolygons?this.workspace.visiblePolygons():void 0,this.acceptor=r.acceptor??new Ts(this.baseline,this.requiredMaxPolygonCount)}optimize(){return this.runPlan(Og)}optimizeParse(n){let t=n.staticSimplification===!1?null:n.staticSimplification??{},o=[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"}];return n.useCandidateFirst||o.push({kind:"finalLossyCandidates"}),t&&o.push({kind:"staticSimplificationCandidates",options:t,stopOnAccept:n.useCandidateFirst}),n.useCandidateFirst&&o.push({kind:"finalLossyCandidates"}),this.runPlan({steps:o})}get best(){return this.acceptor.polygons}get bestCost(){return this.acceptor.cost}runStaticSimplificationCandidates(n={}){if(this.meshResolution!=="lossy"||!Hg(this.source,this.best))return!1;let t=$l(this.source,n);if(!t)return!1;for(let o of this.staticSimplificationPlans(t)){let r=Kg(o,n);if(r&&this.generateStaticSimplificationCandidate(r,n,o.skipInteriorCull))return!0}return!1}staticSimplificationPlans(n){let t=this.source.length-n.length,o=[],r=this.visiblePolygons&&this.visiblePolygons!==this.source?this.source.length-this.visiblePolygons.length:0;return this.visiblePolygons&&this.visiblePolygons!==this.source&&this.source.length>=xg&&r>=Pg&&(t<=Mg||r>=t*Sg)&&o.push({source:this.visiblePolygons,skipInteriorCull:!0}),this.best.length>=yg&&t<=bg&&Wg(this.source)&&o.push({source:this.source,vertexKeyMode:"source"}),o.push({source:this.source,precomputed:n}),o}generateStaticSimplificationCandidate(n,t,o=!1){let r={requiredMaxPolygonCount:this.best.length-1,skipExactRectCover:!0,skipInteriorCull:o,simplifiedCandidate:!0},i=this.workspace.workspaceFor(n,r),s=this.best;return new e(i,{meshResolution:"lossy",stopAtPolygonCount:jg(this.best.length,t)},r,{acceptor:this.acceptor,costCandidateMode:"dom",seamCandidateMode:"dom",offerBaseline:!0}).optimize(),this.best!==s}runPlan(n){for(let t of n.steps){let o=!1;if(t.kind==="baselineCandidates")this.runBaselineCandidates();else if(t.kind==="staticSimplificationCandidates")o=this.runStaticSimplificationCandidates(t.options)&&t.stopOnAccept;else{if(!this.shouldRunLossyPipeline())break;t.kind==="initialLossyCandidates"?this.runInitialLossyPipeline():this.runFinalLossyPipeline()}if(o||this.shouldStop())break}return this.result()}runBaselineCandidates(){if(this.baselineCandidatesComplete||(this.baselineCandidatesComplete=!0,this.offerBaseline&&(this.acceptCandidate(this.baseline),this.shouldStop())))return;let n=this.runOptions.skipExactRectCover===!0?!1:this.meshResolution==="lossy"&&this.options.rectCover===void 0?qg(this.baseline):this.options.rectCover;if(this.shouldStop())return;let t=Kn(this.baseline,n);if(t!==this.baseline&&this.acceptCandidate(t),!this.shouldStop()&&this.meshResolution==="lossy"&&this.options.rectCover===void 0&&this.runOptions.skipExactRectCover!==!0){let o=Kn(this.baseline,void 0);o!==this.baseline&&this.acceptCandidate(o)}}shouldRunLossyPipeline(){return this.meshResolution==="lossy"&&!this.shouldStop()&&this.best.length>1&&this.bestCost>1+1e-9}runInitialLossyPipeline(){if(this.initialLossyCandidatesComplete)return;this.initialLossyCandidatesComplete=!0;let n=this.preprocess(cr);this.acceptCandidate(n),!this.shouldStop()&&(this.options.rectCover===void 0&&this.source.length>=Ll&&this.source.length<=wl&&(this.acceptCandidate(Kn(n,Nl)),this.shouldStop())||this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(this.acceptCandidate(Kn(n,this.options.rectCover)),this.shouldStop()))}runFinalLossyPipeline(){this.finalLossyCandidatesComplete||(this.finalLossyCandidatesComplete=!0,!(this.runOptions.simplifiedCandidate===!0&&this.source.length>lg)&&(this.runAggressiveLossyVariants(),!this.shouldStop()&&this.runLargeRectCoverCandidate()))}runAggressiveLossyVariants(){let n=this.stopAtPolygonCount===void 0&&this.source.length>=ag&&this.best.length<=cg,t=!1;for(let o=n?Ps.length:0;o<Ps.length;o+=1){if(o===1&&!t||o===1&&this.runOptions.simplifiedCandidate===!0&&this.source.length<ug||o===2&&!Jg(this.source))continue;let r=this.preprocess(Ps[o]),i=r;this.options.rectCover===void 0&&this.source.length>=Ll&&this.source.length<=wl&&(i=Kn(r,Nl)),this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(i=Kn(r,this.options.rectCover));let s=this.acceptSeamSafeCandidate(i,this.source.length);if(o===0&&s&&(t=!0),this.shouldStop())return}}runLargeRectCoverCandidate(){if(this.options.rectCover!==void 0)return;let n=Kn(this.best,Qg(this.best));n!==this.best&&this.acceptSeamSafeCandidate(n,this.best.length)}preprocess(n){return this.workspace.preprocess(n)}result(){return{polygons:this.best,visiblePolygons:this.visiblePolygons}}shouldStop(){return this.stopAtPolygonCount!==void 0&&this.best.length<=this.stopAtPolygonCount}acceptCandidate(n,t=qn(n)){return this.emitCandidate({mode:this.costCandidateMode,polygons:n,cost:t})}acceptDomCandidate(n){return this.emitCandidate({mode:"dom",polygons:n})}acceptSeamSafeCandidate(n,t,o){return this.emitCandidate({mode:this.seamCandidateMode,polygons:n,sourcePolygonCount:t,cost:o})}emitCandidate(n){return this.acceptor.accept({...n,maxPolygonCount:n.maxPolygonCount??this.requiredMaxPolygonCount})}},Ts=class{constructor(n,t){this.best=n,this.bestCost=qn(n),this.bestDiagnostics={polygons:n},this.requiredMaxPolygonCount=t}get polygons(){return this.best}get cost(){return this.bestCost}accept(n){return n.mode==="cost"?this.acceptCostCandidate(n.polygons,n.cost):n.mode==="dom"?this.acceptDomCandidate(n.polygons,n.cost,n.maxPolygonCount):this.acceptSeamSafeCandidate(n.polygons,n.sourcePolygonCount??n.polygons.length,n.cost,n.maxPolygonCount)}acceptCostCandidate(n,t=qn(n)){return t>=this.bestCost?!1:(this.commit(n,t),!0)}acceptDomCandidate(n,t=qn(n),o){return n.length>=this.best.length||!this.withinMaxPolygonCount(n,o)?!1:(this.commit(n,t),!0)}acceptSeamSafeCandidate(n,t,o,r){if(n.length>=this.best.length||!this.withinMaxPolygonCount(n,r))return!1;let i=Yg(t);if(this.bestCost-n.length<i)return!1;let s=o??qn(n),a=this.bestCost-s;if(a<=0||a<i)return!1;let c=Dl(n);if(!c)return!1;let l=this.bestSeamDiagnostics();return!l||wg(c,l)||Ng(this.bestTopologyEdges(),this.bestTopologySelfDiagnostics(),n)?!1:(this.commit(n,s,c),!0)}withinMaxPolygonCount(n,t){let o=t??this.requiredMaxPolygonCount;return o===void 0||n.length<=o}commit(n,t,o){this.best=n,this.bestCost=t,this.bestDiagnostics={polygons:n,seam:o}}resetBestDiagnostics(n){this.bestDiagnostics={polygons:this.best,seam:n}}bestSeamDiagnostics(){if(this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),!this.bestDiagnostics.seam){let n=Dl(this.best);if(!n)return null;this.bestDiagnostics.seam=n}return this.bestDiagnostics.seam}bestTopologyEdges(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologyEdges||(this.bestDiagnostics.topologyEdges=Gl(this.best)),this.bestDiagnostics.topologyEdges}bestTopologySelfDiagnostics(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologySelf||(this.bestDiagnostics.topologySelf=kg(this.bestTopologyEdges(),Ss)),this.bestDiagnostics.topologySelf}};function qn(e){let n=0;for(let t of e){let o=t.vertices.length,r=o<=4?0:Math.min(4,o-4)*.12,i=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+r+i}return n}function Dl(e){try{return vl(e)}catch(n){if(n instanceof RangeError&&n.message==="Set maximum size exceeded")return null;throw n}}function wg(e,n){return e.nearPairs>n.nearPairs||e.unclosedPairs>n.unclosedPairs||e.maxMeasuredGapPx>n.maxMeasuredGapPx+1e-9||e.maxResidualGapPx>n.maxResidualGapPx+1e-9}function Ng(e,n,t){let o=Gl(t);return Dg(e,o,Ss)?!0:Bg(o.boundarySegments,Ss,n)}function Dg(e,n,t){if(e.internalSegments.length===0)return!1;let o=Fg(e,t);for(let r of n.boundarySegments)if(!e.boundaryKeys.has(r.key)&&(e.internalKeys.has(r.key)||$g(r,o,t)))return!0;return!1}function Fg(e,n){return(!e.internalIndex||e.internalIndexTolerance!==n)&&(e.internalIndex=Is(e.internalSegments,n),e.internalIndexTolerance=n),e.internalIndex}function Bg(e,n,t){let o=Is(e,n),r=new Set,i=0,s=0,a=0;for(let c of e)i=Math.max(i,c.index+1);for(let c of e)for(let l of _s(c,o,n)){if(l===c||l.polygon===c.polygon||l.key===c.key)continue;let u=c.index<l.index?c.index*i+l.index:l.index*i+c.index;if(r.has(u))continue;r.add(u);let f=Vs(c,l,n);if(f&&(s+=1,a+=f.overlapLength,s>t.tJunctionPairs||a>t.tJunctionLength+1e-9))return!0}return!1}function kg(e,n){let t={tJunctionPairs:0,tJunctionLength:0};return zg(t,e.boundarySegments,n),t}function zg(e,n,t){let o=Is(n,t),r=new Set,i=0;for(let s of n)i=Math.max(i,s.index+1);for(let s of n)for(let a of _s(s,o,t)){if(a===s||a.polygon===s.polygon||a.key===s.key)continue;let c=s.index<a.index?s.index*i+a.index:a.index*i+s.index;if(r.has(c))continue;r.add(c);let l=Vs(s,a,t);l&&(e.tJunctionPairs+=1,e.tJunctionLength+=l.overlapLength)}}function Gl(e){let n=new Map;for(let c=0;c<e.length;c+=1){let l=e[c].vertices;for(let u=0;u<l.length;u+=1){let f=l[u],d=l[(u+1)%l.length],m=Ug(io(f,d),c,u,f,d);if(!m)continue;let p=n.get(m.key);p?p.count+=1:n.set(m.key,{count:1,segment:m})}}let t=new Set,o=new Set,r=[],i=[],s=0,a=0;for(let c of n.values()){let l={...c.segment,index:a};a+=1,c.count===1?(t.add(l.key),r.push(l),s+=l.length):(o.add(l.key),i.push(l))}return{boundaryKeys:t,internalKeys:o,boundarySegments:r,internalSegments:i,boundaryLength:s}}function Ug(e,n,t,o,r){let i=_n(r,o),s=Math.hypot(i[0],i[1],i[2]);if(s<=1e-10)return null;let a=[i[0]/s,i[1]/s,i[2]/s];return{index:-1,key:e,polygon:n,edge:t,a:o,b:r,dir:a,length:s,minX:Math.min(o[0],r[0]),minY:Math.min(o[1],r[1]),minZ:Math.min(o[2],r[2]),maxX:Math.max(o[0],r[0]),maxY:Math.max(o[1],r[1]),maxZ:Math.max(o[2],r[2])}}function Is(e,n){let t=Math.max(n*8,.5),o=new Map;for(let r of e)Gg(o,r,t,n);return{cellSize:t,cells:o}}function Gg(e,n,t,o){let[r,i,s]=ur([n.minX-o,n.minY-o,n.minZ-o],t),[a,c,l]=ur([n.maxX+o,n.maxY+o,n.maxZ+o],t);for(let u=r;u<=a;u+=1)for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function ur(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function _s(e,n,t){let o=[],r=new Set,[i,s,a]=ur([e.minX-t,e.minY-t,e.minZ-t],n.cellSize),[c,l,u]=ur([e.maxX+t,e.maxY+t,e.maxZ+t],n.cellSize);for(let f=i;f<=c;f+=1)for(let d=s;d<=l;d+=1)for(let m=a;m<=u;m+=1){let p=n.cells.get(`${f},${d},${m}`);if(p)for(let g of p)r.has(g)||(r.add(g),o.push(g))}return o}function $g(e,n,t){for(let o of _s(e,n,t))if(Vs(e,o,t))return!0;return!1}function Vs(e,n,t){if(!Xg(e,n,t)||Math.abs(on(e.dir,n.dir))<Ag)return null;let o=on(_n(n.a,e.a),e.dir),r=on(_n(n.b,e.a),e.dir),i=Math.max(0,Math.min(o,r)),s=Math.min(e.length,Math.max(o,r)),a=s-i;if(a<=Math.max(Cg,Math.min(e.length,n.length)*1e-4))return null;let c=[e.a[0]+e.dir[0]*((i+s)/2),e.a[1]+e.dir[1]*((i+s)/2),e.a[2]+e.dir[2]*((i+s)/2)],l=Math.max(0,Math.min(n.length,on(_n(c,n.a),n.dir))),u=[n.a[0]+n.dir[0]*l,n.a[1]+n.dir[1]*l,n.a[2]+n.dir[2]*l],f=ou(c,u);return f<=t?{overlapLength:a,offset:f}:null}function Xg(e,n,t){return e.minX<=n.maxX+t&&n.minX<=e.maxX+t&&e.minY<=n.maxY+t&&n.minY<=e.maxY+t&&e.minZ<=n.maxZ+t&&n.minZ<=e.maxZ+t}function Yg(e){return Math.max(ig,e*sg)}function jg(e,n){let t=Number.isFinite(n.earlyStopDropRatio)?Math.max(0,n.earlyStopDropRatio):gg;return Math.max(0,e-Math.max(1,Math.ceil(e*t)))}function Wg(e){return e.some(n=>n.simplifySourceVertexKeys?.length===n.vertices.length)}function Hg(e,n){return e.length===0||n.length/e.length>hg}function $l(e,n,t){let o=ar(e,{...n.simplifyTriangleMeshOptions,...t?{vertexKeyMode:t}:{}});return o===e||o.length>=e.length?null:o}function Kg(e,n){return e.precomputed!==void 0?e.precomputed:$l(e.source,n,e.vertexKeyMode)}function Kn(e,n){if(n===!1)return e;let t=Zg(e,n);if(!t)return e;let o=Zo(e,t);return o.length<e.length?o:e}function Zg(e,n){if(n&&n!==!0)return n;let t=n===!0,o=e.length;return o>2200||!t&&o>=Tg&&o<Eg||!t&&o>vg?null:!t&&o<=300?{...Zn,maxCandidateAxes:1}:o>300?!t&&(Xl(e)>12||Yl(e)>Ig)?null:{...Zn,maxCandidateAxes:Math.min(Zn.maxCandidateAxes??24,2)}:Zn}function qg(e){return e.length>qp||e.length===0||e0(e)/e.length<Qp?!1:_g}function Qg(e){return e.length<Jp||e.length>eg||Xl(e)<=12||Yl(e)>ng?!1:Vg}function Jg(e){return e.length<=tg}function e0(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function Xl(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function Yl(e){let n=new Map;for(let o of e)for(let r=0;r<o.vertices.length;r++){let i=o.vertices[r],s=o.vertices[(r+1)%o.vertices.length],a=io(i,s);n.set(a,(n.get(a)??0)+1)}let t=0;for(let o of n.values())o===1&&(t+=1);return t}function fr(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function Es(e,n){if(n===e||n.length===e.length&&n.every((r,i)=>r===e[i]))return null;let t=new Set(n),o=[];for(let r=0;r<e.length;r++)t.has(e[r])&&o.push(r);return o.length===e.length?null:o}function n0(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let r=jt(e);if(r.size===0)t=null;else{t=[];for(let i=0;i<e.length;i++)r.has(i)||t.push(i)}n&&(n.dedupedIndices=t)}let o=fr(e,t);return n&&(n.deduped=o),o}function t0(e,n){if(n?.skipInteriorCull)return e;if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let r=hn(e);t=Es(e,r),n&&(n.interiorIndices=t)}let o=fr(e,t);return n&&(n.interior=o),o}function o0(e,n,t){let o=n0(e,t),r=t0(o,t),i=t?.baseline??sn(r);if(t&&!t.baseline&&(t.baseline=i),!n)return i;let s=n===!0?to:i0(n);if(s.isolatedPairs){let u=Bl(Fl(o,t),s,t),f=sn(u);if(t?.snappedInteriorUsesBaselineFilter&&r0(i,f)){let d=Bl(Fl(o,t,!0),s,t),m=sn(d);m.length<f.length&&(f=m)}return f.length<i.length?f:i}let a=b0(o,s,t),c=hn(a),l=sn(c);return l.length<i.length?l:i}function jl(e,n){return n?(n.snapped||(n.snapped=mr(e)),n.snapped):mr(e)}function Fl(e,n,t=!1){if(!n)return hn(mr(e));if(t&&n.snappedInteriorExact)return n.snappedInteriorExact;if(!t&&n.snappedInterior)return n.snappedInterior;let o=jl(e,n);if(t){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorExactIndices=n.interiorIndices,n.snappedInteriorExact=n.interior,n.snappedInteriorExact;let r=hn(o);return n.snappedInteriorExactIndices=Es(o,r),n.snappedInteriorExact=r,n.snappedInteriorExact}if(!n.snappedInterior){if(o===e&&n.deduped===e&&n.interior)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=n.interior,n.snappedInteriorUsesBaselineFilter=!1,n.snappedInterior;if(n.reuseSnappedInteriorCull!==!1&&n.interiorIndices!==void 0)return n.snappedInteriorIndices=n.interiorIndices,n.snappedInterior=fr(o,n.snappedInteriorIndices),n.snappedInteriorUsesBaselineFilter=!0,n.snappedInterior;if(n.snappedInteriorIndices===void 0){let r=hn(o);n.snappedInteriorIndices=Es(o,r),n.snappedInterior=r,n.snappedInteriorExactIndices=n.snappedInteriorIndices,n.snappedInteriorExact=r,n.snappedInteriorUsesBaselineFilter=!1}else n.snappedInterior=fr(o,n.snappedInteriorIndices)}return n.snappedInterior}function r0(e,n){return n.length>=e.length}function i0(e){return{maxAngleDeg:e.maxAngleDeg??to.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??to.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??to.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??to.isolatedPairs}}function Bl(e,n,t){let o=s0(e,t),r=[];for(let s of a0(e,o))c0(s,n)&&r.push(s.candidate);let i=u0(r);return i.length===0?e:l0(e,i)}function s0(e,n){if(n?.trianglePairSource?.polygons===e)return n.trianglePairSource;let t=e.map(s=>{let a=Rs(s);return a?{polygon:s,normal:a.normal,area:a.area,materialKey:Ql(s)}:null}),o=new Map;for(let s=0;s<e.length;s++){let a=e[s];if(!(a.vertices.length!==3||!t[s]))for(let c=0;c<a.vertices.length;c++){let l=io(a.vertices[c],a.vertices[(c+1)%a.vertices.length]),u=o.get(l);u?u.push(s):o.set(l,[s])}}let r=[];for(let s of o.values())s.length===2&&r.push([s[0],s[1]]);let i={polygons:e,metas:t,edgeOwnerPairs:r};return n&&(n.trianglePairSource=i),i}function a0(e,n){if(n.preparedCandidates)return n.preparedCandidates;let t=[];for(let[o,r]of n.edgeOwnerPairs){let i=g0(o,r,e,n.metas);i&&t.push(i)}return n.preparedCandidates=t,t}function c0(e,n){let t=Math.cos(n.maxAngleDeg*Math.PI/180);return e.normalDot>=t&&e.maxDistance<=Math.min(n.maxPlaneDisplacement,n.maxBoundaryDisplacement)}function l0(e,n){let t=new Map,o=new Set,r=Wl(n.flatMap(s=>s.vertexMoves));for(let s of n){let a=Math.min(s.a,s.b);t.set(a,s.polygon),o.add(Math.max(s.a,s.b))}let i=[];for(let s=0;s<e.length;s++){let a=t.get(s);if(a){i.push(a);continue}o.has(s)||i.push(e[s])}return r.size>0?Hl(i,r):i}function u0(e){return e.length>3e3?f0(e):m0(e)}function f0(e){let n=new Map;for(let i of e)n.set(i.a,(n.get(i.a)??0)+1),n.set(i.b,(n.get(i.b)??0)+1);let t=[...e].sort((i,s)=>{let a=(n.get(i.a)??0)+(n.get(i.b)??0),c=(n.get(s.a)??0)+(n.get(s.b)??0);return a-c||i.score-s.score}),o=new Set,r=[];for(let i of t)o.has(i.a)||o.has(i.b)||(o.add(i.a),o.add(i.b),r.push(i));return r}function m0(e){let n=new Map;for(let l=0;l<e.length;l++){let u=e[l],f=n.get(u.a);f?f.push(l):n.set(u.a,[l]);let d=n.get(u.b);d?d.push(l):n.set(u.b,[l])}let t=[],o=new Array(e.length).fill(!0),r=new Map,i=new vs;for(let[l,u]of n)r.set(l,u.length);let s=l=>(r.get(l.a)??0)+(r.get(l.b)??0),a=l=>{let u=e[l];i.push({degree:s(u),score:u.score,index:l})},c=(l,u)=>{if(!o[l])return;o[l]=!1;let f=e[l];for(let d of[f.a,f.b])r.set(d,(r.get(d)??0)-1),u.add(d)};for(let l=0;l<e.length;l++)a(l);for(;i.size()>0;){let l=i.pop();if(!o[l.index])continue;let u=e[l.index];if(s(u)!==l.degree){a(l.index);continue}t.push(u);let d=new Set;for(let m of[u.a,u.b])for(let p of n.get(m)??[])c(p,d);for(let m of d)for(let p of n.get(m)??[])o[p]&&a(p)}return t}var vs=class{constructor(){this.items=[]}size(){return this.items.length}push(n){this.items.push(n);let t=this.items.length-1;for(;t>0;){let o=t-1>>1;if(Ms(this.items[o],this.items[t])<=0)break;[this.items[o],this.items[t]]=[this.items[t],this.items[o]],t=o}}pop(){if(this.items.length===0)return null;let n=this.items[0],t=this.items.pop();if(this.items.length>0){this.items[0]=t;let o=0;for(;;){let r=o*2+1,i=r+1,s=o;if(r<this.items.length&&Ms(this.items[r],this.items[s])<0&&(s=r),i<this.items.length&&Ms(this.items[i],this.items[s])<0&&(s=i),s===o)break;[this.items[o],this.items[s]]=[this.items[s],this.items[o]],o=s}}return n}};function Ms(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function Wl(e){let n=new Map;for(let o of e){let r=n.get(o.key);r?(r.x+=o.target[0],r.y+=o.target[1],r.z+=o.target[2],r.count+=1):n.set(o.key,{x:o.target[0],y:o.target[1],z:o.target[2],count:1})}let t=new Map;for(let[o,r]of n)t.set(o,[r.x/r.count,r.y/r.count,r.z/r.count]);return t}function d0(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o].vertices,i=n[o]?.vertices;if(!i||i.length!==r.length)continue;for(let c=0;c<r.length;c++)t.push({key:ln(r[c]),target:i[c]});let s=e[o].textureTriangles??[],a=n[o]?.textureTriangles??[];for(let c=0;c<s.length;c++){let l=a[c];if(l)for(let u=0;u<s[c].vertices.length;u++)t.push({key:ln(s[c].vertices[u]),target:l.vertices[u]})}}return t}function p0(e,n){let t=[];for(let o of e)for(let r of o.textureTriangles??[])for(let i of r.vertices)t.push({key:ln(i),target:Ds(i,n)});return t}function Hl(e,n){return e.map(t=>{let o=!1,r=a=>{let c=n.get(ln(a));return c?(o=!0,c):a},i=t.vertices.map(r),s=Os(t.textureTriangles,r);return o?{...t,vertices:i,...s?{textureTriangles:s}:{}}:t})}function g0(e,n,t,o){let r=t[e],i=t[n],s=o[e],a=o[n];if(!s||!a||r.vertices.length!==3||i.vertices.length!==3||!V0(r,i,s,a))return null;let c=ws(r,i);if(!c)return null;let[l,u,f,d]=c;if((f+1)%i.vertices.length===d)return null;let p=Math.abs(on(s.normal,a.normal)),g=Math.cos(og*Math.PI/180);if(p<g)return null;let h=(u+1)%r.vertices.length,y=3-f-d,b=[r.vertices[u],r.vertices[h],r.vertices[l],i.vertices[y]],x=h0(b);if(!x)return null;let P=0,M=0;for(let S of b){let T=Math.abs(Ns(S,x));P=Math.max(P,T),M+=T*T}if(P>rg)return null;let C=b.map(S=>Ds(S,x));if(!y0(C,x.normal))return null;let E=Rs({vertices:C});if(!E||on(E.normal,s.normal)<.2||on(E.normal,a.normal)<.2)return null;let A={vertices:b,color:r.color,...r.doubleSided?{doubleSided:!0}:{},...r.data?{data:{...r.data}}:{}};if(Ls(r,i)&&r.uvs&&i.uvs&&r.texture){A.texture=r.texture,r.textureWrap&&(A.textureWrap={...r.textureWrap}),r.textureAlphaMode&&(A.textureAlphaMode=r.textureAlphaMode),A.uvs=[[...r.uvs[u]],[...r.uvs[h]],[...r.uvs[l]],[...i.uvs[y]]];let S=x0([r,i]);S?.length&&(A.textureTriangles=S)}return{normalDot:p,maxDistance:P,candidate:{a:e,b:n,polygon:A,vertexMoves:[...b.map((S,T)=>({key:ln(S),target:C[T]})),...p0([r,i],x)],score:M/b.length+P*.25+(1-p)*.1}}}function h0(e){if(e.length<3)return null;let n=0,t=0,o=0,r=0,i=0,s=0;for(let c=0;c<e.length;c++){let l=e[c],u=e[(c+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),t+=(l[2]-u[2])*(l[0]+u[0]),o+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],i+=l[1],s+=l[2]}let a=ru([n,t,o]);return a?{normal:a,point:[r/e.length,i/e.length,s/e.length]}:null}function y0(e,n){let t=0;for(let o=0;o<e.length;o++){let r=e[o],i=e[(o+1)%e.length],s=e[(o+2)%e.length],a=on(tu(_n(i,r),_n(s,i)),n);if(Math.abs(a)<=1e-9)continue;let c=a>0?1:-1;if(t===0)t=c;else if(t!==c)return!1}return!0}function b0(e,n,t){let o=jl(e,t),r=T0(o,n);if(r<=0)return o;let i=o.map(m=>{let p=Rs(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Ql(m)}:null}),s=I0(o,i),a=new Set,c=Array(o.length),l=[],u=(m,p)=>{c[m]=p};for(let m=0;m<o.length;m++){let p=i[m];if(a.has(m))continue;if(!p){u(m,o[m]);continue}let g=O0(m,i,s,a,r,n);for(let y of g)a.add(y);if(g.length<2){u(m,o[m]);continue}let h=S0(g,o,i,s,r,n);l.push(...h.vertexMoves);for(let y of g)u(y,h.polygons.get(y)??o[y])}let f=c.flatMap(m=>m?[m]:[]),d=l.length>0?Hl(f,Wl(l)):f;return mr(d)}function mr(e){let n=ql(e),t=1e-4;if(n<=0)return e;let o=E0(n),r=v0(t),i=!1,s=e.map(a=>{let c=!1,l=p=>{let g=o.snap(p);return oo(g,p)||(c=!0),g},u=a.vertices.map(l),f=a.uvs&&a.uvs.length===a.vertices.length?a.uvs.map(p=>{let g=r.snap(p);return ro(g,p)||(c=!0),g}):void 0,d=Os(a.textureTriangles,l);if(!c&&!a.texture)return a;let m={...a,vertices:u,...f?{uvs:f}:{},...d?{textureTriangles:d}:{}};return i=!0,{...m,...m.texture?{textureTriangles:Kl(m)}:{}}});return i?s:e}function Kl(e){if(e.texture){if(e.textureTriangles?.length)return M0(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return P0(e.vertices,e.uvs)}}function x0(e){let n=e.flatMap(t=>Kl(t)??[]);return n.length>0?n:void 0}function P0(e,n){let t=[];for(let o=1;o<e.length-1;o++)t.push({vertices:[[...e[0]],[...e[o]],[...e[o+1]]],uvs:[[...n[0]],[...n[o]],[...n[o+1]]]});return t}function M0(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Os(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(o=>[...o])}))}function S0(e,n,t,o,r,i){let s=Zl(e,n,t,r,i);return s?C0(s):A0(e,n,t,o,r,i)}function A0(e,n,t,o,r,i){let s=new Set(e),a=[];for(let f of e)for(let d of o.get(f)??[]){if(f>=d||!s.has(d))continue;let m=Zl([f,d],n,t,r,i);m&&a.push(m)}a.sort((f,d)=>d.score-f.score);let c=new Set,l=new Map,u=[];for(let f of a)if(!f.indices.some(d=>c.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];c.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function C0(e){let n=new Map;for(let t=0;t<e.indices.length;t++)n.set(e.indices[t],e.source[t]);return{polygons:n,vertexMoves:e.vertexMoves}}function Zl(e,n,t,o,r){let i=Jl(e,t);if(!i||!eu(e,t,i,o,r))return null;let s=e.map(u=>n[u]),a=s.map(u=>w0(u,i)),c=qn(sn(s)),l=qn(sn(a));return l>=c?null:{indices:e,source:s,projected:a,vertexMoves:d0(s,a),score:c-l}}function T0(e,n){return ql(e)<=0?0:n.maxPlaneDisplacement}function ql(e){let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let c of e)for(let[l,u,f]of c.vertices)n=Math.min(n,l),t=Math.min(t,u),o=Math.min(o,f),r=Math.max(r,l),i=Math.max(i,u),s=Math.max(s,f);if(!Number.isFinite(n))return 0;let a=Math.hypot(r-n,i-t,s-o);return a<=0?0:Math.min(.025,Math.max(1e-4,a*25e-5))}function E0(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i,s)=>`${r},${i},${s}`;return{snap(r){let i=t(r[0]),s=t(r[1]),a=t(r[2]);for(let f=-1;f<=1;f++)for(let d=-1;d<=1;d++)for(let m=-1;m<=1;m++){let p=n.get(o(i+f,s+d,a+m));if(p){for(let g of p)if(ou(r,g)<=e)return[g[0],g[1],g[2]]}}let c=[r[0],r[1],r[2]],l=o(i,s,a),u=n.get(l);return u?u.push(c):n.set(l,[c]),c}}}function v0(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,i)=>`${r},${i}`;return{snap(r){let i=t(r[0]),s=t(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(o(i+u,s+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 a=[r[0],r[1]],c=o(i,s),l=n.get(c);return l?l.push(a):n.set(c,[a]),a}}}function Ql(e){return[e.color??"#cccccc",e.texture??"",e.texture&&e.textureWrap?`${e.textureWrap.s}/${e.textureWrap.t}`:"",e.texture&&e.textureAlphaMode?e.textureAlphaMode:"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided"].join("|")}function Rs(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0,i=n[0];for(let a=1;a<n.length-1;a++){let c=_n(n[a],i),l=_n(n[a+1],i),u=tu(c,l);t+=u[0],o+=u[1],r+=u[2]}let s=Math.hypot(t,o,r);return s<=1e-10?null:{normal:[t/s,o/s,r/s],area:s/2}}function I0(e,n){let t=new Map,o=new Map;for(let r=0;r<e.length;r++){let i=e[r];if(!(!n[r]||i.vertices.length<3))for(let s=0;s<i.vertices.length;s++){let a=io(i.vertices[s],i.vertices[(s+1)%i.vertices.length]),c=t.get(a);c?c.push(r):t.set(a,[r])}}for(let r of t.values())for(let i=0;i<r.length;i++)for(let s=i+1;s<r.length;s++){let a=r[i],c=r[s];_0(e[a],e[c],n[a],n[c])&&(kl(o,a,c),kl(o,c,a))}return o}function _0(e,n,t,o){if(!t||!o||t.materialKey!==o.materialKey||!!e.uvs!=!!n.uvs)return!1;if(dr(e)||dr(n))return Ls(e,n);if(!e.uvs||!n.uvs)return!0;let r=ws(e,n);if(!r)return!1;let[i,s,a,c]=r;return ro(e.uvs[i],n.uvs[a])&&ro(e.uvs[s],n.uvs[c])}function V0(e,n,t,o){return t.materialKey!==o.materialKey?!1:dr(e)||dr(n)?Ls(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function dr(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function Ls(e,n){if(!e.texture||!n.texture||e.texture!==n.texture||(e.textureWrap?.s??"")!==(n.textureWrap?.s??"")||(e.textureWrap?.t??"")!==(n.textureWrap?.t??"")||(e.textureAlphaMode??"")!==(n.textureAlphaMode??"")||e.material?.texture||n.material?.texture||!e.uvs||!n.uvs||e.uvs.length!==e.vertices.length||n.uvs.length!==n.vertices.length)return!1;let t=ws(e,n);if(!t)return!1;let[o,r,i,s]=t;return ro(e.uvs[o],n.uvs[i])&&ro(e.uvs[r],n.uvs[s])}function kl(e,n,t){let o=e.get(n);o?o.add(t):e.set(n,new Set([t]))}function O0(e,n,t,o,r,i){let s=[e],a=new Set([e]),c=[e];for(;c.length>0;){let l=c.shift();for(let u of t.get(l)??[]){if(o.has(u)||a.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&R0([...s,u],n,r,i)&&(s.push(u),a.add(u),c.push(u))}}return s}function R0(e,n,t,o){let r=Jl(e,n);return!!r&&eu(e,n,r,t,o)}function Jl(e,n){let t=n[e[0]];if(!t)return null;let o=0,r=0,i=0,s=0,a=0,c=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let g=on(t.normal,p.normal)<0?-1:1,h=Math.max(p.area,1e-6);o+=p.normal[0]*g*h,r+=p.normal[1]*g*h,i+=p.normal[2]*g*h;for(let y of p.polygon.vertices)s+=y[0],a+=y[1],c+=y[2],l+=1}let u=ru([o,r,i]);if(!u||l===0)return null;let f=nu(e,n),d=L0(e,n,u,f);if(d){let m=(d.min+d.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m],boundaryVertexKeys:f}}return{normal:u,point:[s/l,a/l,c/l],boundaryVertexKeys:f}}function L0(e,n,t,o){let r=1/0,i=-1/0;for(let s of e){let a=n[s];if(a)for(let c of a.polygon.vertices){if(!o.has(ln(c)))continue;let l=on(c,t);r=Math.min(r,l),i=Math.max(i,l)}}return Number.isFinite(r)&&Number.isFinite(i)?{min:r,max:i}:null}function eu(e,n,t,o,r){let i=Math.cos(r.maxAngleDeg*Math.PI/180),s=t.boundaryVertexKeys??nu(e,n);for(let a of e){let c=n[a];if(!c||Math.abs(on(c.normal,t.normal))<i)return!1;for(let l of c.polygon.vertices){let u=s.has(ln(l))?r.maxBoundaryDisplacement:o;if(Math.abs(Ns(l,t))>u)return!1}}return!0}function nu(e,n){let t=new Map;for(let r of e){let i=n[r];if(!i)continue;let s=i.polygon.vertices;for(let a=0;a<s.length;a++){let c=s[a],l=s[(a+1)%s.length],u=io(c,l),f=t.get(u);f?f.count+=1:t.set(u,{count:1,a:c,b:l})}}let o=new Set;for(let r of t.values())r.count===1&&(o.add(ln(r.a)),o.add(ln(r.b)));return o}function w0(e,n){let t=r=>Ds(r,n),o=Os(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...o?{textureTriangles:o}:{}}}function ws(e,n){for(let t=0;t<e.vertices.length;t++){let o=(t+1)%e.vertices.length;for(let r=0;r<n.vertices.length;r++){let i=(r+1)%n.vertices.length;if(oo(e.vertices[t],n.vertices[r])&&oo(e.vertices[o],n.vertices[i]))return[t,o,r,i];if(oo(e.vertices[t],n.vertices[i])&&oo(e.vertices[o],n.vertices[r]))return[t,o,i,r]}}return null}function io(e,n){let t=ln(e),o=ln(n);return t<o?`${t}|${o}`:`${o}|${t}`}function ln(e){return`${e[0]},${e[1]},${e[2]}`}function oo(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function ro(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function _n(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function tu(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 on(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function ou(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function ru(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 Ns(e,n){return on(_n(e,n.point),n.normal)}function Ds(e,n){let t=Ns(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var N0=36,D0=.15,F0=.2,B0=650,k0=15e3,z0=.25;function Fs(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function iu(e){let n=Tn(e);return!n||n.alpha<1?e.trim().toLowerCase():`#${n.rgb.map(t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")).join("")}`}function U0(e){let n=Tn(e);return n?{rgb:[Math.max(0,Math.min(255,Math.round(n.rgb[0]))),Math.max(0,Math.min(255,Math.round(n.rgb[1]))),Math.max(0,Math.min(255,Math.round(n.rgb[2])))],alpha:n.alpha}:null}function G0(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function su(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),i=Math.min(n,t,o),s=r-i,a=0;return s!==0&&(r===n?a=60*((t-o)/s%6):r===t?a=60*((o-n)/s+2):a=60*((n-t)/s+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:s/r,value:r}}function $0(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function X0(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=su(e),o=su(n),r=t.saturation<.08,i=o.saturation<.08;if(r||i)return r===i;let s=Math.min(t.value,o.value)<.18?32:18;return $0(t.hue,o.hue)<=s}function Y0(e,n){let t=new Map;for(let s of e.keys()){let a=U0(s);a&&t.set(s,a)}let o=[],r=new Map,i=Array.from(e.entries()).sort((s,a)=>a[1]-s[1]||s[0].localeCompare(a[0]));for(let[s]of i){let a=t.get(s);if(!a){r.set(s,s);continue}let c=null;for(let l of o){if(!X0(a,l.parsed))continue;let u=G0(a,l.parsed);u>n||(!c||u<c.distance)&&(c={color:l.color,distance:u})}c?r.set(s,c.color):(o.push({color:s,parsed:a}),r.set(s,s))}return r}function j0(e,n,t){if(t!=="lossy"||e.animation)return e;let o=n.source;if(!o||o.polygons===e.polygons)return e;let r=n.bakedTextureColorMergeDistance??N0;if(!Number.isFinite(r)||r<=0)return e;let i=new Map,s=[];for(let u=0;u<e.polygons.length;u+=1){let f=o.polygons[u],d=e.polygons[u];if(!f||!d||f===d||!d.color||!Fs(f)||Fs(d))continue;let m=iu(d.color);s.push(u),i.set(m,(i.get(m)??0)+1)}if(i.size<2)return e;let a=Y0(i,r),c=!1,l=e.polygons.slice();for(let u of s){let f=l[u],d=iu(f.color),m=a.get(d)??d;m!==d&&(l[u]={...f,color:m},c=!0)}return c?{...e,polygons:l}:e}function W0(e){let n=0;for(let t of e)Fs(t)&&(n+=1);return e.length===0||n/e.length<=z0}function H0(e){return!!e.metadata?.stlTopology}function K0(e,n){return n?Math.max(e.simplifyEarlyStopDropRatio??D0,F0):e.simplifyEarlyStopDropRatio}function Qn(e,n={}){return new Bs(e,n).optimize()}var Bs=class{constructor(n,t){this.result=n,this.options=t,this.meshResolution=t.meshResolution??"lossy"}optimize(){if(this.result.voxelSource||this.result.animation)return this.result;let n=j0(this.result,this.options,this.meshResolution),t=H0(n),o=t?"lossless":this.meshResolution,r=this.canSimplify(n.polygons,o),i=r&&n.polygons.length>=B0&&n.polygons.length<=k0,s=Ul(n.polygons,{meshResolution:o,useCandidateFirst:i,staticSimplification:r?{simplifyTriangleMeshOptions:this.options.simplifyTriangleMeshOptions,earlyStopDropRatio:K0(this.options,i)}:!1,skipInteriorCull:t});return s===n.polygons?n:{...n,polygons:s}}canSimplify(n,t){return t==="lossy"&&this.options.simplifyTriangleMeshes!==!1&&W0(n)}};function Z0(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[O,L,D]of n)t+=O,o+=L,r+=D;let i=1/n.length;t*=i,o*=i,r*=i;let s=n[0],a=n[1],c=n[2],l=a[0]-s[0],u=a[1]-s[1],f=a[2]-s[2],d=c[0]-s[0],m=c[1]-s[1],p=c[2]-s[2],g=u*p-f*m,h=f*d-l*p,y=l*m-u*d,b=Math.hypot(g,h,y);if(b<1e-9)return null;g/=b,h/=b,y/=b;let x=n.length-2,P=new Float64Array(x*9),M=0;for(let O=1;O<n.length-1;O++){let L=n[0],D=n[O],_=n[O+1];P[M++]=L[0],P[M++]=L[1],P[M++]=L[2],P[M++]=D[0],P[M++]=D[1],P[M++]=D[2],P[M++]=_[0],P[M++]=_[1],P[M++]=_[2]}let C=0,E=1/0,A=1/0,S=1/0,T=-1/0,v=-1/0,R=-1/0;for(let[O,L,D]of n){let _=O-t,w=L-o,V=D-r,j=_*_+w*w+V*V;j>C&&(C=j),O<E&&(E=O),O>T&&(T=O),L<A&&(A=L),L>v&&(v=L),D<S&&(S=D),D>R&&(R=D)}return{centroid:[t,o,r],normal:[g,h,y],triFlat:P,bcx:t,bcy:o,bcz:r,br2:C,minX:E,minY:A,minZ:S,maxX:T,maxY:v,maxZ:R}}function q0(e,n,t,o,r,i,s,a){let c=s[a],l=s[a+1],u=s[a+2],f=s[a+3]-c,d=s[a+4]-l,m=s[a+5]-u,p=s[a+6]-c,g=s[a+7]-l,h=s[a+8]-u,y=r*h-i*g,b=i*p-o*h,x=o*g-r*p,P=f*y+d*b+m*x;if(P>-1e-9&&P<1e-9)return!1;let M=1/P,C=e-c,E=n-l,A=t-u,S=M*(C*y+E*b+A*x);if(S<0||S>1)return!1;let T=E*m-A*d,v=A*f-C*m,R=C*d-E*f,O=M*(o*T+r*v+i*R);return O<0||S+O>1?!1:M*(p*T+g*v+h*R)>.001}function Q0(e,n,t,o,r,i,s){let a=s.bcx-e,c=s.bcy-n,l=s.bcz-t,u=a*o+c*r+l*i,f=a-u*o,d=c-u*r,m=l-u*i;if(f*f+d*d+m*m>s.br2)return!1;let p=s.triFlat,g=p.length;for(let h=0;h<g;h+=9)if(q0(e,n,t,o,r,i,p,h))return!0;return!1}var so=9,J0=6,Ze=12;function ks(e,n,t,o,r,i){let s=o-e,a=r-n,c=i-t;return s*a+a*c+c*s}function eh(e){let n=[];for(let C=0;C<e.length;C++)e[C]&&n.push(C);let t=n.length,o=new Int32Array(t);for(let C=0;C<t;C++)o[C]=n[C];let r=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,i[C]=(E.minY+E.maxY)*.5,s[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*so),l=0,u=new Float64Array(Ze),f=new Float64Array(Ze),d=new Float64Array(Ze),m=new Float64Array(Ze),p=new Float64Array(Ze),g=new Float64Array(Ze),h=new Int32Array(Ze),y=new Float64Array(Ze-1),b=new Int32Array(Ze-1),x=new Float64Array(Ze-1),P=new Int32Array(Ze-1);function M(C,E){let A=l++,S=A*so,T=E-C,v=1/0,R=1/0,O=1/0,L=-1/0,D=-1/0,_=-1/0;for(let Y=C;Y<E;Y++){let ne=e[o[Y]];ne.minX<v&&(v=ne.minX),ne.maxX>L&&(L=ne.maxX),ne.minY<R&&(R=ne.minY),ne.maxY>D&&(D=ne.maxY),ne.minZ<O&&(O=ne.minZ),ne.maxZ>_&&(_=ne.maxZ)}if(c[S]=v,c[S+1]=R,c[S+2]=O,c[S+3]=L,c[S+4]=D,c[S+5]=_,T<=J0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let w=1/0,V=1/0,j=1/0,G=-1/0,Z=-1/0,ee=-1/0;for(let Y=C;Y<E;Y++)r[Y]<w&&(w=r[Y]),r[Y]>G&&(G=r[Y]),i[Y]<V&&(V=i[Y]),i[Y]>Z&&(Z=i[Y]),s[Y]<j&&(j=s[Y]),s[Y]>ee&&(ee=s[Y]);let W=G-w,ie=Z-V,z=ee-j;if(W===0&&ie===0&&z===0)return c[S+6]=1,c[S+7]=C,c[S+8]=E,A;let X=ks(v,R,O,L,D,_),U=X>0?1/X:0,I=T+1,B=0,N=0;for(let Y=0;Y<3;Y++){let ne=Y===0?w:Y===1?V:j,le=Y===0?W:Y===1?ie:z;if(le===0)continue;let ye=Y===0?r:Y===1?i:s,Ce=Ze/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),h.fill(0);for(let K=C;K<E;K++){let oe=(ye[K]-ne)*Ce|0;oe>=Ze&&(oe=Ze-1);let pe=e[o[K]];pe.minX<u[oe]&&(u[oe]=pe.minX),pe.maxX>m[oe]&&(m[oe]=pe.maxX),pe.minY<f[oe]&&(f[oe]=pe.minY),pe.maxY>p[oe]&&(p[oe]=pe.maxY),pe.minZ<d[oe]&&(d[oe]=pe.minZ),pe.maxZ>g[oe]&&(g[oe]=pe.maxZ),h[oe]++}let Ve=1/0,Ee=1/0,Me=1/0,Re=-1/0,F=-1/0,q=-1/0,J=0;for(let K=0;K<Ze-1;K++)u[K]<Ve&&(Ve=u[K]),m[K]>Re&&(Re=m[K]),f[K]<Ee&&(Ee=f[K]),p[K]>F&&(F=p[K]),d[K]<Me&&(Me=d[K]),g[K]>q&&(q=g[K]),J+=h[K],y[K]=ks(Ve,Ee,Me,Re,F,q),b[K]=J;let te=1/0,ue=1/0,ce=1/0,he=-1/0,Se=-1/0,ve=-1/0,xe=0;for(let K=Ze-2;K>=0;K--){let oe=K+1;u[oe]<te&&(te=u[oe]),m[oe]>he&&(he=m[oe]),f[oe]<ue&&(ue=f[oe]),p[oe]>Se&&(Se=p[oe]),d[oe]<ce&&(ce=d[oe]),g[oe]>ve&&(ve=g[oe]),xe+=h[oe],x[K]=ks(te,ue,ce,he,Se,ve),P[K]=xe}for(let K=0;K<Ze-1;K++){if(b[K]===0||P[K]===0)continue;let oe=.125+(y[K]*b[K]+x[K]*P[K])*U;oe<I&&(I=oe,B=Y,N=ne+(K+1)/Ce)}}let H=B===0?r:B===1?i:s,$=C,k=E-1;for(;$<=k;)if(H[$]<N)$++;else{let Y=o[$];o[$]=o[k],o[k]=Y;let ne=r[$];r[$]=r[k],r[k]=ne;let le=i[$];i[$]=i[k],i[k]=le;let ye=s[$];s[$]=s[k],s[k]=ye,k--}let Q=$;(Q===C||Q===E)&&(Q=C+E>>1),c[S+6]=0;let ae=M(C,Q),se=M(Q,E);return c[A*so+7]=ae,c[A*so+8]=se,A}return t>0&&M(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function nh(e,n,t,o,r,i,s,a,c){if(a.nodeCount===0)return!1;let{data:l,polyIndices:u,meta:f}=a,d=o!==0?1/o:o>=0?1/0:-1/0,m=r!==0?1/r:r>=0?1/0:-1/0,p=i!==0?1/i:i>=0?1/0:-1/0,g=0;for(c[g++]=0;g>0;){let y=c[--g]*so,b=(l[y]-e)*d,x=(l[y+3]-e)*d,P=b<x?b:x,M=b<x?x:b,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,A=C<E?C:E,S=C<E?E:C;if(P>S||A>M)continue;A>P&&(P=A),S<M&&(M=S);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,R=T<v?T:v,O=T<v?v:T;if(!(P>O||R>M)&&(O<M&&(M=O),!(M<.001)))if(l[y+6]===1){let L=l[y+7]|0,D=l[y+8]|0;for(let _=L;_<D;_++){let w=u[_];if(w===s)continue;let V=f[w];if(V&&Q0(e,n,t,o,r,i,V))return!0}}else c[g++]=l[y+7]|0,c[g++]=l[y+8]|0}return!1}function au(e,n,t){let o=new Set;if(e.length<2)return o;let r=Math.hypot(n[0],n[1],n[2]);if(r<1e-9)return o;let i=n[0]/r,s=n[1]/r,a=n[2]/r,c=e.map(Z0);if(t&&t.size>0)for(let f of t)c[f]=null;let l=eh(c),u=new Int32Array(Math.max(64,l.nodeCount));for(let f=0;f<e.length;f++){let d=c[f];if(!d)continue;let m=d.centroid[0]+d.normal[0]*.001,p=d.centroid[1]+d.normal[1]*.001,g=d.centroid[2]+d.normal[2]*.001;d.normal[0]*i+d.normal[1]*s+d.normal[2]*a<=0||nh(m,p,g,i,s,a,f,l,u)&&o.add(f)}return o}var ao=1e-5,zs=.001,Us=6;function pr(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let a=1;a+1<n.length;a++){let c=n[a],l=n[a+1],u=c[1]-t[1],f=c[0]-t[0],d=c[2]-t[2],m=l[1]-t[1],p=l[0]-t[0],g=l[2]-t[2];o-=f*g-d*p,r-=d*m-u*g,i-=u*p-f*m}let s=Math.hypot(o,r,i);return s<1e-9?null:[o/s,r/s,i/s]}function Gs(e,n){let t=n.meshRotation,o=t?Dn(e,t):e;return Yo(o,n.rotX,0,n.rotY)[2]}function At(e,n,t=ao){return Gs(e,n)>t}function cu(e,n,t=ao){let o=pr(e);return o===null||At(o,n,t)}function $s(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function Xs(e){let n=new Map;for(let t of e){if(!t)continue;let o=$s(t);n.has(o)||n.set(o,t)}return Array.from(n,([t,o])=>({key:t,normal:o}))}function lu(e){return Xs(e.map(pr))}function Ys(e,n=zs){let t=Math.abs(e[0]),o=Math.abs(e[1]),r=Math.abs(e[2]),i=Math.max(t,o,r);return i>1-n&&t+o+r-i<n}function uu(e){return e.length<=Us&&e.every(({normal:n})=>Ys(n))}function fu(e,n,t=ao){let o=[];for(let{key:r,normal:i}of e)At(i,n,t)&&o.push(r);return o.sort(),o.join("|")}function js(e,n,t,o,r){let i=(p,g,h)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=g,y[(e+2)%3]=h,y},s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function Ws(e={}){let n=e.size??5,t=e.thickness??.025,o=e.negative??!1,r=e.xColor??"#ff3a3a",i=e.yColor??"#3aff3a",s=e.zColor??"#3a8aff",a=n*t/2,c=o?-n:0;return[...js(0,c,n,a,r),...js(1,c,n,a,i),...js(2,c,n,a,s)]}var th=["right","left","front","back","top","bottom"];function Hs(e){return[e[0],e[1],e[2]]}function mu(e,n){return{min:[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.min(e[2],n[2])],max:[Math.max(e[0],n[0]),Math.max(e[1],n[1]),Math.max(e[2],n[2])]}}function oh(e){if(e.min&&e.max)return mu(e.min,e.max);let n=e.center?Hs(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=Hs(e.size):t=[1,1,1];let o=[t[0]/2,t[1]/2,t[2]/2];return mu([n[0]-o[0],n[1]-o[1],n[2]-o[2]],[n[0]+o[0],n[1]+o[1],n[2]+o[2]])}function rh(e,n){let[t,o,r]=e,[i,s,a]=n;return[{name:"right",vertices:[[i,o,r],[i,s,r],[i,s,a],[i,o,a]]},{name:"left",vertices:[[t,s,r],[t,o,r],[t,o,a],[t,s,a]]},{name:"front",vertices:[[i,s,r],[t,s,r],[t,s,a],[i,s,a]]},{name:"back",vertices:[[t,o,r],[i,o,r],[i,o,a],[t,o,a]]},{name:"top",vertices:[[t,o,a],[i,o,a],[i,s,a],[t,s,a]]},{name:"bottom",vertices:[[t,s,r],[i,s,r],[i,o,r],[t,o,r]]}]}function ih(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function sh(e,n){let t={vertices:e.vertices.map(Hs)};return n.color!==void 0&&(t.color=n.color),n.texture!==void 0&&(t.texture=n.texture),n.material!==void 0&&(t.material=n.material),n.uvs!==void 0&&(t.uvs=n.uvs.map(o=>[o[0],o[1]])),n.data!==void 0&&(t.data={...n.data}),t}function Ks(e={}){let{min:n,max:t}=oh(e);if(n[0]===t[0]||n[1]===t[1]||n[2]===t[2])return[];let o={color:e.color??"#ffffff",texture:e.texture,material:e.material,uvs:e.uvs,data:e.data},r=rh(n,t),i=new Map(r.map(a=>[a.name,a])),s=[];for(let a of th){let c=e.faces?.[a];if(c===!1)continue;let l=i.get(a);l&&s.push(sh(l,ih(o,c)))}return s}function du(e,n,t,o){let r=[0,0,0];return r[e]=n,r[(e+1)%3]=t,r[(e+2)%3]=o,r}function ah(e,n,t,o,r){let i=(p,g,h)=>du(e,p,g,h),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,-o,-o),f=i(t,o,-o),d=i(t,o,o),m=i(t,-o,o);return[{vertices:[s,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[s,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,s,u,m],color:r}]}function ch(e,n,t,o,r){let i=(f,d,m)=>du(e,f,d,m),s=i(n,-o,-o),a=i(n,o,-o),c=i(n,o,o),l=i(n,-o,o),u=i(t,0,0);return[{vertices:[s,a,c,l],color:r},{vertices:[s,a,u],color:r},{vertices:[a,c,u],color:r},{vertices:[c,l,u],color:r},{vertices:[l,s,u],color:r}]}function lh(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function Zs(e){let n=e.axis,t=e.sign??1,o=e.shaftLength??4,r=e.shaftHalfThickness??.05,i=e.headLength??.8,s=e.headHalfThickness??.2,a=e.color??"#ffffff",c=e.shaft??!0,l=o*t,u=Math.min(0,l),f=Math.max(0,l),d=l,m=(o+i)*t,p=ch(n,d,m,s,a),g=t===-1?lh(p):p;return c?[...ah(n,u,f,r,a),...g]:g}function gr(e,n,t){let o=[0,0,0],r=(e+1)%3,i=(e+2)%3;return o[r]=Math.cos(t)*n,o[i]=Math.sin(t)*n,o}function qs(e){let n=e.axis,t=e.radius,o=e.halfThickness??Math.max(.05,t*.04),r=e.segments??32,i=e.color??"#ffffff",s=t-o,a=t+o,c=[];for(let l=0;l<r;l++){let u=l/r*Math.PI*2,f=(l+1)/r*Math.PI*2,d=gr(n,s,u),m=gr(n,s,f),p=gr(n,a,u),g=gr(n,a,f);c.push({vertices:[d,p,g,m],color:i})}return c}function Qs(e){let n=e.axis,t=e.outerRadius,o=e.color??"#ffffff",r=(n+1)%3,i=(n+2)%3,s=(a,c)=>{let l=[0,0,0];return l[n]=0,l[r]=a,l[i]=c,l};return[{vertices:[s(-t,-t),s(t,-t),s(t,t),s(-t,t)],color:o}]}function Js(e){let n=e.axis,t=e.size??.4,o=e.offset??t*2,r=typeof o=="number"?o:o[0],i=typeof o=="number"?o:o[1],s=e.along??0,a=e.color??"#ffffff",c=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=s,m[c]=r+f,m[l]=i+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:a}]}function ea(e){let{center:n,size:t,color:o="#ffffff"}=e,[r,i,s]=n,a=[[r+t,i,s],[r-t,i,s],[r,i+t,s],[r,i-t,s],[r,i,s+t],[r,i,s-t]];return[[0,2,4],[2,1,4],[1,3,4],[3,0,4],[2,0,5],[1,2,5],[3,1,5],[0,3,5]].map(l=>({vertices:[a[l[0]],a[l[1]],a[l[2]]],color:o}))}function na(e={}){let{radius:n=50,color:t="#cccccc"}=e,o=Math.min(Math.max(0,Math.floor(e.subdivisions??1)),3),r=(1+Math.sqrt(5))/2,i=[[-1,r,0],[1,r,0],[-1,-r,0],[1,-r,0],[0,-1,r],[0,1,r],[0,-1,-r],[0,1,-r],[r,0,-1],[r,0,1],[-r,0,-1],[-r,0,1]].map(([c,l,u])=>{let f=Math.sqrt(c*c+l*l+u*u);return[c/f,l/f,u/f]}),s=[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]];for(let c=0;c<o;c++){let l=[...i],u=[],f=new Map,d=(m,p)=>{let g=m<p?`${m}-${p}`:`${p}-${m}`,h=f.get(g);if(h!==void 0)return h;let y=i[m],b=i[p],x=(y[0]+b[0])/2,P=(y[1]+b[1])/2,M=(y[2]+b[2])/2,C=Math.sqrt(x*x+P*P+M*M);x/=C,P/=C,M/=C;let E=l.length;return l.push([x,P,M]),f.set(g,E),E};for(let[m,p,g]of s){let h=d(m,p),y=d(p,g),b=d(g,m);u.push([m,h,b]),u.push([p,y,h]),u.push([g,b,y]),u.push([h,y,b])}i=l,s=u}let a=i.map(([c,l,u])=>[c*n,l*n,u*n]);return s.map(([c,l,u])=>({vertices:[a[c],a[l],a[u]],color:t}))}function ta(e={}){let{size:n=100,color:t="#cccccc"}=e,o=n/Math.sqrt(3),r=[[o,o,o],[o,-o,-o],[-o,o,-o],[-o,-o,o]];return[[0,1,2],[0,3,1],[0,2,3],[1,3,2]].map(([s,a,c])=>({vertices:[r[s],r[a],r[c]],color:t}))}function oa(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=n/Math.sqrt(1+o*o),i=[[-1,o,0],[1,o,0],[-1,-o,0],[1,-o,0],[0,-1,o],[0,1,o],[0,-1,-o],[0,1,-o],[o,0,-1],[o,0,1],[-o,0,-1],[-o,0,1]].map(([a,c,l])=>[a*r,c*r,l*r]);return[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]].map(([a,c,l])=>({vertices:[i[a],i[c],i[l]],color:t}))}function ra(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=1/o,i=n/Math.sqrt(3),a=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1],[0,r,o],[0,-r,o],[0,r,-o],[0,-r,-o],[r,o,0],[-r,o,0],[r,-o,0],[-r,-o,0],[o,0,r],[o,0,-r],[-o,0,r],[-o,0,-r]].map(([l,u,f])=>[l*i,u*i,f*i]);return[[12,13,4,8,0],[0,8,9,2,16],[16,17,1,12,0],[1,10,5,13,12],[17,3,11,10,1],[2,9,6,15,14],[2,14,3,17,16],[14,15,7,11,3],[18,6,9,8,4],[4,13,5,19,18],[5,10,11,7,19],[18,19,7,15,6]].map(l=>({vertices:l.map(u=>a[u]),color:t}))}function co(e={}){let{radius:n=50,height:t=100,radialSegments:o=12,color:r="#cccccc"}=e,i=e.radiusTop??n,s=t/2,a=-s,c=s,l=Math.max(3,o),u=[],f=Array.from({length:l+1},(p,g)=>g/l*Math.PI*2),d=n<=1e-6,m=i<=1e-6;for(let p=0;p<l&&!(d&&m);p++){let g=f[p],h=f[p+1],y=Math.cos(g)*n,b=Math.sin(g)*n,x=Math.cos(h)*n,P=Math.sin(h)*n,M=Math.cos(g)*i,C=Math.sin(g)*i,E=Math.cos(h)*i,A=Math.sin(h)*i,S=[y,b,a],T=[x,P,a],v=[E,A,c],R=[M,C,c];if(m){let O=[0,0,c];u.push({vertices:[S,T,O],color:r})}else if(d){let O=[0,0,a];u.push({vertices:[O,v,R],color:r})}else u.push({vertices:[S,T,v,R],color:r})}if(n>1e-6){let p=[0,0,a];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*n,Math.sin(h)*n,a],x=[Math.cos(y)*n,Math.sin(y)*n,a];u.push({vertices:[[...p],[...x],[...b]],color:r})}}if(i>1e-6){let p=[0,0,c];for(let g=0;g<l;g++){let h=f[g],y=f[g+1],b=[Math.cos(h)*i,Math.sin(h)*i,c],x=[Math.cos(y)*i,Math.sin(y)*i,c];u.push({vertices:[[...p],[...b],[...x]],color:r})}}return u}function ia(e={}){return co({...e,radiusTop:0})}function hr(e,n,t,o){let r=Math.sin(e),i=Math.cos(e),s=Math.sin(n),a=Math.cos(n);return[(t+o*a)*i,(t+o*a)*r,o*s]}function sa(e={}){let{radius:n=50,tube:t=15,radialSegments:o=12,tubularSegments:r=16,color:i="#cccccc"}=e,s=Math.max(3,o),a=Math.max(3,r),c=[];for(let l=0;l<s;l++){let u=l/s*Math.PI*2,f=(l+1)/s*Math.PI*2;for(let d=0;d<a;d++){let m=d/a*Math.PI*2,p=(d+1)/a*Math.PI*2,g=hr(u,m,n,t),h=hr(f,m,n,t),y=hr(f,p,n,t),b=hr(u,p,n,t);c.push({vertices:[g,h,y,b],color:i})}}return c}var pu=.01,gu=.01;function hu(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,o=e[0]/t,r=e[1]/t,i=e[2]/t,s=Math.sign(i||1)*Math.max(Math.abs(i),.01),a=n,c=.01;return[1,0,0,0,0,1,0,0,-o/s,-r/s,c,0,a*o/s,a*r/s,a*(1-c),1]}function yu(e,n,t){let o=e[2]-n[2];if(Math.abs(o)<1e-9)return null;let r=(t-e[2])/o;return r<0?null:[e[0]+r*(e[0]-n[0]),e[1]+r*(e[1]-n[1])]}function bu(e,n,t){let o=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],s=Math.hypot(o,r,i)||1;return(n[0]*o+n[1]*r+n[2]*i)/s>0}function xu(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e[0]*o+e[1]*r+e[2]*i>0}function yr(e){if(e.length<=1)return e.map(s=>[s[0],s[1]]);let t=e.map(s=>[s[0],s[1]]);t.sort((s,a)=>s[0]-a[0]||s[1]-a[1]);let o=(s,a,c)=>(a[0]-s[0])*(c[1]-s[1])-(a[1]-s[1])*(c[0]-s[0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function aa(e){let n=0,t=e.length;for(let o=0;o<t;o++){let r=e[o],i=e[(o+1)%t];n+=r[0]*i[1]-i[0]*r[1]}return n/2}function yn(e){let n=e.map(t=>[t[0],t[1]]);return aa(n)<0&&n.reverse(),n}function Pu(e,n,t){let o=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/o,i=n[1]/o,s=n[2]/o,a=Math.sign(s||1)*Math.max(Math.abs(s),.01),c=e[2]-t;return[e[0]-r/a*c,e[1]-i/a*c]}function Mu(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}function uh(e){if(e.length<3)return e.map((s,a)=>a);let t=e.map((s,a)=>a).sort((s,a)=>e[s][0]-e[a][0]||e[s][1]-e[a][1]),o=(s,a,c)=>(e[a][0]-e[s][0])*(e[c][1]-e[s][1])-(e[a][1]-e[s][1])*(e[c][0]-e[s][0]),r=[];for(let s of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],s)<=0;)r.pop();r.push(s)}let i=[];for(let s=t.length-1;s>=0;s--){let a=t[s];for(;i.length>=2&&o(i[i.length-2],i[i.length-1],a)<=0;)i.pop();i.push(a)}return r.pop(),i.pop(),r.concat(i)}function br(e,n,t){if(e.length<3)return null;let o=Mu(n),r=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],i=r[0]*o[0]+r[1]*o[1]+r[2]*o[2],s=Mu([r[0]-i*o[0],r[1]-i*o[1],r[2]-i*o[2]]),a=[o[1]*s[2]-o[2]*s[1],o[2]*s[0]-o[0]*s[2],o[0]*s[1]-o[1]*s[0]],c=e.map(f=>[f[0]*s[0]+f[1]*s[1]+f[2]*s[2],f[0]*a[0]+f[1]*a[1]+f[2]*a[2]]),l=uh(c);if(l.length<3)return null;let u=Math.max(3,Math.floor(t));if(l.length>u){let f=(d,m,p)=>{let g=c[d][0],h=c[d][1];return Math.abs((c[m][0]-g)*(c[p][1]-h)-(c[p][0]-g)*(c[m][1]-h))*.5};for(;l.length>u;){let d=1/0,m=0;for(let p=0;p<l.length;p++){let g=f(l[(p-1+l.length)%l.length],l[p],l[(p+1)%l.length]);g<d&&(d=g,m=p)}l.splice(m,1)}}return l.map(f=>[e[f][0],e[f][1],e[f][2]])}function Su(e){let n=Math.hypot(e[0],e[1],e[2]);return n<1e-9?[0,0,1]:[e[0]/n,e[1]/n,e[2]/n]}var fh=[[],[3,0],[0,1],[3,1],[1,2],[3,0,1,2],[0,2],[3,2],[2,3],[2,0],[0,1,2,3],[2,1],[1,3],[1,0],[0,3],[]];function mh(e,n){if(e.length<4)return e;let t=1,o=-1;for(let u=0;u<e.length;u++){let f=e[u][0]-e[0][0],d=e[u][1]-e[0][1],m=f*f+d*d;m>o&&(o=m,t=u)}let r=u=>{if(u.length<3)return u;let f=u[0],d=u[u.length-1],m=-1,p=n,g=d[0]-f[0],h=d[1]-f[1],y=Math.hypot(g,h)||1;for(let b=1;b<u.length-1;b++){let x=Math.abs((u[b][0]-f[0])*h-(u[b][1]-f[1])*g)/y;x>p&&(p=x,m=b)}return m<0?[f,d]:[...r(u.slice(0,m+1)).slice(0,-1),...r(u.slice(m))]},i=e.slice(0,t+1),s=[...e.slice(t),e[0]],a=r(i),c=r(s),l=[...a.slice(0,-1),...c.slice(0,-1)];return l.length>=3?l:e}function dh(e,n,t){let o=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let s=t[r][0],a=t[r][1],c=t[i][0],l=t[i][1];a>n!=l>n&&e<(c-s)*(n-a)/(l-a)+s&&(o=!o)}return o}function xr(e,n,t,o=1,r="contour"){let i=Su(n),s=Math.abs(i[0])<.9?[1,0,0]:[0,1,0],a=s[0]*i[0]+s[1]*i[1]+s[2]*i[2],c=Su([s[0]-a*i[0],s[1]-a*i[1],s[2]-a*i[2]]),l=[i[1]*c[2]-i[2]*c[1],i[2]*c[0]-i[0]*c[2],i[0]*c[1]-i[1]*c[0]],u=1/0,f=1/0,d=-1/0,m=-1/0,p=1/0,g=-1/0,h=[];for(let D of e){if(D.length<3)continue;let _=[],w=0;for(let V of D){let j=V[0]*c[0]+V[1]*c[1]+V[2]*c[2],G=V[0]*l[0]+V[1]*l[1]+V[2]*l[2],Z=V[0]*i[0]+V[1]*i[1]+V[2]*i[2];_.push([j,G]),w+=Z,j<u&&(u=j),j>d&&(d=j),G<f&&(f=G),G>m&&(m=G),Z<p&&(p=Z),Z>g&&(g=Z)}h.push({pts:_,depth:w/D.length})}if(!Number.isFinite(u)||h.length===0)return null;let y=d-u,b=m-f,x=Math.max(y,b);if(x<1e-6)return null;let P=Math.max(r==="pixel"?3:8,Math.min(384,Math.round(t*(r==="pixel"?1:2)))),M=x/P,C=1,E=u-C*M,A=f-C*M,S=Math.ceil(y/M)+2*C+1,T=Math.ceil(b/M)+2*C+1;if(S*T>4e5)return null;let v=.6,R=(D,_,w)=>{let V=new Uint8Array(S*T),j=(I,B)=>I<0||B<0||I>=S||B>=T?0:V[B*S+I],G=(I,B,N,H,$,k)=>(N-I)*(k-B)-(H-B)*($-I);for(let I of D){let B=I.pts;for(let N=1;N<B.length-1;N++){let H=B[0],$=B[N],k=B[N+1],Q=Math.floor((Math.min(H[0],$[0],k[0])-E)/M),ae=Math.ceil((Math.max(H[0],$[0],k[0])-E)/M),se=Math.floor((Math.min(H[1],$[1],k[1])-A)/M),Y=Math.ceil((Math.max(H[1],$[1],k[1])-A)/M);if(Q<0&&(Q=0),ae>S-1&&(ae=S-1),se<0&&(se=0),Y>T-1&&(Y=T-1),!(Math.abs(G(H[0],H[1],$[0],$[1],k[0],k[1]))<1e-12))for(let ne=se;ne<=Y;ne++){let le=A+(ne+.5)*M;for(let ye=Q;ye<=ae;ye++){if(V[ne*S+ye])continue;let Ce=E+(ye+.5)*M,Ve=G($[0],$[1],k[0],k[1],Ce,le),Ee=G(k[0],k[1],H[0],H[1],Ce,le),Me=G(H[0],H[1],$[0],$[1],Ce,le);(Ve>=0&&Ee>=0&&Me>=0||Ve<=0&&Ee<=0&&Me<=0)&&(V[ne*S+ye]=1)}}}}if(r==="pixel"){let I=new Uint8Array(S*T),B=(N,H)=>{let $=E+N*M,k=A+H*M;return[$*c[0]+k*l[0]+_*i[0],$*c[1]+k*l[1]+_*i[1],$*c[2]+k*l[2]+_*i[2]]};for(let N=0;N<T;N++)for(let H=0;H<S;H++){if(!V[N*S+H]||I[N*S+H])continue;let $=1;for(;H+$<S&&V[N*S+H+$]&&!I[N*S+H+$];)$++;let k=1;e:for(;N+k<T;){for(let Q=0;Q<$;Q++)if(!V[(N+k)*S+H+Q]||I[(N+k)*S+H+Q])break e;k++}for(let Q=N;Q<N+k;Q++)for(let ae=H;ae<H+$;ae++)I[Q*S+ae]=1;w.push([B(H,N),B(H+$,N),B(H+$,N+k),B(H,N+k)])}return}let Z=(I,B)=>`${Math.round(I*2)},${Math.round(B*2)}`,ee=new Map,W=new Map,ie=(I,B,N)=>I===0?[B+.5,N]:I===1?[B+1,N+.5]:I===2?[B+.5,N+1]:[B,N+.5],z=(I,B)=>{let N=Z(I[0],I[1]),H=Z(B[0],B[1]);N!==H&&(ee.has(N)||ee.set(N,[]),ee.has(H)||ee.set(H,[]),ee.get(N).push(B),ee.get(H).push(I),W.set(N,I),W.set(H,B))};for(let I=0;I<T-1;I++)for(let B=0;B<S-1;B++){let N=j(B,I)|j(B+1,I)<<1|j(B+1,I+1)<<2|j(B,I+1)<<3,H=fh[N];for(let $=0;$<H.length;$+=2)z(ie(H[$],B,I),ie(H[$+1],B,I))}if(ee.size===0)return;let X=new Set,U=[];for(let I of ee.keys()){if(X.has(I))continue;let B=[],N=I,H="",$=0;for(;N&&!X.has(N)&&$++<1e6;){X.add(N),B.push(W.get(N));let Q=ee.get(N)??[],ae="";for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H&&!X.has(Y)){ae=Y;break}}if(!ae)for(let se of Q){let Y=Z(se[0],se[1]);if(Y!==H){ae=Y;break}}if(H=N,N=ae,N===I)break}if(B.length<3)continue;let k=mh(B,v);k.length>=3&&U.push(k)}for(let I of U){let B=0,N=I[0][0],H=I[0][1];for(let se of U)se!==I&&dh(N,H,se)&&B++;let $=B%2===0,k=0;for(let se=0;se<I.length;se++){let Y=I[se],ne=I[(se+1)%I.length];k+=Y[0]*ne[1]-ne[0]*Y[1]}let ae=k>0===$?I:[...I].reverse();w.push(ae.map(se=>{let Y=E+se[0]*M,ne=A+se[1]*M;return[Y*c[0]+ne*l[0]+_*i[0],Y*c[1]+ne*l[1]+_*i[1],Y*c[2]+ne*l[2]+_*i[2]]}))}},O=[],L=Math.max(1,Math.floor(o));if(L<=1||g-p<1e-6){let D=g+(g-p)+x;R(h,D,O)}else{let D=g-p,_=D/L,w=D*.05;for(let V=0;V<L;V++){let j=p+V*_,G=V===L-1?1/0:p+(V+1)*_,Z=h.filter(ee=>ee.depth>=j&&ee.depth<G);Z.length&&R(Z,j-w,O)}}return O.length?O:null}function ca(e){let n=0,t=0,o=0,r=0,i=0,s=0,a=0,c=0,l=0,u=!1;for(let y of e)if(y.length>=3&&!u){let b=y[0],x=y[1],P=y[2];n=x[0]-b[0],t=x[1]-b[1],o=x[2]-b[2],r=P[0]-b[0],i=P[1]-b[1],s=P[2]-b[2],a=b[0],c=b[1],l=b[2],u=!0}if(!u)return!0;let f=t*s-o*i,d=o*r-n*s,m=n*i-t*r,p=Math.hypot(f,d,m);if(p<1e-9)return!0;f/=p,d/=p,m/=p;let g=0;for(let y of e)for(let b of y)g=Math.max(g,Math.abs(b[0]-a)+Math.abs(b[1]-c)+Math.abs(b[2]-l));let h=Math.max(.001,g*.001);for(let y of e)for(let b of y){let x=(b[0]-a)*f+(b[1]-c)*d+(b[2]-l)*m;if(Math.abs(x)>h)return!1}return!0}function la(e,n=300){if(e.length===0||e.length>n)return!1;let t=0,o=0,r=0,i=0,s=!1;for(let c of e)for(let l of c)s||(o=l[0],r=l[1],i=l[2],s=!0),t=Math.max(t,Math.abs(l[0]-o)+Math.abs(l[1]-r)+Math.abs(l[2]-i));let a=Math.max(.001,t*.005);for(let c of e){if(c.length<3)continue;let l=c[0],u=c[1],f=c[2],d=(u[1]-l[1])*(f[2]-l[2])-(u[2]-l[2])*(f[1]-l[1]),m=(u[2]-l[2])*(f[0]-l[0])-(u[0]-l[0])*(f[2]-l[2]),p=(u[0]-l[0])*(f[1]-l[1])-(u[1]-l[1])*(f[0]-l[0]),g=Math.hypot(d,m,p);if(g<1e-9)continue;d/=g,m/=g,p/=g;let h=!1,y=!1;for(let b of e)for(let x of b){let P=(x[0]-l[0])*d+(x[1]-l[1])*m+(x[2]-l[2])*p;if(P>a?h=!0:P<-a&&(y=!0),h&&y)return!1}}return!0}function Au(e){let{polysWorldVerts:n,lightDir:t,definition:o,isSelf:r,style:i,pointLights:s}=e,a=ca(n),c=r&&la(n);if(a||c)return{};let l=r?Math.max(2,Math.min(6,Math.round(o/8))):1,u=i==="pixel"?"pixel":"contour",f=p=>{let g=xr(n,p,o,l,u);if(g&&g.length)return g;if(!r){let h=[];for(let b of n)for(let x of b)h.push(x);let y=br(h,p,o);if(y&&y.length>=3)return[y]}},d=f(t),m;if(s&&s.length>0){let p=0,g=0,h=0,y=0;for(let b of n)for(let x of b)p+=x[0],g+=x[1],h+=x[2],y++;y>0&&(p/=y,g/=y,h/=y),m=[];for(let b of s){let x=[b.position[0]-p,b.position[1]-g,b.position[2]-h];m[b.index]=f(x)}}return{overrideSilhouette:d,overridePointSilhouettes:m}}function Vn(e,n){if(e.length===0||n.length<3)return[];let t=e.map(r=>[r[0],r[1]]),o=n.length;for(let r=0;r<o;r++){if(t.length===0)return[];let i=t;t=[];let s=n[r],a=n[(r+1)%o],c=f=>(a[0]-s[0])*(f[1]-s[1])-(a[1]-s[1])*(f[0]-s[0])>=0,l=(f,d)=>{let m=s[0],p=s[1],g=a[0],h=a[1],y=f[0],b=f[1],x=d[0],P=d[1],M=(m-g)*(b-P)-(p-h)*(y-x);if(Math.abs(M)<1e-12)return[f[0],f[1]];let C=((m-y)*(b-P)-(p-b)*(y-x))/M;return[m+C*(g-m),p+C*(h-p)]},u=i.length;for(let f=0;f<u;f++){let d=i[f],m=i[(f+u-1)%u],p=c(d),g=c(m);p?(g||t.push(l(m,d)),t.push([d[0],d[1]])):g&&t.push(l(m,d))}}return t}function Pr(e){if(!Number.isFinite(e)||e<=0)throw new Error("PolyCSS world unit size must be a positive finite number.");return e}function ua(e,n=50){return e*Pr(n)}function fa(e,n=50){return e/Pr(n)}function rn(e,n=50){let t=Pr(n);return[e[1]*t,e[0]*t,e[2]*t]}function ma(e,n=50){let t=Pr(n);return[e[1]/t,e[0]/t,e[2]/t]}function Mr(e){return[e[1],e[0],e[2]]}function da(e){return e?.direction?{...e,direction:Mr(e.direction)}:e}var Cu=ua,Tu=fa,Eu=rn,vu=ma,Iu=Mr,_u=da;function Sr(e){return e==null?[1,1,1]:typeof e=="number"?[e,e,e]:[e[0]??1,e[1]??1,e[2]??1]}function Ct(e){let n=Sr(e),t=n[0]===1&&n[1]===1&&n[2]===1;return(o,r)=>{let i=rn(r),s=o[1]*50,a=o[0]*50,c=o[2]*50,l=t?s:s*n[0],u=t?a:a*n[1],f=t?c:c*n[2];return[l+i[0],u+i[1],f+i[2]]}}function pa(e,n){if(e.length<3||n===0)return e;let t=[],o=e.length;for(let r=0;r<o;r++){let i=e[(r-1+o)%o],s=e[r],a=e[(r+1)%o],c=s[0]-i[0],l=s[1]-i[1],u=a[0]-s[0],f=a[1]-s[1],d=Math.hypot(c,l),m=Math.hypot(u,f);if(d<1e-9||m<1e-9){t.push(s);continue}let p=l/d,g=-c/d,h=f/m,y=-u/m,b=p+h,x=g+y,P=Math.hypot(b,x);if(P<1e-9){t.push(s);continue}let M=b/P,C=x/P,E=M*p+C*g;if(Math.abs(E)<1e-9){t.push(s);continue}let A=n/E;t.push([s[0]+M*A,s[1]+C*A])}return t}var ga=.5,ha=.001,ya=.5;function Ar(e,n,t,o){let r=[];for(let u=0;u<e.length;u++){if(o.has(u))continue;let f=e[u];if(f.vertices.length<3)continue;let d=f.vertices.map(A=>t(A,n)),m=d[0],p=0,g=0,h=0;for(let A=1;A+1<d.length;A++){let S=d[A],T=d[A+1],v=S[0]-m[0],R=S[1]-m[1],O=S[2]-m[2],L=T[0]-m[0],D=T[1]-m[1],_=T[2]-m[2];p+=D*O-_*R,g+=_*v-L*O,h+=L*R-D*v}let y=Math.hypot(p,g,h);if(y<1e-9)continue;let b=[p/y,g/y,h/y],x=null;for(let A=1;A<d.length;A++){let S=d[A],T=S[0]-m[0],v=S[1]-m[1],R=S[2]-m[2],O=Math.hypot(T,v,R);if(O>1e-9){x=[T/O,v/O,R/O];break}}if(!x)continue;let P=x[0]*b[0]+x[1]*b[1]+x[2]*b[2];x=[x[0]-P*b[0],x[1]-P*b[1],x[2]-P*b[2]];let M=Math.hypot(x[0],x[1],x[2]);if(M<1e-9)continue;x=[x[0]/M,x[1]/M,x[2]/M];let C=[b[1]*x[2]-b[2]*x[1],b[2]*x[0]-b[0]*x[2],b[0]*x[1]-b[1]*x[0]],E=b[0]*m[0]+b[1]*m[1]+b[2]*m[2];r.push({face:f,O:m,n:b,u:x,v:C,offset:E,polyIndex:u})}let i=[];for(let u of r){let f=!1;for(let d of i){let m=d.rep;if(!(1-(u.n[0]*m.n[0]+u.n[1]*m.n[1]+u.n[2]*m.n[2])>ha)&&!(Math.abs(u.offset-m.offset)>ya)){d.faces.push(u),f=!0;break}}f||i.push({rep:u,faces:[u]})}let s=[],a=3,c=u=>`${u[0].toFixed(a)},${u[1].toFixed(a)},${u[2].toFixed(a)}`;for(let u of i){if(u.faces.length===1){l(u.faces);continue}let f=u.faces.map(h=>{let y=new Set;for(let b of h.face.vertices)y.add(c(t(b,n)));return y}),d=u.faces.map((h,y)=>y),m=h=>{for(;d[h]!==h;)d[h]=d[d[h]],h=d[h];return h},p=(h,y)=>{let b=m(h),x=m(y);b!==x&&(d[b]=x)};for(let h=0;h<u.faces.length;h++)for(let y=h+1;y<u.faces.length;y++){let b=f[h],x=f[y],P=0;for(let M of b)if(x.has(M)&&(P++,P>=2))break;P>=2&&p(h,y)}let g=new Map;for(let h=0;h<u.faces.length;h++){let y=m(h),b=g.get(y);b||(b=[],g.set(y,b)),b.push(u.faces[h])}for(let h of g.values())l(h)}function l(u){let f=u[0],{O:d,n:m,u:p,v:g}=f,h=[],y=[],b=[];for(let M of u){let C=[];for(let E of M.face.vertices){let A=t(E,n),S=A[0]-d[0],T=A[1]-d[1],v=A[2]-d[2],R=[S*p[0]+T*p[1]+v*p[2],S*g[0]+T*g[1]+v*g[2]];h.push(R),C.push(R)}C.length>=3&&(y.push(yn(C)),b.push(M.polyIndex))}if(h.length<3)return;let x=yr(h);if(x.length<3)return;let P=pa(yn(x),ga);s.push({O:d,n:m,u:p,v:g,outlineUv:P,memberPolysUv:y,memberPolyIndices:b})}return s}function Vu(e){let n=typeof e.scale=="number"?e.scale:e.scale?.[0]??1,t=typeof e.scale=="number"?e.scale:e.scale?.[1]??1,o=typeof e.scale=="number"?e.scale:e.scale?.[2]??1,r=n!==1||t!==1||o!==1,i=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),s=e.position?rn(e.position):[0,0,0],a=[];return(s[0]!==0||s[1]!==0||s[2]!==0)&&a.push(`translate3d(${s[0]}px, ${s[1]}px, ${s[2]}px)`),i&&(e.rotation[0]&&a.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&a.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&a.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&a.push(`scale3d(${n}, ${t}, ${o})`),a.length>0?a.join(" "):void 0}function Ou(e={}){let n=e.target??_e.target,t=e.autoCenterOffset??[0,0,0],o=e.layoutScale??1,r=e.worldUnitPx??50,i=(e.zoom??_e.zoom)/r*o,s=(e.distance??_e.distance)*o,a=rn([n[0]+t[0],n[1]+t[1],n[2]+t[2]],r);return`${s!==0?`translateZ(${-s}px) `:""}scale(${i}) rotateX(${e.rotX??_e.rotX}deg) rotate(${e.rotY??_e.rotY}deg) translate3d(${-a[0]}px, ${-a[1]}px, ${-a[2]}px)`}var un=50,Jn=[.4,-.7,.59],et="#ffffff",nt=1,tt="#ffffff",ot=.4,On=4096,lo=1,Cr=.1,Tr=1,uo=On*On,Er=uo*3,Tt=2048,vr=4*1024*1024,Ir=16*1024*1024,_r=.995,Vr=512,Ru=12,Ae=.001,de=1e-9,Or=1e-4,Rr=.1,fo=.01,Lu=.75,wu=1,Nu=250,Du=1.5,Lr=.75,bn=3,wr=2,mo=4,Nr=[1,10,100,1e3,1e4,1e5,1e6],xn=64,Dr=32,Fr=96,nn=64,Br=128,po=50,go=1e-7,Pn=16,kr=.9,tn=.75,ho=.2,zr=.05,Ur=256,Gr=.6,Fu=1.5;function $r(e){return e===void 0||e==="auto"||!Number.isFinite(e)?1:Math.max(0,Math.min(1,e))}var yo=new Map;function rt(e){if(yo.has(e)){let t=yo.get(e);return t===void 0?null:t}let n=Tn(e);return yo.size>=Vr&&yo.clear(),yo.set(e,n),n}function fn(e){let n=rt(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Xr({r:e,g:n,b:t}){return`${e},${n},${t}`}function bo(e){return rt(e)?.alpha??1}function xo({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function Bu(e,n){if(n)for(let t of n){if(t.scale<=0)continue;let o=fn(t.color);e[0]+=Xe(o.r/255)*t.scale,e[1]+=Xe(o.g/255)*t.scale,e[2]+=Xe(o.b/255)*t.scale}}function Po(e,n,t,o,r){let i=fn(n),s=fn(t),a=Xe(i.r/255),c=Xe(i.g/255),l=Xe(i.b/255),u=Xe(s.r/255),f=Xe(s.g/255),d=Xe(s.b/255),m=[a*e,c*e,l*e];return Bu(m,r),{r:(m[0]+u*o)*Et,g:(m[1]+f*o)*Et,b:(m[2]+d*o)*Et}}function ku({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Xe(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function ph(e){return e<=.0031308?e*12.92:1.055*Math.pow(e,1/2.4)-.055}var Et=1/Math.PI;function Rn(e,n,t,o,r,i){let s=fn(e),a=fn(t),c=fn(o),l=Xe(s.r/255),u=Xe(s.g/255),f=Xe(s.b/255),d=Xe(a.r/255),m=Xe(a.g/255),p=Xe(a.b/255),g=Xe(c.r/255),h=Xe(c.g/255),y=Xe(c.b/255),b=[d*n,m*n,p*n];Bu(b,i);let x=l*(b[0]+g*r)*Et,P=u*(b[1]+h*r)*Et,M=f*(b[2]+y*r)*Et,C=v=>Math.max(0,Math.min(255,Math.round(ph(Math.max(0,Math.min(1,v)))*255))),E=C(x),A=C(P),S=C(M),T=bo(e);return T<1?`rgba(${E}, ${A}, ${S}, ${T})`:xo({r:E,g:A,b:S})}function Yr(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=rt(e);if(!t)return e;let o=255/Math.max(1,Math.round(n)-1),r=s=>Math.max(0,Math.min(255,Math.round(Math.round(s/o)*o))),i={r:r(t.rgb[0]),g:r(t.rgb[1]),b:r(t.rgb[2])};return t.alpha<1?`rgba(${i.r}, ${i.g}, ${i.b}, ${t.alpha})`:xo(i)}function zu(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function Uu(e,n,t){let o=(r,i)=>{let s=i-r;return Math.abs(s)<=t?i:r+Math.sign(s)*t};return{r:o(e.r,n.r),g:o(e.g,n.g),b:o(e.b,n.b)}}function Gu(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:xo(e)}function $u(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=rt(e),o=rt(n);if(!t||!o)return 1;let r=t.rgb[0]-o.rgb[0],i=t.rgb[1]-o.rgb[1],s=t.rgb[2]-o.rgb[2],a=(t.alpha-o.alpha)*255;return Math.sqrt(r*r+i*i+s*s+a*a)/510}function jr(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p?(p.degree+=1,p.degree===2?p.polyB=a:p.polyB=null):i.set(m,{polyA:a,polyB:null,vertA:f,vertB:d,degree:1})}}let s=new Map;for(let[a,c]of i)s.set(a,{polyA:c.polyA,polyB:c.polyB,vertA:c.vertA,vertB:c.vertB});return s}function Wr(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,i=n[2]/t;return e.map(s=>s?s[0]*o+s[1]*r+s[2]*i<-1e-6:!0)}function ba(e,n){let o=a=>Math.round(a/1e-4).toString(36),r=a=>`${o(a[0])},${o(a[1])},${o(a[2])}`,i=new Map,s=a=>{let c=r(a);i.set(c,(i.get(c)??0)+1)};for(let a of e.values()){let c=n[a.polyA]??!1,l;a.polyB===null?l=c:l=c!==(n[a.polyB]??!1),l&&(s(a.vertA),s(a.vertB))}for(let a of i.values())if(a!==2)return!1;return!0}function Mo(e,n){let t=[];for(let l of e.values()){let u=n[l.polyA]??!1;if(l.polyB===null)u&&t.push([l.vertA,l.vertB]);else{let f=n[l.polyB]??!1;u!==f&&t.push([l.vertA,l.vertB])}}if(t.length===0)return[];let o=1e-4,r=l=>Math.round(l/o).toString(36),i=l=>`${r(l[0])},${r(l[1])},${r(l[2])}`,s=t.map(([l,u])=>({a:l,b:u,aKey:i(l),bKey:i(u),used:!1})),a=new Map;for(let l of s){let u=a.get(l.aKey);u||(u=[],a.set(l.aKey,u)),u.push(l);let f=a.get(l.bKey);f||(f=[],a.set(l.bKey,f)),f.push(l)}let c=[];for(let l of s){if(l.used)continue;let u=[l.a],f=l,d=l.aKey,m=l.bKey;f.used=!0;for(let p=0;p<s.length+1;p++){u.push(f.bKey===m?f.b:f.a);let g=a.get(m)??[],h=null;for(let y of g)if(!(y===f||y.used)){h=y;break}if(!h||(h.used=!0,d=m,m=h.aKey===d?h.bKey:h.aKey,f=h,m===l.aKey))break}u.length>=3&&c.push(u)}return c}var Xu=40;function Yu(e){let t=a=>Math.round(a/1e-4).toString(36),o=a=>`${t(a[0])},${t(a[1])},${t(a[2])}`,r=(a,c)=>{let l=o(a),u=o(c);return l<u?`${l}|${u}`:`${u}|${l}`},i=new Map;for(let a=0;a<e.length;a++){let c=e[a];if(!c||c.vertices.length<2)continue;let l=c.vertices;for(let u=0;u<l.length;u++){let f=l[u],d=l[(u+1)%l.length],m=r(f,d),p=i.get(m);p||(p=[],i.set(m,p)),p.push(a)}}let s=new Map;for(let a of i.values())if(!(a.length<2))for(let c of a)for(let l of a){if(c===l)continue;let u=s.get(c);u||(u=new Set,s.set(c,u)),u.add(l)}return s}function ju(e,n,t,o){let r=Ct(t),i=!!o&&(o[0]!==0||o[1]!==0||o[2]!==0),s=i?rn(n):null,a=e.map(c=>{if(!c)return{vertices:[],color:""};let l=c.vertices.map(u=>r(u,n));return i&&s&&o&&(l=l.map(u=>{let f=[u[0]-s[0],u[1]-s[1],u[2]-s[2]],d=Dn(f,o);return[d[0]+s[0],d[1]+s[1],d[2]+s[2]]})),{vertices:l,color:""}});return jr(a)}function Wu(e,n,t,o,r){let i=[],s=Ct(t),a=!!r&&(r[0]!==0||r[1]!==0||r[2]!==0),c=a?rn(n):null;for(let l=0;l<e.length;l++){if(!o(l))continue;let u=e[l];if(!u)continue;let f=u.vertices.map(M=>s(M,n));a&&c&&r&&(f=f.map(M=>{let C=[M[0]-c[0],M[1]-c[1],M[2]-c[2]],E=Dn(C,r);return[E[0]+c[0],E[1]+c[1],E[2]+c[2]]}));let d=1/0,m=1/0,p=1/0,g=-1/0,h=-1/0,y=-1/0;for(let M of f)M[0]<d&&(d=M[0]),M[0]>g&&(g=M[0]),M[1]<m&&(m=M[1]),M[1]>h&&(h=M[1]),M[2]<p&&(p=M[2]),M[2]>y&&(y=M[2]);let b=[[d,m,p],[g,m,p],[d,h,p],[g,h,p],[d,m,y],[g,m,y],[d,h,y],[g,h,y]],x=null,P=0;if(f.length>=3){let M=f[0],C=f[1],E=f[2],A=[C[0]-M[0],C[1]-M[1],C[2]-M[2]],S=[E[0]-M[0],E[1]-M[1],E[2]-M[2]],T=S[1]*A[2]-S[2]*A[1],v=S[2]*A[0]-S[0]*A[2],R=S[0]*A[1]-S[1]*A[0],O=Math.hypot(T,v,R);O>1e-9&&(x=[T/O,v/O,R/O],P=x[0]*M[0]+x[1]*M[1]+x[2]*M[2])}i.push({wv:f,bboxCorners:b,planeN:x,planeOffset:P,polygonIndex:l})}return i}function Hu(e,n,t,o,r,i){let s=Ct(t),a=!!i&&(i[0]!==0||i[1]!==0||i[2]!==0),c=a?rn(n):null,f=Ar(e,n,a&&c&&i?(h,y)=>{let b=s(h,y),x=[b[0]-c[0],b[1]-c[1],b[2]-c[2]],P=Dn(x,i);return[P[0]+c[0],P[1]+c[1],P[2]+c[2]]}:s,o).map((h,y)=>{let{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A}=h,S=1/0,T=1/0,v=-1/0,R=-1/0;for(let Z of C)Z[0]<S&&(S=Z[0]),Z[1]<T&&(T=Z[1]),Z[0]>v&&(v=Z[0]),Z[1]>R&&(R=Z[1]);let O=v-S,L=R-T,D=r*50,_=b[0]+S*P[0]+T*M[0]+D*x[0],w=b[1]+S*P[1]+T*M[1]+D*x[1],V=b[2]+S*P[2]+T*M[2]+D*x[2],G=`matrix3d(${[P[0],P[1],P[2],0,M[0],M[1],M[2],0,x[0],x[1],x[2],0,_,w,V,1].map(Z=>Z.toFixed(4)).join(",")})`;return{O:b,n:x,u:P,v:M,outlineUv:C,memberPolysUv:E,memberPolyIndices:A,minU:S,minV:T,width:O,height:L,matrixCss:G,faceIndex:y,lift:D}}),d=.015,m=.5,p=20,g=new Set;for(let h=0;h<f.length;h++){if(g.has(h))continue;let y=f[h],b=y.n[0]*y.O[0]+y.n[1]*y.O[1]+y.n[2]*y.O[2],x=y.minU,P=y.minV,M=y.minU+y.width,C=y.minV+y.height;for(let E=0;E<f.length;E++){if(E===h||g.has(E))continue;let A=f[E];if(y.n[0]*A.n[0]+y.n[1]*A.n[1]+y.n[2]*A.n[2]<1-d)continue;let T=y.n[0]*A.O[0]+y.n[1]*A.O[1]+y.n[2]*A.O[2];if(T<=b+m||T-b>p)continue;let v=1/0,R=1/0,O=-1/0,L=-1/0;for(let D of A.outlineUv){let _=A.O[0]+D[0]*A.u[0]+D[1]*A.v[0],w=A.O[1]+D[0]*A.u[1]+D[1]*A.v[1],V=A.O[2]+D[0]*A.u[2]+D[1]*A.v[2],j=_-y.O[0],G=w-y.O[1],Z=V-y.O[2],ee=j*y.u[0]+G*y.u[1]+Z*y.u[2],W=j*y.v[0]+G*y.v[1]+Z*y.v[2];ee<v&&(v=ee),ee>O&&(O=ee),W<R&&(R=W),W>L&&(L=W)}if(v<=x&&O>=M&&R<=P&&L>=C){let D=Math.max(0,M-x)*Math.max(0,C-P);if(Math.max(0,O-v)*Math.max(0,L-R)>D*2)continue;g.add(h);break}}}return f=f.filter((h,y)=>!g.has(y)),f}function Pa(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:s,allPointLights:a,thisPointIndex:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=Math.hypot(i[0],i[1],i[2])||1,p=i[0]/m,g=i[1]/m,h=i[2]/m,y=!!s,b=y?_=>{let w=s[0]-_[0],V=s[1]-_[1],j=s[2]-_[2],G=Math.hypot(w,V,j)||1;return[w/G,V/G,j/G]}:_=>[p,g,h],x=u?.color??"#ffffff",P=u?.intensity??.4,M=f?.intensity??1,C=f?.color??"#ffffff",E=d?.color??"#000000",A=d?.opacity??.25,S=!y,T=d?.maxExtend??2e3,v=[],R=new Array(r.length).fill(!1),O=r.map((_,w)=>{if(y){if(_.overridePointSilhouettes){let W=_.overridePointSilhouettes[c??-1];if(W)return W}else if(_.overrideSilhouette)return _.overrideSilhouette}else if(_.overrideSilhouette)return _.overrideSilhouette;if(y){if(_.selfShadowEdgeMap)return R[w]=!0,null;let W=_.edgeOwners;if(!W)return null;let ie=_.casterPolygonCount??0;if(ie===0)return null;let z=new Array(ie).fill(!0);for(let X of _.items){if(X.polygonIndex>=ie)continue;let U=X.planeN;if(!U){z[X.polygonIndex]=!0;continue}let I=0,B=0,N=0;for(let k of X.wv)I+=k[0],B+=k[1],N+=k[2];let H=X.wv.length>0?1/X.wv.length:0,$=b([I*H,B*H,N*H]);z[X.polygonIndex]=U[0]*$[0]+U[1]*$[1]+U[2]*$[2]<-1e-6}return ba(W,z)?Mo(W,z):(R[w]=!0,null)}let V=_.edgeOwners;if(_.selfShadowEdgeMap)return R[w]=!0,null;if(!V)return null;let j=_.casterPolygonCount??0;if(j<Xu||_.items.length<Xu)return null;let G=0;for(let W of _.items)W.planeN&&G++;if(G*2<_.items.length)return null;let Z=new Array(j).fill(null);for(let W of _.items)W.planeN&&W.polygonIndex<j&&(Z[W.polygonIndex]=W.planeN);let ee=Wr(Z,i);return ba(V,ee)?Mo(V,ee):(R[w]=!0,null)}),L=(_,w,V,j)=>{if(_.length<3)return[];let G=[],Z=W=>(W[0]-w[0])*V[0]+(W[1]-w[1])*V[1]+(W[2]-w[2])*V[2],ee=(W,ie,z,X)=>{let U=(z-j)/(z-X);return[W[0]+U*(ie[0]-W[0]),W[1]+U*(ie[1]-W[1]),W[2]+U*(ie[2]-W[2])]};for(let W=0;W<_.length;W++){let ie=_[W],z=_[(W+_.length-1)%_.length],X=Z(ie),U=Z(z),I=X>j,B=U>j;I?(B||G.push(ee(z,ie,U,X)),G.push(ie)):B&&G.push(ee(z,ie,U,X))}return G},D={rotX:l.rotX,rotY:l.rotY};for(let _ of n){let{O:w,n:V,u:j,v:G,outlineUv:Z,minU:ee,minV:W,width:ie,height:z}=_,X=b(w),U=X[0]*V[0]+X[1]*V[1]+X[2]*V[2];if(U<=1e-6||!At(V,D))continue;let I=Math.max(0,p*V[0]+g*V[1]+h*V[2]),B=0,N=0;for(let re of Z)B+=re[0],N+=re[1];let H=Z.length>0?1/Z.length:0;B*=H,N*=H;let $=[w[0]+B*j[0]+N*G[0],w[1]+B*j[1]+N*G[1],w[2]+B*j[2]+N*G[2]],k=[],Q=0;if(a)for(let re=0;re<a.length;re++){let fe=a[re],me=fe.position[0]-$[0],Pe=fe.position[1]-$[1],ge=fe.position[2]-$[2],Fe=Math.hypot(me,Pe,ge)||1,Le=Math.max(0,me/Fe*V[0]+Pe/Fe*V[1]+ge/Fe*V[2]);k[re]=Le,Q+=(fe.intensity??1)*Le}let ae=re=>(re[0]-w[0])*V[0]+(re[1]-w[1])*V[1]+(re[2]-w[2])*V[2],se=(re,fe,me,Pe)=>{let ge=me/(me-Pe);return[re[0]+ge*(fe[0]-re[0]),re[1]+ge*(fe[1]-re[1]),re[2]+ge*(fe[2]-re[2])]},Y=re=>{let fe=re[0]-w[0],me=re[1]-w[1],Pe=re[2]-w[2],ge=y?b(re):[p,g,h],Fe=y?ge[0]*V[0]+ge[1]*V[1]+ge[2]*V[2]:U,Le=Fe>.001?Fe:.001,Oe=(fe*V[0]+me*V[1]+Pe*V[2])/Le,$e=re[0]-Oe*ge[0],ze=re[1]-Oe*ge[1],Ue=re[2]-Oe*ge[2],We=$e-w[0],be=ze-w[1],De=Ue-w[2];return[We*j[0]+be*j[1]+De*j[2],We*G[0]+be*G[1]+De*G[2]]},ne=new Map,le=0,ye=ee,Ce=W,Ve=_.minU+ie,Ee=_.minV+z,Me=1/0,Re=1/0,F=-1/0,q=-1/0;for(let re of r)for(let fe of re.items)for(let me of fe.wv){let Pe=me[0]-w[0],ge=me[1]-w[1],Fe=me[2]-w[2],Le=Pe*j[0]+ge*j[1]+Fe*j[2],Oe=Pe*G[0]+ge*G[1]+Fe*G[2];Le<Me&&(Me=Le),Le>F&&(F=Le),Oe<Re&&(Re=Oe),Oe>q&&(q=Oe)}let J=Number.isFinite(Me)?[[Me-T,Re-T],[F+T,Re-T],[F+T,q+T],[Me-T,q+T]]:[],te=.05,ue=V[0]*w[0]+V[1]*w[1]+V[2]*w[2],ce=.0025,he=5,Se=.94;for(let re=0;re<r.length;re++){let fe=r[re],me=fe.selfShadowEdgeMap,Pe=O[re];if(Pe!==null){if(Pe.length===0)continue;let ge=!!fe.overrideSilhouette,Fe=!1;if(ge){let Le=0;for(let Oe of Pe){if(Oe.length<3)continue;let $e=L(Oe,w,V,te);if($e.length<3)continue;let ze=$e.map(Y),Ue=0;for(let We=0;We<ze.length;We++){let be=ze[We],De=ze[(We+1)%ze.length];Ue+=be[0]*De[1]-De[0]*be[1]}Math.abs(Ue)>Le&&(Le=Math.abs(Ue),Fe=Ue<0)}}for(let Le of Pe){if(Le.length<3)continue;let Oe=L(Le,w,V,te);if(Oe.length<3)continue;let $e=Oe.map(Y),ze=ge?Fe?[...$e].reverse():$e:yn($e),Ue=J.length===4?Vn(ze,J):ze;if(Ue.length<3)continue;let We=Vn(Ue,Z);if(We.length<3)continue;let be;for(let De of _.memberPolysUv){let Ie=Vn(We,yn(De));Ie.length<3||(be||(be=ne.get(fe.id),be||(be={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,be))),be.verts.push(Ie),be.subPolygonIndices.push(-1),le++)}}continue}for(let ge of fe.items){if(me){let be=me.get(ge.polygonIndex);if(be){let De=!1;for(let Ie of _.memberPolyIndices)if(be.has(Ie)){De=!0;break}if(De){let Ie=ge.planeN;if(!Ie||Math.abs(Ie[0]*V[0]+Ie[1]*V[1]+Ie[2]*V[2])>Se)continue}}}if(ge.planeN&&!R[re]){let be=p,De=g,Ie=h;if(y){let Do=0,Fo=0,Bo=0;for(let kt of ge.wv)Do+=kt[0],Fo+=kt[1],Bo+=kt[2];let wn=ge.wv.length>0?1/ge.wv.length:0,dt=b([Do*wn,Fo*wn,Bo*wn]);be=dt[0],De=dt[1],Ie=dt[2]}if(ge.planeN[0]*be+ge.planeN[1]*De+ge.planeN[2]*Ie>-1e-6)continue}if(ge.planeN){let be=ge.planeN,De=be[0]*V[0]+be[1]*V[1]+be[2]*V[2];if(Math.abs(De)>1-ce){let Ie=De>0?1:-1;if(Math.abs(ge.planeOffset-Ie*ue)<he)continue}}let Fe=ge.bboxCorners,Le=!1,Oe=1/0,$e=1/0,ze=-1/0,Ue=-1/0;for(let be=0;be<8;be++){let De=Fe[be];ae(De)>te&&(Le=!0);let Ie=Y(De);Ie[0]<Oe&&(Oe=Ie[0]),Ie[0]>ze&&(ze=Ie[0]),Ie[1]<$e&&($e=Ie[1]),Ie[1]>Ue&&(Ue=Ie[1])}if(!Le||ze<ye||Oe>Ve||Ue<Ce||$e>Ee)continue;let We=ge.wv;for(let be=1;be<We.length-1;be++){let De=We[0],Ie=We[be],No=We[be+1],Do=ae(De),Fo=ae(Ie),Bo=ae(No),wn=[],dt=[[De,Do],[Ie,Fo],[No,Bo]];for(let pt=0;pt<3;pt++){let[Cn,zt]=dt[pt],[ko,Ut]=dt[(pt+1)%3],Gt=zt>te,zo=Ut>te;Gt&&wn.push(Cn),Gt!==zo&&wn.push(se(Cn,ko,zt,Ut))}if(wn.length<3)continue;let kt=wn.map(Y),mc=yn(kt),dc=J.length===4?Vn(mc,J):mc;if(dc.length<3)continue;let pc=Vn(dc,Z);if(pc.length<3)continue;let $n;for(let pt of _.memberPolysUv){let Cn=Vn(pc,yn(pt));if(!(Cn.length<3)){if(me){let zt=0,ko=1/0,Ut=-1/0,Gt=1/0,zo=-1/0;for(let Uo=0;Uo<Cn.length;Uo++){let gn=Cn[Uo],gc=Cn[(Uo+1)%Cn.length];zt+=gn[0]*gc[1]-gc[0]*gn[1],gn[0]<ko&&(ko=gn[0]),gn[0]>Ut&&(Ut=gn[0]),gn[1]<Gt&&(Gt=gn[1]),gn[1]>zo&&(zo=gn[1])}if(Math.abs(zt)*.5<5)continue}$n||($n=ne.get(fe.id),$n||($n={id:fe.id,verts:[],subPolygonIndices:[]},ne.set(fe.id,$n))),$n.verts.push(Cn),$n.subPolygonIndices.push(ge.polygonIndex),le++}}}}}if(le===0||!(ie>0)||!(z>0))continue;let ve=S?M*I:(a?.[c??-1]?.intensity??1)*(k[c??-1]??0),xe=M*I+Q+Math.max(0,P),K=A;if(o)if(xe>0){let re=Math.max(0,(xe-ve)/xe);K=A*(1-Math.pow(re,1/2.4))}else K=0;let oe=_.memberPolyIndices[0]??0,pe=t[oe]?.color??"#cccccc",qe=S?0:M*I,Ye=[];if(a)for(let re=0;re<a.length;re++){if(y&&re===c)continue;let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Ye.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let Ge=o?E:Rn(pe,qe,C,x,P,Ye),we=1/0,Ne=1/0,Je=-1/0,Qe=-1/0;for(let re of ne.values())for(let fe of re.verts)for(let me of fe)me[0]<we&&(we=me[0]),me[0]>Je&&(Je=me[0]),me[1]<Ne&&(Ne=me[1]),me[1]>Qe&&(Qe=me[1]);we=Math.floor(we-1),Ne=Math.floor(Ne-1),Je=Math.ceil(Je+1),Qe=Math.ceil(Qe+1),we<ee&&(we=ee),Ne<W&&(Ne=W),Je>ee+ie&&(Je=ee+ie),Qe>W+z&&(Qe=W+z);let Mn=Je-we,Sn=Qe-Ne;if(!(Mn>0)||!(Sn>0))continue;let Gn=_.lift,Bt=w[0]+we*j[0]+Ne*G[0]+Gn*V[0],ft=w[1]+we*j[1]+Ne*G[1]+Gn*V[1],An=w[2]+we*j[2]+Ne*G[2]+Gn*V[2],mt=`matrix3d(${[j[0],j[1],j[2],0,G[0],G[1],G[2],0,V[0],V[1],V[2],0,Bt,ft,An,1].map(re=>re.toFixed(4)).join(",")})`,je=[],en=[];for(let re of ne.values()){let fe="";for(let me of re.verts){fe+=`M${(me[0][0]-we).toFixed(1)},${(me[0][1]-Ne).toFixed(1)}`;for(let Pe=1;Pe<me.length;Pe++)fe+=`L${(me[Pe][0]-we).toFixed(1)},${(me[Pe][1]-Ne).toFixed(1)}`;fe+="Z",en.push(me.map(Pe=>[Pe[0],Pe[1]]))}je.push({casterId:re.id,d:fe,casterPolygonIndices:re.subPolygonIndices})}let Te=[];if(a)for(let re=0;re<a.length;re++){let fe=k[re]??0;if(fe<=0)continue;let me=a[re];Te.push({color:me.color??"#ffffff",scale:(me.intensity??1)*fe})}let ke=o?"":Rn(pe,M*I,C,x,P,Te);v.push({faceIndex:_.faceIndex,memberPolyIndices:_.memberPolyIndices,matrixCss:mt,width:Mn,height:Sn,fill:Ge,opacity:K,paths:je,fullLitFill:ke,facePolysUv:en})}return v}function gh(e,n){let t=gt(e)?.rgb??[0,0,0],o=gt(n)?.rgb??[255,255,255],r=i=>{let s=o[i]??0;return s<=0?255:Math.max(0,Math.min(255,Math.round(t[i]/s*255)))};return`rgb(${r(0)},${r(1)},${r(2)})`}function xa(e,n,t){let o="";for(let r of e)if(!(r.length<3)){o+=`M${(r[0][0]-n).toFixed(1)},${(r[0][1]-t).toFixed(1)}`;for(let i=1;i<r.length;i++)o+=`L${(r[i][0]-n).toFixed(1)},${(r[i][1]-t).toFixed(1)}`;o+="Z"}return o}function Ku(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,runDirectional:s,pointPasses:a,allPointLights:c,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d}=e,m=d?.opacity??.25,p=new Map;for(let b of n)p.set(b.faceIndex,b);let g=new Map,h=(b,x)=>{let P=Pa({receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:i,lightPos:b,allPointLights:c,thisPointIndex:x,cameraRot:l,ambientLight:u,directionalLight:f,shadow:d});for(let M of P){if(M.facePolysUv.length===0)continue;let C=M.fullLitFill!=="",E=g.get(M.faceIndex);E||(E={memberPolyIndices:M.memberPolyIndices,base:M.fullLitFill,solid:C,layers:[]},g.set(M.faceIndex,E)),E.layers.push({polys:M.facePolysUv,fill:M.fill,opacity:M.opacity})}};s&&h(void 0,void 0);for(let b of a)h(b.lightPos,b.index);let y=[];for(let[b,x]of g){let P=p.get(b);if(!P||x.layers.length===0)continue;let M=1/0,C=1/0,E=-1/0,A=-1/0;for(let z of x.layers)for(let X of z.polys)for(let U of X)U[0]<M&&(M=U[0]),U[0]>E&&(E=U[0]),U[1]<C&&(C=U[1]),U[1]>A&&(A=U[1]);if(!Number.isFinite(M))continue;M=Math.floor(M-1),C=Math.floor(C-1),E=Math.ceil(E+1),A=Math.ceil(A+1);let S=E-M,T=A-C;if(!(S>0)||!(T>0))continue;let{O:v,u:R,v:O,n:L,lift:D}=P,_=v[0]+M*R[0]+C*O[0]+D*L[0],w=v[1]+M*R[1]+C*O[1]+D*L[1],V=v[2]+M*R[2]+C*O[2]+D*L[2],G=`matrix3d(${[R[0],R[1],R[2],0,O[0],O[1],O[2],0,L[0],L[1],L[2],0,_,w,V,1].map(z=>z.toFixed(4)).join(",")})`,Z=x.solid&&x.layers.length>1,ee=null,W=null,ie=[];if(Z){ee=x.base,W="";for(let z of x.layers)W+=xa(z.polys,M,C);for(let z of x.layers)ie.push({d:xa(z.polys,M,C),fill:gh(z.fill,x.base),multiply:!0,opacity:1})}else for(let z of x.layers)ie.push({d:xa(z.polys,M,C),fill:z.fill,multiply:!1,opacity:z.opacity});y.push({faceIndex:b,memberPolyIndices:x.memberPolyIndices,matrixCss:G,width:S,height:T,svgOpacity:Z?m:1,baseFill:ee,baseD:W,layers:ie})}return y}var hh=Symbol.for("polycss.animation.triangleFrameSource"),yh=Symbol.for("polycss.animation.triangleFrameTarget"),Sa=2200,Hr=2201,Aa=2202;function bh(e,n){let t=0,o=1,r=1,i=Hr,s=1/0,a=0,c=!1,l=null,u=!0,f=!1,d={clampWhenFinished:!1,get timeScale(){return r},set timeScale(m){r=m},get weight(){return o},set weight(m){o=m},get time(){return t},set time(m){t=m},get isRunning(){return c},get enabled(){return u},set enabled(m){u=m},get paused(){return f},set paused(m){f=m},play(){return c=!0,d},stop(){return c=!1,t=0,a=0,l=null,d},reset(){return t=0,a=0,d},fadeIn(m){return l={from:0,to:1,elapsed:0,duration:m},o=0,d},fadeOut(m){return l={from:o,to:0,elapsed:0,duration:m},d},crossFadeTo(m,p){return d.fadeOut(p),m.fadeIn(p),d},crossFadeFrom(m,p){return m.fadeOut(p),d.fadeIn(p),d},setLoop(m,p){return i=m,s=p,d},setEffectiveTimeScale(m){return r=m,d},setEffectiveWeight(m){return o=m,d}};return d._internal={get clip(){return e},get time(){return t},get weight(){return o},get enabled(){return u},get paused(){return f},get running(){return c},get loopMode(){return i},get repetitions(){return s},get completedReps(){return a},set completedReps(m){a=m},get clampWhenFinished(){return d.clampWhenFinished},get timeScale(){return r},get fade(){return l},advance(m){if(!c)return;if(l){l.elapsed+=m;let g=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(o=l.from+(l.to-l.from)*g,g>=1&&(o=l.to,l=null,o<=0)){c=!1;return}}if(f)return;let p=e.duration;if(!(p<=0)){if(t+=m*r,i===Sa)t>=p&&(t=d.clampWhenFinished?p:0,c=!1);else if(i===Hr){if(t>=p){let g=t%p,h=Math.floor(t/p);a+=h,t=g,s!==1/0&&a>=s&&(t=d.clampWhenFinished?p:0,c=!1)}}else if(p>0){let g=p*2,h=t%g;if(t>=g){let y=Math.floor(t/g);a+=y,s!==1/0&&a>=s?(t=d.clampWhenFinished?p:0,c=!1):t=h}}}},sampleTime(){if(i===Aa){let m=e.duration,p=m*2,g=t%p;return g<=m?g:p-g}return t}},d}function xh(e){return e._internal}function Ma(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function Zu(e,n){let t=new Map,o=n,r=e;function i(f){let d=Ma(n.clips,f);if(!d)throw new Error(`PolyAnimationMixer: no clip found for key "${f}". Available: ${n.clips.map(p=>p.name).join(", ")}`);let m=t.get(d.index);return m||(m=bh(d,n),t.set(d.index,m)),m}function s(f){let d=Ma(n.clips,f);return d?t.get(d.index)??null:null}function a(f){let d=[];for(let y of t.values()){let b=xh(y);b.advance(f),b.running&&b.enabled&&d.push({internal:b,clip:b.clip})}if(d.length===0)return;if(d.length===1){let{internal:y,clip:b}=d[0],x=y.sampleTime(),P=o[hh]?.(b.name,x);if(P&&r[yh]?.(P))return;let M=n.sample(b.name,x);e.setPolygons(M);return}let m=0;for(let{internal:y}of d)m+=y.weight;if(m<=0)return;let p=d.map(({internal:y,clip:b})=>({polygons:n.sample(b.name,y.sampleTime()),weight:y.weight/m})),g=p[0].polygons;if(g.length===0)return;let h=g.map((y,b)=>{let x=y.vertices.map((P,M)=>{let C=0,E=0,A=0;for(let{polygons:S,weight:T}of p){let v=S[b];if(!v)continue;let R=v.vertices[M];R&&(C+=R[0]*T,E+=R[1]*T,A+=R[2]*T)}return[C,E,A]});return{...y,vertices:x}});e.setPolygons(h)}function c(){for(let f of t.values())f.stop()}function l(f){let d=Ma(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:i,existingAction:s,update:a,stopAllAction:c,uncacheClip:l,uncacheRoot:u}}var Ta={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},nf={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ph={0:"POINTS",1:"LINES",2:"LINE_LOOP",3:"LINE_STRIP",4:"TRIANGLES",5:"TRIANGLE_STRIP",6:"TRIANGLE_FAN"},Ea=["EXT_meshopt_compression","KHR_meshopt_compression"];function Mh(e){return e===5120||e===5121||e===5122||e===5123}function tf(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Sh(e){let n=e.indexOf(",");if(n<0)throw new Error("parseGltf: malformed data: URI");let t=e.slice(5,n),o=e.slice(n+1);if(!t.includes(";base64")){let s=decodeURIComponent(o),a=new Uint8Array(s.length);for(let c=0;c<s.length;c++)a[c]=s.charCodeAt(c)&255;return a}let r=globalThis.atob(o),i=new Uint8Array(r.length);for(let s=0;s<r.length;s++)i[s]=r.charCodeAt(s);return i}function Ah(e){let n=new DataView(e);if(n.getUint32(0,!0)!==1179937895)throw new Error("parseGltf: not a GLB (bad magic)");let t=n.getUint32(4,!0);if(t!==2)throw new Error(`parseGltf: only glTF v2 supported (got v${t})`);let o=12,r=null,i=null;for(;o<e.byteLength;){let s=n.getUint32(o,!0),a=n.getUint32(o+4,!0),c=o+8;if(a===1313821514){let l=new Uint8Array(e,c,s);r=JSON.parse(tf(l))}else a===5130562&&(i=new Uint8Array(e,c,s));o=c+s}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:i}}function qu(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function Ch(e){let n=qu(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=qu(e.asset?.minVersion);if(e.asset?.minVersion&&(!t||t[0]>2||t[0]===2&&t[1]>0))throw new Error(`parseGltf: glTF asset requires minVersion ${e.asset.minVersion}`)}function Th(e,n,t){let o=e.buffers??[],r=new Set(e.extensionsRequired??[]),i=Ea.some(s=>r.has(s));return o.map((s,a)=>{let c=s.uri;if(c){if(c.startsWith("data:"))return Sh(c);if(t){let l=t(c);if(l instanceof Uint8Array)return l;throw new Error("parseGltf: resolveBuffer returned a Promise; use parseGltf via async if your buffers are external")}throw new Error(`parseGltf: external buffer URI "${c}" \u2014 provide options.resolveBuffer`)}if(a===0&&n)return n;if(i&&Ea.some(l=>s.extensions?.[l]))return new Uint8Array(0);throw new Error(`parseGltf: buffer[${a}] has no uri and no GLB BIN chunk`)})}function Ao(e,n,t){let o=e.bufferViews?.[t],r=o?n[o.buffer]:void 0;if(!o||!r)throw new Error(`parseGltf: bad bufferView ${t}`);let i=o.byteOffset??0;if(i<0||o.byteLength<0||i+o.byteLength>r.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${o.buffer}`);return{buffer:r,view:o}}function of(e,n,t,o){if(e.count<=0)return;let r=e.byteOffset??0,i=r+t*(e.count-1)+o;if(r<0||i>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function rf(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function Eh(e,n,t){if(t||e===5126)return new Float32Array(n);switch(e){case 5120:return new Int8Array(n);case 5121:return new Uint8Array(n);case 5122:return new Int16Array(n);case 5123:return new Uint16Array(n);case 5125:return new Uint32Array(n);default:throw new Error(`parseGltf: unhandled componentType ${e}`)}}function Kr(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Ta[o.componentType],i=nf[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);if(o.sparse||o.normalized||o.bufferView===void 0){let{values:h}=Co(e,n,t);return{array:Eh(o.componentType,h,o.normalized),count:o.count,componentCount:i}}let{buffer:s,view:a}=Ao(e,n,o.bufferView),c=(a.byteOffset??0)+(o.byteOffset??0),l=o.count*i,u=r*i,f=rf(a,u);if(of(o,a,f,u),f===u){let h=s.buffer.slice(s.byteOffset+c,s.byteOffset+c+l*r),y;switch(o.componentType){case 5120:y=new Int8Array(h);break;case 5121:y=new Uint8Array(h);break;case 5122:y=new Int16Array(h);break;case 5123:y=new Uint16Array(h);break;case 5125:y=new Uint32Array(h);break;case 5126:y=new Float32Array(h);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}return{array:y,count:o.count,componentCount:i}}let d;switch(o.componentType){case 5120:d=new Int8Array(l);break;case 5121:d=new Uint8Array(l);break;case 5122:d=new Int16Array(l);break;case 5123:d=new Uint16Array(l);break;case 5125:d=new Uint32Array(l);break;case 5126:d=new Float32Array(l);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}let m=new DataView(s.buffer),p=s.byteOffset+c,g=0;for(let h=0;h<o.count;h++){let y=p+h*f;for(let b=0;b<i;b++)d[g++]=Qr(m,y+b*r,o.componentType)}return{array:d,count:o.count,componentCount:i}}function Qr(e,n,t){switch(t){case 5120:return e.getInt8(n);case 5121:return e.getUint8(n);case 5122:return e.getInt16(n,!0);case 5123:return e.getUint16(n,!0);case 5125:return e.getUint32(n,!0);case 5126:return e.getFloat32(n,!0);default:throw new Error(`parseGltf: unhandled componentType ${t}`)}}function Qu(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 Co(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Ta[o.componentType],i=nf[o.type];if(!r||!i)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);let s=r*i,a=new Array(o.count*i).fill(0);if(o.bufferView!==void 0){let{buffer:c,view:l}=Ao(e,n,o.bufferView),u=c.byteOffset+(l.byteOffset??0)+(o.byteOffset??0),f=rf(l,s);of(o,l,f,s);let d=new DataView(c.buffer),m=0;for(let p=0;p<o.count;p++){let g=u+p*f;for(let h=0;h<i;h++){let y=Qr(d,g+h*r,o.componentType);a[m++]=o.normalized?Qu(y,o.componentType):y}}}if(o.sparse){let c=o.sparse,l=c.indices,u=Ta[l.componentType];if(l.componentType!==5121&&l.componentType!==5123&&l.componentType!==5125)throw new Error(`parseGltf: unhandled sparse index componentType ${l.componentType}`);let{buffer:f,view:d}=Ao(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),p=new DataView(f.buffer),{buffer:g,view:h}=Ao(e,n,c.values.bufferView),y=g.byteOffset+(h.byteOffset??0)+(c.values.byteOffset??0),b=new DataView(g.buffer);for(let x=0;x<c.count;x++){let P=Qr(p,m+x*u,l.componentType);for(let M=0;M<i;M++){let C=Qr(b,y+(x*i+M)*r,o.componentType);a[P*i+M]=o.normalized?Qu(C,o.componentType):C}}}return{values:a,count:o.count,componentCount:i}}function vh(e,n,t){let o=[],r=[],i=globalThis;for(let s of e.images??[]){if(s.uri){if(t&&!s.uri.startsWith("data:"))try{o.push(new i.URL(s.uri,t).href)}catch{o.push(s.uri)}else o.push(s.uri);continue}if(s.bufferView!==void 0){let a;try{let{buffer:f,view:d}=Ao(e,n,s.bufferView),m=d.byteOffset??0;a=f.subarray(m,m+d.byteLength)}catch{o.push("");continue}let c=s.mimeType??"image/png",l=new i.Blob([a],{type:c}),u=i.URL.createObjectURL(l);o.push(u),r.push(u)}else o.push("")}return{urls:o,objectUrls:r}}function Ju(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function Ih(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:Ju(t?.wrapS),t:Ju(t?.wrapT)}}function sf(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function _h(e,n){let t=new Map,o=e.materials??[];for(let r=0;r<o.length;r++){let i=o[r].pbrMetallicRoughness?.baseColorTexture?.index;if(i===void 0)continue;let s=e.textures?.[i],a=s?.source;if(a===void 0)continue;let c=n[a];c&&t.set(r,{url:c,wrap:Ih(e,s),alphaMode:sf(o[r].alphaMode),texCoord:o[r].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function Vh(e,n,t){let o=e?.pbrMetallicRoughness?.baseColorFactor;if(!o||o.length<3)return n;let r=c=>Math.max(0,Math.min(1,c)),i=c=>Math.round(r(c)*255).toString(16).padStart(2,"0"),s=c=>Math.round(r(c)*255),a=t==="opaque"?1:r(o[3]??1);return a<1?`rgba(${s(o[0])}, ${s(o[1])}, ${s(o[2])}, ${Math.round(a*1e3)/1e3})`:`#${i(o[0])}${i(o[1])}${i(o[2])}`}var vt=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function af(e,n){let t=new Array(16);return cf(t,e,n)}function cf(e,n,t){for(let o=0;o<4;o++)for(let r=0;r<4;r++)e[r*4+o]=n[0+o]*t[r*4+0]+n[4+o]*t[r*4+1]+n[8+o]*t[r*4+2]+n[12+o]*t[r*4+3];return e}function Zr(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 lf(e,n,t){let o=e?.[0]??0,r=e?.[1]??0,i=e?.[2]??0,s=n?.[0]??0,a=n?.[1]??0,c=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=s+s,p=a+a,g=c+c,h=s*m,y=s*p,b=s*g,x=a*p,P=a*g,M=c*g,C=l*m,E=l*p,A=l*g;return[(1-(x+M))*u,(y+A)*u,(b-E)*u,0,(y-A)*f,(1-(h+M))*f,(P+C)*f,0,(b+E)*d,(P-C)*d,(1-(h+x))*d,0,o,r,i,1]}function Oh(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():lf(e.translation,e.rotation,e.scale)}function uf(e,n,t){let o=new Array(Math.min(e.length,n.length));for(let r=0;r<o.length;r++)o[r]=e[r]+(n[r]-e[r])*t;return o}function So(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 Rh(e,n,t){let o=So(e),r=So(n),i=o[0]*r[0]+o[1]*r[1]+o[2]*r[2]+o[3]*r[3];if(i<0&&(i=-i,r=[-r[0],-r[1],-r[2],-r[3]]),i>.9995)return So(uf(o,r,t));let s=Math.acos(Math.max(-1,Math.min(1,i))),a=Math.sin(s),c=Math.sin((1-t)*s)/a,l=Math.sin(t*s)/a;return So([o[0]*c+r[0]*l,o[1]*c+r[1]*l,o[2]*c+r[2]*l,o[3]*c+r[3]*l])}function ff(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 mf(e){return e.matrix?e.matrix.slice():lf(e.translation,e.rotation,e.scale)}function Lh(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function df(e,n){let t=e.nodes??[],o=new Array(t.length),r=new Set,i=new Set,s=(c,l)=>{if(c<0||c>=t.length||i.has(c))return;let u=af(l,n[c]??vt);o[c]=u,r.add(c),i.add(c);for(let f of t[c].children??[])s(f,u);i.delete(c)},a=Lh(e);if(a.length>0)for(let c of a)s(c,vt);for(let c=0;c<t.length;c++)r.has(c)||s(c,vt);return o}var pf=Symbol("polycss.gltfAnimationRuntimeInfo"),wh=Symbol.for("polycss.animation.triangleFrameSource");function gf(e,n){return e?e[pf]?.withPolygonFilter(n):void 0}function Ca(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Nh(e,n,t){return Ca(e,n)||Ca(e,t)||Ca(n,t)}function ef(e,n,t,o,r){if(t===void 0)return;let{values:i,count:s,componentCount:a}=Co(e,n,t);if(s!==r||a<1)return;let c=[];for(let l=0;l<s;l++){let u=[];for(let f=0;f<o;f++)u.push(i[l*a+f]??0);c.push(u)}return c}function Dh(e,n,t,o){if(t===void 0)return Array.from({length:o},()=>vt.slice());let{values:r,componentCount:i,count:s}=Co(e,n,t);if(i!==16)throw new Error(`parseGltf: inverseBindMatrices accessor ${t} is not MAT4`);let a=[];for(let c=0;c<o;c++){let l=Math.min(c,s-1);a.push(r.slice(l*16,l*16+16))}return a}function qr(e,n){let t=e.componentCount,o=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(o,o+t)}function Fh(e,n,t){let o=e.input;if(o.length===0)return[];if(o.length===1||n<=o[0])return qr(e,0);let r=o.length-1;if(n>=o[r])return qr(e,r);let i=0,s=r;for(;i+1<s;){let d=i+s>>1;o[d]<=n?i=d:s=d}let a=o[i],c=o[i+1],l=c>a?(n-a)/(c-a):0,u=qr(e,i),f=qr(e,i+1);return e.interpolation==="STEP"?u:t==="rotation"?Rh(u,f,l):uf(u,f,l)}function hf(e,n){let t=[];for(let o=0;o<(e.animations?.length??0);o++){let r=e.animations[o],i=(r.samplers??[]).map(c=>{let l=Co(e,n,c.input),u=Co(e,n,c.output);return{input:l.values,output:u.values,componentCount:u.componentCount,interpolation:c.interpolation??"LINEAR"}}),s=[];for(let c of r.channels??[]){let l=c.target.node,u=c.target.path,f=i[c.sampler];l===void 0||!u||!f||u!=="translation"&&u!=="rotation"&&u!=="scale"||s.push({sampler:f,targetNode:l,path:u})}let a=s.reduce((c,l)=>{let u=l.sampler.input;return Math.max(c,u[u.length-1]??0)},0);t.push({info:{index:o,name:r.name??`animation_${o}`,duration:a,channelCount:s.length},channels:s})}return t}function yf(e,n,t,o){let r=t.info.duration,i=r>0?(o%r+r)%r:Math.max(0,o),s=n.map(a=>({translation:a.translation.slice(),rotation:a.rotation.slice(),scale:a.scale.slice(),matrix:a.matrix?a.matrix.slice():void 0}));for(let a of t.channels){let c=s[a.targetNode];if(!c)continue;let l=Fh(a.sampler,i,a.path);c.matrix=void 0,a.path==="translation"?c.translation=l.slice(0,3):a.path==="rotation"?c.rotation=So(l.slice(0,4)):a.path==="scale"&&(c.scale=l.slice(0,3))}return df(e,s.map(mf))}function Bh(e,n,t,o,r,i){if((e.animations??[]).length===0||t.length===0)return;let a=(e.nodes??[]).map(h=>ff(h)),c=a.map(mf),l=df(e,c),u=(e.skins??[]).map(h=>({joints:h.joints??[],inverseBindMatrices:Dh(e,n,h.inverseBindMatrices,h.joints?.length??0)})),f=hf(e,n),d=f.map(h=>h.info);if(d.length===0)return;let m=h=>{let y=t.map(b=>new Array(b.triangleMask.length).fill(!1));for(let b of h){let x=o[b];if(!x)return;let P=y[x.sourceIndex];if(!P||x.triangleIndex<0||x.triangleIndex>=P.length)return;P[x.triangleIndex]=!0}return y.map((b,x)=>{let P=t[x],M=new Set,C=0;for(let E=0;E+2<P.indices.length;E+=3,C++)b[C]&&(M.add(P.indices[E]),M.add(P.indices[E+1]),M.add(P.indices[E+2]));return{triangleMask:b,activeVertices:Array.from(M).sort((E,A)=>E-A)}})},p=(h,y,b,x,P,M,C,E,A)=>{let S=r(h),T=r(y),v=r(b),R={vertices:[S,T,v],color:x};return P&&(R.texture=P),P&&M&&(R.textureWrap=M),P&&C&&(R.textureAlphaMode=C),E&&(R.doubleSided=!0),A&&(R.uvs=A),R},g=h=>{let y=t.reduce((O,L,D)=>{let _=h?.[D]?.triangleMask??L.triangleMask,w=0;for(let V=0;V<_.length;V++)_[V]&&w++;return O+w},0),b=new Float64Array(Math.max(0,y*9)),x=new Array(y),P=new Array(y).fill(!1),M={polygonCount:0,vertices:b,colors:x,textureFlags:P,solidTriangles:!0},C=t.map(O=>new Array(O.positions.length)),E=u.map(O=>O.joints.map(()=>new Array(16))),A=(O,L)=>{let D=typeof O=="number"?f[O]:f.find(_=>_.info.name===O);return D?yf(e,a,D,L):null},S=(O,L,D,_)=>{let w=D?.activeVertices,V=C[O],j=(G,Z,ee,W)=>{let ie=V[G];ie?(ie[0]=Z,ie[1]=ee,ie[2]=W):V[G]=[Z,ee,W]};if(L.skinIndex!==void 0&&L.joints&&L.weights&&u[L.skinIndex]){let G=u[L.skinIndex],Z=L.joints,ee=L.weights,W=E[L.skinIndex]??[];for(let z=0;z<G.joints.length;z++){let X=G.joints[z],U=_[X],I=G.inverseBindMatrices[z],B=W[z]??(W[z]=new Array(16));W[z]=U&&I?cf(B,U,I):void 0}let ie=z=>{let X=L.positions[z],U=0,I=0,B=0,N=0,H=Z[z]??[],$=ee[z]??[];for(let k=0;k<4;k++){let Q=$[k]??0;if(Q<=0)continue;let ae=Math.round(H[k]??0),se=W[ae];if(!se)continue;let Y=se[0]*X[0]+se[4]*X[1]+se[8]*X[2]+se[12],ne=se[1]*X[0]+se[5]*X[1]+se[9]*X[2]+se[13],le=se[2]*X[0]+se[6]*X[1]+se[10]*X[2]+se[14];U+=Y*Q,I+=ne*Q,B+=le*Q,N+=Q}if(N>0){let k=1/N;j(z,U*k,I*k,B*k)}else j(z,L.meshBindWorld[0]*X[0]+L.meshBindWorld[4]*X[1]+L.meshBindWorld[8]*X[2]+L.meshBindWorld[12],L.meshBindWorld[1]*X[0]+L.meshBindWorld[5]*X[1]+L.meshBindWorld[9]*X[2]+L.meshBindWorld[13],L.meshBindWorld[2]*X[0]+L.meshBindWorld[6]*X[1]+L.meshBindWorld[10]*X[2]+L.meshBindWorld[14])};if(w)for(let z of w)ie(z);else for(let z=0;z<L.positions.length;z++)ie(z)}else{let G=L.meshNode!==null?_[L.meshNode]??L.meshBindWorld:L.meshBindWorld,Z=ee=>{let W=L.positions[ee];j(ee,G[0]*W[0]+G[4]*W[1]+G[8]*W[2]+G[12],G[1]*W[0]+G[5]*W[1]+G[9]*W[2]+G[13],G[2]*W[0]+G[6]*W[1]+G[10]*W[2]+G[14])};if(w)for(let ee of w)Z(ee);else for(let ee=0;ee<L.positions.length;ee++)Z(ee)}return V},T=(O,L)=>{let D=A(O,L);if(!D)return[];let _=[];for(let w=0;w<t.length;w++){let V=t[w],j=h?.[w],G=j?.triangleMask??V.triangleMask,Z=S(w,V,j,D),ee=0;for(let W=0;W+2<V.indices.length;W+=3,ee++){if(!G[ee])continue;let ie=V.indices[W],z=V.indices[W+1],X=V.indices[W+2],U=Z[ie],I=Z[z],B=Z[X];if(!U||!I||!B)continue;let N;if(V.uvs&&V.texture){let $=V.uvs[ie],k=V.uvs[z],Q=V.uvs[X];$&&k&&Q&&(N=[$,k,Q])}let H=p(U,I,B,V.color,V.texture,V.textureWrap,V.textureAlphaMode,V.doubleSided,N);H&&_.push(H)}}return _},v=(O,L)=>{let D=A(O,L);if(!D)return null;b.length<y*9&&(b=new Float64Array(y*9),M.vertices=b),x.length<y&&(x=new Array(y),M.colors=x),P.length<y&&(P=new Array(y).fill(!1),M.textureFlags=P);let _=0,w=0,V=!1;for(let j=0;j<t.length;j++){let G=t[j],Z=h?.[j],ee=Z?.triangleMask??G.triangleMask,W=S(j,G,Z,D),ie=0;for(let z=0;z+2<G.indices.length;z+=3,ie++){if(!ee[ie])continue;let X=G.indices[z],U=G.indices[z+1],I=G.indices[z+2],B=W[X],N=W[U],H=W[I];if(!B||!N||!H)continue;i(B,b,w),i(N,b,w+3),i(H,b,w+6),x[_]=G.color;let $=!!G.texture;P[_]=$,$&&(V=!0),_++,w+=9}}return M.polygonCount=_,M.solidTriangles=!V,M},R={clips:d,sample:T};return R[wh]=v,R[pf]={withPolygonFilter(O){let L=m(O);return L?g(L):void 0}},R};return g()}function Jr(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.materialColors??{},i=n?.materialTextures??{},s=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,a=s.byteLength,c,l=null;if(s.byteLength>=4&&new DataView(s).getUint32(0,!0)===1179937895){let F=Ah(s);c=F.doc,l=F.bin}else c=JSON.parse(tf(new Uint8Array(s)));Ch(c);let u=Th(c,l,n?.resolveBuffer),{urls:f,objectUrls:d}=vh(c,u,n?.baseUrl),m=_h(c,f),p=[],g=new Set,h=new Set(c.extensionsRequired??[]),y=h.has("KHR_mesh_quantization")||(c.extensionsUsed??[]).includes("KHR_mesh_quantization");function b(F,q){g.has(F)||(g.add(F),p.push(q))}function x(F,q){if(F===void 0)return!1;let J=c.accessors?.[F];if(!J)return!1;let te=ue=>c.bufferViews?.[ue]?.extensions?.[q]!==void 0;return!!(J.bufferView!==void 0&&te(J.bufferView)||J.sparse&&(te(J.sparse.indices.bufferView)||te(J.sparse.values.bufferView)))}function P(F){for(let q of Ea)if(h.has(q)&&(F.extensions?.[q]||x(F.indices,q)||Object.values(F.attributes??{}).some(J=>x(J,q))))return q}function M(F,q){if(q instanceof Float32Array)return!0;let J=c.accessors?.[F];return y&&J?.type==="VEC3"&&Mh(J.componentType)}function C(F,q){return(q!==null?c.nodes?.[q]?.weights:void 0)??F.weights??[]}function E(F,q,J,te,ue){let ce=J.targets;if(!ce||ce.length===0)return;let he=C(F,te);if(!he.some(xe=>Number.isFinite(xe)&&xe!==0))return;let Se=Array.from({length:ue},()=>[0,0,0]),ve=!1;for(let xe=0;xe<ce.length;xe++){let K=he[xe]??0;if(!Number.isFinite(K)||K===0)continue;let oe=ce[xe]?.POSITION;if(oe===void 0)continue;let{array:pe,count:qe,componentCount:Ye}=Kr(c,u,oe);if(qe!==ue||Ye<3){b(`morph-position-count:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with mismatched count`);continue}if(!M(oe,pe)){b(`morph-position-type:${q}:${xe}`,`Mesh ${F.name??q}: skipped morph target ${xe} POSITION with unsupported accessor type`);continue}ve=!0;for(let Ge=0;Ge<ue;Ge++){let we=Ge*Ye,Ne=Se[Ge];Ne[0]+=Number(pe[we])*K,Ne[1]+=Number(pe[we+1])*K,Ne[2]+=Number(pe[we+2])*K}}return ve?Se:void 0}let A=[],S=[],T=[],v=(c.meshes??[]).map((F,q)=>F.name??`mesh_${q}`),R=(c.materials??[]).map((F,q)=>F.name??`material_${q}`);function O(F,q){if(q===4)return F;let J=[];if(q===5)for(let te=0;te+2<F.length;te++)J.push(F[te],F[te+1+te%2],F[te+2-te%2]);else if(q===6)for(let te=0;te+2<F.length;te++)J.push(F[te+1],F[te+2],F[0]);return J}function L(F){let q=[];for(let J=0;J+2<F.length;J+=3){let te=F[J],ue=F[J+1],ce=F[J+2];q.push(te,ue,ce,te,ce,ue)}return q}function D(F,q,J){let te=c.meshes?.[F];if(te){if(!Array.isArray(te.primitives)){b(`malformed-primitives:${F}`,`Mesh ${te.name??F}: skipped mesh with non-array primitives`);return}for(let ue=0;ue<te.primitives.length;ue+=1){let ce=te.primitives[ue];if(!ce)continue;let he=ce.mode??4;if(he!==4&&he!==5&&he!==6){let Te=Ph[he]??`mode ${he}`;b(`unsupported-mode:${he}`,`Skipped primitives with unsupported mode ${he} (${Te})`);continue}if(ce.extensions?.KHR_draco_mesh_compression&&h.has("KHR_draco_mesh_compression")){b("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}let Se=P(ce);if(Se){b(Se,`Skipped primitives with unsupported required extension ${Se}`);continue}if(ce.attributes.POSITION===void 0){b(`missing-position:${F}`,`Mesh ${te.name??F}: skipped primitive without POSITION attribute`);continue}let ve=ce.material!==void 0?c.materials?.[ce.material]:void 0,xe=sf(ve?.alphaMode),K=ve?.name,pe=(K?r[K]:void 0)??Vh(ve,o,xe),qe=ve?.doubleSided===!0,Ye=ce.material!==void 0?m.get(ce.material):void 0,Ge=K&&i[K]?i[K]:ce.material!==void 0?Ye?.url:void 0,we=Ge&&ce.material!==void 0?Ye?.wrap:void 0,Ne=Ge?Ye?.alphaMode??xe:void 0,Je=Ge?Ye?.texCoord??0:0,Qe=ce.attributes.POSITION,{array:Mn,count:Sn,componentCount:Gn}=Kr(c,u,Qe);if(!M(Qe,Mn))continue;let Bt=E(te,F,ce,J,Sn),ft=[],An=[];for(let Te=0;Te<Sn;Te++){let ke=Te*Gn,re=Bt?.[Te],fe=[Number(Mn[ke])+(re?.[0]??0),Number(Mn[ke+1])+(re?.[1]??0),Number(Mn[ke+2])+(re?.[2]??0)];ft.push(fe),An.push(Zr(q,fe))}let pn=null,mt=ce.attributes[`TEXCOORD_${Je}`];if(Ge&&mt!==void 0){let{array:Te,count:ke}=Kr(c,u,mt);pn=[];let re=1;Te instanceof Uint8Array?re=1/255:Te instanceof Uint16Array&&(re=1/65535);for(let fe=0;fe<ke;fe++){let me=Te[fe*2]*re,Pe=Te[fe*2+1]*re;pn.push([me,1-Pe])}}let je;if(ce.indices!==void 0){let{array:Te,count:ke}=Kr(c,u,ce.indices);je=[];for(let re=0;re<ke;re++)je.push(Number(Te[re]))}else je=An.map((Te,ke)=>ke);je=O(je,he),qe&&(je=L(je));let en;if((c.animations?.length??0)>0){let Te=ef(c,u,ce.attributes.JOINTS_0,4,Sn),ke=ef(c,u,ce.attributes.WEIGHTS_0,4,Sn);en={sourceIndex:S.length,meshNode:J,meshBindWorld:q,skinIndex:J!==null?c.nodes?.[J]?.skin:void 0,positions:ft,indices:je,triangleMask:[],color:pe,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:pn??void 0,joints:Te,weights:ke},S.push(en)}for(let Te=0;Te+2<je.length;Te+=3){let ke=je[Te],re=je[Te+1],fe=je[Te+2],me=en?en.triangleMask.length:void 0;en&&en.triangleMask.push(!1);let Pe=An[ke],ge=An[re],Fe=An[fe];if(!Pe||!ge||!Fe)continue;let Le;if(pn&&Ge){let $e=pn[ke],ze=pn[re],Ue=pn[fe];$e&&ze&&Ue&&(Le=[$e,ze,Ue])}let Oe=`${F}:${ue}:${J??"root"}`;A.push({v0:Pe,v1:ge,v2:Fe,color:pe,texture:Ge,textureWrap:we,textureAlphaMode:Ne,doubleSided:qe,uvs:Le,simplifySourceVertexKeys:[`${Oe}:${ke}`,`${Oe}:${re}`,`${Oe}:${fe}`],source:en,sourceIndex:en?.sourceIndex,sourceTriangleIndex:me})}}}}function _(F,q,J){if(J.has(F)){b(`recursive-node:${F}`,`Skipped recursive node reference ${F} in glTF scene graph`);return}let te=c.nodes?.[F];if(!te)return;let ue=af(q,Oh(te));typeof te.mesh=="number"&&D(te.mesh,ue,F),J.add(F);for(let ce of te.children??[])_(ce,ue,J);J.delete(F)}function w(F){let q=new Set,J=F.info.duration;for(let te of F.channels)for(let ue of te.sampler.input)!Number.isFinite(ue)||ue<=0||J>0&&ue>=J||q.add(ue);return J>0&&(q.add(J*.25),q.add(J*.5),q.add(J*.75)),Array.from(q).sort((te,ue)=>te-ue).slice(0,128)}function V(F,q){let J=F.source;if(!J||F.sourceTriangleIndex===void 0||J.skinIndex!==void 0)return;let te=F.sourceTriangleIndex*3,ue=J.indices[te],ce=J.indices[te+1],he=J.indices[te+2],Se=ue!==void 0?J.positions[ue]:void 0,ve=ce!==void 0?J.positions[ce]:void 0,xe=he!==void 0?J.positions[he]:void 0;if(!Se||!ve||!xe)return;let K=J.meshNode!==null?q[J.meshNode]??J.meshBindWorld:J.meshBindWorld;return{v0:Zr(K,Se),v1:Zr(K,ve),v2:Zr(K,xe)}}function j(F,q){return F[0]===q[0]&&F[1]===q[1]&&F[2]===q[2]}function G(F){return j(F.v0,F.v1)||j(F.v0,F.v2)||j(F.v1,F.v2)}function Z(){return A.some(F=>!G(F))}function ee(){if(A.length===0||(c.animations?.length??0)===0||Z())return;let F=hf(c,u);if(F.length===0)return;let q=(c.nodes??[]).map(te=>ff(te)),J=new Array(A.length);for(let te of F)for(let ue of w(te)){let ce=yf(c,q,te,ue);for(let he=0;he<A.length;he++){if(J[he])continue;let Se=V(A[he],ce);Se&&!G(Se)&&(J[he]=Se)}}if(J.some(Boolean))for(let te=0;te<A.length;te++){let ue=J[te];ue&&(A[te].v0=ue.v0,A[te].v1=ue.v1,A[te].v2=ue.v2)}}let W=c.scene??0,ie=c.scenes?.[W]?.nodes;if(ie&&ie.length>0)for(let F of ie)_(F,vt,new Set);else{(c.meshes?.length??0)===0&&b("no-gltf-meshes","No glTF meshes found");for(let F=0;F<(c.meshes?.length??0);F++)D(F,vt,null)}ee();let z=kh(d);if(A.length===0)return{polygons:[],objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:0,meshes:v,materials:R,sourceBytes:a}};let X=1/0,U=1/0,I=1/0,B=-1/0,N=-1/0,H=-1/0;for(let F of A)for(let q of[F.v0,F.v1,F.v2])q[0]<X&&(X=q[0]),q[0]>B&&(B=q[0]),q[1]<U&&(U=q[1]),q[1]>N&&(N=q[1]),q[2]<I&&(I=q[2]),q[2]>H&&(H=q[2]);let $=Math.max(B-X,N-U,H-I),k=$>0?t/$:1,Q=n?.center,ae=Q===!0||Q==="center",se=ae?(X+B)*.5:X,Y=ae?(U+N)*.5:U,ne=ae?(I+H)*.5:I,le=F=>Math.round(F*1e3)/1e3,ye=n?.upAxis??"y",Ce=ye==="z"?([F,q,J])=>[le((F-se)*k),le((q-Y)*k),le((J-ne)*k)]:([F,q,J])=>[le((J-ne)*k),le((F-se)*k),le((q-Y)*k)],Ve=ye==="z"?(F,q,J)=>{q[J]=le((F[0]-se)*k),q[J+1]=le((F[1]-Y)*k),q[J+2]=le((F[2]-ne)*k)}:(F,q,J)=>{q[J]=le((F[2]-ne)*k),q[J+1]=le((F[0]-se)*k),q[J+2]=le((F[1]-Y)*k)},Ee=[],Me=0;for(let F of A){let q=Ce(F.v0),J=Ce(F.v1),te=Ce(F.v2),ue=Nh(q,J,te);if(F.source&&F.sourceTriangleIndex!==void 0&&(F.source.triangleMask[F.sourceTriangleIndex]=!ue),ue){Me++;continue}let ce={vertices:[q,J,te],color:F.color};F.texture&&(ce.texture=F.texture),F.texture&&F.textureWrap&&(ce.textureWrap=F.textureWrap),F.texture&&F.textureAlphaMode&&(ce.textureAlphaMode=F.textureAlphaMode),F.doubleSided&&(ce.doubleSided=!0),F.uvs&&(ce.uvs=F.uvs),F.simplifySourceVertexKeys&&(ce.simplifySourceVertexKeys=F.simplifySourceVertexKeys),Ee.push(ce),T.push(F.sourceIndex!==void 0&&F.sourceTriangleIndex!==void 0?{sourceIndex:F.sourceIndex,triangleIndex:F.sourceTriangleIndex}:void 0)}Ee.length===0&&Me>0&&b("all-projected-triangles-degenerate","No non-degenerate glTF triangles remained after normalization");let Re=Bh(c,u,S,T,Ce,Ve);return{polygons:Ee,animation:Re,objectUrls:d,dispose:z,warnings:p,metadata:{triangleCount:Ee.length,meshes:v,materials:R,animations:Re?.clips,sourceBytes:a}}}function kh(e){let n=!1;return()=>{if(n)return;n=!0;let t=globalThis.URL;if(t?.revokeObjectURL)for(let o of e)try{t.revokeObjectURL(o)}catch{}}}var Tf=Symbol("polycss.solidTextureBakedAnimationInfo"),bf=Symbol.for("polycss.animation.triangleFrameSource"),zh=16*1024*1024,Uh=2,Gh=32,$h=2,Xh=.08,Yh=8,jh=128,xf=32,Wh=.045,Hh=10,It=6,Kh=16;function va(e){return e.material?.texture??e.texture}function Zh(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function qh(e,n){return new Promise((t,o)=>{let r=new n,i=!1,s=a=>{i||(i=!0,a())};r.decoding="async",r.onload=()=>s(()=>t(r)),r.onerror=()=>s(()=>o(new Error(`texture load failed: ${e}`))),r.src=e})}async function Qh(e,n,t){try{let o=await qh(e,n.Image),r=Math.max(0,Math.floor(o.naturalWidth||o.width||0)),i=Math.max(0,Math.floor(o.naturalHeight||o.height||0));if(r<=0||i<=0||r*i>t)return null;let s=n.createCanvas();s.width=r,s.height=i;let a=s.getContext("2d",{willReadFrequently:!0});if(!a)return null;a.drawImage(o,0,0,r,i);let c=a.getImageData(0,0,r,i).data;return{width:r,height:i,data:c,lowDetail:Jh(r,i,c)}}catch{return null}}function Pf(e,n,t,o,r,i){let s=(o*n+t)*4,a=(i*n+r)*4;return Math.max(Math.abs((e[s]??0)-(e[a]??0)),Math.abs((e[s+1]??0)-(e[a+1]??0)),Math.abs((e[s+2]??0)-(e[a+2]??0)))}function Jh(e,n,t){let o=Math.max(1,Math.floor(Math.max(e,n)/jh)),r=0,i=0,s=0;for(let a=0;a<n;a+=o)for(let c=0;c<e;c+=o){if(c+o<e){let l=Pf(t,e,c,a,c+o,a);s+=l,r++,l>xf&&i++}if(a+o<n){let l=Pf(t,e,c,a,c,a+o);s+=l,r++,l>xf&&i++}}return r>0&&i/r<=Wh&&s/r<=Hh}function Mf(e,n,t){return Math.max(n,Math.min(t,e))}function Sf(e,n){if(!Number.isFinite(e))return null;switch(n){case"repeat":return e-Math.floor(e);case"mirrored-repeat":{let t=Math.floor(e),o=e-t;return Math.abs(t%2)===1?1-o:o}default:return Math.max(0,Math.min(1,e))}}function ey(e,n,t){let o=n[0],r=1-n[1],i=Sf(o,t?.s),s=Sf(r,t?.t);if(i===null||s===null)return null;let a=Mf(Math.floor(i*e.width),0,e.width-1),l=(Mf(Math.floor(s*e.height),0,e.height-1)*e.width+a)*4;return{r:e.data[l]??0,g:e.data[l+1]??0,b:e.data[l+2]??0,a:e.data[l+3]??255}}function Bn(e,n,t,o,r,i){return[e[0]*o+n[0]*r+t[0]*i,e[1]*o+n[1]*r+t[1]*i]}function ny(e){let[n,t,o]=e;return[Bn(n,t,o,1/3,1/3,1/3),Bn(n,t,o,.8,.1,.1),Bn(n,t,o,.1,.8,.1),Bn(n,t,o,.1,.1,.8),Bn(n,t,o,.45,.45,.1),Bn(n,t,o,.45,.1,.45),Bn(n,t,o,.1,.45,.45)]}function ty(e){let[n,t,o]=e,r=ny(e);for(let i=1;i<It;i++)for(let s=1;s<It-i;s++){let a=It-i-s;a<=0||r.push(Bn(n,t,o,i/It,s/It,a/It))}return r}function Ef(e){if(e.textureTriangles?.length)return e.textureTriangles;let n=e.uvs;if(!n||n.length!==e.vertices.length||n.length<3)return[];let t=[];for(let o=1;o+1<n.length;o++)t.push({uvs:[n[0],n[o],n[o+1]]});return t}function Ia(e,n,t){return Math.abs(e.r-n.r)<=t&&Math.abs(e.g-n.g)<=t&&Math.abs(e.b-n.b)<=t&&Math.abs(e.a-n.a)<=t}function ei(e){let n=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");if(e.a>=255)return`#${n(e.r)}${n(e.g)}${n(e.b)}`;let t=Math.round(Math.max(0,Math.min(255,e.a))/255*1e3)/1e3;return`rgba(${Math.round(e.r)}, ${Math.round(e.g)}, ${Math.round(e.b)}, ${t})`}function vf(e){if(!e)return null;let n=e.trim().toLowerCase(),t=n.match(/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(t){let i=t[1],s=a=>{let c=i.length<=4?i[a]+i[a]:i.slice(a*2,a*2+2);return parseInt(c,16)};return{r:s(0),g:s(1),b:s(2),a:i.length===4||i.length===8?s(3):255}}let o=n.match(/^rgba?\(\s*([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)(?:\s*,\s*([0-9.]+)\s*)?\)$/);if(!o)return null;let r=o[4]===void 0?255:Number(o[4])<=1?Number(o[4])*255:Number(o[4]);return{r:Number(o[1]),g:Number(o[2]),b:Number(o[3]),a:r}}function oy(){return{min:{r:255,g:255,b:255,a:255},max:{r:0,g:0,b:0,a:0},sum:{r:0,g:0,b:0,a:0},colors:new Map,count:0}}function If(e){return`${e.r},${e.g},${e.b},${e.a}`}function Af(e,n){e.min.r=Math.min(e.min.r,n.r),e.min.g=Math.min(e.min.g,n.g),e.min.b=Math.min(e.min.b,n.b),e.min.a=Math.min(e.min.a,n.a),e.max.r=Math.max(e.max.r,n.r),e.max.g=Math.max(e.max.g,n.g),e.max.b=Math.max(e.max.b,n.b),e.max.a=Math.max(e.max.a,n.a),e.sum.r+=n.r,e.sum.g+=n.g,e.sum.b+=n.b,e.sum.a+=n.a;let t=If(n),o=e.colors.get(t);e.colors.set(t,{color:n,count:(o?.count??0)+1}),e.count++}function Cf(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 ry(e){if(e.count<Yh||e.colors.size<=1||e.colors.size>$h)return null;let n=null;for(let r of e.colors.values())(!n||r.count>n.count)&&(n=r);if(!n)return null;let t=e.count-n.count,o=Math.max(1,Math.floor(e.count*Xh));return t<=o?n.color:null}function iy(e,n,t,o){let r=Ef(e);if(r.length===0)return null;let i=oy(),s=e.textureAlphaMode==="opaque"?vf(e.color):null;for(let a of r)for(let c of ty(a.uvs)){let l=ey(n,c,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){s&&Af(i,{...s,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),Af(i,l)}if(i.count===0)return e.textureAlphaMode==="opaque"&&e.color?e.color:null;if(e.textureAlphaMode==="opaque"&&i.max.a===0&&e.color)return e.color;if(Ia(i.min,i.max,t))return ei(Cf(i));if(!o){let a=ry(i);if(a)return ei(a)}return o||!n.lowDetail||!Ia(i.min,i.max,Gh)?null:ei(Cf(i))}function _f(e,n){let{texture:t,textureWrap:o,textureAlphaMode:r,material:i,uvs:s,textureTriangles:a,...c}=e,l=e.uvs?.length===e.vertices.length?e.uvs.map(d=>`uv:${Math.round(d[0]*1e5)},${Math.round(d[1]*1e5)}`):void 0,u=l??e.simplifyVertexKeys,f=e.simplifySourceVertexKeys?.length===e.vertices.length?e.simplifySourceVertexKeys.map((d,m)=>l?`${d}|${l[m]}`:d):e.simplifySourceVertexKeys;return{...c,color:n,...u?{simplifyVertexKeys:u}:{},...f?{simplifySourceVertexKeys:f}:{}}}function sy(e,n){if(n.length<2)return e;let t=[],o=new Map;for(let l of n){let u=vf(e[l]?.color);if(!u||u.a<255)continue;let f=If(u);t.push({index:l,key:f});let d=o.get(f);d?d.count+=1:o.set(f,{color:u,count:1})}if(o.size<2)return e;let r=[],i=new Map,s=[...o.entries()].sort((l,u)=>u[1].count-l[1].count||l[0].localeCompare(u[0]));for(let[l,u]of s){let f=null;for(let d of r)if(Ia(u.color,d,Kh)){f=d;break}f||(f=u.color,r.push(f)),i.set(l,ei(f))}let a=!1,c=e.slice();for(let l of t){let u=i.get(l.key),f=e[l.index];!u||!f||f.color===u||(c[l.index]={...f,color:u},a=!0)}return a?c:e}function ay(e,n){let t=e.slice();for(let o=0;o<n.length;o++){let r=n[o],i=e[r.index];i&&(t[r.index]=_f(i,r.color))}return t}function Vf(e){return e?e[Tf]:void 0}async function Of(e,n={}){if(n.enabled===!1)return null;let t=Zh();if(!t)return null;let o=e.filter(c=>va(c)&&Ef(c).length>0);if(o.length===0)return null;let r=n.maxTexturePixels??zh,i=new Map;await Promise.all(Array.from(new Set(o.map(c=>va(c)))).map(async c=>{i.set(c,await Qh(c,t,r))}));let s=n.colorTolerance??Uh,a=n.colorTolerance!==void 0;return{bake(c){let l=!1,u=[],f=c.map((d,m)=>{let p=va(d);if(!p)return d;let g=i.get(p);if(!g)return d;let h=iy(d,g,s,a);return h?(l=!0,u.push(m),_f(d,h)):d});return l?{polygons:sy(f,u),changed:!0,bakedIndices:u}:{polygons:c,changed:!1,bakedIndices:u}}}}async function Rf(e,n={}){let t=await Of(e,n);return t?t.bake(e).polygons:e}async function ni(e,n={}){let t=await Of(e.polygons,n);if(!t)return e;let o=t.bake(e.polygons);if(!o.changed)return e;let r=[];for(let a of o.bakedIndices){let l=o.polygons[a].color;l&&r.push({index:a,color:l})}let i=e.animation,s=i&&{...i,sample(a,c){return ay(i.sample(a,c),r)}};if(s&&i){let a=i[bf];if(a){let c=new Map(r.map(f=>[f.index,f.color])),l=[],u={polygonCount:0,vertices:new Float64Array(0),colors:l,solidTriangles:!1};s[bf]=(f,d)=>{let m=a(f,d);if(!m)return m;l.length<m.polygonCount&&(l=new Array(m.polygonCount),u.colors=l);let p=m.textureFlags,g=m.solidTriangles===!0||!!p;for(let h=0;h<m.polygonCount;h++){let y=c.get(h);l[h]=y??m.colors?.[h],p?.[h]&&!y&&(g=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=p,u.solidTriangles=g,u}}s[Tf]={source:i,bakedColorEntries:r}}return{...e,polygons:o.polygons,animation:s}}var Lf=Symbol.for("polycss.animation.triangleFrameSource");function cy(e,n){let t=e[n];if(!t)return null;let o=[];for(let r=0;r<t.vertices.length;r++)o.push(n,r);return{rest:t,originalIndex:n,sourceRefs:o}}function ly(e){let n=hn(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((r,i)=>t.set(r,i));let o=[];for(let r of n){let i=t.get(r);if(i===void 0)return[];let s=cy(e,i);if(!s)return[];o.push(s)}return o}function _a(e,n,t=!1){let o=new Array(n.length);for(let r=0;r<n.length;r++){let i=n[r],s=i.sourceRefs,a=new Array(s.length/2);for(let l=0,u=0;l<s.length;l+=2,u++){let d=e[s[l]]?.vertices[s[l+1]];if(!d)return e;let m=d[0],p=d[1],g=d[2];if(!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(g))return e;a[u]=[m,p,g]}let c=t?i.rest.color:e[s[0]??-1]?.color??i.rest.color;o[r]={...i.rest,vertices:a,color:c}}return o}function uy(e,n){let t=new Map;return n.forEach((o,r)=>{t.set(o,r)}),e.map((o,r)=>({...o,sourceRefs:o.sourceRefs.map((i,s)=>s%2===0?t.get(i)??-1:i)}))}function fy(e,n){if(e.length<n.length)return null;let t=new Array(n.length);for(let o=0;o<n.length;o++){let r=e[o],i=n[o];if(!r||r.vertices.length!==i.rest.vertices.length)return null;t[o]={...i.rest,vertices:r.vertices,color:i.rest.color}}return t}function my(e){return!!(e.texture||e.material?.texture)}function wf(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=ly(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let o=Vf(e.animation),r=o?.source??e.animation,i=t.map(b=>b.originalIndex),s=gf(r,i),a=s??r,c=s?uy(t,i):t,l=t.map(b=>b.rest.color),u=t.every(b=>b.rest.vertices.length===3&&!my(b.rest)),f=s&&!o&&t.length===i.length&&t.every((b,x)=>b.rest.vertices.length===3&&b.sourceRefs.length===6&&b.sourceRefs[0]===i[x]&&b.sourceRefs[2]===i[x]&&b.sourceRefs[4]===i[x]),d=a[Lf],m=new Float64Array(t.length*9),p=l.slice(),g=new Array(t.length).fill(!1),h={polygonCount:t.length,vertices:m,colors:p,textureFlags:g,solidTriangles:u},y={...e.animation,sample(b,x){let P=a.sample(b,x);return f?P:s&&o?u&&t.length===i.length?fy(P,t)??_a(P,c,!0):_a(P,c,!0):_a(P,c,!!o)}};return d&&u&&(y[Lf]=(b,x)=>{let P=d(b,x);if(!P)return P;if(s)return P.polygonCount<t.length||P.vertices.length<t.length*9?null:(h.polygonCount=t.length,h.vertices=P.vertices,h.colors=o?l:P.colors,h.textureFlags=o?g:P.textureFlags,h.solidTriangles=o?u:P.solidTriangles===!0,h);m.length<t.length*9&&(m=new Float64Array(t.length*9),h.vertices=m),p.length<t.length&&(p=new Array(t.length),h.colors=p),g.length<t.length&&(g=new Array(t.length).fill(!1),h.textureFlags=g);let M=u&&P.solidTriangles!==!1;for(let C=0;C<c.length;C++){let E=c[C],A=E.sourceRefs;for(let v=0,R=0;v<A.length;v+=2,R++){let O=A[v],L=A[v+1];if(O<0||O>=P.polygonCount)return null;let D=O*9+L*3,_=C*9+R*3;if(D+2>=P.vertices.length)return null;m[_]=P.vertices[D],m[_+1]=P.vertices[D+1],m[_+2]=P.vertices[D+2]}let S=A[0],T=!!P.textureFlags?.[S];g[C]=T,p[C]=o?E.rest.color:P.colors?.[S]??E.rest.color,!o&&T&&(M=!1)}return h.polygonCount=t.length,h.vertices=m,h.colors=p,h.textureFlags=g,h.solidTriangles=o?u:M,h}),{...e,polygons:t.map(b=>b.rest),animation:y,metadata:{...e.metadata,triangleCount:t.length}}}var dy=/^[0-9A-Fa-f]{6}$/,py=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function gy(e){let n=[],t="";for(let o of e.split(`
|
|
2
2
|
`)){let r=o.endsWith("\r")?o.slice(0,-1):o;if(r.endsWith("\\")){t+=`${r.slice(0,-1).trimEnd()} `;continue}n.push(t+r),t=""}return t&&n.push(t.trimEnd()),n}function ti(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.palette??py,i=n?.materialColors??{},s=n?.materialTextures??{},a=[],c=[],l=[],u=[],f=new Map,d=[],m=new Set,p=o,g,h=n?.includeObjects?new Set(n.includeObjects):null,y=n?.excludeObjects?new Set(n.excludeObjects):null,b=null,x=()=>b===null?h===null:!(h&&!h.has(b)||y&&y.has(b)),P=z=>z in i?i[z]:dy.test(z)?`#${z}`:(f.has(z)||(f.set(z,r[u.length%r.length]),u.push(z)),f.get(z)),M=(z,X)=>{m.has(z)||(m.add(z),d.push(X))},C=(z,X)=>{let U=parseInt(z,10);return Number.isFinite(U)?U<0?X+U:U-1:NaN},E=gy(e);for(let z of E)if(!(z.length===0||z.charCodeAt(0)===35)){if(z.startsWith("v ")){let X=z.trim().split(/\s+/);a.push([parseFloat(X[1]),parseFloat(X[2]),parseFloat(X[3])])}else if(z.startsWith("vt ")){let X=z.trim().split(/\s+/);c.push([parseFloat(X[1]),parseFloat(X[2])])}else if(z.startsWith("o "))b=z.trim().slice(2).trim();else if(z.startsWith("usemtl ")){let X=z.trim().split(/\s+/)[1];p=P(X),g=s[X]}else if(z.startsWith("p "))x()&&M("unsupported-point-elements","Skipped OBJ point elements; PolyCSS only renders face polygons");else if(z.startsWith("l "))x()&&M("unsupported-line-elements","Skipped OBJ line elements; PolyCSS only renders face polygons");else if(z.startsWith("f ")){if(!x())continue;let X=z.trim().split(/\s+/).slice(1),U=[],I=[];for(let B of X){let N=B.split("/");U.push(C(N[0],a.length));let H=N[1];if(H&&H.length>0){let $=C(H,c.length);I.push(Number.isFinite($)?$:null)}else I.push(null)}l.push({idx:U,uvIdx:I,color:p,texture:g})}}if(a.length===0||l.length===0)return hy(u,e.length,d);let A=new Set;for(let z of l)for(let X of z.idx)A.add(X);let S=1/0,T=1/0,v=1/0,R=-1/0,O=-1/0,L=-1/0;for(let z of A){let X=a[z];X&&(X[0]<S&&(S=X[0]),X[0]>R&&(R=X[0]),X[1]<T&&(T=X[1]),X[1]>O&&(O=X[1]),X[2]<v&&(v=X[2]),X[2]>L&&(L=X[2]))}let D=Math.max(R-S,O-T,L-v),_=D>0?t/D:1,w=n?.center,V=w===!0||w==="center",j=V?(S+R)*.5:S,G=V?(T+O)*.5:T,Z=V?(v+L)*.5:v,ee=z=>Math.round(z*1e3)/1e3,W=a.map(([z,X,U])=>[ee((U-Z)*_),ee((z-j)*_),ee((X-G)*_)]),ie=[];for(let{idx:z,uvIdx:X,color:U,texture:I}of l)for(let B=1;B<z.length-1;B++){let N=z[0],H=z[B],$=z[B+1],k=W[N],Q=W[H],ae=W[$];if(!k||!Q||!ae||k[0]===Q[0]&&k[1]===Q[1]&&k[2]===Q[2]||k[0]===ae[0]&&k[1]===ae[1]&&k[2]===ae[2]||Q[0]===ae[0]&&Q[1]===ae[1]&&Q[2]===ae[2])continue;let se;if(I){let ne=X[0],le=X[B],ye=X[B+1];if(ne!=null&&le!=null&&ye!=null){let Ce=c[ne],Ve=c[le],Ee=c[ye];Ce&&Ve&&Ee&&(se=[Ce,Ve,Ee])}}let Y={vertices:[k,Q,ae],color:U};I&&(Y.texture=I),se&&(Y.uvs=se),ie.push(Y)}return{polygons:ie,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:ie.length,materials:u,sourceBytes:e.length}}}function hy(e,n,t=[]){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:t,metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var Va=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function oi(e){let n={},t={},o=null;for(let r of e.split(`
|
|
3
3
|
`)){let i=r.trim();if(!(i.length===0||i.charCodeAt(0)===35)){if(i.startsWith("newmtl ")){o=i.slice(7).trim();continue}if(o){if(i.startsWith("Kd ")){let s=i.split(/\s+/),a=parseFloat(s[1]),c=parseFloat(s[2]),l=parseFloat(s[3]);Number.isFinite(a)&&Number.isFinite(c)&&Number.isFinite(l)&&(n[o]=`#${Va(a)}${Va(c)}${Va(l)}`)}else if(i.startsWith("map_Kd ")){let s=i.split(/\s+/),a=s[s.length-1]?.replace(/\\+/g,"/");a&&a!=="map_Kd"&&(t[o]=a)}}}}return{colors:n,textures:t}}var yy=[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 by(e){let n=e>>0&255,t=e>>8&255,o=e>>16&255;return[n,t,o]}function Oa(e){return(e&255).toString(16).padStart(2,"0")}function Ff(e,n,t){return`#${Oa(e)}${Oa(n)}${Oa(t)}`}function xy(e,n,t,o){if(o>=255)return Ff(e,n,t);let r=Math.round(Math.max(0,Math.min(255,o))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function Bf(e){let n=e.match(/^#([0-9a-f]{6})$/i);if(n){let o=n[1];return{rgb:[parseInt(o.slice(0,2),16),parseInt(o.slice(2,4),16),parseInt(o.slice(4,6),16)],alpha:1}}let t=e.match(/^rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)$/i);return t?{rgb:[Number(t[1]),Number(t[2]),Number(t[3])],alpha:Number(t[4])}:null}function kf(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function Nf(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),i=Math.min(n,t,o),s=r-i,a=0;return s!==0&&(r===n?a=60*((t-o)/s%6):r===t?a=60*((o-n)/s+2):a=60*((n-t)/s+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:s/r,value:r}}function Py(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function zf(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=Nf(e),o=Nf(n),r=t.saturation<.08,i=o.saturation<.08;if(r||i)return r===i;let s=Math.min(t.value,o.value)<.16?35:24;return Py(t.hue,o.hue)<=s}function My(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return null;let o=new Map;for(let a of e.keys()){let c=Bf(a);c&&o.set(a,c)}let r=[],i=new Map,s=Array.from(e.entries()).sort((a,c)=>c[1]-a[1]||a[0].localeCompare(c[0]));for(let[a]of s){let c=o.get(a);if(!c){i.set(a,a);continue}let l=null;for(let u of r){if(!zf(c,u.parsed))continue;let f=kf(c,u.parsed);f>t||(!l||f<l.distance)&&(l={color:u.color,distance:f})}l?i.set(a,l.color):(r.push({color:a,parsed:c}),i.set(a,a))}return i}var Sy=[[1,0],[-1,0],[0,1],[0,-1]];function Uf(e,n){return`${e},${n}`}function Ay(e){let n=e.indexOf(",");return[Number(e.slice(0,n)),Number(e.slice(n+1))]}function Cy(e,n,t){return e<=4||(n===1||t===1)&&e<=12?!0:Math.min(n,t)<=2&&Math.max(n,t)>=4&&e<=18}function Ty(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return;let o=new Map,r=i=>(o.has(i)||o.set(i,Bf(i)),o.get(i)??null);for(let i of e.values()){if(i.size<3)continue;let s=new Map;for(let l of i.values())s.set(l,(s.get(l)??0)+1);let a=new Set,c=[];for(let[l,u]of i){if(a.has(l))continue;let f=[l],d=[],m=new Map,p=1/0,g=-1/0,h=1/0,y=-1/0;for(a.add(l);f.length>0;){let C=f.pop();d.push(C);let[E,A]=Ay(C);p=Math.min(p,E),g=Math.max(g,E),h=Math.min(h,A),y=Math.max(y,A);for(let[S,T]of Sy){let v=Uf(E+S,A+T),R=i.get(v);if(R){if(R===u){a.has(v)||(a.add(v),f.push(v));continue}m.set(R,(m.get(R)??0)+1)}}}let b=g-p+1,x=y-h+1;if(!Cy(d.length,b,x)||m.size===0)continue;let P=r(u);if(!P)continue;let M=null;for(let[C,E]of m){let A=s.get(C)??0;if(A<=d.length)continue;let S=r(C);if(!S||!zf(P,S))continue;let T=kf(P,S);if(T>t)continue;let v={color:C,contacts:E,distance:T,count:A};(!M||v.contacts>M.contacts||v.contacts===M.contacts&&v.count>M.count||v.contacts===M.contacts&&v.count===M.count&&v.distance<M.distance||v.contacts===M.contacts&&v.count===M.count&&v.distance===M.distance&&v.color.localeCompare(M.color)<0)&&(M=v)}if(M)for(let C of d)c.push([C,M.color])}for(let[l,u]of c)i.set(l,u)}}var Ey=542658390,vy=new Set(["nTRN","nGRP","nSHP"]),Iy="Skipped MagicaVoxel scene graph transforms; models were flattened into one grid";function ri(e,n){let t=n?.targetSize??60,o=e.byteLength;if(e.byteLength<8)return _t(o,["parseVox: buffer too small to be a valid .vox file"]);let r=new DataView(e);if(r.getUint32(0,!0)!==Ey)return _t(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return _t(o,["parseVox: buffer too small for MAIN chunk"]);if(Df(r,8)!=="MAIN")return _t(o,["parseVox: expected MAIN chunk at offset 8"]);let c=20+r.getUint32(12,!0),l=c+r.getUint32(16,!0),u=[],f=[],d=[],m=null,p=U=>{d.includes(U)||d.push(U)};for(;c<l&&c+12<=e.byteLength;){let U=Df(r,c),I=r.getUint32(c+4,!0),B=r.getUint32(c+8,!0),N=c+12,H=N+I+B;if(U==="SIZE"){if(I>=12&&N+12<=e.byteLength){let $=r.getUint32(N,!0),k=r.getUint32(N+4,!0),Q=r.getUint32(N+8,!0);u.push({sx:$,sy:k,sz:Q})}}else if(U==="XYZI"){if(I>=4&&N+4<=e.byteLength){let $=r.getUint32(N,!0),k=[],Q=Math.min($,Math.floor((I-4)/4));for(let ae=0;ae<Q;ae++){let se=N+4+ae*4;k.push({x:r.getUint8(se),y:r.getUint8(se+1),z:r.getUint8(se+2),colorIndex:r.getUint8(se+3)})}f.push(k)}}else if(U==="RGBA"&&I>=1024&&N+1024<=e.byteLength){m=[];for(let $=0;$<256;$++){let k=N+$*4,Q=r.getUint8(k),ae=r.getUint8(k+1),se=r.getUint8(k+2),Y=r.getUint8(k+3);m.push(xy(Q,ae,se,Y))}}vy.has(U)&&p(Iy),c=H}let g=[],h=new Set;for(let U of f)for(let I of U){if(I.colorIndex===0)continue;let B=`${I.x},${I.y},${I.z}`;h.has(B)||(h.add(B),g.push(I))}if(g.length===0)return _t(o,d);let y=new Map,b=U=>{let I=y.get(U);if(I)return I;let B=U-1,N;if(m!==null)N=m[B]??"#888888";else{let H=yy[U]??0,[$,k,Q]=by(H);N=Ff($,k,Q)}return y.set(U,N),N},x=new Map;for(let U of g){let I=b(U.colorIndex);x.set(I,(x.get(I)??0)+1)}let P=My(x,n?.paletteMergeDistance),M=U=>{let I=b(U);return P?.get(I)??I},C=(U,I,B)=>h.has(`${U},${I},${B}`),E=new Map,A=(U,I,B,N,H)=>{let $=`${U}:${I}`,k=E.get($);k||(k=new Map,E.set($,k)),k.set(Uf(B,N),H)};for(let U of g){let{x:I,y:B,z:N}=U,H=M(U.colorIndex);C(I+1,B,N)||A(0,I+1,B,N,H),C(I-1,B,N)||A(1,I,B,N,H),C(I,B+1,N)||A(2,B+1,I,N,H),C(I,B-1,N)||A(3,B,I,N,H),C(I,B,N+1)||A(4,N+1,I,B,H),C(I,B,N-1)||A(5,N,I,B,H)}Ty(E,n?.colorRegionMergeDistance);let S=new Map;for(let[U,I]of E)for(let[B,N]of I){let H=`${U}:${N}`,$=S.get(H);$||($=new Set,S.set(H,$)),$.add(B)}function T(U){let I=new Set,B=[],N=1/0,H=-1/0,$=1/0,k=-1/0;for(let Q of U){let[ae,se]=Q.split(","),Y=+ae,ne=+se;Y<N&&(N=Y),Y>H&&(H=Y),ne<$&&($=ne),ne>k&&(k=ne)}for(let Q=$;Q<=k;Q++)for(let ae=N;ae<=H;ae++){let se=`${ae},${Q}`;if(!U.has(se)||I.has(se))continue;let Y=1;for(;ae+Y<=H;){let le=`${ae+Y},${Q}`;if(!U.has(le)||I.has(le))break;Y++}let ne=1;e:for(;Q+ne<=k;){for(let le=0;le<Y;le++){let ye=`${ae+le},${Q+ne}`;if(!U.has(ye)||I.has(ye))break e}ne++}for(let le=0;le<ne;le++)for(let ye=0;ye<Y;ye++)I.add(`${ae+ye},${Q+le}`);B.push({u:ae,v:Q,w:Y,h:ne})}return B}let v=(U,I,B,N,H,$)=>{let k=B+H,Q=N+$;switch(U){case 0:return[[I,B,N],[I,k,N],[I,k,Q],[I,B,Q]];case 1:return[[I,k,N],[I,B,N],[I,B,Q],[I,k,Q]];case 2:return[[B,I,N],[B,I,Q],[k,I,Q],[k,I,N]];case 3:return[[k,I,N],[k,I,Q],[B,I,Q],[B,I,N]];case 4:return[[B,N,I],[k,N,I],[k,Q,I],[B,Q,I]];default:return[[B,Q,I],[k,Q,I],[k,N,I],[B,N,I]]}},R=[];for(let[U,I]of S){let B=U.indexOf(":"),N=U.indexOf(":",B+1),H=+U.slice(0,B),$=+U.slice(B+1,N),k=U.slice(N+1);for(let{u:Q,v:ae,w:se,h:Y}of T(I))R.push({vertices:v(H,$,Q,ae,se,Y),color:k})}if(R.length===0)return _t(o,d);let O=1/0,L=1/0,D=1/0,_=-1/0,w=-1/0,V=-1/0;for(let U of R)for(let I of U.vertices)I[0]<O&&(O=I[0]),I[0]>_&&(_=I[0]),I[1]<L&&(L=I[1]),I[1]>w&&(w=I[1]),I[2]<D&&(D=I[2]),I[2]>V&&(V=I[2]);let j=Math.max(_-O,w-L,V-D),G=j>0?t/j:1,Z=G*50,ee=Number.isFinite(Z)&&Z>0?Math.max(1,Math.round(Z))/50:G,W={kind:"magica-vox",cells:g.map(U=>({x:w-(U.y+1),y:U.x-O,z:U.z-D,color:M(U.colorIndex)})),rows:Math.max(0,w-L),cols:Math.max(0,_-O),depth:Math.max(0,V-D),scale:ee,sourceBytes:o},ie=U=>Math.round(U*1e3)/1e3,z=U=>[ie((U[0]-O)*ee),ie((U[1]-L)*ee),ie((U[2]-D)*ee)],X=R.map(({vertices:U,color:I})=>({vertices:U.map(z),color:I}));return{polygons:X,voxelSource:W,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:X.length,sourceBytes:o,voxelCount:g.length}}}function Df(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 _t(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var _y="#888888";var Vy=/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/,it="COLOR=";function Xf(e,n,t){let o=n??t;if(!Number.isFinite(o))throw new Error(`parseStl: ${e} must be finite`);return o}function Oy(e,n,t){let o=Xf(e,n,t);if(o<=0)throw new Error(`parseStl: ${e} must be greater than 0`);return o}function Ry(e){if(e===void 0||e==="z"||e==="y")return e??"z";throw new Error('parseStl: upAxis must be "z" or "y"')}function Ly(e){let n=e??_y;if(typeof n!="string"||n.trim().length===0)throw new Error("parseStl: defaultColor must be a non-empty string");return n}function wy(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 Yf(e){let n=globalThis.TextDecoder;return new n().decode(e)}function ii(e,n){return[e.getFloat32(n,!0),e.getFloat32(n+4,!0),e.getFloat32(n+8,!0)]}function si(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Gf(e){let n=e.trim().split(/\s+/);if(n.length!==3||!n.every(o=>Vy.test(o)))return null;let t=[Number(n[0]),Number(n[1]),Number(n[2])];return si(t)?t:null}function Ny(e){let n="";for(let o of e)o!==0&&(n+=o>=32&&o<=126?String.fromCharCode(o):" ");return n.replace(/\s+/g," ").trim()||void 0}function Ra(e){return Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")}function jf(e,n,t,o=255){if(o>=255)return`#${Ra(e)}${Ra(n)}${Ra(t)}`;let r=Math.round(o/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function La(e){return Math.round(e/31*255)}function Dy(e){for(let n=0;n<80-it.length-4;n+=1){let t=!0;for(let a=0;a<it.length;a+=1)if(e.getUint8(n+a)!==it.charCodeAt(a)){t=!1;break}if(!t)continue;let o=e.getUint8(n+it.length),r=e.getUint8(n+it.length+1),i=e.getUint8(n+it.length+2),s=e.getUint8(n+it.length+3);return{defaultColor:jf(o,r,i,s),alpha:Math.round(s/255*1e3)/1e3,alphaByte:s}}return null}function Fy(e,n){if((e&32768)!==0)return{color:n.defaultColor,usesDefaultColor:!0};let t=La(e&31),o=La(e>>5&31),r=La(e>>10&31);return{color:jf(t,o,r,n.alphaByte),usesDefaultColor:!1}}function By(e){let n=[],t=/^\s*solid(?:\s+([^\r\n]*?))?\s*$/gim,o=/^\s*endsolid\b[^\r\n]*$/gim,r;for(;r=t.exec(e);)n.push({index:r.index,kind:"start",name:(r[1]??"").trim()});for(;r=o.exec(e);)n.push({index:r.index,kind:"end"});return n.sort((i,s)=>i.index-s.index||(i.kind==="end"?-1:1))}function ky(e){let n=Math.min(e.byteLength,1024);for(let t=84;t<n;t+=1){let o=e[t];if(o===0||o<9||o>13&&o<32||o>126)return!0}return!1}function zy(e){let n=Yf(e.subarray(0,Math.min(e.byteLength,512))).trimStart().toLowerCase();return!n.startsWith("solid")&&!n.startsWith("facet")?!1:!ky(e)}function Uy(e){if(e.byteLength<84)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(80,!0),o=84+t*50;if(o===e.byteLength)return{triangleCount:t,declaredTriangleCount:t,trailingBytes:0};if(zy(e))return null;if(o<e.byteLength)return{triangleCount:t,declaredTriangleCount:t,trailingBytes:e.byteLength-o};let r=e.byteLength-84;return r>0&&r%50===0?{triangleCount:r/50,declaredTriangleCount:t,trailingBytes:0}:null}function Gy(e,n,t){let o=new DataView(e.buffer,e.byteOffset,e.byteLength),{triangleCount:r,declaredTriangleCount:i,trailingBytes:s}=n;i!==r&&t.push(`parseStl: binary STL declared ${i} triangles but contains ${r} complete triangle record${r===1?"":"s"}`),s>0&&t.push(`parseStl: ignored ${s} trailing binary byte${s===1?"":"s"}`);let a=Ny(e.subarray(0,80)),c=Dy(o),l=0,u=0,f=[];for(let d=0,m=84;d<r;d+=1,m+=50){let p=ii(o,m),g=[ii(o,m+12),ii(o,m+24),ii(o,m+36)];if(!g.every(si))throw new Error(`parseStl: non-finite coordinate in binary triangle ${d}`);let h=o.getUint16(m+48,!0),y=c?Fy(h,c):null;y&&(y.usesDefaultColor?u+=1:l+=1),f.push({normal:si(p)?p:null,hasIgnoredNormal:!si(p),color:y?.color,vertices:g,hasIgnoredAttribute:!c&&h!==0})}return{format:"binary",facets:f,binaryHeader:a,color:c?{format:"magics",defaultColor:c.defaultColor,alpha:c.alpha,coloredTriangleCount:l,defaultColorTriangleCount:u}:void 0}}function $f(e,n){let t=[],o=/^\s*facet\s+normal\s+([^\r\n]+)([\s\S]*?)^\s*endfacet\b[^\r\n]*$/gim,r=/^\s*vertex\s+([^\r\n]+)/gim,i=/^\s*facet\s+normal\b/gim,s=By(e),a=0,c,l=0;for(;i.exec(e);)l+=1;let u=0,f=0,d=0,m;for(;m=o.exec(e);){for(u+=1;a<s.length&&s[a].index<m.index;){let b=s[a];c=b.kind==="start"?b.name:void 0,a+=1}let p=Gf(m[1]);p||(d+=1);let g=[],h=!1;r.lastIndex=0;let y;for(;y=r.exec(m[2]);){let b=Gf(y[1]);if(!b){h=!0;break}g.push(b)}if(h||g.length!==3){f+=1;continue}t.push({normal:p,hasIgnoredNormal:!p,solidName:c,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:t}}function Vt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function ci(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 wa(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Wf(e){return Math.hypot(e[0],e[1],e[2])}function $y(e){let n=ci(Vt(e[1],e[0]),Vt(e[2],e[0]));return Wf(n)<=1e-8}function ai(e){let n=Wf(e);return n<=1e-8?null:[e[0]/n,e[1]/n,e[2]/n]}function Xy(e){let n=t=>Object.is(t,-0)?0:t;return`${n(e[0])},${n(e[1])},${n(e[2])}`}function Yy(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function Na(e,n){return n?[e.vertices[0],e.vertices[2],e.vertices[1]]:e.vertices}function jy(e,n,t){let o=0;for(let r of n.facets){let[i,s,a]=Na(e[r],t[r]);o+=wa(i,ci(s,a))/6}return o}function Wy(e,n,t){if(n.facets.length<8)return null;let o=0,r=0;for(let s of n.facets){let a=e[s],c=a.normal?ai(a.normal):null;if(!c)continue;let l=Na(a,t[s]),u=ai(ci(Vt(l[1],l[0]),Vt(l[2],l[0])));if(!u)continue;let f=wa(u,c);f>=.95?o+=1:f<=-.95&&(r+=1)}let i=o+r;return i/n.facets.length<.75?null:r/i>=.9?"opposed":o/i>=.9?"aligned":null}function Hy(e){let n=new Map,t=e.map(()=>[]);for(let u=0;u<e.length;u+=1){let f=e[u].vertices.map(Xy);for(let d=0;d<3;d+=1){let m=f[d],p=f[(d+1)%3],g=Yy(m,p),h=n.get(g),y={facetIndex:u,from:m,to:p};h?h.push(y):n.set(g,[y])}}let o=0;for(let u of n.values()){if(u.length>2&&(o+=1),u.length<2)continue;let[f,...d]=u;for(let m of d){let p=f.from===m.from&&f.to===m.to;t[f.facetIndex].push({to:m.facetIndex,flipDiffers:p}),t[m.facetIndex].push({to:f.facetIndex,flipDiffers:p})}}let r=new Array(e.length).fill(!1),i=new Array(e.length).fill(-1),s=[],a=0;for(let u=0;u<e.length;u+=1){if(i[u]>=0)continue;let f=s.length,d={facets:[],conflicts:0,boundaryEdges:0,nonManifoldEdges:0,flippedOutward:!1,flippedToSuppliedNormals:!1};s.push(d),i[u]=f;let m=[u];for(let p=0;p<m.length;p+=1){let g=m[p];d.facets.push(g);for(let h of t[g]){let y=r[g]!==h.flipDiffers;i[h.to]<0?(i[h.to]=f,r[h.to]=y,m.push(h.to)):r[h.to]!==y&&g<h.to&&(d.conflicts+=1,a+=1)}}}for(let u of n.values()){let f=s[i[u[0].facetIndex]];u.length===1?f.boundaryEdges+=1:u.length>2&&(f.nonManifoldEdges+=1)}for(let u of s){if(u.nonManifoldEdges>0||u.conflicts>0){for(let d of u.facets)r[d]=!1;continue}if(u.boundaryEdges>0){if(Wy(e,u,r)==="opposed"){for(let d of u.facets)r[d]=!r[d];u.flippedToSuppliedNormals=!0}continue}if(jy(e,u,r)<-1e-10){for(let d of u.facets)r[d]=!r[d];u.flippedOutward=!0}}let c=0;return{facets:e.map((u,f)=>r[f]?(c+=1,{...u,vertices:Na(u,!0)}):u),repairedCount:c,componentCount:s.length,outwardComponentCount:s.filter(u=>u.flippedOutward).length,suppliedNormalComponentCount:s.filter(u=>u.flippedToSuppliedNormals).length,conflictCount:a,nonManifoldEdgeCount:o}}function Ky(e,n,t,o,r){let i=s=>Math.round(s*1e3)/1e3;return r==="y"?[i((e[2]-n[2])*t+o),i((e[0]-n[0])*t+o),i((e[1]-n[1])*t+o)]:[i((e[0]-n[0])*t+o),i((e[1]-n[1])*t+o),i((e[2]-n[2])*t+o)]}function Zy(e){if(e.every(r=>r.solidName===void 0))return;let n=[],t=e[0]?.solidName??"",o=0;for(let r=1;r<=e.length;r+=1){let i=e[r]?.solidName??"";r<e.length&&i===t||(n.push({name:t,start:o,count:r-o}),t=i,o=r)}return n}function qy(e){if(!e)return;let n=[],t=new Set;for(let o of e)!o.name||t.has(o.name)||(t.add(o.name),n.push(o.name));return n.length>0?n:void 0}function li(e,n){let t=Oy("targetSize",n?.targetSize,60),o=Xf("gridShift",n?.gridShift,1),r=Ly(n?.defaultColor),i=Ry(n?.upAxis),s=[],a=wy(e),c=typeof e=="string"?e.length:a.byteLength;if(c===0||typeof e=="string"&&e.trim().length===0)throw new Error("parseStl: empty input");let l=a?Uy(a):null,u=typeof e=="string"?$f(e,s):l?Gy(a,l,s):$f(Yf(a),s),f=0,d=0,m=0,p=[];for(let A of u.facets){if(A.hasIgnoredAttribute&&(f+=1),A.hasIgnoredNormal&&u.format==="binary"&&(d+=1),$y(A.vertices)){m+=1;continue}p.push(A)}let g=Hy(p),h=0;for(let A of g.facets){let S=ai(ci(Vt(A.vertices[1],A.vertices[0]),Vt(A.vertices[2],A.vertices[0]))),T=A.normal?ai(A.normal):null;S&&T&&wa(S,T)<.95&&(h+=1)}if(f>0&&s.push(`parseStl: ignored non-zero binary attribute byte count on ${f} triangle${f===1?"":"s"}`),d>0&&s.push(`parseStl: ignored ${d} non-finite binary normal${d===1?"":"s"}`),m>0&&s.push(`parseStl: skipped ${m} degenerate triangle${m===1?"":"s"}`),g.repairedCount>0&&s.push(`parseStl: repaired winding on ${g.repairedCount} triangle${g.repairedCount===1?"":"s"}`),g.outwardComponentCount>0&&s.push(`parseStl: oriented ${g.outwardComponentCount} closed component${g.outwardComponentCount===1?"":"s"} outward`),g.suppliedNormalComponentCount>0&&s.push(`parseStl: oriented ${g.suppliedNormalComponentCount} open component${g.suppliedNormalComponentCount===1?"":"s"} from supplied normals`),g.conflictCount>0&&s.push(`parseStl: found ${g.conflictCount} inconsistent shared-edge winding constraint${g.conflictCount===1?"":"s"}`),g.nonManifoldEdgeCount>0&&s.push(`parseStl: found ${g.nonManifoldEdgeCount} non-manifold shared edge${g.nonManifoldEdgeCount===1?"":"s"}`),h>0&&s.push(`parseStl: ${h} supplied normal${h===1?" disagrees":"s disagree"} with triangle winding`),p.length===0)throw u.facets.length===0?new Error(`parseStl: no valid ${u.format} facets`):new Error("parseStl: no valid facets after filtering");let y=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0];for(let A of g.facets)for(let S of A.vertices)for(let T=0;T<3;T+=1)S[T]<y[T]&&(y[T]=S[T]),S[T]>b[T]&&(b[T]=S[T]);let x=Math.max(b[0]-y[0],b[1]-y[1],b[2]-y[2]),P=x>0?t/x:1,M=Zy(g.facets),C=qy(M),E=g.facets.map(A=>({vertices:A.vertices.map(S=>Ky(S,y,P,o,i)),color:A.color??r}));return{polygons:E,objectUrls:[],dispose:()=>{},warnings:s,metadata:{triangleCount:E.length,meshes:C,materials:[],sourceBytes:c,stlHeader:u.binaryHeader,stlColor:u.color,stlSolids:M,stlTopology:{componentCount:g.componentCount,repairedTriangleCount:g.repairedCount,outwardComponentCount:g.outwardComponentCount,suppliedNormalComponentCount:g.suppliedNormalComponentCount,inconsistentSharedEdgeCount:g.conflictCount,nonManifoldSharedEdgeCount:g.nonManifoldEdgeCount}}}}var kn="loadMesh";async function Hf(e,n){let t=n?.solidTextureSamples;return t===!1?e:ni(e,typeof t=="object"?t:void 0)}function Qy(e){let n=e.split("?")[0].split("#")[0],t=n.lastIndexOf(".");return t<0?"":n.slice(t+1).toLowerCase()}async function Kf(e,n){let t=Qy(e);if(t==="mtl")throw new Error(`${kn}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let o=globalThis.fetch;if(!o)throw new Error(`${kn}: no fetch() in this environment`);let r=n?.baseUrl??e;if(t==="obj"){let i=await o(e);if(!i.ok)throw new Error(`${kn}: ${e} \u2192 ${i.status}`);let s=await i.text(),a=n?.objOptions;if(n?.mtlUrl){let u=await o(n.mtlUrl);if(!u.ok)throw new Error(`${kn}: ${n.mtlUrl} \u2192 ${u.status}`);let f=await u.text(),{colors:d,textures:m}=oi(f),p={},g=globalThis.URL,h=globalThis.document?.baseURI,y=n.mtlUrl;if(g&&h)try{y=new g(n.mtlUrl,h).toString()}catch{}for(let[b,x]of Object.entries(m)){if(g)try{p[b]=new g(x,y).toString();continue}catch{}let P=n.mtlUrl.lastIndexOf("/"),M=P>=0?n.mtlUrl.slice(0,P+1):"";p[b]=x.startsWith("/")||/^https?:\/\//.test(x)?x:M+x}a={...a??{},materialColors:{...d,...a?.materialColors??{}},materialTextures:{...p,...a?.materialTextures??{}}}}let c=ti(s,a),l=await Hf(c,n);return Qn(l,{meshResolution:n?.meshResolution,source:c})}if(t==="glb"||t==="gltf"){let i=await o(e);if(!i.ok)throw new Error(`${kn}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer(),a=Jr(s,{baseUrl:r,...n?.gltfOptions??{}}),c=await Hf(a,n);return Qn(c,{meshResolution:n?.meshResolution,source:a})}if(t==="vox"){let i=await o(e);if(!i.ok)throw new Error(`${kn}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer();return Qn(ri(s,n?.voxOptions),{meshResolution:n?.meshResolution})}if(t==="stl"){let i=await o(e);if(!i.ok)throw new Error(`${kn}: ${e} \u2192 ${i.status}`);let s=await i.arrayBuffer();return Qn(li(s,n?.stlOptions),{meshResolution:n?.meshResolution})}throw new Error(`${kn}: unsupported extension ".${t}" (supported: obj, glb, gltf, vox, stl)`)}function Be(e,n){if(Object.is(e,0)||Object.is(e,-0))return"0";if(e===1)return"1";if(e===-1)return"-1";let t=Nr[n]??10**n,o=Math.round(e*t)/t;return Object.is(o,0)||Object.is(o,-0)?"0":String(o)}function Zf(e,n=mo){let t=Be(e,n);return t==="0"?"0":`${t}px`}function mn(e,n=bn){if(e.length===0)return"";let t=Be(e[0],n);for(let o=1;o<e.length;o++)t+=`,${Be(e[o],n)}`;return t}function qf(e,n,t,o,r=bn){return ui(e[0],e[1],e[2],n[0],n[1],n[2],t[0],t[1],t[2],o[0],o[1],o[2],r)}function ui(e,n,t,o,r,i,s,a,c,l,u,f,d=bn){if(d===3){let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,g=Math.round(t*1e3)/1e3||0,h=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(i*1e3)/1e3||0,x=Math.round(s*1e3)/1e3||0,P=Math.round(a*1e3)/1e3||0,M=Math.round(c*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,E=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`${m},${p},${g},0,${h},${y},${b},0,${x},${P},${M},0,${C},${E},${A},1`}return`${Be(e,d)},${Be(n,d)},${Be(t,d)},0,${Be(o,d)},${Be(r,d)},${Be(i,d)},0,${Be(s,d)},${Be(a,d)},${Be(c,d)},0,${Be(l,d)},${Be(u,d)},${Be(f,d)},1`}function fi(e,n,t,o,r,i,s,a,c,l,u,f,d=bn){if(d!==3)return`matrix3d(${ui(e,n,t,o,r,i,s,a,c,l,u,f,d)})`;let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,g=Math.round(t*1e3)/1e3||0,h=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,b=Math.round(i*1e3)/1e3||0,x=Math.round(s*1e3)/1e3||0,P=Math.round(a*1e3)/1e3||0,M=Math.round(c*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,E=Math.round(u*1e3)/1e3||0,A=Math.round(f*1e3)/1e3||0;return`matrix3d(${m},${p},${g},0,${h},${y},${b},0,${x},${P},${M},0,${C},${E},${A},1)`}function Ot(e,n,t,o=0,r=0){let i=e.matrix.split(",").map(d=>Number(d));if(i.length!==16||i.some(d=>!Number.isFinite(d)))return e.matrix;let s=i[0],a=i[1],c=i[2],l=i[4],u=i[5],f=i[6];return i[0]*=n,i[1]*=n,i[2]*=n,i[4]*=t,i[5]*=t,i[6]*=t,i[12]+=o*s+r*l,i[13]+=o*a+r*u,i[14]+=o*c+r*f,mn(i)}function Qf(e,n){return Ot(e,n.width/Pn,n.height/Pn,n.minX,n.minY)}function Da(e){let n=e.seamBleedInsets??{left:0,right:0,top:0,bottom:0},t=e.canvasW||1,o=e.canvasH||1;return Ot(e,(t+n.left+n.right)/xn,(o+n.top+n.bottom)/xn,-n.left,-n.top)}function Rt(e,n,t=n){let o=e.matrix.split(",").map(r=>Number(r));return o.length!==16||o.some(r=>!Number.isFinite(r))?e.canonicalMatrix:(o[0]*=e.canvasW/n,o[1]*=e.canvasW/n,o[2]*=e.canvasW/n,o[4]*=e.canvasH/t,o[5]*=e.canvasH/t,o[6]*=e.canvasH/t,mn(o))}function Ln(e,n=wr){let t=Be(e,n);return Number(t)===0?"0":`${t}%`}function Jf(e,n=bn){return`matrix3d(${e.split(",").map(t=>{let o=Number(t.trim());return Number.isFinite(o)?Be(o,n):t.trim()}).join(",")})`}function em(e,n=mo){let t=Be(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function nm(e){return`matrix3d(${Da(e)})`}function dn(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function zn(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let s=1;s+1<e.length;s++){let a=e[s],c=e[s+1],l=[a[0]-n[0],a[1]-n[1],a[2]-n[2]],u=[c[0]-n[0],c[1]-n[1],c[2]-n[2]];t-=l[1]*u[2]-l[2]*u[1],o-=l[2]*u[0]-l[0]*u[2],r-=l[0]*u[1]-l[1]*u[0]}let i=Math.hypot(t,o,r);return i<=de?null:(t/=i,o/=i,r/=i,[t,o,r])}function Lt(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],i=e[(t+2)%e.length],s=(r[0]-o[0])*(i[1]-r[1])-(r[1]-o[1])*(i[0]-r[0]);if(Math.abs(s)<=de)return!1;let a=Math.sign(s);if(n===0)n=a;else if(a!==n)return!1}return!0}function mi(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function di(e,n,t,o){let r=n[0]-e[0],i=n[1]-e[1],s=o[0]-t[0],a=o[1]-t[1],c=r*a-i*s;if(Math.abs(c)<=de)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*s)/c;return[e[0]+f*r,e[1]+f*i]}function tm(e,n,t,o,r,i,s,a){let c=t-e,l=o-n,u=s-r,f=a-i,d=c*f-l*u;if(Math.abs(d)<=de)return null;let m=r-e,p=i-n,g=(m*f-p*u)/d;return[e+g*c,n+g*l]}function st(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let s=0;s<e.length;s+=2)t+=e[s],o+=e[s+1];t/=r,o/=r;let i=e.slice();for(let s=0;s<i.length;s+=2){let a=i[s]-t,c=i[s+1]-o,l=Math.hypot(a,c);l<=Ae||(i[s]+=a/l*n,i[s+1]+=c/l*n)}return i}function at(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let c=0;c<e.length;c+=2)t.push([e[c],e[c+1]]);if(!Lt(t))return st(e,n);let o=mi(t);if(Math.abs(o)<=de)return st(e,n);let r=o>0?1:-1,i=[];for(let c=0;c<t.length;c++){let l=t[c],u=t[(c+1)%t.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=de)return st(e,n);let p=r*(d/m)*n,g=r*(-f/m)*n;i.push({a:[l[0]+p,l[1]+g],b:[u[0]+p,u[1]+g]})}let s=[],a=Math.max(2,n*4);for(let c=0;c<t.length;c++){let l=i[(c+t.length-1)%t.length],u=i[c],f=di(l.a,l.b,u.a,u.b);if(!f)return st(e,n);let d=t[c],m=f[0]-d[0],p=f[1]-d[1],g=Math.hypot(m,p);g>a?s.push(d[0]+m/g*a,d[1]+p/g*a):s.push(f[0],f[1])}return s}function wt(e,n){if(e.length<6||e.length%2!==0)return e;let t=e.length/2;if(n.length!==t)return e;let o=n.map(f=>typeof f=="number"&&Number.isFinite(f)?Math.max(0,f):0),r=Math.max(0,...o);if(r<=0)return e;if(o.every(f=>Math.abs(f-o[0])<=de))return at(e,o[0]);let i=[];for(let f=0;f<e.length;f+=2)i.push([e[f],e[f+1]]);if(!Lt(i))return e;let s=mi(i);if(Math.abs(s)<=de)return e;let a=s>0?1:-1,c=[];for(let f=0;f<i.length;f++){let d=i[f],m=i[(f+1)%i.length],p=m[0]-d[0],g=m[1]-d[1],h=Math.hypot(p,g);if(h<=de)return e;let y=o[f],b=a*(g/h)*y,x=a*(-p/h)*y;c.push({a:[d[0]+b,d[1]+x],b:[m[0]+b,m[1]+x]})}let l=[],u=Math.max(2,r*4);for(let f=0;f<i.length;f++){let d=c[(f+i.length-1)%i.length],m=c[f],p=di(d.a,d.b,m.a,m.b);if(!p)return e;let g=i[f],h=p[0]-g[0],y=p[1]-g[1],b=Math.hypot(h,y);b>u?l.push(g[0]+h/b*u,g[1]+y/b*u):l.push(p[0],p[1])}return l}function To(e,n,t,o,r,i,s){if(s<=0)return[e,n,t,o,r,i];let a=(e*o-n*t+t*i-o*r+r*n-i*e)/2,c=()=>st([e,n,t,o,r,i],s);if(Math.abs(a)<=de)return c();let l=a>0?1:-1,u=t-e,f=o-n,d=Math.sqrt(u*u+f*f),m=r-t,p=i-o,g=Math.sqrt(m*m+p*p),h=e-r,y=n-i,b=Math.sqrt(h*h+y*y);if(d<=de||g<=de||b<=de)return c();let x=l*(f/d)*s,P=l*(-u/d)*s,M=e+x,C=n+P,E=t+x,A=o+P,S=l*(p/g)*s,T=l*(-m/g)*s,v=t+S,R=o+T,O=r+S,L=i+T,D=l*(y/b)*s,_=l*(-h/b)*s,w=r+D,V=i+_,j=e+D,G=n+_,Z=j-w,ee=G-V,W=E-M,ie=A-C,z=Z*ie-ee*W;if(Math.abs(z)<=de)return c();let X=M-w,U=C-V,I=(X*ie-U*W)/z,B=w+I*Z,N=V+I*ee,H=E-M,$=A-C,k=O-v,Q=L-R,ae=H*Q-$*k;if(Math.abs(ae)<=de)return c();let se=v-M,Y=R-C,ne=(se*Q-Y*k)/ae,le=M+ne*H,ye=C+ne*$,Ce=O-v,Ve=L-R,Ee=j-w,Me=G-V,Re=Ce*Me-Ve*Ee;if(Math.abs(Re)<=de)return c();let F=w-v,q=V-R,J=(F*Me-q*Ee)/Re,te=v+J*Ce,ue=R+J*Ve,ce=Math.max(2,s*4),he=B-e,Se=N-n,ve=Math.sqrt(he*he+Se*Se);ve>ce&&(B=e+he/ve*ce,N=n+Se/ve*ce);let xe=le-t,K=ye-o,oe=Math.sqrt(xe*xe+K*K);oe>ce&&(le=t+xe/oe*ce,ye=o+K/oe*ce);let pe=te-r,qe=ue-i,Ye=Math.sqrt(pe*pe+qe*qe);return Ye>ce&&(te=r+pe/Ye*ce,ue=i+qe/Ye*ce),[B,N,le,ye,te,ue]}function pi(e,n,t,o){let r=e+n;if(o<=0||t<=de||r<=de||!Number.isFinite(e+n+t+o))return To(e,0,0,t,r,t,o);let i=Math.sqrt(e*e+t*t),s=Math.sqrt(n*n+t*t);if(i<=de||s<=de)return To(e,0,0,t,r,t,o);let a=-o*t/i,c=-o*e/i,l=o*t/s,u=-o*n/s,f=e+a,d=c,m=r+l,p=t+u,g=-t*r;if(Math.abs(g)<=de)return To(e,0,0,t,r,t,o);let h=f-m,y=d-p,b=(h*t+y*e)/g,x=m-b*n,P=p-b*t,M=-o*(e+i)/t,C=t+o,E=r+o*(n+s)/t,A=C,S=Math.max(2,o*4),T=x-e,v=P,R=Math.sqrt(T*T+v*v);R>S&&(x=e+T/R*S,P=v/R*S);let O=Math.sqrt(M*M+o*o);O>S&&(M=M/O*S,C=t+o/O*S);let L=E-r,D=Math.sqrt(L*L+o*o);return D>S&&(E=r+L/D*S,A=t+o/D*S),[x,P,M,C,E,A]}function Eo(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=dn(n.vertices,t,o),i=zn(r);if(!i)return null;let s=e.screenPts[0],a=e.screenPts[1],c=e.screenPts[2],l=e.screenPts[3],u=e.screenPts[4],f=e.screenPts[5],d=c-s,m=l-a,p=u-s,g=f-a,h=d*g-m*p;if(Math.abs(h)<=de)return null;let y=r[0],b=r[1],x=r[2],P=[b[0]-y[0],b[1]-y[1],b[2]-y[2]],M=[x[0]-y[0],x[1]-y[1],x[2]-y[2]],C=[(P[0]*g-m*M[0])/h,(P[1]*g-m*M[1])/h,(P[2]*g-m*M[2])/h],E=[(d*M[0]-P[0]*p)/h,(d*M[1]-P[1]*p)/h,(d*M[2]-P[2]*p)/h],A=y[0]-C[0]*s-E[0]*a,S=y[1]-C[1]*s-E[1]*a,T=y[2]-C[2]*s-E[2]*a;return{normal:i,xAxis:C,yAxis:E,tx:A,ty:S,tz:T}}function gi(e){return Math.max(0,Math.min(6,Math.floor(e??bn)))}function om(e){return`${e[0]},${e[1]},${e[2]}`}function rm(e,n){let t=om(e),o=om(n);return t<o?`${t}|${o}`:`${o}|${t}`}function im(e){let n=new Map;for(let o=0;o<e.length;o++){let r=e[o].vertices;if(!(!r||r.length<3||!e[o].texture))for(let i=0;i<r.length;i++){let s=rm(r[i],r[(i+1)%r.length]),a=n.get(s),c={polygon:o,edge:i};a?a.push(c):n.set(s,[c])}}let t=e.map(()=>new Set);for(let o of n.values())if(!(o.length<2))for(let r=0;r<o.length;r++)for(let i=r+1;i<o.length;i++)t[o[r].polygon].add(o[r].edge),t[o[i].polygon].add(o[i].edge);return t.map(o=>o.size>0?o:void 0)}function vo(e,n){return typeof e=="number"&&Number.isFinite(e)?Math.max(0,e):n}function hi(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function Io(e,n,t){if(t<=0||e.length<6||e.length%2!==0)return 0;let o=e.length/2;if(n<0||n>=o)return 0;let r=[];for(let A=0;A<e.length;A+=2)r.push([e[A],e[A+1]]);let[i,s]=r[n],[a,c]=r[(n+1)%o],l=a-i,u=c-s,f=Math.hypot(l,u);if(f<=Ae)return 0;let d=[],m=Number.POSITIVE_INFINITY;for(let A=0;A<o;A+=1){if(A===n||A===(n+1)%o)continue;let[S,T]=r[A],v=Math.abs((S-i)*u-(T-s)*l)/f;v>Ae&&(m=Math.min(m,v))}Number.isFinite(m)&&d.push(m*.5);let p=r[(n+o-1)%o],g=r[(n+2)%o],h=p[0]-i,y=p[1]-s,b=g[0]-a,x=g[1]-c,P=Math.hypot(h,y),M=Math.hypot(b,x);if(P>Ae){let A=Math.abs(l*y-u*h)/(f*P);A>Ae&&d.push(P*A)}if(M>Ae){let A=Math.abs(-l*x- -u*b)/(f*M);A>Ae&&d.push(M*A)}let C=d.filter(A=>Number.isFinite(A)&&A>0);if(C.length===0)return Number.isFinite(t)?Math.max(0,t):0;let E=Math.min(...C);return Math.max(0,Math.min(Number.isFinite(t)?t:E,E))}function yi(e,n,t){if(!n?.size||t===void 0)return;let o=new Map;for(let r of n){let i=Io(e,r,t);i>0&&o.set(r,i)}return o.size>0?o:void 0}function bi(e,n){return e<3||!n?.size?null:Array.from({length:e},(t,o)=>Math.max(0,n.get(o)??0))}function xi(e,n){if(!n?.size||e.length<6||e.length%2!==0)return;let t=e.length/2,o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(let l=0;l<e.length;l+=2){let u=e[l],f=e[l+1];o=Math.min(o,u),r=Math.min(r,f),i=Math.max(i,u),s=Math.max(s,f)}if(!Number.isFinite(o+r+i+s))return;let a=Math.max(Ae*8,.25),c={left:0,right:0,top:0,bottom:0};for(let[l,u]of n){let f=Math.max(0,u);if(f<=0||l<0||l>=t)continue;let d=l*2,m=(l+1)%t*2,p=e[d],g=e[d+1],h=e[m],y=e[m+1];Math.abs(p-h)<=a?Math.abs(p-o)<=a&&Math.abs(h-o)<=a?c.left=Math.max(c.left,f):Math.abs(p-i)<=a&&Math.abs(h-i)<=a&&(c.right=Math.max(c.right,f)):Math.abs(g-y)<=a&&(Math.abs(g-r)<=a&&Math.abs(y-r)<=a?c.top=Math.max(c.top,f):Math.abs(g-s)<=a&&Math.abs(y-s)<=a&&(c.bottom=Math.max(c.bottom,f)))}return c.left||c.right||c.top||c.bottom?c:void 0}function Jy(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function eb(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=dn(e.vertices,n,t),r=zn(o);return r?{normal:r,planeD:Jy(r,o[0])}:null}function nb(e,n){return(e.material?.key??e.color??"")===(n.material?.key??n.color??"")&&e.color===n.color}function sm(e,n={}){return new Set(Fa(e,n).keys())}function Fa(e,n={}){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(c=>eb(c,t,o)),i=new Map;for(let c=0;c<e.length;c++){let l=e[c].vertices;if(!(!l||l.length<3))for(let u=0;u<l.length;u++){let f=rm(l[u],l[(u+1)%l.length]),d=i.get(f),m={polygon:c,edge:u};d?d.push(m):i.set(f,[m])}}let s=new Map,a=(c,l)=>{let u=s.get(c);u?u.add(l):s.set(c,new Set([l]))};for(let c of i.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l],d=c[u],m=f.polygon,p=d.polygon;!r[m]||!r[p]||nb(e[m],e[p])&&(a(m,f.edge),a(p,d.edge))}return s}function tb(e,n,t,o,r,i){let s=(e-t)*(i-o)-(n-o)*(r-t);return Math.abs(s)>go?!1:(e-t)*(e-r)+(n-o)*(n-i)<=go}function Ba(e,n=po,t=po){let o=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){let[s,a]=e[r],[c,l]=e[i];if(tb(n,t,s,a,c,l))return!0;a>t!=l>t&&n<(c-s)*(t-a)/(l-a)+s&&(o=!o)}return o}function ka(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(let l=0;l<e.length;l+=2){let u=e[l],f=e[l+1];!Number.isFinite(u)||!Number.isFinite(f)||(o=Math.min(o,u),r=Math.min(r,f),i=Math.max(i,u),s=Math.max(s,f))}let a=i-o,c=s-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(a)||!Number.isFinite(c)||a<=de||c<=de?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:a,height:c}}function Nt(e){let n=e.bleedRatio??1,t=kr*n,o=e.canvasW||1,r=e.canvasH||1,i=t>0?at(e.screenPts,t):e.screenPts,s=t>0?ka(i,o,r):{minX:0,minY:0,width:o,height:r},a=[];for(let c=0;c<i.length;c+=2){let l=Math.max(0,Math.min(100,(i[c]-s.minX)/s.width*100)),u=Math.max(0,Math.min(100,(i[c+1]-s.minY)/s.height*100));a.push([l,u])}return{bounds:s,points:a}}function za(e){let n=[];for(let t of e){let o=n[n.length-1];o&&Math.hypot(o[0]-t[0],o[1]-t[1])<=ho||n.push(t)}if(n.length>1){let t=n[0],o=n[n.length-1];Math.hypot(t[0]-o[0],t[1]-o[1])<=ho&&n.pop()}return n}function Ua([e,n]){let t=new Set;return Math.abs(e)<=tn&&t.add("left"),Math.abs(e-100)<=tn&&t.add("right"),Math.abs(n)<=tn&&t.add("top"),Math.abs(n-100)<=tn&&t.add("bottom"),t.size>0?t:null}function Ga(e,n){for(let t of e)if(n.has(t))return!0;return!1}function $a(e,n,t,o){let r=(i,s,a)=>{let c=n.has(s)?e:o.has(s)?t:null,l=n.has(a)?e:o.has(a)?t:null;if(!c||!l)return null;let u=(()=>{switch(i){case"topLeft":return{x:c[0],y:l[1]};case"topRight":return{x:100-c[0],y:l[1]};case"bottomRight":return{x:100-c[0],y:100-l[1]};case"bottomLeft":return{x:c[0],y:100-l[1]}}})();return u.x>tn&&u.y>tn&&u.x<100-tn&&u.y<100-tn?[i,u]:null};return(n.has("top")||o.has("top"))&&(n.has("left")||o.has("left"))?r("topLeft","top","left"):(n.has("top")||o.has("top"))&&(n.has("right")||o.has("right"))?r("topRight","top","right"):(n.has("bottom")||o.has("bottom"))&&(n.has("right")||o.has("right"))?r("bottomRight","bottom","right"):(n.has("bottom")||o.has("bottom"))&&(n.has("left")||o.has("left"))?r("bottomLeft","bottom","left"):null}function Pi(e){if(e.texture||ct(e)||Un(e))return null;let n=Nt(e),t=za(n.points);if(t.length<4)return null;let o=t.map(Ua);if(o.some(s=>!s))return null;let r={},i=0;for(let s=0;s<t.length;s+=1){let a=o[s],c=o[(s+1)%t.length];if(Ga(a,c))continue;let l=$a(t[s],a,t[(s+1)%t.length],c);if(!l)return null;let[u,f]=l,d=r[u];if(d&&(Math.abs(d.x-f.x)>tn||Math.abs(d.y-f.y)>tn))return null;r[u]=f,i+=1}return i>0?{bounds:n.bounds,radii:r}:null}function ob([e,n]){return`${Ln(e)} ${Ln(n)}`}function rb(e){return`polygon(${e.map(ob).join(",")})`}function ib(e){if(Ba(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[s,a]of e)n+=s,t+=a;let r=Ln(Math.max(0,Math.min(100,n/o))),i=Ln(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${i})`}function Mi(e){return`${rb(e)} ${ib(e)}`}function am(e){return Mi(Nt(e).points)}function Xa(e,n){return Ot(e,n.width/Pn,n.height/Pn,n.minX,n.minY)}function cm(e){let n=Nt(e);return`matrix3d(${Xa(e,n.bounds)})`}function lm(e){let n=Nt(e);return[`transform:matrix3d(${Xa(e,n.bounds)})`,`border-shape:${Mi(n.points)}`].join(";")}function um(e,n){let t=[`transform:matrix3d(${Xa(e,n.bounds)})`,`width:${Pn}px`,`height:${Pn}px`,"border:0","box-sizing:border-box","background:currentColor"];for(let[o,r]of Object.entries(n.radii)){let i=o.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);t.push(`border-${i}-radius:${Ln(r.x)} ${Ln(r.y)}`),t.push(`corner-${i}-shape:bevel`)}return t.join(";")}function _o(e){return e.textureImageSource??e.material?.imageSource}function Si(e){return e.material?.texture??e.texture??e.textureImageSource?.url??e.material?.imageSource?.url}function Vo(e,n={}){let t=_o(e);return{...n,...e.material?.presentation,...t?.imageRendering?{imageRendering:t.imageRendering}:null,...e.texturePresentation}}function fm(e,n){return Vo(e,{imageRendering:n}).imageRendering??"auto"}function mm(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function Oo(e){let n=e?.maxWeightRatio,t=Math.max(0,mm(e?.denomEps,zr)),o=typeof n=="number"&&Number.isFinite(n)&&n>0?Math.max(1,n):Ur,r=Math.max(0,mm(e?.bleed,Gr));return{denomEps:t,maxWeightRatio:o,bleed:r,disableGuards:e?.disableGuards===!0}}function Ai(e,n){if(e.length!==4||!Lt(e))return null;let[t,o,r,i]=e,s=t[0]-o[0]+r[0]-i[0],a=t[1]-o[1]+r[1]-i[1],c=o[0]-r[0],l=i[0]-r[0],u=o[1]-r[1],f=i[1]-r[1],d=c*f-u*l;if(Math.abs(d)<=de)return null;let m=(s*f-a*l)/d,p=(c*a-u*s)/d,g=[1,1+m,1+m+p,1+p];if(g.some(b=>!Number.isFinite(b)))return null;let h=Math.min(...g),y=Math.max(...g);return!n.disableGuards&&(h<=n.denomEps||y/h>n.maxWeightRatio)?null:{g:m,h:p,w1:1+m,w3:1+p}}function Ro(e,n,t,o,r,i,s,a,c){if(e.length!==8)return null;let l=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!Ai(l,a))return null;let u=bi(4,c),f=u?wt(e,u):at(e,a.bleed),d=[[f[0],f[1]],[f[2],f[3]],[f[4],f[5]],[f[6],f[7]]],m=Ai(d,a);if(!m)return null;let{g:p,h:g,w1:h,w3:y}=m,[b,x,,P]=d,M=[r+b[0]*n[0]+b[1]*t[0],i+b[0]*n[1]+b[1]*t[1],s+b[0]*n[2]+b[1]*t[2]],C=([A,S],T)=>[(T-1)*r+(T*A-b[0])*n[0]+(T*S-b[1])*t[0],(T-1)*i+(T*A-b[0])*n[1]+(T*S-b[1])*t[1],(T-1)*s+(T*A-b[0])*n[2]+(T*S-b[1])*t[2]],E=[...C(x,h),p,...C(P,y),g,o[0],o[1],o[2],0,M[0],M[1],M[2],1];for(let A=0;A<8;A+=1)E[A]/=xn;return mn(E,6)}function Lo(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function dm(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 Ya(e){return!e.texture}function ja(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=dn(e.vertices,n,t),r=zn(o);return r?{pts:o,normal:r,planeD:Lo(r,o[0]),optimizable:Ya(e)}:null}function Wa(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:vi(e,n)}function vi(e,n){return!e||!n||Lo(e.normal,n.normal)<1-Or?!1:Math.abs(e.planeD-n.planeD)<=Rr}function Ci(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??Jn,i=t?.color??et,s=Math.max(0,t?.intensity??nt),a=o?.color??tt,c=Math.max(0,o?.intensity??ot),l=Math.hypot(r[0],r[1],r[2])||1,u=r[0]/l,f=r[1]/l,d=r[2]/l,m=s*Math.max(0,e.normal[0]*u+e.normal[1]*f+e.normal[2]*d),p=Po(m,i,a,c);return p.r*.2126+p.g*.7152+p.b*.0722}function Ha(e,n,t,o,r){if(!e||e.length===0)return;let i=0,s=0,a=0;for(let u of n)i+=u[0],s+=u[1],a+=u[2];let c=1/n.length;i*=c,s*=c,a*=c;let l=[];for(let u of e){let f=u.position[1]*o,d=u.position[0]*o,m=u.position[2]*r,p=f-i,g=d-s,h=m-a,y=Math.hypot(p,g,h)||1;p/=y,g/=y,h/=y;let b=t[0]*p+t[1]*g+t[2]*h;b<=0||l.push({color:u.color??"#ffffff",scale:Math.max(0,u.intensity??1)*b})}return l.length?l:void 0}function Ka(e){let n=[...e],t=Math.abs(n[0])>de?0:Math.abs(n[1])>de?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function lt(e,n,t,o,r={}){let i=Lo(o,t),s=[o[0]-i*t[0],o[1]-i*t[1],o[2]-i*t[2]],a=Math.hypot(s[0],s[1],s[2]);if(a<=de)return null;let c=[s[0]/a,s[1]/a,s[2]/a],l=[t[1]*c[2]-t[2]*c[1],t[2]*c[0]-t[0]*c[2],t[0]*c[1]-t[1]*c[0]],u=Math.hypot(l[0],l[1],l[2]);if(u<=de)return null;let f=[l[0]/u,l[1]/u,l[2]/u],d=e.map(D=>{let _=D[0]-n[0],w=D[1]-n[1],V=D[2]-n[2];return[_*c[0]+w*c[1]+V*c[2],_*f[0]+w*f[1]+V*f[2]]}),m=r.boundsOrigin??n,p=n[0]-m[0],g=n[1]-m[1],h=n[2]-m[2],y=p*c[0]+g*c[1]+h*c[2],b=p*f[0]+g*f[1]+h*f[2],x=1/0,P=1/0,M=-1/0,C=-1/0;for(let[D,_]of d){let w=D+y,V=_+b;w<x&&(x=w),w>M&&(M=w),V<P&&(P=V),V>C&&(C=V)}let E=M-x,A=C-P;if(!Number.isFinite(E)||!Number.isFinite(A))return null;let S=r.snapBounds?Math.floor(x+Ae):x,T=r.snapBounds?Math.floor(P+Ae):P,v=r.snapBounds?Math.ceil(M-Ae):M,R=r.snapBounds?Math.ceil(C-Ae):C,O=Math.max(1,r.snapBounds?v-S:Math.ceil(E)),L=Math.max(1,r.snapBounds?R-T:Math.ceil(A));return{xAxis:c,yAxis:f,local2D:d,shiftX:y-S,shiftY:b-T,canvasW:O,canvasH:L,pixelArea:O*L,rawArea:E*A}}function Ti(e){return`${e[0]},${e[1]},${e[2]}`}function pm(e,n){return Ti(e)<Ti(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function sb(e,n){let t=Ti(e),o=Ti(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Za(e,n,t,o){let r=0,i=0;for(let s of e){let a=n[s];if(!a)return null;let c=lt(a.pts,a.pts[0],a.normal,t,{boundsOrigin:o,snapBounds:!0});if(!c)return null;r+=c.pixelArea,i+=c.rawArea}return{pixelArea:r,rawArea:i}}function qa(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,i=new Set;for(let s of e){let a=n[s];if(!a)continue;let c=[a.pts[1][0]-a.pts[0][0],a.pts[1][1]-a.pts[0][1],a.pts[1][2]-a.pts[0][2]],l=lt(a.pts,a.pts[0],a.normal,c);o&&l?(o.pixelArea+=l.pixelArea,o.rawArea+=l.rawArea):o=null;for(let u=0;u<a.pts.length;u++){let f=pm(a.pts[u],a.pts[(u+1)%a.pts.length]),d=lt(a.pts,a.pts[0],a.normal,f);if(!d)continue;let m=Ka(d.xAxis);if(i.has(m))continue;i.add(m);let p=Za(e,n,d.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-Ae)&&(r={xAxis:d.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+Ae)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function gm(e,n){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(f=>ja(f,t,o)),i=new Map,s=e.map(()=>new Set),a=e.map(()=>new Set);for(let f=0;f<e.length;f++){let d=e[f].vertices;if(!(!d||d.length<3))for(let m=0;m<d.length;m++){let p=sb(d[m],d[(m+1)%d.length]),g=i.get(p),h={polygon:f,edge:m};g?g.push(h):i.set(p,[h])}}let c=e.map(()=>new Set);for(let f of i.values())if(!(f.length<2))for(let d=0;d<f.length;d++)for(let m=d+1;m<f.length;m++){let p=f[d],g=f[m],h=p.polygon,y=g.polygon;if(e[h].texture&&e[y].texture&&(a[p.polygon].add(p.edge),a[g.polygon].add(g.edge)),vi(r[h],r[y]))s[p.polygon].add(p.edge),s[g.polygon].add(g.edge);else{let b=Ci(r[h],n),x=Ci(r[y],n);b!==null&&x!==null&&(b<=x+fo&&s[p.polygon].add(p.edge),x<=b+fo&&s[g.polygon].add(g.edge))}Wa(r[h],r[y])&&(c[h].add(y),c[y].add(h))}let l=Array(e.length).fill(void 0),u=new Set;for(let f=0;f<e.length;f++){if(u.has(f)||!r[f]?.optimizable)continue;let d=[],m=[f];for(u.add(f);m.length>0;){let g=m.pop();d.push(g);for(let h of c[g])u.has(h)||(u.add(h),m.push(h))}if(d.length<2)continue;let p=qa(d,r);if(p)for(let g of d)l[g]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:s[g],textureEdgeRepairEdges:a[g]}}for(let f=0;f<e.length;f++)!l[f]&&(s[f].size>0||a[f].size>0)&&(l[f]={seamEdges:s[f],textureEdgeRepairEdges:a[f]});return l}function Ei(e,n,t,o){if(o.optimize&&o.fixedXAxis)return lt(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,i=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,s=i??(o.optimize?e.map((a,c)=>c):[0]);for(let a of s){let c=(a+1)%e.length,l=i?pm(e[a],e[c]):[e[c][0]-e[a][0],e[c][1]-e[a][1],e[c][2]-e[a][2]],u=lt(e,n,t,l,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-Ae)&&(r=u)}return r}function Qa(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,i)=>{for(let s of r)if(Math.abs(s-i)<=Ae)return;r.push(i)};for(let[r,i]of e.local2D)o(n,r+e.shiftX),o(t,i+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,i)=>r-i),t.sort((r,i)=>r-i),Math.abs(n[0])>Ae||Math.abs(t[0])>Ae||n[1]-n[0]<=Ae||t[1]-t[0]<=Ae))return!1;for(let[r,i]of e.local2D){let s=r+e.shiftX,a=i+e.shiftY,c=Math.abs(s-n[0])<=Ae||Math.abs(s-n[1])<=Ae,l=Math.abs(a-t[0])<=Ae||Math.abs(a-t[1])<=Ae;if(!c||!l)return!1}return!0}function Ii(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[i,s,a]=n,c=t[0],l=t[1],u=o[0],f=o[1],d=r[0],m=r[1],p=i[0],g=1-i[1],h=s[0],y=1-s[1],b=a[0],x=1-a[1],P=h-p,M=y-g,C=b-p,E=x-g,A=P*E-C*M;if(Math.abs(A)<=1e-9)return null;let S=u-c,T=d-c,v=f-l,R=m-l,O={a:(S*E-T*M)/A,b:(P*T-C*S)/A,c:(v*E-R*M)/A,d:(P*R-C*v)/A,e:0,f:0};return O.e=c-O.a*p-O.b*g,O.f=l-O.c*p-O.d*g,O}function _i(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let i of e){let s=i[0],a=1-i[1];if(!Number.isFinite(s)||!Number.isFinite(a))return null;n=Math.min(n,s),o=Math.max(o,s),t=Math.min(t,a),r=Math.max(r,a)}return{minU:n,minV:t,maxU:o,maxV:r}}function Ja(e,n,t,o,r,i,s,a){let l=dn(e.vertices,n,t).map(d=>{let m=d[0]-o[0],p=d[1]-o[1],g=d[2]-o[2];return[m*r[0]+p*r[1]+g*r[2]+s,m*i[0]+p*i[1]+g*i[2]+a]}),u=Ii(l,e.uvs),f=_i(e.uvs);return!u&&!f?null:{screenPts:l.flatMap(([d,m])=>[d,m]),uvAffine:u,uvSampleRect:f}}function ec(e,n,t,o,r){let i=t,{vertices:s,uvs:a}=e,c=Si(e);if(!s||s.length<3)return null;let l=t.tileSize??50,u=t.layerElevation??l,f=dn(s,l,u),d=f[0],m=f[1],p=[m[0]-d[0],m[1]-d[1],m[2]-d[2]];if(Math.hypot(p[0],p[1],p[2])===0)return null;let h=zn(f);if(!h)return null;let y=Ei(f,d,h,{optimize:!1}),b=c||y&&Qa(y)?y:Ei(f,d,h,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:P,local2D:M}=b,C=c&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,E=!!(c&&C),A=b.shiftX,S=b.shiftY,T=b.canvasW,v=b.canvasH,R=[];for(let[Me,Re]of M)R.push(Me+A,Re+S);let O=d[0]-A*x[0]-S*P[0],L=d[1]-A*x[1]-S*P[1],D=d[2]-A*x[2]-S*P[2],_=mn([x[0],x[1],x[2],0,P[0],P[1],P[2],0,h[0],h[1],h[2],0,O,L,D,1]),w=mn([x[0]*T,x[1]*T,x[2]*T,0,P[0]*v,P[1]*v,P[2]*v,0,h[0],h[1],h[2],0,O,L,D,1]),V=mn([x[0]*T/nn,x[1]*T/nn,x[2]*T/nn,0,P[0]*v/nn,P[1]*v/nn,P[2]*v/nn,0,h[0],h[1],h[2],0,O,L,D,1]),j=hi(i.seamBleed),G=yi(R,i.seamEdges??r?.seamEdges,j),Z=G?new Set(G.keys()):void 0,ee=G?Math.max(...G.values()):void 0,W=xi(R,G),ie=!c&&s.length===4?Ro(R,x,P,h,O,L,D,o,G):null,z=t.directionalLight,X=t.ambientLight,U=z?.direction??Jn,I=z?.color??et,B=Math.max(0,z?.intensity??nt),N=X?.color??tt,H=Math.max(0,X?.intensity??ot),$=Math.hypot(U[0],U[1],U[2])||1,k=U[0]/$,Q=U[1]/$,ae=U[2]/$,Y=t.lightOccludedPolyIndices?.has(n)??!1?0:B*Math.max(0,h[0]*k+h[1]*Q+h[2]*ae),ne=Ha(t.pointLights,f,h,l,u),le=Po(Y,I,N,H,ne),ye=Rn(e.color??"#cccccc",Y,I,N,H,ne),Ce=null,Ve=null;c&&a&&a.length>=3&&a.length===s.length&&(Ve=_i(a),Ce=Ii(M.map(([Me,Re])=>[Me+A,Re+S]),a));let Ee=c&&e.textureTriangles?.length?e.textureTriangles.map(Me=>Ja(Me,l,u,d,x,P,A,S)).filter(Me=>!!Me):null;return{index:n,polygon:e,texture:c,tileSize:l,layerElevation:u,matrix:_,canonicalMatrix:w,atlasMatrix:V,projectiveMatrix:ie,canvasW:T,canvasH:v,screenPts:R,uvAffine:Ce,uvSampleRect:Ve,textureTriangles:Ee,textureEdgeRepairEdges:C,textureEdgeRepair:E,seamBleed:ee,seamBleedEdges:Z,seamBleedEdgeAmounts:G,seamBleedInsets:W,bleedRatio:$r(i.seamBleed),normal:h,textureTint:le,shadedColor:ye}}function hm(e,n,t={},o,r){let i=Oo(o),s=t,a=r??(t.textureEdgeRepairEdges?.size?{seamEdges:new Set,textureEdgeRepairEdges:t.textureEdgeRepairEdges}:void 0);return ec(e,n,s,i,a)}function Vi(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function ab(e){return!!e&&typeof e.url=="string"&&e.url.length>0&&Vi(e.width)&&Vi(e.height)}function cb(e){let n=e.sourceRect;return n?!Number.isFinite(n.x)||!Number.isFinite(n.y)||!Vi(n.width)||!Vi(n.height)?null:{x:n.x,y:n.y,width:n.width,height:n.height}:{x:0,y:0,width:e.width,height:e.height}}function lb(e,n,t){let o=e.split(",").map(Number);if(o.length!==16||o.some(s=>!Number.isFinite(s)))return null;let r=xn/n,i=xn/t;for(let s=0;s<4;s+=1)o[s]*=r;for(let s=4;s<8;s+=1)o[s]*=i;return mn(o,6)}function Oi(e,n={}){let t=_o(e.polygon);if(!ab(t))return null;let o=Vo(e.polygon,{imageRendering:n.imageRendering,backend:n.backend,lighting:n.lighting,projection:n.projection});if(o.backend!=="image")return null;let r=o.lighting??"source";if(r!=="source")return null;let i=cb(t);if(!i)return null;let s=Math.max(1,i.width),a=Math.max(1,i.height),c=o.projection??"affine",l=c,u=null;if(c==="projective"){if(n.allowProjective===!1||e.screenPts.length!==8||e.polygon.vertices.length!==4)return null;let f=n.projectiveQuadGuards??Oo(void 0),d=Eo(e,e.polygon);if(!d)return null;let m=Ro(e.screenPts,d.xAxis,d.yAxis,d.normal,d.tx,d.ty,d.tz,f,e.seamBleedEdgeAmounts);if(u=m?lb(m,s,a):null,!u)return null}else l="affine",u=Rt(e,s,a);return{source:t,url:t.url,sourceRect:i,leafWidth:s,leafHeight:a,matrix:u,backgroundPosition:[-i.x,-i.y],backgroundSize:[t.width,t.height],imageRendering:o.imageRendering??"auto",lighting:r,projection:l}}function nc(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=.001,r=(i,s)=>{for(let a of i)if(Math.abs(a-s)<=o)return;i.push(s)};for(let i=0;i<e.screenPts.length;i+=2)r(n,e.screenPts[i]),r(t,e.screenPts[i+1]);if(n.length!==2||t.length!==2||(n.sort((i,s)=>i-s),t.sort((i,s)=>i-s),Math.abs(n[0])>o||Math.abs(t[0])>o||n[1]-n[0]<=o||t[1]-t[0]<=o))return null;for(let i=0;i<e.screenPts.length;i+=2){let s=e.screenPts[i],a=e.screenPts[i+1],c=Math.abs(s-n[0])<=o||Math.abs(s-n[1])<=o,l=Math.abs(a-t[0])<=o||Math.abs(a-t[1])<=o;if(!c||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function Un(e){return!!nc(e)}function ct(e){return!e.texture&&e.polygon.vertices.length===3}function Dt(e){return!e.texture&&!!e.projectiveMatrix&&!Un(e)}function ym(e){let n=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(e);return/\bVersion\/[\d.]+.*\bSafari\//.test(e)&&!n}function Ri(e,n){e.set(n,(e.get(n)??0)+1)}function Li(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function bm(e,n,t,o){let r=!t.has("b"),i=r&&o.projectiveQuadSupported,s=!t.has("u")&&o.solidTriangleSupported,a=!t.has("i")&&!!o.cornerShapeSupported,c=!t.has("i")&&o.borderShapeSupported,l=t.has("b");return e.map(u=>{if(u?.texture&&Oi(u,{allowProjective:o.projectiveQuadSupported,backend:o.textureBackend,imageRendering:o.textureImageRendering,lighting:o.textureImageLighting,projection:o.textureProjection}))return null;if(!u||u.texture)return u;if(s&&ct(u))return null;let f=Un(u);return a&&!f&&!(i&&Dt(u))&&Pi(u)!==null||r&&f||i&&Dt(u)||c&&(!f||l)?null:u})}function xm(e,n,t,o,r,i,s){let a=new Map,c=new Map,l=new Map,u=!t.has("b"),f=u&&o.projectiveQuadSupported,d=!t.has("u")&&o.solidTriangleSupported,m=!t.has("i")&&o.cornerShapeSupported,p=!t.has("i")&&o.borderShapeSupported;for(let y of e){if(!y||y.texture)continue;let b=m&&!!s?.(y);if(n==="dynamic"){if(!(d&&ct(y))&&!(u&&Un(y))&&!(f&&Dt(y))&&!b&&!p)continue;let x=r(y.polygon.color??"#cccccc"),P=i(x);Ri(c,P),l.has(P)||l.set(P,x);continue}!(d&&ct(y))&&!(u&&Un(y))&&!(f&&Dt(y))&&!b&&!p||Ri(a,y.shadedColor)}let g=Li(a),h=Li(c);return{paintColor:g,dynamicColorKey:h,dynamicColor:h?l.get(h):void 0}}function ub(e,n){if((e+1)%3===n)return e;if((n+1)%3===e)return n}function fb(e,n,t,o,r,i,s){if(!e?.size)return null;let a=vo(n,t);return[[i,o],[o,r],[r,i]].map(([l,u],f)=>{let d=ub(l,u),m=d!==void 0&&e.has(d)?a:0;return Io(s,f,m)})}function wi(e,n,t,o,r,i,s,a){let c=i,l="",u,f,d="";if(s){let m=a??e.color??"#cccccc",p=i.directionalLight,g=i.ambientLight,h=p?.direction??Jn,y=p?.color??et,b=Math.max(0,p?.intensity??nt),x=g?.color??tt,P=Math.max(0,g?.intensity??ot),M=Math.hypot(h[0],h[1],h[2])||1,C=h[0]/M,E=h[1]/M,A=h[2]/M,T=i.lightOccludedPolyIndices?.has(n)??!1?0:b*Math.max(0,t*C+o*E+r*A),v=i.tileSize??50,R=i.layerElevation??v,O=Ha(i.pointLights,dn(e.vertices,v,R),[t,o,r],v,R),L=Rn(m,T,y,x,P,O),D=i.textureLighting??"baked",_=D==="baked"&&c.stableTriangleColorSteps?Yr(L,c.stableTriangleColorSteps):L,w=fn(m),V=_===i.solidPaintDefaults?.paintColor,j=D==="dynamic"&&Xr(w)===i.solidPaintDefaults?.dynamicColorKey;l=D==="dynamic"||V?"":_,u=l?fn(l):void 0,f=l?bo(l):void 0,d=D==="dynamic"?`--pnx:${t.toFixed(4)};--pny:${o.toFixed(4)};--pnz:${r.toFixed(4)};`+(j?"":`--psr:${(w.r/255).toFixed(4)};--psg:${(w.g/255).toFixed(4)};--psb:${(w.b/255).toFixed(4)};`):""}return{index:n,polygon:e,colorComputed:s,bakedColor:l||void 0,bakedRgb:u,bakedAlpha:f,dynamicVars:d}}function Pm(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??50,r=t.layerElevation??o,i=e.vertices[0],s=e.vertices[1],a=e.vertices[2],c=[i[1]*o,i[0]*o,i[2]*r],l=[s[1]*o,s[0]*o,s[2]*r],u=[a[1]*o,a[0]*o,a[2]*r],f=l[0]-c[0],d=l[1]-c[1],m=l[2]-c[2],p=u[0]-c[0],g=u[1]-c[1],h=u[2]-c[2],y=-(d*h-m*g),b=-(m*p-f*h),x=-(f*g-d*p),P=Math.sqrt(y*y+b*b+x*x);return P<=de?null:(y/=P,b/=P,x/=P,wi(e,n,y,b,x,t,!0))}function Mm(e,n,t,o={}){if(e.texture||e.vertices.length!==3)return null;let r=t.tileSize??50,i=t.layerElevation??r,s=e.vertices[0],a=e.vertices[1],c=e.vertices[2],l=s[1]*r,u=s[0]*r,f=s[2]*i,d=a[1]*r,m=a[0]*r,p=a[2]*i,g=c[1]*r,h=c[0]*r,y=c[2]*i;return Ni(e,n,t,o,l,u,f,d,m,p,g,h,y)}function Ni(e,n,t,o,r,i,s,a,c,l,u,f,d){let m=t,p=a-r,g=c-i,h=l-s,y=u-r,b=f-i,x=d-s,P=-(g*x-h*b),M=-(h*y-p*x),C=-(p*b-g*y),E=Math.sqrt(P*P+M*M+C*C);if(E<=de)return null;P/=E,M/=E,C/=E;let A=o.basis,S=A?.a??0,T=A?.b??1,v=A?.c??2;S<0||S>2||T<0||T>2||v<0||v>2||S===T||S===v||T===v?(A=void 0,S=0,T=1,v=2):S===0&&T===1&&v===2||S===1&&T===2&&v===0||S===2&&T===0&&v===1||(A=void 0,S=0,T=1,v=2);let R=()=>A?Ni(e,n,t,{...o,basis:void 0},r,i,s,a,c,l,u,f,d):null;if(!A){let Pe=p*p+g*g+h*h,ge=u-a,Fe=f-c,Le=d-l,Oe=r-u,$e=i-f,ze=s-d,Ue=ge*ge+Fe*Fe+Le*Le,We=Oe*Oe+$e*$e+ze*ze,be=Pe;Ue>be&&(S=1,T=2,v=0,be=Ue),We>be&&(S=2,T=0,v=1)}let O,L,D,_,w,V,j=v===0?r:v===1?a:u,G=v===0?i:v===1?c:f,Z=v===0?s:v===1?l:d;S===0?(O=r,L=i,D=s):S===1?(O=a,L=c,D=l):(O=u,L=f,D=d),T===0?(_=r,w=i,V=s):T===1?(_=a,w=c,V=l):(_=u,w=f,V=d);let ee=_-O,W=w-L,ie=V-D,z=Math.sqrt(ee*ee+W*W+ie*ie);if(z<=de)return R();let X=ee/z,U=W/z,I=ie/z,B=(j-O)*X+(G-L)*U+(Z-D)*I,N=M*I-C*U,H=C*X-P*I,$=P*U-M*X,k=E/z;if(k<=de)return R();let Q=Math.max(0,Math.min(z,B)),ae=Math.max(0,z-Q),se=[Q,0,0,k,Q+ae,k],Y=Lr*(m.bleedRatio??1),ne=fb(m.seamEdges,m.seamBleed,Y,S,T,v,se),le=ne?wt(se,ne):pi(Q,ae,k,vo(m.seamBleed,Y)),ye=le[0],Ce=le[1],Ve=le[2],Ee=le[3],Me=le[4],Re=le[5],F=(Ee+Re)/2,q=ye-Ve,J=Me-ye,te=F-Ce;if(q<=de||J<=de||te<=de||!Number.isFinite(q+J+te))return R();let ue=o.includeColor??!0,ce=!1,he,Se,ve,xe="";if(ue){let Pe=wi(e,n,P,M,C,t,!0,o.color);ce=Pe.colorComputed,he=Pe.bakedColor,Se=Pe.bakedRgb,ve=Pe.bakedAlpha,xe=Pe.dynamicVars??""}let K=he?`color:${he};`:"",oe=o.primitive??o.resolvedPrimitive??"border",qe=1/(oe==="border-large"?Fr:Dr),Ye=q+J,Ge=Ye*qe,we=(J-q)*.5*qe,Ne=te*qe,Je=ye-Q-Ye*.5,Qe=Ce,Mn=X*Ge,Sn=U*Ge,Gn=I*Ge,Bt=X*we+N*Ne,ft=U*we+H*Ne,An=I*we+$*Ne,pn=j+X*Je+N*Qe,mt=G+U*Je+H*Qe,je=Z+I*Je+$*Qe,en=o.matrixDecimals??gi(m.stableTriangleMatrixDecimals),Te=fi(Mn,Sn,Gn,Bt,ft,An,P,M,C,pn,mt,je,en),ke=t.textureLighting??"baked",fe=m.optimizeStableTriangleStyle===!0&&ke==="baked"?"":`transform:${Te};`+K+xe,me=A&&A.a===S&&A.b===T&&A.c===v?A:{a:S,b:T,c:v};return{index:n,polygon:e,styleText:fe,transformText:Te,basis:me,primitive:oe,colorComputed:ce,bakedColor:he,bakedRgb:Se,bakedAlpha:ve,dynamicVars:xe}}function ut(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Tr,Math.max(Cr,n))}function Di(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function tc(e,n){let t=Di(e);if(t<=0)return 1;let o=Math.max(1,...e.map(s=>Math.max(s.width,s.height))),r=Tt/o,i=Math.sqrt(n/(t*4));return ut(Math.min(r,i))}function oc(e,n){let t=Di(e),o=.5;return t<=uo?o=1:t<=Er&&(o=.75),ut(Math.min(o,tc(e,n)))}function rc(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function ic(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function sc(e,n,t){let o=rc(e,n),r=ic(e,n),i=o>Tt?Tt/o:1,s=r>t?Math.sqrt(t/r):1;return Math.min(i,s)}function ac(e){return e?vr:Ir}function cc(e,n){return e!==void 0&&e!=="auto"?nn:n?nn:Br}function Sm(e,n){return wo(e,n,1,"canonical")}function lc(e,n,t,o=uc(e)){let r=t??"canonical";if(r==="local")return{width:Math.max(1,e.canvasW||1),height:Math.max(1,e.canvasH||1),sizing:r};if(r==="raster"){let i=ut(n);return{width:Math.max(1,(e.canvasW||1)*i),height:Math.max(1,(e.canvasH||1)*i),sizing:r}}return{width:o,height:o,sizing:"canonical"}}function wo(e,n,t,o="canonical"){for(let r of e.entries){if(!r)continue;let i=lc(r,t,o,n);r.atlasCanonicalSize=n,r.atlasLeafSizing=i.sizing,r.atlasLeafWidth=i.width,r.atlasLeafHeight=i.height,r.atlasMatrix=Rt(r,i.width,i.height)}return e}function uc(e){return e.atlasCanonicalSize??nn}function fc(e){return Math.max(lo,Math.ceil(lo/e))}function Ft(e,n=1){let t=Array(e.length).fill(null),o=[],r=fc(n),i=e.filter(c=>!!c).sort((c,l)=>l.canvasH-c.canvasH||l.canvasW-c.canvasW||c.index-l.index),s=()=>({width:r,height:r,entries:[],shelves:[]}),a=(c,l,u)=>{if(c.sealed)return null;for(let m of c.shelves)if(l.canvasH<=m.height&&m.x+l.canvasW+r<=On){let p={...l,pageIndex:u,x:m.x,y:m.y};return m.x+=l.canvasW+r*2,c.entries.push(p),c.width=Math.max(c.width,p.x+l.canvasW+r),p}let f=c.shelves.length===0?r:c.height+r;if(f+l.canvasH+r>On)return null;let d={...l,pageIndex:u,x:r,y:f};return c.shelves.push({x:r+l.canvasW+r*2,y:f,height:l.canvasH}),c.entries.push(d),c.width=Math.max(c.width,d.x+l.canvasW+r),c.height=Math.max(c.height,f+l.canvasH+r),d};for(let c of i){if(c.canvasW+r*2>On||c.canvasH+r*2>On){let f=o.length,d={...c,pageIndex:f,x:r,y:r};t[c.index]=d,o.push({width:c.canvasW+r*2,height:c.canvasH+r*2,entries:[d],shelves:[],sealed:!0});continue}let u=null;for(let f=0;f<o.length&&(u=a(o[f],c,f),!u);f++);if(!u){let f=s(),d=o.length;o.push(f),u=a(f,c,d)}u&&(t[c.index]=u)}return{entries:t,pages:o.map(({width:c,height:l,entries:u})=>({width:c,height:l,entries:u}))}}function mb(e,n,t){let o=oc(n.pages,t),r=o===1?n:Ft(e,o);for(let i=0;i<4;i++){let s=sc(r.pages,o,t);if(s>=1)break;let a=ut(o*s*_r);if(a>=o)break;o=a,r=Ft(e,o)}return{packed:r,atlasScale:o}}function Am(e,n,t,o="canonical"){let r=cc(n,t);if(n!==void 0&&n!=="auto"){let a=ut(n);return{packed:wo(Ft(e,a),r,a,o),atlasScale:a,atlasCanonicalSize:r}}let i=Ft(e,1),s=mb(e,i,ac(t));return{packed:wo(s.packed,r,s.atlasScale,o),atlasScale:s.atlasScale,atlasCanonicalSize:r}}0&&(module.exports={ASYNC_RENDER_BUDGET_MS,ATLAS_CANONICAL_SIZE_AUTO_DESKTOP,ATLAS_CANONICAL_SIZE_EXPLICIT,ATLAS_MAX_SIZE,ATLAS_PADDING,AUTO_ATLAS_LOW_AREA,AUTO_ATLAS_MAX_BITMAP_SIDE,AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP,AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE,AUTO_ATLAS_MEDIUM_AREA,AUTO_ATLAS_SCALE_GUARD,BAKED_SHADOW_MIN_UP,BAKED_SHADOW_Z_SQUASH,BASE_TILE,BASIS_EPS,BORDER_SHAPE_BLEED,BORDER_SHAPE_CANONICAL_SIZE,BORDER_SHAPE_CENTER_PERCENT,BORDER_SHAPE_POINT_EPS,CAMERA_BACKFACE_CULL_EPS,COLOR_PARSE_CACHE_MAX,CORNER_SHAPE_DUPLICATE_EPS,CORNER_SHAPE_POINT_EPS,DECIMAL_SCALES,DEFAULT_AMBIENT_COLOR,DEFAULT_AMBIENT_INTENSITY,DEFAULT_ATLAS_CSS_DECIMALS,DEFAULT_BORDER_SHAPE_DECIMALS,DEFAULT_CAMERA_STATE,DEFAULT_LIGHT_COLOR,DEFAULT_LIGHT_DIR,DEFAULT_LIGHT_INTENSITY,DEFAULT_MATRIX_DECIMALS,DEFAULT_PROJECTION,DEFAULT_SEAM_BLEED,DEFAULT_SEAM_FACET_SPLIT_OPTIONS,DEFAULT_SEAM_OVERLAP_OPTIONS,DEFAULT_TILE,LoopOnce,LoopPingPong,LoopRepeat,MAX_ATLAS_SCALE,MIN_ATLAS_SCALE,PROJECTIVE_QUAD_BLEED,PROJECTIVE_QUAD_DENOM_EPS,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,QUAT_IDENTITY,RECEIVER_NORMAL_TOL,RECEIVER_OFFSET_TOL,RECEIVER_OUTLINE_EXPAND,RECT_EPS,SEAM_LIGHT_EPS,SOLID_QUAD_CANONICAL_SIZE,SOLID_TRIANGLE_BLEED,SOLID_TRIANGLE_CANONICAL_SIZE,SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE,SURFACE_DISTANCE_EPS,SURFACE_NORMAL_EPS,TEXTURE_EDGE_REPAIR_ALPHA_MIN,TEXTURE_EDGE_REPAIR_RADIUS,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN,TEXTURE_TRIANGLE_BLEED,VOXEL_CAMERA_CULL_AXIS_EPS,VOXEL_CAMERA_CULL_NORMAL_LIMIT,applyPackedAtlasCanonicalSize,applyPackedAtlasLeafSizing,arrowPolygons,atlasArea,atlasBitmapMaxSide,atlasCanonicalSizeForEntry,atlasCanonicalSizeForTextureQuality,atlasDecodedBytes,atlasPadding,autoAtlasBudgetFactor,autoAtlasMaxDecodedBytes,autoAtlasScale,autoAtlasScaleCap,axesHelperPolygons,bakeSolidTextureSampledPolygons,bakeSolidTextureSamples,basisAxisKey,borderShapeBoundsFromPoints,borderShapeGeometryForPlan,boxPolygons,buildBakedShadowProjectionMatrix,buildBasisHints,buildEdgeOwners,buildParametricCasterOverride,buildPolyCameraSceneTransform,buildPolyMeshTransform,buildPolySceneTransform,buildSceneContext,buildSeamBleedPolygonEdges,buildSeamBleedPolygonSet,buildSharedEdgeMap,buildTextureEdgeRepairSets,cachedParsePureColor,cameraCullNormalGroups,cameraCullNormalGroupsFromPolygons,cameraCullNormalKey,cameraCullVisibleSignature,cameraFacingDepth,capturePolyCameraSnapshot,chooseIslandXAxis,chooseLocalBasis,clampChannel,classifyFacing,clipPolygonToConvex2D,colorErrorScore,compatibleBleedSurface,compatibleSurface,computeCoverageShadowSilhouette,computeLightVisibility,computeMergedReceiverShadows,computeParametricShadowSilhouette,computePlanSeamBleedEdgeAmounts,computeProjectiveQuadCoefficients,computeProjectiveQuadMatrix,computeReceiverShadowFaces,computeSceneBbox,computeSeamBleedInsets,computeShapeLighting,computeSolidTriangleColorPlan,computeSolidTriangleColorPlanFromNormal,computeSolidTrianglePlan,computeSolidTrianglePlanFromCssPoints,computeSurfaceNormal,computeTextureAtlasPlan,computeTextureAtlasPlanPublic,computeTexturePaintMetrics,computeUvAffine,computeUvSampleRect,conePolygons,convexHull2D,cornerShapeDiagonal,cornerShapeGeometryForPlan,cornerShapePointSides,coverPlanarPolygons,createIsometricCamera,createPolyAnimationMixer,crossVec,cssBorderShapeForGeometry,cssBorderShapeForPlan,cssDistanceToWorld,cssPoints,cssPositionToWorld,cullInteriorPolygons,cylinderPolygons,dedupeOverlappingPolygons,dodecahedronPolygons,dominantCountKey,dotVec,ensureCcw2D,eulerXYZFromQuat,evaluateIslandAxis,expandClipPoints,expandConvexHullOutward,extractSilhouetteLoops,filterAtlasPlans,findOverlappingPolygonDuplicates,formatAffineMatrix3dColumns,formatAffineMatrix3dScalars,formatAffineMatrix3dTransformScalars,formatAtlasMatrix,formatBorderShapeElementStyle,formatBorderShapeEntryMatrix,formatBorderShapeMatrix,formatColor,formatCornerShapeElementStyle,formatCssLength,formatCssLengthPx,formatMatrix3d,formatMatrix3dValues,formatPercent,formatScaledMatrixFromPlan,formatSolidQuadEntryMatrix,formatSolidQuadMatrix,fullRectBounds,getPolygonBasisInfo,getSolidPaintDefaultsForPlansCore,groupReceiverFaceGroups,icosahedronPolygons,incrementCount,intersect2DLines,intersect2DLinesRaw,inverseRotateVec3,isAxisAlignedSurfaceNormal,isBakedShadowCaster,isBasisOptimizable,isConvexCaster,isConvexPolygonPoints,isFlatCaster,isFullRectBasis,isFullRectSolid,isPointShadowCaster,isProjectiveQuadPlan,isSolidTrianglePlan,isVoxelCameraCullableNormalGroups,loadMesh,makeLocalBasis,mergePolygons,meshScaleVec3,normalFacesCamera,normalizeAtlasScale,normalizeInvertMultiplier,normalizePolygons,normalizedSeamBleed,octahedronPolygons,offsetConvexPolygonPoints,offsetConvexPolygonPointsByEdgeAmounts,offsetStableTrianglePoints,offsetTrianglePoints,optimizeAnimatedMeshPolygons,optimizeMeshParseResult,optimizeMeshPolygons,packTextureAtlasPlans,packTextureAtlasPlansWithScaleCore,parseAlpha,parseColor,parseGltf,parseHex,parseHexColor,parseMtl,parseObj,parsePureColor,parseRgbColor,parseStl,parseVox,planePolygons,polyCameraTargetToCss,polyCssDistanceToWorld,polyCssPositionToWorld,polygonContainsPoint,polygonCssSurfaceNormal,polygonFaces,polygonFacesCamera,polygonSignedArea2D,prepareCasterEdgeOwners,prepareCasterPolyItems,prepareReceiverFacePlanes,projectCssVertexToGround,projectCssVertexToGroundFromPoint,projectTextureTriangle,quantizeCssColor,quatFromAxisAngle,quatFromEulerXYZ,quatMultiply,repairMeshSeams,resolveAtlasLeafBox,resolveBleedRatio,resolvePolyCameraAppliedPerspectiveStyle,resolvePolyTextureImageRendering,resolvePolyTextureImageSource,resolvePolyTextureLeafGeometry,resolvePolyTexturePresentation,resolvePolyTextureUrl,resolveProjectiveQuadGuards,resolveSeamBleed,rgbEqual,rgbKey,rgbToCss,rgbToHex,ringPolygons,ringQuadPolygons,rotateVec3,rotateVec3InWrapperCssFrame,roundDecimal,safariCssProjectiveUnsupported,safePlanSeamBleedAmount,screenToWorldOnSphere,screenToWorldRay,seamBleedAmountArray,seamFacetSplitPolygons,seamFacetSplitReport,seamLightBrightness,seamOverlapDiagnostics,seamOverlapPolygons,seamOverlapReport,shadeColor,shadePolygon,sharedCornerShapeSide,signedArea2D,simplifyCornerShapePoints,simplifyTriangleMeshPolygons,spherePolygons,stableBasisFromPlan,stableTriangleMatrixDecimals,stepRgbToward,tetrahedronPolygons,textureTintFactors,tintToCss,torusPolygons,worldCssForMesh,worldDirectionToCss,worldDirectionToPolyCss,worldDirectionalLightToCss,worldDirectionalLightToPolyCss,worldDistanceToCss,worldDistanceToPolyCss,worldPositionToCss,worldPositionToPolyCss});
|