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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/WebLinkChart.js +1 -1
  2. package/analysis/ShadowCast/types.d.ts +2 -0
  3. package/applications/Components/analysisUtils.d.ts +1 -0
  4. package/applications/Components/analysisUtils.js +1 -1
  5. package/arcade/arcadeAsyncRuntime.js +1 -1
  6. package/arcade/arcadeCompiler.js +1 -1
  7. package/arcade/featureSetUtils.js +1 -1
  8. package/arcade/featureset/actions/Adapted.js +1 -1
  9. package/arcade/featureset/actions/AttributeFilter.js +1 -1
  10. package/arcade/featureset/actions/GroupBy.js +1 -1
  11. package/arcade/featureset/actions/SpatialFilter.js +1 -1
  12. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  13. package/arcade/featureset/sources/FeatureLayerMemory.js +1 -1
  14. package/arcade/featureset/sources/FeatureLayerOGC.js +1 -1
  15. package/arcade/featureset/sources/FeatureLayerRelated.js +1 -1
  16. package/arcade/featureset/support/FeatureSet.js +1 -1
  17. package/arcade/featureset/support/FeatureSetIterator.js +1 -1
  18. package/assets/esri/core/workers/RemoteClient.js +1 -1
  19. package/assets/esri/core/workers/chunks/014dbe6fa93a277b08f7.js +1 -0
  20. package/assets/esri/core/workers/chunks/{51355866a0dcf41cfded.js → 0a5427127634738aa239.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{c7c721de93bc8688e13c.js → 1d4ea8db272655c0608c.js} +1 -1
  22. package/assets/esri/core/workers/chunks/1d566539ff6fb6ac798c.js +1 -0
  23. package/assets/esri/core/workers/chunks/1de216d9850c39c1735d.js +1 -0
  24. package/assets/esri/core/workers/chunks/262232437d37a7460b11.js +1 -0
  25. package/assets/esri/core/workers/chunks/{1817cf11e85afca947d3.js → 328106e181e5957ceaa5.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{d3db7244fac7398cc700.js → 4b6a44c6265c8959abd8.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{f1ac1c8b1331ec79e898.js → 59ce992d3a5e7c32b9fb.js} +1 -1
  28. package/assets/esri/core/workers/chunks/{8a946cbc816f373c136b.js → 5e30acfda04f7fc2b676.js} +1 -1
  29. package/assets/esri/core/workers/chunks/6330d8767ba1d5329daa.js +1 -0
  30. package/assets/esri/core/workers/chunks/{3f03165487c1c2340fff.js → 690a40d2eef52bfc149f.js} +1 -1
  31. package/assets/esri/core/workers/chunks/{dd34d56caafa38d4b8e4.js → 7aa730e5ac7b268e3c98.js} +1 -1
  32. package/assets/esri/core/workers/chunks/{1fa55d4c4b092a98bdd7.js → b56c07c0b43cb1999070.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{24a3c6f0154787968724.js → c5967133f3ba34a883f8.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{bfb9cbe59d36d18f9157.js → cda5c95fd49b8901f7d4.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{b451dc416eebd0931ef8.js → ce8fc1ca229d53a4b68d.js} +6 -6
  36. package/assets/esri/core/workers/chunks/{c9e7cc5d853908ab5b2f.js → ce99abfdcd71ff9e4e36.js} +1 -1
  37. package/assets/esri/core/workers/chunks/{726a797f5df7eeee0b3d.js → d786b17cc9062b1450ac.js} +1 -1
  38. package/assets/esri/core/workers/chunks/{2e76fbd3c874300fc4a7.js → de3da4d31a7529761565.js} +1 -1
  39. package/assets/esri/core/workers/chunks/{eb6218634a492667506a.js → e501d68a1464805c4b4e.js} +1 -1
  40. package/assets/esri/core/workers/chunks/{33431e8131f6017de2f9.js → e7f4d135ef9665de1468.js} +1 -1
  41. package/assets/esri/core/workers/chunks/{d8623f5f13a084e439c2.js → e9bc3c6482ba778c9349.js} +37 -37
  42. package/assets/esri/core/workers/chunks/{7420fa18ba12014b22ea.js → ee67c8a7c1f8b482cd99.js} +1 -1
  43. package/assets/esri/core/workers/chunks/{abb05a903440d97a6a74.js → f441fc74451330384fb0.js} +1 -1
  44. package/assets/esri/core/workers/chunks/f609b256df9eb3803464.js +1 -0
  45. package/assets/esri/core/workers/chunks/f97a7cb367634353177d.js +1 -0
  46. package/chunks/CloudsComposition.glsl.js +1 -1
  47. package/chunks/ComponentShader.glsl.js +2 -2
  48. package/chunks/DefaultMaterial.glsl.js +1 -1
  49. package/chunks/GaussianSplat.glsl.js +2 -2
  50. package/chunks/Laserlines.glsl.js +1 -1
  51. package/chunks/Path.glsl.js +1 -1
  52. package/chunks/RealisticTree.glsl.js +1 -1
  53. package/chunks/Terrain.glsl.js +34 -36
  54. package/chunks/WaterSurface.glsl.js +1 -1
  55. package/chunks/boundedPlane.js +1 -1
  56. package/chunks/cameraUtilsSpherical.js +1 -1
  57. package/chunks/vec32.js +1 -1
  58. package/config.js +1 -1
  59. package/core/has.js +1 -1
  60. package/core/iteratorUtils.js +1 -1
  61. package/core/libs/gl-matrix-2/math/quat.js +1 -1
  62. package/core/libs/gl-matrix-2/math/vec3.js +1 -1
  63. package/geometry/support/lineSegment.js +1 -1
  64. package/geometry/support/meshUtils/merge.js +1 -1
  65. package/geometry/support/sphere.js +1 -1
  66. package/interfaces.d.ts +35 -5
  67. package/kernel.js +1 -1
  68. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  69. package/layers/VoxelWasmPerSceneView.js +1 -1
  70. package/layers/knowledgeGraph/layerUtils.js +1 -1
  71. package/layers/orientedImagery/transformations/worldToImage.js +1 -1
  72. package/layers/support/csvUtils.js +1 -1
  73. package/layers/video/VideoController.js +1 -1
  74. package/layers/voxel/VoxelVolume.js +1 -1
  75. package/package.json +5 -5
  76. package/support/revision.js +1 -1
  77. package/views/2d/analysis/ElevationProfile/ElevationProfileLineVisualization2D.js +1 -1
  78. package/views/2d/interactive/SegmentLabels2D.js +1 -1
  79. package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
  80. package/views/3d/FocusAreasView.js +1 -1
  81. package/views/3d/analysis/AreaMeasurement/support/MeasurementData.js +1 -1
  82. package/views/3d/analysis/Dimension/lengthDimensionConstraintUtils.js +1 -1
  83. package/views/3d/analysis/Dimension/lengthDimensionUtils.js +1 -1
  84. package/views/3d/analysis/ElevationProfile/ElevationProfileLineVisualization3D.js +1 -1
  85. package/views/3d/analysis/ElevationProfile/ElevationProfileVisualization3D.js +1 -1
  86. package/views/3d/analysis/ElevationProfileAnalysisView3D.js +1 -1
  87. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  88. package/views/3d/analysis/LineOfSight/LineOfSightIntersectionResult.js +1 -1
  89. package/views/3d/analysis/Slice/sliceToolUtils.js +1 -1
  90. package/views/3d/analysis/Viewshed/ViewshedScaleOrientManipulation.js +1 -1
  91. package/views/3d/analysis/Viewshed/ViewshedSubTool.js +1 -1
  92. package/views/3d/analysis/Viewshed/ViewshedSubVisualization.js +1 -1
  93. package/views/3d/analysis/Viewshed/ViewshedTool.js +1 -1
  94. package/views/3d/animation/pointToPoint/Camera.js +1 -1
  95. package/views/3d/camera/constraintUtils/distance.js +1 -1
  96. package/views/3d/camera/constraintUtils/tilt.js +1 -1
  97. package/views/3d/environment/ChapmanAtmosphere.js +1 -1
  98. package/views/3d/environment/CloudsParameters.js +1 -1
  99. package/views/3d/environment/EnvironmentManager.js +1 -1
  100. package/views/3d/environment/MarsAtmosphere.js +1 -1
  101. package/views/3d/interactive/SegmentLabels3D.js +1 -1
  102. package/views/3d/interactive/editingTools/manipulations/MoveZManipulation.js +1 -1
  103. package/views/3d/interactive/editingTools/media/MediaElementManipulator3D.js +1 -1
  104. package/views/3d/interactive/editingTools/reshape/edgeOffsetUtils.js +1 -1
  105. package/views/3d/interactive/measurementTools/directLineMeasurement3D/DirectLineMeasurement3DTool.js +1 -1
  106. package/views/3d/interactive/visualElements/MeasurementArrowVisualElement.js +1 -1
  107. package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
  108. package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
  109. package/views/3d/layers/GraphicsLayerView3D.js +1 -1
  110. package/views/3d/layers/I3SMeshView3D.js +1 -1
  111. package/views/3d/layers/ImagerySubView3D.js +1 -1
  112. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  113. package/views/3d/layers/RouteLayerView3D.js +1 -1
  114. package/views/3d/layers/graphics/Graphics3DGraphicsPipeline.js +1 -1
  115. package/views/3d/layers/graphics/Graphics3DScaleVisibility.js +1 -1
  116. package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
  117. package/views/3d/layers/graphics/pipeline/rendering/DirectRenderer.js +1 -1
  118. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  119. package/views/3d/layers/i3s/PointCloudRenderer.js +1 -1
  120. package/views/3d/layers/support/FeatureTileMeasurements3D.js +1 -1
  121. package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
  122. package/views/3d/state/Frustum.js +1 -1
  123. package/views/3d/state/ViewStateManager.js +1 -1
  124. package/views/3d/state/controllers/FovController.js +1 -1
  125. package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
  126. package/views/3d/state/controllers/momentum/ZoomPlanarMomentumController.js +1 -1
  127. package/views/3d/support/FrustumExtentIntersection.js +1 -1
  128. package/views/3d/support/cameraUtils.js +1 -1
  129. package/views/3d/support/intersectionUtils.js +1 -1
  130. package/views/3d/support/pointsOfInterest/CameraOnSurface.js +1 -1
  131. package/views/3d/support/pointsOfInterest/CenterOnSurface.js +1 -1
  132. package/views/3d/support/pointsOfInterest/Focus.js +1 -1
  133. package/views/3d/support/viewpointUtils.js +1 -1
  134. package/views/3d/terrain/OverlayManager.js +1 -1
  135. package/views/3d/terrain/OverlayRenderer.js +1 -1
  136. package/views/3d/terrain/PatchRenderData.js +1 -1
  137. package/views/3d/terrain/SphericalPatch.js +1 -1
  138. package/views/3d/terrain/TerrainRenderer.js +1 -1
  139. package/views/3d/terrain/Tile.js +1 -1
  140. package/views/3d/terrain/TileCompositor.js +1 -1
  141. package/views/3d/webgl/RenderCamera.js +1 -1
  142. package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
  143. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechnique.js +1 -1
  144. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  145. package/views/3d/webgl-engine/core/renderPasses/RenderPassManager.js +1 -1
  146. package/views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js +4 -7
  147. package/views/3d/webgl-engine/core/shaderLibrary/hud/HUD.glsl.js +6 -6
  148. package/views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateAmbientLighting.glsl.js +4 -4
  149. package/views/3d/webgl-engine/core/shaderLibrary/shading/EvaluateSceneLighting.glsl.js +19 -15
  150. package/views/3d/webgl-engine/core/shaderLibrary/shading/MainLighting.glsl.js +2 -2
  151. package/views/3d/webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js +1 -1
  152. package/views/3d/webgl-engine/core/shaderLibrary/terrain/TerrainTexture.glsl.js +5 -5
  153. package/views/3d/webgl-engine/core/shaderLibrary/terrain/TileBackground.glsl.js +14 -14
  154. package/views/3d/webgl-engine/core/shaderLibrary/util/BlendModes.glsl.js +16 -37
  155. package/views/3d/webgl-engine/effects/RenderPluginManager.js +1 -1
  156. package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
  157. package/views/3d/webgl-engine/effects/geometry/RenderOccludedRenderNode.js +1 -1
  158. package/views/3d/webgl-engine/effects/haze/Haze.js +1 -1
  159. package/views/3d/webgl-engine/effects/transparency/OITBlend.js +1 -1
  160. package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
  161. package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
  162. package/views/3d/webgl-engine/lib/Normals.js +1 -1
  163. package/views/3d/webgl-engine/lib/Object3D.js +1 -1
  164. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  165. package/views/3d/webgl-engine/lib/RenderingContext.js +1 -1
  166. package/views/3d/webgl-engine/lib/ShadowAccumulator.js +1 -1
  167. package/views/3d/webgl-engine/lib/SortedRenderGeometryRenderer.js +1 -1
  168. package/views/3d/webgl-engine/lib/Viewshed.js +1 -1
  169. package/views/3d/webgl-engine/lib/edgeRendering/edgePreprocessing.js +1 -1
  170. package/views/3d/webgl-engine/lib/geometryDataUtils.js +1 -1
  171. package/views/3d/webgl-engine/lib/triangleIntersectionUtils.js +1 -1
  172. package/views/3d/webgl-engine/materials/CheckerBoardMaterial.js +1 -1
  173. package/views/3d/webgl-engine/materials/ColorMaterial.js +1 -1
  174. package/views/3d/webgl-engine/materials/DefaultMaterial.js +1 -1
  175. package/views/3d/webgl-engine/materials/DefaultTechniqueConfiguration.js +1 -1
  176. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  177. package/views/3d/webgl-engine/materials/HeatmapDensityMaterial.js +1 -1
  178. package/views/3d/webgl-engine/materials/ImageMaterial.js +1 -1
  179. package/views/3d/webgl-engine/materials/LineCalloutMaterial.js +1 -1
  180. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  181. package/views/3d/webgl-engine/materials/MeasurementArrowMaterial.js +1 -1
  182. package/views/3d/webgl-engine/materials/NativeLineMaterial.js +1 -1
  183. package/views/3d/webgl-engine/materials/PatternMaterial.js +1 -1
  184. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  185. package/views/3d/webgl-engine/materials/ShadedColorMaterial.js +1 -1
  186. package/views/3d/webgl-engine/materials/SlicePlaneMaterial.js +1 -1
  187. package/views/3d/webgl-engine/materials/WaterMaterial.js +1 -1
  188. package/views/3d/webgl-engine/materials/renderers/VaoRenderer.js +1 -1
  189. package/views/3d/webgl-engine/materials/renderers/VaoWriter.js +1 -1
  190. package/views/3d/webgl-engine/shaders/ColorMaterialTechnique.js +1 -1
  191. package/views/3d/webgl-engine/shaders/DefaultMaterialTechnique.js +1 -1
  192. package/views/3d/webgl-engine/shaders/GaussianSplat.glsl.js +1 -1
  193. package/views/3d/webgl-engine/shaders/GaussianSplatTechniqueConfiguration.js +1 -1
  194. package/views/3d/webgl-engine/shaders/ImageMaterialTechnique.js +1 -1
  195. package/views/3d/webgl-engine/shaders/LineMarkerTechnique.js +1 -1
  196. package/views/3d/webgl-engine/shaders/NativeLineTechnique.js +1 -1
  197. package/views/3d/webgl-engine/shaders/OutputColorHighlightOLID.glsl.js +9 -10
  198. package/views/3d/webgl-engine/shaders/PatternTechnique.js +1 -1
  199. package/views/3d/webgl-engine/shaders/RibbonLineTechnique.js +1 -1
  200. package/views/3d/webgl-engine/shaders/SphereDepthInterpolate.glsl.js +1 -1
  201. package/views/3d/webgl-engine/shaders/Terrain.glsl.js +1 -1
  202. package/views/3d/webgl-engine/shaders/TerrainTechnique.js +1 -1
  203. package/views/3d/webgl-engine/shaders/TerrainTechniqueConfiguration.js +1 -1
  204. package/views/GroundView.js +1 -1
  205. package/views/SceneView.js +1 -1
  206. package/views/analysis/ElevationProfile/elevationProfileVisualizationUtils.js +1 -1
  207. package/views/interactive/GraphicManipulator.js +1 -1
  208. package/views/interactive/coordinateHelper.js +1 -1
  209. package/views/interactive/editGeometry/operations/OffsetEdgeVertex.js +1 -1
  210. package/views/interactive/sketch/constraints.js +1 -1
  211. package/views/interactive/snapping/featureSources/sceneLayerSource/SceneLayerSnappingSourceWorker.js +1 -1
  212. package/views/interactive/snapping/featureSources/sceneLayerSource/sceneLayerSnappingUtils.js +1 -1
  213. package/views/interactive/snapping/hints/LineSnappingHint.js +1 -1
  214. package/views/interactive/tooltip/tooltipCommonUtils.js +1 -1
  215. package/views/layers/LayerView.js +1 -1
  216. package/views/navigation/PanSphericalMomentumEstimator.js +1 -1
  217. package/views/support/LayerViewManager.js +1 -1
  218. package/views/support/euclideanAreaMeasurementUtils.js +1 -1
  219. package/views/support/euclideanLengthMeasurementUtils.js +1 -1
  220. package/views/support/geodesicLengthMeasurementUtils.js +1 -1
  221. package/views/support/geometry3dUtils.js +1 -1
  222. package/webmap/utils.js +1 -1
  223. package/widgets/Sketch/SketchViewModel.js +1 -1
  224. package/assets/esri/core/workers/chunks/11687718c8635eb7bf37.js +0 -1
  225. package/assets/esri/core/workers/chunks/15c1a48e8cd2a8882d85.js +0 -1
  226. package/assets/esri/core/workers/chunks/1b9e7d416c9f00e020bb.js +0 -1
  227. package/assets/esri/core/workers/chunks/5000a37fba27464d10ca.js +0 -1
  228. package/assets/esri/core/workers/chunks/b075d3714fab0591d67c.js +0 -1
  229. package/assets/esri/core/workers/chunks/d8975dd7b85b5d065ee4.js +0 -1
  230. package/assets/esri/core/workers/chunks/f43e1e1a1b2eb737e00c.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{neverReached as t}from"../../../core/compilerUtils.js";import{lerp as e}from"../../../core/mathUtils.js";import{invert as i}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as r}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as n,j as o,E as s,p as a,h as c,g as l}from"../../../chunks/vec32.js";import{create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as h}from"../../../geometry/ellipsoidUtils.js";import{computeTranslationToOriginAndRotation as d}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectBoundingRect as _}from"../../../geometry/projection/projectBoundingRect.js";import{projectVectorToVector as m}from"../../../geometry/projection/projectVectorToVector.js";import{empty as g,create as x,expandWithVec3 as f}from"../../../geometry/support/aaBoundingBox.js";import{center as u,create as y}from"../../../geometry/support/aaBoundingRect.js";import{fromPoints as j,create as R}from"../../../geometry/support/lineSegment.js";import{create as b,fromVectorsAndPoint as S,copy as B,negate as C,signedDistance as H}from"../../../geometry/support/plane.js";import{wrap as w}from"../../../geometry/support/ray.js";import{frustumLineSegment as M}from"./intersectionUtils.js";const A=.5*Math.PI,E=A/Math.PI*180;class G{constructor(t){this._extent=new Array(4),this._planes=new Array(6),this._maxSpan=0,this._center={origin:p(),direction:p()},this._renderCoordsHelper=t.renderCoordsHelper;for(let e=0;e<4;e++)this._extent[e]={origin:p(),direction:p(),cap:{next:null,direction:p()}},this._planes[e]=b();this._planes[4]=b(),this._planes[5]=b(),this._planesWithoutFar=this._planes.slice(0,5)}update(t,e,i,r=!0){const a=this._extent;this._toRenderBoundingExtent(t,e,i),n(this._center.origin,a[0].origin,a[2].origin),o(this._center.origin,this._center.origin,.5),this._renderCoordsHelper.worldUpAtPosition(this._center.origin,this._center.direction),r||o(this._center.direction,this._center.direction,-1);for(let n=0;n<4;n++){const t=a[n];this._renderCoordsHelper.worldUpAtPosition(t.origin,t.direction);const e=a[3===n?0:n+1];t.cap.next=e.origin,s(t.cap.direction,t.origin,e.origin),S(t.direction,t.cap.direction,t.origin,this._planes[n]),r||o(t.direction,t.direction,-1)}S(a[0].cap.direction,a[1].cap.direction,a[0].origin,this._planes[4]),r?C(this._planes[4],this._planes[5]):(B(this._planes[5],this._planes[4]),C(this._planes[4],this._planes[4])),this._maxSpan=Math.max(Math.abs(t[0]-t[2]),Math.abs(t[1]-t[3])),this._maxSpanSpatialReference=e,this._minGlobalAltitude=.9*h(this._maxSpanSpatialReference).radius}isVisibleInFrustum(t,e,i=!1){if(null==t)return!1;if(1===this._renderCoordsHelper.viewingMode){const i=this._maxSpanSpatialReference.isGeographic?E:A*e;if(this._maxSpan>i)return!0;if(null!=t.altitude&&t.altitude>=this._minGlobalAltitude)return this._isVisibleInFrustumGlobal(t)}if(0===this._maxSpan){const e=this._extent[0];return!(i||!t.intersectsRay(w(e.origin,e.direction)))}for(let n=0;n<this._extent.length;n++){const e=this._extent[n];if(!i&&t.intersectsRay(w(e.origin,e.direction)))return!0;if(t.intersectsLineSegment(j(e.origin,e.cap.next,k),e.cap.direction))return!0}const r=i?this._planes:this._planesWithoutFar;for(let n=0;n<t.lines.length;n++){const e=t.lines[n];if(M(r,e.origin,e.endpoint,e.direction))return!0}return!1}_toRenderBoundingExtentGlobal(t,r,n){const o=5;u(t,v),v[2]=n,d(r,v,F,this._renderCoordsHelper.spatialReference),i(I,F),g(V);for(const{x0:i,x1:s,y0:c,y1:l}of U)for(let p=0;p<o;p++){const h=p/(o-1);v[0]=e(t[i],t[s],h),v[1]=e(t[c],t[l],h),v[2]=n,m(v,r,v,this._renderCoordsHelper.spatialReference),a(v,v,I),f(V,v)}c(this._extent[0].origin,V[0],V[1],V[2]),c(this._extent[1].origin,V[3],V[1],V[2]),c(this._extent[2].origin,V[3],V[4],V[2]),c(this._extent[3].origin,V[0],V[4],V[2]);for(let e=0;e<4;++e)a(this._extent[e].origin,this._extent[e].origin,F)}_toRenderBoundingExtentLocal(t,e,i){_(t,e,P,this._renderCoordsHelper.spatialReference),c(this._extent[0].origin,P[0],P[1],i),c(this._extent[1].origin,P[2],P[1],i),c(this._extent[2].origin,P[2],P[3],i),c(this._extent[3].origin,P[0],P[3],i)}_toRenderBoundingExtent(e,i,r){switch(this._renderCoordsHelper.viewingMode){case 1:this._toRenderBoundingExtentGlobal(e,i,r);break;case 2:this._toRenderBoundingExtentLocal(e,i,r);break;default:t(this._renderCoordsHelper.viewingMode)}}_isVisibleInFrustumGlobal(t){if(H(t.planes[4],this._center.origin)<0&&l(this._center.direction,t.direction)<0)return!0;for(let e=0;e<4;e++){const i=this._extent[e];if(H(t.planes[4],i.origin)<0&&l(i.direction,t.direction)<0)return!0}return!1}}const U=[{x0:0,y0:1,x1:2,y1:1},{x0:0,y0:3,x1:2,y1:3},{x0:0,y0:1,x1:0,y1:3},{x0:2,y0:1,x1:2,y1:3}],v=p(),F=r(),I=r(),V=x(),P=y(),k=R();export{G as FrustumExtentIntersection};
5
+ import{neverReached as t}from"../../../core/compilerUtils.js";import{lerp as e}from"../../../core/mathUtils.js";import{invert as i}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as r}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as n,j as o,D as s,p as a,h as c,g as l}from"../../../chunks/vec32.js";import{create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as h}from"../../../geometry/ellipsoidUtils.js";import{computeTranslationToOriginAndRotation as d}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectBoundingRect as _}from"../../../geometry/projection/projectBoundingRect.js";import{projectVectorToVector as m}from"../../../geometry/projection/projectVectorToVector.js";import{empty as g,create as x,expandWithVec3 as f}from"../../../geometry/support/aaBoundingBox.js";import{center as u,create as y}from"../../../geometry/support/aaBoundingRect.js";import{fromPoints as j,create as R}from"../../../geometry/support/lineSegment.js";import{create as b,fromVectorsAndPoint as S,copy as B,negate as C,signedDistance as H}from"../../../geometry/support/plane.js";import{wrap as w}from"../../../geometry/support/ray.js";import{frustumLineSegment as M}from"./intersectionUtils.js";const A=.5*Math.PI,G=A/Math.PI*180;class E{constructor(t){this._extent=new Array(4),this._planes=new Array(6),this._maxSpan=0,this._center={origin:p(),direction:p()},this._renderCoordsHelper=t.renderCoordsHelper;for(let e=0;e<4;e++)this._extent[e]={origin:p(),direction:p(),cap:{next:null,direction:p()}},this._planes[e]=b();this._planes[4]=b(),this._planes[5]=b(),this._planesWithoutFar=this._planes.slice(0,5)}update(t,e,i,r=!0){const a=this._extent;this._toRenderBoundingExtent(t,e,i),n(this._center.origin,a[0].origin,a[2].origin),o(this._center.origin,this._center.origin,.5),this._renderCoordsHelper.worldUpAtPosition(this._center.origin,this._center.direction),r||o(this._center.direction,this._center.direction,-1);for(let n=0;n<4;n++){const t=a[n];this._renderCoordsHelper.worldUpAtPosition(t.origin,t.direction);const e=a[3===n?0:n+1];t.cap.next=e.origin,s(t.cap.direction,t.origin,e.origin),S(t.direction,t.cap.direction,t.origin,this._planes[n]),r||o(t.direction,t.direction,-1)}S(a[0].cap.direction,a[1].cap.direction,a[0].origin,this._planes[4]),r?C(this._planes[4],this._planes[5]):(B(this._planes[5],this._planes[4]),C(this._planes[4],this._planes[4])),this._maxSpan=Math.max(Math.abs(t[0]-t[2]),Math.abs(t[1]-t[3])),this._maxSpanSpatialReference=e,this._minGlobalAltitude=.9*h(this._maxSpanSpatialReference).radius}isVisibleInFrustum(t,e,i=!1){if(null==t)return!1;if(1===this._renderCoordsHelper.viewingMode){const i=this._maxSpanSpatialReference.isGeographic?G:A*e;if(this._maxSpan>i)return!0;if(null!=t.altitude&&t.altitude>=this._minGlobalAltitude)return this._isVisibleInFrustumGlobal(t)}if(0===this._maxSpan){const e=this._extent[0];return!(i||!t.intersectsRay(w(e.origin,e.direction)))}for(let n=0;n<this._extent.length;n++){const e=this._extent[n];if(!i&&t.intersectsRay(w(e.origin,e.direction)))return!0;if(t.intersectsLineSegment(j(e.origin,e.cap.next,k),e.cap.direction))return!0}const r=i?this._planes:this._planesWithoutFar;for(let n=0;n<t.lines.length;n++){const e=t.lines[n];if(M(r,e.origin,e.endpoint,e.direction))return!0}return!1}_toRenderBoundingExtentGlobal(t,r,n){const o=5;u(t,v),v[2]=n,d(r,v,F,this._renderCoordsHelper.spatialReference),i(I,F),g(V);for(const{x0:i,x1:s,y0:c,y1:l}of U)for(let p=0;p<o;p++){const h=p/(o-1);v[0]=e(t[i],t[s],h),v[1]=e(t[c],t[l],h),v[2]=n,m(v,r,v,this._renderCoordsHelper.spatialReference),a(v,v,I),f(V,v)}c(this._extent[0].origin,V[0],V[1],V[2]),c(this._extent[1].origin,V[3],V[1],V[2]),c(this._extent[2].origin,V[3],V[4],V[2]),c(this._extent[3].origin,V[0],V[4],V[2]);for(let e=0;e<4;++e)a(this._extent[e].origin,this._extent[e].origin,F)}_toRenderBoundingExtentLocal(t,e,i){_(t,e,P,this._renderCoordsHelper.spatialReference),c(this._extent[0].origin,P[0],P[1],i),c(this._extent[1].origin,P[2],P[1],i),c(this._extent[2].origin,P[2],P[3],i),c(this._extent[3].origin,P[0],P[3],i)}_toRenderBoundingExtent(e,i,r){switch(this._renderCoordsHelper.viewingMode){case 1:this._toRenderBoundingExtentGlobal(e,i,r);break;case 2:this._toRenderBoundingExtentLocal(e,i,r);break;default:t(this._renderCoordsHelper.viewingMode)}}_isVisibleInFrustumGlobal(t){if(H(t.planes[4],this._center.origin)<0&&l(this._center.direction,t.direction)<0)return!0;for(let e=0;e<4;e++){const i=this._extent[e];if(H(t.planes[4],i.origin)<0&&l(i.direction,t.direction)<0)return!0}return!1}}const U=[{x0:0,y0:1,x1:2,y1:1},{x0:0,y0:3,x1:2,y1:3},{x0:0,y0:1,x1:0,y1:3},{x0:2,y0:1,x1:2,y1:3}],v=p(),F=r(),I=r(),V=x(),P=y(),k=R();export{E as FrustumExtentIntersection};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Camera.js";import t from"../../../core/Logger.js";import{deg2rad as n,rad2deg as r,asinClamped as i}from"../../../core/mathUtils.js";import{throwIfAborted as a}from"../../../core/promiseUtils.js";import{d as o,D as c,H as s,b as l}from"../../../chunks/vec32.js";import{create as u,clone as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as m}from"../../../geometry/ellipsoidUtils.js";import p from"../../../geometry/Point.js";import{projectWithZConversion as d,project as h}from"../../../geometry/projectionUtils.js";import g from"../../../geometry/SpatialReference.js";import{projectPointToVectorAsync as y,projectPointToVector as v}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToPointAsync as R,projectVectorToPoint as w}from"../../../geometry/projection/projectVectorToPoint.js";import{gcsCyclical as x,webMercatorCyclical as M}from"../../../geometry/support/normalizeUtils.js";import{toRenderCamera as j}from"../webgl.js";import{getGreatCircleSpanAt as T}from"./earthUtils.js";import{getElevationAtPoint as z}from"./ElevationProvider.js";import{viewModeDependentUtil as S,directionToHeadingTilt as C}from"./viewingModeUtils.js";import{isSpatialReferenceSupported as b}from"../../support/spatialReferenceSupport.js";const P=()=>t.getLogger("esri.views.3d.support.cameraUtils"),A=96*39.37,L=1,U=8,H=5,q=1,I=u();function E(e){return e.spatialReference??g.WGS84}function F(e,t,n,r,i){return S(e).headingTiltToDirectionUp(t,n,r,i)}function G(e,t){const{camera:n}=e.state,{unitInMeters:r}=e.renderCoordsHelper;t/=r;return n.width/2/n.pixelRatio/(A/t)/Math.tan(n.fovX/2)}function D(e,t){const{camera:n}=e.state,{unitInMeters:r}=e.renderCoordsHelper,i=t*Math.tan(n.fovX/2),a=n.width/2/n.pixelRatio;return A/(a/i)*r}function O(e,t,n,r){const i=r.levelAtScale(t),a=k(C(e,n.eye,n.viewForward,n.up).tilt),o=Math.max(i-a,0);return r.scaleAtLevel(o)}function X(e,t,n){const r=n.levelAtScale(e),i=k(t);return n.scaleAtLevel(r+i)}function k(e){return 2*((e>90?180-e:e)/90)**2}function V(e,t,n=0){const r=e.basemapTerrain?.tilingScheme;if(!r)return 0;const i=m(e.spatialReference).radius,a=2===e.state.viewingMode?t.eye[2]:l(t.eye)-i;return O(e,D(e,Math.abs(a-n)),t,r)}function W(e,t,n=0){const r=j(e,t);return r?V(e,r,n):0}const Y=1,N=100;function Z(e,t,a,o){if(0===t)return 0;const s=e.state.contentCamera,u=c(s.eye,a),f=e.basemapTerrain?.tilingScheme;if(!f)return P().error("#scaleToTargetDistance()","Cannot compute distance from scale without a tiling scheme"),u;let p=u;const d=C(e,s.eye,s.viewForward,s.up),h=d.tilt>90;if(e.state.isLocal){const r=(G(e,X(t,d.tilt,f))-Math.abs(s.eye[2]-o[2]))/Math.cos(n(d.tilt));return p=h?p-r:p+r,p}let g=1/0,y=0,v=te(e,d.heading,d.tilt,a,u,1);if(!v)return p;const R=l(o);for(;g>Y&&y<N;){const o=l(v.eye),u=h?180-v.tilt:v.tilt,w=n(u),x=Math.sin(w)*o,M=Math.cos(w)*o,j=G(e,X(t,v.tilt,f)),T=h?R-j:R+j,z=i(x/T),S=Math.cos(z)*T-M,C=c(v.eye,a);p=h?C-S:C+S,v=te(e,d.heading,d.tilt,a,p,1);const b=Me(e,v,r(s.fov));if(!v||!b)return p;const P=W(e,b,R-m(e.spatialReference).radius);g=Math.abs(t-P),++y}return p}async function B(e,t,n,r,i,a){return K(e,t,G(e,n),r,i,a)}function J(e,t,n,r,i,a){return Me(e,te(e,r.heading,r.tilt,t,n,i),r.fov,a)}async function K(e,t,n,r,i,o){const c=await ne(e,r.heading,r.tilt,t,n,i,o);return a(o),je(e,c,r.fov,o)}function Q(e,t){return!!(e.basemapTerrain&&e.renderCoordsHelper.fromRenderCoords(t,I,e.spatialReference)&&e.elevationProvider&&(z(e.elevationProvider,I)??0)>I[2]-q)}async function $(e,t,n){if(Q(e,t))return!0;const{elevationProvider:r,spatialReference:i,renderCoordsHelper:o}=e;if(null==r||!o.fromRenderCoords(t,I,i))return!1;const[c,s,l]=I,u=await r.queryElevation(c,s,l,i,"ground",n)??0;return a(n),u>l-q}async function _(e,t,n){const r=u();if(null==t)return o(r,e.state.camera.center);if(t instanceof p){const{renderSpatialReference:i,basemapTerrain:o,elevationProvider:c}=e,s=t.spatialReference;if(await y(t,r,i,{signal:n}),a(n),null==t.z&&null!=o&&null!=c){const i=await c.queryElevation(t.x,t.y,t.z??0,s,"ground",n);a(n),null!=i&&e.renderCoordsHelper.setAltitude(r,i)}return r}return o(r,t)}function ee(e,t){const n=u();if(null==t)return o(n,e.state.camera.center);if(t instanceof p){if(!v(t,n,e.renderSpatialReference))return null;const{basemapTerrain:r,elevationProvider:i}=e;if(null==t.z&&null!=r&&null!=i){const r=z(i,t);null!=r&&e.renderCoordsHelper.setAltitude(n,r)}return n}return o(n,t)}function te(e,t,n,r,i,a){return re(e,t,n,r instanceof p?r:null,ee(e,r),i,a)}async function ne(e,t,n,r,i,o,c){const s=r instanceof p?r:null,l=await _(e,r,c);return a(c),ie(e,t,n,s,l,i,o,c)}function re(e,t,n,r,i,a,o){if(null==i)return null;if(!r&&(r=new p({spatialReference:E(e)}),!w(i,e.renderSpatialReference,r)))return null;const c=ae(e,t,n,i,a,o);if(oe(e,n,o)&&Q(e,c.eye)){const{tilt:o,mode:c}=ce(e,n,i,a);return re(e,t,o,r,i,a,c)}return se(c,i)}async function ie(e,t,n,r,i,o,c,s){r||(r=new p({spatialReference:E(e)}),await R(i,e.renderSpatialReference,r,{signal:s})||(r=null)),a(s);const l=ae(e,t,n,i,o,c);if(oe(e,n,c)&&await $(e,l.eye,s)){a(s);const{tilt:c,mode:l}=ce(e,n,i,o);return ie(e,t,c,r,i,o,l,s)}return se(l,i)}function ae(e,t,n,r,i,a){const o=ge(e,t,n,r,i=Math.max(i,e.state.constraints.minimumPoiDistance),a);return(0,S(e).eyeForCenterWithHeadingTilt)(r,i,o.heading,o.tilt)}function oe(e,t,n){const r=e.map.ground.navigationConstraint;return 1===n&&e.state.isGlobal&&t>0&&(null==r||"stay-above"===r.type)}function ce(e,t,n,r){const i=we(e,n,r,Re(e,r,t,n));return{tilt:i,mode:t-i<1?0:1}}function se(e,t){return{...e,center:f(t)}}function le(e,t){const{state:n,spatialReference:r}=e,i=t.spatialReference;return n.isGlobal&&b(i,1)||n.isLocal&&r.equals(i)}function ue(e,t){let n,r,i;if(e.state.isGlobal){const e=new p(t.xmin,t.ymin,t.spatialReference),a=new p(t.xmax,t.ymax,t.spatialReference),o=t.spatialReference.isGeographic?x:M;n=new p({x:o.center(e.x,a.x),y:(a.y+e.y)/2,z:null!=t.zmax&&null!=t.zmin?(t.zmax+t.zmin)/2:void 0,spatialReference:t.spatialReference});const c=m(t.spatialReference),s=T(n,e,a);r=s.lon,i=s.lat,o.diff(e.x,a.x)>o.range/2&&(r+=c.halfCircumference),r=Math.min(r,c.halfCircumference),i=Math.min(i,c.halfCircumference)}else{const a=e.renderSpatialReference??t.spatialReference;a.equals(t.spatialReference)||(t=h(t,a)),r=t.xmax-t.xmin,i=t.ymax-t.ymin;const o=null!=t.zmax&&null!=t.zmin?(t.zmax+t.zmin)/2:void 0;n=new p({x:t.xmin+.5*r,y:t.ymin+.5*i,z:o,spatialReference:a})}const a=null!=t.zmax&&null!=t.zmin?t.zmax-t.zmin:0,o=e.state.camera,c=1/Math.tan(o.fovX/2),s=1/Math.tan(o.fovY/2),l=1/Math.tan(o.fov/2);return{center:n,distance:Math.max(.5*r*c,.5*i*s,.5*a*l)/L}}async function fe(e,t,n,r,i,o){const c=le(e,t)?t:await d(t,e.spatialReference,{signal:o});a(o);const{center:s,distance:l}=ue(e,c),u=await ne(e,n,r,s,l,i,o);return a(o),je(e,u,e.camera.fov,o)}function me(e,t,n,r,i,a){let o;try{o=le(e,t)?t:h(t,e.spatialReference)}catch(u){return null}const{center:c,distance:s}=ue(e,o),l=te(e,n,r,c,s,i);return null==l?null:Me(e,l,e.camera.fov,a)}function pe(e,t,n){const r=e.renderSpatialReference,i=new p({spatialReference:E(e)});if(!w(n,r,i))return null;const a=Math.tan(t.fovX/2),o=Math.tan(t.fovY/2),c=s(t.eye,n),l=2*c*a*L,u=2*c*o*L;return S(e).toExtent(e,i,l,u)}function de(e,t){return S(e).toArea(e,t)}function he(e,t,n){const r=e.pointsOfInterest.centerOnSurfaceFrequent.distance;if(Math.log(n/r)/Math.LN2>U)return!0;const i=t,a=e.pointsOfInterest.centerOnSurfaceFrequent.renderLocation;return c(i,a)/(Math.tan(.5*e.state.camera.fov)*r)>H}function ge(e,t,n,r,i,a){let o=0;return 1===a&&he(e,r,i)?(t=0,o=ve(e,i,n,r)):o=xe(e,r,i,n),o=e.state.constraints.clampTilt(i,o),{heading:t,tilt:n=we(e,r,i,o)}}const ye=.7;function ve(e,t,n,r){const i=xe(e,r,t,n);if(!e.state.constraints.tilt)return i;const a=e.state.constraints.tilt(t);a.max=Math.min(a.max,.5*Math.PI);const o=a.min*(1-ye)+a.max*ye;return Math.min(i,o)}function Re(e,t,n,r){let i=xe(e,r,t,n);if(!e.state.constraints.tilt)return i;const a=e.state.constraints.tilt(t);return i=Math.min(i,.5*Math.PI),a.min*(1-ye)+i*ye}function we(e,t,n,r){return S(e).lookAtTiltToEyeTilt(r,t,n)}function xe(e,t,n,r){return S(e).eyeTiltToLookAtTilt(r,t,n)}function Me(t,n,r,i){if(null==n)return null;const a=t.renderSpatialReference,o=new p({spatialReference:E(t)});return w(n.eye,a,o)?(i??=new e,i.position=o,i.heading=n.heading,i.tilt=n.tilt,i.fov=r,i):null}async function je(t,n,r,i){const o=t.renderSpatialReference,c=new p({spatialReference:E(t)});return await R(n.eye,o,c,{signal:i}),a(i),new e(c,n.heading,n.tilt,r)}function Te(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.levelAtScale(t);P().error("#scaleToZoom()","Cannot compute zoom from scale without a tiling scheme")}function ze(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.scaleAtLevel(t);P().error("#zoomToScale()","Cannot compute scale from zoom without a tiling scheme")}export{O as applyTiltAdjustToScale,D as distanceToScale,K as fromCenterDistanceAsync,J as fromCenterDistanceSync,B as fromCenterScale,fe as fromExtentAsync,me as fromExtentSync,ne as getObserverForPointAtDistanceAsync,te as getObserverForPointAtDistanceSync,E as getViewSR,F as headingTiltToDirectionUp,X as removeTiltAdjustFromScale,Y as scaleErrorThreshold,G as scaleToDistance,Te as scaleToZoom,de as toArea,pe as toExtent,Z as viewScaleToCameraDistance,ze as zoomToScale};
5
+ import e from"../../../Camera.js";import t from"../../../core/Logger.js";import{deg2rad as n,rad2deg as r,asinClamped as i}from"../../../core/mathUtils.js";import{throwIfAborted as a}from"../../../core/promiseUtils.js";import{d as o,C as c,G as s,b as l}from"../../../chunks/vec32.js";import{create as u,clone as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as m}from"../../../geometry/ellipsoidUtils.js";import p from"../../../geometry/Point.js";import{projectWithZConversion as d,project as h}from"../../../geometry/projectionUtils.js";import g from"../../../geometry/SpatialReference.js";import{projectPointToVectorAsync as y,projectPointToVector as v}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToPointAsync as R,projectVectorToPoint as w}from"../../../geometry/projection/projectVectorToPoint.js";import{gcsCyclical as x,webMercatorCyclical as M}from"../../../geometry/support/normalizeUtils.js";import{toRenderCamera as j}from"../webgl.js";import{getGreatCircleSpanAt as T}from"./earthUtils.js";import{getElevationAtPoint as z}from"./ElevationProvider.js";import{viewModeDependentUtil as S,directionToHeadingTilt as C}from"./viewingModeUtils.js";import{isSpatialReferenceSupported as b}from"../../support/spatialReferenceSupport.js";const P=()=>t.getLogger("esri.views.3d.support.cameraUtils"),A=96*39.37,L=1,U=8,H=5,q=1,G=u();function I(e){return e.spatialReference??g.WGS84}function E(e,t,n,r,i){return S(e).headingTiltToDirectionUp(t,n,r,i)}function F(e,t){const{camera:n}=e.state,{unitInMeters:r}=e.renderCoordsHelper;t/=r;return n.width/2/n.pixelRatio/(A/t)/Math.tan(n.fovX/2)}function O(e,t){const{camera:n}=e.state,{unitInMeters:r}=e.renderCoordsHelper,i=t*Math.tan(n.fovX/2),a=n.width/2/n.pixelRatio;return A/(a/i)*r}function X(e,t,n,r){const i=r.levelAtScale(t),a=D(C(e,n.eye,n.viewForward,n.up).tilt),o=Math.max(i-a,0);return r.scaleAtLevel(o)}function k(e,t,n){const r=n.levelAtScale(e),i=D(t);return n.scaleAtLevel(r+i)}function D(e){return 2*((e>90?180-e:e)/90)**2}function V(e,t,n=0){const r=e.basemapTerrain?.tilingScheme;if(!r)return 0;const i=m(e.spatialReference).radius,a=2===e.state.viewingMode?t.eye[2]:l(t.eye)-i;return X(e,O(e,Math.abs(a-n)),t,r)}function W(e,t,n=0){const r=j(e,t);return r?V(e,r,n):0}const Y=1,N=100;function Z(e,t,a,o){if(0===t)return 0;const s=e.state.contentCamera,u=c(s.eye,a),f=e.basemapTerrain?.tilingScheme;if(!f)return P().error("#scaleToTargetDistance()","Cannot compute distance from scale without a tiling scheme"),u;let p=u;const d=C(e,s.eye,s.viewForward,s.up),h=d.tilt>90;if(e.state.isLocal){const r=(F(e,k(t,d.tilt,f))-Math.abs(s.eye[2]-o[2]))/Math.cos(n(d.tilt));return p=h?p-r:p+r,p}let g=1/0,y=0,v=te(e,d.heading,d.tilt,a,u,1);if(!v)return p;const R=l(o);for(;g>Y&&y<N;){const o=l(v.eye),u=h?180-v.tilt:v.tilt,w=n(u),x=Math.sin(w)*o,M=Math.cos(w)*o,j=F(e,k(t,v.tilt,f)),T=h?R-j:R+j,z=i(x/T),S=Math.cos(z)*T-M,C=c(v.eye,a);p=h?C-S:C+S,v=te(e,d.heading,d.tilt,a,p,1);const b=Me(e,v,r(s.fov));if(!v||!b)return p;const P=W(e,b,R-m(e.spatialReference).radius);g=Math.abs(t-P),++y}return p}async function B(e,t,n,r,i,a){return K(e,t,F(e,n),r,i,a)}function J(e,t,n,r,i,a){return Me(e,te(e,r.heading,r.tilt,t,n,i),r.fov,a)}async function K(e,t,n,r,i,o){const c=await ne(e,r.heading,r.tilt,t,n,i,o);return a(o),je(e,c,r.fov,o)}function Q(e,t){return!!(e.basemapTerrain&&e.renderCoordsHelper.fromRenderCoords(t,G,e.spatialReference)&&e.elevationProvider&&(z(e.elevationProvider,G)??0)>G[2]-q)}async function $(e,t,n){if(Q(e,t))return!0;const{elevationProvider:r,spatialReference:i,renderCoordsHelper:o}=e;if(null==r||!o.fromRenderCoords(t,G,i))return!1;const[c,s,l]=G,u=await r.queryElevation(c,s,l,i,"ground",n)??0;return a(n),u>l-q}async function _(e,t,n){const r=u();if(null==t)return o(r,e.state.camera.center);if(t instanceof p){const{renderSpatialReference:i,basemapTerrain:o,elevationProvider:c}=e,s=t.spatialReference;if(await y(t,r,i,{signal:n}),a(n),null==t.z&&null!=o&&null!=c){const i=await c.queryElevation(t.x,t.y,t.z??0,s,"ground",n);a(n),null!=i&&e.renderCoordsHelper.setAltitude(r,i)}return r}return o(r,t)}function ee(e,t){const n=u();if(null==t)return o(n,e.state.camera.center);if(t instanceof p){if(!v(t,n,e.renderSpatialReference))return null;const{basemapTerrain:r,elevationProvider:i}=e;if(null==t.z&&null!=r&&null!=i){const r=z(i,t);null!=r&&e.renderCoordsHelper.setAltitude(n,r)}return n}return o(n,t)}function te(e,t,n,r,i,a){return re(e,t,n,r instanceof p?r:null,ee(e,r),i,a)}async function ne(e,t,n,r,i,o,c){const s=r instanceof p?r:null,l=await _(e,r,c);return a(c),ie(e,t,n,s,l,i,o,c)}function re(e,t,n,r,i,a,o){if(null==i)return null;if(!r&&(r=new p({spatialReference:I(e)}),!w(i,e.renderSpatialReference,r)))return null;const c=ae(e,t,n,i,a,o);if(oe(e,n,o)&&Q(e,c.eye)){const{tilt:o,mode:c}=ce(e,n,i,a);return re(e,t,o,r,i,a,c)}return se(c,i)}async function ie(e,t,n,r,i,o,c,s){r||(r=new p({spatialReference:I(e)}),await R(i,e.renderSpatialReference,r,{signal:s})||(r=null)),a(s);const l=ae(e,t,n,i,o,c);if(oe(e,n,c)&&await $(e,l.eye,s)){a(s);const{tilt:c,mode:l}=ce(e,n,i,o);return ie(e,t,c,r,i,o,l,s)}return se(l,i)}function ae(e,t,n,r,i,a){const o=ge(e,t,n,r,i=Math.max(i,e.state.constraints.minimumPoiDistance),a);return(0,S(e).eyeForCenterWithHeadingTilt)(r,i,o.heading,o.tilt)}function oe(e,t,n){const r=e.map.ground.navigationConstraint;return 1===n&&e.state.isGlobal&&t>0&&(null==r||"stay-above"===r.type)}function ce(e,t,n,r){const i=we(e,n,r,Re(e,r,t,n));return{tilt:i,mode:t-i<1?0:1}}function se(e,t){return{...e,center:f(t)}}function le(e,t){const{state:n,spatialReference:r}=e,i=t.spatialReference;return n.isGlobal&&b(i,1)||n.isLocal&&r.equals(i)}function ue(e,t){let n,r,i;if(e.state.isGlobal){const e=new p(t.xmin,t.ymin,t.spatialReference),a=new p(t.xmax,t.ymax,t.spatialReference),o=t.spatialReference.isGeographic?x:M;n=new p({x:o.center(e.x,a.x),y:(a.y+e.y)/2,z:null!=t.zmax&&null!=t.zmin?(t.zmax+t.zmin)/2:void 0,spatialReference:t.spatialReference});const c=m(t.spatialReference),s=T(n,e,a);r=s.lon,i=s.lat,o.diff(e.x,a.x)>o.range/2&&(r+=c.halfCircumference),r=Math.min(r,c.halfCircumference),i=Math.min(i,c.halfCircumference)}else{const a=e.renderSpatialReference??t.spatialReference;a.equals(t.spatialReference)||(t=h(t,a)),r=t.xmax-t.xmin,i=t.ymax-t.ymin;const o=null!=t.zmax&&null!=t.zmin?(t.zmax+t.zmin)/2:void 0;n=new p({x:t.xmin+.5*r,y:t.ymin+.5*i,z:o,spatialReference:a})}const a=null!=t.zmax&&null!=t.zmin?t.zmax-t.zmin:0,o=e.state.camera,c=1/Math.tan(o.fovX/2),s=1/Math.tan(o.fovY/2),l=1/Math.tan(o.fov/2);return{center:n,distance:Math.max(.5*r*c,.5*i*s,.5*a*l)/L}}async function fe(e,t,n,r,i,o){const c=le(e,t)?t:await d(t,e.spatialReference,{signal:o});a(o);const{center:s,distance:l}=ue(e,c),u=await ne(e,n,r,s,l,i,o);return a(o),je(e,u,e.camera.fov,o)}function me(e,t,n,r,i,a){let o;try{o=le(e,t)?t:h(t,e.spatialReference)}catch(u){return null}const{center:c,distance:s}=ue(e,o),l=te(e,n,r,c,s,i);return null==l?null:Me(e,l,e.camera.fov,a)}function pe(e,t,n){const r=e.renderSpatialReference,i=new p({spatialReference:I(e)});if(!w(n,r,i))return null;const a=Math.tan(t.fovX/2),o=Math.tan(t.fovY/2),c=s(t.eye,n),l=2*c*a*L,u=2*c*o*L;return S(e).toExtent(e,i,l,u)}function de(e,t){return S(e).toArea(e,t)}function he(e,t,n){const r=e.pointsOfInterest.centerOnSurfaceFrequent.distance;if(Math.log(n/r)/Math.LN2>U)return!0;const i=t,a=e.pointsOfInterest.centerOnSurfaceFrequent.renderLocation;return c(i,a)/(Math.tan(.5*e.state.camera.fov)*r)>H}function ge(e,t,n,r,i,a){let o=0;return 1===a&&he(e,r,i)?(t=0,o=ve(e,i,n,r)):o=xe(e,r,i,n),o=e.state.constraints.clampTilt(i,o),{heading:t,tilt:n=we(e,r,i,o)}}const ye=.7;function ve(e,t,n,r){const i=xe(e,r,t,n);if(!e.state.constraints.tilt)return i;const a=e.state.constraints.tilt(t);a.max=Math.min(a.max,.5*Math.PI);const o=a.min*(1-ye)+a.max*ye;return Math.min(i,o)}function Re(e,t,n,r){let i=xe(e,r,t,n);if(!e.state.constraints.tilt)return i;const a=e.state.constraints.tilt(t);return i=Math.min(i,.5*Math.PI),a.min*(1-ye)+i*ye}function we(e,t,n,r){return S(e).lookAtTiltToEyeTilt(r,t,n)}function xe(e,t,n,r){return S(e).eyeTiltToLookAtTilt(r,t,n)}function Me(t,n,r,i){if(null==n)return null;const a=t.renderSpatialReference,o=new p({spatialReference:I(t)});return w(n.eye,a,o)?(i??=new e,i.position=o,i.heading=n.heading,i.tilt=n.tilt,i.fov=r,i):null}async function je(t,n,r,i){const o=t.renderSpatialReference,c=new p({spatialReference:I(t)});return await R(n.eye,o,c,{signal:i}),a(i),new e(c,n.heading,n.tilt,r)}function Te(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.levelAtScale(t);P().error("#scaleToZoom()","Cannot compute zoom from scale without a tiling scheme")}function ze(e,t){const n=e.basemapTerrain?.tilingScheme;if(n)return n.scaleAtLevel(t);P().error("#zoomToScale()","Cannot compute scale from zoom without a tiling scheme")}export{X as applyTiltAdjustToScale,O as distanceToScale,K as fromCenterDistanceAsync,J as fromCenterDistanceSync,B as fromCenterScale,fe as fromExtentAsync,me as fromExtentSync,ne as getObserverForPointAtDistanceAsync,te as getObserverForPointAtDistanceSync,I as getViewSR,E as headingTiltToDirectionUp,k as removeTiltAdjustFromScale,Y as scaleErrorThreshold,F as scaleToDistance,Te as scaleToZoom,de as toArea,pe as toExtent,Z as viewScaleToCameraDistance,ze as zoomToScale};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{create as r}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{D as n,d as t,e as i,j as e,g as c,i as o,n as u}from"../../../chunks/vec32.js";import{create as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getNormal as l,signedDistance as s}from"../../../geometry/support/plane.js";function p(r,n,t){return r[0]*n[0]+r[1]*n[1]+r[2]*n[2]+r[3]<t}function a(r,n,t){const i=n[0],e=n[1],c=n[2];return!(r[0][0]*i+r[0][1]*e+r[0][2]*c+r[0][3]>t)&&(!(r[1][0]*i+r[1][1]*e+r[1][2]*c+r[1][3]>t)&&(!(r[2][0]*i+r[2][1]*e+r[2][2]*c+r[2][3]>t)&&(!(r[3][0]*i+r[3][1]*e+r[3][2]*c+r[3][3]>t)&&(!(r[4][0]*i+r[4][1]*e+r[4][2]*c+r[4][3]>t)&&!(r[5][0]*i+r[5][1]*e+r[5][2]*c+r[5][3]>t)))))}function m(r,n,t,i){return h(r,n,null,v(i,n,t,!1))}function d(r,n){for(let t=0;t<6;t++){if(s(r[t],n)>0)return!1}return!0}function g(r,n,t,i){return h(r,n,t,v(i,n,t,!0))}function j(r,n,t,u){const f=c(t,i(r,u,n));return o(r,n,e(r,t,f))}const b={dir:f(),len:0,clip:r()};function v(r,c,o,f){const l=b;return r?(o&&f&&(l.len=n(c,o)),t(l.dir,r)):f?(l.len=n(c,o),i(l.dir,o,c),e(l.dir,l.dir,1/l.len)):(i(l.dir,o,c),u(l.dir,l.dir)),l}function x(r,n,t){const i=c(l(r),t.dir),e=-s(r,n);if(e<0&&i>=0)return!1;if(i>-1e-6&&i<1e-6)return e>0;if((e<0||i<0)&&!(e<0&&i<0))return!0;const o=e/i;return i>0?o<t.clip[1]&&(t.clip[1]=o):o>t.clip[0]&&(t.clip[0]=o),t.clip[0]<=t.clip[1]}function h(r,n,t,i){i.clip[0]=0,i.clip[1]=t?i.len:Number.MAX_VALUE;for(let e=0;e<r.length;e++)if(!x(r[e],n,i))return!1;return!0}export{j as closestPointOnRay,g as frustumLineSegment,d as frustumPoint,m as frustumRay,a as frustumSphere,p as planeSphere};
5
+ import{create as r}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{C as n,d as t,e as i,j as e,g as c,i as o,n as u}from"../../../chunks/vec32.js";import{create as f}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getNormal as l,signedDistance as s}from"../../../geometry/support/plane.js";function p(r,n,t){return r[0]*n[0]+r[1]*n[1]+r[2]*n[2]+r[3]<t}function a(r,n,t){const i=n[0],e=n[1],c=n[2];return!(r[0][0]*i+r[0][1]*e+r[0][2]*c+r[0][3]>t)&&(!(r[1][0]*i+r[1][1]*e+r[1][2]*c+r[1][3]>t)&&(!(r[2][0]*i+r[2][1]*e+r[2][2]*c+r[2][3]>t)&&(!(r[3][0]*i+r[3][1]*e+r[3][2]*c+r[3][3]>t)&&(!(r[4][0]*i+r[4][1]*e+r[4][2]*c+r[4][3]>t)&&!(r[5][0]*i+r[5][1]*e+r[5][2]*c+r[5][3]>t)))))}function m(r,n,t,i){return h(r,n,null,v(i,n,t,!1))}function d(r,n){for(let t=0;t<6;t++){if(s(r[t],n)>0)return!1}return!0}function g(r,n,t,i){return h(r,n,t,v(i,n,t,!0))}function j(r,n,t,u){const f=c(t,i(r,u,n));return o(r,n,e(r,t,f))}const b={dir:f(),len:0,clip:r()};function v(r,c,o,f){const l=b;return r?(o&&f&&(l.len=n(c,o)),t(l.dir,r)):f?(l.len=n(c,o),i(l.dir,o,c),e(l.dir,l.dir,1/l.len)):(i(l.dir,o,c),u(l.dir,l.dir)),l}function x(r,n,t){const i=c(l(r),t.dir),e=-s(r,n);if(e<0&&i>=0)return!1;if(i>-1e-6&&i<1e-6)return e>0;if((e<0||i<0)&&!(e<0&&i<0))return!0;const o=e/i;return i>0?o<t.clip[1]&&(t.clip[1]=o):o>t.clip[0]&&(t.clip[0]=o),t.clip[0]<=t.clip[1]}function h(r,n,t,i){i.clip[0]=0,i.clip[1]=t?i.len:Number.MAX_VALUE;for(let e=0;e<r.length;e++)if(!x(r[e],n,i))return!1;return!0}export{j as closestPointOnRay,g as frustumLineSegment,d as frustumPoint,m as frustumRay,a as frustumSphere,p as planeSphere};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import{destroyMaybe as e}from"../../../../core/maybe.js";import{on as r}from"../../../../core/reactiveUtils.js";import{property as i,subclass as o}from"../../../../core/accessorSupport/decorators.js";import{D as s,m as n,d as a}from"../../../../chunks/vec32.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import d from"../../../../geometry/Point.js";import{InvalidLayerError as h}from"../../../../layers/support/ElevationQuery.js";import{distanceToScale as p}from"../cameraUtils.js";import{PointOfInterest as c}from"./PointOfInterest.js";import{PropertiesPool as u}from"../../../support/PropertiesPool.js";import{Yield as m}from"../../../support/Yield.js";let _=class extends c{constructor(t){super(t),this._dirty=!1,this._propertiesPool=new u({location:()=>new d,renderLocation:()=>l()},this),this._estimatedSurfaceAltitude=0,this._elevationQueryController=null,this.renderLocation=l(),this._tmpPoint=new d}initialize(){if(this.scheduler&&this.addHandles(this.scheduler.registerTask(this.task,this)),this.runTask(),this.map){const t=()=>this._setDirty();this.addHandles(r(()=>this.map?.ground?.layers,"change",t,{onListenerAdd:t,onListenerRemove:t}))}this._updateRenderLocation()}destroy(){this._cancelPendingRequest(),this._propertiesPool=e(this._propertiesPool)}get _camera(){return this.state.contentCamera}get location(){const t=this._propertiesPool.get("location");return t.spatialReference=this.state.spatialReference,this.renderCoordsHelper.fromRenderCoords(this.renderLocation,t),t}get scale(){const t=this._camera,e=s(t.eye,this.renderLocation),r={renderCoordsHelper:this.renderCoordsHelper,state:{camera:t}};return p(r,e)}get updating(){return this._dirty||null!=this._elevationQueryController}updateRenderLocation(){this._setDirty(),this._updateRenderLocation()}_setDirty(){this._dirty||(this._dirty=!0,this.notifyChange("updating"))}_cancelPendingRequest(){const t=this._elevationQueryController;t&&(this._elevationQueryController=null,t.abort(),this.notifyChange("updating"))}get readyToRun(){return!this._elevationQueryController&&this._dirty}runTask(){if(this._cancelPendingRequest(),this._dirty=!1,this.notifyChange("updating"),!this.map?.ground)return this._updateSurfaceAltitude(0),m;const t=this.state.spatialReference;this._tmpPoint.spatialReference=t,this.renderCoordsHelper.fromRenderCoords(this._camera.eye,this._tmpPoint);const e=(this._tmpPoint.z??0)>f&&1===this.renderCoordsHelper.viewingMode&&(t.isWGS84||t.isWebMercator);let r=new AbortController;return this.map.ground.queryElevation(this._tmpPoint,{signal:r.signal,cache:this.cache,minDemResolution:e?g:0}).then(t=>this._updateSurfaceAltitude(t.geometry.z??0)).catch(t=>{if(t.name===h)if(this.integratedMeshElevationSampler){this._tmpPoint.spatialReference=this.integratedMeshElevationSampler.spatialReference,this.renderCoordsHelper.fromRenderCoords(this._camera.eye,this._tmpPoint);const t=this.integratedMeshElevationSampler.elevationAt(this._tmpPoint.x,this._tmpPoint.y)??0;this._updateSurfaceAltitude(t===this.integratedMeshElevationSampler.noDataValue?0:t)}else this._updateSurfaceAltitude(0)}).catch(()=>{}).then(()=>{this._elevationQueryController===r&&(this._elevationQueryController=null,this.notifyChange("updating")),r=null}),this._elevationQueryController=r,m}_updateSurfaceAltitude(t){this._estimatedSurfaceAltitude!==t&&(this._estimatedSurfaceAltitude=t,this._updateRenderLocation())}_updateRenderLocation(){this.renderCoordsHelper.setAltitude(y,this._estimatedSurfaceAltitude,this._camera.eye),n(this._get("renderLocation"),y)||(this._set("renderLocation",a(this._propertiesPool.get("renderLocation"),y)),this.notifyChange("renderLocation"))}};t([i({constructOnly:!0})],_.prototype,"scheduler",void 0),t([i({constructOnly:!0})],_.prototype,"cache",void 0),t([i({constructOnly:!0})],_.prototype,"map",void 0),t([i({constructOnly:!0})],_.prototype,"task",void 0),t([i({constructOnly:!0})],_.prototype,"integratedMeshElevationSampler",void 0),t([i()],_.prototype,"location",null),t([i()],_.prototype,"renderLocation",void 0),t([i()],_.prototype,"scale",null),t([i()],_.prototype,"updating",null),_=t([o("esri.views.3d.support.pointsOfInterest.CameraOnSurface")],_);const y=l(),f=1e5,g=1e6;export{_ as CameraOnSurface};
5
+ import{__decorate as t}from"tslib";import{destroyMaybe as e}from"../../../../core/maybe.js";import{on as r}from"../../../../core/reactiveUtils.js";import{property as i,subclass as o}from"../../../../core/accessorSupport/decorators.js";import{C as s,m as n,d as a}from"../../../../chunks/vec32.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import d from"../../../../geometry/Point.js";import{InvalidLayerError as h}from"../../../../layers/support/ElevationQuery.js";import{distanceToScale as p}from"../cameraUtils.js";import{PointOfInterest as c}from"./PointOfInterest.js";import{PropertiesPool as u}from"../../../support/PropertiesPool.js";import{Yield as m}from"../../../support/Yield.js";let _=class extends c{constructor(t){super(t),this._dirty=!1,this._propertiesPool=new u({location:()=>new d,renderLocation:()=>l()},this),this._estimatedSurfaceAltitude=0,this._elevationQueryController=null,this.renderLocation=l(),this._tmpPoint=new d}initialize(){if(this.scheduler&&this.addHandles(this.scheduler.registerTask(this.task,this)),this.runTask(),this.map){const t=()=>this._setDirty();this.addHandles(r(()=>this.map?.ground?.layers,"change",t,{onListenerAdd:t,onListenerRemove:t}))}this._updateRenderLocation()}destroy(){this._cancelPendingRequest(),this._propertiesPool=e(this._propertiesPool)}get _camera(){return this.state.contentCamera}get location(){const t=this._propertiesPool.get("location");return t.spatialReference=this.state.spatialReference,this.renderCoordsHelper.fromRenderCoords(this.renderLocation,t),t}get scale(){const t=this._camera,e=s(t.eye,this.renderLocation),r={renderCoordsHelper:this.renderCoordsHelper,state:{camera:t}};return p(r,e)}get updating(){return this._dirty||null!=this._elevationQueryController}updateRenderLocation(){this._setDirty(),this._updateRenderLocation()}_setDirty(){this._dirty||(this._dirty=!0,this.notifyChange("updating"))}_cancelPendingRequest(){const t=this._elevationQueryController;t&&(this._elevationQueryController=null,t.abort(),this.notifyChange("updating"))}get readyToRun(){return!this._elevationQueryController&&this._dirty}runTask(){if(this._cancelPendingRequest(),this._dirty=!1,this.notifyChange("updating"),!this.map?.ground)return this._updateSurfaceAltitude(0),m;const t=this.state.spatialReference;this._tmpPoint.spatialReference=t,this.renderCoordsHelper.fromRenderCoords(this._camera.eye,this._tmpPoint);const e=(this._tmpPoint.z??0)>f&&1===this.renderCoordsHelper.viewingMode&&(t.isWGS84||t.isWebMercator);let r=new AbortController;return this.map.ground.queryElevation(this._tmpPoint,{signal:r.signal,cache:this.cache,minDemResolution:e?g:0}).then(t=>this._updateSurfaceAltitude(t.geometry.z??0)).catch(t=>{if(t.name===h)if(this.integratedMeshElevationSampler){this._tmpPoint.spatialReference=this.integratedMeshElevationSampler.spatialReference,this.renderCoordsHelper.fromRenderCoords(this._camera.eye,this._tmpPoint);const t=this.integratedMeshElevationSampler.elevationAt(this._tmpPoint.x,this._tmpPoint.y)??0;this._updateSurfaceAltitude(t===this.integratedMeshElevationSampler.noDataValue?0:t)}else this._updateSurfaceAltitude(0)}).catch(()=>{}).then(()=>{this._elevationQueryController===r&&(this._elevationQueryController=null,this.notifyChange("updating")),r=null}),this._elevationQueryController=r,m}_updateSurfaceAltitude(t){this._estimatedSurfaceAltitude!==t&&(this._estimatedSurfaceAltitude=t,this._updateRenderLocation())}_updateRenderLocation(){this.renderCoordsHelper.setAltitude(y,this._estimatedSurfaceAltitude,this._camera.eye),n(this._get("renderLocation"),y)||(this._set("renderLocation",a(this._propertiesPool.get("renderLocation"),y)),this.notifyChange("renderLocation"))}};t([i({constructOnly:!0})],_.prototype,"scheduler",void 0),t([i({constructOnly:!0})],_.prototype,"cache",void 0),t([i({constructOnly:!0})],_.prototype,"map",void 0),t([i({constructOnly:!0})],_.prototype,"task",void 0),t([i({constructOnly:!0})],_.prototype,"integratedMeshElevationSampler",void 0),t([i()],_.prototype,"location",null),t([i()],_.prototype,"renderLocation",void 0),t([i()],_.prototype,"scale",null),t([i()],_.prototype,"updating",null),_=t([o("esri.views.3d.support.pointsOfInterest.CameraOnSurface")],_);const y=l(),f=1e5,g=1e6;export{_ as CameraOnSurface};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import{clamp as e}from"../../../../core/mathUtils.js";import{removeMaybe as r,destroyMaybe as i}from"../../../../core/maybe.js";import{property as s,subclass as o}from"../../../../core/accessorSupport/decorators.js";import{d as a,D as n,j as c,i as u,m as l,F as d}from"../../../../chunks/vec32.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as h}from"../../../../geometry/ellipsoidUtils.js";import f from"../../../../geometry/Point.js";import{projectBoundingRect as m}from"../../../../geometry/projection/projectBoundingRect.js";import{create as _}from"../../../../geometry/support/aaBoundingRect.js";import{debugFlags as S}from"../debugFlags.js";import{PointOfInterest as y}from"./PointOfInterest.js";import{PropertiesPool as g}from"../../../support/PropertiesPool.js";import{Yield as A}from"../../../support/Yield.js";let j=class extends y{constructor(t){super(t),this._propertiesPool=new g({location:()=>new f,renderLocation:()=>p()},this),this._currentSurfaceAltitude=0,this._latestSurfaceAltitude=0,this.distance=0,this.renderLocation=p(),this.updating=!1}initialize(){this._frameWorker=this.scheduler.registerTask(this.task,this),this.runTask()}destroy(){this._frameWorker=r(this._frameWorker),this._propertiesPool=i(this._propertiesPool)}get _camera(){return this.state.contentCamera}get location(){const t=this._propertiesPool?.get("location");return t?(t.spatialReference=this.state.spatialReference,this.renderCoordsHelper.fromRenderCoords(this.renderLocation,t),t):new f}updateRenderLocation(){this.updating=!0,this._updateRenderLocation()}get estimatedSurfaceAltitude(){return this._latestSurfaceAltitude}get readyToRun(){return this.updating}runTask(){return this._latestSurfaceAltitude=this.estimateSurfaceAltitudeAtCenter(),this._updateRenderLocation(),this.updating=!1,A}_updateRenderLocation(){const t=L;let e=this._calculateSurfaceIntersection(this._currentSurfaceAltitude,t);const r=this._currentSurfaceAltitude!==this._latestSurfaceAltitude;!e&&r&&(e=this._calculateSurfaceIntersection(this._latestSurfaceAltitude,t),e&&(this._currentSurfaceAltitude=this._latestSurfaceAltitude));const i=v;e&&this._latestSurfaceAltitudeChangesDistanceSignificantly(t,i)&&(a(t,i),this._currentSurfaceAltitude=this._latestSurfaceAltitude),e?this.distance=n(this._camera.eye,t):(c(t,this._camera.viewForward,this._get("distance")),u(t,t,this._camera.eye)),l(this._get("renderLocation"),t)||this._set("renderLocation",a(this._propertiesPool.get("renderLocation"),t))}_calculateSurfaceIntersection(t,r){const i=this._camera;if(!this.renderCoordsHelper.intersectInfiniteManifold(i.ray,t,r))return!1;if(this.state.isGlobal){const e=h(this.renderCoordsHelper.spatialReference).radius,s=e+t,o=d(i.eye),a=o<s*s,l=n(i.eye,r);if(a&&l>e/4){const t=s-Math.sqrt(o);return c(r,i.viewForward,t),u(r,r,i.eye),!0}}else{const t=this.surface?.ready?this.surface.groundExtent:null;null!=t&&m(t,this.surface?.spatialReference,C,this.renderCoordsHelper.spatialReference)&&(r[0]=e(r[0],C[0],C[2]),r[1]=e(r[1],C[1],C[3]))}return!0}_latestSurfaceAltitudeChangesDistanceSignificantly(t,e){if(this._latestSurfaceAltitude===this._currentSurfaceAltitude||null==t)return!1;if(this._calculateSurfaceIntersection(this._latestSurfaceAltitude,e)){if(S.TESTS_DISABLE_OPTIMIZATIONS)return!0;const r=this._camera.eye,i=n(r,t),s=n(r,e);if(Math.abs(s-i)/i>R)return!0}return!1}};t([s({constructOnly:!0})],j.prototype,"scheduler",void 0),t([s({constructOnly:!0})],j.prototype,"task",void 0),t([s()],j.prototype,"distance",void 0),t([s({constructOnly:!0})],j.prototype,"estimateSurfaceAltitudeAtCenter",void 0),t([s({readOnly:!0})],j.prototype,"location",null),t([s({readOnly:!0})],j.prototype,"renderLocation",void 0),t([s()],j.prototype,"updating",void 0),j=t([o("esri.views.3d.support.pointsOfInterest.CenterOnSurface")],j);const R=.05,L=p(),v=p(),C=_();export{j as CenterOnSurface};
5
+ import{__decorate as t}from"tslib";import{clamp as e}from"../../../../core/mathUtils.js";import{removeMaybe as r,destroyMaybe as i}from"../../../../core/maybe.js";import{property as s,subclass as o}from"../../../../core/accessorSupport/decorators.js";import{d as a,C as n,j as c,i as u,m as l,E as d}from"../../../../chunks/vec32.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as h}from"../../../../geometry/ellipsoidUtils.js";import f from"../../../../geometry/Point.js";import{projectBoundingRect as m}from"../../../../geometry/projection/projectBoundingRect.js";import{create as _}from"../../../../geometry/support/aaBoundingRect.js";import{debugFlags as S}from"../debugFlags.js";import{PointOfInterest as y}from"./PointOfInterest.js";import{PropertiesPool as g}from"../../../support/PropertiesPool.js";import{Yield as A}from"../../../support/Yield.js";let j=class extends y{constructor(t){super(t),this._propertiesPool=new g({location:()=>new f,renderLocation:()=>p()},this),this._currentSurfaceAltitude=0,this._latestSurfaceAltitude=0,this.distance=0,this.renderLocation=p(),this.updating=!1}initialize(){this._frameWorker=this.scheduler.registerTask(this.task,this),this.runTask()}destroy(){this._frameWorker=r(this._frameWorker),this._propertiesPool=i(this._propertiesPool)}get _camera(){return this.state.contentCamera}get location(){const t=this._propertiesPool?.get("location");return t?(t.spatialReference=this.state.spatialReference,this.renderCoordsHelper.fromRenderCoords(this.renderLocation,t),t):new f}updateRenderLocation(){this.updating=!0,this._updateRenderLocation()}get estimatedSurfaceAltitude(){return this._latestSurfaceAltitude}get readyToRun(){return this.updating}runTask(){return this._latestSurfaceAltitude=this.estimateSurfaceAltitudeAtCenter(),this._updateRenderLocation(),this.updating=!1,A}_updateRenderLocation(){const t=C;let e=this._calculateSurfaceIntersection(this._currentSurfaceAltitude,t);const r=this._currentSurfaceAltitude!==this._latestSurfaceAltitude;!e&&r&&(e=this._calculateSurfaceIntersection(this._latestSurfaceAltitude,t),e&&(this._currentSurfaceAltitude=this._latestSurfaceAltitude));const i=L;e&&this._latestSurfaceAltitudeChangesDistanceSignificantly(t,i)&&(a(t,i),this._currentSurfaceAltitude=this._latestSurfaceAltitude),e?this.distance=n(this._camera.eye,t):(c(t,this._camera.viewForward,this._get("distance")),u(t,t,this._camera.eye)),l(this._get("renderLocation"),t)||this._set("renderLocation",a(this._propertiesPool.get("renderLocation"),t))}_calculateSurfaceIntersection(t,r){const i=this._camera;if(!this.renderCoordsHelper.intersectInfiniteManifold(i.ray,t,r))return!1;if(this.state.isGlobal){const e=h(this.renderCoordsHelper.spatialReference).radius,s=e+t,o=d(i.eye),a=o<s*s,l=n(i.eye,r);if(a&&l>e/4){const t=s-Math.sqrt(o);return c(r,i.viewForward,t),u(r,r,i.eye),!0}}else{const t=this.surface?.ready?this.surface.groundExtent:null;null!=t&&m(t,this.surface?.spatialReference,v,this.renderCoordsHelper.spatialReference)&&(r[0]=e(r[0],v[0],v[2]),r[1]=e(r[1],v[1],v[3]))}return!0}_latestSurfaceAltitudeChangesDistanceSignificantly(t,e){if(this._latestSurfaceAltitude===this._currentSurfaceAltitude||null==t)return!1;if(this._calculateSurfaceIntersection(this._latestSurfaceAltitude,e)){if(S.TESTS_DISABLE_OPTIMIZATIONS)return!0;const r=this._camera.eye,i=n(r,t),s=n(r,e);if(Math.abs(s-i)/i>R)return!0}return!1}};t([s({constructOnly:!0})],j.prototype,"scheduler",void 0),t([s({constructOnly:!0})],j.prototype,"task",void 0),t([s()],j.prototype,"distance",void 0),t([s({constructOnly:!0})],j.prototype,"estimateSurfaceAltitudeAtCenter",void 0),t([s({readOnly:!0})],j.prototype,"location",null),t([s({readOnly:!0})],j.prototype,"renderLocation",void 0),t([s()],j.prototype,"updating",void 0),j=t([o("esri.views.3d.support.pointsOfInterest.CenterOnSurface")],j);const R=.05,C=p(),L=p(),v=_();export{j as CenterOnSurface};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{clamp as t}from"../../../../core/mathUtils.js";import{destroyMaybe as r}from"../../../../core/maybe.js";import{watch as o}from"../../../../core/reactiveUtils.js";import{createRenderScreenPointArray3 as i}from"../../../../core/screenUtils.js";import{property as n,subclass as s}from"../../../../core/accessorSupport/decorators.js";import{m as a,g as c,G as d,d as p,l,e as u,n as h}from"../../../../chunks/vec32.js";import{create as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import f from"../../../../geometry/Point.js";import{wrap as y}from"../../../../geometry/support/ray.js";import{PointOfInterest as g}from"./PointOfInterest.js";import{PropertiesPool as P}from"../../../support/PropertiesPool.js";import{TaskPriority as _}from"../../../support/Scheduler.js";import{Yield as L}from"../../../support/Yield.js";let R=class extends g{constructor(e){super(e),this._propertiesPool=new P({location:()=>new f,renderLocation:()=>m()},this),this._dirty=!0,this.renderLocation=this._propertiesPool.get("renderLocation")}initialize(){this.addHandles([o(()=>this.centerOnSurface.renderLocation,()=>this.updateRenderLocation(),{equals:a}),o(()=>this.state.contentCamera,()=>this.updateRenderLocation())]),this.scheduler&&this.addHandles(this.scheduler.registerTask(_.POINT_OF_INTEREST_FREQUENT,this))}destroy(){this._propertiesPool=r(this._propertiesPool)}get updating(){return this._dirty||this.centerOnSurface.updating}get location(){const e=this._propertiesPool.get("location");return e.spatialReference=this.state.spatialReference,this.renderCoordsHelper.fromRenderCoords(this.renderLocation,e),e}get worldUnitsPerContentPixel(){const{camera:e,contentPixelRatio:t}=this.state;return e.computeRenderPixelSizeAt(this.renderLocation)*(e.pixelRatio/t)}get readyToRun(){return this._dirty}runTask(){const e=this._get("renderLocation"),r=this.centerOnSurface.renderLocation,o=this.renderCoordsHelper,i=this.state.contentCamera;this._dirty=!1,o.worldUpAtPosition(r,S);const n=Math.max(0,(Math.acos(c(S,i.viewForward))-.5*Math.PI)*(i.aboveGround?1:-1));if(Number.isNaN(n)){if(!e||!d(e,r)){const e=this._propertiesPool.get("renderLocation");p(e,r),this._set("renderLocation",e)}return L}const s=1-t(n/(.5*Math.PI),0,1),a=s*s*s;this._calculateScreenHorizontalEdgeOnSurface(O);const u=this._propertiesPool.get("renderLocation");return l(u,r,O,a),e&&d(e,u)||this._set("renderLocation",u),L}_calculateScreenHorizontalEdgeOnSurface(e){const t=this.state.contentCamera,r=t.getRenderCenter(i());if(r[1]=t.aboveGround?t.padding[2]:t.fullHeight-t.padding[0],this.estimateSurfaceIntersectionAtRenderPoint(r,e))return e;const o=this.renderCoordsHelper.getAltitude(this.centerOnSurface.renderLocation);if(t.unprojectFromRenderScreen(r,j)){u(j,j,t.eye);const r=h(j,j);if(this.renderCoordsHelper.intersectInfiniteManifold(y(t.eye,r),o,e))return e}return this.renderCoordsHelper.setAltitude(e,o,t.eye)}updateRenderLocation(){this._dirty=!0}};e([n()],R.prototype,"_dirty",void 0),e([n({constructOnly:!0})],R.prototype,"scheduler",void 0),e([n({constructOnly:!0})],R.prototype,"centerOnSurface",void 0),e([n({constructOnly:!0})],R.prototype,"estimateSurfaceIntersectionAtRenderPoint",void 0),e([n()],R.prototype,"updating",null),e([n()],R.prototype,"location",null),e([n()],R.prototype,"renderLocation",void 0),e([n()],R.prototype,"worldUnitsPerContentPixel",null),R=e([s("esri.views.3d.support.pointsOfInterest.Focus")],R);const S=m(),j=m(),O=m();export{R as Focus};
5
+ import{__decorate as e}from"tslib";import{clamp as t}from"../../../../core/mathUtils.js";import{destroyMaybe as r}from"../../../../core/maybe.js";import{watch as o}from"../../../../core/reactiveUtils.js";import{createRenderScreenPointArray3 as i}from"../../../../core/screenUtils.js";import{property as n,subclass as s}from"../../../../core/accessorSupport/decorators.js";import{m as a,g as c,F as d,d as p,l,e as u,n as h}from"../../../../chunks/vec32.js";import{create as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import f from"../../../../geometry/Point.js";import{wrap as y}from"../../../../geometry/support/ray.js";import{PointOfInterest as g}from"./PointOfInterest.js";import{PropertiesPool as P}from"../../../support/PropertiesPool.js";import{TaskPriority as _}from"../../../support/Scheduler.js";import{Yield as L}from"../../../support/Yield.js";let R=class extends g{constructor(e){super(e),this._propertiesPool=new P({location:()=>new f,renderLocation:()=>m()},this),this._dirty=!0,this.renderLocation=this._propertiesPool.get("renderLocation")}initialize(){this.addHandles([o(()=>this.centerOnSurface.renderLocation,()=>this.updateRenderLocation(),{equals:a}),o(()=>this.state.contentCamera,()=>this.updateRenderLocation())]),this.scheduler&&this.addHandles(this.scheduler.registerTask(_.POINT_OF_INTEREST_FREQUENT,this))}destroy(){this._propertiesPool=r(this._propertiesPool)}get updating(){return this._dirty||this.centerOnSurface.updating}get location(){const e=this._propertiesPool.get("location");return e.spatialReference=this.state.spatialReference,this.renderCoordsHelper.fromRenderCoords(this.renderLocation,e),e}get worldUnitsPerContentPixel(){const{camera:e,contentPixelRatio:t}=this.state;return e.computeRenderPixelSizeAt(this.renderLocation)*(e.pixelRatio/t)}get readyToRun(){return this._dirty}runTask(){const e=this._get("renderLocation"),r=this.centerOnSurface.renderLocation,o=this.renderCoordsHelper,i=this.state.contentCamera;this._dirty=!1,o.worldUpAtPosition(r,S);const n=Math.max(0,(Math.acos(c(S,i.viewForward))-.5*Math.PI)*(i.aboveGround?1:-1));if(Number.isNaN(n)){if(!e||!d(e,r)){const e=this._propertiesPool.get("renderLocation");p(e,r),this._set("renderLocation",e)}return L}const s=1-t(n/(.5*Math.PI),0,1),a=s*s*s;this._calculateScreenHorizontalEdgeOnSurface(O);const u=this._propertiesPool.get("renderLocation");return l(u,r,O,a),e&&d(e,u)||this._set("renderLocation",u),L}_calculateScreenHorizontalEdgeOnSurface(e){const t=this.state.contentCamera,r=t.getRenderCenter(i());if(r[1]=t.aboveGround?t.padding[2]:t.fullHeight-t.padding[0],this.estimateSurfaceIntersectionAtRenderPoint(r,e))return e;const o=this.renderCoordsHelper.getAltitude(this.centerOnSurface.renderLocation);if(t.unprojectFromRenderScreen(r,j)){u(j,j,t.eye);const r=h(j,j);if(this.renderCoordsHelper.intersectInfiniteManifold(y(t.eye,r),o,e))return e}return this.renderCoordsHelper.setAltitude(e,o,t.eye)}updateRenderLocation(){this._dirty=!0}};e([n()],R.prototype,"_dirty",void 0),e([n({constructOnly:!0})],R.prototype,"scheduler",void 0),e([n({constructOnly:!0})],R.prototype,"centerOnSurface",void 0),e([n({constructOnly:!0})],R.prototype,"estimateSurfaceIntersectionAtRenderPoint",void 0),e([n()],R.prototype,"updating",null),e([n()],R.prototype,"location",null),e([n()],R.prototype,"renderLocation",void 0),e([n()],R.prototype,"worldUnitsPerContentPixel",null),R=e([s("esri.views.3d.support.pointsOfInterest.Focus")],R);const S=m(),j=m(),O=m();export{R as Focus};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import t from"../../../Camera.js";import e from"../../../Graphic.js";import n from"../../../Viewpoint.js";import{result as r}from"../../../core/asyncUtils.js";import"../../../core/has.js";import{cyclicalDegrees as a}from"../../../core/Cyclical.js";import o from"../../../core/Error.js";import{throwIfAborted as i}from"../../../core/promiseUtils.js";import{fromMat4 as s,transpose as c}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as l}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{create as m}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{j as u,i as f,D as p,d as g,e as y,h,t as d}from"../../../chunks/vec32.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import x from"../../../geometry/Extent.js";import j from"../../../geometry/Geometry.js";import v from"../../../geometry/Multipoint.js";import b from"../../../geometry/Point.js";import{projectWithZConversion as R,tryProjectWithZConversion as z}from"../../../geometry/projectionUtils.js";import G from"../../../geometry/SpatialReference.js";import{computeTranslationToOriginAndRotation as B}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectPointToVectorAsync as M}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToPoint as S}from"../../../geometry/projection/projectVectorToPoint.js";import{projectVectorToVector as Z}from"../../../geometry/projection/projectVectorToVector.js";import{create as F,center as T,toRect as P,isPoint as A,empty as E,expandWithVec3 as V,expandWithAABB as k,width as O,height as U,depth as N}from"../../../geometry/support/aaBoundingBox.js";import{create as I,isPoint as C}from"../../../geometry/support/aaBoundingRect.js";import{polygonCentroidPoint as D}from"../../../geometry/support/centroid.js";import{intersectsPoint as W}from"../../../geometry/support/frustum.js";import{getResolutionInMetersForScale as Y}from"../../../geometry/support/scaleUtils.js";import{fromRenderCamera as q,toRenderCamera as J}from"../webgl.js";import{cameraOnContentAlongViewDirection as X}from"../camera/intersectionUtils.js";import{getViewSR as _,fromExtentAsync as H,scaleToDistance as K,fromCenterDistanceAsync as L,fromExtentSync as Q,distanceToScale as $,fromCenterDistanceSync as tt,fromCenterScale as et,zoomToScale as nt}from"./cameraUtils.js";import{getElevationAtPoint as rt}from"./ElevationProvider.js";import{directionToHeadingTilt as at}from"./viewingModeUtils.js";const ot=.66;function it(t){return 360-a.normalize(t)}function st(t){return a.normalize(360-t)}function ct(t,e,n){const r=e.camera;if(null!=r)return mt(r,_(t));const{targetGeometry:a}=e;if(null==a)return null;const{camera:o,mode:i}=ft(t,e.rotation,n);if("point"===a.type)return pt(t,e,a,o,i);const s=a.extent;return null==s?null:Q(t,s,o.heading,o.tilt,i)}async function lt(t,e,n,r){const a=e.camera;if(null!=a)return ut(a,_(t),r);const{targetGeometry:o}=e;if(null==o)throw new Error("Viewpoint has no targetGeometry!");const{camera:i,mode:s}=ft(t,e.rotation,n);if("point"===o.type)return gt(t,e,o,i,s,r);const c=o.extent;if(null==c)throw new Error("Target geometry has no extent!");return H(t,c,i.heading,i.tilt,s,r)}function mt(t,e){const n=t.position;let r;try{r=z(n,e)}catch(o){return null}if(!r)return null;const a=t.clone();return a.position=r.clone(),a}async function ut(t,e,n){const r=t.position,a=await R(r,e,{signal:n});i(n);const o=t.clone();return o.position=a.clone(),o}function ft(t,e,n){const r=q(t,t.state.camera);let a=1;return null!=e&&(r.heading=it(e),a=0),null!=n&&(r.tilt=n),{camera:r,mode:a}}function pt(t,e,n,r,a){const o=t.spatialReference;let i;try{i=z(n.clone(),o)}catch(c){return null}if(!i)return null;const s=null!=e.scale?K(t,e.scale):t.state.camera.distance;return tt(t,i,s,r,a)}async function gt(t,e,n,r,a,o){const s=t.spatialReference,c=await R(n.clone(),s,{signal:o});i(o);const l=null!=e.scale?K(t,e.scale):t.state.camera.distance;return L(t,c,l,r,a,o)}function yt(t,e,r=null){return null==r&&(r=new n),jt(t,null,e.clone(),r)}async function ht(e,r,a){const i=At(e,r);if(!i)throw new o("viewpointutils-create:no-target","Missing target for creating viewpoint");const s=new t({fov:e.camera.fov}),c=new n({camera:s});if(i.target instanceof n){return Et(await zt(e,i.target,i,a,c))}if(i.target instanceof t)return Et(await Gt(e,i.target,a,c));const l=null!=i.scale||null!=i.zoom;if(i.target instanceof x){const t=i.target.xmin===i.target.xmax||i.target.ymin===i.target.ymax;return Et(l||t?await Mt(e,i,i.target.center,s,a,c):await Ft(e,i,i.target,s,a,c))}const m=new kt,u=l?wt(e,i):void 0;if(await Rt(e,i.target,u,m,a),isFinite(m.boundingBox[0])){let t;if(T(m.boundingBox,Ot),Jt.x=Ot[0],Jt.y=Ot[1],Jt.z=Ot[2],Jt.spatialReference=e.spatialReference,isFinite(Jt.z)&&m.hasZ?t=A(m.boundingBox):(Jt.z=void 0,t=C(P(m.boundingBox,Ct))),l||t)return Et(await Mt(e,i,Jt,s,a,c));const n=Vt(e,m.screenSpaceObjects);return Et(await Pt(e,i,Jt,m.boundingBox,n,s,a,c))}return i.position?Et(await St(e,i,s,c,a)):Et(await Zt(e,i,s,a,c))}function dt(t,e){return null==e.scale&&null!=e.zoom?nt(t,e.zoom):e.scale}function wt(t,e){const n=dt(t,e);return n?Y(n):void 0}function xt(t,e){let n=!1;return null!=e.heading?(t.heading=e.heading,n=!0):null!=e.rotation&&(t.heading=it(e.rotation),n=!0),null!=e.tilt&&(t.tilt=e.tilt,n=!0),null!=e.fov&&(t.fov=e.fov),n}function jt(t,e,n,r){const a=t.spatialReference||G.WGS84;if(e??=J(t,n),null==e)return r;const o=new b({spatialReference:a});return S(e.center,t.renderSpatialReference,o)?(r.targetGeometry=o,r.scale=$(t,e.distance),r.rotation=st(n.heading),r.camera=n,r):r}async function vt(t,e,n,r){const a=()=>new o("viewpointutils:invalid-geometry","The target is missing a valid geometry");if(!e)throw a();"mesh"===e.type&&(e=e.extent);const i=t.basemapTerrain.spatialReference;if(!e.hasZ&&t.basemapTerrain){let n;switch(e.type){case"point":n=e;break;case"multipoint":case"polyline":n=e.extent?.center;break;case"extent":n=e.center;break;case"polygon":{const t=D(e);n=t?b.fromJSON(t):null;break}}null!=n&&i&&t.elevationProvider?(n=await R(n,i,{signal:r}),Ot[2]=rt(t.elevationProvider,n)??0):Ot[2]=0}const s=Xt[e.type],c=new Array;if(s(e,e.hasZ?t=>{c.push([t[0],t[1],t[2]])}:t=>{c.push([t[0],t[1]])},Ot),0===c.length)throw a();const l=e.spatialReference,m=t.spatialReference,u=await R(new v({spatialReference:l,hasZ:e.hasZ,hasM:!1,points:c}),m,{signal:r});if(e.hasZ&&(n.hasZ=!0),e.hasZ)for(const[o,f,p]of u.points)Ot[0]=o,Ot[1]=f,Ot[2]=p,V(n.boundingBox,Ot);else for(const[o,f]of u.points)Ot[0]=o,Ot[1]=f,V(n.boundingBox,Ot)}async function bt(t,e,n,a,o){const i=await r(t.whenViewForGraphic(e));if(!1===i.ok||null==i.value||!("whenGraphicBounds"in i.value))return void await vt(t,e.geometry,a,o);const s=i.value,c=await r(s.whenGraphicBounds(e,{minDemResolution:n}));if(!1===c.ok||!c.value)return void await vt(t,e.geometry,a,o);const{screenSpaceObjects:l,boundingBox:m}=c.value;k(a.boundingBox,m),l&&l.forEach(t=>{a.screenSpaceObjects.push(t)}),isFinite(m[2])&&(a.hasZ=!0)}async function Rt(t,n,r,a,o){if(Array.isArray(n)&&2===n.length){const e=n[0],r=n[1];if("number"==typeof e&&"number"==typeof r)return Jt.x=e,Jt.y=r,Jt.z=void 0,Jt.spatialReference=t.spatialReference?.isGeographic?t.spatialReference:G.WGS84,void await vt(t,Jt,a,o)}n&&"map"in n&&"function"==typeof n.map?await Promise.allSettled(n.map(e=>Rt(t,e,r,a,o))):n instanceof j?await vt(t,n,a,o):n instanceof e&&await bt(t,n,r,a,o)}async function zt(t,e,n,r,a){if(e.camera)return Gt(t,e.camera,r,a);a.scale=e.scale,a.rotation=e.rotation,a.targetGeometry=null!=e.targetGeometry?e.targetGeometry.clone():null,a.camera=null,null!=n.heading?a.rotation=st(n.heading):null!=n.rotation&&(a.rotation=n.rotation);const o=dt(t,n);return null!=o&&(a.scale=o),a.camera=await lt(t,a,n.tilt,r),a}async function Gt(t,e,n,r){const a=t.spatialReference,o=await R(e.position,a,{signal:n}),i=e.clone();return i.position=o,jt(t,null,i,r)}async function Bt(t,e,n,r,a,o,i){const s=t.renderSpatialReference;return await M(e,Yt,s,{signal:i}),await M(n,Wt,s,{signal:i}),o.targetGeometry=new b(e),a.position=new b(n),y(Dt,Yt,Wt),at(t,Wt,Dt,r.up,a),o.scale=$(t,p(Wt,Yt)),o.rotation=st(a.heading),o.camera=a,o}async function Mt(t,e,n,r,a,o){o.targetGeometry=n.clone();const i=X(t);if(e.position)return Bt(t,o.targetGeometry,e.position,i,r,o,a);if(e.zoomFactor){const n=i.distance/e.zoomFactor,r=u(Ot,i.viewForward,-n);i.eye=f(Ot,i.center,r),o.scale=$(t,n)}q(t,i,r);const s=xt(r,e)?0:1;if(!e.zoomFactor){const n=dt(t,e);if(null==n){await M(o.targetGeometry,Ot,t.renderSpatialReference,{signal:a});const e=W(i.frustum,Ot)?p(i.eye,Ot):i.distance;o.camera=await L(t,o.targetGeometry,e,r,s),o.scale=$(t,e)}else o.scale=n,o.camera=await et(t,o.targetGeometry,o.scale,r,s,a)}return o}async function St(t,e,n,r,a){const o=X(t);g(Dt,o.viewForward),at(t,o.eye,Dt,o.up,qt);const i=t.spatialReference,{position:s}=e;if(s){const t=await R(s,i,{signal:a});n.position=t}else n.position=new b;return n.heading=null!=e.heading?e.heading:qt.heading,n.tilt=null!=e.tilt?e.tilt:qt.tilt,jt(t,null,n,r)}async function Zt(t,e,n,r,a){if(null!=e.heading||null!=e.rotation||null!=e.scale||null!=e.tilt||null!=e.zoom||null!=e.zoomFactor){const o=X(t),{spatialReference:i,renderSpatialReference:s}=t,c=new b({spatialReference:i});return S(o.center,s,c)?Mt(t,e,c,n,r,a):a}return a.scale=t.scale,a.camera=t.camera.clone(),xt(a.camera,e),a}async function Ft(t,e,n,r,a,o){o.targetGeometry=n.clone();const i=X(t);q(t,i,r);const s=xt(r,e)?0:1;return o.camera=await H(t,n,r.heading,r.tilt,s,a),o}function Tt(t,e,n,r,a){let o=0;null!=n.z?o=n.z:t.basemapTerrain&&t.elevationProvider&&(o=rt(t.elevationProvider,n)),h(Ot,n.x,n.y,o),B(t.spatialReference,Ot,Ut,t.renderSpatialReference),s(Nt,Ut),c(Nt,Nt),E(It);const i=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]];for(let s=0;s<i.length;s++){const e=i[s];let n=r[e[2]];isFinite(n)||(n=o),h(Ot,r[e[0]],r[e[1]],n),Z(Ot,t.spatialReference,Ot,t.renderSpatialReference),V(It,d(Ot,Ot,Nt))}const l=O(It),m=U(It),u=N(It),f=1/Math.tan(e.fovX/2),p=1/Math.tan(e.fovY/2),g=.5*Math.sqrt(l*l+u*u)*Math.max(p,f)+.5*m,y=.5*m*p+.5*Math.max(l,u);return Math.max(g,y)/a}async function Pt(t,e,n,r,a,o,i,s){s.targetGeometry=n.clone();const c=X(t),l=Tt(t,c,n,r,a);q(t,c,o);const m=xt(o,e)?0:1;return s.camera=await L(t,s.targetGeometry,l,o,m,i),s.scale=$(t,l),s}function At(t,e){if(!e||!t.spatialReference)return null;const n={target:void 0};return"declaredClass"in e||Array.isArray(e)?n.target=e:(Object.assign(n,e),!n.target&&"center"in e&&e.center&&(n.target=e.center)),n}function Et(t){return null!=t?.camera&&(t.rotation=st(t.camera.heading)),t}function Vt(t,e){const n=ot;if(!e.length)return n;let r=Number.NEGATIVE_INFINITY;for(let a=0;a<e.length;a++){const t=e[a].screenSpaceBoundingRect;r=Math.max(r,Math.abs(t[0]),Math.abs(t[1]),Math.abs(t[2]),Math.abs(t[3]))}return n-r/Math.min(t.width,t.height)*2}class kt{constructor(){this.hasZ=!1,this.boundingBox=E(),this.screenSpaceObjects=new Array}}const Ot=w(),Ut=m(),Nt=l(),It=F(),Ct=I(),Dt=w(),Wt=w(),Yt=w(),qt={heading:0,tilt:0},Jt=new b,Xt={point(t,e,n){n[0]=t.x,n[1]=t.y,null!=t.z&&(n[2]=t.z),e(n)},polygon(t,e,n){const r=t.hasZ;for(let a=0;a<t.rings.length;a++){const o=t.rings[a];for(let t=0;t<o.length;t++)n[0]=o[t][0],n[1]=o[t][1],r&&(n[2]=o[t][2]),e(n)}},polyline(t,e,n){const r=t.hasZ;for(let a=0;a<t.paths.length;a++){const o=t.paths[a];for(let t=0;t<o.length;t++)n[0]=o[t][0],n[1]=o[t][1],r&&(n[2]=o[t][2]),e(n)}},multipoint(t,e,n){const r=t.points,a=t.hasZ;for(let o=0;o<r.length;o++)n[0]=r[o][0],n[1]=r[o][1],a&&(n[2]=r[o][2]),e(n)},extent(t,e,n){null!=t.zmin&&null!=t.zmax?(e(h(n,t.xmin,t.ymin,t.zmin)),e(h(n,t.xmax,t.ymin,t.zmin)),e(h(n,t.xmin,t.ymax,t.zmin)),e(h(n,t.xmax,t.ymax,t.zmin)),e(h(n,t.xmin,t.ymin,t.zmax)),e(h(n,t.xmax,t.ymin,t.zmax)),e(h(n,t.xmin,t.ymax,t.zmax)),e(h(n,t.xmax,t.ymax,t.zmax))):(e(h(n,t.xmin,t.ymin,n[2])),e(h(n,t.xmax,t.ymin,n[2])),e(h(n,t.xmin,t.ymax,n[2])),e(h(n,t.xmax,t.ymax,n[2])))}};export{ht as create,yt as fromCamera,lt as toCameraAsync,ct as toCameraSync};
5
+ import t from"../../../Camera.js";import e from"../../../Graphic.js";import n from"../../../Viewpoint.js";import{result as r}from"../../../core/asyncUtils.js";import"../../../core/has.js";import{cyclicalDegrees as a}from"../../../core/Cyclical.js";import o from"../../../core/Error.js";import{throwIfAborted as i}from"../../../core/promiseUtils.js";import{fromMat4 as s,transpose as c}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as l}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{create as m}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{j as u,i as f,C as p,d as g,e as y,h,t as d}from"../../../chunks/vec32.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import x from"../../../geometry/Extent.js";import j from"../../../geometry/Geometry.js";import v from"../../../geometry/Multipoint.js";import b from"../../../geometry/Point.js";import{projectWithZConversion as R,tryProjectWithZConversion as z}from"../../../geometry/projectionUtils.js";import G from"../../../geometry/SpatialReference.js";import{computeTranslationToOriginAndRotation as B}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectPointToVectorAsync as M}from"../../../geometry/projection/projectPointToVector.js";import{projectVectorToPoint as S}from"../../../geometry/projection/projectVectorToPoint.js";import{projectVectorToVector as Z}from"../../../geometry/projection/projectVectorToVector.js";import{create as F,center as T,toRect as P,isPoint as A,empty as E,expandWithVec3 as V,expandWithAABB as k,width as O,height as U,depth as N}from"../../../geometry/support/aaBoundingBox.js";import{create as C,isPoint as I}from"../../../geometry/support/aaBoundingRect.js";import{polygonCentroidPoint as W}from"../../../geometry/support/centroid.js";import{intersectsPoint as Y}from"../../../geometry/support/frustum.js";import{getResolutionInMetersForScale as q}from"../../../geometry/support/scaleUtils.js";import{fromRenderCamera as D,toRenderCamera as J}from"../webgl.js";import{cameraOnContentAlongViewDirection as X}from"../camera/intersectionUtils.js";import{getViewSR as _,fromExtentAsync as H,scaleToDistance as K,fromCenterDistanceAsync as L,fromExtentSync as Q,distanceToScale as $,fromCenterDistanceSync as tt,fromCenterScale as et,zoomToScale as nt}from"./cameraUtils.js";import{getElevationAtPoint as rt}from"./ElevationProvider.js";import{directionToHeadingTilt as at}from"./viewingModeUtils.js";const ot=.66;function it(t){return 360-a.normalize(t)}function st(t){return a.normalize(360-t)}function ct(t,e,n){const r=e.camera;if(null!=r)return mt(r,_(t));const{targetGeometry:a}=e;if(null==a)return null;const{camera:o,mode:i}=ft(t,e.rotation,n);if("point"===a.type)return pt(t,e,a,o,i);const s=a.extent;return null==s?null:Q(t,s,o.heading,o.tilt,i)}async function lt(t,e,n,r){const a=e.camera;if(null!=a)return ut(a,_(t),r);const{targetGeometry:o}=e;if(null==o)throw new Error("Viewpoint has no targetGeometry!");const{camera:i,mode:s}=ft(t,e.rotation,n);if("point"===o.type)return gt(t,e,o,i,s,r);const c=o.extent;if(null==c)throw new Error("Target geometry has no extent!");return H(t,c,i.heading,i.tilt,s,r)}function mt(t,e){const n=t.position;let r;try{r=z(n,e)}catch(o){return null}if(!r)return null;const a=t.clone();return a.position=r.clone(),a}async function ut(t,e,n){const r=t.position,a=await R(r,e,{signal:n});i(n);const o=t.clone();return o.position=a.clone(),o}function ft(t,e,n){const r=D(t,t.state.camera);let a=1;return null!=e&&(r.heading=it(e),a=0),null!=n&&(r.tilt=n),{camera:r,mode:a}}function pt(t,e,n,r,a){const o=t.spatialReference;let i;try{i=z(n.clone(),o)}catch(c){return null}if(!i)return null;const s=null!=e.scale?K(t,e.scale):t.state.camera.distance;return tt(t,i,s,r,a)}async function gt(t,e,n,r,a,o){const s=t.spatialReference,c=await R(n.clone(),s,{signal:o});i(o);const l=null!=e.scale?K(t,e.scale):t.state.camera.distance;return L(t,c,l,r,a,o)}function yt(t,e,r=null){return null==r&&(r=new n),jt(t,null,e.clone(),r)}async function ht(e,r,a){const i=At(e,r);if(!i)throw new o("viewpointutils-create:no-target","Missing target for creating viewpoint");const s=new t({fov:e.camera.fov}),c=new n({camera:s});if(i.target instanceof n){return Et(await zt(e,i.target,i,a,c))}if(i.target instanceof t)return Et(await Gt(e,i.target,a,c));const l=null!=i.scale||null!=i.zoom;if(i.target instanceof x){const t=i.target.xmin===i.target.xmax||i.target.ymin===i.target.ymax;return Et(l||t?await Mt(e,i,i.target.center,s,a,c):await Ft(e,i,i.target,s,a,c))}const m=new kt,u=l?wt(e,i):void 0;if(await Rt(e,i.target,u,m,a),isFinite(m.boundingBox[0])){let t;if(T(m.boundingBox,Ot),Jt.x=Ot[0],Jt.y=Ot[1],Jt.z=Ot[2],Jt.spatialReference=e.spatialReference,isFinite(Jt.z)&&m.hasZ?t=A(m.boundingBox):(Jt.z=void 0,t=I(P(m.boundingBox,It))),l||t)return Et(await Mt(e,i,Jt,s,a,c));const n=Vt(e,m.screenSpaceObjects);return Et(await Pt(e,i,Jt,m.boundingBox,n,s,a,c))}return i.position?Et(await St(e,i,s,c,a)):Et(await Zt(e,i,s,a,c))}function dt(t,e){return null==e.scale&&null!=e.zoom?nt(t,e.zoom):e.scale}function wt(t,e){const n=dt(t,e);return n?q(n):void 0}function xt(t,e){let n=!1;return null!=e.heading?(t.heading=e.heading,n=!0):null!=e.rotation&&(t.heading=it(e.rotation),n=!0),null!=e.tilt&&(t.tilt=e.tilt,n=!0),null!=e.fov&&(t.fov=e.fov),n}function jt(t,e,n,r){const a=t.spatialReference||G.WGS84;if(e??=J(t,n),null==e)return r;const o=new b({spatialReference:a});return S(e.center,t.renderSpatialReference,o)?(r.targetGeometry=o,r.scale=$(t,e.distance),r.rotation=st(n.heading),r.camera=n,r):r}async function vt(t,e,n,r){const a=()=>new o("viewpointutils:invalid-geometry","The target is missing a valid geometry");if(!e)throw a();"mesh"===e.type&&(e=e.extent);const i=t.basemapTerrain.spatialReference;if(!e.hasZ&&t.basemapTerrain){let n;switch(e.type){case"point":n=e;break;case"multipoint":case"polyline":n=e.extent?.center;break;case"extent":n=e.center;break;case"polygon":{const t=W(e);n=t?b.fromJSON(t):null;break}}null!=n&&i&&t.elevationProvider?(n=await R(n,i,{signal:r}),Ot[2]=rt(t.elevationProvider,n)??0):Ot[2]=0}const s=Xt[e.type],c=new Array;if(s(e,e.hasZ?t=>{c.push([t[0],t[1],t[2]])}:t=>{c.push([t[0],t[1]])},Ot),0===c.length)throw a();const l=e.spatialReference,m=t.spatialReference,u=await R(new v({spatialReference:l,hasZ:e.hasZ,hasM:!1,points:c}),m,{signal:r});if(e.hasZ&&(n.hasZ=!0),e.hasZ)for(const[o,f,p]of u.points)Ot[0]=o,Ot[1]=f,Ot[2]=p,V(n.boundingBox,Ot);else for(const[o,f]of u.points)Ot[0]=o,Ot[1]=f,V(n.boundingBox,Ot)}async function bt(t,e,n,a,o){const i=await r(t.whenViewForGraphic(e));if(!1===i.ok||null==i.value||!("whenGraphicBounds"in i.value))return void await vt(t,e.geometry,a,o);const s=i.value,c=await r(s.whenGraphicBounds(e,{minDemResolution:n}));if(!1===c.ok||!c.value)return void await vt(t,e.geometry,a,o);const{screenSpaceObjects:l,boundingBox:m}=c.value;k(a.boundingBox,m),l&&l.forEach(t=>{a.screenSpaceObjects.push(t)}),isFinite(m[2])&&(a.hasZ=!0)}async function Rt(t,n,r,a,o){if(Array.isArray(n)&&2===n.length){const e=n[0],r=n[1];if("number"==typeof e&&"number"==typeof r)return Jt.x=e,Jt.y=r,Jt.z=void 0,Jt.spatialReference=t.spatialReference?.isGeographic?t.spatialReference:G.WGS84,void await vt(t,Jt,a,o)}n&&"map"in n&&"function"==typeof n.map?await Promise.allSettled(n.map(e=>Rt(t,e,r,a,o))):n instanceof j?await vt(t,n,a,o):n instanceof e&&await bt(t,n,r,a,o)}async function zt(t,e,n,r,a){if(e.camera)return Gt(t,e.camera,r,a);a.scale=e.scale,a.rotation=e.rotation,a.targetGeometry=null!=e.targetGeometry?e.targetGeometry.clone():null,a.camera=null,null!=n.heading?a.rotation=st(n.heading):null!=n.rotation&&(a.rotation=n.rotation);const o=dt(t,n);return null!=o&&(a.scale=o),a.camera=await lt(t,a,n.tilt,r),a}async function Gt(t,e,n,r){const a=t.spatialReference,o=await R(e.position,a,{signal:n}),i=e.clone();return i.position=o,jt(t,null,i,r)}async function Bt(t,e,n,r,a,o,i){const s=t.renderSpatialReference;return await M(e,qt,s,{signal:i}),await M(n,Yt,s,{signal:i}),o.targetGeometry=new b(e),a.position=new b(n),y(Wt,qt,Yt),at(t,Yt,Wt,r.up,a),o.scale=$(t,p(Yt,qt)),o.rotation=st(a.heading),o.camera=a,o}async function Mt(t,e,n,r,a,o){o.targetGeometry=n.clone();const i=X(t);if(e.position)return Bt(t,o.targetGeometry,e.position,i,r,o,a);if(e.zoomFactor){const n=i.distance/e.zoomFactor,r=u(Ot,i.viewForward,-n);i.eye=f(Ot,i.center,r),o.scale=$(t,n)}D(t,i,r);const s=xt(r,e)?0:1;if(!e.zoomFactor){const n=dt(t,e);if(null==n){await M(o.targetGeometry,Ot,t.renderSpatialReference,{signal:a});const e=Y(i.frustum,Ot)?p(i.eye,Ot):i.distance;o.camera=await L(t,o.targetGeometry,e,r,s),o.scale=$(t,e)}else o.scale=n,o.camera=await et(t,o.targetGeometry,o.scale,r,s,a)}return o}async function St(t,e,n,r,a){const o=X(t);g(Wt,o.viewForward),at(t,o.eye,Wt,o.up,Dt);const i=t.spatialReference,{position:s}=e;if(s){const t=await R(s,i,{signal:a});n.position=t}else n.position=new b;return n.heading=null!=e.heading?e.heading:Dt.heading,n.tilt=null!=e.tilt?e.tilt:Dt.tilt,jt(t,null,n,r)}async function Zt(t,e,n,r,a){if(null!=e.heading||null!=e.rotation||null!=e.scale||null!=e.tilt||null!=e.zoom||null!=e.zoomFactor){const o=X(t),{spatialReference:i,renderSpatialReference:s}=t,c=new b({spatialReference:i});return S(o.center,s,c)?Mt(t,e,c,n,r,a):a}return a.scale=t.scale,a.camera=t.camera.clone(),xt(a.camera,e),a}async function Ft(t,e,n,r,a,o){o.targetGeometry=n.clone();const i=X(t);D(t,i,r);const s=xt(r,e)?0:1;return o.camera=await H(t,n,r.heading,r.tilt,s,a),o}function Tt(t,e,n,r,a){let o=0;null!=n.z?o=n.z:t.basemapTerrain&&t.elevationProvider&&(o=rt(t.elevationProvider,n)),h(Ot,n.x,n.y,o),B(t.spatialReference,Ot,Ut,t.renderSpatialReference),s(Nt,Ut),c(Nt,Nt),E(Ct);const i=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]];for(let s=0;s<i.length;s++){const e=i[s];let n=r[e[2]];isFinite(n)||(n=o),h(Ot,r[e[0]],r[e[1]],n),Z(Ot,t.spatialReference,Ot,t.renderSpatialReference),V(Ct,d(Ot,Ot,Nt))}const l=O(Ct),m=U(Ct),u=N(Ct),f=1/Math.tan(e.fovX/2),p=1/Math.tan(e.fovY/2),g=.5*Math.sqrt(l*l+u*u)*Math.max(p,f)+.5*m,y=.5*m*p+.5*Math.max(l,u);return Math.max(g,y)/a}async function Pt(t,e,n,r,a,o,i,s){s.targetGeometry=n.clone();const c=X(t),l=Tt(t,c,n,r,a);D(t,c,o);const m=xt(o,e)?0:1;return s.camera=await L(t,s.targetGeometry,l,o,m,i),s.scale=$(t,l),s}function At(t,e){if(!e||!t.spatialReference)return null;const n={target:void 0};return"declaredClass"in e||Array.isArray(e)?n.target=e:(Object.assign(n,e),!n.target&&"center"in e&&e.center&&(n.target=e.center)),n}function Et(t){return null!=t?.camera&&(t.rotation=st(t.camera.heading)),t}function Vt(t,e){const n=ot;if(!e.length)return n;let r=Number.NEGATIVE_INFINITY;for(let a=0;a<e.length;a++){const t=e[a].screenSpaceBoundingRect;r=Math.max(r,Math.abs(t[0]),Math.abs(t[1]),Math.abs(t[2]),Math.abs(t[3]))}return n-r/Math.min(t.width,t.height)*2}class kt{constructor(){this.hasZ=!1,this.boundingBox=E(),this.screenSpaceObjects=new Array}}const Ot=w(),Ut=m(),Nt=l(),Ct=F(),It=C(),Wt=w(),Yt=w(),qt=w(),Dt={heading:0,tilt:0},Jt=new b,Xt={point(t,e,n){n[0]=t.x,n[1]=t.y,null!=t.z&&(n[2]=t.z),e(n)},polygon(t,e,n){const r=t.hasZ;for(let a=0;a<t.rings.length;a++){const o=t.rings[a];for(let t=0;t<o.length;t++)n[0]=o[t][0],n[1]=o[t][1],r&&(n[2]=o[t][2]),e(n)}},polyline(t,e,n){const r=t.hasZ;for(let a=0;a<t.paths.length;a++){const o=t.paths[a];for(let t=0;t<o.length;t++)n[0]=o[t][0],n[1]=o[t][1],r&&(n[2]=o[t][2]),e(n)}},multipoint(t,e,n){const r=t.points,a=t.hasZ;for(let o=0;o<r.length;o++)n[0]=r[o][0],n[1]=r[o][1],a&&(n[2]=r[o][2]),e(n)},extent(t,e,n){null!=t.zmin&&null!=t.zmax?(e(h(n,t.xmin,t.ymin,t.zmin)),e(h(n,t.xmax,t.ymin,t.zmin)),e(h(n,t.xmin,t.ymax,t.zmin)),e(h(n,t.xmax,t.ymax,t.zmin)),e(h(n,t.xmin,t.ymin,t.zmax)),e(h(n,t.xmax,t.ymin,t.zmax)),e(h(n,t.xmin,t.ymax,t.zmax)),e(h(n,t.xmax,t.ymax,t.zmax))):(e(h(n,t.xmin,t.ymin,n[2])),e(h(n,t.xmax,t.ymin,n[2])),e(h(n,t.xmin,t.ymax,n[2])),e(h(n,t.xmax,t.ymax,n[2])))}};export{ht as create,yt as fromCamera,lt as toCameraAsync,ct as toCameraSync};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{cyclicalPI as r}from"../../../core/Cyclical.js";import"../../../core/has.js";import{clamp as s,deg2rad as i}from"../../../core/mathUtils.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{watch as a,when as o,sync as l}from"../../../core/reactiveUtils.js";import{property as h,subclass as d}from"../../../core/accessorSupport/decorators.js";import{subtract as c}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{i as u,e as p,d as m,D as g}from"../../../chunks/vec32.js";import{create as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as _,s as v,i as f}from"../../../chunks/vec42.js";import{fromValues as w,create as x}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as R}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as S}from"../../../geometry/projection/projectVectorToVector.js";import{create as P,width as O,center as D,copy as T,intersection as M,contains as b,offset as j}from"../../../geometry/support/aaBoundingRect.js";import{createSpatialReferenceCyclical as I}from"../../../geometry/support/normalizeUtils.js";import{create as E,wrap as U}from"../../../geometry/support/ray.js";import{Sphere as V}from"../../../geometry/support/sphere.js";import{angleAroundAxis as C}from"../../../geometry/support/vector.js";import{y2lat as q}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as A}from"../state/utils/viewUtils.js";import{debugFlags as F}from"../support/debugFlags.js";import{DebugPoint as H}from"../support/debugUtils.js";import{OverlayRenderer as G}from"./OverlayRenderer.js";import{Intersector as z}from"../webgl-engine/lib/Intersector.js";import{fromValues as L}from"../webgl-engine/lib/LocalOriginFactory.js";import{SortedRenderGeometryRenderer as B}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as k,ensureTextureSize as W}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as Y}from"../webgl-engine/parts/renderUtils.js";import{TaskPriority as N,noBudget as X}from"../../support/Scheduler.js";import{Yield as Z}from"../../support/Yield.js";const J=1.3,K=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let Q,$=class extends t{constructor(e){super(e),this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._latestOriginId=0,this.groundView=e.view.groundView}initialize(){const{view:e}=this;this.renderer=new G({parent:this}),e.stage.renderer.plugins.add(this.renderer);const t=()=>this.requestRender();this._groundIntersector=new z(e.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([a(()=>this.renderer.hasHighlights,t),this.renderer.events.on("has-water",()=>e.stage?.renderer.updateHasFlags()),this.renderer.events.on("content-changed",t),a(()=>e.state.camera.pixelRatio,t),a(()=>e.state.alignPixelEnabled,t),this.renderer.events.on("textures-disposed",()=>this.groundView.requestRender(1)),a(()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location],()=>this.setPlacementDirty()),a(()=>[e.state?.pixelRatio,e.state?.contentPixelRatio],()=>this.setPlacementDirty(),l),o(()=>this.groundView,e=>e.on("elevation-change",()=>this.setPlacementDirty())),e.on("resize",()=>this.setPlacementDirty()),e.resourceController.scheduler.registerTask(N.OVERLAY,this)]),e.stage.renderer.overlay=this}destroy(){this.view?.stage&&(this.view.stage.renderer.plugins.remove(this.renderer),this.view.stage.renderer.overlay=null,n(this.renderer)),Q&&(Q.hide(),Q=null),this.renderer=null}get spatialReference(){return this._spatialReference}set spatialReference(e){this._spatialReference=e,this.renderer.longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this.renderer.longitudeCyclical=I(e))):this.renderer.disposeOverlays()}get readyToRun(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||F.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&(this.terrainSurface.ready||!this.terrainSurface.enabled)}get _isSpherical(){return this.view.state.isGlobal}get worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?R(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return J/this.view.resolutionScale}get longitudeCyclical(){return this.renderer.longitudeCyclical}get suspended(){return this.terrainSurface.enabled&&this.terrainSurface.suspended}get updating(){return this.readyToRun||!!this.renderer?.updating||this._contentUpdated}render(){return this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.precompileShaders(this.view.state)?this._drawOverlays():null}get hasOverlays(){return this.renderer.hasOverlays}registerDrapeSource(e,t){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources),this.renderer.registerDrapeSource(e,t),this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("readyToRun")}registerGeometryDrapeSource(e){const t=new B({stage:this.view.stage,drapeSource:e,rendererContext:this.renderer});return this.registerDrapeSource(e,t),t}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("readyToRun"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.requestRender()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this.updateOverlays(e,this.view.state.contentCamera,1)}updateOverlays(e,t,r){if(!this._spatialReference)return Z;const s=this._computeOverlayHeight(t);this._computeOverlayExtents(t,s,ie),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,ie.stretch);const i=this._updateOverlay(0,ie.inner,s,1*ie.pixelRatioAdjustment,ie.mapUnitsPerPixel),n=O(ie.inner)/O(ie.outer),a=this._updateOverlay(1,ie.outer,s,n*ie.pixelRatioAdjustment,ie.mapUnitsPerPixel);1!==i&&1!==a||(this._drapeSources.forEach(e=>this._updateDrapeSourceExtent(e)),this.groundView.updateOverlayParameters(),this.groundView.requestRender(r)),0===i&&0===a||this.requestRender(),this._placementDirty=!1,e.madeProgress()}_computeOverlayHeight(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s)),{maxPreferredTexturePixels:n,maxTextureSize:a}=this.view.stage.renderView.renderingContext.parameters,o=.5*a;return k(W({width:i,height:i},{maxPreferredTexturePixels:2*n,maxTextureSize:o})[1],o)}get overlays(){return this.renderer.overlays}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return 0;const n=this.renderer.overlays[e],a=n.mapUnitsPerPixel;if(n.mapUnitsPerPixel=i,n.pixelRatio=s,ee(t,n.extent)&&r===n.resolution)return a===i?0:2;n.setExtent(t),n.resolution=r;const o=D(n.extent);return n.renderLocalOrigin=L(o[0],o[1],0,"OV_"+this._latestOriginId++),1}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[0],s=this.renderer.overlays[1],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}reloadShaders(){Y(),this.requestRender(),this.runTask(X)}requestRender(e=1){this.renderer.hasOverlays?(1===e?(this._contentUpdated=!0,this._drawTexturesDirty=!0):this._drawTexturesAnimateDirty=!0,this.view.stage.renderView.requestRender(e)):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s,i){const n=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,oe,t,r);if(null==n)return!1;const a=n.origin,o=u(se,n.origin,n.direction);this._groundIntersector.reset(a,o,e),this._groundIntersector.intersect([]),this.view.groundView.intersect(this._groundIntersector,null,a,o);const l=this._groundIntersector.results.min;return l.getIntersectionPoint(i)&&l.withinDistance(s)}_findHorizonBasedPointOfInterest(e,t){let i=.5;const n=.55,a=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=s(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:a+l,e.aboveGround?a-l:1/0),d=e.aboveGround;if("global"===this.view.viewingMode){const t=se;le.radius=R(this.view.spatialReference).radius+h,le.closestPointOnSilhouette(U(e.eye,e.viewForward),t),p(t,t,e.eye);const s=r.normalize(C(e.viewForward,t,e.viewRight))/e.fovY+.5,a=s<=0||s>=1?.5:n;i=d?a*s:s+a*(1-s)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),r=Math.tan(t),a=w(0,r,1,0),o=_(a,a,e.projectionMatrix)[1],l=s(.5+.5*o,0,1);i=1===l||0===l?.5:d?l*n:1-(1-l)*n}return this._intersectGroundFromView(e,.5,i,o.distance,t)}_computeOverlayExtents(e,t,r){const{view:s}=this,n=s.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,a=y();this._findHorizonBasedPointOfInterest(e,a)||m(a,n);const o=this._renderSR;F.OVERLAY_SHOW_CENTER?(null==Q&&(Q=new H(s.graphics,"red")),Q.show(a,o)):null!=Q&&Q.hide();const l=Math.max(.1,g(e.eye,a)),h=A(s.renderCoordsHelper,n,e.eye),d=this._spatialReference;this._overlaySREqualsRenderSR||S(a,o,a,d);const u=this._isSpherical,p=this.groundView.groundExtent,_=!u&&d?.isGeographic,w=_&&d?1/R(d).metersPerDegree:1,x=s.state.contentPixelRatio,P=e.perScreenPixelRatio/x*l*w;r.mapUnitsPerPixel=P/this.worldToPCSRatio,r.stretch=this._overlayStretch;let D=t*P/2*r.stretch,j=!1,I=_?90:1/0;u&&p&&d&&(d.isWebMercator?(D/=Math.cos(q(a[1])),I=p[3]):(j=!0,D/=R(d).metersPerDegree,I=90),D>=I&&(D=I,a[1]=0,d.isWebMercator&&(a[0]=0)));let E=1;j&&(E=1/Math.max(.2,Math.cos(Math.abs(i(a[1])))),D*E>180&&(E=180/D),r.mapUnitsPerPixel*=E);const U=Math.log(2)/12;D=Math.exp(Math.round(Math.log(D)/U)*U);const V=D*E,C=32,G=.5*t/(C*V),z=.5*t/(C*D);a[0]=Math.round(a[0]*G)/G,a[1]=Math.round(a[1]*z)/z;const L=r.inner;L[0]=a[0]-V,L[1]=a[1]-D,L[2]=a[0]+V,L[3]=a[1]+D,u&&this._shiftExtentToFitBounds(L,1/0,I);const B=r.outer;if(6*V>O(p))T(B,p);else{if(Math.PI/2-Math.abs(h-Math.PI/2)<=.25*Math.PI)B[0]=L[0]-V,B[1]=L[1]-D,B[2]=L[2]+V,B[3]=L[3]+D;else{S(e.eye,o,se,d),c(re,a,se);let t=-Math.atan2(re[1],re[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));v(re,K[r],2*D),re[0]*=E,re[2]*=E,f(B,L,re)}}if(u)B[0]=this.longitudeCyclical.clamp(B[0]),B[2]=this.longitudeCyclical.clamp(B[2]),B[1]=Math.max(B[1],-I),B[3]=Math.min(B[3],I);else{const e=M(L,p,ne),t=M(B,p,ae);b(e,t)&&(B[2]=B[0],B[3]=B[1])}const k=Math.abs(L[2]-L[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,k),r.pixelRatioAdjustment=r.mapUnitsPerPixel/k}_drawOverlays(e=this.view.state){if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const t=!this._drawTexturesDirty&&this._drawTexturesAnimateDirty?0:1;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const r=this.renderer.computeValidity();this.renderer.releaseRenderTargets(t),this.renderer.drawOverlays(e,t);return r!==this.renderer.computeValidity()&&(this.groundView.updateOverlayParameters(),this.groundView.requestRender(1)),this.groundView.requestRender(t),1===t&&this.terrainSurface.requestUpdate(),this.renderer}_pointIsInExtent(e,t){if(this.longitudeCyclical)return this.longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),j(e,s,i)}get test(){}};function ee(e,t){const r=1e-5,s=F.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([h()],$.prototype,"_spatialReference",void 0),e([h({readOnly:!0})],$.prototype,"readyToRun",null),e([h()],$.prototype,"_placementDirty",void 0),e([h()],$.prototype,"_contentUpdated",void 0),e([h()],$.prototype,"_isSpherical",null),e([h()],$.prototype,"worldToPCSRatio",null),e([h()],$.prototype,"renderer",void 0),e([h({constructOnly:!0})],$.prototype,"view",void 0),e([h({constructOnly:!0})],$.prototype,"groundView",void 0),e([h({constructOnly:!0})],$.prototype,"terrainSurface",void 0),e([h()],$.prototype,"suspended",null),e([h()],$.prototype,"updating",null),$=e([d("esri.views.3d.terrain.OverlayManager")],$);class te{constructor(){this.inner=P(),this.outer=P(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=J}}const re=x(),se=y(),ie=new te,ne=P(),ae=P(),oe=E(),le=new V;export{$ as OverlayManager};
5
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import{cyclicalPI as r}from"../../../core/Cyclical.js";import"../../../core/has.js";import{clamp as s,deg2rad as i}from"../../../core/mathUtils.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{watch as a,when as o,sync as l}from"../../../core/reactiveUtils.js";import{property as h,subclass as d}from"../../../core/accessorSupport/decorators.js";import{subtract as u}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{i as c,e as p,d as m,C as g}from"../../../chunks/vec32.js";import{create as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as _,s as v,i as f}from"../../../chunks/vec42.js";import{fromValues as w,create as x}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as R}from"../../../geometry/ellipsoidUtils.js";import{projectVectorToVector as S}from"../../../geometry/projection/projectVectorToVector.js";import{create as P,width as O,center as D,copy as T,intersection as M,contains as j,offset as b}from"../../../geometry/support/aaBoundingRect.js";import{createSpatialReferenceCyclical as I}from"../../../geometry/support/normalizeUtils.js";import{create as E,wrap as U}from"../../../geometry/support/ray.js";import{Sphere as V}from"../../../geometry/support/sphere.js";import{angleAroundAxis as C}from"../../../geometry/support/vector.js";import{y2lat as q}from"../../../geometry/support/webMercatorUtils.js";import{viewAngle as A}from"../state/utils/viewUtils.js";import{debugFlags as F}from"../support/debugFlags.js";import{DebugPoint as H}from"../support/debugUtils.js";import{OverlayRenderer as G}from"./OverlayRenderer.js";import{Intersector as z}from"../webgl-engine/lib/Intersector.js";import{fromValues as L}from"../webgl-engine/lib/LocalOriginFactory.js";import{SortedRenderGeometryRenderer as B}from"../webgl-engine/lib/SortedRenderGeometryRenderer.js";import{applyTextureResizeModulo as k,ensureTextureSize as W}from"../webgl-engine/lib/textureUtils.js";import{removeLoadedShaderModules as Y}from"../webgl-engine/parts/renderUtils.js";import{TaskPriority as N,noBudget as X}from"../../support/Scheduler.js";import{Yield as Z}from"../../support/Yield.js";const J=1.3,K=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let Q,$=class extends t{constructor(e){super(e),this._renderSR=null,this._overlaySREqualsRenderSR=!0,this._drapeSources=new Set,this._drapeTargets=new Set,this._placementDirty=!1,this._contentUpdated=!1,this._drawTexturesDirty=!1,this._drawTexturesAnimateDirty=!1,this._latestOriginId=0,this.groundView=e.view.groundView}initialize(){const{view:e}=this;this.renderer=new G({parent:this}),e.stage.renderer.plugins.add(this.renderer);const t=()=>this.requestRender();this._groundIntersector=new z(e.state.viewingMode),this._groundIntersector.options.backfacesTerrain=!0,this._groundIntersector.options.invisibleTerrain=!0,this._groundIntersector.options.hud=!1,this.addHandles([a(()=>this.renderer.hasHighlights,t),this.renderer.events.on("has-water",()=>e.stage?.renderer.updateHasFlags()),this.renderer.events.on("content-changed",t),a(()=>e.state.camera.pixelRatio,t),a(()=>e.state.alignPixelEnabled,t),this.renderer.events.on("textures-disposed",()=>this.groundView.requestRender(1)),a(()=>[e.pointsOfInterest?.renderPointOfView,e.pointsOfInterest?.centerOnSurfaceFrequent?.location],()=>this.setPlacementDirty()),a(()=>[e.state?.pixelRatio,e.state?.contentPixelRatio],()=>this.setPlacementDirty(),l),o(()=>this.groundView,e=>e.on("elevation-change",()=>this.setPlacementDirty())),e.on("resize",()=>this.setPlacementDirty()),e.resourceController.scheduler.registerTask(N.OVERLAY,this)]),e.stage.renderer.overlay=this}destroy(){this.view?.stage&&(this.view.stage.renderer.plugins.remove(this.renderer),this.view.stage.renderer.overlay=null,n(this.renderer)),Q&&(Q.hide(),Q=null),this.renderer=null}get spatialReference(){return this._spatialReference}set spatialReference(e){this._spatialReference=e,this.renderer.longitudeCyclical=null;const t=this.view.renderSpatialReference;null!=e&&null!=t?(this._renderSR=t,this._overlaySREqualsRenderSR=e.equals(this._renderSR),this._isSpherical&&(this.renderer.longitudeCyclical=I(e))):this.renderer.disposeOverlays()}get readyToRun(){return this._placementDirty&&(this._drapeSources.size>0||this.view.graphics.length>0||F.OVERLAY_DRAW_DEBUG_TEXTURE)&&!!this._spatialReference&&!this.suspended&&this.groundView.ready}get _isSpherical(){return this.view.state.isGlobal}get worldToPCSRatio(){return null!=this._spatialReference&&this._spatialReference.isGeographic&&!this.view.state.isLocal?R(this._spatialReference).metersPerDegree:1}get _overlayStretch(){return J/this.view.resolutionScale}get longitudeCyclical(){return this.renderer.longitudeCyclical}get suspended(){return this.terrainSurface.enabled&&this.terrainSurface.suspended}get updating(){return this.readyToRun||!!this.renderer?.updating||this._contentUpdated}render(){return this._contentUpdated=!1,this.renderer.processSyncDrapeSources(),this.renderer.precompileShaders(this.view.state)?this._drawOverlays():null}get hasOverlays(){return this.renderer.hasOverlays}registerDrapeSource(e,t){this._drapeSources.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources),this.renderer.registerDrapeSource(e,t),this._updateDrapeSourceExtent(e),this._setContentDirty(),this.notifyChange("readyToRun")}registerGeometryDrapeSource(e){const t=new B({stage:this.view.stage,drapeSource:e,rendererContext:this.renderer});return this.registerDrapeSource(e,t),t}_updateDrapeSourceExtent(e){2===this.renderer.overlays.length&&null!=e.setDrapingExtent&&null!=this._spatialReference&&e.setDrapingExtent(this.renderer.overlays,this._spatialReference)}unregisterDrapeSource(e){this._drapeSources.has(e)&&(this._drapeSources.delete(e),this.renderer.removeDrapeSourceRenderer(e),this.renderer.ensureDrapeSources(this._drapeSources),this._setContentDirty(),this.notifyChange("readyToRun"))}registerDrapeTarget(e){this._drapeTargets.add(e),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources)}unregisterDrapeTarget(e){this._drapeTargets.delete(e),this.renderer.ensureDrapeTargets(this._drapeTargets)}_setContentDirty(){this.setPlacementDirty(),this.requestRender()}setPlacementDirty(){this._placementDirty=!0}runTask(e){return this.updateOverlays(e,this.view.state.contentCamera,1)}updateOverlays(e,t,r){if(!this._spatialReference)return Z;const s=this._computeOverlayHeight(t);this._computeOverlayExtents(t,s,ie),this.renderer.ensureOverlays(this._drapeTargets,this._drapeSources,ie.stretch);const i=this._updateOverlay(0,ie.inner,s,1*ie.pixelRatioAdjustment,ie.mapUnitsPerPixel),n=O(ie.inner)/O(ie.outer),a=this._updateOverlay(1,ie.outer,s,n*ie.pixelRatioAdjustment,ie.mapUnitsPerPixel);1!==i&&1!==a||(this._drapeSources.forEach(e=>this._updateDrapeSourceExtent(e)),this.groundView.updateOverlayParameters(),this.groundView.requestRender(r)),0===i&&0===a||this.requestRender(),this._placementDirty=!1,e.madeProgress()}_computeOverlayHeight(e){const t=this.view.state.contentPixelRatio*this.view.resolutionScale,r=e.fullWidth/e.pixelRatio*t,s=e.fullHeight/e.pixelRatio*t,i=Math.ceil(1.5*Math.max(r,s)),{maxPreferredTexturePixels:n,maxTextureSize:a}=this.view.stage.renderView.renderingContext.parameters,o=.5*a;return k(W({width:i,height:i},{maxPreferredTexturePixels:2*n,maxTextureSize:o})[1],o)}get overlays(){return this.renderer.overlays}_updateOverlay(e,t,r,s,i){if(0===this.renderer.overlays.length)return 0;const n=this.renderer.overlays[e],a=n.mapUnitsPerPixel;if(n.mapUnitsPerPixel=i,n.pixelRatio=s,ee(t,n.extent)&&r===n.resolution)return a===i?0:2;n.setExtent(t),n.resolution=r;const o=D(n.extent);return n.renderLocalOrigin=L(o[0],o[1],0,"OV_"+this._latestOriginId++),1}overlayPixelSizeInMapUnits(e,t){if(0===this.renderer.overlays.length)return t();const r=this.renderer.overlays[0],s=this.renderer.overlays[1],i=this._pointIsInExtent(e,r.extent)?r:s;return(i.extent[2]-i.extent[0])/i.resolution}reloadShaders(){Y(),this.requestRender(),this.runTask(X)}requestRender(e=1){this.renderer.hasOverlays?(1===e?(this._contentUpdated=!0,this._drawTexturesDirty=!0):this._drawTexturesAnimateDirty=!0,this.view.stage.renderView.requestRender(e)):this.setPlacementDirty()}_intersectGroundFromView(e,t,r,s,i){const n=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(e,oe,t,r);if(null==n)return!1;const a=n.origin,o=c(se,n.origin,n.direction);this._groundIntersector.reset(a,o,e),this._groundIntersector.intersect([]),this.view.groundView.intersect(this._groundIntersector,null,a,o);const l=this._groundIntersector.results.min;return l.getIntersectionPoint(i)&&l.withinDistance(s)}_findHorizonBasedPointOfInterest(e,t){let i=.5;const n=.55,a=this.view.renderCoordsHelper.getAltitude(e.eye),o=this.view.pointsOfInterest.centerOnSurfaceFrequent,l=1e-5,h=s(o.estimatedSurfaceAltitude,e.aboveGround?-1/0:a+l,e.aboveGround?a-l:1/0),d=e.aboveGround;if("global"===this.view.viewingMode){const t=se;le.radius=R(this.view.spatialReference).radius+h,le.closestPointOnSilhouette(U(e.eye,e.viewForward),t),p(t,t,e.eye);const s=r.normalize(C(e.viewForward,t,e.viewRight))/e.fovY+.5,a=s<=0||s>=1?.5:n;i=d?a*s:s+a*(1-s)}else{const t=.5*Math.PI-Math.acos(-e.viewForward[2]),r=Math.tan(t),a=w(0,r,1,0),o=_(a,a,e.projectionMatrix)[1],l=s(.5+.5*o,0,1);i=1===l||0===l?.5:d?l*n:1-(1-l)*n}return this._intersectGroundFromView(e,.5,i,o.distance,t)}_computeOverlayExtents(e,t,r){const{view:s}=this,n=s.pointsOfInterest.centerOnSurfaceFrequent.renderLocation,a=y();this._findHorizonBasedPointOfInterest(e,a)||m(a,n);const o=this._renderSR;F.OVERLAY_SHOW_CENTER?(null==Q&&(Q=new H(s.graphics,"red")),Q.show(a,o)):null!=Q&&Q.hide();const l=Math.max(.1,g(e.eye,a)),h=A(s.renderCoordsHelper,n,e.eye),d=this._spatialReference;this._overlaySREqualsRenderSR||S(a,o,a,d);const c=this._isSpherical,p=this.groundView.groundExtent,_=!c&&d?.isGeographic,w=_&&d?1/R(d).metersPerDegree:1,x=s.state.contentPixelRatio,P=e.perScreenPixelRatio/x*l*w;r.mapUnitsPerPixel=P/this.worldToPCSRatio,r.stretch=this._overlayStretch;let D=t*P/2*r.stretch,b=!1,I=_?90:1/0;c&&p&&d&&(d.isWebMercator?(D/=Math.cos(q(a[1])),I=p[3]):(b=!0,D/=R(d).metersPerDegree,I=90),D>=I&&(D=I,a[1]=0,d.isWebMercator&&(a[0]=0)));let E=1;b&&(E=1/Math.max(.2,Math.cos(Math.abs(i(a[1])))),D*E>180&&(E=180/D),r.mapUnitsPerPixel*=E);const U=Math.log(2)/12;D=Math.exp(Math.round(Math.log(D)/U)*U);const V=D*E,C=32,G=.5*t/(C*V),z=.5*t/(C*D);a[0]=Math.round(a[0]*G)/G,a[1]=Math.round(a[1]*z)/z;const L=r.inner;L[0]=a[0]-V,L[1]=a[1]-D,L[2]=a[0]+V,L[3]=a[1]+D,c&&this._shiftExtentToFitBounds(L,1/0,I);const B=r.outer;if(p&&6*V>O(p))T(B,p);else{if(Math.PI/2-Math.abs(h-Math.PI/2)<=.25*Math.PI)B[0]=L[0]-V,B[1]=L[1]-D,B[2]=L[2]+V,B[3]=L[3]+D;else{S(e.eye,o,se,d),u(re,a,se);let t=-Math.atan2(re[1],re[0])+.125*Math.PI;t<0&&(t+=2*Math.PI);const r=Math.floor(t/(.25*Math.PI));v(re,K[r],2*D),re[0]*=E,re[2]*=E,f(B,L,re)}}if(c)B[0]=this.longitudeCyclical.clamp(B[0]),B[2]=this.longitudeCyclical.clamp(B[2]),B[1]=Math.max(B[1],-I),B[3]=Math.min(B[3],I);else{const e=M(L,p,ne),t=M(B,p,ae);j(e,t)&&(B[2]=B[0],B[3]=B[1])}const k=Math.abs(L[2]-L[0])/t;r.mapUnitsPerPixel=Math.max(r.mapUnitsPerPixel,k),r.pixelRatioAdjustment=r.mapUnitsPerPixel/k}_drawOverlays(e=this.view.state){if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;const t=!this._drawTexturesDirty&&this._drawTexturesAnimateDirty?0:1;this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;const r=this.renderer.computeValidity();this.renderer.releaseRenderTargets(t),this.renderer.drawOverlays(e,t);return r!==this.renderer.computeValidity()&&(this.groundView.updateOverlayParameters(),this.groundView.requestRender(1)),this.groundView.requestRender(t),1===t&&this.terrainSurface.requestUpdate(),this.renderer}_pointIsInExtent(e,t){if(this.longitudeCyclical)return this.longitudeCyclical.contains(t[0],t[2],e.x)&&e.y>=t[1]&&e.y<=t[3];const r=e.x,s=e.y;return r>t[0]&&r<t[2]&&s>t[1]&&s<t[3]}_shiftExtentToFitBounds(e,t,r){let s=0,i=0;e[0]<-t?s=e[0]+t:e[2]>t&&(s=t-e[2]),e[1]<-r?i=e[1]+r:e[3]>r&&(i=r-e[3]),b(e,s,i)}get test(){}};function ee(e,t){const r=1e-5,s=F.TESTS_DISABLE_OPTIMIZATIONS?0:r*Math.max(e[2]-e[0],e[3]-e[1],t[2]-t[0],t[3]-t[1]);return Math.abs(t[0]-e[0])<=s&&Math.abs(t[1]-e[1])<=s&&Math.abs(t[2]-e[2])<=s&&Math.abs(t[3]-e[3])<=s}e([h()],$.prototype,"_spatialReference",void 0),e([h({readOnly:!0})],$.prototype,"readyToRun",null),e([h()],$.prototype,"_placementDirty",void 0),e([h()],$.prototype,"_contentUpdated",void 0),e([h()],$.prototype,"_isSpherical",null),e([h()],$.prototype,"worldToPCSRatio",null),e([h()],$.prototype,"renderer",void 0),e([h({constructOnly:!0})],$.prototype,"view",void 0),e([h({constructOnly:!0})],$.prototype,"groundView",void 0),e([h({constructOnly:!0})],$.prototype,"terrainSurface",void 0),e([h()],$.prototype,"suspended",null),e([h()],$.prototype,"updating",null),$=e([d("esri.views.3d.terrain.OverlayManager")],$);class te{constructor(){this.inner=P(),this.outer=P(),this.mapUnitsPerPixel=0,this.pixelRatioAdjustment=1,this.stretch=J}}const re=x(),se=y(),ie=new te,ne=P(),ae=P(),oe=E(),le=new V;export{$ as OverlayManager};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as e}from"tslib";import{unique as r}from"../../../core/arrayUtils.js";import{EventEmitter as t}from"../../../core/Evented.js";import"../../../core/has.js";import{someMap as s,everyMap as i}from"../../../core/MapUtils.js";import{disposeMaybe as n}from"../../../core/maybe.js";import o from"../../../core/PooledArray.js";import{watch as a,on as h,syncAndInitial as d,initial as l}from"../../../core/reactiveUtils.js";import{someSet as c}from"../../../core/SetUtils.js";import{property as u,subclass as p}from"../../../core/accessorSupport/decorators.js";import{ortho as _,fromTranslation as g}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{h as m}from"../../../chunks/vec32.js";import{ones as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{debugFlags as f}from"../support/debugFlags.js";import{Overlay as R}from"./Overlay.js";import{OverlayRenderTargets as v}from"./OverlayRenderTargets.js";import x from"../webgl/RenderCamera.js";import{T as w}from"../../../chunks/TextureOnly.glsl.js";import{SyncRenderPlugin as T}from"../webgl-engine/effects/RenderPlugin.js";import{trackHighlightOptions as S,renderHighlightBuffer as b}from"../webgl-engine/effects/highlight/Highlight.js";import{GLMaterialRepository as O}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as D}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as C,defaultRenderOccludedMask as P}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as j}from"../webgl-engine/lib/ShadowMap.js";import{TextureTechnique as E}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as M}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as F}from"../webgl-engine/lighting/Lightsources.js";import{O as W}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as q}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import{TaskPriority as V,noBudget as A}from"../../support/Scheduler.js";import{Texture as k}from"../../webgl/Texture.js";import{TextureDescriptor as G}from"../../webgl/TextureDescriptor.js";let I=class extends T{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new W,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new o,this._passParameters=new w,this._screenToWorldRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new x,this.events=new t,this.longitudeCyclical=null,this.produces=new Map([[18,e=>8!==e||this.hasHighlights],[19,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1}initialize(){const e=this._view,r=e.stage,t=r.renderer.fboCache,{waterTextures:s,techniques:i}=r.renderView;this._renderContext=new C(this._rctx,new j(t,e.state.viewingMode),i),this.addHandles([a(()=>s.updating,()=>this.events.emit("content-changed"),d),a(()=>this._spatialReference,e=>this._localOriginFactory=new D(e),d),h(()=>e.allLayerViews,"after-changes",()=>this._sortedDrapeSourceRenderersDirty=!0),a(()=>S(e.state.highlights),()=>this._sortedDrapeSourceRenderersDirty=!0,l),a(()=>e.state.highlights,r=>{this._bindParameters.highlights=r,this._bindParameters.highlightOrderMap=e.state.highlightOrderMap},l),e.resourceController.scheduler.registerTask(V.OVERLAY_RENDERER,this)]);const{_bindParameters:n,_camera:o}=this;o.near=1,o.far=1e4,o.relativeElevation=null,n.slot=18,n.mainDepth=null,n.camera=o,n.oitPass=0,n.updateLighting([new F(y())],0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=n(this._passParameters.texture),this.disposeOverlays(),this._renderContext=null,this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToWorldRatio(){return this._screenToWorldRatio}get localOriginFactory(){return this._localOriginFactory}get pluginContext(){return this._pluginContext}initializeRenderContext(e){const r=new O(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit("content-changed"),this.notifyChange("updating"),this.notifyChange("isEmpty")},()=>this.events.emit("content-changed"));this._pluginContext={...e,materials:r},this._techniques.precompile(q)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||s(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return null!=this._overlays&&null!=this._renderTargets}getMaterialRenderer(e){for(const r of this._renderers.values()){const t=r.getMaterialRenderer(e);if(t)return t}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),r(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,r){const t=this._renderers.get(e);null!=t&&t.destroy(),this._renderers.set(e,r),this._sortedDrapeSourceRenderersDirty=!0,"fullOpacity"in e&&this.addHandles(a(()=>e.fullOpacity,()=>this.events.emit("content-changed")),e)}removeDrapeSourceRenderer(e){if(null==e)return;const r=this._renderers.get(e);null!=r&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),r.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=!!this._overlays&&c(e,e=>1===e.drapeTargetType)}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=c(e,e=>1===e.drapeSourceType),this._hasDrapedRasterSource=c(e,e=>0===e.drapeSourceType),this._hasDrapedFlowSource=c(e,e=>2===e.drapeSourceType)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,r,t=this._bindParameters.overlayStretch){null==this._overlays&&(this._renderTargets=new v(this._stage.renderer.fboCache),this._overlays=[new R,new R]),this.ensureDrapeTargets(e),this.ensureDrapeSources(r),this._bindParameters.overlayStretch=t}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit("textures-disposed")}_useOverlayColorInsteadOfColorNoRasterImage(e){return 1===e&&!this._needsColorWithoutRasterImage&&this._hasDrapedFeatureSource}getTexture(e){const r=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(r?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(e,()=>!0)}_onMaterialOrContentChanged(){this.renderOccludedFlags=s(this._renderers,e=>e.hasOccluders)?L:1}_processDrapeSources(e,r){let t=!1;for(const[s,i]of this._renderers){if(e.done)break;(s.destroyed||r(s))&&(i.commitChanges()&&(t=!0,e.madeProgress()))}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,t=!0,this._updateSortedDrapeSourceRenderers(),e.madeProgress()),this.compact(e),t&&(null!=this._overlays&&0===this._renderers.size&&this.disposeOverlays(),this.notifyChange("updating"),this.notifyChange("isEmpty"),this._onMaterialOrContentChanged(),this.hasHighlights=s(this._renderers,e=>e.hasHighlights),this.events.emit("content-changed"))}compact(e){let r=!1;for(const t of this._renderers.values()){if(e.done)break;r=t.compact(e)||r}return r&&this.notifyChange("updating"),r}hasHighlight(e){return s(this._renderers,r=>r.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(A,e=>1===e.updatePolicy)}get isEmpty(){return!f.OVERLAY_DRAW_DEBUG_TEXTURE&&i(this._renderers,e=>e.isEmpty)}get hasWater(){const e=s(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit("has-water")),this._hasWater}renders(e){if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==e&&2!==e)return!0;if(!this._overlays)return!1;const r=this._overlays[0];for(const i of this._overlays)i.setupGeometryViews(this.longitudeCyclical);if(!r.hasSomeSizedView())return!1;const t=this._renderContext.output;this._renderContext.output=this._renderTargets?.targets.find(r=>r.content===e)?.output??0,++this._techniques.precompiling;const s=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,this._renderContext.output=t,s}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:this._renderTargets?.getTexture(0)?1:0}updateAnimation(e){let r=!1;return this._renderers.forEach(t=>r=t.updateAnimation(e)||r),r&&this.parent.requestRender(0),r}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;const r=this._bindParameters;r.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(const t of this._renderTargets.targets){if(1===t.content&&!this._needsColorWithoutRasterImage)continue;const{output:e}=t;this._renderContext.output=e,r.slot=2===e?19:18,8===e&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null);const s=this._renderContext.renderOccludedMask;4===t.content&&(this._renderContext.renderOccludedMask=L),this._sortedRenderers.forAll(({drapeSource:e,renderer:r})=>{1===t.content&&0===e.drapeSourceType||4===t.content&&r.hasOnlyOccluders||r.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=s,r.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,r){if(!this._overlays||!this._renderTargets)return;for(const s of this._overlays)s.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;const t=this.allSourcesOccluders;for(const s of this._renderTargets.targets){if(!(0===s.content&&this._hasDrapedFlowSource)&&!s.handleRenderRequest(r)||1===s.content&&!this._needsColorWithoutRasterImage||4===s.content&&t)continue;const e=this._drawTarget(0,s),i=this._drawTarget(1,s);(e||i)&&s.fbo.generateMipMap()}}_drawTarget(e,r){const t=this._overlays[e],s=t.canvasGeometries;if(0===s.numViews)return!1;const i=this._view.state.contentPixelRatio;this._screenToWorldRatio=i*t.mapUnitsPerPixel/this._bindParameters.overlayStretch;const{output:n}=r;if(this.isEmpty||2===n&&!this.hasWater||!t.hasSomeSizedView())return!1;const{_rctx:o,_camera:a,_renderContext:h,_bindParameters:d}=this;if(a.pixelRatio=t.pixelRatio*i,h.output=n,d.screenToWorldRatio=this._screenToWorldRatio,d.screenToPCSRatio=this._screenToWorldRatio*this.parent.worldToPCSRatio,d.slot=2===n?19:18,4===r.content&&(h.renderOccludedMask=L),!this.renders(r.content))return h.renderOccludedMask=P,!1;const{resolution:l}=t,c=0===e,u=c?0:l;if(o.setViewport(u,0,l,l),this._bindTargetFBO(r),c)if(8!==r.output)o.setClearColor(0,0,0,0),o.clear(16384);else{const{gl:e}=o;e.clearBufferuiv(e.COLOR,0,[0,0,0,0])}if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==r.content&&2!==r.content){this._techniques.precompile(E,z);const r=this._techniques.get(E,z);for(let i=0;i<s.numViews;i++)this._setViewParameters(s.extents[i],t),this._ensureDebugPatternResources(t.resolution,B[e]),o.bindTechnique(r,d,this._passParameters),o.screen.draw()}if(8===r.output){const{fboCache:t}=this._stage.renderer,s=this._resolution;this._bindTargetFBO(r),b(o,t,{width:s,height:s},d,()=>this._renderAllGeometry(e,r),u)}else this._renderAllGeometry(e,r);return o.bindFramebuffer(null),h.renderOccludedMask=P,!0}get allSourcesOccluders(){return i(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,r){const t=this._overlays[e],s=t.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:n})=>{if(1===r.content&&0===i.drapeSourceType)return;const{fullOpacity:o}=i,a=null!=o&&o<1&&0===r.output&&this._bindTemporaryFBO();for(let e=0;e<s.numViews;e++)this._setViewParameters(s.extents[e],t),n.render(this._renderContext);if(a){this._bindTargetFBO(r),this._overlayParameters.texture=a.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;const t=this._techniques.get(q);this._rctx.bindTechnique(t,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),a.release()}})}_bindTargetFBO(e){const r=this._resolution,t=2*r;e.fbo.ensureFramebuffer(t,r),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){const e=this._resolution,r=2*e,t=this._stage.renderer.fboCache,s=t.acquire(r,e,"overlay tmp");return t.rctx.bindFramebuffer(s.fbo),t.rctx.clear(16384),s}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit("content-changed")}intersect(e,r,t,s){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(const{renderer:n}of this._sortedRenderers)i=n.intersect?.(e,r,t,s,i)??i}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),0===this._renderers.size)return;const e=this._view.map.allLayers.map(e=>e.uid),r=e.length;this._renderers.forEach((t,s)=>{const i=e.indexOf(s.layer?.uid),n=i>=0,o=s.renderGroup??(n?0:1),a=s.drapeSourcePriorityOffset??0,h=r*o+(n?i:0)+a;this._sortedRenderers.push(new U(s,t,h))}),this._sortedRenderers.sort((e,r)=>e.index-r.index)}_setViewParameters(e,r){const t=this._camera;t.viewport=[0,0,r.resolution,r.resolution],_(t.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],t.near,t.far),g(t.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,r){if(m(this._passParameters.color,r[0],r[1],r[2]),this._passParameters.texture)return;const t=new Uint8Array(e*e*4);let s=0;for(let n=0;n<e;n++)for(let r=0;r<e;r++){const i=Math.floor(r/10),o=Math.floor(n/10);i<2||o<2||10*i>e-20||10*o>e-20?(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=255):(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=1&i&&1&o?1&r^1&n?0:255:1&i^1&o?0:128)}const i=new G(e);i.samplingMode=9728,this._passParameters.texture=new k(this._rctx,i,t)}get test(){}};e([u()],I.prototype,"hasHighlights",void 0),e([u()],I.prototype,"renderOccludedFlags",void 0),e([u()],I.prototype,"_sortedDrapeSourceRenderersDirty",void 0),e([u({constructOnly:!0})],I.prototype,"parent",void 0),e([u({readOnly:!0})],I.prototype,"_techniques",null),e([u({type:Boolean,readOnly:!0})],I.prototype,"updating",null),e([u()],I.prototype,"isEmpty",null),I=e([p("esri.views.3d.terrain.OverlayRenderer")],I);class U{constructor(e,r,t){this.drapeSource=e,this.renderer=r,this.index=t}}const B=[[1,.5,.5],[.5,.5,1]],H=-2,L=4,z=new M;z.hasAlpha=!0;export{I as OverlayRenderer,H as drapedZ,L as overlayRenderOccludedFlag};
5
+ import{__decorate as e}from"tslib";import{unique as r}from"../../../core/arrayUtils.js";import{EventEmitter as t}from"../../../core/Evented.js";import"../../../core/has.js";import{someMap as s,everyMap as i}from"../../../core/MapUtils.js";import{disposeMaybe as n}from"../../../core/maybe.js";import o from"../../../core/PooledArray.js";import{watch as a,on as h,syncAndInitial as d,initial as l}from"../../../core/reactiveUtils.js";import{someSet as c}from"../../../core/SetUtils.js";import{property as u,subclass as p}from"../../../core/accessorSupport/decorators.js";import{ortho as _,fromTranslation as g}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{h as m}from"../../../chunks/vec32.js";import{ones as y}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{debugFlags as f}from"../support/debugFlags.js";import{Overlay as R}from"./Overlay.js";import{OverlayRenderTargets as v}from"./OverlayRenderTargets.js";import w from"../webgl/RenderCamera.js";import{T as x}from"../../../chunks/TextureOnly.glsl.js";import{SyncRenderPlugin as T}from"../webgl-engine/effects/RenderPlugin.js";import{trackHighlightOptions as O,renderHighlightBuffer as S}from"../webgl-engine/effects/highlight/Highlight.js";import{GLMaterialRepository as b}from"../webgl-engine/lib/GLMaterialRepository.js";import{GridLocalOriginFactory as D}from"../webgl-engine/lib/GridLocalOriginFactory.js";import{RenderContext as C,defaultRenderOccludedMask as P}from"../webgl-engine/lib/RenderContext.js";import{ShadowMap as j}from"../webgl-engine/lib/ShadowMap.js";import{TextureTechnique as E}from"../webgl-engine/lib/TextureTechnique.js";import{TextureTechniqueConfiguration as M}from"../webgl-engine/lib/TextureTechniqueConfiguration.js";import{AmbientLight as F}from"../webgl-engine/lighting/Lightsources.js";import{O as W}from"../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as q}from"../webgl-engine/shaders/OverlayCompositingTechnique.js";import{TaskPriority as V,noBudget as A}from"../../support/Scheduler.js";import{Texture as k}from"../../webgl/Texture.js";import{TextureDescriptor as G}from"../../webgl/TextureDescriptor.js";let I=class extends T{constructor(e){super(e),this._overlays=null,this._renderTargets=null,this._overlayParameters=new W,this.hasHighlights=!1,this.renderOccludedFlags=1,this._hasWater=!1,this._renderers=new Map,this._sortedDrapeSourceRenderersDirty=!1,this._sortedRenderers=new o,this._passParameters=new x,this._screenToWorldRatio=1,this._localOriginFactory=null,this.unloadedMemory=0,this.ignoresMemoryFactor=!1,this._camera=new w,this.events=new t,this.longitudeCyclical=null,this.produces=new Map([[19,e=>8!==e||this.hasHighlights],[20,()=>this._hasWater]]),this._hasTargetWithoutRasterImage=!1,this._hasDrapedFeatureSource=!1,this._hasDrapedRasterSource=!1,this._hasDrapedFlowSource=!1}initialize(){const e=this._view,r=e.stage,t=r.renderer.fboCache,{waterTextures:s,techniques:i}=r.renderView;this._renderContext=new C(this._rctx,new j(t,e.state.viewingMode),i);const n=this._bindParameters;this.addHandles([a(()=>s.updating,()=>this.events.emit("content-changed"),d),a(()=>this._spatialReference,e=>this._localOriginFactory=new D(e),d),h(()=>e.allLayerViews,"after-changes",()=>this._sortedDrapeSourceRenderersDirty=!0),a(()=>O(e.state.highlights),()=>this._sortedDrapeSourceRenderersDirty=!0,l),a(()=>e.state.highlights,r=>{n.highlights=r,n.highlightOrderMap=e.state.highlightOrderMap},l),e.resourceController.scheduler.registerTask(V.OVERLAY_RENDERER,this)]);const o=this._camera;o.near=1,o.far=1e4,o.relativeElevation=null,n.slot=19,n.camera=o,n.updateLighting([new F(y())],0,0,0)}destroy(){this._renderers.forEach(e=>e.destroy()),this._renderers.clear(),this._passParameters.texture=n(this._passParameters.texture),this.disposeOverlays(),this._renderContext=null,this._sortedRenderers.prune()}get _bindParameters(){return this._renderContext.bind}get _rctx(){return this._stage.renderView.renderingContext}get _view(){return this.parent.view}get _stage(){return this.parent.view.stage}get _spatialReference(){return this.parent.spatialReference}get _techniques(){return this._stage.renderView.techniques}get rctx(){return this._rctx}get materials(){return this._pluginContext.materials}get screenToWorldRatio(){return this._screenToWorldRatio}get localOriginFactory(){return this._localOriginFactory}get pluginContext(){return this._pluginContext}initializeRenderContext(e){const r=new b(this._view.stage.renderView.textures,this._techniques,()=>{this._onMaterialOrContentChanged(),this.events.emit("content-changed"),this.notifyChange("updating"),this.notifyChange("isEmpty")},()=>this.events.emit("content-changed"));this._pluginContext={...e,materials:r},this._techniques.precompile(q)}uninitializeRenderContext(){}acquireTechniques(){return[]}render(){}get updating(){return this._sortedDrapeSourceRenderersDirty||s(this._renderers,e=>e.updating||e.canCompact)}get hasOverlays(){return null!=this._overlays&&null!=this._renderTargets}getMaterialRenderer(e){for(const r of this._renderers.values()){const t=r.getMaterialRenderer(e);if(t)return t}return null}get layers(){return this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers(),r(this._sortedRenderers.map(e=>e.drapeSource.layer).filter(e=>!!e))}registerDrapeSource(e,r){const t=this._renderers.get(e);null!=t&&t.destroy(),this._renderers.set(e,r),this._sortedDrapeSourceRenderersDirty=!0,"fullOpacity"in e&&this.addHandles(a(()=>e.fullOpacity,()=>this.events.emit("content-changed")),e)}removeDrapeSourceRenderer(e){if(null==e)return;const r=this._renderers.get(e);null!=r&&(this._sortedDrapeSourceRenderersDirty=!0,this._renderers.delete(e),this.removeHandles(e),r.destroy())}computeValidity(){return this._renderTargets?.computeValidity()??0}releaseRenderTargets(e){this._renderTargets?.dispose(e)}get overlays(){return this._overlays??[]}ensureDrapeTargets(e){this._hasTargetWithoutRasterImage=!!this._overlays&&c(e,e=>1===e.drapeTargetType)}ensureDrapeSources(e){this._overlays?(this._hasDrapedFeatureSource=c(e,e=>1===e.drapeSourceType),this._hasDrapedRasterSource=c(e,e=>0===e.drapeSourceType),this._hasDrapedFlowSource=c(e,e=>2===e.drapeSourceType)):this._hasDrapedFeatureSource=this._hasDrapedRasterSource=this._hasDrapedFlowSource=!1}get _needsColorWithoutRasterImage(){return this._hasDrapedRasterSource&&this._hasDrapedFeatureSource&&this._hasTargetWithoutRasterImage}ensureOverlays(e,r,t=this._bindParameters.overlayStretch){null==this._overlays&&(this._renderTargets=new v(this._stage.renderer.fboCache),this._overlays=[new R,new R]),this.ensureDrapeTargets(e),this.ensureDrapeSources(r),this._bindParameters.overlayStretch=t}disposeOverlays(){this._overlays=null,this._renderTargets?.dispose(1),this._renderTargets=null,this.events.emit("textures-disposed")}_useOverlayColorInsteadOfColorNoRasterImage(e){return 1===e&&!this._needsColorWithoutRasterImage&&this._hasDrapedFeatureSource}getTexture(e){const r=this._useOverlayColorInsteadOfColorNoRasterImage(e);return this._renderTargets?.getTexture(r?0:e)}get readyToRun(){return this.updating}runTask(e){this._processDrapeSources(e,()=>!0)}_onMaterialOrContentChanged(){this.renderOccludedFlags=s(this._renderers,e=>e.hasOccluders)?L:1}_processDrapeSources(e,r){let t=!1;for(const[s,i]of this._renderers){if(e.done)break;(s.destroyed||r(s))&&(i.commitChanges()&&(t=!0,e.madeProgress()))}this._sortedDrapeSourceRenderersDirty&&(this._sortedDrapeSourceRenderersDirty=!1,t=!0,this._updateSortedDrapeSourceRenderers(),e.madeProgress()),this.compact(e),t&&(null!=this._overlays&&0===this._renderers.size&&this.disposeOverlays(),this.notifyChange("updating"),this.notifyChange("isEmpty"),this._onMaterialOrContentChanged(),this.hasHighlights=s(this._renderers,e=>e.hasHighlights),this.events.emit("content-changed"))}compact(e){let r=!1;for(const t of this._renderers.values()){if(e.done)break;r=t.compact(e)||r}return r&&this.notifyChange("updating"),r}hasHighlight(e){return s(this._renderers,r=>r.hasHighlight(e))}processSyncDrapeSources(){this._processDrapeSources(A,e=>1===e.updatePolicy)}get isEmpty(){return!f.OVERLAY_DRAW_DEBUG_TEXTURE&&i(this._renderers,e=>e.isEmpty)}get hasWater(){const e=s(this._renderers,({hasWater:e})=>e);return e!==this._hasWater&&(this._hasWater=e,this.events.emit("has-water")),this._hasWater}renders(e){if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==e&&2!==e)return!0;if(!this._overlays)return!1;const r=this._overlays[0];for(const i of this._overlays)i.setupGeometryViews(this.longitudeCyclical);if(!r.hasSomeSizedView())return!1;const t=this._setOutput(this._renderTargets?.targets.find(r=>r.content===e)?.output??0);++this._techniques.precompiling;const s=this._sortedRenderers.some(({renderer:e})=>e.precompile(this._renderContext));return--this._techniques.precompiling,this._setOutput(t),s}_setOutput(e){const r=this._renderContext.output;return this._renderContext.output=e,this._bindParameters.slot=2===e?20:19,r}get mode(){return this.isEmpty?0:this.hasWater&&this.renders(3)?2:this._renderTargets?.getTexture(0)?1:0}updateAnimation(e){let r=!1;return this._renderers.forEach(t=>r=t.updateAnimation(e)||r),r&&this.parent.requestRender(0),r}updateDrapeSourceOrder(){this._sortedDrapeSourceRenderersDirty=!0}precompileShaders(e){if(!this._overlays||!this._renderTargets)return!1;const r=this._bindParameters;r.alignPixelEnabled=e.alignPixelEnabled,++this._techniques.precompiling;for(const t of this._renderTargets.targets){if(1===t.content&&!this._needsColorWithoutRasterImage)continue;const{output:e}=t;this._setOutput(e),8===e&&(r.highlightMixTexture=r.highlights.length>1?this._rctx.emptyTexture:null);const s=this._renderContext.renderOccludedMask;4===t.content&&(this._renderContext.renderOccludedMask=L),this._sortedRenderers.forAll(({drapeSource:e,renderer:r})=>{1===t.content&&0===e.drapeSourceType||4===t.content&&r.hasOnlyOccluders||r.precompile(this._renderContext)}),this._renderContext.renderOccludedMask=s,r.highlightMixTexture=null}return--this._techniques.precompiling,!0}drawOverlays(e,r){if(!this._overlays||!this._renderTargets)return;for(const s of this._overlays)s.setupGeometryViews(this.longitudeCyclical);this._bindParameters.alignPixelEnabled=e.alignPixelEnabled;const t=this.allSourcesOccluders;for(const s of this._renderTargets.targets){if(!(0===s.content&&this._hasDrapedFlowSource)&&!s.handleRenderRequest(r)||1===s.content&&!this._needsColorWithoutRasterImage||4===s.content&&t)continue;const e=this._drawTarget(0,s),i=this._drawTarget(1,s);(e||i)&&s.fbo.generateMipMap()}}_drawTarget(e,r){const t=this._overlays[e],s=t.canvasGeometries;if(0===s.numViews)return!1;const i=this._view.state.contentPixelRatio;this._screenToWorldRatio=i*t.mapUnitsPerPixel/this._bindParameters.overlayStretch;const{output:n,content:o}=r;if(this.isEmpty||2===n&&!this.hasWater||!t.hasSomeSizedView())return!1;const{_rctx:a,_camera:h,_renderContext:d,_bindParameters:l}=this;if(h.pixelRatio=t.pixelRatio*i,this._setOutput(n),l.screenToWorldRatio=this._screenToWorldRatio,l.screenToPCSRatio=this._screenToWorldRatio*this.parent.worldToPCSRatio,4===o&&(d.renderOccludedMask=L),!this.renders(o))return d.renderOccludedMask=P,!1;const{resolution:c}=t,u=0===e,p=u?0:c;a.setViewport(p,0,c,c),this._bindTargetFBO(r),u&&(8===n?a.gl.clearBufferuiv(a.gl.COLOR,0,[0,0,0,0]):(a.setClearColor(0,0,0,0),a.clear(16384)));if(f.OVERLAY_DRAW_DEBUG_TEXTURE&&4!==o&&2!==o){this._techniques.precompile(E,z);const r=this._techniques.get(E,z);for(let i=0;i<s.numViews;i++)this._setViewParameters(s.extents[i],t),this._ensureDebugPatternResources(t.resolution,B[e]),a.bindTechnique(r,l,this._passParameters),a.screen.draw()}if(8===n){const{fboCache:t}=this._stage.renderer,s=this._resolution;this._bindTargetFBO(r),S(a,t,{width:s,height:s},l,()=>this._renderAllGeometry(e,r),p)}else this._renderAllGeometry(e,r);return a.bindFramebuffer(null),d.renderOccludedMask=P,!0}get allSourcesOccluders(){return i(this._renderers,e=>e.hasOnlyOccluders)}_renderAllGeometry(e,r){const t=this._overlays[e],s=t.canvasGeometries;this._sortedRenderers.forAll(({drapeSource:i,renderer:n})=>{if(1===r.content&&0===i.drapeSourceType)return;const{fullOpacity:o}=i,a=null!=o&&o<1&&0===r.output&&this._bindTemporaryFBO();for(let e=0;e<s.numViews;e++)this._setViewParameters(s.extents[e],t),n.render(this._renderContext);if(a){this._bindTargetFBO(r),this._overlayParameters.texture=a.getTexture(),this._overlayParameters.opacity=o,this._overlayParameters.overlayIndex=e;const t=this._techniques.get(q);this._rctx.bindTechnique(t,this._bindParameters,this._overlayParameters),this._rctx.screen.draw(),a.release()}})}_bindTargetFBO(e){const r=this._resolution,t=2*r;e.fbo.ensureFramebuffer(t,r),e.fbo.bind(this._rctx)}_bindTemporaryFBO(){const e=this._resolution,r=2*e,t=this._stage.renderer.fboCache,s=t.acquire(r,e,"overlay tmp");return t.rctx.bindFramebuffer(s.fbo),t.rctx.clear(16384),s}get _resolution(){return this._overlays?.[0].resolution??0}notifyContentChanged(){this.events.emit("content-changed")}intersect(e,r,t,s){this._sortedDrapeSourceRenderersDirty&&this._updateSortedDrapeSourceRenderers();let i=0;for(const{renderer:n}of this._sortedRenderers)i=n.intersect?.(e,r,t,s,i)??i}_updateSortedDrapeSourceRenderers(){if(this._sortedRenderers.clear(),0===this._renderers.size)return;const e=this._view.map.allLayers.map(e=>e.uid),r=e.length;this._renderers.forEach((t,s)=>{const i=e.indexOf(s.layer?.uid),n=i>=0,o=s.renderGroup??(n?0:1),a=s.drapeSourcePriorityOffset??0,h=r*o+(n?i:0)+a;this._sortedRenderers.push(new U(s,t,h))}),this._sortedRenderers.sort((e,r)=>e.index-r.index)}_setViewParameters(e,r){const t=this._camera;t.viewport=[0,0,r.resolution,r.resolution],_(t.projectionMatrix,0,e[2]-e[0],0,e[3]-e[1],t.near,t.far),g(t.viewMatrix,[-e[0],-e[1],0])}_ensureDebugPatternResources(e,r){if(m(this._passParameters.color,r[0],r[1],r[2]),this._passParameters.texture)return;const t=new Uint8Array(e*e*4);let s=0;for(let n=0;n<e;n++)for(let r=0;r<e;r++){const i=Math.floor(r/10),o=Math.floor(n/10);i<2||o<2||10*i>e-20||10*o>e-20?(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=255):(t[s++]=255,t[s++]=255,t[s++]=255,t[s++]=1&i&&1&o?1&r^1&n?0:255:1&i^1&o?0:128)}const i=new G(e);i.samplingMode=9728,this._passParameters.texture=new k(this._rctx,i,t)}get test(){}};e([u()],I.prototype,"hasHighlights",void 0),e([u()],I.prototype,"renderOccludedFlags",void 0),e([u()],I.prototype,"_sortedDrapeSourceRenderersDirty",void 0),e([u({constructOnly:!0})],I.prototype,"parent",void 0),e([u({readOnly:!0})],I.prototype,"_techniques",null),e([u({type:Boolean,readOnly:!0})],I.prototype,"updating",null),e([u()],I.prototype,"isEmpty",null),I=e([p("esri.views.3d.terrain.OverlayRenderer")],I);class U{constructor(e,r,t){this.drapeSource=e,this.renderer=r,this.index=t}}const B=[[1,.5,.5],[.5,.5,1]],H=-2,L=4,z=new M;z.hasAlpha=!0;export{I as OverlayRenderer,H as drapedZ,L as overlayRenderOccludedFlag};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r,releaseMaybe as i}from"../../../core/maybe.js";import{D as s,H as o,B as a,e as n,n as l,g as d,a as g,G as h}from"../../../chunks/vec32.js";import{create as u,clone as m}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{containsXY as c}from"../../../geometry/support/aaBoundingRect.js";import{earth as f}from"../../../geometry/support/Ellipsoid.js";import{glLayout as p}from"../support/buffer/glUtil.js";import{GeometryState as y}from"./GeometryState.js";import{PatchGeometry as x}from"./PatchGeometry.js";import{maxTileNeighborLevelDelta as _}from"./TerrainConst.js";import{internalAssert as v,neighborEdgeIndices as $,oppositeEdge as E,neighborCornerIndices as C,enableTerrainInternalChecks as S,v32s as D,lij2s as b}from"./terrainUtils.js";import{TextureFader as j}from"./TextureFader.js";import{TextureReference as R}from"./TextureReference.js";import V from"./TileOverlayData.js";import{fallsWithinLayerView as T}from"./tileUtils.js";import{VertexArrayObject as w}from"../webgl-engine/lib/VertexArrayObject.js";import{BufferObject as A}from"../../webgl/BufferObject.js";import{VertexBuffer as P}from"../../webgl/VertexBuffer.js";class N{constructor(){this.geometry=new x,this.geometryState=null,this._texture=null,this._textureOpacity=1,this._textureRef=new j(()=>this._tile.surface.fadeDuration),this.overlay=new V,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new y,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureRef.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),S&&this.tile.intersectsClippingArea)for(let t=0;t<4;++t)v(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.groundExtent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,o=$[e];if(!t)return v(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(o)),i;if(t.loaded){const r=t,o=r.renderData.geometryState,a=s-r.level;if(v(a>=0),0===a){const e=o.numVerticesPerSide-1;return Math.max(e,i)}const n=2**a,l=o.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}v(!t.leaf);let a=i;return t.forAllSubtreeOnSide(E(o),e=>e===r||(e.loaded?(a=Math.max(a,2**(e.level-s)),!0):(v(!e.leaf),!1))),a}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.loaded||t.level===e.level)&&t?.intersectsClippingArea,s=r.edgePeerNeighbors,o=r.edgePeerNeighborSamplerVersions;for(let a=0;a<4;++a){const n=e.findNeighborTile($[a],i),l=X(e,n),d=l?.renderData?.geometryState.samplerDataVersion??-1,g=s[a],h=l!==X(e,g),u=o[a]!==d;S&&n&&(v(e.level>=n.level),v(e.level-n.level<=_)),s[a]=n,(h||u)&&(o[a]=d,this._markEdgeDirty(a));const m=r.edgeResolutions[a],c=this._calculateEdgeResolution(a,n);v(t(c)),v(c>=1),r.edgeResolutions[a]=c,m!==c&&this._markEdgeResolutionDirty(a)}for(let t=0;t<4;++t){const o=e.findNeighborTile(C[t],i);r.cornerPeerNeighbors[t]=o;const a=X(e,s[t]),n=X(e,s[(t+1)%4]),l=X(e,o);L[t]=l,L[(t+1)%4]=n,L[(t+2)%4]=e,L[(t+3)%4]=a,v(L.some(t=>t?.loaded||t===e));const d=L.reduce((e,t)=>Math.min(e,t?.level??1/0),1/0);L.forEach((e,t)=>{e&&e?.level>d&&(L[t]=null)}),v(L.some(t=>t?.loaded||t===e));const g=r.cornerNeighborCornerTiles,h=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<4;++e){const r=L[e],i=r?.renderData.geometryState.samplerDataVersion??-1,s=4*t+e,o=g[s]!==r,a=!o&&h[s]!==i;(o||a)&&(g[s]=r,h[s]=i,this._markCornerDirty(t))}S&&v(Q.some(r=>g[4*t+r]?.loaded||g[4*t+r]===e))}S&&v(this.geometryState.edgeResolutions.every(e=>e>0));for(let t=0;t<4;++t)L[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;S&&v(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every(e=>e>0)),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,o=!r||!{}||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged||this.numVerticesPerSideChanged,a=0!==this.dirtyEdgeResolutions,n=s.edgeResolutions.reduce((e,t)=>e+t+1,0),l=o||a&&n>(i?.maxEdgeVertexCount??0),d=!l&&a,g=!d&&(0!==this.dirtyEdges||a),h=!g&&0!==this.dirtyCorners;l?(this.releaseGeometry(),this._createGeometry(e)):d?t.updateEdgeElevationsAndResolutions():g||h?t.updateEdgeElevations():h?t.updateCornerElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r,i){const s=t?6408:6407;return null!=this._texture&&(0===r&&this._tile.surface.fadeDuration>0&&this._isTextureVisible(this._texture)||this._texture.descriptor.width!==e||this._texture.descriptor.pixelFormat!==s)&&this.releaseTexture(),null==this._texture&&(this._texture=i(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){this._texture&&(this._texture=i(this._texture),this.tile.setMemoryDirty())}reuseTexture(e,t){return!(!e||!this._texture)&&(e.setTextureReference(new R(this._texture,0,t,this._textureOpacity,0,1)),!0)}get numVerticesPerSideChanged(){return 0!==(this._modifiedFlags&B)}get samplerDataChanged(){return 0!==(this._modifiedFlags&H)}get clippingAreaChanged(){return 0!==(this._modifiedFlags&W)}get wireframeChanged(){return 0!==(this._modifiedFlags&q)}get dirtyEdges(){return this._modifiedFlags>>z&15}get dirtyCorners(){return this._modifiedFlags>>J&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>K&15}_markCornerDirty(e){const t=1<<e<<J;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<z;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<K;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<J|15<<z|15<<K}updateGeometryState(){const t=this._elevationInfo,r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.minimumVerticesPerSide,s=Math.max(i,5);let o=r.clippingArea;r.intersectsClippingArea&&!r.withinClippingArea||(o=null);const a=this.geometryState;let n=!1;a.numVerticesPerSide!==s&&(this._modifiedFlags|=1,a.numVerticesPerSide=s,a.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=2,a.samplerData=t.samplerData,a.samplerDataVersion++,n=!0),e(a.clippingArea,o)||(this._modifiedFlags=4,a.clippingArea=o,n=!0);const l=r.surface.wireframe;return a.wireframe!==l&&(this._modifiedFlags=8,a.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const{vertexAttributes:t,indices:r}=this.geometry,i=e.gl;this._vao=new w(e,new P(e,p(t.layout),t.buffer),A.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=0){e?.texture===this._texture?this._textureOpacity=e.opacities[0]:this.releaseTexture(),this._textureRef.push(e,t)}get textureReference(){return this._textureRef.current}get nextTextureReference(){return this._textureRef.next}get textureFadeFactor(){return this._textureRef.fadeFactor}get textureIsFading(){return this._textureRef.isFading}_isTextureVisible(e){return this._textureRef.current?.texture===e||this._textureRef.next?.texture===e&&this._textureRef.fadeFactor<1}get _elevationInfo(){const e=this.geometryState.samplerData,t=this.tile.layerInfo[0],r=t.length,i=new Array(r);let s=0,o=0,a=!1;for(let d=0;d<r;d++){const r=t[d],n=r.upsampleInfo?.tile;if(n){const t=n.layerInfo[0][d].data,r=t&&t.samplerData;e&&e[s]===r||(a=!0),i[s++]=r,o=Math.max(o,n.lij[0])}else if(r.data){const t=this.tile.surface.layerViewByIndex(d,0);if(T(this.tile,t)){const t=r.data;e&&e[s]===t.samplerData||(a=!0),i[s++]=t.samplerData,o=this.tile.level}}}null!=e&&e.length!==s&&(a=!0);const n=s>0,l=n?i:null;return n&&(i.length=s),{changed:a,samplerData:l,maxTileLevel:o}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){}checkGeometryWaterproofness(){if(!S)return;const e=this.tile;if(!e.loaded||!e.intersectsClippingArea||0===e.level)return void v(e?.loaded);const r=e.surface.groundExtent;if(null!=r&&!e.intersectsExtent(r))return;const i=$.map((t,i)=>null!=r&&(i<2?-1:1)*(e.extent[3-i]-r[3-i])<0),p=e.level;v(0===this.dirtyCorners),v(0===this.dirtyEdges),v(0===this.dirtyEdgeResolutions),v(!this.numVerticesPerSideChanged),v(!this.samplerDataChanged),v(!this.clippingAreaChanged),v(!this.wireframeChanged);const y=C.map(t=>e.findNeighborCornerTileExact(t,t=>!t.intersectsClippingArea||t.loaded||t.level===e.level)??null).map(e=>e?.intersectsClippingArea?e:null),x=this.geometryState;for(let t=0;t<4;++t){const r=x.cornerPeerNeighbors[t],i=y[t];v(i===r,`Tile[${e.lij}].corner[${t}] out of date: cur=[${r?.lij}] exp=[${i?.lij}]`)}$.forEach((r,y)=>{if(i[y])return;const x=e.findNeighborTile(r,e=>(e.level===p||e?.loaded)&&e?.intersectsClippingArea);if(!x){const t=!e.surface.updatingRootTiles&&null!=e.surface.rootTiles&&e.surface.rootTiles.length>0&&e.shouldHaveNeighbor(r);return void v(!t)}v(x.loaded||x.level===e.level),v(x===this.geometryState.edgePeerNeighbors[y]);const _=p-x.level;if(!x.loaded)return v(!x.leaf),void v(0===_);const $=x.renderData;v(e.isEdgeNeighbor(x,r)),v(_>=0);const E=2**_;if(_<0)return void v(!1);const C=e.renderData,S=C.geometry,j=C.localOrigin,R=S.getEdgeCount(y),V=S.numVerticesPerSide-1,T=$.geometry;if(!T)return void v(!1);const w=$.localOrigin,A=this.geometryState.edgePeerNeighbors[y];if(A?.loaded){const e=A.renderData;v(C.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion),v(this.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion)}const P=(y+2)%4,N=T.getEdgeCount(P),L=R-1,X=N-1;v(L*E===X,`Tile[${e.lij}]:e${y},res=${L} edgeRes mismatch with Neighbor[${x.lij}]:e${P},res=${X} (expected:${L*E})`);const B=e.extent,H=0===r||4===r,W=N-1,q=W>>_,z=R-1;if(q<1)return void v(1===z);v(q===z),v(t(q));const J=T.numVerticesPerSide-1;v(_>0||q===Math.max(J,V));const K=e.getNeighborEdgeStartVertexIndex(y,x);v(0<=K&&K<E);const Q=K*q;v(0<=Q&&Q<=W-q);let Y=0,Z=Q;S.getEdgeVertexPosition(y,F,j,0),S.getEdgeVertexPosition(y,G,j,R-1);const ee=s(F,G),te=Math.max(I,1e-4*ee);for(let t=0;t<=q;++t){S.getEdgeVertexPosition(y,F,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=t/q,s=H?B[0]+i*(B[2]-B[0]):6===r?B[0]:B[2],p=H?4===r?B[1]:B[3]:B[1]+i*(B[3]-B[1]),_=e.surface.groundExtent;if(null==_||c(_,s,p)){const t=o(F,G),r=a(F)-f.radius,i=a(G)-f.radius,c=t<te;if(!c){console.warn(`Tile edge vertex position mismatch: between [${e.lij}].edge${y}[${Y}/${R}] and [${x.lij}].edge${P}[${Z}/${N}]`),null!=_&&console.warn(" surface extent= ",_," x,y=",s,",",p);const o=u();n(o,C.localOrigin,$.localOrigin),a(o)>0&&console.warn(` localOrigins: ${C.localOrigin} vs ${$.localOrigin} d=${a(o)} [${o}]`);(()=>{const t=m(F),r=m(G);e.updateEdgeElevations(),x.updateEdgeElevations(),S.getEdgeVertexPosition(y,F,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=u();g(i,F,t),a(i)>0&&console.warn(` XXX Tile[${e.lij}] edge out of date: ${t} vs ${F} d=${a(i)} [${i}]`),g(i,G,r),a(i)>0&&console.warn(` XXX Neighbor[${x.lij}] edge out of date: ${r} vs ${G} d=${a(i)} [${i}]`)})();const l=S.getEdgeCount(y),d=T.getEdgeCount(N);v(c,`Mismatch in tile [${e.lij}].edge[${y}][${Y}/${l}] vs neighbor [${x.lij}].edge[${P}][${Z}/${d}] ${D(F)} vs ${D(G)} dist=${t} h(t|n|d)=${r}|${i}|${i-r}`)}S.getEdgeNormal(y,O,Y),T.getEdgeNormal(P,M,Z),l(k,O),l(U,M);const E=d(k,U),V=1-E<.01||!1||e===x;if(!V){const t=u();g(t,O,M);const r=()=>`Mismatch in tile edge normal ${b(e.lij)} (${Y}/${R-1}) edge ${y} vs neighbor ${b(x.lij)} (${Z}/${N-1}) nedge ${P} :${D(O)} vs ${D(M)} dot = ${E} : ${D(t)}`;console.warn("Mismatch in tile edge normal: ",r());{e.updateEdgeElevations(),x.updateEdgeElevations();const t=u(),r=u();S.getEdgeNormal(y,t,Y),T.getEdgeNormal(P,r,Z),h(O,t)||console.warn("Missing update in tile normal: ",D(O)," => ",D(t)),h(M,r)||console.warn("Missing update in neighbor normal: ",D(M)," => ",D(r))}v(V,r())}}Y+=1,Z+=1}})}}const F=u(),G=u(),O=u(),M=u(),k=u(),U=u(),I=1,L=[null,null,null,null];function X(e,t){return t?.loaded||t===e?t:null}const B=1,H=2,W=4,q=8,z=4,J=8,K=12,Q=[0,1,2,3];export{N as PatchRenderData,X as neighborTileIfLoadedOrSelf,Q as zeroToFour};
5
+ import{equals as e}from"../../../core/arrayUtils.js";import"../../../core/has.js";import{isPowerOfTwo as t}from"../../../core/mathUtils.js";import{disposeMaybe as r,releaseMaybe as i}from"../../../core/maybe.js";import{C as s,G as o,H as a,e as n,n as l,g as d,a as g,F as h}from"../../../chunks/vec32.js";import{create as u,clone as m}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{containsXY as c}from"../../../geometry/support/aaBoundingRect.js";import{earth as f}from"../../../geometry/support/Ellipsoid.js";import{glLayout as p}from"../support/buffer/glUtil.js";import{GeometryState as y}from"./GeometryState.js";import{PatchGeometry as x}from"./PatchGeometry.js";import{maxTileNeighborLevelDelta as _}from"./TerrainConst.js";import{internalAssert as v,neighborEdgeIndices as $,oppositeEdge as E,neighborCornerIndices as C,enableTerrainInternalChecks as S,v32s as D,lij2s as b}from"./terrainUtils.js";import{TextureFader as j}from"./TextureFader.js";import{TextureReference as R}from"./TextureReference.js";import V from"./TileOverlayData.js";import{fallsWithinLayerView as T}from"./tileUtils.js";import{VertexArrayObject as w}from"../webgl-engine/lib/VertexArrayObject.js";import{BufferObject as A}from"../../webgl/BufferObject.js";import{VertexBuffer as P}from"../../webgl/VertexBuffer.js";class F{constructor(){this.geometry=new x,this.geometryState=null,this._texture=null,this._textureOpacity=1,this._textureRef=new j(()=>this._tile.surface.fadeDuration),this.overlay=new V,this._localOrigin=null,this._geometryStateChangedSinceLastUpdate=!0,this._hasGeometry=!1,this._modifiedFlags=0}get tile(){return this._tile}get localOrigin(){return this._localOrigin}init(e,t){this.clear(),this._tile=e,this.geometry.reset(),this.intersectionData=null,this.geometryState=new y,this._localOrigin=t,this.overlay.clear()}clear(){this.releaseGeometry(),this.releaseTexture(),this._textureRef.clear(),this._tile=null,this.intersectionData=null,this.geometryState=null}updateGeometryIfNeeded(e){if((!this._vao||this._geometryStateChangedSinceLastUpdate||this.wireframeChanged||this.clippingAreaChanged||this.samplerDataChanged||this.numVerticesPerSideChanged||this.dirtyCorners||this.dirtyEdgeResolutions||this.dirtyEdges)&&(this._updateGeometry(e),this._geometryStateChangedSinceLastUpdate=!1),S&&this.tile.intersectsClippingArea)for(let t=0;t<4;++t)v(this.geometry.getEdgeCount(t)===this.geometryState.edgeResolutions[t]+1)}_calculateEdgeResolution(e,t){const r=this.tile,i=this.geometryState.numVerticesPerSide-1;if(!r.surface.isGlobal){const t=r.surface.groundExtent;if(null!=t&&(0===e&&r.extent[3]>t[3]||1===e&&r.extent[2]>t[2]||2===e&&r.extent[1]<t[1]||3===e&&r.extent[0]<t[0]))return i}const s=r.level,o=$[e];if(!t)return v(null==r.surface?.rootTiles||r.surface.updatingRootTiles||!r.shouldHaveNeighbor(o)),i;if(t.loaded){const r=t,o=r.renderData.geometryState,a=s-r.level;if(v(a>=0),0===a){const e=o.numVerticesPerSide-1;return Math.max(e,i)}const n=2**a,l=o.edgeResolutions[(e+2)%4]/n;return Math.max(1,l)}v(!t.leaf);let a=i;return t.forAllSubtreeOnSide(E(o),e=>e===r||(e.loaded?(a=Math.max(a,2**(e.level-s)),!0):(v(!e.leaf),!1))),a}updateNeighborData(){const e=this.tile;if(!e.intersectsClippingArea)return;const r=e.renderData.geometryState,i=t=>(t.loaded||t.level===e.level)&&t?.intersectsClippingArea,s=r.edgePeerNeighbors,o=r.edgePeerNeighborSamplerVersions;for(let a=0;a<4;++a){const n=e.findNeighborTile($[a],i),l=X(e,n),d=l?.renderData?.geometryState.samplerDataVersion??-1,g=s[a],h=l!==X(e,g),u=o[a]!==d;S&&n&&(v(e.level>=n.level),v(e.level-n.level<=_)),s[a]=n,(h||u)&&(o[a]=d,this._markEdgeDirty(a));const m=r.edgeResolutions[a],c=this._calculateEdgeResolution(a,n);v(t(c)),v(c>=1),r.edgeResolutions[a]=c,m!==c&&this._markEdgeResolutionDirty(a)}for(let t=0;t<4;++t){const o=e.findNeighborTile(C[t],i);r.cornerPeerNeighbors[t]=o;const a=X(e,s[t]),n=X(e,s[(t+1)%4]),l=X(e,o);L[t]=l,L[(t+1)%4]=n,L[(t+2)%4]=e,L[(t+3)%4]=a,v(L.some(t=>t?.loaded||t===e));const d=L.reduce((e,t)=>Math.min(e,t?.level??1/0),1/0);L.forEach((e,t)=>{e&&e?.level>d&&(L[t]=null)}),v(L.some(t=>t?.loaded||t===e));const g=r.cornerNeighborCornerTiles,h=r.cornerNeighborCornerTileSamplerVersions;for(let e=0;e<4;++e){const r=L[e],i=r?.renderData.geometryState.samplerDataVersion??-1,s=4*t+e,o=g[s]!==r,a=!o&&h[s]!==i;(o||a)&&(g[s]=r,h[s]=i,this._markCornerDirty(t))}S&&v(Q.some(r=>g[4*t+r]?.loaded||g[4*t+r]===e))}S&&v(this.geometryState.edgeResolutions.every(e=>e>0));for(let t=0;t<4;++t)L[t]=null}_updateGeometry(e){if(!this.tile.intersectsClippingArea)return;S&&v(!this.tile.intersectsClippingArea||this.geometryState.edgeResolutions.every(e=>e>0)),this.intersectionData=null;const{tile:t,_vao:r,geometry:i,geometryState:s}=this,o=!r||!{}||this.wireframeChanged||this.samplerDataChanged||this.clippingAreaChanged||this.numVerticesPerSideChanged,a=0!==this.dirtyEdgeResolutions,n=s.edgeResolutions.reduce((e,t)=>e+t+1,0),l=o||a&&n>(i?.maxEdgeVertexCount??0),d=!l&&a,g=!d&&(0!==this.dirtyEdges||a),h=!g&&0!==this.dirtyCorners;l?(this.releaseGeometry(),this._createGeometry(e)):d?t.updateEdgeElevationsAndResolutions():g||h?t.updateEdgeElevations():h?t.updateCornerElevations():console.warn("Update for no reason?"),this._modifiedFlags=0}get hasGeometry(){return this._hasGeometry}releaseGeometry(){return this._hasGeometry=!1,this.intersectionData=null,!!this._vao&&(this._vao=r(this._vao),this.geometry.release(),!0)}ensureTexture(e,t,r,i){const s=t?6408:6407;return null!=this._texture&&(0===r&&this._tile.surface.fadeDuration>0&&this._isTextureVisible(this._texture)||this._texture.descriptor.width!==e||this._texture.descriptor.pixelFormat!==s)&&this.releaseTexture(),null==this._texture&&(this._texture=i(),this.tile.setMemoryDirty()),this._texture}releaseTexture(){this._texture&&(this._texture=i(this._texture),this.tile.setMemoryDirty())}reuseTexture(e,t){return!(!e||!this._texture)&&(e.setTextureReference(new R(this._texture,0,t,this._textureOpacity,0,1)),!0)}get numVerticesPerSideChanged(){return 0!==(this._modifiedFlags&B)}get samplerDataChanged(){return 0!==(this._modifiedFlags&H)}get clippingAreaChanged(){return 0!==(this._modifiedFlags&W)}get wireframeChanged(){return 0!==(this._modifiedFlags&q)}get dirtyEdges(){return this._modifiedFlags>>z&15}get dirtyCorners(){return this._modifiedFlags>>J&15}get dirtyEdgeResolutions(){return this._modifiedFlags>>K&15}_markCornerDirty(e){const t=1<<e<<J;this._modifiedFlags|=t}_markEdgeDirty(e){const t=1<<e<<z;this._modifiedFlags|=t,this._markCornerDirty((e+0)%4),this._markCornerDirty((e+3)%4)}_markEdgeResolutionDirty(e){const t=1<<e<<K;this._modifiedFlags|=t,this._markEdgeDirty(e)}_markAllEdgesAndCornersDirty(){this._modifiedFlags|=15<<J|15<<z|15<<K}updateGeometryState(){const t=this._elevationInfo,r=this.tile,i=t.samplerData?r.getElevationVerticesPerSide(t.maxTileLevel):r.minimumVerticesPerSide,s=Math.max(i,5);let o=r.clippingArea;r.intersectsClippingArea&&!r.withinClippingArea||(o=null);const a=this.geometryState;let n=!1;a.numVerticesPerSide!==s&&(this._modifiedFlags|=1,a.numVerticesPerSide=s,a.samplerDataVersion++,n=!0),t.changed&&(this._modifiedFlags|=2,a.samplerData=t.samplerData,a.samplerDataVersion++,n=!0),e(a.clippingArea,o)||(this._modifiedFlags=4,a.clippingArea=o,n=!0);const l=r.surface.wireframe;return a.wireframe!==l&&(this._modifiedFlags=8,a.wireframe=l,n=!0),this._geometryStateChangedSinceLastUpdate||=n,n&&this._markAllEdgesAndCornersDirty(),this._hasGeometry=!0,this._geometryStateChangedSinceLastUpdate}_createGeometry(e){this.tile.createGeometry();const{vertexAttributes:t,indices:r}=this.geometry,i=e.gl;this._vao=new w(e,new P(e,p(t.layout),t.buffer),A.createIndex(e,i.STATIC_DRAW,r)),this._hasGeometry=!0}get vao(){return this._vao}setTextureReference(e,t=0){e?.texture===this._texture?this._textureOpacity=e.opacities[0]:this.releaseTexture(),this._textureRef.push(e,t)}get textureReference(){return this._textureRef.current}get nextTextureReference(){return this._textureRef.next}get textureFadeFactor(){return this._textureRef.fadeFactor}get textureIsFading(){return this._textureRef.isFading}_isTextureVisible(e){return this._textureRef.current?.texture===e||this._textureRef.next?.texture===e&&this._textureRef.fadeFactor<1}get _elevationInfo(){const e=this.geometryState.samplerData,t=this.tile.layerInfo[0],r=t.length,i=new Array(r);let s=0,o=0,a=!1;for(let d=0;d<r;d++){const r=t[d],n=r.upsampleInfo?.tile;if(n){const t=n.layerInfo[0][d].data,r=t&&t.samplerData;e&&e[s]===r||(a=!0),i[s++]=r,o=Math.max(o,n.lij[0])}else if(r.data){const t=this.tile.surface.layerViewByIndex(d,0);if(T(this.tile,t)){const t=r.data;e&&e[s]===t.samplerData||(a=!0),i[s++]=t.samplerData,o=this.tile.level}}}null!=e&&e.length!==s&&(a=!0);const n=s>0,l=n?i:null;return n&&(i.length=s),{changed:a,samplerData:l,maxTileLevel:o}}get estimatedGeometryMemoryUsage(){const e=this.intersectionData?.estimatedMemoryUsage??0;return(this.geometry.indices?.byteLength??0)+(this.geometry.vertexAttributes?.byteLength??0)+e}get texture(){return this._texture}get test(){}checkGeometryWaterproofness(){if(!S)return;const e=this.tile;if(!e.loaded||!e.intersectsClippingArea||0===e.level)return void v(e?.loaded);const r=e.surface.groundExtent;if(null!=r&&!e.intersectsExtent(r))return;const i=$.map((t,i)=>null!=r&&(i<2?-1:1)*(e.extent[3-i]-r[3-i])<0),p=e.level;v(0===this.dirtyCorners),v(0===this.dirtyEdges),v(0===this.dirtyEdgeResolutions),v(!this.numVerticesPerSideChanged),v(!this.samplerDataChanged),v(!this.clippingAreaChanged),v(!this.wireframeChanged);const y=C.map(t=>e.findNeighborCornerTileExact(t,t=>!t.intersectsClippingArea||t.loaded||t.level===e.level)??null).map(e=>e?.intersectsClippingArea?e:null),x=this.geometryState;for(let t=0;t<4;++t){const r=x.cornerPeerNeighbors[t],i=y[t];v(i===r,`Tile[${e.lij}].corner[${t}] out of date: cur=[${r?.lij}] exp=[${i?.lij}]`)}$.forEach((r,y)=>{if(i[y])return;const x=e.findNeighborTile(r,e=>(e.level===p||e?.loaded)&&e?.intersectsClippingArea);if(!x){const t=!e.surface.updatingRootTiles&&null!=e.surface.rootTiles&&e.surface.rootTiles.length>0&&e.shouldHaveNeighbor(r);return void v(!t)}v(x.loaded||x.level===e.level),v(x===this.geometryState.edgePeerNeighbors[y]);const _=p-x.level;if(!x.loaded)return v(!x.leaf),void v(0===_);const $=x.renderData;v(e.isEdgeNeighbor(x,r)),v(_>=0);const E=2**_;if(_<0)return void v(!1);const C=e.renderData,S=C.geometry,j=C.localOrigin,R=S.getEdgeCount(y),V=S.numVerticesPerSide-1,T=$.geometry;if(!T)return void v(!1);const w=$.localOrigin,A=this.geometryState.edgePeerNeighbors[y];if(A?.loaded){const e=A.renderData;v(C.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion),v(this.geometryState.edgePeerNeighborSamplerVersions[y]===e.geometryState.samplerDataVersion)}const P=(y+2)%4,F=T.getEdgeCount(P),L=R-1,X=F-1;v(L*E===X,`Tile[${e.lij}]:e${y},res=${L} edgeRes mismatch with Neighbor[${x.lij}]:e${P},res=${X} (expected:${L*E})`);const B=e.extent,H=0===r||4===r,W=F-1,q=W>>_,z=R-1;if(q<1)return void v(1===z);v(q===z),v(t(q));const J=T.numVerticesPerSide-1;v(_>0||q===Math.max(J,V));const K=e.getNeighborEdgeStartVertexIndex(y,x);v(0<=K&&K<E);const Q=K*q;v(0<=Q&&Q<=W-q);let Y=0,Z=Q;S.getEdgeVertexPosition(y,N,j,0),S.getEdgeVertexPosition(y,G,j,R-1);const ee=s(N,G),te=Math.max(I,1e-4*ee);for(let t=0;t<=q;++t){S.getEdgeVertexPosition(y,N,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=t/q,s=H?B[0]+i*(B[2]-B[0]):6===r?B[0]:B[2],p=H?4===r?B[1]:B[3]:B[1]+i*(B[3]-B[1]),_=e.surface.groundExtent;if(null==_||c(_,s,p)){const t=o(N,G),r=a(N)-f.radius,i=a(G)-f.radius,c=t<te;if(!c){console.warn(`Tile edge vertex position mismatch: between [${e.lij}].edge${y}[${Y}/${R}] and [${x.lij}].edge${P}[${Z}/${F}]`),null!=_&&console.warn(" surface extent= ",_," x,y=",s,",",p);const o=u();n(o,C.localOrigin,$.localOrigin),a(o)>0&&console.warn(` localOrigins: ${C.localOrigin} vs ${$.localOrigin} d=${a(o)} [${o}]`);(()=>{const t=m(N),r=m(G);e.updateEdgeElevations(),x.updateEdgeElevations(),S.getEdgeVertexPosition(y,N,j,Y),T.getEdgeVertexPosition(P,G,w,Z);const i=u();g(i,N,t),a(i)>0&&console.warn(` XXX Tile[${e.lij}] edge out of date: ${t} vs ${N} d=${a(i)} [${i}]`),g(i,G,r),a(i)>0&&console.warn(` XXX Neighbor[${x.lij}] edge out of date: ${r} vs ${G} d=${a(i)} [${i}]`)})();const l=S.getEdgeCount(y),d=T.getEdgeCount(F);v(c,`Mismatch in tile [${e.lij}].edge[${y}][${Y}/${l}] vs neighbor [${x.lij}].edge[${P}][${Z}/${d}] ${D(N)} vs ${D(G)} dist=${t} h(t|n|d)=${r}|${i}|${i-r}`)}S.getEdgeNormal(y,O,Y),T.getEdgeNormal(P,M,Z),l(k,O),l(U,M);const E=d(k,U),V=1-E<.01||!1||e===x;if(!V){const t=u();g(t,O,M);const r=()=>`Mismatch in tile edge normal ${b(e.lij)} (${Y}/${R-1}) edge ${y} vs neighbor ${b(x.lij)} (${Z}/${F-1}) nedge ${P} :${D(O)} vs ${D(M)} dot = ${E} : ${D(t)}`;console.warn("Mismatch in tile edge normal: ",r());{e.updateEdgeElevations(),x.updateEdgeElevations();const t=u(),r=u();S.getEdgeNormal(y,t,Y),T.getEdgeNormal(P,r,Z),h(O,t)||console.warn("Missing update in tile normal: ",D(O)," => ",D(t)),h(M,r)||console.warn("Missing update in neighbor normal: ",D(M)," => ",D(r))}v(V,r())}}Y+=1,Z+=1}})}}const N=u(),G=u(),O=u(),M=u(),k=u(),U=u(),I=1,L=[null,null,null,null];function X(e,t){return t?.loaded||t===e?t:null}const B=1,H=2,W=4,q=8,z=4,J=8,K=12,Q=[0,1,2,3];export{F as PatchRenderData,X as neighborTileIfLoadedOrSelf,Q as zeroToFour};
@@ -2,4 +2,4 @@
2
2
  All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/5.0/esri/copyright.txt for details.
4
4
  */
5
- import{lerp as t}from"../../../core/mathUtils.js";import{n as e,h as i,i as s,j as n,B as o,f as r,g as a,H as l,a as h}from"../../../chunks/vec32.js";import{ZEROS as u,create as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lonLatToSphericalPCPF as d}from"../../../geometry/projection/lonLatToSphericalPCPF.js";import{newDoubleArray as p}from"../../../geometry/support/DoubleArray.js";import{intersectsSphere as f,numPlanes as m}from"../../../geometry/support/frustum.js";import{Sphere as g}from"../../../geometry/support/sphere.js";import{createSphericalGlobePatch as x,updateCornerSpherical as $,updateEdgesAndCornersSpherical as v,updateEdgeElevationsAndResolutionsSpherical as M}from"./PatchGeometryFactory.js";import{enableTerrainInternalChecks as _,internalAssert as b,almostEquals as j}from"./terrainUtils.js";import{Tile as y}from"./Tile.js";import{compareTilesByLij as B}from"./tileUtils.js";class S extends y{constructor(t,e,i,s,n){super(),this._convexHull=new Array(24),this._boundingSphere=new g,this._baseUsedMemory=1816,this.init(t,e,i,s,n)}init(i,s,n,o,r){super.init(i,s,n,o,r);const a=this.ellipsoid.radius,l=this.extentInRadians[0],h=this.extentInRadians[1],u=this.extentInRadians[2],c=this.extentInRadians[3],p=t(h,c,.5),f=t(l,u,.5),m=0===i?0:Math.min(Math.abs(h),Math.abs(c));this._edgeLen=(u-l)*Math.cos(m)*a,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=a-Math.sqrt(a*a-this._edgeLen2/4),d(this.centerAtSeaLevel,f,p,this.ellipsoid.radius),e(this.up,this.centerAtSeaLevel),this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateBoundingVolumes();const t=this._center;if(0===this.lij[0])t[1].center=u,i(t[0],0,0,0),i(t[2],0,0,0),t[1].radius=this.ellipsoid.radius+this.elevationBoundsMax;else{this._updateCenter();const e=t[1],i=this.convexHull;let s=0;const n=e.center;for(let t=0;t<8;++t)s=Math.max(s,H(n,i,3*t));t[1].radius=Math.sqrt(s)}}_calculateFrustumVisibility(t){if(!f(t,this._boundingSphere))return 2;if(this.lij[0]<10)return 1;const e=this.convexHull,i=this.surface.view.state.camera.near;let s=!0;for(let n=0;n<m;n++){const o=4===n,r=t[n],a=r[0],l=r[1],h=r[2],u=r[3]-(o?i:0);let c=!1;for(let t=0;t<8;++t){const i=3*t;if(a*e[i]+l*e[i+1]+h*e[i+2]+u<0){if(c=!0,!s)break}else s=!1}if(!c)return 2}return s?0:1}computeElevationBounds(){super.computeElevationBounds(),this._updateBoundingVolumes()}createGeometry(){x(this.renderData,this._getPatchType()),this._updateBoundingVolumes(),this.setMemoryDirty()}_updateBoundingVolumes(){this._updateConvexHull(),this._updateBoundingSphere(),_&&this._checkBVs()}_updateBoundingSphere(){const t=this._boundingSphere,e=this.elevationBoundsMin,i=this.elevationBoundsMax,r=this.ellipsoid.radius,a=i;if(0===this.level)t.center=u,t.radius=r+a;else{const a=this.extentInRadians,l=.5*(a[0]+a[2]),h=a[1],u=a[3];T(I,l,h,r),T(L,l,u,r),s(t.center,I,L);const c=r+.5*(e+i);n(t.center,t.center,c/o(t.center));const d=this.convexHull;let p=0;const f=(t,e)=>{const i=t[0]-d[3*e],s=t[1]-d[3*e+1],n=t[2]-d[3*e+2];return Math.sqrt(i*i+s*s+n*n)};for(let e=0;e<8;++e){const i=f(t.center,e);p=Math.max(p,i)}const m=p;t.radius=m+2}}_updateConvexHull(){const t=this.extentInRadians,i=this.ellipsoid.radius;if(0===this.level)return;const l=this.elevationBoundsMin,u=this.elevationBoundsMax,d=this._getPatchType(),p=this.surface.isWebMercator,f=p&&1===d,m=p&&2===d,g=m||f,x=Math.PI/2,$=t[0],v=t[2],M=m?-x:t[1],_=f?x:t[3],y=.5*($+v),B=l,S=i+(g?Math.min(0,B-1):B),V=(t,e,i)=>T(t,e,i,S),H=c(),R=c(),I=c(),L=c();V(H,$,M),V(R,$,_),V(I,v,_),V(L,v,M);const P=(t,e)=>{for(let i=0;i<3;++i)this._convexHull[3*e+i]=t[i]};P(H,0),P(R,1),P(I,2),P(L,3);const F=u,A=i+(g?Math.max(0,F+1):F),k=c(),D=c(),E=c();T(D,y,_,S),T(E,y,M,S),s(k,D,E),e(k,k);const w=c(),U=c(),q=(t,i)=>{h(U,t,i),e(U,U);const o=-a(t,w)/a(U,w);b(o>=0),n(U,U,o),s(t,t,U)};if(2**this.lij[0]>2*this.lij[1]){const t=E,i=c();r(i,C,t),e(i,i),r(w,t,i),e(w,w),b(j(a(w,t)/o(t),0)),q(H,R),q(L,I),P(H,0),P(L,3)}else if(2**this.lij[0]!==2*this.lij[1]){const t=D,i=c();r(i,C,t),e(i,i),r(w,i,t),e(w,w),q(R,H),q(I,L),P(R,1),P(I,2)}const N=(t,e)=>{const i=A/a(e,k);for(let s=0;s<3;++s)this._convexHull[3*t+s]=e[s]*i};N(4,H),N(5,R),N(6,I),N(7,L)}_getPatchType(){const t=this.lij[1],e=0===t,i=t===(1<<this.level)-1;return e?i?3:1:i?2:0}intersectsRay(t,e,i,s){const n=this._boundingSphere,o=n.radius+i,r=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],a=n.center[0]-t[0],l=n.center[1]-t[1],h=n.center[2]-t[2],u=(a*e[0]+l*e[1]+h*e[2])/r,c=e[0]*u-a,d=e[1]*u-l,p=e[2]*u-h;return c*c+d*d+p*p<o*o}get minimumVerticesPerSide(){return this.level<V.length?V[this.level]+1:2}updateCornerElevations(){$(this.renderData),this._updateBoundingVolumes()}updateEdgeElevations(){v(this.renderData),this._updateBoundingVolumes()}updateEdgeElevationsAndResolutions(){M(this.renderData),this._updateBoundingVolumes()}_checkBVs(){if(!_)return;if(this.level<=2)return;const t=this._boundingSphere,i=t.radius,n=t.center,u=c(),d=this.ellipsoid.radius,f=this.elevationBoundsMin,m=this.elevationBoundsMax,g=d+f,x=1,$=0,v=this._center[1];v.center;const M=v.radius,y=this.convexHull,S=(t,e)=>{for(let i=0;i<3;++i)t[i]=y[3*e+i]};{const t=c(),i=c(),s=c(),n=c(),o=c(),l=(l,u,c,d)=>{S(i,l),S(s,u),S(n,c),h(i,i,s),h(n,n,s),r(t,i,n),e(t,t);const p=a(t,s);S(o,d);const f=a(t,o),m=Math.abs(f-p);b(j(m,0),`Non coplanar ${l},${u},${c},${d} diff = ${m}`)};l(0,1,2,3),l(4,5,6,7),l(0,1,4,5),l(1,2,5,6),l(2,3,6,7),l(3,0,7,4)}const V=p(24),H=(t,e,i)=>{const s=4*t;for(let n=0;n<3;++n)V[s+n]=e[n];V[s+3]=i},C=c(),I=c(),L=c(),P=c(),F=(t,i,s,n)=>{S(C,i),S(I,s),S(L,n),h(C,C,I),e(C,C),h(L,L,I),e(L,L),r(P,C,L),e(P,P);const o=a(P,I);H(t,P,o)};F(0,0,1,2),F(1,1,0,4),F(2,1,5,2),F(3,3,2,6),F(4,4,0,3),F(5,4,6,5);const A=(t,e,i,s)=>{const n=4*t;return V[n]*e+V[n+1]*i+V[n+2]*s-V[n+3]},k=(t,e,i,s)=>A(t,e,i,s)>=-1,D=(t,e)=>k(t,e[0],e[1],e[2]),E=2**this.lij[0]>2*this.lij[1],w=(t,e,s)=>Math.sqrt(R(t,e,s,n[0],n[1],n[2]))<i,U=t=>w(t[0],t[1],t[2]),q=(t,e)=>w(t[e],t[e+1],t[e+2]),N=this.extentInRadians,G=.5*(N[0]+N[2]),z=N[1],O=N[3],W=c(),J=c();T(W,G,O,g),T(J,G,z,g);const K=E?"Upper":"Lower";let Q=!0;for(let e=0;e<6;++e){for(let t=0;t<8;++t){const i=3*t,s=k(e,y[i],y[i+1],y[i+2]);Q&&=s,b(s,`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}b(D(e,J),`Tile[${this.lij}] (${K}) bottom mid outside of plane ${e}`),b(D(e,W),`Tile[${this.lij}] (${K}) top mid outside of plane ${e}`)}b(Q,"Not all convex hull points are inside convex hull polyhedron"),b(U(J),`Tile[${this.lij}] (${K}) bottom mid outside of bounding sphere`),b(U(W),`Tile[${this.lij}] (${K}) top mid outside of bounding sphere`);for(let e=0;e<8;++e){const t=q(y,3*e);b(t,`Tile[${this.lij}] Convex hull point ${e} outside of bounding sphere`)}for(let e=0;e<6;++e)for(let t=0;t<8;++t){const i=3*t;k(e,y[i],y[i+1],y[i+2])||console.error(`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}const{extentInRadians:X}=this,Y=Math.max(X[2]-X[0],X[3]-X[1]),Z=Math.round(Y*d),{renderData:tt}=this;if(!tt)return;const{geometry:et,geometryState:it,localOrigin:st}=tt,nt=et.vertexAttributes?.position;if(!nt)return;const ot=c(),rt=et.numVerticesPerSide-2,{indices:at,indexCount:lt,edgeVerticesStartIndex:ht,poleVerticesStartIndex:ut}=et;if(!at)return;const ct=new Set;for(let e=0;e<lt;++e){const t=at[e];if(ct.has(t))continue;ct.add(t);const r=t<ut,a=t>=ht;let h=!1,c=-1;if(a){let e=ht;for(let i=0;i<4;++i){const s=it.edgeResolutions[i];if(t===e||t===e+s-1){h=!0;break}if(e+=s,t<e){c=i;break}}}const p=a?it.edgePeerNeighbors[c]:null,g=a&&p&&B(this,p)>0;nt.getVec(t,u),s(ot,u,st);const v=o(ot)-d;let _=0,b=!1;const j=f-v,y=v-m,S=j>x,V=y>x,H=S||V,R=()=>{const e=r?"internal":a&&!h?"edge":h?"corner":"pole";return`Tile[${this.lij}].vertex[${t}]:${e}`+(S?"(below)":V?"(above)":"")+(g?"(Neighbor)":"")},T=l(ot,n);if(T>=i+$){const t=T-i;H||(console.error(`${R()} is out of the bounding sphere by ${t.toFixed(0)} / ${i.toFixed(0)}[tol=${$}] h=${v.toFixed(0)} / [${f.toFixed(0)}..${m.toFixed(0)}] (${(t/i).toFixed(0)})`),b=!0)}for(let e=0;e<6;++e)if(!k(e,ot[0],ot[1],ot[2])){const s=A(e,ot[0],ot[1],ot[2]),n=t%rt,o=(t-n)/rt;0===e&&j||5===e&&y||(console.error(`${R()} (${n},${o})|${rt}] is out of the bounding trapezoid plane ${e} h=${Math.round(v)} / [${Math.round(f)}..${Math.round(m)}] dist=${Math.round(s)} radii = ${Math.round(i)}/${Math.round(M)}} : maxL = ${Z}`),++_)}if(b||_>0)break}}get convexHull(){return this._convexHull}}const V=[128,64,64,32,16,8,8,4];function H(t,e,i){return R(t[0],t[1],t[2],e[i],e[i+1],e[i+2])}function R(t,e,i,s,n,o){const r=s-t,a=n-e,l=o-i;return r*r+a*a+l*l}const T=(t,e,i,s)=>{const n=Math.cos(e),o=Math.sin(e),r=Math.cos(i),a=Math.sin(i);t[0]=s*r*n,t[1]=s*r*o,t[2]=s*a},C=[0,0,1],I=c(),L=c();export{S as SphericalPatch};
5
+ import{lerp as t}from"../../../core/mathUtils.js";import{n as e,h as i,i as s,j as n,H as o,f as r,g as a,G as l,a as h}from"../../../chunks/vec32.js";import{ZEROS as u,create as c}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{lonLatToSphericalPCPF as d}from"../../../geometry/projection/lonLatToSphericalPCPF.js";import{newDoubleArray as p}from"../../../geometry/support/DoubleArray.js";import{intersectsSphere as f,numPlanes as m}from"../../../geometry/support/frustum.js";import{Sphere as g}from"../../../geometry/support/sphere.js";import{createSphericalGlobePatch as x,updateCornerSpherical as $,updateEdgesAndCornersSpherical as v,updateEdgeElevationsAndResolutionsSpherical as M}from"./PatchGeometryFactory.js";import{enableTerrainInternalChecks as _,internalAssert as b,almostEquals as j}from"./terrainUtils.js";import{Tile as y}from"./Tile.js";import{compareTilesByLij as B}from"./tileUtils.js";class S extends y{constructor(t,e,i,s,n){super(),this._convexHull=new Array(24),this._boundingSphere=new g,this._baseUsedMemory=1816,this.init(t,e,i,s,n)}init(i,s,n,o,r){super.init(i,s,n,o,r);const a=this.ellipsoid.radius,l=this.extentInRadians[0],h=this.extentInRadians[1],u=this.extentInRadians[2],c=this.extentInRadians[3],p=t(h,c,.5),f=t(l,u,.5),m=0===i?0:Math.min(Math.abs(h),Math.abs(c));this._edgeLen=(u-l)*Math.cos(m)*a,this._edgeLen2=this._edgeLen*this._edgeLen,this._curvatureHeight=a-Math.sqrt(a*a-this._edgeLen2/4),d(this.centerAtSeaLevel,f,p,this.ellipsoid.radius),e(this.up,this.centerAtSeaLevel),this.updateRadiusAndCenter()}updateRadiusAndCenter(){this._updateBoundingVolumes();const t=this._center;if(0===this.lij[0])t[1].center=u,i(t[0],0,0,0),i(t[2],0,0,0),t[1].radius=this.ellipsoid.radius+this.elevationBoundsMax;else{this._updateCenter();const e=t[1],i=this.convexHull;let s=0;const n=e.center;for(let t=0;t<8;++t)s=Math.max(s,H(n,i,3*t));t[1].radius=Math.sqrt(s)}}_calculateFrustumVisibility(t){if(!f(t,this._boundingSphere))return 2;if(this.lij[0]<10)return 1;const e=this.convexHull,i=this.surface.view.state.camera.near;let s=!0;for(let n=0;n<m;n++){const o=4===n,r=t[n],a=r[0],l=r[1],h=r[2],u=r[3]-(o?i:0);let c=!1;for(let t=0;t<8;++t){const i=3*t;if(a*e[i]+l*e[i+1]+h*e[i+2]+u<0){if(c=!0,!s)break}else s=!1}if(!c)return 2}return s?0:1}computeElevationBounds(){super.computeElevationBounds(),this._updateBoundingVolumes()}createGeometry(){x(this.renderData,this._getPatchType()),this._updateBoundingVolumes(),this.setMemoryDirty()}_updateBoundingVolumes(){this._updateConvexHull(),this._updateBoundingSphere(),_&&this._checkBVs()}_updateBoundingSphere(){const t=this._boundingSphere,e=this.elevationBoundsMin,i=this.elevationBoundsMax,r=this.ellipsoid.radius,a=i;if(0===this.level)t.center=u,t.radius=r+a;else{const a=this.extentInRadians,l=.5*(a[0]+a[2]),h=a[1],u=a[3];T(I,l,h,r),T(L,l,u,r),s(t.center,I,L);const c=r+.5*(e+i);n(t.center,t.center,c/o(t.center));const d=this.convexHull;let p=0;const f=(t,e)=>{const i=t[0]-d[3*e],s=t[1]-d[3*e+1],n=t[2]-d[3*e+2];return Math.sqrt(i*i+s*s+n*n)};for(let e=0;e<8;++e){const i=f(t.center,e);p=Math.max(p,i)}const m=p;t.radius=m+2}}_updateConvexHull(){const t=this.extentInRadians,i=this.ellipsoid.radius;if(0===this.level)return;const l=this.elevationBoundsMin,u=this.elevationBoundsMax,d=this._getPatchType(),p=this.surface.isWebMercator,f=p&&1===d,m=p&&2===d,g=m||f,x=Math.PI/2,$=t[0],v=t[2],M=m?-x:t[1],_=f?x:t[3],y=.5*($+v),B=l,S=i+(g?Math.min(0,B-1):B),V=(t,e,i)=>T(t,e,i,S),H=c(),R=c(),I=c(),L=c();V(H,$,M),V(R,$,_),V(I,v,_),V(L,v,M);const P=(t,e)=>{for(let i=0;i<3;++i)this._convexHull[3*e+i]=t[i]};P(H,0),P(R,1),P(I,2),P(L,3);const F=u,A=i+(g?Math.max(0,F+1):F),k=c(),D=c(),E=c();T(D,y,_,S),T(E,y,M,S),s(k,D,E),e(k,k);const w=c(),U=c(),q=(t,i)=>{h(U,t,i),e(U,U);const o=-a(t,w)/a(U,w);b(o>=0),n(U,U,o),s(t,t,U)};if(2**this.lij[0]>2*this.lij[1]){const t=E,i=c();r(i,C,t),e(i,i),r(w,t,i),e(w,w),b(j(a(w,t)/o(t),0)),q(H,R),q(L,I),P(H,0),P(L,3)}else if(2**this.lij[0]!==2*this.lij[1]){const t=D,i=c();r(i,C,t),e(i,i),r(w,i,t),e(w,w),q(R,H),q(I,L),P(R,1),P(I,2)}const N=(t,e)=>{const i=A/a(e,k);for(let s=0;s<3;++s)this._convexHull[3*t+s]=e[s]*i};N(4,H),N(5,R),N(6,I),N(7,L)}_getPatchType(){const t=this.lij[1],e=0===t,i=t===(1<<this.level)-1;return e?i?3:1:i?2:0}intersectsRay(t,e,i,s){const n=this._boundingSphere,o=n.radius+i,r=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],a=n.center[0]-t[0],l=n.center[1]-t[1],h=n.center[2]-t[2],u=(a*e[0]+l*e[1]+h*e[2])/r,c=e[0]*u-a,d=e[1]*u-l,p=e[2]*u-h;return c*c+d*d+p*p<o*o}get minimumVerticesPerSide(){return this.level<V.length?V[this.level]+1:2}updateCornerElevations(){$(this.renderData),this._updateBoundingVolumes()}updateEdgeElevations(){v(this.renderData),this._updateBoundingVolumes()}updateEdgeElevationsAndResolutions(){M(this.renderData),this._updateBoundingVolumes()}_checkBVs(){if(!_)return;if(this.level<=2)return;const t=this._boundingSphere,i=t.radius,n=t.center,u=c(),d=this.ellipsoid.radius,f=this.elevationBoundsMin,m=this.elevationBoundsMax,g=d+f,x=1,$=0,v=this._center[1];v.center;const M=v.radius,y=this.convexHull,S=(t,e)=>{for(let i=0;i<3;++i)t[i]=y[3*e+i]};{const t=c(),i=c(),s=c(),n=c(),o=c(),l=(l,u,c,d)=>{S(i,l),S(s,u),S(n,c),h(i,i,s),h(n,n,s),r(t,i,n),e(t,t);const p=a(t,s);S(o,d);const f=a(t,o),m=Math.abs(f-p);b(j(m,0),`Non coplanar ${l},${u},${c},${d} diff = ${m}`)};l(0,1,2,3),l(4,5,6,7),l(0,1,4,5),l(1,2,5,6),l(2,3,6,7),l(3,0,7,4)}const V=p(24),H=(t,e,i)=>{const s=4*t;for(let n=0;n<3;++n)V[s+n]=e[n];V[s+3]=i},C=c(),I=c(),L=c(),P=c(),F=(t,i,s,n)=>{S(C,i),S(I,s),S(L,n),h(C,C,I),e(C,C),h(L,L,I),e(L,L),r(P,C,L),e(P,P);const o=a(P,I);H(t,P,o)};F(0,0,1,2),F(1,1,0,4),F(2,1,5,2),F(3,3,2,6),F(4,4,0,3),F(5,4,6,5);const A=(t,e,i,s)=>{const n=4*t;return V[n]*e+V[n+1]*i+V[n+2]*s-V[n+3]},k=(t,e,i,s)=>A(t,e,i,s)>=-1,D=(t,e)=>k(t,e[0],e[1],e[2]),E=2**this.lij[0]>2*this.lij[1],w=(t,e,s)=>Math.sqrt(R(t,e,s,n[0],n[1],n[2]))<i,U=t=>w(t[0],t[1],t[2]),q=(t,e)=>w(t[e],t[e+1],t[e+2]),N=this.extentInRadians,G=.5*(N[0]+N[2]),z=N[1],O=N[3],W=c(),J=c();T(W,G,O,g),T(J,G,z,g);const K=E?"Upper":"Lower";let Q=!0;for(let e=0;e<6;++e){for(let t=0;t<8;++t){const i=3*t,s=k(e,y[i],y[i+1],y[i+2]);Q&&=s,b(s,`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}b(D(e,J),`Tile[${this.lij}] (${K}) bottom mid outside of plane ${e}`),b(D(e,W),`Tile[${this.lij}] (${K}) top mid outside of plane ${e}`)}b(Q,"Not all convex hull points are inside convex hull polyhedron"),b(U(J),`Tile[${this.lij}] (${K}) bottom mid outside of bounding sphere`),b(U(W),`Tile[${this.lij}] (${K}) top mid outside of bounding sphere`);for(let e=0;e<8;++e){const t=q(y,3*e);b(t,`Tile[${this.lij}] Convex hull point ${e} outside of bounding sphere`)}for(let e=0;e<6;++e)for(let t=0;t<8;++t){const i=3*t;k(e,y[i],y[i+1],y[i+2])||console.error(`Tile[${this.lij}] Convex hull point ${t} outside of plane ${e}`)}const{extentInRadians:X}=this,Y=Math.max(X[2]-X[0],X[3]-X[1]),Z=Math.round(Y*d),{renderData:tt}=this;if(!tt)return;const{geometry:et,geometryState:it,localOrigin:st}=tt,nt=et.vertexAttributes?.position;if(!nt)return;const ot=c(),rt=et.numVerticesPerSide-2,{indices:at,indexCount:lt,edgeVerticesStartIndex:ht,poleVerticesStartIndex:ut}=et;if(!at)return;const ct=new Set;for(let e=0;e<lt;++e){const t=at[e];if(ct.has(t))continue;ct.add(t);const r=t<ut,a=t>=ht;let h=!1,c=-1;if(a){let e=ht;for(let i=0;i<4;++i){const s=it.edgeResolutions[i];if(t===e||t===e+s-1){h=!0;break}if(e+=s,t<e){c=i;break}}}const p=a?it.edgePeerNeighbors[c]:null,g=a&&p&&B(this,p)>0;nt.getVec(t,u),s(ot,u,st);const v=o(ot)-d;let _=0,b=!1;const j=f-v,y=v-m,S=j>x,V=y>x,H=S||V,R=()=>{const e=r?"internal":a&&!h?"edge":h?"corner":"pole";return`Tile[${this.lij}].vertex[${t}]:${e}`+(S?"(below)":V?"(above)":"")+(g?"(Neighbor)":"")},T=l(ot,n);if(T>=i+$){const t=T-i;H||(console.error(`${R()} is out of the bounding sphere by ${t.toFixed(0)} / ${i.toFixed(0)}[tol=${$}] h=${v.toFixed(0)} / [${f.toFixed(0)}..${m.toFixed(0)}] (${(t/i).toFixed(0)})`),b=!0)}for(let e=0;e<6;++e)if(!k(e,ot[0],ot[1],ot[2])){const s=A(e,ot[0],ot[1],ot[2]),n=t%rt,o=(t-n)/rt;0===e&&j||5===e&&y||(console.error(`${R()} (${n},${o})|${rt}] is out of the bounding trapezoid plane ${e} h=${Math.round(v)} / [${Math.round(f)}..${Math.round(m)}] dist=${Math.round(s)} radii = ${Math.round(i)}/${Math.round(M)}} : maxL = ${Z}`),++_)}if(b||_>0)break}}get convexHull(){return this._convexHull}}const V=[128,64,64,32,16,8,8,4];function H(t,e,i){return R(t[0],t[1],t[2],e[i],e[i+1],e[i+2])}function R(t,e,i,s,n,o){const r=s-t,a=n-e,l=o-i;return r*r+a*a+l*l}const T=(t,e,i,s)=>{const n=Math.cos(e),o=Math.sin(e),r=Math.cos(i),a=Math.sin(i);t[0]=s*r*n,t[1]=s*r*o,t[2]=s*a},C=[0,0,1],I=c(),L=c();export{S as SphericalPatch};