@arcgis/core 5.0.0-next.37 → 5.0.0-next.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Color.js +1 -1
- package/analysis/DimensionSimpleStyle.js +1 -1
- package/analysis/ElevationProfileAnalysis.js +1 -1
- package/applications/Components/testUtils.d.ts +4 -0
- package/applications/Components/testUtils.js +5 -0
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/02a65563779b4c64b2cf.js +1 -0
- package/assets/esri/core/workers/chunks/{328106e181e5957ceaa5.js → 09ac2bbc7327e6e6b5a2.js} +1 -1
- package/assets/esri/core/workers/chunks/1a9ed3c59a9a8bafb251.js +1 -0
- package/assets/esri/core/workers/chunks/{b96af22ec1470905e4fb.js → 1c857191e5898aba50fe.js} +1 -1
- package/assets/esri/core/workers/chunks/2795e491f803654413d2.js +1 -0
- package/assets/esri/core/workers/chunks/{3904f8732c9953cb177d.js → 28b235b56a83c498d73f.js} +1 -1
- package/assets/esri/core/workers/chunks/36d15c35fbbd4dedd5cb.js +1 -0
- package/assets/esri/core/workers/chunks/48f805929fe6241952f5.js +1 -0
- package/assets/esri/core/workers/chunks/4c278fb2d51ca6226050.js +1 -0
- package/assets/esri/core/workers/chunks/6052eccb9395c8efb295.js +1 -0
- package/assets/esri/core/workers/chunks/613cbac9cb925cd20b48.js +1 -0
- package/assets/esri/core/workers/chunks/{febce0d80f019dc2a427.js → 646f58b69d2354f1ef27.js} +1 -1
- package/assets/esri/core/workers/chunks/7eab0bb42f9f062522ef.js +1 -0
- package/assets/esri/core/workers/chunks/{5e34a183420e7007a989.js → 8e8d5422f57269d8c8d2.js} +1 -1
- package/assets/esri/core/workers/chunks/9100330ed4b4437c819d.js +1 -0
- package/assets/esri/core/workers/chunks/95cb062cae4c31c07124.js +1 -0
- package/assets/esri/core/workers/chunks/{ce8fc1ca229d53a4b68d.js → 96f798ee286b59396131.js} +50 -50
- package/assets/esri/core/workers/chunks/{e9bc3c6482ba778c9349.js → 9d95f38da21f97214f83.js} +1 -1
- package/assets/esri/core/workers/chunks/ad4fcb73cfe9a1e4b710.js +1 -0
- package/assets/esri/core/workers/chunks/{a8a017d7969562d21d2e.js → b48aceaeefa07214e430.js} +1 -1
- package/assets/esri/core/workers/chunks/c1a4d1ec0125617374b4.js +1 -0
- package/assets/esri/core/workers/chunks/{d2a6f035022a3f060ffa.js → c320a29df40e85fb4a8e.js} +1 -1
- package/assets/esri/core/workers/chunks/{52c8687b473c9953c2f2.js → d9958654c6438f28237b.js} +1 -1
- package/assets/esri/core/workers/chunks/{27ec791318e81285c222.js → dca6a61fd239cf1ff90c.js} +1 -1
- package/assets/esri/core/workers/chunks/e66bcdfd75e0113d1cec.js +1 -0
- package/assets/esri/core/workers/chunks/f1381c5a2a1de1ef9139.js +1 -0
- package/assets/esri/core/workers/chunks/f21cb5b34d4d1e3af1a9.js +1 -0
- package/chunks/ChapmanAtmosphere.glsl.js +20 -20
- package/chunks/GaussianSplat.glsl.js +2 -2
- package/chunks/HUDMaterial.glsl.js +38 -38
- package/chunks/Haze.glsl.js +23 -23
- package/config.js +1 -1
- package/core/Collection.js +1 -1
- package/core/CollectionFlattener.js +1 -1
- package/core/arrayUtils.js +1 -1
- package/geometry/support/buffer/BufferView.js +1 -1
- package/geometry/support/curves/densifyCurvedGeometry.js +1 -1
- package/interfaces.d.ts +74 -0
- package/kernel.js +1 -1
- package/layers/ImageryTileLayer.js +1 -1
- package/layers/RouteLayer.js +1 -1
- package/layers/support/FeatureReductionCluster.js +1 -1
- package/layers/support/LabelClass.js +1 -1
- package/package.json +3 -3
- package/renderers/FlowRenderer.js +1 -1
- package/renderers/HeatmapRenderer.js +1 -1
- package/renderers/PieChartRenderer.js +1 -1
- package/rest/route/utils.js +1 -1
- package/rest/support/PointBarrier.js +1 -1
- package/rest/support/Stop.js +1 -1
- package/support/revision.js +1 -1
- package/support/tests/meshUtils.js +5 -0
- package/support/tests/serviceMockDependencies.js +5 -0
- package/support/tests/setupServiceMocksMesh.js +5 -0
- package/symbols/Font.js +1 -1
- package/symbols/IconSymbol3DLayer.js +1 -1
- package/symbols/LineSymbol.js +1 -1
- package/symbols/LineSymbol3DLayer.js +1 -1
- package/symbols/MarkerSymbol.js +1 -1
- package/symbols/PictureFillSymbol.js +1 -1
- package/symbols/PictureMarkerSymbol.js +1 -1
- package/symbols/TextSymbol.js +1 -1
- package/symbols/TextSymbol3DLayer.js +1 -1
- package/symbols/callouts/LineCallout3D.js +1 -1
- package/symbols/edges/Edges3D.js +1 -1
- package/symbols/support/Symbol3DIconOutline.js +1 -1
- package/symbols/support/Symbol3DOutline.js +1 -1
- package/symbols/support/Symbol3DVerticalOffset.js +1 -1
- package/views/2d/layers/RouteLayerView2D.js +1 -1
- package/views/2d/layers/support/RouteLayerInteraction.js +1 -1
- package/views/2d/layers/support/util.js +1 -1
- package/views/3d/analysis/Dimension/DimensionTool.js +1 -1
- package/views/3d/analysis/Slice/SliceTool.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
- package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementCutFillVisualization.js +1 -1
- package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementShiftTool.js +1 -1
- package/views/3d/camera/intersectionUtils.js +1 -1
- package/views/3d/environment/ChapmanApproximation.glsl.js +8 -8
- package/views/3d/environment/ChapmanAtmosphere.glsl.js +1 -1
- package/views/3d/environment/ChapmanRaymarching.glsl.js +16 -15
- package/views/3d/layers/FlowSubView3D.js +1 -1
- package/views/3d/layers/PointCloudWorker.js +1 -1
- package/views/3d/layers/graphics/Deconflictor.js +1 -1
- package/views/3d/layers/graphics/Graphics3DGraphic.js +1 -1
- package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineCalloutSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObject3DGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
- package/views/3d/state/NearFarHeuristic.js +1 -1
- package/views/3d/support/flow/FlowSubViewTiles3D.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatDataStore.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/TextureBackedBuffer.glsl.js +4 -4
- package/views/3d/webgl-engine/core/shaderLibrary/TextureBackedBufferFields.glsl.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/hud/HUD.glsl.js +12 -12
- package/views/3d/webgl-engine/core/shaderLibrary/util/GaussianSplatUnpacking.glsl.js +8 -8
- package/views/3d/webgl-engine/lib/CutFillColor.js +1 -1
- package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBuffer.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferFieldCreation.js +5 -0
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferFields.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferLayout.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferLayoutField.js +5 -0
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferUtils.js +5 -0
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBuffer.js +5 -0
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBufferView.js +5 -0
- package/views/3d/webgl-engine/shaders/GaussianSplat.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/TerrainTechnique.js +1 -1
- package/views/BreakpointsOwner.js +1 -1
- package/views/ToolViewManager.js +1 -1
- package/views/View.js +1 -1
- package/views/analysis/ElevationProfile/ElevationProfileTool.js +1 -1
- package/views/draw/support/Reshape.js +1 -1
- package/views/interactive/InteractiveToolBase.js +1 -1
- package/views/interactive/ToolViewManagerManipulatorState.js +1 -1
- package/views/layers/GroupLayerView.js +1 -1
- package/views/support/Scheduler.js +1 -1
- package/widgets/OrientedImageryViewer/components/ImageOverlays.js +1 -1
- package/widgets/ScaleRangeSlider.js +1 -1
- package/widgets/Slider.js +1 -1
- package/widgets/UtilityNetworkTrace/UtilityNetworkTraceViewModel.js +1 -1
- package/assets/esri/core/workers/chunks/1d877c3c96c40eab906c.js +0 -1
- package/assets/esri/core/workers/chunks/22f745539ca54d8cd30d.js +0 -1
- package/assets/esri/core/workers/chunks/42f3e83826b3a3dedaaa.js +0 -1
- package/assets/esri/core/workers/chunks/44471962c30344dfafdf.js +0 -1
- package/assets/esri/core/workers/chunks/8ca83a9af9d24b192128.js +0 -1
- package/assets/esri/core/workers/chunks/951a3442d4342539f2ea.js +0 -1
- package/assets/esri/core/workers/chunks/9527f1a611557a7af237.js +0 -1
- package/assets/esri/core/workers/chunks/ad3a4d139613b4c0e0b4.js +0 -1
- package/assets/esri/core/workers/chunks/c1c77a00f639eaee9c0d.js +0 -1
- package/assets/esri/core/workers/chunks/c5967133f3ba34a883f8.js +0 -1
- package/assets/esri/core/workers/chunks/c8d2cce4a426c72ab173.js +0 -1
- package/assets/esri/core/workers/chunks/e0a74250d22fa1d7dc18.js +0 -1
- package/assets/esri/core/workers/chunks/e3be67c762af672ec602.js +0 -1
- package/assets/esri/core/workers/chunks/eefad79be500667af96e.js +0 -1
- package/assets/esri/core/workers/chunks/f8caceeaa14d99c35526.js +0 -1
- package/assets/esri/core/workers/chunks/f919f0db9f9ec0c649b9.js +0 -1
- package/views/3d/webgl-engine/core/shaderLibrary/util/FastApproximateTrigonometry.glsl.js +0 -26
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as m}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as f,sync as y,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/units.js";import{property as w,subclass as C}from"../../../core/accessorSupport/decorators.js";import{m as S,h as b,d as E}from"../../../chunks/vec32.js";import{create as x}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as R}from"../../../geometry/ellipsoidUtils.js";import U from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as k,intersection as V,intersectsSphere as A,empty as B,expand as O}from"../../../geometry/support/aaBoundingRect.js";import{copy as G,create as N}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as q}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as W}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as $}from"../../../layers/support/layerUtils.js";import{debugFlags as Q}from"../support/debugFlags.js";import{ElevationRange as z}from"../support/ElevationRange.js";import{toBoundingRect as Y}from"../support/extentUtils.js";import{updatingProgress as X}from"../support/updatingProperties.js";import{ElevationBounds as K}from"./ElevationBounds.js";import{ElevationData as J,sampleElevation as Z}from"./ElevationData.js";import{ElevationUpdateEventImplementation as ee}from"./ElevationUpdateEvent.js";import{create as te}from"./ExtentHelper.js";import{LayerClasses as ie}from"./LayerClass.js";import{OverlayManager as re}from"./OverlayManager.js";import{PlanarPatch as se}from"./PlanarPatch.js";import{Queue as ae}from"./Queue.js";import{ScaleRangeQueries as ne}from"./ScaleRangeQueries.js";import{SphericalPatch as le}from"./SphericalPatch.js";import{SplitLimits as oe}from"./SplitLimits.js";import{maxRootTiles as he,tooManyRootTilesAfterChangeError as de,tooManyRootTilesForLayerError as pe,maxTileNeighborLevelDelta as ue,maxMemoryLodBias as ce}from"./TerrainConst.js";import{TerrainRenderer as ge}from"./TerrainRenderer.js";import me from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as _e,isVectorTileLayerView as fe,neighborEdgeIndices as ye,internalAssert as Te,oppositeEdge as ve,isSurfaceLayerView as we,isGroupLayerView as Ce,isMapTileLayerView as Se,isBlendableLayerView as be,isElevationLayerView as Ee,releaseTerrainData as xe,enableTerrainInternalChecks as Le,oppositeCorner as Pe,enableWaterproofTests as Re,enableInternalTerrainChecks as Ue,enableTerrainWaterproofChecks as Me,neighborCornerIndices as De}from"./terrainUtils.js";import{Tile as je,lijEquals as Ie}from"./Tile.js";import{printAllocations as ke}from"./TilePerLayerInfo.js";import{sortTiles as Ve,IteratorPreorder as Ae,IteratorPostorder as Be,compareTilesByLij as Oe,hasLoadableSiblings as Ge,sortTilesByPOI as Ne}from"./tileUtils.js";import{TilingSchemeLogic as qe}from"./TilingSchemeLogic.js";import{UpsampleInfo as Fe}from"./UpsampleInfo.js";import{isCompositeBlendMode as We,blendModeFromString as He}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as $e}from"../../support/layerViewUtils.js";import{ImmediateTask as Qe,TaskPriority as ze,noBudget as Ye}from"../../support/Scheduler.js";import{TextureCompressionTracker as Xe}from"../../support/TextureCompressionTracker.js";import{Yield as Ke}from"../../support/Yield.js";var Je;let Ze=class extends n{static{Je=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ve(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new Xe,this._iteratorPool=new p(()=>new Ae,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Be,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new me,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=x(),this._eyePosSurfaceSR=x(),this._splitLimits=new oe,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Qe,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new Fe),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=U.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new z(1/0,-1/0),this._rootTileElevationRange=new z(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?le:se,this._ellipsoid=P(t.spatialReference),this._renderer=new ge(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),$e()||(this._scaleRangeQueries=new ne)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new H(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([_(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),_(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([_(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},f),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),f),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},y),_(()=>this.snapLevel,()=>this._viewChanged=!0,y),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:S})}),_(()=>Q.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&Q.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=te(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new qe({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(ze.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),y),_(()=>this.groundExtent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),f),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),_(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),_(()=>this.userClippingExtent,()=>this._updateClippingExtent(),y)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Qe,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),je.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),ke(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get userClippingExtent(){const{spatialReference:e}=this,t=this.view?.clippingArea;if(null==t||null==e)return null;const i=I(),r=Y(t,i,e)?i:null,s=this._get("userClippingExtent");return k(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){const e=V(this.fullGroundExtent,this.userClippingExtent,I()),t=this._get("groundExtent");return k(e,t)?t:e}get fullGroundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||null!=this._rootTiles}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return q(this._spatialReference)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(tt,e,t,i);a(n,0,n,0);return lt(s,this._xNormalizer?.normalize(n[0])??n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,lt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!D(e,tt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(tt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;tt[0]>t[2]&&(i+=1),tt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationRange(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system"),null;it.copy(e),i(it.center,0,it.center,0);const r=new z,s=this._rootTiles;if(null!=s){const e=[];for(const i of s)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,it))continue;const s=i.children;if(null==s[0]||i.rendered)r.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of s)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&null!=this._rootTiles?new z(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*R;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,it.center,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;it.radius=t;let i=null;const r=e=>{if(e&&A(e.extent,it)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;_e(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??U.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(Je._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled)return void this._setRootTiles(null);const i=rt;let s=t.rootTilesInExtent(e,i,5*he);if(null!=this._rootTiles){if(s.length>he)return void l.getLogger(this).warn(de);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,Ie);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>Ie(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>he&&(l.getLogger(this).warn(pe),s=t.rootTilesInExtent(e,i,he)),this._setRootTiles(s.map(e=>this._newRootTile(e)));k(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Oe),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Oe);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=Ge(e),i=this.visibleElevationRange;let r=t?i.minElevation:1/0,s=t?i.maxElevation:-1/0;const a=this.groundExtent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.minElevation!==r||i.maxElevation!==s)&&(this.visibleElevationRange=new K(r,s))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this._rootTileElevationRange;r.minElevation===e&&r.maxElevation===t||(this._rootTileElevationRange=new K(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=G(this._splitLimits.frustum??N(),t.frustum):this._splitLimits.frustum=null,E(this._eyePosRenderSR,t.eye),j(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(fe)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=at.extent;B(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>O(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),at.spatialReference=this.spatialReference,this.emit("elevation-change",at),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Le&&this._checkTileInvariant(),!e.hasProgressed)return Ke}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(_e(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(_e(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){_e(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)_e(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=ue;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${ue} (edge[${i}])`),_e(r,`tile level delta [${t.level}] vs [${e.level}] > ${ue}`))}_e(t.level-e.level<=ue,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-ue,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(ye[i],s);if(null!=a){if(t.leaf&&t.level>=ue){let i=a;for(;t.level-i.level<ue;)i=i.parent;const s=[r,t.lij[1]>>ue,t.lij[2]>>ue];if(!Ie(s,i.lij)){const r=e.get(i);_e(!r.has(t),"Cannot already have neighbor"),r.add(t)}}_e(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),_e(t.level-a.level<=ue,`Tile level delta [${t.level}] vs [${a.level}] > ${ue}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);_e(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new ae(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=n?.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?ot(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){Te(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Oe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Te(r.loaded),Te(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=De[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(Pe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(ve(ye[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(Te(e.has(t)||Oe(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Le&&Re&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=ue){const e=e=>e.leaf||i-e.level<ue;for(let r=0;r<4;++r){const a=s.findNeighborTile(ye[r],e);null!=a&&i-a.level===ue&&(t=!1,Le&&(Te(a.leaf),Te(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*ce}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?dt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(Je._tileMemcacheKey,e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){_e(e.leaf,"Tile that is already split should not be split again!"),_e(e.rendered,"Tile marked to split is not rendered"),dt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),_e(e.rendered,"parent should be rendered"),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>ot(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){nt.spatialReference=this.spatialReference,nt.extent=e.extent,nt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",nt)}createTile(e,t,i,r){_e(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.groundExtent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){_e(!e.hasPendingUpdate(1),"_mergeTile sanity check"),_e(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),_e(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),ot(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=Ye){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),we(e)||Ce(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ce(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(Se(e)&&!$(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((be(e)||Ce(e))&&We(He[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Ee(e)?0:1}_registerTiledLayerView(e){const t=[];if((be(e)||Ce(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Ce(e)){const i=this._layerClassFromLayerView(e);t.push(_(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(_(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(_(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!we(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ie){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.setNeedsRender(e)}requestUpdate(){1===++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||fe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,c(r),g(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();return 0===t?Ee(i)?this._requestElevationTileData(e,i,r):Promise.reject():Se(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!m(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new J(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationRange(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{xe(s),m(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(i)?xe(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return xe(i),void l.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):l.getLogger(this).warn("TerrainSurface: received data from unknown layer")}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Re)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.leaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.leaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._isGeographic?1:0)}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this._isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ue(e)}enableWaterproofnessChecks(e){Me(e)}static cleanupTerrainSurface(){st.prune()}enable(e){e!==this.enabled&&(this._set("enabled",e),e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],Ze.prototype,"_renderer",void 0),e([w({constructOnly:!0})],Ze.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],Ze.prototype,"view",void 0),e([w({constructOnly:!0})],Ze.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],Ze.prototype,"terrainTextureCompressionTracker",void 0),e([w()],Ze.prototype,"_hasPendingUpdates",void 0),e([w()],Ze.prototype,"_asyncWorkItems",void 0),e([w()],Ze.prototype,"_allTilesDirty",void 0),e([w()],Ze.prototype,"_allTilesSorted",void 0),e([w()],Ze.prototype,"_allTilesCreated",void 0),e([w()],Ze.prototype,"_viewChanged",void 0),e([w({type:Number})],Ze.prototype,"heading",void 0),e([w()],Ze.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],Ze.prototype,"_watchUpdatingTracking",void 0),e([w()],Ze.prototype,"_frameTask",void 0),e([w()],Ze.prototype,"demResolution",null),e([w({readOnly:!0})],Ze.prototype,"snapLevel",null),e([w({readOnly:!0})],Ze.prototype,"lodSnappingEnabled",null),e([w({readOnly:!0})],Ze.prototype,"userClippingExtent",null),e([w()],Ze.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],Ze.prototype,"groundExtent",null),e([w({readOnly:!0})],Ze.prototype,"fullGroundExtent",null),e([w({readOnly:!0})],Ze.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],Ze.prototype,"updating",null),e([w({readOnly:!0})],Ze.prototype,"readyToRun",null),e([w(X)],Ze.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],Ze.prototype,"updatingProgressValue",null),e([w()],Ze.prototype,"_maxNumUpdating",void 0),e([w()],Ze.prototype,"baseOpacity",null),e([w()],Ze.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],Ze.prototype,"viewingMode",null),e([w()],Ze.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],Ze.prototype,"ready",null),e([w({readOnly:!0})],Ze.prototype,"rootTiles",null),e([w()],Ze.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],Ze.prototype,"spatialReference",null),e([w({type:t})],Ze.prototype,"backgroundColor",null),e([w({value:!1})],Ze.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],Ze.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLogic",void 0),e([w()],Ze.prototype,"wireframe",null),e([w({value:!1})],Ze.prototype,"suspended",null),e([w()],Ze.prototype,"fadeDuration",null),e([w()],Ze.prototype,"_xNormalizer",null),e([w()],Ze.prototype,"visibleElevationRange",void 0),e([w()],Ze.prototype,"_rootTileElevationRange",void 0),e([w()],Ze.prototype,"_layerViewsDirty",void 0),e([w()],Ze.prototype,"renderPatchBorders",null),e([w()],Ze.prototype,"renderingDisabled",null),e([w({readOnly:!0})],Ze.prototype,"enabled",void 0),Ze=Je=e([C("esri.views.3d.terrain.TerrainSurface")],Ze);const et=Ze,tt=x(),it=new W,rt=I(),st=new u,at=new ee("ground"),nt={spatialReference:null,extent:null,scale:0};function lt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return Z(t,i,s)}return null}function ot(e,t){!e.leaf||e.level<ue||ut(e,e=>{t&&ht(e);const i=pt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=pt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function ht(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<ue||ut(e,e=>{ht(e)})}function dt(e){e.level<ue||ut(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,pt(t));)t=t.parent}})}function pt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function ut(e,t){if(e.level<ue)return;const i=e.level-ue,r=e.lij[1]>>ue,s=e.lij[2]>>ue,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(ye[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{et as default};
|
|
5
|
+
import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as m}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as f,sync as y,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/units.js";import{property as w,subclass as C}from"../../../core/accessorSupport/decorators.js";import{m as S,h as b,d as E}from"../../../chunks/vec32.js";import{create as x}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as R}from"../../../geometry/ellipsoidUtils.js";import U from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as k,intersection as V,intersectsSphere as A,empty as B,expand as O}from"../../../geometry/support/aaBoundingRect.js";import{copy as G,create as N}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as q}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as W}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as $}from"../../../layers/support/layerUtils.js";import{debugFlags as Q}from"../support/debugFlags.js";import{ElevationRange as z}from"../support/ElevationRange.js";import{toBoundingRect as Y}from"../support/extentUtils.js";import{updatingProgress as X}from"../support/updatingProperties.js";import{ElevationBounds as K}from"./ElevationBounds.js";import{ElevationData as J,sampleElevation as Z}from"./ElevationData.js";import{ElevationUpdateEventImplementation as ee}from"./ElevationUpdateEvent.js";import{create as te}from"./ExtentHelper.js";import{LayerClasses as ie}from"./LayerClass.js";import{OverlayManager as re}from"./OverlayManager.js";import{PlanarPatch as se}from"./PlanarPatch.js";import{Queue as ae}from"./Queue.js";import{ScaleRangeQueries as ne}from"./ScaleRangeQueries.js";import{SphericalPatch as le}from"./SphericalPatch.js";import{SplitLimits as oe}from"./SplitLimits.js";import{maxRootTiles as he,tooManyRootTilesAfterChangeError as de,tooManyRootTilesForLayerError as pe,maxTileNeighborLevelDelta as ue,maxMemoryLodBias as ce}from"./TerrainConst.js";import{TerrainRenderer as ge}from"./TerrainRenderer.js";import me from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as _e,isVectorTileLayerView as fe,neighborEdgeIndices as ye,internalAssert as Te,oppositeEdge as ve,isSurfaceLayerView as we,isGroupLayerView as Ce,isMapTileLayerView as Se,isBlendableLayerView as be,isElevationLayerView as Ee,releaseTerrainData as xe,enableTerrainInternalChecks as Le,oppositeCorner as Pe,enableWaterproofTests as Re,enableInternalTerrainChecks as Ue,enableTerrainWaterproofChecks as Me,neighborCornerIndices as De}from"./terrainUtils.js";import{Tile as je,lijEquals as Ie}from"./Tile.js";import{printAllocations as ke}from"./TilePerLayerInfo.js";import{sortTiles as Ve,IteratorPreorder as Ae,IteratorPostorder as Be,compareTilesByLij as Oe,hasLoadableSiblings as Ge,sortTilesByPOI as Ne}from"./tileUtils.js";import{TilingSchemeLogic as qe}from"./TilingSchemeLogic.js";import{UpsampleInfo as Fe}from"./UpsampleInfo.js";import{isCompositeBlendMode as We,blendModeFromString as He}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as $e}from"../../support/layerViewUtils.js";import{ImmediateTask as Qe,TaskPriority as ze,noBudget as Ye}from"../../support/Scheduler.js";import{TextureCompressionTracker as Xe}from"../../support/TextureCompressionTracker.js";import{Yield as Ke}from"../../support/Yield.js";var Je;let Ze=class extends n{static{Je=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ve(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new Xe,this._iteratorPool=new p(()=>new Ae,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Be,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new me,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=x(),this._eyePosSurfaceSR=x(),this._splitLimits=new oe,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Qe,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new Fe),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=U.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new z(1/0,-1/0),this._rootTileElevationRange=new z(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?le:se,this._ellipsoid=P(t.spatialReference),this._renderer=new ge(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),$e()||(this._scaleRangeQueries=new ne)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new H(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([_(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),_(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([_(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},f),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),f),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},y),_(()=>this.snapLevel,()=>this._viewChanged=!0,y),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:S})}),_(()=>Q.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&Q.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=te(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new qe({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(ze.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),y),_(()=>this.groundExtent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),f),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),_(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),_(()=>this.userClippingExtent,()=>this._updateClippingExtent(),y)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Qe,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),je.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),ke(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get userClippingExtent(){const{spatialReference:e}=this,t=this.view?.clippingArea;if(null==t||null==e)return null;const i=I(),r=Y(t,i,e)?i:null,s=this._get("userClippingExtent");return k(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){const e=V(this.fullGroundExtent,this.userClippingExtent,I()),t=this._get("groundExtent");return k(e,t)?t:e}get fullGroundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||null!=this._rootTiles}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return q(this._spatialReference)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(tt,e,t,i);a(n,0,n,0);return lt(s,this._xNormalizer?.normalize(n[0])??n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,lt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!D(e,tt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(tt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;tt[0]>t[2]&&(i+=1),tt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationRange(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system"),null;it.copy(e),i(it.center,0,it.center,0);const r=new z,s=this._rootTiles;if(null!=s){const e=[];for(const i of s)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,it))continue;const s=i.children;if(null==s[0]||i.rendered)r.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of s)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&null!=this._rootTiles?new z(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*R;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,it.center,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;it.radius=t;let i=null;const r=e=>{if(e&&A(e.extent,it)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;_e(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??U.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(Je._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled)return void this._setRootTiles(null);const i=rt;let s=t.rootTilesInExtent(e,i,5*he);if(null!=this._rootTiles){if(s.length>he)return void l.getLogger(this).warn(de);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,Ie);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>Ie(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>he&&(l.getLogger(this).warn(pe),s=t.rootTilesInExtent(e,i,he)),this._setRootTiles(s.map(e=>this._newRootTile(e)));k(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Oe),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Oe);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=Ge(e),i=this.visibleElevationRange;let r=t?i.minElevation:1/0,s=t?i.maxElevation:-1/0;const a=this.groundExtent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.minElevation!==r||i.maxElevation!==s)&&(this.visibleElevationRange=new K(r,s))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this._rootTileElevationRange;r.minElevation===e&&r.maxElevation===t||(this._rootTileElevationRange=new K(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=G(this._splitLimits.frustum??N(),t.frustum):this._splitLimits.frustum=null,E(this._eyePosRenderSR,t.eye),j(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(fe)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=at.extent;B(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>O(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),at.spatialReference=this.spatialReference,this.emit("elevation-change",at),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Le&&this._checkTileInvariant(),!e.hasProgressed)return Ke}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(_e(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(_e(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){_e(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)_e(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=ue;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${ue} (edge[${i}])`),_e(r,`tile level delta [${t.level}] vs [${e.level}] > ${ue}`))}_e(t.level-e.level<=ue,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-ue,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(ye[i],s);if(null!=a){if(t.leaf&&t.level>=ue){let i=a;for(;t.level-i.level<ue;)i=i.parent;const s=[r,t.lij[1]>>ue,t.lij[2]>>ue];if(!Ie(s,i.lij)){const r=e.get(i);_e(!r.has(t),"Cannot already have neighbor"),r.add(t)}}_e(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),_e(t.level-a.level<=ue,`Tile level delta [${t.level}] vs [${a.level}] > ${ue}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);_e(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new ae(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=n?.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?ot(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){Te(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Oe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Te(r.loaded),Te(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=De[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(Pe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(ve(ye[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(Te(e.has(t)||Oe(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Le&&Re&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=ue){const e=e=>e.leaf||i-e.level<ue;for(let r=0;r<4;++r){const a=s.findNeighborTile(ye[r],e);null!=a&&i-a.level===ue&&(t=!1,Le&&(Te(a.leaf),Te(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*ce}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?dt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(Je._tileMemcacheKey,e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){_e(e.leaf,"Tile that is already split should not be split again!"),_e(e.rendered,"Tile marked to split is not rendered"),dt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),_e(e.rendered,"parent should be rendered"),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>ot(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){nt.spatialReference=this.spatialReference,nt.extent=e.extent,nt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",nt)}createTile(e,t,i,r){_e(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.groundExtent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){_e(!e.hasPendingUpdate(1),"_mergeTile sanity check"),_e(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),_e(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),ot(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=Ye){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),we(e)||Ce(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ce(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(Se(e)&&!$(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((be(e)||Ce(e))&&We(He[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Ee(e)?0:1}_registerTiledLayerView(e){const t=[];if((be(e)||Ce(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Ce(e)){const i=this._layerClassFromLayerView(e);t.push(_(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(_(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(_(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!we(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ie){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.setNeedsRender(e)}requestUpdate(){1===++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||fe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,c(r),g(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();return 0===t?Ee(i)?this._requestElevationTileData(e,i,r):Promise.reject():Se(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!m(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new J(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationRange(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{xe(s),m(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(i)?xe(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return xe(i),void l.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):l.getLogger(this).warn("TerrainSurface: received data from unknown layer")}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Re)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.leaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.leaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._isGeographic?1:0)}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this._isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ue(e)}enableWaterproofnessChecks(e){Me(e)}static cleanupTerrainSurface(){st.prune()}enable(e){e!==this.enabled&&(this._set("enabled",e),e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],Ze.prototype,"_renderer",void 0),e([w({constructOnly:!0})],Ze.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],Ze.prototype,"view",void 0),e([w({constructOnly:!0})],Ze.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],Ze.prototype,"terrainTextureCompressionTracker",void 0),e([w()],Ze.prototype,"_hasPendingUpdates",void 0),e([w()],Ze.prototype,"_asyncWorkItems",void 0),e([w()],Ze.prototype,"_allTilesDirty",void 0),e([w()],Ze.prototype,"_allTilesSorted",void 0),e([w()],Ze.prototype,"allTilesCreated",null),e([w()],Ze.prototype,"_allTilesCreated",void 0),e([w()],Ze.prototype,"_viewChanged",void 0),e([w({type:Number})],Ze.prototype,"heading",void 0),e([w()],Ze.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],Ze.prototype,"_watchUpdatingTracking",void 0),e([w()],Ze.prototype,"_frameTask",void 0),e([w()],Ze.prototype,"demResolution",null),e([w({readOnly:!0})],Ze.prototype,"snapLevel",null),e([w({readOnly:!0})],Ze.prototype,"lodSnappingEnabled",null),e([w({readOnly:!0})],Ze.prototype,"userClippingExtent",null),e([w()],Ze.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],Ze.prototype,"groundExtent",null),e([w({readOnly:!0})],Ze.prototype,"fullGroundExtent",null),e([w({readOnly:!0})],Ze.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],Ze.prototype,"updating",null),e([w({readOnly:!0})],Ze.prototype,"readyToRun",null),e([w(X)],Ze.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],Ze.prototype,"updatingProgressValue",null),e([w()],Ze.prototype,"_maxNumUpdating",void 0),e([w()],Ze.prototype,"baseOpacity",null),e([w()],Ze.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],Ze.prototype,"viewingMode",null),e([w()],Ze.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],Ze.prototype,"ready",null),e([w({readOnly:!0})],Ze.prototype,"rootTiles",null),e([w()],Ze.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],Ze.prototype,"spatialReference",null),e([w({type:t})],Ze.prototype,"backgroundColor",null),e([w({value:!1})],Ze.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],Ze.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLogic",void 0),e([w()],Ze.prototype,"wireframe",null),e([w({value:!1})],Ze.prototype,"suspended",null),e([w()],Ze.prototype,"fadeDuration",null),e([w()],Ze.prototype,"_xNormalizer",null),e([w()],Ze.prototype,"visibleElevationRange",void 0),e([w()],Ze.prototype,"_rootTileElevationRange",void 0),e([w()],Ze.prototype,"_layerViewsDirty",void 0),e([w()],Ze.prototype,"renderPatchBorders",null),e([w()],Ze.prototype,"renderingDisabled",null),e([w({readOnly:!0})],Ze.prototype,"enabled",void 0),Ze=Je=e([C("esri.views.3d.terrain.TerrainSurface")],Ze);const et=Ze,tt=x(),it=new W,rt=I(),st=new u,at=new ee("ground"),nt={spatialReference:null,extent:null,scale:0};function lt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return Z(t,i,s)}return null}function ot(e,t){!e.leaf||e.level<ue||ut(e,e=>{t&&ht(e);const i=pt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=pt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function ht(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<ue||ut(e,e=>{ht(e)})}function dt(e){e.level<ue||ut(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,pt(t));)t=t.parent}})}function pt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function ut(e,t){if(e.level<ue)return;const i=e.level-ue,r=e.lij[1]>>ue,s=e.lij[2]>>ue,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(ye[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{et as default};
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{generateUID as e}from"../../../../../core/uid.js";import{unpackFloat4x8 as t,unpackHalf2x8 as o,glslType as d,glslDecodeField as a}from"./TextureBackedBufferFields.glsl.js";import{glsl as r}from"../shaderModules/glsl.js";import{assert as n}from"../../lib/Util.js";class i{constructor(t,o,d,a=()=>!0){this.moduleId=e(),this.namespace=`_tbb_${this.moduleId}_`,this.TextureBackedBufferModule=(e,r)=>c(this.namespace,e,r,o,d,t,a),this.getTextureAttribute=s(this.namespace)}}function c(e,i,c,s,l,u,m){const{vertex:$}=i;$.include(t),$.include(o);const x=`${e}tbbStride`,h=`${e}TextureBackedBufferItemData`,p=`${e}fetchTextureBackedBufferItemData`,
|
|
6
|
-
struct ${h} {`);for(const t of
|
|
5
|
+
import{generateUID as e}from"../../../../../core/uid.js";import{unpackFloat4x8 as t,unpackHalf2x8 as o,glslType as d,glslDecodeField as a}from"./TextureBackedBufferFields.glsl.js";import{glsl as r}from"../shaderModules/glsl.js";import{assert as n}from"../../lib/Util.js";class i{constructor(t,o,d,a=()=>!0){this.moduleId=e(),this.namespace=`_tbb_${this.moduleId}_`,this.TextureBackedBufferModule=(e,r)=>c(this.namespace,e,r,o,d,t,a),this.getTextureAttribute=s(this.namespace)}}function c(e,i,c,s,l,u,m){const{vertex:$}=i;$.include(t),$.include(o);const x=`${e}tbbStride`,h=`${e}TextureBackedBufferItemData`,p=`${e}fetchTextureBackedBufferItemData`,B=f(e);for(const t of[x,h,p,B])n(t.length<1024,"Identifiers do not have a valid length");$.constants.add(x,"float",u.texelStride),$.uniforms.add(l);const I=new Array;for(const t of u.fields.values())m(t.name,c)&&I.push(t);if(0===I.length)return;const g=[];for(let t=0;t<u.texelStride;++t)g.push(!1);for(const t of I)for(let e=0;e<t.numTexels;++e)g[t.startTexel+e]=!0;$.code.add(r`
|
|
6
|
+
struct ${h} {`);for(const t of I)$.code.add(r`\t${d(t)} ${t.name};`);$.code.add(r`};`),$.code.add(r`
|
|
7
7
|
${h} ${p}(float itemIndex) {
|
|
8
8
|
${h} itemData;
|
|
9
9
|
float index = itemIndex * ${x};
|
|
10
10
|
float texSize = float(textureSize(${l.name}, 0).x);
|
|
11
11
|
float coordX = mod(index, texSize) + 0.5;
|
|
12
12
|
float coordY = floor(index / texSize) + 0.5;
|
|
13
|
-
`);for(let t=0;t<
|
|
14
|
-
}`),$.code.add(r`${h} ${
|
|
13
|
+
`);for(let t=0;t<g.length;++t)!1!==g[t]&&$.code.add(r`lowp uvec4 texel${r.int(t)} = texelFetch(${l.name}, ivec2(coordX + ${r.float(t)}, coordY), 0);`);for(const t of I)$.code.add(r`itemData.${t.name} = ${a(t)};`);$.code.add(r`return itemData;
|
|
14
|
+
}`),$.code.add(r`${h} ${B};`),$.main.add(r`${B} = ${p}(${s});`)}function s(e){const t=f(e);return e=>r`${t}.${e}`}function f(e){return`${e}ItemData`}export{i as TextureBackedBufferModule};
|
|
@@ -8,4 +8,4 @@ return unpackHalf2x16(halfBits).x;
|
|
|
8
8
|
}`)}function r(t){t.code.add(n`highp float unpackFloat4x8(highp uint bits0, highp uint bits1, highp uint bits2, highp uint bits3) {
|
|
9
9
|
highp uint floatBits = (bits3 << 24u) |(bits2 << 16u) | (bits1 << 8u) | bits0;
|
|
10
10
|
return uintBitsToFloat(floatBits);
|
|
11
|
-
}`)}function
|
|
11
|
+
}`)}function c(t){const{fieldType:e,glslDecodeArgumentString:n}=t;return`${(0,a[e])(n)}`}const a={u8:t=>n`${t}`,unorm8:t=>n`float(${t})/255.0`,vec4unorm8:t=>n`vec4(${t})/255.0`,f16:e?t=>n`unpackHalf2x8(${t})`:t=>n`unpackFloat4x8(${t})`,f32:t=>n`unpackFloat4x8(${t})`,vec4u8:t=>n`uvec4(${t})`};export{c as glslDecodeField,u as glslType,r as unpackFloat4x8,i as unpackHalf2x8};
|
|
@@ -39,22 +39,22 @@ float absCosAngle;
|
|
|
39
39
|
return groundRelative;
|
|
40
40
|
}
|
|
41
41
|
`),u.draped&&!u.hasVerticalOffset||i(v),u.draped||(v.uniforms.add(new f("perDistancePixelRatio",e=>Math.tan(e.camera.fovY/2)/(e.camera.fullViewport[2]/2))),v.code.add(c`
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
void applyHUDVerticalGroundOffset(vec3 normalModel, inout vec3 posModel, inout vec3 posView) {
|
|
43
|
+
float distanceToCamera = length(posView);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// Compute offset in world units for a half pixel shift
|
|
46
|
+
float pixelOffset = distanceToCamera * perDistancePixelRatio * ${c.float(p)};
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Apply offset along normal in the direction away from the ground surface
|
|
49
|
+
vec3 modelOffset = normalModel * aboveGround * pixelOffset;
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// Apply the same offset also on the view space position
|
|
52
|
+
vec3 viewOffset = (viewNormal * vec4(modelOffset, 1.0)).xyz;
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
posModel += modelOffset;
|
|
55
|
+
posView += viewOffset;
|
|
56
|
+
}
|
|
57
|
+
`)),u.screenCenterOffsetUnitsEnabled&&n(v),u.hasScreenSizePerspective&&o(v),v.code.add(c`
|
|
58
58
|
vec4 projectPositionHUD(out ProjectHUDAux aux) {
|
|
59
59
|
vec3 centerOffset = centerOffsetAndDistance.xyz;
|
|
60
60
|
float pointGroundDistance = centerOffsetAndDistance.w;
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{
|
|
5
|
+
import{create as a}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Float3PassUniform as e}from"../../shaderModules/Float3PassUniform.js";import{glsl as i}from"../../shaderModules/glsl.js";import{NoParameters as t}from"../../../../../webgl/NoParameters.js";class o extends t{constructor(){super(...arguments),this.tileCameraPosition=a(),this.cameraDelta=a()}}function n(a){a.code.add(i`vec4 unpackColor(uvec4 packedGaussian) {
|
|
6
6
|
vec4 color;
|
|
7
7
|
color.r = float((packedGaussian.w >> 1u) & 0xfeu);
|
|
8
8
|
color.g = float((packedGaussian.w >> 9u) & 0xffu);
|
|
9
9
|
color.b = float((packedGaussian.w >> 16u) & 0xfeu);
|
|
10
10
|
color.a = float((packedGaussian.w >> 24u) & 0xffu);
|
|
11
11
|
return color / 255.0;
|
|
12
|
-
}`),
|
|
12
|
+
}`),a.code.add(i`vec3 unpackScale(uvec4 packedGaussian) {
|
|
13
13
|
uint sx = (packedGaussian.z >> 10u) & 0xffu;
|
|
14
14
|
uint sy = (packedGaussian.z >> 18u) & 0xffu;
|
|
15
15
|
uint szLow = (packedGaussian.z >> 26u) & 0x3fu;
|
|
16
16
|
uint szHigh = packedGaussian.a & 0x3u;
|
|
17
17
|
uint sz = szLow | (szHigh << 6u);
|
|
18
18
|
return exp(vec3(sx, sy, sz) / 16.0 - 10.0);
|
|
19
|
-
}`),
|
|
19
|
+
}`),a.code.add(i`const uint MASK_9_BITS = 0x1FFu;
|
|
20
20
|
const float SQRT_HALF = 0.7071067811865476;
|
|
21
21
|
const ivec3 COMPONENT_ORDER[4] = ivec3[4](
|
|
22
22
|
ivec3(3, 2, 1),
|
|
@@ -41,7 +41,7 @@ sumSquares += value * value;
|
|
|
41
41
|
}
|
|
42
42
|
quaternion[int(largestComponent)] = sqrt(1.0 - sumSquares);
|
|
43
43
|
return quaternion;
|
|
44
|
-
}`),
|
|
44
|
+
}`),a.code.add(i`vec3 unpackTileOriginRelativePosition(uvec4 packedGaussian) {
|
|
45
45
|
uint packedPositionLow = packedGaussian.y;
|
|
46
46
|
uint packedPositionHigh = packedGaussian.z;
|
|
47
47
|
uint x = packedPositionLow & 0x3FFFu;
|
|
@@ -50,10 +50,10 @@ uint zLow = (packedPositionLow >> 28u) & 0xFu;
|
|
|
50
50
|
uint zHigh = packedPositionHigh & 0x3FFu;
|
|
51
51
|
uint z = zLow | (zHigh << 4u);
|
|
52
52
|
return vec3(float(x), float(y), float(z));
|
|
53
|
-
}`),e.code.add(
|
|
53
|
+
}`),a.uniforms.add(new e("tileCameraPosition",a=>a.tileCameraPosition),new e("cameraDelta",a=>a.cameraDelta)).code.add(i`vec3 unpackCameraRelativeGaussianPosition(uvec4 packedHeader, highp vec3 position) {
|
|
54
54
|
vec3 tileOrigin = uintBitsToFloat(packedHeader.xyz);
|
|
55
55
|
float invPosScale = 1.0 / exp2(float(packedHeader.w & 0xfu));
|
|
56
|
-
vec3 delta = tileOrigin.xyz -
|
|
57
|
-
vec3 cameraRelativePosition = position
|
|
56
|
+
vec3 delta = tileOrigin.xyz - tileCameraPosition;
|
|
57
|
+
vec3 cameraRelativePosition = position * invPosScale + delta * 2.048 - cameraDelta;
|
|
58
58
|
return cameraRelativePosition;
|
|
59
|
-
}`)}export{
|
|
59
|
+
}`)}export{n as GaussianSplatUnpacking,o as GaussianSplatUnpackingPassParameters};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{__decorate as e}from"tslib";import t from"../../../../Color.js";import{disposeMaybe as i}from"../../../../core/maybe.js";import{watch as s,syncAndInitial as o}from"../../../../core/reactiveUtils.js";import{property as r,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{d as a}from"../../../../chunks/vec32.js";import{RenderCategory as n,InternalRenderCategory as u}from"../../webgl.js";import{glLayout as
|
|
5
|
+
import{__decorate as e}from"tslib";import t from"../../../../Color.js";import{disposeMaybe as i}from"../../../../core/maybe.js";import{watch as s,syncAndInitial as o}from"../../../../core/reactiveUtils.js";import{property as r,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{d as a}from"../../../../chunks/vec32.js";import{RenderCategory as n,InternalRenderCategory as u}from"../../webgl.js";import{glLayout as c}from"../../support/buffer/glUtil.js";import{newLayout as h}from"../../support/buffer/InterleavedLayout.js";import m from"../../webgl/RenderNode.js";import{VertexArrayObject as d}from"./VertexArrayObject.js";import{C as f}from"../../../../chunks/CutFillComposition.glsl.js";import{CutFillCompositionTechnique as p}from"../shaders/CutFillCompositionTechnique.js";import{C}from"../../../../chunks/CutFillMask.glsl.js";import{CutFillMaskTechnique as _}from"../shaders/CutFillMaskTechnique.js";import{DefaultMaterialPassParameters as g,DefaultMaterialDrawParameters as b,DefaultMaterialTechnique as T}from"../shaders/DefaultMaterialTechnique.js";import{DefaultMaterialTechniqueConfiguration as q}from"../shaders/DefaultMaterialTechniqueConfiguration.js";import{DepthStencilAttachment as V,PrimitiveType as v}from"../../../webgl/enums.js";import{noParameters as F}from"../../../webgl/NoParameters.js";import{VertexBuffer as w}from"../../../webgl/VertexBuffer.js";let P=class extends m{constructor(e){super(e),this.consumes={required:[n.OPAQUE]},this.produces=u.CUTFILL_COLOR,this.measureType="cut-fill",this._vaoCut=null,this._vaoFill=null,this._countCut=0,this._countFill=0,this._maskParameters=new C,this._cutVolumeParameters=new g,this._fillVolumeParameters=new g,this._compositeParameters=new f,this._drawParameters=new b;const t=1===e.view.state.viewingMode;this._cutVolumeTechniqueConfiguration=new q(t),this._cutVolumeTechniqueConfiguration.customDepthTest=2,this._cutVolumeTechniqueConfiguration.writeDepth=!1,this._cutVolumeTechniqueConfiguration.cullFace=1,this._cutVolumeTechniqueConfiguration.doubleSidedMode=2,this._fillVolumeTechniqueConfiguration=new q(t),this._fillVolumeTechniqueConfiguration.cullFace=2}initialize(){this.addHandles([s(()=>[this.cutColor,this.fillColor],()=>this._updateColors(),o),s(()=>this.measureType,()=>{this.precompile(),this.requestRender(1)},o)])}destroy(){this._vaoCut=i(this._vaoCut),this._vaoFill=i(this._vaoFill)}precompile(){"cut-fill"===this.measureType?(this._cutVolumeTechniqueConfiguration.cullFace=1,this._cutVolumeTechniqueConfiguration.doubleSidedMode=2):(this._cutVolumeTechniqueConfiguration.cullFace=0,this._cutVolumeTechniqueConfiguration.doubleSidedMode=0),this.techniques.precompile(T,this._cutVolumeTechniqueConfiguration),this.techniques.precompile(T,this._fillVolumeTechniqueConfiguration),this.techniques.precompile(_),this.techniques.precompile(p)}render(e){const i=this.techniques.get(T,this._cutVolumeTechniqueConfiguration),s=this.techniques.get(T,this._fillVolumeTechniqueConfiguration),o=this.techniques.get(_),r=this.techniques.get(p),l=e.find(({name:e})=>e===this.produces);if(!this._vaoCut||!this._vaoFill)return l;if(!(i&&s&&o.compiled&&r.compiled))return this.requestRender(1),l;const a=this.bindParameters,n=a.camera,u=n.fullViewport[2],c=n.fullViewport[3],h=this.renderingContext,m=this.fboCache,d=m.acquire(u,c,"cutfill color mask",2);d.attachDepth(l.getAttachment(V)),h.bindFramebuffer(d.fbo),h.setClearColor(0,0,0,1),h.clear(17408),h.setViewport(0,0,u,c),h.bindTechnique(o,a,F,this._maskParameters),h.setFaceCullingEnabled(!1),h.setStencilTestEnabled(!0),h.setStencilOpSeparate(1028,7680,34055,7680),h.setStencilOpSeparate(1029,7680,34056,7680),h.setDepthWriteEnabled(!1),h.bindVAO(this._vaoCut),h.setDepthTestEnabled(!0),h.setStencilWriteMask(255),h.setStencilFunction(519,0,255),h.setColorMask(!1,!1,!1,!1),h.drawArrays(v.TRIANGLES,0,this._countCut),h.setDepthTestEnabled(!1),h.setStencilWriteMask(0),h.setStencilFunction(517,0,255),h.setColorMask(!0,!1,!1,!1),h.drawArrays(v.TRIANGLES,0,this._countCut),h.bindVAO(this._vaoFill),h.setDepthTestEnabled(!0),h.setStencilWriteMask(255),h.setStencilFunction(519,0,255),h.setColorMask(!1,!0,!1,!1),h.drawArrays(v.TRIANGLES,0,this._countFill);const f=m.acquire(u,c,"cutfill color volumes",5);f.attachDepth(l.getAttachment(V)),h.bindFramebuffer(f.fbo),h.setClearColor(0,0,0,0),h.clear(16384),h.setColorMask(!0,!0,!0,!0),h.bindTechnique(i,this.bindParameters,this._cutVolumeParameters,this._drawParameters),h.setPolygonOffset(1,1),h.setPolygonOffsetFillEnabled(!0),h.bindVAO(this._vaoCut),h.drawArrays(v.TRIANGLES,0,this._countCut),h.bindTechnique(s,this.bindParameters,this._fillVolumeParameters,this._drawParameters),h.setPolygonOffset(0,0),h.setPolygonOffsetFillEnabled(!1),h.bindVAO(this._vaoFill),h.drawArrays(v.TRIANGLES,0,this._countFill);const C=this.fboCache.acquire(u,c,this.produces);return h.bindFramebuffer(C.fbo),this._compositeParameters.color=l.getTexture(),this._compositeParameters.cutFillVolumes=f.getTexture(),this._compositeParameters.cutFillMask=d.getTexture(),t.toUnitRGBA(this.borderColor,this._compositeParameters.borderColor),h.bindTechnique(r,a,this._compositeParameters),h.screen.draw(),d.release(),f.release(),C.attachDepth(l.getAttachment(V)),C}enable(){this.produces=u.CUTFILL_COLOR,this.requestRender(1)}disable(){this.produces="disabled",this.requestRender(1)}updateGeometries(e,t,s){this._vaoCut=i(this._vaoCut),this._vaoCut=this._createVao(e),this._countCut=e.indicesBottom.length+e.indicesExtruded.length,this._vaoFill=i(this._vaoFill),this._vaoFill=this._createVao(t),this._countFill=t.indicesBottom.length+t.indicesExtruded.length,this._maskParameters.origin=s,a(this._drawParameters.origin,s),this.requestRender(1)}_updateColors(){this._cutVolumeParameters.diffuse=t.toUnitRGB(this.cutColor),this._cutVolumeParameters.opacity=this.cutColor.a,this._fillVolumeParameters.diffuse=t.toUnitRGB(this.fillColor),this._fillVolumeParameters.opacity=this.fillColor.a,this.requestRender(1)}_createVao(e){const t=this.renderingContext,{vertices:i,normals:s,indicesBottom:o,indicesExtruded:r}=e,l=y.createBuffer(o.length+r.length),{position:a,normal:n}=l;for(let c=0;c<o.length;c++){const e=3*o[c];a.set(c,0,i[e]),a.set(c,1,i[e+1]),a.set(c,2,i[e+2]),n.set(c,0,s[e]),n.set(c,1,s[e+1]),n.set(c,2,s[e+2])}for(let c=0;c<r.length;c++){const e=c+o.length,t=3*r[c];a.set(e,0,i[t]),a.set(e,1,i[t+1]),a.set(e,2,i[t+2]),n.set(e,0,s[t]),n.set(e,1,s[t+1]),n.set(e,2,s[t+2])}const u=new w(t,c(y),l.buffer);return new d(t,u)}};e([r()],P.prototype,"consumes",void 0),e([r()],P.prototype,"produces",void 0),e([r()],P.prototype,"cutColor",void 0),e([r()],P.prototype,"fillColor",void 0),e([r()],P.prototype,"borderColor",void 0),e([r()],P.prototype,"measureType",void 0),P=e([l("esri.views.3d.webgl-engine.lib.CutFillColor")],P);const y=h().vec3f("position").vec3f("normal").freeze();class j{constructor(e,t,i,s){this.vertices=e,this.indicesBottom=t,this.indicesExtruded=i,this.normals=s}}export{P as CutFillColor,j as VolumeGeometry};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{__decorate as t}from"tslib";import{watch as e}from"../../../../core/reactiveUtils.js";import{property as s,subclass as i}from"../../../../core/accessorSupport/decorators.js";import{set as a}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{
|
|
5
|
+
import{__decorate as t}from"tslib";import{watch as e}from"../../../../core/reactiveUtils.js";import{property as s,subclass as i}from"../../../../core/accessorSupport/decorators.js";import{set as a}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{e as r,b as n,j as o,q as h,g as l,E as p,d as m,J as u}from"../../../../chunks/vec32.js";import{create as c,clone as d}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{c as f}from"../../../../chunks/vec42.js";import{create as _}from"../../../../geometry/support/plane.js";import{fromPoints as g}from"../../../../geometry/support/ray.js";import{Sphere as P}from"../../../../geometry/support/sphere.js";import{RenderCategory as b}from"../../webgl.js";import{GaussianSplatTarget as C}from"../../layers/i3s/Intersector.js";import{GaussianSplatDataStore as v}from"../../support/gaussianSplatting/GaussianSplatDataStore.js";import w from"../../webgl/RenderNode.js";import{IntersectorResult as y}from"./IntersectorResult.js";import{G as S}from"../../../../chunks/GaussianSplat.glsl.js";import{G as x}from"../../../../chunks/GaussianSplatComposition.glsl.js";import{GaussianSplatCompositionTechnique as q}from"../shaders/GaussianSplatCompositionTechnique.js";import{G as T}from"../../../../chunks/GaussianSplatDepthComposition.glsl.js";import{GaussianSplatDepthCompositionTechnique as j}from"../shaders/GaussianSplatDepthCompositionTechnique.js";import{GaussianSplatDepthTechnique as D}from"../shaders/GaussianSplatDepthTechnique.js";import{GaussianSplatTechnique as G}from"../shaders/GaussianSplatTechnique.js";import{GaussianSplatTechniqueConfiguration as A}from"../shaders/GaussianSplatTechniqueConfiguration.js";import{DepthStencilAttachment as R,PrimitiveType as E}from"../../../webgl/enums.js";var F;let H=class extends w{static{F=this}constructor(t){super(t),this.gaussianPosition=c(),this.intersectionRayDir=c(),this.intersectionPlane=_(),this._slicePlaneEnabled=!1,this._data=null,this.produces=b.OPAQUE,this.type=0,this.isGround=!1,this.layerViewUid="",this._passParameters=new S,this._compositionPassParameters=new x,this._depthCompositionPassParameters=new T,this._previousCameraPosition=c(),this._previousCameraDirection=c(),this.fadeHelper=null,this._configuration=new A(t.view.state.isGlobal),this._depthConfiguration=new A(t.view.state.isGlobal,!0)}async initialize(){this._data=new v(this),this.view.sceneIntersectionHelper.addIntersectionHandler(this),this.addHandles([e(()=>this.view.state.camera,()=>this._onCameraChange())])}precompile(){this._configuration.alphaCutoff=this.view.qualitySettings.gaussianSplat.minimumOpacity,this._configuration.terrainDepthTest=this.bindParameters.terrainDepthTest,this._configuration.fadingEnabled=this.fadeHelper.fadingEnabled,this.techniques.precompile(G,this._configuration),this._depthConfiguration.alphaCutoff=this.view.qualitySettings.gaussianSplat.minimumOpacity,this._depthConfiguration.terrainDepthTest=this.bindParameters.terrainDepthTest,this.techniques.precompile(D,this._depthConfiguration),this.techniques.precompile(q),this.techniques.precompile(j)}render(t){const e=t.find(({name:t})=>t===b.OPAQUE);if(this._handleFading(),!this._data.visibleGaussians||!this._data.orderTexture.texture||!this._data.textureAtlas.texture)return e;const s=this.techniques.get(G,this._configuration),i=this.techniques.get(D,this._depthConfiguration),r=this.techniques.get(q),n=this.techniques.get(j);if(!(s.compiled&&i.compiled&&n.compiled&&r.compiled))return this.requestRender(1),e;const{fullWidth:o,fullHeight:h}=this.bindParameters.camera,l=this.fboCache,p=l.acquire(o,h,"gaussian color output");p.attachDepth(e.getAttachment(R));const m=this.renderingContext;m.bindFramebuffer(p.fbo),m.setClearColor(0,0,0,0),m.clear(16384),this._passParameters.totalGaussians=this._data.visibleGaussians,this._passParameters.splatOrder=this._data.orderTexture.texture,this._passParameters.splatFading=this._data.fadingTexture.texture,this._passParameters.splatAtlas=this._data.textureAtlas.texture;const u=Math.tan(.5*this.camera.fovY),c=u/h*o;a(this._passParameters.tanFov,c,u),this._passParameters.focalLength=h/(2*u);const d=this.view.qualitySettings.gaussianSplat.minimumSplatPixelRadius;this._passParameters.minSplatRadius=d*Math.sqrt(o*h)/Math.sqrt(2073600),this._prepareHighPrecisionCameraPosition(),this.renderingContext.bindTechnique(s,this.bindParameters,this._passParameters),this.renderingContext.drawArraysInstanced(E.TRIANGLE_STRIP,0,4,this._data.visibleGaussians);const f=l.acquire(o,h,"splat depth",8);f.attachDepth(e.getAttachment(R)),m.bindFramebuffer(f.fbo),m.setClearColor(0,0,0,0),m.clear(16384),this.renderingContext.bindTechnique(i,this.bindParameters,this._passParameters),this.renderingContext.drawArraysInstanced(E.TRIANGLE_STRIP,0,4,this._data.visibleGaussians);const _=l.acquire(o,h,this.produces);return this._depthCompositionPassParameters.splatDepth=f.getTexture(),_.attachDepth(e.getAttachment(R)),m.bindFramebuffer(_.fbo),m.bindTechnique(n,this.bindParameters,this._depthCompositionPassParameters),m.screen.draw(),this._compositionPassParameters.color=e.getTexture(),this._compositionPassParameters.splatColor=p.getTexture(),m.bindFramebuffer(_.fbo),m.bindTechnique(r,this.bindParameters,this._compositionPassParameters),m.screen.draw(),p.release(),f.release(),_}intersect(t,e,s,i){const{gaussianPosition:a,intersectionRayDir:m,intersectionPlane:u,layerViewUid:_}=this,b=g(s,i);r(m,i,s);const v=1/n(m);o(m,m,v);const w=c();h(w,m),f(u,m[0],m[1],m[2],-l(m,s));const S=new M,x=new M,q=new Array;this._data.visibleGaussianTiles.forEach(r=>{const{maxScale:n}=r,o=r.obb.minimumDistancePlane(u),h=r.obb.maximumDistancePlane(u),c=h<0,f=null!=S.dist&&null!=x.dist&&S.dist<o*v&&x.dist>h*v;if(c||f)return;if(!new P(r.obb.center,r.obb.radius+n).intersectRay(b,null))return;if(!r.obb.intersectRay(s,m,n))return;const{positions:g,squaredScales:C,gaussianAtlasIndices:y}=r,T=y.length;for(let u=0;u<T;u++){const r=3*u;a[0]=g[r]-s[0],a[1]=g[r+1]-s[1],a[2]=g[r+2]-s[2];const n=C[u],o=l(a,m),h=o*o;if(p(a)-h>n)continue;const c=o*v,f=t=>(t.point=t.point?t.point.fill(a[0],a[1],a[2]):d(a),t.dist=c,t.normal=w,t.layerViewUid=_,t);if((null==S.dist||c<S.dist)&&(null==e||e(s,i,c))&&f(S),0!==t.options.store&&(null==x.dist||c>x.dist)&&(null==e||e(s,i,c))&&f(x),2===t.options.store&&(null==e||e(s,i,c))){const t=new M;q.push(f(t))}}});const T=(t,e)=>{const{layerViewUid:s}=e,i=new C(e.point,s);t.set(0,i,e.dist,e.normal)};if(I(S)){const e=t.results.min;(null==e.distance||S.dist<e.distance)&&T(e,S)}if(I(x)&&0!==t.options.store){const e=t.results.max;(null==e.distance||x.dist>e.distance)&&T(e,x)}if(2===t.options.store)for(const r of q){const e=new y(b);T(e,r),t.results.all.push(e)}}get slicePlaneEnabled(){return this._slicePlaneEnabled}set slicePlaneEnabled(t){this._slicePlaneEnabled!==t&&(this._slicePlaneEnabled=t,this.requestRender(1))}get data(){return this._data}destroy(){this._data.destroy(),super.destroy()}_onCameraChange(){const t=this.view.state.camera.eye,e=this.view.state.camera.ray.direction,s=.001;(Math.abs(t[0]-this._previousCameraPosition[0])>s||Math.abs(t[1]-this._previousCameraPosition[1])>s||Math.abs(t[2]-this._previousCameraPosition[2])>s||Math.abs(e[0]-this._previousCameraDirection[0])>s||Math.abs(e[1]-this._previousCameraDirection[1])>s||Math.abs(e[2]-this._previousCameraDirection[2])>s)&&(m(this._previousCameraPosition,t),m(this._previousCameraDirection,e),this._data.requestSort())}_prepareHighPrecisionCameraPosition(){o(this._passParameters.tileCameraPosition,this.camera.eye,1/F.tileSize),u(this._passParameters.tileCameraPosition,this._passParameters.tileCameraPosition),o(this._passParameters.cameraDelta,this._passParameters.tileCameraPosition,F.tileSize),r(this._passParameters.cameraDelta,this.camera.eye,this._passParameters.cameraDelta)}_handleFading(){if(0===this.fadeHelper.numFadingTiles)return void(this._previousFrameStart=null);this._previousFrameStart??=this.view.stage.renderer.renderContext.time;const t=this.view.stage?.renderer.renderContext.time-this._previousFrameStart;this.fadeHelper.updateAllTileFading(t),this._previousFrameStart=this.view.stage.renderer.renderContext.time,this._data.fadingTexture.updateTexture(this._data.textureAtlas.pageAllocator.pageCount)}static{this.tileSize=2.048}};function I(t){return null!=t.dist&&null!=t.point}t([s({constructOnly:!0})],H.prototype,"fadeHelper",void 0),H=F=t([i("esri.views.3d.webgl-engine.lib.GaussianSplatRenderNode")],H);class M{constructor(){this.point=null,this.dist=null,this.normal=null,this.layerViewUid=""}}export{H as GaussianSplatRenderNode};
|