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.
- package/dist/browser/s3m-three.iife.ext-three.js +12 -12
- package/dist/browser/s3m-three.iife.js +12 -12
- package/dist/render/DatasetManager.d.ts +3 -1
- package/dist/render/DatasetManager.d.ts.map +1 -1
- package/dist/render/DatasetManager.js +2 -1
- package/dist/render/DatasetManager.js.map +1 -1
- package/dist/render/GeometryBuilder.d.ts +1 -0
- package/dist/render/GeometryBuilder.d.ts.map +1 -1
- package/dist/render/GeometryBuilder.js +23 -0
- package/dist/render/GeometryBuilder.js.map +1 -1
- package/dist/render/S3MViewer.d.ts +8 -0
- package/dist/render/S3MViewer.d.ts.map +1 -1
- package/dist/render/S3MViewer.js +25 -1
- package/dist/render/S3MViewer.js.map +1 -1
- package/dist/render/viewer/types.d.ts +6 -0
- package/dist/render/viewer/types.d.ts.map +1 -1
- package/dist/render/viewer/types.js.map +1 -1
- package/dist/tileset/S3MTileset.d.ts +30 -2
- package/dist/tileset/S3MTileset.d.ts.map +1 -1
- package/dist/tileset/S3MTileset.js +99 -4
- package/dist/tileset/S3MTileset.js.map +1 -1
- package/docs/API.md +9 -28
- package/package.json +1 -1
- package/src/render/DatasetManager.ts +5 -1
- package/src/render/GeometryBuilder.ts +21 -0
- package/src/render/S3MViewer.ts +25 -1
- package/src/render/viewer/types.ts +6 -0
- package/src/tileset/S3MTileset.ts +106 -5
|
@@ -928,7 +928,7 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
928
928
|
float o = uObjectId + 1.0;
|
|
929
929
|
gl_FragColor = vec4(mod(o, 256.0) / 255.0, floor(o / 256.0) / 255.0, 0.0, 0.0);
|
|
930
930
|
}
|
|
931
|
-
`,side:t.DoubleSide,depthTest:!0,depthWrite:!0})}function Ga(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 Ka,qa,Ja,Ya,Xa=c((()=>{nn(),Ka=new t.Vector2(1e3,1e3),qa=new t.Sphere,Ja=new t.Matrix4,Ya=new t.Ray})),Za=l({LINE_PRIMITIVE:()=>13,POINT_PRIMITIVE:()=>1,buildTileObjects:()=>fo,setSplatViewport:()=>to});function Qa(e){return e===13||e===2||e===3}function $a(e){return e===1}function eo(){return po??(po=Va()),po}function to(e,t){po&&po.uniforms.uViewport.value.set(e,t)}function no(e,n){let r=n.vertexAttributes.find(e=>e.semantic===`gsScale`),i=n.vertexAttributes.find(e=>e.semantic===`gsRotation`),a=e.attributes.position;if(!r||!i||!a)return null;let o=Math.min(n.verticesCount,Math.floor(a.array.length/a.components));if(o<=0)return null;let s=Pa(r.data,r.stride,r.offsetInBytes,o),c=Fa(i.data,i.stride,i.offsetInBytes,o),l=ro(s,o),u=Ha();u.instanceCount=o,u.setAttribute(`iCenter`,new t.InstancedBufferAttribute(a.array,3)),u.setAttribute(`iScale`,new t.InstancedBufferAttribute(s,3)),u.setAttribute(`iQuat`,new t.InstancedBufferAttribute(c,4));let d=new Float32Array(o*4);d.fill(1);let f=n.vertexAttributes.find(e=>e.semantic===`color`);if(f&&f.dtype===`u8`){let e=f.components??4,t=Math.min(o,Math.floor(f.data.length/f.stride));for(let n=0;n<t;n++){let t=n*f.stride+f.offsetInBytes;d[n*4]=f.data[t]/255,d[n*4+1]=f.data[t+1]/255,d[n*4+2]=f.data[t+2]/255,e>=4&&(d[n*4+3]=f.data[t+3]/255)}}else if(e.attributes.aColor){let t=e.attributes.aColor,n=t.components??4;for(let e=0;e<o;e++)for(let r=0;r<Math.min(n,4);r++)d[e*4+r]=t.array[e*n+r]}u.setAttribute(`iColor`,new t.InstancedBufferAttribute(d,4));let p=a.array,m=1/0,h=1/0,g=1/0,_=-1/0,v=-1/0,y=-1/0,b=0;for(let e=0;e<o;e++){let t=p[e*3],n=p[e*3+1],r=p[e*3+2];t<m&&(m=t),t>_&&(_=t),n<h&&(h=n),n>v&&(v=n),r<g&&(g=r),r>y&&(y=r);let i=s[e*3],a=s[e*3+1],o=s[e*3+2];i>b&&(b=i),a>b&&(b=a),o>b&&(b=o)}let x=new t.Box3;o>0&&(x.min.set(m,h,g),x.max.set(_,v,y));let S=new t.Sphere(new t.Vector3,0);return x.isEmpty()||x.getBoundingSphere(S),S.radius+=3*b,u.boundingSphere=S,{geo:u,sigma:l}}function ro(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 io(){return mo||(mo=new t.PointsMaterial({size:2,sizeAttenuation:!1,vertexColors:!0})),mo}function ao(e){if(!e)return[];if(Array.isArray(e))return e;let t=e,n=t.materials??t.material;return Array.isArray(n)?n:[]}function oo(e){return e?.material??e}function so(e){return e?.name??e?.id}function co(e){return(e?.textureStates??e?.textureunitstates??[]).map(e=>e?.textureunitstate??e).filter(e=>!!e)}function lo(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 uo(e){let n=String(e?.cullMode??``).toUpperCase();return n===`CULL_BACK`||n===`BACKWARD`?t.FrontSide:n===`CULL_FRONT`?t.BackSide:t.DoubleSide}async function fo(e,n={}){let r=n.uniforms??Ii(),i=n.textureCache??new Map,a=new t.Group,o=[],s=[],c={meshes:0,vertices:0,triangles:0,textures:0,instanced:0,edgeLines:0,skipped:[]},l=new t.LineBasicMaterial({color:new t.Color(n.edgeColor??`#1f2937`),transparent:!0,opacity:.75,depthWrite:!1});a.userData.hasNativeEdges=!1;let u=t=>{let n=e.textures?.[t];return n?.packKey?`${t}#${n.packKey}`:t};for(let[t,n]of Object.entries(e.textures??{})){let e=u(t),r=i.get(e);if(r){let t=r.image;if((t?.width??0)*(t?.height??0)>=(n.width??0)*(n.height??0))continue;i.delete(e)}let{texture:a,decoded:o}=await _i(n);a?(i.set(e,a),s.push(e),c.textures++):c.skipped.push(`texture ${t} → ${o}`)}let d=ao(e.materials),f=e=>d.findIndex(t=>so(oo(t))===e),p=(e,a=!1,o=!1,s=1)=>{let c=oo(d.find(t=>so(oo(t))===e)),l=co(c),f=l[0],p=f?i.get(u(so(f)??f.id??``))??null:null,m=l[1],h=globalThis.__S3M_NO_BAKE===!0,g=a&&m&&!h?i.get(u(so(m)??m.id??``))??null:null,_=f?.texmodmatrix??f?.matrix;if(p&&Array.isArray(_)&&_.length===16&&!lo(_)&&(p=p.clone(),p.matrixAutoUpdate=!1,p.matrix.set(_[0],_[4],_[12],_[1],_[5],_[13],0,0,1)),p&&f?.addressmode){let e=f.addressmode.u,n=f.addressmode.v;(e!==void 0||n!==void 0)&&(p.matrixAutoUpdate&&(p=p.clone()),e!==void 0&&(p.wrapS=e===0?t.RepeatWrapping:t.ClampToEdgeWrapping),n!==void 0&&(p.wrapT=n===0?t.RepeatWrapping:t.ClampToEdgeWrapping))}let v=c?.diffuse??{r:1,g:1,b:1,a:1},y=[f,m].some(e=>/\.water$/i.test(String(so(e)??e?.id??``))),b=ua({alphaMode:c?.alphaMode,diffuseAlpha:v.a??1,transparentSorting:c?.transparentsorting===!0,vertexAlphaMin:s,isWaterWithoutMap:y&&!p}),x=typeof c?.shininess==`number`&&c.shininess>0?Math.max(.15,1-c.shininess/128):.95,S=p?.userData?.s3mHasAlpha?Math.max(c?.alphaCutoff??0,.01):0,C=Li({uniforms:r,map:p,color:y&&!p?ho.clone():new t.Color(v.r??1,v.g??1,v.b??1),side:uo(c),transparent:b,opacity:y&&!p?.86:v.a??1,roughness:y&&!p?.12:x,alphaTest:S,atlas:a&&!!p,texCoordZ:o&&!!p,secMap:g});return n.polygonOffset&&(C.polygonOffset=!0,C.polygonOffsetFactor=n.polygonOffset.factor,C.polygonOffsetUnits=n.polygonOffset.units),C},m=n.assembled??Aa(e,{batching:n.batching!==!1,dedupeCoincident:n.dedupeCoincident});c.vertices=m.stats.vertices,c.edgeLines=m.stats.edgeLines,c.instanced=m.stats.instanced,m.stats.originalMeshes!=null&&(c.originalMeshes=m.stats.originalMeshes),c.skipped.push(...m.stats.skipped);let h=new t.Matrix4,g=e=>{let n=new t.BufferGeometry;for(let[r,i]of Object.entries(e.attributes))i&&n.setAttribute(r,new t.BufferAttribute(i.array,i.components,i.normalized));return e.index?n.setIndex(new t.BufferAttribute(e.index,1)):n.setDrawRange(0,e.vertexCount),n.boundingBox=new t.Box3(new t.Vector3(...e.bounds.boxMin),new t.Vector3(...e.bounds.boxMax)),n.boundingSphere=new t.Sphere(new t.Vector3(...e.bounds.sphereCenter),e.bounds.sphereRadius),n};for(let r of m.primitives){let i=g(r),s=e.geoPackage[r.geoNames[0]]??null,u=s?.vertexPackage,d=p(r.passNames[0],!!r.attributes.aAtlasRect,!!r.attributes.aTexCoordZ,da(r.attributes.aColor)),m=r.matrix&&r.matrix.length===16?new t.Matrix4().fromArray(r.matrix):null;if(Qa(r.primitiveType)){let e=new t.LineSegments(i,l);e.visible=n.edges===!0,e.renderOrder=go,e.raycast=()=>{},e.userData.isEdgeLines=!0,e.userData.skeletonName=r.skeletonName,m&&!m.equals(h)&&m.decompose(e.position,e.quaternion,e.scale),a.add(e),o.push(e),a.userData.hasNativeEdges=!0;continue}if($a(r.primitiveType)){let n=u?no(r,u):null;if(n){let i=new t.InstancedMesh(n.geo,eo(),n.geo.instanceCount);i.raycast=Ua,i.frustumCulled=!1,i.renderOrder=_o,n.sigma>0&&(c.splatSigma=Math.max(c.splatSigma??0,n.sigma)),c.splatCount=(c.splatCount??0)+n.geo.instanceCount,i.userData.isPointCloud=!0,i.userData.isGaussianSplat=!0,i.userData.skeletonName=r.skeletonName,i.userData.geoRef=s,i.userData.tileRef=e,i.userData.primitiveType=r.primitiveType,m&&!m.equals(h)&&m.decompose(i.position,i.quaternion,i.scale),a.add(i),o.push(i),c.meshes++;continue}i.getAttribute(`color`)||i.setAttribute(`color`,i.getAttribute(`aColor`));let l=new t.Points(i,io());l.userData.isPointCloud=!0,l.userData.skeletonName=r.skeletonName,l.userData.geoRef=s,l.userData.tileRef=e,l.userData.primitiveType=r.primitiveType,m&&!m.equals(h)&&m.decompose(l.position,l.quaternion,l.scale),a.add(l),o.push(l),c.meshes++;continue}let _;if(u&&u.instanceIndex!==-1&&(u.instanceMode===16||u.instanceMode===17)&&u.instanceBuffer&&(u.instanceCount??0)>0&&u){if(!i.getAttribute(`aInstanceBatchId`)){let e=u.instanceBatchIds,n=e&&e.length===u.instanceCount?e.slice():new Float32Array(u.instanceCount).fill(-1);i.setAttribute(`aInstanceBatchId`,new t.InstancedBufferAttribute(n,1));let r=new Float32Array(u.instanceCount);for(let e=0;e<r.length;e++)r[e]=e;i.setAttribute(`aInstanceIndex`,new t.InstancedBufferAttribute(r,1))}let e=new t.InstancedMesh(i,d,u.instanceCount);e.instanceMatrix.setUsage(t.StaticDrawUsage);let n=new t.Matrix4,r=new t.Color,a=u.instanceMode,o=new Float32Array(u.instanceBuffer.buffer,u.instanceBuffer.byteOffset,u.instanceCount*a);for(let t=0;t<u.instanceCount;t++){let i=t*a;if(n.set(o[i+0],o[i+1],o[i+2],o[i+3],o[i+4],o[i+5],o[i+6],o[i+7],o[i+8],o[i+9],o[i+10],o[i+11],0,0,0,1),e.setMatrixAt(t,n),a>=16){let n=o[i+12],a=o[i+13],s=o[i+14];Number.isFinite(n)&&Number.isFinite(a)&&Number.isFinite(s)&&(r.setRGB(n,a,s),e.setColorAt(t,r))}}e.instanceMatrix.needsUpdate=!0,e.instanceColor&&(e.instanceColor.needsUpdate=!0),e.frustumCulled=!1,_=e}else _=new t.Mesh(i,d);m&&!m.equals(h)&&m.decompose(_.position,_.quaternion,_.scale),_.userData.skeletonName=r.skeletonName,_.userData.geoRef=s,_.userData.tileRef=e,_.userData.primitiveType=r.primitiveType;let v=f(r.passNames[0]);if(v>=0&&!d.transparent&&(_.renderOrder=Math.min(v,vo)),r.batchedFrom!=null&&r.batchedFrom>1){_.userData.isBatched=!0,_.userData.batchedCount=r.batchedFrom;let t=new Map;for(let n of r.geoNames){let r=e.geoPackage[n];if(r?.pickInfo)for(let e of Object.values(r.pickInfo))typeof e.batchId==`number`&&e.batchId>=0&&t.set(e.batchId,r)}t.size>0&&(_.userData.geoByBatchId=t)}a.add(_),o.push(_),c.meshes++,r.primitiveType===4&&(c.triangles+=r.indexCount/3)}return a.children.length||c.skipped.push(`tile 无可用几何`),a.userData.textureKeys=s,{group:a,stats:c,objects:o,textureKeys:s}}var po,mo,ho,go,_o,vo,yo=c((()=>{wi(),ca(),fa(),Na(),Ba(),Xa(),nn(),po=null,mo=null,ho=new t.Color(1920611),go=1e3,_o=1001,vo=999}));b();function bo(e){return e.slice(0,e.lastIndexOf(`/`)+1)}function xo(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 So(e,t){if(!t)return null;try{return Co(new URL(t,e).href)}catch{return Co(`${bo(e)}${t}`)}}function Co(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 wo=110540,To=111320;function Eo(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 Do(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?So(bo(e),n):Co(`${r[r.length-1]===`path`&&r[r.length-2]===`data`?`${r.join(`/`)}/${a}`:`${r.join(`/`)}/data/path/${a}`}/${n}`)}function Oo(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=To*Math.cos(i*Math.PI/180);n>1e-6&&(o=r+e/n,s=r+t/n,l=i+a/wo,c=i+u/wo)}}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 ko=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){y(this,`configUrl`,void 0),y(this,`config`,null),y(this,`_blockTileIndex`,null),y(this,`anchor`,{lon:0,lat:0,height:0}),y(this,`rootUrls`,[]),y(this,`nodes`,new Map),y(this,`failed`,new Set),y(this,`textureCache`,new Map),y(this,`maxImageCache`,void 0),y(this,`_textureRefs`,new Map),y(this,`_tileTextureKeys`,new Map),y(this,`pending`,new Set),y(this,`atlasLod`,void 0),y(this,`atlasLodCache`,new Map),y(this,`_groupCache`,new Map),y(this,`externalAtlasCache`,new Map),y(this,`leafRequestCache`,new Map),y(this,`_leafPending`,new Map),y(this,`atlasUpgraded`,new Set),y(this,`atlasUpgradeSkipped`,new Map),y(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:[]}),y(this,`maxConcurrent`,void 0),y(this,`maxTiles`,void 0),y(this,`maxTriangles`,void 0),y(this,`lodRangeScale`,void 0),y(this,`_onTile`,void 0),y(this,`_onTileRemoved`,void 0),y(this,`_onError`,void 0),y(this,`_onProgress`,void 0),y(this,`_maxRetries`,void 0),y(this,`authenticate`,void 0),y(this,`_unsupported`,void 0),y(this,`_retryCount`,new Map),y(this,`_retryAt`,new Map),y(this,`_parentOf`,new Map),y(this,`_frame`,0),y(this,`_permanentReported`,!1),y(this,`hardCap`,96),y(this,`isS3MV1`,!1),y(this,`_buildTile`,void 0),y(this,`_polygonOffset`,void 0),y(this,`_uniforms`,void 0),y(this,`_workerClient`,void 0),y(this,`_useWorker`,void 0),y(this,`_queue`,[]),y(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=xo(this.configUrl);let e=await Ut(this.configUrl,this.authenticate,`config`);if(!e.ok)throw Error(`配置读取失败 ${e.status} ${this.configUrl}`);let t=Oo(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=So(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=So(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=Eo(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(()=>(yo(),Za));this._buildTile=e.buildTileObjects}return this._buildTile}async _parseClassicTile(e){if(this._useWorker&&this._workerClient===void 0&&(this._workerClient=un()),this._workerClient)try{return await this._workerClient.parseTile(e,!0)}catch(e){if(e instanceof sn)this._workerClient=null;else throw e}return{tile:await Pt(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=Pr(n),a=!1,o=new Map,s=new Map,c=[];for(let[e,t]of Object.entries(r)){let n=Gr(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=Kr(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=Xr(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)&&Fr(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=So(bo(e),`${n[0]}.texblock?extratiles=${n.join(`;`)}`);try{if(!r)throw Error(`无法拼出 URL`);let e=await Ut(r,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await Rr(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=So(bo(e),`${t}.texblock`);try{if(!n)throw Error(`无法拼出 URL`);let e=await Ut(n,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let r=(await Rr(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=It(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 Ut(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 qr(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?Do(e,t.childTile):So(bo(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?Do(e,p?.childTile):So(bo(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?on({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()}};yo();var Ao={ambientIntensity:.4,hemisphereIntensity:.8,keyLightIntensity:1,fillLightIntensity:.35},jo={ambientIntensity:.12,hemisphereIntensity:.2,keyLightIntensity:1.95,fillLightIntensity:.15},Mo={default:Ao,supermap:jo};function No(e){return e&&Object.prototype.hasOwnProperty.call(Mo,e)?Mo[e]:Ao}ca(),wi(),b();var Po={ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50},Fo=class{get envRT(){return this._envRT}set envRT(e){this._envRT=e}constructor(e){y(this,`ctx`,void 0),y(this,`ambient`,null),y(this,`hemi`,null),y(this,`key`,null),y(this,`fill`,null),y(this,`_state`,void 0),y(this,`_envRT`,null),this.ctx=e,this._state={...Po};let t=e.options;t.lightingPreset&&t.lightingPreset!=="default"&&(Object.assign(this._state,No(t.lightingPreset)),this.applyColorPipeline(t.lightingPreset)),t.light&&Object.assign(this._state,t.light)}_create(){this.ambient=new t.AmbientLight(this._state.ambientColor,this._state.ambientIntensity),this.hemi=new t.HemisphereLight(this._state.hemisphereColor,this._state.hemisphereGroundColor,this._state.hemisphereIntensity),this.key=new t.DirectionalLight(this._state.keyLightColor,this._state.keyLightIntensity),this.fill=new t.DirectionalLight(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`;Pi(t?`direct`:`linear`),mi(!t),li(t?1:1/0)}setLightingPreset(e){Object.assign(this._state,No(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??t.NoToneMapping,toneMappingExposure:e?e.toneMappingExposure:this.ctx.options.toneMappingExposure??1}}async setEnvironment(e,n=1){let r=this.ctx.renderer(),i=this.ctx.scene();if(!r||!i)return;if(i.environmentIntensity=Math.max(0,n),e==null){i.environment=null,this._envRT?.dispose(),this._envRT=null,this.ctx.repaint();return}let a=typeof e==`string`,o=a?await new t.TextureLoader().loadAsync(e):e;o.mapping=t.EquirectangularReflectionMapping;let s=new t.PMREMGenerator(r);s.compileEquirectangularShader();let c=s.fromEquirectangular(o);s.dispose(),a&&o.dispose(),i.environment=c.texture,this._envRT?.dispose(),this._envRT=c,this.ctx.repaint()}dispose(){this._envRT?.dispose(),this._envRT=null}};b();var Io=class{constructor(e){y(this,`uniforms`,void 0),y(this,`_meshHeight`,new Map),y(this,`_min`,1/0),y(this,`_max`,-1/0),y(this,`_box`,new t.Box3),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}},Lo=new Uint32Array,Ro=new Uint32Array,zo=new Uint32Array(256),Bo=new Float32Array(1),Vo=new Uint32Array(Bo.buffer);function Ho(e){Bo[0]=e;let t=Vo[0];return t&2147483648?~t>>>0:(t|2147483648)>>>0}function Uo(e,t,n,r){let i=r&&r.length>=t?r:new Uint32Array(t);if(t<=1)return t===1&&(i[0]=0),i;Lo.length<t&&(Lo=new Uint32Array(t)),Ro.length<t&&(Ro=new Uint32Array(t));let a=Lo,o=Ro,s=n.elements,c=s[2],l=s[6],u=s[10],d=s[14];for(let n=0;n<t;n++)a[n]=Ho(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;zo.fill(0);for(let e=0;e<t;e++)zo[a[f[e]]>>>n&255]++;let r=0;for(let e=0;e<256;e++){let t=zo[e];zo[e]=r,r+=t}for(let e=0;e<t;e++){let t=f[e];p[zo[a[t]>>>n&255]++]=t}let i=f;f=p,p=i}return f!==i&&i.set(f),i}var Wo=[`iCenter`,`iScale`,`iQuat`,`iColor`],Go=new t.Matrix4,Ko=new WeakMap,qo=new WeakMap;function Jo(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;Go.multiplyMatrices(t,e.matrixWorld);let a=qo.get(r);(!a||a.length<i)&&(a=new Uint32Array(i),qo.set(r,a)),Uo(r.array,i,Go,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 Wo){let t=n.getAttribute(e);if(!t)continue;let r=t.array,o=t.itemSize,s=i*o,c=Ko.get(t);(!c||c.length<s)&&(c=new r.constructor(s),Ko.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}b();var Yo=class{constructor(){y(this,`_lastView`,new t.Matrix4),y(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&&Jo(n,e.matrixWorldInverse);this._lastView.copy(e.matrixWorldInverse),this._sorted=!0}}reset(){this._sorted=!1,this._lastView.identity()}};ca(),ki();function Xo(){return{uResolution:{value:new t.Vector2(1,1)},uDpr:{value:1}}}var Zo=`
|
|
931
|
+
`,side:t.DoubleSide,depthTest:!0,depthWrite:!0})}function Ga(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 Ka,qa,Ja,Ya,Xa=c((()=>{nn(),Ka=new t.Vector2(1e3,1e3),qa=new t.Sphere,Ja=new t.Matrix4,Ya=new t.Ray})),Za=l({LINE_PRIMITIVE:()=>13,POINT_PRIMITIVE:()=>1,buildTileObjects:()=>fo,setSplatViewport:()=>to});function Qa(e){return e===13||e===2||e===3}function $a(e){return e===1}function eo(){return po??(po=Va()),po}function to(e,t){po&&po.uniforms.uViewport.value.set(e,t)}function no(e,n){let r=n.vertexAttributes.find(e=>e.semantic===`gsScale`),i=n.vertexAttributes.find(e=>e.semantic===`gsRotation`),a=e.attributes.position;if(!r||!i||!a)return null;let o=Math.min(n.verticesCount,Math.floor(a.array.length/a.components));if(o<=0)return null;let s=Pa(r.data,r.stride,r.offsetInBytes,o),c=Fa(i.data,i.stride,i.offsetInBytes,o),l=ro(s,o),u=Ha();u.instanceCount=o,u.setAttribute(`iCenter`,new t.InstancedBufferAttribute(a.array,3)),u.setAttribute(`iScale`,new t.InstancedBufferAttribute(s,3)),u.setAttribute(`iQuat`,new t.InstancedBufferAttribute(c,4));let d=new Float32Array(o*4);d.fill(1);let f=n.vertexAttributes.find(e=>e.semantic===`color`);if(f&&f.dtype===`u8`){let e=f.components??4,t=Math.min(o,Math.floor(f.data.length/f.stride));for(let n=0;n<t;n++){let t=n*f.stride+f.offsetInBytes;d[n*4]=f.data[t]/255,d[n*4+1]=f.data[t+1]/255,d[n*4+2]=f.data[t+2]/255,e>=4&&(d[n*4+3]=f.data[t+3]/255)}}else if(e.attributes.aColor){let t=e.attributes.aColor,n=t.components??4;for(let e=0;e<o;e++)for(let r=0;r<Math.min(n,4);r++)d[e*4+r]=t.array[e*n+r]}u.setAttribute(`iColor`,new t.InstancedBufferAttribute(d,4));let p=a.array,m=1/0,h=1/0,g=1/0,_=-1/0,v=-1/0,y=-1/0,b=0;for(let e=0;e<o;e++){let t=p[e*3],n=p[e*3+1],r=p[e*3+2];t<m&&(m=t),t>_&&(_=t),n<h&&(h=n),n>v&&(v=n),r<g&&(g=r),r>y&&(y=r);let i=s[e*3],a=s[e*3+1],o=s[e*3+2];i>b&&(b=i),a>b&&(b=a),o>b&&(b=o)}let x=new t.Box3;o>0&&(x.min.set(m,h,g),x.max.set(_,v,y));let S=new t.Sphere(new t.Vector3,0);return x.isEmpty()||x.getBoundingSphere(S),S.radius+=3*b,u.boundingSphere=S,{geo:u,sigma:l}}function ro(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 io(){return mo||(mo=new t.PointsMaterial({size:2,sizeAttenuation:!1,vertexColors:!0})),mo}function ao(e){if(!e)return[];if(Array.isArray(e))return e;let t=e,n=t.materials??t.material;return Array.isArray(n)?n:[]}function oo(e){return e?.material??e}function so(e){return e?.name??e?.id}function co(e){return(e?.textureStates??e?.textureunitstates??[]).map(e=>e?.textureunitstate??e).filter(e=>!!e)}function lo(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 uo(e){let n=String(e?.cullMode??``).toUpperCase();return n===`CULL_BACK`||n===`BACKWARD`?t.FrontSide:n===`CULL_FRONT`?t.BackSide:t.DoubleSide}async function fo(e,n={}){let r=n.uniforms??Ii(),i=n.textureCache??new Map,a=new t.Group,o=[],s=[],c={meshes:0,vertices:0,triangles:0,textures:0,instanced:0,edgeLines:0,skipped:[]},l=new t.LineBasicMaterial({color:new t.Color(n.edgeColor??`#1f2937`),transparent:!0,opacity:.75,depthWrite:!1});a.userData.hasNativeEdges=!1;let u=t=>{let n=e.textures?.[t];return n?.packKey?`${t}#${n.packKey}`:t};for(let[t,n]of Object.entries(e.textures??{})){let e=u(t),r=i.get(e);if(r){let t=r.image;if((t?.width??0)*(t?.height??0)>=(n.width??0)*(n.height??0))continue;i.delete(e)}let{texture:a,decoded:o}=await _i(n);a?(i.set(e,a),s.push(e),c.textures++):c.skipped.push(`texture ${t} → ${o}`)}let d=ao(e.materials),f=e=>d.findIndex(t=>so(oo(t))===e),p=(e,a=!1,o=!1,s=1)=>{let c=oo(d.find(t=>so(oo(t))===e)),l=co(c),f=l[0],p=f?i.get(u(so(f)??f.id??``))??null:null,m=l[1],h=globalThis.__S3M_NO_BAKE===!0,g=a&&m&&!h?i.get(u(so(m)??m.id??``))??null:null,_=f?.texmodmatrix??f?.matrix;if(p&&Array.isArray(_)&&_.length===16&&!lo(_)&&(p=p.clone(),p.matrixAutoUpdate=!1,p.matrix.set(_[0],_[4],_[12],_[1],_[5],_[13],0,0,1)),p&&f?.addressmode){let e=f.addressmode.u,n=f.addressmode.v;(e!==void 0||n!==void 0)&&(p.matrixAutoUpdate&&(p=p.clone()),e!==void 0&&(p.wrapS=e===0?t.RepeatWrapping:t.ClampToEdgeWrapping),n!==void 0&&(p.wrapT=n===0?t.RepeatWrapping:t.ClampToEdgeWrapping))}let v=c?.diffuse??{r:1,g:1,b:1,a:1},y=[f,m].some(e=>/\.water$/i.test(String(so(e)??e?.id??``))),b=ua({alphaMode:c?.alphaMode,diffuseAlpha:v.a??1,transparentSorting:c?.transparentsorting===!0,vertexAlphaMin:s,isWaterWithoutMap:y&&!p}),x=typeof c?.shininess==`number`&&c.shininess>0?Math.max(.15,1-c.shininess/128):.95,S=p?.userData?.s3mHasAlpha?Math.max(c?.alphaCutoff??0,.01):0,C=Li({uniforms:r,map:p,color:y&&!p?ho.clone():new t.Color(v.r??1,v.g??1,v.b??1),side:uo(c),transparent:b,opacity:y&&!p?.86:v.a??1,roughness:y&&!p?.12:x,alphaTest:S,atlas:a&&!!p,texCoordZ:o&&!!p,secMap:g});return n.polygonOffset&&(C.polygonOffset=!0,C.polygonOffsetFactor=n.polygonOffset.factor,C.polygonOffsetUnits=n.polygonOffset.units),C},m=n.assembled??Aa(e,{batching:n.batching!==!1,dedupeCoincident:n.dedupeCoincident});c.vertices=m.stats.vertices,c.edgeLines=m.stats.edgeLines,c.instanced=m.stats.instanced,m.stats.originalMeshes!=null&&(c.originalMeshes=m.stats.originalMeshes),c.skipped.push(...m.stats.skipped);let h=new t.Matrix4,g=e=>{let n=new t.BufferGeometry;for(let[r,i]of Object.entries(e.attributes))i&&n.setAttribute(r,new t.BufferAttribute(i.array,i.components,i.normalized));return e.index?n.setIndex(new t.BufferAttribute(e.index,1)):n.setDrawRange(0,e.vertexCount),n.boundingBox=new t.Box3(new t.Vector3(...e.bounds.boxMin),new t.Vector3(...e.bounds.boxMax)),n.boundingSphere=new t.Sphere(new t.Vector3(...e.bounds.sphereCenter),e.bounds.sphereRadius),n};for(let r of m.primitives){let i=g(r),s=e.geoPackage[r.geoNames[0]]??null,u=s?.vertexPackage,d=p(r.passNames[0],!!r.attributes.aAtlasRect,!!r.attributes.aTexCoordZ,da(r.attributes.aColor)),m=r.matrix&&r.matrix.length===16?new t.Matrix4().fromArray(r.matrix):null;if(Qa(r.primitiveType)){let e=new t.LineSegments(i,l);e.visible=n.edges===!0,e.renderOrder=go,e.raycast=()=>{},e.userData.isEdgeLines=!0,e.userData.skeletonName=r.skeletonName,m&&!m.equals(h)&&m.decompose(e.position,e.quaternion,e.scale),a.add(e),o.push(e),a.userData.hasNativeEdges=!0;continue}if($a(r.primitiveType)){let n=u?no(r,u):null;if(n){let i=new t.InstancedMesh(n.geo,eo(),n.geo.instanceCount);i.raycast=Ua,i.frustumCulled=!1,i.renderOrder=_o,n.sigma>0&&(c.splatSigma=Math.max(c.splatSigma??0,n.sigma)),c.splatCount=(c.splatCount??0)+n.geo.instanceCount,i.userData.isPointCloud=!0,i.userData.isGaussianSplat=!0,i.userData.skeletonName=r.skeletonName,i.userData.geoRef=s,i.userData.tileRef=e,i.userData.primitiveType=r.primitiveType,m&&!m.equals(h)&&m.decompose(i.position,i.quaternion,i.scale),a.add(i),o.push(i),c.meshes++;continue}i.getAttribute(`color`)||i.setAttribute(`color`,i.getAttribute(`aColor`));let l=new t.Points(i,io());l.userData.isPointCloud=!0,l.userData.skeletonName=r.skeletonName,l.userData.geoRef=s,l.userData.tileRef=e,l.userData.primitiveType=r.primitiveType,m&&!m.equals(h)&&m.decompose(l.position,l.quaternion,l.scale),a.add(l),o.push(l),c.meshes++;continue}let _;if(u&&u.instanceIndex!==-1&&(u.instanceMode===16||u.instanceMode===17)&&u.instanceBuffer&&(u.instanceCount??0)>0&&u){if(!i.getAttribute(`aInstanceBatchId`)){let e=u.instanceBatchIds,n=e&&e.length===u.instanceCount?e.slice():new Float32Array(u.instanceCount).fill(-1);i.setAttribute(`aInstanceBatchId`,new t.InstancedBufferAttribute(n,1));let r=new Float32Array(u.instanceCount);for(let e=0;e<r.length;e++)r[e]=e;i.setAttribute(`aInstanceIndex`,new t.InstancedBufferAttribute(r,1))}let e=new t.InstancedMesh(i,d,u.instanceCount);e.instanceMatrix.setUsage(t.StaticDrawUsage);let n=new t.Matrix4,r=new t.Color,a=u.instanceMode,o=new Float32Array(u.instanceBuffer.buffer,u.instanceBuffer.byteOffset,u.instanceCount*a);for(let t=0;t<u.instanceCount;t++){let i=t*a;if(n.set(o[i+0],o[i+1],o[i+2],o[i+3],o[i+4],o[i+5],o[i+6],o[i+7],o[i+8],o[i+9],o[i+10],o[i+11],0,0,0,1),e.setMatrixAt(t,n),a>=16){let n=o[i+12],a=o[i+13],s=o[i+14];Number.isFinite(n)&&Number.isFinite(a)&&Number.isFinite(s)&&(r.setRGB(n,a,s),e.setColorAt(t,r))}}e.instanceMatrix.needsUpdate=!0,e.instanceColor&&(e.instanceColor.needsUpdate=!0),e.frustumCulled=!1,_=e}else _=new t.Mesh(i,d);m&&!m.equals(h)&&m.decompose(_.position,_.quaternion,_.scale),_.userData.skeletonName=r.skeletonName,_.userData.geoRef=s,_.userData.tileRef=e,_.userData.primitiveType=r.primitiveType;let v=f(r.passNames[0]);if(v>=0&&!d.transparent&&(_.renderOrder=Math.min(v,vo)),r.batchedFrom!=null&&r.batchedFrom>1){_.userData.isBatched=!0,_.userData.batchedCount=r.batchedFrom;let t=new Map;for(let n of r.geoNames){let r=e.geoPackage[n];if(r?.pickInfo)for(let e of Object.values(r.pickInfo))typeof e.batchId==`number`&&e.batchId>=0&&t.set(e.batchId,r)}t.size>0&&(_.userData.geoByBatchId=t)}a.add(_),o.push(_),c.meshes++,r.primitiveType===4&&(c.triangles+=r.indexCount/3)}a.children.length||c.skipped.push(`tile 无可用几何`);let _=0;for(let e of o){let t=e,n=t.geometry;if(n){if(n.attributes)for(let e of Object.values(n.attributes))e&&e.array&&(_+=e.array.byteLength);n.index&&n.index.array&&(_+=n.index.array.byteLength)}if(t.isInstancedMesh){let e=t;e.instanceMatrix&&e.instanceMatrix.array&&(_+=e.instanceMatrix.array.byteLength),e.instanceColor&&e.instanceColor.array&&(_+=e.instanceColor.array.byteLength)}}return c.memory=_,a.userData.textureKeys=s,{group:a,stats:c,objects:o,textureKeys:s}}var po,mo,ho,go,_o,vo,yo=c((()=>{wi(),ca(),fa(),Na(),Ba(),Xa(),nn(),po=null,mo=null,ho=new t.Color(1920611),go=1e3,_o=1001,vo=999}));b();function bo(e){return e.slice(0,e.lastIndexOf(`/`)+1)}function xo(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 So(e,t){if(!t)return null;try{return Co(new URL(t,e).href)}catch{return Co(`${bo(e)}${t}`)}}function Co(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 wo=110540,To=111320;function Eo(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 Do(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?So(bo(e),n):Co(`${r[r.length-1]===`path`&&r[r.length-2]===`data`?`${r.join(`/`)}/${a}`:`${r.join(`/`)}/data/path/${a}`}/${n}`)}function Oo(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=To*Math.cos(i*Math.PI/180);n>1e-6&&(o=r+e/n,s=r+t/n,l=i+a/wo,c=i+u/wo)}}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 ko(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 Ao(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 jo=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){y(this,`configUrl`,void 0),y(this,`config`,null),y(this,`_blockTileIndex`,null),y(this,`anchor`,{lon:0,lat:0,height:0}),y(this,`rootUrls`,[]),y(this,`nodes`,new Map),y(this,`failed`,new Set),y(this,`textureCache`,new Map),y(this,`maxImageCache`,void 0),y(this,`_textureRefs`,new Map),y(this,`_tileTextureKeys`,new Map),y(this,`pending`,new Set),y(this,`atlasLod`,void 0),y(this,`atlasLodCache`,new Map),y(this,`_groupCache`,new Map),y(this,`externalAtlasCache`,new Map),y(this,`leafRequestCache`,new Map),y(this,`_leafPending`,new Map),y(this,`atlasUpgraded`,new Set),y(this,`atlasUpgradeSkipped`,new Map),y(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:[]}),y(this,`maxConcurrent`,void 0),y(this,`maxTiles`,void 0),y(this,`maxTriangles`,void 0),y(this,`maxMemory`,void 0),y(this,`lodRangeScale`,void 0),y(this,`_onTile`,void 0),y(this,`_onTileRemoved`,void 0),y(this,`_onError`,void 0),y(this,`_onProgress`,void 0),y(this,`_maxRetries`,void 0),y(this,`authenticate`,void 0),y(this,`_unsupported`,void 0),y(this,`_retryCount`,new Map),y(this,`_retryAt`,new Map),y(this,`_parentOf`,new Map),y(this,`_frame`,0),y(this,`_permanentReported`,!1),y(this,`hardCap`,96),y(this,`isS3MV1`,!1),y(this,`_buildTile`,void 0),y(this,`_polygonOffset`,void 0),y(this,`_uniforms`,void 0),y(this,`_workerClient`,void 0),y(this,`_useWorker`,void 0),y(this,`_queue`,[]),y(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=xo(this.configUrl);let e=await Ut(this.configUrl,this.authenticate,`config`);if(!e.ok)throw Error(`配置读取失败 ${e.status} ${this.configUrl}`);let t=Oo(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=So(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=So(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+=Ao(t.group));return e}_residentTextureBytes(){let e=0;for(let t of this.textureCache.values())e+=ko(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=Eo(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(()=>(yo(),Za));this._buildTile=e.buildTileObjects}return this._buildTile}async _parseClassicTile(e){if(this._useWorker&&this._workerClient===void 0&&(this._workerClient=un()),this._workerClient)try{return await this._workerClient.parseTile(e,!0)}catch(e){if(e instanceof sn)this._workerClient=null;else throw e}return{tile:await Pt(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=Pr(n),a=!1,o=new Map,s=new Map,c=[];for(let[e,t]of Object.entries(r)){let n=Gr(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=Kr(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=Xr(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)&&Fr(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=So(bo(e),`${n[0]}.texblock?extratiles=${n.join(`;`)}`);try{if(!r)throw Error(`无法拼出 URL`);let e=await Ut(r,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await Rr(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=So(bo(e),`${t}.texblock`);try{if(!n)throw Error(`无法拼出 URL`);let e=await Ut(n,this.authenticate,`texblock`);if(!e.ok)throw Error(`HTTP ${e.status}`);let r=(await Rr(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=It(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 Ut(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 qr(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?Do(e,t.childTile):So(bo(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?Do(e,p?.childTile):So(bo(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??Ao(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?on({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()}};yo();var Mo={ambientIntensity:.4,hemisphereIntensity:.8,keyLightIntensity:1,fillLightIntensity:.35},No={ambientIntensity:.12,hemisphereIntensity:.2,keyLightIntensity:1.95,fillLightIntensity:.15},Po={default:Mo,supermap:No};function Fo(e){return e&&Object.prototype.hasOwnProperty.call(Po,e)?Po[e]:Mo}ca(),wi(),b();var Io={ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50},Lo=class{get envRT(){return this._envRT}set envRT(e){this._envRT=e}constructor(e){y(this,`ctx`,void 0),y(this,`ambient`,null),y(this,`hemi`,null),y(this,`key`,null),y(this,`fill`,null),y(this,`_state`,void 0),y(this,`_envRT`,null),this.ctx=e,this._state={...Io};let t=e.options;t.lightingPreset&&t.lightingPreset!=="default"&&(Object.assign(this._state,Fo(t.lightingPreset)),this.applyColorPipeline(t.lightingPreset)),t.light&&Object.assign(this._state,t.light)}_create(){this.ambient=new t.AmbientLight(this._state.ambientColor,this._state.ambientIntensity),this.hemi=new t.HemisphereLight(this._state.hemisphereColor,this._state.hemisphereGroundColor,this._state.hemisphereIntensity),this.key=new t.DirectionalLight(this._state.keyLightColor,this._state.keyLightIntensity),this.fill=new t.DirectionalLight(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`;Pi(t?`direct`:`linear`),mi(!t),li(t?1:1/0)}setLightingPreset(e){Object.assign(this._state,Fo(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??t.NoToneMapping,toneMappingExposure:e?e.toneMappingExposure:this.ctx.options.toneMappingExposure??1}}async setEnvironment(e,n=1){let r=this.ctx.renderer(),i=this.ctx.scene();if(!r||!i)return;if(i.environmentIntensity=Math.max(0,n),e==null){i.environment=null,this._envRT?.dispose(),this._envRT=null,this.ctx.repaint();return}let a=typeof e==`string`,o=a?await new t.TextureLoader().loadAsync(e):e;o.mapping=t.EquirectangularReflectionMapping;let s=new t.PMREMGenerator(r);s.compileEquirectangularShader();let c=s.fromEquirectangular(o);s.dispose(),a&&o.dispose(),i.environment=c.texture,this._envRT?.dispose(),this._envRT=c,this.ctx.repaint()}dispose(){this._envRT?.dispose(),this._envRT=null}};b();var Ro=class{constructor(e){y(this,`uniforms`,void 0),y(this,`_meshHeight`,new Map),y(this,`_min`,1/0),y(this,`_max`,-1/0),y(this,`_box`,new t.Box3),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}},zo=new Uint32Array,Bo=new Uint32Array,Vo=new Uint32Array(256),Ho=new Float32Array(1),Uo=new Uint32Array(Ho.buffer);function Wo(e){Ho[0]=e;let t=Uo[0];return t&2147483648?~t>>>0:(t|2147483648)>>>0}function Go(e,t,n,r){let i=r&&r.length>=t?r:new Uint32Array(t);if(t<=1)return t===1&&(i[0]=0),i;zo.length<t&&(zo=new Uint32Array(t)),Bo.length<t&&(Bo=new Uint32Array(t));let a=zo,o=Bo,s=n.elements,c=s[2],l=s[6],u=s[10],d=s[14];for(let n=0;n<t;n++)a[n]=Wo(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;Vo.fill(0);for(let e=0;e<t;e++)Vo[a[f[e]]>>>n&255]++;let r=0;for(let e=0;e<256;e++){let t=Vo[e];Vo[e]=r,r+=t}for(let e=0;e<t;e++){let t=f[e];p[Vo[a[t]>>>n&255]++]=t}let i=f;f=p,p=i}return f!==i&&i.set(f),i}var Ko=[`iCenter`,`iScale`,`iQuat`,`iColor`],qo=new t.Matrix4,Jo=new WeakMap,Yo=new WeakMap;function Xo(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;qo.multiplyMatrices(t,e.matrixWorld);let a=Yo.get(r);(!a||a.length<i)&&(a=new Uint32Array(i),Yo.set(r,a)),Go(r.array,i,qo,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 Ko){let t=n.getAttribute(e);if(!t)continue;let r=t.array,o=t.itemSize,s=i*o,c=Jo.get(t);(!c||c.length<s)&&(c=new r.constructor(s),Jo.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}b();var Zo=class{constructor(){y(this,`_lastView`,new t.Matrix4),y(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&&Xo(n,e.matrixWorldInverse);this._lastView.copy(e.matrixWorldInverse),this._sorted=!0}}reset(){this._sorted=!1,this._lastView.identity()}};ca(),ki();function Qo(){return{uResolution:{value:new t.Vector2(1,1)},uDpr:{value:1}}}var $o=`
|
|
932
932
|
attribute vec3 aOther;
|
|
933
933
|
attribute float aSide;
|
|
934
934
|
attribute float aBatchId;
|
|
@@ -1067,7 +1067,7 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1067
1067
|
|
|
1068
1068
|
gl_Position = vec4( ndc * clipA.w, clipA.z, clipA.w );
|
|
1069
1069
|
}
|
|
1070
|
-
`,
|
|
1070
|
+
`,es=`
|
|
1071
1071
|
uniform vec3 uColor;
|
|
1072
1072
|
uniform float uOpacity;
|
|
1073
1073
|
|
|
@@ -1075,14 +1075,14 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1075
1075
|
if ( uOpacity <= 0.003 ) discard;
|
|
1076
1076
|
gl_FragColor = vec4( uColor, uOpacity );
|
|
1077
1077
|
}
|
|
1078
|
-
`;function
|
|
1078
|
+
`;function ts(e,n={},r,i){let a=r??{uColor:{value:new t.Color(n.color??`#ffffff`)},uOpacity:{value:n.opacity??1},uWidth:{value:n.width??1.5},uElevation:{value:n.elevation??0}};n.color!==void 0&&r&&a.uColor.value.set(n.color),n.opacity!==void 0&&r&&(a.uOpacity.value=n.opacity),n.width!==void 0&&r&&(a.uWidth.value=n.width);let o={uBatchTex:i?.uBatchTex??{value:qi},uBatchTex2:i?.uBatchTex2??{value:qi},uBatchMix:i?.uBatchMix??{value:0},uBatchTexWidth:i?.uBatchTexWidth??{value:1},uBatchTexActive:i?.uBatchTexActive??{value:0},uPathTex:i?.uPathTex??{value:Oi.DUMMY_PATH_TEX},uPathCount:i?.uPathCount??{value:1},uPathTexActive:i?.uPathTexActive??{value:0},uPathTime:i?.uPathTime??{value:0}},s=new t.ShaderMaterial({uniforms:{uResolution:e.uResolution,uDpr:e.uDpr,uColor:a.uColor,uOpacity:a.uOpacity,uWidth:a.uWidth,uElevation:a.uElevation??{value:n.elevation??0},uOffset:a.uOffset??{value:0},uTranslation:{value:new t.Vector3(0,0,0)},uBatchTex:o.uBatchTex,uBatchTex2:o.uBatchTex2,uBatchMix:o.uBatchMix,uBatchTexWidth:o.uBatchTexWidth,uBatchTexActive:o.uBatchTexActive,uPathTex:o.uPathTex,uPathCount:o.uPathCount,uPathTexActive:o.uPathTexActive,uPathTime:o.uPathTime},vertexShader:$o,fragmentShader:es,transparent:!0,depthWrite:!1,side:t.DoubleSide,polygonOffset:!0,polygonOffsetFactor:-2,polygonOffsetUnits:-2});return s.userData.isThickLine=!0,s}function ns(e,n,r){let i=Math.floor(e.length/6),a=i*4,o=new Float32Array(a*3),s=new Float32Array(a*3),c=new Float32Array(a),l=new Float32Array(a),u=new Float32Array(a*3),d=a>65535?new Uint32Array(i*6):new Uint16Array(i*6);for(let t=0;t<i;t++){let i=t*6,a=e[i],o=e[i+1],s=e[i+2],c=e[i+3],p=e[i+4],m=e[i+5],h=n?Number(n[t]??-1):-1,g=r?Number(r[i]??0):0,_=r?Number(r[i+1]??0):0,v=r?Number(r[i+2]??0):0,y=t*4;f(y,a,o,s,c,p,m,-1),f(y+1,a,o,s,c,p,m,1),f(y+2,c,p,m,a,o,s,1),f(y+3,c,p,m,a,o,s,-1);for(let e=0;e<4;e++){l[y+e]=h;let t=(y+e)*3;u[t]=g,u[t+1]=_,u[t+2]=v}let b=t*6;d[b]=y,d[b+1]=y+1,d[b+2]=y+2,d[b+3]=y,d[b+4]=y+2,d[b+5]=y+3}function f(e,t,n,r,i,a,l,u){let d=e*3;o[d]=t,o[d+1]=n,o[d+2]=r,s[d]=i,s[d+1]=a,s[d+2]=l,c[e]=u}let p=new t.BufferGeometry;return p.setAttribute(`position`,new t.BufferAttribute(o,3)),p.setAttribute(`aOther`,new t.BufferAttribute(s,3)),p.setAttribute(`aSide`,new t.BufferAttribute(c,1)),p.setAttribute(`aBatchId`,new t.BufferAttribute(l,1)),p.setAttribute(`aNormal`,new t.BufferAttribute(u,3)),p.setIndex(new t.BufferAttribute(d,1)),p.computeBoundingSphere(),p}function rs(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=is(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 is(e,t,n,r){return`${Math.round(e*r)},${Math.round(t*r)},${Math.round(n*r)}`}var as=6e4,os=100;function ss(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]*os)},${Math.round(s[n]*os)},${Math.round(c[n]*os)}`,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>=as*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}function cs(e,t,n,r){return`${Math.round(e*r)},${Math.round(t*r)},${Math.round(n*r)}`}function ls(e,n){let r=e.getAttribute(`position`);if(!r||r.count===0)return e;let i=1/Math.max(n,1e-9),a=new Map,o=[],s=new Int32Array(r.count);for(let e=0;e<r.count;e++){let t=r.getX(e),n=r.getY(e),c=r.getZ(e),l=cs(t,n,c,i),u=a.get(l);u===void 0&&(u=o.length/3,o.push(t,n,c),a.set(l,u)),s[e]=u}let c=e.getIndex(),l=c?c.count:r.count,u=new Uint32Array(l);for(let e=0;e<l;e++)u[e]=s[c?c.getX(e):e];let d=new t.BufferGeometry;return d.setAttribute(`position`,new t.Float32BufferAttribute(o,3)),d.setIndex(new t.BufferAttribute(u,1)),d}b();var us=`
|
|
1079
1079
|
out vec2 vUv;
|
|
1080
1080
|
void main() {
|
|
1081
1081
|
vUv = uv;
|
|
1082
1082
|
// 直接给裁剪空间坐标,不走任何矩阵 —— 全屏 quad 没有相机语义
|
|
1083
1083
|
gl_Position = vec4( position.xy, 0.0, 1.0 );
|
|
1084
1084
|
}
|
|
1085
|
-
`,
|
|
1085
|
+
`,ds=`
|
|
1086
1086
|
precision highp float;
|
|
1087
1087
|
|
|
1088
1088
|
uniform sampler2D tNormal;
|
|
@@ -1144,9 +1144,9 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1144
1144
|
gl_FragDepth = d;
|
|
1145
1145
|
fragColor = vec4( uColor, a );
|
|
1146
1146
|
}
|
|
1147
|
-
`,us=class{constructor(){y(this,`rt`,null),y(this,`width`,0),y(this,`height`,0),y(this,`normalMaterial`,new t.MeshNormalMaterial),y(this,`quadScene`,new t.Scene),y(this,`quadCamera`,new t.OrthographicCamera(-1,1,1,-1,0,1)),y(this,`material`,void 0),this.material=new t.ShaderMaterial({glslVersion:t.GLSL3,uniforms:{tNormal:{value:null},tDepth:{value:null},uTexel:{value:new t.Vector2(1,1)},uRadius:{value:1.5},uNormalThreshold:{value:.55},uDepthThreshold:{value:.08},uColor:{value:new t.Color(`#334155`)},uOpacity:{value:.6}},vertexShader:cs,fragmentShader:ls,transparent:!0,depthTest:!0,depthWrite:!1,side:t.DoubleSide,blending:t.NormalBlending});let e=new t.Mesh(new t.PlaneGeometry(2,2),this.material);e.frustumCulled=!1,e.raycast=()=>{},this.quadScene.add(e)}supported(e){return e.capabilities.isWebGL2===!0}ensureTarget(e,n){if(this.rt&&this.width===e&&this.height===n)return this.rt;this.disposeTarget();let r=new t.WebGLRenderTarget(Math.max(1,e),Math.max(1,n),{minFilter:t.NearestFilter,magFilter:t.NearestFilter,format:t.RGBAFormat,type:t.UnsignedByteType,depthBuffer:!0,stencilBuffer:!1,generateMipmaps:!1});return r.texture.generateMipmaps=!1,r.depthTexture=new t.DepthTexture(Math.max(1,e),Math.max(1,n),t.UnsignedIntType),this.rt=r,this.width=e,this.height=n,r}render(e,n,r,i,a,o){if(!this.supported(e)||i<=0||a<=0)return;let s=this.ensureTarget(i,a),c=n.overrideMaterial,l=e.getClearColor(new t.Color),u=e.getClearAlpha();n.overrideMaterial=this.normalMaterial,e.setRenderTarget(s),e.setClearColor(0,0),e.clear(!0,!0,!0),e.render(n,r),n.overrideMaterial=c,e.setRenderTarget(null),e.setClearColor(l,u);let d=this.material.uniforms;d.tNormal.value=s.texture,d.tDepth.value=s.depthTexture,d.uTexel.value.set(1/Math.max(1,i),1/Math.max(1,a)),d.uRadius.value=Math.max(1,o.radius),d.uNormalThreshold.value=Math.max(.001,o.normalThreshold),d.uDepthThreshold.value=Math.max(.001,o.depthThreshold),d.uColor.value.copy(o.color),d.uOpacity.value=o.opacity,e.setViewport(0,0,i,a),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?.()})}};ca(),b();function ds(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function fs(e){let t=e??1;return t<0?0:t>1?1:t}var ps=[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`],ms=class{constructor(e){y(this,`host`,void 0),y(this,`lineShared`,void 0),y(this,`edgeMaterial`,void 0),y(this,`selectionEdgeMaterial`,void 0),y(this,`_edgeStyleUniforms`,void 0),y(this,`_selEdgeStyleUniforms`,void 0),y(this,`_hullStyleUniforms`,void 0),y(this,`_enabled`,!1),y(this,`_modes`,void 0),y(this,`_creaseLines`,null),y(this,`_nativeLines`,new Set),y(this,`_gpuEdge`,null),y(this,`_gpuEdgeColor`,new t.Color),this.host=e;let n=e.style;this._modes=Ai(!1),this.lineShared=Xo(),this._edgeStyleUniforms={uColor:{value:new t.Color(n.edgeColor)},uWidth:{value:Math.max(.1,n.edgeWidth??1.5)},uOpacity:{value:.6},uOffset:{value:n.edgeOffset??.15}},this.edgeMaterial=$o(this.lineShared,{},this._edgeStyleUniforms);let r=n;this._selEdgeStyleUniforms={uColor:{value:new t.Color(r.outlineColor??r.selectColor??`#ffffff`)},uWidth:{value:Math.max(.1,r.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:r.selectElevation??0}},this.selectionEdgeMaterial=$o(this.lineShared,{},this._selEdgeStyleUniforms),this._hullStyleUniforms={uColor:{value:new t.Color(n.edgeColor)},uWidth:{value:Math.max(0,n.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||hs(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))*fs(i.opacity)*a;if(o<=.004||(this._gpuEdge||(this._gpuEdge=new us),!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=ds(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 $o(this.lineShared,{},t?this._selEdgeStyleUniforms:this._edgeStyleUniforms,i)}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring),r=Ai(e),i=!ji(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!hs(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 n=await Ut(e,this.host.authenticate,`creases`);if(!n.ok)throw Error(`[s3m] 棱线缓存加载失败: ${n.status} ${e}`);let r=await n.arrayBuffer(),i=new Float32Array(r);if(i.length<6)return;let a=new t.BufferGeometry;a.setAttribute(`position`,new t.BufferAttribute(i,3));let o=this.host.style,s=new t.LineBasicMaterial({color:new t.Color(o.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,o.edgeOpacity??.6))*fs(o.opacity),depthWrite:!1}),c=new t.LineSegments(a,s);c.renderOrder=2,c.frustumCulled=!1,c.raycast=()=>{},this.clearCreases(),this._creaseLines=c,this.host.scene?.add(c),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))*fs(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)*fs(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 ps.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 n=e.userData;if(n.edges||n.nativeEdges||!e.geometry||this._shouldSkipAutoEdges(n,``))return;let r=e.geometry.getAttribute(`position`);if((e.geometry.index?.count??(r?r.count:0))>12e4)return;let i=ss(e.geometry,.005),a=this.host.style.edgeThreshold??55,o,s;if(this._modes.offset){let e=[];o=as(i,null,a,e),e.length>0&&(s=new Float32Array(e))}else{let e=new t.EdgesGeometry(i,a),n=e.getAttribute(`position`);o=n?n.array:null,e.dispose()}if(i.dispose(),!o||o.length<6)return;let c=.005,l=ts(e.geometry,c),u;if(l){let e=o.length/6;u=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;u[t]=l.get(ns(o[e],o[e+1],o[e+2],1/c))??-1}}let d=new t.Mesh(es(o,u,s),this.createPerMeshEdgeMaterial(e));d.renderOrder=2,d.frustumCulled=!1,d.raycast=()=>{},d.userData.isThickEdge=!0,n.edges=d,e.add(d)}_ensureHull(e){let n=e.userData;if(n.edgeHull||!e.geometry||e.isInstancedMesh||this._shouldSkipAutoEdges(n,``))return;let r=zi(this.host.uniforms,this.host.style.edgeHullWidth??.9,this._hullStyleUniforms,!0);r.uniforms.uSelWhole.value=1,r.uniforms.uSelBatch.value=-1;let i=ds(e);i?.userData?.uBatchTex&&(r.uniforms.uBatchTex.value=i.userData.uBatchTex.value,r.uniforms.uBatchTexWidth.value=i.userData.uBatchTexWidth.value,r.uniforms.uBatchTexActive.value=i.userData.uBatchTexActive.value);let a=new t.Mesh(e.geometry,r);a.renderOrder=2,a.frustumCulled=!1,a.raycast=()=>{},a.userData.isEdgeHull=!0,n.edgeHull=a,e.add(a)}_createSelectionEdgeMaterial(e){let t=ds(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 $o(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 hs(e){return e.isPoints===!0}Vt(),ca(),b();function gs(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 n=new t.Euler(e[0],e[1],e[2]),r=new t.Matrix4().makeRotationFromEuler(n).elements;return[r[0],r[4],r[8],r[1],r[5],r[9],r[2],r[6],r[10]]}if(e.length===4){let n=new t.Quaternion(e[0],e[1],e[2],e[3]),r=new t.Matrix4().makeRotationFromQuaternion(n).elements;return[r[0],r[4],r[8],r[1],r[5],r[9],r[2],r[6],r[10]]}}if(e instanceof t.Euler){let n=new t.Matrix4().makeRotationFromEuler(e).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}if(e instanceof t.Quaternion){let n=new t.Matrix4().makeRotationFromQuaternion(e).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}if(e instanceof t.Matrix3){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 t.Matrix4){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 _s(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 n=new t.Quaternion(e[0],e[1],e[2],e[3]),r=new t.Euler().setFromQuaternion(n);return[r.x,r.y,r.z]}}if(e instanceof t.Euler)return[e.x,e.y,e.z];if(e instanceof t.Quaternion){let n=new t.Euler().setFromQuaternion(e);return[n.x,n.y,n.z]}if(e instanceof t.Matrix3){let n=new t.Matrix4().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),r=new t.Euler().setFromRotationMatrix(n);return[r.x,r.y,r.z]}if(e instanceof t.Matrix4){let n=new t.Euler().setFromRotationMatrix(e);return[n.x,n.y,n.z]}return[0,0,0]}function vs(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function ys(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 bs(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 xs(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 Ss=class{constructor(e,t,n,r,i,a=()=>!1){y(this,`_getLayerFloorHeight`,void 0),y(this,`_triggerRepaint`,void 0),y(this,`_onStyleChanged`,void 0),y(this,`_getAllMeshes`,void 0),y(this,`_applyOverrideHook`,void 0),y(this,`_isLayerTransparent`,void 0),y(this,`featureStyles`,new Map),y(this,`thematicColors`,new Map),y(this,`thematicElevation`,new Map),y(this,`thematicField`,null),y(this,`elevationField`,null),y(this,`filter`,null),y(this,`fieldFilter`,null),y(this,`_meshBatchTextures`,new WeakMap),y(this,`_markedMeshes`,new Set),y(this,`_dirtyAll`,!1),y(this,`_flushScheduled`,!1),y(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,n,r){if(!n)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let i=e.smids?.length?[...new Set(e.smids)]:r;if(!i.length)return this.clearThematicColors(),{field:e.field,type:`discrete`,matched:0,missing:0,legend:[]};let a=await n.queryBySmids(i),o=[],s=[];for(let t of i){let n=a.get(t),r=n?n[e.field]:void 0;if(r==null||r===``)continue;let i=Number(r);Number.isFinite(i)?o.push({smid:t,val:i}):s.push({smid:t,val:String(r)})}let c=o.length>=s.length&&o.length>0,l=new Map,u=[],d=e.defaultColor??`#64748b`,f=e.nullColor??`#334155`;if(c){let n=o.map(e=>e.val),r=Math.min(...n),i=Math.max(...n)-r||1,a=(e.ramp??[`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`]).map(e=>new t.Color(e)),s=Math.max(2,e.stops??5);for(let e=0;e<s;e++){let t=e/s,n=(e+1)/s,o=ys(a,(t+n)/2),c=r+t*i,l=r+n*i;u.push({color:`#${o.getHexString()}`,label:`${xs(c)} ~ ${xs(l)}`,count:0,min:c,max:l})}for(let{smid:e,val:t}of o){let n=Math.min(1,Math.max(0,(t-r)/i)),a=Math.min(s-1,Math.floor(n*s)),o=u[a].color;l.set(e,o),u[a].count++}}else{let t=new Map;for(let{val:e}of s)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];u.push({color:o,label:t,count:a})}let a=new Map(u.map(e=>[e.label,e.color]));for(let{smid:e,val:t}of s)l.set(e,a.get(t)??d)}let p=0;for(let e of i)l.has(e)||(l.set(e,f),p++);return p>0&&u.push({color:f,label:`无数据 / 缺失`,count:p}),this.setThematicColors(l,e.field),{field:e.field,type:c?`continuous`:`discrete`,matched:i.length-p,missing:p,legend:u}}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?bs(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=H(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,n,r,i,a){let o=n;for(let t=0;t<o;t++){e[t*4+0]=-1,e[t*4+1]=-1,e[t*4+2]=-1,e[t*4+3]=0;let n=(o+t)*4;e[n+0]=0,e[n+1]=0,e[n+2]=0,e[n+3]=0;let r=(o*2+t)*4;e[r+0]=1,e[r+1]=0,e[r+2]=0,e[r+3]=0;let i=(o*3+t)*4;e[i+0]=0,e[i+1]=1,e[i+2]=0,e[i+3]=0;let a=(o*4+t)*4;e[a+0]=0,e[a+1]=0,e[a+2]=1,e[a+3]=0;let s=(o*5+t)*4;e[s+0]=-1,e[s+1]=0,e[s+2]=0,e[s+3]=0}let s=!1,c=new Set,l=new Map,u=new Map,d=new Map,f=new Map,p=new Map,m=new Map,h=new Map,g=new Map,_=this.filter,v=i.userData;for(let[e,t]of Object.entries(r)){let n=Number(e),r=H(t);if(r<0||r>=o)continue;g.set(r,(g.get(r)??0)+1);let s=!1;if(_&&(_.include&&_.include.length>0&&!_.include.includes(n)&&(s=!0),_.exclude&&_.exclude.length>0&&_.exclude.includes(n)&&(s=!0),_.predicate)){let{segments:e}=U(v.geoRef,r),t=zt({smid:n,box:Rt(i.geometry,e),triangles:0,floorHeight:this._getLayerFloorHeight()});_.predicate({...t,smid:n})||(s=!0)}if(s){c.add(r);continue}if(this.fieldFilter){let e=this.fieldFilter.matched.has(n);if(this.fieldFilter.mode===`keep`?!e:e){c.add(r);continue}}let y=a.get(n);if(y?.hidden){c.add(r);continue}let b=y?.opacity;if(b!=null){if(b<=0){c.add(r);continue}b<1&&!h.has(r)&&h.set(r,b)}let x=y?.color??this.thematicColors.get(n);x&&!l.has(r)&&l.set(r,x);let S=y?.elevation??this.thematicElevation.get(n);if(S!=null&&!u.has(r)&&u.set(r,S),y?.translation&&!d.has(r)&&d.set(r,y.translation),y?.rotation!=null&&!f.has(r)){let e=gs(y.rotation);e&&f.set(r,e)}y?.pivot&&!p.has(r)&&p.set(r,y.pivot),y?.gpuPath&&!m.has(r)&&m.set(r,y.gpuPath)}for(let t of c)e[t*4+3]=-1,s=!0;let y=new t.Color;for(let[t,n]of l)c.has(t)||(y.set(n),e[t*4+0]=y.r,e[t*4+1]=y.g,e[t*4+2]=y.b,s=!0);for(let[t,n]of u){if(c.has(t))continue;e[t*4+3]=n;let r=(o+t)*4;e[r+2]=n,s=!0}for(let[t,n]of d){if(c.has(t))continue;let r=(o+t)*4;e[r+0]=n[0],e[r+1]=n[1],e[r+2]=n[2]+(u.get(t)??0),s=!0}let b=!1;for(let[t,n]of h)c.has(t)||(e[(o+t)*4+3]=n,s=!0,b=!0);for(let[t,n]of f){if(c.has(t))continue;let r=p.get(t)??[0,0,0],i=(o*2+t)*4;e[i+0]=n[0],e[i+1]=n[1],e[i+2]=n[2],e[i+3]=r[0];let a=(o*3+t)*4;e[a+0]=n[3],e[a+1]=n[4],e[a+2]=n[5],e[a+3]=r[1];let l=(o*4+t)*4;e[l+0]=n[6],e[l+1]=n[7],e[l+2]=n[8],e[l+3]=r[2],s=!0}for(let[t,n]of p)f.has(t)||c.has(t)||(e[(o*2+t)*4+3]=n[0],e[(o*3+t)*4+3]=n[1],e[(o*4+t)*4+3]=n[2],s=!0);for(let[t,n]of m){if(c.has(t))continue;let r=(o*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,s=!0}let x=0;for(let[e,t]of g)t<2||(c.has(e)||l.has(e)||u.has(e)||f.has(e)||m.has(e))&&x++;return{hasActive:s,hasFade:b,conflicts:x}}applyOverridesToMesh(e){let n=vs(e);if(!n)return;let r=e.userData.geoRef?.pickInfo,i=this.featureStyles.size>0||this.thematicColors.size>0||this.thematicElevation.size>0,a=this.filter,o=this.fieldFilter!=null||a!=null&&((a.include?.length??0)>0||(a.exclude?.length??0)>0||a.predicate!=null);if(!i&&!o||!r||Object.keys(r).length===0){n.userData.uBatchTexActive&&(n.userData.uBatchTexActive.value=0),n.transparent&&!this._isLayerTransparent()&&Ri(n,!1);return}let s=0;for(let e of Object.values(r)){let t=H(e);t>s&&(s=t)}let c=Math.max(s+1,1),l=this._meshBatchTextures.get(e);if(!l||l.width<c){let r=new Float32Array(c*6*4),i=new t.DataTexture(r,c,6,t.RGBAFormat,t.FloatType);i.minFilter=t.NearestFilter,i.magFilter=t.NearestFilter,l={texture:i,data:r,width:c},this._meshBatchTextures.set(e,l),n.userData.uBatchTex.value=i,n.userData.uBatchTexWidth.value=c}let{data:u,texture:d}=l,{hasActive:f,hasFade:p,conflicts:m}=this._bakeStylesIntoBuffer(u,l.width,r,e,this.featureStyles);p&&!n.transparent?n.transparent=!0:!p&&n.transparent&&!this._isLayerTransparent()&&Ri(n,!1),m>0&&!this._batchConflictWarned&&(this._batchConflictWarned=!0,console.warn(`[s3m] 有 ${m} 个单体状态写不进独立的 batch(多个 SMID 共用同一个 batchId,\n S3M 的单体化粒度只到 batch,无法单独隐藏/改色其中一部分)。
|
|
1147
|
+
`,fs=class{constructor(){y(this,`rt`,null),y(this,`width`,0),y(this,`height`,0),y(this,`normalMaterial`,new t.MeshNormalMaterial),y(this,`quadScene`,new t.Scene),y(this,`quadCamera`,new t.OrthographicCamera(-1,1,1,-1,0,1)),y(this,`material`,void 0),this.material=new t.ShaderMaterial({glslVersion:t.GLSL3,uniforms:{tNormal:{value:null},tDepth:{value:null},uTexel:{value:new t.Vector2(1,1)},uRadius:{value:1.5},uNormalThreshold:{value:.55},uDepthThreshold:{value:.08},uColor:{value:new t.Color(`#334155`)},uOpacity:{value:.6}},vertexShader:us,fragmentShader:ds,transparent:!0,depthTest:!0,depthWrite:!1,side:t.DoubleSide,blending:t.NormalBlending});let e=new t.Mesh(new t.PlaneGeometry(2,2),this.material);e.frustumCulled=!1,e.raycast=()=>{},this.quadScene.add(e)}supported(e){return e.capabilities.isWebGL2===!0}ensureTarget(e,n){if(this.rt&&this.width===e&&this.height===n)return this.rt;this.disposeTarget();let r=new t.WebGLRenderTarget(Math.max(1,e),Math.max(1,n),{minFilter:t.NearestFilter,magFilter:t.NearestFilter,format:t.RGBAFormat,type:t.UnsignedByteType,depthBuffer:!0,stencilBuffer:!1,generateMipmaps:!1});return r.texture.generateMipmaps=!1,r.depthTexture=new t.DepthTexture(Math.max(1,e),Math.max(1,n),t.UnsignedIntType),this.rt=r,this.width=e,this.height=n,r}render(e,n,r,i,a,o){if(!this.supported(e)||i<=0||a<=0)return;let s=this.ensureTarget(i,a),c=n.overrideMaterial,l=e.getClearColor(new t.Color),u=e.getClearAlpha();n.overrideMaterial=this.normalMaterial,e.setRenderTarget(s),e.setClearColor(0,0),e.clear(!0,!0,!0),e.render(n,r),n.overrideMaterial=c,e.setRenderTarget(null),e.setClearColor(l,u);let d=this.material.uniforms;d.tNormal.value=s.texture,d.tDepth.value=s.depthTexture,d.uTexel.value.set(1/Math.max(1,i),1/Math.max(1,a)),d.uRadius.value=Math.max(1,o.radius),d.uNormalThreshold.value=Math.max(.001,o.normalThreshold),d.uDepthThreshold.value=Math.max(.001,o.depthThreshold),d.uColor.value.copy(o.color),d.uOpacity.value=o.opacity,e.setViewport(0,0,i,a),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?.()})}};ca(),b();function ps(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function ms(e){let t=e??1;return t<0?0:t>1?1:t}var hs=[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`],gs=class{constructor(e){y(this,`host`,void 0),y(this,`lineShared`,void 0),y(this,`edgeMaterial`,void 0),y(this,`selectionEdgeMaterial`,void 0),y(this,`_edgeStyleUniforms`,void 0),y(this,`_selEdgeStyleUniforms`,void 0),y(this,`_hullStyleUniforms`,void 0),y(this,`_enabled`,!1),y(this,`_modes`,void 0),y(this,`_creaseLines`,null),y(this,`_nativeLines`,new Set),y(this,`_gpuEdge`,null),y(this,`_gpuEdgeColor`,new t.Color),this.host=e;let n=e.style;this._modes=Ai(!1),this.lineShared=Qo(),this._edgeStyleUniforms={uColor:{value:new t.Color(n.edgeColor)},uWidth:{value:Math.max(.1,n.edgeWidth??1.5)},uOpacity:{value:.6},uOffset:{value:n.edgeOffset??.15}},this.edgeMaterial=ts(this.lineShared,{},this._edgeStyleUniforms);let r=n;this._selEdgeStyleUniforms={uColor:{value:new t.Color(r.outlineColor??r.selectColor??`#ffffff`)},uWidth:{value:Math.max(.1,r.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:r.selectElevation??0}},this.selectionEdgeMaterial=ts(this.lineShared,{},this._selEdgeStyleUniforms),this._hullStyleUniforms={uColor:{value:new t.Color(n.edgeColor)},uWidth:{value:Math.max(0,n.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||_s(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))*ms(i.opacity)*a;if(o<=.004||(this._gpuEdge||(this._gpuEdge=new fs),!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=ps(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 ts(this.lineShared,{},t?this._selEdgeStyleUniforms:this._edgeStyleUniforms,i)}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring),r=Ai(e),i=!ji(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!_s(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 n=await Ut(e,this.host.authenticate,`creases`);if(!n.ok)throw Error(`[s3m] 棱线缓存加载失败: ${n.status} ${e}`);let r=await n.arrayBuffer(),i=new Float32Array(r);if(i.length<6)return;let a=new t.BufferGeometry;a.setAttribute(`position`,new t.BufferAttribute(i,3));let o=this.host.style,s=new t.LineBasicMaterial({color:new t.Color(o.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,o.edgeOpacity??.6))*ms(o.opacity),depthWrite:!1}),c=new t.LineSegments(a,s);c.renderOrder=2,c.frustumCulled=!1,c.raycast=()=>{},this.clearCreases(),this._creaseLines=c,this.host.scene?.add(c),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))*ms(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)*ms(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 hs.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 n=e.userData;if(n.edges||n.nativeEdges||!e.geometry||this._shouldSkipAutoEdges(n,``))return;let r=e.geometry.getAttribute(`position`);if((e.geometry.index?.count??(r?r.count:0))>12e4)return;let i=ls(e.geometry,.005),a=this.host.style.edgeThreshold??55,o,s;if(this._modes.offset){let e=[];o=ss(i,null,a,e),e.length>0&&(s=new Float32Array(e))}else{let e=new t.EdgesGeometry(i,a),n=e.getAttribute(`position`);o=n?n.array:null,e.dispose()}if(i.dispose(),!o||o.length<6)return;let c=.005,l=rs(e.geometry,c),u;if(l){let e=o.length/6;u=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;u[t]=l.get(is(o[e],o[e+1],o[e+2],1/c))??-1}}let d=new t.Mesh(ns(o,u,s),this.createPerMeshEdgeMaterial(e));d.renderOrder=2,d.frustumCulled=!1,d.raycast=()=>{},d.userData.isThickEdge=!0,n.edges=d,e.add(d)}_ensureHull(e){let n=e.userData;if(n.edgeHull||!e.geometry||e.isInstancedMesh||this._shouldSkipAutoEdges(n,``))return;let r=zi(this.host.uniforms,this.host.style.edgeHullWidth??.9,this._hullStyleUniforms,!0);r.uniforms.uSelWhole.value=1,r.uniforms.uSelBatch.value=-1;let i=ps(e);i?.userData?.uBatchTex&&(r.uniforms.uBatchTex.value=i.userData.uBatchTex.value,r.uniforms.uBatchTexWidth.value=i.userData.uBatchTexWidth.value,r.uniforms.uBatchTexActive.value=i.userData.uBatchTexActive.value);let a=new t.Mesh(e.geometry,r);a.renderOrder=2,a.frustumCulled=!1,a.raycast=()=>{},a.userData.isEdgeHull=!0,n.edgeHull=a,e.add(a)}_createSelectionEdgeMaterial(e){let t=ps(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 ts(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 _s(e){return e.isPoints===!0}Vt(),ca(),b();function vs(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 n=new t.Euler(e[0],e[1],e[2]),r=new t.Matrix4().makeRotationFromEuler(n).elements;return[r[0],r[4],r[8],r[1],r[5],r[9],r[2],r[6],r[10]]}if(e.length===4){let n=new t.Quaternion(e[0],e[1],e[2],e[3]),r=new t.Matrix4().makeRotationFromQuaternion(n).elements;return[r[0],r[4],r[8],r[1],r[5],r[9],r[2],r[6],r[10]]}}if(e instanceof t.Euler){let n=new t.Matrix4().makeRotationFromEuler(e).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}if(e instanceof t.Quaternion){let n=new t.Matrix4().makeRotationFromQuaternion(e).elements;return[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]]}if(e instanceof t.Matrix3){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 t.Matrix4){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 ys(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 n=new t.Quaternion(e[0],e[1],e[2],e[3]),r=new t.Euler().setFromQuaternion(n);return[r.x,r.y,r.z]}}if(e instanceof t.Euler)return[e.x,e.y,e.z];if(e instanceof t.Quaternion){let n=new t.Euler().setFromQuaternion(e);return[n.x,n.y,n.z]}if(e instanceof t.Matrix3){let n=new t.Matrix4().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),r=new t.Euler().setFromRotationMatrix(n);return[r.x,r.y,r.z]}if(e instanceof t.Matrix4){let n=new t.Euler().setFromRotationMatrix(e);return[n.x,n.y,n.z]}return[0,0,0]}function bs(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function xs(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 Ss(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 Cs(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 ws=class{constructor(e,t,n,r,i,a=()=>!1){y(this,`_getLayerFloorHeight`,void 0),y(this,`_triggerRepaint`,void 0),y(this,`_onStyleChanged`,void 0),y(this,`_getAllMeshes`,void 0),y(this,`_applyOverrideHook`,void 0),y(this,`_isLayerTransparent`,void 0),y(this,`featureStyles`,new Map),y(this,`thematicColors`,new Map),y(this,`thematicElevation`,new Map),y(this,`thematicField`,null),y(this,`elevationField`,null),y(this,`filter`,null),y(this,`fieldFilter`,null),y(this,`_meshBatchTextures`,new WeakMap),y(this,`_markedMeshes`,new Set),y(this,`_dirtyAll`,!1),y(this,`_flushScheduled`,!1),y(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,n,r){if(!n)throw Error(`[s3m] 未配置业务属性数据源,先调用 setAttributeSource() 或构造时传 attributes`);let i=e.smids?.length?[...new Set(e.smids)]:r;if(!i.length)return this.clearThematicColors(),{field:e.field,type:`discrete`,matched:0,missing:0,legend:[]};let a=await n.queryBySmids(i),o=[],s=[];for(let t of i){let n=a.get(t),r=n?n[e.field]:void 0;if(r==null||r===``)continue;let i=Number(r);Number.isFinite(i)?o.push({smid:t,val:i}):s.push({smid:t,val:String(r)})}let c=o.length>=s.length&&o.length>0,l=new Map,u=[],d=e.defaultColor??`#64748b`,f=e.nullColor??`#334155`;if(c){let n=o.map(e=>e.val),r=Math.min(...n),i=Math.max(...n)-r||1,a=(e.ramp??[`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`]).map(e=>new t.Color(e)),s=Math.max(2,e.stops??5);for(let e=0;e<s;e++){let t=e/s,n=(e+1)/s,o=xs(a,(t+n)/2),c=r+t*i,l=r+n*i;u.push({color:`#${o.getHexString()}`,label:`${Cs(c)} ~ ${Cs(l)}`,count:0,min:c,max:l})}for(let{smid:e,val:t}of o){let n=Math.min(1,Math.max(0,(t-r)/i)),a=Math.min(s-1,Math.floor(n*s)),o=u[a].color;l.set(e,o),u[a].count++}}else{let t=new Map;for(let{val:e}of s)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];u.push({color:o,label:t,count:a})}let a=new Map(u.map(e=>[e.label,e.color]));for(let{smid:e,val:t}of s)l.set(e,a.get(t)??d)}let p=0;for(let e of i)l.has(e)||(l.set(e,f),p++);return p>0&&u.push({color:f,label:`无数据 / 缺失`,count:p}),this.setThematicColors(l,e.field),{field:e.field,type:c?`continuous`:`discrete`,matched:i.length-p,missing:p,legend:u}}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?Ss(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=H(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,n,r,i,a){let o=n;for(let t=0;t<o;t++){e[t*4+0]=-1,e[t*4+1]=-1,e[t*4+2]=-1,e[t*4+3]=0;let n=(o+t)*4;e[n+0]=0,e[n+1]=0,e[n+2]=0,e[n+3]=0;let r=(o*2+t)*4;e[r+0]=1,e[r+1]=0,e[r+2]=0,e[r+3]=0;let i=(o*3+t)*4;e[i+0]=0,e[i+1]=1,e[i+2]=0,e[i+3]=0;let a=(o*4+t)*4;e[a+0]=0,e[a+1]=0,e[a+2]=1,e[a+3]=0;let s=(o*5+t)*4;e[s+0]=-1,e[s+1]=0,e[s+2]=0,e[s+3]=0}let s=!1,c=new Set,l=new Map,u=new Map,d=new Map,f=new Map,p=new Map,m=new Map,h=new Map,g=new Map,_=this.filter,v=i.userData;for(let[e,t]of Object.entries(r)){let n=Number(e),r=H(t);if(r<0||r>=o)continue;g.set(r,(g.get(r)??0)+1);let s=!1;if(_&&(_.include&&_.include.length>0&&!_.include.includes(n)&&(s=!0),_.exclude&&_.exclude.length>0&&_.exclude.includes(n)&&(s=!0),_.predicate)){let{segments:e}=U(v.geoRef,r),t=zt({smid:n,box:Rt(i.geometry,e),triangles:0,floorHeight:this._getLayerFloorHeight()});_.predicate({...t,smid:n})||(s=!0)}if(s){c.add(r);continue}if(this.fieldFilter){let e=this.fieldFilter.matched.has(n);if(this.fieldFilter.mode===`keep`?!e:e){c.add(r);continue}}let y=a.get(n);if(y?.hidden){c.add(r);continue}let b=y?.opacity;if(b!=null){if(b<=0){c.add(r);continue}b<1&&!h.has(r)&&h.set(r,b)}let x=y?.color??this.thematicColors.get(n);x&&!l.has(r)&&l.set(r,x);let S=y?.elevation??this.thematicElevation.get(n);if(S!=null&&!u.has(r)&&u.set(r,S),y?.translation&&!d.has(r)&&d.set(r,y.translation),y?.rotation!=null&&!f.has(r)){let e=vs(y.rotation);e&&f.set(r,e)}y?.pivot&&!p.has(r)&&p.set(r,y.pivot),y?.gpuPath&&!m.has(r)&&m.set(r,y.gpuPath)}for(let t of c)e[t*4+3]=-1,s=!0;let y=new t.Color;for(let[t,n]of l)c.has(t)||(y.set(n),e[t*4+0]=y.r,e[t*4+1]=y.g,e[t*4+2]=y.b,s=!0);for(let[t,n]of u){if(c.has(t))continue;e[t*4+3]=n;let r=(o+t)*4;e[r+2]=n,s=!0}for(let[t,n]of d){if(c.has(t))continue;let r=(o+t)*4;e[r+0]=n[0],e[r+1]=n[1],e[r+2]=n[2]+(u.get(t)??0),s=!0}let b=!1;for(let[t,n]of h)c.has(t)||(e[(o+t)*4+3]=n,s=!0,b=!0);for(let[t,n]of f){if(c.has(t))continue;let r=p.get(t)??[0,0,0],i=(o*2+t)*4;e[i+0]=n[0],e[i+1]=n[1],e[i+2]=n[2],e[i+3]=r[0];let a=(o*3+t)*4;e[a+0]=n[3],e[a+1]=n[4],e[a+2]=n[5],e[a+3]=r[1];let l=(o*4+t)*4;e[l+0]=n[6],e[l+1]=n[7],e[l+2]=n[8],e[l+3]=r[2],s=!0}for(let[t,n]of p)f.has(t)||c.has(t)||(e[(o*2+t)*4+3]=n[0],e[(o*3+t)*4+3]=n[1],e[(o*4+t)*4+3]=n[2],s=!0);for(let[t,n]of m){if(c.has(t))continue;let r=(o*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,s=!0}let x=0;for(let[e,t]of g)t<2||(c.has(e)||l.has(e)||u.has(e)||f.has(e)||m.has(e))&&x++;return{hasActive:s,hasFade:b,conflicts:x}}applyOverridesToMesh(e){let n=bs(e);if(!n)return;let r=e.userData.geoRef?.pickInfo,i=this.featureStyles.size>0||this.thematicColors.size>0||this.thematicElevation.size>0,a=this.filter,o=this.fieldFilter!=null||a!=null&&((a.include?.length??0)>0||(a.exclude?.length??0)>0||a.predicate!=null);if(!i&&!o||!r||Object.keys(r).length===0){n.userData.uBatchTexActive&&(n.userData.uBatchTexActive.value=0),n.transparent&&!this._isLayerTransparent()&&Ri(n,!1);return}let s=0;for(let e of Object.values(r)){let t=H(e);t>s&&(s=t)}let c=Math.max(s+1,1),l=this._meshBatchTextures.get(e);if(!l||l.width<c){let r=new Float32Array(c*6*4),i=new t.DataTexture(r,c,6,t.RGBAFormat,t.FloatType);i.minFilter=t.NearestFilter,i.magFilter=t.NearestFilter,l={texture:i,data:r,width:c},this._meshBatchTextures.set(e,l),n.userData.uBatchTex.value=i,n.userData.uBatchTexWidth.value=c}let{data:u,texture:d}=l,{hasActive:f,hasFade:p,conflicts:m}=this._bakeStylesIntoBuffer(u,l.width,r,e,this.featureStyles);p&&!n.transparent?n.transparent=!0:!p&&n.transparent&&!this._isLayerTransparent()&&Ri(n,!1),m>0&&!this._batchConflictWarned&&(this._batchConflictWarned=!0,console.warn(`[s3m] 有 ${m} 个单体状态写不进独立的 batch(多个 SMID 共用同一个 batchId,\n S3M 的单体化粒度只到 batch,无法单独隐藏/改色其中一部分)。
|
|
1148
1148
|
当前规则:任一 SMID 需要隐藏则整批隐藏,颜色 / 抬高取首个。
|
|
1149
|
-
用 layer.auditBatches() 可以列出具体是哪些 SMID 共用了 batchId。`)),d.needsUpdate=!0,n.userData.uBatchTexActive&&(n.userData.uBatchTexActive.value=+!!f)}prepareCrossFade(e,n){for(let r of n){let n=vs(r);if(!n)continue;let i=r.userData.geoRef?.pickInfo;if(!i||Object.keys(i).length===0)continue;let a=0;for(let e of Object.values(i)){let t=H(e);t>a&&(a=t)}let o=Math.max(a+1,1),s=this._meshBatchTextures.get(r);if(!s||s.width<o){let e=new Float32Array(o*6*4),i=new t.DataTexture(e,o,6,t.RGBAFormat,t.FloatType);i.minFilter=t.NearestFilter,i.magFilter=t.NearestFilter,s={texture:i,data:e,width:o},this._meshBatchTextures.set(r,s),n.userData.uBatchTex.value=i,n.userData.uBatchTexWidth.value=o}if(!s.texture2||!s.data2||s.data2.length<s.width*6*4){let e=new Float32Array(s.width*6*4),n=new t.DataTexture(e,s.width,6,t.RGBAFormat,t.FloatType);n.minFilter=t.NearestFilter,n.magFilter=t.NearestFilter,s.data2=e,s.texture2=n}this._bakeStylesIntoBuffer(s.data,s.width,i,r,this.featureStyles),s.texture.needsUpdate=!0;let c=this._bakeStylesIntoBuffer(s.data2,s.width,i,r,e);s.texture2.needsUpdate=!0,n.userData.uBatchTex2.value=s.texture2,n.userData.uBatchTexActive.value=1,c.hasFade&&!n.transparent&&(n.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=vs(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=vs(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)}};Vt(),Xa(),b();var Cs=65534,ws=class{constructor(e){y(this,`host`,void 0),y(this,`pickables`,new Map),y(this,`_pickSeq`,0),y(this,`_freePickIds`,[]),this.host=e}allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>Cs){for(let e=0;e<=Cs;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,n){if(!this.host.camera||!this.host.canvas)return null;let r=this.host.canvas,i=r.clientWidth||r.width,a=r.clientHeight||r.height;if(!i||!a)return null;let o=e/i*2-1,s=-(n/a)*2+1,c=new t.Vector3(o,s,-1).unproject(this.host.camera),l=new t.Vector3(o,s,1).unproject(this.host.camera).clone().sub(c).normalize();return new t.Ray(c,l)}intersectMeshAtRay(e,n,r){let i=new t.Raycaster;i.ray.copy(n);let a=i.intersectObject(e,!1);if(!a.length)return null;if(r!=null){let e=a.find(e=>e.instanceId===r);return e?e.point:a[0].point}return a[0].point}buildPickResult(e,n,r,i){let a=n.mesh.userData;if(a.isGaussianSplat)return this.buildSplatPickResult(e,n,r,i);let o=null,s=e.batchId,c=e.instanceIndex,l=a.geoRef,u=[];if(c!=null){let e=this.instanceFeature(n.mesh,l,c);if(!e)return null;o=e.smid,s=e.batchId}else{l=a.geoByBatchId?.get(e.batchId)??a.geoRef;let t=U(l,e.batchId);o=t.smid,u=t.segments}if(this.host.isFeatureHidden(o,s))return null;let d=null,f=0;if(c!=null)d=this.instanceBox(n.mesh,c),f=n.mesh.geometry.index?Math.round(n.mesh.geometry.index.count/3):0;else if(o!=null&&this.host.smidMeshes.has(o)){let e=this.host.smidMeshes.get(o),t=1/0,n=1/0,r=1/0,i=-1/0,a=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,d=u?.[o]??u?.[String(o)],p=d?H(d):-1,m=d?.segments??(p>=0?U(e.geoRef,p).segments:[]),h=Rt(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>a&&(a=h.maxY),h.maxZ>s&&(s=h.maxZ),c+=h.count,f+=h.triangles)}c>0&&(d={minX:t,minY:n,minZ:r,maxX:i,maxY:a,maxZ:s,count:c,triangles:f})}if(!d&&(d=Rt(n.mesh.geometry,u),!d&&n.mesh.geometry)){n.mesh.geometry.boundingBox||n.mesh.geometry.computeBoundingBox();let e=n.mesh.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})}let p=n.mesh.geometry,m=f>0?f:p.index?Math.round(p.index.count/3):0,h=zt({smid:o,box:d,triangles:m,floorHeight:this.host.style.floorHeight}),g=null;if(d&&this.host.sceneAnchor){let e=new t.Vector3((d.minX+d.maxX)/2,(d.minY+d.maxY)/2,(d.minZ+d.maxZ)/2);e.applyMatrix4(n.mesh.matrixWorld);let r=this.host.sceneAnchor.meterInMercator;g=this.host.lngLatFromWorld(e.x*r+this.host.sceneAnchor.x,-e.y*r+this.host.sceneAnchor.y)}let _=r??null;!_&&i&&(_=this.intersectMeshAtRay(n.mesh,i,c));let v=null,y=null,b=null;if(_&&this.host.sceneAnchor){let e=o==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(o),n=e.translation,r=e.elevation,i=_.clone();if(e.rotation){let n=gs(e.rotation);if(n){let r=new t.Matrix3().set(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8]),a=e.pivot?new t.Vector3(e.pivot[0],e.pivot[1],e.pivot[2]):new t.Vector3(0,0,0);i.sub(a).applyMatrix3(r).add(a)}}n?i.add(new t.Vector3(n[0],n[1],n[2])):r&&(i.z+=r),v=[i.x,i.y,i.z];let a=this.host.sceneAnchor.meterInMercator;y=this.host.lngLatFromWorld(i.x*a+this.host.sceneAnchor.x,-i.y*a+this.host.sceneAnchor.y),b=i.z+(this.host.sceneAnchor.altitude??0)}else g&&d&&this.host.sceneAnchor&&(y=g,b=(d.minZ+d.maxZ)/2+(this.host.sceneAnchor.altitude??0));return{datasetId:n.datasetId,datasetName:this.host.datasets.get(n.datasetId)?.name??n.datasetId,objectId:e.objectId,batchId:s,instanceIndex:c,skeletonName:n.skeletonName,centerLngLat:g,point:v,lngLat:y,altitude:b,...h,mesh:n.mesh}}buildSplatPickResult(e,n,r,i){let a=this.host.sceneAnchor;if(!a)return null;let o=n.mesh,s=r??null;!s&&i&&(s=this.intersectMeshAtRay(o,i));let c=Ga(o.geometry),l=c?{minX:c.minX,minY:c.minY,minZ:c.minZ,maxX:c.maxX,maxY:c.maxY,maxZ:c.maxZ,count:c.count,triangles:0}:null,u=zt({smid:null,box:l,triangles:0,floorHeight:this.host.style.floorHeight}),d=a.meterInMercator,f=null,p=null,m=null,h=null;if(s)f=[s.x,s.y,s.z],p=this.host.lngLatFromWorld(s.x*d+a.x,-s.y*d+a.y),m=s.z+(a.altitude??0),h=p;else if(l){let e=new t.Vector3((l.minX+l.maxX)/2,(l.minY+l.maxY)/2,(l.minZ+l.maxZ)/2).applyMatrix4(o.matrixWorld);h=this.host.lngLatFromWorld(e.x*d+a.x,-e.y*d+a.y),m=e.z+(a.altitude??0)}return{datasetId:n.datasetId,datasetName:this.host.datasets.get(n.datasetId)?.name??n.datasetId,objectId:e.objectId,batchId:-1,instanceIndex:void 0,skeletonName:n.skeletonName,centerLngLat:h,point:f,lngLat:p,altitude:m,...u,mesh:o}}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,n){if(!this.host.camera||!this.host.sceneAnchor)return null;let r=this.pick(e,n);if(r?.point&&r?.lngLat&&r.altitude!=null)return{lngLat:r.lngLat,altitude:r.altitude,point:r.point};let i=this.getRayAt(e,n);if(!i)return null;let a=new t.Plane(new t.Vector3(0,0,1),0),o=new t.Vector3,s=i.intersectPlane(a,o);if(s){let e=this.host.sceneAnchor.meterInMercator;return{lngLat:this.host.lngLatFromWorld(s.x*e+this.host.sceneAnchor.x,-s.y*e+this.host.sceneAnchor.y),altitude:s.z+(this.host.sceneAnchor.altitude??0),point:[s.x,s.y,s.z]}}return null}drillPick(e,n,r=10){if(!this.host.sceneAnchor||!this.host.camera)return[];let i=this.getRayAt(e,n);if(!i)return[];let a=new t.Raycaster;a.ray.copy(i);let o=[...this.pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),s=a.intersectObjects(o,!1);if(!s.length)return[];let c=[],l=new Set,u=new Set;for(let e of s){if(c.length>=r)break;let t=e.object,n=t.userData;if(n.pickId==null)continue;let i=this.pickables.get(n.pickId);if(!i)continue;let a=null,o=-1,s=e.instanceId;if(s!=null){let e=this.instanceFeature(t,n.geoRef,s);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let r=t.geometry.attributes.aBatchId;if(r){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(r.getX(i)),a=U(n.geoByBatchId?.get(o)??n.geoRef,o).smid}}if(a!=null){if(l.has(a))continue;l.add(a)}else{let e=`${n.pickId}:${o}:${s??-1}`;if(u.has(e))continue;u.add(e)}if(this.host.isFeatureHidden(a,o))continue;let d={objectId:n.pickId,batchId:o,instanceIndex:s},f=this.buildPickResult(d,i,e.point);f&&c.push(f)}return c}getFeatureBounds(e){if(!this.host.sceneAnchor)return null;let n=1/0,r=-1/0,i=1/0,a=-1/0,o=!1;for(let s of this.pickables.values()){let c=s.mesh,l=c.userData,u=l.geoRef,d=u?.pickInfo;if(!d)continue;let f=null;if(c.isInstancedMesh){let t=l.instanceLookup;t||(t=Lt(d),l.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){f=this.instanceBox(c,n);break}}else{let t=d,n=t[e]??t[String(e)];if(n){let e=U(u,H(n));if(f=Rt(c.geometry,e.segments),!f&&c.geometry){c.geometry.boundingBox||c.geometry.computeBoundingBox();let e=c.geometry.boundingBox;e&&(f={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(f){o=!0;let s=[new t.Vector3(f.minX,f.minY,f.minZ),new t.Vector3(f.maxX,f.minY,f.minZ),new t.Vector3(f.minX,f.maxY,f.minZ),new t.Vector3(f.maxX,f.maxY,f.minZ),new t.Vector3(f.minX,f.minY,f.maxZ),new t.Vector3(f.maxX,f.minY,f.maxZ),new t.Vector3(f.minX,f.maxY,f.maxZ),new t.Vector3(f.maxX,f.maxY,f.maxZ)],l=e==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(e),u=l.translation,d=l.elevation,p=l.rotation?gs(l.rotation):null,m=null,h=null;p&&(m=new t.Matrix3().set(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]),h=l.pivot?new t.Vector3(l.pivot[0],l.pivot[1],l.pivot[2]):new t.Vector3(0,0,0));let g=e==null?null:this.host.gpuPathPoseAt(e),_=null;if(g&&g.yaw!==0){let e=Math.cos(g.yaw),n=Math.sin(g.yaw);_=new t.Matrix3().set(e,-n,0,n,e,0,0,0,1)}for(let e of s){if(m&&h&&e.sub(h).applyMatrix3(m).add(h),_){let n=h??new t.Vector3(0,0,0);e.sub(n).applyMatrix3(_).add(n)}u?e.add(new t.Vector3(u[0],u[1],u[2])):d&&(e.z+=d),g&&e.add(new t.Vector3(g.pos[0],g.pos[1],g.pos[2])),e.applyMatrix4(c.matrixWorld);let o=this.host.sceneAnchor.meterInMercator,[s,l]=this.host.lngLatFromWorld(e.x*o+this.host.sceneAnchor.x,-e.y*o+this.host.sceneAnchor.y);s<n&&(n=s),s>r&&(r=s),l<i&&(i=l),l>a&&(a=l)}}}return o?[[n,i],[r,a]]:null}instanceFeature(e,t,n){let r=e.userData;return r.instanceLookup||(r.instanceLookup=Lt(t?.pickInfo)),r.instanceLookup.get(n)??null}instanceBox(e,n){let r=e;if(!r.isInstancedMesh)return null;let i=e.geometry;i.boundingBox||i.computeBoundingBox();let a=i.boundingBox;if(!a)return null;let o=new t.Matrix4;r.getMatrixAt(n,o);let s=a.clone().applyMatrix4(o);return{minX:s.min.x,minY:s.min.y,minZ:s.min.z,maxX:s.max.x,maxY:s.max.y,maxZ:s.max.z,count:i.getAttribute(`position`)?.count??0,triangles:i.index?Math.round(i.index.count/3):0}}};Vt(),b();function Ts(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function Es(e){let t=e??1;return t<0?0:t>1?1:t}function Ds(e){return e.isPoints===!0}var Os=class{constructor(e){y(this,`host`,void 0),y(this,`selection`,null),y(this,`selectedMeshes`,[]),y(this,`_outlineMeshes`,[]),y(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(Ds(e)){this.host.applyPointCloudStyle(e,!1);continue}let t=Ts(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=Ts(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?H(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)Ds(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=>!Ds(e));t.length&&((this.host.style.outlineStyle??`edges`)===`edges`?this.addSelectionEdges(e,t):this.addSelectionHull(e,t))}this.host.requestRepaint()}addSelectionEdges(e,n){this.syncStyle();for(let r of n){let n=r.userData,i=n.geoRef,a=[],o=-1;if(r===e.mesh&&e.instanceIndex!=null){a=[{vertexOffset:0,vertexCount:r.geometry.getAttribute(`position`)?.count??0}];let t=i?.pickInfo,n=t?.[e.smid??``]??t?.[String(e.smid)];o=n?H(n):-1}else if(e.smid!=null){let t=i?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],r=n?H(n):-1;o=r,a=n?.segments??(r>=0?U(i,r).segments:[])}else r===e.mesh&&(a=U(n.geoByBatchId?.get(e.batchId)??i,e.batchId).segments,o=e.batchId);let s=as(r.geometry,a);if(s&&s.length>0){let n=o>=0?new Float32Array(s.length/6).fill(o):void 0,i=new t.Mesh(es(s,n),this.host.createSelectionEdgeMaterial(r));i.renderOrder=4,i.frustumCulled=!1,i.raycast=()=>{},i.userData.isSelectionEdge=!0,r===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(i,e),r.add(i),this._selectionEdgeMeshes.push(i)}}this._selectionEdgeMeshes.length===0&&this.addSelectionHull(e,n)}applyInstanceTransform(e,n){let r=n.mesh;if(n.instanceIndex==null||!r.isInstancedMesh)return;let i=new t.Matrix4;r.getMatrixAt(n.instanceIndex,i),i.decompose(e.position,e.quaternion,e.scale)}addSelectionHull(e,n){let r=e.instanceIndex!=null;this.host.outlineMaterial.uniforms.uSelBatch.value=r?-1:e.batchId,this.host.outlineMaterial.uniforms.uSelWhole.value=r||e.batchId<0?1:0,this.host.outlineMaterial.uniforms.uElevation.value=r?this.selectionElevation(e):this.host.style.selectElevation??0;for(let r of n){let n=Ts(r);n?.userData?.uBatchTex&&(this.host.outlineMaterial.uniforms.uBatchTex.value=n.userData.uBatchTex.value,this.host.outlineMaterial.uniforms.uBatchTexWidth.value=n.userData.uBatchTexWidth.value,this.host.outlineMaterial.uniforms.uBatchTexActive.value=n.userData.uBatchTexActive.value);let i=new t.Mesh(r.geometry,this.host.outlineMaterial);i.renderOrder=3,i.frustumCulled=!1,i.raycast=()=>{},r===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(i,e),r.add(i),this._outlineMeshes.push(i)}}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=Es(e.opacity),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?Ts(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,n){if(!n.point)return!1;let r=e.geometry;if(!r||(r.boundingBox||r.computeBoundingBox(),!r.boundingBox))return!1;let i=new t.Vector3(n.point[0],n.point[1],n.point[2]);e.updateWorldMatrix(!0,!1);let a=e.matrixWorld.clone().invert(),o=i.applyMatrix4(a);return r.boundingBox.clone().expandByScalar(.5).containsPoint(o)}replayOnto(e){let t=this.selection;if(!t)return;let n=Ts(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?H(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),Ds(e)&&this.host.applyPointCloudStyle(e,!0),this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers}};ca();var ks=2;function As(e){return e===Q.SOLID?`solid`:e===Q.HEIGHT?`height`:`vertex`}var js=`
|
|
1149
|
+
用 layer.auditBatches() 可以列出具体是哪些 SMID 共用了 batchId。`)),d.needsUpdate=!0,n.userData.uBatchTexActive&&(n.userData.uBatchTexActive.value=+!!f)}prepareCrossFade(e,n){for(let r of n){let n=bs(r);if(!n)continue;let i=r.userData.geoRef?.pickInfo;if(!i||Object.keys(i).length===0)continue;let a=0;for(let e of Object.values(i)){let t=H(e);t>a&&(a=t)}let o=Math.max(a+1,1),s=this._meshBatchTextures.get(r);if(!s||s.width<o){let e=new Float32Array(o*6*4),i=new t.DataTexture(e,o,6,t.RGBAFormat,t.FloatType);i.minFilter=t.NearestFilter,i.magFilter=t.NearestFilter,s={texture:i,data:e,width:o},this._meshBatchTextures.set(r,s),n.userData.uBatchTex.value=i,n.userData.uBatchTexWidth.value=o}if(!s.texture2||!s.data2||s.data2.length<s.width*6*4){let e=new Float32Array(s.width*6*4),n=new t.DataTexture(e,s.width,6,t.RGBAFormat,t.FloatType);n.minFilter=t.NearestFilter,n.magFilter=t.NearestFilter,s.data2=e,s.texture2=n}this._bakeStylesIntoBuffer(s.data,s.width,i,r,this.featureStyles),s.texture.needsUpdate=!0;let c=this._bakeStylesIntoBuffer(s.data2,s.width,i,r,e);s.texture2.needsUpdate=!0,n.userData.uBatchTex2.value=s.texture2,n.userData.uBatchTexActive.value=1,c.hasFade&&!n.transparent&&(n.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=bs(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=bs(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)}};Vt(),Xa(),b();var Ts=65534,Es=class{constructor(e){y(this,`host`,void 0),y(this,`pickables`,new Map),y(this,`_pickSeq`,0),y(this,`_freePickIds`,[]),this.host=e}allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>Ts){for(let e=0;e<=Ts;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,n){if(!this.host.camera||!this.host.canvas)return null;let r=this.host.canvas,i=r.clientWidth||r.width,a=r.clientHeight||r.height;if(!i||!a)return null;let o=e/i*2-1,s=-(n/a)*2+1,c=new t.Vector3(o,s,-1).unproject(this.host.camera),l=new t.Vector3(o,s,1).unproject(this.host.camera).clone().sub(c).normalize();return new t.Ray(c,l)}intersectMeshAtRay(e,n,r){let i=new t.Raycaster;i.ray.copy(n);let a=i.intersectObject(e,!1);if(!a.length)return null;if(r!=null){let e=a.find(e=>e.instanceId===r);return e?e.point:a[0].point}return a[0].point}buildPickResult(e,n,r,i){let a=n.mesh.userData;if(a.isGaussianSplat)return this.buildSplatPickResult(e,n,r,i);let o=null,s=e.batchId,c=e.instanceIndex,l=a.geoRef,u=[];if(c!=null){let e=this.instanceFeature(n.mesh,l,c);if(!e)return null;o=e.smid,s=e.batchId}else{l=a.geoByBatchId?.get(e.batchId)??a.geoRef;let t=U(l,e.batchId);o=t.smid,u=t.segments}if(this.host.isFeatureHidden(o,s))return null;let d=null,f=0;if(c!=null)d=this.instanceBox(n.mesh,c),f=n.mesh.geometry.index?Math.round(n.mesh.geometry.index.count/3):0;else if(o!=null&&this.host.smidMeshes.has(o)){let e=this.host.smidMeshes.get(o),t=1/0,n=1/0,r=1/0,i=-1/0,a=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,d=u?.[o]??u?.[String(o)],p=d?H(d):-1,m=d?.segments??(p>=0?U(e.geoRef,p).segments:[]),h=Rt(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>a&&(a=h.maxY),h.maxZ>s&&(s=h.maxZ),c+=h.count,f+=h.triangles)}c>0&&(d={minX:t,minY:n,minZ:r,maxX:i,maxY:a,maxZ:s,count:c,triangles:f})}if(!d&&(d=Rt(n.mesh.geometry,u),!d&&n.mesh.geometry)){n.mesh.geometry.boundingBox||n.mesh.geometry.computeBoundingBox();let e=n.mesh.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})}let p=n.mesh.geometry,m=f>0?f:p.index?Math.round(p.index.count/3):0,h=zt({smid:o,box:d,triangles:m,floorHeight:this.host.style.floorHeight}),g=null;if(d&&this.host.sceneAnchor){let e=new t.Vector3((d.minX+d.maxX)/2,(d.minY+d.maxY)/2,(d.minZ+d.maxZ)/2);e.applyMatrix4(n.mesh.matrixWorld);let r=this.host.sceneAnchor.meterInMercator;g=this.host.lngLatFromWorld(e.x*r+this.host.sceneAnchor.x,-e.y*r+this.host.sceneAnchor.y)}let _=r??null;!_&&i&&(_=this.intersectMeshAtRay(n.mesh,i,c));let v=null,y=null,b=null;if(_&&this.host.sceneAnchor){let e=o==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(o),n=e.translation,r=e.elevation,i=_.clone();if(e.rotation){let n=vs(e.rotation);if(n){let r=new t.Matrix3().set(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8]),a=e.pivot?new t.Vector3(e.pivot[0],e.pivot[1],e.pivot[2]):new t.Vector3(0,0,0);i.sub(a).applyMatrix3(r).add(a)}}n?i.add(new t.Vector3(n[0],n[1],n[2])):r&&(i.z+=r),v=[i.x,i.y,i.z];let a=this.host.sceneAnchor.meterInMercator;y=this.host.lngLatFromWorld(i.x*a+this.host.sceneAnchor.x,-i.y*a+this.host.sceneAnchor.y),b=i.z+(this.host.sceneAnchor.altitude??0)}else g&&d&&this.host.sceneAnchor&&(y=g,b=(d.minZ+d.maxZ)/2+(this.host.sceneAnchor.altitude??0));return{datasetId:n.datasetId,datasetName:this.host.datasets.get(n.datasetId)?.name??n.datasetId,objectId:e.objectId,batchId:s,instanceIndex:c,skeletonName:n.skeletonName,centerLngLat:g,point:v,lngLat:y,altitude:b,...h,mesh:n.mesh}}buildSplatPickResult(e,n,r,i){let a=this.host.sceneAnchor;if(!a)return null;let o=n.mesh,s=r??null;!s&&i&&(s=this.intersectMeshAtRay(o,i));let c=Ga(o.geometry),l=c?{minX:c.minX,minY:c.minY,minZ:c.minZ,maxX:c.maxX,maxY:c.maxY,maxZ:c.maxZ,count:c.count,triangles:0}:null,u=zt({smid:null,box:l,triangles:0,floorHeight:this.host.style.floorHeight}),d=a.meterInMercator,f=null,p=null,m=null,h=null;if(s)f=[s.x,s.y,s.z],p=this.host.lngLatFromWorld(s.x*d+a.x,-s.y*d+a.y),m=s.z+(a.altitude??0),h=p;else if(l){let e=new t.Vector3((l.minX+l.maxX)/2,(l.minY+l.maxY)/2,(l.minZ+l.maxZ)/2).applyMatrix4(o.matrixWorld);h=this.host.lngLatFromWorld(e.x*d+a.x,-e.y*d+a.y),m=e.z+(a.altitude??0)}return{datasetId:n.datasetId,datasetName:this.host.datasets.get(n.datasetId)?.name??n.datasetId,objectId:e.objectId,batchId:-1,instanceIndex:void 0,skeletonName:n.skeletonName,centerLngLat:h,point:f,lngLat:p,altitude:m,...u,mesh:o}}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,n){if(!this.host.camera||!this.host.sceneAnchor)return null;let r=this.pick(e,n);if(r?.point&&r?.lngLat&&r.altitude!=null)return{lngLat:r.lngLat,altitude:r.altitude,point:r.point};let i=this.getRayAt(e,n);if(!i)return null;let a=new t.Plane(new t.Vector3(0,0,1),0),o=new t.Vector3,s=i.intersectPlane(a,o);if(s){let e=this.host.sceneAnchor.meterInMercator;return{lngLat:this.host.lngLatFromWorld(s.x*e+this.host.sceneAnchor.x,-s.y*e+this.host.sceneAnchor.y),altitude:s.z+(this.host.sceneAnchor.altitude??0),point:[s.x,s.y,s.z]}}return null}drillPick(e,n,r=10){if(!this.host.sceneAnchor||!this.host.camera)return[];let i=this.getRayAt(e,n);if(!i)return[];let a=new t.Raycaster;a.ray.copy(i);let o=[...this.pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),s=a.intersectObjects(o,!1);if(!s.length)return[];let c=[],l=new Set,u=new Set;for(let e of s){if(c.length>=r)break;let t=e.object,n=t.userData;if(n.pickId==null)continue;let i=this.pickables.get(n.pickId);if(!i)continue;let a=null,o=-1,s=e.instanceId;if(s!=null){let e=this.instanceFeature(t,n.geoRef,s);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let r=t.geometry.attributes.aBatchId;if(r){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(r.getX(i)),a=U(n.geoByBatchId?.get(o)??n.geoRef,o).smid}}if(a!=null){if(l.has(a))continue;l.add(a)}else{let e=`${n.pickId}:${o}:${s??-1}`;if(u.has(e))continue;u.add(e)}if(this.host.isFeatureHidden(a,o))continue;let d={objectId:n.pickId,batchId:o,instanceIndex:s},f=this.buildPickResult(d,i,e.point);f&&c.push(f)}return c}getFeatureBounds(e){if(!this.host.sceneAnchor)return null;let n=1/0,r=-1/0,i=1/0,a=-1/0,o=!1;for(let s of this.pickables.values()){let c=s.mesh,l=c.userData,u=l.geoRef,d=u?.pickInfo;if(!d)continue;let f=null;if(c.isInstancedMesh){let t=l.instanceLookup;t||(t=Lt(d),l.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){f=this.instanceBox(c,n);break}}else{let t=d,n=t[e]??t[String(e)];if(n){let e=U(u,H(n));if(f=Rt(c.geometry,e.segments),!f&&c.geometry){c.geometry.boundingBox||c.geometry.computeBoundingBox();let e=c.geometry.boundingBox;e&&(f={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(f){o=!0;let s=[new t.Vector3(f.minX,f.minY,f.minZ),new t.Vector3(f.maxX,f.minY,f.minZ),new t.Vector3(f.minX,f.maxY,f.minZ),new t.Vector3(f.maxX,f.maxY,f.minZ),new t.Vector3(f.minX,f.minY,f.maxZ),new t.Vector3(f.maxX,f.minY,f.maxZ),new t.Vector3(f.minX,f.maxY,f.maxZ),new t.Vector3(f.maxX,f.maxY,f.maxZ)],l=e==null?{}:this.host.featureStyleManager.getFeatureEffectiveOffset(e),u=l.translation,d=l.elevation,p=l.rotation?vs(l.rotation):null,m=null,h=null;p&&(m=new t.Matrix3().set(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]),h=l.pivot?new t.Vector3(l.pivot[0],l.pivot[1],l.pivot[2]):new t.Vector3(0,0,0));let g=e==null?null:this.host.gpuPathPoseAt(e),_=null;if(g&&g.yaw!==0){let e=Math.cos(g.yaw),n=Math.sin(g.yaw);_=new t.Matrix3().set(e,-n,0,n,e,0,0,0,1)}for(let e of s){if(m&&h&&e.sub(h).applyMatrix3(m).add(h),_){let n=h??new t.Vector3(0,0,0);e.sub(n).applyMatrix3(_).add(n)}u?e.add(new t.Vector3(u[0],u[1],u[2])):d&&(e.z+=d),g&&e.add(new t.Vector3(g.pos[0],g.pos[1],g.pos[2])),e.applyMatrix4(c.matrixWorld);let o=this.host.sceneAnchor.meterInMercator,[s,l]=this.host.lngLatFromWorld(e.x*o+this.host.sceneAnchor.x,-e.y*o+this.host.sceneAnchor.y);s<n&&(n=s),s>r&&(r=s),l<i&&(i=l),l>a&&(a=l)}}}return o?[[n,i],[r,a]]:null}instanceFeature(e,t,n){let r=e.userData;return r.instanceLookup||(r.instanceLookup=Lt(t?.pickInfo)),r.instanceLookup.get(n)??null}instanceBox(e,n){let r=e;if(!r.isInstancedMesh)return null;let i=e.geometry;i.boundingBox||i.computeBoundingBox();let a=i.boundingBox;if(!a)return null;let o=new t.Matrix4;r.getMatrixAt(n,o);let s=a.clone().applyMatrix4(o);return{minX:s.min.x,minY:s.min.y,minZ:s.min.z,maxX:s.max.x,maxY:s.max.y,maxZ:s.max.z,count:i.getAttribute(`position`)?.count??0,triangles:i.index?Math.round(i.index.count/3):0}}};Vt(),b();function Ds(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function Os(e){let t=e??1;return t<0?0:t>1?1:t}function ks(e){return e.isPoints===!0}var As=class{constructor(e){y(this,`host`,void 0),y(this,`selection`,null),y(this,`selectedMeshes`,[]),y(this,`_outlineMeshes`,[]),y(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(ks(e)){this.host.applyPointCloudStyle(e,!1);continue}let t=Ds(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=Ds(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?H(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)ks(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=>!ks(e));t.length&&((this.host.style.outlineStyle??`edges`)===`edges`?this.addSelectionEdges(e,t):this.addSelectionHull(e,t))}this.host.requestRepaint()}addSelectionEdges(e,n){this.syncStyle();for(let r of n){let n=r.userData,i=n.geoRef,a=[],o=-1;if(r===e.mesh&&e.instanceIndex!=null){a=[{vertexOffset:0,vertexCount:r.geometry.getAttribute(`position`)?.count??0}];let t=i?.pickInfo,n=t?.[e.smid??``]??t?.[String(e.smid)];o=n?H(n):-1}else if(e.smid!=null){let t=i?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],r=n?H(n):-1;o=r,a=n?.segments??(r>=0?U(i,r).segments:[])}else r===e.mesh&&(a=U(n.geoByBatchId?.get(e.batchId)??i,e.batchId).segments,o=e.batchId);let s=ss(r.geometry,a);if(s&&s.length>0){let n=o>=0?new Float32Array(s.length/6).fill(o):void 0,i=new t.Mesh(ns(s,n),this.host.createSelectionEdgeMaterial(r));i.renderOrder=4,i.frustumCulled=!1,i.raycast=()=>{},i.userData.isSelectionEdge=!0,r===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(i,e),r.add(i),this._selectionEdgeMeshes.push(i)}}this._selectionEdgeMeshes.length===0&&this.addSelectionHull(e,n)}applyInstanceTransform(e,n){let r=n.mesh;if(n.instanceIndex==null||!r.isInstancedMesh)return;let i=new t.Matrix4;r.getMatrixAt(n.instanceIndex,i),i.decompose(e.position,e.quaternion,e.scale)}addSelectionHull(e,n){let r=e.instanceIndex!=null;this.host.outlineMaterial.uniforms.uSelBatch.value=r?-1:e.batchId,this.host.outlineMaterial.uniforms.uSelWhole.value=r||e.batchId<0?1:0,this.host.outlineMaterial.uniforms.uElevation.value=r?this.selectionElevation(e):this.host.style.selectElevation??0;for(let r of n){let n=Ds(r);n?.userData?.uBatchTex&&(this.host.outlineMaterial.uniforms.uBatchTex.value=n.userData.uBatchTex.value,this.host.outlineMaterial.uniforms.uBatchTexWidth.value=n.userData.uBatchTexWidth.value,this.host.outlineMaterial.uniforms.uBatchTexActive.value=n.userData.uBatchTexActive.value);let i=new t.Mesh(r.geometry,this.host.outlineMaterial);i.renderOrder=3,i.frustumCulled=!1,i.raycast=()=>{},r===e.mesh&&e.instanceIndex!=null&&this.applyInstanceTransform(i,e),r.add(i),this._outlineMeshes.push(i)}}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=Os(e.opacity),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?Ds(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,n){if(!n.point)return!1;let r=e.geometry;if(!r||(r.boundingBox||r.computeBoundingBox(),!r.boundingBox))return!1;let i=new t.Vector3(n.point[0],n.point[1],n.point[2]);e.updateWorldMatrix(!0,!1);let a=e.matrixWorld.clone().invert(),o=i.applyMatrix4(a);return r.boundingBox.clone().expandByScalar(.5).containsPoint(o)}replayOnto(e){let t=this.selection;if(!t)return;let n=Ds(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?H(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),ks(e)&&this.host.applyPointCloudStyle(e,!0),this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers}};ca();var js=2;function Ms(e){return e===Q.SOLID?`solid`:e===Q.HEIGHT?`height`:`vertex`}var Ns=`
|
|
1150
1150
|
uniform float uPointSize;
|
|
1151
1151
|
varying float vWorldZ;
|
|
1152
1152
|
void main() {
|
|
@@ -1155,7 +1155,7 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1155
1155
|
gl_Position = projectionMatrix * viewMatrix * world;
|
|
1156
1156
|
gl_PointSize = uPointSize;
|
|
1157
1157
|
}
|
|
1158
|
-
`,
|
|
1158
|
+
`,Ps=`
|
|
1159
1159
|
uniform vec3 uColorA;
|
|
1160
1160
|
uniform vec3 uColorB;
|
|
1161
1161
|
uniform float uHeightMin;
|
|
@@ -1166,13 +1166,13 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1166
1166
|
float h = clamp( ( vWorldZ - uHeightMin ) / max( uHeightMax - uHeightMin, 0.001 ), 0.0, 1.0 );
|
|
1167
1167
|
gl_FragColor = vec4( mix( uColorA, uColorB, h ), uOpacity );
|
|
1168
1168
|
}
|
|
1169
|
-
`,
|
|
1169
|
+
`,Fs=`
|
|
1170
1170
|
uniform vec3 uSelColor;
|
|
1171
1171
|
uniform float uOpacity;
|
|
1172
1172
|
void main() {
|
|
1173
1173
|
gl_FragColor = vec4( uSelColor, uOpacity );
|
|
1174
1174
|
}
|
|
1175
|
-
`;function
|
|
1175
|
+
`;function Is(e,n,r){let i;return i=e===`height`?new t.ShaderMaterial({uniforms:{uColorA:r.uColorA,uColorB:r.uColorB,uHeightMin:r.uHeightMin,uHeightMax:r.uHeightMax,uPointSize:{value:js},uOpacity:{value:n.opacity??1}},vertexShader:Ns,fragmentShader:Ps,transparent:(n.opacity??1)<.999,depthWrite:(n.opacity??1)>=.999}):e===`selected`?new t.ShaderMaterial({uniforms:{uSelColor:r.uSelColor,uPointSize:{value:js},uOpacity:{value:n.opacity??1}},vertexShader:Ns,fragmentShader:Fs,transparent:(n.opacity??1)<.999,depthWrite:(n.opacity??1)>=.999}):e===`solid`?new t.PointsMaterial({size:js,sizeAttenuation:!1,color:new t.Color(n.colorA),transparent:(n.opacity??1)<.999,opacity:n.opacity??1,depthWrite:(n.opacity??1)>=.999}):new t.PointsMaterial({size:js,sizeAttenuation:!1,vertexColors:!0,transparent:(n.opacity??1)<.999,opacity:n.opacity??1,depthWrite:(n.opacity??1)>=.999}),i.userData.pcOwned=!0,i}function Ls(e,t,n,r=!1){let i=e.userData,a=r?`selected`:Ms(t.mode);if(i.pcKind!==a){let r=e.material;e.material=Is(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 Rs(e){let t=Array.isArray(e)?e[0]:e;return!!t&&t.userData?.pcOwned===!0}Xa(),b();var zs=`
|
|
1176
1176
|
attribute float aBatchId;
|
|
1177
1177
|
#ifdef USE_INSTANCING
|
|
1178
1178
|
// 实例化:单体粒度在实例上,顶点属性里没有可用的 batchId
|
|
@@ -1301,7 +1301,7 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1301
1301
|
// 跟显示尺寸(2px)不匹配,点云会很难点中。对 Mesh 图元这行被忽略。
|
|
1302
1302
|
gl_PointSize = 2.0;
|
|
1303
1303
|
}
|
|
1304
|
-
`,
|
|
1304
|
+
`,Bs=`
|
|
1305
1305
|
uniform float uObjectId;
|
|
1306
1306
|
varying float vBatch;
|
|
1307
1307
|
void main() {
|
|
@@ -1314,7 +1314,7 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1314
1314
|
floor( b / 256.0 ) / 255.0
|
|
1315
1315
|
);
|
|
1316
1316
|
}
|
|
1317
|
-
`,zs=(()=>{let e=new t.DataTexture(new Float32Array([-1,-1,-1,0,0,0,0,0]),1,2,t.RGBAFormat,t.FloatType);return e.minFilter=t.NearestFilter,e.magFilter=t.NearestFilter,e.needsUpdate=!0,e})(),Bs=(()=>{let e=new t.DataTexture(new Float32Array([0,0,0,0]),1,1,t.RGBAFormat,t.FloatType);return e.minFilter=t.NearestFilter,e.magFilter=t.NearestFilter,e.needsUpdate=!0,e})();function Vs(e){return new t.ShaderMaterial({uniforms:{uObjectId:{value:e},uBatchTex:{value:zs},uBatchTex2:{value:zs},uBatchMix:{value:0},uBatchTexWidth:{value:1},uBatchTexActive:{value:0},uPathTex:{value:Bs},uPathCount:{value:1},uPathTime:{value:0},uPathTexActive:{value:0},uSelBatch:{value:-1},uSelWhole:{value:0},uSelElevation:{value:0}},vertexShader:Ls,fragmentShader:Rs,side:t.DoubleSide,depthTest:!0,depthWrite:!0,toneMapped:!1})}function Hs(e){return e.isPoints===!0}var Us=class{constructor(e,t={}){y(this,`renderer`,void 0),y(this,`size`,void 0),y(this,`target`,null),y(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 t.WebGLRenderTarget(e,e,{minFilter:t.NearestFilter,magFilter:t.NearestFilter,format:t.RGBAFormat,type:t.UnsignedByteType,depthBuffer:!0,stencilBuffer:!1}),this.target.texture.colorSpace=t.LinearSRGBColorSpace),this.target}pick(e,n,r,i){let a=this.renderer,o=a.domElement,s=o.width,c=o.height;if(!s||!c)return null;let l=Math.floor(r/o.clientWidth*s),u=Math.floor(i/o.clientHeight*c);if(l<0||u<0||l>=s||u>=c)return null;let d=this._ensureTarget(this.size),f=c-1-u,p=Math.floor(this.size/2),m=Math.floor(this.size/2);d.viewport.set(p-l,m-f,s,c);let h=a.getRenderTarget(),g=a.getViewport(new t.Vector4),_=a.toneMapping,v=a.outputColorSpace,y=a.autoClear,b=a.getClearColor(new t.Color),x=a.getClearAlpha(),S=[],C=new Set;e.traverseVisible(e=>{let t=e;if(!t.isMesh&&!Hs(t))return;let n=t.userData;if(n.pickId===void 0)return;let r=n.isGaussianSplat===!0;n.pickMaterial||(n.pickMaterial=r?Wa(n.pickId):Vs(n.pickId)),!r&&t.isInstancedMesh&&C.add(n.pickId);let i=t.material,a=n.pickMaterial;if(r){S.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=zs,a.uniforms.uBatchTex2.value=zs,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??Bs,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,S.push([t,i]),t.material=a});let w=[];e.traverseVisible(e=>{let t=e;(t.isMesh||Hs(t))&&t.userData.pickId===void 0&&(w.push(t),t.visible=!1)});let T=null;try{a.resetState(),a.setRenderTarget(d),a.toneMapping=t.NoToneMapping,a.outputColorSpace=t.LinearSRGBColorSpace,a.autoClear=!0,a.setClearColor(0,0),a.clear(),a.render(e,n),a.readRenderTargetPixels(d,p,m,1,1,this.buf);let r=this.buf[0],i=this.buf[1],o=this.buf[2],s=this.buf[3],c=r+i*256-1,l=o+s*256-1;c>=0&&(T=C.has(c)?{objectId:c,batchId:-1,instanceIndex:Math.max(0,l)}:{objectId:c,batchId:l})}finally{for(let[e,t]of S)e.material=t;for(let e of w)e.visible=!0;a.setRenderTarget(h),a.setViewport(g),a.toneMapping=_,a.outputColorSpace=v,a.autoClear=y,a.setClearColor(b,x),a.resetState()}return T}dispose(){this.target?.dispose(),this.target=null}},Ws=1.70158,Gs=Ws*1.525,Ks=2.70158,qs=2*Math.PI/3,Js=2*Math.PI/4.5,Ys=7.5625,Xs=2.75;function Zs(e){if(e<1/Xs)return Ys*e*e;if(e<2/Xs){let t=e-1.5/Xs;return Ys*t*t+.75}if(e<2.5/Xs){let t=e-2.25/Xs;return Ys*t*t+.9375}let t=e-2.625/Xs;return Ys*t*t+.984375}function Qs(e){return 1-Zs(1-e)}var $s={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=>Ks*e*e*e-Ws*e*e,easeOutBack:e=>1+Ks*(e-1)**3+Ws*(e-1)**2,easeInOutBack:e=>e<.5?(2*e)**2*(7.189819*e-Gs)/2:((2*e-2)**2*(3.5949095*(e*2-2)+Gs)+2)/2,easeInElastic:e=>e===0?0:e===1?1:-(2**(10*e-10))*Math.sin((e*10-10.75)*qs),easeOutElastic:e=>e===0?0:e===1?1:2**(-10*e)*Math.sin((e*10-.75)*qs)+1,easeInOutElastic:e=>e===0?0:e===1?1:e<.5?-(2**(20*e-10)*Math.sin((20*e-11.125)*Js))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*Js)/2+1,easeInBounce:Qs,easeOutBounce:Zs,easeInOutBounce:e=>e<.5?(1-Qs(1-2*e))/2:(1+Qs(2*e-1))/2},ec=Object.keys($s);function tc(e){if(typeof e==`function`)return e;let t=$s[e];if(!t)throw Error(`[s3m] 未知的缓动曲线: ${String(e)}`);return t}var nc=8,rc=.001,ic=1e-7,ac=12,oc=(e,t)=>1-3*t+3*e,sc=(e,t)=>3*t-6*e,cc=e=>3*e;function lc(e,t,n){return((oc(t,n)*e+sc(t,n))*e+cc(t))*e}function uc(e,t,n){return 3*oc(t,n)*e*e+2*sc(t,n)*e+cc(t)}function dc(e,t,n,r){if(e===t&&n===r)return e=>e;let i=t=>{let r=t;for(let i=0;i<nc;i++){let i=uc(r,e,n);if(Math.abs(i)<rc)break;let a=lc(r,e,n)-t;if(Math.abs(a)<ic)return r;r-=a/i}let i=0,a=1;r=t;for(let o=0;o<ac;o++){let o=lc(r,e,n);if(Math.abs(o-t)<ic)return r;o<t?i=r:a=r,r=(i+a)/2}return r};return e=>e<=0?0:e>=1?1:lc(i(e),t,r)}function fc(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)}}b();var pc=1e-4,mc=.15;function hc(e){return e<0?0:e>1?1:e}function gc(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 _c=class{constructor(e,t){y(this,`key`,void 0),y(this,`channel`,void 0),y(this,`dim`,void 0),y(this,`to`,new Float32Array(3)),y(this,`_cur`,new Float32Array(3)),y(this,`done`,!1),y(this,`onComplete`,void 0),this.key=e,this.channel=t,this.dim=t.dim}},vc=class extends _c{constructor(...e){super(...e),y(this,`_from`,new Float32Array(3)),y(this,`_start`,0),y(this,`_duration`,0),y(this,`_delay`,0),y(this,`_ease`,tc(`linear`)),y(this,`_retarget`,`proportional`),y(this,`_span`,0),y(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?tc(t.easing):tc(`linear`),this._retarget=t.retarget??`proportional`,this._span=gc(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:hc(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>pc){let e=gc(this._from,this.to,this.dim)/this._span;i=Math.min(r,Math.max(r*mc,r*e))}this._start=t,this._delay=Math.max(0,n.delay??0),this._duration=i,this._ease=n.easing?tc(n.easing):this._ease,this._span=gc(this._from,this.to,this.dim),this._progress=0,this.done=!1}},yc=class extends _c{constructor(...e){super(...e),y(this,`_x0`,new Float32Array(3)),y(this,`_v0`,new Float32Array(3)),y(this,`_vel`,new Float32Array(3)),y(this,`_start`,0),y(this,`_k`,120),y(this,`_c`,14),y(this,`_eps`,.001),y(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}=bc(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=bc(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 bc(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 xc=class{constructor(e=()=>performance.now()){y(this,`_channels`,new Map),y(this,`_tracks`,new Map),y(this,`_buf`,new Float32Array(3)),y(this,`_finished`,[]),y(this,`_now`,void 0),y(this,`_budgetMs`,2.5),y(this,`_lastTick`,-1/0),y(this,`_skipped`,0),y(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 yc;if(c&&c!=null&&u!==l&&(this._tracks.delete(e),c=void 0),c||this.onActive?.(),!c){let t=l?new yc(e,r):new vc(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}};b();var Sc=class{constructor(){y(this,`datasets`,new Map),y(this,`sceneAnchor`,null),y(this,`totalMaxTiles`,0)}get(e){return this.datasets.get(e)}values(){return this.datasets.values()}registerDataset(e){let n=this.datasets.get(e.id);if(n)return n;let r=new t.Group;r.name=`s3m-dataset:${e.id}`,r.visible=e.visible!==!1;let i={id:e.id,name:e.name??e.id,options:e,root:r,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,i),this.rebalanceBudgets(),i}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,n,r,i,a,o,s,c,l,u=1/0,d=128,f){let p=this.datasets.get(e.id);if(p)return p;let m=new t.Group;m.name=`s3m-dataset:${e.id}`,m.visible=e.visible!==!1,n.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 ko({configUrl:e.configUrl,maxTiles:e.maxTiles??s,maxConcurrent:c,maxTriangles:e.maxTriangles??u,maxImageCache:e.maxImageCache??d,lodRangeScale:e.lodRangeScale??a,buildTile:o??null,polygonOffset:e.polygonOffset,useWorker:e.useWorker,authenticate:e.authenticate??f,unsupported:e.unsupported,uniforms:i,onTile:e=>{l.onTile(e,h)},onTileRemoved:e=>{l.onTileRemoved(e,h)},onProgress:()=>{l.onStats(),l.triggerRepaint()},onError:e=>{h.error=e,l.onError(e),l.onStats()}});h.tileset=g,this.rebalanceBudgets();try{await g.init()}catch(e){return h.error=e,l.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,r),l.onReady(h),l.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=Qt(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0));let n=this.sceneAnchor.meterInMercator,r=Qt(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=Eo(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}};b();var Cc=class{constructor(e={}){y(this,`mode`,void 0),y(this,`opacity`,void 0),y(this,`color`,void 0),y(this,`gridColor`,void 0),y(this,`gridSize`,void 0),y(this,`excavationBounds`,null),y(this,`size`,void 0),y(this,`groundHeight`,0),y(this,`occlude`,void 0),y(this,`trackHeight`,void 0),y(this,`group`,void 0),y(this,`_mesh`,null),y(this,`_material`,null),y(this,`_depthMesh`,null),y(this,`_depthMaterial`,null),y(this,`_geom`,null),y(this,`_occludeExplicit`,void 0),this.mode=e.mode??`none`,this.opacity=e.opacity??.62,this.color=new t.Color(e.color??`#0f172a`),this.gridColor=new t.Color(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 t.Group,this.group.name=`s3m-ground-surface`,this._initMesh(),this._applyMode()}_initMesh(){let e=new t.PlaneGeometry(this.size,this.size,1,1);this._geom=e;let n=new t.ShaderMaterial({transparent:!0,depthTest:!0,depthWrite:!1,side:t.DoubleSide,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 t.Vector2(-9999,-9999)},uExcavationMax:{value:new t.Vector2(9999,9999)}},vertexShader:`
|
|
1317
|
+
`,Vs=(()=>{let e=new t.DataTexture(new Float32Array([-1,-1,-1,0,0,0,0,0]),1,2,t.RGBAFormat,t.FloatType);return e.minFilter=t.NearestFilter,e.magFilter=t.NearestFilter,e.needsUpdate=!0,e})(),Hs=(()=>{let e=new t.DataTexture(new Float32Array([0,0,0,0]),1,1,t.RGBAFormat,t.FloatType);return e.minFilter=t.NearestFilter,e.magFilter=t.NearestFilter,e.needsUpdate=!0,e})();function Us(e){return new t.ShaderMaterial({uniforms:{uObjectId:{value:e},uBatchTex:{value:Vs},uBatchTex2:{value:Vs},uBatchMix:{value:0},uBatchTexWidth:{value:1},uBatchTexActive:{value:0},uPathTex:{value:Hs},uPathCount:{value:1},uPathTime:{value:0},uPathTexActive:{value:0},uSelBatch:{value:-1},uSelWhole:{value:0},uSelElevation:{value:0}},vertexShader:zs,fragmentShader:Bs,side:t.DoubleSide,depthTest:!0,depthWrite:!0,toneMapped:!1})}function Ws(e){return e.isPoints===!0}var Gs=class{constructor(e,t={}){y(this,`renderer`,void 0),y(this,`size`,void 0),y(this,`target`,null),y(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 t.WebGLRenderTarget(e,e,{minFilter:t.NearestFilter,magFilter:t.NearestFilter,format:t.RGBAFormat,type:t.UnsignedByteType,depthBuffer:!0,stencilBuffer:!1}),this.target.texture.colorSpace=t.LinearSRGBColorSpace),this.target}pick(e,n,r,i){let a=this.renderer,o=a.domElement,s=o.width,c=o.height;if(!s||!c)return null;let l=Math.floor(r/o.clientWidth*s),u=Math.floor(i/o.clientHeight*c);if(l<0||u<0||l>=s||u>=c)return null;let d=this._ensureTarget(this.size),f=c-1-u,p=Math.floor(this.size/2),m=Math.floor(this.size/2);d.viewport.set(p-l,m-f,s,c);let h=a.getRenderTarget(),g=a.getViewport(new t.Vector4),_=a.toneMapping,v=a.outputColorSpace,y=a.autoClear,b=a.getClearColor(new t.Color),x=a.getClearAlpha(),S=[],C=new Set;e.traverseVisible(e=>{let t=e;if(!t.isMesh&&!Ws(t))return;let n=t.userData;if(n.pickId===void 0)return;let r=n.isGaussianSplat===!0;n.pickMaterial||(n.pickMaterial=r?Wa(n.pickId):Us(n.pickId)),!r&&t.isInstancedMesh&&C.add(n.pickId);let i=t.material,a=n.pickMaterial;if(r){S.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=Vs,a.uniforms.uBatchTex2.value=Vs,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??Hs,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,S.push([t,i]),t.material=a});let w=[];e.traverseVisible(e=>{let t=e;(t.isMesh||Ws(t))&&t.userData.pickId===void 0&&(w.push(t),t.visible=!1)});let T=null;try{a.resetState(),a.setRenderTarget(d),a.toneMapping=t.NoToneMapping,a.outputColorSpace=t.LinearSRGBColorSpace,a.autoClear=!0,a.setClearColor(0,0),a.clear(),a.render(e,n),a.readRenderTargetPixels(d,p,m,1,1,this.buf);let r=this.buf[0],i=this.buf[1],o=this.buf[2],s=this.buf[3],c=r+i*256-1,l=o+s*256-1;c>=0&&(T=C.has(c)?{objectId:c,batchId:-1,instanceIndex:Math.max(0,l)}:{objectId:c,batchId:l})}finally{for(let[e,t]of S)e.material=t;for(let e of w)e.visible=!0;a.setRenderTarget(h),a.setViewport(g),a.toneMapping=_,a.outputColorSpace=v,a.autoClear=y,a.setClearColor(b,x),a.resetState()}return T}dispose(){this.target?.dispose(),this.target=null}},Ks=1.70158,qs=Ks*1.525,Js=2.70158,Ys=2*Math.PI/3,Xs=2*Math.PI/4.5,Zs=7.5625,Qs=2.75;function $s(e){if(e<1/Qs)return Zs*e*e;if(e<2/Qs){let t=e-1.5/Qs;return Zs*t*t+.75}if(e<2.5/Qs){let t=e-2.25/Qs;return Zs*t*t+.9375}let t=e-2.625/Qs;return Zs*t*t+.984375}function ec(e){return 1-$s(1-e)}var tc={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=>Js*e*e*e-Ks*e*e,easeOutBack:e=>1+Js*(e-1)**3+Ks*(e-1)**2,easeInOutBack:e=>e<.5?(2*e)**2*(7.189819*e-qs)/2:((2*e-2)**2*(3.5949095*(e*2-2)+qs)+2)/2,easeInElastic:e=>e===0?0:e===1?1:-(2**(10*e-10))*Math.sin((e*10-10.75)*Ys),easeOutElastic:e=>e===0?0:e===1?1:2**(-10*e)*Math.sin((e*10-.75)*Ys)+1,easeInOutElastic:e=>e===0?0:e===1?1:e<.5?-(2**(20*e-10)*Math.sin((20*e-11.125)*Xs))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*Xs)/2+1,easeInBounce:ec,easeOutBounce:$s,easeInOutBounce:e=>e<.5?(1-ec(1-2*e))/2:(1+ec(2*e-1))/2},nc=Object.keys(tc);function rc(e){if(typeof e==`function`)return e;let t=tc[e];if(!t)throw Error(`[s3m] 未知的缓动曲线: ${String(e)}`);return t}var ic=8,ac=.001,oc=1e-7,sc=12,cc=(e,t)=>1-3*t+3*e,lc=(e,t)=>3*t-6*e,uc=e=>3*e;function dc(e,t,n){return((cc(t,n)*e+lc(t,n))*e+uc(t))*e}function fc(e,t,n){return 3*cc(t,n)*e*e+2*lc(t,n)*e+uc(t)}function pc(e,t,n,r){if(e===t&&n===r)return e=>e;let i=t=>{let r=t;for(let i=0;i<ic;i++){let i=fc(r,e,n);if(Math.abs(i)<ac)break;let a=dc(r,e,n)-t;if(Math.abs(a)<oc)return r;r-=a/i}let i=0,a=1;r=t;for(let o=0;o<sc;o++){let o=dc(r,e,n);if(Math.abs(o-t)<oc)return r;o<t?i=r:a=r,r=(i+a)/2}return r};return e=>e<=0?0:e>=1?1:dc(i(e),t,r)}function mc(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)}}b();var hc=1e-4,gc=.15;function _c(e){return e<0?0:e>1?1:e}function vc(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 yc=class{constructor(e,t){y(this,`key`,void 0),y(this,`channel`,void 0),y(this,`dim`,void 0),y(this,`to`,new Float32Array(3)),y(this,`_cur`,new Float32Array(3)),y(this,`done`,!1),y(this,`onComplete`,void 0),this.key=e,this.channel=t,this.dim=t.dim}},bc=class extends yc{constructor(...e){super(...e),y(this,`_from`,new Float32Array(3)),y(this,`_start`,0),y(this,`_duration`,0),y(this,`_delay`,0),y(this,`_ease`,rc(`linear`)),y(this,`_retarget`,`proportional`),y(this,`_span`,0),y(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?rc(t.easing):rc(`linear`),this._retarget=t.retarget??`proportional`,this._span=vc(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:_c(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>hc){let e=vc(this._from,this.to,this.dim)/this._span;i=Math.min(r,Math.max(r*gc,r*e))}this._start=t,this._delay=Math.max(0,n.delay??0),this._duration=i,this._ease=n.easing?rc(n.easing):this._ease,this._span=vc(this._from,this.to,this.dim),this._progress=0,this.done=!1}},xc=class extends yc{constructor(...e){super(...e),y(this,`_x0`,new Float32Array(3)),y(this,`_v0`,new Float32Array(3)),y(this,`_vel`,new Float32Array(3)),y(this,`_start`,0),y(this,`_k`,120),y(this,`_c`,14),y(this,`_eps`,.001),y(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}=Sc(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=Sc(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 Sc(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 Cc=class{constructor(e=()=>performance.now()){y(this,`_channels`,new Map),y(this,`_tracks`,new Map),y(this,`_buf`,new Float32Array(3)),y(this,`_finished`,[]),y(this,`_now`,void 0),y(this,`_budgetMs`,2.5),y(this,`_lastTick`,-1/0),y(this,`_skipped`,0),y(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 xc;if(c&&c!=null&&u!==l&&(this._tracks.delete(e),c=void 0),c||this.onActive?.(),!c){let t=l?new xc(e,r):new bc(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}};b();var wc=class{constructor(){y(this,`datasets`,new Map),y(this,`sceneAnchor`,null),y(this,`totalMaxTiles`,0)}get(e){return this.datasets.get(e)}values(){return this.datasets.values()}registerDataset(e){let n=this.datasets.get(e.id);if(n)return n;let r=new t.Group;r.name=`s3m-dataset:${e.id}`,r.visible=e.visible!==!1;let i={id:e.id,name:e.name??e.id,options:e,root:r,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,i),this.rebalanceBudgets(),i}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,n,r,i,a,o,s,c,l,u=1/0,d=128,f,p=1/0){let m=this.datasets.get(e.id);if(m)return m;let h=new t.Group;h.name=`s3m-dataset:${e.id}`,h.visible=e.visible!==!1,n.add(h);let g={id:e.id,name:e.name??e.id,options:e,root:h,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,g);let _=new jo({configUrl:e.configUrl,maxTiles:e.maxTiles??s,maxConcurrent:c,maxTriangles:e.maxTriangles??u,maxMemory:e.maxMemory??p,maxImageCache:e.maxImageCache??d,lodRangeScale:e.lodRangeScale??a,buildTile:o??null,polygonOffset:e.polygonOffset,useWorker:e.useWorker,authenticate:e.authenticate??f,unsupported:e.unsupported,uniforms:i,onTile:e=>{l.onTile(e,g)},onTileRemoved:e=>{l.onTileRemoved(e,g)},onProgress:()=>{l.onStats(),l.triggerRepaint()},onError:e=>{g.error=e,l.onError(e),l.onStats()}});g.tileset=_,this.rebalanceBudgets();try{await _.init()}catch(e){return g.error=e,l.onError(e),g}return g.anchor=_.anchor,g.baseAlignOffset=this.computeAlignOffset(_,e.align),g.userOffset=e.heightOffset??0,g.heightOffset=g.baseAlignOffset+g.userOffset,this.layoutDataset(g,r),l.onReady(g),l.triggerRepaint(),g}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=Qt(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0));let n=this.sceneAnchor.meterInMercator,r=Qt(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=Eo(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}};b();var Tc=class{constructor(e={}){y(this,`mode`,void 0),y(this,`opacity`,void 0),y(this,`color`,void 0),y(this,`gridColor`,void 0),y(this,`gridSize`,void 0),y(this,`excavationBounds`,null),y(this,`size`,void 0),y(this,`groundHeight`,0),y(this,`occlude`,void 0),y(this,`trackHeight`,void 0),y(this,`group`,void 0),y(this,`_mesh`,null),y(this,`_material`,null),y(this,`_depthMesh`,null),y(this,`_depthMaterial`,null),y(this,`_geom`,null),y(this,`_occludeExplicit`,void 0),this.mode=e.mode??`none`,this.opacity=e.opacity??.62,this.color=new t.Color(e.color??`#0f172a`),this.gridColor=new t.Color(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 t.Group,this.group.name=`s3m-ground-surface`,this._initMesh(),this._applyMode()}_initMesh(){let e=new t.PlaneGeometry(this.size,this.size,1,1);this._geom=e;let n=new t.ShaderMaterial({transparent:!0,depthTest:!0,depthWrite:!1,side:t.DoubleSide,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 t.Vector2(-9999,-9999)},uExcavationMax:{value:new t.Vector2(9999,9999)}},vertexShader:`
|
|
1318
1318
|
varying vec2 vEnuPos;
|
|
1319
1319
|
void main() {
|
|
1320
1320
|
vec4 worldPos = modelMatrix * vec4(position, 1.0);
|
|
@@ -1392,4 +1392,4 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1392
1392
|
}
|
|
1393
1393
|
gl_FragColor = vec4(1.0);
|
|
1394
1394
|
}
|
|
1395
|
-
`}),a=new t.Mesh(e,i);a.position.set(0,0,-.02),a.renderOrder=-1e3,a.name=`s3m-ground-depth`,a.visible=!1,this.group.add(a),this._depthMesh=a,this._depthMaterial=i,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()}};wi(),ca(),Ei(),ki(),b();function wc(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function Tc(e){return e.isPoints===!0}function Ec(e){let t=e??1;return t<0?0:t>1?1:t}var Dc=.001,Oc=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`metalness`,`roughness`,`edgeWidth`,`edgeOpacity`,`edgeOffset`,`edgeHullWidth`,`outlineWidth`],kc=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],Ac=[`translation`,`elevation`,`opacity`,`color`,`rotation`],jc=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={}){y(this,`options`,void 0),y(this,`pickable`,void 0),y(this,`onStats`,void 0),y(this,`onReady`,void 0),y(this,`onPick`,void 0),y(this,`onError`,void 0),y(this,`geo`,null),y(this,`canvas`,null),y(this,`renderer`,null),y(this,`scene`,null),y(this,`camera`,null),y(this,`picker`,null),y(this,`uniforms`,void 0),y(this,`style`,void 0),y(this,`_styleTarget`,void 0),y(this,`outlineMaterial`,void 0),y(this,`lineShared`,void 0),y(this,`edgeMaterial`,void 0),y(this,`selectionEdgeMaterial`,void 0),y(this,`_edges`,void 0),y(this,`groundManager`,void 0),y(this,`_datasetManager`,new Sc),y(this,`_featureStyleManager`,void 0),y(this,`gpuPathManager`,new Oi),y(this,`_customPathTime`,!1),y(this,`_picks`,void 0),y(this,`_smidMeshes`,new Map),y(this,`_heights`,void 0),y(this,`_sel`,void 0),y(this,`_tileFadeSeq`,0),y(this,`_modeGen`,0),y(this,`_shadingPrewarmed`,!1),y(this,`_prewarmShadingEnabled`,!0),y(this,`_prewarming`,!1),y(this,`_pathSpecs`,new Map),y(this,`_pathScratch`,new Float32Array(3)),y(this,`_pathScratch2`,new Float32Array(3)),y(this,`_pointClouds`,new Set),y(this,`_splats`,new Yo),y(this,`_opacityTransparent`,!1),y(this,`animator`,new xc),y(this,`attributeQuery`,null),y(this,`_enuMatrix`,new t.Matrix4),y(this,`_frameMvp`,new t.Matrix4),y(this,`_colorScratch`,new t.Color),y(this,`_frame`,0),y(this,`_fps`,{value:0,last:0}),y(this,`_lights`,void 0),y(this,`_datasetQueue`,void 0),y(this,`_onRequestRepaint`,()=>{}),y(this,`_getBearing`,void 0),y(this,`_authenticate`,void 0),y(this,`_lodRangeScale`,1),y(this,`_unsupported`,void 0),y(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,ui(e.maxTextureSize??1/0),Mi(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 Cc(e.ground),this.scene||(this.scene=new t.Scene,this.scene.add(this.groundManager.group)),this._featureStyleManager=new Ss(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._sel.selection&&this._sel.syncStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=Ii(),this._lights=new Fo({scene:()=>this.scene,renderer:()=>this.renderer,uniforms:this.uniforms,options:this.options,getBearing:()=>this._getBearing?.(),repaint:()=>this.triggerRepaint()}),this._lights.addToScene(),this._heights=new Io(this.uniforms);let n=this;this._picks=new ws({get picker(){return n.picker},get camera(){return n.camera},get scene(){return n.scene},get canvas(){return n.canvas},get style(){return n.style},get sceneAnchor(){return n.sceneAnchor},get datasets(){return n.datasets},get featureStyleManager(){return n._featureStyleManager},get smidMeshes(){return n._smidMeshes},lngLatFromWorld:(e,t)=>n._lngLatFromWorld(e,t),gpuPathPoseAt:e=>n._gpuPathPoseAt(e),isFeatureHidden:(e,t)=>n._isFeatureHidden(e,t)}),fi(dn),this.style={...Ui,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=zi(this.uniforms),this._edges=new ms({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 Os({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 Jt({...e.attributes,authenticate:e.attributes.authenticate??this._authenticate}))}_createRenderer(e,n){let r=new t.WebGLRenderer({canvas:e,context:n,antialias:!0});return r.autoClear=!1,r.setPixelRatio(1),r.toneMapping=this.options.toneMapping===void 0?t.NoToneMapping:this.options.toneMapping,r.toneMappingExposure=this.options.toneMappingExposure??1,r}_syncTextureCapabilities(e){let t=!!e.getExtension(`WEBGL_compressed_texture_s3tc`),n=!!e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`);di(t&&n)}mount(e,n){this.canvas=e,this.renderer=this._createRenderer(e,n),ci(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(n),this.scene=new t.Scene,this.scene.add(this.groundManager.group),this._addLights(),this.camera=new t.Camera,this.camera.matrixAutoUpdate=!1,this.picker=new Us(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),ci(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new Us(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 $t(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=_s(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=_s(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 Ti?t:new Ti(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=_s(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=_s(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 Ac)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 Jt({...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=wc(t);r&&r.dispose(),Is(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=Tc(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=wc(o);if(e){let t=Ec(this.style.opacity),n=this.style.depthWrite!==!1;Ri(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),Ri(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),Tc(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),wc(t)?.dispose?.()}Is(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:Bi[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 kc.includes(e)?3:1}_registerAnimChannels(){for(let e of Oc)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 kc)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??$.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===$.REPLACE?0:n===$.MULTIPLY?2:n===$.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=Ec(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=Ec(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(Tc(n.mesh))continue;let r=wc(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||Ri(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)){Fs(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=wc(t.mesh)?.userData.uFlatShading;n&&n.value!==e&&(n.value=e)}this._requestRepaint()}setMaterialQuality(e){Mi(e),this._rebuildStyledMaterials(),this._requestRepaint()}get materialQuality(){return Ni()}_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=Li({...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(wc(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,ci(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,ui(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===Q.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),to(r.width,r.height),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),(this.uniforms.uOpacity?.value??1)>Dc&&(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===Q.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=Eo(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()}};b();var Mc=class e{constructor(t={}){y(this,`id`,void 0),y(this,`options`,void 0),y(this,`pickable`,void 0),y(this,`onStats`,void 0),y(this,`onReady`,void 0),y(this,`onPick`,void 0),y(this,`onError`,void 0),y(this,`viewer`,void 0),y(this,`_projection`,`perspective`),y(this,`_projectionT`,0),y(this,`_orthoWarned`,!1),y(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 jc({...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}},Nc=1e-4;function Pc(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])>Nc*r)return!1}return!0}function Fc(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 Ic(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function Lc(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Rc(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 zc(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 Bc(e,n){let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new t.Matrix4().fromArray(Array.from(r)),a=new t.Matrix4().fromArray(Array.from(e.mvp));if(i.determinant()===0||!Ic(i,n.fov))return null;let o=i.clone().invert().multiply(a);if(!Pc(i.clone().multiply(o),Array.from(e.mvp))||!Fc(o)||!Ic(i,n.fov))return null;let{distance:s,fov:c,aspect:l}=n;if(!(s>0)||!(c>0)||!(l>0))return null;let u=s*Math.tan(c/2),d=u*l,f=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,p=e.farZ!=null&&e.farZ>f?e.farZ:s*4+1e3;p>f||(p=f+1e3);let m=new t.OrthographicCamera(-d,d,u,-u,f,p);return m.updateProjectionMatrix(),{matrix:m.projectionMatrix.clone().multiply(o),view:o}}function Vc(e,n){if(!(n>0)||n>=1)return null;let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new t.Matrix4().fromArray(Array.from(r));if(!Number.isFinite(i.determinant())||i.determinant()===0||Math.abs(i.elements[11]+1)>1e-6)return null;let a=e.nearZ!=null&&e.nearZ>0?e.nearZ:NaN,o=e.farZ!=null&&e.farZ>a?e.farZ:NaN;if(!(a>0)||!(o>a)){let e=-i.elements[10];if(!(e>1)||(a=-i.elements[14]/(e+1),o=a*(e+1)/(e-1),!(a>0)||!(o>a)))return null}let s=a*n;if(!(s>0)||!(s<o))return null;let c=i.clone();c.elements[10]=-(o+s)/(o-s),c.elements[14]=-2*o*s/(o-s);let l=c.multiply(i.clone().invert()).multiply(new t.Matrix4().fromArray(Array.from(e.mvp)));for(let e=0;e<16;e++)if(!Number.isFinite(l.elements[e]))return null;return l}function Hc(e,n,r){let i=e.projectionMatrix;if(!i||i.length<16)return null;let a=new t.Matrix4().fromArray(Array.from(i)),o=new t.Matrix4().fromArray(Array.from(e.mvp));if(a.determinant()===0||!Ic(a,n.fov))return null;let s=a.clone().invert().multiply(o);if(!Pc(a.clone().multiply(s),Array.from(e.mvp))||!Fc(s))return null;let c=Math.max(0,Math.min(1,r));if(c<=0)return{matrix:o,view:s};let{distance:l,fov:u,aspect:d}=n;if(!(l>0)||!(u>0)||!(d>0))return null;let f=l*Math.tan(u/2),p=f*d,m=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,h=e.farZ!=null&&e.farZ>m?e.farZ:l*4+1e3;h>m||(h=m+1e3);let g=new t.OrthographicCamera(-p,p,f,-f,m,h);if(g.updateProjectionMatrix(),c>=1)return{matrix:g.projectionMatrix.clone().multiply(s),view:s};let _=new t.Matrix4,v=a.elements,y=g.projectionMatrix.elements,b=_.elements;for(let e=0;e<16;e++)b[e]=(1-c)*v[e]+c*y[e];return{matrix:_.multiply(s),view:s}}var Uc=l({Animator:()=>xc,AttributeQuery:()=>Jt,BinaryReader:()=>x,DEFAULT_FLOOR_HEIGHT:()=>Bt,DEFAULT_LIGHT_PRESET:()=>Ao,DEFAULT_STYLE:()=>Ui,DatasetManager:()=>Sc,EARTH_RADIUS:()=>Yt,EASING_NAMES:()=>ec,FeatureStyleManager:()=>Ss,GPUPathManager:()=>Oi,GpuEdgePass:()=>us,GroundManager:()=>Cc,HostRenderer:()=>Mc,LIGHT_PRESETS:()=>Mo,Path:()=>Ti,Picker:()=>Us,PixelFormat:()=>Y,S3MFormatError:()=>Nt,S3MTileset:()=>ko,S3MViewer:()=>jc,S3M_VERSION:()=>rt,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>$,SELECT_MODE_LABELS:()=>Vi,STYLE:()=>Q,STYLE_LABELS:()=>Bi,SUPERMAP_LIGHT_PRESET:()=>jo,TextureCompress:()=>X,VertexTag:()=>B,VertexTagV3:()=>it,authFetch:()=>Ut,buildAttributes:()=>zt,buildBlendedMVP:()=>Hc,buildFeatureEdgeSegments:()=>as,buildNearScaledMVP:()=>Vc,buildOrthoMVP:()=>Bc,buildThickLineGeometry:()=>es,buildTileObjects:()=>fo,createLineSharedUniforms:()=>Xo,createOutlineMaterial:()=>zi,createSharedUniforms:()=>Ii,createStyledMaterial:()=>Li,createTexture:()=>_i,createThickLineMaterial:()=>$o,cubicBezier:()=>dc,default:()=>jc,dxtPixelFormatOf:()=>Or,easing:()=>tc,extractEulerAngles:()=>_s,extractFovRadians:()=>zc,extractNearFar:()=>Rc,extractProjectionMatrix:()=>Lc,getColorPipeline:()=>Fi,getMaterialQuality:()=>Ni,isS3M1Buffer:()=>Le,lngLatFromMercator:()=>Zt,lngLatFromWorld:()=>$t,measureSegments:()=>Rt,mercatorFromLngLat:()=>Xt,parseS3M1:()=>nt,parseS3MB:()=>Pt,planDegradations:()=>It,resolveAuthRequest:()=>Ht,resolveEdgeModes:()=>Ai,resolveFeature:()=>U,resolveLightingPreset:()=>No,resolveRotationMatrix:()=>gs,resolveTextureKind:()=>Dr,sameEdgeModes:()=>ji,setColorPipeline:()=>Pi,setMaterialQuality:()=>Mi,setMaxAnisotropy:()=>ci,setMaxTextureSize:()=>ui,setSrgbTextureDecode:()=>mi,steps:()=>fc,worldFromLngLat:()=>Qt});Vt(),ca(),ki(),yo(),wi(),Ar(),Ei(),Vt(),Ar(),wi(),Ei(),ki(),ca(),yo();var Wc=globalThis;return Wc.THREE||(Wc.THREE=t),Wc.S3M=Uc,e.Animator=xc,e.AttributeQuery=Jt,e.BinaryReader=x,e.DEFAULT_FLOOR_HEIGHT=Bt,e.DEFAULT_LIGHT_PRESET=Ao,e.DEFAULT_STYLE=Ui,e.DatasetManager=Sc,e.EARTH_RADIUS=Yt,e.EASING_NAMES=ec,e.FeatureStyleManager=Ss,e.GPUPathManager=Oi,e.GpuEdgePass=us,e.GroundManager=Cc,e.HostRenderer=Mc,e.LIGHT_PRESETS=Mo,e.Path=Ti,e.Picker=Us,e.PixelFormat=Y,e.S3MFormatError=Nt,e.S3MTileset=ko,e.S3MViewer=jc,e.default=jc,e.S3M_VERSION=rt,e.SAMPLES_PER_PATH=Di,e.SELECT_MODE=$,e.SELECT_MODE_LABELS=Vi,e.STYLE=Q,e.STYLE_LABELS=Bi,e.SUPERMAP_LIGHT_PRESET=jo,e.TextureCompress=X,e.VertexTag=B,e.VertexTagV3=it,e.authFetch=Ut,e.buildAttributes=zt,e.buildBlendedMVP=Hc,e.buildFeatureEdgeSegments=as,e.buildNearScaledMVP=Vc,e.buildOrthoMVP=Bc,e.buildThickLineGeometry=es,e.buildTileObjects=fo,e.createLineSharedUniforms=Xo,e.createOutlineMaterial=zi,e.createSharedUniforms=Ii,e.createStyledMaterial=Li,e.createTexture=_i,e.createThickLineMaterial=$o,e.cubicBezier=dc,e.dxtPixelFormatOf=Or,e.easing=tc,e.extractEulerAngles=_s,e.extractFovRadians=zc,e.extractNearFar=Rc,e.extractProjectionMatrix=Lc,e.getColorPipeline=Fi,e.getMaterialQuality=Ni,e.isS3M1Buffer=Le,e.lngLatFromMercator=Zt,e.lngLatFromWorld=$t,e.measureSegments=Rt,e.mercatorFromLngLat=Xt,e.parseS3M1=nt,e.parseS3MB=Pt,e.planDegradations=It,e.resolveAuthRequest=Ht,e.resolveEdgeModes=Ai,e.resolveFeature=U,e.resolveLightingPreset=No,e.resolveRotationMatrix=gs,e.resolveTextureKind=Dr,e.sameEdgeModes=ji,e.setColorPipeline=Pi,e.setMaterialQuality=Mi,e.setMaxAnisotropy=ci,e.setMaxTextureSize=ui,e.setSrgbTextureDecode=mi,e.steps=fc,e.worldFromLngLat=Qt,e})({},THREE);
|
|
1395
|
+
`}),a=new t.Mesh(e,i);a.position.set(0,0,-.02),a.renderOrder=-1e3,a.name=`s3m-ground-depth`,a.visible=!1,this.group.add(a),this._depthMesh=a,this._depthMaterial=i,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()}};wi(),ca(),Ei(),ki(),b();function Ec(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function Dc(e){return e.isPoints===!0}function Oc(e){let t=e??1;return t<0?0:t>1?1:t}var kc=.001,Ac=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`metalness`,`roughness`,`edgeWidth`,`edgeOpacity`,`edgeOffset`,`edgeHullWidth`,`outlineWidth`],jc=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],Mc=[`translation`,`elevation`,`opacity`,`color`,`rotation`],Nc=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={}){y(this,`options`,void 0),y(this,`pickable`,void 0),y(this,`onStats`,void 0),y(this,`onReady`,void 0),y(this,`onPick`,void 0),y(this,`onError`,void 0),y(this,`geo`,null),y(this,`canvas`,null),y(this,`renderer`,null),y(this,`scene`,null),y(this,`camera`,null),y(this,`picker`,null),y(this,`uniforms`,void 0),y(this,`style`,void 0),y(this,`_styleTarget`,void 0),y(this,`outlineMaterial`,void 0),y(this,`lineShared`,void 0),y(this,`edgeMaterial`,void 0),y(this,`selectionEdgeMaterial`,void 0),y(this,`_edges`,void 0),y(this,`groundManager`,void 0),y(this,`_datasetManager`,new wc),y(this,`_featureStyleManager`,void 0),y(this,`gpuPathManager`,new Oi),y(this,`_customPathTime`,!1),y(this,`_picks`,void 0),y(this,`_smidMeshes`,new Map),y(this,`_heights`,void 0),y(this,`_sel`,void 0),y(this,`_tileFadeSeq`,0),y(this,`_modeGen`,0),y(this,`_shadingPrewarmed`,!1),y(this,`_prewarmShadingEnabled`,!0),y(this,`_prewarming`,!1),y(this,`_pathSpecs`,new Map),y(this,`_pathScratch`,new Float32Array(3)),y(this,`_pathScratch2`,new Float32Array(3)),y(this,`_pointClouds`,new Set),y(this,`_splats`,new Zo),y(this,`_opacityTransparent`,!1),y(this,`animator`,new Cc),y(this,`attributeQuery`,null),y(this,`_enuMatrix`,new t.Matrix4),y(this,`_frameMvp`,new t.Matrix4),y(this,`_colorScratch`,new t.Color),y(this,`_frame`,0),y(this,`_fps`,{value:0,last:0}),y(this,`_lights`,void 0),y(this,`_datasetQueue`,void 0),y(this,`_onRequestRepaint`,()=>{}),y(this,`_getBearing`,void 0),y(this,`_authenticate`,void 0),y(this,`_lodRangeScale`,1),y(this,`_unsupported`,void 0),y(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,ui(e.maxTextureSize??1/0),Mi(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 Tc(e.ground),this.scene||(this.scene=new t.Scene,this.scene.add(this.groundManager.group)),this._featureStyleManager=new ws(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._sel.selection&&this._sel.syncStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=Ii(),this._lights=new Lo({scene:()=>this.scene,renderer:()=>this.renderer,uniforms:this.uniforms,options:this.options,getBearing:()=>this._getBearing?.(),repaint:()=>this.triggerRepaint()}),this._lights.addToScene(),this._heights=new Ro(this.uniforms);let n=this;this._picks=new Es({get picker(){return n.picker},get camera(){return n.camera},get scene(){return n.scene},get canvas(){return n.canvas},get style(){return n.style},get sceneAnchor(){return n.sceneAnchor},get datasets(){return n.datasets},get featureStyleManager(){return n._featureStyleManager},get smidMeshes(){return n._smidMeshes},lngLatFromWorld:(e,t)=>n._lngLatFromWorld(e,t),gpuPathPoseAt:e=>n._gpuPathPoseAt(e),isFeatureHidden:(e,t)=>n._isFeatureHidden(e,t)}),fi(dn),this.style={...Ui,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=zi(this.uniforms),this._edges=new gs({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 As({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 Jt({...e.attributes,authenticate:e.attributes.authenticate??this._authenticate}))}_createRenderer(e,n){let r=new t.WebGLRenderer({canvas:e,context:n,antialias:!0});return r.autoClear=!1,r.setPixelRatio(1),r.toneMapping=this.options.toneMapping===void 0?t.NoToneMapping:this.options.toneMapping,r.toneMappingExposure=this.options.toneMappingExposure??1,r}_syncTextureCapabilities(e){let t=!!e.getExtension(`WEBGL_compressed_texture_s3tc`),n=!!e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`);di(t&&n)}mount(e,n){this.canvas=e,this.renderer=this._createRenderer(e,n),ci(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(n),this.scene=new t.Scene,this.scene.add(this.groundManager.group),this._addLights(),this.camera=new t.Camera,this.camera.matrixAutoUpdate=!1,this.picker=new Gs(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),ci(this.renderer.capabilities.getMaxAnisotropy(),this.options.anisotropyCap??1/0),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new Gs(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 $t(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=ys(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=ys(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 Ti?t:new Ti(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=ys(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=ys(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 Mc)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 Jt({...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=Ec(t);r&&r.dispose(),Rs(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=Dc(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=Ec(o);if(e){let t=Oc(this.style.opacity),n=this.style.depthWrite!==!1;Ri(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),Ri(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),Dc(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),Ec(t)?.dispose?.()}Rs(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:Bi[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 jc.includes(e)?3:1}_registerAnimChannels(){for(let e of Ac)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 jc)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??$.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===$.REPLACE?0:n===$.MULTIPLY?2:n===$.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=Oc(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=Oc(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(Dc(n.mesh))continue;let r=Ec(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||Ri(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)){Ls(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=Ec(t.mesh)?.userData.uFlatShading;n&&n.value!==e&&(n.value=e)}this._requestRepaint()}setMaterialQuality(e){Mi(e),this._rebuildStyledMaterials(),this._requestRepaint()}get materialQuality(){return Ni()}_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=Li({...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(Ec(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,ci(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,ui(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===Q.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),to(r.width,r.height),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),(this.uniforms.uOpacity?.value??1)>kc&&(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===Q.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=Eo(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()}};b();var Pc=class e{constructor(t={}){y(this,`id`,void 0),y(this,`options`,void 0),y(this,`pickable`,void 0),y(this,`onStats`,void 0),y(this,`onReady`,void 0),y(this,`onPick`,void 0),y(this,`onError`,void 0),y(this,`viewer`,void 0),y(this,`_projection`,`perspective`),y(this,`_projectionT`,0),y(this,`_orthoWarned`,!1),y(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 Nc({...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}},Fc=1e-4;function Ic(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])>Fc*r)return!1}return!0}function Lc(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 Rc(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function zc(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Bc(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 Vc(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 Hc(e,n){let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new t.Matrix4().fromArray(Array.from(r)),a=new t.Matrix4().fromArray(Array.from(e.mvp));if(i.determinant()===0||!Rc(i,n.fov))return null;let o=i.clone().invert().multiply(a);if(!Ic(i.clone().multiply(o),Array.from(e.mvp))||!Lc(o)||!Rc(i,n.fov))return null;let{distance:s,fov:c,aspect:l}=n;if(!(s>0)||!(c>0)||!(l>0))return null;let u=s*Math.tan(c/2),d=u*l,f=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,p=e.farZ!=null&&e.farZ>f?e.farZ:s*4+1e3;p>f||(p=f+1e3);let m=new t.OrthographicCamera(-d,d,u,-u,f,p);return m.updateProjectionMatrix(),{matrix:m.projectionMatrix.clone().multiply(o),view:o}}function Uc(e,n){if(!(n>0)||n>=1)return null;let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new t.Matrix4().fromArray(Array.from(r));if(!Number.isFinite(i.determinant())||i.determinant()===0||Math.abs(i.elements[11]+1)>1e-6)return null;let a=e.nearZ!=null&&e.nearZ>0?e.nearZ:NaN,o=e.farZ!=null&&e.farZ>a?e.farZ:NaN;if(!(a>0)||!(o>a)){let e=-i.elements[10];if(!(e>1)||(a=-i.elements[14]/(e+1),o=a*(e+1)/(e-1),!(a>0)||!(o>a)))return null}let s=a*n;if(!(s>0)||!(s<o))return null;let c=i.clone();c.elements[10]=-(o+s)/(o-s),c.elements[14]=-2*o*s/(o-s);let l=c.multiply(i.clone().invert()).multiply(new t.Matrix4().fromArray(Array.from(e.mvp)));for(let e=0;e<16;e++)if(!Number.isFinite(l.elements[e]))return null;return l}function Wc(e,n,r){let i=e.projectionMatrix;if(!i||i.length<16)return null;let a=new t.Matrix4().fromArray(Array.from(i)),o=new t.Matrix4().fromArray(Array.from(e.mvp));if(a.determinant()===0||!Rc(a,n.fov))return null;let s=a.clone().invert().multiply(o);if(!Ic(a.clone().multiply(s),Array.from(e.mvp))||!Lc(s))return null;let c=Math.max(0,Math.min(1,r));if(c<=0)return{matrix:o,view:s};let{distance:l,fov:u,aspect:d}=n;if(!(l>0)||!(u>0)||!(d>0))return null;let f=l*Math.tan(u/2),p=f*d,m=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,h=e.farZ!=null&&e.farZ>m?e.farZ:l*4+1e3;h>m||(h=m+1e3);let g=new t.OrthographicCamera(-p,p,f,-f,m,h);if(g.updateProjectionMatrix(),c>=1)return{matrix:g.projectionMatrix.clone().multiply(s),view:s};let _=new t.Matrix4,v=a.elements,y=g.projectionMatrix.elements,b=_.elements;for(let e=0;e<16;e++)b[e]=(1-c)*v[e]+c*y[e];return{matrix:_.multiply(s),view:s}}var Gc=l({Animator:()=>Cc,AttributeQuery:()=>Jt,BinaryReader:()=>x,DEFAULT_FLOOR_HEIGHT:()=>Bt,DEFAULT_LIGHT_PRESET:()=>Mo,DEFAULT_STYLE:()=>Ui,DatasetManager:()=>wc,EARTH_RADIUS:()=>Yt,EASING_NAMES:()=>nc,FeatureStyleManager:()=>ws,GPUPathManager:()=>Oi,GpuEdgePass:()=>fs,GroundManager:()=>Tc,HostRenderer:()=>Pc,LIGHT_PRESETS:()=>Po,Path:()=>Ti,Picker:()=>Gs,PixelFormat:()=>Y,S3MFormatError:()=>Nt,S3MTileset:()=>jo,S3MViewer:()=>Nc,S3M_VERSION:()=>rt,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>$,SELECT_MODE_LABELS:()=>Vi,STYLE:()=>Q,STYLE_LABELS:()=>Bi,SUPERMAP_LIGHT_PRESET:()=>No,TextureCompress:()=>X,VertexTag:()=>B,VertexTagV3:()=>it,authFetch:()=>Ut,buildAttributes:()=>zt,buildBlendedMVP:()=>Wc,buildFeatureEdgeSegments:()=>ss,buildNearScaledMVP:()=>Uc,buildOrthoMVP:()=>Hc,buildThickLineGeometry:()=>ns,buildTileObjects:()=>fo,createLineSharedUniforms:()=>Qo,createOutlineMaterial:()=>zi,createSharedUniforms:()=>Ii,createStyledMaterial:()=>Li,createTexture:()=>_i,createThickLineMaterial:()=>ts,cubicBezier:()=>pc,default:()=>Nc,dxtPixelFormatOf:()=>Or,easing:()=>rc,extractEulerAngles:()=>ys,extractFovRadians:()=>Vc,extractNearFar:()=>Bc,extractProjectionMatrix:()=>zc,getColorPipeline:()=>Fi,getMaterialQuality:()=>Ni,isS3M1Buffer:()=>Le,lngLatFromMercator:()=>Zt,lngLatFromWorld:()=>$t,measureSegments:()=>Rt,mercatorFromLngLat:()=>Xt,parseS3M1:()=>nt,parseS3MB:()=>Pt,planDegradations:()=>It,resolveAuthRequest:()=>Ht,resolveEdgeModes:()=>Ai,resolveFeature:()=>U,resolveLightingPreset:()=>Fo,resolveRotationMatrix:()=>vs,resolveTextureKind:()=>Dr,sameEdgeModes:()=>ji,setColorPipeline:()=>Pi,setMaterialQuality:()=>Mi,setMaxAnisotropy:()=>ci,setMaxTextureSize:()=>ui,setSrgbTextureDecode:()=>mi,steps:()=>mc,worldFromLngLat:()=>Qt});Vt(),ca(),ki(),yo(),wi(),Ar(),Ei(),Vt(),Ar(),wi(),Ei(),ki(),ca(),yo();var Kc=globalThis;return Kc.THREE||(Kc.THREE=t),Kc.S3M=Gc,e.Animator=Cc,e.AttributeQuery=Jt,e.BinaryReader=x,e.DEFAULT_FLOOR_HEIGHT=Bt,e.DEFAULT_LIGHT_PRESET=Mo,e.DEFAULT_STYLE=Ui,e.DatasetManager=wc,e.EARTH_RADIUS=Yt,e.EASING_NAMES=nc,e.FeatureStyleManager=ws,e.GPUPathManager=Oi,e.GpuEdgePass=fs,e.GroundManager=Tc,e.HostRenderer=Pc,e.LIGHT_PRESETS=Po,e.Path=Ti,e.Picker=Gs,e.PixelFormat=Y,e.S3MFormatError=Nt,e.S3MTileset=jo,e.S3MViewer=Nc,e.default=Nc,e.S3M_VERSION=rt,e.SAMPLES_PER_PATH=Di,e.SELECT_MODE=$,e.SELECT_MODE_LABELS=Vi,e.STYLE=Q,e.STYLE_LABELS=Bi,e.SUPERMAP_LIGHT_PRESET=No,e.TextureCompress=X,e.VertexTag=B,e.VertexTagV3=it,e.authFetch=Ut,e.buildAttributes=zt,e.buildBlendedMVP=Wc,e.buildFeatureEdgeSegments=ss,e.buildNearScaledMVP=Uc,e.buildOrthoMVP=Hc,e.buildThickLineGeometry=ns,e.buildTileObjects=fo,e.createLineSharedUniforms=Qo,e.createOutlineMaterial=zi,e.createSharedUniforms=Ii,e.createStyledMaterial=Li,e.createTexture=_i,e.createThickLineMaterial=ts,e.cubicBezier=pc,e.dxtPixelFormatOf=Or,e.easing=rc,e.extractEulerAngles=ys,e.extractFovRadians=Vc,e.extractNearFar=Bc,e.extractProjectionMatrix=zc,e.getColorPipeline=Fi,e.getMaterialQuality=Ni,e.isS3M1Buffer=Le,e.lngLatFromMercator=Zt,e.lngLatFromWorld=$t,e.measureSegments=Rt,e.mercatorFromLngLat=Xt,e.parseS3M1=nt,e.parseS3MB=Pt,e.planDegradations=It,e.resolveAuthRequest=Ht,e.resolveEdgeModes=Ai,e.resolveFeature=U,e.resolveLightingPreset=Fo,e.resolveRotationMatrix=vs,e.resolveTextureKind=Dr,e.sameEdgeModes=ji,e.setColorPipeline=Pi,e.setMaterialQuality=Mi,e.setMaxAnisotropy=ci,e.setMaxTextureSize=ui,e.setSrgbTextureDecode=mi,e.steps=mc,e.worldFromLngLat=Qt,e})({},THREE);
|