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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/WebLinkChart.js +1 -1
  2. package/analysis/ShadowCast/types.d.ts +2 -0
  3. package/applications/Components/analysisUtils.d.ts +1 -0
  4. package/applications/Components/analysisUtils.js +1 -1
  5. package/arcade/arcadeAsyncRuntime.js +1 -1
  6. package/arcade/arcadeCompiler.js +1 -1
  7. package/arcade/featureSetUtils.js +1 -1
  8. package/arcade/featureset/actions/Adapted.js +1 -1
  9. package/arcade/featureset/actions/AttributeFilter.js +1 -1
  10. package/arcade/featureset/actions/GroupBy.js +1 -1
  11. package/arcade/featureset/actions/SpatialFilter.js +1 -1
  12. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  13. package/arcade/featureset/sources/FeatureLayerMemory.js +1 -1
  14. package/arcade/featureset/sources/FeatureLayerOGC.js +1 -1
  15. package/arcade/featureset/sources/FeatureLayerRelated.js +1 -1
  16. package/arcade/featureset/support/FeatureSet.js +1 -1
  17. package/arcade/featureset/support/FeatureSetIterator.js +1 -1
  18. package/assets/esri/core/workers/RemoteClient.js +1 -1
  19. package/assets/esri/core/workers/chunks/014dbe6fa93a277b08f7.js +1 -0
  20. package/assets/esri/core/workers/chunks/06462b267ff8d5984882.js +1 -0
  21. package/assets/esri/core/workers/chunks/{b48bb38e5d60fc7a9097.js → 08ef90e3fcfd4eda4301.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{fa01d1813fa78034526e.js → 0a5427127634738aa239.js} +1 -1
  23. package/assets/esri/core/workers/chunks/0a58b57e1777a8b0ea23.js +1 -0
  24. package/assets/esri/core/workers/chunks/{7115c52e22b7becff8de.js → 103153951ba312dc5e9e.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{c7c721de93bc8688e13c.js → 1d4ea8db272655c0608c.js} +1 -1
  26. package/assets/esri/core/workers/chunks/1d566539ff6fb6ac798c.js +1 -0
  27. package/assets/esri/core/workers/chunks/1de216d9850c39c1735d.js +1 -0
  28. package/assets/esri/core/workers/chunks/20e4243ea563d05a5256.js +1 -0
  29. package/assets/esri/core/workers/chunks/262232437d37a7460b11.js +1 -0
  30. package/assets/esri/core/workers/chunks/{fafbacf2467e6883b6c9.js → 28db329528def851efd7.js} +1 -1
  31. package/assets/esri/core/workers/chunks/{2367bd1cb34799a3f08a.js → 30184e39129d9c66ea54.js} +1 -1
  32. package/assets/esri/core/workers/chunks/{f55328aabf84770c8e6a.js → 328106e181e5957ceaa5.js} +1 -1
  33. package/assets/esri/core/workers/chunks/48e2737182c75005fb8f.js +1 -0
  34. package/assets/esri/core/workers/chunks/{d3db7244fac7398cc700.js → 4b6a44c6265c8959abd8.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{a372d9af43ade7c6314c.js → 52c8687b473c9953c2f2.js} +1 -1
  36. package/assets/esri/core/workers/chunks/{63933cbcb5c12df09715.js → 59ce992d3a5e7c32b9fb.js} +1 -1
  37. package/assets/esri/core/workers/chunks/{c9c2e00fed979c21e2f0.js → 5e30acfda04f7fc2b676.js} +1 -1
  38. package/assets/esri/core/workers/chunks/6330d8767ba1d5329daa.js +1 -0
  39. package/assets/esri/core/workers/chunks/640085b5ade5c7f16228.js +1 -0
  40. package/assets/esri/core/workers/chunks/690a40d2eef52bfc149f.js +1 -0
  41. package/assets/esri/core/workers/chunks/727804cf901094b1d620.js +1 -0
  42. package/assets/esri/core/workers/chunks/{dd34d56caafa38d4b8e4.js → 7aa730e5ac7b268e3c98.js} +1 -1
  43. package/assets/esri/core/workers/chunks/8c271e9272e4eaf1325a.js +1 -0
  44. package/assets/esri/core/workers/chunks/{2a0fe1aede5c68374ccf.js → 8ec238b5b59ef18a1713.js} +1 -1
  45. package/assets/esri/core/workers/chunks/{f1dfb1323d50247e80f9.js → 9110287f272141f60c35.js} +1 -1
  46. package/assets/esri/core/workers/chunks/951a3442d4342539f2ea.js +1 -0
  47. package/assets/esri/core/workers/chunks/9664d9e679abc41f6c42.js +1 -0
  48. package/assets/esri/core/workers/chunks/{2921f05a40fda12f9f81.js → a00bba1c7cbf8cd7892c.js} +1 -1
  49. package/assets/esri/core/workers/chunks/a716b8fdeda4e16f03ab.js +1 -0
  50. package/assets/esri/core/workers/chunks/aead7c9830fa310e5b53.js +1 -0
  51. package/assets/esri/core/workers/chunks/{1fa55d4c4b092a98bdd7.js → b56c07c0b43cb1999070.js} +1 -1
  52. package/assets/esri/core/workers/chunks/b59be95949445ff5afab.js +1 -0
  53. package/assets/esri/core/workers/chunks/b6dec5dfdeca54bae88d.js +1 -0
  54. package/assets/esri/core/workers/chunks/{6afd59412bfc134bdf75.js → c052fb8c952cda0b5d13.js} +1 -1
  55. package/assets/esri/core/workers/chunks/c5967133f3ba34a883f8.js +1 -0
  56. package/assets/esri/core/workers/chunks/{4356274cfa477eb6d749.js → cda5c95fd49b8901f7d4.js} +1 -1
  57. package/assets/esri/core/workers/chunks/{82cc758bddd9f8397b9f.js → ce8fc1ca229d53a4b68d.js} +8 -8
  58. package/assets/esri/core/workers/chunks/{f2ebd6471e1259a6eac0.js → ce99abfdcd71ff9e4e36.js} +1 -1
  59. package/assets/esri/core/workers/chunks/{726a797f5df7eeee0b3d.js → d786b17cc9062b1450ac.js} +1 -1
  60. package/assets/esri/core/workers/chunks/dd105d6e0fcedee32644.js +1 -0
  61. package/assets/esri/core/workers/chunks/{2e76fbd3c874300fc4a7.js → de3da4d31a7529761565.js} +1 -1
  62. package/assets/esri/core/workers/chunks/e1148067ceae7d9eaaf8.js +1 -0
  63. package/assets/esri/core/workers/chunks/{b536fdb655ad293d9024.js → e501d68a1464805c4b4e.js} +1 -1
  64. package/assets/esri/core/workers/chunks/{33431e8131f6017de2f9.js → e7f4d135ef9665de1468.js} +1 -1
  65. package/assets/esri/core/workers/chunks/{97650ee3d0eecb69ccbb.js → e9bc3c6482ba778c9349.js} +39 -39
  66. package/assets/esri/core/workers/chunks/{7804be2f5b3d86188a24.js → edc3d98f33d7bf959154.js} +1 -1
  67. package/assets/esri/core/workers/chunks/{0446562aee0639c61485.js → ee67c8a7c1f8b482cd99.js} +1 -1
  68. package/assets/esri/core/workers/chunks/eefad79be500667af96e.js +1 -0
  69. package/assets/esri/core/workers/chunks/{2b7f9a57a2cfbc108673.js → f1b99529e2055873b65a.js} +1 -1
  70. package/assets/esri/core/workers/chunks/{abb05a903440d97a6a74.js → f441fc74451330384fb0.js} +1 -1
  71. package/assets/esri/core/workers/chunks/f609b256df9eb3803464.js +1 -0
  72. package/assets/esri/core/workers/chunks/f693a4d97b2762d0e6ff.js +1 -0
  73. package/assets/esri/core/workers/chunks/f8caceeaa14d99c35526.js +1 -0
  74. package/assets/esri/core/workers/chunks/f97a7cb367634353177d.js +1 -0
  75. package/assets/esri/core/workers/chunks/febce0d80f019dc2a427.js +1 -0
  76. package/assets/esri/rest/knowledgeGraph/wasmInterface/arcgis-knowledge-client-core-simd.wasm +0 -0
  77. package/assets/esri/rest/knowledgeGraph/wasmInterface/arcgis-knowledge-client-core.wasm +0 -0
  78. package/assets/esri/themes/base/widgets/_Attribution.scss +1 -0
  79. package/assets/esri/themes/dark/main.css +1 -1
  80. package/assets/esri/themes/light/main.css +1 -1
  81. package/assets/esri/themes/light/view.css +1 -1
  82. package/chunks/CloudsComposition.glsl.js +1 -1
  83. package/chunks/ComponentShader.glsl.js +2 -2
  84. package/chunks/DefaultMaterial.glsl.js +1 -1
  85. package/chunks/GaussianSplat.glsl.js +2 -2
  86. package/chunks/Laserlines.glsl.js +1 -1
  87. package/chunks/Magnifier.glsl.js +1 -1
  88. package/chunks/Path.glsl.js +1 -1
  89. package/chunks/RealisticTree.glsl.js +1 -1
  90. package/chunks/Terrain.glsl.js +34 -36
  91. package/chunks/WaterSurface.glsl.js +1 -1
  92. package/chunks/arcgis-knowledge-client-core-simd.js +1 -1
  93. package/chunks/arcgis-knowledge-client-core.js +1 -1
  94. package/chunks/boundedPlane.js +1 -1
  95. package/chunks/cameraUtilsSpherical.js +1 -1
  96. package/chunks/vec32.js +1 -1
  97. package/chunks/vec42.js +1 -1
  98. package/config.js +1 -1
  99. package/core/has.js +1 -1
  100. package/core/iteratorUtils.js +1 -1
  101. package/core/libs/gl-matrix-2/math/quat.js +1 -1
  102. package/core/libs/gl-matrix-2/math/vec3.js +1 -1
  103. package/core/libs/gl-matrix-2/math/vec4.js +1 -1
  104. package/geometry/support/aaBoundingRect.js +1 -1
  105. package/geometry/support/buffer/BufferView.js +1 -1
  106. package/geometry/support/buffer/internals/Vec4.js +1 -1
  107. package/geometry/support/lineSegment.js +1 -1
  108. package/geometry/support/meshUtils/merge.js +1 -1
  109. package/geometry/support/sphere.js +1 -1
  110. package/interfaces.d.ts +143 -5
  111. package/kernel.js +1 -1
  112. package/layers/GaussianSplatLayer.js +1 -1
  113. package/layers/IntegratedMesh3DTilesLayer.js +1 -1
  114. package/layers/IntegratedMeshLayer.js +1 -1
  115. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  116. package/layers/VoxelWasmPerSceneView.js +1 -1
  117. package/layers/knowledgeGraph/layerUtils.js +1 -1
  118. package/layers/orientedImagery/transformations/worldToImage.js +1 -1
  119. package/layers/support/csvUtils.js +1 -1
  120. package/layers/video/VideoController.js +1 -1
  121. package/layers/voxel/VoxelVolume.js +1 -1
  122. package/package.json +5 -5
  123. package/rest/knowledgeGraph/DataModel.js +1 -1
  124. package/rest/knowledgeGraph/GraphDataModelSingletonOperationResult.d.ts +4 -0
  125. package/rest/knowledgeGraph/GraphDataModelSingletonOperationResult.js +5 -0
  126. package/rest/knowledgeGraph/GraphProperty.js +1 -1
  127. package/rest/knowledgeGraph/wasmInterface/WasmDataModelWrapperInterfaces.js +1 -1
  128. package/rest/knowledgeGraph/wasmInterface/updateToWasmEncodedFactories.js +1 -1
  129. package/rest/knowledgeGraph/wasmInterface/wasmToDataModelChangeResponseFactories.js +1 -1
  130. package/rest/knowledgeGraph/wasmInterface/wasmToDataModelFactories.js +1 -1
  131. package/rest/knowledgeGraphService.d.ts +3 -0
  132. package/rest/knowledgeGraphService.js +1 -1
  133. package/support/revision.js +1 -1
  134. package/views/2d/analysis/ElevationProfile/ElevationProfileLineVisualization2D.js +1 -1
  135. package/views/2d/interactive/SegmentLabels2D.js +1 -1
  136. package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
  137. package/views/3d/FocusAreasView.js +1 -1
  138. package/views/3d/GroundView3D.js +1 -1
  139. package/views/3d/analysis/AreaMeasurement/support/MeasurementData.js +1 -1
  140. package/views/3d/analysis/Dimension/lengthDimensionConstraintUtils.js +1 -1
  141. package/views/3d/analysis/Dimension/lengthDimensionUtils.js +1 -1
  142. package/views/3d/analysis/ElevationProfile/ElevationProfileLineSceneComputation.js +1 -1
  143. package/views/3d/analysis/ElevationProfile/ElevationProfileLineVisualization3D.js +1 -1
  144. package/views/3d/analysis/ElevationProfile/ElevationProfileVisualization3D.js +1 -1
  145. package/views/3d/analysis/ElevationProfileAnalysisView3D.js +1 -1
  146. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  147. package/views/3d/analysis/LineOfSight/LineOfSightIntersectionResult.js +1 -1
  148. package/views/3d/analysis/LineOfSight/LineOfSightRayIntersector.js +1 -1
  149. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  150. package/views/3d/analysis/Viewshed/ViewshedScaleOrientManipulation.js +1 -1
  151. package/views/3d/analysis/Viewshed/ViewshedSubTool.js +1 -1
  152. package/views/3d/analysis/Viewshed/ViewshedSubVisualization.js +1 -1
  153. package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
  154. package/views/3d/animation/pointToPoint/Camera.js +1 -1
  155. package/views/3d/camera/constraintUtils/distance.js +1 -1
  156. package/views/3d/camera/constraintUtils/tilt.js +1 -1
  157. package/views/3d/environment/ChapmanAtmosphere.js +1 -1
  158. package/views/3d/environment/CloudsParameters.js +1 -1
  159. package/views/3d/environment/EnvironmentManager.js +1 -1
  160. package/views/3d/environment/Fog.js +1 -1
  161. package/views/3d/environment/MarsAtmosphere.js +1 -1
  162. package/views/3d/interactive/SegmentLabels3D.js +1 -1
  163. package/views/3d/interactive/editingTools/manipulations/MoveZManipulation.js +1 -1
  164. package/views/3d/interactive/editingTools/media/MediaElementManipulator3D.js +1 -1
  165. package/views/3d/interactive/editingTools/reshape/edgeOffsetUtils.js +1 -1
  166. package/views/3d/interactive/measurementTools/directLineMeasurement3D/DirectLineMeasurement3DTool.js +1 -1
  167. package/views/3d/interactive/visualElements/ExtendedLineVisualElement.js +1 -1
  168. package/views/3d/interactive/visualElements/MeasurementAreaVisualElement.js +1 -1
  169. package/views/3d/interactive/visualElements/MeasurementArrowVisualElement.js +1 -1
  170. package/views/3d/interactive/visualElements/OutlineVisualElement.js +1 -1
  171. package/views/3d/interactive/visualElements/ParallelLineVisualElement.js +1 -1
  172. package/views/3d/interactive/visualElements/PointVisualElement.js +1 -1
  173. package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
  174. package/views/3d/interactive/visualElements/SlicePlaneVisualElement.js +1 -1
  175. package/views/3d/interactive/visualElements/VerticesVisualElement.js +1 -1
  176. package/views/3d/layers/DrapedSubView3D.js +1 -1
  177. package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
  178. package/views/3d/layers/GraphicsLayerView3D.js +1 -1
  179. package/views/3d/layers/I3SMeshView3D.js +1 -1
  180. package/views/3d/layers/ImagerySubView3D.js +1 -1
  181. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  182. package/views/3d/layers/IntegratedMeshLayerView3D.js +1 -1
  183. package/views/3d/layers/RouteLayerView3D.js +1 -1
  184. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  185. package/views/3d/layers/graphics/Graphics3DFrustumVisibility.js +1 -1
  186. package/views/3d/layers/graphics/Graphics3DGraphicsPipeline.js +1 -1
  187. package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
  188. package/views/3d/layers/graphics/Graphics3DScaleVisibility.js +1 -1
  189. package/views/3d/layers/graphics/Graphics3DSymbolLayer.js +1 -1
  190. package/views/3d/layers/graphics/Graphics3DWaterSymbolLayer.js +1 -1
  191. package/views/3d/layers/graphics/graphicUtils.js +1 -1
  192. package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
  193. package/views/3d/layers/graphics/pipeline/rendering/DirectRenderer.js +1 -1
  194. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  195. package/views/3d/layers/i3s/PointCloudRenderer.js +1 -1
  196. package/views/3d/layers/support/FastSymbolUpdates.js +1 -1
  197. package/views/3d/layers/support/FeatureTileMeasurements3D.js +1 -1
  198. package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
  199. package/views/3d/layers/support/Tiles3DIntersectionHandler.js +1 -1
  200. package/views/3d/state/ConstraintsManager.js +1 -1
  201. package/views/3d/state/Frustum.js +1 -1
  202. package/views/3d/state/ViewStateManager.js +1 -1
  203. package/views/3d/state/controllers/FovController.js +1 -1
  204. package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
  205. package/views/3d/state/controllers/momentum/ZoomPlanarMomentumController.js +1 -1
  206. package/views/3d/support/FrustumExtentIntersection.js +1 -1
  207. package/views/3d/support/cameraUtils.js +1 -1
  208. package/views/3d/support/flow/FlowSubViewTiles3D.js +1 -1
  209. package/views/3d/support/gaussianSplatting/GaussianSplatFadeTexture.js +1 -1
  210. package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +1 -1
  211. package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +1 -1
  212. package/views/3d/support/intersectionUtils.js +1 -1
  213. package/views/3d/support/pointsOfInterest/CameraOnSurface.js +1 -1
  214. package/views/3d/support/pointsOfInterest/CenterOnSurface.js +1 -1
  215. package/views/3d/support/pointsOfInterest/Focus.js +1 -1
  216. package/views/3d/support/pointsOfInterest/PointsOfInterest.js +1 -1
  217. package/views/3d/support/pointsOfInterest/StableSurfaceCenter.js +1 -1
  218. package/views/3d/support/viewpointUtils.js +1 -1
  219. package/views/3d/terrain/Overlay.js +1 -1
  220. package/views/3d/terrain/OverlayManager.js +1 -1
  221. package/views/3d/terrain/OverlayRenderer.js +1 -1
  222. package/views/3d/terrain/PatchRenderData.js +1 -1
  223. package/views/3d/terrain/ScaleRangeQueries.js +1 -1
  224. package/views/3d/terrain/SphericalPatch.js +1 -1
  225. package/views/3d/terrain/TerrainRenderer.js +1 -1
  226. package/views/3d/terrain/TerrainSurface.js +1 -1
  227. package/views/3d/terrain/TextureFader.js +1 -1
  228. package/views/3d/terrain/TextureReference.js +1 -1
  229. package/views/3d/terrain/Tile.js +1 -1
  230. package/views/3d/terrain/TileCompositor.js +1 -1
  231. package/views/3d/webgl/RenderCamera.js +1 -1
  232. package/views/3d/webgl-engine/collections/Component/Material/ComponentData.glsl.js +1 -1
  233. package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
  234. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechnique.js +1 -1
  235. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  236. package/views/3d/webgl-engine/core/renderPasses/RenderPassManager.js +1 -1
  237. package/views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js +4 -7
  238. package/views/3d/webgl-engine/core/shaderLibrary/attributes/VerticalOffset.glsl.js +1 -1
  239. package/views/3d/webgl-engine/core/shaderLibrary/hud/HUD.glsl.js +6 -6
  240. package/views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateAmbientLighting.glsl.js +4 -4
  241. package/views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateSceneLighting.glsl.js +19 -15
  242. package/views/3d/webgl-engine/core/shaderLibrary/shading/MainLighting.glsl.js +2 -2
  243. package/views/3d/webgl-engine/core/shaderLibrary/shading/WaterDistortion.glsl.js +1 -1
  244. package/views/3d/webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js +1 -1
  245. package/views/3d/webgl-engine/core/shaderLibrary/terrain/TerrainTexture.glsl.js +5 -5
  246. package/views/3d/webgl-engine/core/shaderLibrary/terrain/TileBackground.glsl.js +14 -14
  247. package/views/3d/webgl-engine/core/shaderLibrary/util/BlendModes.glsl.js +16 -37
  248. package/views/3d/webgl-engine/core/shaderLibrary/util/CameraSpace.glsl.js +2 -2
  249. package/views/3d/webgl-engine/effects/RenderPluginManager.js +1 -1
  250. package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
  251. package/views/3d/webgl-engine/effects/geometry/RenderOccludedRenderNode.js +1 -1
  252. package/views/3d/webgl-engine/effects/haze/Haze.js +1 -1
  253. package/views/3d/webgl-engine/effects/transparency/OITBlend.js +1 -1
  254. package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
  255. package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
  256. package/views/3d/webgl-engine/lib/MainFramebuffer.js +1 -1
  257. package/views/3d/webgl-engine/lib/Normals.js +1 -1
  258. package/views/3d/webgl-engine/lib/Object3D.js +1 -1
  259. package/views/3d/webgl-engine/lib/PathGeometryData.js +1 -1
  260. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  261. package/views/3d/webgl-engine/lib/RenderingContext.js +1 -1
  262. package/views/3d/webgl-engine/lib/ShadowAccumulator.js +1 -1
  263. package/views/3d/webgl-engine/lib/ShadowCastRenderer.js +1 -1
  264. package/views/3d/webgl-engine/lib/ShadowMap.js +1 -1
  265. package/views/3d/webgl-engine/lib/SortedRenderGeometryRenderer.js +1 -1
  266. package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
  267. package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBuffer.js +1 -1
  268. package/views/3d/webgl-engine/lib/Viewshed.js +1 -1
  269. package/views/3d/webgl-engine/lib/edgeRendering/EdgeRenderer.js +1 -1
  270. package/views/3d/webgl-engine/lib/edgeRendering/edgePreprocessing.js +1 -1
  271. package/views/3d/webgl-engine/lib/geometryDataUtils.js +1 -1
  272. package/views/3d/webgl-engine/lib/triangleIntersectionUtils.js +1 -1
  273. package/views/3d/webgl-engine/materials/CheckerBoardMaterial.js +1 -1
  274. package/views/3d/webgl-engine/materials/ColorMaterial.js +1 -1
  275. package/views/3d/webgl-engine/materials/DefaultMaterial.js +1 -1
  276. package/views/3d/webgl-engine/materials/DefaultTechniqueConfiguration.js +1 -1
  277. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  278. package/views/3d/webgl-engine/materials/HeatmapDensityMaterial.js +1 -1
  279. package/views/3d/webgl-engine/materials/ImageMaterial.js +1 -1
  280. package/views/3d/webgl-engine/materials/LineCalloutMaterial.js +1 -1
  281. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  282. package/views/3d/webgl-engine/materials/MeasurementArrowMaterial.js +1 -1
  283. package/views/3d/webgl-engine/materials/NativeLineMaterial.js +1 -1
  284. package/views/3d/webgl-engine/materials/PatternMaterial.js +1 -1
  285. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  286. package/views/3d/webgl-engine/materials/ShadedColorMaterial.js +1 -1
  287. package/views/3d/webgl-engine/materials/SlicePlaneMaterial.js +1 -1
  288. package/views/3d/webgl-engine/materials/WaterMaterial.js +1 -1
  289. package/views/3d/webgl-engine/materials/renderers/VaoRenderer.js +1 -1
  290. package/views/3d/webgl-engine/materials/renderers/VaoWriter.js +1 -1
  291. package/views/3d/webgl-engine/shaders/AnimatedLine.glsl.js +1 -1
  292. package/views/3d/webgl-engine/shaders/ColorMaterialTechnique.js +1 -1
  293. package/views/3d/webgl-engine/shaders/DefaultMaterialTechnique.js +1 -1
  294. package/views/3d/webgl-engine/shaders/GaussianSplat.glsl.js +1 -1
  295. package/views/3d/webgl-engine/shaders/GaussianSplatTechniqueConfiguration.js +1 -1
  296. package/views/3d/webgl-engine/shaders/ImageMaterialTechnique.js +1 -1
  297. package/views/3d/webgl-engine/shaders/LineMarkerTechnique.js +1 -1
  298. package/views/3d/webgl-engine/shaders/NativeLineTechnique.js +1 -1
  299. package/views/3d/webgl-engine/shaders/OutputColorHighlightOLID.glsl.js +9 -10
  300. package/views/3d/webgl-engine/shaders/PatternTechnique.js +1 -1
  301. package/views/3d/webgl-engine/shaders/RibbonLineTechnique.js +1 -1
  302. package/views/3d/webgl-engine/shaders/SphereDepthInterpolate.glsl.js +1 -1
  303. package/views/3d/webgl-engine/shaders/Terrain.glsl.js +1 -1
  304. package/views/3d/webgl-engine/shaders/TerrainTechnique.js +1 -1
  305. package/views/3d/webgl-engine/shaders/TerrainTechniqueConfiguration.js +1 -1
  306. package/views/3d/webgl-engine/shaders/ensureColor4.js +1 -1
  307. package/views/3d/webgl-engine/shaders/sources/edgeRenderer/EdgeUtil.glsl.js +5 -5
  308. package/views/GroundView.js +1 -1
  309. package/views/SceneView.js +1 -1
  310. package/views/analysis/ElevationProfile/elevationProfileVisualizationUtils.js +1 -1
  311. package/views/interactive/GraphicManipulator.js +1 -1
  312. package/views/interactive/coordinateHelper.js +1 -1
  313. package/views/interactive/editGeometry/operations/OffsetEdgeVertex.js +1 -1
  314. package/views/interactive/sketch/constraints.js +1 -1
  315. package/views/interactive/snapping/featureSources/sceneLayerSource/SceneLayerSnappingSourceWorker.js +1 -1
  316. package/views/interactive/snapping/featureSources/sceneLayerSource/sceneLayerSnappingUtils.js +1 -1
  317. package/views/interactive/snapping/hints/LineSnappingHint.js +1 -1
  318. package/views/interactive/tooltip/tooltipCommonUtils.js +1 -1
  319. package/views/layers/LayerView.js +1 -1
  320. package/views/navigation/PanSphericalMomentumEstimator.js +1 -1
  321. package/views/support/GroundElevationSampler.js +1 -1
  322. package/views/support/LayerViewManager.js +1 -1
  323. package/views/support/euclideanAreaMeasurementUtils.js +1 -1
  324. package/views/support/euclideanLengthMeasurementUtils.js +1 -1
  325. package/views/support/geodesicLengthMeasurementUtils.js +1 -1
  326. package/views/support/geometry3dUtils.js +1 -1
  327. package/webmap/utils.js +1 -1
  328. package/widgets/Sketch/SketchViewModel.js +1 -1
  329. package/widgets/support/SelectionList.js +1 -1
  330. package/assets/esri/core/workers/chunks/032444974011118127d7.js +0 -1
  331. package/assets/esri/core/workers/chunks/05e55118dc0023d500fc.js +0 -1
  332. package/assets/esri/core/workers/chunks/089221bac1f019692f48.js +0 -1
  333. package/assets/esri/core/workers/chunks/11687718c8635eb7bf37.js +0 -1
  334. package/assets/esri/core/workers/chunks/15c1a48e8cd2a8882d85.js +0 -1
  335. package/assets/esri/core/workers/chunks/1b9e7d416c9f00e020bb.js +0 -1
  336. package/assets/esri/core/workers/chunks/1bfe0b2bf38d4dee7fd6.js +0 -1
  337. package/assets/esri/core/workers/chunks/27bd88e1101873d4ce12.js +0 -1
  338. package/assets/esri/core/workers/chunks/483dc4ee5d73cdfe6229.js +0 -1
  339. package/assets/esri/core/workers/chunks/53d95ba86d010231fc4e.js +0 -1
  340. package/assets/esri/core/workers/chunks/7d3e665613927904ba4f.js +0 -1
  341. package/assets/esri/core/workers/chunks/a5f2da24497349239648.js +0 -1
  342. package/assets/esri/core/workers/chunks/a7b1b42bdb9cb9ecac45.js +0 -1
  343. package/assets/esri/core/workers/chunks/acaaefd4997316d319b8.js +0 -1
  344. package/assets/esri/core/workers/chunks/ad138b989c2c7a1168ac.js +0 -1
  345. package/assets/esri/core/workers/chunks/cc7c37f9ed3f831fd25c.js +0 -1
  346. package/assets/esri/core/workers/chunks/d14bd320f72d8e8a0ad8.js +0 -1
  347. package/assets/esri/core/workers/chunks/d86e59da76eea888ba86.js +0 -1
  348. package/assets/esri/core/workers/chunks/d8975dd7b85b5d065ee4.js +0 -1
  349. package/assets/esri/core/workers/chunks/de99c4fd1582a8e610cf.js +0 -1
  350. package/assets/esri/core/workers/chunks/ded3ef385d5a3a2ec8ca.js +0 -1
  351. package/assets/esri/core/workers/chunks/e3a994587f9b2e88db85.js +0 -1
  352. package/assets/esri/core/workers/chunks/eab0938d4ad7d7cc7309.js +0 -1
  353. package/assets/esri/core/workers/chunks/ed1dabed10ff9f4e0369.js +0 -1
  354. package/assets/esri/core/workers/chunks/ef5b13ee3362763c1096.js +0 -1
  355. package/assets/esri/core/workers/chunks/effbc4d240752e8ba0ab.js +0 -1
  356. package/assets/esri/core/workers/chunks/f403d8e414766fab2936.js +0 -1
  357. package/assets/esri/core/workers/chunks/f43e1e1a1b2eb737e00c.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{unique as r}from"../../../core/arrayUtils.js";import{EventEmitter as t}from"../../../core/Evented.js";import"../../../core/has.js";import{someMap as s,everyMap as i}from"../../../core/MapUtils.js";import{disposeMaybe as n}from"../../../core/maybe.js";import o from"../../../core/PooledArray.js";import{watch as a,on as h,syncAndInitial as d,initial as l}from"../../../core/reactiveUtils.js";import{someSet as c}from"../../../core/SetUtils.js";import{property as u,subclass as p}from"../../../core/accessorSupport/decorators.js";import{ortho as _,fromTranslation as g}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{h as m}from"../../../chunks/vec32.js";import{ones as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{debugFlags as f}from"../support/debugFlags.js";import{Overlay as R}from"./Overlay.js";import{OverlayRenderTargets as v}from"./OverlayRenderTargets.js";import x from"../webgl/RenderCamera.js";import{T as w}from"../../../chunks/TextureOnly.glsl.js";import{SyncRenderPlugin as T}from"../webgl-engine/effects/RenderPlugin.js";import{trackHighlightOptions as S,renderHighlightBuffer as b}from"../webgl-engine/effects/highlight/Highlight.js";import{GLMaterialRepository as O}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as D}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as C,defaultRenderOccludedMask as P}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as j}from"../webgl-engine/lib/ShadowMap.js";import{TextureTechnique as E}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as M}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as F}from"../webgl-engine/lighting/Lightsources.js";import{O as W}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as q}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import{TaskPriority as V,noBudget as A}from"../../support/Scheduler.js";import{Texture as k}from"../../webgl/Texture.js";import{TextureDescriptor as G}from"../../webgl/TextureDescriptor.js";let I=class extends T{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new W,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new o,this._passParameters=new w,this._screenToWorldRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new x,this.events=new t,this.longitudeCyclical=null,this.produces=new Map([[18,e=>8!==e||this.hasHighlights],[19,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1}initialize(){const e=this._view,r=e.stage,t=r.renderer.fboCache,{waterTextures:s,techniques:i}=r.renderView;this._renderContext=new C(this._rctx,new j(t,e.state.viewingMode),i),this.addHandles([a(()=>s.updating,()=>this.events.emit("content-changed"),d),a(()=>this._spatialReference,e=>this._localOriginFactory=new D(e),d),h(()=>e.allLayerViews,"after-changes",()=>this._sortedDrapeSourceRenderersDirty=!0),a(()=>S(e.state.highlights),()=>this._sortedDrapeSourceRenderersDirty=!0,l),a(()=>e.state.highlights,r=>{this._bindParameters.highlights=r,this._bindParameters.highlightOrderMap=e.state.highlightOrderMap},l),e.resourceController.scheduler.registerTask(V.OVERLAY_RENDERER,this)]);const{_bindParameters:n,_camera:o}=this;o.near=1,o.far=1e4,o.relativeElevation=null,n.slot=18,n.mainDepth=null,n.camera=o,n.oitPass=0,n.updateLighting([new F(y())],0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=n(this._passParameters.texture),this.disposeOverlays(),this._renderContext=null,this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToWorldRatio(){return this._screenToWorldRatio}get localOriginFactory(){return this._localOriginFactory}get pluginContext(){return this._pluginContext}initializeRenderContext(e){const r=new O(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit("content-changed"),this.notifyChange("updating"),this.notifyChange("isEmpty")},()=>this.events.emit("content-changed"));this._pluginContext={...e,materials:r},this._techniques.precompile(q)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||s(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return null!=this._overlays&&null!=this._renderTargets}getMaterialRenderer(e){for(const r of this._renderers.values()){const t=r.getMaterialRenderer(e);if(t)return t}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),r(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,r){const t=this._renderers.get(e);null!=t&&t.destroy(),this._renderers.set(e,r),this._sortedDrapeSourceRenderersDirty=!0,"fullOpacity"in e&&this.addHandles(a(()=>e.fullOpacity,()=>this.events.emit("content-changed")),e)}removeDrapeSourceRenderer(e){if(null==e)return;const r=this._renderers.get(e);null!=r&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),r.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=!!this._overlays&&c(e,e=>1===e.drapeTargetType)}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=c(e,e=>1===e.drapeSourceType),this._hasDrapedRasterSource=c(e,e=>0===e.drapeSourceType),this._hasDrapedFlowSource=c(e,e=>2===e.drapeSourceType)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,r,t=this._bindParameters.overlayStretch){null==this._overlays&&(this._renderTargets=new v(this._stage.renderer.fboCache),this._overlays=[new R,new R]),this.ensureDrapeTargets(e),this.ensureDrapeSources(r),this._bindParameters.overlayStretch=t}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit("textures-disposed")}_useOverlayColorInsteadOfColorNoRasterImage(e){return 1===e&&!this._needsColorWithoutRasterImage&&this._hasDrapedFeatureSource}getTexture(e){const r=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(r?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(e,()=>!0)}_onMaterialOrContentChanged(){this.renderOccludedFlags=s(this._renderers,e=>e.hasOccluders)?L:1}_processDrapeSources(e,r){let t=!1;for(const[s,i]of this._renderers){if(e.done)break;(s.destroyed||r(s))&&(i.commitChanges()&&(t=!0,e.madeProgress()))}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,t=!0,this._updateSortedDrapeSourceRenderers(),e.madeProgress()),this.compact(e),t&&(null!=this._overlays&&0===this._renderers.size&&this.disposeOverlays(),this.notifyChange("updating"),this.notifyChange("isEmpty"),this._onMaterialOrContentChanged(),this.hasHighlights=s(this._renderers,e=>e.hasHighlights),this.events.emit("content-changed"))}compact(e){let r=!1;for(const t of this._renderers.values()){if(e.done)break;r=t.compact(e)||r}return r&&this.notifyChange("updating"),r}hasHighlight(e){return s(this._renderers,r=>r.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(A,e=>1===e.updatePolicy)}get isEmpty(){return!f.OVERLAY_DRAW_DEBUG_TEXTURE&&i(this._renderers,e=>e.isEmpty)}get hasWater(){const e=s(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit("has-water")),this._hasWater}renders(e){if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==e&&2!==e)return!0;if(!this._overlays)return!1;const r=this._overlays[0];for(const i of this._overlays)i.setupGeometryViews(this.longitudeCyclical);if(!r.hasSomeSizedView())return!1;const t=this._renderContext.output;this._renderContext.output=this._renderTargets?.targets.find(r=>r.content===e)?.output??0,++this._techniques.precompiling;const s=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,this._renderContext.output=t,s}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:this._renderTargets?.getTexture(0)?1:0}updateAnimation(e){let r=!1;return this._renderers.forEach(t=>r=t.updateAnimation(e)||r),r&&this.parent.requestRender(0),r}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;const r=this._bindParameters;r.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(const t of this._renderTargets.targets){if(1===t.content&&!this._needsColorWithoutRasterImage)continue;const{output:e}=t;this._renderContext.output=e,r.slot=2===e?19:18,8===e&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null);const s=this._renderContext.renderOccludedMask;4===t.content&&(this._renderContext.renderOccludedMask=L),this._sortedRenderers.forAll(({drapeSource:e,renderer:r})=>{1===t.content&&0===e.drapeSourceType||4===t.content&&r.hasOnlyOccluders||r.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=s,r.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,r){if(!this._overlays||!this._renderTargets)return;for(const s of this._overlays)s.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;const t=this.allSourcesOccluders;for(const s of this._renderTargets.targets){if(!(0===s.content&&this._hasDrapedFlowSource)&&!s.handleRenderRequest(r)||1===s.content&&!this._needsColorWithoutRasterImage||4===s.content&&t)continue;const e=this._drawTarget(0,s),i=this._drawTarget(1,s);(e||i)&&s.fbo.generateMipMap()}}_drawTarget(e,r){const t=this._overlays[e],s=t.canvasGeometries;if(0===s.numViews)return!1;const i=this._view.state.contentPixelRatio;this._screenToWorldRatio=i*t.mapUnitsPerPixel/this._bindParameters.overlayStretch;const{output:n}=r;if(this.isEmpty||2===n&&!this.hasWater||!t.hasSomeSizedView())return!1;const{_rctx:o,_camera:a,_renderContext:h,_bindParameters:d}=this;if(a.pixelRatio=t.pixelRatio*i,h.output=n,d.screenToWorldRatio=this._screenToWorldRatio,d.screenToPCSRatio=this._screenToWorldRatio*this.parent.worldToPCSRatio,d.slot=2===n?19:18,4===r.content&&(h.renderOccludedMask=L),!this.renders(r.content))return h.renderOccludedMask=P,!1;const{resolution:l}=t,c=0===e,u=c?0:l;if(o.setViewport(u,0,l,l),this._bindTargetFBO(r),c)if(8!==r.output)o.setClearColor(0,0,0,0),o.clear(16384);else{const{gl:e}=o;e.clearBufferuiv(e.COLOR,0,[0,0,0,0])}if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==r.content&&2!==r.content){this._techniques.precompile(E,z);const r=this._techniques.get(E,z);for(let i=0;i<s.numViews;i++)this._setViewParameters(s.extents[i],t),this._ensureDebugPatternResources(t.resolution,B[e]),o.bindTechnique(r,d,this._passParameters),o.screen.draw()}if(8===r.output){const{fboCache:t}=this._stage.renderer,s=this._resolution;this._bindTargetFBO(r),b(o,t,{width:s,height:s},d,()=>this._renderAllGeometry(e,r),u)}else this._renderAllGeometry(e,r);return o.bindFramebuffer(null),h.renderOccludedMask=P,!0}get allSourcesOccluders(){return i(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,r){const t=this._overlays[e],s=t.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:n})=>{if(1===r.content&&0===i.drapeSourceType)return;const{fullOpacity:o}=i,a=null!=o&&o<1&&0===r.output&&this._bindTemporaryFBO();for(let e=0;e<s.numViews;e++)this._setViewParameters(s.extents[e],t),n.render(this._renderContext);if(a){this._bindTargetFBO(r),this._overlayParameters.texture=a.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;const t=this._techniques.get(q);this._rctx.bindTechnique(t,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),a.release()}})}_bindTargetFBO(e){const r=this._resolution,t=2*r;e.fbo.ensureFramebuffer(t,r),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){const e=this._resolution,r=2*e,t=this._stage.renderer.fboCache,s=t.acquire(r,e,"overlay tmp");return t.rctx.bindFramebuffer(s.fbo),t.rctx.clear(16384),s}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit("content-changed")}intersect(e,r,t,s){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(const{renderer:n}of this._sortedRenderers)i=n.intersect?.(e,r,t,s,i)??i}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),0===this._renderers.size)return;const e=this._view.map.allLayers.map(e=>e.uid),r=e.length;this._renderers.forEach((t,s)=>{const i=e.indexOf(s.layer?.uid),n=i>=0,o=s.renderGroup??(n?0:1),a=s.drapeSourcePriorityOffset??0,h=r*o+(n?i:0)+a;this._sortedRenderers.push(new U(s,t,h))}),this._sortedRenderers.sort((e,r)=>e.index-r.index)}_setViewParameters(e,r){const t=this._camera;t.viewport=[0,0,r.resolution,r.resolution],_(t.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],t.near,t.far),g(t.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,r){if(m(this._passParameters.color,r[0],r[1],r[2]),this._passParameters.texture)return;const t=new Uint8Array(e*e*4);let s=0;for(let n=0;n<e;n++)for(let r=0;r<e;r++){const i=Math.floor(r/10),o=Math.floor(n/10);i<2||o<2||10*i>e-20||10*o>e-20?(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=255):(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=1&i&&1&o?1&r^1&n?0:255:1&i^1&o?0:128)}const i=new G(e);i.samplingMode=9728,this._passParameters.texture=new k(this._rctx,i,t)}get test(){}};e([u()],I.prototype,"hasHighlights",void 0),e([u()],I.prototype,"renderOccludedFlags",void 0),e([u()],I.prototype,"_sortedDrapeSourceRenderersDirty",void 0),e([u({constructOnly:!0})],I.prototype,"parent",void 0),e([u({readOnly:!0})],I.prototype,"_techniques",null),e([u({type:Boolean,readOnly:!0})],I.prototype,"updating",null),e([u()],I.prototype,"isEmpty",null),I=e([p("esri.views.3d.terrain.OverlayRenderer")],I);class U{constructor(e,r,t){this.drapeSource=e,this.renderer=r,this.index=t}}const B=[[1,.5,.5],[.5,.5,1]],H=-2,L=4,z=new M;z.hasAlpha=!0;export{I as OverlayRenderer,H as drapedZ,L as overlayRenderOccludedFlag};
