s3m-three 0.3.10 → 0.3.11

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.
@@ -901,4 +901,4 @@ var S3M=(function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.
901
901
  }
902
902
  gl_FragColor = vec4(1.0);
903
903
  }
904
- `}),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()}};Wr(),mi(),Kr(),Yr(),Tt(),y();var yo=65534;function $(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function bo(e){return e.isPoints===!0}var xo=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`edgeWidth`,`edgeOpacity`,`outlineWidth`],So=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],Co=[`translation`,`elevation`,`opacity`,`color`,`rotation`],wo=class e{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={}){v(this,`options`,void 0),v(this,`pickable`,void 0),v(this,`onStats`,void 0),v(this,`onReady`,void 0),v(this,`onPick`,void 0),v(this,`onError`,void 0),v(this,`geo`,null),v(this,`canvas`,null),v(this,`renderer`,null),v(this,`scene`,null),v(this,`camera`,null),v(this,`picker`,null),v(this,`uniforms`,void 0),v(this,`style`,void 0),v(this,`_styleTarget`,void 0),v(this,`outlineMaterial`,void 0),v(this,`lineShared`,void 0),v(this,`edgeMaterial`,void 0),v(this,`selectionEdgeMaterial`,void 0),v(this,`_edgeStyleUniforms`,void 0),v(this,`_selEdgeStyleUniforms`,void 0),v(this,`groundManager`,void 0),v(this,`_datasetManager`,new lo),v(this,`_featureStyleManager`,void 0),v(this,`gpuPathManager`,new Jr),v(this,`_customPathTime`,!1),v(this,`_pickables`,new Map),v(this,`_pickSeq`,0),v(this,`_freePickIds`,[]),v(this,`_smidMeshes`,new Map),v(this,`_meshHeight`,new Map),v(this,`_heightMin`,1/0),v(this,`_heightMax`,-1/0),v(this,`_boxScratch`,new t.Box3),v(this,`_selection`,null),v(this,`_selectedMeshes`,[]),v(this,`_outlineMesh`,null),v(this,`_outlineMeshes`,[]),v(this,`_selectionEdges`,null),v(this,`_selectionEdgeMeshes`,[]),v(this,`_edgesEnabled`,!1),v(this,`_tileFadeSeq`,0),v(this,`_modeGen`,0),v(this,`_pathSpecs`,new Map),v(this,`_pathScratch`,new Float32Array(3)),v(this,`_creaseLines`,null),v(this,`_nativeEdgeLines`,new Set),v(this,`_pointClouds`,new Set),v(this,`_opacityTransparent`,!1),v(this,`animator`,new Xa),v(this,`attributeQuery`,null),v(this,`_enuMatrix`,new t.Matrix4),v(this,`_colorScratch`,new t.Color),v(this,`_needsRepaint`,!0),v(this,`_frame`,0),v(this,`_fps`,{value:0,last:0}),v(this,`_ambientLight`,void 0),v(this,`_hemiLight`,void 0),v(this,`_keyLight`,void 0),v(this,`_fillLight`,void 0),v(this,`_lightOptions`,{ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50}),v(this,`_datasetQueue`,void 0),v(this,`_onRequestRepaint`,()=>{}),v(this,`_getBearing`,void 0),v(this,`_lodRangeScale`,1),this.options=e,this.pickable=e.pickable!==!1,this._lodRangeScale=e.lodRangeScale??1,e.light&&Object.assign(this._lightOptions,e.light),e.totalMaxTiles&&(this._datasetManager.totalMaxTiles=e.totalMaxTiles),this._onRequestRepaint=e.onRequestRepaint??(()=>{}),this._getBearing=e.getBearing,this.onStats=e.onStats??(()=>{}),this.onReady=e.onReady??(()=>{}),this.onPick=e.onPick??(()=>{}),this.onError=e.onError??(e=>console.warn(`[s3m]`,e)),this.groundManager=new vo(e.ground),this.scene||(this.scene=new t.Scene,this.scene.add(this.groundManager.group),this._addLights()),this._featureStyleManager=new _o(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._selection&&this._syncSelectionStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=Xr(),Ir(Bt),this.style={...ti,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Qr(this.uniforms),this.lineShared=Za(),this._edgeStyleUniforms={uColor:{value:new t.Color(this.style.edgeColor)},uWidth:{value:Math.max(.1,this.style.edgeWidth??1.5)},uOpacity:{value:.6}},this.edgeMaterial=eo(this.lineShared,{},this._edgeStyleUniforms),this._selEdgeStyleUniforms={uColor:{value:new t.Color(this.style.outlineColor??this.style.selectColor)},uWidth:{value:Math.max(.1,this.style.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:this.style.selectElevation??0}},this.selectionEdgeMaterial=eo(this.lineShared,{},this._selEdgeStyleUniforms),this.setEdges(!!this.style.edges),this._fps.last=performance.now(),this._datasetQueue=this._normalizeDatasets(e),e.attributes&&(this.attributeQuery=new At(e.attributes))}_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`);Fr(t&&n)}mount(e,n){this.canvas=e,this.renderer=this._createRenderer(e,n),Pr(this.renderer.capabilities.getMaxAnisotropy()),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 va(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),Pr(this.renderer.capabilities.getMaxAnisotropy()),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new va(this.renderer),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.outlineMaterial.dispose(),this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose(),this.scene?.clear(),this._selectedMeshes=[],this._outlineMeshes=[],this._selectionEdgeMeshes=[],this._outlineMesh=null,this._selectionEdges=null,this._smidMeshes.clear(),this._meshHeight.clear(),this.animator.clear(),this.animator.unregisterPrefix(`tile.`),this.animator.unregisterPrefix(`feature.`),this._pathSpecs.clear(),this._heightMin=1/0,this._heightMax=-1/0,this.renderer?.dispose(),this.renderer=null,this.canvas=null}_createLights(){this._ambientLight=new t.AmbientLight(this._lightOptions.ambientColor,this._lightOptions.ambientIntensity),this._hemiLight=new t.HemisphereLight(this._lightOptions.hemisphereColor,this._lightOptions.hemisphereGroundColor,this._lightOptions.hemisphereIntensity),this._keyLight=new t.DirectionalLight(this._lightOptions.keyLightColor,this._lightOptions.keyLightIntensity),this._fillLight=new t.DirectionalLight(this._lightOptions.fillLightColor,this._lightOptions.fillLightIntensity),this._updateLights()}_addLights(){this.scene&&(this._ambientLight||this._createLights(),this.scene.add(this._ambientLight,this._hemiLight,this._keyLight,this._fillLight))}_applyLightOptions(){this._ambientLight&&(this._ambientLight.intensity=this._lightOptions.ambientIntensity,this._ambientLight.color.set(this._lightOptions.ambientColor)),this._hemiLight&&(this._hemiLight.intensity=this._lightOptions.hemisphereIntensity,this._hemiLight.color.set(this._lightOptions.hemisphereColor),this._hemiLight.groundColor.set(this._lightOptions.hemisphereGroundColor)),this._keyLight&&(this._keyLight.intensity=this._lightOptions.keyLightIntensity,this._keyLight.color.set(this._lightOptions.keyLightColor)),this._fillLight&&(this._fillLight.intensity=this._lightOptions.fillLightIntensity,this._fillLight.color.set(this._lightOptions.fillLightColor))}setLight(e){let t={...e};t.mainColor!==void 0&&t.keyLightColor===void 0&&(t.keyLightColor=t.mainColor),t.mainIntensity!==void 0&&t.keyLightIntensity===void 0&&(t.keyLightIntensity=t.mainIntensity),Object.assign(this._lightOptions,t),this._applyLightOptions(),this._updateLights(),this._needsRepaint=!0,this.triggerRepaint()}getLight(){return{...this._lightOptions}}setToneMapping(e,t=1){this.options.toneMapping=e,this.options.toneMappingExposure=t,this.renderer&&(this.renderer.toneMapping=e,this.renderer.toneMappingExposure=t,this._needsRepaint=!0,this.triggerRepaint())}getToneMapping(){return{toneMapping:this.renderer?this.renderer.toneMapping:this.options.toneMapping??t.NoToneMapping,toneMappingExposure:this.renderer?this.renderer.toneMappingExposure:this.options.toneMappingExposure??1}}_updateLights(){if(!this._keyLight||!this._fillLight)return;let e=this._lightOptions.mode===`fixed`?0:(this._getBearing?.()??0)*Math.PI/180,t=(t,n,r)=>{if(!t)return;let i=e+n*Math.PI/180,a=r*Math.PI/180,o=Math.cos(a);t.position.set(Math.sin(i)*o,Math.cos(i)*o,Math.sin(a)).multiplyScalar(1e3)};t(this._keyLight,this._lightOptions.azimuth,this._lightOptions.altitude),t(this._fillLight,this._lightOptions.azimuth+65,Math.max(10,this._lightOptions.altitude-20))}_normalizeDatasets(e){return Array.isArray(e.datasets)?e.datasets.filter(e=>!!e?.configUrl):e.configUrl?[{id:`default`,name:`默认数据集`,configUrl:e.configUrl,useWorker:e.useWorker}]:[]}async addDataset(e){if(!this.scene)throw Error(`[s3m] 图层尚未 addLayer,不能添加数据集`);return await this._datasetManager.addDataset(e,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._needsRepaint=!0,this._requestRepaint()},onTileRemoved:(e,t)=>{this._unregisterTile(e,t),this.onStats(this.stats),this._needsRepaint=!0,this._requestRepaint()},onStats:()=>{this.onStats(this.stats),this._requestRepaint()},onError:e=>{this.onError(e),this.onStats(this.stats)},onReady:e=>{this.onReady(e),this._refreshAllHeights(),this.groundManager.excavationBounds||this.groundManager.autoFitExcavation(this.datasets.values())},triggerRepaint:()=>{this._requestRepaint()}})}_lngLatFromWorld(e,t){return Ft(this.geo,e,t)}recomputeAnchors(){this._datasetManager.recomputeAnchors(this.geo),this._refreshAllHeights(),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._refreshAllHeights(),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._refreshAllHeights(),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=fo(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=fo(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 Gr?t:new Gr(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)}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=fo(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=fo(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 Co)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 At(e):null}getLoadedSmids(){return[...this._smidMeshes.keys()]}auditBatches(){let e=this._featureStyleManager.auditBatches(this._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._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}_markOverridesDirty(e=`all`){e===`all`?this._featureStyleManager.markOverridesDirty(void 0,this.getAllMeshes()):this._featureStyleManager.markOverridesDirty(e)}flushOverrides(){this._featureStyleManager.flushOverrides()}_applyOverridesToMesh(e){this._featureStyleManager.applyOverridesToMesh(e)}removeDataset(e){if(this.datasets.get(e)){this._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._pickables.delete(n.pickId),this._releasePickId(n.pickId),n.pickId=void 0),this._unindexMeshSmids(t),this._removeMeshHeight(t),t.geometry?.dispose?.();let r=$(t);r&&r.dispose(),fa(t.material)&&t.material.dispose(),this._featureStyleManager.disposeMesh(t)})});for(let[t,n]of this._pickables)n.datasetId===e&&this._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._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;for(let r of e.group.children){if(r.isLineSegments&&r.userData.isEdgeLines){r.visible=this._edgesEnabled,this._nativeEdgeLines.add(r),this._styleEdgeLine(r);continue}let i=bo(r),a=r;if(!a.isMesh&&!i)continue;i&&this._pointClouds.add(r);let o=a.userData;if(o.pickId=this._allocPickId(),o.datasetId=t.id,o.nativeEdges=n,this._pickables.set(o.pickId,{datasetId:t.id,mesh:a,tile:e.tile,skeletonName:o.skeletonName??``}),this._indexMeshSmids(a),this._addMeshHeight(a),!n&&!i&&this._datasetEdgesEnabled(t)&&!this._shouldSkipAutoEdges(o,t.name)&&this._ensureEdges(a),i)this._applyPointCloudStyle(r);else{let e=$(a);if(e){let t=Math.min(1,Math.max(.05,this.style.opacity??1));e.transparent=t<.999,e.depthWrite=t>=.999,e.flatShading=this.style.shading!==`smooth`,e.needsUpdate=!0,this._featureStyleManager.applyOverridesToMesh(a),this._startTileFade(a,e)}}this._replaySelectionOnto(a)}}_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),this._featureStyleManager.applyOverridesToMesh(e),t.transparent||(t.depthWrite=!0),this._requestRepaint()}})}_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)}_replaySelectionOnto(e){let t=this._selection;if(!t)return;let n=$(e);if(!n)return;let r=e.userData,i=-1;if(t.smid!=null){let e=r.geoRef?.pickInfo,n=e?.[t.smid]??e?.[String(t.smid)];i=n?H(n):-1}if(e===t.mesh&&(i=t.batchId),i<0&&e!==t.mesh){if(t.smid==null&&r.datasetId===t.datasetId&&this._isMeshCoveringSelection(e,t))i=-1;else return}n.userData.uSelBatch.value=i,n.userData.uSelWhole.value=+(i<0),this._selectedMeshes.includes(e)||this._selectedMeshes.push(e),bo(e)&&this._applyPointCloudStyle(e,!0),this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers}_unregisterTile(e,t){e.group.traverse(e=>{let t=e;if(e.isLineSegments&&t.userData?.isEdgeLines&&this._nativeEdgeLines.delete(e),bo(e)&&this._pointClouds.delete(e),t.userData?.tileFadeKey&&(this.animator.unregister(t.userData.tileFadeKey),t.userData.tileFadeKey=void 0),t.userData?.pickId!=null&&(this._pickables.delete(t.userData.pickId),this._releasePickId(t.userData.pickId),t.userData.pickId=void 0),t.isMesh){this._selectedMeshes.includes(t)&&(this._selectedMeshes=this._selectedMeshes.filter(e=>e!==t));let e=this._selection;if(e&&e.mesh===t){let n=e.smid,r=n==null?this._selectedMeshes.find(e=>e!==t&&e.parent&&e.parent.visible)??this._selectedMeshes.find(e=>e!==t&&e.parent):[...this._smidMeshes.get(n)??[]].find(e=>e!==t&&e.parent);r?(this._selection={...e,mesh:r},this._replaySelectionOnto(r)):this.select(null)}this._unindexMeshSmids(t),this._removeMeshHeight(t),this._featureStyleManager.disposeMesh(t),$(t)?.dispose?.()}fa(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)}_allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>yo){for(let e=0;e<=yo;e++)if(!this._pickables.has(e))return e;throw Error(`[s3m] 可拾取网格超过 65535 个,2 字节 ID 编码不够用`)}return this._pickSeq++}_releasePickId(e){this._freePickIds.push(e)}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:$r[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 So.includes(e)?3:1}_registerAnimChannels(){for(let e of xo)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of So)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._syncEdgeStyle()}}),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`)&&this._refreshEdgeLines())}_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&&this._edgesEnabled?(this._disposeEdges(),this.setEdges(!0)):(`edgeColor`in e||`edgeWidth`in e||`opacity`in e||`edgeOpacity`in e)&&this._refreshEdgeLines(),this._selection&&(`outline`in e||`outlineStyle`in e?this.select(this._selection,{silent:!0}):this._syncSelectionStyle())}_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??Q.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===Q.REPLACE?0:n===Q.MULTIPLY?2:n===Q.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),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=Math.min(1,Math.max(.05,this.style.opacity??1));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._pickables.values()){if(bo(n.mesh))continue;let r=$(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||(r.transparent=t,r.depthWrite=!t||e))}}for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._syncEdgeStyle(),this._requestRepaint()}_applyPointCloudStyle(e,t=this._selectedMeshes.includes(e)){da(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`;for(let t of this._pickables.values()){let n=$(t.mesh);n&&n.flatShading!==e&&(n.flatShading=e,n.needsUpdate=!0)}this._requestRepaint()}_addMeshHeight(e){let t=e.geometry?.boundingBox;if(!t)return;this._boxScratch.copy(t).applyMatrix4(e.matrixWorld);let n=this._boxScratch.min.z,r=this._boxScratch.max.z;Number.isFinite(n)&&Number.isFinite(r)&&(this._meshHeight.set(e,{min:n,max:r}),n<this._heightMin&&(this._heightMin=n),r>this._heightMax&&(this._heightMax=r),this._pushHeightRange())}_removeMeshHeight(e){let t=this._meshHeight.get(e);t&&(this._meshHeight.delete(e),t.min===this._heightMin||t.max===this._heightMax?this._recomputeHeightRange():this._pushHeightRange())}_refreshAllHeights(){if(this._meshHeight.size===0)return;let e=[...this._meshHeight.keys()];this._meshHeight.clear(),this._heightMin=1/0,this._heightMax=-1/0;for(let t of e)this._addMeshHeight(t);this._pushHeightRange()}_recomputeHeightRange(){let e=1/0,t=-1/0;for(let n of this._meshHeight.values())n.min<e&&(e=n.min),n.max>t&&(t=n.max);this._heightMin=e,this._heightMax=t,this._pushHeightRange()}_pushHeightRange(){let e=this._heightMin,t=this._heightMax;(!Number.isFinite(e)||!Number.isFinite(t)||t<=e)&&(e=0,t=100),this.uniforms.uHeightMin.value=e,this.uniforms.uHeightMax.value=t}_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))}}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring);this._edgesEnabled=e,this.style.edges=e,this._styleTarget.edges=e;for(let t of this.datasets.values())t.root.traverse(t=>{t.userData.isEdgeLines&&(t.visible=e,this._styleEdgeLine(t))});if(this._syncEdgeStyle(),!e){n?this.animator.to(`style.edgeFade`,0,{...t,onComplete:()=>{this._disposeEdges(),this._requestRepaint(),t?.onComplete?.()}}):(this._setEdgeFade(1),this._disposeEdges()),this._requestRepaint();return}let r=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e.userData;return!t.edges&&!t.nativeEdges&&!bo(e)}),i=0,a=()=>{let e=performance.now();for(;i<r.length&&performance.now()-e<8;)this._ensureEdges(r[i++]);i<r.length?setTimeout(a,0):this._requestRepaint()};a(),n?(this._setEdgeFade(0),this.animator.to(`style.edgeFade`,1,t)):this._setEdgeFade(1)}_setEdgeFade(e){this.uniforms.uEdgeFade&&(this.uniforms.uEdgeFade.value=e),this._syncEdgeStyle()}_disposeEdges(){for(let e of this._pickables.values())this._removeEdges(e.mesh)}async loadCreases(e){let n=await fetch(e);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.style,s=new t.LineBasicMaterial({color:new t.Color(o.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,o.edgeOpacity??.6))*Math.min(1,Math.max(.05,o.opacity??1)),depthWrite:!1}),c=new t.LineSegments(a,s);c.renderOrder=2,c.frustumCulled=!1,c.raycast=()=>{},this.clearCreases(),this._creaseLines=c,this.scene?.add(c),this._requestRepaint()}clearCreases(){this._creaseLines&&(this.scene?.remove(this._creaseLines),this._creaseLines.geometry.dispose(),this._creaseLines.material?.dispose?.(),this._creaseLines=null,this._requestRepaint())}_syncEdgeStyle(){let e=this.style,t=this.uniforms.uEdgeFade?.value??1,n=Math.min(1,Math.max(0,e.edgeOpacity??.6))*Math.min(1,Math.max(.05,e.opacity??1))*t,r=this.edgeMaterial.uniforms;if(r.uColor.value.set(e.edgeColor),r.uWidth.value=Math.max(.1,e.edgeWidth??1.5),r.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.style.edgeColor),t.opacity=(this.style.edgeOpacity??.6)*Math.min(1,Math.max(.05,this.style.opacity??1))*(this.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._nativeEdgeLines)e.parent&&this._styleEdgeLine(e)}_datasetEdgesEnabled(e){let t=e.options?.enableEdges;return t===!0||t!==!1&&this._edgesEnabled}_shouldSkipAutoEdges(t,n){let r=`${t.skeletonName??``} ${n}`.toLowerCase();return e._EDGE_SKIP_KEYWORDS.some(e=>r.includes(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=co(e.geometry,.005),a=this.style.edgeThreshold??55,o=new t.EdgesGeometry(i,a);i.dispose();let s=o.getAttribute(`position`),c=s?s.array:null;if(o.dispose(),!c||c.length<6)return;let l=.005,u=no(e.geometry,l),d;if(u){let e=c.length/6;d=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;d[t]=u.get(ro(c[e],c[e+1],c[e+2],1/l))??-1}}let f=new t.Mesh(to(c,d),this._createEdgeMaterial(e));f.renderOrder=2,f.frustumCulled=!1,f.raycast=()=>{},f.userData.isThickEdge=!0,n.edges=f,e.add(f)}_createEdgeMaterial(e){let t=$(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return eo(this.lineShared,{},this._edgeStyleUniforms,n)}_createSelectionEdgeMaterial(e){let t=$(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return eo(this.lineShared,{},this._selEdgeStyleUniforms,n)}_removeEdges(e){let t=e.userData,n=t.edges;if(!n)return;e.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(e=>e?.dispose?.()):r?.dispose?.(),t.edges=null}getRayAt(e,n){if(!this.camera||!this.canvas)return null;let r=this.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.camera),l=new t.Vector3(o,s,1).unproject(this.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,o=null,s=e.batchId,c=e.instanceIndex,l=a.geoRef,u=[];if(c!=null){let e=this._instanceFeature(n.mesh,l,c);if(!e)return null;o=e.smid,s=e.batchId}else{l=a.geoByBatchId?.get(e.batchId)??a.geoRef;let t=U(l,e.batchId);o=t.smid,u=t.segments}if(this._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._smidMeshes.has(o)){let e=this._smidMeshes.get(o),t=1/0,n=1/0,r=1/0,i=-1/0,a=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,d=u?.[o]??u?.[String(o)],p=d?H(d):-1,m=d?.segments??(p>=0?U(e.geoRef,p).segments:[]),h=St(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=St(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=Ct({smid:o,box:d,triangles:m,floorHeight:this.style.floorHeight}),g=null;if(d&&this.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.sceneAnchor.meterInMercator;g=this._lngLatFromWorld(e.x*r+this.sceneAnchor.x,-e.y*r+this.sceneAnchor.y)}let _=r??null;!_&&i&&(_=this._intersectMeshAtRay(n.mesh,i,c));let v=null,y=null,b=null;if(_&&this.sceneAnchor){let e=o==null?{}:this._featureStyleManager.getFeatureEffectiveOffset(o),n=e.translation,r=e.elevation,i=_.clone();if(e.rotation){let n=uo(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.sceneAnchor.meterInMercator;y=this._lngLatFromWorld(i.x*a+this.sceneAnchor.x,-i.y*a+this.sceneAnchor.y),b=i.z+(this.sceneAnchor.altitude??0)}else g&&d&&this.sceneAnchor&&(y=g,b=(d.minZ+d.maxZ)/2+(this.sceneAnchor.altitude??0));return{datasetId:n.datasetId,datasetName:this.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}}pick(e,t){if(!this.picker||!this.scene||!this.camera||!this.sceneAnchor)return null;let n=this.picker.pick(this.scene,this.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.camera||!this.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.sceneAnchor.meterInMercator;return{lngLat:this._lngLatFromWorld(s.x*e+this.sceneAnchor.x,-s.y*e+this.sceneAnchor.y),altitude:s.z+(this.sceneAnchor.altitude??0),point:[s.x,s.y,s.z]}}return null}drillPick(e,n,r=10){if(!this.sceneAnchor||!this.camera)return[];let i=this.getRayAt(e,n);if(!i)return[];let a=new t.Raycaster;a.ray.copy(i);let o=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),s=a.intersectObjects(o,!1);if(!s.length)return[];let c=[],l=new Set,u=new Set;for(let e of s){if(c.length>=r)break;let t=e.object,n=t.userData;if(n.pickId==null)continue;let i=this._pickables.get(n.pickId);if(!i)continue;let a=null,o=-1,s=e.instanceId;if(s!=null){let e=this._instanceFeature(t,n.geoRef,s);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let r=t.geometry.attributes.aBatchId;if(r){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(r.getX(i)),a=U(n.geoByBatchId?.get(o)??n.geoRef,o).smid}}if(a!=null){if(l.has(a))continue;l.add(a)}else{let e=`${n.pickId}:${o}:${s??-1}`;if(u.has(e))continue;u.add(e)}if(this._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.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=xt(d),l.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){f=this._instanceBox(c,n);break}}else{let t=d,n=t[e]??t[String(e)];if(n){let e=U(u,H(n));if(f=St(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._featureStyleManager.getFeatureEffectiveOffset(e),u=l.translation,d=l.elevation,p=l.rotation?uo(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));for(let e of s){m&&h&&e.sub(h).applyMatrix3(m).add(h),u?e.add(new t.Vector3(u[0],u[1],u[2])):d&&(e.z+=d),e.applyMatrix4(c.matrixWorld);let o=this.sceneAnchor.meterInMercator,[s,l]=this._lngLatFromWorld(e.x*o+this.sceneAnchor.x,-e.y*o+this.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=xt(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}}select(e,{silent:t=!1}={}){if(this._selection){for(let e of this._selectedMeshes){if(bo(e)){this._applyPointCloudStyle(e,!1);continue}let t=$(e);t&&(t.userData.uSelBatch.value=-1,t.userData.uSelWhole.value=0)}this._selectedMeshes=[],this._clearSelectionDecoration(),this._selection=null}if(!e){this.uniforms.uSelMix.value=0,this.uniforms.uDim.value=0,this.outlineMaterial.uniforms.uSelBatch.value=-1,this.outlineMaterial.uniforms.uSelWhole.value=0,this.outlineMaterial.uniforms.uElevation.value=0,this._requestRepaint(),t||this.onPick(null);return}this._selection=e;let n=new Set;if(e.smid!=null){let t=this._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=$(t);if(!n)continue;let r=e.batchId;if(e.instanceIndex!=null&&t===e.mesh)r=e.batchId;else if(e.smid!=null){let n=t.userData.geoRef?.pickInfo,i=n?.[e.smid]??n?.[String(e.smid)],a=i?H(i):-1;r=a>=0?a:t===e.mesh?e.batchId:-1}n.userData.uSelBatch.value=r,n.userData.uSelWhole.value=+(r<0),this._selectedMeshes.push(t)}for(let e of this._selectedMeshes)bo(e)&&this._applyPointCloudStyle(e,!0);if(this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers,this.style.outline){let t=[...n].filter(e=>!bo(e));t.length&&((this.style.outlineStyle??`edges`)===`edges`?this._addSelectionEdges(e,t):this._addSelectionHull(e,t))}this._requestRepaint()}_addSelectionEdges(e,n){this._syncSelectionStyle();for(let r of n){let n=r.userData,i=n.geoRef,a=[],o=-1;if(r===e.mesh&&e.instanceIndex!=null){a=[{vertexOffset:0,vertexCount:r.geometry.getAttribute(`position`)?.count??0}];let t=i?.pickInfo,n=t?.[e.smid??``]??t?.[String(e.smid)];o=n?H(n):-1}else if(e.smid!=null){let t=i?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],r=n?H(n):-1;o=r,a=n?.segments??(r>=0?U(i,r).segments:[])}else r===e.mesh&&(a=U(n.geoByBatchId?.get(e.batchId)??i,e.batchId).segments,o=e.batchId);let s=oo(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(to(s,n),this._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):this._selectionEdges=this._selectionEdgeMeshes[0]??null}_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.outlineMaterial.uniforms.uSelBatch.value=r?-1:e.batchId,this.outlineMaterial.uniforms.uSelWhole.value=r||e.batchId<0?1:0,this.outlineMaterial.uniforms.uElevation.value=r?this._selectionElevation(e):this.style.selectElevation??0;for(let r of n){let n=$(r);n?.userData?.uBatchTex&&(this.outlineMaterial.uniforms.uBatchTex.value=n.userData.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=n.userData.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=n.userData.uBatchTexActive.value);let i=new t.Mesh(r.geometry,this.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)}this._outlineMesh=this._outlineMeshes[0]??null}_syncSelectionStyle(){let e=this.style,t=this.selectionEdgeMaterial.uniforms;t.uColor.value.set(e.outlineColor??e.selectColor),t.uWidth.value=Math.max(.1,e.outlineWidthPx??3),t.uOpacity.value=Math.min(1,Math.max(.05,e.opacity??1)),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?$(t)?.userData:null;n?.uBatchTex&&(this.outlineMaterial.uniforms.uBatchTex.value=n.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=n.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=n.uBatchTexActive.value)}}_selectionElevation(e){let t=this.style.selectElevation??0;if(e.smid!=null){let n=this._featureStyleManager.getFeatureEffectiveOffset(e.smid);n.elevation&&(t+=n.elevation)}return t}_clearSelectionDecoration(){for(let e of this._outlineMeshes)e.parent?.remove(e);this._outlineMeshes=[],this._outlineMesh=null;for(let e of this._selectionEdgeMeshes)e.parent?.remove(e),e.geometry.dispose();this._selectionEdgeMeshes=[],this._selectionEdges=null}_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}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()}}renderFrame(e){if(!this.renderer||!this.scene||!this.camera||!this.sceneAnchor||!this.canvas)return!1;let n=this.renderer.getContext();if(n&&typeof n.isContextLost==`function`&&n.isContextLost())return!1;let r=this.animator.tick();this.flushOverrides();let i=this.canvas,a=this.sceneAnchor.meterInMercator;this._enuMatrix.set(a,0,0,this.sceneAnchor.x,0,-a,0,this.sceneAnchor.y,0,0,a,this.sceneAnchor.z,0,0,0,1);let o=new t.Matrix4().fromArray(e.mvp);o.multiply(this._enuMatrix),this.camera.projectionMatrix.copy(o),this.camera.projectionMatrixInverse.copy(o).invert();let s=e.cameraEnu;this.camera.position.set(s[0],s[1],s[2]),this.camera.matrixWorld.setPosition(s[0],s[1],s[2]),this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert(),this.groundManager.update(this.camera);let c=!1;for(let t of this.datasets.values()){if(!t.visible||!t.tileset)continue;let n=[s[0]-t.offset[0],s[1]-t.offset[1],s[2]-t.offset[2]];t.tileset.update(n,e.fovRad,e.canvasHeight)&&(c=!0)}this.style.mode===Z.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(i),this.renderer.setViewport(0,0,i.width,i.height),this.renderer.resetState(),this.renderer.render(this.scene,this.camera),this._frame++;let u=performance.now();return u-this._fps.last>500&&(this._fps.value=Math.round(this._frame*1e3/(u-this._fps.last)),this._frame=0,this._fps.last=u),r||this.style.mode===Z.DYNAMIC||l||this.stats.loading>0||c}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};for(let t of this.datasets.values()){let n=t.tileset?.stats;n&&(e.tiles+=n.tiles,e.loading+=n.loading,e.failed+=n.failed,e.meshes+=n.meshes,e.vertices+=n.vertices,e.triangles+=n.triangles)}return e}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of this.datasets.values()){let a=ta(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()}};v(wo,`_EDGE_SKIP_KEYWORDS`,[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`]),Ji();var To=1e-4;function Eo(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])>To*r)return!1}return!0}function Do(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 Oo(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function ko(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Ao(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 jo(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 Mo(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||!Oo(i,n.fov))return null;let o=i.clone().invert().multiply(a);if(!Eo(i.clone().multiply(o),Array.from(e.mvp))||!Do(o)||!Oo(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 No(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||!Oo(a,n.fov))return null;let s=a.clone().invert().multiply(o);if(!Eo(a.clone().multiply(s),Array.from(e.mvp))||!Do(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 Po=u({Animator:()=>Xa,AttributeQuery:()=>At,BinaryReader:()=>b,DEFAULT_FLOOR_HEIGHT:()=>wt,DEFAULT_STYLE:()=>ti,DatasetManager:()=>lo,EARTH_RADIUS:()=>jt,EASING_NAMES:()=>ka,FeatureStyleManager:()=>_o,GPUPathManager:()=>Jr,GroundManager:()=>vo,Path:()=>Gr,Picker:()=>va,PixelFormat:()=>G,S3MFormatError:()=>yt,S3MTileset:()=>ia,S3MViewer:()=>wo,S3M_VERSION:()=>Ue,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>Q,SELECT_MODE_LABELS:()=>ei,STYLE:()=>Z,STYLE_LABELS:()=>$r,TextureCompress:()=>K,VertexTag:()=>B,VertexTagV3:()=>We,buildAttributes:()=>Ct,buildBlendedMVP:()=>No,buildFeatureEdgeSegments:()=>oo,buildOrthoMVP:()=>Mo,buildThickLineGeometry:()=>to,buildTileObjects:()=>Gi,createLineSharedUniforms:()=>Za,createOutlineMaterial:()=>Qr,createSharedUniforms:()=>Xr,createStyledMaterial:()=>Zr,createTexture:()=>Br,createThickLineMaterial:()=>eo,cubicBezier:()=>Ba,default:()=>wo,dxtPixelFormatOf:()=>Cn,easing:()=>Aa,extractEulerAngles:()=>fo,extractFovRadians:()=>jo,extractNearFar:()=>Ao,extractProjectionMatrix:()=>ko,isS3M1Buffer:()=>Me,lngLatFromMercator:()=>Nt,lngLatFromWorld:()=>Ft,measureSegments:()=>St,mercatorFromLngLat:()=>Mt,parseS3M1:()=>He,parseS3MB:()=>bt,resolveFeature:()=>U,resolveRotationMatrix:()=>uo,resolveTextureKind:()=>Sn,setMaxAnisotropy:()=>Pr,steps:()=>Va,worldFromLngLat:()=>Pt});Tt(),mi(),Yr(),Wr(),En(),Kr(),Tt(),En(),Wr(),Kr(),Yr(),mi(),Ji();var Fo=globalThis;return Fo.THREE||(Fo.THREE=t),Fo.S3M=Po,e.Animator=Xa,e.AttributeQuery=At,e.BinaryReader=b,e.DEFAULT_FLOOR_HEIGHT=wt,e.DEFAULT_STYLE=ti,e.DatasetManager=lo,e.EARTH_RADIUS=jt,e.EASING_NAMES=ka,e.FeatureStyleManager=_o,e.GPUPathManager=Jr,e.GroundManager=vo,e.Path=Gr,e.Picker=va,e.PixelFormat=G,e.S3MFormatError=yt,e.S3MTileset=ia,e.S3MViewer=wo,e.default=wo,e.S3M_VERSION=Ue,e.SAMPLES_PER_PATH=qr,e.SELECT_MODE=Q,e.SELECT_MODE_LABELS=ei,e.STYLE=Z,e.STYLE_LABELS=$r,e.TextureCompress=K,e.VertexTag=B,e.VertexTagV3=We,e.buildAttributes=Ct,e.buildBlendedMVP=No,e.buildFeatureEdgeSegments=oo,e.buildOrthoMVP=Mo,e.buildThickLineGeometry=to,e.buildTileObjects=Gi,e.createLineSharedUniforms=Za,e.createOutlineMaterial=Qr,e.createSharedUniforms=Xr,e.createStyledMaterial=Zr,e.createTexture=Br,e.createThickLineMaterial=eo,e.cubicBezier=Ba,e.dxtPixelFormatOf=Cn,e.easing=Aa,e.extractEulerAngles=fo,e.extractFovRadians=jo,e.extractNearFar=Ao,e.extractProjectionMatrix=ko,e.isS3M1Buffer=Me,e.lngLatFromMercator=Nt,e.lngLatFromWorld=Ft,e.measureSegments=St,e.mercatorFromLngLat=Mt,e.parseS3M1=He,e.parseS3MB=bt,e.resolveFeature=U,e.resolveRotationMatrix=uo,e.resolveTextureKind=Sn,e.setMaxAnisotropy=Pr,e.steps=Va,e.worldFromLngLat=Pt,e})({},THREE);
904
+ `}),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()}};Wr(),mi(),Kr(),Yr(),Tt(),y();var yo=65534;function $(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function bo(e){return e.isPoints===!0}var xo=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`edgeWidth`,`edgeOpacity`,`outlineWidth`],So=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],Co=[`translation`,`elevation`,`opacity`,`color`,`rotation`],wo=class e{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={}){v(this,`options`,void 0),v(this,`pickable`,void 0),v(this,`onStats`,void 0),v(this,`onReady`,void 0),v(this,`onPick`,void 0),v(this,`onError`,void 0),v(this,`geo`,null),v(this,`canvas`,null),v(this,`renderer`,null),v(this,`scene`,null),v(this,`camera`,null),v(this,`picker`,null),v(this,`uniforms`,void 0),v(this,`style`,void 0),v(this,`_styleTarget`,void 0),v(this,`outlineMaterial`,void 0),v(this,`lineShared`,void 0),v(this,`edgeMaterial`,void 0),v(this,`selectionEdgeMaterial`,void 0),v(this,`_edgeStyleUniforms`,void 0),v(this,`_selEdgeStyleUniforms`,void 0),v(this,`groundManager`,void 0),v(this,`_datasetManager`,new lo),v(this,`_featureStyleManager`,void 0),v(this,`gpuPathManager`,new Jr),v(this,`_customPathTime`,!1),v(this,`_pickables`,new Map),v(this,`_pickSeq`,0),v(this,`_freePickIds`,[]),v(this,`_smidMeshes`,new Map),v(this,`_meshHeight`,new Map),v(this,`_heightMin`,1/0),v(this,`_heightMax`,-1/0),v(this,`_boxScratch`,new t.Box3),v(this,`_selection`,null),v(this,`_selectedMeshes`,[]),v(this,`_outlineMesh`,null),v(this,`_outlineMeshes`,[]),v(this,`_selectionEdges`,null),v(this,`_selectionEdgeMeshes`,[]),v(this,`_edgesEnabled`,!1),v(this,`_tileFadeSeq`,0),v(this,`_modeGen`,0),v(this,`_pathSpecs`,new Map),v(this,`_pathScratch`,new Float32Array(3)),v(this,`_creaseLines`,null),v(this,`_nativeEdgeLines`,new Set),v(this,`_pointClouds`,new Set),v(this,`_opacityTransparent`,!1),v(this,`animator`,new Xa),v(this,`attributeQuery`,null),v(this,`_enuMatrix`,new t.Matrix4),v(this,`_colorScratch`,new t.Color),v(this,`_needsRepaint`,!0),v(this,`_frame`,0),v(this,`_fps`,{value:0,last:0}),v(this,`_ambientLight`,void 0),v(this,`_hemiLight`,void 0),v(this,`_keyLight`,void 0),v(this,`_fillLight`,void 0),v(this,`_lightOptions`,{ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50}),v(this,`_datasetQueue`,void 0),v(this,`_onRequestRepaint`,()=>{}),v(this,`_getBearing`,void 0),v(this,`_lodRangeScale`,1),this.options=e,this.pickable=e.pickable!==!1,this._lodRangeScale=e.lodRangeScale??1,e.light&&Object.assign(this._lightOptions,e.light),e.totalMaxTiles&&(this._datasetManager.totalMaxTiles=e.totalMaxTiles),this._onRequestRepaint=e.onRequestRepaint??(()=>{}),this._getBearing=e.getBearing,this.onStats=e.onStats??(()=>{}),this.onReady=e.onReady??(()=>{}),this.onPick=e.onPick??(()=>{}),this.onError=e.onError??(e=>console.warn(`[s3m]`,e)),this.groundManager=new vo(e.ground),this.scene||(this.scene=new t.Scene,this.scene.add(this.groundManager.group),this._addLights()),this._featureStyleManager=new _o(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._selection&&this._syncSelectionStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=Xr(),Ir(Bt),this.style={...ti,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Qr(this.uniforms),this.lineShared=Za(),this._edgeStyleUniforms={uColor:{value:new t.Color(this.style.edgeColor)},uWidth:{value:Math.max(.1,this.style.edgeWidth??1.5)},uOpacity:{value:.6}},this.edgeMaterial=eo(this.lineShared,{},this._edgeStyleUniforms),this._selEdgeStyleUniforms={uColor:{value:new t.Color(this.style.outlineColor??this.style.selectColor)},uWidth:{value:Math.max(.1,this.style.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:this.style.selectElevation??0}},this.selectionEdgeMaterial=eo(this.lineShared,{},this._selEdgeStyleUniforms),this.setEdges(!!this.style.edges),this._applyOpacity(),this._fps.last=performance.now(),this._datasetQueue=this._normalizeDatasets(e),e.attributes&&(this.attributeQuery=new At(e.attributes))}_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`);Fr(t&&n)}mount(e,n){this.canvas=e,this.renderer=this._createRenderer(e,n),Pr(this.renderer.capabilities.getMaxAnisotropy()),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 va(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),Pr(this.renderer.capabilities.getMaxAnisotropy()),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new va(this.renderer),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.outlineMaterial.dispose(),this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose(),this.scene?.clear(),this._selectedMeshes=[],this._outlineMeshes=[],this._selectionEdgeMeshes=[],this._outlineMesh=null,this._selectionEdges=null,this._smidMeshes.clear(),this._meshHeight.clear(),this.animator.clear(),this.animator.unregisterPrefix(`tile.`),this.animator.unregisterPrefix(`feature.`),this._pathSpecs.clear(),this._heightMin=1/0,this._heightMax=-1/0,this.renderer?.dispose(),this.renderer=null,this.canvas=null}_createLights(){this._ambientLight=new t.AmbientLight(this._lightOptions.ambientColor,this._lightOptions.ambientIntensity),this._hemiLight=new t.HemisphereLight(this._lightOptions.hemisphereColor,this._lightOptions.hemisphereGroundColor,this._lightOptions.hemisphereIntensity),this._keyLight=new t.DirectionalLight(this._lightOptions.keyLightColor,this._lightOptions.keyLightIntensity),this._fillLight=new t.DirectionalLight(this._lightOptions.fillLightColor,this._lightOptions.fillLightIntensity),this._updateLights()}_addLights(){this.scene&&(this._ambientLight||this._createLights(),this.scene.add(this._ambientLight,this._hemiLight,this._keyLight,this._fillLight))}_applyLightOptions(){this._ambientLight&&(this._ambientLight.intensity=this._lightOptions.ambientIntensity,this._ambientLight.color.set(this._lightOptions.ambientColor)),this._hemiLight&&(this._hemiLight.intensity=this._lightOptions.hemisphereIntensity,this._hemiLight.color.set(this._lightOptions.hemisphereColor),this._hemiLight.groundColor.set(this._lightOptions.hemisphereGroundColor)),this._keyLight&&(this._keyLight.intensity=this._lightOptions.keyLightIntensity,this._keyLight.color.set(this._lightOptions.keyLightColor)),this._fillLight&&(this._fillLight.intensity=this._lightOptions.fillLightIntensity,this._fillLight.color.set(this._lightOptions.fillLightColor))}setLight(e){let t={...e};t.mainColor!==void 0&&t.keyLightColor===void 0&&(t.keyLightColor=t.mainColor),t.mainIntensity!==void 0&&t.keyLightIntensity===void 0&&(t.keyLightIntensity=t.mainIntensity),Object.assign(this._lightOptions,t),this._applyLightOptions(),this._updateLights(),this._needsRepaint=!0,this.triggerRepaint()}getLight(){return{...this._lightOptions}}setToneMapping(e,t=1){this.options.toneMapping=e,this.options.toneMappingExposure=t,this.renderer&&(this.renderer.toneMapping=e,this.renderer.toneMappingExposure=t,this._needsRepaint=!0,this.triggerRepaint())}getToneMapping(){return{toneMapping:this.renderer?this.renderer.toneMapping:this.options.toneMapping??t.NoToneMapping,toneMappingExposure:this.renderer?this.renderer.toneMappingExposure:this.options.toneMappingExposure??1}}_updateLights(){if(!this._keyLight||!this._fillLight)return;let e=this._lightOptions.mode===`fixed`?0:(this._getBearing?.()??0)*Math.PI/180,t=(t,n,r)=>{if(!t)return;let i=e+n*Math.PI/180,a=r*Math.PI/180,o=Math.cos(a);t.position.set(Math.sin(i)*o,Math.cos(i)*o,Math.sin(a)).multiplyScalar(1e3)};t(this._keyLight,this._lightOptions.azimuth,this._lightOptions.altitude),t(this._fillLight,this._lightOptions.azimuth+65,Math.max(10,this._lightOptions.altitude-20))}_normalizeDatasets(e){return Array.isArray(e.datasets)?e.datasets.filter(e=>!!e?.configUrl):e.configUrl?[{id:`default`,name:`默认数据集`,configUrl:e.configUrl,useWorker:e.useWorker}]:[]}async addDataset(e){if(!this.scene)throw Error(`[s3m] 图层尚未 addLayer,不能添加数据集`);return await this._datasetManager.addDataset(e,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._needsRepaint=!0,this._requestRepaint()},onTileRemoved:(e,t)=>{this._unregisterTile(e,t),this.onStats(this.stats),this._needsRepaint=!0,this._requestRepaint()},onStats:()=>{this.onStats(this.stats),this._requestRepaint()},onError:e=>{this.onError(e),this.onStats(this.stats)},onReady:e=>{this.onReady(e),this._refreshAllHeights(),this.groundManager.excavationBounds||this.groundManager.autoFitExcavation(this.datasets.values())},triggerRepaint:()=>{this._requestRepaint()}})}_lngLatFromWorld(e,t){return Ft(this.geo,e,t)}recomputeAnchors(){this._datasetManager.recomputeAnchors(this.geo),this._refreshAllHeights(),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._refreshAllHeights(),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._refreshAllHeights(),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=fo(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=fo(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 Gr?t:new Gr(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)}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=fo(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=fo(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 Co)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 At(e):null}getLoadedSmids(){return[...this._smidMeshes.keys()]}auditBatches(){let e=this._featureStyleManager.auditBatches(this._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._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}_markOverridesDirty(e=`all`){e===`all`?this._featureStyleManager.markOverridesDirty(void 0,this.getAllMeshes()):this._featureStyleManager.markOverridesDirty(e)}flushOverrides(){this._featureStyleManager.flushOverrides()}_applyOverridesToMesh(e){this._featureStyleManager.applyOverridesToMesh(e)}removeDataset(e){if(this.datasets.get(e)){this._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._pickables.delete(n.pickId),this._releasePickId(n.pickId),n.pickId=void 0),this._unindexMeshSmids(t),this._removeMeshHeight(t),t.geometry?.dispose?.();let r=$(t);r&&r.dispose(),fa(t.material)&&t.material.dispose(),this._featureStyleManager.disposeMesh(t)})});for(let[t,n]of this._pickables)n.datasetId===e&&this._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._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;for(let r of e.group.children){if(r.isLineSegments&&r.userData.isEdgeLines){r.visible=this._edgesEnabled,this._nativeEdgeLines.add(r),this._styleEdgeLine(r);continue}let i=bo(r),a=r;if(!a.isMesh&&!i)continue;i&&this._pointClouds.add(r);let o=a.userData;if(o.pickId=this._allocPickId(),o.datasetId=t.id,o.nativeEdges=n,this._pickables.set(o.pickId,{datasetId:t.id,mesh:a,tile:e.tile,skeletonName:o.skeletonName??``}),this._indexMeshSmids(a),this._addMeshHeight(a),!n&&!i&&this._datasetEdgesEnabled(t)&&!this._shouldSkipAutoEdges(o,t.name)&&this._ensureEdges(a),i)this._applyPointCloudStyle(r);else{let e=$(a);if(e){e.transparent=Math.min(1,Math.max(.05,this.style.opacity??1))<.999;let t=this.style.depthWrite!==!1;e.depthWrite=e.transparent?t:this.style.depthWrite!==!1,e.flatShading=this.style.shading!==`smooth`,e.needsUpdate=!0,this._featureStyleManager.applyOverridesToMesh(a),this._startTileFade(a,e)}}this._replaySelectionOnto(a)}}_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),this._featureStyleManager.applyOverridesToMesh(e),t.depthWrite=this.style.depthWrite!==!1,this._requestRepaint()}})}_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)}_replaySelectionOnto(e){let t=this._selection;if(!t)return;let n=$(e);if(!n)return;let r=e.userData,i=-1;if(t.smid!=null){let e=r.geoRef?.pickInfo,n=e?.[t.smid]??e?.[String(t.smid)];i=n?H(n):-1}if(e===t.mesh&&(i=t.batchId),i<0&&e!==t.mesh){if(t.smid==null&&r.datasetId===t.datasetId&&this._isMeshCoveringSelection(e,t))i=-1;else return}n.userData.uSelBatch.value=i,n.userData.uSelWhole.value=+(i<0),this._selectedMeshes.includes(e)||this._selectedMeshes.push(e),bo(e)&&this._applyPointCloudStyle(e,!0),this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers}_unregisterTile(e,t){e.group.traverse(e=>{let t=e;if(e.isLineSegments&&t.userData?.isEdgeLines&&this._nativeEdgeLines.delete(e),bo(e)&&this._pointClouds.delete(e),t.userData?.tileFadeKey&&(this.animator.unregister(t.userData.tileFadeKey),t.userData.tileFadeKey=void 0),t.userData?.pickId!=null&&(this._pickables.delete(t.userData.pickId),this._releasePickId(t.userData.pickId),t.userData.pickId=void 0),t.isMesh){this._selectedMeshes.includes(t)&&(this._selectedMeshes=this._selectedMeshes.filter(e=>e!==t));let e=this._selection;if(e&&e.mesh===t){let n=e.smid,r=n==null?this._selectedMeshes.find(e=>e!==t&&e.parent&&e.parent.visible)??this._selectedMeshes.find(e=>e!==t&&e.parent):[...this._smidMeshes.get(n)??[]].find(e=>e!==t&&e.parent);r?(this._selection={...e,mesh:r},this._replaySelectionOnto(r)):this.select(null)}this._unindexMeshSmids(t),this._removeMeshHeight(t),this._featureStyleManager.disposeMesh(t),$(t)?.dispose?.()}fa(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)}_allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>yo){for(let e=0;e<=yo;e++)if(!this._pickables.has(e))return e;throw Error(`[s3m] 可拾取网格超过 65535 个,2 字节 ID 编码不够用`)}return this._pickSeq++}_releasePickId(e){this._freePickIds.push(e)}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:$r[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 So.includes(e)?3:1}_registerAnimChannels(){for(let e of xo)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of So)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._syncEdgeStyle()}}),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`)&&this._refreshEdgeLines())}_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&&this._edgesEnabled?(this._disposeEdges(),this.setEdges(!0)):(`edgeColor`in e||`edgeWidth`in e||`opacity`in e||`edgeOpacity`in e)&&this._refreshEdgeLines(),this._selection&&(`outline`in e||`outlineStyle`in e?this.select(this._selection,{silent:!0}):this._syncSelectionStyle())}_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??Q.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===Q.REPLACE?0:n===Q.MULTIPLY?2:n===Q.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.uOpacity&&t.opacity!=null&&(e.uOpacity.value=Math.min(1,Math.max(.05,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=Math.min(1,Math.max(.05,this.style.opacity??1));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._pickables.values()){if(bo(n.mesh))continue;let r=$(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||(r.transparent=t,r.depthWrite=!t||e))}}for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._syncEdgeStyle(),this._requestRepaint()}_applyPointCloudStyle(e,t=this._selectedMeshes.includes(e)){da(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`;for(let t of this._pickables.values()){let n=$(t.mesh);n&&n.flatShading!==e&&(n.flatShading=e,n.needsUpdate=!0)}this._requestRepaint()}_addMeshHeight(e){let t=e.geometry?.boundingBox;if(!t)return;this._boxScratch.copy(t).applyMatrix4(e.matrixWorld);let n=this._boxScratch.min.z,r=this._boxScratch.max.z;Number.isFinite(n)&&Number.isFinite(r)&&(this._meshHeight.set(e,{min:n,max:r}),n<this._heightMin&&(this._heightMin=n),r>this._heightMax&&(this._heightMax=r),this._pushHeightRange())}_removeMeshHeight(e){let t=this._meshHeight.get(e);t&&(this._meshHeight.delete(e),t.min===this._heightMin||t.max===this._heightMax?this._recomputeHeightRange():this._pushHeightRange())}_refreshAllHeights(){if(this._meshHeight.size===0)return;let e=[...this._meshHeight.keys()];this._meshHeight.clear(),this._heightMin=1/0,this._heightMax=-1/0;for(let t of e)this._addMeshHeight(t);this._pushHeightRange()}_recomputeHeightRange(){let e=1/0,t=-1/0;for(let n of this._meshHeight.values())n.min<e&&(e=n.min),n.max>t&&(t=n.max);this._heightMin=e,this._heightMax=t,this._pushHeightRange()}_pushHeightRange(){let e=this._heightMin,t=this._heightMax;(!Number.isFinite(e)||!Number.isFinite(t)||t<=e)&&(e=0,t=100),this.uniforms.uHeightMin.value=e,this.uniforms.uHeightMax.value=t}_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))}}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring);this._edgesEnabled=e,this.style.edges=e,this._styleTarget.edges=e;for(let t of this.datasets.values())t.root.traverse(t=>{t.userData.isEdgeLines&&(t.visible=e,this._styleEdgeLine(t))});if(this._syncEdgeStyle(),!e){n?this.animator.to(`style.edgeFade`,0,{...t,onComplete:()=>{this._disposeEdges(),this._requestRepaint(),t?.onComplete?.()}}):(this._setEdgeFade(1),this._disposeEdges()),this._requestRepaint();return}let r=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e.userData;return!t.edges&&!t.nativeEdges&&!bo(e)}),i=0,a=()=>{let e=performance.now();for(;i<r.length&&performance.now()-e<8;)this._ensureEdges(r[i++]);i<r.length?setTimeout(a,0):this._requestRepaint()};a(),n?(this._setEdgeFade(0),this.animator.to(`style.edgeFade`,1,t)):this._setEdgeFade(1)}_setEdgeFade(e){this.uniforms.uEdgeFade&&(this.uniforms.uEdgeFade.value=e),this._syncEdgeStyle()}_disposeEdges(){for(let e of this._pickables.values())this._removeEdges(e.mesh)}async loadCreases(e){let n=await fetch(e);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.style,s=new t.LineBasicMaterial({color:new t.Color(o.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,o.edgeOpacity??.6))*Math.min(1,Math.max(.05,o.opacity??1)),depthWrite:!1}),c=new t.LineSegments(a,s);c.renderOrder=2,c.frustumCulled=!1,c.raycast=()=>{},this.clearCreases(),this._creaseLines=c,this.scene?.add(c),this._requestRepaint()}clearCreases(){this._creaseLines&&(this.scene?.remove(this._creaseLines),this._creaseLines.geometry.dispose(),this._creaseLines.material?.dispose?.(),this._creaseLines=null,this._requestRepaint())}_syncEdgeStyle(){let e=this.style,t=this.uniforms.uEdgeFade?.value??1,n=Math.min(1,Math.max(0,e.edgeOpacity??.6))*Math.min(1,Math.max(.05,e.opacity??1))*t,r=this.edgeMaterial.uniforms;if(r.uColor.value.set(e.edgeColor),r.uWidth.value=Math.max(.1,e.edgeWidth??1.5),r.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.style.edgeColor),t.opacity=(this.style.edgeOpacity??.6)*Math.min(1,Math.max(.05,this.style.opacity??1))*(this.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._nativeEdgeLines)e.parent&&this._styleEdgeLine(e)}_datasetEdgesEnabled(e){let t=e.options?.enableEdges;return t===!0||t!==!1&&this._edgesEnabled}_shouldSkipAutoEdges(t,n){let r=`${t.skeletonName??``} ${n}`.toLowerCase();return e._EDGE_SKIP_KEYWORDS.some(e=>r.includes(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=co(e.geometry,.005),a=this.style.edgeThreshold??55,o=new t.EdgesGeometry(i,a);i.dispose();let s=o.getAttribute(`position`),c=s?s.array:null;if(o.dispose(),!c||c.length<6)return;let l=.005,u=no(e.geometry,l),d;if(u){let e=c.length/6;d=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;d[t]=u.get(ro(c[e],c[e+1],c[e+2],1/l))??-1}}let f=new t.Mesh(to(c,d),this._createEdgeMaterial(e));f.renderOrder=2,f.frustumCulled=!1,f.raycast=()=>{},f.userData.isThickEdge=!0,n.edges=f,e.add(f)}_createEdgeMaterial(e){let t=$(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return eo(this.lineShared,{},this._edgeStyleUniforms,n)}_createSelectionEdgeMaterial(e){let t=$(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return eo(this.lineShared,{},this._selEdgeStyleUniforms,n)}_removeEdges(e){let t=e.userData,n=t.edges;if(!n)return;e.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(e=>e?.dispose?.()):r?.dispose?.(),t.edges=null}getRayAt(e,n){if(!this.camera||!this.canvas)return null;let r=this.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.camera),l=new t.Vector3(o,s,1).unproject(this.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,o=null,s=e.batchId,c=e.instanceIndex,l=a.geoRef,u=[];if(c!=null){let e=this._instanceFeature(n.mesh,l,c);if(!e)return null;o=e.smid,s=e.batchId}else{l=a.geoByBatchId?.get(e.batchId)??a.geoRef;let t=U(l,e.batchId);o=t.smid,u=t.segments}if(this._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._smidMeshes.has(o)){let e=this._smidMeshes.get(o),t=1/0,n=1/0,r=1/0,i=-1/0,a=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,d=u?.[o]??u?.[String(o)],p=d?H(d):-1,m=d?.segments??(p>=0?U(e.geoRef,p).segments:[]),h=St(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=St(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=Ct({smid:o,box:d,triangles:m,floorHeight:this.style.floorHeight}),g=null;if(d&&this.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.sceneAnchor.meterInMercator;g=this._lngLatFromWorld(e.x*r+this.sceneAnchor.x,-e.y*r+this.sceneAnchor.y)}let _=r??null;!_&&i&&(_=this._intersectMeshAtRay(n.mesh,i,c));let v=null,y=null,b=null;if(_&&this.sceneAnchor){let e=o==null?{}:this._featureStyleManager.getFeatureEffectiveOffset(o),n=e.translation,r=e.elevation,i=_.clone();if(e.rotation){let n=uo(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.sceneAnchor.meterInMercator;y=this._lngLatFromWorld(i.x*a+this.sceneAnchor.x,-i.y*a+this.sceneAnchor.y),b=i.z+(this.sceneAnchor.altitude??0)}else g&&d&&this.sceneAnchor&&(y=g,b=(d.minZ+d.maxZ)/2+(this.sceneAnchor.altitude??0));return{datasetId:n.datasetId,datasetName:this.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}}pick(e,t){if(!this.picker||!this.scene||!this.camera||!this.sceneAnchor)return null;let n=this.picker.pick(this.scene,this.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.camera||!this.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.sceneAnchor.meterInMercator;return{lngLat:this._lngLatFromWorld(s.x*e+this.sceneAnchor.x,-s.y*e+this.sceneAnchor.y),altitude:s.z+(this.sceneAnchor.altitude??0),point:[s.x,s.y,s.z]}}return null}drillPick(e,n,r=10){if(!this.sceneAnchor||!this.camera)return[];let i=this.getRayAt(e,n);if(!i)return[];let a=new t.Raycaster;a.ray.copy(i);let o=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),s=a.intersectObjects(o,!1);if(!s.length)return[];let c=[],l=new Set,u=new Set;for(let e of s){if(c.length>=r)break;let t=e.object,n=t.userData;if(n.pickId==null)continue;let i=this._pickables.get(n.pickId);if(!i)continue;let a=null,o=-1,s=e.instanceId;if(s!=null){let e=this._instanceFeature(t,n.geoRef,s);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let r=t.geometry.attributes.aBatchId;if(r){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(r.getX(i)),a=U(n.geoByBatchId?.get(o)??n.geoRef,o).smid}}if(a!=null){if(l.has(a))continue;l.add(a)}else{let e=`${n.pickId}:${o}:${s??-1}`;if(u.has(e))continue;u.add(e)}if(this._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.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=xt(d),l.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){f=this._instanceBox(c,n);break}}else{let t=d,n=t[e]??t[String(e)];if(n){let e=U(u,H(n));if(f=St(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._featureStyleManager.getFeatureEffectiveOffset(e),u=l.translation,d=l.elevation,p=l.rotation?uo(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));for(let e of s){m&&h&&e.sub(h).applyMatrix3(m).add(h),u?e.add(new t.Vector3(u[0],u[1],u[2])):d&&(e.z+=d),e.applyMatrix4(c.matrixWorld);let o=this.sceneAnchor.meterInMercator,[s,l]=this._lngLatFromWorld(e.x*o+this.sceneAnchor.x,-e.y*o+this.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=xt(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}}select(e,{silent:t=!1}={}){if(this._selection){for(let e of this._selectedMeshes){if(bo(e)){this._applyPointCloudStyle(e,!1);continue}let t=$(e);t&&(t.userData.uSelBatch.value=-1,t.userData.uSelWhole.value=0)}this._selectedMeshes=[],this._clearSelectionDecoration(),this._selection=null}if(!e){this.uniforms.uSelMix.value=0,this.uniforms.uDim.value=0,this.outlineMaterial.uniforms.uSelBatch.value=-1,this.outlineMaterial.uniforms.uSelWhole.value=0,this.outlineMaterial.uniforms.uElevation.value=0,this._requestRepaint(),t||this.onPick(null);return}this._selection=e;let n=new Set;if(e.smid!=null){let t=this._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=$(t);if(!n)continue;let r=e.batchId;if(e.instanceIndex!=null&&t===e.mesh)r=e.batchId;else if(e.smid!=null){let n=t.userData.geoRef?.pickInfo,i=n?.[e.smid]??n?.[String(e.smid)],a=i?H(i):-1;r=a>=0?a:t===e.mesh?e.batchId:-1}n.userData.uSelBatch.value=r,n.userData.uSelWhole.value=+(r<0),this._selectedMeshes.push(t)}for(let e of this._selectedMeshes)bo(e)&&this._applyPointCloudStyle(e,!0);if(this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers,this.style.outline){let t=[...n].filter(e=>!bo(e));t.length&&((this.style.outlineStyle??`edges`)===`edges`?this._addSelectionEdges(e,t):this._addSelectionHull(e,t))}this._requestRepaint()}_addSelectionEdges(e,n){this._syncSelectionStyle();for(let r of n){let n=r.userData,i=n.geoRef,a=[],o=-1;if(r===e.mesh&&e.instanceIndex!=null){a=[{vertexOffset:0,vertexCount:r.geometry.getAttribute(`position`)?.count??0}];let t=i?.pickInfo,n=t?.[e.smid??``]??t?.[String(e.smid)];o=n?H(n):-1}else if(e.smid!=null){let t=i?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],r=n?H(n):-1;o=r,a=n?.segments??(r>=0?U(i,r).segments:[])}else r===e.mesh&&(a=U(n.geoByBatchId?.get(e.batchId)??i,e.batchId).segments,o=e.batchId);let s=oo(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(to(s,n),this._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):this._selectionEdges=this._selectionEdgeMeshes[0]??null}_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.outlineMaterial.uniforms.uSelBatch.value=r?-1:e.batchId,this.outlineMaterial.uniforms.uSelWhole.value=r||e.batchId<0?1:0,this.outlineMaterial.uniforms.uElevation.value=r?this._selectionElevation(e):this.style.selectElevation??0;for(let r of n){let n=$(r);n?.userData?.uBatchTex&&(this.outlineMaterial.uniforms.uBatchTex.value=n.userData.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=n.userData.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=n.userData.uBatchTexActive.value);let i=new t.Mesh(r.geometry,this.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)}this._outlineMesh=this._outlineMeshes[0]??null}_syncSelectionStyle(){let e=this.style,t=this.selectionEdgeMaterial.uniforms;t.uColor.value.set(e.outlineColor??e.selectColor),t.uWidth.value=Math.max(.1,e.outlineWidthPx??3),t.uOpacity.value=Math.min(1,Math.max(.05,e.opacity??1)),t.uElevation&&(t.uElevation.value=e.selectElevation??0);for(let e of this._outlineMeshes){let t=e.parent,n=t?$(t)?.userData:null;n?.uBatchTex&&(this.outlineMaterial.uniforms.uBatchTex.value=n.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=n.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=n.uBatchTexActive.value)}}_selectionElevation(e){let t=this.style.selectElevation??0;if(e.smid!=null){let n=this._featureStyleManager.getFeatureEffectiveOffset(e.smid);n.elevation&&(t+=n.elevation)}return t}_clearSelectionDecoration(){for(let e of this._outlineMeshes)e.parent?.remove(e);this._outlineMeshes=[],this._outlineMesh=null;for(let e of this._selectionEdgeMeshes)e.parent?.remove(e),e.geometry.dispose();this._selectionEdgeMeshes=[],this._selectionEdges=null}_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}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()}}renderFrame(e){if(!this.renderer||!this.scene||!this.camera||!this.sceneAnchor||!this.canvas)return!1;let n=this.renderer.getContext();if(n&&typeof n.isContextLost==`function`&&n.isContextLost())return!1;let r=this.animator.tick();this.flushOverrides();let i=this.canvas,a=this.sceneAnchor.meterInMercator;this._enuMatrix.set(a,0,0,this.sceneAnchor.x,0,-a,0,this.sceneAnchor.y,0,0,a,this.sceneAnchor.z,0,0,0,1);let o=new t.Matrix4().fromArray(e.mvp);o.multiply(this._enuMatrix),this.camera.projectionMatrix.copy(o),this.camera.projectionMatrixInverse.copy(o).invert();let s=e.cameraEnu;this.camera.position.set(s[0],s[1],s[2]),this.camera.matrixWorld.setPosition(s[0],s[1],s[2]),this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert(),this.groundManager.update(this.camera);let c=!1;for(let t of this.datasets.values()){if(!t.visible||!t.tileset)continue;let n=[s[0]-t.offset[0],s[1]-t.offset[1],s[2]-t.offset[2]];t.tileset.update(n,e.fovRad,e.canvasHeight)&&(c=!0)}this.style.mode===Z.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(i),this.renderer.setViewport(0,0,i.width,i.height),this.renderer.resetState(),this.renderer.render(this.scene,this.camera),this._frame++;let u=performance.now();return u-this._fps.last>500&&(this._fps.value=Math.round(this._frame*1e3/(u-this._fps.last)),this._frame=0,this._fps.last=u),r||this.style.mode===Z.DYNAMIC||l||this.stats.loading>0||c}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};for(let t of this.datasets.values()){let n=t.tileset?.stats;n&&(e.tiles+=n.tiles,e.loading+=n.loading,e.failed+=n.failed,e.meshes+=n.meshes,e.vertices+=n.vertices,e.triangles+=n.triangles)}return e}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of this.datasets.values()){let a=ta(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()}};v(wo,`_EDGE_SKIP_KEYWORDS`,[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`]),Ji();var To=1e-4;function Eo(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])>To*r)return!1}return!0}function Do(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 Oo(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function ko(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function Ao(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 jo(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 Mo(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||!Oo(i,n.fov))return null;let o=i.clone().invert().multiply(a);if(!Eo(i.clone().multiply(o),Array.from(e.mvp))||!Do(o)||!Oo(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 No(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||!Oo(a,n.fov))return null;let s=a.clone().invert().multiply(o);if(!Eo(a.clone().multiply(s),Array.from(e.mvp))||!Do(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 Po=u({Animator:()=>Xa,AttributeQuery:()=>At,BinaryReader:()=>b,DEFAULT_FLOOR_HEIGHT:()=>wt,DEFAULT_STYLE:()=>ti,DatasetManager:()=>lo,EARTH_RADIUS:()=>jt,EASING_NAMES:()=>ka,FeatureStyleManager:()=>_o,GPUPathManager:()=>Jr,GroundManager:()=>vo,Path:()=>Gr,Picker:()=>va,PixelFormat:()=>G,S3MFormatError:()=>yt,S3MTileset:()=>ia,S3MViewer:()=>wo,S3M_VERSION:()=>Ue,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>Q,SELECT_MODE_LABELS:()=>ei,STYLE:()=>Z,STYLE_LABELS:()=>$r,TextureCompress:()=>K,VertexTag:()=>B,VertexTagV3:()=>We,buildAttributes:()=>Ct,buildBlendedMVP:()=>No,buildFeatureEdgeSegments:()=>oo,buildOrthoMVP:()=>Mo,buildThickLineGeometry:()=>to,buildTileObjects:()=>Gi,createLineSharedUniforms:()=>Za,createOutlineMaterial:()=>Qr,createSharedUniforms:()=>Xr,createStyledMaterial:()=>Zr,createTexture:()=>Br,createThickLineMaterial:()=>eo,cubicBezier:()=>Ba,default:()=>wo,dxtPixelFormatOf:()=>Cn,easing:()=>Aa,extractEulerAngles:()=>fo,extractFovRadians:()=>jo,extractNearFar:()=>Ao,extractProjectionMatrix:()=>ko,isS3M1Buffer:()=>Me,lngLatFromMercator:()=>Nt,lngLatFromWorld:()=>Ft,measureSegments:()=>St,mercatorFromLngLat:()=>Mt,parseS3M1:()=>He,parseS3MB:()=>bt,resolveFeature:()=>U,resolveRotationMatrix:()=>uo,resolveTextureKind:()=>Sn,setMaxAnisotropy:()=>Pr,steps:()=>Va,worldFromLngLat:()=>Pt});Tt(),mi(),Yr(),Wr(),En(),Kr(),Tt(),En(),Wr(),Kr(),Yr(),mi(),Ji();var Fo=globalThis;return Fo.THREE||(Fo.THREE=t),Fo.S3M=Po,e.Animator=Xa,e.AttributeQuery=At,e.BinaryReader=b,e.DEFAULT_FLOOR_HEIGHT=wt,e.DEFAULT_STYLE=ti,e.DatasetManager=lo,e.EARTH_RADIUS=jt,e.EASING_NAMES=ka,e.FeatureStyleManager=_o,e.GPUPathManager=Jr,e.GroundManager=vo,e.Path=Gr,e.Picker=va,e.PixelFormat=G,e.S3MFormatError=yt,e.S3MTileset=ia,e.S3MViewer=wo,e.default=wo,e.S3M_VERSION=Ue,e.SAMPLES_PER_PATH=qr,e.SELECT_MODE=Q,e.SELECT_MODE_LABELS=ei,e.STYLE=Z,e.STYLE_LABELS=$r,e.TextureCompress=K,e.VertexTag=B,e.VertexTagV3=We,e.buildAttributes=Ct,e.buildBlendedMVP=No,e.buildFeatureEdgeSegments=oo,e.buildOrthoMVP=Mo,e.buildThickLineGeometry=to,e.buildTileObjects=Gi,e.createLineSharedUniforms=Za,e.createOutlineMaterial=Qr,e.createSharedUniforms=Xr,e.createStyledMaterial=Zr,e.createTexture=Br,e.createThickLineMaterial=eo,e.cubicBezier=Ba,e.dxtPixelFormatOf=Cn,e.easing=Aa,e.extractEulerAngles=fo,e.extractFovRadians=jo,e.extractNearFar=Ao,e.extractProjectionMatrix=ko,e.isS3M1Buffer=Me,e.lngLatFromMercator=Nt,e.lngLatFromWorld=Ft,e.measureSegments=St,e.mercatorFromLngLat=Mt,e.parseS3M1=He,e.parseS3MB=bt,e.resolveFeature=U,e.resolveRotationMatrix=uo,e.resolveTextureKind=Sn,e.setMaxAnisotropy=Pr,e.steps=Va,e.worldFromLngLat=Pt,e})({},THREE);
@@ -4735,4 +4735,4 @@ void main() {
4735
4735
  }
4736
4736
  gl_FragColor = vec4(1.0);
4737
4737
  }
4738
- `}),i=new dc(e,r);i.position.set(0,0,-.02),i.renderOrder=-1e3,i.name=`s3m-ground-depth`,i.visible=!1,this.group.add(i),this._depthMesh=i,this._depthMaterial=r,this._syncUniforms()}_applyMode(){this._mesh&&(this._mesh.visible=this.mode!==`none`),this._material&&(this._material.uniforms.uMode.value=this.mode===`excavate`?2:+(this.mode===`translucent`),this._material.depthWrite=this.mode===`excavate`),this._depthMesh&&(this._depthMesh.visible=this.occlude,this._depthMaterial&&(this._depthMaterial.uniforms.uPunchPit.value=+(this.mode===`excavate`)))}update(e){e&&this.group.position.set(e.position.x,e.position.y,this.groundHeight)}setGroundHeight(e){this.groundHeight=e,this.group.position.z=e}setMode(e){this.mode=e,this._occludeExplicit||(this.occlude=e===`excavate`),this._applyMode()}setOcclude(e){this.occlude=e,this._occludeExplicit=!0,this._applyMode()}setOpacity(e){this.opacity=Math.max(0,Math.min(1,e)),this._material&&(this._material.uniforms.uOpacity.value=this.opacity)}setColors(e,t){this.color.set(e),t&&this.gridColor.set(t),this._material&&(this._material.uniforms.uColor.value=this.color,this._material.uniforms.uGridColor.value=this.gridColor)}setExcavationBounds(e){this.excavationBounds=e,this._syncUniforms()}autoFitExcavation(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e){let e=o.tileset?.config,s=e?.rootTiles??e?.tiles;if(Array.isArray(s))for(let e of s){let s=e.boundingBox;if(!s)continue;let c=s.center??{x:0,y:0},l=s.xExtent?.x?Math.abs(s.xExtent.x):50,u=s.yExtent?.y?Math.abs(s.yExtent.y):50,d=c.x+o.offset[0]-l,f=c.x+o.offset[0]+l,p=c.y+o.offset[1]-u,m=c.y+o.offset[1]+u;d<t&&(t=d),f>r&&(r=f),p<n&&(n=p),m>i&&(i=m),a=!0}}a&&Number.isFinite(t)&&this.setExcavationBounds([t-5,n-5,r+5,i+5])}_syncUniforms(){let e=this.excavationBounds;if(this._material){let t=this._material.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}if(this._depthMaterial){let t=this._depthMaterial.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}}dispose(){this._geom?.dispose(),this._geom=null,this._material?.dispose(),this._material=null,this._depthMaterial?.dispose(),this._depthMaterial=null,this._mesh=null,this._depthMesh=null,this.group.clear()}};rh(),Oy(),eb(),Ay(),Ny(),a_(),uh();var iS=65534;function aS(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function oS(e){return e.isPoints===!0}var sS=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`edgeWidth`,`edgeOpacity`,`outlineWidth`],cS=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],lS=[`translation`,`elevation`,`opacity`,`color`,`rotation`],uS=class e{get datasets(){return this._datasetManager.datasets}get sceneAnchor(){return this._datasetManager.sceneAnchor}set sceneAnchor(e){this._datasetManager.sceneAnchor=e}_requestRepaint(){this._onRequestRepaint()}triggerRepaint(){this._requestRepaint()}constructor(e={}){X(this,`options`,void 0),X(this,`pickable`,void 0),X(this,`onStats`,void 0),X(this,`onReady`,void 0),X(this,`onPick`,void 0),X(this,`onError`,void 0),X(this,`geo`,null),X(this,`canvas`,null),X(this,`renderer`,null),X(this,`scene`,null),X(this,`camera`,null),X(this,`picker`,null),X(this,`uniforms`,void 0),X(this,`style`,void 0),X(this,`_styleTarget`,void 0),X(this,`outlineMaterial`,void 0),X(this,`lineShared`,void 0),X(this,`edgeMaterial`,void 0),X(this,`selectionEdgeMaterial`,void 0),X(this,`_edgeStyleUniforms`,void 0),X(this,`_selEdgeStyleUniforms`,void 0),X(this,`groundManager`,void 0),X(this,`_datasetManager`,new Yx),X(this,`_featureStyleManager`,void 0),X(this,`gpuPathManager`,new My),X(this,`_customPathTime`,!1),X(this,`_pickables`,new Map),X(this,`_pickSeq`,0),X(this,`_freePickIds`,[]),X(this,`_smidMeshes`,new Map),X(this,`_meshHeight`,new Map),X(this,`_heightMin`,1/0),X(this,`_heightMax`,-1/0),X(this,`_boxScratch`,new ho),X(this,`_selection`,null),X(this,`_selectedMeshes`,[]),X(this,`_outlineMesh`,null),X(this,`_outlineMeshes`,[]),X(this,`_selectionEdges`,null),X(this,`_selectionEdgeMeshes`,[]),X(this,`_edgesEnabled`,!1),X(this,`_tileFadeSeq`,0),X(this,`_modeGen`,0),X(this,`_pathSpecs`,new Map),X(this,`_pathScratch`,new Float32Array(3)),X(this,`_creaseLines`,null),X(this,`_nativeEdgeLines`,new Set),X(this,`_pointClouds`,new Set),X(this,`_opacityTransparent`,!1),X(this,`animator`,new Ix),X(this,`attributeQuery`,null),X(this,`_enuMatrix`,new U),X(this,`_colorScratch`,new W),X(this,`_needsRepaint`,!0),X(this,`_frame`,0),X(this,`_fps`,{value:0,last:0}),X(this,`_ambientLight`,void 0),X(this,`_hemiLight`,void 0),X(this,`_keyLight`,void 0),X(this,`_fillLight`,void 0),X(this,`_lightOptions`,{ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50}),X(this,`_datasetQueue`,void 0),X(this,`_onRequestRepaint`,()=>{}),X(this,`_getBearing`,void 0),X(this,`_lodRangeScale`,1),this.options=e,this.pickable=e.pickable!==!1,this._lodRangeScale=e.lodRangeScale??1,e.light&&Object.assign(this._lightOptions,e.light),e.totalMaxTiles&&(this._datasetManager.totalMaxTiles=e.totalMaxTiles),this._onRequestRepaint=e.onRequestRepaint??(()=>{}),this._getBearing=e.getBearing,this.onStats=e.onStats??(()=>{}),this.onReady=e.onReady??(()=>{}),this.onPick=e.onPick??(()=>{}),this.onError=e.onError??(e=>console.warn(`[s3m]`,e)),this.groundManager=new rS(e.ground),this.scene||(this.scene=new Wl,this.scene.add(this.groundManager.group),this._addLights()),this._featureStyleManager=new nS(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._selection&&this._syncSelectionStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=Py(),by(b_),this.style={...Vy,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Iy(this.uniforms),this.lineShared=Lx(),this._edgeStyleUniforms={uColor:{value:new W(this.style.edgeColor)},uWidth:{value:Math.max(.1,this.style.edgeWidth??1.5)},uOpacity:{value:.6}},this.edgeMaterial=Bx(this.lineShared,{},this._edgeStyleUniforms),this._selEdgeStyleUniforms={uColor:{value:new W(this.style.outlineColor??this.style.selectColor)},uWidth:{value:Math.max(.1,this.style.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:this.style.selectElevation??0}},this.selectionEdgeMaterial=Bx(this.lineShared,{},this._selEdgeStyleUniforms),this.setEdges(!!this.style.edges),this._fps.last=performance.now(),this._datasetQueue=this._normalizeDatasets(e),e.attributes&&(this.attributeQuery=new u_(e.attributes))}_createRenderer(e,t){let n=new Vl({canvas:e,context:t,antialias:!0});return n.autoClear=!1,n.setPixelRatio(1),n.toneMapping=this.options.toneMapping===void 0?0:this.options.toneMapping,n.toneMappingExposure=this.options.toneMappingExposure??1,n}_syncTextureCapabilities(e){let t=!!e.getExtension(`WEBGL_compressed_texture_s3tc`),n=!!e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`);yy(t&&n)}mount(e,t){this.canvas=e,this.renderer=this._createRenderer(e,t),vy(this.renderer.capabilities.getMaxAnisotropy()),this._syncTextureCapabilities(t),this.scene=new Wl,this.scene.add(this.groundManager.group),this._addLights(),this.camera=new _c,this.camera.matrixAutoUpdate=!1,this.picker=new ix(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),vy(this.renderer.capabilities.getMaxAnisotropy()),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new ix(this.renderer),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.outlineMaterial.dispose(),this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose(),this.scene?.clear(),this._selectedMeshes=[],this._outlineMeshes=[],this._selectionEdgeMeshes=[],this._outlineMesh=null,this._selectionEdges=null,this._smidMeshes.clear(),this._meshHeight.clear(),this.animator.clear(),this.animator.unregisterPrefix(`tile.`),this.animator.unregisterPrefix(`feature.`),this._pathSpecs.clear(),this._heightMin=1/0,this._heightMax=-1/0,this.renderer?.dispose(),this.renderer=null,this.canvas=null}_createLights(){this._ambientLight=new mp(this._lightOptions.ambientColor,this._lightOptions.ambientIntensity),this._hemiLight=new ep(this._lightOptions.hemisphereColor,this._lightOptions.hemisphereGroundColor,this._lightOptions.hemisphereIntensity),this._keyLight=new pp(this._lightOptions.keyLightColor,this._lightOptions.keyLightIntensity),this._fillLight=new pp(this._lightOptions.fillLightColor,this._lightOptions.fillLightIntensity),this._updateLights()}_addLights(){this.scene&&(this._ambientLight||this._createLights(),this.scene.add(this._ambientLight,this._hemiLight,this._keyLight,this._fillLight))}_applyLightOptions(){this._ambientLight&&(this._ambientLight.intensity=this._lightOptions.ambientIntensity,this._ambientLight.color.set(this._lightOptions.ambientColor)),this._hemiLight&&(this._hemiLight.intensity=this._lightOptions.hemisphereIntensity,this._hemiLight.color.set(this._lightOptions.hemisphereColor),this._hemiLight.groundColor.set(this._lightOptions.hemisphereGroundColor)),this._keyLight&&(this._keyLight.intensity=this._lightOptions.keyLightIntensity,this._keyLight.color.set(this._lightOptions.keyLightColor)),this._fillLight&&(this._fillLight.intensity=this._lightOptions.fillLightIntensity,this._fillLight.color.set(this._lightOptions.fillLightColor))}setLight(e){let t={...e};t.mainColor!==void 0&&t.keyLightColor===void 0&&(t.keyLightColor=t.mainColor),t.mainIntensity!==void 0&&t.keyLightIntensity===void 0&&(t.keyLightIntensity=t.mainIntensity),Object.assign(this._lightOptions,t),this._applyLightOptions(),this._updateLights(),this._needsRepaint=!0,this.triggerRepaint()}getLight(){return{...this._lightOptions}}setToneMapping(e,t=1){this.options.toneMapping=e,this.options.toneMappingExposure=t,this.renderer&&(this.renderer.toneMapping=e,this.renderer.toneMappingExposure=t,this._needsRepaint=!0,this.triggerRepaint())}getToneMapping(){return{toneMapping:this.renderer?this.renderer.toneMapping:this.options.toneMapping??0,toneMappingExposure:this.renderer?this.renderer.toneMappingExposure:this.options.toneMappingExposure??1}}_updateLights(){if(!this._keyLight||!this._fillLight)return;let e=this._lightOptions.mode===`fixed`?0:(this._getBearing?.()??0)*Math.PI/180,t=(t,n,r)=>{if(!t)return;let i=e+n*Math.PI/180,a=r*Math.PI/180,o=Math.cos(a);t.position.set(Math.sin(i)*o,Math.cos(i)*o,Math.sin(a)).multiplyScalar(1e3)};t(this._keyLight,this._lightOptions.azimuth,this._lightOptions.altitude),t(this._fillLight,this._lightOptions.azimuth+65,Math.max(10,this._lightOptions.altitude-20))}_normalizeDatasets(e){return Array.isArray(e.datasets)?e.datasets.filter(e=>!!e?.configUrl):e.configUrl?[{id:`default`,name:`默认数据集`,configUrl:e.configUrl,useWorker:e.useWorker}]:[]}async addDataset(e){if(!this.scene)throw Error(`[s3m] 图层尚未 addLayer,不能添加数据集`);return await this._datasetManager.addDataset(e,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._needsRepaint=!0,this._requestRepaint()},onTileRemoved:(e,t)=>{this._unregisterTile(e,t),this.onStats(this.stats),this._needsRepaint=!0,this._requestRepaint()},onStats:()=>{this.onStats(this.stats),this._requestRepaint()},onError:e=>{this.onError(e),this.onStats(this.stats)},onReady:e=>{this.onReady(e),this._refreshAllHeights(),this.groundManager.excavationBounds||this.groundManager.autoFitExcavation(this.datasets.values())},triggerRepaint:()=>{this._requestRepaint()}})}_lngLatFromWorld(e,t){return h_(this.geo,e,t)}recomputeAnchors(){this._datasetManager.recomputeAnchors(this.geo),this._refreshAllHeights(),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._refreshAllHeights(),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._refreshAllHeights(),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=Zx(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=Zx(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 ky?t:new ky(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)}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=Zx(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=Zx(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 lS)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 u_(e):null}getLoadedSmids(){return[...this._smidMeshes.keys()]}auditBatches(){let e=this._featureStyleManager.auditBatches(this._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._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}_markOverridesDirty(e=`all`){e===`all`?this._featureStyleManager.markOverridesDirty(void 0,this.getAllMeshes()):this._featureStyleManager.markOverridesDirty(e)}flushOverrides(){this._featureStyleManager.flushOverrides()}_applyOverridesToMesh(e){this._featureStyleManager.applyOverridesToMesh(e)}removeDataset(e){if(this.datasets.get(e)){this._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._pickables.delete(n.pickId),this._releasePickId(n.pickId),n.pickId=void 0),this._unindexMeshSmids(t),this._removeMeshHeight(t),t.geometry?.dispose?.();let r=aS(t);r&&r.dispose(),Qb(t.material)&&t.material.dispose(),this._featureStyleManager.disposeMesh(t)})});for(let[t,n]of this._pickables)n.datasetId===e&&this._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._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;for(let r of e.group.children){if(r.isLineSegments&&r.userData.isEdgeLines){r.visible=this._edgesEnabled,this._nativeEdgeLines.add(r),this._styleEdgeLine(r);continue}let i=oS(r),a=r;if(!a.isMesh&&!i)continue;i&&this._pointClouds.add(r);let o=a.userData;if(o.pickId=this._allocPickId(),o.datasetId=t.id,o.nativeEdges=n,this._pickables.set(o.pickId,{datasetId:t.id,mesh:a,tile:e.tile,skeletonName:o.skeletonName??``}),this._indexMeshSmids(a),this._addMeshHeight(a),!n&&!i&&this._datasetEdgesEnabled(t)&&!this._shouldSkipAutoEdges(o,t.name)&&this._ensureEdges(a),i)this._applyPointCloudStyle(r);else{let e=aS(a);if(e){let t=Math.min(1,Math.max(.05,this.style.opacity??1));e.transparent=t<.999,e.depthWrite=t>=.999,e.flatShading=this.style.shading!==`smooth`,e.needsUpdate=!0,this._featureStyleManager.applyOverridesToMesh(a),this._startTileFade(a,e)}}this._replaySelectionOnto(a)}}_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),this._featureStyleManager.applyOverridesToMesh(e),t.transparent||(t.depthWrite=!0),this._requestRepaint()}})}_isMeshCoveringSelection(e,t){if(!t.point)return!1;let n=e.geometry;if(!n||(n.boundingBox||n.computeBoundingBox(),!n.boundingBox))return!1;let r=new H(t.point[0],t.point[1],t.point[2]);e.updateWorldMatrix(!0,!1);let i=e.matrixWorld.clone().invert(),a=r.applyMatrix4(i);return n.boundingBox.clone().expandByScalar(.5).containsPoint(a)}_replaySelectionOnto(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?Qg(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),oS(e)&&this._applyPointCloudStyle(e,!0),this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers}_unregisterTile(e,t){e.group.traverse(e=>{let t=e;if(e.isLineSegments&&t.userData?.isEdgeLines&&this._nativeEdgeLines.delete(e),oS(e)&&this._pointClouds.delete(e),t.userData?.tileFadeKey&&(this.animator.unregister(t.userData.tileFadeKey),t.userData.tileFadeKey=void 0),t.userData?.pickId!=null&&(this._pickables.delete(t.userData.pickId),this._releasePickId(t.userData.pickId),t.userData.pickId=void 0),t.isMesh){this._selectedMeshes.includes(t)&&(this._selectedMeshes=this._selectedMeshes.filter(e=>e!==t));let e=this._selection;if(e&&e.mesh===t){let n=e.smid,r=n==null?this._selectedMeshes.find(e=>e!==t&&e.parent&&e.parent.visible)??this._selectedMeshes.find(e=>e!==t&&e.parent):[...this._smidMeshes.get(n)??[]].find(e=>e!==t&&e.parent);r?(this._selection={...e,mesh:r},this._replaySelectionOnto(r)):this.select(null)}this._unindexMeshSmids(t),this._removeMeshHeight(t),this._featureStyleManager.disposeMesh(t),aS(t)?.dispose?.()}Qb(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)}_allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>iS){for(let e=0;e<=iS;e++)if(!this._pickables.has(e))return e;throw Error(`[s3m] 可拾取网格超过 65535 个,2 字节 ID 编码不够用`)}return this._pickSeq++}_releasePickId(e){this._freePickIds.push(e)}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:Ry[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 cS.includes(e)?3:1}_registerAnimChannels(){for(let e of sS)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of cS)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._syncEdgeStyle()}}),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`)&&this._refreshEdgeLines())}_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&&this._edgesEnabled?(this._disposeEdges(),this.setEdges(!0)):(`edgeColor`in e||`edgeWidth`in e||`opacity`in e||`edgeOpacity`in e)&&this._refreshEdgeLines(),this._selection&&(`outline`in e||`outlineStyle`in e?this.select(this._selection,{silent:!0}):this._syncSelectionStyle())}_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??zy.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===zy.REPLACE?0:n===zy.MULTIPLY?2:n===zy.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),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=Math.min(1,Math.max(.05,this.style.opacity??1));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._pickables.values()){if(oS(n.mesh))continue;let r=aS(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||(r.transparent=t,r.depthWrite=!t||e))}}for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._syncEdgeStyle(),this._requestRepaint()}_applyPointCloudStyle(e,t=this._selectedMeshes.includes(e)){Zb(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`;for(let t of this._pickables.values()){let n=aS(t.mesh);n&&n.flatShading!==e&&(n.flatShading=e,n.needsUpdate=!0)}this._requestRepaint()}_addMeshHeight(e){let t=e.geometry?.boundingBox;if(!t)return;this._boxScratch.copy(t).applyMatrix4(e.matrixWorld);let n=this._boxScratch.min.z,r=this._boxScratch.max.z;Number.isFinite(n)&&Number.isFinite(r)&&(this._meshHeight.set(e,{min:n,max:r}),n<this._heightMin&&(this._heightMin=n),r>this._heightMax&&(this._heightMax=r),this._pushHeightRange())}_removeMeshHeight(e){let t=this._meshHeight.get(e);t&&(this._meshHeight.delete(e),t.min===this._heightMin||t.max===this._heightMax?this._recomputeHeightRange():this._pushHeightRange())}_refreshAllHeights(){if(this._meshHeight.size===0)return;let e=[...this._meshHeight.keys()];this._meshHeight.clear(),this._heightMin=1/0,this._heightMax=-1/0;for(let t of e)this._addMeshHeight(t);this._pushHeightRange()}_recomputeHeightRange(){let e=1/0,t=-1/0;for(let n of this._meshHeight.values())n.min<e&&(e=n.min),n.max>t&&(t=n.max);this._heightMin=e,this._heightMax=t,this._pushHeightRange()}_pushHeightRange(){let e=this._heightMin,t=this._heightMax;(!Number.isFinite(e)||!Number.isFinite(t)||t<=e)&&(e=0,t=100),this.uniforms.uHeightMin.value=e,this.uniforms.uHeightMax.value=t}_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))}}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring);this._edgesEnabled=e,this.style.edges=e,this._styleTarget.edges=e;for(let t of this.datasets.values())t.root.traverse(t=>{t.userData.isEdgeLines&&(t.visible=e,this._styleEdgeLine(t))});if(this._syncEdgeStyle(),!e){n?this.animator.to(`style.edgeFade`,0,{...t,onComplete:()=>{this._disposeEdges(),this._requestRepaint(),t?.onComplete?.()}}):(this._setEdgeFade(1),this._disposeEdges()),this._requestRepaint();return}let r=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e.userData;return!t.edges&&!t.nativeEdges&&!oS(e)}),i=0,a=()=>{let e=performance.now();for(;i<r.length&&performance.now()-e<8;)this._ensureEdges(r[i++]);i<r.length?setTimeout(a,0):this._requestRepaint()};a(),n?(this._setEdgeFade(0),this.animator.to(`style.edgeFade`,1,t)):this._setEdgeFade(1)}_setEdgeFade(e){this.uniforms.uEdgeFade&&(this.uniforms.uEdgeFade.value=e),this._syncEdgeStyle()}_disposeEdges(){for(let e of this._pickables.values())this._removeEdges(e.mesh)}async loadCreases(e){let t=await fetch(e);if(!t.ok)throw Error(`[s3m] 棱线缓存加载失败: ${t.status} ${e}`);let n=await t.arrayBuffer(),r=new Float32Array(n);if(r.length<6)return;let i=new q;i.setAttribute(`position`,new G(r,3));let a=this.style,o=new Qu({color:new W(a.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,a.edgeOpacity??.6))*Math.min(1,Math.max(.05,a.opacity??1)),depthWrite:!1}),s=new ld(i,o);s.renderOrder=2,s.frustumCulled=!1,s.raycast=()=>{},this.clearCreases(),this._creaseLines=s,this.scene?.add(s),this._requestRepaint()}clearCreases(){this._creaseLines&&(this.scene?.remove(this._creaseLines),this._creaseLines.geometry.dispose(),this._creaseLines.material?.dispose?.(),this._creaseLines=null,this._requestRepaint())}_syncEdgeStyle(){let e=this.style,t=this.uniforms.uEdgeFade?.value??1,n=Math.min(1,Math.max(0,e.edgeOpacity??.6))*Math.min(1,Math.max(.05,e.opacity??1))*t,r=this.edgeMaterial.uniforms;if(r.uColor.value.set(e.edgeColor),r.uWidth.value=Math.max(.1,e.edgeWidth??1.5),r.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.style.edgeColor),t.opacity=(this.style.edgeOpacity??.6)*Math.min(1,Math.max(.05,this.style.opacity??1))*(this.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._nativeEdgeLines)e.parent&&this._styleEdgeLine(e)}_datasetEdgesEnabled(e){let t=e.options?.enableEdges;return t===!0||t!==!1&&this._edgesEnabled}_shouldSkipAutoEdges(t,n){let r=`${t.skeletonName??``} ${n}`.toLowerCase();return e._EDGE_SKIP_KEYWORDS.some(e=>r.includes(e))}_ensureEdges(e){let t=e.userData;if(t.edges||t.nativeEdges||!e.geometry||this._shouldSkipAutoEdges(t,``))return;let n=e.geometry.getAttribute(`position`);if((e.geometry.index?.count??(n?n.count:0))>12e4)return;let r=Jx(e.geometry,.005),i=this.style.edgeThreshold??55,a=new Qd(r,i);r.dispose();let o=a.getAttribute(`position`),s=o?o.array:null;if(a.dispose(),!s||s.length<6)return;let c=.005,l=Hx(e.geometry,c),u;if(l){let e=s.length/6;u=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;u[t]=l.get(Ux(s[e],s[e+1],s[e+2],1/c))??-1}}let d=new dc(Vx(s,u),this._createEdgeMaterial(e));d.renderOrder=2,d.frustumCulled=!1,d.raycast=()=>{},d.userData.isThickEdge=!0,t.edges=d,e.add(d)}_createEdgeMaterial(e){let t=aS(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return Bx(this.lineShared,{},this._edgeStyleUniforms,n)}_createSelectionEdgeMaterial(e){let t=aS(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return Bx(this.lineShared,{},this._selEdgeStyleUniforms,n)}_removeEdges(e){let t=e.userData,n=t.edges;if(!n)return;e.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(e=>e?.dispose?.()):r?.dispose?.(),t.edges=null}getRayAt(e,t){if(!this.camera||!this.canvas)return null;let n=this.canvas,r=n.clientWidth||n.width,i=n.clientHeight||n.height;if(!r||!i)return null;let a=e/r*2-1,o=-(t/i)*2+1,s=new H(a,o,-1).unproject(this.camera),c=new H(a,o,1).unproject(this.camera).clone().sub(s).normalize();return new Bo(s,c)}_intersectMeshAtRay(e,t,n){let r=new gm;r.ray.copy(t);let i=r.intersectObject(e,!1);if(!i.length)return null;if(n!=null){let e=i.find(e=>e.instanceId===n);return e?e.point:i[0].point}return i[0].point}_buildPickResult(e,t,n,r){let i=t.mesh.userData,a=null,o=e.batchId,s=e.instanceIndex,c=i.geoRef,l=[];if(s!=null){let e=this._instanceFeature(t.mesh,c,s);if(!e)return null;a=e.smid,o=e.batchId}else{c=i.geoByBatchId?.get(e.batchId)??i.geoRef;let t=e_(c,e.batchId);a=t.smid,l=t.segments}if(this._isFeatureHidden(a,o))return null;let u=null,d=0;if(s!=null)u=this._instanceBox(t.mesh,s),d=t.mesh.geometry.index?Math.round(t.mesh.geometry.index.count/3):0;else if(a!=null&&this._smidMeshes.has(a)){let e=this._smidMeshes.get(a),t=1/0,n=1/0,r=1/0,i=-1/0,o=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,f=u?.[a]??u?.[String(a)],p=f?Qg(f):-1,m=f?.segments??(p>=0?e_(e.geoRef,p).segments:[]),h=t_(l.geometry,m);h&&(h.minX<t&&(t=h.minX),h.minY<n&&(n=h.minY),h.minZ<r&&(r=h.minZ),h.maxX>i&&(i=h.maxX),h.maxY>o&&(o=h.maxY),h.maxZ>s&&(s=h.maxZ),c+=h.count,d+=h.triangles)}c>0&&(u={minX:t,minY:n,minZ:r,maxX:i,maxY:o,maxZ:s,count:c,triangles:d})}if(!u&&(u=t_(t.mesh.geometry,l),!u&&t.mesh.geometry)){t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let e=t.mesh.geometry.boundingBox;e&&(u={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}let f=t.mesh.geometry,p=d>0?d:f.index?Math.round(f.index.count/3):0,m=n_({smid:a,box:u,triangles:p,floorHeight:this.style.floorHeight}),h=null;if(u&&this.sceneAnchor){let e=new H((u.minX+u.maxX)/2,(u.minY+u.maxY)/2,(u.minZ+u.maxZ)/2);e.applyMatrix4(t.mesh.matrixWorld);let n=this.sceneAnchor.meterInMercator;h=this._lngLatFromWorld(e.x*n+this.sceneAnchor.x,-e.y*n+this.sceneAnchor.y)}let g=n??null;!g&&r&&(g=this._intersectMeshAtRay(t.mesh,r,s));let _=null,v=null,y=null;if(g&&this.sceneAnchor){let e=a==null?{}:this._featureStyleManager.getFeatureEffectiveOffset(a),t=e.translation,n=e.elevation,r=g.clone();if(e.rotation){let t=Xx(e.rotation);if(t){let n=new V().set(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]),i=e.pivot?new H(e.pivot[0],e.pivot[1],e.pivot[2]):new H(0,0,0);r.sub(i).applyMatrix3(n).add(i)}}t?r.add(new H(t[0],t[1],t[2])):n&&(r.z+=n),_=[r.x,r.y,r.z];let i=this.sceneAnchor.meterInMercator;v=this._lngLatFromWorld(r.x*i+this.sceneAnchor.x,-r.y*i+this.sceneAnchor.y),y=r.z+(this.sceneAnchor.altitude??0)}else h&&u&&this.sceneAnchor&&(v=h,y=(u.minZ+u.maxZ)/2+(this.sceneAnchor.altitude??0));return{datasetId:t.datasetId,datasetName:this.datasets.get(t.datasetId)?.name??t.datasetId,objectId:e.objectId,batchId:o,instanceIndex:s,skeletonName:t.skeletonName,centerLngLat:h,point:_,lngLat:v,altitude:y,...m,mesh:t.mesh}}pick(e,t){if(!this.picker||!this.scene||!this.camera||!this.sceneAnchor)return null;let n=this.picker.pick(this.scene,this.camera,e,t);if(!n)return null;let r=this._pickables.get(n.objectId);if(!r)return null;let i=this.getRayAt(e,t);return this._buildPickResult(n,r,void 0,i??void 0)}pickPosition(e,t){if(!this.camera||!this.sceneAnchor)return null;let n=this.pick(e,t);if(n?.point&&n?.lngLat&&n.altitude!=null)return{lngLat:n.lngLat,altitude:n.altitude,point:n.point};let r=this.getRayAt(e,t);if(!r)return null;let i=new Ac(new H(0,0,1),0),a=new H,o=r.intersectPlane(i,a);if(o){let e=this.sceneAnchor.meterInMercator;return{lngLat:this._lngLatFromWorld(o.x*e+this.sceneAnchor.x,-o.y*e+this.sceneAnchor.y),altitude:o.z+(this.sceneAnchor.altitude??0),point:[o.x,o.y,o.z]}}return null}drillPick(e,t,n=10){if(!this.sceneAnchor||!this.camera)return[];let r=this.getRayAt(e,t);if(!r)return[];let i=new gm;i.ray.copy(r);let a=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),o=i.intersectObjects(a,!1);if(!o.length)return[];let s=[],c=new Set,l=new Set;for(let e of o){if(s.length>=n)break;let t=e.object,r=t.userData;if(r.pickId==null)continue;let i=this._pickables.get(r.pickId);if(!i)continue;let a=null,o=-1,u=e.instanceId;if(u!=null){let e=this._instanceFeature(t,r.geoRef,u);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let n=t.geometry.attributes.aBatchId;if(n){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(n.getX(i)),a=e_(r.geoByBatchId?.get(o)??r.geoRef,o).smid}}if(a!=null){if(c.has(a))continue;c.add(a)}else{let e=`${r.pickId}:${o}:${u??-1}`;if(l.has(e))continue;l.add(e)}if(this._isFeatureHidden(a,o))continue;let d={objectId:r.pickId,batchId:o,instanceIndex:u},f=this._buildPickResult(d,i,e.point);f&&s.push(f)}return s}getFeatureBounds(e){if(!this.sceneAnchor)return null;let t=1/0,n=-1/0,r=1/0,i=-1/0,a=!1;for(let o of this._pickables.values()){let s=o.mesh,c=s.userData,l=c.geoRef,u=l?.pickInfo;if(!u)continue;let d=null;if(s.isInstancedMesh){let t=c.instanceLookup;t||(t=$g(u),c.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){d=this._instanceBox(s,n);break}}else{let t=u,n=t[e]??t[String(e)];if(n){let e=e_(l,Qg(n));if(d=t_(s.geometry,e.segments),!d&&s.geometry){s.geometry.boundingBox||s.geometry.computeBoundingBox();let e=s.geometry.boundingBox;e&&(d={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}}}if(d){a=!0;let o=[new H(d.minX,d.minY,d.minZ),new H(d.maxX,d.minY,d.minZ),new H(d.minX,d.maxY,d.minZ),new H(d.maxX,d.maxY,d.minZ),new H(d.minX,d.minY,d.maxZ),new H(d.maxX,d.minY,d.maxZ),new H(d.minX,d.maxY,d.maxZ),new H(d.maxX,d.maxY,d.maxZ)],c=e==null?{}:this._featureStyleManager.getFeatureEffectiveOffset(e),l=c.translation,u=c.elevation,f=c.rotation?Xx(c.rotation):null,p=null,m=null;f&&(p=new V().set(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]),m=c.pivot?new H(c.pivot[0],c.pivot[1],c.pivot[2]):new H(0,0,0));for(let e of o){p&&m&&e.sub(m).applyMatrix3(p).add(m),l?e.add(new H(l[0],l[1],l[2])):u&&(e.z+=u),e.applyMatrix4(s.matrixWorld);let a=this.sceneAnchor.meterInMercator,[o,c]=this._lngLatFromWorld(e.x*a+this.sceneAnchor.x,-e.y*a+this.sceneAnchor.y);o<t&&(t=o),o>n&&(n=o),c<r&&(r=c),c>i&&(i=c)}}}return a?[[t,r],[n,i]]:null}_instanceFeature(e,t,n){let r=e.userData;return r.instanceLookup||(r.instanceLookup=$g(t?.pickInfo)),r.instanceLookup.get(n)??null}_instanceBox(e,t){let n=e;if(!n.isInstancedMesh)return null;let r=e.geometry;r.boundingBox||r.computeBoundingBox();let i=r.boundingBox;if(!i)return null;let a=new U;n.getMatrixAt(t,a);let o=i.clone().applyMatrix4(a);return{minX:o.min.x,minY:o.min.y,minZ:o.min.z,maxX:o.max.x,maxY:o.max.y,maxZ:o.max.z,count:r.getAttribute(`position`)?.count??0,triangles:r.index?Math.round(r.index.count/3):0}}select(e,{silent:t=!1}={}){if(this._selection){for(let e of this._selectedMeshes){if(oS(e)){this._applyPointCloudStyle(e,!1);continue}let t=aS(e);t&&(t.userData.uSelBatch.value=-1,t.userData.uSelWhole.value=0)}this._selectedMeshes=[],this._clearSelectionDecoration(),this._selection=null}if(!e){this.uniforms.uSelMix.value=0,this.uniforms.uDim.value=0,this.outlineMaterial.uniforms.uSelBatch.value=-1,this.outlineMaterial.uniforms.uSelWhole.value=0,this.outlineMaterial.uniforms.uElevation.value=0,this._requestRepaint(),t||this.onPick(null);return}this._selection=e;let n=new Set;if(e.smid!=null){let t=this._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?Qg(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)oS(e)&&this._applyPointCloudStyle(e,!0);if(this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers,this.style.outline){let t=[...n].filter(e=>!oS(e));t.length&&((this.style.outlineStyle??`edges`)===`edges`?this._addSelectionEdges(e,t):this._addSelectionHull(e,t))}this._requestRepaint()}_addSelectionEdges(e,t){this._syncSelectionStyle();for(let n of t){let t=n.userData,r=t.geoRef,i=[],a=-1;if(n===e.mesh&&e.instanceIndex!=null){i=[{vertexOffset:0,vertexCount:n.geometry.getAttribute(`position`)?.count??0}];let t=r?.pickInfo,o=t?.[e.smid??``]??t?.[String(e.smid)];a=o?Qg(o):-1}else if(e.smid!=null){let t=r?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],o=n?Qg(n):-1;a=o,i=n?.segments??(o>=0?e_(r,o).segments:[])}else n===e.mesh&&(i=e_(t.geoByBatchId?.get(e.batchId)??r,e.batchId).segments,a=e.batchId);let o=Kx(n.geometry,i);if(o&&o.length>0){let t=a>=0?new Float32Array(o.length/6).fill(a):void 0,r=new dc(Vx(o,t),this._createSelectionEdgeMaterial(n));r.renderOrder=4,r.frustumCulled=!1,r.raycast=()=>{},r.userData.isSelectionEdge=!0,n===e.mesh&&e.instanceIndex!=null&&this._applyInstanceTransform(r,e),n.add(r),this._selectionEdgeMeshes.push(r)}}this._selectionEdgeMeshes.length===0?this._addSelectionHull(e,t):this._selectionEdges=this._selectionEdgeMeshes[0]??null}_applyInstanceTransform(e,t){let n=t.mesh;if(t.instanceIndex==null||!n.isInstancedMesh)return;let r=new U;n.getMatrixAt(t.instanceIndex,r),r.decompose(e.position,e.quaternion,e.scale)}_addSelectionHull(e,t){let n=e.instanceIndex!=null;this.outlineMaterial.uniforms.uSelBatch.value=n?-1:e.batchId,this.outlineMaterial.uniforms.uSelWhole.value=n||e.batchId<0?1:0,this.outlineMaterial.uniforms.uElevation.value=n?this._selectionElevation(e):this.style.selectElevation??0;for(let n of t){let t=aS(n);t?.userData?.uBatchTex&&(this.outlineMaterial.uniforms.uBatchTex.value=t.userData.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=t.userData.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=t.userData.uBatchTexActive.value);let r=new dc(n.geometry,this.outlineMaterial);r.renderOrder=3,r.frustumCulled=!1,r.raycast=()=>{},n===e.mesh&&e.instanceIndex!=null&&this._applyInstanceTransform(r,e),n.add(r),this._outlineMeshes.push(r)}this._outlineMesh=this._outlineMeshes[0]??null}_syncSelectionStyle(){let e=this.style,t=this.selectionEdgeMaterial.uniforms;t.uColor.value.set(e.outlineColor??e.selectColor),t.uWidth.value=Math.max(.1,e.outlineWidthPx??3),t.uOpacity.value=Math.min(1,Math.max(.05,e.opacity??1)),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.outlineMaterial.uniforms.uBatchTex.value=n.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=n.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=n.uBatchTexActive.value)}}_selectionElevation(e){let t=this.style.selectElevation??0;if(e.smid!=null){let n=this._featureStyleManager.getFeatureEffectiveOffset(e.smid);n.elevation&&(t+=n.elevation)}return t}_clearSelectionDecoration(){for(let e of this._outlineMeshes)e.parent?.remove(e);this._outlineMeshes=[],this._outlineMesh=null;for(let e of this._selectionEdgeMeshes)e.parent?.remove(e),e.geometry.dispose();this._selectionEdgeMeshes=[],this._selectionEdges=null}_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}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()}}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;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=new U().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;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,e.canvasHeight)&&(s=!0)}this.style.mode===Ly.DYNAMIC&&(this.uniforms.uTime.value+=.016*(this.style.speed??1)),this.gpuPathManager.updateUniforms(this.uniforms);let c=(this.uniforms.uPathTexActive?.value??0)>0;c&&!this._customPathTime&&this.uniforms.uPathTime&&(this.uniforms.uPathTime.value+=.016),this._updateLights(),this._updateLineResolution(r),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),this.renderer.render(this.scene,this.camera),this._frame++;let l=performance.now();return l-this._fps.last>500&&(this._fps.value=Math.round(this._frame*1e3/(l-this._fps.last)),this._frame=0,this._fps.last=l),n||this.style.mode===Ly.DYNAMIC||c||this.stats.loading>0||s}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};for(let t of this.datasets.values()){let n=t.tileset?.stats;n&&(e.tiles+=n.tiles,e.loading+=n.loading,e.failed+=n.failed,e.meshes+=n.meshes,e.vertices+=n.vertices,e.triangles+=n.triangles)}return e}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of this.datasets.values()){let a=Vb(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()}};X(uS,`_EDGE_SKIP_KEYWORDS`,[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`]),Pb(),rh();var dS=1e-4;function fS(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])>dS*r)return!1}return!0}function pS(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 mS(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function hS(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function gS(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 _S(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 vS(e,t){let n=e.projectionMatrix;if(!n||n.length<16)return null;let r=new U().fromArray(Array.from(n)),i=new U().fromArray(Array.from(e.mvp));if(r.determinant()===0||!mS(r,t.fov))return null;let a=r.clone().invert().multiply(i);if(!fS(r.clone().multiply(a),Array.from(e.mvp))||!pS(a)||!mS(r,t.fov))return null;let{distance:o,fov:s,aspect:c}=t;if(!(o>0)||!(s>0)||!(c>0))return null;let l=o*Math.tan(s/2),u=l*c,d=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,f=e.farZ!=null&&e.farZ>d?e.farZ:o*4+1e3;f>d||(f=d+1e3);let p=new zc(-u,u,l,-l,d,f);return p.updateProjectionMatrix(),{matrix:p.projectionMatrix.clone().multiply(a),view:a}}function yS(e,t,n){let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new U().fromArray(Array.from(r)),a=new U().fromArray(Array.from(e.mvp));if(i.determinant()===0||!mS(i,t.fov))return null;let o=i.clone().invert().multiply(a);if(!fS(i.clone().multiply(o),Array.from(e.mvp))||!pS(o))return null;let s=Math.max(0,Math.min(1,n));if(s<=0)return{matrix:a,view:o};let{distance:c,fov:l,aspect:u}=t;if(!(c>0)||!(l>0)||!(u>0))return null;let d=c*Math.tan(l/2),f=d*u,p=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,m=e.farZ!=null&&e.farZ>p?e.farZ:c*4+1e3;m>p||(m=p+1e3);let h=new zc(-f,f,d,-d,p,m);if(h.updateProjectionMatrix(),s>=1)return{matrix:h.projectionMatrix.clone().multiply(o),view:o};let g=new U,_=i.elements,v=h.projectionMatrix.elements,y=g.elements;for(let e=0;e<16;e++)y[e]=(1-s)*_[e]+s*v[e];return{matrix:g.multiply(o),view:o}}var bS=i({Animator:()=>Ix,AttributeQuery:()=>u_,BinaryReader:()=>dh,DEFAULT_FLOOR_HEIGHT:()=>i_,DEFAULT_STYLE:()=>Vy,DatasetManager:()=>Yx,EARTH_RADIUS:()=>d_,EASING_NAMES:()=>hx,FeatureStyleManager:()=>nS,GPUPathManager:()=>My,GroundManager:()=>rS,Path:()=>ky,Picker:()=>ix,PixelFormat:()=>rv,S3MFormatError:()=>Xg,S3MTileset:()=>Wb,S3MViewer:()=>uS,S3M_VERSION:()=>vg,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>zy,SELECT_MODE_LABELS:()=>By,STYLE:()=>Ly,STYLE_LABELS:()=>Ry,TextureCompress:()=>iv,VertexTag:()=>yg,VertexTagV3:()=>bg,buildAttributes:()=>n_,buildBlendedMVP:()=>yS,buildFeatureEdgeSegments:()=>Kx,buildOrthoMVP:()=>vS,buildThickLineGeometry:()=>Vx,buildTileObjects:()=>jb,createLineSharedUniforms:()=>Lx,createOutlineMaterial:()=>Iy,createSharedUniforms:()=>Py,createStyledMaterial:()=>Fy,createTexture:()=>wy,createThickLineMaterial:()=>Bx,cubicBezier:()=>Ex,default:()=>uS,dxtPixelFormatOf:()=>nv,easing:()=>gx,extractEulerAngles:()=>Zx,extractFovRadians:()=>_S,extractNearFar:()=>gS,extractProjectionMatrix:()=>hS,isS3M1Buffer:()=>ag,lngLatFromMercator:()=>p_,lngLatFromWorld:()=>h_,measureSegments:()=>t_,mercatorFromLngLat:()=>f_,parseS3M1:()=>_g,parseS3MB:()=>Zg,resolveFeature:()=>e_,resolveRotationMatrix:()=>Xx,resolveTextureKind:()=>tv,setMaxAnisotropy:()=>vy,steps:()=>Dx,worldFromLngLat:()=>m_});a_(),eb(),Ny(),Oy(),sv(),Ay(),rh(),a_(),sv(),Oy(),Ay(),Ny(),eb(),Pb();var xS=globalThis;return xS.THREE||(xS.THREE=a),xS.S3M=bS,e.Animator=Ix,e.AttributeQuery=u_,e.BinaryReader=dh,e.DEFAULT_FLOOR_HEIGHT=i_,e.DEFAULT_STYLE=Vy,e.DatasetManager=Yx,e.EARTH_RADIUS=d_,e.EASING_NAMES=hx,e.FeatureStyleManager=nS,e.GPUPathManager=My,e.GroundManager=rS,e.Path=ky,e.Picker=ix,e.PixelFormat=rv,e.S3MFormatError=Xg,e.S3MTileset=Wb,e.S3MViewer=uS,e.default=uS,e.S3M_VERSION=vg,e.SAMPLES_PER_PATH=jy,e.SELECT_MODE=zy,e.SELECT_MODE_LABELS=By,e.STYLE=Ly,e.STYLE_LABELS=Ry,e.TextureCompress=iv,e.VertexTag=yg,e.VertexTagV3=bg,e.buildAttributes=n_,e.buildBlendedMVP=yS,e.buildFeatureEdgeSegments=Kx,e.buildOrthoMVP=vS,e.buildThickLineGeometry=Vx,e.buildTileObjects=jb,e.createLineSharedUniforms=Lx,e.createOutlineMaterial=Iy,e.createSharedUniforms=Py,e.createStyledMaterial=Fy,e.createTexture=wy,e.createThickLineMaterial=Bx,e.cubicBezier=Ex,e.dxtPixelFormatOf=nv,e.easing=gx,e.extractEulerAngles=Zx,e.extractFovRadians=_S,e.extractNearFar=gS,e.extractProjectionMatrix=hS,e.isS3M1Buffer=ag,e.lngLatFromMercator=p_,e.lngLatFromWorld=h_,e.measureSegments=t_,e.mercatorFromLngLat=f_,e.parseS3M1=_g,e.parseS3MB=Zg,e.resolveFeature=e_,e.resolveRotationMatrix=Xx,e.resolveTextureKind=tv,e.setMaxAnisotropy=vy,e.steps=Dx,e.worldFromLngLat=m_,e})({});
4738
+ `}),i=new dc(e,r);i.position.set(0,0,-.02),i.renderOrder=-1e3,i.name=`s3m-ground-depth`,i.visible=!1,this.group.add(i),this._depthMesh=i,this._depthMaterial=r,this._syncUniforms()}_applyMode(){this._mesh&&(this._mesh.visible=this.mode!==`none`),this._material&&(this._material.uniforms.uMode.value=this.mode===`excavate`?2:+(this.mode===`translucent`),this._material.depthWrite=this.mode===`excavate`),this._depthMesh&&(this._depthMesh.visible=this.occlude,this._depthMaterial&&(this._depthMaterial.uniforms.uPunchPit.value=+(this.mode===`excavate`)))}update(e){e&&this.group.position.set(e.position.x,e.position.y,this.groundHeight)}setGroundHeight(e){this.groundHeight=e,this.group.position.z=e}setMode(e){this.mode=e,this._occludeExplicit||(this.occlude=e===`excavate`),this._applyMode()}setOcclude(e){this.occlude=e,this._occludeExplicit=!0,this._applyMode()}setOpacity(e){this.opacity=Math.max(0,Math.min(1,e)),this._material&&(this._material.uniforms.uOpacity.value=this.opacity)}setColors(e,t){this.color.set(e),t&&this.gridColor.set(t),this._material&&(this._material.uniforms.uColor.value=this.color,this._material.uniforms.uGridColor.value=this.gridColor)}setExcavationBounds(e){this.excavationBounds=e,this._syncUniforms()}autoFitExcavation(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=!1;for(let o of e){let e=o.tileset?.config,s=e?.rootTiles??e?.tiles;if(Array.isArray(s))for(let e of s){let s=e.boundingBox;if(!s)continue;let c=s.center??{x:0,y:0},l=s.xExtent?.x?Math.abs(s.xExtent.x):50,u=s.yExtent?.y?Math.abs(s.yExtent.y):50,d=c.x+o.offset[0]-l,f=c.x+o.offset[0]+l,p=c.y+o.offset[1]-u,m=c.y+o.offset[1]+u;d<t&&(t=d),f>r&&(r=f),p<n&&(n=p),m>i&&(i=m),a=!0}}a&&Number.isFinite(t)&&this.setExcavationBounds([t-5,n-5,r+5,i+5])}_syncUniforms(){let e=this.excavationBounds;if(this._material){let t=this._material.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}if(this._depthMaterial){let t=this._depthMaterial.uniforms;e?(t.uHasExcavation.value=1,t.uExcavationMin.value.set(e[0],e[1]),t.uExcavationMax.value.set(e[2],e[3])):t.uHasExcavation.value=0}}dispose(){this._geom?.dispose(),this._geom=null,this._material?.dispose(),this._material=null,this._depthMaterial?.dispose(),this._depthMaterial=null,this._mesh=null,this._depthMesh=null,this.group.clear()}};rh(),Oy(),eb(),Ay(),Ny(),a_(),uh();var iS=65534;function aS(e){let t=Array.isArray(e.material)?e.material[0]:e.material;return t?.userData?.isStyled?t:null}function oS(e){return e.isPoints===!0}var sS=[`opacity`,`floorHeight`,`selectOpacity`,`selectEmissive`,`selectElevation`,`dimFactor`,`texMix`,`roofThreshold`,`ambientGain`,`edgeWidth`,`edgeOpacity`,`outlineWidth`],cS=[`colorA`,`colorB`,`colorC`,`selectColor`,`edgeColor`],lS=[`translation`,`elevation`,`opacity`,`color`,`rotation`],uS=class e{get datasets(){return this._datasetManager.datasets}get sceneAnchor(){return this._datasetManager.sceneAnchor}set sceneAnchor(e){this._datasetManager.sceneAnchor=e}_requestRepaint(){this._onRequestRepaint()}triggerRepaint(){this._requestRepaint()}constructor(e={}){X(this,`options`,void 0),X(this,`pickable`,void 0),X(this,`onStats`,void 0),X(this,`onReady`,void 0),X(this,`onPick`,void 0),X(this,`onError`,void 0),X(this,`geo`,null),X(this,`canvas`,null),X(this,`renderer`,null),X(this,`scene`,null),X(this,`camera`,null),X(this,`picker`,null),X(this,`uniforms`,void 0),X(this,`style`,void 0),X(this,`_styleTarget`,void 0),X(this,`outlineMaterial`,void 0),X(this,`lineShared`,void 0),X(this,`edgeMaterial`,void 0),X(this,`selectionEdgeMaterial`,void 0),X(this,`_edgeStyleUniforms`,void 0),X(this,`_selEdgeStyleUniforms`,void 0),X(this,`groundManager`,void 0),X(this,`_datasetManager`,new Yx),X(this,`_featureStyleManager`,void 0),X(this,`gpuPathManager`,new My),X(this,`_customPathTime`,!1),X(this,`_pickables`,new Map),X(this,`_pickSeq`,0),X(this,`_freePickIds`,[]),X(this,`_smidMeshes`,new Map),X(this,`_meshHeight`,new Map),X(this,`_heightMin`,1/0),X(this,`_heightMax`,-1/0),X(this,`_boxScratch`,new ho),X(this,`_selection`,null),X(this,`_selectedMeshes`,[]),X(this,`_outlineMesh`,null),X(this,`_outlineMeshes`,[]),X(this,`_selectionEdges`,null),X(this,`_selectionEdgeMeshes`,[]),X(this,`_edgesEnabled`,!1),X(this,`_tileFadeSeq`,0),X(this,`_modeGen`,0),X(this,`_pathSpecs`,new Map),X(this,`_pathScratch`,new Float32Array(3)),X(this,`_creaseLines`,null),X(this,`_nativeEdgeLines`,new Set),X(this,`_pointClouds`,new Set),X(this,`_opacityTransparent`,!1),X(this,`animator`,new Ix),X(this,`attributeQuery`,null),X(this,`_enuMatrix`,new U),X(this,`_colorScratch`,new W),X(this,`_needsRepaint`,!0),X(this,`_frame`,0),X(this,`_fps`,{value:0,last:0}),X(this,`_ambientLight`,void 0),X(this,`_hemiLight`,void 0),X(this,`_keyLight`,void 0),X(this,`_fillLight`,void 0),X(this,`_lightOptions`,{ambientIntensity:.4,ambientColor:16777215,hemisphereIntensity:.8,hemisphereColor:16777215,hemisphereGroundColor:11976907,keyLightIntensity:1,keyLightColor:16777215,fillLightIntensity:.35,fillLightColor:16777215,mode:`headlamp`,azimuth:150,altitude:50}),X(this,`_datasetQueue`,void 0),X(this,`_onRequestRepaint`,()=>{}),X(this,`_getBearing`,void 0),X(this,`_lodRangeScale`,1),this.options=e,this.pickable=e.pickable!==!1,this._lodRangeScale=e.lodRangeScale??1,e.light&&Object.assign(this._lightOptions,e.light),e.totalMaxTiles&&(this._datasetManager.totalMaxTiles=e.totalMaxTiles),this._onRequestRepaint=e.onRequestRepaint??(()=>{}),this._getBearing=e.getBearing,this.onStats=e.onStats??(()=>{}),this.onReady=e.onReady??(()=>{}),this.onPick=e.onPick??(()=>{}),this.onError=e.onError??(e=>console.warn(`[s3m]`,e)),this.groundManager=new rS(e.ground),this.scene||(this.scene=new Wl,this.scene.add(this.groundManager.group),this._addLights()),this._featureStyleManager=new nS(()=>this.style.floorHeight,()=>this._requestRepaint(),()=>{this._selection&&this._syncSelectionStyle()},()=>this.getAllMeshes(),e=>this._applyOverridesToMesh(e),()=>this._opacityTransparent),this.uniforms=Py(),by(b_),this.style={...Vy,...e.style??{}},this._styleTarget={...this.style},this._opacityTransparent=(this.style.opacity??1)<.999,this._applyStyleUniforms(),this._registerAnimChannels(),this.animator.onActive=()=>this._requestRepaint(),this.outlineMaterial=Iy(this.uniforms),this.lineShared=Lx(),this._edgeStyleUniforms={uColor:{value:new W(this.style.edgeColor)},uWidth:{value:Math.max(.1,this.style.edgeWidth??1.5)},uOpacity:{value:.6}},this.edgeMaterial=Bx(this.lineShared,{},this._edgeStyleUniforms),this._selEdgeStyleUniforms={uColor:{value:new W(this.style.outlineColor??this.style.selectColor)},uWidth:{value:Math.max(.1,this.style.outlineWidthPx??3)},uOpacity:{value:1},uElevation:{value:this.style.selectElevation??0}},this.selectionEdgeMaterial=Bx(this.lineShared,{},this._selEdgeStyleUniforms),this.setEdges(!!this.style.edges),this._applyOpacity(),this._fps.last=performance.now(),this._datasetQueue=this._normalizeDatasets(e),e.attributes&&(this.attributeQuery=new u_(e.attributes))}_createRenderer(e,t){let n=new Vl({canvas:e,context:t,antialias:!0});return n.autoClear=!1,n.setPixelRatio(1),n.toneMapping=this.options.toneMapping===void 0?0:this.options.toneMapping,n.toneMappingExposure=this.options.toneMappingExposure??1,n}_syncTextureCapabilities(e){let t=!!e.getExtension(`WEBGL_compressed_texture_s3tc`),n=!!e.getExtension(`WEBGL_compressed_texture_s3tc_srgb`);yy(t&&n)}mount(e,t){this.canvas=e,this.renderer=this._createRenderer(e,t),vy(this.renderer.capabilities.getMaxAnisotropy()),this._syncTextureCapabilities(t),this.scene=new Wl,this.scene.add(this.groundManager.group),this._addLights(),this.camera=new _c,this.camera.matrixAutoUpdate=!1,this.picker=new ix(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),vy(this.renderer.capabilities.getMaxAnisotropy()),this._syncTextureCapabilities(e),this.picker?.dispose(),this.picker=new ix(this.renderer),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.outlineMaterial.dispose(),this.edgeMaterial.dispose(),this.selectionEdgeMaterial.dispose(),this.scene?.clear(),this._selectedMeshes=[],this._outlineMeshes=[],this._selectionEdgeMeshes=[],this._outlineMesh=null,this._selectionEdges=null,this._smidMeshes.clear(),this._meshHeight.clear(),this.animator.clear(),this.animator.unregisterPrefix(`tile.`),this.animator.unregisterPrefix(`feature.`),this._pathSpecs.clear(),this._heightMin=1/0,this._heightMax=-1/0,this.renderer?.dispose(),this.renderer=null,this.canvas=null}_createLights(){this._ambientLight=new mp(this._lightOptions.ambientColor,this._lightOptions.ambientIntensity),this._hemiLight=new ep(this._lightOptions.hemisphereColor,this._lightOptions.hemisphereGroundColor,this._lightOptions.hemisphereIntensity),this._keyLight=new pp(this._lightOptions.keyLightColor,this._lightOptions.keyLightIntensity),this._fillLight=new pp(this._lightOptions.fillLightColor,this._lightOptions.fillLightIntensity),this._updateLights()}_addLights(){this.scene&&(this._ambientLight||this._createLights(),this.scene.add(this._ambientLight,this._hemiLight,this._keyLight,this._fillLight))}_applyLightOptions(){this._ambientLight&&(this._ambientLight.intensity=this._lightOptions.ambientIntensity,this._ambientLight.color.set(this._lightOptions.ambientColor)),this._hemiLight&&(this._hemiLight.intensity=this._lightOptions.hemisphereIntensity,this._hemiLight.color.set(this._lightOptions.hemisphereColor),this._hemiLight.groundColor.set(this._lightOptions.hemisphereGroundColor)),this._keyLight&&(this._keyLight.intensity=this._lightOptions.keyLightIntensity,this._keyLight.color.set(this._lightOptions.keyLightColor)),this._fillLight&&(this._fillLight.intensity=this._lightOptions.fillLightIntensity,this._fillLight.color.set(this._lightOptions.fillLightColor))}setLight(e){let t={...e};t.mainColor!==void 0&&t.keyLightColor===void 0&&(t.keyLightColor=t.mainColor),t.mainIntensity!==void 0&&t.keyLightIntensity===void 0&&(t.keyLightIntensity=t.mainIntensity),Object.assign(this._lightOptions,t),this._applyLightOptions(),this._updateLights(),this._needsRepaint=!0,this.triggerRepaint()}getLight(){return{...this._lightOptions}}setToneMapping(e,t=1){this.options.toneMapping=e,this.options.toneMappingExposure=t,this.renderer&&(this.renderer.toneMapping=e,this.renderer.toneMappingExposure=t,this._needsRepaint=!0,this.triggerRepaint())}getToneMapping(){return{toneMapping:this.renderer?this.renderer.toneMapping:this.options.toneMapping??0,toneMappingExposure:this.renderer?this.renderer.toneMappingExposure:this.options.toneMappingExposure??1}}_updateLights(){if(!this._keyLight||!this._fillLight)return;let e=this._lightOptions.mode===`fixed`?0:(this._getBearing?.()??0)*Math.PI/180,t=(t,n,r)=>{if(!t)return;let i=e+n*Math.PI/180,a=r*Math.PI/180,o=Math.cos(a);t.position.set(Math.sin(i)*o,Math.cos(i)*o,Math.sin(a)).multiplyScalar(1e3)};t(this._keyLight,this._lightOptions.azimuth,this._lightOptions.altitude),t(this._fillLight,this._lightOptions.azimuth+65,Math.max(10,this._lightOptions.altitude-20))}_normalizeDatasets(e){return Array.isArray(e.datasets)?e.datasets.filter(e=>!!e?.configUrl):e.configUrl?[{id:`default`,name:`默认数据集`,configUrl:e.configUrl,useWorker:e.useWorker}]:[]}async addDataset(e){if(!this.scene)throw Error(`[s3m] 图层尚未 addLayer,不能添加数据集`);return await this._datasetManager.addDataset(e,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._needsRepaint=!0,this._requestRepaint()},onTileRemoved:(e,t)=>{this._unregisterTile(e,t),this.onStats(this.stats),this._needsRepaint=!0,this._requestRepaint()},onStats:()=>{this.onStats(this.stats),this._requestRepaint()},onError:e=>{this.onError(e),this.onStats(this.stats)},onReady:e=>{this.onReady(e),this._refreshAllHeights(),this.groundManager.excavationBounds||this.groundManager.autoFitExcavation(this.datasets.values())},triggerRepaint:()=>{this._requestRepaint()}})}_lngLatFromWorld(e,t){return h_(this.geo,e,t)}recomputeAnchors(){this._datasetManager.recomputeAnchors(this.geo),this._refreshAllHeights(),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._refreshAllHeights(),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._refreshAllHeights(),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=Zx(t),o=this._ensureFeatureChannel(e,`rotation`);this.animator.to(o,a,r)}rotateFeatureBy(e,t,n,r){let i=Zx(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 ky?t:new ky(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)}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=Zx(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=Zx(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 lS)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 u_(e):null}getLoadedSmids(){return[...this._smidMeshes.keys()]}auditBatches(){let e=this._featureStyleManager.auditBatches(this._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._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}_markOverridesDirty(e=`all`){e===`all`?this._featureStyleManager.markOverridesDirty(void 0,this.getAllMeshes()):this._featureStyleManager.markOverridesDirty(e)}flushOverrides(){this._featureStyleManager.flushOverrides()}_applyOverridesToMesh(e){this._featureStyleManager.applyOverridesToMesh(e)}removeDataset(e){if(this.datasets.get(e)){this._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._pickables.delete(n.pickId),this._releasePickId(n.pickId),n.pickId=void 0),this._unindexMeshSmids(t),this._removeMeshHeight(t),t.geometry?.dispose?.();let r=aS(t);r&&r.dispose(),Qb(t.material)&&t.material.dispose(),this._featureStyleManager.disposeMesh(t)})});for(let[t,n]of this._pickables)n.datasetId===e&&this._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._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;for(let r of e.group.children){if(r.isLineSegments&&r.userData.isEdgeLines){r.visible=this._edgesEnabled,this._nativeEdgeLines.add(r),this._styleEdgeLine(r);continue}let i=oS(r),a=r;if(!a.isMesh&&!i)continue;i&&this._pointClouds.add(r);let o=a.userData;if(o.pickId=this._allocPickId(),o.datasetId=t.id,o.nativeEdges=n,this._pickables.set(o.pickId,{datasetId:t.id,mesh:a,tile:e.tile,skeletonName:o.skeletonName??``}),this._indexMeshSmids(a),this._addMeshHeight(a),!n&&!i&&this._datasetEdgesEnabled(t)&&!this._shouldSkipAutoEdges(o,t.name)&&this._ensureEdges(a),i)this._applyPointCloudStyle(r);else{let e=aS(a);if(e){e.transparent=Math.min(1,Math.max(.05,this.style.opacity??1))<.999;let t=this.style.depthWrite!==!1;e.depthWrite=e.transparent?t:this.style.depthWrite!==!1,e.flatShading=this.style.shading!==`smooth`,e.needsUpdate=!0,this._featureStyleManager.applyOverridesToMesh(a),this._startTileFade(a,e)}}this._replaySelectionOnto(a)}}_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),this._featureStyleManager.applyOverridesToMesh(e),t.depthWrite=this.style.depthWrite!==!1,this._requestRepaint()}})}_isMeshCoveringSelection(e,t){if(!t.point)return!1;let n=e.geometry;if(!n||(n.boundingBox||n.computeBoundingBox(),!n.boundingBox))return!1;let r=new H(t.point[0],t.point[1],t.point[2]);e.updateWorldMatrix(!0,!1);let i=e.matrixWorld.clone().invert(),a=r.applyMatrix4(i);return n.boundingBox.clone().expandByScalar(.5).containsPoint(a)}_replaySelectionOnto(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?Qg(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),oS(e)&&this._applyPointCloudStyle(e,!0),this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers}_unregisterTile(e,t){e.group.traverse(e=>{let t=e;if(e.isLineSegments&&t.userData?.isEdgeLines&&this._nativeEdgeLines.delete(e),oS(e)&&this._pointClouds.delete(e),t.userData?.tileFadeKey&&(this.animator.unregister(t.userData.tileFadeKey),t.userData.tileFadeKey=void 0),t.userData?.pickId!=null&&(this._pickables.delete(t.userData.pickId),this._releasePickId(t.userData.pickId),t.userData.pickId=void 0),t.isMesh){this._selectedMeshes.includes(t)&&(this._selectedMeshes=this._selectedMeshes.filter(e=>e!==t));let e=this._selection;if(e&&e.mesh===t){let n=e.smid,r=n==null?this._selectedMeshes.find(e=>e!==t&&e.parent&&e.parent.visible)??this._selectedMeshes.find(e=>e!==t&&e.parent):[...this._smidMeshes.get(n)??[]].find(e=>e!==t&&e.parent);r?(this._selection={...e,mesh:r},this._replaySelectionOnto(r)):this.select(null)}this._unindexMeshSmids(t),this._removeMeshHeight(t),this._featureStyleManager.disposeMesh(t),aS(t)?.dispose?.()}Qb(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)}_allocPickId(){let e=this._freePickIds.pop();if(e!==void 0)return e;if(this._pickSeq>iS){for(let e=0;e<=iS;e++)if(!this._pickables.has(e))return e;throw Error(`[s3m] 可拾取网格超过 65535 个,2 字节 ID 编码不够用`)}return this._pickSeq++}_releasePickId(e){this._freePickIds.push(e)}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:Ry[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 cS.includes(e)?3:1}_registerAnimChannels(){for(let e of sS)this.animator.register(`style.${e}`,{dim:1,read:t=>{t[0]=Number(this.style[e]??0)},write:t=>{this.style[e]=t[0],this._onStyleChannelWrote(e)}});for(let e of cS)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._syncEdgeStyle()}}),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`)&&this._refreshEdgeLines())}_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&&this._edgesEnabled?(this._disposeEdges(),this.setEdges(!0)):(`edgeColor`in e||`edgeWidth`in e||`opacity`in e||`edgeOpacity`in e)&&this._refreshEdgeLines(),this._selection&&(`outline`in e||`outlineStyle`in e?this.select(this._selection,{silent:!0}):this._syncSelectionStyle())}_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??zy.OVERLAY;e.uSelMode&&(e.uSelMode.value=n===zy.REPLACE?0:n===zy.MULTIPLY?2:n===zy.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.uOpacity&&t.opacity!=null&&(e.uOpacity.value=Math.min(1,Math.max(.05,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=Math.min(1,Math.max(.05,this.style.opacity??1));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._pickables.values()){if(oS(n.mesh))continue;let r=aS(n.mesh);r&&(r.userData.uBatchTexActive?.value||(r.userData.uTileFade?.value??1)<1||(r.transparent=t,r.depthWrite=!t||e))}}for(let e of this._pointClouds)this._applyPointCloudStyle(e);this._syncEdgeStyle(),this._requestRepaint()}_applyPointCloudStyle(e,t=this._selectedMeshes.includes(e)){Zb(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`;for(let t of this._pickables.values()){let n=aS(t.mesh);n&&n.flatShading!==e&&(n.flatShading=e,n.needsUpdate=!0)}this._requestRepaint()}_addMeshHeight(e){let t=e.geometry?.boundingBox;if(!t)return;this._boxScratch.copy(t).applyMatrix4(e.matrixWorld);let n=this._boxScratch.min.z,r=this._boxScratch.max.z;Number.isFinite(n)&&Number.isFinite(r)&&(this._meshHeight.set(e,{min:n,max:r}),n<this._heightMin&&(this._heightMin=n),r>this._heightMax&&(this._heightMax=r),this._pushHeightRange())}_removeMeshHeight(e){let t=this._meshHeight.get(e);t&&(this._meshHeight.delete(e),t.min===this._heightMin||t.max===this._heightMax?this._recomputeHeightRange():this._pushHeightRange())}_refreshAllHeights(){if(this._meshHeight.size===0)return;let e=[...this._meshHeight.keys()];this._meshHeight.clear(),this._heightMin=1/0,this._heightMax=-1/0;for(let t of e)this._addMeshHeight(t);this._pushHeightRange()}_recomputeHeightRange(){let e=1/0,t=-1/0;for(let n of this._meshHeight.values())n.min<e&&(e=n.min),n.max>t&&(t=n.max);this._heightMin=e,this._heightMax=t,this._pushHeightRange()}_pushHeightRange(){let e=this._heightMin,t=this._heightMax;(!Number.isFinite(e)||!Number.isFinite(t)||t<=e)&&(e=0,t=100),this.uniforms.uHeightMin.value=e,this.uniforms.uHeightMax.value=t}_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))}}setEdges(e,t){let n=!!t&&((t.duration??0)>0||!!t.spring);this._edgesEnabled=e,this.style.edges=e,this._styleTarget.edges=e;for(let t of this.datasets.values())t.root.traverse(t=>{t.userData.isEdgeLines&&(t.visible=e,this._styleEdgeLine(t))});if(this._syncEdgeStyle(),!e){n?this.animator.to(`style.edgeFade`,0,{...t,onComplete:()=>{this._disposeEdges(),this._requestRepaint(),t?.onComplete?.()}}):(this._setEdgeFade(1),this._disposeEdges()),this._requestRepaint();return}let r=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e.userData;return!t.edges&&!t.nativeEdges&&!oS(e)}),i=0,a=()=>{let e=performance.now();for(;i<r.length&&performance.now()-e<8;)this._ensureEdges(r[i++]);i<r.length?setTimeout(a,0):this._requestRepaint()};a(),n?(this._setEdgeFade(0),this.animator.to(`style.edgeFade`,1,t)):this._setEdgeFade(1)}_setEdgeFade(e){this.uniforms.uEdgeFade&&(this.uniforms.uEdgeFade.value=e),this._syncEdgeStyle()}_disposeEdges(){for(let e of this._pickables.values())this._removeEdges(e.mesh)}async loadCreases(e){let t=await fetch(e);if(!t.ok)throw Error(`[s3m] 棱线缓存加载失败: ${t.status} ${e}`);let n=await t.arrayBuffer(),r=new Float32Array(n);if(r.length<6)return;let i=new q;i.setAttribute(`position`,new G(r,3));let a=this.style,o=new Qu({color:new W(a.edgeColor),transparent:!0,opacity:Math.min(1,Math.max(0,a.edgeOpacity??.6))*Math.min(1,Math.max(.05,a.opacity??1)),depthWrite:!1}),s=new ld(i,o);s.renderOrder=2,s.frustumCulled=!1,s.raycast=()=>{},this.clearCreases(),this._creaseLines=s,this.scene?.add(s),this._requestRepaint()}clearCreases(){this._creaseLines&&(this.scene?.remove(this._creaseLines),this._creaseLines.geometry.dispose(),this._creaseLines.material?.dispose?.(),this._creaseLines=null,this._requestRepaint())}_syncEdgeStyle(){let e=this.style,t=this.uniforms.uEdgeFade?.value??1,n=Math.min(1,Math.max(0,e.edgeOpacity??.6))*Math.min(1,Math.max(.05,e.opacity??1))*t,r=this.edgeMaterial.uniforms;if(r.uColor.value.set(e.edgeColor),r.uWidth.value=Math.max(.1,e.edgeWidth??1.5),r.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.style.edgeColor),t.opacity=(this.style.edgeOpacity??.6)*Math.min(1,Math.max(.05,this.style.opacity??1))*(this.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._nativeEdgeLines)e.parent&&this._styleEdgeLine(e)}_datasetEdgesEnabled(e){let t=e.options?.enableEdges;return t===!0||t!==!1&&this._edgesEnabled}_shouldSkipAutoEdges(t,n){let r=`${t.skeletonName??``} ${n}`.toLowerCase();return e._EDGE_SKIP_KEYWORDS.some(e=>r.includes(e))}_ensureEdges(e){let t=e.userData;if(t.edges||t.nativeEdges||!e.geometry||this._shouldSkipAutoEdges(t,``))return;let n=e.geometry.getAttribute(`position`);if((e.geometry.index?.count??(n?n.count:0))>12e4)return;let r=Jx(e.geometry,.005),i=this.style.edgeThreshold??55,a=new Qd(r,i);r.dispose();let o=a.getAttribute(`position`),s=o?o.array:null;if(a.dispose(),!s||s.length<6)return;let c=.005,l=Hx(e.geometry,c),u;if(l){let e=s.length/6;u=new Float32Array(e);for(let t=0;t<e;t++){let e=t*6;u[t]=l.get(Ux(s[e],s[e+1],s[e+2],1/c))??-1}}let d=new dc(Vx(s,u),this._createEdgeMaterial(e));d.renderOrder=2,d.frustumCulled=!1,d.raycast=()=>{},d.userData.isThickEdge=!0,t.edges=d,e.add(d)}_createEdgeMaterial(e){let t=aS(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return Bx(this.lineShared,{},this._edgeStyleUniforms,n)}_createSelectionEdgeMaterial(e){let t=aS(e),n=t?.userData?.uBatchTex?{uBatchTex:t.userData.uBatchTex,uBatchTex2:t.userData.uBatchTex2,uBatchMix:this.uniforms.uBatchMix,uBatchTexWidth:t.userData.uBatchTexWidth,uBatchTexActive:t.userData.uBatchTexActive,uPathTex:this.uniforms.uPathTex,uPathCount:this.uniforms.uPathCount,uPathTexActive:this.uniforms.uPathTexActive,uPathTime:this.uniforms.uPathTime}:void 0;return Bx(this.lineShared,{},this._selEdgeStyleUniforms,n)}_removeEdges(e){let t=e.userData,n=t.edges;if(!n)return;e.remove(n),n.geometry?.dispose();let r=n.material;Array.isArray(r)?r.forEach(e=>e?.dispose?.()):r?.dispose?.(),t.edges=null}getRayAt(e,t){if(!this.camera||!this.canvas)return null;let n=this.canvas,r=n.clientWidth||n.width,i=n.clientHeight||n.height;if(!r||!i)return null;let a=e/r*2-1,o=-(t/i)*2+1,s=new H(a,o,-1).unproject(this.camera),c=new H(a,o,1).unproject(this.camera).clone().sub(s).normalize();return new Bo(s,c)}_intersectMeshAtRay(e,t,n){let r=new gm;r.ray.copy(t);let i=r.intersectObject(e,!1);if(!i.length)return null;if(n!=null){let e=i.find(e=>e.instanceId===n);return e?e.point:i[0].point}return i[0].point}_buildPickResult(e,t,n,r){let i=t.mesh.userData,a=null,o=e.batchId,s=e.instanceIndex,c=i.geoRef,l=[];if(s!=null){let e=this._instanceFeature(t.mesh,c,s);if(!e)return null;a=e.smid,o=e.batchId}else{c=i.geoByBatchId?.get(e.batchId)??i.geoRef;let t=e_(c,e.batchId);a=t.smid,l=t.segments}if(this._isFeatureHidden(a,o))return null;let u=null,d=0;if(s!=null)u=this._instanceBox(t.mesh,s),d=t.mesh.geometry.index?Math.round(t.mesh.geometry.index.count/3):0;else if(a!=null&&this._smidMeshes.has(a)){let e=this._smidMeshes.get(a),t=1/0,n=1/0,r=1/0,i=-1/0,o=-1/0,s=-1/0,c=0;for(let l of e){let e=l.userData,u=e.geoRef?.pickInfo,f=u?.[a]??u?.[String(a)],p=f?Qg(f):-1,m=f?.segments??(p>=0?e_(e.geoRef,p).segments:[]),h=t_(l.geometry,m);h&&(h.minX<t&&(t=h.minX),h.minY<n&&(n=h.minY),h.minZ<r&&(r=h.minZ),h.maxX>i&&(i=h.maxX),h.maxY>o&&(o=h.maxY),h.maxZ>s&&(s=h.maxZ),c+=h.count,d+=h.triangles)}c>0&&(u={minX:t,minY:n,minZ:r,maxX:i,maxY:o,maxZ:s,count:c,triangles:d})}if(!u&&(u=t_(t.mesh.geometry,l),!u&&t.mesh.geometry)){t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let e=t.mesh.geometry.boundingBox;e&&(u={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}let f=t.mesh.geometry,p=d>0?d:f.index?Math.round(f.index.count/3):0,m=n_({smid:a,box:u,triangles:p,floorHeight:this.style.floorHeight}),h=null;if(u&&this.sceneAnchor){let e=new H((u.minX+u.maxX)/2,(u.minY+u.maxY)/2,(u.minZ+u.maxZ)/2);e.applyMatrix4(t.mesh.matrixWorld);let n=this.sceneAnchor.meterInMercator;h=this._lngLatFromWorld(e.x*n+this.sceneAnchor.x,-e.y*n+this.sceneAnchor.y)}let g=n??null;!g&&r&&(g=this._intersectMeshAtRay(t.mesh,r,s));let _=null,v=null,y=null;if(g&&this.sceneAnchor){let e=a==null?{}:this._featureStyleManager.getFeatureEffectiveOffset(a),t=e.translation,n=e.elevation,r=g.clone();if(e.rotation){let t=Xx(e.rotation);if(t){let n=new V().set(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]),i=e.pivot?new H(e.pivot[0],e.pivot[1],e.pivot[2]):new H(0,0,0);r.sub(i).applyMatrix3(n).add(i)}}t?r.add(new H(t[0],t[1],t[2])):n&&(r.z+=n),_=[r.x,r.y,r.z];let i=this.sceneAnchor.meterInMercator;v=this._lngLatFromWorld(r.x*i+this.sceneAnchor.x,-r.y*i+this.sceneAnchor.y),y=r.z+(this.sceneAnchor.altitude??0)}else h&&u&&this.sceneAnchor&&(v=h,y=(u.minZ+u.maxZ)/2+(this.sceneAnchor.altitude??0));return{datasetId:t.datasetId,datasetName:this.datasets.get(t.datasetId)?.name??t.datasetId,objectId:e.objectId,batchId:o,instanceIndex:s,skeletonName:t.skeletonName,centerLngLat:h,point:_,lngLat:v,altitude:y,...m,mesh:t.mesh}}pick(e,t){if(!this.picker||!this.scene||!this.camera||!this.sceneAnchor)return null;let n=this.picker.pick(this.scene,this.camera,e,t);if(!n)return null;let r=this._pickables.get(n.objectId);if(!r)return null;let i=this.getRayAt(e,t);return this._buildPickResult(n,r,void 0,i??void 0)}pickPosition(e,t){if(!this.camera||!this.sceneAnchor)return null;let n=this.pick(e,t);if(n?.point&&n?.lngLat&&n.altitude!=null)return{lngLat:n.lngLat,altitude:n.altitude,point:n.point};let r=this.getRayAt(e,t);if(!r)return null;let i=new Ac(new H(0,0,1),0),a=new H,o=r.intersectPlane(i,a);if(o){let e=this.sceneAnchor.meterInMercator;return{lngLat:this._lngLatFromWorld(o.x*e+this.sceneAnchor.x,-o.y*e+this.sceneAnchor.y),altitude:o.z+(this.sceneAnchor.altitude??0),point:[o.x,o.y,o.z]}}return null}drillPick(e,t,n=10){if(!this.sceneAnchor||!this.camera)return[];let r=this.getRayAt(e,t);if(!r)return[];let i=new gm;i.ray.copy(r);let a=[...this._pickables.values()].map(e=>e.mesh).filter(e=>{let t=e;for(;t;){if(!t.visible)return!1;t=t.parent}return!0}),o=i.intersectObjects(a,!1);if(!o.length)return[];let s=[],c=new Set,l=new Set;for(let e of o){if(s.length>=n)break;let t=e.object,r=t.userData;if(r.pickId==null)continue;let i=this._pickables.get(r.pickId);if(!i)continue;let a=null,o=-1,u=e.instanceId;if(u!=null){let e=this._instanceFeature(t,r.geoRef,u);if(!e)continue;a=e.smid,o=e.batchId}else if(e.faceIndex!=null){let n=t.geometry.attributes.aBatchId;if(n){let i=t.geometry.index?t.geometry.index.getX(e.faceIndex*3):e.faceIndex*3;o=Math.round(n.getX(i)),a=e_(r.geoByBatchId?.get(o)??r.geoRef,o).smid}}if(a!=null){if(c.has(a))continue;c.add(a)}else{let e=`${r.pickId}:${o}:${u??-1}`;if(l.has(e))continue;l.add(e)}if(this._isFeatureHidden(a,o))continue;let d={objectId:r.pickId,batchId:o,instanceIndex:u},f=this._buildPickResult(d,i,e.point);f&&s.push(f)}return s}getFeatureBounds(e){if(!this.sceneAnchor)return null;let t=1/0,n=-1/0,r=1/0,i=-1/0,a=!1;for(let o of this._pickables.values()){let s=o.mesh,c=s.userData,l=c.geoRef,u=l?.pickInfo;if(!u)continue;let d=null;if(s.isInstancedMesh){let t=c.instanceLookup;t||(t=$g(u),c.instanceLookup=t);for(let[n,r]of t)if(r.smid===e){d=this._instanceBox(s,n);break}}else{let t=u,n=t[e]??t[String(e)];if(n){let e=e_(l,Qg(n));if(d=t_(s.geometry,e.segments),!d&&s.geometry){s.geometry.boundingBox||s.geometry.computeBoundingBox();let e=s.geometry.boundingBox;e&&(d={minX:e.min.x,maxX:e.max.x,minY:e.min.y,maxY:e.max.y,minZ:e.min.z,maxZ:e.max.z,count:0,triangles:0})}}}if(d){a=!0;let o=[new H(d.minX,d.minY,d.minZ),new H(d.maxX,d.minY,d.minZ),new H(d.minX,d.maxY,d.minZ),new H(d.maxX,d.maxY,d.minZ),new H(d.minX,d.minY,d.maxZ),new H(d.maxX,d.minY,d.maxZ),new H(d.minX,d.maxY,d.maxZ),new H(d.maxX,d.maxY,d.maxZ)],c=e==null?{}:this._featureStyleManager.getFeatureEffectiveOffset(e),l=c.translation,u=c.elevation,f=c.rotation?Xx(c.rotation):null,p=null,m=null;f&&(p=new V().set(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]),m=c.pivot?new H(c.pivot[0],c.pivot[1],c.pivot[2]):new H(0,0,0));for(let e of o){p&&m&&e.sub(m).applyMatrix3(p).add(m),l?e.add(new H(l[0],l[1],l[2])):u&&(e.z+=u),e.applyMatrix4(s.matrixWorld);let a=this.sceneAnchor.meterInMercator,[o,c]=this._lngLatFromWorld(e.x*a+this.sceneAnchor.x,-e.y*a+this.sceneAnchor.y);o<t&&(t=o),o>n&&(n=o),c<r&&(r=c),c>i&&(i=c)}}}return a?[[t,r],[n,i]]:null}_instanceFeature(e,t,n){let r=e.userData;return r.instanceLookup||(r.instanceLookup=$g(t?.pickInfo)),r.instanceLookup.get(n)??null}_instanceBox(e,t){let n=e;if(!n.isInstancedMesh)return null;let r=e.geometry;r.boundingBox||r.computeBoundingBox();let i=r.boundingBox;if(!i)return null;let a=new U;n.getMatrixAt(t,a);let o=i.clone().applyMatrix4(a);return{minX:o.min.x,minY:o.min.y,minZ:o.min.z,maxX:o.max.x,maxY:o.max.y,maxZ:o.max.z,count:r.getAttribute(`position`)?.count??0,triangles:r.index?Math.round(r.index.count/3):0}}select(e,{silent:t=!1}={}){if(this._selection){for(let e of this._selectedMeshes){if(oS(e)){this._applyPointCloudStyle(e,!1);continue}let t=aS(e);t&&(t.userData.uSelBatch.value=-1,t.userData.uSelWhole.value=0)}this._selectedMeshes=[],this._clearSelectionDecoration(),this._selection=null}if(!e){this.uniforms.uSelMix.value=0,this.uniforms.uDim.value=0,this.outlineMaterial.uniforms.uSelBatch.value=-1,this.outlineMaterial.uniforms.uSelWhole.value=0,this.outlineMaterial.uniforms.uElevation.value=0,this._requestRepaint(),t||this.onPick(null);return}this._selection=e;let n=new Set;if(e.smid!=null){let t=this._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?Qg(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)oS(e)&&this._applyPointCloudStyle(e,!0);if(this.uniforms.uSelMix.value=1,this.uniforms.uDim.value=+!!this.style.dimOthers,this.style.outline){let t=[...n].filter(e=>!oS(e));t.length&&((this.style.outlineStyle??`edges`)===`edges`?this._addSelectionEdges(e,t):this._addSelectionHull(e,t))}this._requestRepaint()}_addSelectionEdges(e,t){this._syncSelectionStyle();for(let n of t){let t=n.userData,r=t.geoRef,i=[],a=-1;if(n===e.mesh&&e.instanceIndex!=null){i=[{vertexOffset:0,vertexCount:n.geometry.getAttribute(`position`)?.count??0}];let t=r?.pickInfo,o=t?.[e.smid??``]??t?.[String(e.smid)];a=o?Qg(o):-1}else if(e.smid!=null){let t=r?.pickInfo,n=t?.[e.smid]??t?.[String(e.smid)],o=n?Qg(n):-1;a=o,i=n?.segments??(o>=0?e_(r,o).segments:[])}else n===e.mesh&&(i=e_(t.geoByBatchId?.get(e.batchId)??r,e.batchId).segments,a=e.batchId);let o=Kx(n.geometry,i);if(o&&o.length>0){let t=a>=0?new Float32Array(o.length/6).fill(a):void 0,r=new dc(Vx(o,t),this._createSelectionEdgeMaterial(n));r.renderOrder=4,r.frustumCulled=!1,r.raycast=()=>{},r.userData.isSelectionEdge=!0,n===e.mesh&&e.instanceIndex!=null&&this._applyInstanceTransform(r,e),n.add(r),this._selectionEdgeMeshes.push(r)}}this._selectionEdgeMeshes.length===0?this._addSelectionHull(e,t):this._selectionEdges=this._selectionEdgeMeshes[0]??null}_applyInstanceTransform(e,t){let n=t.mesh;if(t.instanceIndex==null||!n.isInstancedMesh)return;let r=new U;n.getMatrixAt(t.instanceIndex,r),r.decompose(e.position,e.quaternion,e.scale)}_addSelectionHull(e,t){let n=e.instanceIndex!=null;this.outlineMaterial.uniforms.uSelBatch.value=n?-1:e.batchId,this.outlineMaterial.uniforms.uSelWhole.value=n||e.batchId<0?1:0,this.outlineMaterial.uniforms.uElevation.value=n?this._selectionElevation(e):this.style.selectElevation??0;for(let n of t){let t=aS(n);t?.userData?.uBatchTex&&(this.outlineMaterial.uniforms.uBatchTex.value=t.userData.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=t.userData.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=t.userData.uBatchTexActive.value);let r=new dc(n.geometry,this.outlineMaterial);r.renderOrder=3,r.frustumCulled=!1,r.raycast=()=>{},n===e.mesh&&e.instanceIndex!=null&&this._applyInstanceTransform(r,e),n.add(r),this._outlineMeshes.push(r)}this._outlineMesh=this._outlineMeshes[0]??null}_syncSelectionStyle(){let e=this.style,t=this.selectionEdgeMaterial.uniforms;t.uColor.value.set(e.outlineColor??e.selectColor),t.uWidth.value=Math.max(.1,e.outlineWidthPx??3),t.uOpacity.value=Math.min(1,Math.max(.05,e.opacity??1)),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.outlineMaterial.uniforms.uBatchTex.value=n.uBatchTex.value,this.outlineMaterial.uniforms.uBatchTexWidth.value=n.uBatchTexWidth.value,this.outlineMaterial.uniforms.uBatchTexActive.value=n.uBatchTexActive.value)}}_selectionElevation(e){let t=this.style.selectElevation??0;if(e.smid!=null){let n=this._featureStyleManager.getFeatureEffectiveOffset(e.smid);n.elevation&&(t+=n.elevation)}return t}_clearSelectionDecoration(){for(let e of this._outlineMeshes)e.parent?.remove(e);this._outlineMeshes=[],this._outlineMesh=null;for(let e of this._selectionEdgeMeshes)e.parent?.remove(e),e.geometry.dispose();this._selectionEdgeMeshes=[],this._selectionEdges=null}_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}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()}}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;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=new U().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;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,e.canvasHeight)&&(s=!0)}this.style.mode===Ly.DYNAMIC&&(this.uniforms.uTime.value+=.016*(this.style.speed??1)),this.gpuPathManager.updateUniforms(this.uniforms);let c=(this.uniforms.uPathTexActive?.value??0)>0;c&&!this._customPathTime&&this.uniforms.uPathTime&&(this.uniforms.uPathTime.value+=.016),this._updateLights(),this._updateLineResolution(r),this.renderer.setViewport(0,0,r.width,r.height),this.renderer.resetState(),this.renderer.render(this.scene,this.camera),this._frame++;let l=performance.now();return l-this._fps.last>500&&(this._fps.value=Math.round(this._frame*1e3/(l-this._fps.last)),this._frame=0,this._fps.last=l),n||this.style.mode===Ly.DYNAMIC||c||this.stats.loading>0||s}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};for(let t of this.datasets.values()){let n=t.tileset?.stats;n&&(e.tiles+=n.tiles,e.loading+=n.loading,e.failed+=n.failed,e.meshes+=n.meshes,e.vertices+=n.vertices,e.triangles+=n.triangles)}return e}getBounds(){let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of this.datasets.values()){let a=Vb(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()}};X(uS,`_EDGE_SKIP_KEYWORDS`,[`terrain`,`ground`,`vegetation`,`green`,`road`,`dem`,`绿地`,`道路`,`地面`,`地形`,`植被`,`铺装`]),Pb(),rh();var dS=1e-4;function fS(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])>dS*r)return!1}return!0}function pS(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 mS(e,t){return t>0&&Math.abs(e.elements[5]*Math.tan(t/2)-1)<.001}function hS(e){if(!e||typeof e!=`object`)return null;let t=e;return t.defaultProjectionData?.projectionMatrix??t.projectionMatrix??null}function gS(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 _S(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 vS(e,t){let n=e.projectionMatrix;if(!n||n.length<16)return null;let r=new U().fromArray(Array.from(n)),i=new U().fromArray(Array.from(e.mvp));if(r.determinant()===0||!mS(r,t.fov))return null;let a=r.clone().invert().multiply(i);if(!fS(r.clone().multiply(a),Array.from(e.mvp))||!pS(a)||!mS(r,t.fov))return null;let{distance:o,fov:s,aspect:c}=t;if(!(o>0)||!(s>0)||!(c>0))return null;let l=o*Math.tan(s/2),u=l*c,d=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,f=e.farZ!=null&&e.farZ>d?e.farZ:o*4+1e3;f>d||(f=d+1e3);let p=new zc(-u,u,l,-l,d,f);return p.updateProjectionMatrix(),{matrix:p.projectionMatrix.clone().multiply(a),view:a}}function yS(e,t,n){let r=e.projectionMatrix;if(!r||r.length<16)return null;let i=new U().fromArray(Array.from(r)),a=new U().fromArray(Array.from(e.mvp));if(i.determinant()===0||!mS(i,t.fov))return null;let o=i.clone().invert().multiply(a);if(!fS(i.clone().multiply(o),Array.from(e.mvp))||!pS(o))return null;let s=Math.max(0,Math.min(1,n));if(s<=0)return{matrix:a,view:o};let{distance:c,fov:l,aspect:u}=t;if(!(c>0)||!(l>0)||!(u>0))return null;let d=c*Math.tan(l/2),f=d*u,p=e.nearZ!=null&&e.nearZ>0?e.nearZ:1,m=e.farZ!=null&&e.farZ>p?e.farZ:c*4+1e3;m>p||(m=p+1e3);let h=new zc(-f,f,d,-d,p,m);if(h.updateProjectionMatrix(),s>=1)return{matrix:h.projectionMatrix.clone().multiply(o),view:o};let g=new U,_=i.elements,v=h.projectionMatrix.elements,y=g.elements;for(let e=0;e<16;e++)y[e]=(1-s)*_[e]+s*v[e];return{matrix:g.multiply(o),view:o}}var bS=i({Animator:()=>Ix,AttributeQuery:()=>u_,BinaryReader:()=>dh,DEFAULT_FLOOR_HEIGHT:()=>i_,DEFAULT_STYLE:()=>Vy,DatasetManager:()=>Yx,EARTH_RADIUS:()=>d_,EASING_NAMES:()=>hx,FeatureStyleManager:()=>nS,GPUPathManager:()=>My,GroundManager:()=>rS,Path:()=>ky,Picker:()=>ix,PixelFormat:()=>rv,S3MFormatError:()=>Xg,S3MTileset:()=>Wb,S3MViewer:()=>uS,S3M_VERSION:()=>vg,SAMPLES_PER_PATH:()=>256,SELECT_MODE:()=>zy,SELECT_MODE_LABELS:()=>By,STYLE:()=>Ly,STYLE_LABELS:()=>Ry,TextureCompress:()=>iv,VertexTag:()=>yg,VertexTagV3:()=>bg,buildAttributes:()=>n_,buildBlendedMVP:()=>yS,buildFeatureEdgeSegments:()=>Kx,buildOrthoMVP:()=>vS,buildThickLineGeometry:()=>Vx,buildTileObjects:()=>jb,createLineSharedUniforms:()=>Lx,createOutlineMaterial:()=>Iy,createSharedUniforms:()=>Py,createStyledMaterial:()=>Fy,createTexture:()=>wy,createThickLineMaterial:()=>Bx,cubicBezier:()=>Ex,default:()=>uS,dxtPixelFormatOf:()=>nv,easing:()=>gx,extractEulerAngles:()=>Zx,extractFovRadians:()=>_S,extractNearFar:()=>gS,extractProjectionMatrix:()=>hS,isS3M1Buffer:()=>ag,lngLatFromMercator:()=>p_,lngLatFromWorld:()=>h_,measureSegments:()=>t_,mercatorFromLngLat:()=>f_,parseS3M1:()=>_g,parseS3MB:()=>Zg,resolveFeature:()=>e_,resolveRotationMatrix:()=>Xx,resolveTextureKind:()=>tv,setMaxAnisotropy:()=>vy,steps:()=>Dx,worldFromLngLat:()=>m_});a_(),eb(),Ny(),Oy(),sv(),Ay(),rh(),a_(),sv(),Oy(),Ay(),Ny(),eb(),Pb();var xS=globalThis;return xS.THREE||(xS.THREE=a),xS.S3M=bS,e.Animator=Ix,e.AttributeQuery=u_,e.BinaryReader=dh,e.DEFAULT_FLOOR_HEIGHT=i_,e.DEFAULT_STYLE=Vy,e.DatasetManager=Yx,e.EARTH_RADIUS=d_,e.EASING_NAMES=hx,e.FeatureStyleManager=nS,e.GPUPathManager=My,e.GroundManager=rS,e.Path=ky,e.Picker=ix,e.PixelFormat=rv,e.S3MFormatError=Xg,e.S3MTileset=Wb,e.S3MViewer=uS,e.default=uS,e.S3M_VERSION=vg,e.SAMPLES_PER_PATH=jy,e.SELECT_MODE=zy,e.SELECT_MODE_LABELS=By,e.STYLE=Ly,e.STYLE_LABELS=Ry,e.TextureCompress=iv,e.VertexTag=yg,e.VertexTagV3=bg,e.buildAttributes=n_,e.buildBlendedMVP=yS,e.buildFeatureEdgeSegments=Kx,e.buildOrthoMVP=vS,e.buildThickLineGeometry=Vx,e.buildTileObjects=jb,e.createLineSharedUniforms=Lx,e.createOutlineMaterial=Iy,e.createSharedUniforms=Py,e.createStyledMaterial=Fy,e.createTexture=wy,e.createThickLineMaterial=Bx,e.cubicBezier=Ex,e.dxtPixelFormatOf=nv,e.easing=gx,e.extractEulerAngles=Zx,e.extractFovRadians=_S,e.extractNearFar=gS,e.extractProjectionMatrix=hS,e.isS3M1Buffer=ag,e.lngLatFromMercator=p_,e.lngLatFromWorld=h_,e.measureSegments=t_,e.mercatorFromLngLat=f_,e.parseS3M1=_g,e.parseS3MB=Zg,e.resolveFeature=e_,e.resolveRotationMatrix=Xx,e.resolveTextureKind=tv,e.setMaxAnisotropy=vy,e.steps=Dx,e.worldFromLngLat=m_,e})({});