@arcgis/core 4.25.0-next.20220718 → 4.25.0-next.20220721

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 (284) hide show
  1. package/Camera.js +1 -1
  2. package/analysis/DimensioningAnalysis.js +1 -1
  3. package/analysis/LineOfSightAnalysis.js +1 -1
  4. package/analysis/SliceAnalysis.js +1 -1
  5. package/arcade/featureset/support/RecentlyUsedCache.js +1 -1
  6. package/arcade/functions/featuresetgeom.js +1 -1
  7. package/assets/esri/core/workers/RemoteClient.js +1 -1
  8. package/assets/esri/core/workers/chunks/1751de504354d98ac3fd.js +1 -0
  9. package/assets/esri/core/workers/chunks/1f4f1896880bfa6801c5.js +1 -0
  10. package/assets/esri/core/workers/chunks/290cd411d0d18b1d0efd.js +1 -0
  11. package/assets/esri/core/workers/chunks/{ab3bd5fecdb97f2d690e.js → 3b5be512567d9c1c6fe6.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{c3236a7058e64ea3b939.js → 3c9da9b88777700879aa.js} +1 -1
  13. package/assets/esri/core/workers/chunks/{f96e8724ae3458f5e262.js → 4a7aa1b9de61eb013647.js} +1 -1
  14. package/assets/esri/core/workers/chunks/4cb64ccb5fba126f9a66.js +1 -0
  15. package/assets/esri/core/workers/chunks/{68f19e58aae01791944e.js → 579ba109718bc2554008.js} +1 -1
  16. package/assets/esri/core/workers/chunks/59845b02b07a8ed7ce81.js +1 -0
  17. package/assets/esri/core/workers/chunks/{c705f907ce60a646d9aa.js → 652d36523efbe5c9ebb2.js} +1 -1
  18. package/assets/esri/core/workers/chunks/888d8e4471c9a2cd5009.js +1 -0
  19. package/assets/esri/core/workers/chunks/9493a8e5d6001b6bf275.js +1 -0
  20. package/assets/esri/core/workers/chunks/9d824cdfbcdf3cb3246f.js +1 -0
  21. package/assets/esri/core/workers/chunks/bf348f6f52701fa6016e.js +987 -0
  22. package/assets/esri/core/workers/chunks/d02881954c0cc0d39dfb.js +1 -0
  23. package/assets/esri/core/workers/chunks/{1ecbf642debc2207b762.js → da54483123f377e9b3e1.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{61b71b8e028eda10ccab.js → e4ad2cf5d6bded02e392.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{3bfab05ae07ac18a75fe.js → f298a70f3b6f27675d53.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{d499cce61c1c5c367380.js → f40290cfad3fe6fb4ef9.js} +1 -1
  27. package/assets/esri/layers/support/rasterFormats/lerc-wasm.wasm +0 -0
  28. package/assets/esri/themes/base/widgets/_Tooltip.scss +1 -1
  29. package/assets/esri/themes/dark/main.css +1 -1
  30. package/assets/esri/themes/light/main.css +1 -1
  31. package/assets/esri/themes/light/view.css +1 -1
  32. package/chunks/ComponentShader.glsl.js +39 -33
  33. package/chunks/Laserlines.glsl.js +4 -4
  34. package/chunks/Precipitation.glsl.js +2 -2
  35. package/chunks/RibbonLine.glsl.js +46 -44
  36. package/chunks/Stars.glsl.js +2 -2
  37. package/chunks/Terrain.glsl.js +25 -17
  38. package/chunks/boundedPlane.js +1 -1
  39. package/chunks/lerc-wasm.js +1 -1
  40. package/chunks/mat2d.js +1 -1
  41. package/chunks/quatf32.js +1 -1
  42. package/core/BidiEngine.js +1 -1
  43. package/core/accessorSupport/watch.js +1 -1
  44. package/core/libs/gl-matrix-2/factories/quatf32.js +1 -1
  45. package/core/libs/gl-matrix-2/math/mat2d.js +1 -1
  46. package/core/perspectiveUtils.js +1 -1
  47. package/core/promiseUtils.js +1 -1
  48. package/core/reactiveUtils.js +1 -1
  49. package/core/unitUtils.js +1 -1
  50. package/geometry/projection.js +1 -1
  51. package/geometry/projectionEllipsoid.js +1 -1
  52. package/geometry/support/MeshTexture.js +1 -1
  53. package/geometry/support/axisAngleDegrees.js +1 -1
  54. package/geometry/support/coordinateSystem.js +1 -1
  55. package/geometry/support/geodesicUtils.js +1 -1
  56. package/geometry/support/meshUtils/exporters/gltf/index.js +1 -1
  57. package/geometry/support/meshUtils/loadExternal.js +1 -1
  58. package/geometry/support/meshUtils/loadGLTFMesh.js +1 -1
  59. package/geometry/support/scaleUtils.js +1 -1
  60. package/geometry/support/spatialReferenceUtils.js +1 -1
  61. package/identity/IdentityManagerBase.js +1 -1
  62. package/identity/IdentityModal.js +1 -1
  63. package/interfaces.d.ts +3 -33
  64. package/layers/FeatureLayer.js +1 -1
  65. package/layers/effects/parser.js +1 -1
  66. package/layers/graphics/hydratedFeatures.js +1 -1
  67. package/layers/graphics/sources/support/sourceUtils.js +1 -1
  68. package/layers/mixins/ArcGISImageService.js +1 -1
  69. package/layers/ogc/wfsUtils.js +1 -1
  70. package/layers/support/ContingentValue.js +1 -1
  71. package/layers/support/ElevationQuery.js +1 -1
  72. package/layers/support/PixelBlock.js +1 -1
  73. package/layers/support/kmlUtils.js +1 -1
  74. package/layers/support/rasterDatasets/CloudRaster.js +1 -1
  75. package/layers/support/rasterDatasets/EphemeralBlockCache.js +1 -1
  76. package/layers/support/rasterDatasets/ImageServerRaster.js +1 -1
  77. package/layers/support/rasterDatasets/multipartParser.js +1 -1
  78. package/layers/support/rasterFormats/ImageCanvasDecoder.js +1 -1
  79. package/layers/support/rasterFormats/JpgPlus.js +1 -1
  80. package/layers/support/rasterFormats/Lerc.js +1 -1
  81. package/layers/support/rasterFormats/RasterCodec.js +1 -1
  82. package/layers/support/rasterFormats/Raw.js +1 -1
  83. package/layers/support/rasterFormats/TiffTags.js +1 -1
  84. package/layers/support/rasterFunctions/vectorFieldUtils.js +1 -1
  85. package/layers/support/vectorTileLayerLoader.js +1 -1
  86. package/layers/support/wmtsUtils.js +1 -1
  87. package/package.json +1 -1
  88. package/renderers/RasterShadedReliefRenderer.js +1 -1
  89. package/renderers/RasterStretchRenderer.js +1 -1
  90. package/renderers/UniqueValueRenderer.js +1 -1
  91. package/renderers/support/AuthoringInfo.js +1 -1
  92. package/renderers/support/RasterSymbolizer.js +1 -1
  93. package/rest/query/operations/query.js +1 -1
  94. package/rest/query/operations/queryTopFeatures.js +1 -1
  95. package/rest/support/DirectionsFeatureSet.js +1 -1
  96. package/rest/support/ImageHistogramParameters.js +1 -1
  97. package/rest/support/ImageSampleParameters.js +1 -1
  98. package/smartMapping/labels/clusters.js +1 -1
  99. package/smartMapping/renderers/relationship.js +1 -1
  100. package/smartMapping/support/adapters/support/utils.js +1 -1
  101. package/support/basemapUtils.js +1 -1
  102. package/support/revision.js +1 -1
  103. package/symbols/LabelSymbol3D.js +1 -1
  104. package/symbols/PointSymbol3D.js +1 -1
  105. package/symbols/cim/CIMCursor.js +1 -1
  106. package/symbols/cim/CIMSymbolDrawHelper.js +1 -1
  107. package/symbols/cim/CIMSymbolRasterizer.js +1 -1
  108. package/symbols/support/previewSymbol3D.js +1 -1
  109. package/symbols/support/webStyleSymbolUtils.js +1 -1
  110. package/views/2d/ViewState.js +1 -1
  111. package/views/2d/engine/vectorTiles/Feature.js +1 -1
  112. package/views/2d/engine/vectorTiles/style/StyleRepository.js +1 -1
  113. package/views/2d/engine/webgl/SDFConverter.js +1 -1
  114. package/views/2d/engine/webgl/TurboLine.js +1 -1
  115. package/views/2d/engine/webgl/brushes/BrushClip.js +1 -1
  116. package/views/2d/engine/webgl/brushes/BrushOverlay.js +1 -1
  117. package/views/2d/engine/webgl/brushes/WGLGeometryBrushLabel.js +1 -1
  118. package/views/2d/engine/webgl/brushes/WGLGeometryBrushLine.js +1 -1
  119. package/views/2d/engine/webgl/brushes/WGLGeometryBrushText.js +1 -1
  120. package/views/2d/engine/webgl/collisions/MetricReader.js +1 -1
  121. package/views/2d/engine/webgl/cpuMapped/DisplayRecordReader.js +1 -1
  122. package/views/2d/engine/webgl/cpuMapped/FreeList.js +1 -1
  123. package/views/2d/engine/webgl/mesh/heuristics.js +1 -1
  124. package/views/2d/engine/webgl/mesh/templates/WGLDynamicFillTemplate.js +1 -1
  125. package/views/2d/engine/webgl/mesh/templates/WGLDynamicLineTemplate.js +1 -1
  126. package/views/2d/engine/webgl/mesh/templates/WGLDynamicMarkerTemplate.js +1 -1
  127. package/views/2d/engine/webgl/mesh/templates/WGLDynamicTextTemplate.js +1 -1
  128. package/views/2d/engine/webgl/mesh/templates/WGLFillTemplate.js +1 -1
  129. package/views/2d/engine/webgl/mesh/templates/WGLLineTemplate.js +1 -1
  130. package/views/2d/engine/webgl/mesh/templates/WGLMarkerTemplate.js +1 -1
  131. package/views/2d/engine/webgl/mesh/templates/shapingUtils.js +1 -1
  132. package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
  133. package/views/2d/input/MapViewInputManager.js +1 -1
  134. package/views/2d/layers/features/createSymbolSchema.js +1 -1
  135. package/views/2d/viewpointUtils.js +1 -1
  136. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  137. package/views/3d/analysis/LineOfSight/LineOfSightIntersectionResult.js +1 -1
  138. package/views/3d/analysis/LineOfSight/LineOfSightRayIntersector.js +1 -1
  139. package/views/3d/analysis/LineOfSight/LineOfSightTool.js +1 -1
  140. package/views/3d/analysis/LineOfSight/LineOfSightVisualization.js +1 -1
  141. package/views/3d/analysis/LineOfSightAnalysisView3D.js +1 -1
  142. package/views/3d/analysis/Slice/SliceTool.js +1 -1
  143. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  144. package/views/3d/camera/constraintUtils/distance.js +1 -1
  145. package/views/3d/environment/ChapmanAtmosphereTechniqueConfiguration.js +1 -1
  146. package/views/3d/environment/CloudsComposition.js +1 -1
  147. package/views/3d/environment/FogTechnique.js +1 -1
  148. package/views/3d/glTF/internal/Resource.js +1 -1
  149. package/views/3d/input/SceneInputManager.js +1 -1
  150. package/views/3d/interactive/editingTools/dragEventPipeline3D.js +1 -1
  151. package/views/3d/interactive/editingTools/draw/DrawGraphicTool3D.js +1 -1
  152. package/views/3d/interactive/editingTools/reshapeGraphic/edgeOffsetUtils.js +1 -1
  153. package/views/3d/interactive/editingTools/transformGraphic/GraphicScaleRotateTransform.js +1 -1
  154. package/views/3d/interactive/editingTools/transformGraphic/GraphicTransformTool.js +1 -1
  155. package/views/3d/interactive/editingTools/transformGraphic/ScaleRotateObjectSymbol3DAdapter.js +1 -1
  156. package/views/3d/interactive/measurementTools/directLineMeasurement3D/DirectLineMeasurement3DTool.js +1 -1
  157. package/views/3d/layers/FeatureLayerViewBase3D.js +1 -1
  158. package/views/3d/layers/GraphicsLayerView3D.js +1 -1
  159. package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
  160. package/views/3d/layers/graphics/Graphics3DExtrudeSymbolLayer.js +1 -1
  161. package/views/3d/layers/graphics/Graphics3DLineCalloutSymbolLayer.js +1 -1
  162. package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
  163. package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
  164. package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
  165. package/views/3d/layers/graphics/Graphics3DPathSymbolLayer.js +1 -1
  166. package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
  167. package/views/3d/layers/graphics/lineUtils.js +1 -1
  168. package/views/3d/layers/i3s/I3SGeometryUtil.js +1 -1
  169. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  170. package/views/3d/layers/i3s/IDBCache.js +1 -1
  171. package/views/3d/layers/i3s/IDBMockCache.js +1 -1
  172. package/views/3d/layers/i3s/PointRenderer.js +1 -1
  173. package/views/3d/layers/support/featureTileQuery3D.js +1 -1
  174. package/views/3d/state/ViewState.js +1 -1
  175. package/views/3d/support/cameraUtils.js +1 -1
  176. package/views/3d/support/orientedBoundingBox.js +1 -1
  177. package/views/3d/support/viewpointUtils.js +1 -1
  178. package/views/3d/terrain/Overlay.js +1 -1
  179. package/views/3d/terrain/OverlayRenderTarget.js +1 -1
  180. package/views/3d/terrain/OverlayRenderer.js +1 -1
  181. package/views/3d/terrain/TerrainRenderer.js +1 -1
  182. package/views/3d/terrain/TerrainSurface.js +1 -1
  183. package/views/3d/terrain/TilingSchemeLogic.js +1 -1
  184. package/views/3d/terrain/interfaces.js +1 -1
  185. package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
  186. package/views/3d/webgl-engine/collections/Component/DepthRange.js +1 -1
  187. package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
  188. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  189. package/views/3d/webgl-engine/collections/Component/Material/shader/ComponentShader.glsl.js +1 -1
  190. package/views/3d/webgl-engine/collections/Component/RenderGeometry.js +1 -1
  191. package/views/3d/webgl-engine/core/renderPasses/AllRenderPasses.js +1 -1
  192. package/views/3d/webgl-engine/core/renderPasses/RenderPassManager.js +1 -1
  193. package/views/3d/webgl-engine/core/shaderLibrary/ShaderOutput.js +1 -1
  194. package/views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js +2 -2
  195. package/views/3d/webgl-engine/core/shaderLibrary/attributes/InstancedDoublePrecision.glsl.js +2 -2
  196. package/views/3d/webgl-engine/core/shaderLibrary/attributes/ObjectAndLayerIdColor.glsl.js +9 -0
  197. package/views/3d/webgl-engine/core/shaderLibrary/default/DefaultMaterialAuxiliaryPasses.glsl.js +18 -17
  198. package/views/3d/webgl-engine/lib/DefaultVertexAttributeLocations.js +1 -1
  199. package/views/3d/webgl-engine/lib/Geometry.js +1 -1
  200. package/views/3d/webgl-engine/lib/Intersector.js +1 -1
  201. package/views/3d/webgl-engine/lib/ObjectAndLayerIdRenderHelper.js +5 -0
  202. package/views/3d/webgl-engine/lib/Octree.js +1 -1
  203. package/views/3d/webgl-engine/lib/OffscreenRendering.js +1 -1
  204. package/views/3d/webgl-engine/lib/PathGeometry.js +1 -1
  205. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  206. package/views/3d/webgl-engine/lib/TextureTechniqueConfiguration.js +1 -1
  207. package/views/3d/webgl-engine/lib/VertexAttribute.js +1 -1
  208. package/views/3d/webgl-engine/lib/geometryDataUtils.js +1 -1
  209. package/views/3d/webgl-engine/lib/lodRendering/InstanceData.js +1 -1
  210. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  211. package/views/3d/webgl-engine/lib/lodRendering/RenderInstanceData.js +1 -1
  212. package/views/3d/webgl-engine/materials/DefaultMaterial.js +1 -1
  213. package/views/3d/webgl-engine/materials/NativeLineMaterial.js +1 -1
  214. package/views/3d/webgl-engine/materials/PathMaterial.js +1 -1
  215. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  216. package/views/3d/webgl-engine/materials/ShadedColorMaterial.js +1 -1
  217. package/views/3d/webgl-engine/materials/internal/bufferWriterUtils.js +1 -1
  218. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  219. package/views/3d/webgl-engine/parts/ScreenshotManager.js +1 -1
  220. package/views/3d/webgl-engine/shaders/DefaultMaterialTechnique.js +1 -1
  221. package/views/3d/webgl-engine/shaders/DefaultMaterialTechniqueConfiguration.js +1 -1
  222. package/views/3d/webgl-engine/shaders/LaserlinePathTechniqueConfiguration.js +1 -1
  223. package/views/3d/webgl-engine/shaders/RibbonLine.glsl.js +1 -1
  224. package/views/3d/webgl-engine/shaders/RibbonLineTechnique.js +1 -1
  225. package/views/3d/webgl-engine/shaders/RibbonLineTechniqueConfiguration.js +1 -1
  226. package/views/DOMContainer.js +1 -1
  227. package/views/MapView.js +1 -1
  228. package/views/SceneView.js +1 -1
  229. package/views/View.js +1 -1
  230. package/views/analysis/analysisViewUtils.js +1 -1
  231. package/views/animation/pointToPoint/apex/planning.js +1 -1
  232. package/views/draw/PolygonDrawAction.js +1 -1
  233. package/views/draw/PolylineDrawAction.js +1 -1
  234. package/views/draw/support/createUtils.js +1 -1
  235. package/views/draw/support/surfaceCoordinateSystems.js +1 -1
  236. package/views/input/InputManager.js +1 -1
  237. package/views/input/handlers/LatestPointer.js +1 -1
  238. package/views/input/handlers/MultiTouch.js +5 -0
  239. package/views/interactive/editGeometry/operations/OffsetEdgeVertex.js +1 -1
  240. package/views/interactive/snapping/featureSources/GraphicsSnappingSource.js +1 -1
  241. package/views/interactive/snapping/featureSources/featureServiceSource/FeatureServiceTileCache.js +1 -1
  242. package/views/interactive/tooltip/Tooltip.js +1 -1
  243. package/views/interactive/tooltip/support/measurements.js +1 -1
  244. package/views/layers/GroupLayerView.js +1 -1
  245. package/views/navigation/FilteredFiniteDifference.js +1 -1
  246. package/views/navigation/MomentumEstimator.js +1 -1
  247. package/views/navigation/PanPlanarMomentumEstimator.js +1 -1
  248. package/views/navigation/PanSphericalMomentumEstimator.js +1 -1
  249. package/views/navigation/RotationMomentumEstimator.js +1 -1
  250. package/views/support/GroundViewElevationSampler.js +1 -1
  251. package/views/support/euclideanAreaMeasurementUtils.js +1 -1
  252. package/views/support/euclideanLengthMeasurementUtils.js +1 -1
  253. package/views/support/screenshotUtils.js +1 -1
  254. package/views/webgl/BufferObject.js +1 -1
  255. package/views/webgl/FramebufferObject.js +1 -1
  256. package/views/webgl/Texture.js +1 -1
  257. package/views/webgl/capabilities/Capabilities.js +1 -1
  258. package/views/webgl/capabilities.js +1 -1
  259. package/views/webgl/renderState.js +1 -1
  260. package/webscene/spec-certification/api.js +1 -1
  261. package/widgets/CoordinateConversion/support/formatUtils.js +1 -1
  262. package/widgets/ElevationProfile/ElevationProfileController.js +1 -1
  263. package/widgets/ElevationProfile/ElevationProfileLineInput.js +1 -1
  264. package/widgets/ElevationProfile/ElevationProfileLineView.js +1 -1
  265. package/widgets/ElevationProfile/support/chartUtils.js +1 -1
  266. package/widgets/ElevationProfile/support/geometryUtils.js +1 -1
  267. package/widgets/Expand.js +1 -1
  268. package/widgets/Legend/support/sizeRampUtils.js +1 -1
  269. package/widgets/LineOfSight/LineOfSightViewModel.js +1 -1
  270. package/widgets/Popup/PopupViewModel.js +1 -1
  271. package/widgets/Popup/actionUtils.js +1 -1
  272. package/widgets/ScaleRangeSlider.js +1 -1
  273. package/widgets/Slider/SliderViewModel.js +1 -1
  274. package/widgets/Widget.js +1 -1
  275. package/assets/esri/core/workers/chunks/04ea469cb081e181ca82.js +0 -1
  276. package/assets/esri/core/workers/chunks/16c2626ca47132700519.js +0 -1
  277. package/assets/esri/core/workers/chunks/1e4e5d147263e98536bc.js +0 -1
  278. package/assets/esri/core/workers/chunks/35083def3c658d1ae9ff.js +0 -1
  279. package/assets/esri/core/workers/chunks/40032d2bf404a46b8f80.js +0 -1
  280. package/assets/esri/core/workers/chunks/613e82a3e13442685ac4.js +0 -1
  281. package/assets/esri/core/workers/chunks/64b4f1dbf61439cde801.js +0 -1
  282. package/assets/esri/core/workers/chunks/abd68b7ba3be4696611c.js +0 -1
  283. package/assets/esri/core/workers/chunks/b8a062c0c9c626acf61e.js +0 -982
  284. package/assets/esri/core/workers/chunks/e08686088be0aaca1a99.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/4.25/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Camera.js";import{Cyclical as t}from"../../../core/Cyclical.js";import n from"../../../core/Logger.js";import{deg2rad as r,rad2deg as i}from"../../../core/mathUtils.js";import{isNone as o,unwrapOr as a,isSome as s}from"../../../core/maybe.js";import{createResolver as c}from"../../../core/promiseUtils.js";import{g as l,a as f,j as u,i as m,c as p}from"../../../chunks/vec3.js";import{a as d,c as h}from"../../../chunks/vec3f64.js";import v from"../../../geometry/Point.js";import{projectPointToVector as g,projectVectorToVector as y,projectVectorToPoint as R,project as x}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import j from"../../../geometry/SpatialReference.js";import{ViewingMode as w}from"../../ViewingMode.js";import{cameraOnContentAlongViewDirection as S}from"../camera/intersectionUtils.js";import{c as T,t as C}from"../../../chunks/cameraUtilsPlanar.js";import{c as z,t as b}from"../../../chunks/cameraUtilsSpherical.js";import{getGreatCircleSpanAt as U}from"./earthUtils.js";import{getElevationAtPoint as A}from"./ElevationProvider.js";import{isSpatialReferenceSupported as D}from"../../support/spatialReferenceSupport.js";const H=n.getLogger("esri.views.3d.support.cameraUtils"),P=39.37,L=96,E=1,G=8,O=5,k=1,I=h(),q=h(),J={heading:0,tilt:0},F=new v,W=new t(-20037508.342788905,20037508.342788905),X=new t(-180,180);var K;function Y(e){return e.spatialReference||j.WGS84}function N(e){return"global"===e.viewingMode?z:T}function V(e,t,n,r,i){return N(e).headingTiltToDirectionUp(t,n,r,i)}function Z(e,t){if(o(t))return null;const n=e.renderSpatialReference,i=N(e).headingTiltToDirectionUp,a=h();if(!g(t.position,a,n))return null;const s=i(a,t.heading,t.tilt);l(s.direction,s.direction,e.state.camera.distance),f(s.direction,s.direction,a);const c=S(e,a,s.direction,s.up);return c.fov=r(t.fov),c}!function(e){e[e.LOCKED=0]="LOCKED",e[e.ADJUST=1]="ADJUST"}(K||(K={}));const B=h();function Q(t,n,r){const a=t.renderSpatialReference,s=ne(t,n.eye,n.viewForward,n.up,J);let c=Y(t);return y(n.eye,a,B,c)||(c=j.WGS84,y(n.eye,a,B,c)),o(r)?new e(new v(B,c),s.heading,s.tilt,i(n.fov)):(r.position.x=B[0],r.position.y=B[1],r.position.z=B[2],r.position.spatialReference=c,r.heading=s.heading,r.tilt=s.tilt,r.fov=i(n.fov),r)}function $(e,t,n){const i=e.state.camera,o=i.width/2/i.pixelRatio;e.renderCoordsHelper.viewingMode===w.Global&&null!=n&&(t*=Math.cos(r(n))),t/=e.renderCoordsHelper.unitInMeters;return o/(L*P/t)/Math.tan(i.fovX/2)}function _(e,t,n){const i=e.state.camera,o=t*Math.tan(i.fovX/2),a=i.width/2/i.pixelRatio;let s=L*P/(a/o);return e.renderCoordsHelper.viewingMode===w.Global&&(s/=Math.cos(r(n))),s*=e.renderCoordsHelper.unitInMeters,s}function ee(e,t,n,r,i,o){return te(e,t,$(e,n,t.latitude),r,i,o)}function te(e,t,n,r,i,a){if(we(a)){const s=new je(a.signal);return se(e,r.heading,r.tilt,t,n,i,s),void s.resolver.promise.then((t=>{const n=ye(e,t,r.fov);if(!o(n))return a.resolver.resolve(n);a.resolver.reject()}),(e=>a.resolver.reject(e)))}const s=se(e,r.heading,r.tilt,t,n,i);return ye(e,s,r.fov,a)}function ne(e,t,n,r,i){return N(e).directionToHeadingTilt(t,n,r,i)}function re(e,t){return!!(e.basemapTerrain&&e.renderCoordsHelper.fromRenderCoords(t,F,e.spatialReference)&&a(A(e.elevationProvider,F),0)>F.z-k)}async function ie(e,t,n){if(!e.renderCoordsHelper.fromRenderCoords(t,F,e.spatialReference))return!1;const r=await e.elevationProvider.queryElevation(F.x,F.y,F.z,F.spatialReference,"ground",n);return a(r,0)>F.z-k}async function oe(e,t,n){const r=h();if(t)if(t instanceof v){if(g(t,r,e.renderSpatialReference),null==t.z&&null!=e.basemapTerrain){const i=await e.elevationProvider.queryElevation(t.x,t.y,t.z,t.spatialReference,"ground",n);return s(i)&&e.renderCoordsHelper.setAltitude(r,i),r}}else p(r,t);else p(r,e.state.camera.center);return r}function ae(e,t){const n=h();if(t&&t instanceof v){if(g(t,n,e.renderSpatialReference),null==t.z&&null!=e.basemapTerrain){const r=A(e.elevationProvider,t);s(r)&&e.renderCoordsHelper.setAltitude(n,r)}}else p(n,t||e.state.camera.center);return n}function se(e,t,n,r,i,o,a){const s=r&&r instanceof v?r:null;if(we(a))return oe(e,r,a.signal).then((r=>{ce(e,t,n,s,r,i,o,a)}),(e=>a.resolver.reject(e))),null;const c=ae(e,r);return ce(e,t,n,s,c,i,o,a)}function ce(e,t,n,r,i,a,s,c){if(o(r)){const t=e.renderSpatialReference;if(r=R(i,t,Y(e)),o(r))return null}a=Math.max(a,e.state.constraints.minimumPoiDistance);const l=me(e,t,n,i,a,s),f=(0,N(e).eyeForCenterWithHeadingTilt)(i,a,l.heading,l.tilt);if(s===K.ADJUST&&"global"===e.viewingMode&&n>0){const o=()=>{const o=ve(e,i,a,he(e,a,n,i));return s=n-o<1?K.LOCKED:K.ADJUST,ce(e,t,o,r,i,a,s,c)},l=e.map.ground.navigationConstraint;if(!l||"stay-above"===l.type){if(re(e,f.eye))return o();if(we(c))return ie(e,f.eye,c.signal).then((e=>e?o():(c.resolver.resolve({eye:f.eye,up:f.up,center:d(i),heading:f.heading,tilt:f.tilt}),null))),null}}const u=!c||we(c)?{center:h(),eye:h(),up:h(),tilt:0,heading:0}:c;return u.eye=f.eye,u.up=f.up,u.center=d(i),u.heading=f.heading,u.tilt=f.tilt,we(c)&&c.resolver.resolve(u),u}function le(e,t,n,r,i,s=null){const c=null!=t.zmax&&null!=t.zmin;let l,f,u;if(e.state.isGlobal){if(!D(t.spatialReference,w.Global))return we(s)&&s.resolver.reject(),null;const e=new v(t.xmin,t.ymin,t.spatialReference),n=new v(t.xmax,t.ymax,t.spatialReference),r=t.spatialReference.isGeographic?X:W;l=new v({x:r.center(e.x,n.x),y:(n.y+e.y)/2,z:c?(t.zmax+t.zmin)/2:null,spatialReference:t.spatialReference});const i=M(t.spatialReference),o=U(l,e,n);f=o.lon,u=o.lat,r.diff(e.x,n.x)>r.range/2&&(f+=i.halfCircumference),f=Math.min(f,i.halfCircumference),u=Math.min(u,i.halfCircumference)}else{const n=a(e.renderSpatialReference,t.spatialReference);n.equals(t.spatialReference)||(t=x(t,n)),f=t.xmax-t.xmin,u=t.ymax-t.ymin;const r=c?(t.zmax+t.zmin)/2:null;l=new v({x:t.xmin+.5*f,y:t.ymin+.5*u,z:r,spatialReference:n})}const m=c?t.zmax-t.zmin:0,p=e.state.camera,d=1/Math.tan(p.fovX/2),h=1/Math.tan(p.fovY/2),g=1/Math.tan(p.fov/2),y=Math.max(.5*f*d,.5*u*h,.5*m*g)/E;if(we(s)){const t=new je(s.signal);return se(e,n,r,l,y,i,t),void t.resolver.promise.then((t=>{const n=ye(e,t,e.camera.fov);if(!o(n))return s.resolver.resolve(n);s.resolver.reject()}),(e=>s.resolver.reject(e)))}const R=se(e,n,r,l,y,i);return ye(e,R,e.camera.fov,s)}function fe(e,t,n){const r=e.renderSpatialReference,i=R(n,r,Y(e));if(o(i))return null;const a=Math.tan(t.fovX/2),s=Math.tan(t.fovY/2),c=u(t.eye,n),l=2*c*a*E,f=2*c*s*E;return"global"===e.viewingMode?b(e,i,l,f):C(e,i,l,f)}function ue(e,t,n){const r=e.pointsOfInterest.centerOnSurfaceFrequent.distance;if(Math.log(n/r)/Math.LN2>G)return!0;const i=e.renderSpatialReference,a=Y(e),s=R(t,i,a),c=R(e.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i,a);if(o(s)||o(c))return!1;const l=Math.tan(.5*e.state.camera.fov)*r;return c.distance(s)/l>O}function me(e,t,n,r,i,o){let a=0;return o===K.ADJUST&&ue(e,r,i)?(t=0,a=de(e,i,n,r)):a=ge(e,r,i,n),a=e.state.constraints.clampTilt(i,a),{heading:t,tilt:n=ve(e,r,i,a)}}const pe=.7;function de(e,t,n,r){const i=e.state.constraints.tilt(t);i.max=Math.min(i.max,.5*Math.PI);const o=i.min*(1-pe)+i.max*pe,a=ge(e,r,t,n);return Math.min(a,o)}function he(e,t,n,r){const i=e.state.constraints.tilt(t);let o=ge(e,r,t,n);return o=Math.min(o,.5*Math.PI),i.min*(1-pe)+o*pe}function ve(e,t,n,r){return N(e).lookAtTiltToEyeTilt(r,t,n)}function ge(e,t,n,r){return N(e).eyeTiltToLookAtTilt(r,t,n)}function ye(t,n,r,i){if(o(n))return null;const a=t.renderSpatialReference,c=R(n.eye,a,Y(t));return o(c)?null:s(i)?(i.position=c,i.heading=n.heading,i.tilt=n.tilt,i.fov=r,i):new e(c,n.heading,n.tilt,r)}function Re(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.levelAtScale(t);H.error("#scaleToZoom()","Cannot compute zoom from scale without a tiling scheme")}function xe(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.scaleAtLevel(t);H.error("#zoomToScale()","Cannot compute scale from zoom without a tiling scheme")}function Me(t,n,r){const i=t.renderSpatialReference;let o,a;n||(n=t.state.camera);const s=j.WGS84;return n instanceof e?(o=n.position.latitude,g(n.position,I,i),g(r,q,i),a=m(I,q)):(y(n.center,i,q,s),o=q[1],a=n.distance),_(t,a,o)}class je{constructor(e){this.signal=e,this.resolver=c()}}function we(e){return e&&"resolver"in e}export{je as AsyncContext,K as OrientationMode,Me as computeScale,ne as directionToHeadingTilt,_ as distanceToScale,Z as externalToInternal,te as fromCenterDistance,ee as fromCenterScale,le as fromExtent,se as getObserverForPointAtDistance,V as headingTiltToDirectionUp,Q as internalToExternal,ye as observerToCamera,$ as scaleToDistance,Re as scaleToZoom,fe as toExtent,xe as zoomToScale};
5
+ import e from"../../../Camera.js";import{Cyclical as t}from"../../../core/Cyclical.js";import n from"../../../core/Logger.js";import{deg2rad as r,rad2deg as i}from"../../../core/mathUtils.js";import{isNone as o,unwrapOr as a,isSome as s}from"../../../core/maybe.js";import{createResolver as c}from"../../../core/promiseUtils.js";import{g as l,a as f,j as u,i as m,c as p}from"../../../chunks/vec3.js";import{a as d,c as h}from"../../../chunks/vec3f64.js";import v from"../../../geometry/Point.js";import{projectPointToVector as g,projectVectorToVector as y,projectVectorToPoint as R,project as x}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import j from"../../../geometry/SpatialReference.js";import{ViewingMode as w}from"../../ViewingMode.js";import{cameraOnContentAlongViewDirection as S}from"../camera/intersectionUtils.js";import{t as T,c as C}from"../../../chunks/cameraUtilsPlanar.js";import{t as z,c as b}from"../../../chunks/cameraUtilsSpherical.js";import{getGreatCircleSpanAt as U}from"./earthUtils.js";import{getElevationAtPoint as A}from"./ElevationProvider.js";import{isSpatialReferenceSupported as D}from"../../support/spatialReferenceSupport.js";const H=n.getLogger("esri.views.3d.support.cameraUtils"),P=39.37,L=96,E=1,G=8,O=5,k=1,I=h(),q=h(),J={heading:0,tilt:0},F=new v,W=new t(-20037508.342788905,20037508.342788905),X=new t(-180,180);var K;function Y(e){return e.spatialReference||j.WGS84}function N(e){return"global"===e.viewingMode?b:C}function V(e,t,n,r,i){return N(e).headingTiltToDirectionUp(t,n,r,i)}function Z(e,t){if(o(t))return null;const n=e.renderSpatialReference,i=N(e).headingTiltToDirectionUp,a=h();if(!g(t.position,a,n))return null;const s=i(a,t.heading,t.tilt);l(s.direction,s.direction,e.state.camera.distance),f(s.direction,s.direction,a);const c=S(e,a,s.direction,s.up);return c.fov=r(t.fov),c}!function(e){e[e.LOCKED=0]="LOCKED",e[e.ADJUST=1]="ADJUST"}(K||(K={}));const B=h();function Q(t,n,r){const a=t.renderSpatialReference,s=ne(t,n.eye,n.viewForward,n.up,J);let c=Y(t);return y(n.eye,a,B,c)||(c=j.WGS84,y(n.eye,a,B,c)),o(r)?new e(new v(B,c),s.heading,s.tilt,i(n.fov)):(r.position.x=B[0],r.position.y=B[1],r.position.z=B[2],r.position.spatialReference=c,r.heading=s.heading,r.tilt=s.tilt,r.fov=i(n.fov),r)}function $(e,t,n){const i=e.state.camera,o=i.width/2/i.pixelRatio;e.renderCoordsHelper.viewingMode===w.Global&&null!=n&&(t*=Math.cos(r(n))),t/=e.renderCoordsHelper.unitInMeters;return o/(L*P/t)/Math.tan(i.fovX/2)}function _(e,t,n){const i=e.state.camera,o=t*Math.tan(i.fovX/2),a=i.width/2/i.pixelRatio;let s=L*P/(a/o);return e.renderCoordsHelper.viewingMode===w.Global&&(s/=Math.cos(r(n))),s*=e.renderCoordsHelper.unitInMeters,s}function ee(e,t,n,r,i,o){return te(e,t,$(e,n,t.latitude),r,i,o)}function te(e,t,n,r,i,a){if(we(a)){const s=new je(a.signal);return se(e,r.heading,r.tilt,t,n,i,s),void s.resolver.promise.then((t=>{const n=ye(e,t,r.fov);if(!o(n))return a.resolver.resolve(n);a.resolver.reject()}),(e=>a.resolver.reject(e)))}const s=se(e,r.heading,r.tilt,t,n,i);return ye(e,s,r.fov,a)}function ne(e,t,n,r,i){return N(e).directionToHeadingTilt(t,n,r,i)}function re(e,t){return!!(e.basemapTerrain&&e.renderCoordsHelper.fromRenderCoords(t,F,e.spatialReference)&&a(A(e.elevationProvider,F),0)>F.z-k)}async function ie(e,t,n){if(!e.renderCoordsHelper.fromRenderCoords(t,F,e.spatialReference))return!1;const r=await e.elevationProvider.queryElevation(F.x,F.y,F.z,F.spatialReference,"ground",n);return a(r,0)>F.z-k}async function oe(e,t,n){const r=h();if(t)if(t instanceof v){if(g(t,r,e.renderSpatialReference),null==t.z&&null!=e.basemapTerrain){const i=await e.elevationProvider.queryElevation(t.x,t.y,t.z,t.spatialReference,"ground",n);return s(i)&&e.renderCoordsHelper.setAltitude(r,i),r}}else p(r,t);else p(r,e.state.camera.center);return r}function ae(e,t){const n=h();if(t&&t instanceof v){if(g(t,n,e.renderSpatialReference),null==t.z&&null!=e.basemapTerrain){const r=A(e.elevationProvider,t);s(r)&&e.renderCoordsHelper.setAltitude(n,r)}}else p(n,t||e.state.camera.center);return n}function se(e,t,n,r,i,o,a){const s=r&&r instanceof v?r:null;if(we(a))return oe(e,r,a.signal).then((r=>{ce(e,t,n,s,r,i,o,a)}),(e=>a.resolver.reject(e))),null;const c=ae(e,r);return ce(e,t,n,s,c,i,o,a)}function ce(e,t,n,r,i,a,s,c){if(o(r)){const t=e.renderSpatialReference;if(r=R(i,t,Y(e)),o(r))return null}a=Math.max(a,e.state.constraints.minimumPoiDistance);const l=me(e,t,n,i,a,s),f=(0,N(e).eyeForCenterWithHeadingTilt)(i,a,l.heading,l.tilt);if(s===K.ADJUST&&"global"===e.viewingMode&&n>0){const o=()=>{const o=ve(e,i,a,he(e,a,n,i));return s=n-o<1?K.LOCKED:K.ADJUST,ce(e,t,o,r,i,a,s,c)},l=e.map.ground.navigationConstraint;if(!l||"stay-above"===l.type){if(re(e,f.eye))return o();if(we(c))return ie(e,f.eye,c.signal).then((e=>e?o():(c.resolver.resolve({eye:f.eye,up:f.up,center:d(i),heading:f.heading,tilt:f.tilt}),null))),null}}const u=!c||we(c)?{center:h(),eye:h(),up:h(),tilt:0,heading:0}:c;return u.eye=f.eye,u.up=f.up,u.center=d(i),u.heading=f.heading,u.tilt=f.tilt,we(c)&&c.resolver.resolve(u),u}function le(e,t,n,r,i,s=null){const c=null!=t.zmax&&null!=t.zmin;let l,f,u;if(e.state.isGlobal){if(!D(t.spatialReference,w.Global))return we(s)&&s.resolver.reject(),null;const e=new v(t.xmin,t.ymin,t.spatialReference),n=new v(t.xmax,t.ymax,t.spatialReference),r=t.spatialReference.isGeographic?X:W;l=new v({x:r.center(e.x,n.x),y:(n.y+e.y)/2,z:c?(t.zmax+t.zmin)/2:null,spatialReference:t.spatialReference});const i=M(t.spatialReference),o=U(l,e,n);f=o.lon,u=o.lat,r.diff(e.x,n.x)>r.range/2&&(f+=i.halfCircumference),f=Math.min(f,i.halfCircumference),u=Math.min(u,i.halfCircumference)}else{const n=a(e.renderSpatialReference,t.spatialReference);n.equals(t.spatialReference)||(t=x(t,n)),f=t.xmax-t.xmin,u=t.ymax-t.ymin;const r=c?(t.zmax+t.zmin)/2:null;l=new v({x:t.xmin+.5*f,y:t.ymin+.5*u,z:r,spatialReference:n})}const m=c?t.zmax-t.zmin:0,p=e.state.camera,d=1/Math.tan(p.fovX/2),h=1/Math.tan(p.fovY/2),g=1/Math.tan(p.fov/2),y=Math.max(.5*f*d,.5*u*h,.5*m*g)/E;if(we(s)){const t=new je(s.signal);return se(e,n,r,l,y,i,t),void t.resolver.promise.then((t=>{const n=ye(e,t,e.camera.fov);if(!o(n))return s.resolver.resolve(n);s.resolver.reject()}),(e=>s.resolver.reject(e)))}const R=se(e,n,r,l,y,i);return ye(e,R,e.camera.fov,s)}function fe(e,t,n){const r=e.renderSpatialReference,i=R(n,r,Y(e));if(o(i))return null;const a=Math.tan(t.fovX/2),s=Math.tan(t.fovY/2),c=u(t.eye,n),l=2*c*a*E,f=2*c*s*E;return"global"===e.viewingMode?z(e,i,l,f):T(e,i,l,f)}function ue(e,t,n){const r=e.pointsOfInterest.centerOnSurfaceFrequent.distance;if(Math.log(n/r)/Math.LN2>G)return!0;const i=e.renderSpatialReference,a=Y(e),s=R(t,i,a),c=R(e.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,i,a);if(o(s)||o(c))return!1;const l=Math.tan(.5*e.state.camera.fov)*r;return c.distance(s)/l>O}function me(e,t,n,r,i,o){let a=0;return o===K.ADJUST&&ue(e,r,i)?(t=0,a=de(e,i,n,r)):a=ge(e,r,i,n),a=e.state.constraints.clampTilt(i,a),{heading:t,tilt:n=ve(e,r,i,a)}}const pe=.7;function de(e,t,n,r){const i=e.state.constraints.tilt(t);i.max=Math.min(i.max,.5*Math.PI);const o=i.min*(1-pe)+i.max*pe,a=ge(e,r,t,n);return Math.min(a,o)}function he(e,t,n,r){const i=e.state.constraints.tilt(t);let o=ge(e,r,t,n);return o=Math.min(o,.5*Math.PI),i.min*(1-pe)+o*pe}function ve(e,t,n,r){return N(e).lookAtTiltToEyeTilt(r,t,n)}function ge(e,t,n,r){return N(e).eyeTiltToLookAtTilt(r,t,n)}function ye(t,n,r,i){if(o(n))return null;const a=t.renderSpatialReference,c=R(n.eye,a,Y(t));return o(c)?null:s(i)?(i.position=c,i.heading=n.heading,i.tilt=n.tilt,i.fov=r,i):new e(c,n.heading,n.tilt,r)}function Re(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.levelAtScale(t);H.error("#scaleToZoom()","Cannot compute zoom from scale without a tiling scheme")}function xe(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.scaleAtLevel(t);H.error("#zoomToScale()","Cannot compute scale from zoom without a tiling scheme")}function Me(t,n,r){const i=t.renderSpatialReference;let o,a;n||(n=t.state.camera);const s=j.WGS84;return n instanceof e?(o=n.position.latitude,g(n.position,I,i),g(r,q,i),a=m(I,q)):(y(n.center,i,q,s),o=q[1],a=n.distance),_(t,a,o)}class je{constructor(e){this.signal=e,this.resolver=c()}}function we(e){return e&&"resolver"in e}export{je as AsyncContext,K as OrientationMode,Me as computeScale,ne as directionToHeadingTilt,_ as distanceToScale,Z as externalToInternal,te as fromCenterDistance,ee as fromCenterScale,le as fromExtent,se as getObserverForPointAtDistance,V as headingTiltToDirectionUp,Q as internalToExternal,ye as observerToCamera,$ as scaleToDistance,Re as scaleToZoom,fe as toExtent,xe as zoomToScale};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{h as t,e}from"../../../chunks/mat3.js";import{c as a}from"../../../chunks/mat3f64.js";import{a as n,c as r}from"../../../chunks/quat.js";import{a as s,b as f}from"../../../chunks/quatf32.js";import{a as o}from"../../../chunks/quatf64.js";import{c as i,b as h,q as c,w as u,s as l,t as m,a as z,u as S}from"../../../chunks/vec3.js";import{a as b,b as M}from"../../../chunks/vec3f32.js";import{a as p,b as q,c as j}from"../../../chunks/vec3f64.js";import{t as k}from"../../../chunks/vec4.js";import{c as v}from"../../../chunks/vec4f64.js";import{create as x}from"../../../geometry/support/aaBoundingBox.js";import{signedDistance as y,normal as g}from"../../../geometry/support/plane.js";import{computeOBB as w}from"./dito.js";const A=o(),B=j(),d=j(),I=v(),C=a();class D{constructor(t){const e=56,a=0,n=24,r=36,s=t*e;this.buffer=new ArrayBuffer(s),this.obbs=new Array(t);for(let o=0;o<t;o++)this.obbs[o]={center:q(this.buffer,e*o+a),halfSize:M(this.buffer,e*o+n),quaternion:f(this.buffer,e*o+r)}}}function E(t=[0,0,0],e=[-1,-1,-1],a=[0,0,0,1]){return{center:p(t),halfSize:b(e),quaternion:s(a)}}function F(t){return E(t.center,t.halfSize,t.quaternion)}function G(t,e){i(e.center,t.center),i(e.halfSize,t.halfSize),n(e.quaternion,t.quaternion)}function H(t,e){return e=e||E(),w(t,e),e}function J(t,e){const a=y(e,t.center),n=U(t,g(e));return a>n?1:a<-n?-1:0}function K(e,a){a||(a=x());const n=t(C,e.quaternion),r=e.halfSize[0]*Math.abs(n[0])+e.halfSize[1]*Math.abs(n[3])+e.halfSize[2]*Math.abs(n[6]),s=e.halfSize[0]*Math.abs(n[1])+e.halfSize[1]*Math.abs(n[4])+e.halfSize[2]*Math.abs(n[7]),f=e.halfSize[0]*Math.abs(n[2])+e.halfSize[1]*Math.abs(n[5])+e.halfSize[2]*Math.abs(n[8]);return a[0]=e.center[0]-r,a[1]=e.center[1]-s,a[2]=e.center[2]-f,a[3]=e.center[0]+r,a[4]=e.center[1]+s,a[5]=e.center[2]+f,a}function L(t,e){return y(e,t.center)-U(t,g(e))}function N(t,e){return y(e,t.center)+U(t,g(e))}function O(t,e){return J(t,e[0])<=0&&J(t,e[1])<=0&&J(t,e[2])<=0&&J(t,e[3])<=0&&J(t,e[4])<=0&&J(t,e[5])<=0}function P(t,e,a,n=0){r(A,t.quaternion),h(B,e,t.center);const s=c(B,B,A),f=c(d,a,A);let o=-1/0,i=1/0;for(let r=0;r<3;r++)if(Math.abs(f[r])>1e-6){const e=(n+t.halfSize[r]-s[r])/f[r],a=(-n-t.halfSize[r]-s[r])/f[r];o=Math.max(o,Math.min(e,a)),i=Math.min(i,Math.max(e,a))}else if(s[r]>t.halfSize[r]+n||s[r]<-t.halfSize[r]-n)return!1;return o<=i}function Q(a,n,s,f,o){r(A,a.quaternion),u(B,n,a.center),c(B,B,A);const i=B[0]<-a.halfSize[0]?-1:B[0]>a.halfSize[0]?1:0,h=B[1]<-a.halfSize[1]?-1:B[1]>a.halfSize[1]?1:0,S=B[2]<-a.halfSize[2]?-1:B[2]>a.halfSize[2]?1:0,b=Math.abs(i)+Math.abs(h)+Math.abs(S);if(0===b)return 1/0;const M=1===b?4:6,p=6*(i+3*h+9*S+13);t(C,a.quaternion),e(C,C,a.halfSize);for(let t=0;t<M;t++){const e=T[p+t];l(B,((1&e)<<1)-1,(2&e)-1,((4&e)>>1)-1),m(B,B,C),z(I,a.center,B),I[3]=1,k(I,I,s);const n=1/Math.max(1e-6,I[3]);R[2*t]=I[0]*n,R[2*t+1]=I[1]*n}const q=2*M-2;let j=R[0]*(R[3]-R[q+1])+R[q]*(R[1]-R[q-1]);for(let t=2;t<q;t+=2)j+=R[t]*(R[t+3]-R[t-1]);return Math.abs(j)*f*o*.125}const R=[.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.2],T=(()=>{const t=new Int8Array(162);let e=0;const a=a=>{for(let n=0;n<a.length;n++)t[e+n]=a[n];e+=6};return a([6,2,3,1,5,4]),a([0,2,3,1,5,4]),a([0,2,3,7,5,4]),a([0,1,3,2,6,4]),a([0,1,3,2,0,0]),a([0,1,5,7,3,2]),a([0,1,3,7,6,4]),a([0,1,3,7,6,2]),a([0,1,5,7,6,2]),a([0,1,5,4,6,2]),a([0,1,5,4,0,0]),a([0,1,3,7,5,4]),a([0,2,6,4,0,0]),a([0,0,0,0,0,0]),a([1,3,7,5,0,0]),a([2,3,7,6,4,0]),a([2,3,7,6,0,0]),a([2,3,1,5,7,6]),a([0,1,5,7,6,2]),a([0,1,5,7,6,4]),a([0,1,3,7,6,4]),a([4,5,7,6,2,0]),a([4,5,7,6,0,0]),a([4,5,1,3,7,6]),a([0,2,3,7,5,4]),a([6,2,3,7,5,4]),a([6,2,3,1,5,4]),t})();function U(t,e){r(A,t.quaternion),c(B,e,A);const a=t.halfSize;return Math.abs(B[0]*a[0])+Math.abs(B[1]*a[1])+Math.abs(B[2]*a[2])}function V(t,e){for(let a=0;a<8;++a){const n=e[a];n[0]=1&a?-t.halfSize[0]:t.halfSize[0],n[1]=2&a?-t.halfSize[1]:t.halfSize[1],n[2]=4&a?-t.halfSize[2]:t.halfSize[2],c(n,n,t.quaternion),z(n,n,t.center)}}function W(t){return S(t.halfSize)}export{D as ObbArray,F as clone,H as compute,V as corners,E as create,P as intersectLine,J as intersectPlane,O as isVisible,N as maximumDistancePlane,L as minimumDistancePlane,Q as projectedArea,U as projectedRadius,W as radius,G as set,K as toAaBoundingBox};
5
+ import{h as t,e}from"../../../chunks/mat3.js";import{c as a}from"../../../chunks/mat3f64.js";import{a as n,c as r}from"../../../chunks/quat.js";import{a as s,b as f}from"../../../chunks/quatf32.js";import{a as o}from"../../../chunks/quatf64.js";import{c as i,b as h,q as c,w as u,s as l,t as m,a as z,u as S}from"../../../chunks/vec3.js";import{b,a as M}from"../../../chunks/vec3f32.js";import{b as p,a as q,c as j}from"../../../chunks/vec3f64.js";import{t as k}from"../../../chunks/vec4.js";import{c as v}from"../../../chunks/vec4f64.js";import{create as x}from"../../../geometry/support/aaBoundingBox.js";import{signedDistance as y,normal as g}from"../../../geometry/support/plane.js";import{computeOBB as w}from"./dito.js";const A=o(),B=j(),d=j(),I=v(),C=a();class D{constructor(t){const e=56,a=0,n=24,r=36,f=t*e;this.buffer=new ArrayBuffer(f),this.obbs=new Array(t);for(let o=0;o<t;o++)this.obbs[o]={center:p(this.buffer,e*o+a),halfSize:b(this.buffer,e*o+n),quaternion:s(this.buffer,e*o+r)}}}function E(t=[0,0,0],e=[-1,-1,-1],a=[0,0,0,1]){return{center:q(t),halfSize:M(e),quaternion:f(a)}}function F(t){return E(t.center,t.halfSize,t.quaternion)}function G(t,e){i(e.center,t.center),i(e.halfSize,t.halfSize),n(e.quaternion,t.quaternion)}function H(t,e){return e=e||E(),w(t,e),e}function J(t,e){const a=y(e,t.center),n=U(t,g(e));return a>n?1:a<-n?-1:0}function K(e,a){a||(a=x());const n=t(C,e.quaternion),r=e.halfSize[0]*Math.abs(n[0])+e.halfSize[1]*Math.abs(n[3])+e.halfSize[2]*Math.abs(n[6]),s=e.halfSize[0]*Math.abs(n[1])+e.halfSize[1]*Math.abs(n[4])+e.halfSize[2]*Math.abs(n[7]),f=e.halfSize[0]*Math.abs(n[2])+e.halfSize[1]*Math.abs(n[5])+e.halfSize[2]*Math.abs(n[8]);return a[0]=e.center[0]-r,a[1]=e.center[1]-s,a[2]=e.center[2]-f,a[3]=e.center[0]+r,a[4]=e.center[1]+s,a[5]=e.center[2]+f,a}function L(t,e){return y(e,t.center)-U(t,g(e))}function N(t,e){return y(e,t.center)+U(t,g(e))}function O(t,e){return J(t,e[0])<=0&&J(t,e[1])<=0&&J(t,e[2])<=0&&J(t,e[3])<=0&&J(t,e[4])<=0&&J(t,e[5])<=0}function P(t,e,a,n=0){r(A,t.quaternion),h(B,e,t.center);const s=c(B,B,A),f=c(d,a,A);let o=-1/0,i=1/0;for(let r=0;r<3;r++)if(Math.abs(f[r])>1e-6){const e=(n+t.halfSize[r]-s[r])/f[r],a=(-n-t.halfSize[r]-s[r])/f[r];o=Math.max(o,Math.min(e,a)),i=Math.min(i,Math.max(e,a))}else if(s[r]>t.halfSize[r]+n||s[r]<-t.halfSize[r]-n)return!1;return o<=i}function Q(a,n,s,f,o){r(A,a.quaternion),u(B,n,a.center),c(B,B,A);const i=B[0]<-a.halfSize[0]?-1:B[0]>a.halfSize[0]?1:0,h=B[1]<-a.halfSize[1]?-1:B[1]>a.halfSize[1]?1:0,S=B[2]<-a.halfSize[2]?-1:B[2]>a.halfSize[2]?1:0,b=Math.abs(i)+Math.abs(h)+Math.abs(S);if(0===b)return 1/0;const M=1===b?4:6,p=6*(i+3*h+9*S+13);t(C,a.quaternion),e(C,C,a.halfSize);for(let t=0;t<M;t++){const e=T[p+t];l(B,((1&e)<<1)-1,(2&e)-1,((4&e)>>1)-1),m(B,B,C),z(I,a.center,B),I[3]=1,k(I,I,s);const n=1/Math.max(1e-6,I[3]);R[2*t]=I[0]*n,R[2*t+1]=I[1]*n}const q=2*M-2;let j=R[0]*(R[3]-R[q+1])+R[q]*(R[1]-R[q-1]);for(let t=2;t<q;t+=2)j+=R[t]*(R[t+3]-R[t-1]);return Math.abs(j)*f*o*.125}const R=[.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.2],T=(()=>{const t=new Int8Array(162);let e=0;const a=a=>{for(let n=0;n<a.length;n++)t[e+n]=a[n];e+=6};return a([6,2,3,1,5,4]),a([0,2,3,1,5,4]),a([0,2,3,7,5,4]),a([0,1,3,2,6,4]),a([0,1,3,2,0,0]),a([0,1,5,7,3,2]),a([0,1,3,7,6,4]),a([0,1,3,7,6,2]),a([0,1,5,7,6,2]),a([0,1,5,4,6,2]),a([0,1,5,4,0,0]),a([0,1,3,7,5,4]),a([0,2,6,4,0,0]),a([0,0,0,0,0,0]),a([1,3,7,5,0,0]),a([2,3,7,6,4,0]),a([2,3,7,6,0,0]),a([2,3,1,5,7,6]),a([0,1,5,7,6,2]),a([0,1,5,7,6,4]),a([0,1,3,7,6,4]),a([4,5,7,6,2,0]),a([4,5,7,6,0,0]),a([4,5,1,3,7,6]),a([0,2,3,7,5,4]),a([6,2,3,7,5,4]),a([6,2,3,1,5,4]),t})();function U(t,e){r(A,t.quaternion),c(B,e,A);const a=t.halfSize;return Math.abs(B[0]*a[0])+Math.abs(B[1]*a[1])+Math.abs(B[2]*a[2])}function V(t,e){for(let a=0;a<8;++a){const n=e[a];n[0]=1&a?-t.halfSize[0]:t.halfSize[0],n[1]=2&a?-t.halfSize[1]:t.halfSize[1],n[2]=4&a?-t.halfSize[2]:t.halfSize[2],c(n,n,t.quaternion),z(n,n,t.center)}}function W(t){return S(t.halfSize)}export{D as ObbArray,F as clone,H as compute,V as corners,E as create,P as intersectLine,J as intersectPlane,O as isVisible,N as maximumDistancePlane,L as minimumDistancePlane,Q as projectedArea,U as projectedRadius,W as radius,G as set,K as toAaBoundingBox};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Camera.js";import"../../../geometry.js";import t from"../../../Graphic.js";import n from"../../../Viewpoint.js";import{result as r}from"../../../core/asyncUtils.js";import"../../../core/has.js";import{cyclicalDegrees as a}from"../../../core/Cyclical.js";import o from"../../../core/Error.js";import{isSome as i,isNone as s,unwrapOr as c,unwrap as l}from"../../../core/maybe.js";import{eachAlways as m}from"../../../core/promiseUtils.js";import{f,t as u}from"../../../chunks/mat3.js";import{c as p}from"../../../chunks/mat3f64.js";import{c as g}from"../../../chunks/mat4f64.js";import{g as h,a as y,i as d,c as x,b as w,s as v,t as b}from"../../../chunks/vec3.js";import{c as j}from"../../../chunks/vec3f64.js";import{projectVectorToPoint as R,projectPointToVector as G,projectBuffer as z,computeTranslationToOriginAndRotation as S,projectVectorToVector as B}from"../../../geometry/projection.js";import{create as k,empty as M,center as Z,toRect as A,isPoint as F,expandWithVec3 as E,expandWithAABB as T,width as U,height as D,depth as O}from"../../../geometry/support/aaBoundingBox.js";import{create as C,isPoint as P}from"../../../geometry/support/aaBoundingRect.js";import{intersectsPoint as I}from"../../../geometry/support/frustum.js";import{getResolutionInMetersForScale as J}from"../../../geometry/support/scaleUtils.js";import{project as K,canProject as L}from"../../../geometry/support/webMercatorUtils.js";import{cameraOnContentAlongViewDirection as N}from"../camera/intersectionUtils.js";import{internalToExternal as V,OrientationMode as W,scaleToDistance as Y,fromCenterDistance as $,fromExtent as q,zoomToScale as X,externalToInternal as _,computeScale as H,AsyncContext as Q,distanceToScale as ee,fromCenterScale as te,directionToHeadingTilt as ne}from"./cameraUtils.js";import{getElevationAtPoint as re}from"./ElevationProvider.js";import ae from"../../../geometry/Point.js";import oe from"../../../geometry/SpatialReference.js";import ie from"../../../geometry/Extent.js";import se from"../../../geometry/Geometry.js";const ce=.66;function le(e){return 360-a.normalize(e)}function me(e){return a.normalize(360-e)}function fe(e){return i(e)&&e.resolver&&e.resolver.reject(),null}function ue(e,t){return i(e)&&e.resolver&&e.resolver.resolve(t),t}function pe(e,t,n,r=null){if(!t)return fe(r);const a=e.spatialReference||oe.WGS84;if(i(t.camera)){const e=K(t.camera.position,a);if(s(e))return fe(r);const n=t.camera.clone();return n.position=e,ue(r,n)}if(s(t.targetGeometry))return fe(r);const o=t.get("targetGeometry.spatialReference");if(o&&!L(o,a))return fe(r);const c=V(e,e.state.camera);let l=W.ADJUST;if(null!=t.rotation&&(c.heading=le(t.rotation),l=W.LOCKED),null!=n&&(c.tilt=n),"point"===t.targetGeometry.type){const n=t.targetGeometry;let a;const o=t.targetGeometry.clone();return a=null!=t.scale?Y(e,t.scale,n.latitude):e.state.camera.distance,$(e,o,a,c,l,r)}const m=t.targetGeometry.extent;return q(e,m,c.heading,c.tilt,l,r)}function ge(e,t,r=null){return s(r)&&(r=new n),we(e,null,t.clone(),r)}async function he(t,r,a){const i=Fe(t,r);if(!i)throw new o("viewpointutils-create:no-target","Missing target for creating viewpoint");const s=new e({fov:t.camera.fov}),c=new n({camera:s});if(i.target instanceof n){return Ee(await Re(t,i.target,i,a,c))}if(i.target instanceof e)return Ee(Ge(t,i.target,c));const l=null!=i.scale||null!=i.zoom;if(i.target instanceof ie){const e=i.target.xmin===i.target.xmax||i.target.ymin===i.target.ymax;return Ee(l||e?await Se(t,i,i.target.center,s,a,c):await Me(t,i,i.target,s,a,c))}const m={boundingBox:M(),hasZ:!1,screenSpaceObjects:[]},f=l?de(t,i):void 0;if(await je(t,i.target,f,m),isFinite(m.boundingBox[0])){let e;if(Z(m.boundingBox,Ue),Ne.x=Ue[0],Ne.y=Ue[1],Ne.z=Ue[2],Ne.spatialReference=t.spatialReference,isFinite(Ne.z)&&m.hasZ?e=F(m.boundingBox):(Ne.z=void 0,e=P(A(m.boundingBox,Pe))),l||e)return Ee(await Se(t,i,Ne,s,a,c));const n=Te(t,m.screenSpaceObjects);return Ee(await Ae(t,i,Ne,m.boundingBox,n,s,a,c))}return i.position?Ee(Be(t,i,s,c)):Ee(await ke(t,i,s,a,c))}function ye(e,t){return null==t.scale&&null!=t.zoom?X(e,t.zoom):t.scale}function de(e,t){return J(ye(e,t))}function xe(e,t){let n=!1;return null!=t.heading?(e.heading=t.heading,n=!0):null!=t.rotation&&(e.heading=le(t.rotation),n=!0),null!=t.tilt&&(e.tilt=t.tilt,n=!0),null!=t.fov&&(e.fov=t.fov),n}function we(e,t,n,r){const a=e.spatialReference||oe.WGS84;return t=i(t)?t:_(e,n),s(t)||(r.targetGeometry=R(t.center,e.renderSpatialReference,a),r.scale=H(e,t),r.rotation=me(n.heading),r.camera=n),r}function ve(e,t,n){if(!t)return;if(!L(t.spatialReference,e.spatialReference))throw new o("viewpointutils:incompatible-spatialreference",`Spatial reference (${t.spatialReference?t.spatialReference.wkid:"unknown"}) is incompatible with the view (${e.spatialReference.wkid})`,{geometry:t});const r=[];if(!t.hasZ&&e.basemapTerrain){let n;switch(t.type){case"point":n=t;break;case"multipoint":case"polyline":n=t.extent.center;break;case"mesh":n=t.origin;break;case"extent":n=t.center;break;case"polygon":n=t.centroid}n&&i(e.basemapTerrain.spatialReference)&&L(n,e.basemapTerrain.spatialReference)?Ue[2]=c(re(e.elevationProvider,n),0):Ue[2]=0}(0,Ve[t.type])(t,(e=>{r.push(e[0],e[1],e[2])}),Ue);const a=r.length/3;if(0===a)return;const s=new Array(r.length);if(z(r,t.spatialReference,0,s,e.spatialReference,0,a)){t.hasZ&&(n.hasZ=!0);for(let e=0;e<s.length;e+=3)t.hasZ?(Ue[0]=s[e+0],Ue[1]=s[e+1],Ue[2]=s[e+2]):(Ue[0]=s[e+0],Ue[1]=s[e+1]),E(n.boundingBox,Ue)}}async function be(e,t,n,a){const o=await r(e.whenViewForGraphic(t));if(!1===o.ok||s(o.value)||!("whenGraphicBounds"in o.value))return void ve(e,t.geometry,a);const i=o.value,c=await r(i.whenGraphicBounds(t,{minDemResolution:n}));if(!1===c.ok)return void ve(e,t.geometry,a);const{screenSpaceObjects:l,boundingBox:m}=c.value;T(a.boundingBox,m),l&&l.forEach((e=>{a.screenSpaceObjects.push(e)})),isFinite(m[2])&&(a.hasZ=!0)}async function je(e,n,r,a){if(Array.isArray(n)&&2===n.length){const t=n[0],r=n[1];if("number"==typeof t&&"number"==typeof r)return Ne.x=t,Ne.y=r,Ne.z=void 0,Ne.spatialReference=e.spatialReference.isGeographic?e.spatialReference:oe.WGS84,void ve(e,Ne,a)}n&&"function"==typeof n.map?await m(n.map((t=>je(e,t,r,a)))):n instanceof se?ve(e,n,a):n instanceof t&&await be(e,n,r,a)}async function Re(e,t,n,r,a){if(i(t.camera))return Ge(e,t.camera,a);a.scale=t.scale,a.rotation=t.rotation,a.targetGeometry=i(t.targetGeometry)?t.targetGeometry.clone():null,a.camera=null,null!=n.heading?a.rotation=me(n.heading):null!=n.rotation&&(a.rotation=n.rotation);const o=ye(e,n);null!=o&&(a.scale=o);const s=new Q(r);return pe(e,a,n.tilt,s),a.camera=await s.resolver.promise,a}function Ge(e,t,n){const r=e.spatialReference,a=K(t.position,r);return s(a)?null:((t=t.clone()).fov=e.camera.fov,t.position=a,we(e,null,t,n))}function ze(e,t,n,r,a,o){const i=e.renderSpatialReference;return G(n.position,Je,i),G(t,Ke,i),o.targetGeometry=new ae(t),a.position=new ae(n.position),w(Ie,Ke,Je),ne(e,Je,Ie,r.up,a),o.scale=ee(e,d(Je,Ke),o.targetGeometry.latitude),o.rotation=me(a.heading),o.camera=a,o}async function Se(e,t,n,r,a,i){if(s(n))throw new o("createfromcenter","invalid point");i.targetGeometry=n.clone();const c=N(e);if(t.position)return ze(e,i.targetGeometry,t,c,r,i);if(t.zoomFactor){const r=c.distance/t.zoomFactor,a=h(Ue,c.viewForward,-r);c.eye=y(Ue,c.center,a),i.scale=ee(e,r,n.latitude)}V(e,c,r);const l=xe(r,t)?W.LOCKED:W.ADJUST;if(!t.zoomFactor){i.scale=ye(e,t),null==i.scale&&(G(n,Ue,e.renderSpatialReference),I(c.frustum,Ue)?i.scale=ee(e,d(c.eye,Ue),n.latitude):i.scale=H(e,c));const o=new Q(a);te(e,i.targetGeometry,i.scale,r,l,o),i.camera=await o.resolver.promise}return i}function Be(e,t,n,r){const a=N(e);return x(Ie,a.viewForward),ne(e,a.eye,Ie,a.up,Le),n.position=new ae(t.position),n.heading=null!=t.heading?t.heading:Le.heading,n.tilt=null!=t.tilt?t.tilt:Le.tilt,we(e,null,n,r)}async function ke(e,t,n,r,a){const o=N(e);return Se(e,t,R(o.center,e.renderSpatialReference,e.spatialReference),n,r,a)}async function Me(e,t,n,r,a,o){o.targetGeometry=n.clone();const i=N(e);V(e,i,r);const s=xe(r,t)?W.LOCKED:W.ADJUST,c=new Q(a);return q(e,n,r.heading,r.tilt,s,c),o.camera=await c.resolver.promise,o}function Ze(e,t,n,r,a){let o=0;n.hasZ?o=n.z:e.basemapTerrain&&(o=l(re(e.elevationProvider,n))),v(Ue,n.x,n.y,o),S(e.spatialReference,Ue,De,e.renderSpatialReference),f(Oe,De),u(Oe,Oe),M(Ce);const i=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]];for(let l=0;l<i.length;l++){const t=i[l];let n=r[t[2]];isFinite(n)||(n=o),v(Ue,r[t[0]],r[t[1]],n),B(Ue,e.spatialReference,Ue,e.renderSpatialReference),E(Ce,b(Ue,Ue,Oe))}const s=U(Ce),c=D(Ce),m=O(Ce),p=1/Math.tan(t.fovX/2),g=1/Math.tan(t.fovY/2),h=.5*Math.sqrt(s*s+m*m)*Math.max(g,p)+.5*c,y=.5*c*g+.5*Math.max(s,m);return Math.max(h,y)/a}async function Ae(e,t,n,r,a,o,i,s){s.targetGeometry=n.clone();const c=N(e),l=Ze(e,c,n,r,a);V(e,c,o);const m=xe(o,t)?W.LOCKED:W.ADJUST;s.scale=ee(e,l,s.targetGeometry.latitude);const f=new Q(i);return te(e,s.targetGeometry,s.scale,o,m,f),s.camera=await f.resolver.promise,s}function Fe(e,t){if(!t||!e.spatialReference)return null;const n={target:null};if("declaredClass"in t||Array.isArray(t))n.target=t;else{for(const e in t)n[e]=t[e];t.center&&!n.target&&(n.target=t.center)}return n}function Ee(e){return e&&i(e.camera)&&(e.rotation=me(e.camera.heading)),e}function Te(e,t){const n=ce;if(!t.length)return n;let r=Number.NEGATIVE_INFINITY;for(let a=0;a<t.length;a++){const e=t[a].screenSpaceBoundingRect;r=Math.max(r,Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2]),Math.abs(e[3]))}return n-r/Math.min(e.width,e.height)*2}const Ue=j(),De=g(),Oe=p(),Ce=k(),Pe=C(),Ie=j(),Je=j(),Ke=j(),Le={heading:0,tilt:0},Ne=new ae,Ve={point(e,t,n){n[0]=e.x,n[1]=e.y,e.hasZ&&(n[2]=e.z),t(n)},polygon(e,t,n){const r=e.hasZ;for(let a=0;a<e.rings.length;a++){const o=e.rings[a];for(let e=0;e<o.length;e++)n[0]=o[e][0],n[1]=o[e][1],r&&(n[2]=o[e][2]),t(n)}},polyline(e,t,n){const r=e.hasZ;for(let a=0;a<e.paths.length;a++){const o=e.paths[a];for(let e=0;e<o.length;e++)n[0]=o[e][0],n[1]=o[e][1],r&&(n[2]=o[e][2]),t(n)}},multipoint(e,t,n){const r=e.points,a=e.hasZ;for(let o=0;o<r.length;o++)n[0]=r[o][0],n[1]=r[o][1],a&&(n[2]=r[o][2]),t(n)},extent(e,t,n){e.hasZ?(t(v(n,e.xmin,e.ymin,e.zmin)),t(v(n,e.xmax,e.ymin,e.zmin)),t(v(n,e.xmin,e.ymax,e.zmin)),t(v(n,e.xmax,e.ymax,e.zmin)),t(v(n,e.xmin,e.ymin,e.zmax)),t(v(n,e.xmax,e.ymin,e.zmax)),t(v(n,e.xmin,e.ymax,e.zmax)),t(v(n,e.xmax,e.ymax,e.zmax))):(t(v(n,e.xmin,e.ymin,n[2])),t(v(n,e.xmax,e.ymin,n[2])),t(v(n,e.xmin,e.ymax,n[2])),t(v(n,e.xmax,e.ymax,n[2])))},mesh(e,t,n){const r=e.vertexAttributes&&e.vertexAttributes.position;if(r)for(let a=0;a<r.length;a+=3)t(v(n,r[a+0],r[a+1],r[a+2]))}};export{he as create,ge as fromCamera,me as headingToRotation,le as rotationToHeading,pe as toCamera};
5
+ import e from"../../../Camera.js";import"../../../geometry.js";import t from"../../../Graphic.js";import n from"../../../Viewpoint.js";import{result as r}from"../../../core/asyncUtils.js";import"../../../core/has.js";import{cyclicalDegrees as a}from"../../../core/Cyclical.js";import o from"../../../core/Error.js";import{isSome as i,isNone as s,unwrapOr as c,unwrap as l}from"../../../core/maybe.js";import{eachAlways as m}from"../../../core/promiseUtils.js";import{f,t as u}from"../../../chunks/mat3.js";import{c as p}from"../../../chunks/mat3f64.js";import{c as g}from"../../../chunks/mat4f64.js";import{g as h,a as y,i as d,c as x,b as w,s as v,t as b}from"../../../chunks/vec3.js";import{c as j}from"../../../chunks/vec3f64.js";import{projectVectorToPoint as R,projectPointToVector as G,projectBuffer as z,computeTranslationToOriginAndRotation as S,projectVectorToVector as B}from"../../../geometry/projection.js";import{create as k,empty as M,center as Z,toRect as A,isPoint as F,expandWithVec3 as T,expandWithAABB as E,width as U,height as D,depth as O}from"../../../geometry/support/aaBoundingBox.js";import{create as C,isPoint as P}from"../../../geometry/support/aaBoundingRect.js";import{intersectsPoint as I}from"../../../geometry/support/frustum.js";import{getResolutionInMetersForScale as J}from"../../../geometry/support/scaleUtils.js";import{project as K,canProject as L}from"../../../geometry/support/webMercatorUtils.js";import{cameraOnContentAlongViewDirection as N}from"../camera/intersectionUtils.js";import{internalToExternal as V,OrientationMode as W,scaleToDistance as Y,fromCenterDistance as $,fromExtent as q,externalToInternal as X,computeScale as _,AsyncContext as H,distanceToScale as Q,fromCenterScale as ee,directionToHeadingTilt as te,zoomToScale as ne}from"./cameraUtils.js";import{getElevationAtPoint as re}from"./ElevationProvider.js";import ae from"../../../geometry/Point.js";import oe from"../../../geometry/SpatialReference.js";import ie from"../../../geometry/Extent.js";import se from"../../../geometry/Geometry.js";const ce=.66;function le(e){return 360-a.normalize(e)}function me(e){return a.normalize(360-e)}function fe(e){return i(e)&&e.resolver&&e.resolver.reject(),null}function ue(e,t){return i(e)&&e.resolver&&e.resolver.resolve(t),t}function pe(e,t,n,r=null){if(!t)return fe(r);const a=e.spatialReference||oe.WGS84;if(i(t.camera)){const e=K(t.camera.position,a);if(s(e))return fe(r);const n=t.camera.clone();return n.position=e,ue(r,n)}if(s(t.targetGeometry))return fe(r);const o=t.get("targetGeometry.spatialReference");if(o&&!L(o,a))return fe(r);const c=V(e,e.state.camera);let l=W.ADJUST;if(null!=t.rotation&&(c.heading=le(t.rotation),l=W.LOCKED),null!=n&&(c.tilt=n),"point"===t.targetGeometry.type){const n=t.targetGeometry;let a;const o=t.targetGeometry.clone();return a=null!=t.scale?Y(e,t.scale,n.latitude):e.state.camera.distance,$(e,o,a,c,l,r)}const m=t.targetGeometry.extent;return q(e,m,c.heading,c.tilt,l,r)}function ge(e,t,r=null){return s(r)&&(r=new n),we(e,null,t.clone(),r)}async function he(t,r,a){const i=Fe(t,r);if(!i)throw new o("viewpointutils-create:no-target","Missing target for creating viewpoint");const s=new e({fov:t.camera.fov}),c=new n({camera:s});if(i.target instanceof n){return Te(await Re(t,i.target,i,a,c))}if(i.target instanceof e)return Te(Ge(t,i.target,c));const l=null!=i.scale||null!=i.zoom;if(i.target instanceof ie){const e=i.target.xmin===i.target.xmax||i.target.ymin===i.target.ymax;return Te(l||e?await Se(t,i,i.target.center,s,a,c):await Me(t,i,i.target,s,a,c))}const m={boundingBox:M(),hasZ:!1,screenSpaceObjects:[]},f=l?de(t,i):void 0;if(await je(t,i.target,f,m),isFinite(m.boundingBox[0])){let e;if(Z(m.boundingBox,Ue),Ne.x=Ue[0],Ne.y=Ue[1],Ne.z=Ue[2],Ne.spatialReference=t.spatialReference,isFinite(Ne.z)&&m.hasZ?e=F(m.boundingBox):(Ne.z=void 0,e=P(A(m.boundingBox,Pe))),l||e)return Te(await Se(t,i,Ne,s,a,c));const n=Ee(t,m.screenSpaceObjects);return Te(await Ae(t,i,Ne,m.boundingBox,n,s,a,c))}return i.position?Te(Be(t,i,s,c)):Te(await ke(t,i,s,a,c))}function ye(e,t){return null==t.scale&&null!=t.zoom?ne(e,t.zoom):t.scale}function de(e,t){return J(ye(e,t))}function xe(e,t){let n=!1;return null!=t.heading?(e.heading=t.heading,n=!0):null!=t.rotation&&(e.heading=le(t.rotation),n=!0),null!=t.tilt&&(e.tilt=t.tilt,n=!0),null!=t.fov&&(e.fov=t.fov),n}function we(e,t,n,r){const a=e.spatialReference||oe.WGS84;return t=i(t)?t:X(e,n),s(t)||(r.targetGeometry=R(t.center,e.renderSpatialReference,a),r.scale=_(e,t),r.rotation=me(n.heading),r.camera=n),r}function ve(e,t,n){const r=()=>new o("viewpointutils:invalid-geometry","The target is missing a valid geometry");if(!t)throw r();if(!L(t.spatialReference,e.spatialReference))throw new o("viewpointutils:incompatible-spatialreference",`Spatial reference (${t.spatialReference?t.spatialReference.wkid:"unknown"}) is incompatible with the view (${e.spatialReference.wkid})`,{geometry:t});const a=[];if(!t.hasZ&&e.basemapTerrain){let n;switch(t.type){case"point":n=t;break;case"multipoint":case"polyline":n=t.extent?.center;break;case"mesh":n=t.origin;break;case"extent":n=t.center;break;case"polygon":n=t.centroid}n&&i(e.basemapTerrain.spatialReference)&&L(n,e.basemapTerrain.spatialReference)?Ue[2]=c(re(e.elevationProvider,n),0):Ue[2]=0}(0,Ve[t.type])(t,(e=>{a.push(e[0],e[1],e[2])}),Ue);const s=a.length/3;if(0===s)throw r();const l=new Array(a.length);if(z(a,t.spatialReference,0,l,e.spatialReference,0,s)){t.hasZ&&(n.hasZ=!0);for(let e=0;e<l.length;e+=3)t.hasZ?(Ue[0]=l[e+0],Ue[1]=l[e+1],Ue[2]=l[e+2]):(Ue[0]=l[e+0],Ue[1]=l[e+1]),T(n.boundingBox,Ue)}}async function be(e,t,n,a){const o=await r(e.whenViewForGraphic(t));if(!1===o.ok||s(o.value)||!("whenGraphicBounds"in o.value))return void ve(e,t.geometry,a);const i=o.value,c=await r(i.whenGraphicBounds(t,{minDemResolution:n}));if(!1===c.ok)return void ve(e,t.geometry,a);const{screenSpaceObjects:l,boundingBox:m}=c.value;E(a.boundingBox,m),l&&l.forEach((e=>{a.screenSpaceObjects.push(e)})),isFinite(m[2])&&(a.hasZ=!0)}async function je(e,n,r,a){if(Array.isArray(n)&&2===n.length){const t=n[0],r=n[1];if("number"==typeof t&&"number"==typeof r)return Ne.x=t,Ne.y=r,Ne.z=void 0,Ne.spatialReference=e.spatialReference.isGeographic?e.spatialReference:oe.WGS84,void ve(e,Ne,a)}n&&"function"==typeof n.map?await m(n.map((t=>je(e,t,r,a)))):n instanceof se?ve(e,n,a):n instanceof t&&await be(e,n,r,a)}async function Re(e,t,n,r,a){if(i(t.camera))return Ge(e,t.camera,a);a.scale=t.scale,a.rotation=t.rotation,a.targetGeometry=i(t.targetGeometry)?t.targetGeometry.clone():null,a.camera=null,null!=n.heading?a.rotation=me(n.heading):null!=n.rotation&&(a.rotation=n.rotation);const o=ye(e,n);null!=o&&(a.scale=o);const s=new H(r);return pe(e,a,n.tilt,s),a.camera=await s.resolver.promise,a}function Ge(e,t,n){const r=e.spatialReference,a=K(t.position,r);return s(a)?null:((t=t.clone()).fov=e.camera.fov,t.position=a,we(e,null,t,n))}function ze(e,t,n,r,a,o){const i=e.renderSpatialReference;return G(n.position,Je,i),G(t,Ke,i),o.targetGeometry=new ae(t),a.position=new ae(n.position),w(Ie,Ke,Je),te(e,Je,Ie,r.up,a),o.scale=Q(e,d(Je,Ke),o.targetGeometry.latitude),o.rotation=me(a.heading),o.camera=a,o}async function Se(e,t,n,r,a,i){if(s(n))throw new o("createfromcenter","invalid point");i.targetGeometry=n.clone();const c=N(e);if(t.position)return ze(e,i.targetGeometry,t,c,r,i);if(t.zoomFactor){const r=c.distance/t.zoomFactor,a=h(Ue,c.viewForward,-r);c.eye=y(Ue,c.center,a),i.scale=Q(e,r,n.latitude)}V(e,c,r);const l=xe(r,t)?W.LOCKED:W.ADJUST;if(!t.zoomFactor){i.scale=ye(e,t),null==i.scale&&(G(n,Ue,e.renderSpatialReference),I(c.frustum,Ue)?i.scale=Q(e,d(c.eye,Ue),n.latitude):i.scale=_(e,c));const o=new H(a);ee(e,i.targetGeometry,i.scale,r,l,o),i.camera=await o.resolver.promise}return i}function Be(e,t,n,r){const a=N(e);return x(Ie,a.viewForward),te(e,a.eye,Ie,a.up,Le),n.position=new ae(t.position),n.heading=null!=t.heading?t.heading:Le.heading,n.tilt=null!=t.tilt?t.tilt:Le.tilt,we(e,null,n,r)}async function ke(e,t,n,r,a){const o=N(e);return Se(e,t,R(o.center,e.renderSpatialReference,e.spatialReference),n,r,a)}async function Me(e,t,n,r,a,o){o.targetGeometry=n.clone();const i=N(e);V(e,i,r);const s=xe(r,t)?W.LOCKED:W.ADJUST,c=new H(a);return q(e,n,r.heading,r.tilt,s,c),o.camera=await c.resolver.promise,o}function Ze(e,t,n,r,a){let o=0;n.hasZ?o=n.z:e.basemapTerrain&&(o=l(re(e.elevationProvider,n))),v(Ue,n.x,n.y,o),S(e.spatialReference,Ue,De,e.renderSpatialReference),f(Oe,De),u(Oe,Oe),M(Ce);const i=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]];for(let l=0;l<i.length;l++){const t=i[l];let n=r[t[2]];isFinite(n)||(n=o),v(Ue,r[t[0]],r[t[1]],n),B(Ue,e.spatialReference,Ue,e.renderSpatialReference),T(Ce,b(Ue,Ue,Oe))}const s=U(Ce),c=D(Ce),m=O(Ce),p=1/Math.tan(t.fovX/2),g=1/Math.tan(t.fovY/2),h=.5*Math.sqrt(s*s+m*m)*Math.max(g,p)+.5*c,y=.5*c*g+.5*Math.max(s,m);return Math.max(h,y)/a}async function Ae(e,t,n,r,a,o,i,s){s.targetGeometry=n.clone();const c=N(e),l=Ze(e,c,n,r,a);V(e,c,o);const m=xe(o,t)?W.LOCKED:W.ADJUST;s.scale=Q(e,l,s.targetGeometry.latitude);const f=new H(i);return ee(e,s.targetGeometry,s.scale,o,m,f),s.camera=await f.resolver.promise,s}function Fe(e,t){if(!t||!e.spatialReference)return null;const n={target:null};if("declaredClass"in t||Array.isArray(t))n.target=t;else{for(const e in t)n[e]=t[e];t.center&&!n.target&&(n.target=t.center)}return n}function Te(e){return e&&i(e.camera)&&(e.rotation=me(e.camera.heading)),e}function Ee(e,t){const n=ce;if(!t.length)return n;let r=Number.NEGATIVE_INFINITY;for(let a=0;a<t.length;a++){const e=t[a].screenSpaceBoundingRect;r=Math.max(r,Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2]),Math.abs(e[3]))}return n-r/Math.min(e.width,e.height)*2}const Ue=j(),De=g(),Oe=p(),Ce=k(),Pe=C(),Ie=j(),Je=j(),Ke=j(),Le={heading:0,tilt:0},Ne=new ae,Ve={point(e,t,n){n[0]=e.x,n[1]=e.y,e.hasZ&&(n[2]=e.z),t(n)},polygon(e,t,n){const r=e.hasZ;for(let a=0;a<e.rings.length;a++){const o=e.rings[a];for(let e=0;e<o.length;e++)n[0]=o[e][0],n[1]=o[e][1],r&&(n[2]=o[e][2]),t(n)}},polyline(e,t,n){const r=e.hasZ;for(let a=0;a<e.paths.length;a++){const o=e.paths[a];for(let e=0;e<o.length;e++)n[0]=o[e][0],n[1]=o[e][1],r&&(n[2]=o[e][2]),t(n)}},multipoint(e,t,n){const r=e.points,a=e.hasZ;for(let o=0;o<r.length;o++)n[0]=r[o][0],n[1]=r[o][1],a&&(n[2]=r[o][2]),t(n)},extent(e,t,n){e.hasZ?(t(v(n,e.xmin,e.ymin,e.zmin)),t(v(n,e.xmax,e.ymin,e.zmin)),t(v(n,e.xmin,e.ymax,e.zmin)),t(v(n,e.xmax,e.ymax,e.zmin)),t(v(n,e.xmin,e.ymin,e.zmax)),t(v(n,e.xmax,e.ymin,e.zmax)),t(v(n,e.xmin,e.ymax,e.zmax)),t(v(n,e.xmax,e.ymax,e.zmax))):(t(v(n,e.xmin,e.ymin,n[2])),t(v(n,e.xmax,e.ymin,n[2])),t(v(n,e.xmin,e.ymax,n[2])),t(v(n,e.xmax,e.ymax,n[2])))},mesh(e,t,n){const r=e.vertexAttributes&&e.vertexAttributes.position;if(r)for(let a=0;a<r.length;a+=3)t(v(n,r[a+0],r[a+1],r[a+2]))}};export{he as create,ge as fromCamera,me as headingToRotation,le as rotationToHeading,pe as toCamera};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{nextHighestPowerOfTwo as e}from"../../../core/mathUtils.js";import{create as t,offset as r,copy as s}from"../../../geometry/support/aaBoundingRect.js";import{RenderTargetType as i,OverlayIndex as a}from"./interfaces.js";import{ValidationState as o}from"../webgl-engine/lib/basicInterfaces.js";import{fromValues as n}from"../webgl-engine/lib/LocalOriginFactory.js";var h;!function(e){e[e.None=0]="None",e[e.ColorAndWater=1]="ColorAndWater",e[e.Highlight=2]="Highlight",e[e.Occluded=3]="Occluded"}(h||(h={}));class l{constructor(e,r){this.index=e,this.renderTargets=r,this._extent=t(),this.resolution=0,this.renderLocalOrigin=n(0,0,0,"O"),this.pixelRatio=1,this.mapUnitsPerPixel=1,this.canvasGeometries=new u,this.validTargets=null,this.hasDrapedFeatureSource=!1,this.hasDrapedRasterSource=!1,this.hasTargetWithoutRasterImage=!1,this.index=e,this.validTargets=new Array(r.renderTargets.length).fill(!1)}get extent(){return this._extent}getValidTexture(e){return this.validTargets[e]?this.renderTargets.getTarget(e).getTexture():null}get _needsColorWithoutRasterImage(){return this.hasDrapedRasterSource&&this.hasDrapedFeatureSource&&this.hasTargetWithoutRasterImage}getColorTexture(e){const t=e===h.ColorAndWater?this.renderTargets.getTarget(i.Color):e===h.Highlight?this.renderTargets.getTarget(i.Highlight):this.renderTargets.getTarget(i.Occluded);return t?t.getTexture():null}getColorTextureNoRasterImage(){return this._needsColorWithoutRasterImage?this.getValidTexture(i.ColorNoRasterImage):this.hasDrapedFeatureSource?this.getValidTexture(i.Color):null}getNormalTexture(e){const t=e===h.ColorAndWater?this.renderTargets.getTarget(i.Water):null;return t?t.getTexture():null}draw(e,t){const r=this.computeRenderTargetValidityBitfield();for(const s of this.renderTargets.renderTargets)s.type!==i.ColorNoRasterImage||this._needsColorWithoutRasterImage?this.validTargets[s.type]=e.drawTarget(this,s,t):this.validTargets[s.type]=!1;return r^this.computeRenderTargetValidityBitfield()?o.CHANGED:o.UNCHANGED}computeRenderTargetValidityBitfield(){const e=this.validTargets;return+e[i.Color]|+e[i.ColorNoRasterImage]<<1|+e[i.Highlight]<<2|+e[i.Water]<<3|+e[i.Occluded]<<4}setupGeometryViewsCyclical(e){this.setupGeometryViewsDirect();const t=.001*e.range;if(this._extent[0]-t<=e.min){const t=this.canvasGeometries.extents[this.canvasGeometries.numViews++];r(this._extent,e.range,0,t)}if(this._extent[2]+t>=e.max){const t=this.canvasGeometries.extents[this.canvasGeometries.numViews++];r(this._extent,-e.range,0,t)}}setupGeometryViewsDirect(){this.canvasGeometries.numViews=1,s(this.canvasGeometries.extents[0],this._extent)}hasSomeSizedView(){for(let e=0;e<this.canvasGeometries.numViews;e++){const t=this.canvasGeometries.extents[e];if(t[0]!==t[2]&&t[1]!==t[3])return!0}return!1}applyViewport(e){e.setViewport(this.index===a.INNER?0:this.resolution,0,this.resolution,this.resolution)}}function g(t,r,s){return Math.min(e(Math.max(t,r)+256),s)}class u{constructor(){this.extents=[t(),t(),t()],this.numViews=0}}export{l as Overlay,h as OverlaySource,g as computeOverlayResolution};
5
+ import{nextHighestPowerOfTwo as e}from"../../../core/mathUtils.js";import{create as t,offset as r,copy as s}from"../../../geometry/support/aaBoundingRect.js";import{RenderTargetType as i,OverlayIndex as a}from"./interfaces.js";import{ValidationState as o}from"../webgl-engine/lib/basicInterfaces.js";import{fromValues as n}from"../webgl-engine/lib/LocalOriginFactory.js";var h;!function(e){e[e.None=0]="None",e[e.ColorAndWater=1]="ColorAndWater",e[e.Highlight=2]="Highlight",e[e.Occluded=3]="Occluded",e[e.ObjectAndLayerIdColor=4]="ObjectAndLayerIdColor"}(h||(h={}));class l{constructor(e,r){this.index=e,this.renderTargets=r,this._extent=t(),this.resolution=0,this.renderLocalOrigin=n(0,0,0,"O"),this.pixelRatio=1,this.mapUnitsPerPixel=1,this.canvasGeometries=new d,this.validTargets=null,this.hasDrapedFeatureSource=!1,this.hasDrapedRasterSource=!1,this.hasTargetWithoutRasterImage=!1,this.index=e,this.validTargets=new Array(r.renderTargets.length).fill(!1)}get extent(){return this._extent}getValidTexture(e){return this.validTargets[e]?this.renderTargets.getTarget(e).getTexture():null}get _needsColorWithoutRasterImage(){return this.hasDrapedRasterSource&&this.hasDrapedFeatureSource&&this.hasTargetWithoutRasterImage}getColorTexture(e){const t=e===h.ColorAndWater?this.renderTargets.getTarget(i.Color):e===h.Highlight?this.renderTargets.getTarget(i.Highlight):e===h.ObjectAndLayerIdColor?this.renderTargets.getTarget(i.ObjectAndLayerIdColor):this.renderTargets.getTarget(i.Occluded);return t?t.getTexture():null}getColorTextureNoRasterImage(){return this._needsColorWithoutRasterImage?this.getValidTexture(i.ColorNoRasterImage):this.hasDrapedFeatureSource?this.getValidTexture(i.Color):null}getNormalTexture(e){const t=e===h.ColorAndWater?this.renderTargets.getTarget(i.Water):null;return t?t.getTexture():null}draw(e,t){const r=this.computeRenderTargetValidityBitfield();for(const s of this.renderTargets.renderTargets)s.type!==i.ColorNoRasterImage||this._needsColorWithoutRasterImage?this.validTargets[s.type]=e.drawTarget(this,s,t):this.validTargets[s.type]=!1;return r^this.computeRenderTargetValidityBitfield()?o.CHANGED:o.UNCHANGED}computeRenderTargetValidityBitfield(){const e=this.validTargets;return+e[i.Color]|+e[i.ColorNoRasterImage]<<1|+e[i.Highlight]<<2|+e[i.Water]<<3|+e[i.Occluded]<<4}setupGeometryViewsCyclical(e){this.setupGeometryViewsDirect();const t=.001*e.range;if(this._extent[0]-t<=e.min){const t=this.canvasGeometries.extents[this.canvasGeometries.numViews++];r(this._extent,e.range,0,t)}if(this._extent[2]+t>=e.max){const t=this.canvasGeometries.extents[this.canvasGeometries.numViews++];r(this._extent,-e.range,0,t)}}setupGeometryViewsDirect(){this.canvasGeometries.numViews=1,s(this.canvasGeometries.extents[0],this._extent)}hasSomeSizedView(){for(let e=0;e<this.canvasGeometries.numViews;e++){const t=this.canvasGeometries.extents[e];if(t[0]!==t[2]&&t[1]!==t[3])return!0}return!1}applyViewport(e){e.setViewport(this.index===a.INNER?0:this.resolution,0,this.resolution,this.resolution)}}function g(t,r,s){return Math.min(e(Math.max(t,r)+256),s)}class d{constructor(){this.extents=[t(),t(),t()],this.numViews=0}}export{l as Overlay,h as OverlaySource,g as computeOverlayResolution};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{RenderTargetType as e}from"./interfaces.js";import{OverlayFramebufferObject as r}from"./OverlayFramebufferObject.js";import{ShaderOutput as s}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";class t{constructor(e,s,t,o=!0){this.output=s,this.type=t,this.valid=!1,this.lastUsed=1/0,this.fbo=new r(e,o)}}class o{constructor(r){this.renderTargets=[new t(r,s.Color,e.Color),new t(r,s.Color,e.ColorNoRasterImage),new t(r,s.Highlight,e.Highlight,!1),new t(r,s.Normal,e.Water),new t(r,s.Color,e.Occluded)]}getTarget(e){return this.renderTargets[e].fbo}dispose(){for(const e of this.renderTargets)e.fbo.dispose()}disposeRenderTargetMemory(){for(const e of this.renderTargets)e.fbo.disposeRenderTargetMemory()}validateUsageForTarget(e,r,s){if(e)r.lastUsed=s;else if(s-r.lastUsed>a)r.fbo.disposeRenderTargetMemory(),r.lastUsed=1/0;else if(r.lastUsed<1/0)return!0;return!1}get gpuMemoryUsage(){return this.renderTargets.reduce(((e,r)=>e+r.fbo.gpuMemoryUsage),0)}}const a=1e3;export{o as OverlayRenderTarget,t as RenderTargetDescriptor};
5
+ import has from"../../../core/has.js";import{RenderTargetType as e}from"./interfaces.js";import{OverlayFramebufferObject as r}from"./OverlayFramebufferObject.js";import{ShaderOutput as t}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";class s{constructor(e,t,s,o=!0){this.output=t,this.type=s,this.valid=!1,this.lastUsed=1/0,this.fbo=new r(e,o)}}class o{constructor(r){this.renderTargets=[new s(r,t.Color,e.Color),new s(r,t.Color,e.ColorNoRasterImage),new s(r,t.Highlight,e.Highlight,!1),new s(r,t.Normal,e.Water),new s(r,t.Color,e.Occluded)],has("enable-feature:objectAndLayerId-rendering")&&this.renderTargets.push(new s(r,t.ObjectAndLayerIdColor,e.ObjectAndLayerIdColor))}getTarget(e){return this.renderTargets[e].fbo}dispose(){for(const e of this.renderTargets)e.fbo.dispose()}disposeRenderTargetMemory(){for(const e of this.renderTargets)e.fbo.disposeRenderTargetMemory()}validateUsageForTarget(e,r,t){if(e)r.lastUsed=t;else if(t-r.lastUsed>a)r.fbo.disposeRenderTargetMemory(),r.lastUsed=1/0;else if(r.lastUsed<1/0)return!0;return!1}get gpuMemoryUsage(){return this.renderTargets.reduce(((e,r)=>e+r.fbo.gpuMemoryUsage),0)}}const a=1e3;export{o as OverlayRenderTarget,s as RenderTargetDescriptor};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import r from"../../../core/Accessor.js";import t from"../../../core/Evented.js";import s from"../../../core/Handles.js";import{someMap as i}from"../../../core/MapUtils.js";import{releaseMaybe as o,disposeMaybe as a,isSome as n,isNone as h,unwrapOr as d}from"../../../core/maybe.js";import l from"../../../core/PooledArray.js";import{watch as c,syncAndInitial as p,on as u}from"../../../core/reactiveUtils.js";import{someSet as m}from"../../../core/SetUtils.js";import{property as _}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as g}from"../../../core/accessorSupport/decorators/subclass.js";import{x as y,f as R}from"../../../chunks/mat4.js";import{s as f}from"../../../chunks/vec3.js";import{f as T}from"../../../chunks/vec3f64.js";import{ViewingMode as b}from"../../ViewingMode.js";import{DrapeTargetType as w,DrapeSourceType as v}from"../layers/interfaces.js";import x from"../support/debugFlags.js";import{OverlayIndex as O,RenderTargetType as S}from"./interfaces.js";import{Overlay as D}from"./Overlay.js";import{OverlayFramebufferObject as j}from"./OverlayFramebufferObject.js";import{OverlayRenderTarget as P}from"./OverlayRenderTarget.js";import{ShaderOutput as E}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{T as A}from"../../../chunks/TextureOnly.glsl.js";import{ShaderTechniqueRepository as C}from"../webgl-engine/core/shaderTechnique/ShaderTechniqueRepository.js";import{autoDispose as F,AutoDisposableMixin as q}from"../webgl-engine/lib/AutoDisposable.js";import{UpdatePolicy as M}from"../webgl-engine/lib/basicInterfaces.js";import{Camera as W}from"../webgl-engine/lib/Camera.js";import{GLMaterialRepository as U}from"../webgl-engine/lib/GLMaterialRepository.js";import{createEmptyDepthTexture as V,createQuadVAO as I}from"../webgl-engine/lib/glUtil3D.js";import{GridLocalOriginFactory as B}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderOccludedFlag as H}from"../webgl-engine/lib/Material.js";import{OverlayRenderContext as N}from"../webgl-engine/lib/RenderContext.js";import{RenderSlot as k}from"../webgl-engine/lib/RenderSlot.js";import{ShadowMap as L}from"../webgl-engine/lib/ShadowMap.js";import{SortedRenderGeometryRenderer as G}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{SSAOHelper as z}from"../webgl-engine/lib/SSAOHelper.js";import{TextureTechnique as Y}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as X}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{TransparencyPassType as Q}from"../webgl-engine/lib/TransparencyPassType.js";import{AmbientLight as J}from"../webgl-engine/lighting/Lightsources.js";import{StippleTextureRepository as K}from"../webgl-engine/materials/StippleTextureRepository.js";import{AlphaMode as Z,CompositingFunction as $}from"../webgl-engine/shaders/CompositingTechniqueConfiguration.js";import{ImmediateTask as ee,TaskPriority as re,noBudget as te}from"../../support/Scheduler.js";import{ClearBufferBit as se,PrimitiveType as ie,TextureType as oe,PixelFormat as ae,PixelType as ne,TextureSamplingMode as he}from"../../webgl/enums.js";import{Texture as de}from"../../webgl/Texture.js";import{vertexCount as le}from"../../webgl/Util.js";let ce=class extends(q(r)){constructor(e){super(e),this._overlays=null,this._overlayRenderTarget=null,this._hasHighlights=!1,this._rendersOccluded=!1,this._hasWater=!1,this._handles=new s,this._frameTask=ee,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new l,this._passParameters=new A,this._rctx=null,this._materialRepository=null,this._screenToWorldRatio=1,this._localOriginFactory=null,this.worldToPCSRatio=1,this.events=new t,this.longitudeCyclical=null}get _bindParameters(){return this._renderContext.bindParameters}get rctx(){return this._rctx}get materialRepository(){return this._materialRepository}get screenToWorldRatio(){return this._screenToWorldRatio}get localOriginFactory(){return this._localOriginFactory}initialize(){const e=this.view._stage.renderView;this._rctx=e.renderingContext;const r=e.waterTextureRepository;this._stippleTextureRepository=new K(e.renderingContext),this._shaderTechniqueRepository=new C({rctx:this._rctx,viewingMode:b.Local,stippleTextureRepository:this._stippleTextureRepository,waterTextureRepository:r}),this._renderContext=new N(this._rctx,new L(this._rctx,this.view.state.viewingMode),new z(this._shaderTechniqueRepository,this._rctx,(()=>{}))),this._handles.add([c((()=>r.updating),(()=>this.events.emit("content-changed")),p),c((()=>this.spatialReference),(e=>this._localOriginFactory=new B(e)),p),u((()=>this.view.allLayerViews),"after-changes",(()=>this._sortedDrapeSourceRenderersDirty=!0))]),this._materialRepository=new U(e.textureRepository,this._shaderTechniqueRepository,(e=>{(e.renderOccluded&ye)>0!==this._rendersOccluded&&this._updateRendersOccluded(),this.events.emit("content-changed"),this.notifyChange("updating")}),(()=>this.events.emit("content-changed"))),this._bindParameters.slot=k.DRAPED_MATERIAL,this._bindParameters.highlightDepthTexture=V(this._rctx),this._bindParameters.camera=_e,this._bindParameters.transparencyPassType=Q.NONE,this._bindParameters.lighting.groundLightingFactor=1,this._bindParameters.lighting.globalFactor=0,this._bindParameters.lighting.set([new J(T(1,1,1))]),this._frameTask=this.view.resourceController.scheduler.registerTask(re.STAGE,this),this._handles.add(this._frameTask)}dispose(){this._handles.destroy(),this._renderers.forEach((e=>e.destroy())),this._renderers.clear(),this._debugTextureTechnique=o(this._debugTextureTechnique),this._passParameters.texture=a(this._passParameters.texture),this._bindParameters.highlightDepthTexture=a(this._bindParameters.highlightDepthTexture),this._shaderTechniqueRepository=a(this._shaderTechniqueRepository),this._temporaryFBO=a(this._temporaryFBO),this._quadVAO=a(this._quadVAO),this.disposeOverlays()}get updating(){return this._sortedDrapeSourceRenderersDirty||this._frameTask.updating||i(this._renderers,(e=>e.updating))}get hasOverlays(){return n(this._overlays)&&n(this._overlayRenderTarget)}get gpuMemoryUsage(){return n(this._overlayRenderTarget)?this._overlayRenderTarget.gpuMemoryUsage:0}createGeometryDrapeSourceRenderer(e){return this.createDrapeSourceRenderer(e,G)}createDrapeSourceRenderer(e,r,t){const s=this._renderers.get(e);n(s)&&s.destroy();const i=new r({...t,rendererContext:this,drapeSource:e});return this._renderers.set(e,i),this._sortedDrapeSourceRenderersDirty=!0,"fullOpacity"in e&&this._handles.add(c((()=>e.fullOpacity),(()=>this.events.emit("content-changed"))),e),i}removeDrapeSourceRenderer(e){if(h(e))return;const r=this._renderers.get(e);h(r)||(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this._handles.remove(e),r.destroy())}collectUnusedRenderTargetMemory(e){let r=!1;if(n(this._overlayRenderTarget))for(const t of this._overlayRenderTarget.renderTargets){const s=this.overlays[0].validTargets[t.type]||!this.overlays[1].validTargets[t.type];r=this._overlayRenderTarget.validateUsageForTarget(s,t,e)||r}return r}get overlays(){return d(this._overlays,[])}ensureDrapeTargets(e){n(this._overlays)&&this._overlays.forEach((r=>{r.hasTargetWithoutRasterImage=m(e,(e=>e.drapeTargetType===w.WithoutRasterImage))}))}ensureDrapeSources(e){n(this._overlays)&&this._overlays.forEach((r=>{r.hasDrapedFeatureSource=m(e,(e=>e.drapeSourceType===v.Features)),r.hasDrapedRasterSource=m(e,(e=>e.drapeSourceType===v.RasterImage))}))}ensureOverlays(e,r){h(this._overlays)&&(this._overlayRenderTarget=new P(this._rctx),this._overlays=[new D(O.INNER,this._overlayRenderTarget),new D(O.OUTER,this._overlayRenderTarget)]),this.ensureDrapeTargets(e),this.ensureDrapeSources(r)}disposeOverlays(){this._overlays=null,this._overlayRenderTarget=a(this._overlayRenderTarget),this.events.emit("textures-disposed")}get running(){return this.updating}runTask(e,r=(()=>!0)){this._frameTask.processQueue(e),e.done||this._processDrapeSources(e,r)}_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._updateSortedDrapeSourceRenderers(),t&&(n(this._overlays)&&0===this._renderers.size&&this.disposeOverlays(),this.notifyChange("updating"),this.events.emit("content-changed"),this._updateHasHighlights(),this._updateRendersOccluded(),this._updateHasWater())}processSyncDrapeSources(){this._processDrapeSources(te,(e=>e.updatePolicy===M.SYNC))}isEmpty(){if(x.OVERLAY_DRAW_DEBUG_TEXTURE)return!1;for(const e of this._renderers.values())if(!e.isEmpty)return!1;return!0}get hasHighlights(){return this._hasHighlights}get hasWater(){return this._hasWater}get rendersOccluded(){return this._rendersOccluded}updateAnimation(e){let r=!1;return this._renderers.forEach((t=>r=t.updateAnimation(e)||r)),r}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}drawTarget(e,r,t){const s=e.canvasGeometries;if(0===s.numViews)return!1;this._screenToWorldRatio=t*e.mapUnitsPerPixel;const i=r.output;if(this.isEmpty()||i===E.Highlight&&!this.hasHighlights||i===E.Normal&&!this.hasWater||!e.hasSomeSizedView())return!1;const o=r.fbo;if(!o.isValid())return!1;const a=2*e.resolution,h=e.resolution;o.resize(a,h);const d=this._rctx;_e.pixelRatio=e.pixelRatio*t,this._renderContext.output=i,this._bindParameters.screenToWorldRatio=this._screenToWorldRatio,this._bindParameters.screenToPCSRatio=this._screenToWorldRatio*this.worldToPCSRatio,this._bindParameters.slot=i===E.Normal?k.DRAPED_WATER:k.DRAPED_MATERIAL,e.applyViewport(this._rctx),o.bind(d),e.index===O.INNER&&(d.setClearColor(0,0,0,0),d.clearSafe(se.COLOR_BUFFER_BIT));const l=r.type===S.ColorNoRasterImage?pe.ExcludeRasterImage:r.type===S.Occluded?pe.OccludedOnly:pe.Normal;if(l===pe.OccludedOnly&&(this._renderContext.renderOccludedMask=ye),x.OVERLAY_DRAW_DEBUG_TEXTURE&&l!==pe.OccludedOnly)for(let n=0;n<s.numViews;n++)this._setViewParameters(s.extents[n],e,_e),this._drawDebugTexture(e.resolution,me[e.index]);return this._renderers.size>0&&this._sortedRenderers.forAll((({drapeSource:r,renderer:t})=>{if(l===pe.ExcludeRasterImage&&r.drapeSourceType===v.RasterImage)return;const{fullOpacity:c}=r,p=n(c)&&c<1&&i===E.Color;p&&(this.bindTemporaryFramebuffer(this._rctx,a,h),d.clearSafe(se.COLOR_BUFFER_BIT));for(let i=0;i<s.numViews;i++)this._setViewParameters(s.extents[i],e,_e),t.render(this._renderContext,this._bindParameters);p&&n(this._temporaryFBO)&&(o.bind(d),this.view._stage.renderView.compositingHelper.composite(this._renderContext.bindParameters,this._temporaryFBO.getTexture(),Z.PremultipliedAlpha,c,$.OverlayWithTransparency,e.index))})),d.bindFramebuffer(null),o.generateMipMap(),this._renderContext.resetRenderOccludedMask(),!0}bindTemporaryFramebuffer(e,r,t){h(this._temporaryFBO)&&(this._temporaryFBO=new j(e,!1)),this._temporaryFBO.resize(r,t),this._temporaryFBO.bind(e)}async reloadShaders(){await this._shaderTechniqueRepository.reloadAll()}notifyContentChanged(){this.events.emit("content-changed")}intersect(e,r,t,s){let i=0;for(const o of this._renderers.values())i=o.intersect?.(e,r,t,s,i)??i}_updateSortedDrapeSourceRenderers(){if(!this._sortedDrapeSourceRenderersDirty)return;if(this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers.clear(),0===this._renderers.size)return;const e=this.view.map.allLayers;this._renderers.forEach(((r,t)=>{const s=e.indexOf(t.layer);this._sortedRenderers.push(new ue(t,r,s<0?1/0:s))})),this._sortedRenderers.sort(((e,r)=>e.index-r.index))}_setViewParameters(e,r,t){t.viewport[0]=t.viewport[1]=0,t.viewport[2]=t.viewport[3]=r.resolution,y(t.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],t.near,t.far),R(t.viewMatrix,[-e[0],-e[1],0]),this._bindParameters.camera=t}_updateHasWater(){const e=i(this._renderers,(e=>e.hasWater));e!==this._hasWater&&(this._hasWater=e,this.events.emit("has-water",e))}_updateHasHighlights(){const e=i(this._renderers,(e=>e.hasHighlights));e!==this._hasHighlights&&(this._hasHighlights=e,this.events.emit("has-highlights",e))}_updateRendersOccluded(){const e=i(this._renderers,(e=>e.rendersOccluded));e!==this._rendersOccluded&&(this._rendersOccluded=e,this.events.emit("renders-occluded",e))}_drawDebugTexture(e,r){this._ensureDebugPatternResources(e,e,r);const t=this._rctx;t.bindTechnique(this._debugTextureTechnique,this._passParameters,null),t.bindVAO(this._quadVAO),t.drawArrays(ie.TRIANGLE_STRIP,0,le(this._quadVAO,"geometry"))}_ensureDebugPatternResources(e,r,t){if(f(this._passParameters.color,t[0],t[1],t[2]),this._passParameters.texture)return;const s=new Uint8Array(e*r*4);let i=0;for(let a=0;a<r;a++)for(let t=0;t<e;t++){const o=Math.floor(t/10),n=Math.floor(a/10);o<2||n<2||10*o>e-20||10*n>r-20?(s[i++]=255,s[i++]=255,s[i++]=255,s[i++]=255):(s[i++]=255,s[i++]=255,s[i++]=255,s[i++]=1&o&&1&n?1&t^1&a?0:255:1&o^1&n?0:128)}this._passParameters.texture=new de(this._rctx,{target:oe.TEXTURE_2D,pixelFormat:ae.RGBA,dataType:ne.UNSIGNED_BYTE,samplingMode:he.NEAREST,width:e,height:r},s);const o=new X;o.hasAlpha=!0,this._debugTextureTechnique=this._shaderTechniqueRepository.acquire(Y,o),this._quadVAO=I(this._rctx)}get test(){return{drapeSourceRenderers:this._renderers,getDrapeSourceRenderer:e=>this._renderers.get(e)}}};var pe;e([_()],ce.prototype,"_frameTask",void 0),e([_()],ce.prototype,"_sortedDrapeSourceRenderersDirty",void 0),e([F()],ce.prototype,"_shaderTechniqueRepository",void 0),e([F()],ce.prototype,"_stippleTextureRepository",void 0),e([_({constructOnly:!0})],ce.prototype,"view",void 0),e([_()],ce.prototype,"worldToPCSRatio",void 0),e([_()],ce.prototype,"spatialReference",void 0),e([_({type:Boolean,readOnly:!0})],ce.prototype,"updating",null),ce=e([g("esri.views.3d.terrain.OverlayRenderer")],ce),function(e){e[e.Normal=0]="Normal",e[e.OccludedOnly=1]="OccludedOnly",e[e.ExcludeRasterImage=2]="ExcludeRasterImage"}(pe||(pe={}));class ue{constructor(e,r,t){this.drapeSource=e,this.renderer=r,this.index=t}}const me=[[1,.5,.5],[.5,.5,1]],_e=new W;_e.near=1,_e.far=1e4,_e.relativeElevation=null;const ge=-2,ye=H.OccludeAndTransparent;export{ge as DRAPED_Z,pe as DrawPassOption,ce as OverlayRenderer,ye as overlayRenderOccludedFlag};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import r from"../../../core/Accessor.js";import t from"../../../core/Evented.js";import s from"../../../core/Handles.js";import{someMap as i}from"../../../core/MapUtils.js";import{releaseMaybe as o,disposeMaybe as a,isSome as n,isNone as h,unwrapOr as d}from"../../../core/maybe.js";import l from"../../../core/PooledArray.js";import{watch as c,syncAndInitial as p,on as u}from"../../../core/reactiveUtils.js";import{someSet as m}from"../../../core/SetUtils.js";import{property as _}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as g}from"../../../core/accessorSupport/decorators/subclass.js";import{x as y,f as R}from"../../../chunks/mat4.js";import{s as f}from"../../../chunks/vec3.js";import{f as T}from"../../../chunks/vec3f64.js";import{ViewingMode as b}from"../../ViewingMode.js";import{DrapeTargetType as w,DrapeSourceType as v}from"../layers/interfaces.js";import x from"../support/debugFlags.js";import{OverlayIndex as O,RenderTargetType as S}from"./interfaces.js";import{Overlay as D}from"./Overlay.js";import{OverlayFramebufferObject as j}from"./OverlayFramebufferObject.js";import{OverlayRenderTarget as P}from"./OverlayRenderTarget.js";import{ShaderOutput as E}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{T as A}from"../../../chunks/TextureOnly.glsl.js";import{ShaderTechniqueRepository as C}from"../webgl-engine/core/shaderTechnique/ShaderTechniqueRepository.js";import{AutoDisposableMixin as F,autoDispose as q}from"../webgl-engine/lib/AutoDisposable.js";import{UpdatePolicy as M}from"../webgl-engine/lib/basicInterfaces.js";import{Camera as W}from"../webgl-engine/lib/Camera.js";import{GLMaterialRepository as U}from"../webgl-engine/lib/GLMaterialRepository.js";import{createEmptyDepthTexture as V,createQuadVAO as I}from"../webgl-engine/lib/glUtil3D.js";import{GridLocalOriginFactory as B}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderOccludedFlag as H}from"../webgl-engine/lib/Material.js";import{OverlayRenderContext as N}from"../webgl-engine/lib/RenderContext.js";import{RenderSlot as k}from"../webgl-engine/lib/RenderSlot.js";import{ShadowMap as L}from"../webgl-engine/lib/ShadowMap.js";import{SortedRenderGeometryRenderer as G}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{SSAOHelper as z}from"../webgl-engine/lib/SSAOHelper.js";import{TextureTechnique as Y}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as X}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{TransparencyPassType as Q}from"../webgl-engine/lib/TransparencyPassType.js";import{AmbientLight as J}from"../webgl-engine/lighting/Lightsources.js";import{StippleTextureRepository as K}from"../webgl-engine/materials/StippleTextureRepository.js";import{AlphaMode as Z,CompositingFunction as $}from"../webgl-engine/shaders/CompositingTechniqueConfiguration.js";import{ImmediateTask as ee,TaskPriority as re,noBudget as te}from"../../support/Scheduler.js";import{ClearBufferBit as se,PrimitiveType as ie,TextureType as oe,PixelFormat as ae,PixelType as ne,TextureSamplingMode as he}from"../../webgl/enums.js";import{Texture as de}from"../../webgl/Texture.js";import{vertexCount as le}from"../../webgl/Util.js";let ce=class extends(F(r)){constructor(e){super(e),this._overlays=null,this._overlayRenderTarget=null,this._hasHighlights=!1,this._rendersOccluded=!1,this._hasWater=!1,this._handles=new s,this._frameTask=ee,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new l,this._passParameters=new A,this._rctx=null,this._materialRepository=null,this._screenToWorldRatio=1,this._localOriginFactory=null,this.worldToPCSRatio=1,this.events=new t,this.longitudeCyclical=null}get _bindParameters(){return this._renderContext.bindParameters}get rctx(){return this._rctx}get materialRepository(){return this._materialRepository}get screenToWorldRatio(){return this._screenToWorldRatio}get localOriginFactory(){return this._localOriginFactory}initialize(){const e=this.view._stage.renderView;this._rctx=e.renderingContext;const r=e.waterTextureRepository;this._stippleTextureRepository=new K(e.renderingContext),this._shaderTechniqueRepository=new C({rctx:this._rctx,viewingMode:b.Local,stippleTextureRepository:this._stippleTextureRepository,waterTextureRepository:r}),this._renderContext=new N(this._rctx,new L(this._rctx,this.view.state.viewingMode),new z(this._shaderTechniqueRepository,this._rctx,(()=>{}))),this._handles.add([c((()=>r.updating),(()=>this.events.emit("content-changed")),p),c((()=>this.spatialReference),(e=>this._localOriginFactory=new B(e)),p),u((()=>this.view.allLayerViews),"after-changes",(()=>this._sortedDrapeSourceRenderersDirty=!0))]),this._materialRepository=new U(e.textureRepository,this._shaderTechniqueRepository,(e=>{(e.renderOccluded&ye)>0!==this._rendersOccluded&&this._updateRendersOccluded(),this.events.emit("content-changed"),this.notifyChange("updating")}),(()=>this.events.emit("content-changed"))),this._bindParameters.slot=k.DRAPED_MATERIAL,this._bindParameters.highlightDepthTexture=V(this._rctx),this._bindParameters.camera=_e,this._bindParameters.transparencyPassType=Q.NONE,this._bindParameters.lighting.groundLightingFactor=1,this._bindParameters.lighting.globalFactor=0,this._bindParameters.lighting.set([new J(T(1,1,1))]),this._frameTask=this.view.resourceController.scheduler.registerTask(re.STAGE,this),this._handles.add(this._frameTask)}dispose(){this._handles.destroy(),this._renderers.forEach((e=>e.destroy())),this._renderers.clear(),this._debugTextureTechnique=o(this._debugTextureTechnique),this._passParameters.texture=a(this._passParameters.texture),this._bindParameters.highlightDepthTexture=a(this._bindParameters.highlightDepthTexture),this._shaderTechniqueRepository=a(this._shaderTechniqueRepository),this._temporaryFBO=a(this._temporaryFBO),this._quadVAO=a(this._quadVAO),this.disposeOverlays()}get updating(){return this._sortedDrapeSourceRenderersDirty||this._frameTask.updating||i(this._renderers,(e=>e.updating))}get hasOverlays(){return n(this._overlays)&&n(this._overlayRenderTarget)}get gpuMemoryUsage(){return n(this._overlayRenderTarget)?this._overlayRenderTarget.gpuMemoryUsage:0}createGeometryDrapeSourceRenderer(e){return this.createDrapeSourceRenderer(e,G)}createDrapeSourceRenderer(e,r,t){const s=this._renderers.get(e);n(s)&&s.destroy();const i=new r({...t,rendererContext:this,drapeSource:e});return this._renderers.set(e,i),this._sortedDrapeSourceRenderersDirty=!0,"fullOpacity"in e&&this._handles.add(c((()=>e.fullOpacity),(()=>this.events.emit("content-changed"))),e),i}removeDrapeSourceRenderer(e){if(h(e))return;const r=this._renderers.get(e);h(r)||(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this._handles.remove(e),r.destroy())}collectUnusedRenderTargetMemory(e){let r=!1;if(n(this._overlayRenderTarget))for(const t of this._overlayRenderTarget.renderTargets){const s=this.overlays[0].validTargets[t.type]||!this.overlays[1].validTargets[t.type];r=this._overlayRenderTarget.validateUsageForTarget(s,t,e)||r}return r}get overlays(){return d(this._overlays,[])}ensureDrapeTargets(e){n(this._overlays)&&this._overlays.forEach((r=>{r.hasTargetWithoutRasterImage=m(e,(e=>e.drapeTargetType===w.WithoutRasterImage))}))}ensureDrapeSources(e){n(this._overlays)&&this._overlays.forEach((r=>{r.hasDrapedFeatureSource=m(e,(e=>e.drapeSourceType===v.Features)),r.hasDrapedRasterSource=m(e,(e=>e.drapeSourceType===v.RasterImage))}))}ensureOverlays(e,r){h(this._overlays)&&(this._overlayRenderTarget=new P(this._rctx),this._overlays=[new D(O.INNER,this._overlayRenderTarget),new D(O.OUTER,this._overlayRenderTarget)]),this.ensureDrapeTargets(e),this.ensureDrapeSources(r)}disposeOverlays(){this._overlays=null,this._overlayRenderTarget=a(this._overlayRenderTarget),this.events.emit("textures-disposed")}get running(){return this.updating}runTask(e,r=(()=>!0)){this._frameTask.processQueue(e),e.done||this._processDrapeSources(e,r)}_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._updateSortedDrapeSourceRenderers(),t&&(n(this._overlays)&&0===this._renderers.size&&this.disposeOverlays(),this.notifyChange("updating"),this.events.emit("content-changed"),this._updateHasHighlights(),this._updateRendersOccluded(),this._updateHasWater())}processSyncDrapeSources(){this._processDrapeSources(te,(e=>e.updatePolicy===M.SYNC))}isEmpty(){if(x.OVERLAY_DRAW_DEBUG_TEXTURE)return!1;for(const e of this._renderers.values())if(!e.isEmpty)return!1;return!0}get hasHighlights(){return this._hasHighlights}get hasWater(){return this._hasWater}get rendersOccluded(){return this._rendersOccluded}updateAnimation(e){let r=!1;return this._renderers.forEach((t=>r=t.updateAnimation(e)||r)),r}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}drawTarget(e,r,t){const s=e.canvasGeometries;if(0===s.numViews)return!1;this._screenToWorldRatio=t*e.mapUnitsPerPixel;const i=r.output;if(this.isEmpty()||i===E.Highlight&&!this.hasHighlights||i===E.Normal&&!this.hasWater||!e.hasSomeSizedView())return!1;const o=r.fbo;if(!o.isValid())return!1;const a=2*e.resolution,h=e.resolution;o.resize(a,h);const d=this._rctx;_e.pixelRatio=e.pixelRatio*t,this._renderContext.output=i,this._bindParameters.screenToWorldRatio=this._screenToWorldRatio,this._bindParameters.screenToPCSRatio=this._screenToWorldRatio*this.worldToPCSRatio,this._bindParameters.slot=i===E.Normal?k.DRAPED_WATER:k.DRAPED_MATERIAL,e.applyViewport(this._rctx),o.bind(d),e.index===O.INNER&&(d.setClearColor(0,0,0,0),d.clearSafe(se.COLOR_BUFFER_BIT));const l=r.type===S.ColorNoRasterImage?pe.ExcludeRasterImage:r.type===S.Occluded?pe.OccludedOnly:pe.Normal;if(l===pe.OccludedOnly&&(this._renderContext.renderOccludedMask=ye),x.OVERLAY_DRAW_DEBUG_TEXTURE&&l!==pe.OccludedOnly)for(let n=0;n<s.numViews;n++)this._setViewParameters(s.extents[n],e,_e),this._drawDebugTexture(e.resolution,me[e.index]);return this._renderers.size>0&&this._sortedRenderers.forAll((({drapeSource:r,renderer:t})=>{if(l===pe.ExcludeRasterImage&&r.drapeSourceType===v.RasterImage)return;const{fullOpacity:c}=r,p=n(c)&&c<1&&i===E.Color;p&&(this.bindTemporaryFramebuffer(this._rctx,a,h),d.clearSafe(se.COLOR_BUFFER_BIT));for(let i=0;i<s.numViews;i++)this._setViewParameters(s.extents[i],e,_e),t.render(this._renderContext,this._bindParameters);p&&n(this._temporaryFBO)&&(o.bind(d),this.view._stage.renderView.compositingHelper.composite(this._renderContext.bindParameters,this._temporaryFBO.getTexture(),Z.PremultipliedAlpha,c,$.OverlayWithTransparency,e.index))})),d.bindFramebuffer(null),o.generateMipMap(),this._renderContext.resetRenderOccludedMask(),!0}bindTemporaryFramebuffer(e,r,t){h(this._temporaryFBO)&&(this._temporaryFBO=new j(e,!1)),this._temporaryFBO.resize(r,t),this._temporaryFBO.bind(e)}async reloadShaders(){await this._shaderTechniqueRepository.reloadAll()}notifyContentChanged(){this.events.emit("content-changed")}intersect(e,r,t,s){let i=0;for(const o of this._renderers.values())i=o.intersect?.(e,r,t,s,i)??i}_updateSortedDrapeSourceRenderers(){if(!this._sortedDrapeSourceRenderersDirty)return;if(this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers.clear(),0===this._renderers.size)return;const e=this.view.map.allLayers;this._renderers.forEach(((r,t)=>{const s=e.indexOf(t.layer);this._sortedRenderers.push(new ue(t,r,s<0?1/0:s))})),this._sortedRenderers.sort(((e,r)=>e.index-r.index))}_setViewParameters(e,r,t){t.viewport[0]=t.viewport[1]=0,t.viewport[2]=t.viewport[3]=r.resolution,y(t.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],t.near,t.far),R(t.viewMatrix,[-e[0],-e[1],0]),this._bindParameters.camera=t}_updateHasWater(){const e=i(this._renderers,(e=>e.hasWater));e!==this._hasWater&&(this._hasWater=e,this.events.emit("has-water",e))}_updateHasHighlights(){const e=i(this._renderers,(e=>e.hasHighlights));e!==this._hasHighlights&&(this._hasHighlights=e,this.events.emit("has-highlights",e))}_updateRendersOccluded(){const e=i(this._renderers,(e=>e.rendersOccluded));e!==this._rendersOccluded&&(this._rendersOccluded=e,this.events.emit("renders-occluded",e))}_drawDebugTexture(e,r){this._ensureDebugPatternResources(e,e,r);const t=this._rctx;t.bindTechnique(this._debugTextureTechnique,this._passParameters,null),t.bindVAO(this._quadVAO),t.drawArrays(ie.TRIANGLE_STRIP,0,le(this._quadVAO,"geometry"))}_ensureDebugPatternResources(e,r,t){if(f(this._passParameters.color,t[0],t[1],t[2]),this._passParameters.texture)return;const s=new Uint8Array(e*r*4);let i=0;for(let a=0;a<r;a++)for(let t=0;t<e;t++){const o=Math.floor(t/10),n=Math.floor(a/10);o<2||n<2||10*o>e-20||10*n>r-20?(s[i++]=255,s[i++]=255,s[i++]=255,s[i++]=255):(s[i++]=255,s[i++]=255,s[i++]=255,s[i++]=1&o&&1&n?1&t^1&a?0:255:1&o^1&n?0:128)}this._passParameters.texture=new de(this._rctx,{target:oe.TEXTURE_2D,pixelFormat:ae.RGBA,dataType:ne.UNSIGNED_BYTE,samplingMode:he.NEAREST,width:e,height:r},s);const o=new X;o.hasAlpha=!0,this._debugTextureTechnique=this._shaderTechniqueRepository.acquire(Y,o),this._quadVAO=I(this._rctx)}get test(){return{drapeSourceRenderers:this._renderers,getDrapeSourceRenderer:e=>this._renderers.get(e)}}};var pe;e([_()],ce.prototype,"_frameTask",void 0),e([_()],ce.prototype,"_sortedDrapeSourceRenderersDirty",void 0),e([q()],ce.prototype,"_shaderTechniqueRepository",void 0),e([q()],ce.prototype,"_stippleTextureRepository",void 0),e([_({constructOnly:!0})],ce.prototype,"view",void 0),e([_()],ce.prototype,"worldToPCSRatio",void 0),e([_()],ce.prototype,"spatialReference",void 0),e([_({type:Boolean,readOnly:!0})],ce.prototype,"updating",null),ce=e([g("esri.views.3d.terrain.OverlayRenderer")],ce),function(e){e[e.Normal=0]="Normal",e[e.OccludedOnly=1]="OccludedOnly",e[e.ExcludeRasterImage=2]="ExcludeRasterImage"}(pe||(pe={}));class ue{constructor(e,r,t){this.drapeSource=e,this.renderer=r,this.index=t}}const me=[[1,.5,.5],[.5,.5,1]],_e=new W;_e.near=1,_e.far=1e4,_e.relativeElevation=null;const ge=-2,ye=H.OccludeAndTransparent;export{ge as DRAPED_Z,pe as DrawPassOption,ce as OverlayRenderer,ye 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/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{isSome as r,disposeMaybe as s,isNone as n}from"../../../core/maybe.js";import o from"../../../core/ObjectPool.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{I as h}from"../../../chunks/mat4f64.js";import{b as d,s as c,e as u}from"../../../chunks/vec3.js";import{Z as p,f as g,c as _}from"../../../chunks/vec3f64.js";import{Z as f,c as m}from"../../../chunks/vec4f64.js";import{create as b,set as T}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as y}from"../../../geometry/support/buffer/BufferView.js";import{ViewingMode as R}from"../../ViewingMode.js";import{TextureUpdate as O}from"./interfaces.js";import{LayerClass as v}from"./LayerClass.js";import{OverlaySource as x}from"./Overlay.js";import{overlayRenderOccludedFlag as C}from"./OverlayRenderer.js";import{clearCaches as D}from"./PatchGeometry.js";import{PatchRenderData as P}from"./PatchRenderData.js";import{RenderOrder as q}from"./RenderOrder.js";import{ScaleRangeQueries as S}from"./ScaleRangeQueries.js";import{ENABLE_TERRAIN_INTERNAL_CHECKS as E}from"./terrainUtils.js";import{TileRenderer as A}from"./TileRenderer.js";import{TileUpdate as w}from"./TileUpdate.js";import{IteratorPreorder as N,sortTiles as G,compareTiles as j}from"./tileUtils.js";import{componentMinimalSizeForIntersectionData as I,ComponentIntersectionData as F}from"../webgl-engine/collections/Component/ComponentIntersectionData.js";import{ShaderOutput as L}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{OverlayMode as U}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{T as k}from"../../../chunks/Terrain.glsl.js";import{TileBlendInput as B}from"../webgl-engine/core/shaderLibrary/terrain/TileBlendInput.js";import{RenderRequestType as M}from"../webgl-engine/lib/basicInterfaces.js";import{createEmptyTexture as H}from"../webgl-engine/lib/glUtil3D.js";import{newIntersectorResult as V}from"../webgl-engine/lib/Intersector.js";import{IntersectorType as z,StoreResults as Q}from"../webgl-engine/lib/IntersectorInterfaces.js";import{RenderOccludedFlag as W}from"../webgl-engine/lib/Material.js";import{RenderSlot as Y}from"../webgl-engine/lib/RenderSlot.js";import{getSettings as X}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as Z}from"../webgl-engine/lib/VertexAttribute.js";import{TERRAIN_ID as K,getVerticalOffsetTerrain as J}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as $}from"../webgl-engine/materials/DrawParameters.js";import{intersectAabbInvDirBefore as ee,intersectTriangles as te}from"../webgl-engine/materials/internal/MaterialUtil.js";import{TerrainTechnique as ie}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as re}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{ClearBufferBit as se,PrimitiveType as ne}from"../../webgl/enums.js";const oe=7,ae=10,le=b(),he=m();let de=class extends i{constructor(e){super(e),this.type=z.TERRAIN,this.isGround=!0,this._tileSize=256,this._techniqueConfiguration=new re,this._passParameters=new k,this._rctx=null,this._isTransparent=!1,this._scaleRangeQueries=new S,this._renderDataPool=new o(P),this._patchGroups=new Map,this._patchGroupsDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new N,this._highestVisibleLODTile=null,this._visible=!0,this._opaque=!0,this._velvetOverground=!0,this._castShadows=!0,this._emptyTex=null,this._tileRenderer=null,this._stencilEnabledLayerExtents=new Array,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.needsHighlight=!1,this.renderOccludedFlags=W.Occlude}get _isGlobal(){return this._stage.viewingMode===R.Global}get shadingEnabled(){return this._techniqueConfiguration?.shading}initialize(){const e=[Y.OPAQUE_TERRAIN,Y.TRANSPARENT_TERRAIN,Y.OCCLUDED_TERRAIN];this._stage.addRenderPlugin(e,this)}destroy(){this._stage.removeRenderPlugin(this),D()}get canRender(){return this._visible&&!!this._rootTiles&&!this.renderingDisabled}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setDirty()}set opaque(e){this._opaque!==e&&(this._opaque=e,this.setNeedsRender())}get opaque(){return this._opaque&&!this._techniqueConfiguration.hasSlicePlane}get needsLinearDepth(){return this._overlayRenderer.hasWater}set isTransparent(e){this._isTransparent!==e&&(this._isTransparent=e,this.setNeedsRender())}get isTransparent(){return this._isTransparent}get renderPatchBorders(){return!!this._techniqueConfiguration.tileBorders}set renderPatchBorders(e){this._techniqueConfiguration.tileBorders!==e&&(this._techniqueConfiguration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get cullBackFaces(){return this._techniqueConfiguration.backfaceCullingEnabled}set cullBackFaces(e){this._techniqueConfiguration.backfaceCullingEnabled!==e&&(this._techniqueConfiguration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}set renderOrder(e){this._set("renderOrder",e),this._setSortingDirty()}set velvetOverground(e){this._velvetOverground!==e&&(this._velvetOverground=e,this.setNeedsRender())}get layerUid(){return K}get slicePlaneEnabled(){return this._techniqueConfiguration.hasSlicePlane}set slicePlaneEnabled(e){this._techniqueConfiguration.hasSlicePlane!==e&&(this._techniqueConfiguration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._techniqueConfiguration.textureFadingEnabled!==e&&(this._techniqueConfiguration.textureFadingEnabled=e,this.setNeedsRender())}setDebugScreenSizePerspective(e){this._techniqueConfiguration.screenSizePerspective!==e&&(this._techniqueConfiguration.screenSizePerspective=e,this.setNeedsRender())}toggleShading(){this._techniqueConfiguration.shading=!this._techniqueConfiguration.shading,this.setNeedsRender()}setRootTiles(e){this._rootTiles=e,this.setDirty()}setNeedsHighlight(e){this.needsHighlight=e,this.setNeedsRender()}setRenderOccludedOverlay(e){this.renderOccludedFlags=e?C:W.Occlude,this.setNeedsRender()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}setTileSize(e){this._tileSize=e,r(this._tileRenderer)&&(this._tileRenderer.tileSize=e),this.setDirty()}_prepareTileForLoading(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e),e.renderData.localOrigin=this._getLocalOriginOfTile(e))}loadTile(e){this._prepareTileForLoading(e),this.updateTileGeometry(e),this.updateTileTexture(e,w.TEXTURE_FADING)}queryVisibleLevelRange(e,t,i,r){this._scaleRangeQueries.queryVisibleLevelRange(e,t,i,r),this.setNeedsRender()}updateTileTexture(e,t){r(this._tileRenderer)&&(this._tileRenderer.updateTileTexture(e,t===w.TEXTURE_FADING?O.FADING:O.UNFADED),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){this._prepareTileForLoading(e),e.renderData.updateGeometryStateAndPrepareForGeometryGeneration(this.wireframe)}updateTileGeometry(e){for(const t of e.layerInfo[v.ELEVATION])t.pendingUpdates&=~w.GEOMETRY;e.resetPendingUpdate(w.GEOMETRY);e.renderData.updateGeometryIfChanged(this._rctx,this.wireframe)&&this.setDirty()}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=ae-oe,i=Math.max(0,Math.floor((e.level-t)/oe)*oe);if(this._isGlobal&&0===i)return p;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}setVisibility(e){this._visible=e,this.setDirty()}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this._allTiles.forAll((e=>{e.isLoaded&&(this.updateTileGeometry(e),e.updateNeighborsAfterGeometryChange())})),this.setNeedsRender())}setDirty(e=M.UPDATE){this._patchGroupsDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=M.UPDATE){this._patchSortingDirty=!0,this._context.requestRender(e)}setNeedsRender(e=M.UPDATE){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._rctx=e.renderContext.rctx,this._techniqueRepository=e.shaderTechniqueRepository,this._tileRenderer=new A(this._rctx,this._tileSize,this._techniqueRepository),this.updateTileBackground(),this._emptyTex=H(this._rctx)}uninitializeRenderContext(){this._emptyTex=s(this._emptyTex),this._tileRenderer=s(this._tileRenderer)}intersect(e,t,i,s){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&!this._opaque)return;const o=pe,a=ge;d(o,s,i),c(a,1/o[0],1/o[1],1/o[2]);const l=e.results.min,p=e.results.max,g=e.results.ground,_=e.options.store===Q.MIN,f=!!e.results.ground.target,m=J(e.verticalOffset),b=e.tolerance;let R,O=_&&r(l.dist)?l.dist:1/0;const v=c=>{const f=c.renderData;if(!f?.vao)return;const v=f.geometryInfo;T(le,v.boundingBox);const x=f.localOrigin;r(m)&&(m.localOrigin=x,m.applyToAabb(le));const C=le;if(_e[0]=i[0]-x[0],_e[1]=i[1]-x[1],_e[2]=i[2]-x[2],!ee(C,_e,a,b,O))return;const D=(e,t,i)=>{e.set(this.type,c,t,i,h),O=_&&r(l.dist)?l.dist:1/0},P=(a,h)=>{if(r(h)&&a>=0&&(e.options.backfacesTerrain||u(h,o)<0)&&(e.options.invisibleTerrain||!e.options.selectionMode||null==t||t(i,s,a))){if((null==g.dist||a<g.dist)&&D(g,a,h),e.options.isFiltered)return;e.options.store===Q.ALL&&(n(R)?(R=V(e.ray),D(R,a,h),e.results.all.push(R)):a<R.dist&&D(R,a,h)),(null==l.dist||a<l.dist)&&D(l,a,h),e.options.store!==Q.MIN&&(null==p.dist||a>p.dist)&&D(p,a,h)}},q=fe;d(q,s,x);const S=v.indices,E=v.vertexAttributes,A={data:E.getField(Z.POSITION,y).typedBuffer,size:3,stride:E.stride/4},w=v.indexCount/3;if(n(m)&&w>I){const e=c.renderData;n(e.intersectionData)&&(e.intersectionData=new F(S,0,w,A)),e.intersectionData.intersectRay({r0:_e,r1:q},P)}else te(_e,q,0,w,S,A,null,m,P)},x=this._rootTiles;if(r(x)){(()=>{const t=this._tileIterator;t.reset(x);const s=e.options.invisibleTerrain;for(;!t.done;){const e=t.next();!(e.visible||s&&e.intersectsClippingArea)||!r(m)&&!e.intersectsRay(i,o,b,O)||f&&this._useStencilForTile(e)?t.skipSubtree():v(e)}})()}}prepareTechnique(e){if(e.bindParameters.slot===Y.OCCLUDED_TERRAIN){if(0==(e.renderOccludedMask&C))return null}else{const t=this.opaque?Y.OPAQUE_TERRAIN:Y.TRANSPARENT_TERRAIN;if(e.bindParameters.slot!==t)return null}switch(e.output){case L.Color:{this._techniqueConfiguration.hasScreenSpaceReflections=e.bindParameters.ssr.enabled,this._techniqueConfiguration.hasCloudsReflections=r(e.bindParameters.clouds.data),this._techniqueConfiguration.receiveShadows=e.bindParameters.shadowMap.ready,this._techniqueConfiguration.receiveAmbientOcclusion=e.bindParameters.ssaoHelper.ready,this._techniqueConfiguration.overlayMode=this._overlayRenderer.isEmpty()?U.Disabled:this._overlayRenderer.hasWater?U.EnabledWithWater:U.Enabled;const t=e.bindParameters.slot===Y.OCCLUDED_TERRAIN?x.Occluded:x.ColorAndWater;return this._updateTechnique(L.Color,t===x.Occluded)}case L.Shadow:case L.ShadowExludeHighlight:return this._castShadows&&1===e.bindParameters.lighting.globalFactor?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(L.Shadow,!1)):null;case L.Depth:return this.isTransparent&&this._overlayRenderer.isEmpty()?null:(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(L.Depth,!1));case L.Normal:return this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(L.Normal,!1);case L.Highlight:return this.needsHighlight?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(L.Highlight,!1)):null}return null}render(e,t){const i=1===e.bindParameters.lighting.globalFactor;switch(this._updatePatchGroups(),t.useStencil=!1,e.output){case L.Color:{const i=e.bindParameters.slot===Y.OCCLUDED_TERRAIN?x.Occluded:x.ColorAndWater;this._renderMaterialPass(e,t,i);break}case L.Shadow:case L.ShadowExludeHighlight:this._castShadows&&i&&this._renderAuxiliaryPass(e,t,x.None);break;case L.Depth:this.isTransparent&&this._overlayRenderer.isEmpty()||this._renderAuxiliaryPass(e,t,x.None);break;case L.Normal:this._renderAuxiliaryPass(e,t,x.None);break;case L.Highlight:this.needsHighlight&&(this._renderAuxiliaryPass(e,t,x.Highlight),e.rctx.clearSafe(se.DEPTH_BUFFER_BIT))}this._scaleRangeQueries.hasPendingQueries()&&this.setNeedsRender()}_renderMaterialPass(e,t,i){const{rctx:r}=e;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this._scaleRangeQueries.prepareQueries(),this.opaque?this._renderPatchGroups(e,t,i):e.offscreenRenderingHelper.renderToTargets((()=>this._renderPatchGroups(e,t,i)),e.offscreenRenderingHelper.tmpColor,e.offscreenRenderingHelper.mainDepth,[0,0,0,0]),this._scaleRangeQueries.processQueries()}_renderAuxiliaryPass(e,t,i){const r=e.rctx;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._renderPatchGroupsAuxiliary(e,t,i)}updateTileBackground(e=null){if(n(this._tileRenderer))return;const i=this._tileRenderer;let s=null;if(r(e)){const i=t.toUnitRGBA(e);s=g(i[0]||0,i[1]||0,i[2]||0)}i.setBackground(s),this._allTiles.forAll((e=>i.updateTileTexture(e,O.FADING))),this._techniqueConfiguration.tileBlendInput=i.backgroundIsGrid?B.GridComposite:r(i.backgroundColor)?B.ColorComposite:B.LayerOnly,this.setNeedsRender()}_updatePatchGroups(){if(this._patchGroupsDirty&&(this._highestVisibleLODTile=null,this._rebuildPatchGroups(),this._patchGroupsDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty&&this.renderOrder!==q.NONE){const e=Array.from(this._patchGroups.values());e.forEach((e=>G(this.renderOrder,e,this._stencilEnabledLayerExtents))),e.sort(((e,t)=>j(e[0],t[0],this.renderOrder))),this._patchGroups=new Map(e.map((e=>[e[0].renderData.localOrigin,e]))),this._patchSortingDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(!n(e)){e[0]?.surface.checkAllTileWaterproofness(),this._patchGroups.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||e.visible)if(e.rendered){if(i){const r=this._patchGroups.get(i.localOrigin)||new Array;this._patchGroups.set(i.localOrigin,r),r.push(e),(!this._highestVisibleLODTile||e.vlevel>this._highestVisibleLODTile.vlevel)&&(this._highestVisibleLODTile=e),t.skipSubtree()}}else this._numTilesCulled++;else this._numTilesCulled++,t.skipSubtree()}}_useStencilForTile(e){for(const t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderPatchGroupsAuxiliary(e,t,i){const r=this._stencilEnabledLayerExtents.length>0;this._patchGroups.forEach((s=>{const n=s[0].renderData.localOrigin;t.program.bindDraw(new $(n),e.bindParameters,this._passParameters);for(let o=0;o<s.length;o++)this._renderPatch(e,t,s[o],ne.TRIANGLES,r,i)})),e.rctx.bindVAO(null)}_renderPatchGroups(e,t,i){const s=e.rctx,o=e.bindParameters.camera,a=t.program;if(this._techniqueConfiguration.screenSizePerspective&&this.pointsOfInterest){const e=X(this._stage.viewingMode,this._ellipsoidRadius),t=this.pointsOfInterest.centerOnSurfaceFrequent.distance;e.update({distance:t,fovY:o.fovY})}const l=this._stencilEnabledLayerExtents.length>0,h=i===x.Occluded;h&&(a.bindTexture("tex",this._emptyTex),a.setUniform1f("blend",1),a.setUniform4fv("texOffsetAndScale",f));const d=r(this._tileRenderer)&&r(this._tileRenderer.backgroundColor)?this._tileRenderer.backgroundColor:p;this._techniqueConfiguration.tileBlendInput===B.ColorComposite&&a.setUniform3fv("backgroundColor",d);const c=this.wireframe?ne.LINES:ne.TRIANGLES;this._techniqueConfiguration.textureFadingEnabled&&a.bindTexture("texNext",this._emptyTex),this._patchGroups.forEach((s=>{const o=s[0].renderData.localOrigin;t.program.bindDraw(new $(o),e.bindParameters,this._passParameters),this._numOriginsRendered++;for(let d=0;d<s.length;d++){const o=s[d],u=o.renderData.textureReference;if(!n(u)){if(!h){this._scaleRangeQueries.scaleQueriesForTile(o),ue(o.renderData.geometryInfo.uvOffsetAndScale,u.offsetAndScale,he),a.setUniform4fv("texOffsetAndScale",he),a.bindTexture("tex",u.texture.texture);const e=o.renderData.textureFadeFactor,t=e<1?o.renderData.nextTextureReference:null;this._techniqueConfiguration.textureFadingEnabled&&r(t)&&e<1?(ue(o.renderData.geometryInfo.uvOffsetAndScale,t.offsetAndScale,he),a.setUniform1f("fadeFactor",e),a.setUniform4fv("nextTexOffsetAndScale",he),a.setUniform3fv("nextTexOpacities",t.opacities),a.bindTexture("texNext",t.texture.texture)):a.setUniform1f("fadeFactor",1),o.renderData.textureIsFading&&this.setNeedsRender(),a.setUniform3fv("textureOpacities",u.opacities)}this._renderPatch(e,t,o,c,l,i),o.renderOrder=this._numTilesRendered,this._numTilesRendered++}}})),s.bindVAO(null)}_renderPatch(e,t,i,r,s,o){const a=i.renderData,l=a.vao,h=l.indexBuffer;if(n(h))return void(E&&console.error("Rendered tile with no indices: ",i.lij," : ",a));const d=t.program;o!==x.None&&this._bindOverlayPatchData(d,a.overlay),s&&(t.useStencil=this._useStencilForTile(i),t.bindPipelineState(e.rctx,e.bindParameters.slot));const c=a.geometryInfo.indexCount;e.rctx.bindVAO(l),d.assertCompatibleVertexAttributeLocations(l),e.rctx.drawElements(r,c,h.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_updateTechnique(e,t){return this._techniqueConfiguration.output=e,e===L.Color&&(this._techniqueConfiguration.atmosphere=this._isGlobal&&this._velvetOverground),this._techniqueConfiguration.renderOccluded=t,this._techniqueConfiguration.stencilEnabled=!1,this._shaderTechnique=this._techniqueRepository.releaseAndAcquire(ie,this._techniqueConfiguration,this._shaderTechnique),this._shaderTechnique}get test(){return{tileRenderer:this._tileRenderer}}};e([a({constructOnly:!0})],de.prototype,"_overlayRenderer",void 0),e([a({constructOnly:!0})],de.prototype,"_stage",void 0),e([a({readOnly:!0})],de.prototype,"_isGlobal",null),e([a({constructOnly:!0})],de.prototype,"_allTiles",void 0),e([a({constructOnly:!0})],de.prototype,"_ellipsoidRadius",void 0),e([a({value:!1})],de.prototype,"renderingDisabled",null),e([a()],de.prototype,"renderPatchBorders",null),e([a()],de.prototype,"cullBackFaces",null),e([a({value:q.FRONT_TO_BACK})],de.prototype,"renderOrder",null),e([a()],de.prototype,"wireframe",null),de=e([l("esri.views.3d.terrain.TerrainRenderer")],de);const ce=de;function ue(e,t,i){i[0]=e[0]*t[2]+t[0],i[1]=e[1]*t[3]+t[1],i[2]=e[2]*t[2],i[3]=e[3]*t[3]}const pe=_(),ge=_(),_e=_(),fe=_();export{ce as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{isSome as r,disposeMaybe as s,isNone as n}from"../../../core/maybe.js";import a from"../../../core/ObjectPool.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{I as h}from"../../../chunks/mat4f64.js";import{b as d,s as c,e as u}from"../../../chunks/vec3.js";import{Z as p,f as _,c as g}from"../../../chunks/vec3f64.js";import{Z as f,c as m}from"../../../chunks/vec4f64.js";import{create as b,set as T}from"../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as y}from"../../../geometry/support/buffer/BufferView.js";import{ViewingMode as R}from"../../ViewingMode.js";import{TextureUpdate as O}from"./interfaces.js";import{LayerClass as x}from"./LayerClass.js";import{OverlaySource as v}from"./Overlay.js";import{overlayRenderOccludedFlag as C}from"./OverlayRenderer.js";import{clearCaches as D}from"./PatchGeometry.js";import{PatchRenderData as P}from"./PatchRenderData.js";import{RenderOrder as q}from"./RenderOrder.js";import{ScaleRangeQueries as S}from"./ScaleRangeQueries.js";import{ENABLE_TERRAIN_INTERNAL_CHECKS as A}from"./terrainUtils.js";import{TileRenderer as E}from"./TileRenderer.js";import{TileUpdate as w}from"./TileUpdate.js";import{IteratorPreorder as N,sortTiles as j,compareTiles as G}from"./tileUtils.js";import{componentMinimalSizeForIntersectionData as I,ComponentIntersectionData as L}from"../webgl-engine/collections/Component/ComponentIntersectionData.js";import{ShaderOutput as F}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{OverlayMode as U}from"../webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js";import{T as k}from"../../../chunks/Terrain.glsl.js";import{TileBlendInput as B}from"../webgl-engine/core/shaderLibrary/terrain/TileBlendInput.js";import{RenderRequestType as M}from"../webgl-engine/lib/basicInterfaces.js";import{createEmptyTexture as H}from"../webgl-engine/lib/glUtil3D.js";import{newIntersectorResult as V}from"../webgl-engine/lib/Intersector.js";import{IntersectorType as z,StoreResults as Q}from"../webgl-engine/lib/IntersectorInterfaces.js";import{RenderOccludedFlag as W}from"../webgl-engine/lib/Material.js";import{RenderSlot as Y}from"../webgl-engine/lib/RenderSlot.js";import{getSettings as X}from"../webgl-engine/lib/screenSizePerspectiveUtils.js";import{VertexAttribute as Z}from"../webgl-engine/lib/VertexAttribute.js";import{TERRAIN_ID as K,getVerticalOffsetTerrain as J}from"../webgl-engine/lib/verticalOffsetUtils.js";import{DrawParameters as $}from"../webgl-engine/materials/DrawParameters.js";import{intersectAabbInvDirBefore as ee,intersectTriangles as te}from"../webgl-engine/materials/internal/MaterialUtil.js";import{TerrainTechnique as ie}from"../webgl-engine/shaders/TerrainTechnique.js";import{TerrainTechniqueConfiguration as re}from"../webgl-engine/shaders/TerrainTechniqueConfiguration.js";import{ClearBufferBit as se,PrimitiveType as ne}from"../../webgl/enums.js";const ae=7,oe=10,le=b(),he=m();let de=class extends i{constructor(e){super(e),this.type=z.TERRAIN,this.isGround=!0,this._tileSize=256,this._techniqueConfiguration=new re,this._passParameters=new k,this._rctx=null,this._isTransparent=!1,this._scaleRangeQueries=new S,this._renderDataPool=new a(P),this._patchGroups=new Map,this._patchGroupsDirty=!0,this._patchSortingDirty=!0,this._tileIterator=new N,this._highestVisibleLODTile=null,this._visible=!0,this._opaque=!0,this._velvetOverground=!0,this._castShadows=!0,this._emptyTex=null,this._tileRenderer=null,this._stencilEnabledLayerExtents=new Array,this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this.needsHighlight=!1,this.renderOccludedFlags=W.Occlude}get _isGlobal(){return this._stage.viewingMode===R.Global}get shadingEnabled(){return this._techniqueConfiguration?.shading}initialize(){const e=[Y.OPAQUE_TERRAIN,Y.TRANSPARENT_TERRAIN,Y.OCCLUDED_TERRAIN];this._stage.addRenderPlugin(e,this)}destroy(){this._stage.removeRenderPlugin(this),D()}get canRender(){return this._visible&&!!this._rootTiles&&!this.renderingDisabled}set renderingDisabled(e){this._set("renderingDisabled",!!e),this.setDirty()}set opaque(e){this._opaque!==e&&(this._opaque=e,this.setNeedsRender())}get opaque(){return this._opaque&&!this._techniqueConfiguration.hasSlicePlane}get needsLinearDepth(){return this._overlayRenderer.hasWater}set isTransparent(e){this._isTransparent!==e&&(this._isTransparent=e,this.setNeedsRender())}get isTransparent(){return this._isTransparent}get renderPatchBorders(){return!!this._techniqueConfiguration.tileBorders}set renderPatchBorders(e){this._techniqueConfiguration.tileBorders!==e&&(this._techniqueConfiguration.tileBorders=e,this.setNeedsRender(),this.notifyChange("renderPatchBorders"))}get cullBackFaces(){return this._techniqueConfiguration.backfaceCullingEnabled}set cullBackFaces(e){this._techniqueConfiguration.backfaceCullingEnabled!==e&&(this._techniqueConfiguration.backfaceCullingEnabled=e,this.notifyChange("cullBackFaces"),this.setNeedsRender())}set renderOrder(e){this._set("renderOrder",e),this._setSortingDirty()}set velvetOverground(e){this._velvetOverground!==e&&(this._velvetOverground=e,this.setNeedsRender())}get layerUid(){return K}get slicePlaneEnabled(){return this._techniqueConfiguration.hasSlicePlane}set slicePlaneEnabled(e){this._techniqueConfiguration.hasSlicePlane!==e&&(this._techniqueConfiguration.hasSlicePlane=e,this.setNeedsRender())}set textureFadingEnabled(e){this._techniqueConfiguration.textureFadingEnabled!==e&&(this._techniqueConfiguration.textureFadingEnabled=e,this.setNeedsRender())}setDebugScreenSizePerspective(e){this._techniqueConfiguration.screenSizePerspective!==e&&(this._techniqueConfiguration.screenSizePerspective=e,this.setNeedsRender())}toggleShading(){this._techniqueConfiguration.shading=!this._techniqueConfiguration.shading,this.setNeedsRender()}setRootTiles(e){this._rootTiles=e,this.setDirty()}setNeedsHighlight(e){this.needsHighlight=e,this.setNeedsRender()}setRenderOccludedOverlay(e){this.renderOccludedFlags=e?C:W.Occlude,this.setNeedsRender()}setStencilEnabledLayerExtents(e){this._stencilEnabledLayerExtents=e,this._setSortingDirty()}setTileSize(e){this._tileSize=e,r(this._tileRenderer)&&(this._tileRenderer.tileSize=e),this.setDirty()}_prepareTileForLoading(e){e.renderData||(e.renderData=this._renderDataPool.acquire(),e.renderData.init(e),e.renderData.localOrigin=this._getLocalOriginOfTile(e))}loadTile(e){this._prepareTileForLoading(e),this.updateTileGeometry(e),this.updateTileTexture(e,w.TEXTURE_FADING)}queryVisibleLevelRange(e,t,i,r){this._scaleRangeQueries.queryVisibleLevelRange(e,t,i,r),this.setNeedsRender()}updateTileTexture(e,t){r(this._tileRenderer)&&(this._tileRenderer.updateTileTexture(e,t===w.TEXTURE_FADING?O.FADING:O.UNFADED),this.setNeedsRender(),e.resetPendingUpdate(t))}updateTileGeometryState(e){this._prepareTileForLoading(e),e.renderData.updateGeometryStateAndPrepareForGeometryGeneration(this.wireframe)}updateTileGeometry(e){for(const t of e.layerInfo[x.ELEVATION])t.pendingUpdates&=~w.GEOMETRY;e.resetPendingUpdate(w.GEOMETRY);e.renderData.updateGeometryIfChanged(this._rctx,this.wireframe)&&this.setDirty()}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=oe-ae,i=Math.max(0,Math.floor((e.level-t)/ae)*ae);if(this._isGlobal&&0===i)return p;for(;e.parent&&e.level>i;)e=e.parent;return e.centerAtSeaLevel}setVisibility(e){this._visible=e,this.setDirty()}getStats(){return{numTilesRendered:this._numTilesRendered,numTilesCulled:this._numTilesCulled,numOriginsRendered:this._numOriginsRendered}}set wireframe(e){this._get("wireframe")!==e&&(this._set("wireframe",e),this._allTiles.forAll((e=>{e.isLoaded&&(this.updateTileGeometry(e),e.updateNeighborsAfterGeometryChange())})),this.setNeedsRender())}setDirty(e=M.UPDATE){this._patchGroupsDirty=!0,this._context.requestRender(e)}_setSortingDirty(e=M.UPDATE){this._patchSortingDirty=!0,this._context.requestRender(e)}setNeedsRender(e=M.UPDATE){this._context.requestRender(e)}initializeRenderContext(e){this._context=e,this._rctx=e.renderContext.rctx,this._techniqueRepository=e.shaderTechniqueRepository,this._tileRenderer=new E(this._rctx,this._tileSize,this._techniqueRepository),this.updateTileBackground(),this._emptyTex=H(this._rctx)}uninitializeRenderContext(){this._emptyTex=s(this._emptyTex),this._tileRenderer=s(this._tileRenderer)}intersect(e,t,i,s){if(!this._rootTiles||e.options.selectOpaqueTerrainOnly&&e.options.selectionMode&&!this._opaque)return;const a=pe,o=_e;d(a,s,i),c(o,1/a[0],1/a[1],1/a[2]);const l=e.results.min,p=e.results.max,_=e.results.ground,g=e.options.store===Q.MIN,f=!!e.results.ground.target,m=J(e.verticalOffset),b=e.tolerance;let R,O=g&&r(l.dist)?l.dist:1/0;const x=c=>{const f=c.renderData;if(!f?.vao)return;const x=f.geometryInfo;T(le,x.boundingBox);const v=f.localOrigin;r(m)&&(m.localOrigin=v,m.applyToAabb(le));const C=le;if(ge[0]=i[0]-v[0],ge[1]=i[1]-v[1],ge[2]=i[2]-v[2],!ee(C,ge,o,b,O))return;const D=(e,t,i)=>{e.set(this.type,c,t,i,h),O=g&&r(l.dist)?l.dist:1/0},P=(o,h)=>{if(r(h)&&o>=0&&(e.options.backfacesTerrain||u(h,a)<0)&&(e.options.invisibleTerrain||!e.options.selectionMode||null==t||t(i,s,o))){if((null==_.dist||o<_.dist)&&D(_,o,h),e.options.isFiltered)return;e.options.store===Q.ALL&&(n(R)?(R=V(e.ray),D(R,o,h),e.results.all.push(R)):o<R.dist&&D(R,o,h)),(null==l.dist||o<l.dist)&&D(l,o,h),e.options.store!==Q.MIN&&(null==p.dist||o>p.dist)&&D(p,o,h)}},q=fe;d(q,s,v);const S=x.indices,A=x.vertexAttributes,E={data:A.getField(Z.POSITION,y).typedBuffer,size:3,stride:A.stride/4},w=x.indexCount/3;if(n(m)&&w>I){const e=c.renderData;n(e.intersectionData)&&(e.intersectionData=new L(S,0,w,E)),e.intersectionData.intersectRay({r0:ge,r1:q},P)}else te(ge,q,0,w,S,E,null,m,P)},v=this._rootTiles;if(r(v)){(()=>{const t=this._tileIterator;t.reset(v);const s=e.options.invisibleTerrain;for(;!t.done;){const e=t.next();!(e.visible||s&&e.intersectsClippingArea)||!r(m)&&!e.intersectsRay(i,a,b,O)||f&&this._useStencilForTile(e)?t.skipSubtree():x(e)}})()}}prepareTechnique(e){if(e.bindParameters.slot===Y.OCCLUDED_TERRAIN){if(0==(e.renderOccludedMask&C))return null}else{const t=this.opaque?Y.OPAQUE_TERRAIN:Y.TRANSPARENT_TERRAIN;if(e.bindParameters.slot!==t)return null}switch(e.output){case F.Color:{this._techniqueConfiguration.hasScreenSpaceReflections=e.bindParameters.ssr.enabled,this._techniqueConfiguration.hasCloudsReflections=r(e.bindParameters.clouds.data),this._techniqueConfiguration.receiveShadows=e.bindParameters.shadowMap.ready,this._techniqueConfiguration.receiveAmbientOcclusion=e.bindParameters.ssaoHelper.ready,this._techniqueConfiguration.overlayMode=this._overlayRenderer.isEmpty()?U.Disabled:this._overlayRenderer.hasWater?U.EnabledWithWater:U.Enabled;const t=e.bindParameters.slot===Y.OCCLUDED_TERRAIN?v.Occluded:v.ColorAndWater;return this._updateTechnique(F.Color,t===v.Occluded)}case F.Shadow:case F.ShadowExludeHighlight:return this._castShadows&&1===e.bindParameters.lighting.globalFactor?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(F.Shadow,!1)):null;case F.Depth:return this.isTransparent&&this._overlayRenderer.isEmpty()?null:(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(F.Depth,!1));case F.Normal:return this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(F.Normal,!1);case F.ObjectAndLayerIdColor:return this._updateTechnique(F.ObjectAndLayerIdColor,!1);case F.Highlight:return this.needsHighlight?(this._techniqueConfiguration.receiveShadows=this._techniqueConfiguration.receiveAmbientOcclusion=!1,this._updateTechnique(F.Highlight,!1)):null}return null}render(e,t){const i=1===e.bindParameters.lighting.globalFactor;switch(this._updatePatchGroups(),t.useStencil=!1,e.output){case F.Color:{const i=e.bindParameters.slot===Y.OCCLUDED_TERRAIN?v.Occluded:v.ColorAndWater;this._renderMaterialPass(e,t,i);break}case F.Shadow:case F.ShadowExludeHighlight:this._castShadows&&i&&this._renderAuxiliaryPass(e,t,v.None);break;case F.Depth:this.isTransparent&&this._overlayRenderer.isEmpty()||this._renderAuxiliaryPass(e,t,v.None);break;case F.Normal:this._renderAuxiliaryPass(e,t,v.None);break;case F.ObjectAndLayerIdColor:this._renderAuxiliaryPass(e,t,v.ObjectAndLayerIdColor);break;case F.Highlight:this.needsHighlight&&(this._renderAuxiliaryPass(e,t,v.Highlight),e.rctx.clearSafe(se.DEPTH_BUFFER_BIT))}this._scaleRangeQueries.hasPendingQueries()&&this.setNeedsRender()}_renderMaterialPass(e,t,i){const{rctx:r}=e;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._numTilesRendered=0,this._numTilesCulled=0,this._numOriginsRendered=0,this._scaleRangeQueries.prepareQueries(),this.opaque?this._renderPatchGroups(e,t,i):e.offscreenRenderingHelper.renderToTargets((()=>this._renderPatchGroups(e,t,i)),e.offscreenRenderingHelper.tmpColor,e.offscreenRenderingHelper.mainDepth,[0,0,0,0]),this._scaleRangeQueries.processQueries()}_renderAuxiliaryPass(e,t,i){const r=e.rctx;this._passParameters.overlaySource=i,r.bindTechnique(t,this._passParameters,e.bindParameters),this._renderPatchGroupsAuxiliary(e,t,i)}updateTileBackground(e=null){if(n(this._tileRenderer))return;const i=this._tileRenderer;let s=null;if(r(e)){const i=t.toUnitRGBA(e);s=_(i[0]||0,i[1]||0,i[2]||0)}i.setBackground(s),this._allTiles.forAll((e=>i.updateTileTexture(e,O.FADING))),this._techniqueConfiguration.tileBlendInput=i.backgroundIsGrid?B.GridComposite:r(i.backgroundColor)?B.ColorComposite:B.LayerOnly,this.setNeedsRender()}_updatePatchGroups(){if(this._patchGroupsDirty&&(this._highestVisibleLODTile=null,this._rebuildPatchGroups(),this._patchGroupsDirty=!1,this._patchSortingDirty=!0),this._patchSortingDirty&&this.renderOrder!==q.NONE){const e=Array.from(this._patchGroups.values());e.forEach((e=>j(this.renderOrder,e,this._stencilEnabledLayerExtents))),e.sort(((e,t)=>G(e[0],t[0],this.renderOrder))),this._patchGroups=new Map(e.map((e=>[e[0].renderData.localOrigin,e]))),this._patchSortingDirty=!1}}_rebuildPatchGroups(){const e=this._rootTiles;if(!n(e)){e[0]?.surface.checkAllTileWaterproofness(),this._patchGroups.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||e.visible)if(e.rendered){if(i){const r=this._patchGroups.get(i.localOrigin)||new Array;this._patchGroups.set(i.localOrigin,r),r.push(e),(!this._highestVisibleLODTile||e.vlevel>this._highestVisibleLODTile.vlevel)&&(this._highestVisibleLODTile=e),t.skipSubtree()}}else this._numTilesCulled++;else this._numTilesCulled++,t.skipSubtree()}}_useStencilForTile(e){for(const t of this._stencilEnabledLayerExtents)if(e.intersectsExtent(t))return!0;return!1}_renderPatchGroupsAuxiliary(e,t,i){const r=this._stencilEnabledLayerExtents.length>0;this._patchGroups.forEach((s=>{const n=s[0].renderData.localOrigin;t.program.bindDraw(new $(n),e.bindParameters,this._passParameters);for(let a=0;a<s.length;a++)this._renderPatch(e,t,s[a],ne.TRIANGLES,r,i)})),e.rctx.bindVAO(null)}_renderPatchGroups(e,t,i){const s=e.rctx,a=e.bindParameters.camera,o=t.program;if(this._techniqueConfiguration.screenSizePerspective&&this.pointsOfInterest){const e=X(this._stage.viewingMode,this._ellipsoidRadius),t=this.pointsOfInterest.centerOnSurfaceFrequent.distance;e.update({distance:t,fovY:a.fovY})}const l=this._stencilEnabledLayerExtents.length>0,h=i===v.Occluded;h&&(o.bindTexture("tex",this._emptyTex),o.setUniform1f("blend",1),o.setUniform4fv("texOffsetAndScale",f));const d=r(this._tileRenderer)&&r(this._tileRenderer.backgroundColor)?this._tileRenderer.backgroundColor:p;this._techniqueConfiguration.tileBlendInput===B.ColorComposite&&o.setUniform3fv("backgroundColor",d);const c=this.wireframe?ne.LINES:ne.TRIANGLES;this._techniqueConfiguration.textureFadingEnabled&&o.bindTexture("texNext",this._emptyTex),this._patchGroups.forEach((s=>{const a=s[0].renderData.localOrigin;t.program.bindDraw(new $(a),e.bindParameters,this._passParameters),this._numOriginsRendered++;for(let d=0;d<s.length;d++){const a=s[d],u=a.renderData.textureReference;if(!n(u)){if(!h){this._scaleRangeQueries.scaleQueriesForTile(a),ue(a.renderData.geometryInfo.uvOffsetAndScale,u.offsetAndScale,he),o.setUniform4fv("texOffsetAndScale",he),o.bindTexture("tex",u.texture.texture);const e=a.renderData.textureFadeFactor,t=e<1?a.renderData.nextTextureReference:null;this._techniqueConfiguration.textureFadingEnabled&&r(t)&&e<1?(ue(a.renderData.geometryInfo.uvOffsetAndScale,t.offsetAndScale,he),o.setUniform1f("fadeFactor",e),o.setUniform4fv("nextTexOffsetAndScale",he),o.setUniform3fv("nextTexOpacities",t.opacities),o.bindTexture("texNext",t.texture.texture)):o.setUniform1f("fadeFactor",1),a.renderData.textureIsFading&&this.setNeedsRender(),o.setUniform3fv("textureOpacities",u.opacities)}this._renderPatch(e,t,a,c,l,i),a.renderOrder=this._numTilesRendered,this._numTilesRendered++}}})),s.bindVAO(null)}_renderPatch(e,t,i,r,s,a){const o=i.renderData,l=o.vao,h=l.indexBuffer;if(n(h))return void(A&&console.error("Rendered tile with no indices: ",i.lij," : ",o));const d=t.program;a!==v.None&&this._bindOverlayPatchData(d,o.overlay),s&&(t.useStencil=this._useStencilForTile(i),t.bindPipelineState(e.rctx,e.bindParameters.slot));const c=o.geometryInfo.indexCount;e.rctx.bindVAO(l),d.assertCompatibleVertexAttributeLocations(l),e.rctx.drawElements(r,c,h.indexType,0)}_bindOverlayPatchData(e,t){e.setUniform4fv("overlayTexOffset",t.offsets),e.setUniform4fv("overlayTexScale",t.scales)}_updateTechnique(e,t){return this._techniqueConfiguration.output=e,e===F.Color&&(this._techniqueConfiguration.atmosphere=this._isGlobal&&this._velvetOverground),this._techniqueConfiguration.renderOccluded=t,this._techniqueConfiguration.stencilEnabled=!1,this._shaderTechnique=this._techniqueRepository.releaseAndAcquire(ie,this._techniqueConfiguration,this._shaderTechnique),this._shaderTechnique}get test(){return{tileRenderer:this._tileRenderer}}};e([o({constructOnly:!0})],de.prototype,"_overlayRenderer",void 0),e([o({constructOnly:!0})],de.prototype,"_stage",void 0),e([o({readOnly:!0})],de.prototype,"_isGlobal",null),e([o({constructOnly:!0})],de.prototype,"_allTiles",void 0),e([o({constructOnly:!0})],de.prototype,"_ellipsoidRadius",void 0),e([o({value:!1})],de.prototype,"renderingDisabled",null),e([o()],de.prototype,"renderPatchBorders",null),e([o()],de.prototype,"cullBackFaces",null),e([o({value:q.FRONT_TO_BACK})],de.prototype,"renderOrder",null),e([o()],de.prototype,"wireframe",null),de=e([l("esri.views.3d.terrain.TerrainRenderer")],de);const ce=de;function ue(e,t,i){i[0]=e[0]*t[2]+t[0],i[1]=e[1]*t[3]+t[1],i[2]=e[2]*t[2],i[3]=e[3]*t[3]}const pe=g(),_e=g(),ge=g(),fe=g();export{ce as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.25/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import _ from"../../../core/PooledArray.js";import{isAbortError as g,isAborted as m,createAbortError as f}from"../../../core/promiseUtils.js";import{watch as T,syncAndInitial as y,sync as v,initial as w}from"../../../core/reactiveUtils.js";import{property as L}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{m as b}from"../../../chunks/mat4.js";import{c as E}from"../../../chunks/mat4f64.js";import{c as D}from"../../../chunks/vec3.js";import{c as C}from"../../../chunks/vec3f64.js";import{c as x}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as U}from"../../../core/support/WatchUpdatingTracking.js";import{projectVectorToVector as P,projectPointToVector as R}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import{create as j,equals as A,intersection as I,intersectsSphere as V}from"../../../geometry/support/aaBoundingRect.js";import{create as k,copy as N}from"../../../geometry/support/frustum.js";import{isPlateCarree as O}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as B}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as q}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as G}from"../../../layers/support/layerUtils.js";import{acquireDecoder as W}from"../../../layers/support/LercDecoder.js";import{printAllocations as F}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as H,scaleToZoom as Q}from"../support/cameraUtils.js";import X from"../support/debugFlags.js";import{toBoundingRect as z}from"../support/extentUtils.js";import{ClientType as Y}from"../support/index.js";import{updatingProgress as $}from"../support/updatingProperties.js";import{ElevationBounds as K}from"./ElevationBounds.js";import{sampleElevation as J,ElevationData as Z}from"./ElevationData.js";import{create as ee}from"./ExtentHelper.js";import{LODSnapping as te,TextureUpdate as ie}from"./interfaces.js";import{LayerClass as re,LayerClasses as se}from"./LayerClass.js";import{OverlayManager as ae}from"./OverlayManager.js";import{PlanarPatch as ne}from"./PlanarPatch.js";import{RenderOrder as le}from"./RenderOrder.js";import{SphericalPatch as oe}from"./SphericalPatch.js";import{MAX_ROOT_TILES as he,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as de,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as pe,MAX_MEMORY_LOD_BIAS as ue,ELEVATION_NODATA_VALUE as ce}from"./TerrainConst.js";import _e from"./TerrainRenderer.js";import ge from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as me,internalAssert as fe,isSurfaceLayerView as Te,isMapTileLayerView as ye,isBlendableLayerView as ve,isGroupLayer as we,isElevationLayerView as Le,isVectorTileLayerView as Se,useFetchTileForLayer as be,isImageryTileLayerView as Ee,isTileLayerView as De,releaseTileData as Ce,ENABLE_WATERPROOFNESS_TESTS as xe,enableTerrainInternalChecks as Ue,enableTerrainWaterproofnessChecks as Pe}from"./terrainUtils.js";import{SplitLimits as Re,Tile as Me}from"./Tile.js";import{printAllocations as je}from"./TilePerLayerInfo.js";import{TileUpdate as Ae}from"./TileUpdate.js";import{IteratorPreorder as Ie,IteratorPostorder as Ve,hasLoadableSiblings as ke,sortTilesByPOI as Ne,sortTiles as Oe}from"./tileUtils.js";import{TilingSchemeLogic as Be}from"./TilingSchemeLogic.js";import{UpsampleInfo as qe}from"./UpsampleInfo.js";import{isCompositeBlendMode as Ge,blendModeFromString as We}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{RenderRequestType as Fe}from"../webgl-engine/lib/basicInterfaces.js";import{ImmediateTask as He,TaskPriority as Qe,noBudget as Xe}from"../../support/Scheduler.js";const ze=.25;let Ye=class extends(a.EventedMixin(i)){constructor(e){super(e),this._elevationBounds=new K,this._iteratorPool=new c(Ie,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new Ve,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visibleCached=!1,this._usedMemory=null,this._performanceInfo=new ge,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=C(),this._eyePosSurfaceSR=C(),this._splitLimits=new Re,this._snapLevel=1/0,this._frustum=k(),this._viewProjectionMatrix=E(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new U,this._frameTask=He,this._allTiles=new _,this._upsampleInfoPool=new c(qe),this._rootTilesExtent=j(),this._maxNumUpdating=1,this.maxTextureScale=1.2,this._updatingRootTiles=!1,this._deferTileNeighborUpdate=!1,this._neighborTilesToUpdate=new Set,this.enableBatchTileGeometryUpdates=!0,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=W(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(ne):new c(oe);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new q(e.newCache("elevation-query")),this._set("overlayManager",new ae({surface:this})),this._handles.add([T((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),T((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e)))],"overlayManager"),this._renderer=new _e({_overlayRenderer:this.overlayManager.renderer,_ellipsoidRadius:M(this.view.spatialReference).radius,_stage:this.view._stage,_allTiles:this._allTiles}),this._handles.add([T((()=>this.baseOpacity),(e=>{this._handleLayerViewChanges(),this._updateBaseOpacity(e)}),y),T((()=>this.hasCompositeBlendMode),(()=>{this._updateBaseOpacity(this.baseOpacity)}),y),T((()=>this.renderingDisabled),(()=>this._updateTransparentTerrain()),v),T((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(e)}),y),T((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>()=>this._allTilesSorted=!1))})),T((()=>X.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&X.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),w)]),this._extentHelper=ee(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:this.view.spatialReference});const t=this.view.defaultsFromMap?new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}):this.view.map.allLayers,i=new Be({layers:t,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:this.view.spatialReference});this._set("tilingSchemeLogic",i),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(Y.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(Y.BASEMAP);const r=this.view.resourceController.scheduler;this._frameTask=r.registerTask(Qe.TERRAIN_SURFACE,this),this._handles.add([T((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),w),T((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),v),T((()=>this.extent),(()=>this._updateRootTiles()),w),this.view.on("resize",(()=>this._viewChangeUpdate())),T((()=>{const e=this.view,t=e.state;return[this._lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),y),T((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),w),T((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),v)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache),this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),this._extentHelper=d(this._extentHelper),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Me.prune(),this._treeDebugger&&(this._treeDebugger.destroy(),this._treeDebugger=null),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),F(),je()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){const e=this.view.pointsOfInterest?.contentCameraOnSurface?.scale;if(e){const t=this.view.state.contentCamera;let i=H(this.view,t.eye,t.viewForward,t.up).tilt;i>90&&(i=180-i);const r=2*(i/90)**2,s=Q(this.view,e)-r;Math.abs(this._snapLevel-s)>ze&&(Math.round(s)!==Math.round(this._snapLevel)&&(this._viewChanged=!0),this._snapLevel=s)}return Math.round(this._snapLevel)}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?te.ON:te.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=j(),r=z(t,i,e)?i:null,s=this._get("extent");return A(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=I(this.groundExtent,this._userClippingExtent,j()),t=this._get("extent");return A(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this._watchUpdatingTracking.updating||this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||this._asyncWorkItems>0||!this._allTilesSorted||this._layerViewsDirty)&&this.ready&&!this.suspended||this.overlayManager.updating||this._frameTask.updating)}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view.map.ground.opacity}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this.rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}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._updateTransparentTerrain()}_updateTransparentTerrain(){const e=!this.renderingDisabled&&!this.opaque;this.view?._stage?.renderView.setRenderParameters({transparentTerrain:e})}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}set velvetOverground(e){e!==this.velvetOverground&&(this._renderer.velvetOverground=e),this._set("velvetOverground",e)}get wireframe(){return this._renderer.wireframe}set wireframe(e){this._renderer.wireframe=e}set _visible(e){e!==this._visibleCached&&(this._visibleCached=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get textureFadeDuration(){return this.view.qualitySettings.tiledSurface.textureFadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this.getTileWithElevation(e,t,i,r,et);return p(s)?null:J(et[0],et[1],s.renderData.geometryState.samplerData)}getTileWithElevation(e,t,i,r,s=et){const a=this.rootTiles;if(p(a)||!a.length)return null;if(0===a[0].layerInfo[re.ELEVATION].length)return null;if(s[0]=e,s[1]=t,s[2]=i,!P(s,r,s,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;for(let n of a){if(!n.containsPoint(s))continue;for(;n&&!n.rendered&&!n.isLeaf;){let e=0;s[0]>.5*(n.extent[0]+n.extent[2])&&(e+=1),s[1]<.5*(n.extent[1]+n.extent[3])&&(e+=2),n=n.children[e]}const e=n.renderData;return(e?e.geometryState.samplerData:null)?n:null}return null}get elevationBounds(){return this._elevationBounds}getScale(e){if(this.tilingScheme){if(!R(e,et,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this.rootTiles;if(u(t))for(let e of t)if(e?.containsPoint(et)){for(;!e.isLeaf&&!e.rendered;){let t=0;et[0]>e.children[0].extent[2]&&(t+=1),et[1]<e.children[0].extent[1]&&(t+=2),e=e.children[t]}return this._getLodBiasCorrectedScale(e.level)}}return 1e100}getSphereElevationBounds(e,t,i,r,s){if(et[0]=e,et[1]=t,et[2]=i,et[3]=r,!P(et,s,et,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;let a=1/0,n=-1/0;const o=e=>{if(e&&V(e.extent,et))if(e.isLeaf||e.rendered)a=Math.min(a,e.elevationBounds[0]),n=Math.max(n,e.elevationBounds[1]);else for(const t of e.children)o(t)},h=this.rootTiles;if(u(h))for(const l of h)o(l);return{min:a,max:n}}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,et,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;et[3]=t;let i=null;const r=e=>{if(e&&V(e.extent,et))if(e.isLeaf||e.rendered){const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}else for(const t of e.children)r(t)},s=this.rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._renderer.queryVisibleLevelRange(e,s+n,a+n,r)}_updateBaseOpacity(e){const t=this._renderer.opaque;this._renderer.opaque=e>=1&&!this.hasCompositeBlendMode,this._renderer.isTransparent=this._allSurfaceLayersTransparent();const i=t!==this._renderer.opaque;i&&this._updateTransparentTerrain(),this._updateTileTextures(i?ie.UNFADED:ie.IMMEDIATE)}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;e!==this.tilingScheme&&(me(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles(),this._set("tilingScheme",e),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles()))}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return it[0]=e,it[1]=t,it[2]=i,s.init(it,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=tt;let s=t.rootTilesInExtent(e,i,5*he);if(u(this.rootTiles)){if(s.length>he)return void l.getLogger(this.declaredClass).warn(de);const e=this.rootTiles.map((e=>e.lij)),t=r(e,s,Ke);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this.rootTiles.filter((e=>!(t.removed.findIndex((t=>Ke(t,e.lij)))>-1)||(this._purgeTile(e,!0),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>he&&(l.getLogger(this.declaredClass).warn(pe),s=t.rootTilesInExtent(e,i,he)),this._setRootTiles(s.map((e=>this._newRootTile(e))));A(i,this._rootTilesExtent)||(this._rootTilesExtent=j(i)),this._visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._allTiles.forEach((e=>{e.isLoaded&&this._prepareToLoadTile(e)})),this._allTiles.forAll((e=>{e.isLoaded&&(this._updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e))})),this._updatingRootTiles=!1,this.checkAllTileWaterproofness()}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return t.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ae.SPLIT&&t.setPendingUpdate(Ae.SPLIT),this._loadTile(t),this._deferTileNeighborUpdate||t.checkGeometryWaterproofness(),t}_setRootTiles(e){if(this._set("rootTiles",e),this._allTiles.clear(),u(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)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visibleCached&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this.rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Ae.GEOMETRY)&&this._updateTileGeometry(e)}_updateTilesVisibility(e){if(p(e))return;const t=ke(e);let i=t?this._elevationBounds.min:1/0,r=t?this._elevationBounds.max:-1/0;const s=this.extent,a=this._viewProjectionMatrix;this.setTileTreeDirty();const n=this._iteratorPool.acquire();for(n.reset(e);!n.done;){const e=n.next();e.updateClippingStatus(s)&&e.resetPendingUpdate(Ae.GEOMETRY)&&this._updateTileGeometry(e),e.setPendingUpdate(Ae.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(a),e.renderData&&(i=Math.min(e.elevationBounds[0],i),r=Math.max(e.elevationBounds[1],r))}n.remove(),this._viewChanged=!0,this._allTilesDirty=!0,isFinite(i)&&isFinite(r)&&(this._elevationBounds.min===i&&this._elevationBounds.max===r||(this._elevationBounds.min=i,this._elevationBounds.max=r,this.emit("elevation-bounds-change",null)))}_updateViewDependentParameters(){const e=this.view.state.camera,t=this.view.state.contentCamera,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?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=k()),N(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,N(this._frustum,e.frustum),b(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),D(this._eyePosRenderSR,t.eye),P(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(Je(e)?(this._loadChildren(e),this._deferTileNeighborUpdate||(this._checkTileNeighborsWaterproofness(e),e.children.forEach((e=>e.checkGeometryWaterproofness())))):Ze(e)&&this._loadParent(e))}_updateTileGeometry(e){e.updateVisibility(),this._renderer.updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e),this._elevationUpdate(e),this._usedMemory=null,this._deferTileNeighborUpdate&&this._neighborTilesToUpdate.delete(e)}_updateTileNeighborsAfterGeometryChange(e,t){if(this._deferTileNeighborUpdate){const t=this._neighborTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}else e.updateNeighborsAfterGeometryChange(t)}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Ae.TEXTURE_FADING)?Ae.TEXTURE_FADING:!!e.resetPendingUpdate(Ae.TEXTURE_NOFADING)&&Ae.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_elevationUpdate(e){st.spatialReference=this.spatialReference,st.tile=e,st.extent=e.extent,this.emit("elevation-change",st)}get running(){return this.updating&&this.ready&&!this.suspended}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateTileStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),e.run((()=>this._updateElevation(e))),e.run((()=>this._updateTextures(e))),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),e.done?this.requestUpdate():this._usedMemory=this._recalculateUsedMemory(),this.notifyChange("updatingProgressValue")}_updateTileStatus(e){if(!this._viewChanged||!this.rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();for(t.reset(this.rootTiles);!t.done;){const e=t.next(),i=e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping);if(i!==Ae.SPLIT){if(e.resetPendingUpdate(Ae.SPLIT)&&e.updateAgentSuspension(),i===Ae.VSPLITMERGE&&e.updateAgents(re.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(Ae.MERGE),e.resetPendingUpdate(Ae.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(this._viewProjectionMatrix);t.remove()}}else e.resetPendingUpdate(Ae.MERGE),e.isLeaf&&(e.setPendingUpdate(Ae.SPLIT),t.skipSubtree())}t.remove(),this.requestUpdate(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_prepareBatchTileGeometryUpdate(){fe(0===this._neighborTilesToUpdate.size),this.enableBatchTileGeometryUpdates&&(this._deferTileNeighborUpdate=!0)}_batchUpdateUpdatedTileNeighbors(){if(this.enableBatchTileGeometryUpdates){this._deferTileNeighborUpdate=!1;const e=this._neighborTilesToUpdate;(()=>{const t=()=>{for(const t of e)t.updateNeighborsWithChangedEdgeResolution()};(()=>{for(const t of e)t.updateNeighborDataAndGeometryIfNeeded()})(),t(),e.clear()})()}}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate(),this._prepareBatchTileGeometryUpdate();let i=!1,r=!1;for(;!e.done;){r=!0;let s=!1;const a=!this._allTiles.some((r=>{if(!i&&!r.loadable)return e.done;let a=r;if(r.resetPendingUpdate(Ae.MERGE)){if(!t)return r.setPendingUpdate(Ae.MERGE),e.done;for(;a.parent?.resetPendingUpdate(Ae.MERGE);)a=a.parent;this._mergeTile(a),s=!0,e.madeProgress()}else r.resetPendingUpdate(Ae.SPLIT)&&(this._splitTile(r),s=!0,e.madeProgress());return!e.done&&a===r&&r.resetPendingUpdate(Ae.RENDERDATA)&&(this._updateRenderData(r),e.madeProgress()),e.done}));if(s&&(this._allTilesSorted=!1,this._allTilesDirty=!0),a){if(!i){i=!0;continue}if(!s)break;this._updateTilesVisibility(this.rootTiles)}else this._allTilesDirty=!0}r||(this._allTilesDirty=!0),this._batchUpdateUpdatedTileNeighbors(),this._sortTiles(e)}_updateElevation(e){return this._prepareBatchTileGeometryUpdate(),this._allTiles.some((t=>(t.resetPendingUpdate(Ae.GEOMETRY)&&(this._updateTileGeometry(t),this._updateTileTexture(t,e),e.madeProgress()),e.done))),this._batchUpdateUpdatedTileNeighbors(),e.hasProgressed}_updateTextures(e){return this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done))),e.hasProgressed}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(Fe.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ue}_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(){u(this.rootTiles)&&(this.rootTiles.forEach((e=>this._purgeTile(e,!1))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this._visible=!1}_purgeDescendantTiles(e){if(e.isLeaf)return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i],!1)||t;return e.unsetChildren(),t}_purgeTile(e,t){const i=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),t&&this._updateTileNeighborsAfterGeometryChange(e),this._tilePool.release(e),i}_unloadTile(e){this._deferTileNeighborUpdate&&this._neighborTilesToUpdate.delete(e),e.unload(this._renderer)}_splitTile(e){me(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(Ae.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){at.spatialReference=this.spatialReference,at.extent=e.extent,at.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",at)}_createTile(e,t,i,r){me(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),s.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ae.SPLIT&&s.setPendingUpdate(Ae.SPLIT),s}_mergeTile(e){me(!e.hasPendingUpdate(Ae.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(me(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._updateTileNeighborsAfterGeometryChange(e),this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(e),this._emitTileScaleChange(e)),this._allTilesDirty=!0,++this._performanceInfo.numMerged}_checkTileAndNeighborsWaterproofness(e){e.checkGeometryWaterproofness(),this._checkTileNeighborsWaterproofness(e)}_checkTileNeighborsWaterproofness(e){xe&&e.forallNeighbors((e=>!!e.isLoaded&&(e.checkGeometryWaterproofness(),!0)))}_loadChildren(e){this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(e),me(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._prepareToLoadTile(e))),t.forEach((e=>this._loadTilePrepared(e))),this._updateTileNeighborsAfterGeometryChange(e,e.level+1),this._deferTileNeighborUpdate||(t.forEach((e=>e.updateNeighborsWithChangedEdgeResolution())),t.forEach((e=>e.checkGeometryWaterproofness())),this._checkTileNeighborsWaterproofness(e)),this._emitTileScaleChange(e,e.level+1)}_loadParent(e){this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(e);const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._updateTileNeighborsAfterGeometryChange(t),this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(t),this._emitTileScaleChange(t,t.level)}_unloadChildren(e){if(!e.isLeaf)for(let t=0;t<4;++t){const i=e.children[t];this._unloadChildren(i),this._unloadTile(i)}}_postLoadTile(e){e.setPendingUpdate(Ae.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e),this._elevationUpdate(e)}_loadTile(e){e.load(this._renderer),this._postLoadTile(e)}_loadTilePrepared(e){e.loadPrepared(this._renderer),this._postLoadTile(e)}_prepareToLoadTile(e){e.prepareToLoad(this._renderer)}_elevationDataArrived(e,t,i){const r=new Z(e.lij,e.extent,i);e.dataArrived(t,re.ELEVATION,r);const s=[e],a=e.level,n=this._iteratorPool.acquire();for(n.reset(s);!n.done;){const e=n.next();e.findElevationBoundsForLayer(t,a),e.computeElevationBounds()}n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=Xe){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),Te(s))if(this._basemapLayerViewHandles.has(s.uid)){const e=this._layerClassFromLayerView(s),i=this._getLayerIdxByUID(e,s.uid);u(i)&&((i<r||p(r))&&(t=!0),r=i)}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this._renderer.isTransparent=this._allSurfaceLayersTransparent(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(ye(t)&&!G(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if(ve(e)){const t=we(e.layer.parent)?"normal":e.layer.blendMode;if(Ge(We[t]))return!0}return!1}_layerClassFromLayerView(e){return Le(e)?re.ELEVATION:re.MAP}_registerTiledLayerView(e){const t=[],i=this._layerClassFromLayerView(e);t.push(T((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(T((()=>e.fullOpacity),(()=>this._updateTileTextures(ie.UNFADED)))),t.push(T((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),ve(e)&&t.push(T((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(ie.UNFADED)}))),e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);u(t)&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)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||!Te(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===re.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of se){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()}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this.rootTiles);!t.done;){const i=t.next();i.restartAgents(e),e===re.ELEVATION&&i.computeElevationBounds()}}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(re.MAP),e===ie.IMMEDIATE?this.renderer.updateTileTexture(t,Ae.TEXTURE_NOFADING):t.updateRenderData(re.MAP,e)})),this._renderer.isTransparent=this._allSurfaceLayersTransparent()}_invalidateLayerData(e,t){this._allTiles.forAll((i=>i.removeLayerAgent(e,t))),this._allTiles.forAll((i=>i.invalidateLayerData(e,t)))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=Fe.UPDATE){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||Se(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,g(t)||this._dataMissing(e,i,s,{notInTilemap:!0}),t})).then((()=>this._frameTask.schedule((()=>this._requestTileData(e,i,s,r)),r.signal))))}_requestTileData(e,t,i,r){return t===re.ELEVATION?Le(i)?this._requestElevationTileData(e,i,r):Promise.reject():ye(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(m(i))return;const s=this._layerIndexByUid[re.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer %d %s",re.ELEVATION,e.lij.toString())},s=i=>{g(i)||(this._dataMissing(e,re.ELEVATION,t,i),this.requestUpdate())};if(be(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:ce,signal:i.signal}).then((e=>{if(!m(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true.")}),s).finally((()=>{--this._asyncWorkItems}));const a=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);return this._elevationDataRequester.request(a,"binary",i).then((e=>this._lercDecoder.decode(e,{noDataValue:ce},i.signal))).then((e=>{e?r({values:e.pixelData,width:e.width,height:e.height,noDataValue:e.noDataValue,minValue:e.minValue,maxValue:e.maxValue}):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Ce(s),m(i)||(this._dataMissing(e,re.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),m(i)?Ce(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(Se(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(Ee(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(De(t)&&be(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(m(i))return l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(f());a(e)}),n);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);B(t.layer)&&t.layer.refreshTimestamp&&(o+=`${o.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const h=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(o,h,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(re.MAP,t.uid);u(r)?e.dataArrived(r,re.MAP,i):(Ce(i),l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer"))}_getLayerIdxByUID(e,t){return this._layerIndexByUid[e].get(t)}_dataMissing(e,t,i,r){const s=this._getLayerIdxByUID(t,i.uid);u(s)?e.dataMissing(s,t,r):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this.rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}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.isLeaf&&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}getUsedMemory(){return this.tilingScheme?(p(this._usedMemory)&&(this._usedMemory=this._recalculateUsedMemory()),u(this._usedMemory)?this._usedMemory:0):0}_recalculateUsedMemory(){return this.tilingScheme?this._allTiles.reduce(((e,t)=>e+t.usedMemory),0):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._getLayerIdxByUID(i,e.uid);return u(r)&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this.rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this.rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this.rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return me(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}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(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e.rootTiles)&&(e._mergeTile(e.rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){rt.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&rt.push(e)}));const t=rt.toArray();return Oe(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTileWaterproofness(){if(!xe)return;const e=this.rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.indices?.length>0??!1,i=(e,i)=>{t(e)&&console.error("Tile[",e.lij,"] has geometry although parent[",i.lij,"] has geom")},r=e=>{if(e.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)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.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get shadingEnabled(){return this._renderer.shadingEnabled}get isWebMercator(){return!!this.tilingScheme?.spatialReference.isWebMercator}get isWebMercatorOnPlateeCarree(){return this.isWebMercator&&O(this.view?.renderSpatialReference)}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(u(this.spatialReference)&&this.spatialReference.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){Pe(e)}};e([L()],Ye.prototype,"_renderer",void 0),e([L()],Ye.prototype,"_hasPendingUpdates",void 0),e([L()],Ye.prototype,"_asyncWorkItems",void 0),e([L()],Ye.prototype,"_allTilesDirty",void 0),e([L()],Ye.prototype,"_allTilesSorted",void 0),e([L()],Ye.prototype,"_viewChanged",void 0),e([L({readOnly:!0})],Ye.prototype,"_watchUpdatingTracking",void 0),e([L()],Ye.prototype,"_frameTask",void 0),e([L({readOnly:!0})],Ye.prototype,"snapLevel",null),e([L({readOnly:!0})],Ye.prototype,"lodSnapping",null),e([L({constructOnly:!0})],Ye.prototype,"view",void 0),e([L()],Ye.prototype,"_userClippingExtent",null),e([L()],Ye.prototype,"_rootTilesExtent",void 0),e([L({readOnly:!0})],Ye.prototype,"extent",null),e([L({readOnly:!0})],Ye.prototype,"groundExtent",null),e([L({readOnly:!0})],Ye.prototype,"_tilingSchemeExtent",null),e([L({readOnly:!0})],Ye.prototype,"updating",null),e([L($)],Ye.prototype,"updatingProgress",void 0),e([L({readOnly:!0})],Ye.prototype,"updatingProgressValue",null),e([L()],Ye.prototype,"_maxNumUpdating",void 0),e([L()],Ye.prototype,"baseOpacity",null),e([L()],Ye.prototype,"hasCompositeBlendMode",void 0),e([L({readOnly:!0})],Ye.prototype,"overlayManager",void 0),e([L({readOnly:!0})],Ye.prototype,"viewingMode",null),e([L()],Ye.prototype,"maxTextureScale",void 0),e([L({readOnly:!0})],Ye.prototype,"ready",null),e([L({value:le.FRONT_TO_BACK})],Ye.prototype,"renderOrder",null),e([L({readOnly:!0})],Ye.prototype,"rootTiles",void 0),e([L({readOnly:!0})],Ye.prototype,"spatialReference",null),e([L({type:t})],Ye.prototype,"backgroundColor",null),e([L({value:!1})],Ye.prototype,"slicePlaneEnabled",null),e([L({readOnly:!0})],Ye.prototype,"tilingScheme",void 0),e([L({readOnly:!0})],Ye.prototype,"tilingSchemeLocked",null),e([L({readOnly:!0})],Ye.prototype,"tilingSchemeLogic",void 0),e([L({value:!0})],Ye.prototype,"velvetOverground",null),e([L()],Ye.prototype,"wireframe",null),e([L({value:!1})],Ye.prototype,"suspended",null),e([L()],Ye.prototype,"textureFadeDuration",null),e([L()],Ye.prototype,"_layerViewsDirty",void 0),e([L()],Ye.prototype,"renderPatchBorders",null),e([L()],Ye.prototype,"renderingDisabled",null),Ye=e([S("esri.views.3d.terrain.TerrainSurface")],Ye);const $e=Ye;function Ke(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function Je(e){return!e.isLeaf&&(e.children.some((e=>e.shouldLoad))||e.children.some((e=>Je(e))))}function Ze(e){return e.isLeaf&&e.parent&&e.parent.shouldLoad}const et=x(),tt=j(),it=[0,0,0],rt=new _,st={spatialReference:null,tile:null,extent:null,context:"ground"},at={spatialReference:null,extent:null,scale:0};export{$e as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Color.js";import i from"../../../core/Accessor.js";import{difference as r}from"../../../core/arrayUtils.js";import s from"../../../core/CollectionFlattener.js";import a from"../../../core/Evented.js";import n from"../../../core/Handles.js";import l from"../../../core/Logger.js";import{clamp as o}from"../../../core/mathUtils.js";import{releaseMaybe as h,destroyMaybe as d,isNone as p,isSome as u}from"../../../core/maybe.js";import c from"../../../core/ObjectPool.js";import _ from"../../../core/PooledArray.js";import{isAbortError as g,isAborted as m,createAbortError as f}from"../../../core/promiseUtils.js";import{watch as T,syncAndInitial as y,sync as v,initial as w}from"../../../core/reactiveUtils.js";import{property as L}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import{m as b}from"../../../chunks/mat4.js";import{c as E}from"../../../chunks/mat4f64.js";import{c as D}from"../../../chunks/vec3.js";import{c as C}from"../../../chunks/vec3f64.js";import{c as x}from"../../../chunks/vec4f64.js";import{WatchUpdatingTracking as U}from"../../../core/support/WatchUpdatingTracking.js";import{projectVectorToVector as P,projectPointToVector as R}from"../../../geometry/projection.js";import{getReferenceEllipsoid as M}from"../../../geometry/projectionEllipsoid.js";import{create as j,equals as A,intersection as I,intersectsSphere as V}from"../../../geometry/support/aaBoundingRect.js";import{create as k,copy as N}from"../../../geometry/support/frustum.js";import{isPlateCarree as O}from"../../../geometry/support/spatialReferenceUtils.js";import{isRefreshableLayer as B}from"../../../layers/mixins/RefreshableLayer.js";import{ElevationQueryTileCache as q}from"../../../layers/support/ElevationQueryTileCache.js";import{isBaseLayer as G}from"../../../layers/support/layerUtils.js";import{acquireDecoder as W}from"../../../layers/support/LercDecoder.js";import{printAllocations as F}from"../../2d/engine/vectorTiles/VectorTile.js";import{directionToHeadingTilt as H,scaleToZoom as Q}from"../support/cameraUtils.js";import X from"../support/debugFlags.js";import{toBoundingRect as z}from"../support/extentUtils.js";import{ClientType as Y}from"../support/index.js";import{updatingProgress as $}from"../support/updatingProperties.js";import{ElevationBounds as K}from"./ElevationBounds.js";import{sampleElevation as J,ElevationData as Z}from"./ElevationData.js";import{create as ee}from"./ExtentHelper.js";import{LODSnapping as te,TextureUpdate as ie}from"./interfaces.js";import{LayerClass as re,LayerClasses as se}from"./LayerClass.js";import{OverlayManager as ae}from"./OverlayManager.js";import{PlanarPatch as ne}from"./PlanarPatch.js";import{RenderOrder as le}from"./RenderOrder.js";import{SphericalPatch as oe}from"./SphericalPatch.js";import{MAX_ROOT_TILES as he,TOO_MANY_ROOT_TILES_AFTER_CHANGE_ERROR as de,TOO_MANY_ROOT_TILES_FOR_LAYER_ERROR as pe,MAX_MEMORY_LOD_BIAS as ue,ELEVATION_NODATA_VALUE as ce}from"./TerrainConst.js";import _e from"./TerrainRenderer.js";import ge from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as me,internalAssert as fe,isSurfaceLayerView as Te,isMapTileLayerView as ye,isBlendableLayerView as ve,isGroupLayer as we,isElevationLayerView as Le,isVectorTileLayerView as Se,useFetchTileForLayer as be,isImageryTileLayerView as Ee,isTileLayerView as De,releaseTileData as Ce,ENABLE_WATERPROOFNESS_TESTS as xe,enableTerrainInternalChecks as Ue,enableTerrainWaterproofnessChecks as Pe}from"./terrainUtils.js";import{SplitLimits as Re,Tile as Me}from"./Tile.js";import{printAllocations as je}from"./TilePerLayerInfo.js";import{TileUpdate as Ae}from"./TileUpdate.js";import{IteratorPreorder as Ie,IteratorPostorder as Ve,hasLoadableSiblings as ke,sortTilesByPOI as Ne,sortTiles as Oe}from"./tileUtils.js";import{TilingSchemeLogic as Be}from"./TilingSchemeLogic.js";import{UpsampleInfo as qe}from"./UpsampleInfo.js";import{isCompositeBlendMode as Ge,blendModeFromString as We}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{RenderRequestType as Fe}from"../webgl-engine/lib/basicInterfaces.js";import{ImmediateTask as He,TaskPriority as Qe,noBudget as Xe}from"../../support/Scheduler.js";const ze=.25;let Ye=class extends(a.EventedMixin(i)){constructor(e){super(e),this._elevationBounds=new K,this._iteratorPool=new c(Ie,(e=>e.remove=()=>this._iteratorPool.release(e))),this._postorderIterator=new Ve,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._visibleCached=!1,this._usedMemory=null,this._performanceInfo=new ge,this._viewChanged=!1,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=C(),this._eyePosSurfaceSR=C(),this._splitLimits=new Re,this._snapLevel=1/0,this._frustum=k(),this._viewProjectionMatrix=E(),this._layerViews=[new Array,new Array],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._handles=new n,this._watchUpdatingTracking=new U,this._frameTask=He,this._allTiles=new _,this._upsampleInfoPool=new c(qe),this._rootTilesExtent=j(),this._maxNumUpdating=1,this.maxTextureScale=1.2,this._updatingRootTiles=!1,this._deferTileNeighborUpdate=!1,this._neighborTilesToUpdate=new Set,this.enableBatchTileGeometryUpdates=!0,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this._isGlobal=!e.view?.state?.isLocal}initialize(){this._lercDecoder=W(this.view.resourceController),this._tilePool=this.view.state.isLocal?new c(ne):new c(oe);const e=this.view.resourceController.memoryController;this._upsampleMapCache=e.newCache("esri.views.3d.terrain.upsample",(e=>e.unloadMapData())),this._elevationQueryCache=new q(e.newCache("elevation-query")),this._set("overlayManager",new ae({surface:this})),this._handles.add([T((()=>this.overlayManager.hasHighlights),(e=>this._renderer.setNeedsHighlight(e))),T((()=>this.overlayManager.rendersOccluded),(e=>this._renderer.setRenderOccludedOverlay(e)))],"overlayManager"),this._renderer=new _e({_overlayRenderer:this.overlayManager.renderer,_ellipsoidRadius:M(this.view.spatialReference).radius,_stage:this.view._stage,_allTiles:this._allTiles}),this._handles.add([T((()=>this.baseOpacity),(e=>{this._handleLayerViewChanges(),this._updateBaseOpacity(e)}),y),T((()=>this.hasCompositeBlendMode),(()=>{this._updateBaseOpacity(this.baseOpacity)}),y),T((()=>this.renderingDisabled),(()=>this._updateTransparentTerrain()),v),T((()=>this.backgroundColor),(e=>{this._handleLayerViewChanges(),this._renderer.updateTileBackground(e)}),y),T((()=>this.view.pointsOfInterest),(e=>{this._renderer.pointsOfInterest=e,this._watchUpdatingTracking.removeAll(),e&&this._watchUpdatingTracking.add((()=>e.focus.renderLocation),(()=>()=>this._allTilesSorted=!1))})),T((()=>X.TERRAIN_TILE_TREE_SHOW_TILES),(e=>{e&&!this._treeDebugger?import("../layers/support/TerrainTileTree3DDebugger.js").then((({TerrainTileTree3DDebugger:e})=>{!this._treeDebugger&&X.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new e({view:this.view}))})):e||(this._treeDebugger=d(this._treeDebugger))}),w)]),this._extentHelper=ee(this.viewingMode,{layers:this.view.map.allLayers,layerViews:this.view.allLayerViews,viewSpatialReference:this.view.spatialReference});const t=this.view.defaultsFromMap?new s({getCollections:()=>this.view?.defaultsFromMap?.mapCollections?.map((({layers:e})=>e)),getChildrenFunction:e=>e&&"layers"in e?e.layers:null}):this.view.map.allLayers,i=new Be({layers:t,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:this.view.spatialReference});this._set("tilingSchemeLogic",i),this._updateTilingScheme(),this._elevationDataRequester=this.view.resourceController.createStreamDataRequester(Y.ELEVATION),this._mapDataRequester=this.view.resourceController.createStreamDataRequester(Y.BASEMAP);const r=this.view.resourceController.scheduler;this._frameTask=r.registerTask(Qe.TERRAIN_SURFACE,this),this._handles.add([T((()=>this._extentHelper.stencilEnabledExtents),(e=>this._renderer.setStencilEnabledLayerExtents(e)),w),T((()=>this.tilingSchemeLogic.tilingScheme),(()=>this._updateTilingScheme()),v),T((()=>this.extent),(()=>this._updateRootTiles()),w),this.view.on("resize",(()=>this._viewChangeUpdate())),T((()=>{const e=this.view,t=e.state;return[this._lodBias,this.lodSnapping,e.resourceController?.memoryController?.memoryFactor,t.camera,t.contentCamera,t.fixedContentCamera]}),(()=>this._viewChangeUpdate()),y),T((()=>this.view.qualitySettings?.tiledSurface?.textureFadeDuration),(e=>this._renderer.textureFadingEnabled=e>0),w),T((()=>this._userClippingExtent),(()=>this._updateClippingExtent()),v)]),this._handles.add(this.view.allLayerViews.on("after-changes",(()=>this._layerViewsDirty=!0))),this._layerViewsDirty=!0,this._handleLayerViewChanges()}destroy(){this._frameTask.remove(),this._handles.destroy(),this._watchUpdatingTracking.destroy(),this._lercDecoder=h(this._lercDecoder),this._removeAllTiles(),this._upsampleMapCache=d(this._upsampleMapCache),this._elevationQueryCache=d(this._elevationQueryCache),this._set("tilingSchemeLogic",d(this.tilingSchemeLogic)),this._extentHelper=d(this._extentHelper),this._basemapLayerViewHandles.forEach(((e,t)=>this._unregisterTiledLayerView(t))),this._elevationDataRequester=null,this._mapDataRequester=null,this._set("overlayManager",d(this.overlayManager)),this._tilePool=d(this._tilePool),Me.prune(),this._treeDebugger&&(this._treeDebugger.destroy(),this._treeDebugger=null),this._renderer=d(this._renderer),this._iteratorPool=d(this._iteratorPool),this._set("view",null),this._upsampleInfoPool=d(this._upsampleInfoPool),F(),je()}get renderer(){return this._renderer}get frustum(){return this._frustum}get snapLevel(){const e=this.view.pointsOfInterest?.contentCameraOnSurface?.scale;if(e){const t=this.view.state.contentCamera;let i=H(this.view,t.eye,t.viewForward,t.up).tilt;i>90&&(i=180-i);const r=2*(i/90)**2,s=Q(this.view,e)-r;Math.abs(this._snapLevel-s)>ze&&(Math.round(s)!==Math.round(this._snapLevel)&&(this._viewChanged=!0),this._snapLevel=s)}return Math.round(this._snapLevel)}get lodSnapping(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences?te.ON:te.OFF}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get mapTileRequester(){return this._mapDataRequester}get _userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(p(t)||p(e))return null;const i=j(),r=z(t,i,e)?i:null,s=this._get("extent");return A(r,s)?s:r}get rootTilesExtent(){return this._rootTilesExtent}get extent(){const e=I(this.groundExtent,this._userClippingExtent,j()),t=this._get("extent");return A(e,t)?t:e}get groundExtent(){return u(this._tilingSchemeExtent)?this._tilingSchemeExtent:this._rootTilesExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),!!((this._watchUpdatingTracking.updating||this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||this._asyncWorkItems>0||!this._allTilesSorted||this._layerViewsDirty)&&this.ready&&!this.suspended||this.overlayManager.updating||this._frameTask.updating)}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view.map.ground.opacity}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return u(this.rootTiles)}set renderOrder(e){this._renderer.renderOrder=e,this._set("renderOrder",e)}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._updateTransparentTerrain()}_updateTransparentTerrain(){const e=!this.renderingDisabled&&!this.opaque;this.view?._stage?.renderView.setRenderParameters({transparentTerrain:e})}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}set velvetOverground(e){e!==this.velvetOverground&&(this._renderer.velvetOverground=e),this._set("velvetOverground",e)}get wireframe(){return this._renderer.wireframe}set wireframe(e){this._renderer.wireframe=e}set _visible(e){e!==this._visibleCached&&(this._visibleCached=e,this._renderer.setVisibility(e),this.suspended=!e)}get opaque(){return this._renderer.opaque}set suspended(e){this._set("suspended",e),this._viewChangeUpdate()}get textureFadeDuration(){return this.view.qualitySettings.tiledSurface.textureFadeDuration??0}intersect(e,t,i,r){this._renderer.intersect(e,t,i,r)}getElevation(e,t,i,r){const s=this.getTileWithElevation(e,t,i,r,et);return p(s)?null:J(et[0],et[1],s.renderData.geometryState.samplerData)}getTileWithElevation(e,t,i,r,s=et){const a=this.rootTiles;if(p(a)||!a.length)return null;if(0===a[0].layerInfo[re.ELEVATION].length)return null;if(s[0]=e,s[1]=t,s[2]=i,!P(s,r,s,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system"),null;for(let n of a){if(!n.containsPoint(s))continue;for(;n&&!n.rendered&&!n.isLeaf;){let e=0;s[0]>.5*(n.extent[0]+n.extent[2])&&(e+=1),s[1]<.5*(n.extent[1]+n.extent[3])&&(e+=2),n=n.children[e]}const e=n.renderData;return(e?e.geometryState.samplerData:null)?n:null}return null}get elevationBounds(){return this._elevationBounds}getScale(e){if(this.tilingScheme){if(!R(e,et,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system"),null;const t=this.rootTiles;if(u(t))for(let e of t)if(e?.containsPoint(et)){for(;!e.isLeaf&&!e.rendered;){let t=0;et[0]>e.children[0].extent[2]&&(t+=1),et[1]<e.children[0].extent[1]&&(t+=2),e=e.children[t]}return this._getLodBiasCorrectedScale(e.level)}}return 1e100}getSphereElevationBounds(e,t,i,r,s){if(et[0]=e,et[1]=t,et[2]=i,et[3]=r,!P(et,s,et,this.tilingScheme?.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereElevationBounds(): could not project given point to tiling scheme coordinate system"),null;let a=1/0,n=-1/0;const o=e=>{if(e&&V(e.extent,et))if(e.isLeaf||e.rendered)a=Math.min(a,e.elevationBounds[0]),n=Math.max(n,e.elevationBounds[1]);else for(const t of e.children)o(t)},h=this.rootTiles;if(u(h))for(const l of h)o(l);return{min:a,max:n}}getSphereScale(e,t){if(!this.tilingScheme)return null;if(!R(e,et,this.spatialReference))return l.getLogger(this.declaredClass).error("TerrainSurface.getSphereScale(): could not project given point to tiling scheme coordinate system"),null;et[3]=t;let i=null;const r=e=>{if(e&&V(e.extent,et))if(e.isLeaf||e.rendered){const t=this._getLodBiasCorrectedScale(e.level);i=null==i?t:Math.min(i,t)}else for(const t of e.children)r(t)},s=this.rootTiles;if(u(s))for(const a of s)r(a);return i}queryVisibleScaleRange(e,t,i,r){const s=t?this.tilingScheme.levelAtScale(t):0,a=i?this.tilingScheme.levelAtScale(i):1/0,n=this._lodBias;this._renderer.queryVisibleLevelRange(e,s+n,a+n,r)}_updateBaseOpacity(e){const t=this._renderer.opaque;this._renderer.opaque=e>=1&&!this.hasCompositeBlendMode,this._renderer.isTransparent=this._allSurfaceLayersTransparent();const i=t!==this._renderer.opaque;i&&this._updateTransparentTerrain(),this._updateTileTextures(i?ie.UNFADED:ie.IMMEDIATE)}_updateTilingScheme(){const e=this.tilingSchemeLogic.tilingScheme;e!==this.tilingScheme&&(me(!!e,"tiling scheme cannot be reset to undefined"),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles(),this._set("tilingScheme",e),this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.setTileSize(e.pixelSize),this.overlayManager.setSpatialReference(e.spatialReference),this._updateRootTiles()))}_acquireTile(e,t,i,r){const s=this._tilePool.acquire();return it[0]=e,it[1]=t,it[2]=i,s.init(it,r,this),s}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){const{extent:e,tilingScheme:t}=this;if(!t)return;const i=tt;let s=t.rootTilesInExtent(e,i,5*he);if(u(this.rootTiles)){if(s.length>he)return void l.getLogger(this.declaredClass).warn(de);const e=this.rootTiles.map((e=>e.lij)),t=r(e,s,Ke);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){const e=this.rootTiles.filter((e=>!(t.removed.findIndex((t=>Ke(t,e.lij)))>-1)||(this._purgeTile(e,!0),!1)));t.added.forEach((t=>e.push(this._newRootTile(t)))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,s.length>he&&(l.getLogger(this.declaredClass).warn(pe),s=t.rootTilesInExtent(e,i,he)),this._setRootTiles(s.map((e=>this._newRootTile(e))));A(i,this._rootTilesExtent)||(this._rootTilesExtent=j(i)),this._visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange("ready"),this._allTiles.forEach((e=>{e.isLoaded&&this._prepareToLoadTile(e)})),this._allTiles.forAll((e=>{e.isLoaded&&(this._updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e))})),this._updatingRootTiles=!1,this.checkAllTileWaterproofness()}_newRootTile(e){const t=this._acquireTile(0,e[1],e[2],null);return t.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ae.SPLIT&&t.setPendingUpdate(Ae.SPLIT),this._loadTile(t),this._deferTileNeighborUpdate||t.checkGeometryWaterproofness(),t}_setRootTiles(e){if(this._set("rootTiles",e),this._allTiles.clear(),u(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)}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.suspended&&this.tilingScheme&&this._visibleCached&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this.rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.extent)&&e.resetPendingUpdate(Ae.GEOMETRY)&&this._updateTileGeometry(e)}_updateTilesVisibility(e){if(p(e))return;const t=ke(e);let i=t?this._elevationBounds.min:1/0,r=t?this._elevationBounds.max:-1/0;const s=this.extent,a=this._viewProjectionMatrix;this.setTileTreeDirty();const n=this._iteratorPool.acquire();for(n.reset(e);!n.done;){const e=n.next();e.updateClippingStatus(s)&&e.resetPendingUpdate(Ae.GEOMETRY)&&this._updateTileGeometry(e),e.setPendingUpdate(Ae.RENDERDATA),e.computeVisibility(),e.updateScreenDepth(a),e.renderData&&(i=Math.min(e.elevationBounds[0],i),r=Math.max(e.elevationBounds[1],r))}n.remove(),this._viewChanged=!0,this._allTilesDirty=!0,isFinite(i)&&isFinite(r)&&(this._elevationBounds.min===i&&this._elevationBounds.max===r||(this._elevationBounds.min=i,this._elevationBounds.max=r,this.emit("elevation-bounds-change",null)))}_updateViewDependentParameters(){const e=this.view.state.camera,t=this.view.state.contentCamera,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?(p(this._splitLimits.frustum)&&(this._splitLimits.frustum=k()),N(this._splitLimits.frustum,t.frustum)):this._splitLimits.frustum=null,N(this._frustum,e.frustum),b(this._viewProjectionMatrix,t.projectionMatrix,t.viewMatrix),D(this._eyePosRenderSR,t.eye),P(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateRenderData(e){e.rendered&&!e.shouldLoad&&(Je(e)?(this._loadChildren(e),this._deferTileNeighborUpdate||(this._checkTileNeighborsWaterproofness(e),e.children.forEach((e=>e.checkGeometryWaterproofness())))):Ze(e)&&this._loadParent(e))}_updateTileGeometry(e){e.updateVisibility(),this._renderer.updateTileGeometry(e),this._updateTileNeighborsAfterGeometryChange(e),this._elevationUpdate(e),this._usedMemory=null,this._deferTileNeighborUpdate&&this._neighborTilesToUpdate.delete(e)}_updateTileNeighborsAfterGeometryChange(e,t){if(this._deferTileNeighborUpdate){const t=this._neighborTilesToUpdate;e.forEachLoadedNeighbor((e=>{t.add(e)}))}else e.updateNeighborsAfterGeometryChange(t)}_updateTileTexture(e,t){const i=e.resetPendingUpdate(Ae.TEXTURE_FADING)?Ae.TEXTURE_FADING:!!e.resetPendingUpdate(Ae.TEXTURE_NOFADING)&&Ae.TEXTURE_NOFADING;i&&(this._renderer.updateTileTexture(e,i),this._usedMemory=null,t.madeProgress())}_elevationUpdate(e){st.spatialReference=this.spatialReference,st.tile=e,st.extent=e.extent,this.emit("elevation-change",st)}get running(){return this.updating&&this.ready&&!this.suspended}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateTileStatus(e),this._sortTiles(e);const t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),e.run((()=>this._updateElevation(e))),e.run((()=>this._updateTextures(e))),t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty(),e.done?this.requestUpdate():this._usedMemory=this._recalculateUsedMemory(),this.notifyChange("updatingProgressValue")}_updateTileStatus(e){if(!this._viewChanged||!this.rootTiles||e.done)return;this._viewChanged=!1;const t=this._iteratorPool.acquire();for(t.reset(this.rootTiles);!t.done;){const e=t.next(),i=e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping);if(i!==Ae.SPLIT){if(e.resetPendingUpdate(Ae.SPLIT)&&e.updateAgentSuspension(),i===Ae.VSPLITMERGE&&e.updateAgents(re.ELEVATION),t.skipSubtree(),!e.isLeaf){e.setPendingUpdate(Ae.MERGE),e.resetPendingUpdate(Ae.SPLIT);const t=this._iteratorPool.acquire();t.resetOne(e);for(let e=t.next();!t.done;e=t.next())this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(this._viewProjectionMatrix);t.remove()}}else e.resetPendingUpdate(Ae.MERGE),e.isLeaf&&(e.setPendingUpdate(Ae.SPLIT),t.skipSubtree())}t.remove(),this.requestUpdate(),e.madeProgress()}_sortTiles(e){e.done||this._allTilesSorted||(Ne(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger&&this._treeDebugger.update(),e.madeProgress())}_prepareBatchTileGeometryUpdate(){fe(0===this._neighborTilesToUpdate.size),this.enableBatchTileGeometryUpdates&&(this._deferTileNeighborUpdate=!0)}_batchUpdateUpdatedTileNeighbors(){if(this.enableBatchTileGeometryUpdates){this._deferTileNeighborUpdate=!1;const e=this._neighborTilesToUpdate;(()=>{const t=()=>{for(const t of e)t.updateNeighborsWithChangedEdgeResolution()};(()=>{for(const t of e)t.updateNeighborDataAndGeometryIfNeeded()})(),t(),e.clear()})()}}_mergeAndSplit(e,t){if(this.suspended||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate(),this._prepareBatchTileGeometryUpdate();let i=!1,r=!1;for(;!e.done;){r=!0;let s=!1;const a=!this._allTiles.some((r=>{if(!i&&!r.loadable)return e.done;let a=r;if(r.resetPendingUpdate(Ae.MERGE)){if(!t)return r.setPendingUpdate(Ae.MERGE),e.done;for(;a.parent?.resetPendingUpdate(Ae.MERGE);)a=a.parent;this._mergeTile(a),s=!0,e.madeProgress()}else r.resetPendingUpdate(Ae.SPLIT)&&(this._splitTile(r),s=!0,e.madeProgress());return!e.done&&a===r&&r.resetPendingUpdate(Ae.RENDERDATA)&&(this._updateRenderData(r),e.madeProgress()),e.done}));if(s&&(this._allTilesSorted=!1,this._allTilesDirty=!0),a){if(!i){i=!0;continue}if(!s)break;this._updateTilesVisibility(this.rootTiles)}else this._allTilesDirty=!0}r||(this._allTilesDirty=!0),this._batchUpdateUpdatedTileNeighbors(),this._sortTiles(e)}_updateElevation(e){return this._prepareBatchTileGeometryUpdate(),this._allTiles.some((t=>(t.resetPendingUpdate(Ae.GEOMETRY)&&(this._updateTileGeometry(t),this._updateTileTexture(t,e),e.madeProgress()),e.done))),this._batchUpdateUpdatedTileNeighbors(),e.hasProgressed}_updateTextures(e){return this._allTiles.some((t=>(this._updateTileTexture(t,e),e.done))),e.hasProgressed}_updateClippingExtent(){this.spatialReference&&(this.updateTileOverlayParams(Fe.UPDATE),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){const e=this.view.resourceController.memoryController.memoryFactor;return this.view.qualitySettings.tiledSurface.lodBias-(1-e)*ue}_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(){u(this.rootTiles)&&(this.rootTiles.forEach((e=>this._purgeTile(e,!1))),this._setRootTiles(null),this.notifyChange("ready")),this._allTiles.clear(),this._visible=!1}_purgeDescendantTiles(e){if(e.isLeaf)return!1;let t=!1;for(let i=0;i<4;++i)t=this._purgeTile(e.children[i],!1)||t;return e.unsetChildren(),t}_purgeTile(e,t){const i=this._purgeDescendantTiles(e)||e.rendered;return this._allTiles.removeUnordered(e),this._unloadTile(e),t&&this._updateTileNeighborsAfterGeometryChange(e),this._tilePool.release(e),i}_unloadTile(e){this._deferTileNeighborUpdate&&this._neighborTilesToUpdate.delete(e),e.unload(this._renderer)}_splitTile(e){me(e.isLeaf,"tile that is already split should not be split again!");const t=e.level+1,i=2*e.lij[1],r=2*e.lij[2];e.setChildren(this._createTile(t,i,r,e),this._createTile(t,i,r+1,e),this._createTile(t,i+1,r,e),this._createTile(t,i+1,r+1,e)),e.setPendingUpdate(Ae.RENDERDATA),e.updateAgentSuspension(),this._allTiles.pushArray(e.children),this._allTilesDirty=!0,++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){at.spatialReference=this.spatialReference,at.extent=e.extent,at.scale=this._getLodBiasCorrectedScale(t),this.emit("scale-change",at)}_createTile(e,t,i,r){me(!!r,"_createTile sanity check");const s=this._acquireTile(e,t,i,r);return s.updateClippingStatus(this.extent),s.updateScreenDepth(this._viewProjectionMatrix),s.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.lodSnapping)===Ae.SPLIT&&s.setPendingUpdate(Ae.SPLIT),s}_mergeTile(e){me(!e.hasPendingUpdate(Ae.SPLIT),"_mergeTile sanity check"),this._purgeDescendantTiles(e)&&(me(!e.renderData,"_mergeTile sanity check"),this._loadTile(e),this._updateTileNeighborsAfterGeometryChange(e),this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(e),this._emitTileScaleChange(e)),this._allTilesDirty=!0,++this._performanceInfo.numMerged}_checkTileAndNeighborsWaterproofness(e){e.checkGeometryWaterproofness(),this._checkTileNeighborsWaterproofness(e)}_checkTileNeighborsWaterproofness(e){xe&&e.forallNeighbors((e=>!!e.isLoaded&&(e.checkGeometryWaterproofness(),!0)))}_loadChildren(e){this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(e),me(e.rendered,"parent should be rendered"),this._unloadTile(e);const t=e.children;t.forEach((e=>this._prepareToLoadTile(e))),t.forEach((e=>this._loadTilePrepared(e))),this._updateTileNeighborsAfterGeometryChange(e,e.level+1),this._deferTileNeighborUpdate||(t.forEach((e=>e.updateNeighborsWithChangedEdgeResolution())),t.forEach((e=>e.checkGeometryWaterproofness())),this._checkTileNeighborsWaterproofness(e)),this._emitTileScaleChange(e,e.level+1)}_loadParent(e){this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(e);const t=e.parent;this._unloadChildren(t),this._loadTile(t),this._updateTileNeighborsAfterGeometryChange(t),this._deferTileNeighborUpdate||this._checkTileAndNeighborsWaterproofness(t),this._emitTileScaleChange(t,t.level)}_unloadChildren(e){if(!e.isLeaf)for(let t=0;t<4;++t){const i=e.children[t];this._unloadChildren(i),this._unloadTile(i)}}_postLoadTile(e){e.setPendingUpdate(Ae.RENDERDATA),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager&&this.overlayManager.hasOverlays&&this.overlayManager.setTileParameters(e),this._elevationUpdate(e)}_loadTile(e){e.load(this._renderer),this._postLoadTile(e)}_loadTilePrepared(e){e.loadPrepared(this._renderer),this._postLoadTile(e)}_prepareToLoadTile(e){e.prepareToLoad(this._renderer)}_elevationDataArrived(e,t,i){const r=new Z(e.lij,e.extent,i);e.dataArrived(t,re.ELEVATION,r);const s=[e],a=e.level,n=this._iteratorPool.acquire();for(n.reset(s);!n.done;){const e=n.next();e.findElevationBoundsForLayer(t,a),e.computeElevationBounds()}n.remove(),this._updateTilesVisibility(s)}_handleLayerViewChanges(e=Xe){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1;const i=new Set;let r=-1;for(const s of this.view.allLayerViews.items)if(i.add(s.uid),Te(s))if(this._basemapLayerViewHandles.has(s.uid)){const e=this._layerClassFromLayerView(s),i=this._getLayerIdxByUID(e,s.uid);u(i)&&((i<r||p(r))&&(t=!0),r=i)}else this._registerTiledLayerView(s),s.layer.loaded&&(t=!0);this._basemapLayerViewHandles.forEach(((e,r)=>{i.has(r)||(this._unregisterTiledLayerView(r),t=!0)})),t&&this._updateTiledLayers(),this._renderer.isTransparent=this._allSurfaceLayersTransparent(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),e.madeProgress()}_allSurfaceLayersTransparent(){let e=0===this.view.map?.ground?.opacity;for(const t of this.view.allLayerViews.items)if(ye(t)&&!G(t.layer)&&0!==t.fullOpacity)return e=!1,e;return e}_hasCompositeBlendMode(){for(const e of this.view.allLayerViews.items)if(ve(e)){const t=we(e.layer.parent)?"normal":e.layer.blendMode;if(Ge(We[t]))return!0}return!1}_layerClassFromLayerView(e){return Le(e)?re.ELEVATION:re.MAP}_registerTiledLayerView(e){const t=[],i=this._layerClassFromLayerView(e);t.push(T((()=>e.suspended),(()=>this._updateTiledLayers()))),t.push(T((()=>e.fullOpacity),(()=>this._updateTileTextures(ie.UNFADED)))),t.push(T((()=>"effectiveScaleRange"in e.layer?e.layer.effectiveScaleRange:null),(()=>this._restartAllAgents(i)))),ve(e)&&t.push(T((()=>e.layer.blendMode),(()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(ie.UNFADED)}))),e.on("data-changed",(()=>{const t=this._getLayerIdxByUID(i,e.uid);u(t)&&this._invalidateLayerData(t,i)})),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){const t=this._basemapLayerViewHandles.get(e);if(t){for(let e=0;e<t.length;e++)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||!Te(e)||!e.fullExtent)return;const r=this._layerClassFromLayerView(e);if(r===re.MAP){const t=e.displayLevelRange.maxLevel;t!==1/0&&(null===i||t>i)&&(i=t)}t[r].push(e)}));for(const r of se){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()}_restartAllAgents(e){const t=this._postorderIterator;for(t.reset(this.rootTiles);!t.done;){const i=t.next();i.restartAgents(e),e===re.ELEVATION&&i.computeElevationBounds()}}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll((t=>{t.updateAgents(re.MAP),e===ie.IMMEDIATE?this.renderer.updateTileTexture(t,Ae.TEXTURE_NOFADING):t.updateRenderData(re.MAP,e)})),this._renderer.isTransparent=this._allSurfaceLayersTransparent()}_invalidateLayerData(e,t){this._allTiles.forAll((i=>i.removeLayerAgent(e,t))),this._allTiles.forAll((i=>i.invalidateLayerData(e,t)))}setTileTreeDirty(){this._allTilesDirty=!0}requestRender(e=Fe.UPDATE){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||Se(s)?this._requestTileData(e,i,s,r):(++this._asyncWorkItems,a.tilemapCache.fetchAvailability(e.lij[0],e.lij[1],e.lij[2],{...r,timeout:6e3}).then((()=>--this._asyncWorkItems)).catch((t=>{throw--this._asyncWorkItems,g(t)||this._dataMissing(e,i,s,{notInTilemap:!0}),t})).then((()=>this._frameTask.schedule((()=>this._requestTileData(e,i,s,r)),r.signal))))}_requestTileData(e,t,i,r){return t===re.ELEVATION?Le(i)?this._requestElevationTileData(e,i,r):Promise.reject():ye(i)?this._requestMapTileData(e,i,r):Promise.reject()}_requestElevationTileData(e,t,i){++this._asyncWorkItems;const r=r=>{if(m(i))return;const s=this._layerIndexByUid[re.ELEVATION].get(t.uid);null!=s?(this._usedMemory=null,this.requestUpdate(),this._elevationDataArrived(e,s,r)):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer %d %s",re.ELEVATION,e.lij.toString())},s=i=>{g(i)||(this._dataMissing(e,re.ELEVATION,t,i),this.requestUpdate())};if(be(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],{noDataValue:ce,signal:i.signal}).then((e=>{if(!m(i))return this._frameTask.schedule((()=>r(e)),i.signal,s);l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true.")}),s).finally((()=>{--this._asyncWorkItems}));const a=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);return this._elevationDataRequester.request(a,"binary",i).then((e=>this._lercDecoder.decode(e,{noDataValue:ce},i.signal))).then((e=>{e?r({values:e.pixelData,width:e.width,height:e.height,noDataValue:e.noDataValue,minValue:e.minValue,maxValue:e.maxValue}):s(new Error("LERC decoding failed"))}),s).finally((()=>{--this._asyncWorkItems}))}_requestMapTileData(e,t,i){++this._asyncWorkItems;const r=(r,s)=>{--this._asyncWorkItems,Ce(s),m(i)||(this._dataMissing(e,re.MAP,t,r),this.requestUpdate())},s=e=>t=>r(t,e),a=r=>this._frameTask.schedule((()=>{--this._asyncWorkItems,this.requestUpdate(),m(i)?Ce(r):this._mapTileDataArrived(e,t,r)}),i.signal,s(r)).catch(s(r)),n=(e,t=null)=>this._frameTask.schedule((()=>r(e,t)));if(Se(t)){const r=t.schemaHelper.getLevelRowColumn(e.lij);return t.fetchTile(r[0],r[1],r[2],i).then(a,n)}if(Ee(t))return t.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then(a,n);if(De(t)&&be(t.layer))return t.layer.fetchTile(e.lij[0],e.lij[1],e.lij[2],i).then((e=>{if(m(i))return l.getLogger(this.declaredClass).warnOnce("A call to fetchTile resolved even though the request was aborted. fetchTile should not resolve if options.signal.aborted is true."),void n(f());a(e)}),n);let o=t.getTileUrl(e.lij[0],e.lij[1],e.lij[2]);B(t.layer)&&t.layer.refreshTimestamp&&(o+=`${o.includes("?")?"&":"?"}_ts=${t.layer.refreshTimestamp}`);const h=t.hasMixedImageFormats?"image+type":"image";return this._mapDataRequester.request(o,h,i).then(a,n)}_mapTileDataArrived(e,t,i){const r=this._getLayerIdxByUID(re.MAP,t.uid);u(r)?e.dataArrived(r,re.MAP,i):(Ce(i),l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer"))}_getLayerIdxByUID(e,t){return this._layerIndexByUid[e].get(t)}_dataMissing(e,t,i,r){const s=this._getLayerIdxByUID(t,i.uid);u(s)?e.dataMissing(s,t,r):l.getLogger(this.declaredClass).warn("TerrainSurface: received data from unknown layer")}updateTileOverlayParams(e){this.rootTiles&&this.overlayManager&&(this._allTiles.forAll((e=>{e.renderData&&this.overlayManager.setTileParameters(e)})),this._renderer.setNeedsRender(e))}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.isLeaf&&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}getUsedMemory(){return this.tilingScheme?(p(this._usedMemory)&&(this._usedMemory=this._recalculateUsedMemory()),u(this._usedMemory)?this._usedMemory:0):0}_recalculateUsedMemory(){return this.tilingScheme?this._allTiles.reduce(((e,t)=>e+t.usedMemory),0):null}getUsedMemoryForLayerView(e){let t=0;const i=this._layerClassFromLayerView(e),r=this._getLayerIdxByUID(i,e.uid);return u(r)&&this._allTiles.forAll((e=>t+=e.getUsedMemoryForLayer(i,r))),t}getTile(e){if(p(e)||p(this.rootTiles))return null;const t=e.split("/").map((e=>+e));if(0===t[0])return this.rootTiles.find((e=>e.lij[1]===t[1]&&e.lij[2]===t[2]));const i=2**t[0],r=Math.floor(t[1]/i),s=Math.floor(t[2]/i);let a;if(this.rootTiles.some((e=>e.lij[1]===r&&e.lij[2]===s&&(a=e,!0))),a){let e=1<<t[0]-1;for(;a.lij[0]<t[0];){let i=t[1]&e?2:0;if((t[2]&e)>0&&i++,!a.children[i])return null;a=a.children[i],e>>=1}return me(a.lij[0]===t[0]&&a.lij[1]===t[1]&&a.lij[2]===t[2],"not the right tile?"),a}return null}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(){const e=this;return{renderer:e._renderer,lercDecoder:e._lercDecoder,forceReload:()=>{u(e.rootTiles)&&(e._mergeTile(e.rootTiles[0]),e._viewChangeUpdate())},getTiles:()=>e._allTiles.toArray(),getRenderedTiles(){rt.clear(),e._allTiles.forAll((e=>{e.visible&&e.rendered&&rt.push(e)}));const t=rt.toArray();return Oe(e.renderOrder,t),t},lockTilingScheme(t,i){e._extentHelper.defaultTiledLayersExtent=i,e.tilingSchemeLogic.test.lockTilingScheme(t)}}}checkAllTileWaterproofness(){if(!xe)return;const e=this.rootTiles;if(p(e))return;const t=e=>e?.renderData?.geometryInfo?.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.renderData&&!e.renderData.geometryState&&console.error("Tile[",e.lij,"] has renderData but not geometryState"),e.renderData&&!e.renderData.geometryInfo&&console.error("Tile[",e.lij,"] has renderData but not geometryInfo"),!e.renderData?.geometryInfo||(e.renderData.geometryInfo.indices?.length??0)>0||console.error("Tile[",e.lij,"] has renderData but no indices - geometryInfo: ",e.renderData.geometryInfo),t(e)){e.checkGeometryWaterproofness();for(const t of e.children)i(t,e)}else if(e.isLeaf)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.isLeaf)for(const a of e.children)s(a)};for(const a of e)r(a),s(a)}get isGlobal(){return this._isGlobal}get shadingEnabled(){return this._renderer.shadingEnabled}get isWebMercator(){return!!this.tilingScheme?.spatialReference.isWebMercator}get isWebMercatorOnPlateeCarree(){return this.isWebMercator&&O(this.view?.renderSpatialReference)}isEastEndWrap(e){return this.isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this.isGlobal&&0===e[2]}lijEastEnd(e){return 2**(e+(u(this.spatialReference)&&this.spatialReference.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){Pe(e)}};e([L()],Ye.prototype,"_renderer",void 0),e([L()],Ye.prototype,"_hasPendingUpdates",void 0),e([L()],Ye.prototype,"_asyncWorkItems",void 0),e([L()],Ye.prototype,"_allTilesDirty",void 0),e([L()],Ye.prototype,"_allTilesSorted",void 0),e([L()],Ye.prototype,"_viewChanged",void 0),e([L({readOnly:!0})],Ye.prototype,"_watchUpdatingTracking",void 0),e([L()],Ye.prototype,"_frameTask",void 0),e([L({readOnly:!0})],Ye.prototype,"snapLevel",null),e([L({readOnly:!0})],Ye.prototype,"lodSnapping",null),e([L({constructOnly:!0})],Ye.prototype,"view",void 0),e([L()],Ye.prototype,"_userClippingExtent",null),e([L()],Ye.prototype,"_rootTilesExtent",void 0),e([L({readOnly:!0})],Ye.prototype,"extent",null),e([L({readOnly:!0})],Ye.prototype,"groundExtent",null),e([L({readOnly:!0})],Ye.prototype,"_tilingSchemeExtent",null),e([L({readOnly:!0})],Ye.prototype,"updating",null),e([L($)],Ye.prototype,"updatingProgress",void 0),e([L({readOnly:!0})],Ye.prototype,"updatingProgressValue",null),e([L()],Ye.prototype,"_maxNumUpdating",void 0),e([L()],Ye.prototype,"baseOpacity",null),e([L()],Ye.prototype,"hasCompositeBlendMode",void 0),e([L({readOnly:!0})],Ye.prototype,"overlayManager",void 0),e([L({readOnly:!0})],Ye.prototype,"viewingMode",null),e([L()],Ye.prototype,"maxTextureScale",void 0),e([L({readOnly:!0})],Ye.prototype,"ready",null),e([L({value:le.FRONT_TO_BACK})],Ye.prototype,"renderOrder",null),e([L({readOnly:!0})],Ye.prototype,"rootTiles",void 0),e([L({readOnly:!0})],Ye.prototype,"spatialReference",null),e([L({type:t})],Ye.prototype,"backgroundColor",null),e([L({value:!1})],Ye.prototype,"slicePlaneEnabled",null),e([L({readOnly:!0})],Ye.prototype,"tilingScheme",void 0),e([L({readOnly:!0})],Ye.prototype,"tilingSchemeLocked",null),e([L({readOnly:!0})],Ye.prototype,"tilingSchemeLogic",void 0),e([L({value:!0})],Ye.prototype,"velvetOverground",null),e([L()],Ye.prototype,"wireframe",null),e([L({value:!1})],Ye.prototype,"suspended",null),e([L()],Ye.prototype,"textureFadeDuration",null),e([L()],Ye.prototype,"_layerViewsDirty",void 0),e([L()],Ye.prototype,"renderPatchBorders",null),e([L()],Ye.prototype,"renderingDisabled",null),Ye=e([S("esri.views.3d.terrain.TerrainSurface")],Ye);const $e=Ye;function Ke(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function Je(e){return!e.isLeaf&&(e.children.some((e=>e.shouldLoad))||e.children.some((e=>Je(e))))}function Ze(e){return e.isLeaf&&e.parent&&e.parent.shouldLoad}const et=x(),tt=j(),it=[0,0,0],rt=new _,st={spatialReference:null,tile:null,extent:null,context:"ground"},at={spatialReference:null,extent:null,scale:0};export{$e as default};