5
+ import{__decorate as e}from"tslib";import{unique as r}from"../../../core/arrayUtils.js";import{EventEmitter as t}from"../../../core/Evented.js";import"../../../core/has.js";import{someMap as s,everyMap as i}from"../../../core/MapUtils.js";import{disposeMaybe as n}from"../../../core/maybe.js";import o from"../../../core/PooledArray.js";import{watch as a,on as h,syncAndInitial as d,initial as l}from"../../../core/reactiveUtils.js";import{someSet as c}from"../../../core/SetUtils.js";import{property as u,subclass as p}from"../../../core/accessorSupport/decorators.js";import{ortho as _,fromTranslation as g}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{h as m}from"../../../chunks/vec32.js";import{ones as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{debugFlags as f}from"../support/debugFlags.js";import{Overlay as R}from"./Overlay.js";import{OverlayRenderTargets as v}from"./OverlayRenderTargets.js";import w from"../webgl/RenderCamera.js";import{T as x}from"../../../chunks/TextureOnly.glsl.js";import{SyncRenderPlugin as T}from"../webgl-engine/effects/RenderPlugin.js";import{trackHighlightOptions as O,renderHighlightBuffer as S}from"../webgl-engine/effects/highlight/Highlight.js";import{GLMaterialRepository as b}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as D}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as C,defaultRenderOccludedMask as P}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as j}from"../webgl-engine/lib/ShadowMap.js";import{TextureTechnique as E}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as M}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as F}from"../webgl-engine/lighting/Lightsources.js";import{O as W}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as q}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import{TaskPriority as V,noBudget as A}from"../../support/Scheduler.js";import{Texture as k}from"../../webgl/Texture.js";import{TextureDescriptor as G}from"../../webgl/TextureDescriptor.js";let I=class extends T{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new W,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new o,this._passParameters=new x,this._screenToWorldRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new w,this.events=new t,this.longitudeCyclical=null,this.produces=new Map([[19,e=>8!==e||this.hasHighlights],[20,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1}initialize(){const e=this._view,r=e.stage,t=r.renderer.fboCache,{waterTextures:s,techniques:i}=r.renderView;this._renderContext=new C(this._rctx,new j(t,e.state.viewingMode),i);const n=this._bindParameters;this.addHandles([a(()=>s.updating,()=>this.events.emit("content-changed"),d),a(()=>this._spatialReference,e=>this._localOriginFactory=new D(e),d),h(()=>e.allLayerViews,"after-changes",()=>this._sortedDrapeSourceRenderersDirty=!0),a(()=>O(e.state.highlights),()=>this._sortedDrapeSourceRenderersDirty=!0,l),a(()=>e.state.highlights,r=>{n.highlights=r,n.highlightOrderMap=e.state.highlightOrderMap},l),e.resourceController.scheduler.registerTask(V.OVERLAY_RENDERER,this)]);const o=this._camera;o.near=1,o.far=1e4,o.relativeElevation=null,n.slot=19,n.camera=o,n.updateLighting([new F(y())],0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=n(this._passParameters.texture),this.disposeOverlays(),this._renderContext=null,this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToWorldRatio(){return this._screenToWorldRatio}get localOriginFactory(){return this._localOriginFactory}get pluginContext(){return this._pluginContext}initializeRenderContext(e){const r=new b(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit("content-changed"),this.notifyChange("updating"),this.notifyChange("isEmpty")},()=>this.events.emit("content-changed"));this._pluginContext={...e,materials:r},this._techniques.precompile(q)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||s(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return null!=this._overlays&&null!=this._renderTargets}getMaterialRenderer(e){for(const r of this._renderers.values()){const t=r.getMaterialRenderer(e);if(t)return t}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),r(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,r){const t=this._renderers.get(e);null!=t&&t.destroy(),this._renderers.set(e,r),this._sortedDrapeSourceRenderersDirty=!0,"fullOpacity"in e&&this.addHandles(a(()=>e.fullOpacity,()=>this.events.emit("content-changed")),e)}removeDrapeSourceRenderer(e){if(null==e)return;const r=this._renderers.get(e);null!=r&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),r.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=!!this._overlays&&c(e,e=>1===e.drapeTargetType)}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=c(e,e=>1===e.drapeSourceType),this._hasDrapedRasterSource=c(e,e=>0===e.drapeSourceType),this._hasDrapedFlowSource=c(e,e=>2===e.drapeSourceType)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,r,t=this._bindParameters.overlayStretch){null==this._overlays&&(this._renderTargets=new v(this._stage.renderer.fboCache),this._overlays=[new R,new R]),this.ensureDrapeTargets(e),this.ensureDrapeSources(r),this._bindParameters.overlayStretch=t}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit("textures-disposed")}_useOverlayColorInsteadOfColorNoRasterImage(e){return 1===e&&!this._needsColorWithoutRasterImage&&this._hasDrapedFeatureSource}getTexture(e){const r=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(r?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(e,()=>!0)}_onMaterialOrContentChanged(){this.renderOccludedFlags=s(this._renderers,e=>e.hasOccluders)?L:1}_processDrapeSources(e,r){let t=!1;for(const[s,i]of this._renderers){if(e.done)break;(s.destroyed||r(s))&&(i.commitChanges()&&(t=!0,e.madeProgress()))}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,t=!0,this._updateSortedDrapeSourceRenderers(),e.madeProgress()),this.compact(e),t&&(null!=this._overlays&&0===this._renderers.size&&this.disposeOverlays(),this.notifyChange("updating"),this.notifyChange("isEmpty"),this._onMaterialOrContentChanged(),this.hasHighlights=s(this._renderers,e=>e.hasHighlights),this.events.emit("content-changed"))}compact(e){let r=!1;for(const t of this._renderers.values()){if(e.done)break;r=t.compact(e)||r}return r&&this.notifyChange("updating"),r}hasHighlight(e){return s(this._renderers,r=>r.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(A,e=>1===e.updatePolicy)}get isEmpty(){return!f.OVERLAY_DRAW_DEBUG_TEXTURE&&i(this._renderers,e=>e.isEmpty)}get hasWater(){const e=s(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit("has-water")),this._hasWater}renders(e){if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==e&&2!==e)return!0;if(!this._overlays)return!1;const r=this._overlays[0];for(const i of this._overlays)i.setupGeometryViews(this.longitudeCyclical);if(!r.hasSomeSizedView())return!1;const t=this._setOutput(this._renderTargets?.targets.find(r=>r.content===e)?.output??0);++this._techniques.precompiling;const s=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,this._setOutput(t),s}_setOutput(e){const r=this._renderContext.output;return this._renderContext.output=e,this._bindParameters.slot=2===e?20:19,r}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:this._renderTargets?.getTexture(0)?1:0}updateAnimation(e){let r=!1;return this._renderers.forEach(t=>r=t.updateAnimation(e)||r),r&&this.parent.requestRender(0),r}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;const r=this._bindParameters;r.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(const t of this._renderTargets.targets){if(1===t.content&&!this._needsColorWithoutRasterImage)continue;const{output:e}=t;this._setOutput(e),8===e&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null);const s=this._renderContext.renderOccludedMask;4===t.content&&(this._renderContext.renderOccludedMask=L),this._sortedRenderers.forAll(({drapeSource:e,renderer:r})=>{1===t.content&&0===e.drapeSourceType||4===t.content&&r.hasOnlyOccluders||r.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=s,r.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,r){if(!this._overlays||!this._renderTargets)return;for(const s of this._overlays)s.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;const t=this.allSourcesOccluders;for(const s of this._renderTargets.targets){if(!(0===s.content&&this._hasDrapedFlowSource)&&!s.handleRenderRequest(r)||1===s.content&&!this._needsColorWithoutRasterImage||4===s.content&&t)continue;const e=this._drawTarget(0,s),i=this._drawTarget(1,s);(e||i)&&s.fbo.generateMipMap()}}_drawTarget(e,r){const t=this._overlays[e],s=t.canvasGeometries;if(0===s.numViews)return!1;const i=this._view.state.contentPixelRatio;this._screenToWorldRatio=i*t.mapUnitsPerPixel/this._bindParameters.overlayStretch;const{output:n,content:o}=r;if(this.isEmpty||2===n&&!this.hasWater||!t.hasSomeSizedView())return!1;const{_rctx:a,_camera:h,_renderContext:d,_bindParameters:l}=this;if(h.pixelRatio=t.pixelRatio*i,this._setOutput(n),l.screenToWorldRatio=this._screenToWorldRatio,l.screenToPCSRatio=this._screenToWorldRatio*this.parent.worldToPCSRatio,4===o&&(d.renderOccludedMask=L),!this.renders(o))return d.renderOccludedMask=P,!1;const{resolution:c}=t,u=0===e,p=u?0:c;a.setViewport(p,0,c,c),this._bindTargetFBO(r),u&&(8===n?a.gl.clearBufferuiv(a.gl.COLOR,0,[0,0,0,0]):(a.setClearColor(0,0,0,0),a.clear(16384)));if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==o&&2!==o){this._techniques.precompile(E,z);const r=this._techniques.get(E,z);for(let i=0;i<s.numViews;i++)this._setViewParameters(s.extents[i],t),this._ensureDebugPatternResources(t.resolution,B[e]),a.bindTechnique(r,l,this._passParameters),a.screen.draw()}if(8===n){const{fboCache:t}=this._stage.renderer,s=this._resolution;this._bindTargetFBO(r),S(a,t,{width:s,height:s},l,()=>this._renderAllGeometry(e,r),p)}else this._renderAllGeometry(e,r);return a.bindFramebuffer(null),d.renderOccludedMask=P,!0}get allSourcesOccluders(){return i(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,r){const t=this._overlays[e],s=t.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:n})=>{if(1===r.content&&0===i.drapeSourceType)return;const{fullOpacity:o}=i,a=null!=o&&o<1&&0===r.output&&this._bindTemporaryFBO();for(let e=0;e<s.numViews;e++)this._setViewParameters(s.extents[e],t),n.render(this._renderContext);if(a){this._bindTargetFBO(r),this._overlayParameters.texture=a.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;const t=this._techniques.get(q);this._rctx.bindTechnique(t,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),a.release()}})}_bindTargetFBO(e){const r=this._resolution,t=2*r;e.fbo.ensureFramebuffer(t,r),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){const e=this._resolution,r=2*e,t=this._stage.renderer.fboCache,s=t.acquire(r,e,"overlay tmp");return t.rctx.bindFramebuffer(s.fbo),t.rctx.clear(16384),s}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit("content-changed")}intersect(e,r,t,s){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(const{renderer:n}of this._sortedRenderers)i=n.intersect?.(e,r,t,s,i)??i}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),0===this._renderers.size)return;const e=this._view.map.allLayers.map(e=>e.uid),r=e.length;this._renderers.forEach((t,s)=>{const i=e.indexOf(s.layer?.uid),n=i>=0,o=s.renderGroup??(n?0:1),a=s.drapeSourcePriorityOffset??0,h=r*o+(n?i:0)+a;this._sortedRenderers.push(new U(s,t,h))}),this._sortedRenderers.sort((e,r)=>e.index-r.index)}_setViewParameters(e,r){const t=this._camera;t.viewport=[0,0,r.resolution,r.resolution],_(t.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],t.near,t.far),g(t.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,r){if(m(this._passParameters.color,r[0],r[1],r[2]),this._passParameters.texture)return;const t=new Uint8Array(e*e*4);let s=0;for(let n=0;n<e;n++)for(let r=0;r<e;r++){const i=Math.floor(r/10),o=Math.floor(n/10);i<2||o<2||10*i>e-20||10*o>e-20?(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=255):(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=1&i&&1&o?1&r^1&n?0:255:1&i^1&o?0:128)}const i=new G(e);i.samplingMode=9728,this._passParameters.texture=new k(this._rctx,i,t)}get test(){}};e([u()],I.prototype,"hasHighlights",void 0),e([u()],I.prototype,"renderOccludedFlags",void 0),e([u()],I.prototype,"_sortedDrapeSourceRenderersDirty",void 0),e([u({constructOnly:!0})],I.prototype,"parent",void 0),e([u({readOnly:!0})],I.prototype,"_techniques",null),e([u({type:Boolean,readOnly:!0})],I.prototype,"updating",null),e([u()],I.prototype,"isEmpty",null),I=e([p("esri.views.3d.terrain.OverlayRenderer")],I);class U{constructor(e,r,t){this.drapeSource=e,this.renderer=r,this.index=t}}const B=[[1,.5,.5],[.5,.5,1]],H=-2,L=4,z=new M;z.hasAlpha=!0;export{I as OverlayRenderer,H as drapedZ,L as overlayRenderOccludedFlag};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r,releaseMaybe as i}from"../../../core/maybe.js";import{D as s,H as o,B as a,e as n,n as l,g as d,a as g,G as h}from"../../../chunks/vec32.js";import{create as u,clone as m}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{containsXY as c}from"../../../geometry/support/aaBoundingRect.js";import{earth as f}from"../../../geometry/support/Ellipsoid.js";import{glLayout as p}from"../support/buffer/glUtil.js";import{GeometryState as y}from"./GeometryState.js";import{PatchGeometry as x}from"./PatchGeometry.js";import{maxTileNeighborLevelDelta as _}from"./TerrainConst.js";import{internalAssert as v,neighborEdgeIndices as $,oppositeEdge as C,neighborCornerIndices as E,enableTerrainInternalChecks as S,v32s as D,lij2s as b}from"./terrainUtils.js";import{TextureFader as j}from"./TextureFader.js";import{TextureReference as R}from"./TextureReference.js";import V from"./TileOverlayData.js";import{fallsWithinLayerView as T}from"./tileUtils.js";import{VertexArrayObject as w}from"../webgl-engine/lib/VertexArrayObject.js";import{BufferObject as A}from"../../webgl/BufferObject.js";import{VertexBuffer as P}from"../../webgl/VertexBuffer.js";class N{constructor(){this.geometry=new x,this.geometryState=null,this._texture=null,this._textureOpacity=1,this._textureRef=new j(()=>this._tile.surface.fadeDuration),this.overlay=new V,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new y,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureRef.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),S&&this.tile.intersectsClippingArea)for(let t=0;t<4;++t)v(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.extent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,o=$[e];if(!t)return v(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(o)),i;if(t.loaded){const r=t,o=r.renderData.geometryState,a=s-r.level;if(v(a>=0),0===a){const e=o.numVerticesPerSide-1;return Math.max(e,i)}const n=2**a,l=o.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}v(!t.leaf);let a=i;return t.forAllSubtreeOnSide(C(o),e=>e===r||(e.loaded?(a=Math.max(a,2**(e.level-s)),!0):(v(!e.leaf),!1))),a}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.loaded||t.level===e.level)&&t?.intersectsClippingArea,s=r.edgePeerNeighbors,o=r.edgePeerNeighborSamplerVersions;for(let a=0;a<4;++a){const n=e.findNeighborTile($[a],i),l=X(e,n),d=l?.renderData?.geometryState.samplerDataVersion??-1,g=s[a],h=l!==X(e,g),u=o[a]!==d;S&&n&&(v(e.level>=n.level),v(e.level-n.level<=_)),s[a]=n,(h||u)&&(o[a]=d,this._markEdgeDirty(a));const m=r.edgeResolutions[a],c=this._calculateEdgeResolution(a,n);v(t(c)),v(c>=1),r.edgeResolutions[a]=c,m!==c&&this._markEdgeResolutionDirty(a)}for(let t=0;t<4;++t){const o=e.findNeighborTile(E[t],i);r.cornerPeerNeighbors[t]=o;const a=X(e,s[t]),n=X(e,s[(t+1)%4]),l=X(e,o);L[t]=l,L[(t+1)%4]=n,L[(t+2)%4]=e,L[(t+3)%4]=a,v(L.some(t=>t?.loaded||t===e));const d=L.reduce((e,t)=>Math.min(e,t?.level??1/0),1/0);L.forEach((e,t)=>{e&&e?.level>d&&(L[t]=null)}),v(L.some(t=>t?.loaded||t===e));const g=r.cornerNeighborCornerTiles,h=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<4;++e){const r=L[e],i=r?.renderData.geometryState.samplerDataVersion??-1,s=4*t+e,o=g[s]!==r,a=!o&&h[s]!==i;(o||a)&&(g[s]=r,h[s]=i,this._markCornerDirty(t))}S&&v(Q.some(r=>g[4*t+r]?.loaded||g[4*t+r]===e))}S&&v(this.geometryState.edgeResolutions.every(e=>e>0));for(let t=0;t<4;++t)L[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;S&&v(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every(e=>e>0)),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,o=!r||!{}||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged||this.numVerticesPerSideChanged,a=0!==this.dirtyEdgeResolutions,n=s.edgeResolutions.reduce((e,t)=>e+t+1,0),l=o||a&&n>(i?.maxEdgeVertexCount??0),d=!l&&a,g=!d&&(0!==this.dirtyEdges||a),h=!g&&0!==this.dirtyCorners;l?(this.releaseGeometry(),this._createGeometry(e)):d?t.updateEdgeElevationsAndResolutions():g||h?t.updateEdgeElevations():h?t.updateCornerElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r,i){const s=t?6408:6407;return null!=this._texture&&(0===r&&this._tile.surface.fadeDuration>0&&this._isTextureVisible(this._texture)||this._texture.descriptor.width!==e||this._texture.descriptor.pixelFormat!==s)&&this.releaseTexture(),null==this._texture&&(this._texture=i(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){this._texture&&(this._texture=i(this._texture),this.tile.setMemoryDirty())}reuseTexture(e,t){return!(!e||!this._texture)&&(e.setTextureReference(new R(this._texture,0,t,this._textureOpacity,0,1)),!0)}get numVerticesPerSideChanged(){return 0!==(this._modifiedFlags&B)}get samplerDataChanged(){return 0!==(this._modifiedFlags&H)}get clippingAreaChanged(){return 0!==(this._modifiedFlags&W)}get wireframeChanged(){return 0!==(this._modifiedFlags&q)}get dirtyEdges(){return this._modifiedFlags>>z&15}get dirtyCorners(){return this._modifiedFlags>>J&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>K&15}_markCornerDirty(e){const t=1<<e<<J;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<z;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<K;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<J|15<<z|15<<K}updateGeometryState(){const t=this._elevationInfo,r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.minimumVerticesPerSide,s=Math.max(i,5);let o=r.clippingArea;r.intersectsClippingArea&&!r.withinClippingArea||(o=null);const a=this.geometryState;let n=!1;a.numVerticesPerSide!==s&&(this._modifiedFlags|=1,a.numVerticesPerSide=s,a.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=2,a.samplerData=t.samplerData,a.samplerDataVersion++,n=!0),e(a.clippingArea,o)||(this._modifiedFlags=4,a.clippingArea=o,n=!0);const l=r.surface.wireframe;return a.wireframe!==l&&(this._modifiedFlags=8,a.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const{vertexAttributes:t,indices:r}=this.geometry,i=e.gl;this._vao=new w(e,new P(e,p(t.layout),t.buffer),A.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=0){e?.texture===this._texture?this._textureOpacity=e.opacities[0]:this.releaseTexture(),this._textureRef.push(e,t)}get textureReference(){return this._textureRef.current}get nextTextureReference(){return this._textureRef.next}get textureFadeFactor(){return this._textureRef.fadeFactor}get textureIsFading(){return this._textureRef.isFading}_isTextureVisible(e){return this._textureRef.current?.texture===e||this._textureRef.next?.texture===e&&this._textureRef.fadeFactor<1}get _elevationInfo(){const e=this.geometryState.samplerData,t=this.tile.layerInfo[0],r=t.length,i=new Array(r);let s=0,o=0,a=!1;for(let d=0;d<r;d++){const r=t[d],n=r.upsampleInfo?.tile;if(n){const t=n.layerInfo[0][d].data,r=t&&t.samplerData;e&&e[s]===r||(a=!0),i[s++]=r,o=Math.max(o,n.lij[0])}else if(r.data){const t=this.tile.surface.layerViewByIndex(d,0);if(T(this.tile,t)){const t=r.data;e&&e[s]===t.samplerData||(a=!0),i[s++]=t.samplerData,o=this.tile.level}}}null!=e&&e.length!==s&&(a=!0);const n=s>0,l=n?i:null;return n&&(i.length=s),{changed:a,samplerData:l,maxTileLevel:o}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){}checkGeometryWaterproofness(){if(!S)return;const e=this.tile;if(!e.loaded||!e.intersectsClippingArea||0===e.level)return void v(e?.loaded);const r=e.surface.extent;if(null!=r&&!e.intersectsExtent(r))return;const i=$.map((t,i)=>null!=r&&(i<2?-1:1)*(e.extent[3-i]-r[3-i])<0),p=e.level;v(0===this.dirtyCorners),v(0===this.dirtyEdges),v(0===this.dirtyEdgeResolutions),v(!this.numVerticesPerSideChanged),v(!this.samplerDataChanged),v(!this.clippingAreaChanged),v(!this.wireframeChanged);const y=E.map(t=>e.findNeighborCornerTileExact(t,t=>!t.intersectsClippingArea||t.loaded||t.level===e.level)??null).map(e=>e?.intersectsClippingArea?e:null),x=this.geometryState;for(let t=0;t<4;++t){const r=x.cornerPeerNeighbors[t],i=y[t];v(i===r,`Tile[${e.lij}].corner[${t}] out of date: cur=[${r?.lij}] exp=[${i?.lij}]`)}$.forEach((r,y)=>{if(i[y])return;const x=e.findNeighborTile(r,e=>(e.level===p||e?.loaded)&&e?.intersectsClippingArea);if(!x){const t=!e.surface.updatingRootTiles&&null!=e.surface.rootTiles&&e.surface.rootTiles.length>0&&e.shouldHaveNeighbor(r);return void v(!t)}v(x.loaded||x.level===e.level),v(x===this.geometryState.edgePeerNeighbors[y]);const _=p-x.level;if(!x.loaded)return v(!x.leaf),void v(0===_);const $=x.renderData;v(e.isEdgeNeighbor(x,r)),v(_>=0);const C=2**_;if(_<0)return void v(!1);const E=e.renderData,S=E.geometry,j=E.localOrigin,R=S.getEdgeCount(y),V=S.numVerticesPerSide-1,T=$.geometry;if(!T)return void v(!1);const w=$.localOrigin,A=this.geometryState.edgePeerNeighbors[y];if(A?.loaded){const e=A.renderData;v(E.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion),v(this.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion)}const P=(y+2)%4,N=T.getEdgeCount(P),L=R-1,X=N-1;v(L*C===X,`Tile[${e.lij}]:e${y},res=${L} edgeRes mismatch with Neighbor[${x.lij}]:e${P},res=${X} (expected:${L*C})`);const B=e.extent,H=0===r||4===r,W=N-1,q=W>>_,z=R-1;if(q<1)return void v(1===z);v(q===z),v(t(q));const J=T.numVerticesPerSide-1;v(_>0||q===Math.max(J,V));const K=e.getNeighborEdgeStartVertexIndex(y,x);v(0<=K&&K<C);const Q=K*q;v(0<=Q&&Q<=W-q);let Y=0,Z=Q;S.getEdgeVertexPosition(y,F,j,0),S.getEdgeVertexPosition(y,G,j,R-1);const ee=s(F,G),te=Math.max(I,1e-4*ee);for(let t=0;t<=q;++t){S.getEdgeVertexPosition(y,F,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=t/q,s=H?B[0]+i*(B[2]-B[0]):6===r?B[0]:B[2],p=H?4===r?B[1]:B[3]:B[1]+i*(B[3]-B[1]),_=e.surface.extent;if(null==_||c(_,s,p)){const t=o(F,G),r=a(F)-f.radius,i=a(G)-f.radius,c=t<te;if(!c){console.warn(`Tile edge vertex position mismatch: between [${e.lij}].edge${y}[${Y}/${R}] and [${x.lij}].edge${P}[${Z}/${N}]`),null!=_&&console.warn(" surface extent= ",_," x,y=",s,",",p);const o=u();n(o,E.localOrigin,$.localOrigin),a(o)>0&&console.warn(` localOrigins: ${E.localOrigin} vs ${$.localOrigin} d=${a(o)} [${o}]`);(()=>{const t=m(F),r=m(G);e.updateEdgeElevations(),x.updateEdgeElevations(),S.getEdgeVertexPosition(y,F,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=u();g(i,F,t),a(i)>0&&console.warn(` XXX Tile[${e.lij}] edge out of date: ${t} vs ${F} d=${a(i)} [${i}]`),g(i,G,r),a(i)>0&&console.warn(` XXX Neighbor[${x.lij}] edge out of date: ${r} vs ${G} d=${a(i)} [${i}]`)})();const l=S.getEdgeCount(y),d=T.getEdgeCount(N);v(c,`Mismatch in tile [${e.lij}].edge[${y}][${Y}/${l}] vs neighbor [${x.lij}].edge[${P}][${Z}/${d}] ${D(F)} vs ${D(G)} dist=${t} h(t|n|d)=${r}|${i}|${i-r}`)}S.getEdgeNormal(y,O,Y),T.getEdgeNormal(P,M,Z),l(k,O),l(U,M);const C=d(k,U),V=1-C<.01||!1||e===x;if(!V){const t=u();g(t,O,M);const r=()=>`Mismatch in tile edge normal ${b(e.lij)} (${Y}/${R-1}) edge ${y} vs neighbor ${b(x.lij)} (${Z}/${N-1}) nedge ${P} :${D(O)} vs ${D(M)} dot = ${C} : ${D(t)}`;console.warn("Mismatch in tile edge normal: ",r());{e.updateEdgeElevations(),x.updateEdgeElevations();const t=u(),r=u();S.getEdgeNormal(y,t,Y),T.getEdgeNormal(P,r,Z),h(O,t)||console.warn("Missing update in tile normal: ",D(O)," => ",D(t)),h(M,r)||console.warn("Missing update in neighbor normal: ",D(M)," => ",D(r))}v(V,r())}}Y+=1,Z+=1}})}}const F=u(),G=u(),O=u(),M=u(),k=u(),U=u(),I=1,L=[null,null,null,null];function X(e,t){return t?.loaded||t===e?t:null}const B=1,H=2,W=4,q=8,z=4,J=8,K=12,Q=[0,1,2,3];export{N as PatchRenderData,X as neighborTileIfLoadedOrSelf,Q as zeroToFour};
5
+ import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r,releaseMaybe as i}from"../../../core/maybe.js";import{C as s,G as o,H as a,e as n,n as l,g as d,a as g,F as h}from"../../../chunks/vec32.js";import{create as u,clone as m}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{containsXY as c}from"../../../geometry/support/aaBoundingRect.js";import{earth as f}from"../../../geometry/support/Ellipsoid.js";import{glLayout as p}from"../support/buffer/glUtil.js";import{GeometryState as y}from"./GeometryState.js";import{PatchGeometry as x}from"./PatchGeometry.js";import{maxTileNeighborLevelDelta as _}from"./TerrainConst.js";import{internalAssert as v,neighborEdgeIndices as $,oppositeEdge as E,neighborCornerIndices as C,enableTerrainInternalChecks as S,v32s as D,lij2s as b}from"./terrainUtils.js";import{TextureFader as j}from"./TextureFader.js";import{TextureReference as R}from"./TextureReference.js";import V from"./TileOverlayData.js";import{fallsWithinLayerView as T}from"./tileUtils.js";import{VertexArrayObject as w}from"../webgl-engine/lib/VertexArrayObject.js";import{BufferObject as A}from"../../webgl/BufferObject.js";import{VertexBuffer as P}from"../../webgl/VertexBuffer.js";class F{constructor(){this.geometry=new x,this.geometryState=null,this._texture=null,this._textureOpacity=1,this._textureRef=new j(()=>this._tile.surface.fadeDuration),this.overlay=new V,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new y,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureRef.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),S&&this.tile.intersectsClippingArea)for(let t=0;t<4;++t)v(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.groundExtent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,o=$[e];if(!t)return v(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(o)),i;if(t.loaded){const r=t,o=r.renderData.geometryState,a=s-r.level;if(v(a>=0),0===a){const e=o.numVerticesPerSide-1;return Math.max(e,i)}const n=2**a,l=o.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}v(!t.leaf);let a=i;return t.forAllSubtreeOnSide(E(o),e=>e===r||(e.loaded?(a=Math.max(a,2**(e.level-s)),!0):(v(!e.leaf),!1))),a}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.loaded||t.level===e.level)&&t?.intersectsClippingArea,s=r.edgePeerNeighbors,o=r.edgePeerNeighborSamplerVersions;for(let a=0;a<4;++a){const n=e.findNeighborTile($[a],i),l=X(e,n),d=l?.renderData?.geometryState.samplerDataVersion??-1,g=s[a],h=l!==X(e,g),u=o[a]!==d;S&&n&&(v(e.level>=n.level),v(e.level-n.level<=_)),s[a]=n,(h||u)&&(o[a]=d,this._markEdgeDirty(a));const m=r.edgeResolutions[a],c=this._calculateEdgeResolution(a,n);v(t(c)),v(c>=1),r.edgeResolutions[a]=c,m!==c&&this._markEdgeResolutionDirty(a)}for(let t=0;t<4;++t){const o=e.findNeighborTile(C[t],i);r.cornerPeerNeighbors[t]=o;const a=X(e,s[t]),n=X(e,s[(t+1)%4]),l=X(e,o);L[t]=l,L[(t+1)%4]=n,L[(t+2)%4]=e,L[(t+3)%4]=a,v(L.some(t=>t?.loaded||t===e));const d=L.reduce((e,t)=>Math.min(e,t?.level??1/0),1/0);L.forEach((e,t)=>{e&&e?.level>d&&(L[t]=null)}),v(L.some(t=>t?.loaded||t===e));const g=r.cornerNeighborCornerTiles,h=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<4;++e){const r=L[e],i=r?.renderData.geometryState.samplerDataVersion??-1,s=4*t+e,o=g[s]!==r,a=!o&&h[s]!==i;(o||a)&&(g[s]=r,h[s]=i,this._markCornerDirty(t))}S&&v(Q.some(r=>g[4*t+r]?.loaded||g[4*t+r]===e))}S&&v(this.geometryState.edgeResolutions.every(e=>e>0));for(let t=0;t<4;++t)L[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;S&&v(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every(e=>e>0)),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,o=!r||!{}||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged||this.numVerticesPerSideChanged,a=0!==this.dirtyEdgeResolutions,n=s.edgeResolutions.reduce((e,t)=>e+t+1,0),l=o||a&&n>(i?.maxEdgeVertexCount??0),d=!l&&a,g=!d&&(0!==this.dirtyEdges||a),h=!g&&0!==this.dirtyCorners;l?(this.releaseGeometry(),this._createGeometry(e)):d?t.updateEdgeElevationsAndResolutions():g||h?t.updateEdgeElevations():h?t.updateCornerElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r,i){const s=t?6408:6407;return null!=this._texture&&(0===r&&this._tile.surface.fadeDuration>0&&this._isTextureVisible(this._texture)||this._texture.descriptor.width!==e||this._texture.descriptor.pixelFormat!==s)&&this.releaseTexture(),null==this._texture&&(this._texture=i(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){this._texture&&(this._texture=i(this._texture),this.tile.setMemoryDirty())}reuseTexture(e,t){return!(!e||!this._texture)&&(e.setTextureReference(new R(this._texture,0,t,this._textureOpacity,0,1)),!0)}get numVerticesPerSideChanged(){return 0!==(this._modifiedFlags&B)}get samplerDataChanged(){return 0!==(this._modifiedFlags&H)}get clippingAreaChanged(){return 0!==(this._modifiedFlags&W)}get wireframeChanged(){return 0!==(this._modifiedFlags&q)}get dirtyEdges(){return this._modifiedFlags>>z&15}get dirtyCorners(){return this._modifiedFlags>>J&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>K&15}_markCornerDirty(e){const t=1<<e<<J;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<z;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<K;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<J|15<<z|15<<K}updateGeometryState(){const t=this._elevationInfo,r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.minimumVerticesPerSide,s=Math.max(i,5);let o=r.clippingArea;r.intersectsClippingArea&&!r.withinClippingArea||(o=null);const a=this.geometryState;let n=!1;a.numVerticesPerSide!==s&&(this._modifiedFlags|=1,a.numVerticesPerSide=s,a.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=2,a.samplerData=t.samplerData,a.samplerDataVersion++,n=!0),e(a.clippingArea,o)||(this._modifiedFlags=4,a.clippingArea=o,n=!0);const l=r.surface.wireframe;return a.wireframe!==l&&(this._modifiedFlags=8,a.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const{vertexAttributes:t,indices:r}=this.geometry,i=e.gl;this._vao=new w(e,new P(e,p(t.layout),t.buffer),A.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=0){e?.texture===this._texture?this._textureOpacity=e.opacities[0]:this.releaseTexture(),this._textureRef.push(e,t)}get textureReference(){return this._textureRef.current}get nextTextureReference(){return this._textureRef.next}get textureFadeFactor(){return this._textureRef.fadeFactor}get textureIsFading(){return this._textureRef.isFading}_isTextureVisible(e){return this._textureRef.current?.texture===e||this._textureRef.next?.texture===e&&this._textureRef.fadeFactor<1}get _elevationInfo(){const e=this.geometryState.samplerData,t=this.tile.layerInfo[0],r=t.length,i=new Array(r);let s=0,o=0,a=!1;for(let d=0;d<r;d++){const r=t[d],n=r.upsampleInfo?.tile;if(n){const t=n.layerInfo[0][d].data,r=t&&t.samplerData;e&&e[s]===r||(a=!0),i[s++]=r,o=Math.max(o,n.lij[0])}else if(r.data){const t=this.tile.surface.layerViewByIndex(d,0);if(T(this.tile,t)){const t=r.data;e&&e[s]===t.samplerData||(a=!0),i[s++]=t.samplerData,o=this.tile.level}}}null!=e&&e.length!==s&&(a=!0);const n=s>0,l=n?i:null;return n&&(i.length=s),{changed:a,samplerData:l,maxTileLevel:o}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){}checkGeometryWaterproofness(){if(!S)return;const e=this.tile;if(!e.loaded||!e.intersectsClippingArea||0===e.level)return void v(e?.loaded);const r=e.surface.groundExtent;if(null!=r&&!e.intersectsExtent(r))return;const i=$.map((t,i)=>null!=r&&(i<2?-1:1)*(e.extent[3-i]-r[3-i])<0),p=e.level;v(0===this.dirtyCorners),v(0===this.dirtyEdges),v(0===this.dirtyEdgeResolutions),v(!this.numVerticesPerSideChanged),v(!this.samplerDataChanged),v(!this.clippingAreaChanged),v(!this.wireframeChanged);const y=C.map(t=>e.findNeighborCornerTileExact(t,t=>!t.intersectsClippingArea||t.loaded||t.level===e.level)??null).map(e=>e?.intersectsClippingArea?e:null),x=this.geometryState;for(let t=0;t<4;++t){const r=x.cornerPeerNeighbors[t],i=y[t];v(i===r,`Tile[${e.lij}].corner[${t}] out of date: cur=[${r?.lij}] exp=[${i?.lij}]`)}$.forEach((r,y)=>{if(i[y])return;const x=e.findNeighborTile(r,e=>(e.level===p||e?.loaded)&&e?.intersectsClippingArea);if(!x){const t=!e.surface.updatingRootTiles&&null!=e.surface.rootTiles&&e.surface.rootTiles.length>0&&e.shouldHaveNeighbor(r);return void v(!t)}v(x.loaded||x.level===e.level),v(x===this.geometryState.edgePeerNeighbors[y]);const _=p-x.level;if(!x.loaded)return v(!x.leaf),void v(0===_);const $=x.renderData;v(e.isEdgeNeighbor(x,r)),v(_>=0);const E=2**_;if(_<0)return void v(!1);const C=e.renderData,S=C.geometry,j=C.localOrigin,R=S.getEdgeCount(y),V=S.numVerticesPerSide-1,T=$.geometry;if(!T)return void v(!1);const w=$.localOrigin,A=this.geometryState.edgePeerNeighbors[y];if(A?.loaded){const e=A.renderData;v(C.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion),v(this.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion)}const P=(y+2)%4,F=T.getEdgeCount(P),L=R-1,X=F-1;v(L*E===X,`Tile[${e.lij}]:e${y},res=${L} edgeRes mismatch with Neighbor[${x.lij}]:e${P},res=${X} (expected:${L*E})`);const B=e.extent,H=0===r||4===r,W=F-1,q=W>>_,z=R-1;if(q<1)return void v(1===z);v(q===z),v(t(q));const J=T.numVerticesPerSide-1;v(_>0||q===Math.max(J,V));const K=e.getNeighborEdgeStartVertexIndex(y,x);v(0<=K&&K<E);const Q=K*q;v(0<=Q&&Q<=W-q);let Y=0,Z=Q;S.getEdgeVertexPosition(y,N,j,0),S.getEdgeVertexPosition(y,G,j,R-1);const ee=s(N,G),te=Math.max(I,1e-4*ee);for(let t=0;t<=q;++t){S.getEdgeVertexPosition(y,N,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=t/q,s=H?B[0]+i*(B[2]-B[0]):6===r?B[0]:B[2],p=H?4===r?B[1]:B[3]:B[1]+i*(B[3]-B[1]),_=e.surface.groundExtent;if(null==_||c(_,s,p)){const t=o(N,G),r=a(N)-f.radius,i=a(G)-f.radius,c=t<te;if(!c){console.warn(`Tile edge vertex position mismatch: between [${e.lij}].edge${y}[${Y}/${R}] and [${x.lij}].edge${P}[${Z}/${F}]`),null!=_&&console.warn(" surface extent= ",_," x,y=",s,",",p);const o=u();n(o,C.localOrigin,$.localOrigin),a(o)>0&&console.warn(` localOrigins: ${C.localOrigin} vs ${$.localOrigin} d=${a(o)} [${o}]`);(()=>{const t=m(N),r=m(G);e.updateEdgeElevations(),x.updateEdgeElevations(),S.getEdgeVertexPosition(y,N,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=u();g(i,N,t),a(i)>0&&console.warn(` XXX Tile[${e.lij}] edge out of date: ${t} vs ${N} d=${a(i)} [${i}]`),g(i,G,r),a(i)>0&&console.warn(` XXX Neighbor[${x.lij}] edge out of date: ${r} vs ${G} d=${a(i)} [${i}]`)})();const l=S.getEdgeCount(y),d=T.getEdgeCount(F);v(c,`Mismatch in tile [${e.lij}].edge[${y}][${Y}/${l}] vs neighbor [${x.lij}].edge[${P}][${Z}/${d}] ${D(N)} vs ${D(G)} dist=${t} h(t|n|d)=${r}|${i}|${i-r}`)}S.getEdgeNormal(y,O,Y),T.getEdgeNormal(P,M,Z),l(k,O),l(U,M);const E=d(k,U),V=1-E<.01||!1||e===x;if(!V){const t=u();g(t,O,M);const r=()=>`Mismatch in tile edge normal ${b(e.lij)} (${Y}/${R-1}) edge ${y} vs neighbor ${b(x.lij)} (${Z}/${F-1}) nedge ${P} :${D(O)} vs ${D(M)} dot = ${E} : ${D(t)}`;console.warn("Mismatch in tile edge normal: ",r());{e.updateEdgeElevations(),x.updateEdgeElevations();const t=u(),r=u();S.getEdgeNormal(y,t,Y),T.getEdgeNormal(P,r,Z),h(O,t)||console.warn("Missing update in tile normal: ",D(O)," => ",D(t)),h(M,r)||console.warn("Missing update in neighbor normal: ",D(M)," => ",D(r))}v(V,r())}}Y+=1,Z+=1}})}}const N=u(),G=u(),O=u(),M=u(),k=u(),U=u(),I=1,L=[null,null,null,null];function X(e,t){return t?.loaded||t===e?t:null}const B=1,H=2,W=4,q=8,z=4,J=8,K=12,Q=[0,1,2,3];export{F as PatchRenderData,X as neighborTileIfLoadedOrSelf,Q as zeroToFour};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import s from"../../../core/ObjectPool.js";import r from"../../../core/PooledArray.js";import{property as i,subclass as o}from"../../../core/accessorSupport/decorators.js";import{d as u}from"../../../chunks/vec42.js";import{create as n}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";class l{constructor(){this.extent=n(),this.minLevel=0,this.maxLevel=0,this.callback=null}}let a=class extends t{constructor(){super(...arguments),this._queries=new r({initialSize:10}),this._queriesInvPtr=0,this._queryQueue=new r({initialSize:30}),this._queryPool=new s(()=>new l)}queryVisibleLevelRange(e,t,s,r){const i=this._queryPool.acquire();u(i.extent,e),i.minLevel=t??-Number.MAX_VALUE,i.maxLevel=s??Number.MAX_VALUE,i.callback=r,this._queryQueue.push(i),this.notifyChange("updating")}get updating(){return 0!==this._queryQueue.length}prepare(){for(;this._queries.length<this._queries.data.length&&this._queryQueue.length>0;){const e=this._queryQueue.pop();this._queries.push(e)}this._queriesInvPtr=this._queries.length}process(){for(let e=0;e<this._queries.length;e++){const t=this._queries.data[e];this._queryPool.release(t),t.callback(e>=this._queriesInvPtr),t.callback=null}this._queries.clear(),this.notifyChange("updating")}queriesForTile(e){const t=e.level;let s=0;for(;s<this._queriesInvPtr;){const r=this._queries.data[s],i=r.extent;t>=r.minLevel&&t<=r.maxLevel&&i[0]<=e.extent[2]&&i[2]>=e.extent[0]&&i[1]<=e.extent[3]&&i[3]>=e.extent[1]?(this._queries.swapElements(s,this._queriesInvPtr-1),this._queriesInvPtr--):s++}}};e([i()],a.prototype,"updating",null),a=e([o("esri.views.3d.terrain.ScaleRangeQueries")],a);export{a as ScaleRangeQueries};
5
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import s from"../../../core/ObjectPool.js";import r from"../../../core/PooledArray.js";import{property as i,subclass as o}from"../../../core/accessorSupport/decorators.js";import{f as u}from"../../../chunks/vec42.js";import{create as n}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";class l{constructor(){this.extent=n(),this.minLevel=0,this.maxLevel=0,this.callback=null}}let a=class extends t{constructor(){super(...arguments),this._queries=new r({initialSize:10}),this._queriesInvPtr=0,this._queryQueue=new r({initialSize:30}),this._queryPool=new s(()=>new l)}queryVisibleLevelRange(e,t,s,r){const i=this._queryPool.acquire();u(i.extent,e),i.minLevel=t??-Number.MAX_VALUE,i.maxLevel=s??Number.MAX_VALUE,i.callback=r,this._queryQueue.push(i),this.notifyChange("updating")}get updating(){return 0!==this._queryQueue.length}prepare(){for(;this._queries.length<this._queries.data.length&&this._queryQueue.length>0;){const e=this._queryQueue.pop();this._queries.push(e)}this._queriesInvPtr=this._queries.length}process(){for(let e=0;e<this._queries.length;e++){const t=this._queries.data[e];this._queryPool.release(t),t.callback(e>=this._queriesInvPtr),t.callback=null}this._queries.clear(),this.notifyChange("updating")}queriesForTile(e){const t=e.level;let s=0;for(;s<this._queriesInvPtr;){const r=this._queries.data[s],i=r.extent;t>=r.minLevel&&t<=r.maxLevel&&i[0]<=e.extent[2]&&i[2]>=e.extent[0]&&i[1]<=e.extent[3]&&i[3]>=e.extent[1]?(this._queries.swapElements(s,this._queriesInvPtr-1),this._queriesInvPtr--):s++}}};e([i()],a.prototype,"updating",null),a=e([o("esri.views.3d.terrain.ScaleRangeQueries")],a);export{a as ScaleRangeQueries};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{lerp as t}from"../../../core/mathUtils.js";import{n as e,h as i,i as s,j as n,B as o,f as r,g as a,H as l,a as h}from"../../../chunks/vec32.js";import{ZEROS as u,create as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lonLatToSphericalPCPF as d}from"../../../geometry/projection/lonLatToSphericalPCPF.js";import{newDoubleArray as p}from"../../../geometry/support/DoubleArray.js";import{intersectsSphere as f,numPlanes as m}from"../../../geometry/support/frustum.js";import{Sphere as g}from"../../../geometry/support/sphere.js";import{createSphericalGlobePatch as x,updateCornerSpherical as $,updateEdgesAndCornersSpherical as v,updateEdgeElevationsAndResolutionsSpherical as M}from"./PatchGeometryFactory.js";import{enableTerrainInternalChecks as _,internalAssert as b,almostEquals as j}from"./terrainUtils.js";import{Tile as y}from"./Tile.js";import{compareTilesByLij as B}from"./tileUtils.js";class S extends y{constructor(t,e,i,s,n){super(),this._convexHull=new Array(24),this._boundingSphere=new g,this._baseUsedMemory=1816,this.init(t,e,i,s,n)}init(i,s,n,o,r){super.init(i,s,n,o,r);const a=this.ellipsoid.radius,l=this.extentInRadians[0],h=this.extentInRadians[1],u=this.extentInRadians[2],c=this.extentInRadians[3],p=t(h,c,.5),f=t(l,u,.5),m=0===i?0:Math.min(Math.abs(h),Math.abs(c));this._edgeLen=(u-l)*Math.cos(m)*a,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=a-Math.sqrt(a*a-this._edgeLen2/4),d(this.centerAtSeaLevel,f,p,this.ellipsoid.radius),e(this.up,this.centerAtSeaLevel),this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateBoundingVolumes();const t=this._center;if(0===this.lij[0])t[1].center=u,i(t[0],0,0,0),i(t[2],0,0,0),t[1].radius=this.ellipsoid.radius+this.elevationBoundsMax;else{this._updateCenter();const e=t[1],i=this.convexHull;let s=0;const n=e.center;for(let t=0;t<8;++t)s=Math.max(s,H(n,i,3*t));t[1].radius=Math.sqrt(s)}}_calculateFrustumVisibility(t){if(!f(t,this._boundingSphere))return 2;if(this.lij[0]<10)return 1;const e=this.convexHull,i=this.surface.view.state.camera.near;let s=!0;for(let n=0;n<m;n++){const o=4===n,r=t[n],a=r[0],l=r[1],h=r[2],u=r[3]-(o?i:0);let c=!1;for(let t=0;t<8;++t){const i=3*t;if(a*e[i]+l*e[i+1]+h*e[i+2]+u<0){if(c=!0,!s)break}else s=!1}if(!c)return 2}return s?0:1}computeElevationBounds(){super.computeElevationBounds(),this._updateBoundingVolumes()}createGeometry(){x(this.renderData,this._getPatchType()),this._updateBoundingVolumes(),this.setMemoryDirty()}_updateBoundingVolumes(){this._updateConvexHull(),this._updateBoundingSphere(),_&&this._checkBVs()}_updateBoundingSphere(){const t=this._boundingSphere,e=this.elevationBoundsMin,i=this.elevationBoundsMax,r=this.ellipsoid.radius,a=i;if(0===this.level)t.center=u,t.radius=r+a;else{const a=this.extentInRadians,l=.5*(a[0]+a[2]),h=a[1],u=a[3];T(I,l,h,r),T(L,l,u,r),s(t.center,I,L);const c=r+.5*(e+i);n(t.center,t.center,c/o(t.center));const d=this.convexHull;let p=0;const f=(t,e)=>{const i=t[0]-d[3*e],s=t[1]-d[3*e+1],n=t[2]-d[3*e+2];return Math.sqrt(i*i+s*s+n*n)};for(let e=0;e<8;++e){const i=f(t.center,e);p=Math.max(p,i)}const m=p;t.radius=m+2}}_updateConvexHull(){const t=this.extentInRadians,i=this.ellipsoid.radius;if(0===this.level)return;const l=this.elevationBoundsMin,u=this.elevationBoundsMax,d=this._getPatchType(),p=this.surface.isWebMercator,f=p&&1===d,m=p&&2===d,g=m||f,x=Math.PI/2,$=t[0],v=t[2],M=m?-x:t[1],_=f?x:t[3],y=.5*($+v),B=l,S=i+(g?Math.min(0,B-1):B),V=(t,e,i)=>T(t,e,i,S),H=c(),R=c(),I=c(),L=c();V(H,$,M),V(R,$,_),V(I,v,_),V(L,v,M);const P=(t,e)=>{for(let i=0;i<3;++i)this._convexHull[3*e+i]=t[i]};P(H,0),P(R,1),P(I,2),P(L,3);const F=u,A=i+(g?Math.max(0,F+1):F),k=c(),D=c(),E=c();T(D,y,_,S),T(E,y,M,S),s(k,D,E),e(k,k);const w=c(),U=c(),q=(t,i)=>{h(U,t,i),e(U,U);const o=-a(t,w)/a(U,w);b(o>=0),n(U,U,o),s(t,t,U)};if(2**this.lij[0]>2*this.lij[1]){const t=E,i=c();r(i,C,t),e(i,i),r(w,t,i),e(w,w),b(j(a(w,t)/o(t),0)),q(H,R),q(L,I),P(H,0),P(L,3)}else if(2**this.lij[0]!==2*this.lij[1]){const t=D,i=c();r(i,C,t),e(i,i),r(w,i,t),e(w,w),q(R,H),q(I,L),P(R,1),P(I,2)}const N=(t,e)=>{const i=A/a(e,k);for(let s=0;s<3;++s)this._convexHull[3*t+s]=e[s]*i};N(4,H),N(5,R),N(6,I),N(7,L)}_getPatchType(){const t=this.lij[1],e=0===t,i=t===(1<<this.level)-1;return e?i?3:1:i?2:0}intersectsRay(t,e,i,s){const n=this._boundingSphere,o=n.radius+i,r=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],a=n.center[0]-t[0],l=n.center[1]-t[1],h=n.center[2]-t[2],u=(a*e[0]+l*e[1]+h*e[2])/r,c=e[0]*u-a,d=e[1]*u-l,p=e[2]*u-h;return c*c+d*d+p*p<o*o}get minimumVerticesPerSide(){return this.level<V.length?V[this.level]+1:2}updateCornerElevations(){$(this.renderData),this._updateBoundingVolumes()}updateEdgeElevations(){v(this.renderData),this._updateBoundingVolumes()}updateEdgeElevationsAndResolutions(){M(this.renderData),this._updateBoundingVolumes()}_checkBVs(){if(!_)return;if(this.level<=2)return;const t=this._boundingSphere,i=t.radius,n=t.center,u=c(),d=this.ellipsoid.radius,f=this.elevationBoundsMin,m=this.elevationBoundsMax,g=d+f,x=1,$=0,v=this._center[1];v.center;const M=v.radius,y=this.convexHull,S=(t,e)=>{for(let i=0;i<3;++i)t[i]=y[3*e+i]};{const t=c(),i=c(),s=c(),n=c(),o=c(),l=(l,u,c,d)=>{S(i,l),S(s,u),S(n,c),h(i,i,s),h(n,n,s),r(t,i,n),e(t,t);const p=a(t,s);S(o,d);const f=a(t,o),m=Math.abs(f-p);b(j(m,0),`Non coplanar ${l},${u},${c},${d} diff = ${m}`)};l(0,1,2,3),l(4,5,6,7),l(0,1,4,5),l(1,2,5,6),l(2,3,6,7),l(3,0,7,4)}const V=p(24),H=(t,e,i)=>{const s=4*t;for(let n=0;n<3;++n)V[s+n]=e[n];V[s+3]=i},C=c(),I=c(),L=c(),P=c(),F=(t,i,s,n)=>{S(C,i),S(I,s),S(L,n),h(C,C,I),e(C,C),h(L,L,I),e(L,L),r(P,C,L),e(P,P);const o=a(P,I);H(t,P,o)};F(0,0,1,2),F(1,1,0,4),F(2,1,5,2),F(3,3,2,6),F(4,4,0,3),F(5,4,6,5);const A=(t,e,i,s)=>{const n=4*t;return V[n]*e+V[n+1]*i+V[n+2]*s-V[n+3]},k=(t,e,i,s)=>A(t,e,i,s)>=-1,D=(t,e)=>k(t,e[0],e[1],e[2]),E=2**this.lij[0]>2*this.lij[1],w=(t,e,s)=>Math.sqrt(R(t,e,s,n[0],n[1],n[2]))<i,U=t=>w(t[0],t[1],t[2]),q=(t,e)=>w(t[e],t[e+1],t[e+2]),N=this.extentInRadians,G=.5*(N[0]+N[2]),z=N[1],O=N[3],W=c(),J=c();T(W,G,O,g),T(J,G,z,g);const K=E?"Upper":"Lower";let Q=!0;for(let e=0;e<6;++e){for(let t=0;t<8;++t){const i=3*t,s=k(e,y[i],y[i+1],y[i+2]);Q&&=s,b(s,`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}b(D(e,J),`Tile[${this.lij}] (${K}) bottom mid outside of plane ${e}`),b(D(e,W),`Tile[${this.lij}] (${K}) top mid outside of plane ${e}`)}b(Q,"Not all convex hull points are inside convex hull polyhedron"),b(U(J),`Tile[${this.lij}] (${K}) bottom mid outside of bounding sphere`),b(U(W),`Tile[${this.lij}] (${K}) top mid outside of bounding sphere`);for(let e=0;e<8;++e){const t=q(y,3*e);b(t,`Tile[${this.lij}] Convex hull point ${e} outside of bounding sphere`)}for(let e=0;e<6;++e)for(let t=0;t<8;++t){const i=3*t;k(e,y[i],y[i+1],y[i+2])||console.error(`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}const{extentInRadians:X}=this,Y=Math.max(X[2]-X[0],X[3]-X[1]),Z=Math.round(Y*d),{renderData:tt}=this;if(!tt)return;const{geometry:et,geometryState:it,localOrigin:st}=tt,nt=et.vertexAttributes?.position;if(!nt)return;const ot=c(),rt=et.numVerticesPerSide-2,{indices:at,indexCount:lt,edgeVerticesStartIndex:ht,poleVerticesStartIndex:ut}=et;if(!at)return;const ct=new Set;for(let e=0;e<lt;++e){const t=at[e];if(ct.has(t))continue;ct.add(t);const r=t<ut,a=t>=ht;let h=!1,c=-1;if(a){let e=ht;for(let i=0;i<4;++i){const s=it.edgeResolutions[i];if(t===e||t===e+s-1){h=!0;break}if(e+=s,t<e){c=i;break}}}const p=a?it.edgePeerNeighbors[c]:null,g=a&&p&&B(this,p)>0;nt.getVec(t,u),s(ot,u,st);const v=o(ot)-d;let _=0,b=!1;const j=f-v,y=v-m,S=j>x,V=y>x,H=S||V,R=()=>{const e=r?"internal":a&&!h?"edge":h?"corner":"pole";return`Tile[${this.lij}].vertex[${t}]:${e}`+(S?"(below)":V?"(above)":"")+(g?"(Neighbor)":"")},T=l(ot,n);if(T>=i+$){const t=T-i;H||(console.error(`${R()} is out of the bounding sphere by ${t.toFixed(0)} / ${i.toFixed(0)}[tol=${$}] h=${v.toFixed(0)} / [${f.toFixed(0)}..${m.toFixed(0)}] (${(t/i).toFixed(0)})`),b=!0)}for(let e=0;e<6;++e)if(!k(e,ot[0],ot[1],ot[2])){const s=A(e,ot[0],ot[1],ot[2]),n=t%rt,o=(t-n)/rt;0===e&&j||5===e&&y||(console.error(`${R()} (${n},${o})|${rt}] is out of the bounding trapezoid plane ${e} h=${Math.round(v)} / [${Math.round(f)}..${Math.round(m)}] dist=${Math.round(s)} radii = ${Math.round(i)}/${Math.round(M)}} : maxL = ${Z}`),++_)}if(b||_>0)break}}get convexHull(){return this._convexHull}}const V=[128,64,64,32,16,8,8,4];function H(t,e,i){return R(t[0],t[1],t[2],e[i],e[i+1],e[i+2])}function R(t,e,i,s,n,o){const r=s-t,a=n-e,l=o-i;return r*r+a*a+l*l}const T=(t,e,i,s)=>{const n=Math.cos(e),o=Math.sin(e),r=Math.cos(i),a=Math.sin(i);t[0]=s*r*n,t[1]=s*r*o,t[2]=s*a},C=[0,0,1],I=c(),L=c();export{S as SphericalPatch};
5
+ import{lerp as t}from"../../../core/mathUtils.js";import{n as e,h as i,i as s,j as n,H as o,f as r,g as a,G as l,a as h}from"../../../chunks/vec32.js";import{ZEROS as u,create as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lonLatToSphericalPCPF as d}from"../../../geometry/projection/lonLatToSphericalPCPF.js";import{newDoubleArray as p}from"../../../geometry/support/DoubleArray.js";import{intersectsSphere as f,numPlanes as m}from"../../../geometry/support/frustum.js";import{Sphere as g}from"../../../geometry/support/sphere.js";import{createSphericalGlobePatch as x,updateCornerSpherical as $,updateEdgesAndCornersSpherical as v,updateEdgeElevationsAndResolutionsSpherical as M}from"./PatchGeometryFactory.js";import{enableTerrainInternalChecks as _,internalAssert as b,almostEquals as j}from"./terrainUtils.js";import{Tile as y}from"./Tile.js";import{compareTilesByLij as B}from"./tileUtils.js";class S extends y{constructor(t,e,i,s,n){super(),this._convexHull=new Array(24),this._boundingSphere=new g,this._baseUsedMemory=1816,this.init(t,e,i,s,n)}init(i,s,n,o,r){super.init(i,s,n,o,r);const a=this.ellipsoid.radius,l=this.extentInRadians[0],h=this.extentInRadians[1],u=this.extentInRadians[2],c=this.extentInRadians[3],p=t(h,c,.5),f=t(l,u,.5),m=0===i?0:Math.min(Math.abs(h),Math.abs(c));this._edgeLen=(u-l)*Math.cos(m)*a,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=a-Math.sqrt(a*a-this._edgeLen2/4),d(this.centerAtSeaLevel,f,p,this.ellipsoid.radius),e(this.up,this.centerAtSeaLevel),this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateBoundingVolumes();const t=this._center;if(0===this.lij[0])t[1].center=u,i(t[0],0,0,0),i(t[2],0,0,0),t[1].radius=this.ellipsoid.radius+this.elevationBoundsMax;else{this._updateCenter();const e=t[1],i=this.convexHull;let s=0;const n=e.center;for(let t=0;t<8;++t)s=Math.max(s,H(n,i,3*t));t[1].radius=Math.sqrt(s)}}_calculateFrustumVisibility(t){if(!f(t,this._boundingSphere))return 2;if(this.lij[0]<10)return 1;const e=this.convexHull,i=this.surface.view.state.camera.near;let s=!0;for(let n=0;n<m;n++){const o=4===n,r=t[n],a=r[0],l=r[1],h=r[2],u=r[3]-(o?i:0);let c=!1;for(let t=0;t<8;++t){const i=3*t;if(a*e[i]+l*e[i+1]+h*e[i+2]+u<0){if(c=!0,!s)break}else s=!1}if(!c)return 2}return s?0:1}computeElevationBounds(){super.computeElevationBounds(),this._updateBoundingVolumes()}createGeometry(){x(this.renderData,this._getPatchType()),this._updateBoundingVolumes(),this.setMemoryDirty()}_updateBoundingVolumes(){this._updateConvexHull(),this._updateBoundingSphere(),_&&this._checkBVs()}_updateBoundingSphere(){const t=this._boundingSphere,e=this.elevationBoundsMin,i=this.elevationBoundsMax,r=this.ellipsoid.radius,a=i;if(0===this.level)t.center=u,t.radius=r+a;else{const a=this.extentInRadians,l=.5*(a[0]+a[2]),h=a[1],u=a[3];T(I,l,h,r),T(L,l,u,r),s(t.center,I,L);const c=r+.5*(e+i);n(t.center,t.center,c/o(t.center));const d=this.convexHull;let p=0;const f=(t,e)=>{const i=t[0]-d[3*e],s=t[1]-d[3*e+1],n=t[2]-d[3*e+2];return Math.sqrt(i*i+s*s+n*n)};for(let e=0;e<8;++e){const i=f(t.center,e);p=Math.max(p,i)}const m=p;t.radius=m+2}}_updateConvexHull(){const t=this.extentInRadians,i=this.ellipsoid.radius;if(0===this.level)return;const l=this.elevationBoundsMin,u=this.elevationBoundsMax,d=this._getPatchType(),p=this.surface.isWebMercator,f=p&&1===d,m=p&&2===d,g=m||f,x=Math.PI/2,$=t[0],v=t[2],M=m?-x:t[1],_=f?x:t[3],y=.5*($+v),B=l,S=i+(g?Math.min(0,B-1):B),V=(t,e,i)=>T(t,e,i,S),H=c(),R=c(),I=c(),L=c();V(H,$,M),V(R,$,_),V(I,v,_),V(L,v,M);const P=(t,e)=>{for(let i=0;i<3;++i)this._convexHull[3*e+i]=t[i]};P(H,0),P(R,1),P(I,2),P(L,3);const F=u,A=i+(g?Math.max(0,F+1):F),k=c(),D=c(),E=c();T(D,y,_,S),T(E,y,M,S),s(k,D,E),e(k,k);const w=c(),U=c(),q=(t,i)=>{h(U,t,i),e(U,U);const o=-a(t,w)/a(U,w);b(o>=0),n(U,U,o),s(t,t,U)};if(2**this.lij[0]>2*this.lij[1]){const t=E,i=c();r(i,C,t),e(i,i),r(w,t,i),e(w,w),b(j(a(w,t)/o(t),0)),q(H,R),q(L,I),P(H,0),P(L,3)}else if(2**this.lij[0]!==2*this.lij[1]){const t=D,i=c();r(i,C,t),e(i,i),r(w,i,t),e(w,w),q(R,H),q(I,L),P(R,1),P(I,2)}const N=(t,e)=>{const i=A/a(e,k);for(let s=0;s<3;++s)this._convexHull[3*t+s]=e[s]*i};N(4,H),N(5,R),N(6,I),N(7,L)}_getPatchType(){const t=this.lij[1],e=0===t,i=t===(1<<this.level)-1;return e?i?3:1:i?2:0}intersectsRay(t,e,i,s){const n=this._boundingSphere,o=n.radius+i,r=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],a=n.center[0]-t[0],l=n.center[1]-t[1],h=n.center[2]-t[2],u=(a*e[0]+l*e[1]+h*e[2])/r,c=e[0]*u-a,d=e[1]*u-l,p=e[2]*u-h;return c*c+d*d+p*p<o*o}get minimumVerticesPerSide(){return this.level<V.length?V[this.level]+1:2}updateCornerElevations(){$(this.renderData),this._updateBoundingVolumes()}updateEdgeElevations(){v(this.renderData),this._updateBoundingVolumes()}updateEdgeElevationsAndResolutions(){M(this.renderData),this._updateBoundingVolumes()}_checkBVs(){if(!_)return;if(this.level<=2)return;const t=this._boundingSphere,i=t.radius,n=t.center,u=c(),d=this.ellipsoid.radius,f=this.elevationBoundsMin,m=this.elevationBoundsMax,g=d+f,x=1,$=0,v=this._center[1];v.center;const M=v.radius,y=this.convexHull,S=(t,e)=>{for(let i=0;i<3;++i)t[i]=y[3*e+i]};{const t=c(),i=c(),s=c(),n=c(),o=c(),l=(l,u,c,d)=>{S(i,l),S(s,u),S(n,c),h(i,i,s),h(n,n,s),r(t,i,n),e(t,t);const p=a(t,s);S(o,d);const f=a(t,o),m=Math.abs(f-p);b(j(m,0),`Non coplanar ${l},${u},${c},${d} diff = ${m}`)};l(0,1,2,3),l(4,5,6,7),l(0,1,4,5),l(1,2,5,6),l(2,3,6,7),l(3,0,7,4)}const V=p(24),H=(t,e,i)=>{const s=4*t;for(let n=0;n<3;++n)V[s+n]=e[n];V[s+3]=i},C=c(),I=c(),L=c(),P=c(),F=(t,i,s,n)=>{S(C,i),S(I,s),S(L,n),h(C,C,I),e(C,C),h(L,L,I),e(L,L),r(P,C,L),e(P,P);const o=a(P,I);H(t,P,o)};F(0,0,1,2),F(1,1,0,4),F(2,1,5,2),F(3,3,2,6),F(4,4,0,3),F(5,4,6,5);const A=(t,e,i,s)=>{const n=4*t;return V[n]*e+V[n+1]*i+V[n+2]*s-V[n+3]},k=(t,e,i,s)=>A(t,e,i,s)>=-1,D=(t,e)=>k(t,e[0],e[1],e[2]),E=2**this.lij[0]>2*this.lij[1],w=(t,e,s)=>Math.sqrt(R(t,e,s,n[0],n[1],n[2]))<i,U=t=>w(t[0],t[1],t[2]),q=(t,e)=>w(t[e],t[e+1],t[e+2]),N=this.extentInRadians,G=.5*(N[0]+N[2]),z=N[1],O=N[3],W=c(),J=c();T(W,G,O,g),T(J,G,z,g);const K=E?"Upper":"Lower";let Q=!0;for(let e=0;e<6;++e){for(let t=0;t<8;++t){const i=3*t,s=k(e,y[i],y[i+1],y[i+2]);Q&&=s,b(s,`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}b(D(e,J),`Tile[${this.lij}] (${K}) bottom mid outside of plane ${e}`),b(D(e,W),`Tile[${this.lij}] (${K}) top mid outside of plane ${e}`)}b(Q,"Not all convex hull points are inside convex hull polyhedron"),b(U(J),`Tile[${this.lij}] (${K}) bottom mid outside of bounding sphere`),b(U(W),`Tile[${this.lij}] (${K}) top mid outside of bounding sphere`);for(let e=0;e<8;++e){const t=q(y,3*e);b(t,`Tile[${this.lij}] Convex hull point ${e} outside of bounding sphere`)}for(let e=0;e<6;++e)for(let t=0;t<8;++t){const i=3*t;k(e,y[i],y[i+1],y[i+2])||console.error(`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}const{extentInRadians:X}=this,Y=Math.max(X[2]-X[0],X[3]-X[1]),Z=Math.round(Y*d),{renderData:tt}=this;if(!tt)return;const{geometry:et,geometryState:it,localOrigin:st}=tt,nt=et.vertexAttributes?.position;if(!nt)return;const ot=c(),rt=et.numVerticesPerSide-2,{indices:at,indexCount:lt,edgeVerticesStartIndex:ht,poleVerticesStartIndex:ut}=et;if(!at)return;const ct=new Set;for(let e=0;e<lt;++e){const t=at[e];if(ct.has(t))continue;ct.add(t);const r=t<ut,a=t>=ht;let h=!1,c=-1;if(a){let e=ht;for(let i=0;i<4;++i){const s=it.edgeResolutions[i];if(t===e||t===e+s-1){h=!0;break}if(e+=s,t<e){c=i;break}}}const p=a?it.edgePeerNeighbors[c]:null,g=a&&p&&B(this,p)>0;nt.getVec(t,u),s(ot,u,st);const v=o(ot)-d;let _=0,b=!1;const j=f-v,y=v-m,S=j>x,V=y>x,H=S||V,R=()=>{const e=r?"internal":a&&!h?"edge":h?"corner":"pole";return`Tile[${this.lij}].vertex[${t}]:${e}`+(S?"(below)":V?"(above)":"")+(g?"(Neighbor)":"")},T=l(ot,n);if(T>=i+$){const t=T-i;H||(console.error(`${R()} is out of the bounding sphere by ${t.toFixed(0)} / ${i.toFixed(0)}[tol=${$}] h=${v.toFixed(0)} / [${f.toFixed(0)}..${m.toFixed(0)}] (${(t/i).toFixed(0)})`),b=!0)}for(let e=0;e<6;++e)if(!k(e,ot[0],ot[1],ot[2])){const s=A(e,ot[0],ot[1],ot[2]),n=t%rt,o=(t-n)/rt;0===e&&j||5===e&&y||(console.error(`${R()} (${n},${o})|${rt}] is out of the bounding trapezoid plane ${e} h=${Math.round(v)} / [${Math.round(f)}..${Math.round(m)}] dist=${Math.round(s)} radii = ${Math.round(i)}/${Math.round(M)}} : maxL = ${Z}`),++_)}if(b||_>0)break}}get convexHull(){return this._convexHull}}const V=[128,64,64,32,16,8,8,4];function H(t,e,i){return R(t[0],t[1],t[2],e[i],e[i+1],e[i+2])}function R(t,e,i,s,n,o){const r=s-t,a=n-e,l=o-i;return r*r+a*a+l*l}const T=(t,e,i,s)=>{const n=Math.cos(e),o=Math.sin(e),r=Math.cos(i),a=Math.sin(i);t[0]=s*r*n,t[1]=s*r*o,t[2]=s*a},C=[0,0,1],I=c(),L=c();export{S as SphericalPatch};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import has from"../../../core/has.js";import{disposeMaybe as i}from"../../../core/maybe.js";import{MemCachePool as r}from"../../../core/MemCachePool.js";import s from"../../../core/ObjectPool.js";import{watch as n,sync as a}from"../../../core/reactiveUtils.js";import{property as l,subclass as o}from"../../../core/accessorSupport/decorators.js";import{e as c,h as d,g as h}from"../../../chunks/vec32.js";import{ZEROS as u,create as _,fromValues as g}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as f,ZEROS as p}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as m,set as b}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as y}from"../../../geometry/support/buffer/BufferView.js";import{overlayRenderOccludedFlag as T}from"./OverlayRenderer.js";import{PatchRenderData as x}from"./PatchRenderData.js";import{TerrainAttributesCache as R}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as v}from"./terrainUtils.js";import{TileRenderer as O}from"./TileRenderer.js";import{IteratorPreorder as P,sortTiles as w,compareTiles as D}from"./tileUtils.js";import{getOverlayContentForOutputTerrain as S}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as B,ConsumesDepth as E,ConsumesNone as C}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as F}from"../webgl-engine/lib/Attribute.js";import{IntersectorResult as j}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as q,MeshIntersectionOptions as A,intersectTriangles as k}from"../webgl-engine/lib/RayIntersections.js";import{TriangleIntersectionData as M}from"../webgl-engine/lib/TriangleIntersectionData.js";import{terrainId as G,getVerticalOffsetTerrain as U}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as N}from"../webgl-engine/materials/DrawParameters.js";import{T as I}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as L}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as V}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as z}from"../../webgl/enums.js";const H=7,W=10,Q=200,Z=m();let J=class extends B{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return 1===this._stage.viewingMode}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}constructor(e,t,i,n,a){super({}),this._overlayRenderer=e,this._stage=t,this._allTiles=i,this._compressionTracker=n,this.type=7,this.isGround=!0,this._passParameters=new I,this._drawParameters=new N,this._renderDataPool=new s(()=>new x),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new P,this._castShadows=!1,this._inViewshed=!1,this._cutFillEnabled=!1,this._tileRenderer=null,this._stencilEnabledLayerExtents=new Array,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.renderOccludedFlags=1,this.produces=new Map([[1,()=>this._produces()&&0===this.transparency],[6,()=>this._produces()&&(1===this.transparency||2===this.transparency)],[9,()=>this._produces()&&this.renderOccludedFlags===T]]),this._tileSize=256,this._configuration=new V(1===t.viewingMode),this._tileTextureCache=new r((e,t)=>a.newCache(e,t),"TileTexture"),this.tileGeometryCache=new R(a)}normalizeCtorArgs(){return{}}initialize(){this._stage.addRenderPlugin(this),this.addHandles(n(()=>this._overlayRenderer.renderOccludedFlags,e=>{this.renderOccludedFlags=e,this.setNeedsRender()},a))}destroy(){this._stage.removeRenderPlugin(this),this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}consumes(){return this._overlayRenderer.hasWater?E:C}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setDirty()}set visible(e){this._set("visible",!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.setNeedsRender())}get transparency(){return this._configuration.transparencyMode}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get cullBackFaces(){return this._configuration.backfaceCullingEnabled}set cullBackFaces(e){this._configuration.backfaceCullingEnabled!==e&&(this._configuration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}get layerViewUid(){return G}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.setNeedsRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.setNeedsRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,null!=this._tileRenderer&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,32)}reuseTextureFromParent(e){const t=e.parent;if(!t)return!1;const i=f(1&e.lij[2]?.5:0,1&e.lij[1]?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,i)??!1}updateTileTexture(e,t){null!=this._tileRenderer&&(this._tileRenderer.updateTileTexture(e,32===t?0:2),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(const i of e.layerInfo[0])i.pendingUpdates&=-9;e.resetPendingUpdate(8);const t=e.renderData.updateGeometryState();return t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){const t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){const t=W-H,i=Math.max(0,Math.floor((e.level-t)/H)*H);if(this._isGlobal&&0===i)return u;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this.setNeedsRender())}setDirty(e=1){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=1){this._patchSortingDirty=!0,this._context.requestRender(e)}setNeedsRender(e=1){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new O(this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=i(this._tileRenderer)}intersect(e,t,i,r){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&0!==this.transparency)return;const s=K,n=X;c(s,r,i),d(n,1/s[0],1/s[1],1/s[2]);const a=e.results.min,l=e.results.max,o=e.results.ground,u=0===e.options.store,_=!!e.results.ground.target,g=U(e.verticalOffset),f=e.tolerance;let p,m=u&&null!=a.distance?a.distance:1/0;const T=e.options,x=T.normalRequired||!T.backfacesTerrain,R=new A(f,!1,x),v=d=>{const _=d.renderData;if(!_?.vao)return;const v=_.geometry;b(Z,v.boundingBox);const O=_.localOrigin;null!=g&&(g.localOrigin=O,g.applyToAabb(Z));const P=Z;if(Y[0]=i[0]-O[0],Y[1]=i[1]-O[1],Y[2]=i[2]-O[2],!q(P,Y,n,f,m))return;const w=(e,t,i)=>{e.set(this.type,d,t,i),m=u&&null!=a.distance?a.distance:1/0},D=(n,c,d)=>{if((!x||null!=d)&&n>=0&&(T.backfacesTerrain||h(d,s)<0)&&(T.invisibleTerrain||!T.selectionMode||null==t||t(i,r,n))){if((null==o.distance||n<o.distance)&&w(o,n,d),T.isFiltered)return;2===T.store&&(null==p?(p=new j(e.ray),w(p,n,d),e.results.all.push(p)):n<p.distance&&w(p,n,d)),(null==a.distance||n<a.distance)&&w(a,n,d),0!==T.store&&(null==l.distance||n>l.distance)&&w(l,n,d)}},S=$;c(S,r,O);const{indices:B,indexCount:E}=v,C=v.vertexAttributes,A=C.getField("position",y),G=new F(A.typedBuffer,3,C.stride/4),U=E/3;if(!g&&U>Q){const e=d.renderData;e.intersectionData??=new M(B,U,G),e.intersectionData.intersectRay(Y,S,R,D)}else k(Y,S,0,U,B,G,g,R,D)},O=this._rootTiles;if(null!=O){(()=>{const t=this._tileIterator;t.reset(O);const r=e.options.invisibleTerrain;for(let e=t.next();e;e=t.next())!(e.visible||r&&e.intersectsClippingArea)||null==g&&!e.intersectsRay(i,s,f,m)||_&&this._useStencilForTile(e)?t.skipSubtree():v(e)})()}}processScaleRangeQueries(e,t){if(!t.done&&e)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(const t of this._visiblePatchesByOrigin.values())for(const i of t)null!=i.renderData?.textureReference&&e.queriesForTile(i);e.process(),t.madeProgress()}}acquireTechniques(e){const t=!!has("enable-feature:terrain-shadows")&&e.bind.shadowMap.enabled;t!==this._castShadows&&(this._castShadows=t,this._patchesByOriginDirty=!0);const i=e.bind.viewshedEnabled;this._inViewshed!==i&&(this._inViewshed=i,this._patchesByOriginDirty=!0);const r=e.bind.cutFillEnabled;if(this._cutFillEnabled!==r&&(this._cutFillEnabled=r,this._patchesByOriginDirty=!0),9===e.bind.slot){if(0===(e.renderOccludedMask&T))return null}else{const t=0===this.transparency?1:6;if(e.bind.slot!==t)return null}if(3===this.transparency)return null;const s=this._configuration;switch(s.screenSpaceReflections=s.cloudReflections=s.receiveShadows=s.receiveAmbientOcclusion=s.renderOccluded=s.hasHighlightMixTexture=!1,s.overlayMode=this._overlayRenderer.mode,e.output){case 0:{s.screenSpaceReflections=null!=e.bind.ssr.lastFrameColor,s.cloudReflections=null!=e.bind.clouds.data;const t=9===e.bind.slot;return s.receiveShadows=e.bind.shadowMap.ready&&!t,s.renderOccluded=t,s.receiveAmbientOcclusion=!t&&null!=e.bind.ssao,this._acquireTechnique(e.output)}case 3:case 5:return this._castShadows?this._acquireTechnique(3):null;case 6:return this._inViewshed?this._acquireTechnique(6):null;case 7:return this._cutFillEnabled?this._acquireTechnique(7):null;case 1:case 2:return this._acquireTechnique(e.output);case 9:return this._acquireTechnique(9);case 8:return s.hasHighlightMixTexture=null!=e.bind.highlightMixTexture,this._overlayRenderer.hasHighlights?this._acquireTechnique(8):null}return null}render(e,t){switch(this._updatePatchGroups(),t.useStencil=!1,this._passParameters.overlayContent=S(e.output,e.bind),e.output){case 0:return this._renderMaterialPass(e,t);case 1:case 2:case 9:return this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);case 8:{const i=e.bind.highlight?.name;i&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(2)&&this._overlayRenderer.hasHighlight(i)&&this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);break}case 3:case 5:case 6:case 7:return this._renderAuxiliaryPass(e,t,this._allPatchesByOrigin)}}updateTileBackground(e){if(null==this._tileRenderer)return;const i=this._tileRenderer;let r;if(null!=e){const i=t.toUnitRGBA(e);r=g(i[0]||0,i[1]||0,i[2]||0)}i.setBackground(r),this._allTiles.forAll(e=>i.updateTileTexture(e,0)),this._configuration.tileBlendInput=i.backgroundIsGrid?2:null!=i.backgroundColor?1:0,this.setNeedsRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty){const e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(const i of e)w(i,t);e.sort((e,t)=>D(e[0],t[0])),this._visiblePatchesByOrigin=new Map(e.map(e=>[e[0].renderData.localOrigin,e])),this.notifyChange("visibleTiles"),this._patchSortingDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(null!=e){e[0]?.surface.checkAllTilesWaterproofness(),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(const t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){const t=this._tileIterator;for(t.resetOne(e);!t.done;){const e=t.next(),i=e.renderData;if(!i){this._numTilesCulled++;continue}const r=i.localOrigin;if(this._castShadows||this._inViewshed||this._cutFillEnabled){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let s=this._visiblePatchesByOrigin.get(r);s||(s=[],this._visiblePatchesByOrigin.set(r,s)),s.push(e),t.skipSubtree()}}_useStencilForTile(e){for(const t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderAuxiliaryPass(e,t,i){const{rctx:r,bind:s}=e;r.bindTechnique(t,s,this._passParameters);const n=this._stencilEnabledLayerExtents.length>0;i.forEach(e=>{this._drawParameters.origin=e[0].renderData.localOrigin,t.program.bindDraw(s,this._passParameters,this._drawParameters);for(let i=0;i<e.length;i++)this._renderPatch(r,t,e[i],z.TRIANGLES,n,null===this._passParameters.overlayContent)}),r.bindVAO(null)}_renderMaterialPass(e,t){const{rctx:i,bind:r}=e;i.bindTechnique(t,r,this._passParameters),this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;const s=t.program,n=this._stencilEnabledLayerExtents.length>0,a=9===r.slot;a&&(s.bindTexture("tex",i.emptyTexture),s.setUniform3fv("textureOpacities",u),s.setUniform4fv("texOffsetAndScale",p));const l=null!=this._tileRenderer?.backgroundColor?this._tileRenderer.backgroundColor:u;1===this._configuration.tileBlendInput&&s.setUniform3fv("backgroundColor",l);const o=this.wireframe?z.LINES:z.TRIANGLES;this._configuration.textureFadingEnabled&&s.bindTexture("texNext",i.emptyTexture);const c=this._visiblePatchesByOrigin;for(const d of c.values()){const e=d[0].renderData.localOrigin;this._drawParameters.origin=e,t.program.bindDraw(r,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(const r of d){const e=r.renderData,l=e.textureReference;if(null!=l){if(!a){s.setUniform4fv("texOffsetAndScale",l.offsetAndScale),s.bindTexture("tex",l.texture.texture);const t=e.textureFadeFactor,i=t<1?e.nextTextureReference:null;this._configuration.textureFadingEnabled&&i&&t<1?(s.setUniform1f("fadeFactor",t),s.setUniform4fv("nextTexOffsetAndScale",i.offsetAndScale),s.setUniform3fv("nextTexOpacities",i.opacities),s.bindTexture("texNext",i.texture.texture)):s.setUniform1f("fadeFactor",1),e.textureIsFading&&this.setNeedsRender(2),s.setUniform3fv("textureOpacities",l.opacities)}this._renderPatch(i,t,r,o,n),r.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}i.bindVAO(null)}_renderPatch(e,t,i,r,s,n=!1){const a=i.renderData,l=a.vao,o=l?.indexBuffer;if(!l||null==o)return void(v&&console.error("Rendered tile with no indices: ",i.lij," : ",a));const c=t.program;n||this._overlayRenderer.isEmpty||this._bindOverlayPatchData(c,a.overlay),s&&(t.useStencil=this._useStencilForTile(i),e.setPipelineState(t.getPipeline()));const d=a.geometry.indexCount;e.bindVAO(l),c.assertCompatibleVertexAttributeLocations(l),e.drawElements(r,d,o.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_acquireTechnique(e){return this._configuration.output=e,this._techniques.get(L,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([l({readOnly:!0})],J.prototype,"visibleTiles",null),e([l({readOnly:!0})],J.prototype,"_isGlobal",null),e([l()],J.prototype,"renderOccludedFlags",void 0),e([l({value:!1})],J.prototype,"renderingDisabled",null),e([l({value:!0})],J.prototype,"visible",null),e([l()],J.prototype,"renderPatchBorders",null),e([l()],J.prototype,"cullBackFaces",null),e([l()],J.prototype,"wireframe",null),J=e([o("esri.views.3d.terrain.TerrainRenderer")],J);const K=_(),X=_(),Y=_(),$=_();export{J as TerrainRenderer};
5
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import has from"../../../core/has.js";import{disposeMaybe as i}from"../../../core/maybe.js";import{MemCachePool as r}from"../../../core/MemCachePool.js";import s from"../../../core/ObjectPool.js";import{watch as n,sync as a}from"../../../core/reactiveUtils.js";import{property as o,subclass as l}from"../../../core/accessorSupport/decorators.js";import{e as c,h as d,g as h}from"../../../chunks/vec32.js";import{ZEROS as u,create as _,fromValues as g}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as f,ZEROS as p}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as m,set as y}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as b}from"../../../geometry/support/buffer/BufferView.js";import{overlayRenderOccludedFlag as T}from"./OverlayRenderer.js";import{PatchRenderData as x}from"./PatchRenderData.js";import{TerrainAttributesCache as v}from"./TerrainAttributesCache.js";import{enableTerrainInternalChecks as R}from"./terrainUtils.js";import{TileRenderer as P}from"./TileRenderer.js";import{IteratorPreorder as O,sortTiles as w,compareTiles as D}from"./tileUtils.js";import{getOverlayContentForOutputTerrain as S}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{SyncRenderPlugin as B,ConsumesDepth as E,ConsumesNone as j}from"../webgl-engine/effects/RenderPlugin.js";import{Vertices as F}from"../webgl-engine/lib/Attribute.js";import{IntersectorResult as q}from"../webgl-engine/lib/IntersectorResult.js";import{intersectAabbInvDirBefore as C,MeshIntersectionOptions as A,intersectTriangles as G}from"../webgl-engine/lib/RayIntersections.js";import{TriangleIntersectionData as M}from"../webgl-engine/lib/TriangleIntersectionData.js";import{terrainId as k,getVerticalOffsetTerrain as U}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as N}from"../webgl-engine/materials/DrawParameters.js";import{T as I}from"../../../chunks/Terrain.glsl.js";import{TerrainTechnique as L}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as V}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{PrimitiveType as z}from"../../webgl/enums.js";const H=7,W=10,Q=200,Z=m();let J=class extends B{get visibleTiles(){return Array.from(this._visiblePatchesByOrigin.values()).flat()}get _isGlobal(){return 1===this._stage.viewingMode}get _techniques(){return this._context.techniques}get _rctx(){return this._context.renderContext.rctx}constructor(e,t,i,n,a){super({}),this._overlayRenderer=e,this._stage=t,this._allTiles=i,this._compressionTracker=n,this.type=7,this.isGround=!0,this._passParameters=new I,this._drawParameters=new N,this._renderDataPool=new s(()=>new x),this._visiblePatchesByOrigin=new Map,this._allPatchesByOrigin=new Map,this._patchesByOriginDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new O,this._castShadows=!1,this._inViewshed=!1,this._cutFillEnabled=!1,this._tileRenderer=null,this._stencilEnabledLayerExtents=new Array,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.renderOccludedFlags=1,this._oitGround=!!has("enable-feature:oit-ground"),this.produces=new Map([[1,()=>1===this._desiredSlot],[6,()=>6===this._desiredSlot],[7,()=>7===this._desiredSlot],[10,()=>this._produces()&&this.renderOccludedFlags===T]]),this._tileSize=256,this._configuration=new V(1===t.viewingMode),this._tileTextureCache=new r((e,t)=>a.newCache(e,t),"TileTexture"),this.tileGeometryCache=new v(a)}normalizeCtorArgs(){return{}}initialize(){this._stage.addRenderPlugin(this),this.addHandles(n(()=>this._overlayRenderer.renderOccludedFlags,e=>{this.renderOccludedFlags=e,this.setNeedsRender()},a))}destroy(){this._stage.removeRenderPlugin(this),this._tileTextureCache.destroy(),this.tileGeometryCache.destroy(),this._allTiles.prune(),this._tileRenderer=null}_produces(){return this.visible&&!!this._rootTiles&&!this.renderingDisabled}consumes(){return this._overlayRenderer.hasWater?E:j}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setDirty()}set visible(e){this._set("visible",!!e),this.setDirty()}updateHeading(e){this._tileRenderer?.updateHeading(e)}set transparency(e){this._configuration.transparencyMode!==e&&(this._configuration.transparencyMode=e,this.setNeedsRender())}get transparency(){return this._configuration.transparencyMode}get renderPatchBorders(){return this._configuration.tileBorders}set renderPatchBorders(e){this._configuration.tileBorders!==e&&(this._configuration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get layerViewUid(){return k}get slicePlaneEnabled(){return this._configuration.hasSlicePlane}set slicePlaneEnabled(e){this._configuration.hasSlicePlane!==e&&(this._configuration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._configuration.textureFadingEnabled!==e&&(this._configuration.textureFadingEnabled=e,this.setNeedsRender())}set pbrMode(e){this._configuration.pbrMode!==e&&(this._configuration.pbrMode=e,this.setNeedsRender())}setRootTiles(e){this._rootTiles=e,this.setDirty()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}set tileSize(e){this._tileSize=e,null!=this._tileRenderer&&(this._tileRenderer.tileSize=e),this.setDirty()}get tileSize(){return this._tileSize}_ensureRenderData(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e,this._getLocalOriginOfTile(e)))}loadTile(e){this._ensureRenderData(e),this.updateTileGeometryState(e),this.reuseTextureFromParent(e)||this.updateTileTexture(e,32)}reuseTextureFromParent(e){const t=e.parent;if(!t)return!1;const i=f(1&e.lij[2]?.5:0,1&e.lij[1]?0:.5,.5,.5);return t.renderData?.reuseTexture(e.renderData,i)??!1}updateTileTexture(e,t){null!=this._tileRenderer&&(this._tileRenderer.updateTileTexture(e,32===t?0:2),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){for(const i of e.layerInfo[0])i.pendingUpdates&=-9;e.resetPendingUpdate(8);const t=e.renderData.updateGeometryState();return t&&this.setDirty(),t}updateGeometryIfNeeded(e){e.loaded&&e.renderData.updateGeometryIfNeeded(this._rctx)}unloadTile(e){const t=e.renderData;t&&(t.releaseGeometry(),this._renderDataPool.release(t),t.clear(),e.renderData=null,e.setMemoryDirty(),this.setDirty())}_getLocalOriginOfTile(e){const t=W-H,i=Math.max(0,Math.floor((e.level-t)/H)*H);if(this._isGlobal&&0===i)return u;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this.setNeedsRender())}setDirty(e=1){this._patchesByOriginDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=1){this._patchSortingDirty=!0,this._context.requestRender(e)}setNeedsRender(e=1){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._tileRenderer=new P(this._rctx,this._tileSize,this._techniques,this._tileTextureCache,this._compressionTracker),this.updateTileBackground()}uninitializeRenderContext(){this._tileRenderer=i(this._tileRenderer)}intersect(e,t,i,r){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&0!==this.transparency)return;const s=K,n=X;c(s,r,i),d(n,1/s[0],1/s[1],1/s[2]);const a=e.results.min,o=e.results.max,l=e.results.ground,u=0===e.options.store,_=!!e.results.ground.target,g=U(e.verticalOffset),f=e.tolerance;let p,m=u&&null!=a.distance?a.distance:1/0;const T=e.options,x=T.normalRequired||!T.backfacesTerrain,v=new A(f,!1,x),R=d=>{const _=d.renderData;if(!_?.vao)return;const R=_.geometry;y(Z,R.boundingBox);const P=_.localOrigin;null!=g&&(g.localOrigin=P,g.applyToAabb(Z));const O=Z;if(Y[0]=i[0]-P[0],Y[1]=i[1]-P[1],Y[2]=i[2]-P[2],!C(O,Y,n,f,m))return;const w=(e,t,i)=>{e.set(this.type,d,t,i),m=u&&null!=a.distance?a.distance:1/0},D=(n,c,d)=>{if((!x||null!=d)&&n>=0&&(T.backfacesTerrain||h(d,s)<0)&&(T.invisibleTerrain||!T.selectionMode||null==t||t(i,r,n))){if((null==l.distance||n<l.distance)&&w(l,n,d),T.isFiltered)return;2===T.store&&(null==p?(p=new q(e.ray),w(p,n,d),e.results.all.push(p)):n<p.distance&&w(p,n,d)),(null==a.distance||n<a.distance)&&w(a,n,d),0!==T.store&&(null==o.distance||n>o.distance)&&w(o,n,d)}},S=$;c(S,r,P);const{indices:B,indexCount:E}=R,j=R.vertexAttributes,A=j.getField("position",b),k=new F(A.typedBuffer,3,j.stride/4),U=E/3;if(!g&&U>Q){const e=d.renderData;e.intersectionData??=new M(B,U,k),e.intersectionData.intersectRay(Y,S,v,D)}else G(Y,S,0,U,B,k,g,v,D)},P=this._rootTiles;if(null!=P){(()=>{const t=this._tileIterator;t.reset(P);const r=e.options.invisibleTerrain;for(let e=t.next();e;e=t.next())!(e.visible||r&&e.intersectsClippingArea)||null==g&&!e.intersectsRay(i,s,f,m)||_&&this._useStencilForTile(e)?t.skipSubtree():R(e)})()}}processScaleRangeQueries(e,t){if(!t.done&&e)for(this._updatePatchGroups();e.updating&&!t.done;){e.prepare();for(const t of this._visiblePatchesByOrigin.values())for(const i of t)null!=i.renderData?.textureReference&&e.queriesForTile(i);e.process(),t.madeProgress()}}get _desiredSlot(){if(!this._produces())return null;switch(this.transparency){case 0:return 1;case 1:case 2:return this._oitGround?7:6;case 3:case 4:return null}}acquireTechniques(e){const{shadowMap:t,viewshedEnabled:i,cutFillEnabled:r,slot:s,oitPass:n,hasEmission:a}=e.bind,o=!!has("enable-feature:terrain-shadows")&&t.enabled;if(o!==this._castShadows&&(this._castShadows=o,this._patchesByOriginDirty=!0),this._inViewshed!==i&&(this._inViewshed=i,this._patchesByOriginDirty=!0),this._cutFillEnabled!==r&&(this._cutFillEnabled=r,this._patchesByOriginDirty=!0),3===this.transparency)return null;if(10===s){if(0===(e.renderOccludedMask&T))return null}else if(s!==this._desiredSlot)return null;const l=this._configuration;switch(l.screenSpaceReflections=l.cloudReflections=l.receiveShadows=l.receiveAmbientOcclusion=l.renderOccluded=l.hasHighlightMixTexture=l.hasEmission=!1,l.overlayMode=this._overlayRenderer.mode,l.oitPass=0,e.output){case 0:{const{ssr:i,clouds:r,ssao:o}=e.bind;l.screenSpaceReflections=null!=i.lastFrameColor,l.cloudReflections=null!=r.data;const c=10===s;return l.receiveShadows=t.ready&&!c,l.renderOccluded=c,l.receiveAmbientOcclusion=!c&&null!=o,l.oitPass=n,l.hasEmission=a,this._acquireTechnique(e.output)}case 3:case 5:return this._castShadows?this._acquireTechnique(3):null;case 6:return this._inViewshed?this._acquireTechnique(6):null;case 7:return this._cutFillEnabled?this._acquireTechnique(7):null;case 1:case 2:return this._acquireTechnique(e.output);case 9:return this._acquireTechnique(9);case 8:return l.hasHighlightMixTexture=null!=e.bind.highlightMixTexture,this._overlayRenderer.hasHighlights?this._acquireTechnique(8):null}return null}render(e,t){switch(this._updatePatchGroups(),t.useStencil=!1,this._passParameters.overlayContent=S(e.output,e.bind),e.output){case 0:return this._renderMaterialPass(e,t);case 1:case 2:case 9:return this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);case 8:{const i=e.bind.highlight?.name;i&&this._overlayRenderer.hasHighlights&&this._overlayRenderer.renders(2)&&this._overlayRenderer.hasHighlight(i)&&this._renderAuxiliaryPass(e,t,this._visiblePatchesByOrigin);break}case 3:case 5:case 6:case 7:return this._renderAuxiliaryPass(e,t,this._allPatchesByOrigin)}}updateTileBackground(e){if(null==this._tileRenderer)return;const i=this._tileRenderer;let r;if(null!=e){const i=t.toUnitRGBA(e);r=g(i[0]||0,i[1]||0,i[2]||0)}i.setBackground(r),this._allTiles.forAll(e=>i.updateTileTexture(e,0)),this._configuration.tileBlendInput=i.backgroundIsGrid?2:null!=i.backgroundColor?1:0,this.setNeedsRender()}_updatePatchGroups(){if(this._patchesByOriginDirty&&(this._rebuildPatchGroups(),this._patchesByOriginDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty){const e=Array.from(this._visiblePatchesByOrigin.values()),t=this._stencilEnabledLayerExtents;for(const i of e)w(i,t);e.sort((e,t)=>D(e[0],t[0])),this._visiblePatchesByOrigin=new Map(e.map(e=>[e[0].renderData.localOrigin,e])),this.notifyChange("visibleTiles"),this._patchSortingDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(null!=e){e[0]?.surface.checkAllTilesWaterproofness(),this._visiblePatchesByOrigin.clear(),this._allPatchesByOrigin.clear();for(const t of e)this._rebuildPatchGroupsForRootTile(t)}}_rebuildPatchGroupsForRootTile(e){const t=this._tileIterator;for(t.resetOne(e);!t.done;){const e=t.next(),i=e.renderData;if(!i){this._numTilesCulled++;continue}const r=i.localOrigin;if(this._castShadows||this._inViewshed||this._cutFillEnabled){let t=this._allPatchesByOrigin.get(r);t||(t=[],this._allPatchesByOrigin.set(r,t)),t.push(e)}if(!e.visible){this._numTilesCulled++,t.skipSubtree();continue}let s=this._visiblePatchesByOrigin.get(r);s||(s=[],this._visiblePatchesByOrigin.set(r,s)),s.push(e),t.skipSubtree()}}_useStencilForTile(e){for(const t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderAuxiliaryPass(e,t,i){const{rctx:r,bind:s}=e;r.bindTechnique(t,s,this._passParameters);const n=this._stencilEnabledLayerExtents.length>0;i.forEach(i=>{this._drawParameters.origin=i[0].renderData.localOrigin,t.program.bindDraw(s,this._passParameters,this._drawParameters);for(let r=0;r<i.length;r++)this._renderPatch(e,t,i[r],z.TRIANGLES,n,null===this._passParameters.overlayContent)}),r.bindVAO(null)}_renderMaterialPass(e,t){const{rctx:i,bind:r}=e,s=i.bindTechnique(t,r,this._passParameters);this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0;const n=10===r.slot;n&&(s.bindTexture("tex",i.emptyTexture),s.setUniform3fv("textureOpacities",u),s.setUniform4fv("texOffsetAndScale",p));const a=null!=this._tileRenderer?.backgroundColor?this._tileRenderer.backgroundColor:u;1===this._configuration.tileBlendInput&&s.setUniform3fv("backgroundColor",a);const o=this._stencilEnabledLayerExtents.length>0,l=this.wireframe?z.LINES:z.TRIANGLES;7===r.slot&&i.setFrontFace(r.camera.aboveGround?2305:2304),this._configuration.textureFadingEnabled&&s.bindTexture("texNext",i.emptyTexture);const c=this._visiblePatchesByOrigin;for(const d of c.values()){const i=d[0].renderData.localOrigin;this._drawParameters.origin=i,t.program.bindDraw(r,this._passParameters,this._drawParameters),this._numOriginsRendered++;for(const r of d){const i=r.renderData,a=i.textureReference;if(null!=a){if(!n){s.setUniform4fv("texOffsetAndScale",a.offsetAndScale),s.bindTexture("tex",a.texture.texture);const e=i.textureFadeFactor,t=e<1?i.nextTextureReference:null;this._configuration.textureFadingEnabled&&t&&e<1?(s.setUniform1f("fadeFactor",e),s.setUniform4fv("nextTexOffsetAndScale",t.offsetAndScale),s.setUniform3fv("nextTexOpacities",t.opacities),s.bindTexture("texNext",t.texture.texture)):s.setUniform1f("fadeFactor",1),i.textureIsFading&&this.setNeedsRender(2),s.setUniform3fv("textureOpacities",a.opacities)}this._renderPatch(e,t,r,l,o),r.renderOrder=this._numTilesRendered,this._numTilesRendered++}}}i.bindVAO(null)}_renderPatch(e,t,i,r,s,n=!1){const a=i.renderData,o=a.vao,l=o?.indexBuffer;if(!o||null==l)return void(R&&console.error("Rendered tile with no indices: ",i.lij," : ",a));const c=t.program;n||this._overlayRenderer.isEmpty||this._bindOverlayPatchData(c,a.overlay);const{rctx:d,bind:h}=e;s&&(t.useStencil=this._useStencilForTile(i),d.setPipelineState(t.getPipeline(h)));const u=a.geometry.indexCount;d.bindVAO(o),c.assertCompatibleVertexAttributeLocations(o),d.drawElements(r,u,l.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_acquireTechnique(e){return this._configuration.output=e,this._techniques.get(L,this._configuration)}get test(){}hasHighlight(e){return this._overlayRenderer.hasHighlight(e)}};e([o({readOnly:!0})],J.prototype,"visibleTiles",null),e([o({readOnly:!0})],J.prototype,"_isGlobal",null),e([o()],J.prototype,"renderOccludedFlags",void 0),e([o({value:!1})],J.prototype,"renderingDisabled",null),e([o({value:!0})],J.prototype,"visible",null),e([o()],J.prototype,"renderPatchBorders",null),e([o()],J.prototype,"wireframe",null),J=e([l("esri.views.3d.terrain.TerrainRenderer")],J);const K=_(),X=_(),Y=_(),$=_();export{J as TerrainRenderer};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as m}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as y,sync as f,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/units.js";import{property as w,subclass as C}from"../../../core/accessorSupport/decorators.js";import{m as S,h as b,d as E}from"../../../chunks/vec32.js";import{create as x}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as U}from"../../../geometry/ellipsoidUtils.js";import R from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as k,intersection as V,intersectsSphere as A,empty as B,expand as O}from"../../../geometry/support/aaBoundingRect.js";import{copy as G,create as N}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as q}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as W}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as $}from"../../../layers/support/layerUtils.js";import{debugFlags as Q}from"../support/debugFlags.js";import{ElevationRange as z}from"../support/ElevationRange.js";import{toBoundingRect as Y}from"../support/extentUtils.js";import{updatingProgress as X}from"../support/updatingProperties.js";import{ElevationBounds as K}from"./ElevationBounds.js";import{ElevationData as J,sampleElevation as Z}from"./ElevationData.js";import{ElevationUpdateEventImplementation as ee}from"./ElevationUpdateEvent.js";import{create as te}from"./ExtentHelper.js";import{LayerClasses as ie}from"./LayerClass.js";import{OverlayManager as re}from"./OverlayManager.js";import{PlanarPatch as se}from"./PlanarPatch.js";import{Queue as ae}from"./Queue.js";import{ScaleRangeQueries as ne}from"./ScaleRangeQueries.js";import{SphericalPatch as le}from"./SphericalPatch.js";import{SplitLimits as oe}from"./SplitLimits.js";import{maxRootTiles as he,tooManyRootTilesAfterChangeError as de,tooManyRootTilesForLayerError as pe,maxTileNeighborLevelDelta as ue,maxMemoryLodBias as ce}from"./TerrainConst.js";import{TerrainRenderer as ge}from"./TerrainRenderer.js";import me from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as _e,isVectorTileLayerView as ye,neighborEdgeIndices as fe,internalAssert as Te,oppositeEdge as ve,isSurfaceLayerView as we,isGroupLayerView as Ce,isMapTileLayerView as Se,isBlendableLayerView as be,isElevationLayerView as Ee,releaseTerrainData as xe,enableTerrainInternalChecks as Le,oppositeCorner as Pe,enableWaterproofTests as Ue,enableInternalTerrainChecks as Re,enableTerrainWaterproofChecks as Me,neighborCornerIndices as De}from"./terrainUtils.js";import{Tile as je,lijEquals as Ie}from"./Tile.js";import{printAllocations as ke}from"./TilePerLayerInfo.js";import{sortTiles as Ve,IteratorPreorder as Ae,IteratorPostorder as Be,compareTilesByLij as Oe,hasLoadableSiblings as Ge,sortTilesByPOI as Ne}from"./tileUtils.js";import{TilingSchemeLogic as qe}from"./TilingSchemeLogic.js";import{UpsampleInfo as Fe}from"./UpsampleInfo.js";import{isCompositeBlendMode as We,blendModeFromString as He}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as $e}from"../../support/layerViewUtils.js";import{ImmediateTask as Qe,TaskPriority as ze,noBudget as Ye}from"../../support/Scheduler.js";import{TextureCompressionTracker as Xe}from"../../support/TextureCompressionTracker.js";import{Yield as Ke}from"../../support/Yield.js";var Je;let Ze=class extends n{static{Je=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ve(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new Xe,this._iteratorPool=new p(()=>new Ae,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Be,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new me,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=x(),this._eyePosSurfaceSR=x(),this._splitLimits=new oe,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Qe,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new Fe),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=R.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new z(1/0,-1/0),this.rootTileElevationRange=new z(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?le:se,this._ellipsoid=P(t.spatialReference),this._renderer=new ge(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),$e()||(this._scaleRangeQueries=new ne)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new H(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([_(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),_(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([_(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},y),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),y),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},f),_(()=>this.snapLevel,()=>this._viewChanged=!0,f),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:S})}),_(()=>Q.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&Q.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=te(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new qe({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(ze.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),f),_(()=>this.extent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),y),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),_(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),_(()=>this._userClippingExtent,()=>this._updateClippingExtent(),f)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Qe,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),je.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),ke(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get _userClippingExtent(){const{spatialReference:e}=this,t=this.view?.clippingArea;if(null==t||null==e)return null;const i=I(),r=Y(t,i,e)?i:null,s=this._get("extent");return k(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=V(this.groundExtent,this._userClippingExtent,I()),t=this._get("extent");return k(e,t)?t:e}get groundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||null!=this._rootTiles}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return q(this._spatialReference)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(tt,e,t,i);a(n,0,n,0);return lt(s,this._xNormalizer?.normalize(n[0])??n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,lt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!D(e,tt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(tt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;tt[0]>t[2]&&(i+=1),tt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationRange(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system"),null;it.copy(e),i(it.center,0,it.center,0);const r=new z,s=this._rootTiles;if(null!=s){const e=[];for(const i of s)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,it))continue;const s=i.children;if(null==s[0]||i.rendered)r.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of s)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&null!=this._rootTiles?new z(this.rootTileElevationRange.minElevation,this.rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*U;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,it.center,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;it.radius=t;let i=null;const r=e=>{if(e&&A(e.extent,it)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;_e(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??R.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(Je._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=rt;let s=t.rootTilesInExtent(e,i,5*he);if(null!=this._rootTiles){if(s.length>he)return void l.getLogger(this).warn(de);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,Ie);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>Ie(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>he&&(l.getLogger(this).warn(pe),s=t.rootTilesInExtent(e,i,he)),this._setRootTiles(s.map(e=>this._newRootTile(e)));k(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Oe),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Oe);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=Ge(e),i=this.visibleElevationRange;let r=t?i.minElevation:1/0,s=t?i.maxElevation:-1/0;const a=this.extent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.minElevation!==r||i.maxElevation!==s)&&(this.visibleElevationRange=new K(r,s))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this.rootTileElevationRange;r.minElevation===e&&r.maxElevation===t||(this.rootTileElevationRange=new K(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=G(this._splitLimits.frustum??N(),t.frustum):this._splitLimits.frustum=null,E(this._eyePosRenderSR,t.eye),j(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(ye)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=at.extent;B(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>O(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),at.spatialReference=this.spatialReference,this.emit("elevation-change",at),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Le&&this._checkTileInvariant(),!e.hasProgressed)return Ke}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(_e(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(_e(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){_e(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)_e(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=ue;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${ue} (edge[${i}])`),_e(r,`tile level delta [${t.level}] vs [${e.level}] > ${ue}`))}_e(t.level-e.level<=ue,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-ue,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(fe[i],s);if(null!=a){if(t.leaf&&t.level>=ue){let i=a;for(;t.level-i.level<ue;)i=i.parent;const s=[r,t.lij[1]>>ue,t.lij[2]>>ue];if(!Ie(s,i.lij)){const r=e.get(i);_e(!r.has(t),"Cannot already have neighbor"),r.add(t)}}_e(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),_e(t.level-a.level<=ue,`Tile level delta [${t.level}] vs [${a.level}] > ${ue}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);_e(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new ae(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=n?.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?ot(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){Te(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Oe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Te(r.loaded),Te(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=De[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(Pe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(ve(fe[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(Te(e.has(t)||Oe(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Le&&Ue&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=ue){const e=e=>e.leaf||i-e.level<ue;for(let r=0;r<4;++r){const a=s.findNeighborTile(fe[r],e);null!=a&&i-a.level===ue&&(t=!1,Le&&(Te(a.leaf),Te(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*ce}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?dt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(Je._tileMemcacheKey,e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){_e(e.leaf,"Tile that is already split should not be split again!"),_e(e.rendered,"Tile marked to split is not rendered"),dt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),_e(e.rendered,"parent should be rendered"),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>ot(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){nt.spatialReference=this.spatialReference,nt.extent=e.extent,nt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",nt)}createTile(e,t,i,r){_e(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.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){_e(!e.hasPendingUpdate(1),"_mergeTile sanity check"),_e(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),_e(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),ot(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=Ye){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),we(e)||Ce(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ce(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(Se(e)&&!$(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((be(e)||Ce(e))&&We(He[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Ee(e)?0:1}_registerTiledLayerView(e){const t=[];if((be(e)||Ce(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Ce(e)){const i=this._layerClassFromLayerView(e);t.push(_(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(_(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(_(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!we(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ie){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.setNeedsRender(e)}requestUpdate(){1===++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||ye(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,c(r),g(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();return 0===t?Ee(i)?this._requestElevationTileData(e,i,r):Promise.reject():Se(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!m(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new J(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationRange(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{xe(s),m(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(i)?xe(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return xe(i),void l.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):l.getLogger(this).warn("TerrainSurface: received data from unknown layer")}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Ue)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){Me(e)}static cleanupTerrainSurface(){st.prune()}enable(e){e!==this.enabled&&(e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this._set("enabled",e),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],Ze.prototype,"_renderer",void 0),e([w({constructOnly:!0})],Ze.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],Ze.prototype,"view",void 0),e([w({constructOnly:!0})],Ze.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],Ze.prototype,"terrainTextureCompressionTracker",void 0),e([w()],Ze.prototype,"_hasPendingUpdates",void 0),e([w()],Ze.prototype,"_asyncWorkItems",void 0),e([w()],Ze.prototype,"_allTilesDirty",void 0),e([w()],Ze.prototype,"_allTilesSorted",void 0),e([w()],Ze.prototype,"_allTilesCreated",void 0),e([w()],Ze.prototype,"_viewChanged",void 0),e([w({type:Number})],Ze.prototype,"heading",void 0),e([w()],Ze.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],Ze.prototype,"_watchUpdatingTracking",void 0),e([w()],Ze.prototype,"_frameTask",void 0),e([w()],Ze.prototype,"demResolution",null),e([w({readOnly:!0})],Ze.prototype,"snapLevel",null),e([w({readOnly:!0})],Ze.prototype,"lodSnappingEnabled",null),e([w()],Ze.prototype,"_userClippingExtent",null),e([w()],Ze.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],Ze.prototype,"extent",null),e([w({readOnly:!0})],Ze.prototype,"groundExtent",null),e([w({readOnly:!0})],Ze.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],Ze.prototype,"updating",null),e([w({readOnly:!0})],Ze.prototype,"readyToRun",null),e([w(X)],Ze.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],Ze.prototype,"updatingProgressValue",null),e([w()],Ze.prototype,"_maxNumUpdating",void 0),e([w()],Ze.prototype,"baseOpacity",null),e([w()],Ze.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],Ze.prototype,"viewingMode",null),e([w()],Ze.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],Ze.prototype,"ready",null),e([w({readOnly:!0})],Ze.prototype,"rootTiles",null),e([w()],Ze.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],Ze.prototype,"spatialReference",null),e([w({type:t})],Ze.prototype,"backgroundColor",null),e([w({value:!1})],Ze.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],Ze.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLogic",void 0),e([w()],Ze.prototype,"wireframe",null),e([w({value:!1})],Ze.prototype,"suspended",null),e([w()],Ze.prototype,"fadeDuration",null),e([w()],Ze.prototype,"_xNormalizer",null),e([w()],Ze.prototype,"visibleElevationRange",void 0),e([w()],Ze.prototype,"rootTileElevationRange",void 0),e([w()],Ze.prototype,"_layerViewsDirty",void 0),e([w()],Ze.prototype,"renderPatchBorders",null),e([w()],Ze.prototype,"renderingDisabled",null),e([w({readOnly:!0})],Ze.prototype,"enabled",void 0),Ze=Je=e([C("esri.views.3d.terrain.TerrainSurface")],Ze);const et=Ze,tt=x(),it=new W,rt=I(),st=new u,at=new ee("ground"),nt={spatialReference:null,extent:null,scale:0};function lt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return Z(t,i,s)}return null}function ot(e,t){!e.leaf||e.level<ue||ut(e,e=>{t&&ht(e);const i=pt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=pt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function ht(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<ue||ut(e,e=>{ht(e)})}function dt(e){e.level<ue||ut(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,pt(t));)t=t.parent}})}function pt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function ut(e,t){if(e.level<ue)return;const i=e.level-ue,r=e.lij[1]>>ue,s=e.lij[2]>>ue,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(fe[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{et as default};
5
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as i,difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as n}from"../../../core/Evented.js";import"../../../core/has.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{destroyMaybe as h}from"../../../core/maybe.js";import{MemCachePool as d}from"../../../core/MemCachePool.js";import p from"../../../core/ObjectPool.js";import u from"../../../core/PooledArray.js";import{throwIfAborted as c,isAbortError as g,isAborted as m}from"../../../core/promiseUtils.js";import{watch as _,syncAndInitial as f,sync as y,initial as T}from"../../../core/reactiveUtils.js";import{getMetersPerUnitForSR as v}from"../../../core/units.js";import{property as w,subclass as C}from"../../../core/accessorSupport/decorators.js";import{m as S,h as b,d as E}from"../../../chunks/vec32.js";import{create as x}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as L}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as P,radiusModifier as R}from"../../../geometry/ellipsoidUtils.js";import U from"../../../geometry/SpatialReference.js";import{getProjector as M}from"../../../geometry/projection/projectors.js";import{projectPointToVector as D}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as j}from"../../../geometry/projection/projectVectorToVector.js";import{create as I,equals as k,intersection as V,intersectsSphere as A,empty as B,expand as O}from"../../../geometry/support/aaBoundingRect.js";import{copy as G,create as N}from"../../../geometry/support/frustum.js";import{createSpatialReferenceCyclical as q}from"../../../geometry/support/normalizeUtils.js";import{isPlateCarree as F}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as W}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as H}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as $}from"../../../layers/support/layerUtils.js";import{debugFlags as Q}from"../support/debugFlags.js";import{ElevationRange as z}from"../support/ElevationRange.js";import{toBoundingRect as Y}from"../support/extentUtils.js";import{updatingProgress as X}from"../support/updatingProperties.js";import{ElevationBounds as K}from"./ElevationBounds.js";import{ElevationData as J,sampleElevation as Z}from"./ElevationData.js";import{ElevationUpdateEventImplementation as ee}from"./ElevationUpdateEvent.js";import{create as te}from"./ExtentHelper.js";import{LayerClasses as ie}from"./LayerClass.js";import{OverlayManager as re}from"./OverlayManager.js";import{PlanarPatch as se}from"./PlanarPatch.js";import{Queue as ae}from"./Queue.js";import{ScaleRangeQueries as ne}from"./ScaleRangeQueries.js";import{SphericalPatch as le}from"./SphericalPatch.js";import{SplitLimits as oe}from"./SplitLimits.js";import{maxRootTiles as he,tooManyRootTilesAfterChangeError as de,tooManyRootTilesForLayerError as pe,maxTileNeighborLevelDelta as ue,maxMemoryLodBias as ce}from"./TerrainConst.js";import{TerrainRenderer as ge}from"./TerrainRenderer.js";import me from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as _e,isVectorTileLayerView as fe,neighborEdgeIndices as ye,internalAssert as Te,oppositeEdge as ve,isSurfaceLayerView as we,isGroupLayerView as Ce,isMapTileLayerView as Se,isBlendableLayerView as be,isElevationLayerView as Ee,releaseTerrainData as xe,enableTerrainInternalChecks as Le,oppositeCorner as Pe,enableWaterproofTests as Re,enableInternalTerrainChecks as Ue,enableTerrainWaterproofChecks as Me,neighborCornerIndices as De}from"./terrainUtils.js";import{Tile as je,lijEquals as Ie}from"./Tile.js";import{printAllocations as ke}from"./TilePerLayerInfo.js";import{sortTiles as Ve,IteratorPreorder as Ae,IteratorPostorder as Be,compareTilesByLij as Oe,hasLoadableSiblings as Ge,sortTilesByPOI as Ne}from"./tileUtils.js";import{TilingSchemeLogic as qe}from"./TilingSchemeLogic.js";import{UpsampleInfo as Fe}from"./UpsampleInfo.js";import{isCompositeBlendMode as We,blendModeFromString as He}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as $e}from"../../support/layerViewUtils.js";import{ImmediateTask as Qe,TaskPriority as ze,noBudget as Ye}from"../../support/Scheduler.js";import{TextureCompressionTracker as Xe}from"../../support/TextureCompressionTracker.js";import{Yield as Ke}from"../../support/Yield.js";var Je;let Ze=class extends n{static{Je=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return Ve(i(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){const{_allTiles:e,tilingScheme:t}=this;if(0===e.length)return{min:1,max:1};const i=v(t.spatialReference);let r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;for(const a of e){const e=t.resolutionAtLevel(a.level)*i;r=Math.min(r,e),s=Math.max(s,e)}return{min:r,max:s}}constructor(e){super(e),this.terrainTextureCompressionTracker=new Xe,this._iteratorPool=new p(()=>new Ae,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new Be,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new me,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=x(),this._eyePosSurfaceSR=x(),this._splitLimits=new oe,this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._watchUpdatingTracking=new L,this._frameTask=Qe,this._allTiles=new u,this._upsampleInfoPool=new p(()=>new Fe),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=I(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=U.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new z(1/0,-1/0),this._rootTileElevationRange=new z(1/0,-1/0),this._projectorCache=new Map,this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._oneBatchPerFrameTask=!0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;const{view:t}=e;this.overlayManager=new re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?le:se,this._ellipsoid=P(t.spatialReference),this._renderer=new ge(this.overlayManager.renderer,t.stage,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),$e()||(this._scaleRangeQueries=new ne)}initialize(){const{view:e}=this,{resourceController:t}=e,{memoryController:i}=t;this._tileCache=new d((e,t)=>i.newCache(e,t),"terrain-tile"),this._upsampleMapCache=i.newCache("terrain-upsample",({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new H(i.newCache("elevation-query"));const r=this.overlayManager;this.addHandles([_(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),_(()=>this.renderer.visible,e=>this.suspended=!e),_(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)}),_(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(null==e)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree)return void(this.heading=90*Math.round(e/90)%360);const i=Math.round(e)%360,r=Math.abs(i-this.heading);(2===t||Math.min(r,360-r)>=30)&&(this.heading=i)})],"overlayManager"),this.addHandles([_(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},f),_(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),f),_(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},y),_(()=>this.snapLevel,()=>this._viewChanged=!0,y),_(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:S})}),_(()=>Q.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&Q.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=h(this._treeDebugger))},T)]);const{spatialReference:a}=e;this._extentHelper=te(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});const n=new s({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}),l=new qe({layers:n,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set("tilingSchemeLogic",l),this._updateTilingScheme();const o=t.scheduler;this._frameTask=o.registerTask(ze.TERRAIN_SURFACE,this),this.addHandles([_(()=>this._extentHelper.stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),T),_(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),y),_(()=>this.groundExtent,()=>this._updateRootTiles(),T),e.on("resize",()=>this._viewChangeUpdate()),_(()=>{const t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),f),_(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,T),_(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,T),_(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>this._updateAllTileGeometries()),_(()=>this.userClippingExtent,()=>this._updateClippingExtent(),y)]),this.addHandles(e.allLayerViews.on("after-changes",()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._watchUpdatingTracking?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._frameTask.remove(),this._frameTask=Qe,this._watchUpdatingTracking?.destroy(),this._removeAllTiles(),this._set("tilingSchemeLogic",h(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set("overlayManager",h(this.overlayManager)),this._tileCache=h(this._tileCache),this._allTiles.prune(),je.prune(),this._treeDebugger=h(this._treeDebugger),this._renderer.destroyed||this._renderer.destroy(),this._renderer=null,this._iteratorPool=h(this._iteratorPool),this._upsampleMapCache=h(this._upsampleMapCache),this._elevationQueryCache=h(this._elevationQueryCache),this._set("view",null),this._extentHelper=h(this._extentHelper),this._upsampleInfoPool=h(this._upsampleInfoPool),ke(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return this._extentHelper.stencilEnabledExtents.length>0}get userClippingExtent(){const{spatialReference:e}=this,t=this.view?.clippingArea;if(null==t||null==e)return null;const i=I(),r=Y(t,i,e)?i:null,s=this._get("userClippingExtent");return k(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){const e=V(this.fullGroundExtent,this.userClippingExtent,I()),t=this._get("groundExtent");return k(e,t)?t:e}get fullGroundExtent(){return null!=this._tilingSchemeExtent?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._watchUpdatingTracking?.updating||this._asyncWorkItems>0)&&this.ready&&!this.suspended||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.suspended}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||null!=this._rootTiles}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set("slicePlaneEnabled",e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return 0===this._renderer.transparency}get invisible(){return 3===this._renderer.transparency}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return q(this._spatialReference)}getElevation(e,t,i,r){const s=this._rootTiles;if(!s?.length||!this.enabled)return null;if(0===s[0].layerInfo[0].length)return null;let a=this._elevationProjectorCache.get(r);if(void 0===a&&(a=M(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),null==a)return l.getLogger(this).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;const n=b(tt,e,t,i);a(n,0,n,0);return lt(s,this._xNormalizer?.normalize(n[0])??n[0],n[1])}getElevations(e,t,i){const r=this._rootTiles,s=r?r[0].layerInfo[0].length:0;if(r?.length&&0!==s&&this.enabled)for(let a=0;a<t;++a){const t=3*a;i(a,lt(r,e[t],e[t+1]))}else for(let a=0;a<t;++a)i(a,null)}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!D(e,tt,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this._rootTiles;if(null!=t)for(const i of t)if(i?.containsPoint(tt)){let e=i;for(;e.children[0]&&!e.rendered;){const t=e.children[0].extent;let i=0;tt[0]>t[2]&&(i+=1),tt[1]<t[1]&&(i+=2),e=e.children[i]}return this._getLodBiasCorrectedScale(e.level)}return 1/0}_ensureProjector(e){const t=this._projectorCache.get(e);if(t)return t;const i=M(e,this._tilingSchemeSpatialReference)??null;return this._projectorCache.set(e,i),i}getSphereElevationRange(e,t){if(!this.enabled||null==this._rootTiles)return null;const i=this._ensureProjector(t);if(null==i)return l.getLogger(this).error("TerrainSurface.getSphereElevationRange(): could not project given point to tiling scheme coordinate system"),null;it.copy(e),i(it.center,0,it.center,0);const r=new z,s=this._rootTiles;if(null!=s){const e=[];for(const i of s)e.push(i);let t=0;for(;t<e.length;){const i=e[t];if(++t,!A(i.extent,it))continue;const s=i.children;if(null==s[0]||i.rendered)r.expandElevationRangeValues(i.elevationBoundsMin,i.elevationBoundsMax);else for(const t of s)e.push(t)}}return r}getRootElevationRange(){return this.enabled&&null!=this._rootTiles?new z(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){const e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*R;return Math.min(e,this._ellipsoid.radius)}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!D(e,it.center,this.spatialReference))return l.getLogger(this).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;it.radius=t;let i=null;const r=e=>{if(e&&A(e.extent,it)){const t=e.children;if(t[0]&&!e.rendered)for(const e of t)r(e);else{const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}}},s=this._rootTiles;if(null!=s)for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){if(!this._scaleRangeQueries)return;const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,s+n,a+n,r)}_evaluateTransparency(){const e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,i=this._renderer.transparency,r=this._isFullyTransparent?t?3:2:e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,i!==r}_updateTilingScheme(){const{tilingScheme:e}=this.tilingSchemeLogic;if(!(e!==this.tilingScheme))return;_e(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();const t=e?.spatialReference??U.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&F(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set("tilingScheme",e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._projectorCache.clear(),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey="TerrainTileMemcache"}_acquireTile(e,t,i,r){const s=this._tileCache.pop(Je._tileMemcacheKey);return s?(s.init(e,t,i,r,this),s):new this._tileConstructor(e,t,i,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled)return void this._setRootTiles(null);const i=rt;let s=t.rootTilesInExtent(e,i,5*he);if(null!=this._rootTiles){if(s.length>he)return void l.getLogger(this).warn(de);const e=this._rootTiles.map(e=>e.lij),t=r(e,s,Ie);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this._rootTiles.filter(e=>!(t.removed.findIndex(t=>Ie(t,e.lij))>-1)||(this._purgeTile(e),!1));t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>he&&(l.getLogger(this).warn(pe),s=t.rootTilesInExtent(e,i,he)),this._setRootTiles(s.map(e=>this._newRootTile(e)));k(i,this._rootTilesExtent)||(this._rootTilesExtent=I(i)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness()}_updateAllTileGeometries(){const e=this._allTiles.filter(e=>e.loaded&&e.intersectsClippingArea);e.sort(Oe),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){if(0===e.length)return;e.sort(Oe);const t=this.renderer;e.forEach(e=>t.updateGeometryIfNeeded(e)),e.forEach(e=>this._pendingTilesForElevationUpdateEvent.add(e))}_shouldSplit(e){return 1===e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),null!=e){const t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(null==e)return;const t=Ge(e),i=this.visibleElevationRange;let r=t?i.minElevation:1/0,s=t?i.maxElevation:-1/0;const a=this.groundExtent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);const l=this._iteratorPool.acquire();for(l.reset(e);!l.done;){const e=l.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),s=Math.max(e.elevationBoundsMax,s))}l.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(s)&&(i.minElevation!==r||i.maxElevation!==s)&&(this.visibleElevationRange=new K(r,s))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;const i=this._rootTiles;null!=i&&i.forEach(({elevationBoundsMin:i,elevationBoundsMax:r})=>{e=Math.min(e,i),t=Math.max(t,r)});const r=this._rootTileElevationRange;r.minElevation===e&&r.maxElevation===t||(this._rootTileElevationRange=new K(e,t))}_updateViewDependentParameters(){const{camera:e,contentCamera:t}=this.view.state,i=Math.tan(.5*t.fovX),r=Math.tan(.5*t.fovY),s=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=i,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=s/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=s/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=G(this._splitLimits.frustum??N(),t.frustum):this._splitLimits.frustum=null,E(this._eyePosRenderSR,t.eye),j(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility();this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){e.forEachLoadedNeighbor(e=>{this._layerViews[1].some(fe)&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){const i=e.resetPendingUpdate(32)?32:!!e.resetPendingUpdate(16)&&16;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;const e=at.extent;B(e),this._pendingTilesForElevationUpdateEvent.forEach(t=>O(e,t.extent,e)),this._pendingTilesForElevationUpdateEvent.clear(),at.spatialReference=this.spatialReference,this.emit("elevation-change",at),this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;if(this._mergeAndSplit(e,t),this._updateElevation(e),this._updateTextures(e),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&e.hasProgressed&&this.requestUpdate(),this.notifyChange("updatingProgressValue"),Le&&this._checkTileInvariant(),!e.hasProgressed)return Ke}_checkTileInvariant(){const e=new Map;this._allTiles.forAll(t=>e.set(t,new Set)),this._allTiles.forAll(t=>{if(_e(t.rendered===t.leaf,` rendered ${t.rendered} != ${t.leaf} leaf`),!t.leaf){const e=e=>0===e.unmergableChildCount&&0===e.maxLevelDeltaNeighborCount,i=t.children.reduce((t,i)=>t+(e(i)?0:1),0);if(_e(t.unmergableChildCount===i,` Tile[${t.lij.toString()}] unmergeable child count mismatch: actual ${t.unmergableChildCount} vs ${i}`),t.hasPendingUpdate(4)){_e(!t.hasPendingUpdate(1),"Tile can be both split and merge at the same time");for(const e of t.children)_e(e.leaf||e.hasPendingUpdate(4),"Child of tile to merge must also merge")}}for(let i=0;i<4;++i){if(t.rendered){const e=t.renderData?.geometryState.edgePeerNeighbors[i];if(null!=e){{const r=t.level-e.level<=ue;r||(console.log(`tile level delta [${t.lij.toString()}] vs [${e.lij.toString()}] > ${ue} (edge[${i}])`),_e(r,`tile level delta [${t.level}] vs [${e.level}] > ${ue}`))}_e(t.level-e.level<=ue,`Max tile lod delta exceeded: [${t.lij.toString()}] vs [${e.lij.toString()}]`)}}const r=t.level-ue,s=e=>e.leaf||e.level===t.level,a=t.findNeighborTile(ye[i],s);if(null!=a){if(t.leaf&&t.level>=ue){let i=a;for(;t.level-i.level<ue;)i=i.parent;const s=[r,t.lij[1]>>ue,t.lij[2]>>ue];if(!Ie(s,i.lij)){const r=e.get(i);_e(!r.has(t),"Cannot already have neighbor"),r.add(t)}}_e(a.rendered||a.level===t.level,"Non-same-level-neighbor of rendered must be rendered"),_e(t.level-a.level<=ue,`Tile level delta [${t.level}] vs [${a.level}] > ${ue}`)}}}),this._allTiles.forAll(t=>{const i=t.maxLevelDeltaNeighborCount,r=e.get(t);_e(i===r.size,`Tile[${t.lij.toString()}] merge-blocker mismatch: actual ${i} vs ${r.size}`)})}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;const t=new ae(this._allTiles.length);t.pushAll(this._rootTiles);const i=this.snapLevel,r=this._splitLimits,s=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});const a=this.view.state.contentCamera.viewProjectionMatrix;for(;!t.empty;){const e=t.pop(),n=e.parent,l=n?.hasPendingUpdate(4),o=l?4:e.shouldSplit(r,s,i),h=1===o;e.leaf?ot(e,h):t.pushAll(e.children),l?(e.resetPendingUpdate(1),e.leaf||e.setPendingUpdate(4),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(a)):h?(e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),2===o&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1)))}this.requestUpdate(),(this._shortBatches||!this._oneBatchPerFrameTask)&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||!this.view.pointsOfInterest?.focus||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){Te(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_updatePendingTileGeometries(){const e=this._pendingTilesToUpdate,t=Array.from(e.keys()).filter(e=>e.loaded&&e.intersectsClippingArea);if(0===t.length)return void e.clear();const i=(i,r)=>{!r?.loaded||!r.intersectsClippingArea||r.level<i.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(Oe);const r=t.length;for(let s=0;s<r;++s){const r=t[s];Te(r.loaded),Te(r.intersectsClippingArea);const a=r.renderData;a.updateNeighborData();const n=a.dirtyEdgeResolutions,l=a.geometryState,o=e=>{const t=De[e];i(r,l.cornerPeerNeighbors[e]?.findCorner(Pe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(n&1<<t){const s=a.geometryState.edgePeerNeighbors[t];s&&s?.level>=r.level&&s.forAllSubtreeOnSide(ve(ye[t]),t=>!(!t.loaded||!t.intersectsClippingArea)&&(Te(e.has(t)||Oe(r,t)<0),i(r,t),!0)),o((t+1)%4),o(t)}}e.clear(),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,Le&&Re&&this.checkAllTilesWaterproofness()}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let i=!1;const r=this.view.state.fixedContentCamera;let s=!1;for(;!e.done;){s=!0;let a=!1;const n=!this._allTiles.some(s=>{if(!i&&!r&&!s.visible)return e.done;let n=s;if(s.hasPendingUpdate(4)){if(!t||s.unmergableChildCount>0)return e.done;for(s.resetPendingUpdate(4);null!=n.parent&&0===n.parent.unmergableChildCount&&n.parent.resetPendingUpdate(4);)n=n.parent;this._mergeTile(n),a=!0,e.madeProgress()}else if(s.resetPendingUpdate(1)){let t=!0;const i=s.level;if(i>=ue){const e=e=>e.leaf||i-e.level<ue;for(let r=0;r<4;++r){const a=s.findNeighborTile(ye[r],e);null!=a&&i-a.level===ue&&(t=!1,Le&&(Te(a.leaf),Te(a.hasPendingUpdate(1))))}}t?(this._splitTile(s),e.madeProgress(),a=!0):s.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries()),n){if(!i){i=!0;continue}if(!a)break}else this._allTilesDirty=!0}s?e.madeProgress():this._allTilesDirty=!0,!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries(),this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)),this._sortTiles(e)}_updateElevation(e){e.done||(this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()),e.done)),!this._oneBatchPerFrameTask&&this._updatePendingTileGeometries())}_updateTextures(e){e.done||this._allTiles.some(t=>(this._updateTileTexture(t,e),e.done))}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*ce}_getLodBiasCorrectedScale(e){const t=this.tilingScheme.levels,i=o(e-this._lodBias,0,t.length-1),r=i-Math.floor(i);return t[Math.floor(i)].scale*(1-r)+t[Math.ceil(i)].scale*r}_removeAllTiles(){null!=this._rootTiles&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){const t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?dt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(Je._tileMemcacheKey,e),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){_e(e.leaf,"Tile that is already split should not be split again!"),_e(e.rendered,"Tile marked to split is not rendered"),dt(e);const t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange("demResolution"),this.emit("tiles-changed",{allTiles:this.allTiles}),e.updateAgentSuspension(),_e(e.rendered,"parent should be rendered"),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>ot(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){nt.spatialReference=this.spatialReference,nt.extent=e.extent,nt.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",nt)}createTile(e,t,i,r){_e(!!r,"createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.groundExtent),s.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(s)&&s.setPendingUpdate(1),s}get _shortBatches(){return 2!==this.view.state.mode}_mergeTile(e){_e(!e.hasPendingUpdate(1),"_mergeTile sanity check"),_e(!e.leaf,"Cannot merge a leaf"),e.leaf||(this._purgeSubtree(e),_e(!e.renderData,"Merging tile with existing render data?"),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),ot(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=Ye){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(let s=this.view.allLayerViews.length-1;s>=0;s--){const e=this.view.allLayerViews.items[s];if(i.add(e.uid),we(e)||Ce(e))if(this._basemapLayerViewHandles.has(e.uid)&&!Ce(e)){const i=this._layerClassFromLayerView(e),s=this.getLayerIndexByUID(i,e.uid);null!=s&&((s<r||null==r)&&(t=!0),r=s)}else this._registerTiledLayerView(e),e.layer.loaded&&(t=!0)}this._basemapLayerViewHandles.forEach((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(const e of this.view.allLayerViews.items)if(Se(e)&&!$(e.layer)&&0!==e.fullOpacity)return!1;return!0}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if((be(e)||Ce(e))&&We(He[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return Ee(e)?0:1}_registerTiledLayerView(e){const t=[];if((be(e)||Ce(e))&&t.push(_(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!Ce(e)){const i=this._layerClassFromLayerView(e);t.push(_(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(_(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));const{layer:r}=e;"effectiveScaleRange"in r&&t.push(_(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(i))),t.push(e.on("data-changed",()=>{const t=this.getLayerIndexByUID(i,e.uid);null!=t&&this._invalidateLayerData(t,i)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(const e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;const e=this.view.allLayerViews,t=[[],[]];let i=null;e.forEach(e=>{if(!e.layer||e.suspended||!we(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(1===r){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)});for(const r of ie){const e=this._layerViews[r],i=t[r];i.reverse();const s=i.length;let a=e.length!==s;const n=new Array(s),l=new Array(e.length);this._layerIndexByUid[r].clear();for(let t=0;t<s;t++){const s=i[t].uid;this._layerIndexByUid[r].set(s,t);const o=e.indexOf(i[t]);n[t]=o,t!==o&&(a=!0),o>-1&&(l[o]=t)}if(a){const e=this._postorderIterator;for(e.reset(this._rootTiles);!e.done;)e.next().modifyLayers(l,n,r);this._layerViews[r]=i,this._restartAllAgents(r),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(i)&&(this._viewChangeUpdate(),this.notifyChange("tilingScheme"))}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){const i=t.next();i.restartAgents(e),0===e&&i.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),1===e?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._allTiles.forAll(i=>i.removeLayerAgent(e,t)),this._allTiles.forAll(i=>i.invalidateLayerData(e,t))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.setNeedsRender(e)}requestUpdate(){1===++this._pendingUpdates&&(this._hasPendingUpdates=!0)}requestTileData(e,t,i,r){const s=this.layerViewByIndex(t,i),a=s.layer;return!a.tilemapCache||fe(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).then(()=>--this._asyncWorkItems).catch(t=>{throw--this._asyncWorkItems,c(r),g(t)||this._dataMissing(e,i,s),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,i,s,r),r.signal)))}_requestTileData(e,t,i,r){if(this.destroying)return Promise.resolve();return 0===t?Ee(i)?this._requestElevationTileData(e,i,r):Promise.reject():Se(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{!m(i)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},s=i=>{g(i)||(l.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${i}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,i).then(e=>this._frameTask.schedule(()=>r(e)),s).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,i){const r=this._layerIndexByUid[0].get(t.uid);if(null==r)return void l.getLogger(this).warn("TerrainSurface: received data from unknown layer %d %s",0,e.lij.toString());const s=new J(e.lij,e.extent,i);e.dataArrived(r,0,s),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:0});const a=[e],n=e.level,o=this._iteratorPool.acquire();for(o.reset(a);!o.done;){const e=o.next();e.findElevationBoundsForLayer(r,n),e.computeElevationBounds()}0===n&&this._updateRootTileElevationRange(),o.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{xe(s),m(i)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(i)?xe(r):this._mapTileDataArrived(e,t,r)},i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule(()=>r(e,t));return t.fetchTile(e.lij,i).then(a,n).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,i){const r=this.getLayerIndexByUID(1,t.uid);if(null==r)return xe(i),void l.getLogger(this).warn("TerrainSurface: received data from unknown layer");e.dataArrived(r,1,i),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:1})}_dataMissing(e,t,i){const r=this.getLayerIndexByUID(t,i.uid);null!=r?(e.dataMissing(r,t),this.emit("tile-data-changed",{tile:e,layerIndex:r,layerClass:t})):l.getLogger(this).warn("TerrainSurface: received data from unknown layer")}get performanceInfo(){const e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;const i=t.level;t.renderData&&(e.numLoadedPerLevel[i]=(e.numLoadedPerLevel[i]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[i]=(e.numRenderedPerLevel[i]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(null==this._usedMemory&&(this._usedMemory=this._recalculateUsedMemory()),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(i,e.uid);return null!=r&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(i,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(){if(!Re)return;const e=this._rootTiles;if(null==e)return;const t=e=>e?.renderData?.geometry?.indices?.length>0,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.intersectsClippingArea)if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometry&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometry||(e.renderData.geometry.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometry),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.leaf)console.error("Tile[",e.lij,"] has no geometry and no children, from root to leaf");else for(const t of e.children)r(t)},s=e=>{const t=e.parent?.visible??!0,i=e.visible;e.computeVisibility();const r=e.visible;if(i!==r&&t&&console.error(" Tile[",e.lij,"] has out of date visibility: ",i," instead of ",r),!e.leaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&0===e[2]}lijEastEnd(e){return 1<<e+(this._isGeographic?1:0)}wrapEastWest(e){const t=this.lijEastEnd(e[0]),i=e[2];if(0<=i&&i<t)return e;if(!this._isGlobal)return null;const r=(i+(i<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Ue(e)}enableWaterproofnessChecks(e){Me(e)}static cleanupTerrainSurface(){st.prune()}enable(e){e!==this.enabled&&(this._set("enabled",e),e?(this._updateRootTiles(),this.suspended=!1):(this.suspended=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange("ready"))}updateOverlayParameters(){const{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([w()],Ze.prototype,"_renderer",void 0),e([w({constructOnly:!0})],Ze.prototype,"_scaleRangeQueries",void 0),e([w({constructOnly:!0})],Ze.prototype,"view",void 0),e([w({constructOnly:!0})],Ze.prototype,"overlayManager",void 0),e([w({constructOnly:!0})],Ze.prototype,"terrainTextureCompressionTracker",void 0),e([w()],Ze.prototype,"_hasPendingUpdates",void 0),e([w()],Ze.prototype,"_asyncWorkItems",void 0),e([w()],Ze.prototype,"_allTilesDirty",void 0),e([w()],Ze.prototype,"_allTilesSorted",void 0),e([w()],Ze.prototype,"_allTilesCreated",void 0),e([w()],Ze.prototype,"_viewChanged",void 0),e([w({type:Number})],Ze.prototype,"heading",void 0),e([w()],Ze.prototype,"_splitLimits",void 0),e([w({readOnly:!0})],Ze.prototype,"_watchUpdatingTracking",void 0),e([w()],Ze.prototype,"_frameTask",void 0),e([w()],Ze.prototype,"demResolution",null),e([w({readOnly:!0})],Ze.prototype,"snapLevel",null),e([w({readOnly:!0})],Ze.prototype,"lodSnappingEnabled",null),e([w({readOnly:!0})],Ze.prototype,"userClippingExtent",null),e([w()],Ze.prototype,"_rootTilesExtent",void 0),e([w({readOnly:!0})],Ze.prototype,"groundExtent",null),e([w({readOnly:!0})],Ze.prototype,"fullGroundExtent",null),e([w({readOnly:!0})],Ze.prototype,"_tilingSchemeExtent",null),e([w({readOnly:!0})],Ze.prototype,"updating",null),e([w({readOnly:!0})],Ze.prototype,"readyToRun",null),e([w(X)],Ze.prototype,"updatingProgress",void 0),e([w({readOnly:!0})],Ze.prototype,"updatingProgressValue",null),e([w()],Ze.prototype,"_maxNumUpdating",void 0),e([w()],Ze.prototype,"baseOpacity",null),e([w()],Ze.prototype,"hasCompositeBlendMode",void 0),e([w({readOnly:!0})],Ze.prototype,"viewingMode",null),e([w()],Ze.prototype,"maxTextureScale",void 0),e([w({readOnly:!0})],Ze.prototype,"ready",null),e([w({readOnly:!0})],Ze.prototype,"rootTiles",null),e([w()],Ze.prototype,"_rootTiles",void 0),e([w({readOnly:!0})],Ze.prototype,"spatialReference",null),e([w({type:t})],Ze.prototype,"backgroundColor",null),e([w({value:!1})],Ze.prototype,"slicePlaneEnabled",null),e([w({readOnly:!0})],Ze.prototype,"tilingScheme",void 0),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLocked",null),e([w({readOnly:!0})],Ze.prototype,"tilingSchemeLogic",void 0),e([w()],Ze.prototype,"wireframe",null),e([w({value:!1})],Ze.prototype,"suspended",null),e([w()],Ze.prototype,"fadeDuration",null),e([w()],Ze.prototype,"_xNormalizer",null),e([w()],Ze.prototype,"visibleElevationRange",void 0),e([w()],Ze.prototype,"_rootTileElevationRange",void 0),e([w()],Ze.prototype,"_layerViewsDirty",void 0),e([w()],Ze.prototype,"renderPatchBorders",null),e([w()],Ze.prototype,"renderingDisabled",null),e([w({readOnly:!0})],Ze.prototype,"enabled",void 0),Ze=Je=e([C("esri.views.3d.terrain.TerrainSurface")],Ze);const et=Ze,tt=x(),it=new W,rt=I(),st=new u,at=new ee("ground"),nt={spatialReference:null,extent:null,scale:0};function lt(e,t,i){for(const r of e){if(!r.containsPointXY(t,i))continue;let e=r;for(;e&&!e.renderData;){const r=(t>e.extentMidX?1:0)+(i<e.extentMidY?2:0);e=e.children[r]}const s=e?.renderData?.geometryState.samplerData??null;return Z(t,i,s)}return null}function ot(e,t){!e.leaf||e.level<ue||ut(e,e=>{t&&ht(e);const i=pt(e);if(e.maxLevelDeltaNeighborCount++,i){let t=e.parent;for(;t;){const e=pt(t);if(t.unmergableChildCount++,!e)break;t=t.parent}}})}function ht(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<ue||ut(e,e=>{ht(e)})}function dt(e){e.level<ue||ut(e,e=>{if(e.maxLevelDeltaNeighborCount--,0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount){let t=e.parent;for(;t&&(t.unmergableChildCount--,pt(t));)t=t.parent}})}function pt(e){return 0===e.maxLevelDeltaNeighborCount&&0===e.unmergableChildCount}function ut(e,t){if(e.level<ue)return;const i=e.level-ue,r=e.lij[1]>>ue,s=e.lij[2]>>ue,a=e=>e.leaf||e.level===i;for(let n=0;n<4;++n){const l=e.findNeighborTile(ye[n],a);if(!l||l.level!==i)continue;const o=l.lij;o[1]===r&&o[2]===s||t(l)}}export{et as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{destroyMaybe as t}from"../../../core/maybe.js";class e{constructor(t){this._getFadeDuration=t,this._fadeStart=0,this._delayedTime=0}clear(){this._current=t(this._current),this._next=t(this._next),this._waiting=t(this._waiting),this._delayed=t(this._delayed)}get current(){if(null==this._current)return null;if(!this._isFadingEnabled){let t=null;this._delayed?(t=this._delayed,this._delayed=null):this._waiting?(t=this._waiting,this._waiting=null):this._next&&(t=this._next,this._next=null),t&&(this.clear(),this._current=t)}let i=e.test.fadeMoment;if(this._delayed&&(i=i||performance.now(),i>=this._delayedTime&&(this._push(this._delayed,0),this._delayed=null)),this._next){i=i||performance.now();const e=this._fadeDuration,n=null!=this._current&&this._next.texture===this._current.texture,s=0!==this._next.type,a=i-this._fadeStart>=e;(n||s||a)&&(t(this._current),this._current=this._next,this._next=this._waiting,this._waiting=null,this._fadeStart=this._alignFadeStart(i))}return this._current}get next(){return this._next}get fadeFactor(){if(null==this._next)return 1;const t=e.test.fadeMoment||performance.now(),i=Math.max(0,t-this._fadeStart),n=this._fadeDuration;return i>n?0:1-i/n}get isFading(){return null!=this._next||null!=this._delayed}push(e,i=0){this._delayed=t(this._delayed),this._push(e,i)}_push(i,n){if(this._isFadingEnabled||this.clear(),null==this._current)return void(this._current=i);const s=e.test.fadeMoment||performance.now();return 0!==n?(this._delayed=i,void(this._delayedTime=s+n)):null==this._next?(this._next=i,void(this._fadeStart=this._alignFadeStart(s))):void(null!=i&&(t(this._waiting),this._waiting=i))}get _fadeDuration(){const t=this._getFadeDuration();return this._waiting?.5*t:t}_alignFadeStart(t){const e=this._getFadeDuration();return t+e-t%e}get _isFadingEnabled(){return this._getFadeDuration()>0}static{this.test={fadeMoment:0}}}export{e as TextureFader};
5
+ import{destroyMaybe as t}from"../../../core/maybe.js";class e{constructor(t){this._getFadeDuration=t,this._fadeStart=0,this._delayedTime=0}clear(){this._current=t(this._current),this._next=t(this._next),this._waiting=t(this._waiting),this._delayed=t(this._delayed)}get current(){if(null==this._current)return null;if(!this._isFadingEnabled){let t=null;this._delayed?(t=this._delayed,this._delayed=null):this._waiting?(t=this._waiting,this._waiting=null):this._next&&(t=this._next,this._next=null),t&&(this.clear(),this._current=t)}let i=e.test.fadeMoment;if(this._delayed&&(i=i||performance.now(),i>=this._delayedTime&&(this._push(this._delayed,0),this._delayed=null)),this._next){i=i||performance.now();const e=this._fadeDuration,n=null!=this._current&&this._next.texture===this._current.texture,s=0!==this._next.type,r=i-this._fadeStart>=e;(n||s||r)&&(t(this._current),this._current=this._next,this._next=this._waiting,this._waiting=null,this._fadeStart=this._alignFadeStart(i))}return this._current}get next(){return this._next}get fadeFactor(){if(null==this._next)return 1;const t=e.test.fadeMoment||performance.now(),i=Math.max(0,t-this._fadeStart),n=this._fadeDuration;return i>n?0:1-i/n}get isFading(){return null!=this._next||null!=this._delayed}push(e,i=0){this._delayed=t(this._delayed),this._push(e,i)}_push(i,n){if(this._isFadingEnabled||this.clear(),null==this._current)return void(this._current=i);const s=this._waiting??this._next??this._current;if(i?.equals(s))return void i.destroy();const r=e.test.fadeMoment||performance.now();return 0!==n?(this._delayed=i,void(this._delayedTime=r+n)):null==this._next?(this._next=i,void(this._fadeStart=this._alignFadeStart(r))):void(null!=i&&(t(this._waiting),this._waiting=i))}get _fadeDuration(){const t=this._getFadeDuration();return this._waiting?.5*t:t}_alignFadeStart(t){const e=this._getFadeDuration();return t+e-t%e}get _isFadingEnabled(){return this._getFadeDuration()>0}static{this.test={fadeMoment:0}}}export{e as TextureFader};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{fromValues as t}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";class e{constructor(e,s,r,i,o,c){this.texture=e,this.type=s,this.offsetAndScale=r,e.retain(),this.opacities=t(i,o,c)}destroy(){this.texture.release()}}export{e as TextureReference};
5
+ import{equals as t}from"../../../core/arrayUtils.js";import{fromValues as e}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";class s{constructor(t,s,r,i,o,a){this.texture=t,this.type=s,this.offsetAndScale=r,t.retain(),this.opacities=e(i,o,a)}destroy(){this.texture.release()}equals(e){return null!=e&&this.texture===e.texture&&t(this.offsetAndScale,e.offsetAndScale)&&t(this.opacities,e.opacities)}}export{s as TextureReference};