@arcgis/core 6.0.0-next.35 → 6.0.0-next.37

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 (188) hide show
  1. package/assets/esri/core/workers/RemoteClient.js +1 -1
  2. package/assets/esri/core/workers/chunks/{0202eb8c2b2865f99981.js → 00311d1b18d5952a014b.js} +1 -1
  3. package/assets/esri/core/workers/chunks/0b21d0e2e5a91c34a108.js +1 -0
  4. package/assets/esri/core/workers/chunks/{f717005e14a7e9141df7.js → 2050c844b5a29b1df28a.js} +1 -1
  5. package/assets/esri/core/workers/chunks/2c3612379111457c3221.js +1 -0
  6. package/assets/esri/core/workers/chunks/2f9072563194026e320e.js +1 -0
  7. package/assets/esri/core/workers/chunks/{d9a240a3c6bf85124474.js → 342a97974a78007b25e0.js} +1 -1
  8. package/assets/esri/core/workers/chunks/34467f7d84baffd772a3.js +1 -0
  9. package/assets/esri/core/workers/chunks/{4d18b48d4a282a0f341c.js → 427d929dc7f89b0a1ea9.js} +1 -1
  10. package/assets/esri/core/workers/chunks/432728c557be5dfa26b5.js +1 -0
  11. package/assets/esri/core/workers/chunks/46969f379623810b2eca.js +1 -0
  12. package/assets/esri/core/workers/chunks/592b5db1459c02cf6a0c.js +1 -0
  13. package/assets/esri/core/workers/chunks/6a21dc13a465757ba007.js +1 -0
  14. package/assets/esri/core/workers/chunks/{379db67f78161ebd5468.js → 7023651ed6398dcf8efb.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{90360c0bd053d3e3fd77.js → 7027a0e7bfabb3bb7fc2.js} +1 -1
  16. package/assets/esri/core/workers/chunks/78818c2a898444f7e890.js +1 -0
  17. package/assets/esri/core/workers/chunks/{40c2674dae73f0942751.js → 7d497df6e13162156342.js} +1 -1
  18. package/assets/esri/core/workers/chunks/8a3dfe997712dc2ddead.js +1 -0
  19. package/assets/esri/core/workers/chunks/{81bcc495e6eaf2cf7474.js → 8f82a0a6747f673a2a7e.js} +1 -1
  20. package/assets/esri/core/workers/chunks/9826baa3c15ea2062669.js +1 -0
  21. package/assets/esri/core/workers/chunks/{d3369ffed19f4c264dcd.js → 9ab0735e86cf8932bf9d.js} +1 -1
  22. package/assets/esri/core/workers/chunks/ab0ea4042f4e13874aed.js +1 -0
  23. package/assets/esri/core/workers/chunks/ab98ade3257360015d6c.js +1 -0
  24. package/assets/esri/core/workers/chunks/{796c6195b6bf59dcc9bd.js → b25a05c58b0fd0f6ac60.js} +1 -1
  25. package/assets/esri/core/workers/chunks/b90271ce38522bcf813b.js +1 -0
  26. package/assets/esri/core/workers/chunks/ba91df9835cdea7698a9.js +1 -0
  27. package/assets/esri/core/workers/chunks/bfe13ac9fa1aafb190a1.js +1 -0
  28. package/assets/esri/core/workers/chunks/ce0274847ccce6a1ac53.js +1 -0
  29. package/assets/esri/core/workers/chunks/cf2e5f827cea7d7319ce.js +1 -0
  30. package/assets/esri/core/workers/chunks/dae2036faa28dade2119.js +1 -0
  31. package/assets/esri/core/workers/chunks/{e8fb2ba7b7a4f0916325.js → eed4b90494a54f8b337b.js} +1 -1
  32. package/assets/esri/core/workers/chunks/fc77eb7683e708774168.js +1 -0
  33. package/chunks/Clouds.glsl.js +7 -11
  34. package/chunks/RibbonLine.glsl.js +158 -84
  35. package/config.js +1 -1
  36. package/core/libs/gl-matrix-2/math/vec3.js +1 -1
  37. package/kernel.js +1 -1
  38. package/layers/BaseElevationLayer.js +1 -1
  39. package/layers/ElevationLayer.js +1 -1
  40. package/layers/IntegratedMesh3DTilesLayer.js +1 -1
  41. package/layers/IntegratedMeshLayer.d.ts +2 -0
  42. package/layers/IntegratedMeshLayer.js +1 -1
  43. package/layers/knowledgeGraph/KnowledgeGraphLayerDataManager.js +1 -1
  44. package/layers/support/ElevationQuery.js +1 -1
  45. package/layers/video/VideoController.js +3 -3
  46. package/layers/video/types.d.ts +12 -0
  47. package/package.json +3 -3
  48. package/support/timeUtils.js +1 -1
  49. package/views/2d/engine/Bitmap.js +1 -1
  50. package/views/2d/engine/flow/styles/Imagery.js +1 -1
  51. package/views/2d/engine/vectorTiles/SpriteMosaic.js +1 -1
  52. package/views/2d/engine/vectorTiles/VTLPainter3D.js +1 -1
  53. package/views/2d/engine/webgl/AttributeStoreView.js +1 -1
  54. package/views/2d/engine/webgl/GlyphMosaic.js +1 -1
  55. package/views/2d/engine/webgl/Overlay.js +1 -1
  56. package/views/2d/engine/webgl/OverlayMultipoint.js +1 -1
  57. package/views/2d/engine/webgl/SpriteMosaic.js +1 -1
  58. package/views/2d/engine/webgl/VideoScreenRenderer.js +1 -1
  59. package/views/2d/engine/webgl/animations/store/AnimationStore.js +1 -1
  60. package/views/2d/engine/webgl/collisions/LabelStore.js +1 -1
  61. package/views/2d/engine/webgl/effects/highlight/HighlightGradient.js +1 -1
  62. package/views/2d/engine/webgl/shaderGraph/techniques/TextureStatisticsTechnique.js +1 -1
  63. package/views/2d/engine/webgl/shaderGraph/techniques/blend/BlendTechnique.js +1 -1
  64. package/views/2d/engine/webgl/shaderGraph/techniques/colorize/ColorizeTechnique.js +1 -1
  65. package/views/2d/engine/webgl/shaderGraph/techniques/dotDensity/DotDensityResources.js +1 -1
  66. package/views/2d/engine/webgl/shaderGraph/techniques/drop-shadow/DropShadowTechnique.js +1 -1
  67. package/views/2d/engine/webgl/shaderGraph/techniques/heatmap/HeatmapResources.js +1 -1
  68. package/views/2d/engine/webgl/shaderGraph/techniques/magnifier/MagnifierTechnique.js +1 -1
  69. package/views/2d/engine/webgl/shaderGraph/techniques/opacity/OpacityTechnique.js +1 -1
  70. package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterColorizerTechnique.js +1 -1
  71. package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterHighlightTechnique.js +1 -1
  72. package/views/2d/engine/webgl/shaderGraph/techniques/raster/processor/textureUtils.js +1 -1
  73. package/views/2d/engine/webgl/shaderGraph/techniques/tile/TileDebugInfoTexture.js +1 -1
  74. package/views/2d/engine/webgl/textureUtils.js +1 -1
  75. package/views/2d/layers/LayerView2D.js +1 -1
  76. package/views/2d/webglDeps.js +1 -1
  77. package/views/3d/GroundView3D.js +1 -1
  78. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  79. package/views/3d/analysis/LineOfSight/placementUtils.js +1 -1
  80. package/views/3d/analysis/Viewshed/placementUtils.js +1 -1
  81. package/views/3d/input/SceneInputManager.js +1 -1
  82. package/views/3d/interactive/Manipulator3D.js +1 -1
  83. package/views/3d/interactive/editingTools/draw/DrawGraphicTool3D.js +1 -1
  84. package/views/3d/interactive/editingTools/originGeometryVisualElementUtils.js +1 -1
  85. package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
  86. package/views/3d/layers/I3SMeshView3D.js +1 -1
  87. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  88. package/views/3d/layers/graphics/ElevationAligners.js +1 -1
  89. package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
  90. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  91. package/views/3d/layers/i3s/LayerElevationProvider.js +1 -1
  92. package/views/3d/layers/support/Tiles3DBVH.js +1 -1
  93. package/views/3d/layers/support/Tiles3DMeshIntersectionHandler.js +1 -1
  94. package/views/3d/support/engineContent/line.js +1 -1
  95. package/views/3d/support/engineContent/marker.js +1 -1
  96. package/views/3d/support/flow/StreamlineResources3D.js +1 -1
  97. package/views/3d/support/flow/StreamlineResources3DOverlay.js +1 -1
  98. package/views/3d/support/flow/StreamlineResources3DShape.js +1 -1
  99. package/views/3d/support/flow/geometryUtils.js +1 -1
  100. package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +1 -1
  101. package/views/3d/support/gaussianSplatting/GaussianSplatIntersectionHandler.js +1 -1
  102. package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +1 -1
  103. package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +1 -1
  104. package/views/3d/support/gaussianSplatting/GaussianTile.js +1 -1
  105. package/views/3d/support/gaussianSplatting/GaussianTileBuilder.js +2 -0
  106. package/views/3d/support/gaussianSplatting/formatConstants.js +2 -0
  107. package/views/3d/support/pointsOfInterest/CameraOnSurface.js +1 -1
  108. package/views/3d/support/pointsOfInterest/StableSurfaceCenter.js +1 -1
  109. package/views/3d/support/pointsOfInterest/SurfaceGeometryUpdates.js +1 -1
  110. package/views/3d/terrain/OverlayRenderer.js +1 -1
  111. package/views/3d/terrain/TerrainRenderer.js +1 -1
  112. package/views/3d/terrain/TerrainSurface.js +1 -1
  113. package/views/3d/terrain/TileCompositor.js +1 -1
  114. package/views/3d/terrain/TileRenderer.js +1 -1
  115. package/views/3d/webgl/RenderNode.d.ts +1 -1
  116. package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
  117. package/views/3d/webgl-engine/core/FBOCache.js +1 -1
  118. package/views/3d/webgl-engine/core/renderPasses/RenderPassManager.js +1 -1
  119. package/views/3d/webgl-engine/core/shaderLibrary/hud/HUD.glsl.js +1 -1
  120. package/views/3d/webgl-engine/core/shaderLibrary/util/GaussianSplatUnpacking.glsl.js +15 -11
  121. package/views/3d/webgl-engine/effects/atmosphere/LocalAtmosphere.js +1 -1
  122. package/views/3d/webgl-engine/effects/atmosphere/MarsAtmosphere.js +1 -1
  123. package/views/3d/webgl-engine/effects/clouds/CloudsRenderer.js +1 -1
  124. package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
  125. package/views/3d/webgl-engine/effects/magnifier/Magnifier.js +1 -1
  126. package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
  127. package/views/3d/webgl-engine/effects/ssao/SSAO.js +1 -1
  128. package/views/3d/webgl-engine/effects/stars/Stars.js +1 -1
  129. package/views/3d/webgl-engine/lib/AttributeView.js +1 -1
  130. package/views/3d/webgl-engine/lib/BasisUtil.js +1 -1
  131. package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
  132. package/views/3d/webgl-engine/lib/DDSUtil.js +1 -1
  133. package/views/3d/webgl-engine/lib/DrapedHeatmapRenderer.js +1 -1
  134. package/views/3d/webgl-engine/lib/GPUPointOcclusionQuery.js +1 -1
  135. package/views/3d/webgl-engine/lib/GaussianSplatRenderUtils.js +1 -1
  136. package/views/3d/webgl-engine/lib/ManagedTexture.js +1 -1
  137. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  138. package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
  139. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBuffer.js +1 -1
  140. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBufferView.js +1 -1
  141. package/views/3d/webgl-engine/lib/VerticesView.js +2 -0
  142. package/views/3d/webgl-engine/lib/attributeViewUtils.js +1 -1
  143. package/views/3d/webgl-engine/lib/edgeRendering/strokes.js +1 -1
  144. package/views/3d/webgl-engine/lib/glUtil3D.js +1 -1
  145. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  146. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  147. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  148. package/views/3d/webgl-engine/materials/internal/WaterTextureRepository.js +1 -1
  149. package/views/3d/webgl-engine/materials/internal/lineMarkerBufferUtils.js +2 -0
  150. package/views/3d/webgl-engine/materials/internal/ribbonLineBufferUtils.js +2 -0
  151. package/views/3d/webgl-engine/materials/renderers/VaoRenderer.js +1 -1
  152. package/views/3d/webgl-engine/materials/stippleTextureRepository.js +1 -1
  153. package/views/draw/DrawTool.js +1 -1
  154. package/views/draw/support/ManagedTooltipField.js +1 -1
  155. package/views/support/TextureCompressionHelper.js +1 -1
  156. package/views/support/imageReprojection.js +1 -1
  157. package/views/webgl/FramebufferObject.js +1 -1
  158. package/views/webgl/RenderingContext.js +1 -1
  159. package/views/webgl/Texture.js +1 -1
  160. package/views/webgl/rasterUtils.js +1 -1
  161. package/views/webgl/testSVGPremultipliedAlpha.js +1 -1
  162. package/views/webgl/textureUtils.js +1 -1
  163. package/widgets/OrientedImageryViewer/navigation/NavigationManager.js +1 -1
  164. package/widgets/OrientedImageryViewer/navigation/queries.js +1 -1
  165. package/widgets/OrientedImageryViewer/navigation/utils.js +1 -1
  166. package/widgets/OrientedImageryViewer.js +2 -2
  167. package/widgets/ScaleRangeSlider/types.d.ts +3 -3
  168. package/assets/esri/core/workers/chunks/039d9bc5b5015012f811.js +0 -1
  169. package/assets/esri/core/workers/chunks/08140725277de5d2e41a.js +0 -1
  170. package/assets/esri/core/workers/chunks/16cda273927ab0a39544.js +0 -1
  171. package/assets/esri/core/workers/chunks/29c610ce1c81ebb84a6b.js +0 -1
  172. package/assets/esri/core/workers/chunks/3223f9fbc76ba9ef8d13.js +0 -1
  173. package/assets/esri/core/workers/chunks/3fdcc383bbd9cf0d274c.js +0 -1
  174. package/assets/esri/core/workers/chunks/46c290108a90518ef695.js +0 -1
  175. package/assets/esri/core/workers/chunks/48b8b57f559a53c6c513.js +0 -1
  176. package/assets/esri/core/workers/chunks/4a979fce1c971b614a18.js +0 -1
  177. package/assets/esri/core/workers/chunks/5bd1414220e42cb8ebcf.js +0 -1
  178. package/assets/esri/core/workers/chunks/5d781c2c6204cffffd0d.js +0 -1
  179. package/assets/esri/core/workers/chunks/723df53cfa0189837d01.js +0 -1
  180. package/assets/esri/core/workers/chunks/7400b8c454b47ee4fb3c.js +0 -1
  181. package/assets/esri/core/workers/chunks/7af4edc6e87d27b9d467.js +0 -1
  182. package/assets/esri/core/workers/chunks/990e96139b5a1dccb061.js +0 -1
  183. package/assets/esri/core/workers/chunks/a607541959169741a943.js +0 -1
  184. package/assets/esri/core/workers/chunks/aa779896fd9e5c341349.js +0 -1
  185. package/assets/esri/core/workers/chunks/c131e0dd180a4c10e12e.js +0 -1
  186. package/assets/esri/core/workers/chunks/f3b4159c0722df8ffe13.js +0 -1
  187. package/assets/esri/core/workers/chunks/f75eec2cbc541eec9712.js +0 -1
  188. package/views/3d/webgl-engine/lib/GaussianSplatPrepassDepthRenderer.js +0 -2
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{unique as t}from"../../../core/arrayUtils.js";import{EventEmitter as n}from"../../../core/Evented.js";import"../../../core/has.js";import{someMap as r,everyMap as i}from"../../../core/MapUtils.js";import{disposeMaybe as a}from"../../../core/maybe.js";import o from"../../../core/PooledArray.js";import{watch as s,syncAndInitial as c,on as l,initial as u}from"../../../core/reactiveUtils.js";import{someSet as d}from"../../../core/SetUtils.js";import{property as f,subclass as p}from"../../../core/accessorSupport/decorators.js";import{ortho as m,fromTranslation as h}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{set as g}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ones as _}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{debugFlags as v}from"../support/debugFlags.js";import{Overlay as y}from"./Overlay.js";import{OverlayRenderTargets as b}from"./OverlayRenderTargets.js";import x from"../webgl/RenderCamera.js";import{SyncRenderPlugin as S}from"../webgl-engine/effects/RenderPlugin.js";import{trackHighlightOptions as C,renderHighlightBuffer as w}from"../webgl-engine/effects/highlight/Highlight.js";import{GLMaterialRepository as T}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as E}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as D,defaultRenderOccludedMask as O}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as k}from"../webgl-engine/lib/ShadowMap.js";import{T as A}from"../../../chunks/Texture.glsl.js";import{TextureTechnique as j}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as M}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as N}from"../webgl-engine/lighting/Lightsources.js";import{O as P}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as F}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import{TaskPriority as I}from"../../support/Scheduler.js";import L from"../../webgl/Texture.js";import{TextureDescriptor as R}from"../../webgl/TextureDescriptor.js";let z=class extends S{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new P,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new o,this._passParameters=new A,this._screenToMapUnitsRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new x,this.events=new n,this.longitudeCyclical=null,this.produces=new Map([[18,e=>e!==10||this.hasHighlights],[19,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1;let{state:t,stage:r}=e.parent.view,i=r.renderer.fboCache,a=r.renderView.renderingContext,s=r.renderView.techniques;this._renderContext=new D(a,new k(i,t.viewingMode),s)}initialize(){let e=this._view,t=e.stage.renderView.waterTextures;this.addHandles([s(()=>t.updating,()=>this.events.emit(`content-changed`),c),s(()=>this._spatialReference,e=>this._localOriginFactory=new E(e),c),l(()=>e.allLayerViews,`after-changes`,()=>this._sortedDrapeSourceRenderersDirty=!0),s(()=>C(e.state.highlights),()=>this._sortedDrapeSourceRenderersDirty=!0,u),s(()=>e.state.highlights,e=>{this._bindParameters.highlights=e},u),e.resourceController.scheduler.registerTask(I.OVERLAY_RENDERER,this)]);let n=this._camera;n.near=1,n.far=1e4,n.relativeElevation=null,this._bindParameters.slot=18,this._bindParameters.camera=n,this._bindParameters.updateLighting(new N(_()),0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=a(this._passParameters.texture),this.disposeOverlays(),this._renderContext.destroy(),this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToMapUnitsRatio(){return this._screenToMapUnitsRatio}get mapUnitsToGroundRatio(){return this.parent.mapUnitsToPlanarDistanceRatio*this._bindParameters.planarDistanceToGroundRatio}get localOriginFactory(){return this._localOriginFactory}set overlayStretch(e){this._bindParameters.overlayStretch=e}get overlayStretch(){return this._bindParameters.overlayStretch}set time(e){this._renderContext.time=e}get pluginContext(){return this._pluginContext}initializeRenderContext(e){let t=new T(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit(`content-changed`),this.notifyChange(`updating`),this.notifyChange(`isEmpty`)},()=>this.events.emit(`content-changed`));this._pluginContext={...e,materials:t},this._techniques.precompile(F)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||r(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return this._overlays!=null&&this._renderTargets!=null}getMaterialRenderer(e){for(let t of this._renderers.values()){let n=t.getMaterialRenderer(e);if(n)return n}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),t(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,t){this._renderers.get(e)?.destroy(),this._renderers.set(e,t),this._sortedDrapeSourceRenderersDirty=!0,`fullOpacity`in e&&this.addHandles(s(()=>e.fullOpacity,()=>this.events.emit(`content-changed`)),e)}removeDrapeSourceRenderer(e){if(e==null)return;let t=this._renderers.get(e);t!=null&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),t.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=this._overlays?d(e,e=>e.drapeTargetType===1):!1}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=d(e,e=>e.drapeSourceType===1),this._hasDrapedRasterSource=d(e,e=>e.drapeSourceType===0),this._hasDrapedFlowSource=d(e,e=>e.drapeSourceType===2)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,t){this._overlays??=(this._renderTargets=new b(this._stage.renderer.fboCache),[new y,new y]),this.ensureDrapeTargets(e),this.ensureDrapeSources(t)}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit(`textures-disposed`)}_useOverlayColorInsteadOfColorNoRasterImage(e){return e===1&&!this._needsColorWithoutRasterImage&&(this._hasDrapedFeatureSource||this._hasDrapedRasterSource)}getTexture(e){let t=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(t?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(()=>!0,e)}_onMaterialOrContentChanged(){this.renderOccludedFlags=r(this._renderers,e=>e.hasOccluders)?H:1}_processDrapeSources(e,t){let n=!1;for(let[r,i]of this._renderers){if(t?.done)break;(r.destroyed||e(r))&&i.commitChanges()&&(n=!0,t?.madeProgress())}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,n=!0,this._updateSortedDrapeSourceRenderers(),t?.madeProgress()),t&&this.compact(t),n&&(this._overlays!=null&&this._renderers.size===0&&this.disposeOverlays(),this.notifyChange(`updating`),this.notifyChange(`isEmpty`),this._onMaterialOrContentChanged(),this.hasHighlights=r(this._renderers,e=>e.hasHighlights),this.events.emit(`content-changed`))}compact(e){let t=!1;for(let n of this._renderers.values()){if(e.done)break;t=n.compact(e)||t}return t&&this.notifyChange(`updating`),t}hasHighlight(e){return r(this._renderers,t=>t.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(e=>e.updatePolicy===1)}get isEmpty(){return!v.OVERLAY_DRAW_DEBUG_TEXTURE&&i(this._renderers,e=>e.isEmpty)}get hasWater(){let e=r(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit(`has-water`)),this._hasWater}renders(e){if(v.OVERLAY_DRAW_DEBUG_TEXTURE&&e!==4&&e!==2)return!0;if(!this._overlays)return!1;let t=this._overlays[0];for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);if(!t.hasSomeSizedView())return!1;let n=this._setOutput(this._renderTargets?.targets.find(t=>t.content===e)?.output??0),r=this._bindParameters,i=r.highlightMixTexture;r.output===10&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null),++this._techniques.precompiling;let a=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,r.highlightMixTexture=i,this._setOutput(n),a}_setOutput(e){let t=this._bindParameters.output;return this._bindParameters.output=e,this._bindParameters.slot=e===4?19:18,t}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:+!!this._renderTargets?.getTexture(0)}updateAnimation(e){let t=!1;return this._renderers.forEach(n=>t=n.updateAnimation(e)||t),t&&this.parent.requestRender(0),t}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;let t=this._bindParameters;t.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(let e of this._renderTargets.targets){if(e.content===1&&!this._needsColorWithoutRasterImage)continue;let{output:n}=e;this._setOutput(n),n===10&&(t.highlightMixTexture=t.highlights.length>1?this._rctx.emptyTexture:null);let r=this._renderContext.renderOccludedMask;e.content===4&&(this._renderContext.renderOccludedMask=H),this._sortedRenderers.forAll(({drapeSource:t,renderer:n})=>{e.content===1&&t.drapeSourceType===0||e.content===4&&n.hasOnlyOccluders||n.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=r,t.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,t){if(!this._overlays||!this._renderTargets)return;for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;let n=this.allSourcesOccluders;for(let e of this._renderTargets.targets){if(!(e.content===0&&this._hasDrapedFlowSource)&&!e.handleRenderRequest(t)||e.content===1&&!this._needsColorWithoutRasterImage||e.content===4&&n)continue;let r=this._drawTarget(0,e),i=this._drawTarget(1,e);(r||i)&&e.fbo.generateMipMap()}}_drawTarget(e,t){let n=this._overlays[e],r=n.canvasGeometries;if(r.numViews===0)return!1;let i=this._view.state.contentPixelRatio;this._screenToMapUnitsRatio=i*n.mapUnitsPerPixel/this._bindParameters.overlayStretch;let{output:a,content:o}=t;if(this.isEmpty||a===4&&!this.hasWater||!n.hasSomeSizedView())return!1;let{_rctx:s,_camera:c,_renderContext:l,_bindParameters:u}=this;if(c.pixelRatio=n.pixelRatio*i,this._setOutput(a),u.screenToMapUnitsRatio=this._screenToMapUnitsRatio,u.screenToPlanarDistanceRatio=this._screenToMapUnitsRatio*this.parent.mapUnitsToPlanarDistanceRatio,o===4&&(l.renderOccludedMask=H),!this.renders(o))return l.renderOccludedMask=O,!1;let{resolution:d}=n,f=e===0,p=f?0:d;if(s.setViewport(p,0,d,d),this._bindTargetFBO(t),f&&(a===10?s.gl.clearBufferuiv(s.gl.COLOR,0,[0,0,0,0]):(s.setClearColor(0,0,0,0),s.clear(16384))),v.OVERLAY_DRAW_DEBUG_TEXTURE&&o!==4&&o!==2){this._techniques.precompile(j,U);let t=this._techniques.get(j,U);for(let i=0;i<r.numViews;i++)this._setViewParameters(r.extents[i],n),this._ensureDebugPatternResources(n.resolution,V[e]),s.bindTechnique(t,u,this._passParameters),s.screen.draw()}if(a===10){let{fboCache:n}=this._stage.renderer,r=this._resolution;this._bindTargetFBO(t),w(s,n,r,r,u,()=>this._renderAllGeometry(e,t),p)}else this._renderAllGeometry(e,t);return s.bindFramebuffer(null),l.renderOccludedMask=O,!0}get allSourcesOccluders(){return i(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,t){let n=this._overlays[e],r=n.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:a})=>{if(t.content===1&&i.drapeSourceType===0)return;let{fullOpacity:o}=i,s=o!=null&&o<1&&t.output===0&&this._bindTemporaryFBO();for(let e=0;e<r.numViews;e++)this._setViewParameters(r.extents[e],n),a.render(this._renderContext);if(s){this._bindTargetFBO(t),this._overlayParameters.texture=s.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;let n=this._techniques.get(F);this._rctx.bindTechnique(n,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),s.release()}})}_bindTargetFBO(e){let t=this._resolution,n=2*t;e.fbo.ensureFramebuffer(n,t),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){let e=this._resolution,t=2*e,n=this._stage.renderer.fboCache,r=n.acquire(t,e,`overlay tmp`);return n.rctx.bindFramebuffer(r.fbo),n.rctx.clear(16384),r}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit(`content-changed`)}intersectRay(e,t,n,r){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(let{renderer:a}of this._sortedRenderers)i=a.intersectRay?.(e,t,n,r,i)??i}*intersectScreenPolygon(e,t,n){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let r=0;for(let{renderer:i}of this._sortedRenderers)r=yield*i.intersectScreenPolygon(e,t,n,r)}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),this._renderers.size===0)return;let e=this._view.map.allLayers.map(e=>e.uid),t=e.length;this._renderers.forEach((n,r)=>{let i=e.indexOf(r.layer?.uid),a=i>=0,o=r.renderGroup??+!a,s=r.drapeSourcePriorityOffset??0,c=t*o+(a?i:0)+s;this._sortedRenderers.push(new B(r,n,c))}),this._sortedRenderers.sort((e,t)=>e.index-t.index)}_setViewParameters(e,t){let n=this._camera;n.viewport=[0,0,t.resolution,t.resolution],this._bindParameters.planarDistanceToGroundRatio=this.parent.getPlanarDistanceToGroundRatio((e[1]+e[3])*.5),m(n.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],n.near,n.far),h(n.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,t){if(g(this._passParameters.color,t[0],t[1],t[2]),this._passParameters.texture)return;let n=new Uint8Array(e*e*4),r=0;for(let t=0;t<e;t++)for(let i=0;i<e;i++){let a=Math.floor(i/10),o=Math.floor(t/10);a<2||o<2||a*10>e-20||o*10>e-20?(n[r++]=255,n[r++]=255,n[r++]=255,n[r++]=255):(n[r++]=255,n[r++]=255,n[r++]=255,a&1&&o&1?n[r++]=i&1^t&1?0:255:n[r++]=a&1^o&1?0:128)}let i=new R(e);i.samplingMode=9728,this._passParameters.texture=new L(this._rctx,i,n)}get test(){}};e([f()],z.prototype,`hasHighlights`,void 0),e([f()],z.prototype,`renderOccludedFlags`,void 0),e([f()],z.prototype,`_sortedDrapeSourceRenderersDirty`,void 0),e([f({constructOnly:!0})],z.prototype,`parent`,void 0),e([f({readOnly:!0})],z.prototype,`_techniques`,null),e([f({type:Boolean,readOnly:!0})],z.prototype,`updating`,null),e([f()],z.prototype,`isEmpty`,null),z=e([p(`esri.views.3d.terrain.OverlayRenderer`)],z);class B{constructor(e,t,n){this.drapeSource=e,this.renderer=t,this.index=n}}const V=[[1,.5,.5],[.5,.5,1]],H=4,U=new M;U.hasAlpha=!0;export{z as OverlayRenderer,H as overlayRenderOccludedFlag};
2
+ import{__decorate as e}from"tslib";import{unique as t}from"../../../core/arrayUtils.js";import{EventEmitter as n}from"../../../core/Evented.js";import"../../../core/has.js";import{someMap as r,everyMap as i}from"../../../core/MapUtils.js";import{disposeMaybe as a}from"../../../core/maybe.js";import o from"../../../core/PooledArray.js";import{watch as s,syncAndInitial as c,on as l,initial as u}from"../../../core/reactiveUtils.js";import{someSet as d}from"../../../core/SetUtils.js";import{property as f,subclass as p}from"../../../core/accessorSupport/decorators.js";import{ortho as m,fromTranslation as h}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{set as g}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ones as _}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{debugFlags as v}from"../support/debugFlags.js";import{Overlay as y}from"./Overlay.js";import{OverlayRenderTargets as b}from"./OverlayRenderTargets.js";import x from"../webgl/RenderCamera.js";import{SyncRenderPlugin as S}from"../webgl-engine/effects/RenderPlugin.js";import{trackHighlightOptions as C,renderHighlightBuffer as w}from"../webgl-engine/effects/highlight/Highlight.js";import{GLMaterialRepository as T}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as E}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as D,defaultRenderOccludedMask as O}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as k}from"../webgl-engine/lib/ShadowMap.js";import{T as A}from"../../../chunks/Texture.glsl.js";import{TextureTechnique as j}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as M}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as N}from"../webgl-engine/lighting/Lightsources.js";import{O as P}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as F}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import{TaskPriority as I}from"../../support/Scheduler.js";import{Texture as L}from"../../webgl/Texture.js";import{TextureDescriptor as R}from"../../webgl/TextureDescriptor.js";let z=class extends S{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new P,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new o,this._passParameters=new A,this._screenToMapUnitsRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new x,this.events=new n,this.longitudeCyclical=null,this.produces=new Map([[18,e=>e!==10||this.hasHighlights],[19,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1;let{state:t,stage:r}=e.parent.view,i=r.renderer.fboCache,a=r.renderView.renderingContext,s=r.renderView.techniques;this._renderContext=new D(a,new k(i,t.viewingMode),s)}initialize(){let e=this._view,t=e.stage.renderView.waterTextures;this.addHandles([s(()=>t.updating,()=>this.events.emit(`content-changed`),c),s(()=>this._spatialReference,e=>this._localOriginFactory=new E(e),c),l(()=>e.allLayerViews,`after-changes`,()=>this._sortedDrapeSourceRenderersDirty=!0),s(()=>C(e.state.highlights),()=>this._sortedDrapeSourceRenderersDirty=!0,u),s(()=>e.state.highlights,e=>{this._bindParameters.highlights=e},u),e.resourceController.scheduler.registerTask(I.OVERLAY_RENDERER,this)]);let n=this._camera;n.near=1,n.far=1e4,n.relativeElevation=null,this._bindParameters.slot=18,this._bindParameters.camera=n,this._bindParameters.updateLighting(new N(_()),0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=a(this._passParameters.texture),this.disposeOverlays(),this._renderContext.destroy(),this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToMapUnitsRatio(){return this._screenToMapUnitsRatio}get mapUnitsToGroundRatio(){return this.parent.mapUnitsToPlanarDistanceRatio*this._bindParameters.planarDistanceToGroundRatio}get localOriginFactory(){return this._localOriginFactory}set overlayStretch(e){this._bindParameters.overlayStretch=e}get overlayStretch(){return this._bindParameters.overlayStretch}set time(e){this._renderContext.time=e}get pluginContext(){return this._pluginContext}initializeRenderContext(e){let t=new T(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit(`content-changed`),this.notifyChange(`updating`),this.notifyChange(`isEmpty`)},()=>this.events.emit(`content-changed`));this._pluginContext={...e,materials:t},this._techniques.precompile(F)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||r(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return this._overlays!=null&&this._renderTargets!=null}getMaterialRenderer(e){for(let t of this._renderers.values()){let n=t.getMaterialRenderer(e);if(n)return n}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),t(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,t){this._renderers.get(e)?.destroy(),this._renderers.set(e,t),this._sortedDrapeSourceRenderersDirty=!0,`fullOpacity`in e&&this.addHandles(s(()=>e.fullOpacity,()=>this.events.emit(`content-changed`)),e)}removeDrapeSourceRenderer(e){if(e==null)return;let t=this._renderers.get(e);t!=null&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),t.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=this._overlays?d(e,e=>e.drapeTargetType===1):!1}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=d(e,e=>e.drapeSourceType===1),this._hasDrapedRasterSource=d(e,e=>e.drapeSourceType===0),this._hasDrapedFlowSource=d(e,e=>e.drapeSourceType===2)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,t){this._overlays??=(this._renderTargets=new b(this._stage.renderer.fboCache),[new y,new y]),this.ensureDrapeTargets(e),this.ensureDrapeSources(t)}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit(`textures-disposed`)}_useOverlayColorInsteadOfColorNoRasterImage(e){return e===1&&!this._needsColorWithoutRasterImage&&(this._hasDrapedFeatureSource||this._hasDrapedRasterSource)}getTexture(e){let t=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(t?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(()=>!0,e)}_onMaterialOrContentChanged(){this.renderOccludedFlags=r(this._renderers,e=>e.hasOccluders)?H:1}_processDrapeSources(e,t){let n=!1;for(let[r,i]of this._renderers){if(t?.done)break;(r.destroyed||e(r))&&i.commitChanges()&&(n=!0,t?.madeProgress())}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,n=!0,this._updateSortedDrapeSourceRenderers(),t?.madeProgress()),t&&this.compact(t),n&&(this._overlays!=null&&this._renderers.size===0&&this.disposeOverlays(),this.notifyChange(`updating`),this.notifyChange(`isEmpty`),this._onMaterialOrContentChanged(),this.hasHighlights=r(this._renderers,e=>e.hasHighlights),this.events.emit(`content-changed`))}compact(e){let t=!1;for(let n of this._renderers.values()){if(e.done)break;t=n.compact(e)||t}return t&&this.notifyChange(`updating`),t}hasHighlight(e){return r(this._renderers,t=>t.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(e=>e.updatePolicy===1)}get isEmpty(){return!v.OVERLAY_DRAW_DEBUG_TEXTURE&&i(this._renderers,e=>e.isEmpty)}get hasWater(){let e=r(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit(`has-water`)),this._hasWater}renders(e){if(v.OVERLAY_DRAW_DEBUG_TEXTURE&&e!==4&&e!==2)return!0;if(!this._overlays)return!1;let t=this._overlays[0];for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);if(!t.hasSomeSizedView())return!1;let n=this._setOutput(this._renderTargets?.targets.find(t=>t.content===e)?.output??0),r=this._bindParameters,i=r.highlightMixTexture;r.output===10&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null),++this._techniques.precompiling;let a=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,r.highlightMixTexture=i,this._setOutput(n),a}_setOutput(e){let t=this._bindParameters.output;return this._bindParameters.output=e,this._bindParameters.slot=e===4?19:18,t}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:+!!this._renderTargets?.getTexture(0)}updateAnimation(e){let t=!1;return this._renderers.forEach(n=>t=n.updateAnimation(e)||t),t&&this.parent.requestRender(0),t}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;let t=this._bindParameters;t.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(let e of this._renderTargets.targets){if(e.content===1&&!this._needsColorWithoutRasterImage)continue;let{output:n}=e;this._setOutput(n),n===10&&(t.highlightMixTexture=t.highlights.length>1?this._rctx.emptyTexture:null);let r=this._renderContext.renderOccludedMask;e.content===4&&(this._renderContext.renderOccludedMask=H),this._sortedRenderers.forAll(({drapeSource:t,renderer:n})=>{e.content===1&&t.drapeSourceType===0||e.content===4&&n.hasOnlyOccluders||n.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=r,t.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,t){if(!this._overlays||!this._renderTargets)return;for(let e of this._overlays)e.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;let n=this.allSourcesOccluders;for(let e of this._renderTargets.targets){if(!(e.content===0&&this._hasDrapedFlowSource)&&!e.handleRenderRequest(t)||e.content===1&&!this._needsColorWithoutRasterImage||e.content===4&&n)continue;let r=this._drawTarget(0,e),i=this._drawTarget(1,e);(r||i)&&e.fbo.generateMipMap()}}_drawTarget(e,t){let n=this._overlays[e],r=n.canvasGeometries;if(r.numViews===0)return!1;let i=this._view.state.contentPixelRatio;this._screenToMapUnitsRatio=i*n.mapUnitsPerPixel/this._bindParameters.overlayStretch;let{output:a,content:o}=t;if(this.isEmpty||a===4&&!this.hasWater||!n.hasSomeSizedView())return!1;let{_rctx:s,_camera:c,_renderContext:l,_bindParameters:u}=this;if(c.pixelRatio=n.pixelRatio*i,this._setOutput(a),u.screenToMapUnitsRatio=this._screenToMapUnitsRatio,u.screenToPlanarDistanceRatio=this._screenToMapUnitsRatio*this.parent.mapUnitsToPlanarDistanceRatio,o===4&&(l.renderOccludedMask=H),!this.renders(o))return l.renderOccludedMask=O,!1;let{resolution:d}=n,f=e===0,p=f?0:d;if(s.setViewport(p,0,d,d),this._bindTargetFBO(t),f&&(a===10?s.gl.clearBufferuiv(s.gl.COLOR,0,[0,0,0,0]):(s.setClearColor(0,0,0,0),s.clear(16384))),v.OVERLAY_DRAW_DEBUG_TEXTURE&&o!==4&&o!==2){this._techniques.precompile(j,U);let t=this._techniques.get(j,U);for(let i=0;i<r.numViews;i++)this._setViewParameters(r.extents[i],n),this._ensureDebugPatternResources(n.resolution,V[e]),s.bindTechnique(t,u,this._passParameters),s.screen.draw()}if(a===10){let{fboCache:n}=this._stage.renderer,r=this._resolution;this._bindTargetFBO(t),w(s,n,r,r,u,()=>this._renderAllGeometry(e,t),p)}else this._renderAllGeometry(e,t);return s.bindFramebuffer(null),l.renderOccludedMask=O,!0}get allSourcesOccluders(){return i(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,t){let n=this._overlays[e],r=n.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:a})=>{if(t.content===1&&i.drapeSourceType===0)return;let{fullOpacity:o}=i,s=o!=null&&o<1&&t.output===0&&this._bindTemporaryFBO();for(let e=0;e<r.numViews;e++)this._setViewParameters(r.extents[e],n),a.render(this._renderContext);if(s){this._bindTargetFBO(t),this._overlayParameters.texture=s.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;let n=this._techniques.get(F);this._rctx.bindTechnique(n,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),s.release()}})}_bindTargetFBO(e){let t=this._resolution,n=2*t;e.fbo.ensureFramebuffer(n,t),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){let e=this._resolution,t=2*e,n=this._stage.renderer.fboCache,r=n.acquire(t,e,`overlay tmp`);return n.rctx.bindFramebuffer(r.fbo),n.rctx.clear(16384),r}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit(`content-changed`)}intersectRay(e,t,n,r){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(let{renderer:a}of this._sortedRenderers)i=a.intersectRay?.(e,t,n,r,i)??i}*intersectScreenPolygon(e,t,n){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let r=0;for(let{renderer:i}of this._sortedRenderers)r=yield*i.intersectScreenPolygon(e,t,n,r)}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),this._renderers.size===0)return;let e=this._view.map.allLayers.map(e=>e.uid),t=e.length;this._renderers.forEach((n,r)=>{let i=e.indexOf(r.layer?.uid),a=i>=0,o=r.renderGroup??+!a,s=r.drapeSourcePriorityOffset??0,c=t*o+(a?i:0)+s;this._sortedRenderers.push(new B(r,n,c))}),this._sortedRenderers.sort((e,t)=>e.index-t.index)}_setViewParameters(e,t){let n=this._camera;n.viewport=[0,0,t.resolution,t.resolution],this._bindParameters.planarDistanceToGroundRatio=this.parent.getPlanarDistanceToGroundRatio((e[1]+e[3])*.5),m(n.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],n.near,n.far),h(n.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,t){if(g(this._passParameters.color,t[0],t[1],t[2]),this._passParameters.texture)return;let n=new Uint8Array(e*e*4),r=0;for(let t=0;t<e;t++)for(let i=0;i<e;i++){let a=Math.floor(i/10),o=Math.floor(t/10);a<2||o<2||a*10>e-20||o*10>e-20?(n[r++]=255,n[r++]=255,n[r++]=255,n[r++]=255):(n[r++]=255,n[r++]=255,n[r++]=255,a&1&&o&1?n[r++]=i&1^t&1?0:255:n[r++]=a&1^o&1?0:128)}let i=new R(e);i.samplingMode=9728,this._passParameters.texture=new L(this._rctx,i,n)}get test(){}};e([f()],z.prototype,`hasHighlights`,void 0),e([f()],z.prototype,`renderOccludedFlags`,void 0),e([f()],z.prototype,`_sortedDrapeSourceRenderersDirty`,void 0),e([f({constructOnly:!0})],z.prototype,`parent`,void 0),e([f({readOnly:!0})],z.prototype,`_techniques`,null),e([f({type:Boolean,readOnly:!0})],z.prototype,`updating`,null),e([f()],z.prototype,`isEmpty`,null),z=e([p(`esri.views.3d.terrain.OverlayRenderer`)],z);class B{constructor(e,t,n){this.drapeSource=e,this.renderer=t,this.index=n}}const V=[[1,.5,.5],[.5,.5,1]],H=4,U=new M;U.hasAlpha=!0;export{z as OverlayRenderer,H as overlayRenderOccludedFlag};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import has from"../../../core/has.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{MemCachePool as n}from"../../../core/MemCachePool.js";import r from"../../../core/ObjectPool.js";import{watch as i,sync as a}from"../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import{subtract as c,set as l,dot as u}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as d,fromValues as f,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as m,ZEROS as h}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as g,set as _}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as v}from"../../../geometry/support/buffer/BufferView.js";import{overlayRenderOccludedFlag as y}from"./OverlayRenderer.js";import{PatchRenderData as b}from"./PatchRenderData.js";import{TerrainAttributesCache as x}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as S}from"./terrainUtils.js";import{TileRenderer as C}from"./TileRenderer.js";import{IteratorPreorder as w,fallsWithinLayerView as T,usesStencil as E,sortTiles as D,compareTiles as O}from"./tileUtils.js";import{getOverlayContentForOutputTerrain as k}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as A}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as j}from"../webgl-engine/lib/Attribute.js";import{IntersectorResultRay as M}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as N,MeshIntersectionOptions as P,intersectTriangles as F}from"../webgl-engine/lib/RayIntersections.js";import{TriangleIntersectionData as I}from"../webgl-engine/lib/TriangleIntersectionData.js";import{terrainId as L,getVerticalOffsetTerrain as R}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as z}from"../webgl-engine/materials/DrawParameters.js";import{hasShadowHighlights as B}from"../webgl-engine/shaders/ReceiveShadowsConfiguration.js";import{T as V}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as H}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as U}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as W}from"../../webgl/enums.js";const G=g();let K=class extends A{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return this._view.stage.viewingMode===1}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}get renderOccludedFlags(){return this._overlayRenderer.renderOccludedFlags}constructor(e,t,i,a,o){super({}),this._surface=e,this._overlayRenderer=t,this._allTiles=i,this._compressionTracker=a,this.type=7,this.isGround=!0,this._passParameters=new V,this._drawParameters=new z,this._renderDataPool=new r(()=>new b),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new w,this._castShadows=!1,this._inViewshed=!1,this._cutFillEnabled=!1,this._tileRenderer=null,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.produces=new Map([[1,()=>this._desiredSlot===1],[7,()=>this._desiredSlot===7],[9,()=>this._produces()&&this.renderOccludedFlags===y]]),this._tileSize=256,this._configuration=new U(e.isGlobal),this._tileTextureCache=new n((e,t)=>o.newCache(e,t),`TileTexture`),this.tileGeometryCache=new x(o)}normalizeCtorArgs(){return{}}initialize(){this.addHandles(i(()=>this._overlayRenderer.renderOccludedFlags,()=>this.requestRender(),a))}destroy(){this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}set renderingDisabled(e){this._set(`renderingDisabled`,!!e),this.setDirty()}set visible(e){this._set(`visible`,!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.requestRender())}get transparency(){return this._configuration.transparencyMode}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.requestRender(),this.notifyChange(`renderPatchBorders`))}get layerViewUid(){return L}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.requestRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.requestRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.requestRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,this._tileRenderer!=null&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,32)}reuseTextureFromParent(e){let{parent:t}=e;if(!this._canReuseTextureFromParent(t,e))return!1;let n=m(e.lij[2]&1?.5:0,e.lij[1]&1?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,n)??!1}_canReuseTextureFromParent(e,t){if(!e)return!1;let{layerInfo:n,surface:r}=t;for(let i=0;i<n[1].length;i++){let n=r.layerViewByIndex(i,1);if(T(e,n)!==T(t,n))return!1}return!0}updateTileTexture(e,t){this._tileRenderer!=null&&(this._tileRenderer.updateTileTexture(e,t===32?0:2),this.requestRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(let t of e.layerInfo[0])t.pendingUpdates&=-9;e.resetPendingUpdate(8);let t=e.renderData.updateGeometryState();return this._surface.updateElevationSources(e),t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){let t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){let t=Math.max(0,Math.floor((e.level-3)/7)*7);if(this._isGlobal&&t===0)return d;for(;e.parent&&e.level>t;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get(`wireframe`)!==e&&(this._set(`wireframe`,e),this.requestRender())}setDirty(e=1){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=1){this._patchSortingDirty=!0,this._context.requestRender(e)}requestRender(e=1){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new C(this._surface,this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=t(this._tileRenderer)}intersectRay(e,t,n,r){let i=this._rootTiles;if(!i||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==0)return;let a=q,o=J;c(a,r,n),l(o,1/a[0],1/a[1],1/a[2]);let s=e.results.min,d=e.results.max,f=e.results.ground,p=e.options.store===0,m=!!e.results.ground.target,h=R(e.verticalOffset),g=e.tolerance,y,b=p&&s.distance!=null?s.distance:1/0,x=e.options,S=x.normalRequired||!x.backfacesTerrain,C=new P(g,!1,S),w=i=>{let l=i.renderData;if(!l?.vao)return;let m=l.geometry;_(G,m.boundingBox);let w=l.localOrigin;if(h!=null&&(h.localOrigin=w,h.applyToAabb(G)),Y[0]=n[0]-w[0],Y[1]=n[1]-w[1],Y[2]=n[2]-w[2],!N(G,Y,o,g,b))return;let T=(e,t,n,r)=>{e.set(this.type,i,t,n,r),b=p&&s.renderDistance!=null?s.renderDistance:1/0},E=(i,o,c)=>{(!S||c!=null)&&o>=0&&(x.backfacesTerrain||u(c,a)<0)&&(x.invisibleTerrain||!x.selectionMode||t==null||t(n,r,o))&&((f.renderDistance==null||o<f.renderDistance)&&T(f,i,o,c),x.isFiltered||(x.store===2&&(y==null?(y=new M(e.ray),T(y,i,o,c),e.results.all.push(y)):o<y.renderDistance&&T(y,i,o,c)),(s.renderDistance==null||o<s.renderDistance)&&T(s,i,o,c),x.store!==0&&(d.renderDistance==null||o>d.renderDistance)&&T(d,i,o,c)))},D=X;c(D,r,w);let{indices:O,indexCount:k}=m,A=m.vertexAttributes,P=A.getField(`position`,v),L=new j(P.typedBuffer,3,A.stride/4),R=k/3;!h&&R>200?(l.intersectionData??=new I(O,R,L),l.intersectionData.intersectRay(Y,D,C,E)):F(Y,D,0,R,(e,t)=>P.getVec(O[t],e),h,C,E)},T=this._tileIterator;T.reset(i);let D=e.options.invisibleTerrain;for(let e=T.next();e;e=T.next())(e.visible||D&&e.intersectsClippingArea)&&(h!=null||e.intersectsRay(n,a,g,b))&&(!m||!E(e,this._stencilEnabledLayerExtents))?w(e):T.skipSubtree()}processScaleRangeQueries(e,t){if(!t.done&&e)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(let t of this._visiblePatchesByOrigin.values())for(let n of t)n.renderData?.textureReference!=null&&e.queriesForTile(n);e.process(),t.madeProgress()}}get _view(){return this._surface.view}get _desiredSlot(){if(!this._produces())return null;switch(this.transparency){case 0:return 1;case 1:case 2:return 7;case 3:case 4:return null}}acquireTechniques(e){let{shadowMap:t,viewshedEnabled:n,cutFillComputationEnabled:r,slot:i,hasEmission:a,useFloatBlend:o}=e.bind,s=!!has(`enable-feature:terrain-shadows`)&&t.enabled;if(s!==this._castShadows&&(this._castShadows=s,this._patchesByOriginDirty=!0),this._inViewshed!==n&&(this._inViewshed=n,this._patchesByOriginDirty=!0),this._cutFillEnabled!==r&&(this._cutFillEnabled=r,this._patchesByOriginDirty=!0),this.transparency===3)return null;if(i===9){if((e.renderOccludedMask&y)===0)return null}else if(i!==this._desiredSlot)return null;let c=this._configuration;switch(c.receiveGlobalIllumination=c.screenSpaceReflections=c.cloudReflections=c.receiveShadows=c.hasShadowHighlights=c.receiveAmbientOcclusion=c.renderOccluded=c.hasHighlightMixTexture=!1,c.hasEmission=a,c.overlayMode=this._overlayRenderer.mode,c.useFloatBlend=o.value,e.output){case 0:case 1:case 2:{let n=e.bind;c.screenSpaceReflections=n.hasScreenSpaceReflections,c.cloudReflections=n.clouds.data!=null;let r=i===9;return c.receiveShadows=t.ready&&!r,c.hasShadowHighlights=B(c,e.bind),c.renderOccluded=r,c.receiveAmbientOcclusion=!r&&n.ssao!=null,c.receiveGlobalIllumination=!r&&n.globalIlluminationEnabled,this._acquireTechnique(e.output)}case 5:case 7:return this._castShadows?this._acquireTechnique(5):null;case 8:return this._inViewshed?this._acquireTechnique(8):null;case 9:return this._cutFillEnabled?this._acquireTechnique(9):null;case 3:case 4:case 11:return this._acquireTechnique(e.output);case 10:return c.hasHighlightMixTexture=e.bind.highlightMixTexture!=null,this._overlayRenderer.hasHighlights?this._acquireTechnique(10):null}return null}render(e,t){switch(this._updatePatchGroups(),this._passParameters.useStencil=!1,this._passParameters.overlayContent=k(e.output,e.bind),e.output){case 0:case 1:case 2:return this._renderMaterialPass(e,t);case 3:case 4:case 11:return this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);case 10:{let n=e.bind.highlight?.name;n&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(2)&&this._overlayRenderer.hasHighlight(n)&&this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);break}case 5:case 7:case 8:case 9:return this._renderAuxiliaryPass(e,t,this._allPatchesByOrigin)}}updateTileBackground(e){if(this._tileRenderer==null)return;let t=this._tileRenderer,n;if(e!=null){let t=e.toUnitRGBA();n=f(t[0]||0,t[1]||0,t[2]||0)}t.setBackground(n),this._allTiles.forAll(e=>t.updateTileTexture(e,0)),this._configuration.tileBlendInput=t.backgroundIsGrid?2:t.backgroundColor==null?0:1,this.requestRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty){let e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(let n of e)D(n,t);e.sort((e,t)=>O(e[0],t[0])),this._visiblePatchesByOrigin=new Map(e.map(e=>[e[0].renderData.localOrigin,e])),this.notifyChange(`visibleTiles`),this._patchSortingDirty=!1}}_rebuildPatchGroups(){let e=this._rootTiles;if(e!=null){e[0]?.surface.checkAllTilesWaterproofness(`render-patch-groups`),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(let t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){let t=this._tileIterator;for(t.resetOne(e);!t.done;){let e=t.next(),n=e.renderData;if(!n){this._numTilesCulled++;continue}let r=n.localOrigin;if(this._castShadows||this._inViewshed||this._cutFillEnabled){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let i=this._visiblePatchesByOrigin.get(r);i||(i=[],this._visiblePatchesByOrigin.set(r,i)),i.push(e),t.skipSubtree()}}_renderAuxiliaryPass(e,t,n){let{rctx:r,bind:i}=e;r.bindTechnique(t,i,this._passParameters);let a=!!this._stencilEnabledLayerExtents?.length;n.forEach(n=>{this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(i,this._passParameters,this._drawParameters);for(let r=0;r<n.length;r++)this._renderPatch(e,t,n[r],W.TRIANGLES,a,this._passParameters.overlayContent===null)}),r.bindVAO(null)}_renderMaterialPass(e,t){let{rctx:n,bind:r}=e,i=n.bindTechnique(t,r,this._passParameters);this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;let a=r.slot===9;a&&(i.bindTexture(`tex`,n.emptyTexture),i.setUniform3fv(`textureOpacities`,d),i.setUniform4fv(`texOffsetAndScale`,h));let o=this._tileRenderer?.backgroundColor==null?d:this._tileRenderer.backgroundColor;this._configuration.tileBlendInput===1&&i.setUniform3fv(`backgroundColor`,o);let s=!!this._stencilEnabledLayerExtents?.length,c=this.wireframe?W.LINES:W.TRIANGLES;this._configuration.textureFadingEnabled&&i.bindTexture(`texNext`,n.emptyTexture);for(let n of this._visiblePatchesByOrigin.values()){this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(r,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(let r of n){let n=r.renderData,o=n.textureReference;if(o!=null){if(!a){i.setUniform4fv(`texOffsetAndScale`,o.offsetAndScale),i.bindTexture(`tex`,o.texture.texture);let e=n.textureFadeFactor,t=e<1?n.nextTextureReference:null;this._configuration.textureFadingEnabled&&t&&e<1?(i.setUniform1f(`fadeFactor`,e),i.setUniform4fv(`nextTexOffsetAndScale`,t.offsetAndScale),i.setUniform3fv(`nextTexOpacities`,t.opacities),i.bindTexture(`texNext`,t.texture.texture)):i.setUniform1f(`fadeFactor`,1),n.textureIsFading&&this.requestRender(2),i.setUniform3fv(`textureOpacities`,o.opacities)}this._renderPatch(e,t,r,c,s),r.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}n.bindVAO(null)}_renderPatch(e,t,n,r,i,a=!1){let o=n.renderData,s=o.vao,c=s?.indexBuffer;if(!s||c==null){S&&console.error(`Rendered tile with no indices: `,n.lij,` : `,o);return}let l=t.program;!a&&!this._overlayRenderer.isEmpty&&this._bindOverlayPatchData(l,o.overlay);let{rctx:u,bind:d}=e;i&&(this._passParameters.useStencil=E(n,this._stencilEnabledLayerExtents),u.setPipelineState(t.getPipeline(d,this._passParameters)));let f=o.geometry.indexCount;u.bindVAO(s),l.assertCompatibleVertexAttributeLocations(s),u.drawElements(r,f,c.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv(`overlayTexOffset`,t.offsets),e.setUniform4fv(`overlayTexScale`,t.scales)}_acquireTechnique(e){return this._configuration.output=e,this._techniques.get(H,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([o({readOnly:!0})],K.prototype,`visibleTiles`,null),e([o({readOnly:!0})],K.prototype,`_isGlobal`,null),e([o()],K.prototype,`renderOccludedFlags`,null),e([o({value:!1})],K.prototype,`renderingDisabled`,null),e([o({value:!0})],K.prototype,`visible`,null),e([o()],K.prototype,`renderPatchBorders`,null),e([o()],K.prototype,`wireframe`,null),K=e([s(`esri.views.3d.terrain.TerrainRenderer`)],K);const q=p(),J=p(),Y=p(),X=p();export{K as TerrainRenderer};
2
+ import{__decorate as e}from"tslib";import has from"../../../core/has.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{MemCachePool as n}from"../../../core/MemCachePool.js";import r from"../../../core/ObjectPool.js";import{watch as i,sync as a}from"../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../core/accessorSupport/decorators.js";import{subtract as c,set as l,dot as u}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as d,fromValues as f,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as m,ZEROS as h}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as g,set as _}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as v}from"../../../geometry/support/buffer/BufferView.js";import{overlayRenderOccludedFlag as y}from"./OverlayRenderer.js";import{PatchRenderData as b}from"./PatchRenderData.js";import{TerrainAttributesCache as x}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as S}from"./terrainUtils.js";import{TileRenderer as C}from"./TileRenderer.js";import{IteratorPreorder as w,fallsWithinLayerView as T,usesStencil as E,sortTiles as D,compareTiles as O}from"./tileUtils.js";import{getOverlayContentForOutputTerrain as k}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as A}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as j}from"../webgl-engine/lib/Attribute.js";import{IntersectorResultRay as M}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as N,MeshIntersectionOptions as P,intersectTriangles as F}from"../webgl-engine/lib/RayIntersections.js";import{TriangleIntersectionData as I}from"../webgl-engine/lib/TriangleIntersectionData.js";import{terrainId as L,getVerticalOffsetTerrain as R}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as z}from"../webgl-engine/materials/DrawParameters.js";import{hasShadowHighlights as B}from"../webgl-engine/shaders/ReceiveShadowsConfiguration.js";import{T as V}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as H}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as U}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as W}from"../../webgl/enums.js";const G=g();let K=class extends A{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return this._view.stage.viewingMode===1}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}get renderOccludedFlags(){return this._overlayRenderer.renderOccludedFlags}constructor(e,t,i,a,o){super({}),this._surface=e,this._overlayRenderer=t,this._allTiles=i,this._compressionTracker=a,this.type=7,this.isGround=!0,this._passParameters=new V,this._drawParameters=new z,this._renderDataPool=new r(()=>new b),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new w,this._castShadows=!1,this._inViewshed=!1,this._cutFillEnabled=!1,this._tileRenderer=null,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.produces=new Map([[1,()=>this._desiredSlot===1],[7,()=>this._desiredSlot===7],[9,()=>this._produces()&&this.renderOccludedFlags===y]]),this._tileSize=256,this._configuration=new U(e.isGlobal),this._tileTextureCache=new n((e,t)=>o.newCache(e,t),`TileTexture`),this.tileGeometryCache=new x(o)}normalizeCtorArgs(){return{}}initialize(){this.addHandles(i(()=>this._overlayRenderer.renderOccludedFlags,()=>this.requestRender(),a))}destroy(){this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}set renderingDisabled(e){this._set(`renderingDisabled`,!!e),this.setDirty()}set visible(e){this._set(`visible`,!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.requestRender())}get transparency(){return this._configuration.transparencyMode}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.requestRender(),this.notifyChange(`renderPatchBorders`))}get layerViewUid(){return L}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.requestRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.requestRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.requestRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,this._tileRenderer!=null&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,32)}reuseTextureFromParent(e){let{parent:t}=e;if(!this._canReuseTextureFromParent(t,e))return!1;let n=m(e.lij[2]&1?.5:0,e.lij[1]&1?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,n)??!1}_canReuseTextureFromParent(e,t){if(!e)return!1;let{layerInfo:n,surface:r}=t;for(let i=0;i<n[1].length;i++){let n=r.layerViewByIndex(i,1);if(T(e,n)!==T(t,n))return!1}return!0}updateTileTexture(e,t){if(this._tileRenderer!=null){let n=t===32?0:2;if(!this._tileRenderer.updateTileTexture(e,n))return e.updateRenderData(1,n),!1;this.requestRender(),e.resetPendingUpdate(t)}return!0}updateTileGeometryState(e){for(let t of e.layerInfo[0])t.pendingUpdates&=-9;e.resetPendingUpdate(8);let t=e.renderData.updateGeometryState();return this._surface.updateElevationSources(e),t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){let t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){let t=Math.max(0,Math.floor((e.level-3)/7)*7);if(this._isGlobal&&t===0)return d;for(;e.parent&&e.level>t;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get(`wireframe`)!==e&&(this._set(`wireframe`,e),this.requestRender())}setDirty(e=1){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=1){this._patchSortingDirty=!0,this._context.requestRender(e)}requestRender(e=1){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new C(this._surface,this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=t(this._tileRenderer)}intersectRay(e,t,n,r){let i=this._rootTiles;if(!i||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&this.transparency!==0)return;let a=q,o=J;c(a,r,n),l(o,1/a[0],1/a[1],1/a[2]);let s=e.results.min,d=e.results.max,f=e.results.ground,p=e.options.store===0,m=!!e.results.ground.target,h=R(e.verticalOffset),g=e.tolerance,y,b=p&&s.distance!=null?s.distance:1/0,x=e.options,S=x.normalRequired||!x.backfacesTerrain,C=new P(g,!1,S),w=i=>{let l=i.renderData;if(!l?.vao)return;let m=l.geometry;_(G,m.boundingBox);let w=l.localOrigin;if(h!=null&&(h.localOrigin=w,h.applyToAabb(G)),Y[0]=n[0]-w[0],Y[1]=n[1]-w[1],Y[2]=n[2]-w[2],!N(G,Y,o,g,b))return;let T=(e,t,n,r)=>{e.set(this.type,i,t,n,r),b=p&&s.renderDistance!=null?s.renderDistance:1/0},E=(i,o,c)=>{(!S||c!=null)&&o>=0&&(x.backfacesTerrain||u(c,a)<0)&&(x.invisibleTerrain||!x.selectionMode||t==null||t(n,r,o))&&((f.renderDistance==null||o<f.renderDistance)&&T(f,i,o,c),x.isFiltered||(x.store===2&&(y==null?(y=new M(e.ray),T(y,i,o,c),e.results.all.push(y)):o<y.renderDistance&&T(y,i,o,c)),(s.renderDistance==null||o<s.renderDistance)&&T(s,i,o,c),x.store!==0&&(d.renderDistance==null||o>d.renderDistance)&&T(d,i,o,c)))},D=X;c(D,r,w);let{indices:O,indexCount:k}=m,A=m.vertexAttributes,P=A.getField(`position`,v),L=new j(P.typedBuffer,3,A.stride/4),R=k/3;!h&&R>200?(l.intersectionData??=new I(O,R,L),l.intersectionData.intersectRay(Y,D,C,E)):F(Y,D,0,R,(e,t)=>P.getVec(O[t],e),h,C,E)},T=this._tileIterator;T.reset(i);let D=e.options.invisibleTerrain;for(let e=T.next();e;e=T.next())(e.visible||D&&e.intersectsClippingArea)&&(h!=null||e.intersectsRay(n,a,g,b))&&(!m||!E(e,this._stencilEnabledLayerExtents))?w(e):T.skipSubtree()}processScaleRangeQueries(e,t){if(!t.done&&e)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(let t of this._visiblePatchesByOrigin.values())for(let n of t)n.renderData?.textureReference!=null&&e.queriesForTile(n);e.process(),t.madeProgress()}}get _view(){return this._surface.view}get _desiredSlot(){if(!this._produces())return null;switch(this.transparency){case 0:return 1;case 1:case 2:return 7;case 3:case 4:return null}}acquireTechniques(e){let{shadowMap:t,viewshedEnabled:n,cutFillComputationEnabled:r,slot:i,hasEmission:a,useFloatBlend:o}=e.bind,s=!!has(`enable-feature:terrain-shadows`)&&t.enabled;if(s!==this._castShadows&&(this._castShadows=s,this._patchesByOriginDirty=!0),this._inViewshed!==n&&(this._inViewshed=n,this._patchesByOriginDirty=!0),this._cutFillEnabled!==r&&(this._cutFillEnabled=r,this._patchesByOriginDirty=!0),this.transparency===3)return null;if(i===9){if((e.renderOccludedMask&y)===0)return null}else if(i!==this._desiredSlot)return null;let c=this._configuration;switch(c.receiveGlobalIllumination=c.screenSpaceReflections=c.cloudReflections=c.receiveShadows=c.hasShadowHighlights=c.receiveAmbientOcclusion=c.renderOccluded=c.hasHighlightMixTexture=!1,c.hasEmission=a,c.overlayMode=this._overlayRenderer.mode,c.useFloatBlend=o.value,e.output){case 0:case 1:case 2:{let n=e.bind;c.screenSpaceReflections=n.hasScreenSpaceReflections,c.cloudReflections=n.clouds.data!=null;let r=i===9;return c.receiveShadows=t.ready&&!r,c.hasShadowHighlights=B(c,e.bind),c.renderOccluded=r,c.receiveAmbientOcclusion=!r&&n.ssao!=null,c.receiveGlobalIllumination=!r&&n.globalIlluminationEnabled,this._acquireTechnique(e.output)}case 5:case 7:return this._castShadows?this._acquireTechnique(5):null;case 8:return this._inViewshed?this._acquireTechnique(8):null;case 9:return this._cutFillEnabled?this._acquireTechnique(9):null;case 3:case 4:case 11:return this._acquireTechnique(e.output);case 10:return c.hasHighlightMixTexture=e.bind.highlightMixTexture!=null,this._overlayRenderer.hasHighlights?this._acquireTechnique(10):null}return null}render(e,t){switch(this._updatePatchGroups(),this._passParameters.useStencil=!1,this._passParameters.overlayContent=k(e.output,e.bind),e.output){case 0:case 1:case 2:return this._renderMaterialPass(e,t);case 3:case 4:case 11:return this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);case 10:{let n=e.bind.highlight?.name;n&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(2)&&this._overlayRenderer.hasHighlight(n)&&this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);break}case 5:case 7:case 8:case 9:return this._renderAuxiliaryPass(e,t,this._allPatchesByOrigin)}}updateTileBackground(e){if(this._tileRenderer==null)return;let t=this._tileRenderer,n;if(e!=null){let t=e.toUnitRGBA();n=f(t[0]||0,t[1]||0,t[2]||0)}t.setBackground(n),this._allTiles.forAll(e=>{t.updateTileTexture(e,0)||e.updateRenderData(1,0)}),this._configuration.tileBlendInput=t.backgroundIsGrid?2:t.backgroundColor==null?0:1,this.requestRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty){let e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(let n of e)D(n,t);e.sort((e,t)=>O(e[0],t[0])),this._visiblePatchesByOrigin=new Map(e.map(e=>[e[0].renderData.localOrigin,e])),this.notifyChange(`visibleTiles`),this._patchSortingDirty=!1}}_rebuildPatchGroups(){let e=this._rootTiles;if(e!=null){e[0]?.surface.checkAllTilesWaterproofness(`render-patch-groups`),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(let t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){let t=this._tileIterator;for(t.resetOne(e);!t.done;){let e=t.next(),n=e.renderData;if(!n){this._numTilesCulled++;continue}let r=n.localOrigin;if(this._castShadows||this._inViewshed||this._cutFillEnabled){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let i=this._visiblePatchesByOrigin.get(r);i||(i=[],this._visiblePatchesByOrigin.set(r,i)),i.push(e),t.skipSubtree()}}_renderAuxiliaryPass(e,t,n){let{rctx:r,bind:i}=e;r.bindTechnique(t,i,this._passParameters);let a=!!this._stencilEnabledLayerExtents?.length;n.forEach(n=>{this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(i,this._passParameters,this._drawParameters);for(let r=0;r<n.length;r++)this._renderPatch(e,t,n[r],W.TRIANGLES,a,this._passParameters.overlayContent===null)}),r.bindVAO(null)}_renderMaterialPass(e,t){let{rctx:n,bind:r}=e,i=n.bindTechnique(t,r,this._passParameters);this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;let a=r.slot===9;a&&(i.bindTexture(`tex`,n.emptyTexture),i.setUniform3fv(`textureOpacities`,d),i.setUniform4fv(`texOffsetAndScale`,h));let o=this._tileRenderer?.backgroundColor==null?d:this._tileRenderer.backgroundColor;this._configuration.tileBlendInput===1&&i.setUniform3fv(`backgroundColor`,o);let s=!!this._stencilEnabledLayerExtents?.length,c=this.wireframe?W.LINES:W.TRIANGLES;this._configuration.textureFadingEnabled&&i.bindTexture(`texNext`,n.emptyTexture);for(let n of this._visiblePatchesByOrigin.values()){this._drawParameters.origin=n[0].renderData.localOrigin,t.program.bindDraw(r,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(let r of n){let n=r.renderData,o=n.textureReference;if(o!=null){if(!a){i.setUniform4fv(`texOffsetAndScale`,o.offsetAndScale),i.bindTexture(`tex`,o.texture.texture);let e=n.textureFadeFactor,t=e<1?n.nextTextureReference:null;this._configuration.textureFadingEnabled&&t&&e<1?(i.setUniform1f(`fadeFactor`,e),i.setUniform4fv(`nextTexOffsetAndScale`,t.offsetAndScale),i.setUniform3fv(`nextTexOpacities`,t.opacities),i.bindTexture(`texNext`,t.texture.texture)):i.setUniform1f(`fadeFactor`,1),n.textureIsFading&&this.requestRender(2),i.setUniform3fv(`textureOpacities`,o.opacities)}this._renderPatch(e,t,r,c,s),r.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}n.bindVAO(null)}_renderPatch(e,t,n,r,i,a=!1){let o=n.renderData,s=o.vao,c=s?.indexBuffer;if(!s||c==null){S&&console.error(`Rendered tile with no indices: `,n.lij,` : `,o);return}let l=t.program;!a&&!this._overlayRenderer.isEmpty&&this._bindOverlayPatchData(l,o.overlay);let{rctx:u,bind:d}=e;i&&(this._passParameters.useStencil=E(n,this._stencilEnabledLayerExtents),u.setPipelineState(t.getPipeline(d,this._passParameters)));let f=o.geometry.indexCount;u.bindVAO(s),l.assertCompatibleVertexAttributeLocations(s),u.drawElements(r,f,c.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv(`overlayTexOffset`,t.offsets),e.setUniform4fv(`overlayTexScale`,t.scales)}_acquireTechnique(e){return this._configuration.output=e,this._techniques.get(H,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([o({readOnly:!0})],K.prototype,`visibleTiles`,null),e([o({readOnly:!0})],K.prototype,`_isGlobal`,null),e([o()],K.prototype,`renderOccludedFlags`,null),e([o({value:!1})],K.prototype,`renderingDisabled`,null),e([o({value:!0})],K.prototype,`visible`,null),e([o()],K.prototype,`renderPatchBorders`,null),e([o()],K.prototype,`wireframe`,null),K=e([s(`esri.views.3d.terrain.TerrainRenderer`)],K);const q=p(),J=p(),Y=p(),X=p();export{K as TerrainRenderer};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import has from"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as ne,isAborted as p}from"../../../core/promiseUtils.js";import{watch as m,syncAndInitial as h,initial as g,sync as _}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as re}from"../../../core/units.js";import{property as v,subclass as ie}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ae,set as oe,copy as se}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as ce}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b,radiusModifier as le}from"../../../geometry/ellipsoidUtils.js";import{projectWithoutEngine as ue}from"../../../geometry/projectionUtils.js";import x from"../../../geometry/SpatialReference.js";import{projectBoundingSphere as de}from"../../../geometry/projection/projectBoundingSphere.js";import{getProjector as fe}from"../../../geometry/projection/projectors.js";import{projectPointToVector as pe}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as me}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,fromExtent as he,equals as C,intersection as ge,intersectsSphere as _e}from"../../../geometry/support/aaBoundingRect.js";import{copy as ve,create as ye}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as be}from"../../../geometry/support/normalizeUtils.js";import{isGeographic as w,isPlateCarree as xe}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as Se}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as Ce}from"../../../layers/support/ElevationQueryTileCache.js";import{isIntegratedMeshLayer as we,isBaseLayer as Te}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Ee}from"../../../request/queue.js";import{debugFlags as T}from"../support/debugFlags.js";import{ElevationRange as E}from"../support/ElevationRange.js";import{ElevationUpdateEvent as De}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Oe}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as ke}from"../support/extentUtils.js";import{geographicMbsToGeographicExtent as Ae,mbsToGeographicExtent as je,intersectsGeographicExtent as Me}from"../support/sphereExtentUtils.js";import{isSupportedGCSOnGlobe as D}from"../support/supportedSpatialReference.js";import{updatingProgress as Ne}from"../support/updatingProperties.js";import{ElevationBounds as O}from"./ElevationBounds.js";import{ElevationData as Pe,sampleElevation as Fe}from"./ElevationData.js";import{create as Ie}from"./ExtentHelper.js";import{LayerClasses as Le}from"./LayerClass.js";import{OverlayManager as Re}from"./OverlayManager.js";import{PlanarPatch as ze}from"./PlanarPatch.js";import{Queue as Be}from"./Queue.js";import{ScaleRangeQueries as Ve}from"./ScaleRangeQueries.js";import{SphericalPatch as He}from"./SphericalPatch.js";import{SplitLimits as Ue}from"./SplitLimits.js";import{maxRootTiles as k,tooManyRootTilesAfterChangeError as We,tooManyRootTilesForLayerError as Ge,maxTileNeighborLevelDelta as A,maxMemoryLodBias as Ke}from"./TerrainConst.js";import{TerrainRenderer as qe}from"./TerrainRenderer.js";import Je from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as j,isVectorTileLayerView as M,internalAssert as N,oppositeEdge as Ye,neighborEdgeIndices as P,isSurfaceLayerView as F,isGroupLayerView as I,isMapTileLayerView as L,isBlendableLayerView as R,isElevationLayerView as z,releaseTerrainData as B,oppositeCorner as Xe,enableTerrainInternalChecks as V,enableWaterproofTests as Ze,enableInternalTerrainChecks as Qe,enableTerrainWaterproofChecks as $e,neighborCornerIndices as et}from"./terrainUtils.js";import{Tile as tt,lijEquals as H}from"./Tile.js";import{printAllocations as nt}from"./TilePerLayerInfo.js";import{sortTiles as rt,IteratorPreorder as it,IteratorPostorder as at,compareTilesByLij as U,hasLoadableSiblings as ot,sortTilesByPOI as st,traverseTilesPreorder as W}from"./tileUtils.js";import{TilingSchemeLogic as ct}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as lt}from"./TransparencyMode.js";import{UpsampleInfo as ut}from"./UpsampleInfo.js";import{isCompositeBlendMode as dt,blendModeFromString as ft}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as pt}from"../../support/layerViewUtils.js";import{ImmediateTask as G,TaskPriority as mt,noBudget as ht}from"../../support/Scheduler.js";import{TextureCompressionTracker as gt}from"../../support/TextureCompressionTracker.js";import{Yield as _t}from"../../support/Yield.js";var K;let q=class extends o{static{K=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return rt(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=re(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new gt,this._iteratorPool=new d(()=>new it,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new at,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new Je,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=y(),this._eyePosSurfaceSR=y(),this._splitLimits=new Ue,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new ce,this._poiWatchHandle=null,this._frameTask=G,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new ut),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=S(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=x.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new E(1/0,-1/0),this._rootTileElevationRange=new E(1/0,-1/0),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new Re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?He:ze,this._ellipsoid=b(t.spatialReference),this._renderer=new qe(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),pt()||(this._scaleRangeQueries=new Ve)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new Ce(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([m(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),m(()=>this.renderer.visible,e=>this.freeze=!e),m(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},h)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},g),this.addHandles([m(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},h),m(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),h),m(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},_),m(()=>this.snapLevel,()=>this._viewChanged=!0,_),m(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ae}))}),m(()=>T.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&T.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},g)]);let{spatialReference:a}=e;this._extentHelper=Ie(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new ct({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(mt.TERRAIN_SURFACE,this),this.addHandles([m(()=>this._stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),g),m(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),_),m(()=>this.groundExtent,()=>this._updateRootTiles(),g),e.on(`resize`,()=>this._viewChangeUpdate()),m(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),h),m(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,g),m(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,g),m(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>{this._allTiles.forAll(e=>this.updateElevationSources(e)),this._updateAllTileGeometries()}),m(()=>this.userClippingExtent,()=>this._updateClippingExtent(),_)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=G,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),tt.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),nt(),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._stencilEnabledExtents?.length}get _stencilEnabledExtents(){let e=this.spatialReference,t=!!has(`enable-feature:im-as-ground`);return e==null?null:Iterator.from(this.view.allLayerViews).map(n=>{let{layer:r}=n;if(!we(r)||t&&!r.isUsedAsGroundLayer)return null;let{fullExtent:i}=r,a=i==null||i.spatialReference.equals(e)?i:ue(i,i.spatialReference,e);return a?he(a):null}).filter(e=>e!=null).toArray()}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=S(),r=ke(t,n,e)?n:null,i=this._get(`userClippingExtent`);return C(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=ge(this.fullGroundExtent,this.userClippingExtent,S()),t=this._get(`groundExtent`);return C(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||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.freeze}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||this._rootTiles!=null}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 this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return be(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=fe(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=oe(J,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return St(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=St(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!pe(e,J,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(J)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;J[0]>e[2]&&(n+=1),J[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}getSphereElevationRange(e,t){if(!this.enabled)return null;let n=this._rootTiles,r=this._tilingSchemeSpatialReference;if(n==null||r==null||n.length===0)return null;let i=w(r);if(i){let n=w(t)&&D(t),i=b(t);if(n&&D(r)&&i===b(r))Ae(e,Y,i.radius);else if(!je(e,t,Y,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null}else if(!de(e,t,yt,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null;let a=new E,o=[];for(let e of n)o.push(e);let c=0;for(;c<o.length;){let e=o[c];if(++c,!(i?Me(e.extent,Y,r):_e(e.extent,yt)))continue;let t=e.children;if(t[0]==null||e.rendered)a.expandElevationRangeValues(e.elevationBoundsMin,e.elevationBoundsMax);else for(let e of t)o.push(e)}return a}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new E(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*le;return Math.min(e,this._ellipsoid.radius)}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?lt(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;j(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??x.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&xe(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set(`tilingScheme`,e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey=`TerrainTileMemcache`}_acquireTile(e,t,n,r){let i=this._tileCache.pop(K._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=bt,i=t.rootTilesInExtent(e,n,k*5);if(this._rootTiles!=null){if(i.length>k){s.getLogger(this).warn(We);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,H);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>H(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>k&&(s.getLogger(this).warn(Ge),i=t.rootTilesInExtent(e,n,k)),this._setRootTiles(i.map(e=>this._newRootTile(e)));C(n,this._rootTilesExtent)||(this._rootTilesExtent=S(n)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(U),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),e!=null){let 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.freeze&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(e==null)return;let t=ot(e),n=this.visibleElevationRange,r=t?n.minElevation:1/0,i=t?n.maxElevation:-1/0,a=this.groundExtent,o=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let s=this._iteratorPool.acquire();for(s.reset(e);!s.done;){let e=s.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(o),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),i=Math.max(e.elevationBoundsMax,i))}s.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(i)&&(n.minElevation!==r||n.maxElevation!==i)&&(this.visibleElevationRange=new O(r,i))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new O(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/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=ve(this._splitLimits.frustum??ye(),t.frustum):this._splitLimits.frustum=null,se(this._eyePosRenderSR,t.eye),me(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility(),this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){let t;e.forEachLoadedNeighbor(e=>{t??=this._layerViews[1].some(M),t&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.resetPendingUpdate(32)?32:e.resetPendingUpdate(16)?16:!1;n&&(this._renderer.updateTileTexture(e,n),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Oe(t,this.spatialReference)){let t=new De(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}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);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let n=this._pendingTilesToUpdate.size>0,r=n&&this._hasPendingGeometryWithoutIndices();if((!e.done||r)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||n&&!r)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!e.hasProgressed)return _t}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new Be(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=e.elevationLevel,l=s?4:e.shouldSplit(i,a,r),u=l===1;e.leaf?Z(e,u):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):(u?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),l===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0)),e.elevationLevel!==c&&this.updateElevationSources(e))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(st(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){N(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(U);let r=t.length;for(let i=0;i<r;++i){let r=t[i];N(r.loaded),N(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=et[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(Xe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Ye(P[t]),t=>this._canUpdateTileGeometry(t)?(N(e.has(t)||U(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),t.sort(U),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,V&&Ze&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=A){let e=e=>e.leaf||n-e.level<A;for(let r=0;r<4;++r){let a=i.findNeighborTile(P[r],e);a!=null&&n-a.level===A&&(t=!1,V&&(N(a.leaf),N(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}updateElevationSources(e){e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate())}_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)*Ke}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(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){let 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?wt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(K._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){j(e.leaf,`Tile that is already split should not be split again!`),j(e.rendered,`Tile marked to split is not rendered`),wt(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),j(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=>Z(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){X.spatialReference=this.spatialReference,X.extent=e.extent,X.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,X)}createTile(e,t,n,r){j(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){j(!e.hasPendingUpdate(1),`_mergeTile sanity check`),j(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),j(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Z(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=ht){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),F(i)||I(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!I(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.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(let e of this.view.allLayerViews.items)if(L(e)&&!Te(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((R(e)||I(e))&&dt(ft[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!z(e)}_registerTiledLayerView(e){let t=[];if((R(e)||I(e))&&t.push(m(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!I(e)){let n=this._layerClassFromLayerView(e);t.push(m(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(m(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(m(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!F(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of Le){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(W(this._rootTiles,n=>n.removeLayerAgent(e,t)),W(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||M(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),ne(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?z(n)?this._requestElevationTileData(e,n,r):Promise.reject():L(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!p(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{ne(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Ee,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Pe(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{B(i),p(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),p(n)?B(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(B(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let 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++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(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,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(e=`render-patch-groups`){}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&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Qe(e)}enableWaterproofnessChecks(e){$e(e)}static cleanupTerrainSurface(){xt.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([v()],q.prototype,`_renderer`,void 0),e([v({constructOnly:!0})],q.prototype,`_scaleRangeQueries`,void 0),e([v({constructOnly:!0})],q.prototype,`view`,void 0),e([v({constructOnly:!0})],q.prototype,`overlayManager`,void 0),e([v()],q.prototype,`_hasPendingUpdates`,void 0),e([v()],q.prototype,`_asyncWorkItems`,void 0),e([v()],q.prototype,`_allTilesDirty`,void 0),e([v()],q.prototype,`_allTilesSorted`,void 0),e([v()],q.prototype,`allTilesCreated`,null),e([v()],q.prototype,`_allTilesCreated`,void 0),e([v()],q.prototype,`_viewChanged`,void 0),e([v({type:Number})],q.prototype,`heading`,void 0),e([v()],q.prototype,`_splitLimits`,void 0),e([v()],q.prototype,`_frameTask`,void 0),e([v()],q.prototype,`demResolution`,null),e([v({readOnly:!0})],q.prototype,`snapLevel`,null),e([v({readOnly:!0})],q.prototype,`lodSnappingEnabled`,null),e([v()],q.prototype,`_stencilEnabledExtents`,null),e([v({readOnly:!0})],q.prototype,`userClippingExtent`,null),e([v()],q.prototype,`_rootTilesExtent`,void 0),e([v({readOnly:!0})],q.prototype,`groundExtent`,null),e([v({readOnly:!0})],q.prototype,`fullGroundExtent`,null),e([v({readOnly:!0})],q.prototype,`_tilingSchemeExtent`,null),e([v({readOnly:!0})],q.prototype,`updating`,null),e([v({readOnly:!0})],q.prototype,`readyToRun`,null),e([v(Ne)],q.prototype,`updatingProgress`,void 0),e([v({readOnly:!0})],q.prototype,`updatingProgressValue`,null),e([v()],q.prototype,`_maxNumUpdating`,void 0),e([v()],q.prototype,`baseOpacity`,null),e([v()],q.prototype,`hasCompositeBlendMode`,void 0),e([v({readOnly:!0})],q.prototype,`viewingMode`,null),e([v()],q.prototype,`maxTextureScale`,void 0),e([v({readOnly:!0})],q.prototype,`ready`,null),e([v({readOnly:!0})],q.prototype,`rootTiles`,null),e([v()],q.prototype,`_rootTiles`,void 0),e([v({readOnly:!0})],q.prototype,`spatialReference`,null),e([v({type:t})],q.prototype,`backgroundColor`,null),e([v({value:!1})],q.prototype,`slicePlaneEnabled`,null),e([v({readOnly:!0})],q.prototype,`tilingScheme`,void 0),e([v({readOnly:!0})],q.prototype,`tilingSchemeLocked`,null),e([v({readOnly:!0})],q.prototype,`tilingSchemeLogic`,void 0),e([v()],q.prototype,`wireframe`,null),e([v()],q.prototype,`opaque`,null),e([v()],q.prototype,`invisible`,null),e([v({value:!1})],q.prototype,`freeze`,null),e([v()],q.prototype,`fadeDuration`,null),e([v()],q.prototype,`_xNormalizer`,null),e([v()],q.prototype,`visibleElevationRange`,void 0),e([v()],q.prototype,`_rootTileElevationRange`,void 0),e([v()],q.prototype,`_layerViewsDirty`,void 0),e([v()],q.prototype,`renderPatchBorders`,null),e([v()],q.prototype,`renderingDisabled`,null),e([v({readOnly:!0})],q.prototype,`enabled`,void 0),q=K=e([ie(`esri.views.3d.terrain.TerrainSurface`)],q);const vt=q,J=y(),yt=new Se,Y=S(),bt=S(),xt=new f,X={spatialReference:null,extent:null,scale:0};function St(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return Fe(t,n,i)}return null}function Z(e,t){!e.leaf||e.level<A||$(e,e=>{t&&Ct(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}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<A||$(e,e=>{Ct(e)})}function wt(e){e.level<A||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<A)return;let n=e.level-A,r=e.lij[1]>>A,i=e.lij[2]>>A,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(P[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{vt as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import has from"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as ne,isAborted as p}from"../../../core/promiseUtils.js";import{watch as m,syncAndInitial as h,initial as g,sync as _}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as re}from"../../../core/units.js";import{property as v,subclass as ie}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ae,set as oe,copy as se}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as ce}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b,radiusModifier as le}from"../../../geometry/ellipsoidUtils.js";import{projectWithoutEngine as ue}from"../../../geometry/projectionUtils.js";import x from"../../../geometry/SpatialReference.js";import{projectBoundingSphere as de}from"../../../geometry/projection/projectBoundingSphere.js";import{getProjector as fe}from"../../../geometry/projection/projectors.js";import{projectPointToVector as pe}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as me}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,fromExtent as he,equals as C,intersection as ge,intersectsSphere as _e}from"../../../geometry/support/aaBoundingRect.js";import{copy as ve,create as ye}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as be}from"../../../geometry/support/normalizeUtils.js";import{isGeographic as w,isPlateCarree as xe}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as Se}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as Ce}from"../../../layers/support/ElevationQueryTileCache.js";import{isIntegratedMeshLayer as we,isBaseLayer as Te}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Ee}from"../../../request/queue.js";import{debugFlags as T}from"../support/debugFlags.js";import{ElevationRange as E}from"../support/ElevationRange.js";import{ElevationUpdateEvent as De}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Oe}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as ke}from"../support/extentUtils.js";import{geographicMbsToGeographicExtent as Ae,mbsToGeographicExtent as je,intersectsGeographicExtent as Me}from"../support/sphereExtentUtils.js";import{isSupportedGCSOnGlobe as D}from"../support/supportedSpatialReference.js";import{updatingProgress as Ne}from"../support/updatingProperties.js";import{ElevationBounds as O}from"./ElevationBounds.js";import{ElevationData as Pe,sampleElevation as Fe}from"./ElevationData.js";import{create as Ie}from"./ExtentHelper.js";import{LayerClasses as Le}from"./LayerClass.js";import{OverlayManager as Re}from"./OverlayManager.js";import{PlanarPatch as ze}from"./PlanarPatch.js";import{Queue as Be}from"./Queue.js";import{ScaleRangeQueries as Ve}from"./ScaleRangeQueries.js";import{SphericalPatch as He}from"./SphericalPatch.js";import{SplitLimits as Ue}from"./SplitLimits.js";import{maxRootTiles as k,tooManyRootTilesAfterChangeError as We,tooManyRootTilesForLayerError as Ge,maxTileNeighborLevelDelta as A,maxMemoryLodBias as Ke}from"./TerrainConst.js";import{TerrainRenderer as qe}from"./TerrainRenderer.js";import Je from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as j,isVectorTileLayerView as M,internalAssert as N,oppositeEdge as Ye,neighborEdgeIndices as P,isSurfaceLayerView as F,isGroupLayerView as I,isMapTileLayerView as L,isBlendableLayerView as R,isElevationLayerView as z,releaseTerrainData as B,oppositeCorner as Xe,enableTerrainInternalChecks as V,enableWaterproofTests as Ze,enableInternalTerrainChecks as Qe,enableTerrainWaterproofChecks as $e,neighborCornerIndices as et}from"./terrainUtils.js";import{Tile as tt,lijEquals as H}from"./Tile.js";import{printAllocations as nt}from"./TilePerLayerInfo.js";import{sortTiles as rt,IteratorPreorder as it,IteratorPostorder as at,compareTilesByLij as U,hasLoadableSiblings as ot,sortTilesByPOI as st,traverseTilesPreorder as W}from"./tileUtils.js";import{TilingSchemeLogic as ct}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as lt}from"./TransparencyMode.js";import{UpsampleInfo as ut}from"./UpsampleInfo.js";import{isCompositeBlendMode as dt,blendModeFromString as ft}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as pt}from"../../support/layerViewUtils.js";import{ImmediateTask as G,TaskPriority as mt,noBudget as ht}from"../../support/Scheduler.js";import{TextureCompressionTracker as gt}from"../../support/TextureCompressionTracker.js";import{Yield as _t}from"../../support/Yield.js";var K;let q=class extends o{static{K=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return rt(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=re(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new gt,this._iteratorPool=new d(()=>new it,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new at,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new Je,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=y(),this._eyePosSurfaceSR=y(),this._splitLimits=new Ue,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new ce,this._poiWatchHandle=null,this._frameTask=G,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new ut),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=S(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=x.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new E(1/0,-1/0),this._rootTileElevationRange=new E(1/0,-1/0),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new Re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?He:ze,this._ellipsoid=b(t.spatialReference),this._renderer=new qe(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),pt()||(this._scaleRangeQueries=new Ve)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new Ce(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([m(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),m(()=>this.renderer.visible,e=>this.freeze=!e),m(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},h)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},g),this.addHandles([m(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},h),m(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),h),m(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},_),m(()=>this.snapLevel,()=>this._viewChanged=!0,_),m(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ae}))}),m(()=>T.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&T.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},g)]);let{spatialReference:a}=e;this._extentHelper=Ie(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new ct({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(mt.TERRAIN_SURFACE,this),this.addHandles([m(()=>this._stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),g),m(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),_),m(()=>this.groundExtent,()=>this._updateRootTiles(),g),e.on(`resize`,()=>this._viewChangeUpdate()),m(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),h),m(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,g),m(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,g),m(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>{this._allTiles.forAll(e=>this.updateElevationSources(e)),this._updateAllTileGeometries()}),m(()=>this.userClippingExtent,()=>this._updateClippingExtent(),_)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=G,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),tt.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),nt(),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._stencilEnabledExtents?.length}get _stencilEnabledExtents(){let e=this.spatialReference,t=!!has(`enable-feature:im-as-ground`);return e==null?null:Iterator.from(this.view.allLayerViews).map(n=>{let{layer:r}=n;if(!we(r)||t&&!r.isUsedAsGroundLayer)return null;let{fullExtent:i}=r,a=i==null||i.spatialReference.equals(e)?i:ue(i,i.spatialReference,e);return a?he(a):null}).filter(e=>e!=null).toArray()}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=S(),r=ke(t,n,e)?n:null,i=this._get(`userClippingExtent`);return C(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=ge(this.fullGroundExtent,this.userClippingExtent,S()),t=this._get(`groundExtent`);return C(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||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.freeze}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||this._rootTiles!=null}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 this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return be(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=fe(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=oe(J,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return St(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=St(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!pe(e,J,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(J)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;J[0]>e[2]&&(n+=1),J[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}getSphereElevationRange(e,t){if(!this.enabled)return null;let n=this._rootTiles,r=this._tilingSchemeSpatialReference;if(n==null||r==null||n.length===0)return null;let i=w(r);if(i){let n=w(t)&&D(t),i=b(t);if(n&&D(r)&&i===b(r))Ae(e,Y,i.radius);else if(!je(e,t,Y,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null}else if(!de(e,t,yt,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null;let a=new E,o=[];for(let e of n)o.push(e);let c=0;for(;c<o.length;){let e=o[c];if(++c,!(i?Me(e.extent,Y,r):_e(e.extent,yt)))continue;let t=e.children;if(t[0]==null||e.rendered)a.expandElevationRangeValues(e.elevationBoundsMin,e.elevationBoundsMax);else for(let e of t)o.push(e)}return a}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new E(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*le;return Math.min(e,this._ellipsoid.radius)}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?lt(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;j(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??x.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&xe(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set(`tilingScheme`,e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey=`TerrainTileMemcache`}_acquireTile(e,t,n,r){let i=this._tileCache.pop(K._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=bt,i=t.rootTilesInExtent(e,n,k*5);if(this._rootTiles!=null){if(i.length>k){s.getLogger(this).warn(We);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,H);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>H(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>k&&(s.getLogger(this).warn(Ge),i=t.rootTilesInExtent(e,n,k)),this._setRootTiles(i.map(e=>this._newRootTile(e)));C(n,this._rootTilesExtent)||(this._rootTilesExtent=S(n)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(U),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),e!=null){let 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.freeze&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(e==null)return;let t=ot(e),n=this.visibleElevationRange,r=t?n.minElevation:1/0,i=t?n.maxElevation:-1/0,a=this.groundExtent,o=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let s=this._iteratorPool.acquire();for(s.reset(e);!s.done;){let e=s.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(o),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),i=Math.max(e.elevationBoundsMax,i))}s.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(i)&&(n.minElevation!==r||n.maxElevation!==i)&&(this.visibleElevationRange=new O(r,i))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new O(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/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=ve(this._splitLimits.frustum??ye(),t.frustum):this._splitLimits.frustum=null,se(this._eyePosRenderSR,t.eye),me(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility(),this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){let t;e.forEachLoadedNeighbor(e=>{t??=this._layerViews[1].some(M),t&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.hasPendingUpdate(32)?32:e.hasPendingUpdate(16)?16:!1;if(n){let r=this._renderer.updateTileTexture(e,n);return this._usedMemory=null,r&&e.resetPendingUpdate(n),t.madeProgress(),r}return!0}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Oe(t,this.spatialReference)){let t=new De(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}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);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e);let n=this._updateTextures(e);t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let r=this._pendingTilesToUpdate.size>0,i=r&&this._hasPendingGeometryWithoutIndices();if((!e.done||i)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||r&&!i)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!n||!e.hasProgressed)return _t}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new Be(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=e.elevationLevel,l=s?4:e.shouldSplit(i,a,r),u=l===1;e.leaf?Z(e,u):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):(u?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),l===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0)),e.elevationLevel!==c&&this.updateElevationSources(e))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(st(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){N(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(U);let r=t.length;for(let i=0;i<r;++i){let r=t[i];N(r.loaded),N(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=et[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(Xe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Ye(P[t]),t=>this._canUpdateTileGeometry(t)?(N(e.has(t)||U(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),t.sort(U),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,V&&Ze&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=A){let e=e=>e.leaf||n-e.level<A;for(let r=0;r<4;++r){let a=i.findNeighborTile(P[r],e);a!=null&&n-a.level===A&&(t=!1,V&&(N(a.leaf),N(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}updateElevationSources(e){e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate())}_updateTextures(e){if(e.done)return!0;let t=!0;return this._allTiles.some(n=>(this._updateTileTexture(n,e)||(t=!1),e.done)),t}_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)*Ke}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(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){let 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?wt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(K._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){j(e.leaf,`Tile that is already split should not be split again!`),j(e.rendered,`Tile marked to split is not rendered`),wt(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),j(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=>Z(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){X.spatialReference=this.spatialReference,X.extent=e.extent,X.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,X)}createTile(e,t,n,r){j(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){j(!e.hasPendingUpdate(1),`_mergeTile sanity check`),j(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),j(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Z(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=ht){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),F(i)||I(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!I(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.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(let e of this.view.allLayerViews.items)if(L(e)&&!Te(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((R(e)||I(e))&&dt(ft[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!z(e)}_registerTiledLayerView(e){let t=[];if((R(e)||I(e))&&t.push(m(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!I(e)){let n=this._layerClassFromLayerView(e);t.push(m(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(m(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(m(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!F(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of Le){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(W(this._rootTiles,n=>n.removeLayerAgent(e,t)),W(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||M(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),ne(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?z(n)?this._requestElevationTileData(e,n,r):Promise.reject():L(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!p(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{ne(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Ee,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Pe(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{B(i),p(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),p(n)?B(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(B(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let 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++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(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,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(e=`render-patch-groups`){}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&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Qe(e)}enableWaterproofnessChecks(e){$e(e)}static cleanupTerrainSurface(){xt.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([v()],q.prototype,`_renderer`,void 0),e([v({constructOnly:!0})],q.prototype,`_scaleRangeQueries`,void 0),e([v({constructOnly:!0})],q.prototype,`view`,void 0),e([v({constructOnly:!0})],q.prototype,`overlayManager`,void 0),e([v()],q.prototype,`_hasPendingUpdates`,void 0),e([v()],q.prototype,`_asyncWorkItems`,void 0),e([v()],q.prototype,`_allTilesDirty`,void 0),e([v()],q.prototype,`_allTilesSorted`,void 0),e([v()],q.prototype,`allTilesCreated`,null),e([v()],q.prototype,`_allTilesCreated`,void 0),e([v()],q.prototype,`_viewChanged`,void 0),e([v({type:Number})],q.prototype,`heading`,void 0),e([v()],q.prototype,`_splitLimits`,void 0),e([v()],q.prototype,`_frameTask`,void 0),e([v()],q.prototype,`demResolution`,null),e([v({readOnly:!0})],q.prototype,`snapLevel`,null),e([v({readOnly:!0})],q.prototype,`lodSnappingEnabled`,null),e([v()],q.prototype,`_stencilEnabledExtents`,null),e([v({readOnly:!0})],q.prototype,`userClippingExtent`,null),e([v()],q.prototype,`_rootTilesExtent`,void 0),e([v({readOnly:!0})],q.prototype,`groundExtent`,null),e([v({readOnly:!0})],q.prototype,`fullGroundExtent`,null),e([v({readOnly:!0})],q.prototype,`_tilingSchemeExtent`,null),e([v({readOnly:!0})],q.prototype,`updating`,null),e([v({readOnly:!0})],q.prototype,`readyToRun`,null),e([v(Ne)],q.prototype,`updatingProgress`,void 0),e([v({readOnly:!0})],q.prototype,`updatingProgressValue`,null),e([v()],q.prototype,`_maxNumUpdating`,void 0),e([v()],q.prototype,`baseOpacity`,null),e([v()],q.prototype,`hasCompositeBlendMode`,void 0),e([v({readOnly:!0})],q.prototype,`viewingMode`,null),e([v()],q.prototype,`maxTextureScale`,void 0),e([v({readOnly:!0})],q.prototype,`ready`,null),e([v({readOnly:!0})],q.prototype,`rootTiles`,null),e([v()],q.prototype,`_rootTiles`,void 0),e([v({readOnly:!0})],q.prototype,`spatialReference`,null),e([v({type:t})],q.prototype,`backgroundColor`,null),e([v({value:!1})],q.prototype,`slicePlaneEnabled`,null),e([v({readOnly:!0})],q.prototype,`tilingScheme`,void 0),e([v({readOnly:!0})],q.prototype,`tilingSchemeLocked`,null),e([v({readOnly:!0})],q.prototype,`tilingSchemeLogic`,void 0),e([v()],q.prototype,`wireframe`,null),e([v()],q.prototype,`opaque`,null),e([v()],q.prototype,`invisible`,null),e([v({value:!1})],q.prototype,`freeze`,null),e([v()],q.prototype,`fadeDuration`,null),e([v()],q.prototype,`_xNormalizer`,null),e([v()],q.prototype,`visibleElevationRange`,void 0),e([v()],q.prototype,`_rootTileElevationRange`,void 0),e([v()],q.prototype,`_layerViewsDirty`,void 0),e([v()],q.prototype,`renderPatchBorders`,null),e([v()],q.prototype,`renderingDisabled`,null),e([v({readOnly:!0})],q.prototype,`enabled`,void 0),q=K=e([ie(`esri.views.3d.terrain.TerrainSurface`)],q);const vt=q,J=y(),yt=new Se,Y=S(),bt=S(),xt=new f,X={spatialReference:null,extent:null,scale:0};function St(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return Fe(t,n,i)}return null}function Z(e,t){!e.leaf||e.level<A||$(e,e=>{t&&Ct(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}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<A||$(e,e=>{Ct(e)})}function wt(e){e.level<A||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<A)return;let n=e.level-A,r=e.lij[1]>>A,i=e.lij[2]>>A,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(P[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{vt as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../../core/Logger.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{ZEROS as n}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{VectorTileRendererHelper3D as r}from"../../2d/engine/vectorTiles/VectorTileRendererHelper3D.js";import{updateUniformBufferObject as i}from"../../2d/engine/webgl/shaderGraph/uniformBufferUtils.js";import{tileInfoUniformBlockBinding as a,getTileInfoUniforms as o}from"../../2d/engine/webgl/shaderGraph/techniques/shaders/TileInfo.js";import{viewInfoUniformBlockBinding as s,getViewUniforms as c}from"../../2d/engine/webgl/shaderGraph/techniques/shaders/ViewInfo.js";import{BlendLayersTechnique as l}from"./BlendLayersTechnique.js";import{BlendLayersTechniqueConfiguration as u}from"./BlendLayersTechniqueConfiguration.js";import{RasterColorizerTechnique as d}from"./RasterColorizerTechnique.js";import{RasterColorizerTechniqueConfiguration as f}from"./RasterColorizerTechniqueConfiguration.js";import{MultiSizeFramebuffer as p}from"./support/MultiSizeFramebuffer.js";import{BindParameters as m}from"../webgl-engine/lib/BindParameters.js";import{createQuadVAO as h}from"../webgl-engine/lib/glUtil3D.js";import{PrimitiveType as g}from"../../webgl/enums.js";import _ from"../../webgl/Texture.js";import{UniformBufferObject as v}from"../../webgl/UniformBufferObject.js";const y=()=>e.getLogger(`esri.views.3d.terrain`);class b{constructor(e,t){this._rctx=e,this._techniques=t,this._fbos=[],this._vectorTileHelper=new r,this._tileInfoUniformBufferObject=null,this._viewInfoUniformBufferObject=null,this._blendConfiguration=new u,this._current=0,this._lastUsedIds=[],this._lastCreatedBufferId=0,this._onHoldIds=[],this._vao=h(this._rctx,1),this._bindParameters=new m(null)}dispose(){this._bindParameters.destroy(),this._fbos.forEach(t),this._fbos=null,this._vtFBO=t(this._vtFBO),this._vao=t(this._vao),this._vectorTileHelper=t(this._vectorTileHelper),this._tileInfoUniformBufferObject?.dispose(),this._tileInfoUniformBufferObject=null,this._viewInfoUniformBufferObject?.dispose(),this._viewInfoUniformBufferObject=null}updateHeading(e){this._vectorTileHelper?.updateHeading(e)}_acquireBlendTechnique(e,t,n,r=!1,i=0){this._blendConfiguration.output=t,this._blendConfiguration.blendMode=e,this._blendConfiguration.applyBaseOpacity=n,this._blendConfiguration.premultipliedAlphaSource=r,this._blendConfiguration.background=i,++this._techniques.precompiling;let a=this._techniques.get(l,this._blendConfiguration);return--this._techniques.precompiling,a}drawBackground(e,t){let n=this._acquireBlendTechnique(0,t?2:3,!1,!1,1),r=this._rctx.bindTechnique(n,this._bindParameters,e);this._render(r)}_render(e){this._rctx.bindVAO(this._vao),e.assertCompatibleVertexAttributeLocations(this._vao),this._rctx.drawArrays(g.TRIANGLE_STRIP,0,this._vao.vertexCount(`geometry`))}drawGroup(e,t,n,r,i=!0){t===1&&(e.fboTexture=this._fbos[this.getLastOnHoldId()].get(n).colorTexture??this._rctx.emptyTexture),e.texture=this.currentFBO(n).colorTexture,this.closeGroup(n);let a=e.baseOpacity<1,o=this._acquireBlendTechnique(r,t,a,i),s=this._rctx.bindTechnique(o,this._bindParameters,e);this._render(s)}drawImageData(e,t,n,r,i=!1){if(e.texture==null)return;let a=e.baseOpacity<1;e.fboTexture=(t===4||r===0&&!a&&!i?null:this.switch(n).colorTexture)??this._rctx.emptyTexture;let o=this._acquireBlendTechnique(r,t,a,i),s=this._rctx.bindTechnique(o,this._bindParameters,e);this._render(s)}drawRasterData(e,t,n,r,i){let a=i.sourceLayerInfo.data;if(!a.source)return;let o=i.tile.surface.layerViewByIndex(i.layerIndex,1);if(`ensureSymbolizerParameters`in o&&o.ensureSymbolizerParameters(a),!a.bind(this._rctx))return;let s=e.baseOpacity<1;e.fboTexture=(r===0&&!s?null:this.switch(n).colorTexture)??this._rctx.emptyTexture;let c=this._acquireRasterTechnique(a,t,r,s);if(!c)return;a.opacity=e.opacity;let l=a.getUniforms(this._rctx);l.scale=i.scale,l.offset=i.offset,l.backgroundColor=e.backgroundColor,l.fboTexture=e.fboTexture,l.baseOpacity=e.baseOpacity;let u=this._rctx.bindTechnique(c,this._bindParameters,l);this._render(u)}_acquireRasterTechnique(e,t,n,r){if(!this._rctx.capabilities.colorBufferFloat)return null;let i=e.symbolizerParameters,a=[`stretch`,`lut`,`hillshade`].indexOf(i.type);this._rasterConfiguration??=new f,this._rasterConfiguration.output=t,this._rasterConfiguration.blendMode=n,this._rasterConfiguration.applyBaseOpacity=r,this._rasterConfiguration.colorizerType=a,this._rasterConfiguration.applyColormap=!!i.colormap,this._rasterConfiguration.requireBilinearWithNN=e.isBilinearWithStretchColorRamp,this._rasterConfiguration.stretchType=+!e.hasStretchTypeNone(),++this._techniques.precompiling;let o=this._techniques.get(d,this._rasterConfiguration);return--this._techniques.precompiling,o}drawVectorData(e,t,r,i,a,o,s,c){let l=this._rctx,u=a.sourceLayerInfo.data,d=a.tile.surface.layerViewByIndex(a.layerIndex,1),{painter:f,schemaHelper:m,tilingScheme:h,contentZoom:g}=d,_=d.layer.styleRepository,v=Math.round(1/a.scale),b=e.baseOpacity<1,x=b||e.opacity<1||i!==0||t!==1,S=x,C=this._acquireBlendTechnique(i,t,b,S);l.setPipelineState(C.getPipeline(this._bindParameters,e));let w=null,T=null;x?(T=this.currentFBO(r),this._vtFBO??=new p(this._rctx),w=this._vtFBO.get(r),l.bindFramebuffer(w),this._clearCurrentFBO()):c&&l.clear(256);try{if(u||_.backgroundBucketIds.length>0){let e=this._vectorTileHelper.updateViewRenderParameters(l,a.sourceLod,u,f,m,h,v,a.offset,s,o,g);this._updateViewInfo(e),this._updateTileInfo(e)}this._vectorTileHelper.renderBackground(l,a.sourceLod,u,f,_,m,h),u&&this._vectorTileHelper.renderContent(l,u,a.vtlNeighborInfos,f,_)}catch(e){y().warnOnce(`A render call containing vector tiles did not resolve correctly.`,e)}return!w||(l.bindFramebuffer(T),e.texture=w.colorTexture,e.offset=n,e.scale=1,this.drawImageData(e,t,r,i,S),c)}_updateTileInfo(e){let t=this._tileInfoUniformBufferObject??=new v(this._rctx,a.descriptor);i(t,a,o(e)),this._rctx.bindUBO(a.bindingPoint,t)}_updateViewInfo(e){let t=this._viewInfoUniformBufferObject??=new v(this._rctx,s.descriptor);i(t,s,c(e)),this._rctx.bindUBO(s.bindingPoint,t)}copyFBOToTexture(e){let t=this._rctx,n=t.bindTexture(e.texture,_.TEXTURE_UNIT_FOR_UPDATES),r=e.descriptor;t.gl.copyTexImage2D(3553,0,r.pixelFormat,0,0,r.width,r.height,0),e.generateMipmap(),t.bindTexture(n,_.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,n){this._rctx.bindFramebuffer(e),n&&(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,n=!0){if(this._current=t,t>=this._fbos.length)for(let e=this._fbos.length;e<=t;e++)this._fbos.push(new p(this._rctx));this._initFBO(this._fbos[t].get(e),e,n)}_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){let t=this.currentFBO(e),n=this._current;return this._bindNextFreeBuffer(e),this._lastUsedIds.push(n),t}getLastOnHoldId(){return this._onHoldIds[this._onHoldIds.length-1]}closeGroup(e){let 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{b as TileCompositor};
2
+ import e from"../../../core/Logger.js";import{disposeMaybe as t}from"../../../core/maybe.js";import{ZEROS as n}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{VectorTileRendererHelper3D as r}from"../../2d/engine/vectorTiles/VectorTileRendererHelper3D.js";import{updateUniformBufferObject as i}from"../../2d/engine/webgl/shaderGraph/uniformBufferUtils.js";import{tileInfoUniformBlockBinding as a,getTileInfoUniforms as o}from"../../2d/engine/webgl/shaderGraph/techniques/shaders/TileInfo.js";import{viewInfoUniformBlockBinding as s,getViewUniforms as c}from"../../2d/engine/webgl/shaderGraph/techniques/shaders/ViewInfo.js";import{BlendLayersTechnique as l}from"./BlendLayersTechnique.js";import{BlendLayersTechniqueConfiguration as u}from"./BlendLayersTechniqueConfiguration.js";import{RasterColorizerTechnique as d}from"./RasterColorizerTechnique.js";import{RasterColorizerTechniqueConfiguration as f}from"./RasterColorizerTechniqueConfiguration.js";import{MultiSizeFramebuffer as p}from"./support/MultiSizeFramebuffer.js";import{BindParameters as m}from"../webgl-engine/lib/BindParameters.js";import{createQuadVAO as h}from"../webgl-engine/lib/glUtil3D.js";import{PrimitiveType as g}from"../../webgl/enums.js";import{makePipelineState as _,defaultColorWrite as v,premultipliedAlpha as y}from"../../webgl/renderState.js";import{Texture as b}from"../../webgl/Texture.js";import{UniformBufferObject as x}from"../../webgl/UniformBufferObject.js";const S=()=>e.getLogger(`esri.views.3d.terrain`);class C{constructor(e,t){this._rctx=e,this._techniques=t,this._fbos=[],this._vectorTileHelper=new r,this._tileInfoUniformBufferObject=null,this._viewInfoUniformBufferObject=null,this._blendConfiguration=new u,this._current=0,this._lastUsedIds=[],this._lastCreatedBufferId=0,this._onHoldIds=[],this._vao=h(this._rctx,1),this._bindParameters=new m(null)}dispose(){this._bindParameters.destroy(),this._fbos.forEach(t),this._fbos=null,this._vtFBO=t(this._vtFBO),this._vao=t(this._vao),this._vectorTileHelper=t(this._vectorTileHelper),this._tileInfoUniformBufferObject?.dispose(),this._tileInfoUniformBufferObject=null,this._viewInfoUniformBufferObject?.dispose(),this._viewInfoUniformBufferObject=null}updateHeading(e){this._vectorTileHelper?.updateHeading(e)}_acquireBlendTechnique(e,t,n,r=!1,i=0){return this._blendConfiguration.output=t,this._blendConfiguration.blendMode=e,this._blendConfiguration.applyBaseOpacity=n,this._blendConfiguration.premultipliedAlphaSource=r,this._blendConfiguration.background=i,this._techniques.getCompiled(l,this._blendConfiguration)}drawBackground(e,t){let n=this._acquireBlendTechnique(0,t?2:3,!1,!1,1);if(!n)return!1;let r=this._rctx.bindTechnique(n,this._bindParameters,e);return this._render(r),!0}_render(e){this._rctx.bindVAO(this._vao),e.assertCompatibleVertexAttributeLocations(this._vao),this._rctx.drawArrays(g.TRIANGLE_STRIP,0,this._vao.vertexCount(`geometry`))}drawGroup(e,t,n,r,i=!0){let a=e.baseOpacity<1,o=this._acquireBlendTechnique(r,t,a,i);if(!o)return!1;t===1&&(e.fboTexture=this._fbos[this.getLastOnHoldId()].get(n).colorTexture??this._rctx.emptyTexture),e.texture=this.currentFBO(n).colorTexture,this.closeGroup(n);let s=this._rctx.bindTechnique(o,this._bindParameters,e);return this._render(s),!0}drawImageData(e,t,n,r,i=!1){if(e.texture==null)return!0;let a=e.baseOpacity<1,o=this._acquireBlendTechnique(r,t,a,i);if(!o)return!1;e.fboTexture=(t===4||r===0&&!a&&!i?null:this.switch(n).colorTexture)??this._rctx.emptyTexture;let s=this._rctx.bindTechnique(o,this._bindParameters,e);return this._render(s),!0}drawRasterData(e,t,n,r,i){let a=i.sourceLayerInfo.data;if(!a.source)return!0;let o=i.tile.surface.layerViewByIndex(i.layerIndex,1);if(`ensureSymbolizerParameters`in o&&o.ensureSymbolizerParameters(a),!a.bind(this._rctx))return!0;let s=e.baseOpacity<1,c=this._acquireRasterTechnique(a,t,r,s);if(!c)return!0;if(!c.compiled)return!1;e.fboTexture=(r===0&&!s?null:this.switch(n).colorTexture)??this._rctx.emptyTexture,a.opacity=e.opacity;let l=a.getUniforms(this._rctx);l.scale=i.scale,l.offset=i.offset,l.backgroundColor=e.backgroundColor,l.fboTexture=e.fboTexture,l.baseOpacity=e.baseOpacity;let u=this._rctx.bindTechnique(c,this._bindParameters,l);return this._render(u),!0}_acquireRasterTechnique(e,t,n,r){if(!this._rctx.capabilities.colorBufferFloat)return null;let i=e.symbolizerParameters,a=[`stretch`,`lut`,`hillshade`].indexOf(i.type);this._rasterConfiguration??=new f,this._rasterConfiguration.output=t,this._rasterConfiguration.blendMode=n,this._rasterConfiguration.applyBaseOpacity=r,this._rasterConfiguration.colorizerType=a,this._rasterConfiguration.applyColormap=!!i.colormap,this._rasterConfiguration.requireBilinearWithNN=e.isBilinearWithStretchColorRamp,this._rasterConfiguration.stretchType=+!e.hasStretchTypeNone(),++this._techniques.precompiling;let o=this._techniques.get(d,this._rasterConfiguration);return--this._techniques.precompiling,o}drawVectorData(e,t,r,i,a,o,s,c){let l=this._rctx,u=a.sourceLayerInfo.data,d=a.tile.surface.layerViewByIndex(a.layerIndex,1),{painter:f,schemaHelper:m,tilingScheme:h,contentZoom:g}=d,_=d.layer.styleRepository,v=Math.round(1/a.scale),y=e.baseOpacity<1,b=y||e.opacity<1||i!==0||t!==1,x=b;if(b&&!this._acquireBlendTechnique(i,t,y,x))return 0;l.setPipelineState(w);let C=null,T=null;b?(T=this.currentFBO(r),this._vtFBO??=new p(this._rctx),C=this._vtFBO.get(r),l.bindFramebuffer(C),this._clearCurrentFBO()):c&&l.clear(256);try{if(u||_.backgroundBucketIds.length>0){let e=this._vectorTileHelper.updateViewRenderParameters(l,a.sourceLod,u,f,m,h,v,a.offset,s,o,g);this._updateViewInfo(e),this._updateTileInfo(e)}this._vectorTileHelper.renderBackground(l,a.sourceLod,u,f,_,m,h),u&&this._vectorTileHelper.renderContent(l,u,a.vtlNeighborInfos,f,_)}catch(e){S().warnOnce(`A render call containing vector tiles did not resolve correctly.`,e)}return C?(l.bindFramebuffer(T),e.texture=C.colorTexture,e.offset=n,e.scale=1,this.drawImageData(e,t,r,i,x)?c?2:1:0):2}_updateTileInfo(e){let t=this._tileInfoUniformBufferObject??=new x(this._rctx,a.descriptor);i(t,a,o(e)),this._rctx.bindUBO(a.bindingPoint,t)}_updateViewInfo(e){let t=this._viewInfoUniformBufferObject??=new x(this._rctx,s.descriptor);i(t,s,c(e)),this._rctx.bindUBO(s.bindingPoint,t)}copyFBOToTexture(e){let t=this._rctx,n=t.bindTexture(e.texture,b.TEXTURE_UNIT_FOR_UPDATES),r=e.descriptor;t.gl.copyTexImage2D(3553,0,r.pixelFormat,0,0,r.width,r.height,0),e.generateMipmap(),t.bindTexture(n,b.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,n){this._rctx.bindFramebuffer(e),n&&(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,n=!0){if(this._current=t,t>=this._fbos.length)for(let e=this._fbos.length;e<=t;e++)this._fbos.push(new p(this._rctx));this._initFBO(this._fbos[t].get(e),e,n)}_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){let t=this.currentFBO(e),n=this._current;return this._bindNextFreeBuffer(e),this._lastUsedIds.push(n),t}getLastOnHoldId(){return this._onHoldIds[this._onHoldIds.length-1]}closeGroup(e){let 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)}}const w=_({blending:y,colorWrite:v});export{C as TileCompositor};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import"../../../core/has.js";import{disposeMaybe as e,releaseMaybe as t}from"../../../core/maybe.js";import{set as n,copy as r}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{ZEROS as i}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as a}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isBaseLayer as o,isGroupLayer as s,isReferenceLayer as c}from"../../../layers/support/layerUtils.js";import{isLayerViewWithFlowRenderer as l}from"../support/flowUtils.js";import{BlendLayersPassParameters as u}from"./BlendLayersTechnique.js";import{isBlendableLayerView as d,isVectorTileLayerView as f,isVectorTileRenderInfo as p,isImageryTileRenderInfo as m,isImageSourceRenderInfo as h,isTextureTileRenderInfo as g,isVectorTilePerLayerInfo as _}from"./terrainUtils.js";import{TextureReference as v}from"./TextureReference.js";import{TileCompositor as y}from"./TileCompositor.js";import{TileRenderInfo as b}from"./TileRenderInfo.js";import{getCacheKey as x,TileTexture as S}from"./TileTexture.js";import{fallsWithinLayerView as C}from"./tileUtils.js";import{blendModeFromString as w}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{isCompressible as T}from"../../support/TextureCompressionWorkerHandle.js";import E from"../../webgl/Texture.js";import{TextureDescriptor as D}from"../../webgl/TextureDescriptor.js";class O{constructor(e,t,n,r,i,a){this._surface=e,this._rctx=t,this.tileSize=n,this._techniques=r,this._cache=i,this._compressionTracker=a,this._passParameters=new u,this._backgroundColor=null,this._maxAnisotropy=this._rctx.parameters.maxMaxAnisotropy,this._compositor=new y(this._rctx,this._techniques)}dispose(){this._compositor=e(this._compositor),this._sharedBackground=t(this._sharedBackground)}get backgroundIsGrid(){return this._backgroundColor==null}get backgroundColor(){return this._backgroundColor}updateHeading(e){this._compositor?.updateHeading(e)}updateTileTexture(e,t){if(!e.renderData)return;let n=this._prepareComposite(e),r=n.targetTextureSize/this.tileSize;n.numTexturedLayers===0||n.firstTexturedLayerIndex===null?this._useBackgroundTexture(e,n,t!==0):(n.numTexturedLayers!==1||n.backgroundVTLIndex!=null||n.foundBlendMode||!this._useLayerTexture(e,n.firstTexturedLayerIndex??0))&&this._composeLayers(e,t,r,F,n)}_prepareComposite(e){let t=this._surface,n=t.baseOpacity,r=t.view.state.contentPixelRatio,i=e.layerInfo[1],a=new P(e.lij,this.tileSize);F.clear(),I.length=0;for(let u=0;u<i.length;u++){let p=t.layerViewByIndex(u,1),m=p.layer,h=!C(e,p),g=m.opacity,_=p.fullOpacity;if(a.hasBasemapLayers=a.hasBasemapLayers||o(m),l(p))continue;if(d(p)){let e=p.layer.blendMode!==`normal`;if(s(m.parent)){let t=m.parent.uid;t!=null&&t!==``&&(e=j(m.parent)||e)}e&&(a.foundBlendMode=e,a.backgroundCovered=!1)}if(this._canSkipLayer(g,h,a.foundBlendMode)){this._clearTexturePendingUpdates(i[u]);continue}++a.numVisibleLayers;let v=f(p);a.backgroundVTLIndex==null&&v&&p.layer.styleRepository.backgroundBucketIds.length>0&&(a.backgroundVTLIndex=u);let y=k(e,u,v);if(!(!y||(this._clearTexturePendingUpdates(i[u]),!y.sourceLayerInfo.data))){if(s(m.parent)){let e=m.parent.uid;e!=null&&e!==``&&M(m.parent,u)}if(v)a.targetTextureSize=Math.max(a.targetTextureSize,this.tileSize*r);else{let e=this._prepareTextureForBackgroundCoverageCheck(y,c(m));n===1&&_===1&&(p.isOpaque||e?.descriptor.isOpaque===!0)&&(a.backgroundCovered=!0)}++a.numTexturedLayers,a.firstTexturedLayerIndex??=u}}return a.lastLayerIndex=i.length-1,a}_canSkipLayer(e,t,n){return this._isLayerNonContributing(e,t)&&!n}_isLayerNonContributing(e,t){return e===0||t}_clearTexturePendingUpdates(e){e.pendingUpdates&=-1}_prepareTextureForBackgroundCoverageCheck(e,t){return this._dataToTexture(e,t)?e.sourceLayerInfo.data:null}setBackground(e){this._backgroundColor!==e&&(this._backgroundColor=e,this._sharedBackground&&this._drawBackgroundTexture(this._sharedBackground))}_drawBackgroundTexture(e,t,n){if(e.texture.setSamplingMode(9987),this._passParameters.offset=i,this._passParameters.scale=1,this._passParameters.opacity=1,this.backgroundColor&&(this._passParameters.backgroundColor=this.backgroundColor),this._compositor.bind(this.tileSize),n?.backgroundVTLIndex==null||t==null)this._compositor.drawBackground(this._passParameters,this.backgroundColor!=null);else{let e=k(t,n.backgroundVTLIndex,!0);this._passParameters.opacity=this._surface.layerViewByIndex(n.backgroundVTLIndex,1).layer.opacity,this._compositor.drawVectorData(this._passParameters,this.backgroundIsGrid?3:2,n.targetTextureSize,0,e,n.targetTextureSize/this.tileSize,this.tileSize,!1)}this._compositor.copyFBOToTexture(e),this._compositor.unbind()}_useBackgroundTexture(e,t,n){let r=e.renderData,i=!n&&!r.textureReference?.isBackground&&(this._surface.view.layerViewManager.updating||t.numVisibleLayers>0)?5e3:0;r.setTextureReference(new v(this._composeBackground(e,t),!0,0,R,this._surface.baseOpacity,0,1),i)}_composeBackground(e,t){if(t?.backgroundVTLIndex==null)return this._sharedBackground??(this._sharedBackground=this._buildTexture(this.tileSize,!1),this._drawBackgroundTexture(this._sharedBackground)),this._sharedBackground;let n=e.renderData.ensureTexture(this.tileSize,!1,0,()=>this._buildTexture(this.tileSize,!1,9987));return this._drawBackgroundTexture(n,e,t),n}_useLayerTexture(e,t){let n=this._surface.layerViewByIndex(t,1),r=o(n.layer),i=r?this._surface.baseOpacity:1,s=r?1:this._surface.baseOpacity,l=n.fullOpacity,u=k(e,t,!1);return this._dataToTexture(u,c(n.layer))?(e.renderData.setTextureReference(new v(u.sourceLayerInfo.data,!1,0,a(u.offset[0],u.offset[1],u.scale,u.scale),i,s,l)),!0):!1}_composeLayers(e,t,n,r,a){let{lastLayerIndex:s,hasBasemapLayers:u,targetTextureSize:h,backgroundCovered:g,foundBlendMode:_,backgroundVTLIndex:y}=a;this._compositor.ensureBuffer(h);let b=!g||_,x=this._surface.baseOpacity,S=!1,T=9987,E=!1,D=0;for(let t=s;t>=0;t--){let a=this._surface.layerViewByIndex(t,1);if(l(a))continue;let s=a.layer,g=f(a),v=k(e,t,g),O=s.opacity,j=!C(e,a),M=!v?.sourceLayerInfo.data&&t===y;if(!v?.sourceLayerInfo.data&&!M||this._canSkipLayer(O,j,_))continue;let N=!o(s)&&!S;S||=N;let P=this._openGroupsAtLayer(t,h,x,u,b,N,r),F=P?4:b&&D===0?this.backgroundIsGrid?3:2:1,L=w[d(a)?a.layer.blendMode:`normal`];for(this._passParameters.baseOpacity=N&&!P&&x<1?x:1,this._passParameters.opacity=O,M||p(v)?E=this._compositor.drawVectorData(this._passParameters,F,h,L,v,n,this.tileSize,E):m(v)?(this._compositor.drawRasterData(this._passParameters,F,h,L,v),A(v)&&(T=9728)):this._dataToTexture(v,c(s))&&(this._passParameters.texture=v.sourceLayerInfo.data.texture,this._passParameters.offset=v.offset,this._passParameters.scale=v.scale,this._compositor.drawImageData(this._passParameters,F,h,L));I.length>0&&I[I.length-1].end===t;){let e=I.pop();this._passParameters.baseOpacity=e.baseOpacity,this._passParameters.opacity=e.opacity,this._passParameters.offset=i,this._passParameters.scale=1,this._compositor.drawGroup(this._passParameters,e.output,h,w[e.blendMode])}D++}let O=e.renderData,j=_||S&&x<1,M=O.ensureTexture(h,j,t,()=>this._buildTexture(h,j,T));M.texture.setSamplingMode(T),this._compositor.copyFBOToTexture(M),this._compositor.unbind(),O.setTextureReference(new v(M,!1,t,R,S?1:x,0,1))}_openGroupsAtLayer(e,t,n,r,i,a,o){let s=!1;return o.forEach(o=>{o.start===e&&(o.output=r?1:i&&a?this.backgroundIsGrid?3:2:1,o.baseOpacity=a?n:1,I.push(o),this._compositor.openGroup(t),s=!0)}),s}_dataToTexture(e,t){if(h(e)){let n=e.sourceLayerInfo,r=!t;n.data=this._buildTexture(n.data,!0,r,e.scale!==1,e.tile.onCompressionFinished),e.tile.setMemoryDirty()}return g(e)}_buildTexture(e,t,n=9987,r=!1,i=()=>{}){return e==null?null:typeof e==`number`?this._buildTextureFromSize(e,t,n):this._buildTextureFromImage(e,t,n,r,i)}_buildTextureFromSize(e,t,n){let r=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);return r.width=r.height=e,this._buildTileTexture(r)}_buildTextureFromImage(e,t,n,r,i){let a=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);a.isOpaque=e.isOpaque,a.isOpaque&&(a.pixelFormat=6407);let{bitmap:o}=e;a.width=o.width,a.height=o.height;let s=typeof n==`boolean`&&n;return this._buildTileTexture(a,s,r,i,o)}_createTextureDescriptor(e,t){let n=new D;return n.wrapMode=33071,n.samplingMode=t,n.maxAnisotropy=this._maxAnisotropy,n.preMultiplyAlpha=!0,n.flipped=!0,n.hasMipmap=!0,e||(n.pixelFormat=6407),n}_buildTileTexture(e,t=!1,n=!1,r=()=>{},i){let a=this._cache.pop(x(e,!1))??this._cache.pop(x(e,!0));if(t&&=T(i,e),a)return a.retain(),a.texture.setSamplingMode(e.samplingMode),t?a.texture.enableCompression({compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}):a.texture.disableCompression(),a.texture.setData(i),a;e.compress=t?{compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}:void 0;let o=new E(this._rctx,e,i);return new S(o,this._cache)}get test(){}}function k(e,t,i){L.layerIndex=t,L.vtlNeighborInfos.clear();let a=e.layerInfo[1][t];if(n(L.offset,0,0),L.tile=e,L.scale=1,L.sourceLod=e.lij,L.sourceLayerInfo=a,a.data)return i&&e.forEachLoadedNeighbor((n,r)=>{if(n.level!==e.level)return;let i=n.layerInfo[1][t];if(!_(i)||a.data===i.data)return;let o=L.vtlNeighborInfos.pushNew();o.offset=z[r],o.sourceLod=n.lij,o.sourceLayerInfo=i}),L;let o=a.upsampleInfo,s=o?.tile?.layerInfo[1][t];return s&&o.tile?(L.tile=o.tile,r(L.offset,o.offset),L.scale=o.scale,L.sourceLod=o.tile.lij,L.sourceLayerInfo=s,L):i?L:null}function A(e){let t=e.sourceLayerInfo.data;return t.source?t.interpolation===`nearest`:!1}function j(e){let t=e.blendMode!==`normal`;return s(e.parent)&&(t=j(e.parent)||t),t}function M(e,t){s(e.parent)&&M(e.parent,t);let n=e.uid;if(n!=null&&n!==``){let r=F.get(n);r?r.start=t:F.set(n,new N(t,t,e.blendMode,e.opacity,1,1))}}class N{constructor(e,t,n,r,i,a){this.start=e,this.end=t,this.blendMode=n,this.opacity=r,this.output=i,this.baseOpacity=a}}class P{constructor(e,t){this.lij=e,this.targetTextureSize=t,this.numTexturedLayers=0,this.numVisibleLayers=0,this.backgroundCovered=!1,this.hasBasemapLayers=!1,this.foundBlendMode=!1,this.lastLayerIndex=0}}const F=new Map,I=[],L=new b,R=a(0,0,1,1),z=[];z[0]=[0,-1],z[1]=[-1,-1],z[2]=[-1,0],z[3]=[-1,1],z[4]=[0,1],z[5]=[1,1],z[6]=[1,0],z[7]=[1,-1];function B(){L.sourceLayerInfo=null,L.tile=null,L.vtlNeighborInfos.prune()}export{N as GroupInfo,O as TileRenderer,B as cleanupTileRenderer};
2
+ import"../../../core/has.js";import{disposeMaybe as e,releaseMaybe as t}from"../../../core/maybe.js";import{set as n,copy as r}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{ZEROS as i}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as a}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isBaseLayer as o,isGroupLayer as s,isReferenceLayer as c}from"../../../layers/support/layerUtils.js";import{isLayerViewWithFlowRenderer as l}from"../support/flowUtils.js";import{BlendLayersPassParameters as u}from"./BlendLayersTechnique.js";import{isBlendableLayerView as d,isVectorTileLayerView as f,isVectorTileRenderInfo as p,isImageryTileRenderInfo as m,isImageSourceRenderInfo as h,isTextureTileRenderInfo as g,isVectorTilePerLayerInfo as _}from"./terrainUtils.js";import{TextureReference as v}from"./TextureReference.js";import{TileCompositor as y}from"./TileCompositor.js";import{TileRenderInfo as b}from"./TileRenderInfo.js";import{getCacheKey as x,TileTexture as S}from"./TileTexture.js";import{fallsWithinLayerView as C}from"./tileUtils.js";import{blendModeFromString as w}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{isCompressible as T}from"../../support/TextureCompressionWorkerHandle.js";import{Texture as E}from"../../webgl/Texture.js";import{TextureDescriptor as D}from"../../webgl/TextureDescriptor.js";class O{constructor(e,t,n,r,i,a){this._surface=e,this._rctx=t,this.tileSize=n,this._techniques=r,this._cache=i,this._compressionTracker=a,this._passParameters=new u,this._backgroundColor=null,this._maxAnisotropy=this._rctx.parameters.maxMaxAnisotropy,this._compositor=new y(this._rctx,this._techniques)}dispose(){this._compositor=e(this._compositor),this._sharedBackground=t(this._sharedBackground)}get backgroundIsGrid(){return this._backgroundColor==null}get backgroundColor(){return this._backgroundColor}updateHeading(e){this._compositor?.updateHeading(e)}updateTileTexture(e,t){if(!e.renderData)return!0;let n=this._prepareComposite(e),r=n.targetTextureSize/this.tileSize;return n.numTexturedLayers===0||n.firstTexturedLayerIndex===null?this._useBackgroundTexture(e,n,t!==0):n.numTexturedLayers===1&&n.backgroundVTLIndex==null&&!n.foundBlendMode&&this._useLayerTexture(e,n.firstTexturedLayerIndex??0)?!0:this._composeLayers(e,t,r,F,n)}_prepareComposite(e){let t=this._surface,n=t.baseOpacity,r=t.view.state.contentPixelRatio,i=e.layerInfo[1],a=new P(e.lij,this.tileSize);F.clear(),I.length=0;for(let u=0;u<i.length;u++){let p=t.layerViewByIndex(u,1),m=p.layer,h=!C(e,p),g=m.opacity,_=p.fullOpacity;if(a.hasBasemapLayers=a.hasBasemapLayers||o(m),l(p))continue;if(d(p)){let e=p.layer.blendMode!==`normal`;if(s(m.parent)){let t=m.parent.uid;t!=null&&t!==``&&(e=j(m.parent)||e)}e&&(a.foundBlendMode=e,a.backgroundCovered=!1)}if(this._canSkipLayer(g,h,a.foundBlendMode)){this._clearTexturePendingUpdates(i[u]);continue}++a.numVisibleLayers;let v=f(p);a.backgroundVTLIndex==null&&v&&p.layer.styleRepository.backgroundBucketIds.length>0&&(a.backgroundVTLIndex=u);let y=k(e,u,v);if(!(!y||(this._clearTexturePendingUpdates(i[u]),!y.sourceLayerInfo.data))){if(s(m.parent)){let e=m.parent.uid;e!=null&&e!==``&&M(m.parent,u)}if(v)a.targetTextureSize=Math.max(a.targetTextureSize,this.tileSize*r);else{let e=this._prepareTextureForBackgroundCoverageCheck(y,c(m));n===1&&_===1&&(p.isOpaque||e?.descriptor.isOpaque===!0)&&(a.backgroundCovered=!0)}++a.numTexturedLayers,a.firstTexturedLayerIndex??=u}}return a.lastLayerIndex=i.length-1,a}_canSkipLayer(e,t,n){return this._isLayerNonContributing(e,t)&&!n}_isLayerNonContributing(e,t){return e===0||t}_clearTexturePendingUpdates(e){e.pendingUpdates&=-1}_prepareTextureForBackgroundCoverageCheck(e,t){return this._dataToTexture(e,t)?e.sourceLayerInfo.data:null}setBackground(e){this._backgroundColor!==e&&(this._backgroundColor=e,this._sharedBackground&&(this._drawBackground()?(this._sharedBackground.texture.setSamplingMode(9987),this._compositor.copyFBOToTexture(this._sharedBackground),this._compositor.unbind()):this._sharedBackground=t(this._sharedBackground)))}_drawBackground(e,t){if(this._passParameters.offset=i,this._passParameters.scale=1,this._passParameters.opacity=1,this.backgroundColor&&(this._passParameters.backgroundColor=this.backgroundColor),this._compositor.bind(this.tileSize),t?.backgroundVTLIndex==null||e==null){if(!this._compositor.drawBackground(this._passParameters,this.backgroundColor!=null))return this._compositor.unbind(),!1}else{let n=k(e,t.backgroundVTLIndex,!0);if(this._passParameters.opacity=this._surface.layerViewByIndex(t.backgroundVTLIndex,1).layer.opacity,this._compositor.drawVectorData(this._passParameters,this.backgroundIsGrid?3:2,t.targetTextureSize,0,n,t.targetTextureSize/this.tileSize,this.tileSize,!1)===0)return this._compositor.unbind(),!1}return!0}_useBackgroundTexture(e,t,n){let r=this._composeBackground(e,t);if(!r)return!1;let i=e.renderData,a=!n&&!i.textureReference?.isBackground&&(this._surface.view.layerViewManager.updating||t.numVisibleLayers>0)?5e3:0;return i.setTextureReference(new v(r,!0,0,R,this._surface.baseOpacity,0,1),a),!0}_composeBackground(e,t){if(t?.backgroundVTLIndex==null){if(this._sharedBackground==null){if(!this._drawBackground())return null;this._sharedBackground=this._buildTexture(this.tileSize,!1),this._sharedBackground.texture.setSamplingMode(9987),this._compositor.copyFBOToTexture(this._sharedBackground),this._compositor.unbind()}return this._sharedBackground}if(!this._drawBackground(e,t))return null;let n=e.renderData.ensureTexture(this.tileSize,!1,0,()=>this._buildTexture(this.tileSize,!1,9987));return n.texture.setSamplingMode(9987),this._compositor.copyFBOToTexture(n),this._compositor.unbind(),n}_useLayerTexture(e,t){let n=this._surface.layerViewByIndex(t,1),r=o(n.layer),i=r?this._surface.baseOpacity:1,s=r?1:this._surface.baseOpacity,l=n.fullOpacity,u=k(e,t,!1);return this._dataToTexture(u,c(n.layer))?(e.renderData.setTextureReference(new v(u.sourceLayerInfo.data,!1,0,a(u.offset[0],u.offset[1],u.scale,u.scale),i,s,l)),!0):!1}_composeLayers(e,t,n,r,a){let{lastLayerIndex:s,hasBasemapLayers:u,targetTextureSize:h,backgroundCovered:g,foundBlendMode:_,backgroundVTLIndex:y}=a;this._compositor.ensureBuffer(h);let b=!g||_,x=this._surface.baseOpacity,S=!1,T=9987,E=!1,D=0;for(let t=s;t>=0;t--){let a=this._surface.layerViewByIndex(t,1);if(l(a))continue;let s=a.layer,g=f(a),v=k(e,t,g),O=s.opacity,j=!C(e,a),M=!v?.sourceLayerInfo.data&&t===y;if(!v?.sourceLayerInfo.data&&!M||this._canSkipLayer(O,j,_))continue;let N=!o(s)&&!S;S||=N;let P=this._openGroupsAtLayer(t,h,x,u,b,N,r),F=P?4:b&&D===0?this.backgroundIsGrid?3:2:1,L=w[d(a)?a.layer.blendMode:`normal`];if(this._passParameters.baseOpacity=N&&!P&&x<1?x:1,this._passParameters.opacity=O,M||p(v)){let e=this._compositor.drawVectorData(this._passParameters,F,h,L,v,n,this.tileSize,E);if(e===0)return this._compositor.unbind(),!1;E=e===2}else if(m(v)){if(!this._compositor.drawRasterData(this._passParameters,F,h,L,v))return this._compositor.unbind(),!1;A(v)&&(T=9728)}else if(this._dataToTexture(v,c(s))&&(this._passParameters.texture=v.sourceLayerInfo.data.texture,this._passParameters.offset=v.offset,this._passParameters.scale=v.scale,!this._compositor.drawImageData(this._passParameters,F,h,L)))return this._compositor.unbind(),!1;for(;I.length>0&&I[I.length-1].end===t;){let e=I.pop();if(this._passParameters.baseOpacity=e.baseOpacity,this._passParameters.opacity=e.opacity,this._passParameters.offset=i,this._passParameters.scale=1,!this._compositor.drawGroup(this._passParameters,e.output,h,w[e.blendMode]))return this._compositor.unbind(),!1}D++}let O=e.renderData,j=_||S&&x<1,M=O.ensureTexture(h,j,t,()=>this._buildTexture(h,j,T));return M.texture.setSamplingMode(T),this._compositor.copyFBOToTexture(M),this._compositor.unbind(),O.setTextureReference(new v(M,!1,t,R,S?1:x,0,1)),!0}_openGroupsAtLayer(e,t,n,r,i,a,o){let s=!1;return o.forEach(o=>{o.start===e&&(o.output=r?1:i&&a?this.backgroundIsGrid?3:2:1,o.baseOpacity=a?n:1,I.push(o),this._compositor.openGroup(t),s=!0)}),s}_dataToTexture(e,t){if(h(e)){let n=e.sourceLayerInfo,r=!t;n.data=this._buildTexture(n.data,!0,r,e.scale!==1,e.tile.onCompressionFinished),e.tile.setMemoryDirty()}return g(e)}_buildTexture(e,t,n=9987,r=!1,i=()=>{}){return e==null?null:typeof e==`number`?this._buildTextureFromSize(e,t,n):this._buildTextureFromImage(e,t,n,r,i)}_buildTextureFromSize(e,t,n){let r=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);return r.width=r.height=e,this._buildTileTexture(r)}_buildTextureFromImage(e,t,n,r,i){let a=this._createTextureDescriptor(t,typeof n==`boolean`?9987:n);a.isOpaque=e.isOpaque,a.isOpaque&&(a.pixelFormat=6407);let{bitmap:o}=e;a.width=o.width,a.height=o.height;let s=typeof n==`boolean`&&n;return this._buildTileTexture(a,s,r,i,o)}_createTextureDescriptor(e,t){let n=new D;return n.wrapMode=33071,n.samplingMode=t,n.maxAnisotropy=this._maxAnisotropy,n.preMultiplyAlpha=!0,n.flipped=!0,n.hasMipmap=!0,e||(n.pixelFormat=6407),n}_buildTileTexture(e,t=!1,n=!1,r=()=>{},i){let a=this._cache.pop(x(e,!1))??this._cache.pop(x(e,!0));if(t&&=T(i,e),a)return a.retain(),a.texture.setSamplingMode(e.samplingMode),t?a.texture.enableCompression({compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}):a.texture.disableCompression(),a.texture.setData(i),a;e.compress=t?{compressionTracker:this._compressionTracker,compressionCallback:r,preserveSourceBitmap:n}:void 0;let o=new E(this._rctx,e,i);return new S(o,this._cache)}get test(){}}function k(e,t,i){L.layerIndex=t,L.vtlNeighborInfos.clear();let a=e.layerInfo[1][t];if(n(L.offset,0,0),L.tile=e,L.scale=1,L.sourceLod=e.lij,L.sourceLayerInfo=a,a.data)return i&&e.forEachLoadedNeighbor((n,r)=>{if(n.level!==e.level)return;let i=n.layerInfo[1][t];if(!_(i)||a.data===i.data)return;let o=L.vtlNeighborInfos.pushNew();o.offset=z[r],o.sourceLod=n.lij,o.sourceLayerInfo=i}),L;let o=a.upsampleInfo,s=o?.tile?.layerInfo[1][t];return s&&o.tile?(L.tile=o.tile,r(L.offset,o.offset),L.scale=o.scale,L.sourceLod=o.tile.lij,L.sourceLayerInfo=s,L):i?L:null}function A(e){let t=e.sourceLayerInfo.data;return t.source?t.interpolation===`nearest`:!1}function j(e){let t=e.blendMode!==`normal`;return s(e.parent)&&(t=j(e.parent)||t),t}function M(e,t){s(e.parent)&&M(e.parent,t);let n=e.uid;if(n!=null&&n!==``){let r=F.get(n);r?r.start=t:F.set(n,new N(t,t,e.blendMode,e.opacity,1,1))}}class N{constructor(e,t,n,r,i,a){this.start=e,this.end=t,this.blendMode=n,this.opacity=r,this.output=i,this.baseOpacity=a}}class P{constructor(e,t){this.lij=e,this.targetTextureSize=t,this.numTexturedLayers=0,this.numVisibleLayers=0,this.backgroundCovered=!1,this.hasBasemapLayers=!1,this.foundBlendMode=!1,this.lastLayerIndex=0}}const F=new Map,I=[],L=new b,R=a(0,0,1,1),z=[];z[0]=[0,-1],z[1]=[-1,-1],z[2]=[-1,0],z[3]=[-1,1],z[4]=[0,1],z[5]=[1,1],z[6]=[1,0],z[7]=[1,-1];function B(){L.sourceLayerInfo=null,L.tile=null,L.vtlNeighborInfos.prune()}export{N as GroupInfo,O as TileRenderer,B as cleanupTileRenderer};
@@ -202,7 +202,7 @@ export interface RenderNodeProperties extends Partial<Pick<RenderNode, "produces
202
202
  * @see [Sample - Custom Render Node - Windmills](https://developers.arcgis.com/javascript/latest/sample-code/custom-render-node-windmills/)
203
203
  */
204
204
  export default abstract class RenderNode extends Accessor {
205
- constructor(properties?: RenderNodeProperties);
205
+ constructor(properties: RenderNodeProperties);
206
206
  /** Get the render representation of the current camera of a view. */
207
207
  get camera(): RenderCamera;
208
208
  /**
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{destroyMaybe as e}from"../../../../../core/maybe.js";import{set as t}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as r}from"../../../../../geometry/support/aaBoundingBox.js";import{encodeSymbolColor as i}from"../../../layers/support/symbolColorUtils.js";import{computeOffsetObb as a}from"../../../support/orientedBoundingBox.js";import{ComponentParametersUniform as o,ComponentParametersVarying as s}from"./ComponentDrawParameters.js";import{UniformComponentParameters as c}from"./UniformComponentParameters.js";import{olidEnabled as l}from"../../effects/geometry/olidUtils.js";import{defaultHighlightName as u}from"../../../../support/HighlightDefaults.js";class d{constructor(e,t,n,r,i,a){this._collection=e,this.transform=t,this.obb=n,this._componentData=r,this._renderable=i,this._intersectionGeometry=a,this.visible=!1,this.offsetObb=null,this._aabbInWorldCoordinates=null}destroy(){this._collection.materials.release(this._renderable.material),this._intersectionGeometry=e(this._intersectionGeometry),this._renderable=e(this._renderable),this._componentData=e(this._componentData)}get componentData(){return this._componentData}get renderable(){return this._renderable}get intersectionGeometry(){return this._intersectionGeometry}get emissions(){return this.renderable.material.emissions}updateMaterial(e,t){let{_renderable:n}=this,r=n.material,{opacity:i,useFloatBlend:a,...o}=e,s=i??n.opacity,c=this._collection.materials.acquire({...r.parameters,...o,groundTransparencyMode:e.groundTransparencyMode??r.parameters.groundTransparencyMode,isObjectTransparent:s<1},n.geometry.parameters,t??n.drawParameters.componentParameters);this._collection.materials.release(r),c!==r&&n.updateMaterial(c)}get opacity(){return this.renderable.opacity}updateOpacity(e,t){if(this.opacity===e){if(t===void 0||t===this.renderable.material.parameters.groundTransparencyMode)return}else this._renderable.updateOpacity(e);this.updateMaterial({opacity:e,groundTransparencyMode:t})}updateCameraDerivedParameters(e){let{eye:t}=e,{centerX:n,centerY:r,centerZ:i}=this.obb;this._renderable.meta.cameraDepthSquared=(t[0]-n)**2+(t[1]-r)**2+(t[2]-i)**2}setComponentData(e,t){let n=this._componentData,{materialDataBuffer:r,materialDataIndices:u}=n,d=new c,p=r.textureBuffer,m=p.getVec4Field(`colorAndCastShadows`),h=p.getScalarField(`elevationOffset`),g=p.getScalarField(`emissiveStrength`),_=p.getScalarField(`emissiveSourceMode`),v=p.getVec4Field(`olidColor`),y=new Uint8Array(4),b=new Uint32Array(y.buffer),x=0,S=0,C=0,w=0,T=0,E=n.verticalOffsets,D=1/0,O=-1/0,k=!1,A=!1,j=!1,M=0;for(let t=0;t<n.count;t++){e(t,d),x+=+(d.externalColor[3]<1),S+=+(d.externalColorMixMode===3&&d.externalColor[3]===1),w+=+(d.emissiveStrength>0),T+=+(d.emissiveSource===1),A||=d.emissiveStrength!==1,C+=+d.castShadows,i(d.externalColor,d.externalColorMixMode,y),y[2]=y[2]&254|d.castShadows,m.setArray(u[t],y),k||=t>0&&M!==b[0],M=b[0],j||=d.elevationOffset!==0,j&&E==null&&(E=Array(t).fill(0)),E!=null&&(E[t]=d.elevationOffset),D=Math.min(D,d.elevationOffset),O=Math.max(O,d.elevationOffset),h.set(u[t],d.elevationOffset),g.set(u[t],d.emissiveStrength),_.set(u[t],d.emissiveSource===0?0:255);let r=d.olidColor;r!=null&&v.setArray(u[t],r),d.pickable!==n.isPickable(t)&&n.updatePickabilityWithCount(t,d.pickable)}n.verticalOffsets=j?E:null,this.offsetObb=j?a(this.obb,D,O,t,this.offsetObb??this.obb.clone()):null;let N;if(k||j||l()||(A||T>0)&&w>0){let{count:e}=n;N=new s(f(x,e),f(S,e),f(w,e),f(T,e),f(C,e)),p.updateTexture(),this._renderable.updateComponentParametersVarying(N,p)}else N=new o(d.externalColor,d.externalColorMixMode,d.emissiveStrength,d.emissiveSource,d.castShadows?0:2),this._renderable.updateComponentParametersUniform(N);this.updateMaterial({},N)}addHighlight(e,t){return this._componentData.addComponentHighlight(e,t)}removeHighlight(e,t){return this._componentData.removeComponentHighlight(e,t)}clearHighlights(){this._componentData.clearHighlights()}get aabbInWorldCoordinates(){let e=this._aabbInWorldCoordinates;return e||(e=this._computeAabbInWorldCoordinates(),this._aabbInWorldCoordinates=e),e}_computeAabbInWorldCoordinates(){let e=r(),{positions:n}=this._intersectionGeometry;if(Math.floor(n.length/3)>0){let{transform:r}=this,i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0,u=h;for(let e=0;e<n.length;e+=3)t(u,n[e+0],n[e+1],n[e+2]),r.applyVec3(u,u),i=Math.min(i,u[0]),a=Math.min(a,u[1]),o=Math.min(o,u[2]),s=Math.max(s,u[0]),c=Math.max(c,u[1]),l=Math.max(l,u[2]);e[0]=i,e[1]=a,e[2]=o,e[3]=s,e[4]=c,e[5]=l}return e}submit(e,t){let{componentData:n,renderable:r}=this;if(r.drawParameters.opacity<=0)return;let{geometry:i,drawParameters:a,material:o}=r,s=r.meta.cameraDepthSquared,{geometryRanges:c,highlightRangesMap:l,shadowmapRanges:d}=n,f=e=>e.submitDraw(o,a,i,c,s);switch(o.materialPass){case 0:f(e.opaque);break;case 1:f(e.transparent);break;case 2:f(e.opaque),f(e.transparent);break;case 3:f(e.integratedMesh),p(t)&&f(e.occludedGround),m(t)&&f(e.highlightIntegratedMesh);break;case 4:f(e.transparentIntegratedMesh)}if(a.castAnyShadows){if(l!=null)for(let t of l)t[0]===u&&e.highlightShadowMap.submitDraw(o,a,i,t[1],s,t[0]);d!=null&&e.defaultShadowMap.submitDraw(o,a,i,d,s),f(e.shadowMap)}if(l!=null)for(let t of l)e.highlight.submitDraw(o,a,i,t[1],s,t[0]);t.viewshedEnabled&&f(e.viewshedShadowMap)}}function f(e,t){return e===t?0:e===0?2:1}function p(e){return e.overlay?.getTexture(e.overlay?.allSourcesOccluders?1:4)!=null}function m(e){return e.overlay?.getTexture(2)!=null}const h=n();export{d as ComponentObject};
2
+ import{destroyMaybe as e}from"../../../../../core/maybe.js";import{set as t}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as r}from"../../../../../geometry/support/aaBoundingBox.js";import{encodeSymbolColor as i}from"../../../layers/support/symbolColorUtils.js";import{computeOffsetObb as a}from"../../../support/orientedBoundingBox.js";import{ComponentParametersUniform as o,ComponentParametersVarying as s}from"./ComponentDrawParameters.js";import{UniformComponentParameters as c}from"./UniformComponentParameters.js";import{olidEnabled as l}from"../../effects/geometry/olidUtils.js";import{defaultHighlightName as u}from"../../../../support/HighlightDefaults.js";class d{constructor(e,t,n,r,i,a){this._collection=e,this.transform=t,this.obb=n,this._componentData=r,this._renderable=i,this._intersectionGeometry=a,this.visible=!1,this.offsetObb=null,this._aabbInWorldCoordinates=null}destroy(){this._collection.materials.release(this._renderable.material),this._intersectionGeometry=e(this._intersectionGeometry),this._renderable=e(this._renderable),this._componentData=e(this._componentData)}get componentData(){return this._componentData}get renderable(){return this._renderable}get intersectionGeometry(){return this._intersectionGeometry}get emissions(){return this.renderable.material.emissions}updateMaterial(e,t){let{_renderable:n}=this,r=n.material,{opacity:i,useFloatBlend:a,...o}=e,s=i??n.opacity,c=this._collection.materials.acquire({...r.parameters,...o,groundTransparencyMode:e.groundTransparencyMode??r.parameters.groundTransparencyMode,isObjectTransparent:s<1},n.geometry.parameters,t??n.drawParameters.componentParameters);this._collection.materials.release(r),c!==r&&n.updateMaterial(c)}updatePolygonOffset(e){this._renderable.material.parameters.polygonOffset!==e&&this.updateMaterial({polygonOffset:e})}get opacity(){return this.renderable.opacity}updateOpacity(e,t){if(this.opacity===e){if(t===void 0||t===this.renderable.material.parameters.groundTransparencyMode)return}else this._renderable.updateOpacity(e);this.updateMaterial({opacity:e,groundTransparencyMode:t})}updateCameraDerivedParameters(e){let{eye:t}=e,{centerX:n,centerY:r,centerZ:i}=this.obb;this._renderable.meta.cameraDepthSquared=(t[0]-n)**2+(t[1]-r)**2+(t[2]-i)**2}setComponentData(e,t){let n=this._componentData,{materialDataBuffer:r,materialDataIndices:u}=n,d=new c,p=r.textureBuffer,m=p.getVec4Field(`colorAndCastShadows`),h=p.getScalarField(`elevationOffset`),g=p.getScalarField(`emissiveStrength`),_=p.getScalarField(`emissiveSourceMode`),v=p.getVec4Field(`olidColor`),y=new Uint8Array(4),b=new Uint32Array(y.buffer),x=0,S=0,C=0,w=0,T=0,E=n.verticalOffsets,D=1/0,O=-1/0,k=!1,A=!1,j=!1,M=0;for(let t=0;t<n.count;t++){e(t,d),x+=+(d.externalColor[3]<1),S+=+(d.externalColorMixMode===3&&d.externalColor[3]===1),w+=+(d.emissiveStrength>0),T+=+(d.emissiveSource===1),A||=d.emissiveStrength!==1,C+=+d.castShadows,i(d.externalColor,d.externalColorMixMode,y),y[2]=y[2]&254|d.castShadows,m.setArray(u[t],y),k||=t>0&&M!==b[0],M=b[0],j||=d.elevationOffset!==0,j&&E==null&&(E=Array(t).fill(0)),E!=null&&(E[t]=d.elevationOffset),D=Math.min(D,d.elevationOffset),O=Math.max(O,d.elevationOffset),h.set(u[t],d.elevationOffset),g.set(u[t],d.emissiveStrength),_.set(u[t],d.emissiveSource===0?0:255);let r=d.olidColor;r!=null&&v.setArray(u[t],r),d.pickable!==n.isPickable(t)&&n.updatePickabilityWithCount(t,d.pickable)}n.verticalOffsets=j?E:null,this.offsetObb=j?a(this.obb,D,O,t,this.offsetObb??this.obb.clone()):null;let N;if(k||j||l()||(A||T>0)&&w>0){let{count:e}=n;N=new s(f(x,e),f(S,e),f(w,e),f(T,e),f(C,e)),p.updateTexture(),this._renderable.updateComponentParametersVarying(N,p)}else N=new o(d.externalColor,d.externalColorMixMode,d.emissiveStrength,d.emissiveSource,d.castShadows?0:2),this._renderable.updateComponentParametersUniform(N);this.updateMaterial({},N)}addHighlight(e,t){return this._componentData.addComponentHighlight(e,t)}removeHighlight(e,t){return this._componentData.removeComponentHighlight(e,t)}clearHighlights(){this._componentData.clearHighlights()}get aabbInWorldCoordinates(){let e=this._aabbInWorldCoordinates;return e||(e=this._computeAabbInWorldCoordinates(),this._aabbInWorldCoordinates=e),e}_computeAabbInWorldCoordinates(){let e=r(),{positions:n}=this._intersectionGeometry;if(Math.floor(n.length/3)>0){let{transform:r}=this,i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0,u=h;for(let e=0;e<n.length;e+=3)t(u,n[e+0],n[e+1],n[e+2]),r.applyVec3(u,u),i=Math.min(i,u[0]),a=Math.min(a,u[1]),o=Math.min(o,u[2]),s=Math.max(s,u[0]),c=Math.max(c,u[1]),l=Math.max(l,u[2]);e[0]=i,e[1]=a,e[2]=o,e[3]=s,e[4]=c,e[5]=l}return e}submit(e,t){let{componentData:n,renderable:r}=this;if(r.drawParameters.opacity<=0)return;let{geometry:i,drawParameters:a,material:o}=r,s=r.meta.cameraDepthSquared,{geometryRanges:c,highlightRangesMap:l,shadowmapRanges:d}=n,f=e=>e.submitDraw(o,a,i,c,s);switch(o.materialPass){case 0:f(e.opaque);break;case 1:f(e.transparent);break;case 2:f(e.opaque),f(e.transparent);break;case 3:f(e.integratedMesh),p(t)&&f(e.occludedGround),m(t)&&f(e.highlightIntegratedMesh);break;case 4:f(e.transparentIntegratedMesh)}if(a.castAnyShadows){if(l!=null)for(let t of l)t[0]===u&&e.highlightShadowMap.submitDraw(o,a,i,t[1],s,t[0]);d!=null&&e.defaultShadowMap.submitDraw(o,a,i,d,s),f(e.shadowMap)}if(l!=null)for(let t of l)e.highlight.submitDraw(o,a,i,t[1],s,t[0]);t.viewshedEnabled&&f(e.viewshedShadowMap)}}function f(e,t){return e===t?0:e===0?2:1}function p(e){return e.overlay?.getTexture(e.overlay?.allSourcesOccluders?1:4)!=null}function m(e){return e.overlay?.getTexture(2)!=null}const h=n();export{d as ComponentObject};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../webgl/ManagedColorAttachment.js";import{ManagedDepthTexture as t}from"../../webgl/ManagedDepthTexture.js";import n from"../../webgl/ManagedFBO.js";import{isDepthFormat as r,formatString as i,DepthTextureFormats as a,ColorFormats as o}from"./FBOCacheFormats.js";import{FBOCacheUsage as s}from"./FBOCacheUsage.js";import{FBOPool as c}from"./FBOPool.js";import{DepthStencilAttachment as l,ColorAttachment0 as u}from"../../../webgl/enums.js";import{DisposableFramebufferObject as d}from"../../../webgl/FramebufferObject.js";import f from"../../../webgl/Texture.js";class p{constructor(e){this.rctx=e,this._interactive=!1,this._usage=new s,this._acquired=new Set,this._cache=new c(e.newCache,`FBOCache`),this._colorCache=new c(e.newCache,`ColorAttachmentCache`),this._depthCache=new c(e.newCache,`DepthAttachmentCache`)}destroy(){this._cache.destroy(),this._depthCache.destroy(),this._colorCache.destroy()}clean(){this._cache.clean(),this._colorCache.clean(),this._depthCache.clean()}frameStart(){this._cache.frame(),this._colorCache.frame(),this._depthCache.frame(),this.debugCallback?.(),this._usage.clear()}frameEnd(){this.debugCallback&&(this._usage.summarize(),this._acquired.forEach(e=>this.debugCallback?.(e.name,e.fbo)))}get usedMemory(){return this._acquired.values().reduce((e,t)=>e+t.usedMemory,this._cache.usedMemory+this._colorCache.usedMemory+this._depthCache.usedMemory)}set interactive(e){this._cache.interactive=this._colorCache.interactive=this._depthCache.interactive=e,this._interactive=e}get interactive(){return this._interactive}acquire(e,t,a,o=5){let s=g(o,e,t),c=this._cache.pop(s),{rctx:f}=this;if(c){c.retain(),c.setName(a);let e=c.getAttachment(l);e&&(e.name=h);let t=c.getAttachment(u);t&&(t.name=m(0)),f.unbindTexture(c.fbo.colorTexture)}else{let i=new d(f);c=new n(s,a,i,(n,r,i)=>{r??=5,i??=m(n-u);let a=this._acquireColor(r,e,t,i);return this.rctx.unbindTexture(a.attachment),c.attachColor(a,n),a.release(),c},n=>{n??=14;let r=this.acquireDepth(n,e,t,`${c.name} ${h}`);return c.attachDepth(r),r.release(),c},()=>{if(!c)return;this.debugCallback?.(c.name,c.fbo),this._acquired.delete(c);let e=r(o);e&&c.getAttachment(l)!=null||!e&&c.getAttachment(u)!=null?(e?(c.fbo?.invalidateAttachments([l]),c.detachAllColors()):(c.fbo?.invalidateAttachments([u]),c.detachAllButColor0()),this._trackRelease(c),this._cache.put(c)):c.dispose()}),r(o)?c.acquireDepth(o):c.acquireColor(u,o)}return this._trackAcquire(c,`f `+i(o),e,t),this._trackHandle(c)}acquireDepth(e,n,r,o){let s=g(e,n,r),c=this._depthCache.pop(s);if(c)c.retain(),c.attachment.setShadowFiltering(!1);else{let i=new f(this.rctx,{...a[e],width:n,height:r});c=new t(s,i,()=>{this._trackRelease(c),this._depthCache.put(c)})}return c.name=o,this._trackAcquire(c,`d `+i(e),n,r),c}_acquireColor(t,n,r,a){let s=g(t,n,r),c=this._colorCache.pop(s);if(c)c.retain();else{let i=new f(this.rctx,{...o[t],width:n,height:r,isImmutable:!0});c=new e(s,i,()=>{this._trackRelease(c),this._colorCache.put(c)})}return c.name=a,this._trackAcquire(c,`c `+i(t),n,r),c}_trackHandle(e){return this._acquired.add(e),e}_trackAcquire(e,t,n,r){this.debugCallback&&this._usage.add(e,t,n,r)}_trackRelease(e){this.debugCallback&&this._usage.remove(e)}}function m(e=0){return`color${e}`}const h=`depth`;function g(e,t,n){return`${t}x${n}:${e}`}export{p as FBOCache};
2
+ import e from"../../webgl/ManagedColorAttachment.js";import{ManagedDepthTexture as t}from"../../webgl/ManagedDepthTexture.js";import n from"../../webgl/ManagedFBO.js";import{isDepthFormat as r,formatString as i,DepthTextureFormats as a,ColorFormats as o}from"./FBOCacheFormats.js";import{FBOCacheUsage as s}from"./FBOCacheUsage.js";import{FBOPool as c}from"./FBOPool.js";import{DepthStencilAttachment as l,ColorAttachment0 as u}from"../../../webgl/enums.js";import{DisposableFramebufferObject as d}from"../../../webgl/FramebufferObject.js";import{Texture as f}from"../../../webgl/Texture.js";class p{constructor(e){this.rctx=e,this._interactive=!1,this._usage=new s,this._acquired=new Set,this._cache=new c(e.newCache,`FBOCache`),this._colorCache=new c(e.newCache,`ColorAttachmentCache`),this._depthCache=new c(e.newCache,`DepthAttachmentCache`)}destroy(){this._cache.destroy(),this._depthCache.destroy(),this._colorCache.destroy()}clean(){this._cache.clean(),this._colorCache.clean(),this._depthCache.clean()}frameStart(){this._cache.frame(),this._colorCache.frame(),this._depthCache.frame(),this.debugCallback?.(),this._usage.clear()}frameEnd(){this.debugCallback&&(this._usage.summarize(),this._acquired.forEach(e=>this.debugCallback?.(e.name,e.fbo)))}get usedMemory(){return this._acquired.values().reduce((e,t)=>e+t.usedMemory,this._cache.usedMemory+this._colorCache.usedMemory+this._depthCache.usedMemory)}set interactive(e){this._cache.interactive=this._colorCache.interactive=this._depthCache.interactive=e,this._interactive=e}get interactive(){return this._interactive}acquire(e,t,a,o=5){let s=g(o,e,t),c=this._cache.pop(s),{rctx:f}=this;if(c){c.retain(),c.setName(a);let e=c.getAttachment(l);e&&(e.name=h);let t=c.getAttachment(u);t&&(t.name=m(0)),f.unbindTexture(c.fbo.colorTexture)}else{let i=new d(f);c=new n(s,a,i,(n,r,i)=>{r??=5,i??=m(n-u);let a=this._acquireColor(r,e,t,i);return this.rctx.unbindTexture(a.attachment),c.attachColor(a,n),a.release(),c},n=>{n??=14;let r=this.acquireDepth(n,e,t,`${c.name} ${h}`);return c.attachDepth(r),r.release(),c},()=>{if(!c)return;this.debugCallback?.(c.name,c.fbo),this._acquired.delete(c);let e=r(o);e&&c.getAttachment(l)!=null||!e&&c.getAttachment(u)!=null?(e?(c.fbo?.invalidateAttachments([l]),c.detachAllColors()):(c.fbo?.invalidateAttachments([u]),c.detachAllButColor0()),this._trackRelease(c),this._cache.put(c)):c.dispose()}),r(o)?c.acquireDepth(o):c.acquireColor(u,o)}return this._trackAcquire(c,`f `+i(o),e,t),this._trackHandle(c)}acquireDepth(e,n,r,o){let s=g(e,n,r),c=this._depthCache.pop(s);if(c)c.retain(),c.attachment.setShadowFiltering(!1);else{let i=new f(this.rctx,{...a[e],width:n,height:r});c=new t(s,i,()=>{this._trackRelease(c),this._depthCache.put(c)})}return c.name=o,this._trackAcquire(c,`d `+i(e),n,r),c}_acquireColor(t,n,r,a){let s=g(t,n,r),c=this._colorCache.pop(s);if(c)c.retain();else{let i=new f(this.rctx,{...o[t],width:n,height:r,isImmutable:!0});c=new e(s,i,()=>{this._trackRelease(c),this._colorCache.put(c)})}return c.name=a,this._trackAcquire(c,`c `+i(t),n,r),c}_trackHandle(e){return this._acquired.add(e),e}_trackAcquire(e,t,n,r){this.debugCallback&&this._usage.add(e,t,n,r)}_trackRelease(e){this.debugCallback&&this._usage.remove(e)}}function m(e=0){return`color${e}`}const h=`depth`;function g(e,t,n){return`${t}x${n}:${e}`}export{p as FBOCache};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{disposeMaybe as t}from"../../../../../core/maybe.js";import{subclass as n}from"../../../../../core/accessorSupport/decorators.js";import{fromMat4 as r,transpose as i,invert as a}from"../../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as o}from"../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{set as s,copy as c}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as l}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{MaterialPassParameters as u,ShadowMapPassParameters as d,HighlightPassParameters as f,ViewshedShadowMapPassParameters as p,AllRenderPasses as m}from"./AllRenderPasses.js";import{TwoVectorPosition as h}from"../util/TwoVectorPosition.js";import{SyncRenderPlugin as g}from"../../effects/RenderPlugin.js";import{getEmissions as _}from"../../effects/emissive/emissions.js";import{DepthRange as v}from"../../lib/DepthRange.js";import{SizedPixelFormat as y,DataType as b}from"../../../../webgl/enums.js";import x from"../../../../webgl/Texture.js";import{TextureDescriptor as S}from"../../../../webgl/TextureDescriptor.js";let C=class extends g{constructor(){super(...arguments),this.produces=new Map([[2,e=>this._produces(e,2)],[4,e=>this._produces(e,4)],[0,e=>this._produces(e,0)],[6,e=>this._produces(e,6)],[9,e=>this._produces(e,9)]]),this._drawParametersArray=[],this._drawParametersSet=new Set,this._materialPassParameters=new u,this._shadowPassParameters=new d,this._highlightPassParameters=new f,this._viewshedPassParameters=new p,this._systems=[]}initializeRenderContext(e){this._context=e,this._passes=new m(e,this)}get rctx(){return this._context.renderContext.rctx}get bind(){return this._context.renderContext.bind}uninitializeRenderContext(){}dispose(){this._context=null,this._systems.length=0,this._transformationTexture=t(this._transformationTexture),Object.values(this._passes).forEach(e=>e.destroy())}register(e){this._systems.push(e)}_produces(e,t){return!!this._invoke(e,t,e=>e.count>0)}prepareRender(e){let{_systems:n,_passes:r}=this;n.length!==0&&(this._drawParametersSet.clear(),this._drawParametersArray.length=0,this._transformationTexture=t(this._transformationTexture),Object.values(this._passes).forEach(e=>e.prepareSubmit()),n.forEach(t=>t.submit(r,e.bind)),this._updateTransformationTexture(),Object.values(this._passes).forEach(e=>e.finishSubmit()),this._context.techniques.frameUpdate())}acquireTechniques(e){if(this._systems.length===0)return null;let{output:t,bind:n}=e;return this._invoke(t,n.slot,(t,r)=>(this._updateParameters(n.camera,r,n.slot),r.transformationTexture=this._transformationTexture,t.acquire(r,e.bind)))}render(e,t){this._invoke(e.output,e.bind.slot,(n,r)=>n.dispatch(r,e.bind,t))}_invoke(e,t,n){switch(t){case 2:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:return n(this._passes.opaque,this._materialPassParameters);case 10:return n(this._passes.highlight,this._highlightPassParameters);case 5:return n(this._passes.shadowMap,this._shadowPassParameters);case 6:return n(this._passes.highlightShadowMap,this._shadowPassParameters);case 7:return n(this._passes.defaultShadowMap,this._shadowPassParameters);case 8:return n(this._passes.viewshedShadowMap,this._viewshedPassParameters)}break;case 4:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:return n(this._passes.transparent,this._materialPassParameters)}break;case 0:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:case 9:return n(this._passes.integratedMesh,this._materialPassParameters);case 10:return n(this._passes.highlightIntegratedMesh,this._highlightPassParameters)}break;case 6:switch(e){case 0:case 1:case 2:return n(this._passes.transparentIntegratedMesh,this._materialPassParameters)}break;case 9:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:return n(this._passes.occludedGround,this._materialPassParameters)}}return null}requestRender(){this._context.requestRender()}queryDepthRange(e){return this._systems.reduce((t,n)=>t.union(n.queryDepthRange(e)),new v)}get emissions(){return _(this._systems)}_updateParameters(e,t,n){let o=e.viewInverseTransposeMatrix,l=n===4,u=n===9;s(w,o[3],o[7],o[11]),E.set(w),c(t.transformWorldFromViewTH,E.high),c(t.transformWorldFromViewTL,E.low),c(t.slicePlaneLocalOrigin,w),r(t.transformViewFromCameraRelativeRS,e.viewMatrix),t.identifier===0&&(this._materialPassParameters.transparent=l,this._materialPassParameters.occludedGround=u,i(T,t.transformViewFromCameraRelativeRS),a(t.transformNormalViewFromGlobal,T))}hasHighlight(e){return this._systems.some(t=>t.hasHighlight(e))}registerDrawParameters(e){if(!this._drawParametersSet.has(e)){this._drawParametersSet.add(e);let t=this._drawParametersArray.length;this._drawParametersArray.push(e),e.setTransformationDrawId(t)}}_updateTransformationTexture(){let e=this._drawParametersArray.length;if(e===0)return;let t=2**Math.ceil(Math.log2(e)),n=new Float32Array(t*15);for(let t=0;t<e;t++){let e=this._drawParametersArray[t];e.setTransformationDrawId(t);let r=t*15;n.set(e.transformationFloats,r)}if(this._transformationTexture&&this._transformationTexture.descriptor.height>=e)this._transformationTexture.updateData(0,0,0,5,e,n);else{this._transformationTexture?.dispose();let e=new S(5,t);e.internalFormat=y.RGB32F,e.dataType=b.FLOAT,e.hasMipmap=!1,e.isImmutable=!0,e.pixelFormat=6407,e.samplingMode=9728,this._transformationTexture=new x(this.rctx,e,n)}}};C=e([n(`esri.views.3d.webgl-engine.core.renderPasses.RenderPassManager`)],C);const w=l(),T=o(),E=new h;export{C as RenderPassManager};
2
+ import{__decorate as e}from"tslib";import{disposeMaybe as t}from"../../../../../core/maybe.js";import{subclass as n}from"../../../../../core/accessorSupport/decorators.js";import{fromMat4 as r,transpose as i,invert as a}from"../../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as o}from"../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{set as s,copy as c}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as l}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{MaterialPassParameters as u,ShadowMapPassParameters as d,HighlightPassParameters as f,ViewshedShadowMapPassParameters as p,AllRenderPasses as m}from"./AllRenderPasses.js";import{TwoVectorPosition as h}from"../util/TwoVectorPosition.js";import{SyncRenderPlugin as g}from"../../effects/RenderPlugin.js";import{getEmissions as _}from"../../effects/emissive/emissions.js";import{DepthRange as v}from"../../lib/DepthRange.js";import{SizedPixelFormat as y,DataType as b}from"../../../../webgl/enums.js";import{Texture as x}from"../../../../webgl/Texture.js";import{TextureDescriptor as S}from"../../../../webgl/TextureDescriptor.js";let C=class extends g{constructor(){super(...arguments),this.produces=new Map([[2,e=>this._produces(e,2)],[4,e=>this._produces(e,4)],[0,e=>this._produces(e,0)],[6,e=>this._produces(e,6)],[9,e=>this._produces(e,9)]]),this._drawParametersArray=[],this._drawParametersSet=new Set,this._materialPassParameters=new u,this._shadowPassParameters=new d,this._highlightPassParameters=new f,this._viewshedPassParameters=new p,this._systems=[]}initializeRenderContext(e){this._context=e,this._passes=new m(e,this)}get rctx(){return this._context.renderContext.rctx}get bind(){return this._context.renderContext.bind}uninitializeRenderContext(){}dispose(){this._context=null,this._systems.length=0,this._transformationTexture=t(this._transformationTexture),Object.values(this._passes).forEach(e=>e.destroy())}register(e){this._systems.push(e)}_produces(e,t){return!!this._invoke(e,t,e=>e.count>0)}prepareRender(e){let{_systems:n,_passes:r}=this;n.length!==0&&(this._drawParametersSet.clear(),this._drawParametersArray.length=0,this._transformationTexture=t(this._transformationTexture),Object.values(this._passes).forEach(e=>e.prepareSubmit()),n.forEach(t=>t.submit(r,e.bind)),this._updateTransformationTexture(),Object.values(this._passes).forEach(e=>e.finishSubmit()),this._context.techniques.frameUpdate())}acquireTechniques(e){if(this._systems.length===0)return null;let{output:t,bind:n}=e;return this._invoke(t,n.slot,(t,r)=>(this._updateParameters(n.camera,r,n.slot),r.transformationTexture=this._transformationTexture,t.acquire(r,e.bind)))}render(e,t){this._invoke(e.output,e.bind.slot,(n,r)=>n.dispatch(r,e.bind,t))}_invoke(e,t,n){switch(t){case 2:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:return n(this._passes.opaque,this._materialPassParameters);case 10:return n(this._passes.highlight,this._highlightPassParameters);case 5:return n(this._passes.shadowMap,this._shadowPassParameters);case 6:return n(this._passes.highlightShadowMap,this._shadowPassParameters);case 7:return n(this._passes.defaultShadowMap,this._shadowPassParameters);case 8:return n(this._passes.viewshedShadowMap,this._viewshedPassParameters)}break;case 4:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:return n(this._passes.transparent,this._materialPassParameters)}break;case 0:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:case 9:return n(this._passes.integratedMesh,this._materialPassParameters);case 10:return n(this._passes.highlightIntegratedMesh,this._highlightPassParameters)}break;case 6:switch(e){case 0:case 1:case 2:return n(this._passes.transparentIntegratedMesh,this._materialPassParameters)}break;case 9:switch(e){case 0:case 1:case 2:case 3:case 4:case 11:return n(this._passes.occludedGround,this._materialPassParameters)}}return null}requestRender(){this._context.requestRender()}queryDepthRange(e){return this._systems.reduce((t,n)=>t.union(n.queryDepthRange(e)),new v)}get emissions(){return _(this._systems)}_updateParameters(e,t,n){let o=e.viewInverseTransposeMatrix,l=n===4,u=n===9;s(w,o[3],o[7],o[11]),E.set(w),c(t.transformWorldFromViewTH,E.high),c(t.transformWorldFromViewTL,E.low),c(t.slicePlaneLocalOrigin,w),r(t.transformViewFromCameraRelativeRS,e.viewMatrix),t.identifier===0&&(this._materialPassParameters.transparent=l,this._materialPassParameters.occludedGround=u,i(T,t.transformViewFromCameraRelativeRS),a(t.transformNormalViewFromGlobal,T))}hasHighlight(e){return this._systems.some(t=>t.hasHighlight(e))}registerDrawParameters(e){if(!this._drawParametersSet.has(e)){this._drawParametersSet.add(e);let t=this._drawParametersArray.length;this._drawParametersArray.push(e),e.setTransformationDrawId(t)}}_updateTransformationTexture(){let e=this._drawParametersArray.length;if(e===0)return;let t=2**Math.ceil(Math.log2(e)),n=new Float32Array(t*15);for(let t=0;t<e;t++){let e=this._drawParametersArray[t];e.setTransformationDrawId(t);let r=t*15;n.set(e.transformationFloats,r)}if(this._transformationTexture&&this._transformationTexture.descriptor.height>=e)this._transformationTexture.updateData(0,0,0,5,e,n);else{this._transformationTexture?.dispose();let e=new S(5,t);e.internalFormat=y.RGB32F,e.dataType=b.FLOAT,e.hasMipmap=!1,e.isImmutable=!0,e.pixelFormat=6407,e.samplingMode=9728,this._transformationTexture=new x(this.rctx,e,n)}}};C=e([n(`esri.views.3d.webgl-engine.core.renderPasses.RenderPassManager`)],C);const w=l(),T=o(),E=new h;export{C as RenderPassManager};