@arcgis/core 4.34.0-next.74 → 4.34.0-next.76

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 (248) hide show
  1. package/PopupTemplate.js +1 -1
  2. package/applications/Components/QuantityFormatter.js +1 -1
  3. package/applications/Components/arcadeEditorUtils.d.ts +4 -0
  4. package/applications/Components/arcadeEditorUtils.js +5 -0
  5. package/applications/Components/featureUtils.d.ts +1 -0
  6. package/applications/Components/featureUtils.js +1 -1
  7. package/arcade/Feature.js +1 -1
  8. package/arcade/Pixel.js +5 -0
  9. package/arcade/Voxel.js +1 -1
  10. package/arcade/arcadeAsyncRuntime.js +1 -1
  11. package/arcade/arcadeCompiler.js +1 -1
  12. package/arcade/arcadeRuntime.js +1 -1
  13. package/arcade/featureSetUtils.js +1 -1
  14. package/arcade/featureset/actions/GroupBy.js +1 -1
  15. package/arcade/featureset/actions/OrderBy.js +1 -1
  16. package/arcade/featureset/support/FeatureSetIterator.js +1 -1
  17. package/arcade/functions/feature.js +1 -1
  18. package/arcade/functions/featuresetbase.js +1 -1
  19. package/arcade/functions/featuresetstring.js +1 -1
  20. package/arcade/functions/fieldStats.js +1 -1
  21. package/arcade/functions/geometry.js +1 -1
  22. package/arcade/functions/maths.js +1 -1
  23. package/arcade/functions/string.js +1 -1
  24. package/arcade/languageUtils.js +1 -1
  25. package/arcade.js +1 -1
  26. package/assets/esri/core/workers/RemoteClient.js +1 -1
  27. package/assets/esri/core/workers/chunks/009556f323e58271bc7a.js +1 -0
  28. package/assets/esri/core/workers/chunks/{11acefc48c0354e675df.js → 0309d008e50e55c7ff1d.js} +1 -1
  29. package/assets/esri/core/workers/chunks/13de06e614adf92239fe.js +1 -0
  30. package/assets/esri/core/workers/chunks/14a22d1a0eefa970efa1.js +1 -0
  31. package/assets/esri/core/workers/chunks/16d66770ef841564ee3f.js +1 -0
  32. package/assets/esri/core/workers/chunks/17103e6542aae53c7301.js +1 -0
  33. package/assets/esri/core/workers/chunks/{dd447dfc50ee7f511b84.js → 19c1f1431c0b2f4525a2.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{5c30252c1bb8350cae5f.js → 1c52999a6392370844a6.js} +1 -1
  35. package/assets/esri/core/workers/chunks/21bfad7283620766d9cd.js +1 -0
  36. package/assets/esri/core/workers/chunks/{7219ceab0b6fae2e69b6.js → 280af3640f8e93c1024e.js} +2 -2
  37. package/assets/esri/core/workers/chunks/{49f7a5523462aebf90fc.js.LICENSE.txt → 280af3640f8e93c1024e.js.LICENSE.txt} +1 -1
  38. package/assets/esri/core/workers/chunks/3064320d54a9b48bd697.js +1 -0
  39. package/assets/esri/core/workers/chunks/3a5f0c759dd2f4638343.js +1 -0
  40. package/assets/esri/core/workers/chunks/{d12f373fcf5848ddcd8a.js → 3f523bc8551e712c9bd4.js} +1 -1
  41. package/assets/esri/core/workers/chunks/{5b7e5ec6aea1f7f9b005.js → 3fecfe4f8ca2a5fd7360.js} +1 -1
  42. package/assets/esri/core/workers/chunks/4832faefd3b7edc17c84.js +1 -0
  43. package/assets/esri/core/workers/chunks/{78b33c6d73824085c6d1.js → 48449abe795cb7a831eb.js} +1 -1
  44. package/assets/esri/core/workers/chunks/4d47187bc0821413492d.js +1 -0
  45. package/assets/esri/core/workers/chunks/5102c20645d9708c34b4.js +1 -0
  46. package/assets/esri/core/workers/chunks/541bffd61006d0e36166.js +1 -0
  47. package/assets/esri/core/workers/chunks/58cc06ed86301f4cee75.js +1 -0
  48. package/assets/esri/core/workers/chunks/{e12e8d69c05c182b6a69.js → 61bb39597ccf89f99a72.js} +1 -1
  49. package/assets/esri/core/workers/chunks/{f4e9640306f64b1af7a3.js → 65ec21d29e8563fdbc55.js} +1 -1
  50. package/assets/esri/core/workers/chunks/67d9cfe02613cb73ee37.js.LICENSE.txt +1 -1
  51. package/assets/esri/core/workers/chunks/{6dc62c170e9583222df2.js → 70367da4ba916376f40c.js} +1 -1
  52. package/assets/esri/core/workers/chunks/{fb669a2e50ca7aacac25.js → 71fef0a33b7ed9456e47.js} +1 -1
  53. package/assets/esri/core/workers/chunks/7430c462c350fdd26349.js +1 -0
  54. package/assets/esri/core/workers/chunks/{ff3fe5c97a98c8cab4ac.js → 7a23b127f551bf13ef54.js} +2 -2
  55. package/assets/esri/core/workers/chunks/{ff3fe5c97a98c8cab4ac.js.LICENSE.txt → 7a23b127f551bf13ef54.js.LICENSE.txt} +1 -1
  56. package/assets/esri/core/workers/chunks/7b73a808922b52755abd.js +1 -0
  57. package/assets/esri/core/workers/chunks/{d682dd49bb9ee7f48f93.js → 9304c3cdf732745577fd.js} +1 -1
  58. package/assets/esri/core/workers/chunks/{8d642b34d40edfe02d8e.js → 9c64b78c5c9b35b31d98.js} +2 -2
  59. package/assets/esri/core/workers/chunks/{8d642b34d40edfe02d8e.js.LICENSE.txt → 9c64b78c5c9b35b31d98.js.LICENSE.txt} +1 -1
  60. package/assets/esri/core/workers/chunks/a0edff37fd4a3f2cb2eb.js +1 -0
  61. package/assets/esri/core/workers/chunks/a6533bab3b2fbc1e2a47.js +1 -0
  62. package/assets/esri/core/workers/chunks/a9f6054d86982b9e5a7c.js +1 -0
  63. package/assets/esri/core/workers/chunks/{10ec10ca361842efce92.js → ab005fe84952f0676020.js} +1 -1
  64. package/assets/esri/core/workers/chunks/{5c53deb45bc142219c76.js → b15ff6c9ef2de8a49853.js} +2 -2
  65. package/assets/esri/core/workers/chunks/{5a476e6743902e35f81a.js.LICENSE.txt → b15ff6c9ef2de8a49853.js.LICENSE.txt} +1 -1
  66. package/assets/esri/core/workers/chunks/b70d71144a060f7eeeeb.js +1 -0
  67. package/assets/esri/core/workers/chunks/b8d02f1b73c374767a5f.js +1 -0
  68. package/assets/esri/core/workers/chunks/ba6452acee3d6defb37e.js +1 -0
  69. package/assets/esri/core/workers/chunks/bccecd678faff927ac76.js +1 -0
  70. package/assets/esri/core/workers/chunks/{ce1f4508487298ab57b6.js → bd2dc1282c49125ede89.js} +1 -1
  71. package/assets/esri/core/workers/chunks/bfbbf180c2c8fdbb6731.js +1 -0
  72. package/assets/esri/core/workers/chunks/{f542bdc994a5ea3aa9d1.js → c38360d912f256519e06.js} +1 -1
  73. package/assets/esri/core/workers/chunks/{e3ad0a390387c5847aca.js → c6fecf2bbd2a711f15d3.js} +1 -1
  74. package/assets/esri/core/workers/chunks/c86f5bb199cf046b8952.js +1 -0
  75. package/assets/esri/core/workers/chunks/cd1869e183001266c4c1.js +2 -0
  76. package/assets/esri/core/workers/chunks/{626c18c1bbc50b3b16b2.js.LICENSE.txt → cd1869e183001266c4c1.js.LICENSE.txt} +1 -1
  77. package/assets/esri/core/workers/chunks/{90321feb56f3a84f6e58.js → d153b29c542c37ae1636.js} +2 -2
  78. package/assets/esri/core/workers/chunks/{90321feb56f3a84f6e58.js.LICENSE.txt → d153b29c542c37ae1636.js.LICENSE.txt} +1 -1
  79. package/assets/esri/core/workers/chunks/{b5f197e24982f6e14468.js → d1f181f91b36351f1d3b.js} +2 -2
  80. package/assets/esri/core/workers/chunks/d55c55d39a253630d228.js +1 -0
  81. package/assets/esri/core/workers/chunks/{49f7a5523462aebf90fc.js → d66cdb9bb494da19696b.js} +2 -2
  82. package/assets/esri/core/workers/chunks/{5c53deb45bc142219c76.js.LICENSE.txt → d66cdb9bb494da19696b.js.LICENSE.txt} +1 -1
  83. package/assets/esri/core/workers/chunks/{9c00c2263e52ad51c2a2.js → d95554f43694b4769675.js} +1 -1
  84. package/assets/esri/core/workers/chunks/dd587d51dad2d82708d1.js +1 -0
  85. package/assets/esri/core/workers/chunks/ecac5ca00c742bfb5898.js +1 -0
  86. package/assets/esri/core/workers/chunks/ed773dab5965e42a2879.js +2 -0
  87. package/assets/esri/core/workers/chunks/{7219ceab0b6fae2e69b6.js.LICENSE.txt → ed773dab5965e42a2879.js.LICENSE.txt} +1 -1
  88. package/assets/esri/core/workers/chunks/{0d946a226b846b3c0849.js → fc06014fb484fc8c697e.js} +1 -1
  89. package/assets/esri/images/portal/xrexperience16.png +0 -0
  90. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  91. package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
  92. package/chunks/Compositing.glsl.js +4 -3
  93. package/chunks/Fog.glsl.js +6 -6
  94. package/chunks/GlowComposition.glsl.js +31 -12
  95. package/chunks/LineMarker.glsl.js +37 -36
  96. package/chunks/RibbonLine.glsl.js +83 -83
  97. package/chunks/array.js +1 -1
  98. package/chunks/cameraUtilsSpherical.js +1 -1
  99. package/chunks/languageUtils.js +1 -1
  100. package/chunks/lyr3DMain.js +1 -1
  101. package/chunks/lyr3DWorker.js +1 -1
  102. package/config.js +1 -1
  103. package/core/quantityFormatUtils.js +1 -1
  104. package/core/sql.d.ts +1 -0
  105. package/core/unitFormatUtils.js +1 -1
  106. package/core/unitUtils.js +1 -1
  107. package/form/FormTemplate.js +1 -1
  108. package/geometry/support/curves/circleUtils.js +1 -1
  109. package/geometry/support/curves/circularArcUtils.js +1 -1
  110. package/geometry/support/curves/closestPointOnCurve.js +1 -1
  111. package/geometry/support/curves/curveExtent.js +1 -1
  112. package/geometry/support/curves/lineUtils.js +5 -0
  113. package/geometry/support/heightModelInfoUtils.js +1 -1
  114. package/geometry/support/normalizeUtils.js +1 -1
  115. package/geometry/support/spatialReferenceUtils.js +1 -1
  116. package/interfaces.d.ts +315 -18
  117. package/kernel.js +1 -1
  118. package/layers/GaussianSplatLayer.js +1 -1
  119. package/layers/ImageryLayer.js +1 -1
  120. package/layers/ImageryTileLayer.js +1 -1
  121. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  122. package/layers/Lyr3DWorkerHandle.js +1 -1
  123. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  124. package/layers/support/fieldUtils.js +1 -1
  125. package/layers/support/tiles3DUtils.js +1 -1
  126. package/networks/CircuitManager.js +1 -1
  127. package/networks/support/Circuit.js +1 -1
  128. package/networks/support/CircuitSection.js +1 -1
  129. package/networks/support/Subcircuit.js +1 -1
  130. package/package.json +2 -2
  131. package/portal/PortalItem.js +1 -1
  132. package/renderers/ClassBreaksRenderer.js +1 -1
  133. package/renderers/DictionaryRenderer.js +1 -1
  134. package/renderers/DotDensityRenderer.js +1 -1
  135. package/renderers/HeatmapRenderer.js +1 -1
  136. package/renderers/PieChartRenderer.js +1 -1
  137. package/renderers/UniqueValueRenderer.js +1 -1
  138. package/renderers/mixins/VisualVariablesMixin.js +1 -1
  139. package/support/arcadeUtils.js +1 -1
  140. package/support/loadArcade.js +1 -1
  141. package/support/modeUtils.js +1 -1
  142. package/support/revision.js +1 -1
  143. package/symbols/CIMSymbol.js +1 -1
  144. package/symbols/support/FeatureExpressionInfo.js +1 -1
  145. package/views/2d/layers/LayerView2D.js +1 -1
  146. package/views/2d/layers/MediaLayerView2D.js +1 -1
  147. package/views/2d/layers/TileLayerView2D.js +1 -1
  148. package/views/3d/analysis/Dimension/DimensionVisualization.js +1 -1
  149. package/views/3d/analysis/Dimension/LengthDimensionSubTool.js +1 -1
  150. package/views/3d/analysis/Dimension/lengthDimensionManipulatorUtils.js +1 -1
  151. package/views/3d/analysis/Slice/ResizeManipulator.js +1 -1
  152. package/views/3d/analysis/Slice/RotateManipulator.js +1 -1
  153. package/views/3d/analysis/Slice/ShiftManipulator.js +1 -1
  154. package/views/3d/analysis/Viewshed/ViewshedFieldOfViewManipulation.js +1 -1
  155. package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementTool.js +1 -1
  156. package/views/3d/environment/Fog.js +1 -1
  157. package/views/3d/interactive/visualElements/ExtendedLineVisualElement.js +1 -1
  158. package/views/3d/interactive/visualElements/LineVisualElement.js +1 -1
  159. package/views/3d/interactive/visualElements/MarkerVisualElement.js +1 -1
  160. package/views/3d/interactive/visualElements/OutlineVisualElement.js +1 -1
  161. package/views/3d/interactive/visualElements/ParallelLineVisualElement.js +1 -1
  162. package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
  163. package/views/3d/layers/FlowSubView3D.js +1 -1
  164. package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
  165. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  166. package/views/3d/layers/Lyr3DWorker.js +1 -1
  167. package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
  168. package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
  169. package/views/3d/layers/i3s/PointCloudRenderer.js +1 -1
  170. package/views/3d/layers/support/Tiles3DIntersectionHandler.js +1 -1
  171. package/views/3d/state/SurfaceCollisionConstraint.js +1 -1
  172. package/views/3d/state/ViewStateManager.js +1 -1
  173. package/views/3d/state/controllers/SurfaceCollisionCorrectionController.js +1 -1
  174. package/views/3d/support/cameraUtils.js +1 -1
  175. package/views/3d/support/cameraUtilsSpherical.js +1 -1
  176. package/views/3d/support/flow/FlowSubViewExtent3D.js +1 -1
  177. package/views/3d/support/flow/FlowSubViewTiles3D.js +1 -1
  178. package/views/3d/support/flow/FlowWorker.js +1 -1
  179. package/views/3d/support/flow/geometryUtils.js +1 -1
  180. package/views/3d/support/flow/loadUtils.js +1 -1
  181. package/{layers/support/GaussianSplatAtlasPageAllocator.js → views/3d/support/gaussianSplatting/GaussianSplatAtlasPages.js} +1 -1
  182. package/views/3d/support/gaussianSplatting/GaussianSplatDataStore.js +5 -0
  183. package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +5 -0
  184. package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +5 -0
  185. package/views/3d/support/gaussianSplatting/GaussianTile.js +5 -0
  186. package/views/3d/terrain/OverlayManager.js +1 -1
  187. package/views/3d/terrain/TerrainSurface.js +1 -1
  188. package/views/3d/webgl-engine/core/shaderLibrary/attributes/RibbonVertexPosition.glsl.js +23 -13
  189. package/views/3d/webgl-engine/core/shaderLibrary/shading/LineStipple.glsl.js +37 -25
  190. package/views/3d/webgl-engine/core/shaderLibrary/shading/MarkerSizing.glsl.js +11 -11
  191. package/views/3d/webgl-engine/core/shaderLibrary/util/NoPerspective.glsl.js +5 -0
  192. package/views/3d/webgl-engine/effects/glow/GlowComposition.glsl.js +1 -1
  193. package/views/3d/webgl-engine/effects/glow/GlowPresets.glsl.js +1 -1
  194. package/views/3d/webgl-engine/effects/glow/GlowRenderNode.js +1 -1
  195. package/views/3d/webgl-engine/lib/CompositingHelper.js +1 -1
  196. package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
  197. package/views/3d/webgl-engine/lib/GridLocalOriginFactory.js +1 -1
  198. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  199. package/views/3d/webgl-engine/lib/edgeRendering/strokes.js +1 -1
  200. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  201. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  202. package/views/3d/webgl-engine/materials/stippleTextureRepository.js +1 -1
  203. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  204. package/views/3d/webgl-engine/shaders/CompositingTechnique.js +1 -1
  205. package/views/3d/webgl-engine/shaders/CompositingTechniqueConfiguration.js +1 -1
  206. package/views/3d/webgl-engine/shaders/LineMarker.glsl.js +1 -1
  207. package/views/3d/webgl-engine/shaders/LineMarkerTechniqueConfiguration.js +1 -1
  208. package/views/3d/webgl-engine/shaders/RibbonLine.glsl.js +1 -1
  209. package/views/3d/webgl-engine/shaders/RibbonLineTechniqueConfiguration.js +1 -1
  210. package/views/3d/webgl-engine/shaders/sources/edgeRenderer/LineOffset.glsl.js +10 -11
  211. package/views/GroundView.js +1 -1
  212. package/views/VideoView.js +1 -1
  213. package/views/interactive/snapping/allLayerSnapping.js +1 -1
  214. package/views/layers/ImageryLayerView.js +1 -1
  215. package/views/support/LayerViewManager.js +1 -1
  216. package/widgets/Feature/support/arcadeFeatureUtils.js +1 -1
  217. package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
  218. package/widgets/support/widget.js +1 -1
  219. package/assets/esri/core/workers/chunks/06bd58c219678315cf5c.js +0 -1
  220. package/assets/esri/core/workers/chunks/0751f539db31bdb5caec.js +0 -1
  221. package/assets/esri/core/workers/chunks/19228ab0fe7944c554e5.js +0 -1
  222. package/assets/esri/core/workers/chunks/2a19a4d7d1c580121065.js +0 -1
  223. package/assets/esri/core/workers/chunks/3d2629357242492afcfa.js +0 -1
  224. package/assets/esri/core/workers/chunks/5a476e6743902e35f81a.js +0 -2
  225. package/assets/esri/core/workers/chunks/5a95688651d7e8b7101d.js +0 -1
  226. package/assets/esri/core/workers/chunks/5c4ba165816809e06340.js +0 -1
  227. package/assets/esri/core/workers/chunks/5f239972cb95afdfa77a.js +0 -1
  228. package/assets/esri/core/workers/chunks/626c18c1bbc50b3b16b2.js +0 -2
  229. package/assets/esri/core/workers/chunks/6963ded8428cc8d51d85.js +0 -1
  230. package/assets/esri/core/workers/chunks/6c3ae96c6ef764fb9552.js +0 -1
  231. package/assets/esri/core/workers/chunks/6da298da2ec09cced0b5.js +0 -1
  232. package/assets/esri/core/workers/chunks/76ec3d2646ba64e3442f.js +0 -1
  233. package/assets/esri/core/workers/chunks/8b1d2bbb2b2eb1830921.js +0 -1
  234. package/assets/esri/core/workers/chunks/925ad2665c2fe0f47cc3.js +0 -1
  235. package/assets/esri/core/workers/chunks/a2f4b6d8da93f106852c.js +0 -1
  236. package/assets/esri/core/workers/chunks/ada8e07ff12bc5d4a1d9.js +0 -1
  237. package/assets/esri/core/workers/chunks/b03dcbc31bccb9fdf9fe.js +0 -1
  238. package/assets/esri/core/workers/chunks/b0de01f8c9b1c3182e0c.js +0 -1
  239. package/assets/esri/core/workers/chunks/c7ba8f2aca0fbd6ceded.js +0 -1
  240. package/assets/esri/core/workers/chunks/c908184d747d33366881.js +0 -1
  241. package/assets/esri/core/workers/chunks/d1711256493d55eca523.js +0 -1
  242. package/assets/esri/core/workers/chunks/d305ca524837c5dc81c8.js +0 -1
  243. package/assets/esri/core/workers/chunks/e6e4e2fb9568319c6207.js +0 -1
  244. package/assets/esri/core/workers/chunks/e6f2ac738df16fb5e13a.js +0 -1
  245. package/assets/esri/core/workers/chunks/e8d25d4ca9b335883f34.js +0 -1
  246. package/assets/esri/core/workers/chunks/ee391a41144855fc625d.js +0 -1
  247. package/assets/esri/core/workers/chunks/f060a52a9b69eb250d63.js +0 -1
  248. package/layers/support/gaussianSplatUtils.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import u from"../../../core/ObjectPool.js";import p from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as _}from"../../../core/promiseUtils.js";import{watch as m,syncAndInitial as f,sync as y,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/unitUtils.js";import{property as w}from"../../../core/accessorSupport/decorators/property.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{q as C,i as b,c as x}from"../../../chunks/vec32.js";import{create as E}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as U}from"../../../geometry/ellipsoidUtils.js";import D from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as R}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as B,equals as I,intersection as k,intersectsSphere as A,empty as V,expand as q}from"../../../geometry/support/aaBoundingRect.js";import{copy as O,create as G}from"../../../geometry/support/frustum.js";import{isPlateCarree as N}from"../../../geometry/support/spatialReferenceUtils.js";import{m as F,c as W,n as H,o as $,e as Q}from"../../../chunks/sphere.js";import{ElevationQueryTileCache as z}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as Y}from"../../../layers/support/layerUtils.js";import{debugFlags as X}from"../support/debugFlags.js";import{ElevationRange as K}from"../support/ElevationRange.js";import{toBoundingRect as J}from"../support/extentUtils.js";import{updatingProgress as Z}from"../support/updatingProperties.js";import{ElevationBounds as ee}from"./ElevationBounds.js";import{ElevationData as te,sampleElevation as ie}from"./ElevationData.js";import{ElevationUpdateEventImplementation as re}from"./ElevationUpdateEvent.js";import{create as se}from"./ExtentHelper.js";import{LayerClasses as ae}from"./LayerClass.js";import{OverlayManager as ne}from"./OverlayManager.js";import{PlanarPatch as le}from"./PlanarPatch.js";import{ScaleRangeQueries as oe}from"./ScaleRangeQueries.js";import{SphericalPatch as he}from"./SphericalPatch.js";import{SplitLimits as de}from"./SplitLimits.js";import{maxRootTiles as ue,tooManyRootTilesAfterChangeError as pe,tooManyRootTilesForLayerError as ce,maxTileNeighborLevelDelta as ge,maxMemoryLodBias as _e}from"./TerrainConst.js";import{TerrainRenderer as me}from"./TerrainRenderer.js";import fe from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as ye,isVectorTileLayerView as Te,neighborEdgeIndices as ve,internalAssert as we,oppositeEdge as Se,isSurfaceLayerView as Ce,isGroupLayerView as be,isMapTileLayerView as xe,isBlendableLayerView as Ee,isElevationLayerView as Le,releaseTerrainData as Pe,enableTerrainInternalChecks as Ue,oppositeCorner as De,enableWaterproofTests as Me,enableInternalTerrainChecks as Re,enableTerrainWaterproofChecks as je,neighborCornerIndices as Be}from"./terrainUtils.js";import{Tile as Ie,lijEquals as ke}from"./Tile.js";import{printAllocations as Ae}from"./TilePerLayerInfo.js";import{sortTiles as Ve,IteratorPreorder as qe,IteratorPostorder as Oe,compareTilesByLij as Ge,hasLoadableSiblings as Ne,sortTilesByPOI as Fe}from"./tileUtils.js";import{TilingSchemeLogic as We}from"./TilingSchemeLogic.js";import{UpsampleInfo as He}from"./UpsampleInfo.js";import{isCompositeBlendMode as $e,blendModeFromString as Qe}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as ze}from"../../support/layerViewUtils.js";import{ImmediateTask as Ye,TaskPriority as Xe,noBudget as Ke}from"../../support/Scheduler.js";import{TextureCompressionTracker as Je}from"../../support/TextureCompressionTracker.js";import{Yield as Ze}from"../../support/Yield.js";var et;let tt=class extends n{static{et=this}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ve(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new Je,this._iteratorPool=new u(()=>new qe,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Oe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new fe,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=E(),this._eyePosSurfaceSR=E(),this._splitLimits=new de,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Ye,this._allTiles=new p,this._upsampleInfoPool=new u(()=>new He),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=B(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=D.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new ee(1/0,-1/0),this.rootTileElevationBounds=new ee(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new ne({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?he:le,this._ellipsoid=P(t.spatialReference),this._renderer=new me(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),ze()||(this._scaleRangeQueries=new oe)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new z(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([m(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),m(()=>this.renderer.visible,e=>this.suspended=!e),m(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),m(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([m(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},f),m(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),f),m(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},y),m(()=>this.snapLevel,()=>this._viewChanged=!0,y),m(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:C})}),m(()=>X.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&X.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=se(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new We({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme(),this._elevationDataRequester=t.createStreamDataRequester(0),this._mapDataRequester=t.createStreamDataRequester(1);const o=t.scheduler;this._frameTask=o.registerTask(Xe.TERRAIN_SURFACE,this),this.addHandles([m(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),m(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),y),m(()=>this.extent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),m(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),f),m(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),m(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),m(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),m(()=>this._userClippingExtent,()=>this._updateClippingExtent(),y)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Ye,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),Ie.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),Ae(),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(){if(this.lodSnappingEnabled){const{view:e,tilingScheme:t}=this,i=e.scale;if(t&&i){const r=t.levelAtScale(i)+e.qualitySettings.tiledSurface.lodBias,s=t.getMaxLod();return r<=0?null:Math.min(r,s||1/0)}}return null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get _userClippingExtent(){const{spatialReference:e}=this,t=this.view?.clippingArea;if(null==t||null==e)return null;const i=B(),r=J(t,i,e)?i:null,s=this._get("extent");return I(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=k(this.groundExtent,this._userClippingExtent,B()),t=this._get("extent");return I(e,t)?t:e}get groundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||null!=this._rootTiles}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(rt,e,t,i);a(n,0,n,0);return ht(s,n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,ht(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!R(e,rt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(rt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;rt[0]>t[2]&&(i+=1),rt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationBounds(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;F(e,st);const r=H(st,E());i(r,0,r,0),$(st,r);const s=new K,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,st))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return this.enabled&&null!=this._rootTiles?new K(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationBounds.min)*U;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,mt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;Q(st,mt,t);let i=null;const r=e=>{if(e&&A(e.extent,st)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;ye(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??D.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&N(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(et._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=at;let s=t.rootTilesInExtent(e,i,5*ue);if(null!=this._rootTiles){if(s.length>ue)return void l.getLogger(this).warn(pe);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,ke);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>ke(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>ue&&(l.getLogger(this).warn(ce),s=t.rootTilesInExtent(e,i,ue)),this._setRootTiles(s.map(e=>this._newRootTile(e)));I(i,this._rootTilesExtent)||(this._rootTilesExtent=B(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Ge),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Ge);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=Ne(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new ee(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new ee(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=O(this._splitLimits.frustum??G(),t.frustum):this._splitLimits.frustum=null,x(this._eyePosRenderSR,t.eye),j(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(Te)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=lt.extent;V(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>q(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),lt.spatialReference=this.spatialReference,this.emit("elevation-change",lt),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Ue&&this._checkTileInvariant(),!e.hasProgressed)return Ze}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(ye(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(ye(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){ye(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)ye(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=ge;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${ge} (edge[${i}])`),ye(r,`tile level delta [${t.level}] vs [${e.level}] > ${ge}`))}ye(t.level-e.level<=ge,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-ge,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(ve[i],s);if(null!=a){if(t.leaf&&t.level>=ge){let i=a;for(;t.level-i.level<ge;)i=i.parent;const s=[r,t.lij[1]>>ge,t.lij[2]>>ge];if(!ke(s,i.lij)){const r=e.get(i);ye(!r.has(t),"Cannot already have neighbor"),r.add(t)}}ye(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),ye(t.level-a.level<=ge,`Tile level delta [${t.level}] vs [${a.level}] > ${ge}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);ye(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new dt(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=n?.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?ut(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Fe(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){we(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Ge);const r=t.length;for(let s=0;s<r;++s){const r=t[s];we(r.loaded),we(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=Be[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(De(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(Se(ve[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(we(e.has(t)||Ge(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Ue&&Me&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=ge){const e=e=>e.leaf||i-e.level<ge;for(let r=0;r<4;++r){const a=s.findNeighborTile(ve[r],e);null!=a&&i-a.level===ge&&(t=!1,Ue&&(we(a.leaf),we(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.overlayManager?.updateOverlayParameters(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.quality;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*_e}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?ct(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(et._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){ye(e.leaf,"Tile that is already split should not be split again!"),ye(e.rendered,"Tile marked to split is not rendered"),ct(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),ye(e.rendered,"parent should be rendered"),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>ut(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){ot.spatialReference=this.spatialReference,ot.extent=e.extent,ot.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",ot)}createTile(e,t,i,r){ye(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){ye(!e.hasPendingUpdate(1),"_mergeTile sanity check"),ye(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),ye(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),ut(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&this.overlayManager.updateTileOverlayParameters(e)}_handleLayerViewChanges(e=Ke){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),Ce(e)||be(e))if(this._basemapLayerViewHandles.has(e.uid)&&!be(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(xe(e)&&!Y(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Ee(e)||be(e))&&$e(Qe[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Le(e)?0:1}_registerTiledLayerView(e){const t=[];if((Ee(e)||be(e))&&t.push(m(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!be(e)){const i=this._layerClassFromLayerView(e);t.push(m(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(m(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(m(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!Ce(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ae){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=1){this.renderer.setNeedsRender(e)}requestUpdate(){1===++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||Te(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,c(r),g(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();const s=0===t;return r.requester??=s?this._elevationDataRequester:this._mapDataRequester,s?Le(i)?this._requestElevationTileData(e,i,r):Promise.reject():xe(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!_(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new te(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationBounds(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Pe(s),_(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),_(i)?Pe(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return Pe(i),void l.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):l.getLogger(this).warn("TerrainSurface: received data from unknown layer")}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Me)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.leaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.leaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._isGeographic?1:0)}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this._isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Re(e)}enableWaterproofnessChecks(e){je(e)}static cleanupTerrainSurface(){nt.prune()}enable(e){e!==this.enabled&&(e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this._set("enabled",e),this.notifyChange("ready"))}};e([w()],tt.prototype,"_renderer",void 0),e([w({constructOnly:!0})],tt.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],tt.prototype,"view",void 0),e([w({constructOnly:!0})],tt.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],tt.prototype,"terrainTextureCompressionTracker",void 0),e([w()],tt.prototype,"_hasPendingUpdates",void 0),e([w()],tt.prototype,"_asyncWorkItems",void 0),e([w()],tt.prototype,"_allTilesDirty",void 0),e([w()],tt.prototype,"_allTilesSorted",void 0),e([w()],tt.prototype,"_viewChanged",void 0),e([w({type:Number})],tt.prototype,"heading",void 0),e([w()],tt.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],tt.prototype,"_watchUpdatingTracking",void 0),e([w()],tt.prototype,"_frameTask",void 0),e([w()],tt.prototype,"demResolution",null),e([w({readOnly:!0})],tt.prototype,"snapLevel",null),e([w({readOnly:!0})],tt.prototype,"lodSnappingEnabled",null),e([w()],tt.prototype,"_userClippingExtent",null),e([w()],tt.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],tt.prototype,"extent",null),e([w({readOnly:!0})],tt.prototype,"groundExtent",null),e([w({readOnly:!0})],tt.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],tt.prototype,"updating",null),e([w({readOnly:!0})],tt.prototype,"readyToRun",null),e([w(Z)],tt.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],tt.prototype,"updatingProgressValue",null),e([w()],tt.prototype,"_maxNumUpdating",void 0),e([w()],tt.prototype,"baseOpacity",null),e([w()],tt.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],tt.prototype,"viewingMode",null),e([w()],tt.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],tt.prototype,"ready",null),e([w({readOnly:!0})],tt.prototype,"rootTiles",null),e([w()],tt.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],tt.prototype,"spatialReference",null),e([w({type:t})],tt.prototype,"backgroundColor",null),e([w({value:!1})],tt.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],tt.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],tt.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],tt.prototype,"tilingSchemeLogic",void 0),e([w()],tt.prototype,"wireframe",null),e([w({value:!1})],tt.prototype,"suspended",null),e([w()],tt.prototype,"fadeDuration",null),e([w()],tt.prototype,"visibleElevationBounds",void 0),e([w()],tt.prototype,"rootTileElevationBounds",void 0),e([w()],tt.prototype,"_layerViewsDirty",void 0),e([w()],tt.prototype,"renderPatchBorders",null),e([w()],tt.prototype,"visualizeNormals",null),e([w()],tt.prototype,"renderingDisabled",null),e([w({readOnly:!0})],tt.prototype,"enabled",void 0),tt=et=e([S("esri.views.3d.terrain.TerrainSurface")],tt);const it=tt,rt=E(),st=W(),at=B(),nt=new p,lt=new re("ground"),ot={spatialReference:null,extent:null,scale:0};function ht(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return ie(t,i,s)}return null}class dt{constructor(e){this.capacity=e,this._head=0,this._tail=0,this._data=new Array(e)}push(e){const t=this._tail;if(!(t<this.capacity))throw new Error("Queue full");this._data[t]=e,this._tail=t+1}pushAll(e){const t=e.length;if(0===t)return;const i=this._tail;if(!(i+t<=this.capacity))throw new Error("Queue full");for(let r=0;r<t;++r)this._data[i+r]=e[r];this._tail=i+t}pop(){const e=this._head;if(e<this._tail){const t=this._data[e];return this._head=e+1,t}}get empty(){return this._head>=this._tail}get full(){return this._tail>=this._data.length}}function ut(e,t){!e.leaf||e.level<ge||_t(e,e=>{t&&pt(e);const i=gt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=gt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function pt(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<ge||_t(e,e=>{pt(e)})}function ct(e){e.level<ge||_t(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,gt(t));)t=t.parent}})}function gt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function _t(e,t){if(e.level<ge)return;const i=e.level-ge,r=e.lij[1]>>ge,s=e.lij[2]>>ge,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(ve[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}const mt=E();export{it as default};
5
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import u from"../../../core/ObjectPool.js";import p from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as _}from"../../../core/promiseUtils.js";import{watch as m,syncAndInitial as f,sync as y,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/unitUtils.js";import{property as w}from"../../../core/accessorSupport/decorators/property.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{q as C,i as b,c as x}from"../../../chunks/vec32.js";import{create as E}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as U}from"../../../geometry/ellipsoidUtils.js";import D from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as R}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as B,equals as I,intersection as k,intersectsSphere as A,empty as V,expand as q}from"../../../geometry/support/aaBoundingRect.js";import{copy as N,create as O}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as G}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{m as W,c as H,n as $,o as z,e as Q}from"../../../chunks/sphere.js";import{ElevationQueryTileCache as Y}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as X}from"../../../layers/support/layerUtils.js";import{debugFlags as K}from"../support/debugFlags.js";import{ElevationRange as J}from"../support/ElevationRange.js";import{toBoundingRect as Z}from"../support/extentUtils.js";import{updatingProgress as ee}from"../support/updatingProperties.js";import{ElevationBounds as te}from"./ElevationBounds.js";import{ElevationData as ie,sampleElevation as re}from"./ElevationData.js";import{ElevationUpdateEventImplementation as se}from"./ElevationUpdateEvent.js";import{create as ae}from"./ExtentHelper.js";import{LayerClasses as ne}from"./LayerClass.js";import{OverlayManager as le}from"./OverlayManager.js";import{PlanarPatch as oe}from"./PlanarPatch.js";import{ScaleRangeQueries as he}from"./ScaleRangeQueries.js";import{SphericalPatch as de}from"./SphericalPatch.js";import{SplitLimits as ue}from"./SplitLimits.js";import{maxRootTiles as pe,tooManyRootTilesAfterChangeError as ce,tooManyRootTilesForLayerError as ge,maxTileNeighborLevelDelta as _e,maxMemoryLodBias as me}from"./TerrainConst.js";import{TerrainRenderer as fe}from"./TerrainRenderer.js";import ye from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as Te,isVectorTileLayerView as ve,neighborEdgeIndices as we,internalAssert as Se,oppositeEdge as Ce,isSurfaceLayerView as be,isGroupLayerView as xe,isMapTileLayerView as Ee,isBlendableLayerView as Le,isElevationLayerView as Pe,releaseTerrainData as Ue,enableTerrainInternalChecks as De,oppositeCorner as Me,enableWaterproofTests as Re,enableInternalTerrainChecks as je,enableTerrainWaterproofChecks as Be,neighborCornerIndices as Ie}from"./terrainUtils.js";import{Tile as ke,lijEquals as Ae}from"./Tile.js";import{printAllocations as Ve}from"./TilePerLayerInfo.js";import{sortTiles as qe,IteratorPreorder as Ne,IteratorPostorder as Oe,compareTilesByLij as Ge,hasLoadableSiblings as Fe,sortTilesByPOI as We}from"./tileUtils.js";import{TilingSchemeLogic as He}from"./TilingSchemeLogic.js";import{UpsampleInfo as $e}from"./UpsampleInfo.js";import{isCompositeBlendMode as ze,blendModeFromString as Qe}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as Ye}from"../../support/layerViewUtils.js";import{ImmediateTask as Xe,TaskPriority as Ke,noBudget as Je}from"../../support/Scheduler.js";import{TextureCompressionTracker as Ze}from"../../support/TextureCompressionTracker.js";import{Yield as et}from"../../support/Yield.js";var tt;let it=class extends n{static{tt=this}get allTiles(){return a(this._allTiles)}get renderedTiles(){return qe(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new Ze,this._iteratorPool=new u(()=>new Ne,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Oe,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._usedMemory=null,this._performanceInfo=new ye,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=E(),this._eyePosSurfaceSR=E(),this._splitLimits=new ue,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Xe,this._allTiles=new p,this._upsampleInfoPool=new u(()=>new $e),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=B(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=D.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationBounds=new te(1/0,-1/0),this.rootTileElevationBounds=new te(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new le({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?de:oe,this._ellipsoid=P(t.spatialReference),this._renderer=new fe(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),Ye()||(this._scaleRangeQueries=new he)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new Y(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([m(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),m(()=>this.renderer.visible,e=>this.suspended=!e),m(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),m(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([m(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},f),m(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),f),m(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},y),m(()=>this.snapLevel,()=>this._viewChanged=!0,y),m(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:C})}),m(()=>K.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&K.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=ae(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new He({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme(),this._elevationDataRequester=t.createStreamDataRequester(0),this._mapDataRequester=t.createStreamDataRequester(1);const o=t.scheduler;this._frameTask=o.registerTask(Ke.TERRAIN_SURFACE,this),this.addHandles([m(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),m(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),y),m(()=>this.extent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),m(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),f),m(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),m(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),m(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),m(()=>this._userClippingExtent,()=>this._updateClippingExtent(),y)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Xe,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),ke.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),Ve(),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(){if(this.lodSnappingEnabled){const{view:e,tilingScheme:t}=this,i=e.scale;if(t&&i){const r=t.levelAtScale(i)+e.qualitySettings.tiledSurface.lodBias,s=t.getMaxLod();return r<=0?null:Math.min(r,s||1/0)}}return null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get _userClippingExtent(){const{spatialReference:e}=this,t=this.view?.clippingArea;if(null==t||null==e)return null;const i=B(),r=Z(t,i,e)?i:null,s=this._get("extent");return I(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=k(this.groundExtent,this._userClippingExtent,B()),t=this._get("extent");return I(e,t)?t:e}get groundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||null!=this._rootTiles}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return G(this._spatialReference)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(st,e,t,i);a(n,0,n,0);return dt(s,this._xNormalizer?.normalize(n[0])??n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,dt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!R(e,st,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(st)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;st[0]>t[2]&&(i+=1),st[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationBounds(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;W(e,at);const r=$(at,E());i(r,0,r,0),z(at,r);const s=new J,a=this._rootTiles;if(null!=a){const e=[];for(const i of a)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,at))continue;const r=i.children;if(null==r[0]||i.rendered)s.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of r)e.push(t)}}return s}getRootElevationBounds(){return this.enabled&&null!=this._rootTiles?new J(this.rootTileElevationBounds.min,this.rootTileElevationBounds.max):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationBounds.min)*U;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,ft,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;Q(at,ft,t);let i=null;const r=e=>{if(e&&A(e.extent,at)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;Te(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??D.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(tt._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=nt;let s=t.rootTilesInExtent(e,i,5*pe);if(null!=this._rootTiles){if(s.length>pe)return void l.getLogger(this).warn(ce);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,Ae);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>Ae(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>pe&&(l.getLogger(this).warn(ge),s=t.rootTilesInExtent(e,i,pe)),this._setRootTiles(s.map(e=>this._newRootTile(e)));I(i,this._rootTilesExtent)||(this._rootTilesExtent=B(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Ge),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Ge);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationBounds(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=Fe(e),i=this.visibleElevationBounds;let r=t?i.min:1/0,s=t?i.max:-1/0;const a=this.extent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty();const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.min!==r||i.max!==s)&&(this.visibleElevationBounds=new te(r,s))}_updateRootTileElevationBounds(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this.rootTileElevationBounds;r.min===e&&r.max===t||(this.rootTileElevationBounds=new te(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=N(this._splitLimits.frustum??O(),t.frustum):this._splitLimits.frustum=null,x(this._eyePosRenderSR,t.eye),j(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(ve)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=ot.extent;V(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>q(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),ot.spatialReference=this.spatialReference,this.emit("elevation-change",ot),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),De&&this._checkTileInvariant(),!e.hasProgressed)return et}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(Te(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(Te(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){Te(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)Te(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=_e;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${_e} (edge[${i}])`),Te(r,`tile level delta [${t.level}] vs [${e.level}] > ${_e}`))}Te(t.level-e.level<=_e,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-_e,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(we[i],s);if(null!=a){if(t.leaf&&t.level>=_e){let i=a;for(;t.level-i.level<_e;)i=i.parent;const s=[r,t.lij[1]>>_e,t.lij[2]>>_e];if(!Ae(s,i.lij)){const r=e.get(i);Te(!r.has(t),"Cannot already have neighbor"),r.add(t)}}Te(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),Te(t.level-a.level<=_e,`Tile level delta [${t.level}] vs [${a.level}] > ${_e}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);Te(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new ut(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=n?.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?pt(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(We(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){Se(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Ge);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Se(r.loaded),Se(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=Ie[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(Me(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(Ce(we[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(Se(e.has(t)||Ge(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,De&&Re&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=_e){const e=e=>e.leaf||i-e.level<_e;for(let r=0;r<4;++r){const a=s.findNeighborTile(we[r],e);null!=a&&i-a.level===_e&&(t=!1,De&&(Se(a.leaf),Se(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.overlayManager?.updateOverlayParameters(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.quality;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*me}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?gt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(tt._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){Te(e.leaf,"Tile that is already split should not be split again!"),Te(e.rendered,"Tile marked to split is not rendered"),gt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),Te(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=>pt(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){ht.spatialReference=this.spatialReference,ht.extent=e.extent,ht.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",ht)}createTile(e,t,i,r){Te(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){Te(!e.hasPendingUpdate(1),"_mergeTile sanity check"),Te(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),Te(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),pt(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&this.overlayManager.updateTileOverlayParameters(e)}_handleLayerViewChanges(e=Je){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),be(e)||xe(e))if(this._basemapLayerViewHandles.has(e.uid)&&!xe(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(Ee(e)&&!X(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((Le(e)||xe(e))&&ze(Qe[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Pe(e)?0:1}_registerTiledLayerView(e){const t=[];if((Le(e)||xe(e))&&t.push(m(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!xe(e)){const i=this._layerClassFromLayerView(e);t.push(m(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(m(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(m(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!be(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ne){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationBounds()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=1){this.renderer.setNeedsRender(e)}requestUpdate(){1===++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||ve(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,c(r),g(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();const s=0===t;return r.requester??=s?this._elevationDataRequester:this._mapDataRequester,s?Pe(i)?this._requestElevationTileData(e,i,r):Promise.reject():Ee(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!_(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new ie(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationBounds(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{Ue(s),_(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),_(i)?Ue(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return Ue(i),void l.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):l.getLogger(this).warn("TerrainSurface: received data from unknown layer")}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get visualizeNormals(){return this._renderer.visualizeNormals}set visualizeNormals(e){this._renderer.visualizeNormals=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Re)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.leaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.leaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._isGeographic?1:0)}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this._isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){je(e)}enableWaterproofnessChecks(e){Be(e)}static cleanupTerrainSurface(){lt.prune()}enable(e){e!==this.enabled&&(e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this._set("enabled",e),this.notifyChange("ready"))}};e([w()],it.prototype,"_renderer",void 0),e([w({constructOnly:!0})],it.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],it.prototype,"view",void 0),e([w({constructOnly:!0})],it.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],it.prototype,"terrainTextureCompressionTracker",void 0),e([w()],it.prototype,"_hasPendingUpdates",void 0),e([w()],it.prototype,"_asyncWorkItems",void 0),e([w()],it.prototype,"_allTilesDirty",void 0),e([w()],it.prototype,"_allTilesSorted",void 0),e([w()],it.prototype,"_viewChanged",void 0),e([w({type:Number})],it.prototype,"heading",void 0),e([w()],it.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],it.prototype,"_watchUpdatingTracking",void 0),e([w()],it.prototype,"_frameTask",void 0),e([w()],it.prototype,"demResolution",null),e([w({readOnly:!0})],it.prototype,"snapLevel",null),e([w({readOnly:!0})],it.prototype,"lodSnappingEnabled",null),e([w()],it.prototype,"_userClippingExtent",null),e([w()],it.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],it.prototype,"extent",null),e([w({readOnly:!0})],it.prototype,"groundExtent",null),e([w({readOnly:!0})],it.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],it.prototype,"updating",null),e([w({readOnly:!0})],it.prototype,"readyToRun",null),e([w(ee)],it.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],it.prototype,"updatingProgressValue",null),e([w()],it.prototype,"_maxNumUpdating",void 0),e([w()],it.prototype,"baseOpacity",null),e([w()],it.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],it.prototype,"viewingMode",null),e([w()],it.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],it.prototype,"ready",null),e([w({readOnly:!0})],it.prototype,"rootTiles",null),e([w()],it.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],it.prototype,"spatialReference",null),e([w({type:t})],it.prototype,"backgroundColor",null),e([w({value:!1})],it.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],it.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],it.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],it.prototype,"tilingSchemeLogic",void 0),e([w()],it.prototype,"wireframe",null),e([w({value:!1})],it.prototype,"suspended",null),e([w()],it.prototype,"fadeDuration",null),e([w()],it.prototype,"_xNormalizer",null),e([w()],it.prototype,"visibleElevationBounds",void 0),e([w()],it.prototype,"rootTileElevationBounds",void 0),e([w()],it.prototype,"_layerViewsDirty",void 0),e([w()],it.prototype,"renderPatchBorders",null),e([w()],it.prototype,"visualizeNormals",null),e([w()],it.prototype,"renderingDisabled",null),e([w({readOnly:!0})],it.prototype,"enabled",void 0),it=tt=e([S("esri.views.3d.terrain.TerrainSurface")],it);const rt=it,st=E(),at=H(),nt=B(),lt=new p,ot=new se("ground"),ht={spatialReference:null,extent:null,scale:0};function dt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return re(t,i,s)}return null}class ut{constructor(e){this.capacity=e,this._head=0,this._tail=0,this._data=new Array(e)}push(e){const t=this._tail;if(!(t<this.capacity))throw new Error("Queue full");this._data[t]=e,this._tail=t+1}pushAll(e){const t=e.length;if(0===t)return;const i=this._tail;if(!(i+t<=this.capacity))throw new Error("Queue full");for(let r=0;r<t;++r)this._data[i+r]=e[r];this._tail=i+t}pop(){const e=this._head;if(e<this._tail){const t=this._data[e];return this._head=e+1,t}}get empty(){return this._head>=this._tail}get full(){return this._tail>=this._data.length}}function pt(e,t){!e.leaf||e.level<_e||mt(e,e=>{t&&ct(e);const i=_t(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=_t(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function ct(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<_e||mt(e,e=>{ct(e)})}function gt(e){e.level<_e||mt(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,_t(t));)t=t.parent}})}function _t(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function mt(e,t){if(e.level<_e)return;const i=e.level-_e,r=e.lij[1]>>_e,s=e.lij[2]>>_e,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(we[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}const ft=E();export{rt as default};
@@ -2,14 +2,24 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{VisualVariables as e}from"../shading/VisualVariables.glsl.js";import{Float3PassUniform as a}from"../../shaderModules/Float3PassUniform.js";import{FloatPassUniform as i}from"../../shaderModules/FloatPassUniform.js";import{FloatsPassUniform as t}from"../../shaderModules/FloatsPassUniform.js";import{glsl as r,If as o}from"../../shaderModules/glsl.js";const v=8;function c(c,l){const{vertex:s,attributes:n}=c;s.uniforms.add(new i("intrinsicWidth",e=>e.width)),l.hasVVSize?(n.add("sizeFeatureAttribute","float"),s.uniforms.add(new a("vvSizeMinSize",e=>e.vvSize.minSize),new a("vvSizeMaxSize",e=>e.vvSize.maxSize),new a("vvSizeOffset",e=>e.vvSize.offset),new a("vvSizeFactor",e=>e.vvSize.factor),new a("vvSizeFallback",e=>e.vvSize.fallback)),s.code.add(r`float getSize() {
6
- if (isnan(sizeFeatureAttribute)) {
7
- return vvSizeFallback.x;
8
- }
9
- return intrinsicWidth * clamp(vvSizeOffset + sizeFeatureAttribute * vvSizeFactor, vvSizeMinSize, vvSizeMaxSize).x;
10
- }`)):(n.add("size","float"),s.code.add(r`float getSize(){
11
- return intrinsicWidth * size;
12
- }`)),l.hasVVOpacity?(n.add("opacityFeatureAttribute","float"),s.constants.add("vvOpacityNumber","int",8),s.uniforms.add(new t("vvOpacityValues",e=>e.vvOpacity.values,v),new t("vvOpacityOpacities",e=>e.vvOpacity.opacityValues,v),new i("vvOpacityFallback",e=>e.vvOpacity.fallback,{supportsNaN:!0})),s.code.add(r`
5
+ import{invert as e,translate as i}from"../../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as a}from"../../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{VisualVariables as t}from"../shading/VisualVariables.glsl.js";import{ScreenSizePerspective as r,addScreenSizePerspective as o}from"../util/ScreenSizePerspective.glsl.js";import{addCameraPosition as c}from"../util/View.glsl.js";import{Float3PassUniform as s}from"../../shaderModules/Float3PassUniform.js";import{FloatPassUniform as l}from"../../shaderModules/FloatPassUniform.js";import{FloatsPassUniform as v}from"../../shaderModules/FloatsPassUniform.js";import{glsl as n,If as p}from"../../shaderModules/glsl.js";import{Matrix4DrawUniform as d}from"../../shaderModules/Matrix4DrawUniform.js";const u=8;function f(a,f){const{vertex:m,attributes:S}=a;m.uniforms.add(new l("intrinsicWidth",e=>e.width));const{hasScreenSizePerspective:y,spherical:O}=f;y?(a.include(r,f),o(m),c(m,f),m.uniforms.add(new d("inverseViewMatrix",(a,t)=>e(z,i(z,t.camera.viewMatrix,a.origin)))),m.code.add(n`
6
+ float applyLineSizeScreenSizePerspective(float size, vec3 pos) {
7
+ vec3 worldPos = (inverseViewMatrix * vec4(pos.xyz, 1)).xyz;
8
+ vec3 groundUp = ${O?n`normalize(worldPos + localOrigin)`:n`vec3(0.0, 0.0, 1.0)`};
9
+ float absCosAngle = abs(dot(groundUp, normalize(worldPos - cameraPosition)));
10
+
11
+ return screenSizePerspectiveScaleFloat(size, absCosAngle, length(pos), screenSizePerspective);
12
+ }
13
+ `)):m.code.add(n`float applyLineSizeScreenSizePerspective(float size, vec3 pos) {
14
+ return size;
15
+ }`),f.hasVVSize?(S.add("sizeFeatureAttribute","float"),m.uniforms.add(new s("vvSizeMinSize",e=>e.vvSize.minSize),new s("vvSizeMaxSize",e=>e.vvSize.maxSize),new s("vvSizeOffset",e=>e.vvSize.offset),new s("vvSizeFactor",e=>e.vvSize.factor),new s("vvSizeFallback",e=>e.vvSize.fallback)),m.code.add(n`float getSize(vec3 pos) {
16
+ float size = isnan(sizeFeatureAttribute)
17
+ ? vvSizeFallback.x
18
+ : intrinsicWidth * clamp(vvSizeOffset + sizeFeatureAttribute * vvSizeFactor, vvSizeMinSize, vvSizeMaxSize).x;
19
+ return applyLineSizeScreenSizePerspective(size, pos);
20
+ }`)):(S.add("size","float"),m.code.add(n`float getSize(vec3 pos) {
21
+ return applyLineSizeScreenSizePerspective(intrinsicWidth * size, pos);
22
+ }`)),f.hasVVOpacity?(S.add("opacityFeatureAttribute","float"),m.constants.add("vvOpacityNumber","int",8),m.uniforms.add(new v("vvOpacityValues",e=>e.vvOpacity.values,u),new v("vvOpacityOpacities",e=>e.vvOpacity.opacityValues,u),new l("vvOpacityFallback",e=>e.vvOpacity.fallback,{supportsNaN:!0})),m.code.add(n`
13
23
  float interpolateOpacity(float value) {
14
24
  if (value <= vvOpacityValues[0]) {
15
25
  return vvOpacityOpacities[0];
@@ -28,19 +38,19 @@ return intrinsicWidth * size;
28
38
  vec4 applyOpacity(vec4 color) {
29
39
  if (isnan(opacityFeatureAttribute)) {
30
40
  // If there is a color vv then it will already have taken care of applying the fallback
31
- return ${o(l.hasVVColor,"color","vec4(color.rgb, vvOpacityFallback)")};
41
+ return ${p(f.hasVVColor,"color","vec4(color.rgb, vvOpacityFallback)")};
32
42
  }
33
43
 
34
44
  return vec4(color.rgb, interpolateOpacity(opacityFeatureAttribute));
35
45
  }
36
- `)):s.code.add(r`vec4 applyOpacity(vec4 color) {
46
+ `)):m.code.add(n`vec4 applyOpacity(vec4 color) {
37
47
  return color;
38
- }`),l.hasVVColor?(c.include(e,l),n.add("colorFeatureAttribute","float"),s.code.add(r`vec4 getColor() {
48
+ }`),f.hasVVColor?(a.include(t,f),S.add("colorFeatureAttribute","float"),m.code.add(n`vec4 getColor() {
39
49
  vec4 color = interpolateVVColor(colorFeatureAttribute);
40
50
  if (isnan(color.r)) {
41
51
  return vec4(0);
42
52
  }
43
53
  return applyOpacity(color);
44
- }`)):(n.add("color","vec4"),s.code.add(r`vec4 getColor() {
54
+ }`)):(S.add("color","vec4"),m.code.add(n`vec4 getColor() {
45
55
  return applyOpacity(color);
46
- }`))}export{c as RibbonVertexPosition};
56
+ }`))}const z=a();export{f as RibbonVertexPosition};
@@ -2,55 +2,67 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{RgbaFloatEncoding as e}from"../util/RgbaFloatEncoding.glsl.js";import{addCameraPosition as t,addPixelRatio as o}from"../util/View.glsl.js";import{Float4PassUniform as r}from"../../shaderModules/Float4PassUniform.js";import{FloatBindUniform as i}from"../../shaderModules/FloatBindUniform.js";import{FloatPassUniform as l}from"../../shaderModules/FloatPassUniform.js";import{glsl as a,If as p}from"../../shaderModules/glsl.js";import{Texture2DPassUniform as s}from"../../shaderModules/Texture2DPassUniform.js";import{computeTextureSize as n,computeLongestPattern as d}from"../../../materials/stippleTextureRepository.js";import{ensureColor4 as c}from"../../../shaders/ensureColor4.js";function f(n,d){if(!d.stippleEnabled)return void n.fragment.code.add(a`float getStippleAlpha() { return 1.0; }
5
+ import{NoPerspectiveRead as e}from"../util/NoPerspective.glsl.js";import{RgbaFloatEncoding as t}from"../util/RgbaFloatEncoding.glsl.js";import{addCameraPosition as o,addPixelRatio as i}from"../util/View.glsl.js";import{Float4PassUniform as r}from"../../shaderModules/Float4PassUniform.js";import{FloatBindUniform as l}from"../../shaderModules/FloatBindUniform.js";import{FloatPassUniform as a}from"../../shaderModules/FloatPassUniform.js";import{glsl as s,If as n}from"../../shaderModules/glsl.js";import{Texture2DPassUniform as p}from"../../shaderModules/Texture2DPassUniform.js";import{computeTextureSize as d}from"../../../materials/stippleTextureRepository.js";import{ensureColor4 as c}from"../../../shaders/ensureColor4.js";function f(d,f){if(!f.stippleEnabled)return void d.fragment.code.add(s`float getStippleAlpha(float lineWidth) { return 1.0; }
6
6
  void discardByStippleAlpha(float stippleAlpha, float threshold) {}
7
- vec4 blendStipple(vec4 color, float stippleAlpha) { return color; }`);const f=!(d.draped&&d.stipplePreferContinuous),{vertex:g,fragment:h}=n;h.include(e),d.draped||(t(g,d),g.uniforms.add(new i("worldToScreenPerDistanceRatio",({camera:e})=>1/e.perScreenPixelRatio)).code.add(a`float computeWorldToScreenRatio(vec3 segmentCenter) {
7
+ vec4 blendStipple(vec4 color, float stippleAlpha) { return color; }`);const g=!(f.draped&&f.stipplePreferContinuous),{vertex:S,fragment:h}=d;h.include(t),f.draped||(o(S,f),S.uniforms.add(new l("worldToScreenPerDistanceRatio",({camera:e})=>1/e.perScreenPixelRatio)).code.add(s`float computeWorldToScreenRatio(vec3 segmentCenter) {
8
8
  float segmentDistanceToCamera = length(segmentCenter - cameraPosition);
9
9
  return worldToScreenPerDistanceRatio / segmentDistanceToCamera;
10
- }`)),n.varyings.add("vStippleDistance","float"),n.varyings.add("vStippleDistanceLimits","vec2"),n.varyings.add("vStipplePatternStretch","float"),g.code.add(a`
10
+ }`)),d.varyings.add("vStippleDistance","float"),d.varyings.add("vStippleDistanceLimits","vec2"),d.varyings.add("vStipplePatternStretch","float"),S.code.add(s`
11
11
  float discretizeWorldToScreenRatio(float worldToScreenRatio) {
12
- float step = ${a.float(u)};
12
+ float step = ${s.float(u)};
13
13
 
14
14
  float discreteWorldToScreenRatio = log(worldToScreenRatio);
15
15
  discreteWorldToScreenRatio = ceil(discreteWorldToScreenRatio / step) * step;
16
16
  discreteWorldToScreenRatio = exp(discreteWorldToScreenRatio);
17
17
  return discreteWorldToScreenRatio;
18
18
  }
19
- `),g.code.add(a`vec2 computeStippleDistanceLimits(float startPseudoScreen, float segmentLengthPseudoScreen, float segmentLengthScreen, float patternLength) {`),g.code.add(a`
20
- if (segmentLengthPseudoScreen >= ${f?"patternLength":"1e4"}) {
21
- `),o(g),g.code.add(a`float repetitions = segmentLengthScreen / (patternLength * pixelRatio);
22
- float flooredRepetitions = max(1.0, floor(repetitions + 0.5));
23
- float segmentLengthScreenRounded = flooredRepetitions * patternLength;
24
- float stretch = repetitions / flooredRepetitions;
25
- vStipplePatternStretch = max(0.75, stretch);
26
- return vec2(0.0, segmentLengthScreenRounded);
27
- }
28
- return vec2(startPseudoScreen, startPseudoScreen + segmentLengthPseudoScreen);
29
- }`),h.uniforms.add(new s("stipplePatternTexture",e=>e.stippleTexture),new l("stipplePatternSDFNormalizer",e=>m(e.stipplePattern)),new l("stipplePatternPixelSizeInv",e=>1/S(e))),d.stippleOffColorEnabled&&h.uniforms.add(new r("stippleOffColor",e=>c(e.stippleOffColor))),h.code.add(a`float getStippleSDF(out bool isClamped) {
30
- float stippleDistanceClamped = clamp(vStippleDistance, vStippleDistanceLimits.x, vStippleDistanceLimits.y);
19
+ `),i(S),S.code.add(s`
20
+ vec2 computeStippleDistanceLimits(float startPseudoScreen, float segmentLengthPseudoScreen, float segmentLengthScreen, float patternLength) {
21
+
22
+ // First check if the segment is long enough to support fully screen space patterns.
23
+ // Force sparse mode for segments that are very large in screen space even if it is not allowed,
24
+ // to avoid imprecision from calculating with large floats.
25
+ if (segmentLengthPseudoScreen >= ${g?"patternLength":"1e4"}) {
26
+ // Round the screen length to get an integer number of pattern repetitions (minimum 1).
27
+ float repetitions = segmentLengthScreen / (patternLength * pixelRatio);
28
+ float flooredRepetitions = max(1.0, floor(repetitions + 0.5));
29
+ float segmentLengthScreenRounded = flooredRepetitions * patternLength;
30
+
31
+ float stretch = repetitions / flooredRepetitions;
32
+
33
+ // We need to impose a lower bound on the stretch factor to prevent the dots from merging together when there is only 1 repetition.
34
+ // 0.75 is the lowest possible stretch value for flooredRepetitions > 1, so it makes sense as lower bound.
35
+ vStipplePatternStretch = max(0.75, stretch);
36
+
37
+ return vec2(0.0, segmentLengthScreenRounded);
38
+ }
39
+ return vec2(startPseudoScreen, startPseudoScreen + segmentLengthPseudoScreen);
40
+ }
41
+ `),h.uniforms.add(new p("stipplePatternTexture",e=>e.stippleTexture),new a("stipplePatternPixelSizeInv",e=>1/m(e))),f.stippleOffColorEnabled&&h.uniforms.add(new r("stippleOffColor",e=>c(e.stippleOffColor))),d.include(e),h.code.add(s`float getStippleSDF(out bool isClamped) {
42
+ float stippleDistanceClamped = noPerspectiveRead(clamp(vStippleDistance, vStippleDistanceLimits.x, vStippleDistanceLimits.y));
43
+ float lineSizeInv = noPerspectiveRead(vLineSizeInv);
31
44
  vec2 aaCorrectedLimits = vStippleDistanceLimits + vec2(1.0, -1.0) / gl_FragCoord.w;
32
45
  isClamped = vStippleDistance < aaCorrectedLimits.x || vStippleDistance > aaCorrectedLimits.y;
33
- float u = stippleDistanceClamped * gl_FragCoord.w * stipplePatternPixelSizeInv * vLineSizeInv;
46
+ float u = stippleDistanceClamped * stipplePatternPixelSizeInv * lineSizeInv;
34
47
  u = fract(u);
35
- float encodedSDF = rgbaTofloat(texture(stipplePatternTexture, vec2(u, 0.5)));
36
- float sdf = (encodedSDF * 2.0 - 1.0) * stipplePatternSDFNormalizer;
48
+ float sdf = texture(stipplePatternTexture, vec2(u, 0.5)).r;
37
49
  return (sdf - 0.5) * vStipplePatternStretch + 0.5;
38
50
  }
39
51
  float getStippleSDF() {
40
52
  bool ignored;
41
53
  return getStippleSDF(ignored);
42
54
  }
43
- float getStippleAlpha() {
55
+ float getStippleAlpha(float lineWidth) {
44
56
  bool isClamped;
45
57
  float stippleSDF = getStippleSDF(isClamped);
46
- float antiAliasedResult = clamp(stippleSDF * vLineWidth + 0.5, 0.0, 1.0);
58
+ float antiAliasedResult = clamp(stippleSDF * lineWidth + 0.5, 0.0, 1.0);
47
59
  return isClamped ? floor(antiAliasedResult + 0.5) : antiAliasedResult;
48
- }`),h.code.add(a`
60
+ }`),h.code.add(s`
49
61
  void discardByStippleAlpha(float stippleAlpha, float threshold) {
50
- ${p(!d.stippleOffColorEnabled,"if (stippleAlpha < threshold) { discard; }")}
62
+ ${n(!f.stippleOffColorEnabled,"if (stippleAlpha < threshold) { discard; }")}
51
63
  }
52
64
 
53
65
  vec4 blendStipple(vec4 color, float stippleAlpha) {
54
- return ${d.stippleOffColorEnabled?"mix(color, stippleOffColor, stippleAlpha)":"vec4(color.rgb, color.a * stippleAlpha)"};
66
+ return ${f.stippleOffColorEnabled?"mix(color, stippleOffColor, stippleAlpha)":"vec4(color.rgb, color.a * stippleAlpha)"};
55
67
  }
56
- `)}function m(e){return e?(Math.floor(.5*(d(e)-1))+.5)/e.pixelRatio:1}function S(e){const t=e.stipplePattern;return t?n(e.stipplePattern)/t.pixelRatio:1}const u=.4;export{f as LineStipple,S as computePixelSize};
68
+ `)}function m(e){const t=e.stipplePattern;return t?d(e.stipplePattern)/t.pixelRatio:1}const u=.4;export{f as LineStipple,m as computePixelSize};
@@ -2,21 +2,21 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{markerSizePerLineWidth as e}from"../../../../support/engineContent/marker.js";import{addPixelRatio as r}from"../util/View.glsl.js";import{FloatBindUniform as t}from"../../shaderModules/FloatBindUniform.js";import{glsl as o}from"../../shaderModules/glsl.js";function a(a,n){const i=a.vertex;r(i),null==i.uniforms.get("markerScale")&&i.constants.add("markerScale","float",1),i.constants.add("markerSizePerLineWidth","float",e).code.add(o`float getLineWidth() {
6
- return max(getSize(), 1.0) * pixelRatio;
5
+ import{markerSizePerLineWidth as e}from"../../../../support/engineContent/marker.js";import{addPixelRatio as r}from"../util/View.glsl.js";import{FloatBindUniform as t}from"../../shaderModules/FloatBindUniform.js";import{glsl as o}from"../../shaderModules/glsl.js";function a(a,i){const n=a.vertex;r(n),null==n.uniforms.get("markerScale")&&n.constants.add("markerScale","float",1),n.constants.add("markerSizePerLineWidth","float",e).code.add(o`float getLineWidth(vec3 pos) {
6
+ return max(getSize(pos), 1.0) * pixelRatio;
7
7
  }
8
- float getScreenMarkerSize() {
9
- return markerSizePerLineWidth * markerScale * getLineWidth();
10
- }`),2===n.space&&(i.constants.add("maxSegmentLengthFraction","float",.45),i.uniforms.add(new t("perRenderPixelRatio",e=>e.camera.perRenderPixelRatio)),i.code.add(o`bool areWorldMarkersHidden(vec4 pos, vec4 other) {
11
- vec3 midPoint = mix(pos.xyz, other.xyz, 0.5);
8
+ float getScreenMarkerSize(float lineWidth) {
9
+ return markerScale * markerSizePerLineWidth * lineWidth;
10
+ }`),2===i.space&&(n.constants.add("maxSegmentLengthFraction","float",.45),n.uniforms.add(new t("perRenderPixelRatio",e=>e.camera.perRenderPixelRatio)),n.code.add(o`bool areWorldMarkersHidden(vec3 pos, vec3 other) {
11
+ vec3 midPoint = mix(pos, other, 0.5);
12
12
  float distanceToCamera = length(midPoint);
13
13
  float screenToWorldRatio = perRenderPixelRatio * distanceToCamera * 0.5;
14
- float worldMarkerSize = getScreenMarkerSize() * screenToWorldRatio;
15
- float segmentLen = length(pos.xyz - other.xyz);
14
+ float worldMarkerSize = getScreenMarkerSize(getLineWidth(pos)) * screenToWorldRatio;
15
+ float segmentLen = length(pos - other);
16
16
  return worldMarkerSize > maxSegmentLengthFraction * segmentLen;
17
17
  }
18
- float getWorldMarkerSize(vec4 pos) {
19
- float distanceToCamera = length(pos.xyz);
18
+ float getWorldMarkerSize(vec3 pos) {
19
+ float distanceToCamera = length(pos);
20
20
  float screenToWorldRatio = perRenderPixelRatio * distanceToCamera * 0.5;
21
- return getScreenMarkerSize() * screenToWorldRatio;
21
+ return getScreenMarkerSize(getLineWidth(pos)) * screenToWorldRatio;
22
22
  }`))}export{a as MarkerSizing};
@@ -0,0 +1,5 @@
1
+ /*
2
+ All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
+ See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
+ */
5
+ function e(e){e.vertex.code.add("#define noPerspectiveWrite(x, w) (x * w)")}function d(e){e.fragment.code.add("#define noPerspectiveRead(x) (x * gl_FragCoord.w)")}export{d as NoPerspectiveRead,e as NoPerspectiveWrite};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import"../../core/shaderLibrary/ScreenSpacePass.glsl.js";import"../../core/shaderLibrary/shading/Gamma.glsl.js";import"../../core/shaderModules/FloatsPassUniform.js";import"../../core/shaderModules/glsl.js";import"../../core/shaderModules/IntegerPassUniform.js";import"../../core/shaderModules/Texture2DPassUniform.js";import"../../shaders/ToneMapping.glsl.js";import"../../../../webgl/NoParameters.js";import"../../../../webgl/ShaderBuilder.js";export{G as GlowCompositionPassParameters,b as build}from"../../../../../chunks/GlowComposition.glsl.js";
5
+ import"../../core/shaderLibrary/output/ReadDepth.glsl.js";import"../../core/shaderLibrary/shading/Gamma.glsl.js";import"../../core/shaderModules/FloatPassUniform.js";import"../../core/shaderModules/FloatsPassUniform.js";import"../../core/shaderModules/glsl.js";import"../../core/shaderModules/IntegerPassUniform.js";import"../../core/shaderModules/Texture2DBindUniform.js";import"../../core/shaderModules/Texture2DPassUniform.js";import"./GlowPresets.glsl.js";import"../raymarching/RayDistanceFalloff.glsl.js";import"../../shaders/ScreenSpacePassAtmosphere.glsl.js";import"../../shaders/ToneMapping.glsl.js";import"../../../../webgl/ShaderBuilder.js";export{G as GlowCompositionPassParameters,b as build}from"../../../../../chunks/GlowComposition.glsl.js";
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- const n=2.6,s={sunny:.0022,rainy:.0022,cloudy:.0022,snowy:.0042,foggy:.0042};class t{constructor(n){this.presets=n,this.presets=c(n)}}const o={sunny:new t([2.1,.8,.6,.4,.2,.1]),foggy:new t([0,0,.06,.12,.25,.57])};function c(n,s=1){const t=n[0]+n[1]+n[2]+n[3]+n[4]+n[5];return t<=s?n:[n[0]/t,n[1]/t,n[2]/t,n[3]/t,n[4]/t,n[5]/t]}export{s as blurRadiusPresets,n as defaultExposure,o as lodFactorsPresets,c as normalizePreset};
5
+ const s=2.6,n={sunny:.0022,rainy:.0022,cloudy:.0022,snowy:.0022,foggy:.0022};class e{constructor(s){this.presets=s,this.presets=o(s)}}const t={minDisperse:new e([.8,.12,.06,.02,0,0]),maxDisperse:new e([0,0,.06,.12,.25,.57])};function o(s,n=1){const e=s[0]+s[1]+s[2]+s[3]+s[4]+s[5];return e<=n?s:[s[0]/e,s[1]/e,s[2]/e,s[3]/e,s[4]/e,s[5]/e]}export{n as blurRadiusPresets,s as defaultExposure,t as lodFactorsPresets,o as normalizePreset};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{lerp as t}from"../../../../../core/mathUtils.js";import{watch as i,syncAndInitial as r}from"../../../../../core/reactiveUtils.js";import{property as o}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as s}from"../../../../../core/accessorSupport/decorators/subclass.js";import{ZEROS as a}from"../../../../../core/libs/gl-matrix-2/factories/vec4f32.js";import{InternalRenderCategory as n}from"../../../webgl.js";import{TransparentEnvironment as l}from"../TransparentEnvironment.js";import{G as c}from"../../../../../chunks/GlowBlur.glsl.js";import{GlowBlurTechnique as h}from"./GlowBlurTechnique.js";import{GlowBlurTechniqueConfiguration as u}from"./GlowBlurTechniqueConfiguration.js";import{G as m}from"../../../../../chunks/GlowComposition.glsl.js";import{GlowCompositionTechnique as p}from"./GlowCompositionTechnique.js";import{GlowCompositionTechniqueConfiguration as d}from"./GlowCompositionTechniqueConfiguration.js";import{blurRadiusPresets as g,lodFactorsPresets as _,normalizePreset as b}from"./GlowPresets.glsl.js";import{ColorAttachment1 as f,DepthStencilAttachment as w}from"../../../../webgl/enums.js";let P=class extends l{constructor(e){super(e),this.consumes={required:[n.TRANSPARENT_ENVIRONMENT,"emissive"]},this.produces=n.TRANSPARENT_ENVIRONMENT,this._blurHorizontalConfiguration=new u,this._blurVerticalConfiguration=new u,this._compositionConfiguration=new d,this._compositionParameters=new m,this._blurParameters=new c,this._blurScale=3.06,this._blurLodCombination=0,this._glowEnabled=!1,this._glowResults=new Array;e.view.stage.renderView.techniques.precompile(p,this._compositionConfiguration)}initialize(){this.addHandles([i(()=>this._updateFogParameters(),()=>{},r),i(()=>this.view.qualitySettings.glow,e=>{this._glowEnabled=e,this.precompile(),this.requestRender(1)},r)])}_updateFogParameters(){const e=this.view.environment.weather;if("sunny"===e.type||"cloudy"===e.type)this._blurParameters.blurRadius=g[e.type];else{const i="foggy"===e.type?e.fogStrength:e.precipitation;this._blurParameters.blurRadius=t(g.cloudy,g[e.type],i)}this._computeLodFactors(),this.requestRender(1)}_computeLodFactors(e=_.sunny.presets,i=_.foggy.presets){e.forEach((e,r)=>{this._compositionParameters.lodFactors[r]=t(e,i[r],this._blurLodCombination)})}precompile(){this._glowEnabled&&(this.techniques.precompile(h,this._blurHorizontalConfiguration),this._blurVerticalConfiguration.glowStage=1,this.techniques.precompile(h,this._blurVerticalConfiguration)),this._compositionConfiguration.blurEnabled=this._glowEnabled,this.techniques.precompile(p,this._compositionConfiguration)}render(e){const t=e.find(({name:e})=>e===n.TRANSPARENT_ENVIRONMENT),i=t.getAttachment(f)?.attachment;if(!i)return t;const r=t.getAttachment(w);if(!this._glowEnabled){const e=this.techniques.get(p,this._compositionConfiguration);if(!e.compiled)return this.requestRender(1),t;const o=t.getTexture(),s=this.fboCache,{fullWidth:a,fullHeight:n}=this.bindParameters.camera,l=this.renderingContext,c=s.acquire(o.descriptor.width,o.descriptor.height,this.produces);return this._prepareFBO(c,a,n),this._compositionParameters.color=o,this._compositionParameters.emission=i,l.bindTechnique(e,this.bindParameters,this._compositionParameters),l.screen.draw(),c.attachDepth(r),c.attachColor(t.getAttachment(f),f),c}const o=this.techniques.get(h,this._blurHorizontalConfiguration),s=this.techniques.get(h,this._blurVerticalConfiguration),a=this.techniques.get(p,this._compositionConfiguration);if(!o.compiled||!s.compiled||!a.compiled)return this.requestRender(1),t;const l=t.getTexture(),c=this.fboCache,{fullWidth:u,fullHeight:m}=this.bindParameters.camera,d=this.renderingContext;let g=i,_=Math.ceil(u/2),b=Math.ceil(m/2);const P=5,C=this._blurParameters.blurRadius;for(let n=0;n<P;n++){const e=c.acquire(_,b,"glow horizontal",8);this._blurParameters.color=g,this._prepareFBO(e,_,b),d.bindTechnique(o,this.bindParameters,this._blurParameters),d.screen.draw();const t=c.acquire(_,b,"glow vertical",8);this._blurParameters.color=e.getTexture(),this._prepareFBO(t,_,b),d.bindTechnique(s,this.bindParameters,this._blurParameters),d.screen.draw(),e.release(),this._glowResults[n]=t,_=Math.ceil(_/2),b=Math.ceil(b/2),g=this._glowResults[n].getTexture(),this._blurParameters.blurRadius*=this._blurScale}this._blurParameters.blurRadius=C,this._compositionParameters.color=l,this._compositionParameters.emission=i,this._compositionParameters.lodTexture0=this._glowResults[0].getTexture(),this._compositionParameters.lodTexture1=this._glowResults[1].getTexture(),this._compositionParameters.lodTexture2=this._glowResults[2].getTexture(),this._compositionParameters.lodTexture3=this._glowResults[3].getTexture(),this._compositionParameters.lodTexture4=this._glowResults[4].getTexture();const T=c.acquire(l.descriptor.width,l.descriptor.height,this.produces);return T.acquireColor(f,8,"emissive glow"),this._prepareFBO(T,u,m,!0),d.bindTechnique(a,this.bindParameters,this._compositionParameters),d.screen.draw(),this._glowResults.forEach(e=>e.release()),T.attachDepth(r),T}_prepareFBO(e,t,i,r=!1){const o=this.renderingContext;o.bindFramebuffer(e.fbo),o.setViewport(0,0,t,i),o.setClearColor(0,0,0,0),o.clear(16384),r&&o.clearBuffer(1,a)}get test(){return{compositionParameters:this._compositionParameters,blurParameters:this._blurParameters,setBlurLodCombination:e=>{this._blurLodCombination=e,this._computeLodFactors()},setLodFactors:e=>{this._computeLodFactors(b(e))},toggleTonemapping:e=>{this._compositionConfiguration.tonemappingEnabled=e,this.requestRender(1)}}}};e([o()],P.prototype,"consumes",void 0),e([o()],P.prototype,"produces",void 0),P=e([s("esri.views.3d.webgl-engine.effects.glow.GlowRenderNode")],P);export{P as GlowRenderNode};
5
+ import{__decorate as e}from"tslib";import{lerp as t}from"../../../../../core/mathUtils.js";import{watch as i,syncAndInitial as r}from"../../../../../core/reactiveUtils.js";import{property as s}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as o}from"../../../../../core/accessorSupport/decorators/subclass.js";import{l as a}from"../../../../../chunks/vec32.js";import{ZEROS as n}from"../../../../../core/libs/gl-matrix-2/factories/vec4f32.js";import{getReferenceEllipsoid as c}from"../../../../../geometry/ellipsoidUtils.js";import{InternalRenderCategory as h}from"../../../webgl.js";import{TransparentEnvironment as l}from"../TransparentEnvironment.js";import{G as m}from"../../../../../chunks/GlowBlur.glsl.js";import{GlowBlurTechnique as u}from"./GlowBlurTechnique.js";import{GlowBlurTechniqueConfiguration as p}from"./GlowBlurTechniqueConfiguration.js";import{G as d}from"../../../../../chunks/GlowComposition.glsl.js";import{GlowCompositionTechnique as g}from"./GlowCompositionTechnique.js";import{GlowCompositionTechniqueConfiguration as _}from"./GlowCompositionTechniqueConfiguration.js";import{blurRadiusPresets as f,lodFactorsPresets as b,normalizePreset as w}from"./GlowPresets.glsl.js";import{ColorAttachment1 as P,DepthStencilAttachment as R}from"../../../../webgl/enums.js";let T=class extends l{constructor(e){super(e),this.consumes={required:[h.TRANSPARENT_ENVIRONMENT,"emissive"]},this.produces=h.TRANSPARENT_ENVIRONMENT,this._blurHorizontalConfiguration=new p,this._blurVerticalConfiguration=new p,this._compositionConfiguration=new _,this._compositionParameters=new d,this._blurParameters=new m,this._blurScale=3.06,this._glowEnabled=!1,this._glowResults=new Array;const t=c(e.view.spatialReference);this._atmosphereRadius=t.radius+t.atmosphereHeight;e.view.stage.renderView.techniques.precompile(g,this._compositionConfiguration)}initialize(){this.addHandles([i(()=>this._updateFogParameters(),()=>{},r),i(()=>this.view.qualitySettings.glow,e=>{this._glowEnabled=e,this.precompile(),this.requestRender(1)},r)])}_updateFogParameters(){const e=this.view.environment.weather;if("sunny"===e.type||"cloudy"===e.type)this._blurParameters.blurRadius=f[e.type],this._compositionParameters.distanceModifier=0;else{const i="foggy"===e.type?e.fogStrength:e.precipitation;this._blurParameters.blurRadius=t(f.cloudy,f[e.type],i),this._compositionParameters.distanceModifier="foggy"===e.type?t(3e-5,.005,e.fogStrength**3):t(4e-6,2e-4,(e.precipitation??0)**3)}this._computeLodFactors(),this.requestRender(1)}_computeLodFactors(e=b.minDisperse.presets,i=b.maxDisperse.presets){e.forEach((e,r)=>{this._compositionParameters.lodFactors[r]=t(e,i[r],this._compositionParameters.dispersionWeight)})}precompile(){this._glowEnabled&&(this.techniques.precompile(u,this._blurHorizontalConfiguration),this._blurVerticalConfiguration.glowStage=1,this.techniques.precompile(u,this._blurVerticalConfiguration)),this._compositionConfiguration.blurEnabled=this._glowEnabled,this.techniques.precompile(g,this._compositionConfiguration)}render(e){const t=e.find(({name:e})=>e===h.TRANSPARENT_ENVIRONMENT),i=t.getAttachment(P)?.attachment;if(!i)return t;const r=t.getAttachment(R);if(!this._glowEnabled){const e=this.techniques.get(g,this._compositionConfiguration);if(!e.compiled)return this.requestRender(1),t;const s=t.getTexture(),o=this.fboCache,{fullWidth:a,fullHeight:n}=this.bindParameters.camera,c=this.renderingContext,h=o.acquire(s.descriptor.width,s.descriptor.height,this.produces);return this._prepareFBO(h,a,n),this._compositionParameters.color=s,this._compositionParameters.emission=i,c.bindTechnique(e,this.bindParameters,this._compositionParameters),c.screen.draw(),h.attachDepth(r),h.attachColor(t.getAttachment(P),P),h}const s=this.techniques.get(u,this._blurHorizontalConfiguration),o=this.techniques.get(u,this._blurVerticalConfiguration),n=this.techniques.get(g,this._compositionConfiguration);if(!s.compiled||!o.compiled||!n.compiled)return this.requestRender(1),t;const c=t.getTexture(),l=this.fboCache,{fullWidth:m,fullHeight:p}=this.bindParameters.camera,d=this.renderingContext;let _=i,f=Math.ceil(m/2),b=Math.ceil(p/2);const w=5,T=this._blurParameters.blurRadius;for(let a=0;a<w;a++){const e=l.acquire(f,b,"glow horizontal",8);this._blurParameters.color=_,this._prepareFBO(e,f,b),d.bindTechnique(s,this.bindParameters,this._blurParameters),d.screen.draw();const t=l.acquire(f,b,"glow vertical",8);this._blurParameters.color=e.getTexture(),this._prepareFBO(t,f,b),d.bindTechnique(o,this.bindParameters,this._blurParameters),d.screen.draw(),e.release(),this._glowResults[a]=t,f=Math.ceil(f/2),b=Math.ceil(b/2),_=this._glowResults[a].getTexture(),this._blurParameters.blurRadius*=this._blurScale}this._blurParameters.blurRadius=T;const C=this.bindParameters.camera,q=a(C.eye);this._compositionParameters.atmosphereC=q**2-this._atmosphereRadius**2,this._compositionParameters.color=c,this._compositionParameters.emission=i,this._compositionParameters.lodTexture0=this._glowResults[0].getTexture(),this._compositionParameters.lodTexture1=this._glowResults[1].getTexture(),this._compositionParameters.lodTexture2=this._glowResults[2].getTexture(),this._compositionParameters.lodTexture3=this._glowResults[3].getTexture(),this._compositionParameters.lodTexture4=this._glowResults[4].getTexture();const x=l.acquire(c.descriptor.width,c.descriptor.height,this.produces);return x.acquireColor(P,8,"emissive glow"),this._prepareFBO(x,m,p,!0),d.bindTechnique(n,this.bindParameters,this._compositionParameters),d.screen.draw(),this._glowResults.forEach(e=>e.release()),x.attachDepth(r),x}_prepareFBO(e,t,i,r=!1){const s=this.renderingContext;s.bindFramebuffer(e.fbo),s.setViewport(0,0,t,i),s.setClearColor(0,0,0,0),s.clear(16384),r&&s.clearBuffer(1,n)}get test(){return{compositionParameters:this._compositionParameters,blurParameters:this._blurParameters,setBlurLodCombination:e=>{this._compositionParameters.dispersionWeight=e,this._computeLodFactors()},setLodFactors:e=>{this._computeLodFactors(w(e))},toggleTonemapping:e=>{this._compositionConfiguration.tonemappingEnabled=e,this.requestRender(1)}}}};e([s()],T.prototype,"consumes",void 0),e([s()],T.prototype,"produces",void 0),T=e([o("esri.views.3d.webgl-engine.effects.glow.GlowRenderNode")],T);export{T as GlowRenderNode};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{C as i}from"../../../../chunks/Compositing.glsl.js";import{CompositingTechnique as t}from"../shaders/CompositingTechnique.js";import{CompositingTechniqueConfiguration as s}from"../shaders/CompositingTechniqueConfiguration.js";import{H as e}from"../../../../chunks/HUDCompositing.glsl.js";import{HUDCompositingTechnique as o}from"../shaders/HUDCompositingTechnique.js";class r{constructor(r,h){this._rctx=r,this._techniques=h,this._configuration=new s,this._passParameters=new i,this._hudParameters=new e,this._configuration.blitMode=2,this._techniques.precompile(t,this._configuration),this._configuration.hasOpacityFactor=!0,this._techniques.precompile(t,this._configuration),this._configuration.hasOpacityFactor=!1,this._configuration.blitMode=1,this._techniques.precompile(t,this._configuration),this._configuration.blitMode=3,this._techniques.precompile(t,this._configuration),this._techniques.precompile(o)}compositeHUD(i,t){this._hudParameters.texture=t;const s=this._techniques.get(o);this._rctx.bindTechnique(s,i,this._hudParameters),this._rctx.screen.draw()}compositePreMultipliedAlpha(i,t,s=1){this._composite(i,t,2,s)}composite(i,t){this._composite(i,t,1,1)}blitDepthToLinearDepth(i,t){this._composite(i,t,3,1)}_composite(i,s,e,o){this._configuration.blitMode=e,this._configuration.hasOpacityFactor=1!==o,this._passParameters.texture=s,this._passParameters.opacity=o;const r=this._techniques.get(t,this._configuration);this._rctx.bindTechnique(r,i,this._passParameters),this._rctx.screen.draw()}}export{r as default};
5
+ import{C as i}from"../../../../chunks/Compositing.glsl.js";import{CompositingTechnique as t}from"../shaders/CompositingTechnique.js";import{CompositingTechniqueConfiguration as s}from"../shaders/CompositingTechniqueConfiguration.js";import{H as e}from"../../../../chunks/HUDCompositing.glsl.js";import{HUDCompositingTechnique as o}from"../shaders/HUDCompositingTechnique.js";class r{constructor(r,h){this._rctx=r,this._techniques=h,this._configuration=new s,this._passParameters=new i,this._hudParameters=new e,this._configuration.blitMode=2,this._techniques.precompile(t,this._configuration),this._configuration.hasOpacityFactor=!0,this._techniques.precompile(t,this._configuration),this._configuration.hasOpacityFactor=!1,this._configuration.blitMode=1,this._techniques.precompile(t,this._configuration),this._configuration.blitEmissiveMode=1,this._techniques.precompile(t,this._configuration),this._configuration.blitEmissiveMode=0,this._configuration.blitMode=3,this._techniques.precompile(t,this._configuration),this._techniques.precompile(o)}compositeHUD(i,t){this._hudParameters.texture=t;const s=this._techniques.get(o);this._rctx.bindTechnique(s,i,this._hudParameters),this._rctx.screen.draw()}compositePreMultipliedAlpha(i,t,s=1){this._composite(i,t,2,s)}composite(i,t,s){this._composite(i,t,1,1,s)}blitDepthToLinearDepth(i,t){this._composite(i,t,3,1)}_composite(i,s,e,o,r=0){this._configuration.blitMode=e,this._configuration.hasOpacityFactor=1!==o,this._configuration.blitEmissiveMode=r,this._passParameters.texture=s,this._passParameters.opacity=o;const h=this._techniques.get(t,this._configuration);this._rctx.bindTechnique(h,i,this._passParameters),this._rctx.screen.draw()}}export{r as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import{reallocGrowthFactor as e}from"../../../../core/arrayUtils.js";import s from"../../../../core/PooledArray.js";import{watch as i}from"../../../../core/reactiveUtils.js";import"../../../../core/Logger.js";import"../../../../core/has.js";import"../../../../core/Error.js";import{subclass as r}from"../../../../core/accessorSupport/decorators/subclass.js";import{set as a}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as o,fromValues as n}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{d as l,l as h,g as u,u as c,e as p,k as m,J as d,c as _}from"../../../../chunks/vec32.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as g}from"../../../../chunks/vec42.js";import{create as b}from"../../../../geometry/support/aaBoundingBox.js";import{create as x}from"../../../../geometry/support/plane.js";import{fromPoints as T}from"../../../../geometry/support/ray.js";import{initialSplatAtlasTextureHeight as A,GaussianSplatAtlasPageAllocator as C,elementsPerSplatPage as w,splatAtlasTextureWidth as S}from"../../../../layers/support/GaussianSplatAtlasPageAllocator.js";import{GaussianSplatHit as y,isValidPointHit as P,maxAllowedVisibleGaussians as j,nodeToPosition as q}from"../../../../layers/support/gaussianSplatUtils.js";import"../../../webgl/BufferObject.js";import{FramebufferObject as v}from"../../../webgl/FramebufferObject.js";import"../../../webgl/Program.js";import"../../../webgl/Renderbuffer.js";import{Texture as G}from"../../../webgl/Texture.js";import{DepthStencilAttachment as D,PrimitiveType as I,PixelType as k,SizedPixelFormat as V}from"../../../webgl/enums.js";import"../../../webgl/checkWebGLError.js";import{RenderCategory as H}from"../../webgl.js";import{GaussianSplatTarget as M}from"../../layers/i3s/Intersector.js";import{makeScheduleFunction as U}from"../../layers/support/makeScheduleFunction.js";import{GaussianSplatSortWorkerHandle as B}from"../../support/GaussianSplatWorkerHandle.js";import F from"../../webgl/RenderNode.js";import{IntersectorResult as R}from"./IntersectorResult.js";import{G as E}from"../../../../chunks/GaussianSplat.glsl.js";import{G as O}from"../../../../chunks/GaussianSplatComposition.glsl.js";import{GaussianSplatCompositionTechnique as N}from"../shaders/GaussianSplatCompositionTechnique.js";import{G as z}from"../../../../chunks/GaussianSplatDepthComposition.glsl.js";import{GaussianSplatDepthCompositionTechnique as W}from"../shaders/GaussianSplatDepthCompositionTechnique.js";import{GaussianSplatDepthTechnique as L}from"../shaders/GaussianSplatDepthTechnique.js";import{GaussianSplatTechnique as Q}from"../shaders/GaussianSplatTechnique.js";import{GaussianSplatTechniqueConfiguration as J}from"../shaders/GaussianSplatTechniqueConfiguration.js";import{TextureDescriptor as Y}from"../../../webgl/TextureDescriptor.js";var K;let X=class extends F{static{K=this}static{this.tileSize=2.048}constructor(t){super(t),this.produces=H.OPAQUE,this.type=0,this.isGround=!1,this.layerViewUid="",this._gaussianSplatParameters=new E,this._gaussianSplatCompositionParameters=new O,this._gaussianSplatDepthCompositionParameters=new z,this._splatDepthTechniqueConfiguration=new J(!0),this._totalVisibleGaussians=0,this._orderTexture=null,this._textureAtlas=null,this._splatAtlasTextureHeight=A,this._visibleGaussianTiles=new s,this._workerHandle=null,this._isSorting=!1,this._pendingSortTask=!1,this._bufferCapacity=0,this._orderTextureCapacity=0,this._previousCameraPosition=f(),this._previousCameraDirection=f(),this._tanFov=o(),this._tempVec=f(),this._cameraDelta=f(),this._coarseCameraPosition=f(),this.point=f(),this.rayDir=f(),this.dirPlane=x(),this.tileBox=b(),this._slicePlaneEnabled=!1,this._cache=t.view.resourceController.memoryController.newCache("gaussian texture cache",t=>t.dispose()),this.pageAllocator=new C}async initialize(){this.view.sceneIntersectionHelper.addIntersectionHandler(this),this._ensureTextureAtlas(),this.addHandles([i(()=>this.view.state.camera,()=>this._onCameraChange())]);const{resourceController:t}=this.view;this._workerHandle=new B(U(t))}precompile(){this.techniques.precompile(Q),this.techniques.precompile(L,this._splatDepthTechniqueConfiguration),this.techniques.precompile(N),this.techniques.precompile(W)}render(t){const e=t.find(({name:t})=>t===H.OPAQUE),s=this.techniques.get(Q),i=this.techniques.get(L,this._splatDepthTechniqueConfiguration),r=this.techniques.get(N),o=this.techniques.get(W);if(!(s.compiled&&i.compiled&&o.compiled&&r.compiled))return this.requestRender(1),e;const{fullWidth:n,fullHeight:l}=this.bindParameters.camera,h=this.fboCache,u=h.acquire(n,l,"gaussian color output");u.attachDepth(e.getAttachment(D));const c=this.renderingContext;c.bindFramebuffer(u.fbo),c.setClearColor(0,0,0,0),c.clear(16384),this._gaussianSplatParameters.totalGaussians=this._totalVisibleGaussians,this._gaussianSplatParameters.splatOrder=this._orderTexture,this._gaussianSplatParameters.splatAtlas=this._textureAtlas;const p=Math.tan(.5*this.camera.fovY),m=p/l*n;a(this._tanFov,m,p);const d=l/(2*p);this._gaussianSplatParameters.focalLength=d,this._gaussianSplatParameters.tanFov=this._tanFov,this._prepareHighPrecisionCameraPosition(),this.renderingContext.bindTechnique(s,this.bindParameters,this._gaussianSplatParameters),this.renderingContext.drawArraysInstanced(I.TRIANGLE_STRIP,0,4,this._totalVisibleGaussians);const _=h.acquire(n,l,"splat depth",8);_.attachDepth(e.getAttachment(D)),c.bindFramebuffer(_.fbo),c.setClearColor(0,0,0,0),c.clear(16384),this.renderingContext.bindTechnique(i,this.bindParameters,this._gaussianSplatParameters),this.renderingContext.drawArraysInstanced(I.TRIANGLE_STRIP,0,4,this._totalVisibleGaussians);const f=h.acquire(n,l,this.produces);return this._gaussianSplatDepthCompositionParameters.splatDepth=_.getTexture(),f.attachDepth(e.getAttachment(D)),c.bindFramebuffer(f.fbo),c.bindTechnique(o,this.bindParameters,this._gaussianSplatDepthCompositionParameters),c.screen.draw(),this._gaussianSplatCompositionParameters.color=e.getTexture(),this._gaussianSplatCompositionParameters.splatColor=u.getTexture(),c.bindFramebuffer(f.fbo),c.bindTechnique(r,this.bindParameters,this._gaussianSplatCompositionParameters),c.screen.draw(),u.release(),_.release(),f}updateGaussianVisibility(t){this._visibleGaussianTiles=t,this._requestSort()}intersect(t,e,s,i){const r=f(),a=this.point,o=this.rayDir,n=this.dirPlane,d=this.layerViewUid;l(o,i,s);const _=1/h(o);u(o,o,_),c(r,o),g(n,o[0],o[1],o[2],-p(o,s));const b=new y,x=new y,A=new Array;this._visibleGaussianTiles.forAll(l=>{if(!l.obb.intersectRay(s,o,l.maxScale))return;const h=l.obb.minimumDistancePlane(n),u=l.obb.maximumDistancePlane(n),c=u<0,f=null!=b.dist&&null!=x.dist&&b.dist<h*_&&x.dist>u*_;if(c||f)return;const g=l.gaussianAtlasIndices.length,T=l.positions,C=l.squaredScales;for(let n=0;n<g;n++){const h=3*n;a[0]=T[h]-s[0],a[1]=T[h+1]-s[1],a[2]=T[h+2]-s[2];const u=C[n],c=p(a,o);if(m(a)-c*c>u)continue;const f=c*_,g=t=>(t.point=q(l,n,t.point),t.dist=f,t.normal=r,t.tile=l,t.pointId=n,t.layerViewUid=d,t);if((null==b.dist||f<b.dist)&&(null==e||e(s,i,f))&&g(b),0!==t.options.store&&(null==x.dist||f>x.dist)&&(null==e||e(s,i,f))&&g(x),2===t.options.store&&(null==e||e(s,i,f))){const t=new y;A.push(g(t))}}});const C=t=>{const{layerViewUid:e}=t;return new M(t.point,e)},w=(t,e)=>{const s=C(e);t.set(this.type,s,e.dist,e.normal)};if(P(b)){const e=t.results.min;(null==e.distance||b.dist<e.distance)&&w(e,b)}if(P(x)&&0!==t.options.store){const e=t.results.max;(null==e.distance||x.dist>e.distance)&&w(e,x)}if(2===t.options.store){const e=T(s,i);for(const s of A){const i=new R(e);w(i,s),t.results.all.push(i)}}}get slicePlaneEnabled(){return this._slicePlaneEnabled}set slicePlaneEnabled(t){this._slicePlaneEnabled!==t&&(this._slicePlaneEnabled=t,this.requestRender(1))}destroy(){this._workerHandle?.destroyWorkerAndSelf(),this._textureAtlas?.dispose(),this._orderTexture?.dispose(),super.destroy()}updateTextureAtlas(t,e,s){this._ensureTextureAtlas(),this._textureAtlas.updateData(0,t,e,w,1,s)}growTextureAtlas(){if(!this._textureAtlas)return void this._ensureTextureAtlas();const t=Math.floor(this._splatAtlasTextureHeight*e),s=new v(this.renderingContext,this._textureAtlas),i=this.fboCache.acquire(S,t,"gaussian splat atlas resize",11);this.renderingContext.blitFramebuffer(s,i.fbo,16384,9728,0,0,S,this._splatAtlasTextureHeight,0,0,S,this._splatAtlasTextureHeight),this._textureAtlas?.dispose(),this._textureAtlas=i.fbo?.detachColorTexture(),i.dispose(),this._splatAtlasTextureHeight=t,this._updatePageAllocator()}_clearBuffersAndTextures(){this._bufferCapacity=0,this._orderTextureCapacity=0,this._orderTexture?.dispose(),this._orderTexture=null,this._textureAtlas&&(this._cache.put("splatTextureAtlas",this._textureAtlas),this._textureAtlas=null)}_ensureBufferCapacity(t){if(this._bufferCapacity<t){const s=Math.ceil(t*e);this._atlasIndicesBuffer=new Uint32Array(s),this._sortedAtlasIndicesBuffer=new Uint32Array(s),this._bufferCapacity=s}}_ensureOrderTextureCapacity(t){if(this._orderTextureCapacity<t){this._orderTexture?.dispose();const s=Z(Math.ceil(t*e)),i=s[0]*s[1];this._orderBuffer=new Uint32Array(i);const r=new Y;r.height=s[0],r.width=s[1],r.pixelFormat=36244,r.dataType=k.UNSIGNED_INT,r.internalFormat=V.R32UI,r.wrapMode=33071,r.samplingMode=9728,this._orderTexture=new G(this.renderingContext,r),this._orderTextureCapacity=i}}_ensureTextureAtlas(){if(this._textureAtlas)return;const t=this._cache.pop("splatTextureAtlas");if(t)return void(this._textureAtlas=t);const e=new Y;e.height=this._splatAtlasTextureHeight,e.width=S,e.pixelFormat=36249,e.dataType=k.UNSIGNED_INT,e.internalFormat=V.RGBA32UI,e.samplingMode=9728,e.wrapMode=33071,this._textureAtlas=new G(this.renderingContext,e),this._updatePageAllocator()}_updatePageAllocator(){const t=S*this._splatAtlasTextureHeight/w;this.pageAllocator.pageCount!==t&&this.pageAllocator.resize(t)}_onCameraChange(){const t=this.view.state.camera.eye,e=this.view.state.camera.ray.direction,s=.001;(Math.abs(t[0]-this._previousCameraPosition[0])>s||Math.abs(t[1]-this._previousCameraPosition[1])>s||Math.abs(t[2]-this._previousCameraPosition[2])>s||Math.abs(e[0]-this._previousCameraDirection[0])>s||Math.abs(e[1]-this._previousCameraDirection[1])>s||Math.abs(e[2]-this._previousCameraDirection[2])>s)&&this._requestSort()}_prepareHighPrecisionCameraPosition(){u(this._tempVec,this.camera.eye,1/K.tileSize),d(this._tempVec,this._tempVec),_(this._coarseCameraPosition,this._tempVec),this._gaussianSplatParameters.cameraPos8k=this._coarseCameraPosition,u(this._tempVec,this._tempVec,K.tileSize),l(this._cameraDelta,this.camera.eye,this._tempVec),this._gaussianSplatParameters.cameraDelta=this._cameraDelta}_requestSort(){this._isSorting?this._pendingSortTask=!0:(this._isSorting=!0,this._pendingSortTask=!1,this._sortOnWorker().then(()=>{this._isSorting=!1,this._pendingSortTask&&this._requestSort()}).catch(()=>{this._isSorting=!1,this._pendingSortTask&&this._requestSort()}))}async _sortOnWorker(){let t=0;if(this._visibleGaussianTiles.forAll(e=>t+=e.gaussianAtlasIndices.length),0===t||t>j)return this._totalVisibleGaussians=0,this._clearBuffersAndTextures(),void this.requestRender(1);this._ensureBufferCapacity(t),this._ensureTextureAtlas();const e=this.camera.ray.direction,s=e[0],i=e[1],r=e[2],a=1/Math.sqrt(s*s+i*i+r*r),o=s*a,n=i*a,l=r*a,h=this._atlasIndicesBuffer.subarray(0,t),u=new Float64Array(t);let c=0;this._visibleGaussianTiles.forAll(t=>{const e=t.gaussianAtlasIndices,s=t.positions;for(let i=0;i<e.length;i++){h[c]=e[i];const t=3*i,r=s[t],a=s[t+1],p=s[t+2];u[c]=r*o+a*n+p*l,c++}});const p=new Uint32Array(t);for(let d=0;d<t;d++)p[d]=d;const m={distances:u,sortOrderIndices:p};await(this._workerHandle?.sort(m).then(e=>{const s=this._sortedAtlasIndicesBuffer.subarray(0,t);for(let i=0;i<t;i++)s[i]=h[e.sortedOrderIndices[i]];this._ensureOrderTextureCapacity(t),this._orderBuffer?.set(s),this._orderTexture?.setData(this._orderBuffer),this._totalVisibleGaussians=t,this.requestRender(1)}))}};function Z(t){const e=Math.ceil(Math.sqrt(t)),s=Math.ceil(t/e);return n(e,s)}X=K=t([r("esri.views.3d.webgl-engine.lib.GaussianSplatRenderNode")],X);export{X as GaussianSplatRenderNode};
5
+ import{__decorate as t}from"tslib";import{watch as s}from"../../../../core/reactiveUtils.js";import"../../../../core/Logger.js";import"../../../../core/has.js";import"../../../../core/RandomLCG.js";import"../../../../core/Error.js";import{subclass as e}from"../../../../core/accessorSupport/decorators/subclass.js";import{set as i}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{d as r,l as n,g as o,u as h,e as l,k as c,J as m,c as p}from"../../../../chunks/vec32.js";import{create as u,clone as d}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{s as g}from"../../../../chunks/vec42.js";import{create as f}from"../../../../geometry/support/plane.js";import{fromPoints as _}from"../../../../geometry/support/ray.js";import{j as b,i as P}from"../../../../chunks/sphere.js";import{RenderCategory as C}from"../../webgl.js";import{GaussianSplatTarget as S}from"../../layers/i3s/Intersector.js";import{GaussianSplatDataStore as j}from"../../support/gaussianSplatting/GaussianSplatDataStore.js";import v from"../../webgl/RenderNode.js";import{IntersectorResult as w}from"./IntersectorResult.js";import{G as q}from"../../../../chunks/GaussianSplat.glsl.js";import{G as D}from"../../../../chunks/GaussianSplatComposition.glsl.js";import{GaussianSplatCompositionTechnique as y}from"../shaders/GaussianSplatCompositionTechnique.js";import{G}from"../../../../chunks/GaussianSplatDepthComposition.glsl.js";import{GaussianSplatDepthCompositionTechnique as T}from"../shaders/GaussianSplatDepthCompositionTechnique.js";import{GaussianSplatDepthTechnique as x}from"../shaders/GaussianSplatDepthTechnique.js";import{GaussianSplatTechnique as A}from"../shaders/GaussianSplatTechnique.js";import{GaussianSplatTechniqueConfiguration as R}from"../shaders/GaussianSplatTechniqueConfiguration.js";import{DepthStencilAttachment as V,PrimitiveType as E}from"../../../webgl/enums.js";var I;let k=class extends v{constructor(){super(...arguments),this.gaussianPosition=u(),this.intersectionRayDir=u(),this.intersectionPlane=f(),this._slicePlaneEnabled=!1,this._data=null,this.produces=C.OPAQUE,this.type=0,this.isGround=!1,this.layerViewUid="",this._gaussianSplatParameters=new q,this._gaussianSplatCompositionParameters=new D,this._gaussianSplatDepthCompositionParameters=new G,this._splatDepthTechniqueConfiguration=new R(!0),this._previousCameraPosition=u(),this._previousCameraDirection=u(),this._tanFov=a(),this._tempVec=u(),this._cameraDelta=u(),this._coarseCameraPosition=u()}static{I=this}async initialize(){this._data=new j(this),this.view.sceneIntersectionHelper.addIntersectionHandler(this),this.addHandles([s(()=>this.view.state.camera,()=>this._onCameraChange())])}precompile(){this.techniques.precompile(A),this.techniques.precompile(x,this._splatDepthTechniqueConfiguration),this.techniques.precompile(y),this.techniques.precompile(T)}render(t){const s=t.find(({name:t})=>t===C.OPAQUE),e=this.techniques.get(A),a=this.techniques.get(x,this._splatDepthTechniqueConfiguration),r=this.techniques.get(y),n=this.techniques.get(T);if(!(e.compiled&&a.compiled&&n.compiled&&r.compiled))return this.requestRender(1),s;const{fullWidth:o,fullHeight:h}=this.bindParameters.camera,l=this.fboCache,c=l.acquire(o,h,"gaussian color output");c.attachDepth(s.getAttachment(V));const m=this.renderingContext;m.bindFramebuffer(c.fbo),m.setClearColor(0,0,0,0),m.clear(16384),this._gaussianSplatParameters.totalGaussians=this._data.visibleGaussians,this._gaussianSplatParameters.splatOrder=this._data.orderTexture.texture,this._gaussianSplatParameters.splatAtlas=this._data.textureAtlas.texture;const p=Math.tan(.5*this.camera.fovY),u=p/h*o;i(this._tanFov,u,p);const d=h/(2*p);this._gaussianSplatParameters.focalLength=d,this._gaussianSplatParameters.tanFov=this._tanFov,this._prepareHighPrecisionCameraPosition(),this.renderingContext.bindTechnique(e,this.bindParameters,this._gaussianSplatParameters),this.renderingContext.drawArraysInstanced(E.TRIANGLE_STRIP,0,4,this._data.visibleGaussians);const g=l.acquire(o,h,"splat depth",8);g.attachDepth(s.getAttachment(V)),m.bindFramebuffer(g.fbo),m.setClearColor(0,0,0,0),m.clear(16384),this.renderingContext.bindTechnique(a,this.bindParameters,this._gaussianSplatParameters),this.renderingContext.drawArraysInstanced(E.TRIANGLE_STRIP,0,4,this._data.visibleGaussians);const f=l.acquire(o,h,this.produces);return this._gaussianSplatDepthCompositionParameters.splatDepth=g.getTexture(),f.attachDepth(s.getAttachment(V)),m.bindFramebuffer(f.fbo),m.bindTechnique(n,this.bindParameters,this._gaussianSplatDepthCompositionParameters),m.screen.draw(),this._gaussianSplatCompositionParameters.color=s.getTexture(),this._gaussianSplatCompositionParameters.splatColor=c.getTexture(),m.bindFramebuffer(f.fbo),m.bindTechnique(r,this.bindParameters,this._gaussianSplatCompositionParameters),m.screen.draw(),c.release(),g.release(),f}intersect(t,s,e,i){const{gaussianPosition:a,intersectionRayDir:m,intersectionPlane:p,layerViewUid:f}=this,C=_(e,i);r(m,i,e);const j=1/n(m);o(m,m,j);const v=u();h(v,m),g(p,m[0],m[1],m[2],-l(m,e));const q=new U,D=new U,y=new Array;this._data.visibleGaussianTiles.forEach(r=>{const{maxScale:n}=r,o=r.obb.minimumDistancePlane(p),h=r.obb.maximumDistancePlane(p),u=h<0,g=null!=q.dist&&null!=D.dist&&q.dist<o*j&&D.dist>h*j;if(u||g)return;const _=b(r.obb.center,r.obb.radius+n);if(!P(_,C,null))return;if(!r.obb.intersectRay(e,m,n))return;const{positions:S,squaredScales:w,gaussianAtlasIndices:G}=r,T=G.length;for(let p=0;p<T;p++){const r=3*p;a[0]=S[r]-e[0],a[1]=S[r+1]-e[1],a[2]=S[r+2]-e[2];const n=w[p],o=l(a,m),h=o*o;if(c(a)-h>n)continue;const u=o*j,g=t=>(t.point=t.point?t.point.fill(a[0],a[1],a[2]):d(a),t.dist=u,t.normal=v,t.layerViewUid=f,t);if((null==q.dist||u<q.dist)&&(null==s||s(e,i,u))&&g(q),0!==t.options.store&&(null==D.dist||u>D.dist)&&(null==s||s(e,i,u))&&g(D),2===t.options.store&&(null==s||s(e,i,u))){const t=new U;y.push(g(t))}}});const G=(t,s)=>{const{layerViewUid:e}=s,i=new S(s.point,e);t.set(0,i,s.dist,s.normal)};if(F(q)){const s=t.results.min;(null==s.distance||q.dist<s.distance)&&G(s,q)}if(F(D)&&0!==t.options.store){const s=t.results.max;(null==s.distance||D.dist>s.distance)&&G(s,D)}if(2===t.options.store)for(const r of y){const s=new w(C);G(s,r),t.results.all.push(s)}}get slicePlaneEnabled(){return this._slicePlaneEnabled}set slicePlaneEnabled(t){this._slicePlaneEnabled!==t&&(this._slicePlaneEnabled=t,this.requestRender(1))}get data(){return this._data}destroy(){this._data.destroy(),super.destroy()}_onCameraChange(){const t=this.view.state.camera.eye,s=this.view.state.camera.ray.direction,e=.001;(Math.abs(t[0]-this._previousCameraPosition[0])>e||Math.abs(t[1]-this._previousCameraPosition[1])>e||Math.abs(t[2]-this._previousCameraPosition[2])>e||Math.abs(s[0]-this._previousCameraDirection[0])>e||Math.abs(s[1]-this._previousCameraDirection[1])>e||Math.abs(s[2]-this._previousCameraDirection[2])>e)&&this._data.requestSort()}_prepareHighPrecisionCameraPosition(){o(this._tempVec,this.camera.eye,1/I.tileSize),m(this._tempVec,this._tempVec),p(this._coarseCameraPosition,this._tempVec),this._gaussianSplatParameters.cameraPos8k=this._coarseCameraPosition,o(this._tempVec,this._tempVec,I.tileSize),r(this._cameraDelta,this.camera.eye,this._tempVec),this._gaussianSplatParameters.cameraDelta=this._cameraDelta}static{this.tileSize=2.048}};function F(t){return null!=t.dist&&null!=t.point}k=I=t([e("esri.views.3d.webgl-engine.lib.GaussianSplatRenderNode")],k);class U{constructor(){this.point=null,this.dist=null,this.normal=null,this.layerViewUid=""}}export{k as GaussianSplatRenderNode};