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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/analysis/DimensionAnalysis.js +1 -1
  2. package/analysis/DimensionSimpleStyle.js +1 -1
  3. package/analysis/LengthDimension.js +1 -1
  4. package/analysis/LineOfSightAnalysis.js +1 -1
  5. package/analysis/LineOfSightAnalysisTarget.js +1 -1
  6. package/analysis/Viewshed.js +1 -1
  7. package/analysis/ViewshedAnalysis.js +1 -1
  8. package/assets/esri/core/workers/RemoteClient.js +1 -1
  9. package/assets/esri/core/workers/chunks/02940f7ddaf98e69521e.js +1 -0
  10. package/assets/esri/core/workers/chunks/{9503eedfdda55fc5adab.js → 091ec4fe83038f3558f4.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{322b22a5d54e404bebd5.js → 0c893837f67829757df7.js} +1 -1
  12. package/assets/esri/core/workers/chunks/123541f79be7adff0818.js +1 -0
  13. package/assets/esri/core/workers/chunks/{155861fbd0e5fc2db80c.js → 1a91443970d64a59521d.js} +1 -1
  14. package/assets/esri/core/workers/chunks/1e37337f47f45d6d8005.js +1 -0
  15. package/assets/esri/core/workers/chunks/{4e5405134d079bdf9b7a.js → 1f76f6dcdae9f55389cb.js} +1 -1
  16. package/assets/esri/core/workers/chunks/396299c22994c502e41c.js +1 -0
  17. package/assets/esri/core/workers/chunks/{03daf6f235c6edef6268.js → 398ec098fffe6abceedd.js} +1 -1
  18. package/assets/esri/core/workers/chunks/3b32a24488b3068f0cb7.js +1 -0
  19. package/assets/esri/core/workers/chunks/3b5e9e0b180dc10491ec.js +1 -0
  20. package/assets/esri/core/workers/chunks/46edd6c9ed6701e6b975.js +1 -0
  21. package/assets/esri/core/workers/chunks/{8b0d5551978ab0aac0d1.js → 520f499d79fa71f262c7.js} +1 -1
  22. package/assets/esri/core/workers/chunks/5473409fee59db80f87d.js +1 -0
  23. package/assets/esri/core/workers/chunks/553a8bf5bc5c56d1bcaf.js +1 -0
  24. package/assets/esri/core/workers/chunks/{2211ff0a1f1ae8100231.js → 585ae43c7bcb86a26762.js} +1 -1
  25. package/assets/esri/core/workers/chunks/58716a3a6106a1b0fb9d.js +1 -0
  26. package/assets/esri/core/workers/chunks/{aa6ee2aa4ff6e6d41efb.js → 5882f349f3771868e67f.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{1b17f5f720f6cf3f6d73.js → 5be386b3af867b19ff39.js} +1 -1
  28. package/assets/esri/core/workers/chunks/{ea81f9d71b0842a4be26.js → 5e48898cebb6dbaf09b5.js} +1 -1
  29. package/assets/esri/core/workers/chunks/{139e753d95cfc9470e74.js → 6a65fc1a2931230fe994.js} +1 -1
  30. package/assets/esri/core/workers/chunks/{3e406043a374ee17475b.js → 6f2e7e663229b223b4df.js} +1 -1
  31. package/assets/esri/core/workers/chunks/76e80381fa6d1e084796.js +1 -0
  32. package/assets/esri/core/workers/chunks/{3b380e64566a6cce59e2.js → 7e0ed6e8f7b77e43f628.js} +1 -1
  33. package/assets/esri/core/workers/chunks/8c3779de09291170497f.js +1 -0
  34. package/assets/esri/core/workers/chunks/8e391b5b82429f39791e.js +1 -0
  35. package/assets/esri/core/workers/chunks/947f3a1cad976bba9738.js +1 -0
  36. package/assets/esri/core/workers/chunks/{59a1b637d2c107504a04.js → 966204d6dedc8149c3e9.js} +1 -1
  37. package/assets/esri/core/workers/chunks/ac107079342251a984dd.js +1 -0
  38. package/assets/esri/core/workers/chunks/{572aec57593a08b8045b.js → b15a8d4322f3b7819d2f.js} +1 -1
  39. package/assets/esri/core/workers/chunks/{552c36b40e5a5ec117fb.js → b472c0a21ae29e653f7d.js} +1 -1
  40. package/assets/esri/core/workers/chunks/bdd76a0b6c14e7fb6984.js +1 -0
  41. package/assets/esri/core/workers/chunks/{f372f4eb5527238c46f5.js → c31830ee897d5a7f2582.js} +1 -1
  42. package/assets/esri/core/workers/chunks/c48d97c38e821be17dc5.js +1 -0
  43. package/assets/esri/core/workers/chunks/{0a508e25ec05363e1f04.js → c7ad62f54d2abe1d17a0.js} +1 -1
  44. package/assets/esri/core/workers/chunks/cb1642ea8b66231cbfb5.js +1 -0
  45. package/assets/esri/core/workers/chunks/cf21b217b13770757cb8.js +1 -0
  46. package/assets/esri/core/workers/chunks/d42a4f47843e075c56a8.js +1 -0
  47. package/assets/esri/core/workers/chunks/e2430bc3a1edeb5c3266.js +1 -0
  48. package/assets/esri/core/workers/chunks/e9457a67befc61e11095.js +1 -0
  49. package/assets/esri/core/workers/chunks/f06ef153e106b26a6748.js +1 -0
  50. package/assets/esri/core/workers/chunks/faae3c43048b42341536.js +1 -0
  51. package/assets/esri/core/workers/chunks/fd967a9f3cf0e2890dbb.js +1 -0
  52. package/chunks/h.js +2 -0
  53. package/chunks/projector.js +2 -0
  54. package/config.js +1 -1
  55. package/core/sanitizerUtils.js +1 -1
  56. package/form/FormTemplate.js +1 -1
  57. package/form/elements/Element.js +1 -1
  58. package/form/elements/FieldElement.js +1 -1
  59. package/geometry/ellipsoidUtils.js +4 -4
  60. package/geometry/support/frustumPlanes.js +1 -1
  61. package/geometry/support/plane.js +1 -1
  62. package/geometry/support/triangle.js +1 -1
  63. package/kernel.js +1 -1
  64. package/layers/GraphicsLayer.js +1 -1
  65. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  66. package/layers/geospatialPDF/geospatialPDFParserUtils.js +1 -1
  67. package/layers/geospatialPDF/support/datumUtils.js +2 -0
  68. package/layers/geospatialPDF/support/ellipsoidUtils.js +2 -0
  69. package/layers/geospatialPDF/support/geographicProjectionUtils.js +2 -0
  70. package/layers/geospatialPDF/support/parameterUtils.js +2 -0
  71. package/layers/geospatialPDF/support/projectedProjectionUtils.js +3 -0
  72. package/layers/geospatialPDF/support/projectionToSpatialReference.js +2 -0
  73. package/layers/geospatialPDF/support/statePlaneUtils.js +2 -0
  74. package/layers/geospatialPDF/support/unitUtils.js +2 -0
  75. package/layers/geospatialPDF/support/validateProjectionUtils.js +2 -0
  76. package/layers/graphics/sources/support/clientSideDefaults.js +2 -2
  77. package/layers/knowledgeGraph/KnowledgeGraphSublayer.js +1 -1
  78. package/layers/ogc/ogcFeatureUtils.js +1 -1
  79. package/layers/save/imageryUtils.js +1 -1
  80. package/layers/save/mediaLayerUtils.js +1 -1
  81. package/layers/save/streamLayerUtils.js +1 -1
  82. package/layers/support/ControlPoint.js +1 -1
  83. package/layers/support/ControlPointsGeoreference.js +1 -1
  84. package/layers/support/DimensionalDefinition.js +1 -1
  85. package/layers/support/LabelClass.js +1 -1
  86. package/layers/support/LabelExpressionInfo.js +1 -1
  87. package/layers/support/MediaElementBase.js +1 -1
  88. package/layers/support/MosaicRule.js +1 -1
  89. package/layers/support/MultidimensionalSubset.js +1 -1
  90. package/layers/support/RasterBandInfo.js +1 -1
  91. package/layers/support/RasterFunction.js +1 -1
  92. package/layers/support/RasterFunctionTemplate.js +1 -1
  93. package/layers/support/RasterInfo.js +1 -1
  94. package/layers/support/RasterSensorInfo.js +1 -1
  95. package/layers/support/RasterStorageInfo.js +1 -1
  96. package/layers/support/VideoElement.js +1 -1
  97. package/layers/support/layersLoader.js +1 -1
  98. package/legend/ActiveLayerInfo.d.ts +5 -1
  99. package/legend/ActiveLayerInfo.js +1 -1
  100. package/libs/maquette-advanced-projector/projector.js +1 -1
  101. package/linkChart/LayoutSettings.js +1 -1
  102. package/linkChart/RootedLayoutSettings.js +1 -1
  103. package/package.json +2 -2
  104. package/renderers/FlowRenderer.js +1 -1
  105. package/renderers/RasterColormapRenderer.js +1 -1
  106. package/renderers/RasterShadedReliefRenderer.js +1 -1
  107. package/renderers/RasterStretchRenderer.js +1 -1
  108. package/renderers/VectorFieldRenderer.js +1 -1
  109. package/renderers/support/ColormapInfo.js +1 -1
  110. package/renderers/support/RasterPresetRenderer.js +1 -1
  111. package/renderers/support/rasterRendererHelper.js +1 -1
  112. package/rest/knowledgeGraph/GraphApplyEdits.js +1 -1
  113. package/rest/support/BaseImageMeasureParameters.js +1 -1
  114. package/rest/support/BaseImageMeasureResult.js +1 -1
  115. package/rest/support/FindImagesParameters.js +1 -1
  116. package/rest/support/FindImagesResult.js +1 -1
  117. package/rest/support/ImageAngleParameters.js +1 -1
  118. package/rest/support/ImageAngleResult.js +1 -1
  119. package/rest/support/ImageAreaParameters.js +1 -1
  120. package/rest/support/ImageAreaResult.js +1 -1
  121. package/rest/support/ImageBoundaryParameters.js +1 -1
  122. package/rest/support/ImageBoundaryResult.js +1 -1
  123. package/rest/support/ImageDistanceParameters.js +1 -1
  124. package/rest/support/ImageDistanceResult.js +1 -1
  125. package/rest/support/ImageGPSInfoParameters.js +1 -1
  126. package/rest/support/ImageGPSInfoResult.js +1 -1
  127. package/rest/support/ImageHeightParameters.js +1 -1
  128. package/rest/support/ImageHeightResult.js +1 -1
  129. package/rest/support/ImageHistogramParameters.js +1 -1
  130. package/rest/support/ImageIdentifyParameters.js +1 -1
  131. package/rest/support/ImageIdentifyResult.js +1 -1
  132. package/rest/support/ImagePixelLocationParameters.js +1 -1
  133. package/rest/support/ImagePixelLocationResult.js +1 -1
  134. package/rest/support/ImagePointParameters.js +1 -1
  135. package/rest/support/ImagePointResult.js +1 -1
  136. package/rest/support/ImageSample.js +1 -1
  137. package/rest/support/ImageSampleParameters.js +1 -1
  138. package/rest/support/ImageSampleResult.js +1 -1
  139. package/rest/support/ImageToMapMultirayParameters.js +1 -1
  140. package/rest/support/ImageToMapParameters.js +1 -1
  141. package/rest/support/ImageUrlParameters.js +1 -1
  142. package/rest/support/ImageUrlResult.js +1 -1
  143. package/rest/support/ImageVolumeParameters.js +1 -1
  144. package/rest/support/ImageVolumeResult.js +1 -1
  145. package/rest/support/MapToImageParameters.js +1 -1
  146. package/rest/support/MeasureAreaFromImageResult.js +1 -1
  147. package/rest/support/MeasureFromImageParameters.js +1 -1
  148. package/rest/support/MeasureLengthFromImageResult.js +1 -1
  149. package/symbols/support/cimSymbolUtils.js +1 -1
  150. package/symbols/support/renderUtils.js +1 -1
  151. package/views/2d/ViewState.d.ts +3 -3
  152. package/views/2d/ViewState.js +1 -1
  153. package/views/2d/ViewStateManager.js +1 -1
  154. package/views/2d/engine/vectorTiles/decluttering/CollisionJob.js +1 -1
  155. package/views/2d/engine/vectorTiles/style/geoJSONVectorTileUtils.js +1 -1
  156. package/views/2d/engine/webgl/collisions/LabelMetric.js +1 -1
  157. package/views/2d/engine/webgl/collisions/LabelStore.js +1 -1
  158. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AAnimatedShader.js +1 -1
  159. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedMarkerShader.js +1 -1
  160. package/views/2d/engine/webgl/shaderGraph/techniques/labels/LabelMeshWriter.js +1 -1
  161. package/views/2d/engine/webgl/shaderGraph/techniques/markers/MarkerShader.js +1 -1
  162. package/views/2d/engine/webgl/shaderGraph/techniques/shaders/AFeatureShader.js +1 -1
  163. package/views/2d/engine/webgl/shaderGraph/techniques/shaders/FillShader.js +1 -1
  164. package/views/2d/engine/webgl/shaderGraph/techniques/shaders/LineShader.js +1 -1
  165. package/views/2d/engine/webgl/shaderGraph/techniques/shaders/OutlineFillShader.js +1 -1
  166. package/views/2d/engine/webgl/shaderGraph/techniques/text/TextShader.js +1 -1
  167. package/views/2d/engine/webgl/util/IntervalMatcher.js +1 -1
  168. package/views/3d/FocusAreasView.js +1 -1
  169. package/views/3d/GroundView3D.js +1 -1
  170. package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
  171. package/views/3d/layers/graphics/Graphics3DSymbol.js +1 -1
  172. package/views/3d/layers/i3s/I3SBinaryReader.js +1 -1
  173. package/views/3d/state/ConstraintsManager.js +1 -1
  174. package/views/3d/state/ViewState.js +1 -1
  175. package/views/3d/state/ViewStateManager.js +1 -1
  176. package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +1 -1
  177. package/views/3d/support/gaussianSplatting/GaussianTileLifecycle.js +2 -0
  178. package/views/3d/terrain/OverlayManager.js +1 -1
  179. package/views/3d/terrain/OverlayRenderer.js +1 -1
  180. package/views/3d/terrain/TerrainRenderer.js +1 -1
  181. package/views/3d/terrain/TerrainSurface.js +1 -1
  182. package/views/3d/terrain/Tile.js +1 -1
  183. package/views/3d/terrain/tileUtils.js +1 -1
  184. package/views/3d/webgl-engine/core/shaderLibrary/shading/readShadow.glsl.js +1 -1
  185. package/views/3d/webgl-engine/effects/WeatherFader.js +1 -1
  186. package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +19 -9
  187. package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
  188. package/views/3d/webgl-engine/lib/GeometryUtil.js +1 -1
  189. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  190. package/views/3d/webgl-engine/lib/geometryDataUtils.js +1 -1
  191. package/views/3d/webgl-engine/lib/screenPolygonOverlapUtils.js +1 -1
  192. package/views/3d/webgl-engine/lib/screenPolygonTriangleIntersections.js +1 -1
  193. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  194. package/views/3d/webgl-engine/materials/HUDMaterialBaseInstance.js +1 -1
  195. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  196. package/views/3d/webgl-engine/materials/internal/bufferWriterUtils.js +1 -1
  197. package/views/3d/webgl-engine/materials/internal/lineMarkerBufferUtils.js +1 -1
  198. package/views/3d/webgl-engine/shaders/DefaultMaterialTechnique.js +1 -1
  199. package/views/3d/webgl-engine/shaders/HUDMaterialTechnique.js +1 -1
  200. package/views/3d/webgl-engine/shaders/LineMarkerTechnique.js +1 -1
  201. package/views/3d/webgl-engine/shaders/hudMaterialLayouts.js +2 -0
  202. package/views/3d/webgl-engine/shaders/lineMarkerLayouts.js +2 -0
  203. package/views/overlay/LineOverlayItem.js +1 -1
  204. package/views/overlay/TextOverlayItem.js +1 -1
  205. package/views/overlay/ViewOverlay.js +1 -1
  206. package/views/support/GroundElevationSampler.js +1 -1
  207. package/views/support/HighlightOptions.d.ts +2 -2
  208. package/views/support/HighlightOptions.js +1 -1
  209. package/views/webgl/Util.js +1 -1
  210. package/views/webgl/textureUtils.js +1 -1
  211. package/widgets/FeatureTable/Grid/Grid.js +1 -1
  212. package/widgets/Legend/styles/support/univariateUtils.js +1 -1
  213. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  214. package/widgets/OrientedImageryViewer.js +1 -1
  215. package/assets/esri/core/workers/chunks/01f55004d64309f8538b.js +0 -1
  216. package/assets/esri/core/workers/chunks/0d99bfb75dcb9fa29080.js +0 -1
  217. package/assets/esri/core/workers/chunks/144bad0c2415c345736a.js +0 -1
  218. package/assets/esri/core/workers/chunks/165ca7a97b611c8f26c4.js +0 -1
  219. package/assets/esri/core/workers/chunks/1989410a618865f02dec.js +0 -1
  220. package/assets/esri/core/workers/chunks/2f9072563194026e320e.js +0 -1
  221. package/assets/esri/core/workers/chunks/338d800d4efcc91cead1.js +0 -1
  222. package/assets/esri/core/workers/chunks/3415531224f8494d79ca.js +0 -1
  223. package/assets/esri/core/workers/chunks/59a88dd53f8806bbec06.js +0 -1
  224. package/assets/esri/core/workers/chunks/5aeb5e18514644fe2cf9.js +0 -1
  225. package/assets/esri/core/workers/chunks/6edc13a426e00bb93a9b.js +0 -1
  226. package/assets/esri/core/workers/chunks/7862abd24fb5c3b12e6b.js +0 -1
  227. package/assets/esri/core/workers/chunks/8a3dfe997712dc2ddead.js +0 -1
  228. package/assets/esri/core/workers/chunks/8f82a0a6747f673a2a7e.js +0 -1
  229. package/assets/esri/core/workers/chunks/934e1f2153e6fad6ed23.js +0 -1
  230. package/assets/esri/core/workers/chunks/b25a05c58b0fd0f6ac60.js +0 -1
  231. package/assets/esri/core/workers/chunks/c7adb7b77721c75891f4.js +0 -1
  232. package/assets/esri/core/workers/chunks/cd55cad81accf51d2989.js +0 -1
  233. package/assets/esri/core/workers/chunks/ce324dde6d7daea33638.js +0 -1
  234. package/assets/esri/core/workers/chunks/d3412518a7b518860fbb.js +0 -1
  235. package/assets/esri/core/workers/chunks/dac69c0047488fdf986d.js +0 -1
  236. package/assets/esri/core/workers/chunks/dba5f44c4e4a3f075df2.js +0 -1
  237. package/assets/esri/core/workers/chunks/e67ea2f1714e5abeae44.js +0 -1
  238. package/assets/esri/core/workers/chunks/eed4b90494a54f8b337b.js +0 -1
  239. package/assets/esri/core/workers/chunks/f10c883eb26330e3421c.js +0 -1
  240. package/layers/geospatialPDF/projectionToWKTUtils.js +0 -3
  241. package/libs/maquette/cache.js +0 -2
  242. package/libs/maquette/dom.js +0 -2
  243. package/libs/maquette/h.js +0 -2
  244. package/libs/maquette/index.js +0 -2
  245. package/libs/maquette/mapping.js +0 -2
  246. package/libs/maquette/projection.js +0 -2
  247. package/libs/maquette/projector.js +0 -2
  248. package/libs/maquette/utilities/window-performance-projector-logger.js +0 -2
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import has from"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as ne,isAborted as p}from"../../../core/promiseUtils.js";import{watch as m,syncAndInitial as h,initial as g,sync as _}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as re}from"../../../core/units.js";import{property as v,subclass as ie}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ae,set as oe,copy as se}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as ce}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as b,radiusModifier as le}from"../../../geometry/ellipsoidUtils.js";import{projectWithoutEngine as ue}from"../../../geometry/projectionUtils.js";import x from"../../../geometry/SpatialReference.js";import{projectBoundingSphere as de}from"../../../geometry/projection/projectBoundingSphere.js";import{getProjector as fe}from"../../../geometry/projection/projectors.js";import{projectPointToVector as pe}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as me}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,fromExtent as he,equals as C,intersection as ge,intersectsSphere as _e}from"../../../geometry/support/aaBoundingRect.js";import{copy as ve,create as ye}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as be}from"../../../geometry/support/normalizeUtils.js";import{isGeographic as w,isPlateCarree as xe}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as Se}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as Ce}from"../../../layers/support/ElevationQueryTileCache.js";import{isIntegratedMeshLayer as we,isBaseLayer as Te}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Ee}from"../../../request/queue.js";import{debugFlags as T}from"../support/debugFlags.js";import{ElevationRange as E}from"../support/ElevationRange.js";import{ElevationUpdateEvent as De}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Oe}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as ke}from"../support/extentUtils.js";import{geographicMbsToGeographicExtent as Ae,mbsToGeographicExtent as je,intersectsGeographicExtent as Me}from"../support/sphereExtentUtils.js";import{isSupportedGCSOnGlobe as D}from"../support/supportedSpatialReference.js";import{updatingProgress as Ne}from"../support/updatingProperties.js";import{ElevationBounds as O}from"./ElevationBounds.js";import{ElevationData as Pe,sampleElevation as Fe}from"./ElevationData.js";import{create as Ie}from"./ExtentHelper.js";import{LayerClasses as Le}from"./LayerClass.js";import{OverlayManager as Re}from"./OverlayManager.js";import{PlanarPatch as ze}from"./PlanarPatch.js";import{Queue as Be}from"./Queue.js";import{ScaleRangeQueries as Ve}from"./ScaleRangeQueries.js";import{SphericalPatch as He}from"./SphericalPatch.js";import{SplitLimits as Ue}from"./SplitLimits.js";import{maxRootTiles as k,tooManyRootTilesAfterChangeError as We,tooManyRootTilesForLayerError as Ge,maxTileNeighborLevelDelta as A,maxMemoryLodBias as Ke}from"./TerrainConst.js";import{TerrainRenderer as qe}from"./TerrainRenderer.js";import Je from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as j,isVectorTileLayerView as M,internalAssert as N,oppositeEdge as Ye,neighborEdgeIndices as P,isSurfaceLayerView as F,isGroupLayerView as I,isMapTileLayerView as L,isBlendableLayerView as R,isElevationLayerView as z,releaseTerrainData as B,oppositeCorner as Xe,enableTerrainInternalChecks as V,enableWaterproofTests as Ze,enableInternalTerrainChecks as Qe,enableTerrainWaterproofChecks as $e,neighborCornerIndices as et}from"./terrainUtils.js";import{Tile as tt,lijEquals as H}from"./Tile.js";import{printAllocations as nt}from"./TilePerLayerInfo.js";import{sortTiles as rt,IteratorPreorder as it,IteratorPostorder as at,compareTilesByLij as U,hasLoadableSiblings as ot,sortTilesByPOI as st,traverseTilesPreorder as W}from"./tileUtils.js";import{TilingSchemeLogic as ct}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as lt}from"./TransparencyMode.js";import{UpsampleInfo as ut}from"./UpsampleInfo.js";import{isCompositeBlendMode as dt,blendModeFromString as ft}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as pt}from"../../support/layerViewUtils.js";import{ImmediateTask as G,TaskPriority as mt,noBudget as ht}from"../../support/Scheduler.js";import{TextureCompressionTracker as gt}from"../../support/TextureCompressionTracker.js";import{Yield as _t}from"../../support/Yield.js";var K;let q=class extends o{static{K=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return rt(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=re(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new gt,this._iteratorPool=new d(()=>new it,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new at,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new Je,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=y(),this._eyePosSurfaceSR=y(),this._splitLimits=new Ue,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new ce,this._poiWatchHandle=null,this._frameTask=G,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new ut),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=S(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=x.WebMercator,this._elevationProjectorCache=new Map,this.visibleElevationRange=new E(1/0,-1/0),this._rootTileElevationRange=new E(1/0,-1/0),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new Re({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?He:ze,this._ellipsoid=b(t.spatialReference),this._renderer=new qe(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),pt()||(this._scaleRangeQueries=new Ve)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new Ce(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([m(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),m(()=>this.renderer.visible,e=>this.freeze=!e),m(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},h)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},g),this.addHandles([m(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},h),m(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),h),m(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},_),m(()=>this.snapLevel,()=>this._viewChanged=!0,_),m(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ae}))}),m(()=>T.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&T.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},g)]);let{spatialReference:a}=e;this._extentHelper=Ie(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new ct({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(mt.TERRAIN_SURFACE,this),this.addHandles([m(()=>this._stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),g),m(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),_),m(()=>this.groundExtent,()=>this._updateRootTiles(),g),e.on(`resize`,()=>this._viewChangeUpdate()),m(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),h),m(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,g),m(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,g),m(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>{this._allTiles.forAll(e=>this.updateElevationSources(e)),this._updateAllTileGeometries()}),m(()=>this.userClippingExtent,()=>this._updateClippingExtent(),_)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=G,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),tt.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),nt(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return!!this._stencilEnabledExtents?.length}get _stencilEnabledExtents(){let e=this.spatialReference,t=!!has(`enable-feature:im-as-ground`);return e==null?null:Iterator.from(this.view.allLayerViews).map(n=>{let{layer:r}=n;if(!we(r)||t&&!r.isUsedAsGroundLayer)return null;let{fullExtent:i}=r,a=i==null||i.spatialReference.equals(e)?i:ue(i,i.spatialReference,e);return a?he(a):null}).filter(e=>e!=null).toArray()}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=S(),r=ke(t,n,e)?n:null,i=this._get(`userClippingExtent`);return C(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=ge(this.fullGroundExtent,this.userClippingExtent,S()),t=this._get(`groundExtent`);return C(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.freeze}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||this._rootTiles!=null}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set(`slicePlaneEnabled`,e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return be(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=fe(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=oe(J,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return St(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=St(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}getScale(e){if(!this.tilingScheme)return null;if(!pe(e,J,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(J)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;J[0]>e[2]&&(n+=1),J[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}getSphereElevationRange(e,t){if(!this.enabled)return null;let n=this._rootTiles,r=this._tilingSchemeSpatialReference;if(n==null||r==null||n.length===0)return null;let i=w(r);if(i){let n=w(t)&&D(t),i=b(t);if(n&&D(r)&&i===b(r))Ae(e,Y,i.radius);else if(!je(e,t,Y,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null}else if(!de(e,t,yt,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null;let a=new E,o=[];for(let e of n)o.push(e);let c=0;for(;c<o.length;){let e=o[c];if(++c,!(i?Me(e.extent,Y,r):_e(e.extent,yt)))continue;let t=e.children;if(t[0]==null||e.rendered)a.expandElevationRangeValues(e.elevationBoundsMin,e.elevationBoundsMax);else for(let e of t)o.push(e)}return a}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new E(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=(this._ellipsoid.radius+this.visibleElevationRange.minElevation)*le;return Math.min(e,this._ellipsoid.radius)}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?lt(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;j(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??x.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&xe(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set(`tilingScheme`,e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey=`TerrainTileMemcache`}_acquireTile(e,t,n,r){let i=this._tileCache.pop(K._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=bt,i=t.rootTilesInExtent(e,n,k*5);if(this._rootTiles!=null){if(i.length>k){s.getLogger(this).warn(We);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,H);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>H(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>k&&(s.getLogger(this).warn(Ge),i=t.rootTilesInExtent(e,n,k)),this._setRootTiles(i.map(e=>this._newRootTile(e)));C(n,this._rootTilesExtent)||(this._rootTilesExtent=S(n)),this.renderer.visible=!0,this._viewChangeUpdate(),this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(U),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),e!=null){let t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.freeze&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(e==null)return;let t=ot(e),n=this.visibleElevationRange,r=t?n.minElevation:1/0,i=t?n.maxElevation:-1/0,a=this.groundExtent,o=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let s=this._iteratorPool.acquire();for(s.reset(e);!s.done;){let e=s.next();e.updateClippingStatus(a)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(o),e.renderData&&(r=Math.min(e.elevationBoundsMin,r),i=Math.max(e.elevationBoundsMax,i))}s.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries(),isFinite(r)&&isFinite(i)&&(n.minElevation!==r||n.maxElevation!==i)&&(this.visibleElevationRange=new O(r,i))}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new O(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=ve(this._splitLimits.frustum??ye(),t.frustum):this._splitLimits.frustum=null,se(this._eyePosRenderSR,t.eye),me(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility(),this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){let t;e.forEachLoadedNeighbor(e=>{t??=this._layerViews[1].some(M),t&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.hasPendingUpdate(32)?32:e.hasPendingUpdate(16)?16:!1;if(n){let r=this._renderer.updateTileTexture(e,n);return this._usedMemory=null,r&&e.resetPendingUpdate(n),t.madeProgress(),r}return!0}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Oe(t,this.spatialReference)){let t=new De(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e);let n=this._updateTextures(e);t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let r=this._pendingTilesToUpdate.size>0,i=r&&this._hasPendingGeometryWithoutIndices();if((!e.done||i)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||r&&!i)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!n||!e.hasProgressed)return _t}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new Be(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=e.elevationLevel,l=s?4:e.shouldSplit(i,a,r),u=l===1;e.leaf?Z(e,u):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):(u?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),l===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0)),e.elevationLevel!==c&&this.updateElevationSources(e))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(st(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){N(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(U);let r=t.length;for(let i=0;i<r;++i){let r=t[i];N(r.loaded),N(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=et[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(Xe(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Ye(P[t]),t=>this._canUpdateTileGeometry(t)?(N(e.has(t)||U(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),t.sort(U),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,V&&Ze&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=A){let e=e=>e.leaf||n-e.level<A;for(let r=0;r<4;++r){let a=i.findNeighborTile(P[r],e);a!=null&&n-a.level===A&&(t=!1,V&&(N(a.leaf),N(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}updateElevationSources(e){e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate())}_updateTextures(e){if(e.done)return!0;let t=!0;return this._allTiles.some(n=>(this._updateTileTexture(n,e)||(t=!1),e.done)),t}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*Ke}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange(`ready`)),this._allTiles.clear(),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),this.renderer.visible=!1}_purgeSubtree(e){let t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?wt(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(K._tileMemcacheKey,e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){j(e.leaf,`Tile that is already split should not be split again!`),j(e.rendered,`Tile marked to split is not rendered`),wt(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),j(e.rendered,`parent should be rendered`),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>Z(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){X.spatialReference=this.spatialReference,X.extent=e.extent,X.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,X)}createTile(e,t,n,r){j(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){j(!e.hasPendingUpdate(1),`_mergeTile sanity check`),j(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),j(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),Z(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=ht){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),F(i)||I(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!I(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(let e of this.view.allLayerViews.items)if(L(e)&&!Te(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((R(e)||I(e))&&dt(ft[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!z(e)}_registerTiledLayerView(e){let t=[];if((R(e)||I(e))&&t.push(m(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!I(e)){let n=this._layerClassFromLayerView(e);t.push(m(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(m(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(m(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!F(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of Le){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(W(this._rootTiles,n=>n.removeLayerAgent(e,t)),W(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||M(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),ne(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?z(n)?this._requestElevationTileData(e,n,r):Promise.reject():L(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!p(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{ne(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Ee,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Pe(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{B(i),p(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),p(n)?B(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(B(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(this._usedMemory??=this._recalculateUsedMemory(),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(e=`render-patch-groups`){}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){Qe(e)}enableWaterproofnessChecks(e){$e(e)}static cleanupTerrainSurface(){xt.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([v()],q.prototype,`_renderer`,void 0),e([v({constructOnly:!0})],q.prototype,`_scaleRangeQueries`,void 0),e([v({constructOnly:!0})],q.prototype,`view`,void 0),e([v({constructOnly:!0})],q.prototype,`overlayManager`,void 0),e([v()],q.prototype,`_hasPendingUpdates`,void 0),e([v()],q.prototype,`_asyncWorkItems`,void 0),e([v()],q.prototype,`_allTilesDirty`,void 0),e([v()],q.prototype,`_allTilesSorted`,void 0),e([v()],q.prototype,`allTilesCreated`,null),e([v()],q.prototype,`_allTilesCreated`,void 0),e([v()],q.prototype,`_viewChanged`,void 0),e([v({type:Number})],q.prototype,`heading`,void 0),e([v()],q.prototype,`_splitLimits`,void 0),e([v()],q.prototype,`_frameTask`,void 0),e([v()],q.prototype,`demResolution`,null),e([v({readOnly:!0})],q.prototype,`snapLevel`,null),e([v({readOnly:!0})],q.prototype,`lodSnappingEnabled`,null),e([v()],q.prototype,`_stencilEnabledExtents`,null),e([v({readOnly:!0})],q.prototype,`userClippingExtent`,null),e([v()],q.prototype,`_rootTilesExtent`,void 0),e([v({readOnly:!0})],q.prototype,`groundExtent`,null),e([v({readOnly:!0})],q.prototype,`fullGroundExtent`,null),e([v({readOnly:!0})],q.prototype,`_tilingSchemeExtent`,null),e([v({readOnly:!0})],q.prototype,`updating`,null),e([v({readOnly:!0})],q.prototype,`readyToRun`,null),e([v(Ne)],q.prototype,`updatingProgress`,void 0),e([v({readOnly:!0})],q.prototype,`updatingProgressValue`,null),e([v()],q.prototype,`_maxNumUpdating`,void 0),e([v()],q.prototype,`baseOpacity`,null),e([v()],q.prototype,`hasCompositeBlendMode`,void 0),e([v({readOnly:!0})],q.prototype,`viewingMode`,null),e([v()],q.prototype,`maxTextureScale`,void 0),e([v({readOnly:!0})],q.prototype,`ready`,null),e([v({readOnly:!0})],q.prototype,`rootTiles`,null),e([v()],q.prototype,`_rootTiles`,void 0),e([v({readOnly:!0})],q.prototype,`spatialReference`,null),e([v({type:t})],q.prototype,`backgroundColor`,null),e([v({value:!1})],q.prototype,`slicePlaneEnabled`,null),e([v({readOnly:!0})],q.prototype,`tilingScheme`,void 0),e([v({readOnly:!0})],q.prototype,`tilingSchemeLocked`,null),e([v({readOnly:!0})],q.prototype,`tilingSchemeLogic`,void 0),e([v()],q.prototype,`wireframe`,null),e([v()],q.prototype,`opaque`,null),e([v()],q.prototype,`invisible`,null),e([v({value:!1})],q.prototype,`freeze`,null),e([v()],q.prototype,`fadeDuration`,null),e([v()],q.prototype,`_xNormalizer`,null),e([v()],q.prototype,`visibleElevationRange`,void 0),e([v()],q.prototype,`_rootTileElevationRange`,void 0),e([v()],q.prototype,`_layerViewsDirty`,void 0),e([v()],q.prototype,`renderPatchBorders`,null),e([v()],q.prototype,`renderingDisabled`,null),e([v({readOnly:!0})],q.prototype,`enabled`,void 0),q=K=e([ie(`esri.views.3d.terrain.TerrainSurface`)],q);const vt=q,J=y(),yt=new Se,Y=S(),bt=S(),xt=new f,X={spatialReference:null,extent:null,scale:0};function St(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return Fe(t,n,i)}return null}function Z(e,t){!e.leaf||e.level<A||$(e,e=>{t&&Ct(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}function Ct(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<A||$(e,e=>{Ct(e)})}function wt(e){e.level<A||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<A)return;let n=e.level-A,r=e.lij[1]>>A,i=e.lij[2]>>A,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(P[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{vt as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../Color.js";import{filterInPlace as n,difference as r}from"../../../core/arrayUtils.js";import i from"../../../core/CollectionFlattener.js";import{toConst as a}from"../../../core/compilerUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import has from"../../../core/has.js";import s from"../../../core/Logger.js";import{clamp as c}from"../../../core/mathUtils.js";import{removeMaybe as l,destroyMaybe as u}from"../../../core/maybe.js";import{MemCachePool as ee}from"../../../core/MemCachePool.js";import d from"../../../core/ObjectPool.js";import f from"../../../core/PooledArray.js";import{throwIfAborted as te,isAbortError as p,isAborted as m}from"../../../core/promiseUtils.js";import{watch as h,syncAndInitial as g,initial as _,sync as v}from"../../../core/reactiveUtils.js";import"../../../core/scheduling.js";import{getMetersPerUnitForSR as ne}from"../../../core/units.js";import{property as y,subclass as re}from"../../../core/accessorSupport/decorators.js";import{exactEquals as ie,set as ae,copy as oe}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as se}from"../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as x,radiusModifier as ce}from"../../../geometry/ellipsoidUtils.js";import{projectWithoutEngine as le}from"../../../geometry/projectionUtils.js";import ue from"../../../geometry/SpatialReference.js";import{projectBoundingSphere as de}from"../../../geometry/projection/projectBoundingSphere.js";import{getProjector as fe}from"../../../geometry/projection/projectors.js";import{projectPointToVector as pe}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToVector as me}from"../../../geometry/projection/projectVectorToVector.js";import{create as S,fromExtent as he,equals as C,intersection as ge,intersectsSphere as _e}from"../../../geometry/support/aaBoundingRect.js";import{copy as ve,create as ye}from"../../../geometry/support/frustumPlanes.js";import{createSpatialReferenceCyclical as be}from"../../../geometry/support/normalizeUtils.js";import{isGeographic as w,isPlateCarree as xe}from"../../../geometry/support/spatialReferenceUtils.js";import{Sphere as Se}from"../../../geometry/support/sphere.js";import{ElevationQueryTileCache as Ce}from"../../../layers/support/ElevationQueryTileCache.js";import{isIntegratedMeshLayer as we,isBaseLayer as Te}from"../../../layers/support/layerUtils.js";import{queueHighPriority as Ee}from"../../../request/queue.js";import{debugFlags as T}from"../support/debugFlags.js";import{ElevationRange as E}from"../support/ElevationRange.js";import{ElevationUpdateEvent as De}from"../support/ElevationUpdateEvent.js";import{calculateElevationUpdateExtents as Oe}from"../support/elevationUpdateExtentUtils.js";import{toBoundingRect as ke}from"../support/extentUtils.js";import{geographicMbsToGeographicExtent as Ae,mbsToGeographicExtent as je,intersectsGeographicExtent as Me}from"../support/sphereExtentUtils.js";import{isSupportedGCSOnGlobe as D}from"../support/supportedSpatialReference.js";import{updatingProgress as Ne}from"../support/updatingProperties.js";import{ElevationBounds as Pe}from"./ElevationBounds.js";import{ElevationData as Fe,sampleElevation as Ie}from"./ElevationData.js";import{create as Le}from"./ExtentHelper.js";import{LayerClasses as Re}from"./LayerClass.js";import{OverlayManager as ze}from"./OverlayManager.js";import{PlanarPatch as Be}from"./PlanarPatch.js";import{Queue as Ve}from"./Queue.js";import{ScaleRangeQueries as He}from"./ScaleRangeQueries.js";import{SphericalPatch as Ue}from"./SphericalPatch.js";import{SplitLimits as We}from"./SplitLimits.js";import{maxRootTiles as O,tooManyRootTilesAfterChangeError as Ge,tooManyRootTilesForLayerError as Ke,maxTileNeighborLevelDelta as k,maxMemoryLodBias as qe}from"./TerrainConst.js";import{TerrainRenderer as Je}from"./TerrainRenderer.js";import Ye from"./TerrainSurfacePerformanceInfo.js";import{weakAssert as A,isVectorTileLayerView as j,internalAssert as M,oppositeEdge as Xe,neighborEdgeIndices as N,isSurfaceLayerView as P,isGroupLayerView as F,isMapTileLayerView as I,isBlendableLayerView as L,isElevationLayerView as R,releaseTerrainData as z,oppositeCorner as Ze,enableTerrainInternalChecks as B,enableWaterproofTests as Qe,enableInternalTerrainChecks as $e,enableTerrainWaterproofChecks as et,neighborCornerIndices as tt}from"./terrainUtils.js";import{Tile as nt,lijEquals as V}from"./Tile.js";import{printAllocations as rt}from"./TilePerLayerInfo.js";import{sortTiles as it,IteratorPreorder as at,IteratorPostorder as ot,compareTilesByLij as H,sortTilesByPOI as st,traverseTilesPreorder as U}from"./tileUtils.js";import{TilingSchemeLogic as ct}from"./TilingSchemeLogic.js";import{getGroundTransparencyModeFromOpacity as lt}from"./TransparencyMode.js";import{UpsampleInfo as ut}from"./UpsampleInfo.js";import{isCompositeBlendMode as dt,blendModeFromString as ft}from"../webgl-engine/core/shaderLibrary/output/BlendOptions.js";import{hasLayerBasedScaleVisibility as pt}from"../../support/layerViewUtils.js";import{ImmediateTask as mt,TaskPriority as ht,noBudget as gt}from"../../support/Scheduler.js";import{TextureCompressionTracker as _t}from"../../support/TextureCompressionTracker.js";import{Yield as vt}from"../../support/Yield.js";var W;let G=class extends o{static{W=this}get allTilesCreated(){return this._allTilesCreated}get allTiles(){return a(this._allTiles)}get renderedTiles(){return it(n(this._allTiles.toArray(),e=>e.visible&&e.rendered))}get demResolution(){let{_allTiles:e,tilingScheme:t}=this;if(e.length===0)return{min:1,max:1};let n=ne(t.spatialReference),r=1/0,i=-1/0;for(let a of e){let e=t.resolutionAtLevel(a.level)*n;r=Math.min(r,e),i=Math.max(i,e)}return{min:r,max:i}}constructor(e){super(e),this.terrainTextureCompressionTracker=new _t,this._iteratorPool=new d(()=>new at,e=>e.remove=()=>this._iteratorPool.release(e)),this._postorderIterator=new ot,this._hasPendingUpdates=!1,this._pendingUpdates=0,this._asyncWorkItems=0,this._allTilesDirty=!0,this._allTilesSorted=!0,this._allTilesCreated=!1,this._usedMemory=null,this._performanceInfo=new Ye,this._waterproofnessErrorHandle=null,this._viewChanged=!1,this.heading=0,this._inFrameTask=!1,this._viewChangeUpdateDirty=!1,this._eyePosRenderSR=b(),this._eyePosSurfaceSR=b(),this._splitLimits=new We,this._layerViews=[[],[]],this._layerIndexByUid=[new Map,new Map],this._basemapLayerViewHandles=new Map,this._updatingHandles=new se,this._poiWatchHandle=null,this._frameTask=mt,this._allTiles=new f,this._upsampleInfoPool=new d(()=>new ut),this._shouldEmitChangeEvent=!1,this._rootTilesExtent=S(),this.updatingProgress=.5,this._maxNumUpdating=1,this.maxTextureScale=1.2,this._spatialReference=ue.WebMercator,this._elevationProjectorCache=new Map,this._rootTileElevationRange=new E(1/0,-1/0),this._tilingSchemeSpatialReference=null,this._updatingRootTiles=!1,this._pendingTilesForElevationUpdateEvent=new Set,this._pendingTilesToUpdate=new Set,this.totalGeometryUpdates=0,this.totalTileUpdates=0,this._layerViewsDirty=!1,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._isWebMercator=!1,this._isWebMercatorOnPlateCarree=!1,this.enabled=!0;let{view:t}=e;this.overlayManager=new ze({...e,terrainSurface:this}),this._isGlobal=!t.state?.isLocal,this._isGeographic=this._spatialReference?.isGeographic??!1,this._tileConstructor=this._isGlobal?Ue:Be,this._ellipsoid=x(t.spatialReference),this._renderer=new Je(this,this.overlayManager.renderer,this._allTiles,this.terrainTextureCompressionTracker,t.resourceController.memoryController),pt()||(this._scaleRangeQueries=new He)}initialize(){let{view:e}=this,{resourceController:t}=e,{memoryController:n}=t;e.stage.addRenderPlugin(this._renderer),this._tileCache=new ee((e,t)=>n.newCache(e,t),`terrain-tile`),this._upsampleMapCache=n.newCache(`terrain-upsample`,({tile:e})=>e.unloadMapData()),this._elevationQueryCache=new Ce(n.newCache(`elevation-query`));let r=this.overlayManager;this.addHandles([h(()=>r.renderer.isEmpty,()=>this._evaluateTransparency()),h(()=>this.renderer.visible,e=>this.freeze=!e),h(()=>this.heading,e=>{this._renderer.updateHeading(e),this._updateTileTextures(0)},g)],`overlayManager`),this._updatingHandles.add(()=>({heading:e.camera?.heading,state:e.state?.mode}),({heading:e,state:t})=>{if(e==null)return;if(this.isGlobal&&this.isGeographic||this.isWebMercatorOnPlateCarree){this.heading=Math.round(e/90)*90%360;return}let n=Math.round(e)%360,r=Math.abs(n-this.heading);(t===2||Math.min(r,360-r)>=30)&&(this.heading=n)},_),this.addHandles([h(()=>this.baseOpacity,()=>{this._handleLayerViewChanges(),this._updateTileTextures(this._evaluateTransparency()?1:2)},g),h(()=>this.hasCompositeBlendMode,()=>this._updateTileTextures(this._evaluateTransparency()?1:2),g),h(()=>this.backgroundColor,(e,t)=>{e?.equals(t)||(this._handleLayerViewChanges(),this._renderer.updateTileBackground(e))},v),h(()=>this.snapLevel,()=>this._viewChanged=!0,v),h(()=>this.view.pointsOfInterest,e=>{this._renderer.pointsOfInterest=e,this._poiWatchHandle=l(this._poiWatchHandle),e&&(this._poiWatchHandle=this._updatingHandles.add(()=>e.focus?.renderLocation,()=>this._allTilesSorted=!1,{equals:ie}))}),h(()=>T.TERRAIN_TILE_TREE_SHOW_TILES,t=>{t&&!this._treeDebugger?import(`../layers/support/TerrainTileTree3DDebugger.js`).then(({TerrainTileTree3DDebugger:t})=>{!this._treeDebugger&&T.TERRAIN_TILE_TREE_SHOW_TILES&&(this._treeDebugger=new t({view:e}))}):t||(this._treeDebugger=u(this._treeDebugger))},_)]);let{spatialReference:a}=e;this._extentHelper=Le(this.viewingMode,{layers:e.map.allLayers,layerViews:e.allLayerViews,viewSpatialReference:a});let o=new i({getCollections:()=>e.defaultsFromMap?.mapCollections?.map(({layers:e})=>e),getChildrenFunction:e=>e&&`layers`in e?e.layers:null}),s=new ct({layers:o,extentHelper:this._extentHelper,viewingMode:this.viewingMode,viewSpatialReference:a});this._set(`tilingSchemeLogic`,s),this._updateTilingScheme();let c=t.scheduler;this._frameTask=c.registerTask(ht.TERRAIN_SURFACE,this),this.addHandles([h(()=>this._stencilEnabledExtents,e=>this._renderer.setStencilEnabledLayerExtents(e),_),h(()=>this.tilingSchemeLogic.tilingScheme,()=>this._updateTilingScheme(),v),h(()=>this.groundExtent,()=>this._updateRootTiles(),_),e.on(`resize`,()=>this._viewChangeUpdate()),h(()=>{let t=e.state;return[this._lodBias,this.lodSnappingEnabled,e.quality,t.camera,t.contentCamera,t.fixedContentCamera]},()=>this._viewChangeUpdate(),g),h(()=>e.qualitySettings?.fadeDuration,e=>this._renderer.textureFadingEnabled=e>0,_),h(()=>e.qualitySettings?.physicallyBasedRenderingEnabled,e=>this._renderer.pbrMode=e?5:0,_),h(()=>e.qualitySettings?.tiledSurface.elevationLevelDelta,()=>{this._allTiles.forAll(e=>this.updateElevationSources(e)),this._updateAllTileGeometries()}),h(()=>this.userClippingExtent,()=>this._updateClippingExtent(),v)]),this.addHandles(e.allLayerViews.on(`after-changes`,()=>this._layerViewsDirty=!0)),this._layerViewsDirty=!0,this._handleLayerViewChanges(),this._renderer.updateTileBackground(this.backgroundColor)}clearHandles(){this._updatingHandles?.removeAll(),this.removeAllHandles(),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear()}destroy(){this._waterproofnessErrorHandle?.remove(),this._waterproofnessErrorHandle=null,this._frameTask.remove(),this._frameTask=mt,this._updatingHandles?.destroy(),this._removeAllTiles(),this._set(`tilingSchemeLogic`,u(this.tilingSchemeLogic)),this._basemapLayerViewHandles.forEach((e,t)=>this._unregisterTiledLayerView(t)),this._basemapLayerViewHandles.clear(),this._set(`overlayManager`,u(this.overlayManager)),this._tileCache=u(this._tileCache),this._allTiles.prune(),nt.prune(),this._treeDebugger=u(this._treeDebugger),this._renderer.destroyed||(this.view.stage.removeRenderPlugin(this._renderer),this._renderer.destroy()),this._renderer=null,this._iteratorPool=u(this._iteratorPool),this._upsampleMapCache=u(this._upsampleMapCache),this._elevationQueryCache=u(this._elevationQueryCache),this._set(`view`,null),this._extentHelper=u(this._extentHelper),this._upsampleInfoPool=u(this._upsampleInfoPool),rt(),this._layerViews.forEach(e=>e.length=0),this._performanceInfo=null}get renderer(){return this._renderer}get frustum(){return this.view.state.camera.frustum}get snapLevel(){return this.lodSnappingEnabled?this.view.terrainLevel:null}get lodSnappingEnabled(){return this.view.qualitySettings.tiledSurface.reduceTileLevelDifferences}get upsampleInfoPool(){return this._upsampleInfoPool}get upsampleMapCache(){return this._upsampleMapCache}get elevationQueryCache(){return this._elevationQueryCache}get hasStencilEnabledExtents(){return!!this._stencilEnabledExtents?.length}get _stencilEnabledExtents(){let e=this.spatialReference,t=!!has(`enable-feature:im-as-ground`);return e==null?null:Iterator.from(this.view.allLayerViews).map(n=>{let{layer:r}=n;if(!we(r)||t&&!r.isUsedAsGroundLayer)return null;let{fullExtent:i}=r,a=i==null||i.spatialReference.equals(e)?i:le(i,i.spatialReference,e);return a?he(a):null}).filter(e=>e!=null).toArray()}get userClippingExtent(){let{spatialReference:e}=this,t=this.view?.clippingArea;if(t==null||e==null)return null;let n=S(),r=ke(t,n,e)?n:null,i=this._get(`userClippingExtent`);return C(r,i)?i:r}get rootTilesExtent(){return this._rootTilesExtent}get groundExtent(){let e=ge(this.fullGroundExtent,this.userClippingExtent,S()),t=this._get(`groundExtent`);return C(e,t)?t:e}get fullGroundExtent(){return this._tilingSchemeExtent==null?this._rootTilesExtent:this._tilingSchemeExtent}get _tilingSchemeExtent(){return this.tilingSchemeLogic?.extent}get updating(){return this._hasPendingUpdates||(this._maxNumUpdating=1),this.enabled&&!!((this.readyToRun||this._updatingHandles?.updating||this._asyncWorkItems>0)&&this.ready&&!this.freeze||this.overlayManager?.updating||this.terrainTextureCompressionTracker.compressing)}get readyToRun(){return this.enabled&&(this._hasPendingUpdates||this._viewChanged||this._allTilesDirty||!this._allTilesSorted||this._layerViewsDirty||this._scaleRangeQueries?.updating||this._frameTask.updating)&&this.ready&&!this.freeze}get updatingProgressValue(){return this._maxNumUpdating=Math.max(this._pendingUpdates,this._maxNumUpdating),1-this._pendingUpdates/this._maxNumUpdating}get baseOpacity(){return this.view?.map?.ground?.opacity??1}set baseOpacity(e){this.view.map.ground.opacity=e}get viewingMode(){return this.view.state.viewingMode}get ready(){return!this.enabled||this._rootTiles!=null}get rootTiles(){return this._rootTiles}get spatialReference(){return this.tilingScheme?.spatialReference??null}get backgroundColor(){return this.view?.map?.ground?.surfaceColor}set backgroundColor(e){this.view.map.ground.surfaceColor=e}set slicePlaneEnabled(e){this._renderer.slicePlaneEnabled=e,this._set(`slicePlaneEnabled`,e),this._evaluateTransparency()}get tilingSchemeLocked(){return this.tilingSchemeLogic?.tilingSchemeLocked??!1}get wireframe(){return this._renderer?.wireframe}set wireframe(e){e!==this._renderer.wireframe&&(this._renderer.wireframe=e,this._updateAllTileGeometries())}get opaque(){return this._renderer.transparency===0}get invisible(){return this._renderer.transparency===3}set freeze(e){this._set(`freeze`,e),this._viewChangeUpdate()}get fadeDuration(){return this.view.qualitySettings.fadeDuration??0}intersect(e,t,n,r){this._renderer.intersectRay(e,t,n,r)}getElevationLevelDelta(e){return e<4?3:this.view.qualitySettings.tiledSurface.elevationLevelDelta}get _xNormalizer(){return be(this._spatialReference)}getElevation(e,t,n,r){let i=this._rootTiles;if(!i?.length||!this.enabled||i[0].layerInfo[0].length===0)return null;let a=this._elevationProjectorCache.get(r);if(a===void 0&&(a=fe(r,this._spatialReference)??null,this._elevationProjectorCache.set(r,a)),a==null)return s.getLogger(this).error(`TerrainSurface.getElevation(): could not project given point to tiling scheme coordinate system`),null;let o=ae(K,e,t,n);a(o,0,o,0);let c=this._xNormalizer?.normalize(o[0])??o[0],l=o[1];return Y(i,c,l)}getElevations(e,t,n){let r=this._rootTiles,i=r?r[0].layerInfo[0].length:0;if(!r?.length||i===0||!this.enabled)for(let e=0;e<t;++e)n(e,null);else for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=Y(r,a,o);n(i,s)}}getLayerIndexByUID(e,t){return this._layerIndexByUid[e].get(t)}get visibleElevationRange(){let e=1/0,t=-1/0;for(let n of this._allTiles)n.renderData&&(e=Math.min(e,n.elevationBoundsMin),t=Math.max(t,n.elevationBoundsMax));let n=this._get(`visibleElevationRange`);return n?.minElevation===e&&n.maxElevation===t?n:new E(e,t)}invalidateElevationRange(){this.notifyChange(`visibleElevationRange`)}tileElevationRangeChanged(e,t=1/0,n=-1/0){let r=this._get(`visibleElevationRange`);(!r||t===r.minElevation||n===r.maxElevation||e.renderData&&(e.elevationBoundsMin<r.minElevation||e.elevationBoundsMax>r.maxElevation))&&this.invalidateElevationRange()}getScale(e){if(!this.tilingScheme)return null;if(!pe(e,K,this.spatialReference))return s.getLogger(this).error(`TerrainSurface.getScale(): could not project given point to tiling scheme coordinate system`),null;let t=this._rootTiles;if(t!=null){for(let e of t)if(e?.containsPoint(K)){let t=e;for(;t.children[0]&&!t.rendered;){let e=t.children[0].extent,n=0;K[0]>e[2]&&(n+=1),K[1]<e[1]&&(n+=2),t=t.children[n]}return this._getLodBiasCorrectedScale(t.level)}}return 1/0}getSphereElevationRange(e,t){if(!this.enabled)return null;let n=this._rootTiles,r=this._tilingSchemeSpatialReference;if(n==null||r==null||n.length===0)return null;let i=w(r);if(i){let n=w(t)&&D(t),i=x(t);if(n&&D(r)&&i===x(r))Ae(e,q,i.radius);else if(!je(e,t,q,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null}else if(!de(e,t,bt,r))return s.getLogger(this).error(`TerrainSurface.getSphereElevationRange(): could not project the query sphere`),null;let a=new E,o=[];for(let e of n)o.push(e);let c=0;for(;c<o.length;){let e=o[c];if(++c,!(i?Me(e.extent,q,r):_e(e.extent,bt)))continue;let t=e.children;if(t[0]==null||e.rendered)a.expandElevationRangeValues(e.elevationBoundsMin,e.elevationBoundsMax);else for(let e of t)o.push(e)}return a}getRootElevationRange(){return this.enabled&&this._rootTiles!=null?new E(this._rootTileElevationRange.minElevation,this._rootTileElevationRange.maxElevation):null}getLowerBoundRadius(){let e=this.visibleElevationRange,t=(this._ellipsoid.radius+(e.isEmpty?0:e.minElevation))*ce;return Math.min(t,this._ellipsoid.radius)}queryVisibleScaleRange(e,t,n,r){if(!this._scaleRangeQueries)return;let i=t?this.tilingScheme.levelAtScale(t):0,a=n?this.tilingScheme.levelAtScale(n):1/0,o=this._lodBias;this._scaleRangeQueries.queryVisibleLevelRange(e,i+o,a+o,r)}_evaluateTransparency(){let e=this.baseOpacity,t=this.overlayManager.renderer.isEmpty,n=this._renderer.transparency,r=this._isFullyTransparent?lt(0,t):e>=1&&!this.hasCompositeBlendMode&&!this._renderer.slicePlaneEnabled?0:1;return this._renderer.transparency=r,n!==r&&(this.notifyChange(`opaque`),this.notifyChange(`invisible`),!0)}_updateTilingScheme(){let{tilingScheme:e}=this.tilingSchemeLogic;if(e===this.tilingScheme)return;A(!!e,`tiling scheme cannot be reset to undefined`),this._isGlobal=!this.view?.state?.isLocal,this.tilingScheme&&this._removeAllTiles();let t=e?.spatialReference??ue.WebMercator;this._spatialReference=t,this._isWebMercator=!!t?.isWebMercator,this._isWebMercatorOnPlateCarree=this._isWebMercator&&xe(this.view?.renderSpatialReference),this._isGeographic=t?.isGeographic??!1,this._set(`tilingScheme`,e),this._tilingSchemeSpatialReference=this.tilingScheme?.spatialReference,this._updateClippingExtent(),e&&(this._updateTiledLayers(),this._renderer.tileSize=e.pixelSize,this.overlayManager.spatialReference=e.spatialReference,this._updateRootTiles())}static{this._tileMemcacheKey=`TerrainTileMemcache`}_acquireTile(e,t,n,r){let i=this._tileCache.pop(W._tileMemcacheKey);return i?(i.init(e,t,n,r,this),i):new this._tileConstructor(e,t,n,r,this)}get updatingRootTiles(){return this._updatingRootTiles}_updateRootTiles(){let{groundExtent:e,tilingScheme:t}=this;if(!t)return;if(!this.enabled){this._setRootTiles(null);return}let n=xt,i=t.rootTilesInExtent(e,n,O*5);if(this._rootTiles!=null){if(i.length>O){s.getLogger(this).warn(Ge);return}let e=this._rootTiles.map(e=>e.lij),t=r(e,i,V);if(this._updatingRootTiles=!0,t.removed.length>0||t.added.length>0){let e=this._rootTiles.filter(e=>t.removed.findIndex(t=>V(t,e.lij))>-1?(this._purgeTile(e),!1):!0);t.added.forEach(t=>e.push(this._newRootTile(t))),this._setRootTiles(e)}}else this._updatingRootTiles=!0,i.length>O&&(s.getLogger(this).warn(Ke),i=t.rootTilesInExtent(e,n,O)),this._setRootTiles(i.map(e=>this._newRootTile(e)));C(n,this._rootTilesExtent)||(this._rootTilesExtent=S(n)),this.renderer.visible=!0,this.overlayManager.setPlacementDirty(),this.notifyChange(`ready`),this._updateAllTileGeometries(),this._updatingRootTiles=!1,this._viewChangeUpdate(),this.checkAllTilesWaterproofness(`root-tiles-updated`)}_updateAllTileGeometries(){let e=this._allTiles.filter(e=>this._canUpdateTileGeometry(e));e.length===0||(e.sort(H),e.forEach(e=>this._renderer.updateTileGeometryState(e)),e.forEach(e=>e.renderData.updateNeighborData()),this._updateTilesGeometries(e)),this._pendingTilesToUpdate.clear()}_updateTilesGeometries(e){let t=e.filter(e=>this._canUpdateTileGeometry(e));if(t.length===0)return;let n=this.renderer;for(let e of t)n.updateGeometryIfNeeded(e);for(let e of t)this._pendingTilesForElevationUpdateEvent.add(e)}_canUpdateTileGeometry(e){return e.loaded&&e.intersectsClippingArea&&e.hasGeometryState}_shouldSplit(e){return e.shouldSplit(this._splitLimits,this._eyePosRenderSR,this.snapLevel)===1}_newRootTile(e){let t=this._acquireTile(0,e[1],e[2],null);return this._shouldSplit(t)&&t.setPendingUpdate(1),this._loadTile(t),this._markTileToUpdate(t),this._updateRootTileElevationRange(),t}_setRootTiles(e){if(this._rootTiles=e,this._allTiles.clear(),e!=null){let t=this._iteratorPool.acquire();for(t.reset(e);!t.done;)this._allTiles.push(t.next());t.remove()}this.invalidateElevationRange(),this._renderer.setRootTiles(this._rootTiles),this._updateTilesVisibility(e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_runViewChangeUpdateIfDirty(){this._viewChangeUpdateDirty&&(this._viewChangeUpdateDirty=!1,this._viewChangeUpdate())}_viewChangeUpdate(){this.view&&!this.freeze&&this.tilingScheme&&this.renderer.visible&&(this._inFrameTask||this._updatingRootTiles?this._viewChangeUpdateDirty=!0:(this._viewChangeUpdateDirty=!1,this._updateViewDependentParameters(),this._updateTilesVisibility(this._rootTiles)))}_updateClippingStatus(e){e.updateClippingStatus(this.groundExtent)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e)}_updateTilesVisibility(e){if(e==null)return;let t=this.groundExtent,n=this.view.state.contentCamera.viewProjectionMatrix;this.setTileTreeDirty(!1);let r=this._iteratorPool.acquire();for(r.reset(e);!r.done;){let e=r.next();e.updateClippingStatus(t)&&e.resetPendingUpdate(8)&&this._updateTileGeometryState(e),e.computeVisibility(),e.updateScreenDepth(n)}r.remove(),this._viewChanged=!0,this._allTilesDirty=!0,this._updatePendingTileGeometries()}_updateRootTileElevationRange(){let e=1/0,t=-1/0;this._rootTiles?.forEach(({elevationBoundsMin:n,elevationBoundsMax:r})=>{e=Math.min(e,n),t=Math.max(t,r)});let n=this._rootTileElevationRange;(n.minElevation!==e||n.maxElevation!==t)&&(this._rootTileElevationRange=new Pe(e,t))}_updateViewDependentParameters(){let{camera:e,contentCamera:t}=this.view.state,n=Math.tan(t.fovX*.5),r=Math.tan(t.fovY*.5),i=this.tilingScheme.pixelSize,a=2**-this._lodBias*e.pixelRatio;this._splitLimits.aboveGround=e.aboveGround,this._splitLimits.fovX=n,this._splitLimits.fovY=r,this._splitLimits.relativeWidthLimit=i/e.width*this.maxTextureScale*a,this._splitLimits.relativeHeightLimit=i/e.height*this.maxTextureScale*a,this._splitLimits.maxLod=this.tilingScheme.getMaxLod(),this._splitLimits.angledSplitBias=this.view.qualitySettings.tiledSurface.angledSplitBias,this.view.state.fixedContentCamera?this._splitLimits.frustum=ve(this._splitLimits.frustum??ye(),t.frustum):this._splitLimits.frustum=null,oe(this._eyePosRenderSR,t.eye),me(e.eye,this.view.renderSpatialReference,this._eyePosSurfaceSR,this.spatialReference)}_updateTileGeometryState(e){e.updateVisibility(),this._renderer.updateTileGeometryState(e)&&this._markTileToUpdate(e),this.setMemoryDirty()}_markAllTileNeighborsForUpdate(e){let t;e.forEachLoadedNeighbor(e=>{t??=this._layerViews[1].some(j),t&&e.setPendingUpdate(32),this._pendingTilesToUpdate.add(e)})}_updateTileTexture(e,t){let n=e.hasPendingUpdate(32)?32:e.hasPendingUpdate(16)?16:!1;if(n){let r=this._renderer.updateTileTexture(e,n);return this._usedMemory=null,r&&e.resetPendingUpdate(n),t.madeProgress(),r}return!0}_emitElevationUpdateEventForTiles(){if(!this._shouldEmitChangeEvent)return;let e=this._pendingTilesForElevationUpdateEvent;if(e.size>0){let t=new Float64Array(4*e.size),n=0;for(let r of e)t.set(r.extent,4*n),++n;e.clear();for(let e of Oe(t,this.spatialReference)){let t=new De(this.spatialReference,e,`ground`);this.emit(`elevation-change`,t)}}this._shouldEmitChangeEvent=!1}runTask(e){this._handleLayerViewChanges(e),this._frameTask.processQueue(e),this.renderer.processScaleRangeQueries(this._scaleRangeQueries,e),this._inFrameTask=!0,this._pendingUpdates=0,this._hasPendingUpdates=!1,this._updateAllTilesStatus(e),this._sortTiles(e);let t=!this.view.state.fixedContentCamera;this._mergeAndSplit(e,t),this._updateElevation(e);let n=this._updateTextures(e);t||this._mergeAndSplit(e,!0),this._inFrameTask=!1,this._runViewChangeUpdateIfDirty();let r=this._pendingTilesToUpdate.size>0,i=r&&this._hasPendingGeometryWithoutIndices();if((!e.done||i)&&this._updatePendingTileGeometries(),this._emitElevationUpdateEventForTiles(),e.done&&(e.hasProgressed||r&&!i)&&this.requestUpdate(),this.notifyChange(`updatingProgressValue`),!n||!e.hasProgressed)return vt}_checkTileInvariant(){}_updateAllTilesStatus(e){if(!this._viewChanged||!this._rootTiles||e.done)return;this._viewChanged=!1;let t=!1,n=new Ve(this._allTiles.length);n.pushAll(this._rootTiles);let r=this.snapLevel,i=this._splitLimits,a=this._eyePosRenderSR;this._allTiles.forAll(e=>{e.maxLevelDeltaNeighborCount=0,e.unmergableChildCount=0});let o=this.view.state.contentCamera.viewProjectionMatrix;for(;!n.empty;){let e=n.pop(),s=e.parent?.hasPendingUpdate(4),c=e.elevationLevel,l=s?4:e.shouldSplit(i,a,r),u=l===1;e.leaf?X(e,u):n.pushAll(e.children),s?(e.resetPendingUpdate(1),e.leaf||(e.setPendingUpdate(4),t=!0),this._updateClippingStatus(e),e.updateVisibility(),e.updateScreenDepth(o)):(u?(e.resetPendingUpdate(4),e.leaf&&(e.setPendingUpdate(1),t=!0)):(e.resetPendingUpdate(1)&&e.updateAgentSuspension(),l===2&&e.updateAgents(0),e.leaf||(e.setPendingUpdate(4),e.resetPendingUpdate(1),t=!0)),e.elevationLevel!==c&&this.updateElevationSources(e))}this._allTilesDirty=t,this.requestUpdate(),this._shortBatches&&this._updatePendingTileGeometries(),e.madeProgress()}_sortTiles(e){!e.done&&!this._allTilesSorted&&this.view.pointsOfInterest?.focus&&(st(this._allTiles,this.view.pointsOfInterest.focus.renderLocation),this._allTilesSorted=!0,this._treeDebugger?.update(),e.madeProgress())}_markTileToUpdate(e){M(e.loaded),e.intersectsClippingArea&&(this._pendingTilesToUpdate.add(e),this._markAllTileNeighborsForUpdate(e))}_hasPendingGeometryWithoutIndices(){for(let e of this._pendingTilesToUpdate)if(e.loaded&&e.intersectsClippingArea&&e.renderData?.vao?.indexBuffer==null)return!0;return!1}_updatePendingTileGeometries(){let e=this._pendingTilesToUpdate,t=[];if(e.forEach(e=>{this._canUpdateTileGeometry(e)&&t.push(e)}),t.length===0){e.clear();return}let n=(n,r)=>{!r||!this._canUpdateTileGeometry(r)||r.level<n.level||e.has(r)||(e.add(r),t.push(r),r.renderData.updateNeighborData())};t.sort(H);let r=t.length;for(let i=0;i<r;++i){let r=t[i];M(r.loaded),M(r.intersectsClippingArea);let a=r.renderData;if(!a?.geometryState)continue;a.updateNeighborData();let o=a.dirtyEdgeResolutions,s=a.geometryState,c=e=>{let t=tt[e];n(r,s.cornerPeerNeighbors[e]?.findCorner(Ze(t),e=>e.loaded))};for(let t=0;t<4;++t)if(o&1<<t){let i=a.geometryState.edgePeerNeighbors[t];i&&i?.level>=r.level&&i.forAllSubtreeOnSide(Xe(N[t]),t=>this._canUpdateTileGeometry(t)?(M(e.has(t)||H(r,t)<0),n(r,t),!0):!1),c((t+1)%4),c(t)}}e.clear(),t.sort(H),this._updateTilesGeometries(t),this._shouldEmitChangeEvent=!0,B&&Qe&&this.checkAllTilesWaterproofness(`pending-geometries-updated`)}_mergeAndSplit(e,t){if(this.freeze||e.done||!this._allTilesDirty)return;this._allTilesDirty=!1,this.requestUpdate();let n=!1,r=this.view.state.fixedContentCamera,i=!1;for(;!e.done;){i=!0;let a=!1,o=!this._allTiles.some(i=>{if(!n&&!r&&!i.visible)return e.done;let o=i;if(i.hasPendingUpdate(4)){if(!t||i.unmergableChildCount>0)return e.done;for(i.resetPendingUpdate(4);o.parent!=null&&o.parent.unmergableChildCount===0&&o.parent.resetPendingUpdate(4);)o=o.parent;this._mergeTile(o),a=!0,e.madeProgress()}else if(i.resetPendingUpdate(1)){let t=!0,n=i.level;if(n>=k){let e=e=>e.leaf||n-e.level<k;for(let r=0;r<4;++r){let a=i.findNeighborTile(N[r],e);a!=null&&n-a.level===k&&(t=!1,B&&(M(a.leaf),M(a.hasPendingUpdate(1))))}}t?(this._splitTile(i),e.madeProgress(),a=!0):i.setPendingUpdate(1)}return e.done});if(a&&(this._allTilesSorted=!1,this._allTilesDirty=!0),o){if(!n){n=!0;continue}if(!a)break}else this._allTilesDirty=!0}i?e.madeProgress():this._allTilesDirty=!0,this._allTilesCreated=!this.allTiles.some(e=>e.hasPendingUpdate(1)||e.hasPendingUpdate(4)&&e.unmergableChildCount===0),this._sortTiles(e)}_updateElevation(e){e.done||this._allTiles.some(t=>(t.resetPendingUpdate(8)&&(this._updateTileGeometryState(t),e.madeProgress()),e.done))}updateElevationSources(e){e.needsElevationSourceUpdate()&&(e.updateAgents(0),e.markElevationSourceUpdateRequested(),this.requestUpdate())}_updateTextures(e){if(e.done)return!0;let t=!0;return this._allTiles.some(n=>(this._updateTileTexture(n,e)||(t=!1),e.done)),t}_updateClippingExtent(){this.spatialReference&&(this.updateOverlayParameters(),this.requestRender(1),this.overlayManager.setPlacementDirty(),this._updateRootTiles())}get _lodBias(){return this.view.qualitySettings.tiledSurface.lodBias-(1-this.view.quality)*qe}_getLodBiasCorrectedScale(e){let t=this.tilingScheme.levels,n=c(e-this._lodBias,0,t.length-1),r=n-Math.floor(n),i=t[Math.floor(n)].scale,a=t[Math.ceil(n)].scale;return i*(1-r)+a*r}_removeAllTiles(){this.renderer.visible=!1,this._pendingTilesToUpdate.clear(),this._pendingTilesForElevationUpdateEvent.clear(),this._rootTiles!=null&&(this._rootTiles.forEach(e=>this._purgeTile(e)),this._setRootTiles(null),this.notifyChange(`ready`)),this._allTiles.clear(),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_purgeSubtree(e){let t=e.children;t[0]&&(this._purgeTile(t[0]),this._purgeTile(t[1]),this._purgeTile(t[2]),this._purgeTile(t[3]),e.clearChildren())}_purgeTile(e){e.leaf?Z(e):this._purgeSubtree(e),this._allTiles.removeUnordered(e),this._unloadTile(e),e.dispose(),this._tileCache.put(W._tileMemcacheKey,e),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles})}_unloadTile(e){this._pendingTilesToUpdate.delete(e),this._pendingTilesForElevationUpdateEvent.delete(e),e.unload()}_splitTile(e){A(e.leaf,`Tile that is already split should not be split again!`),A(e.rendered,`Tile marked to split is not rendered`),Z(e);let t=e.createChildren();this._allTiles.pushArray(t),this.notifyChange(`demResolution`),this.emit(`tiles-changed`,{allTiles:this.allTiles}),e.updateAgentSuspension(),A(e.rendered,`parent should be rendered`),t.forEach(e=>this._loadTile(e)),t.forEach(e=>this._pendingTilesToUpdate.add(e)),this._unloadTile(e),this._markAllTileNeighborsForUpdate(e),this._emitTileScaleChange(e,e.level+1),this._allTilesDirty=!0,this._shortBatches&&this._updatePendingTileGeometries(),t.forEach(e=>X(e,e.hasPendingUpdate(1))),++this._performanceInfo.numSplit}_emitTileScaleChange(e,t=e.level){J.spatialReference=this.spatialReference,J.extent=e.extent,J.scale=this._getLodBiasCorrectedScale(t),this.emit(`scale-change`,J)}createTile(e,t,n,r){A(!!r,`createTile sanity check`);let i=this._acquireTile(e,t,n,r);return i.updateClippingStatus(this.groundExtent),i.updateScreenDepth(this.view.state.contentCamera.viewProjectionMatrix),this._shouldSplit(i)&&i.setPendingUpdate(1),i}get _shortBatches(){return this.view.state.mode!==2}_mergeTile(e){A(!e.hasPendingUpdate(1),`_mergeTile sanity check`),A(!e.leaf,`Cannot merge a leaf`),e.leaf||(this._purgeSubtree(e),A(!e.renderData,`Merging tile with existing render data?`),this._loadTile(e),this._markTileToUpdate(e),this._emitTileScaleChange(e),this._shortBatches&&this._updatePendingTileGeometries(),X(e,!1),this._allTilesDirty=!0,++this._performanceInfo.numMerged)}_loadTile(e){e.load(),this.requestUpdate(),this._allTilesDirty=!0,this.overlayManager?.hasOverlays&&e.updateOverlayParameters(this.overlayManager)}_handleLayerViewChanges(e=gt){if(!this._layerViewsDirty)return;this._layerViewsDirty=!1;let t=!1,n=new Set,r=-1;for(let e=this.view.allLayerViews.length-1;e>=0;e--){let i=this.view.allLayerViews.items[e];if(n.add(i.uid),P(i)||F(i)){if(this._basemapLayerViewHandles.has(i.uid)&&!F(i)){let e=this._layerClassFromLayerView(i),n=this.getLayerIndexByUID(e,i.uid);n!=null&&((n<r||r==null)&&(t=!0),r=n)}else this._registerTiledLayerView(i),i.layer.loaded&&(t=!0)}}this._basemapLayerViewHandles.forEach((e,r)=>{n.has(r)||(this._unregisterTiledLayerView(r),t=!0)}),t&&this._updateTiledLayers(),this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._evaluateTransparency(),e.madeProgress()}get _isFullyTransparent(){if(this.view.map?.ground?.opacity>0)return!1;for(let e of this.view.allLayerViews.items)if(I(e)&&!Te(e.layer)&&e.fullOpacity!==0)return!1;return!0}_hasCompositeBlendMode(){for(let e of this.view.allLayerViews.items)if((L(e)||F(e))&&dt(ft[e.layer.blendMode]))return!0;return!1}_layerClassFromLayerView(e){return+!R(e)}_registerTiledLayerView(e){let t=[];if((L(e)||F(e))&&t.push(h(()=>e.layer.blendMode,()=>{this.hasCompositeBlendMode=this._hasCompositeBlendMode(),this._updateTileTextures(2)})),!F(e)){let n=this._layerClassFromLayerView(e);t.push(h(()=>!e.destroyed&&e.suspended,()=>this._updateTiledLayers())),t.push(h(()=>!e.destroyed&&e.fullOpacity,()=>this._updateTileTextures(2)));let{layer:r}=e;`effectiveScaleRange`in r&&t.push(h(()=>!e.destroyed&&r.effectiveScaleRange,()=>this._restartAllAgents(n))),t.push(e.on(`data-changed`,()=>{let t=this.getLayerIndexByUID(n,e.uid);t!=null&&this._invalidateLayerData(t,n)}))}this._unregisterTiledLayerView(e.uid),this._basemapLayerViewHandles.set(e.uid,t)}_unregisterTiledLayerView(e){let t=this._basemapLayerViewHandles.get(e);if(t){for(let e of t)e.remove();this._basemapLayerViewHandles.delete(e)}}_updateTiledLayers(){if(!this.tilingScheme||this.view.suspended)return;let e=this.view.allLayerViews,t=[[],[]],n=null;e.forEach(e=>{if(!e.layer||e.suspended||!P(e)||!e.fullExtent)return;let r=this._layerClassFromLayerView(e);if(r===1){let t=e.displayLevelRange.maxLevel;t!==1/0&&(n===null||t>n)&&(n=t)}t[r].push(e)});for(let e of Re){let n=this._layerViews[e],r=t[e];r.reverse();let i=r.length,a=n.length!==i,o=Array(i),s=Array(n.length);this._layerIndexByUid[e].clear();for(let t=0;t<i;t++){let i=r[t].uid;this._layerIndexByUid[e].set(i,t);let c=n.indexOf(r[t]);o[t]=c,t!==c&&(a=!0),c>-1&&(s[c]=t)}if(a){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;)t.next().modifyLayers(s,o,e);this._layerViews[e]=r,this._restartAllAgents(e),this._updateTilesVisibility(this._rootTiles)}}this.tilingScheme.ensureMaxLod(n)&&(this._viewChangeUpdate(),this.notifyChange(`tilingScheme`))}_restartAllAgents(e){let t=this._postorderIterator;for(t.reset(this._rootTiles);!t.done;){let n=t.next();n.restartAgents(e),e===0&&n.computeElevationBounds()}this._updateRootTileElevationRange()}layerViewByIndex(e,t){return this._layerViews[t][e]}numLayers(e){return this._layerViews[e].length}_updateTileTextures(e){this._allTiles.forAll(t=>{t.updateAgents(1),e===1?this.renderer.updateTileTexture(t,16):t.updateRenderData(1,e)}),this._evaluateTransparency()}_invalidateLayerData(e,t){this._rootTiles!=null&&(U(this._rootTiles,n=>n.removeLayerAgent(e,t)),U(this._rootTiles,n=>{n.invalidateLayerData(e,t),n.restartAgents(t)}))}setTileTreeDirty(e){this._allTilesDirty=!0,e&&(this._allTilesCreated=!1)}requestRender(e=1){this.renderer.requestRender(e)}requestUpdate(){++this._pendingUpdates===1&&(this._hasPendingUpdates=!0)}requestTileData(e,t,n,r){let i=this.layerViewByIndex(t,n),{tilemapCache:a}=i;return!a||j(i)?this._requestTileData(e,n,i,r):(++this._asyncWorkItems,a.fetchAvailability(e.level,e.lij[1],e.lij[2],{...r,timeout:6e3}).catch(t=>{throw te(r),p(t)||this._dataMissing(e,n,i),t}).then(()=>this._frameTask.schedule(()=>this._requestTileData(e,n,i,r),r.signal)).finally(()=>--this._asyncWorkItems))}_requestTileData(e,t,n,r){return this.destroying?Promise.resolve():t===0?R(n)?this._requestElevationTileData(e,n,r):Promise.reject():I(n)?this._requestMapTileData(e,n,r):Promise.reject()}_requestElevationTileData(e,t,n){++this._asyncWorkItems;let r=r=>{!m(n)&&r&&(this.setMemoryDirty(),this.requestUpdate(),this._elevationDataArrived(e,t,r))},i=n=>{p(n)||(s.getLogger(this).error(`Tile ${e.lij.toString()} layer 0/${t.uid} error ${n}`),this._dataMissing(e,0,t),this.requestUpdate())};return t.fetchElevationTile(e,{...Ee,...n}).then(e=>this._frameTask.schedule(()=>r(e)),i).finally(()=>--this._asyncWorkItems)}_elevationDataArrived(e,t,n){let r=this._layerIndexByUid[0].get(t.uid);if(r==null){s.getLogger(this).warn(`TerrainSurface: received data from unknown layer %d %s`,0,e.lij.toString());return}let i=new Fe(e.lij,e.extent,n);e.dataArrived(r,0,i),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:0});let a=[e],o=e.level,c=this._iteratorPool.acquire();for(c.reset(a);!c.done;){let e=c.next();e.findElevationBoundsForLayer(r,o),e.computeElevationBounds()}o===0&&this._updateRootTileElevationRange(),c.remove(),this._updateTilesVisibility(a)}_requestMapTileData(e,t,n){++this._asyncWorkItems;let r=(r,i)=>{z(i),m(n)||(console.error(`Tile ${e.lij.toString()} layer 1/${t.uid} error ${r}`),this._dataMissing(e,1,t),this.requestUpdate())},i=e=>t=>r(t,e);return t.fetchTile(e.lij,n).then(r=>this._frameTask.schedule(()=>{this.requestUpdate(),m(n)?z(r):this._mapTileDataArrived(e,t,r)},n.signal,i(r)).catch(i(r)),(e,t=null)=>this._frameTask.schedule(()=>r(e,t))).finally(()=>--this._asyncWorkItems)}_mapTileDataArrived(e,t,n){let r=this.getLayerIndexByUID(1,t.uid);r==null?(z(n),s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`)):(e.dataArrived(r,1,n),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:1}))}_dataMissing(e,t,n){let r=this.getLayerIndexByUID(t,n.uid);r==null?s.getLogger(this).warn(`TerrainSurface: received data from unknown layer`):(e.dataMissing(r,t),this.emit(`tile-data-changed`,{tile:e,layerIndex:r,layerClass:t}))}get performanceInfo(){let e=this._performanceInfo;return e.numNodes=this._allTiles.length,e.numLeaves=e.numVisible=e.numRendered=e.numLoadedPerLevel.length=e.numRenderedPerLevel.length=0,this._allTiles.forAll(t=>{t.leaf&&e.numLeaves++;let n=t.level;t.renderData&&(e.numLoadedPerLevel[n]=(e.numLoadedPerLevel[n]||0)+1),t.visible&&(e.numVisible++,t.rendered&&(e.numRenderedPerLevel[n]=(e.numRenderedPerLevel[n]||0)+1,e.numRendered++))}),e}setMemoryDirty(){this._usedMemory=null}get usedMemory(){return this.tilingScheme?(this._usedMemory??=this._recalculateUsedMemory(),this._usedMemory??0):0}_recalculateUsedMemory(){return this.tilingScheme?Math.round(this._allTiles.reduce((e,t)=>e+t.usedMemory,0)):null}getUsedMemoryForLayerView(e){let t=0,n=this._layerClassFromLayerView(e),r=this.getLayerIndexByUID(n,e.uid);return r!=null&&this._allTiles.forAll(e=>t+=e.getUsedMemoryForLayer(n,r)),t}get renderPatchBorders(){return this._renderer.renderPatchBorders}set renderPatchBorders(e){this._renderer.renderPatchBorders=e}get renderingDisabled(){return this._renderer.renderingDisabled}set renderingDisabled(e){this._renderer.renderingDisabled=e}get test(){}checkAllTilesWaterproofness(e=`render-patch-groups`){}get isGlobal(){return this._isGlobal}get isGeographic(){return this._isGeographic}get isWebMercator(){return this._isWebMercator}get isWebMercatorOnPlateCarree(){return this._isWebMercatorOnPlateCarree}isEastEndWrap(e){return this._isGlobal&&e[2]===this.lijEastEnd(e[0])-1}isWestEndWrap(e){return this._isGlobal&&e[2]===0}lijEastEnd(e){return 1<<e+ +!!this._isGeographic}wrapEastWest(e){let t=this.lijEastEnd(e[0]),n=e[2];if(0<=n&&n<t)return e;if(!this._isGlobal)return null;let r=(n+(n<0?t:0))%t;return[e[0],e[1],r]}enableInternalChecks(e){$e(e)}enableWaterproofnessChecks(e){et(e)}static cleanupTerrainSurface(){St.prune()}enable(e){e!==this.enabled&&(this._set(`enabled`,e),e?(this._updateRootTiles(),this.freeze=!1,this.view.elevationProvider.register(0,this)):(this.view.elevationProvider.unregister(this),this.freeze=!0,this._removeAllTiles(),this._setRootTiles(null)),this.notifyChange(`ready`))}updateOverlayParameters(){let{overlayManager:e}=this;this.allTiles.forAll(t=>t.updateOverlayParameters(e))}};e([y()],G.prototype,`_renderer`,void 0),e([y({constructOnly:!0})],G.prototype,`_scaleRangeQueries`,void 0),e([y({constructOnly:!0})],G.prototype,`view`,void 0),e([y({constructOnly:!0})],G.prototype,`overlayManager`,void 0),e([y()],G.prototype,`_hasPendingUpdates`,void 0),e([y()],G.prototype,`_asyncWorkItems`,void 0),e([y()],G.prototype,`_allTilesDirty`,void 0),e([y()],G.prototype,`_allTilesSorted`,void 0),e([y()],G.prototype,`allTilesCreated`,null),e([y()],G.prototype,`_allTilesCreated`,void 0),e([y()],G.prototype,`_viewChanged`,void 0),e([y({type:Number})],G.prototype,`heading`,void 0),e([y()],G.prototype,`_splitLimits`,void 0),e([y()],G.prototype,`_frameTask`,void 0),e([y()],G.prototype,`demResolution`,null),e([y({readOnly:!0})],G.prototype,`snapLevel`,null),e([y({readOnly:!0})],G.prototype,`lodSnappingEnabled`,null),e([y()],G.prototype,`_stencilEnabledExtents`,null),e([y({readOnly:!0})],G.prototype,`userClippingExtent`,null),e([y()],G.prototype,`_rootTilesExtent`,void 0),e([y({readOnly:!0})],G.prototype,`groundExtent`,null),e([y({readOnly:!0})],G.prototype,`fullGroundExtent`,null),e([y({readOnly:!0})],G.prototype,`_tilingSchemeExtent`,null),e([y({readOnly:!0})],G.prototype,`updating`,null),e([y({readOnly:!0})],G.prototype,`readyToRun`,null),e([y(Ne)],G.prototype,`updatingProgress`,void 0),e([y({readOnly:!0})],G.prototype,`updatingProgressValue`,null),e([y()],G.prototype,`_maxNumUpdating`,void 0),e([y()],G.prototype,`baseOpacity`,null),e([y()],G.prototype,`hasCompositeBlendMode`,void 0),e([y({readOnly:!0})],G.prototype,`viewingMode`,null),e([y()],G.prototype,`maxTextureScale`,void 0),e([y({readOnly:!0})],G.prototype,`ready`,null),e([y({readOnly:!0})],G.prototype,`rootTiles`,null),e([y()],G.prototype,`_rootTiles`,void 0),e([y({readOnly:!0})],G.prototype,`spatialReference`,null),e([y({type:t})],G.prototype,`backgroundColor`,null),e([y({value:!1})],G.prototype,`slicePlaneEnabled`,null),e([y({readOnly:!0})],G.prototype,`tilingScheme`,void 0),e([y({readOnly:!0})],G.prototype,`tilingSchemeLocked`,null),e([y({readOnly:!0})],G.prototype,`tilingSchemeLogic`,void 0),e([y()],G.prototype,`wireframe`,null),e([y()],G.prototype,`opaque`,null),e([y()],G.prototype,`invisible`,null),e([y({value:!1})],G.prototype,`freeze`,null),e([y()],G.prototype,`fadeDuration`,null),e([y()],G.prototype,`_xNormalizer`,null),e([y()],G.prototype,`visibleElevationRange`,null),e([y()],G.prototype,`_rootTileElevationRange`,void 0),e([y()],G.prototype,`_layerViewsDirty`,void 0),e([y()],G.prototype,`renderPatchBorders`,null),e([y()],G.prototype,`renderingDisabled`,null),e([y({readOnly:!0})],G.prototype,`enabled`,void 0),G=W=e([re(`esri.views.3d.terrain.TerrainSurface`)],G);const yt=G,K=b(),bt=new Se,q=S(),xt=S(),St=new f,J={spatialReference:null,extent:null,scale:0};function Y(e,t,n){for(let r of e){if(!r.containsPointXY(t,n))continue;let e=r;for(;e&&!e.renderData;){let r=+(t>e.extentMidX)+(n<e.extentMidY?2:0);e=e.children[r]}let i=e?.renderData?.geometryState.samplerData??null;return Ie(t,n,i)}return null}function X(e,t){!e.leaf||e.level<k||$(e,e=>{t&&Ct(e);let n=Q(e);if(e.maxLevelDeltaNeighborCount++,n){let t=e.parent;for(;t;){let e=Q(t);if(t.unmergableChildCount++,e)t=t.parent;else break}}})}function Ct(e){if(e.hasPendingUpdate(1))return;let t=e.parent;for(;t?.resetPendingUpdate(4);)t=t.parent;e.resetPendingUpdate(4),e.leaf&&e.setPendingUpdate(1),e.level<k||$(e,e=>{Ct(e)})}function Z(e){e.level<k||$(e,e=>{if(e.maxLevelDeltaNeighborCount--,e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0){let t=e.parent;for(;t&&(t.unmergableChildCount--,Q(t));)t=t.parent}})}function Q(e){return e.maxLevelDeltaNeighborCount===0&&e.unmergableChildCount===0}function $(e,t){if(e.level<k)return;let n=e.level-k,r=e.lij[1]>>k,i=e.lij[2]>>k,a=e=>e.leaf||e.level===n;for(let o=0;o<4;++o){let s=e.findNeighborTile(N[o],a);if(!s||s.level!==n)continue;let c=s.lij;(c[1]!==r||c[2]!==i)&&t(s)}}export{yt as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{toConst as e}from"../../../core/compilerUtils.js";import"../../../core/has.js";import{clamp as t}from"../../../core/mathUtils.js";import{abortMaybe as n}from"../../../core/maybe.js";import r from"../../../core/ObjectPool.js";import{subtract as i,squaredLength as a,dot as o,scale as s,add as c,length as l,copy as u}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as d,unitZ as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as p}from"../../../geometry/ellipsoidUtils.js";import{create as m,equals as h,rectangleContainsRectangleCyclicalAware as g,rectanglesIntersectCyclicalAware as _,width as v,height as y}from"../../../geometry/support/aaBoundingRect.js";import{Sphere as b}from"../../../geometry/support/sphere.js";import{isGroupLayer as x}from"../../../layers/support/layerUtils.js";import{isLayerViewWithFlowRenderer as S}from"../support/flowUtils.js";import{ElevationBounds as C}from"./ElevationBounds.js";import{ElevationTileAgent as w,isElevationTileAgent as T}from"./ElevationTileAgent.js";import{LayerClasses as E}from"./LayerClass.js";import{MapDataCacheItem as D}from"./MapDataCacheItem.js";import{MapTileAgent as O,isMapTileAgent as ee}from"./MapTileAgent.js";import{maxPatchTesselation as te}from"./TerrainConst.js";import{isVectorTile as k,isTileTexture as ne,isRasterTile as re,isCreateBitmapResult as ie}from"./TerrainData.js";import{weakAssert as A,isBlendableLayerView as ae,oppositeCorner as j,internalAssert as M,enableTerrainInternalChecks as N,neighborEdgeIndices as P,oppositeEdge as F,neighborCornerIndices as I,almostEquals as L,isNorth as R,isSouth as z,isWest as B,isEast as V,isWestCorner as oe,isNorthCorner as se}from"./terrainUtils.js";import{tileAgentDone as H}from"./TileAgent.js";import{TilePerLayerInfo as U}from"./TilePerLayerInfo.js";import{fallsWithinLayerView as W}from"./tileUtils.js";class ce{constructor(){this._lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this._dirty=!0,this._previouslyRendered=!1,this._lastElevationSourceUpdateRequestSignature=null,this.extent=m(),this._elevationBoundsMin=NaN,this._elevationBoundsMax=0,this.layerInfo=[[],[]],this.extentInRadians=m(),this.centerAtSeaLevel=d(),this._center=[d(),new b,d()],this.up=f(),this._withinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=0,this._rasterTileMemory=0,this._vectorTileMemory=0,this._mapDataRefCount=0,this.screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0,this.onCompressionFinished=()=>{this.setPendingUpdate(16),this.setMemoryDirty()},this.extentMidX=0,this.extentMidY=0,this.distanceToPOI=-1,this._lastPOI=d(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0}get lij(){return this._lij}get spatialReference(){return this._surface.spatialReference??this._surface.tilingScheme.spatialReference}get isDisposed(){return this._surface==null}get elevationLevelDelta(){return this._surface.getElevationLevelDelta(this.level)}_setPendingUpdateForDescendants(){let e=this._children;if(e[0])for(let t of e)t.renderData&&(t.setPendingUpdate(16),t.setMemoryDirty()),t._setPendingUpdateForDescendants()}static prune(){K.prune(0),q.prune(0),U.prune()}get _cached(){return!this.leaf&&this._mapDataRefCount<=0}get withinClippingArea(){return this._withinClippingArea}get intersectsClippingArea(){return this._intersectsClippingArea}get clippingArea(){return this._clippingArea}get parent(){return this._parent}get children(){return this._children}get surface(){return this._surface}get elevationBoundsMin(){return this._elevationBoundsMin}get elevationBoundsMax(){return this._elevationBoundsMax}get level(){return this._lij[0]}get key(){return`${this._lij[0]}/${this._lij[1]}/${this._lij[2]}`}get edgeLen(){return this._edgeLen}get radius(){return this._center[1].radius}get visible(){return this._dirty&&this.computeVisibility(),this._visible}get frustumVisibility(){return this._dirty&&this.computeVisibility(),this._frustumVisibility}checkVisibility(e){if(this._dirty)return null;let t=this._calculateVisibility(e);if(this._frustumVisibility!==t||this._visible!==(t!==2&&this._intersectsClippingArea))throw Error(`Assertion failed: waterproof.visibility-cache-mismatch: Tile[${this.lij}]`);return t}computeVisibility(){this._dirty=!1;let e=this.parent?.frustumVisibility??1;this._frustumVisibility=this._calculateVisibility(e);let t=this._frustumVisibility!==2&&this._intersectsClippingArea;t!==this._visible&&(this._visible=t,this._surface.emit(`tiles-visibility-changed`),this._surface.renderer.setDirty(),this.updateAgentSuspension())}_calculateVisibility(e){let t=this.parent;return e===0?0:t!=null&&e===2&&this._elevationBoundsMin>=t._elevationBoundsMin&&this._elevationBoundsMax<=t._elevationBoundsMax?2:this._calculateFrustumVisibility(this.surface.frustum,this._surface.view.frustum.boundingSphere)}get _loadable(){return this.visible||this._surface.view.state.fixedContentCamera}get rendered(){let e=!!this.renderData;return e!==this._previouslyRendered&&(this._surface.emit(`tiles-visibility-changed`),this._previouslyRendered=e,this._surface.renderer.setDirty()),e}init(e,t,n,r,i){this._lij[0]=e,this._lij[1]=t,this._lij[2]=n,this.ellipsoid=p(i.tilingScheme.spatialReference),i.tilingScheme.getExtent(e,t,n,this.extent),i.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this.extentMidX=.5*(this.extent[0]+this.extent[2]),this.extentMidY=.5*(this.extent[1]+this.extent[3]),this._withinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,i.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[1].radius=0,this.elevationLevel=e,this._lastElevationSourceUpdateRequestSignature=null,r&&!Number.isNaN(r.elevationBoundsMin)?(this._elevationBoundsMin=r.elevationBoundsMin,this._elevationBoundsMax=r.elevationBoundsMax):(this._elevationBoundsMin=0,this._elevationBoundsMax=0),this._pendingUpdates=0,this.renderData=null,this.screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=r,this.clearChildren(),this._surface=i,this.updateVisibility(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0;for(let e of E){let t=i.numLayers(e),n=this.layerInfo[e];for(let e of n)e.release();n.length=t;for(let r=0;r<t;r++)n[r]=U.acquire(this._surface.upsampleInfoPool),e===0&&this.findElevationBoundsForLayer(r,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(i.tilingScheme.pixelSize,te)}dispose(){A(!this.renderData,`tile.renderData was not unloaded`),this._surface?.upsampleMapCache.pop(this.key),this.layerInfo.forEach(e=>{e.forEach(e=>e.release()),e.length=0}),this._surface=this._parent=null,this.clearChildren(),this.setMemoryDirty()}refMapData(){++this._mapDataRefCount,this._cached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){--this._mapDataRefCount,this._cached&&this.cachedMemory>0&&this._surface.upsampleMapCache.put(this.key,new D(e(this)))}setMemoryDirty(){this._usedMemory=0}get usedMemory(){return this._ensureUsedMemory()+(this._cached?0:this.mapDataMemory)}get cachedMemory(){return this._ensureUsedMemory(),this._surface==null?this.usedMemory:this._cached?this.mapDataMemory:0}get mapDataMemory(){return this._rasterTileMemory+this._vectorTileMemory}get _cpuImageMemorySize(){let e=this._surface.tilingScheme.pixelSize;return e*e*4}_ensureUsedMemory(){if(this._usedMemory>0)return this._vectorTileMemory=this.layerInfo[1].reduce((e,{data:t})=>e+(k(t)?t.usedMemoryPerReference:0),0),this._usedMemory;this._usedMemory=this._baseUsedMemory,this._rasterTileMemory=0,this._vectorTileMemory=0;for(let{data:e}of this.layerInfo[1])k(e)?this._vectorTileMemory+=e.usedMemoryPerReference:this._rasterTileMemory+=this.getTerrainDataMemory(e);for(let e of this.layerInfo[0])this._usedMemory+=e.data?this._cpuImageMemorySize:0;return this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._rasterTileMemory+=this.renderData.texture?.usedMemory??0),this._cached&&this._surface.upsampleMapCache.updateSize(this.key),this._usedMemory}getUsedMemoryForLayer(e,t){let n=this.layerInfo[e][t];return n?.data?e===1?this._cached?0:this.getTerrainDataMemory(n.data):e===0?this._cpuImageMemorySize:0:0}getTerrainDataMemory(e){return ne(e)?e.texture.usedMemory:re(e)?e.memoryUsage:k(e)?e.usedMemoryPerReference:ie(e)?this._cpuImageMemorySize:0}updateScreenDepth(e){let[t,n,r]=this._center[1].center,i=e,a=i[2]*t+i[6]*n+i[10]*r+i[14];this.screenDepth=a<0?0:a/(i[3]*t+i[7]*n+i[11]*r+i[15])}shouldSplit(e,t,n){if(!this.visible||e.frustum&&!(this._intersectsClippingArea&&this._calculateFrustumVisibility(e.frustum)!==2))return 0;let r=this.level;i(Q,this._center[1].center,t);let u=a(Q),d=this._closestCenterOnElevationRange(t,fe),f=i(pe,d,t),p=Math.min(u,a(f));if(this._edgeLen2>p&&r<e.maxLod)return 1;let m=Math.sqrt(p),h=e.fovX*m*2,g=this._edgeLen/h,_=()=>{if(r<e.maxLod)return this.elevationLevel=r,0;let t=r+Math.ceil(-Math.log2(e.relativeWidthLimit/g));return t===this.elevationLevel?0:(this.elevationLevel=t,2)},v=n==null?1/0:n-r;if(v<=.5)return _();let y=o(this.up,Q),b=this._elevationBoundsMax-this._elevationBoundsMin,x=b/this.edgeLen;if(e.aboveGround&&y>0&&x<.001&&y/m-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-x>0)return _();let S=n==null?1:3-Math.min(v,2);if(g*S<e.relativeWidthLimit||r>=e.maxLod)return _();if(r<7)return 1;s($,this.up,y),i($,$,f);let C=a($);if(C<=this.radius*this.radius)return 1;s($,$,this.radius/Math.sqrt(C)),c($,$,d),i($,t,$);let w=Math.min(1,(Math.abs(o($,this.up))+.5*b+this._curvatureHeight)/l($)),T=.1/e.angledSplitBias,E=e.fovY*m*2;return w*(this._edgeLen/E*S)<T*e.relativeHeightLimit?_():1}needsElevationSourceUpdate(){let e=this.renderData?.geometryState.samplerDataSourceLevels;if(e==null)return!1;let t=Math.max(this.elevationLevel-this.elevationLevelDelta,0);return e.some(e=>e>t)&&this._lastElevationSourceUpdateRequestSignature!==this._elevationSourceUpdateRequestSignature(e)}markElevationSourceUpdateRequested(){let e=this.renderData?.geometryState.samplerDataSourceLevels;this._lastElevationSourceUpdateRequestSignature=e==null?null:this._elevationSourceUpdateRequestSignature(e)}_elevationSourceUpdateRequestSignature(e){return`${Math.max(this.elevationLevel-this.elevationLevelDelta,0)}:${e.join(`,`)}`}createChildren(){let e=this._children,t=this.lij[0]+1,n=this.lij[1]*2,r=this.lij[2]*2;return e[0]=this.surface.createTile(t,n,r,this),e[1]=this.surface.createTile(t,n,r+1,this),e[2]=this.surface.createTile(t,n+1,r,this),e[3]=this.surface.createTile(t,n+1,r+1,this),e}clearChildren(){this._children[0]=this._children[1]=this._children[2]=this._children[3]=null}get loaded(){return this.renderData?.hasGeometry??!1}get hasGeometryState(){return this.renderData?.geometryState!=null}load(){this.refMapData();for(let e of E)this._createOrUpdateAgents(0,e);this.surface.renderer.loadTile(this)}unload(){this.renderData&&this.unrefMapData(),this.surface.renderer.unloadTile(this);for(let e of E){let t=this.layerInfo[e];for(let e of t)e.loadingAgent&&e.loadingAgent!==H&&(G(e.loadingAgent),e.loadingAgent=null),e.pendingUpdates=0}this.resetPendingUpdate(8),this.resetPendingUpdate(16),this.resetPendingUpdate(32)}unloadMapData(){let e=this.layerInfo[1];for(let t of e)t.loadingAgent&&t.loadingAgent!==H&&(G(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0,t.invalidateSourceData();this.renderData?.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(h(e,this._clippingArea))return!1;let t=this._intersectsClippingArea,n=this._withinClippingArea;e==null?(this._intersectsClippingArea=!0,this._withinClippingArea=!0):(this._intersectsClippingArea=this.intersectsExtent(e),this._withinClippingArea=this._isWithinExtent(e)),this._clippingArea=e,this.updateVisibility();let r=n&&this._withinClippingArea,i=!n&&!t&&!this._withinClippingArea&&!this._intersectsClippingArea;return this.renderData&&!(r||i)&&this.setPendingUpdate(8),!0}updateVisibility(){this._dirty=!0,this._surface.setTileTreeDirty(!1)}getLayerInfo(e,t){return this.layerInfo[t][e]}hasLayerData(e,t){let n=this.layerInfo[t][e];return!(!n?.data||n.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(let e of E){let t=this.layerInfo[e];for(let e of t)if(e.loadingAgent&&e.loadingAgent!==H&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return this.hasPendingUpdate(1)?!0:e!==0&&!this._loadable}get hasPendingUpdates(){return this._pendingUpdates!==0}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){let t=this._pendingUpdates;return this._pendingUpdates|=e,e===1||e===4?this._surface.setTileTreeDirty(!0):this._surface.requestUpdate(),t!==this._pendingUpdates}resetPendingUpdate(e){return this.hasPendingUpdate(e)?(this._pendingUpdates&=~e,!0):!1}requestLayerData(e,t,r){let i=this.layerInfo[t][e];if(i.waitingAgents.has(r))return console.warn(`agent already requested this piece of map data (tile %s, agent tile %s, layer: %d/%d)`,this._lij.toString(),r.tile.lij.toString(),t,e),!0;if(i.waitingAgents.push(r),i.data&&!i.dataInvalidated){console.warn(`agent requested existing data (tile %s, agent tile %s, layer: %d/%d)`,this._lij.toString(),r.tile.lij.toString(),t,e);let n=k(i.data);return r.dataArrived(this,n),!0}if(i.requestPromise)return!0;n(i.requestAbort),i.requestAbort=new AbortController;let a=this._surface.requestTileData(this,e,t,{signal:i.requestAbort.signal});if(!a)return i.requestAbort=null,!1;let o=()=>{i.requestPromise===a&&(i.requestPromise=null,i.requestAbort=null)};return i.requestPromise=a,a.then(o,o),!0}get leaf(){return this._children[0]==null}hasLij(e){return this._lij[0]===e[0]&&this._lij[1]===e[1]&&this._lij[2]===e[2]}findByLij(e){if(this.hasLij(e))return this;let t=this._children;return t[0]?t[0].findByLij(e)||t[1].findByLij(e)||t[2].findByLij(e)||t[3].findByLij(e):null}distanceToSquared(e){return a(i($,this._center[1].center,e))}containsPoint(e){let t=this.extent;return e[0]>=t[0]&&e[1]>=t[1]&&e[0]<=t[2]&&e[1]<=t[3]}containsPointXY(e,t){let n=this.extent;return e>=n[0]&&t>=n[1]&&e<=n[2]&&t<=n[3]}unrequestLayerData(e,t,n){let r=this.layerInfo[t][e],i=r.waitingAgents,a=i.removeUnordered(n)!=null;A(a,`agent has not requested this piece of map data`),i.length<1&&(r.abortRequest(),this.setMemoryDirty())}dataArrived(e,t,n){let r=k(n),i=this.layerInfo[t][e];i.data=n,i.dataInvalidated=!1,i.waitingAgents.forAll(e=>e.dataArrived(this,r)),i.waitingAgents.clear(),this.setMemoryDirty()}dataMissing(e,t){let n=this.layerInfo[t][e];n.dataMissing=!0,n.waitingAgents.forAll(e=>e.dataMissing()),n.waitingAgents.clear(),this.setMemoryDirty()}updateRenderData(e,t,n){switch(n&&this.forEachLoadedNeighbor(n=>n.updateRenderData(e,t)),e){case 1:return this._updateTexture(t);case 0:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===0?16:32),this.setPendingUpdate(e===0?32:16))}_updateGeometry(){this.setPendingUpdate(8);for(let e of this.layerInfo[0])e.pendingUpdates|=8}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData()}computeElevationBounds(){let e=this._elevationBoundsMin,t=this._elevationBoundsMax,n=1/0,r=-1/0,i=this.layerInfo[0],a=!0;for(let e of i)e.elevationBounds!=null&&(n=Math.min(n,e.elevationBounds.minElevation),r=Math.max(r,e.elevationBounds.maxElevation),e.elevationBounds.hasNoDataValues||(a=!1));a&&(n=Math.min(n,0),r=Math.max(r,0)),(e!==n||t!==r)&&(this._elevationBoundsMin=n,this._elevationBoundsMax=r,this.updateRadiusAndCenter(),this._surface.setTileTreeDirty(!1))}_updateCenter(){let e=this._elevationBoundsMin,t=this._elevationBoundsMax,n=.5*(e+t),r=this._center;s($,this.up,n),c(r[1].center,this.centerAtSeaLevel,$),s($,this.up,e),c(r[0],this.centerAtSeaLevel,$),s($,this.up,t),c(r[2],this.centerAtSeaLevel,$)}_closestCenterOnElevationRange(e,t){if(this._surface.viewingMode===1){if(this.level===0)return u(t,this._center[1].center);let n=o(this.up,e),r=Math.max(this.ellipsoid.radius+this._elevationBoundsMin,Math.min(this.ellipsoid.radius+this._elevationBoundsMax,n));return s(t,this.up,r)}let n=Math.max(this._elevationBoundsMin,Math.min(this._elevationBoundsMax,e[2]));return t[0]=this.centerAtSeaLevel[0],t[1]=this.centerAtSeaLevel[1],t[2]=n,t}findElevationBoundsForLayer(e,t){let n=this.layerInfo[0][e],r=this.elevationLevelDelta,i=Math.max(this.elevationLevel-r,0),a=n.elevationBounds;if(a!=null&&a.level>t&&a.level<=i)return;let o=this._surface.layerViewByIndex(e,0);if(!W(this,o))return;let s=ue,c=!1,l=n.data;if(l&&l.level<=i){let e=n.data;s.minElevation=e.samplerData.data.minValue,s.maxElevation=e.samplerData.data.maxValue,s.hasNoDataValues=e.samplerData.data.hasNoDataValues,s.level=this.level,c=!0}else{let t=0,n,a;for(let o=this._parent;o&&(!a||t<r)&&(t=this.elevationLevel-o.level,n=a||n,a=o.layerInfo[0][e].data,!(!a&&n&&o.level<=i));o=o.parent);a||=n,a&&(a.computeMinMaxValue(this._lij[0],this._lij[1],this._lij[2],s),s.minElevation!==1/0&&(s.level=a.level,c=!0))}c&&(n.elevationBounds??=new C,n.elevationBounds.copyFrom(s))}modifyLayers(e,t,n){let r=this.layerInfo[n];for(let e of r)e.loadingAgent&&e.loadingAgent!==H&&(G(e.loadingAgent),e.loadingAgent=null),e.waitingAgents.clear();for(let t=0;t<r.length;++t)e[t]===void 0&&r[t].release();let i=new Array(...r),a=t.length;r.length=a;for(let e=0;e<a;e++){let n=t[e];r[e]=n>-1?i[n]:U.acquire(this._surface.upsampleInfoPool)}this.setMemoryDirty()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,0))}updateAgents(e){if(this.renderData){let t=this.layerInfo[e];for(let e of t)e.loadingAgent===H&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(let e of E){let t=this._isSuspended(e);for(let n of this.layerInfo[e])n.loadingAgent&&n.loadingAgent!==H&&(n.loadingAgent.setSuspension(t),n.loadingAgent===H&&this.updateRenderData(e,0))}}removeLayerAgent(e,t){let n=this.layerInfo[t][e];n.loadingAgent&&n.loadingAgent!==H&&n.loadingAgent.dispose(),n.loadingAgent=null}agentDone(e,t){let n=this.layerInfo[t][e];n.loadingAgent=H,!n.data&&n.upsampleInfo==null&&this._createOrUpdateAgents(e+1,t)}_hasBlendableAncestor(e){return e.blendMode!==`normal`||x(e.parent)&&this._hasBlendableAncestor(e.parent)}_hasBlendModes(e,t,n){for(let r=e;r<t;++r){let e=this._surface.layerViewByIndex(r,n);if(ae(e)&&e?.layer?.blendMode!==`normal`||x(e?.layer?.parent)&&this._hasBlendableAncestor(e?.layer?.parent))return!0}return!1}_createOrUpdateAgents(e,t){let n=this.layerInfo[t];if(n.length===0)return;let r=this._isSuspended(t),i=!1;for(let a=e;a<n.length;++a){let o=n[a],s=this._surface.layerViewByIndex(a,t),c=!1;(!i||S(s))&&(o.loadingAgent?W(this,s)?(o.loadingAgent!==H&&o.loadingAgent.setSuspension(r),o.loadingAgent!==H&&(c=o.loadingAgent.update())):o.dispose():W(this,s)&&(o.loadingAgent=le(this,a,t,r),c=o.loadingAgent.startLoading(),c?o.loadingAgent===H&&this.setPendingUpdate(8):(G(o.loadingAgent),o.loadingAgent=H)),o.loadingAgent===H&&this.updateRenderData(t,0),!s.destroyed&&!this._hasBlendModes(e,n.length,t)&&c&&s.isOpaque&&(i||=!0))}}_isWithinExtent(e){let t=this.extent;return t[0]>=e[0]&&e[2]>=t[2]&&t[1]>=e[1]&&e[3]>=t[3]}intersectsExtent(e){let t=this.extent;return t[2]>=e[0]&&e[2]>=t[0]&&t[3]>=e[1]&&e[3]>=t[1]}getElevationVerticesPerSide(e){let n=this.elevationLevel-this.level,r=Math.max(this.level-e,this.elevationLevelDelta-n),i=t((this._maxTesselation>>r)+1,2,this._maxTesselation+1),a=this.minimumVerticesPerSide;return Math.max(i,a)}_findLIJ(e,t){if(!e)return null;let{rootTiles:n}=this.surface;if(n!=null){for(let r of n)if(de(r,e)){let n=r,i=e[0]-n.level-1;for(;i>=0&&!n.leaf&&!t(n);){let t=e[1]>>i&1,r=e[2]>>i&1;n=n.children[t*2+r],i--}return t(n)?n:null}}return null}findNeighborTile(e,t){let n=this._lij,r=this._getNeighborLIJ(n,e);return r?J(n,r)?t(this)?this:null:this._findLIJ(r,t):null}findCorner(e,t){let n=e===1?1:e===7?0:e===5?2:3,r=this;for(;r.children[0]&&(!t||!t(r));)r=r.children[n];return r}findNeighborCornerTileExact(e,t){return this.findNeighborTile(e,e=>t(e)||e.level===this.level)?.findCorner(j(e),t)||null}forAllSubtreeOnSide(e,t){let n=e===0?[0,1]:e===1?[1]:e===2?[1,3]:e===3?[3]:e===4?[2,3]:e===5?[2]:e===6?[0,2]:[0],r=e=>{let i=e.children;!t(e)&&i[0]&&n.forEach(e=>r(i[e]))};r(this)}getNeighborEdgeStartVertexIndex(e,t){if(!t)return 0;let n=this.level-t.level;if(M(!N||n>=0),n===0)return 0;let r=2**n,i=(e&1)==1,a=+!i,o=t.lij[a+1]*r,s=this._lij[a+1],c=s-o,l=i?r-1-c:c;return N&&(M(o<=s&&s<o+r),M(0<=l&&l<r)),l}forEachLoadedNeighbor(e){let t=this.level,n=e=>e.level===t||e.loaded;P.forEach(t=>{let r=this.findNeighborTile(t,n);r!=null&&r!==this&&r.forAllSubtreeOnSide(F(t),n=>n.loaded?(e(n,t),!0):!1)}),I.forEach(t=>{let r=this.findNeighborTile(t,n)?.findCorner(j(t),e=>e.loaded);N&&M(!r||Y(this,r,t)),r?.loaded&&e(r,t)})}_getNeighborLIJ(e,t){let n=R(t)?-1:+!!z(t),r=B(t)?-1:+!!V(t),i=[e[0],e[1]+n,e[2]+r];return i[1]<0?null:this.surface.isGlobal?this._wrapLIJ(i):i[2]<0?null:i}_wrapLIJ(e){return!e||e[1]<0||e[1]>=2**e[0]?null:this.surface.wrapEastWest(e)}isEdgeNeighbor(e,t){if(e==null)return!1;if(this.level===0&&e.level===0&&(this._eastEnd&&e._westEnd&&t===2||this._westEnd&&e._eastEnd&&t===6))return!0;let n=Math.max((this.extent[2]-this.extent[0])*1e-6,1);switch(t){case 0:return L(this.extent[3],e.extent[1],n);case 4:return L(this.extent[1],e.extent[3],n);case 2:return L(this.extent[2],e.extent[0],n)||L(this.extent[2],-e.extent[0],n);case 6:return L(this.extent[0],e.extent[2],n)||L(this.extent[0],-e.extent[2],n)}}get _eastEnd(){return this._lij[2]===this.surface.lijEastEnd(this.level)-1}get _westEnd(){return this._lij[2]===0}checkGeometryWaterproofness(){}shouldHaveNeighbor(e){let t=this.extent,{rootTilesExtent:n}=this._surface,r=(t[2]-t[0])*.25;if(R(e)&&t[3]+r>=n[3]||z(e)&&t[1]-r<=n[1])return!1;let i=this.surface.isGlobal;return!(!i&&B(e)&&t[0]-r<=n[0]||!i&&V(e)&&t[2]+r>=n[2])}updateDistanceToPOI(e){let t=this._lastPOI;if(this.distanceToPOI>=0&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return;u(this._lastPOI,e);let n=this._center[1].center,r=e[0]-n[0],i=e[1]-n[1],a=e[2]-n[2];this.distanceToPOI=r*r+i*i+a*a}updateOverlayParameters(e){let{renderData:t}=this;if(!t)return;let{overlays:n,longitudeCyclical:r}=e,i=t.overlay;if(n.length===0)this._clearTileOverlayData(0,i),this._clearTileOverlayData(1,i);else{let[e,t]=n,a=this.extent;g(e.extent,a,r)||_(a,e.extent,r)||_(a,t.extent,r)?(this._setOverlayData(n,r,a,0,i),this._setOverlayData(n,r,a,1,i)):(this._clearTileOverlayData(0,i),this._clearTileOverlayData(1,i))}}_setOverlayData(e,t,n,r,i){let a=e[r].extent,o=v(a),s=y(a),c=n[0];if(t){c=t.minimalMonotonic(a[0],c);let e=t.minimalMonotonic(a[0],n[2]);c>e&&(c=e-(n[2]-n[0]))}if(o===0||s===0){i.setOffsetAndScale(r,0,0,1,1);return}let l=v(n)/o,u=y(n)/s,d=(c-a[0])/o,f=(n[1]-a[1])/s;i.setOffsetAndScale(r,d,f,l,u)}_clearTileOverlayData(e,t){t.setOffsetAndScale(e,-1,-1,-1,-1)}}function le(e,t,n,r){let i=n===0?q.acquire():K.acquire();return i.init(e,t,n,r),i}function G(e){e.dispose(),T(e)?q.release(e):ee(e)&&K.release(e)}const K=new r(()=>new O),q=new r(()=>new w),ue=new C;function de(e,t){let n=e.lij,r=t[0]-n[0];return r<0?!1:t[1]>>r===n[1]&&t[2]>>r===n[2]}function J(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function Y(e,t,n){return e==null||t==null||t===e?!1:e.level>=t.level?X(e,t,n):X(t,e,j(n))}function X(e,t,n){M(e.level>=t.level);let r=oe(n),i=se(n),a=e.extent,o=t.extent,s=[r?a[0]:a[2],i?a[3]:a[1]],c=[r?o[2]:o[0],i?o[1]:o[3]],l=(a[2]-a[0])*1e-5,u=L(s[0],c[0],l)||e.surface.isGlobal&&L(s[0],-c[0],l),d=L(s[1],c[1],l);if(u&&d)return!0;if(e.level===t.level||!u&&!d)return M(!1),!1;let f=u?Z(o[1],o[3],a[1],a[3],l):Z(o[0],o[2],a[0],a[2],l);return M(f),f}function Z(e,t,n,r,i){return e-i<=n&&n<=r&&r<=t+i}const Q=d(),fe=d(),pe=d(),$=d();export{ce as Tile,Y as isCornerNeighbor,J as lijEquals};
2
+ import{toConst as e}from"../../../core/compilerUtils.js";import"../../../core/has.js";import{clamp as t}from"../../../core/mathUtils.js";import{abortMaybe as n}from"../../../core/maybe.js";import r from"../../../core/ObjectPool.js";import{subtract as i,squaredLength as a,dot as o,scale as s,add as c,length as l,copy as u}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as d,unitZ as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as p}from"../../../geometry/ellipsoidUtils.js";import{create as m,equals as h,rectangleContainsRectangleCyclicalAware as g,rectanglesIntersectCyclicalAware as _,width as v,height as y}from"../../../geometry/support/aaBoundingRect.js";import{Sphere as b}from"../../../geometry/support/sphere.js";import{isGroupLayer as x}from"../../../layers/support/layerUtils.js";import{isLayerViewWithFlowRenderer as S}from"../support/flowUtils.js";import{ElevationBounds as C}from"./ElevationBounds.js";import{ElevationTileAgent as w,isElevationTileAgent as T}from"./ElevationTileAgent.js";import{LayerClasses as E}from"./LayerClass.js";import{MapDataCacheItem as D}from"./MapDataCacheItem.js";import{MapTileAgent as O,isMapTileAgent as ee}from"./MapTileAgent.js";import{maxPatchTesselation as te}from"./TerrainConst.js";import{isVectorTile as k,isTileTexture as ne,isRasterTile as re,isCreateBitmapResult as ie}from"./TerrainData.js";import{weakAssert as A,isBlendableLayerView as ae,oppositeCorner as j,internalAssert as M,enableTerrainInternalChecks as N,neighborEdgeIndices as P,oppositeEdge as F,neighborCornerIndices as I,almostEquals as L,isNorth as R,isSouth as z,isWest as B,isEast as V,isWestCorner as oe,isNorthCorner as se}from"./terrainUtils.js";import{tileAgentDone as H}from"./TileAgent.js";import{TilePerLayerInfo as U}from"./TilePerLayerInfo.js";import{fallsWithinLayerView as W}from"./tileUtils.js";class ce{constructor(){this._lij=[0,0,0],this._children=[null,null,null,null],this._pendingUpdates=0,this._dirty=!0,this._previouslyRendered=!1,this._lastElevationSourceUpdateRequestSignature=null,this.extent=m(),this._elevationBoundsMin=NaN,this._elevationBoundsMax=0,this.layerInfo=[[],[]],this.extentInRadians=m(),this.centerAtSeaLevel=d(),this._center=[d(),new b,d()],this.up=f(),this._withinClippingArea=!0,this._intersectsClippingArea=!0,this._maxTesselation=0,this._usedMemory=0,this._rasterTileMemory=0,this._vectorTileMemory=0,this._mapDataRefCount=0,this.screenDepth=0,this.renderOrder=0,this._edgeLen=0,this._edgeLen2=0,this._curvatureHeight=0,this.onCompressionFinished=()=>{this.setPendingUpdate(16),this.setMemoryDirty()},this.extentMidX=0,this.extentMidY=0,this.distanceToPOI=-1,this._lastPOI=d(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0}get lij(){return this._lij}get spatialReference(){return this._surface.spatialReference??this._surface.tilingScheme.spatialReference}get isDisposed(){return this._surface==null}get elevationLevelDelta(){return this._surface.getElevationLevelDelta(this.level)}_setPendingUpdateForDescendants(){let e=this._children;if(e[0])for(let t of e)t.renderData&&(t.setPendingUpdate(16),t.setMemoryDirty()),t._setPendingUpdateForDescendants()}static prune(){K.prune(0),q.prune(0),U.prune()}get _cached(){return!this.leaf&&this._mapDataRefCount<=0}get withinClippingArea(){return this._withinClippingArea}get intersectsClippingArea(){return this._intersectsClippingArea}get clippingArea(){return this._clippingArea}get parent(){return this._parent}get children(){return this._children}get surface(){return this._surface}get elevationBoundsMin(){return this._elevationBoundsMin}get elevationBoundsMax(){return this._elevationBoundsMax}get level(){return this._lij[0]}get key(){return`${this._lij[0]}/${this._lij[1]}/${this._lij[2]}`}get edgeLen(){return this._edgeLen}get radius(){return this._center[1].radius}get visible(){return this._dirty&&this.computeVisibility(),this._visible}get frustumVisibility(){return this._dirty&&this.computeVisibility(),this._frustumVisibility}checkVisibility(e){if(this._dirty)return null;let t=this._calculateVisibility(e);if(this._frustumVisibility!==t||this._visible!==(t!==2&&this._intersectsClippingArea))throw Error(`Assertion failed: waterproof.visibility-cache-mismatch: Tile[${this.lij}]`);return t}computeVisibility(){this._dirty=!1;let e=this.parent?.frustumVisibility??1;this._frustumVisibility=this._calculateVisibility(e);let t=this._frustumVisibility!==2&&this._intersectsClippingArea;t!==this._visible&&(this._visible=t,this._surface.emit(`tiles-visibility-changed`),this._surface.renderer.setDirty(),this.updateAgentSuspension())}_calculateVisibility(e){let t=this.parent;return e===0?0:t!=null&&e===2&&this._elevationBoundsMin>=t._elevationBoundsMin&&this._elevationBoundsMax<=t._elevationBoundsMax?2:this._calculateFrustumVisibility(this.surface.frustum,this._surface.view.frustum.boundingSphere)}get _loadable(){return this.visible||this._surface.view.state.fixedContentCamera}get rendered(){let e=!!this.renderData;return e!==this._previouslyRendered&&(this._surface.emit(`tiles-visibility-changed`),this._previouslyRendered=e,this._surface.renderer.setDirty()),e}init(e,t,n,r,i){this._lij[0]=e,this._lij[1]=t,this._lij[2]=n,this.ellipsoid=p(i.tilingScheme.spatialReference),i.tilingScheme.getExtent(e,t,n,this.extent),i.tilingScheme.convertExtentToRadians(this.extent,this.extentInRadians),this.extentMidX=.5*(this.extent[0]+this.extent[2]),this.extentMidY=.5*(this.extent[1]+this.extent[3]),this._withinClippingArea=!0,this._intersectsClippingArea=!0,this._clippingArea=null,this._mapDataRefCount=0,i.upsampleMapCache.pop(this.key),this._edgeLen=0,this._edgeLen2=0,this._center[1].radius=0,this.elevationLevel=e,this._lastElevationSourceUpdateRequestSignature=null,r&&!Number.isNaN(r.elevationBoundsMin)?(this._elevationBoundsMin=r.elevationBoundsMin,this._elevationBoundsMax=r.elevationBoundsMax):(this._elevationBoundsMin=0,this._elevationBoundsMax=0),this._pendingUpdates=0,this.renderData=null,this.screenDepth=0,this._visible=!1,this._previouslyRendered=!1,this._parent=r,this.clearChildren(),this._surface=i,this.updateVisibility(),this.maxLevelDeltaNeighborCount=0,this.unmergableChildCount=0;for(let e of E){let t=i.numLayers(e),n=this.layerInfo[e];for(let e of n)e.release();n.length=t;for(let r=0;r<t;r++)n[r]=U.acquire(this._surface.upsampleInfoPool),e===0&&this.findElevationBoundsForLayer(r,-1)}this.computeElevationBounds(),this._maxTesselation=Math.min(i.tilingScheme.pixelSize,te)}dispose(){A(!this.renderData,`tile.renderData was not unloaded`),this._surface?.upsampleMapCache.pop(this.key),this.layerInfo.forEach(e=>{e.forEach(e=>e.release()),e.length=0}),this._surface=this._parent=null,this.clearChildren(),this.setMemoryDirty()}refMapData(){++this._mapDataRefCount,this._cached||this._surface.upsampleMapCache.pop(this.key)}unrefMapData(){--this._mapDataRefCount,this._cached&&this.cachedMemory>0&&this._surface.upsampleMapCache.put(this.key,new D(e(this)))}setMemoryDirty(){this._usedMemory=0}get usedMemory(){return this._ensureUsedMemory()+(this._cached?0:this.mapDataMemory)}get cachedMemory(){return this._ensureUsedMemory(),this._surface==null?this.usedMemory:this._cached?this.mapDataMemory:0}get mapDataMemory(){return this._rasterTileMemory+this._vectorTileMemory}get _cpuImageMemorySize(){let e=this._surface.tilingScheme.pixelSize;return e*e*4}_ensureUsedMemory(){if(this._usedMemory>0)return this._vectorTileMemory=this.layerInfo[1].reduce((e,{data:t})=>e+(k(t)?t.usedMemoryPerReference:0),0),this._usedMemory;this._usedMemory=this._baseUsedMemory,this._rasterTileMemory=0,this._vectorTileMemory=0;for(let{data:e}of this.layerInfo[1])k(e)?this._vectorTileMemory+=e.usedMemoryPerReference:this._rasterTileMemory+=this.getTerrainDataMemory(e);for(let e of this.layerInfo[0])this._usedMemory+=e.data?this._cpuImageMemorySize:0;return this.renderData&&(this._usedMemory+=this.renderData.estimatedGeometryMemoryUsage,this._rasterTileMemory+=this.renderData.texture?.usedMemory??0),this._cached&&this._surface.upsampleMapCache.updateSize(this.key),this._usedMemory}getUsedMemoryForLayer(e,t){let n=this.layerInfo[e][t];return n?.data?e===1?this._cached?0:this.getTerrainDataMemory(n.data):e===0?this._cpuImageMemorySize:0:0}getTerrainDataMemory(e){return ne(e)?e.texture.usedMemory:re(e)?e.memoryUsage:k(e)?e.usedMemoryPerReference:ie(e)?this._cpuImageMemorySize:0}updateScreenDepth(e){let[t,n,r]=this._center[1].center,i=e,a=i[2]*t+i[6]*n+i[10]*r+i[14];this.screenDepth=a<0?0:a/(i[3]*t+i[7]*n+i[11]*r+i[15])}shouldSplit(e,t,n){if(!this.visible||e.frustum&&!(this._intersectsClippingArea&&this._calculateFrustumVisibility(e.frustum)!==2))return 0;let r=this.level;i(Q,this._center[1].center,t);let u=a(Q),d=this._closestCenterOnElevationRange(t,fe),f=i(pe,d,t),p=Math.min(u,a(f));if(this._edgeLen2>p&&r<e.maxLod)return 1;let m=Math.sqrt(p),h=e.fovX*m*2,g=this._edgeLen/h,_=()=>{if(r<e.maxLod)return this.elevationLevel=r,0;let t=r+Math.ceil(-Math.log2(e.relativeWidthLimit/g));return t===this.elevationLevel?0:(this.elevationLevel=t,2)},v=n==null?1/0:n-r;if(v<=.5)return _();let y=o(this.up,Q),b=this._elevationBoundsMax-this._elevationBoundsMin,x=b/this.edgeLen;if(e.aboveGround&&y>0&&x<.001&&y/m-Math.sin(this._curvatureHeight/(this.edgeLen*Math.SQRT1_2)*Math.PI)-x>0)return _();let S=n==null?1:3-Math.min(v,2);if(g*S<e.relativeWidthLimit||r>=e.maxLod)return _();if(r<7)return 1;s($,this.up,y),i($,$,f);let C=a($);if(C<=this.radius*this.radius)return 1;s($,$,this.radius/Math.sqrt(C)),c($,$,d),i($,t,$);let w=Math.min(1,(Math.abs(o($,this.up))+.5*b+this._curvatureHeight)/l($)),T=.1/e.angledSplitBias,E=e.fovY*m*2;return w*(this._edgeLen/E*S)<T*e.relativeHeightLimit?_():1}needsElevationSourceUpdate(){let e=this.renderData?.geometryState.samplerDataSourceLevels;if(e==null)return!1;let t=Math.max(this.elevationLevel-this.elevationLevelDelta,0);return e.some(e=>e>t)&&this._lastElevationSourceUpdateRequestSignature!==this._elevationSourceUpdateRequestSignature(e)}markElevationSourceUpdateRequested(){let e=this.renderData?.geometryState.samplerDataSourceLevels;this._lastElevationSourceUpdateRequestSignature=e==null?null:this._elevationSourceUpdateRequestSignature(e)}_elevationSourceUpdateRequestSignature(e){return`${Math.max(this.elevationLevel-this.elevationLevelDelta,0)}:${e.join(`,`)}`}createChildren(){let e=this._children,t=this.lij[0]+1,n=this.lij[1]*2,r=this.lij[2]*2;return e[0]=this.surface.createTile(t,n,r,this),e[1]=this.surface.createTile(t,n,r+1,this),e[2]=this.surface.createTile(t,n+1,r,this),e[3]=this.surface.createTile(t,n+1,r+1,this),e}clearChildren(){this._children[0]=this._children[1]=this._children[2]=this._children[3]=null}get loaded(){return this.renderData?.hasGeometry??!1}get hasGeometryState(){return this.renderData?.geometryState!=null}load(){this.refMapData();for(let e of E)this._createOrUpdateAgents(0,e);this.surface.renderer.loadTile(this)}unload(){this.renderData&&this.unrefMapData(),this.surface.renderer.unloadTile(this);for(let e of E){let t=this.layerInfo[e];for(let e of t)e.loadingAgent&&e.loadingAgent!==H&&(G(e.loadingAgent),e.loadingAgent=null),e.pendingUpdates=0}this.resetPendingUpdate(8),this.resetPendingUpdate(16),this.resetPendingUpdate(32)}unloadMapData(){let e=this.layerInfo[1];for(let t of e)t.loadingAgent&&t.loadingAgent!==H&&(G(t.loadingAgent),t.loadingAgent=null),t.pendingUpdates=0,t.invalidateSourceData();this.renderData?.releaseTexture(),this.setMemoryDirty()}updateClippingStatus(e){if(h(e,this._clippingArea))return!1;let t=this._intersectsClippingArea,n=this._withinClippingArea;e==null?(this._intersectsClippingArea=!0,this._withinClippingArea=!0):(this._intersectsClippingArea=this.intersectsExtent(e),this._withinClippingArea=this._isWithinExtent(e)),this._clippingArea=e,this.updateVisibility();let r=n&&this._withinClippingArea,i=!n&&!t&&!this._withinClippingArea&&!this._intersectsClippingArea;return this.renderData&&!(r||i)&&this.setPendingUpdate(8),!0}updateVisibility(){this._dirty=!0,this._surface.setTileTreeDirty(!1)}getLayerInfo(e,t){return this.layerInfo[t][e]}hasLayerData(e,t){let n=this.layerInfo[t][e];return!(!n?.data||n.dataInvalidated)}get updating(){if(this.hasPendingUpdates)return!0;for(let e of E){let t=this.layerInfo[e];for(let e of t)if(e.loadingAgent&&e.loadingAgent!==H&&e.loadingAgent.updating)return!0}return!1}_isSuspended(e){return this.hasPendingUpdate(1)?!0:e!==0&&!this._loadable}get hasPendingUpdates(){return this._pendingUpdates!==0}hasPendingUpdate(e){return(this._pendingUpdates&e)===e}setPendingUpdate(e){let t=this._pendingUpdates;return this._pendingUpdates|=e,e===1||e===4?this._surface.setTileTreeDirty(!0):this._surface.requestUpdate(),t!==this._pendingUpdates}resetPendingUpdate(e){return this.hasPendingUpdate(e)?(this._pendingUpdates&=~e,!0):!1}requestLayerData(e,t,r){let i=this.layerInfo[t][e];if(i.waitingAgents.has(r))return console.warn(`agent already requested this piece of map data (tile %s, agent tile %s, layer: %d/%d)`,this._lij.toString(),r.tile.lij.toString(),t,e),!0;if(i.waitingAgents.push(r),i.data&&!i.dataInvalidated){console.warn(`agent requested existing data (tile %s, agent tile %s, layer: %d/%d)`,this._lij.toString(),r.tile.lij.toString(),t,e);let n=k(i.data);return r.dataArrived(this,n),!0}if(i.requestPromise)return!0;n(i.requestAbort),i.requestAbort=new AbortController;let a=this._surface.requestTileData(this,e,t,{signal:i.requestAbort.signal});if(!a)return i.requestAbort=null,!1;let o=()=>{i.requestPromise===a&&(i.requestPromise=null,i.requestAbort=null)};return i.requestPromise=a,a.then(o,o),!0}get leaf(){return this._children[0]==null}hasLij(e){return this._lij[0]===e[0]&&this._lij[1]===e[1]&&this._lij[2]===e[2]}findByLij(e){if(this.hasLij(e))return this;let t=this._children;return t[0]?t[0].findByLij(e)||t[1].findByLij(e)||t[2].findByLij(e)||t[3].findByLij(e):null}distanceToSquared(e){return a(i($,this._center[1].center,e))}containsPoint(e){let t=this.extent;return e[0]>=t[0]&&e[1]>=t[1]&&e[0]<=t[2]&&e[1]<=t[3]}containsPointXY(e,t){let n=this.extent;return e>=n[0]&&t>=n[1]&&e<=n[2]&&t<=n[3]}unrequestLayerData(e,t,n){let r=this.layerInfo[t][e],i=r.waitingAgents,a=i.removeUnordered(n)!=null;A(a,`agent has not requested this piece of map data`),i.length<1&&(r.abortRequest(),this.setMemoryDirty())}dataArrived(e,t,n){let r=k(n),i=this.layerInfo[t][e];i.data=n,i.dataInvalidated=!1,i.waitingAgents.forAll(e=>e.dataArrived(this,r)),i.waitingAgents.clear(),this.setMemoryDirty()}dataMissing(e,t){let n=this.layerInfo[t][e];n.dataMissing=!0,n.waitingAgents.forAll(e=>e.dataMissing()),n.waitingAgents.clear(),this.setMemoryDirty()}updateRenderData(e,t,n){switch(n&&this.forEachLoadedNeighbor(n=>n.updateRenderData(e,t)),e){case 1:return this._updateTexture(t);case 0:return this._updateGeometry()}}_updateTexture(e){this.renderData&&(this.resetPendingUpdate(e===0?16:32),this.setPendingUpdate(e===0?32:16))}_updateGeometry(){this.setPendingUpdate(8);for(let e of this.layerInfo[0])e.pendingUpdates|=8}invalidateLayerData(e,t){this.layerInfo[t][e].invalidateSourceData()}computeElevationBounds(){let e=this._elevationBoundsMin,t=this._elevationBoundsMax,n=1/0,r=-1/0,i=this.layerInfo[0],a=!0;for(let e of i)e.elevationBounds!=null&&(n=Math.min(n,e.elevationBounds.minElevation),r=Math.max(r,e.elevationBounds.maxElevation),e.elevationBounds.hasNoDataValues||(a=!1));a&&(n=Math.min(n,0),r=Math.max(r,0)),(e!==n||t!==r)&&(this._elevationBoundsMin=n,this._elevationBoundsMax=r,this.updateRadiusAndCenter(),this._surface.setTileTreeDirty(!1),this.renderData&&this._surface.tileElevationRangeChanged(this,e,t))}_updateCenter(){let e=this._elevationBoundsMin,t=this._elevationBoundsMax,n=.5*(e+t),r=this._center;s($,this.up,n),c(r[1].center,this.centerAtSeaLevel,$),s($,this.up,e),c(r[0],this.centerAtSeaLevel,$),s($,this.up,t),c(r[2],this.centerAtSeaLevel,$)}_closestCenterOnElevationRange(e,t){if(this._surface.viewingMode===1){if(this.level===0)return u(t,this._center[1].center);let n=o(this.up,e),r=Math.max(this.ellipsoid.radius+this._elevationBoundsMin,Math.min(this.ellipsoid.radius+this._elevationBoundsMax,n));return s(t,this.up,r)}let n=Math.max(this._elevationBoundsMin,Math.min(this._elevationBoundsMax,e[2]));return t[0]=this.centerAtSeaLevel[0],t[1]=this.centerAtSeaLevel[1],t[2]=n,t}findElevationBoundsForLayer(e,t){let n=this.layerInfo[0][e],r=this.elevationLevelDelta,i=Math.max(this.elevationLevel-r,0),a=n.elevationBounds;if(a!=null&&a.level>t&&a.level<=i)return;let o=this._surface.layerViewByIndex(e,0);if(!W(this,o))return;let s=ue,c=!1,l=n.data;if(l&&l.level<=i){let e=n.data;s.minElevation=e.samplerData.data.minValue,s.maxElevation=e.samplerData.data.maxValue,s.hasNoDataValues=e.samplerData.data.hasNoDataValues,s.level=this.level,c=!0}else{let t=0,n,a;for(let o=this._parent;o&&(!a||t<r)&&(t=this.elevationLevel-o.level,n=a||n,a=o.layerInfo[0][e].data,!(!a&&n&&o.level<=i));o=o.parent);a||=n,a&&(a.computeMinMaxValue(this._lij[0],this._lij[1],this._lij[2],s),s.minElevation!==1/0&&(s.level=a.level,c=!0))}c&&(n.elevationBounds??=new C,n.elevationBounds.copyFrom(s))}modifyLayers(e,t,n){let r=this.layerInfo[n];for(let e of r)e.loadingAgent&&e.loadingAgent!==H&&(G(e.loadingAgent),e.loadingAgent=null),e.waitingAgents.clear();for(let t=0;t<r.length;++t)e[t]===void 0&&r[t].release();let i=new Array(...r),a=t.length;r.length=a;for(let e=0;e<a;e++){let n=t[e];r[e]=n>-1?i[n]:U.acquire(this._surface.upsampleInfoPool)}this.setMemoryDirty()}restartAgents(e){this.renderData&&(this._createOrUpdateAgents(0,e),this.updateRenderData(e,0))}updateAgents(e){if(this.renderData){let t=this.layerInfo[e];for(let e of t)e.loadingAgent===H&&(e.loadingAgent=null);this._createOrUpdateAgents(0,e)}}updateAgentSuspension(){for(let e of E){let t=this._isSuspended(e);for(let n of this.layerInfo[e])n.loadingAgent&&n.loadingAgent!==H&&(n.loadingAgent.setSuspension(t),n.loadingAgent===H&&this.updateRenderData(e,0))}}removeLayerAgent(e,t){let n=this.layerInfo[t][e];n.loadingAgent&&n.loadingAgent!==H&&n.loadingAgent.dispose(),n.loadingAgent=null}agentDone(e,t){let n=this.layerInfo[t][e];n.loadingAgent=H,!n.data&&n.upsampleInfo==null&&this._createOrUpdateAgents(e+1,t)}_hasBlendableAncestor(e){return e.blendMode!==`normal`||x(e.parent)&&this._hasBlendableAncestor(e.parent)}_hasBlendModes(e,t,n){for(let r=e;r<t;++r){let e=this._surface.layerViewByIndex(r,n);if(ae(e)&&e?.layer?.blendMode!==`normal`||x(e?.layer?.parent)&&this._hasBlendableAncestor(e?.layer?.parent))return!0}return!1}_createOrUpdateAgents(e,t){let n=this.layerInfo[t];if(n.length===0)return;let r=this._isSuspended(t),i=!1;for(let a=e;a<n.length;++a){let o=n[a],s=this._surface.layerViewByIndex(a,t),c=!1;(!i||S(s))&&(o.loadingAgent?W(this,s)?(o.loadingAgent!==H&&o.loadingAgent.setSuspension(r),o.loadingAgent!==H&&(c=o.loadingAgent.update())):o.dispose():W(this,s)&&(o.loadingAgent=le(this,a,t,r),c=o.loadingAgent.startLoading(),c?o.loadingAgent===H&&this.setPendingUpdate(8):(G(o.loadingAgent),o.loadingAgent=H)),o.loadingAgent===H&&this.updateRenderData(t,0),!s.destroyed&&!this._hasBlendModes(e,n.length,t)&&c&&s.isOpaque&&(i||=!0))}}_isWithinExtent(e){let t=this.extent;return t[0]>=e[0]&&e[2]>=t[2]&&t[1]>=e[1]&&e[3]>=t[3]}intersectsExtent(e){let t=this.extent;return t[2]>=e[0]&&e[2]>=t[0]&&t[3]>=e[1]&&e[3]>=t[1]}getElevationVerticesPerSide(e){let n=this.elevationLevel-this.level,r=Math.max(this.level-e,this.elevationLevelDelta-n),i=t((this._maxTesselation>>r)+1,2,this._maxTesselation+1),a=this.minimumVerticesPerSide;return Math.max(i,a)}_findLIJ(e,t){if(!e)return null;let{rootTiles:n}=this.surface;if(n!=null){for(let r of n)if(de(r,e)){let n=r,i=e[0]-n.level-1;for(;i>=0&&!n.leaf&&!t(n);){let t=e[1]>>i&1,r=e[2]>>i&1;n=n.children[t*2+r],i--}return t(n)?n:null}}return null}findNeighborTile(e,t){let n=this._lij,r=this._getNeighborLIJ(n,e);return r?J(n,r)?t(this)?this:null:this._findLIJ(r,t):null}findCorner(e,t){let n=e===1?1:e===7?0:e===5?2:3,r=this;for(;r.children[0]&&(!t||!t(r));)r=r.children[n];return r}findNeighborCornerTileExact(e,t){return this.findNeighborTile(e,e=>t(e)||e.level===this.level)?.findCorner(j(e),t)||null}forAllSubtreeOnSide(e,t){let n=e===0?[0,1]:e===1?[1]:e===2?[1,3]:e===3?[3]:e===4?[2,3]:e===5?[2]:e===6?[0,2]:[0],r=e=>{let i=e.children;!t(e)&&i[0]&&n.forEach(e=>r(i[e]))};r(this)}getNeighborEdgeStartVertexIndex(e,t){if(!t)return 0;let n=this.level-t.level;if(M(!N||n>=0),n===0)return 0;let r=2**n,i=(e&1)==1,a=+!i,o=t.lij[a+1]*r,s=this._lij[a+1],c=s-o,l=i?r-1-c:c;return N&&(M(o<=s&&s<o+r),M(0<=l&&l<r)),l}forEachLoadedNeighbor(e){let t=this.level,n=e=>e.level===t||e.loaded;P.forEach(t=>{let r=this.findNeighborTile(t,n);r!=null&&r!==this&&r.forAllSubtreeOnSide(F(t),n=>n.loaded?(e(n,t),!0):!1)}),I.forEach(t=>{let r=this.findNeighborTile(t,n)?.findCorner(j(t),e=>e.loaded);N&&M(!r||Y(this,r,t)),r?.loaded&&e(r,t)})}_getNeighborLIJ(e,t){let n=R(t)?-1:+!!z(t),r=B(t)?-1:+!!V(t),i=[e[0],e[1]+n,e[2]+r];return i[1]<0?null:this.surface.isGlobal?this._wrapLIJ(i):i[2]<0?null:i}_wrapLIJ(e){return!e||e[1]<0||e[1]>=2**e[0]?null:this.surface.wrapEastWest(e)}isEdgeNeighbor(e,t){if(e==null)return!1;if(this.level===0&&e.level===0&&(this._eastEnd&&e._westEnd&&t===2||this._westEnd&&e._eastEnd&&t===6))return!0;let n=Math.max((this.extent[2]-this.extent[0])*1e-6,1);switch(t){case 0:return L(this.extent[3],e.extent[1],n);case 4:return L(this.extent[1],e.extent[3],n);case 2:return L(this.extent[2],e.extent[0],n)||L(this.extent[2],-e.extent[0],n);case 6:return L(this.extent[0],e.extent[2],n)||L(this.extent[0],-e.extent[2],n)}}get _eastEnd(){return this._lij[2]===this.surface.lijEastEnd(this.level)-1}get _westEnd(){return this._lij[2]===0}checkGeometryWaterproofness(){}shouldHaveNeighbor(e){let t=this.extent,{rootTilesExtent:n}=this._surface,r=(t[2]-t[0])*.25;if(R(e)&&t[3]+r>=n[3]||z(e)&&t[1]-r<=n[1])return!1;let i=this.surface.isGlobal;return!(!i&&B(e)&&t[0]-r<=n[0]||!i&&V(e)&&t[2]+r>=n[2])}updateDistanceToPOI(e){let t=this._lastPOI;if(this.distanceToPOI>=0&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return;u(this._lastPOI,e);let n=this._center[1].center,r=e[0]-n[0],i=e[1]-n[1],a=e[2]-n[2];this.distanceToPOI=r*r+i*i+a*a}updateOverlayParameters(e){let{renderData:t}=this;if(!t)return;let{overlays:n,longitudeCyclical:r}=e,i=t.overlay;if(n.length===0)this._clearTileOverlayData(0,i),this._clearTileOverlayData(1,i);else{let[e,t]=n,a=this.extent;g(e.extent,a,r)||_(a,e.extent,r)||_(a,t.extent,r)?(this._setOverlayData(n,r,a,0,i),this._setOverlayData(n,r,a,1,i)):(this._clearTileOverlayData(0,i),this._clearTileOverlayData(1,i))}}_setOverlayData(e,t,n,r,i){let a=e[r].extent,o=v(a),s=y(a),c=n[0];if(t){c=t.minimalMonotonic(a[0],c);let e=t.minimalMonotonic(a[0],n[2]);c>e&&(c=e-(n[2]-n[0]))}if(o===0||s===0){i.setOffsetAndScale(r,0,0,1,1);return}let l=v(n)/o,u=y(n)/s,d=(c-a[0])/o,f=(n[1]-a[1])/s;i.setOffsetAndScale(r,d,f,l,u)}_clearTileOverlayData(e,t){t.setOffsetAndScale(e,-1,-1,-1,-1)}}function le(e,t,n,r){let i=n===0?q.acquire():K.acquire();return i.init(e,t,n,r),i}function G(e){e.dispose(),T(e)?q.release(e):ee(e)&&K.release(e)}const K=new r(()=>new O),q=new r(()=>new w),ue=new C;function de(e,t){let n=e.lij,r=t[0]-n[0];return r<0?!1:t[1]>>r===n[1]&&t[2]>>r===n[2]}function J(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function Y(e,t,n){return e==null||t==null||t===e?!1:e.level>=t.level?X(e,t,n):X(t,e,j(n))}function X(e,t,n){M(e.level>=t.level);let r=oe(n),i=se(n),a=e.extent,o=t.extent,s=[r?a[0]:a[2],i?a[3]:a[1]],c=[r?o[2]:o[0],i?o[1]:o[3]],l=(a[2]-a[0])*1e-5,u=L(s[0],c[0],l)||e.surface.isGlobal&&L(s[0],-c[0],l),d=L(s[1],c[1],l);if(u&&d)return!0;if(e.level===t.level||!u&&!d)return M(!1),!1;let f=u?Z(o[1],o[3],a[1],a[3],l):Z(o[0],o[2],a[0],a[2],l);return M(f),f}function Z(e,t,n,r,i){return e-i<=n&&n<=r&&r<=t+i}const Q=d(),fe=d(),pe=d(),$=d();export{ce as Tile,Y as isCornerNeighbor,J as lijEquals};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../../core/PooledArray.js";import{isImageryTileLayerView as t}from"./terrainUtils.js";class n{constructor(){this._queue=new e,this.remove=()=>{}}get done(){return this._queue.length===0&&(!this._last||this._last.leaf)}resetOne(e){this._queue.clear(),this._queue.push(e),this._last=void 0}reset(e=null){this._queue.clear(),e!=null&&this._queue.pushArray(e),this._last=void 0}skipSubtree(){this._last=void 0}next(){let e=this._last?.children;return e?.[0]&&this._queue.pushArray(e),this._last=this._queue.pop(),this._last}}class r{constructor(){this._q=new e}get done(){return this._q.length===0}reset(e){if(this._q.clear(),e!=null){this._q.pushArray(e);for(let e=0;e<this._q.length;++e){let t=this._q.data[e];t.leaf||this._q.pushArray(t.children)}}}next(){return this._q.pop()}}function i(e,t,n=()=>!0){if(Array.isArray(e))for(let r=0;r<e.length;r++)a(e[r],t,n);else a(e,t,n)}function a(e,t,n=()=>!0){if(t(e),!e.leaf&&n(e))for(let n of e.children)a(n,t)}function o(e,t){let n=e.extent;return!(t.xmin>n[2]||t.ymin>n[3]||t.xmax<n[0]||t.ymax<n[1])}function s(e,t,n){let r=e.surface.tilingScheme.levels[e.level].scale;return!(t&&t>0&&r>t*1.00000001||n&&n>0&&r<n*.99999999)}function c(e,t){if(t==null||t.destroyed)return!1;let n=l(t);return!(n?.fullExtent==null||!o(e,n.fullExtent)||!s(e,n.minScale,n.maxScale))}function l(e){return t(e)||e.type===`wmts-3d`?{fullExtent:e.fullExtent,minScale:e.layer.minScale,maxScale:e.layer.maxScale}:e.layer}function u(e,t){let n=e.lij,r=t.lij;return n[0]-r[0]||n[1]-r[1]||n[2]-r[2]}function d(e,t=null){return t==null||t.length===0?e.sort(f):e.sort((e,n)=>m(e,n,t))}function f(e,t){let n=e.screenDepth-t.screenDepth;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function p(e,t){let n=e.screenDepth,r=t.screenDepth;return n<r?-1:n>r?1:u(e,t)}function m(e,t,n){let r=h(e,n);return r===h(t,n)?p(e,t):r?1:-1}function h(e,t){return t?.some(t=>e.intersectsExtent(t))??!1}function g(e,t){let n=e.distanceToPOI-t.distanceToPOI;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function _(e,t){let n=e.length;for(let r=0;r<n;++r)e.at(r).updateDistanceToPOI(t);e.sort(g)}function v(e,t,n){let r=1,i=0,a=0;for(;e!==t;)if(r*=.5,i*=.5,a*=.5,e.lij[2]&1&&(i+=.5),e.lij[1]&1||(a+=.5),e=e.parent,e==null)throw Error(`tile was not a descendant of upsampleTile`);n.init(t,i,a,r)}function y(e){for(let t=0;t<e.length;t++){let n=e[t],r=n.parent;if(r)for(let e=0;e<4;e++){let t=r.children[e];if(t&&t!==n)return!0}}return!1}function b(e,t){if(!e||!t||e[0]===t[0])return!1;let n=e[0]<t[0],r=n?e:t,i=n?t:e,a=1<<i[0]-r[0];return Math.floor(i[1]/a)===r[1]&&Math.floor(i[2]/a)===r[2]}function x(e,t){if(t<=e[0])return[[...e]];let n=1<<t-e[0],r=[],i=e[1]*n,a=e[2]*n;for(let e=0;e<n;++e)for(let o=0;o<n;++o)r.push([t,e+i,o+a]);return r}export{r as IteratorPostorder,n as IteratorPreorder,p as compareTiles,u as compareTilesByLij,m as compareTilesWithStencil,v as computeUpsampleInfo,x as descendantsAtLevel,c as fallsWithinLayerView,y as hasLoadableSiblings,d as sortTiles,_ as sortTilesByPOI,b as tilesAreRelated,i as traverseTilesPreorder,h as usesStencil};
2
+ import e from"../../../core/PooledArray.js";import{isImageryTileLayerView as t}from"./terrainUtils.js";class n{constructor(){this._queue=new e,this.remove=()=>{}}get done(){return this._queue.length===0&&(!this._last||this._last.leaf)}resetOne(e){this._queue.clear(),this._queue.push(e),this._last=void 0}reset(e=null){this._queue.clear(),e!=null&&this._queue.pushArray(e),this._last=void 0}skipSubtree(){this._last=void 0}next(){let e=this._last?.children;return e?.[0]&&this._queue.pushArray(e),this._last=this._queue.pop(),this._last}}class r{constructor(){this._q=new e}get done(){return this._q.length===0}reset(e){if(this._q.clear(),e!=null){this._q.pushArray(e);for(let e=0;e<this._q.length;++e){let t=this._q.data[e];t.leaf||this._q.pushArray(t.children)}}}next(){return this._q.pop()}}function i(e,t,n=()=>!0){if(Array.isArray(e))for(let r=0;r<e.length;r++)a(e[r],t,n);else a(e,t,n)}function a(e,t,n=()=>!0){if(t(e),!e.leaf&&n(e))for(let n of e.children)a(n,t)}function o(e,t){let n=e.extent;return!(t.xmin>n[2]||t.ymin>n[3]||t.xmax<n[0]||t.ymax<n[1])}function s(e,t,n){let r=e.surface.tilingScheme.levels[e.level].scale;return!(t&&t>0&&r>t*1.00000001||n&&n>0&&r<n*.99999999)}function c(e,t){if(t==null||t.destroyed)return!1;let n=l(t);return!(n?.fullExtent==null||!o(e,n.fullExtent)||!s(e,n.minScale,n.maxScale))}function l(e){return t(e)||e.type===`wmts-3d`?{fullExtent:e.fullExtent,minScale:e.layer.minScale,maxScale:e.layer.maxScale}:e.layer}function u(e,t){let n=e.lij,r=t.lij;return n[0]-r[0]||n[1]-r[1]||n[2]-r[2]}function d(e,t=null){return t==null||t.length===0?e.sort(f):e.sort((e,n)=>m(e,n,t))}function f(e,t){let n=e.screenDepth-t.screenDepth;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function p(e,t){let n=e.screenDepth,r=t.screenDepth;return n<r?-1:n>r?1:u(e,t)}function m(e,t,n){let r=h(e,n);return r===h(t,n)?p(e,t):r?1:-1}function h(e,t){return t?.some(t=>e.intersectsExtent(t))??!1}function g(e,t){let n=e.distanceToPOI-t.distanceToPOI;if(n!==0)return n;let r=e.lij,i=t.lij;return r[0]-i[0]||r[1]-i[1]||r[2]-i[2]}function _(e,t){let n=e.length;for(let r=0;r<n;++r)e.at(r).updateDistanceToPOI(t);e.sort(g)}function v(e,t,n){let r=1,i=0,a=0;for(;e!==t;)if(r*=.5,i*=.5,a*=.5,e.lij[2]&1&&(i+=.5),e.lij[1]&1||(a+=.5),e=e.parent,e==null)throw Error(`tile was not a descendant of upsampleTile`);n.init(t,i,a,r)}function y(e,t){if(!e||!t||e[0]===t[0])return!1;let n=e[0]<t[0],r=n?e:t,i=n?t:e,a=1<<i[0]-r[0];return Math.floor(i[1]/a)===r[1]&&Math.floor(i[2]/a)===r[2]}function b(e,t){if(t<=e[0])return[[...e]];let n=1<<t-e[0],r=[],i=e[1]*n,a=e[2]*n;for(let e=0;e<n;++e)for(let o=0;o<n;++o)r.push([t,e+i,o+a]);return r}export{r as IteratorPostorder,n as IteratorPreorder,p as compareTiles,u as compareTilesByLij,m as compareTilesWithStencil,v as computeUpsampleInfo,b as descendantsAtLevel,c as fallsWithinLayerView,d as sortTiles,_ as sortTilesByPOI,y as tilesAreRelated,i as traverseTilesPreorder,h as usesStencil};
@@ -1,5 +1,5 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{shadowHighlight as t}from"../bindUniforms.js";import{ForwardLinearDepthConfiguration as n}from"../ForwardLinearDepth.glsl.js";import{forwardLinearDepthToReadShadow as r}from"../forwardLinearDepthToReadShadow.glsl.js";import{calculateUVZShadowPass as i,calculateUVZShadowDraw as a,ReadShadowMapOrigin as o}from"./calculateUVZShadow.glsl.js";import{lightingGlobalFactor as s}from"./lightingUniforms.js";import{glsl as c,If as l}from"../../shaderModules/glsl.js";import{Texture2DShadowBindUniform as u}from"../../shaderModules/Texture2DShadowBindUniform.js";import{parameter as d}from"../../shaderTechnique/ShaderTechniqueConfiguration.js";class f extends o{}class p extends o{}class m extends n{constructor(){super(...arguments),this.hasShadowHighlights=!1,this.receiveShadows=!0}}e([d()],m.prototype,`hasShadowHighlights`,void 0),e([d()],m.prototype,`receiveShadows`,void 0);function h(e,t){t.receiveShadows&&e.fragment.include(i),_(e,t)}function g(e,t){t.receiveShadows&&e.fragment.include(a),_(e,t)}function _(e,t){e.include(r,t);let{hasShadowHighlights:n,receiveShadows:i,spherical:a}=t;i&&(v(e.fragment,n),e.fragment.code.add(c`float readShadowMap(const in vec3 _worldPos, float _linearDepth) {
2
+ import{__decorate as e}from"tslib";import{shadowHighlight as t}from"../bindUniforms.js";import{ForwardLinearDepthConfiguration as n}from"../ForwardLinearDepth.glsl.js";import{forwardLinearDepthToReadShadow as r}from"../forwardLinearDepthToReadShadow.glsl.js";import{calculateUVZShadowDraw as i,calculateUVZShadowPass as a,ReadShadowMapOrigin as o}from"./calculateUVZShadow.glsl.js";import{lightingGlobalFactor as s}from"./lightingUniforms.js";import{glsl as c,If as l}from"../../shaderModules/glsl.js";import{Texture2DShadowBindUniform as u}from"../../shaderModules/Texture2DShadowBindUniform.js";import{parameter as d}from"../../shaderTechnique/ShaderTechniqueConfiguration.js";class f extends o{}class p extends o{}class m extends n{constructor(){super(...arguments),this.hasShadowHighlights=!1,this.receiveShadows=!0}}e([d()],m.prototype,`hasShadowHighlights`,void 0),e([d()],m.prototype,`receiveShadows`,void 0);function h(e,t){t.receiveShadows&&e.fragment.include(a),_(e,t)}function g(e,t){t.receiveShadows&&e.fragment.include(i),_(e,t)}function _(e,t){e.include(r,t);let{hasShadowHighlights:n,receiveShadows:i,spherical:a}=t;i&&(v(e.fragment,n),e.fragment.code.add(c`float readShadowMap(const in vec3 _worldPos, float _linearDepth) {
3
3
  vec3 uvzShadow = calculateUVZShadow(_worldPos, _linearDepth, textureSize(shadowMap, 0));
4
4
  return readShadowMaps(uvzShadow);
5
5
  }
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import"../../../../core/has.js";import{destroyMaybe as n}from"../../../../core/maybe.js";import{watch as r,sync as i}from"../../../../core/reactiveUtils.js";import{signal as a}from"../../../../core/signal.js";import{property as o,subclass as s}from"../../../../core/accessorSupport/decorators.js";import{cloudPresets as c}from"./clouds/CloudsPresets.js";import{CloudsRenderer as l}from"./clouds/CloudsRenderer.js";import{Precipitation as u}from"./precipitation/Precipitation.js";let d=class extends t{constructor(e){super(e),this._clouds=a(null),this._incarnation=0,this._precipitation=null}initialize(){let e=()=>this._requestRender();this.addHandles([r(()=>this._precipitation,e,i),r(()=>this._clouds.value?.state,e,i),r(()=>this.view.state.mode,e,i),r(()=>this.view.state.stationary&&!!this.context.bind.clouds.data&&this.context.bind.clouds.needsStationaryAnchorUpdate(this.view.state.camera),t=>{t&&e()},i),r(()=>this._updateClouds(),e,i),r(()=>this._updatePrecipitation(),e,i),r(()=>this.view.environmentView.weatherEnabled?this.view.environment.weather:null,e=>this._initWeather(e))])}destroy(){this.removeHandles(),this._clouds.value=n(this._clouds.value),this._precipitation=null,this._precipitationOutgoing=null}get readyToRun(){return!!this._clouds.value?.readyToRun||this.view.state.stationary&&!!this.context.bind.clouds.data&&this.context.bind.clouds.needsStationaryAnchorUpdate(this.view.state.camera)}get usedMemory(){return this._clouds.value?.usedMemory??0}_fadeOutPrecipitation(){this._precipitation&&(this._precipitationOutgoing?.destroy(),this._precipitationOutgoing=this._precipitation,this._precipitationOutgoing.fadeOut(()=>this._precipitationOutgoing=n(this._precipitationOutgoing)),this._precipitation=null,++this._incarnation)}get snowCover(){return this._precipitationOutgoing?.snowCover??this._precipitation?.snowCover??0}cleanupCubemap(){let e=this._clouds.value;e?.state===0&&e.coverage===0&&!e.readyToRun&&e.destroyCubeMap()}_requestRender(){this.view.stage.renderView.requestRender()}_initWeather(e){!e||!this.context?this._clouds.value=n(this._clouds.value):this._clouds.value||(this._clouds.value=new l({context:this.context,view:this.view,requestRender:()=>this._requestRender()}))}_updateClouds(){let e=this.view.environment.weather;return e==null||this._clouds.value==null||this._clouds.value.applyPreset(c[e.type],f(e)),++this._incarnation}_updatePrecipitation(){let e=this.view.environment.weather;return e.type===this._precipitation?.type||(this._fadeOutPrecipitation(),(e.type===`rainy`||e.type===`snowy`)&&(this._precipitation=new u({view:this.view,type:e.type}),++this._incarnation)),this._incarnation}get test(){}};e([o({constructOnly:!0})],d.prototype,`view`,void 0),e([o({constructOnly:!0})],d.prototype,`context`,void 0),d=e([s(`esri.views.3d.webgl-engine.effects.WeatherFader`)],d);function f(e){switch(e.type){case`rainy`:case`snowy`:case`cloudy`:case`sunny`:return e.cloudCover;case`foggy`:return e.fogStrength}}export{d as WeatherFader};
2
+ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import"../../../../core/has.js";import{destroyMaybe as n}from"../../../../core/maybe.js";import{watch as r,sync as i}from"../../../../core/reactiveUtils.js";import{signal as a}from"../../../../core/signal.js";import{property as o,subclass as s}from"../../../../core/accessorSupport/decorators.js";import{cloudPresets as c}from"./clouds/CloudsPresets.js";import{CloudsRenderer as l}from"./clouds/CloudsRenderer.js";import{Precipitation as u}from"./precipitation/Precipitation.js";let d=class extends t{constructor(e){super(e),this._clouds=a(null)}initialize(){let e=()=>this._requestRender();this.addHandles([r(()=>this._precipitation,e,i),r(()=>this._clouds.value,e,i),r(()=>this._clouds.value?.state,e,i),r(()=>this.view.state.mode,e,i),r(()=>this.view.state.stationary&&!!this.context.bind.clouds.data&&this.context.bind.clouds.needsStationaryAnchorUpdate(this.view.state.camera),t=>{t&&e()},i),r(()=>[this._weather?.type,f(this._weather)],([e,t])=>this._updateClouds(e,t)),r(()=>this._weather?.type,e=>this._updatePrecipitation(e))])}destroy(){this.removeHandles(),this._clouds.value=n(this._clouds.value),this._precipitation=null,this._precipitationOutgoing=null}get readyToRun(){return!!this._clouds.value?.readyToRun||this.view.state.stationary&&!!this.context.bind.clouds.data&&this.context.bind.clouds.needsStationaryAnchorUpdate(this.view.state.camera)}get usedMemory(){return this._clouds.value?.usedMemory??0}get _weather(){return this.view.environmentView.weatherEnabled?this.view.environment.weather:null}_fadeOutPrecipitation(){this._precipitation&&=(this._precipitationOutgoing?.destroy(),this._precipitationOutgoing=this._precipitation,this._precipitationOutgoing.fadeOut(()=>this._precipitationOutgoing=n(this._precipitationOutgoing)),null)}get snowCover(){return this._precipitationOutgoing?.snowCover??this._precipitation?.snowCover??0}cleanupCubemap(){let e=this._clouds.value;e?.state===0&&e.coverage===0&&!e.readyToRun&&e.destroyCubeMap()}_requestRender(){this.view.stage.renderView.requestRender()}_updateClouds(e,t){!e||!this.context?this._clouds.value=n(this._clouds.value):(this._clouds.value??=new l({context:this.context,view:this.view,requestRender:()=>this._requestRender()}),this._clouds.value.applyPreset(c[e],t))}_updatePrecipitation(e){e!==this._precipitation?.type&&(this._fadeOutPrecipitation(),(e===`rainy`||e===`snowy`)&&(this._precipitation=new u({view:this.view,type:e})))}get test(){}};e([o({constructOnly:!0})],d.prototype,`view`,void 0),e([o({constructOnly:!0})],d.prototype,`context`,void 0),e([o()],d.prototype,`_precipitation`,void 0),d=e([s(`esri.views.3d.webgl-engine.effects.WeatherFader`)],d);function f(e){switch(e?.type){case`rainy`:case`snowy`:case`cloudy`:case`sunny`:return e.cloudCover;case`foggy`:return e.fogStrength;case void 0:return-1}}export{d as WeatherFader};
@@ -70,18 +70,28 @@ depth`),o=this.fboCache.acquire(e,t,`fbo visualizer`),s=i.boundFramebuffer;i.bin
70
70
  return linearDepthFromFloat(rgbaToFloat(depth));
71
71
  }
72
72
 
73
- vec4 readTexture(sampler2D tex, vec2 uv, int lod) {
74
- ivec2 iuv = ivec2(uv * vec2(textureSize(tex, lod)));
75
- return texelFetch(tex, iuv, lod);
76
- }
77
73
 
78
- ${n[0]===`float`?`float linearDepthFromTexture(sampler2D depthTex, vec2 uv) {
74
+ ${s(n[0]===`float`,`
75
+ vec4 readTexture(sampler2D tex, vec2 uv, int lod) {
76
+ ivec2 iuv = ivec2(uv * vec2(textureSize(tex, lod)));
77
+ return texelFetch(tex, iuv, lod);
78
+ }
79
+
80
+ float linearDepthFromTexture(sampler2D depthTex, vec2 uv) {
79
81
  ivec2 iuv = ivec2(uv * vec2(textureSize(depthTex, 0)));
80
82
  return linearDepthFromRGBA(texelFetch(depthTex, iuv, 0));
81
- }`:`float linearDepthFromTexture(usampler2D depthTex, vec2 uv) {
82
- ivec2 iuv = ivec2(uv * vec2(textureSize(depthTex, 0)));
83
- return linearDepthFromRGBA(vec4(texelFetch(depthTex, iuv, 0)) * 255.0);
84
- }`}
83
+ }
84
+ `,`
85
+ vec4 readTexture(usampler2D tex, vec2 uv, int lod) {
86
+ ivec2 iuv = ivec2(uv * vec2(textureSize(tex, lod)));
87
+ return vec4(texelFetch(tex, iuv, lod));
88
+ }
89
+
90
+ float linearDepthFromTexture(usampler2D depthTex, vec2 uv) {
91
+ ivec2 iuv = ivec2(uv * vec2(textureSize(depthTex, 0)));
92
+ return linearDepthFromRGBA(vec4(texelFetch(depthTex, iuv, 0)) * 255.0);
93
+ }
94
+ `)}
85
95
 
86
96
  void main() {
87
97
  ${p(n)}
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{equals as t}from"../../../../../core/arrayUtils.js";import"../../../../../core/has.js";import{releaseMaybe as n,disposeMaybe as r}from"../../../../../core/maybe.js";import{watch as i,initial as a}from"../../../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../../../core/accessorSupport/decorators.js";import{set as c}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{InternalRenderCategory as l}from"../../../webgl.js";import u from"../../../webgl/RenderNode.js";import{HighlightApplyTechnique as d}from"./HighlightApplyTechnique.js";import{H as f}from"../../../../../chunks/HighlightBlur.glsl.js";import{HighlightBlurTechnique as p}from"./HighlightBlurTechnique.js";import{H as m,g as h}from"../../../../../chunks/HighlightDownsample.glsl.js";import{HighlightDownsampleTechnique as g}from"./HighlightDownsampleTechnique.js";import{HighlightPassParameters as _}from"./HighlightPassParameters.js";import{m as v}from"../../../../../chunks/HighlightSharpApply.glsl.js";import{HighlightSharpApplyTechnique as y}from"./HighlightSharpApplyTechnique.js";import{HighlightToSingleTechnique as b}from"./HighlightToSingleTechnique.js";import{Compositor as x}from"../../lib/Compositor.js";import{NoVertex as S}from"../../lib/DefaultVertexBufferLayouts.js";import{VertexArrayObject as C}from"../../lib/VertexArrayObject.js";import{BufferObject as w}from"../../../../webgl/BufferObject.js";import{ColorAttachment0 as T,PrimitiveType as E,DataType as D}from"../../../../webgl/enums.js";import{Texture as O}from"../../../../webgl/Texture.js";import{TextureDescriptor as k}from"../../../../webgl/TextureDescriptor.js";import{VertexBuffer as A}from"../../../../webgl/VertexBuffer.js";let j=class extends u{constructor(e){super(e),this.consumes={required:[l.HIGHLIGHT,`highlights`]},this.produces=l.HIGHLIGHT,this._renderSharpHighlights=(e,t,n)=>{let{techniques:r}=this,i=r.getCompiled(y);if(!i||!this._compositor.isPremultipliedAlphaReady(!1))return!1;let a=this._prepareAndDownSample(t),{fullWidth:o,fullHeight:s,pixelRatio:c,fullViewport:l}=this.bindParameters.camera,u=this.fboCache.acquire(o,s,`highlight overlay`,5);this._clearHighlightOverlay(u),this._passParameters.pixelRatio=Math.min(c,v);let{renderingContext:d,bindParameters:f,_passParameters:p}=this,m=this.view.stage.renderView.renderer;for(let e=0;e<n.length;++e){let{name:t}=n[e];m.hasHighlight(t)&&(p.highlightLevel=e,d.bindFramebuffer(u.fbo),d.setViewport4fv(f.camera.fullViewport),d.bindTechnique(i,f,p),this._renderGrid(a))}let h=this.antialias.isEnabled()?this.antialias.renderTo(u,`highlight antialiasing`,{coverageTexture:a.coverage.getTexture(),horizontalCellCount:a.horizontalCellCount,verticalCellCount:a.verticalCellCount,draw:()=>this._renderGrid(a)}):u;h!==u&&u.release();let{_compositor:g}=this;return d.bindFramebuffer(e.fbo),d.setDrawBuffers([T]),d.setViewport4fv(l),g.compositePreMultipliedAlpha(this.bindParameters,h.getTexture(),!1),h.release(),!0},this._renderGaussianHighlights=(e,t,n)=>{let{renderingContext:r,bindParameters:i,fboCache:a,_passParameters:o,techniques:s}=this,l=s.getCompiled(b),u=s.getCompiled(p),f=s.getCompiled(d);if(!l||!u||!f)return!1;let m=this._prepareAndDownSample(t),{width:h,height:g}=t.descriptor,{fullWidth:_,fullHeight:v,pixelRatio:y,fullViewport:x}=i.camera,S=Math.ceil(_/y),C=Math.ceil(v/y),{_highlightBlurDrawParameters:w}=this,E=this.view.stage.renderView.renderer;for(let t=0;t<n.length;++t){let{name:s}=n[t];if(!E.hasHighlight(s))continue;o.highlightLevel=t,r.setClearColor(0,0,0,0);let d=a.acquire(h,g,`single highlight`,2);r.bindFramebuffer(d.fbo),r.setViewport(0,0,h,g),r.clear(16384),r.bindTechnique(l,i,o),this._renderGrid(m),w.blurInput=d.getTexture(),c(w.blurSize,1/S,0);let p=a.acquire(S,C,`single highlight blur`,2);r.unbindTexture(p.fbo?.colorTexture),r.bindFramebuffer(p.fbo),r.setViewport(0,0,S,C),r.clear(16384),r.bindTechnique(u,i,o,w),this._renderGrid(m),d.release(),c(w.blurSize,0,1/C),o.highlightBlurTexture=p.getTexture(),r.bindFramebuffer(e.fbo),r.setDrawBuffers([T]),r.setViewport4fv(x),r.bindTechnique(f,i,o,w),this._renderGrid(m),p.release()}return!0},this._downsampleDrawParameters=new m,this._passParameters=new _,this._highlightBlurDrawParameters=new f,this._compositor=null,this._grid=new M}initialize(){this._compositor=new x(this.renderingContext,this.techniques),this.addHandles([i(()=>this._optionsData,e=>this._updateOptionsTexture(e),a)])}destroy(){this._grid.coverage=n(this._grid.coverage),this._grid.vao=r(this._grid.vao),this._passParameters.highlightOptionsTexture=n(this._passParameters.highlightOptionsTexture)}get _optionsData(){let e=new Uint8Array(128),n=0;for(let t of this.view.state.highlights){let r=n*4,i=n*4+64;++n;let{color:a}=t,o=t.haloColor??a;e[r+0]=a.r,e[r+1]=a.g,e[r+2]=a.b,e[r+3]=t.fillOpacity*a.a*255,e[i+0]=o.r,e[i+1]=o.g,e[i+2]=o.b,e[i+3]=t.haloOpacity*o.a*255}let r=this._get(`_optionsData`);return t(e,r)?r:e}_updateOptionsTexture(e){if(this._passParameters.highlightOptionsTexture==null){let e=new k(16,2);e.internalFormat=6408,e.samplingMode=9728,this._passParameters.highlightOptionsTexture=new O(this.renderingContext,e,null)}this._passParameters.highlightOptionsTexture.setData(e),this.requestRender(1)}render(e){let t=e.find(({name:e})=>e===l.HIGHLIGHT),{techniques:n,bindParameters:r,_passParameters:i}=this;if(!r.decorations)return t;if(!n.getCompiled(g))return this.requestRender(1),t;let a=this.view.stage.renderer.isFeatureEnabled(13),o=e.find(({name:e})=>e===`highlights`).getTexture(),s=a?this._renderSharpHighlights:this._renderGaussianHighlights,c=a?this._renderGaussianHighlights:this._renderSharpHighlights;return!s(t,o,r.highlights)&&(this.requestRender(1),!c(t,o,r.highlights))||(i.coverageTexture=null,i.highlightTexture=null),t}_clearHighlightOverlay(e){let{renderingContext:t}=this;t.bindFramebuffer(e.fbo),t.setViewport4fv(this.bindParameters.camera.fullViewport),t.setClearColor(0,0,0,0),t.clear(16384)}_prepareAndDownSample(e){this._passParameters.highlightTexture=e,this._gridUpdateResources(e);let t=this.techniques.get(g),n=this._gridComputeCoverage(t,e),{horizontalCellCount:r,verticalCellCount:i}=n,a=this._passParameters;return a.horizontalCellCount=r,a.verticalCellCount=i,a.coverageTexture=n.coverage?.getTexture(),n}_renderGrid(e){let t=e.verticalCellCount*e.horizontalCellCount;this.renderingContext.bindVAO(e.vao),this.renderingContext.drawElementsInstanced(E.TRIANGLES,6,D.UNSIGNED_BYTE,0,t)}_gridUpdateResources(e){let t=this._grid,{width:n,height:r}=e.descriptor;if(t.horizontalCellCount=Math.ceil(n/h),t.verticalCellCount=Math.ceil(r/h),t.vao)return;let i=this.renderingContext,a=w.createIndex(i,35044,F);t.vao=new C(i,new A(i,S),a)}_gridComputeCoverage(e,t){let n=this.renderingContext,r=this._grid,i=t.descriptor,a=Math.ceil(i.width/h),o=Math.ceil(i.height/h);this._downsampleDrawParameters.input=t;let{highlights:s}=this.bindParameters;r.coverage?.release();let c=this.fboCache.acquire(a,o,`highlight coverage`,s.length>L?3:1);return r.coverage=c,n.bindFramebuffer(c.fbo),n.bindTechnique(e,this.bindParameters,this._passParameters,this._downsampleDrawParameters),n.setViewport(0,0,a,o),n.screen.draw(),r}get test(){}};e([o()],j.prototype,`consumes`,void 0),e([o()],j.prototype,`produces`,void 0),e([o({constructOnly:!0})],j.prototype,`antialias`,void 0),e([o()],j.prototype,`_optionsData`,null),j=e([s(`esri.views.3d.webgl-engine.effects.highlight.Highlight`)],j);class M{constructor(){this.coverage=null,this.vao=null,this.verticalCellCount=0,this.horizontalCellCount=0,this.viewportWidth=0,this.viewportHeight=0}}let N=0;function P(e){let t=0;for(let n of e){let{name:e}=n;t+=e.length;let{color:r,fillOpacity:i,haloColor:a,haloOpacity:o}=n;t+=r.r+r.g+r.b+r.a+i,t+=a?a.r+a.g+a.b+a.a+o:0}let n=e.at(0);if(n){let{shadowOpacity:e,shadowDifference:r,shadowColor:i}=n;t+=e+r+i.r+i.g+i.b+i.a}return N+++(t>=0?0:1)}const F=new Uint8Array([0,1,2,2,1,3]);function I(e,t,n,r,i,a,o=0){let{highlights:s}=i,l=s.length>1?t.acquire(n,r,`highlight mix`,s.length>L?3:1):null,{gl:u}=e;if(l){let t=e.boundFramebuffer;e.bindFramebuffer(l.fbo),u.clearBufferuiv(u.COLOR,0,[0,0,0,0]),e.bindFramebuffer(t)}let d=l?.getTexture();i.highlightMixTexture=d,c(i.highlightMixOrigin,o,0),s.forEach((t,s)=>{if(s>0){let t=O.TEXTURE_UNIT_FOR_UPDATES;e.bindTexture(d,t),e.setActiveTexture(t),u.copyTexSubImage2D(3553,0,0,0,o,0,n,r),e.bindTexture(null,t)}e.clear(256),i.highlightLevel=s,a()}),i.highlightLevel=null,i.highlightMixTexture=null,l?.release()}const L=4;export{j as Highlight,L as maxHighlightsPerChannel,I as renderHighlightBuffer,P as trackHighlightOptions};
2
+ import{__decorate as e}from"tslib";import{equals as t}from"../../../../../core/arrayUtils.js";import"../../../../../core/has.js";import{releaseMaybe as n,disposeMaybe as r}from"../../../../../core/maybe.js";import{watch as i,initial as a}from"../../../../../core/reactiveUtils.js";import{property as o,subclass as s}from"../../../../../core/accessorSupport/decorators.js";import{set as c}from"../../../../../core/libs/gl-matrix-2/math/vec2.js";import{InternalRenderCategory as l}from"../../../webgl.js";import u from"../../../webgl/RenderNode.js";import{HighlightApplyTechnique as d}from"./HighlightApplyTechnique.js";import{H as f}from"../../../../../chunks/HighlightBlur.glsl.js";import{HighlightBlurTechnique as p}from"./HighlightBlurTechnique.js";import{H as m,g as h}from"../../../../../chunks/HighlightDownsample.glsl.js";import{HighlightDownsampleTechnique as g}from"./HighlightDownsampleTechnique.js";import{HighlightPassParameters as _}from"./HighlightPassParameters.js";import{m as v}from"../../../../../chunks/HighlightSharpApply.glsl.js";import{HighlightSharpApplyTechnique as y}from"./HighlightSharpApplyTechnique.js";import{HighlightToSingleTechnique as b}from"./HighlightToSingleTechnique.js";import{Compositor as x}from"../../lib/Compositor.js";import{NoVertex as S}from"../../lib/DefaultVertexBufferLayouts.js";import{VertexArrayObject as C}from"../../lib/VertexArrayObject.js";import{BufferObject as w}from"../../../../webgl/BufferObject.js";import{ColorAttachment0 as T,PrimitiveType as E,DataType as D}from"../../../../webgl/enums.js";import{Texture as O}from"../../../../webgl/Texture.js";import{TextureDescriptor as k}from"../../../../webgl/TextureDescriptor.js";import{VertexBuffer as A}from"../../../../webgl/VertexBuffer.js";let j=class extends u{constructor(e){super(e),this.consumes={required:[l.HIGHLIGHT,`highlights`]},this.produces=l.HIGHLIGHT,this._renderSharpHighlights=(e,t,n)=>{let{techniques:r}=this,i=r.getCompiled(y);if(!i||!this._compositor.isPremultipliedAlphaReady(!1))return!1;let a=this._prepareAndDownSample(t),{fullWidth:o,fullHeight:s,pixelRatio:c,fullViewport:l}=this.bindParameters.camera,u=this.fboCache.acquire(o,s,`highlight overlay`,5);this._clearHighlightOverlay(u),this._passParameters.pixelRatio=Math.min(c,v);let{renderingContext:d,bindParameters:f,_passParameters:p}=this,m=this.view.stage.renderView.renderer;for(let e=0;e<n.length;++e){let{name:t}=n[e];m.hasHighlight(t)&&(p.highlightLevel=e,d.bindFramebuffer(u.fbo),d.setViewport4fv(f.camera.fullViewport),d.bindTechnique(i,f,p),this._renderGrid(a))}let h=this.antialias.isEnabled()?this.antialias.renderTo(u,`highlight antialiasing`,{coverageTexture:a.coverage.getTexture(),horizontalCellCount:a.horizontalCellCount,verticalCellCount:a.verticalCellCount,draw:()=>this._renderGrid(a)}):u;h!==u&&u.release();let{_compositor:g}=this;return d.bindFramebuffer(e.fbo),d.setDrawBuffers([T]),d.setViewport4fv(l),g.compositePreMultipliedAlpha(this.bindParameters,h.getTexture(),!1),h.release(),!0},this._renderGaussianHighlights=(e,t,n)=>{let{renderingContext:r,bindParameters:i,fboCache:a,_passParameters:o,techniques:s}=this,l=s.getCompiled(b),u=s.getCompiled(p),f=s.getCompiled(d);if(!l||!u||!f)return!1;let m=this._prepareAndDownSample(t),{width:h,height:g}=t.descriptor,{fullWidth:_,fullHeight:v,pixelRatio:y,fullViewport:x}=i.camera,S=Math.ceil(_/y),C=Math.ceil(v/y),{_highlightBlurDrawParameters:w}=this,E=this.view.stage.renderView.renderer;for(let t=0;t<n.length;++t){let{name:s}=n[t];if(!E.hasHighlight(s))continue;o.highlightLevel=t,r.setClearColor(0,0,0,0);let d=a.acquire(h,g,`single highlight`,2);r.bindFramebuffer(d.fbo),r.setViewport(0,0,h,g),r.clear(16384),r.bindTechnique(l,i,o),this._renderGrid(m),w.blurInput=d.getTexture(),c(w.blurSize,1/S,0);let p=a.acquire(S,C,`single highlight blur`,2);r.unbindTexture(p.fbo?.colorTexture),r.bindFramebuffer(p.fbo),r.setViewport(0,0,S,C),r.clear(16384),r.bindTechnique(u,i,o,w),this._renderGrid(m),d.release(),c(w.blurSize,0,1/C),o.highlightBlurTexture=p.getTexture(),r.bindFramebuffer(e.fbo),r.setDrawBuffers([T]),r.setViewport4fv(x),r.bindTechnique(f,i,o,w),this._renderGrid(m),p.release()}return!0},this._downsampleDrawParameters=new m,this._passParameters=new _,this._highlightBlurDrawParameters=new f,this._compositor=null,this._grid=new M}initialize(){this._compositor=new x(this.renderingContext,this.techniques),this.addHandles([i(()=>this._optionsData,e=>this._updateOptionsTexture(e),a)])}destroy(){this._grid.coverage=n(this._grid.coverage),this._grid.vao=r(this._grid.vao),this._passParameters.highlightOptionsTexture=n(this._passParameters.highlightOptionsTexture)}get _optionsData(){let e=new Uint8Array(128),n=0;for(let t of this.view.state.highlights){let r=n*4,i=n*4+64;++n;let{color:a}=t,o=t.haloColor??a;e[r+0]=a.r,e[r+1]=a.g,e[r+2]=a.b,e[r+3]=t.fillOpacity*a.a*255,e[i+0]=o.r,e[i+1]=o.g,e[i+2]=o.b,e[i+3]=t.haloOpacity*o.a*255}let r=this._get(`_optionsData`);return t(e,r)?r:e}_updateOptionsTexture(e){if(this._passParameters.highlightOptionsTexture==null){let e=new k(16,2);e.internalFormat=6408,e.samplingMode=9728,this._passParameters.highlightOptionsTexture=new O(this.renderingContext,e,null)}this._passParameters.highlightOptionsTexture.setData(e),this.requestRender(1)}render(e){let t=e.find(({name:e})=>e===l.HIGHLIGHT),{techniques:n,bindParameters:r,_passParameters:i}=this;if(!r.decorations)return t;if(!n.getCompiled(g))return this.requestRender(1),t;let a=this.view.stage.renderer.isFeatureEnabled(13),o=e.find(({name:e})=>e===`highlights`).getTexture(),s=a?this._renderSharpHighlights:this._renderGaussianHighlights,c=a?this._renderGaussianHighlights:this._renderSharpHighlights;return!s(t,o,r.highlights)&&(this.requestRender(1),!c(t,o,r.highlights))||(i.coverageTexture=null,i.highlightTexture=null),t}_clearHighlightOverlay(e){let{renderingContext:t}=this;t.bindFramebuffer(e.fbo),t.setViewport4fv(this.bindParameters.camera.fullViewport),t.setClearColor(0,0,0,0),t.clear(16384)}_prepareAndDownSample(e){this._passParameters.highlightTexture=e,this._gridUpdateResources(e);let t=this.techniques.get(g),n=this._gridComputeCoverage(t,e),{horizontalCellCount:r,verticalCellCount:i}=n,a=this._passParameters;return a.horizontalCellCount=r,a.verticalCellCount=i,a.coverageTexture=n.coverage?.getTexture(),n}_renderGrid(e){let t=e.verticalCellCount*e.horizontalCellCount;this.renderingContext.bindVAO(e.vao),this.renderingContext.drawElementsInstanced(E.TRIANGLES,6,D.UNSIGNED_BYTE,0,t)}_gridUpdateResources(e){let t=this._grid,{width:n,height:r}=e.descriptor;if(t.horizontalCellCount=Math.ceil(n/h),t.verticalCellCount=Math.ceil(r/h),t.vao)return;let i=this.renderingContext,a=w.createIndex(i,35044,N);t.vao=new C(i,new A(i,S),a)}_gridComputeCoverage(e,t){let n=this.renderingContext,r=this._grid,i=t.descriptor,a=Math.ceil(i.width/h),o=Math.ceil(i.height/h);this._downsampleDrawParameters.input=t;let{highlights:s}=this.bindParameters;r.coverage?.release();let c=this.fboCache.acquire(a,o,`highlight coverage`,s.length>F?3:1);return r.coverage=c,n.bindFramebuffer(c.fbo),n.bindTechnique(e,this.bindParameters,this._passParameters,this._downsampleDrawParameters),n.setViewport(0,0,a,o),n.screen.draw(),r}get test(){}};e([o()],j.prototype,`consumes`,void 0),e([o()],j.prototype,`produces`,void 0),e([o({constructOnly:!0})],j.prototype,`antialias`,void 0),e([o()],j.prototype,`_optionsData`,null),j=e([s(`esri.views.3d.webgl-engine.effects.highlight.Highlight`)],j);class M{constructor(){this.coverage=null,this.vao=null,this.verticalCellCount=0,this.horizontalCellCount=0,this.viewportWidth=0,this.viewportHeight=0}}const N=new Uint8Array([0,1,2,2,1,3]);function P(e,t,n,r,i,a,o=0){let{highlights:s}=i,l=s.length>1?t.acquire(n,r,`highlight mix`,s.length>F?3:1):null,{gl:u}=e;if(l){let t=e.boundFramebuffer;e.bindFramebuffer(l.fbo),u.clearBufferuiv(u.COLOR,0,[0,0,0,0]),e.bindFramebuffer(t)}let d=l?.getTexture();i.highlightMixTexture=d,c(i.highlightMixOrigin,o,0),s.forEach((t,s)=>{if(s>0){let t=O.TEXTURE_UNIT_FOR_UPDATES;e.bindTexture(d,t),e.setActiveTexture(t),u.copyTexSubImage2D(3553,0,0,0,o,0,n,r),e.bindTexture(null,t)}e.clear(256),i.highlightLevel=s,a()}),i.highlightLevel=null,i.highlightMixTexture=null,l?.release()}const F=4;export{j as Highlight,F as maxHighlightsPerChannel,P as renderHighlightBuffer};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{set as e,transformMat4 as t,subtract as n,normalize as r,scale as i,add as a,dot as o,cross as s,copy as c}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{clone as l,fromValues as u,create as d}from"../../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{ZEROS as f,UNIT_Z as p,create as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{newDoubleArray as h}from"../../../../geometry/support/DoubleArray.js";import{newFloatArray as g,floatArrayFrom as _}from"../../../../geometry/support/FloatArray.js";import{getContinuousIndexArray as v,getZeroIndexArray as y}from"../../../../geometry/support/Indices.js";import{create as b,fromPositionAndNormal as x,intersectRay as S}from"../../../../geometry/support/plane.js";import{wrap as C}from"../../../../geometry/support/ray.js";import{timeStampsToAttribute as w,numTimeStampValuesPerVertex as T}from"../../support/engineContent/line.js";import{Attribute as E}from"./Attribute.js";import{BufferGeometry as D}from"./BufferGeometry.js";import{Buffers as O}from"./Buffers.js";import{scale as k,length as A,normalize as j,add as M}from"./bufferVectorMath.js";import{Geometry as N}from"./Geometry.js";import{assert as P}from"./Util.js";import{getHUDMaterialBufferBaseInstance as F}from"../materials/HUDMaterialBaseInstance.js";import{getInstanceLayout as I}from"../shaders/HUDMaterialTechnique.js";const L=[[-.5,-.5,.5],[.5,-.5,.5],[.5,.5,.5],[-.5,.5,.5],[-.5,-.5,-.5],[.5,-.5,-.5],[.5,.5,-.5],[-.5,.5,-.5]],R=[0,0,1,-1,0,0,1,0,0,0,-1,0,0,1,0,0,0,-1],z=[0,0,1,0,1,1,0,1],ee=[0,1,2,2,3,0,4,0,3,3,7,4,1,5,6,6,2,1,1,0,4,4,5,1,3,2,6,6,7,3,5,4,7,7,6,5],B=Array(36);for(let e=0;e<6;e++)for(let t=0;t<6;t++)B[e*6+t]=e;const V=Array(36);for(let e=0;e<6;e++)V[e*6]=0,V[e*6+1]=1,V[e*6+2]=2,V[e*6+3]=2,V[e*6+4]=3,V[e*6+5]=0;function te(e,t){Array.isArray(t)||(t=[t,t,t]);let n=Array(24);for(let e=0;e<8;e++)n[e*3]=L[e][0]*t[0],n[e*3+1]=L[e][1]*t[1],n[e*3+2]=L[e][2]*t[2];return new N(e,[[`position`,new E(n,ee,3,!0)],[`normal`,new E(R,B,3)],[`uv0`,new E(z,V,2)]])}const H=[[-.5,0,-.5],[.5,0,-.5],[.5,0,.5],[-.5,0,.5],[0,-.5,0],[0,.5,0]],ne=[0,1,-1,1,1,0,0,1,1,-1,1,0,0,-1,-1,1,-1,0,0,-1,1,-1,-1,0],re=[5,1,0,5,2,1,5,3,2,5,0,3,4,0,1,4,1,2,4,2,3,4,3,0],U=[0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7];function W(e,t){Array.isArray(t)||(t=[t,t,t]);let n=Array(18);for(let e=0;e<6;e++)n[e*3]=H[e][0]*t[0],n[e*3+1]=H[e][1]*t[1],n[e*3+2]=H[e][2]*t[2];return new N(e,[[`position`,new E(n,re,3,!0)],[`normal`,new E(ne,U,3)]])}const G=u(-.5,0,-.5),ie=u(.5,0,-.5),K=u(0,0,.5),q=u(0,.5,0),J=d(),Y=d(),X=d(),Z=d(),Q=d();n(J,G,q),n(Y,G,ie),s(X,J,Y),r(X,X),n(J,ie,q),n(Y,ie,K),s(Z,J,Y),r(Z,Z),n(J,K,q),n(Y,K,G),s(Q,J,Y),r(Q,Q);const ae=[G,ie,K,q],oe=[0,-1,0,X[0],X[1],X[2],Z[0],Z[1],Z[2],Q[0],Q[1],Q[2]],se=[0,1,2,3,1,0,3,2,1,3,0,2],ce=[0,0,0,1,1,1,2,2,2,3,3,3];function le(e,t){Array.isArray(t)||(t=[t,t,t]);let n=Array(12);for(let e=0;e<4;e++)n[e*3]=ae[e][0]*t[0],n[e*3+1]=ae[e][1]*t[1],n[e*3+2]=ae[e][2]*t[2];return new N(e,[[`position`,new E(n,se,3,!0)],[`normal`,new E(oe,ce,3)]])}function ue(e,t,n,r,i={uv:!0}){let a=-Math.PI,o=Math.PI*2,s=-Math.PI/2,c=Math.PI,l=Math.max(3,Math.floor(n)),u=Math.max(2,Math.floor(r)),d=(l+1)*(u+1),f=g(d*3),p=g(d*3),m=g(d*2),h=[],_=0;for(let e=0;e<=u;e++){let n=[],r=e/u,i=s+r*c,d=Math.cos(i);for(let e=0;e<=l;e++){let s=e/l,c=a+s*o,u=Math.cos(c)*d,h=Math.sin(i),g=-Math.sin(c)*d;f[3*_]=u*t,f[3*_+1]=h*t,f[3*_+2]=g*t,p[3*_]=u,p[3*_+1]=h,p[3*_+2]=g,m[2*_]=s,m[2*_+1]=r,n.push(_),++_}h.push(n)}let v=[];for(let e=0;e<u;e++)for(let t=0;t<l;t++){let n=h[e][t],r=h[e][t+1],i=h[e+1][t+1],a=h[e+1][t];e===0?(v.push(n),v.push(i),v.push(a)):e===u-1?(v.push(n),v.push(r),v.push(i)):(v.push(n),v.push(r),v.push(i),v.push(i),v.push(a),v.push(n))}let b=[[`position`,new E(f,v,3,!0)],[`normal`,new E(p,v,3,!0)]];return i.uv&&b.push([`uv0`,new E(m,v,2,!0)]),i.offset&&(b[0][0]=`offset`,b.push([`position`,new E(Float64Array.from(i.offset),y(v.length),3,!0)])),new N(e,b)}function de(e,t,n,r){let i=fe(t,n,r);return new N(e,i)}function fe(e,t,n){let r=e,i,a;if(n)i=[0,-1,0,1,0,0,0,0,1,-1,0,0,0,0,-1,0,1,0],a=[0,1,2,0,2,3,0,3,4,0,4,1,1,5,2,2,5,3,3,5,4,4,5,1];else{let e=r*(1+Math.sqrt(5))/2;i=[-r,e,0,r,e,0,-r,-e,0,r,-e,0,0,-r,e,0,r,e,0,-r,-e,0,r,-e,e,0,-r,e,0,r,-e,0,-r,-e,0,r],a=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1]}for(let t=0;t<i.length;t+=3)k(i,t,e/A(i,t));let o={};function s(t,n){t>n&&([t,n]=[n,t]);let r=t.toString()+`.`+n.toString();if(o[r])return o[r];let a=i.length;return i.length+=3,M(i,t*3,i,n*3,i,a),k(i,a,e/A(i,a)),a/=3,o[r]=a,a}for(let e=0;e<t;e++){let e=a.length,t=Array(e*4);for(let n=0;n<e;n+=3){let e=a[n],r=a[n+1],i=a[n+2],o=s(e,r),c=s(r,i),l=s(i,e),u=n*4;t[u]=e,t[u+1]=o,t[u+2]=l,t[u+3]=r,t[u+4]=c,t[u+5]=o,t[u+6]=i,t[u+7]=l,t[u+8]=c,t[u+9]=o,t[u+10]=c,t[u+11]=l}a=t,o={}}let c=_(i);for(let e=0;e<c.length;e+=3)j(c,e);return[[`position`,new E(_(i),a,3,!0)],[`normal`,new E(c,a,3,!0)]]}function pe(e,t,{position:r,normal:i,groundDistance:a,size:o,rotation:s,color:c,uvi:l,centerOffset:u,featureAttribute:d,olidColor:m}={}){let h=I(e.parameters).createBuffer(1);return n($,r??f,t.vec3),h.position.setVec(0,$),h.normal.setVec(0,i??p),h.groundDistance.set(0,a??1),o!=null&&h.size?.setVec(0,o),s!=null&&h.rotation?.set(0,s),c!=null&&h.color?.setVec(0,c),l!=null&&h.uvi?.setVec(0,l),u!=null&&h.centerOffset?.setVec(0,u),d!=null&&h.featureAttribute?.setVec(0,d),m!=null&&h.olidColor?.setVec(0,m),new D(e,new O(h),t,null,F())}const me=[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]];function he(e,t=me){let n=Array(12);for(let e=0;e<4;e++)for(let r=0;r<3;r++)n[e*3+r]=t[e][r];let r=[0,1,2,2,3,0],i=[0,0,1],a=[0,0,0,0,0,0],o=[[`position`,new E(n,r,3,!0)],[`normal`,new E(i,a,3,!0)],[`uv0`,new E([0,0,1,0,1,1,0,1],r,2,!0)],[`color`,new E([255,255,255,255],a,4,!0)]];return new N(e,o)}function ge(e,t,n,r,i=!0,a=!0){let o=0,s=t,c=e,l=u(0,o,0),d=u(0,o+c,0),f=u(0,-1,0),p=u(0,1,0);r&&(o=c,d=u(0,0,0),l=u(0,o,0),f=u(0,1,0),p=u(0,-1,0));let m=[d,l],h=[f,p],_=n+2,v=Math.sqrt(c*c+s*s);if(r)for(let e=n-1;e>=0;e--){let t=2*Math.PI/n*e,r=u(Math.cos(t)*s,o,Math.sin(t)*s);m.push(r);let i=u(c*Math.cos(t)/v,-s/v,c*Math.sin(t)/v);h.push(i)}else for(let e=0;e<n;e++){let t=2*Math.PI/n*e,r=u(Math.cos(t)*s,o,Math.sin(t)*s);m.push(r);let i=u(c*Math.cos(t)/v,s/v,c*Math.sin(t)/v);h.push(i)}let y=[],b=[];if(i){for(let e=3;e<m.length;e++)y.push(1),y.push(e-1),y.push(e),b.push(0),b.push(0),b.push(0);y.push(m.length-1),y.push(2),y.push(1),b.push(0),b.push(0),b.push(0)}if(a){for(let e=3;e<m.length;e++)y.push(e),y.push(e-1),y.push(0),b.push(e),b.push(e-1),b.push(1);y.push(0),y.push(2),y.push(m.length-1),b.push(1),b.push(2),b.push(h.length-1)}let x=g(_*3);for(let e=0;e<_;e++)x[e*3]=m[e][0],x[e*3+1]=m[e][1],x[e*3+2]=m[e][2];let S=g(_*3);for(let e=0;e<_;e++)S[e*3]=h[e][0],S[e*3+1]=h[e][1],S[e*3+2]=h[e][2];return[[`position`,new E(x,y,3,!0)],[`normal`,new E(S,b,3,!0)]]}function _e(e,t,n,r,i,a=!0,o=!0){return new N(e,ge(t,n,r,i,a,o))}function ve(t,n,c,f,p,m,h){let _=p?l(p):u(1,0,0),v=m?l(m):u(0,0,0);h??=!0;let y=d();r(y,_);let b=d();i(b,y,Math.abs(n));let x=d();i(x,b,-.5),a(x,x,v);let S=u(0,1,0);Math.abs(1-o(y,S))<.2&&e(S,0,0,1);let C=d();s(C,y,S),r(C,C),s(S,C,y);let w=f*2+(h?2:0),T=f+(h?2:0),D=g(w*3),O=g(T*3),k=g(w*2),A=Array(f*3*(h?4:2)),j=Array(f*3*(h?4:2));h&&(D[(w-2)*3]=x[0],D[(w-2)*3+1]=x[1],D[(w-2)*3+2]=x[2],k[(w-2)*2]=0,k[(w-2)*2+1]=0,D[(w-1)*3]=D[(w-2)*3]+b[0],D[(w-1)*3+1]=D[(w-2)*3+1]+b[1],D[(w-1)*3+2]=D[(w-2)*3+2]+b[2],k[(w-1)*2]=1,k[(w-1)*2+1]=1,O[(T-2)*3]=-y[0],O[(T-2)*3+1]=-y[1],O[(T-2)*3+2]=-y[2],O[(T-1)*3]=y[0],O[(T-1)*3+1]=y[1],O[(T-1)*3+2]=y[2]);let M=(e,t,n)=>{A[e]=t,j[e]=n},P=0,F=d(),I=d();for(let e=0;e<f;e++){let t=2*Math.PI/f*e;i(F,S,Math.sin(t)),i(I,C,Math.cos(t)),a(F,F,I),O[e*3]=F[0],O[e*3+1]=F[1],O[e*3+2]=F[2],i(F,F,c),a(F,F,x),D[e*3]=F[0],D[e*3+1]=F[1],D[e*3+2]=F[2],k[e*2]=e/f,k[e*2+1]=0,D[(e+f)*3]=D[e*3]+b[0],D[(e+f)*3+1]=D[e*3+1]+b[1],D[(e+f)*3+2]=D[e*3+2]+b[2],k[(e+f)*2]=e/f,k[e*2+1]=1;let n=(e+1)%f;M(P++,e,e),M(P++,e+f,e),M(P++,n,n),M(P++,n,n),M(P++,e+f,e),M(P++,n+f,n)}if(h){for(let e=0;e<f;e++){let t=(e+1)%f;M(P++,w-2,T-2),M(P++,e,T-2),M(P++,t,T-2)}for(let e=0;e<f;e++){let t=(e+1)%f;M(P++,e+f,T-1),M(P++,w-1,T-1),M(P++,t+f,T-1)}}let L=[[`position`,new E(D,A,3,!0)],[`normal`,new E(O,j,3,!0)],[`uv0`,new E(k,A,2,!0)]];return new N(t,L)}function ye(e,t,n,r,i,a){r||=10,i??=!0,P(t.length>1);let o=[[0,0,0]],s=[],c=[];for(let e=0;e<r;e++){s.push([0,-e-1,-((e+1)%r)-1]);let t=e/r*2*Math.PI;c.push([Math.cos(t)*n,Math.sin(t)*n])}return be(e,c,t,o,s,i,a)}function be(t,o,l,d,f,p,h=u(0,0,0)){let _=o.length,v=g(l.length*_*3+(d.length*6||0)),y=g(l.length*_*3+(d?6:0)),w=[],T=[],D=0,O=0,k=m(),A=m(),j=m(),M=m(),P=m(),F=m(),I=m(),L=m(),R=m(),z=m(),ee=m(),B=m(),V=m(),te=b();e(R,0,1,0),n(A,l[1],l[0]),r(A,A),p?(a(L,l[0],h),r(j,L)):e(j,0,0,1),Ee(A,j,R,R,P,j,De),c(M,j),c(B,P);for(let e=0;e<d.length;e++)i(F,P,d[e][0]),i(L,j,d[e][2]),a(F,F,L),a(F,F,l[0]),v[D++]=F[0],v[D++]=F[1],v[D++]=F[2];y[O++]=-A[0],y[O++]=-A[1],y[O++]=-A[2];for(let e=0;e<f.length;e++)w.push(f[e][0]>0?f[e][0]:-f[e][0]-1+d.length),w.push(f[e][1]>0?f[e][1]:-f[e][1]-1+d.length),w.push(f[e][2]>0?f[e][2]:-f[e][2]-1+d.length),T.push(0),T.push(0),T.push(0);let H=d.length,ne=d.length-1;for(let e=0;e<l.length;e++){let t=!1;e>0&&(c(k,A),e<l.length-1?(n(A,l[e+1],l[e]),r(A,A)):t=!0,a(z,k,A),r(z,z),a(ee,l[e-1],M),x(l[e],z,te),S(te,C(ee,k),L)?(n(L,L,l[e]),r(j,L),s(P,z,j),r(P,P)):Ee(z,M,B,R,P,j,De),c(M,j),c(B,P)),p&&(a(L,l[e],h),r(V,L));for(let n=0;n<_;n++)if(i(F,P,o[n][0]),i(L,j,o[n][1]),a(F,F,L),r(I,F),y[O++]=I[0],y[O++]=I[1],y[O++]=I[2],a(F,F,l[e]),v[D++]=F[0],v[D++]=F[1],v[D++]=F[2],!t){let e=(n+1)%_;w.push(H+n),w.push(H+_+n),w.push(H+e),w.push(H+e),w.push(H+_+n),w.push(H+_+e);for(let e=0;e<6;e++){let t=w.length-6;T.push(w[t+e]-ne)}}H+=_}let re=l[l.length-1];for(let e=0;e<d.length;e++)i(F,P,d[e][0]),i(L,j,d[e][1]),a(F,F,L),a(F,F,re),v[D++]=F[0],v[D++]=F[1],v[D++]=F[2];let U=O/3;y[O++]=A[0],y[O++]=A[1],y[O++]=A[2];let W=H-_;for(let e=0;e<f.length;e++)w.push(f[e][0]>=0?H+f[e][0]:-f[e][0]-1+W),w.push(f[e][2]>=0?H+f[e][2]:-f[e][2]-1+W),w.push(f[e][1]>=0?H+f[e][1]:-f[e][1]-1+W),T.push(U),T.push(U),T.push(U);let G=[[`position`,new E(v,w,3,!0)],[`normal`,new E(y,T,3,!0)]];return new N(t,G)}function xe(e,t,n,r,i){let a=h(t.length*3),o=Array(2*(t.length-1)),s=0,c=0;for(let e=0;e<t.length;e++){for(let n=0;n<3;n++)a[s++]=t[e][n];e>0&&(o[c++]=e-1,o[c++]=e)}let l=[[`position`,new E(a,o,3,!0)]];if(n?.length===t.length&&n[0].length===3){let e=g(n.length*3),r=0;for(let i=0;i<t.length;i++)for(let t=0;t<3;t++)e[r++]=n[i][t];l.push([`normal`,new E(e,o,3,!0)])}if(r&&l.push([`color`,new E(r,v(r.length/4),4)]),i?.length===t.length){let e=w(i,1);l.push([`timeStamps`,new E(e,o,T,!0)])}return new N(e,l,null)}function Se(e,t,n,r,i,a=0){let o=Array(18),s=[[-n,a,i/2],[r,a,i/2],[0,t+a,i/2],[-n,a,-i/2],[r,a,-i/2],[0,t+a,-i/2]],c=[0,1,2,3,0,2,2,5,3,1,4,5,5,2,1,1,0,3,3,4,1,4,3,5];for(let e=0;e<6;e++)o[e*3]=s[e][0],o[e*3+1]=s[e][1],o[e*3+2]=s[e][2];return new N(e,[[`position`,new E(o,c,3,!0)]])}function Ce(n,r){let i=n.getMutableAttribute(`position`).data;for(let n=0;n<i.length;n+=3){let a=i[n],o=i[n+1],s=i[n+2];e($,a,o,s),t($,$,r),i[n]=$[0],i[n+1]=$[1],i[n+2]=$[2]}}function we(e,t=e){let n=e.attributes,r=n.get(`position`).data,i=n.get(`normal`).data;if(i){let e=t.getMutableAttribute(`normal`).data;for(let t=0;t<i.length;t+=3){let n=i[t+1];e[t+1]=-i[t+2],e[t+2]=n}}if(r){let e=t.getMutableAttribute(`position`).data;for(let t=0;t<r.length;t+=3){let n=r[t+1];e[t+1]=-r[t+2],e[t+2]=n}}}function Te(e,t,n,i,a){return Math.abs(o(t,e))>a?!1:(s(n,e,t),r(n,n),s(i,n,e),r(i,i),!0)}function Ee(e,t,n,r,i,a,o){return Te(e,t,i,a,o)||Te(e,n,i,a,o)||Te(e,r,i,a,o)}const De=.99619469809,$=m();export{we as cgToGIS,te as createBoxGeometry,_e as createConeGeometry,ge as createConeGeometryData,ve as createCylinderGeometry,W as createDiamondGeometry,Se as createExtrudedTriangle,be as createPathExtrusionGeometry,pe as createPointBufferGeometry,fe as createPolySphereData,de as createPolySphereGeometry,xe as createPolylineGeometry,ue as createSphereGeometry,he as createSquareGeometry,le as createTetrahedronGeometry,ye as createTubeGeometry,Ee as makeOrthoBasisDirUpFallback,Ce as transformInPlace};
2
+ import{set as e,transformMat4 as t,subtract as n,normalize as r,scale as i,add as a,dot as o,cross as s,copy as c}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{clone as l,fromValues as u,create as d}from"../../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{ZEROS as f,UNIT_Z as p,create as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{newDoubleArray as h}from"../../../../geometry/support/DoubleArray.js";import{newFloatArray as g,floatArrayFrom as _}from"../../../../geometry/support/FloatArray.js";import{getContinuousIndexArray as v,getZeroIndexArray as y}from"../../../../geometry/support/Indices.js";import{create as b,fromPositionAndNormal as x,intersectRay as S}from"../../../../geometry/support/plane.js";import{wrap as C}from"../../../../geometry/support/ray.js";import{timeStampsToAttribute as w,numTimeStampValuesPerVertex as T}from"../../support/engineContent/line.js";import{Attribute as E}from"./Attribute.js";import{BufferGeometry as D}from"./BufferGeometry.js";import{Buffers as O}from"./Buffers.js";import{scale as k,length as A,normalize as j,add as M}from"./bufferVectorMath.js";import{Geometry as N}from"./Geometry.js";import{assert as P}from"./Util.js";import{getHUDMaterialBufferBaseInstance as F}from"../materials/HUDMaterialBaseInstance.js";import{getInstanceLayout as I}from"../shaders/hudMaterialLayouts.js";const L=[[-.5,-.5,.5],[.5,-.5,.5],[.5,.5,.5],[-.5,.5,.5],[-.5,-.5,-.5],[.5,-.5,-.5],[.5,.5,-.5],[-.5,.5,-.5]],R=[0,0,1,-1,0,0,1,0,0,0,-1,0,0,1,0,0,0,-1],z=[0,0,1,0,1,1,0,1],ee=[0,1,2,2,3,0,4,0,3,3,7,4,1,5,6,6,2,1,1,0,4,4,5,1,3,2,6,6,7,3,5,4,7,7,6,5],B=Array(36);for(let e=0;e<6;e++)for(let t=0;t<6;t++)B[e*6+t]=e;const V=Array(36);for(let e=0;e<6;e++)V[e*6]=0,V[e*6+1]=1,V[e*6+2]=2,V[e*6+3]=2,V[e*6+4]=3,V[e*6+5]=0;function te(e,t){Array.isArray(t)||(t=[t,t,t]);let n=Array(24);for(let e=0;e<8;e++)n[e*3]=L[e][0]*t[0],n[e*3+1]=L[e][1]*t[1],n[e*3+2]=L[e][2]*t[2];return new N(e,[[`position`,new E(n,ee,3,!0)],[`normal`,new E(R,B,3)],[`uv0`,new E(z,V,2)]])}const H=[[-.5,0,-.5],[.5,0,-.5],[.5,0,.5],[-.5,0,.5],[0,-.5,0],[0,.5,0]],ne=[0,1,-1,1,1,0,0,1,1,-1,1,0,0,-1,-1,1,-1,0,0,-1,1,-1,-1,0],re=[5,1,0,5,2,1,5,3,2,5,0,3,4,0,1,4,1,2,4,2,3,4,3,0],U=[0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7];function W(e,t){Array.isArray(t)||(t=[t,t,t]);let n=Array(18);for(let e=0;e<6;e++)n[e*3]=H[e][0]*t[0],n[e*3+1]=H[e][1]*t[1],n[e*3+2]=H[e][2]*t[2];return new N(e,[[`position`,new E(n,re,3,!0)],[`normal`,new E(ne,U,3)]])}const G=u(-.5,0,-.5),ie=u(.5,0,-.5),K=u(0,0,.5),q=u(0,.5,0),J=d(),Y=d(),X=d(),Z=d(),Q=d();n(J,G,q),n(Y,G,ie),s(X,J,Y),r(X,X),n(J,ie,q),n(Y,ie,K),s(Z,J,Y),r(Z,Z),n(J,K,q),n(Y,K,G),s(Q,J,Y),r(Q,Q);const ae=[G,ie,K,q],oe=[0,-1,0,X[0],X[1],X[2],Z[0],Z[1],Z[2],Q[0],Q[1],Q[2]],se=[0,1,2,3,1,0,3,2,1,3,0,2],ce=[0,0,0,1,1,1,2,2,2,3,3,3];function le(e,t){Array.isArray(t)||(t=[t,t,t]);let n=Array(12);for(let e=0;e<4;e++)n[e*3]=ae[e][0]*t[0],n[e*3+1]=ae[e][1]*t[1],n[e*3+2]=ae[e][2]*t[2];return new N(e,[[`position`,new E(n,se,3,!0)],[`normal`,new E(oe,ce,3)]])}function ue(e,t,n,r,i={uv:!0}){let a=-Math.PI,o=Math.PI*2,s=-Math.PI/2,c=Math.PI,l=Math.max(3,Math.floor(n)),u=Math.max(2,Math.floor(r)),d=(l+1)*(u+1),f=g(d*3),p=g(d*3),m=g(d*2),h=[],_=0;for(let e=0;e<=u;e++){let n=[],r=e/u,i=s+r*c,d=Math.cos(i);for(let e=0;e<=l;e++){let s=e/l,c=a+s*o,u=Math.cos(c)*d,h=Math.sin(i),g=-Math.sin(c)*d;f[3*_]=u*t,f[3*_+1]=h*t,f[3*_+2]=g*t,p[3*_]=u,p[3*_+1]=h,p[3*_+2]=g,m[2*_]=s,m[2*_+1]=r,n.push(_),++_}h.push(n)}let v=[];for(let e=0;e<u;e++)for(let t=0;t<l;t++){let n=h[e][t],r=h[e][t+1],i=h[e+1][t+1],a=h[e+1][t];e===0?(v.push(n),v.push(i),v.push(a)):e===u-1?(v.push(n),v.push(r),v.push(i)):(v.push(n),v.push(r),v.push(i),v.push(i),v.push(a),v.push(n))}let b=[[`position`,new E(f,v,3,!0)],[`normal`,new E(p,v,3,!0)]];return i.uv&&b.push([`uv0`,new E(m,v,2,!0)]),i.offset&&(b[0][0]=`offset`,b.push([`position`,new E(Float64Array.from(i.offset),y(v.length),3,!0)])),new N(e,b)}function de(e,t,n,r){let i=fe(t,n,r);return new N(e,i)}function fe(e,t,n){let r=e,i,a;if(n)i=[0,-1,0,1,0,0,0,0,1,-1,0,0,0,0,-1,0,1,0],a=[0,1,2,0,2,3,0,3,4,0,4,1,1,5,2,2,5,3,3,5,4,4,5,1];else{let e=r*(1+Math.sqrt(5))/2;i=[-r,e,0,r,e,0,-r,-e,0,r,-e,0,0,-r,e,0,r,e,0,-r,-e,0,r,-e,e,0,-r,e,0,r,-e,0,-r,-e,0,r],a=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1]}for(let t=0;t<i.length;t+=3)k(i,t,e/A(i,t));let o={};function s(t,n){t>n&&([t,n]=[n,t]);let r=t.toString()+`.`+n.toString();if(o[r])return o[r];let a=i.length;return i.length+=3,M(i,t*3,i,n*3,i,a),k(i,a,e/A(i,a)),a/=3,o[r]=a,a}for(let e=0;e<t;e++){let e=a.length,t=Array(e*4);for(let n=0;n<e;n+=3){let e=a[n],r=a[n+1],i=a[n+2],o=s(e,r),c=s(r,i),l=s(i,e),u=n*4;t[u]=e,t[u+1]=o,t[u+2]=l,t[u+3]=r,t[u+4]=c,t[u+5]=o,t[u+6]=i,t[u+7]=l,t[u+8]=c,t[u+9]=o,t[u+10]=c,t[u+11]=l}a=t,o={}}let c=_(i);for(let e=0;e<c.length;e+=3)j(c,e);return[[`position`,new E(_(i),a,3,!0)],[`normal`,new E(c,a,3,!0)]]}function pe(e,t,{position:r,normal:i,groundDistance:a,size:o,rotation:s,color:c,uvi:l,centerOffset:u,featureAttribute:d,olidColor:m}={}){let h=I(e.parameters).createBuffer(1);return n($,r??f,t.vec3),h.position.setVec(0,$),h.normal.setVec(0,i??p),h.groundDistance.set(0,a??1),o!=null&&h.size?.setVec(0,o),s!=null&&h.rotation?.set(0,s),c!=null&&h.color?.setVec(0,c),l!=null&&h.uvi?.setVec(0,l),u!=null&&h.centerOffset?.setVec(0,u),d!=null&&h.featureAttribute?.setVec(0,d),m!=null&&h.olidColor?.setVec(0,m),new D(e,new O(h),t,null,F())}const me=[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]];function he(e,t=me){let n=Array(12);for(let e=0;e<4;e++)for(let r=0;r<3;r++)n[e*3+r]=t[e][r];let r=[0,1,2,2,3,0],i=[0,0,1],a=[0,0,0,0,0,0],o=[[`position`,new E(n,r,3,!0)],[`normal`,new E(i,a,3,!0)],[`uv0`,new E([0,0,1,0,1,1,0,1],r,2,!0)],[`color`,new E([255,255,255,255],a,4,!0)]];return new N(e,o)}function ge(e,t,n,r,i=!0,a=!0){let o=0,s=t,c=e,l=u(0,o,0),d=u(0,o+c,0),f=u(0,-1,0),p=u(0,1,0);r&&(o=c,d=u(0,0,0),l=u(0,o,0),f=u(0,1,0),p=u(0,-1,0));let m=[d,l],h=[f,p],_=n+2,v=Math.sqrt(c*c+s*s);if(r)for(let e=n-1;e>=0;e--){let t=2*Math.PI/n*e,r=u(Math.cos(t)*s,o,Math.sin(t)*s);m.push(r);let i=u(c*Math.cos(t)/v,-s/v,c*Math.sin(t)/v);h.push(i)}else for(let e=0;e<n;e++){let t=2*Math.PI/n*e,r=u(Math.cos(t)*s,o,Math.sin(t)*s);m.push(r);let i=u(c*Math.cos(t)/v,s/v,c*Math.sin(t)/v);h.push(i)}let y=[],b=[];if(i){for(let e=3;e<m.length;e++)y.push(1),y.push(e-1),y.push(e),b.push(0),b.push(0),b.push(0);y.push(m.length-1),y.push(2),y.push(1),b.push(0),b.push(0),b.push(0)}if(a){for(let e=3;e<m.length;e++)y.push(e),y.push(e-1),y.push(0),b.push(e),b.push(e-1),b.push(1);y.push(0),y.push(2),y.push(m.length-1),b.push(1),b.push(2),b.push(h.length-1)}let x=g(_*3);for(let e=0;e<_;e++)x[e*3]=m[e][0],x[e*3+1]=m[e][1],x[e*3+2]=m[e][2];let S=g(_*3);for(let e=0;e<_;e++)S[e*3]=h[e][0],S[e*3+1]=h[e][1],S[e*3+2]=h[e][2];return[[`position`,new E(x,y,3,!0)],[`normal`,new E(S,b,3,!0)]]}function _e(e,t,n,r,i,a=!0,o=!0){return new N(e,ge(t,n,r,i,a,o))}function ve(t,n,c,f,p,m,h){let _=p?l(p):u(1,0,0),v=m?l(m):u(0,0,0);h??=!0;let y=d();r(y,_);let b=d();i(b,y,Math.abs(n));let x=d();i(x,b,-.5),a(x,x,v);let S=u(0,1,0);Math.abs(1-o(y,S))<.2&&e(S,0,0,1);let C=d();s(C,y,S),r(C,C),s(S,C,y);let w=f*2+(h?2:0),T=f+(h?2:0),D=g(w*3),O=g(T*3),k=g(w*2),A=Array(f*3*(h?4:2)),j=Array(f*3*(h?4:2));h&&(D[(w-2)*3]=x[0],D[(w-2)*3+1]=x[1],D[(w-2)*3+2]=x[2],k[(w-2)*2]=0,k[(w-2)*2+1]=0,D[(w-1)*3]=D[(w-2)*3]+b[0],D[(w-1)*3+1]=D[(w-2)*3+1]+b[1],D[(w-1)*3+2]=D[(w-2)*3+2]+b[2],k[(w-1)*2]=1,k[(w-1)*2+1]=1,O[(T-2)*3]=-y[0],O[(T-2)*3+1]=-y[1],O[(T-2)*3+2]=-y[2],O[(T-1)*3]=y[0],O[(T-1)*3+1]=y[1],O[(T-1)*3+2]=y[2]);let M=(e,t,n)=>{A[e]=t,j[e]=n},P=0,F=d(),I=d();for(let e=0;e<f;e++){let t=2*Math.PI/f*e;i(F,S,Math.sin(t)),i(I,C,Math.cos(t)),a(F,F,I),O[e*3]=F[0],O[e*3+1]=F[1],O[e*3+2]=F[2],i(F,F,c),a(F,F,x),D[e*3]=F[0],D[e*3+1]=F[1],D[e*3+2]=F[2],k[e*2]=e/f,k[e*2+1]=0,D[(e+f)*3]=D[e*3]+b[0],D[(e+f)*3+1]=D[e*3+1]+b[1],D[(e+f)*3+2]=D[e*3+2]+b[2],k[(e+f)*2]=e/f,k[e*2+1]=1;let n=(e+1)%f;M(P++,e,e),M(P++,e+f,e),M(P++,n,n),M(P++,n,n),M(P++,e+f,e),M(P++,n+f,n)}if(h){for(let e=0;e<f;e++){let t=(e+1)%f;M(P++,w-2,T-2),M(P++,e,T-2),M(P++,t,T-2)}for(let e=0;e<f;e++){let t=(e+1)%f;M(P++,e+f,T-1),M(P++,w-1,T-1),M(P++,t+f,T-1)}}let L=[[`position`,new E(D,A,3,!0)],[`normal`,new E(O,j,3,!0)],[`uv0`,new E(k,A,2,!0)]];return new N(t,L)}function ye(e,t,n,r,i,a){r||=10,i??=!0,P(t.length>1);let o=[[0,0,0]],s=[],c=[];for(let e=0;e<r;e++){s.push([0,-e-1,-((e+1)%r)-1]);let t=e/r*2*Math.PI;c.push([Math.cos(t)*n,Math.sin(t)*n])}return be(e,c,t,o,s,i,a)}function be(t,o,l,d,f,p,h=u(0,0,0)){let _=o.length,v=g(l.length*_*3+(d.length*6||0)),y=g(l.length*_*3+(d?6:0)),w=[],T=[],D=0,O=0,k=m(),A=m(),j=m(),M=m(),P=m(),F=m(),I=m(),L=m(),R=m(),z=m(),ee=m(),B=m(),V=m(),te=b();e(R,0,1,0),n(A,l[1],l[0]),r(A,A),p?(a(L,l[0],h),r(j,L)):e(j,0,0,1),Ee(A,j,R,R,P,j,De),c(M,j),c(B,P);for(let e=0;e<d.length;e++)i(F,P,d[e][0]),i(L,j,d[e][2]),a(F,F,L),a(F,F,l[0]),v[D++]=F[0],v[D++]=F[1],v[D++]=F[2];y[O++]=-A[0],y[O++]=-A[1],y[O++]=-A[2];for(let e=0;e<f.length;e++)w.push(f[e][0]>0?f[e][0]:-f[e][0]-1+d.length),w.push(f[e][1]>0?f[e][1]:-f[e][1]-1+d.length),w.push(f[e][2]>0?f[e][2]:-f[e][2]-1+d.length),T.push(0),T.push(0),T.push(0);let H=d.length,ne=d.length-1;for(let e=0;e<l.length;e++){let t=!1;e>0&&(c(k,A),e<l.length-1?(n(A,l[e+1],l[e]),r(A,A)):t=!0,a(z,k,A),r(z,z),a(ee,l[e-1],M),x(l[e],z,te),S(te,C(ee,k),L)?(n(L,L,l[e]),r(j,L),s(P,z,j),r(P,P)):Ee(z,M,B,R,P,j,De),c(M,j),c(B,P)),p&&(a(L,l[e],h),r(V,L));for(let n=0;n<_;n++)if(i(F,P,o[n][0]),i(L,j,o[n][1]),a(F,F,L),r(I,F),y[O++]=I[0],y[O++]=I[1],y[O++]=I[2],a(F,F,l[e]),v[D++]=F[0],v[D++]=F[1],v[D++]=F[2],!t){let e=(n+1)%_;w.push(H+n),w.push(H+_+n),w.push(H+e),w.push(H+e),w.push(H+_+n),w.push(H+_+e);for(let e=0;e<6;e++){let t=w.length-6;T.push(w[t+e]-ne)}}H+=_}let re=l[l.length-1];for(let e=0;e<d.length;e++)i(F,P,d[e][0]),i(L,j,d[e][1]),a(F,F,L),a(F,F,re),v[D++]=F[0],v[D++]=F[1],v[D++]=F[2];let U=O/3;y[O++]=A[0],y[O++]=A[1],y[O++]=A[2];let W=H-_;for(let e=0;e<f.length;e++)w.push(f[e][0]>=0?H+f[e][0]:-f[e][0]-1+W),w.push(f[e][2]>=0?H+f[e][2]:-f[e][2]-1+W),w.push(f[e][1]>=0?H+f[e][1]:-f[e][1]-1+W),T.push(U),T.push(U),T.push(U);let G=[[`position`,new E(v,w,3,!0)],[`normal`,new E(y,T,3,!0)]];return new N(t,G)}function xe(e,t,n,r,i){let a=h(t.length*3),o=Array(2*(t.length-1)),s=0,c=0;for(let e=0;e<t.length;e++){for(let n=0;n<3;n++)a[s++]=t[e][n];e>0&&(o[c++]=e-1,o[c++]=e)}let l=[[`position`,new E(a,o,3,!0)]];if(n?.length===t.length&&n[0].length===3){let e=g(n.length*3),r=0;for(let i=0;i<t.length;i++)for(let t=0;t<3;t++)e[r++]=n[i][t];l.push([`normal`,new E(e,o,3,!0)])}if(r&&l.push([`color`,new E(r,v(r.length/4),4)]),i?.length===t.length){let e=w(i,1);l.push([`timeStamps`,new E(e,o,T,!0)])}return new N(e,l,null)}function Se(e,t,n,r,i,a=0){let o=Array(18),s=[[-n,a,i/2],[r,a,i/2],[0,t+a,i/2],[-n,a,-i/2],[r,a,-i/2],[0,t+a,-i/2]],c=[0,1,2,3,0,2,2,5,3,1,4,5,5,2,1,1,0,3,3,4,1,4,3,5];for(let e=0;e<6;e++)o[e*3]=s[e][0],o[e*3+1]=s[e][1],o[e*3+2]=s[e][2];return new N(e,[[`position`,new E(o,c,3,!0)]])}function Ce(n,r){let i=n.getMutableAttribute(`position`).data;for(let n=0;n<i.length;n+=3){let a=i[n],o=i[n+1],s=i[n+2];e($,a,o,s),t($,$,r),i[n]=$[0],i[n+1]=$[1],i[n+2]=$[2]}}function we(e,t=e){let n=e.attributes,r=n.get(`position`).data,i=n.get(`normal`).data;if(i){let e=t.getMutableAttribute(`normal`).data;for(let t=0;t<i.length;t+=3){let n=i[t+1];e[t+1]=-i[t+2],e[t+2]=n}}if(r){let e=t.getMutableAttribute(`position`).data;for(let t=0;t<r.length;t+=3){let n=r[t+1];e[t+1]=-r[t+2],e[t+2]=n}}}function Te(e,t,n,i,a){return Math.abs(o(t,e))>a?!1:(s(n,e,t),r(n,n),s(i,n,e),r(i,i),!0)}function Ee(e,t,n,r,i,a,o){return Te(e,t,i,a,o)||Te(e,n,i,a,o)||Te(e,r,i,a,o)}const De=.99619469809,$=m();export{we as cgToGIS,te as createBoxGeometry,_e as createConeGeometry,ge as createConeGeometryData,ve as createCylinderGeometry,W as createDiamondGeometry,Se as createExtrudedTriangle,be as createPathExtrusionGeometry,pe as createPointBufferGeometry,fe as createPolySphereData,de as createPolySphereGeometry,xe as createPolylineGeometry,ue as createSphereGeometry,he as createSquareGeometry,le as createTetrahedronGeometry,ye as createTubeGeometry,Ee as makeOrthoBasisDirUpFallback,Ce as transformInPlace};