@arcgis/core 5.0.0-next.17 → 5.0.0-next.18

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.
Files changed (95) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/{adf7ccf4ef629211c7ee.js → 08aacbfb651cc2e1c054.js} +1 -1
  3. package/assets/esri/core/workers/chunks/{658cd45b5fb304fd840a.js → 3aa77696c5ea54a238da.js} +1 -1
  4. package/assets/esri/core/workers/chunks/{49571d6875de1f2e7e25.js → 4b9dfdc23ba3d6ebcc1b.js} +2 -2
  5. package/assets/esri/core/workers/chunks/{888f188541f8bd68e33e.js → 72f1c3d97e7b9546c113.js} +1 -1
  6. package/assets/esri/core/workers/chunks/{a4518f25b9f8fe704286.js → 76e945da8f30d8641c3d.js} +4 -4
  7. package/chunks/ImageMaterial.glsl.js +1 -1
  8. package/config.js +1 -1
  9. package/interfaces.d.ts +47 -28
  10. package/intl/locale.js +1 -1
  11. package/kernel.js +1 -1
  12. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  13. package/package.json +1 -1
  14. package/support/revision.js +1 -1
  15. package/views/2d/LabelManager.js +1 -1
  16. package/views/2d/engine/webgl/FeatureTile.js +1 -1
  17. package/views/2d/engine/webgl/OverlayMultipoint.js +1 -1
  18. package/views/2d/engine/webgl/VideoScreenRenderer.js +1 -1
  19. package/views/2d/engine/webgl/animations/store/AnimationStore.js +1 -1
  20. package/views/2d/engine/webgl/shaderGraph/techniques/colorize/ColorizeTechnique.js +1 -1
  21. package/views/2d/engine/webgl/shaderGraph/techniques/dotDensity/DotDensityResources.js +1 -1
  22. package/views/2d/engine/webgl/shaderGraph/techniques/drop-shadow/DropShadowTechnique.js +1 -1
  23. package/views/2d/engine/webgl/shaderGraph/techniques/opacity/OpacityTechnique.js +1 -1
  24. package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterColorizerTechnique.js +1 -1
  25. package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterHighlightTechnique.js +1 -1
  26. package/views/2d/engine/webgl/textureUtils.js +1 -1
  27. package/views/2d/layers/features/FeatureContainer.js +1 -1
  28. package/views/3d/GroundView3D.js +1 -1
  29. package/views/3d/analysis/Dimension/LengthDimensionSubTool.js +1 -1
  30. package/views/3d/analysis/Slice/RotateManipulator.js +1 -1
  31. package/views/3d/analysis/images/Factory.js +1 -1
  32. package/views/3d/environment/ChapmanAtmosphere.js +1 -1
  33. package/views/3d/environment/EnvironmentManager.js +1 -1
  34. package/views/3d/layers/BuildingComponentSublayerView3D.js +1 -1
  35. package/views/3d/layers/DrapedSubView3D.js +1 -1
  36. package/views/3d/layers/FlowSubView3D.js +1 -1
  37. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  38. package/views/3d/layers/IntegratedMeshLayerView3D.js +1 -1
  39. package/views/3d/layers/MediaLayerView3D.js +1 -1
  40. package/views/3d/layers/PointCloudLayerView3D.js +1 -1
  41. package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
  42. package/views/3d/layers/SceneLayerView3D.js +1 -1
  43. package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
  44. package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
  45. package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
  46. package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
  47. package/views/3d/layers/graphics/pipeline/rendering/FeaturePipelineRenderManager.js +1 -1
  48. package/views/3d/layers/graphics/wosrLoader.js +1 -1
  49. package/views/3d/layers/i3s/I3SMaterialUtil.js +1 -1
  50. package/views/3d/support/QualityProfile.js +5 -0
  51. package/views/3d/support/QualitySettings.js +1 -1
  52. package/views/3d/support/StreamTextureCollection.js +1 -1
  53. package/views/3d/support/TextureCollection.js +1 -1
  54. package/views/3d/support/engineContent/marker.js +1 -1
  55. package/views/3d/support/engineContent/sdfPrimitives.js +1 -1
  56. package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +1 -1
  57. package/views/3d/terrain/OverlayRenderer.js +1 -1
  58. package/views/3d/terrain/TerrainSurface.js +1 -1
  59. package/views/3d/terrain/TileCompositor.js +1 -1
  60. package/views/3d/webgl-engine/Stage.js +1 -1
  61. package/views/3d/webgl-engine/collections/Component/ComponentObjectCollection.js +1 -1
  62. package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
  63. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  64. package/views/3d/webgl-engine/core/material/MaterialBase.js +1 -1
  65. package/views/3d/webgl-engine/core/material/RenderTexture.js +1 -1
  66. package/views/3d/webgl-engine/effects/haze/Haze.js +1 -1
  67. package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
  68. package/views/3d/webgl-engine/effects/ssao/SSAO.js +1 -1
  69. package/views/3d/webgl-engine/lib/AnimationTimeStep.js +1 -1
  70. package/views/3d/webgl-engine/lib/BasisUtil.js +1 -1
  71. package/views/3d/webgl-engine/lib/DDSUtil.js +1 -1
  72. package/views/3d/webgl-engine/lib/GLTextureMaterial.js +1 -1
  73. package/views/3d/webgl-engine/lib/ManagedTexture.js +5 -0
  74. package/views/3d/webgl-engine/lib/OrderIndependentTransparency.js +1 -1
  75. package/views/3d/webgl-engine/lib/RenderFeature.js +1 -1
  76. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  77. package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
  78. package/views/3d/webgl-engine/lib/TextTextureFactory.js +1 -1
  79. package/views/3d/webgl-engine/lib/TextureRepository.js +1 -1
  80. package/views/3d/webgl-engine/lib/glUtil3D.js +1 -1
  81. package/views/3d/webgl-engine/materials/ImageMaterial.js +1 -1
  82. package/views/3d/webgl-engine/materials/internal/WaterTextureRepository.js +1 -1
  83. package/views/3d/webgl-engine/materials/stippleTextureRepository.js +1 -1
  84. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  85. package/views/GroundView.js +1 -1
  86. package/views/SceneView.js +1 -1
  87. package/views/support/layerViewUtils.js +1 -1
  88. package/views/webgl/Texture.js +1 -1
  89. package/views/webgl/testSVGPremultipliedAlpha.js +1 -1
  90. package/widgets/FeatureForm/FeatureFormUtilityNetworkAssociations/FeatureFormUtilityNetworkAssociationList.js +1 -1
  91. package/widgets/FeatureForm/FeatureFormUtilityNetworkAssociations/UtilityNetworkAssociationSettings.js +1 -1
  92. package/widgets/support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js +1 -1
  93. package/views/3d/support/DisplayQualityProfile.js +0 -5
  94. package/views/3d/webgl-engine/lib/Texture.js +0 -5
  95. /package/views/3d/webgl-engine/lib/{ITexture.js → IManagedTexture.js} +0 -0
