s3m-three 0.4.20 → 0.4.21

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.
@@ -4762,7 +4762,7 @@ void main() {
4762
4762
  float o = uObjectId + 1.0;
4763
4763
  gl_FragColor = vec4(mod(o, 256.0) / 255.0, floor(o / 256.0) / 255.0, 0.0, 0.0);
4764
4764
  }
4765
- `,side:2,depthTest:!0,depthWrite:!0})}function Fx(e){let t=e.getAttribute(`iCenter`);if(!t)return null;let n=t.array,r=t.count;if(!r)return null;let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let e=0;e<r;e++){let t=n[e*3],r=n[e*3+1],u=n[e*3+2];t<i&&(i=t),t>s&&(s=t),r<a&&(a=r),r>c&&(c=r),u<o&&(o=u),u>l&&(l=u)}return{minX:i,minY:a,minZ:o,maxX:s,maxY:c,maxZ:l,count:r}}var Ix,Lx,Rx,zx,Bx=a((()=>{sh(),z_(),Ix=new B(1e3,1e3),Lx=new Io,Rx=new U,zx=new Wo})),Vx=o({LINE_PRIMITIVE:()=>13,POINT_PRIMITIVE:()=>1,buildTileObjects:()=>tS,setSplatViewport:()=>Gx});function Hx(e){return e===13||e===2||e===3}function Ux(e){return e===1}function Wx(){return nS??(nS=jx()),nS}function Gx(e,t){nS&&nS.uniforms.uViewport.value.set(e,t)}function Kx(e,t){let n=t.vertexAttributes.find(e=>e.semantic===`gsScale`),r=t.vertexAttributes.find(e=>e.semantic===`gsRotation`),i=e.attributes.position;if(!n||!r||!i)return null;let a=Math.min(t.verticesCount,Math.floor(i.array.length/i.components));if(a<=0)return null;let o=wx(n.data,n.stride,n.offsetInBytes,a),s=Tx(r.data,r.stride,r.offsetInBytes,a),c=qx(o,a),l=Mx();l.instanceCount=a,l.setAttribute(`iCenter`,new ju(i.array,3)),l.setAttribute(`iScale`,new ju(o,3)),l.setAttribute(`iQuat`,new ju(s,4));let u=new Float32Array(a*4);u.fill(1);let d=t.vertexAttributes.find(e=>e.semantic===`color`);if(d&&d.dtype===`u8`){let e=d.components??4,t=Math.min(a,Math.floor(d.data.length/d.stride));for(let n=0;n<t;n++){let t=n*d.stride+d.offsetInBytes;u[n*4]=d.data[t]/255,u[n*4+1]=d.data[t+1]/255,u[n*4+2]=d.data[t+2]/255,e>=4&&(u[n*4+3]=d.data[t+3]/255)}}else if(e.attributes.aColor){let t=e.attributes.aColor,n=t.components??4;for(let e=0;e<a;e++)for(let r=0;r<Math.min(n,4);r++)u[e*4+r]=t.array[e*n+r]}l.setAttribute(`iColor`,new ju(u,4));let f=i.array,p=1/0,m=1/0,h=1/0,g=-1/0,_=-1/0,v=-1/0,y=0;for(let e=0;e<a;e++){let t=f[e*3],n=f[e*3+1],r=f[e*3+2];t<p&&(p=t),t>g&&(g=t),n<m&&(m=n),n>_&&(_=n),r<h&&(h=r),r>v&&(v=r);let i=o[e*3],a=o[e*3+1],s=o[e*3+2];i>y&&(y=i),a>y&&(y=a),s>y&&(y=s)}let b=new yo;a>0&&(b.min.set(p,m,h),b.max.set(g,_,v));let x=new Io(new H,0);return b.isEmpty()||b.getBoundingSphere(x),x.radius+=3*y,l.boundingSphere=x,{geo:l,sigma:c}}function qx(e,t){let n=Math.max(1,Math.floor(t/512)),r=[];for(let i=0;i<t;i+=n){let t=Math.max(e[i*3],e[i*3+1],e[i*3+2]);Number.isFinite(t)&&t>0&&r.push(t)}return r.length?(r.sort((e,t)=>e-t),r[r.length>>1]):0}function Jx(){return rS||(rS=new hd({size:2,sizeAttenuation:!1,vertexColors:!0})),rS}function Yx(e){if(!e)return[];if(Array.isArray(e))return e;let t=e,n=t.materials??t.material;return Array.isArray(n)?n:[]}function Xx(e){return e?.material??e}function Zx(e){return e?.name??e?.id}function Qx(e){return(e?.textureStates??e?.textureunitstates??[]).map(e=>e?.textureunitstate??e).filter(e=>!!e)}function $x(e){return e.length===16&&e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===1&&e[6]===0&&e[7]===0&&e[8]===0&&e[9]===0&&e[10]===1&&e[11]===0&&e[12]===0&&e[13]===0&&e[14]===0&&e[15]===1}function eS(e){let t=String(e?.cullMode??``).toUpperCase();return t===`CULL_BACK`||t===`BACKWARD`?0:t===`CULL_FRONT`?1:2}async function tS(e,t={}){let n=t.uniforms??wb(),r=t.textureCache??new Map,i=new Il,a=[],o=[],s={meshes:0,vertices:0,triangles:0,textures:0,instanced:0,edgeLines:0,skipped:[]},c=new nd({color:new W(t.edgeColor??`#1f2937`),transparent:!0,opacity:.75,depthWrite:!1});i.userData.hasNativeEdges=!1;let l=t=>{let n=e.textures?.[t];return n?.packKey?`${t}#${n.packKey}`:t};for(let[t,n]of Object.entries(e.textures??{})){let e=l(t),i=r.get(e);if(i){let t=i.image;if((t?.width??0)*(t?.height??0)>=(n.width??0)*(n.height??0))continue;r.delete(e)}let{texture:a,decoded:c}=await ab(n);a?(r.set(e,a),o.push(e),s.textures++):s.skipped.push(`texture ${t} → ${c}`)}let u=Yx(e.materials),d=e=>u.findIndex(t=>Zx(Xx(t))===e),f=(e,i=!1,a=!1,o=1)=>{let s=Xx(u.find(t=>Zx(Xx(t))===e)),c=Qx(s),d=c[0],f=d?r.get(l(Zx(d)??d.id??``))??null:null,p=c[1],m=globalThis.__S3M_NO_BAKE===!0,h=i&&p&&!m?r.get(l(Zx(p)??p.id??``))??null:null,g=d?.texmodmatrix??d?.matrix;if(f&&Array.isArray(g)&&g.length===16&&!$x(g)&&(f=f.clone(),f.matrixAutoUpdate=!1,f.matrix.set(g[0],g[4],g[12],g[1],g[5],g[13],0,0,1)),f&&d?.addressmode){let e=d.addressmode.u,t=d.addressmode.v;(e!==void 0||t!==void 0)&&(f.matrixAutoUpdate&&(f=f.clone()),e!==void 0&&(f.wrapS=e===0?zr:Br),t!==void 0&&(f.wrapT=t===0?zr:Br))}let _=s?.diffuse??{r:1,g:1,b:1,a:1},v=[d,p].some(e=>/\.water$/i.test(String(Zx(e)??e?.id??``))),y=ex({alphaMode:s?.alphaMode,diffuseAlpha:_.a??1,transparentSorting:s?.transparentsorting===!0,vertexAlphaMin:o,isWaterWithoutMap:v&&!f}),b=typeof s?.shininess==`number`&&s.shininess>0?Math.max(.15,1-s.shininess/128):.95,x=f?.userData?.s3mHasAlpha?Math.max(s?.alphaCutoff??0,.01):0,S=Tb({uniforms:n,map:f,color:v&&!f?iS.clone():new W(_.r??1,_.g??1,_.b??1),side:eS(s),transparent:y,opacity:v&&!f?.86:_.a??1,roughness:v&&!f?.12:b,alphaTest:x,atlas:i&&!!f,texCoordZ:a&&!!f,secMap:h});return t.polygonOffset&&(S.polygonOffset=!0,S.polygonOffsetFactor=t.polygonOffset.factor,S.polygonOffsetUnits=t.polygonOffset.units),S},p=t.assembled??bx(e,{batching:t.batching!==!1,dedupeCoincident:t.dedupeCoincident});s.vertices=p.stats.vertices,s.edgeLines=p.stats.edgeLines,s.instanced=p.stats.instanced,p.stats.originalMeshes!=null&&(s.originalMeshes=p.stats.originalMeshes),s.skipped.push(...p.stats.skipped);let m=new U,h=e=>{let t=new q;for(let[n,r]of Object.entries(e.attributes))r&&t.setAttribute(n,new G(r.array,r.components,r.normalized));return e.index?t.setIndex(new G(e.index,1)):t.setDrawRange(0,e.vertexCount),t.boundingBox=new yo(new H(...e.bounds.boxMin),new H(...e.bounds.boxMax)),t.boundingSphere=new Io(new H(...e.bounds.sphereCenter),e.bounds.sphereRadius),t};for(let n of p.primitives){let r=h(n),o=e.geoPackage[n.geoNames[0]]??null,l=o?.vertexPackage,u=f(n.passNames[0],!!n.attributes.aAtlasRect,!!n.attributes.aTexCoordZ,tx(n.attributes.aColor)),p=n.matrix&&n.matrix.length===16?new U().fromArray(n.matrix):null;if(Hx(n.primitiveType)){let e=new pd(r,c);e.visible=t.edges===!0,e.renderOrder=aS,e.raycast=()=>{},e.userData.isEdgeLines=!0,e.userData.skeletonName=n.skeletonName,p&&!p.equals(m)&&p.decompose(e.position,e.quaternion,e.scale),i.add(e),a.push(e),i.userData.hasNativeEdges=!0;continue}if(Ux(n.primitiveType)){let t=l?Kx(n,l):null;if(t){let r=new zu(t.geo,Wx(),t.geo.instanceCount);r.raycast=Nx,r.frustumCulled=!1,r.renderOrder=oS,t.sigma>0&&(s.splatSigma=Math.max(s.splatSigma??0,t.sigma)),s.splatCount=(s.splatCount??0)+t.geo.instanceCount,r.userData.isPointCloud=!0,r.userData.isGaussianSplat=!0,r.userData.skeletonName=n.skeletonName,r.userData.geoRef=o,r.userData.tileRef=e,r.userData.primitiveType=n.primitiveType,p&&!p.equals(m)&&p.decompose(r.position,r.quaternion,r.scale),i.add(r),a.push(r),s.meshes++;continue}r.getAttribute(`color`)||r.setAttribute(`color`,r.getAttribute(`aColor`));let c=new bd(r,Jx());c.userData.isPointCloud=!0,c.userData.skeletonName=n.skeletonName,c.userData.geoRef=o,c.userData.tileRef=e,c.userData.primitiveType=n.primitiveType,p&&!p.equals(m)&&p.decompose(c.position,c.quaternion,c.scale),i.add(c),a.push(c),s.meshes++;continue}let g;if(l&&l.instanceIndex!==-1&&(l.instanceMode===16||l.instanceMode===17)&&l.instanceBuffer&&(l.instanceCount??0)>0&&l){if(!r.getAttribute(`aInstanceBatchId`)){let e=l.instanceBatchIds,t=e&&e.length===l.instanceCount?e.slice():new Float32Array(l.instanceCount).fill(-1);r.setAttribute(`aInstanceBatchId`,new ju(t,1));let n=new Float32Array(l.instanceCount);for(let e=0;e<n.length;e++)n[e]=e;r.setAttribute(`aInstanceIndex`,new ju(n,1))}let e=new zu(r,u,l.instanceCount);e.instanceMatrix.setUsage(Aa);let t=new U,n=new W,i=l.instanceMode,a=new Float32Array(l.instanceBuffer.buffer,l.instanceBuffer.byteOffset,l.instanceCount*i);for(let r=0;r<l.instanceCount;r++){let o=r*i;if(t.set(a[o+0],a[o+1],a[o+2],a[o+3],a[o+4],a[o+5],a[o+6],a[o+7],a[o+8],a[o+9],a[o+10],a[o+11],0,0,0,1),e.setMatrixAt(r,t),i>=16){let t=a[o+12],i=a[o+13],s=a[o+14];Number.isFinite(t)&&Number.isFinite(i)&&Number.isFinite(s)&&(n.setRGB(t,i,s),e.setColorAt(r,n))}}e.instanceMatrix.needsUpdate=!0,e.instanceColor&&(e.instanceColor.needsUpdate=!0),e.frustumCulled=!1,g=e}else g=new hc(r,u);p&&!p.equals(m)&&p.decompose(g.position,g.quaternion,g.scale),g.userData.skeletonName=n.skeletonName,g.userData.geoRef=o,g.userData.tileRef=e,g.userData.primitiveType=n.primitiveType;let _=d(n.passNames[0]);if(_>=0&&!u.transparent&&(g.renderOrder=Math.min(_,sS)),n.batchedFrom!=null&&n.batchedFrom>1){g.userData.isBatched=!0,g.userData.batchedCount=n.batchedFrom;let t=new Map;for(let r of n.geoNames){let n=e.geoPackage[r];if(n?.pickInfo)for(let e of Object.values(n.pickInfo))typeof e.batchId==`number`&&e.batchId>=0&&t.set(e.batchId,n)}t.size>0&&(g.userData.geoByBatchId=t)}i.add(g),a.push(g),s.meshes++,n.primitiveType===4&&(s.triangles+=n.indexCount/3)}return i.children.length||s.skipped.push(`tile 无可用几何`),i.userData.textureKeys=o,{group:i,stats:s,objects:a,textureKeys:o}}var nS,rS,iS,aS,oS,sS,cS=a((()=>{sh(),fb(),Qb(),nx(),Cx(),Ax(),Bx(),z_(),nS=null,rS=null,iS=new W(1920611),aS=1e3,oS=1001,sS=999}));mh();function lS(e){return e.slice(0,e.lastIndexOf(`/`)+1)}function uS(e){if(!e)return e;try{let t=typeof document<`u`?document.baseURI:void 0;return t?new URL(e,t).href:new URL(e).href}catch{return e}}function dS(e,t){if(!t)return null;try{return fS(new URL(t,e).href)}catch{return fS(`${lS(e)}${t}`)}}function fS(e){if(!/[+ ]/.test(e))return e;let t=e.indexOf(`#`),n=t<0?``:e.slice(t),r=t<0?e:e.slice(0,t),i=r.indexOf(`?`),a=i<0?r:r.slice(0,i),o=i<0?``:r.slice(i);return`${a.replace(/\+/g,`%2B`).replace(/ /g,`%20`)}${o}${n}`}var pS=110540,mS=111320;function hS(e){if(!e||typeof e!=`object`)return null;let t=e;if(![t.left,t.bottom,t.right,t.top].every(e=>typeof e==`number`&&Number.isFinite(e)))return null;let{left:n,bottom:r,right:i,top:a}=t;return Math.abs(n)>180||Math.abs(i)>180||Math.abs(a)>90||Math.abs(r)>90||i===n&&a===r?null:{left:n,bottom:r,right:i,top:a}}function gS(e,t){if(!t)return null;let n=t.replace(/\.(osgb|s3mb|s3m)$/i,`.s3m`),r=e.split(`/`),i=r.pop()??``,a=r.pop()??``,o=r.lastIndexOf(`datas`);return!i||!a||o<1?dS(lS(e),n):fS(`${r[r.length-1]===`path`&&r[r.length-2]===`data`?`${r.join(`/`)}/${a}`:`${r.join(`/`)}/data/path/${a}`}/${n}`)}function _S(e){let t=e.trim();if(t.startsWith(`<`)){let e=e=>{let n=RegExp(`<(?:[a-zA-Z0-9_-]+:)?${e}[^>]*>([^<]+)<\\/`,`i`).exec(t);return n?n[1].trim():null},n=t=>parseFloat(e(t)??``),r=n(`X`)||0,i=n(`Y`)||0,a=n(`Z`)||0,o=n(`Left`),s=n(`Right`),c=n(`Top`),l=n(`Bottom`);if(![o,s,c,l].every(Number.isFinite)){let e=n(`MinX`),t=n(`MaxX`),a=n(`MinY`),u=n(`MaxY`);if([e,t,a,u].every(Number.isFinite)&&r&&i){let n=mS*Math.cos(i*Math.PI/180);n>1e-6&&(o=r+e/n,s=r+t/n,l=i+a/pS,c=i+u/pS)}}let u=t.matchAll(/<(?:[a-zA-Z0-9_-]+:)?FileName[^>]*>([^<]+)<\//gi),d=[];for(let e of u)d.push({url:e[1].trim()});let f=n(`MinHeight`),p=n(`MaxHeight`);return{fileType:e(`FileType`)??void 0,position:{x:r,y:i,z:a,units:`Degree`},geoBounds:{left:o,right:s,top:c,bottom:l},heightRange:Number.isFinite(f)||Number.isFinite(p)?{min:f,max:p}:void 0,rootTiles:d,tiles:d}}return JSON.parse(t)}var vS=class{get heightRange(){let e=this.config?.heightRange;return e&&typeof e.min==`number`&&typeof e.max==`number`?{min:e.min,max:e.max}:null}constructor(e){X(this,`configUrl`,void 0),X(this,`config`,null),X(this,`_blockTileIndex`,null),X(this,`anchor`,{lon:0,lat:0,height:0}),X(this,`rootUrls`,[]),X(this,`nodes`,new Map),X(this,`failed`,new Set),X(this,`textureCache`,new Map),X(this,`maxImageCache`,void 0),X(this,`_textureRefs`,new Map),X(this,`_tileTextureKeys`,new Map),X(this,`pending`,new Set),X(this,`atlasLod`,void 0),X(this,`atlasLodCache`,new Map),X(this,`_groupCache`,new Map),X(this,`externalAtlasCache`,new Map),X(this,`leafRequestCache`,new Map),X(this,`_leafPending`,new Map),X(this,`atlasUpgraded`,new Set),X(this,`atlasUpgradeSkipped`,new Map),X(this,`stats`,{tiles:0,loading:0,failed:0,meshes:0,vertices:0,triangles:0,datasets:1,drawCalls:0,programs:0,textures:0,geometries:0,degradations:[]}),X(this,`maxConcurrent`,void 0),X(this,`maxTiles`,void 0),X(this,`maxTriangles`,void 0),X(this,`lodRangeScale`,void 0),X(this,`_onTile`,void 0),X(this,`_onTileRemoved`,void 0),X(this,`_onError`,void 0),X(this,`_onProgress`,void 0),X(this,`_maxRetries`,void 0),X(this,`authenticate`,void 0),X(this,`_unsupported`,void 0),X(this,`_retryCount`,new Map),X(this,`_retryAt`,new Map),X(this,`_parentOf`,new Map),X(this,`_frame`,0),X(this,`_permanentReported`,!1),X(this,`hardCap`,96),X(this,`isS3MV1`,!1),X(this,`_buildTile`,void 0),X(this,`_polygonOffset`,void 0),X(this,`_uniforms`,void 0),X(this,`_workerClient`,void 0),X(this,`_useWorker`,void 0),X(this,`_queue`,[]),X(this,`_active`,0),this.configUrl=e.configUrl,this.lodRangeScale=e.lodRangeScale??3,this._onTile=e.onTile??(()=>{}),this._onTileRemoved=e.onTileRemoved??(()=>{}),this._onError=e.onError??(e=>console.warn(e)),this._onProgress=e.onProgress??(()=>{}),this._maxRetries=Math.max(0,e.maxRetries??2),this.authenticate=e.authenticate,this._unsupported=e.unsupported??`warn`,this._buildTile=e.buildTile??null,this._polygonOffset=e.polygonOffset,this._uniforms=e.uniforms??null,this._useWorker=e.useWorker!==!1,this.maxConcurrent=e.maxConcurrent??4,this.maxTiles=e.maxTiles??64,this.maxTriangles=e.maxTriangles??1/0,this.maxImageCache=e.maxImageCache??128,this.hardCap=this.maxTiles+Math.max(8,Math.ceil(this.maxTiles*.5)),this.atlasLod=e.atlasLod!==!1}async init(){this.configUrl=uS(this.configUrl);let e=await E_(this.configUrl,this.authenticate,`config`);if(!e.ok)throw Error(`配置读取失败 ${e.status} ${this.configUrl}`);let t=_S(await e.text());this.config=t,this.anchor=this._resolveAnchor(t);let n=t.rootTiles??t.tiles??[];if(!n.length)throw Error(`配置中缺少 root tile`);this.rootUrls.length=0;for(let e of n){let t=dS(this.configUrl,e.url);t&&this.rootUrls.push(t)}if(this.isS3MV1=/OSGB/i.test(String(t.fileType??``))||/OSGB/i.test(String(t.dataType??``))||this.rootUrls.length>0&&this.rootUrls.every(e=>/\.s3m($|\?)/i.test(e)),this.rootUrls.every(e=>/\.s3mblock($|\?)/i.test(e))){this._blockTileIndex=new Set(this.rootUrls);for(let e of n){let t=dS(this.configUrl,e.url);t&&this._blockTileIndex.add(t)}}await this._load(this.rootUrls[0]);for(let e of this.rootUrls.slice(1))this._enqueue(e);return this}_enqueue(e,t){if(!e||(t&&this._parentOf.set(e,t),this.nodes.has(e)||this.pending.has(e)||this.failed.has(e))||this._queue.includes(e))return;let n=this._retryAt.get(e);n!==void 0&&performance.now()<n||this.nodes.size+this.pending.size+this._queue.length>=this.hardCap||(this._queue.push(e),this._pump())}registerTileTextures(e,t){this._tileTextureKeys.set(e,t);let n=this.nodes.get(e);n&&(n.textureKeys=t);for(let e of t)this._textureRefs.set(e,(this._textureRefs.get(e)??0)+1)}_evictTileNode(e){this.nodes.delete(e.url),e.group?.parent?.remove(e.group),this._onTileRemoved(e),this._parentOf.delete(e.url),this.stats.tiles=Math.max(0,this.stats.tiles-1),e.stats&&(this.stats.meshes=Math.max(0,this.stats.meshes-(e.stats.meshes??0)),this.stats.vertices=Math.max(0,this.stats.vertices-(e.stats.vertices??0)),this.stats.triangles=Math.max(0,this.stats.triangles-(e.stats.triangles??0)));let t=e.textureKeys??this._tileTextureKeys.get(e.url)??e.group?.userData?.textureKeys;if(this._tileTextureKeys.delete(e.url),t?.length)for(let e of t){let t=(this._textureRefs.get(e)??1)-1;if(t<=0){this._textureRefs.delete(e);let t=this.textureCache.get(e);t&&(t.dispose?.(),this.textureCache.delete(e))}else this._textureRefs.set(e,t)}}putExternalAtlas(e,t){if(this.externalAtlasCache.size>=this.maxImageCache&&!this.externalAtlasCache.has(e)){let e=this.externalAtlasCache.keys().next().value;e!==void 0&&this.externalAtlasCache.delete(e)}Map.prototype.set.call(this.externalAtlasCache,e,t)}getExternalAtlas(e){return this.externalAtlasCache.get(e)}putLeafRecords(e,t){if(this.leafRequestCache.size>=this.maxImageCache&&!this.leafRequestCache.has(e)){let e=this.leafRequestCache.keys().next().value;e!==void 0&&this.leafRequestCache.delete(e)}Map.prototype.set.call(this.leafRequestCache,e,t)}getLeafRecords(e){return this.leafRequestCache.get(e)}_evictOne(e=!1){let t=this._pickVictim(!0,e)??this._pickVictim(!1,e);if(!t)return!1;let n=t.parentUrl??this._parentOf.get(t.url),r=t.childUrls??(t.childUrl?[t.childUrl]:[]);r.some(e=>e!==t.url&&this.nodes.has(e)),this._evictTileNode(t);let i=r.filter(e=>e!==t.url&&this.nodes.has(e));if(i.length){for(let e of i){let t=this.nodes.get(e);t&&(t.parentUrl=n??void 0,n?this._parentOf.set(e,n):this._parentOf.delete(e))}if(n){let e=this.nodes.get(n);if(e){let n=new Set(e.childUrls??[]);e.childUrl&&n.add(e.childUrl),n.delete(t.url);for(let e of i)n.add(e);e.childUrls=[...n],e.childUrl=e.childUrls[0]??null}}}return!0}_residentTriangles(){let e=0;for(let t of this.nodes.values())e+=t.stats?.triangles??0;return e}setMaxTriangles(e){this.maxTriangles=e>0?e:1/0}_trimBudget(){let e=!1,t=0,n=()=>this.nodes.size+this.pending.size>this.maxTiles,r=()=>Number.isFinite(this.maxTriangles)&&this._residentTriangles()>this.maxTriangles,i=this.nodes.size+this.maxTiles+16;for(;(n()||r())&&t++<=i&&this._evictOne(this.nodes.size+this.pending.size>this.hardCap);)e=!0;return e}_pickVictim(e,t=!1){let n=null;for(let r of this.nodes.values()){let i=r.childUrls??(r.childUrl?[r.childUrl]:[]);if((i.length>0&&i.some(e=>e!==r.url&&this.nodes.has(e)))!==e||!t&&r.group.visible&&!i.some(e=>{let t=this.nodes.get(e);return!!t&&t.group.visible}))continue;if(!n){n=r;continue}let a=r.lastSeen??-1,o=n.lastSeen??-1;(a<o||a===o&&(r.distance??0)>(n.distance??0))&&(n=r)}return n}retryFailed(){let e=this.failed.size;return this.failed.clear(),this._retryCount.clear(),this._retryAt.clear(),e}_pump(){for(;this._active<this.maxConcurrent&&this._queue.length;){let e=this._queue.shift();this._active++,this._load(e).finally(()=>{this._active--,this._pump()})}}_resolveAnchor(e){let t=e.position,n=t?.point3D??t,r=!!n&&Number.isFinite(n.x)&&Number.isFinite(n.y),i=hS(e.geoBounds),a=i?(i.left+i.right)/2:void 0,o=i?(i.bottom+i.top)/2:void 0,s=n?.z??0;if(!r)return{lon:a??0,lat:o??0,height:0};if((t?.units??t?.unit??`Degree`)!==`Degree`)return{lon:n.x,lat:n.y,height:s};let c=a===void 0?0:Math.abs(n.x-a),l=o===void 0?0:Math.abs(n.y-o);return c>.5||l>.5?(console.warn(`[s3m] position 与 geoBounds 不一致,改用 geoBounds 中心作为锚点`,{position:n,geoBounds:i}),{lon:a,lat:o,height:s}):{lon:n.x,lat:n.y,height:s}}_pickLod(e){let t=e.groupNode?.pageLods??[];return t.length?t.find(e=>e.childTile&&e.rangeValue>0)??t[0]:null}async _builder(){if(!this._buildTile){let e=await Promise.resolve().then(()=>(cS(),Vx));this._buildTile=e.buildTileObjects}return this._buildTile}async _parseClassicTile(e){if(this._useWorker&&this._workerClient===void 0&&(this._workerClient=K_()),this._workerClient)try{return await this._workerClient.parseTile(e,!0)}catch(e){if(e instanceof U_)this._workerClient=null;else throw e}return{tile:await m_(e)}}_rememberGroups(e,t){for(this._groupCache.delete(e),this._groupCache.set(e,t);this._groupCache.size>24;){let e=this._groupCache.keys().next().value;if(e===void 0)break;this._groupCache.delete(e)}}async _fillExternalAtlases(e,t){let n=e,r=n.texturePackage;if(!r)return;let i=Sy(n),a=!1,o=new Map,s=new Map,c=[];for(let[e,t]of Object.entries(r)){let n=Ny(t.requestNames);if(n.names.length){o.set(e,{tex:t,plan:n});for(let[e,t]of n.packGroups){let n=t.filter(e=>!this.leafRequestCache.has(e));if(!n.length)continue;let r=s.get(e)??[];for(let e of n)r.includes(e)||r.push(e);s.set(e,r)}for(let e of n.plain)!this.leafRequestCache.has(e)&&!c.includes(e)&&c.push(e)}}let l=[];for(let[e,n]of s){let r=null,i=()=>r??(r=this._fetchLeafPack(t,e,n));for(let e of n)l.push(this._ensureLeafFetch(e,i))}for(let e of c)l.push(this._ensureLeafFetch(e,()=>this._fetchLeafFile(t,e)));l.length&&await Promise.all(l);for(let[e,{tex:t,plan:n}]of o){let r=new Map;for(let e of n.names){let t=this.leafRequestCache.get(e);if(t)for(let n of t)r.set(n.id,{source:e,image:n})}let i=Py(t,r);if(i){let n=t;n.composed=!0,n.leafSig=i.sig,n.flipY=!1,t.data=i.data,t.compressType=0,t.pixelFormat=28,t.width=i.width,t.height=i.height,t.rectScale=1,this.atlasUpgraded.add(e),a=!0,(i.missing.length||i.mismatched.length)&&console.warn(`[s3m] leaf 图集部分精灵异常:`,e,{missing:i.missing,mismatched:i.mismatched});continue}let o=!!t.data,s=n=>{if(!o){let r=t.width/t.height,i=n.width/n.height;return Math.abs(i/r-1)<=.02||(this.atlasUpgradeSkipped.set(e,`aspect(no-baseline) ${t.width}x${t.height} vs ${n.width}x${n.height}`),!1)}let r=Ry(t,n);return r.ok?!0:(this.atlasUpgradeSkipped.set(e,`${r.reason} aspectΔ=${(r.aspectDelta*100).toFixed(1)}% scale=${r.scale} err=${Number.isNaN(r.meanAbsError)?`n/a`:r.meanAbsError.toFixed(1)}`),!1)},c=n=>{let r=t;r.composed=!1,r.leafSig=void 0,r.flipY=!0,t.data=n.data,t.compressType=n.compressType,t.pixelFormat=n.pixelFormat,t.rectScale=t.width>0?n.width/t.width:1,t.width=n.width||t.width,t.height=n.height||t.height,this.atlasUpgraded.add(e),a=!0},l=this.externalAtlasCache.get(e);if(l!==null){if(l===void 0){l=null;for(let e of n.plain){let t=this.leafRequestCache.get(e);if(t?.length){l=t[0];break}}this.putExternalAtlas(e,l)}l?s(l)&&c(l):this.atlasUpgradeSkipped.has(e)||this.atlasUpgradeSkipped.set(e,`no usable external image(请求失败或只拿到子精灵)`)}}(i||a)&&Cy(n)}_ensureLeafFetch(e,t){if(this.leafRequestCache.has(e))return Promise.resolve();let n=this._leafPending.get(e);if(n)return n;let r=t().finally(()=>this._leafPending.delete(e));return this._leafPending.set(e,r),r}async _fetchLeafPack(e,t,n){let r=dS(lS(e),`${n[0]}.texblock?extratiles=${n.join(`;`)}`);try{if(!r)throw Error(`无法拼出 URL`);let e=await E_(r,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await Ey(await e.arrayBuffer());if(t.length!==n.length)throw Error(`pack 段数 ${t.length} ≠ 请求名 ${n.length}`);n.forEach((e,n)=>this.putLeafRecords(e,t[n]))}catch(e){console.warn(`[s3m] leaf pack 请求失败:`,r,e);for(let e of n)this.leafRequestCache.has(e)||this.putLeafRecords(e,null)}}async _fetchLeafFile(e,t){let n=dS(lS(e),`${t}.texblock`);try{if(!n)throw Error(`无法拼出 URL`);let e=await E_(n,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let r=(await Ey(await e.arrayBuffer())).flat();this.putLeafRecords(t,r)}catch(e){console.warn(`[s3m] leaf texblock 请求失败:`,n,e),this.leafRequestCache.has(t)||this.putLeafRecords(t,null)}}async _upgradeAtlasLod(e,t){}_noteDegradations(e){let t=e.degradations;if(!t?.length)return;let n=g_(t,this.stats.degradations,this._unsupported);this.stats.degradations=n.known;for(let e of n.messages)console.warn(e);if(n.error)throw n.error}async _load(e){if(!(this.nodes.has(e)||this.pending.has(e)||this.failed.has(e))){this.pending.add(e),this.stats.loading++;try{let t=e.indexOf(`#`),n=t>=0?e.slice(0,t):e,r=t>=0&&Number(e.slice(t+1))||0,i=/\.s3mblock($|\?)/i.test(n),a,o,s=[],c=this._groupCache.get(n);if(c)s=c.names,a=c.tiles[r]??c.tiles[0];else{let e=await E_(n,this.authenticate,`tile`);if(!e.ok)throw Error(`HTTP ${e.status} 加载瓦片失败: ${n}`);if((e.headers.get(`content-type`)||``).includes(`text/html`))throw Error(`瓦片请求返回了 HTML 页面(通常为 404/500 服务端拦截): ${n}`);let t=await e.arrayBuffer();if(i){let e=await Fy(t);this._rememberGroups(n,e),s=e.names,a=e.tiles[r]??e.tiles[0]}else{let e=await this._parseClassicTile(t);a=e.tile,o=e.geometry}}i&&(await this._fillExternalAtlases(a,n),await this._upgradeAtlasLod(a,n)),this._noteDegradations(a);let l=await(await this._builder())(a,{textureCache:this.textureCache,uniforms:this._uniforms,assembled:o,polygonOffset:this._polygonOffset}),{group:u,stats:d}=l,f=l.textureKeys??u.userData?.textureKeys??Object.keys(a.textures??{});this.registerTileTextures(e,f);let p=this._pickLod(a),m=[];for(let t of a.groupNode?.pageLods??[]){let r=String(t.childTile??``).replace(/\.s3mblock$/i,``),a=i&&r?s.indexOf(r):-1,o=a>=0?`${n}#${a}`:this.isS3MV1?gS(e,t.childTile):dS(lS(e),t.childTile);o&&o!==e&&!m.includes(o)&&m.push(o)}let h={url:e,tile:a,group:u,sphere:p?.boundingSphere??null,rangeValue:p?.rangeValue??0,rangeMode:p?.rangeMode??1,childUrl:m[0]??(this.isS3MV1?gS(e,p?.childTile):dS(lS(e),p?.childTile)),childUrls:m,parentUrl:this._parentOf.get(e),state:`ready`,...d.splatSigma?{splatSigma:d.splatSigma}:{},...d.splatCount?{splatCount:d.splatCount}:{},stats:{meshes:d.meshes??0,vertices:d.vertices??0,triangles:d.triangles??0}};this.nodes.set(e,h),this.stats.tiles++,this.stats.meshes+=d.meshes??0,this.stats.vertices+=d.vertices??0,this.stats.triangles+=d.triangles??0,this._onTile(h)}catch(t){let n=t?.permanent===!0,r=(this._retryCount.get(e)??0)+1;if(this._retryCount.set(e,r),!n&&r<=this._maxRetries)this._retryAt.set(e,performance.now()+800*r);else{this.stats.failed++,this.failed.add(e),this._retryAt.delete(e);let t=this._parentOf.get(e),n=t?this.nodes.get(t):void 0;n?.childUrls&&(n.childUrls=n.childUrls.filter(t=>t!==e),n.childUrl=n.childUrls[0]??null)}n?this._permanentReported||(this._permanentReported=!0,this._onError(t)):this._onError(t)}finally{this.pending.delete(e),this.stats.loading--,this._onProgress(this.stats)}}}update(e,t,n){this._frame++;let r=!1;for(let t of this.nodes.values()){var i;if(!t.sphere){t.needRefine=!1;continue}let a=t.sphere.center,o=a.x-e[0],s=a.y-e[1],c=a.z-e[2],l=Math.sqrt(o*o+s*s+c*c)||1e-6;t.distance=l;let u,d=t.rangeMode===0;u=d?l:n*.5/Math.tan(Math.PI/8)*(t.sphere.radius/l)*2;let f=this.lodRangeScale>0?this.lodRangeScale:1,p=t.rangeValue*f;(d?l<p*2:u>p*.5)&&(t.lastSeen=this._frame);let m=t.childUrls??(t.childUrl?[t.childUrl]:[]),h=t.needRefine?d?1.08:.92:1,g=t.splatSigma&&t.sphere?H_({splats:t.splatCount??t.stats?.vertices??0,radius:t.sphere.radius,distance:l,sigma:t.splatSigma,screenHeight:n,hasChild:m.length>0}):null,_=g?g.needRefine:m.length>0&&(d?u<p*h:u>p*h);t.needRefine=_;let v=(i=globalThis).__S3M_LOD_SEEN??(i.__S3M_LOD_SEEN=new Set);if(globalThis.__S3M_LOD_DEBUG&&!v.has(t.url)&&v.size<260&&(v.add(t.url),console.log(`[LOD]`,JSON.stringify({url:t.url.split(`/`).pop(),mode:t.rangeMode,rangeValue:t.rangeValue,radius:t.sphere.radius,dist:+l.toFixed(1),metric:+u.toFixed(1),threshold:+p.toFixed(1),needRefine:_,childUrls:m.map(e=>e.split(`/`).pop()),parent:t.parentUrl?t.parentUrl.split(`/`).pop():null}))),_)for(let e of m)this.failed.has(e)||this.nodes.has(e)||this.pending.has(e)||(this._enqueue(e,t.url),r=!0)}let a=new Set,o=new Set(this.rootUrls);for(let[e,t]of this.nodes){let n=t.parentUrl??this._parentOf.get(e);n&&this.nodes.has(n)||o.add(e)}for(let e of o)this._updateNodeVisibility(e,!0,a)&&(r=!0);for(let[e,t]of this.nodes)a.has(e)||t.group.visible&&(t.group.visible=!1,r=!0);this._trimBudget()&&(r=!0);let s=!1;for(let e of this.nodes.values())if(e.group.visible){s=!0;break}if(!s&&this.nodes.size>0)for(let e of this.nodes.values())!(e.childUrls??(e.childUrl?[e.childUrl]:[])).some(t=>{let n=this.nodes.get(t);return!!n&&n!==e&&n.group.visible})&&!e.group.visible&&(e.group.visible=!0,r=!0);return r}_updateNodeVisibility(e,t,n){let r=this.nodes.get(e);if(!r||n.has(e))return!1;n.add(e);let i=!1,a=r.childUrls??(r.childUrl?[r.childUrl]:[]);if(!t){r.group.visible&&(r.group.visible=!1,i=!0);for(let e of a)this._updateNodeVisibility(e,!1,n)&&(i=!0);return i}let o=a.length>0,s=a.filter(e=>this.nodes.has(e)),c=a.every(e=>this.nodes.has(e)||this.failed.has(e));if(r.needRefine&&o&&s.length>0&&c){r.group.visible&&(r.group.visible=!1,i=!0);for(let e of a)this._updateNodeVisibility(e,!0,n)&&(i=!0)}else{r.group.visible||(r.group.visible=!0,i=!0);for(let e of a)this._updateNodeVisibility(e,!1,n)&&(i=!0)}return i}dispose(){this._workerClient?.dispose();for(let e of this.nodes.values())e.group.traverse(e=>{let t=e;t.geometry?.dispose?.(),Array.isArray(t.material)?t.material.forEach(e=>e.dispose?.()):t.material?.dispose?.()});for(let e of this.textureCache.values())e.dispose?.();this.textureCache.clear(),this.nodes.clear()}};cS();var yS={ambientIntensity:.4,hemisphereIntensity:.8,keyLightIntensity:1,fillLightIntensity:.35},bS={ambientIntensity:.12,hemisphereIntensity:.2,keyLightIntensity:1.95,fillLightIntensity:.15},xS={default:yS,supermap:bS};function SS(e){return e&&Object.prototype.hasOwnProperty.call(xS,e)?xS[e]:yS}sh(),Qb(),fb(),mh();var CS={ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50},wS=class{get envRT(){return this._envRT}set envRT(e){this._envRT=e}constructor(e){X(this,`ctx`,void 0),X(this,`ambient`,null),X(this,`hemi`,null),X(this,`key`,null),X(this,`fill`,null),X(this,`_state`,void 0),X(this,`_envRT`,null),this.ctx=e,this._state={...CS};let t=e.options;t.lightingPreset&&t.lightingPreset!=="default"&&(Object.assign(this._state,SS(t.lightingPreset)),this.applyColorPipeline(t.lightingPreset)),t.light&&Object.assign(this._state,t.light)}_create(){this.ambient=new vp(this._state.ambientColor,this._state.ambientIntensity),this.hemi=new ip(this._state.hemisphereColor,this._state.hemisphereGroundColor,this._state.hemisphereIntensity),this.key=new _p(this._state.keyLightColor,this._state.keyLightIntensity),this.fill=new _p(this._state.fillLightColor,this._state.fillLightIntensity),this.update()}addToScene(){let e=this.ctx.scene();e&&(this.ambient||this._create(),e.add(this.ambient,this.hemi,this.key,this.fill))}get created(){return this.ambient!==null}_applyOptions(){let e=this._state;this.ambient&&(this.ambient.intensity=e.ambientIntensity,this.ambient.color.set(e.ambientColor)),this.hemi&&(this.hemi.intensity=e.hemisphereIntensity,this.hemi.color.set(e.hemisphereColor),this.hemi.groundColor.set(e.hemisphereGroundColor)),this.key&&(this.key.intensity=e.keyLightIntensity,this.key.color.set(e.keyLightColor)),this.fill&&(this.fill.intensity=e.fillLightIntensity,this.fill.color.set(e.fillLightColor))}update(){if(!this.key||!this.fill)return;let e=this._state,t=e.mode===`fixed`?0:(this.ctx.getBearing?.()??0)*Math.PI/180,n=(e,n,r)=>{if(!e)return;let i=t+n*Math.PI/180,a=r*Math.PI/180,o=Math.cos(a);e.position.set(Math.sin(i)*o,Math.cos(i)*o,Math.sin(a)).multiplyScalar(1e3)};n(this.key,e.azimuth,e.altitude),n(this.fill,e.azimuth+65,Math.max(10,e.altitude-20));let r=this.ctx.uniforms?.uSunDirection;r&&r.value.copy(this.key.position).normalize()}applyColorPipeline(e){let t=e===`supermap`;Sb(t?`direct`:`linear`),nb(!t),Zy(t?1:1/0)}setLightingPreset(e){Object.assign(this._state,SS(e)),this.applyColorPipeline(e),this.ctx.options.lightingPreset=e,this._applyOptions(),this.update(),this.ctx.repaint()}setLight(e){let t={...e};t.mainColor!==void 0&&t.keyLightColor===void 0&&(t.keyLightColor=t.mainColor),t.mainIntensity!==void 0&&t.keyLightIntensity===void 0&&(t.keyLightIntensity=t.mainIntensity),Object.assign(this._state,t),this._applyOptions(),this.update(),this.ctx.repaint()}getLight(){return{...this._state}}setToneMapping(e,t=1){this.ctx.options.toneMapping=e,this.ctx.options.toneMappingExposure=t;let n=this.ctx.renderer();n&&(n.toneMapping=e,n.toneMappingExposure=t,this.ctx.repaint())}getToneMapping(){let e=this.ctx.renderer();return{toneMapping:e?e.toneMapping:this.ctx.options.toneMapping??0,toneMappingExposure:e?e.toneMappingExposure:this.ctx.options.toneMappingExposure??1}}async setEnvironment(e,t=1){let n=this.ctx.renderer(),r=this.ctx.scene();if(!n||!r)return;if(r.environmentIntensity=Math.max(0,t),e==null){r.environment=null,this._envRT?.dispose(),this._envRT=null,this.ctx.repaint();return}let i=typeof e==`string`,a=i?await new np().loadAsync(e):e;a.mapping=303;let o=new nl(n);o.compileEquirectangularShader();let s=o.fromEquirectangular(a);o.dispose(),i&&a.dispose(),r.environment=s.texture,this._envRT?.dispose(),this._envRT=s,this.ctx.repaint()}dispose(){this._envRT?.dispose(),this._envRT=null}};sh(),mh();var TS=class{constructor(e){X(this,`uniforms`,void 0),X(this,`_meshHeight`,new Map),X(this,`_min`,1/0),X(this,`_max`,-1/0),X(this,`_box`,new yo),this.uniforms=e}get size(){return this._meshHeight.size}add(e){let t=e.geometry?.boundingBox;if(!t)return;this._box.copy(t).applyMatrix4(e.matrixWorld);let n=this._box.min.z,r=this._box.max.z;Number.isFinite(n)&&Number.isFinite(r)&&(this._meshHeight.set(e,{min:n,max:r}),n<this._min&&(this._min=n),r>this._max&&(this._max=r),this._push())}remove(e){let t=this._meshHeight.get(e);t&&(this._meshHeight.delete(e),t.min===this._min||t.max===this._max?this._recompute():this._push())}refreshAll(){if(this._meshHeight.size===0)return;let e=[...this._meshHeight.keys()];this._meshHeight.clear(),this._min=1/0,this._max=-1/0;for(let t of e)this.add(t);this._push()}clear(){this._meshHeight.clear(),this._min=1/0,this._max=-1/0}get range(){return{min:this._min,max:this._max}}_recompute(){let e=1/0,t=-1/0;for(let n of this._meshHeight.values())n.min<e&&(e=n.min),n.max>t&&(t=n.max);this._min=e,this._max=t,this._push()}_push(){let e=this._min,t=this._max;(!Number.isFinite(e)||!Number.isFinite(t)||t<=e)&&(e=0,t=100),this.uniforms.uHeightMin.value=e,this.uniforms.uHeightMax.value=t}},ES=new Uint32Array,DS=new Uint32Array,OS=new Uint32Array(256),kS=new Float32Array(1),AS=new Uint32Array(kS.buffer);function jS(e){kS[0]=e;let t=AS[0];return t&2147483648?~t>>>0:(t|2147483648)>>>0}function MS(e,t,n,r){let i=r&&r.length>=t?r:new Uint32Array(t);if(t<=1)return t===1&&(i[0]=0),i;ES.length<t&&(ES=new Uint32Array(t)),DS.length<t&&(DS=new Uint32Array(t));let a=ES,o=DS,s=n.elements,c=s[2],l=s[6],u=s[10],d=s[14];for(let n=0;n<t;n++)a[n]=jS(c*e[n*3]+l*e[n*3+1]+u*e[n*3+2]+d),i[n]=n;let f=i,p=o;for(let e=0;e<4;e++){let n=e*8;OS.fill(0);for(let e=0;e<t;e++)OS[a[f[e]]>>>n&255]++;let r=0;for(let e=0;e<256;e++){let t=OS[e];OS[e]=r,r+=t}for(let e=0;e<t;e++){let t=f[e];p[OS[a[t]>>>n&255]++]=t}let i=f;f=p,p=i}return f!==i&&i.set(f),i}sh();var NS=[`iCenter`,`iScale`,`iQuat`,`iColor`],PS=new U,IS=new WeakMap,LS=new WeakMap;function RS(e,t){let n=e.geometry,r=n.getAttribute(`iCenter`);if(!r)return!1;let i=Math.min(n.instanceCount??1/0,r.count);if(i<=1)return!1;PS.multiplyMatrices(t,e.matrixWorld);let a=LS.get(r);(!a||a.length<i)&&(a=new Uint32Array(i),LS.set(r,a)),MS(r.array,i,PS,a);let o=!0;for(let e=0;e<i;e++)if(a[e]!==e){o=!1;break}if(o)return!1;for(let e of NS){let t=n.getAttribute(e);if(!t)continue;let r=t.array,o=t.itemSize,s=i*o,c=IS.get(t);(!c||c.length<s)&&(c=new r.constructor(s),IS.set(t,c));for(let e=0;e<i;e++){let t=a[e]*o,n=e*o;for(let e=0;e<o;e++)c[n+e]=r[t+e]}r.set(c.subarray(0,s)),t.needsUpdate=!0}return!0}sh(),mh();var zS=class{constructor(){X(this,`_lastView`,new U),X(this,`_sorted`,!1)}markDirty(){this._sorted=!1}sort(e,t){if(e&&!(this._sorted&&this._lastView.equals(e.matrixWorldInverse))){for(let n of t)n.userData.isGaussianSplat&&RS(n,e.matrixWorldInverse);this._lastView.copy(e.matrixWorldInverse),this._sorted=!0}}reset(){this._sorted=!1,this._lastView.identity()}};sh(),Qb(),_b();function BS(){return{uResolution:{value:new B(1,1)},uDpr:{value:1}}}var VS=`
4765
+ `,side:2,depthTest:!0,depthWrite:!0})}function Fx(e){let t=e.getAttribute(`iCenter`);if(!t)return null;let n=t.array,r=t.count;if(!r)return null;let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let e=0;e<r;e++){let t=n[e*3],r=n[e*3+1],u=n[e*3+2];t<i&&(i=t),t>s&&(s=t),r<a&&(a=r),r>c&&(c=r),u<o&&(o=u),u>l&&(l=u)}return{minX:i,minY:a,minZ:o,maxX:s,maxY:c,maxZ:l,count:r}}var Ix,Lx,Rx,zx,Bx=a((()=>{sh(),z_(),Ix=new B(1e3,1e3),Lx=new Io,Rx=new U,zx=new Wo})),Vx=o({LINE_PRIMITIVE:()=>13,POINT_PRIMITIVE:()=>1,buildTileObjects:()=>tS,setSplatViewport:()=>Gx});function Hx(e){return e===13||e===2||e===3}function Ux(e){return e===1}function Wx(){return nS??(nS=jx()),nS}function Gx(e,t){nS&&nS.uniforms.uViewport.value.set(e,t)}function Kx(e,t){let n=t.vertexAttributes.find(e=>e.semantic===`gsScale`),r=t.vertexAttributes.find(e=>e.semantic===`gsRotation`),i=e.attributes.position;if(!n||!r||!i)return null;let a=Math.min(t.verticesCount,Math.floor(i.array.length/i.components));if(a<=0)return null;let o=wx(n.data,n.stride,n.offsetInBytes,a),s=Tx(r.data,r.stride,r.offsetInBytes,a),c=qx(o,a),l=Mx();l.instanceCount=a,l.setAttribute(`iCenter`,new ju(i.array,3)),l.setAttribute(`iScale`,new ju(o,3)),l.setAttribute(`iQuat`,new ju(s,4));let u=new Float32Array(a*4);u.fill(1);let d=t.vertexAttributes.find(e=>e.semantic===`color`);if(d&&d.dtype===`u8`){let e=d.components??4,t=Math.min(a,Math.floor(d.data.length/d.stride));for(let n=0;n<t;n++){let t=n*d.stride+d.offsetInBytes;u[n*4]=d.data[t]/255,u[n*4+1]=d.data[t+1]/255,u[n*4+2]=d.data[t+2]/255,e>=4&&(u[n*4+3]=d.data[t+3]/255)}}else if(e.attributes.aColor){let t=e.attributes.aColor,n=t.components??4;for(let e=0;e<a;e++)for(let r=0;r<Math.min(n,4);r++)u[e*4+r]=t.array[e*n+r]}l.setAttribute(`iColor`,new ju(u,4));let f=i.array,p=1/0,m=1/0,h=1/0,g=-1/0,_=-1/0,v=-1/0,y=0;for(let e=0;e<a;e++){let t=f[e*3],n=f[e*3+1],r=f[e*3+2];t<p&&(p=t),t>g&&(g=t),n<m&&(m=n),n>_&&(_=n),r<h&&(h=r),r>v&&(v=r);let i=o[e*3],a=o[e*3+1],s=o[e*3+2];i>y&&(y=i),a>y&&(y=a),s>y&&(y=s)}let b=new yo;a>0&&(b.min.set(p,m,h),b.max.set(g,_,v));let x=new Io(new H,0);return b.isEmpty()||b.getBoundingSphere(x),x.radius+=3*y,l.boundingSphere=x,{geo:l,sigma:c}}function qx(e,t){let n=Math.max(1,Math.floor(t/512)),r=[];for(let i=0;i<t;i+=n){let t=Math.max(e[i*3],e[i*3+1],e[i*3+2]);Number.isFinite(t)&&t>0&&r.push(t)}return r.length?(r.sort((e,t)=>e-t),r[r.length>>1]):0}function Jx(){return rS||(rS=new hd({size:2,sizeAttenuation:!1,vertexColors:!0})),rS}function Yx(e){if(!e)return[];if(Array.isArray(e))return e;let t=e,n=t.materials??t.material;return Array.isArray(n)?n:[]}function Xx(e){return e?.material??e}function Zx(e){return e?.name??e?.id}function Qx(e){return(e?.textureStates??e?.textureunitstates??[]).map(e=>e?.textureunitstate??e).filter(e=>!!e)}function $x(e){return e.length===16&&e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===1&&e[6]===0&&e[7]===0&&e[8]===0&&e[9]===0&&e[10]===1&&e[11]===0&&e[12]===0&&e[13]===0&&e[14]===0&&e[15]===1}function eS(e){let t=String(e?.cullMode??``).toUpperCase();return t===`CULL_BACK`||t===`BACKWARD`?0:t===`CULL_FRONT`?1:2}async function tS(e,t={}){let n=t.uniforms??wb(),r=t.textureCache??new Map,i=new Il,a=[],o=[],s={meshes:0,vertices:0,triangles:0,textures:0,instanced:0,edgeLines:0,skipped:[]},c=new nd({color:new W(t.edgeColor??`#1f2937`),transparent:!0,opacity:.75,depthWrite:!1});i.userData.hasNativeEdges=!1;let l=t=>{let n=e.textures?.[t];return n?.packKey?`${t}#${n.packKey}`:t};for(let[t,n]of Object.entries(e.textures??{})){let e=l(t),i=r.get(e);if(i){let t=i.image;if((t?.width??0)*(t?.height??0)>=(n.width??0)*(n.height??0))continue;r.delete(e)}let{texture:a,decoded:c}=await ab(n);a?(r.set(e,a),o.push(e),s.textures++):s.skipped.push(`texture ${t} → ${c}`)}let u=Yx(e.materials),d=e=>u.findIndex(t=>Zx(Xx(t))===e),f=(e,i=!1,a=!1,o=1)=>{let s=Xx(u.find(t=>Zx(Xx(t))===e)),c=Qx(s),d=c[0],f=d?r.get(l(Zx(d)??d.id??``))??null:null,p=c[1],m=globalThis.__S3M_NO_BAKE===!0,h=i&&p&&!m?r.get(l(Zx(p)??p.id??``))??null:null,g=d?.texmodmatrix??d?.matrix;if(f&&Array.isArray(g)&&g.length===16&&!$x(g)&&(f=f.clone(),f.matrixAutoUpdate=!1,f.matrix.set(g[0],g[4],g[12],g[1],g[5],g[13],0,0,1)),f&&d?.addressmode){let e=d.addressmode.u,t=d.addressmode.v;(e!==void 0||t!==void 0)&&(f.matrixAutoUpdate&&(f=f.clone()),e!==void 0&&(f.wrapS=e===0?zr:Br),t!==void 0&&(f.wrapT=t===0?zr:Br))}let _=s?.diffuse??{r:1,g:1,b:1,a:1},v=[d,p].some(e=>/\.water$/i.test(String(Zx(e)??e?.id??``))),y=ex({alphaMode:s?.alphaMode,diffuseAlpha:_.a??1,transparentSorting:s?.transparentsorting===!0,vertexAlphaMin:o,isWaterWithoutMap:v&&!f}),b=typeof s?.shininess==`number`&&s.shininess>0?Math.max(.15,1-s.shininess/128):.95,x=f?.userData?.s3mHasAlpha?Math.max(s?.alphaCutoff??0,.01):0,S=Tb({uniforms:n,map:f,color:v&&!f?iS.clone():new W(_.r??1,_.g??1,_.b??1),side:eS(s),transparent:y,opacity:v&&!f?.86:_.a??1,roughness:v&&!f?.12:b,alphaTest:x,atlas:i&&!!f,texCoordZ:a&&!!f,secMap:h});return t.polygonOffset&&(S.polygonOffset=!0,S.polygonOffsetFactor=t.polygonOffset.factor,S.polygonOffsetUnits=t.polygonOffset.units),S},p=t.assembled??bx(e,{batching:t.batching!==!1,dedupeCoincident:t.dedupeCoincident});s.vertices=p.stats.vertices,s.edgeLines=p.stats.edgeLines,s.instanced=p.stats.instanced,p.stats.originalMeshes!=null&&(s.originalMeshes=p.stats.originalMeshes),s.skipped.push(...p.stats.skipped);let m=new U,h=e=>{let t=new q;for(let[n,r]of Object.entries(e.attributes))r&&t.setAttribute(n,new G(r.array,r.components,r.normalized));return e.index?t.setIndex(new G(e.index,1)):t.setDrawRange(0,e.vertexCount),t.boundingBox=new yo(new H(...e.bounds.boxMin),new H(...e.bounds.boxMax)),t.boundingSphere=new Io(new H(...e.bounds.sphereCenter),e.bounds.sphereRadius),t};for(let n of p.primitives){let r=h(n),o=e.geoPackage[n.geoNames[0]]??null,l=o?.vertexPackage,u=f(n.passNames[0],!!n.attributes.aAtlasRect,!!n.attributes.aTexCoordZ,tx(n.attributes.aColor)),p=n.matrix&&n.matrix.length===16?new U().fromArray(n.matrix):null;if(Hx(n.primitiveType)){let e=new pd(r,c);e.visible=t.edges===!0,e.renderOrder=aS,e.raycast=()=>{},e.userData.isEdgeLines=!0,e.userData.skeletonName=n.skeletonName,p&&!p.equals(m)&&p.decompose(e.position,e.quaternion,e.scale),i.add(e),a.push(e),i.userData.hasNativeEdges=!0;continue}if(Ux(n.primitiveType)){let t=l?Kx(n,l):null;if(t){let r=new zu(t.geo,Wx(),t.geo.instanceCount);r.raycast=Nx,r.frustumCulled=!1,r.renderOrder=oS,t.sigma>0&&(s.splatSigma=Math.max(s.splatSigma??0,t.sigma)),s.splatCount=(s.splatCount??0)+t.geo.instanceCount,r.userData.isPointCloud=!0,r.userData.isGaussianSplat=!0,r.userData.skeletonName=n.skeletonName,r.userData.geoRef=o,r.userData.tileRef=e,r.userData.primitiveType=n.primitiveType,p&&!p.equals(m)&&p.decompose(r.position,r.quaternion,r.scale),i.add(r),a.push(r),s.meshes++;continue}r.getAttribute(`color`)||r.setAttribute(`color`,r.getAttribute(`aColor`));let c=new bd(r,Jx());c.userData.isPointCloud=!0,c.userData.skeletonName=n.skeletonName,c.userData.geoRef=o,c.userData.tileRef=e,c.userData.primitiveType=n.primitiveType,p&&!p.equals(m)&&p.decompose(c.position,c.quaternion,c.scale),i.add(c),a.push(c),s.meshes++;continue}let g;if(l&&l.instanceIndex!==-1&&(l.instanceMode===16||l.instanceMode===17)&&l.instanceBuffer&&(l.instanceCount??0)>0&&l){if(!r.getAttribute(`aInstanceBatchId`)){let e=l.instanceBatchIds,t=e&&e.length===l.instanceCount?e.slice():new Float32Array(l.instanceCount).fill(-1);r.setAttribute(`aInstanceBatchId`,new ju(t,1));let n=new Float32Array(l.instanceCount);for(let e=0;e<n.length;e++)n[e]=e;r.setAttribute(`aInstanceIndex`,new ju(n,1))}let e=new zu(r,u,l.instanceCount);e.instanceMatrix.setUsage(Aa);let t=new U,n=new W,i=l.instanceMode,a=new Float32Array(l.instanceBuffer.buffer,l.instanceBuffer.byteOffset,l.instanceCount*i);for(let r=0;r<l.instanceCount;r++){let o=r*i;if(t.set(a[o+0],a[o+1],a[o+2],a[o+3],a[o+4],a[o+5],a[o+6],a[o+7],a[o+8],a[o+9],a[o+10],a[o+11],0,0,0,1),e.setMatrixAt(r,t),i>=16){let t=a[o+12],i=a[o+13],s=a[o+14];Number.isFinite(t)&&Number.isFinite(i)&&Number.isFinite(s)&&(n.setRGB(t,i,s),e.setColorAt(r,n))}}e.instanceMatrix.needsUpdate=!0,e.instanceColor&&(e.instanceColor.needsUpdate=!0),e.frustumCulled=!1,g=e}else g=new hc(r,u);p&&!p.equals(m)&&p.decompose(g.position,g.quaternion,g.scale),g.userData.skeletonName=n.skeletonName,g.userData.geoRef=o,g.userData.tileRef=e,g.userData.primitiveType=n.primitiveType;let _=d(n.passNames[0]);if(_>=0&&!u.transparent&&(g.renderOrder=Math.min(_,sS)),n.batchedFrom!=null&&n.batchedFrom>1){g.userData.isBatched=!0,g.userData.batchedCount=n.batchedFrom;let t=new Map;for(let r of n.geoNames){let n=e.geoPackage[r];if(n?.pickInfo)for(let e of Object.values(n.pickInfo))typeof e.batchId==`number`&&e.batchId>=0&&t.set(e.batchId,n)}t.size>0&&(g.userData.geoByBatchId=t)}i.add(g),a.push(g),s.meshes++,n.primitiveType===4&&(s.triangles+=n.indexCount/3)}i.children.length||s.skipped.push(`tile 无可用几何`);let g=0;for(let e of a){let t=e,n=t.geometry;if(n){if(n.attributes)for(let e of Object.values(n.attributes))e&&e.array&&(g+=e.array.byteLength);n.index&&n.index.array&&(g+=n.index.array.byteLength)}if(t.isInstancedMesh){let e=t;e.instanceMatrix&&e.instanceMatrix.array&&(g+=e.instanceMatrix.array.byteLength),e.instanceColor&&e.instanceColor.array&&(g+=e.instanceColor.array.byteLength)}}return s.memory=g,i.userData.textureKeys=o,{group:i,stats:s,objects:a,textureKeys:o}}var nS,rS,iS,aS,oS,sS,cS=a((()=>{sh(),fb(),Qb(),nx(),Cx(),Ax(),Bx(),z_(),nS=null,rS=null,iS=new W(1920611),aS=1e3,oS=1001,sS=999}));mh();function lS(e){return e.slice(0,e.lastIndexOf(`/`)+1)}function uS(e){if(!e)return e;try{let t=typeof document<`u`?document.baseURI:void 0;return t?new URL(e,t).href:new URL(e).href}catch{return e}}function dS(e,t){if(!t)return null;try{return fS(new URL(t,e).href)}catch{return fS(`${lS(e)}${t}`)}}function fS(e){if(!/[+ ]/.test(e))return e;let t=e.indexOf(`#`),n=t<0?``:e.slice(t),r=t<0?e:e.slice(0,t),i=r.indexOf(`?`),a=i<0?r:r.slice(0,i),o=i<0?``:r.slice(i);return`${a.replace(/\+/g,`%2B`).replace(/ /g,`%20`)}${o}${n}`}var pS=110540,mS=111320;function hS(e){if(!e||typeof e!=`object`)return null;let t=e;if(![t.left,t.bottom,t.right,t.top].every(e=>typeof e==`number`&&Number.isFinite(e)))return null;let{left:n,bottom:r,right:i,top:a}=t;return Math.abs(n)>180||Math.abs(i)>180||Math.abs(a)>90||Math.abs(r)>90||i===n&&a===r?null:{left:n,bottom:r,right:i,top:a}}function gS(e,t){if(!t)return null;let n=t.replace(/\.(osgb|s3mb|s3m)$/i,`.s3m`),r=e.split(`/`),i=r.pop()??``,a=r.pop()??``,o=r.lastIndexOf(`datas`);return!i||!a||o<1?dS(lS(e),n):fS(`${r[r.length-1]===`path`&&r[r.length-2]===`data`?`${r.join(`/`)}/${a}`:`${r.join(`/`)}/data/path/${a}`}/${n}`)}function _S(e){let t=e.trim();if(t.startsWith(`<`)){let e=e=>{let n=RegExp(`<(?:[a-zA-Z0-9_-]+:)?${e}[^>]*>([^<]+)<\\/`,`i`).exec(t);return n?n[1].trim():null},n=t=>parseFloat(e(t)??``),r=n(`X`)||0,i=n(`Y`)||0,a=n(`Z`)||0,o=n(`Left`),s=n(`Right`),c=n(`Top`),l=n(`Bottom`);if(![o,s,c,l].every(Number.isFinite)){let e=n(`MinX`),t=n(`MaxX`),a=n(`MinY`),u=n(`MaxY`);if([e,t,a,u].every(Number.isFinite)&&r&&i){let n=mS*Math.cos(i*Math.PI/180);n>1e-6&&(o=r+e/n,s=r+t/n,l=i+a/pS,c=i+u/pS)}}let u=t.matchAll(/<(?:[a-zA-Z0-9_-]+:)?FileName[^>]*>([^<]+)<\//gi),d=[];for(let e of u)d.push({url:e[1].trim()});let f=n(`MinHeight`),p=n(`MaxHeight`);return{fileType:e(`FileType`)??void 0,position:{x:r,y:i,z:a,units:`Degree`},geoBounds:{left:o,right:s,top:c,bottom:l},heightRange:Number.isFinite(f)||Number.isFinite(p)?{min:f,max:p}:void 0,rootTiles:d,tiles:d}}return JSON.parse(t)}function vS(e){if(!e)return 0;if(Array.isArray(e.mipmaps)&&e.mipmaps.length>0){let t=0;for(let n of e.mipmaps)n?.data?.byteLength&&(t+=n.data.byteLength);if(t>0)return t}let t=e.image;if(!t)return 0;if(t.data&&typeof t.data.byteLength==`number`)return t.data.byteLength;let n=t.width??0,r=t.height??0;if(n>0&&r>0){let t=e.generateMipmaps?1.3333333333333333:1;return Math.round(n*r*4*t)}return 0}function yS(e){let t=0;return e?(e.traverse?.(e=>{let n=e.geometry;if(n){if(n.attributes)for(let e of Object.values(n.attributes))e?.array?.byteLength&&(t+=e.array.byteLength);n.index?.array?.byteLength&&(t+=n.index.array.byteLength)}e.isInstancedMesh&&(e.instanceMatrix?.array?.byteLength&&(t+=e.instanceMatrix.array.byteLength),e.instanceColor?.array?.byteLength&&(t+=e.instanceColor.array.byteLength))}),t):0}var bS=class{get heightRange(){let e=this.config?.heightRange;return e&&typeof e.min==`number`&&typeof e.max==`number`?{min:e.min,max:e.max}:null}constructor(e){X(this,`configUrl`,void 0),X(this,`config`,null),X(this,`_blockTileIndex`,null),X(this,`anchor`,{lon:0,lat:0,height:0}),X(this,`rootUrls`,[]),X(this,`nodes`,new Map),X(this,`failed`,new Set),X(this,`textureCache`,new Map),X(this,`maxImageCache`,void 0),X(this,`_textureRefs`,new Map),X(this,`_tileTextureKeys`,new Map),X(this,`pending`,new Set),X(this,`atlasLod`,void 0),X(this,`atlasLodCache`,new Map),X(this,`_groupCache`,new Map),X(this,`externalAtlasCache`,new Map),X(this,`leafRequestCache`,new Map),X(this,`_leafPending`,new Map),X(this,`atlasUpgraded`,new Set),X(this,`atlasUpgradeSkipped`,new Map),X(this,`stats`,{tiles:0,loading:0,failed:0,meshes:0,vertices:0,triangles:0,datasets:1,drawCalls:0,programs:0,textures:0,geometries:0,degradations:[]}),X(this,`maxConcurrent`,void 0),X(this,`maxTiles`,void 0),X(this,`maxTriangles`,void 0),X(this,`maxMemory`,void 0),X(this,`lodRangeScale`,void 0),X(this,`_onTile`,void 0),X(this,`_onTileRemoved`,void 0),X(this,`_onError`,void 0),X(this,`_onProgress`,void 0),X(this,`_maxRetries`,void 0),X(this,`authenticate`,void 0),X(this,`_unsupported`,void 0),X(this,`_retryCount`,new Map),X(this,`_retryAt`,new Map),X(this,`_parentOf`,new Map),X(this,`_frame`,0),X(this,`_permanentReported`,!1),X(this,`hardCap`,96),X(this,`isS3MV1`,!1),X(this,`_buildTile`,void 0),X(this,`_polygonOffset`,void 0),X(this,`_uniforms`,void 0),X(this,`_workerClient`,void 0),X(this,`_useWorker`,void 0),X(this,`_queue`,[]),X(this,`_active`,0),this.configUrl=e.configUrl,this.lodRangeScale=e.lodRangeScale??3,this._onTile=e.onTile??(()=>{}),this._onTileRemoved=e.onTileRemoved??(()=>{}),this._onError=e.onError??(e=>console.warn(e)),this._onProgress=e.onProgress??(()=>{}),this._maxRetries=Math.max(0,e.maxRetries??2),this.authenticate=e.authenticate,this._unsupported=e.unsupported??`warn`,this._buildTile=e.buildTile??null,this._polygonOffset=e.polygonOffset,this._uniforms=e.uniforms??null,this._useWorker=e.useWorker!==!1,this.maxConcurrent=e.maxConcurrent??4,this.maxTiles=e.maxTiles??64,this.maxTriangles=e.maxTriangles??1/0,this.maxMemory=Number.isFinite(e.maxMemory)&&e.maxMemory>0?e.maxMemory:1/0,this.maxImageCache=e.maxImageCache??128,this.hardCap=this.maxTiles+Math.max(8,Math.ceil(this.maxTiles*.5)),this.atlasLod=e.atlasLod!==!1}async init(){this.configUrl=uS(this.configUrl);let e=await E_(this.configUrl,this.authenticate,`config`);if(!e.ok)throw Error(`配置读取失败 ${e.status} ${this.configUrl}`);let t=_S(await e.text());this.config=t,this.anchor=this._resolveAnchor(t);let n=t.rootTiles??t.tiles??[];if(!n.length)throw Error(`配置中缺少 root tile`);this.rootUrls.length=0;for(let e of n){let t=dS(this.configUrl,e.url);t&&this.rootUrls.push(t)}if(this.isS3MV1=/OSGB/i.test(String(t.fileType??``))||/OSGB/i.test(String(t.dataType??``))||this.rootUrls.length>0&&this.rootUrls.every(e=>/\.s3m($|\?)/i.test(e)),this.rootUrls.every(e=>/\.s3mblock($|\?)/i.test(e))){this._blockTileIndex=new Set(this.rootUrls);for(let e of n){let t=dS(this.configUrl,e.url);t&&this._blockTileIndex.add(t)}}await this._load(this.rootUrls[0]);for(let e of this.rootUrls.slice(1))this._enqueue(e);return this}_enqueue(e,t){if(!e||(t&&this._parentOf.set(e,t),this.nodes.has(e)||this.pending.has(e)||this.failed.has(e))||this._queue.includes(e))return;let n=this._retryAt.get(e);n!==void 0&&performance.now()<n||this.nodes.size+this.pending.size+this._queue.length>=this.hardCap||(this._queue.push(e),this._pump())}registerTileTextures(e,t){this._tileTextureKeys.set(e,t);let n=this.nodes.get(e);n&&(n.textureKeys=t);for(let e of t)this._textureRefs.set(e,(this._textureRefs.get(e)??0)+1)}_evictTileNode(e){this.nodes.delete(e.url),e.group?.parent?.remove(e.group),this._onTileRemoved(e),this._parentOf.delete(e.url),this.stats.tiles=Math.max(0,this.stats.tiles-1),e.stats&&(this.stats.meshes=Math.max(0,this.stats.meshes-(e.stats.meshes??0)),this.stats.vertices=Math.max(0,this.stats.vertices-(e.stats.vertices??0)),this.stats.triangles=Math.max(0,this.stats.triangles-(e.stats.triangles??0)));let t=e.textureKeys??this._tileTextureKeys.get(e.url)??e.group?.userData?.textureKeys;if(this._tileTextureKeys.delete(e.url),t?.length)for(let e of t){let t=(this._textureRefs.get(e)??1)-1;if(t<=0){this._textureRefs.delete(e);let t=this.textureCache.get(e);t&&(t.dispose?.(),this.textureCache.delete(e))}else this._textureRefs.set(e,t)}}putExternalAtlas(e,t){if(this.externalAtlasCache.size>=this.maxImageCache&&!this.externalAtlasCache.has(e)){let e=this.externalAtlasCache.keys().next().value;e!==void 0&&this.externalAtlasCache.delete(e)}Map.prototype.set.call(this.externalAtlasCache,e,t)}getExternalAtlas(e){return this.externalAtlasCache.get(e)}putLeafRecords(e,t){if(this.leafRequestCache.size>=this.maxImageCache&&!this.leafRequestCache.has(e)){let e=this.leafRequestCache.keys().next().value;e!==void 0&&this.leafRequestCache.delete(e)}Map.prototype.set.call(this.leafRequestCache,e,t)}getLeafRecords(e){return this.leafRequestCache.get(e)}_evictOne(e=!1){let t=this._pickVictim(!0,e)??this._pickVictim(!1,e);if(!t)return!1;let n=t.parentUrl??this._parentOf.get(t.url),r=t.childUrls??(t.childUrl?[t.childUrl]:[]);r.some(e=>e!==t.url&&this.nodes.has(e)),this._evictTileNode(t);let i=r.filter(e=>e!==t.url&&this.nodes.has(e));if(i.length){for(let e of i){let t=this.nodes.get(e);t&&(t.parentUrl=n??void 0,n?this._parentOf.set(e,n):this._parentOf.delete(e))}if(n){let e=this.nodes.get(n);if(e){let n=new Set(e.childUrls??[]);e.childUrl&&n.add(e.childUrl),n.delete(t.url);for(let e of i)n.add(e);e.childUrls=[...n],e.childUrl=e.childUrls[0]??null}}}return!0}_residentTriangles(){let e=0;for(let t of this.nodes.values())e+=t.stats?.triangles??0;return e}setMaxTriangles(e){this.maxTriangles=e>0?e:1/0}setMaxMemory(e){this.maxMemory=Number.isFinite(e)&&e>0?e:1/0}residentMemory(){return this._residentGeometryBytes()+this._residentTextureBytes()}_residentGeometryBytes(){let e=0;for(let t of this.nodes.values())t.stats&&typeof t.stats.memory==`number`?e+=t.stats.memory:t.group&&(e+=yS(t.group));return e}_residentTextureBytes(){let e=0;for(let t of this.textureCache.values())e+=vS(t);return e}_trimBudget(){let e=!1,t=0,n=()=>this.nodes.size+this.pending.size>this.maxTiles,r=()=>Number.isFinite(this.maxTriangles)&&this._residentTriangles()>this.maxTriangles,i=()=>Number.isFinite(this.maxMemory)&&this.residentMemory()>this.maxMemory,a=this.nodes.size+this.maxTiles+16;for(;(n()||r()||i())&&t++<=a&&this._evictOne(this.nodes.size+this.pending.size>this.hardCap);)e=!0;return e}_pickVictim(e,t=!1){let n=null;for(let r of this.nodes.values()){let i=r.childUrls??(r.childUrl?[r.childUrl]:[]);if((i.length>0&&i.some(e=>e!==r.url&&this.nodes.has(e)))!==e||!t&&r.group.visible&&!i.some(e=>{let t=this.nodes.get(e);return!!t&&t.group.visible}))continue;if(!n){n=r;continue}let a=r.lastSeen??-1,o=n.lastSeen??-1;(a<o||a===o&&(r.distance??0)>(n.distance??0))&&(n=r)}return n}retryFailed(){let e=this.failed.size;return this.failed.clear(),this._retryCount.clear(),this._retryAt.clear(),e}_pump(){for(;this._active<this.maxConcurrent&&this._queue.length;){let e=this._queue.shift();this._active++,this._load(e).finally(()=>{this._active--,this._pump()})}}_resolveAnchor(e){let t=e.position,n=t?.point3D??t,r=!!n&&Number.isFinite(n.x)&&Number.isFinite(n.y),i=hS(e.geoBounds),a=i?(i.left+i.right)/2:void 0,o=i?(i.bottom+i.top)/2:void 0,s=n?.z??0;if(!r)return{lon:a??0,lat:o??0,height:0};if((t?.units??t?.unit??`Degree`)!==`Degree`)return{lon:n.x,lat:n.y,height:s};let c=a===void 0?0:Math.abs(n.x-a),l=o===void 0?0:Math.abs(n.y-o);return c>.5||l>.5?(console.warn(`[s3m] position 与 geoBounds 不一致,改用 geoBounds 中心作为锚点`,{position:n,geoBounds:i}),{lon:a,lat:o,height:s}):{lon:n.x,lat:n.y,height:s}}_pickLod(e){let t=e.groupNode?.pageLods??[];return t.length?t.find(e=>e.childTile&&e.rangeValue>0)??t[0]:null}async _builder(){if(!this._buildTile){let e=await Promise.resolve().then(()=>(cS(),Vx));this._buildTile=e.buildTileObjects}return this._buildTile}async _parseClassicTile(e){if(this._useWorker&&this._workerClient===void 0&&(this._workerClient=K_()),this._workerClient)try{return await this._workerClient.parseTile(e,!0)}catch(e){if(e instanceof U_)this._workerClient=null;else throw e}return{tile:await m_(e)}}_rememberGroups(e,t){for(this._groupCache.delete(e),this._groupCache.set(e,t);this._groupCache.size>24;){let e=this._groupCache.keys().next().value;if(e===void 0)break;this._groupCache.delete(e)}}async _fillExternalAtlases(e,t){let n=e,r=n.texturePackage;if(!r)return;let i=Sy(n),a=!1,o=new Map,s=new Map,c=[];for(let[e,t]of Object.entries(r)){let n=Ny(t.requestNames);if(n.names.length){o.set(e,{tex:t,plan:n});for(let[e,t]of n.packGroups){let n=t.filter(e=>!this.leafRequestCache.has(e));if(!n.length)continue;let r=s.get(e)??[];for(let e of n)r.includes(e)||r.push(e);s.set(e,r)}for(let e of n.plain)!this.leafRequestCache.has(e)&&!c.includes(e)&&c.push(e)}}let l=[];for(let[e,n]of s){let r=null,i=()=>r??(r=this._fetchLeafPack(t,e,n));for(let e of n)l.push(this._ensureLeafFetch(e,i))}for(let e of c)l.push(this._ensureLeafFetch(e,()=>this._fetchLeafFile(t,e)));l.length&&await Promise.all(l);for(let[e,{tex:t,plan:n}]of o){let r=new Map;for(let e of n.names){let t=this.leafRequestCache.get(e);if(t)for(let n of t)r.set(n.id,{source:e,image:n})}let i=Py(t,r);if(i){let n=t;n.composed=!0,n.leafSig=i.sig,n.flipY=!1,t.data=i.data,t.compressType=0,t.pixelFormat=28,t.width=i.width,t.height=i.height,t.rectScale=1,this.atlasUpgraded.add(e),a=!0,(i.missing.length||i.mismatched.length)&&console.warn(`[s3m] leaf 图集部分精灵异常:`,e,{missing:i.missing,mismatched:i.mismatched});continue}let o=!!t.data,s=n=>{if(!o){let r=t.width/t.height,i=n.width/n.height;return Math.abs(i/r-1)<=.02||(this.atlasUpgradeSkipped.set(e,`aspect(no-baseline) ${t.width}x${t.height} vs ${n.width}x${n.height}`),!1)}let r=Ry(t,n);return r.ok?!0:(this.atlasUpgradeSkipped.set(e,`${r.reason} aspectΔ=${(r.aspectDelta*100).toFixed(1)}% scale=${r.scale} err=${Number.isNaN(r.meanAbsError)?`n/a`:r.meanAbsError.toFixed(1)}`),!1)},c=n=>{let r=t;r.composed=!1,r.leafSig=void 0,r.flipY=!0,t.data=n.data,t.compressType=n.compressType,t.pixelFormat=n.pixelFormat,t.rectScale=t.width>0?n.width/t.width:1,t.width=n.width||t.width,t.height=n.height||t.height,this.atlasUpgraded.add(e),a=!0},l=this.externalAtlasCache.get(e);if(l!==null){if(l===void 0){l=null;for(let e of n.plain){let t=this.leafRequestCache.get(e);if(t?.length){l=t[0];break}}this.putExternalAtlas(e,l)}l?s(l)&&c(l):this.atlasUpgradeSkipped.has(e)||this.atlasUpgradeSkipped.set(e,`no usable external image(请求失败或只拿到子精灵)`)}}(i||a)&&Cy(n)}_ensureLeafFetch(e,t){if(this.leafRequestCache.has(e))return Promise.resolve();let n=this._leafPending.get(e);if(n)return n;let r=t().finally(()=>this._leafPending.delete(e));return this._leafPending.set(e,r),r}async _fetchLeafPack(e,t,n){let r=dS(lS(e),`${n[0]}.texblock?extratiles=${n.join(`;`)}`);try{if(!r)throw Error(`无法拼出 URL`);let e=await E_(r,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await Ey(await e.arrayBuffer());if(t.length!==n.length)throw Error(`pack 段数 ${t.length} ≠ 请求名 ${n.length}`);n.forEach((e,n)=>this.putLeafRecords(e,t[n]))}catch(e){console.warn(`[s3m] leaf pack 请求失败:`,r,e);for(let e of n)this.leafRequestCache.has(e)||this.putLeafRecords(e,null)}}async _fetchLeafFile(e,t){let n=dS(lS(e),`${t}.texblock`);try{if(!n)throw Error(`无法拼出 URL`);let e=await E_(n,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let r=(await Ey(await e.arrayBuffer())).flat();this.putLeafRecords(t,r)}catch(e){console.warn(`[s3m] leaf texblock 请求失败:`,n,e),this.leafRequestCache.has(t)||this.putLeafRecords(t,null)}}async _upgradeAtlasLod(e,t){}_noteDegradations(e){let t=e.degradations;if(!t?.length)return;let n=g_(t,this.stats.degradations,this._unsupported);this.stats.degradations=n.known;for(let e of n.messages)console.warn(e);if(n.error)throw n.error}async _load(e){if(!(this.nodes.has(e)||this.pending.has(e)||this.failed.has(e))){this.pending.add(e),this.stats.loading++;try{let t=e.indexOf(`#`),n=t>=0?e.slice(0,t):e,r=t>=0&&Number(e.slice(t+1))||0,i=/\.s3mblock($|\?)/i.test(n),a,o,s=[],c=this._groupCache.get(n);if(c)s=c.names,a=c.tiles[r]??c.tiles[0];else{let e=await E_(n,this.authenticate,`tile`);if(!e.ok)throw Error(`HTTP ${e.status} 加载瓦片失败: ${n}`);if((e.headers.get(`content-type`)||``).includes(`text/html`))throw Error(`瓦片请求返回了 HTML 页面(通常为 404/500 服务端拦截): ${n}`);let t=await e.arrayBuffer();if(i){let e=await Fy(t);this._rememberGroups(n,e),s=e.names,a=e.tiles[r]??e.tiles[0]}else{let e=await this._parseClassicTile(t);a=e.tile,o=e.geometry}}i&&(await this._fillExternalAtlases(a,n),await this._upgradeAtlasLod(a,n)),this._noteDegradations(a);let l=await(await this._builder())(a,{textureCache:this.textureCache,uniforms:this._uniforms,assembled:o,polygonOffset:this._polygonOffset}),{group:u,stats:d}=l,f=l.textureKeys??u.userData?.textureKeys??Object.keys(a.textures??{});this.registerTileTextures(e,f);let p=this._pickLod(a),m=[];for(let t of a.groupNode?.pageLods??[]){let r=String(t.childTile??``).replace(/\.s3mblock$/i,``),a=i&&r?s.indexOf(r):-1,o=a>=0?`${n}#${a}`:this.isS3MV1?gS(e,t.childTile):dS(lS(e),t.childTile);o&&o!==e&&!m.includes(o)&&m.push(o)}let h={url:e,tile:a,group:u,sphere:p?.boundingSphere??null,rangeValue:p?.rangeValue??0,rangeMode:p?.rangeMode??1,childUrl:m[0]??(this.isS3MV1?gS(e,p?.childTile):dS(lS(e),p?.childTile)),childUrls:m,parentUrl:this._parentOf.get(e),state:`ready`,...d.splatSigma?{splatSigma:d.splatSigma}:{},...d.splatCount?{splatCount:d.splatCount}:{},stats:{meshes:d.meshes??0,vertices:d.vertices??0,triangles:d.triangles??0,memory:d.memory??yS(u)}};this.nodes.set(e,h),this.stats.tiles++,this.stats.meshes+=d.meshes??0,this.stats.vertices+=d.vertices??0,this.stats.triangles+=d.triangles??0,this._onTile(h)}catch(t){let n=t?.permanent===!0,r=(this._retryCount.get(e)??0)+1;if(this._retryCount.set(e,r),!n&&r<=this._maxRetries)this._retryAt.set(e,performance.now()+800*r);else{this.stats.failed++,this.failed.add(e),this._retryAt.delete(e);let t=this._parentOf.get(e),n=t?this.nodes.get(t):void 0;n?.childUrls&&(n.childUrls=n.childUrls.filter(t=>t!==e),n.childUrl=n.childUrls[0]??null)}n?this._permanentReported||(this._permanentReported=!0,this._onError(t)):this._onError(t)}finally{this.pending.delete(e),this.stats.loading--,this._onProgress(this.stats)}}}update(e,t,n){this._frame++;let r=!1;for(let t of this.nodes.values()){var i;if(!t.sphere){t.needRefine=!1;continue}let a=t.sphere.center,o=a.x-e[0],s=a.y-e[1],c=a.z-e[2],l=Math.sqrt(o*o+s*s+c*c)||1e-6;t.distance=l;let u,d=t.rangeMode===0;u=d?l:n*.5/Math.tan(Math.PI/8)*(t.sphere.radius/l)*2;let f=this.lodRangeScale>0?this.lodRangeScale:1,p=t.rangeValue*f;(d?l<p*2:u>p*.5)&&(t.lastSeen=this._frame);let m=t.childUrls??(t.childUrl?[t.childUrl]:[]),h=t.needRefine?d?1.08:.92:1,g=t.splatSigma&&t.sphere?H_({splats:t.splatCount??t.stats?.vertices??0,radius:t.sphere.radius,distance:l,sigma:t.splatSigma,screenHeight:n,hasChild:m.length>0}):null,_=g?g.needRefine:m.length>0&&(d?u<p*h:u>p*h);t.needRefine=_;let v=(i=globalThis).__S3M_LOD_SEEN??(i.__S3M_LOD_SEEN=new Set);if(globalThis.__S3M_LOD_DEBUG&&!v.has(t.url)&&v.size<260&&(v.add(t.url),console.log(`[LOD]`,JSON.stringify({url:t.url.split(`/`).pop(),mode:t.rangeMode,rangeValue:t.rangeValue,radius:t.sphere.radius,dist:+l.toFixed(1),metric:+u.toFixed(1),threshold:+p.toFixed(1),needRefine:_,childUrls:m.map(e=>e.split(`/`).pop()),parent:t.parentUrl?t.parentUrl.split(`/`).pop():null}))),_)for(let e of m)this.failed.has(e)||this.nodes.has(e)||this.pending.has(e)||(this._enqueue(e,t.url),r=!0)}let a=new Set,o=new Set(this.rootUrls);for(let[e,t]of this.nodes){let n=t.parentUrl??this._parentOf.get(e);n&&this.nodes.has(n)||o.add(e)}for(let e of o)this._updateNodeVisibility(e,!0,a)&&(r=!0);for(let[e,t]of this.nodes)a.has(e)||t.group.visible&&(t.group.visible=!1,r=!0);this._trimBudget()&&(r=!0);let s=!1;for(let e of this.nodes.values())if(e.group.visible){s=!0;break}if(!s&&this.nodes.size>0)for(let e of this.nodes.values())!(e.childUrls??(e.childUrl?[e.childUrl]:[])).some(t=>{let n=this.nodes.get(t);return!!n&&n!==e&&n.group.visible})&&!e.group.visible&&(e.group.visible=!0,r=!0);return r}_updateNodeVisibility(e,t,n){let r=this.nodes.get(e);if(!r||n.has(e))return!1;n.add(e);let i=!1,a=r.childUrls??(r.childUrl?[r.childUrl]:[]);if(!t){r.group.visible&&(r.group.visible=!1,i=!0);for(let e of a)this._updateNodeVisibility(e,!1,n)&&(i=!0);return i}let o=a.length>0,s=a.filter(e=>this.nodes.has(e)),c=a.every(e=>this.nodes.has(e)||this.failed.has(e));if(r.needRefine&&o&&s.length>0&&c){r.group.visible&&(r.group.visible=!1,i=!0);for(let e of a)this._updateNodeVisibility(e,!0,n)&&(i=!0)}else{r.group.visible||(r.group.visible=!0,i=!0);for(let e of a)this._updateNodeVisibility(e,!1,n)&&(i=!0)}return i}dispose(){this._workerClient?.dispose();for(let e of this.nodes.values())e.group.traverse(e=>{let t=e;t.geometry?.dispose?.(),Array.isArray(t.material)?t.material.forEach(e=>e.dispose?.()):t.material?.dispose?.()});for(let e of this.textureCache.values())e.dispose?.();this.textureCache.clear(),this.nodes.clear()}};cS();var xS={ambientIntensity:.4,hemisphereIntensity:.8,keyLightIntensity:1,fillLightIntensity:.35},SS={ambientIntensity:.12,hemisphereIntensity:.2,keyLightIntensity:1.95,fillLightIntensity:.15},CS={default:xS,supermap:SS};function wS(e){return e&&Object.prototype.hasOwnProperty.call(CS,e)?CS[e]:xS}sh(),Qb(),fb(),mh();var TS={ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50},ES=class{get envRT(){return this._envRT}set envRT(e){this._envRT=e}constructor(e){X(this,`ctx`,void 0),X(this,`ambient`,null),X(this,`hemi`,null),X(this,`key`,null),X(this,`fill`,null),X(this,`_state`,void 0),X(this,`_envRT`,null),this.ctx=e,this._state={...TS};let t=e.options;t.lightingPreset&&t.lightingPreset!=="default"&&(Object.assign(this._state,wS(t.lightingPreset)),this.applyColorPipeline(t.lightingPreset)),t.light&&Object.assign(this._state,t.light)}_create(){this.ambient=new vp(this._state.ambientColor,this._state.ambientIntensity),this.hemi=new ip(this._state.hemisphereColor,this._state.hemisphereGroundColor,this._state.hemisphereIntensity),this.key=new _p(this._state.keyLightColor,this._state.keyLightIntensity),this.fill=new _p(this._state.fillLightColor,this._state.fillLightIntensity),this.update()}addToScene(){let e=this.ctx.scene();e&&(this.ambient||this._create(),e.add(this.ambient,this.hemi,this.key,this.fill))}get created(){return this.ambient!==null}_applyOptions(){let e=this._state;this.ambient&&(this.ambient.intensity=e.ambientIntensity,this.ambient.color.set(e.ambientColor)),this.hemi&&(this.hemi.intensity=e.hemisphereIntensity,this.hemi.color.set(e.hemisphereColor),this.hemi.groundColor.set(e.hemisphereGroundColor)),this.key&&(this.key.intensity=e.keyLightIntensity,this.key.color.set(e.keyLightColor)),this.fill&&(this.fill.intensity=e.fillLightIntensity,this.fill.color.set(e.fillLightColor))}update(){if(!this.key||!this.fill)return;let e=this._state,t=e.mode===`fixed`?0:(this.ctx.getBearing?.()??0)*Math.PI/180,n=(e,n,r)=>{if(!e)return;let i=t+n*Math.PI/180,a=r*Math.PI/180,o=Math.cos(a);e.position.set(Math.sin(i)*o,Math.cos(i)*o,Math.sin(a)).multiplyScalar(1e3)};n(this.key,e.azimuth,e.altitude),n(this.fill,e.azimuth+65,Math.max(10,e.altitude-20));let r=this.ctx.uniforms?.uSunDirection;r&&r.value.copy(this.key.position).normalize()}applyColorPipeline(e){let t=e===`supermap`;Sb(t?`direct`:`linear`),nb(!t),Zy(t?1:1/0)}setLightingPreset(e){Object.assign(this._state,wS(e)),this.applyColorPipeline(e),this.ctx.options.lightingPreset=e,this._applyOptions(),this.update(),this.ctx.repaint()}setLight(e){let t={...e};t.mainColor!==void 0&&t.keyLightColor===void 0&&(t.keyLightColor=t.mainColor),t.mainIntensity!==void 0&&t.keyLightIntensity===void 0&&(t.keyLightIntensity=t.mainIntensity),Object.assign(this._state,t),this._applyOptions(),this.update(),this.ctx.repaint()}getLight(){return{...this._state}}setToneMapping(e,t=1){this.ctx.options.toneMapping=e,this.ctx.options.toneMappingExposure=t;let n=this.ctx.renderer();n&&(n.toneMapping=e,n.toneMappingExposure=t,this.ctx.repaint())}getToneMapping(){let e=this.ctx.renderer();return{toneMapping:e?e.toneMapping:this.ctx.options.toneMapping??0,toneMappingExposure:e?e.toneMappingExposure:this.ctx.options.toneMappingExposure??1}}async setEnvironment(e,t=1){let n=this.ctx.renderer(),r=this.ctx.scene();if(!n||!r)return;if(r.environmentIntensity=Math.max(0,t),e==null){r.environment=null,this._envRT?.dispose(),this._envRT=null,this.ctx.repaint();return}let i=typeof e==`string`,a=i?await new np().loadAsync(e):e;a.mapping=303;let o=new nl(n);o.compileEquirectangularShader();let s=o.fromEquirectangular(a);o.dispose(),i&&a.dispose(),r.environment=s.texture,this._envRT?.dispose(),this._envRT=s,this.ctx.repaint()}dispose(){this._envRT?.dispose(),this._envRT=null}};sh(),mh();var DS=class{constructor(e){X(this,`uniforms`,void 0),X(this,`_meshHeight`,new Map),X(this,`_min`,1/0),X(this,`_max`,-1/0),X(this,`_box`,new yo),this.uniforms=e}get size(){return this._meshHeight.size}add(e){let t=e.geometry?.boundingBox;if(!t)return;this._box.copy(t).applyMatrix4(e.matrixWorld);let n=this._box.min.z,r=this._box.max.z;Number.isFinite(n)&&Number.isFinite(r)&&(this._meshHeight.set(e,{min:n,max:r}),n<this._min&&(this._min=n),r>this._max&&(this._max=r),this._push())}remove(e){let t=this._meshHeight.get(e);t&&(this._meshHeight.delete(e),t.min===this._min||t.max===this._max?this._recompute():this._push())}refreshAll(){if(this._meshHeight.size===0)return;let e=[...this._meshHeight.keys()];this._meshHeight.clear(),this._min=1/0,this._max=-1/0;for(let t of e)this.add(t);this._push()}clear(){this._meshHeight.clear(),this._min=1/0,this._max=-1/0}get range(){return{min:this._min,max:this._max}}_recompute(){let e=1/0,t=-1/0;for(let n of this._meshHeight.values())n.min<e&&(e=n.min),n.max>t&&(t=n.max);this._min=e,this._max=t,this._push()}_push(){let e=this._min,t=this._max;(!Number.isFinite(e)||!Number.isFinite(t)||t<=e)&&(e=0,t=100),this.uniforms.uHeightMin.value=e,this.uniforms.uHeightMax.value=t}},OS=new Uint32Array,kS=new Uint32Array,AS=new Uint32Array(256),jS=new Float32Array(1),MS=new Uint32Array(jS.buffer);function NS(e){jS[0]=e;let t=MS[0];return t&2147483648?~t>>>0:(t|2147483648)>>>0}function PS(e,t,n,r){let i=r&&r.length>=t?r:new Uint32Array(t);if(t<=1)return t===1&&(i[0]=0),i;OS.length<t&&(OS=new Uint32Array(t)),kS.length<t&&(kS=new Uint32Array(t));let a=OS,o=kS,s=n.elements,c=s[2],l=s[6],u=s[10],d=s[14];for(let n=0;n<t;n++)a[n]=NS(c*e[n*3]+l*e[n*3+1]+u*e[n*3+2]+d),i[n]=n;let f=i,p=o;for(let e=0;e<4;e++){let n=e*8;AS.fill(0);for(let e=0;e<t;e++)AS[a[f[e]]>>>n&255]++;let r=0;for(let e=0;e<256;e++){let t=AS[e];AS[e]=r,r+=t}for(let e=0;e<t;e++){let t=f[e];p[AS[a[t]>>>n&255]++]=t}let i=f;f=p,p=i}return f!==i&&i.set(f),i}sh();var IS=[`iCenter`,`iScale`,`iQuat`,`iColor`],LS=new U,RS=new WeakMap,zS=new WeakMap;function BS(e,t){let n=e.geometry,r=n.getAttribute(`iCenter`);if(!r)return!1;let i=Math.min(n.instanceCount??1/0,r.count);if(i<=1)return!1;LS.multiplyMatrices(t,e.matrixWorld);let a=zS.get(r);(!a||a.length<i)&&(a=new Uint32Array(i),zS.set(r,a)),PS(r.array,i,LS,a);let o=!0;for(let e=0;e<i;e++)if(a[e]!==e){o=!1;break}if(o)return!1;for(let e of IS){let t=n.getAttribute(e);if(!t)continue;let r=t.array,o=t.itemSize,s=i*o,c=RS.get(t);(!c||c.length<s)&&(c=new r.constructor(s),RS.set(t,c));for(let e=0;e<i;e++){let t=a[e]*o,n=e*o;for(let e=0;e<o;e++)c[n+e]=r[t+e]}r.set(c.subarray(0,s)),t.needsUpdate=!0}return!0}sh(),mh();var VS=class{constructor(){X(this,`_lastView`,new U),X(this,`_sorted`,!1)}markDirty(){this._sorted=!1}sort(e,t){if(e&&!(this._sorted&&this._lastView.equals(e.matrixWorldInverse))){for(let n of t)n.userData.isGaussianSplat&&BS(n,e.matrixWorldInverse);this._lastView.copy(e.matrixWorldInverse),this._sorted=!0}}reset(){this._sorted=!1,this._lastView.identity()}};sh(),Qb(),_b();function HS(){return{uResolution:{value:new B(1,1)},uDpr:{value:1}}}var US=`
4766
4766
  attribute vec3 aOther;
4767
4767
  attribute float aSide;
4768
4768
  attribute float aBatchId;
@@ -4901,7 +4901,7 @@ void main() {
4901
4901
 
4902
4902
  gl_Position = vec4( ndc * clipA.w, clipA.z, clipA.w );
4903
4903
  }
4904
- `,HS=`
4904
+ `,WS=`
4905
4905
  uniform vec3 uColor;
4906
4906
  uniform float uOpacity;
4907
4907
 
@@ -4909,14 +4909,14 @@ void main() {
4909
4909
  if ( uOpacity <= 0.003 ) discard;
4910
4910
  gl_FragColor = vec4( uColor, uOpacity );
4911
4911
  }
4912
- `;function US(e,t={},n,r){let i=n??{uColor:{value:new W(t.color??`#ffffff`)},uOpacity:{value:t.opacity??1},uWidth:{value:t.width??1.5},uElevation:{value:t.elevation??0}};t.color!==void 0&&n&&i.uColor.value.set(t.color),t.opacity!==void 0&&n&&(i.uOpacity.value=t.opacity),t.width!==void 0&&n&&(i.uWidth.value=t.width);let a={uBatchTex:r?.uBatchTex??{value:Lb},uBatchTex2:r?.uBatchTex2??{value:Lb},uBatchMix:r?.uBatchMix??{value:0},uBatchTexWidth:r?.uBatchTexWidth??{value:1},uBatchTexActive:r?.uBatchTexActive??{value:0},uPathTex:r?.uPathTex??{value:gb.DUMMY_PATH_TEX},uPathCount:r?.uPathCount??{value:1},uPathTexActive:r?.uPathTexActive??{value:0},uPathTime:r?.uPathTime??{value:0}},o=new bc({uniforms:{uResolution:e.uResolution,uDpr:e.uDpr,uColor:i.uColor,uOpacity:i.uOpacity,uWidth:i.uWidth,uElevation:i.uElevation??{value:t.elevation??0},uOffset:i.uOffset??{value:0},uTranslation:{value:new H(0,0,0)},uBatchTex:a.uBatchTex,uBatchTex2:a.uBatchTex2,uBatchMix:a.uBatchMix,uBatchTexWidth:a.uBatchTexWidth,uBatchTexActive:a.uBatchTexActive,uPathTex:a.uPathTex,uPathCount:a.uPathCount,uPathTexActive:a.uPathTexActive,uPathTime:a.uPathTime},vertexShader:VS,fragmentShader:HS,transparent:!0,depthWrite:!1,side:2,polygonOffset:!0,polygonOffsetFactor:-2,polygonOffsetUnits:-2});return o.userData.isThickLine=!0,o}function WS(e,t,n){let r=Math.floor(e.length/6),i=r*4,a=new Float32Array(i*3),o=new Float32Array(i*3),s=new Float32Array(i),c=new Float32Array(i),l=new Float32Array(i*3),u=i>65535?new Uint32Array(r*6):new Uint16Array(r*6);for(let i=0;i<r;i++){let r=i*6,a=e[r],o=e[r+1],s=e[r+2],f=e[r+3],p=e[r+4],m=e[r+5],h=t?Number(t[i]??-1):-1,g=n?Number(n[r]??0):0,_=n?Number(n[r+1]??0):0,v=n?Number(n[r+2]??0):0,y=i*4;d(y,a,o,s,f,p,m,-1),d(y+1,a,o,s,f,p,m,1),d(y+2,f,p,m,a,o,s,1),d(y+3,f,p,m,a,o,s,-1);for(let e=0;e<4;e++){c[y+e]=h;let t=(y+e)*3;l[t]=g,l[t+1]=_,l[t+2]=v}let b=i*6;u[b]=y,u[b+1]=y+1,u[b+2]=y+2,u[b+3]=y,u[b+4]=y+2,u[b+5]=y+3}function d(e,t,n,r,i,c,l,u){let d=e*3;a[d]=t,a[d+1]=n,a[d+2]=r,o[d]=i,o[d+1]=c,o[d+2]=l,s[e]=u}let f=new q;return f.setAttribute(`position`,new G(a,3)),f.setAttribute(`aOther`,new G(o,3)),f.setAttribute(`aSide`,new G(s,1)),f.setAttribute(`aBatchId`,new G(c,1)),f.setAttribute(`aNormal`,new G(l,3)),f.setIndex(new G(u,1)),f.computeBoundingSphere(),f}function GS(e,t){let n=e.getAttribute(`position`),r=e.getAttribute(`aBatchId`);if(!n||!r||n.count===0||n.count!==r.count)return null;let i=1/Math.max(t,1e-9),a=new Map;for(let e=0;e<n.count;e++){let t=KS(n.getX(e),n.getY(e),n.getZ(e),i);a.has(t)||a.set(t,r.getX(e))}return a.size>0?a:null}function KS(e,t,n,r){return`${Math.round(e*r)},${Math.round(t*r)},${Math.round(n*r)}`}var qS=6e4,JS=100;function YS(e,t,n=40,r){let i=e.getAttribute(`position`);if(!i)return null;let a=i.count;if(a<3)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Float32Array(a);for(let e=0;e<a;e++)o[e]=i.getX(e),s[e]=i.getY(e),c[e]=i.getZ(e);let l=null,u=null;if(!e.index){let e=new Map;l=new Uint32Array(a),u=new Uint32Array(a);let t=0;for(let n=0;n<a;n++){let r=`${Math.round(o[n]*JS)},${Math.round(s[n]*JS)},${Math.round(c[n]*JS)}`,i=e.get(r);i===void 0&&(i=t++,e.set(r,i),u[i]=n),l[n]=i}}let d=e=>l?l[e]:e,f=e=>u?u[e]:e,p=e.index,m=p?p.array:null,h=Math.floor(p?p.count/3:a/3);if(h<1)return null;let g=null;if(t&&t.length>0){g=new Uint8Array(a);for(let e of t){let t=Math.max(0,e.vertexOffset|0),n=Math.min(a,t+(e.vertexCount|0));n>t&&g.fill(1,t,n)}if(!g.includes(1))return null}let _=new Float32Array(h*3),v=new Map,y=a+1,b=[],x=Math.cos(n*Math.PI/180),S=-1,C=0,w=0,T=0,E=(e,t,n,i,a)=>{if(b.length>=qS*6)return!1;let l=f(e),u=f(t);return b.push(o[l],s[l],c[l],o[u],s[u],c[u]),r?.push(n,i,a,n,i,a),!0},D=(e,t)=>{if(e===t)return;let n=e<t?e:t,r=e<t?t:e,i=n*y+r,a=v.get(i);if(a===void 0)v.set(i,S);else if(!(a<0)){if(C*_[a*3]+w*_[a*3+1]+T*_[a*3+2]<x){let e=_[a*3]+C,t=_[a*3+1]+w,o=_[a*3+2]+T,s=Math.hypot(e,t,o);s>1e-9?(e/=s,t/=s,o/=s):(e=C,t=w,o=T),E(n,r,e,t,o),v.set(i,-1)}else v.set(i,-2)}};for(S=0;S<h;S++){let e=m?m[S*3]:S*3,t=m?m[S*3+1]:S*3+1,n=m?m[S*3+2]:S*3+2;if(g&&!(g[e]&&g[t]&&g[n]))continue;let r=o[t]-o[e],i=s[t]-s[e],a=c[t]-c[e],l=o[n]-o[e],u=s[n]-s[e],f=c[n]-c[e];C=i*f-a*u,w=a*l-r*f,T=r*u-i*l;let p=Math.hypot(C,w,T);p<1e-12||(C/=p,w/=p,T/=p,_[S*3]=C,_[S*3+1]=w,_[S*3+2]=T,D(d(e),d(t)),D(d(t),d(n)),D(d(n),d(e)))}for(let[e,t]of v){if(t<0)continue;let n=Math.floor(e/y);if(!E(n,e-n*y,_[t*3],_[t*3+1],_[t*3+2]))break}return b.length>0?new Float32Array(b):null}sh();function XS(e,t,n,r){return`${Math.round(e*r)},${Math.round(t*r)},${Math.round(n*r)}`}function ZS(e,t){let n=e.getAttribute(`position`);if(!n||n.count===0)return e;let r=1/Math.max(t,1e-9),i=new Map,a=[],o=new Int32Array(n.count);for(let e=0;e<n.count;e++){let t=n.getX(e),s=n.getY(e),c=n.getZ(e),l=XS(t,s,c,r),u=i.get(l);u===void 0&&(u=a.length/3,a.push(t,s,c),i.set(l,u)),o[e]=u}let s=e.getIndex(),c=s?s.count:n.count,l=new Uint32Array(c);for(let e=0;e<c;e++)l[e]=o[s?s.getX(e):e];let u=new q;return u.setAttribute(`position`,new K(a,3)),u.setIndex(new G(l,1)),u}sh(),mh();var QS=`
4912
+ `;function GS(e,t={},n,r){let i=n??{uColor:{value:new W(t.color??`#ffffff`)},uOpacity:{value:t.opacity??1},uWidth:{value:t.width??1.5},uElevation:{value:t.elevation??0}};t.color!==void 0&&n&&i.uColor.value.set(t.color),t.opacity!==void 0&&n&&(i.uOpacity.value=t.opacity),t.width!==void 0&&n&&(i.uWidth.value=t.width);let a={uBatchTex:r?.uBatchTex??{value:Lb},uBatchTex2:r?.uBatchTex2??{value:Lb},uBatchMix:r?.uBatchMix??{value:0},uBatchTexWidth:r?.uBatchTexWidth??{value:1},uBatchTexActive:r?.uBatchTexActive??{value:0},uPathTex:r?.uPathTex??{value:gb.DUMMY_PATH_TEX},uPathCount:r?.uPathCount??{value:1},uPathTexActive:r?.uPathTexActive??{value:0},uPathTime:r?.uPathTime??{value:0}},o=new bc({uniforms:{uResolution:e.uResolution,uDpr:e.uDpr,uColor:i.uColor,uOpacity:i.uOpacity,uWidth:i.uWidth,uElevation:i.uElevation??{value:t.elevation??0},uOffset:i.uOffset??{value:0},uTranslation:{value:new H(0,0,0)},uBatchTex:a.uBatchTex,uBatchTex2:a.uBatchTex2,uBatchMix:a.uBatchMix,uBatchTexWidth:a.uBatchTexWidth,uBatchTexActive:a.uBatchTexActive,uPathTex:a.uPathTex,uPathCount:a.uPathCount,uPathTexActive:a.uPathTexActive,uPathTime:a.uPathTime},vertexShader:US,fragmentShader:WS,transparent:!0,depthWrite:!1,side:2,polygonOffset:!0,polygonOffsetFactor:-2,polygonOffsetUnits:-2});return o.userData.isThickLine=!0,o}function KS(e,t,n){let r=Math.floor(e.length/6),i=r*4,a=new Float32Array(i*3),o=new Float32Array(i*3),s=new Float32Array(i),c=new Float32Array(i),l=new Float32Array(i*3),u=i>65535?new Uint32Array(r*6):new Uint16Array(r*6);for(let i=0;i<r;i++){let r=i*6,a=e[r],o=e[r+1],s=e[r+2],f=e[r+3],p=e[r+4],m=e[r+5],h=t?Number(t[i]??-1):-1,g=n?Number(n[r]??0):0,_=n?Number(n[r+1]??0):0,v=n?Number(n[r+2]??0):0,y=i*4;d(y,a,o,s,f,p,m,-1),d(y+1,a,o,s,f,p,m,1),d(y+2,f,p,m,a,o,s,1),d(y+3,f,p,m,a,o,s,-1);for(let e=0;e<4;e++){c[y+e]=h;let t=(y+e)*3;l[t]=g,l[t+1]=_,l[t+2]=v}let b=i*6;u[b]=y,u[b+1]=y+1,u[b+2]=y+2,u[b+3]=y,u[b+4]=y+2,u[b+5]=y+3}function d(e,t,n,r,i,c,l,u){let d=e*3;a[d]=t,a[d+1]=n,a[d+2]=r,o[d]=i,o[d+1]=c,o[d+2]=l,s[e]=u}let f=new q;return f.setAttribute(`position`,new G(a,3)),f.setAttribute(`aOther`,new G(o,3)),f.setAttribute(`aSide`,new G(s,1)),f.setAttribute(`aBatchId`,new G(c,1)),f.setAttribute(`aNormal`,new G(l,3)),f.setIndex(new G(u,1)),f.computeBoundingSphere(),f}function qS(e,t){let n=e.getAttribute(`position`),r=e.getAttribute(`aBatchId`);if(!n||!r||n.count===0||n.count!==r.count)return null;let i=1/Math.max(t,1e-9),a=new Map;for(let e=0;e<n.count;e++){let t=JS(n.getX(e),n.getY(e),n.getZ(e),i);a.has(t)||a.set(t,r.getX(e))}return a.size>0?a:null}function JS(e,t,n,r){return`${Math.round(e*r)},${Math.round(t*r)},${Math.round(n*r)}`}var YS=6e4,XS=100;function ZS(e,t,n=40,r){let i=e.getAttribute(`position`);if(!i)return null;let a=i.count;if(a<3)return null;let o=new Float32Array(a),s=new Float32Array(a),c=new Float32Array(a);for(let e=0;e<a;e++)o[e]=i.getX(e),s[e]=i.getY(e),c[e]=i.getZ(e);let l=null,u=null;if(!e.index){let e=new Map;l=new Uint32Array(a),u=new Uint32Array(a);let t=0;for(let n=0;n<a;n++){let r=`${Math.round(o[n]*XS)},${Math.round(s[n]*XS)},${Math.round(c[n]*XS)}`,i=e.get(r);i===void 0&&(i=t++,e.set(r,i),u[i]=n),l[n]=i}}let d=e=>l?l[e]:e,f=e=>u?u[e]:e,p=e.index,m=p?p.array:null,h=Math.floor(p?p.count/3:a/3);if(h<1)return null;let g=null;if(t&&t.length>0){g=new Uint8Array(a);for(let e of t){let t=Math.max(0,e.vertexOffset|0),n=Math.min(a,t+(e.vertexCount|0));n>t&&g.fill(1,t,n)}if(!g.includes(1))return null}let _=new Float32Array(h*3),v=new Map,y=a+1,b=[],x=Math.cos(n*Math.PI/180),S=-1,C=0,w=0,T=0,E=(e,t,n,i,a)=>{if(b.length>=YS*6)return!1;let l=f(e),u=f(t);return b.push(o[l],s[l],c[l],o[u],s[u],c[u]),r?.push(n,i,a,n,i,a),!0},D=(e,t)=>{if(e===t)return;let n=e<t?e:t,r=e<t?t:e,i=n*y+r,a=v.get(i);if(a===void 0)v.set(i,S);else if(!(a<0)){if(C*_[a*3]+w*_[a*3+1]+T*_[a*3+2]<x){let e=_[a*3]+C,t=_[a*3+1]+w,o=_[a*3+2]+T,s=Math.hypot(e,t,o);s>1e-9?(e/=s,t/=s,o/=s):(e=C,t=w,o=T),E(n,r,e,t,o),v.set(i,-1)}else v.set(i,-2)}};for(S=0;S<h;S++){let e=m?m[S*3]:S*3,t=m?m[S*3+1]:S*3+1,n=m?m[S*3+2]:S*3+2;if(g&&!(g[e]&&g[t]&&g[n]))continue;let r=o[t]-o[e],i=s[t]-s[e],a=c[t]-c[e],l=o[n]-o[e],u=s[n]-s[e],f=c[n]-c[e];C=i*f-a*u,w=a*l-r*f,T=r*u-i*l;let p=Math.hypot(C,w,T);p<1e-12||(C/=p,w/=p,T/=p,_[S*3]=C,_[S*3+1]=w,_[S*3+2]=T,D(d(e),d(t)),D(d(t),d(n)),D(d(n),d(e)))}for(let[e,t]of v){if(t<0)continue;let n=Math.floor(e/y);if(!E(n,e-n*y,_[t*3],_[t*3+1],_[t*3+2]))break}return b.length>0?new Float32Array(b):null}sh();function QS(e,t,n,r){return`${Math.round(e*r)},${Math.round(t*r)},${Math.round(n*r)}`}function $S(e,t){let n=e.getAttribute(`position`);if(!n||n.count===0)return e;let r=1/Math.max(t,1e-9),i=new Map,a=[],o=new Int32Array(n.count);for(let e=0;e<n.count;e++){let t=n.getX(e),s=n.getY(e),c=n.getZ(e),l=QS(t,s,c,r),u=i.get(l);u===void 0&&(u=a.length/3,a.push(t,s,c),i.set(l,u)),o[e]=u}let s=e.getIndex(),c=s?s.count:n.count,l=new Uint32Array(c);for(let e=0;e<c;e++)l[e]=o[s?s.getX(e):e];let u=new q;return u.setAttribute(`position`,new K(a,3)),u.setIndex(new G(l,1)),u}sh(),mh();var eC=`
4913
4913
  out vec2 vUv;
4914
4914
  void main() {
4915
4915
  vUv = uv;
4916
4916
  // 直接给裁剪空间坐标,不走任何矩阵 —— 全屏 quad 没有相机语义
4917
4917
  gl_Position = vec4( position.xy, 0.0, 1.0 );
4918
4918
  }
4919
- `,$S=`
4919
+ `,tC=`
4920
4920
  precision highp float;
4921
4921
 
4922
4922
  uniform sampler2D tNormal;
@@ -4978,9 +4978,9 @@ void main() {
4978
4978
  gl_FragDepth = d;
4979
4979
  fragColor = vec4( uColor, a );
4980
4980
  }
4981
- `,eC=class{constructor(){X(this,`rt`,null),X(this,`width`,0),X(this,`height`,0),X(this,`normalMaterial`,new Ef),X(this,`quadScene`,new Jl),X(this,`quadCamera`,new Uc(-1,1,1,-1,0,1)),X(this,`material`,void 0),this.material=new bc({glslVersion:za,uniforms:{tNormal:{value:null},tDepth:{value:null},uTexel:{value:new B(1,1)},uRadius:{value:1.5},uNormalThreshold:{value:.55},uDepthThreshold:{value:.08},uColor:{value:new W(`#334155`)},uOpacity:{value:.6}},vertexShader:QS,fragmentShader:$S,transparent:!0,depthTest:!0,depthWrite:!1,side:2,blending:1});let e=new hc(new Rc(2,2),this.material);e.frustumCulled=!1,e.raycast=()=>{},this.quadScene.add(e)}supported(e){return e.capabilities.isWebGL2===!0}ensureTarget(e,t){if(this.rt&&this.width===e&&this.height===t)return this.rt;this.disposeTarget();let n=new uo(Math.max(1,e),Math.max(1,t),{minFilter:Hr,magFilter:Hr,format:fi,type:Qr,depthBuffer:!0,stencilBuffer:!1,generateMipmaps:!1});return n.texture.generateMipmaps=!1,n.depthTexture=new rl(Math.max(1,e),Math.max(1,t),ri),this.rt=n,this.width=e,this.height=t,n}render(e,t,n,r,i,a){if(!this.supported(e)||r<=0||i<=0)return;let o=this.ensureTarget(r,i),s=t.overrideMaterial,c=e.getClearColor(new W),l=e.getClearAlpha();t.overrideMaterial=this.normalMaterial,e.setRenderTarget(o),e.setClearColor(0,0),e.clear(!0,!0,!0),e.render(t,n),t.overrideMaterial=s,e.setRenderTarget(null),e.setClearColor(c,l);let u=this.material.uniforms;u.tNormal.value=o.texture,u.tDepth.value=o.depthTexture,u.uTexel.value.set(1/Math.max(1,r),1/Math.max(1,i)),u.uRadius.value=Math.max(1,a.radius),u.uNormalThreshold.value=Math.max(.001,a.normalThreshold),u.uDepthThreshold.value=Math.max(.001,a.depthThreshold),u.uColor.value.copy(a.color),u.uOpacity.value=a.opacity,e.setViewport(0,0,r,i),e.resetState(),e.render(this.quadScene,this.quadCamera)}disposeTarget(){this.rt&&(this.rt.depthTexture?.dispose(),this.rt.dispose(),this.rt=null,this.width=0,this.height=0)}dispose(){this.disposeTarget(),this.material.dispose(),this.normalMaterial.dispose(),this.quadScene.traverse(e=>{e.geometry?.dispose?.()})}};sh(),Qb(),mh();function tC(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function nC(e){let t=e??1;return t<0?0:t>1?1:t}var rC=[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`],iC=class{constructor(e){X(this,`host`,void 0),X(this,`lineShared`,void 0),X(this,`edgeMaterial`,void 0),X(this,`selectionEdgeMaterial`,void 0),X(this,`_edgeStyleUniforms`,void 0),X(this,`_selEdgeStyleUniforms`,void 0),X(this,`_hullStyleUniforms`,void 0),X(this,`_enabled`,!1),X(this,`_modes`,void 0),X(this,`_creaseLines`,null),X(this,`_nativeLines`,new Set),X(this,`_gpuEdge`,null),X(this,`_gpuEdgeColor`,new W),this.host=e;let t=e.style;this._modes=vb(!1),this.lineShared=BS(),this._edgeStyleUniforms={uColor:{value:new W(t.edgeColor)},uWidth:{value:Math.max(.1,t.edgeWidth??1.5)},uOpacity:{value:.6},uOffset:{value:t.edgeOffset??.15}},this.edgeMaterial=US(this.lineShared,{},this._edgeStyleUniforms);let n=t;this._selEdgeStyleUniforms={uColor:{value:new W(n.outlineColor??n.selectColor??`#ffffff`)},uWidth:{value:Math.max(.1,n.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:n.selectElevation??0}},this.selectionEdgeMaterial=US(this.lineShared,{},this._selEdgeStyleUniforms),this._hullStyleUniforms={uColor:{value:new W(t.edgeColor)},uWidth:{value:Math.max(0,t.edgeHullWidth??.9)},uOpacity:{value:.6}}}get enabled(){return this._enabled}get modes(){return this._modes}useNativeEdges(e){return e&&this.host.style.forceCpuEdges!==!0&&!this._modes.gpu}registerNativeLine(e,t){this._nativeLines.add(e),e.visible=t,this._styleEdgeLine(e)}unregisterNativeLine(e){this._nativeLines.delete(e)}autoDecorate(e,t,n){if(n||aC(e)||!this._datasetEdgesEnabled(t))return;let r=e.userData;this._shouldSkipAutoEdges(r,t.name)||(this._modes.line||this._modes.hull?this._ensureEdgeDecoration(e):this._modes.gpu||this._ensureEdges(e))}disposeAll(){for(let e of this.host.pickables.values())this._removeEdges(e.mesh);this._gpuEdge?.dispose(),this._gpuEdge=null,this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose()}get gpuEdge(){return this._gpuEdge}set gpuEdge(e){this._gpuEdge=e}disposeGpuEdge(){this._gpuEdge?.dispose(),this._gpuEdge=null}renderGpuEdges(e){if(!this._modes.gpu)return;let t=this.host.renderer,n=this.host.scene,r=this.host.camera;if(!t||!n||!r)return;let i=this.host.style,a=this.host.uniforms.uEdgeFade?.value??1,o=Math.min(1,Math.max(0,i.edgeOpacity??.6))*nC(i.opacity)*a;if(o<=.004||(this._gpuEdge||(this._gpuEdge=new eC),!this._gpuEdge.supported(t)))return;let s=Math.min(179,Math.max(1,i.edgeThreshold??55)),c=2*Math.sin(s*Math.PI/360)*.6;this._gpuEdge.render(t,n,r,e.width,e.height,{color:this._gpuEdgeColor.set(i.edgeColor),opacity:o,radius:Math.max(1,i.edgeWidth??1.5),normalThreshold:c,depthThreshold:.08})}createPerMeshEdgeMaterial(e,t=!1){let n=tC(e),r=this.host.uniforms,i=n?.userData?.uBatchTex?{uBatchTex:n.userData.uBatchTex,uBatchTex2:n.userData.uBatchTex2,uBatchMix:r.uBatchMix,uBatchTexWidth:n.userData.uBatchTexWidth,uBatchTexActive:n.userData.uBatchTexActive,uPathTex:r.uPathTex,uPathCount:r.uPathCount,uPathTexActive:r.uPathTexActive,uPathTime:r.uPathTime}:void 0;return US(this.lineShared,{},t?this._selEdgeStyleUniforms:this._edgeStyleUniforms,i)}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring),r=vb(e),i=!yb(this._modes,r);this._modes=r,this._enabled=r.enabled,this.host.style.edges=e,this.host.styleTarget.edges=e;let a=r.enabled&&!r.gpu&&this.host.style.forceCpuEdges!==!0;for(let e of this._nativeLines)e.visible=a,this._styleEdgeLine(e);if(this._syncEdgeStyle(),!r.gpu&&this._gpuEdge&&(this._gpuEdge.dispose(),this._gpuEdge=null),!r.enabled){n?this.host.animator.to(`style.edgeFade`,0,{...t,onComplete:()=>{this._disposeEdges(),this.host.requestRepaint(),t?.onComplete?.()}}):(this._setEdgeFade(1),this._disposeEdges()),this.host.requestRepaint();return}i&&this._disposeEdges();let o=[...this.host.pickables.values()].map(e=>e.mesh).filter(e=>{let t=e.userData;return!aC(e)&&(t.nativeEdges=t.nativeEdgesRaw===!0&&this.host.style.forceCpuEdges!==!0,!t.nativeEdges&&this._needsEdgeDecoration(t))}),s=0,c=()=>{let e=performance.now();for(;s<o.length&&performance.now()-e<8;)this._ensureEdgeDecoration(o[s++]);s<o.length?setTimeout(c,0):this.host.requestRepaint()};c(),n?(this._setEdgeFade(0),this.host.animator.to(`style.edgeFade`,1,t)):this._setEdgeFade(1)}_setEdgeFade(e){this.host.uniforms.uEdgeFade&&(this.host.uniforms.uEdgeFade.value=e),this._syncEdgeStyle()}_disposeEdges(){for(let e of this.host.pickables.values())this._removeEdges(e.mesh)}async loadCreases(e){let t=await E_(e,this.host.authenticate,`creases`);if(!t.ok)throw Error(`[s3m] 棱线缓存加载失败: ${t.status} ${e}`);let n=await t.arrayBuffer(),r=new Float32Array(n);if(r.length<6)return;let i=new q;i.setAttribute(`position`,new G(r,3));let a=this.host.style,o=new nd({color:new W(a.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,a.edgeOpacity??.6))*nC(a.opacity),depthWrite:!1}),s=new pd(i,o);s.renderOrder=2,s.frustumCulled=!1,s.raycast=()=>{},this.clearCreases(),this._creaseLines=s,this.host.scene?.add(s),this.host.requestRepaint()}clearCreases(){this._creaseLines&&(this.host.scene?.remove(this._creaseLines),this._creaseLines.geometry.dispose(),this._creaseLines.material?.dispose?.(),this._creaseLines=null,this.host.requestRepaint())}_syncEdgeStyle(){let e=this.host.style,t=this.host.uniforms.uEdgeFade?.value??1,n=Math.min(1,Math.max(0,e.edgeOpacity??.6))*nC(e.opacity)*t,r=this.edgeMaterial.uniforms;r.uColor.value.set(e.edgeColor),r.uWidth.value=Math.max(.1,e.edgeWidth??1.5),r.uOpacity.value=n,r.uOffset.value=this._modes.offset?Math.max(0,e.edgeOffset??.15):0;let i=this._hullStyleUniforms;if(i.uColor.value.set(e.edgeColor),i.uWidth.value=Math.max(0,e.edgeHullWidth??.9),i.uOpacity.value=n,this._creaseLines){let t=this._creaseLines.material;t.color.set(e.edgeColor),t.opacity=n}}_styleEdgeLine(e){let t=e.material;t&&t.color&&(t.color.set(this.host.style.edgeColor),t.opacity=(this.host.style.edgeOpacity??.6)*nC(this.host.style.opacity)*(this.host.uniforms.uEdgeFade?.value??1),t.transparent=!0,t.polygonOffset=!0,t.polygonOffsetFactor=-1,t.polygonOffsetUnits=-1,t.needsUpdate=!0)}_refreshEdgeLines(){this._syncEdgeStyle();for(let e of this._nativeLines)e.parent&&this._styleEdgeLine(e)}_datasetEdgesEnabled(e){let t=e.options?.enableEdges;return t===!0||t!==!1&&this._enabled}_shouldSkipAutoEdges(e,t){let n=`${e.skeletonName??``} ${t}`.toLowerCase();return rC.some(e=>n.includes(e))}_needsEdgeDecoration(e){return!!(this._modes.line&&!e.edges||this._modes.hull&&!e.edgeHull)}_ensureEdgeDecoration(e){this._modes.line&&this._ensureEdges(e),this._modes.hull&&this._ensureHull(e)}_ensureEdges(e){let t=e.userData;if(t.edges||t.nativeEdges||!e.geometry||this._shouldSkipAutoEdges(t,``))return;let n=e.geometry.getAttribute(`position`);if((e.geometry.index?.count??(n?n.count:0))>12e4)return;let r=ZS(e.geometry,.005),i=this.host.style.edgeThreshold??55,a,o;if(this._modes.offset){let e=[];a=YS(r,null,i,e),e.length>0&&(o=new Float32Array(e))}else{let e=new nf(r,i),t=e.getAttribute(`position`);a=t?t.array:null,e.dispose()}if(r.dispose(),!a||a.length<6)return;let s=.005,c=GS(e.geometry,s),l;if(c){let e=a.length/6;l=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;l[t]=c.get(KS(a[e],a[e+1],a[e+2],1/s))??-1}}let u=new hc(WS(a,l,o),this.createPerMeshEdgeMaterial(e));u.renderOrder=2,u.frustumCulled=!1,u.raycast=()=>{},u.userData.isThickEdge=!0,t.edges=u,e.add(u)}_ensureHull(e){let t=e.userData;if(t.edgeHull||!e.geometry||e.isInstancedMesh||this._shouldSkipAutoEdges(t,``))return;let n=Db(this.host.uniforms,this.host.style.edgeHullWidth??.9,this._hullStyleUniforms,!0);n.uniforms.uSelWhole.value=1,n.uniforms.uSelBatch.value=-1;let r=tC(e);r?.userData?.uBatchTex&&(n.uniforms.uBatchTex.value=r.userData.uBatchTex.value,n.uniforms.uBatchTexWidth.value=r.userData.uBatchTexWidth.value,n.uniforms.uBatchTexActive.value=r.userData.uBatchTexActive.value);let i=new hc(e.geometry,n);i.renderOrder=2,i.frustumCulled=!1,i.raycast=()=>{},i.userData.isEdgeHull=!0,t.edgeHull=i,e.add(i)}_createSelectionEdgeMaterial(e){let t=tC(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.host.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.host.uniforms.uPathTex,uPathCount:this.host.uniforms.uPathCount,uPathTexActive:this.host.uniforms.uPathTexActive,uPathTime:this.host.uniforms.uPathTime}:void 0;return US(this.lineShared,{},this._selEdgeStyleUniforms,n)}_removeEdges(e){let t=e.userData,n=t.edges;if(n){e.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(e=>e?.dispose?.()):r?.dispose?.(),t.edges=null}let r=t.edgeHull;if(r){e.remove(r);let n=r.material;Array.isArray(n)?n.forEach(e=>e?.dispose?.()):n?.dispose?.(),t.edgeHull=null}}syncStyle(){this._syncEdgeStyle()}refreshLines(){this._refreshEdgeLines()}disposeEdgeGeometry(){this._disposeEdges()}ensureEdges(e){this._ensureEdges(e)}removeEdges(e){this._removeEdges(e)}createSelectionEdgeMaterial(e){return this._createSelectionEdgeMaterial(e)}};function aC(e){return e.isPoints===!0}sh(),w_(),Qb(),mh();function oC(e){if(e==null)return null;if(typeof e==`number`){let t=Math.cos(e),n=Math.sin(e);return[t,-n,0,n,t,0,0,0,1]}if(Array.isArray(e)){if(e.length===3){let t=new es(e[0],e[1],e[2]),n=new U().makeRotationFromEuler(t).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}if(e.length===4){let t=new go(e[0],e[1],e[2],e[3]),n=new U().makeRotationFromQuaternion(t).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}}if(e instanceof es){let t=new U().makeRotationFromEuler(e).elements;return[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]]}if(e instanceof go){let t=new U().makeRotationFromQuaternion(e).elements;return[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]]}if(e instanceof V){let t=e.elements;return[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]]}if(e instanceof U){let t=e.elements;return[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]]}return null}function sC(e){if(e==null)return[0,0,0];if(typeof e==`number`)return[0,0,e];if(Array.isArray(e)){if(e.length===3)return[e[0],e[1],e[2]];if(e.length===4){let t=new go(e[0],e[1],e[2],e[3]),n=new es().setFromQuaternion(t);return[n.x,n.y,n.z]}}if(e instanceof es)return[e.x,e.y,e.z];if(e instanceof go){let t=new es().setFromQuaternion(e);return[t.x,t.y,t.z]}if(e instanceof V){let t=new U().set(e.elements[0],e.elements[3],e.elements[6],0,e.elements[1],e.elements[4],e.elements[7],0,e.elements[2],e.elements[5],e.elements[8],0,0,0,0,1),n=new es().setFromRotationMatrix(t);return[n.x,n.y,n.z]}if(e instanceof U){let t=new es().setFromRotationMatrix(e);return[t.x,t.y,t.z]}return[0,0,0]}function cC(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function lC(e,t){if(e.length<2)return e[0].clone();let n=Math.min(1,Math.max(0,t))*(e.length-1),r=Math.min(e.length-2,Math.floor(n));return e[r].clone().lerp(e[r+1],n-r)}function uC(e,t,n){if(n.keep&&!n.keep(e,t))return!1;if(n.values?.length){let t=e==null?``:String(e);if(!n.values.some(e=>String(e)===t))return!1}if(n.min!=null||n.max!=null){let t=Number(e);if(!Number.isFinite(t)||n.min!=null&&t<n.min||n.max!=null&&t>n.max)return!1}return!n.keep&&!n.values?.length&&n.min==null&&n.max==null?e!=null&&String(e)!==``:!0}function dC(e){if(!Number.isFinite(e))return`—`;let t=Math.abs(e);return t>=100?e.toFixed(0):t>=10?e.toFixed(1):e.toFixed(2)}var fC=class{constructor(e,t,n,r,i,a=()=>!1){X(this,`_getLayerFloorHeight`,void 0),X(this,`_triggerRepaint`,void 0),X(this,`_onStyleChanged`,void 0),X(this,`_getAllMeshes`,void 0),X(this,`_applyOverrideHook`,void 0),X(this,`_isLayerTransparent`,void 0),X(this,`featureStyles`,new Map),X(this,`thematicColors`,new Map),X(this,`thematicElevation`,new Map),X(this,`thematicField`,null),X(this,`elevationField`,null),X(this,`filter`,null),X(this,`fieldFilter`,null),X(this,`_meshBatchTextures`,new WeakMap),X(this,`_markedMeshes`,new Set),X(this,`_dirtyAll`,!1),X(this,`_flushScheduled`,!1),X(this,`_batchConflictWarned`,!1),this._getLayerFloorHeight=e,this._triggerRepaint=t,this._onStyleChanged=n,this._getAllMeshes=r,this._applyOverrideHook=i,this._isLayerTransparent=a}setFeatureStyle(e,t,n){this.featureStyles.set(e,t),this.markOverridesDirty(n),this._onStyleChanged(),this._triggerRepaint()}setFeaturesStyle(e,t,n){for(let n of e)this.featureStyles.set(n,t);this.markOverridesDirty(n),this._onStyleChanged(),this._triggerRepaint()}getFeatureStyle(e){return this.featureStyles.get(e)??null}getFeatureEffectiveOffset(e){if(e==null)return{};let t=this.featureStyles.get(e),n=t?.elevation??this.thematicElevation.get(e);return{translation:t?.translation,elevation:n,rotation:t?.rotation,pivot:t?.pivot}}getFeatureStyles(){return new Map(this.featureStyles)}removeFeatureStyle(e,t){this.featureStyles.delete(e)&&(this.markOverridesDirty(t),this._onStyleChanged(),this._triggerRepaint())}clearFeatureStyles(){this.featureStyles.size>0&&(this.featureStyles.clear(),this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint())}setThematicColors(e,t=`custom`){this.thematicColors=e&&e.size>0?new Map(e):new Map,this.thematicField=this.thematicColors.size>0?t:null,this.markOverridesDirty(),this._triggerRepaint()}clearThematicColors(){this.thematicColors.size!==0&&(this.thematicColors=new Map,this.thematicField=null,this.markOverridesDirty(),this._triggerRepaint())}setThematicElevation(e,t=`custom`){this.thematicElevation=e&&e.size>0?new Map([...e].filter(([,e])=>Number.isFinite(e)&&e>0)):new Map,this.elevationField=this.thematicElevation.size>0?t:null,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint()}clearThematicElevation(){this.thematicElevation.size!==0&&(this.thematicElevation=new Map,this.elevationField=null,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint())}setFilter(e,t){this.filter=e,e&&(e.minHeight!=null||e.maxHeight!=null)?(t.uFilterMinZ&&(t.uFilterMinZ.value=e.minHeight??-99999),t.uFilterMaxZ&&(t.uFilterMaxZ.value=e.maxHeight??99999),t.uFilterHeightActive&&(t.uFilterHeightActive.value=1)):t.uFilterHeightActive&&(t.uFilterHeightActive.value=0),this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint()}clearFilter(e){this.setFilter(null,e)}async colorByField(e,t,n){if(!t)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let r=e.smids?.length?[...new Set(e.smids)]:n;if(!r.length)return this.clearThematicColors(),{field:e.field,type:`discrete`,matched:0,missing:0,legend:[]};let i=await t.queryBySmids(r),a=[],o=[];for(let t of r){let n=i.get(t),r=n?n[e.field]:void 0;if(r==null||r===``)continue;let s=Number(r);Number.isFinite(s)?a.push({smid:t,val:s}):o.push({smid:t,val:String(r)})}let s=a.length>=o.length&&a.length>0,c=new Map,l=[],u=e.defaultColor??`#64748b`,d=e.nullColor??`#334155`;if(s){let t=a.map(e=>e.val),n=Math.min(...t),r=Math.max(...t)-n||1,i=(e.ramp??[`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`]).map(e=>new W(e)),o=Math.max(2,e.stops??5);for(let e=0;e<o;e++){let t=e/o,a=(e+1)/o,s=lC(i,(t+a)/2),c=n+t*r,u=n+a*r;l.push({color:`#${s.getHexString()}`,label:`${dC(c)} ~ ${dC(u)}`,count:0,min:c,max:u})}for(let{smid:e,val:t}of a){let i=Math.min(1,Math.max(0,(t-n)/r)),a=Math.min(o-1,Math.floor(i*o)),s=l[a].color;c.set(e,s),l[a].count++}}else{let t=new Map;for(let{val:e}of o)t.set(e,(t.get(e)??0)+1);let n=[...t.entries()].sort((e,t)=>t[1]-e[1]),r=Array.isArray(e.colors)?e.colors:[`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#06b6d4`,`#84cc16`],i=!Array.isArray(e.colors)&&e.colors?e.colors:null;for(let e=0;e<n.length;e++){let[t,a]=n[e],o=i?.[t]??r[e%r.length];l.push({color:o,label:t,count:a})}let a=new Map(l.map(e=>[e.label,e.color]));for(let{smid:e,val:t}of o)c.set(e,a.get(t)??u)}let f=0;for(let e of r)c.has(e)||(c.set(e,d),f++);return f>0&&l.push({color:d,label:`无数据 / 缺失`,count:f}),this.setThematicColors(c,e.field),{field:e.field,type:s?`continuous`:`discrete`,matched:r.length-f,missing:f,legend:l}}async filterByField(e,t,n){if(!t)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let r=e.smids?.length?[...new Set(e.smids)]:n,i=e.mode??`keep`,a=e.onMissing??`drop`,o={field:e.field,mode:i,matched:0,hidden:[]};if(!r.length)return this.fieldFilter=null,this.markOverridesDirty(),o;let s=await t.queryBySmids(r),c=new Set;for(let t of r){let n=s.get(t);n?uC(n[e.field]??null,n,e)&&c.add(t):a===`keep`&&c.add(t)}o.matched=c.size;let l=i===`keep`;return this.fieldFilter=c.size||l?{field:e.field,mode:l?`keep`:`drop`,matched:c}:null,o.hidden=r.filter(e=>l?!c.has(e):c.has(e)),this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint(),o}clearFieldFilter(){this.fieldFilter&&(this.fieldFilter=null,this.markOverridesDirty(),this._triggerRepaint())}async elevateByField(e,t,n){if(!t)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let r=e.smids?.length?[...new Set(e.smids)]:n,i={field:e.field,matched:0,missing:r.length,min:0,max:0,appliedMax:0};if(!r.length)return this.thematicElevation=new Map,this.elevationField=null,this.markOverridesDirty(),i;let a=await t.queryBySmids(r),o=new Map;for(let t of r){let n=Number(a.get(t)?.[e.field]);Number.isFinite(n)&&o.set(t,n)}if(o.size===0)return this.thematicElevation=new Map,this.elevationField=null,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint(),i;let s=[...o.values()],c=Math.min(...s),l=Math.max(...s),u=e.scale??1,d=e.offset??0,f=new Map,p=0;for(let[t,n]of o){let r=e.map?e.map(n,{min:c,max:l}):n*u+d;Number.isFinite(r)&&(e.max!=null&&r>e.max&&(r=e.max),!(r<=0)&&(f.set(t,r),r>p&&(p=r)))}return this.thematicElevation=f,this.elevationField=e.field,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint(),{field:e.field,matched:f.size,missing:r.length-o.size,min:c,max:l,appliedMax:p}}auditBatches(e){let t=[],n=new Set,r=0;for(let i of e){let e=i.mesh.userData.geoRef?.pickInfo;if(!e)continue;let a=new Map;for(let[t,n]of Object.entries(e)){let e=__(n);if(e<0)continue;let r=Number(t),i=a.get(e);i?i.push(r):a.set(e,[r])}r+=a.size;for(let[e,r]of a)if(!(r.length<2)){for(let e of r)n.add(e);t.push({datasetId:i.datasetId,batchId:e,smids:r})}}return{smids:0,batches:r,conflicts:t,conflictingSmids:n.size}}_bakeStylesIntoBuffer(e,t,n,r,i){let a=t;for(let t=0;t<a;t++){e[t*4+0]=-1,e[t*4+1]=-1,e[t*4+2]=-1,e[t*4+3]=0;let n=(a+t)*4;e[n+0]=0,e[n+1]=0,e[n+2]=0,e[n+3]=0;let r=(a*2+t)*4;e[r+0]=1,e[r+1]=0,e[r+2]=0,e[r+3]=0;let i=(a*3+t)*4;e[i+0]=0,e[i+1]=1,e[i+2]=0,e[i+3]=0;let o=(a*4+t)*4;e[o+0]=0,e[o+1]=0,e[o+2]=1,e[o+3]=0;let s=(a*5+t)*4;e[s+0]=-1,e[s+1]=0,e[s+2]=0,e[s+3]=0}let o=!1,s=new Set,c=new Map,l=new Map,u=new Map,d=new Map,f=new Map,p=new Map,m=new Map,h=new Map,g=this.filter,_=r.userData;for(let[e,t]of Object.entries(n)){let n=Number(e),o=__(t);if(o<0||o>=a)continue;h.set(o,(h.get(o)??0)+1);let v=!1;if(g&&(g.include&&g.include.length>0&&!g.include.includes(n)&&(v=!0),g.exclude&&g.exclude.length>0&&g.exclude.includes(n)&&(v=!0),g.predicate)){let{segments:e}=y_(_.geoRef,o),t=x_({smid:n,box:b_(r.geometry,e),triangles:0,floorHeight:this._getLayerFloorHeight()});g.predicate({...t,smid:n})||(v=!0)}if(v){s.add(o);continue}if(this.fieldFilter){let e=this.fieldFilter.matched.has(n);if(this.fieldFilter.mode===`keep`?!e:e){s.add(o);continue}}let y=i.get(n);if(y?.hidden){s.add(o);continue}let b=y?.opacity;if(b!=null){if(b<=0){s.add(o);continue}b<1&&!m.has(o)&&m.set(o,b)}let x=y?.color??this.thematicColors.get(n);x&&!c.has(o)&&c.set(o,x);let S=y?.elevation??this.thematicElevation.get(n);if(S!=null&&!l.has(o)&&l.set(o,S),y?.translation&&!u.has(o)&&u.set(o,y.translation),y?.rotation!=null&&!d.has(o)){let e=oC(y.rotation);e&&d.set(o,e)}y?.pivot&&!f.has(o)&&f.set(o,y.pivot),y?.gpuPath&&!p.has(o)&&p.set(o,y.gpuPath)}for(let t of s)e[t*4+3]=-1,o=!0;let v=new W;for(let[t,n]of c)s.has(t)||(v.set(n),e[t*4+0]=v.r,e[t*4+1]=v.g,e[t*4+2]=v.b,o=!0);for(let[t,n]of l){if(s.has(t))continue;e[t*4+3]=n;let r=(a+t)*4;e[r+2]=n,o=!0}for(let[t,n]of u){if(s.has(t))continue;let r=(a+t)*4;e[r+0]=n[0],e[r+1]=n[1],e[r+2]=n[2]+(l.get(t)??0),o=!0}let y=!1;for(let[t,n]of m)s.has(t)||(e[(a+t)*4+3]=n,o=!0,y=!0);for(let[t,n]of d){if(s.has(t))continue;let r=f.get(t)??[0,0,0],i=(a*2+t)*4;e[i+0]=n[0],e[i+1]=n[1],e[i+2]=n[2],e[i+3]=r[0];let c=(a*3+t)*4;e[c+0]=n[3],e[c+1]=n[4],e[c+2]=n[5],e[c+3]=r[1];let l=(a*4+t)*4;e[l+0]=n[6],e[l+1]=n[7],e[l+2]=n[8],e[l+3]=r[2],o=!0}for(let[t,n]of f)d.has(t)||s.has(t)||(e[(a*2+t)*4+3]=n[0],e[(a*3+t)*4+3]=n[1],e[(a*4+t)*4+3]=n[2],o=!0);for(let[t,n]of p){if(s.has(t))continue;let r=(a*5+t)*4;e[r+0]=n.pathId,e[r+1]=n.speed??0,e[r+2]=n.phase??0;let i=1;n.loop===`clamp`||n.loop===!1?i=2:n.loop===`pingpong`&&(i=3),n.autoHeading===!1&&(i+=3),e[r+3]=i,o=!0}let b=0;for(let[e,t]of h)t<2||(s.has(e)||c.has(e)||l.has(e)||d.has(e)||p.has(e))&&b++;return{hasActive:o,hasFade:y,conflicts:b}}applyOverridesToMesh(e){let t=cC(e);if(!t)return;let n=e.userData.geoRef?.pickInfo,r=this.featureStyles.size>0||this.thematicColors.size>0||this.thematicElevation.size>0,i=this.filter,a=this.fieldFilter!=null||i!=null&&((i.include?.length??0)>0||(i.exclude?.length??0)>0||i.predicate!=null);if(!r&&!a||!n||Object.keys(n).length===0){t.userData.uBatchTexActive&&(t.userData.uBatchTexActive.value=0),t.transparent&&!this._isLayerTransparent()&&Eb(t,!1);return}let o=0;for(let e of Object.values(n)){let t=__(e);t>o&&(o=t)}let s=Math.max(o+1,1),c=this._meshBatchTextures.get(e);if(!c||c.width<s){let n=new Float32Array(s*6*4),r=new Du(n,s,6,fi,ii);r.minFilter=Hr,r.magFilter=Hr,c={texture:r,data:n,width:s},this._meshBatchTextures.set(e,c),t.userData.uBatchTex.value=r,t.userData.uBatchTexWidth.value=s}let{data:l,texture:u}=c,{hasActive:d,hasFade:f,conflicts:p}=this._bakeStylesIntoBuffer(l,c.width,n,e,this.featureStyles);f&&!t.transparent?t.transparent=!0:!f&&t.transparent&&!this._isLayerTransparent()&&Eb(t,!1),p>0&&!this._batchConflictWarned&&(this._batchConflictWarned=!0,console.warn(`[s3m] 有 ${p} 个单体状态写不进独立的 batch(多个 SMID 共用同一个 batchId,\n S3M 的单体化粒度只到 batch,无法单独隐藏/改色其中一部分)。
4981
+ `,nC=class{constructor(){X(this,`rt`,null),X(this,`width`,0),X(this,`height`,0),X(this,`normalMaterial`,new Ef),X(this,`quadScene`,new Jl),X(this,`quadCamera`,new Uc(-1,1,1,-1,0,1)),X(this,`material`,void 0),this.material=new bc({glslVersion:za,uniforms:{tNormal:{value:null},tDepth:{value:null},uTexel:{value:new B(1,1)},uRadius:{value:1.5},uNormalThreshold:{value:.55},uDepthThreshold:{value:.08},uColor:{value:new W(`#334155`)},uOpacity:{value:.6}},vertexShader:eC,fragmentShader:tC,transparent:!0,depthTest:!0,depthWrite:!1,side:2,blending:1});let e=new hc(new Rc(2,2),this.material);e.frustumCulled=!1,e.raycast=()=>{},this.quadScene.add(e)}supported(e){return e.capabilities.isWebGL2===!0}ensureTarget(e,t){if(this.rt&&this.width===e&&this.height===t)return this.rt;this.disposeTarget();let n=new uo(Math.max(1,e),Math.max(1,t),{minFilter:Hr,magFilter:Hr,format:fi,type:Qr,depthBuffer:!0,stencilBuffer:!1,generateMipmaps:!1});return n.texture.generateMipmaps=!1,n.depthTexture=new rl(Math.max(1,e),Math.max(1,t),ri),this.rt=n,this.width=e,this.height=t,n}render(e,t,n,r,i,a){if(!this.supported(e)||r<=0||i<=0)return;let o=this.ensureTarget(r,i),s=t.overrideMaterial,c=e.getClearColor(new W),l=e.getClearAlpha();t.overrideMaterial=this.normalMaterial,e.setRenderTarget(o),e.setClearColor(0,0),e.clear(!0,!0,!0),e.render(t,n),t.overrideMaterial=s,e.setRenderTarget(null),e.setClearColor(c,l);let u=this.material.uniforms;u.tNormal.value=o.texture,u.tDepth.value=o.depthTexture,u.uTexel.value.set(1/Math.max(1,r),1/Math.max(1,i)),u.uRadius.value=Math.max(1,a.radius),u.uNormalThreshold.value=Math.max(.001,a.normalThreshold),u.uDepthThreshold.value=Math.max(.001,a.depthThreshold),u.uColor.value.copy(a.color),u.uOpacity.value=a.opacity,e.setViewport(0,0,r,i),e.resetState(),e.render(this.quadScene,this.quadCamera)}disposeTarget(){this.rt&&(this.rt.depthTexture?.dispose(),this.rt.dispose(),this.rt=null,this.width=0,this.height=0)}dispose(){this.disposeTarget(),this.material.dispose(),this.normalMaterial.dispose(),this.quadScene.traverse(e=>{e.geometry?.dispose?.()})}};sh(),Qb(),mh();function rC(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function iC(e){let t=e??1;return t<0?0:t>1?1:t}var aC=[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`],oC=class{constructor(e){X(this,`host`,void 0),X(this,`lineShared`,void 0),X(this,`edgeMaterial`,void 0),X(this,`selectionEdgeMaterial`,void 0),X(this,`_edgeStyleUniforms`,void 0),X(this,`_selEdgeStyleUniforms`,void 0),X(this,`_hullStyleUniforms`,void 0),X(this,`_enabled`,!1),X(this,`_modes`,void 0),X(this,`_creaseLines`,null),X(this,`_nativeLines`,new Set),X(this,`_gpuEdge`,null),X(this,`_gpuEdgeColor`,new W),this.host=e;let t=e.style;this._modes=vb(!1),this.lineShared=HS(),this._edgeStyleUniforms={uColor:{value:new W(t.edgeColor)},uWidth:{value:Math.max(.1,t.edgeWidth??1.5)},uOpacity:{value:.6},uOffset:{value:t.edgeOffset??.15}},this.edgeMaterial=GS(this.lineShared,{},this._edgeStyleUniforms);let n=t;this._selEdgeStyleUniforms={uColor:{value:new W(n.outlineColor??n.selectColor??`#ffffff`)},uWidth:{value:Math.max(.1,n.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:n.selectElevation??0}},this.selectionEdgeMaterial=GS(this.lineShared,{},this._selEdgeStyleUniforms),this._hullStyleUniforms={uColor:{value:new W(t.edgeColor)},uWidth:{value:Math.max(0,t.edgeHullWidth??.9)},uOpacity:{value:.6}}}get enabled(){return this._enabled}get modes(){return this._modes}useNativeEdges(e){return e&&this.host.style.forceCpuEdges!==!0&&!this._modes.gpu}registerNativeLine(e,t){this._nativeLines.add(e),e.visible=t,this._styleEdgeLine(e)}unregisterNativeLine(e){this._nativeLines.delete(e)}autoDecorate(e,t,n){if(n||sC(e)||!this._datasetEdgesEnabled(t))return;let r=e.userData;this._shouldSkipAutoEdges(r,t.name)||(this._modes.line||this._modes.hull?this._ensureEdgeDecoration(e):this._modes.gpu||this._ensureEdges(e))}disposeAll(){for(let e of this.host.pickables.values())this._removeEdges(e.mesh);this._gpuEdge?.dispose(),this._gpuEdge=null,this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose()}get gpuEdge(){return this._gpuEdge}set gpuEdge(e){this._gpuEdge=e}disposeGpuEdge(){this._gpuEdge?.dispose(),this._gpuEdge=null}renderGpuEdges(e){if(!this._modes.gpu)return;let t=this.host.renderer,n=this.host.scene,r=this.host.camera;if(!t||!n||!r)return;let i=this.host.style,a=this.host.uniforms.uEdgeFade?.value??1,o=Math.min(1,Math.max(0,i.edgeOpacity??.6))*iC(i.opacity)*a;if(o<=.004||(this._gpuEdge||(this._gpuEdge=new nC),!this._gpuEdge.supported(t)))return;let s=Math.min(179,Math.max(1,i.edgeThreshold??55)),c=2*Math.sin(s*Math.PI/360)*.6;this._gpuEdge.render(t,n,r,e.width,e.height,{color:this._gpuEdgeColor.set(i.edgeColor),opacity:o,radius:Math.max(1,i.edgeWidth??1.5),normalThreshold:c,depthThreshold:.08})}createPerMeshEdgeMaterial(e,t=!1){let n=rC(e),r=this.host.uniforms,i=n?.userData?.uBatchTex?{uBatchTex:n.userData.uBatchTex,uBatchTex2:n.userData.uBatchTex2,uBatchMix:r.uBatchMix,uBatchTexWidth:n.userData.uBatchTexWidth,uBatchTexActive:n.userData.uBatchTexActive,uPathTex:r.uPathTex,uPathCount:r.uPathCount,uPathTexActive:r.uPathTexActive,uPathTime:r.uPathTime}:void 0;return GS(this.lineShared,{},t?this._selEdgeStyleUniforms:this._edgeStyleUniforms,i)}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring),r=vb(e),i=!yb(this._modes,r);this._modes=r,this._enabled=r.enabled,this.host.style.edges=e,this.host.styleTarget.edges=e;let a=r.enabled&&!r.gpu&&this.host.style.forceCpuEdges!==!0;for(let e of this._nativeLines)e.visible=a,this._styleEdgeLine(e);if(this._syncEdgeStyle(),!r.gpu&&this._gpuEdge&&(this._gpuEdge.dispose(),this._gpuEdge=null),!r.enabled){n?this.host.animator.to(`style.edgeFade`,0,{...t,onComplete:()=>{this._disposeEdges(),this.host.requestRepaint(),t?.onComplete?.()}}):(this._setEdgeFade(1),this._disposeEdges()),this.host.requestRepaint();return}i&&this._disposeEdges();let o=[...this.host.pickables.values()].map(e=>e.mesh).filter(e=>{let t=e.userData;return!sC(e)&&(t.nativeEdges=t.nativeEdgesRaw===!0&&this.host.style.forceCpuEdges!==!0,!t.nativeEdges&&this._needsEdgeDecoration(t))}),s=0,c=()=>{let e=performance.now();for(;s<o.length&&performance.now()-e<8;)this._ensureEdgeDecoration(o[s++]);s<o.length?setTimeout(c,0):this.host.requestRepaint()};c(),n?(this._setEdgeFade(0),this.host.animator.to(`style.edgeFade`,1,t)):this._setEdgeFade(1)}_setEdgeFade(e){this.host.uniforms.uEdgeFade&&(this.host.uniforms.uEdgeFade.value=e),this._syncEdgeStyle()}_disposeEdges(){for(let e of this.host.pickables.values())this._removeEdges(e.mesh)}async loadCreases(e){let t=await E_(e,this.host.authenticate,`creases`);if(!t.ok)throw Error(`[s3m] 棱线缓存加载失败: ${t.status} ${e}`);let n=await t.arrayBuffer(),r=new Float32Array(n);if(r.length<6)return;let i=new q;i.setAttribute(`position`,new G(r,3));let a=this.host.style,o=new nd({color:new W(a.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,a.edgeOpacity??.6))*iC(a.opacity),depthWrite:!1}),s=new pd(i,o);s.renderOrder=2,s.frustumCulled=!1,s.raycast=()=>{},this.clearCreases(),this._creaseLines=s,this.host.scene?.add(s),this.host.requestRepaint()}clearCreases(){this._creaseLines&&(this.host.scene?.remove(this._creaseLines),this._creaseLines.geometry.dispose(),this._creaseLines.material?.dispose?.(),this._creaseLines=null,this.host.requestRepaint())}_syncEdgeStyle(){let e=this.host.style,t=this.host.uniforms.uEdgeFade?.value??1,n=Math.min(1,Math.max(0,e.edgeOpacity??.6))*iC(e.opacity)*t,r=this.edgeMaterial.uniforms;r.uColor.value.set(e.edgeColor),r.uWidth.value=Math.max(.1,e.edgeWidth??1.5),r.uOpacity.value=n,r.uOffset.value=this._modes.offset?Math.max(0,e.edgeOffset??.15):0;let i=this._hullStyleUniforms;if(i.uColor.value.set(e.edgeColor),i.uWidth.value=Math.max(0,e.edgeHullWidth??.9),i.uOpacity.value=n,this._creaseLines){let t=this._creaseLines.material;t.color.set(e.edgeColor),t.opacity=n}}_styleEdgeLine(e){let t=e.material;t&&t.color&&(t.color.set(this.host.style.edgeColor),t.opacity=(this.host.style.edgeOpacity??.6)*iC(this.host.style.opacity)*(this.host.uniforms.uEdgeFade?.value??1),t.transparent=!0,t.polygonOffset=!0,t.polygonOffsetFactor=-1,t.polygonOffsetUnits=-1,t.needsUpdate=!0)}_refreshEdgeLines(){this._syncEdgeStyle();for(let e of this._nativeLines)e.parent&&this._styleEdgeLine(e)}_datasetEdgesEnabled(e){let t=e.options?.enableEdges;return t===!0||t!==!1&&this._enabled}_shouldSkipAutoEdges(e,t){let n=`${e.skeletonName??``} ${t}`.toLowerCase();return aC.some(e=>n.includes(e))}_needsEdgeDecoration(e){return!!(this._modes.line&&!e.edges||this._modes.hull&&!e.edgeHull)}_ensureEdgeDecoration(e){this._modes.line&&this._ensureEdges(e),this._modes.hull&&this._ensureHull(e)}_ensureEdges(e){let t=e.userData;if(t.edges||t.nativeEdges||!e.geometry||this._shouldSkipAutoEdges(t,``))return;let n=e.geometry.getAttribute(`position`);if((e.geometry.index?.count??(n?n.count:0))>12e4)return;let r=$S(e.geometry,.005),i=this.host.style.edgeThreshold??55,a,o;if(this._modes.offset){let e=[];a=ZS(r,null,i,e),e.length>0&&(o=new Float32Array(e))}else{let e=new nf(r,i),t=e.getAttribute(`position`);a=t?t.array:null,e.dispose()}if(r.dispose(),!a||a.length<6)return;let s=.005,c=qS(e.geometry,s),l;if(c){let e=a.length/6;l=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;l[t]=c.get(JS(a[e],a[e+1],a[e+2],1/s))??-1}}let u=new hc(KS(a,l,o),this.createPerMeshEdgeMaterial(e));u.renderOrder=2,u.frustumCulled=!1,u.raycast=()=>{},u.userData.isThickEdge=!0,t.edges=u,e.add(u)}_ensureHull(e){let t=e.userData;if(t.edgeHull||!e.geometry||e.isInstancedMesh||this._shouldSkipAutoEdges(t,``))return;let n=Db(this.host.uniforms,this.host.style.edgeHullWidth??.9,this._hullStyleUniforms,!0);n.uniforms.uSelWhole.value=1,n.uniforms.uSelBatch.value=-1;let r=rC(e);r?.userData?.uBatchTex&&(n.uniforms.uBatchTex.value=r.userData.uBatchTex.value,n.uniforms.uBatchTexWidth.value=r.userData.uBatchTexWidth.value,n.uniforms.uBatchTexActive.value=r.userData.uBatchTexActive.value);let i=new hc(e.geometry,n);i.renderOrder=2,i.frustumCulled=!1,i.raycast=()=>{},i.userData.isEdgeHull=!0,t.edgeHull=i,e.add(i)}_createSelectionEdgeMaterial(e){let t=rC(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.host.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.host.uniforms.uPathTex,uPathCount:this.host.uniforms.uPathCount,uPathTexActive:this.host.uniforms.uPathTexActive,uPathTime:this.host.uniforms.uPathTime}:void 0;return GS(this.lineShared,{},this._selEdgeStyleUniforms,n)}_removeEdges(e){let t=e.userData,n=t.edges;if(n){e.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(e=>e?.dispose?.()):r?.dispose?.(),t.edges=null}let r=t.edgeHull;if(r){e.remove(r);let n=r.material;Array.isArray(n)?n.forEach(e=>e?.dispose?.()):n?.dispose?.(),t.edgeHull=null}}syncStyle(){this._syncEdgeStyle()}refreshLines(){this._refreshEdgeLines()}disposeEdgeGeometry(){this._disposeEdges()}ensureEdges(e){this._ensureEdges(e)}removeEdges(e){this._removeEdges(e)}createSelectionEdgeMaterial(e){return this._createSelectionEdgeMaterial(e)}};function sC(e){return e.isPoints===!0}sh(),w_(),Qb(),mh();function cC(e){if(e==null)return null;if(typeof e==`number`){let t=Math.cos(e),n=Math.sin(e);return[t,-n,0,n,t,0,0,0,1]}if(Array.isArray(e)){if(e.length===3){let t=new es(e[0],e[1],e[2]),n=new U().makeRotationFromEuler(t).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}if(e.length===4){let t=new go(e[0],e[1],e[2],e[3]),n=new U().makeRotationFromQuaternion(t).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}}if(e instanceof es){let t=new U().makeRotationFromEuler(e).elements;return[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]]}if(e instanceof go){let t=new U().makeRotationFromQuaternion(e).elements;return[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]]}if(e instanceof V){let t=e.elements;return[t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8]]}if(e instanceof U){let t=e.elements;return[t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]]}return null}function lC(e){if(e==null)return[0,0,0];if(typeof e==`number`)return[0,0,e];if(Array.isArray(e)){if(e.length===3)return[e[0],e[1],e[2]];if(e.length===4){let t=new go(e[0],e[1],e[2],e[3]),n=new es().setFromQuaternion(t);return[n.x,n.y,n.z]}}if(e instanceof es)return[e.x,e.y,e.z];if(e instanceof go){let t=new es().setFromQuaternion(e);return[t.x,t.y,t.z]}if(e instanceof V){let t=new U().set(e.elements[0],e.elements[3],e.elements[6],0,e.elements[1],e.elements[4],e.elements[7],0,e.elements[2],e.elements[5],e.elements[8],0,0,0,0,1),n=new es().setFromRotationMatrix(t);return[n.x,n.y,n.z]}if(e instanceof U){let t=new es().setFromRotationMatrix(e);return[t.x,t.y,t.z]}return[0,0,0]}function uC(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function dC(e,t){if(e.length<2)return e[0].clone();let n=Math.min(1,Math.max(0,t))*(e.length-1),r=Math.min(e.length-2,Math.floor(n));return e[r].clone().lerp(e[r+1],n-r)}function fC(e,t,n){if(n.keep&&!n.keep(e,t))return!1;if(n.values?.length){let t=e==null?``:String(e);if(!n.values.some(e=>String(e)===t))return!1}if(n.min!=null||n.max!=null){let t=Number(e);if(!Number.isFinite(t)||n.min!=null&&t<n.min||n.max!=null&&t>n.max)return!1}return!n.keep&&!n.values?.length&&n.min==null&&n.max==null?e!=null&&String(e)!==``:!0}function pC(e){if(!Number.isFinite(e))return`—`;let t=Math.abs(e);return t>=100?e.toFixed(0):t>=10?e.toFixed(1):e.toFixed(2)}var mC=class{constructor(e,t,n,r,i,a=()=>!1){X(this,`_getLayerFloorHeight`,void 0),X(this,`_triggerRepaint`,void 0),X(this,`_onStyleChanged`,void 0),X(this,`_getAllMeshes`,void 0),X(this,`_applyOverrideHook`,void 0),X(this,`_isLayerTransparent`,void 0),X(this,`featureStyles`,new Map),X(this,`thematicColors`,new Map),X(this,`thematicElevation`,new Map),X(this,`thematicField`,null),X(this,`elevationField`,null),X(this,`filter`,null),X(this,`fieldFilter`,null),X(this,`_meshBatchTextures`,new WeakMap),X(this,`_markedMeshes`,new Set),X(this,`_dirtyAll`,!1),X(this,`_flushScheduled`,!1),X(this,`_batchConflictWarned`,!1),this._getLayerFloorHeight=e,this._triggerRepaint=t,this._onStyleChanged=n,this._getAllMeshes=r,this._applyOverrideHook=i,this._isLayerTransparent=a}setFeatureStyle(e,t,n){this.featureStyles.set(e,t),this.markOverridesDirty(n),this._onStyleChanged(),this._triggerRepaint()}setFeaturesStyle(e,t,n){for(let n of e)this.featureStyles.set(n,t);this.markOverridesDirty(n),this._onStyleChanged(),this._triggerRepaint()}getFeatureStyle(e){return this.featureStyles.get(e)??null}getFeatureEffectiveOffset(e){if(e==null)return{};let t=this.featureStyles.get(e),n=t?.elevation??this.thematicElevation.get(e);return{translation:t?.translation,elevation:n,rotation:t?.rotation,pivot:t?.pivot}}getFeatureStyles(){return new Map(this.featureStyles)}removeFeatureStyle(e,t){this.featureStyles.delete(e)&&(this.markOverridesDirty(t),this._onStyleChanged(),this._triggerRepaint())}clearFeatureStyles(){this.featureStyles.size>0&&(this.featureStyles.clear(),this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint())}setThematicColors(e,t=`custom`){this.thematicColors=e&&e.size>0?new Map(e):new Map,this.thematicField=this.thematicColors.size>0?t:null,this.markOverridesDirty(),this._triggerRepaint()}clearThematicColors(){this.thematicColors.size!==0&&(this.thematicColors=new Map,this.thematicField=null,this.markOverridesDirty(),this._triggerRepaint())}setThematicElevation(e,t=`custom`){this.thematicElevation=e&&e.size>0?new Map([...e].filter(([,e])=>Number.isFinite(e)&&e>0)):new Map,this.elevationField=this.thematicElevation.size>0?t:null,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint()}clearThematicElevation(){this.thematicElevation.size!==0&&(this.thematicElevation=new Map,this.elevationField=null,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint())}setFilter(e,t){this.filter=e,e&&(e.minHeight!=null||e.maxHeight!=null)?(t.uFilterMinZ&&(t.uFilterMinZ.value=e.minHeight??-99999),t.uFilterMaxZ&&(t.uFilterMaxZ.value=e.maxHeight??99999),t.uFilterHeightActive&&(t.uFilterHeightActive.value=1)):t.uFilterHeightActive&&(t.uFilterHeightActive.value=0),this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint()}clearFilter(e){this.setFilter(null,e)}async colorByField(e,t,n){if(!t)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let r=e.smids?.length?[...new Set(e.smids)]:n;if(!r.length)return this.clearThematicColors(),{field:e.field,type:`discrete`,matched:0,missing:0,legend:[]};let i=await t.queryBySmids(r),a=[],o=[];for(let t of r){let n=i.get(t),r=n?n[e.field]:void 0;if(r==null||r===``)continue;let s=Number(r);Number.isFinite(s)?a.push({smid:t,val:s}):o.push({smid:t,val:String(r)})}let s=a.length>=o.length&&a.length>0,c=new Map,l=[],u=e.defaultColor??`#64748b`,d=e.nullColor??`#334155`;if(s){let t=a.map(e=>e.val),n=Math.min(...t),r=Math.max(...t)-n||1,i=(e.ramp??[`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`]).map(e=>new W(e)),o=Math.max(2,e.stops??5);for(let e=0;e<o;e++){let t=e/o,a=(e+1)/o,s=dC(i,(t+a)/2),c=n+t*r,u=n+a*r;l.push({color:`#${s.getHexString()}`,label:`${pC(c)} ~ ${pC(u)}`,count:0,min:c,max:u})}for(let{smid:e,val:t}of a){let i=Math.min(1,Math.max(0,(t-n)/r)),a=Math.min(o-1,Math.floor(i*o)),s=l[a].color;c.set(e,s),l[a].count++}}else{let t=new Map;for(let{val:e}of o)t.set(e,(t.get(e)??0)+1);let n=[...t.entries()].sort((e,t)=>t[1]-e[1]),r=Array.isArray(e.colors)?e.colors:[`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#06b6d4`,`#84cc16`],i=!Array.isArray(e.colors)&&e.colors?e.colors:null;for(let e=0;e<n.length;e++){let[t,a]=n[e],o=i?.[t]??r[e%r.length];l.push({color:o,label:t,count:a})}let a=new Map(l.map(e=>[e.label,e.color]));for(let{smid:e,val:t}of o)c.set(e,a.get(t)??u)}let f=0;for(let e of r)c.has(e)||(c.set(e,d),f++);return f>0&&l.push({color:d,label:`无数据 / 缺失`,count:f}),this.setThematicColors(c,e.field),{field:e.field,type:s?`continuous`:`discrete`,matched:r.length-f,missing:f,legend:l}}async filterByField(e,t,n){if(!t)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let r=e.smids?.length?[...new Set(e.smids)]:n,i=e.mode??`keep`,a=e.onMissing??`drop`,o={field:e.field,mode:i,matched:0,hidden:[]};if(!r.length)return this.fieldFilter=null,this.markOverridesDirty(),o;let s=await t.queryBySmids(r),c=new Set;for(let t of r){let n=s.get(t);n?fC(n[e.field]??null,n,e)&&c.add(t):a===`keep`&&c.add(t)}o.matched=c.size;let l=i===`keep`;return this.fieldFilter=c.size||l?{field:e.field,mode:l?`keep`:`drop`,matched:c}:null,o.hidden=r.filter(e=>l?!c.has(e):c.has(e)),this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint(),o}clearFieldFilter(){this.fieldFilter&&(this.fieldFilter=null,this.markOverridesDirty(),this._triggerRepaint())}async elevateByField(e,t,n){if(!t)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let r=e.smids?.length?[...new Set(e.smids)]:n,i={field:e.field,matched:0,missing:r.length,min:0,max:0,appliedMax:0};if(!r.length)return this.thematicElevation=new Map,this.elevationField=null,this.markOverridesDirty(),i;let a=await t.queryBySmids(r),o=new Map;for(let t of r){let n=Number(a.get(t)?.[e.field]);Number.isFinite(n)&&o.set(t,n)}if(o.size===0)return this.thematicElevation=new Map,this.elevationField=null,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint(),i;let s=[...o.values()],c=Math.min(...s),l=Math.max(...s),u=e.scale??1,d=e.offset??0,f=new Map,p=0;for(let[t,n]of o){let r=e.map?e.map(n,{min:c,max:l}):n*u+d;Number.isFinite(r)&&(e.max!=null&&r>e.max&&(r=e.max),!(r<=0)&&(f.set(t,r),r>p&&(p=r)))}return this.thematicElevation=f,this.elevationField=e.field,this.markOverridesDirty(),this._onStyleChanged(),this._triggerRepaint(),{field:e.field,matched:f.size,missing:r.length-o.size,min:c,max:l,appliedMax:p}}auditBatches(e){let t=[],n=new Set,r=0;for(let i of e){let e=i.mesh.userData.geoRef?.pickInfo;if(!e)continue;let a=new Map;for(let[t,n]of Object.entries(e)){let e=__(n);if(e<0)continue;let r=Number(t),i=a.get(e);i?i.push(r):a.set(e,[r])}r+=a.size;for(let[e,r]of a)if(!(r.length<2)){for(let e of r)n.add(e);t.push({datasetId:i.datasetId,batchId:e,smids:r})}}return{smids:0,batches:r,conflicts:t,conflictingSmids:n.size}}_bakeStylesIntoBuffer(e,t,n,r,i){let a=t;for(let t=0;t<a;t++){e[t*4+0]=-1,e[t*4+1]=-1,e[t*4+2]=-1,e[t*4+3]=0;let n=(a+t)*4;e[n+0]=0,e[n+1]=0,e[n+2]=0,e[n+3]=0;let r=(a*2+t)*4;e[r+0]=1,e[r+1]=0,e[r+2]=0,e[r+3]=0;let i=(a*3+t)*4;e[i+0]=0,e[i+1]=1,e[i+2]=0,e[i+3]=0;let o=(a*4+t)*4;e[o+0]=0,e[o+1]=0,e[o+2]=1,e[o+3]=0;let s=(a*5+t)*4;e[s+0]=-1,e[s+1]=0,e[s+2]=0,e[s+3]=0}let o=!1,s=new Set,c=new Map,l=new Map,u=new Map,d=new Map,f=new Map,p=new Map,m=new Map,h=new Map,g=this.filter,_=r.userData;for(let[e,t]of Object.entries(n)){let n=Number(e),o=__(t);if(o<0||o>=a)continue;h.set(o,(h.get(o)??0)+1);let v=!1;if(g&&(g.include&&g.include.length>0&&!g.include.includes(n)&&(v=!0),g.exclude&&g.exclude.length>0&&g.exclude.includes(n)&&(v=!0),g.predicate)){let{segments:e}=y_(_.geoRef,o),t=x_({smid:n,box:b_(r.geometry,e),triangles:0,floorHeight:this._getLayerFloorHeight()});g.predicate({...t,smid:n})||(v=!0)}if(v){s.add(o);continue}if(this.fieldFilter){let e=this.fieldFilter.matched.has(n);if(this.fieldFilter.mode===`keep`?!e:e){s.add(o);continue}}let y=i.get(n);if(y?.hidden){s.add(o);continue}let b=y?.opacity;if(b!=null){if(b<=0){s.add(o);continue}b<1&&!m.has(o)&&m.set(o,b)}let x=y?.color??this.thematicColors.get(n);x&&!c.has(o)&&c.set(o,x);let S=y?.elevation??this.thematicElevation.get(n);if(S!=null&&!l.has(o)&&l.set(o,S),y?.translation&&!u.has(o)&&u.set(o,y.translation),y?.rotation!=null&&!d.has(o)){let e=cC(y.rotation);e&&d.set(o,e)}y?.pivot&&!f.has(o)&&f.set(o,y.pivot),y?.gpuPath&&!p.has(o)&&p.set(o,y.gpuPath)}for(let t of s)e[t*4+3]=-1,o=!0;let v=new W;for(let[t,n]of c)s.has(t)||(v.set(n),e[t*4+0]=v.r,e[t*4+1]=v.g,e[t*4+2]=v.b,o=!0);for(let[t,n]of l){if(s.has(t))continue;e[t*4+3]=n;let r=(a+t)*4;e[r+2]=n,o=!0}for(let[t,n]of u){if(s.has(t))continue;let r=(a+t)*4;e[r+0]=n[0],e[r+1]=n[1],e[r+2]=n[2]+(l.get(t)??0),o=!0}let y=!1;for(let[t,n]of m)s.has(t)||(e[(a+t)*4+3]=n,o=!0,y=!0);for(let[t,n]of d){if(s.has(t))continue;let r=f.get(t)??[0,0,0],i=(a*2+t)*4;e[i+0]=n[0],e[i+1]=n[1],e[i+2]=n[2],e[i+3]=r[0];let c=(a*3+t)*4;e[c+0]=n[3],e[c+1]=n[4],e[c+2]=n[5],e[c+3]=r[1];let l=(a*4+t)*4;e[l+0]=n[6],e[l+1]=n[7],e[l+2]=n[8],e[l+3]=r[2],o=!0}for(let[t,n]of f)d.has(t)||s.has(t)||(e[(a*2+t)*4+3]=n[0],e[(a*3+t)*4+3]=n[1],e[(a*4+t)*4+3]=n[2],o=!0);for(let[t,n]of p){if(s.has(t))continue;let r=(a*5+t)*4;e[r+0]=n.pathId,e[r+1]=n.speed??0,e[r+2]=n.phase??0;let i=1;n.loop===`clamp`||n.loop===!1?i=2:n.loop===`pingpong`&&(i=3),n.autoHeading===!1&&(i+=3),e[r+3]=i,o=!0}let b=0;for(let[e,t]of h)t<2||(s.has(e)||c.has(e)||l.has(e)||d.has(e)||p.has(e))&&b++;return{hasActive:o,hasFade:y,conflicts:b}}applyOverridesToMesh(e){let t=uC(e);if(!t)return;let n=e.userData.geoRef?.pickInfo,r=this.featureStyles.size>0||this.thematicColors.size>0||this.thematicElevation.size>0,i=this.filter,a=this.fieldFilter!=null||i!=null&&((i.include?.length??0)>0||(i.exclude?.length??0)>0||i.predicate!=null);if(!r&&!a||!n||Object.keys(n).length===0){t.userData.uBatchTexActive&&(t.userData.uBatchTexActive.value=0),t.transparent&&!this._isLayerTransparent()&&Eb(t,!1);return}let o=0;for(let e of Object.values(n)){let t=__(e);t>o&&(o=t)}let s=Math.max(o+1,1),c=this._meshBatchTextures.get(e);if(!c||c.width<s){let n=new Float32Array(s*6*4),r=new Du(n,s,6,fi,ii);r.minFilter=Hr,r.magFilter=Hr,c={texture:r,data:n,width:s},this._meshBatchTextures.set(e,c),t.userData.uBatchTex.value=r,t.userData.uBatchTexWidth.value=s}let{data:l,texture:u}=c,{hasActive:d,hasFade:f,conflicts:p}=this._bakeStylesIntoBuffer(l,c.width,n,e,this.featureStyles);f&&!t.transparent?t.transparent=!0:!f&&t.transparent&&!this._isLayerTransparent()&&Eb(t,!1),p>0&&!this._batchConflictWarned&&(this._batchConflictWarned=!0,console.warn(`[s3m] 有 ${p} 个单体状态写不进独立的 batch(多个 SMID 共用同一个 batchId,\n S3M 的单体化粒度只到 batch,无法单独隐藏/改色其中一部分)。
4982
4982
  当前规则:任一 SMID 需要隐藏则整批隐藏,颜色 / 抬高取首个。
4983
- 用 layer.auditBatches() 可以列出具体是哪些 SMID 共用了 batchId。`)),u.needsUpdate=!0,t.userData.uBatchTexActive&&(t.userData.uBatchTexActive.value=+!!d)}prepareCrossFade(e,t){for(let n of t){let t=cC(n);if(!t)continue;let r=n.userData.geoRef?.pickInfo;if(!r||Object.keys(r).length===0)continue;let i=0;for(let e of Object.values(r)){let t=__(e);t>i&&(i=t)}let a=Math.max(i+1,1),o=this._meshBatchTextures.get(n);if(!o||o.width<a){let e=new Float32Array(a*6*4),r=new Du(e,a,6,fi,ii);r.minFilter=Hr,r.magFilter=Hr,o={texture:r,data:e,width:a},this._meshBatchTextures.set(n,o),t.userData.uBatchTex.value=r,t.userData.uBatchTexWidth.value=a}if(!o.texture2||!o.data2||o.data2.length<o.width*6*4){let e=new Float32Array(o.width*6*4),t=new Du(e,o.width,6,fi,ii);t.minFilter=Hr,t.magFilter=Hr,o.data2=e,o.texture2=t}this._bakeStylesIntoBuffer(o.data,o.width,r,n,this.featureStyles),o.texture.needsUpdate=!0;let s=this._bakeStylesIntoBuffer(o.data2,o.width,r,n,e);o.texture2.needsUpdate=!0,t.userData.uBatchTex2.value=o.texture2,t.userData.uBatchTexActive.value=1,s.hasFade&&!t.transparent&&(t.transparent=!0)}}commitCrossFade(e,t){this.featureStyles.clear();for(let[t,n]of e)this.featureStyles.set(t,n);for(let e of t){let t=cC(e);if(!t)continue;let n=this._meshBatchTextures.get(e);n&&n.data2&&n.texture2&&(n.data.set(n.data2),n.texture.needsUpdate=!0,t.userData.uBatchTex2.value=t.userData.uBatchTex.value)}this._onStyleChanged(),this._triggerRepaint()}cancelCrossFade(e){for(let t of e){let e=cC(t);e&&(e.userData.uBatchTex2.value=e.userData.uBatchTex.value)}this._triggerRepaint()}markOverridesDirty(e,t){if(e)for(let t of e)this._markedMeshes.add(t);else if(t)for(let e of t)this._markedMeshes.add(e);else this._dirtyAll=!0,this._markedMeshes.clear();this._flushScheduled||(this._flushScheduled=!0,queueMicrotask(()=>this.flushOverrides()))}disposeMesh(e){this._markedMeshes.delete(e);let t=this._meshBatchTextures.get(e);t&&(t.texture.dispose(),t.texture2?.dispose(),this._meshBatchTextures.delete(e))}flushOverrides(){if(!this._flushScheduled&&!this._dirtyAll&&this._markedMeshes.size===0)return;this._flushScheduled=!1;let e=this._applyOverrideHook??(e=>this.applyOverridesToMesh(e));if(this._dirtyAll){this._dirtyAll=!1,this._markedMeshes.clear();let t=this._getAllMeshes?this._getAllMeshes():[];for(let n of t)e(n);this._triggerRepaint()}else{for(let t of this._markedMeshes)e(t);this._markedMeshes.clear(),this._triggerRepaint()}}bindGPUPath(e,t,n={},r){let i=this.getFeatureStyle(e)??{};this.setFeatureStyle(e,{...i,gpuPath:{pathId:t,speed:n.speed??0,phase:n.phase??0,loop:n.loop??`loop`,autoHeading:n.autoHeading??!0}},r)}unbindGPUPath(e,t){let n=this.getFeatureStyle(e);if(!n||!n.gpuPath)return;let r={...n};delete r.gpuPath,this.setFeatureStyle(e,r,t)}setGPUPathProgress(e,t,n){let r=this.getFeatureStyle(e);r?.gpuPath&&this.setFeatureStyle(e,{...r,gpuPath:{...r.gpuPath,speed:0,phase:Math.min(1,Math.max(0,t))}},n)}};sh(),w_(),Bx(),mh();var pC=65534,mC=class{constructor(e){X(this,`host`,void 0),X(this,`pickables`,new Map),X(this,`_pickSeq`,0),X(this,`_freePickIds`,[]),this.host=e}allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>pC){for(let e=0;e<=pC;e++)if(!this.pickables.has(e))return e;throw Error(`[s3m] 可拾取网格超过 65535 个,2 字节 ID 编码不够用`)}return this._pickSeq++}releasePickId(e){this._freePickIds.push(e)}meshes(){let e=[];for(let t of this.pickables.values())e.push(t.mesh);return e}clear(){this.pickables.clear(),this._freePickIds.length=0,this._pickSeq=0}getRayAt(e,t){if(!this.host.camera||!this.host.canvas)return null;let n=this.host.canvas,r=n.clientWidth||n.width,i=n.clientHeight||n.height;if(!r||!i)return null;let a=e/r*2-1,o=-(t/i)*2+1,s=new H(a,o,-1).unproject(this.host.camera),c=new H(a,o,1).unproject(this.host.camera).clone().sub(s).normalize();return new Wo(s,c)}intersectMeshAtRay(e,t,n){let r=new bm;r.ray.copy(t);let i=r.intersectObject(e,!1);if(!i.length)return null;if(n!=null){let e=i.find(e=>e.instanceId===n);return e?e.point:i[0].point}return i[0].point}buildPickResult(e,t,n,r){let i=t.mesh.userData;if(i.isGaussianSplat)return this.buildSplatPickResult(e,t,n,r);let a=null,o=e.batchId,s=e.instanceIndex,c=i.geoRef,l=[];if(s!=null){let e=this.instanceFeature(t.mesh,c,s);if(!e)return null;a=e.smid,o=e.batchId}else{c=i.geoByBatchId?.get(e.batchId)??i.geoRef;let t=y_(c,e.batchId);a=t.smid,l=t.segments}if(this.host.isFeatureHidden(a,o))return null;let u=null,d=0;if(s!=null)u=this.instanceBox(t.mesh,s),d=t.mesh.geometry.index?Math.round(t.mesh.geometry.index.count/3):0;else if(a!=null&&this.host.smidMeshes.has(a)){let e=this.host.smidMeshes.get(a),t=1/0,n=1/0,r=1/0,i=-1/0,o=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,f=u?.[a]??u?.[String(a)],p=f?__(f):-1,m=f?.segments??(p>=0?y_(e.geoRef,p).segments:[]),h=b_(l.geometry,m);h&&(h.minX<t&&(t=h.minX),h.minY<n&&(n=h.minY),h.minZ<r&&(r=h.minZ),h.maxX>i&&(i=h.maxX),h.maxY>o&&(o=h.maxY),h.maxZ>s&&(s=h.maxZ),c+=h.count,d+=h.triangles)}c>0&&(u={minX:t,minY:n,minZ:r,maxX:i,maxY:o,maxZ:s,count:c,triangles:d})}if(!u&&(u=b_(t.mesh.geometry,l),!u&&t.mesh.geometry)){t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let e=t.mesh.geometry.boundingBox;e&&(u={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}let f=t.mesh.geometry,p=d>0?d:f.index?Math.round(f.index.count/3):0,m=x_({smid:a,box:u,triangles:p,floorHeight:this.host.style.floorHeight}),h=null;if(u&&this.host.sceneAnchor){let e=new H((u.minX+u.maxX)/2,(u.minY+u.maxY)/2,(u.minZ+u.maxZ)/2);e.applyMatrix4(t.mesh.matrixWorld);let n=this.host.sceneAnchor.meterInMercator;h=this.host.lngLatFromWorld(e.x*n+this.host.sceneAnchor.x,-e.y*n+this.host.sceneAnchor.y)}let g=n??null;!g&&r&&(g=this.intersectMeshAtRay(t.mesh,r,s));let _=null,v=null,y=null;if(g&&this.host.sceneAnchor){let e=a==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(a),t=e.translation,n=e.elevation,r=g.clone();if(e.rotation){let t=oC(e.rotation);if(t){let n=new V().set(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]),i=e.pivot?new H(e.pivot[0],e.pivot[1],e.pivot[2]):new H(0,0,0);r.sub(i).applyMatrix3(n).add(i)}}t?r.add(new H(t[0],t[1],t[2])):n&&(r.z+=n),_=[r.x,r.y,r.z];let i=this.host.sceneAnchor.meterInMercator;v=this.host.lngLatFromWorld(r.x*i+this.host.sceneAnchor.x,-r.y*i+this.host.sceneAnchor.y),y=r.z+(this.host.sceneAnchor.altitude??0)}else h&&u&&this.host.sceneAnchor&&(v=h,y=(u.minZ+u.maxZ)/2+(this.host.sceneAnchor.altitude??0));return{datasetId:t.datasetId,datasetName:this.host.datasets.get(t.datasetId)?.name??t.datasetId,objectId:e.objectId,batchId:o,instanceIndex:s,skeletonName:t.skeletonName,centerLngLat:h,point:_,lngLat:v,altitude:y,...m,mesh:t.mesh}}buildSplatPickResult(e,t,n,r){let i=this.host.sceneAnchor;if(!i)return null;let a=t.mesh,o=n??null;!o&&r&&(o=this.intersectMeshAtRay(a,r));let s=Fx(a.geometry),c=s?{minX:s.minX,minY:s.minY,minZ:s.minZ,maxX:s.maxX,maxY:s.maxY,maxZ:s.maxZ,count:s.count,triangles:0}:null,l=x_({smid:null,box:c,triangles:0,floorHeight:this.host.style.floorHeight}),u=i.meterInMercator,d=null,f=null,p=null,m=null;if(o)d=[o.x,o.y,o.z],f=this.host.lngLatFromWorld(o.x*u+i.x,-o.y*u+i.y),p=o.z+(i.altitude??0),m=f;else if(c){let e=new H((c.minX+c.maxX)/2,(c.minY+c.maxY)/2,(c.minZ+c.maxZ)/2).applyMatrix4(a.matrixWorld);m=this.host.lngLatFromWorld(e.x*u+i.x,-e.y*u+i.y),p=e.z+(i.altitude??0)}return{datasetId:t.datasetId,datasetName:this.host.datasets.get(t.datasetId)?.name??t.datasetId,objectId:e.objectId,batchId:-1,instanceIndex:void 0,skeletonName:t.skeletonName,centerLngLat:m,point:d,lngLat:f,altitude:p,...l,mesh:a}}pick(e,t){if(!this.host.picker||!this.host.scene||!this.host.camera||!this.host.sceneAnchor)return null;let n=this.host.picker.pick(this.host.scene,this.host.camera,e,t);if(!n)return null;let r=this.pickables.get(n.objectId);if(!r)return null;let i=this.getRayAt(e,t);return this.buildPickResult(n,r,void 0,i??void 0)}pickPosition(e,t){if(!this.host.camera||!this.host.sceneAnchor)return null;let n=this.pick(e,t);if(n?.point&&n?.lngLat&&n.altitude!=null)return{lngLat:n.lngLat,altitude:n.altitude,point:n.point};let r=this.getRayAt(e,t);if(!r)return null;let i=new Pc(new H(0,0,1),0),a=new H,o=r.intersectPlane(i,a);if(o){let e=this.host.sceneAnchor.meterInMercator;return{lngLat:this.host.lngLatFromWorld(o.x*e+this.host.sceneAnchor.x,-o.y*e+this.host.sceneAnchor.y),altitude:o.z+(this.host.sceneAnchor.altitude??0),point:[o.x,o.y,o.z]}}return null}drillPick(e,t,n=10){if(!this.host.sceneAnchor||!this.host.camera)return[];let r=this.getRayAt(e,t);if(!r)return[];let i=new bm;i.ray.copy(r);let a=[...this.pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),o=i.intersectObjects(a,!1);if(!o.length)return[];let s=[],c=new Set,l=new Set;for(let e of o){if(s.length>=n)break;let t=e.object,r=t.userData;if(r.pickId==null)continue;let i=this.pickables.get(r.pickId);if(!i)continue;let a=null,o=-1,u=e.instanceId;if(u!=null){let e=this.instanceFeature(t,r.geoRef,u);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let n=t.geometry.attributes.aBatchId;if(n){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(n.getX(i)),a=y_(r.geoByBatchId?.get(o)??r.geoRef,o).smid}}if(a!=null){if(c.has(a))continue;c.add(a)}else{let e=`${r.pickId}:${o}:${u??-1}`;if(l.has(e))continue;l.add(e)}if(this.host.isFeatureHidden(a,o))continue;let d={objectId:r.pickId,batchId:o,instanceIndex:u},f=this.buildPickResult(d,i,e.point);f&&s.push(f)}return s}getFeatureBounds(e){if(!this.host.sceneAnchor)return null;let t=1/0,n=-1/0,r=1/0,i=-1/0,a=!1;for(let o of this.pickables.values()){let s=o.mesh,c=s.userData,l=c.geoRef,u=l?.pickInfo;if(!u)continue;let d=null;if(s.isInstancedMesh){let t=c.instanceLookup;t||(t=v_(u),c.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){d=this.instanceBox(s,n);break}}else{let t=u,n=t[e]??t[String(e)];if(n){let e=y_(l,__(n));if(d=b_(s.geometry,e.segments),!d&&s.geometry){s.geometry.boundingBox||s.geometry.computeBoundingBox();let e=s.geometry.boundingBox;e&&(d={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}}}if(d){a=!0;let o=[new H(d.minX,d.minY,d.minZ),new H(d.maxX,d.minY,d.minZ),new H(d.minX,d.maxY,d.minZ),new H(d.maxX,d.maxY,d.minZ),new H(d.minX,d.minY,d.maxZ),new H(d.maxX,d.minY,d.maxZ),new H(d.minX,d.maxY,d.maxZ),new H(d.maxX,d.maxY,d.maxZ)],c=e==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(e),l=c.translation,u=c.elevation,f=c.rotation?oC(c.rotation):null,p=null,m=null;f&&(p=new V().set(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]),m=c.pivot?new H(c.pivot[0],c.pivot[1],c.pivot[2]):new H(0,0,0));let h=e==null?null:this.host.gpuPathPoseAt(e),g=null;if(h&&h.yaw!==0){let e=Math.cos(h.yaw),t=Math.sin(h.yaw);g=new V().set(e,-t,0,t,e,0,0,0,1)}for(let e of o){if(p&&m&&e.sub(m).applyMatrix3(p).add(m),g){let t=m??new H(0,0,0);e.sub(t).applyMatrix3(g).add(t)}l?e.add(new H(l[0],l[1],l[2])):u&&(e.z+=u),h&&e.add(new H(h.pos[0],h.pos[1],h.pos[2])),e.applyMatrix4(s.matrixWorld);let a=this.host.sceneAnchor.meterInMercator,[o,c]=this.host.lngLatFromWorld(e.x*a+this.host.sceneAnchor.x,-e.y*a+this.host.sceneAnchor.y);o<t&&(t=o),o>n&&(n=o),c<r&&(r=c),c>i&&(i=c)}}}return a?[[t,r],[n,i]]:null}instanceFeature(e,t,n){let r=e.userData;return r.instanceLookup||(r.instanceLookup=v_(t?.pickInfo)),r.instanceLookup.get(n)??null}instanceBox(e,t){let n=e;if(!n.isInstancedMesh)return null;let r=e.geometry;r.boundingBox||r.computeBoundingBox();let i=r.boundingBox;if(!i)return null;let a=new U;n.getMatrixAt(t,a);let o=i.clone().applyMatrix4(a);return{minX:o.min.x,minY:o.min.y,minZ:o.min.z,maxX:o.max.x,maxY:o.max.y,maxZ:o.max.z,count:r.getAttribute(`position`)?.count??0,triangles:r.index?Math.round(r.index.count/3):0}}};sh(),w_(),mh();function hC(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function gC(e){let t=e??1;return t<0?0:t>1?1:t}function _C(e){return e.isPoints===!0}var vC=class{constructor(e){X(this,`host`,void 0),X(this,`selection`,null),X(this,`selectedMeshes`,[]),X(this,`_outlineMeshes`,[]),X(this,`_selectionEdgeMeshes`,[]),this.host=e}get selectionEdgeMeshes(){return this._selectionEdgeMeshes}reset(){this.selection=null,this.selectedMeshes=[],this._outlineMeshes=[],this._selectionEdgeMeshes=[]}select(e,{silent:t=!1}={}){if(this.selection){for(let e of this.selectedMeshes){if(_C(e)){this.host.applyPointCloudStyle(e,!1);continue}let t=hC(e);t&&(t.userData.uSelBatch.value=-1,t.userData.uSelWhole.value=0)}this.selectedMeshes=[],this.clearDecoration(),this.selection=null}if(!e){this.host.uniforms.uSelMix.value=0,this.host.uniforms.uDim.value=0,this.host.outlineMaterial.uniforms.uSelBatch.value=-1,this.host.outlineMaterial.uniforms.uSelWhole.value=0,this.host.outlineMaterial.uniforms.uElevation.value=0,this.host.requestRepaint(),t||this.host.onPick(null);return}this.selection=e;let n=new Set;if(e.smid!=null){let t=this.host.smidMeshes.get(e.smid);if(t)for(let e of t)n.add(e)}n.add(e.mesh);for(let t of n){let n=hC(t);if(!n)continue;let r=e.batchId;if(e.instanceIndex!=null&&t===e.mesh)r=e.batchId;else if(e.smid!=null){let n=t.userData.geoRef?.pickInfo,i=n?.[e.smid]??n?.[String(e.smid)],a=i?__(i):-1;r=a>=0?a:t===e.mesh?e.batchId:-1}n.userData.uSelBatch.value=r,n.userData.uSelWhole.value=+(r<0),this.selectedMeshes.push(t)}for(let e of this.selectedMeshes)_C(e)&&this.host.applyPointCloudStyle(e,!0);if(this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers,this.host.style.outline){let t=[...n].filter(e=>!_C(e));t.length&&((this.host.style.outlineStyle??`edges`)===`edges`?this.addSelectionEdges(e,t):this.addSelectionHull(e,t))}this.host.requestRepaint()}addSelectionEdges(e,t){this.syncStyle();for(let n of t){let t=n.userData,r=t.geoRef,i=[],a=-1;if(n===e.mesh&&e.instanceIndex!=null){i=[{vertexOffset:0,vertexCount:n.geometry.getAttribute(`position`)?.count??0}];let t=r?.pickInfo,o=t?.[e.smid??``]??t?.[String(e.smid)];a=o?__(o):-1}else if(e.smid!=null){let t=r?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],o=n?__(n):-1;a=o,i=n?.segments??(o>=0?y_(r,o).segments:[])}else n===e.mesh&&(i=y_(t.geoByBatchId?.get(e.batchId)??r,e.batchId).segments,a=e.batchId);let o=YS(n.geometry,i);if(o&&o.length>0){let t=a>=0?new Float32Array(o.length/6).fill(a):void 0,r=new hc(WS(o,t),this.host.createSelectionEdgeMaterial(n));r.renderOrder=4,r.frustumCulled=!1,r.raycast=()=>{},r.userData.isSelectionEdge=!0,n===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(r,e),n.add(r),this._selectionEdgeMeshes.push(r)}}this._selectionEdgeMeshes.length===0&&this.addSelectionHull(e,t)}applyInstanceTransform(e,t){let n=t.mesh;if(t.instanceIndex==null||!n.isInstancedMesh)return;let r=new U;n.getMatrixAt(t.instanceIndex,r),r.decompose(e.position,e.quaternion,e.scale)}addSelectionHull(e,t){let n=e.instanceIndex!=null;this.host.outlineMaterial.uniforms.uSelBatch.value=n?-1:e.batchId,this.host.outlineMaterial.uniforms.uSelWhole.value=n||e.batchId<0?1:0,this.host.outlineMaterial.uniforms.uElevation.value=n?this.selectionElevation(e):this.host.style.selectElevation??0;for(let n of t){let t=hC(n);t?.userData?.uBatchTex&&(this.host.outlineMaterial.uniforms.uBatchTex.value=t.userData.uBatchTex.value,this.host.outlineMaterial.uniforms.uBatchTexWidth.value=t.userData.uBatchTexWidth.value,this.host.outlineMaterial.uniforms.uBatchTexActive.value=t.userData.uBatchTexActive.value);let r=new hc(n.geometry,this.host.outlineMaterial);r.renderOrder=3,r.frustumCulled=!1,r.raycast=()=>{},n===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(r,e),n.add(r),this._outlineMeshes.push(r)}}syncStyle(){let e=this.host.style,t=this.host.selectionEdgeMaterial.uniforms;t.uColor.value.set(e.outlineColor??e.selectColor),t.uWidth.value=Math.max(.1,e.outlineWidthPx??3),t.uOpacity.value=gC(e.opacity),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?hC(t)?.userData:null;n?.uBatchTex&&(this.host.outlineMaterial.uniforms.uBatchTex.value=n.uBatchTex.value,this.host.outlineMaterial.uniforms.uBatchTexWidth.value=n.uBatchTexWidth.value,this.host.outlineMaterial.uniforms.uBatchTexActive.value=n.uBatchTexActive.value)}}selectionElevation(e){let t=this.host.style.selectElevation??0;if(e.smid!=null){let n=this.host.featureStyleManager.getFeatureEffectiveOffset(e.smid);n.elevation&&(t+=n.elevation)}return t}clearDecoration(){for(let e of this._outlineMeshes)e.parent?.remove(e);this._outlineMeshes=[];for(let e of this._selectionEdgeMeshes)e.parent?.remove(e),e.geometry.dispose();this._selectionEdgeMeshes=[]}isMeshCoveringSelection(e,t){if(!t.point)return!1;let n=e.geometry;if(!n||(n.boundingBox||n.computeBoundingBox(),!n.boundingBox))return!1;let r=new H(t.point[0],t.point[1],t.point[2]);e.updateWorldMatrix(!0,!1);let i=e.matrixWorld.clone().invert(),a=r.applyMatrix4(i);return n.boundingBox.clone().expandByScalar(.5).containsPoint(a)}replayOnto(e){let t=this.selection;if(!t)return;let n=hC(e);if(!n)return;let r=e.userData,i=-1;if(t.smid!=null){let e=r.geoRef?.pickInfo,n=e?.[t.smid]??e?.[String(t.smid)];i=n?__(n):-1}if(e===t.mesh&&(i=t.batchId),i<0&&e!==t.mesh){if(t.smid==null&&r.datasetId===t.datasetId&&this.isMeshCoveringSelection(e,t))i=-1;else return}n.userData.uSelBatch.value=i,n.userData.uSelWhole.value=+(i<0),this.selectedMeshes.includes(e)||this.selectedMeshes.push(e),_C(e)&&this.host.applyPointCloudStyle(e,!0),this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers}};sh(),Qb();var yC=2;function bC(e){return e===Ob.SOLID?`solid`:e===Ob.HEIGHT?`height`:`vertex`}var xC=`
4983
+ 用 layer.auditBatches() 可以列出具体是哪些 SMID 共用了 batchId。`)),u.needsUpdate=!0,t.userData.uBatchTexActive&&(t.userData.uBatchTexActive.value=+!!d)}prepareCrossFade(e,t){for(let n of t){let t=uC(n);if(!t)continue;let r=n.userData.geoRef?.pickInfo;if(!r||Object.keys(r).length===0)continue;let i=0;for(let e of Object.values(r)){let t=__(e);t>i&&(i=t)}let a=Math.max(i+1,1),o=this._meshBatchTextures.get(n);if(!o||o.width<a){let e=new Float32Array(a*6*4),r=new Du(e,a,6,fi,ii);r.minFilter=Hr,r.magFilter=Hr,o={texture:r,data:e,width:a},this._meshBatchTextures.set(n,o),t.userData.uBatchTex.value=r,t.userData.uBatchTexWidth.value=a}if(!o.texture2||!o.data2||o.data2.length<o.width*6*4){let e=new Float32Array(o.width*6*4),t=new Du(e,o.width,6,fi,ii);t.minFilter=Hr,t.magFilter=Hr,o.data2=e,o.texture2=t}this._bakeStylesIntoBuffer(o.data,o.width,r,n,this.featureStyles),o.texture.needsUpdate=!0;let s=this._bakeStylesIntoBuffer(o.data2,o.width,r,n,e);o.texture2.needsUpdate=!0,t.userData.uBatchTex2.value=o.texture2,t.userData.uBatchTexActive.value=1,s.hasFade&&!t.transparent&&(t.transparent=!0)}}commitCrossFade(e,t){this.featureStyles.clear();for(let[t,n]of e)this.featureStyles.set(t,n);for(let e of t){let t=uC(e);if(!t)continue;let n=this._meshBatchTextures.get(e);n&&n.data2&&n.texture2&&(n.data.set(n.data2),n.texture.needsUpdate=!0,t.userData.uBatchTex2.value=t.userData.uBatchTex.value)}this._onStyleChanged(),this._triggerRepaint()}cancelCrossFade(e){for(let t of e){let e=uC(t);e&&(e.userData.uBatchTex2.value=e.userData.uBatchTex.value)}this._triggerRepaint()}markOverridesDirty(e,t){if(e)for(let t of e)this._markedMeshes.add(t);else if(t)for(let e of t)this._markedMeshes.add(e);else this._dirtyAll=!0,this._markedMeshes.clear();this._flushScheduled||(this._flushScheduled=!0,queueMicrotask(()=>this.flushOverrides()))}disposeMesh(e){this._markedMeshes.delete(e);let t=this._meshBatchTextures.get(e);t&&(t.texture.dispose(),t.texture2?.dispose(),this._meshBatchTextures.delete(e))}flushOverrides(){if(!this._flushScheduled&&!this._dirtyAll&&this._markedMeshes.size===0)return;this._flushScheduled=!1;let e=this._applyOverrideHook??(e=>this.applyOverridesToMesh(e));if(this._dirtyAll){this._dirtyAll=!1,this._markedMeshes.clear();let t=this._getAllMeshes?this._getAllMeshes():[];for(let n of t)e(n);this._triggerRepaint()}else{for(let t of this._markedMeshes)e(t);this._markedMeshes.clear(),this._triggerRepaint()}}bindGPUPath(e,t,n={},r){let i=this.getFeatureStyle(e)??{};this.setFeatureStyle(e,{...i,gpuPath:{pathId:t,speed:n.speed??0,phase:n.phase??0,loop:n.loop??`loop`,autoHeading:n.autoHeading??!0}},r)}unbindGPUPath(e,t){let n=this.getFeatureStyle(e);if(!n||!n.gpuPath)return;let r={...n};delete r.gpuPath,this.setFeatureStyle(e,r,t)}setGPUPathProgress(e,t,n){let r=this.getFeatureStyle(e);r?.gpuPath&&this.setFeatureStyle(e,{...r,gpuPath:{...r.gpuPath,speed:0,phase:Math.min(1,Math.max(0,t))}},n)}};sh(),w_(),Bx(),mh();var hC=65534,gC=class{constructor(e){X(this,`host`,void 0),X(this,`pickables`,new Map),X(this,`_pickSeq`,0),X(this,`_freePickIds`,[]),this.host=e}allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>hC){for(let e=0;e<=hC;e++)if(!this.pickables.has(e))return e;throw Error(`[s3m] 可拾取网格超过 65535 个,2 字节 ID 编码不够用`)}return this._pickSeq++}releasePickId(e){this._freePickIds.push(e)}meshes(){let e=[];for(let t of this.pickables.values())e.push(t.mesh);return e}clear(){this.pickables.clear(),this._freePickIds.length=0,this._pickSeq=0}getRayAt(e,t){if(!this.host.camera||!this.host.canvas)return null;let n=this.host.canvas,r=n.clientWidth||n.width,i=n.clientHeight||n.height;if(!r||!i)return null;let a=e/r*2-1,o=-(t/i)*2+1,s=new H(a,o,-1).unproject(this.host.camera),c=new H(a,o,1).unproject(this.host.camera).clone().sub(s).normalize();return new Wo(s,c)}intersectMeshAtRay(e,t,n){let r=new bm;r.ray.copy(t);let i=r.intersectObject(e,!1);if(!i.length)return null;if(n!=null){let e=i.find(e=>e.instanceId===n);return e?e.point:i[0].point}return i[0].point}buildPickResult(e,t,n,r){let i=t.mesh.userData;if(i.isGaussianSplat)return this.buildSplatPickResult(e,t,n,r);let a=null,o=e.batchId,s=e.instanceIndex,c=i.geoRef,l=[];if(s!=null){let e=this.instanceFeature(t.mesh,c,s);if(!e)return null;a=e.smid,o=e.batchId}else{c=i.geoByBatchId?.get(e.batchId)??i.geoRef;let t=y_(c,e.batchId);a=t.smid,l=t.segments}if(this.host.isFeatureHidden(a,o))return null;let u=null,d=0;if(s!=null)u=this.instanceBox(t.mesh,s),d=t.mesh.geometry.index?Math.round(t.mesh.geometry.index.count/3):0;else if(a!=null&&this.host.smidMeshes.has(a)){let e=this.host.smidMeshes.get(a),t=1/0,n=1/0,r=1/0,i=-1/0,o=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,f=u?.[a]??u?.[String(a)],p=f?__(f):-1,m=f?.segments??(p>=0?y_(e.geoRef,p).segments:[]),h=b_(l.geometry,m);h&&(h.minX<t&&(t=h.minX),h.minY<n&&(n=h.minY),h.minZ<r&&(r=h.minZ),h.maxX>i&&(i=h.maxX),h.maxY>o&&(o=h.maxY),h.maxZ>s&&(s=h.maxZ),c+=h.count,d+=h.triangles)}c>0&&(u={minX:t,minY:n,minZ:r,maxX:i,maxY:o,maxZ:s,count:c,triangles:d})}if(!u&&(u=b_(t.mesh.geometry,l),!u&&t.mesh.geometry)){t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let e=t.mesh.geometry.boundingBox;e&&(u={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}let f=t.mesh.geometry,p=d>0?d:f.index?Math.round(f.index.count/3):0,m=x_({smid:a,box:u,triangles:p,floorHeight:this.host.style.floorHeight}),h=null;if(u&&this.host.sceneAnchor){let e=new H((u.minX+u.maxX)/2,(u.minY+u.maxY)/2,(u.minZ+u.maxZ)/2);e.applyMatrix4(t.mesh.matrixWorld);let n=this.host.sceneAnchor.meterInMercator;h=this.host.lngLatFromWorld(e.x*n+this.host.sceneAnchor.x,-e.y*n+this.host.sceneAnchor.y)}let g=n??null;!g&&r&&(g=this.intersectMeshAtRay(t.mesh,r,s));let _=null,v=null,y=null;if(g&&this.host.sceneAnchor){let e=a==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(a),t=e.translation,n=e.elevation,r=g.clone();if(e.rotation){let t=cC(e.rotation);if(t){let n=new V().set(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]),i=e.pivot?new H(e.pivot[0],e.pivot[1],e.pivot[2]):new H(0,0,0);r.sub(i).applyMatrix3(n).add(i)}}t?r.add(new H(t[0],t[1],t[2])):n&&(r.z+=n),_=[r.x,r.y,r.z];let i=this.host.sceneAnchor.meterInMercator;v=this.host.lngLatFromWorld(r.x*i+this.host.sceneAnchor.x,-r.y*i+this.host.sceneAnchor.y),y=r.z+(this.host.sceneAnchor.altitude??0)}else h&&u&&this.host.sceneAnchor&&(v=h,y=(u.minZ+u.maxZ)/2+(this.host.sceneAnchor.altitude??0));return{datasetId:t.datasetId,datasetName:this.host.datasets.get(t.datasetId)?.name??t.datasetId,objectId:e.objectId,batchId:o,instanceIndex:s,skeletonName:t.skeletonName,centerLngLat:h,point:_,lngLat:v,altitude:y,...m,mesh:t.mesh}}buildSplatPickResult(e,t,n,r){let i=this.host.sceneAnchor;if(!i)return null;let a=t.mesh,o=n??null;!o&&r&&(o=this.intersectMeshAtRay(a,r));let s=Fx(a.geometry),c=s?{minX:s.minX,minY:s.minY,minZ:s.minZ,maxX:s.maxX,maxY:s.maxY,maxZ:s.maxZ,count:s.count,triangles:0}:null,l=x_({smid:null,box:c,triangles:0,floorHeight:this.host.style.floorHeight}),u=i.meterInMercator,d=null,f=null,p=null,m=null;if(o)d=[o.x,o.y,o.z],f=this.host.lngLatFromWorld(o.x*u+i.x,-o.y*u+i.y),p=o.z+(i.altitude??0),m=f;else if(c){let e=new H((c.minX+c.maxX)/2,(c.minY+c.maxY)/2,(c.minZ+c.maxZ)/2).applyMatrix4(a.matrixWorld);m=this.host.lngLatFromWorld(e.x*u+i.x,-e.y*u+i.y),p=e.z+(i.altitude??0)}return{datasetId:t.datasetId,datasetName:this.host.datasets.get(t.datasetId)?.name??t.datasetId,objectId:e.objectId,batchId:-1,instanceIndex:void 0,skeletonName:t.skeletonName,centerLngLat:m,point:d,lngLat:f,altitude:p,...l,mesh:a}}pick(e,t){if(!this.host.picker||!this.host.scene||!this.host.camera||!this.host.sceneAnchor)return null;let n=this.host.picker.pick(this.host.scene,this.host.camera,e,t);if(!n)return null;let r=this.pickables.get(n.objectId);if(!r)return null;let i=this.getRayAt(e,t);return this.buildPickResult(n,r,void 0,i??void 0)}pickPosition(e,t){if(!this.host.camera||!this.host.sceneAnchor)return null;let n=this.pick(e,t);if(n?.point&&n?.lngLat&&n.altitude!=null)return{lngLat:n.lngLat,altitude:n.altitude,point:n.point};let r=this.getRayAt(e,t);if(!r)return null;let i=new Pc(new H(0,0,1),0),a=new H,o=r.intersectPlane(i,a);if(o){let e=this.host.sceneAnchor.meterInMercator;return{lngLat:this.host.lngLatFromWorld(o.x*e+this.host.sceneAnchor.x,-o.y*e+this.host.sceneAnchor.y),altitude:o.z+(this.host.sceneAnchor.altitude??0),point:[o.x,o.y,o.z]}}return null}drillPick(e,t,n=10){if(!this.host.sceneAnchor||!this.host.camera)return[];let r=this.getRayAt(e,t);if(!r)return[];let i=new bm;i.ray.copy(r);let a=[...this.pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),o=i.intersectObjects(a,!1);if(!o.length)return[];let s=[],c=new Set,l=new Set;for(let e of o){if(s.length>=n)break;let t=e.object,r=t.userData;if(r.pickId==null)continue;let i=this.pickables.get(r.pickId);if(!i)continue;let a=null,o=-1,u=e.instanceId;if(u!=null){let e=this.instanceFeature(t,r.geoRef,u);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let n=t.geometry.attributes.aBatchId;if(n){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(n.getX(i)),a=y_(r.geoByBatchId?.get(o)??r.geoRef,o).smid}}if(a!=null){if(c.has(a))continue;c.add(a)}else{let e=`${r.pickId}:${o}:${u??-1}`;if(l.has(e))continue;l.add(e)}if(this.host.isFeatureHidden(a,o))continue;let d={objectId:r.pickId,batchId:o,instanceIndex:u},f=this.buildPickResult(d,i,e.point);f&&s.push(f)}return s}getFeatureBounds(e){if(!this.host.sceneAnchor)return null;let t=1/0,n=-1/0,r=1/0,i=-1/0,a=!1;for(let o of this.pickables.values()){let s=o.mesh,c=s.userData,l=c.geoRef,u=l?.pickInfo;if(!u)continue;let d=null;if(s.isInstancedMesh){let t=c.instanceLookup;t||(t=v_(u),c.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){d=this.instanceBox(s,n);break}}else{let t=u,n=t[e]??t[String(e)];if(n){let e=y_(l,__(n));if(d=b_(s.geometry,e.segments),!d&&s.geometry){s.geometry.boundingBox||s.geometry.computeBoundingBox();let e=s.geometry.boundingBox;e&&(d={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}}}if(d){a=!0;let o=[new H(d.minX,d.minY,d.minZ),new H(d.maxX,d.minY,d.minZ),new H(d.minX,d.maxY,d.minZ),new H(d.maxX,d.maxY,d.minZ),new H(d.minX,d.minY,d.maxZ),new H(d.maxX,d.minY,d.maxZ),new H(d.minX,d.maxY,d.maxZ),new H(d.maxX,d.maxY,d.maxZ)],c=e==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(e),l=c.translation,u=c.elevation,f=c.rotation?cC(c.rotation):null,p=null,m=null;f&&(p=new V().set(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]),m=c.pivot?new H(c.pivot[0],c.pivot[1],c.pivot[2]):new H(0,0,0));let h=e==null?null:this.host.gpuPathPoseAt(e),g=null;if(h&&h.yaw!==0){let e=Math.cos(h.yaw),t=Math.sin(h.yaw);g=new V().set(e,-t,0,t,e,0,0,0,1)}for(let e of o){if(p&&m&&e.sub(m).applyMatrix3(p).add(m),g){let t=m??new H(0,0,0);e.sub(t).applyMatrix3(g).add(t)}l?e.add(new H(l[0],l[1],l[2])):u&&(e.z+=u),h&&e.add(new H(h.pos[0],h.pos[1],h.pos[2])),e.applyMatrix4(s.matrixWorld);let a=this.host.sceneAnchor.meterInMercator,[o,c]=this.host.lngLatFromWorld(e.x*a+this.host.sceneAnchor.x,-e.y*a+this.host.sceneAnchor.y);o<t&&(t=o),o>n&&(n=o),c<r&&(r=c),c>i&&(i=c)}}}return a?[[t,r],[n,i]]:null}instanceFeature(e,t,n){let r=e.userData;return r.instanceLookup||(r.instanceLookup=v_(t?.pickInfo)),r.instanceLookup.get(n)??null}instanceBox(e,t){let n=e;if(!n.isInstancedMesh)return null;let r=e.geometry;r.boundingBox||r.computeBoundingBox();let i=r.boundingBox;if(!i)return null;let a=new U;n.getMatrixAt(t,a);let o=i.clone().applyMatrix4(a);return{minX:o.min.x,minY:o.min.y,minZ:o.min.z,maxX:o.max.x,maxY:o.max.y,maxZ:o.max.z,count:r.getAttribute(`position`)?.count??0,triangles:r.index?Math.round(r.index.count/3):0}}};sh(),w_(),mh();function _C(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function vC(e){let t=e??1;return t<0?0:t>1?1:t}function yC(e){return e.isPoints===!0}var bC=class{constructor(e){X(this,`host`,void 0),X(this,`selection`,null),X(this,`selectedMeshes`,[]),X(this,`_outlineMeshes`,[]),X(this,`_selectionEdgeMeshes`,[]),this.host=e}get selectionEdgeMeshes(){return this._selectionEdgeMeshes}reset(){this.selection=null,this.selectedMeshes=[],this._outlineMeshes=[],this._selectionEdgeMeshes=[]}select(e,{silent:t=!1}={}){if(this.selection){for(let e of this.selectedMeshes){if(yC(e)){this.host.applyPointCloudStyle(e,!1);continue}let t=_C(e);t&&(t.userData.uSelBatch.value=-1,t.userData.uSelWhole.value=0)}this.selectedMeshes=[],this.clearDecoration(),this.selection=null}if(!e){this.host.uniforms.uSelMix.value=0,this.host.uniforms.uDim.value=0,this.host.outlineMaterial.uniforms.uSelBatch.value=-1,this.host.outlineMaterial.uniforms.uSelWhole.value=0,this.host.outlineMaterial.uniforms.uElevation.value=0,this.host.requestRepaint(),t||this.host.onPick(null);return}this.selection=e;let n=new Set;if(e.smid!=null){let t=this.host.smidMeshes.get(e.smid);if(t)for(let e of t)n.add(e)}n.add(e.mesh);for(let t of n){let n=_C(t);if(!n)continue;let r=e.batchId;if(e.instanceIndex!=null&&t===e.mesh)r=e.batchId;else if(e.smid!=null){let n=t.userData.geoRef?.pickInfo,i=n?.[e.smid]??n?.[String(e.smid)],a=i?__(i):-1;r=a>=0?a:t===e.mesh?e.batchId:-1}n.userData.uSelBatch.value=r,n.userData.uSelWhole.value=+(r<0),this.selectedMeshes.push(t)}for(let e of this.selectedMeshes)yC(e)&&this.host.applyPointCloudStyle(e,!0);if(this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers,this.host.style.outline){let t=[...n].filter(e=>!yC(e));t.length&&((this.host.style.outlineStyle??`edges`)===`edges`?this.addSelectionEdges(e,t):this.addSelectionHull(e,t))}this.host.requestRepaint()}addSelectionEdges(e,t){this.syncStyle();for(let n of t){let t=n.userData,r=t.geoRef,i=[],a=-1;if(n===e.mesh&&e.instanceIndex!=null){i=[{vertexOffset:0,vertexCount:n.geometry.getAttribute(`position`)?.count??0}];let t=r?.pickInfo,o=t?.[e.smid??``]??t?.[String(e.smid)];a=o?__(o):-1}else if(e.smid!=null){let t=r?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],o=n?__(n):-1;a=o,i=n?.segments??(o>=0?y_(r,o).segments:[])}else n===e.mesh&&(i=y_(t.geoByBatchId?.get(e.batchId)??r,e.batchId).segments,a=e.batchId);let o=ZS(n.geometry,i);if(o&&o.length>0){let t=a>=0?new Float32Array(o.length/6).fill(a):void 0,r=new hc(KS(o,t),this.host.createSelectionEdgeMaterial(n));r.renderOrder=4,r.frustumCulled=!1,r.raycast=()=>{},r.userData.isSelectionEdge=!0,n===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(r,e),n.add(r),this._selectionEdgeMeshes.push(r)}}this._selectionEdgeMeshes.length===0&&this.addSelectionHull(e,t)}applyInstanceTransform(e,t){let n=t.mesh;if(t.instanceIndex==null||!n.isInstancedMesh)return;let r=new U;n.getMatrixAt(t.instanceIndex,r),r.decompose(e.position,e.quaternion,e.scale)}addSelectionHull(e,t){let n=e.instanceIndex!=null;this.host.outlineMaterial.uniforms.uSelBatch.value=n?-1:e.batchId,this.host.outlineMaterial.uniforms.uSelWhole.value=n||e.batchId<0?1:0,this.host.outlineMaterial.uniforms.uElevation.value=n?this.selectionElevation(e):this.host.style.selectElevation??0;for(let n of t){let t=_C(n);t?.userData?.uBatchTex&&(this.host.outlineMaterial.uniforms.uBatchTex.value=t.userData.uBatchTex.value,this.host.outlineMaterial.uniforms.uBatchTexWidth.value=t.userData.uBatchTexWidth.value,this.host.outlineMaterial.uniforms.uBatchTexActive.value=t.userData.uBatchTexActive.value);let r=new hc(n.geometry,this.host.outlineMaterial);r.renderOrder=3,r.frustumCulled=!1,r.raycast=()=>{},n===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(r,e),n.add(r),this._outlineMeshes.push(r)}}syncStyle(){let e=this.host.style,t=this.host.selectionEdgeMaterial.uniforms;t.uColor.value.set(e.outlineColor??e.selectColor),t.uWidth.value=Math.max(.1,e.outlineWidthPx??3),t.uOpacity.value=vC(e.opacity),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?_C(t)?.userData:null;n?.uBatchTex&&(this.host.outlineMaterial.uniforms.uBatchTex.value=n.uBatchTex.value,this.host.outlineMaterial.uniforms.uBatchTexWidth.value=n.uBatchTexWidth.value,this.host.outlineMaterial.uniforms.uBatchTexActive.value=n.uBatchTexActive.value)}}selectionElevation(e){let t=this.host.style.selectElevation??0;if(e.smid!=null){let n=this.host.featureStyleManager.getFeatureEffectiveOffset(e.smid);n.elevation&&(t+=n.elevation)}return t}clearDecoration(){for(let e of this._outlineMeshes)e.parent?.remove(e);this._outlineMeshes=[];for(let e of this._selectionEdgeMeshes)e.parent?.remove(e),e.geometry.dispose();this._selectionEdgeMeshes=[]}isMeshCoveringSelection(e,t){if(!t.point)return!1;let n=e.geometry;if(!n||(n.boundingBox||n.computeBoundingBox(),!n.boundingBox))return!1;let r=new H(t.point[0],t.point[1],t.point[2]);e.updateWorldMatrix(!0,!1);let i=e.matrixWorld.clone().invert(),a=r.applyMatrix4(i);return n.boundingBox.clone().expandByScalar(.5).containsPoint(a)}replayOnto(e){let t=this.selection;if(!t)return;let n=_C(e);if(!n)return;let r=e.userData,i=-1;if(t.smid!=null){let e=r.geoRef?.pickInfo,n=e?.[t.smid]??e?.[String(t.smid)];i=n?__(n):-1}if(e===t.mesh&&(i=t.batchId),i<0&&e!==t.mesh){if(t.smid==null&&r.datasetId===t.datasetId&&this.isMeshCoveringSelection(e,t))i=-1;else return}n.userData.uSelBatch.value=i,n.userData.uSelWhole.value=+(i<0),this.selectedMeshes.includes(e)||this.selectedMeshes.push(e),yC(e)&&this.host.applyPointCloudStyle(e,!0),this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers}};sh(),Qb();var xC=2;function SC(e){return e===Ob.SOLID?`solid`:e===Ob.HEIGHT?`height`:`vertex`}var CC=`
4984
4984
  uniform float uPointSize;
4985
4985
  varying float vWorldZ;
4986
4986
  void main() {
@@ -4989,7 +4989,7 @@ void main() {
4989
4989
  gl_Position = projectionMatrix * viewMatrix * world;
4990
4990
  gl_PointSize = uPointSize;
4991
4991
  }
4992
- `,SC=`
4992
+ `,wC=`
4993
4993
  uniform vec3 uColorA;
4994
4994
  uniform vec3 uColorB;
4995
4995
  uniform float uHeightMin;
@@ -5000,13 +5000,13 @@ void main() {
5000
5000
  float h = clamp( ( vWorldZ - uHeightMin ) / max( uHeightMax - uHeightMin, 0.001 ), 0.0, 1.0 );
5001
5001
  gl_FragColor = vec4( mix( uColorA, uColorB, h ), uOpacity );
5002
5002
  }
5003
- `,CC=`
5003
+ `,TC=`
5004
5004
  uniform vec3 uSelColor;
5005
5005
  uniform float uOpacity;
5006
5006
  void main() {
5007
5007
  gl_FragColor = vec4( uSelColor, uOpacity );
5008
5008
  }
5009
- `;function wC(e,t,n){let r;return r=e===`height`?new bc({uniforms:{uColorA:n.uColorA,uColorB:n.uColorB,uHeightMin:n.uHeightMin,uHeightMax:n.uHeightMax,uPointSize:{value:yC},uOpacity:{value:t.opacity??1}},vertexShader:xC,fragmentShader:SC,transparent:(t.opacity??1)<.999,depthWrite:(t.opacity??1)>=.999}):e===`selected`?new bc({uniforms:{uSelColor:n.uSelColor,uPointSize:{value:yC},uOpacity:{value:t.opacity??1}},vertexShader:xC,fragmentShader:CC,transparent:(t.opacity??1)<.999,depthWrite:(t.opacity??1)>=.999}):e===`solid`?new hd({size:yC,sizeAttenuation:!1,color:new W(t.colorA),transparent:(t.opacity??1)<.999,opacity:t.opacity??1,depthWrite:(t.opacity??1)>=.999}):new hd({size:yC,sizeAttenuation:!1,vertexColors:!0,transparent:(t.opacity??1)<.999,opacity:t.opacity??1,depthWrite:(t.opacity??1)>=.999}),r.userData.pcOwned=!0,r}function TC(e,t,n,r=!1){let i=e.userData,a=r?`selected`:bC(t.mode);if(i.pcKind!==a){let r=e.material;e.material=wC(a,t,n),r&&r.userData?.pcOwned&&r.dispose(),i.pcKind=a,i.pcTransparent=void 0}else a===`solid`&&e.material.color?.set(t.colorA);let o=Math.min(1,Math.max(.05,t.opacity??1)),s=o<.999,c=t.depthWrite!==!1,l=e.material;l.transparent=s,l.opacity=o,l.depthWrite=!s||c,l.uniforms?.uOpacity&&(l.uniforms.uOpacity.value=o),i.pcTransparent!==s&&(i.pcTransparent=s,l.needsUpdate=!0)}function EC(e){let t=Array.isArray(e)?e[0]:e;return!!t&&t.userData?.pcOwned===!0}sh(),Bx(),mh();var DC=`
5009
+ `;function EC(e,t,n){let r;return r=e===`height`?new bc({uniforms:{uColorA:n.uColorA,uColorB:n.uColorB,uHeightMin:n.uHeightMin,uHeightMax:n.uHeightMax,uPointSize:{value:xC},uOpacity:{value:t.opacity??1}},vertexShader:CC,fragmentShader:wC,transparent:(t.opacity??1)<.999,depthWrite:(t.opacity??1)>=.999}):e===`selected`?new bc({uniforms:{uSelColor:n.uSelColor,uPointSize:{value:xC},uOpacity:{value:t.opacity??1}},vertexShader:CC,fragmentShader:TC,transparent:(t.opacity??1)<.999,depthWrite:(t.opacity??1)>=.999}):e===`solid`?new hd({size:xC,sizeAttenuation:!1,color:new W(t.colorA),transparent:(t.opacity??1)<.999,opacity:t.opacity??1,depthWrite:(t.opacity??1)>=.999}):new hd({size:xC,sizeAttenuation:!1,vertexColors:!0,transparent:(t.opacity??1)<.999,opacity:t.opacity??1,depthWrite:(t.opacity??1)>=.999}),r.userData.pcOwned=!0,r}function DC(e,t,n,r=!1){let i=e.userData,a=r?`selected`:SC(t.mode);if(i.pcKind!==a){let r=e.material;e.material=EC(a,t,n),r&&r.userData?.pcOwned&&r.dispose(),i.pcKind=a,i.pcTransparent=void 0}else a===`solid`&&e.material.color?.set(t.colorA);let o=Math.min(1,Math.max(.05,t.opacity??1)),s=o<.999,c=t.depthWrite!==!1,l=e.material;l.transparent=s,l.opacity=o,l.depthWrite=!s||c,l.uniforms?.uOpacity&&(l.uniforms.uOpacity.value=o),i.pcTransparent!==s&&(i.pcTransparent=s,l.needsUpdate=!0)}function OC(e){let t=Array.isArray(e)?e[0]:e;return!!t&&t.userData?.pcOwned===!0}sh(),Bx(),mh();var kC=`
5010
5010
  attribute float aBatchId;
5011
5011
  #ifdef USE_INSTANCING
5012
5012
  // 实例化:单体粒度在实例上,顶点属性里没有可用的 batchId
@@ -5135,7 +5135,7 @@ void main() {
5135
5135
  // 跟显示尺寸(2px)不匹配,点云会很难点中。对 Mesh 图元这行被忽略。
5136
5136
  gl_PointSize = 2.0;
5137
5137
  }
5138
- `,OC=`
5138
+ `,AC=`
5139
5139
  uniform float uObjectId;
5140
5140
  varying float vBatch;
5141
5141
  void main() {
@@ -5148,7 +5148,7 @@ void main() {
5148
5148
  floor( b / 256.0 ) / 255.0
5149
5149
  );
5150
5150
  }
5151
- `,kC=(()=>{let e=new Du(new Float32Array([-1,-1,-1,0,0,0,0,0]),1,2,fi,ii);return e.minFilter=Hr,e.magFilter=Hr,e.needsUpdate=!0,e})(),AC=(()=>{let e=new Du(new Float32Array([0,0,0,0]),1,1,fi,ii);return e.minFilter=Hr,e.magFilter=Hr,e.needsUpdate=!0,e})();function jC(e){return new bc({uniforms:{uObjectId:{value:e},uBatchTex:{value:kC},uBatchTex2:{value:kC},uBatchMix:{value:0},uBatchTexWidth:{value:1},uBatchTexActive:{value:0},uPathTex:{value:AC},uPathCount:{value:1},uPathTime:{value:0},uPathTexActive:{value:0},uSelBatch:{value:-1},uSelWhole:{value:0},uSelElevation:{value:0}},vertexShader:DC,fragmentShader:OC,side:2,depthTest:!0,depthWrite:!0,toneMapped:!1})}function MC(e){return e.isPoints===!0}var NC=class{constructor(e,t={}){X(this,`renderer`,void 0),X(this,`size`,void 0),X(this,`target`,null),X(this,`buf`,new Uint8Array(4)),this.renderer=e,this.size=Math.max(1,Math.floor(t.size??1))}_ensureTarget(e){return this.target&&this.target.width===e&&this.target.height===e||(this.target?.dispose(),this.target=new uo(e,e,{minFilter:Hr,magFilter:Hr,format:fi,type:Qr,depthBuffer:!0,stencilBuffer:!1}),this.target.texture.colorSpace=_a),this.target}pick(e,t,n,r){let i=this.renderer,a=i.domElement,o=a.width,s=a.height;if(!o||!s)return null;let c=Math.floor(n/a.clientWidth*o),l=Math.floor(r/a.clientHeight*s);if(c<0||l<0||c>=o||l>=s)return null;let u=this._ensureTarget(this.size),d=s-1-l,f=Math.floor(this.size/2),p=Math.floor(this.size/2);u.viewport.set(f-c,p-d,o,s);let m=i.getRenderTarget(),h=i.getViewport(new co),g=i.toneMapping,_=i.outputColorSpace,v=i.autoClear,y=i.getClearColor(new W),b=i.getClearAlpha(),x=[],S=new Set;e.traverseVisible(e=>{let t=e;if(!t.isMesh&&!MC(t))return;let n=t.userData;if(n.pickId===void 0)return;let r=n.isGaussianSplat===!0;n.pickMaterial||(n.pickMaterial=r?Px(n.pickId):jC(n.pickId)),!r&&t.isInstancedMesh&&S.add(n.pickId);let i=t.material,a=n.pickMaterial;if(r){x.push([t,i]),t.material=a;return}let o=Array.isArray(i)?i[0]:i,s=o?.userData?.uBatchTex;s?(a.uniforms.uBatchTex.value=s.value,a.uniforms.uBatchTex2.value=o?.userData?.uBatchTex2?.value??s.value,a.uniforms.uBatchTexWidth.value=o?.userData?.uBatchTexWidth?.value??1,a.uniforms.uBatchTexActive.value=o?.userData?.uBatchTexActive?.value??0):(a.uniforms.uBatchTex.value=kC,a.uniforms.uBatchTex2.value=kC,a.uniforms.uBatchTexWidth.value=1,a.uniforms.uBatchTexActive.value=0),a.uniforms.uBatchMix.value=o?.userData?.uBatchMix?.value??0,a.uniforms.uPathTex.value=o?.userData?.uPathTex?.value??AC,a.uniforms.uPathCount.value=o?.userData?.uPathCount?.value??1,a.uniforms.uPathTime.value=o?.userData?.uPathTime?.value??0,a.uniforms.uPathTexActive.value=o?.userData?.uPathTexActive?.value??0,a.uniforms.uSelBatch.value=o?.userData?.uSelBatch?.value??-1,a.uniforms.uSelWhole.value=o?.userData?.uSelWhole?.value??0,a.uniforms.uSelElevation.value=o?.userData?.uSelElevation?.value??o?.uniforms?.uSelElevation?.value??0,x.push([t,i]),t.material=a});let C=[];e.traverseVisible(e=>{let t=e;(t.isMesh||MC(t))&&t.userData.pickId===void 0&&(C.push(t),t.visible=!1)});let w=null;try{i.resetState(),i.setRenderTarget(u),i.toneMapping=0,i.outputColorSpace=_a,i.autoClear=!0,i.setClearColor(0,0),i.clear(),i.render(e,t),i.readRenderTargetPixels(u,f,p,1,1,this.buf);let n=this.buf[0],r=this.buf[1],a=this.buf[2],o=this.buf[3],s=n+r*256-1,c=a+o*256-1;s>=0&&(w=S.has(s)?{objectId:s,batchId:-1,instanceIndex:Math.max(0,c)}:{objectId:s,batchId:c})}finally{for(let[e,t]of x)e.material=t;for(let e of C)e.visible=!0;i.setRenderTarget(m),i.setViewport(h),i.toneMapping=g,i.outputColorSpace=_,i.autoClear=v,i.setClearColor(y,b),i.resetState()}return w}dispose(){this.target?.dispose(),this.target=null}},PC=1.70158,FC=PC*1.525,IC=2.70158,LC=2*Math.PI/3,RC=2*Math.PI/4.5,zC=7.5625,BC=2.75;function VC(e){if(e<1/BC)return zC*e*e;if(e<2/BC){let t=e-1.5/BC;return zC*t*t+.75}if(e<2.5/BC){let t=e-2.25/BC;return zC*t*t+.9375}let t=e-2.625/BC;return zC*t*t+.984375}function HC(e){return 1-VC(1-e)}var UC={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>1-(1-e)*(1-e),easeInOutQuad:e=>e<.5?2*e*e:1-(-2*e+2)**2/2,easeInCubic:e=>e*e*e,easeOutCubic:e=>1-(1-e)**3,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1-(1-e)**4,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-(-2*e+2)**4/2,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1-(1-e)**5,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1-(-2*e+2)**5/2,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e===0?0:2**(10*e-10),easeOutExpo:e=>e===1?1:1-2**(-10*e),easeInOutExpo:e=>e===0?0:e===1?1:e<.5?2**(20*e-10)/2:(2-2**(-20*e+10))/2,easeInCirc:e=>1-Math.sqrt(1-e*e),easeOutCirc:e=>Math.sqrt(1-(e-1)**2),easeInOutCirc:e=>e<.5?(1-Math.sqrt(1-(2*e)**2))/2:(Math.sqrt(1-(-2*e+2)**2)+1)/2,easeInBack:e=>IC*e*e*e-PC*e*e,easeOutBack:e=>1+IC*(e-1)**3+PC*(e-1)**2,easeInOutBack:e=>e<.5?(2*e)**2*(7.189819*e-FC)/2:((2*e-2)**2*(3.5949095*(e*2-2)+FC)+2)/2,easeInElastic:e=>e===0?0:e===1?1:-(2**(10*e-10))*Math.sin((e*10-10.75)*LC),easeOutElastic:e=>e===0?0:e===1?1:2**(-10*e)*Math.sin((e*10-.75)*LC)+1,easeInOutElastic:e=>e===0?0:e===1?1:e<.5?-(2**(20*e-10)*Math.sin((20*e-11.125)*RC))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*RC)/2+1,easeInBounce:HC,easeOutBounce:VC,easeInOutBounce:e=>e<.5?(1-HC(1-2*e))/2:(1+HC(2*e-1))/2},WC=Object.keys(UC);function GC(e){if(typeof e==`function`)return e;let t=UC[e];if(!t)throw Error(`[s3m] 未知的缓动曲线: ${String(e)}`);return t}var KC=8,qC=.001,JC=1e-7,YC=12,XC=(e,t)=>1-3*t+3*e,ZC=(e,t)=>3*t-6*e,QC=e=>3*e;function $C(e,t,n){return((XC(t,n)*e+ZC(t,n))*e+QC(t))*e}function ew(e,t,n){return 3*XC(t,n)*e*e+2*ZC(t,n)*e+QC(t)}function tw(e,t,n,r){if(e===t&&n===r)return e=>e;let i=t=>{let r=t;for(let i=0;i<KC;i++){let i=ew(r,e,n);if(Math.abs(i)<qC)break;let a=$C(r,e,n)-t;if(Math.abs(a)<JC)return r;r-=a/i}let i=0,a=1;r=t;for(let o=0;o<YC;o++){let o=$C(r,e,n);if(Math.abs(o-t)<JC)return r;o<t?i=r:a=r,r=(i+a)/2}return r};return e=>e<=0?0:e>=1?1:$C(i(e),t,r)}function nw(e,t=`end`){let n=Math.max(1,Math.floor(e));return e=>{let r=Math.min(1,Math.max(0,e));return t===`start`?Math.min(1,(Math.floor(r*n)+1)/n):Math.min(1,Math.floor(r*n)/n)}}mh();var rw=1e-4,iw=.15;function aw(e){return e<0?0:e>1?1:e}function ow(e,t,n){let r=0;for(let i=0;i<n;i++){let n=Math.abs(e[i]-t[i]);n>r&&(r=n)}return r}var sw=class{constructor(e,t){X(this,`key`,void 0),X(this,`channel`,void 0),X(this,`dim`,void 0),X(this,`to`,new Float32Array(3)),X(this,`_cur`,new Float32Array(3)),X(this,`done`,!1),X(this,`onComplete`,void 0),this.key=e,this.channel=t,this.dim=t.dim}},cw=class extends sw{constructor(...e){super(...e),X(this,`_from`,new Float32Array(3)),X(this,`_start`,0),X(this,`_duration`,0),X(this,`_delay`,0),X(this,`_ease`,GC(`linear`)),X(this,`_retarget`,`proportional`),X(this,`_span`,0),X(this,`_progress`,0)}get progress(){return this._progress}start(e,t,n){n?this._from.set(n.subarray(0,this.dim)):this.channel.read(this._from),this._start=e,this._delay=Math.max(0,t.delay??0),this._duration=Math.max(0,t.duration??0),this._ease=t.easing?GC(t.easing):GC(`linear`),this._retarget=t.retarget??`proportional`,this._span=ow(this._from,this.to,this.dim),this._progress=0,this.done=!1}advance(e){let t=e-this._start-this._delay,n=this._duration<=0?1:aw(t/this._duration);this._progress=n;let r=this._ease(n);for(let e=0;e<this.dim;e++)this._cur[e]=this._from[e]+(this.to[e]-this._from[e])*r;this.channel.write(this._cur),n>=1&&(this.done=!0)}retarget(e,t,n){this.channel.read(this._from),this.to.set(e.subarray(0,this.dim));let r=Math.max(0,n.duration??this._duration),i=r;if((n.retarget??this._retarget)!==`fixed`&&this._span>rw){let e=ow(this._from,this.to,this.dim)/this._span;i=Math.min(r,Math.max(r*iw,r*e))}this._start=t,this._delay=Math.max(0,n.delay??0),this._duration=i,this._ease=n.easing?GC(n.easing):this._ease,this._span=ow(this._from,this.to,this.dim),this._progress=0,this.done=!1}},lw=class extends sw{constructor(...e){super(...e),X(this,`_x0`,new Float32Array(3)),X(this,`_v0`,new Float32Array(3)),X(this,`_vel`,new Float32Array(3)),X(this,`_start`,0),X(this,`_k`,120),X(this,`_c`,14),X(this,`_eps`,.001),X(this,`_progress`,0)}get progress(){return this._progress}start(e,t,n){let r=t.spring??{stiffness:120,damping:14};this._k=Math.max(.001,r.stiffness),this._c=Math.max(0,r.damping),this._eps=r.epsilon??.001,n?this._x0.set(n.subarray(0,this.dim)):this.channel.read(this._x0),this._v0.fill(0),this._vel.fill(0),this._start=e,this.done=!1,this._progress=0}advance(e){let t=Math.max(0,(e-this._start)/1e3),n=!0;for(let e=0;e<this.dim;e++){let{x:r,v:i}=uw(this._x0[e]-this.to[e],this._v0[e],this._k,this._c,t);this._cur[e]=this.to[e]+r,this._vel[e]=i,(Math.abs(r)>this._eps||Math.abs(i)>this._eps)&&(n=!1)}if(this.channel.write(this._cur),n){for(let e=0;e<this.dim;e++)this._cur[e]=this.to[e];this.channel.write(this._cur),this.done=!0,this._progress=1}}retarget(e,t,n){this.channel.read(this._cur);let r=n.spring;r&&(this._k=Math.max(.001,r.stiffness),this._c=Math.max(0,r.damping),this._eps=r.epsilon??this._eps);let i=Math.max(0,(t-this._start)/1e3);for(let t=0;t<this.dim;t++){let n=uw(this._x0[t]-this.to[t],this._v0[t],this._k,this._c,i);this._x0[t]=this._cur[t]-e[t],this._v0[t]=n.v}this.to.set(e.subarray(0,this.dim)),this._start=t,this.done=!1}};function uw(e,t,n,r,i){let a=Math.sqrt(n),o=r/(2*a);if(o<1){let n=a*Math.sqrt(1-o*o),r=Math.exp(-o*a*i),s=Math.cos(n*i),c=Math.sin(n*i),l=e,u=(t+o*a*e)/n;return{x:r*(l*s+u*c),v:r*((u*n-o*a*l)*s+(-l*n-o*a*u)*c)}}let s=Math.exp(-a*i),c=t+a*e;return{x:(e+c*i)*s,v:(t-a*c*i)*s}}var dw=class{constructor(e=()=>performance.now()){X(this,`_channels`,new Map),X(this,`_tracks`,new Map),X(this,`_buf`,new Float32Array(3)),X(this,`_finished`,[]),X(this,`_now`,void 0),X(this,`_budgetMs`,2.5),X(this,`_lastTick`,-1/0),X(this,`_skipped`,0),X(this,`onActive`,void 0),this._now=e}set budgetMs(e){this._budgetMs=Math.max(0,e)}get budgetMs(){return this._budgetMs}get skippedLastTick(){return this._skipped}get activeCount(){return this._tracks.size}get active(){return this._tracks.size>0}register(e,t){this._channels.set(e,t)}unregister(e){this._channels.delete(e),this._tracks.delete(e)}unregisterPrefix(e){for(let t of[...this._channels.keys()])t.startsWith(e)&&(this._channels.delete(t),this._tracks.delete(t))}has(e){return this._channels.has(e)}isActive(e){return this._tracks.has(e)}to(e,t,n={}){let r=this._channels.get(e);if(!r)throw Error(`[s3m] 未注册的动画通道: ${e}`);let i=this._buf;if(r.dim===1)i[0]=typeof t==`number`?t:Number(t[0]),i[1]=0,i[2]=0;else{if(typeof t==`number`)throw Error(`[s3m] 通道 ${e} 需要三元数组目标值`);for(let e=0;e<3;e++)i[e]=Number(t[e]??0)}let a=!!n.spring,o=Math.max(0,n.duration??0);if(!a&&o<=0&&!n.delay){this._tracks.delete(e),r.write(i),this.onActive?.(),n.onComplete?.();return}let s=Math.max(this._now(),this._lastTick),c=this._tracks.get(e),l=a,u=c instanceof lw;if(c&&c!=null&&u!==l&&(this._tracks.delete(e),c=void 0),c||this.onActive?.(),!c){let t=l?new lw(e,r):new cw(e,r);t.to.set(i.subarray(0,r.dim)),t.onComplete=n.onComplete,t.start(s,n),this._tracks.set(e,t)}else c.to.set(i.subarray(0,r.dim)),c.onComplete=n.onComplete,c.retarget(i,s,n)}cancel(e){this._tracks.delete(e)}finish(e){let t=this._tracks.get(e);t&&(this._tracks.delete(e),t.channel.write(t.to),this.onActive?.(),t.onComplete?.())}clear(){this._tracks.clear()}tick(e=this._now()){if(this._tracks.size===0)return this._lastTick=Math.max(this._lastTick,e),!1;this._lastTick=Math.max(this._lastTick,e);let t=performance.now(),n=0;for(let r of this._tracks.values())if(r.advance(e),n++,r.done&&this._finished.push(r),performance.now()-t>=this._budgetMs)break;if(this._finished.length>0){for(let e of this._finished)this._tracks.get(e.key)===e&&this._tracks.delete(e.key);let e=this._finished.splice(0,this._finished.length);for(let t of e)t.onComplete?.()}return this._skipped=Math.max(0,this._tracks.size-n),this._tracks.size>0}};sh(),mh();var fw=class{constructor(){X(this,`datasets`,new Map),X(this,`sceneAnchor`,null),X(this,`totalMaxTiles`,0)}get(e){return this.datasets.get(e)}values(){return this.datasets.values()}registerDataset(e){let t=this.datasets.get(e.id);if(t)return t;let n=new Il;n.name=`s3m-dataset:${e.id}`,n.visible=e.visible!==!1;let r={id:e.id,name:e.name??e.id,options:e,root:n,tileset:null,anchor:null,baseAlignOffset:0,userOffset:e.heightOffset??0,heightOffset:e.heightOffset??0,offset:[0,0,0],visible:e.visible!==!1,error:null};return this.datasets.set(e.id,r),this.rebalanceBudgets(),r}rebalanceBudgets(e){let t=e??this.totalMaxTiles;if(!t||t<=0)return;this.totalMaxTiles=t;let n=Array.from(this.datasets.values()).filter(e=>e.visible&&e.tileset),r=Math.max(1,n.length),i=Math.max(8,Math.floor(t/r));for(let e of this.datasets.values())e.tileset&&(e.visible?(e.tileset.maxTiles=i,e.tileset.hardCap=i+Math.max(4,Math.ceil(i*.5))):(e.tileset.maxTiles=Math.min(4,e.tileset.maxTiles),e.tileset.hardCap=Math.min(6,e.tileset.hardCap)))}computeAlignOffset(e,t){if(!t||t===`origin`||!e)return 0;let n=e.heightRange;if(!n)return 0;switch(t){case`top`:return-n.max;case`bottom`:return-n.min;case`center`:return-(n.min+n.max)/2;default:return 0}}async addDataset(e,t,n,r,i,a,o,s,c,l=1/0,u=128,d){let f=this.datasets.get(e.id);if(f)return f;let p=new Il;p.name=`s3m-dataset:${e.id}`,p.visible=e.visible!==!1,t.add(p);let m={id:e.id,name:e.name??e.id,options:e,root:p,tileset:null,anchor:null,baseAlignOffset:0,userOffset:e.heightOffset??0,heightOffset:e.heightOffset??0,offset:[0,0,0],visible:e.visible!==!1,error:null};this.datasets.set(e.id,m);let h=new vS({configUrl:e.configUrl,maxTiles:e.maxTiles??o,maxConcurrent:s,maxTriangles:e.maxTriangles??l,maxImageCache:e.maxImageCache??u,lodRangeScale:e.lodRangeScale??i,buildTile:a??null,polygonOffset:e.polygonOffset,useWorker:e.useWorker,authenticate:e.authenticate??d,unsupported:e.unsupported,uniforms:r,onTile:e=>{c.onTile(e,m)},onTileRemoved:e=>{c.onTileRemoved(e,m)},onProgress:()=>{c.onStats(),c.triggerRepaint()},onError:e=>{m.error=e,c.onError(e),c.onStats()}});m.tileset=h,this.rebalanceBudgets();try{await h.init()}catch(e){return m.error=e,c.onError(e),m}return m.anchor=h.anchor,m.baseAlignOffset=this.computeAlignOffset(h,e.align),m.userOffset=e.heightOffset??0,m.heightOffset=m.baseAlignOffset+m.userOffset,this.layoutDataset(m,n),c.onReady(m),c.triggerRepaint(),m}removeDataset(e,t,n,r){let i=this.datasets.get(e);return i?(r(i),i.tileset?.dispose(),t.remove(i.root),this.datasets.delete(e),this.rebalanceBudgets(),this.datasets.size>0?this.recomputeAnchors(n):this.sceneAnchor=null,!0):!1}clearDatasets(e,t){for(let n of this.datasets.values())t(n),n.tileset?.dispose(),e.remove(n.root);this.datasets.clear(),this.sceneAnchor=null}layoutDataset(e,t){if(!e.anchor)return;this.sceneAnchor||(this.sceneAnchor=F_(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0));let n=this.sceneAnchor.meterInMercator,r=F_(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0);e.offset=[(r.x-this.sceneAnchor.x)/n,-(r.y-this.sceneAnchor.y)/n,(r.z-this.sceneAnchor.z)/n+(e.heightOffset??0)],e.root.position.set(e.offset[0],e.offset[1],e.offset[2]),e.root.updateMatrixWorld(!0)}recomputeAnchors(e){if(this.datasets.size!==0){this.sceneAnchor=null;for(let t of this.datasets.values())this.layoutDataset(t,e)}}getDatasetHeight(e){let t=e??this.datasets.keys().next().value;return t?this.datasets.get(t)?.userOffset??0:0}setDatasetHeight(e,t,n){let r=this.datasets.get(e);r&&(r.userOffset=t,r.heightOffset=r.baseAlignOffset+t,this.layoutDataset(r,n))}setDatasetAlign(e,t,n){let r=this.datasets.get(e);if(!r)return;let i=r.heightOffset-r.baseAlignOffset;r.baseAlignOffset=this.computeAlignOffset(r.tileset,t),r.userOffset=i,r.heightOffset=r.baseAlignOffset+i,r.options.align=t,this.layoutDataset(r,n)}setDatasetVisible(e,t){let n=this.datasets.get(e);n&&(n.visible=t,n.root.visible=t,this.rebalanceBudgets())}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0,i=!1;for(let a of this.datasets.values()){if(!a.visible||!a.tileset?.config)continue;let o=hS(a.tileset.config.geoBounds);o&&(e=Math.min(e,o.left),t=Math.min(t,o.bottom),n=Math.max(n,o.right),r=Math.max(r,o.top),i=!0)}return i?[[e,t],[n,r]]:null}};sh(),mh();var pw=class{constructor(e={}){X(this,`mode`,void 0),X(this,`opacity`,void 0),X(this,`color`,void 0),X(this,`gridColor`,void 0),X(this,`gridSize`,void 0),X(this,`excavationBounds`,null),X(this,`size`,void 0),X(this,`groundHeight`,0),X(this,`occlude`,void 0),X(this,`trackHeight`,void 0),X(this,`group`,void 0),X(this,`_mesh`,null),X(this,`_material`,null),X(this,`_depthMesh`,null),X(this,`_depthMaterial`,null),X(this,`_geom`,null),X(this,`_occludeExplicit`,void 0),this.mode=e.mode??`none`,this.opacity=e.opacity??.62,this.color=new W(e.color??`#0f172a`),this.gridColor=new W(e.gridColor??`#38bdf8`),this.gridSize=e.gridSize??10,this.excavationBounds=e.excavationBounds??null,this.size=e.size??6e3,this._occludeExplicit=e.occlude!==void 0,this.occlude=e.occlude??this.mode===`excavate`,this.trackHeight=e.trackHeight??!0,this.group=new Il,this.group.name=`s3m-ground-surface`,this._initMesh(),this._applyMode()}_initMesh(){let e=new Rc(this.size,this.size,1,1);this._geom=e;let t=new bc({transparent:!0,depthTest:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:this.color},uGridColor:{value:this.gridColor},uOpacity:{value:this.opacity},uGridSize:{value:this.gridSize},uMode:{value:this.mode===`excavate`?2:+(this.mode===`translucent`)},uHasExcavation:{value:0},uExcavationMin:{value:new B(-9999,-9999)},uExcavationMax:{value:new B(9999,9999)}},vertexShader:`
5151
+ `,jC=(()=>{let e=new Du(new Float32Array([-1,-1,-1,0,0,0,0,0]),1,2,fi,ii);return e.minFilter=Hr,e.magFilter=Hr,e.needsUpdate=!0,e})(),MC=(()=>{let e=new Du(new Float32Array([0,0,0,0]),1,1,fi,ii);return e.minFilter=Hr,e.magFilter=Hr,e.needsUpdate=!0,e})();function NC(e){return new bc({uniforms:{uObjectId:{value:e},uBatchTex:{value:jC},uBatchTex2:{value:jC},uBatchMix:{value:0},uBatchTexWidth:{value:1},uBatchTexActive:{value:0},uPathTex:{value:MC},uPathCount:{value:1},uPathTime:{value:0},uPathTexActive:{value:0},uSelBatch:{value:-1},uSelWhole:{value:0},uSelElevation:{value:0}},vertexShader:kC,fragmentShader:AC,side:2,depthTest:!0,depthWrite:!0,toneMapped:!1})}function PC(e){return e.isPoints===!0}var FC=class{constructor(e,t={}){X(this,`renderer`,void 0),X(this,`size`,void 0),X(this,`target`,null),X(this,`buf`,new Uint8Array(4)),this.renderer=e,this.size=Math.max(1,Math.floor(t.size??1))}_ensureTarget(e){return this.target&&this.target.width===e&&this.target.height===e||(this.target?.dispose(),this.target=new uo(e,e,{minFilter:Hr,magFilter:Hr,format:fi,type:Qr,depthBuffer:!0,stencilBuffer:!1}),this.target.texture.colorSpace=_a),this.target}pick(e,t,n,r){let i=this.renderer,a=i.domElement,o=a.width,s=a.height;if(!o||!s)return null;let c=Math.floor(n/a.clientWidth*o),l=Math.floor(r/a.clientHeight*s);if(c<0||l<0||c>=o||l>=s)return null;let u=this._ensureTarget(this.size),d=s-1-l,f=Math.floor(this.size/2),p=Math.floor(this.size/2);u.viewport.set(f-c,p-d,o,s);let m=i.getRenderTarget(),h=i.getViewport(new co),g=i.toneMapping,_=i.outputColorSpace,v=i.autoClear,y=i.getClearColor(new W),b=i.getClearAlpha(),x=[],S=new Set;e.traverseVisible(e=>{let t=e;if(!t.isMesh&&!PC(t))return;let n=t.userData;if(n.pickId===void 0)return;let r=n.isGaussianSplat===!0;n.pickMaterial||(n.pickMaterial=r?Px(n.pickId):NC(n.pickId)),!r&&t.isInstancedMesh&&S.add(n.pickId);let i=t.material,a=n.pickMaterial;if(r){x.push([t,i]),t.material=a;return}let o=Array.isArray(i)?i[0]:i,s=o?.userData?.uBatchTex;s?(a.uniforms.uBatchTex.value=s.value,a.uniforms.uBatchTex2.value=o?.userData?.uBatchTex2?.value??s.value,a.uniforms.uBatchTexWidth.value=o?.userData?.uBatchTexWidth?.value??1,a.uniforms.uBatchTexActive.value=o?.userData?.uBatchTexActive?.value??0):(a.uniforms.uBatchTex.value=jC,a.uniforms.uBatchTex2.value=jC,a.uniforms.uBatchTexWidth.value=1,a.uniforms.uBatchTexActive.value=0),a.uniforms.uBatchMix.value=o?.userData?.uBatchMix?.value??0,a.uniforms.uPathTex.value=o?.userData?.uPathTex?.value??MC,a.uniforms.uPathCount.value=o?.userData?.uPathCount?.value??1,a.uniforms.uPathTime.value=o?.userData?.uPathTime?.value??0,a.uniforms.uPathTexActive.value=o?.userData?.uPathTexActive?.value??0,a.uniforms.uSelBatch.value=o?.userData?.uSelBatch?.value??-1,a.uniforms.uSelWhole.value=o?.userData?.uSelWhole?.value??0,a.uniforms.uSelElevation.value=o?.userData?.uSelElevation?.value??o?.uniforms?.uSelElevation?.value??0,x.push([t,i]),t.material=a});let C=[];e.traverseVisible(e=>{let t=e;(t.isMesh||PC(t))&&t.userData.pickId===void 0&&(C.push(t),t.visible=!1)});let w=null;try{i.resetState(),i.setRenderTarget(u),i.toneMapping=0,i.outputColorSpace=_a,i.autoClear=!0,i.setClearColor(0,0),i.clear(),i.render(e,t),i.readRenderTargetPixels(u,f,p,1,1,this.buf);let n=this.buf[0],r=this.buf[1],a=this.buf[2],o=this.buf[3],s=n+r*256-1,c=a+o*256-1;s>=0&&(w=S.has(s)?{objectId:s,batchId:-1,instanceIndex:Math.max(0,c)}:{objectId:s,batchId:c})}finally{for(let[e,t]of x)e.material=t;for(let e of C)e.visible=!0;i.setRenderTarget(m),i.setViewport(h),i.toneMapping=g,i.outputColorSpace=_,i.autoClear=v,i.setClearColor(y,b),i.resetState()}return w}dispose(){this.target?.dispose(),this.target=null}},IC=1.70158,LC=IC*1.525,RC=2.70158,zC=2*Math.PI/3,BC=2*Math.PI/4.5,VC=7.5625,HC=2.75;function UC(e){if(e<1/HC)return VC*e*e;if(e<2/HC){let t=e-1.5/HC;return VC*t*t+.75}if(e<2.5/HC){let t=e-2.25/HC;return VC*t*t+.9375}let t=e-2.625/HC;return VC*t*t+.984375}function WC(e){return 1-UC(1-e)}var GC={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>1-(1-e)*(1-e),easeInOutQuad:e=>e<.5?2*e*e:1-(-2*e+2)**2/2,easeInCubic:e=>e*e*e,easeOutCubic:e=>1-(1-e)**3,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1-(1-e)**4,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-(-2*e+2)**4/2,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1-(1-e)**5,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1-(-2*e+2)**5/2,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e===0?0:2**(10*e-10),easeOutExpo:e=>e===1?1:1-2**(-10*e),easeInOutExpo:e=>e===0?0:e===1?1:e<.5?2**(20*e-10)/2:(2-2**(-20*e+10))/2,easeInCirc:e=>1-Math.sqrt(1-e*e),easeOutCirc:e=>Math.sqrt(1-(e-1)**2),easeInOutCirc:e=>e<.5?(1-Math.sqrt(1-(2*e)**2))/2:(Math.sqrt(1-(-2*e+2)**2)+1)/2,easeInBack:e=>RC*e*e*e-IC*e*e,easeOutBack:e=>1+RC*(e-1)**3+IC*(e-1)**2,easeInOutBack:e=>e<.5?(2*e)**2*(7.189819*e-LC)/2:((2*e-2)**2*(3.5949095*(e*2-2)+LC)+2)/2,easeInElastic:e=>e===0?0:e===1?1:-(2**(10*e-10))*Math.sin((e*10-10.75)*zC),easeOutElastic:e=>e===0?0:e===1?1:2**(-10*e)*Math.sin((e*10-.75)*zC)+1,easeInOutElastic:e=>e===0?0:e===1?1:e<.5?-(2**(20*e-10)*Math.sin((20*e-11.125)*BC))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*BC)/2+1,easeInBounce:WC,easeOutBounce:UC,easeInOutBounce:e=>e<.5?(1-WC(1-2*e))/2:(1+WC(2*e-1))/2},KC=Object.keys(GC);function qC(e){if(typeof e==`function`)return e;let t=GC[e];if(!t)throw Error(`[s3m] 未知的缓动曲线: ${String(e)}`);return t}var JC=8,YC=.001,XC=1e-7,ZC=12,QC=(e,t)=>1-3*t+3*e,$C=(e,t)=>3*t-6*e,ew=e=>3*e;function tw(e,t,n){return((QC(t,n)*e+$C(t,n))*e+ew(t))*e}function nw(e,t,n){return 3*QC(t,n)*e*e+2*$C(t,n)*e+ew(t)}function rw(e,t,n,r){if(e===t&&n===r)return e=>e;let i=t=>{let r=t;for(let i=0;i<JC;i++){let i=nw(r,e,n);if(Math.abs(i)<YC)break;let a=tw(r,e,n)-t;if(Math.abs(a)<XC)return r;r-=a/i}let i=0,a=1;r=t;for(let o=0;o<ZC;o++){let o=tw(r,e,n);if(Math.abs(o-t)<XC)return r;o<t?i=r:a=r,r=(i+a)/2}return r};return e=>e<=0?0:e>=1?1:tw(i(e),t,r)}function iw(e,t=`end`){let n=Math.max(1,Math.floor(e));return e=>{let r=Math.min(1,Math.max(0,e));return t===`start`?Math.min(1,(Math.floor(r*n)+1)/n):Math.min(1,Math.floor(r*n)/n)}}mh();var aw=1e-4,ow=.15;function sw(e){return e<0?0:e>1?1:e}function cw(e,t,n){let r=0;for(let i=0;i<n;i++){let n=Math.abs(e[i]-t[i]);n>r&&(r=n)}return r}var lw=class{constructor(e,t){X(this,`key`,void 0),X(this,`channel`,void 0),X(this,`dim`,void 0),X(this,`to`,new Float32Array(3)),X(this,`_cur`,new Float32Array(3)),X(this,`done`,!1),X(this,`onComplete`,void 0),this.key=e,this.channel=t,this.dim=t.dim}},uw=class extends lw{constructor(...e){super(...e),X(this,`_from`,new Float32Array(3)),X(this,`_start`,0),X(this,`_duration`,0),X(this,`_delay`,0),X(this,`_ease`,qC(`linear`)),X(this,`_retarget`,`proportional`),X(this,`_span`,0),X(this,`_progress`,0)}get progress(){return this._progress}start(e,t,n){n?this._from.set(n.subarray(0,this.dim)):this.channel.read(this._from),this._start=e,this._delay=Math.max(0,t.delay??0),this._duration=Math.max(0,t.duration??0),this._ease=t.easing?qC(t.easing):qC(`linear`),this._retarget=t.retarget??`proportional`,this._span=cw(this._from,this.to,this.dim),this._progress=0,this.done=!1}advance(e){let t=e-this._start-this._delay,n=this._duration<=0?1:sw(t/this._duration);this._progress=n;let r=this._ease(n);for(let e=0;e<this.dim;e++)this._cur[e]=this._from[e]+(this.to[e]-this._from[e])*r;this.channel.write(this._cur),n>=1&&(this.done=!0)}retarget(e,t,n){this.channel.read(this._from),this.to.set(e.subarray(0,this.dim));let r=Math.max(0,n.duration??this._duration),i=r;if((n.retarget??this._retarget)!==`fixed`&&this._span>aw){let e=cw(this._from,this.to,this.dim)/this._span;i=Math.min(r,Math.max(r*ow,r*e))}this._start=t,this._delay=Math.max(0,n.delay??0),this._duration=i,this._ease=n.easing?qC(n.easing):this._ease,this._span=cw(this._from,this.to,this.dim),this._progress=0,this.done=!1}},dw=class extends lw{constructor(...e){super(...e),X(this,`_x0`,new Float32Array(3)),X(this,`_v0`,new Float32Array(3)),X(this,`_vel`,new Float32Array(3)),X(this,`_start`,0),X(this,`_k`,120),X(this,`_c`,14),X(this,`_eps`,.001),X(this,`_progress`,0)}get progress(){return this._progress}start(e,t,n){let r=t.spring??{stiffness:120,damping:14};this._k=Math.max(.001,r.stiffness),this._c=Math.max(0,r.damping),this._eps=r.epsilon??.001,n?this._x0.set(n.subarray(0,this.dim)):this.channel.read(this._x0),this._v0.fill(0),this._vel.fill(0),this._start=e,this.done=!1,this._progress=0}advance(e){let t=Math.max(0,(e-this._start)/1e3),n=!0;for(let e=0;e<this.dim;e++){let{x:r,v:i}=fw(this._x0[e]-this.to[e],this._v0[e],this._k,this._c,t);this._cur[e]=this.to[e]+r,this._vel[e]=i,(Math.abs(r)>this._eps||Math.abs(i)>this._eps)&&(n=!1)}if(this.channel.write(this._cur),n){for(let e=0;e<this.dim;e++)this._cur[e]=this.to[e];this.channel.write(this._cur),this.done=!0,this._progress=1}}retarget(e,t,n){this.channel.read(this._cur);let r=n.spring;r&&(this._k=Math.max(.001,r.stiffness),this._c=Math.max(0,r.damping),this._eps=r.epsilon??this._eps);let i=Math.max(0,(t-this._start)/1e3);for(let t=0;t<this.dim;t++){let n=fw(this._x0[t]-this.to[t],this._v0[t],this._k,this._c,i);this._x0[t]=this._cur[t]-e[t],this._v0[t]=n.v}this.to.set(e.subarray(0,this.dim)),this._start=t,this.done=!1}};function fw(e,t,n,r,i){let a=Math.sqrt(n),o=r/(2*a);if(o<1){let n=a*Math.sqrt(1-o*o),r=Math.exp(-o*a*i),s=Math.cos(n*i),c=Math.sin(n*i),l=e,u=(t+o*a*e)/n;return{x:r*(l*s+u*c),v:r*((u*n-o*a*l)*s+(-l*n-o*a*u)*c)}}let s=Math.exp(-a*i),c=t+a*e;return{x:(e+c*i)*s,v:(t-a*c*i)*s}}var pw=class{constructor(e=()=>performance.now()){X(this,`_channels`,new Map),X(this,`_tracks`,new Map),X(this,`_buf`,new Float32Array(3)),X(this,`_finished`,[]),X(this,`_now`,void 0),X(this,`_budgetMs`,2.5),X(this,`_lastTick`,-1/0),X(this,`_skipped`,0),X(this,`onActive`,void 0),this._now=e}set budgetMs(e){this._budgetMs=Math.max(0,e)}get budgetMs(){return this._budgetMs}get skippedLastTick(){return this._skipped}get activeCount(){return this._tracks.size}get active(){return this._tracks.size>0}register(e,t){this._channels.set(e,t)}unregister(e){this._channels.delete(e),this._tracks.delete(e)}unregisterPrefix(e){for(let t of[...this._channels.keys()])t.startsWith(e)&&(this._channels.delete(t),this._tracks.delete(t))}has(e){return this._channels.has(e)}isActive(e){return this._tracks.has(e)}to(e,t,n={}){let r=this._channels.get(e);if(!r)throw Error(`[s3m] 未注册的动画通道: ${e}`);let i=this._buf;if(r.dim===1)i[0]=typeof t==`number`?t:Number(t[0]),i[1]=0,i[2]=0;else{if(typeof t==`number`)throw Error(`[s3m] 通道 ${e} 需要三元数组目标值`);for(let e=0;e<3;e++)i[e]=Number(t[e]??0)}let a=!!n.spring,o=Math.max(0,n.duration??0);if(!a&&o<=0&&!n.delay){this._tracks.delete(e),r.write(i),this.onActive?.(),n.onComplete?.();return}let s=Math.max(this._now(),this._lastTick),c=this._tracks.get(e),l=a,u=c instanceof dw;if(c&&c!=null&&u!==l&&(this._tracks.delete(e),c=void 0),c||this.onActive?.(),!c){let t=l?new dw(e,r):new uw(e,r);t.to.set(i.subarray(0,r.dim)),t.onComplete=n.onComplete,t.start(s,n),this._tracks.set(e,t)}else c.to.set(i.subarray(0,r.dim)),c.onComplete=n.onComplete,c.retarget(i,s,n)}cancel(e){this._tracks.delete(e)}finish(e){let t=this._tracks.get(e);t&&(this._tracks.delete(e),t.channel.write(t.to),this.onActive?.(),t.onComplete?.())}clear(){this._tracks.clear()}tick(e=this._now()){if(this._tracks.size===0)return this._lastTick=Math.max(this._lastTick,e),!1;this._lastTick=Math.max(this._lastTick,e);let t=performance.now(),n=0;for(let r of this._tracks.values())if(r.advance(e),n++,r.done&&this._finished.push(r),performance.now()-t>=this._budgetMs)break;if(this._finished.length>0){for(let e of this._finished)this._tracks.get(e.key)===e&&this._tracks.delete(e.key);let e=this._finished.splice(0,this._finished.length);for(let t of e)t.onComplete?.()}return this._skipped=Math.max(0,this._tracks.size-n),this._tracks.size>0}};sh(),mh();var mw=class{constructor(){X(this,`datasets`,new Map),X(this,`sceneAnchor`,null),X(this,`totalMaxTiles`,0)}get(e){return this.datasets.get(e)}values(){return this.datasets.values()}registerDataset(e){let t=this.datasets.get(e.id);if(t)return t;let n=new Il;n.name=`s3m-dataset:${e.id}`,n.visible=e.visible!==!1;let r={id:e.id,name:e.name??e.id,options:e,root:n,tileset:null,anchor:null,baseAlignOffset:0,userOffset:e.heightOffset??0,heightOffset:e.heightOffset??0,offset:[0,0,0],visible:e.visible!==!1,error:null};return this.datasets.set(e.id,r),this.rebalanceBudgets(),r}rebalanceBudgets(e){let t=e??this.totalMaxTiles;if(!t||t<=0)return;this.totalMaxTiles=t;let n=Array.from(this.datasets.values()).filter(e=>e.visible&&e.tileset),r=Math.max(1,n.length),i=Math.max(8,Math.floor(t/r));for(let e of this.datasets.values())e.tileset&&(e.visible?(e.tileset.maxTiles=i,e.tileset.hardCap=i+Math.max(4,Math.ceil(i*.5))):(e.tileset.maxTiles=Math.min(4,e.tileset.maxTiles),e.tileset.hardCap=Math.min(6,e.tileset.hardCap)))}computeAlignOffset(e,t){if(!t||t===`origin`||!e)return 0;let n=e.heightRange;if(!n)return 0;switch(t){case`top`:return-n.max;case`bottom`:return-n.min;case`center`:return-(n.min+n.max)/2;default:return 0}}async addDataset(e,t,n,r,i,a,o,s,c,l=1/0,u=128,d,f=1/0){let p=this.datasets.get(e.id);if(p)return p;let m=new Il;m.name=`s3m-dataset:${e.id}`,m.visible=e.visible!==!1,t.add(m);let h={id:e.id,name:e.name??e.id,options:e,root:m,tileset:null,anchor:null,baseAlignOffset:0,userOffset:e.heightOffset??0,heightOffset:e.heightOffset??0,offset:[0,0,0],visible:e.visible!==!1,error:null};this.datasets.set(e.id,h);let g=new bS({configUrl:e.configUrl,maxTiles:e.maxTiles??o,maxConcurrent:s,maxTriangles:e.maxTriangles??l,maxMemory:e.maxMemory??f,maxImageCache:e.maxImageCache??u,lodRangeScale:e.lodRangeScale??i,buildTile:a??null,polygonOffset:e.polygonOffset,useWorker:e.useWorker,authenticate:e.authenticate??d,unsupported:e.unsupported,uniforms:r,onTile:e=>{c.onTile(e,h)},onTileRemoved:e=>{c.onTileRemoved(e,h)},onProgress:()=>{c.onStats(),c.triggerRepaint()},onError:e=>{h.error=e,c.onError(e),c.onStats()}});h.tileset=g,this.rebalanceBudgets();try{await g.init()}catch(e){return h.error=e,c.onError(e),h}return h.anchor=g.anchor,h.baseAlignOffset=this.computeAlignOffset(g,e.align),h.userOffset=e.heightOffset??0,h.heightOffset=h.baseAlignOffset+h.userOffset,this.layoutDataset(h,n),c.onReady(h),c.triggerRepaint(),h}removeDataset(e,t,n,r){let i=this.datasets.get(e);return i?(r(i),i.tileset?.dispose(),t.remove(i.root),this.datasets.delete(e),this.rebalanceBudgets(),this.datasets.size>0?this.recomputeAnchors(n):this.sceneAnchor=null,!0):!1}clearDatasets(e,t){for(let n of this.datasets.values())t(n),n.tileset?.dispose(),e.remove(n.root);this.datasets.clear(),this.sceneAnchor=null}layoutDataset(e,t){if(!e.anchor)return;this.sceneAnchor||(this.sceneAnchor=F_(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0));let n=this.sceneAnchor.meterInMercator,r=F_(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0);e.offset=[(r.x-this.sceneAnchor.x)/n,-(r.y-this.sceneAnchor.y)/n,(r.z-this.sceneAnchor.z)/n+(e.heightOffset??0)],e.root.position.set(e.offset[0],e.offset[1],e.offset[2]),e.root.updateMatrixWorld(!0)}recomputeAnchors(e){if(this.datasets.size!==0){this.sceneAnchor=null;for(let t of this.datasets.values())this.layoutDataset(t,e)}}getDatasetHeight(e){let t=e??this.datasets.keys().next().value;return t?this.datasets.get(t)?.userOffset??0:0}setDatasetHeight(e,t,n){let r=this.datasets.get(e);r&&(r.userOffset=t,r.heightOffset=r.baseAlignOffset+t,this.layoutDataset(r,n))}setDatasetAlign(e,t,n){let r=this.datasets.get(e);if(!r)return;let i=r.heightOffset-r.baseAlignOffset;r.baseAlignOffset=this.computeAlignOffset(r.tileset,t),r.userOffset=i,r.heightOffset=r.baseAlignOffset+i,r.options.align=t,this.layoutDataset(r,n)}setDatasetVisible(e,t){let n=this.datasets.get(e);n&&(n.visible=t,n.root.visible=t,this.rebalanceBudgets())}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0,i=!1;for(let a of this.datasets.values()){if(!a.visible||!a.tileset?.config)continue;let o=hS(a.tileset.config.geoBounds);o&&(e=Math.min(e,o.left),t=Math.min(t,o.bottom),n=Math.max(n,o.right),r=Math.max(r,o.top),i=!0)}return i?[[e,t],[n,r]]:null}};sh(),mh();var hw=class{constructor(e={}){X(this,`mode`,void 0),X(this,`opacity`,void 0),X(this,`color`,void 0),X(this,`gridColor`,void 0),X(this,`gridSize`,void 0),X(this,`excavationBounds`,null),X(this,`size`,void 0),X(this,`groundHeight`,0),X(this,`occlude`,void 0),X(this,`trackHeight`,void 0),X(this,`group`,void 0),X(this,`_mesh`,null),X(this,`_material`,null),X(this,`_depthMesh`,null),X(this,`_depthMaterial`,null),X(this,`_geom`,null),X(this,`_occludeExplicit`,void 0),this.mode=e.mode??`none`,this.opacity=e.opacity??.62,this.color=new W(e.color??`#0f172a`),this.gridColor=new W(e.gridColor??`#38bdf8`),this.gridSize=e.gridSize??10,this.excavationBounds=e.excavationBounds??null,this.size=e.size??6e3,this._occludeExplicit=e.occlude!==void 0,this.occlude=e.occlude??this.mode===`excavate`,this.trackHeight=e.trackHeight??!0,this.group=new Il,this.group.name=`s3m-ground-surface`,this._initMesh(),this._applyMode()}_initMesh(){let e=new Rc(this.size,this.size,1,1);this._geom=e;let t=new bc({transparent:!0,depthTest:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:this.color},uGridColor:{value:this.gridColor},uOpacity:{value:this.opacity},uGridSize:{value:this.gridSize},uMode:{value:this.mode===`excavate`?2:+(this.mode===`translucent`)},uHasExcavation:{value:0},uExcavationMin:{value:new B(-9999,-9999)},uExcavationMax:{value:new B(9999,9999)}},vertexShader:`
5152
5152
  varying vec2 vEnuPos;
5153
5153
  void main() {
5154
5154
  vec4 worldPos = modelMatrix * vec4(position, 1.0);
@@ -5226,4 +5226,4 @@ void main() {
5226
5226
  }
5227
5227
  gl_FragColor = vec4(1.0);
5228
5228
  }
5229
- `}),i=new hc(e,r);i.position.set(0,0,-.02),i.renderOrder=-1e3,i.name=`s3m-ground-depth`,i.visible=!1,this.group.add(i),this._depthMesh=i,this._depthMaterial=r,this._syncUniforms()}_applyMode(){this._mesh&&(this._mesh.visible=this.mode!==`none`),this._material&&(this._material.uniforms.uMode.value=this.mode===`excavate`?2:+(this.mode===`translucent`),this._material.depthWrite=this.mode===`excavate`),this._depthMesh&&(this._depthMesh.visible=this.occlude,this._depthMaterial&&(this._depthMaterial.uniforms.uPunchPit.value=+(this.mode===`excavate`)))}update(e){e&&this.group.position.set(e.position.x,e.position.y,this.groundHeight)}setGroundHeight(e){this.groundHeight=e,this.group.position.z=e}setMode(e){this.mode=e,this._occludeExplicit||(this.occlude=e===`excavate`),this._applyMode()}setOcclude(e){this.occlude=e,this._occludeExplicit=!0,this._applyMode()}setOpacity(e){this.opacity=Math.max(0,Math.min(1,e)),this._material&&(this._material.uniforms.uOpacity.value=this.opacity)}setColors(e,t){this.color.set(e),t&&this.gridColor.set(t),this._material&&(this._material.uniforms.uColor.value=this.color,this._material.uniforms.uGridColor.value=this.gridColor)}setExcavationBounds(e){this.excavationBounds=e,this._syncUniforms()}autoFitExcavation(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e){let e=o.tileset?.config,s=e?.rootTiles??e?.tiles;if(Array.isArray(s))for(let e of s){let s=e.boundingBox;if(!s)continue;let c=s.center??{x:0,y:0},l=s.xExtent?.x?Math.abs(s.xExtent.x):50,u=s.yExtent?.y?Math.abs(s.yExtent.y):50,d=c.x+o.offset[0]-l,f=c.x+o.offset[0]+l,p=c.y+o.offset[1]-u,m=c.y+o.offset[1]+u;d<t&&(t=d),f>r&&(r=f),p<n&&(n=p),m>i&&(i=m),a=!0}}a&&Number.isFinite(t)&&this.setExcavationBounds([t-5,n-5,r+5,i+5])}_syncUniforms(){let e=this.excavationBounds;if(this._material){let t=this._material.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}if(this._depthMaterial){let t=this._depthMaterial.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}}dispose(){this._geom?.dispose(),this._geom=null,this._material?.dispose(),this._material=null,this._depthMaterial?.dispose(),this._depthMaterial=null,this._mesh=null,this._depthMesh=null,this.group.clear()}};sh(),fb(),Qb(),mb(),_b(),mh();function mw(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function hw(e){return e.isPoints===!0}function gw(e){let t=e??1;return t<0?0:t>1?1:t}var _w=.001,vw=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`metalness`,`roughness`,`edgeWidth`,`edgeOpacity`,`edgeOffset`,`edgeHullWidth`,`outlineWidth`],yw=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],bw=[`translation`,`elevation`,`opacity`,`color`,`rotation`],xw=class{get datasets(){return this._datasetManager.datasets}get sceneAnchor(){return this._datasetManager.sceneAnchor}set sceneAnchor(e){this._datasetManager.sceneAnchor=e}_requestRepaint(){this._onRequestRepaint()}triggerRepaint(){this._requestRepaint()}constructor(e={}){X(this,`options`,void 0),X(this,`pickable`,void 0),X(this,`onStats`,void 0),X(this,`onReady`,void 0),X(this,`onPick`,void 0),X(this,`onError`,void 0),X(this,`geo`,null),X(this,`canvas`,null),X(this,`renderer`,null),X(this,`scene`,null),X(this,`camera`,null),X(this,`picker`,null),X(this,`uniforms`,void 0),X(this,`style`,void 0),X(this,`_styleTarget`,void 0),X(this,`outlineMaterial`,void 0),X(this,`lineShared`,void 0),X(this,`edgeMaterial`,void 0),X(this,`selectionEdgeMaterial`,void 0),X(this,`_edges`,void 0),X(this,`groundManager`,void 0),X(this,`_datasetManager`,new fw),X(this,`_featureStyleManager`,void 0),X(this,`gpuPathManager`,new gb),X(this,`_customPathTime`,!1),X(this,`_picks`,void 0),X(this,`_smidMeshes`,new Map),X(this,`_heights`,void 0),X(this,`_sel`,void 0),X(this,`_tileFadeSeq`,0),X(this,`_modeGen`,0),X(this,`_shadingPrewarmed`,!1),X(this,`_prewarmShadingEnabled`,!0),X(this,`_prewarming`,!1),X(this,`_pathSpecs`,new Map),X(this,`_pathScratch`,new Float32Array(3)),X(this,`_pathScratch2`,new Float32Array(3)),X(this,`_pointClouds`,new Set),X(this,`_splats`,new zS),X(this,`_opacityTransparent`,!1),X(this,`animator`,new dw),X(this,`attributeQuery`,null),X(this,`_enuMatrix`,new U),X(this,`_frameMvp`,new U),X(this,`_colorScratch`,new W),X(this,`_frame`,0),X(this,`_fps`,{value:0,last:0}),X(this,`_lights`,void 0),X(this,`_datasetQueue`,void 0),X(this,`_onRequestRepaint`,()=>{}),X(this,`_getBearing`,void 0),X(this,`_authenticate`,void 0),X(this,`_lodRangeScale`,1),X(this,`_unsupported`,void 0),X(this,`_lodPixelRatioCap`,1/0),this.options=e,this.pickable=e.pickable!==!1,this._lodRangeScale=e.lodRangeScale??1,this._unsupported=e.unsupported??`warn`,this._lodPixelRatioCap=e.lodPixelRatioCap??1/0,Qy(e.maxTextureSize??1/0),bb(e.materialQuality??`pbr`),e.totalMaxTiles&&(this._datasetManager.totalMaxTiles=e.totalMaxTiles),this._onRequestRepaint=e.onRequestRepaint??(()=>{}),this._getBearing=e.getBearing,this._authenticate=e.authenticate,this.onStats=e.onStats??(()=>{}),this.onReady=e.onReady??(()=>{}),this.onPick=e.onPick??(()=>{}),this.onError=e.onError??(e=>console.warn(`[s3m]`,e)),this._prewarmShadingEnabled=e.prewarmShading!==!1,this.groundManager=new pw(e.ground),this.scene||(this.scene=new Jl,this.scene.add(this.groundManager.group)),this._featureStyleManager=new fC(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._sel.selection&&this._sel.syncStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=wb(),this._lights=new wS({scene:()=>this.scene,renderer:()=>this.renderer,uniforms:this.uniforms,options:this.options,getBearing:()=>this._getBearing?.(),repaint:()=>this.triggerRepaint()}),this._lights.addToScene(),this._heights=new TS(this.uniforms);let t=this;this._picks=new mC({get picker(){return t.picker},get camera(){return t.camera},get scene(){return t.scene},get canvas(){return t.canvas},get style(){return t.style},get sceneAnchor(){return t.sceneAnchor},get datasets(){return t.datasets},get featureStyleManager(){return t._featureStyleManager},get smidMeshes(){return t._smidMeshes},lngLatFromWorld:(e,n)=>t._lngLatFromWorld(e,n),gpuPathPoseAt:e=>t._gpuPathPoseAt(e),isFeatureHidden:(e,n)=>t._isFeatureHidden(e,n)}),eb(q_),this.style={...Nb,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Db(this.uniforms),this._edges=new iC({uniforms:this.uniforms,style:this.style,styleTarget:this._styleTarget,animator:this.animator,pickables:this._picks.pickables,scene:this.scene,renderer:this.renderer,camera:this.camera,authenticate:this._authenticate,requestRepaint:()=>this.triggerRepaint()}),this.lineShared=this._edges.lineShared,this.edgeMaterial=this._edges.edgeMaterial,this.selectionEdgeMaterial=this._edges.selectionEdgeMaterial,this._sel=new vC({uniforms:this.uniforms,style:this.style,outlineMaterial:this.outlineMaterial,selectionEdgeMaterial:this.selectionEdgeMaterial,featureStyleManager:this._featureStyleManager,smidMeshes:this._smidMeshes,pointClouds:this._pointClouds,applyPointCloudStyle:(e,t)=>this._applyPointCloudStyle(e,t),onPick:e=>this.onPick(e),requestRepaint:()=>this.triggerRepaint(),createSelectionEdgeMaterial:e=>this._edges.createSelectionEdgeMaterial(e)}),this.setEdges(this.style.edges),this._applyOpacity(),this._fps.last=performance.now(),this._datasetQueue=this._normalizeDatasets(e),e.attributes&&(this.attributeQuery=new j_({...e.attributes,authenticate:e.attributes.authenticate??this._authenticate}))}_createRenderer(e,t){let n=new Gl({canvas:e,context:t,antialias:!0});return n.autoClear=!1,n.setPixelRatio(1),n.toneMapping=this.options.toneMapping===void 0?0:this.options.toneMapping,n.toneMappingExposure=this.options.toneMappingExposure??1,n}_syncTextureCapabilities(e){let t=!!e.getExtension(`WEBGL_compressed_texture_s3tc`),n=!!e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`);$y(t&&n)}mount(e,t){this.canvas=e,this.renderer=this._createRenderer(e,t),Xy(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(t),this.scene=new Jl,this.scene.add(this.groundManager.group),this._addLights(),this.camera=new xc,this.camera.matrixAutoUpdate=!1,this.picker=new NC(this.renderer),this._applyStyleUniforms();for(let e of this._datasetQueue)this.addDataset(e).catch(e=>this.onError(e));this._recomputeAnchors()}restoreContext(e){if(!this.canvas)console.warn(`[s3m] restoreContext 调用过早(尚未 mount),按首次挂载处理`);else{try{this.renderer?.dispose?.()}catch{}this.renderer=this._createRenderer(this.canvas,e),Xy(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new NC(this.renderer),this._edges.disposeGpuEdge(),this._requestRepaint()}}unmount(){for(let e of[...this.datasets.keys()])this.removeDataset(e);this.clearCreases(),this.groundManager.dispose(),this.picker?.dispose(),this.picker=null,this._lights.dispose(),this.outlineMaterial.dispose(),this._edges.disposeGpuEdge(),this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose(),this.scene?.clear(),this._sel.reset(),this._smidMeshes.clear(),this._heights.clear(),this.animator.clear(),this.animator.unregisterPrefix(`tile.`),this.animator.unregisterPrefix(`feature.`),this._pathSpecs.clear(),this.renderer?.dispose?.(),this.renderer=null,this.canvas=null}get _ambientLight(){return this._lights.ambient}get _hemiLight(){return this._lights.hemi}get _keyLight(){return this._lights.key}get _fillLight(){return this._lights.fill}_updateLights(){this._lights.update()}_addLights(){this._lights.addToScene()}setLightingPreset(e){this._lights.setLightingPreset(e)}setLight(e){this._lights.setLight(e)}getLight(){return this._lights.getLight()}setToneMapping(e,t=1){this._lights.setToneMapping(e,t)}getToneMapping(){return this._lights.getToneMapping()}setEnvironment(e,t=1){return this._lights.setEnvironment(e,t)}_normalizeDatasets(e){return Array.isArray(e.datasets)?e.datasets.filter(e=>!!e?.configUrl).map(t=>({...t,polygonOffset:t.polygonOffset??e.polygonOffset})):e.configUrl?[{id:`default`,name:`默认数据集`,configUrl:e.configUrl,useWorker:e.useWorker,polygonOffset:e.polygonOffset}]:[]}async addDataset(e){if(!this.scene)throw Error(`[s3m] 图层尚未 addLayer,不能添加数据集`);let t={...e,unsupported:e.unsupported??this._unsupported};return await this._datasetManager.addDataset(t,this.scene,this.geo,this.uniforms,this._lodRangeScale,this.options.buildTile,this.options.maxTiles??64,this.options.maxConcurrent??4,{onTile:(e,t)=>{this._registerTile(e,t),this.onStats(this.stats),this._requestRepaint()},onTileRemoved:(e,t)=>{this._unregisterTile(e,t),this.onStats(this.stats),this._requestRepaint()},onStats:()=>{this.onStats(this.stats),this._requestRepaint()},onError:e=>{this.onError(e),this.onStats(this.stats)},onReady:e=>{this.onReady(e),this._heights.refreshAll(),this.groundManager.excavationBounds||this.groundManager.autoFitExcavation(this.datasets.values())},triggerRepaint:()=>{this._requestRepaint()}},this.options.maxTriangles??1/0,this.options.maxImageCache??128,this._authenticate)}_lngLatFromWorld(e,t){return I_(this.geo,e,t)}recomputeAnchors(){this._datasetManager.recomputeAnchors(this.geo),this._heights.refreshAll(),this._requestRepaint()}_recomputeAnchors(){this.recomputeAnchors()}getDatasetHeight(e){return this._datasetManager.getDatasetHeight(e)}setDatasetHeight(e,t){let n,r;typeof e==`number`?(n=this.datasets.keys().next().value??``,r=e):(n=e,r=t??0),this._datasetManager.setDatasetHeight(n,r,this.geo),this._syncGroundHeight(),this._heights.refreshAll(),this._requestRepaint()}_syncGroundHeight(){if(!this.groundManager.trackHeight)return;let e=this.datasets.keys().next().value;if(!e)return;let t=this._datasetManager.getDatasetHeight(e);this.groundManager.setGroundHeight(t)}setDatasetAlign(e,t){let n,r;t===void 0&&(e===`origin`||e===`bottom`||e===`top`||e===`center`)?(n=this.datasets.keys().next().value??``,r=e):(n=e,r=t??`origin`),this._datasetManager.setDatasetAlign(n,r,this.geo),this._heights.refreshAll(),this._requestRepaint()}_computeAlignOffset(e,t){return this._datasetManager.computeAlignOffset(e,t)}computeAlignOffset(e,t){return this._datasetManager.computeAlignOffset(e,t)}setFeatureStyle(e,t){this._featureStyleManager.setFeatureStyle(e,t,this._meshesOf([e]))}setFeaturesStyle(e,t){this._featureStyleManager.setFeaturesStyle(e,t,this._meshesOf(e))}moveFeature(e,t,n){let r=this._ensureFeatureChannel(e,`translation`);this.animator.to(r,t,n)}moveFeatureBy(e,t,n){let r=this._featureStyleManager.getFeatureStyle(e)?.translation??[0,0,0];this.moveFeature(e,[r[0]+t[0],r[1]+t[1],r[2]+t[2]],n)}rotateFeature(e,t,n,r){let i=this._featureStyleManager.getFeatureStyle(e)??{};n&&this._featureStyleManager.setFeatureStyle(e,{...i,pivot:n},this._meshesOf([e]));let a=sC(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=sC(this._featureStyleManager.getFeatureStyle(e)?.rotation),a=typeof t==`number`?[0,0,t]:t;this.rotateFeature(e,[i[0]+a[0],i[1]+a[1],i[2]+a[2]],n,r)}crossFadeStyles(e,t){let n=e instanceof Map?e:new Map(Object.entries(e).map(([e,t])=>[Number(e),t])),r=this.getAllMeshes();this._featureStyleManager.prepareCrossFade(n,r);let i=`batch.mix`;this.animator.has(i)||this.animator.register(i,{dim:1,read:e=>{e[0]=this.uniforms.uBatchMix?.value??0},write:e=>{this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=e[0]),this.triggerRepaint()}}),(t?.duration??0)>0||t?.spring?(this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=0),this.animator.to(i,1,{...t,onComplete:()=>{this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=0),this._featureStyleManager.commitCrossFade(n,r),this.triggerRepaint(),t?.onComplete?.()}})):(this.animator.has(i)&&this.animator.cancel(i),this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=0),this._featureStyleManager.commitCrossFade(n,r),this.triggerRepaint(),t?.onComplete?.())}followPath(e,t,n={}){let r=t instanceof pb?t:new pb(t,{closed:n.closed});if(r.length<=0)return;let i=n.offset??[0,0,0],a=n.duration??(n.speed&&n.speed>0?r.length/n.speed*1e3:2e3),o=`feature.${e}.path`;this._pathSpecs.set(o,{path:r,offset:i}),this.animator.has(o)||this.animator.register(o,{dim:1,read:e=>{e[0]=0},write:t=>{let n=this._pathSpecs.get(o);if(!n)return;n.path.sampleAt(t[0],this._pathScratch);let r=this._meshesOf([e]),i=this._featureStyleManager.getFeatureStyle(e)??{};this._featureStyleManager.setFeatureStyle(e,{...i,translation:[n.offset[0]+this._pathScratch[0],n.offset[1]+this._pathScratch[1],n.offset[2]+this._pathScratch[2]]},r);for(let e of r)e.frustumCulled=!1}});let s=()=>{this.animator.to(o,1,{duration:a,easing:n.easing??`linear`,onComplete:()=>{n.loop?s():n.onComplete?.()}})};s()}stopPath(e){let t=`feature.${e}.path`;this.animator.cancel(t),this.animator.unregister(t),this._pathSpecs.delete(t)}_gpuPathPoseAt(e){let t=this._featureStyleManager.getFeatureStyle(e)?.gpuPath;if(!t)return null;let n=this.gpuPathManager.getPath(t.pathId);if(!n||n.length<=0)return null;let r=this.uniforms.uPathTime?.value??0,i=(t.phase??0)+r*(t.speed??0),a=t.loop;a===`clamp`||a===!1?i=Math.min(1,Math.max(0,i)):a===`pingpong`?(i%=2,i<0&&(i+=2),i=i>1?2-i:i):i-=Math.floor(i),n.sampleAt(i,this._pathScratch);let o=[this._pathScratch[0],this._pathScratch[1],this._pathScratch[2]],s=0;if(t.autoHeading!==!1){let e=.001;n.sampleAt(Math.min(1,i+e),this._pathScratch2);let t=this._pathScratch2[0]-o[0],r=this._pathScratch2[1]-o[1];t*t+r*r<1e-8&&(n.sampleAt(Math.max(0,i-e),this._pathScratch2),t=o[0]-this._pathScratch2[0],r=o[1]-this._pathScratch2[1]),t*t+r*r>=1e-8&&(s=Math.atan2(r,t))}return{pos:o,yaw:s}}registerGPUPath(e,t={}){let n=this.gpuPathManager.registerPath(e,t);return this.gpuPathManager.updateUniforms(this.uniforms),n}unregisterGPUPath(e){let t=this.gpuPathManager.unregisterPath(e);return this.gpuPathManager.updateUniforms(this.uniforms),t}getGPUPathManager(){return this.gpuPathManager}bindGPUPath(e,t,n={}){let r;r=typeof t==`number`?t:this.registerGPUPath(t);let i=this._meshesOf([e]);this._featureStyleManager.bindGPUPath(e,r,n,i);for(let e of i)e.frustumCulled=!1;return this.gpuPathManager.updateUniforms(this.uniforms),r}unbindGPUPath(e){let t=this._meshesOf([e]);this._featureStyleManager.unbindGPUPath(e,t),this.gpuPathManager.updateUniforms(this.uniforms)}setGPUPathProgress(e,t){let n=this._meshesOf([e]);this._featureStyleManager.setGPUPathProgress(e,t,n);for(let e of n)e.frustumCulled=!1}setGPUPathTime(e,t=!1){this.uniforms.uPathTime&&(this.uniforms.uPathTime.value=e),this._customPathTime=!t}getGPUPathTime(){return this.uniforms.uPathTime?.value??0}animateFeature(e,t,n){if(t.translation&&this.moveFeature(e,t.translation,n),t.rotation!=null&&this.rotateFeature(e,t.rotation,t.pivot,n),t.elevation!=null&&this.animator.to(this._ensureFeatureChannel(e,`elevation`),t.elevation,n),t.opacity!=null&&this.animator.to(this._ensureFeatureChannel(e,`opacity`),t.opacity,n),t.color&&(this._colorScratch.set(t.color),this.animator.to(this._ensureFeatureChannel(e,`color`),[this._colorScratch.r,this._colorScratch.g,this._colorScratch.b],n)),t.hidden!=null){let n=this._featureStyleManager.getFeatureStyle(e)??{};this.setFeatureStyle(e,{...n,hidden:t.hidden})}}animateFeatures(e,t,n){let r=n?.stagger??0;if(r<=0){for(let r of e)this.animateFeature(r,t,n);return}let i=n?.delay??0;for(let a=0;a<e.length;a++)this.animateFeature(e[a],t,{...n,delay:i+a*r})}setMode(e,t={}){let n=Math.max(0,t.duration??300),r=Math.min(1,Math.max(.05,t.dim??.35));if(this.style.mode===e)return Promise.resolve();if(n<=0)return this.setStyle({mode:e}),Promise.resolve();let i=++this._modeGen;return new Promise(t=>{this.animator.to(`style.fade`,r,{duration:n,easing:`easeInOutQuad`,onComplete:()=>{i===this._modeGen?(this.setStyle({mode:e}),this.animator.to(`style.fade`,1,{duration:n,easing:`easeInOutQuad`,onComplete:t})):t()}})})}_ensureFeatureChannel(e,t){let n=`feature.${e}.${t}`;if(this.animator.has(n))return n;let r=t===`translation`||t===`color`||t===`rotation`?{dim:3,read:n=>{if(t===`translation`){let t=this._featureStyleManager.getFeatureStyle(e)?.translation;n[0]=t?.[0]??0,n[1]=t?.[1]??0,n[2]=t?.[2]??0}else if(t===`rotation`){let t=this._featureStyleManager.getFeatureStyle(e)?.rotation,r=sC(t);n[0]=r[0],n[1]=r[1],n[2]=r[2]}else{let t=this._featureStyleManager.getFeatureStyle(e)?.color??this.style.colorA;this._colorScratch.set(t),n[0]=this._colorScratch.r,n[1]=this._colorScratch.g,n[2]=this._colorScratch.b}},write:n=>{let r=this._meshesOf([e]),i=this._featureStyleManager.getFeatureStyle(e)??{};if(t===`translation`){this._featureStyleManager.setFeatureStyle(e,{...i,translation:[n[0],n[1],n[2]]},r);let t=Math.abs(n[0])>1e-6||Math.abs(n[1])>1e-6||Math.abs(n[2])>1e-6,a=sC(i.rotation),o=Math.abs(a[0])>1e-6||Math.abs(a[1])>1e-6||Math.abs(a[2])>1e-6;for(let e of r)e.frustumCulled=!(t||o)}else if(t===`rotation`){this._featureStyleManager.setFeatureStyle(e,{...i,rotation:[n[0],n[1],n[2]]},r);let t=Math.abs(n[0])>1e-6||Math.abs(n[1])>1e-6||Math.abs(n[2])>1e-6,a=i.translation??[0,0,0],o=Math.abs(a[0])>1e-6||Math.abs(a[1])>1e-6||Math.abs(a[2])>1e-6;for(let e of r)e.frustumCulled=!(t||o)}else{let t=this._colorScratch.setRGB(n[0],n[1],n[2]);this._featureStyleManager.setFeatureStyle(e,{...i,color:`#${t.getHexString()}`},r)}}}:{dim:1,read:n=>{let r=this._featureStyleManager.getFeatureStyle(e);n[0]=(t===`elevation`?r?.elevation:r?.opacity)??+(t===`opacity`)},write:n=>{let r=this._featureStyleManager.getFeatureStyle(e)??{},i=t===`elevation`?{...r,elevation:n[0]}:{...r,opacity:n[0]};this._featureStyleManager.setFeatureStyle(e,i,this._meshesOf([e]))}};return this.animator.register(n,r),n}_releaseFeatureChannels(e){for(let t of bw)this.animator.unregister(`feature.${e}.${t}`);let t=`feature.${e}.path`;this.animator.unregister(t),this._pathSpecs.delete(t)}getFeatureStyle(e){return this._featureStyleManager.getFeatureStyle(e)}getFeatureStyles(){return this._featureStyleManager.getFeatureStyles()}removeFeatureStyle(e){this._releaseFeatureChannels(e),this._featureStyleManager.removeFeatureStyle(e,this._meshesOf([e]))}clearFeatureStyles(){for(let e of this._featureStyleManager.getFeatureStyles().keys())this._releaseFeatureChannels(e);this._featureStyleManager.clearFeatureStyles()}setAttributeSource(e){this.attributeQuery=e?new j_({...e,authenticate:e.authenticate??this._authenticate}):null}getLoadedSmids(){return[...this._smidMeshes.keys()]}auditBatches(){let e=this._featureStyleManager.auditBatches(this._picks.pickables.values());return e.smids=this._smidMeshes.size,e}getThematicField(){return this._featureStyleManager.thematicField}setThematicColors(e,t=`custom`){this._featureStyleManager.setThematicColors(e,t)}clearThematic(){this._featureStyleManager.clearThematicColors()}getFilterField(){return this._featureStyleManager.fieldFilter?.field??null}filterByField(e){return this._featureStyleManager.filterByField(e,this.attributeQuery,this.getLoadedSmids())}clearFieldFilter(){this._featureStyleManager.clearFieldFilter()}getElevationField(){return this._featureStyleManager.elevationField}elevateByField(e){return this._featureStyleManager.elevateByField(e,this.attributeQuery,this.getLoadedSmids())}setThematicElevation(e,t=`custom`){this._featureStyleManager.setThematicElevation(e,t)}clearThematicElevation(){this._featureStyleManager.clearThematicElevation()}colorByField(e){return this._featureStyleManager.colorByField(e,this.attributeQuery,this.getLoadedSmids())}setFilter(e){this._featureStyleManager.setFilter(e,this.uniforms)}getFilter(){return this._featureStyleManager.filter}clearFilter(){this._featureStyleManager.clearFilter(this.uniforms)}setGroundMode(e){this.groundManager.setMode(e),this._requestRepaint()}setGroundOpacity(e){this.groundManager.setOpacity(e),this._requestRepaint()}setExcavationBounds(e){this.groundManager.setExcavationBounds(e),this._requestRepaint()}setGroundOcclude(e){this.groundManager.setOcclude(e),this._requestRepaint()}_isFeatureHidden(e,t){if(e==null)return!1;let n=this._featureStyleManager.fieldFilter;if(n){let t=n.matched.has(e);if(n.mode===`keep`?!t:t)return!0}let r=this._featureStyleManager.filter;return!!(r&&(r.include&&r.include.length>0&&!r.include.includes(e)||r.exclude&&r.exclude.length>0&&r.exclude.includes(e))||this._featureStyleManager.featureStyles.get(e)?.hidden)}getAllMeshes(){let e=[];for(let t of this._picks.pickables.values())e.push(t.mesh);return e}_meshesOf(e){let t=new Set;for(let n of e){let e=this._smidMeshes.get(n);if(e)for(let n of e)t.add(n)}return t}flushOverrides(){this._featureStyleManager.flushOverrides()}_applyOverridesToMesh(e){this._featureStyleManager.applyOverridesToMesh(e)}removeDataset(e){if(this.datasets.get(e)){this._sel.selection?.datasetId===e&&this.select(null),this._datasetManager.removeDataset(e,this.scene,this.geo,e=>{e.root.traverse(e=>{let t=e,n=t.userData;n.pickId!=null&&(this._picks.pickables.delete(n.pickId),this._releasePickId(n.pickId),n.pickId=void 0),this._unindexMeshSmids(t),this._heights.remove(t),t.geometry?.dispose?.();let r=mw(t);r&&r.dispose(),EC(t.material)&&t.material.dispose(),this._featureStyleManager.disposeMesh(t)})});for(let[t,n]of this._picks.pickables)n.datasetId===e&&this._picks.pickables.delete(t);this.onStats(this.stats),this._requestRepaint()}}clearDatasets(){for(let e of[...this.datasets.keys()])this.removeDataset(e)}setDatasetVisible(e,t){this._datasetManager.setDatasetVisible(e,t),!t&&this._sel.selection?.datasetId===e&&this.select(null),this._requestRepaint()}_registerTile(e,t){t.root.add(e.group),e.group.updateMatrixWorld(!0);let n=e.group.userData.hasNativeEdges===!0,r=this._edges.useNativeEdges(n);for(let i of e.group.children){if(i.isLineSegments&&i.userData.isEdgeLines){this._edges.registerNativeLine(i,r&&this._edges.enabled);continue}let a=hw(i),o=i;if(!o.isMesh&&!a)continue;a&&this._pointClouds.add(i),a&&this._splats.markDirty();let s=o.userData;if(s.pickId=this._allocPickId(),s.datasetId=t.id,s.nativeEdges=r,s.nativeEdgesRaw=n,this._picks.pickables.set(s.pickId,{datasetId:t.id,mesh:o,tile:e.tile,skeletonName:s.skeletonName??``}),this._indexMeshSmids(o),this._heights.add(o),this._edges.autoDecorate(o,t,r),a)this._applyPointCloudStyle(i);else{let e=mw(o);if(e){let t=gw(this.style.opacity),n=this.style.depthWrite!==!1;Eb(e,t<.999,n),e.userData.uFlatShading&&(e.userData.uFlatShading.value=this.style.shading===`smooth`?0:1),this._featureStyleManager.applyOverridesToMesh(o),this._startTileFade(o,e)}}this._sel.replayOnto(o)}}_startTileFade(e,t){let n=this.style.fadeIn??0;if(n<=0)return;let r=t.userData.uTileFade;if(!r)return;r.value=0,t.transparent=!0,t.depthWrite=!0;let i=`tile.${this._tileFadeSeq++}.fade`;e.userData.tileFadeKey=i,this.animator.register(i,{dim:1,read:e=>{e[0]=r.value},write:e=>{r.value=e[0]}}),this.animator.to(i,1,{duration:n,easing:`easeOutQuad`,onComplete:()=>{r.value=1,e.userData.tileFadeKey=void 0,this.animator.unregister(i),Eb(t,this._opacityTransparent,this.style.depthWrite!==!1),this._featureStyleManager.applyOverridesToMesh(e),this._requestRepaint()}})}_replaySelectionOnto(e){this._sel.replayOnto(e)}_unregisterTile(e,t){e.group.traverse(e=>{let t=e;if(e.isLineSegments&&t.userData?.isEdgeLines&&this._edges.unregisterNativeLine(e),hw(e)&&this._pointClouds.delete(e),t.userData?.tileFadeKey&&(this.animator.unregister(t.userData.tileFadeKey),t.userData.tileFadeKey=void 0),t.userData?.pickId!=null&&(this._picks.pickables.delete(t.userData.pickId),this._releasePickId(t.userData.pickId),t.userData.pickId=void 0),t.isMesh){this._sel.selectedMeshes.includes(t)&&(this._sel.selectedMeshes=this._sel.selectedMeshes.filter(e=>e!==t));let e=this._sel.selection;if(e&&e.mesh===t){let n=e.smid,r=n==null?this._sel.selectedMeshes.find(e=>e!==t&&e.parent&&e.parent.visible)??this._sel.selectedMeshes.find(e=>e!==t&&e.parent):[...this._smidMeshes.get(n)??[]].find(e=>e!==t&&e.parent);r?(this._sel.selection={...e,mesh:r},this._sel.replayOnto(r)):this.select(null)}this._unindexMeshSmids(t),this._heights.remove(t),this._featureStyleManager.disposeMesh(t),mw(t)?.dispose?.()}EC(t.material)?t.material.dispose():t.material&&(Array.isArray(t.material)?t.material.forEach(e=>e?.dispose?.()):t.material.dispose?.()),t.geometry?.dispose?.()}),t.root.remove(e.group)}setOpacity(e,t){this.setStyle({opacity:e},t)}setStyle(e={},t){Object.assign(this._styleTarget,e);let n=t?.duration??0,r=n>0||!!t?.spring,i=e;if(`edges`in e){let{edges:n,...a}=e;if(i=a,this.setEdges(n,r?t:void 0),Object.keys(i).length===0){this._requestRepaint();return}}let a=[],o={};for(let e of Object.keys(i))r&&this.animator.has(`style.${String(e)}`)?a.push(String(e)):o[e]=i[e];Object.keys(o).length>0&&(Object.assign(this.style,o),this._applyStyleEffects(o));for(let e of a)this.animator.to(`style.${e}`,this._animTargetOf(e,i),{...t,duration:n});this._requestRepaint()}getStyle(){return{...this._styleTarget,modeLabel:kb[this._styleTarget.mode]}}_animTargetOf(e,t){let n=t[e];return this._animDimOf(e)===1?Number(n):(this._colorScratch.set(String(n)),[this._colorScratch.r,this._colorScratch.g,this._colorScratch.b])}_animDimOf(e){return yw.includes(e)?3:1}_registerAnimChannels(){for(let e of vw)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of yw)this.animator.register(`style.${e}`,{dim:3,read:t=>{let n=this._uniformColorOf(e);t[0]=n.r,t[1]=n.g,t[2]=n.b},write:t=>{let n=this._uniformColorOf(e);n.setRGB(t[0],t[1],t[2]),this.style[e]=`#${n.getHexString()}`,this._onStyleChannelWrote(e)}});this.animator.register(`style.edgeFade`,{dim:1,read:e=>{e[0]=this.uniforms.uEdgeFade?.value??1},write:e=>{this.uniforms.uEdgeFade&&(this.uniforms.uEdgeFade.value=e[0]),this._edges.syncStyle()}}),this.animator.register(`style.fade`,{dim:1,read:e=>{e[0]=this.uniforms.uFade?.value??1},write:e=>{this.uniforms.uFade&&(this.uniforms.uFade.value=e[0]),this._requestRepaint()}})}_onStyleChannelWrote(e){e===`opacity`?this._applyOpacity():(this._applyStyleUniforms(),(e===`edgeColor`||e===`edgeWidth`||e===`edgeOpacity`||e===`edgeOffset`||e===`edgeHullWidth`)&&this._edges.refreshLines())}_uniformColorOf(e){let t=this.uniforms;switch(e){case`colorA`:return t.uColorA.value;case`colorB`:return t.uColorB.value;case`colorC`:return t.uColorC.value;case`selectColor`:return t.uSelColor.value;case`edgeColor`:return this.edgeMaterial.uniforms.uColor.value;default:return t.uColorA.value}}_applyStyleEffects(e){this._applyStyleUniforms(),(`opacity`in e||`depthWrite`in e)&&this._applyOpacity(),`mode`in e&&this._applyPointCloudStyles(),`shading`in e&&this._applyShading(),(`edgeThreshold`in e||`forceCpuEdges`in e)&&this._edges.enabled?(this._edges.disposeEdgeGeometry(),this.setEdges(this.style.edges)):(`edgeColor`in e||`edgeWidth`in e||`opacity`in e||`edgeOpacity`in e||`edgeOffset`in e||`edgeHullWidth`in e)&&this._edges.refreshLines(),this._sel.selection&&(`outline`in e||`outlineStyle`in e?this.select(this._sel.selection,{silent:!0}):this._sel.syncStyle())}_applyStyleUniforms(){let e=this.uniforms,t=this.style;e.uMode.value=t.mode,e.uColorA.value.set(t.colorA),e.uColorB.value.set(t.colorB),e.uColorC.value.set(t.colorC),e.uSelColor.value.set(t.selectColor),e.uFloorHeight.value=t.floorHeight;let n=t.selectMode??Ab.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===Ab.REPLACE?0:n===Ab.MULTIPLY?2:n===Ab.GLOW_ONLY?3:1),e.uSelOpacity&&t.selectOpacity!=null&&(e.uSelOpacity.value=t.selectOpacity),e.uSelEmissive&&t.selectEmissive!=null&&(e.uSelEmissive.value=t.selectEmissive),e.uSelElevation&&t.selectElevation!=null&&(e.uSelElevation.value=t.selectElevation),e.uDimFactor&&t.dimFactor!=null&&(e.uDimFactor.value=t.dimFactor),e.uRoofThreshold&&t.roofThreshold!=null&&(e.uRoofThreshold.value=t.roofThreshold),e.uTexMix&&t.texMix!=null&&(e.uTexMix.value=t.texMix),e.uAmbientGain&&t.ambientGain!=null&&(e.uAmbientGain.value=t.ambientGain),e.uMetalness&&(e.uMetalness.value=t.metalness??-1),e.uRoughness&&(e.uRoughness.value=t.roughness??-1),e.uOpacity&&t.opacity!=null&&(e.uOpacity.value=gw(t.opacity)),this.outlineMaterial&&(this.outlineMaterial.uniforms.uElevation&&t.selectElevation!=null&&(this.outlineMaterial.uniforms.uElevation.value=t.selectElevation),t.outlineWidth!=null&&(this.outlineMaterial.uniforms.uWidth.value=t.outlineWidth),t.outlineColor==null?this.outlineMaterial.uniforms.uColor.value.set(t.selectColor):this.outlineMaterial.uniforms.uColor.value.set(t.outlineColor))}_applyOpacity(){let e=gw(this.style.opacity);this.uniforms.uOpacity&&(this.uniforms.uOpacity.value=e);let t=e<.999;if(t!==this._opacityTransparent){this._opacityTransparent=t;let e=this.style.depthWrite!==!1;for(let n of this._picks.pickables.values()){if(hw(n.mesh))continue;let r=mw(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||Eb(r,t,e))}}for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._edges.syncStyle(),this._requestRepaint()}_applyPointCloudStyle(e,t=this._sel.selectedMeshes.includes(e)){TC(e,this.style,this.uniforms,t)}_applyPointCloudStyles(){for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._requestRepaint()}_applyShading(){let e=this.style.shading===`smooth`?0:1;for(let t of this._picks.pickables.values()){let n=mw(t.mesh)?.userData.uFlatShading;n&&n.value!==e&&(n.value=e)}this._requestRepaint()}setMaterialQuality(e){bb(e),this._rebuildStyledMaterials(),this._requestRepaint()}get materialQuality(){return xb()}_rebuildStyledMaterials(){let e=[`uSelBatch`,`uSelWhole`,`uBatchTex`,`uBatchTex2`,`uBatchTexWidth`,`uBatchTexActive`,`uTileFade`];for(let t of this._picks.pickables.values()){let n=t.mesh,r=n.material;if(Array.isArray(r))continue;let i=r;if(!i?.userData?.isStyled||!i.userData?.s3mOpts)continue;let a=i.userData.s3mOpts,o=Tb({...a,uniforms:this.uniforms});for(let t of e){let e=i.userData[t],n=o.userData[t];e&&n&&(n.value=e.value)}n.material=o,i.dispose()}}async prewarmShading(){if(this._shadingPrewarmed||this._prewarming)return;let e=this.renderer,t=this.scene,n=this.camera;if(!e||!t||!n)return;let r=!1;for(let e of this._picks.pickables.values())if(mw(e.mesh)){r=!0;break}if(r){this._shadingPrewarmed=!0;try{let r=e;typeof r.compileAsync==`function`?await r.compileAsync(t,n):e.compile(t,n)}catch{}this._requestRepaint()}}_addMeshHeight(e){this._heights.add(e)}_removeMeshHeight(e){this._heights.remove(e)}_indexMeshSmids(e){let t=e.userData.geoRef?.pickInfo;if(t)for(let n of Object.keys(t)){let t=Number(n);if(!Number.isFinite(t)||t<0)continue;let r=this._smidMeshes.get(t);r||this._smidMeshes.set(t,r=new Set),r.add(e)}}_unindexMeshSmids(e){let t=e.userData.geoRef?.pickInfo;if(t)for(let n of Object.keys(t)){let t=Number(n),r=this._smidMeshes.get(t);r&&(r.delete(e),r.size===0&&this._smidMeshes.delete(t))}}get _edgesEnabled(){return this._edges.enabled}get _edgeModes(){return this._edges.modes}get _gpuEdge(){return this._edges.gpuEdge}set _gpuEdge(e){this._edges.gpuEdge=e}_ensureEdges(e){this._edges.ensureEdges(e)}_removeEdges(e){this._edges.removeEdges(e)}setEdges(e,t){this._edges.setEdges(e,t)}loadCreases(e){return this._edges.loadCreases(e)}clearCreases(){this._edges.clearCreases()}getRayAt(e,t){return this._picks.getRayAt(e,t)}pick(e,t){return this._picks.pick(e,t)}pickPosition(e,t){return this._picks.pickPosition(e,t)}drillPick(e,t,n=10){return this._picks.drillPick(e,t,n)}getFeatureBounds(e){return this._picks.getFeatureBounds(e)}_intersectMeshAtRay(e,t,n){return this._picks.intersectMeshAtRay(e,t,n)}_buildPickResult(e,t,n,r){return this._picks.buildPickResult(e,t,n,r)}_buildSplatPickResult(e,t,n,r){return this._picks.buildSplatPickResult(e,t,n,r)}_instanceFeature(e,t,n){return this._picks.instanceFeature(e,t,n)}_instanceBox(e,t){return this._picks.instanceBox(e,t)}_allocPickId(){return this._picks.allocPickId()}_releasePickId(e){this._picks.releasePickId(e)}get _pickables(){return this._picks.pickables}select(e,t={}){this._sel.select(e,t)}_syncSelectionStyle(){this._sel.syncStyle()}get _selection(){return this._sel.selection}get _selectedMeshes(){return this._sel.selectedMeshes}get _selectionEdgeMeshes(){return this._sel.selectionEdgeMeshes}_updateLineResolution(e){let t=e.width||1,n=e.height||1,r=e.clientWidth||t;this.lineShared.uResolution.value.set(t,n),this.lineShared.uDpr.value=Math.max(1,t/r)}get lodRangeScale(){return this._lodRangeScale}get lodPixelRatioCap(){return this._lodPixelRatioCap}setLodPixelRatioCap(e){let t=e>0?e:1/0;this._lodPixelRatioCap=t,this.options.lodPixelRatioCap=t,this._requestRepaint()}_lodScreenHeight(e){let t=this._lodPixelRatioCap;if(!Number.isFinite(t))return e;let n=this.canvas?.clientHeight??0;return n<=0?e:Math.min(e,n*t)}get maxImageCache(){return this.options.maxImageCache??128}setMaxImageCache(e,t){let n=Number.isFinite(e)?Math.max(1,Math.floor(e)):128;if(t){let e=this.datasets.get(t);e?.tileset&&(e.tileset.maxImageCache=n)}else{this.options.maxImageCache=n;for(let e of this.datasets.values())e.tileset&&(e.tileset.maxImageCache=n)}this._requestRepaint()}get maxTriangles(){return this.options.maxTriangles??1/0}setMaxTriangles(e,t){let n=e>0?e:1/0;if(t){let e=this.datasets.get(t);e?.tileset&&e.tileset.setMaxTriangles(n)}else{this.options.maxTriangles=n;for(let e of this.datasets.values())e.tileset&&e.tileset.setMaxTriangles(n)}}get anisotropyCap(){return this.options.anisotropyCap??1/0}setAnisotropyCap(e){let t=Number.isFinite(e)&&e>0?Math.max(1,e):1/0;this.options.anisotropyCap=t,Xy(this.renderer?.capabilities.getMaxAnisotropy?.()??1,t),this._requestRepaint()}get maxTextureSize(){return this.options.maxTextureSize??1/0}setMaxTextureSize(e){let t=Number.isFinite(e)&&e>=1?e:1/0;this.options.maxTextureSize=t,Qy(t),this._requestRepaint()}setLodRangeScale(e,t){if(!(e<=0)){if(t){let n=this.datasets.get(t);n?.tileset&&(n.tileset.lodRangeScale=e)}else{this._lodRangeScale=e;for(let t of this.datasets.values())t.tileset&&(t.tileset.lodRangeScale=e)}this._requestRepaint()}}_sortSplats(){this._splats.sort(this.camera,this._pointClouds)}renderFrame(e){if(!this.renderer||!this.scene||!this.camera||!this.sceneAnchor||!this.canvas)return!1;let t=this.renderer.getContext();if(t&&typeof t.isContextLost==`function`&&t.isContextLost())return!1;if(this._prewarming)return!0;let n=this.animator.tick();this.flushOverrides();let r=this.canvas,i=this.sceneAnchor.meterInMercator;this._enuMatrix.set(i,0,0,this.sceneAnchor.x,0,-i,0,this.sceneAnchor.y,0,0,i,this.sceneAnchor.z,0,0,0,1);let a=this._frameMvp.fromArray(e.mvp);a.multiply(this._enuMatrix),this.camera.projectionMatrix.copy(a),this.camera.projectionMatrixInverse.copy(a).invert();let o=e.cameraEnu;this.camera.position.set(o[0],o[1],o[2]),this.camera.matrixWorld.setPosition(o[0],o[1],o[2]),this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert(),this.groundManager.update(this.camera);let s=!1,c=this._lodScreenHeight(e.canvasHeight);for(let t of this.datasets.values()){if(!t.visible||!t.tileset)continue;let n=[o[0]-t.offset[0],o[1]-t.offset[1],o[2]-t.offset[2]];t.tileset.update(n,e.fovRad,c)&&(s=!0)}this.style.mode===Ob.DYNAMIC&&(this.uniforms.uTime.value+=.016*(this.style.speed??1)),this.gpuPathManager.updateUniforms(this.uniforms);let l=(this.uniforms.uPathTexActive?.value??0)>0;l&&!this._customPathTime&&this.uniforms.uPathTime&&(this.uniforms.uPathTime.value+=.016),this._updateLights(),this._updateLineResolution(r),Gx(r.width,r.height),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),(this.uniforms.uOpacity?.value??1)>_w&&(this._sortSplats(),this.renderer.render(this.scene,this.camera),this._edges.renderGpuEdges(r)),this._frame++;let u=performance.now();u-this._fps.last>500&&(this._fps.value=Math.round(this._frame*1e3/(u-this._fps.last)),this._frame=0,this._fps.last=u);let d=n||this.style.mode===Ob.DYNAMIC||l||this.stats.loading>0||s;return this._prewarmShadingEnabled&&!this._shadingPrewarmed&&this._picks.pickables.size>0&&this.prewarmShading(),d}get fps(){return this._fps.value}get stats(){let e={tiles:0,loading:0,failed:0,meshes:0,vertices:0,triangles:0,datasets:this.datasets.size,drawCalls:0,programs:0,textures:0,geometries:0,degradations:[]},t=null;for(let n of this.datasets.values()){let r=n.tileset?.stats;if(r&&(e.tiles+=r.tiles,e.loading+=r.loading,e.failed+=r.failed,e.meshes+=r.meshes,e.vertices+=r.vertices,e.triangles+=r.triangles,r.degradations?.length)){t??(t=[]);for(let e of r.degradations)t.includes(e)||t.push(e)}}t&&(e.degradations=t);let n=this.renderer?.info;return n&&(e.drawCalls=n.render.calls,e.programs=n.programs?.length??0,e.textures=n.memory.textures,e.geometries=n.memory.geometries),e}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of this.datasets.values()){let a=hS(i.tileset?.config?.geoBounds);a&&(e=Math.min(e,a.left),n=Math.max(n,a.right),t=Math.min(t,a.bottom),r=Math.max(r,a.top))}return isFinite(e)?[[e,t],[n,r]]:null}dispose(){this.unmount()}};mh();var Sw=class e{constructor(t={}){X(this,`id`,void 0),X(this,`options`,void 0),X(this,`pickable`,void 0),X(this,`onStats`,void 0),X(this,`onReady`,void 0),X(this,`onPick`,void 0),X(this,`onError`,void 0),X(this,`viewer`,void 0),X(this,`_projection`,`perspective`),X(this,`_projectionT`,0),X(this,`_orthoWarned`,!1),X(this,`_nearPlaneScale`,1),this.id=t.id??`s3m`,this.options=t,this.pickable=t.pickable!==!1,this._projection=t.projection===`orthographic`?`orthographic`:`perspective`,this._nearPlaneScale=e.normalizeNearPlaneScale(t.nearPlaneScale),this._projectionT=+(this._projection===`orthographic`),this.onStats=t.onStats??(()=>{}),this.onReady=t.onReady??(()=>{}),this.onPick=t.onPick??(()=>{}),this.onError=t.onError??(e=>console.warn(`[s3m]`,e));let{id:n,projection:r,nearPlaneScale:i,...a}=t;this.viewer=new xw({...a,onRequestRepaint:()=>this.requestRepaint(),getBearing:()=>this.getBearing(),onStats:e=>this.onStats(e),onReady:e=>this.onReady(e),onPick:e=>this.onPick(e),onError:e=>this.onError(e)})}getBearing(){return 0}mountViewer(e,t){this.viewer.renderer?this.viewer.restoreContext(t):this.viewer.mount(e,t)}unmountViewer(){this.viewer.unmount()}driveFrame(e){let t=this.viewer.renderFrame(e);return t&&this.requestRepaint(),t}setProjection(e,t){let n=e===`orthographic`?`orthographic`:`perspective`,r=+(n===`orthographic`),i=t?.duration??0,a=i>0||!!t?.spring;this._projection=n,this._orthoWarned=!1,a?(this._ensureProjectionChannel(),this.viewer.animator.to(`projection.t`,r,{...t,duration:i,easing:t?.easing??`easeInOutCubic`,onComplete:()=>{this._projectionT=r,this.requestRepaint()}}),this.requestRepaint()):(this.viewer.animator.has(`projection.t`)&&this.viewer.animator.cancel(`projection.t`),this._projectionT=r,this.requestRepaint())}get projection(){return this._projection}get projectionT(){return this._projectionT}_ensureProjectionChannel(){this.viewer.animator.has(`projection.t`)||this.viewer.animator.register(`projection.t`,{dim:1,read:e=>{e[0]=this._projectionT},write:e=>{this._projectionT=e[0],this.requestRepaint()}})}setNearPlaneScale(t){this._nearPlaneScale=e.normalizeNearPlaneScale(t),this.requestRepaint()}get nearPlaneScale(){return this._nearPlaneScale}static normalizeNearPlaneScale(e){return typeof e!=`number`||!Number.isFinite(e)?1:e>0&&e<1?e:1}};sh();var Cw=1e-4;function ww(e,t){let n=e.elements;for(let e=0;e<16;e++){let r=Math.max(1,Math.abs(n[e]),Math.abs(t[e]));if(Math.abs(n[e]-t[e])>Cw*r)return!1}return!0}function Tw(e){let t=e.elements,n=1;for(let e=0;e<16;e++){let r=Math.abs(t[e]);r>n&&(n=r)}let r=1e-6*n;return Math.abs(t[3])<r&&Math.abs(t[7])<r&&Math.abs(t[11])<r&&Math.abs(t[15]-1)<r}function Ew(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function Dw(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Ow(e){let t={nearZ:null,farZ:null};if(!e||typeof e!=`object`)return t;let n=e,r=n.defaultProjectionData,i=e=>{let t=n[e];if(typeof t==`number`&&Number.isFinite(t))return t;let i=r?.[e];return typeof i==`number`&&Number.isFinite(i)?i:null};return{nearZ:i(`nearZ`),farZ:i(`farZ`)}}function kw(e,t){if(e&&typeof e==`object`){let t=e.fov;if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t}return typeof t==`number`&&Number.isFinite(t)&&t>0?t:null}function Aw(e,t){let n=e.projectionMatrix;if(!n||n.length<16)return null;let r=new U().fromArray(Array.from(n)),i=new U().fromArray(Array.from(e.mvp));if(r.determinant()===0||!Ew(r,t.fov))return null;let a=r.clone().invert().multiply(i);if(!ww(r.clone().multiply(a),Array.from(e.mvp))||!Tw(a)||!Ew(r,t.fov))return null;let{distance:o,fov:s,aspect:c}=t;if(!(o>0)||!(s>0)||!(c>0))return null;let l=o*Math.tan(s/2),u=l*c,d=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,f=e.farZ!=null&&e.farZ>d?e.farZ:o*4+1e3;f>d||(f=d+1e3);let p=new Uc(-u,u,l,-l,d,f);return p.updateProjectionMatrix(),{matrix:p.projectionMatrix.clone().multiply(a),view:a}}function jw(e,t){if(!(t>0)||t>=1)return null;let n=e.projectionMatrix;if(!n||n.length<16)return null;let r=new U().fromArray(Array.from(n));if(!Number.isFinite(r.determinant())||r.determinant()===0||Math.abs(r.elements[11]+1)>1e-6)return null;let i=e.nearZ!=null&&e.nearZ>0?e.nearZ:NaN,a=e.farZ!=null&&e.farZ>i?e.farZ:NaN;if(!(i>0)||!(a>i)){let e=-r.elements[10];if(!(e>1)||(i=-r.elements[14]/(e+1),a=i*(e+1)/(e-1),!(i>0)||!(a>i)))return null}let o=i*t;if(!(o>0)||!(o<a))return null;let s=r.clone();s.elements[10]=-(a+o)/(a-o),s.elements[14]=-2*a*o/(a-o);let c=s.multiply(r.clone().invert()).multiply(new U().fromArray(Array.from(e.mvp)));for(let e=0;e<16;e++)if(!Number.isFinite(c.elements[e]))return null;return c}function Mw(e,t,n){let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new U().fromArray(Array.from(r)),a=new U().fromArray(Array.from(e.mvp));if(i.determinant()===0||!Ew(i,t.fov))return null;let o=i.clone().invert().multiply(a);if(!ww(i.clone().multiply(o),Array.from(e.mvp))||!Tw(o))return null;let s=Math.max(0,Math.min(1,n));if(s<=0)return{matrix:a,view:o};let{distance:c,fov:l,aspect:u}=t;if(!(c>0)||!(l>0)||!(u>0))return null;let d=c*Math.tan(l/2),f=d*u,p=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,m=e.farZ!=null&&e.farZ>p?e.farZ:c*4+1e3;m>p||(m=p+1e3);let h=new Uc(-f,f,d,-d,p,m);if(h.updateProjectionMatrix(),s>=1)return{matrix:h.projectionMatrix.clone().multiply(o),view:o};let g=new U,_=i.elements,v=h.projectionMatrix.elements,y=g.elements;for(let e=0;e<16;e++)y[e]=(1-s)*_[e]+s*v[e];return{matrix:g.multiply(o),view:o}}var Nw=o({Animator:()=>dw,AttributeQuery:()=>j_,BinaryReader:()=>hh,DEFAULT_FLOOR_HEIGHT:()=>C_,DEFAULT_LIGHT_PRESET:()=>yS,DEFAULT_STYLE:()=>Nb,DatasetManager:()=>fw,EARTH_RADIUS:()=>M_,EASING_NAMES:()=>WC,FeatureStyleManager:()=>fC,GPUPathManager:()=>gb,GpuEdgePass:()=>eC,GroundManager:()=>pw,HostRenderer:()=>Sw,LIGHT_PRESETS:()=>xS,Path:()=>pb,Picker:()=>NC,PixelFormat:()=>my,S3MFormatError:()=>p_,S3MTileset:()=>vS,S3MViewer:()=>xw,S3M_VERSION:()=>Fg,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>Ab,SELECT_MODE_LABELS:()=>jb,STYLE:()=>Ob,STYLE_LABELS:()=>kb,SUPERMAP_LIGHT_PRESET:()=>bS,TextureCompress:()=>hy,VertexTag:()=>Ig,VertexTagV3:()=>Lg,authFetch:()=>E_,buildAttributes:()=>x_,buildBlendedMVP:()=>Mw,buildFeatureEdgeSegments:()=>YS,buildNearScaledMVP:()=>jw,buildOrthoMVP:()=>Aw,buildThickLineGeometry:()=>WS,buildTileObjects:()=>tS,createLineSharedUniforms:()=>BS,createOutlineMaterial:()=>Db,createSharedUniforms:()=>wb,createStyledMaterial:()=>Tb,createTexture:()=>ab,createThickLineMaterial:()=>US,cubicBezier:()=>tw,default:()=>xw,dxtPixelFormatOf:()=>py,easing:()=>GC,extractEulerAngles:()=>sC,extractFovRadians:()=>kw,extractNearFar:()=>Ow,extractProjectionMatrix:()=>Dw,getColorPipeline:()=>Cb,getMaterialQuality:()=>xb,isS3M1Buffer:()=>pg,lngLatFromMercator:()=>P_,lngLatFromWorld:()=>I_,measureSegments:()=>b_,mercatorFromLngLat:()=>N_,parseS3M1:()=>Pg,parseS3MB:()=>m_,planDegradations:()=>g_,resolveAuthRequest:()=>T_,resolveEdgeModes:()=>vb,resolveFeature:()=>y_,resolveLightingPreset:()=>SS,resolveRotationMatrix:()=>oC,resolveTextureKind:()=>fy,sameEdgeModes:()=>yb,setColorPipeline:()=>Sb,setMaterialQuality:()=>bb,setMaxAnisotropy:()=>Xy,setMaxTextureSize:()=>Qy,setSrgbTextureDecode:()=>nb,steps:()=>nw,worldFromLngLat:()=>F_});w_(),Qb(),_b(),cS(),fb(),vy(),mb(),sh(),w_(),vy(),fb(),mb(),_b(),Qb(),cS();var Pw=globalThis;return Pw.THREE||(Pw.THREE=l),Pw.S3M=Nw,e.Animator=dw,e.AttributeQuery=j_,e.BinaryReader=hh,e.DEFAULT_FLOOR_HEIGHT=C_,e.DEFAULT_LIGHT_PRESET=yS,e.DEFAULT_STYLE=Nb,e.DatasetManager=fw,e.EARTH_RADIUS=M_,e.EASING_NAMES=WC,e.FeatureStyleManager=fC,e.GPUPathManager=gb,e.GpuEdgePass=eC,e.GroundManager=pw,e.HostRenderer=Sw,e.LIGHT_PRESETS=xS,e.Path=pb,e.Picker=NC,e.PixelFormat=my,e.S3MFormatError=p_,e.S3MTileset=vS,e.S3MViewer=xw,e.default=xw,e.S3M_VERSION=Fg,e.SAMPLES_PER_PATH=hb,e.SELECT_MODE=Ab,e.SELECT_MODE_LABELS=jb,e.STYLE=Ob,e.STYLE_LABELS=kb,e.SUPERMAP_LIGHT_PRESET=bS,e.TextureCompress=hy,e.VertexTag=Ig,e.VertexTagV3=Lg,e.authFetch=E_,e.buildAttributes=x_,e.buildBlendedMVP=Mw,e.buildFeatureEdgeSegments=YS,e.buildNearScaledMVP=jw,e.buildOrthoMVP=Aw,e.buildThickLineGeometry=WS,e.buildTileObjects=tS,e.createLineSharedUniforms=BS,e.createOutlineMaterial=Db,e.createSharedUniforms=wb,e.createStyledMaterial=Tb,e.createTexture=ab,e.createThickLineMaterial=US,e.cubicBezier=tw,e.dxtPixelFormatOf=py,e.easing=GC,e.extractEulerAngles=sC,e.extractFovRadians=kw,e.extractNearFar=Ow,e.extractProjectionMatrix=Dw,e.getColorPipeline=Cb,e.getMaterialQuality=xb,e.isS3M1Buffer=pg,e.lngLatFromMercator=P_,e.lngLatFromWorld=I_,e.measureSegments=b_,e.mercatorFromLngLat=N_,e.parseS3M1=Pg,e.parseS3MB=m_,e.planDegradations=g_,e.resolveAuthRequest=T_,e.resolveEdgeModes=vb,e.resolveFeature=y_,e.resolveLightingPreset=SS,e.resolveRotationMatrix=oC,e.resolveTextureKind=fy,e.sameEdgeModes=yb,e.setColorPipeline=Sb,e.setMaterialQuality=bb,e.setMaxAnisotropy=Xy,e.setMaxTextureSize=Qy,e.setSrgbTextureDecode=nb,e.steps=nw,e.worldFromLngLat=F_,e})({});
5229
+ `}),i=new hc(e,r);i.position.set(0,0,-.02),i.renderOrder=-1e3,i.name=`s3m-ground-depth`,i.visible=!1,this.group.add(i),this._depthMesh=i,this._depthMaterial=r,this._syncUniforms()}_applyMode(){this._mesh&&(this._mesh.visible=this.mode!==`none`),this._material&&(this._material.uniforms.uMode.value=this.mode===`excavate`?2:+(this.mode===`translucent`),this._material.depthWrite=this.mode===`excavate`),this._depthMesh&&(this._depthMesh.visible=this.occlude,this._depthMaterial&&(this._depthMaterial.uniforms.uPunchPit.value=+(this.mode===`excavate`)))}update(e){e&&this.group.position.set(e.position.x,e.position.y,this.groundHeight)}setGroundHeight(e){this.groundHeight=e,this.group.position.z=e}setMode(e){this.mode=e,this._occludeExplicit||(this.occlude=e===`excavate`),this._applyMode()}setOcclude(e){this.occlude=e,this._occludeExplicit=!0,this._applyMode()}setOpacity(e){this.opacity=Math.max(0,Math.min(1,e)),this._material&&(this._material.uniforms.uOpacity.value=this.opacity)}setColors(e,t){this.color.set(e),t&&this.gridColor.set(t),this._material&&(this._material.uniforms.uColor.value=this.color,this._material.uniforms.uGridColor.value=this.gridColor)}setExcavationBounds(e){this.excavationBounds=e,this._syncUniforms()}autoFitExcavation(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e){let e=o.tileset?.config,s=e?.rootTiles??e?.tiles;if(Array.isArray(s))for(let e of s){let s=e.boundingBox;if(!s)continue;let c=s.center??{x:0,y:0},l=s.xExtent?.x?Math.abs(s.xExtent.x):50,u=s.yExtent?.y?Math.abs(s.yExtent.y):50,d=c.x+o.offset[0]-l,f=c.x+o.offset[0]+l,p=c.y+o.offset[1]-u,m=c.y+o.offset[1]+u;d<t&&(t=d),f>r&&(r=f),p<n&&(n=p),m>i&&(i=m),a=!0}}a&&Number.isFinite(t)&&this.setExcavationBounds([t-5,n-5,r+5,i+5])}_syncUniforms(){let e=this.excavationBounds;if(this._material){let t=this._material.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}if(this._depthMaterial){let t=this._depthMaterial.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}}dispose(){this._geom?.dispose(),this._geom=null,this._material?.dispose(),this._material=null,this._depthMaterial?.dispose(),this._depthMaterial=null,this._mesh=null,this._depthMesh=null,this.group.clear()}};sh(),fb(),Qb(),mb(),_b(),mh();function gw(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function _w(e){return e.isPoints===!0}function vw(e){let t=e??1;return t<0?0:t>1?1:t}var yw=.001,bw=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`metalness`,`roughness`,`edgeWidth`,`edgeOpacity`,`edgeOffset`,`edgeHullWidth`,`outlineWidth`],xw=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],Sw=[`translation`,`elevation`,`opacity`,`color`,`rotation`],Cw=class{get datasets(){return this._datasetManager.datasets}get sceneAnchor(){return this._datasetManager.sceneAnchor}set sceneAnchor(e){this._datasetManager.sceneAnchor=e}_requestRepaint(){this._onRequestRepaint()}triggerRepaint(){this._requestRepaint()}constructor(e={}){X(this,`options`,void 0),X(this,`pickable`,void 0),X(this,`onStats`,void 0),X(this,`onReady`,void 0),X(this,`onPick`,void 0),X(this,`onError`,void 0),X(this,`geo`,null),X(this,`canvas`,null),X(this,`renderer`,null),X(this,`scene`,null),X(this,`camera`,null),X(this,`picker`,null),X(this,`uniforms`,void 0),X(this,`style`,void 0),X(this,`_styleTarget`,void 0),X(this,`outlineMaterial`,void 0),X(this,`lineShared`,void 0),X(this,`edgeMaterial`,void 0),X(this,`selectionEdgeMaterial`,void 0),X(this,`_edges`,void 0),X(this,`groundManager`,void 0),X(this,`_datasetManager`,new mw),X(this,`_featureStyleManager`,void 0),X(this,`gpuPathManager`,new gb),X(this,`_customPathTime`,!1),X(this,`_picks`,void 0),X(this,`_smidMeshes`,new Map),X(this,`_heights`,void 0),X(this,`_sel`,void 0),X(this,`_tileFadeSeq`,0),X(this,`_modeGen`,0),X(this,`_shadingPrewarmed`,!1),X(this,`_prewarmShadingEnabled`,!0),X(this,`_prewarming`,!1),X(this,`_pathSpecs`,new Map),X(this,`_pathScratch`,new Float32Array(3)),X(this,`_pathScratch2`,new Float32Array(3)),X(this,`_pointClouds`,new Set),X(this,`_splats`,new VS),X(this,`_opacityTransparent`,!1),X(this,`animator`,new pw),X(this,`attributeQuery`,null),X(this,`_enuMatrix`,new U),X(this,`_frameMvp`,new U),X(this,`_colorScratch`,new W),X(this,`_frame`,0),X(this,`_fps`,{value:0,last:0}),X(this,`_lights`,void 0),X(this,`_datasetQueue`,void 0),X(this,`_onRequestRepaint`,()=>{}),X(this,`_getBearing`,void 0),X(this,`_authenticate`,void 0),X(this,`_lodRangeScale`,1),X(this,`_unsupported`,void 0),X(this,`_lodPixelRatioCap`,1/0),this.options=e,this.pickable=e.pickable!==!1,this._lodRangeScale=e.lodRangeScale??1,this._unsupported=e.unsupported??`warn`,this._lodPixelRatioCap=e.lodPixelRatioCap??1/0,Qy(e.maxTextureSize??1/0),bb(e.materialQuality??`pbr`),e.totalMaxTiles&&(this._datasetManager.totalMaxTiles=e.totalMaxTiles),this._onRequestRepaint=e.onRequestRepaint??(()=>{}),this._getBearing=e.getBearing,this._authenticate=e.authenticate,this.onStats=e.onStats??(()=>{}),this.onReady=e.onReady??(()=>{}),this.onPick=e.onPick??(()=>{}),this.onError=e.onError??(e=>console.warn(`[s3m]`,e)),this._prewarmShadingEnabled=e.prewarmShading!==!1,this.groundManager=new hw(e.ground),this.scene||(this.scene=new Jl,this.scene.add(this.groundManager.group)),this._featureStyleManager=new mC(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._sel.selection&&this._sel.syncStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=wb(),this._lights=new ES({scene:()=>this.scene,renderer:()=>this.renderer,uniforms:this.uniforms,options:this.options,getBearing:()=>this._getBearing?.(),repaint:()=>this.triggerRepaint()}),this._lights.addToScene(),this._heights=new DS(this.uniforms);let t=this;this._picks=new gC({get picker(){return t.picker},get camera(){return t.camera},get scene(){return t.scene},get canvas(){return t.canvas},get style(){return t.style},get sceneAnchor(){return t.sceneAnchor},get datasets(){return t.datasets},get featureStyleManager(){return t._featureStyleManager},get smidMeshes(){return t._smidMeshes},lngLatFromWorld:(e,n)=>t._lngLatFromWorld(e,n),gpuPathPoseAt:e=>t._gpuPathPoseAt(e),isFeatureHidden:(e,n)=>t._isFeatureHidden(e,n)}),eb(q_),this.style={...Nb,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Db(this.uniforms),this._edges=new oC({uniforms:this.uniforms,style:this.style,styleTarget:this._styleTarget,animator:this.animator,pickables:this._picks.pickables,scene:this.scene,renderer:this.renderer,camera:this.camera,authenticate:this._authenticate,requestRepaint:()=>this.triggerRepaint()}),this.lineShared=this._edges.lineShared,this.edgeMaterial=this._edges.edgeMaterial,this.selectionEdgeMaterial=this._edges.selectionEdgeMaterial,this._sel=new bC({uniforms:this.uniforms,style:this.style,outlineMaterial:this.outlineMaterial,selectionEdgeMaterial:this.selectionEdgeMaterial,featureStyleManager:this._featureStyleManager,smidMeshes:this._smidMeshes,pointClouds:this._pointClouds,applyPointCloudStyle:(e,t)=>this._applyPointCloudStyle(e,t),onPick:e=>this.onPick(e),requestRepaint:()=>this.triggerRepaint(),createSelectionEdgeMaterial:e=>this._edges.createSelectionEdgeMaterial(e)}),this.setEdges(this.style.edges),this._applyOpacity(),this._fps.last=performance.now(),this._datasetQueue=this._normalizeDatasets(e),e.attributes&&(this.attributeQuery=new j_({...e.attributes,authenticate:e.attributes.authenticate??this._authenticate}))}_createRenderer(e,t){let n=new Gl({canvas:e,context:t,antialias:!0});return n.autoClear=!1,n.setPixelRatio(1),n.toneMapping=this.options.toneMapping===void 0?0:this.options.toneMapping,n.toneMappingExposure=this.options.toneMappingExposure??1,n}_syncTextureCapabilities(e){let t=!!e.getExtension(`WEBGL_compressed_texture_s3tc`),n=!!e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`);$y(t&&n)}mount(e,t){this.canvas=e,this.renderer=this._createRenderer(e,t),Xy(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(t),this.scene=new Jl,this.scene.add(this.groundManager.group),this._addLights(),this.camera=new xc,this.camera.matrixAutoUpdate=!1,this.picker=new FC(this.renderer),this._applyStyleUniforms();for(let e of this._datasetQueue)this.addDataset(e).catch(e=>this.onError(e));this._recomputeAnchors()}restoreContext(e){if(!this.canvas)console.warn(`[s3m] restoreContext 调用过早(尚未 mount),按首次挂载处理`);else{try{this.renderer?.dispose?.()}catch{}this.renderer=this._createRenderer(this.canvas,e),Xy(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new FC(this.renderer),this._edges.disposeGpuEdge(),this._requestRepaint()}}unmount(){for(let e of[...this.datasets.keys()])this.removeDataset(e);this.clearCreases(),this.groundManager.dispose(),this.picker?.dispose(),this.picker=null,this._lights.dispose(),this.outlineMaterial.dispose(),this._edges.disposeGpuEdge(),this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose(),this.scene?.clear(),this._sel.reset(),this._smidMeshes.clear(),this._heights.clear(),this.animator.clear(),this.animator.unregisterPrefix(`tile.`),this.animator.unregisterPrefix(`feature.`),this._pathSpecs.clear(),this.renderer?.dispose?.(),this.renderer=null,this.canvas=null}get _ambientLight(){return this._lights.ambient}get _hemiLight(){return this._lights.hemi}get _keyLight(){return this._lights.key}get _fillLight(){return this._lights.fill}_updateLights(){this._lights.update()}_addLights(){this._lights.addToScene()}setLightingPreset(e){this._lights.setLightingPreset(e)}setLight(e){this._lights.setLight(e)}getLight(){return this._lights.getLight()}setToneMapping(e,t=1){this._lights.setToneMapping(e,t)}getToneMapping(){return this._lights.getToneMapping()}setEnvironment(e,t=1){return this._lights.setEnvironment(e,t)}_normalizeDatasets(e){return Array.isArray(e.datasets)?e.datasets.filter(e=>!!e?.configUrl).map(t=>({...t,polygonOffset:t.polygonOffset??e.polygonOffset})):e.configUrl?[{id:`default`,name:`默认数据集`,configUrl:e.configUrl,useWorker:e.useWorker,polygonOffset:e.polygonOffset}]:[]}async addDataset(e){if(!this.scene)throw Error(`[s3m] 图层尚未 addLayer,不能添加数据集`);let t={...e,unsupported:e.unsupported??this._unsupported};return await this._datasetManager.addDataset(t,this.scene,this.geo,this.uniforms,this._lodRangeScale,this.options.buildTile,this.options.maxTiles??64,this.options.maxConcurrent??4,{onTile:(e,t)=>{this._registerTile(e,t),this.onStats(this.stats),this._requestRepaint()},onTileRemoved:(e,t)=>{this._unregisterTile(e,t),this.onStats(this.stats),this._requestRepaint()},onStats:()=>{this.onStats(this.stats),this._requestRepaint()},onError:e=>{this.onError(e),this.onStats(this.stats)},onReady:e=>{this.onReady(e),this._heights.refreshAll(),this.groundManager.excavationBounds||this.groundManager.autoFitExcavation(this.datasets.values())},triggerRepaint:()=>{this._requestRepaint()}},this.options.maxTriangles??1/0,this.options.maxImageCache??128,this._authenticate,this.options.maxMemory??1/0)}_lngLatFromWorld(e,t){return I_(this.geo,e,t)}recomputeAnchors(){this._datasetManager.recomputeAnchors(this.geo),this._heights.refreshAll(),this._requestRepaint()}_recomputeAnchors(){this.recomputeAnchors()}getDatasetHeight(e){return this._datasetManager.getDatasetHeight(e)}setDatasetHeight(e,t){let n,r;typeof e==`number`?(n=this.datasets.keys().next().value??``,r=e):(n=e,r=t??0),this._datasetManager.setDatasetHeight(n,r,this.geo),this._syncGroundHeight(),this._heights.refreshAll(),this._requestRepaint()}_syncGroundHeight(){if(!this.groundManager.trackHeight)return;let e=this.datasets.keys().next().value;if(!e)return;let t=this._datasetManager.getDatasetHeight(e);this.groundManager.setGroundHeight(t)}setDatasetAlign(e,t){let n,r;t===void 0&&(e===`origin`||e===`bottom`||e===`top`||e===`center`)?(n=this.datasets.keys().next().value??``,r=e):(n=e,r=t??`origin`),this._datasetManager.setDatasetAlign(n,r,this.geo),this._heights.refreshAll(),this._requestRepaint()}_computeAlignOffset(e,t){return this._datasetManager.computeAlignOffset(e,t)}computeAlignOffset(e,t){return this._datasetManager.computeAlignOffset(e,t)}setFeatureStyle(e,t){this._featureStyleManager.setFeatureStyle(e,t,this._meshesOf([e]))}setFeaturesStyle(e,t){this._featureStyleManager.setFeaturesStyle(e,t,this._meshesOf(e))}moveFeature(e,t,n){let r=this._ensureFeatureChannel(e,`translation`);this.animator.to(r,t,n)}moveFeatureBy(e,t,n){let r=this._featureStyleManager.getFeatureStyle(e)?.translation??[0,0,0];this.moveFeature(e,[r[0]+t[0],r[1]+t[1],r[2]+t[2]],n)}rotateFeature(e,t,n,r){let i=this._featureStyleManager.getFeatureStyle(e)??{};n&&this._featureStyleManager.setFeatureStyle(e,{...i,pivot:n},this._meshesOf([e]));let a=lC(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=lC(this._featureStyleManager.getFeatureStyle(e)?.rotation),a=typeof t==`number`?[0,0,t]:t;this.rotateFeature(e,[i[0]+a[0],i[1]+a[1],i[2]+a[2]],n,r)}crossFadeStyles(e,t){let n=e instanceof Map?e:new Map(Object.entries(e).map(([e,t])=>[Number(e),t])),r=this.getAllMeshes();this._featureStyleManager.prepareCrossFade(n,r);let i=`batch.mix`;this.animator.has(i)||this.animator.register(i,{dim:1,read:e=>{e[0]=this.uniforms.uBatchMix?.value??0},write:e=>{this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=e[0]),this.triggerRepaint()}}),(t?.duration??0)>0||t?.spring?(this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=0),this.animator.to(i,1,{...t,onComplete:()=>{this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=0),this._featureStyleManager.commitCrossFade(n,r),this.triggerRepaint(),t?.onComplete?.()}})):(this.animator.has(i)&&this.animator.cancel(i),this.uniforms.uBatchMix&&(this.uniforms.uBatchMix.value=0),this._featureStyleManager.commitCrossFade(n,r),this.triggerRepaint(),t?.onComplete?.())}followPath(e,t,n={}){let r=t instanceof pb?t:new pb(t,{closed:n.closed});if(r.length<=0)return;let i=n.offset??[0,0,0],a=n.duration??(n.speed&&n.speed>0?r.length/n.speed*1e3:2e3),o=`feature.${e}.path`;this._pathSpecs.set(o,{path:r,offset:i}),this.animator.has(o)||this.animator.register(o,{dim:1,read:e=>{e[0]=0},write:t=>{let n=this._pathSpecs.get(o);if(!n)return;n.path.sampleAt(t[0],this._pathScratch);let r=this._meshesOf([e]),i=this._featureStyleManager.getFeatureStyle(e)??{};this._featureStyleManager.setFeatureStyle(e,{...i,translation:[n.offset[0]+this._pathScratch[0],n.offset[1]+this._pathScratch[1],n.offset[2]+this._pathScratch[2]]},r);for(let e of r)e.frustumCulled=!1}});let s=()=>{this.animator.to(o,1,{duration:a,easing:n.easing??`linear`,onComplete:()=>{n.loop?s():n.onComplete?.()}})};s()}stopPath(e){let t=`feature.${e}.path`;this.animator.cancel(t),this.animator.unregister(t),this._pathSpecs.delete(t)}_gpuPathPoseAt(e){let t=this._featureStyleManager.getFeatureStyle(e)?.gpuPath;if(!t)return null;let n=this.gpuPathManager.getPath(t.pathId);if(!n||n.length<=0)return null;let r=this.uniforms.uPathTime?.value??0,i=(t.phase??0)+r*(t.speed??0),a=t.loop;a===`clamp`||a===!1?i=Math.min(1,Math.max(0,i)):a===`pingpong`?(i%=2,i<0&&(i+=2),i=i>1?2-i:i):i-=Math.floor(i),n.sampleAt(i,this._pathScratch);let o=[this._pathScratch[0],this._pathScratch[1],this._pathScratch[2]],s=0;if(t.autoHeading!==!1){let e=.001;n.sampleAt(Math.min(1,i+e),this._pathScratch2);let t=this._pathScratch2[0]-o[0],r=this._pathScratch2[1]-o[1];t*t+r*r<1e-8&&(n.sampleAt(Math.max(0,i-e),this._pathScratch2),t=o[0]-this._pathScratch2[0],r=o[1]-this._pathScratch2[1]),t*t+r*r>=1e-8&&(s=Math.atan2(r,t))}return{pos:o,yaw:s}}registerGPUPath(e,t={}){let n=this.gpuPathManager.registerPath(e,t);return this.gpuPathManager.updateUniforms(this.uniforms),n}unregisterGPUPath(e){let t=this.gpuPathManager.unregisterPath(e);return this.gpuPathManager.updateUniforms(this.uniforms),t}getGPUPathManager(){return this.gpuPathManager}bindGPUPath(e,t,n={}){let r;r=typeof t==`number`?t:this.registerGPUPath(t);let i=this._meshesOf([e]);this._featureStyleManager.bindGPUPath(e,r,n,i);for(let e of i)e.frustumCulled=!1;return this.gpuPathManager.updateUniforms(this.uniforms),r}unbindGPUPath(e){let t=this._meshesOf([e]);this._featureStyleManager.unbindGPUPath(e,t),this.gpuPathManager.updateUniforms(this.uniforms)}setGPUPathProgress(e,t){let n=this._meshesOf([e]);this._featureStyleManager.setGPUPathProgress(e,t,n);for(let e of n)e.frustumCulled=!1}setGPUPathTime(e,t=!1){this.uniforms.uPathTime&&(this.uniforms.uPathTime.value=e),this._customPathTime=!t}getGPUPathTime(){return this.uniforms.uPathTime?.value??0}animateFeature(e,t,n){if(t.translation&&this.moveFeature(e,t.translation,n),t.rotation!=null&&this.rotateFeature(e,t.rotation,t.pivot,n),t.elevation!=null&&this.animator.to(this._ensureFeatureChannel(e,`elevation`),t.elevation,n),t.opacity!=null&&this.animator.to(this._ensureFeatureChannel(e,`opacity`),t.opacity,n),t.color&&(this._colorScratch.set(t.color),this.animator.to(this._ensureFeatureChannel(e,`color`),[this._colorScratch.r,this._colorScratch.g,this._colorScratch.b],n)),t.hidden!=null){let n=this._featureStyleManager.getFeatureStyle(e)??{};this.setFeatureStyle(e,{...n,hidden:t.hidden})}}animateFeatures(e,t,n){let r=n?.stagger??0;if(r<=0){for(let r of e)this.animateFeature(r,t,n);return}let i=n?.delay??0;for(let a=0;a<e.length;a++)this.animateFeature(e[a],t,{...n,delay:i+a*r})}setMode(e,t={}){let n=Math.max(0,t.duration??300),r=Math.min(1,Math.max(.05,t.dim??.35));if(this.style.mode===e)return Promise.resolve();if(n<=0)return this.setStyle({mode:e}),Promise.resolve();let i=++this._modeGen;return new Promise(t=>{this.animator.to(`style.fade`,r,{duration:n,easing:`easeInOutQuad`,onComplete:()=>{i===this._modeGen?(this.setStyle({mode:e}),this.animator.to(`style.fade`,1,{duration:n,easing:`easeInOutQuad`,onComplete:t})):t()}})})}_ensureFeatureChannel(e,t){let n=`feature.${e}.${t}`;if(this.animator.has(n))return n;let r=t===`translation`||t===`color`||t===`rotation`?{dim:3,read:n=>{if(t===`translation`){let t=this._featureStyleManager.getFeatureStyle(e)?.translation;n[0]=t?.[0]??0,n[1]=t?.[1]??0,n[2]=t?.[2]??0}else if(t===`rotation`){let t=this._featureStyleManager.getFeatureStyle(e)?.rotation,r=lC(t);n[0]=r[0],n[1]=r[1],n[2]=r[2]}else{let t=this._featureStyleManager.getFeatureStyle(e)?.color??this.style.colorA;this._colorScratch.set(t),n[0]=this._colorScratch.r,n[1]=this._colorScratch.g,n[2]=this._colorScratch.b}},write:n=>{let r=this._meshesOf([e]),i=this._featureStyleManager.getFeatureStyle(e)??{};if(t===`translation`){this._featureStyleManager.setFeatureStyle(e,{...i,translation:[n[0],n[1],n[2]]},r);let t=Math.abs(n[0])>1e-6||Math.abs(n[1])>1e-6||Math.abs(n[2])>1e-6,a=lC(i.rotation),o=Math.abs(a[0])>1e-6||Math.abs(a[1])>1e-6||Math.abs(a[2])>1e-6;for(let e of r)e.frustumCulled=!(t||o)}else if(t===`rotation`){this._featureStyleManager.setFeatureStyle(e,{...i,rotation:[n[0],n[1],n[2]]},r);let t=Math.abs(n[0])>1e-6||Math.abs(n[1])>1e-6||Math.abs(n[2])>1e-6,a=i.translation??[0,0,0],o=Math.abs(a[0])>1e-6||Math.abs(a[1])>1e-6||Math.abs(a[2])>1e-6;for(let e of r)e.frustumCulled=!(t||o)}else{let t=this._colorScratch.setRGB(n[0],n[1],n[2]);this._featureStyleManager.setFeatureStyle(e,{...i,color:`#${t.getHexString()}`},r)}}}:{dim:1,read:n=>{let r=this._featureStyleManager.getFeatureStyle(e);n[0]=(t===`elevation`?r?.elevation:r?.opacity)??+(t===`opacity`)},write:n=>{let r=this._featureStyleManager.getFeatureStyle(e)??{},i=t===`elevation`?{...r,elevation:n[0]}:{...r,opacity:n[0]};this._featureStyleManager.setFeatureStyle(e,i,this._meshesOf([e]))}};return this.animator.register(n,r),n}_releaseFeatureChannels(e){for(let t of Sw)this.animator.unregister(`feature.${e}.${t}`);let t=`feature.${e}.path`;this.animator.unregister(t),this._pathSpecs.delete(t)}getFeatureStyle(e){return this._featureStyleManager.getFeatureStyle(e)}getFeatureStyles(){return this._featureStyleManager.getFeatureStyles()}removeFeatureStyle(e){this._releaseFeatureChannels(e),this._featureStyleManager.removeFeatureStyle(e,this._meshesOf([e]))}clearFeatureStyles(){for(let e of this._featureStyleManager.getFeatureStyles().keys())this._releaseFeatureChannels(e);this._featureStyleManager.clearFeatureStyles()}setAttributeSource(e){this.attributeQuery=e?new j_({...e,authenticate:e.authenticate??this._authenticate}):null}getLoadedSmids(){return[...this._smidMeshes.keys()]}auditBatches(){let e=this._featureStyleManager.auditBatches(this._picks.pickables.values());return e.smids=this._smidMeshes.size,e}getThematicField(){return this._featureStyleManager.thematicField}setThematicColors(e,t=`custom`){this._featureStyleManager.setThematicColors(e,t)}clearThematic(){this._featureStyleManager.clearThematicColors()}getFilterField(){return this._featureStyleManager.fieldFilter?.field??null}filterByField(e){return this._featureStyleManager.filterByField(e,this.attributeQuery,this.getLoadedSmids())}clearFieldFilter(){this._featureStyleManager.clearFieldFilter()}getElevationField(){return this._featureStyleManager.elevationField}elevateByField(e){return this._featureStyleManager.elevateByField(e,this.attributeQuery,this.getLoadedSmids())}setThematicElevation(e,t=`custom`){this._featureStyleManager.setThematicElevation(e,t)}clearThematicElevation(){this._featureStyleManager.clearThematicElevation()}colorByField(e){return this._featureStyleManager.colorByField(e,this.attributeQuery,this.getLoadedSmids())}setFilter(e){this._featureStyleManager.setFilter(e,this.uniforms)}getFilter(){return this._featureStyleManager.filter}clearFilter(){this._featureStyleManager.clearFilter(this.uniforms)}setGroundMode(e){this.groundManager.setMode(e),this._requestRepaint()}setGroundOpacity(e){this.groundManager.setOpacity(e),this._requestRepaint()}setExcavationBounds(e){this.groundManager.setExcavationBounds(e),this._requestRepaint()}setGroundOcclude(e){this.groundManager.setOcclude(e),this._requestRepaint()}_isFeatureHidden(e,t){if(e==null)return!1;let n=this._featureStyleManager.fieldFilter;if(n){let t=n.matched.has(e);if(n.mode===`keep`?!t:t)return!0}let r=this._featureStyleManager.filter;return!!(r&&(r.include&&r.include.length>0&&!r.include.includes(e)||r.exclude&&r.exclude.length>0&&r.exclude.includes(e))||this._featureStyleManager.featureStyles.get(e)?.hidden)}getAllMeshes(){let e=[];for(let t of this._picks.pickables.values())e.push(t.mesh);return e}_meshesOf(e){let t=new Set;for(let n of e){let e=this._smidMeshes.get(n);if(e)for(let n of e)t.add(n)}return t}flushOverrides(){this._featureStyleManager.flushOverrides()}_applyOverridesToMesh(e){this._featureStyleManager.applyOverridesToMesh(e)}removeDataset(e){if(this.datasets.get(e)){this._sel.selection?.datasetId===e&&this.select(null),this._datasetManager.removeDataset(e,this.scene,this.geo,e=>{e.root.traverse(e=>{let t=e,n=t.userData;n.pickId!=null&&(this._picks.pickables.delete(n.pickId),this._releasePickId(n.pickId),n.pickId=void 0),this._unindexMeshSmids(t),this._heights.remove(t),t.geometry?.dispose?.();let r=gw(t);r&&r.dispose(),OC(t.material)&&t.material.dispose(),this._featureStyleManager.disposeMesh(t)})});for(let[t,n]of this._picks.pickables)n.datasetId===e&&this._picks.pickables.delete(t);this.onStats(this.stats),this._requestRepaint()}}clearDatasets(){for(let e of[...this.datasets.keys()])this.removeDataset(e)}setDatasetVisible(e,t){this._datasetManager.setDatasetVisible(e,t),!t&&this._sel.selection?.datasetId===e&&this.select(null),this._requestRepaint()}_registerTile(e,t){t.root.add(e.group),e.group.updateMatrixWorld(!0);let n=e.group.userData.hasNativeEdges===!0,r=this._edges.useNativeEdges(n);for(let i of e.group.children){if(i.isLineSegments&&i.userData.isEdgeLines){this._edges.registerNativeLine(i,r&&this._edges.enabled);continue}let a=_w(i),o=i;if(!o.isMesh&&!a)continue;a&&this._pointClouds.add(i),a&&this._splats.markDirty();let s=o.userData;if(s.pickId=this._allocPickId(),s.datasetId=t.id,s.nativeEdges=r,s.nativeEdgesRaw=n,this._picks.pickables.set(s.pickId,{datasetId:t.id,mesh:o,tile:e.tile,skeletonName:s.skeletonName??``}),this._indexMeshSmids(o),this._heights.add(o),this._edges.autoDecorate(o,t,r),a)this._applyPointCloudStyle(i);else{let e=gw(o);if(e){let t=vw(this.style.opacity),n=this.style.depthWrite!==!1;Eb(e,t<.999,n),e.userData.uFlatShading&&(e.userData.uFlatShading.value=this.style.shading===`smooth`?0:1),this._featureStyleManager.applyOverridesToMesh(o),this._startTileFade(o,e)}}this._sel.replayOnto(o)}}_startTileFade(e,t){let n=this.style.fadeIn??0;if(n<=0)return;let r=t.userData.uTileFade;if(!r)return;r.value=0,t.transparent=!0,t.depthWrite=!0;let i=`tile.${this._tileFadeSeq++}.fade`;e.userData.tileFadeKey=i,this.animator.register(i,{dim:1,read:e=>{e[0]=r.value},write:e=>{r.value=e[0]}}),this.animator.to(i,1,{duration:n,easing:`easeOutQuad`,onComplete:()=>{r.value=1,e.userData.tileFadeKey=void 0,this.animator.unregister(i),Eb(t,this._opacityTransparent,this.style.depthWrite!==!1),this._featureStyleManager.applyOverridesToMesh(e),this._requestRepaint()}})}_replaySelectionOnto(e){this._sel.replayOnto(e)}_unregisterTile(e,t){e.group.traverse(e=>{let t=e;if(e.isLineSegments&&t.userData?.isEdgeLines&&this._edges.unregisterNativeLine(e),_w(e)&&this._pointClouds.delete(e),t.userData?.tileFadeKey&&(this.animator.unregister(t.userData.tileFadeKey),t.userData.tileFadeKey=void 0),t.userData?.pickId!=null&&(this._picks.pickables.delete(t.userData.pickId),this._releasePickId(t.userData.pickId),t.userData.pickId=void 0),t.isMesh){this._sel.selectedMeshes.includes(t)&&(this._sel.selectedMeshes=this._sel.selectedMeshes.filter(e=>e!==t));let e=this._sel.selection;if(e&&e.mesh===t){let n=e.smid,r=n==null?this._sel.selectedMeshes.find(e=>e!==t&&e.parent&&e.parent.visible)??this._sel.selectedMeshes.find(e=>e!==t&&e.parent):[...this._smidMeshes.get(n)??[]].find(e=>e!==t&&e.parent);r?(this._sel.selection={...e,mesh:r},this._sel.replayOnto(r)):this.select(null)}this._unindexMeshSmids(t),this._heights.remove(t),this._featureStyleManager.disposeMesh(t),gw(t)?.dispose?.()}OC(t.material)?t.material.dispose():t.material&&(Array.isArray(t.material)?t.material.forEach(e=>e?.dispose?.()):t.material.dispose?.()),t.geometry?.dispose?.()}),t.root.remove(e.group)}setOpacity(e,t){this.setStyle({opacity:e},t)}setStyle(e={},t){Object.assign(this._styleTarget,e);let n=t?.duration??0,r=n>0||!!t?.spring,i=e;if(`edges`in e){let{edges:n,...a}=e;if(i=a,this.setEdges(n,r?t:void 0),Object.keys(i).length===0){this._requestRepaint();return}}let a=[],o={};for(let e of Object.keys(i))r&&this.animator.has(`style.${String(e)}`)?a.push(String(e)):o[e]=i[e];Object.keys(o).length>0&&(Object.assign(this.style,o),this._applyStyleEffects(o));for(let e of a)this.animator.to(`style.${e}`,this._animTargetOf(e,i),{...t,duration:n});this._requestRepaint()}getStyle(){return{...this._styleTarget,modeLabel:kb[this._styleTarget.mode]}}_animTargetOf(e,t){let n=t[e];return this._animDimOf(e)===1?Number(n):(this._colorScratch.set(String(n)),[this._colorScratch.r,this._colorScratch.g,this._colorScratch.b])}_animDimOf(e){return xw.includes(e)?3:1}_registerAnimChannels(){for(let e of bw)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of xw)this.animator.register(`style.${e}`,{dim:3,read:t=>{let n=this._uniformColorOf(e);t[0]=n.r,t[1]=n.g,t[2]=n.b},write:t=>{let n=this._uniformColorOf(e);n.setRGB(t[0],t[1],t[2]),this.style[e]=`#${n.getHexString()}`,this._onStyleChannelWrote(e)}});this.animator.register(`style.edgeFade`,{dim:1,read:e=>{e[0]=this.uniforms.uEdgeFade?.value??1},write:e=>{this.uniforms.uEdgeFade&&(this.uniforms.uEdgeFade.value=e[0]),this._edges.syncStyle()}}),this.animator.register(`style.fade`,{dim:1,read:e=>{e[0]=this.uniforms.uFade?.value??1},write:e=>{this.uniforms.uFade&&(this.uniforms.uFade.value=e[0]),this._requestRepaint()}})}_onStyleChannelWrote(e){e===`opacity`?this._applyOpacity():(this._applyStyleUniforms(),(e===`edgeColor`||e===`edgeWidth`||e===`edgeOpacity`||e===`edgeOffset`||e===`edgeHullWidth`)&&this._edges.refreshLines())}_uniformColorOf(e){let t=this.uniforms;switch(e){case`colorA`:return t.uColorA.value;case`colorB`:return t.uColorB.value;case`colorC`:return t.uColorC.value;case`selectColor`:return t.uSelColor.value;case`edgeColor`:return this.edgeMaterial.uniforms.uColor.value;default:return t.uColorA.value}}_applyStyleEffects(e){this._applyStyleUniforms(),(`opacity`in e||`depthWrite`in e)&&this._applyOpacity(),`mode`in e&&this._applyPointCloudStyles(),`shading`in e&&this._applyShading(),(`edgeThreshold`in e||`forceCpuEdges`in e)&&this._edges.enabled?(this._edges.disposeEdgeGeometry(),this.setEdges(this.style.edges)):(`edgeColor`in e||`edgeWidth`in e||`opacity`in e||`edgeOpacity`in e||`edgeOffset`in e||`edgeHullWidth`in e)&&this._edges.refreshLines(),this._sel.selection&&(`outline`in e||`outlineStyle`in e?this.select(this._sel.selection,{silent:!0}):this._sel.syncStyle())}_applyStyleUniforms(){let e=this.uniforms,t=this.style;e.uMode.value=t.mode,e.uColorA.value.set(t.colorA),e.uColorB.value.set(t.colorB),e.uColorC.value.set(t.colorC),e.uSelColor.value.set(t.selectColor),e.uFloorHeight.value=t.floorHeight;let n=t.selectMode??Ab.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===Ab.REPLACE?0:n===Ab.MULTIPLY?2:n===Ab.GLOW_ONLY?3:1),e.uSelOpacity&&t.selectOpacity!=null&&(e.uSelOpacity.value=t.selectOpacity),e.uSelEmissive&&t.selectEmissive!=null&&(e.uSelEmissive.value=t.selectEmissive),e.uSelElevation&&t.selectElevation!=null&&(e.uSelElevation.value=t.selectElevation),e.uDimFactor&&t.dimFactor!=null&&(e.uDimFactor.value=t.dimFactor),e.uRoofThreshold&&t.roofThreshold!=null&&(e.uRoofThreshold.value=t.roofThreshold),e.uTexMix&&t.texMix!=null&&(e.uTexMix.value=t.texMix),e.uAmbientGain&&t.ambientGain!=null&&(e.uAmbientGain.value=t.ambientGain),e.uMetalness&&(e.uMetalness.value=t.metalness??-1),e.uRoughness&&(e.uRoughness.value=t.roughness??-1),e.uOpacity&&t.opacity!=null&&(e.uOpacity.value=vw(t.opacity)),this.outlineMaterial&&(this.outlineMaterial.uniforms.uElevation&&t.selectElevation!=null&&(this.outlineMaterial.uniforms.uElevation.value=t.selectElevation),t.outlineWidth!=null&&(this.outlineMaterial.uniforms.uWidth.value=t.outlineWidth),t.outlineColor==null?this.outlineMaterial.uniforms.uColor.value.set(t.selectColor):this.outlineMaterial.uniforms.uColor.value.set(t.outlineColor))}_applyOpacity(){let e=vw(this.style.opacity);this.uniforms.uOpacity&&(this.uniforms.uOpacity.value=e);let t=e<.999;if(t!==this._opacityTransparent){this._opacityTransparent=t;let e=this.style.depthWrite!==!1;for(let n of this._picks.pickables.values()){if(_w(n.mesh))continue;let r=gw(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||Eb(r,t,e))}}for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._edges.syncStyle(),this._requestRepaint()}_applyPointCloudStyle(e,t=this._sel.selectedMeshes.includes(e)){DC(e,this.style,this.uniforms,t)}_applyPointCloudStyles(){for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._requestRepaint()}_applyShading(){let e=this.style.shading===`smooth`?0:1;for(let t of this._picks.pickables.values()){let n=gw(t.mesh)?.userData.uFlatShading;n&&n.value!==e&&(n.value=e)}this._requestRepaint()}setMaterialQuality(e){bb(e),this._rebuildStyledMaterials(),this._requestRepaint()}get materialQuality(){return xb()}_rebuildStyledMaterials(){let e=[`uSelBatch`,`uSelWhole`,`uBatchTex`,`uBatchTex2`,`uBatchTexWidth`,`uBatchTexActive`,`uTileFade`];for(let t of this._picks.pickables.values()){let n=t.mesh,r=n.material;if(Array.isArray(r))continue;let i=r;if(!i?.userData?.isStyled||!i.userData?.s3mOpts)continue;let a=i.userData.s3mOpts,o=Tb({...a,uniforms:this.uniforms});for(let t of e){let e=i.userData[t],n=o.userData[t];e&&n&&(n.value=e.value)}n.material=o,i.dispose()}}async prewarmShading(){if(this._shadingPrewarmed||this._prewarming)return;let e=this.renderer,t=this.scene,n=this.camera;if(!e||!t||!n)return;let r=!1;for(let e of this._picks.pickables.values())if(gw(e.mesh)){r=!0;break}if(r){this._shadingPrewarmed=!0;try{let r=e;typeof r.compileAsync==`function`?await r.compileAsync(t,n):e.compile(t,n)}catch{}this._requestRepaint()}}_addMeshHeight(e){this._heights.add(e)}_removeMeshHeight(e){this._heights.remove(e)}_indexMeshSmids(e){let t=e.userData.geoRef?.pickInfo;if(t)for(let n of Object.keys(t)){let t=Number(n);if(!Number.isFinite(t)||t<0)continue;let r=this._smidMeshes.get(t);r||this._smidMeshes.set(t,r=new Set),r.add(e)}}_unindexMeshSmids(e){let t=e.userData.geoRef?.pickInfo;if(t)for(let n of Object.keys(t)){let t=Number(n),r=this._smidMeshes.get(t);r&&(r.delete(e),r.size===0&&this._smidMeshes.delete(t))}}get _edgesEnabled(){return this._edges.enabled}get _edgeModes(){return this._edges.modes}get _gpuEdge(){return this._edges.gpuEdge}set _gpuEdge(e){this._edges.gpuEdge=e}_ensureEdges(e){this._edges.ensureEdges(e)}_removeEdges(e){this._edges.removeEdges(e)}setEdges(e,t){this._edges.setEdges(e,t)}loadCreases(e){return this._edges.loadCreases(e)}clearCreases(){this._edges.clearCreases()}getRayAt(e,t){return this._picks.getRayAt(e,t)}pick(e,t){return this._picks.pick(e,t)}pickPosition(e,t){return this._picks.pickPosition(e,t)}drillPick(e,t,n=10){return this._picks.drillPick(e,t,n)}getFeatureBounds(e){return this._picks.getFeatureBounds(e)}_intersectMeshAtRay(e,t,n){return this._picks.intersectMeshAtRay(e,t,n)}_buildPickResult(e,t,n,r){return this._picks.buildPickResult(e,t,n,r)}_buildSplatPickResult(e,t,n,r){return this._picks.buildSplatPickResult(e,t,n,r)}_instanceFeature(e,t,n){return this._picks.instanceFeature(e,t,n)}_instanceBox(e,t){return this._picks.instanceBox(e,t)}_allocPickId(){return this._picks.allocPickId()}_releasePickId(e){this._picks.releasePickId(e)}get _pickables(){return this._picks.pickables}select(e,t={}){this._sel.select(e,t)}_syncSelectionStyle(){this._sel.syncStyle()}get _selection(){return this._sel.selection}get _selectedMeshes(){return this._sel.selectedMeshes}get _selectionEdgeMeshes(){return this._sel.selectionEdgeMeshes}_updateLineResolution(e){let t=e.width||1,n=e.height||1,r=e.clientWidth||t;this.lineShared.uResolution.value.set(t,n),this.lineShared.uDpr.value=Math.max(1,t/r)}get lodRangeScale(){return this._lodRangeScale}get lodPixelRatioCap(){return this._lodPixelRatioCap}setLodPixelRatioCap(e){let t=e>0?e:1/0;this._lodPixelRatioCap=t,this.options.lodPixelRatioCap=t,this._requestRepaint()}_lodScreenHeight(e){let t=this._lodPixelRatioCap;if(!Number.isFinite(t))return e;let n=this.canvas?.clientHeight??0;return n<=0?e:Math.min(e,n*t)}get maxImageCache(){return this.options.maxImageCache??128}setMaxImageCache(e,t){let n=Number.isFinite(e)?Math.max(1,Math.floor(e)):128;if(t){let e=this.datasets.get(t);e?.tileset&&(e.tileset.maxImageCache=n)}else{this.options.maxImageCache=n;for(let e of this.datasets.values())e.tileset&&(e.tileset.maxImageCache=n)}this._requestRepaint()}get maxTriangles(){return this.options.maxTriangles??1/0}setMaxTriangles(e,t){let n=e>0?e:1/0;if(t){let e=this.datasets.get(t);e?.tileset&&e.tileset.setMaxTriangles(n)}else{this.options.maxTriangles=n;for(let e of this.datasets.values())e.tileset&&e.tileset.setMaxTriangles(n)}}get maxMemory(){return this.options.maxMemory??1/0}setMaxMemory(e,t){let n=Number.isFinite(e)&&e>0?e:1/0;if(t){let e=this.datasets.get(t);e?.tileset&&e.tileset.setMaxMemory(n)}else{this.options.maxMemory=n;for(let e of this.datasets.values())e.tileset&&e.tileset.setMaxMemory(n)}}get anisotropyCap(){return this.options.anisotropyCap??1/0}setAnisotropyCap(e){let t=Number.isFinite(e)&&e>0?Math.max(1,e):1/0;this.options.anisotropyCap=t,Xy(this.renderer?.capabilities.getMaxAnisotropy?.()??1,t),this._requestRepaint()}get maxTextureSize(){return this.options.maxTextureSize??1/0}setMaxTextureSize(e){let t=Number.isFinite(e)&&e>=1?e:1/0;this.options.maxTextureSize=t,Qy(t),this._requestRepaint()}setLodRangeScale(e,t){if(!(e<=0)){if(t){let n=this.datasets.get(t);n?.tileset&&(n.tileset.lodRangeScale=e)}else{this._lodRangeScale=e;for(let t of this.datasets.values())t.tileset&&(t.tileset.lodRangeScale=e)}this._requestRepaint()}}_sortSplats(){this._splats.sort(this.camera,this._pointClouds)}renderFrame(e){if(!this.renderer||!this.scene||!this.camera||!this.sceneAnchor||!this.canvas)return!1;let t=this.renderer.getContext();if(t&&typeof t.isContextLost==`function`&&t.isContextLost())return!1;if(this._prewarming)return!0;let n=this.animator.tick();this.flushOverrides();let r=this.canvas,i=this.sceneAnchor.meterInMercator;this._enuMatrix.set(i,0,0,this.sceneAnchor.x,0,-i,0,this.sceneAnchor.y,0,0,i,this.sceneAnchor.z,0,0,0,1);let a=this._frameMvp.fromArray(e.mvp);a.multiply(this._enuMatrix),this.camera.projectionMatrix.copy(a),this.camera.projectionMatrixInverse.copy(a).invert();let o=e.cameraEnu;this.camera.position.set(o[0],o[1],o[2]),this.camera.matrixWorld.setPosition(o[0],o[1],o[2]),this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert(),this.groundManager.update(this.camera);let s=!1,c=this._lodScreenHeight(e.canvasHeight);for(let t of this.datasets.values()){if(!t.visible||!t.tileset)continue;let n=[o[0]-t.offset[0],o[1]-t.offset[1],o[2]-t.offset[2]];t.tileset.update(n,e.fovRad,c)&&(s=!0)}this.style.mode===Ob.DYNAMIC&&(this.uniforms.uTime.value+=.016*(this.style.speed??1)),this.gpuPathManager.updateUniforms(this.uniforms);let l=(this.uniforms.uPathTexActive?.value??0)>0;l&&!this._customPathTime&&this.uniforms.uPathTime&&(this.uniforms.uPathTime.value+=.016),this._updateLights(),this._updateLineResolution(r),Gx(r.width,r.height),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),(this.uniforms.uOpacity?.value??1)>yw&&(this._sortSplats(),this.renderer.render(this.scene,this.camera),this._edges.renderGpuEdges(r)),this._frame++;let u=performance.now();u-this._fps.last>500&&(this._fps.value=Math.round(this._frame*1e3/(u-this._fps.last)),this._frame=0,this._fps.last=u);let d=n||this.style.mode===Ob.DYNAMIC||l||this.stats.loading>0||s;return this._prewarmShadingEnabled&&!this._shadingPrewarmed&&this._picks.pickables.size>0&&this.prewarmShading(),d}get fps(){return this._fps.value}get stats(){let e={tiles:0,loading:0,failed:0,meshes:0,vertices:0,triangles:0,datasets:this.datasets.size,drawCalls:0,programs:0,textures:0,geometries:0,degradations:[]},t=null;for(let n of this.datasets.values()){let r=n.tileset?.stats;if(r&&(e.tiles+=r.tiles,e.loading+=r.loading,e.failed+=r.failed,e.meshes+=r.meshes,e.vertices+=r.vertices,e.triangles+=r.triangles,r.degradations?.length)){t??(t=[]);for(let e of r.degradations)t.includes(e)||t.push(e)}}t&&(e.degradations=t);let n=this.renderer?.info;return n&&(e.drawCalls=n.render.calls,e.programs=n.programs?.length??0,e.textures=n.memory.textures,e.geometries=n.memory.geometries),e}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of this.datasets.values()){let a=hS(i.tileset?.config?.geoBounds);a&&(e=Math.min(e,a.left),n=Math.max(n,a.right),t=Math.min(t,a.bottom),r=Math.max(r,a.top))}return isFinite(e)?[[e,t],[n,r]]:null}dispose(){this.unmount()}};mh();var ww=class e{constructor(t={}){X(this,`id`,void 0),X(this,`options`,void 0),X(this,`pickable`,void 0),X(this,`onStats`,void 0),X(this,`onReady`,void 0),X(this,`onPick`,void 0),X(this,`onError`,void 0),X(this,`viewer`,void 0),X(this,`_projection`,`perspective`),X(this,`_projectionT`,0),X(this,`_orthoWarned`,!1),X(this,`_nearPlaneScale`,1),this.id=t.id??`s3m`,this.options=t,this.pickable=t.pickable!==!1,this._projection=t.projection===`orthographic`?`orthographic`:`perspective`,this._nearPlaneScale=e.normalizeNearPlaneScale(t.nearPlaneScale),this._projectionT=+(this._projection===`orthographic`),this.onStats=t.onStats??(()=>{}),this.onReady=t.onReady??(()=>{}),this.onPick=t.onPick??(()=>{}),this.onError=t.onError??(e=>console.warn(`[s3m]`,e));let{id:n,projection:r,nearPlaneScale:i,...a}=t;this.viewer=new Cw({...a,onRequestRepaint:()=>this.requestRepaint(),getBearing:()=>this.getBearing(),onStats:e=>this.onStats(e),onReady:e=>this.onReady(e),onPick:e=>this.onPick(e),onError:e=>this.onError(e)})}getBearing(){return 0}mountViewer(e,t){this.viewer.renderer?this.viewer.restoreContext(t):this.viewer.mount(e,t)}unmountViewer(){this.viewer.unmount()}driveFrame(e){let t=this.viewer.renderFrame(e);return t&&this.requestRepaint(),t}setProjection(e,t){let n=e===`orthographic`?`orthographic`:`perspective`,r=+(n===`orthographic`),i=t?.duration??0,a=i>0||!!t?.spring;this._projection=n,this._orthoWarned=!1,a?(this._ensureProjectionChannel(),this.viewer.animator.to(`projection.t`,r,{...t,duration:i,easing:t?.easing??`easeInOutCubic`,onComplete:()=>{this._projectionT=r,this.requestRepaint()}}),this.requestRepaint()):(this.viewer.animator.has(`projection.t`)&&this.viewer.animator.cancel(`projection.t`),this._projectionT=r,this.requestRepaint())}get projection(){return this._projection}get projectionT(){return this._projectionT}_ensureProjectionChannel(){this.viewer.animator.has(`projection.t`)||this.viewer.animator.register(`projection.t`,{dim:1,read:e=>{e[0]=this._projectionT},write:e=>{this._projectionT=e[0],this.requestRepaint()}})}setNearPlaneScale(t){this._nearPlaneScale=e.normalizeNearPlaneScale(t),this.requestRepaint()}get nearPlaneScale(){return this._nearPlaneScale}static normalizeNearPlaneScale(e){return typeof e!=`number`||!Number.isFinite(e)?1:e>0&&e<1?e:1}};sh();var Tw=1e-4;function Ew(e,t){let n=e.elements;for(let e=0;e<16;e++){let r=Math.max(1,Math.abs(n[e]),Math.abs(t[e]));if(Math.abs(n[e]-t[e])>Tw*r)return!1}return!0}function Dw(e){let t=e.elements,n=1;for(let e=0;e<16;e++){let r=Math.abs(t[e]);r>n&&(n=r)}let r=1e-6*n;return Math.abs(t[3])<r&&Math.abs(t[7])<r&&Math.abs(t[11])<r&&Math.abs(t[15]-1)<r}function Ow(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function kw(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Aw(e){let t={nearZ:null,farZ:null};if(!e||typeof e!=`object`)return t;let n=e,r=n.defaultProjectionData,i=e=>{let t=n[e];if(typeof t==`number`&&Number.isFinite(t))return t;let i=r?.[e];return typeof i==`number`&&Number.isFinite(i)?i:null};return{nearZ:i(`nearZ`),farZ:i(`farZ`)}}function jw(e,t){if(e&&typeof e==`object`){let t=e.fov;if(typeof t==`number`&&Number.isFinite(t)&&t>0)return t}return typeof t==`number`&&Number.isFinite(t)&&t>0?t:null}function Mw(e,t){let n=e.projectionMatrix;if(!n||n.length<16)return null;let r=new U().fromArray(Array.from(n)),i=new U().fromArray(Array.from(e.mvp));if(r.determinant()===0||!Ow(r,t.fov))return null;let a=r.clone().invert().multiply(i);if(!Ew(r.clone().multiply(a),Array.from(e.mvp))||!Dw(a)||!Ow(r,t.fov))return null;let{distance:o,fov:s,aspect:c}=t;if(!(o>0)||!(s>0)||!(c>0))return null;let l=o*Math.tan(s/2),u=l*c,d=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,f=e.farZ!=null&&e.farZ>d?e.farZ:o*4+1e3;f>d||(f=d+1e3);let p=new Uc(-u,u,l,-l,d,f);return p.updateProjectionMatrix(),{matrix:p.projectionMatrix.clone().multiply(a),view:a}}function Nw(e,t){if(!(t>0)||t>=1)return null;let n=e.projectionMatrix;if(!n||n.length<16)return null;let r=new U().fromArray(Array.from(n));if(!Number.isFinite(r.determinant())||r.determinant()===0||Math.abs(r.elements[11]+1)>1e-6)return null;let i=e.nearZ!=null&&e.nearZ>0?e.nearZ:NaN,a=e.farZ!=null&&e.farZ>i?e.farZ:NaN;if(!(i>0)||!(a>i)){let e=-r.elements[10];if(!(e>1)||(i=-r.elements[14]/(e+1),a=i*(e+1)/(e-1),!(i>0)||!(a>i)))return null}let o=i*t;if(!(o>0)||!(o<a))return null;let s=r.clone();s.elements[10]=-(a+o)/(a-o),s.elements[14]=-2*a*o/(a-o);let c=s.multiply(r.clone().invert()).multiply(new U().fromArray(Array.from(e.mvp)));for(let e=0;e<16;e++)if(!Number.isFinite(c.elements[e]))return null;return c}function Pw(e,t,n){let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new U().fromArray(Array.from(r)),a=new U().fromArray(Array.from(e.mvp));if(i.determinant()===0||!Ow(i,t.fov))return null;let o=i.clone().invert().multiply(a);if(!Ew(i.clone().multiply(o),Array.from(e.mvp))||!Dw(o))return null;let s=Math.max(0,Math.min(1,n));if(s<=0)return{matrix:a,view:o};let{distance:c,fov:l,aspect:u}=t;if(!(c>0)||!(l>0)||!(u>0))return null;let d=c*Math.tan(l/2),f=d*u,p=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,m=e.farZ!=null&&e.farZ>p?e.farZ:c*4+1e3;m>p||(m=p+1e3);let h=new Uc(-f,f,d,-d,p,m);if(h.updateProjectionMatrix(),s>=1)return{matrix:h.projectionMatrix.clone().multiply(o),view:o};let g=new U,_=i.elements,v=h.projectionMatrix.elements,y=g.elements;for(let e=0;e<16;e++)y[e]=(1-s)*_[e]+s*v[e];return{matrix:g.multiply(o),view:o}}var Fw=o({Animator:()=>pw,AttributeQuery:()=>j_,BinaryReader:()=>hh,DEFAULT_FLOOR_HEIGHT:()=>C_,DEFAULT_LIGHT_PRESET:()=>xS,DEFAULT_STYLE:()=>Nb,DatasetManager:()=>mw,EARTH_RADIUS:()=>M_,EASING_NAMES:()=>KC,FeatureStyleManager:()=>mC,GPUPathManager:()=>gb,GpuEdgePass:()=>nC,GroundManager:()=>hw,HostRenderer:()=>ww,LIGHT_PRESETS:()=>CS,Path:()=>pb,Picker:()=>FC,PixelFormat:()=>my,S3MFormatError:()=>p_,S3MTileset:()=>bS,S3MViewer:()=>Cw,S3M_VERSION:()=>Fg,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>Ab,SELECT_MODE_LABELS:()=>jb,STYLE:()=>Ob,STYLE_LABELS:()=>kb,SUPERMAP_LIGHT_PRESET:()=>SS,TextureCompress:()=>hy,VertexTag:()=>Ig,VertexTagV3:()=>Lg,authFetch:()=>E_,buildAttributes:()=>x_,buildBlendedMVP:()=>Pw,buildFeatureEdgeSegments:()=>ZS,buildNearScaledMVP:()=>Nw,buildOrthoMVP:()=>Mw,buildThickLineGeometry:()=>KS,buildTileObjects:()=>tS,createLineSharedUniforms:()=>HS,createOutlineMaterial:()=>Db,createSharedUniforms:()=>wb,createStyledMaterial:()=>Tb,createTexture:()=>ab,createThickLineMaterial:()=>GS,cubicBezier:()=>rw,default:()=>Cw,dxtPixelFormatOf:()=>py,easing:()=>qC,extractEulerAngles:()=>lC,extractFovRadians:()=>jw,extractNearFar:()=>Aw,extractProjectionMatrix:()=>kw,getColorPipeline:()=>Cb,getMaterialQuality:()=>xb,isS3M1Buffer:()=>pg,lngLatFromMercator:()=>P_,lngLatFromWorld:()=>I_,measureSegments:()=>b_,mercatorFromLngLat:()=>N_,parseS3M1:()=>Pg,parseS3MB:()=>m_,planDegradations:()=>g_,resolveAuthRequest:()=>T_,resolveEdgeModes:()=>vb,resolveFeature:()=>y_,resolveLightingPreset:()=>wS,resolveRotationMatrix:()=>cC,resolveTextureKind:()=>fy,sameEdgeModes:()=>yb,setColorPipeline:()=>Sb,setMaterialQuality:()=>bb,setMaxAnisotropy:()=>Xy,setMaxTextureSize:()=>Qy,setSrgbTextureDecode:()=>nb,steps:()=>iw,worldFromLngLat:()=>F_});w_(),Qb(),_b(),cS(),fb(),vy(),mb(),sh(),w_(),vy(),fb(),mb(),_b(),Qb(),cS();var Iw=globalThis;return Iw.THREE||(Iw.THREE=l),Iw.S3M=Fw,e.Animator=pw,e.AttributeQuery=j_,e.BinaryReader=hh,e.DEFAULT_FLOOR_HEIGHT=C_,e.DEFAULT_LIGHT_PRESET=xS,e.DEFAULT_STYLE=Nb,e.DatasetManager=mw,e.EARTH_RADIUS=M_,e.EASING_NAMES=KC,e.FeatureStyleManager=mC,e.GPUPathManager=gb,e.GpuEdgePass=nC,e.GroundManager=hw,e.HostRenderer=ww,e.LIGHT_PRESETS=CS,e.Path=pb,e.Picker=FC,e.PixelFormat=my,e.S3MFormatError=p_,e.S3MTileset=bS,e.S3MViewer=Cw,e.default=Cw,e.S3M_VERSION=Fg,e.SAMPLES_PER_PATH=hb,e.SELECT_MODE=Ab,e.SELECT_MODE_LABELS=jb,e.STYLE=Ob,e.STYLE_LABELS=kb,e.SUPERMAP_LIGHT_PRESET=SS,e.TextureCompress=hy,e.VertexTag=Ig,e.VertexTagV3=Lg,e.authFetch=E_,e.buildAttributes=x_,e.buildBlendedMVP=Pw,e.buildFeatureEdgeSegments=ZS,e.buildNearScaledMVP=Nw,e.buildOrthoMVP=Mw,e.buildThickLineGeometry=KS,e.buildTileObjects=tS,e.createLineSharedUniforms=HS,e.createOutlineMaterial=Db,e.createSharedUniforms=wb,e.createStyledMaterial=Tb,e.createTexture=ab,e.createThickLineMaterial=GS,e.cubicBezier=rw,e.dxtPixelFormatOf=py,e.easing=qC,e.extractEulerAngles=lC,e.extractFovRadians=jw,e.extractNearFar=Aw,e.extractProjectionMatrix=kw,e.getColorPipeline=Cb,e.getMaterialQuality=xb,e.isS3M1Buffer=pg,e.lngLatFromMercator=P_,e.lngLatFromWorld=I_,e.measureSegments=b_,e.mercatorFromLngLat=N_,e.parseS3M1=Pg,e.parseS3MB=m_,e.planDegradations=g_,e.resolveAuthRequest=T_,e.resolveEdgeModes=vb,e.resolveFeature=y_,e.resolveLightingPreset=wS,e.resolveRotationMatrix=cC,e.resolveTextureKind=fy,e.sameEdgeModes=yb,e.setColorPipeline=Sb,e.setMaterialQuality=bb,e.setMaxAnisotropy=Xy,e.setMaxTextureSize=Qy,e.setSrgbTextureDecode=nb,e.steps=iw,e.worldFromLngLat=F_,e})({});