@layoutit/polycss-core 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var gs=Object.defineProperty;var zf=Object.getOwnPropertyDescriptor;var Gf=Object.getOwnPropertyNames;var $f=Object.prototype.hasOwnProperty;var Xf=(e,n)=>{for(var t in n)gs(e,t,{get:n[t],enumerable:!0})},Yf=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Gf(n))!$f.call(e,r)&&r!==t&&gs(e,r,{get:()=>n[r],enumerable:!(o=zf(n,r))||o.enumerable});return e};var Wf=e=>Yf(gs({},"__esModule",{value:!0}),e);var Ty={};Xf(Ty,{ASYNC_RENDER_BUDGET_MS:()=>Zl,ATLAS_CANONICAL_SIZE_AUTO_DESKTOP:()=>gr,ATLAS_CANONICAL_SIZE_EXPLICIT:()=>Ye,ATLAS_MAX_SIZE:()=>En,ATLAS_PADDING:()=>Zt,AUTO_ATLAS_LOW_AREA:()=>qt,AUTO_ATLAS_MAX_BITMAP_SIDE:()=>yt,AUTO_ATLAS_MAX_DECODED_BYTES_DESKTOP:()=>sr,AUTO_ATLAS_MAX_DECODED_BYTES_MOBILE:()=>rr,AUTO_ATLAS_MEDIUM_AREA:()=>or,AUTO_ATLAS_SCALE_GUARD:()=>ir,BAKED_SHADOW_MIN_UP:()=>Bl,BAKED_SHADOW_Z_SQUASH:()=>Fl,BASE_TILE:()=>Ue,BASIS_EPS:()=>de,BORDER_SHAPE_BLEED:()=>hr,BORDER_SHAPE_CANONICAL_SIZE:()=>hn,BORDER_SHAPE_CENTER_PERCENT:()=>eo,BORDER_SHAPE_POINT_EPS:()=>no,CAMERA_BACKFACE_CULL_EPS:()=>Ht,COLOR_PARSE_CACHE_MAX:()=>ar,CORNER_SHAPE_DUPLICATE_EPS:()=>to,CORNER_SHAPE_POINT_EPS:()=>We,DECIMAL_SCALES:()=>mr,DEFAULT_AMBIENT_COLOR:()=>Kn,DEFAULT_AMBIENT_INTENSITY:()=>Zn,DEFAULT_ATLAS_CSS_DECIMALS:()=>Jt,DEFAULT_BORDER_SHAPE_DECIMALS:()=>fr,DEFAULT_CAMERA_STATE:()=>Ee,DEFAULT_LIGHT_COLOR:()=>jn,DEFAULT_LIGHT_DIR:()=>Wn,DEFAULT_LIGHT_INTENSITY:()=>Hn,DEFAULT_MATRIX_DECIMALS:()=>pn,DEFAULT_PROJECTION:()=>ka,DEFAULT_SEAM_BLEED:()=>nu,DEFAULT_SEAM_FACET_SPLIT_OPTIONS:()=>Us,DEFAULT_SEAM_OVERLAP_OPTIONS:()=>ks,DEFAULT_TILE:()=>dn,LoopOnce:()=>Zi,LoopPingPong:()=>qi,LoopRepeat:()=>Er,MAX_ATLAS_SCALE:()=>tr,MIN_ATLAS_SCALE:()=>nr,PROJECTIVE_QUAD_BLEED:()=>br,PROJECTIVE_QUAD_DENOM_EPS:()=>yr,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO:()=>xr,QUAT_IDENTITY:()=>nc,RECEIVER_NORMAL_TOL:()=>ji,RECEIVER_OFFSET_TOL:()=>Hi,RECEIVER_OUTLINE_EXPAND:()=>Wi,RECT_EPS:()=>Me,SEAM_LIGHT_EPS:()=>Qt,SOLID_QUAD_CANONICAL_SIZE:()=>gn,SOLID_TRIANGLE_BLEED:()=>ur,SOLID_TRIANGLE_CANONICAL_SIZE:()=>dr,SOLID_TRIANGLE_LARGE_BORDER_CANONICAL_SIZE:()=>pr,SURFACE_DISTANCE_EPS:()=>lr,SURFACE_NORMAL_EPS:()=>cr,TEXTURE_EDGE_REPAIR_ALPHA_MIN:()=>Ql,TEXTURE_EDGE_REPAIR_RADIUS:()=>eu,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN:()=>Jl,TEXTURE_TRIANGLE_BLEED:()=>ql,VOXEL_CAMERA_CULL_AXIS_EPS:()=>bi,VOXEL_CAMERA_CULL_NORMAL_LIMIT:()=>Pi,applyPackedAtlasCanonicalSize:()=>kf,applyPackedAtlasLeafSizing:()=>Po,arrowPolygons:()=>_i,atlasArea:()=>ps,atlasBitmapMaxSide:()=>Ra,atlasCanonicalSizeForEntry:()=>Fa,atlasCanonicalSizeForTextureQuality:()=>Na,atlasDecodedBytes:()=>Va,atlasPadding:()=>Ba,autoAtlasBudgetFactor:()=>La,autoAtlasMaxDecodedBytes:()=>wa,autoAtlasScale:()=>Oa,autoAtlasScaleCap:()=>_a,axesHelperPolygons:()=>Ei,bakeSolidTextureSampledPolygons:()=>Hu,bakeSolidTextureSamples:()=>Lr,basisAxisKey:()=>Sa,borderShapeBoundsFromPoints:()=>da,borderShapeGeometryForPlan:()=>vt,boxPolygons:()=>Ii,buildBakedShadowProjectionMatrix:()=>kl,buildBasisHints:()=>Vf,buildEdgeOwners:()=>Ar,buildPolyCameraSceneTransform:()=>lc,buildPolyMeshTransform:()=>Hl,buildPolySceneTransform:()=>Kl,buildSceneContext:()=>qa,buildSeamBleedPolygonEdges:()=>fa,buildSeamBleedPolygonSet:()=>Af,buildSharedEdgeMap:()=>cu,buildTextureEdgeRepairSets:()=>Sf,cachedParsePureColor:()=>qn,cameraCullNormalGroups:()=>Ai,cameraCullNormalGroupsFromPolygons:()=>Vl,cameraCullNormalKey:()=>Si,cameraCullVisibleSignature:()=>wl,cameraFacingDepth:()=>Mi,capturePolyCameraSnapshot:()=>uc,chooseIslandXAxis:()=>Ca,chooseLocalBasis:()=>rs,clampChannel:()=>_n,classifyFacing:()=>Cr,clipPolygonToConvex2D:()=>Tn,colorErrorScore:()=>iu,compatibleBleedSurface:()=>ss,compatibleSurface:()=>Ma,computeLightVisibility:()=>Ol,computePlanSeamBleedEdgeAmounts:()=>Kr,computeProjectiveQuadCoefficients:()=>ns,computeProjectiveQuadMatrix:()=>xo,computeReceiverShadowFaces:()=>mu,computeSceneBbox:()=>Ps,computeSeamBleedInsets:()=>qr,computeShapeLighting:()=>Ya,computeSolidTriangleColorPlan:()=>Ff,computeSolidTriangleColorPlanFromNormal:()=>ms,computeSolidTrianglePlan:()=>Bf,computeSolidTrianglePlanFromCssPoints:()=>ds,computeSurfaceNormal:()=>Nn,computeTextureAtlasPlan:()=>va,computeTextureAtlasPlanPublic:()=>Lf,computeTexturePaintMetrics:()=>Ja,computeUvAffine:()=>is,computeUvSampleRect:()=>as,conePolygons:()=>Bi,convexHull2D:()=>Zo,cornerShapeDiagonal:()=>ya,cornerShapeGeometryForPlan:()=>Qr,cornerShapePointSides:()=>ga,coverPlanarPolygons:()=>_o,createIsometricCamera:()=>fc,createPolyAnimationMixer:()=>du,crossVec:()=>Of,cssBorderShapeForGeometry:()=>Jr,cssBorderShapeForPlan:()=>Cf,cssDistanceToWorld:()=>Gi,cssPoints:()=>In,cssPositionToWorld:()=>$i,cullInteriorPolygons:()=>fn,cylinderPolygons:()=>Kt,dedupeOverlappingPolygons:()=>Pc,dodecahedronPolygons:()=>Fi,dominantCountKey:()=>fs,dotVec:()=>bo,ensureCcw2D:()=>mn,eulerXYZFromQuat:()=>sc,evaluateIslandAxis:()=>Aa,expandClipPoints:()=>Jn,expandConvexHullOutward:()=>Yi,extractSilhouetteLoops:()=>Tr,filterAtlasPlans:()=>Nf,findOverlappingPolygonDuplicates:()=>Lt,formatAffineMatrix3dColumns:()=>pf,formatAffineMatrix3dScalars:()=>Gr,formatAffineMatrix3dTransformScalars:()=>$r,formatAtlasMatrix:()=>Ct,formatBorderShapeElementStyle:()=>Ef,formatBorderShapeEntryMatrix:()=>Tf,formatBorderShapeMatrix:()=>gf,formatColor:()=>Ot,formatCornerShapeElementStyle:()=>vf,formatCssLength:()=>df,formatCssLengthPx:()=>yf,formatMatrix3d:()=>hf,formatMatrix3dValues:()=>an,formatPercent:()=>vn,formatScaledMatrixFromPlan:()=>At,formatSolidQuadEntryMatrix:()=>xf,formatSolidQuadMatrix:()=>ua,fullRectBounds:()=>Ia,getPolygonBasisInfo:()=>Pa,getSolidPaintDefaultsForPlansCore:()=>Df,groupReceiverFaceGroups:()=>er,icosahedronPolygons:()=>Di,incrementCount:()=>us,intersect2DLines:()=>Yr,intersect2DLinesRaw:()=>bf,inverseRotateVec3:()=>ec,isAxisAlignedSurfaceNormal:()=>Ci,isBakedShadowCaster:()=>Ul,isBasisOptimizable:()=>ba,isConvexPolygonPoints:()=>Tt,isFullRectBasis:()=>Ta,isFullRectSolid:()=>Dn,isProjectiveQuadPlan:()=>It,isSolidTrianglePlan:()=>nt,isVoxelCameraCullableNormalGroups:()=>Ll,loadMesh:()=>mf,makeLocalBasis:()=>tt,mergePolygons:()=>tn,meshScaleVec3:()=>Jo,normalFacesCamera:()=>gt,normalizeAtlasScale:()=>ot,normalizeInvertMultiplier:()=>cc,normalizePolygons:()=>Ao,normalizedSeamBleed:()=>Hr,octahedronPolygons:()=>Li,offsetConvexPolygonPoints:()=>et,offsetConvexPolygonPointsByEdgeAmounts:()=>Et,offsetStableTrianglePoints:()=>Wr,offsetTrianglePoints:()=>uo,optimizeAnimatedMeshPolygons:()=>Zu,optimizeMeshParseResult:()=>Yn,optimizeMeshPolygons:()=>ll,packTextureAtlasPlans:()=>_t,packTextureAtlasPlansWithScaleCore:()=>Uf,parseAlpha:()=>ro,parseColor:()=>Fn,parseGltf:()=>Rr,parseHex:()=>yn,parseHexColor:()=>hs,parseMtl:()=>Nr,parseObj:()=>wr,parsePureColor:()=>Pn,parseRgbColor:()=>ys,parseStl:()=>zr,parseVox:()=>Dr,planePolygons:()=>Vi,polyCameraTargetToCss:()=>Ss,polyCssDistanceToWorld:()=>$l,polyCssPositionToWorld:()=>Yl,polygonContainsPoint:()=>ma,polygonCssSurfaceNormal:()=>jo,polygonFaces:()=>Qa,polygonFacesCamera:()=>Rl,polygonSignedArea2D:()=>Ui,prepareCasterEdgeOwners:()=>lu,prepareCasterPolyItems:()=>uu,prepareReceiverFacePlanes:()=>fu,projectCssVertexToGround:()=>zl,projectTextureTriangle:()=>Ea,quantizeCssColor:()=>Sr,quatFromAxisAngle:()=>oc,quatFromEulerXYZ:()=>rc,quatMultiply:()=>tc,repairMeshSeams:()=>Hc,resolveAtlasLeafBox:()=>Da,resolveBleedRatio:()=>Pr,resolvePolyCameraAppliedPerspectiveStyle:()=>As,resolvePolyTextureImageRendering:()=>If,resolvePolyTextureImageSource:()=>go,resolvePolyTextureLeafGeometry:()=>ls,resolvePolyTexturePresentation:()=>ho,resolvePolyTextureUrl:()=>es,resolveProjectiveQuadGuards:()=>yo,resolveSeamBleed:()=>mo,rgbEqual:()=>ou,rgbKey:()=>Mr,rgbToCss:()=>su,rgbToHex:()=>so,ringPolygons:()=>Oi,ringQuadPolygons:()=>Ri,rotateVec3:()=>Co,rotateVec3InWrapperCssFrame:()=>On,roundDecimal:()=>Ne,safariCssProjectiveUnsupported:()=>wf,safePlanSeamBleedAmount:()=>po,screenToWorldOnSphere:()=>dc,screenToWorldRay:()=>Cs,seamBleedAmountArray:()=>Zr,seamFacetSplitPolygons:()=>Ws,seamFacetSplitReport:()=>jc,seamLightBrightness:()=>ts,seamOverlapDiagnostics:()=>Kc,seamOverlapPolygons:()=>js,seamOverlapReport:()=>qc,shadeColor:()=>Xa,shadePolygon:()=>Vn,sharedCornerShapeSide:()=>ha,signedArea2D:()=>Xr,simplifyCornerShapePoints:()=>pa,simplifyTriangleMeshPolygons:()=>Uo,spherePolygons:()=>wi,stableBasisFromPlan:()=>fo,stableTriangleMatrixDecimals:()=>jr,stepRgbToward:()=>ru,tetrahedronPolygons:()=>Ni,textureTintFactors:()=>io,tintToCss:()=>tu,torusPolygons:()=>ki,worldCssForMesh:()=>ht,worldDirectionToCss:()=>Qo,worldDirectionToPolyCss:()=>Wl,worldDirectionalLightToCss:()=>Xi,worldDirectionalLightToPolyCss:()=>jl,worldDistanceToCss:()=>zi,worldDistanceToPolyCss:()=>Gl,worldPositionToCss:()=>Qe,worldPositionToPolyCss:()=>Xl});module.exports=Wf(Ty);var ka="cubic";function hs(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 ys(e){let n=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)/i);return n?{rgb:[Number(n[1]),Number(n[2]),Number(n[3])],alpha:n[4]?Number(n[4]):1}:null}function Pn(e){if(!e)return null;let n=e.trim(),t=hs(n);return t||ys(n)}function _n(e){return Math.max(0,Math.min(255,Math.round(e)))}function Ot(e){let[n,t,o]=e.rgb.map(_n);return e.alpha<1?`rgba(${n}, ${t}, ${o}, ${e.alpha})`:`rgb(${n}, ${t}, ${o})`}var bs={rgb:[204,204,204],alpha:1},Ua=new Map;function Fn(e){if(!e)return null;let n=e.trim(),t=Ua.get(n);if(t)return t;let o=Pn(n);return o?(Ua.set(n,o),o):null}function Xa(e,n){let t=Fn(e)??bs,o=[_n(t.rgb[0]+n),_n(t.rgb[1]+n),_n(t.rgb[2]+n)];return Ot({rgb:o,alpha:t.alpha})}var xs={direction:[0,0,-1],color:"#ffffff",intensity:1},za={color:"#ffffff",intensity:.4};function Ga(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 $a(e,n,t){let o=Fn(n)??bs;return e*(o.rgb[t]/255)}function Ya(e,n,t,o){let r=Fn(n)??bs,s=Ga(t?.direction??xs.direction),i=t?.color??xs.color,a=Math.max(0,t?.intensity??xs.intensity),c=o?.color??za.color,l=Math.max(0,o?.intensity??za.intensity),u=Ga(e),f=Math.max(0,-(u[0]*s[0]+u[1]*s[1]+u[2]*s[2])),d=a*f,m=[0,0,0];for(let p=0;p<3;p=p+1){let h=r.rgb[p],g=$a(h,c,p)*l,y=$a(h,i,p)*d;m[p]=_n(g+y)}return Ot({rgb:m,alpha:r.alpha})}var Wa="#cccccc",Mo=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],ja=(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]],Ha=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],So=e=>Math.hypot(e[0],e[1],e[2]);function jf(e){let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let u of e)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);let a=r-n,c=s-t,l=i-o;return Math.hypot(a,c,l)}function Hf(){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 Ka(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function Za(e){return e?{...e}:void 0}function Kf(e){if(e)return{...e,imageSource:Ka(e.imageSource),presentation:Za(e.presentation)}}function Ao(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 s=r.vertices;if(s.length<3){t.push(`Polygon ${o}: ${s.length} vertices (need >= 3), dropped`);continue}let i=Mo(s[1],s[0]),a=Mo(s[2],s[0]),c=ja(i,a),l=So(c);if(s.length===3){if(l<1e-12){So(i)<1e-12||So(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:s.slice()}];if(s.length>=4){let f=[c[0]/l,c[1]/l,c[2]/l],d=Ha(f,s[0]),m=jf(s),p=Math.max(1e-6,m*.001),h=0;for(let g=3;g<s.length;g++){let y=Math.abs(Ha(f,s[g])-d);y>h&&(h=y)}if(h>p){let g=[],y=r.uvs&&r.uvs.length===s.length?r.uvs:void 0;for(let x=1;x<s.length-1;x++){let b=[s[0].slice(),s[x].slice(),s[x+1].slice()],P=ja(Mo(b[1],b[0]),Mo(b[2],b[0]));if(So(P)<1e-12)continue;let A={...r,vertices:b};y&&(A.uvs=[y[0].slice(),y[x].slice(),y[x+1].slice()]),g.push(A)}if(g.length===0){t.push(`Polygon ${o}: ${s.length} non-coplanar vertices, fan-triangulation produced no valid triangles, dropped`);continue}t.push(`Polygon ${o}: ${s.length} non-coplanar vertices, fan-triangulated to ${g.length} triangles`),u=g}}for(let f of u){let d=Zf(f,o,t);d&&n.push(d)}}return{polygons:n,warnings:t}}function Zf(e,n,t){let o={vertices:e.vertices},r=Kf(e.material),s=Ka(e.textureImageSource),i=Za(e.texturePresentation),a=r?.texture??e.texture??s?.url??r?.imageSource?.url;if(typeof a=="string"&&a===""&&(a=void 0),e.color!==void 0&&a!==void 0&&Hf()&&t.push(`Polygon ${n}: color and texture both set; texture wins`),e.color!==void 0&&(Fn(e.color)?o.color=e.color:(t.push(`Polygon ${n}: invalid color "${e.color}", replaced with ${Wa}`),o.color=Wa)),a!==void 0&&(o.texture=a,e.textureWrap&&(o.textureWrap={...e.textureWrap}),e.textureAlphaMode&&(o.textureAlphaMode=e.textureAlphaMode)),r&&(o.material=r),s&&(o.textureImageSource=s),i&&(o.texturePresentation=i),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 Ps(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,s=-1/0,i=-1/0,a=!1;for(let c of e)if(c?.vertices)for(let l of c.vertices)l&&(a=!0,l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]));return a?{min:[n,t,o],max:[r,s,i]}:{min:[0,0,0],max:[0,0,0]}}function qa(e){let n=e.polygons??[],t,o;if(e.skipNormalize)t=n,o=[];else{let a=Ao(n);t=a.polygons,o=a.warnings}let r=Ps(t),s=[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:s},warnings:o}}function Qa(e){return!e.vertices||e.vertices.length<3?[]:[{v:e.vertices.map(n=>[n[0],n[1],n[2]]),color:e.color}]}function qf(e){let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],s=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],i=r[1]*s[2]-r[2]*s[1],a=r[2]*s[0]-r[0]*s[2],c=r[0]*s[1]-r[1]*s[0],l=Math.hypot(i,a,c);return l<=1e-9?null:[i/l,a/l,c/l]}function Qf(e){let n=0;for(let t=0;t<e.length;t++){let[o,r]=e[t],[s,i]=e[(t+1)%e.length];n+=o*i-s*r}return Math.abs(n)/2}function Jf(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=qf(o);if(!r)return null;let s=1/0,i=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],h=[r[1]*p[2]-r[2]*p[1],r[2]*p[0]-r[0]*p[2],r[0]*p[1]-r[1]*p[0]],g=Math.hypot(h[0],h[1],h[2]);if(g<=1e-9)continue;let y=[h[0]/g,h[1]/g,h[2]/g],x=o.map(v=>{let I=v[0]-c[0],_=v[1]-c[1],O=v[2]-c[2];return[I*p[0]+_*p[1]+O*p[2],I*y[0]+_*y[1]+O*y[2]]}),b=1/0,P=1/0,A=-1/0,C=-1/0;for(let[v,I]of x)b=Math.min(b,v),P=Math.min(P,I),A=Math.max(A,v),C=Math.max(C,I);let E=A-b,S=C-P,M=Math.max(1,Math.ceil(E))*Math.max(1,Math.ceil(S)),T=Qf(x);T<=1e-9||M<s&&(s=M,i=T)}return!Number.isFinite(s)||i<=1e-9?null:{elementArea:s,polygonArea:i}}function Ja(e,n={}){let t=n.tileSize??100,o=n.layerElevation??t,r=n.texturedOnly??!0,s=0,i=0,a=0,c=0,l=0;for(let f of e){let d=!!f.texture;if(r&&!d)continue;let m=Jf(f.vertices,t,o);m&&(s+=1,d&&(i+=1),a+=m.elementArea,c+=m.polygonArea,l=Math.max(l,Math.max(0,m.elementArea-m.polygonArea)/m.elementArea))}let u=Math.max(0,a-c);return{totalPolygons:e.length,measuredPolygons:s,texturedPolygons:i,elementArea:a,polygonArea:c,transparentArea:u,transparentRatio:a>0?u/a:0,overdrawRatio:c>0?a/c:0,worstTransparentRatio:l}}function Co(e,n,t,o){let r=n*Math.PI/180,s=t*Math.PI/180,i=o*Math.PI/180,[a,c,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,c]=[a*u-c*f,a*f+c*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,l]=[a*u+l*f,-a*f+l*u]}if(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 ec(e,n){let t=-n[0]*Math.PI/180,o=-n[1]*Math.PI/180,r=-n[2]*Math.PI/180,[s,i,a]=e;if(t!==0){let c=Math.cos(t),l=Math.sin(t);[i,a]=[i*c-a*l,i*l+a*c]}if(o!==0){let c=Math.cos(o),l=Math.sin(o);[s,a]=[s*c+a*l,-s*l+a*c]}if(r!==0){let c=Math.cos(r),l=Math.sin(r);[s,i]=[s*c-i*l,s*l+i*c]}return[s,i,a]}function On(e,n){let[t,o,r]=e,s=-(n[2]??0)*Math.PI/180;if(s!==0){let c=Math.cos(s),l=Math.sin(s);[t,o]=[t*c-o*l,t*l+o*c]}let i=-(n[1]??0)*Math.PI/180;if(i!==0){let c=Math.cos(i),l=Math.sin(i);[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 Ms=Math.PI/180,Rt=180/Math.PI,nc=[1,0,0,0];function tc(e,n){let[t,o,r,s]=e,[i,a,c,l]=n;return[t*i-o*a-r*c-s*l,t*a+o*i+r*l-s*c,t*c-o*l+r*i+s*a,t*l+o*c-r*a+s*i]}function oc(e,n){let t=n*.5,o=Math.sin(t);return[Math.cos(t),e[0]*o,e[1]*o,e[2]*o]}function rc(e){let n=e[0]*Ms,t=e[1]*Ms,o=e[2]*Ms,r=Math.cos(n*.5),s=Math.sin(n*.5),i=Math.cos(t*.5),a=Math.sin(t*.5),c=Math.cos(o*.5),l=Math.sin(o*.5);return[r*i*c-s*a*l,s*i*c+r*a*l,r*a*c-s*i*l,r*i*l+s*a*c]}function sc(e){let[n,t,o,r]=e,s=2*(t*r+n*o),i=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,s)),f=Math.asin(u);return Math.abs(u)<.99999?[Math.atan2(-i,a)*Rt,f*Rt,Math.atan2(-c,l)*Rt]:[Math.atan2(2*(o*r+n*t),1-2*(t*t+r*r))*Rt,f*Rt,0]}var Ue=50;function cc(e){if(typeof e=="number")return e===0?void 0:e<0?-1:1;if(typeof e=="boolean")return e?-1:1}var Ee={target:[0,0,0],rotX:65,rotY:45,zoom:.65,distance:0};function Ss(e=Ee.target,n=[0,0,0],t=50){let o=e[0]+n[0],r=e[1]+n[1],s=e[2]+n[2];return[r*t,o*t,s*t]}function lc(e=Ee,n={}){let t=n.tileSize??50,o=n.layoutScale??1,r=e.target??Ee.target,[s,i,a]=Ss(r,n.autoCenterOffset,t),c=(e.zoom??Ee.zoom)/t*o,l=(e.distance??Ee.distance)*o,u=e.rotX??Ee.rotX,f=e.rotY??Ee.rotY;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${u}deg) rotate(${f}deg) translate3d(${-s}px, ${-i}px, ${-a}px)`}function As(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??Ee;return{projection:o,perspectiveStyle:t,appliedPerspectiveStyle:As(t),state:{target:[...r.target??Ee.target],rotX:r.rotX??Ee.rotX,rotY:r.rotY??Ee.rotY,zoom:r.zoom??Ee.zoom,distance:r.distance??Ee.distance}}}var ic=100,ac=1e4,ct=e=>Math.round(e*ic)/ic,em=e=>Math.round(e*ac)/ac;function fc(e={}){let n={target:e.target??[...Ee.target],rotX:e.rotX??Ee.rotX,rotY:e.rotY??Ee.rotY,zoom:e.zoom??Ee.zoom,distance:e.distance??Ee.distance};function t(r){r.target!==void 0&&(n.target=[ct(r.target[0]),ct(r.target[1]),ct(r.target[2])]),r.rotX!==void 0&&(n.rotX=ct(r.rotX)),r.rotY!==void 0&&(n.rotY=ct(r.rotY)),r.zoom!==void 0&&(n.zoom=em(r.zoom)),r.distance!==void 0&&(n.distance=ct(r.distance))}function o(r={}){let i=(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:`${i}px`,height:`${a}px`}}return{state:n,update:t,getStyle:o}}var mc=Math.PI/180;function Cs(e){let{camera:n,tileSize:t,viewportCenterX:o,viewportCenterY:r,mouseX:s,mouseY:i}=e,a=n.rotX*mc,c=n.rotY*mc,l=n.zoom/t,u=n.target,f=s-o,d=i-r,m=f/l,p=d/l,h=Math.cos(a),g=Math.sin(a),y=m,x=p*h,b=-p*g,P=0,A=g,C=h,E=Math.cos(c),S=Math.sin(c),M=y*E+x*S,T=-y*S+x*E,v=b,I=P*E+A*S,_=-P*S+A*E,O=C,R=u[1]*t,w=u[0]*t,F=u[2]*t,D=M+R,K=T+w,H=v+F,Q=[K/t,D/t,H/t],ne=[_/t,I/t,O/t];return{origin:Q,direction:ne}}function dc(e){let{origin:n,direction:t}=Cs(e),{sphereCenter:o,sphereRadius:r}=e,s=n[0]-o[0],i=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*(s*c+i*l+a*u),m=s*s+i*i+a*a-r*r,p=d*d-4*f*m;if(p>=0){let E=Math.sqrt(p),S=(-d-E)/(2*f),M=(-d+E)/(2*f),T=t[2]>=0?Math.max(S,M):Math.min(S,M);return[n[0]+T*t[0],n[1]+T*t[1],n[2]+T*t[2]]}let h=-(s*c+i*l+a*u)/f,g=n[0]+h*c,y=n[1]+h*l,x=n[2]+h*u,b=g-o[0],P=y-o[1],A=x-o[2],C=Math.hypot(b,P,A);return C===0?null:[o[0]+b/C*r,o[1]+P/C*r,o[2]+A/C*r]}var Rn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],To=(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]],Vt=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2],vs=e=>Math.hypot(e[0],e[1],e[2]),lt=(e,n)=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2];function nm(e){return`${e[0]},${e[1]},${e[2]}`}function hc(e){if(e.length<3)return null;let n=Rn(e[1],e[0]),t=Rn(e[2],e[0]),o=To(n,t),r=vs(o);if(r<1e-12)return null;let s=[o[0]/r,o[1]/r,o[2]/r],i=Vt(s,e[0]);return{normal:s,d:i}}function tm(e,n){return Vt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.05}function om(e,n){return Vt(e.normal,n.normal)<1-.001?!1:Math.abs(e.d-n.d)<.001}function rm(e,n,t,o){let r=e.vertices.findIndex(S=>lt(S,t)),s=e.vertices.findIndex(S=>lt(S,o)),i=n.vertices.findIndex(S=>lt(S,t)),a=n.vertices.findIndex(S=>lt(S,o));if(r<0||s<0||i<0||a<0)return null;let c=e.vertices.length,l=n.vertices.length,u=(r+1)%c===s,f=(i+1)%l===a;if(u===f)return null;let d=u?s:r,m=u?r:s,p=f?a:i,h=f?i:a,g=!!(e.uvs&&n.uvs),y=[],x=g?[]:void 0,b=d;for(;y.push(e.vertices[b]),x&&x.push(e.uvs[b]),b!==m;)b=(b+1)%c;for(b=p;y.push(n.vertices[b]),x&&x.push(n.uvs[b]),b!==h;)b=(b+1)%l;let P=[],A=x?[]:void 0;for(let S=0;S<y.length;S++)(P.length===0||!lt(y[S],P[P.length-1]))&&(P.push(y[S]),A&&x&&A.push(x[S]));if(P.length>1&&lt(P[0],P[P.length-1])&&(P.pop(),A?.pop()),g)return gc(P,A);let C=[],E=A?[]:void 0;for(let S=0;S<P.length;S++){let M=P[(S-1+P.length)%P.length],T=P[S],v=P[(S+1)%P.length],I=To(Rn(T,M),Rn(v,M));vs(I)>1e-9&&(C.push(T),E&&A&&E.push(A[S]))}return C.length<3?null:gc(C,E)}function sm(e,n){let t=e.length,o=0;for(let r=0;r<t;r++){let s=e[r],i=e[(r+1)%t],a=e[(r+2)%t],c=Rn(i,s),l=Rn(a,i),u=Vt(To(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 im(e,n){if(e.length<3)return!1;let t=hc(e);if(!t)return!1;for(let o of e)if(Math.abs(Vt(t.normal,o)-t.d)>n)return!1;return!0}function am(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function Ts(e){if(e)return{...e,sourceRect:e.sourceRect?{...e.sourceRect}:void 0}}function Es(e){return e?{...e}:void 0}function pc(e){if(e)return{...e,imageSource:Ts(e.imageSource),presentation:Es(e.presentation)}}function cm(e,n){return(e?.s??"")===(n?.s??"")&&(e?.t??"")===(n?.t??"")}function lm(e,n){return(e??"")===(n??"")}function um(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 gc(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],s=e[(t+2)%e.length];if(!(vs(To(Rn(r,o),Rn(s,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 tn(e){let n=[],t=[],o=new WeakMap,r=m=>{let p=o.get(m);if(p)return p;let h=nm(m);return o.set(m,h),h},s=(m,p)=>{let h=r(m),g=r(p);return h<g?`${h}|${g}`:`${g}|${h}`},i=(m,p)=>r(m)<r(p)?1:-1,a=m=>{let p=new Map;for(let h=0;h<m.length;h++){let g=m[h],y=m[(h+1)%m.length];p.set(s(g,y),i(g,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,h=hc(p);if(!h){n.push(m);continue}let g=m.texture&&m.uvs&&m.uvs.length===p.length?m.uvs.map(x=>[x[0],x[1]]):void 0,y=m.texture&&g?m.textureTriangles?.length?am(m.textureTriangles):um(p,g):void 0;t.push({vertices:p,uvs:g,color:m.color??"#cccccc",texture:m.texture,textureWrap:m.texture?m.textureWrap:void 0,textureAlphaMode:m.texture?m.textureAlphaMode:void 0,textureImageSource:Ts(m.textureImageSource),texturePresentation:Es(m.texturePresentation),material:pc(m.material),textureTriangles:y,normal:h.normal,d:h.d,edgeDirections:a(p),alive:!0,doubleSided:m.doubleSided===!0,data:m.data})}let f=()=>{let m=new Map;for(let g=0;g<t.length;g++){let y=t[g];if(!y.alive)continue;let x=y.vertices.length;if(!u(x))return!1;for(let b=0;b<x;b++){let P=y.vertices[b],A=y.vertices[(b+1)%x],C=s(P,A),E=m.get(C);E?E.second<0&&(E.second=g):(E={a:P,b:A,first:g,second:-1},m.set(C,E))}}let p=!1,h=(g,y,x)=>{let b=g.edgeDirections.get(s(y,x));return b?b===i(y,x)?1:-1:0};for(let g of m.values()){if(g.second<0)continue;let y=g.first,x=g.second;if(y===x)continue;let b=t[y],P=t[x];if(!b.alive||!P.alive||b.color!==P.color||b.texture!==P.texture||!cm(b.textureWrap,P.textureWrap)||!lm(b.textureAlphaMode,P.textureAlphaMode)||b.doubleSided!==P.doubleSided)continue;let A=!!(b.texture||P.texture);if(A&&(!b.textureTriangles||!P.textureTriangles)||!!b.uvs!=!!P.uvs||(A?!om(b,P):!tm(b,P)))continue;if(!u(b.vertices.length+P.vertices.length))return!1;let C=h(b,g.a,g.b);if(C===0)continue;let E=h(P,g.a,g.b);if(E===0||C===E)continue;let[S,M]=C===1?[g.a,g.b]:[g.b,g.a],T=rm(b,P,S,M);if(T){if(!u(T.vertices.length))return!1;T.vertices.length>96||im(T.vertices,.001)&&sm(T.vertices,b.normal)&&(b.vertices=T.vertices,b.uvs=T.uvs,b.edgeDirections=a(T.vertices),b.textureTriangles=A?[...b.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(h=>[h[0],h[1],h[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=Ts(m.textureImageSource)),m.texturePresentation&&(p.texturePresentation=Es(m.texturePresentation)),m.material&&(p.material=pc(m.material)),m.uvs&&(p.uvs=m.uvs.map(h=>[h[0],h[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 fm=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],mm=(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]],on=(e,n)=>e[0]*n[0]+e[1]*n[1]+e[2]*n[2];function dm(e,n){let t=e.vertices;if(!t||t.length<3)return null;let o=0,r=0,s=0;for(let h=0;h<t.length;h++){let g=t[h],y=t[(h+1)%t.length];o+=(g[1]-y[1])*(g[2]+y[2]),r+=(g[2]-y[2])*(g[0]+y[0]),s+=(g[0]-y[0])*(g[1]+y[1])}let i=Math.hypot(o,r,s);if(i<1e-12)return null;let a=[o/i,r/i,s/i],c=0,l=0,u=0;for(let h of t)c+=h[0],l+=h[1],u+=h[2];let f=1/t.length,d=[c*f,l*f,u*f],m=on(a,d),p=i*.5;return{index:n,polygon:e,normal:a,d:m,centroid:d,area:p,local2D:null,bbox2D:null,basis:null}}function pm(e,n){return e.polygon.doubleSided===!0&&n.polygon.doubleSided===!0&&on(e.normal,n.normal)<0}function gm(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=n[0]-e[0]*on(n,e),o=n[1]-e[1]*on(n,e),r=n[2]-e[2]*on(n,e),s=Math.hypot(t,o,r);t/=s,o/=s,r/=s;let i=[t,o,r],a=mm(e,i);return{u:i,v:a}}function hm(e){if(e.local2D)return;let n=gm(e.normal),t=[],o=1/0,r=1/0,s=-1/0,i=-1/0;for(let a of e.polygon.vertices){let c=on(a,n.u),l=on(a,n.v);t.push([c,l]),c<o&&(o=c),c>s&&(s=c),l<r&&(r=l),l>i&&(i=l)}e.local2D=t,e.bbox2D={min:[o,r],max:[s,i]},e.basis=n}function ym(e,n){let t=[],o=1/0,r=1/0,s=-1/0,i=-1/0;for(let a of e.vertices){let c=on(a,n.u),l=on(a,n.v);t.push([c,l]),c<o&&(o=c),c>s&&(s=c),l<r&&(r=l),l>i&&(i=l)}return{local2D:t,bbox2D:{min:[o,r],max:[s,i]}}}function xm(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 yc(e,n){let t=!1;for(let o=0,r=n.length-1;o<n.length;r=o++){let s=n[o],i=n[r];s[1]>e[1]!=i[1]>e[1]&&e[0]<(i[0]-s[0])*(e[1]-s[1])/(i[1]-s[1]+1e-30)+s[0]&&(t=!t)}return t}function xc(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 bm(e,n){let t=xc(e),o=xc(n),r=1e-4,s=0;for(let l of e){let u=[l[0]+(t[0]-l[0])*r,l[1]+(t[1]-l[1])*r];yc(u,n)&&s++}let i=0;for(let l of n){let u=[l[0]+(o[0]-l[0])*r,l[1]+(o[1]-l[1])*r];yc(u,e)&&i++}let a=s/e.length,c=i/n.length;return Math.max(a,c)}function Pm(e,n){let t=e.normal[0],o=e.normal[1],r=e.normal[2],s=Math.abs(t),i=Math.abs(o),a=Math.abs(r),c=t;i>s&&i>a?c=o:a>s&&a>i&&(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 Mm(e,n,t,o){let r=on(e.normal,n.normal);if(Math.abs(r)<1-t)return!1;let s=r>0?1:-1;return Math.abs(e.d-s*n.d)<o}function bc(e,n){let t=fm(n,e.centroid);return on(e.normal,t)>0}function Lt(e,n){if(!e||e.length<2)return new Set;let t=n?.normalTolerance??.001,o=n?.distanceTolerance??.05,r=n?.overlapFraction??.7,s=n?.preserveDoubleSidedBackfaces??!0,i=[];for(let p=0;p<e.length;p++){let h=dm(e[p],p);h&&i.push(h)}if(i.length<2)return new Set;let a=0,c=0,l=0,u=0;for(let p of i)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 i){let h=Pm(p,o),g=d.get(h);g||(g=[],d.set(h,g)),g.push(p)}let m=new Set;for(let p of d.values())if(!(p.length<2))for(let h=0;h<p.length;h++){let g=p[h];if(!m.has(g.index))for(let y=h+1;y<p.length;y++){let x=p[y];if(m.has(x.index)||!Mm(g,x,t,o)||s&&pm(g,x))continue;hm(g);let b=ym(x.polygon,g.basis);if(!xm(g.bbox2D,b.bbox2D)||bm(g.local2D,b.local2D)<r)continue;let A=bc(g,f),C=bc(x,f),E;if(A&&!C?E=g:C&&!A?E=x:E=g.area<x.area?g:x,m.add(E.index),E===g)break}}return m}function Pc(e,n){if(!e||e.length<2)return e??[];let t=Lt(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 Sm=4,Am=8,Cm=.001,Tm=1e-9,Em=1e6,vm=1e6,Im=8,Bn=(e,n)=>[e[0]-n[0],e[1]-n[1],e[2]-n[2]],Os=(e,n)=>[e[0]+n[0],e[1]+n[1],e[2]+n[2]],Dt=(e,n)=>[e[0]*n,e[1]*n,e[2]*n],kn=(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=>Math.hypot(e[0],e[1],e[2]);function Ft(e){let n=Tc(e);return n<=Tm?null:[e[0]/n,e[1]/n,e[2]/n]}function Nt(e,n){return Math.round(e*n)/n}function rn(e){return Nt(e,Em)}function Is(e){return Nt(e,vm)}function _s(e,n){return Math.abs(e[0]-n[0])<=1e-7&&Math.abs(e[1]-n[1])<=1e-7}function Mn(e){return`${rn(e[0])},${rn(e[1])}`}function _m(e){let n=Mn(e.a),t=Mn(e.b);return n<t?`${n}|${t}`:`${t}|${n}`}function ut(e){return`${e[0]},${e[1]},${e[2]}`}function Ec(e,n){let t=ut(e),o=ut(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Rs(e){return e?Object.keys(e).sort().map(n=>`${n}:${String(e[n])}`).join("|"):""}function Mc(e){return[e.color??"#cccccc",e.texture??"",e.uvs?"uv":"plain",e.doubleSided===!0?"double-sided":"single-sided",Rs(e.data)].join("|")}function vc(e){let n=e.vertices;if(!n||n.length<3)return null;let t=n[0],o=[0,0,0];for(let s=1;s<n.length-1;s++)o=Os(o,Cc(Bn(n[s],t),Bn(n[s+1],t)));let r=Ft(o);return r?{normal:r,d:kn(r,t)}:null}function Om(e,n,t){return kn(e.normal,n.normal)>1-t&&Math.abs(e.d-n.d)<=t}function Rm(e){return!e.texture&&!e.uvs&&!e.textureTriangles}function Vm(e,n){let t=n[e[0]]?.data,o=Rs(t);for(let r of e)if(Rs(n[r].data)!==o)return;return t?{...t}:void 0}function Lm(e,n){return e.every(t=>n[t].doubleSided===!0)}function wm(e,n){let t=e.map(c=>Rm(c)?vc(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=Ec(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 s=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||Mc(e[f])===Mc(e[d])&&Om(m,p,n)&&(s[f].add(d),s[d].add(f))}let i=new Set,a=[];for(let c=0;c<e.length;c++){if(!o[c]||i.has(c))continue;let l=[],u=[c];for(i.add(c);u.length>0;){let f=u.shift();l.push(f);for(let d of s[f])i.has(d)||(i.add(d),u.push(d))}a.push(l)}return{groups:a}}function Nm(e,n){let t=new Set(e),o=new Map;for(let s of e){let i=n[s].vertices;for(let a=0;a<i.length;a++){let c=Ec(i[a],i[(a+1)%i.length]),l=o.get(c),u={polygon:s,edge:a};l?l.push(u):o.set(c,[u])}}let r=[];for(let s of o.values()){let i=s.filter(a=>t.has(a.polygon));if(i.length===1){let a=i[0],c=n[a.polygon].vertices;r.push({a:c[a.edge],b:c[(a.edge+1)%c.length]})}else if(i.length!==2)return null}return r}function Dm(e){let n=new Map;for(let t of e)n.set(ut(t.a),(n.get(ut(t.a))??0)+1),n.set(ut(t.b),(n.get(ut(t.b))??0)+1);for(let t of n.values())if(t%2!==0)return!1;return!0}function Ic(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 Fm(e){let n=Ic(e);return`${Nt(n[0],1e3)},${Nt(n[1],1e3)},${Nt(n[2],1e3)}`}function Bm(e){let n=Math.abs(e[0])<.9?[1,0,0]:[0,1,0],t=Bn(n,Dt(e,kn(n,e)));return Ft(t)??[1,0,0]}function km(e,n,t){let o=new Map;for(let s of e){let i=Bn(s.b,s.a),a=Bn(i,Dt(n,kn(i,n))),c=Ft(a);if(!c)continue;let l=Ic(c),u=Fm(l),f=Tc(a),d=o.get(u);d?d.weight+=f:o.set(u,{axis:l,weight:f})}let r=[...o.values()].sort((s,i)=>i.weight-s.weight).slice(0,t).map(s=>s.axis);return r.length===0&&r.push(Bm(n)),r}function Sc(e,n,t,o){let r=Bn(e,n);return[rn(kn(r,t)),rn(kn(r,o))]}function Um(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,s]=e.b,i=(n-t)/(r-t);return rn(o+(s-o)*i)}function Vs(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],s=n[o],i=n[(o+1)%n.length],a=(s[0]-r[0])*(i[1]-s[1])-(s[1]-r[1])*(i[0]-s[0]);Math.abs(a)>1e-8&&t.push(s)}return t}function vo(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 Io(e){let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let[s,i]of e)n=Math.min(n,s),t=Math.min(t,i),o=Math.max(o,s),r=Math.max(r,i);return{minX:n,minY:t,maxX:o,maxY:r}}function _c(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 Eo(e){return Math.abs(vo(e))}function zm(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-8)continue;let a=i>0?1:-1;if(n===0)n=a;else if(n!==a)return!1}return!0}function Gm(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],s=e[0]-n[0],i=e[1]-n[1],a=o*i-r*s,c=Math.hypot(o,r);if(c<=1e-9||Math.abs(a)>Math.max(1e-8,c*1e-8))return!1;let l=s*o+i*r;return l>=-1e-8&&l<=o*o+r*r+1e-8}function $m(e,n,t){let o=t[0]-n[0],r=t[1]-n[1],s=o*o+r*r;return s<=1e-12?0:((e[0]-n[0])*o+(e[1]-n[1])*r)/s}function Xm(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],a=o[1]-t[1],c=Math.hypot(r,s),l=Math.hypot(i,a);if(c<=1e-9||l<=1e-9)return!1;let u=r*(t[1]-e[1])-s*(t[0]-e[0]),f=r*(o[1]-e[1])-s*(o[0]-e[0]),d=r*a-s*i,m=Math.max(1e-8,Math.max(c,l)*1e-8);if(Math.abs(u)>m||Math.abs(f)>m||Math.abs(d)>m)return!1;let p=Math.abs(r)>=Math.abs(s),h=Math.min(p?e[0]:e[1],p?n[0]:n[1]),g=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]),x=Math.max(p?t[0]:t[1],p?o[0]:o[1]);return Math.min(g,x)-Math.max(h,y)>1e-8}function Ym(e,n){for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];for(let s=0;s<n.length;s++)if(Xm(o,r,n[s],n[(s+1)%n.length]))return!0}return!1}function Ac(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o],s=e[(o+1)%e.length],i=[{t:0,point:r},{t:1,point:s}];for(let c of n)_s(c,r)||_s(c,s)||Gm(c,r,s)&&i.push({t:$m(c,r,s),point:c});i.sort((c,l)=>c.t-l.t);let a=[];for(let c of i)a.some(l=>Math.abs(l.t-c.t)<=1e-8||_s(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:[rn(l[0]),rn(l[1])],b:[rn(u[0]),rn(u[1])]})}}return t}function Wm(e,n,t=Io(e),o=Io(n)){if(!_c(t,o)||!Ym(e,n))return null;let r=[...Ac(e,n),...Ac(n,e)],s=new Map;for(let y of r){let x=_m(y),b=s.get(x);b?b.push(y):s.set(x,[y])}let i=!1,a=[];for(let y of s.values()){if(y.length===1){a.push(y[0]);continue}i=!0;let x=y.filter(P=>Mn(P.a)<Mn(P.b)).length,b=y.length-x;if(x!==b)return null}if(!i||a.length<3)return null;let c=new Map;for(let y of a){let x=Mn(y.a);if(c.has(x))return null;c.set(x,y)}let l=a[0],u=Mn(l.a),f=[],d=new Set,m=u;for(let y=0;y<=a.length;y++){let x=c.get(m);if(!x)return null;let b=`${Mn(x.a)}>${Mn(x.b)}`;if(d.has(b))return null;if(d.add(b),f.push(x.a),m=Mn(x.b),m===u)break}if(m!==u||d.size!==a.length)return null;let p=Vs(f);if(p.length<3||!zm(p))return null;let h=Eo(p),g=Eo(e)+Eo(n);return Math.abs(h-g)>Math.max(1e-5,g*1e-5)?null:vo(p)>=0?p:[...p].reverse()}function jm(e){let n=e.map(Vs).filter(r=>r.length>=3&&Eo(r)>1e-8),t=n.map(Io),o=!0;for(;o;){o=!1;for(let r=0;r<n.length;r++){for(let s=r+1;s<n.length;s++){if(!_c(t[r],t[s]))continue;let i=Wm(n[r],n[s],t[r],t[s]);if(i){n[r]=i,t[r]=Io(i),n.splice(s,1),t.splice(s,1),o=!0;break}}if(o)break}}return n}function Hm(e,n,t){let o=new Map;return r=>{let s=rn(r[0]),i=rn(r[1]),a=`${s},${i}`,c=o.get(a);if(c)return[c[0],c[1],c[2]];let l=Os(e,Os(Dt(n,s),Dt(t,i))),u=[Is(l[0]),Is(l[1]),Is(l[2])];return o.set(a,u),[u[0],u[1],u[2]]}}function Km(e,n,t,o,r){let s=t[0]?.a;if(!s)return null;let i=Ft(Bn(r,Dt(o,kn(r,o))));if(!i)return null;let a=Ft(Cc(o,i));if(!a)return null;let c=[],l=[];for(let y of t){let x=Sc(y.a,s,i,a),b=Sc(y.b,s,i,a);Math.hypot(x[0]-b[0],x[1]-b[1])<=1e-7||(c.push({a:x,b}),l.push(x[0],b[0]))}let u=Um(l);if(c.length<3||u.length<2)return null;let f=n[e[0]].color,d=Vm(e,n),m=Lm(e,n),p=[];for(let y=0;y<u.length-1;y++){let x=u[y],b=u[y+1];if(b-x<=1e-7)continue;let P=(x+b)/2,A=c.filter(C=>{let E=Math.min(C.a[0],C.b[0]),S=Math.max(C.a[0],C.b[0]);return E<P&&P<S&&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(A.length!==0){if(A.length%2!==0)return null;for(let C=0;C<A.length;C+=2){let E=A[C].segment,S=A[C+1].segment,M=wt(E,x),T=wt(E,b),v=wt(S,x),I=wt(S,b),_=Vs([[x,M],[b,T],[b,I],[x,v]]);if(_.length<3||Math.abs(vo(_))<=1e-8)continue;let O=vo(_)>0?_:[..._].reverse();p.push(O)}}}if(p.length===0||e.length>2&&p.length>e.length*Im)return null;let h=Hm(s,i,a),g=jm(p).map(y=>({vertices:y.map(h),...f?{color:f}:{},...m?{doubleSided:!0}:{},...d?{data:d}:{}}));return tn(g)}function Zm(e,n,t){let o=Nm(e,n);if(!o||o.length<3||!Dm(o))return null;let r=vc(n[e[0]]);if(!r)return null;let s=null;for(let i of km(o,r.normal,t)){let a=Km(e,n,o,r.normal,i);a&&(!s||a.length<s.length)&&(s=a)}return!s||s.length>=e.length?null:s}function _o(e,n={}){let t=n.minGroupPolygons??Sm,o=n.maxCandidateAxes??Am,r=n.planeEpsilon??Cm,s=e??[];if(s.length<t)return s;let{groups:i}=wm(s,r);if(i.length===0)return s;let a=new Map,c=new Set;for(let u of i){if(u.length<t)continue;let f=Zm(u,s,o);if(f){a.set(u[0],f);for(let d of u)c.add(d)}}if(a.size===0)return s;let l=[];for(let u=0;u<s.length;u++){let f=a.get(u);if(f){l.push(...f);continue}c.has(u)||l.push(s[u])}return l}function qm(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 Qm(e){if(e.length<100)return!1;let n=new Map;for(let o of e){let r=o.vertices;for(let s=0;s<r.length;s++){let i=qm(r[s],r[(s+1)%r.length]);n.set(i,(n.get(i)??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 Jm(e,n,t){let o=Math.abs(e)>.9?0:1,r=Math.abs(e)>.9?1:0,s=r*t,i=-o*t,a=o*n-r*e,c=Math.hypot(s,i,a);return s/=c,i/=c,a/=c,{ux:s,uy:i,uz:a,vx:n*a-t*i,vy:t*s-e*a,vz:e*i-n*s}}function ed(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[K,H,Q]of n)t+=K,o+=H,r+=Q;let s=1/n.length;t*=s,o*=s,r*=s;let i=n[0],a=n[1],c=n[2],l=a[0]-i[0],u=a[1]-i[1],f=a[2]-i[2],d=c[0]-i[0],m=c[1]-i[1],p=c[2]-i[2],h=u*p-f*m,g=f*d-l*p,y=l*m-u*d,x=Math.hypot(h,g,y);if(x<1e-9)return null;h/=x,g/=x,y/=x;let{ux:b,uy:P,uz:A,vx:C,vy:E,vz:S}=Jm(h,g,y),M=n.length-2,T=new Float64Array(M*9),v=0;for(let K=1;K<n.length-1;K++){let H=n[0],Q=n[K],ne=n[K+1];T[v++]=H[0],T[v++]=H[1],T[v++]=H[2],T[v++]=Q[0],T[v++]=Q[1],T[v++]=Q[2],T[v++]=ne[0],T[v++]=ne[1],T[v++]=ne[2]}let I=0,_=1/0,O=1/0,R=1/0,w=-1/0,F=-1/0,D=-1/0;for(let[K,H,Q]of n){let ne=K-t,ee=H-o,ue=Q-r,U=ne*ne+ee*ee+ue*ue;U>I&&(I=U),K<_&&(_=K),K>w&&(w=K),H<O&&(O=H),H>F&&(F=H),Q<R&&(R=Q),Q>D&&(D=Q)}return{centroid:[t,o,r],normal:[h,g,y],vertices:n,triFlat:T,bcx:t,bcy:o,bcz:r,br2:I,ux:b,uy:P,uz:A,vx:C,vy:E,vz:S,minX:_,minY:O,minZ:R,maxX:w,maxY:F,maxZ:D}}function nd(e,n,t,o,r,s,i,a){let c=i[a],l=i[a+1],u=i[a+2],f=i[a+3]-c,d=i[a+4]-l,m=i[a+5]-u,p=i[a+6]-c,h=i[a+7]-l,g=i[a+8]-u,y=r*g-s*h,x=s*p-o*g,b=o*h-r*p,P=f*y+d*x+m*b;if(P>-1e-9&&P<1e-9)return!1;let A=1/P,C=e-c,E=n-l,S=t-u,M=A*(C*y+E*x+S*b);if(M<0||M>1)return!1;let T=E*m-S*d,v=S*f-C*m,I=C*d-E*f,_=A*(o*T+r*v+s*I);return _<0||M+_>1?!1:A*(p*T+h*v+g*I)>.001}function td(e,n,t,o,r,s,i){let a=i.bcx-e,c=i.bcy-n,l=i.bcz-t,u=a*o+c*r+l*s,f=a-u*o,d=c-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,h=p.length;for(let g=0;g<h;g+=9)if(nd(e,n,t,o,r,s,p,g))return!0;return!1}var Bt=9,od=6,ze=8;function Ls(e,n,t,o,r,s){let i=o-e,a=r-n,c=s-t;return i*a+a*c+c*i}function rd(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),s=new Float64Array(t),i=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,s[C]=(E.minY+E.maxY)*.5,i[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*Bt),l=0,u=new Float64Array(ze),f=new Float64Array(ze),d=new Float64Array(ze),m=new Float64Array(ze),p=new Float64Array(ze),h=new Float64Array(ze),g=new Int32Array(ze),y=new Float64Array(ze-1),x=new Int32Array(ze-1),b=new Float64Array(ze-1),P=new Int32Array(ze-1);function A(C,E){let S=l++,M=S*Bt,T=E-C,v=1/0,I=1/0,_=1/0,O=-1/0,R=-1/0,w=-1/0;for(let z=C;z<E;z++){let te=e[o[z]];te.minX<v&&(v=te.minX),te.maxX>O&&(O=te.maxX),te.minY<I&&(I=te.minY),te.maxY>R&&(R=te.maxY),te.minZ<_&&(_=te.minZ),te.maxZ>w&&(w=te.maxZ)}if(c[M]=v,c[M+1]=I,c[M+2]=_,c[M+3]=O,c[M+4]=R,c[M+5]=w,T<=od)return c[M+6]=1,c[M+7]=C,c[M+8]=E,S;let F=1/0,D=1/0,K=1/0,H=-1/0,Q=-1/0,ne=-1/0;for(let z=C;z<E;z++)r[z]<F&&(F=r[z]),r[z]>H&&(H=r[z]),s[z]<D&&(D=s[z]),s[z]>Q&&(Q=s[z]),i[z]<K&&(K=i[z]),i[z]>ne&&(ne=i[z]);let ee=H-F,ue=Q-D,U=ne-K;if(ee===0&&ue===0&&U===0)return c[M+6]=1,c[M+7]=C,c[M+8]=E,S;let $=Ls(v,I,_,O,R,w),k=$>0?1/$:0,L=T+1,W=0,Y=0;for(let z=0;z<3;z++){let te=z===0?F:z===1?D:K,ce=z===0?ee:z===1?ue:U;if(ce===0)continue;let ye=z===0?r:z===1?s:i,he=ze/ce;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),h.fill(-1/0),g.fill(0);for(let N=C;N<E;N++){let X=(ye[N]-te)*he|0;X>=ze&&(X=ze-1);let oe=e[o[N]];oe.minX<u[X]&&(u[X]=oe.minX),oe.maxX>m[X]&&(m[X]=oe.maxX),oe.minY<f[X]&&(f[X]=oe.minY),oe.maxY>p[X]&&(p[X]=oe.maxY),oe.minZ<d[X]&&(d[X]=oe.minZ),oe.maxZ>h[X]&&(h[X]=oe.maxZ),g[X]++}let xe=1/0,ge=1/0,Ae=1/0,Fe=-1/0,V=-1/0,G=-1/0,j=0;for(let N=0;N<ze-1;N++)u[N]<xe&&(xe=u[N]),m[N]>Fe&&(Fe=m[N]),f[N]<ge&&(ge=f[N]),p[N]>V&&(V=p[N]),d[N]<Ae&&(Ae=d[N]),h[N]>G&&(G=h[N]),j+=g[N],y[N]=Ls(xe,ge,Ae,Fe,V,G),x[N]=j;let J=1/0,le=1/0,re=1/0,pe=-1/0,be=-1/0,ie=-1/0,ae=0;for(let N=ze-2;N>=0;N--){let X=N+1;u[X]<J&&(J=u[X]),m[X]>pe&&(pe=m[X]),f[X]<le&&(le=f[X]),p[X]>be&&(be=p[X]),d[X]<re&&(re=d[X]),h[X]>ie&&(ie=h[X]),ae+=g[X],b[N]=Ls(J,le,re,pe,be,ie),P[N]=ae}for(let N=0;N<ze-1;N++){if(x[N]===0||P[N]===0)continue;let X=.125+(y[N]*x[N]+b[N]*P[N])*k;X<L&&(L=X,W=z,Y=te+(N+1)/he)}}let se=W===0?r:W===1?s:i,Z=C,B=E-1;for(;Z<=B;)if(se[Z]<Y)Z++;else{let z=o[Z];o[Z]=o[B],o[B]=z;let te=r[Z];r[Z]=r[B],r[B]=te;let ce=s[Z];s[Z]=s[B],s[B]=ce;let ye=i[Z];i[Z]=i[B],i[B]=ye,B--}let q=Z;(q===C||q===E)&&(q=C+E>>1),c[M+6]=0;let me=A(C,q),fe=A(q,E);return c[S*Bt+7]=me,c[S*Bt+8]=fe,S}return t>0&&A(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function ws(e,n,t,o,r,s,i,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=s!==0?1/s:s>=0?1/0:-1/0,h=0;for(c[h++]=0;h>0;){let y=c[--h]*Bt,x=(l[y]-e)*d,b=(l[y+3]-e)*d,P=x<b?x:b,A=x<b?b:x,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,S=C<E?C:E,M=C<E?E:C;if(P>M||S>A)continue;S>P&&(P=S),M<A&&(A=M);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,I=T<v?T:v,_=T<v?v:T;if(!(P>_||I>A)&&(_<A&&(A=_),!(A<.001)))if(l[y+6]===1){let O=l[y+7]|0,R=l[y+8]|0;for(let w=O;w<R;w++){let F=u[w];if(F===i)continue;let D=f[F];if(D&&td(e,n,t,o,r,s,D))return!0}}else c[h++]=l[y+7]|0,c[h++]=l[y+8]|0}return!1}function sd(e){let n=Oc.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 s=(r+.5)/e,i=Math.sqrt(Math.max(0,1-s*s)),a=2*Math.PI*(r/t);o[r*3]=i*Math.cos(a),o[r*3+1]=i*Math.sin(a),o[r*3+2]=s}return Oc.set(e,o),o}var Oc=new Map;function fn(e,n){let t=n?.samples??8;if(e.length<4||t<1||!n?.force&&Qm(e))return e;let o=Math.max(1,Math.ceil(t*(n?.minEscapeRatio??1/t))),r=e.map(ed),s=sd(t),i=[],a=rd(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){i.push(e[f]);continue}let m=d.normal[0],p=d.normal[1],h=d.normal[2],g=.001*m,y=.001*p,x=.001*h;{let R=d.centroid[0]+g,w=d.centroid[1]+y,F=d.centroid[2]+x;if(!ws(R,w,F,m,p,h,f,a,c)){i.push(e[f]);continue}}let{ux:b,uy:P,uz:A,vx:C,vy:E,vz:S}=d,M=d.centroid[0],T=d.centroid[1],v=d.centroid[2],I=d.vertices,_=I.length,O=0;u[O++]=M+g,u[O++]=T+y,u[O++]=v+x;for(let R=0;R<_;R++){let w=I[R];u[O++]=w[0]+(M-w[0])*.08+g,u[O++]=w[1]+(T-w[1])*.08+y,u[O++]=w[2]+(v-w[2])*.08+x}for(let R=0;R<_;R++){let w=I[R],F=I[(R+1)%_],D=(w[0]+F[0])*.5,K=(w[1]+F[1])*.5,H=(w[2]+F[2])*.5;u[O++]=D+(M-D)*.08+g,u[O++]=K+(T-K)*.08+y,u[O++]=H+(v-H)*.08+x}if(o<=1){let R=!1;e:for(let w=0;w<s.length;w+=3){let F=s[w],D=s[w+1],K=s[w+2],H=F*b+D*C+K*m,Q=F*P+D*E+K*p,ne=F*A+D*S+K*h;for(let ee=0;ee<O;ee+=3){let ue=u[ee],U=u[ee+1],$=u[ee+2];if(!ws(ue,U,$,H,Q,ne,f,a,c)){R=!0;break e}}}R&&i.push(e[f])}else{let R=0;for(let w=0;w<s.length;w+=3){let F=s[w],D=s[w+1],K=s[w+2],H=F*b+D*C+K*m,Q=F*P+D*E+K*p,ne=F*A+D*S+K*h;for(let ee=0;ee<O;ee+=3){let ue=u[ee],U=u[ee+1],$=u[ee+2];if(!ws(ue,U,$,H,Q,ne,f,a,c)){R++;break}}}R>=o&&i.push(e[f])}}return i}var ks={overlapPx:1.25,maxGapPx:14,capacityScale:1},Us={budget:40};function Un(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function ft(e){return typeof e=="number"?{overlapPx:Math.max(0,e)*.175,maxGapPx:14,capacityScale:1}:{overlapPx:Math.max(0,Un(e?.overlapPx,1.25)),maxGapPx:Math.max(0,Un(e?.maxGapPx,14)),capacityScale:Math.max(0,Un(e?.capacityScale,1))}}function mt(e,n){return!(typeof n=="number"&&n<=0)&&e.maxGapPx>1e-6&&e.capacityScale>1e-6}function Fc(e){return{rotX:Un(e?.rotX,65),rotY:Un(e?.rotY,45),viewAware:e?.viewAware!==!1,passes:Math.max(1,Math.min(3,Math.round(Un(e?.passes,2)))),budget:Math.max(0,Math.min(256,Math.round(Un(e?.budget,40))))}}function Sn(e){return e.map(n=>[n[1]*50,n[0]*50,n[2]*50])}function Bc(e){return[e[1]/50,e[0]/50,e[2]/50]}function No(e){return`${e[0]},${e[1]},${e[2]}`}function id(e,n){let t=No(e),o=No(n);return t<o?`${t}|${o}`:`${o}|${t}`}function An(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function dt(e){return Math.hypot(e[0],e[1],e[2])}function Gt(e){let n=dt(e);return n>1e-6?[e[0]/n,e[1]/n,e[2]/n]:null}function zt(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Oo(e,n,t,o){let r=n*Math.PI/180,s=t*Math.PI/180,i=o*Math.PI/180,[a,c,l]=e;if(i!==0){let u=Math.cos(i),f=Math.sin(i);[a,c]=[a*u-c*f,a*f+c*u]}if(s!==0){let u=Math.cos(s),f=Math.sin(s);[a,l]=[a*u+l*f,-a*f+l*u]}if(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 zs(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 ad(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=An(e[o],n),s=An(e[o+1],n),i=zs(r,s);t[0]-=i[0],t[1]-=i[1],t[2]-=i[2]}return Gt(t)}function Gs(e){let n=e[0],t=ad(e);if(!t)return null;let o=null;for(let u=0;u<e.length;u+=1){let f=An(e[(u+1)%e.length],e[u]);if(dt(f)>1e-6){o=f;break}}if(!o)return null;let r=zt(o,t),s=[o[0]-r*t[0],o[1]-r*t[1],o[2]-r*t[2]],i=Gt(s);if(!i)return null;let a=Gt(zs(t,i));if(!a)return null;let c=e.map(u=>{let f=An(u,n);return[zt(f,i),zt(f,a)]}),l=Do(c);return Math.abs(l)>1e-6?{origin:n,normal:t,xAxis:i,yAxis:a,local:c,area:l}:null}function Do(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 $s(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=1e-6)continue;let a=Math.sign(i);if(n===0)n=a;else if(a!==n)return!1}return!0}function kc(e,n,t){let o=e[t],r=e[(t+1)%e.length],s=r[0]-o[0],i=r[1]-o[1],a=Math.hypot(s,i);if(a<=1e-6)return null;let c=n>0?1:-1;return[c*(i/a),c*(-s/a)]}function cd(e,n){let t=kc(e.local,e.area,n);return t?Gt([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 Uc(e,n){let t=e.length,o=e[n],r=e[(n+1)%t],s=r[0]-o[0],i=r[1]-o[1],a=Math.hypot(s,i);if(a<=1e-6)return 0;let c=[a*.24],l=1/0;for(let f=0;f<t;f+=1){if(f===n||f===(n+1)%t)continue;let d=e[f],m=Math.abs((d[0]-o[0])*i-(d[1]-o[1])*s)/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 h=Math.abs(s*m-i*d)/(a*p);h>1e-6&&c.push(p*h*.32)}return Math.min(...c)}function zc(e){return e.map(n=>{let t=Sn(n.vertices),o=Gs(t),r=!Xs(n)&&!!o&&$s(o.local),s=r?o.local.map((i,a)=>Uc(o.local,a)):[];return{basis:o,cssPoints:t,capacities:s,patchable:r}})}function Xs(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function ld(e){return e.material?.key??e.color??""}function Gc(e,n,t){let o=[];for(let r=0;r<n.length;r+=1){let s=n[r];if(!(!s.patchable||!s.basis))for(let i=0;i<s.cssPoints.length;i+=1){let a=s.cssPoints[i],c=s.cssPoints[(i+1)%s.cssPoints.length],l=An(c,a),u=dt(l),f=Gt(l),d=cd(s.basis,i),m=(s.capacities[i]??0)*t;!f||!d||m<=1e-6||u<=1e-6||o.push({index:o.length,polygon:r,edge:i,key:id(a,c),a,b:c,minX:Math.min(a[0],c[0]),minY:Math.min(a[1],c[1]),minZ:Math.min(a[2],c[2]),maxX:Math.max(a[0],c[0]),maxY:Math.max(a[1],c[1]),maxZ:Math.max(a[2],c[2]),length:u,dir:f,normal:s.basis.normal,outward:d,capacity:m,materialKey:ld(e[r]),color:e[r].color})}}return o}function Ys(e,n){return e.materialKey===n.materialKey&&e.color===n.color}function Ro(e,n){return dt(An(e,n))<=1e-4}function ud(e,n){return Ro(e.a,n.a)||Ro(e.a,n.b)||Ro(e.b,n.a)||Ro(e.b,n.b)}function fd(e,n){return Ys(e,n)?ud(e,n)?"connected-facet":"true-gap":"material-boundary"}function Ns(e,n,t,o,r,s){return{kind:e,aPolygon:n.polygon,aEdge:n.edge,bPolygon:t.polygon,bEdge:t.edge,aColor:n.color,bColor:t.color,aMaterialKey:n.materialKey,bMaterialKey:t.materialKey,gapPx:o.gap,spanPx:o.aEnd-o.aStart,aStartPx:o.aStart,aEndPx:o.aEnd,bStartPx:o.bStart,bEndPx:o.bEnd,targetClosurePx:r,appliedClosurePx:s,residualGapPx:Math.max(0,o.gap-s),residualTargetPx:Math.max(0,r-s)}}function Rc(e,n,t,o,r){let s=Math.max(0,Math.min(n.length,Math.min(t,o))),i=Math.max(0,Math.min(n.length,Math.max(t,o)));if(r<=1e-6||i-s<=1e-6)return;let a=e[n.polygon].get(n.edge),c={start:s,end:i,amount:r};a?a.push(c):e[n.polygon].set(n.edge,[c])}function Fo(){return{exactPairs:0,nearPairs:0,patchedPolygons:0,patchedEdges:0,maxMeasuredGapPx:0,maxAppliedAmountPx:0,unclosedPairs:0,maxResidualGapPx:0}}function md(e,n){let t=0,o=0,r=0;for(let s of e){s.size>0&&(r+=1),o+=s.size;for(let i of s.values())for(let a of i)t=Math.max(t,a.amount)}return{...n,patchedPolygons:r,patchedEdges:o,maxAppliedAmountPx:t}}function Bo(e,n,t=!1,o=!1){let r=zc(e),s=Gc(e,r,n.capacityScale),i=o?[]:e.map(()=>new Map),a=Fo(),c=t?[]:void 0;if(s.length===0)return{edgeRepairs:i,diagnostics:a,candidates:c};let l=new Map;for(let u of s){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 dd(s,l,i,a,n,c),{edgeRepairs:i,diagnostics:o?a:md(i,a),candidates:c}}function dd(e,n,t,o,r,s){let i=r.maxGapPx,a=new Set;for(let[m,p]of n)p.length>1&&a.add(m);let c=(m,p)=>{let h=m.index<p.index?m:p,g=m.index<p.index?p:m;if(g.polygon===h.polygon||h.key===g.key&&a.has(h.key)||!s&&!Ys(h,g)||!pd(h,g,i)||Math.abs(zt(h.dir,g.dir))<.985)return;let y=xd(h,g,i);if(!y)return;let x=fd(h,g),b=y.gap+r.overlapPx;if(x==="material-boundary"){s?.push(Ns(x,h,g,y,b,0));return}let P=b;if(P<=.25){s?.push(Ns(x,h,g,y,b,0));return}let A=h.capacity*y.facingA,C=g.capacity*y.facingB,E=Math.min(A,P/2),S=Math.min(C,P/2);if(P-=E+S,P>1e-6){let M=Math.min(A-E,P);E+=M,P-=M}if(P>1e-6){let M=Math.min(C-S,P);S+=M,P-=M}s?.push(Ns(x,h,g,y,b,E+S)),t.length>0&&E>1e-6&&Rc(t,h,y.aStart,y.aEnd,E/y.facingA),t.length>0&&S>1e-6&&Rc(t,g,y.bStart,y.bEnd,S/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,i*2);if(e.length<=1e4){let m=[...e].sort((g,y)=>g.minX-y.minX),p=new Int32Array(m.length),h=0;for(let g=0;g+1<m.length;g+=1){let x=m[g].maxX+i,b=g+1;for(;b<m.length&&m[b].minX<=x;)b+=1;if(p[g]=b,h+=b-g-1,h>25e6)break}if(h<=2e6||h<=25e6&&yd(e,l,i)){for(let g=0;g+1<m.length;g+=1)for(let y=g+1;y<p[g];y+=1)c(m[g],m[y]);return}}let u=new Map;for(let m of e)gd(u,m,l,i);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 h=p+1;h<m.length;h+=1){let g=m[p],y=m[h],x=g.index<y.index?g:y,b=g.index<y.index?y:g,P=x.index*d+b.index;f.has(P)||(f.add(P),c(x,b))}}function pd(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 Vc(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function gd(e,n,t,o){let[r,s,i,a,c,l]=$c(n,t,o);for(let u=r;u<=a;u+=1)for(let f=s;f<=c;f+=1)for(let d=i;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function $c(e,n,t){let[o,r,s]=Vc([e.minX-t,e.minY-t,e.minZ-t],n),[i,a,c]=Vc([e.maxX+t,e.maxY+t,e.maxZ+t],n);return[o,r,s,i,a,c]}function hd(e,n,t){let[o,r,s,i,a,c]=$c(e,n,t);return(i-o+1)*(a-r+1)*(c-s+1)}function yd(e,n,t){let o=0,r=0;for(let s of e){let i=hd(s,n,t);if(o+=i,i>r&&(r=i),r>8192)return!0}return o/Math.max(1,e.length)>256}function Lc(e,n,t){return(e[0]-n[0])*t[0]+(e[1]-n[1])*t[1]+(e[2]-n[2])*t[2]}function wc(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 xd(e,n,t){let o=Lc(n.a,e.a,e.dir),r=Lc(n.b,e.a,e.dir),s=Math.max(0,Math.min(o,r)),i=Math.min(e.length,Math.max(o,r)),a=i-s,c=Math.min(e.length,n.length);if(a<Math.max(.75,c*.12))return null;let l=(s+i)/2,u=e.a[0]+e.dir[0]*l,f=e.a[1]+e.dir[1]*l,d=e.a[2]+e.dir[2]*l,m=Math.max(0,Math.min(n.length,(u-n.a[0])*n.dir[0]+(f-n.a[1])*n.dir[1]+(d-n.a[2])*n.dir[2])),p=n.a[0]+n.dir[0]*m-u,h=n.a[1]+n.dir[1]*m-f,g=n.a[2]+n.dir[2]*m-d,y=Math.hypot(p,h,g);if(y<=1e-6||y>t||y>Math.min(t,Math.max(4,c*.28)))return null;let x=1/y,b=p*x,P=h*x,A=g*x,C=e.outward[0]*b+e.outward[1]*P+e.outward[2]*A,E=-(n.outward[0]*b+n.outward[1]*P+n.outward[2]*A);if(C<.5||E<.5)return null;let S=Math.max(0,Math.min(n.length,wc(e,s,n))),M=Math.max(0,Math.min(n.length,wc(e,i,n)));return{gap:y,facingA:C,facingB:E,aStart:s,aEnd:i,bStart:Math.min(S,M),bEnd:Math.max(S,M)}}function Ds(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 kt(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 bd(e,n,t){if(!e?.length||n<=1e-6||t<=1e-6)return[];let o=new Set([0,n]);for(let i of e){let a=Math.max(0,Math.min(n,i.start)),c=Math.max(0,Math.min(n,i.end));c-a<=1e-6||i.amount<=1e-6||(o.add(a),o.add(c))}let r=Array.from(o).sort((i,a)=>i-a),s=[];for(let i=0;i+1<r.length;i+=1){let a=r[i],c=r[i+1];if(c-a<=1e-6)continue;let l=(a+c)/2,u=0;for(let d of e)l+1e-6<d.start||l-1e-6>d.end||(u=Math.max(u,d.amount));let f=Math.min(t,u);f>1e-6&&s.push({start:a,end:c,amount:f})}return s}function Pd(e,n){if(n.length<3||!$s(n))return!1;let t=Do(e),o=Do(n);return Math.sign(o)===Math.sign(t)&&Math.abs(o)>=Math.abs(t)-1e-6}function Md(e,n,t){if(n.size===0||e.vertices.length<3||Xs(e))return e;let o=Sn(e.vertices),r=Gs(o);if(!r||!$s(r.local))return e;let s=[];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=kc(r.local,r.area,l);if(!m||d<=1e-6)return e;let p=bd(n.get(l),d,Uc(r.local,l)*t);kt(s,u);let h=0;for(let g of p){g.start>h+1e-6&&kt(s,Ds(u,f,d,g.start));let y=Ds(u,f,d,g.start),x=Ds(u,f,d,g.end);kt(s,[y[0]+m[0]*g.amount,y[1]+m[1]*g.amount]),kt(s,[x[0]+m[0]*g.amount,x[1]+m[1]*g.amount]),g.end<d-1e-6&&kt(s,x),h=g.end}}let i=s[0],a=s[s.length-1];if(i&&a&&Math.hypot(i[0]-a[0],i[1]-a[1])<=1e-6&&s.pop(),!Pd(r.local,s))return e;let c=s.map(([l,u])=>Bc([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 Xc(e){return e.vertices.length===4&&!Xs(e)}function Sd(e){let n=e.basis?.local;if(!n||n.length!==4)return 1;let t=1/0,o=1/0,r=-1/0,s=-1/0;for(let[c,l]of n)t=Math.min(t,c),o=Math.min(o,l),r=Math.max(r,c),s=Math.max(s,l);let i=Math.max(1e-6,(r-t)*(s-o));return .75+(1-Math.max(0,Math.min(1,Math.abs(e.basis.area)/i)))*2.5}function Fs(e,n){return dt(An(Sn([e])[0],Sn([n])[0]))}function Vo(e,n,t){let o=Fs(e,n),r=Fs(n,t),s=Fs(t,e),i=Math.max(o,r,s);return i<=1e-6?0:dt(zs(An(Sn([n])[0],Sn([e])[0]),An(Sn([t])[0],Sn([e])[0])))*.5/(i*i)}function Ad(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],a=o[1]-t[1],c=r*a-s*i;if(Math.abs(c)<=1e-6)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*i)/c;return[e[0]+f*r,e[1]+f*s]}function Cd(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=Do(e);if(Math.abs(o)<=1e-6)return null;let r=o>0?1:-1,s=[];for(let c=0;c<e.length;c+=1){let l=e[c],u=e[(c+1)%e.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=1e-6)return null;let p=Math.max(0,n[c]),h=r*(d/m)*p,g=r*(-f/m)*p;s.push({a:[l[0]+h,l[1]+g],b:[u[0]+h,u[1]+g]})}let i=[],a=Math.max(2,t*4);for(let c=0;c<e.length;c+=1){let l=s[(c+e.length-1)%e.length],u=s[c],f=Ad(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],h=Math.hypot(m,p);i.push(h>a?[d[0]+m/h*a,d[1]+p/h*a]:f)}return i}function Td(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 Lo(e,n){let t=Gs(Sn(e));if(!t)return e;let o=Cd(t.local,n);return o?o.map(r=>Bc(Td(t,r))):e}function Ed(e,n){let t={...e,uvs:void 0,textureTriangles:void 0},[o,r,s,i]=e.vertices,a=Math.min(Vo(o,r,s),Vo(o,s,i)),c=Math.min(Vo(o,r,i),Vo(r,s,i)),l=u=>n.has(u)?.75:0;return a>=c?[{...t,vertices:Lo([o,r,s],[l(0),l(1),1.25])},{...t,vertices:Lo([o,s,i],[1.25,l(2),l(3)])}]:[{...t,vertices:Lo([o,r,i],[l(0),1.25,l(3)])},{...t,vertices:Lo([r,s,i],[l(1),l(2),1.25])}]}function Nc(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 wo(e,n){let t=e[n];if(t===n)return n;let o=wo(e,t);return e[n]=o,o}function vd(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 Id(e,n){return n?e.e.some(t=>n.endpoints.has(t)):!0}function _d(e,n,t,o){let r=[];for(let[c,l]of t){if(l.length!==2)continue;let[u,f]=l;if(!Ys(u,f))continue;let d=l.filter(C=>Xc(e[C.polygon]));if(d.length===0)continue;let m=d[0],p=1-Math.min(1,Math.abs(zt(u.normal,f.normal))),h=Math.max(u.length,f.length);if(p<.01&&h<64)continue;let g=Math.max(...d.map(C=>Sd(n[C.polygon]))),y=d.length===2?1.18:1,x=Math.max(.08,p),b=o.viewAware?Od(u,f,o.rotX,o.rotY):{proj:h,vr:1},P=o.viewAware?Math.max(b.proj,h*.12):h,A=o.viewAware?.18+b.vr*1.82:1;r.push({key:c,e:[No(m.a),No(m.b)],o:l,r:d,len:h,rank:P,proj:b.proj,s:P*(.58+x*2.8)*g*y*A,nr:p,sr:g,vr:b.vr,comp:-1,sel:!1,why:"below-threshold",cost:d.length})}let s=Array.from({length:r.length},(c,l)=>l),i=new Map;for(let c=0;c<r.length;c+=1)for(let l of r[c].e){let u=i.get(l);if(u===void 0)i.set(l,c);else{let f=wo(s,u),d=wo(s,c);f!==d&&(s[d]=f)}}let a=new Map;for(let c=0;c<r.length;c+=1){let l=wo(s,c),u=a.get(l);u===void 0&&(u=a.size,a.set(l,u)),r[c].comp=u}return r}function Od(e,n,t,o){let r=Oo(e.a,t,0,o),s=Oo(e.b,t,0,o),i=Math.hypot(s[0]-r[0],s[1]-r[1]),a=Oo(e.normal,t,0,o)[2],c=Oo(n.normal,t,0,o)[2],l=Math.max(0,a,c),u=Math.min(1,Math.abs(a-c));return{proj:i,vr:Math.max(.04,Math.min(1,l*.85+u*.45))}}function Rd(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 Ut(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 Dc(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,s=e.rank*(.6+n*n*1.4)*t*o*r/Math.sqrt(Math.max(1,e.r.length));return Math.max(s,Ut(e)*.75)}function Bs(e){let n=new Set;for(let t of e)for(let o of t.r)n.add(o.polygon);return n.size}function Yc(e,n){return e.nr<=.25&&e.rank>=n.median*1.08&&e.proj>=24}function Vd(e,n,t){return e.s>=n||e.rank>=t}function Ld(e,n,t,o,r,s,i){let a=Math.max(0,Math.floor(t));if(a<=0||e.length===0||n==="follow-up")return{budgetLimit:a,componentBudgets:null};let c=new Map;for(let m of e){let 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 h=p.filter(A=>Vd(A,s,i)||A.s>=f);if(h.length===0)continue;let g=p.filter(A=>Yc(A,r)),y=Bs(h),x=Bs(g),b=Math.ceil(Math.sqrt(Math.max(0,x-y))*3),P=Math.min(Bs(p),y+b);P<=0||(l.set(m,P),d+=P)}return l.size===0?{budgetLimit:0,componentBudgets:l}:{budgetLimit:Math.min(a,d),componentBudgets:l}}function wd(e,n,t){let o=new Map;if(e.length===0||t<=0)return{selected:o,budgetLimit:0};let r=Nc(e.map(M=>M.s)),s=Nc(e.map(M=>M.rank)),i=Math.max(1e-6,r.q3-r.q1),a=Math.min(r.max,Math.max(r.p95,r.q3+i*.85)),c=Math.min(r.max,Math.max(r.p80,r.q3+i*.15)),l=Math.min(r.max,Math.max(r.p70,r.q3)),u=Math.max(s.p97,s.median*1.8),f=Math.max(s.p88,s.median*1.35),d=Ld(e,n,t,r,s,a,u),m=d.budgetLimit;if(m<=0)return{selected:o,budgetLimit:0};let p=Rd(e),h=new Set,g=new Set,y=new Set,x=new Map,b=n==="primary"?Math.min(Math.max(0,d.budgetLimit-1),Math.max(2,Math.floor(d.budgetLimit*.28))):0,P=[...e].sort((M,T)=>Ut(T)-Ut(M)||T.s/Math.max(1,T.r.length)-M.s/Math.max(1,M.r.length)||T.len-M.len),A=[...e].sort((M,T)=>Dc(T)-Dc(M)||Ut(T)-Ut(M)||T.len-M.len),C=(M,T)=>{M.sel=!0,M.why=T,y.add(M.comp);for(let v of M.e)g.add(v);for(let v of M.r){h.add(v.polygon);let I=o.get(v.polygon);I?I.add(v.edge):o.set(v.polygon,new Set([v.edge]))}},E=(M,T)=>{let v=d.componentBudgets;if(T<=0||!v)return!0;let I=v.get(M.comp)??0;return(x.get(M.comp)??0)+T<=I},S=(M,T)=>{T<=0||!d.componentBudgets||x.set(M.comp,(x.get(M.comp)??0)+T)};for(let M of A){let T=M.r.reduce((I,_)=>I+(h.has(_.polygon)?0:1),0);if(M.cost=T,!(T>m||!E(M,T)||T>0&&m-T<b||!Yc(M,s))&&(C(M,"global-outlier"),S(M,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let M of P){if(M.sel)continue;let T=M.r.reduce((R,w)=>R+(h.has(w.polygon)?0:1),0);if(M.cost=T,T>m||!E(M,T)||T>0&&m-T<b)continue;let v=M.r.length===2,I=p.has(M)&&(n==="primary"||n==="follow-up"&&M.s>=c*1.08&&M.rank>=f)&&(v?M.s>=c||M.rank>=f:M.s>=c*1.18||M.rank>=f*1.12),_=v?M.s>=a||M.rank>=u:M.s>=a*1.35||M.rank>=u*1.2,O=T===0&&(v?M.s>=l||M.rank>=f:M.s>=l*1.25||M.rank>=f*1.12);if(!(!I&&!_&&!O)&&(C(M,I?"component-anchor":_?"global-outlier":"shared-polygon"),S(M,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}for(let M of P){if(M.sel)continue;let T=M.r.reduce((w,F)=>w+(h.has(F.polygon)?0:1),0);if(M.cost=T,T>1||T>m||!E(M,T))continue;let v=M.r.some(w=>h.has(w.polygon)),I=M.e.some(w=>g.has(w));if(n==="primary"&&M.r.length===1&&T===1&&(y.has(M.comp)||I||v)&&M.rank>=f*1.05&&M.nr>=.16&&M.vr<=.32){if(C(M,"local-follow-up"),S(M,T),m-=T,m<=0)return{selected:o,budgetLimit:d.budgetLimit};continue}if(M.r.length!==2)continue;let O=v&&T===1&&M.proj>=f*1.45&&M.vr<=.18;if(!I&&!O)continue;if((M.s>=l*.42||M.rank>=f*.62)&&M.s<=l*1.1&&M.proj>=24&&(C(M,"local-follow-up"),S(M,T),m-=T,m<=0))return{selected:o,budgetLimit:d.budgetLimit}}return{selected:o,budgetLimit:d.budgetLimit}}function Wc(e,n,t,o,r){let s=zc(e),i=Gc(e,s,n.capacityScale),a=new Map;for(let u of i){let f=a.get(u.key);f?f.push(u):a.set(u.key,[u])}let c=_d(e,s,a,t).filter(u=>Id(u,r)),l=wd(c,r?"follow-up":"primary",o);return{selected:l.selected,candidates:c,budgetLimit:l.budgetLimit}}function Nd(e,n){let t=[];for(let o=0;o<e.length;o+=1){let r=e[o],s=n.get(o);s&&Xc(r)?t.push(...Ed(r,s)):t.push(r)}return t}function Dd(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 Ws(e,n,t){let o=ft(n),r=Fc(t);if(!mt(o,n)||e.length===0)return e;let s=e,i,a=r.budget;for(let c=0;c<r.passes;c+=1){let l=Wc(s,o,r,a,i);if(c===0&&(a=Math.min(a,l.budgetLimit)),l.selected.size===0)break;let u=Nd(s,l.selected);if(u.length===s.length)break;if(a-=l.selected.size,a<=0){s=u;break}i=vd(l.candidates),s=u}return s}function jc(e,n,t){let o=ft(n),r=Fc(t);if(!mt(o,n)||e.length===0)return{candidates:[],selectedPolygons:0,selectedEdges:0,addedPolygons:0};let s=Wc(e,o,r,r.budget),i=0;for(let a of s.selected.values())i+=a.size;return{candidates:s.candidates.map(Dd),selectedPolygons:s.selected.size,selectedEdges:i,addedPolygons:s.selected.size}}function js(e,n){let t=ft(n);if(!mt(t,n)||e.length===0)return e;let{edgeRepairs:o}=Bo(e,t);return o.some(r=>r.size>0)?e.map((r,s)=>Md(r,o[s],t.capacityScale)):e}function Hc(e,n=ks,t=Us){if(e.length===0)return e;let o=Ws(e,n,t);return js(o,n)}function Kc(e,n){let t=ft(n);return!mt(t,n)||e.length===0?Fo():Bo(e,t).diagnostics}function Zc(e,n){let t=ft(n);return!mt(t,n)||e.length===0?Fo():Bo(e,t,!1,!0).diagnostics}function qc(e,n){let t=ft(n);if(!mt(t,n)||e.length===0)return{diagnostics:Fo(),candidates:[]};let o=Bo(e,t,!0);return{diagnostics:o.diagnostics,candidates:o.candidates??[]}}var zn={ratio:.7,maxError:.18,maxNormalDot:Math.cos(65*Math.PI/180),preserveVertices:!0,vertexKeyMode:"relaxed",lockBoundary:!0,minGroupTriangles:80,maxPasses:12};function Fd(e={}){let n=Number.isFinite(e.ratio)?Math.max(.05,Math.min(.98,e.ratio)):zn.ratio,t=Number.isFinite(e.maxError)&&e.maxError>0?e.maxError:zn.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??zn.preserveVertices,vertexKeyMode:e.vertexKeyMode??zn.vertexKeyMode,lockBoundary:e.lockBoundary??zn.lockBoundary,minGroupTriangles:Math.max(3,Math.floor(e.minGroupTriangles??zn.minGroupTriangles)),maxPasses:Math.max(1,Math.floor(e.maxPasses??zn.maxPasses))}}function Bd(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function kd(e){return e.vertices.length===3&&!Bd(e)}function Ud(e){return[e.color??"",e.doubleSided===!0?"2":"1",e.material?.key??""].join("\0")}function Qc(e){return`${Math.round(e[0]*1e5)},${Math.round(e[1]*1e5)},${Math.round(e[2]*1e5)}`}function zd(e,n,t,o){let r=o.vertexKeyMode==="source"?e.simplifySourceVertexKeys?.[t]??e.simplifyVertexKeys?.[t]:e.simplifyVertexKeys?.[t];return r?`${Qc(n)}|${r}`:Qc(n)}function Gd(e,n){return[e[0]+n[0],e[1]+n[1],e[2]+n[2]]}function pt(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function $d(e,n){return[e[0]*n,e[1]*n,e[2]*n]}function Hs(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Jc(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 qs(e){return Math.hypot(e[0],e[1],e[2])}function Ks(e,n){return qs(pt(e,n))}function Xd(e){let n=qs(e);return n>1e-12?[e[0]/n,e[1]/n,e[2]/n]:[0,0,1]}function Qs(e,n,t,o){return Xd(Jc(pt(e[t],e[n]),pt(e[o],e[n])))}function el(e,n,t,o){return qs(Jc(pt(e[t],e[n]),pt(e[o],e[n])))/2}function Yd(){return[0,0,0,0,0,0,0,0,0,0]}function ko(e,n){for(let t=0;t<e.length;t+=1)e[t]+=n[t]}function Wd(e,n,t){let o=e[0],r=e[1],s=e[2],i=-Hs(e,n);return[o*o*t,o*r*t,o*s*t,o*i*t,r*r*t,r*s*t,r*i*t,s*s*t,s*i*t,i*i*t]}function Zs(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 jd(e,n,t,o,r,s,i,a,c,l,u,f){let d=e*(r*c-s*a)-n*(o*c-s*i)+t*(o*a-r*i);if(Math.abs(d)<1e-10)return null;let m=1/d,p=l*(r*c-s*a)-n*(u*c-s*f)+t*(u*a-r*f),h=e*(u*c-s*f)-l*(o*c-s*i)+t*(o*f-u*i),g=e*(r*f-u*a)-n*(o*f-u*i)+l*(o*a-r*i),y=[p*m,h*m,g*m];return y.every(Number.isFinite)?y:null}function Hd(e,n,t,o){let r=jd(e[0],e[1],e[2],e[1],e[4],e[5],e[2],e[5],e[7],-e[3],-e[6],-e[8]),s=$d(Gd(n,t),.5),i=Ks(n,t)*1.35,a=o?[n,t]:[n,t,s,...r&&Ks(r,s)<=i?[r]:[]],c=a[0],l=Zs(e,c);for(let u=1;u<a.length;u+=1){let f=a[u],d=Zs(e,f);d<l&&(c=f,l=d)}return c}function Kd(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function Zd(e,n,t){return`${e}|${n}|${t}`}function qd(e,n){let t=new Map,o=[],r=[];for(let s of e){let i=[];for(let u=0;u<s.vertices.length;u+=1){let f=s.vertices[u],d=zd(s,f,u,n),m=t.get(d);m===void 0&&(m=o.length,t.set(d,m),o.push([...f])),i.push(m)}let[a,c,l]=i;a===void 0||c===void 0||l===void 0||a===c||a===l||c===l||r.push({a,b:c,c:l,polygon:s,normal:Qs(o,a,c,l)})}return{vertices:o,triangles:r}}function Qd(e,n){let t=qd(e,n),o=Array.from({length:t.vertices.length},()=>new Set),r=Array.from({length:t.triangles.length},()=>!0);for(let s=0;s<t.triangles.length;s+=1){let i=t.triangles[s];o[i.a].add(s),o[i.b].add(s),o[i.c].add(s)}return{vertices:t.vertices,triangles:t.triangles,alive:r,vertexTriangles:o,activeCount:t.triangles.length}}function Jd(e){let n=new Map,t=(o,r,s)=>{let i=Kd(o,r),a=n.get(i);a?a.triangles.push(s):n.set(i,{a:Math.min(o,r),b:Math.max(o,r),triangles:[s]})};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 ep(e){let n=Array.from({length:e.vertices.length},()=>Yd());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,el(e.vertices,o.a,o.b,o.c)),s=Wd(o.normal,e.vertices[o.a],Math.sqrt(r));ko(n[o.a],s),ko(n[o.b],s),ko(n[o.c],s)}return n}function np(e,n,t){let o=new Set,r=s=>{let i=e.vertexTriangles[s];if(i)for(let a of i)e.alive[a]&&o.add(a)};return r(n),r(t),Array.from(o).sort((s,i)=>s-i)}function tp(e,n,t){let o=e.vertexTriangles[n],r=e.vertexTriangles[t];if(!o||!r)return 0;let[s,i]=o.size<=r.size?[o,r]:[r,o],a=0;for(let c of s)e.alive[c]&&i.has(c)&&(a+=1);return a}function nl(e,n,t){return[e.a===t?n:e.a,e.b===t?n:e.b,e.c===t?n:e.c]}function op(e,n,t){if(tp(e,n.a,n.b)!==2)return null;let o=np(e,n.a,n.b);if(o.length===0)return null;let r=e.vertices[n.a];e.vertices[n.a]=n.target;let s=0,i=!0;for(let a of o){let c=e.triangles[a],[l,u,f]=nl(c,n.a,n.b);if(l===u||l===f||u===f)continue;if(el(e.vertices,l,u,f)<=1e-8){i=!1;break}let m=Qs(e.vertices,l,u,f);if(Hs(c.normal,m)<t.maxNormalDot){i=!1;break}let p=c.a===n.a?r:e.vertices[c.a];if(Math.abs(Hs(c.normal,pt(n.target,p)))>t.maxError){i=!1;break}s+=1}return e.vertices[n.a]=r,i&&s>0?o:null}function rp(e,n,t){e.vertexTriangles[t.a]?.delete(n),e.vertexTriangles[t.b]?.delete(n),e.vertexTriangles[t.c]?.delete(n)}function sp(e,n,t){e.vertexTriangles[t.a].add(n),e.vertexTriangles[t.b].add(n),e.vertexTriangles[t.c].add(n)}function ip(e,n,t){e.vertices[n.a]=n.target;let o=new Set;for(let r of t){if(!e.alive[r])continue;let s=e.triangles[r],[i,a,c]=nl(s,n.a,n.b);if(rp(e,r,s),i===a||i===c||a===c){e.alive[r]=!1,e.activeCount-=1;continue}let l=Zd(i,a,c);if(o.has(l)){e.alive[r]=!1,e.activeCount-=1;continue}o.add(l);let u={...s,a:i,b:a,c,normal:Qs(e.vertices,i,a,c)};e.triangles[r]=u,sp(e,r,u)}}function ap(e,n){let t=Jd(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=ep(e),s=n.maxError*n.maxError,i=[];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]];ko(c,r[a.b]);let l=Hd(c,e.vertices[a.a],e.vertices[a.b],n.preserveVertices),u=Math.max(0,Zs(c,l));if(u>s*Math.max(1,a.triangles.length))continue;let f=Ks(e.vertices[a.a],e.vertices[a.b]);i.push({a:a.a,b:a.b,target:l,error:u,length:f})}return i.sort((a,c)=>a.error-c.error||a.length-c.length),i}function cp(e){let n=[];for(let t=0;t<e.triangles.length;t+=1)e.alive[t]&&n.push(e.triangles[t]);return n}function lp(e,n){if(e.length<n.minGroupTriangles)return e;let t=Qd(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 s=0;for(let i=0;i<n.maxPasses&&t.activeCount>r;i+=1){let a=ap(t,n);if(a.length===0)break;let c=0;for(let l of a){if(t.activeCount<=r)break;let u=op(t,l,n);if(!u)continue;let f=t.activeCount;ip(t,l,u),!(t.activeCount>=f)&&(s+=1,c+=1)}if(c===0)break}return s===0||t.activeCount>=o?e:cp(t).map(i=>({...i.polygon,vertices:[[...t.vertices[i.a]],[...t.vertices[i.b]],[...t.vertices[i.c]]]}))}function up(e){let n=new Map;for(let t=0;t<e.length;t+=1){let o=e[t];if(!kd(o))continue;let r=Ud(o),s=n.get(r);s?(s.indices.push(t),s.polygons.push(o)):n.set(r,{indices:[t],polygons:[o]})}return n}function Uo(e,n){let t=Fd(n),o=up(e);if(o.size===0)return e;let r=new Map,s=!1;for(let a of o.values()){let c=lp(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],[]);s=!0}}if(!s)return e;let i=[];for(let a=0;a<e.length;a+=1){let c=r.get(a);c?i.push(...c):c===void 0&&i.push(e[a])}return i}var fp=3,mp=.03,dp=.02,$t={maxAngleDeg:fp,maxPlaneDisplacement:mp,maxBoundaryDisplacement:dp,isolatedPairs:!1},zo={maxAngleDeg:15,maxPlaneDisplacement:.35,maxBoundaryDisplacement:.04,isolatedPairs:!0},Js=[{...zo,maxAngleDeg:30},{...zo,maxAngleDeg:45},{...zo,maxAngleDeg:60,maxBoundaryDisplacement:.06}],pp=1800,gp=.65,tl=500,ol=2200,hp=1e3,yp=2200,xp=350,bp=700,Pp=60,Mp=.06,Sp=4,Ap=.003,Cp=4e3,Tp=3e3,Ep=4500,vp=2400,Ip=4200,_p=1800,Op=5e3,Rp=.28,Vp=.15,Lp=.23,wp=2e3,Np=16,Dp=4e3,Fp=900,Bp=16,kp=1.5,ni=.045,Up=.999,zp=1e-5,Gp=24,$p=50,Xp=1e3,Yp=1e3,$n={minGroupPolygons:2,maxCandidateAxes:24},Wp={...$n,maxCandidateAxes:1},rl={...$n,maxCandidateAxes:2},jp={...$n,maxCandidateAxes:2},Hp={steps:[{kind:"baselineCandidates"},{kind:"initialLossyCandidates"},{kind:"finalLossyCandidates"}]};function ll(e,n={}){return Kp(e,n).polygons}function ul(e,n={}){let t={meshResolution:n.meshResolution,stopAtPolygonCount:n.stopAtPolygonCount,rectCover:n.rectCover},o=new Go,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 Kp(e,n={},t={}){return new Go().workspaceFor(e,t).createRun(n,t).optimize()}var Go=class{constructor(){this.workspaces=new Map}workspaceFor(n,t){let o=Zp(t),r=this.workspaces.get(o);r||(r=new WeakMap,this.workspaces.set(o,r));let s=r.get(n);return s||(s=new ti(n,t,this),r.set(n,s)),s}};function Zp(e){return[e.skipInteriorCull===!0?"skip-cull":"cull",e.simplifiedCandidate===!0?"simplified":"source"].join(":")}var ti=class{constructor(n,t,o){this.source=n,this.graph=o,this.preprocessCache={skipInteriorCull:t.skipInteriorCull===!0}}polygons(){return this.source}preprocess(n){return Pg(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<=Ip:n.length<=_p||n.length<=Op&&o>=Rp}visiblePolygons(){return this.preprocessCache.interior??this.preprocessCache.deduped??this.source}createRun(n,t){return new oi(this,n,t)}workspaceFor(n,t){return this.graph.workspaceFor(n,t)}},oi=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 ri(this.baseline,this.requiredMaxPolygonCount)}optimize(){return this.runPlan(Hp)}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"||!fg(this.source,this.best))return!1;let t=ml(this.source,n);if(!t)return!1;for(let o of this.staticSimplificationPlans(t)){let r=mg(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>=Dp&&r>=Fp&&(t<=Bp||r>=t*kp)&&o.push({source:this.visiblePolygons,skipInteriorCull:!0}),this.best.length>=wp&&t<=Np&&ug(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},s=this.workspace.workspaceFor(n,r),i=this.best;return new e(s,{meshResolution:"lossy",stopAtPolygonCount:lg(this.best.length,t)},r,{acceptor:this.acceptor,costCandidateMode:"dom",seamCandidateMode:"dom",offerBaseline:!0}).optimize(),this.best!==i}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?pg(this.baseline):this.options.rectCover;if(this.shouldStop())return;let t=Gn(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=Gn(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(zo);this.acceptCandidate(n),!this.shouldStop()&&(this.options.rectCover===void 0&&this.source.length>=tl&&this.source.length<=ol&&(this.acceptCandidate(Gn(n,rl)),this.shouldStop())||this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(this.acceptCandidate(Gn(n,this.options.rectCover)),this.shouldStop()))}runFinalLossyPipeline(){this.finalLossyCandidatesComplete||(this.finalLossyCandidatesComplete=!0,!(this.runOptions.simplifiedCandidate===!0&&this.source.length>Ep)&&(this.runAggressiveLossyVariants(),!this.shouldStop()&&this.runLargeRectCoverCandidate()))}runAggressiveLossyVariants(){let n=this.stopAtPolygonCount===void 0&&this.source.length>=Cp&&this.best.length<=Tp,t=!1;for(let o=n?Js.length:0;o<Js.length;o+=1){if(o===1&&!t||o===1&&this.runOptions.simplifiedCandidate===!0&&this.source.length<vp||o===2&&!hg(this.source))continue;let r=this.preprocess(Js[o]),s=r;this.options.rectCover===void 0&&this.source.length>=tl&&this.source.length<=ol&&(s=Gn(r,rl)),this.options.rectCover!==void 0&&this.options.rectCover!==!1&&(s=Gn(r,this.options.rectCover));let i=this.acceptSeamSafeCandidate(s,this.source.length);if(o===0&&i&&(t=!0),this.shouldStop())return}}runLargeRectCoverCandidate(){if(this.options.rectCover!==void 0)return;let n=Gn(this.best,gg(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=Xn(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})}},ri=class{constructor(n,t){this.best=n,this.bestCost=Xn(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=Xn(n)){return t>=this.bestCost?!1:(this.commit(n,t),!0)}acceptDomCandidate(n,t=Xn(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 s=cg(t);if(this.bestCost-n.length<s)return!1;let i=o??Xn(n),a=this.bestCost-i;if(a<=0||a<s)return!1;let c=sl(n);if(!c)return!1;let l=this.bestSeamDiagnostics();return!l||qp(c,l)||Qp(this.bestTopologyEdges(),this.bestTopologySelfDiagnostics(),n)?!1:(this.commit(n,i,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=sl(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=fl(this.best)),this.bestDiagnostics.topologyEdges}bestTopologySelfDiagnostics(){return this.bestDiagnostics.polygons!==this.best&&this.resetBestDiagnostics(),this.bestDiagnostics.topologySelf||(this.bestDiagnostics.topologySelf=tg(this.bestTopologyEdges(),ni)),this.bestDiagnostics.topologySelf}};function Xn(e){let n=0;for(let t of e){let o=t.vertices.length,r=o<=4?0:Math.min(4,o-4)*.12,s=t.texture||t.material?.texture||t.textureTriangles?.length?.15:0;n+=1+r+s}return n}function sl(e){try{return Zc(e)}catch(n){if(n instanceof RangeError&&n.message==="Set maximum size exceeded")return null;throw n}}function qp(e,n){return e.nearPairs>n.nearPairs||e.unclosedPairs>n.unclosedPairs||e.maxMeasuredGapPx>n.maxMeasuredGapPx+1e-9||e.maxResidualGapPx>n.maxResidualGapPx+1e-9}function Qp(e,n,t){let o=fl(t);return Jp(e,o,ni)?!0:ng(o.boundarySegments,ni,n)}function Jp(e,n,t){if(e.internalSegments.length===0)return!1;let o=eg(e,t);for(let r of n.boundarySegments)if(!e.boundaryKeys.has(r.key)&&(e.internalKeys.has(r.key)||ig(r,o,t)))return!0;return!1}function eg(e,n){return(!e.internalIndex||e.internalIndexTolerance!==n)&&(e.internalIndex=ai(e.internalSegments,n),e.internalIndexTolerance=n),e.internalIndex}function ng(e,n,t){let o=ai(e,n),r=new Set,s=0,i=0,a=0;for(let c of e)s=Math.max(s,c.index+1);for(let c of e)for(let l of ci(c,o,n)){if(l===c||l.polygon===c.polygon||l.key===c.key)continue;let u=c.index<l.index?c.index*s+l.index:l.index*s+c.index;if(r.has(u))continue;r.add(u);let f=li(c,l,n);if(f&&(i+=1,a+=f.overlapLength,i>t.tJunctionPairs||a>t.tJunctionLength+1e-9))return!0}return!1}function tg(e,n){let t={tJunctionPairs:0,tJunctionLength:0};return og(t,e.boundarySegments,n),t}function og(e,n,t){let o=ai(n,t),r=new Set,s=0;for(let i of n)s=Math.max(s,i.index+1);for(let i of n)for(let a of ci(i,o,t)){if(a===i||a.polygon===i.polygon||a.key===i.key)continue;let c=i.index<a.index?i.index*s+a.index:a.index*s+i.index;if(r.has(c))continue;r.add(c);let l=li(i,a,t);l&&(e.tJunctionPairs+=1,e.tJunctionLength+=l.overlapLength)}}function fl(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=rg(Wt(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=[],s=[],i=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),i+=l.length):(o.add(l.key),s.push(l))}return{boundaryKeys:t,internalKeys:o,boundarySegments:r,internalSegments:s,boundaryLength:i}}function rg(e,n,t,o,r){let s=Cn(r,o),i=Math.hypot(s[0],s[1],s[2]);if(i<=1e-10)return null;let a=[s[0]/i,s[1]/i,s[2]/i];return{index:-1,key:e,polygon:n,edge:t,a:o,b:r,dir:a,length:i,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 ai(e,n){let t=Math.max(n*8,.5),o=new Map;for(let r of e)sg(o,r,t,n);return{cellSize:t,cells:o}}function sg(e,n,t,o){let[r,s,i]=$o([n.minX-o,n.minY-o,n.minZ-o],t),[a,c,l]=$o([n.maxX+o,n.maxY+o,n.maxZ+o],t);for(let u=r;u<=a;u+=1)for(let f=s;f<=c;f+=1)for(let d=i;d<=l;d+=1){let m=`${u},${f},${d}`,p=e.get(m);p?p.push(n):e.set(m,[n])}}function $o(e,n){return[Math.floor(e[0]/n),Math.floor(e[1]/n),Math.floor(e[2]/n)]}function ci(e,n,t){let o=[],r=new Set,[s,i,a]=$o([e.minX-t,e.minY-t,e.minZ-t],n.cellSize),[c,l,u]=$o([e.maxX+t,e.maxY+t,e.maxZ+t],n.cellSize);for(let f=s;f<=c;f+=1)for(let d=i;d<=l;d+=1)for(let m=a;m<=u;m+=1){let p=n.cells.get(`${f},${d},${m}`);if(p)for(let h of p)r.has(h)||(r.add(h),o.push(h))}return o}function ig(e,n,t){for(let o of ci(e,n,t))if(li(e,o,t))return!0;return!1}function li(e,n,t){if(!ag(e,n,t)||Math.abs(qe(e.dir,n.dir))<Up)return null;let o=qe(Cn(n.a,e.a),e.dir),r=qe(Cn(n.b,e.a),e.dir),s=Math.max(0,Math.min(o,r)),i=Math.min(e.length,Math.max(o,r)),a=i-s;if(a<=Math.max(zp,Math.min(e.length,n.length)*1e-4))return null;let c=[e.a[0]+e.dir[0]*((s+i)/2),e.a[1]+e.dir[1]*((s+i)/2),e.a[2]+e.dir[2]*((s+i)/2)],l=Math.max(0,Math.min(n.length,qe(Cn(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=El(c,u);return f<=t?{overlapLength:a,offset:f}:null}function ag(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 cg(e){return Math.max(Sp,e*Ap)}function lg(e,n){let t=Number.isFinite(n.earlyStopDropRatio)?Math.max(0,n.earlyStopDropRatio):Vp;return Math.max(0,e-Math.max(1,Math.ceil(e*t)))}function ug(e){return e.some(n=>n.simplifySourceVertexKeys?.length===n.vertices.length)}function fg(e,n){return e.length===0||n.length/e.length>Lp}function ml(e,n,t){let o=Uo(e,{...n.simplifyTriangleMeshOptions,...t?{vertexKeyMode:t}:{}});return o===e||o.length>=e.length?null:o}function mg(e,n){return e.precomputed!==void 0?e.precomputed:ml(e.source,n,e.vertexKeyMode)}function Gn(e,n){if(n===!1)return e;let t=dg(e,n);if(!t)return e;let o=_o(e,t);return o.length<e.length?o:e}function dg(e,n){if(n&&n!==!0)return n;let t=n===!0,o=e.length;return o>2200||!t&&o>=Gp&&o<$p||!t&&o>Xp?null:!t&&o<=300?{...$n,maxCandidateAxes:1}:o>300?!t&&(dl(e)>12||pl(e)>Yp)?null:{...$n,maxCandidateAxes:Math.min($n.maxCandidateAxes??24,2)}:$n}function pg(e){return e.length>pp||e.length===0||yg(e)/e.length<gp?!1:Wp}function gg(e){return e.length<hp||e.length>yp||dl(e)<=12||pl(e)>xp?!1:jp}function hg(e){return e.length<=bp}function yg(e){let n=0;for(let t of e)t.vertices.length===3&&(n+=1);return n}function dl(e){let n=0;for(let t of e)n=Math.max(n,t.vertices.length);return n}function pl(e){let n=new Map;for(let o of e)for(let r=0;r<o.vertices.length;r++){let s=o.vertices[r],i=o.vertices[(r+1)%o.vertices.length],a=Wt(s,i);n.set(a,(n.get(a)??0)+1)}let t=0;for(let o of n.values())o===1&&(t+=1);return t}function Xo(e,n){return n==null?e:n.map(t=>e[t]).filter(t=>!!t)}function si(e,n){if(n===e||n.length===e.length&&n.every((r,s)=>r===e[s]))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 xg(e,n){if(n?.deduped)return n.deduped;let t=n?.dedupedIndices;if(t===void 0){let r=Lt(e);if(r.size===0)t=null;else{t=[];for(let s=0;s<e.length;s++)r.has(s)||t.push(s)}n&&(n.dedupedIndices=t)}let o=Xo(e,t);return n&&(n.deduped=o),o}function bg(e,n){if(n?.skipInteriorCull)return e;if(n?.interior)return n.interior;let t=n?.interiorIndices;if(t===void 0){let r=fn(e);t=si(e,r),n&&(n.interiorIndices=t)}let o=Xo(e,t);return n&&(n.interior=o),o}function Pg(e,n,t){let o=xg(e,t),r=bg(o,t),s=t?.baseline??tn(r);if(t&&!t.baseline&&(t.baseline=s),!n)return s;let i=n===!0?$t:Sg(n);if(i.isolatedPairs){let u=al(il(o,t),i,t),f=tn(u);if(t?.snappedInteriorUsesBaselineFilter&&Mg(s,f)){let d=al(il(o,t,!0),i,t),m=tn(d);m.length<f.length&&(f=m)}return f.length<s.length?f:s}let a=Ng(o,i,t),c=fn(a),l=tn(c);return l.length<s.length?l:s}function gl(e,n){return n?(n.snapped||(n.snapped=Yo(e)),n.snapped):Yo(e)}function il(e,n,t=!1){if(!n)return fn(Yo(e));if(t&&n.snappedInteriorExact)return n.snappedInteriorExact;if(!t&&n.snappedInterior)return n.snappedInterior;let o=gl(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=fn(o);return n.snappedInteriorExactIndices=si(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=Xo(o,n.snappedInteriorIndices),n.snappedInteriorUsesBaselineFilter=!0,n.snappedInterior;if(n.snappedInteriorIndices===void 0){let r=fn(o);n.snappedInteriorIndices=si(o,r),n.snappedInterior=r,n.snappedInteriorExactIndices=n.snappedInteriorIndices,n.snappedInteriorExact=r,n.snappedInteriorUsesBaselineFilter=!1}else n.snappedInterior=Xo(o,n.snappedInteriorIndices)}return n.snappedInterior}function Mg(e,n){return n.length>=e.length}function Sg(e){return{maxAngleDeg:e.maxAngleDeg??$t.maxAngleDeg,maxPlaneDisplacement:e.maxPlaneDisplacement??$t.maxPlaneDisplacement,maxBoundaryDisplacement:e.maxBoundaryDisplacement??$t.maxBoundaryDisplacement,isolatedPairs:e.isolatedPairs??$t.isolatedPairs}}function al(e,n,t){let o=Ag(e,t),r=[];for(let i of Cg(e,o))Tg(i,n)&&r.push(i.candidate);let s=vg(r);return s.length===0?e:Eg(e,s)}function Ag(e,n){if(n?.trianglePairSource?.polygons===e)return n.trianglePairSource;let t=e.map(i=>{let a=fi(i);return a?{polygon:i,normal:a.normal,area:a.area,materialKey:Ml(i)}:null}),o=new Map;for(let i=0;i<e.length;i++){let a=e[i];if(!(a.vertices.length!==3||!t[i]))for(let c=0;c<a.vertices.length;c++){let l=Wt(a.vertices[c],a.vertices[(c+1)%a.vertices.length]),u=o.get(l);u?u.push(i):o.set(l,[i])}}let r=[];for(let i of o.values())i.length===2&&r.push([i[0],i[1]]);let s={polygons:e,metas:t,edgeOwnerPairs:r};return n&&(n.trianglePairSource=s),s}function Cg(e,n){if(n.preparedCandidates)return n.preparedCandidates;let t=[];for(let[o,r]of n.edgeOwnerPairs){let s=Vg(o,r,e,n.metas);s&&t.push(s)}return n.preparedCandidates=t,t}function Tg(e,n){let t=Math.cos(n.maxAngleDeg*Math.PI/180);return e.normalDot>=t&&e.maxDistance<=Math.min(n.maxPlaneDisplacement,n.maxBoundaryDisplacement)}function Eg(e,n){let t=new Map,o=new Set,r=hl(n.flatMap(i=>i.vertexMoves));for(let i of n){let a=Math.min(i.a,i.b);t.set(a,i.polygon),o.add(Math.max(i.a,i.b))}let s=[];for(let i=0;i<e.length;i++){let a=t.get(i);if(a){s.push(a);continue}o.has(i)||s.push(e[i])}return r.size>0?yl(s,r):s}function vg(e){return e.length>3e3?Ig(e):_g(e)}function Ig(e){let n=new Map;for(let s of e)n.set(s.a,(n.get(s.a)??0)+1),n.set(s.b,(n.get(s.b)??0)+1);let t=[...e].sort((s,i)=>{let a=(n.get(s.a)??0)+(n.get(s.b)??0),c=(n.get(i.a)??0)+(n.get(i.b)??0);return a-c||s.score-i.score}),o=new Set,r=[];for(let s of t)o.has(s.a)||o.has(s.b)||(o.add(s.a),o.add(s.b),r.push(s));return r}function _g(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,s=new ii;for(let[l,u]of n)r.set(l,u.length);let i=l=>(r.get(l.a)??0)+(r.get(l.b)??0),a=l=>{let u=e[l];s.push({degree:i(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(;s.size()>0;){let l=s.pop();if(!o[l.index])continue;let u=e[l.index];if(i(u)!==l.degree){a(l.index);continue}t.push(u);let d=new Set;for(let m of[u.a,u.b])for(let 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 ii=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(ei(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,s=r+1,i=o;if(r<this.items.length&&ei(this.items[r],this.items[i])<0&&(i=r),s<this.items.length&&ei(this.items[s],this.items[i])<0&&(i=s),i===o)break;[this.items[o],this.items[i]]=[this.items[i],this.items[o]],o=i}}return n}};function ei(e,n){return e.degree-n.degree||e.score-n.score||e.index-n.index}function hl(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 Og(e,n){let t=[];for(let o=0;o<e.length;o++){let r=e[o].vertices,s=n[o]?.vertices;if(!s||s.length!==r.length)continue;for(let c=0;c<r.length;c++)t.push({key:sn(r[c]),target:s[c]});let i=e[o].textureTriangles??[],a=n[o]?.textureTriangles??[];for(let c=0;c<i.length;c++){let l=a[c];if(l)for(let u=0;u<i[c].vertices.length;u++)t.push({key:sn(i[c].vertices[u]),target:l.vertices[u]})}}return t}function Rg(e,n){let t=[];for(let o of e)for(let r of o.textureTriangles??[])for(let s of r.vertices)t.push({key:sn(s),target:gi(s,n)});return t}function yl(e,n){return e.map(t=>{let o=!1,r=a=>{let c=n.get(sn(a));return c?(o=!0,c):a},s=t.vertices.map(r),i=ui(t.textureTriangles,r);return o?{...t,vertices:s,...i?{textureTriangles:i}:{}}:t})}function Vg(e,n,t,o){let r=t[e],s=t[n],i=o[e],a=o[n];if(!i||!a||r.vertices.length!==3||s.vertices.length!==3||!jg(r,s,i,a))return null;let c=di(r,s);if(!c)return null;let[l,u,f,d]=c;if((f+1)%s.vertices.length===d)return null;let p=Math.abs(qe(i.normal,a.normal)),h=Math.cos(Pp*Math.PI/180);if(p<h)return null;let g=(u+1)%r.vertices.length,y=3-f-d,x=[r.vertices[u],r.vertices[g],r.vertices[l],s.vertices[y]],b=Lg(x);if(!b)return null;let P=0,A=0;for(let M of x){let T=Math.abs(pi(M,b));P=Math.max(P,T),A+=T*T}if(P>Mp)return null;let C=x.map(M=>gi(M,b));if(!wg(C,b.normal))return null;let E=fi({vertices:C});if(!E||qe(E.normal,i.normal)<.2||qe(E.normal,a.normal)<.2)return null;let S={vertices:x,color:r.color,...r.doubleSided?{doubleSided:!0}:{},...r.data?{data:{...r.data}}:{}};if(mi(r,s)&&r.uvs&&s.uvs&&r.texture){S.texture=r.texture,r.textureWrap&&(S.textureWrap={...r.textureWrap}),r.textureAlphaMode&&(S.textureAlphaMode=r.textureAlphaMode),S.uvs=[[...r.uvs[u]],[...r.uvs[g]],[...r.uvs[l]],[...s.uvs[y]]];let M=Dg([r,s]);M?.length&&(S.textureTriangles=M)}return{normalDot:p,maxDistance:P,candidate:{a:e,b:n,polygon:S,vertexMoves:[...x.map((M,T)=>({key:sn(M),target:C[T]})),...Rg([r,s],b)],score:A/x.length+P*.25+(1-p)*.1}}}function Lg(e){if(e.length<3)return null;let n=0,t=0,o=0,r=0,s=0,i=0;for(let c=0;c<e.length;c++){let l=e[c],u=e[(c+1)%e.length];n+=(l[1]-u[1])*(l[2]+u[2]),t+=(l[2]-u[2])*(l[0]+u[0]),o+=(l[0]-u[0])*(l[1]+u[1]),r+=l[0],s+=l[1],i+=l[2]}let a=vl([n,t,o]);return a?{normal:a,point:[r/e.length,s/e.length,i/e.length]}:null}function wg(e,n){let t=0;for(let o=0;o<e.length;o++){let r=e[o],s=e[(o+1)%e.length],i=e[(o+2)%e.length],a=qe(Tl(Cn(s,r),Cn(i,s)),n);if(Math.abs(a)<=1e-9)continue;let c=a>0?1:-1;if(t===0)t=c;else if(t!==c)return!1}return!0}function Ng(e,n,t){let o=gl(e,t),r=Gg(o,n);if(r<=0)return o;let s=o.map(m=>{let p=fi(m);return p?{polygon:m,normal:p.normal,area:p.area,materialKey:Ml(m)}:null}),i=Yg(o,s),a=new Set,c=Array(o.length),l=[],u=(m,p)=>{c[m]=p};for(let m=0;m<o.length;m++){let p=s[m];if(a.has(m))continue;if(!p){u(m,o[m]);continue}let h=Hg(m,s,i,a,r,n);for(let y of h)a.add(y);if(h.length<2){u(m,o[m]);continue}let g=kg(h,o,s,i,r,n);l.push(...g.vertexMoves);for(let y of h)u(y,g.polygons.get(y)??o[y])}let f=c.flatMap(m=>m?[m]:[]),d=l.length>0?yl(f,hl(l)):f;return Yo(d)}function Yo(e){let n=Pl(e),t=1e-4;if(n<=0)return e;let o=$g(n),r=Xg(t),s=!1,i=e.map(a=>{let c=!1,l=p=>{let h=o.snap(p);return Xt(h,p)||(c=!0),h},u=a.vertices.map(l),f=a.uvs&&a.uvs.length===a.vertices.length?a.uvs.map(p=>{let h=r.snap(p);return Yt(h,p)||(c=!0),h}):void 0,d=ui(a.textureTriangles,l);if(!c&&!a.texture)return a;let m={...a,vertices:u,...f?{uvs:f}:{},...d?{textureTriangles:d}:{}};return s=!0,{...m,...m.texture?{textureTriangles:xl(m)}:{}}});return s?i:e}function xl(e){if(e.texture){if(e.textureTriangles?.length)return Bg(e.textureTriangles);if(e.uvs&&e.uvs.length===e.vertices.length)return Fg(e.vertices,e.uvs)}}function Dg(e){let n=e.flatMap(t=>xl(t)??[]);return n.length>0?n:void 0}function Fg(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 Bg(e){return e.map(n=>({vertices:n.vertices.map(t=>[...t]),uvs:n.uvs.map(t=>[...t])}))}function ui(e,n){if(e?.length)return e.map(t=>({vertices:t.vertices.map(n),uvs:t.uvs.map(o=>[...o])}))}function kg(e,n,t,o,r,s){let i=bl(e,n,t,r,s);return i?zg(i):Ug(e,n,t,o,r,s)}function Ug(e,n,t,o,r,s){let i=new Set(e),a=[];for(let f of e)for(let d of o.get(f)??[]){if(f>=d||!i.has(d))continue;let m=bl([f,d],n,t,r,s);m&&a.push(m)}a.sort((f,d)=>d.score-f.score);let c=new Set,l=new Map,u=[];for(let f of a)if(!f.indices.some(d=>c.has(d))){u.push(...f.vertexMoves);for(let d=0;d<f.indices.length;d++){let m=f.indices[d];c.add(m),l.set(m,n[m])}}return{polygons:l,vertexMoves:u}}function zg(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 bl(e,n,t,o,r){let s=Sl(e,t);if(!s||!Al(e,t,s,o,r))return null;let i=e.map(u=>n[u]),a=i.map(u=>qg(u,s)),c=Xn(tn(i)),l=Xn(tn(a));return l>=c?null:{indices:e,source:i,projected:a,vertexMoves:Og(i,a),score:c-l}}function Gg(e,n){return Pl(e)<=0?0:n.maxPlaneDisplacement}function Pl(e){let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let[l,u,f]of c.vertices)n=Math.min(n,l),t=Math.min(t,u),o=Math.min(o,f),r=Math.max(r,l),s=Math.max(s,u),i=Math.max(i,f);if(!Number.isFinite(n))return 0;let a=Math.hypot(r-n,s-t,i-o);return a<=0?0:Math.min(.025,Math.max(1e-4,a*25e-5))}function $g(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,s,i)=>`${r},${s},${i}`;return{snap(r){let s=t(r[0]),i=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(s+f,i+d,a+m));if(p){for(let h of p)if(El(r,h)<=e)return[h[0],h[1],h[2]]}}let c=[r[0],r[1],r[2]],l=o(s,i,a),u=n.get(l);return u?u.push(c):n.set(l,[c]),c}}}function Xg(e){let n=new Map,t=r=>Math.floor(r/e),o=(r,s)=>`${r},${s}`;return{snap(r){let s=t(r[0]),i=t(r[1]);for(let u=-1;u<=1;u++)for(let f=-1;f<=1;f++){let d=n.get(o(s+u,i+f));if(d){for(let m of d)if(Math.hypot(r[0]-m[0],r[1]-m[1])<=e)return[m[0],m[1]]}}let a=[r[0],r[1]],c=o(s,i),l=n.get(c);return l?l.push(a):n.set(c,[a]),a}}}function Ml(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 fi(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0,s=n[0];for(let a=1;a<n.length-1;a++){let c=Cn(n[a],s),l=Cn(n[a+1],s),u=Tl(c,l);t+=u[0],o+=u[1],r+=u[2]}let i=Math.hypot(t,o,r);return i<=1e-10?null:{normal:[t/i,o/i,r/i],area:i/2}}function Yg(e,n){let t=new Map,o=new Map;for(let r=0;r<e.length;r++){let s=e[r];if(!(!n[r]||s.vertices.length<3))for(let i=0;i<s.vertices.length;i++){let a=Wt(s.vertices[i],s.vertices[(i+1)%s.vertices.length]),c=t.get(a);c?c.push(r):t.set(a,[r])}}for(let r of t.values())for(let s=0;s<r.length;s++)for(let i=s+1;i<r.length;i++){let a=r[s],c=r[i];Wg(e[a],e[c],n[a],n[c])&&(cl(o,a,c),cl(o,c,a))}return o}function Wg(e,n,t,o){if(!t||!o||t.materialKey!==o.materialKey||!!e.uvs!=!!n.uvs)return!1;if(Wo(e)||Wo(n))return mi(e,n);if(!e.uvs||!n.uvs)return!0;let r=di(e,n);if(!r)return!1;let[s,i,a,c]=r;return Yt(e.uvs[s],n.uvs[a])&&Yt(e.uvs[i],n.uvs[c])}function jg(e,n,t,o){return t.materialKey!==o.materialKey?!1:Wo(e)||Wo(n)?mi(e,n):!e.uvs&&!n.uvs&&!e.textureTriangles?.length&&!n.textureTriangles?.length}function Wo(e){return!!(e.texture||e.material?.texture||e.textureTriangles?.length)}function mi(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=di(e,n);if(!t)return!1;let[o,r,s,i]=t;return Yt(e.uvs[o],n.uvs[s])&&Yt(e.uvs[r],n.uvs[i])}function cl(e,n,t){let o=e.get(n);o?o.add(t):e.set(n,new Set([t]))}function Hg(e,n,t,o,r,s){let i=[e],a=new Set([e]),c=[e];for(;c.length>0;){let l=c.shift();for(let u of t.get(l)??[]){if(o.has(u)||a.has(u))continue;let f=n[u],d=n[e];!f||!d||f.materialKey===d.materialKey&&Kg([...i,u],n,r,s)&&(i.push(u),a.add(u),c.push(u))}}return i}function Kg(e,n,t,o){let r=Sl(e,n);return!!r&&Al(e,n,r,t,o)}function Sl(e,n){let t=n[e[0]];if(!t)return null;let o=0,r=0,s=0,i=0,a=0,c=0,l=0;for(let m of e){let p=n[m];if(!p)return null;let h=qe(t.normal,p.normal)<0?-1:1,g=Math.max(p.area,1e-6);o+=p.normal[0]*h*g,r+=p.normal[1]*h*g,s+=p.normal[2]*h*g;for(let y of p.polygon.vertices)i+=y[0],a+=y[1],c+=y[2],l+=1}let u=vl([o,r,s]);if(!u||l===0)return null;let f=Cl(e,n),d=Zg(e,n,u,f);if(d){let m=(d.min+d.max)/2;return{normal:u,point:[u[0]*m,u[1]*m,u[2]*m],boundaryVertexKeys:f}}return{normal:u,point:[i/l,a/l,c/l],boundaryVertexKeys:f}}function Zg(e,n,t,o){let r=1/0,s=-1/0;for(let i of e){let a=n[i];if(a)for(let c of a.polygon.vertices){if(!o.has(sn(c)))continue;let l=qe(c,t);r=Math.min(r,l),s=Math.max(s,l)}}return Number.isFinite(r)&&Number.isFinite(s)?{min:r,max:s}:null}function Al(e,n,t,o,r){let s=Math.cos(r.maxAngleDeg*Math.PI/180),i=t.boundaryVertexKeys??Cl(e,n);for(let a of e){let c=n[a];if(!c||Math.abs(qe(c.normal,t.normal))<s)return!1;for(let l of c.polygon.vertices){let u=i.has(sn(l))?r.maxBoundaryDisplacement:o;if(Math.abs(pi(l,t))>u)return!1}}return!0}function Cl(e,n){let t=new Map;for(let r of e){let s=n[r];if(!s)continue;let i=s.polygon.vertices;for(let a=0;a<i.length;a++){let c=i[a],l=i[(a+1)%i.length],u=Wt(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(sn(r.a)),o.add(sn(r.b)));return o}function qg(e,n){let t=r=>gi(r,n),o=ui(e.textureTriangles,t);return{...e,vertices:e.vertices.map(t),...o?{textureTriangles:o}:{}}}function di(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 s=(r+1)%n.vertices.length;if(Xt(e.vertices[t],n.vertices[r])&&Xt(e.vertices[o],n.vertices[s]))return[t,o,r,s];if(Xt(e.vertices[t],n.vertices[s])&&Xt(e.vertices[o],n.vertices[r]))return[t,o,s,r]}}return null}function Wt(e,n){let t=sn(e),o=sn(n);return t<o?`${t}|${o}`:`${o}|${t}`}function sn(e){return`${e[0]},${e[1]},${e[2]}`}function Xt(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Yt(e,n){return Math.abs(e[0]-n[0])<=1e-4&&Math.abs(e[1]-n[1])<=1e-4}function Cn(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Tl(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 qe(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function El(e,n){return Math.hypot(e[0]-n[0],e[1]-n[1],e[2]-n[2])}function vl(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 pi(e,n){return qe(Cn(e,n.point),n.normal)}function gi(e,n){let t=pi(e,n);return[e[0]-n.normal[0]*t,e[1]-n.normal[1]*t,e[2]-n.normal[2]*t]}var Qg=36,Jg=.15,e0=.2,n0=650,t0=15e3,o0=.25;function hi(e){return!!(e.texture||e.material?.texture||e.uvs?.length||e.textureTriangles?.length)}function Il(e){let n=Pn(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 r0(e){let n=Pn(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 s0(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function _l(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),s=Math.min(n,t,o),i=r-s,a=0;return i!==0&&(r===n?a=60*((t-o)/i%6):r===t?a=60*((o-n)/i+2):a=60*((n-t)/i+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:i/r,value:r}}function i0(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function a0(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=_l(e),o=_l(n),r=t.saturation<.08,s=o.saturation<.08;if(r||s)return r===s;let i=Math.min(t.value,o.value)<.18?32:18;return i0(t.hue,o.hue)<=i}function c0(e,n){let t=new Map;for(let i of e.keys()){let a=r0(i);a&&t.set(i,a)}let o=[],r=new Map,s=Array.from(e.entries()).sort((i,a)=>a[1]-i[1]||i[0].localeCompare(a[0]));for(let[i]of s){let a=t.get(i);if(!a){r.set(i,i);continue}let c=null;for(let l of o){if(!a0(a,l.parsed))continue;let u=s0(a,l.parsed);u>n||(!c||u<c.distance)&&(c={color:l.color,distance:u})}c?r.set(i,c.color):(o.push({color:i,parsed:a}),r.set(i,i))}return r}function l0(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??Qg;if(!Number.isFinite(r)||r<=0)return e;let s=new Map,i=[];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||!hi(f)||hi(d))continue;let m=Il(d.color);i.push(u),s.set(m,(s.get(m)??0)+1)}if(s.size<2)return e;let a=c0(s,r),c=!1,l=e.polygons.slice();for(let u of i){let f=l[u],d=Il(f.color),m=a.get(d)??d;m!==d&&(l[u]={...f,color:m},c=!0)}return c?{...e,polygons:l}:e}function u0(e){let n=0;for(let t of e)hi(t)&&(n+=1);return e.length===0||n/e.length<=o0}function f0(e){return!!e.metadata?.stlTopology}function m0(e,n){return n?Math.max(e.simplifyEarlyStopDropRatio??Jg,e0):e.simplifyEarlyStopDropRatio}function Yn(e,n={}){return new yi(e,n).optimize()}var yi=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=l0(this.result,this.options,this.meshResolution),t=f0(n),o=t?"lossless":this.meshResolution,r=this.canSimplify(n.polygons,o),s=r&&n.polygons.length>=n0&&n.polygons.length<=t0,i=ul(n.polygons,{meshResolution:o,useCandidateFirst:s,staticSimplification:r?{simplifyTriangleMeshOptions:this.options.simplifyTriangleMeshOptions,earlyStopDropRatio:m0(this.options,s)}:!1,skipInteriorCull:t});return i===n.polygons?n:{...n,polygons:i}}canSimplify(n,t){return t==="lossy"&&this.options.simplifyTriangleMeshes!==!1&&u0(n)}};function d0(e){let n=e.vertices;if(!n||n.length<3)return null;let t=0,o=0,r=0;for(let[_,O,R]of n)t+=_,o+=O,r+=R;let s=1/n.length;t*=s,o*=s,r*=s;let i=n[0],a=n[1],c=n[2],l=a[0]-i[0],u=a[1]-i[1],f=a[2]-i[2],d=c[0]-i[0],m=c[1]-i[1],p=c[2]-i[2],h=u*p-f*m,g=f*d-l*p,y=l*m-u*d,x=Math.hypot(h,g,y);if(x<1e-9)return null;h/=x,g/=x,y/=x;let b=n.length-2,P=new Float64Array(b*9),A=0;for(let _=1;_<n.length-1;_++){let O=n[0],R=n[_],w=n[_+1];P[A++]=O[0],P[A++]=O[1],P[A++]=O[2],P[A++]=R[0],P[A++]=R[1],P[A++]=R[2],P[A++]=w[0],P[A++]=w[1],P[A++]=w[2]}let C=0,E=1/0,S=1/0,M=1/0,T=-1/0,v=-1/0,I=-1/0;for(let[_,O,R]of n){let w=_-t,F=O-o,D=R-r,K=w*w+F*F+D*D;K>C&&(C=K),_<E&&(E=_),_>T&&(T=_),O<S&&(S=O),O>v&&(v=O),R<M&&(M=R),R>I&&(I=R)}return{centroid:[t,o,r],normal:[h,g,y],triFlat:P,bcx:t,bcy:o,bcz:r,br2:C,minX:E,minY:S,minZ:M,maxX:T,maxY:v,maxZ:I}}function p0(e,n,t,o,r,s,i,a){let c=i[a],l=i[a+1],u=i[a+2],f=i[a+3]-c,d=i[a+4]-l,m=i[a+5]-u,p=i[a+6]-c,h=i[a+7]-l,g=i[a+8]-u,y=r*g-s*h,x=s*p-o*g,b=o*h-r*p,P=f*y+d*x+m*b;if(P>-1e-9&&P<1e-9)return!1;let A=1/P,C=e-c,E=n-l,S=t-u,M=A*(C*y+E*x+S*b);if(M<0||M>1)return!1;let T=E*m-S*d,v=S*f-C*m,I=C*d-E*f,_=A*(o*T+r*v+s*I);return _<0||M+_>1?!1:A*(p*T+h*v+g*I)>.001}function g0(e,n,t,o,r,s,i){let a=i.bcx-e,c=i.bcy-n,l=i.bcz-t,u=a*o+c*r+l*s,f=a-u*o,d=c-u*r,m=l-u*s;if(f*f+d*d+m*m>i.br2)return!1;let p=i.triFlat,h=p.length;for(let g=0;g<h;g+=9)if(p0(e,n,t,o,r,s,p,g))return!0;return!1}var jt=9,h0=6,Ge=12;function xi(e,n,t,o,r,s){let i=o-e,a=r-n,c=s-t;return i*a+a*c+c*i}function y0(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),s=new Float64Array(t),i=new Float64Array(t);for(let C=0;C<t;C++){let E=e[o[C]];r[C]=(E.minX+E.maxX)*.5,s[C]=(E.minY+E.maxY)*.5,i[C]=(E.minZ+E.maxZ)*.5}let a=2*Math.max(1,t)+1,c=new Float64Array(a*jt),l=0,u=new Float64Array(Ge),f=new Float64Array(Ge),d=new Float64Array(Ge),m=new Float64Array(Ge),p=new Float64Array(Ge),h=new Float64Array(Ge),g=new Int32Array(Ge),y=new Float64Array(Ge-1),x=new Int32Array(Ge-1),b=new Float64Array(Ge-1),P=new Int32Array(Ge-1);function A(C,E){let S=l++,M=S*jt,T=E-C,v=1/0,I=1/0,_=1/0,O=-1/0,R=-1/0,w=-1/0;for(let z=C;z<E;z++){let te=e[o[z]];te.minX<v&&(v=te.minX),te.maxX>O&&(O=te.maxX),te.minY<I&&(I=te.minY),te.maxY>R&&(R=te.maxY),te.minZ<_&&(_=te.minZ),te.maxZ>w&&(w=te.maxZ)}if(c[M]=v,c[M+1]=I,c[M+2]=_,c[M+3]=O,c[M+4]=R,c[M+5]=w,T<=h0)return c[M+6]=1,c[M+7]=C,c[M+8]=E,S;let F=1/0,D=1/0,K=1/0,H=-1/0,Q=-1/0,ne=-1/0;for(let z=C;z<E;z++)r[z]<F&&(F=r[z]),r[z]>H&&(H=r[z]),s[z]<D&&(D=s[z]),s[z]>Q&&(Q=s[z]),i[z]<K&&(K=i[z]),i[z]>ne&&(ne=i[z]);let ee=H-F,ue=Q-D,U=ne-K;if(ee===0&&ue===0&&U===0)return c[M+6]=1,c[M+7]=C,c[M+8]=E,S;let $=xi(v,I,_,O,R,w),k=$>0?1/$:0,L=T+1,W=0,Y=0;for(let z=0;z<3;z++){let te=z===0?F:z===1?D:K,ce=z===0?ee:z===1?ue:U;if(ce===0)continue;let ye=z===0?r:z===1?s:i,he=Ge/ce;u.fill(1/0),f.fill(1/0),d.fill(1/0),m.fill(-1/0),p.fill(-1/0),h.fill(-1/0),g.fill(0);for(let N=C;N<E;N++){let X=(ye[N]-te)*he|0;X>=Ge&&(X=Ge-1);let oe=e[o[N]];oe.minX<u[X]&&(u[X]=oe.minX),oe.maxX>m[X]&&(m[X]=oe.maxX),oe.minY<f[X]&&(f[X]=oe.minY),oe.maxY>p[X]&&(p[X]=oe.maxY),oe.minZ<d[X]&&(d[X]=oe.minZ),oe.maxZ>h[X]&&(h[X]=oe.maxZ),g[X]++}let xe=1/0,ge=1/0,Ae=1/0,Fe=-1/0,V=-1/0,G=-1/0,j=0;for(let N=0;N<Ge-1;N++)u[N]<xe&&(xe=u[N]),m[N]>Fe&&(Fe=m[N]),f[N]<ge&&(ge=f[N]),p[N]>V&&(V=p[N]),d[N]<Ae&&(Ae=d[N]),h[N]>G&&(G=h[N]),j+=g[N],y[N]=xi(xe,ge,Ae,Fe,V,G),x[N]=j;let J=1/0,le=1/0,re=1/0,pe=-1/0,be=-1/0,ie=-1/0,ae=0;for(let N=Ge-2;N>=0;N--){let X=N+1;u[X]<J&&(J=u[X]),m[X]>pe&&(pe=m[X]),f[X]<le&&(le=f[X]),p[X]>be&&(be=p[X]),d[X]<re&&(re=d[X]),h[X]>ie&&(ie=h[X]),ae+=g[X],b[N]=xi(J,le,re,pe,be,ie),P[N]=ae}for(let N=0;N<Ge-1;N++){if(x[N]===0||P[N]===0)continue;let X=.125+(y[N]*x[N]+b[N]*P[N])*k;X<L&&(L=X,W=z,Y=te+(N+1)/he)}}let se=W===0?r:W===1?s:i,Z=C,B=E-1;for(;Z<=B;)if(se[Z]<Y)Z++;else{let z=o[Z];o[Z]=o[B],o[B]=z;let te=r[Z];r[Z]=r[B],r[B]=te;let ce=s[Z];s[Z]=s[B],s[B]=ce;let ye=i[Z];i[Z]=i[B],i[B]=ye,B--}let q=Z;(q===C||q===E)&&(q=C+E>>1),c[M+6]=0;let me=A(C,q),fe=A(q,E);return c[S*jt+7]=me,c[S*jt+8]=fe,S}return t>0&&A(0,t),{data:c,nodeCount:l,polyIndices:o,meta:e}}function x0(e,n,t,o,r,s,i,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=s!==0?1/s:s>=0?1/0:-1/0,h=0;for(c[h++]=0;h>0;){let y=c[--h]*jt,x=(l[y]-e)*d,b=(l[y+3]-e)*d,P=x<b?x:b,A=x<b?b:x,C=(l[y+1]-n)*m,E=(l[y+4]-n)*m,S=C<E?C:E,M=C<E?E:C;if(P>M||S>A)continue;S>P&&(P=S),M<A&&(A=M);let T=(l[y+2]-t)*p,v=(l[y+5]-t)*p,I=T<v?T:v,_=T<v?v:T;if(!(P>_||I>A)&&(_<A&&(A=_),!(A<.001)))if(l[y+6]===1){let O=l[y+7]|0,R=l[y+8]|0;for(let w=O;w<R;w++){let F=u[w];if(F===i)continue;let D=f[F];if(D&&g0(e,n,t,o,r,s,D))return!0}}else c[h++]=l[y+7]|0,c[h++]=l[y+8]|0}return!1}function Ol(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 s=n[0]/r,i=n[1]/r,a=n[2]/r,c=e.map(d0);if(t&&t.size>0)for(let f of t)c[f]=null;let l=y0(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,h=d.centroid[2]+d.normal[2]*.001;d.normal[0]*s+d.normal[1]*i+d.normal[2]*a<=0||x0(m,p,h,s,i,a,f,l,u)&&o.add(f)}return o}var Ht=1e-5,bi=.001,Pi=6;function jo(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let a=1;a+1<n.length;a++){let c=n[a],l=n[a+1],u=c[1]-t[1],f=c[0]-t[0],d=c[2]-t[2],m=l[1]-t[1],p=l[0]-t[0],h=l[2]-t[2];o-=f*h-d*p,r-=d*m-u*h,s-=u*p-f*m}let i=Math.hypot(o,r,s);return i<1e-9?null:[o/i,r/i,s/i]}function Mi(e,n){let t=n.meshRotation,o=t?On(e,t):e;return Co(o,n.rotX,0,n.rotY)[2]}function gt(e,n,t=Ht){return Mi(e,n)>t}function Rl(e,n,t=Ht){let o=jo(e);return o===null||gt(o,n,t)}function Si(e){return`${e[0].toFixed(4)},${e[1].toFixed(4)},${e[2].toFixed(4)}`}function Ai(e){let n=new Map;for(let t of e){if(!t)continue;let o=Si(t);n.has(o)||n.set(o,t)}return Array.from(n,([t,o])=>({key:t,normal:o}))}function Vl(e){return Ai(e.map(jo))}function Ci(e,n=bi){let t=Math.abs(e[0]),o=Math.abs(e[1]),r=Math.abs(e[2]),s=Math.max(t,o,r);return s>1-n&&t+o+r-s<n}function Ll(e){return e.length<=Pi&&e.every(({normal:n})=>Ci(n))}function wl(e,n,t=Ht){let o=[];for(let{key:r,normal:s}of e)gt(s,n,t)&&o.push(r);return o.sort(),o.join("|")}function Ti(e,n,t,o,r){let s=(p,h,g)=>{let y=[0,0,0];return y[e]=p,y[(e+1)%3]=h,y[(e+2)%3]=g,y},i=s(n,-o,-o),a=s(n,o,-o),c=s(n,o,o),l=s(n,-o,o),u=s(t,-o,-o),f=s(t,o,-o),d=s(t,o,o),m=s(t,-o,o);return[{vertices:[i,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function Ei(e={}){let n=e.size??5,t=e.thickness??.025,o=e.negative??!1,r=e.xColor??"#ff3a3a",s=e.yColor??"#3aff3a",i=e.zColor??"#3a8aff",a=n*t/2,c=o?-n:0;return[...Ti(0,c,n,a,r),...Ti(1,c,n,a,s),...Ti(2,c,n,a,i)]}var b0=["right","left","front","back","top","bottom"];function vi(e){return[e[0],e[1],e[2]]}function Nl(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 P0(e){if(e.min&&e.max)return Nl(e.min,e.max);let n=e.center?vi(e.center):[0,0,0],t;typeof e.size=="number"?t=[e.size,e.size,e.size]:e.size?t=vi(e.size):t=[1,1,1];let o=[t[0]/2,t[1]/2,t[2]/2];return Nl([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 M0(e,n){let[t,o,r]=e,[s,i,a]=n;return[{name:"right",vertices:[[s,o,r],[s,i,r],[s,i,a],[s,o,a]]},{name:"left",vertices:[[t,i,r],[t,o,r],[t,o,a],[t,i,a]]},{name:"front",vertices:[[s,i,r],[t,i,r],[t,i,a],[s,i,a]]},{name:"back",vertices:[[t,o,r],[s,o,r],[s,o,a],[t,o,a]]},{name:"top",vertices:[[t,o,a],[s,o,a],[s,i,a],[t,i,a]]},{name:"bottom",vertices:[[t,i,r],[s,i,r],[s,o,r],[t,o,r]]}]}function S0(e,n){let t={...e,...n};return(e.data!==void 0||n?.data!==void 0)&&(t.data={...e.data??{},...n?.data??{}}),t}function A0(e,n){let t={vertices:e.vertices.map(vi)};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 Ii(e={}){let{min:n,max:t}=P0(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=M0(n,t),s=new Map(r.map(a=>[a.name,a])),i=[];for(let a of b0){let c=e.faces?.[a];if(c===!1)continue;let l=s.get(a);l&&i.push(A0(l,S0(o,c)))}return i}function Dl(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 C0(e,n,t,o,r){let s=(p,h,g)=>Dl(e,p,h,g),i=s(n,-o,-o),a=s(n,o,-o),c=s(n,o,o),l=s(n,-o,o),u=s(t,-o,-o),f=s(t,o,-o),d=s(t,o,o),m=s(t,-o,o);return[{vertices:[i,a,c,l],color:r},{vertices:[u,f,d,m],color:r},{vertices:[i,a,f,u],color:r},{vertices:[a,c,d,f],color:r},{vertices:[c,l,m,d],color:r},{vertices:[l,i,u,m],color:r}]}function T0(e,n,t,o,r){let s=(f,d,m)=>Dl(e,f,d,m),i=s(n,-o,-o),a=s(n,o,-o),c=s(n,o,o),l=s(n,-o,o),u=s(t,0,0);return[{vertices:[i,a,c,l],color:r},{vertices:[i,a,u],color:r},{vertices:[a,c,u],color:r},{vertices:[c,l,u],color:r},{vertices:[l,i,u],color:r}]}function E0(e){return e.map(n=>({...n,vertices:[...n.vertices].reverse()}))}function _i(e){let n=e.axis,t=e.sign??1,o=e.shaftLength??4,r=e.shaftHalfThickness??.05,s=e.headLength??.8,i=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+s)*t,p=T0(n,d,m,i,a),h=t===-1?E0(p):p;return c?[...C0(n,u,f,r,a),...h]:h}function Ho(e,n,t){let o=[0,0,0],r=(e+1)%3,s=(e+2)%3;return o[r]=Math.cos(t)*n,o[s]=Math.sin(t)*n,o}function Oi(e){let n=e.axis,t=e.radius,o=e.halfThickness??Math.max(.05,t*.04),r=e.segments??32,s=e.color??"#ffffff",i=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=Ho(n,i,u),m=Ho(n,i,f),p=Ho(n,a,u),h=Ho(n,a,f);c.push({vertices:[d,p,h,m],color:s})}return c}function Ri(e){let n=e.axis,t=e.outerRadius,o=e.color??"#ffffff",r=(n+1)%3,s=(n+2)%3,i=(a,c)=>{let l=[0,0,0];return l[n]=0,l[r]=a,l[s]=c,l};return[{vertices:[i(-t,-t),i(t,-t),i(t,t),i(-t,t)],color:o}]}function Vi(e){let n=e.axis,t=e.size??.4,o=e.offset??t*2,r=typeof o=="number"?o:o[0],s=typeof o=="number"?o:o[1],i=e.along??0,a=e.color??"#ffffff",c=(n+1)%3,l=(n+2)%3,u=(f,d)=>{let m=[0,0,0];return m[n]=i,m[c]=r+f,m[l]=s+d,m};return[{vertices:[u(-t,-t),u(t,-t),u(t,t),u(-t,t)],color:a}]}function Li(e){let{center:n,size:t,color:o="#ffffff"}=e,[r,s,i]=n,a=[[r+t,s,i],[r-t,s,i],[r,s+t,i],[r,s-t,i],[r,s,i+t],[r,s,i-t]];return[[0,2,4],[2,1,4],[1,3,4],[3,0,4],[2,0,5],[1,2,5],[3,1,5],[0,3,5]].map(l=>({vertices:[a[l[0]],a[l[1]],a[l[2]]],color:o}))}function wi(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,s=[[-1,r,0],[1,r,0],[-1,-r,0],[1,-r,0],[0,-1,r],[0,1,r],[0,-1,-r],[0,1,-r],[r,0,-1],[r,0,1],[-r,0,-1],[-r,0,1]].map(([c,l,u])=>{let f=Math.sqrt(c*c+l*l+u*u);return[c/f,l/f,u/f]}),i=[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]];for(let c=0;c<o;c++){let l=[...s],u=[],f=new Map,d=(m,p)=>{let h=m<p?`${m}-${p}`:`${p}-${m}`,g=f.get(h);if(g!==void 0)return g;let y=s[m],x=s[p],b=(y[0]+x[0])/2,P=(y[1]+x[1])/2,A=(y[2]+x[2])/2,C=Math.sqrt(b*b+P*P+A*A);b/=C,P/=C,A/=C;let E=l.length;return l.push([b,P,A]),f.set(h,E),E};for(let[m,p,h]of i){let g=d(m,p),y=d(p,h),x=d(h,m);u.push([m,g,x]),u.push([p,y,g]),u.push([h,x,y]),u.push([g,y,x])}s=l,i=u}let a=s.map(([c,l,u])=>[c*n,l*n,u*n]);return i.map(([c,l,u])=>({vertices:[a[c],a[l],a[u]],color:t}))}function Ni(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(([i,a,c])=>({vertices:[r[i],r[a],r[c]],color:t}))}function Di(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=n/Math.sqrt(1+o*o),s=[[-1,o,0],[1,o,0],[-1,-o,0],[1,-o,0],[0,-1,o],[0,1,o],[0,-1,-o],[0,1,-o],[o,0,-1],[o,0,1],[-o,0,-1],[-o,0,1]].map(([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:[s[a],s[c],s[l]],color:t}))}function Fi(e={}){let{size:n=100,color:t="#cccccc"}=e,o=(1+Math.sqrt(5))/2,r=1/o,s=n/Math.sqrt(3),a=[[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1],[0,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*s,u*s,f*s]);return[[12,13,4,8,0],[0,8,9,2,16],[16,17,1,12,0],[1,10,5,13,12],[17,3,11,10,1],[2,9,6,15,14],[2,14,3,17,16],[14,15,7,11,3],[18,6,9,8,4],[4,13,5,19,18],[5,10,11,7,19],[18,19,7,15,6]].map(l=>({vertices:l.map(u=>a[u]),color:t}))}function Kt(e={}){let{radius:n=50,height:t=100,radialSegments:o=12,color:r="#cccccc"}=e,s=e.radiusTop??n,i=t/2,a=-i,c=i,l=Math.max(3,o),u=[],f=Array.from({length:l+1},(p,h)=>h/l*Math.PI*2),d=n<=1e-6,m=s<=1e-6;for(let p=0;p<l&&!(d&&m);p++){let h=f[p],g=f[p+1],y=Math.cos(h)*n,x=Math.sin(h)*n,b=Math.cos(g)*n,P=Math.sin(g)*n,A=Math.cos(h)*s,C=Math.sin(h)*s,E=Math.cos(g)*s,S=Math.sin(g)*s,M=[y,x,a],T=[b,P,a],v=[E,S,c],I=[A,C,c];if(m){let _=[0,0,c];u.push({vertices:[M,T,_],color:r})}else if(d){let _=[0,0,a];u.push({vertices:[_,v,I],color:r})}else u.push({vertices:[M,T,v,I],color:r})}if(n>1e-6){let p=[0,0,a];for(let h=0;h<l;h++){let g=f[h],y=f[h+1],x=[Math.cos(g)*n,Math.sin(g)*n,a],b=[Math.cos(y)*n,Math.sin(y)*n,a];u.push({vertices:[[...p],[...b],[...x]],color:r})}}if(s>1e-6){let p=[0,0,c];for(let h=0;h<l;h++){let g=f[h],y=f[h+1],x=[Math.cos(g)*s,Math.sin(g)*s,c],b=[Math.cos(y)*s,Math.sin(y)*s,c];u.push({vertices:[[...p],[...x],[...b]],color:r})}}return u}function Bi(e={}){return Kt({...e,radiusTop:0})}function Ko(e,n,t,o){let r=Math.sin(e),s=Math.cos(e),i=Math.sin(n),a=Math.cos(n);return[(t+o*a)*s,(t+o*a)*r,o*i]}function ki(e={}){let{radius:n=50,tube:t=15,radialSegments:o=12,tubularSegments:r=16,color:s="#cccccc"}=e,i=Math.max(3,o),a=Math.max(3,r),c=[];for(let l=0;l<i;l++){let u=l/i*Math.PI*2,f=(l+1)/i*Math.PI*2;for(let d=0;d<a;d++){let m=d/a*Math.PI*2,p=(d+1)/a*Math.PI*2,h=Ko(u,m,n,t),g=Ko(f,m,n,t),y=Ko(f,p,n,t),x=Ko(u,p,n,t);c.push({vertices:[h,g,y,x],color:s})}}return c}var Fl=.01,Bl=.01;function kl(e,n){let t=Math.hypot(e[0],e[1],e[2])||1,o=e[0]/t,r=e[1]/t,s=e[2]/t,i=Math.sign(s||1)*Math.max(Math.abs(s),.01),a=n,c=.01;return[1,0,0,0,0,1,0,0,-o/i,-r/i,c,0,a*o/i,a*r/i,a*(1-c),1]}function Ul(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,s=n[2]/t;return e[0]*o+e[1]*r+e[2]*s>0}function Zo(e){if(e.length<=1)return e.map(i=>[i[0],i[1]]);let t=e.map(i=>[i[0],i[1]]);t.sort((i,a)=>i[0]-a[0]||i[1]-a[1]);let o=(i,a,c)=>(a[0]-i[0])*(c[1]-i[1])-(a[1]-i[1])*(c[0]-i[0]),r=[];for(let i of t){for(;r.length>=2&&o(r[r.length-2],r[r.length-1],i)<=0;)r.pop();r.push(i)}let s=[];for(let i=t.length-1;i>=0;i--){let a=t[i];for(;s.length>=2&&o(s[s.length-2],s[s.length-1],a)<=0;)s.pop();s.push(a)}return r.pop(),s.pop(),r.concat(s)}function Ui(e){let n=0,t=e.length;for(let o=0;o<t;o++){let r=e[o],s=e[(o+1)%t];n+=r[0]*s[1]-s[0]*r[1]}return n/2}function mn(e){let n=e.map(t=>[t[0],t[1]]);return Ui(n)<0&&n.reverse(),n}function zl(e,n,t){let o=Math.hypot(n[0],n[1],n[2])||1,r=n[0]/o,s=n[1]/o,i=n[2]/o,a=Math.sign(i||1)*Math.max(Math.abs(i),.01),c=e[2]-t;return[e[0]-r/a*c,e[1]-s/a*c]}function Tn(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 s=t;t=[];let i=n[r],a=n[(r+1)%o],c=f=>(a[0]-i[0])*(f[1]-i[1])-(a[1]-i[1])*(f[0]-i[0])>=0,l=(f,d)=>{let m=i[0],p=i[1],h=a[0],g=a[1],y=f[0],x=f[1],b=d[0],P=d[1],A=(m-h)*(x-P)-(p-g)*(y-b);if(Math.abs(A)<1e-12)return[f[0],f[1]];let C=((m-y)*(x-P)-(p-x)*(y-b))/A;return[m+C*(h-m),p+C*(g-p)]},u=s.length;for(let f=0;f<u;f++){let d=s[f],m=s[(f+u-1)%u],p=c(d),h=c(m);p?(h||t.push(l(m,d)),t.push([d[0],d[1]])):h&&t.push(l(m,d))}}return t}function qo(e){if(!Number.isFinite(e)||e<=0)throw new Error("PolyCSS world unit size must be a positive finite number.");return e}function zi(e,n=50){return e*qo(n)}function Gi(e,n=50){return e/qo(n)}function Qe(e,n=50){let t=qo(n);return[e[1]*t,e[0]*t,e[2]*t]}function $i(e,n=50){let t=qo(n);return[e[1]/t,e[0]/t,e[2]/t]}function Qo(e){return[e[1],e[0],e[2]]}function Xi(e){return e?.direction?{...e,direction:Qo(e.direction)}:e}var Gl=zi,$l=Gi,Xl=Qe,Yl=$i,Wl=Qo,jl=Xi;function Jo(e){return e==null?[1,1,1]:typeof e=="number"?[e,e,e]:[e[0]??1,e[1]??1,e[2]??1]}function ht(e){let n=Jo(e),t=n[0]===1&&n[1]===1&&n[2]===1;return(o,r)=>{let s=Qe(r),i=o[1]*50,a=o[0]*50,c=o[2]*50,l=t?i:i*n[0],u=t?a:a*n[1],f=t?c:c*n[2];return[l+s[0],u+s[1],f+s[2]]}}function Yi(e,n){if(e.length<3||n===0)return e;let t=[],o=e.length;for(let r=0;r<o;r++){let s=e[(r-1+o)%o],i=e[r],a=e[(r+1)%o],c=i[0]-s[0],l=i[1]-s[1],u=a[0]-i[0],f=a[1]-i[1],d=Math.hypot(c,l),m=Math.hypot(u,f);if(d<1e-9||m<1e-9){t.push(i);continue}let p=l/d,h=-c/d,g=f/m,y=-u/m,x=p+g,b=h+y,P=Math.hypot(x,b);if(P<1e-9){t.push(i);continue}let A=x/P,C=b/P,E=A*p+C*h;if(Math.abs(E)<1e-9){t.push(i);continue}let S=n/E;t.push([i[0]+A*S,i[1]+C*S])}return t}var Wi=.5,ji=.001,Hi=.5;function er(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(S=>t(S,n)),m=d[0],p=0,h=0,g=0;for(let S=1;S+1<d.length;S++){let M=d[S],T=d[S+1],v=M[0]-m[0],I=M[1]-m[1],_=M[2]-m[2],O=T[0]-m[0],R=T[1]-m[1],w=T[2]-m[2];p+=R*_-w*I,h+=w*v-O*_,g+=O*I-R*v}let y=Math.hypot(p,h,g);if(y<1e-9)continue;let x=[p/y,h/y,g/y],b=null;for(let S=1;S<d.length;S++){let M=d[S],T=M[0]-m[0],v=M[1]-m[1],I=M[2]-m[2],_=Math.hypot(T,v,I);if(_>1e-9){b=[T/_,v/_,I/_];break}}if(!b)continue;let P=b[0]*x[0]+b[1]*x[1]+b[2]*x[2];b=[b[0]-P*x[0],b[1]-P*x[1],b[2]-P*x[2]];let A=Math.hypot(b[0],b[1],b[2]);if(A<1e-9)continue;b=[b[0]/A,b[1]/A,b[2]/A];let C=[x[1]*b[2]-x[2]*b[1],x[2]*b[0]-x[0]*b[2],x[0]*b[1]-x[1]*b[0]],E=x[0]*m[0]+x[1]*m[1]+x[2]*m[2];r.push({face:f,O:m,n:x,u:b,v:C,offset:E,polyIndex:u})}let s=[];for(let u of r){let f=!1;for(let d of s){let m=d.rep;if(!(1-(u.n[0]*m.n[0]+u.n[1]*m.n[1]+u.n[2]*m.n[2])>ji)&&!(Math.abs(u.offset-m.offset)>Hi)){d.faces.push(u),f=!0;break}}f||s.push({rep:u,faces:[u]})}let i=[],a=3,c=u=>`${u[0].toFixed(a)},${u[1].toFixed(a)},${u[2].toFixed(a)}`;for(let u of s){if(u.faces.length===1){l(u.faces);continue}let f=u.faces.map(g=>{let y=new Set;for(let x of g.face.vertices)y.add(c(t(x,n)));return y}),d=u.faces.map((g,y)=>y),m=g=>{for(;d[g]!==g;)d[g]=d[d[g]],g=d[g];return g},p=(g,y)=>{let x=m(g),b=m(y);x!==b&&(d[x]=b)};for(let g=0;g<u.faces.length;g++)for(let y=g+1;y<u.faces.length;y++){let x=f[g],b=f[y],P=0;for(let A of x)if(b.has(A)&&(P++,P>=2))break;P>=2&&p(g,y)}let h=new Map;for(let g=0;g<u.faces.length;g++){let y=m(g),x=h.get(y);x||(x=[],h.set(y,x)),x.push(u.faces[g])}for(let g of h.values())l(g)}function l(u){let f=u[0],{O:d,n:m,u:p,v:h}=f,g=[],y=[],x=[];for(let A of u){let C=[];for(let E of A.face.vertices){let S=t(E,n),M=S[0]-d[0],T=S[1]-d[1],v=S[2]-d[2],I=[M*p[0]+T*p[1]+v*p[2],M*h[0]+T*h[1]+v*h[2]];g.push(I),C.push(I)}C.length>=3&&(y.push(mn(C)),x.push(A.polyIndex))}if(g.length<3)return;let b=Zo(g);if(b.length<3)return;let P=Yi(mn(b),Wi);i.push({O:d,n:m,u:p,v:h,outlineUv:P,memberPolysUv:y,memberPolyIndices:x})}return i}function Hl(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,s=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),i=e.position?Qe(e.position):[0,0,0],a=[];return(i[0]!==0||i[1]!==0||i[2]!==0)&&a.push(`translate3d(${i[0]}px, ${i[1]}px, ${i[2]}px)`),s&&(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 Kl(e={}){let n=e.target??Ee.target,t=e.autoCenterOffset??[0,0,0],o=e.layoutScale??1,r=e.worldUnitPx??50,s=(e.zoom??Ee.zoom)/r*o,i=(e.distance??Ee.distance)*o,a=Qe([n[0]+t[0],n[1]+t[1],n[2]+t[2]],r);return`${i!==0?`translateZ(${-i}px) `:""}scale(${s}) rotateX(${e.rotX??Ee.rotX}deg) rotate(${e.rotY??Ee.rotY}deg) translate3d(${-a[0]}px, ${-a[1]}px, ${-a[2]}px)`}var dn=50,Wn=[.4,-.7,.59],jn="#ffffff",Hn=1,Kn="#ffffff",Zn=.4,En=4096,Zt=1,nr=.1,tr=1,qt=En*En,or=qt*3,yt=2048,rr=4*1024*1024,sr=16*1024*1024,ir=.995,ar=512,Zl=12,Me=.001,de=1e-9,cr=1e-4,lr=.1,Qt=.01,ql=.75,Ql=1,Jl=250,eu=1.5,ur=.75,pn=3,fr=2,Jt=4,mr=[1,10,100,1e3,1e4,1e5,1e6],gn=64,dr=32,pr=96,Ye=64,gr=128,eo=50,no=1e-7,hn=16,hr=.9,We=.75,to=.2,yr=.05,xr=256,br=.6,nu=1.5;function Pr(e){return e===void 0||e==="auto"||!Number.isFinite(e)?1:Math.max(0,Math.min(1,e))}var oo=new Map;function qn(e){if(oo.has(e)){let t=oo.get(e);return t===void 0?null:t}let n=Pn(e);return oo.size>=ar&&oo.clear(),oo.set(e,n),n}function yn(e){let n=qn(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Mr({r:e,g:n,b:t}){return`${e},${n},${t}`}function ro(e){return qn(e)?.alpha??1}function so({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 io(e,n,t,o){let r=yn(n),s=yn(t),i=$e(r.r/255),a=$e(r.g/255),c=$e(r.b/255),l=$e(s.r/255),u=$e(s.g/255),f=$e(s.b/255);return{r:(i*e+l*o)*xt,g:(a*e+u*o)*xt,b:(c*e+f*o)*xt}}function tu({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 $e(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function v0(e){return e<=.0031308?e*12.92:1.055*Math.pow(e,1/2.4)-.055}var xt=1/Math.PI;function Vn(e,n,t,o,r){let s=yn(e),i=yn(t),a=yn(o),c=$e(s.r/255),l=$e(s.g/255),u=$e(s.b/255),f=$e(i.r/255),d=$e(i.g/255),m=$e(i.b/255),p=$e(a.r/255),h=$e(a.g/255),g=$e(a.b/255),y=c*(f*n+p*r)*xt,x=l*(d*n+h*r)*xt,b=u*(m*n+g*r)*xt,P=M=>Math.max(0,Math.min(255,Math.round(v0(Math.max(0,Math.min(1,M)))*255))),A=P(y),C=P(x),E=P(b),S=ro(e);return S<1?`rgba(${A}, ${C}, ${E}, ${S})`:so({r:A,g:C,b:E})}function Sr(e,n){if(!Number.isFinite(n)||n<=1)return e;let t=qn(e);if(!t)return e;let o=255/Math.max(1,Math.round(n)-1),r=i=>Math.max(0,Math.min(255,Math.round(Math.round(i/o)*o))),s={r:r(t.rgb[0]),g:r(t.rgb[1]),b:r(t.rgb[2])};return t.alpha<1?`rgba(${s.r}, ${s.g}, ${s.b}, ${t.alpha})`:so(s)}function ou(e,n){return!!e&&!!n&&e.r===n.r&&e.g===n.g&&e.b===n.b}function ru(e,n,t){let o=(r,s)=>{let i=s-r;return Math.abs(i)<=t?s:r+Math.sign(i)*t};return{r:o(e.r,n.r),g:o(e.g,n.g),b:o(e.b,n.b)}}function su(e,n=1){return n<1?`rgba(${e.r}, ${e.g}, ${e.b}, ${n})`:so(e)}function iu(e,n){if(e===void 0)return Number.POSITIVE_INFINITY;if(e===n)return 0;let t=qn(e),o=qn(n);if(!t||!o)return 1;let r=t.rgb[0]-o.rgb[0],s=t.rgb[1]-o.rgb[1],i=t.rgb[2]-o.rgb[2],a=(t.alpha-o.alpha)*255;return Math.sqrt(r*r+s*s+i*i+a*a)/510}function Ar(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}`},s=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=s.get(m);p?(p.degree+=1,p.degree===2?p.polyB=a:p.polyB=null):s.set(m,{polyA:a,polyB:null,vertA:f,vertB:d,degree:1})}}let i=new Map;for(let[a,c]of s)i.set(a,{polyA:c.polyA,polyB:c.polyB,vertA:c.vertA,vertB:c.vertB});return i}function Cr(e,n){let t=Math.hypot(n[0],n[1],n[2])||1,o=n[0]/t,r=n[1]/t,s=n[2]/t;return e.map(i=>i?i[0]*o+i[1]*r+i[2]*s<-1e-6:!0)}function Tr(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),s=l=>`${r(l[0])},${r(l[1])},${r(l[2])}`,i=t.map(([l,u])=>({a:l,b:u,aKey:s(l),bKey:s(u),used:!1})),a=new Map;for(let l of i){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 i){if(l.used)continue;let u=[l.a],f=l,d=l.aKey,m=l.bKey;f.used=!0;for(let p=0;p<i.length+1;p++){u.push(f.bKey===m?f.b:f.a);let h=a.get(m)??[],g=null;for(let y of h)if(!(y===f||y.used)){g=y;break}if(!g||(g.used=!0,d=m,m=g.aKey===d?g.bKey:g.aKey,f=g,m===l.aKey))break}u.length>=3&&c.push(u)}return c}var au=40;function cu(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}`},s=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=s.get(m);p||(p=[],s.set(m,p)),p.push(a)}}let i=new Map;for(let a of s.values())if(!(a.length<2))for(let c of a)for(let l of a){if(c===l)continue;let u=i.get(c);u||(u=new Set,i.set(c,u)),u.add(l)}return i}function lu(e,n,t,o){let r=ht(t),s=!!o&&(o[0]!==0||o[1]!==0||o[2]!==0),i=s?Qe(n):null,a=e.map(c=>{if(!c)return{vertices:[],color:""};let l=c.vertices.map(u=>r(u,n));return s&&i&&o&&(l=l.map(u=>{let f=[u[0]-i[0],u[1]-i[1],u[2]-i[2]],d=On(f,o);return[d[0]+i[0],d[1]+i[1],d[2]+i[2]]})),{vertices:l,color:""}});return Ar(a)}function uu(e,n,t,o,r){let s=[],i=ht(t),a=!!r&&(r[0]!==0||r[1]!==0||r[2]!==0),c=a?Qe(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(A=>i(A,n));a&&c&&r&&(f=f.map(A=>{let C=[A[0]-c[0],A[1]-c[1],A[2]-c[2]],E=On(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,h=-1/0,g=-1/0,y=-1/0;for(let A of f)A[0]<d&&(d=A[0]),A[0]>h&&(h=A[0]),A[1]<m&&(m=A[1]),A[1]>g&&(g=A[1]),A[2]<p&&(p=A[2]),A[2]>y&&(y=A[2]);let x=[[d,m,p],[h,m,p],[d,g,p],[h,g,p],[d,m,y],[h,m,y],[d,g,y],[h,g,y]],b=null,P=0;if(f.length>=3){let A=f[0],C=f[1],E=f[2],S=[C[0]-A[0],C[1]-A[1],C[2]-A[2]],M=[E[0]-A[0],E[1]-A[1],E[2]-A[2]],T=M[1]*S[2]-M[2]*S[1],v=M[2]*S[0]-M[0]*S[2],I=M[0]*S[1]-M[1]*S[0],_=Math.hypot(T,v,I);_>1e-9&&(b=[T/_,v/_,I/_],P=b[0]*A[0]+b[1]*A[1]+b[2]*A[2])}s.push({wv:f,bboxCorners:x,planeN:b,planeOffset:P,polygonIndex:l})}return s}function fu(e,n,t,o,r,s){let i=ht(t),a=!!s&&(s[0]!==0||s[1]!==0||s[2]!==0),c=a?Qe(n):null,f=er(e,n,a&&c&&s?(g,y)=>{let x=i(g,y),b=[x[0]-c[0],x[1]-c[1],x[2]-c[2]],P=On(b,s);return[P[0]+c[0],P[1]+c[1],P[2]+c[2]]}:i,o).map((g,y)=>{let{O:x,n:b,u:P,v:A,outlineUv:C,memberPolysUv:E,memberPolyIndices:S}=g,M=1/0,T=1/0,v=-1/0,I=-1/0;for(let Q of C)Q[0]<M&&(M=Q[0]),Q[1]<T&&(T=Q[1]),Q[0]>v&&(v=Q[0]),Q[1]>I&&(I=Q[1]);let _=v-M,O=I-T,R=r*50,w=x[0]+M*P[0]+T*A[0]+R*b[0],F=x[1]+M*P[1]+T*A[1]+R*b[1],D=x[2]+M*P[2]+T*A[2]+R*b[2],H=`matrix3d(${[P[0],P[1],P[2],0,A[0],A[1],A[2],0,b[0],b[1],b[2],0,w,F,D,1].map(Q=>Q.toFixed(4)).join(",")})`;return{O:x,n:b,u:P,v:A,outlineUv:C,memberPolysUv:E,memberPolyIndices:S,minU:M,minV:T,width:_,height:O,matrixCss:H,faceIndex:y,lift:R}}),d=.015,m=.5,p=20,h=new Set;for(let g=0;g<f.length;g++){if(h.has(g))continue;let y=f[g],x=y.n[0]*y.O[0]+y.n[1]*y.O[1]+y.n[2]*y.O[2],b=y.minU,P=y.minV,A=y.minU+y.width,C=y.minV+y.height;for(let E=0;E<f.length;E++){if(E===g||h.has(E))continue;let S=f[E];if(y.n[0]*S.n[0]+y.n[1]*S.n[1]+y.n[2]*S.n[2]<1-d)continue;let T=y.n[0]*S.O[0]+y.n[1]*S.O[1]+y.n[2]*S.O[2];if(T<=x+m||T-x>p)continue;let v=1/0,I=1/0,_=-1/0,O=-1/0;for(let R of S.outlineUv){let w=S.O[0]+R[0]*S.u[0]+R[1]*S.v[0],F=S.O[1]+R[0]*S.u[1]+R[1]*S.v[1],D=S.O[2]+R[0]*S.u[2]+R[1]*S.v[2],K=w-y.O[0],H=F-y.O[1],Q=D-y.O[2],ne=K*y.u[0]+H*y.u[1]+Q*y.u[2],ee=K*y.v[0]+H*y.v[1]+Q*y.v[2];ne<v&&(v=ne),ne>_&&(_=ne),ee<I&&(I=ee),ee>O&&(O=ee)}if(v<=b&&_>=A&&I<=P&&O>=C){let R=Math.max(0,A-b)*Math.max(0,C-P);if(Math.max(0,_-v)*Math.max(0,O-I)>R*2)continue;h.add(g);break}}}return f=f.filter((g,y)=>!h.has(y)),f}function mu(e){let{receiverPlanes:n,receiverPolygons:t,receiverHasTexture:o,casters:r,lightDir:s,cameraRot:i,ambientLight:a,directionalLight:c,shadow:l}=e,u=Math.hypot(s[0],s[1],s[2])||1,f=s[0]/u,d=s[1]/u,m=s[2]/u,p=a?.color??"#ffffff",h=a?.intensity??.4,g=c?.intensity??1,y=l?.color??"#000000",x=l?.opacity??.25,b=l?.maxExtend??2e3,P=[],A=r.map(S=>{let M=S.edgeOwners;if(!M||S.selfShadowEdgeMap)return null;let T=S.casterPolygonCount??0;if(T<au||S.items.length<au)return null;let v=0;for(let O of S.items)O.planeN&&v++;if(v*2<S.items.length)return null;let I=new Array(T).fill(null);for(let O of S.items)O.planeN&&O.polygonIndex<T&&(I[O.polygonIndex]=O.planeN);let _=Cr(I,s);return Tr(M,_)}),C=(S,M,T,v)=>{if(S.length<3)return[];let I=[],_=R=>(R[0]-M[0])*T[0]+(R[1]-M[1])*T[1]+(R[2]-M[2])*T[2],O=(R,w,F,D)=>{let K=(F-v)/(F-D);return[R[0]+K*(w[0]-R[0]),R[1]+K*(w[1]-R[1]),R[2]+K*(w[2]-R[2])]};for(let R=0;R<S.length;R++){let w=S[R],F=S[(R+S.length-1)%S.length],D=_(w),K=_(F),H=D>v,Q=K>v;H?(Q||I.push(O(F,w,K,D)),I.push(w)):Q&&I.push(O(F,w,K,D))}return I},E={rotX:i.rotX,rotY:i.rotY};for(let S of n){let{O:M,n:T,u:v,v:I,outlineUv:_,minU:O,minV:R,width:w,height:F}=S,D=f*T[0]+d*T[1]+m*T[2];if(D<=1e-6||!gt(T,E))continue;let K=ie=>(ie[0]-M[0])*T[0]+(ie[1]-M[1])*T[1]+(ie[2]-M[2])*T[2],H=(ie,ae,N,X)=>{let oe=N/(N-X);return[ie[0]+oe*(ae[0]-ie[0]),ie[1]+oe*(ae[1]-ie[1]),ie[2]+oe*(ae[2]-ie[2])]},Q=ie=>{let ae=ie[0]-M[0],N=ie[1]-M[1],X=ie[2]-M[2],oe=(ae*T[0]+N*T[1]+X*T[2])/D,ve=ie[0]-oe*f,Ce=ie[1]-oe*d,Pe=ie[2]-oe*m,Oe=ve-M[0],Re=Ce-M[1],Ve=Pe-M[2];return[Oe*v[0]+Re*v[1]+Ve*v[2],Oe*I[0]+Re*I[1]+Ve*I[2]]},ne=new Map,ee=0,ue=O,U=R,$=S.minU+w,k=S.minV+F,L=1/0,W=1/0,Y=-1/0,se=-1/0;for(let ie of r)for(let ae of ie.items)for(let N of ae.wv){let X=N[0]-M[0],oe=N[1]-M[1],ve=N[2]-M[2],Ce=X*v[0]+oe*v[1]+ve*v[2],Pe=X*I[0]+oe*I[1]+ve*I[2];Ce<L&&(L=Ce),Ce>Y&&(Y=Ce),Pe<W&&(W=Pe),Pe>se&&(se=Pe)}let Z=Number.isFinite(L)?[[L-b,W-b],[Y+b,W-b],[Y+b,se+b],[L-b,se+b]]:[],B=.05,q=T[0]*M[0]+T[1]*M[1]+T[2]*M[2],me=.0025,fe=5;for(let ie=0;ie<r.length;ie++){let ae=r[ie],N=ae.selfShadowEdgeMap,X=A[ie];if(X!==null){if(X.length===0)continue;for(let oe of X){if(oe.length<3)continue;let ve=C(oe,M,T,B);if(ve.length<3)continue;let Ce=ve.map(Q),Pe=mn(Ce),Oe=Z.length===4?Tn(Pe,Z):Pe;if(Oe.length<3)continue;let Re=Tn(Oe,_);if(Re.length<3)continue;let Ve;for(let Xe of S.memberPolysUv){let Te=Tn(Re,mn(Xe));Te.length<3||(Ve||(Ve=ne.get(ae.id),Ve||(Ve={id:ae.id,verts:[],subPolygonIndices:[]},ne.set(ae.id,Ve))),Ve.verts.push(Te),Ve.subPolygonIndices.push(-1),ee++)}}continue}for(let oe of ae.items){if(N){let Te=N.get(oe.polygonIndex);if(Te){let Be=!1;for(let De of S.memberPolyIndices)if(Te.has(De)){Be=!0;break}if(Be)continue}}if(oe.planeN&&oe.planeN[0]*f+oe.planeN[1]*d+oe.planeN[2]*m>-1e-6)continue;if(oe.planeN){let Te=oe.planeN,Be=Te[0]*T[0]+Te[1]*T[1]+Te[2]*T[2];if(Math.abs(Be)>1-me){let De=Be>0?1:-1;if(Math.abs(oe.planeOffset-De*q)<fe)continue}}let ve=oe.bboxCorners,Ce=!1,Pe=1/0,Oe=1/0,Re=-1/0,Ve=-1/0;for(let Te=0;Te<8;Te++){let Be=ve[Te];K(Be)>B&&(Ce=!0);let De=Q(Be);De[0]<Pe&&(Pe=De[0]),De[0]>Re&&(Re=De[0]),De[1]<Oe&&(Oe=De[1]),De[1]>Ve&&(Ve=De[1])}if(!Ce||Re<ue||Pe>$||Ve<U||Oe>k)continue;let Xe=oe.wv;for(let Te=1;Te<Xe.length-1;Te++){let Be=Xe[0],De=Xe[Te],rt=Xe[Te+1],st=K(Be),xn=K(De),Je=K(rt),bn=[],ke=[[Be,st],[De,xn],[rt,Je]];for(let He=0;He<3;He++){let[Ie,en]=ke[He],[cn,nn]=ke[(He+1)%3],Ke=en>B,ln=nn>B;Ke&&bn.push(Ie),Ke!==ln&&bn.push(H(Ie,cn,en,nn))}if(bn.length<3)continue;let je=bn.map(Q),Se=mn(je),Le=Z.length===4?Tn(Se,Z):Se;if(Le.length<3)continue;let we=Tn(Le,_);if(we.length<3)continue;let _e;for(let He of S.memberPolysUv){let Ie=Tn(we,mn(He));if(!(Ie.length<3)){if(N){let en=0,cn=1/0,nn=-1/0,Ke=1/0,ln=-1/0;for(let un=0;un<Ie.length;un++){let Ze=Ie[un],at=Ie[(un+1)%Ie.length];en+=Ze[0]*at[1]-at[0]*Ze[1],Ze[0]<cn&&(cn=Ze[0]),Ze[0]>nn&&(nn=Ze[0]),Ze[1]<Ke&&(Ke=Ze[1]),Ze[1]>ln&&(ln=Ze[1])}if(Math.abs(en)*.5<5)continue}_e||(_e=ne.get(ae.id),_e||(_e={id:ae.id,verts:[],subPolygonIndices:[]},ne.set(ae.id,_e))),_e.verts.push(Ie),_e.subPolygonIndices.push(oe.polygonIndex),ee++}}}}}if(ee===0||!(w>0)||!(F>0))continue;let z=x;if(o){let ae=g*Math.max(0,D)+Math.max(0,h);if(ae>0){let N=Math.max(0,h)/ae,X=Math.pow(N,1/2.4);z=x*(1-X)}else z=0}let te=S.memberPolyIndices[0]??0,ce=t[te]?.color??"#cccccc",ye=o?y:Vn(ce,0,"#000000",p,h),he=1/0,xe=1/0,ge=-1/0,Ae=-1/0;for(let ie of ne.values())for(let ae of ie.verts)for(let N of ae)N[0]<he&&(he=N[0]),N[0]>ge&&(ge=N[0]),N[1]<xe&&(xe=N[1]),N[1]>Ae&&(Ae=N[1]);he=Math.floor(he-1),xe=Math.floor(xe-1),ge=Math.ceil(ge+1),Ae=Math.ceil(Ae+1),he<O&&(he=O),xe<R&&(xe=R),ge>O+w&&(ge=O+w),Ae>R+F&&(Ae=R+F);let Fe=ge-he,V=Ae-xe;if(!(Fe>0)||!(V>0))continue;let G=S.lift,j=M[0]+he*v[0]+xe*I[0]+G*T[0],J=M[1]+he*v[1]+xe*I[1]+G*T[1],le=M[2]+he*v[2]+xe*I[2]+G*T[2],pe=`matrix3d(${[v[0],v[1],v[2],0,I[0],I[1],I[2],0,T[0],T[1],T[2],0,j,J,le,1].map(ie=>ie.toFixed(4)).join(",")})`,be=[];for(let ie of ne.values()){let ae="";for(let N of ie.verts){ae+=`M${(N[0][0]-he).toFixed(1)},${(N[0][1]-xe).toFixed(1)}`;for(let X=1;X<N.length;X++)ae+=`L${(N[X][0]-he).toFixed(1)},${(N[X][1]-xe).toFixed(1)}`;ae+="Z"}be.push({casterId:ie.id,d:ae,casterPolygonIndices:ie.subPolygonIndices})}P.push({faceIndex:S.faceIndex,memberPolyIndices:S.memberPolyIndices,matrixCss:pe,width:Fe,height:V,fill:ye,opacity:z,paths:be})}return P}var I0=Symbol.for("polycss.animation.triangleFrameSource"),_0=Symbol.for("polycss.animation.triangleFrameTarget"),Zi=2200,Er=2201,qi=2202;function O0(e,n){let t=0,o=1,r=1,s=Er,i=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 s=m,i=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 s},get repetitions(){return i},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 h=l.duration>0?Math.min(l.elapsed/l.duration,1):1;if(o=l.from+(l.to-l.from)*h,h>=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,s===Zi)t>=p&&(t=d.clampWhenFinished?p:0,c=!1);else if(s===Er){if(t>=p){let h=t%p,g=Math.floor(t/p);a+=g,t=h,i!==1/0&&a>=i&&(t=d.clampWhenFinished?p:0,c=!1)}}else if(p>0){let h=p*2,g=t%h;if(t>=h){let y=Math.floor(t/h);a+=y,i!==1/0&&a>=i?(t=d.clampWhenFinished?p:0,c=!1):t=g}}}},sampleTime(){if(s===qi){let m=e.duration,p=m*2,h=t%p;return h<=m?h:p-h}return t}},d}function R0(e){return e._internal}function Ki(e,n){return typeof n=="number"?e[n]:e.find(t=>t.name===n)}function du(e,n){let t=new Map,o=n,r=e;function s(f){let d=Ki(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=O0(d,n),t.set(d.index,m)),m}function i(f){let d=Ki(n.clips,f);return d?t.get(d.index)??null:null}function a(f){let d=[];for(let y of t.values()){let x=R0(y);x.advance(f),x.running&&x.enabled&&d.push({internal:x,clip:x.clip})}if(d.length===0)return;if(d.length===1){let{internal:y,clip:x}=d[0],b=y.sampleTime(),P=o[I0]?.(x.name,b);if(P&&r[_0]?.(P))return;let A=n.sample(x.name,b);e.setPolygons(A);return}let m=0;for(let{internal:y}of d)m+=y.weight;if(m<=0)return;let p=d.map(({internal:y,clip:x})=>({polygons:n.sample(x.name,y.sampleTime()),weight:y.weight/m})),h=p[0].polygons;if(h.length===0)return;let g=h.map((y,x)=>{let b=y.vertices.map((P,A)=>{let C=0,E=0,S=0;for(let{polygons:M,weight:T}of p){let v=M[x];if(!v)continue;let I=v.vertices[A];I&&(C+=I[0]*T,E+=I[1]*T,S+=I[2]*T)}return[C,E,S]});return{...y,vertices:b}});e.setPolygons(g)}function c(){for(let f of t.values())f.stop()}function l(f){let d=Ki(n.clips,f);d&&t.delete(d.index)}function u(){t.clear()}return{clipAction:s,existingAction:i,update:a,stopAllAction:c,uncacheClip:l,uncacheRoot:u}}var Ji={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},xu={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},V0={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 L0(e){return e===5120||e===5121||e===5122||e===5123}function bu(e){let n=globalThis.TextDecoder;return new n().decode(e)}function w0(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 i=decodeURIComponent(o),a=new Uint8Array(i.length);for(let c=0;c<i.length;c++)a[c]=i.charCodeAt(c)&255;return a}let r=globalThis.atob(o),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s}function N0(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,s=null;for(;o<e.byteLength;){let i=n.getUint32(o,!0),a=n.getUint32(o+4,!0),c=o+8;if(a===1313821514){let l=new Uint8Array(e,c,i);r=JSON.parse(bu(l))}else a===5130562&&(s=new Uint8Array(e,c,i));o=c+i}if(!r)throw new Error("parseGltf: no JSON chunk in GLB");return{doc:r,bin:s}}function pu(e){if(!e)return null;let n=/^(\d+)\.(\d+)(?:\D.*)?$/.exec(e);return n?[Number(n[1]),Number(n[2])]:null}function D0(e){let n=pu(e.asset?.version);if(!n||n[0]!==2)throw new Error(`parseGltf: only glTF asset v2 supported (got ${e.asset?.version??"missing"})`);let t=pu(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 F0(e,n,t){let o=e.buffers??[],r=new Set(e.extensionsRequired??[]),s=ea.some(i=>r.has(i));return o.map((i,a)=>{let c=i.uri;if(c){if(c.startsWith("data:"))return w0(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(s&&ea.some(l=>i.extensions?.[l]))return new Uint8Array(0);throw new Error(`parseGltf: buffer[${a}] has no uri and no GLB BIN chunk`)})}function co(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 s=o.byteOffset??0;if(s<0||o.byteLength<0||s+o.byteLength>r.byteLength)throw new Error(`parseGltf: bufferView ${t} outside buffer ${o.buffer}`);return{buffer:r,view:o}}function Pu(e,n,t,o){if(e.count<=0)return;let r=e.byteOffset??0,s=r+t*(e.count-1)+o;if(r<0||s>n.byteLength)throw new Error("parseGltf: accessor does not fit bufferView")}function Mu(e,n){return e.byteStride!==void 0&&e.byteStride>0?e.byteStride:n}function B0(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 vr(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Ji[o.componentType],s=xu[o.type];if(!r||!s)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);if(o.sparse||o.normalized||o.bufferView===void 0){let{values:g}=lo(e,n,t);return{array:B0(o.componentType,g,o.normalized),count:o.count,componentCount:s}}let{buffer:i,view:a}=co(e,n,o.bufferView),c=(a.byteOffset??0)+(o.byteOffset??0),l=o.count*s,u=r*s,f=Mu(a,u);if(Pu(o,a,f,u),f===u){let g=i.buffer.slice(i.byteOffset+c,i.byteOffset+c+l*r),y;switch(o.componentType){case 5120:y=new Int8Array(g);break;case 5121:y=new Uint8Array(g);break;case 5122:y=new Int16Array(g);break;case 5123:y=new Uint16Array(g);break;case 5125:y=new Uint32Array(g);break;case 5126:y=new Float32Array(g);break;default:throw new Error(`parseGltf: unhandled componentType ${o.componentType}`)}return{array:y,count:o.count,componentCount:s}}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(i.buffer),p=i.byteOffset+c,h=0;for(let g=0;g<o.count;g++){let y=p+g*f;for(let x=0;x<s;x++)d[h++]=Or(m,y+x*r,o.componentType)}return{array:d,count:o.count,componentCount:s}}function Or(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 gu(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 lo(e,n,t){let o=e.accessors?.[t];if(!o)throw new Error(`parseGltf: bad accessor ${t}`);let r=Ji[o.componentType],s=xu[o.type];if(!r||!s)throw new Error(`parseGltf: unsupported accessor type ${o.type}/${o.componentType}`);let i=r*s,a=new Array(o.count*s).fill(0);if(o.bufferView!==void 0){let{buffer:c,view:l}=co(e,n,o.bufferView),u=c.byteOffset+(l.byteOffset??0)+(o.byteOffset??0),f=Mu(l,i);Pu(o,l,f,i);let d=new DataView(c.buffer),m=0;for(let p=0;p<o.count;p++){let h=u+p*f;for(let g=0;g<s;g++){let y=Or(d,h+g*r,o.componentType);a[m++]=o.normalized?gu(y,o.componentType):y}}}if(o.sparse){let c=o.sparse,l=c.indices,u=Ji[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}=co(e,n,l.bufferView),m=f.byteOffset+(d.byteOffset??0)+(l.byteOffset??0),p=new DataView(f.buffer),{buffer:h,view:g}=co(e,n,c.values.bufferView),y=h.byteOffset+(g.byteOffset??0)+(c.values.byteOffset??0),x=new DataView(h.buffer);for(let b=0;b<c.count;b++){let P=Or(p,m+b*u,l.componentType);for(let A=0;A<s;A++){let C=Or(x,y+(b*s+A)*r,o.componentType);a[P*s+A]=o.normalized?gu(C,o.componentType):C}}}return{values:a,count:o.count,componentCount:s}}function k0(e,n,t){let o=[],r=[],s=globalThis;for(let i of e.images??[]){if(i.uri){if(t&&!i.uri.startsWith("data:"))try{o.push(new s.URL(i.uri,t).href)}catch{o.push(i.uri)}else o.push(i.uri);continue}if(i.bufferView!==void 0){let a;try{let{buffer:f,view:d}=co(e,n,i.bufferView),m=d.byteOffset??0;a=f.subarray(m,m+d.byteLength)}catch{o.push("");continue}let c=i.mimeType??"image/png",l=new s.Blob([a],{type:c}),u=s.URL.createObjectURL(l);o.push(u),r.push(u)}else o.push("")}return{urls:o,objectUrls:r}}function hu(e){switch(e??10497){case 33071:return"clamp-to-edge";case 33648:return"mirrored-repeat";case 10497:return"repeat";default:return"repeat"}}function U0(e,n){let t=n?.sampler!==void 0?e.samplers?.[n.sampler]:void 0;return{s:hu(t?.wrapS),t:hu(t?.wrapT)}}function Su(e){switch(e){case"BLEND":return"blend";case"MASK":return"mask";default:return"opaque"}}function z0(e,n){let t=new Map,o=e.materials??[];for(let r=0;r<o.length;r++){let s=o[r].pbrMetallicRoughness?.baseColorTexture?.index;if(s===void 0)continue;let i=e.textures?.[s],a=i?.source;if(a===void 0)continue;let c=n[a];c&&t.set(r,{url:c,wrap:U0(e,i),alphaMode:Su(o[r].alphaMode),texCoord:o[r].pbrMetallicRoughness?.baseColorTexture?.texCoord??0})}return t}function G0(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)),s=c=>Math.round(r(c)*255).toString(16).padStart(2,"0"),i=c=>Math.round(r(c)*255),a=t==="opaque"?1:r(o[3]??1);return a<1?`rgba(${i(o[0])}, ${i(o[1])}, ${i(o[2])}, ${Math.round(a*1e3)/1e3})`:`#${s(o[0])}${s(o[1])}${s(o[2])}`}var bt=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Au(e,n){let t=new Array(16);return Cu(t,e,n)}function Cu(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 Ir(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 Tu(e,n,t){let o=e?.[0]??0,r=e?.[1]??0,s=e?.[2]??0,i=n?.[0]??0,a=n?.[1]??0,c=n?.[2]??0,l=n?.[3]??1,u=t?.[0]??1,f=t?.[1]??1,d=t?.[2]??1,m=i+i,p=a+a,h=c+c,g=i*m,y=i*p,x=i*h,b=a*p,P=a*h,A=c*h,C=l*m,E=l*p,S=l*h;return[(1-(b+A))*u,(y+S)*u,(x-E)*u,0,(y-S)*f,(1-(g+A))*f,(P+C)*f,0,(x+E)*d,(P-C)*d,(1-(g+b))*d,0,o,r,s,1]}function $0(e){return e.matrix&&e.matrix.length===16?e.matrix.slice():Tu(e.translation,e.rotation,e.scale)}function Eu(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 ao(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 X0(e,n,t){let o=ao(e),r=ao(n),s=o[0]*r[0]+o[1]*r[1]+o[2]*r[2]+o[3]*r[3];if(s<0&&(s=-s,r=[-r[0],-r[1],-r[2],-r[3]]),s>.9995)return ao(Eu(o,r,t));let i=Math.acos(Math.max(-1,Math.min(1,s))),a=Math.sin(i),c=Math.sin((1-t)*i)/a,l=Math.sin(t*i)/a;return ao([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 vu(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 Iu(e){return e.matrix?e.matrix.slice():Tu(e.translation,e.rotation,e.scale)}function Y0(e){let n=e.scene??0,t=e.scenes?.[n]?.nodes;return t&&t.length>0?t:[]}function _u(e,n){let t=e.nodes??[],o=new Array(t.length),r=new Set,s=new Set,i=(c,l)=>{if(c<0||c>=t.length||s.has(c))return;let u=Au(l,n[c]??bt);o[c]=u,r.add(c),s.add(c);for(let f of t[c].children??[])i(f,u);s.delete(c)},a=Y0(e);if(a.length>0)for(let c of a)i(c,bt);for(let c=0;c<t.length;c++)r.has(c)||i(c,bt);return o}var Ou=Symbol("polycss.gltfAnimationRuntimeInfo"),W0=Symbol.for("polycss.animation.triangleFrameSource");function Ru(e,n){return e?e[Ou]?.withPolygonFilter(n):void 0}function Qi(e,n){return e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function j0(e,n,t){return Qi(e,n)||Qi(e,t)||Qi(n,t)}function yu(e,n,t,o,r){if(t===void 0)return;let{values:s,count:i,componentCount:a}=lo(e,n,t);if(i!==r||a<1)return;let c=[];for(let l=0;l<i;l++){let u=[];for(let f=0;f<o;f++)u.push(s[l*a+f]??0);c.push(u)}return c}function H0(e,n,t,o){if(t===void 0)return Array.from({length:o},()=>bt.slice());let{values:r,componentCount:s,count:i}=lo(e,n,t);if(s!==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,i-1);a.push(r.slice(l*16,l*16+16))}return a}function _r(e,n){let t=e.componentCount,o=e.interpolation==="CUBICSPLINE"?(n*3+1)*t:n*t;return e.output.slice(o,o+t)}function K0(e,n,t){let o=e.input;if(o.length===0)return[];if(o.length===1||n<=o[0])return _r(e,0);let r=o.length-1;if(n>=o[r])return _r(e,r);let s=0,i=r;for(;s+1<i;){let d=s+i>>1;o[d]<=n?s=d:i=d}let a=o[s],c=o[s+1],l=c>a?(n-a)/(c-a):0,u=_r(e,s),f=_r(e,s+1);return e.interpolation==="STEP"?u:t==="rotation"?X0(u,f,l):Eu(u,f,l)}function Vu(e,n){let t=[];for(let o=0;o<(e.animations?.length??0);o++){let r=e.animations[o],s=(r.samplers??[]).map(c=>{let l=lo(e,n,c.input),u=lo(e,n,c.output);return{input:l.values,output:u.values,componentCount:u.componentCount,interpolation:c.interpolation??"LINEAR"}}),i=[];for(let c of r.channels??[]){let l=c.target.node,u=c.target.path,f=s[c.sampler];l===void 0||!u||!f||u!=="translation"&&u!=="rotation"&&u!=="scale"||i.push({sampler:f,targetNode:l,path:u})}let a=i.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:i.length},channels:i})}return t}function Lu(e,n,t,o){let r=t.info.duration,s=r>0?(o%r+r)%r:Math.max(0,o),i=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=i[a.targetNode];if(!c)continue;let l=K0(a.sampler,s,a.path);c.matrix=void 0,a.path==="translation"?c.translation=l.slice(0,3):a.path==="rotation"?c.rotation=ao(l.slice(0,4)):a.path==="scale"&&(c.scale=l.slice(0,3))}return _u(e,i.map(Iu))}function Z0(e,n,t,o,r,s){if((e.animations??[]).length===0||t.length===0)return;let a=(e.nodes??[]).map(g=>vu(g)),c=a.map(Iu),l=_u(e,c),u=(e.skins??[]).map(g=>({joints:g.joints??[],inverseBindMatrices:H0(e,n,g.inverseBindMatrices,g.joints?.length??0)})),f=Vu(e,n),d=f.map(g=>g.info);if(d.length===0)return;let m=g=>{let y=t.map(x=>new Array(x.triangleMask.length).fill(!1));for(let x of g){let b=o[x];if(!b)return;let P=y[b.sourceIndex];if(!P||b.triangleIndex<0||b.triangleIndex>=P.length)return;P[b.triangleIndex]=!0}return y.map((x,b)=>{let P=t[b],A=new Set,C=0;for(let E=0;E+2<P.indices.length;E+=3,C++)x[C]&&(A.add(P.indices[E]),A.add(P.indices[E+1]),A.add(P.indices[E+2]));return{triangleMask:x,activeVertices:Array.from(A).sort((E,S)=>E-S)}})},p=(g,y,x,b,P,A,C,E,S)=>{let M=r(g),T=r(y),v=r(x),I={vertices:[M,T,v],color:b};return P&&(I.texture=P),P&&A&&(I.textureWrap=A),P&&C&&(I.textureAlphaMode=C),E&&(I.doubleSided=!0),S&&(I.uvs=S),I},h=g=>{let y=t.reduce((_,O,R)=>{let w=g?.[R]?.triangleMask??O.triangleMask,F=0;for(let D=0;D<w.length;D++)w[D]&&F++;return _+F},0),x=new Float64Array(Math.max(0,y*9)),b=new Array(y),P=new Array(y).fill(!1),A={polygonCount:0,vertices:x,colors:b,textureFlags:P,solidTriangles:!0},C=t.map(_=>new Array(_.positions.length)),E=u.map(_=>_.joints.map(()=>new Array(16))),S=(_,O)=>{let R=typeof _=="number"?f[_]:f.find(w=>w.info.name===_);return R?Lu(e,a,R,O):null},M=(_,O,R,w)=>{let F=R?.activeVertices,D=C[_],K=(H,Q,ne,ee)=>{let ue=D[H];ue?(ue[0]=Q,ue[1]=ne,ue[2]=ee):D[H]=[Q,ne,ee]};if(O.skinIndex!==void 0&&O.joints&&O.weights&&u[O.skinIndex]){let H=u[O.skinIndex],Q=O.joints,ne=O.weights,ee=E[O.skinIndex]??[];for(let U=0;U<H.joints.length;U++){let $=H.joints[U],k=w[$],L=H.inverseBindMatrices[U],W=ee[U]??(ee[U]=new Array(16));ee[U]=k&&L?Cu(W,k,L):void 0}let ue=U=>{let $=O.positions[U],k=0,L=0,W=0,Y=0,se=Q[U]??[],Z=ne[U]??[];for(let B=0;B<4;B++){let q=Z[B]??0;if(q<=0)continue;let me=Math.round(se[B]??0),fe=ee[me];if(!fe)continue;let z=fe[0]*$[0]+fe[4]*$[1]+fe[8]*$[2]+fe[12],te=fe[1]*$[0]+fe[5]*$[1]+fe[9]*$[2]+fe[13],ce=fe[2]*$[0]+fe[6]*$[1]+fe[10]*$[2]+fe[14];k+=z*q,L+=te*q,W+=ce*q,Y+=q}if(Y>0){let B=1/Y;K(U,k*B,L*B,W*B)}else K(U,O.meshBindWorld[0]*$[0]+O.meshBindWorld[4]*$[1]+O.meshBindWorld[8]*$[2]+O.meshBindWorld[12],O.meshBindWorld[1]*$[0]+O.meshBindWorld[5]*$[1]+O.meshBindWorld[9]*$[2]+O.meshBindWorld[13],O.meshBindWorld[2]*$[0]+O.meshBindWorld[6]*$[1]+O.meshBindWorld[10]*$[2]+O.meshBindWorld[14])};if(F)for(let U of F)ue(U);else for(let U=0;U<O.positions.length;U++)ue(U)}else{let H=O.meshNode!==null?w[O.meshNode]??O.meshBindWorld:O.meshBindWorld,Q=ne=>{let ee=O.positions[ne];K(ne,H[0]*ee[0]+H[4]*ee[1]+H[8]*ee[2]+H[12],H[1]*ee[0]+H[5]*ee[1]+H[9]*ee[2]+H[13],H[2]*ee[0]+H[6]*ee[1]+H[10]*ee[2]+H[14])};if(F)for(let ne of F)Q(ne);else for(let ne=0;ne<O.positions.length;ne++)Q(ne)}return D},T=(_,O)=>{let R=S(_,O);if(!R)return[];let w=[];for(let F=0;F<t.length;F++){let D=t[F],K=g?.[F],H=K?.triangleMask??D.triangleMask,Q=M(F,D,K,R),ne=0;for(let ee=0;ee+2<D.indices.length;ee+=3,ne++){if(!H[ne])continue;let ue=D.indices[ee],U=D.indices[ee+1],$=D.indices[ee+2],k=Q[ue],L=Q[U],W=Q[$];if(!k||!L||!W)continue;let Y;if(D.uvs&&D.texture){let Z=D.uvs[ue],B=D.uvs[U],q=D.uvs[$];Z&&B&&q&&(Y=[Z,B,q])}let se=p(k,L,W,D.color,D.texture,D.textureWrap,D.textureAlphaMode,D.doubleSided,Y);se&&w.push(se)}}return w},v=(_,O)=>{let R=S(_,O);if(!R)return null;x.length<y*9&&(x=new Float64Array(y*9),A.vertices=x),b.length<y&&(b=new Array(y),A.colors=b),P.length<y&&(P=new Array(y).fill(!1),A.textureFlags=P);let w=0,F=0,D=!1;for(let K=0;K<t.length;K++){let H=t[K],Q=g?.[K],ne=Q?.triangleMask??H.triangleMask,ee=M(K,H,Q,R),ue=0;for(let U=0;U+2<H.indices.length;U+=3,ue++){if(!ne[ue])continue;let $=H.indices[U],k=H.indices[U+1],L=H.indices[U+2],W=ee[$],Y=ee[k],se=ee[L];if(!W||!Y||!se)continue;s(W,x,F),s(Y,x,F+3),s(se,x,F+6),b[w]=H.color;let Z=!!H.texture;P[w]=Z,Z&&(D=!0),w++,F+=9}}return A.polygonCount=w,A.solidTriangles=!D,A},I={clips:d,sample:T};return I[W0]=v,I[Ou]={withPolygonFilter(_){let O=m(_);return O?h(O):void 0}},I};return h()}function Rr(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.materialColors??{},s=n?.materialTextures??{},i=e instanceof Uint8Array?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,a=i.byteLength,c,l=null;if(i.byteLength>=4&&new DataView(i).getUint32(0,!0)===1179937895){let V=N0(i);c=V.doc,l=V.bin}else c=JSON.parse(bu(new Uint8Array(i)));D0(c);let u=F0(c,l,n?.resolveBuffer),{urls:f,objectUrls:d}=k0(c,u,n?.baseUrl),m=z0(c,f),p=[],h=new Set,g=new Set(c.extensionsRequired??[]),y=g.has("KHR_mesh_quantization")||(c.extensionsUsed??[]).includes("KHR_mesh_quantization");function x(V,G){h.has(V)||(h.add(V),p.push(G))}function b(V,G){if(V===void 0)return!1;let j=c.accessors?.[V];if(!j)return!1;let J=le=>c.bufferViews?.[le]?.extensions?.[G]!==void 0;return!!(j.bufferView!==void 0&&J(j.bufferView)||j.sparse&&(J(j.sparse.indices.bufferView)||J(j.sparse.values.bufferView)))}function P(V){for(let G of ea)if(g.has(G)&&(V.extensions?.[G]||b(V.indices,G)||Object.values(V.attributes??{}).some(j=>b(j,G))))return G}function A(V,G){if(G instanceof Float32Array)return!0;let j=c.accessors?.[V];return y&&j?.type==="VEC3"&&L0(j.componentType)}function C(V,G){return(G!==null?c.nodes?.[G]?.weights:void 0)??V.weights??[]}function E(V,G,j,J,le){let re=j.targets;if(!re||re.length===0)return;let pe=C(V,J);if(!pe.some(ae=>Number.isFinite(ae)&&ae!==0))return;let be=Array.from({length:le},()=>[0,0,0]),ie=!1;for(let ae=0;ae<re.length;ae++){let N=pe[ae]??0;if(!Number.isFinite(N)||N===0)continue;let X=re[ae]?.POSITION;if(X===void 0)continue;let{array:oe,count:ve,componentCount:Ce}=vr(c,u,X);if(ve!==le||Ce<3){x(`morph-position-count:${G}:${ae}`,`Mesh ${V.name??G}: skipped morph target ${ae} POSITION with mismatched count`);continue}if(!A(X,oe)){x(`morph-position-type:${G}:${ae}`,`Mesh ${V.name??G}: skipped morph target ${ae} POSITION with unsupported accessor type`);continue}ie=!0;for(let Pe=0;Pe<le;Pe++){let Oe=Pe*Ce,Re=be[Pe];Re[0]+=Number(oe[Oe])*N,Re[1]+=Number(oe[Oe+1])*N,Re[2]+=Number(oe[Oe+2])*N}}return ie?be:void 0}let S=[],M=[],T=[],v=(c.meshes??[]).map((V,G)=>V.name??`mesh_${G}`),I=(c.materials??[]).map((V,G)=>V.name??`material_${G}`);function _(V,G){if(G===4)return V;let j=[];if(G===5)for(let J=0;J+2<V.length;J++)j.push(V[J],V[J+1+J%2],V[J+2-J%2]);else if(G===6)for(let J=0;J+2<V.length;J++)j.push(V[J+1],V[J+2],V[0]);return j}function O(V){let G=[];for(let j=0;j+2<V.length;j+=3){let J=V[j],le=V[j+1],re=V[j+2];G.push(J,le,re,J,re,le)}return G}function R(V,G,j){let J=c.meshes?.[V];if(J){if(!Array.isArray(J.primitives)){x(`malformed-primitives:${V}`,`Mesh ${J.name??V}: skipped mesh with non-array primitives`);return}for(let le=0;le<J.primitives.length;le+=1){let re=J.primitives[le];if(!re)continue;let pe=re.mode??4;if(pe!==4&&pe!==5&&pe!==6){let Se=V0[pe]??`mode ${pe}`;x(`unsupported-mode:${pe}`,`Skipped primitives with unsupported mode ${pe} (${Se})`);continue}if(re.extensions?.KHR_draco_mesh_compression&&g.has("KHR_draco_mesh_compression")){x("KHR_draco_mesh_compression","Skipped primitives with unsupported required extension KHR_draco_mesh_compression");continue}let be=P(re);if(be){x(be,`Skipped primitives with unsupported required extension ${be}`);continue}if(re.attributes.POSITION===void 0){x(`missing-position:${V}`,`Mesh ${J.name??V}: skipped primitive without POSITION attribute`);continue}let ie=re.material!==void 0?c.materials?.[re.material]:void 0,ae=Su(ie?.alphaMode),N=ie?.name,oe=(N?r[N]:void 0)??G0(ie,o,ae),ve=ie?.doubleSided===!0,Ce=re.material!==void 0?m.get(re.material):void 0,Pe=N&&s[N]?s[N]:re.material!==void 0?Ce?.url:void 0,Oe=Pe&&re.material!==void 0?Ce?.wrap:void 0,Re=Pe?Ce?.alphaMode??ae:void 0,Ve=Pe?Ce?.texCoord??0:0,Xe=re.attributes.POSITION,{array:Te,count:Be,componentCount:De}=vr(c,u,Xe);if(!A(Xe,Te))continue;let rt=E(J,V,re,j,Be),st=[],xn=[];for(let Se=0;Se<Be;Se++){let Le=Se*De,we=rt?.[Se],_e=[Number(Te[Le])+(we?.[0]??0),Number(Te[Le+1])+(we?.[1]??0),Number(Te[Le+2])+(we?.[2]??0)];st.push(_e),xn.push(Ir(G,_e))}let Je=null,bn=re.attributes[`TEXCOORD_${Ve}`];if(Pe&&bn!==void 0){let{array:Se,count:Le}=vr(c,u,bn);Je=[];let we=1;Se instanceof Uint8Array?we=1/255:Se instanceof Uint16Array&&(we=1/65535);for(let _e=0;_e<Le;_e++){let He=Se[_e*2]*we,Ie=Se[_e*2+1]*we;Je.push([He,1-Ie])}}let ke;if(re.indices!==void 0){let{array:Se,count:Le}=vr(c,u,re.indices);ke=[];for(let we=0;we<Le;we++)ke.push(Number(Se[we]))}else ke=xn.map((Se,Le)=>Le);ke=_(ke,pe),ve&&(ke=O(ke));let je;if((c.animations?.length??0)>0){let Se=yu(c,u,re.attributes.JOINTS_0,4,Be),Le=yu(c,u,re.attributes.WEIGHTS_0,4,Be);je={sourceIndex:M.length,meshNode:j,meshBindWorld:G,skinIndex:j!==null?c.nodes?.[j]?.skin:void 0,positions:st,indices:ke,triangleMask:[],color:oe,texture:Pe,textureWrap:Oe,textureAlphaMode:Re,doubleSided:ve,uvs:Je??void 0,joints:Se,weights:Le},M.push(je)}for(let Se=0;Se+2<ke.length;Se+=3){let Le=ke[Se],we=ke[Se+1],_e=ke[Se+2],He=je?je.triangleMask.length:void 0;je&&je.triangleMask.push(!1);let Ie=xn[Le],en=xn[we],cn=xn[_e];if(!Ie||!en||!cn)continue;let nn;if(Je&&Pe){let ln=Je[Le],it=Je[we],un=Je[_e];ln&&it&&un&&(nn=[ln,it,un])}let Ke=`${V}:${le}:${j??"root"}`;S.push({v0:Ie,v1:en,v2:cn,color:oe,texture:Pe,textureWrap:Oe,textureAlphaMode:Re,doubleSided:ve,uvs:nn,simplifySourceVertexKeys:[`${Ke}:${Le}`,`${Ke}:${we}`,`${Ke}:${_e}`],source:je,sourceIndex:je?.sourceIndex,sourceTriangleIndex:He})}}}}function w(V,G,j){if(j.has(V)){x(`recursive-node:${V}`,`Skipped recursive node reference ${V} in glTF scene graph`);return}let J=c.nodes?.[V];if(!J)return;let le=Au(G,$0(J));typeof J.mesh=="number"&&R(J.mesh,le,V),j.add(V);for(let re of J.children??[])w(re,le,j);j.delete(V)}function F(V){let G=new Set,j=V.info.duration;for(let J of V.channels)for(let le of J.sampler.input)!Number.isFinite(le)||le<=0||j>0&&le>=j||G.add(le);return j>0&&(G.add(j*.25),G.add(j*.5),G.add(j*.75)),Array.from(G).sort((J,le)=>J-le).slice(0,128)}function D(V,G){let j=V.source;if(!j||V.sourceTriangleIndex===void 0||j.skinIndex!==void 0)return;let J=V.sourceTriangleIndex*3,le=j.indices[J],re=j.indices[J+1],pe=j.indices[J+2],be=le!==void 0?j.positions[le]:void 0,ie=re!==void 0?j.positions[re]:void 0,ae=pe!==void 0?j.positions[pe]:void 0;if(!be||!ie||!ae)return;let N=j.meshNode!==null?G[j.meshNode]??j.meshBindWorld:j.meshBindWorld;return{v0:Ir(N,be),v1:Ir(N,ie),v2:Ir(N,ae)}}function K(V,G){return V[0]===G[0]&&V[1]===G[1]&&V[2]===G[2]}function H(V){return K(V.v0,V.v1)||K(V.v0,V.v2)||K(V.v1,V.v2)}function Q(){return S.some(V=>!H(V))}function ne(){if(S.length===0||(c.animations?.length??0)===0||Q())return;let V=Vu(c,u);if(V.length===0)return;let G=(c.nodes??[]).map(J=>vu(J)),j=new Array(S.length);for(let J of V)for(let le of F(J)){let re=Lu(c,G,J,le);for(let pe=0;pe<S.length;pe++){if(j[pe])continue;let be=D(S[pe],re);be&&!H(be)&&(j[pe]=be)}}if(j.some(Boolean))for(let J=0;J<S.length;J++){let le=j[J];le&&(S[J].v0=le.v0,S[J].v1=le.v1,S[J].v2=le.v2)}}let ee=c.scene??0,ue=c.scenes?.[ee]?.nodes;if(ue&&ue.length>0)for(let V of ue)w(V,bt,new Set);else{(c.meshes?.length??0)===0&&x("no-gltf-meshes","No glTF meshes found");for(let V=0;V<(c.meshes?.length??0);V++)R(V,bt,null)}ne();let U=q0(d);if(S.length===0)return{polygons:[],objectUrls:d,dispose:U,warnings:p,metadata:{triangleCount:0,meshes:v,materials:I,sourceBytes:a}};let $=1/0,k=1/0,L=1/0,W=-1/0,Y=-1/0,se=-1/0;for(let V of S)for(let G of[V.v0,V.v1,V.v2])G[0]<$&&($=G[0]),G[0]>W&&(W=G[0]),G[1]<k&&(k=G[1]),G[1]>Y&&(Y=G[1]),G[2]<L&&(L=G[2]),G[2]>se&&(se=G[2]);let Z=Math.max(W-$,Y-k,se-L),B=Z>0?t/Z:1,q=n?.center,me=q===!0||q==="center",fe=me?($+W)*.5:$,z=me?(k+Y)*.5:k,te=me?(L+se)*.5:L,ce=V=>Math.round(V*1e3)/1e3,ye=n?.upAxis??"y",he=ye==="z"?([V,G,j])=>[ce((V-fe)*B),ce((G-z)*B),ce((j-te)*B)]:([V,G,j])=>[ce((j-te)*B),ce((V-fe)*B),ce((G-z)*B)],xe=ye==="z"?(V,G,j)=>{G[j]=ce((V[0]-fe)*B),G[j+1]=ce((V[1]-z)*B),G[j+2]=ce((V[2]-te)*B)}:(V,G,j)=>{G[j]=ce((V[2]-te)*B),G[j+1]=ce((V[0]-fe)*B),G[j+2]=ce((V[1]-z)*B)},ge=[],Ae=0;for(let V of S){let G=he(V.v0),j=he(V.v1),J=he(V.v2),le=j0(G,j,J);if(V.source&&V.sourceTriangleIndex!==void 0&&(V.source.triangleMask[V.sourceTriangleIndex]=!le),le){Ae++;continue}let re={vertices:[G,j,J],color:V.color};V.texture&&(re.texture=V.texture),V.texture&&V.textureWrap&&(re.textureWrap=V.textureWrap),V.texture&&V.textureAlphaMode&&(re.textureAlphaMode=V.textureAlphaMode),V.doubleSided&&(re.doubleSided=!0),V.uvs&&(re.uvs=V.uvs),V.simplifySourceVertexKeys&&(re.simplifySourceVertexKeys=V.simplifySourceVertexKeys),ge.push(re),T.push(V.sourceIndex!==void 0&&V.sourceTriangleIndex!==void 0?{sourceIndex:V.sourceIndex,triangleIndex:V.sourceTriangleIndex}:void 0)}ge.length===0&&Ae>0&&x("all-projected-triangles-degenerate","No non-degenerate glTF triangles remained after normalization");let Fe=Z0(c,u,M,T,he,xe);return{polygons:ge,animation:Fe,objectUrls:d,dispose:U,warnings:p,metadata:{triangleCount:ge.length,meshes:v,materials:I,animations:Fe?.clips,sourceBytes:a}}}function q0(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 zu=Symbol("polycss.solidTextureBakedAnimationInfo"),wu=Symbol.for("polycss.animation.triangleFrameSource"),Q0=16*1024*1024,J0=2,eh=32,nh=2,th=.08,oh=8,rh=128,Nu=32,sh=.045,ih=10,Pt=6,ah=16;function na(e){return e.material?.texture??e.texture}function ch(){let e=globalThis;return typeof e.Image!="function"||typeof e.document?.createElement!="function"?null:{Image:e.Image,createCanvas(){return e.document.createElement("canvas")}}}function lh(e,n){return new Promise((t,o)=>{let r=new n,s=!1,i=a=>{s||(s=!0,a())};r.decoding="async",r.onload=()=>i(()=>t(r)),r.onerror=()=>i(()=>o(new Error(`texture load failed: ${e}`))),r.src=e})}async function uh(e,n,t){try{let o=await lh(e,n.Image),r=Math.max(0,Math.floor(o.naturalWidth||o.width||0)),s=Math.max(0,Math.floor(o.naturalHeight||o.height||0));if(r<=0||s<=0||r*s>t)return null;let i=n.createCanvas();i.width=r,i.height=s;let a=i.getContext("2d",{willReadFrequently:!0});if(!a)return null;a.drawImage(o,0,0,r,s);let c=a.getImageData(0,0,r,s).data;return{width:r,height:s,data:c,lowDetail:fh(r,s,c)}}catch{return null}}function Du(e,n,t,o,r,s){let i=(o*n+t)*4,a=(s*n+r)*4;return Math.max(Math.abs((e[i]??0)-(e[a]??0)),Math.abs((e[i+1]??0)-(e[a+1]??0)),Math.abs((e[i+2]??0)-(e[a+2]??0)))}function fh(e,n,t){let o=Math.max(1,Math.floor(Math.max(e,n)/rh)),r=0,s=0,i=0;for(let a=0;a<n;a+=o)for(let c=0;c<e;c+=o){if(c+o<e){let l=Du(t,e,c,a,c+o,a);i+=l,r++,l>Nu&&s++}if(a+o<n){let l=Du(t,e,c,a,c,a+o);i+=l,r++,l>Nu&&s++}}return r>0&&s/r<=sh&&i/r<=ih}function Fu(e,n,t){return Math.max(n,Math.min(t,e))}function Bu(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 mh(e,n,t){let o=n[0],r=1-n[1],s=Bu(o,t?.s),i=Bu(r,t?.t);if(s===null||i===null)return null;let a=Fu(Math.floor(s*e.width),0,e.width-1),l=(Fu(Math.floor(i*e.height),0,e.height-1)*e.width+a)*4;return{r:e.data[l]??0,g:e.data[l+1]??0,b:e.data[l+2]??0,a:e.data[l+3]??255}}function Ln(e,n,t,o,r,s){return[e[0]*o+n[0]*r+t[0]*s,e[1]*o+n[1]*r+t[1]*s]}function dh(e){let[n,t,o]=e;return[Ln(n,t,o,1/3,1/3,1/3),Ln(n,t,o,.8,.1,.1),Ln(n,t,o,.1,.8,.1),Ln(n,t,o,.1,.1,.8),Ln(n,t,o,.45,.45,.1),Ln(n,t,o,.45,.1,.45),Ln(n,t,o,.1,.45,.45)]}function ph(e){let[n,t,o]=e,r=dh(e);for(let s=1;s<Pt;s++)for(let i=1;i<Pt-s;i++){let a=Pt-s-i;a<=0||r.push(Ln(n,t,o,s/Pt,i/Pt,a/Pt))}return r}function Gu(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 ta(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 Vr(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 $u(e){if(!e)return null;let n=e.trim().toLowerCase(),t=n.match(/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i);if(t){let s=t[1],i=a=>{let c=s.length<=4?s[a]+s[a]:s.slice(a*2,a*2+2);return parseInt(c,16)};return{r:i(0),g:i(1),b:i(2),a:s.length===4||s.length===8?i(3):255}}let 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 gh(){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 Xu(e){return`${e.r},${e.g},${e.b},${e.a}`}function ku(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=Xu(n),o=e.colors.get(t);e.colors.set(t,{color:n,count:(o?.count??0)+1}),e.count++}function Uu(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 hh(e){if(e.count<oh||e.colors.size<=1||e.colors.size>nh)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*th));return t<=o?n.color:null}function yh(e,n,t,o){let r=Gu(e);if(r.length===0)return null;let s=gh(),i=e.textureAlphaMode==="opaque"?$u(e.color):null;for(let a of r)for(let c of ph(a.uvs)){let l=mh(n,c,e.textureWrap);if(!l)return null;if(e.textureAlphaMode==="opaque"&&l.a===0&&e.color){i&&ku(s,{...i,a:255});continue}e.textureAlphaMode==="opaque"&&(l.a=255),ku(s,l)}if(s.count===0)return e.textureAlphaMode==="opaque"&&e.color?e.color:null;if(e.textureAlphaMode==="opaque"&&s.max.a===0&&e.color)return e.color;if(ta(s.min,s.max,t))return Vr(Uu(s));if(!o){let a=hh(s);if(a)return Vr(a)}return o||!n.lowDetail||!ta(s.min,s.max,eh)?null:Vr(Uu(s))}function Yu(e,n){let{texture:t,textureWrap:o,textureAlphaMode:r,material:s,uvs:i,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 xh(e,n){if(n.length<2)return e;let t=[],o=new Map;for(let l of n){let u=$u(e[l]?.color);if(!u||u.a<255)continue;let f=Xu(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=[],s=new Map,i=[...o.entries()].sort((l,u)=>u[1].count-l[1].count||l[0].localeCompare(u[0]));for(let[l,u]of i){let f=null;for(let d of r)if(ta(u.color,d,ah)){f=d;break}f||(f=u.color,r.push(f)),s.set(l,Vr(f))}let a=!1,c=e.slice();for(let l of t){let u=s.get(l.key),f=e[l.index];!u||!f||f.color===u||(c[l.index]={...f,color:u},a=!0)}return a?c:e}function bh(e,n){let t=e.slice();for(let o=0;o<n.length;o++){let r=n[o],s=e[r.index];s&&(t[r.index]=Yu(s,r.color))}return t}function Wu(e){return e?e[zu]:void 0}async function ju(e,n={}){if(n.enabled===!1)return null;let t=ch();if(!t)return null;let o=e.filter(c=>na(c)&&Gu(c).length>0);if(o.length===0)return null;let r=n.maxTexturePixels??Q0,s=new Map;await Promise.all(Array.from(new Set(o.map(c=>na(c)))).map(async c=>{s.set(c,await uh(c,t,r))}));let i=n.colorTolerance??J0,a=n.colorTolerance!==void 0;return{bake(c){let l=!1,u=[],f=c.map((d,m)=>{let p=na(d);if(!p)return d;let h=s.get(p);if(!h)return d;let g=yh(d,h,i,a);return g?(l=!0,u.push(m),Yu(d,g)):d});return l?{polygons:xh(f,u),changed:!0,bakedIndices:u}:{polygons:c,changed:!1,bakedIndices:u}}}}async function Hu(e,n={}){let t=await ju(e,n);return t?t.bake(e).polygons:e}async function Lr(e,n={}){let t=await ju(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 s=e.animation,i=s&&{...s,sample(a,c){return bh(s.sample(a,c),r)}};if(i&&s){let a=s[wu];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};i[wu]=(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,h=m.solidTriangles===!0||!!p;for(let g=0;g<m.polygonCount;g++){let y=c.get(g);l[g]=y??m.colors?.[g],p?.[g]&&!y&&(h=!1)}return u.polygonCount=m.polygonCount,u.vertices=m.vertices,u.textureFlags=p,u.solidTriangles=h,u}}i[zu]={source:s,bakedColorEntries:r}}return{...e,polygons:o.polygons,animation:i}}var Ku=Symbol.for("polycss.animation.triangleFrameSource");function Ph(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 Mh(e){let n=fn(e);if(n.length>=e.length)return[];let t=new Map;e.forEach((r,s)=>t.set(r,s));let o=[];for(let r of n){let s=t.get(r);if(s===void 0)return[];let i=Ph(e,s);if(!i)return[];o.push(i)}return o}function oa(e,n,t=!1){let o=new Array(n.length);for(let r=0;r<n.length;r++){let s=n[r],i=s.sourceRefs,a=new Array(i.length/2);for(let l=0,u=0;l<i.length;l+=2,u++){let d=e[i[l]]?.vertices[i[l+1]];if(!d)return e;let m=d[0],p=d[1],h=d[2];if(!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(h))return e;a[u]=[m,p,h]}let c=t?s.rest.color:e[i[0]??-1]?.color??s.rest.color;o[r]={...s.rest,vertices:a,color:c}}return o}function Sh(e,n){let t=new Map;return n.forEach((o,r)=>{t.set(o,r)}),e.map((o,r)=>({...o,sourceRefs:o.sourceRefs.map((s,i)=>i%2===0?t.get(s)??-1:s)}))}function Ah(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],s=n[o];if(!r||r.vertices.length!==s.rest.vertices.length)return null;t[o]={...s.rest,vertices:r.vertices,color:s.rest.color}}return t}function Ch(e){return!!(e.texture||e.material?.texture)}function Zu(e,n={}){if(!e.animation||e.polygons.length===0||n.meshResolution==="lossless")return e;let t=Mh(e.polygons);if(t.length===0||t.length>=e.polygons.length)return e;let o=Wu(e.animation),r=o?.source??e.animation,s=t.map(x=>x.originalIndex),i=Ru(r,s),a=i??r,c=i?Sh(t,s):t,l=t.map(x=>x.rest.color),u=t.every(x=>x.rest.vertices.length===3&&!Ch(x.rest)),f=i&&!o&&t.length===s.length&&t.every((x,b)=>x.rest.vertices.length===3&&x.sourceRefs.length===6&&x.sourceRefs[0]===s[b]&&x.sourceRefs[2]===s[b]&&x.sourceRefs[4]===s[b]),d=a[Ku],m=new Float64Array(t.length*9),p=l.slice(),h=new Array(t.length).fill(!1),g={polygonCount:t.length,vertices:m,colors:p,textureFlags:h,solidTriangles:u},y={...e.animation,sample(x,b){let P=a.sample(x,b);return f?P:i&&o?u&&t.length===s.length?Ah(P,t)??oa(P,c,!0):oa(P,c,!0):oa(P,c,!!o)}};return d&&u&&(y[Ku]=(x,b)=>{let P=d(x,b);if(!P)return P;if(i)return P.polygonCount<t.length||P.vertices.length<t.length*9?null:(g.polygonCount=t.length,g.vertices=P.vertices,g.colors=o?l:P.colors,g.textureFlags=o?h:P.textureFlags,g.solidTriangles=o?u:P.solidTriangles===!0,g);m.length<t.length*9&&(m=new Float64Array(t.length*9),g.vertices=m),p.length<t.length&&(p=new Array(t.length),g.colors=p),h.length<t.length&&(h=new Array(t.length).fill(!1),g.textureFlags=h);let A=u&&P.solidTriangles!==!1;for(let C=0;C<c.length;C++){let E=c[C],S=E.sourceRefs;for(let v=0,I=0;v<S.length;v+=2,I++){let _=S[v],O=S[v+1];if(_<0||_>=P.polygonCount)return null;let R=_*9+O*3,w=C*9+I*3;if(R+2>=P.vertices.length)return null;m[w]=P.vertices[R],m[w+1]=P.vertices[R+1],m[w+2]=P.vertices[R+2]}let M=S[0],T=!!P.textureFlags?.[M];h[C]=T,p[C]=o?E.rest.color:P.colors?.[M]??E.rest.color,!o&&T&&(A=!1)}return g.polygonCount=t.length,g.vertices=m,g.colors=p,g.textureFlags=h,g.solidTriangles=o?u:A,g}),{...e,polygons:t.map(x=>x.rest),animation:y,metadata:{...e.metadata,triangleCount:t.length}}}var Th=/^[0-9A-Fa-f]{6}$/,Eh=["#3b82f6","#ef4444","#22c55e","#eab308","#a855f7","#06b6d4","#f97316","#ec4899"];function vh(e){let n=[],t="";for(let o of e.split(`
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 wr(e,n){let t=n?.targetSize??60,o=n?.defaultColor??"#888888",r=n?.palette??Eh,s=n?.materialColors??{},i=n?.materialTextures??{},a=[],c=[],l=[],u=[],f=new Map,d=[],m=new Set,p=o,h,g=n?.includeObjects?new Set(n.includeObjects):null,y=n?.excludeObjects?new Set(n.excludeObjects):null,x=null,b=()=>x===null?g===null:!(g&&!g.has(x)||y&&y.has(x)),P=U=>U in s?s[U]:Th.test(U)?`#${U}`:(f.has(U)||(f.set(U,r[u.length%r.length]),u.push(U)),f.get(U)),A=(U,$)=>{m.has(U)||(m.add(U),d.push($))},C=(U,$)=>{let k=parseInt(U,10);return Number.isFinite(k)?k<0?$+k:k-1:NaN},E=vh(e);for(let U of E)if(!(U.length===0||U.charCodeAt(0)===35)){if(U.startsWith("v ")){let $=U.trim().split(/\s+/);a.push([parseFloat($[1]),parseFloat($[2]),parseFloat($[3])])}else if(U.startsWith("vt ")){let $=U.trim().split(/\s+/);c.push([parseFloat($[1]),parseFloat($[2])])}else if(U.startsWith("o "))x=U.trim().slice(2).trim();else if(U.startsWith("usemtl ")){let $=U.trim().split(/\s+/)[1];p=P($),h=i[$]}else if(U.startsWith("p "))b()&&A("unsupported-point-elements","Skipped OBJ point elements; PolyCSS only renders face polygons");else if(U.startsWith("l "))b()&&A("unsupported-line-elements","Skipped OBJ line elements; PolyCSS only renders face polygons");else if(U.startsWith("f ")){if(!b())continue;let $=U.trim().split(/\s+/).slice(1),k=[],L=[];for(let W of $){let Y=W.split("/");k.push(C(Y[0],a.length));let se=Y[1];if(se&&se.length>0){let Z=C(se,c.length);L.push(Number.isFinite(Z)?Z:null)}else L.push(null)}l.push({idx:k,uvIdx:L,color:p,texture:h})}}if(a.length===0||l.length===0)return Ih(u,e.length,d);let S=new Set;for(let U of l)for(let $ of U.idx)S.add($);let M=1/0,T=1/0,v=1/0,I=-1/0,_=-1/0,O=-1/0;for(let U of S){let $=a[U];$&&($[0]<M&&(M=$[0]),$[0]>I&&(I=$[0]),$[1]<T&&(T=$[1]),$[1]>_&&(_=$[1]),$[2]<v&&(v=$[2]),$[2]>O&&(O=$[2]))}let R=Math.max(I-M,_-T,O-v),w=R>0?t/R:1,F=n?.center,D=F===!0||F==="center",K=D?(M+I)*.5:M,H=D?(T+_)*.5:T,Q=D?(v+O)*.5:v,ne=U=>Math.round(U*1e3)/1e3,ee=a.map(([U,$,k])=>[ne((k-Q)*w),ne((U-K)*w),ne(($-H)*w)]),ue=[];for(let{idx:U,uvIdx:$,color:k,texture:L}of l)for(let W=1;W<U.length-1;W++){let Y=U[0],se=U[W],Z=U[W+1],B=ee[Y],q=ee[se],me=ee[Z];if(!B||!q||!me||B[0]===q[0]&&B[1]===q[1]&&B[2]===q[2]||B[0]===me[0]&&B[1]===me[1]&&B[2]===me[2]||q[0]===me[0]&&q[1]===me[1]&&q[2]===me[2])continue;let fe;if(L){let te=$[0],ce=$[W],ye=$[W+1];if(te!=null&&ce!=null&&ye!=null){let he=c[te],xe=c[ce],ge=c[ye];he&&xe&&ge&&(fe=[he,xe,ge])}}let z={vertices:[B,q,me],color:k};L&&(z.texture=L),fe&&(z.uvs=fe),ue.push(z)}return{polygons:ue,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:ue.length,materials:u,sourceBytes:e.length}}}function Ih(e,n,t=[]){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:t,metadata:{triangleCount:0,materials:e,sourceBytes:n}}}var ra=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,"0");function Nr(e){let n={},t={},o=null;for(let r of e.split(`
3
- `)){let s=r.trim();if(!(s.length===0||s.charCodeAt(0)===35)){if(s.startsWith("newmtl ")){o=s.slice(7).trim();continue}if(o){if(s.startsWith("Kd ")){let i=s.split(/\s+/),a=parseFloat(i[1]),c=parseFloat(i[2]),l=parseFloat(i[3]);Number.isFinite(a)&&Number.isFinite(c)&&Number.isFinite(l)&&(n[o]=`#${ra(a)}${ra(c)}${ra(l)}`)}else if(s.startsWith("map_Kd ")){let i=s.split(/\s+/),a=i[i.length-1]?.replace(/\\+/g,"/");a&&a!=="map_Kd"&&(t[o]=a)}}}}return{colors:n,textures:t}}var _h=[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 Oh(e){let n=e>>0&255,t=e>>8&255,o=e>>16&255;return[n,t,o]}function sa(e){return(e&255).toString(16).padStart(2,"0")}function Ju(e,n,t){return`#${sa(e)}${sa(n)}${sa(t)}`}function Rh(e,n,t,o){if(o>=255)return Ju(e,n,t);let r=Math.round(Math.max(0,Math.min(255,o))/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function ef(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 nf(e,n){return Math.hypot(e.rgb[0]-n.rgb[0],e.rgb[1]-n.rgb[1],e.rgb[2]-n.rgb[2])}function qu(e){let n=e.rgb[0]/255,t=e.rgb[1]/255,o=e.rgb[2]/255,r=Math.max(n,t,o),s=Math.min(n,t,o),i=r-s,a=0;return i!==0&&(r===n?a=60*((t-o)/i%6):r===t?a=60*((o-n)/i+2):a=60*((n-t)/i+4)),a<0&&(a+=360),{hue:a,saturation:r===0?0:i/r,value:r}}function Vh(e,n){let t=Math.abs(e-n)%360;return t>180?360-t:t}function tf(e,n){if(e.alpha<1||n.alpha<1)return!1;let t=qu(e),o=qu(n),r=t.saturation<.08,s=o.saturation<.08;if(r||s)return r===s;let i=Math.min(t.value,o.value)<.16?35:24;return Vh(t.hue,o.hue)<=i}function Lh(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=ef(a);c&&o.set(a,c)}let r=[],s=new Map,i=Array.from(e.entries()).sort((a,c)=>c[1]-a[1]||a[0].localeCompare(c[0]));for(let[a]of i){let c=o.get(a);if(!c){s.set(a,a);continue}let l=null;for(let u of r){if(!tf(c,u.parsed))continue;let f=nf(c,u.parsed);f>t||(!l||f<l.distance)&&(l={color:u.color,distance:f})}l?s.set(a,l.color):(r.push({color:a,parsed:c}),s.set(a,a))}return s}var wh=[[1,0],[-1,0],[0,1],[0,-1]];function of(e,n){return`${e},${n}`}function Nh(e){let n=e.indexOf(",");return[Number(e.slice(0,n)),Number(e.slice(n+1))]}function Dh(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 Fh(e,n){let t=n??0;if(!Number.isFinite(t)||t<=0)return;let o=new Map,r=s=>(o.has(s)||o.set(s,ef(s)),o.get(s)??null);for(let s of e.values()){if(s.size<3)continue;let i=new Map;for(let l of s.values())i.set(l,(i.get(l)??0)+1);let a=new Set,c=[];for(let[l,u]of s){if(a.has(l))continue;let f=[l],d=[],m=new Map,p=1/0,h=-1/0,g=1/0,y=-1/0;for(a.add(l);f.length>0;){let C=f.pop();d.push(C);let[E,S]=Nh(C);p=Math.min(p,E),h=Math.max(h,E),g=Math.min(g,S),y=Math.max(y,S);for(let[M,T]of wh){let v=of(E+M,S+T),I=s.get(v);if(I){if(I===u){a.has(v)||(a.add(v),f.push(v));continue}m.set(I,(m.get(I)??0)+1)}}}let x=h-p+1,b=y-g+1;if(!Dh(d.length,x,b)||m.size===0)continue;let P=r(u);if(!P)continue;let A=null;for(let[C,E]of m){let S=i.get(C)??0;if(S<=d.length)continue;let M=r(C);if(!M||!tf(P,M))continue;let T=nf(P,M);if(T>t)continue;let v={color:C,contacts:E,distance:T,count:S};(!A||v.contacts>A.contacts||v.contacts===A.contacts&&v.count>A.count||v.contacts===A.contacts&&v.count===A.count&&v.distance<A.distance||v.contacts===A.contacts&&v.count===A.count&&v.distance===A.distance&&v.color.localeCompare(A.color)<0)&&(A=v)}if(A)for(let C of d)c.push([C,A.color])}for(let[l,u]of c)s.set(l,u)}}var Bh=542658390,kh=new Set(["nTRN","nGRP","nSHP"]),Uh="Skipped MagicaVoxel scene graph transforms; models were flattened into one grid";function Dr(e,n){let t=n?.targetSize??60,o=e.byteLength;if(e.byteLength<8)return Mt(o,["parseVox: buffer too small to be a valid .vox file"]);let r=new DataView(e);if(r.getUint32(0,!0)!==Bh)return Mt(o,["parseVox: not a .vox file (bad magic)"]);if(e.byteLength<20)return Mt(o,["parseVox: buffer too small for MAIN chunk"]);if(Qu(r,8)!=="MAIN")return Mt(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=k=>{d.includes(k)||d.push(k)};for(;c<l&&c+12<=e.byteLength;){let k=Qu(r,c),L=r.getUint32(c+4,!0),W=r.getUint32(c+8,!0),Y=c+12,se=Y+L+W;if(k==="SIZE"){if(L>=12&&Y+12<=e.byteLength){let Z=r.getUint32(Y,!0),B=r.getUint32(Y+4,!0),q=r.getUint32(Y+8,!0);u.push({sx:Z,sy:B,sz:q})}}else if(k==="XYZI"){if(L>=4&&Y+4<=e.byteLength){let Z=r.getUint32(Y,!0),B=[],q=Math.min(Z,Math.floor((L-4)/4));for(let me=0;me<q;me++){let fe=Y+4+me*4;B.push({x:r.getUint8(fe),y:r.getUint8(fe+1),z:r.getUint8(fe+2),colorIndex:r.getUint8(fe+3)})}f.push(B)}}else if(k==="RGBA"&&L>=1024&&Y+1024<=e.byteLength){m=[];for(let Z=0;Z<256;Z++){let B=Y+Z*4,q=r.getUint8(B),me=r.getUint8(B+1),fe=r.getUint8(B+2),z=r.getUint8(B+3);m.push(Rh(q,me,fe,z))}}kh.has(k)&&p(Uh),c=se}let h=[],g=new Set;for(let k of f)for(let L of k){if(L.colorIndex===0)continue;let W=`${L.x},${L.y},${L.z}`;g.has(W)||(g.add(W),h.push(L))}if(h.length===0)return Mt(o,d);let y=new Map,x=k=>{let L=y.get(k);if(L)return L;let W=k-1,Y;if(m!==null)Y=m[W]??"#888888";else{let se=_h[k]??0,[Z,B,q]=Oh(se);Y=Ju(Z,B,q)}return y.set(k,Y),Y},b=new Map;for(let k of h){let L=x(k.colorIndex);b.set(L,(b.get(L)??0)+1)}let P=Lh(b,n?.paletteMergeDistance),A=k=>{let L=x(k);return P?.get(L)??L},C=(k,L,W)=>g.has(`${k},${L},${W}`),E=new Map,S=(k,L,W,Y,se)=>{let Z=`${k}:${L}`,B=E.get(Z);B||(B=new Map,E.set(Z,B)),B.set(of(W,Y),se)};for(let k of h){let{x:L,y:W,z:Y}=k,se=A(k.colorIndex);C(L+1,W,Y)||S(0,L+1,W,Y,se),C(L-1,W,Y)||S(1,L,W,Y,se),C(L,W+1,Y)||S(2,W+1,L,Y,se),C(L,W-1,Y)||S(3,W,L,Y,se),C(L,W,Y+1)||S(4,Y+1,L,W,se),C(L,W,Y-1)||S(5,Y,L,W,se)}Fh(E,n?.colorRegionMergeDistance);let M=new Map;for(let[k,L]of E)for(let[W,Y]of L){let se=`${k}:${Y}`,Z=M.get(se);Z||(Z=new Set,M.set(se,Z)),Z.add(W)}function T(k){let L=new Set,W=[],Y=1/0,se=-1/0,Z=1/0,B=-1/0;for(let q of k){let[me,fe]=q.split(","),z=+me,te=+fe;z<Y&&(Y=z),z>se&&(se=z),te<Z&&(Z=te),te>B&&(B=te)}for(let q=Z;q<=B;q++)for(let me=Y;me<=se;me++){let fe=`${me},${q}`;if(!k.has(fe)||L.has(fe))continue;let z=1;for(;me+z<=se;){let ce=`${me+z},${q}`;if(!k.has(ce)||L.has(ce))break;z++}let te=1;e:for(;q+te<=B;){for(let ce=0;ce<z;ce++){let ye=`${me+ce},${q+te}`;if(!k.has(ye)||L.has(ye))break e}te++}for(let ce=0;ce<te;ce++)for(let ye=0;ye<z;ye++)L.add(`${me+ye},${q+ce}`);W.push({u:me,v:q,w:z,h:te})}return W}let v=(k,L,W,Y,se,Z)=>{let B=W+se,q=Y+Z;switch(k){case 0:return[[L,W,Y],[L,B,Y],[L,B,q],[L,W,q]];case 1:return[[L,B,Y],[L,W,Y],[L,W,q],[L,B,q]];case 2:return[[W,L,Y],[W,L,q],[B,L,q],[B,L,Y]];case 3:return[[B,L,Y],[B,L,q],[W,L,q],[W,L,Y]];case 4:return[[W,Y,L],[B,Y,L],[B,q,L],[W,q,L]];default:return[[W,q,L],[B,q,L],[B,Y,L],[W,Y,L]]}},I=[];for(let[k,L]of M){let W=k.indexOf(":"),Y=k.indexOf(":",W+1),se=+k.slice(0,W),Z=+k.slice(W+1,Y),B=k.slice(Y+1);for(let{u:q,v:me,w:fe,h:z}of T(L))I.push({vertices:v(se,Z,q,me,fe,z),color:B})}if(I.length===0)return Mt(o,d);let _=1/0,O=1/0,R=1/0,w=-1/0,F=-1/0,D=-1/0;for(let k of I)for(let L of k.vertices)L[0]<_&&(_=L[0]),L[0]>w&&(w=L[0]),L[1]<O&&(O=L[1]),L[1]>F&&(F=L[1]),L[2]<R&&(R=L[2]),L[2]>D&&(D=L[2]);let K=Math.max(w-_,F-O,D-R),H=K>0?t/K:1,Q=H*50,ne=Number.isFinite(Q)&&Q>0?Math.max(1,Math.round(Q))/50:H,ee={kind:"magica-vox",cells:h.map(k=>({x:F-(k.y+1),y:k.x-_,z:k.z-R,color:A(k.colorIndex)})),rows:Math.max(0,F-O),cols:Math.max(0,w-_),depth:Math.max(0,D-R),scale:ne,sourceBytes:o},ue=k=>Math.round(k*1e3)/1e3,U=k=>[ue((k[0]-_)*ne),ue((k[1]-O)*ne),ue((k[2]-R)*ne)],$=I.map(({vertices:k,color:L})=>({vertices:k.map(U),color:L}));return{polygons:$,voxelSource:ee,objectUrls:[],dispose:()=>{},warnings:d,metadata:{triangleCount:$.length,sourceBytes:o,voxelCount:h.length}}}function Qu(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 Mt(e,n){return{polygons:[],objectUrls:[],dispose:()=>{},warnings:n,metadata:{triangleCount:0,sourceBytes:e}}}var zh="#888888";var Gh=/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/,Qn="COLOR=";function af(e,n,t){let o=n??t;if(!Number.isFinite(o))throw new Error(`parseStl: ${e} must be finite`);return o}function $h(e,n,t){let o=af(e,n,t);if(o<=0)throw new Error(`parseStl: ${e} must be greater than 0`);return o}function Xh(e){if(e===void 0||e==="z"||e==="y")return e??"z";throw new Error('parseStl: upAxis must be "z" or "y"')}function Yh(e){let n=e??zh;if(typeof n!="string"||n.trim().length===0)throw new Error("parseStl: defaultColor must be a non-empty string");return n}function Wh(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 cf(e){let n=globalThis.TextDecoder;return new n().decode(e)}function Fr(e,n){return[e.getFloat32(n,!0),e.getFloat32(n+4,!0),e.getFloat32(n+8,!0)]}function Br(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function rf(e){let n=e.trim().split(/\s+/);if(n.length!==3||!n.every(o=>Gh.test(o)))return null;let t=[Number(n[0]),Number(n[1]),Number(n[2])];return Br(t)?t:null}function jh(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 ia(e){return Math.max(0,Math.min(255,e)).toString(16).padStart(2,"0")}function lf(e,n,t,o=255){if(o>=255)return`#${ia(e)}${ia(n)}${ia(t)}`;let r=Math.round(o/255*1e3)/1e3;return`rgba(${e}, ${n}, ${t}, ${r})`}function aa(e){return Math.round(e/31*255)}function Hh(e){for(let n=0;n<80-Qn.length-4;n+=1){let t=!0;for(let a=0;a<Qn.length;a+=1)if(e.getUint8(n+a)!==Qn.charCodeAt(a)){t=!1;break}if(!t)continue;let o=e.getUint8(n+Qn.length),r=e.getUint8(n+Qn.length+1),s=e.getUint8(n+Qn.length+2),i=e.getUint8(n+Qn.length+3);return{defaultColor:lf(o,r,s,i),alpha:Math.round(i/255*1e3)/1e3,alphaByte:i}}return null}function Kh(e,n){if((e&32768)!==0)return{color:n.defaultColor,usesDefaultColor:!0};let t=aa(e&31),o=aa(e>>5&31),r=aa(e>>10&31);return{color:lf(t,o,r,n.alphaByte),usesDefaultColor:!1}}function Zh(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((s,i)=>s.index-i.index||(s.kind==="end"?-1:1))}function qh(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 Qh(e){let n=cf(e.subarray(0,Math.min(e.byteLength,512))).trimStart().toLowerCase();return!n.startsWith("solid")&&!n.startsWith("facet")?!1:!qh(e)}function Jh(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(Qh(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 ey(e,n,t){let o=new DataView(e.buffer,e.byteOffset,e.byteLength),{triangleCount:r,declaredTriangleCount:s,trailingBytes:i}=n;s!==r&&t.push(`parseStl: binary STL declared ${s} triangles but contains ${r} complete triangle record${r===1?"":"s"}`),i>0&&t.push(`parseStl: ignored ${i} trailing binary byte${i===1?"":"s"}`);let a=jh(e.subarray(0,80)),c=Hh(o),l=0,u=0,f=[];for(let d=0,m=84;d<r;d+=1,m+=50){let p=Fr(o,m),h=[Fr(o,m+12),Fr(o,m+24),Fr(o,m+36)];if(!h.every(Br))throw new Error(`parseStl: non-finite coordinate in binary triangle ${d}`);let g=o.getUint16(m+48,!0),y=c?Kh(g,c):null;y&&(y.usesDefaultColor?u+=1:l+=1),f.push({normal:Br(p)?p:null,hasIgnoredNormal:!Br(p),color:y?.color,vertices:h,hasIgnoredAttribute:!c&&g!==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 sf(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,s=/^\s*facet\s+normal\b/gim,i=Zh(e),a=0,c,l=0;for(;s.exec(e);)l+=1;let u=0,f=0,d=0,m;for(;m=o.exec(e);){for(u+=1;a<i.length&&i[a].index<m.index;){let x=i[a];c=x.kind==="start"?x.name:void 0,a+=1}let p=rf(m[1]);p||(d+=1);let h=[],g=!1;r.lastIndex=0;let y;for(;y=r.exec(m[2]);){let x=rf(y[1]);if(!x){g=!0;break}h.push(x)}if(g||h.length!==3){f+=1;continue}t.push({normal:p,hasIgnoredNormal:!p,solidName:c,vertices:[h[0],h[1],h[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 St(e,n){return[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Ur(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 ca(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function uf(e){return Math.hypot(e[0],e[1],e[2])}function ny(e){let n=Ur(St(e[1],e[0]),St(e[2],e[0]));return uf(n)<=1e-8}function kr(e){let n=uf(e);return n<=1e-8?null:[e[0]/n,e[1]/n,e[2]/n]}function ty(e){let n=t=>Object.is(t,-0)?0:t;return`${n(e[0])},${n(e[1])},${n(e[2])}`}function oy(e,n){return e<n?`${e}|${n}`:`${n}|${e}`}function la(e,n){return n?[e.vertices[0],e.vertices[2],e.vertices[1]]:e.vertices}function ry(e,n,t){let o=0;for(let r of n.facets){let[s,i,a]=la(e[r],t[r]);o+=ca(s,Ur(i,a))/6}return o}function sy(e,n,t){if(n.facets.length<8)return null;let o=0,r=0;for(let i of n.facets){let a=e[i],c=a.normal?kr(a.normal):null;if(!c)continue;let l=la(a,t[i]),u=kr(Ur(St(l[1],l[0]),St(l[2],l[0])));if(!u)continue;let f=ca(u,c);f>=.95?o+=1:f<=-.95&&(r+=1)}let s=o+r;return s/n.facets.length<.75?null:r/s>=.9?"opposed":o/s>=.9?"aligned":null}function iy(e){let n=new Map,t=e.map(()=>[]);for(let u=0;u<e.length;u+=1){let f=e[u].vertices.map(ty);for(let d=0;d<3;d+=1){let m=f[d],p=f[(d+1)%3],h=oy(m,p),g=n.get(h),y={facetIndex:u,from:m,to:p};g?g.push(y):n.set(h,[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),s=new Array(e.length).fill(-1),i=[],a=0;for(let u=0;u<e.length;u+=1){if(s[u]>=0)continue;let f=i.length,d={facets:[],conflicts:0,boundaryEdges:0,nonManifoldEdges:0,flippedOutward:!1,flippedToSuppliedNormals:!1};i.push(d),s[u]=f;let m=[u];for(let p=0;p<m.length;p+=1){let h=m[p];d.facets.push(h);for(let g of t[h]){let y=r[h]!==g.flipDiffers;s[g.to]<0?(s[g.to]=f,r[g.to]=y,m.push(g.to)):r[g.to]!==y&&h<g.to&&(d.conflicts+=1,a+=1)}}}for(let u of n.values()){let f=i[s[u[0].facetIndex]];u.length===1?f.boundaryEdges+=1:u.length>2&&(f.nonManifoldEdges+=1)}for(let u of i){if(u.nonManifoldEdges>0||u.conflicts>0){for(let d of u.facets)r[d]=!1;continue}if(u.boundaryEdges>0){if(sy(e,u,r)==="opposed"){for(let d of u.facets)r[d]=!r[d];u.flippedToSuppliedNormals=!0}continue}if(ry(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:la(u,!0)}):u),repairedCount:c,componentCount:i.length,outwardComponentCount:i.filter(u=>u.flippedOutward).length,suppliedNormalComponentCount:i.filter(u=>u.flippedToSuppliedNormals).length,conflictCount:a,nonManifoldEdgeCount:o}}function ay(e,n,t,o,r){let s=i=>Math.round(i*1e3)/1e3;return r==="y"?[s((e[2]-n[2])*t+o),s((e[0]-n[0])*t+o),s((e[1]-n[1])*t+o)]:[s((e[0]-n[0])*t+o),s((e[1]-n[1])*t+o),s((e[2]-n[2])*t+o)]}function cy(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 s=e[r]?.solidName??"";r<e.length&&s===t||(n.push({name:t,start:o,count:r-o}),t=s,o=r)}return n}function ly(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 zr(e,n){let t=$h("targetSize",n?.targetSize,60),o=af("gridShift",n?.gridShift,1),r=Yh(n?.defaultColor),s=Xh(n?.upAxis),i=[],a=Wh(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?Jh(a):null,u=typeof e=="string"?sf(e,i):l?ey(a,l,i):sf(cf(a),i),f=0,d=0,m=0,p=[];for(let S of u.facets){if(S.hasIgnoredAttribute&&(f+=1),S.hasIgnoredNormal&&u.format==="binary"&&(d+=1),ny(S.vertices)){m+=1;continue}p.push(S)}let h=iy(p),g=0;for(let S of h.facets){let M=kr(Ur(St(S.vertices[1],S.vertices[0]),St(S.vertices[2],S.vertices[0]))),T=S.normal?kr(S.normal):null;M&&T&&ca(M,T)<.95&&(g+=1)}if(f>0&&i.push(`parseStl: ignored non-zero binary attribute byte count on ${f} triangle${f===1?"":"s"}`),d>0&&i.push(`parseStl: ignored ${d} non-finite binary normal${d===1?"":"s"}`),m>0&&i.push(`parseStl: skipped ${m} degenerate triangle${m===1?"":"s"}`),h.repairedCount>0&&i.push(`parseStl: repaired winding on ${h.repairedCount} triangle${h.repairedCount===1?"":"s"}`),h.outwardComponentCount>0&&i.push(`parseStl: oriented ${h.outwardComponentCount} closed component${h.outwardComponentCount===1?"":"s"} outward`),h.suppliedNormalComponentCount>0&&i.push(`parseStl: oriented ${h.suppliedNormalComponentCount} open component${h.suppliedNormalComponentCount===1?"":"s"} from supplied normals`),h.conflictCount>0&&i.push(`parseStl: found ${h.conflictCount} inconsistent shared-edge winding constraint${h.conflictCount===1?"":"s"}`),h.nonManifoldEdgeCount>0&&i.push(`parseStl: found ${h.nonManifoldEdgeCount} non-manifold shared edge${h.nonManifoldEdgeCount===1?"":"s"}`),g>0&&i.push(`parseStl: ${g} supplied normal${g===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],x=[-1/0,-1/0,-1/0];for(let S of h.facets)for(let M of S.vertices)for(let T=0;T<3;T+=1)M[T]<y[T]&&(y[T]=M[T]),M[T]>x[T]&&(x[T]=M[T]);let b=Math.max(x[0]-y[0],x[1]-y[1],x[2]-y[2]),P=b>0?t/b:1,A=cy(h.facets),C=ly(A),E=h.facets.map(S=>({vertices:S.vertices.map(M=>ay(M,y,P,o,s)),color:S.color??r}));return{polygons:E,objectUrls:[],dispose:()=>{},warnings:i,metadata:{triangleCount:E.length,meshes:C,materials:[],sourceBytes:c,stlHeader:u.binaryHeader,stlColor:u.color,stlSolids:A,stlTopology:{componentCount:h.componentCount,repairedTriangleCount:h.repairedCount,outwardComponentCount:h.outwardComponentCount,suppliedNormalComponentCount:h.suppliedNormalComponentCount,inconsistentSharedEdgeCount:h.conflictCount,nonManifoldSharedEdgeCount:h.nonManifoldEdgeCount}}}}var wn="loadMesh";async function ff(e,n){let t=n?.solidTextureSamples;return t===!1?e:Lr(e,typeof t=="object"?t:void 0)}function uy(e){let n=e.split("?")[0].split("#")[0],t=n.lastIndexOf(".");return t<0?"":n.slice(t+1).toLowerCase()}async function mf(e,n){let t=uy(e);if(t==="mtl")throw new Error(`${wn}: .mtl is a material file, not a mesh \u2014 use parseMtl directly`);let o=globalThis.fetch;if(!o)throw new Error(`${wn}: no fetch() in this environment`);let r=n?.baseUrl??e;if(t==="obj"){let s=await o(e);if(!s.ok)throw new Error(`${wn}: ${e} \u2192 ${s.status}`);let i=await s.text(),a=n?.objOptions;if(n?.mtlUrl){let u=await o(n.mtlUrl);if(!u.ok)throw new Error(`${wn}: ${n.mtlUrl} \u2192 ${u.status}`);let f=await u.text(),{colors:d,textures:m}=Nr(f),p={},h=globalThis.URL,g=globalThis.document?.baseURI,y=n.mtlUrl;if(h&&g)try{y=new h(n.mtlUrl,g).toString()}catch{}for(let[x,b]of Object.entries(m)){if(h)try{p[x]=new h(b,y).toString();continue}catch{}let P=n.mtlUrl.lastIndexOf("/"),A=P>=0?n.mtlUrl.slice(0,P+1):"";p[x]=b.startsWith("/")||/^https?:\/\//.test(b)?b:A+b}a={...a??{},materialColors:{...d,...a?.materialColors??{}},materialTextures:{...p,...a?.materialTextures??{}}}}let c=wr(i,a),l=await ff(c,n);return Yn(l,{meshResolution:n?.meshResolution,source:c})}if(t==="glb"||t==="gltf"){let s=await o(e);if(!s.ok)throw new Error(`${wn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer(),a=Rr(i,{baseUrl:r,...n?.gltfOptions??{}}),c=await ff(a,n);return Yn(c,{meshResolution:n?.meshResolution,source:a})}if(t==="vox"){let s=await o(e);if(!s.ok)throw new Error(`${wn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return Yn(Dr(i,n?.voxOptions),{meshResolution:n?.meshResolution})}if(t==="stl"){let s=await o(e);if(!s.ok)throw new Error(`${wn}: ${e} \u2192 ${s.status}`);let i=await s.arrayBuffer();return Yn(zr(i,n?.stlOptions),{meshResolution:n?.meshResolution})}throw new Error(`${wn}: unsupported extension ".${t}" (supported: obj, glb, gltf, vox, stl)`)}function Ne(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=mr[n]??10**n,o=Math.round(e*t)/t;return Object.is(o,0)||Object.is(o,-0)?"0":String(o)}function df(e,n=Jt){let t=Ne(e,n);return t==="0"?"0":`${t}px`}function an(e,n=pn){if(e.length===0)return"";let t=Ne(e[0],n);for(let o=1;o<e.length;o++)t+=`,${Ne(e[o],n)}`;return t}function pf(e,n,t,o,r=pn){return Gr(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 Gr(e,n,t,o,r,s,i,a,c,l,u,f,d=pn){if(d===3){let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,g=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,x=Math.round(s*1e3)/1e3||0,b=Math.round(i*1e3)/1e3||0,P=Math.round(a*1e3)/1e3||0,A=Math.round(c*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,E=Math.round(u*1e3)/1e3||0,S=Math.round(f*1e3)/1e3||0;return`${m},${p},${h},0,${g},${y},${x},0,${b},${P},${A},0,${C},${E},${S},1`}return`${Ne(e,d)},${Ne(n,d)},${Ne(t,d)},0,${Ne(o,d)},${Ne(r,d)},${Ne(s,d)},0,${Ne(i,d)},${Ne(a,d)},${Ne(c,d)},0,${Ne(l,d)},${Ne(u,d)},${Ne(f,d)},1`}function $r(e,n,t,o,r,s,i,a,c,l,u,f,d=pn){if(d!==3)return`matrix3d(${Gr(e,n,t,o,r,s,i,a,c,l,u,f,d)})`;let m=Math.round(e*1e3)/1e3||0,p=Math.round(n*1e3)/1e3||0,h=Math.round(t*1e3)/1e3||0,g=Math.round(o*1e3)/1e3||0,y=Math.round(r*1e3)/1e3||0,x=Math.round(s*1e3)/1e3||0,b=Math.round(i*1e3)/1e3||0,P=Math.round(a*1e3)/1e3||0,A=Math.round(c*1e3)/1e3||0,C=Math.round(l*1e3)/1e3||0,E=Math.round(u*1e3)/1e3||0,S=Math.round(f*1e3)/1e3||0;return`matrix3d(${m},${p},${h},0,${g},${y},${x},0,${b},${P},${A},0,${C},${E},${S},1)`}function At(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(d=>Number(d));if(s.length!==16||s.some(d=>!Number.isFinite(d)))return e.matrix;let i=s[0],a=s[1],c=s[2],l=s[4],u=s[5],f=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*l,s[13]+=o*a+r*u,s[14]+=o*c+r*f,an(s)}function gf(e,n){return At(e,n.width/hn,n.height/hn,n.minX,n.minY)}function ua(e){let n=e.seamBleedInsets??{left:0,right:0,top:0,bottom:0},t=e.canvasW||1,o=e.canvasH||1;return At(e,(t+n.left+n.right)/gn,(o+n.top+n.bottom)/gn,-n.left,-n.top)}function Ct(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,an(o))}function vn(e,n=fr){let t=Ne(e,n);return Number(t)===0?"0":`${t}%`}function hf(e,n=pn){return`matrix3d(${e.split(",").map(t=>{let o=Number(t.trim());return Number.isFinite(o)?Ne(o,n):t.trim()}).join(",")})`}function yf(e,n=Jt){let t=Ne(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function xf(e){return`matrix3d(${ua(e)})`}function In(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function Nn(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let i=1;i+1<e.length;i++){let a=e[i],c=e[i+1],l=[a[0]-n[0],a[1]-n[1],a[2]-n[2]],u=[c[0]-n[0],c[1]-n[1],c[2]-n[2]];t-=l[1]*u[2]-l[2]*u[1],o-=l[2]*u[0]-l[0]*u[2],r-=l[0]*u[1]-l[1]*u[0]}let s=Math.hypot(t,o,r);return s<=de?null:(t/=s,o/=s,r/=s,[t,o,r])}function Tt(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],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=de)return!1;let a=Math.sign(i);if(n===0)n=a;else if(a!==n)return!1}return!0}function Xr(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 Yr(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],a=o[1]-t[1],c=r*a-s*i;if(Math.abs(c)<=de)return null;let l=t[0]-e[0],u=t[1]-e[1],f=(l*a-u*i)/c;return[e[0]+f*r,e[1]+f*s]}function bf(e,n,t,o,r,s,i,a){let c=t-e,l=o-n,u=i-r,f=a-s,d=c*f-l*u;if(Math.abs(d)<=de)return null;let m=r-e,p=s-n,h=(m*f-p*u)/d;return[e+h*c,n+h*l]}function Jn(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let a=s[i]-t,c=s[i+1]-o,l=Math.hypot(a,c);l<=Me||(s[i]+=a/l*n,s[i+1]+=c/l*n)}return s}function et(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(!Tt(t))return Jn(e,n);let o=Xr(t);if(Math.abs(o)<=de)return Jn(e,n);let r=o>0?1:-1,s=[];for(let c=0;c<t.length;c++){let l=t[c],u=t[(c+1)%t.length],f=u[0]-l[0],d=u[1]-l[1],m=Math.hypot(f,d);if(m<=de)return Jn(e,n);let p=r*(d/m)*n,h=r*(-f/m)*n;s.push({a:[l[0]+p,l[1]+h],b:[u[0]+p,u[1]+h]})}let i=[],a=Math.max(2,n*4);for(let c=0;c<t.length;c++){let l=s[(c+t.length-1)%t.length],u=s[c],f=Yr(l.a,l.b,u.a,u.b);if(!f)return Jn(e,n);let d=t[c],m=f[0]-d[0],p=f[1]-d[1],h=Math.hypot(m,p);h>a?i.push(d[0]+m/h*a,d[1]+p/h*a):i.push(f[0],f[1])}return i}function Et(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 et(e,o[0]);let s=[];for(let f=0;f<e.length;f+=2)s.push([e[f],e[f+1]]);if(!Tt(s))return e;let i=Xr(s);if(Math.abs(i)<=de)return e;let a=i>0?1:-1,c=[];for(let f=0;f<s.length;f++){let d=s[f],m=s[(f+1)%s.length],p=m[0]-d[0],h=m[1]-d[1],g=Math.hypot(p,h);if(g<=de)return e;let y=o[f],x=a*(h/g)*y,b=a*(-p/g)*y;c.push({a:[d[0]+x,d[1]+b],b:[m[0]+x,m[1]+b]})}let l=[],u=Math.max(2,r*4);for(let f=0;f<s.length;f++){let d=c[(f+s.length-1)%s.length],m=c[f],p=Yr(d.a,d.b,m.a,m.b);if(!p)return e;let h=s[f],g=p[0]-h[0],y=p[1]-h[1],x=Math.hypot(g,y);x>u?l.push(h[0]+g/x*u,h[1]+y/x*u):l.push(p[0],p[1])}return l}function uo(e,n,t,o,r,s,i){if(i<=0)return[e,n,t,o,r,s];let a=(e*o-n*t+t*s-o*r+r*n-s*e)/2,c=()=>Jn([e,n,t,o,r,s],i);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=s-o,h=Math.sqrt(m*m+p*p),g=e-r,y=n-s,x=Math.sqrt(g*g+y*y);if(d<=de||h<=de||x<=de)return c();let b=l*(f/d)*i,P=l*(-u/d)*i,A=e+b,C=n+P,E=t+b,S=o+P,M=l*(p/h)*i,T=l*(-m/h)*i,v=t+M,I=o+T,_=r+M,O=s+T,R=l*(y/x)*i,w=l*(-g/x)*i,F=r+R,D=s+w,K=e+R,H=n+w,Q=K-F,ne=H-D,ee=E-A,ue=S-C,U=Q*ue-ne*ee;if(Math.abs(U)<=de)return c();let $=A-F,k=C-D,L=($*ue-k*ee)/U,W=F+L*Q,Y=D+L*ne,se=E-A,Z=S-C,B=_-v,q=O-I,me=se*q-Z*B;if(Math.abs(me)<=de)return c();let fe=v-A,z=I-C,te=(fe*q-z*B)/me,ce=A+te*se,ye=C+te*Z,he=_-v,xe=O-I,ge=K-F,Ae=H-D,Fe=he*Ae-xe*ge;if(Math.abs(Fe)<=de)return c();let V=F-v,G=D-I,j=(V*Ae-G*ge)/Fe,J=v+j*he,le=I+j*xe,re=Math.max(2,i*4),pe=W-e,be=Y-n,ie=Math.sqrt(pe*pe+be*be);ie>re&&(W=e+pe/ie*re,Y=n+be/ie*re);let ae=ce-t,N=ye-o,X=Math.sqrt(ae*ae+N*N);X>re&&(ce=t+ae/X*re,ye=o+N/X*re);let oe=J-r,ve=le-s,Ce=Math.sqrt(oe*oe+ve*ve);return Ce>re&&(J=r+oe/Ce*re,le=s+ve/Ce*re),[W,Y,ce,ye,J,le]}function Wr(e,n,t,o){let r=e+n;if(o<=0||t<=de||r<=de||!Number.isFinite(e+n+t+o))return uo(e,0,0,t,r,t,o);let s=Math.sqrt(e*e+t*t),i=Math.sqrt(n*n+t*t);if(s<=de||i<=de)return uo(e,0,0,t,r,t,o);let a=-o*t/s,c=-o*e/s,l=o*t/i,u=-o*n/i,f=e+a,d=c,m=r+l,p=t+u,h=-t*r;if(Math.abs(h)<=de)return uo(e,0,0,t,r,t,o);let g=f-m,y=d-p,x=(g*t+y*e)/h,b=m-x*n,P=p-x*t,A=-o*(e+s)/t,C=t+o,E=r+o*(n+i)/t,S=C,M=Math.max(2,o*4),T=b-e,v=P,I=Math.sqrt(T*T+v*v);I>M&&(b=e+T/I*M,P=v/I*M);let _=Math.sqrt(A*A+o*o);_>M&&(A=A/_*M,C=t+o/_*M);let O=E-r,R=Math.sqrt(O*O+o*o);return R>M&&(E=r+O/R*M,S=t+o/R*M),[b,P,A,C,E,S]}function fo(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=In(n.vertices,t,o),s=Nn(r);if(!s)return null;let i=e.screenPts[0],a=e.screenPts[1],c=e.screenPts[2],l=e.screenPts[3],u=e.screenPts[4],f=e.screenPts[5],d=c-i,m=l-a,p=u-i,h=f-a,g=d*h-m*p;if(Math.abs(g)<=de)return null;let y=r[0],x=r[1],b=r[2],P=[x[0]-y[0],x[1]-y[1],x[2]-y[2]],A=[b[0]-y[0],b[1]-y[1],b[2]-y[2]],C=[(P[0]*h-m*A[0])/g,(P[1]*h-m*A[1])/g,(P[2]*h-m*A[2])/g],E=[(d*A[0]-P[0]*p)/g,(d*A[1]-P[1]*p)/g,(d*A[2]-P[2]*p)/g],S=y[0]-C[0]*i-E[0]*a,M=y[1]-C[1]*i-E[1]*a,T=y[2]-C[2]*i-E[2]*a;return{normal:s,xAxis:C,yAxis:E,tx:S,ty:M,tz:T}}function jr(e){return Math.max(0,Math.min(6,Math.floor(e??pn)))}function Pf(e){return`${e[0]},${e[1]},${e[2]}`}function Mf(e,n){let t=Pf(e),o=Pf(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Sf(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 s=0;s<r.length;s++){let i=Mf(r[s],r[(s+1)%r.length]),a=n.get(i),c={polygon:o,edge:s};a?a.push(c):n.set(i,[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 s=r+1;s<o.length;s++)t[o[r].polygon].add(o[r].edge),t[o[s].polygon].add(o[s].edge);return t.map(o=>o.size>0?o:void 0)}function mo(e,n){return typeof e=="number"&&Number.isFinite(e)?Math.max(0,e):n}function Hr(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function po(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 S=0;S<e.length;S+=2)r.push([e[S],e[S+1]]);let[s,i]=r[n],[a,c]=r[(n+1)%o],l=a-s,u=c-i,f=Math.hypot(l,u);if(f<=Me)return 0;let d=[],m=Number.POSITIVE_INFINITY;for(let S=0;S<o;S+=1){if(S===n||S===(n+1)%o)continue;let[M,T]=r[S],v=Math.abs((M-s)*u-(T-i)*l)/f;v>Me&&(m=Math.min(m,v))}Number.isFinite(m)&&d.push(m*.5);let p=r[(n+o-1)%o],h=r[(n+2)%o],g=p[0]-s,y=p[1]-i,x=h[0]-a,b=h[1]-c,P=Math.hypot(g,y),A=Math.hypot(x,b);if(P>Me){let S=Math.abs(l*y-u*g)/(f*P);S>Me&&d.push(P*S)}if(A>Me){let S=Math.abs(-l*b- -u*x)/(f*A);S>Me&&d.push(A*S)}let C=d.filter(S=>Number.isFinite(S)&&S>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 Kr(e,n,t){if(!n?.size||t===void 0)return;let o=new Map;for(let r of n){let s=po(e,r,t);s>0&&o.set(r,s)}return o.size>0?o:void 0}function Zr(e,n){return e<3||!n?.size?null:Array.from({length:e},(t,o)=>Math.max(0,n.get(o)??0))}function qr(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,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let l=0;l<e.length;l+=2){let u=e[l],f=e[l+1];o=Math.min(o,u),r=Math.min(r,f),s=Math.max(s,u),i=Math.max(i,f)}if(!Number.isFinite(o+r+s+i))return;let a=Math.max(Me*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],h=e[d+1],g=e[m],y=e[m+1];Math.abs(p-g)<=a?Math.abs(p-o)<=a&&Math.abs(g-o)<=a?c.left=Math.max(c.left,f):Math.abs(p-s)<=a&&Math.abs(g-s)<=a&&(c.right=Math.max(c.right,f)):Math.abs(h-y)<=a&&(Math.abs(h-r)<=a&&Math.abs(y-r)<=a?c.top=Math.max(c.top,f):Math.abs(h-i)<=a&&Math.abs(y-i)<=a&&(c.bottom=Math.max(c.bottom,f)))}return c.left||c.right||c.top||c.bottom?c:void 0}function fy(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function my(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=In(e.vertices,n,t),r=Nn(o);return r?{normal:r,planeD:fy(r,o[0])}:null}function dy(e,n){return(e.material?.key??e.color??"")===(n.material?.key??n.color??"")&&e.color===n.color}function Af(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=>my(c,t,o)),s=new Map;for(let c=0;c<e.length;c++){let l=e[c].vertices;if(!(!l||l.length<3))for(let u=0;u<l.length;u++){let f=Mf(l[u],l[(u+1)%l.length]),d=s.get(f),m={polygon:c,edge:u};d?d.push(m):s.set(f,[m])}}let i=new Map,a=(c,l)=>{let u=i.get(c);u?u.add(l):i.set(c,new Set([l]))};for(let c of s.values())if(!(c.length<2))for(let l=0;l<c.length;l++)for(let u=l+1;u<c.length;u++){let f=c[l],d=c[u],m=f.polygon,p=d.polygon;!r[m]||!r[p]||dy(e[m],e[p])&&(a(m,f.edge),a(p,d.edge))}return i}function py(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>no?!1:(e-t)*(e-r)+(n-o)*(n-s)<=no}function ma(e,n=eo,t=eo){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,a]=e[r],[c,l]=e[s];if(py(n,t,i,a,c,l))return!0;a>t!=l>t&&n<(c-i)*(t-a)/(l-a)+i&&(o=!o)}return o}function da(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let l=0;l<e.length;l+=2){let u=e[l],f=e[l+1];!Number.isFinite(u)||!Number.isFinite(f)||(o=Math.min(o,u),r=Math.min(r,f),s=Math.max(s,u),i=Math.max(i,f))}let a=s-o,c=i-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 vt(e){let n=e.bleedRatio??1,t=hr*n,o=e.canvasW||1,r=e.canvasH||1,s=t>0?et(e.screenPts,t):e.screenPts,i=t>0?da(s,o,r):{minX:0,minY:0,width:o,height:r},a=[];for(let c=0;c<s.length;c+=2){let l=Math.max(0,Math.min(100,(s[c]-i.minX)/i.width*100)),u=Math.max(0,Math.min(100,(s[c+1]-i.minY)/i.height*100));a.push([l,u])}return{bounds:i,points:a}}function pa(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])<=to||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])<=to&&n.pop()}return n}function ga([e,n]){let t=new Set;return Math.abs(e)<=We&&t.add("left"),Math.abs(e-100)<=We&&t.add("right"),Math.abs(n)<=We&&t.add("top"),Math.abs(n-100)<=We&&t.add("bottom"),t.size>0?t:null}function ha(e,n){for(let t of e)if(n.has(t))return!0;return!1}function ya(e,n,t,o){let r=(s,i,a)=>{let c=n.has(i)?e:o.has(i)?t:null,l=n.has(a)?e:o.has(a)?t:null;if(!c||!l)return null;let u=(()=>{switch(s){case"topLeft":return{x:c[0],y:l[1]};case"topRight":return{x:100-c[0],y:l[1]};case"bottomRight":return{x:100-c[0],y:100-l[1]};case"bottomLeft":return{x:c[0],y:100-l[1]}}})();return u.x>We&&u.y>We&&u.x<100-We&&u.y<100-We?[s,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 Qr(e){if(e.texture||nt(e)||Dn(e))return null;let n=vt(e),t=pa(n.points);if(t.length<4)return null;let o=t.map(ga);if(o.some(i=>!i))return null;let r={},s=0;for(let i=0;i<t.length;i+=1){let a=o[i],c=o[(i+1)%t.length];if(ha(a,c))continue;let l=ya(t[i],a,t[(i+1)%t.length],c);if(!l)return null;let[u,f]=l,d=r[u];if(d&&(Math.abs(d.x-f.x)>We||Math.abs(d.y-f.y)>We))return null;r[u]=f,s+=1}return s>0?{bounds:n.bounds,radii:r}:null}function gy([e,n]){return`${vn(e)} ${vn(n)}`}function hy(e){return`polygon(${e.map(gy).join(",")})`}function yy(e){if(ma(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,a]of e)n+=i,t+=a;let r=vn(Math.max(0,Math.min(100,n/o))),s=vn(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function Jr(e){return`${hy(e)} ${yy(e)}`}function Cf(e){return Jr(vt(e).points)}function xa(e,n){return At(e,n.width/hn,n.height/hn,n.minX,n.minY)}function Tf(e){let n=vt(e);return`matrix3d(${xa(e,n.bounds)})`}function Ef(e){let n=vt(e);return[`transform:matrix3d(${xa(e,n.bounds)})`,`border-shape:${Jr(n.points)}`].join(";")}function vf(e,n){let t=[`transform:matrix3d(${xa(e,n.bounds)})`,`width:${hn}px`,`height:${hn}px`,"border:0","box-sizing:border-box","background:currentColor"];for(let[o,r]of Object.entries(n.radii)){let s=o.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`);t.push(`border-${s}-radius:${vn(r.x)} ${vn(r.y)}`),t.push(`corner-${s}-shape:bevel`)}return t.join(";")}function go(e){return e.textureImageSource??e.material?.imageSource}function es(e){return e.material?.texture??e.texture??e.textureImageSource?.url??e.material?.imageSource?.url}function ho(e,n={}){let t=go(e);return{...n,...e.material?.presentation,...t?.imageRendering?{imageRendering:t.imageRendering}:null,...e.texturePresentation}}function If(e,n){return ho(e,{imageRendering:n}).imageRendering??"auto"}function _f(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function yo(e){let n=e?.maxWeightRatio,t=Math.max(0,_f(e?.denomEps,yr)),o=typeof n=="number"&&Number.isFinite(n)&&n>0?Math.max(1,n):xr,r=Math.max(0,_f(e?.bleed,br));return{denomEps:t,maxWeightRatio:o,bleed:r,disableGuards:e?.disableGuards===!0}}function ns(e,n){if(e.length!==4||!Tt(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],a=t[1]-o[1]+r[1]-s[1],c=o[0]-r[0],l=s[0]-r[0],u=o[1]-r[1],f=s[1]-r[1],d=c*f-u*l;if(Math.abs(d)<=de)return null;let m=(i*f-a*l)/d,p=(c*a-u*i)/d,h=[1,1+m,1+m+p,1+p];if(h.some(x=>!Number.isFinite(x)))return null;let g=Math.min(...h),y=Math.max(...h);return!n.disableGuards&&(g<=n.denomEps||y/g>n.maxWeightRatio)?null:{g:m,h:p,w1:1+m,w3:1+p}}function xo(e,n,t,o,r,s,i,a,c){if(e.length!==8)return null;let l=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!ns(l,a))return null;let u=Zr(4,c),f=u?Et(e,u):et(e,a.bleed),d=[[f[0],f[1]],[f[2],f[3]],[f[4],f[5]],[f[6],f[7]]],m=ns(d,a);if(!m)return null;let{g:p,h,w1:g,w3:y}=m,[x,b,,P]=d,A=[r+x[0]*n[0]+x[1]*t[0],s+x[0]*n[1]+x[1]*t[1],i+x[0]*n[2]+x[1]*t[2]],C=([S,M],T)=>[(T-1)*r+(T*S-x[0])*n[0]+(T*M-x[1])*t[0],(T-1)*s+(T*S-x[0])*n[1]+(T*M-x[1])*t[1],(T-1)*i+(T*S-x[0])*n[2]+(T*M-x[1])*t[2]],E=[...C(b,g),p,...C(P,y),h,o[0],o[1],o[2],0,A[0],A[1],A[2],1];for(let S=0;S<8;S+=1)E[S]/=gn;return an(E,6)}function bo(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Of(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 ba(e){return!e.texture}function Pa(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=In(e.vertices,n,t),r=Nn(o);return r?{pts:o,normal:r,planeD:bo(r,o[0]),optimizable:ba(e)}:null}function Ma(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:ss(e,n)}function ss(e,n){return!e||!n||bo(e.normal,n.normal)<1-cr?!1:Math.abs(e.planeD-n.planeD)<=lr}function ts(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??Wn,s=t?.color??jn,i=Math.max(0,t?.intensity??Hn),a=o?.color??Kn,c=Math.max(0,o?.intensity??Zn),l=Math.hypot(r[0],r[1],r[2])||1,u=r[0]/l,f=r[1]/l,d=r[2]/l,m=i*Math.max(0,e.normal[0]*u+e.normal[1]*f+e.normal[2]*d),p=io(m,s,a,c);return p.r*.2126+p.g*.7152+p.b*.0722}function Sa(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 tt(e,n,t,o,r={}){let s=bo(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],a=Math.hypot(i[0],i[1],i[2]);if(a<=de)return null;let c=[i[0]/a,i[1]/a,i[2]/a],l=[t[1]*c[2]-t[2]*c[1],t[2]*c[0]-t[0]*c[2],t[0]*c[1]-t[1]*c[0]],u=Math.hypot(l[0],l[1],l[2]);if(u<=de)return null;let f=[l[0]/u,l[1]/u,l[2]/u],d=e.map(R=>{let w=R[0]-n[0],F=R[1]-n[1],D=R[2]-n[2];return[w*c[0]+F*c[1]+D*c[2],w*f[0]+F*f[1]+D*f[2]]}),m=r.boundsOrigin??n,p=n[0]-m[0],h=n[1]-m[1],g=n[2]-m[2],y=p*c[0]+h*c[1]+g*c[2],x=p*f[0]+h*f[1]+g*f[2],b=1/0,P=1/0,A=-1/0,C=-1/0;for(let[R,w]of d){let F=R+y,D=w+x;F<b&&(b=F),F>A&&(A=F),D<P&&(P=D),D>C&&(C=D)}let E=A-b,S=C-P;if(!Number.isFinite(E)||!Number.isFinite(S))return null;let M=r.snapBounds?Math.floor(b+Me):b,T=r.snapBounds?Math.floor(P+Me):P,v=r.snapBounds?Math.ceil(A-Me):A,I=r.snapBounds?Math.ceil(C-Me):C,_=Math.max(1,r.snapBounds?v-M:Math.ceil(E)),O=Math.max(1,r.snapBounds?I-T:Math.ceil(S));return{xAxis:c,yAxis:f,local2D:d,shiftX:y-M,shiftY:x-T,canvasW:_,canvasH:O,pixelArea:_*O,rawArea:E*S}}function os(e){return`${e[0]},${e[1]},${e[2]}`}function Rf(e,n){return os(e)<os(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 xy(e,n){let t=os(e),o=os(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Aa(e,n,t,o){let r=0,s=0;for(let i of e){let a=n[i];if(!a)return null;let c=tt(a.pts,a.pts[0],a.normal,t,{boundsOrigin:o,snapBounds:!0});if(!c)return null;r+=c.pixelArea,s+=c.rawArea}return{pixelArea:r,rawArea:s}}function Ca(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let a=n[i];if(!a)continue;let c=[a.pts[1][0]-a.pts[0][0],a.pts[1][1]-a.pts[0][1],a.pts[1][2]-a.pts[0][2]],l=tt(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=Rf(a.pts[u],a.pts[(u+1)%a.pts.length]),d=tt(a.pts,a.pts[0],a.normal,f);if(!d)continue;let m=Sa(d.xAxis);if(s.has(m))continue;s.add(m);let p=Aa(e,n,d.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-Me)&&(r={xAxis:d.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+Me)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function Vf(e,n){let t=n.tileSize??50,o=n.layerElevation??t,r=e.map(f=>Pa(f,t,o)),s=new Map,i=e.map(()=>new Set),a=e.map(()=>new Set);for(let f=0;f<e.length;f++){let d=e[f].vertices;if(!(!d||d.length<3))for(let m=0;m<d.length;m++){let p=xy(d[m],d[(m+1)%d.length]),h=s.get(p),g={polygon:f,edge:m};h?h.push(g):s.set(p,[g])}}let c=e.map(()=>new Set);for(let f of s.values())if(!(f.length<2))for(let d=0;d<f.length;d++)for(let m=d+1;m<f.length;m++){let p=f[d],h=f[m],g=p.polygon,y=h.polygon;if(e[g].texture&&e[y].texture&&(a[p.polygon].add(p.edge),a[h.polygon].add(h.edge)),ss(r[g],r[y]))i[p.polygon].add(p.edge),i[h.polygon].add(h.edge);else{let x=ts(r[g],n),b=ts(r[y],n);x!==null&&b!==null&&(x<=b+Qt&&i[p.polygon].add(p.edge),b<=x+Qt&&i[h.polygon].add(h.edge))}Ma(r[g],r[y])&&(c[g].add(y),c[y].add(g))}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 h=m.pop();d.push(h);for(let g of c[h])u.has(g)||(u.add(g),m.push(g))}if(d.length<2)continue;let p=Ca(d,r);if(p)for(let h of d)l[h]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:a[h]}}for(let f=0;f<e.length;f++)!l[f]&&(i[f].size>0||a[f].size>0)&&(l[f]={seamEdges:i[f],textureEdgeRepairEdges:a[f]});return l}function rs(e,n,t,o){if(o.optimize&&o.fixedXAxis)return tt(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((a,c)=>c):[0]);for(let a of i){let c=(a+1)%e.length,l=s?Rf(e[a],e[c]):[e[c][0]-e[a][0],e[c][1]-e[a][1],e[c][2]-e[a][2]],u=tt(e,n,t,l,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-Me)&&(r=u)}return r}function Ta(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=Me)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>Me||Math.abs(t[0])>Me||n[1]-n[0]<=Me||t[1]-t[0]<=Me))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,a=s+e.shiftY,c=Math.abs(i-n[0])<=Me||Math.abs(i-n[1])<=Me,l=Math.abs(a-t[0])<=Me||Math.abs(a-t[1])<=Me;if(!c||!l)return!1}return!0}function is(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,a]=n,c=t[0],l=t[1],u=o[0],f=o[1],d=r[0],m=r[1],p=s[0],h=1-s[1],g=i[0],y=1-i[1],x=a[0],b=1-a[1],P=g-p,A=y-h,C=x-p,E=b-h,S=P*E-C*A;if(Math.abs(S)<=1e-9)return null;let M=u-c,T=d-c,v=f-l,I=m-l,_={a:(M*E-T*A)/S,b:(P*T-C*M)/S,c:(v*E-I*A)/S,d:(P*I-C*v)/S,e:0,f:0};return _.e=c-_.a*p-_.b*h,_.f=l-_.c*p-_.d*h,_}function as(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],a=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(a))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,a),r=Math.max(r,a)}return{minU:n,minV:t,maxU:o,maxV:r}}function Ea(e,n,t,o,r,s,i,a){let l=In(e.vertices,n,t).map(d=>{let m=d[0]-o[0],p=d[1]-o[1],h=d[2]-o[2];return[m*r[0]+p*r[1]+h*r[2]+i,m*s[0]+p*s[1]+h*s[2]+a]}),u=is(l,e.uvs),f=as(e.uvs);return!u&&!f?null:{screenPts:l.flatMap(([d,m])=>[d,m]),uvAffine:u,uvSampleRect:f}}function va(e,n,t,o,r){let s=t,{vertices:i,uvs:a}=e,c=es(e);if(!i||i.length<3)return null;let l=t.tileSize??50,u=t.layerElevation??l,f=In(i,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 g=Nn(f);if(!g)return null;let y=rs(f,d,g,{optimize:!1}),x=c||y&&Ta(y)?y:rs(f,d,g,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!x)return null;let{xAxis:b,yAxis:P,local2D:A}=x,C=c&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,E=!!(c&&C),S=x.shiftX,M=x.shiftY,T=x.canvasW,v=x.canvasH,I=[];for(let[ge,Ae]of A)I.push(ge+S,Ae+M);let _=d[0]-S*b[0]-M*P[0],O=d[1]-S*b[1]-M*P[1],R=d[2]-S*b[2]-M*P[2],w=an([b[0],b[1],b[2],0,P[0],P[1],P[2],0,g[0],g[1],g[2],0,_,O,R,1]),F=an([b[0]*T,b[1]*T,b[2]*T,0,P[0]*v,P[1]*v,P[2]*v,0,g[0],g[1],g[2],0,_,O,R,1]),D=an([b[0]*T/Ye,b[1]*T/Ye,b[2]*T/Ye,0,P[0]*v/Ye,P[1]*v/Ye,P[2]*v/Ye,0,g[0],g[1],g[2],0,_,O,R,1]),K=Hr(s.seamBleed),H=Kr(I,s.seamEdges??r?.seamEdges,K),Q=H?new Set(H.keys()):void 0,ne=H?Math.max(...H.values()):void 0,ee=qr(I,H),ue=!c&&i.length===4?xo(I,b,P,g,_,O,R,o,H):null,U=t.directionalLight,$=t.ambientLight,k=U?.direction??Wn,L=U?.color??jn,W=Math.max(0,U?.intensity??Hn),Y=$?.color??Kn,se=Math.max(0,$?.intensity??Zn),Z=Math.hypot(k[0],k[1],k[2])||1,B=k[0]/Z,q=k[1]/Z,me=k[2]/Z,z=t.lightOccludedPolyIndices?.has(n)??!1?0:W*Math.max(0,g[0]*B+g[1]*q+g[2]*me),te=io(z,L,Y,se),ce=Vn(e.color??"#cccccc",z,L,Y,se),ye=null,he=null;c&&a&&a.length>=3&&a.length===i.length&&(he=as(a),ye=is(A.map(([ge,Ae])=>[ge+S,Ae+M]),a));let xe=c&&e.textureTriangles?.length?e.textureTriangles.map(ge=>Ea(ge,l,u,d,b,P,S,M)).filter(ge=>!!ge):null;return{index:n,polygon:e,texture:c,tileSize:l,layerElevation:u,matrix:w,canonicalMatrix:F,atlasMatrix:D,projectiveMatrix:ue,canvasW:T,canvasH:v,screenPts:I,uvAffine:ye,uvSampleRect:he,textureTriangles:xe,textureEdgeRepairEdges:C,textureEdgeRepair:E,seamBleed:ne,seamBleedEdges:Q,seamBleedEdgeAmounts:H,seamBleedInsets:ee,bleedRatio:Pr(s.seamBleed),normal:g,textureTint:te,shadedColor:ce}}function Lf(e,n,t={},o,r){let s=yo(o),i=t,a=r??(t.textureEdgeRepairEdges?.size?{seamEdges:new Set,textureEdgeRepairEdges:t.textureEdgeRepairEdges}:void 0);return va(e,n,i,s,a)}function cs(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function by(e){return!!e&&typeof e.url=="string"&&e.url.length>0&&cs(e.width)&&cs(e.height)}function Py(e){let n=e.sourceRect;return n?!Number.isFinite(n.x)||!Number.isFinite(n.y)||!cs(n.width)||!cs(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 My(e,n,t){let o=e.split(",").map(Number);if(o.length!==16||o.some(i=>!Number.isFinite(i)))return null;let r=gn/n,s=gn/t;for(let i=0;i<4;i+=1)o[i]*=r;for(let i=4;i<8;i+=1)o[i]*=s;return an(o,6)}function ls(e,n={}){let t=go(e.polygon);if(!by(t))return null;let o=ho(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 s=Py(t);if(!s)return null;let i=Math.max(1,s.width),a=Math.max(1,s.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??yo(void 0),d=fo(e,e.polygon);if(!d)return null;let m=xo(e.screenPts,d.xAxis,d.yAxis,d.normal,d.tx,d.ty,d.tz,f,e.seamBleedEdgeAmounts);if(u=m?My(m,i,a):null,!u)return null}else l="affine",u=Ct(e,i,a);return{source:t,url:t.url,sourceRect:s,leafWidth:i,leafHeight:a,matrix:u,backgroundPosition:[-s.x,-s.y],backgroundSize:[t.width,t.height],imageRendering:o.imageRendering??"auto",lighting:r,projection:l}}function Ia(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=.001,r=(s,i)=>{for(let a of s)if(Math.abs(a-i)<=o)return;s.push(i)};for(let s=0;s<e.screenPts.length;s+=2)r(n,e.screenPts[s]),r(t,e.screenPts[s+1]);if(n.length!==2||t.length!==2||(n.sort((s,i)=>s-i),t.sort((s,i)=>s-i),Math.abs(n[0])>o||Math.abs(t[0])>o||n[1]-n[0]<=o||t[1]-t[0]<=o))return null;for(let s=0;s<e.screenPts.length;s+=2){let i=e.screenPts[s],a=e.screenPts[s+1],c=Math.abs(i-n[0])<=o||Math.abs(i-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 Dn(e){return!!Ia(e)}function nt(e){return!e.texture&&e.polygon.vertices.length===3}function It(e){return!e.texture&&!!e.projectiveMatrix&&!Dn(e)}function wf(e){let n=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(e);return/\bVersion\/[\d.]+.*\bSafari\//.test(e)&&!n}function us(e,n){e.set(n,(e.get(n)??0)+1)}function fs(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function Nf(e,n,t,o){let r=!t.has("b"),s=r&&o.projectiveQuadSupported,i=!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&&ls(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(i&&nt(u))return null;let f=Dn(u);return a&&!f&&!(s&&It(u))&&Qr(u)!==null||r&&f||s&&It(u)||c&&(!f||l)?null:u})}function Df(e,n,t,o,r,s,i){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 x=m&&!!i?.(y);if(n==="dynamic"){if(!(d&&nt(y))&&!(u&&Dn(y))&&!(f&&It(y))&&!x&&!p)continue;let b=r(y.polygon.color??"#cccccc"),P=s(b);us(c,P),l.has(P)||l.set(P,b);continue}!(d&&nt(y))&&!(u&&Dn(y))&&!(f&&It(y))&&!x&&!p||us(a,y.shadedColor)}let h=fs(a),g=fs(c);return{paintColor:h,dynamicColorKey:g,dynamicColor:g?l.get(g):void 0}}function Sy(e,n){if((e+1)%3===n)return e;if((n+1)%3===e)return n}function Ay(e,n,t,o,r,s,i){if(!e?.size)return null;let a=mo(n,t);return[[s,o],[o,r],[r,s]].map(([l,u],f)=>{let d=Sy(l,u),m=d!==void 0&&e.has(d)?a:0;return po(i,f,m)})}function ms(e,n,t,o,r,s,i,a){let c=s,l="",u,f,d="";if(i){let m=a??e.color??"#cccccc",p=s.directionalLight,h=s.ambientLight,g=p?.direction??Wn,y=p?.color??jn,x=Math.max(0,p?.intensity??Hn),b=h?.color??Kn,P=Math.max(0,h?.intensity??Zn),A=Math.hypot(g[0],g[1],g[2])||1,C=g[0]/A,E=g[1]/A,S=g[2]/A,T=s.lightOccludedPolyIndices?.has(n)??!1?0:x*Math.max(0,t*C+o*E+r*S),v=Vn(m,T,y,b,P),I=s.textureLighting??"baked",_=I==="baked"&&c.stableTriangleColorSteps?Sr(v,c.stableTriangleColorSteps):v,O=yn(m),R=_===s.solidPaintDefaults?.paintColor,w=I==="dynamic"&&Mr(O)===s.solidPaintDefaults?.dynamicColorKey;l=I==="dynamic"||R?"":_,u=l?yn(l):void 0,f=l?ro(l):void 0,d=I==="dynamic"?`--pnx:${t.toFixed(4)};--pny:${o.toFixed(4)};--pnz:${r.toFixed(4)};`+(w?"":`--psr:${(O.r/255).toFixed(4)};--psg:${(O.g/255).toFixed(4)};--psb:${(O.b/255).toFixed(4)};`):""}return{index:n,polygon:e,colorComputed:i,bakedColor:l||void 0,bakedRgb:u,bakedAlpha:f,dynamicVars:d}}function Ff(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??50,r=t.layerElevation??o,s=e.vertices[0],i=e.vertices[1],a=e.vertices[2],c=[s[1]*o,s[0]*o,s[2]*r],l=[i[1]*o,i[0]*o,i[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],h=u[1]-c[1],g=u[2]-c[2],y=-(d*g-m*h),x=-(m*p-f*g),b=-(f*h-d*p),P=Math.sqrt(y*y+x*x+b*b);return P<=de?null:(y/=P,x/=P,b/=P,ms(e,n,y,x,b,t,!0))}function Bf(e,n,t,o={}){if(e.texture||e.vertices.length!==3)return null;let r=t.tileSize??50,s=t.layerElevation??r,i=e.vertices[0],a=e.vertices[1],c=e.vertices[2],l=i[1]*r,u=i[0]*r,f=i[2]*s,d=a[1]*r,m=a[0]*r,p=a[2]*s,h=c[1]*r,g=c[0]*r,y=c[2]*s;return ds(e,n,t,o,l,u,f,d,m,p,h,g,y)}function ds(e,n,t,o,r,s,i,a,c,l,u,f,d){let m=t,p=a-r,h=c-s,g=l-i,y=u-r,x=f-s,b=d-i,P=-(h*b-g*x),A=-(g*y-p*b),C=-(p*x-h*y),E=Math.sqrt(P*P+A*A+C*C);if(E<=de)return null;P/=E,A/=E,C/=E;let S=o.basis,M=S?.a??0,T=S?.b??1,v=S?.c??2;M<0||M>2||T<0||T>2||v<0||v>2||M===T||M===v||T===v?(S=void 0,M=0,T=1,v=2):M===0&&T===1&&v===2||M===1&&T===2&&v===0||M===2&&T===0&&v===1||(S=void 0,M=0,T=1,v=2);let I=()=>S?ds(e,n,t,{...o,basis:void 0},r,s,i,a,c,l,u,f,d):null;if(!S){let Ie=p*p+h*h+g*g,en=u-a,cn=f-c,nn=d-l,Ke=r-u,ln=s-f,it=i-d,un=en*en+cn*cn+nn*nn,Ze=Ke*Ke+ln*ln+it*it,at=Ie;un>at&&(M=1,T=2,v=0,at=un),Ze>at&&(M=2,T=0,v=1)}let _,O,R,w,F,D,K=v===0?r:v===1?a:u,H=v===0?s:v===1?c:f,Q=v===0?i:v===1?l:d;M===0?(_=r,O=s,R=i):M===1?(_=a,O=c,R=l):(_=u,O=f,R=d),T===0?(w=r,F=s,D=i):T===1?(w=a,F=c,D=l):(w=u,F=f,D=d);let ne=w-_,ee=F-O,ue=D-R,U=Math.sqrt(ne*ne+ee*ee+ue*ue);if(U<=de)return I();let $=ne/U,k=ee/U,L=ue/U,W=(K-_)*$+(H-O)*k+(Q-R)*L,Y=A*L-C*k,se=C*$-P*L,Z=P*k-A*$,B=E/U;if(B<=de)return I();let q=Math.max(0,Math.min(U,W)),me=Math.max(0,U-q),fe=[q,0,0,B,q+me,B],z=ur*(m.bleedRatio??1),te=Ay(m.seamEdges,m.seamBleed,z,M,T,v,fe),ce=te?Et(fe,te):Wr(q,me,B,mo(m.seamBleed,z)),ye=ce[0],he=ce[1],xe=ce[2],ge=ce[3],Ae=ce[4],Fe=ce[5],V=(ge+Fe)/2,G=ye-xe,j=Ae-ye,J=V-he;if(G<=de||j<=de||J<=de||!Number.isFinite(G+j+J))return I();let le=o.includeColor??!0,re=!1,pe,be,ie,ae="";if(le){let Ie=ms(e,n,P,A,C,t,!0,o.color);re=Ie.colorComputed,pe=Ie.bakedColor,be=Ie.bakedRgb,ie=Ie.bakedAlpha,ae=Ie.dynamicVars??""}let N=pe?`color:${pe};`:"",X=o.primitive??o.resolvedPrimitive??"border",ve=1/(X==="border-large"?pr:dr),Ce=G+j,Pe=Ce*ve,Oe=(j-G)*.5*ve,Re=J*ve,Ve=ye-q-Ce*.5,Xe=he,Te=$*Pe,Be=k*Pe,De=L*Pe,rt=$*Oe+Y*Re,st=k*Oe+se*Re,xn=L*Oe+Z*Re,Je=K+$*Ve+Y*Xe,bn=H+k*Ve+se*Xe,ke=Q+L*Ve+Z*Xe,je=o.matrixDecimals??jr(m.stableTriangleMatrixDecimals),Se=$r(Te,Be,De,rt,st,xn,P,A,C,Je,bn,ke,je),Le=t.textureLighting??"baked",_e=m.optimizeStableTriangleStyle===!0&&Le==="baked"?"":`transform:${Se};`+N+ae,He=S&&S.a===M&&S.b===T&&S.c===v?S:{a:M,b:T,c:v};return{index:n,polygon:e,styleText:_e,transformText:Se,basis:He,primitive:X,colorComputed:re,bakedColor:pe,bakedRgb:be,bakedAlpha:ie,dynamicVars:ae}}function ot(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(tr,Math.max(nr,n))}function ps(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function _a(e,n){let t=ps(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=yt/o,s=Math.sqrt(n/(t*4));return ot(Math.min(r,s))}function Oa(e,n){let t=ps(e),o=.5;return t<=qt?o=1:t<=or&&(o=.75),ot(Math.min(o,_a(e,n)))}function Ra(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function Va(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function La(e,n,t){let o=Ra(e,n),r=Va(e,n),s=o>yt?yt/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function wa(e){return e?rr:sr}function Na(e,n){return e!==void 0&&e!=="auto"?Ye:n?Ye:gr}function kf(e,n){return Po(e,n,1,"canonical")}function Da(e,n,t,o=Fa(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 s=ot(n);return{width:Math.max(1,(e.canvasW||1)*s),height:Math.max(1,(e.canvasH||1)*s),sizing:r}}return{width:o,height:o,sizing:"canonical"}}function Po(e,n,t,o="canonical"){for(let r of e.entries){if(!r)continue;let s=Da(r,t,o,n);r.atlasCanonicalSize=n,r.atlasLeafSizing=s.sizing,r.atlasLeafWidth=s.width,r.atlasLeafHeight=s.height,r.atlasMatrix=Ct(r,s.width,s.height)}return e}function Fa(e){return e.atlasCanonicalSize??Ye}function Ba(e){return Math.max(Zt,Math.ceil(Zt/e))}function _t(e,n=1){let t=Array(e.length).fill(null),o=[],r=Ba(n),s=e.filter(c=>!!c).sort((c,l)=>l.canvasH-c.canvasH||l.canvasW-c.canvasW||c.index-l.index),i=()=>({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<=En){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>En)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 s){if(c.canvasW+r*2>En||c.canvasH+r*2>En){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=i(),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 Cy(e,n,t){let o=Oa(n.pages,t),r=o===1?n:_t(e,o);for(let s=0;s<4;s++){let i=La(r.pages,o,t);if(i>=1)break;let a=ot(o*i*ir);if(a>=o)break;o=a,r=_t(e,o)}return{packed:r,atlasScale:o}}function Uf(e,n,t,o="canonical"){let r=Na(n,t);if(n!==void 0&&n!=="auto"){let a=ot(n);return{packed:Po(_t(e,a),r,a,o),atlasScale:a,atlasCanonicalSize:r}}let s=_t(e,1),i=Cy(e,s,wa(t));return{packed:Po(i.packed,r,i.atlasScale,o),atlasScale:i.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,buildPolyCameraSceneTransform,buildPolyMeshTransform,buildPolySceneTransform,buildSceneContext,buildSeamBleedPolygonEdges,buildSeamBleedPolygonSet,buildSharedEdgeMap,buildTextureEdgeRepairSets,cachedParsePureColor,cameraCullNormalGroups,cameraCullNormalGroupsFromPolygons,cameraCullNormalKey,cameraCullVisibleSignature,cameraFacingDepth,capturePolyCameraSnapshot,chooseIslandXAxis,chooseLocalBasis,clampChannel,classifyFacing,clipPolygonToConvex2D,colorErrorScore,compatibleBleedSurface,compatibleSurface,computeLightVisibility,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,isConvexPolygonPoints,isFullRectBasis,isFullRectSolid,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,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});
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
+ `)){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
+ `)){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});