@@ -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 y,sync as f,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/unitUtils.js";import{property as w}from"../../../core/accessorSupport/decorators/property.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{q as C,j as b,d as x}from"../../../chunks/vec32.js";import{create as E}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as U}from"../../../geometry/ellipsoidUtils.js";import M from"../../../geometry/SpatialReference.js";import{getProjector as j}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as R}from"../../../geometry/projection/projectVectorToVector.js";import{create as B,equals as I,intersection as k,intersectsSphere as V,empty as A,expand as O}from"../../../geometry/support/aaBoundingRect.js";import{copy as N,create as G}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as q}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{m as W,c as H,n as $,o as z,e as Q}from"../../../chunks/sphere.js";import{ElevationQueryTileCache as Y}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as X}from"../../../layers/support/layerUtils.js";import{debugFlags as K}from"../support/debugFlags.js";import{ElevationRange as J}from"../support/ElevationRange.js";import{toBoundingRect as Z}from"../support/extentUtils.js";import{updatingProgress as ee}from"../support/updatingProperties.js";import{ElevationBounds as te}from"./ElevationBounds.js";import{ElevationData as ie,sampleElevation as re}from"./ElevationData.js";import{ElevationUpdateEventImplementation as se}from"./ElevationUpdateEvent.js";import{create as ae}from"./ExtentHelper.js";import{LayerClasses as ne}from"./LayerClass.js";import{OverlayManager as le}from"./OverlayManager.js";import{PlanarPatch as oe}from"./PlanarPatch.js";import{Queue as he}from"./Queue.js";import{ScaleRangeQueries as de}from"./ScaleRangeQueries.js";import{SphericalPatch as pe}from"./SphericalPatch.js";import{SplitLimits as ue}from"./SplitLimits.js";import{maxRootTiles as ce,tooManyRootTilesAfterChangeError as ge,tooManyRootTilesForLayerError as me,maxTileNeighborLevelDelta as _e,maxMemoryLodBias as ye}from"./TerrainConst.js";import{TerrainRenderer as fe}from"./TerrainRenderer.js";import Te from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ve,isVectorTileLayerView as we,neighborEdgeIndices as Se,internalAssert as Ce,oppositeEdge as be,isSurfaceLayerView as xe,isGroupLayerView as Ee,isMapTileLayerView as Le,isBlendableLayerView as Pe,isElevationLayerView as Ue,releaseTerrainData as Me,enableTerrainInternalChecks as je,oppositeCorner as De,enableWaterproofTests as Re,enableInternalTerrainChecks as Be,enableTerrainWaterproofChecks as Ie,neighborCornerIndices as ke}from"./terrainUtils.js";import{Tile as Ve,lijEquals as Ae}from"./Tile.js";import{printAllocations as Oe}from"./TilePerLayerInfo.js";import{sortTiles as Ne,IteratorPreorder as Ge,IteratorPostorder as qe,compareTilesByLij as Fe,hasLoadableSiblings as We,sortTilesByPOI as He}from"./tileUtils.js";import{TilingSchemeLogic as $e}from"./TilingSchemeLogic.js";import{UpsampleInfo as ze}from"./UpsampleInfo.js";import{isCompositeBlendMode as Qe,blendModeFromString as Ye}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as Xe}from"../../support/layerViewUtils.js";import{ImmediateTask as Ke,TaskPriority as Je,noBudget as Ze}from"../../support/Scheduler.js";import{TextureCompressionTracker as et}from"../../support/TextureCompressionTracker.js";import{Yield as tt}from"../../support/Yield.js";var it;let rt=class extends n{static{it=this}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ne(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 et,this._iteratorPool=new p(()=>new Ge,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new qe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new Te,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=E(),this._eyePosSurfaceSR=E(),this._splitLimits=new ue,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Ke,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new ze),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=B(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=M.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new te(1/0,-1/0),this.rootTileElevationBounds=new te(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 le({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?pe:oe,this._ellipsoid=P(t.spatialReference),this._renderer=new fe(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),Xe()||(this._scaleRangeQueries=new de)}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 Y(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)},y),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),y),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},f),_(()=>this.snapLevel,()=>this._viewChanged=!0,f),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:C})}),_(()=>K.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&K.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=ae(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 $e({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(Je.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),f),_(()=>this.extent,()=>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(),y),_(()=>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(),f)]),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=Ke,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(),Ve.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),Oe(),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=B(),r=Z(t,i,e)?i:null,s=this._get("extent");return I(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=k(this.groundExtent,this._userClippingExtent,B()),t=this._get("extent");return I(e,t)?t:e}get groundExtent(){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=j(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(at,e,t,i);a(n,0,n,0);return pt(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,pt(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,at,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(at)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;at[0]>t[2]&&(i+=1),at[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=j(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationBounds(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;W(e,nt);const r=$(nt,E());i(r,0,r,0),z(nt,r);const s=new J,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!V(i.extent,nt))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return this.enabled&&null!=this._rootTiles?new J(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationBounds.min)*U;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,yt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;Q(nt,yt,t);let i=null;const r=e=>{if(e&&V(e.extent,nt)){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;ve(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??M.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(it._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{extent:e,tilingScheme:t}=this;if(!t)return;const i=lt;let s=t.rootTilesInExtent(e,i,5*ce);if(null!=this._rootTiles){if(s.length>ce)return void l.getLogger(this).warn(ge);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,Ae);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>Ae(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>ce&&(l.getLogger(this).warn(me),s=t.rootTilesInExtent(e,i,ce)),this._setRootTiles(s.map(e=>this._newRootTile(e)));I(i,this._rootTilesExtent)||(this._rootTilesExtent=B(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(Fe),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(Fe);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._updateRootTileElevationBounds(),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.extent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=We(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty();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.min!==r||i.max!==s)&&(this.visibleElevationBounds=new te(r,s))}_updateRootTileElevationBounds(){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.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new te(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=N(this._splitLimits.frustum??G(),t.frustum):this._splitLimits.frustum=null,x(this._eyePosRenderSR,t.eye),R(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(we)&&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=ht.extent;A(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>O(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),ht.spatialReference=this.spatialReference,this.emit("elevation-change",ht),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"),je&&this._checkTileInvariant(),!e.hasProgressed)return tt}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(ve(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(ve(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){ve(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)ve(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<=_e;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${_e} (edge[${i}])`),ve(r,`tile level delta [${t.level}] vs [${e.level}] > ${_e}`))}ve(t.level-e.level<=_e,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-_e,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(Se[i],s);if(null!=a){if(t.leaf&&t.level>=_e){let i=a;for(;t.level-i.level<_e;)i=i.parent;const s=[r,t.lij[1]>>_e,t.lij[2]>>_e];if(!Ae(s,i.lij)){const r=e.get(i);ve(!r.has(t),"Cannot already have neighbor"),r.add(t)}}ve(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),ve(t.level-a.level<=_e,`Tile level delta [${t.level}] vs [${a.level}] > ${_e}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);ve(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 he(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?ut(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||(He(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){Ce(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(Fe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Ce(r.loaded),Ce(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=ke[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(De(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(be(Se[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(Ce(e.has(t)||Fe(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,je&&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>=_e){const e=e=>e.leaf||i-e.level<_e;for(let r=0;r<4;++r){const a=s.findNeighborTile(Se[r],e);null!=a&&i-a.level===_e&&(t=!1,je&&(Ce(a.leaf),Ce(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._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(){const e=this.view.quality;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ye}_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?gt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(it._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){ve(e.leaf,"Tile that is already split should not be split again!"),ve(e.rendered,"Tile marked to split is not rendered"),gt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),ve(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=>ut(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){dt.spatialReference=this.spatialReference,dt.extent=e.extent,dt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",dt)}createTile(e,t,i,r){ve(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){ve(!e.hasPendingUpdate(1),"_mergeTile sanity check"),ve(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),ve(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),ut(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=Ze){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),xe(e)||Ee(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ee(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(Le(e)&&!X(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Pe(e)||Ee(e))&&Qe(Ye[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Ue(e)?0:1}_registerTiledLayerView(e){const t=[];if((Pe(e)||Ee(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Ee(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||!xe(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 ne){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._updateRootTileElevationBounds()}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(){this._allTilesDirty=!0}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||we(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?Ue(i)?this._requestElevationTileData(e,i,r):Promise.reject():Le(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 ie(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._updateRootTileElevationBounds(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Me(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)?Me(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 Me(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 visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=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){Be(e)}enableWaterproofnessChecks(e){Ie(e)}static cleanupTerrainSurface(){ot.prune()}enable(e){e!==this.enabled&&(e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this._set("enabled",e),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],rt.prototype,"_renderer",void 0),e([w({constructOnly:!0})],rt.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],rt.prototype,"view",void 0),e([w({constructOnly:!0})],rt.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],rt.prototype,"terrainTextureCompressionTracker",void 0),e([w()],rt.prototype,"_hasPendingUpdates",void 0),e([w()],rt.prototype,"_asyncWorkItems",void 0),e([w()],rt.prototype,"_allTilesDirty",void 0),e([w()],rt.prototype,"_allTilesSorted",void 0),e([w()],rt.prototype,"_viewChanged",void 0),e([w({type:Number})],rt.prototype,"heading",void 0),e([w()],rt.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],rt.prototype,"_watchUpdatingTracking",void 0),e([w()],rt.prototype,"_frameTask",void 0),e([w()],rt.prototype,"demResolution",null),e([w({readOnly:!0})],rt.prototype,"snapLevel",null),e([w({readOnly:!0})],rt.prototype,"lodSnappingEnabled",null),e([w()],rt.prototype,"_userClippingExtent",null),e([w()],rt.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],rt.prototype,"extent",null),e([w({readOnly:!0})],rt.prototype,"groundExtent",null),e([w({readOnly:!0})],rt.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],rt.prototype,"updating",null),e([w({readOnly:!0})],rt.prototype,"readyToRun",null),e([w(ee)],rt.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],rt.prototype,"updatingProgressValue",null),e([w()],rt.prototype,"_maxNumUpdating",void 0),e([w()],rt.prototype,"baseOpacity",null),e([w()],rt.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],rt.prototype,"viewingMode",null),e([w()],rt.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],rt.prototype,"ready",null),e([w({readOnly:!0})],rt.prototype,"rootTiles",null),e([w()],rt.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],rt.prototype,"spatialReference",null),e([w({type:t})],rt.prototype,"backgroundColor",null),e([w({value:!1})],rt.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],rt.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],rt.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],rt.prototype,"tilingSchemeLogic",void 0),e([w()],rt.prototype,"wireframe",null),e([w({value:!1})],rt.prototype,"suspended",null),e([w()],rt.prototype,"fadeDuration",null),e([w()],rt.prototype,"_xNormalizer",null),e([w()],rt.prototype,"visibleElevationBounds",void 0),e([w()],rt.prototype,"rootTileElevationBounds",void 0),e([w()],rt.prototype,"_layerViewsDirty",void 0),e([w()],rt.prototype,"renderPatchBorders",null),e([w()],rt.prototype,"visualizeNormals",null),e([w()],rt.prototype,"renderingDisabled",null),e([w({readOnly:!0})],rt.prototype,"enabled",void 0),rt=it=e([S("esri.views.3d.terrain.TerrainSurface")],rt);const st=rt,at=E(),nt=H(),lt=B(),ot=new u,ht=new se("ground"),dt={spatialReference:null,extent:null,scale:0};function pt(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 re(t,i,s)}return null}function ut(e,t){!e.leaf||e.level<_e||_t(e,e=>{t&&ct(e);const i=mt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=mt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function ct(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<_e||_t(e,e=>{ct(e)})}function gt(e){e.level<_e||_t(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,mt(t));)t=t.parent}})}function mt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function _t(e,t){if(e.level<_e)return;const i=e.level-_e,r=e.lij[1]>>_e,s=e.lij[2]>>_e,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(Se[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}const yt=E();export{st 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 y,sync as f,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/unitUtils.js";import{property as w}from"../../../core/accessorSupport/decorators/property.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{q as C,j as b,d as x}from"../../../chunks/vec32.js";import{create as E}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as U}from"../../../geometry/ellipsoidUtils.js";import M from"../../../geometry/SpatialReference.js";import{getProjector as j}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as R}from"../../../geometry/projection/projectVectorToVector.js";import{create as B,equals as I,intersection as k,intersectsSphere as V,empty as A,expand as O}from"../../../geometry/support/aaBoundingRect.js";import{copy as N,create as G}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as q}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{m as W,c as H,n as $,o as z,e as Q}from"../../../chunks/sphere.js";import{ElevationQueryTileCache as Y}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as X}from"../../../layers/support/layerUtils.js";import{debugFlags as K}from"../support/debugFlags.js";import{ElevationRange as J}from"../support/ElevationRange.js";import{toBoundingRect as Z}from"../support/extentUtils.js";import{updatingProgress as ee}from"../support/updatingProperties.js";import{ElevationBounds as te}from"./ElevationBounds.js";import{ElevationData as ie,sampleElevation as re}from"./ElevationData.js";import{ElevationUpdateEventImplementation as se}from"./ElevationUpdateEvent.js";import{create as ae}from"./ExtentHelper.js";import{LayerClasses as ne}from"./LayerClass.js";import{OverlayManager as le}from"./OverlayManager.js";import{PlanarPatch as oe}from"./PlanarPatch.js";import{Queue as he}from"./Queue.js";import{ScaleRangeQueries as de}from"./ScaleRangeQueries.js";import{SphericalPatch as pe}from"./SphericalPatch.js";import{SplitLimits as ue}from"./SplitLimits.js";import{maxRootTiles as ce,tooManyRootTilesAfterChangeError as ge,tooManyRootTilesForLayerError as me,maxTileNeighborLevelDelta as _e,maxMemoryLodBias as ye}from"./TerrainConst.js";import{TerrainRenderer as fe}from"./TerrainRenderer.js";import Te from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ve,isVectorTileLayerView as we,neighborEdgeIndices as Se,internalAssert as Ce,oppositeEdge as be,isSurfaceLayerView as xe,isGroupLayerView as Ee,isMapTileLayerView as Le,isBlendableLayerView as Pe,isElevationLayerView as Ue,releaseTerrainData as Me,enableTerrainInternalChecks as je,oppositeCorner as De,enableWaterproofTests as Re,enableInternalTerrainChecks as Be,enableTerrainWaterproofChecks as Ie,neighborCornerIndices as ke}from"./terrainUtils.js";import{Tile as Ve,lijEquals as Ae}from"./Tile.js";import{printAllocations as Oe}from"./TilePerLayerInfo.js";import{sortTiles as Ne,IteratorPreorder as Ge,IteratorPostorder as qe,compareTilesByLij as Fe,hasLoadableSiblings as We,sortTilesByPOI as He}from"./tileUtils.js";import{TilingSchemeLogic as $e}from"./TilingSchemeLogic.js";import{UpsampleInfo as ze}from"./UpsampleInfo.js";import{isCompositeBlendMode as Qe,blendModeFromString as Ye}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as Xe}from"../../support/layerViewUtils.js";import{ImmediateTask as Ke,TaskPriority as Je,noBudget as Ze}from"../../support/Scheduler.js";import{TextureCompressionTracker as et}from"../../support/TextureCompressionTracker.js";import{Yield as tt}from"../../support/Yield.js";var it;let rt=class extends n{static{it=this}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ne(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 et,this._iteratorPool=new p(()=>new Ge,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new qe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new Te,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=E(),this._eyePosSurfaceSR=E(),this._splitLimits=new ue,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Ke,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new ze),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=B(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=M.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new te(1/0,-1/0),this.rootTileElevationBounds=new te(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 le({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?pe:oe,this._ellipsoid=P(t.spatialReference),this._renderer=new fe(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),Xe()||(this._scaleRangeQueries=new de)}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 Y(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)},y),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),y),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},f),_(()=>this.snapLevel,()=>this._viewChanged=!0,f),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:C})}),_(()=>K.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&K.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=ae(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 $e({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(Je.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),f),_(()=>this.extent,()=>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(),y),_(()=>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(),f)]),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=Ke,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(),Ve.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),Oe(),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=B(),r=Z(t,i,e)?i:null,s=this._get("extent");return I(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=k(this.groundExtent,this._userClippingExtent,B()),t=this._get("extent");return I(e,t)?t:e}get groundExtent(){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=j(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(at,e,t,i);a(n,0,n,0);return pt(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,pt(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,at,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(at)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;at[0]>t[2]&&(i+=1),at[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=j(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationBounds(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;W(e,nt);const r=$(nt,E());i(r,0,r,0),z(nt,r);const s=new J,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!V(i.extent,nt))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return this.enabled&&null!=this._rootTiles?new J(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationBounds.min)*U;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,yt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;Q(nt,yt,t);let i=null;const r=e=>{if(e&&V(e.extent,nt)){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;ve(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??M.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(it._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{extent:e,tilingScheme:t}=this;if(!t)return;const i=lt;let s=t.rootTilesInExtent(e,i,5*ce);if(null!=this._rootTiles){if(s.length>ce)return void l.getLogger(this).warn(ge);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,Ae);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>Ae(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>ce&&(l.getLogger(this).warn(me),s=t.rootTilesInExtent(e,i,ce)),this._setRootTiles(s.map(e=>this._newRootTile(e)));I(i,this._rootTilesExtent)||(this._rootTilesExtent=B(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(Fe),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(Fe);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._updateRootTileElevationBounds(),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.extent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=We(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty();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.min!==r||i.max!==s)&&(this.visibleElevationBounds=new te(r,s))}_updateRootTileElevationBounds(){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.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new te(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=N(this._splitLimits.frustum??G(),t.frustum):this._splitLimits.frustum=null,x(this._eyePosRenderSR,t.eye),R(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(we)&&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=ht.extent;A(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>O(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),ht.spatialReference=this.spatialReference,this.emit("elevation-change",ht),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"),je&&this._checkTileInvariant(),!e.hasProgressed)return tt}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(ve(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(ve(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){ve(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)ve(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<=_e;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${_e} (edge[${i}])`),ve(r,`tile level delta [${t.level}] vs [${e.level}] > ${_e}`))}ve(t.level-e.level<=_e,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-_e,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(Se[i],s);if(null!=a){if(t.leaf&&t.level>=_e){let i=a;for(;t.level-i.level<_e;)i=i.parent;const s=[r,t.lij[1]>>_e,t.lij[2]>>_e];if(!Ae(s,i.lij)){const r=e.get(i);ve(!r.has(t),"Cannot already have neighbor"),r.add(t)}}ve(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),ve(t.level-a.level<=_e,`Tile level delta [${t.level}] vs [${a.level}] > ${_e}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);ve(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 he(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?ut(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||(He(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){Ce(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(Fe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Ce(r.loaded),Ce(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=ke[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(De(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(be(Se[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(Ce(e.has(t)||Fe(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,je&&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>=_e){const e=e=>e.leaf||i-e.level<_e;for(let r=0;r<4;++r){const a=s.findNeighborTile(Se[r],e);null!=a&&i-a.level===_e&&(t=!1,je&&(Ce(a.leaf),Ce(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._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)*ye}_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?gt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(it._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){ve(e.leaf,"Tile that is already split should not be split again!"),ve(e.rendered,"Tile marked to split is not rendered"),gt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),ve(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=>ut(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){dt.spatialReference=this.spatialReference,dt.extent=e.extent,dt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",dt)}createTile(e,t,i,r){ve(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){ve(!e.hasPendingUpdate(1),"_mergeTile sanity check"),ve(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),ve(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),ut(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=Ze){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),xe(e)||Ee(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ee(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(Le(e)&&!X(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Pe(e)||Ee(e))&&Qe(Ye[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Ue(e)?0:1}_registerTiledLayerView(e){const t=[];if((Pe(e)||Ee(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Ee(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||!xe(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 ne){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._updateRootTileElevationBounds()}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(){this._allTilesDirty=!0}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||we(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?Ue(i)?this._requestElevationTileData(e,i,r):Promise.reject():Le(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 ie(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._updateRootTileElevationBounds(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Me(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)?Me(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 Me(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 visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=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){Be(e)}enableWaterproofnessChecks(e){Ie(e)}static cleanupTerrainSurface(){ot.prune()}enable(e){e!==this.enabled&&(e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this._set("enabled",e),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],rt.prototype,"_renderer",void 0),e([w({constructOnly:!0})],rt.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],rt.prototype,"view",void 0),e([w({constructOnly:!0})],rt.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],rt.prototype,"terrainTextureCompressionTracker",void 0),e([w()],rt.prototype,"_hasPendingUpdates",void 0),e([w()],rt.prototype,"_asyncWorkItems",void 0),e([w()],rt.prototype,"_allTilesDirty",void 0),e([w()],rt.prototype,"_allTilesSorted",void 0),e([w()],rt.prototype,"_viewChanged",void 0),e([w({type:Number})],rt.prototype,"heading",void 0),e([w()],rt.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],rt.prototype,"_watchUpdatingTracking",void 0),e([w()],rt.prototype,"_frameTask",void 0),e([w()],rt.prototype,"demResolution",null),e([w({readOnly:!0})],rt.prototype,"snapLevel",null),e([w({readOnly:!0})],rt.prototype,"lodSnappingEnabled",null),e([w()],rt.prototype,"_userClippingExtent",null),e([w()],rt.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],rt.prototype,"extent",null),e([w({readOnly:!0})],rt.prototype,"groundExtent",null),e([w({readOnly:!0})],rt.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],rt.prototype,"updating",null),e([w({readOnly:!0})],rt.prototype,"readyToRun",null),e([w(ee)],rt.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],rt.prototype,"updatingProgressValue",null),e([w()],rt.prototype,"_maxNumUpdating",void 0),e([w()],rt.prototype,"baseOpacity",null),e([w()],rt.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],rt.prototype,"viewingMode",null),e([w()],rt.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],rt.prototype,"ready",null),e([w({readOnly:!0})],rt.prototype,"rootTiles",null),e([w()],rt.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],rt.prototype,"spatialReference",null),e([w({type:t})],rt.prototype,"backgroundColor",null),e([w({value:!1})],rt.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],rt.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],rt.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],rt.prototype,"tilingSchemeLogic",void 0),e([w()],rt.prototype,"wireframe",null),e([w({value:!1})],rt.prototype,"suspended",null),e([w()],rt.prototype,"fadeDuration",null),e([w()],rt.prototype,"_xNormalizer",null),e([w()],rt.prototype,"visibleElevationBounds",void 0),e([w()],rt.prototype,"rootTileElevationBounds",void 0),e([w()],rt.prototype,"_layerViewsDirty",void 0),e([w()],rt.prototype,"renderPatchBorders",null),e([w()],rt.prototype,"visualizeNormals",null),e([w()],rt.prototype,"renderingDisabled",null),e([w({readOnly:!0})],rt.prototype,"enabled",void 0),rt=it=e([S("esri.views.3d.terrain.TerrainSurface")],rt);const st=rt,at=E(),nt=H(),lt=B(),ot=new u,ht=new se("ground"),dt={spatialReference:null,extent:null,scale:0};function pt(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 re(t,i,s)}return null}function ut(e,t){!e.leaf||e.level<_e||_t(e,e=>{t&&ct(e);const i=mt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=mt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function ct(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<_e||_t(e,e=>{ct(e)})}function gt(e){e.level<_e||_t(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,mt(t));)t=t.parent}})}function mt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function _t(e,t){if(e.level<_e)return;const i=e.level-_e,r=e.lij[1]>>_e,s=e.lij[2]>>_e,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(Se[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}const yt=E();export{st as default};
@@ -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 e from"../../../core/Logger.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{ZEROS as r}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{VectorTileRendererHelper3D as i}from"../../2d/engine/vectorTiles/VectorTileRendererHelper3D.js";import{BlendLayersTechnique as s}from"./BlendLayersTechnique.js";import{BlendLayersTechniqueConfiguration as o}from"./BlendLayersTechniqueConfiguration.js";import{RasterColorizerTechnique as n}from"./RasterColorizerTechnique.js";import{RasterColorizerTechniqueConfiguration as a}from"./RasterColorizerTechniqueConfiguration.js";import{MultiSizeFramebuffer as h}from"./support/MultiSizeFramebuffer.js";import{BindParameters as c}from"../webgl-engine/lib/BindParameters.js";import{createQuadVAO as u}from"../webgl-engine/lib/glUtil3D.js";import{PrimitiveType as l}from"../../webgl/enums.js";import{Texture as d}from"../../webgl/Texture.js";const _=()=>e.getLogger("esri.views.3d.terrain");class f{constructor(e,t){this._rctx=e,this._techniques=t,this._fbos=[],this._vectorTileHelper=new i,this._bindParameters=new c(null),this._blendConfiguration=new o,this._current=0,this._lastUsedIds=new Array,this._lastCreatedBufferId=0,this._onHoldIds=new Array,this._vao=u(this._rctx,1)}dispose(){this._fbos.forEach(t),this._fbos=null,this._vtFBO=t(this._vtFBO),this._vao=t(this._vao),this._vectorTileHelper=t(this._vectorTileHelper)}updateHeading(e){this._vectorTileHelper?.updateHeading(e)}_acquireBlendTechnique(e,t,r,i=0,o=0){return this._blendConfiguration.output=t,this._blendConfiguration.blendMode=e,this._blendConfiguration.baseOpacityMode=r,this._blendConfiguration.premultipliedSource=i,this._blendConfiguration.background=o,this._techniques.precompile(s,this._blendConfiguration),this._techniques.get(s,this._blendConfiguration)}drawBackground(e,t){const r=this._acquireBlendTechnique(0,t?2:3,0,0,1),i=this._rctx.bindTechnique(r,this._bindParameters,e);this._render(i)}_render(e){this._rctx.bindVAO(this._vao),e.assertCompatibleVertexAttributeLocations(this._vao),this._rctx.drawArrays(l.TRIANGLE_STRIP,0,this._vao.vertexCount("geometry"))}drawGroup(e,t,r,i,s=1){1===t&&(e.fboTexture=this._fbos[this.getLastOnHoldId()].get(r).colorTexture,null==e.fboTexture&&(e.fboTexture=this._rctx.emptyTexture)),e.texture=this.currentFBO(r).colorTexture,this.closeGroup(r);const o=e.baseOpacity<1?1:0,n=this._acquireBlendTechnique(i,t,o,s),a=this._rctx.bindTechnique(n,this._bindParameters,e);this._render(a)}drawImageData(e,t,r,i,s=0){if(null==e.texture)return;const o=e.baseOpacity<1?1:0;e.fboTexture=4===t||0===i&&0===o&&0===s?null:this.switch(r).colorTexture,null==e.fboTexture&&(e.fboTexture=this._rctx.emptyTexture);const n=this._acquireBlendTechnique(i,t,o,s),a=this._rctx.bindTechnique(n,this._bindParameters,e);this._render(a)}drawRasterData(e,t,r,i,s){const o=s.sourceLayerInfo.data;if(!o.source)return;if(s.tile.surface.layerViewByIndex(s.layerIndex,1).ensureSymbolizerParameters(o),!o.bind(this._rctx))return;const n=e.baseOpacity<1?1:0;e.fboTexture=0===i&&0===n?null:this.switch(r).colorTexture;const a=this._acquireRasterTechnique(o,t,i,n);if(!a)return;o.opacity=e.opacity;const h=o.getUniforms(this._rctx);h.scale=s.scale,h.offset=s.offset,h.backgroundColor=e.backgroundColor,h.fboTexture=e.fboTexture,h.baseOpacity=e.baseOpacity;const c=this._rctx.bindTechnique(a,this._bindParameters,h);this._render(c)}_acquireRasterTechnique(e,t,r,i){if(!this._rctx.capabilities.colorBufferFloat)return null;const s=e.symbolizerParameters,o=["stretch","lut","hillshade"].indexOf(s.type);return this._rasterConfiguration??=new a,this._rasterConfiguration.output=t,this._rasterConfiguration.blendMode=r,this._rasterConfiguration.baseOpacityMode=i,this._rasterConfiguration.colorizerType=o,this._rasterConfiguration.applyColormap=!!s.colormap,this._rasterConfiguration.requireBilinearWithNN=e.isBilinearWithStretchColorRamp,this._rasterConfiguration.stretchType=e.hasStretchTypeNone()?0:1,this._techniques.precompile(n,this._rasterConfiguration),this._techniques.get(n,this._rasterConfiguration)}drawVectorData(e,t,i,s,o,n,a,c){const u=this._rctx,l=o.sourceLayerInfo.data,d=o.tile.surface.layerViewByIndex(o.layerIndex,1),f=e.baseOpacity<1?1:0,p=1===f||e.opacity<1||0!==s||1!==t,b=p?1:0,g=this._acquireBlendTechnique(s,t,f,b);u.setPipelineState(g.getPipeline());let x=null,m=null;p?(m=this.currentFBO(i),null==this._vtFBO&&(this._vtFBO=new h(this._rctx)),x=this._vtFBO.get(i),u.bindFramebuffer(x),this._clearCurrentFBO()):c&&u.clear(256);try{this._vectorTileHelper.renderBackground(u,o.sourceLod,d.painter,d.layer.styleRepository,d.schemaHelper,Math.round(1/o.scale),o.offset,a,n,d.contentZoom),l&&this._vectorTileHelper.renderContent(u,o.sourceLod,l,o.vtlNeighborInfos,d.painter,d.layer.styleRepository,d.schemaHelper,Math.round(1/o.scale),o.offset,a,n,d.contentZoom)}catch(T){_().warnOnce("A render call containing vector tiles did not resolve correctly.",T)}return!x||(u.bindFramebuffer(m),e.texture=x.colorTexture,e.offset=r,e.scale=1,this.drawImageData(e,t,i,s,b),c)}copyFBOToTexture(e){const t=this._rctx,r=t.bindTexture(e.texture,d.TEXTURE_UNIT_FOR_UPDATES),i=e.descriptor;t.gl.copyTexImage2D(3553,0,i.pixelFormat,0,0,i.width,i.height,0),e.generateMipmap(),t.bindTexture(r,d.TEXTURE_UNIT_FOR_UPDATES)}_clearCurrentFBO(){this._rctx.setStencilWriteMask(255),this._rctx.setClearColor(0,0,0,0),this._rctx.setClearDepth(1),this._rctx.setClearStencil(0),this._rctx.clear(17664)}_initFBO(e,t,r){this._rctx.bindFramebuffer(e),r&&(this._rctx.setViewport(0,0,t,t),this._clearCurrentFBO())}ensureBuffer(e){this._lastUsedIds.length=0,this._lastUsedIds.push(1),this._lastCreatedBufferId=1,this._onHoldIds.length=0,this.bind(e)}bind(e,t=0,r=!0){if(this._current=t,t>=this._fbos.length)for(let i=this._fbos.length;i<=t;i++)this._fbos.push(new h(this._rctx));this._initFBO(this._fbos[t].get(e),e,r)}_bindNextFreeBuffer(e){this._lastUsedIds.length>0?this.bind(e,this._lastUsedIds.pop()):(this._lastCreatedBufferId++,this.bind(e,this._lastCreatedBufferId))}openGroup(e){this._onHoldIds.push(this._current),this._bindNextFreeBuffer(e)}switch(e){const t=this.currentFBO(e),r=this._current;return this._bindNextFreeBuffer(e),this._lastUsedIds.push(r),t}getLastOnHoldId(){return this._onHoldIds[this._onHoldIds.length-1]}closeGroup(e){const t=this._current;this._bindNextFreeBuffer(e),this._lastUsedIds.push(t),this._lastUsedIds.push(this._onHoldIds.pop())}unbind(){this._rctx.bindFramebuffer(null)}currentFBO(e){return this._fbos[this._current].get(e)}}export{f as TileCompositor};
5
+ import e from"../../../core/Logger.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{ZEROS as r}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{VectorTileRendererHelper3D as i}from"../../2d/engine/vectorTiles/VectorTileRendererHelper3D.js";import{BlendLayersTechnique as s}from"./BlendLayersTechnique.js";import{BlendLayersTechniqueConfiguration as o}from"./BlendLayersTechniqueConfiguration.js";import{RasterColorizerTechnique as n}from"./RasterColorizerTechnique.js";import{RasterColorizerTechniqueConfiguration as a}from"./RasterColorizerTechniqueConfiguration.js";import{MultiSizeFramebuffer as h}from"./support/MultiSizeFramebuffer.js";import{BindParameters as c}from"../webgl-engine/lib/BindParameters.js";import{createQuadVAO as l}from"../webgl-engine/lib/glUtil3D.js";import{PrimitiveType as u}from"../../webgl/enums.js";import{Texture as d}from"../../webgl/Texture.js";const _=()=>e.getLogger("esri.views.3d.terrain");class f{constructor(e,t){this._rctx=e,this._techniques=t,this._fbos=[],this._vectorTileHelper=new i,this._bindParameters=new c(null),this._blendConfiguration=new o,this._current=0,this._lastUsedIds=new Array,this._lastCreatedBufferId=0,this._onHoldIds=new Array,this._vao=l(this._rctx,1)}dispose(){this._fbos.forEach(t),this._fbos=null,this._vtFBO=t(this._vtFBO),this._vao=t(this._vao),this._vectorTileHelper=t(this._vectorTileHelper)}updateHeading(e){this._vectorTileHelper?.updateHeading(e)}_acquireBlendTechnique(e,t,r,i=0,o=0){return this._blendConfiguration.output=t,this._blendConfiguration.blendMode=e,this._blendConfiguration.baseOpacityMode=r,this._blendConfiguration.premultipliedSource=i,this._blendConfiguration.background=o,this._techniques.precompile(s,this._blendConfiguration),this._techniques.get(s,this._blendConfiguration)}drawBackground(e,t){const r=this._acquireBlendTechnique(0,t?2:3,0,0,1),i=this._rctx.bindTechnique(r,this._bindParameters,e);this._render(i)}_render(e){this._rctx.bindVAO(this._vao),e.assertCompatibleVertexAttributeLocations(this._vao),this._rctx.drawArrays(u.TRIANGLE_STRIP,0,this._vao.vertexCount("geometry"))}drawGroup(e,t,r,i,s=1){1===t&&(e.fboTexture=this._fbos[this.getLastOnHoldId()].get(r).colorTexture,null==e.fboTexture&&(e.fboTexture=this._rctx.emptyTexture)),e.texture=this.currentFBO(r).colorTexture,this.closeGroup(r);const o=e.baseOpacity<1?1:0,n=this._acquireBlendTechnique(i,t,o,s),a=this._rctx.bindTechnique(n,this._bindParameters,e);this._render(a)}drawImageData(e,t,r,i,s=0){if(null==e.texture)return;const o=e.baseOpacity<1?1:0;e.fboTexture=4===t||0===i&&0===o&&0===s?null:this.switch(r).colorTexture,null==e.fboTexture&&(e.fboTexture=this._rctx.emptyTexture);const n=this._acquireBlendTechnique(i,t,o,s),a=this._rctx.bindTechnique(n,this._bindParameters,e);this._render(a)}drawRasterData(e,t,r,i,s){const o=s.sourceLayerInfo.data;if(!o.source)return;if(s.tile.surface.layerViewByIndex(s.layerIndex,1).ensureSymbolizerParameters(o),!o.bind(this._rctx))return;const n=e.baseOpacity<1?1:0;e.fboTexture=0===i&&0===n?null:this.switch(r).colorTexture;const a=this._acquireRasterTechnique(o,t,i,n);if(!a)return;o.opacity=e.opacity;const h=o.getUniforms(this._rctx);h.scale=s.scale,h.offset=s.offset,h.backgroundColor=e.backgroundColor,h.fboTexture=e.fboTexture,h.baseOpacity=e.baseOpacity;const c=this._rctx.bindTechnique(a,this._bindParameters,h);this._render(c)}_acquireRasterTechnique(e,t,r,i){if(!this._rctx.capabilities.colorBufferFloat)return null;const s=e.symbolizerParameters,o=["stretch","lut","hillshade"].indexOf(s.type);return this._rasterConfiguration??=new a,this._rasterConfiguration.output=t,this._rasterConfiguration.blendMode=r,this._rasterConfiguration.baseOpacityMode=i,this._rasterConfiguration.colorizerType=o,this._rasterConfiguration.applyColormap=!!s.colormap,this._rasterConfiguration.requireBilinearWithNN=e.isBilinearWithStretchColorRamp,this._rasterConfiguration.stretchType=e.hasStretchTypeNone()?0:1,this._techniques.precompile(n,this._rasterConfiguration),this._techniques.get(n,this._rasterConfiguration)}drawVectorData(e,t,i,s,o,n,a,c){const l=this._rctx,u=o.sourceLayerInfo.data,d=o.tile.surface.layerViewByIndex(o.layerIndex,1),f=e.baseOpacity<1?1:0,p=1===f||e.opacity<1||0!==s||1!==t,b=p?1:0,g=this._acquireBlendTechnique(s,t,f,b);l.setPipelineState(g.getPipeline());let m=null,x=null;p?(x=this.currentFBO(i),null==this._vtFBO&&(this._vtFBO=new h(this._rctx)),m=this._vtFBO.get(i),l.bindFramebuffer(m),this._clearCurrentFBO()):c&&l.clear(256);try{this._vectorTileHelper.renderBackground(l,o.sourceLod,d.painter,d.layer.styleRepository,d.schemaHelper,Math.round(1/o.scale),o.offset,a,n,d.contentZoom),u&&this._vectorTileHelper.renderContent(l,o.sourceLod,u,o.vtlNeighborInfos,d.painter,d.layer.styleRepository,d.schemaHelper,Math.round(1/o.scale),o.offset,a,n,d.contentZoom)}catch(T){_().warnOnce("A render call containing vector tiles did not resolve correctly.",T)}return!m||(l.bindFramebuffer(x),e.texture=m.colorTexture,e.offset=r,e.scale=1,this.drawImageData(e,t,i,s,b),c)}copyFBOToTexture(e){const t=this._rctx,r=t.bindTexture(e.texture,d.TEXTURE_UNIT_FOR_UPDATES),i=e.descriptor;t.gl.copyTexImage2D(3553,0,i.pixelFormat,0,0,i.width,i.height,0),e.generateMipmap(),t.bindTexture(r,d.TEXTURE_UNIT_FOR_UPDATES)}_clearCurrentFBO(){this._rctx.setStencilWriteMask(255),this._rctx.setClearColor(0,0,0,0),this._rctx.setClearDepth(1),this._rctx.setClearStencil(0),this._rctx.clear(17664)}_initFBO(e,t,r){this._rctx.bindFramebuffer(e),r&&(this._rctx.setViewport(0,0,t,t),this._clearCurrentFBO())}ensureBuffer(e){this._lastUsedIds.length=0,this._lastUsedIds.push(1),this._lastCreatedBufferId=1,this._onHoldIds.length=0,this.bind(e)}bind(e,t=0,r=!0){if(this._current=t,t>=this._fbos.length)for(let i=this._fbos.length;i<=t;i++)this._fbos.push(new h(this._rctx));this._initFBO(this._fbos[t].get(e),e,r)}_bindNextFreeBuffer(e){this._lastUsedIds.length>0?this.bind(e,this._lastUsedIds.pop()):(this._lastCreatedBufferId++,this.bind(e,this._lastCreatedBufferId))}openGroup(e){this._onHoldIds.push(this._current),this._bindNextFreeBuffer(e)}switch(e){const t=this.currentFBO(e),r=this._current;return this._bindNextFreeBuffer(e),this._lastUsedIds.push(r),t}getLastOnHoldId(){return this._onHoldIds[this._onHoldIds.length-1]}closeGroup(e){const t=this._current;this._bindNextFreeBuffer(e),this._lastUsedIds.push(t),this._lastUsedIds.push(this._onHoldIds.pop())}unbind(){this._rctx.bindFramebuffer(null)}currentFBO(e){return this._fbos[this._current].get(e)}}export{f as TileCompositor};
@@ -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"../../../core/Accessor.js";import{removeUnordered as r}from"../../../core/arrayUtils.js";import{toConst as s}from"../../../core/compilerUtils.js";import"../../../core/has.js";import{destroyMaybe as i}from"../../../core/maybe.js";import{isPromiseLike as n}from"../../../core/promiseUtils.js";import{signal as o}from"../../../core/signal.js";import{property as d}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import{isIntersectionHandler as h}from"../state/helpers/SceneIntersectionHelper.js";import{TextureCollection as l}from"../support/TextureCollection.js";import{ChangeSet as c}from"./lib/ChangeSet.js";import{Model as m}from"./parts/Model.js";import{RenderView as y}from"./parts/RenderView.js";import{TaskPriority as u,noBudget as p}from"../../support/Scheduler.js";import{Yield as _}from"../../support/Yield.js";let g=class extends t{constructor(e){super(e),this._model=new m,this._canCompact=o(!1),this._layers=new Array,this._asyncChangeSet=new c,this._syncChangeSet=new c,this._layerSyncSet=new Set,this._textures=new l(this,e.view.resourceController.scheduler),this._frameTask=e.view.resourceController.scheduler.registerTask(u.STAGE,this),this.addHandles(this._frameTask)}initialize(){this._renderView=new y({stage:this})}destroy(){this.removeAllHandles(),this._textures.destroy(),this._set("textures",null),this._renderView=i(this._renderView),this._set("renderView",null),this._layers.length=0,this._model=null,this._set("renderer",null),this.options.canvas=null,this._set("options",null)}get viewingMode(){return this.view.state.viewingMode}get updating(){return!this.destroyed&&!this.destroying&&(this.readyToRun||this.renderView.updating||this._frameTask.updating||this.textures.updating)}get renderView(){return this._renderView}get renderer(){return this.renderView?.renderer}get textures(){return this._textures}addTexture(e){this._model.addTexture(e),this.renderView.requestRender()}removeTexture(e){null!=e&&!this.destroyed&&this._model.hasTexture(e)&&(this._model.removeTexture(e),this.renderView.requestRender())}addTextures(e){null!=e&&(this._model.addTextures(e),this.renderView.requestRender())}removeTextures(e){null!=e&&(this._model?.removeTextures(e),this.renderView.requestRender())}forEachTexture(e){this._model.forEachTexture(e)}getTexture(e){return this._model.getTexture(e)}addLayer(e){this._layers.includes(e)||(this._model.addLayer(e),this._layers.push(e),this._model.dirtySet.layerAdded(e),this.renderView.requestRender())}removeLayer(e){null!=e&&!this.destroyed&&this._model.hasLayer(s(e))&&(this._model.dirtySet.layerRemoved(e),this.commitLayer(e),r(this._layers,e),this._model.dirtySet.assertLayerClean(e.id),this._model.removeLayer(e),this.renderView.requestRender())}getLayer(e){return this._model.getLayer(e)}handleEvent(e,t){this.destroyed||(this._model.dirtySet[e](t),this.renderView.requestRender())}get readyToRun(){return this._model.dirtySet.dirty||!this._asyncChangeSet.empty||this._canCompact.value}runTask(e){if(this._frameTask.processQueue(e),this._commit(e),this.renderer.compact(e),this._canCompact.value=this.renderer.canCompact,!e.hasProgressed)return _}compact(e){return this._canCompact.value=!1,this.renderer.compact(e)}_commit(e){const t=this._model.dirtySet;this._asyncChangeSet.empty||e.done||(this.renderer.commit(this._asyncChangeSet,e),this.renderView.requestRender(),e.madeProgress()),this._layers.forEach(r=>{if(e.done)return;const s=this._layerSyncSet.has(r.id)||1===r.updatePolicy,i=s?this._syncChangeSet:this._asyncChangeSet;t.commitLayer(r.id,i),this._layerSyncSet.delete(r.id),i.empty||(this.renderer.commit(i,s?p:e),this.renderView.requestRender(),e.madeProgress())}),this._syncChangeSet.empty||(this.renderer.commit(this._syncChangeSet,p),this.renderView.requestRender(),e.madeProgress()),this._layers.forEach(r=>{e.done||this._layerSyncSet.has(r.id)||0!==r.updatePolicy||(t.commitLayer(r.id,this._asyncChangeSet),this._asyncChangeSet.empty||(this.renderer.commit(this._asyncChangeSet,e),this.renderView.requestRender(),e.madeProgress()))}),this._layerSyncSet.clear(),this.notifyChange("readyToRun")}commitSyncLayers(){const e=this._model.dirtySet;this._layers.forEach(t=>{this._layerSyncSet.has(t.id)||1===t.updatePolicy?(e.commitLayer(t.id,this._syncChangeSet),this._layerSyncSet.delete(t.id)):e.commitSyncUpdates(t.id,this._syncChangeSet)});for(const t of this._layerSyncSet)e.commitLayer(t,this._syncChangeSet);this._layerSyncSet.clear(),this._syncChangeSet.empty||(this.renderer.commit(this._syncChangeSet,p),this.renderView.requestRender())}commitLayer(e){this._model.dirtySet.commitLayer(e.id,this._syncChangeSet),this._layerSyncSet.delete(e.id),this._syncChangeSet.empty||(this.renderer.commit(this._syncChangeSet,p),this.renderView.requestRender())}schedule(e,t){return this._frameTask.schedule(e,t)}reschedule(e,t){return this._frameTask.reschedule(e,t)}syncLayer(e){this._layerSyncSet.add(e),this.renderView.requestRender()}get layers(){return this._layers}addRenderPlugin(e,t){const r=this.renderer.plugins.add(e,t),s=()=>{h(e)&&this.view.sceneIntersectionHelper.addIntersectionHandler(e)};if(n(r))return r.then(s);s()}removeRenderPlugin(e){this.destroyed||(h(e)&&this.view.sceneIntersectionHelper.removeIntersectionHandler(e),this.renderer.plugins.remove(e))}get test(){}};e([d({constructOnly:!0})],g.prototype,"view",void 0),e([d({constructOnly:!0})],g.prototype,"options",void 0),e([d({readOnly:!0})],g.prototype,"viewingMode",null),e([d({constructOnly:!0})],g.prototype,"container",void 0),e([d({readOnly:!0})],g.prototype,"updating",null),e([d({readOnly:!0})],g.prototype,"renderView",null),e([d({readOnly:!0})],g.prototype,"renderer",null),e([d({readOnly:!0})],g.prototype,"textures",null),e([d({readOnly:!0})],g.prototype,"readyToRun",null),g=e([a("esri.views.3d.webgl-engine.Stage")],g);export{g as Stage};
5
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{removeUnordered as r}from"../../../core/arrayUtils.js";import{toConst as s}from"../../../core/compilerUtils.js";import"../../../core/has.js";import{destroyMaybe as i}from"../../../core/maybe.js";import{isPromiseLike as n}from"../../../core/promiseUtils.js";import{signal as o}from"../../../core/signal.js";import{property as d}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import{isIntersectionHandler as h}from"../state/helpers/SceneIntersectionHelper.js";import{TextureCollection as l}from"../support/TextureCollection.js";import{ChangeSet as c}from"./lib/ChangeSet.js";import{Model as m}from"./parts/Model.js";import{RenderView as y}from"./parts/RenderView.js";import{TaskPriority as u,noBudget as p}from"../../support/Scheduler.js";import{Yield as _}from"../../support/Yield.js";let g=class extends t{constructor(e){super(e),this._model=new m,this._canCompact=o(!1),this._layers=new Array,this._asyncChangeSet=new c,this._syncChangeSet=new c,this._layerSyncSet=new Set,this._textures=new l(this,e.view.resourceController.scheduler),this._frameTask=e.view.resourceController.scheduler.registerTask(u.STAGE,this),this.addHandles(this._frameTask)}get sphericalSpatialReference(){return 2===this.viewingMode?0:this.view.spatialReference.isWebMercator?1:2}initialize(){this._renderView=new y({stage:this})}destroy(){this.removeAllHandles(),this._textures.destroy(),this._set("textures",null),this._renderView=i(this._renderView),this._set("renderView",null),this._layers.length=0,this._model=null,this._set("renderer",null),this.options.canvas=null,this._set("options",null)}get viewingMode(){return this.view.state.viewingMode}get updating(){return!this.destroyed&&!this.destroying&&(this.readyToRun||this.renderView.updating||this._frameTask.updating||this.textures.updating)}get renderView(){return this._renderView}get renderer(){return this.renderView?.renderer}get textures(){return this._textures}addTexture(e){this._model.addTexture(e),this.renderView.requestRender()}removeTexture(e){null!=e&&!this.destroyed&&this._model.hasTexture(e)&&(this._model.removeTexture(e),this.renderView.requestRender())}addTextures(e){null!=e&&(this._model.addTextures(e),this.renderView.requestRender())}removeTextures(e){null!=e&&(this._model?.removeTextures(e),this.renderView.requestRender())}forEachTexture(e){this._model.forEachTexture(e)}getTexture(e){return this._model.getTexture(e)}addLayer(e){this._layers.includes(e)||(this._model.addLayer(e),this._layers.push(e),this._model.dirtySet.layerAdded(e),this.renderView.requestRender())}removeLayer(e){null!=e&&!this.destroyed&&this._model.hasLayer(s(e))&&(this._model.dirtySet.layerRemoved(e),this.commitLayer(e),r(this._layers,e),this._model.dirtySet.assertLayerClean(e.id),this._model.removeLayer(e),this.renderView.requestRender())}getLayer(e){return this._model.getLayer(e)}handleEvent(e,t){this.destroyed||(this._model.dirtySet[e](t),this.renderView.requestRender())}get readyToRun(){return this._model.dirtySet.dirty||!this._asyncChangeSet.empty||this._canCompact.value}runTask(e){if(this._frameTask.processQueue(e),this._commit(e),this.renderer.compact(e),this._canCompact.value=this.renderer.canCompact,!e.hasProgressed)return _}compact(e){return this._canCompact.value=!1,this.renderer.compact(e)}_commit(e){const t=this._model.dirtySet;this._asyncChangeSet.empty||e.done||(this.renderer.commit(this._asyncChangeSet,e),this.renderView.requestRender(),e.madeProgress()),this._layers.forEach(r=>{if(e.done)return;const s=this._layerSyncSet.has(r.id)||1===r.updatePolicy,i=s?this._syncChangeSet:this._asyncChangeSet;t.commitLayer(r.id,i),this._layerSyncSet.delete(r.id),i.empty||(this.renderer.commit(i,s?p:e),this.renderView.requestRender(),e.madeProgress())}),this._syncChangeSet.empty||(this.renderer.commit(this._syncChangeSet,p),this.renderView.requestRender(),e.madeProgress()),this._layers.forEach(r=>{e.done||this._layerSyncSet.has(r.id)||0!==r.updatePolicy||(t.commitLayer(r.id,this._asyncChangeSet),this._asyncChangeSet.empty||(this.renderer.commit(this._asyncChangeSet,e),this.renderView.requestRender(),e.madeProgress()))}),this._layerSyncSet.clear(),this.notifyChange("readyToRun")}commitSyncLayers(){const e=this._model.dirtySet;this._layers.forEach(t=>{this._layerSyncSet.has(t.id)||1===t.updatePolicy?(e.commitLayer(t.id,this._syncChangeSet),this._layerSyncSet.delete(t.id)):e.commitSyncUpdates(t.id,this._syncChangeSet)});for(const t of this._layerSyncSet)e.commitLayer(t,this._syncChangeSet);this._layerSyncSet.clear(),this._syncChangeSet.empty||(this.renderer.commit(this._syncChangeSet,p),this.renderView.requestRender())}commitLayer(e){this._model.dirtySet.commitLayer(e.id,this._syncChangeSet),this._layerSyncSet.delete(e.id),this._syncChangeSet.empty||(this.renderer.commit(this._syncChangeSet,p),this.renderView.requestRender())}schedule(e,t){return this._frameTask.schedule(e,t)}reschedule(e,t){return this._frameTask.reschedule(e,t)}syncLayer(e){this._layerSyncSet.add(e),this.renderView.requestRender()}get layers(){return this._layers}addRenderPlugin(e,t){const r=this.renderer.plugins.add(e,t),s=()=>{h(e)&&this.view.sceneIntersectionHelper.addIntersectionHandler(e)};if(n(r))return r.then(s);s()}removeRenderPlugin(e){this.destroyed||(h(e)&&this.view.sceneIntersectionHelper.removeIntersectionHandler(e),this.renderer.plugins.remove(e))}get test(){}};e([d({constructOnly:!0})],g.prototype,"view",void 0),e([d({constructOnly:!0})],g.prototype,"options",void 0),e([d({readOnly:!0})],g.prototype,"viewingMode",null),e([d({constructOnly:!0})],g.prototype,"container",void 0),e([d({readOnly:!0})],g.prototype,"updating",null),e([d({readOnly:!0})],g.prototype,"renderView",null),e([d({readOnly:!0})],g.prototype,"renderer",null),e([d({readOnly:!0})],g.prototype,"textures",null),e([d({readOnly:!0})],g.prototype,"readyToRun",null),g=e([a("esri.views.3d.webgl-engine.Stage")],g);export{g as Stage};
@@ -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"../../../../../core/has.js";import e from"../../../../../core/Logger.js";import{getOrCreateMapValue as t}from"../../../../../core/MapUtils.js";import i from"../../../../../core/PooledArray.js";import{isTypedArray as o}from"../../../../../core/typedArrayUtil.js";import{s as n}from"../../../../../chunks/vec32.js";import{clone as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as s}from"../../../../../geometry/support/aaBoundingBox.js";import{compactIndices as a}from"../../../../../geometry/support/Indices.js";import{c}from"../../../../../chunks/vec3.js";import{c as l}from"../../../../../chunks/vec33.js";import{encodeSymbolColor as m}from"../../../layers/support/symbolColorUtils.js";import{computeOffsetObb as f}from"../../../support/orientedBoundingBox.js";import{glLayout as h}from"../../../support/buffer/glUtil.js";import{ComponentData as p}from"./ComponentData.js";import{ComponentObject as g}from"./ComponentObject.js";import{IntersectionGeometry as u}from"./IntersectionGeometry.js";import{Renderable as d}from"./Renderable.js";import{RenderGeometry as b}from"./RenderGeometry.js";import{RenderSubmitSystem as v}from"./RenderSubmitSystem.js";import{createVertexBufferLayout as y}from"./SourceGeometry.js";import{UniformComponentParameters as _}from"./UniformComponentParameters.js";import{ComponentParametersVarying as C,ComponentParametersUniform as M,ComponentMaterial as w}from"./Material/ComponentMaterial.js";import{indexGlLayout as x}from"./Material/ComponentTechnique.js";import{maxElevationOffset as j,maxPackedRGBEmission as O}from"./Material/shader/ComponentData.glsl.js";import{olidEnabled as S}from"../../effects/geometry/olidUtils.js";import{getVisibility as D,updatePickabilityWithCount as R}from"../../lib/ComponentUtils.js";import{VertexArrayObject as B}from"../../lib/VertexArrayObject.js";import{getVerticalOffsetI3S as A}from"../../lib/verticalOffsetUtils.js";import{BufferManager as P}from"../../lib/TextureBackedBuffer/BufferManager.js";import{BufferObject as V}from"../../../../webgl/BufferObject.js";import{PrimitiveType as E}from"../../../../webgl/enums.js";import{VertexBuffer as H}from"../../../../webgl/VertexBuffer.js";const U=()=>e.getLogger("esri.views.3d.webgl-engine.collections.Component.ComponentObjectCollection");class k{constructor(e,t){this._renderManager=e,this._viewingMode=t,this._elevationRangeCacheVerticalOffset=NaN,this._elevationRangeCacheMin=NaN,this._elevationRangeCacheMax=NaN,this._activeHighlightOptions=new Map,this._visible=new i,this._hidden=new i,this._renderSubmit=new v(this),this._renderManager.register(this._renderSubmit),this._componentBufferManager=new P(e.rctx,N())}destroy(){this._componentBufferManager.destroy(),this._componentBufferManager=null,this._visible.forAll(e=>e.destroy()),this._visible.prune(),this._hidden.forAll(e=>e.destroy()),this._hidden.prune(),this._renderSubmit.destroy()}createObject(e){const{geometry:t}=e,i=new p(this._componentBufferManager,a(t.componentOffsets)),o=this._createRenderable(e,i),n=new u(this._viewingMode,t.positionData,i,e.elevationAlignable),r=new g(e.transform,e.obb.clone(),i,o,n);return(r.visible?this._visible:this._hidden).push(r),r}destroyObject(e){const t=e;(t.visible?this._visible:this._hidden).removeUnordered(t),t.destroy(),this._notifyDirty()}setObjectVisibility(e,t){const i=e;t!==i.visible&&(t?(this._hidden.removeUnordered(i),this._visible.push(i)):(this._visible.removeUnordered(i),this._hidden.push(i)),i.visible=t,this._notifyDirty())}preSubmit(e){const t=e.camera.eye;this.visibleObjects.forAll(e=>e.renderable.meta.cameraDepthSquared=n(t,e.obb.center))}getMaterial(e){return e.renderable.material}updateMaterial(e,t){const i=e.renderable.material;t(i),i.dirty&&this._notifyDirty()}setAllComponentVisibilities(e,t){const i=e;i.componentData.visibility.reset(t),i.componentData.markVisibilityDirty(),this._notifyDirty()}forEachVisibleComponent(e,t){return e.componentData.visibility.forEachComponent(t)}getComponentCount(e){const t=e,i=t.componentData.visibility.componentCount;return{visible:i,invisible:t.componentData.count-i}}setComponentData(e,t){const i=e,{renderable:o,componentData:n}=i,r=o.material,s=n.materialDataBuffer,a=n.materialDataIndices,c=new _,l=s.textureBuffer,h=l.getVec5Field("colorAndCastShadows"),p=l.getScalarField("elevationOffset"),g=l.getScalarField("emissiveStrength"),u=l.getScalarField("emissiveSourceMode"),d=l.getVec4Field("oidColor"),b=new Uint8Array(4),v=new Uint32Array(b.buffer);let y=0,w=0,x=0,j=0,O=0,B=n.verticalOffsets,A=1/0,P=-1/0,V=!1,E=!1,H=!1,U=0,k=!1;for(let f=0;f<n.count;f++){t(f,c),y+=+(c.externalColor[3]<1),w+=+(3===c.externalColorMixMode&&1===c.externalColor[3]),j+=+(c.emissiveStrength>0),O+=+(1===c.emissiveSource),E||=1!==c.emissiveStrength,x+=+c.castShadows,m(c.externalColor,c.externalColorMixMode,b),h.setValues(a[f],b[0],b[1],b[2],b[3],+c.castShadows),V||=f>0&&(U!==v[0]||k!==c.castShadows),U=v[0],k=c.castShadows,H||=0!==c.elevationOffset,H&&null==B&&(B=new Array(f).fill(0)),null!=B&&(B[f]=c.elevationOffset),A=Math.min(A,c.elevationOffset),P=Math.max(P,c.elevationOffset),p.set(a[f],c.elevationOffset),g.set(a[f],c.emissiveStrength),u.set(a[f],0===c.emissiveSource?0:255);const e=c.olidColor;null!=e&&d.setArray(a[f],e),c.pickable!==D(n.pickability,f)&&R(n,f,c.pickable)}n.verticalOffsets=H?B:null,i.offsetObb=H?f(i.obb,A,P,this._viewingMode,i.offsetObb??i.obb.clone()):null,V||H||S()||(E||O>0)&&j>0?(r.componentParameters=new C,r.componentParameters.castShadows=I(x,n.count),r.componentParameters.transparent=I(y,n.count),r.componentParameters.opaqueOverride=I(w,n.count),r.componentParameters.emissiveOverride=I(j,n.count),r.componentParameters.emissiveSourceOverride=I(O,n.count),r.textureBackedBufferParameters.textureBackedBuffer=l,l.updateTexture()):(r.componentParameters=new M,r.componentParameters.castShadows=c.castShadows?0:2,r.componentParameters.externalColor=c.externalColor,r.componentParameters.externalColorMixMode=c.externalColorMixMode,r.componentParameters.emissiveStrength=c.emissiveStrength,r.componentParameters.emissiveSource=c.emissiveSource,r.textureBackedBufferParameters.textureBackedBuffer=null),this._elevationRangeCacheVerticalOffset=NaN,this._notifyDirty()}getComponentAabb(e,t,i,o=!1){e.intersectionGeometry.getComponentAabb(t,i);const n=e,r=n.componentData.verticalOffsets;if(o||null==r)return i;const s=r[t];if(2===this._viewingMode||0===s)return i[2]+=s,i[5]+=s,i;const a=A(s);return a.localOrigin=n.transform.position,a.applyToAabb(i)}getComponentObb(e){return e.obb}getObjectTransform(e){return e.transform}getComponentPositions(e,t,i){return e.intersectionGeometry.getComponentPositions(t,i)}expandRangeWithComponentObjectElevationRange(e,t,i,o){Number.isNaN(this._elevationRangeCacheVerticalOffset)||this._elevationRangeCacheVerticalOffset!==t||o.expandElevationRangeValues(this._elevationRangeCacheMin,this._elevationRangeCacheMax);const n=e,r=n.componentData,s=r.count,a=r.verticalOffsets,c=n.intersectionGeometry,l=2===this._viewingMode,m=c.getComponentAabbs(),f=G;let h=1/0,p=-1/0;for(let g=0;g<s;g++){const e=6*g,r=a?.[g]??0;let s=1/0,c=-1/0;if(l)s=m[e+2]+r+t,c=m[e+5]+r+t;else{if(f[0]=m[e],f[1]=m[e+1],f[2]=m[e+2],f[3]=m[e+3],f[4]=m[e+4],f[5]=m[e+5],0!==r){const e=A(r);e.localOrigin=n.transform.position,e.applyToAabb(f)}const s=Math.max(Math.abs(f[3]),Math.abs(f[0])),a=Math.max(Math.abs(f[4]),Math.abs(f[1])),c=t+f[5]+i;o.expandElevationRangeValues(t+f[2],Math.sqrt(s*s+a*a+c*c)-i)}o.expandElevationRangeValues(s,c),h=Math.min(h,s),p=Math.max(p,c)}this._elevationRangeCacheVerticalOffset=t,this._elevationRangeCacheMin=h,this._elevationRangeCacheMax=p}intersect(e,t,i,o,n,r){const s=e,{transform:a,componentData:c,intersectionGeometry:l}=s;return null!=o&&(o.localOrigin=a.position),l.intersect(t,i,o,c.verticalOffsets,a,n,r)}addEdges(e,t,i,o,n){const r=e,{indices:s,positions:a}=r.intersectionGeometry,c=r.componentData.offsets;return t.addComponentObject(r,a,s,c,i,o,n)}async extractEdgeInformation(e,t,i){const o=e,n=o.componentData.visibility;if(n.allInvisible()){const{extractComponentsEdgeLocationsLayout:e}=await import("../../lib/edgeRendering/edgeProcessing.js");return{buffer:e.createBuffer(0),origin:[0,0,0]}}const{indices:s,positions:a}=o.intersectionGeometry,m=o.componentData.offsets,{EdgeInputBufferLayout:f}=await import("../../lib/edgeRendering/bufferLayouts.js"),h=f.createBuffer(a.length/3);l(h.position.typedBuffer,a,h.position.typedBufferStride,3),c(h.position,h.position,o.transform.rotationScale),this._setComponentIndices(h.componentIndex,s,m);const p=h.count,g=this._computeVisibilityIndices(s,n,m,p);return{origin:r(o.transform.position),buffer:await t.extractComponentsEdgeLocations({indices:g,indicesLength:g.length,skipDeduplicate:!0,data:h,writerSettings:{reducedPrecision:!1,variants:0}},i)}}_setComponentIndices(e,t,i){let o=0;for(let n=0;n<i.length-1;n++){const r=i[n],s=i[n+1];for(let i=r;i<s;i++){const n=t?t[i]:i;e.set(n,o)}o++}}_computeVisibilityIndices(e,t,i,n){if(e&&t.allVisible())return e;let r=0;t.forEachComponentRange((e,t)=>(r+=i[t]-i[e],!0));const s=o(e)?2===e?.BYTES_PER_ELEMENT||n<=65536?new Uint16Array(r):new Uint32Array(r):new Array(r);let a=0;return t.forEachComponentRange((t,o)=>{const n=i[t],r=i[o];for(let i=n;i<r;i++)s[a++]=e?e[i]:i;return!0}),s}addComponentHighlight(e,i,o){const n=e.componentData,r=t(n.componentHighlights,o,()=>new Uint32Array(n.count+1));{const e=this._activeHighlightOptions.get(o)??0;this._activeHighlightOptions.set(o,e+1)}0===r[i]++&&(n.markHighlightsDirty(),this._notifyDirty()),r[n.count]++}removeComponentHighlight(e,t,i){const{componentData:o}=e,n=o.componentHighlights.get(i);if(void 0===n)return void U().warn("Removing non-existing highlight.");const r=n[t];if(0===r)return void U().warn("Removing non-existing highlight.");this._removeActiveHighlight(i);const s=n[o.count];if(r>1)return n[t]=r-1,void(n[o.count]=s-1);n[t]=0,1===s?o.componentHighlights.delete(i):n[o.count]=s-1,o.markHighlightsDirty(),this._notifyDirty()}_removeActiveHighlight(e,t=1){const i=this._activeHighlightOptions.get(e);if(void 0===i)U().warn("Removing non-existing highlight.");else{const o=i-t;o<0&&U().warn("Removing non-existing highlight."),o<=0?this._activeHighlightOptions.delete(e):this._activeHighlightOptions.set(e,o)}}clearHighlights(e){const{componentData:t}=e,{componentHighlights:i}=t;if(i.size>0){for(const e of i)this._removeActiveHighlight(e[0],e[1][t.count]);i.clear(),t.markHighlightsDirty(),this._notifyDirty()}}hasHighlight(e){return this._activeHighlightOptions.has(e)}getObjectGPUMemoryUsage(e){return e.renderable.meta.gpuMemoryEstimate}get visibleObjects(){return this._visible}_createRenderable(e,t){const i=this._renderManager.rctx,o=e.geometry,n=o.vertices.layoutParameters,r=h(y(n)),s=new H(i,r,o.vertices.data),a=o.indices?V.createIndex(i,35044,o.indices):null,c=new Uint16Array(o.vertices.count);for(let h=0;h<t.count;h++){const e=t.offsets[h],i=t.offsets[h+1],n=t.materialDataIndices[h];if(null!=o.indices)for(let t=e;t<i;t++){c[o.indices[t]]=n}else for(let t=e;t<i;t++)c[t]=n}const l=new H(i,x,c.buffer),m=new w(e.transform,e.toMapSpace,e.obb.radius<L),f=new B(i,new Map([["geometry",s],["componentIndices",l]]),a),p=new b(f,E.TRIANGLES,n,null!=a),g={cameraDepthSquared:.5,gpuMemoryEstimate:s.usedMemory+l.usedMemory+(null!=a?a.usedMemory:0)};return new d(m,p,g)}_notifyDirty(){this._renderManager.notifyDirty()}}function I(e,t){return e===t?0:0===e?2:1}function N(){const e=[{name:"colorAndCastShadows",type:"u8u8u7xu8"},{name:"elevationOffset",type:"packed-f32",maxValue:j},{name:"emissiveStrength",type:"packed-f24",maxValue:O},{name:"emissiveSourceMode",type:"u8"}];return S()&&e.push({name:"oidColor",type:"vec4u8"}),e}const G=s(),L=5e4;export{k as ComponentObjectCollection};
5
+ import"../../../../../core/has.js";import e from"../../../../../core/Logger.js";import{getOrCreateMapValue as t}from"../../../../../core/MapUtils.js";import i from"../../../../../core/PooledArray.js";import{isTypedArray as o}from"../../../../../core/typedArrayUtil.js";import{s as n}from"../../../../../chunks/vec32.js";import{clone as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as s}from"../../../../../geometry/support/aaBoundingBox.js";import{compactIndices as a}from"../../../../../geometry/support/Indices.js";import{c}from"../../../../../chunks/vec3.js";import{c as l}from"../../../../../chunks/vec33.js";import{encodeSymbolColor as m}from"../../../layers/support/symbolColorUtils.js";import{computeOffsetObb as f}from"../../../support/orientedBoundingBox.js";import{glLayout as h}from"../../../support/buffer/glUtil.js";import{ComponentData as p}from"./ComponentData.js";import{ComponentObject as g}from"./ComponentObject.js";import{IntersectionGeometry as u}from"./IntersectionGeometry.js";import{Renderable as d}from"./Renderable.js";import{RenderGeometry as b}from"./RenderGeometry.js";import{RenderSubmitSystem as v}from"./RenderSubmitSystem.js";import{createVertexBufferLayout as y}from"./SourceGeometry.js";import{UniformComponentParameters as _}from"./UniformComponentParameters.js";import{ComponentParametersVarying as C,ComponentParametersUniform as M,ComponentMaterial as w}from"./Material/ComponentMaterial.js";import{indexGlLayout as x}from"./Material/ComponentTechnique.js";import{maxElevationOffset as j,maxPackedRGBEmission as O}from"./Material/shader/ComponentData.glsl.js";import{olidEnabled as S}from"../../effects/geometry/olidUtils.js";import{getVisibility as D,updatePickabilityWithCount as R}from"../../lib/ComponentUtils.js";import{VertexArrayObject as B}from"../../lib/VertexArrayObject.js";import{getVerticalOffsetI3S as A}from"../../lib/verticalOffsetUtils.js";import{BufferManager as P}from"../../lib/TextureBackedBuffer/BufferManager.js";import{BufferObject as V}from"../../../../webgl/BufferObject.js";import{PrimitiveType as E}from"../../../../webgl/enums.js";import{VertexBuffer as H}from"../../../../webgl/VertexBuffer.js";const U=()=>e.getLogger("esri.views.3d.webgl-engine.collections.Component.ComponentObjectCollection");class k{constructor(e,t,o){this._renderManager=e,this._viewingMode=t,this._sphericalSpatialReference=o,this._elevationRangeCacheVerticalOffset=NaN,this._elevationRangeCacheMin=NaN,this._elevationRangeCacheMax=NaN,this._activeHighlightOptions=new Map,this._visible=new i,this._hidden=new i,this._renderSubmit=new v(this),this._renderManager.register(this._renderSubmit),this._componentBufferManager=new P(e.rctx,N())}destroy(){this._componentBufferManager.destroy(),this._componentBufferManager=null,this._visible.forAll(e=>e.destroy()),this._visible.prune(),this._hidden.forAll(e=>e.destroy()),this._hidden.prune(),this._renderSubmit.destroy()}createObject(e){const{geometry:t}=e,i=new p(this._componentBufferManager,a(t.componentOffsets)),o=this._createRenderable(e,i),n=new u(this._viewingMode,t.positionData,i,e.elevationAlignable),r=new g(e.transform,e.obb.clone(),i,o,n);return(r.visible?this._visible:this._hidden).push(r),r}destroyObject(e){const t=e;(t.visible?this._visible:this._hidden).removeUnordered(t),t.destroy(),this._notifyDirty()}setObjectVisibility(e,t){const i=e;t!==i.visible&&(t?(this._hidden.removeUnordered(i),this._visible.push(i)):(this._visible.removeUnordered(i),this._hidden.push(i)),i.visible=t,this._notifyDirty())}preSubmit(e){const t=e.camera.eye;this.visibleObjects.forAll(e=>e.renderable.meta.cameraDepthSquared=n(t,e.obb.center))}getMaterial(e){return e.renderable.material}updateMaterial(e,t){const i=e.renderable.material;t(i),i.dirty&&this._notifyDirty()}setAllComponentVisibilities(e,t){const i=e;i.componentData.visibility.reset(t),i.componentData.markVisibilityDirty(),this._notifyDirty()}forEachVisibleComponent(e,t){return e.componentData.visibility.forEachComponent(t)}getComponentCount(e){const t=e,i=t.componentData.visibility.componentCount;return{visible:i,invisible:t.componentData.count-i}}setComponentData(e,t){const i=e,{renderable:o,componentData:n}=i,r=o.material,s=n.materialDataBuffer,a=n.materialDataIndices,c=new _,l=s.textureBuffer,h=l.getVec5Field("colorAndCastShadows"),p=l.getScalarField("elevationOffset"),g=l.getScalarField("emissiveStrength"),u=l.getScalarField("emissiveSourceMode"),d=l.getVec4Field("oidColor"),b=new Uint8Array(4),v=new Uint32Array(b.buffer);let y=0,w=0,x=0,j=0,O=0,B=n.verticalOffsets,A=1/0,P=-1/0,V=!1,E=!1,H=!1,U=0,k=!1;for(let f=0;f<n.count;f++){t(f,c),y+=+(c.externalColor[3]<1),w+=+(3===c.externalColorMixMode&&1===c.externalColor[3]),j+=+(c.emissiveStrength>0),O+=+(1===c.emissiveSource),E||=1!==c.emissiveStrength,x+=+c.castShadows,m(c.externalColor,c.externalColorMixMode,b),h.setValues(a[f],b[0],b[1],b[2],b[3],+c.castShadows),V||=f>0&&(U!==v[0]||k!==c.castShadows),U=v[0],k=c.castShadows,H||=0!==c.elevationOffset,H&&null==B&&(B=new Array(f).fill(0)),null!=B&&(B[f]=c.elevationOffset),A=Math.min(A,c.elevationOffset),P=Math.max(P,c.elevationOffset),p.set(a[f],c.elevationOffset),g.set(a[f],c.emissiveStrength),u.set(a[f],0===c.emissiveSource?0:255);const e=c.olidColor;null!=e&&d.setArray(a[f],e),c.pickable!==D(n.pickability,f)&&R(n,f,c.pickable)}n.verticalOffsets=H?B:null,i.offsetObb=H?f(i.obb,A,P,this._viewingMode,i.offsetObb??i.obb.clone()):null,V||H||S()||(E||O>0)&&j>0?(r.componentParameters=new C,r.componentParameters.castShadows=I(x,n.count),r.componentParameters.transparent=I(y,n.count),r.componentParameters.opaqueOverride=I(w,n.count),r.componentParameters.emissiveOverride=I(j,n.count),r.componentParameters.emissiveSourceOverride=I(O,n.count),r.textureBackedBufferParameters.textureBackedBuffer=l,l.updateTexture()):(r.componentParameters=new M,r.componentParameters.castShadows=c.castShadows?0:2,r.componentParameters.externalColor=c.externalColor,r.componentParameters.externalColorMixMode=c.externalColorMixMode,r.componentParameters.emissiveStrength=c.emissiveStrength,r.componentParameters.emissiveSource=c.emissiveSource,r.textureBackedBufferParameters.textureBackedBuffer=null),this._elevationRangeCacheVerticalOffset=NaN,this._notifyDirty()}getComponentAabb(e,t,i,o=!1){e.intersectionGeometry.getComponentAabb(t,i);const n=e,r=n.componentData.verticalOffsets;if(o||null==r)return i;const s=r[t];if(2===this._viewingMode||0===s)return i[2]+=s,i[5]+=s,i;const a=A(s);return a.localOrigin=n.transform.position,a.applyToAabb(i)}getComponentObb(e){return e.obb}getObjectTransform(e){return e.transform}getComponentPositions(e,t,i){return e.intersectionGeometry.getComponentPositions(t,i)}expandRangeWithComponentObjectElevationRange(e,t,i,o){Number.isNaN(this._elevationRangeCacheVerticalOffset)||this._elevationRangeCacheVerticalOffset!==t||o.expandElevationRangeValues(this._elevationRangeCacheMin,this._elevationRangeCacheMax);const n=e,r=n.componentData,s=r.count,a=r.verticalOffsets,c=n.intersectionGeometry,l=2===this._viewingMode,m=c.getComponentAabbs(),f=G;let h=1/0,p=-1/0;for(let g=0;g<s;g++){const e=6*g,r=a?.[g]??0;let s=1/0,c=-1/0;if(l)s=m[e+2]+r+t,c=m[e+5]+r+t;else{if(f[0]=m[e],f[1]=m[e+1],f[2]=m[e+2],f[3]=m[e+3],f[4]=m[e+4],f[5]=m[e+5],0!==r){const e=A(r);e.localOrigin=n.transform.position,e.applyToAabb(f)}const s=Math.max(Math.abs(f[3]),Math.abs(f[0])),a=Math.max(Math.abs(f[4]),Math.abs(f[1])),c=t+f[5]+i;o.expandElevationRangeValues(t+f[2],Math.sqrt(s*s+a*a+c*c)-i)}o.expandElevationRangeValues(s,c),h=Math.min(h,s),p=Math.max(p,c)}this._elevationRangeCacheVerticalOffset=t,this._elevationRangeCacheMin=h,this._elevationRangeCacheMax=p}intersect(e,t,i,o,n,r){const s=e,{transform:a,componentData:c,intersectionGeometry:l}=s;return null!=o&&(o.localOrigin=a.position),l.intersect(t,i,o,c.verticalOffsets,a,n,r)}addEdges(e,t,i,o,n){const r=e,{indices:s,positions:a}=r.intersectionGeometry,c=r.componentData.offsets;return t.addComponentObject(r,a,s,c,i,o,n)}async extractEdgeInformation(e,t,i){const o=e,n=o.componentData.visibility;if(n.allInvisible()){const{extractComponentsEdgeLocationsLayout:e}=await import("../../lib/edgeRendering/edgeProcessing.js");return{buffer:e.createBuffer(0),origin:[0,0,0]}}const{indices:s,positions:a}=o.intersectionGeometry,m=o.componentData.offsets,{EdgeInputBufferLayout:f}=await import("../../lib/edgeRendering/bufferLayouts.js"),h=f.createBuffer(a.length/3);l(h.position.typedBuffer,a,h.position.typedBufferStride,3),c(h.position,h.position,o.transform.rotationScale),this._setComponentIndices(h.componentIndex,s,m);const p=h.count,g=this._computeVisibilityIndices(s,n,m,p);return{origin:r(o.transform.position),buffer:await t.extractComponentsEdgeLocations({indices:g,indicesLength:g.length,skipDeduplicate:!0,data:h,writerSettings:{reducedPrecision:!1,variants:0}},i)}}_setComponentIndices(e,t,i){let o=0;for(let n=0;n<i.length-1;n++){const r=i[n],s=i[n+1];for(let i=r;i<s;i++){const n=t?t[i]:i;e.set(n,o)}o++}}_computeVisibilityIndices(e,t,i,n){if(e&&t.allVisible())return e;let r=0;t.forEachComponentRange((e,t)=>(r+=i[t]-i[e],!0));const s=o(e)?2===e?.BYTES_PER_ELEMENT||n<=65536?new Uint16Array(r):new Uint32Array(r):new Array(r);let a=0;return t.forEachComponentRange((t,o)=>{const n=i[t],r=i[o];for(let i=n;i<r;i++)s[a++]=e?e[i]:i;return!0}),s}addComponentHighlight(e,i,o){const n=e.componentData,r=t(n.componentHighlights,o,()=>new Uint32Array(n.count+1));{const e=this._activeHighlightOptions.get(o)??0;this._activeHighlightOptions.set(o,e+1)}0===r[i]++&&(n.markHighlightsDirty(),this._notifyDirty()),r[n.count]++}removeComponentHighlight(e,t,i){const{componentData:o}=e,n=o.componentHighlights.get(i);if(void 0===n)return void U().warn("Removing non-existing highlight.");const r=n[t];if(0===r)return void U().warn("Removing non-existing highlight.");this._removeActiveHighlight(i);const s=n[o.count];if(r>1)return n[t]=r-1,void(n[o.count]=s-1);n[t]=0,1===s?o.componentHighlights.delete(i):n[o.count]=s-1,o.markHighlightsDirty(),this._notifyDirty()}_removeActiveHighlight(e,t=1){const i=this._activeHighlightOptions.get(e);if(void 0===i)U().warn("Removing non-existing highlight.");else{const o=i-t;o<0&&U().warn("Removing non-existing highlight."),o<=0?this._activeHighlightOptions.delete(e):this._activeHighlightOptions.set(e,o)}}clearHighlights(e){const{componentData:t}=e,{componentHighlights:i}=t;if(i.size>0){for(const e of i)this._removeActiveHighlight(e[0],e[1][t.count]);i.clear(),t.markHighlightsDirty(),this._notifyDirty()}}hasHighlight(e){return this._activeHighlightOptions.has(e)}getObjectGPUMemoryUsage(e){return e.renderable.meta.gpuMemoryEstimate}get visibleObjects(){return this._visible}_createRenderable(e,t){const i=this._renderManager.rctx,o=e.geometry,n=o.vertices.layoutParameters,r=h(y(n)),s=new H(i,r,o.vertices.data),a=o.indices?V.createIndex(i,35044,o.indices):null,c=new Uint16Array(o.vertices.count);for(let h=0;h<t.count;h++){const e=t.offsets[h],i=t.offsets[h+1],n=t.materialDataIndices[h];if(null!=o.indices)for(let t=e;t<i;t++){c[o.indices[t]]=n}else for(let t=e;t<i;t++)c[t]=n}const l=new H(i,x,c.buffer),m=new w(e.transform,e.toMapSpace,e.obb.radius<L,this._sphericalSpatialReference),f=new B(i,new Map([["geometry",s],["componentIndices",l]]),a),p=new b(f,E.TRIANGLES,n,null!=a),g={cameraDepthSquared:.5,gpuMemoryEstimate:s.usedMemory+l.usedMemory+(null!=a?a.usedMemory:0)};return new d(m,p,g)}_notifyDirty(){this._renderManager.notifyDirty()}}function I(e,t){return e===t?0:0===e?2:1}function N(){const e=[{name:"colorAndCastShadows",type:"u8u8u7xu8"},{name:"elevationOffset",type:"packed-f32",maxValue:j},{name:"emissiveStrength",type:"packed-f24",maxValue:O},{name:"emissiveSourceMode",type:"u8"}];return S()&&e.push({name:"oidColor",type:"vec4u8"}),e}const G=s(),L=5e4;export{k as ComponentObjectCollection};
@@ -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{invert as t,transpose as r}from"../../../../../../core/libs/gl-matrix-2/math/mat3.js";import{clone as s}from"../../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{I as o,q as i}from"../../../../../../chunks/vec32.js";import{freeze as a,ZEROS as l}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{v as n}from"../../../../../../chunks/vec42.js";import{freeze as h,fromValues as u}from"../../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{ComponentTechnique as c}from"./ComponentTechnique.js";import{ComponentTechniqueConfiguration as p}from"./ComponentTechniqueConfiguration.js";import{parameter as d,parameterBlock as m,MaterialBase as v,MaterialParameterBlock as x}from"../../../core/material/MaterialBase.js";import{TextureBackedBufferParameters as g}from"../../../core/shaderLibrary/TextureBackedBuffer.glsl.js";import{TwoVectorPosition as f}from"../../../core/util/TwoVectorPosition.js";import{advancedMRRFactors as y}from"../../../materials/pbrUtils.js";import{defaultHighlightName as M}from"../../../../../support/HighlightDefaults.js";import{alphaCutoff as b}from"../../../../../../webscene/support/AlphaCutoff.js";class T extends v{constructor(e,o,i){super(),this.toMapSpace=o,this.useENUForGlobalOverlayUV=i,this.baseColor=h(1,1,1,1),this.usePBR=!1,this.hasParametersFromSource=!1,this.sphereDepthInterpolate=!1,this.mrrFactors=y,this.baseColorTexture=null,this.metallicRoughnessTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.emissionTexture=null,this.emissiveBaseColor=a(0,0,0),this.emissiveStrength=0,this.commonMaterialParameters=new S,this.componentParameters=new w,this.textureBackedBufferParameters=new g,this.objectOpacity=1,this.textureAlphaCutoff=b,this.alphaDiscardMode=1,this.isIntegratedMesh=!1,this.polygonOffsetEnabled=!1,this.ellipsoidMode=1,this.hasOccludees=!1;const l=new f(e.position),n=s(e.rotationScale);t(n,n),r(n,n),this.transformNormalGlobalFromModel=n,this.transformWorldFromModelTL=l.low,this.transformWorldFromModelTH=l.high,this.transformWorldFromModelRS=e.rotationScale}dispose(){this.baseColorTexture=null,this.metallicRoughnessTexture=null,this.emissionTexture=null,this.occlusionTexture=null,this.normalTexture=null}get _hasEmissiveBase(){return null!=this.emissionTexture||!i(this.emissiveBaseColor,l)}get _hasEmissiveStrength(){return 2!==this.componentParameters.emissiveOverride}get hasEmissions(){return this._hasEmissiveStrength&&(this._hasEmissiveBase||2!==this.componentParameters.emissiveSourceOverride)}get texture(){return this.baseColorTexture?.glTexture}get textureMetallicRoughness(){return this.metallicRoughnessTexture?.glTexture}get textureEmissive(){return this.emissionTexture?.glTexture}get textureOcclusion(){return this.occlusionTexture?.glTexture}get textureNormal(){return this.normalTexture?.glTexture}acquireTechnique(e,t,r,s){const o=new p(e.context.spherical,e.context.sphericalSR);o.renderOccluded=9===r.slot,o.hasVertexColors=s.hasVertexColors,o.hasNormals=s.hasNormals,o.textureCoordinateType=s.textureCoordinateType,o.hasMetallicRoughnessTexture=null!=this.metallicRoughnessTexture,o.hasOcclusionTexture=null!=this.occlusionTexture,o.hasNormalTexture=null!=this.normalTexture,o.sphereDepthInterpolate=this.sphereDepthInterpolate&&1===e.viewingMode,o.oitPass=0===t.identifier&&null!=r.oitPass?r.oitPass:0,o.terrainDepthTest=0===t.identifier&&r.terrainDepthTest,o.cullAboveTerrain=0===t.identifier&&r.cullAboveTerrain,o.ellipsoidMode=this.ellipsoidMode,o.componentData=this.componentParameters.type,o.textureBackedBufferLayout=this.textureBackedBufferParameters.textureBackedBuffer?.layout.hash??0,o.cullFace=this.commonMaterialParameters.cullFace,o.doubleSidedMode=this.commonMaterialParameters.doubleSided?1:0,o.hasColorTexture=null!=this.baseColorTexture;const i=this._computeWhichMaterialPass();o.blendingEnabled=1===i||2===i,o.alphaDiscardMode=this.alphaDiscardMode,o.integratedMeshMode=this.isIntegratedMesh?D(r)?C(r)?3:2:1:0,o.hasPolygonOffset=this.polygonOffsetEnabled,o.pbrMode=3===o.integratedMeshMode?4:this.usePBR?this.hasParametersFromSource?s.shadeNormals&&this.isIntegratedMesh?0:2:1:0;const a=1===this.componentParameters.emissiveSourceOverride,l=2===this.componentParameters.emissiveSourceOverride,n=null!=this.emissionTexture;if(o.emissionSource=this.hasEmissions?this._hasEmissiveBase&&1===o.pbrMode?l?n?4:2:a?n?5:7:6:a?7:6:0,o.shadeNormals=s.shadeNormals,o.normalType=o.hasNormals?1:2,o.hasSlicePlane=null!=r.slicePlane&&this.commonMaterialParameters.hasSlicePlane,o.receiveAmbientOcclusion=o.hasOccludees=o.receiveShadows=o.screenSpaceReflections=o.cloudReflections=o.hasHighlightMixTexture=!1,1===t.identifier)o.output=4,o.vertexDiscardMode=0;else if(3===t.identifier)o.output=7,o.vertexDiscardMode=0;else if(2===t.identifier)o.output=9,o.vertexDiscardMode=0,o.hasHighlightMixTexture=null!=r.highlightMixTexture;else{switch(o.vertexDiscardMode=2===i?t.transparent?2:1:0,o.output=t.output,t.output){case 0:case 1:o.receiveAmbientOcclusion=s.applySSAO&&null!=r.ssao?.getTexture(),o.hasOccludees=r.hasOccludees,o.receiveShadows=r.shadowMap.ready,o.screenSpaceReflections=null!=r.ssr.lastFrameColor,o.cloudReflections=null!=r.clouds.data?.cubeMap?.colorTexture;break;case 10:o.olidColor=!0}o.snowCover=r.snowCover>0}const h=e.get(c,o);return this._setClean(),h}submit(e,t,r){if(this.objectOpacity<=0)return;const{componentData:s,renderable:o}=r,{geometry:i}=o,a=o.meta.cameraDepthSquared;s.updateHighlights(t.highlights);const{geometryRanges:l,highlightRangesMap:n,shadowmapRanges:h}=s;switch(this._computeWhichMaterialPass()){case 0:e.opaque.submitDraw(this,i,l,a);break;case 1:e.transparent.submitDraw(this,i,l,a);break;case 2:e.opaque.submitDraw(this,i,l,a),e.transparent.submitDraw(this,i,l,a);break;case 3:e.integratedMesh.submitDraw(this,i,l,a),B(t)&&e.occludedGround.submitDraw(this,i,l,a),P(t)&&e.highlightIntegratedMesh.submitDraw(this,i,l,a);break;case 4:e.transparentIntegratedMesh.submitDraw(this,i,l,a)}if(2!==this.componentParameters.castShadows){if(null!=n)for(const t of n)t[0]===M&&e.highlightShadowMap.submitDraw(this,i,t[1],a,t[0]);null!=h&&e.defaultShadowMap.submitDraw(this,i,h,a),e.shadowMap.submitDraw(this,i,l,a)}if(null!=n)for(const u of n)e.highlight.submitDraw(this,i,u[1],a,u[0]);t.viewshedEnabled&&e.viewshedShadowMap.submitDraw(this,i,l,a)}_computeWhichMaterialPass(){if(this.isIntegratedMesh&&this.objectOpacity>=1)return 3;if(this.isIntegratedMesh&&this.objectOpacity<1)return 4;if(this.objectOpacity<1)return 1;if(0===this.componentParameters.opaqueOverride)return 0;if(this.baseColor[3]<1||0===this.alphaDiscardMode||3===this.alphaDiscardMode)return 1;switch(this.componentParameters.transparent){case 2:return 0;case 0:return 1;case 1:return 2}}}e([d({vectorOps:n})],T.prototype,"baseColor",void 0),e([d()],T.prototype,"usePBR",void 0),e([d()],T.prototype,"hasParametersFromSource",void 0),e([d()],T.prototype,"sphereDepthInterpolate",void 0),e([d({vectorOps:o})],T.prototype,"mrrFactors",void 0),e([d({dispose:!0})],T.prototype,"baseColorTexture",void 0),e([d({dispose:!0})],T.prototype,"metallicRoughnessTexture",void 0),e([d({dispose:!0})],T.prototype,"normalTexture",void 0),e([d({dispose:!0})],T.prototype,"occlusionTexture",void 0),e([d({dispose:!0})],T.prototype,"emissionTexture",void 0),e([d({vectorOps:o})],T.prototype,"emissiveBaseColor",void 0),e([d()],T.prototype,"emissiveStrength",void 0),e([m()],T.prototype,"commonMaterialParameters",void 0),e([m()],T.prototype,"componentParameters",void 0),e([m()],T.prototype,"textureBackedBufferParameters",void 0),e([d()],T.prototype,"objectOpacity",void 0),e([d()],T.prototype,"textureAlphaCutoff",void 0),e([d()],T.prototype,"alphaDiscardMode",void 0),e([d()],T.prototype,"isIntegratedMesh",void 0),e([d()],T.prototype,"polygonOffsetEnabled",void 0),e([d()],T.prototype,"ellipsoidMode",void 0),e([d()],T.prototype,"hasOccludees",void 0);class S extends x{constructor(){super(...arguments),this.doubleSided=!1,this.cullFace=2,this.hasSlicePlane=!0}}e([d()],S.prototype,"doubleSided",void 0),e([d()],S.prototype,"cullFace",void 0),e([d()],S.prototype,"hasSlicePlane",void 0);class w extends x{constructor(){super(...arguments),this.externalColor=u(1,1,1,1),this.externalColorMixMode=1,this.emissiveStrength=0,this.emissiveSource=0,this.castShadows=0}get transparent(){return this.externalColor[3]<1?0:2}get opaqueOverride(){return 3===this.externalColorMixMode&&1===this.externalColor[3]?0:2}get emissiveOverride(){return this.emissiveStrength>0?0:2}get emissiveSourceOverride(){return 1===this.emissiveSource?0:2}get visible(){return this.externalColor[3]>0?0:2}get type(){return 0}}e([d({vectorOps:n})],w.prototype,"externalColor",void 0),e([d()],w.prototype,"externalColorMixMode",void 0),e([d()],w.prototype,"emissiveStrength",void 0),e([d()],w.prototype,"emissiveSource",void 0),e([d()],w.prototype,"castShadows",void 0);class O extends x{constructor(){super(...arguments),this.transparent=2,this.opaqueOverride=2,this.emissiveOverride=2,this.emissiveSourceOverride=2,this.castShadows=2}get type(){return 1}}function P(e){return null!=e.overlay?.getTexture(2)}function C(e){return null!=e.overlay?.getTexture(3)}function D(e){return null!=e.overlay?.getTexture(1)}function B(e){return null!=e.overlay?.getTexture(e.overlay?.allSourcesOccluders?1:4)}e([d()],O.prototype,"transparent",void 0),e([d()],O.prototype,"opaqueOverride",void 0),e([d()],O.prototype,"emissiveOverride",void 0),e([d()],O.prototype,"emissiveSourceOverride",void 0),e([d()],O.prototype,"castShadows",void 0);export{S as CommonMaterialParameters,T as ComponentMaterial,w as ComponentParametersUniform,O as ComponentParametersVarying};
5
+ import{__decorate as e}from"tslib";import{invert as t,transpose as r}from"../../../../../../core/libs/gl-matrix-2/math/mat3.js";import{clone as s}from"../../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{I as o,q as i}from"../../../../../../chunks/vec32.js";import{freeze as a,ZEROS as n}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{v as l}from"../../../../../../chunks/vec42.js";import{freeze as h,fromValues as u}from"../../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{ComponentTechnique as p}from"./ComponentTechnique.js";import{ComponentTechniqueConfiguration as c}from"./ComponentTechniqueConfiguration.js";import{parameter as d,parameterBlock as m,MaterialBase as v,MaterialParameterBlock as g}from"../../../core/material/MaterialBase.js";import{isColorOrColorEmission as f}from"../../../core/shaderLibrary/ShaderOutput.js";import{TextureBackedBufferParameters as x}from"../../../core/shaderLibrary/TextureBackedBuffer.glsl.js";import{TwoVectorPosition as y}from"../../../core/util/TwoVectorPosition.js";import{advancedMRRFactors as M}from"../../../materials/pbrUtils.js";import{defaultHighlightName as b}from"../../../../../support/HighlightDefaults.js";import{alphaCutoff as T}from"../../../../../../webscene/support/AlphaCutoff.js";class S extends v{constructor(e,o,i,n){super(),this.toMapSpace=o,this.useENUForGlobalOverlayUV=i,this.baseColor=h(1,1,1,1),this.usePBR=!1,this.hasParametersFromSource=!1,this.sphereDepthInterpolate=!1,this.mrrFactors=M,this.baseColorTexture=null,this.metallicRoughnessTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.emissionTexture=null,this.emissiveBaseColor=a(0,0,0),this.emissiveStrength=0,this.commonMaterialParameters=new C,this.componentParameters=new O,this.textureBackedBufferParameters=new x,this.objectOpacity=1,this.textureAlphaCutoff=T,this.alphaDiscardMode=1,this.isIntegratedMesh=!1,this.polygonOffsetEnabled=!1,this.ellipsoidMode=1,this.hasOccludees=!1;const l=s(e.rotationScale);t(l,l),r(l,l),this.transformNormalGlobalFromModel=l;const u=new y(e.position);this.transformWorldFromModelTL=u.low,this.transformWorldFromModelTH=u.high,this.transformWorldFromModelRS=e.rotationScale,this._configuration=new c(n),this._updateMaterialConfiguration()}dispose(){this.baseColorTexture=null,this.metallicRoughnessTexture=null,this.emissionTexture=null,this.occlusionTexture=null,this.normalTexture=null}get _hasEmissiveBase(){return null!=this.emissionTexture||!i(this.emissiveBaseColor,n)}get _hasEmissiveStrength(){return 2!==this.componentParameters.emissiveOverride}get hasEmissions(){return this._hasEmissiveStrength&&(this._hasEmissiveBase||2!==this.componentParameters.emissiveSourceOverride)}get texture(){return this.baseColorTexture?.texture}get textureMetallicRoughness(){return this.metallicRoughnessTexture?.texture}get textureEmissive(){return this.emissionTexture?.texture}get textureOcclusion(){return this.occlusionTexture?.texture}get textureNormal(){return this.normalTexture?.texture}acquireTechnique(e,t,r,s){const o=this._updateConfiguration(t,r,s);return e.get(p,o)}_updateConfiguration(e,t,r){return this._updateMaterialConfiguration(),this._updateDrawConfiguration(e,t,r)}_updateMaterialConfiguration(){if(!this.dirty)return;const e=this._configuration;e.hasMetallicRoughnessTexture=null!=this.metallicRoughnessTexture,e.hasOcclusionTexture=null!=this.occlusionTexture,e.hasNormalTexture=null!=this.normalTexture,e.sphereDepthInterpolate=this.sphereDepthInterpolate&&e.spherical,e.ellipsoidMode=this.ellipsoidMode,e.componentData=this.componentParameters.type,e.textureBackedBufferLayout=this.textureBackedBufferParameters.textureBackedBuffer?.layout.hash??0,e.cullFace=this.commonMaterialParameters.cullFace,e.doubleSidedMode=this.commonMaterialParameters.doubleSided?1:0,e.hasColorTexture=null!=this.baseColorTexture;const t=this._computeWhichMaterialPass();e.blendingEnabled=1===t||2===t,e.alphaDiscardMode=this.alphaDiscardMode,e.hasPolygonOffset=this.polygonOffsetEnabled,this._setClean()}_updateDrawConfiguration(e,t,r){const s=this._configuration,o=e.identifier;s.renderOccluded=9===t.slot,s.hasVertexColors=r.hasVertexColors,s.hasNormals=r.hasNormals,s.textureCoordinateType=r.textureCoordinateType;const i=0===o;s.oitPass=i?t.oitPass:0,s.terrainDepthTest=i&&t.terrainDepthTest,s.cullAboveTerrain=!!i&&t.cullAboveTerrain,s.integratedMeshMode=this.isIntegratedMesh?B(t)?D(t)?3:2:1:0,s.pbrMode=3===s.integratedMeshMode?4:this.usePBR?this.hasParametersFromSource?r.shadeNormals&&this.isIntegratedMesh?0:2:1:0;const a=1===this.componentParameters.emissiveSourceOverride,n=2===this.componentParameters.emissiveSourceOverride,l=null!=this.emissionTexture;s.emissionSource=this.hasEmissions?this._hasEmissiveBase&&1===s.pbrMode?n?l?4:2:a?l?5:7:6:a?7:6:0,s.shadeNormals=r.shadeNormals,s.normalType=s.hasNormals?1:2,s.hasSlicePlane=null!=t.slicePlane&&this.commonMaterialParameters.hasSlicePlane,s.hasHighlightMixTexture=2===o&&null!=t.highlightMixTexture,s.output=1===o?4:3===o?7:2===o?9:e.output,s.snowCover=i&&t.snowCover>0;const h=this._computeWhichMaterialPass();s.vertexDiscardMode=i&&2===h?e.transparent?2:1:0,s.olidColor=i&&10===e.output;const u=i&&f(e.output);return s.receiveAmbientOcclusion=u&&r.applySSAO&&null!=t.ssao?.getTexture(),s.hasOccludees=u&&t.hasOccludees,s.receiveShadows=u&&t.shadowMap.ready,s.screenSpaceReflections=u&&null!=t.ssr.lastFrameColor,s.cloudReflections=u&&null!=t.clouds.data?.cubeMap?.colorTexture,s}submit(e,t,r){if(this.objectOpacity<=0)return;const{componentData:s,renderable:o}=r,{geometry:i}=o,a=o.meta.cameraDepthSquared;s.updateHighlights(t.highlights);const{geometryRanges:n,highlightRangesMap:l,shadowmapRanges:h}=s,u=e=>e.submitDraw(this,i,n,a);switch(this._computeWhichMaterialPass()){case 0:u(e.opaque);break;case 1:u(e.transparent);break;case 2:u(e.opaque),u(e.transparent);break;case 3:u(e.integratedMesh),j(t)&&u(e.occludedGround),w(t)&&u(e.highlightIntegratedMesh);break;case 4:u(e.transparentIntegratedMesh)}if(2!==this.componentParameters.castShadows){if(null!=l)for(const t of l)t[0]===b&&e.highlightShadowMap.submitDraw(this,i,t[1],a,t[0]);null!=h&&e.defaultShadowMap.submitDraw(this,i,h,a),u(e.shadowMap)}if(null!=l)for(const p of l)e.highlight.submitDraw(this,i,p[1],a,p[0]);t.viewshedEnabled&&u(e.viewshedShadowMap)}_computeWhichMaterialPass(){if(this.isIntegratedMesh&&this.objectOpacity>=1)return 3;if(this.isIntegratedMesh&&this.objectOpacity<1)return 4;if(this.objectOpacity<1)return 1;if(0===this.componentParameters.opaqueOverride)return 0;if(this.baseColor[3]<1||0===this.alphaDiscardMode||3===this.alphaDiscardMode)return 1;switch(this.componentParameters.transparent){case 2:return 0;case 0:return 1;case 1:return 2}}}e([d({vectorOps:l})],S.prototype,"baseColor",void 0),e([d()],S.prototype,"usePBR",void 0),e([d()],S.prototype,"hasParametersFromSource",void 0),e([d()],S.prototype,"sphereDepthInterpolate",void 0),e([d({vectorOps:o})],S.prototype,"mrrFactors",void 0),e([d({dispose:!0})],S.prototype,"baseColorTexture",void 0),e([d({dispose:!0})],S.prototype,"metallicRoughnessTexture",void 0),e([d({dispose:!0})],S.prototype,"normalTexture",void 0),e([d({dispose:!0})],S.prototype,"occlusionTexture",void 0),e([d({dispose:!0})],S.prototype,"emissionTexture",void 0),e([d({vectorOps:o})],S.prototype,"emissiveBaseColor",void 0),e([d()],S.prototype,"emissiveStrength",void 0),e([m()],S.prototype,"commonMaterialParameters",void 0),e([m()],S.prototype,"componentParameters",void 0),e([m()],S.prototype,"textureBackedBufferParameters",void 0),e([d()],S.prototype,"objectOpacity",void 0),e([d()],S.prototype,"textureAlphaCutoff",void 0),e([d()],S.prototype,"alphaDiscardMode",void 0),e([d()],S.prototype,"isIntegratedMesh",void 0),e([d()],S.prototype,"polygonOffsetEnabled",void 0),e([d()],S.prototype,"ellipsoidMode",void 0),e([d()],S.prototype,"hasOccludees",void 0);class C extends g{constructor(){super(...arguments),this.doubleSided=!1,this.cullFace=2,this.hasSlicePlane=!0}}e([d()],C.prototype,"doubleSided",void 0),e([d()],C.prototype,"cullFace",void 0),e([d()],C.prototype,"hasSlicePlane",void 0);class O extends g{constructor(){super(...arguments),this.externalColor=u(1,1,1,1),this.externalColorMixMode=1,this.emissiveStrength=0,this.emissiveSource=0,this.castShadows=0}get transparent(){return this.externalColor[3]<1?0:2}get opaqueOverride(){return 3===this.externalColorMixMode&&1===this.externalColor[3]?0:2}get emissiveOverride(){return this.emissiveStrength>0?0:2}get emissiveSourceOverride(){return 1===this.emissiveSource?0:2}get visible(){return this.externalColor[3]>0?0:2}get type(){return 0}}e([d({vectorOps:l})],O.prototype,"externalColor",void 0),e([d()],O.prototype,"externalColorMixMode",void 0),e([d()],O.prototype,"emissiveStrength",void 0),e([d()],O.prototype,"emissiveSource",void 0),e([d()],O.prototype,"castShadows",void 0);class P extends g{constructor(){super(...arguments),this.transparent=2,this.opaqueOverride=2,this.emissiveOverride=2,this.emissiveSourceOverride=2,this.castShadows=2}get type(){return 1}}function w(e){return null!=e.overlay?.getTexture(2)}function D(e){return null!=e.overlay?.getTexture(3)}function B(e){return null!=e.overlay?.getTexture(1)}function j(e){return null!=e.overlay?.getTexture(e.overlay?.allSourcesOccluders?1:4)}e([d()],P.prototype,"transparent",void 0),e([d()],P.prototype,"opaqueOverride",void 0),e([d()],P.prototype,"emissiveOverride",void 0),e([d()],P.prototype,"emissiveSourceOverride",void 0),e([d()],P.prototype,"castShadows",void 0);export{C as CommonMaterialParameters,S as ComponentMaterial,O as ComponentParametersUniform,P as ComponentParametersVarying};
@@ -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{isColorEmissionHighlightOrOID as o}from"../../../core/shaderLibrary/ShaderOutput.js";import{parameter as t,ShaderTechniqueConfiguration as i}from"../../../core/shaderTechnique/ShaderTechniqueConfiguration.js";import{MAX_COUNT_TEXTURE_BACKED_BUFFER_LAYOUTS as s}from"../../../lib/TextureBackedBuffer/TextureBackedBufferLayout.js";class r extends i{constructor(e,o){super(),this.spherical=e,this.sphericalSR=o,this.output=0,this.textureCoordinateType=0,this.componentData=0,this.textureBackedBufferLayout=0,this.cullFace=2,this.vertexDiscardMode=0,this.doubleSidedMode=2,this.alphaDiscardMode=1,this.integratedMeshMode=0,this.oitPass=0,this.ellipsoidMode=1,this.pbrMode=0,this.normalType=0,this.emissionSource=0,this.hasVertexColors=!1,this.hasNormals=!1,this.shadeNormals=!0,this.hasSlicePlane=!1,this.hasColorTexture=!1,this.hasHighlightMixTexture=!1,this.receiveAmbientOcclusion=!0,this.receiveShadows=!0,this.blendingEnabled=!0,this.screenSpaceReflections=!1,this.hasPolygonOffset=!1,this.hasMetallicRoughnessTexture=!1,this.hasOcclusionTexture=!1,this.hasNormalTexture=!1,this.hasOccludees=!1,this.terrainDepthTest=!1,this.cullAboveTerrain=!1,this.hasNormalTextureTransform=!1,this.cloudReflections=!0,this.snowCover=!1,this.olidColor=!1,this.renderOccluded=!1,this.sphereDepthInterpolate=!1,this.discardInvisibleFragments=!1,this.occlusionPass=!1,this.bindType=2,this.useCustomDTRExponentForWater=!1,this.hasVertexTangents=!1,this.highStepCount=!1,this.instanced=!1,this.instancedDoublePrecision=!1,this.hasModelTransformation=!1,this.useFillLights=!0,this.draped=!1}get overlayEnabled(){return(2===this.integratedMeshMode||3===this.integratedMeshMode)&&o(this.output)}}e([t({count:11})],r.prototype,"output",void 0),e([t({count:3})],r.prototype,"textureCoordinateType",void 0),e([t({count:2})],r.prototype,"componentData",void 0),e([t({count:s})],r.prototype,"textureBackedBufferLayout",void 0),e([t({count:3})],r.prototype,"cullFace",void 0),e([t({count:3})],r.prototype,"vertexDiscardMode",void 0),e([t({count:3})],r.prototype,"doubleSidedMode",void 0),e([t({count:4})],r.prototype,"alphaDiscardMode",void 0),e([t({count:4})],r.prototype,"integratedMeshMode",void 0),e([t({count:3})],r.prototype,"oitPass",void 0),e([t({count:4})],r.prototype,"ellipsoidMode",void 0),e([t({count:7})],r.prototype,"pbrMode",void 0),e([t({count:3})],r.prototype,"normalType",void 0),e([t({count:8})],r.prototype,"emissionSource",void 0),e([t()],r.prototype,"hasVertexColors",void 0),e([t()],r.prototype,"hasNormals",void 0),e([t()],r.prototype,"shadeNormals",void 0),e([t()],r.prototype,"hasSlicePlane",void 0),e([t()],r.prototype,"hasColorTexture",void 0),e([t()],r.prototype,"hasHighlightMixTexture",void 0),e([t()],r.prototype,"receiveAmbientOcclusion",void 0),e([t()],r.prototype,"receiveShadows",void 0),e([t()],r.prototype,"blendingEnabled",void 0),e([t()],r.prototype,"screenSpaceReflections",void 0),e([t()],r.prototype,"hasPolygonOffset",void 0),e([t()],r.prototype,"hasMetallicRoughnessTexture",void 0),e([t()],r.prototype,"hasOcclusionTexture",void 0),e([t()],r.prototype,"hasNormalTexture",void 0),e([t()],r.prototype,"hasOccludees",void 0),e([t()],r.prototype,"terrainDepthTest",void 0),e([t()],r.prototype,"cullAboveTerrain",void 0),e([t()],r.prototype,"hasNormalTextureTransform",void 0),e([t()],r.prototype,"cloudReflections",void 0),e([t()],r.prototype,"snowCover",void 0),e([t()],r.prototype,"olidColor",void 0),e([t()],r.prototype,"renderOccluded",void 0),e([t()],r.prototype,"sphereDepthInterpolate",void 0);export{r as ComponentTechniqueConfiguration};
5
+ import{__decorate as e}from"tslib";import{isColorEmissionHighlightOrOID as t}from"../../../core/shaderLibrary/ShaderOutput.js";import{parameter as o,ShaderTechniqueConfiguration as i}from"../../../core/shaderTechnique/ShaderTechniqueConfiguration.js";import{MAX_COUNT_TEXTURE_BACKED_BUFFER_LAYOUTS as s}from"../../../lib/TextureBackedBuffer/TextureBackedBufferLayout.js";class r extends i{constructor(e){super(),this.sphericalSR=e,this.output=0,this.textureCoordinateType=0,this.componentData=0,this.textureBackedBufferLayout=0,this.cullFace=2,this.vertexDiscardMode=0,this.doubleSidedMode=2,this.alphaDiscardMode=1,this.integratedMeshMode=0,this.oitPass=0,this.ellipsoidMode=1,this.pbrMode=0,this.normalType=0,this.emissionSource=0,this.hasVertexColors=!1,this.hasNormals=!1,this.shadeNormals=!0,this.hasSlicePlane=!1,this.hasColorTexture=!1,this.hasHighlightMixTexture=!1,this.receiveAmbientOcclusion=!0,this.receiveShadows=!0,this.blendingEnabled=!0,this.screenSpaceReflections=!1,this.hasPolygonOffset=!1,this.hasMetallicRoughnessTexture=!1,this.hasOcclusionTexture=!1,this.hasNormalTexture=!1,this.hasOccludees=!1,this.terrainDepthTest=!1,this.cullAboveTerrain=!1,this.hasNormalTextureTransform=!1,this.cloudReflections=!0,this.snowCover=!1,this.olidColor=!1,this.renderOccluded=!1,this.sphereDepthInterpolate=!1,this.discardInvisibleFragments=!1,this.occlusionPass=!1,this.bindType=2,this.useCustomDTRExponentForWater=!1,this.hasVertexTangents=!1,this.highStepCount=!1,this.instanced=!1,this.instancedDoublePrecision=!1,this.hasModelTransformation=!1,this.useFillLights=!0,this.draped=!1}get spherical(){return 0!==this.sphericalSR}get overlayEnabled(){return(2===this.integratedMeshMode||3===this.integratedMeshMode)&&t(this.output)}}e([o({count:11})],r.prototype,"output",void 0),e([o({count:3})],r.prototype,"textureCoordinateType",void 0),e([o({count:2})],r.prototype,"componentData",void 0),e([o({count:s})],r.prototype,"textureBackedBufferLayout",void 0),e([o({count:3})],r.prototype,"cullFace",void 0),e([o({count:3})],r.prototype,"vertexDiscardMode",void 0),e([o({count:3})],r.prototype,"doubleSidedMode",void 0),e([o({count:4})],r.prototype,"alphaDiscardMode",void 0),e([o({count:4})],r.prototype,"integratedMeshMode",void 0),e([o({count:3})],r.prototype,"oitPass",void 0),e([o({count:4})],r.prototype,"ellipsoidMode",void 0),e([o({count:7})],r.prototype,"pbrMode",void 0),e([o({count:3})],r.prototype,"normalType",void 0),e([o({count:8})],r.prototype,"emissionSource",void 0),e([o()],r.prototype,"hasVertexColors",void 0),e([o()],r.prototype,"hasNormals",void 0),e([o()],r.prototype,"shadeNormals",void 0),e([o()],r.prototype,"hasSlicePlane",void 0),e([o()],r.prototype,"hasColorTexture",void 0),e([o()],r.prototype,"hasHighlightMixTexture",void 0),e([o()],r.prototype,"receiveAmbientOcclusion",void 0),e([o()],r.prototype,"receiveShadows",void 0),e([o()],r.prototype,"blendingEnabled",void 0),e([o()],r.prototype,"screenSpaceReflections",void 0),e([o()],r.prototype,"hasPolygonOffset",void 0),e([o()],r.prototype,"hasMetallicRoughnessTexture",void 0),e([o()],r.prototype,"hasOcclusionTexture",void 0),e([o()],r.prototype,"hasNormalTexture",void 0),e([o()],r.prototype,"hasOccludees",void 0),e([o()],r.prototype,"terrainDepthTest",void 0),e([o()],r.prototype,"cullAboveTerrain",void 0),e([o()],r.prototype,"hasNormalTextureTransform",void 0),e([o()],r.prototype,"cloudReflections",void 0),e([o()],r.prototype,"snowCover",void 0),e([o()],r.prototype,"olidColor",void 0),e([o()],r.prototype,"renderOccluded",void 0),e([o()],r.prototype,"sphereDepthInterpolate",void 0);export{r as ComponentTechniqueConfiguration};
@@ -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{NoParameters as t}from"../../../../webgl/NoParameters.js";class r extends t{constructor(){super(...arguments),this._dirty=!0}_setDirty(){this._dirty=!0}_setClean(){if(this._dirty=!1,null!=this._parameterBlocks)for(const t of this._parameterBlocks)this[t]._setClean()}get dirty(){return this._dirty||this._checkParameterBlocksDirty()}_checkParameterBlocksDirty(){if(null==this._parameterBlocks)return!1;for(const t of this._parameterBlocks)if(this[t].dirty)return!0;return!1}}class e{constructor(){this._dirty=!0}_setDirty(){this._dirty=!0}_setClean(){this._dirty=!1}get dirty(){return this._dirty}}function s(t={}){return(r,e)=>{const s=r._parameterCount??0;if(r._parameterCount=s+1,t.vectorOps){const i=t.vectorOps;Object.defineProperty(r,e,{get(){return this[s]},set(t){const r=this[s];if(null==r)this[s]=Array.from(t);else{if(i.equals(r,t))return;i.copy(r,t)}this._setDirty()}})}else Object.defineProperty(r,e,{get(){return this[s]},set(r){this[s]!==r&&(t.dispose&&this[s]&&this[s].dispose(),this[s]=r,this._setDirty())}})}}function i(){return(t,r)=>{const e=t._parameterCount??0;t._parameterCount=e+1,t._parameterBlocks=t._parameterBlocks||[],t._parameterBlocks.push(e),Object.defineProperty(t,r,{get(){return this[e]},set(t){this[e]!==t&&(this[e]=t,this._setDirty())}})}}export{r as MaterialBase,e as MaterialParameterBlock,s as parameter,i as parameterBlock};
5
+ import{NoParameters as t}from"../../../../webgl/NoParameters.js";class r extends t{constructor(){super(...arguments),this._dirty=!0}_setDirty(){this._dirty=!0}_setClean(){if(this._dirty=!1,null!=this._parameterBlocks)for(const t of this._parameterBlocks)this[t]._setClean()}get dirty(){return this._dirty||this._checkParameterBlocksDirty()}_checkParameterBlocksDirty(){if(null==this._parameterBlocks)return!1;for(const t of this._parameterBlocks)if(this[t].dirty)return!0;return!1}}class e{constructor(){this._dirty=!0}_setDirty(){this._dirty=!0}_setClean(){this._dirty=!1}get dirty(){return this._dirty}}function s(t={}){return(r,e)=>{const s=r._parameterCount??0;r._parameterCount=s+1;const i=t.vectorOps;i?Object.defineProperty(r,e,{get(){return this[s]},set(t){const r=this[s];if(null==r)this[s]=Array.from(t);else{if(i.equals(r,t))return;i.copy(r,t)}this._setDirty()}}):Object.defineProperty(r,e,{get(){return this[s]},set(r){this[s]!==r&&(t.dispose&&this[s]&&this[s].dispose(),this[s]=r,this._setDirty())}})}}function i(){return(t,r)=>{const e=t._parameterCount??0;t._parameterCount=e+1,t._parameterBlocks=t._parameterBlocks||[],t._parameterBlocks.push(e),Object.defineProperty(t,r,{get(){return this[e]},set(t){this[e]!==t&&(this[e]=t,this._setDirty())}})}}export{r as MaterialBase,e as MaterialParameterBlock,s as parameter,i as parameterBlock};
@@ -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{releaseMaybe as e}from"../../../../../core/maybe.js";import{isPromiseLike as t}from"../../../../../core/promiseUtils.js";class s{constructor(s,r){this._textures=s,this.loadPromise=null,this._disposed=!1;const i=this._textures.acquire(r);t(i)?(i.then(t=>{this._disposed?e(t):this._textureRef=t}),this.loadPromise=i):this._textureRef=i}dispose(){this._textureRef=e(this._textureRef),this._disposed=!0}get glTexture(){return this._textureRef?.glTexture}}export{s as RenderTexture};
5
+ import{releaseMaybe as t}from"../../../../../core/maybe.js";import{isPromiseLike as e}from"../../../../../core/promiseUtils.js";class s{constructor(s,r){this._textures=s,this.loadPromise=null,this._disposed=!1;const i=this._textures.acquire(r);e(i)?(i.then(e=>{this._disposed?t(e):this._textureRef=e}),this.loadPromise=i):this._textureRef=i}dispose(){this._textureRef=t(this._textureRef),this._disposed=!0}get texture(){return this._textureRef?.texture}}export{s as RenderTexture};
@@ -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{lerp as t,clamp as r,smoothstep as s}from"../../../../../core/mathUtils.js";import{disposeMaybe as i}from"../../../../../core/maybe.js";import{watch as o,syncAndInitial as a}from"../../../../../core/reactiveUtils.js";import"../../../../../core/Logger.js";import"../../../../../core/has.js";import"../../../../../core/RandomLCG.js";import"../../../../../core/Error.js";import{subclass as n}from"../../../../../core/accessorSupport/decorators/subclass.js";import{set as m}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{b as h,m as p}from"../../../../../chunks/vec32.js";import{s as c}from"../../../../../chunks/vec42.js";import{earth as d}from"../../../../../geometry/support/Ellipsoid.js";import{InternalRenderCategory as u}from"../../../webgl.js";import{TransparentEnvironment as f}from"../TransparentEnvironment.js";import{H as l}from"../../../../../chunks/HazeCompositing.glsl.js";import{HazeCompositingTechnique as _}from"./HazeCompositingTechnique.js";import{HazePassParameters as g,HazeTechnique as b}from"./HazeTechnique.js";import{HazeTechniqueConfiguration as w}from"./HazeTechniqueConfiguration.js";import{createQuadVAO as P}from"../../lib/glUtil3D.js";import{applyTextureResizeModulo as j}from"../../lib/textureUtils.js";import{DepthStencilAttachment as v,PrimitiveType as A}from"../../../../webgl/enums.js";let C=class extends f{constructor(e){super(e),this._compositingPassParameters=new l,this._passParameters=new g,this._hazeConfiguration=new w,this.requireGeometryDepth=!0,this._oldAmount=1,this._newAmount=1,this._amount=this._newAmount;const t=e.view.stage.renderView.techniques;t.precompile(b,new w);const r=new w;r.reduced=!0,t.precompile(b,r),t.precompile(_)}initialize(){this.addHandles([o(()=>this.view.environment.atmosphereEnabled,e=>e?this._enable():this._disable(),a),o(()=>this.view.stage?.renderer.renderContext.bind.clouds.fadeFactor??1,e=>this._fade(e),a),o(()=>this.view.environment.weather.type,e=>this._newAmount="rainy"===e?0:1,a),o(()=>this.view.stage.renderer?.fullResolutionAtmosphere,e=>this._hazeConfiguration.reduced=!e,a)])}_fade(e){e>=1?(this._amount=this._newAmount,this._oldAmount=this._newAmount):this._amount=e<=0?this._oldAmount:t(this._oldAmount,this._newAmount,e)}destroy(){this._vao=i(this._vao)}render(e){const r=e.find(({name:e})=>e===u.TRANSPARENT_ENVIRONMENT);if(!this.bindParameters.mainDepth)return r;const s=this.renderingContext,i=this.techniques.get(b,this._hazeConfiguration);if(!i.compiled)return r;const o=r.getAttachment(v);if(this._update(),!this._hazeConfiguration.reduced)return r.detachDepth(),s.bindFramebuffer(r.fbo),s.bindTechnique(i,this.bindParameters,this._passParameters),this._renderCommon(s),r.attachDepth(o),r;const a=this.techniques.get(_);if(!a.compiled)return r;const n=s.getViewport(),m=this.camera,p=h(m.eye)-d.radius;let c;const f=d.atmosphereHeight;if(p<f){const e=Math.min(1,Math.max(0,p/f));c=t(.4,.5,e)}else{const e=Math.min(1,Math.max(0,(p-f)/(15*f)));c=t(.5,1,e)}const l=this.renderingContext.parameters.maxTextureSize,g=j(Math.round(c*m.fullViewport[2]),l),w=j(Math.round(c*m.fullViewport[3]),l);s.setViewport(0,0,g,w);const P=this.fboCache.acquire(g,w,"haze",5);return s.bindFramebuffer(P.fbo),s.clearFramebuffer([0,0,0,1],!0,!0),s.bindTechnique(i,this.bindParameters,this._passParameters),this._renderCommon(s),s.setViewport(n.x,n.y,n.width,n.height),this._compositingPassParameters.color=P.getTexture(),r.detachDepth(),s.bindFramebuffer(r.fbo),s.bindTechnique(a,this.bindParameters,this._compositingPassParameters),s.screen.draw(),r.attachDepth(o),P.release(),r}_renderCommon(e){this._vao??=P(e,1),e.bindVAO(this._vao),e.drawArrays(A.TRIANGLE_STRIP,0,4)}_update(){const e=this.bindParameters.camera,i=p(e.eye),o=Math.sqrt(i),a=i-this._passParameters.radii[1]*this._passParameters.radii[1],n=r((o-this._passParameters.radii[0])/d.atmosphereHeight,0,1);c(this._passParameters.heightParameters,o,i,a,n);const h=this.view.basemapTerrain?.getLowerBoundRadius()??0;m(this._passParameters.radii,h,h+d.atmosphereHeight),this._passParameters.hazeStrength=t(t(.6,1,s(9500,10500,o-d.radius)),1,this._amount)}};C=e([n("esri.views.3d.webgl-engine.effects.haze.Haze")],C);export{C as Haze};
5
+ import{__decorate as e}from"tslib";import{lerp as t,clamp as r,smoothstep as s}from"../../../../../core/mathUtils.js";import{disposeMaybe as i}from"../../../../../core/maybe.js";import{watch as o,syncAndInitial as a}from"../../../../../core/reactiveUtils.js";import"../../../../../core/Logger.js";import"../../../../../core/has.js";import"../../../../../core/RandomLCG.js";import"../../../../../core/Error.js";import{subclass as n}from"../../../../../core/accessorSupport/decorators/subclass.js";import{set as m}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{b as h,m as p}from"../../../../../chunks/vec32.js";import{s as c}from"../../../../../chunks/vec42.js";import{earth as d}from"../../../../../geometry/support/Ellipsoid.js";import{InternalRenderCategory as u}from"../../../webgl.js";import{TransparentEnvironment as f}from"../TransparentEnvironment.js";import{H as l}from"../../../../../chunks/HazeCompositing.glsl.js";import{HazeCompositingTechnique as _}from"./HazeCompositingTechnique.js";import{HazePassParameters as g,HazeTechnique as b}from"./HazeTechnique.js";import{HazeTechniqueConfiguration as w}from"./HazeTechniqueConfiguration.js";import{createQuadVAO as P}from"../../lib/glUtil3D.js";import{applyTextureResizeModulo as j}from"../../lib/textureUtils.js";import{DepthStencilAttachment as v,PrimitiveType as A}from"../../../../webgl/enums.js";let C=class extends f{constructor(e){super(e),this._compositingPassParameters=new l,this._passParameters=new g,this._hazeConfiguration=new w,this.requireGeometryDepth=!0,this._oldAmount=1,this._newAmount=1,this._amount=this._newAmount;const t=e.view.stage.renderView.techniques;t.precompile(b,new w);const r=new w;r.reduced=!0,t.precompile(b,r),t.precompile(_)}initialize(){this.addHandles([o(()=>this.view.environment.atmosphereEnabled,e=>e?this._enable():this._disable(),a),o(()=>this.view.stage?.renderer.renderContext.bind.clouds.fadeFactor??1,e=>this._fade(e),a),o(()=>this.view.environment.weather.type,e=>this._newAmount="rainy"===e?0:1,a),o(()=>this.view.stage.renderer?.highResolutionAtmosphere,e=>this._hazeConfiguration.reduced=!e,a)])}_fade(e){e>=1?(this._amount=this._newAmount,this._oldAmount=this._newAmount):this._amount=e<=0?this._oldAmount:t(this._oldAmount,this._newAmount,e)}destroy(){this._vao=i(this._vao)}render(e){const r=e.find(({name:e})=>e===u.TRANSPARENT_ENVIRONMENT);if(!this.bindParameters.mainDepth)return r;const s=this.renderingContext,i=this.techniques.get(b,this._hazeConfiguration);if(!i.compiled)return r;const o=r.getAttachment(v);if(this._update(),!this._hazeConfiguration.reduced)return r.detachDepth(),s.bindFramebuffer(r.fbo),s.bindTechnique(i,this.bindParameters,this._passParameters),this._renderCommon(s),r.attachDepth(o),r;const a=this.techniques.get(_);if(!a.compiled)return r;const n=s.getViewport(),m=this.camera,p=h(m.eye)-d.radius;let c;const f=d.atmosphereHeight;if(p<f){const e=Math.min(1,Math.max(0,p/f));c=t(.4,.5,e)}else{const e=Math.min(1,Math.max(0,(p-f)/(15*f)));c=t(.5,1,e)}const l=this.renderingContext.parameters.maxTextureSize,g=j(Math.round(c*m.fullViewport[2]),l),w=j(Math.round(c*m.fullViewport[3]),l);s.setViewport(0,0,g,w);const P=this.fboCache.acquire(g,w,"haze",5);return s.bindFramebuffer(P.fbo),s.clearFramebuffer([0,0,0,1],!0,!0),s.bindTechnique(i,this.bindParameters,this._passParameters),this._renderCommon(s),s.setViewport(n.x,n.y,n.width,n.height),this._compositingPassParameters.color=P.getTexture(),r.detachDepth(),s.bindFramebuffer(r.fbo),s.bindTechnique(a,this.bindParameters,this._compositingPassParameters),s.screen.draw(),r.attachDepth(o),P.release(),r}_renderCommon(e){this._vao??=P(e,1),e.bindVAO(this._vao),e.drawArrays(A.TRIANGLE_STRIP,0,4)}_update(){const e=this.bindParameters.camera,i=p(e.eye),o=Math.sqrt(i),a=i-this._passParameters.radii[1]*this._passParameters.radii[1],n=r((o-this._passParameters.radii[0])/d.atmosphereHeight,0,1);c(this._passParameters.heightParameters,o,i,a,n);const h=this.view.basemapTerrain?.getLowerBoundRadius()??0;m(this._passParameters.radii,h,h+d.atmosphereHeight),this._passParameters.hazeStrength=t(t(.6,1,s(9500,10500,o-d.radius)),1,this._amount)}};C=e([n("esri.views.3d.webgl-engine.effects.haze.Haze")],C);export{C as Haze};
@@ -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 r from"../../../../../core/Logger.js";import{disposeMaybe as t}from"../../../../../core/maybe.js";import{throwIfAborted as s}from"../../../../../core/promiseUtils.js";import{watch as i,syncAndInitial as a}from"../../../../../core/reactiveUtils.js";import{property as o}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/RandomLCG.js";import{subclass as n}from"../../../../../core/accessorSupport/decorators/subclass.js";import{requestImage as h}from"../../../../../request/image.js";import{RenderCategory as u,InternalRenderCategory as c}from"../../../webgl.js";import l from"../../../webgl/RenderNode.js";import{SMAABlendWeightsTechnique as m}from"./SMAABlendWeightsTechnique.js";import{SMAABlurTechnique as d}from"./SMAABlurTechnique.js";import{SMAAEdgeDetectTechnique as p}from"./SMAAEdgeDetectTechnique.js";import{SMAAPassParameters as f}from"./SMAAPassParameters.js";import{Texture as b}from"../../../../webgl/Texture.js";import{TextureDescriptor as T}from"../../../../webgl/TextureDescriptor.js";let x=class extends l{constructor(e){super(e),this.produces="disabled",this.consumes={required:[c.ANTIALIASING],optional:[u.COMPOSITE]},this._areaTexture=null,this._searchTexture=null,this._smaaParameters=new f}initialize(){this.addHandles([i(()=>this.isEnabled(),e=>e?this.enable():this.disable(),a)])}async enable(){if(this.destroyed)return;if(this.produces=c.ANTIALIASING,this.requestRender(1),this._abortController||this._areaTexture&&this._searchTexture)return;this._abortController=new AbortController;const e=this._abortController.signal;try{const r=await import("./SMAAData.js");if(this.destroyed)return;if(await this._loadTextures(r,e),this.destroyed)return;this.requestRender(1)}catch(t){r.getLogger(this).errorOnce(t)}this.destroyed||(this._abortController=null)}async _loadTextures(e,r){s(r);const[t,i]=await Promise.allSettled([h(e.areaTexture,{signal:r}),h(e.searchTexure,{signal:r})]);if(s(r),"fulfilled"!==t.status||"fulfilled"!==i.status)return;const a=this.renderingContext;this._areaTexture=g(a,9729,6407,t.value),this._searchTexture=g(a,9728,6409,i.value)}disable(){this.produces="disabled",this.requestRender(1)}destroy(){this._searchTexture=t(this._searchTexture),this._areaTexture=t(this._areaTexture)}precompile(){this.techniques.precompile(p),this.techniques.precompile(m),this.techniques.precompile(d)}render(e){const r=e.find(({name:e})=>e===c.ANTIALIASING),t=e.find(({name:e})=>e===u.COMPOSITE);if(!t)return r;if(!this._areaTexture||!this._searchTexture)return this.view.stage.renderer.blitFBO(t,r,!1),this.requestRender(1),r;const s=this.techniques.get(p),i=this.techniques.get(m),a=this.techniques.get(d);if(!s.compiled||!i.compiled||!a.compiled)return this.view.stage.renderer.blitFBO(t,r,!1),this.requestRender(1),r;const o=t.fbo.width,n=t.fbo.height,h=this.renderingContext;h.setViewport(0,0,o,n);const l=this.fboCache.acquire(o,n,"smaa edges",2);h.bindFramebuffer(l.fbo),h.setClearColor(0,0,0,1),h.clear(16384),this._smaaParameters.color=t.getTexture();const f=this.bindParameters;h.bindTechnique(s,f,this._smaaParameters),h.screen.draw();const b=this.fboCache.acquire(o,n,"smaa blend");return h.bindFramebuffer(b.fbo),h.setClearColor(0,0,1,1),h.clear(16384),this._smaaParameters.inputTexture=l.getTexture(),this._smaaParameters.areaTexture=this._areaTexture,this._smaaParameters.searchTexture=this._searchTexture,h.bindTechnique(i,f,this._smaaParameters),h.screen.draw(),l.release(),h.bindFramebuffer(r.fbo),h.setClearColor(0,1,0,1),h.clear(16384),this._smaaParameters.inputTexture=b.getTexture(),h.bindTechnique(a,f,this._smaaParameters),h.screen.draw(),b.release(),r}};function g(e,r,t,s){const i=new T(s.width,s.height);return i.pixelFormat=t,i.wrapMode=33071,i.samplingMode=r,new b(e,i,s)}e([o()],x.prototype,"produces",void 0),e([o()],x.prototype,"consumes",void 0),e([o({constructOnly:!0})],x.prototype,"isEnabled",void 0),e([o()],x.prototype,"_abortController",void 0),x=e([n("esri.views.3d.webgl-engine.effects.smaa.SMAA")],x);export{x as SMAA};
5
+ import{__decorate as e}from"tslib";import r from"../../../../../core/Logger.js";import{abortMaybe as t,disposeMaybe as s}from"../../../../../core/maybe.js";import{throwIfAborted as i}from"../../../../../core/promiseUtils.js";import{watch as o,syncAndInitial as a}from"../../../../../core/reactiveUtils.js";import{property as n}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/RandomLCG.js";import{subclass as h}from"../../../../../core/accessorSupport/decorators/subclass.js";import{requestImage as l}from"../../../../../request/image.js";import{RenderCategory as c,InternalRenderCategory as u}from"../../../webgl.js";import m from"../../../webgl/RenderNode.js";import{SMAABlendWeightsTechnique as d}from"./SMAABlendWeightsTechnique.js";import{SMAABlurTechnique as p}from"./SMAABlurTechnique.js";import{SMAAEdgeDetectTechnique as f}from"./SMAAEdgeDetectTechnique.js";import{SMAAPassParameters as b}from"./SMAAPassParameters.js";import{Texture as T}from"../../../../webgl/Texture.js";import{TextureDescriptor as x}from"../../../../webgl/TextureDescriptor.js";let _=class extends m{constructor(e){super(e),this.produces="disabled",this.consumes={required:[u.ANTIALIASING],optional:[c.COMPOSITE]},this._areaTexture=null,this._searchTexture=null,this._smaaParameters=new b}initialize(){this.addHandles([o(()=>this.isEnabled(),e=>e?this.enable():this.disable(),a)])}async enable(){if(this.destroyed)return;if(this.produces=u.ANTIALIASING,this.requestRender(1),this._abortController||this._areaTexture&&this._searchTexture)return;this._abortController=new AbortController;const e=this._abortController.signal;try{const r=await import("./SMAAData.js");if(this.destroyed)return;if(await this._loadTextures(r,e),this.destroyed)return;this.requestRender(1)}catch(t){r.getLogger(this).errorOnce(t)}this.destroyed||(this._abortController=null)}async _loadTextures(e,r){i(r);const[t,s]=await Promise.allSettled([l(e.areaTexture,{signal:r}),l(e.searchTexure,{signal:r})]);if(i(r),"fulfilled"!==t.status||"fulfilled"!==s.status)return;const o=this.renderingContext;this._areaTexture=g(o,9729,6407,t.value),this._searchTexture=g(o,9728,6409,s.value)}disable(){this.produces="disabled",this.requestRender(1)}destroy(){this._abortController=t(this._abortController),this._searchTexture=s(this._searchTexture),this._areaTexture=s(this._areaTexture)}precompile(){this.techniques.precompile(f),this.techniques.precompile(d),this.techniques.precompile(p)}render(e){const r=e.find(({name:e})=>e===u.ANTIALIASING),t=e.find(({name:e})=>e===c.COMPOSITE);if(!t)return r;if(!this._areaTexture||!this._searchTexture)return this.view.stage.renderer.blitFBO(t,r,!1),this.requestRender(1),r;const s=this.techniques.get(f),i=this.techniques.get(d),o=this.techniques.get(p);if(!s.compiled||!i.compiled||!o.compiled)return this.view.stage.renderer.blitFBO(t,r,!1),this.requestRender(1),r;const a=t.fbo.width,n=t.fbo.height,h=this.renderingContext;h.setViewport(0,0,a,n);const l=this.fboCache.acquire(a,n,"smaa edges",2);h.bindFramebuffer(l.fbo),h.setClearColor(0,0,0,1),h.clear(16384),this._smaaParameters.color=t.getTexture();const m=this.bindParameters;h.bindTechnique(s,m,this._smaaParameters),h.screen.draw();const b=this.fboCache.acquire(a,n,"smaa blend");return h.bindFramebuffer(b.fbo),h.setClearColor(0,0,1,1),h.clear(16384),this._smaaParameters.inputTexture=l.getTexture(),this._smaaParameters.areaTexture=this._areaTexture,this._smaaParameters.searchTexture=this._searchTexture,h.bindTechnique(i,m,this._smaaParameters),h.screen.draw(),l.release(),h.bindFramebuffer(r.fbo),h.setClearColor(0,1,0,1),h.clear(16384),this._smaaParameters.inputTexture=b.getTexture(),h.bindTechnique(o,m,this._smaaParameters),h.screen.draw(),b.release(),r}};function g(e,r,t,s){const i=new x(s.width,s.height);return i.pixelFormat=t,i.wrapMode=33071,i.samplingMode=r,new T(e,i,s)}e([n()],_.prototype,"produces",void 0),e([n()],_.prototype,"consumes",void 0),e([n({constructOnly:!0})],_.prototype,"isEnabled",void 0),e([n()],_.prototype,"_abortController",void 0),_=e([h("esri.views.3d.webgl-engine.effects.smaa.SMAA")],_);export{_ as SMAA};
@@ -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{clamp as r}from"../../../../../core/mathUtils.js";import{disposeMaybe as t}from"../../../../../core/maybe.js";import{watch as s}from"../../../../../core/reactiveUtils.js";import{Milliseconds as i}from"../../../../../core/time.js";import{property as o}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as a}from"../../../../../core/accessorSupport/decorators/subclass.js";import{set as m}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{InternalRenderCategory as n}from"../../../webgl.js";import p from"../../../webgl/RenderNode.js";import{distanceFadeEnd as c,distanceFadeStart as h}from"../../core/shaderLibrary/shading/ScreenSpaceConstants.js";import{SSAOBlurTechnique as u}from"./SSAOBlurTechnique.js";import{noiseData as l}from"./SSAONoiseData.js";import{SSAOPassParameters as d,BlurDrawParameters as f}from"./SSAOParameters.js";import{SSAOTechnique as b}from"./SSAOTechnique.js";import{g as w}from"../../../../../chunks/SSAO.glsl.js";import{DepthStencilAttachment as S}from"../../../../webgl/enums.js";import{Texture as T}from"../../../../webgl/Texture.js";import{TextureDescriptor as _}from"../../../../webgl/TextureDescriptor.js";const g=2;let j=class extends p{constructor(e){super(e),this.consumes={required:["normals"]},this.produces=n.SSAO,this.isEnabled=()=>!1,this._enableTime=i(0),this._passParameters=new d,this._drawParameters=new f}initialize(){const e=Uint8Array.from(atob(l),e=>e.charCodeAt(0)),r=new _(32);r.wrapMode=33071,r.pixelFormat=6407,r.wrapMode=10497,r.hasMipmap=!0,this._passParameters.noiseTexture=new T(this.renderingContext,r,e),this.techniques.precompile(b),this.techniques.precompile(u),this.addHandles(s(()=>this.isEnabled(),()=>this._enableTime=i(0)))}destroy(){this._passParameters.noiseTexture=t(this._passParameters.noiseTexture)}render(e){const t=e.find(({name:e})=>"normals"===e),s=t?.getTexture(),o=t?.getTexture(S);if(!s||!o)return;const a=this.techniques.get(b),p=this.techniques.get(u);if(!a.compiled||!p.compiled)return this._enableTime=i(performance.now()),void this.requestRender(1);0===this._enableTime&&(this._enableTime=i(performance.now()));const l=this.renderingContext,d=this.view.qualitySettings.fadeDuration,f=this.bindParameters,T=f.camera,_=T.relativeElevation,j=r((c-_)/(c-h),0,1),x=d>0?Math.min(d,performance.now()-this._enableTime)/d:1,q=x*j;this._passParameters.normalTexture=s,this._passParameters.depthTexture=o,this._passParameters.projScale=1/T.computeScreenPixelSizeAtDist(1),this._passParameters.intensity=4*P/w(T)**6*q;const v=T.fullViewport[2],y=T.fullViewport[3],A=this.fboCache.acquire(v,y,"ssao input",2);l.bindFramebuffer(A.fbo),l.setViewport(0,0,v,y),l.bindTechnique(a,f,this._passParameters,this._drawParameters),l.screen.draw();const C=Math.round(v/g),O=Math.round(y/g),V=this.fboCache.acquire(C,O,"ssao blur",0);l.bindFramebuffer(V.fbo),this._drawParameters.colorTexture=A.getTexture(),m(this._drawParameters.blurSize,0,g/y),l.bindTechnique(p,f,this._passParameters,this._drawParameters),l.setViewport(0,0,C,O),l.screen.draw(),A.release();const M=this.fboCache.acquire(C,O,n.SSAO,0);return l.bindFramebuffer(M.fbo),l.setViewport(0,0,v,y),l.setClearColor(1,1,1,0),l.clear(16384),this._drawParameters.colorTexture=V.getTexture(),m(this._drawParameters.blurSize,g/v,0),l.bindTechnique(p,f,this._passParameters,this._drawParameters),l.setViewport(0,0,C,O),l.screen.draw(),l.setViewport4fv(T.fullViewport),V.release(),x<1&&this.requestRender(2),M}};e([o()],j.prototype,"consumes",void 0),e([o()],j.prototype,"produces",void 0),e([o({constructOnly:!0})],j.prototype,"isEnabled",void 0),j=e([a("esri.views.3d.webgl-engine.effects.ssao.SSAO")],j);const P=.5;export{j as SSAO,g as blurSizePixels};
5
+ import{__decorate as e}from"tslib";import{clamp as r}from"../../../../../core/mathUtils.js";import{disposeMaybe as t}from"../../../../../core/maybe.js";import{watch as s}from"../../../../../core/reactiveUtils.js";import{Milliseconds as i}from"../../../../../core/time.js";import{property as o}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as a}from"../../../../../core/accessorSupport/decorators/subclass.js";import{set as m}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{InternalRenderCategory as n}from"../../../webgl.js";import p from"../../../webgl/RenderNode.js";import{distanceFadeEnd as c,distanceFadeStart as h}from"../../core/shaderLibrary/shading/ScreenSpaceConstants.js";import{SSAOBlurTechnique as u}from"./SSAOBlurTechnique.js";import{noiseData as l}from"./SSAONoiseData.js";import{SSAOPassParameters as d,BlurDrawParameters as f}from"./SSAOParameters.js";import{SSAOTechnique as b}from"./SSAOTechnique.js";import{g as w}from"../../../../../chunks/SSAO.glsl.js";import{DepthStencilAttachment as S}from"../../../../webgl/enums.js";import{Texture as _}from"../../../../webgl/Texture.js";import{TextureDescriptor as T}from"../../../../webgl/TextureDescriptor.js";const g=2;let j=class extends p{constructor(e){super(e),this.consumes={required:["normals"]},this.produces=n.SSAO,this.isEnabled=()=>!1,this._enableTime=i(0),this._passParameters=new d,this._drawParameters=new f}initialize(){const e=Uint8Array.from(atob(l),e=>e.charCodeAt(0)),r=new T(32);r.wrapMode=33071,r.pixelFormat=6407,r.wrapMode=10497,r.hasMipmap=!0,this._passParameters.noiseTexture=new _(this.renderingContext,r,e),this.techniques.precompile(b),this.techniques.precompile(u),this.addHandles(s(()=>this.isEnabled(),()=>this._enableTime=i(0)))}destroy(){this._passParameters.noiseTexture=t(this._passParameters.noiseTexture)}render(e){const t=e.find(({name:e})=>"normals"===e),s=t?.getTexture(),o=t?.getTexture(S);if(!s||!o)return;const a=this.techniques.get(b),p=this.techniques.get(u);if(!a.compiled||!p.compiled)return this._enableTime=i(performance.now()),void this.requestRender(1);0===this._enableTime&&(this._enableTime=i(performance.now()));const l=this.renderingContext,d=this.view.qualitySettings.fadeDuration,f=this.bindParameters,_=f.camera,T=_.relativeElevation,j=r((c-T)/(c-h),0,1),x=d>0?Math.min(d,performance.now()-this._enableTime)/d:1,q=x*j;this._passParameters.normalTexture=s,this._passParameters.depthTexture=o,this._passParameters.projScale=1/_.computeScreenPixelSizeAtDist(1),this._passParameters.intensity=4*P/w(_)**6*q;const v=_.fullViewport[2],y=_.fullViewport[3],A=this.fboCache.acquire(v,y,"ssao input",2);l.bindFramebuffer(A.fbo),l.setViewport(0,0,v,y),l.bindTechnique(a,f,this._passParameters,this._drawParameters),l.screen.draw();const C=Math.round(v/g),O=Math.round(y/g),V=this.fboCache.acquire(C,O,"ssao blur",0);l.bindFramebuffer(V.fbo),this._drawParameters.colorTexture=A.getTexture(),m(this._drawParameters.blurSize,0,g/y),l.bindTechnique(p,f,this._passParameters,this._drawParameters),l.setViewport(0,0,C,O),l.screen.draw(),A.release();const M=this.fboCache.acquire(C,O,n.SSAO,0);return l.bindFramebuffer(M.fbo),l.setViewport(0,0,v,y),l.setClearColor(1,1,1,0),l.clear(16384),this._drawParameters.colorTexture=V.getTexture(),m(this._drawParameters.blurSize,g/v,0),l.bindTechnique(p,f,this._passParameters,this._drawParameters),l.setViewport(0,0,C,O),l.screen.draw(),l.setViewport4fv(_.fullViewport),V.release(),x<1&&this.requestRender(2),M}};e([o()],j.prototype,"consumes",void 0),e([o()],j.prototype,"produces",void 0),e([o({constructOnly:!0})],j.prototype,"isEnabled",void 0),j=e([a("esri.views.3d.webgl-engine.effects.ssao.SSAO")],j);const P=.5;export{j as SSAO,g as blurSizePixels};