s3m-three 0.4.23 → 0.4.24
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/analysis/clipping.d.ts +63 -0
- package/dist/analysis/clipping.d.ts.map +1 -0
- package/dist/analysis/clipping.js +69 -0
- package/dist/analysis/clipping.js.map +1 -0
- package/dist/analysis/depth.d.ts +55 -0
- package/dist/analysis/depth.d.ts.map +1 -0
- package/dist/analysis/depth.js +99 -0
- package/dist/analysis/depth.js.map +1 -0
- package/dist/analysis/index.d.ts +21 -0
- package/dist/analysis/index.d.ts.map +1 -0
- package/dist/analysis/index.js +17 -0
- package/dist/analysis/index.js.map +1 -0
- package/dist/analysis/lineOfSight.d.ts +60 -0
- package/dist/analysis/lineOfSight.d.ts.map +1 -0
- package/dist/analysis/lineOfSight.js +56 -0
- package/dist/analysis/lineOfSight.js.map +1 -0
- package/dist/analysis/measure.d.ts +56 -0
- package/dist/analysis/measure.d.ts.map +1 -0
- package/dist/analysis/measure.js +95 -0
- package/dist/analysis/measure.js.map +1 -0
- package/dist/analysis/skyline.d.ts +55 -0
- package/dist/analysis/skyline.d.ts.map +1 -0
- package/dist/analysis/skyline.js +78 -0
- package/dist/analysis/skyline.js.map +1 -0
- package/dist/analysis/viewshed.d.ts +48 -0
- package/dist/analysis/viewshed.d.ts.map +1 -0
- package/dist/analysis/viewshed.js +115 -0
- package/dist/analysis/viewshed.js.map +1 -0
- package/dist/browser/s3m-three.iife.ext-three.js +20 -3
- package/dist/browser/s3m-three.iife.js +20 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/render/S3MViewer.d.ts +106 -0
- package/dist/render/S3MViewer.d.ts.map +1 -1
- package/dist/render/S3MViewer.js +174 -1
- package/dist/render/S3MViewer.js.map +1 -1
- package/dist/render/analysis/DepthPass.d.ts +78 -0
- package/dist/render/analysis/DepthPass.d.ts.map +1 -0
- package/dist/render/analysis/DepthPass.js +209 -0
- package/dist/render/analysis/DepthPass.js.map +1 -0
- package/dist/render/viewer/PickService.d.ts +15 -0
- package/dist/render/viewer/PickService.d.ts.map +1 -1
- package/dist/render/viewer/PickService.js +41 -0
- package/dist/render/viewer/PickService.js.map +1 -1
- package/docs/API.md +100 -0
- package/package.json +1 -1
- package/src/analysis/clipping.ts +135 -0
- package/src/analysis/depth.ts +126 -0
- package/src/analysis/index.ts +47 -0
- package/src/analysis/lineOfSight.ts +110 -0
- package/src/analysis/measure.ts +119 -0
- package/src/analysis/skyline.ts +125 -0
- package/src/analysis/viewshed.ts +160 -0
- package/src/index.ts +5 -0
- package/src/render/S3MViewer.ts +233 -2
- package/src/render/analysis/DepthPass.ts +278 -0
- package/src/render/viewer/PickService.ts +47 -0
|
@@ -1146,7 +1146,7 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1146
1146
|
}
|
|
1147
1147
|
`,hs=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:ps,fragmentShader:ms,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?.()})}};da(),b();function gs(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function _s(e){let t=e??1;return t<0?0:t>1?1:t}var vs=[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`],ys=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=ji(!1),this.lineShared=ts(),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=is(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=is(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||bs(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))*_s(i.opacity)*a;if(o<=.004||(this._gpuEdge||(this._gpuEdge=new hs),!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=gs(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 is(this.lineShared,{},t?this._selEdgeStyleUniforms:this._edgeStyleUniforms,i)}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring),r=ji(e),i=!Mi(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!bs(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 Ht(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))*_s(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))*_s(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)*_s(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 vs.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=fs(e.geometry,.005),a=this.host.style.edgeThreshold??55,o,s;if(this._modes.offset){let e=[];o=us(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=os(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(ss(o[e],o[e+1],o[e+2],1/c))??-1}}let d=new t.Mesh(as(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=Hi(this.host.uniforms,this.host.style.edgeHullWidth??.9,this._hullStyleUniforms,!0);r.uniforms.uSelWhole.value=1,r.uniforms.uSelBatch.value=-1;let i=gs(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=gs(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 is(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 bs(e){return e.isPoints===!0}Bt(),da(),b();function xs(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 Ss(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 Cs(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function ws(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 Ts(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 Es(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 Ds=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=ws(a,(t+n)/2),c=r+t*i,l=r+n*i;u.push({color:`#${o.getHexString()}`,label:`${Es(c)} ~ ${Es(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?Ts(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=U(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=U(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}=W(v.geoRef,r),t=Rt({smid:n,box:Lt(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=xs(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=Cs(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()&&Vi(n,!1);return}let s=0;for(let e of Object.values(r)){let t=U(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()&&Vi(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=Cs(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=U(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=Cs(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=Cs(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)}};Bt(),$a(),b();var Os=65534,ks=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>Os){for(let e=0;e<=Os;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=W(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?U(d):-1,m=d?.segments??(p>=0?W(e.geoRef,p).segments:[]),h=Lt(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=Lt(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=Rt({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=xs(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=Ja(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=Rt({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=W(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=It(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=W(u,U(n));if(f=Lt(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?xs(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=It(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}}};Bt(),b();function As(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function js(e){let t=e??1;return t<0?0:t>1?1:t}function Ms(e){return e.isPoints===!0}var Ns=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(Ms(e)){this.host.applyPointCloudStyle(e,!1);continue}let t=As(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=As(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?U(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)Ms(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=>!Ms(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?U(n):-1}else if(e.smid!=null){let t=i?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],r=n?U(n):-1;o=r,a=n?.segments??(r>=0?W(i,r).segments:[])}else r===e.mesh&&(a=W(n.geoByBatchId?.get(e.batchId)??i,e.batchId).segments,o=e.batchId);let s=us(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(as(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=As(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=js(e.opacity),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?As(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=As(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?U(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),Ms(e)&&this.host.applyPointCloudStyle(e,!0),this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers}};da();var Ps=2;function Fs(e){return e===Q.SOLID?`solid`:e===Q.HEIGHT?`height`:`vertex`}var Is=`
|
|
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=Cs(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=U(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=Cs(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=Cs(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)}};Bt(),$a(),b();var Os=65534,ks=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>Os){for(let e=0;e<=Os;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=W(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?U(d):-1,m=d?.segments??(p>=0?W(e.geoRef,p).segments:[]),h=Lt(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=Lt(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=Rt({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=xs(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=Ja(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=Rt({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}raycastDistance(e,n,r){if(!this.host.scene)return null;let i=[...this.pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0});if(!i.length)return null;let a=new t.Raycaster;a.set(new t.Vector3(e[0],e[1],e[2]),new t.Vector3(n[0],n[1],n[2]).normalize()),a.near=0,a.far=r;let o=a.intersectObjects(i,!1);if(!o.length)return null;let s=o[0];return{distance:s.distance,point:[s.point.x,s.point.y,s.point.z]}}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=W(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=It(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=W(u,U(n));if(f=Lt(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?xs(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=It(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}}};Bt(),b();function As(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function js(e){let t=e??1;return t<0?0:t>1?1:t}function Ms(e){return e.isPoints===!0}var Ns=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(Ms(e)){this.host.applyPointCloudStyle(e,!1);continue}let t=As(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=As(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?U(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)Ms(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=>!Ms(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?U(n):-1}else if(e.smid!=null){let t=i?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],r=n?U(n):-1;o=r,a=n?.segments??(r>=0?W(i,r).segments:[])}else r===e.mesh&&(a=W(n.geoByBatchId?.get(e.batchId)??i,e.batchId).segments,o=e.batchId);let s=us(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(as(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=As(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=js(e.opacity),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?As(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=As(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?U(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),Ms(e)&&this.host.applyPointCloudStyle(e,!0),this.host.uniforms.uSelMix.value=1,this.host.uniforms.uDim.value=+!!this.host.style.dimOthers}};da();var Ps=2;function Fs(e){return e===Q.SOLID?`solid`:e===Q.HEIGHT?`height`:`vertex`}var Is=`
|
|
1150
1150
|
uniform float uPointSize;
|
|
1151
1151
|
varying float vWorldZ;
|
|
1152
1152
|
void main() {
|
|
@@ -1314,7 +1314,24 @@ 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
|
-
`,Ws=(()=>{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})(),Gs=(()=>{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 Ks(e){return new t.ShaderMaterial({uniforms:{uObjectId:{value:e},uBatchTex:{value:Ws},uBatchTex2:{value:Ws},uBatchMix:{value:0},uBatchTexWidth:{value:1},uBatchTexActive:{value:0},uPathTex:{value:Gs},uPathCount:{value:1},uPathTime:{value:0},uPathTexActive:{value:0},uSelBatch:{value:-1},uSelWhole:{value:0},uSelElevation:{value:0}},vertexShader:Hs,fragmentShader:Us,side:t.DoubleSide,depthTest:!0,depthWrite:!0,toneMapped:!1})}function qs(e){return e.isPoints===!0}var Js=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&&!qs(t))return;let n=t.userData;if(n.pickId===void 0)return;let r=n.isGaussianSplat===!0;n.pickMaterial||(n.pickMaterial=r?qa(n.pickId):Ks(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=Ws,a.uniforms.uBatchTex2.value=Ws,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??Gs,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||qs(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}},Ys=1.70158,Xs=Ys*1.525,Zs=2.70158,Qs=2*Math.PI/3,$s=2*Math.PI/4.5,ec=7.5625,tc=2.75;function nc(e){if(e<1/tc)return ec*e*e;if(e<2/tc){let t=e-1.5/tc;return ec*t*t+.75}if(e<2.5/tc){let t=e-2.25/tc;return ec*t*t+.9375}let t=e-2.625/tc;return ec*t*t+.984375}function rc(e){return 1-nc(1-e)}var ic={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=>Zs*e*e*e-Ys*e*e,easeOutBack:e=>1+Zs*(e-1)**3+Ys*(e-1)**2,easeInOutBack:e=>e<.5?(2*e)**2*(7.189819*e-Xs)/2:((2*e-2)**2*(3.5949095*(e*2-2)+Xs)+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)*$s))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*$s)/2+1,easeInBounce:rc,easeOutBounce:nc,easeInOutBounce:e=>e<.5?(1-rc(1-2*e))/2:(1+rc(2*e-1))/2},ac=Object.keys(ic);function oc(e){if(typeof e==`function`)return e;let t=ic[e];if(!t)throw Error(`[s3m] 未知的缓动曲线: ${String(e)}`);return t}var sc=8,cc=.001,lc=1e-7,uc=12,dc=(e,t)=>1-3*t+3*e,fc=(e,t)=>3*t-6*e,pc=e=>3*e;function mc(e,t,n){return((dc(t,n)*e+fc(t,n))*e+pc(t))*e}function hc(e,t,n){return 3*dc(t,n)*e*e+2*fc(t,n)*e+pc(t)}function gc(e,t,n,r){if(e===t&&n===r)return e=>e;let i=t=>{let r=t;for(let i=0;i<sc;i++){let i=hc(r,e,n);if(Math.abs(i)<cc)break;let a=mc(r,e,n)-t;if(Math.abs(a)<lc)return r;r-=a/i}let i=0,a=1;r=t;for(let o=0;o<uc;o++){let o=mc(r,e,n);if(Math.abs(o-t)<lc)return r;o<t?i=r:a=r,r=(i+a)/2}return r};return e=>e<=0?0:e>=1?1:mc(i(e),t,r)}function _c(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 vc=1e-4,yc=.15;function bc(e){return e<0?0:e>1?1:e}function xc(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 Sc=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}},Cc=class extends Sc{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`,oc(`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?oc(t.easing):oc(`linear`),this._retarget=t.retarget??`proportional`,this._span=xc(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:bc(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>vc){let e=xc(this._from,this.to,this.dim)/this._span;i=Math.min(r,Math.max(r*yc,r*e))}this._start=t,this._delay=Math.max(0,n.delay??0),this._duration=i,this._ease=n.easing?oc(n.easing):this._ease,this._span=xc(this._from,this.to,this.dim),this._progress=0,this.done=!1}},wc=class extends Sc{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}=Tc(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=Tc(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 Tc(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 Ec=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 wc;if(c&&c!=null&&u!==l&&(this._tracks.delete(e),c=void 0),c||this.onActive?.(),!c){let t=l?new wc(e,r):new Cc(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 Dc=class{constructor(){y(this,`datasets`,new Map),y(this,`sceneAnchor`,null),y(this,`totalMaxTiles`,0),y(this,`defaultMaterialQuality`,void 0),y(this,`defaultColorPipeline`,void 0),y(this,`defaultTextureOptions`,void 0)}setDefaultMaterialQuality(e){this.defaultMaterialQuality=e;for(let t of this.datasets.values())t.options.materialQuality||t.tileset?.setMaterialQuality(e)}setRenderProfile(e){e.colorPipeline!==void 0&&(this.defaultColorPipeline=e.colorPipeline),e.textureOptions!==void 0&&(this.defaultTextureOptions=e.textureOptions);for(let t of this.datasets.values())t.tileset?.setRenderProfile(e)}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 Po({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,materialQuality:e.materialQuality??this.defaultMaterialQuality,colorPipeline:this.defaultColorPipeline,textureOptions:this.defaultTextureOptions,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=Zt(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0));let n=this.sceneAnchor.meterInMercator,r=Zt(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=ko(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 Oc=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
|
+
`,Ws=(()=>{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})(),Gs=(()=>{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 Ks(e){return new t.ShaderMaterial({uniforms:{uObjectId:{value:e},uBatchTex:{value:Ws},uBatchTex2:{value:Ws},uBatchMix:{value:0},uBatchTexWidth:{value:1},uBatchTexActive:{value:0},uPathTex:{value:Gs},uPathCount:{value:1},uPathTime:{value:0},uPathTexActive:{value:0},uSelBatch:{value:-1},uSelWhole:{value:0},uSelElevation:{value:0}},vertexShader:Hs,fragmentShader:Us,side:t.DoubleSide,depthTest:!0,depthWrite:!0,toneMapped:!1})}function qs(e){return e.isPoints===!0}var Js=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&&!qs(t))return;let n=t.userData;if(n.pickId===void 0)return;let r=n.isGaussianSplat===!0;n.pickMaterial||(n.pickMaterial=r?qa(n.pickId):Ks(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=Ws,a.uniforms.uBatchTex2.value=Ws,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??Gs,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||qs(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}},Ys=1.70158,Xs=Ys*1.525,Zs=2.70158,Qs=2*Math.PI/3,$s=2*Math.PI/4.5,ec=7.5625,tc=2.75;function nc(e){if(e<1/tc)return ec*e*e;if(e<2/tc){let t=e-1.5/tc;return ec*t*t+.75}if(e<2.5/tc){let t=e-2.25/tc;return ec*t*t+.9375}let t=e-2.625/tc;return ec*t*t+.984375}function rc(e){return 1-nc(1-e)}var ic={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=>Zs*e*e*e-Ys*e*e,easeOutBack:e=>1+Zs*(e-1)**3+Ys*(e-1)**2,easeInOutBack:e=>e<.5?(2*e)**2*(7.189819*e-Xs)/2:((2*e-2)**2*(3.5949095*(e*2-2)+Xs)+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)*$s))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*$s)/2+1,easeInBounce:rc,easeOutBounce:nc,easeInOutBounce:e=>e<.5?(1-rc(1-2*e))/2:(1+rc(2*e-1))/2},ac=Object.keys(ic);function oc(e){if(typeof e==`function`)return e;let t=ic[e];if(!t)throw Error(`[s3m] 未知的缓动曲线: ${String(e)}`);return t}var sc=8,cc=.001,lc=1e-7,uc=12,dc=(e,t)=>1-3*t+3*e,fc=(e,t)=>3*t-6*e,pc=e=>3*e;function mc(e,t,n){return((dc(t,n)*e+fc(t,n))*e+pc(t))*e}function hc(e,t,n){return 3*dc(t,n)*e*e+2*fc(t,n)*e+pc(t)}function gc(e,t,n,r){if(e===t&&n===r)return e=>e;let i=t=>{let r=t;for(let i=0;i<sc;i++){let i=hc(r,e,n);if(Math.abs(i)<cc)break;let a=mc(r,e,n)-t;if(Math.abs(a)<lc)return r;r-=a/i}let i=0,a=1;r=t;for(let o=0;o<uc;o++){let o=mc(r,e,n);if(Math.abs(o-t)<lc)return r;o<t?i=r:a=r,r=(i+a)/2}return r};return e=>e<=0?0:e>=1?1:mc(i(e),t,r)}function _c(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 vc=1e-4,yc=.15;function bc(e){return e<0?0:e>1?1:e}function xc(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 Sc=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}},Cc=class extends Sc{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`,oc(`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?oc(t.easing):oc(`linear`),this._retarget=t.retarget??`proportional`,this._span=xc(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:bc(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>vc){let e=xc(this._from,this.to,this.dim)/this._span;i=Math.min(r,Math.max(r*yc,r*e))}this._start=t,this._delay=Math.max(0,n.delay??0),this._duration=i,this._ease=n.easing?oc(n.easing):this._ease,this._span=xc(this._from,this.to,this.dim),this._progress=0,this.done=!1}},wc=class extends Sc{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}=Tc(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=Tc(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 Tc(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 Ec=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 wc;if(c&&c!=null&&u!==l&&(this._tracks.delete(e),c=void 0),c||this.onActive?.(),!c){let t=l?new wc(e,r):new Cc(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}};function Dc(e,t){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2];return Math.sqrt(n*n+r*r+i*i)}function Oc(e,t){let n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)}function kc(e,t){return t[2]-e[2]}function Ac(e){let t=0;for(let n=1;n<e.length;n++)t+=Dc(e[n-1],e[n]);return t}function jc(e){let t=0;for(let n=1;n<e.length;n++)t+=Oc(e[n-1],e[n]);return t}function Mc(e){return e.length<2?0:Ac(e)+Dc(e[e.length-1],e[0])}function Nc(e){let t=e.length;if(t<3)return 0;let n=0,r=0,i=0;for(let a=0;a<t;a++){let o=e[a],s=e[(a+1)%t];n+=(o[1]-s[1])*(o[2]+s[2]),r+=(o[2]-s[2])*(o[0]+s[0]),i+=(o[0]-s[0])*(o[1]+s[1])}return Math.sqrt(n*n+r*r+i*i)/2}function Pc(e){let t=e.length;if(t<3)return 0;let n=0;for(let r=0;r<t;r++){let i=e[r],a=e[(r+1)%t];n+=i[0]*a[1]-a[0]*i[1]}return Math.abs(n)/2}function Fc(e,t){return{distance3D:Dc(e,t),distanceHorizontal:Oc(e,t),heightDiff:kc(e,t)}}function Ic(e,t,n,r={}){let i=Dc(e,t);if(i<=1e-6)return{visible:!0,distance:0,blockedDistance:null,blockedPoint:null,visibleRatio:1};let a=[(t[0]-e[0])/i,(t[1]-e[1])/i,(t[2]-e[2])/i],o=Math.max(0,r.originOffset??.05),s=Math.max(0,r.targetOffset??.05),c=Math.min(o+s,i*.5),l=[e[0]+a[0]*o,e[1]+a[1]*o,e[2]+a[2]*o],u=Math.max(0,i-c),d=n(l,a,u);if(d&&d.distance<u){let t=Math.min(i,d.distance+o);return{visible:!1,distance:i,blockedDistance:t,blockedPoint:d.point??[e[0]+a[0]*t,e[1]+a[1]*t,e[2]+a[2]*t],visibleRatio:Math.max(0,Math.min(1,t/i))}}return{visible:!0,distance:i,blockedDistance:null,blockedPoint:null,visibleRatio:1}}function Lc(e){let t=Math.hypot(e[0],e[1],e[2]);return t<1e-9?[0,0,1]:[e[0]/t,e[1]/t,e[2]/t]}function Rc(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function zc(e,t){let n=Lc(e);return{normal:n,constant:-Rc(n,t)}}function Bc(e,t){for(let n of e)if(Rc(n.normal,t)+n.constant<0)return!1;return!0}function Vc(e){return[zc(e.normal,e.point)]}function Hc(e){let t=[Math.min(e.a[0],e.b[0]),Math.min(e.a[1],e.b[1]),Math.min(e.a[2],e.b[2])],n=[Math.max(e.a[0],e.b[0]),Math.max(e.a[1],e.b[1]),Math.max(e.a[2],e.b[2])];return[{normal:[1,0,0],constant:-t[0]},{normal:[-1,0,0],constant:n[0]},{normal:[0,1,0],constant:-t[1]},{normal:[0,-1,0],constant:n[1]},{normal:[0,0,1],constant:-t[2]},{normal:[0,0,-1],constant:n[2]}]}function Uc(e){let t=[zc([e.keepX,0,0],e.center),zc([0,e.keepY,0],e.center)];return e.horizontal&&t.push(zc([0,0,e.keepZ??-1],e.center)),t}function Wc(e){switch(e.type){case`plane`:return Vc(e);case`box`:return Hc(e);case`cross`:return Uc(e)}}var Gc=256/255,Kc=255/256,qc=1/256,Jc=16777216;function Yc(e){let t=Math.min(1,Math.max(0,e));if(t<=0)return[0,0,0,0];if(t>=1)return[255,255,255,255];let n=Zc(t*Jc),r=Zc(n.int*qc),i=Zc(r.int*qc),a=e=>Math.max(0,Math.min(255,Math.round(e*255)));return[a(i.int/255),a(i.frac*Gc),a(r.frac*Gc),a(n.frac)]}function Xc(e,t=0){let n=e[t]/255,r=e[t+1]/255,i=e[t+2]/255,a=e[t+3]/255;return n*Kc+Kc/256*r+Kc/65536*i+a/Jc}function Zc(e){let t=Math.floor(e);return{frac:e-t,int:t}}function Qc(e,t,n,r){let i=n*2-1,a=r,o=a[0]*e+a[4]*t+a[8]*i+a[12],s=a[1]*e+a[5]*t+a[9]*i+a[13],c=a[2]*e+a[6]*t+a[10]*i+a[14],l=a[3]*e+a[7]*t+a[11]*i+a[15],u=Math.abs(l)>1e-12?1/l:1;return[o*u,s*u,c*u]}function $c(e,t,n,r){return[(e+.5)/n*2-1,1-(t+.5)/r*2]}function el(e,t){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],a=Math.hypot(n,r),o=Math.hypot(a,i);return{azimuth:(Math.atan2(n,r)*180/Math.PI+360)%360,elevation:Math.atan2(i,a)*180/Math.PI,distance:o}}function tl(e){let{rgba:t,width:n,height:r,inverseViewProj:i,cameraPos:a}=e,o=e.skyDepth??.9999,s=Math.max(1,Math.floor(e.step??1)),c=Math.ceil(n/s),l=new Float32Array(c),u=new Float32Array(c),d=new Float32Array(c*2),f=new Uint8Array(c),p=-90,m=90,h=0;for(let e=0;e<c;e++){let c=Math.min(n-1,e*s),g=!1;for(let s=0;s<r;s++){let h=Xc(t,(s*n+c)*4);if(h>=o)continue;let[_,v]=$c(c,s,n,r),{azimuth:y,elevation:b}=el(a,Qc(_,v,h,i));l[e]=y,u[e]=b,d[e*2]=(c+.5)/n,d[e*2+1]=(s+.5)/r,f[e]=1,b>p&&(p=b),b<m&&(m=b),g=!0;break}g||(h++,l[e]=0,u[e]=0,d[e*2]=(c+.5)/n,d[e*2+1]=1,f[e]=0,0>p&&(p=0),0<m&&(m=0))}return{azimuths:l,elevations:u,maxElevation:p,minElevation:m,openRatio:c>0?h/c:0,screen:d,hasGeometry:f}}function nl(e,t,n){let r=Math.max(.001,n.radius),i=Math.max(2,Math.floor(n.grid??96)),a=Math.max(0,n.bias??.5),o=n.groundZ??0,s=r*2/i,c=e[0]-r,l=e[1]-r,u=new Float32Array(i*i),d=0,f=0;for(let n=0;n<i;n++){let p=l+(n+.5)*s;for(let l=0;l<i;l++){let m=c+(l+.5)*s-e[0],h=p-e[1],g=o-e[2],_=Math.sqrt(m*m+h*h+g*g),v=n*i+l;if(_>r||_<1e-6){u[v]=-1;continue}let y=_<=t([m/_,h/_,g/_])+a;u[v]=+!!y,f++,y&&d++}}return{raster:u,grid:i,minX:c,minY:l,cellSize:s,visibleRatio:f>0?d/f:0}}function rl(e,t,n){return r=>{let[i,a,o]=r,s=Math.abs(i),c=Math.abs(a),l=Math.abs(o),u,d,f;if(s>=c&&s>=l){u=i>=0?0:1;let e=s;d=i>=0?-o/e:o/e,f=-a/e}else if(c>=l){u=a>=0?2:3;let e=c;d=i/e,f=a>=0?o/e:-o/e}else{u=o>=0?4:5;let e=l;d=o>=0?i/e:-i/e,f=-a/e}let p=e[u];if(!p)return 1/0;let m=Math.min(t-1,Math.max(0,Math.floor((d+1)/2*t))),h=Xc(p,(Math.min(t-1,Math.max(0,Math.floor((f+1)/2*t)))*t+m)*4);return h>=.9999?1/0:h*n}}function il(e,t){if(!t?.length)return()=>{};let n=t.filter(e=>e&&!e.parent);for(let t of n)e.add(t);return()=>{for(let t of n)e.remove(t)}}function al(e){return{target:e.getRenderTarget(),toneMapping:e.toneMapping,colorSpace:e.outputColorSpace,autoClear:e.autoClear,clearColor:e.getClearColor(new t.Color),clearAlpha:e.getClearAlpha()}}function ol(e,t){e.setRenderTarget(t.target),e.toneMapping=t.toneMapping,e.outputColorSpace=t.colorSpace,e.autoClear=t.autoClear,e.setClearColor(t.clearColor,t.clearAlpha)}function sl(e,t,n,r){let i=new Uint8Array(n*r*4);e.readRenderTargetPixels(t,0,0,n,r,i);let a=new Uint8Array(i.length),o=n*4;for(let e=0;e<r;e++)a.set(i.subarray((r-1-e)*o,(r-e)*o),e*o);return a}function cl(e,n){return new t.WebGLRenderTarget(e,n,{format:t.RGBAFormat,type:t.UnsignedByteType,minFilter:t.NearestFilter,magFilter:t.NearestFilter,depthBuffer:!0})}function ll(e,n,r,i){let a=e.renderer(),o=e.scene(),s=e.camera();if(!a||!o||!s)return null;let c=Math.max(1,Math.floor(n)),l=Math.max(1,Math.floor(r)),u=cl(c,l),d=new t.MeshDepthMaterial({depthPacking:t.RGBADepthPacking}),f=o.overrideMaterial,p=al(a),m=il(o,i),h=null;try{a.resetState(),a.setRenderTarget(u),a.toneMapping=t.NoToneMapping,a.outputColorSpace=t.LinearSRGBColorSpace,a.autoClear=!0,a.setClearColor(16777215,1),a.clear(),o.overrideMaterial=d,s.updateMatrixWorld(),a.render(o,s),h=sl(a,u,c,l)}finally{m(),o.overrideMaterial=f,ol(a,p),d.dispose(),u.dispose()}let g=new t.Matrix4().multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse),_=new Float32Array(g.clone().invert().elements),v=new t.Vector3().setFromMatrixPosition(s.matrixWorld);return{rgba:h,width:c,height:l,inverseViewProj:_,cameraPos:[v.x,v.y,v.z]}}var ul=[{forward:[1,0,0],up:[0,-1,0]},{forward:[-1,0,0],up:[0,-1,0]},{forward:[0,1,0],up:[0,0,1]},{forward:[0,-1,0],up:[0,0,-1]},{forward:[0,0,1],up:[0,-1,0]},{forward:[0,0,-1],up:[0,-1,0]}];function dl(e,n,r){return ul.map(({forward:i,up:a})=>{let o=new t.PerspectiveCamera(90,1,n,r);return o.up.set(a[0],a[1],a[2]),o.position.set(e[0],e[1],e[2]),o.lookAt(e[0]+i[0],e[1]+i[1],e[2]+i[2]),o.updateMatrixWorld(!0),o})}function fl(e,n,r,i,a){let o=e.renderer(),s=e.scene();if(!o||!s)return null;let c=Math.max(8,Math.floor(r)),l=cl(c,c),u=new t.ShaderMaterial({uniforms:{uOrigin:{value:new t.Vector3(n[0],n[1],n[2])},uMaxDist:{value:i}},vertexShader:`
|
|
1318
|
+
varying vec3 vWorld;
|
|
1319
|
+
void main() {
|
|
1320
|
+
vec4 world = modelMatrix * vec4( position, 1.0 );
|
|
1321
|
+
vWorld = world.xyz;
|
|
1322
|
+
gl_Position = projectionMatrix * viewMatrix * world;
|
|
1323
|
+
}
|
|
1324
|
+
`,fragmentShader:`
|
|
1325
|
+
#include <common>
|
|
1326
|
+
#include <packing>
|
|
1327
|
+
uniform vec3 uOrigin;
|
|
1328
|
+
uniform float uMaxDist;
|
|
1329
|
+
varying vec3 vWorld;
|
|
1330
|
+
void main() {
|
|
1331
|
+
float d = clamp( length( vWorld - uOrigin ) / uMaxDist, 0.0, 1.0 );
|
|
1332
|
+
gl_FragColor = packDepthToRGBA( d );
|
|
1333
|
+
}
|
|
1334
|
+
`}),d=s.overrideMaterial,f=al(o),p=il(s,a),m=dl(n,.1,i),h=[];try{o.resetState(),o.setRenderTarget(l),o.toneMapping=t.NoToneMapping,o.outputColorSpace=t.LinearSRGBColorSpace,o.autoClear=!0,o.setClearColor(16777215,1),s.overrideMaterial=u;for(let e of m)o.clear(),o.render(s,e),h.push(sl(o,l,c,c))}finally{p(),s.overrideMaterial=d,ol(o,f),u.dispose(),l.dispose()}return h}b();var pl=class{constructor(){y(this,`datasets`,new Map),y(this,`sceneAnchor`,null),y(this,`totalMaxTiles`,0),y(this,`defaultMaterialQuality`,void 0),y(this,`defaultColorPipeline`,void 0),y(this,`defaultTextureOptions`,void 0)}setDefaultMaterialQuality(e){this.defaultMaterialQuality=e;for(let t of this.datasets.values())t.options.materialQuality||t.tileset?.setMaterialQuality(e)}setRenderProfile(e){e.colorPipeline!==void 0&&(this.defaultColorPipeline=e.colorPipeline),e.textureOptions!==void 0&&(this.defaultTextureOptions=e.textureOptions);for(let t of this.datasets.values())t.tileset?.setRenderProfile(e)}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 Po({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,materialQuality:e.materialQuality??this.defaultMaterialQuality,colorPipeline:this.defaultColorPipeline,textureOptions:this.defaultTextureOptions,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=Zt(t,e.anchor.lon,e.anchor.lat,e.anchor.height??0));let n=this.sceneAnchor.meterInMercator,r=Zt(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=ko(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 ml=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
1335
|
varying vec2 vEnuPos;
|
|
1319
1336
|
void main() {
|
|
1320
1337
|
vec4 worldPos = modelMatrix * vec4(position, 1.0);
|
|
@@ -1392,4 +1409,4 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
|
|
|
1392
1409
|
}
|
|
1393
1410
|
gl_FragColor = vec4(1.0);
|
|
1394
1411
|
}
|
|
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()}};Ti(),da(),Di(),Ai(),b();function kc(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function Ac(e){return e.isPoints===!0}function jc(e){let t=e??1;return t<0?0:t>1?1:t}var Mc=.001,Nc=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`metalness`,`roughness`,`edgeWidth`,`edgeOpacity`,`edgeOffset`,`edgeHullWidth`,`outlineWidth`],Pc={metalness:0,roughness:.95},Fc=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],Ic=[`translation`,`elevation`,`opacity`,`color`,`rotation`],Lc=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 Dc),y(this,`_materialQuality`,void 0),y(this,`_colorPipeline`,void 0),y(this,`_pipelineGen`,0),y(this,`_featureStyleManager`,void 0),y(this,`gpuPathManager`,new ki),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 es),y(this,`_opacityTransparent`,!1),y(this,`animator`,new Ec),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,di(e.maxTextureSize??1/0),this._materialQuality=Ni(e.materialQuality),this._datasetManager.defaultMaterialQuality=this._materialQuality,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 Oc(e.ground),this.scene||(this.scene=new t.Scene,this.scene.add(this.groundManager.group)),this._featureStyleManager=new Ds(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._sel.selection&&this._sel.syncStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=zi(),this._colorPipeline=Ri(e.colorPipeline),this._applyRenderProfile({},!0),this._lights=new Bo({scene:()=>this.scene,renderer:()=>this.renderer,uniforms:this.uniforms,options:this.options,getBearing:()=>this._getBearing?.(),repaint:()=>this.triggerRepaint(),applyRenderProfile:(e,t)=>this._applyRenderProfile(e,t)}),this._lights.addToScene(),this._heights=new Vo(this.uniforms);let n=this;this._picks=new ks({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)}),pi(un),this.style={...Ki,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Hi(this.uniforms),this._edges=new ys({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 Ns({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 qt({...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`);fi(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 Js(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 Js(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 Qt(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=Ss(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=Ss(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 Ei?t:new Ei(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=Ss(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=Ss(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 Ic)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 qt({...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=kc(t);r&&r.dispose(),Vs(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=Ac(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=kc(o);if(e){let t=jc(this.style.opacity),n=this.style.depthWrite!==!1;Vi(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),Vi(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),Ac(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),kc(t)?.dispose?.()}Vs(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:Ui[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 Fc.includes(e)?3:1}_registerAnimChannels(){for(let e of Nc)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??Pc[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of Fc)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=jc(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=jc(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(Ac(n.mesh))continue;let r=kc(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||Vi(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)){Bs(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=kc(t.mesh)?.userData.uFlatShading;n&&n.value!==e&&(n.value=e)}this._requestRepaint()}setMaterialQuality(e){this._materialQuality=Ni(e)??`pbr`,this._datasetManager.setDefaultMaterialQuality(this._materialQuality),this._rebuildStyledMaterials(),this._requestRepaint()}get materialQuality(){return this._materialQuality??Fi()}setColorPipeline(e,t={}){let n=Ri(e)??`linear`;if(n===this.colorPipeline)return Promise.resolve();let r=Math.max(0,t.duration??0);if(r<=0)return this._applyRenderProfile({colorPipeline:n}),Promise.resolve();let i=Math.min(1,Math.max(.05,t.dim??.35)),a=++this._pipelineGen;return new Promise(e=>{this.animator.to(`style.fade`,i,{duration:r,easing:`easeInOutQuad`,onComplete:()=>{a===this._pipelineGen?(this._applyRenderProfile({colorPipeline:n}),this.animator.to(`style.fade`,1,{duration:r,easing:`easeInOutQuad`,onComplete:e})):e()}})})}get colorPipeline(){return this._colorPipeline??Li()}_textureOptions(){return{srgbDecode:this.colorPipeline!==`direct`,maxSize:this.options.maxTextureSize??1/0,anisotropyCap:this.options.anisotropyCap??1/0}}_applyRenderProfile(e,t=!1){let n=this.colorPipeline;e.colorPipeline!==void 0&&(this._colorPipeline=Ri(e.colorPipeline)??`linear`),e.anisotropyCap!==void 0&&(this.options.anisotropyCap=e.anisotropyCap);let r=this._textureOptions();this._datasetManager.setRenderProfile({colorPipeline:this.colorPipeline,textureOptions:r}),!t&&(this.colorPipeline!==n&&this._rebuildStyledMaterials(),this._syncCachedTextures(r),this._requestRepaint())}_syncCachedTextures(e){let n=e.srgbDecode?t.SRGBColorSpace:t.NoColorSpace;for(let t of this.datasets.values()){let r=t.tileset?.textureCache;if(r){for(let e of r.values())e.colorSpace!==n&&(e.colorSpace=n,e.needsUpdate=!0);ui(r.values(),e.anisotropyCap??1/0)}}}_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=Bi({...a,uniforms:this.uniforms,materialQuality:this.materialQuality,colorPipeline:this.colorPipeline});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(kc(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._applyRenderProfile({anisotropyCap:t})}get maxTextureSize(){return this.options.maxTextureSize??1/0}setMaxTextureSize(e){let t=Number.isFinite(e)&&e>=1?e:1/0;this.options.maxTextureSize=t,di(t),this._datasetManager.setRenderProfile({textureOptions:this._textureOptions()}),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),io(r.width,r.height),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),(this.uniforms.uOpacity?.value??1)>Mc&&(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=ko(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 Rc=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 Lc({...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}},zc=1e-4;function Bc(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])>zc*r)return!1}return!0}function Vc(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 Hc(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function Uc(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Wc(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 Gc(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 Kc(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||!Hc(i,n.fov))return null;let o=i.clone().invert().multiply(a);if(!Bc(i.clone().multiply(o),Array.from(e.mvp))||!Vc(o)||!Hc(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 qc(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 Jc(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||!Hc(a,n.fov))return null;let s=a.clone().invert().multiply(o);if(!Bc(a.clone().multiply(s),Array.from(e.mvp))||!Vc(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 Yc=l({Animator:()=>Ec,AttributeQuery:()=>qt,BinaryReader:()=>x,DEFAULT_FLOOR_HEIGHT:()=>zt,DEFAULT_LIGHT_PRESET:()=>Fo,DEFAULT_STYLE:()=>Ki,DatasetManager:()=>Dc,EARTH_RADIUS:()=>Jt,EASING_NAMES:()=>ac,FeatureStyleManager:()=>Ds,GPUPathManager:()=>ki,GpuEdgePass:()=>hs,GroundManager:()=>Oc,HostRenderer:()=>Rc,LIGHT_PRESETS:()=>Lo,Path:()=>Ei,Picker:()=>Js,PixelFormat:()=>Y,S3MFormatError:()=>Mt,S3MTileset:()=>Po,S3MViewer:()=>Lc,S3M_VERSION:()=>nt,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>$,SELECT_MODE_LABELS:()=>Wi,STYLE:()=>Q,STYLE_LABELS:()=>Ui,SUPERMAP_LIGHT_PRESET:()=>Io,TextureCompress:()=>X,VertexTag:()=>V,VertexTagV3:()=>rt,authFetch:()=>Ht,buildAttributes:()=>Rt,buildBlendedMVP:()=>Jc,buildFeatureEdgeSegments:()=>us,buildNearScaledMVP:()=>qc,buildOrthoMVP:()=>Kc,buildThickLineGeometry:()=>as,buildTileObjects:()=>ho,createLineSharedUniforms:()=>ts,createOutlineMaterial:()=>Hi,createSharedUniforms:()=>zi,createStyledMaterial:()=>Bi,createTexture:()=>vi,createThickLineMaterial:()=>is,cubicBezier:()=>gc,default:()=>Lc,dxtPixelFormatOf:()=>Or,easing:()=>oc,extractEulerAngles:()=>Ss,extractFovRadians:()=>Gc,extractNearFar:()=>Wc,extractProjectionMatrix:()=>Uc,getColorPipeline:()=>Li,getMaterialQuality:()=>Fi,isS3M1Buffer:()=>Ie,lngLatFromMercator:()=>Xt,lngLatFromWorld:()=>Qt,measureSegments:()=>Lt,mercatorFromLngLat:()=>Yt,parseS3M1:()=>tt,parseS3MB:()=>Nt,planDegradations:()=>Ft,resolveAuthRequest:()=>Vt,resolveEdgeModes:()=>ji,resolveFeature:()=>W,resolveLightingPreset:()=>Ro,resolveRotationMatrix:()=>xs,resolveTextureKind:()=>Dr,sameEdgeModes:()=>Mi,setColorPipeline:()=>Ii,setMaterialQuality:()=>Pi,setMaxAnisotropy:()=>ci,setMaxTextureSize:()=>di,setSrgbTextureDecode:()=>hi,steps:()=>_c,worldFromLngLat:()=>Zt});Bt(),da(),Ai(),So(),Ti(),Ar(),Di(),Bt(),Ar(),Ti(),Di(),Ai(),da(),So();var Xc=globalThis;return Xc.THREE||(Xc.THREE=t),Xc.S3M=Yc,e.Animator=Ec,e.AttributeQuery=qt,e.BinaryReader=x,e.DEFAULT_FLOOR_HEIGHT=zt,e.DEFAULT_LIGHT_PRESET=Fo,e.DEFAULT_STYLE=Ki,e.DatasetManager=Dc,e.EARTH_RADIUS=Jt,e.EASING_NAMES=ac,e.FeatureStyleManager=Ds,e.GPUPathManager=ki,e.GpuEdgePass=hs,e.GroundManager=Oc,e.HostRenderer=Rc,e.LIGHT_PRESETS=Lo,e.Path=Ei,e.Picker=Js,e.PixelFormat=Y,e.S3MFormatError=Mt,e.S3MTileset=Po,e.S3MViewer=Lc,e.default=Lc,e.S3M_VERSION=nt,e.SAMPLES_PER_PATH=Oi,e.SELECT_MODE=$,e.SELECT_MODE_LABELS=Wi,e.STYLE=Q,e.STYLE_LABELS=Ui,e.SUPERMAP_LIGHT_PRESET=Io,e.TextureCompress=X,e.VertexTag=V,e.VertexTagV3=rt,e.authFetch=Ht,e.buildAttributes=Rt,e.buildBlendedMVP=Jc,e.buildFeatureEdgeSegments=us,e.buildNearScaledMVP=qc,e.buildOrthoMVP=Kc,e.buildThickLineGeometry=as,e.buildTileObjects=ho,e.createLineSharedUniforms=ts,e.createOutlineMaterial=Hi,e.createSharedUniforms=zi,e.createStyledMaterial=Bi,e.createTexture=vi,e.createThickLineMaterial=is,e.cubicBezier=gc,e.dxtPixelFormatOf=Or,e.easing=oc,e.extractEulerAngles=Ss,e.extractFovRadians=Gc,e.extractNearFar=Wc,e.extractProjectionMatrix=Uc,e.getColorPipeline=Li,e.getMaterialQuality=Fi,e.isS3M1Buffer=Ie,e.lngLatFromMercator=Xt,e.lngLatFromWorld=Qt,e.measureSegments=Lt,e.mercatorFromLngLat=Yt,e.parseS3M1=tt,e.parseS3MB=Nt,e.planDegradations=Ft,e.resolveAuthRequest=Vt,e.resolveEdgeModes=ji,e.resolveFeature=W,e.resolveLightingPreset=Ro,e.resolveRotationMatrix=xs,e.resolveTextureKind=Dr,e.sameEdgeModes=Mi,e.setColorPipeline=Ii,e.setMaterialQuality=Pi,e.setMaxAnisotropy=ci,e.setMaxTextureSize=di,e.setSrgbTextureDecode=hi,e.steps=_c,e.worldFromLngLat=Zt,e})({},THREE);
|
|
1412
|
+
`}),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()}};Ti(),da(),Di(),Ai(),b();function hl(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function gl(e){return e.isPoints===!0}function _l(e){let t=e??1;return t<0?0:t>1?1:t}var vl=.001,yl=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`metalness`,`roughness`,`edgeWidth`,`edgeOpacity`,`edgeOffset`,`edgeHullWidth`,`outlineWidth`],bl={metalness:0,roughness:.95},xl=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],Sl=[`translation`,`elevation`,`opacity`,`color`,`rotation`],Cl=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 pl),y(this,`_materialQuality`,void 0),y(this,`_colorPipeline`,void 0),y(this,`_pipelineGen`,0),y(this,`_clip`,null),y(this,`_featureStyleManager`,void 0),y(this,`gpuPathManager`,new ki),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 es),y(this,`_opacityTransparent`,!1),y(this,`animator`,new Ec),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,di(e.maxTextureSize??1/0),this._materialQuality=Ni(e.materialQuality),this._datasetManager.defaultMaterialQuality=this._materialQuality,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 ml(e.ground),this.scene||(this.scene=new t.Scene,this.scene.add(this.groundManager.group)),this._featureStyleManager=new Ds(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._sel.selection&&this._sel.syncStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=zi(),this._colorPipeline=Ri(e.colorPipeline),this._applyRenderProfile({},!0),this._lights=new Bo({scene:()=>this.scene,renderer:()=>this.renderer,uniforms:this.uniforms,options:this.options,getBearing:()=>this._getBearing?.(),repaint:()=>this.triggerRepaint(),applyRenderProfile:(e,t)=>this._applyRenderProfile(e,t)}),this._lights.addToScene(),this._heights=new Vo(this.uniforms);let n=this;this._picks=new ks({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)}),pi(un),this.style={...Ki,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Hi(this.uniforms),this._edges=new ys({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 Ns({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 qt({...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`);fi(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._applyClipping(),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 Js(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._applyClipping(),this.picker?.dispose(),this.picker=new Js(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 Qt(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=Ss(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=Ss(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 Ei?t:new Ei(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=Ss(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=Ss(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 Sl)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 qt({...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=hl(t);r&&r.dispose(),Vs(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=gl(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=hl(o);if(e){let t=_l(this.style.opacity),n=this.style.depthWrite!==!1;Vi(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),Vi(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),gl(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),hl(t)?.dispose?.()}Vs(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:Ui[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 xl.includes(e)?3:1}_registerAnimChannels(){for(let e of yl)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??bl[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of xl)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=_l(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=_l(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(gl(n.mesh))continue;let r=hl(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||Vi(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)){Bs(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=hl(t.mesh)?.userData.uFlatShading;n&&n.value!==e&&(n.value=e)}this._requestRepaint()}setMaterialQuality(e){this._materialQuality=Ni(e)??`pbr`,this._datasetManager.setDefaultMaterialQuality(this._materialQuality),this._rebuildStyledMaterials(),this._requestRepaint()}get materialQuality(){return this._materialQuality??Fi()}setColorPipeline(e,t={}){let n=Ri(e)??`linear`;if(n===this.colorPipeline)return Promise.resolve();let r=Math.max(0,t.duration??0);if(r<=0)return this._applyRenderProfile({colorPipeline:n}),Promise.resolve();let i=Math.min(1,Math.max(.05,t.dim??.35)),a=++this._pipelineGen;return new Promise(e=>{this.animator.to(`style.fade`,i,{duration:r,easing:`easeInOutQuad`,onComplete:()=>{a===this._pipelineGen?(this._applyRenderProfile({colorPipeline:n}),this.animator.to(`style.fade`,1,{duration:r,easing:`easeInOutQuad`,onComplete:e})):e()}})})}get colorPipeline(){return this._colorPipeline??Li()}_textureOptions(){return{srgbDecode:this.colorPipeline!==`direct`,maxSize:this.options.maxTextureSize??1/0,anisotropyCap:this.options.anisotropyCap??1/0}}_applyRenderProfile(e,t=!1){let n=this.colorPipeline;e.colorPipeline!==void 0&&(this._colorPipeline=Ri(e.colorPipeline)??`linear`),e.anisotropyCap!==void 0&&(this.options.anisotropyCap=e.anisotropyCap);let r=this._textureOptions();this._datasetManager.setRenderProfile({colorPipeline:this.colorPipeline,textureOptions:r}),!t&&(this.colorPipeline!==n&&this._rebuildStyledMaterials(),this._syncCachedTextures(r),this._requestRepaint())}_syncCachedTextures(e){let n=e.srgbDecode?t.SRGBColorSpace:t.NoColorSpace;for(let t of this.datasets.values()){let r=t.tileset?.textureCache;if(r){for(let e of r.values())e.colorSpace!==n&&(e.colorSpace=n,e.needsUpdate=!0);ui(r.values(),e.anisotropyCap??1/0)}}}_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=Bi({...a,uniforms:this.uniforms,materialQuality:this.materialQuality,colorPipeline:this.colorPipeline});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(hl(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)}_sceneFromLngLat(e){let t=this.sceneAnchor;if(!t)return[0,0,0];let n=t.meterInMercator,r=Zt(this.geo,e.lng,e.lat,e.altitude);return[(r.x-t.x)/n,-(r.y-t.y)/n,e.altitude-(t.altitude??0)]}lngLatToPoint(e){return this._sceneFromLngLat(e)}pointToLngLat(e){return this._lngLatFromScene(e)}_lngLatFromScene(e){let t=this.sceneAnchor;if(!t)return{lng:0,lat:0,altitude:e[2]};let n=t.meterInMercator,[r,i]=Qt(this.geo,e[0]*n+t.x,-e[1]*n+t.y);return{lng:r,lat:i,altitude:e[2]+(t.altitude??0)}}measureDistance(e,t){return Fc(this._sceneFromLngLat(e),this._sceneFromLngLat(t))}measurePolyline(e){let t=e.map(e=>this._sceneFromLngLat(e));return{length3D:Ac(t),lengthHorizontal:jc(t)}}measurePolygon(e){let t=e.map(e=>this._sceneFromLngLat(e));return{area3D:Nc(t),areaHorizontal:Pc(t),perimeter:Mc(t)}}lineOfSight(e,t,n={}){return Ic(this._sceneFromLngLat(e),this._sceneFromLngLat(t),(e,t,n)=>{let r=this._picks.raycastDistance(e,t,n);return r?{distance:r.distance,point:r.point}:null},n)}setClipping(e){this._clip=e,this._applyClipping(),this._requestRepaint()}get clipping(){return this._clip}_applyClipping(){let e=this.renderer;e&&(e.clippingPlanes=this._clip?Wc(this._clip).map(e=>new t.Plane(new t.Vector3(e.normal[0],e.normal[1],e.normal[2]),e.constant)):[])}_depthCtx(){return{renderer:()=>this.renderer,scene:()=>this.scene,camera:()=>this.camera}}skyline(e={}){let t=ll(this._depthCtx(),e.width??640,e.height??360,e.include);return t?tl({rgba:t.rgba,width:t.width,height:t.height,inverseViewProj:t.inverseViewProj,cameraPos:t.cameraPos,step:e.step}):null}viewshed(e){let t=e.eyeHeight??1.7,n=this._sceneFromLngLat({...e.origin,altitude:e.origin.altitude+t}),r=e.size??128,i=fl(this._depthCtx(),n,r,e.radius,e.include);return i?nl(n,rl(i,r,e.radius),{radius:e.radius,grid:e.grid,groundZ:0}):null}_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._applyRenderProfile({anisotropyCap:t})}get maxTextureSize(){return this.options.maxTextureSize??1/0}setMaxTextureSize(e){let t=Number.isFinite(e)&&e>=1?e:1/0;this.options.maxTextureSize=t,di(t),this._datasetManager.setRenderProfile({textureOptions:this._textureOptions()}),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),io(r.width,r.height),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),(this.uniforms.uOpacity?.value??1)>vl&&(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=ko(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 wl=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 Cl({...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}},Tl=1e-4;function El(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])>Tl*r)return!1}return!0}function Dl(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 Ol(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function kl(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Al(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 jl(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 Ml(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||!Ol(i,n.fov))return null;let o=i.clone().invert().multiply(a);if(!El(i.clone().multiply(o),Array.from(e.mvp))||!Dl(o)||!Ol(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 Nl(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 Pl(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||!Ol(a,n.fov))return null;let s=a.clone().invert().multiply(o);if(!El(a.clone().multiply(s),Array.from(e.mvp))||!Dl(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 Fl=l({Animator:()=>Ec,AttributeQuery:()=>qt,BinaryReader:()=>x,CUBE_FACES:()=>ul,DEFAULT_FLOOR_HEIGHT:()=>zt,DEFAULT_LIGHT_PRESET:()=>Fo,DEFAULT_STYLE:()=>Ki,DatasetManager:()=>pl,EARTH_RADIUS:()=>Jt,EASING_NAMES:()=>ac,FeatureStyleManager:()=>Ds,GPUPathManager:()=>ki,GpuEdgePass:()=>hs,GroundManager:()=>ml,HostRenderer:()=>wl,LIGHT_PRESETS:()=>Lo,Path:()=>Ei,Picker:()=>Js,PixelFormat:()=>Y,S3MFormatError:()=>Mt,S3MTileset:()=>Po,S3MViewer:()=>Cl,S3M_VERSION:()=>nt,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>$,SELECT_MODE_LABELS:()=>Wi,STYLE:()=>Q,STYLE_LABELS:()=>Ui,SUPERMAP_LIGHT_PRESET:()=>Io,TextureCompress:()=>X,VertexTag:()=>V,VertexTagV3:()=>rt,authFetch:()=>Ht,azimuthElevation:()=>el,boxClipping:()=>Hc,buildAttributes:()=>Rt,buildBlendedMVP:()=>Pl,buildClipPlanes:()=>Wc,buildCubeCameras:()=>dl,buildFeatureEdgeSegments:()=>us,buildNearScaledMVP:()=>Nl,buildOrthoMVP:()=>Ml,buildThickLineGeometry:()=>as,buildTileObjects:()=>ho,captureRadialCube:()=>fl,captureSkylineDepth:()=>ll,computeViewshed:()=>nl,createLineSharedUniforms:()=>ts,createOutlineMaterial:()=>Hi,createSharedUniforms:()=>zi,createStyledMaterial:()=>Bi,createTexture:()=>vi,createThickLineMaterial:()=>is,crossClipping:()=>Uc,cubicBezier:()=>gc,default:()=>Cl,distance3D:()=>Dc,distanceHorizontal:()=>Oc,dxtPixelFormatOf:()=>Or,easing:()=>oc,extractEulerAngles:()=>Ss,extractFovRadians:()=>jl,extractNearFar:()=>Al,extractProjectionMatrix:()=>kl,getColorPipeline:()=>Li,getMaterialQuality:()=>Fi,heightDifference:()=>kc,isPointKept:()=>Bc,isS3M1Buffer:()=>Ie,lineOfSight:()=>Ic,lngLatFromMercator:()=>Xt,lngLatFromWorld:()=>Qt,makeCubeDistanceSampler:()=>rl,measureSegment:()=>Fc,measureSegments:()=>Lt,mercatorFromLngLat:()=>Yt,packRGBADepth:()=>Yc,parseS3M1:()=>tt,parseS3MB:()=>Nt,pixelToNdc:()=>$c,planDegradations:()=>Ft,planeClipping:()=>Vc,planeFromPointNormal:()=>zc,polygonArea:()=>Nc,polygonAreaHorizontal:()=>Pc,polygonPerimeter:()=>Mc,polylineLength:()=>Ac,polylineLengthHorizontal:()=>jc,resolveAuthRequest:()=>Vt,resolveEdgeModes:()=>ji,resolveFeature:()=>W,resolveLightingPreset:()=>Ro,resolveRotationMatrix:()=>xs,resolveTextureKind:()=>Dr,sameEdgeModes:()=>Mi,setColorPipeline:()=>Ii,setMaterialQuality:()=>Pi,setMaxAnisotropy:()=>ci,setMaxTextureSize:()=>di,setSrgbTextureDecode:()=>hi,skylineFromDepth:()=>tl,steps:()=>_c,unpackRGBADepth:()=>Xc,unprojectNdc:()=>Qc,worldFromLngLat:()=>Zt});Bt(),da(),Ai(),So(),Ti(),Ar(),Di(),Bt(),Ar(),Ti(),Di(),Ai(),da(),So();var Il=globalThis;return Il.THREE||(Il.THREE=t),Il.S3M=Fl,e.Animator=Ec,e.AttributeQuery=qt,e.BinaryReader=x,e.CUBE_FACES=ul,e.DEFAULT_FLOOR_HEIGHT=zt,e.DEFAULT_LIGHT_PRESET=Fo,e.DEFAULT_STYLE=Ki,e.DatasetManager=pl,e.EARTH_RADIUS=Jt,e.EASING_NAMES=ac,e.FeatureStyleManager=Ds,e.GPUPathManager=ki,e.GpuEdgePass=hs,e.GroundManager=ml,e.HostRenderer=wl,e.LIGHT_PRESETS=Lo,e.Path=Ei,e.Picker=Js,e.PixelFormat=Y,e.S3MFormatError=Mt,e.S3MTileset=Po,e.S3MViewer=Cl,e.default=Cl,e.S3M_VERSION=nt,e.SAMPLES_PER_PATH=Oi,e.SELECT_MODE=$,e.SELECT_MODE_LABELS=Wi,e.STYLE=Q,e.STYLE_LABELS=Ui,e.SUPERMAP_LIGHT_PRESET=Io,e.TextureCompress=X,e.VertexTag=V,e.VertexTagV3=rt,e.authFetch=Ht,e.azimuthElevation=el,e.boxClipping=Hc,e.buildAttributes=Rt,e.buildBlendedMVP=Pl,e.buildClipPlanes=Wc,e.buildCubeCameras=dl,e.buildFeatureEdgeSegments=us,e.buildNearScaledMVP=Nl,e.buildOrthoMVP=Ml,e.buildThickLineGeometry=as,e.buildTileObjects=ho,e.captureRadialCube=fl,e.captureSkylineDepth=ll,e.computeViewshed=nl,e.createLineSharedUniforms=ts,e.createOutlineMaterial=Hi,e.createSharedUniforms=zi,e.createStyledMaterial=Bi,e.createTexture=vi,e.createThickLineMaterial=is,e.crossClipping=Uc,e.cubicBezier=gc,e.distance3D=Dc,e.distanceHorizontal=Oc,e.dxtPixelFormatOf=Or,e.easing=oc,e.extractEulerAngles=Ss,e.extractFovRadians=jl,e.extractNearFar=Al,e.extractProjectionMatrix=kl,e.getColorPipeline=Li,e.getMaterialQuality=Fi,e.heightDifference=kc,e.isPointKept=Bc,e.isS3M1Buffer=Ie,e.lineOfSight=Ic,e.lngLatFromMercator=Xt,e.lngLatFromWorld=Qt,e.makeCubeDistanceSampler=rl,e.measureSegment=Fc,e.measureSegments=Lt,e.mercatorFromLngLat=Yt,e.packRGBADepth=Yc,e.parseS3M1=tt,e.parseS3MB=Nt,e.pixelToNdc=$c,e.planDegradations=Ft,e.planeClipping=Vc,e.planeFromPointNormal=zc,e.polygonArea=Nc,e.polygonAreaHorizontal=Pc,e.polygonPerimeter=Mc,e.polylineLength=Ac,e.polylineLengthHorizontal=jc,e.resolveAuthRequest=Vt,e.resolveEdgeModes=ji,e.resolveFeature=W,e.resolveLightingPreset=Ro,e.resolveRotationMatrix=xs,e.resolveTextureKind=Dr,e.sameEdgeModes=Mi,e.setColorPipeline=Ii,e.setMaterialQuality=Pi,e.setMaxAnisotropy=ci,e.setMaxTextureSize=di,e.setSrgbTextureDecode=hi,e.skylineFromDepth=tl,e.steps=_c,e.unpackRGBADepth=Xc,e.unprojectNdc=Qc,e.worldFromLngLat=Zt,e})({},THREE);
|