@arcgis/core 6.0.0-next.34 → 6.0.0-next.36

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 (232) hide show
  1. package/Basemap.d.ts +2 -2
  2. package/analysis/ShadowCastAnalysis.d.ts +11 -5
  3. package/arcgisGlobal.d.ts +1 -0
  4. package/assets/esri/core/libs/libtess/libtess-f32.wasm +0 -0
  5. package/assets/esri/core/libs/libtess/libtess-f64.wasm +0 -0
  6. package/assets/esri/core/workers/RemoteClient.js +1 -1
  7. package/assets/esri/core/workers/chunks/01f55004d64309f8538b.js +1 -0
  8. package/assets/esri/core/workers/chunks/0202eb8c2b2865f99981.js +1 -0
  9. package/assets/esri/core/workers/chunks/{67e533748435253aaba6.js → 0284f608d25c654fcc11.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{7810586c35dfe1437516.js → 06102715e9a8f218e07c.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{6029773458ab98600f67.js → 07e5482e1fc69be5de09.js} +1 -1
  12. package/assets/esri/core/workers/chunks/08140725277de5d2e41a.js +1 -0
  13. package/assets/esri/core/workers/chunks/{2d9a1f23ec6ce90723ac.js → 0d99bfb75dcb9fa29080.js} +1 -1
  14. package/assets/esri/core/workers/chunks/10ad7b35b6800d40444e.js +1 -0
  15. package/assets/esri/core/workers/chunks/1132e28aaa5825b10b6e.js +1 -0
  16. package/assets/esri/core/workers/chunks/{dd30b02c5978c1c5f511.js → 155861fbd0e5fc2db80c.js} +1 -1
  17. package/assets/esri/core/workers/chunks/165ca7a97b611c8f26c4.js +1 -0
  18. package/assets/esri/core/workers/chunks/1ae0c9345626e70affd3.js +2 -0
  19. package/assets/esri/core/workers/chunks/{cd355baab983033c3ef0.js → 1ec772eaa63eb6937231.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{5c04835b0b52461183cd.js → 1fd82fcba2758741996a.js} +1 -1
  21. package/assets/esri/core/workers/chunks/21e1d423ee33f916547e.js +1 -0
  22. package/assets/esri/core/workers/chunks/{e8e54faf947a582b4cf7.js → 247617c0dbae2386ab3b.js} +1 -1
  23. package/assets/esri/core/workers/chunks/{97ec46605f16333144b7.js → 26ea39dfdf887f357fce.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{85de980c5b296ec69323.js → 279089a6a3f08022c678.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{b657363113f4a37e634b.js → 3223f9fbc76ba9ef8d13.js} +1 -1
  26. package/assets/esri/core/workers/chunks/322b22a5d54e404bebd5.js +1 -0
  27. package/assets/esri/core/workers/chunks/{122e75b21699a4e83b15.js → 338d800d4efcc91cead1.js} +1 -1
  28. package/assets/esri/core/workers/chunks/3537fe95b83a13b156cc.js +1 -0
  29. package/assets/esri/core/workers/chunks/{f09bc86cd52224febfcb.js → 3b380e64566a6cce59e2.js} +1 -1
  30. package/assets/esri/core/workers/chunks/{a1e8209d00809c9520a0.js → 3fe4c89acd325d36618d.js} +1 -1
  31. package/assets/esri/core/workers/chunks/449a2dee17b54946f245.js +1 -0
  32. package/assets/esri/core/workers/chunks/{311e4969f19df63451dd.js → 4e5405134d079bdf9b7a.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{d070fcb73ce274ab80e4.js → 5504ec9bd9ee4d10af07.js} +1 -1
  34. package/assets/esri/core/workers/chunks/552c36b40e5a5ec117fb.js +1 -0
  35. package/assets/esri/core/workers/chunks/5622f3faa59434772857.js +1 -0
  36. package/assets/esri/core/workers/chunks/59a1b637d2c107504a04.js +1 -0
  37. package/assets/esri/core/workers/chunks/59a88dd53f8806bbec06.js +1 -0
  38. package/assets/esri/core/workers/chunks/5c2fe67527c9d7b4dba3.js +1 -0
  39. package/assets/esri/core/workers/chunks/5d781c2c6204cffffd0d.js +1 -0
  40. package/assets/esri/core/workers/chunks/61d36730564c5ac5edab.js +1 -0
  41. package/assets/esri/core/workers/chunks/6604272ef6fe85279032.js +1 -0
  42. package/assets/esri/core/workers/chunks/{90c1d10eae7ae71889b0.js → 7400b8c454b47ee4fb3c.js} +1 -1
  43. package/assets/esri/core/workers/chunks/796c6195b6bf59dcc9bd.js +1 -0
  44. package/assets/esri/core/workers/chunks/7b45ac83e279fe9516a5.js +1 -0
  45. package/assets/esri/core/workers/chunks/{2de077c7b971f2c215a6.js → 7ddbde8fdd1cf3c53f50.js} +1 -1
  46. package/assets/esri/core/workers/chunks/804606b194dc9e71d088.js +1 -0
  47. package/assets/esri/core/workers/chunks/8102f0bf5707c3be3310.js +1 -0
  48. package/assets/esri/core/workers/chunks/{676c8c0329d68f9f3ac4.js → 81bcc495e6eaf2cf7474.js} +1 -1
  49. package/assets/esri/core/workers/chunks/{d1d6154b4af1c9cc497b.js → 934e1f2153e6fad6ed23.js} +1 -1
  50. package/assets/esri/core/workers/chunks/{e096c1d9d53af74d3207.js → 990e96139b5a1dccb061.js} +1 -1
  51. package/assets/esri/core/workers/chunks/{f28b63c1179366dac8a2.js → 9e2c30b67bab5795306e.js} +1 -1
  52. package/assets/esri/core/workers/chunks/{9184c947cdefe06bf551.js → a18c3cbe505a19d29569.js} +1 -1
  53. package/assets/esri/core/workers/chunks/aa6ee2aa4ff6e6d41efb.js +1 -0
  54. package/assets/esri/core/workers/chunks/{3fd5c3cd8457ddc68798.js → aa779896fd9e5c341349.js} +1 -1
  55. package/assets/esri/core/workers/chunks/ac10c7d2c4829a150037.js +1 -0
  56. package/assets/esri/core/workers/chunks/{e0a7a75709121a26f255.js → afc8a9847f31bb66b13b.js} +1 -1
  57. package/assets/esri/core/workers/chunks/c7adb7b77721c75891f4.js +1 -0
  58. package/assets/esri/core/workers/chunks/{bead830a677690eeb6fb.js → ce8ef2eec290e1df6b2a.js} +1 -1
  59. package/assets/esri/core/workers/chunks/d3369ffed19f4c264dcd.js +1 -0
  60. package/assets/esri/core/workers/chunks/d3412518a7b518860fbb.js +1 -0
  61. package/assets/esri/core/workers/chunks/{3048e74e6246324ce6fc.js → d5916500514a41a4758f.js} +1 -1
  62. package/assets/esri/core/workers/chunks/{c034c30e577d620b8e28.js → dac69c0047488fdf986d.js} +1 -1
  63. package/assets/esri/core/workers/chunks/dcc782e4bf9e8a8202f9.js +1 -0
  64. package/assets/esri/core/workers/chunks/dcdf837a452dc0cac582.js +1 -0
  65. package/assets/esri/core/workers/chunks/{19a4fa965b70fc6f78f6.js → e209cb1f3f14bf576ebe.js} +1 -1
  66. package/assets/esri/core/workers/chunks/e67ea2f1714e5abeae44.js +1 -0
  67. package/assets/esri/core/workers/chunks/e8fb2ba7b7a4f0916325.js +1 -0
  68. package/assets/esri/core/workers/chunks/efcd38aad9aa667001b2.js +1 -0
  69. package/assets/esri/core/workers/chunks/{3aafdb905c697bc9b1ad.js → f372f4eb5527238c46f5.js} +1 -1
  70. package/assets/esri/core/workers/chunks/f497968055af459c5da4.js +1 -0
  71. package/assets/esri/core/workers/chunks/f7123ba1286f64e13e91.js +1 -0
  72. package/assets/esri/core/workers/chunks/fcb4707c2e95099b9f30.js +1 -0
  73. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  74. package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
  75. package/chunks/BlurEmission.glsl.js +9 -4
  76. package/chunks/RibbonLine.glsl.js +158 -84
  77. package/chunks/Terrain.glsl.js +9 -9
  78. package/chunks/libtess-f32.js +1 -1
  79. package/chunks/libtess-f64.js +1 -1
  80. package/chunks/lyr3DMain.js +1 -1
  81. package/chunks/lyr3DWorker.js +2 -2
  82. package/config.d.ts +3 -3
  83. package/config.js +1 -1
  84. package/core/mathUtils.js +1 -1
  85. package/form/FormTemplate.d.ts +1 -1
  86. package/geometry/libtess.js +1 -1
  87. package/geometry/projection/projectors.js +1 -1
  88. package/identity/Credential.d.ts +1 -1
  89. package/identity/IdentityManager.d.ts +1 -1
  90. package/identity/OAuthInfo.d.ts +1 -1
  91. package/identity/ServerInfo.d.ts +1 -1
  92. package/kernel.js +1 -1
  93. package/layers/CSVLayer.js +1 -1
  94. package/layers/GaussianSplatLayer.js +1 -1
  95. package/layers/IntegratedMesh3DTilesLayer.js +1 -1
  96. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  97. package/layers/VectorTileLayer.d.ts +2 -2
  98. package/layers/VideoLayer.js +1 -1
  99. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  100. package/layers/graphics/sources/CSVSource.js +1 -1
  101. package/layers/graphics/sources/GeoJSONSource.js +1 -1
  102. package/layers/graphics/sources/MemorySource.js +2 -2
  103. package/layers/graphics/sources/support/ParquetSourceWorker.js +1 -1
  104. package/layers/graphics/sources/support/QueryTask.js +1 -1
  105. package/layers/graphics/sources/support/timeQueryUtils.js +2 -0
  106. package/layers/mixins/APIKeyMixin.d.ts +1 -1
  107. package/layers/ogc/types.d.ts +1 -1
  108. package/layers/support/TelemetryData.d.ts +28 -4
  109. package/layers/support/TimeInformation.js +1 -1
  110. package/layers/support/tiles3DUtils.js +1 -1
  111. package/layers/support/timeInfoUtils.js +2 -0
  112. package/layers/video/videoUtils.js +1 -1
  113. package/package.json +2 -2
  114. package/rest/query/executeAttributeBinsQuery.js +1 -1
  115. package/rest/query/executeForExtent.js +1 -1
  116. package/rest/query/executeForTopCount.js +1 -1
  117. package/rest/query/executeForTopExtents.js +1 -1
  118. package/rest/query/executeForTopIds.js +1 -1
  119. package/rest/query/executeTopFeaturesQuery.js +1 -1
  120. package/rest/query/operations/query.js +1 -1
  121. package/rest/query/operations/queryAttributeBins.js +1 -1
  122. package/rest/query/operations/queryTopFeatures.js +1 -1
  123. package/rest/support/timeUtils.js +1 -1
  124. package/support/timeUtils.js +1 -1
  125. package/views/2d/engine/webgl/FeatureDisplayList.js +1 -1
  126. package/views/2d/engine/webgl/GlyphMosaic.js +1 -1
  127. package/views/2d/engine/webgl/GlyphWorker.js +1 -1
  128. package/views/2d/engine/webgl/TextureManager.js +1 -1
  129. package/views/2d/engine/webgl/materialKeyUtils.js +2 -0
  130. package/views/2d/engine/webgl/mesh/MeshData.js +1 -1
  131. package/views/2d/engine/webgl/mesh/templates/shapingUtils.js +1 -1
  132. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedMarkerMeshWriter.js +1 -1
  133. package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedPolyMeshWriters.js +1 -1
  134. package/views/2d/engine/webgl/shaderGraph/techniques/fill/ComplexOutlineFillMeshWriter.js +1 -1
  135. package/views/2d/engine/webgl/shaderGraph/techniques/fill/GradientFillMeshWriter.js +1 -1
  136. package/views/2d/engine/webgl/shaderGraph/techniques/fill/PatternFillMeshWriter.js +1 -1
  137. package/views/2d/engine/webgl/shaderGraph/techniques/fill/PatternOutlineFillMeshWriter.js +1 -1
  138. package/views/2d/engine/webgl/shaderGraph/techniques/labels/LabelMeshWriter.js +1 -1
  139. package/views/2d/engine/webgl/shaderGraph/techniques/line/GradientStrokeMeshWriter.js +1 -1
  140. package/views/2d/engine/webgl/shaderGraph/techniques/line/TexturedLineMeshWriter.js +1 -1
  141. package/views/2d/engine/webgl/shaderGraph/techniques/markers/MarkerMeshWriter.js +1 -1
  142. package/views/2d/engine/webgl/shaderGraph/techniques/text/TextMeshWriter.js +1 -1
  143. package/views/2d/layers/VideoLayerView2D.js +1 -1
  144. package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
  145. package/views/3d/analysis/LineOfSight/placementUtils.js +1 -1
  146. package/views/3d/analysis/ShadowCast/ShadowCastError.d.ts +40 -0
  147. package/views/3d/analysis/ShadowCast/ShadowCastError.js +2 -0
  148. package/views/3d/analysis/ShadowCast/sunlightUtils.js +2 -0
  149. package/views/3d/analysis/ShadowCastAnalysisView3D.d.ts +16 -1
  150. package/views/3d/analysis/ShadowCastAnalysisView3D.js +1 -1
  151. package/views/3d/analysis/Viewshed/placementUtils.js +1 -1
  152. package/views/3d/camera/constraintUtils/surfaceCollision.js +1 -1
  153. package/views/3d/camera/intersectionUtils.js +1 -1
  154. package/views/3d/interactive/Manipulator3D.js +1 -1
  155. package/views/3d/interactive/editingTools/draw/DrawGraphicTool3D.js +1 -1
  156. package/views/3d/interactive/editingTools/originGeometryVisualElementUtils.js +1 -1
  157. package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
  158. package/views/3d/layers/I3SMeshView3D.js +1 -1
  159. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  160. package/views/3d/layers/Lyr3DWorker.js +1 -1
  161. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  162. package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
  163. package/views/3d/layers/i3s/LayerElevationProvider.js +1 -1
  164. package/views/3d/layers/support/FeatureMemory.js +1 -1
  165. package/views/3d/layers/support/FeatureTile.js +1 -1
  166. package/views/3d/layers/support/Tiles3DBVH.js +1 -1
  167. package/views/3d/layers/support/Tiles3DMeshIntersectionHandler.js +1 -1
  168. package/views/3d/navigation/modes/GroundNavigationMode3D.js +1 -1
  169. package/views/3d/state/Constraints.js +1 -1
  170. package/views/3d/state/NearFarHeuristic.js +1 -1
  171. package/views/3d/state/utils/groundNavigationUtils.js +1 -1
  172. package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +1 -1
  173. package/views/3d/support/gaussianSplatting/GaussianSplatIntersectionHandler.js +1 -1
  174. package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +1 -1
  175. package/views/3d/support/gaussianSplatting/GaussianTile.js +1 -1
  176. package/views/3d/support/orientedBoundingBox.js +1 -1
  177. package/views/3d/support/pointsOfInterest/SurfaceGeometryUpdates.js +1 -1
  178. package/views/3d/support/sphereExtentUtils.js +1 -1
  179. package/views/3d/terrain/TerrainSurface.js +1 -1
  180. package/views/3d/terrain/TileRenderer.js +1 -1
  181. package/views/3d/terrain/tileUtils.js +1 -1
  182. package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
  183. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  184. package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
  185. package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
  186. package/views/3d/webgl.d.ts +1 -1
  187. package/views/draw/DrawTool.js +1 -1
  188. package/views/support/Scheduler.js +1 -1
  189. package/widgets/Directions.d.ts +1 -1
  190. package/widgets/OrientedImageryViewer/navigation/NavigationManager.js +1 -1
  191. package/widgets/OrientedImageryViewer/navigation/queries.js +1 -1
  192. package/widgets/OrientedImageryViewer/navigation/utils.js +1 -1
  193. package/widgets/OrientedImageryViewer.js +2 -2
  194. package/assets/esri/core/workers/chunks/0f6c0d42100c21367e5c.js +0 -1
  195. package/assets/esri/core/workers/chunks/176d0a06ebff5a29dedf.js +0 -1
  196. package/assets/esri/core/workers/chunks/18776a130d96879a68b1.js +0 -1
  197. package/assets/esri/core/workers/chunks/20a698709c3c11ff2c16.js +0 -1
  198. package/assets/esri/core/workers/chunks/24ada9511b074dc5ae27.js +0 -1
  199. package/assets/esri/core/workers/chunks/277263466837e1673f56.js +0 -1
  200. package/assets/esri/core/workers/chunks/2c8ca43563c4f3e94535.js +0 -1
  201. package/assets/esri/core/workers/chunks/379ef56f6b32494832a6.js +0 -1
  202. package/assets/esri/core/workers/chunks/38d852676677e5697864.js +0 -1
  203. package/assets/esri/core/workers/chunks/38df7b1d58c4bcf693d0.js +0 -1
  204. package/assets/esri/core/workers/chunks/507ecc3692e6d0700958.js +0 -1
  205. package/assets/esri/core/workers/chunks/5a9b7eb26f936f03d02e.js +0 -1
  206. package/assets/esri/core/workers/chunks/5f07f52bb8b7721f08d3.js +0 -1
  207. package/assets/esri/core/workers/chunks/661847f1b7044f21600f.js +0 -1
  208. package/assets/esri/core/workers/chunks/6b5c073dddd89d06ed80.js +0 -1
  209. package/assets/esri/core/workers/chunks/6ddc29a144640acb1192.js +0 -1
  210. package/assets/esri/core/workers/chunks/6ebe73f69ae822053b70.js +0 -1
  211. package/assets/esri/core/workers/chunks/6f6d1873753a9c6994aa.js +0 -1
  212. package/assets/esri/core/workers/chunks/7582654a0fc70910731c.js +0 -1
  213. package/assets/esri/core/workers/chunks/7e211d8a8ad6c6a7cf3e.js +0 -1
  214. package/assets/esri/core/workers/chunks/849f446c718e892f39ce.js +0 -1
  215. package/assets/esri/core/workers/chunks/8517d96fc8ba7b21d845.js +0 -2
  216. package/assets/esri/core/workers/chunks/a107f16cd004626b5018.js +0 -1
  217. package/assets/esri/core/workers/chunks/a65951f1d5702cfd996e.js +0 -1
  218. package/assets/esri/core/workers/chunks/bf62be00f3040f91aaee.js +0 -1
  219. package/assets/esri/core/workers/chunks/c570b90995c65bbb2e14.js +0 -1
  220. package/assets/esri/core/workers/chunks/c576bef77e34920af188.js +0 -1
  221. package/assets/esri/core/workers/chunks/caad4f475d6eb01c2850.js +0 -1
  222. package/assets/esri/core/workers/chunks/cf1ec61eb2ad147bb931.js +0 -1
  223. package/assets/esri/core/workers/chunks/daae21cf77864f3293ef.js +0 -1
  224. package/assets/esri/core/workers/chunks/dc2f93453dfa40f623ab.js +0 -1
  225. package/assets/esri/core/workers/chunks/e81173724e8de8c1e65b.js +0 -1
  226. package/assets/esri/core/workers/chunks/e83f9abee611c5b80009.js +0 -1
  227. package/assets/esri/core/workers/chunks/ec8b7476eac4718eb0ac.js +0 -1
  228. package/assets/esri/core/workers/chunks/f45064066e1ab041a0b2.js +0 -1
  229. package/assets/esri/core/workers/chunks/ffe49d9e7df081bef4a5.js +0 -1
  230. package/views/2d/engine/webgl/hashMosaic.js +0 -2
  231. package/views/3d/webgl-engine/lib/GaussianSplatPrepassDepthRenderer.js +0 -2
  232. /package/assets/esri/core/workers/chunks/{8517d96fc8ba7b21d845.js.LICENSE.txt → 1ae0c9345626e70affd3.js.LICENSE.txt} +0 -0
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBoundingSphere as r}from"../../../../geometry/projection/projectBoundingSphere.js";import{Sphere as i}from"../../../../geometry/support/sphere.js";import{NodeBoundingData as a,Node as o,NodeTraversalState as s}from"./I3SNode.js";import{addWraparound as c}from"./I3SUtil.js";import{ValidatedNode as l}from"./ValidatedNode.js";import{ElevationRange as u}from"../../support/ElevationRange.js";import{Obb as d}from"../../support/orientedBoundingBox.js";class f{constructor(e,t,n,r,i){this.childOffset=e,this.childCount=t,this.visibilityCache=n,this._boundingData=r,this.node=i,this.parentIndex=-1,this.useAsHole=0,this.filterImpact=2,this.traversalState=null}get nodeBoundingData(){return this._boundingData}destroy(){this._boundingData=null,this.node=null,this.traversalState=null}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.nodeBoundingData?.invalidateServiceBVsInRenderSR()}}class p{constructor(e=[],t=[]){this._nodeDescriptors=e,this._children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}destroy(){for(let e of this._nodeDescriptors)e.destroy();this._nodeDescriptors.length=0,this._children.length=0}get nodes(){return this._nodeDescriptors}addNode(e){return this._nodeDescriptors.push(e),this._nodeDescriptors.length-1}setNodes(e,t){this._nodeDescriptors=e,this._children=t}get children(){return this._children}}class m{get _useNodePages(){return this._pageSize>0}constructor(t,n,r,i,o,s,c,l,u,d,f,m,h,_,y){if(this.viewingMode=t,this._layer=n,this._requester=i,this._clientNodeLoader=o,this._viewportQueries=s,this._logger=c,this.holeFilling=l,this._isLoaded=u,this._isReloading=d,this._shouldLoadNode=f,this._enable=m,this._needsUpdate=h,this._computeVisibilityObb=_,this._computeNodeFiltering=y,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=0,this._lodConversion=e=>e,this._isEditable=!1,this.urlPrefix=``,this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=-1/0,this._maxProcessingPrio=1/0,this._version=v(0),this._visibilityCacheVersion=v(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._progressiveLoadPenaltyWeight=10,this._missingPagesAndNodes=new Set,this._prioritizedMissingNodeAndPageIds=[],this._prefetchNodes=new Set,this._prioritizedPrefetchNodes=[],this._updates=new g(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this._pageQueue=[],this._newPages=[],this._needsNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._isEditable=n.associatedLayer?.infoFor3D!=null,n.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${n.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,r.type===`page`){let e=r.rootPage;switch(this.urlPrefix=r.urlPrefix,this._pageSize=r.pageSize,r.lodMetric){case`maxScreenThreshold`:this._lodMetric=1;break;case`maxScreenThresholdSQ`:this._lodMetric=1,this._lodConversion=k}if(this._isEditable){this._rootIndex=-1;let t=C(r.rootIndex,r.pageSize),n=e.nodes[t],i={nodes:[{index:this._rootIndex,children:[r.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(S(this._rootIndex,this._pageSize),i),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=r.rootIndex;this._addPage(S(r.rootIndex,this._pageSize),e),this._updateParentsAndLevel()}else if(r.type===`node`){this.urlPrefix=r.urlPrefix;let e=new p;if(this._nodePages.set(0,e),this._isEditable){this._clientNodePage=new p;let e={id:`-1`,version:null,mbs:r.rootNode.mbs,obb:r.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:`root`,href:`../root`,mbs:r.rootNode.mbs,obb:r.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new a(e.id),-1);let t=this._validateNode(e.id,e);t&&this._addNode(t,this._rootIndex)}else this._rootIndex=this._makeRefNode(new a(r.rootNode.id),-1);let t=this._validateNode(r.rootNode.id,r.rootNode);t&&this._addNode(t,0)}}addClientNodeToIndex(e,t){let n=new a(e,t),r=this._makeClientRefNode(n,-1);return this._linkChildToParentNode(-1,r),this.requestUpdate(),r}removeClientNodeFromIndex(e,t,n){this._destroyClientRefNode(e,t,n),this.requestUpdate()}_canRequest(e){return!this._requester.isFull(e)}_loadPage(e){if(this._nodePages.has(e)){this._logger.error(`Requested load page [${e}] already loaded`);return}if(this._loadingPages.has(e)){this._logger.error(`Requested load page [${e}] already loading`);return}this._loadingPages.add(e);let n=this.urlPrefix+e;this._requester.request(n,`json`).then(t=>{this._nodePages.has(e)?this._logger.error(`Queued page [${e}] already loaded`):this._pageQueue.push({pageIndex:e,page:t})}).catch(n=>{this._loadingPages.delete(e),t(n)||(this._failedPages.add(e),this._logger.error(`#loadPage()`,this._layer,`Error when loading page ${e}`,n))})}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){let{pageIndex:t,page:n}=this._pageQueue.shift();this._addPage(t,n),this._loadingPages.delete(t),e.madeProgress(),this._needsNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this._needsNodeElevationRange)for(;this._newPages.length>0&&!e.done;)this._nodePages.get(this._newPages.shift())?.nodes.forEach(e=>{let t=e.parentIndex;for(;t!=null&&t!==this._rootIndex;){let e=this.getNode(t);e?.elevationRangeValid&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this._getParentIndex(t)}})}_addPage(e,t){if(this._nodePages.has(e)){this._logger.error(`Page[${e}] reloaded`);return}let n=[],r=[],a=t.nodes.map((t,a)=>{let s=n.length,c=t.children?t.children.length:0;r.push(this._rootIndex);for(let e=0;e<c;e++)n.push(t.children[e]);let l=`${t.index}`,u=d.fromJSON(t.obb),p=new i(u.getCenter(N),u.radius),m=t.mesh?.attribute,h=t.mesh?.geometry,g=t.mesh?.material,v={hasSharedResource:!1,isEmpty:h==null,attributes:m?.resource==null?void 0:`${m.resource}`,geometry:h?.resource==null?void 0:`${h.resource}`,texture:g?.resource==null?void 0:`${g.resource}`,geometryDefinition:h?h.definition:-1,materialDefinition:g?g.definition:-1},y=new o(l,w(a,e,this._pageSize),p,c,0,v,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),h?.featureCount??null,u);return y.visibilityObbInRenderSR=this._computeVisibilityObb(y),y.vertexCount=h?h.vertexCount:0,new f(s,c,_(this._visibilityCacheVersion),null,y)}),s=new p(a,n);e===-1?this._clientNodePage=s:this._nodePages.set(e,s)}_updateParentsAndLevel(){let e=[],t=(t,n,r)=>{let i=this._getPage(t);if(i!=null){let a=C(t,this._pageSize),o=i.nodes[a];o.parentIndex=n??-1;let s=o.node;s!=null&&(s.level=r,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){let n=e.pop(),r=this.getNode(n);if(r!=null)for(let e=0;e<r.childCount;e++)t(this.getChildIndex(r.index,e),n,r.level+1),this._maxLevel=Math.max(this._maxLevel,r.level+1)}}_getPage(e){let t=S(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeDescriptor(e){let t=this._getPage(e);return t==null?null:(t.lastTraversed=this._frameNumber,t.nodes[C(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);let n=this.getParent(t),r=n==null?0:n.level+1;this._maxLevel=Math.max(this._maxLevel,e.children?r+1:r);let{lodMetric:i,maxError:a}=E(e.lodSelection),s=this._getNodeDescriptor(t);if(s.node!=null)return this._logger.error(`Loaded node[${t}] already in descriptor`),s.node;let c=new o(e.id,t,e.mbs,s.childCount,r,e.resources,e.version,i,a,e.numFeatures,e.obb?d.fromJSON(e.obb):null);s.node=c,c.visibilityObbInRenderSR=this._computeVisibilityObb(c);let l=s.nodeBoundingData;return l!=null&&(l.serviceMbsInIndexSR??=e.mbs,c.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=c.visibilityObbInRenderSR),c}_makeRefNode(e,t){let n=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(n==null)return-1;let r=n.nodes.length,i=new f(0,0,_(this._visibilityCacheVersion),e,null);return n.addNode(i),i.parentIndex=t,e.invalidateServiceBVsInRenderSR(),r}_makeClientRefNode(e,t){let n=this._clientNodePage;if(n==null)return-1;if(t>=0)throw Error(`I3SIndex::client side nodes can not be made children of service side nodes.`);let r=-(n.nodes.length+1),i=new f(0,0,_(this._visibilityCacheVersion),e,null);return n.addNode(i),i.parentIndex=t,e.invalidateServiceBVsInRenderSR(),r}_linkChildToParentNode(e,t){let n=this._clientNodePage;if(n==null||e>=0)return;let r=C(e,this._pageSize),i=C(t,this._pageSize),a=n.nodes[r],o=a.childOffset;n.children.splice(a.childOffset+a.childCount,0,t),a.childCount+=1,a.node!=null&&(a.node.childCount+=1);for(let e of n.nodes)e.childOffset>o&&(e.childOffset+=1);let s=n.nodes[i];s.parentIndex=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,n){let r=this._clientNodePage;if(r==null)return;let i=this._getParentIndex(e);if(i==null)return;let a=new Set,o=new Map,s=e=>{let n=C(e,this._pageSize),i=r.nodes[n];if(i.childCount>0)for(let e=i.childOffset;e<i.childOffset+i.childCount;++e)s(r.children[e]);let o=i.node?.id??i.nodeBoundingData?.id;if(o==null)throw Error(`Node has no id`);t(o,e),a.add(i)};s(e);let c=r.nodes,l=r.children,u=r.nodes.map(()=>-1),d=[],f=[];for(let e=0;e<c.length;++e){let t=c[e];if(a.has(t))continue;let r=d.length,i=w(e,-1,this._pageSize),s=w(r,-1,this._pageSize);if(t.node&&(t.node.index=s),u[e]=s,d.push(t),i!==s){let e=t.node?.id??t.nodeBoundingData?.id;if(e==null)throw Error(`Node has no id`);n(e,i,s),o.set(i,s)}}for(let e=0;e<d.length;++e){let t=w(e,-1,this._pageSize),n=d[e],r=f.length;for(let e=n.childOffset;e<n.childOffset+n.childCount;++e){let n=l[e];if(n>=0)f.push(n);else{let e=C(n,this._pageSize),r=c[e];if(a.has(r))continue;let i=u[e];f.push(i),r.parentIndex=t}}n.childOffset=r,n.childCount=f.length-r,n.node&&(n.node.childCount=n.childCount)}r.setNodes(d,f),this._updateParentBoundingInformation(u[C(i,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null,n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,o=this._getNodeDescriptor(t);if(o==null)return;for(let i=0;i<o.childCount;i++){let o=this.getChildIndex(t,i),s=this._getNodeDescriptor(o),c=s==null?null:s.nodeBoundingData||s.node;if(c?.serviceMbsInIndexSR!=null&&c.serviceMbsInIndexSR.radius>0){if(e==null)e=A.copyFrom(c.serviceMbsInIndexSR);else{let t=j;r(c.serviceMbsInIndexSR,n,t,a);let i=M;r(e,n,i,a),r(t.union(i),a,e,n)}}}let s=t=>{t!=null&&(t.serviceObbInIndexSR=null,e==null?t.serviceMbsInIndexSR?.invalidate():(t.serviceMbsInIndexSR??=new i,t.serviceMbsInIndexSR.copyFrom(e)),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};s(o.nodeBoundingData),s(o.node),this.invalidateNodeVisibilityCacheInternal(o),t=this._getParentIndex(t)}while(t!=null)}populateChildren(e,t){let n=this._getNodeDescriptor(e),r=this._getPage(e);n.childOffset=r.children.length,n.childCount=t.length;for(let n=0;n<t.length;n++){let i=this._makeRefNode(t[n],e);r.children.push(i)}}getNode(e){let t=this._getNodeDescriptor(e);return t==null?null:t.node}getIndexById(e){let t;return this._forAllNodes((n,r)=>{(n.node!=null&&n.node.id===e||n.nodeBoundingData!=null&&n.nodeBoundingData.id===e)&&(t=r)}),t}getNodeById(e){let t=this.getIndexById(e);return t!=null&&t>=0?this.getNode(t):null}getChildIndex(e,t){let n=this._getPage(e);if(n==null)return-1;let r=n.nodes[C(e,this._pageSize)];return n.children[r.childOffset+t]}_getParentIndex(e){let t=this._getPage(e);return t!=null&&e!==this._rootIndex?t.nodes[C(e,this._pageSize)]?.parentIndex:null}getParent(e){let t=this._getParentIndex(e);return t==null?null:this.getNode(t)}isLeaf(e){let t=this._getNodeDescriptor(e);return t!=null&&t.childCount===0}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes(e=>{e.node!=null&&(e.node.geometryObbInRenderSR=null)})}invalidateVisibilityCache(){this._visibilityCacheVersion=v(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){let t=this._getNodeDescriptor(e);t!=null&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=_(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){let t=this._getNodeDescriptor(e);t!=null&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){let t=this._getNodeDescriptor(e);t!=null&&(this._needsNodeElevationRange?(t.node==null?t.nodeBoundingData:t.node)?.invalidateElevationRange():this.invalidateBoundingVolumeCache(e))}invalidateGeometryVisibility(e){let t=this._getNodeDescriptor(e)?.node;t&&(t.geometryObbInRenderSR=null,t.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){this.rootNode!=null&&this.traverse(this.rootNode,e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0))}_isElevationRangeValid(e){if(!this._needsNodeElevationRange)return!0;let t=e?.node??e?.nodeBoundingData;return!t||t.elevationRangeValid}_updateElevationRange(e,t){let n=this._getNodeDescriptor(e);if(!n)return!1;let r=n?.node??n?.nodeBoundingData;if(!r)return!1;if(r.elevationRangeValid)return t?.expandElevationRange(r),!0;let i=new u,a=!1;for(let t=0;t<n.childCount;t++){let n=this.getChildIndex(e,t),r=this._updateElevationRange(n,i);a||=!r}if(n.childCount===0||a){let e=!n.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(r,e,i)}(i.minElevation===1/0||i.maxElevation===-1/0)&&i.expandElevationRangeValues(0,0);let{minElevation:o,maxElevation:s}=r;return o===i.minElevation&&s===i.maxElevation?(t?.expandElevationRange(r),!0):(n.node?.setElevationRange(i),n.nodeBoundingData?.setElevationRange(i),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(r),!0)}isNodeVisible(e){let t=this._getNodeDescriptor(e);if(t==null)return!0;let n=t.nodeBoundingData;if(n!=null&&!n.serviceMbsInIndexSR)return!0;if(this._isElevationRangeValid(t)&&b(t.visibilityCache,this._visibilityCacheVersion))return x(t.visibilityCache);let r=t.node,i=this._viewportQueries;if(r){let e=i.ensureElevationAgnosticBoundingVolume(r),n=i.isElevationAgnosticBoundingVolumeVisible(e),a=n;if(this._needsNodeElevationRange&&n){let t=i.getNodeObbInRenderSRIndependentOfElevationOffset(r);t!=null&&(a=i.isObbVisibleIndependentOfElevation(e,t))}if(!a)return t.visibilityCache=y(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(r!=null||n!=null)&&t.filterImpact===2){let e=r==null?n==null?null:n.serviceMbsInIndexSR:r.serviceMbsInIndexSR;t.filterImpact=e==null?0:this._computeNodeFiltering(e)}let a=r!=null&&t.filterImpact===1,o=(r==null||r.imModificationImpact!==2)&&!a;if(o){let t=r&&(!n||r.visibilityObbInRenderSR)?r:n??null;t!=null&&(this._needsNodeElevationRange&&this._updateElevationRange(e),o=i.isNodeVisible(t))}return t.visibilityCache=y(o,this._visibilityCacheVersion),o}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;let t=this._getNodeDescriptor(e);return t?.node?.geometryObbInRenderSR!=null&&(!this.layerHasModifications||t.node.imModificationImpact!==4)?this._viewportQueries.isGeometryVisible(t.node):!0}_traverseCoverage(e,t,n,r,i){let a=this._getPage(e);if(a==null||t.childCount===0)return;let o=t.childOffset+t.childCount,s=[];for(let e=t.childOffset;e<o;++e){let t=a.children[e],n=this._getNodeDescriptor(t);n?.node!=null&&this.isGeometryVisible(t)&&s.push(n)}r/=s.length;for(let e of s){let t=e.node.index;this._isLoaded(t)||this._isReloading(t)?(i.delta=Math.max(i.delta,n),i.coverage+=r):this._traverseCoverage(t,e,n+1,r,i)}}useNodeAsHole(e){if(this.holeFilling===`off`)return!1;let t=this._getNodeDescriptor(e);if(t==null)return!1;if(this.holeFilling===`always`)return!0;if(b(t.useAsHole,this._version))return x(t.useAsHole);let n={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,n);let r=n.delta*n.coverage<=.5;return t.useAsHole=y(r,this._version),r}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.destroy(),this._nodePages.clear(),this._clientNodePage=null,this._layer=null,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._imModificationUncategorized.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=v(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes(({node:e})=>{e!=null&&(e.imModificationImpact=4,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))}),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes(e=>{if(e!=null){e.filterImpact=2;let t=e.node;t!=null&&this.invalidateNodeVisibilityCache(t.index)}}),this.invalidateVisibilityCache()}update(e,t,n){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this.resetUpdateState(e);let r=!0,i=new D,a=new O,o=this._imModificationUncategorized;o.clear();let s=new Set,c=0;this.traverseVisible((s,l,u)=>{let d=e=>{this._shouldLoadNode(e)&&e.childCount&&(r=!1)};if(!l){let e=S(s,this._pageSize),t=this._getNodeLoadPriority(s);t===1/0&&(t=this._getNodeLoadPriority(u)),h.set(e,Math.max(t,h.get(e)||0)),!this._loadingPages.has(e)&&!this._failedPages.has(e)&&(this._missingPagesAndNodes.add(e),++c),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,t);return}let{node:f,childCount:p}=l;if(this._updateNodeFeatureEstimate(f,a),!f){let e=this._getNodeLoadPriority(s);!this._loadingNodes.has(s)&&!this._failedNodes.has(s)&&(this._missingPagesAndNodes.add(s),h.set(s,e)),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e);return}let m=this._getPage(s);if(!this._useNodePages&&this._missingPagesAndNodes.size===0)for(let e=0;e<p;e++){let t=m.children[l.childOffset+e],n=this._getNodeDescriptor(t);n!=null&&!n.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(h.set(t,this._getNodeLoadPriority(t)),this._prefetchNodes.add(t))}if(f.failed||f.resources.isEmpty){d(f);return}if(this._isLoaded(s)){if(i.known+=f.memory,++i.knownNodes,d(f),this._shouldLoadNode(f)||(i.unremoved+=f.memory),this._needsUpdate(f)){let e=this._getNodeLoadPriority(s);h.set(s,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(s)}return}if(f.memory&&(i.known+=f.memory,++i.knownNodes),!this._shouldLoadNode(f)){this._isReloading(s)&&this._updates.remove.push(s);return}if(d(f),f.memory?(i.missing+=f.memory,i.known+=f.memory,++i.knownNodes):++i.missingNodes,e.includes(f.index)){this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._getNodeLoadPriority(s)),this._updates.cancel=this._updates.cancel.filter(e=>e!==f.index);return}if(!t.done&&this._enable(f)){t.madeProgress();return}let g=this._getNodeLoadPriority(s);h.set(s,g),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,g),this._updates.add.push(s),this.layerHasModifications&&n&&f!=null&&f.imModificationImpact===4&&o.push(s)},s),this._frameNumber++,this._prioritizeMissingNodesAndPages(),this._removeUnusedNodePages(s,c),this._handleModifications(n,o),this._updateUnloadedMemoryEstimate(i),this._featureEstimate.estimate=this._computeFeatureEstimate(a),this._featureEstimate.leavesReached=r,this._updates.add.filterInPlace(e=>h.get(e)>=this._maxUnloadedPrio).sort((e,t)=>h.get(e)-h.get(t)),this._updates.update.sort((e,t)=>h.get(e)-h.get(t)),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.size,this._dirty=this._indexMissing>0,h.clear()}_updateUnloadedMemoryEstimate(e){this._unloadedMemoryEstimate=e.missing-e.unremoved,e.knownNodes>3&&e.missingNodes>0&&(this._unloadedMemoryEstimate+=e.known/e.knownNodes*e.missingNodes),this._unloadedMemoryEstimate=Math.max(0,this._unloadedMemoryEstimate)*.8}resetUpdateState(e){this._maxUnloadedPrio=-1/0,this._maxProcessingPrio=-1/0,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),h.clear()}_prioritizeMissingNodesAndPages(){let e=this._prioritizedMissingNodeAndPageIds;e.length=0,this._missingPagesAndNodes.forEach(t=>e.push(t)),e.sort((e,t)=>h.get(e)-h.get(t)),e.length>0&&(this._maxUnloadedPrio=h.get(e[e.length-1]),this._prefetchNodes.clear())}_handleModifications(e,t){this.layerHasModifications&&this._updates.add.length!==0&&(t.length>0&&e?.(t),this._updates.add.filterInPlace(e=>{let t=this._getNodeDescriptor(e),n=t?.node==null||t.node.imModificationImpact!==2;return n||this.invalidateNodeVisibilityCache(e),n}))}checkFeatureTarget(e,t){let n=this._viewportQueries.updateScreenSpaceErrorBias(t),r=t,i=t,a=n,o=10;for(;o--;){let n=new O;if(this._updateFeatureEstimate(r,n),this._computeFeatureEstimate(n)<=e){if(r>=t||n.missingNodes>0||o===0)break;a=r,r=(r+i)*.5}else i=r,r=(r+a)*.5}return this._version=v(this._version),this._viewportQueries.updateScreenSpaceErrorBias(n),Math.min(t,r)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;let n=e.size,r=this._nodePages,i=r.size+this._loadingPages.size+t;if(i>P&&i>n){let t=[];for(let[n,i]of r)i.numNodesWithLoadedChildren===0&&!e.has(n)&&t.push([i.lastTraversed,n]);t.sort((e,t)=>e[0]-t[0]).some(e=>{let t=e[1];return this._deleteNodePage(t),r.size<=P})}}_updateFeatureEstimate(e,t){this._version=v(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible((e,n)=>this._updateNodeFeatureEstimate(n?.node,t))}_updateNodeFeatureEstimate(e,t){e!=null&&!e.failed&&this._shouldLoadNode(e)&&(e.numFeatures==null?++t.missingNodes:(t.numFeatures+=e.numFeatures,++t.knownNodes))}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._prioritizedMissingNodeAndPageIds,this._missingPagesAndNodes)}prefetch(){let e=this._prioritizedPrefetchNodes;return this._prefetchNodes.forEach(t=>e.push(t)),e.sort((e,t)=>h.get(e)-h.get(t)),this._load(e,this._prefetchNodes)}_load(e,t){if(e.length===0||!this._canRequest(this.urlPrefix))return!1;for(;e.length>0&&this._canRequest(this.urlPrefix);){let n=e[e.length-1];e.length--,t.delete(n),this._useNodePages&&n>=0?this._loadPage(n):this._loadNode(n)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.size>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(e==null)return null;let t=e.index,n=this._getNodeDescriptor(t);if(!n)return null;let r=n?.traversalState;if(r&&b(r.version,this._version))return r;let i=this._viewportQueries.getLodLevel(e),a=this._viewportQueries.hasLOD(e),o=!0;if(a){let e=this._getParentIndex(t);if(e!=null){let t=this._getNodeDescriptor(e)?.traversalState;o=!!t&&i>t.lodLevel}else o=i>0}else o=e.childCount===0;return r?(r.lodLevel=i,r.isChosen=o,r.version=y(!0,this._version),r):(r=new s(a,o,i,y(!0,this._version)),n.traversalState=r,r)}_loadNode(e){if(this._loadingNodes.has(e)){this._logger.error(`Node[${e}] already loading`);return}this._loadingNodes.add(e);let n=this._getNodeDescriptor(e);if(n.node){this._logger.error(`Node[${e}] already in descriptor`);return}let r=n.nodeBoundingData;if(r==null){this._failedNodes.add(e);return}let i=r.id,a=this.urlPrefix+i,o=()=>{this._loadingNodes.delete(e),this._missingPagesAndNodes.size===0&&this._loadingNodes.size===0&&this.requestUpdate()};(e>=0?this._requester.request(a,`json`):this._clientNodeLoader.loadNodeJSON(i)).then(t=>{o();let n=this._validateNode(i,t);if(n==null)return;n.obb&&this.invalidateNodeVisibilityCache(e);let r=this._addNode(n,e);this.nodeTraversalState(r)}).catch(n=>{o(),t(n)||(this._logger.error(`#loadNode()`,this._layer,`Error loading node: `+a),this._failedNodes.add(e))})}_validateNode(e,t){if(typeof t!=`object`||!t||t.id!==e)return this._logger.error(`#validateNode()`,this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error(`#validateNode()`,this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&t.sharedResource.href!==`./shared`&&t.sharedResource.href!==`./shared/`&&this._logger.warn(`#validateNode()`,this._layer,`Invalid shared resource href on node "${e}"`);let n=t.geometryData;n!=null&&!(Array.isArray(n)&&n.length===0)&&!(Array.isArray(n)&&n.length===1&&n[0].href===`./geometries/0`)&&this._logger.warn(`#validateNode()`,this._layer,`Invalid geometry data on node "${e}"`);let r=t.attributeData,o=this._layer.attributeStorageInfo;r!=null&&(!Array.isArray(r)||r.some((e,t)=>e.href!==`./attributes/${o?.[t]?.key??`f_${t}`}/0`))&&this._logger.warn(`#validateNode()`,this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn(`#validateNode()`,this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);let s=t.hasOwnProperty(`obb`)&&!this.ignoreServiceObb?t.obb:void 0,c=t.featureData?.length===1&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,u=Array.isArray(t.children)?t.children.map(t=>{if(t==null)return null;let n=t=>this._logger.error(`#validateNode()`,this._layer,`Invalid node reference on node ${e}: ${t}`);if(typeof t.id==`number`)n(`id ${t.id} is a number instead of a string.`);else if(typeof t.id!=`string`||!Array.isArray(t.mbs))return n(`Missing or invalid id.`),null;if(!Array.isArray(t.mbs))return n(`Invalid bounding volume on reference ${t.id}.`),null;let r=new a(`${t.id}`,new i(t.mbs));return r.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty(`obb`)&&t.obb?d.fromJSON(t.obb):null,r.visibilityObbInRenderSR=this._computeVisibilityObb(r),r}).filter(e=>e!=null):null,f=t.featureData?.length??!1,p=t.isEmpty===!0;return new l(e,new i(t.mbs),s,typeof t.version==`string`?t.version:null,{isEmpty:!f&&p,hasSharedResource:t.sharedResource!=null,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:t.geometryData==null?void 0:e},u,Array.isArray(t.lodSelection)?t.lodSelection:null,c)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes(e=>{e.node!=null&&(e.node.failed=!1)})}_getNodeLoadPriority(e){let t=this._getNodeDescriptor(e),n=this._getParentIndex(e);if(t==null||n==null&&t.node==null)return n==null?1/0:this._getNodeLoadPriority(n);let r=0;t.node&&n!=null&&(r=this._getNodeDescriptor(n).traversalState?.lodLevel??0);let i=this._getHoleBonus(e);return-(this._viewportQueries.distToCameraPOIRay(t.nodeBoundingData??t.node)*(1+r)+r*this._progressiveLoadPenaltyWeight*this._viewportQueries.distCameraToPOI())+i}_getHoleBonus(e){return this._hasLoadedAncestor(e)?0:this._progressiveLoadPenaltyWeight*this._viewportQueries.distCameraToPOI()}_hasLoadedAncestor(e){let t=this._getParentIndex(e);for(;t!=null;){if(this._isLoaded(t))return!0;t=this._getParentIndex(t)}return!1}traverseVisible(e,t){let n=this._getNodeDescriptor(this._rootIndex);n==null?e(this._rootIndex,null,null):this._traverseVisible(this._rootIndex,null,n,e,t)}_traverseVisible(e,t,n,r,i){let a=S(e,this._pageSize);if(i&&i.add(a),n.node&&n.childCount===0){this.isGeometryVisible(e)&&r(e,n,t);return}if(!this.isNodeVisible(e)||(r(e,n,t),n.node==null))return;let o=this.nodeTraversalState(n.node);if(o?.nodeHasLOD&&o.lodLevel===this._maxLodLevel)return;let s=this._getPageFromPageIndex(a);for(let t=0;t<n.childCount;t++){let a=s.children[n.childOffset+t],o=this._getNodeDescriptor(a);if(o)this._traverseVisible(a,e,o,r,i);else{if(i){let e=S(a,this._pageSize);i.add(e)}r(a,null,e)}}}traverse(e,t){for(let n of this.traverseValues(e,t));}*traverseValues(e,t){t(e)&&(yield e,yield*this._traverseDescendantValues(e,t))}*_traverseDescendantValues(e,t){let n=e.index,r=this._pageSize,i=S(n,r),a=this._getPageFromPageIndex(i);if(a==null)return;let o=this._frameNumber,s=this._nodePages,c=C(n,r),l=a.nodes[c],u=l.childCount;if(a.lastTraversed=o,u===0)return;let d=[],f=[],p=0;{let{childOffset:e,childCount:t}=l,{children:n}=a;f.length=2**Math.ceil(Math.log2(p+t));for(let r=e;r<e+t;++r){let e=n[r];e>=0?(f[p]=e,++p):d.push(e)}}if(d.length>0){let e=this._clientNodePage;if(e){let n=e.children,r=0;for(;r<d.length;){let i=d[r];++r;let a=-i-1,o=e.nodes[a],s=o.node;if(!s||!t(s))continue;yield s;let{childCount:c}=o;if(c===0)continue;let{childOffset:l}=o,u=l+c;for(let e=l;e<u;++e)d.push(n[e])}}}if(p>0){let e=0;if(r>0){let n=i*r,c=a,l=c.nodes;for(;e<p;){let i=f[e];++e;let a;if(n<=i&&i<n+r)a=c;else{let e=i/r|0,t=s.get(e);if(t===void 0)continue;a=t,a.lastTraversed=o,c=a,l=c.nodes,n=r*e}let u=i-n,d=l[u],m=d?.node;if(m==null||t(m)===!1||(yield m,d.node==null))continue;let{childCount:h}=d;if(h===0)continue;let g=p+h;for(f.length<g&&(f.length=2**Math.ceil(Math.log2(p+h)));f.length<p+h;)f.length+=f.length;let _=a.children,{childOffset:v}=d,y=v+h;for(let e=v;e<y;++e)f[p]=_[e],++p}}else{let n=s.get(0);if(n)for(;e<p;){let r=f[e++],i=n.nodes[r],a=i.node;if(!a||!t(a))continue;yield a;let{childCount:o}=i;if(o===0)continue;f.length=Math.max(f.length,2**Math.ceil(Math.log2(p+o)));let s=n.children,{childOffset:c}=i,l=c+o;for(let e=c;e<l;++e)f[p]=s[e],++p}}}}traverseDescendants(e,t){for(let n of this._traverseDescendantValues(e,t));}updateChildrenLoaded(e,t){let n=this.getNode(e);for(;n!=null;){let e=n.childrenLoaded,r=e+t;n.childrenLoaded=r;let i=e===0?1:r===0?-1:0,a=n.index;if(i!==0){let e=this._getPage(a);e.numNodesWithLoadedChildren+=i}n=this.getParent(a)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this._needsNodeElevationRange=t&&!!e&&(e.mode===`relative-to-ground`||e.mode===`relative-to-scene`||e.mode===`on-the-ground`),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes(e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.nodeBoundingData?.invalidateElevationRange()})}_forAllNodes(e){if(this._clientNodePage!=null){let t=this._clientNodePage;for(let n=0;n<t.nodes.length;n++)e(t.nodes[n],-(n+1))}for(let[t,n]of this._nodePages){let r=t*this._pageSize;for(let t=0;t<n.nodes.length;t++)e(n.nodes[t],r+t)}}clearCaches(){if(this._useNodePages){let e=this._nodePages,t=new Set;this.traverseVisible(e=>t.add(S(e,this._pageSize)));for(let[n,r]of e)if(r.numNodesWithLoadedChildren===0&&!t.has(n))this._deleteNodePage(n);else for(let e of r.nodes)e.traversalState=null}}_deleteNodePage(e){if(!this._nodePages.has(e)){this._logger.error(`Destroying non-existent page ${e}`);return}let t=this._nodePages.get(e);this._nodePages.delete(e),t?.destroy()}get test(){}}const h=new Map;class g{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}destroy(){this.update.prune(),this.add.prune(),this.remove.prune(),this.cancel.length=0}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function _(e){return c(e,-2)}function v(e){return c(e,2)}function y(e,t){return t+ +!!e}function b(e,t){return(e&-2)===t}function x(e){return(e&1)==1}function S(e,t){return e<0?-1:t>0?e/t|0:0}function C(e,t){return e<0?-e-1:t===0?e:e%t}function w(e,t,n){return t===-1?-(e+1):n===0?e:t*n+e}const T=[[`maxScreenThreshold`,1],[`screenSpaceRelative`,2],[`removedFeatureDiameter`,3],[`distanceRangeFromDefaultCamera`,4]];function E(e){if(e){for(let t=0;t<e.length;t++)for(let n of T)if(n[0]===e[t].metricType)return{lodMetric:n[1],maxError:e[t].maxError}}return{lodMetric:0,maxError:0}}class D{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class O{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function k(e){return Math.sqrt(4/Math.PI*e)}const A=new i,j=new i,M=new i,N=n(),P=has(`esri-mobile`)?100:300;export{m as I3SIndex,E as selectErrorMetric};
2
+ import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBoundingSphere as r}from"../../../../geometry/projection/projectBoundingSphere.js";import{Sphere as i}from"../../../../geometry/support/sphere.js";import{NodeBoundingData as a,Node as o,NodeTraversalState as s}from"./I3SNode.js";import{addWraparound as c}from"./I3SUtil.js";import{ValidatedNode as l}from"./ValidatedNode.js";import{ElevationRange as u}from"../../support/ElevationRange.js";import{Obb as d}from"../../support/orientedBoundingBox.js";class f{constructor(e,t,n,r,i){this.childOffset=e,this.childCount=t,this.visibilityCache=n,this._boundingData=r,this.node=i,this.parentIndex=-1,this.useAsHole=0,this.filterImpact=2,this.traversalState=null}get nodeBoundingData(){return this._boundingData}destroy(){this._boundingData=null,this.node=null,this.traversalState=null}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.nodeBoundingData?.invalidateServiceBVsInRenderSR()}}class p{constructor(e=[],t=[]){this._nodeDescriptors=e,this._children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}destroy(){for(let e of this._nodeDescriptors)e.destroy();this._nodeDescriptors.length=0,this._children.length=0}get nodes(){return this._nodeDescriptors}addNode(e){return this._nodeDescriptors.push(e),this._nodeDescriptors.length-1}setNodes(e,t){this._nodeDescriptors=e,this._children=t}get children(){return this._children}}class m{get _useNodePages(){return this._pageSize>0}constructor(t,n,r,i,o,s,c,l,u,d,f,m,h,_,y,b,x){if(this.viewingMode=t,this._layer=n,this._groundNavigationCheckDistance=i,this._requester=s,this._clientNodeLoader=c,this._viewportQueries=l,this._logger=u,this.holeFilling=d,this._isLoaded=f,this._isReloading=m,this._shouldLoadNode=h,this._enable=_,this._needsUpdate=y,this._computeVisibilityObb=b,this._computeNodeFiltering=x,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=0,this._lodConversion=e=>e,this._isEditable=!1,this.urlPrefix=``,this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=-1/0,this._maxProcessingPrio=1/0,this._version=v(0),this._visibilityCacheVersion=v(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._progressiveLoadPenaltyWeight=10,this._missingPagesAndNodes=new Set,this._prioritizedMissingNodeAndPageIds=[],this._prefetchNodes=new Set,this._prioritizedPrefetchNodes=[],this._updates=new g(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this.isGroundNavigationMode=!1,this._pageQueue=[],this._newPages=[],this._needsNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._isEditable=n.associatedLayer?.infoFor3D!=null,this.isGroundNavigationMode=r,n.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${n.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,o.type===`page`){let e=o.rootPage;switch(this.urlPrefix=o.urlPrefix,this._pageSize=o.pageSize,o.lodMetric){case`maxScreenThreshold`:this._lodMetric=1;break;case`maxScreenThresholdSQ`:this._lodMetric=1,this._lodConversion=k}if(this._isEditable){this._rootIndex=-1;let t=C(o.rootIndex,o.pageSize),n=e.nodes[t],r={nodes:[{index:this._rootIndex,children:[o.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(S(this._rootIndex,this._pageSize),r),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=o.rootIndex;this._addPage(S(o.rootIndex,this._pageSize),e),this._updateParentsAndLevel()}else if(o.type===`node`){this.urlPrefix=o.urlPrefix;let e=new p;if(this._nodePages.set(0,e),this._isEditable){this._clientNodePage=new p;let e={id:`-1`,version:null,mbs:o.rootNode.mbs,obb:o.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:`root`,href:`../root`,mbs:o.rootNode.mbs,obb:o.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new a(e.id),-1);let t=this._validateNode(e.id,e);t&&this._addNode(t,this._rootIndex)}else this._rootIndex=this._makeRefNode(new a(o.rootNode.id),-1);let t=this._validateNode(o.rootNode.id,o.rootNode);t&&this._addNode(t,0)}}addClientNodeToIndex(e,t){let n=new a(e,t),r=this._makeClientRefNode(n,-1);return this._linkChildToParentNode(-1,r),this.requestUpdate(),r}removeClientNodeFromIndex(e,t,n){this._destroyClientRefNode(e,t,n),this.requestUpdate()}_canRequest(e){return!this._requester.isFull(e)}_loadPage(e){if(this._nodePages.has(e)){this._logger.error(`Requested load page [${e}] already loaded`);return}if(this._loadingPages.has(e)){this._logger.error(`Requested load page [${e}] already loading`);return}this._loadingPages.add(e);let n=this.urlPrefix+e;this._requester.request(n,`json`).then(t=>{this._nodePages.has(e)?this._logger.error(`Queued page [${e}] already loaded`):this._pageQueue.push({pageIndex:e,page:t})}).catch(n=>{this._loadingPages.delete(e),t(n)||(this._failedPages.add(e),this._logger.error(`#loadPage()`,this._layer,`Error when loading page ${e}`,n))})}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){let{pageIndex:t,page:n}=this._pageQueue.shift();this._addPage(t,n),this._loadingPages.delete(t),e.madeProgress(),this._needsNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this._needsNodeElevationRange)for(;this._newPages.length>0&&!e.done;)this._nodePages.get(this._newPages.shift())?.nodes.forEach(e=>{let t=e.parentIndex;for(;t!=null&&t!==this._rootIndex;){let e=this.getNode(t);e?.elevationRangeValid&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this._getParentIndex(t)}})}_addPage(e,t){if(this._nodePages.has(e)){this._logger.error(`Page[${e}] reloaded`);return}let n=[],r=[],a=t.nodes.map((t,a)=>{let s=n.length,c=t.children?t.children.length:0;r.push(this._rootIndex);for(let e=0;e<c;e++)n.push(t.children[e]);let l=`${t.index}`,u=d.fromJSON(t.obb),p=new i(u.getCenter(N),u.radius),m=t.mesh?.attribute,h=t.mesh?.geometry,g=t.mesh?.material,v={hasSharedResource:!1,isEmpty:h==null,attributes:m?.resource==null?void 0:`${m.resource}`,geometry:h?.resource==null?void 0:`${h.resource}`,texture:g?.resource==null?void 0:`${g.resource}`,geometryDefinition:h?h.definition:-1,materialDefinition:g?g.definition:-1},y=new o(l,w(a,e,this._pageSize),p,c,0,v,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),h?.featureCount??null,u);return y.visibilityObbInRenderSR=this._computeVisibilityObb(y),y.vertexCount=h?h.vertexCount:0,new f(s,c,_(this._visibilityCacheVersion),null,y)}),s=new p(a,n);e===-1?this._clientNodePage=s:this._nodePages.set(e,s)}_updateParentsAndLevel(){let e=[],t=(t,n,r)=>{let i=this._getPage(t);if(i!=null){let a=C(t,this._pageSize),o=i.nodes[a];o.parentIndex=n??-1;let s=o.node;s!=null&&(s.level=r,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){let n=e.pop(),r=this.getNode(n);if(r!=null)for(let e=0;e<r.childCount;e++)t(this.getChildIndex(r.index,e),n,r.level+1),this._maxLevel=Math.max(this._maxLevel,r.level+1)}}_getPage(e){let t=S(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeDescriptor(e){let t=this._getPage(e);return t==null?null:(t.lastTraversed=this._frameNumber,t.nodes[C(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);let n=this.getParent(t),r=n==null?0:n.level+1;this._maxLevel=Math.max(this._maxLevel,e.children?r+1:r);let{lodMetric:i,maxError:a}=E(e.lodSelection),s=this._getNodeDescriptor(t);if(s.node!=null)return this._logger.error(`Loaded node[${t}] already in descriptor`),s.node;let c=new o(e.id,t,e.mbs,s.childCount,r,e.resources,e.version,i,a,e.numFeatures,e.obb?d.fromJSON(e.obb):null);s.node=c,c.visibilityObbInRenderSR=this._computeVisibilityObb(c);let l=s.nodeBoundingData;return l!=null&&(l.serviceMbsInIndexSR??=e.mbs,c.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=c.visibilityObbInRenderSR),c}_makeRefNode(e,t){let n=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(n==null)return-1;let r=n.nodes.length,i=new f(0,0,_(this._visibilityCacheVersion),e,null);return n.addNode(i),i.parentIndex=t,e.invalidateServiceBVsInRenderSR(),r}_makeClientRefNode(e,t){let n=this._clientNodePage;if(n==null)return-1;if(t>=0)throw Error(`I3SIndex::client side nodes can not be made children of service side nodes.`);let r=-(n.nodes.length+1),i=new f(0,0,_(this._visibilityCacheVersion),e,null);return n.addNode(i),i.parentIndex=t,e.invalidateServiceBVsInRenderSR(),r}_linkChildToParentNode(e,t){let n=this._clientNodePage;if(n==null||e>=0)return;let r=C(e,this._pageSize),i=C(t,this._pageSize),a=n.nodes[r],o=a.childOffset;n.children.splice(a.childOffset+a.childCount,0,t),a.childCount+=1,a.node!=null&&(a.node.childCount+=1);for(let e of n.nodes)e.childOffset>o&&(e.childOffset+=1);let s=n.nodes[i];s.parentIndex=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,n){let r=this._clientNodePage;if(r==null)return;let i=this._getParentIndex(e);if(i==null)return;let a=new Set,o=new Map,s=e=>{let n=C(e,this._pageSize),i=r.nodes[n];if(i.childCount>0)for(let e=i.childOffset;e<i.childOffset+i.childCount;++e)s(r.children[e]);let o=i.node?.id??i.nodeBoundingData?.id;if(o==null)throw Error(`Node has no id`);t(o,e),a.add(i)};s(e);let c=r.nodes,l=r.children,u=r.nodes.map(()=>-1),d=[],f=[];for(let e=0;e<c.length;++e){let t=c[e];if(a.has(t))continue;let r=d.length,i=w(e,-1,this._pageSize),s=w(r,-1,this._pageSize);if(t.node&&(t.node.index=s),u[e]=s,d.push(t),i!==s){let e=t.node?.id??t.nodeBoundingData?.id;if(e==null)throw Error(`Node has no id`);n(e,i,s),o.set(i,s)}}for(let e=0;e<d.length;++e){let t=w(e,-1,this._pageSize),n=d[e],r=f.length;for(let e=n.childOffset;e<n.childOffset+n.childCount;++e){let n=l[e];if(n>=0)f.push(n);else{let e=C(n,this._pageSize),r=c[e];if(a.has(r))continue;let i=u[e];f.push(i),r.parentIndex=t}}n.childOffset=r,n.childCount=f.length-r,n.node&&(n.node.childCount=n.childCount)}r.setNodes(d,f),this._updateParentBoundingInformation(u[C(i,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null,n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,o=this._getNodeDescriptor(t);if(o==null)return;for(let i=0;i<o.childCount;i++){let o=this.getChildIndex(t,i),s=this._getNodeDescriptor(o),c=s==null?null:s.nodeBoundingData||s.node;if(c?.serviceMbsInIndexSR!=null&&c.serviceMbsInIndexSR.radius>0){if(e==null)e=A.copyFrom(c.serviceMbsInIndexSR);else{let t=j;r(c.serviceMbsInIndexSR,n,t,a);let i=M;r(e,n,i,a),r(t.union(i),a,e,n)}}}let s=t=>{t!=null&&(t.serviceObbInIndexSR=null,e==null?t.serviceMbsInIndexSR?.invalidate():(t.serviceMbsInIndexSR??=new i,t.serviceMbsInIndexSR.copyFrom(e)),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};s(o.nodeBoundingData),s(o.node),this.invalidateNodeVisibilityCacheInternal(o),t=this._getParentIndex(t)}while(t!=null)}populateChildren(e,t){let n=this._getNodeDescriptor(e),r=this._getPage(e);n.childOffset=r.children.length,n.childCount=t.length;for(let n=0;n<t.length;n++){let i=this._makeRefNode(t[n],e);r.children.push(i)}}getNode(e){let t=this._getNodeDescriptor(e);return t==null?null:t.node}getIndexById(e){let t;return this._forAllNodes((n,r)=>{(n.node!=null&&n.node.id===e||n.nodeBoundingData!=null&&n.nodeBoundingData.id===e)&&(t=r)}),t}getNodeById(e){let t=this.getIndexById(e);return t!=null&&t>=0?this.getNode(t):null}getChildIndex(e,t){let n=this._getPage(e);if(n==null)return-1;let r=n.nodes[C(e,this._pageSize)];return n.children[r.childOffset+t]}_getParentIndex(e){let t=this._getPage(e);return t!=null&&e!==this._rootIndex?t.nodes[C(e,this._pageSize)]?.parentIndex:null}getParent(e){let t=this._getParentIndex(e);return t==null?null:this.getNode(t)}isLeaf(e){let t=this._getNodeDescriptor(e);return t!=null&&t.childCount===0}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes(e=>{e.node!=null&&(e.node.geometryObbInRenderSR=null)})}invalidateVisibilityCache(){this._visibilityCacheVersion=v(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){let t=this._getNodeDescriptor(e);t!=null&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=_(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){let t=this._getNodeDescriptor(e);t!=null&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){let t=this._getNodeDescriptor(e);t!=null&&(this._needsNodeElevationRange?(t.node==null?t.nodeBoundingData:t.node)?.invalidateElevationRange():this.invalidateBoundingVolumeCache(e))}invalidateGeometryVisibility(e){let t=this._getNodeDescriptor(e)?.node;t&&(t.geometryObbInRenderSR=null,t.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){this.rootNode!=null&&this.traverse(this.rootNode,e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0))}_isElevationRangeValid(e){if(!this._needsNodeElevationRange)return!0;let t=e?.node??e?.nodeBoundingData;return!t||t.elevationRangeValid}_updateElevationRange(e,t){let n=this._getNodeDescriptor(e);if(!n)return!1;let r=n?.node??n?.nodeBoundingData;if(!r)return!1;if(r.elevationRangeValid)return t?.expandElevationRange(r),!0;let i=new u,a=!1;for(let t=0;t<n.childCount;t++){let n=this.getChildIndex(e,t),r=this._updateElevationRange(n,i);a||=!r}if(n.childCount===0||a){let e=!n.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(r,e,i)}(i.minElevation===1/0||i.maxElevation===-1/0)&&i.expandElevationRangeValues(0,0);let{minElevation:o,maxElevation:s}=r;return o===i.minElevation&&s===i.maxElevation?(t?.expandElevationRange(r),!0):(n.node?.setElevationRange(i),n.nodeBoundingData?.setElevationRange(i),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(r),!0)}isNodeVisible(e){let t=this._getNodeDescriptor(e);if(t==null)return!0;let n=t.nodeBoundingData;if(n!=null&&!n.serviceMbsInIndexSR)return!0;if(this._isElevationRangeValid(t)&&b(t.visibilityCache,this._visibilityCacheVersion))return x(t.visibilityCache);let r=t.node,i=this._viewportQueries;if(r){let e=i.ensureElevationAgnosticBoundingVolume(r),n=i.isElevationAgnosticBoundingVolumeVisible(e,this.isGroundNavigationMode?this._groundNavigationCheckDistance:0),a=n;if(this._needsNodeElevationRange&&n){let t=i.getNodeObbInRenderSRIndependentOfElevationOffset(r);t!=null&&(a=i.isObbVisibleIndependentOfElevation(e,t))}if(!a)return t.visibilityCache=y(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(r!=null||n!=null)&&t.filterImpact===2){let e=r==null?n==null?null:n.serviceMbsInIndexSR:r.serviceMbsInIndexSR;t.filterImpact=e==null?0:this._computeNodeFiltering(e)}let a=r!=null&&t.filterImpact===1,o=(r==null||r.imModificationImpact!==2)&&!a;if(o){let t=r&&(!n||r.visibilityObbInRenderSR)?r:n??null;t!=null&&(this._needsNodeElevationRange&&this._updateElevationRange(e),o=i.isNodeVisible(t,this.isGroundNavigationMode))}return t.visibilityCache=y(o,this._visibilityCacheVersion),o}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;let t=this._getNodeDescriptor(e);return t?.node?.geometryObbInRenderSR!=null&&(!this.layerHasModifications||t.node.imModificationImpact!==4)?this._viewportQueries.isGeometryVisible(t.node,this.isGroundNavigationMode):!0}_traverseCoverage(e,t,n,r,i){let a=this._getPage(e);if(a==null||t.childCount===0)return;let o=t.childOffset+t.childCount,s=[];for(let e=t.childOffset;e<o;++e){let t=a.children[e],n=this._getNodeDescriptor(t);n?.node!=null&&this.isGeometryVisible(t)&&s.push(n)}r/=s.length;for(let e of s){let t=e.node.index;this._isLoaded(t)||this._isReloading(t)?(i.delta=Math.max(i.delta,n),i.coverage+=r):this._traverseCoverage(t,e,n+1,r,i)}}useNodeAsHole(e){if(this.holeFilling===`off`)return!1;let t=this._getNodeDescriptor(e);if(t==null)return!1;if(this.holeFilling===`always`)return!0;if(b(t.useAsHole,this._version))return x(t.useAsHole);let n={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,n);let r=n.delta*n.coverage<=.5;return t.useAsHole=y(r,this._version),r}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.destroy(),this._nodePages.clear(),this._clientNodePage=null,this._layer=null,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._imModificationUncategorized.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=v(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes(({node:e})=>{e!=null&&(e.imModificationImpact=4,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))}),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes(e=>{if(e!=null){e.filterImpact=2;let t=e.node;t!=null&&this.invalidateNodeVisibilityCache(t.index)}}),this.invalidateVisibilityCache()}update(e,t,n){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this.resetUpdateState(e);let r=!0,i=new D,a=new O,o=this._imModificationUncategorized;o.clear();let s=new Set,c=0;this.traverseVisible((s,l,u)=>{let d=e=>{this._shouldLoadNode(e)&&e.childCount&&(r=!1)};if(!l){let e=S(s,this._pageSize),t=this._getNodeLoadPriority(s);t===1/0&&(t=this._getNodeLoadPriority(u)),h.set(e,Math.max(t,h.get(e)||0)),!this._loadingPages.has(e)&&!this._failedPages.has(e)&&(this._missingPagesAndNodes.add(e),++c),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,t);return}let{node:f,childCount:p}=l;if(this._updateNodeFeatureEstimate(f,a),!f){let e=this._getNodeLoadPriority(s);!this._loadingNodes.has(s)&&!this._failedNodes.has(s)&&(this._missingPagesAndNodes.add(s),h.set(s,e)),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e);return}let m=this._getPage(s);if(!this._useNodePages&&this._missingPagesAndNodes.size===0)for(let e=0;e<p;e++){let t=m.children[l.childOffset+e],n=this._getNodeDescriptor(t);n!=null&&!n.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(h.set(t,this._getNodeLoadPriority(t)),this._prefetchNodes.add(t))}if(f.failed||f.resources.isEmpty){d(f);return}if(this._isLoaded(s)){if(i.known+=f.memory,++i.knownNodes,d(f),this._shouldLoadNode(f)||(i.unremoved+=f.memory),this._needsUpdate(f)){let e=this._getNodeLoadPriority(s);h.set(s,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(s)}return}if(f.memory&&(i.known+=f.memory,++i.knownNodes),!this._shouldLoadNode(f)){this._isReloading(s)&&this._updates.remove.push(s);return}if(d(f),f.memory?(i.missing+=f.memory,i.known+=f.memory,++i.knownNodes):++i.missingNodes,e.includes(f.index)){this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._getNodeLoadPriority(s)),this._updates.cancel=this._updates.cancel.filter(e=>e!==f.index);return}if(!t.done&&this._enable(f)){t.madeProgress();return}let g=this._getNodeLoadPriority(s);h.set(s,g),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,g),this._updates.add.push(s),this.layerHasModifications&&n&&f!=null&&f.imModificationImpact===4&&o.push(s)},s),this._frameNumber++,this._prioritizeMissingNodesAndPages(),this._removeUnusedNodePages(s,c),this._handleModifications(n,o),this._updateUnloadedMemoryEstimate(i),this._featureEstimate.estimate=this._computeFeatureEstimate(a),this._featureEstimate.leavesReached=r,this._updates.add.filterInPlace(e=>h.get(e)>=this._maxUnloadedPrio).sort((e,t)=>h.get(e)-h.get(t)),this._updates.update.sort((e,t)=>h.get(e)-h.get(t)),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.size,this._dirty=this._indexMissing>0,h.clear()}_updateUnloadedMemoryEstimate(e){this._unloadedMemoryEstimate=e.missing-e.unremoved,e.knownNodes>3&&e.missingNodes>0&&(this._unloadedMemoryEstimate+=e.known/e.knownNodes*e.missingNodes),this._unloadedMemoryEstimate=Math.max(0,this._unloadedMemoryEstimate)*.8}resetUpdateState(e){this._maxUnloadedPrio=-1/0,this._maxProcessingPrio=-1/0,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),h.clear()}_prioritizeMissingNodesAndPages(){let e=this._prioritizedMissingNodeAndPageIds;e.length=0,this._missingPagesAndNodes.forEach(t=>e.push(t)),e.sort((e,t)=>h.get(e)-h.get(t)),e.length>0&&(this._maxUnloadedPrio=h.get(e[e.length-1]),this._prefetchNodes.clear())}_handleModifications(e,t){this.layerHasModifications&&this._updates.add.length!==0&&(t.length>0&&e?.(t),this._updates.add.filterInPlace(e=>{let t=this._getNodeDescriptor(e),n=t?.node==null||t.node.imModificationImpact!==2;return n||this.invalidateNodeVisibilityCache(e),n}))}checkFeatureTarget(e,t){let n=this._viewportQueries.updateScreenSpaceErrorBias(t),r=t,i=t,a=n,o=10;for(;o--;){let n=new O;if(this._updateFeatureEstimate(r,n),this._computeFeatureEstimate(n)<=e){if(r>=t||n.missingNodes>0||o===0)break;a=r,r=(r+i)*.5}else i=r,r=(r+a)*.5}return this._version=v(this._version),this._viewportQueries.updateScreenSpaceErrorBias(n),Math.min(t,r)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;let n=e.size,r=this._nodePages,i=r.size+this._loadingPages.size+t;if(i>P&&i>n){let t=[];for(let[n,i]of r)i.numNodesWithLoadedChildren===0&&!e.has(n)&&t.push([i.lastTraversed,n]);t.sort((e,t)=>e[0]-t[0]).some(e=>{let t=e[1];return this._deleteNodePage(t),r.size<=P})}}_updateFeatureEstimate(e,t){this._version=v(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible((e,n)=>this._updateNodeFeatureEstimate(n?.node,t))}_updateNodeFeatureEstimate(e,t){e!=null&&!e.failed&&this._shouldLoadNode(e)&&(e.numFeatures==null?++t.missingNodes:(t.numFeatures+=e.numFeatures,++t.knownNodes))}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._prioritizedMissingNodeAndPageIds,this._missingPagesAndNodes)}prefetch(){let e=this._prioritizedPrefetchNodes;return this._prefetchNodes.forEach(t=>e.push(t)),e.sort((e,t)=>h.get(e)-h.get(t)),this._load(e,this._prefetchNodes)}_load(e,t){if(e.length===0||!this._canRequest(this.urlPrefix))return!1;for(;e.length>0&&this._canRequest(this.urlPrefix);){let n=e[e.length-1];e.length--,t.delete(n),this._useNodePages&&n>=0?this._loadPage(n):this._loadNode(n)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.size>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(e==null)return null;let t=e.index,n=this._getNodeDescriptor(t);if(!n)return null;let r=n?.traversalState;if(r&&b(r.version,this._version))return r;let i=this._viewportQueries.getLodLevel(e),a=this._viewportQueries.hasLOD(e),o=!0;if(a){let e=this._getParentIndex(t);if(e!=null){let t=this._getNodeDescriptor(e)?.traversalState;o=!!t&&i>t.lodLevel}else o=i>0}else o=e.childCount===0;return r?(r.lodLevel=i,r.isChosen=o,r.version=y(!0,this._version),r):(r=new s(a,o,i,y(!0,this._version)),n.traversalState=r,r)}_loadNode(e){if(this._loadingNodes.has(e)){this._logger.error(`Node[${e}] already loading`);return}this._loadingNodes.add(e);let n=this._getNodeDescriptor(e);if(n.node){this._logger.error(`Node[${e}] already in descriptor`);return}let r=n.nodeBoundingData;if(r==null){this._failedNodes.add(e);return}let i=r.id,a=this.urlPrefix+i,o=()=>{this._loadingNodes.delete(e),this._missingPagesAndNodes.size===0&&this._loadingNodes.size===0&&this.requestUpdate()};(e>=0?this._requester.request(a,`json`):this._clientNodeLoader.loadNodeJSON(i)).then(t=>{o();let n=this._validateNode(i,t);if(n==null)return;n.obb&&this.invalidateNodeVisibilityCache(e);let r=this._addNode(n,e);this.nodeTraversalState(r)}).catch(n=>{o(),t(n)||(this._logger.error(`#loadNode()`,this._layer,`Error loading node: `+a),this._failedNodes.add(e))})}_validateNode(e,t){if(typeof t!=`object`||!t||t.id!==e)return this._logger.error(`#validateNode()`,this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error(`#validateNode()`,this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&t.sharedResource.href!==`./shared`&&t.sharedResource.href!==`./shared/`&&this._logger.warn(`#validateNode()`,this._layer,`Invalid shared resource href on node "${e}"`);let n=t.geometryData;n!=null&&!(Array.isArray(n)&&n.length===0)&&!(Array.isArray(n)&&n.length===1&&n[0].href===`./geometries/0`)&&this._logger.warn(`#validateNode()`,this._layer,`Invalid geometry data on node "${e}"`);let r=t.attributeData,o=this._layer.attributeStorageInfo;r!=null&&(!Array.isArray(r)||r.some((e,t)=>e.href!==`./attributes/${o?.[t]?.key??`f_${t}`}/0`))&&this._logger.warn(`#validateNode()`,this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn(`#validateNode()`,this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);let s=t.hasOwnProperty(`obb`)&&!this.ignoreServiceObb?t.obb:void 0,c=t.featureData?.length===1&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,u=Array.isArray(t.children)?t.children.map(t=>{if(t==null)return null;let n=t=>this._logger.error(`#validateNode()`,this._layer,`Invalid node reference on node ${e}: ${t}`);if(typeof t.id==`number`)n(`id ${t.id} is a number instead of a string.`);else if(typeof t.id!=`string`||!Array.isArray(t.mbs))return n(`Missing or invalid id.`),null;if(!Array.isArray(t.mbs))return n(`Invalid bounding volume on reference ${t.id}.`),null;let r=new a(`${t.id}`,new i(t.mbs));return r.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty(`obb`)&&t.obb?d.fromJSON(t.obb):null,r.visibilityObbInRenderSR=this._computeVisibilityObb(r),r}).filter(e=>e!=null):null,f=t.featureData?.length??!1,p=t.isEmpty===!0;return new l(e,new i(t.mbs),s,typeof t.version==`string`?t.version:null,{isEmpty:!f&&p,hasSharedResource:t.sharedResource!=null,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:t.geometryData==null?void 0:e},u,Array.isArray(t.lodSelection)?t.lodSelection:null,c)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes(e=>{e.node!=null&&(e.node.failed=!1)})}_getNodeLoadPriority(e){let t=this._getNodeDescriptor(e),n=this._getParentIndex(e);if(t==null||n==null&&t.node==null)return n==null?1/0:this._getNodeLoadPriority(n);let r=0;t.node&&n!=null&&(r=this._getNodeDescriptor(n).traversalState?.lodLevel??0);let i=this._getHoleBonus(e);return-(this._viewportQueries.distToCameraPOIRay(t.nodeBoundingData??t.node)*(1+r)+r*this._progressiveLoadPenaltyWeight*this._viewportQueries.distCameraToPOI())+i}_getHoleBonus(e){return this._hasLoadedAncestor(e)?0:this._progressiveLoadPenaltyWeight*this._viewportQueries.distCameraToPOI()}_hasLoadedAncestor(e){let t=this._getParentIndex(e);for(;t!=null;){if(this._isLoaded(t))return!0;t=this._getParentIndex(t)}return!1}traverseVisible(e,t){let n=this._getNodeDescriptor(this._rootIndex);n==null?e(this._rootIndex,null,null):this._traverseVisible(this._rootIndex,null,n,e,t)}_traverseVisible(e,t,n,r,i){let a=S(e,this._pageSize);if(i&&i.add(a),n.node&&n.childCount===0){this.isGeometryVisible(e)&&r(e,n,t);return}if(!this.isNodeVisible(e)||(r(e,n,t),n.node==null))return;let o=this.nodeTraversalState(n.node);if(o?.nodeHasLOD&&o.lodLevel===this._maxLodLevel)return;let s=this._getPageFromPageIndex(a);for(let t=0;t<n.childCount;t++){let a=s.children[n.childOffset+t],o=this._getNodeDescriptor(a);if(o)this._traverseVisible(a,e,o,r,i);else{if(i){let e=S(a,this._pageSize);i.add(e)}r(a,null,e)}}}traverse(e,t){for(let n of this.traverseValues(e,t));}*traverseValues(e,t){t(e)&&(yield e,yield*this._traverseDescendantValues(e,t))}*_traverseDescendantValues(e,t){let n=e.index,r=this._pageSize,i=S(n,r),a=this._getPageFromPageIndex(i);if(a==null)return;let o=this._frameNumber,s=this._nodePages,c=C(n,r),l=a.nodes[c],u=l.childCount;if(a.lastTraversed=o,u===0)return;let d=[],f=[],p=0;{let{childOffset:e,childCount:t}=l,{children:n}=a;f.length=2**Math.ceil(Math.log2(p+t));for(let r=e;r<e+t;++r){let e=n[r];e>=0?(f[p]=e,++p):d.push(e)}}if(d.length>0){let e=this._clientNodePage;if(e){let n=e.children,r=0;for(;r<d.length;){let i=d[r];++r;let a=-i-1,o=e.nodes[a],s=o.node;if(!s||!t(s))continue;yield s;let{childCount:c}=o;if(c===0)continue;let{childOffset:l}=o,u=l+c;for(let e=l;e<u;++e)d.push(n[e])}}}if(p>0){let e=0;if(r>0){let n=i*r,c=a,l=c.nodes;for(;e<p;){let i=f[e];++e;let a;if(n<=i&&i<n+r)a=c;else{let e=i/r|0,t=s.get(e);if(t===void 0)continue;a=t,a.lastTraversed=o,c=a,l=c.nodes,n=r*e}let u=i-n,d=l[u],m=d?.node;if(m==null||t(m)===!1||(yield m,d.node==null))continue;let{childCount:h}=d;if(h===0)continue;let g=p+h;for(f.length<g&&(f.length=2**Math.ceil(Math.log2(p+h)));f.length<p+h;)f.length+=f.length;let _=a.children,{childOffset:v}=d,y=v+h;for(let e=v;e<y;++e)f[p]=_[e],++p}}else{let n=s.get(0);if(n)for(;e<p;){let r=f[e++],i=n.nodes[r],a=i.node;if(!a||!t(a))continue;yield a;let{childCount:o}=i;if(o===0)continue;f.length=Math.max(f.length,2**Math.ceil(Math.log2(p+o)));let s=n.children,{childOffset:c}=i,l=c+o;for(let e=c;e<l;++e)f[p]=s[e],++p}}}}traverseDescendants(e,t){for(let n of this._traverseDescendantValues(e,t));}updateChildrenLoaded(e,t){let n=this.getNode(e);for(;n!=null;){let e=n.childrenLoaded,r=e+t;n.childrenLoaded=r;let i=e===0?1:r===0?-1:0,a=n.index;if(i!==0){let e=this._getPage(a);e.numNodesWithLoadedChildren+=i}n=this.getParent(a)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this._needsNodeElevationRange=t&&!!e&&(e.mode===`relative-to-ground`||e.mode===`relative-to-scene`||e.mode===`on-the-ground`),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes(e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.nodeBoundingData?.invalidateElevationRange()})}_forAllNodes(e){if(this._clientNodePage!=null){let t=this._clientNodePage;for(let n=0;n<t.nodes.length;n++)e(t.nodes[n],-(n+1))}for(let[t,n]of this._nodePages){let r=t*this._pageSize;for(let t=0;t<n.nodes.length;t++)e(n.nodes[t],r+t)}}clearCaches(){if(this._useNodePages){let e=this._nodePages,t=new Set;this.traverseVisible(e=>t.add(S(e,this._pageSize)));for(let[n,r]of e)if(r.numNodesWithLoadedChildren===0&&!t.has(n))this._deleteNodePage(n);else for(let e of r.nodes)e.traversalState=null}}_deleteNodePage(e){if(!this._nodePages.has(e)){this._logger.error(`Destroying non-existent page ${e}`);return}let t=this._nodePages.get(e);this._nodePages.delete(e),t?.destroy()}get test(){}}const h=new Map;class g{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}destroy(){this.update.prune(),this.add.prune(),this.remove.prune(),this.cancel.length=0}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function _(e){return c(e,-2)}function v(e){return c(e,2)}function y(e,t){return t+ +!!e}function b(e,t){return(e&-2)===t}function x(e){return(e&1)==1}function S(e,t){return e<0?-1:t>0?e/t|0:0}function C(e,t){return e<0?-e-1:t===0?e:e%t}function w(e,t,n){return t===-1?-(e+1):n===0?e:t*n+e}const T=[[`maxScreenThreshold`,1],[`screenSpaceRelative`,2],[`removedFeatureDiameter`,3],[`distanceRangeFromDefaultCamera`,4]];function E(e){if(e){for(let t=0;t<e.length;t++)for(let n of T)if(n[0]===e[t].metricType)return{lodMetric:n[1],maxError:e[t].maxError}}return{lodMetric:0,maxError:0}}class D{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class O{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function k(e){return Math.sqrt(4/Math.PI*e)}const A=new i,j=new i,M=new i,N=n(),P=has(`esri-mobile`)?100:300;export{m as I3SIndex,E as selectErrorMetric};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import"../../../../core/has.js";import{normalize as e,length as t,set as n,equals as r,subtract as i,dot as a,len as o,sqrDist as s,copy as c,scale as l,sub as u,scaleAndAdd as d,distance as f,squaredLength as p,squaredDistance as m,add as h}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as g}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as _}from"../../../../geometry/ellipsoidUtils.js";import v from"../../../../geometry/SpatialReference.js";import{getSphericalPCPF as y}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{projectBoundingRect as b}from"../../../../geometry/projection/projectBoundingRect.js";import{projectBoundingSphere as x}from"../../../../geometry/projection/projectBoundingSphere.js";import{getProjector as ee}from"../../../../geometry/projection/projectors.js";import{create as S,fromValues as C}from"../../../../geometry/support/aaBoundingRect.js";import{signedDistance as w,getNormal as T}from"../../../../geometry/support/plane.js";import{isPlateCarree as te,webMercatorValid as ne}from"../../../../geometry/support/spatialReferenceUtils.js";import{Sphere as re}from"../../../../geometry/support/sphere.js";import{evaluateElevationAlignmentAtPoint as E}from"../graphics/elevationAlignmentUtils.js";import{ElevationContext as D}from"../graphics/ElevationContext.js";import{createContextWithoutExpressionSupport as O,extractExpressionInfo as ie}from"../graphics/featureExpressionInfoUtils.js";import{intersectBoundingRectWithMbs as k}from"./I3SUtil.js";import{Frustum as A}from"../../state/Frustum.js";import"../../support/elevationUpdateExtentUtils.js";import{Obb as j,computeOffsetObb as ae}from"../../support/orientedBoundingBox.js";import{SweptSphereCylindricalVolume as oe,SphereGlobal as se,SweptSphereConicalVolume as ce}from"../../support/SweptSphereVolume.js";import{sphereToGeographicExtent as le,intersectsGeographicExtent as ue}from"../../support/sphereExtentUtils.js";const M=1e5;class N{get _frustumPlanes(){return this._frustum.planes}constructor(e,t,n,r,i,a,o,s,c={}){this._indexSR=e,this._renderCoordsHelper=t,this._clippingArea=i,this._elevationProvider=a,this._viewingMode=o,this._options=c,this._viewDirection=g(),this._useFrustumCulling=!1,this._poi=g(),this._cameraPOIDirection=g(),this._elevationContext=null,this.minCenterDistance=1/0,this.maxCenterDistance=0,this.maxLodLevel=2,this._screenspaceErrorBias=c.screenspaceErrorBias||1,this._progressiveLoadFactor=c.progressiveLoadFactor||1,this._frustum=new A(t),this.updateCamera(n,r);let l=this._renderCoordsHelper.spatialReference;this._renderSR=l,this._renderSRSphericalPCPF=y(l),this._isGlobalMode=this._viewingMode===1,this.elevationIntersectionSpatialReference=this._isGlobalMode?this._indexSR.isWebMercator?this._indexSR:this._elevationProvider.spatialReference:l,this.updateElevationInfo(s),this._isECEFOBBInLocalMode=this._indexSR.isWGS84&&(l.isWebMercator||te(l)),this._indexSREllipsoidRadius=_(this._indexSR).radius,this._indexSRSphericalPCPF=y(e),this._projectorIndexSRToIndexSRSphericalPCPF=ee(this._indexSR,this._indexSRSphericalPCPF)}updateElevationInfo(e){e==null?this._elevationContext=null:(this._elevationContext=D.fromElevationInfo(e),this._elevationContext.setFeatureExpressionInfoContext(O(ie(e,!1))))}updateCamera(t,n){this._useFrustumCulling=n,e(this._viewDirection,t.viewForward),n&&this._frustum.update(t),this._halfScreenPixelSizePerDistance=t.screenPixelSizePerDistance/2,this._camPos=t.eye,this._updateCameraPOIDirection(),this.minCenterDistance=1/0,this.maxCenterDistance=0}setPointOfInterest(e){this._poi=e,this._updateCameraPOIDirection()}updateScreenSpaceErrorBias(e){let t=this._screenspaceErrorBias;return this._screenspaceErrorBias=e,t}updateClippingArea(e){this._clippingArea=e}expandElevationRange(e,t,n){if(this._elevationContext==null)return;let r=e.serviceMbsInIndexSR;if(!r)return;let i=this._elevationContext.mode===`relative-to-scene`?`scene`:`ground`,a=this._elevationProvider;if(a.getSphereElevationRange){let e=a.getSphereElevationRange(r,this._indexSR,i);if(e){n.expandElevationRange(e);return}}let[o,s,c]=r.center,l=a.getElevation(o,s,c,this._indexSR,i);l&&n.expandElevationRangeValues(l,l);let u=t?null:a.getRootElevationRange?.();u&&n.expandElevationRange(u)}calculateServiceMbsInRenderSR(e){let{serviceMbsInRenderSR:t}=e;if(t.isValid)return t;let{serviceMbsInIndexSR:n}=e;if(!n?.isValid)return t;let r=G;return x(n,this._indexSR,r,this._renderSR),e.updateServiceMbsInRenderSR(r)}intersectsElevationUpdate(e,t){if(this._isGlobalMode&&this._indexSR.isWebMercator){let n=t.serviceMbsInIndexSR;if(!n?.isValid)return!0;let[r,i]=ne,a=i-r,o=e[2]-e[0]>=a,s=o?0:Math.round((n.center[0]-(e[0]+e[2])/2)/a)*a;return C(o?-1/0:e[0]+s,e[1],o?1/0:e[2]+s,e[3],K),k(K,n)!==0}let n=this.calculateServiceMbsInRenderSR(t);if(!n.isValid)return!0;if(!this._isGlobalMode)return k(e,n)!==0;let r=t.serviceMbsElevationUpdateExtent;return r[0]>r[2]&&(le(n,r),this.elevationIntersectionSpatialReference.isWebMercator&&Number.isFinite(r[0])&&(r[1]=Math.max(-90,r[1]),r[3]=Math.min(90,r[3]),b(r,v.WGS84,r,this.elevationIntersectionSpatialReference)||C(-1/0,-1/0,1/0,1/0,r))),ue(e,r,this.elevationIntersectionSpatialReference)}calculateServiceMbsInRenderSRElevationAdjusted(e){let{serviceMbsInRenderSRElevationAdjusted:t}=e;if(t.isValid)return t;let{serviceMbsInIndexSR:n}=e,r=this.calculateServiceMbsInRenderSR(e);if(!r.isValid||!n?.isValid)return t;let i=G;i.copyFrom(r);let{_elevationContext:a}=this;if(a){let{minElevation:t}=e,{_renderCoordsHelper:r}=this,o=n.center,s=0;if(Number.isFinite(t)){let n=0,c=0,{maxElevation:l}=e,u=o[2];switch(a.mode){case`relative-to-ground`:case`relative-to-scene`:n=a.geometryZWithOffset(u,r)+t-u,c=l-t;break;case`on-the-ground`:n=t-u,c=l-t}s=n+.5*c,i.radius+=.5*c}else i.radius<M&&(s=E(o,this._elevationProvider,a,r)-o[2]);s&&fe(i,s,this._viewingMode)}return e.updateServiceMbsInRenderSRElevationAdjusted(i)}_isGlobalMbsContainingPlanetCenter(e){return this._viewingMode===1&&t(e.center)<=e.radius}calculateMbsConeInRenderSR(e){let{mbsConeInRenderSR:t}=e;if(t)return t;if(!e.elevationRangeValid)return null;let{minElevation:n,maxElevation:r}=e;if(!Number.isFinite(n)||!(n<r))return null;let i=this.calculateServiceMbsInRenderSR(e);if(!i.isValid)return null;let a=this._elevationContext;if(a?.mode===`relative-to-ground`||a?.mode===`relative-to-scene`){let t=e.serviceMbsInIndexSR;if(!t?.isValid)return null;let i=t.center[2],o=a.geometryZWithOffset(i,this._renderCoordsHelper);if(this._viewingMode===2)n+=o,r+=o;else{let e=o-i;n+=e,r+=e}}let o=this._renderCoordsHelper.referenceEllipsoid.radius,s=this._viewingMode===2?new oe(i,n,r):this._isGlobalMbsContainingPlanetCenter(i)?new se(i,o+n,o+r):new ce(i,o+n,o+r);return e.updateMbsConeInRenderSR(s)}getAndUpdateVisibilityObbInRenderSR(e){{let t=e.visibilityObbInRenderSR;if(t)return t}let t=this._indexSREllipsoidRadius*.01,{serviceMbsInIndexSR:r,serviceObbInIndexSR:i}=e;if(i==null||!r||!i.isValid||this._isECEFOBBInLocalMode&&(i.halfSizeX>t||i.halfSizeY>t||i.halfSizeZ>t))return null;{let t=e.serviceObbInRenderSR;if(t==null)t=new j,e.serviceObbInRenderSR=t;else if(t.isValid)return t;let a=r.radius,o=0,s=0,c=i.centerZ,l=this._renderCoordsHelper,u=this._elevationContext;if(u&&e.elevationRangeValid){let{minElevation:t,maxElevation:n}=e;switch(u.mode){case`relative-to-ground`:case`relative-to-scene`:o=u.geometryZWithOffset(c,l)+t-c,s=n-t;break;case`on-the-ground`:o=t-c,s=n-t}}else if(u&&a<M){let e=n(z,i.centerX,i.centerY,c);o=E(e,this._elevationProvider,u,l)-c}let d=s>0,f=d?R:t;return i.transform(f,this._indexSR,this._renderSR,o,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),d&&ae(f,0,s,this._viewingMode,t),t}}getNodeObbInRenderSRIndependentOfElevationOffset(e){{let t=e.visibilityObbInRenderSR??e.serviceObbInRenderSR??null;if(t?.isValid)return t}let t=e.serviceObbInIndexSR;return t?this._viewingMode===2&&Math.max(t.halfSizeX,t.halfSizeY,t.halfSizeZ)>.2*this._indexSREllipsoidRadius?null:(t.transform(R,this._indexSR,this._renderSR,void 0,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),R):null}ensureElevationAgnosticBoundingVolume(e){return!e.elevationAgnosticBoundingVolume.valid&&e.level>0&&(this._viewingMode===1?this._updateElevationAgnosticBoundingVolumeGlobal(e):this._updateElevationAgnosticBoundingVolumeLocal(e)),e.elevationAgnosticBoundingVolume}_updateCameraPOIDirection(){r(this._poi,this._camPos)?this._cameraPOIDirection=this._viewDirection:(i(this._cameraPOIDirection,this._camPos,this._poi),e(this._cameraPOIDirection,this._cameraPOIDirection))}_updateElevationAgnosticBoundingVolumeGlobal(t){let n=this.getNodeObbInRenderSRIndependentOfElevationOffset(t),r=t.elevationAgnosticBoundingVolume,i=-1,s;if(n){let t=z;n.getCenter(t),e(t,t),s=t,n.getCorners(B);for(let n of B){e(n,n);let o=a(n,t);if(o<=0){r.invalidate();return}let s=Math.sqrt(Math.max(0,1-o*o));i=Math.max(i,s)}}else{let n=t.serviceMbsInRenderSR;if(!n.isValid){r.invalidate();return}let{center:a,radius:c}=n,l=o(a);if(l<c){r.invalidate();return}i=c/l,s=e(W,a)}r.set(s,i+_e)}_updateElevationAgnosticBoundingVolumeLocal(e){let t=e.elevationAgnosticBoundingVolume,n=this.getNodeObbInRenderSRIndependentOfElevationOffset(e);if(n){let e=n.getCenter(z);e[2]=0;let r=0,i=V;n.getCorners(B);for(let e of B){e[2]=0;let t=s(i,e);r=Math.max(r,t)}t.set(e,Math.sqrt(r))}else{let n=e.serviceMbsInRenderSR;if(n.isValid){let e=c(z,n.center);e[2]=0,t.set(e,n.radius)}}}isNodeVisible(e){if(!this._isMBSinClippingArea(this.calculateServiceMbsInRenderSR(e)))return!1;if(!this._useFrustumCulling)return!0;let t=this.getAndUpdateVisibilityObbInRenderSR(e);return t?t.intersectsFrustumConservativeApproximation(this._frustumPlanes):this._frustum.intersectsSphere(this.calculateServiceMbsInRenderSRElevationAdjusted(e))}isElevationAgnosticBoundingVolumeVisible(e){return!this._useFrustumCulling||!e.valid?!0:e.intersectsFrustumConservative(this._frustum,this._viewingMode,1)?this._viewingMode!==1||this._isConeVisibleInFrustum(e):!1}_isConeVisibleInFrustum(t){let n=t.radius;if(n>he)return!0;let r=this._frustumPlanes,{center:i,radius:o}=this._frustum.boundingSphere,s=t.getAxis(W),c=a(s,i),f=o+1,p=c-f,m=c+f;if(p<=0)return!0;let h=l(F,s,p),g=l(I,s,m),_=n/Math.sqrt(1-n*n);for(let t of r){let n=T(t),r=e(L,n),i=a(r,s);if(Math.abs(1-i)<ge)continue;let o=H;l(o,s,i),u(o,o,r),e(o,o);let c=de;if(d(c,h,o,p*_),!(w(t,c)<=0)&&(d(c,g,o,m*_),!(w(t,c)<=0)))return!1}return!0}isObbVisibleIndependentOfElevation(e,t){if(!this._useFrustumCulling||!e.valid)return!0;let{center:n,radius:r}=this._frustum.boundingSphere,i=r+1,o=this._frustumPlanes,s=B;if(t.getCorners(s),this._viewingMode===1){let t=e.getAxis(W),r=a(t,n),c=r-i,u=r+i;if(c<=0)return!0;for(let e of o){let n=!0;for(let r of s){let i=a(r,t),o=U;if(l(o,r,c/i),w(e,o)<=0){n=!1;break}let s=U;if(l(s,r,u/i),w(e,s)<=0){n=!1;break}}if(n)return!1}}else{let e=n[2]-i,t=n[2]+i;for(let n of o){let r=!0,i=T(n),a=i[0],o=i[1],c=i[2],l=n[3];for(let n of s){let i=a*n[0]+o*n[1]+l;if(i+c*e<=0||i+c*t<=0){r=!1;break}}if(r)return!1}}return!0}isGeometryVisible(e){return this._useFrustumCulling?e.geometryObbInRenderSR?.intersectsFrustumConservativeApproximation(this._frustumPlanes)??this.isNodeVisible(e):!0}_isMBSinClippingArea(e){return this._clippingArea==null||k(this._clippingArea,e)!==0}_screenSpaceDiameterMbs(e,t){let n=this.calcCameraDistanceToSurfaceAndUpdateMinmaxWithCenterDistance(e);return n<0?pe:t/n/this._halfScreenPixelSizePerDistance}calcCameraDistanceToSurfaceAndUpdateMinmaxWithCenterDistance(e){let t=this.calculateMbsConeInRenderSR(e);if(t==null)return this.calcCameraDistanceToSurfaceAndUpdateMinmaxWithSphere(e);let n=t.calculateSurfaceDistanceFromPoint(this._camPos),r=t.calculateCenterDistanceFromPoint(this._camPos);return this._updateMinMaxDistanceToCenter(r),n}calcCameraDistanceToSurfaceAndUpdateMinmaxWithSphere(e){return this.calcCameraDistanceToCenterAndUpdateMinmax(e)-this.calculateServiceMbsInRenderSRElevationAdjusted(e).radius}calcCameraDistanceToCenterAndUpdateMinmax(e){let t=this.calculateServiceMbsInRenderSRElevationAdjusted(e),n=f(t.center,this._camPos);return this._updateMinMaxDistanceToCenter(n),n}_calculateAngleDependentLoDForSphere(e,n){let r=u(V,e,this._camPos),i=t(e),o=t(r);if(i===0||o===0)return 1;let s=(Math.abs(a(e,r))/i+n)/o;return Math.min(1,s)}calcAngleDependentLoD(e){let n=this.calculateMbsConeInRenderSR(e);if(n==null){let{center:t,radius:n}=this.calculateServiceMbsInRenderSRElevationAdjusted(e);return this._calculateAngleDependentLoDForSphere(t,n)}let{center:r,radius:i}=this.calculateServiceMbsInRenderSR(e);if(this._viewingMode===2)c(q,r),q[2]=n.lowerCenterHeight,c(J,r),J[2]=n.upperCenterHeight;else{let e=t(r);if(e===0)return 1;l(q,r,n.lowerCenterHeight/e),l(J,r,n.upperCenterHeight/e)}let o=this._calculateAngleDependentLoDForSphere(q,i),s=this._calculateAngleDependentLoDForSphere(J,i);if(this._viewingMode===2)c(Y,r),Y[2]=Math.max(n.lowerCenterHeight,Math.min(n.upperCenterHeight,this._camPos[2]));else{let e=t(r);if(e===0)return Math.max(o,s);let i=Math.max(n.lowerCenterHeight,Math.min(n.upperCenterHeight,a(this._camPos,r)/e));l(Y,r,i/e)}return Math.max(o,s,this._calculateAngleDependentLoDForSphere(Y,i))}hasLOD(e){return e.lodMetric!==0}_getDistanceToSurfaceGlobeMode(e,n){let r=t(n.center),o=t(e)-r;l(q,e,a(e,n.center)/p(e));let s=m(n.center,q),c=n.radius;if(s<=c*c)return Math.abs(o);let u=l(q,n.center,1/r),d=c*c/(2*r),g=l(J,u,r-d),_=i(Y,e,g),v=i(Y,_,l(X,u,a(u,_))),y=h(Y,g,l(Y,v,c/t(v))),b=f(e,y);if(o>=Z){let n=i(J,e,y),r=a(n,u)/t(n);r<Q&&(r=$),b/=r}return b}_getDistanceToSurface(e,t){return this._isGlobalMode?this._getDistanceToSurfaceGlobeMode(e,t):P(e,t)}_applyGlobalFlatAngleCorrectionToConeDistance(e,n){n.calculateClosestCenterToPoint(this._camPos,X);let r=t(X);if(r===0||t(this._camPos)-r<Z)return e;let o=i(Y,this._camPos,X),s=t(o);if(s===0)return e;let c=a(o,X)/(s*r);return e/(c<Q?$:c)}calculateScreenSpaceRelativeSphere(e){let t=this.calculateServiceMbsInRenderSRElevationAdjusted(e),n=this._getDistanceToSurface(this._camPos,t),r=n+t.radius;return this._updateMinMaxDistanceToCenter(r),2*n*this._halfScreenPixelSizePerDistance}calculateScreenSpaceRelativeCone(e){let t=e.calculateCenterDistanceFromPoint(this._camPos);this._updateMinMaxDistanceToCenter(t);let n=e.calculateSurfaceDistanceFromPoint(this._camPos);return 2*(this._isGlobalMode?this._applyGlobalFlatAngleCorrectionToConeDistance(n,e):n)*this._halfScreenPixelSizePerDistance}_updateMinMaxDistanceToCenter(e){e>0?(this.minCenterDistance=Math.min(this.minCenterDistance,e),this.maxCenterDistance=Math.max(this.maxCenterDistance,e)):(this.minCenterDistance=0,this.maxCenterDistance=Math.max(this.maxCenterDistance,-e))}getLodLevel(e){if(e.lodMetric===0)return 0;if(e.childCount===0)return this.maxLodLevel;if(this._useFrustumCulling&&this._progressiveLoadFactor<1){let t=this._progressiveLoadFactor*this._screenspaceErrorBias,n=this._screenspaceErrorBias;return this.evaluateLODmetric(e,t)?this.evaluateLODmetric(e,n)?2:1:0}return this.evaluateLODmetric(e,this._screenspaceErrorBias)?this.maxLodLevel:0}evaluateLODmetric(e,t){switch(e.lodMetric){case 1:{let n=this._screenSpaceDiameterMbs(e,(e.serviceMbsInIndexSR?.radius??0)*t);return this._options.angleDependentLoD&&(n*=this.calcAngleDependentLoD(e)),n<e.maxError}case 2:{let n=this.calculateMbsConeInRenderSR(e),r=n?this.calculateScreenSpaceRelativeCone(n):this.calculateScreenSpaceRelativeSphere(e);return e.maxError*t<=r}case 3:return this._screenSpaceDiameterMbs(e,e.maxError)*t<me;case 4:return this.calcCameraDistanceToSurfaceAndUpdateMinmaxWithCenterDistance(e)>e.maxError*t}return!1}distToCameraPOIRay(e){if(e==null)return 0;let t=this.calculateServiceMbsInRenderSRElevationAdjusted(e),n=t.center,r=a(n,this._cameraPOIDirection),i=r*r,o=p(n)-i;return Math.sqrt(o)-t.radius}distCameraToPOI(){return f(this._camPos,this._poi)}}function P(e,t){let n=e[0]-t.center[0],r=e[1]-t.center[1],i=e[2]-t.center[2],a=n*n+r*r,o=t.radius;if(a<=o*o)return Math.abs(i);let s=Math.sqrt(a)-o;return Math.sqrt(i*i+s*s)}const F=g(),I=g(),L=g(),R=new j,z=g(),B=[g(),g(),g(),g(),g(),g(),g(),g()],V=g(),H=g(),de=g(),U=g(),W=g(),G=new re,K=S(),q=g(),J=g(),Y=g(),X=g();function fe(e,n,r){if(r===2)e.center[2]+=n;else{let r=t(e.center);if(r===0){e.radius+=Math.abs(n);return}l(e.center,e.center,1+n/r)}}const pe=.5*Number.MAX_VALUE,me=10,Z=2e5,Q=.08,$=1e-4,he=.9,ge=.01,_e=.001;export{N as default};
2
+ import"../../../../core/has.js";import{normalize as e,add as t,scale as n,length as r,set as i,equals as a,subtract as o,dot as s,len as c,sqrDist as l,copy as u,sub as d,scaleAndAdd as f,distance as p,squaredLength as m,squaredDistance as h}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as g}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as _}from"../../../../geometry/ellipsoidUtils.js";import v from"../../../../geometry/Point.js";import y from"../../../../geometry/SpatialReference.js";import{getSphericalPCPF as b}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{projectBoundingRect as ee}from"../../../../geometry/projection/projectBoundingRect.js";import{projectBoundingSphere as te}from"../../../../geometry/projection/projectBoundingSphere.js";import{getProjector as ne}from"../../../../geometry/projection/projectors.js";import{create as re,fromValues as x}from"../../../../geometry/support/aaBoundingRect.js";import{create as ie,fromPoints as S,distance2 as ae}from"../../../../geometry/support/lineSegment.js";import{signedDistance as C,getNormal as w}from"../../../../geometry/support/plane.js";import{isPlateCarree as oe,webMercatorValid as se}from"../../../../geometry/support/spatialReferenceUtils.js";import{Sphere as T}from"../../../../geometry/support/sphere.js";import{evaluateElevationAlignmentAtPoint as E}from"../graphics/elevationAlignmentUtils.js";import{ElevationContext as ce}from"../graphics/ElevationContext.js";import{createContextWithoutExpressionSupport as le,extractExpressionInfo as ue}from"../graphics/featureExpressionInfoUtils.js";import{intersectBoundingRectWithMbs as D}from"./I3SUtil.js";import{Frustum as de}from"../../state/Frustum.js";import{groundNavigationConstants as fe}from"../../state/utils/groundNavigationUtils.js";import"../../support/elevationUpdateExtentUtils.js";import{Obb as O,computeOffsetObb as pe}from"../../support/orientedBoundingBox.js";import{SweptSphereCylindricalVolume as me,SphereGlobal as he,SweptSphereConicalVolume as k}from"../../support/SweptSphereVolume.js";import{sphereToGeographicExtent as A,intersectsGeographicExtent as j}from"../../support/sphereExtentUtils.js";const M=1e5;class N{get _frustumPlanes(){return this._frustum.planes}constructor(e,t,n,r,i,a,o,s,c={}){this._indexSR=e,this._renderCoordsHelper=t,this._clippingArea=i,this._elevationProvider=a,this._viewingMode=o,this._options=c,this._viewDirection=g(),this._useFrustumCulling=!1,this._poi=g(),this._cameraPOIDirection=g(),this._elevationContext=null,this._checkBelowSegmentEnd=g(),this.minCenterDistance=1/0,this.maxCenterDistance=0,this.maxLodLevel=2,this._screenspaceErrorBias=c.screenspaceErrorBias||1,this._progressiveLoadFactor=c.progressiveLoadFactor||1,this._frustum=new de(t),this.updateCamera(n,r);let l=this._renderCoordsHelper.spatialReference;this._renderSR=l,this._renderSRSphericalPCPF=b(l),this._isGlobalMode=this._viewingMode===1,this.elevationIntersectionSpatialReference=this._isGlobalMode?this._indexSR.isWebMercator?this._indexSR:this._elevationProvider.spatialReference:l,this.updateElevationInfo(s),this._isECEFOBBInLocalMode=this._indexSR.isWGS84&&(l.isWebMercator||oe(l)),this._indexSREllipsoidRadius=_(this._indexSR).radius,this._indexSRSphericalPCPF=b(e),this._projectorIndexSRToIndexSRSphericalPCPF=ne(this._indexSR,this._indexSRSphericalPCPF),this._groundNavigationCheckDistance=fe.i3sNodeDownwardCheckDistanceInMeters/this._renderCoordsHelper.unitInMeters}updateElevationInfo(e){e==null?this._elevationContext=null:(this._elevationContext=ce.fromElevationInfo(e),this._elevationContext.setFeatureExpressionInfoContext(le(ue(e,!1))))}updateCamera(r,i){this._useFrustumCulling=i,e(this._viewDirection,r.viewForward),i&&this._frustum.update(r),this._halfScreenPixelSizePerDistance=r.screenPixelSizePerDistance/2,this._camPos=r.eye,this._updateCameraPOIDirection(),this.minCenterDistance=1/0,this.maxCenterDistance=0,t(this._checkBelowSegmentEnd,this._camPos,n(this._checkBelowSegmentEnd,this._renderCoordsHelper.worldUpAtPosition(this._camPos,this._checkBelowSegmentEnd),-this._groundNavigationCheckDistance))}setPointOfInterest(e){this._poi=e,this._updateCameraPOIDirection()}updateScreenSpaceErrorBias(e){let t=this._screenspaceErrorBias;return this._screenspaceErrorBias=e,t}updateClippingArea(e){this._clippingArea=e}expandElevationRange(e,t,n){if(this._elevationContext==null)return;let r=e.serviceMbsInIndexSR;if(!r)return;let i=this._elevationContext.mode===`relative-to-scene`?`scene`:`ground`,a=this._elevationProvider;if(a.getSphereElevationRange){let e=a.getSphereElevationRange(r,this._indexSR,i);if(e){n.expandElevationRange(e);return}}let[o,s,c]=r.center,l=a.getElevation(o,s,c,this._indexSR,i);l&&n.expandElevationRangeValues(l,l);let u=t?null:a.getRootElevationRange?.();u&&n.expandElevationRange(u)}calculateServiceMbsInRenderSR(e){let{serviceMbsInRenderSR:t}=e;if(t.isValid)return t;let{serviceMbsInIndexSR:n}=e;if(!n?.isValid)return t;let r=G;return te(n,this._indexSR,r,this._renderSR),e.updateServiceMbsInRenderSR(r)}intersectsElevationUpdate(e,t){if(this._isGlobalMode&&this._indexSR.isWebMercator){let n=t.serviceMbsInIndexSR;if(!n?.isValid)return!0;let[r,i]=se,a=i-r,o=e[2]-e[0]>=a,s=o?0:Math.round((n.center[0]-(e[0]+e[2])/2)/a)*a;return x(o?-1/0:e[0]+s,e[1],o?1/0:e[2]+s,e[3],K),D(K,n)!==0}let n=this.calculateServiceMbsInRenderSR(t);if(!n.isValid)return!0;if(!this._isGlobalMode)return D(e,n)!==0;let r=t.serviceMbsElevationUpdateExtent;return r[0]>r[2]&&(A(n,r),this.elevationIntersectionSpatialReference.isWebMercator&&Number.isFinite(r[0])&&(r[1]=Math.max(-90,r[1]),r[3]=Math.min(90,r[3]),ee(r,y.WGS84,r,this.elevationIntersectionSpatialReference)||x(-1/0,-1/0,1/0,1/0,r))),j(e,r,this.elevationIntersectionSpatialReference)}_evaluateElevationAlignmentInIndexSR(e,t){return B.x=e[0],B.y=e[1],B.z=e[2],B.spatialReference=this._indexSR,E(B,this._elevationProvider,t,this._renderCoordsHelper)}calculateServiceMbsInRenderSRElevationAdjusted(e){let{serviceMbsInRenderSRElevationAdjusted:t}=e;if(t.isValid)return t;let{serviceMbsInIndexSR:n}=e,r=this.calculateServiceMbsInRenderSR(e);if(!r.isValid||!n?.isValid)return t;let i=G;i.copyFrom(r);let{_elevationContext:a}=this;if(a){let{minElevation:t}=e,{_renderCoordsHelper:r}=this,o=n.center,s=0;if(Number.isFinite(t)){let n=0,c=0,{maxElevation:l}=e,u=o[2];switch(a.mode){case`relative-to-ground`:case`relative-to-scene`:n=a.geometryZWithOffset(u,r)+t-u,c=l-t;break;case`on-the-ground`:n=t-u,c=l-t}s=n+.5*c,i.radius+=.5*c}else i.radius<M&&(s=this._evaluateElevationAlignmentInIndexSR(o,a)-o[2]);s&&ye(i,s,this._viewingMode)}return e.updateServiceMbsInRenderSRElevationAdjusted(i)}_isGlobalMbsContainingPlanetCenter(e){return this._viewingMode===1&&r(e.center)<=e.radius}calculateMbsConeInRenderSR(e){let{mbsConeInRenderSR:t}=e;if(t)return t;if(!e.elevationRangeValid)return null;let{minElevation:n,maxElevation:r}=e;if(!Number.isFinite(n)||!(n<r))return null;let i=this.calculateServiceMbsInRenderSR(e);if(!i.isValid)return null;let a=this._elevationContext;if(a?.mode===`relative-to-ground`||a?.mode===`relative-to-scene`){let t=e.serviceMbsInIndexSR;if(!t?.isValid)return null;let i=t.center[2],o=a.geometryZWithOffset(i,this._renderCoordsHelper);if(this._viewingMode===2)n+=o,r+=o;else{let e=o-i;n+=e,r+=e}}let o=this._renderCoordsHelper.referenceEllipsoid.radius,s=this._viewingMode===2?new me(i,n,r):this._isGlobalMbsContainingPlanetCenter(i)?new he(i,o+n,o+r):new k(i,o+n,o+r);return e.updateMbsConeInRenderSR(s)}getAndUpdateVisibilityObbInRenderSR(e){{let t=e.visibilityObbInRenderSR;if(t)return t}let t=this._indexSREllipsoidRadius*.01,{serviceMbsInIndexSR:n,serviceObbInIndexSR:r}=e;if(r==null||!n||!r.isValid||this._isECEFOBBInLocalMode&&(r.halfSizeX>t||r.halfSizeY>t||r.halfSizeZ>t))return null;{let t=e.serviceObbInRenderSR;if(t==null)t=new O,e.serviceObbInRenderSR=t;else if(t.isValid)return t;let a=n.radius,o=0,s=0,c=r.centerZ,l=this._renderCoordsHelper,u=this._elevationContext;if(u&&e.elevationRangeValid){let{minElevation:t,maxElevation:n}=e;switch(u.mode){case`relative-to-ground`:case`relative-to-scene`:o=u.geometryZWithOffset(c,l)+t-c,s=n-t;break;case`on-the-ground`:o=t-c,s=n-t}}else if(u&&a<M){let e=i(z,r.centerX,r.centerY,c);o=this._evaluateElevationAlignmentInIndexSR(e,u)-c}let d=s>0,f=d?R:t;return r.transform(f,this._indexSR,this._renderSR,o,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),d&&pe(f,0,s,this._viewingMode,t),t}}getNodeObbInRenderSRIndependentOfElevationOffset(e){{let t=e.visibilityObbInRenderSR??e.serviceObbInRenderSR??null;if(t?.isValid)return t}let t=e.serviceObbInIndexSR;return t?this._viewingMode===2&&Math.max(t.halfSizeX,t.halfSizeY,t.halfSizeZ)>.2*this._indexSREllipsoidRadius?null:(t.transform(R,this._indexSR,this._renderSR,void 0,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),R):null}ensureElevationAgnosticBoundingVolume(e){return!e.elevationAgnosticBoundingVolume.valid&&e.level>0&&(this._viewingMode===1?this._updateElevationAgnosticBoundingVolumeGlobal(e):this._updateElevationAgnosticBoundingVolumeLocal(e)),e.elevationAgnosticBoundingVolume}_updateCameraPOIDirection(){a(this._poi,this._camPos)?this._cameraPOIDirection=this._viewDirection:(o(this._cameraPOIDirection,this._camPos,this._poi),e(this._cameraPOIDirection,this._cameraPOIDirection))}_updateElevationAgnosticBoundingVolumeGlobal(t){let n=this.getNodeObbInRenderSRIndependentOfElevationOffset(t),r=t.elevationAgnosticBoundingVolume,i=-1,a;if(n){let t=z;n.getCenter(t),e(t,t),a=t,n.getCorners(V);for(let n of V){e(n,n);let a=s(n,t);if(a<=0){r.invalidate();return}let o=Math.sqrt(Math.max(0,1-a*a));i=Math.max(i,o)}}else{let n=t.serviceMbsInRenderSR;if(!n.isValid){r.invalidate();return}let{center:o,radius:s}=n,l=c(o);if(l<s){r.invalidate();return}i=s/l,a=e(W,o)}r.set(a,i+we)}_updateElevationAgnosticBoundingVolumeLocal(e){let t=e.elevationAgnosticBoundingVolume,n=this.getNodeObbInRenderSRIndependentOfElevationOffset(e);if(n){let e=n.getCenter(z);e[2]=0;let r=0,i=H;n.getCorners(V);for(let e of V){e[2]=0;let t=l(i,e);r=Math.max(r,t)}t.set(e,Math.sqrt(r))}else{let n=e.serviceMbsInRenderSR;if(n.isValid){let e=u(z,n.center);e[2]=0,t.set(e,n.radius)}}}isNodeVisible(e,t=!1){if(!this._isMBSinClippingArea(this.calculateServiceMbsInRenderSR(e)))return!1;if(!this._useFrustumCulling||t&&this.isNodeCloseBelowCamera(e))return!0;let n=this.getAndUpdateVisibilityObbInRenderSR(e);return n?n.intersectsFrustumConservativeApproximation(this._frustumPlanes):this._frustum.intersectsSphere(this.calculateServiceMbsInRenderSRElevationAdjusted(e))}isNodeCloseBelowCamera(e){let t=this.getAndUpdateVisibilityObbInRenderSR(e);if(t?.isValid)return t.intersectSegment(this._camPos,this._checkBelowSegmentEnd);let n=this.calculateServiceMbsInRenderSRElevationAdjusted(e);if(!n.isValid)return!0;let r=S(this._camPos,this._checkBelowSegmentEnd,ge);return ae(r,n.center)<=n.radius**2}isElevationAgnosticBoundingVolumeVisible(e,t){return!this._useFrustumCulling||!e.valid?!0:e.intersectsFrustumConservative(this._frustum,this._viewingMode,1+t)?this._viewingMode!==1||this._isConeVisibleInFrustum(e):!1}_isConeVisibleInFrustum(t){let r=t.radius;if(r>Se)return!0;let i=this._frustumPlanes,{center:a,radius:o}=this._frustum.boundingSphere,c=t.getAxis(W),l=s(c,a),u=o+1,p=l-u,m=l+u;if(p<=0)return!0;let h=n(F,c,p),g=n(I,c,m),_=r/Math.sqrt(1-r*r);for(let t of i){let r=w(t),i=e(L,r),a=s(i,c);if(Math.abs(1-a)<Ce)continue;let o=_e;n(o,c,a),d(o,o,i),e(o,o);let l=ve;if(f(l,h,o,p*_),!(C(t,l)<=0)&&(f(l,g,o,m*_),!(C(t,l)<=0)))return!1}return!0}isObbVisibleIndependentOfElevation(e,t){if(!this._useFrustumCulling||!e.valid)return!0;let{center:r,radius:i}=this._frustum.boundingSphere,a=i+1,o=this._frustumPlanes,c=V;if(t.getCorners(c),this._viewingMode===1){let t=e.getAxis(W),i=s(t,r),l=i-a,u=i+a;if(l<=0)return!0;for(let e of o){let r=!0;for(let i of c){let a=s(i,t),o=U;if(n(o,i,l/a),C(e,o)<=0){r=!1;break}let c=U;if(n(c,i,u/a),C(e,c)<=0){r=!1;break}}if(r)return!1}}else{let e=r[2]-a,t=r[2]+a;for(let n of o){let r=!0,i=w(n),a=i[0],o=i[1],s=i[2],l=n[3];for(let n of c){let i=a*n[0]+o*n[1]+l;if(i+s*e<=0||i+s*t<=0){r=!1;break}}if(r)return!1}}return!0}isGeometryVisible(e,t){if(!this._useFrustumCulling)return!0;let n=e.geometryObbInRenderSR;return!n?.isValid||n.intersectsFrustumConservativeApproximation(this._frustumPlanes)||t&&n.intersectSegment(this._camPos,this._checkBelowSegmentEnd)}_isMBSinClippingArea(e){return this._clippingArea==null||D(this._clippingArea,e)!==0}_screenSpaceDiameterMbs(e,t){let n=this.calcCameraDistanceToSurfaceAndUpdateMinmaxWithCenterDistance(e);return n<0?be:t/n/this._halfScreenPixelSizePerDistance}calcCameraDistanceToSurfaceAndUpdateMinmaxWithCenterDistance(e){let t=this.calculateMbsConeInRenderSR(e);if(t==null)return this.calcCameraDistanceToSurfaceAndUpdateMinmaxWithSphere(e);let n=t.calculateSurfaceDistanceFromPoint(this._camPos),r=t.calculateCenterDistanceFromPoint(this._camPos);return this._updateMinMaxDistanceToCenter(r),n}calcCameraDistanceToSurfaceAndUpdateMinmaxWithSphere(e){return this.calcCameraDistanceToCenterAndUpdateMinmax(e)-this.calculateServiceMbsInRenderSRElevationAdjusted(e).radius}calcCameraDistanceToCenterAndUpdateMinmax(e){let t=this.calculateServiceMbsInRenderSRElevationAdjusted(e),n=p(t.center,this._camPos);return this._updateMinMaxDistanceToCenter(n),n}_calculateAngleDependentLoDForSphere(e,t){let n=d(H,e,this._camPos),i=r(e),a=r(n);if(i===0||a===0)return 1;let o=(Math.abs(s(e,n))/i+t)/a;return Math.min(1,o)}calcAngleDependentLoD(e){let t=this.calculateMbsConeInRenderSR(e);if(t==null){let{center:t,radius:n}=this.calculateServiceMbsInRenderSRElevationAdjusted(e);return this._calculateAngleDependentLoDForSphere(t,n)}let{center:i,radius:a}=this.calculateServiceMbsInRenderSR(e);if(this._viewingMode===2)u(q,i),q[2]=t.lowerCenterHeight,u(J,i),J[2]=t.upperCenterHeight;else{let e=r(i);if(e===0)return 1;n(q,i,t.lowerCenterHeight/e),n(J,i,t.upperCenterHeight/e)}let o=this._calculateAngleDependentLoDForSphere(q,a),c=this._calculateAngleDependentLoDForSphere(J,a);if(this._viewingMode===2)u(Y,i),Y[2]=Math.max(t.lowerCenterHeight,Math.min(t.upperCenterHeight,this._camPos[2]));else{let e=r(i);if(e===0)return Math.max(o,c);let a=Math.max(t.lowerCenterHeight,Math.min(t.upperCenterHeight,s(this._camPos,i)/e));n(Y,i,a/e)}return Math.max(o,c,this._calculateAngleDependentLoDForSphere(Y,a))}hasLOD(e){return e.lodMetric!==0}_getDistanceToSurfaceGlobeMode(e,i){let a=r(i.center),c=r(e)-a;n(q,e,s(e,i.center)/m(e));let l=h(i.center,q),u=i.radius;if(l<=u*u)return Math.abs(c);let d=n(q,i.center,1/a),f=u*u/(2*a),g=n(J,d,a-f),_=o(Y,e,g),v=o(Y,_,n(X,d,s(d,_))),y=t(Y,g,n(Y,v,u/r(v))),b=p(e,y);if(c>=Z){let t=o(J,e,y),n=s(t,d)/r(t);n<Q&&(n=$),b/=n}return b}_getDistanceToSurface(e,t){return this._isGlobalMode?this._getDistanceToSurfaceGlobeMode(e,t):P(e,t)}_applyGlobalFlatAngleCorrectionToConeDistance(e,t){t.calculateClosestCenterToPoint(this._camPos,X);let n=r(X);if(n===0||r(this._camPos)-n<Z)return e;let i=o(Y,this._camPos,X),a=r(i);if(a===0)return e;let c=s(i,X)/(a*n);return e/(c<Q?$:c)}calculateScreenSpaceRelativeSphere(e){let t=this.calculateServiceMbsInRenderSRElevationAdjusted(e),n=this._getDistanceToSurface(this._camPos,t),r=n+t.radius;return this._updateMinMaxDistanceToCenter(r),2*n*this._halfScreenPixelSizePerDistance}calculateScreenSpaceRelativeCone(e){let t=e.calculateCenterDistanceFromPoint(this._camPos);this._updateMinMaxDistanceToCenter(t);let n=e.calculateSurfaceDistanceFromPoint(this._camPos);return 2*(this._isGlobalMode?this._applyGlobalFlatAngleCorrectionToConeDistance(n,e):n)*this._halfScreenPixelSizePerDistance}_updateMinMaxDistanceToCenter(e){e>0?(this.minCenterDistance=Math.min(this.minCenterDistance,e),this.maxCenterDistance=Math.max(this.maxCenterDistance,e)):(this.minCenterDistance=0,this.maxCenterDistance=Math.max(this.maxCenterDistance,-e))}getLodLevel(e){if(e.lodMetric===0)return 0;if(e.childCount===0)return this.maxLodLevel;if(this._useFrustumCulling&&this._progressiveLoadFactor<1){let t=this._progressiveLoadFactor*this._screenspaceErrorBias,n=this._screenspaceErrorBias;return this.evaluateLODmetric(e,t)?this.evaluateLODmetric(e,n)?2:1:0}return this.evaluateLODmetric(e,this._screenspaceErrorBias)?this.maxLodLevel:0}evaluateLODmetric(e,t){switch(e.lodMetric){case 1:{let n=this._screenSpaceDiameterMbs(e,(e.serviceMbsInIndexSR?.radius??0)*t);return this._options.angleDependentLoD&&(n*=this.calcAngleDependentLoD(e)),n<e.maxError}case 2:{let n=this.calculateMbsConeInRenderSR(e),r=n?this.calculateScreenSpaceRelativeCone(n):this.calculateScreenSpaceRelativeSphere(e);return e.maxError*t<=r}case 3:return this._screenSpaceDiameterMbs(e,e.maxError)*t<xe;case 4:return this.calcCameraDistanceToSurfaceAndUpdateMinmaxWithCenterDistance(e)>e.maxError*t}return!1}distToCameraPOIRay(e){if(e==null)return 0;let t=this.calculateServiceMbsInRenderSRElevationAdjusted(e),n=t.center,r=s(n,this._cameraPOIDirection),i=r*r,a=m(n)-i;return Math.sqrt(a)-t.radius}distCameraToPOI(){return p(this._camPos,this._poi)}}function P(e,t){let n=e[0]-t.center[0],r=e[1]-t.center[1],i=e[2]-t.center[2],a=n*n+r*r,o=t.radius;if(a<=o*o)return Math.abs(i);let s=Math.sqrt(a)-o;return Math.sqrt(i*i+s*s)}const F=g(),I=g(),L=g(),R=new O,z=g(),B=new v,V=[g(),g(),g(),g(),g(),g(),g(),g()],H=g(),ge=ie(),_e=g(),ve=g(),U=g(),W=g(),G=new T,K=re(),q=g(),J=g(),Y=g(),X=g();function ye(e,t,i){if(i===2)e.center[2]+=t;else{let i=r(e.center);if(i===0){e.radius+=Math.abs(t);return}n(e.center,e.center,1+t/i)}}const be=.5*Number.MAX_VALUE,xe=10,Z=2e5,Q=.08,$=1e-4,Se=.9,Ce=.01,we=.001;export{N as default};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import{EventedAccessor as t}from"../../../../core/Evented.js";import n from"../../../../core/Logger.js";import{property as r,subclass as i}from"../../../../core/accessorSupport/decorators.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/quatf64.js";import{set as o,transformQuatValues as s}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{canProjectWithoutEngine as l}from"../../../../geometry/projectionUtils.js";import{projectBoundingRect as u}from"../../../../geometry/projection/projectBoundingRect.js";import{projectBoundingSphere as d}from"../../../../geometry/projection/projectBoundingSphere.js";import{create as f,allFinite as p,fromExtent as m}from"../../../../geometry/support/aaBoundingRect.js";import{getInfo as h}from"../../../../geometry/support/spatialReferenceUtils.js";import{Sphere as g}from"../../../../geometry/support/sphere.js";import{ElevationRange as _}from"../../support/ElevationRange.js";import{ElevationUpdateEvent as v}from"../../support/ElevationUpdateEvent.js";import{ProjectedElevationUpdateExtent as y,calculateElevationUpdateExtents as b,fullWorldElevationUpdateExtent as x,planetCenterProximityToleranceMeters as S}from"../../support/elevationUpdateExtentUtils.js";import{Intersector as C}from"../../webgl-engine/lib/Intersector.js";let w=class extends t{constructor(e){super(e),this._renderCoordsHelper=e.view.renderCoordsHelper,this._renderSR=this._renderCoordsHelper.spatialReference,this._layerElevationSource=e.layerElevationSource,this._projectedExtent=new y(this._renderCoordsHelper)}initialize(){this._intersector=new C(this.view.state.viewingMode),this._intersector.options.store=0,this._intersector.options.normalRequired=!1}get spatialReference(){return this.view?.elevationProvider?.spatialReference}getElevation(e,t,r,i){let a=this._renderCoordsHelper,s=o(E,e,t,r);if(!a.toRenderCoords(s,i,s))return n.getLogger(this).error(`could not project point to compute elevation`),null;let{layerElevationSource:c,_intersector:l,intersectionHandler:u}=this,d=c.fullExtent,f=d!=null&&Number.isFinite(d.xmin)&&Number.isFinite(d.xmax)&&Number.isFinite(d.ymin)&&Number.isFinite(d.ymax)&&Number.isFinite(d.zmin)&&Number.isFinite(d.zmax)?new _(d.zmin,d.zmax):c.elevationRange;if(f==null)return null;let p=c.elevationOffset,m=f.minElevation+p,h=f.maxElevation+p,g=a.setAltitude(k,h,s),v=a.setAltitude(A,m,s);return l.reset(g,v,this.view.state.camera),u.intersectRay(l,null,g,v,null,!0),l.results.min.getIntersectionPoint(s)?a.getAltitude(s):null}getElevations(e,t,n){let{groundSpatialReference:r}=this.view;for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=this.getElevation(a,o,0,r);n(i,s)}}getSphereElevationRange(e,t){return d(e,t,T,this._renderSR),this._layerElevationSource.getElevationRange(T)}getRootElevationRange(){let e=this.layerElevationSource.fullExtent;return e?.hasZ?new _(e.zmin,e.zmax):null}notifyObjectsChanged(e){this._notifyObjectsChanged(e.length,t=>{for(let n of e)if(!t(n))break})}notifyObjectsChangedFunctional(e,t){this._notifyObjectsChanged(e,t)}notifyObjectChanged(e){this._notifyObjectsChanged(1,t=>{t(e)})}_notifyObjectsChanged(e,t){if(e===0)return;let n=this.spatialReference;if(n==null)return;if(!l(this._renderSR,n)){this._emitFullExtentElevationChange(n);return}let r=new Float64Array(4*e),i=!1,a=0;t(e=>this._computeObjectExtent(e,r,a,n)?(a++,!0):(i=!0,!1)),i?this._emitFullExtentElevationChange(n):this._emitElevationChangeEvents(r,n)}_computeObjectExtent(e,t,n,r){if(this.view.state.viewingMode===1&&P(e))return!1;let i=this._projectedExtent;return E[0]=e.centerX,E[1]=e.centerY,E[2]=e.centerZ,i.reset(E,e.radius,r),!this._expandExtent(e,i,r)||!p(i.extent)?!1:(t.set(i.extent,4*n),!0)}_emitElevationChangeEvents(e,t){for(let n of b(e,t))this._emitElevationChangeEvent(n,t)}_emitFullExtentElevationChange(e){let t=f(),n=this._layerElevationSource.fullExtent;if(n!=null&&u(m(n,M),n.spatialReference,t,e)&&p(t)){this._emitElevationChangeEvent(t,e);return}let r=h(e);r!=null&&this._emitElevationChangeEvent(x(e,r),e)}_emitElevationChangeEvent(e,t){let n=new v(t,e,this.intersectionHandler.isGround?`ground`:`scene`);this.emit(`elevation-change`,n)}_expandExtent(e,t,n){e.getCorners(O);for(let e=0;e<8;++e){let r=O[e];if(t.addRenderPoint(r,n)==null)return!1}for(let e=0;e<D.length;e+=2)if(!t.addRenderEdge(O[D[e]],O[D[e+1]],n))return!1;return!0}};e([r({constructOnly:!0})],w.prototype,`layerElevationSource`,void 0),e([r({constructOnly:!0})],w.prototype,`intersectionHandler`,void 0),e([r({constructOnly:!0})],w.prototype,`view`,void 0),e([r()],w.prototype,`spatialReference`,null),w=e([i(`esri.views.3d.layers.i3s.LayerElevationProvider`)],w);const T=new g,E=c(),D=[0,1,2,3,4,5,6,7,0,2,1,3,4,6,5,7,0,4,1,5,2,6,3,7],O=Array.from({length:8},()=>c()),k=c(),A=c(),j=a(),M=f(),N=c();function P(e){N[0]=-e.centerX,N[1]=-e.centerY,N[2]=-e.centerZ,e.getQuaternion(j),s(N,N,-j[0],-j[1],-j[2],j[3]);let t=Math.max(Math.abs(N[0])-e.halfSizeX,0),n=Math.max(Math.abs(N[1])-e.halfSizeY,0),r=Math.max(Math.abs(N[2])-e.halfSizeZ,0);return t*t+n*n+r*r<=S*S}export{w as LayerElevationProvider};
2
+ import{__decorate as e}from"tslib";import{EventedAccessor as t}from"../../../../core/Evented.js";import n from"../../../../core/Logger.js";import{property as r,subclass as i}from"../../../../core/accessorSupport/decorators.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/quatf64.js";import{set as o,transformQuatValues as s}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{canProjectWithoutEngine as l}from"../../../../geometry/projectionUtils.js";import{projectBoundingRect as u}from"../../../../geometry/projection/projectBoundingRect.js";import{projectBoundingSphere as d}from"../../../../geometry/projection/projectBoundingSphere.js";import{create as f,allFinite as p,fromExtent as m}from"../../../../geometry/support/aaBoundingRect.js";import{getInfo as h}from"../../../../geometry/support/spatialReferenceUtils.js";import{Sphere as g}from"../../../../geometry/support/sphere.js";import{ElevationRange as _}from"../../support/ElevationRange.js";import{ElevationUpdateEvent as v}from"../../support/ElevationUpdateEvent.js";import{ProjectedElevationUpdateExtent as y,calculateElevationUpdateExtents as b,fullWorldElevationUpdateExtent as x,planetCenterProximityToleranceMeters as S}from"../../support/elevationUpdateExtentUtils.js";import{Intersector as C}from"../../webgl-engine/lib/Intersector.js";let w=class extends t{constructor(e){super(e),this._renderCoordsHelper=e.view.renderCoordsHelper,this._renderSR=this._renderCoordsHelper.spatialReference,this._layerElevationSource=e.layerElevationSource,this._projectedExtent=new y(this._renderCoordsHelper)}initialize(){this._intersector=new C(this.view.state.viewingMode),this._intersector.options.store=0,this._intersector.options.normalRequired=!1}get spatialReference(){return this.view?.elevationProvider?.spatialReference}getElevation(e,t,r,i){let a=this._renderCoordsHelper,s=o(E,e,t,r);if(!a.toRenderCoords(s,i,s))return n.getLogger(this).error(`could not project point to compute elevation`),null;let{layerElevationSource:c,_intersector:l,intersectionHandler:u}=this,d=c.elevationRange;if(d==null||d.isEmpty)return null;let f=d.minElevation,p=d.maxElevation,m=p>f?(p-f)/2:1,h=a.setAltitude(k,p+m,s),g=a.setAltitude(A,f-m,s);return l.reset(h,g,this.view.state.camera),u.intersectRay(l,null,h,g,null,!0),l.results.min.getIntersectionPoint(s)?a.getAltitude(s):null}getElevations(e,t,n){let{groundSpatialReference:r}=this.view;for(let i=0;i<t;++i){let t=i*3,a=e[t],o=e[t+1],s=this.getElevation(a,o,0,r);n(i,s)}}getSphereElevationRange(e,t){return d(e,t,T,this._renderSR),this._layerElevationSource.getElevationRange(T)}getRootElevationRange(){let e=this.layerElevationSource.fullExtent;return e?.hasZ?new _(e.zmin,e.zmax):null}notifyObjectsChanged(e){this._notifyObjectsChanged(e.length,t=>{for(let n of e)if(!t(n))break})}notifyObjectsChangedFunctional(e,t){this._notifyObjectsChanged(e,t)}notifyObjectChanged(e){this._notifyObjectsChanged(1,t=>{t(e)})}_notifyObjectsChanged(e,t){if(e===0)return;let n=this.spatialReference;if(n==null)return;if(!l(this._renderSR,n)){this._emitFullExtentElevationChange(n);return}let r=new Float64Array(4*e),i=!1,a=0;t(e=>this._computeObjectExtent(e,r,a,n)?(a++,!0):(i=!0,!1)),i?this._emitFullExtentElevationChange(n):this._emitElevationChangeEvents(r,n)}_computeObjectExtent(e,t,n,r){if(this.view.state.viewingMode===1&&P(e))return!1;let i=this._projectedExtent;return E[0]=e.centerX,E[1]=e.centerY,E[2]=e.centerZ,i.reset(E,e.radius,r),!this._expandExtent(e,i,r)||!p(i.extent)?!1:(t.set(i.extent,4*n),!0)}_emitElevationChangeEvents(e,t){for(let n of b(e,t))this._emitElevationChangeEvent(n,t)}_emitFullExtentElevationChange(e){let t=f(),n=this._layerElevationSource.fullExtent;if(n!=null&&u(m(n,M),n.spatialReference,t,e)&&p(t)){this._emitElevationChangeEvent(t,e);return}let r=h(e);r!=null&&this._emitElevationChangeEvent(x(e,r),e)}_emitElevationChangeEvent(e,t){let n=new v(t,e,this.intersectionHandler.isGround?`ground`:`scene`);this.emit(`elevation-change`,n)}_expandExtent(e,t,n){e.getCorners(O);for(let e=0;e<8;++e){let r=O[e];if(t.addRenderPoint(r,n)==null)return!1}for(let e=0;e<D.length;e+=2)if(!t.addRenderEdge(O[D[e]],O[D[e+1]],n))return!1;return!0}};e([r({constructOnly:!0})],w.prototype,`layerElevationSource`,void 0),e([r({constructOnly:!0})],w.prototype,`intersectionHandler`,void 0),e([r({constructOnly:!0})],w.prototype,`view`,void 0),e([r()],w.prototype,`spatialReference`,null),w=e([i(`esri.views.3d.layers.i3s.LayerElevationProvider`)],w);const T=new g,E=c(),D=[0,1,2,3,4,5,6,7,0,2,1,3,4,6,5,7,0,4,1,5,2,6,3,7],O=Array.from({length:8},()=>c()),k=c(),A=c(),j=a(),M=f(),N=c();function P(e){N[0]=-e.centerX,N[1]=-e.centerY,N[2]=-e.centerZ,e.getQuaternion(j),s(N,N,-j[0],-j[1],-j[2],j[3]);let t=Math.max(Math.abs(N[0])-e.halfSizeX,0),n=Math.max(Math.abs(N[1])-e.halfSizeY,0),r=Math.max(Math.abs(N[2])-e.halfSizeZ,0);return t*t+n*n+r*r<=S*S}export{w as LayerElevationProvider};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import"../../../../core/has.js";import{getOrCreateMapValue as e}from"../../../../core/MapUtils.js";import{estimateAttributesMemory as t}from"../../../../core/memoryEstimations.js";import{signal as n}from"../../../../core/signal.js";import{estimateGeometryMemory as r}from"../../../../layers/graphics/dehydratedFeatures.js";class i{constructor(e=()=>void 0){this._getGeometryKey=e,this._payloads=new Map,this._geometries=new Map,this._usedMemory=n(0),this._duplicatedMemory=n(0),this._referenceCount=n(0)}findGeometry(e,t){if(e===void 0)return;let n=this._geometries.get(e);if(n){for(let e of n)if(t(e))return e}}get usedMemory(){return this._usedMemory.value}get usedMemoryPerFeature(){return this._referenceCount.value>0?this._duplicatedMemory.value/this._referenceCount.value:0}ref(n,i,a=!0){let o;a&&n.geometry&&!this._payloads.has(n.geometry)&&(o=this._getGeometryKey(n.geometry,i),o!==void 0&&e(this._geometries,o,()=>new Set).add(n.geometry)),this._duplicatedMemory.value+=this._refPayload(n.geometry,r,o)+this._refPayload(n.attributes,t),this._referenceCount.value++}unref(e){let t=e.geometry,n=t&&this._payloads.get(t);if(t&&n?.count===1&&n.geometryKey!==void 0){let e=this._geometries.get(n.geometryKey);e.delete(t),e.size===0&&this._geometries.delete(n.geometryKey)}this._duplicatedMemory.value-=this._unrefPayload(e.geometry)+this._unrefPayload(e.attributes),this._referenceCount.value--}_refPayload(e,t,n){if(e==null)return 0;let r=this._payloads.get(e);if(r)return r.count++,r.size;let i=t(e);return this._payloads.set(e,new a(i,n)),this._usedMemory.value+=i,i}_unrefPayload(e){if(e==null)return 0;let t=this._payloads.get(e);return--t.count===0&&(this._payloads.delete(e),this._usedMemory.value-=t.size),t.size}get test(){}}class a{constructor(e,t){this.size=e,this.geometryKey=t,this.count=1}}export{i as FeatureMemory};
2
+ import"../../../../core/has.js";import{getOrCreateMapValue as e}from"../../../../core/MapUtils.js";import{estimateAttributesMemory as t}from"../../../../core/memoryEstimations.js";import{signal as n}from"../../../../core/signal.js";import{baseDehydratedGraphicMemory as r,estimateGeometryMemory as i}from"../../../../layers/graphics/dehydratedFeatures.js";class a{constructor(e=()=>void 0){this._getGeometryKey=e,this._payloads=new Map,this._geometries=new Map,this._usedMemory=n(0),this._duplicatedMemory=n(0),this._referenceCount=n(0)}findGeometry(e,t){if(e===void 0)return;let n=this._geometries.get(e);if(n){for(let e of n)if(t(e))return e}}get usedMemory(){return this._usedMemory.value}get usedMemoryPerFeature(){return this._referenceCount.value>0?this._duplicatedMemory.value/this._referenceCount.value:0}getFeatureSize(e){return r+(e.geometry==null?0:this._payloads.get(e.geometry)?.size??0)+(e.attributes==null?0:this._payloads.get(e.attributes)?.size??0)}ref(n,r,a=!0){let o;a&&n.geometry&&!this._payloads.has(n.geometry)&&(o=this._getGeometryKey(n.geometry,r),o!==void 0&&e(this._geometries,o,()=>new Set).add(n.geometry)),this._duplicatedMemory.value+=this._refPayload(n.geometry,i,o)+this._refPayload(n.attributes,t),this._referenceCount.value++}unref(e){let t=e.geometry,n=t&&this._payloads.get(t);if(t&&n?.count===1&&n.geometryKey!==void 0){let e=this._geometries.get(n.geometryKey);e.delete(t),e.size===0&&this._geometries.delete(n.geometryKey)}this._duplicatedMemory.value-=this._unrefPayload(e.geometry)+this._unrefPayload(e.attributes),this._referenceCount.value--}_refPayload(e,t,n){if(e==null)return 0;let r=this._payloads.get(e);if(r)return r.count++,r.size;let i=t(e);return this._payloads.set(e,new o(i,n)),this._usedMemory.value+=i,i}_unrefPayload(e){if(e==null)return 0;let t=this._payloads.get(e);return--t.count===0&&(this._payloads.delete(e),this._usedMemory.value-=t.size),t.size}get test(){}}class o{constructor(e,t){this.size=e,this.geometryKey=t,this.count=1}}export{a as FeatureMemory};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{shuffle as e}from"../../../../core/arrayUtils.js";import has from"../../../../core/has.js";import{baseObjectMemory as t}from"../../../../core/memoryEstimations.js";import{signal as n}from"../../../../core/signal.js";import{create as r,diameter as i}from"../../../../geometry/support/aaBoundingBox.js";import{create as a,fromExtent as o,intersects as s,copy as c,positiveInfinity as l,intersection as u}from"../../../../geometry/support/aaBoundingRect.js";import{numVertices as d,estimateSize as f,getObjectId as p,computeAABB as m}from"../../../../layers/graphics/dehydratedFeatures.js";import{computeMaxZ as h}from"../graphics/graphicUtils.js";import{SampledGeometryMaxDistanceRatio as g}from"./SampledGeometryMaxDistanceRatio.js";class _{constructor(e,t){this.descriptor=e,this._memory=t,this._numVertices=0,this.exceededTransferLimit=n(!1),this._fetchFailed=n(!1),this._sorted=!1,this._numFeatures=n(v),this._emptyFeatureRatio=n(0),this._estimatedSize=-1,this._sampledDensityEstimate=-1,this._displayingFeatures=null,this.alive=!0,this.filtered=!1,this._features=null,this._featuresLength=n(0),this._featureLimit=n(0),this._fetchStatus=0,this.fetchInformation=n(``),this.fetchingResolution=this.displayingResolution=e.resolution}get featuresMissing(){return this.fetchFailed||(this.hasPreciseFeatureCount?this._featuresLength.value<this.numFeatures:this.exceededTransferLimit.value)}get showsAllFeatures(){return!this.fetchFailed&&this.displayingFeatures!=null&&(this.hasPreciseFeatureCount?this.displayingFeatures.length===this.numFeatures:!this.exceededTransferLimit.value)}get missingAttributes(){return this._missingAttributes}get fetchFailed(){return this._fetchFailed.value}set fetchFailed(e){this._fetchFailed.value=e}get displayingFeatures(){return this._displayingFeatures}set displayingFeatures(e){this._displayingFeatures=e,this.extentIncludingBorrowedFeatures=null}get perTileMaximumNumberOfFeaturesExceeded(){let e=this.isFetched&&this.featuresMissing;return!this.filtered&&(e||this.hasFeatureLimit)}get features(){return this._features}get featureLimit(){return this._featureLimit.value}set featureLimit(e){this._featureLimit.value=e}get hasFeatureLimit(){return this.featureLimit!==this._featuresLength.value}get availableFields(){return this._availableFields}setFeatures(e,t,n,r,i=this.fetchingResolution,a=!0){this._replaceFeatures(e,i,a),this._availableFields=n,this._featuresLength.value=e?.length??0,this._sorted=!1,this._estimatedSize=-1,this._sampledDensityEstimate=-1,this._missingAttributes=r,e&&e.length>0?(this._emptyFeatureRatio.value=t/(e.length+t),this._numVertices=e.reduce((e,t)=>e+d(t.geometry),0)):(this._emptyFeatureRatio.value=0,this._numVertices=0)}computeZQuantizationFactor(){if(this._features&&this._features.length>0){let e=this._features.reduce((e,{geometry:t})=>Math.max(e,h(t)??0),0);return Math.floor(e/this.descriptor.planetRadius)+1}return 1}get emptyFeatureRatio(){return this._emptyFeatureRatio.value}get numFeatures(){return this.hasPreciseFeatureCount?this._numFeatures.value:this._features?this._featuresLength.value:0}set numFeatures(e){this._numFeatures.value=e}get hasPreciseFeatureCount(){return this._numFeatures.value>v}get needsFeatureCount(){return this._numFeatures.value===v}get numVertices(){return this._numVertices}get id(){return this.descriptor.id}get estimatedSize(){return this.updateEstimates(),this._estimatedSize}get sampledDensityEstimate(){return this._sampledDensityEstimate}updateEstimates(){if(this._estimatedSize<0||this._sampledDensityEstimate<0){this._estimatedSize=0,this._sampledDensityEstimate=0;let e=Math.floor(Math.sqrt(S));if(this._features){let t=null,n=new g(S,has(`featurelayer-snapping-density-max-distance`)*this.fetchingResolution),r=this._features.length;for(let i=0;i<r;++i){let a=this._features[i],o=f(a);if(this._estimatedSize+=o,!n.done){let o=r-i,s=Math.ceil(o/Math.max(1,Math.floor(Math.sqrt(n.numRemainingSamples))));if(i%s===0){let r=Math.max(Math.floor(n.numRemainingSamples/o),e);n.sampleGeometry(a.geometry,t,r)}}t=a.geometry}this._sampledDensityEstimate=n.numSamples>=C?n.ratio:0}return!0}return!1}get fetchStatus(){return this._fetchStatus}requestFetch(){this._fetchStatus=0}requestRefetch(){this._fetchStatus=1}requestAttributes(){this._fetchStatus=this._fetchStatus===9||this.attributeRefetchCompletionStatus===9?6:4}get needsAttributesFetching(){return this._fetchStatus===4||this._fetchStatus===5||this._fetchStatus===6||this._fetchStatus===7}get attributeRefetchCompletionStatus(){return this._fetchStatus===6||this._fetchStatus===7?9:8}startFetch(){this._fetchStatus=this.needsAttributesFetching?this.attributeRefetchCompletionStatus===9?7:5:this.needsRefetch?3:2}fetchDone(e){this._fetchStatus=e}get isFetching(){return this._fetchStatus===2||this.isRefetching}get isRefetching(){return this._fetchStatus===3||this._fetchStatus===5||this._fetchStatus===7}get needsFetch(){return this._fetchStatus===0||this.needsRefetch}get needsRefetch(){return this._fetchStatus===1||this._fetchStatus===4||this._fetchStatus===6}get isFetched(){return this._fetchStatus===8||this._fetchStatus===9}isFullyFetched(e){return!!this.features&&(this.features.length>=e||this.fetchStatus===9)}resetFetching(){this.needsAttributesFetching?this.requestAttributes():this._fetchStatus=+!!this.isRefetching}get needsDisplayUpdate(){return!!this._features&&!x(this._features,this.displayingFeatures,this.featureLimit)}intersects(e){return e==null||!this.descriptor.extent||(o(e,w),s(this.descriptor.extent,w))}intersectionIncludingBorrowed(e,t){let n=this.extentIncludingBorrowedFeatures==null?this.descriptor.extent:this.extentIncludingBorrowedFeatures;return!e&&!n?(c(t,l),t):(e==null?c(t,n):(o(e,t),u(t,n,t)),t)}_shuffle(t){this._features?.sort((e,n)=>p(e,t)-p(n,t)),e(this._features,16438)}_sortBySize(e){this._features?.sort((t,n)=>i(m(n.geometry,T))-i(m(t.geometry,T))||p(t,e)-p(n,e))}reduceFeatures(e,t,n,r){if(e<=0)return!1;if(!this._features)return this.featureLimit=0,!1;let i=!1;this.featureLimit=Math.ceil(this.numFeatures*e),this.featureLimit>this._features.length&&this._fetchStatus===8&&this._features.length>0&&(this._fetchStatus=1,i=!0),!this._sorted&&e<1&&(r===1?this._shuffle(n):this._sortBySize(n),this._sorted=!0);let a=Math.max(this.featureLimit,Math.ceil(t*this.numFeatures));if(this._features.length>a){for(let e=a;e<this._features.length;e++)this._memory.unref(this._features[e]);switch(this._features.length=this._featuresLength.value=a,this._estimatedSize=-1,this.exceededTransferLimit.value=!1,this._fetchStatus){case 9:this._fetchStatus=8;break;case 6:this._fetchStatus=4;break;case 7:this._fetchStatus=5}}return i}get cache(){return new b(this,this._features,this._numFeatures.value,this._emptyFeatureRatio.value)}set cache(e){this._replaceFeatures(e.features,e.resolution),this.requestController=null,this._availableFields=e.availableFields,this._featuresLength.value=e.features?.length??0,this._numFeatures.value=e.numFeatures,this._emptyFeatureRatio.value=e.emptyFeatureRatio,this._fetchStatus=e.fetchStatus,this.exceededTransferLimit.value=e.exceededTransferLimit,this._estimatedSize=-1,this._sampledDensityEstimate=-1,this.fetchInformation.value=e.fetchInformation}_replaceFeatures(e,t,n=!0){for(let r of e??[])this._memory.ref(r,t,n);for(let e of this._features??[])this._memory.unref(e);this._features=e}}const v=-1,y=-2;class b{constructor(e,n,r,i){this.features=n,this.numFeatures=r,this.emptyFeatureRatio=i,this.usedMemory=t+e.estimatedSize,this.resolution=e.displayingResolution,this.availableFields=e.availableFields,this.fetchStatus=e.fetchStatus,this.exceededTransferLimit=e.exceededTransferLimit.value,this.fetchInformation=e.fetchInformation.value}}function x(e,t,n){if(t==null||e==null||n!==t.length||n>e.length)return!1;for(let r=0;r<n;++r)if(e[r]!==t[r])return!1;return!0}const S=150,C=100,w=a(),T=r();export{_ as FeatureTile,b as FeatureTileCacheItem,y as failedFeatureCount};
2
+ import{shuffle as e}from"../../../../core/arrayUtils.js";import has from"../../../../core/has.js";import{baseObjectMemory as t}from"../../../../core/memoryEstimations.js";import{signal as n}from"../../../../core/signal.js";import{create as r,diameter as i}from"../../../../geometry/support/aaBoundingBox.js";import{create as a,fromExtent as o,intersects as s,copy as c,positiveInfinity as l,intersection as u}from"../../../../geometry/support/aaBoundingRect.js";import{numVertices as d,getObjectId as f,computeAABB as p}from"../../../../layers/graphics/dehydratedFeatures.js";import{computeMaxZ as m}from"../graphics/graphicUtils.js";import{SampledGeometryMaxDistanceRatio as h}from"./SampledGeometryMaxDistanceRatio.js";class g{constructor(e,t){this.descriptor=e,this._memory=t,this._numVertices=0,this.exceededTransferLimit=n(!1),this._fetchFailed=n(!1),this._sorted=!1,this._numFeatures=n(_),this._emptyFeatureRatio=n(0),this._estimatedSize=-1,this._sampledDensityEstimate=-1,this._displayingFeatures=null,this.alive=!0,this.filtered=!1,this._features=null,this._featuresLength=n(0),this._featureLimit=n(0),this._fetchStatus=0,this.fetchInformation=n(``),this.fetchingResolution=this.displayingResolution=e.resolution}get featuresMissing(){return this.fetchFailed||(this.hasPreciseFeatureCount?this._featuresLength.value<this.numFeatures:this.exceededTransferLimit.value)}get showsAllFeatures(){return!this.fetchFailed&&this.displayingFeatures!=null&&(this.hasPreciseFeatureCount?this.displayingFeatures.length===this.numFeatures:!this.exceededTransferLimit.value)}get missingAttributes(){return this._missingAttributes}get fetchFailed(){return this._fetchFailed.value}set fetchFailed(e){this._fetchFailed.value=e}get displayingFeatures(){return this._displayingFeatures}set displayingFeatures(e){this._displayingFeatures=e,this.extentIncludingBorrowedFeatures=null}get perTileMaximumNumberOfFeaturesExceeded(){let e=this.isFetched&&this.featuresMissing;return!this.filtered&&(e||this.hasFeatureLimit)}get features(){return this._features}get featureLimit(){return this._featureLimit.value}set featureLimit(e){this._featureLimit.value=e}get hasFeatureLimit(){return this.featureLimit!==this._featuresLength.value}get availableFields(){return this._availableFields}setFeatures(e,t,n,r,i=this.fetchingResolution,a=!0){this._replaceFeatures(e,i,a),this._availableFields=n,this._featuresLength.value=e?.length??0,this._sorted=!1,this._estimatedSize=-1,this._sampledDensityEstimate=-1,this._missingAttributes=r,e&&e.length>0?(this._emptyFeatureRatio.value=t/(e.length+t),this._numVertices=e.reduce((e,t)=>e+d(t.geometry),0)):(this._emptyFeatureRatio.value=0,this._numVertices=0)}computeZQuantizationFactor(){if(this._features&&this._features.length>0){let e=this._features.reduce((e,{geometry:t})=>Math.max(e,m(t)??0),0);return Math.floor(e/this.descriptor.planetRadius)+1}return 1}get emptyFeatureRatio(){return this._emptyFeatureRatio.value}get numFeatures(){return this.hasPreciseFeatureCount?this._numFeatures.value:this._features?this._featuresLength.value:0}set numFeatures(e){this._numFeatures.value=e}get hasPreciseFeatureCount(){return this._numFeatures.value>_}get needsFeatureCount(){return this._numFeatures.value===_}get numVertices(){return this._numVertices}get id(){return this.descriptor.id}get estimatedSize(){return this.updateEstimates(),this._estimatedSize}get sampledDensityEstimate(){return this._sampledDensityEstimate}updateEstimates(){if(this._estimatedSize<0||this._sampledDensityEstimate<0){this._estimatedSize=0,this._sampledDensityEstimate=0;let e=Math.floor(Math.sqrt(x));if(this._features){let t=null,n=new h(x,has(`featurelayer-snapping-density-max-distance`)*this.fetchingResolution),r=this._features.length;for(let i=0;i<r;++i){let a=this._features[i],o=this._memory.getFeatureSize(a);if(this._estimatedSize+=o,!n.done){let o=r-i,s=Math.ceil(o/Math.max(1,Math.floor(Math.sqrt(n.numRemainingSamples))));if(i%s===0){let r=Math.max(Math.floor(n.numRemainingSamples/o),e);n.sampleGeometry(a.geometry,t,r)}}t=a.geometry}this._sampledDensityEstimate=n.numSamples>=S?n.ratio:0}return!0}return!1}get fetchStatus(){return this._fetchStatus}requestFetch(){this._fetchStatus=0}requestRefetch(){this._fetchStatus=1}requestAttributes(){this._fetchStatus=this._fetchStatus===9||this.attributeRefetchCompletionStatus===9?6:4}get needsAttributesFetching(){return this._fetchStatus===4||this._fetchStatus===5||this._fetchStatus===6||this._fetchStatus===7}get attributeRefetchCompletionStatus(){return this._fetchStatus===6||this._fetchStatus===7?9:8}startFetch(){this._fetchStatus=this.needsAttributesFetching?this.attributeRefetchCompletionStatus===9?7:5:this.needsRefetch?3:2}fetchDone(e){this._fetchStatus=e}get isFetching(){return this._fetchStatus===2||this.isRefetching}get isRefetching(){return this._fetchStatus===3||this._fetchStatus===5||this._fetchStatus===7}get needsFetch(){return this._fetchStatus===0||this.needsRefetch}get needsRefetch(){return this._fetchStatus===1||this._fetchStatus===4||this._fetchStatus===6}get isFetched(){return this._fetchStatus===8||this._fetchStatus===9}isFullyFetched(e){return!!this.features&&(this.features.length>=e||this.fetchStatus===9)}resetFetching(){this.needsAttributesFetching?this.requestAttributes():this._fetchStatus=+!!this.isRefetching}get needsDisplayUpdate(){return!!this._features&&!b(this._features,this.displayingFeatures,this.featureLimit)}intersects(e){return e==null||!this.descriptor.extent||(o(e,C),s(this.descriptor.extent,C))}intersectionIncludingBorrowed(e,t){let n=this.extentIncludingBorrowedFeatures==null?this.descriptor.extent:this.extentIncludingBorrowedFeatures;return!e&&!n?(c(t,l),t):(e==null?c(t,n):(o(e,t),u(t,n,t)),t)}_shuffle(t){this._features?.sort((e,n)=>f(e,t)-f(n,t)),e(this._features,16438)}_sortBySize(e){this._features?.sort((t,n)=>i(p(n.geometry,w))-i(p(t.geometry,w))||f(t,e)-f(n,e))}reduceFeatures(e,t,n,r){if(e<=0)return!1;if(!this._features)return this.featureLimit=0,!1;let i=!1;this.featureLimit=Math.ceil(this.numFeatures*e),this.featureLimit>this._features.length&&this._fetchStatus===8&&this._features.length>0&&(this._fetchStatus=1,i=!0),!this._sorted&&e<1&&(r===1?this._shuffle(n):this._sortBySize(n),this._sorted=!0);let a=Math.max(this.featureLimit,Math.ceil(t*this.numFeatures));if(this._features.length>a){for(let e=a;e<this._features.length;e++)this._memory.unref(this._features[e]);switch(this._features.length=this._featuresLength.value=a,this._estimatedSize=-1,this.exceededTransferLimit.value=!1,this._fetchStatus){case 9:this._fetchStatus=8;break;case 6:this._fetchStatus=4;break;case 7:this._fetchStatus=5}}return i}get cache(){return new y(this,this._features,this._numFeatures.value,this._emptyFeatureRatio.value)}set cache(e){this._replaceFeatures(e.features,e.resolution),this.requestController=null,this._availableFields=e.availableFields,this._featuresLength.value=e.features?.length??0,this._numFeatures.value=e.numFeatures,this._emptyFeatureRatio.value=e.emptyFeatureRatio,this._fetchStatus=e.fetchStatus,this.exceededTransferLimit.value=e.exceededTransferLimit,this._estimatedSize=-1,this._sampledDensityEstimate=-1,this.fetchInformation.value=e.fetchInformation}_replaceFeatures(e,t,n=!0){for(let r of e??[])this._memory.ref(r,t,n);for(let e of this._features??[])this._memory.unref(e);this._features=e}}const _=-1,v=-2;class y{constructor(e,n,r,i){this.features=n,this.numFeatures=r,this.emptyFeatureRatio=i,this.usedMemory=t+e.estimatedSize,this.resolution=e.displayingResolution,this.availableFields=e.availableFields,this.fetchStatus=e.fetchStatus,this.exceededTransferLimit=e.exceededTransferLimit.value,this.fetchInformation=e.fetchInformation.value}}function b(e,t,n){if(t==null||e==null||n!==t.length||n>e.length)return!1;for(let r=0;r<n;++r)if(e[r]!==t[r])return!1;return!0}const x=150,S=100,C=a(),w=r();export{g as FeatureTile,y as FeatureTileCacheItem,v as failedFeatureCount};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import e from"../../../../core/Logger.js";import{getOrCreateMapValue as t}from"../../../../core/MapUtils.js";import{sub as n,normalize as r,len as i,dot as a}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as o,create as s}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as c,isEmpty as l,containedBySphere as u,setEmpty as d,intersectsSphere as f,intersectsRay as p,copy as m,exactEquals as h}from"../../../../geometry/support/aaBoundingBox.js";import{fromValues as g}from"../../../../geometry/support/aaBoundingRect.js";import{earth as _}from"../../../../geometry/support/Ellipsoid.js";import{ElevationRange as v}from"../../support/ElevationRange.js";function y(e,t){return e===`local`?new x(t):new S(t)}class b{constructor(e,t){this.viewingMode=e,this.layerExtent=t,this._rootNode=null,this._intersectionGeneration=0,this._tileMap=new Map}destroy(){this._rootNode?.clear(),this._tileMap.clear()}_nextIntersectionGeneration(){return this._intersectionGeneration++,this._intersectionGeneration}addTile(e){let{obb:n}=e,r=[this._ensureRootNode()],i=[],a=t(this._tileMap,e,()=>new Set),o=t=>{if(a.has(t))return;let n=t.addOwnTile(e);T(i,t.parent,n),a.add(t)};for(;r.length>0;){let t=r.pop(),i=this._getSizeStopLength(t);if(t.treeDepth>=U||A(e.obb)>=.5*i){o(t);continue}let{hPlane:a,vPlane:s}=t,c=n.signedDistancePlane(a.normal,a.distance),l=n.signedDistancePlane(s.normal,s.distance);c===0&&l===0?o(t):w(t,c,l,(e,t)=>{r.push(this._ensureChild(e,t))})}this._propagateSummaryUpdates(i)}removeTile(t){if(!this._rootNode){e.getLogger(`Tiles3DBVH`).error(`Tiles3DBVH: Attempted to remove a tile that is not loaded (no root node)`);return}let n=this._tileMap.get(t);if(!n||n.size===0){e.getLogger(`Tiles3DBVH`).error(`Tiles3DBVH internal error: Attempted to remove a tile that is not loaded (not in tile map)`);return}let r=[];this._tileMap.delete(t);for(let e of n){e.removeOwnTile(t);let n=e.updateOwnSummaries();T(r,e.parent,n)}this._propagateSummaryUpdates(r)}_propagateSummaryUpdates(e){if(e.length===0)return;e.sort((e,t)=>e.node.treeDepth-t.node.treeDepth);let t=new Map,n=-1,r=()=>e.length>0?e[e.length-1].node.treeDepth:-1;for(;e.length>0||t.size>0;){let i=t.size>0?n:r(),a=t;for(t=new Map;e.length>0&&r()===i;){let{node:t,childrenUpdateKind:n}=e.pop();E(a,t,n)}for(let[e,n]of a){let r=0;for(let t=0;t<4;t++){let n=e.children[t];n&&n.isLeaf&&!n.hasTiles&&(n.clear(),e.children[t]=null,r=3)}r|=e.updateSubtreeSummaries(n|r),E(t,e.parent,r)}t.size>0&&(n=i-1)}}forEachTileIntersectingRay(e,t,n,r){r?this._forEachTileIntersectingVerticalRay(e,t,n):this._forEachTileIntersectingRayGeneral(e,t,n)}_forEachTileIntersectingRayGeneral(e,t,i){let a=this._rootNode;if(!a)return;n(B,t,e);let o=r(B,B);if(!a.subtreeIntersectsRay(e,o,{tMin:0,tMax:1/0}))return;let s=this._nextIntersectionGeneration(),c=[a],l=H;l.length=0,l.push(0,1/0);let u={tMin:0,tMax:1/0};for(;c.length>0;){let t=c.pop();u.tMax=l.pop(),u.tMin=l.pop(),t.forEachOwnTileIntersectingRay(e,o,u,s,i);let{hPlane:n,vPlane:r}=t;for(let i=0;i<4;i++){let a=t.children[i];if(a==null)continue;let s=i,d=s===0||s===2,f=s===0||s===1,p=N(e,o,N(e,o,u,r,!d),n,!f);p&&a.subtreeIntersectsRay(e,o,p)&&(c.push(a),l.push(p.tMin,p.tMax))}}}_forEachTileIntersectingVerticalRay(e,t,a){let o=this._rootNode;if(!o)return;n(B,t,e);let s=r(B,B),c={tMin:0,tMax:this.viewingMode===`global`?i(e):1/0};if(!o.subtreeIntersectsRay(e,s,c))return;let l=this._nextIntersectionGeneration(),u=[o];for(;u.length>0;){let t=u.pop();t.forEachOwnTileIntersectingRay(e,s,c,l,a),t.isLeaf||w(t,k(t.hPlane,e),k(t.vPlane,e),(t,n)=>{let r=t.children[n];r&&r.subtreeIntersectsRay(e,s,c)&&u.push(r)},1)}}getElevationRangeIntersectingSphere(e){let t=this._rootNode;if(!t||!t.subtreeIntersectsSphere(e))return null;let n=this._nextIntersectionGeneration(),r=new v,i=[t];for(;i.length>0;){let t=i.pop();if(!r.contains(t.subtreeElevationRange)){if(t.subtreeContainedBySphere(e))r.expandElevationRange(t.subtreeElevationRange);else{if(t.ownIntersectsSphere(e))for(let i of t.ownTiles){if(i.bvhIntersectionGeneration===n||(i.bvhIntersectionGeneration=n,!(i.boundingVolumeIntersectsSphere?.(e)??i.obb.intersectSphere(e))))continue;let t=i.elevationRange;r.contains(t)||r.expandElevationRange(t)}t.isLeaf||w(t,O(e.center,e.radius,t.hPlane),O(e.center,e.radius,t.vPlane),(t,n)=>{let a=t.children[n];if(a&&a.subtreeIntersectsSphere(e)){if(r.contains(a.subtreeElevationRange))return;i.push(a)}})}}}return r.isEmpty?null:r}}class x extends b{constructor(e){super(`local`,e)}_getSizeStopLength(e){return e.sideLength}_ensureRootNode(){if(!this._rootNode){let e=this.layerExtent,t=Math.max(Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2]),Math.abs(e[3])),n=2**Math.max(1,Math.ceil(Math.log2(t))),r=new C(null,0,g(-n,-n,n,n),new D(o(0,1,0),0),new D(o(1,0,0),0),n*2,c(-n,-n,-1/0,n,n,1/0));this._rootNode=r}return this._rootNode}_ensureChild(t,n){if(t.treeDepth>=U){let t=`Internal error: attempted to create a child node for a node that is already at max depth`;throw e.getLogger(`Tiles3DBVH`).error(t),Error(t)}let r=t.children[n];if(r===null){let{extent:e,hPlane:i,vPlane:a,treeDepth:o,sideLength:s}=t,l=.5*(e[0]+e[2]),u=.5*(e[1]+e[3]),d=n===0||n===1,f=n===2||n===0,p=g(f?e[0]:l,d?e[1]:u,f?l:e[2],d?u:e[3]),m=new D(i.normal,-.5*(p[1]+p[3])),h=new D(a.normal,-.5*(p[0]+p[2]));r=new C(t,o+1,p,m,h,s*.5,c(p[0],p[1],-1/0,p[2],p[3],1/0)),t.children[n]=r}return r}}class S extends b{constructor(e){super(`global`,e)}_getSizeStopLength(e){return M(e.extent)}_ensureRootNode(){if(!this._rootNode){let e=new C(null,0,g(-Math.PI,-Math.PI/2,Math.PI,Math.PI/2),new D(o(0,0,1),0),new D(o(0,1,0),0),Math.PI*_.radius);this._rootNode=e}return this._rootNode}_ensureChild(t,n){if(t.treeDepth>=U){let t=`Attempted to create a child node for a node that is already at max depth`;throw e.getLogger(`Tiles3DBVH`).error(t),Error(t)}let r=t.children[n];if(r===null){let{extent:e,treeDepth:i}=t,a=.5*(e[0]+e[2]),s=.5*(e[1]+e[3]),c=n===0||n===1,l=n===2||n===0,u=g(l?e[0]:a,c?e[1]:s,l?a:e[2],c?s:e[3]),d=.5*(u[0]+u[2]),f=.5*(u[1]+u[3]),p=Math.cos(d),m=Math.sin(d),h=Math.cos(f),_=Math.sin(f),v=o(-_*p,-_*m,h),y=new D(v,0),b=new D(o(-m,p,0),0),x=j(u);r=new C(t,i+1,u,y,b,x),t.children[n]=r}return r}}class C{constructor(e,t,n,r,i,a,o){this.parent=e,this._treeDepth=t,this.extent=n,this.hPlane=r,this.vPlane=i,this.sideLength=a,this.bounds=o,this._ownAABB=c(1/0,1/0,1/0,-1/0,-1/0,-1/0),this._subtreeAABB=c(1/0,1/0,1/0,-1/0,-1/0,-1/0),this._ownElevationRange=new v,this._subtreeElevationRange=new v,this._ownTiles=[],this.children=[null,null,null,null]}get subtreeAABB(){return this._subtreeAABB}get subtreeElevationRange(){return this._subtreeElevationRange}subtreeContainedBySphere(e){let t=this._subtreeAABB;return l(t)?!0:u(t,e)}clear(){for(let e=0;e<4;e++)this.children[e]?.clear(),this.children[e]=null;this._ownTiles.length=0,d(this._ownAABB),d(this._subtreeAABB),this._ownElevationRange.initializeEmpty(),this._subtreeElevationRange.initializeEmpty()}get isLeaf(){return this.children.every(e=>e==null)}get treeDepth(){return this._treeDepth}subtreeIntersectsSphere(e){return f(this.subtreeAABB,e)}ownIntersectsSphere(e){return this.hasTiles&&f(this._ownAABB,e)}subtreeIntersectsRay(e,t,n){return p(this._subtreeAABB,e,t,n)}ownIntersectsRay(e,t,n){return this.hasTiles?p(this._ownAABB,e,t,n):null}forEachOwnTileIntersectingRay(e,t,n,r,i){if(this.ownIntersectsRay(e,t,n))for(let n of this.ownTiles)n.bvhIntersectionGeneration!==r&&(n.bvhIntersectionGeneration=r,(n.boundingVolumeIntersectsRay?.(e,t)??n.obb.intersectRay(e,t))&&i(n))}addOwnTile(e){this._ownTiles.push(e);let t=P(this._ownAABB,e,this.bounds)&&F(this._subtreeAABB,this._ownAABB,this.bounds),n=this._ownElevationRange.expandElevationRange(e.elevationRange)&&this._subtreeElevationRange.expandElevationRange(e.elevationRange);return!!t|(n?2:0)}removeOwnTile(t){let n=this._ownTiles,r=n.indexOf(t);if(r===-1){e.getLogger(`Tiles3DBVH`).error(`BVNode: Attempted to remove a tile that is not in the node`);return}let i=n.length-1;r<i&&(n[r]=n[i]),n.length=i}updateOwnSummaries(){let e=I(this._ownAABB,this.ownTiles,this.bounds),t=L(this._ownElevationRange,this.ownTiles),n=!!e|(t?2:0);return this.updateSubtreeSummaries(n)}updateSubtreeSummaries(e){if(this.isLeaf&&!this.hasTiles)return d(this._subtreeAABB),this._subtreeElevationRange.initializeEmpty(),3;let t=0;if(e&1){m(R,this._subtreeAABB),d(this._subtreeAABB),F(this._subtreeAABB,this._ownAABB,this.bounds);for(let e of this.children)e&&F(this._subtreeAABB,e.subtreeAABB,this.bounds);h(this._subtreeAABB,R)||(t|=1)}if(e&2){z.setElevationRange(this._subtreeElevationRange),this._subtreeElevationRange.initializeEmpty(),this._subtreeElevationRange.expandElevationRange(this._ownElevationRange);for(let e of this.children)e&&this._subtreeElevationRange.expandElevationRange(e.subtreeElevationRange);this._subtreeElevationRange.equals(z)||(t|=2)}return t}get ownTiles(){return this._ownTiles}get hasTiles(){return this._ownTiles.length>0}}function w(e,t,n,r,i=1e-12){t<=i&&(n<=i&&r(e,0),n>=-i&&r(e,1)),t>=-i&&(n<=i&&r(e,2),n>=-i&&r(e,3))}function T(e,t,n){t!=null&&n!==0&&e.push({node:t,childrenUpdateKind:n})}function E(e,t,n){if(t==null||n===0)return;let r=e.get(t)??0;e.set(t,r|n)}class D{constructor(e=[0,0,0],t=0){this.normal=e,this.distance=t}}function O(e,t,n){let r=a(n.normal,e)+n.distance;return r<0?Math.min(r+t,0):Math.max(r-t,0)}function k(e,t){return a(e.normal,t)+e.distance}function A(e){return 2*Math.max(e.halfSizeX,e.halfSizeY,e.halfSizeZ)}function j(e){let t=Math.abs(e[2]-e[0]),n=Math.abs(e[3]-e[1]),r=.5*(e[1]+e[3]),i=_.radius*Math.abs(Math.cos(r))*t,a=_.radius*n;return Math.max(i,a)}function M(e){let t=Math.abs(e[2]-e[0]),n=Math.abs(e[3]-e[1]),r=.5*(e[1]+e[3]),i=_.radius*Math.abs(Math.cos(r))*t,a=_.radius*n;return Math.min(i,a)}function N(e,t,n,r,i){if(!n)return null;let o=1e-12,s=a(r.normal,t),c=k(r,e)+n.tMin*s;if(Math.abs(s)<o)return(i?c>=-1e-12:c<=o)?n:null;let l=n.tMin-c/s,u=i===s>0?{tMin:Math.max(n.tMin,l),tMax:n.tMax}:{tMin:n.tMin,tMax:Math.min(n.tMax,l)};return u.tMin<=u.tMax?u:null}function P(e,t,n){let{obb:r}=t,i=[o(1,0,0),o(0,1,0),o(0,0,1)],a=r.getCenter(V),s=!1;for(let t=0;t<3;t++){let o=r.projectedRadius(i[t]),c=Math.max(n?.[t]??-1/0,a[t]-o),l=Math.min(n?.[t+3]??1/0,a[t]+o);c<e[t]&&(e[t]=c,s=!0),l>e[t+3]&&(e[t+3]=l,s=!0)}return s}function F(e,t,n){if(l(t))return!1;let r=!1;for(let i=0;i<3;i++){let a=Math.max(n?.[i]??-1/0,t[i]),o=Math.min(n?.[i+3]??1/0,t[i+3]);a<e[i]&&(e[i]=a,r=!0),o>e[i+3]&&(e[i+3]=o,r=!0)}return r}function I(e,t,n){m(R,e),d(e);for(let r of t)P(e,r,n);return!h(e,R)}function L(e,t){z.setElevationRange(e),e.initializeEmpty();for(let n of t)e.expandElevationRange(n.elevationRange);return!e.equals(z)}const R=c(0,0,0,0,0,0),z=new v,B=s(),V=s(),H=[],U=30;export{y as createTileBVH};
2
+ import e from"../../../../core/Logger.js";import{getOrCreateMapValue as t}from"../../../../core/MapUtils.js";import{sub as n,normalize as r,len as i,dot as a}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as o,create as s}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as c,isEmpty as l,containedBySphere as u,setEmpty as d,intersectsSphere as f,intersectsRay as p,copy as m,exactEquals as h}from"../../../../geometry/support/aaBoundingBox.js";import{fromValues as g}from"../../../../geometry/support/aaBoundingRect.js";import{earth as _}from"../../../../geometry/support/Ellipsoid.js";import{ElevationRange as v}from"../../support/ElevationRange.js";function y(e,t){return e===`local`?new x(t):new S(t)}class b{constructor(e,t){this.viewingMode=e,this.layerExtent=t,this._rootNode=null,this._intersectionGeneration=0,this._tileMap=new Map}get elevationRange(){return this._rootNode?.subtreeElevationRange}destroy(){this._rootNode?.clear(),this._tileMap.clear()}_nextIntersectionGeneration(){return this._intersectionGeneration++,this._intersectionGeneration}addTile(e){let{obb:n}=e,r=[this._ensureRootNode()],i=[],a=t(this._tileMap,e,()=>new Set),o=t=>{if(a.has(t))return;let n=t.addOwnTile(e);T(i,t.parent,n),a.add(t)};for(;r.length>0;){let t=r.pop(),i=this._getSizeStopLength(t);if(t.treeDepth>=U||A(e.obb)>=.5*i){o(t);continue}let{hPlane:a,vPlane:s}=t,c=n.signedDistancePlane(a.normal,a.distance),l=n.signedDistancePlane(s.normal,s.distance);c===0&&l===0?o(t):w(t,c,l,(e,t)=>{r.push(this._ensureChild(e,t))})}this._propagateSummaryUpdates(i)}removeTile(t){if(!this._rootNode){e.getLogger(`Tiles3DBVH`).error(`Tiles3DBVH: Attempted to remove a tile that is not loaded (no root node)`);return}let n=this._tileMap.get(t);if(!n||n.size===0){e.getLogger(`Tiles3DBVH`).error(`Tiles3DBVH internal error: Attempted to remove a tile that is not loaded (not in tile map)`);return}let r=[];this._tileMap.delete(t);for(let e of n){e.removeOwnTile(t);let n=e.updateOwnSummaries();T(r,e.parent,n)}this._propagateSummaryUpdates(r)}_propagateSummaryUpdates(e){if(e.length===0)return;e.sort((e,t)=>e.node.treeDepth-t.node.treeDepth);let t=new Map,n=-1,r=()=>e.length>0?e[e.length-1].node.treeDepth:-1;for(;e.length>0||t.size>0;){let i=t.size>0?n:r(),a=t;for(t=new Map;e.length>0&&r()===i;){let{node:t,childrenUpdateKind:n}=e.pop();E(a,t,n)}for(let[e,n]of a){let r=0;for(let t=0;t<4;t++){let n=e.children[t];n&&n.isLeaf&&!n.hasTiles&&(n.clear(),e.children[t]=null,r=3)}r|=e.updateSubtreeSummaries(n|r),E(t,e.parent,r)}t.size>0&&(n=i-1)}}forEachTileIntersectingRay(e,t,n,r){r?this._forEachTileIntersectingVerticalRay(e,t,n):this._forEachTileIntersectingRayGeneral(e,t,n)}_forEachTileIntersectingRayGeneral(e,t,i){let a=this._rootNode;if(!a)return;n(B,t,e);let o=r(B,B);if(!a.subtreeIntersectsRay(e,o,{tMin:0,tMax:1/0}))return;let s=this._nextIntersectionGeneration(),c=[a],l=H;l.length=0,l.push(0,1/0);let u={tMin:0,tMax:1/0};for(;c.length>0;){let t=c.pop();u.tMax=l.pop(),u.tMin=l.pop(),t.forEachOwnTileIntersectingRay(e,o,u,s,i);let{hPlane:n,vPlane:r}=t;for(let i=0;i<4;i++){let a=t.children[i];if(a==null)continue;let s=i,d=s===0||s===2,f=s===0||s===1,p=N(e,o,N(e,o,u,r,!d),n,!f);p&&a.subtreeIntersectsRay(e,o,p)&&(c.push(a),l.push(p.tMin,p.tMax))}}}_forEachTileIntersectingVerticalRay(e,t,a){let o=this._rootNode;if(!o)return;n(B,t,e);let s=r(B,B),c={tMin:0,tMax:this.viewingMode===`global`?i(e):1/0};if(!o.subtreeIntersectsRay(e,s,c))return;let l=this._nextIntersectionGeneration(),u=[o];for(;u.length>0;){let t=u.pop();t.forEachOwnTileIntersectingRay(e,s,c,l,a),t.isLeaf||w(t,k(t.hPlane,e),k(t.vPlane,e),(t,n)=>{let r=t.children[n];r&&r.subtreeIntersectsRay(e,s,c)&&u.push(r)},1)}}getElevationRangeIntersectingSphere(e){let t=this._rootNode;if(!t||!t.subtreeIntersectsSphere(e))return null;let n=this._nextIntersectionGeneration(),r=new v,i=[t];for(;i.length>0;){let t=i.pop();if(!r.contains(t.subtreeElevationRange)){if(t.subtreeContainedBySphere(e))r.expandElevationRange(t.subtreeElevationRange);else{if(t.ownIntersectsSphere(e))for(let i of t.ownTiles){if(i.bvhIntersectionGeneration===n||(i.bvhIntersectionGeneration=n,!(i.boundingVolumeIntersectsSphere?.(e)??i.obb.intersectSphere(e))))continue;let t=i.elevationRange;r.contains(t)||r.expandElevationRange(t)}t.isLeaf||w(t,O(e.center,e.radius,t.hPlane),O(e.center,e.radius,t.vPlane),(t,n)=>{let a=t.children[n];if(a&&a.subtreeIntersectsSphere(e)){if(r.contains(a.subtreeElevationRange))return;i.push(a)}})}}}return r.isEmpty?null:r}}class x extends b{constructor(e){super(`local`,e)}_getSizeStopLength(e){return e.sideLength}_ensureRootNode(){if(!this._rootNode){let e=this.layerExtent,t=Math.max(Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2]),Math.abs(e[3])),n=2**Math.max(1,Math.ceil(Math.log2(t))),r=new C(null,0,g(-n,-n,n,n),new D(o(0,1,0),0),new D(o(1,0,0),0),n*2,c(-n,-n,-1/0,n,n,1/0));this._rootNode=r}return this._rootNode}_ensureChild(t,n){if(t.treeDepth>=U){let t=`Internal error: attempted to create a child node for a node that is already at max depth`;throw e.getLogger(`Tiles3DBVH`).error(t),Error(t)}let r=t.children[n];if(r===null){let{extent:e,hPlane:i,vPlane:a,treeDepth:o,sideLength:s}=t,l=.5*(e[0]+e[2]),u=.5*(e[1]+e[3]),d=n===0||n===1,f=n===2||n===0,p=g(f?e[0]:l,d?e[1]:u,f?l:e[2],d?u:e[3]),m=new D(i.normal,-.5*(p[1]+p[3])),h=new D(a.normal,-.5*(p[0]+p[2]));r=new C(t,o+1,p,m,h,s*.5,c(p[0],p[1],-1/0,p[2],p[3],1/0)),t.children[n]=r}return r}}class S extends b{constructor(e){super(`global`,e)}_getSizeStopLength(e){return M(e.extent)}_ensureRootNode(){if(!this._rootNode){let e=new C(null,0,g(-Math.PI,-Math.PI/2,Math.PI,Math.PI/2),new D(o(0,0,1),0),new D(o(0,1,0),0),Math.PI*_.radius);this._rootNode=e}return this._rootNode}_ensureChild(t,n){if(t.treeDepth>=U){let t=`Attempted to create a child node for a node that is already at max depth`;throw e.getLogger(`Tiles3DBVH`).error(t),Error(t)}let r=t.children[n];if(r===null){let{extent:e,treeDepth:i}=t,a=.5*(e[0]+e[2]),s=.5*(e[1]+e[3]),c=n===0||n===1,l=n===2||n===0,u=g(l?e[0]:a,c?e[1]:s,l?a:e[2],c?s:e[3]),d=.5*(u[0]+u[2]),f=.5*(u[1]+u[3]),p=Math.cos(d),m=Math.sin(d),h=Math.cos(f),_=Math.sin(f),v=o(-_*p,-_*m,h),y=new D(v,0),b=new D(o(-m,p,0),0),x=j(u);r=new C(t,i+1,u,y,b,x),t.children[n]=r}return r}}class C{constructor(e,t,n,r,i,a,o){this.parent=e,this._treeDepth=t,this.extent=n,this.hPlane=r,this.vPlane=i,this.sideLength=a,this.bounds=o,this._ownAABB=c(1/0,1/0,1/0,-1/0,-1/0,-1/0),this._subtreeAABB=c(1/0,1/0,1/0,-1/0,-1/0,-1/0),this._ownElevationRange=new v,this._subtreeElevationRange=new v,this._ownTiles=[],this.children=[null,null,null,null]}get subtreeAABB(){return this._subtreeAABB}get subtreeElevationRange(){return this._subtreeElevationRange}subtreeContainedBySphere(e){let t=this._subtreeAABB;return l(t)?!0:u(t,e)}clear(){for(let e=0;e<4;e++)this.children[e]?.clear(),this.children[e]=null;this._ownTiles.length=0,d(this._ownAABB),d(this._subtreeAABB),this._ownElevationRange.initializeEmpty(),this._subtreeElevationRange.initializeEmpty()}get isLeaf(){return this.children.every(e=>e==null)}get treeDepth(){return this._treeDepth}subtreeIntersectsSphere(e){return f(this.subtreeAABB,e)}ownIntersectsSphere(e){return this.hasTiles&&f(this._ownAABB,e)}subtreeIntersectsRay(e,t,n){return p(this._subtreeAABB,e,t,n)}ownIntersectsRay(e,t,n){return this.hasTiles?p(this._ownAABB,e,t,n):null}forEachOwnTileIntersectingRay(e,t,n,r,i){if(this.ownIntersectsRay(e,t,n))for(let n of this.ownTiles)n.bvhIntersectionGeneration!==r&&(n.bvhIntersectionGeneration=r,(n.boundingVolumeIntersectsRay?.(e,t)??n.obb.intersectRay(e,t))&&i(n))}addOwnTile(e){this._ownTiles.push(e);let t=P(this._ownAABB,e,this.bounds)&&F(this._subtreeAABB,this._ownAABB,this.bounds),n=this._ownElevationRange.expandElevationRange(e.elevationRange)&&this._subtreeElevationRange.expandElevationRange(e.elevationRange);return!!t|(n?2:0)}removeOwnTile(t){let n=this._ownTiles,r=n.indexOf(t);if(r===-1){e.getLogger(`Tiles3DBVH`).error(`BVNode: Attempted to remove a tile that is not in the node`);return}let i=n.length-1;r<i&&(n[r]=n[i]),n.length=i}updateOwnSummaries(){let e=I(this._ownAABB,this.ownTiles,this.bounds),t=L(this._ownElevationRange,this.ownTiles),n=!!e|(t?2:0);return this.updateSubtreeSummaries(n)}updateSubtreeSummaries(e){if(this.isLeaf&&!this.hasTiles)return d(this._subtreeAABB),this._subtreeElevationRange.initializeEmpty(),3;let t=0;if(e&1){m(R,this._subtreeAABB),d(this._subtreeAABB),F(this._subtreeAABB,this._ownAABB,this.bounds);for(let e of this.children)e&&F(this._subtreeAABB,e.subtreeAABB,this.bounds);h(this._subtreeAABB,R)||(t|=1)}if(e&2){z.setElevationRange(this._subtreeElevationRange),this._subtreeElevationRange.initializeEmpty(),this._subtreeElevationRange.expandElevationRange(this._ownElevationRange);for(let e of this.children)e&&this._subtreeElevationRange.expandElevationRange(e.subtreeElevationRange);this._subtreeElevationRange.equals(z)||(t|=2)}return t}get ownTiles(){return this._ownTiles}get hasTiles(){return this._ownTiles.length>0}}function w(e,t,n,r,i=1e-12){t<=i&&(n<=i&&r(e,0),n>=-i&&r(e,1)),t>=-i&&(n<=i&&r(e,2),n>=-i&&r(e,3))}function T(e,t,n){t!=null&&n!==0&&e.push({node:t,childrenUpdateKind:n})}function E(e,t,n){if(t==null||n===0)return;let r=e.get(t)??0;e.set(t,r|n)}class D{constructor(e=[0,0,0],t=0){this.normal=e,this.distance=t}}function O(e,t,n){let r=a(n.normal,e)+n.distance;return r<0?Math.min(r+t,0):Math.max(r-t,0)}function k(e,t){return a(e.normal,t)+e.distance}function A(e){return 2*Math.max(e.halfSizeX,e.halfSizeY,e.halfSizeZ)}function j(e){let t=Math.abs(e[2]-e[0]),n=Math.abs(e[3]-e[1]),r=.5*(e[1]+e[3]),i=_.radius*Math.abs(Math.cos(r))*t,a=_.radius*n;return Math.max(i,a)}function M(e){let t=Math.abs(e[2]-e[0]),n=Math.abs(e[3]-e[1]),r=.5*(e[1]+e[3]),i=_.radius*Math.abs(Math.cos(r))*t,a=_.radius*n;return Math.min(i,a)}function N(e,t,n,r,i){if(!n)return null;let o=1e-12,s=a(r.normal,t),c=k(r,e)+n.tMin*s;if(Math.abs(s)<o)return(i?c>=-1e-12:c<=o)?n:null;let l=n.tMin-c/s,u=i===s>0?{tMin:Math.max(n.tMin,l),tMax:n.tMax}:{tMin:n.tMin,tMax:Math.min(n.tMax,l)};return u.tMin<=u.tMax?u:null}function P(e,t,n){let{obb:r}=t,i=[o(1,0,0),o(0,1,0),o(0,0,1)],a=r.getCenter(V),s=!1;for(let t=0;t<3;t++){let o=r.projectedRadius(i[t]),c=Math.max(n?.[t]??-1/0,a[t]-o),l=Math.min(n?.[t+3]??1/0,a[t]+o);c<e[t]&&(e[t]=c,s=!0),l>e[t+3]&&(e[t+3]=l,s=!0)}return s}function F(e,t,n){if(l(t))return!1;let r=!1;for(let i=0;i<3;i++){let a=Math.max(n?.[i]??-1/0,t[i]),o=Math.min(n?.[i+3]??1/0,t[i+3]);a<e[i]&&(e[i]=a,r=!0),o>e[i+3]&&(e[i+3]=o,r=!0)}return r}function I(e,t,n){m(R,e),d(e);for(let r of t)P(e,r,n);return!h(e,R)}function L(e,t){z.setElevationRange(e),e.initializeEmpty();for(let n of t)e.expandElevationRange(n.elevationRange);return!e.equals(z)}const R=c(0,0,0,0,0,0),z=new v,B=s(),V=s(),H=[],U=30;export{y as createTileBVH};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import has from"../../../../core/has.js";import{create as e}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{project as t}from"../../../../geometry/projectionUtils.js";import{fromExtent as n}from"../../../../geometry/support/aaBoundingRect.js";import{Tiles3DTarget as r}from"../i3s/Intersector.js";import{createTileBVH as i}from"./Tiles3DBVH.js";import{ElevationRange as a}from"../../support/ElevationRange.js";import{IntersectorResultRay as o}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as s,computeInvDir as c,intersectAabbInvDir as l}from"../../webgl-engine/lib/RayIntersections.js";class u{constructor(e){this.layerView=e,this.type=8,this.slicePlaneEnabled=!1,this.layerViewUid=e.uid;let r=e.view.viewingMode,a=(e.useEsriCrs?e.fullExtentInLocalViewSpatialReference:e.layer.fullExtent?t(e.layer.fullExtent,e.view.renderSpatialReference):void 0)??e.view.extent,o=n(a);this.isGround=!has(`enable-feature:im-as-ground`)||e.layer.isUsedAsGroundLayer,this._bvh=i(r,o)}destroy(){this._bvh.destroy()}addTile(e){this._bvh.addTile(e)}removeTile(e){this._bvh.removeTile(e)}intersectRay(e,t,n,i,a,u){if(e.options.filteredLayerViewUids.includes(this.layerView.uid))return;let{results:f,tolerance:p}=e,m=e.options.store===2,{componentObjectCollection:h}=this.layerView.view.stage.renderView,g=new s(p,u,e.options.normalRequired),_=c(n,i,d),v=(a,s,c)=>{if(s<0||t!=null&&!t(n,i,a))return;let l=e=>{let t=new r(this.layerView.uid);e.set(this.type,t,a,s,c)};if(this.isGround&&(f.ground.renderDistance==null||s<f.ground.renderDistance)&&l(f.ground),!e.options.isFiltered&&((f.min.renderDistance==null||s<f.min.renderDistance)&&l(f.min),(f.max.renderDistance==null||s>f.max.renderDistance)&&l(f.max),m)){let t=new o(e.ray);l(t),e.results.all.push(t)}};this._bvh.forEachTileIntersectingRay(n,i,e=>{let{componentObjects:t}=e;for(let e of t)l(e.aabbInWorldCoordinates,n,_,0)&&h.intersectRay(e,n,i,null,g,v)},u)}getElevationRange(e){return this._bvh.getElevationRangeIntersectingSphere(e)??new a(0,0)}}const d=e();export{u as Tiles3DMeshIntersectionHandler};
2
+ import has from"../../../../core/has.js";import{create as e}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{project as t}from"../../../../geometry/projectionUtils.js";import{fromExtent as n}from"../../../../geometry/support/aaBoundingRect.js";import{Tiles3DTarget as r}from"../i3s/Intersector.js";import{createTileBVH as i}from"./Tiles3DBVH.js";import{ElevationRange as a}from"../../support/ElevationRange.js";import{IntersectorResultRay as o}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as s,computeInvDir as c,intersectAabbInvDir as l}from"../../webgl-engine/lib/RayIntersections.js";class u{constructor(e){this.layerView=e,this.type=8,this.slicePlaneEnabled=!1,this.layerViewUid=e.uid;let r=e.view.viewingMode,a=(e.useEsriCrs?e.fullExtentInLocalViewSpatialReference:e.layer.fullExtent?t(e.layer.fullExtent,e.view.renderSpatialReference):void 0)??e.view.extent,o=n(a);this.isGround=!has(`enable-feature:im-as-ground`)||e.layer.isUsedAsGroundLayer,this._bvh=i(r,o)}destroy(){this._bvh.destroy()}addTile(e){this._bvh.addTile(e)}removeTile(e){this._bvh.removeTile(e)}intersectRay(e,t,n,i,a,u){if(e.options.filteredLayerViewUids.includes(this.layerView.uid))return;let{results:f,tolerance:p}=e,m=e.options.store===2,{componentObjectCollection:h}=this.layerView.view.stage.renderView,g=new s(p,u,e.options.normalRequired),_=c(n,i,d),v=(a,s,c)=>{if(s<0||t!=null&&!t(n,i,a))return;let l=e=>{let t=new r(this.layerView.uid);e.set(this.type,t,a,s,c)};if(this.isGround&&(f.ground.renderDistance==null||s<f.ground.renderDistance)&&l(f.ground),!e.options.isFiltered&&((f.min.renderDistance==null||s<f.min.renderDistance)&&l(f.min),(f.max.renderDistance==null||s>f.max.renderDistance)&&l(f.max),m)){let t=new o(e.ray);l(t),e.results.all.push(t)}};this._bvh.forEachTileIntersectingRay(n,i,e=>{let{componentObjects:t}=e;for(let e of t)l(e.aabbInWorldCoordinates,n,_,0)&&h.intersectRay(e,n,i,null,g,v)},u)}get elevationRange(){let e=this._bvh.elevationRange;return e!=null&&!e.isEmpty?new a(e.minElevation,e.maxElevation):null}getElevationRange(e){return this._bvh.getElevationRangeIntersectingSphere(e)??new a(0,0)}}const d=e();export{u as Tiles3DMeshIntersectionHandler};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../../core/Logger.js";import{property as n,subclass as r}from"../../../../core/accessorSupport/decorators.js";import{NavigationMode3D as i}from"./NavigationMode3D.js";let a=class extends i{constructor(e){super(e),this.type=`ground`,this.nearOverride=.5,this.farOverride=1e4}attach(e){super.attach(e),this._warnIfOffsetIsBelowConstraints()}detach(){super.detach()}get offset(){let e=this._get(`offset`);return e===void 0?1.5:e}set offset(e){this._set(`offset`,e),this._warnIfOffsetIsBelowConstraints()}_warnIfOffsetIsBelowConstraints(){if(this.view==null||this.offset==null)return;let e=this.view.state.constraints.altitude,n=this.view.state.constraints.collision;e&&this.offset<e.min&&t.getLogger(this).warn(`offset-smaller-than-altitude-constraint`,`The ground navigation offset of ${this.offset} is smaller than the view's min altitude constraint with a value of ${e.min}. Unexpected behaviour close to ground might occur. Adjust or remove constraints from view.constraints.altitude to address this.`);let r=this.view.state.constraints.elevationMargin;n?.enabled&&this.offset<r&&t.getLogger(this).warn(`offset-smaller-than-navigation-constraint`,`The ground navigation offset of ${this.offset} is smaller than the value of ${r} that is enforced by the view's navigation constraint. Unexpected behaviour close to ground might occur. Adjust or remove constraints from view.map.ground.navigationConstraint to address this.`)}};e([n()],a.prototype,`include`,void 0),e([n()],a.prototype,`exclude`,void 0),e([n()],a.prototype,`offset`,null),a=e([r(`esri.views.3d.navigation.modes.GroundNavigationMode3D`)],a);export{a as GroundNavigationMode3D};
2
+ import{__decorate as e}from"tslib";import t from"../../../../core/Logger.js";import{property as n,subclass as r}from"../../../../core/accessorSupport/decorators.js";import{NavigationMode3D as i}from"./NavigationMode3D.js";let a=class extends i{constructor(e){super(e),this.type=`ground`,this.nearOverride=.5,this.farOverride=1e4}attach(e){super.attach(e),this._warnIfOffsetIsBelowConstraints()}detach(){super.detach()}get offset(){let e=this._get(`offset`);return e===void 0?1.5:e}set offset(e){this._set(`offset`,e),this._warnIfOffsetIsBelowConstraints()}_warnIfOffsetIsBelowConstraints(){if(this.view==null||this.offset==null)return;let e=this.view.state.constraints.altitude,n=this.view.state.constraints.collision;e&&this.offset<e.min&&t.getLogger(this).warn(`offset-smaller-than-altitude-constraint`,`The ground navigation offset of ${this.offset} is smaller than the view's min altitude constraint with a value of ${e.min}. Unexpected behaviour close to ground might occur. Adjust or remove constraints from view.constraints.altitude to address this.`);let r=n.elevationMargin;n?.enabled&&this.offset<r&&t.getLogger(this).warn(`offset-smaller-than-navigation-constraint`,`The ground navigation offset of ${this.offset} is smaller than the value of ${r} that is enforced by the view's navigation constraint. Unexpected behaviour close to ground might occur. Adjust or remove constraints from view.map.ground.navigationConstraint to address this.`)}};e([n()],a.prototype,`include`,void 0),e([n()],a.prototype,`exclude`,void 0),e([n()],a.prototype,`offset`,null),a=e([r(`esri.views.3d.navigation.modes.GroundNavigationMode3D`)],a);export{a as GroundNavigationMode3D};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import n from"../../../core/Logger.js";import{clamp as r,deg2rad as i}from"../../../core/mathUtils.js";import{property as a,subclass as o}from"../../../core/accessorSupport/decorators.js";import{earth as s}from"../../../geometry/support/Ellipsoid.js";import{makePiecewiseLinearFunction as c}from"../support/mathUtils.js";let l=class extends t{constructor(e){super(e),this.collision=new g,this.distance=1/0,this.minimumPoiDistance=4,this.tilt=null}get altitude(){return this.mode===2?null:this._get(`altitude`)||null}set altitude(e){this.mode===2?n.getLogger(this).warn(`Altitude constraint is ignored in local scenes`):this._set(`altitude`,e)}get elevationMargin(){return this.state.view.navigation.mode.type===`ground`||this.state.view.navigation.isInPlacementMode?h:m}get mode(){return this.state.viewingMode}clampAltitude(e){return this.altitude?r(e,this.altitude.min,this.altitude.max):e}clampTilt(e,t){if(!this.tilt)return t;let n=this.tilt(e);return r(t,n.min,n.max)}clampDistance(e){return Math.min(e,this.distance)}createDefaultTilt(){return this.mode===2?this._createDefaultTiltLocal():this._createDefaultTiltGlobal()}createConstantMaxTilt(e){return(t,n=p)=>(n.min=f.min,n.max=e,n)}_createDefaultTiltLocal(){let e=this.collision.enabled?c([[4e3,f.max],[1e4,i(88)],[6e6,i(88)]]):()=>f.max;return(t,n=p)=>(n.min=f.min,n.max=e(t),n)}_createDefaultTiltGlobal(){let e=this.collision.enabled?c([[4e3,f.max],[5e4,i(88)],[6e6,i(88)],[2e7,f.min]]):c([[3e5,f.max],[3e6,i(88)],[6e6,i(88)],[2e7,f.min]]);return(t,n=p)=>(n.min=f.min,n.max=e(t),n)}};e([a()],l.prototype,`altitude`,null),e([a({readOnly:!0})],l.prototype,`collision`,void 0),e([a()],l.prototype,`elevationMargin`,null),e([a()],l.prototype,`distance`,void 0),e([a({readOnly:!0})],l.prototype,`minimumPoiDistance`,void 0),e([a()],l.prototype,`tilt`,void 0),e([a({constructOnly:!0})],l.prototype,`state`,void 0),l=e([o(`esri.views.3d.state.Constraints`)],l);function u(e){return{min:-2e5,max:4*e.radius}}const d=u(s),f={min:i(.5),max:i(179.5)},p={min:0,max:0},m=5,h=1;let g=class extends t{constructor(){super(...arguments),this.enabled=!0}};e([a({type:Boolean})],g.prototype,`enabled`,void 0),g=e([o(`esri.views.3d.state.Constraints.CollisionConstraint`)],g);export{l as Constraints,f as TiltRange,d as earthAltitudeConstraint};
2
+ import{__decorate as e}from"tslib";import t from"../../../core/Accessor.js";import n from"../../../core/Logger.js";import{clamp as r,deg2rad as i}from"../../../core/mathUtils.js";import{property as a,subclass as o}from"../../../core/accessorSupport/decorators.js";import{earth as s}from"../../../geometry/support/Ellipsoid.js";import{makePiecewiseLinearFunction as c}from"../support/mathUtils.js";let l=class extends t{constructor(e){super(e),this.collision=new m,this.distance=1/0,this.minimumPoiDistance=4,this.tilt=null}get altitude(){return this.mode===2?null:this._get(`altitude`)||null}set altitude(e){this.mode===2?n.getLogger(this).warn(`Altitude constraint is ignored in local scenes`):this._set(`altitude`,e)}get mode(){return this.state.viewingMode}clampAltitude(e){return this.altitude?r(e,this.altitude.min,this.altitude.max):e}clampTilt(e,t){if(!this.tilt)return t;let n=this.tilt(e);return r(t,n.min,n.max)}clampDistance(e){return Math.min(e,this.distance)}createDefaultTilt(){return this.mode===2?this._createDefaultTiltLocal():this._createDefaultTiltGlobal()}createConstantMaxTilt(e){return(t,n=p)=>(n.min=f.min,n.max=e,n)}_createDefaultTiltLocal(){let e=this.collision.enabled?c([[4e3,f.max],[1e4,i(88)],[6e6,i(88)]]):()=>f.max;return(t,n=p)=>(n.min=f.min,n.max=e(t),n)}_createDefaultTiltGlobal(){let e=this.collision.enabled?c([[4e3,f.max],[5e4,i(88)],[6e6,i(88)],[2e7,f.min]]):c([[3e5,f.max],[3e6,i(88)],[6e6,i(88)],[2e7,f.min]]);return(t,n=p)=>(n.min=f.min,n.max=e(t),n)}};e([a()],l.prototype,`altitude`,null),e([a({readOnly:!0})],l.prototype,`collision`,void 0),e([a()],l.prototype,`distance`,void 0),e([a({readOnly:!0})],l.prototype,`minimumPoiDistance`,void 0),e([a()],l.prototype,`tilt`,void 0),e([a({constructOnly:!0})],l.prototype,`state`,void 0),l=e([o(`esri.views.3d.state.Constraints`)],l);function u(e){return{min:-2e5,max:4*e.radius}}const d=u(s),f={min:i(.5),max:i(179.5)},p={min:0,max:0};let m=class extends t{constructor(){super(...arguments),this.enabled=!0,this.elevationMargin=1}};e([a({type:Boolean})],m.prototype,`enabled`,void 0),e([a({type:Number})],m.prototype,`elevationMargin`,void 0),m=e([o(`esri.views.3d.state.Constraints.CollisionConstraint`)],m);export{l as Constraints,f as TiltRange,d as earthAltitudeConstraint};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{acosClamped as e,lerp as t,clamp as n}from"../../../core/mathUtils.js";import{getMetersPerUnitForSR as r}from"../../../core/units.js";import{length as i,normalize as a,scale as o,dot as s,subtract as c,set as l}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as u}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as d}from"../../../geometry/ellipsoidUtils.js";import f from"../../../geometry/Extent.js";import{create as p,fromValues as m}from"../../../geometry/support/ray.js";import{Sphere as h}from"../../../geometry/support/sphere.js";import{computeInnerAltitudeFade as g}from"../webgl-engine/effects/atmosphere/atmosphereUtils.js";import{DepthRange as _}from"../webgl-engine/lib/DepthRange.js";function v(e,t,n){return e===1?new b(t,n):new y(t,n)}class y{constructor(e,t){this._elevationProvider=e,this._referenceEllipsoid=d(t),this._unitInMeters=r(t,this._referenceEllipsoid.metersPerDegree)}compute(e,r,i,o){let{eye:u,center:d}=e,f=this._unitInMeters,p=u[2]*f,m=p-o,h=this._elevationProvider?.visibleElevationRange,g=h?m>=0?p-f*h.minElevation:f*h.maxElevation-p:p,_=r??P,v={x:_.xmax-_.xmin,y:_.ymax-_.ymin,z:4*Math.max(_.xmax-_.xmin,_.ymax-_.ymin)},y=Math.max(v.x,v.y,v.z),b=c(A,d,u),S=l(k,b[0]>0?_.xmax:_.xmin,b[1]>0?_.ymax:_.ymin,b[2]>0?y/2:-y/2);c(S,S,u),a(b,b);let C=s(S,b)*1.1*f,T=Math.abs(m),E=Math.sqrt(T*(T+2*this._referenceEllipsoid.radius)),M=Math.max(_.xmax-_.xmin,_.ymax-_.ymin),N=M*D*f,F=M*O*f,I=n((g-F)/(N-F),0,1)**3,L=Math.min(t(E,C,I),E)*Math.max(Math.log(Math.abs(m)),1);return x(Math.min(L,Math.max(34064e4,y))/f,w,f,j)}computeFarDistance(e,t,n){return n}}class b{constructor(e,t){this._elevationProvider=e,this._referenceEllipsoid=d(t)}compute(r,l,u,d){let{eye:f}=r,p=i(f),h=this._referenceEllipsoid.radius,v=p-h,y=this._computeVirtualAltitude(v,d),b=this._elevationProvider?.visibleElevationRange.maxElevation??0,D=g(y),O=this._computeFarDistance(p,y,d),P=(Math.log(y)-S)/(C-S);x(O,n(w-P*(w-T),T,w),1,j);let F=h+b,I=h+this._referenceEllipsoid.atmosphereHeight,L=Math.max(F,I),R=p-L;if(D>0&&R>E){let n=a(k,o(k,r.eye,-1)),l=a(A,r.viewForward),d=e(s(n,l)),f=r.fovY*.5,p=Math.cos(f),h=_.Infinite.near;if(d<=f)h=R*p;else{let e=a(k,r.viewUp),t=o(k,e,Math.tan(f)),n=a(k,c(k,l,t)),s=m(r.eye,n,N);if(M.radius=L,M.intersectRay(s,k)){let e=c(k,k,r.eye);h=i(e)*p}}let g=Math.min(u.near,h)*.99;g<_.Infinite.near&&g>j.near&&(j.near=t(j.near,g,D))}return j}computeFarDistance(e,t){let n=i(e),r=n-this._referenceEllipsoid.radius,a=this._computeVirtualAltitude(r,t);return this._computeFarDistance(n,a,t)}_computeFarDistance(e,t,n){let r=this._referenceEllipsoid.radius,i=r+Math.min(0,n),a=g(t),o=Math.sqrt(t*(t+2*i)),s=o+Math.min(o*.2,r*.01),c=(e+r)*1.2;return a<.5?s:c}_computeVirtualAltitude(e,t){let n=Math.abs(e-t);return Math.max(n,Math.abs(e))}}function x(e,t,n,r){let i=E/n,a=e/t;return a>i?(r.far=e,r.near=a):(r.near=i,r.far=r.near*t),r}const S=7.983,C=16.994,w=2e4,T=100,E=2,D=.001,O=1e-4,k=u(),A=u(),j={near:0,far:0},M=new h,N=p(),P=new f({xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0});export{b as NearFarHeuristicGlobal,v as createNearFarHeuristic,E as minNearDistanceInMeters};
2
+ import{acosClamped as e,lerp as t,smoothstep as n,clamp as r}from"../../../core/mathUtils.js";import{getMetersPerUnitForSR as i}from"../../../core/units.js";import{length as a,normalize as o,scale as s,dot as c,subtract as l,set as u}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as d}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as f}from"../../../geometry/ellipsoidUtils.js";import p from"../../../geometry/Extent.js";import{create as m,fromValues as h}from"../../../geometry/support/ray.js";import{Sphere as g}from"../../../geometry/support/sphere.js";import{computeInnerAltitudeFade as _}from"../webgl-engine/effects/atmosphere/atmosphereUtils.js";import{DepthRange as v}from"../webgl-engine/lib/DepthRange.js";function y(e,t,n){return e===1?new x(t,n):new b(t,n)}class b{constructor(e,t){this._elevationProvider=e,this._referenceEllipsoid=f(t),this._unitInMeters=i(t,this._referenceEllipsoid.metersPerDegree)}compute(e,n,i,a){let{eye:s,center:d}=e,f=this._unitInMeters,p=s[2]*f,m=p-a,h=this._elevationProvider?.visibleElevationRange,g=h?m>=0?p-f*h.minElevation:f*h.maxElevation-p:p,_=n??B,v={x:_.xmax-_.xmin,y:_.ymax-_.ymin,z:4*Math.max(_.xmax-_.xmin,_.ymax-_.ymin)},y=Math.max(v.x,v.y,v.z),b=l(I,d,s),x=u(F,b[0]>0?_.xmax:_.xmin,b[1]>0?_.ymax:_.ymin,b[2]>0?y/2:-y/2);l(x,x,s),o(b,b);let w=c(x,b)*1.1*f,T=Math.abs(m),D=Math.sqrt(T*(T+2*this._referenceEllipsoid.radius)),O=Math.max(_.xmax-_.xmin,_.ymax-_.ymin),k=O*N*f,A=O*P*f,j=r((g-A)/(k-A),0,1)**3,M=Math.min(t(D,w,j),D)*Math.max(Math.log(Math.abs(m)),1);return S(Math.min(M,Math.max(34064e4,y))/f,E,f,L),C(p,a,L)}computeFarDistance(e,t,n){return n}}class x{constructor(e,t){this._elevationProvider=e,this._referenceEllipsoid=f(t)}compute(n,i,u,d){let{eye:f}=n,p=a(f),m=this._referenceEllipsoid.radius,g=p-m,y=this._computeVirtualAltitude(g,d),b=this._elevationProvider?.visibleElevationRange.maxElevation??0,x=_(y),O=this._computeFarDistance(p,y,d),k=(Math.log(y)-w)/(T-w);S(O,r(E-k*(E-D),D,E),1,L);let A=m+b,j=m+this._referenceEllipsoid.atmosphereHeight,N=Math.max(A,j),P=p-N;if(x>0&&P>M){let r=o(F,s(F,n.eye,-1)),i=o(I,n.viewForward),d=e(c(r,i)),f=n.fovY*.5,p=Math.cos(f),m=v.Infinite.near;if(d<=f)m=P*p;else{let e=o(F,n.viewUp),t=s(F,e,Math.tan(f)),r=o(F,l(F,i,t)),c=h(n.eye,r,z);if(R.radius=N,R.intersectRay(c,F)){let e=l(F,F,n.eye);m=a(e)*p}}let g=Math.min(u.near,m)*.99;g<v.Infinite.near&&g>L.near&&(L.near=t(L.near,g,x))}return C(g,d,L)}computeFarDistance(e,t){let n=a(e),r=n-this._referenceEllipsoid.radius,i=this._computeVirtualAltitude(r,t);return this._computeFarDistance(n,i,t)}_computeFarDistance(e,t,n){let r=this._referenceEllipsoid.radius,i=r+Math.min(0,n),a=_(t),o=Math.sqrt(t*(t+2*i)),s=o+Math.min(o*.2,r*.01),c=(e+r)*1.2;return a<.5?s:c}_computeVirtualAltitude(e,t){let n=Math.abs(e-t);return Math.max(n,Math.abs(e))}}function S(e,t,n,r){let i=M/n,a=e/t;return a>i?(r.far=e,r.near=a):(r.near=i,r.far=r.near*t),r}function C(e,r,i){let a=Math.abs(e-r),o=n(A,j,a);return i.near=t(O,L.near,o),i.far=t(k,L.far,o),i}const w=7.983,T=16.994,E=2e4,D=100,O=1,k=4e4,A=1,j=5,M=2,N=.001,P=1e-4,F=d(),I=d(),L={near:0,far:0},R=new g,z=m(),B=new p({xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0});export{x as NearFarHeuristicGlobal,b as NearFarHeuristicLocal,y as createNearFarHeuristic,M as minNearDistanceInMeters};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{createScreenPointArray as e}from"../../../../core/screenUtils.js";import{crossAndNormalize as t,copy as n,scale as r,subtract as i,add as a,distance as o,normalize as s,cross as c,dot as l,scaleAndAdd as u,length as d}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as p}from"../../../../geometry/ellipsoidUtils.js";import{fromValues as m}from"../../../../geometry/support/lineSegment.js";import{create as h,fromPositionAndNormal as g,distance as _,projectPoint as v,projectVector as y,intersectLineSegment as b}from"../../../../geometry/support/plane.js";import{create as x}from"../../../../geometry/support/ray.js";import{Sphere as S}from"../../../../geometry/support/sphere.js";import{fromRenderCamera as ee}from"../../webgl.js";import{getVoxelWasm as C}from"../../layers/VoxelWasm.js";import{pickPointAndInitSphere as w,sphereOrPlanePointFromScreenPoint as T,intersectPlaneFromScreenPoint as E,searchAreaSize as D}from"./navigationUtils.js";import{OffsetCorrectionController as O}from"./OffsetCorrectionController.js";import{fromScreenAtEye as te}from"../../support/geometryUtils/ray.js";import ne from"../../webgl/RenderCamera.js";import{Intersector as re}from"../../webgl-engine/lib/Intersector.js";const k=1.5,A={xSpeedMultiplier:k,ySpeedMultiplier:k,maxElevation:1e4,relativeHorizonPadding:.1,minimumHorizonPadding:12},j=f(),M=f(),N=e(),P=f(),F=h(),I=f(),L=f(),R=f(),z=f(),B=f(),ie=f(),V=f(),H=f(),U=f(),W=f(),G=e(),K=x(),q=new S,J=f(),Y=h(),X=f(),ae=f();function oe(e,t){return y(t,e.viewForward,j),a(M,e.eye,j),e.projectToScreen(M,N),N[1]}function se(e,n,d){let f=e.eye;if(o(n.center,f)<n.radius)return s(B,f),c(ie,B,e.viewRight),a(M,f,ie),e.projectToScreen(M,G),G[1];let p=e.up;te(e,d,K);let m=n.radius;if(t(P,p,K.direction),g(f,P,F),_(F,n.center)>m)return null;v(F,n.center,I);let h=o(n.center,I),y=Math.sqrt(m**2-h**2);i(L,f,I),s(R,L),t(z,P,R);let b=l(L,R),x=l(L,z),S=Math.sqrt(b**2+x**2),ee=Math.sqrt(S**2-y**2),C=y**2/S**2,w=y/S**2*ee,T=C*b,E=w*-x,D=C*x,O=w*b,ne=T+E,re=T-E,k=D+O,A=D-O;return a(V,I,u(V,r(V,R,ne),z,k)),a(H,I,u(H,r(H,R,re),z,A)),i(U,V,f),s(U,U),i(W,H,f),s(W,W),l(e.viewForward,U)>=l(e.viewForward,W)?e.projectToScreen(V,G):e.projectToScreen(H,G),G[1]}function ce(e,t,n=!0){return n?e<t:e<=t}function Z(e,t,n=!0){return n?e>t:e>=t}function le(e,t,n){return t?e>n:e<n}function Q(e,t){let n=e.fullHeight/e.pixelRatio,r=Math.max(t,n-t);return Math.max(A.minimumHorizonPadding,A.relativeHorizonPadding*r)}function ue(e,t){return[de(e,t),fe(e,t)]}function de(e,t){let n=e.fullHeight/e.pixelRatio;return Math.min(n,t+Q(e,t))}function fe(e,t){return Math.max(0,t-Q(e,t))}function pe(e,t,n){let r={translation:e,location:t};return n&&(r.normal=n),r}function me(e){let{view:t}=e;return t.viewingMode===`global`?he(e):ge(e)}function he(e){let{view:t,originalScreenPoint:r,horizonY:i,horizonPadding:a,outTranslation:c,outGrabLocation:l,outGrabNormal:u,intersectionOptions:d,depthSearchSize:f}=e,m=t.state.camera,h=pe(c,l,u);q.radius=p(t.spatialReference).radius;let g=w(t,m,r,q.radius,1,d);if(g.scenePickPoint==null)return!1;let _=g.hasGeometryIntersection;n(J,g.scenePickPoint),n(h.location,J);let v=g.sphere;h.normal&&g.normal&&n(h.normal,g.normal);let y=ve(r,i,a,_),b=_?o(J,m.eye):1/0;return y.wasAdjusted&&ye({view:t,screenAdjustment:y,intersector:$(t),fallbackCheck:(e,t,n)=>{let r=T(v,m,e,t);return r&&n&&s(n,t),r},output:h,intersectionOptions:d}),xe({view:t,screenPoint:y.adjustedScreenPoint,camera:m,initialDistance:b,depthSearchSize:f??D,output:h}),!0}function ge(e){let{view:t,originalScreenPoint:r,horizonY:i,horizonPadding:a,outTranslation:c,outGrabLocation:l,outGrabNormal:d,intersectionOptions:f,depthSearchSize:p}=e,m=t.sceneIntersectionHelper,h=t.state.camera,_=$(t),v=pe(c,l,d);m.intersectIntersectorScreen(r,_,f);let y=_.results.min.getIntersectionPoint(J),b=y?o(J,h.eye):1/0;y&&(n(v.location,J),v.normal&&n(v.normal,_.results.min.normal)),t.renderCoordsHelper.worldUpAtPosition(h.eye,B),u(X,h.eye,B,-h.relativeElevation),g(X,B,Y);let x=ve(r,i,a,y);return x.wasAdjusted&&ye({view:t,screenAdjustment:x,intersector:_,fallbackCheck:(e,t,n)=>{let r=E(Y,h,e,t);return r&&n&&s(n,B),r},output:v,intersectionOptions:f}),xe({view:t,screenPoint:x.adjustedScreenPoint,camera:h,initialDistance:b,depthSearchSize:p??D,output:v}),!0}function _e(e,t,n,r){return!r&&ce(e,t)||r&&le(e,!1,n[0])?n[0]:!r&&Z(e,t,!1)?n[1]:null}function ve(t,n,r,i){let a=_e(t[1],n,r,i);return{originalScreenPoint:t,adjustedScreenPoint:e(t[0],a??t[1]),horizonY:n,horizonPadding:r,wasAdjusted:a!==null}}function $(e){let t=new re(e.state.viewingMode);return t.options.selectionMode=!0,t.options.store=0,t.options.hud=!1,t.options.normalRequired=!0,t}function ye(e){let{view:t,screenAdjustment:r,fallbackCheck:i,intersector:a,output:o,intersectionOptions:s}=e,c=t.sceneIntersectionHelper;c.intersectIntersectorScreen(r.adjustedScreenPoint,a,{...s,requiresGroundFeedback:!0});let l=a.results.min.getIntersectionPoint(o.location);if(l){o.normal&&n(o.normal,a.results.min.normal);return}let u=be(r);c.intersectIntersectorScreen(u,a,{...s,requiresGroundFeedback:!0}),l=a.results.min.getIntersectionPoint(o.location),l?o.normal&&n(o.normal,a.results.min.normal):(l=i(r.adjustedScreenPoint,o.location,o.normal),l||i(u,o.location,o.normal))}function be(t){let{originalScreenPoint:n,adjustedScreenPoint:r,horizonY:i,horizonPadding:a}=t,o=Z(r[1],i)?Math.min(a[1],n[1]):Math.max(a[0],n[1]);return e(r[0],o)}function xe(e){Se(e),Ce(e)}function Se(e){let{view:t,camera:r,output:a}=e,{offset:o}=t.navigation.mode;if(!o)return;let{translation:s,location:c}=a;t.renderCoordsHelper.worldUpAtPosition(r.eye,B),u(X,r.eye,B,-o),g(X,B,F),b(F,m(r.eye,i(j,c,r.eye)),X)&&(n(c,X),i(s,c,r.eye))}function Ce(e){let{view:t,screenPoint:n,camera:o,initialDistance:c,depthSearchSize:l,output:u}=e,f=l>0?t.stage.renderView.getMinimalDepthForArea(C(t),n[0],n[1],o,l):null;i(u.translation,u.location,o.eye);let p=Math.min(d(u.translation),c);f&&f<=p&&(p=f),s(u.translation,u.translation),r(u.translation,u.translation,p),a(u.location,u.translation,o.eye)}async function we(e,t,n,r,i){let a=new ne().copyFrom(e.state.camera);if(Te({view:e,camera:a,forwardDirection:t,forwardDistance:n,detectCollisions:!0}))return r?r.smoothlyCorrectGroundElevation({camera:a,deltaTime:i}):new O(e).immediatelyCorrectGroundElevation({camera:a,correctionLimit:100}),e.goTo(ee(e,a),{duration:500,liftOffDisabled:!0})}function Te(e){let{view:s,camera:c,forwardDirection:l,forwardDistance:u,detectCollisions:f}=e,p=s.navigation.mode;if(p.type!==`ground`)return!1;s.renderCoordsHelper.worldUpAtPosition(c.eye,B);let m=s.sceneIntersectionHelper,h=$(s),g=t(j,B,t(j,l,B));n(K.origin,c.eye),r(K.direction,g,u);let _=m.intersectRay(K,h,J,{include:p.include,exclude:p.exclude}),v=i(ae,c.center,c.eye);return!f||!_||o(J,c.eye)>Math.abs(u)?c.eye=a(j,K.origin,K.direction):(i(j,J,c.eye),d(j)>2&&(Ee(j,j,.25,2),c.eye=a(j,c.eye,j))),c.center=a(j,c.eye,v),!0}function Ee(e,t,n,i){let a=d(e),o=Math.min(n,Math.max(a-i,0)/a);r(t,e,o)}export{Te as advanceGroundNavigationCamera,Q as computeHorizonPadding,ue as computeHorizonPaddingLimits,me as findGroundNavigationGrabLocation,oe as findPlaneHorizonY,se as findSphereHorizonY,we as groundNavigationAdvance,A as groundNavigationConstants,ce as isAboveHorizon,Z as isBelowHorizon,Ee as shortenTranslation,le as shouldClampScreenY};
2
+ import{createScreenPointArray as e}from"../../../../core/screenUtils.js";import{crossAndNormalize as t,copy as n,scale as r,subtract as i,add as a,distance as o,normalize as s,cross as c,dot as l,scaleAndAdd as u,length as d}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as p}from"../../../../geometry/ellipsoidUtils.js";import{fromValues as m}from"../../../../geometry/support/lineSegment.js";import{create as h,fromPositionAndNormal as g,distance as _,projectPoint as v,projectVector as y,intersectLineSegment as b}from"../../../../geometry/support/plane.js";import{create as x}from"../../../../geometry/support/ray.js";import{Sphere as S}from"../../../../geometry/support/sphere.js";import{fromRenderCamera as ee}from"../../webgl.js";import{getVoxelWasm as C}from"../../layers/VoxelWasm.js";import{pickPointAndInitSphere as w,sphereOrPlanePointFromScreenPoint as T,intersectPlaneFromScreenPoint as E,searchAreaSize as D}from"./navigationUtils.js";import{OffsetCorrectionController as O}from"./OffsetCorrectionController.js";import{fromScreenAtEye as te}from"../../support/geometryUtils/ray.js";import ne from"../../webgl/RenderCamera.js";import{Intersector as re}from"../../webgl-engine/lib/Intersector.js";const k=1.5,A={xSpeedMultiplier:k,ySpeedMultiplier:k,maxElevation:1e4,relativeHorizonPadding:.1,minimumHorizonPadding:12,i3sNodeDownwardCheckDistanceInMeters:5},j=f(),M=f(),N=e(),P=f(),F=h(),I=f(),L=f(),R=f(),z=f(),B=f(),ie=f(),V=f(),H=f(),U=f(),W=f(),G=e(),K=x(),q=new S,J=f(),Y=h(),X=f(),ae=f();function oe(e,t){return y(t,e.viewForward,j),a(M,e.eye,j),e.projectToScreen(M,N),N[1]}function se(e,n,d){let f=e.eye;if(o(n.center,f)<n.radius)return s(B,f),c(ie,B,e.viewRight),a(M,f,ie),e.projectToScreen(M,G),G[1];let p=e.up;te(e,d,K);let m=n.radius;if(t(P,p,K.direction),g(f,P,F),_(F,n.center)>m)return null;v(F,n.center,I);let h=o(n.center,I),y=Math.sqrt(m**2-h**2);i(L,f,I),s(R,L),t(z,P,R);let b=l(L,R),x=l(L,z),S=Math.sqrt(b**2+x**2),ee=Math.sqrt(S**2-y**2),C=y**2/S**2,w=y/S**2*ee,T=C*b,E=w*-x,D=C*x,O=w*b,ne=T+E,re=T-E,k=D+O,A=D-O;return a(V,I,u(V,r(V,R,ne),z,k)),a(H,I,u(H,r(H,R,re),z,A)),i(U,V,f),s(U,U),i(W,H,f),s(W,W),l(e.viewForward,U)>=l(e.viewForward,W)?e.projectToScreen(V,G):e.projectToScreen(H,G),G[1]}function ce(e,t,n=!0){return n?e<t:e<=t}function Z(e,t,n=!0){return n?e>t:e>=t}function le(e,t,n){return t?e>n:e<n}function Q(e,t){let n=e.fullHeight/e.pixelRatio,r=Math.max(t,n-t);return Math.max(A.minimumHorizonPadding,A.relativeHorizonPadding*r)}function ue(e,t){return[de(e,t),fe(e,t)]}function de(e,t){let n=e.fullHeight/e.pixelRatio;return Math.min(n,t+Q(e,t))}function fe(e,t){return Math.max(0,t-Q(e,t))}function pe(e,t,n){let r={translation:e,location:t};return n&&(r.normal=n),r}function me(e){let{view:t}=e;return t.viewingMode===`global`?he(e):ge(e)}function he(e){let{view:t,originalScreenPoint:r,horizonY:i,horizonPadding:a,outTranslation:c,outGrabLocation:l,outGrabNormal:u,intersectionOptions:d,depthSearchSize:f}=e,m=t.state.camera,h=pe(c,l,u);q.radius=p(t.spatialReference).radius;let g=w(t,m,r,q.radius,1,d);if(g.scenePickPoint==null)return!1;let _=g.hasGeometryIntersection;n(J,g.scenePickPoint),n(h.location,J);let v=g.sphere;h.normal&&g.normal&&n(h.normal,g.normal);let y=ve(r,i,a,_),b=_?o(J,m.eye):1/0;return y.wasAdjusted&&ye({view:t,screenAdjustment:y,intersector:$(t),fallbackCheck:(e,t,n)=>{let r=T(v,m,e,t);return r&&n&&s(n,t),r},output:h,intersectionOptions:d}),xe({view:t,screenPoint:y.adjustedScreenPoint,camera:m,initialDistance:b,depthSearchSize:f??D,output:h}),!0}function ge(e){let{view:t,originalScreenPoint:r,horizonY:i,horizonPadding:a,outTranslation:c,outGrabLocation:l,outGrabNormal:d,intersectionOptions:f,depthSearchSize:p}=e,m=t.sceneIntersectionHelper,h=t.state.camera,_=$(t),v=pe(c,l,d);m.intersectIntersectorScreen(r,_,f);let y=_.results.min.getIntersectionPoint(J),b=y?o(J,h.eye):1/0;y&&(n(v.location,J),v.normal&&n(v.normal,_.results.min.normal)),t.renderCoordsHelper.worldUpAtPosition(h.eye,B),u(X,h.eye,B,-h.relativeElevation),g(X,B,Y);let x=ve(r,i,a,y);return x.wasAdjusted&&ye({view:t,screenAdjustment:x,intersector:_,fallbackCheck:(e,t,n)=>{let r=E(Y,h,e,t);return r&&n&&s(n,B),r},output:v,intersectionOptions:f}),xe({view:t,screenPoint:x.adjustedScreenPoint,camera:h,initialDistance:b,depthSearchSize:p??D,output:v}),!0}function _e(e,t,n,r){return!r&&ce(e,t)||r&&le(e,!1,n[0])?n[0]:!r&&Z(e,t,!1)?n[1]:null}function ve(t,n,r,i){let a=_e(t[1],n,r,i);return{originalScreenPoint:t,adjustedScreenPoint:e(t[0],a??t[1]),horizonY:n,horizonPadding:r,wasAdjusted:a!==null}}function $(e){let t=new re(e.state.viewingMode);return t.options.selectionMode=!0,t.options.store=0,t.options.hud=!1,t.options.normalRequired=!0,t}function ye(e){let{view:t,screenAdjustment:r,fallbackCheck:i,intersector:a,output:o,intersectionOptions:s}=e,c=t.sceneIntersectionHelper;c.intersectIntersectorScreen(r.adjustedScreenPoint,a,{...s,requiresGroundFeedback:!0});let l=a.results.min.getIntersectionPoint(o.location);if(l){o.normal&&n(o.normal,a.results.min.normal);return}let u=be(r);c.intersectIntersectorScreen(u,a,{...s,requiresGroundFeedback:!0}),l=a.results.min.getIntersectionPoint(o.location),l?o.normal&&n(o.normal,a.results.min.normal):(l=i(r.adjustedScreenPoint,o.location,o.normal),l||i(u,o.location,o.normal))}function be(t){let{originalScreenPoint:n,adjustedScreenPoint:r,horizonY:i,horizonPadding:a}=t,o=Z(r[1],i)?Math.min(a[1],n[1]):Math.max(a[0],n[1]);return e(r[0],o)}function xe(e){Se(e),Ce(e)}function Se(e){let{view:t,camera:r,output:a}=e,{offset:o}=t.navigation.mode;if(!o)return;let{translation:s,location:c}=a;t.renderCoordsHelper.worldUpAtPosition(r.eye,B),u(X,r.eye,B,-o),g(X,B,F),b(F,m(r.eye,i(j,c,r.eye)),X)&&(n(c,X),i(s,c,r.eye))}function Ce(e){let{view:t,screenPoint:n,camera:o,initialDistance:c,depthSearchSize:l,output:u}=e,f=l>0?t.stage.renderView.getMinimalDepthForArea(C(t),n[0],n[1],o,l):null;i(u.translation,u.location,o.eye);let p=Math.min(d(u.translation),c);f&&f<=p&&(p=f),s(u.translation,u.translation),r(u.translation,u.translation,p),a(u.location,u.translation,o.eye)}async function we(e,t,n,r,i){let a=new ne().copyFrom(e.state.camera);if(Te({view:e,camera:a,forwardDirection:t,forwardDistance:n,detectCollisions:!0}))return r?r.smoothlyCorrectGroundElevation({camera:a,deltaTime:i}):new O(e).immediatelyCorrectGroundElevation({camera:a,correctionLimit:100}),e.goTo(ee(e,a),{duration:500,liftOffDisabled:!0})}function Te(e){let{view:s,camera:c,forwardDirection:l,forwardDistance:u,detectCollisions:f}=e,p=s.navigation.mode;if(p.type!==`ground`)return!1;s.renderCoordsHelper.worldUpAtPosition(c.eye,B);let m=s.sceneIntersectionHelper,h=$(s),g=t(j,B,t(j,l,B));n(K.origin,c.eye),r(K.direction,g,u);let _=m.intersectRay(K,h,J,{include:p.include,exclude:p.exclude}),v=i(ae,c.center,c.eye);return!f||!_||o(J,c.eye)>Math.abs(u)?c.eye=a(j,K.origin,K.direction):(i(j,J,c.eye),d(j)>2&&(Ee(j,j,.25,2),c.eye=a(j,c.eye,j))),c.center=a(j,c.eye,v),!0}function Ee(e,t,n,i){let a=d(e),o=Math.min(n,Math.max(a-i,0)/a);r(t,e,o)}export{Te as advanceGroundNavigationCamera,Q as computeHorizonPadding,ue as computeHorizonPaddingLimits,me as findGroundNavigationGrabLocation,oe as findPlaneHorizonY,se as findSphereHorizonY,we as groundNavigationAdvance,A as groundNavigationConstants,ce as isAboveHorizon,Z as isBelowHorizon,Ee as shortenTranslation,le as shouldClampScreenY};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{signal as e}from"../../../../core/signal.js";import{Milliseconds as t}from"../../../../core/time.js";import{getGaussianSplatAlphaCutoffValue as n}from"../../webgl-engine/shaders/GaussianSplatTechniqueConfiguration.js";class r{static{this.fadeInEase=e=>e*(2-e)}static{this.fadeOutEase=e=>e*e}static{this.inverseFadeInEase=e=>1-Math.sqrt(1-e)}static{this.inverseFadeOutEase=e=>Math.sqrt(1-e)}static{this.minimumFadeDuration=t(80)}static{this.resetFadeDurationInterval=t(1e3)}constructor(n){this._view=n,this._numFadingTiles=e(0),this._tmpFullyFadedOutTiles=[],this._visibilityUpdatePending=!1,this._previousNumFadingTiles=0,this._lastStoppedFading=t(0),this._currentFadeDuration=this.baseFadeDuration}get numFadingTiles(){return this._numFadingTiles.value}updateForFrame(e){if(e!==this._lastUpdatedFrameStart){if(this._lastUpdatedFrameStart=e,this.numFadingTiles===0)this._previousFrameStart=null;else{let n=t(this._previousFrameStart==null?0:e-this._previousFrameStart);this.updateAllTileFading(n),this._previousFrameStart=e}this._view.updateFadingTexture()}}fadeTile(e,t,n){let r=this._getTargetOpacity(t);if(e.fadeDirection=t,!this.fadingEnabled){this._instantTileFading(e,r);return}let i=e.opacityModifier;if(i!==r){let r=this._getFadeProgressFromOpacity(i,t);this._startTileFading(e,r,n)}else this._stopTileFading(e)}updateAllTileFading(e){let t=this._tmpFullyFadedOutTiles;t.length=0,this._view.tileHandles.forEach(n=>{this._updateTileFading(n,e)&&t.push(n)}),t.length>0&&(this._view.notifyTileObbsChanged(t),this._visibilityUpdatePending=!0),this._numFadingTiles.value===0&&this._visibilityUpdatePending&&(this._visibilityUpdatePending=!1,this._view.updateGaussians()),this._numFadingTiles.value>0&&this._view.view.stage?.renderView.requestRender(2)}onFadeDurationChanged(e){e===0&&this.numFadingTiles>0&&this._instantlyFullyFadeAllTiles()}isTileFadingOut(e){return e.fadeProgress!=null&&e.fadeDirection===1}onTileDiscarded(e){e.fadeProgress!=null&&(this._numFadingTiles.value--,this._numFadingTiles.value===0&&(this._lastStoppedFading=t(performance.now())))}updateFadeDuration(){if(this.numFadingTiles&&this.numFadingTiles>=this._previousNumFadingTiles){let e=this._currentFadeDuration*.95;this._currentFadeDuration=t(Math.max(e,r.minimumFadeDuration))}else this.numFadingTiles===0&&performance.now()-this._lastStoppedFading>r.resetFadeDurationInterval&&(this._currentFadeDuration=this.baseFadeDuration);return this._previousNumFadingTiles=this.numFadingTiles,this._currentFadeDuration}get updating(){return this._numFadingTiles.value>0}get baseFadeDuration(){return this._view.view.qualitySettings.fadeDuration}get fadingEnabled(){return this.baseFadeDuration!==0}_startTileFading(e,t,n){e.fadeProgress??this._numFadingTiles.value++,e.fadeDuration=n,e.fadeProgress=t}_stopTileFading(e){e.fadeProgress!=null&&(e.fadeDirection===1&&this._onTileFullyFadedOut(e),this._numFadingTiles.value--,this._numFadingTiles.value===0&&(this._lastStoppedFading=t(performance.now())),e.fadeDuration=null,e.fadeProgress=null)}_updateTileFading(e,t){let{fadeProgress:n,fadeDirection:i}=e;if(n==null)return!1;let a=this._fadeDirectionToSign(i),o=e.fadeDuration,s=this._getTargetOpacity(i),c=t/Math.abs(o||1),l=Math.min(n+c,1),u=s-a*(1-(i===0?r.fadeInEase:r.fadeOutEase)(l)),d=l===1||this._tileReachedFadeOutCutoff(e,u);if(e.opacityModifier=d?s:u,d){let t=i===1;return this._stopTileFading(e),this._updateOpacityModifier(e),t}return e.fadeProgress=l,this._updateOpacityModifier(e),!1}_updateOpacityModifier(e){for(let t=0;t<e.pageIds.length;t++){let n=e.pageIds[t];this._view.data.fadingTexture.updateBuffer(e.opacityModifier,n)}}_tileReachedFadeOutCutoff(e,t){if(e.fadeDirection!==1)return!1;let r=n(this._view.view.qualitySettings.gaussianSplat.minimumOpacity);return t*e.maxGaussianOpacity<=r}_instantTileFading(e,t){e.fadeDuration=null,e.fadeProgress=null,e.opacityModifier=t,this._updateOpacityModifier(e),e.fadeDirection===1&&this._onTileFullyFadedOut(e)}_instantlyFullyFadeAllTiles(){let e=this._tmpFullyFadedOutTiles;e.length=0,this._view.tileHandles.forEach(t=>{if(t.fadeProgress!=null){let n=t.fadeDirection===1;this._instantTileFading(t,this._getTargetOpacity(t.fadeDirection)),n&&e.push(t)}});let t=e.length>0;t&&(this._visibilityUpdatePending=!0),this._numFadingTiles.value=0,this._visibilityUpdatePending&&(this._visibilityUpdatePending=!1,this._view.updateGaussians()),t&&this._view.notifyTileObbsChanged(e)}_onTileFullyFadedOut(e){e.lifecycleState=0,this._view.moveTileToCache(e)}_fadeDirectionToSign(e){return e===0?1:-1}_getTargetOpacity(e){return+(e===0)}_getFadeProgressFromOpacity(e,t){let n=Math.max(0,Math.min(e,1));return t===0?r.inverseFadeInEase(n):r.inverseFadeOutEase(n)}}export{r as GaussianSplatFadeHelper};
2
+ import{signal as e}from"../../../../core/signal.js";import{Milliseconds as t}from"../../../../core/time.js";import{getGaussianSplatAlphaCutoffValue as n}from"../../webgl-engine/shaders/GaussianSplatTechniqueConfiguration.js";class r{static{this.fadeInEase=e=>e*(2-e)}static{this.fadeOutEase=e=>e*e}static{this.inverseFadeInEase=e=>1-Math.sqrt(1-e)}static{this.inverseFadeOutEase=e=>Math.sqrt(1-e)}static{this.minimumFadeDuration=t(80)}static{this.resetFadeDurationInterval=t(1e3)}constructor(n){this._view=n,this._numFadingTiles=e(0),this._tmpFullyFadedOutTiles=[],this._visibilityUpdatePending=!1,this._previousNumFadingTiles=0,this._lastStoppedFading=t(0),this._currentFadeDuration=this.baseFadeDuration}get numFadingTiles(){return this._numFadingTiles.value}updateForFrame(e){if(e!==this._lastUpdatedFrameStart){if(this._lastUpdatedFrameStart=e,this.numFadingTiles===0)this._previousFrameStart=null;else{let n=t(this._previousFrameStart==null?0:e-this._previousFrameStart);this.updateAllTileFading(n),this._previousFrameStart=e}this._view.updateFadingTexture()}}fadeTile(e,t,n){let r=this._getTargetOpacity(t);if(e.fadeDirection=t,!this.fadingEnabled){this._instantTileFading(e,r);return}let i=e.opacityModifier;if(i!==r){let r=this._getFadeProgressFromOpacity(i,t);this._startTileFading(e,r,n)}else this._stopTileFading(e)}updateAllTileFading(e){let t=this._tmpFullyFadedOutTiles;t.length=0,this._view.tileHandles.forEach(n=>{this._updateTileFading(n,e)&&t.push(n)}),t.length>0&&(this._view.notifyTileObbsChanged(t),this._visibilityUpdatePending=!0),this._numFadingTiles.value===0&&this._visibilityUpdatePending&&(this._visibilityUpdatePending=!1,this._view.updateActiveTileVisibility()),this._numFadingTiles.value>0&&this._view.view.stage?.renderView.requestRender(2)}onFadeDurationChanged(e){e===0&&this.numFadingTiles>0&&this._instantlyFullyFadeAllTiles()}isTileFadingOut(e){return e.fadeProgress!=null&&e.fadeDirection===1}onTileDiscarded(e){e.fadeProgress!=null&&(this._numFadingTiles.value--,this._numFadingTiles.value===0&&(this._lastStoppedFading=t(performance.now())))}updateFadeDuration(){if(this.numFadingTiles&&this.numFadingTiles>=this._previousNumFadingTiles){let e=this._currentFadeDuration*.95;this._currentFadeDuration=t(Math.max(e,r.minimumFadeDuration))}else this.numFadingTiles===0&&performance.now()-this._lastStoppedFading>r.resetFadeDurationInterval&&(this._currentFadeDuration=this.baseFadeDuration);return this._previousNumFadingTiles=this.numFadingTiles,this._currentFadeDuration}get updating(){return this._numFadingTiles.value>0}get baseFadeDuration(){return this._view.view.qualitySettings.fadeDuration}get fadingEnabled(){return this.baseFadeDuration!==0}_startTileFading(e,t,n){e.fadeProgress??this._numFadingTiles.value++,e.fadeDuration=n,e.fadeProgress=t}_stopTileFading(e){e.fadeProgress!=null&&(e.fadeDirection===1&&this._onTileFullyFadedOut(e),this._numFadingTiles.value--,this._numFadingTiles.value===0&&(this._lastStoppedFading=t(performance.now())),e.fadeDuration=null,e.fadeProgress=null)}_updateTileFading(e,t){let{fadeProgress:n,fadeDirection:i}=e;if(n==null)return!1;let a=this._fadeDirectionToSign(i),o=e.fadeDuration,s=this._getTargetOpacity(i),c=t/Math.abs(o||1),l=Math.min(n+c,1),u=s-a*(1-(i===0?r.fadeInEase:r.fadeOutEase)(l)),d=l===1||this._tileReachedFadeOutCutoff(e,u);if(e.opacityModifier=d?s:u,d){let t=i===1;return this._stopTileFading(e),this._updateOpacityModifier(e),t}return e.fadeProgress=l,this._updateOpacityModifier(e),!1}_updateOpacityModifier(e){for(let t=0;t<e.pageIds.length;t++){let n=e.pageIds[t];this._view.data.fadingTexture.updateBuffer(e.opacityModifier,n)}}_tileReachedFadeOutCutoff(e,t){if(e.fadeDirection!==1)return!1;let r=n(this._view.view.qualitySettings.gaussianSplat.minimumOpacity);return t*e.maxGaussianOpacity<=r}_instantTileFading(e,t){e.fadeDuration=null,e.fadeProgress=null,e.opacityModifier=t,this._updateOpacityModifier(e),e.fadeDirection===1&&this._onTileFullyFadedOut(e)}_instantlyFullyFadeAllTiles(){let e=this._tmpFullyFadedOutTiles;e.length=0,this._view.tileHandles.forEach(t=>{if(t.fadeProgress!=null){let n=t.fadeDirection===1;this._instantTileFading(t,this._getTargetOpacity(t.fadeDirection)),n&&e.push(t)}});let t=e.length>0;t&&(this._visibilityUpdatePending=!0),this._numFadingTiles.value=0,this._visibilityUpdatePending&&(this._visibilityUpdatePending=!1,this._view.updateActiveTileVisibility()),t&&this._view.notifyTileObbsChanged(e)}_onTileFullyFadedOut(e){e.lifecycleState=0,this._view.moveTileToCache(e)}_fadeDirectionToSign(e){return e===0?1:-1}_getTargetOpacity(e){return+(e===0)}_getFadeProgressFromOpacity(e,t){let n=Math.max(0,Math.min(e,1));return t===0?r.inverseFadeInEase(n):r.inverseFadeOutEase(n)}}export{r as GaussianSplatFadeHelper};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{subtract as e,length as t,scale as n,negate as r,dot as i,transformQuatValues as a}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as s}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{project as c}from"../../../../geometry/projectionUtils.js";import{intersects as l,contains as u}from"../../../../geometry/support/aaBoundingBox.js";import{fromExtent as d}from"../../../../geometry/support/aaBoundingRect.js";import{create as f}from"../../../../geometry/support/plane.js";import{fromPoints as p}from"../../../../geometry/support/ray.js";import{GaussianSplatTarget as m}from"../../layers/i3s/Intersector.js";import{createTileBVH as h}from"../../layers/support/Tiles3DBVH.js";import{ElevationRange as g}from"../ElevationRange.js";import{IntersectorResultRay as _}from"../../webgl-engine/lib/IntersectorResult.js";class v{constructor(e){this.layerView=e,this.type=0,this.slicePlaneEnabled=!1,this.isGround=!1,this._ellipsoidLocalRayOrigin=o(),this._ellipsoidLocalRayDir=o(),this.intersectionNormal=o(),this.intersectionRayDir=o(),this.intersectionPlane=f(),this.layerViewUid=e.uid;let t=e.view.viewingMode,n=(e.useEsriCrs?e.fullExtentInLocalViewSpatialReference:e.layer.fullExtent?c(e.layer.fullExtent,e.view.renderSpatialReference):void 0)??e.view.extent,r=d(n);this._bvh=h(t,r)}destroy(){this._bvh.destroy()}addTile(e){this._bvh.addTile(e)}removeTile(e){this._bvh.removeTile(e)}intersectRay(a,c,d,f,h,g){let{intersectionRayDir:v,intersectionPlane:x,layerViewUid:S,intersectionNormal:C}=this,w=p(d,f);e(v,f,d);let T=1/t(v);n(v,v,T),r(C,v),s(x,v[0],v[1],v[2],-i(v,d));let E=new b,D=new b,O=a.options.store,k=O===0,A=O===2,j=O===1||A,M=A?[]:null,N=(e,t,n,r,i,a,s,c)=>{let l=e.point??=o();l[0]=n,l[1]=r,l[2]=i,e.dist=t,e.normal=C;let u=e.outwardDirection??=o(),d=a*a+s*s+c*c;if(d>0){let e=1/Math.sqrt(d);u[0]=a*e,u[1]=s*e,u[2]=c*e}else u[0]=C[0],u[1]=C[1],u[2]=C[2];return e.layerViewUid=S,e},P=d[0],F=d[1],I=d[2],L=v[0],R=v[1],z=v[2],B=this.layerView.clippingBox,V=e=>{let{relativePositions:t,packedRotations:n,packedOpacityScaledScales:r,gaussianCount:i,obb:a,maxSplatMbsRadiusSquared:o}=e,s=a.centerX,l=a.centerY,u=a.centerZ,p=-1,m=B[0],h=B[1],g=B[2],_=B[3],v=B[4],y=B[5];for(let e=0,a=0;e<i;e++,a+=3){let i=t[a]+s,x=t[a+1]+l,S=t[a+2]+u;if(i<m||x<h||S<g||i>_||x>v||S>y)continue;let C=i-P,w=x-F,O=S-I,B=C*L+w*R+O*z;if(B<0&&B*B>o)continue;let V=B<0?0:B;if(C*C+w*w+O*O-V*V>o||k&&E.dist!=null&&(p<0&&(p=Math.sqrt(o)),Math.max(B-p,0)*T>=E.dist))continue;let H=this._intersectGaussianEllipsoid(C,w,O,L,R,z,n[e],r[e]);if(H<0)continue;let U=H*T;if(c!=null&&!c(d,f,U))continue;let W=E.dist==null||U<E.dist,G=j&&(D.dist==null||U>D.dist);if(!W&&!G&&!A)continue;let K=L*H,q=R*H,ee=z*H,J=P+K,Y=F+q,X=I+ee,Z=K-C,Q=q-w,$=ee-O;if(W&&N(E,U,J,Y,X,Z,Q,$),G&&N(D,U,J,Y,X,Z,Q,$),A){let e=new b;M.push(N(e,U,J,Y,X,Z,Q,$))}}},H=e=>{let{relativePositions:t,packedRotations:n,packedOpacityScaledScales:r,gaussianCount:i,obb:a,maxSplatMbsRadiusSquared:o}=e,s=a.centerX,l=a.centerY,u=a.centerZ,p=-1,m=P-s,h=F-l,g=I-u;for(let e=0,a=0;e<i;e++,a+=3){let i=t[a]-m,s=t[a+1]-h,l=t[a+2]-g,u=i*L+s*R+l*z;if(u<0&&u*u>o)continue;let _=u<0?0:u;if(i*i+s*s+l*l-_*_>o||k&&E.dist!=null&&(p<0&&(p=Math.sqrt(o)),Math.max(u-p,0)*T>=E.dist))continue;let v=this._intersectGaussianEllipsoid(i,s,l,L,R,z,n[e],r[e]);if(v<0)continue;let y=v*T;if(c!=null&&!c(d,f,y))continue;let x=E.dist==null||y<E.dist,S=j&&(D.dist==null||y>D.dist);if(!x&&!S&&!A)continue;let C=L*v,w=R*v,O=z*v,B=P+C,V=F+w,H=I+O,U=C-i,W=w-s,G=O-l;if(x&&N(E,y,B,V,H,U,W,G),S&&N(D,y,B,V,H,U,W,G),A){let e=new b;M.push(N(e,y,B,V,H,U,W,G))}}},U=(e,t)=>{let{min:n,max:r}=e.obb.signedDistanceRangePlane(x);if(r<0)return;let i=n*T;if(!(k&&E.dist!=null&&E.dist<i)){if(E.dist!=null&&D.dist!=null){let e=r*T;if(E.dist<i&&D.dist>e)return}t?V(e):H(e)}};this._bvh.forEachTileIntersectingRay(d,f,B==null?e=>{U(e,!1)}:e=>{let t=e.boundingBox;l(t,B)&&U(e,!u(B,t))},g);let W=(e,t)=>{let{layerViewUid:n}=t,r=new m(t.point,t.outwardDirection,n);e.set(0,r,t.dist,t.dist,t.normal)};if(y(E)){let e=a.results.min;(e.distance==null||E.dist<e.distance)&&W(e,E)}if(y(D)&&j){let e=a.results.max;(e.distance==null||D.dist>e.distance)&&W(e,D)}if(A&&M?.length)for(let e of M){let t=new _(w);W(t,e),a.results.all.push(t)}}_intersectGaussianEllipsoid(e,t,n,r,i,o,s,c){let l=s>>>30,u=s&1023,d=s>>>10&1023,f=s>>>20&1023,p=(u&x)*S*(1-(u>>>9&1)*2),m=(d&x)*S*(1-(d>>>9&1)*2),h=(f&x)*S*(1-(f>>>9&1)*2),g,_,v,y,b=p*p+m*m+h*h,T=Math.sqrt(Math.max(0,1-b));switch(l){case 0:g=T,_=h,v=m,y=p;break;case 1:g=h,_=T,v=m,y=p;break;case 2:g=h,_=m,v=T,y=p;break;default:g=h,_=m,v=p,y=T}let E=this._ellipsoidLocalRayOrigin;E[0]=-e,E[1]=-t,E[2]=-n,a(E,E,-g,-_,-v,y);let D=this._ellipsoidLocalRayDir;D[0]=r,D[1]=i,D[2]=o,a(D,D,-g,-_,-v,y);let O=w[c&255],k=w[c>>>8&255],A=w[c>>>16],j=E[0]*O,M=E[1]*k,N=E[2]*A,P=j*j+M*M+N*N;if(P<=1)return 0;let F=D[0]*O,I=D[1]*k,L=D[2]*A,R=F*F+I*I+L*L,z=j*F+M*I+N*L;if(z>0)return C;let B=z*z-R*(P-1);return B<0?C:(-z-Math.sqrt(B))/R}getElevationRange(e){return this._bvh.getElevationRangeIntersectingSphere(e)??new g(0,0)}}function y(e){return e.dist!=null&&e.point!=null}class b{constructor(){this.point=null,this.dist=null,this.normal=null,this.outwardDirection=null,this.layerViewUid=``}}const x=511,S=Math.SQRT1_2/511,C=-1,w=(()=>{let e=new Float64Array(256);for(let t=0;t<e.length;t++)e[t]=Math.exp(10-t/16)/3;return e})();export{v as GaussianSplatIntersectionHandler};
2
+ import{subtract as e,length as t,scale as n,negate as r,dot as i,transformQuatValues as a}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as s}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{project as c}from"../../../../geometry/projectionUtils.js";import{intersects as l,contains as u}from"../../../../geometry/support/aaBoundingBox.js";import{fromExtent as d}from"../../../../geometry/support/aaBoundingRect.js";import{create as f}from"../../../../geometry/support/plane.js";import{fromPoints as p}from"../../../../geometry/support/ray.js";import{GaussianSplatTarget as m}from"../../layers/i3s/Intersector.js";import{createTileBVH as h}from"../../layers/support/Tiles3DBVH.js";import{ElevationRange as g}from"../ElevationRange.js";import{IntersectorResultRay as _}from"../../webgl-engine/lib/IntersectorResult.js";class v{constructor(e){this.layerView=e,this.type=0,this.slicePlaneEnabled=!1,this.isGround=!1,this._ellipsoidLocalRayOrigin=o(),this._ellipsoidLocalRayDir=o(),this.intersectionNormal=o(),this.intersectionRayDir=o(),this.intersectionPlane=f(),this.layerViewUid=e.uid;let t=e.view.viewingMode,n=(e.useEsriCrs?e.fullExtentInLocalViewSpatialReference:e.layer.fullExtent?c(e.layer.fullExtent,e.view.renderSpatialReference):void 0)??e.view.extent,r=d(n);this._bvh=h(t,r)}destroy(){this._bvh.destroy()}addTile(e){this._bvh.addTile(e)}removeTile(e){this._bvh.removeTile(e)}get elevationRange(){let e=this._bvh.elevationRange;return e!=null&&!e.isEmpty?new g(e.minElevation,e.maxElevation):null}intersectRay(a,c,d,f,h,g){let{intersectionRayDir:v,intersectionPlane:x,layerViewUid:S,intersectionNormal:C}=this,w=p(d,f);e(v,f,d);let T=1/t(v);n(v,v,T),r(C,v),s(x,v[0],v[1],v[2],-i(v,d));let E=new b,D=new b,O=a.options.store,k=O===0,A=O===2,j=O===1||A,M=A?[]:null,N=(e,t,n,r,i,a,s,c)=>{let l=e.point??=o();l[0]=n,l[1]=r,l[2]=i,e.dist=t,e.normal=C;let u=e.outwardDirection??=o(),d=a*a+s*s+c*c;if(d>0){let e=1/Math.sqrt(d);u[0]=a*e,u[1]=s*e,u[2]=c*e}else u[0]=C[0],u[1]=C[1],u[2]=C[2];return e.layerViewUid=S,e},P=d[0],F=d[1],I=d[2],L=v[0],R=v[1],z=v[2],B=this.layerView.clippingBox,V=e=>{let{relativePositions:t,packedRotations:n,packedOpacityScaledScales:r,gaussianCount:i,obb:a,maxSplatMbsRadiusSquared:o}=e,s=a.centerX,l=a.centerY,u=a.centerZ,p=-1,m=B[0],h=B[1],g=B[2],_=B[3],v=B[4],y=B[5];for(let e=0,a=0;e<i;e++,a+=3){let i=t[a]+s,x=t[a+1]+l,S=t[a+2]+u;if(i<m||x<h||S<g||i>_||x>v||S>y)continue;let C=i-P,w=x-F,O=S-I,B=C*L+w*R+O*z;if(B<0&&B*B>o)continue;let V=B<0?0:B;if(C*C+w*w+O*O-V*V>o||k&&E.dist!=null&&(p<0&&(p=Math.sqrt(o)),Math.max(B-p,0)*T>=E.dist))continue;let H=this._intersectGaussianEllipsoid(C,w,O,L,R,z,n[e],r[e]);if(H<0)continue;let U=H*T;if(c!=null&&!c(d,f,U))continue;let W=E.dist==null||U<E.dist,G=j&&(D.dist==null||U>D.dist);if(!W&&!G&&!A)continue;let K=L*H,q=R*H,ee=z*H,J=P+K,Y=F+q,X=I+ee,Z=K-C,Q=q-w,$=ee-O;if(W&&N(E,U,J,Y,X,Z,Q,$),G&&N(D,U,J,Y,X,Z,Q,$),A){let e=new b;M.push(N(e,U,J,Y,X,Z,Q,$))}}},H=e=>{let{relativePositions:t,packedRotations:n,packedOpacityScaledScales:r,gaussianCount:i,obb:a,maxSplatMbsRadiusSquared:o}=e,s=a.centerX,l=a.centerY,u=a.centerZ,p=-1,m=P-s,h=F-l,g=I-u;for(let e=0,a=0;e<i;e++,a+=3){let i=t[a]-m,s=t[a+1]-h,l=t[a+2]-g,u=i*L+s*R+l*z;if(u<0&&u*u>o)continue;let _=u<0?0:u;if(i*i+s*s+l*l-_*_>o||k&&E.dist!=null&&(p<0&&(p=Math.sqrt(o)),Math.max(u-p,0)*T>=E.dist))continue;let v=this._intersectGaussianEllipsoid(i,s,l,L,R,z,n[e],r[e]);if(v<0)continue;let y=v*T;if(c!=null&&!c(d,f,y))continue;let x=E.dist==null||y<E.dist,S=j&&(D.dist==null||y>D.dist);if(!x&&!S&&!A)continue;let C=L*v,w=R*v,O=z*v,B=P+C,V=F+w,H=I+O,U=C-i,W=w-s,G=O-l;if(x&&N(E,y,B,V,H,U,W,G),S&&N(D,y,B,V,H,U,W,G),A){let e=new b;M.push(N(e,y,B,V,H,U,W,G))}}},U=(e,t)=>{let{min:n,max:r}=e.obb.signedDistanceRangePlane(x);if(r<0)return;let i=n*T;if(!(k&&E.dist!=null&&E.dist<i)){if(E.dist!=null&&D.dist!=null){let e=r*T;if(E.dist<i&&D.dist>e)return}t?V(e):H(e)}};this._bvh.forEachTileIntersectingRay(d,f,B==null?e=>{U(e,!1)}:e=>{let t=e.boundingBox;l(t,B)&&U(e,!u(B,t))},g);let W=(e,t)=>{let{layerViewUid:n}=t,r=new m(t.point,t.outwardDirection,n);e.set(0,r,t.dist,t.dist,t.normal)};if(y(E)){let e=a.results.min;(e.distance==null||E.dist<e.distance)&&W(e,E)}if(y(D)&&j){let e=a.results.max;(e.distance==null||D.dist>e.distance)&&W(e,D)}if(A&&M?.length)for(let e of M){let t=new _(w);W(t,e),a.results.all.push(t)}}_intersectGaussianEllipsoid(e,t,n,r,i,o,s,c){let l=s>>>30,u=s&1023,d=s>>>10&1023,f=s>>>20&1023,p=(u&x)*S*(1-(u>>>9&1)*2),m=(d&x)*S*(1-(d>>>9&1)*2),h=(f&x)*S*(1-(f>>>9&1)*2),g,_,v,y,b=p*p+m*m+h*h,T=Math.sqrt(Math.max(0,1-b));switch(l){case 0:g=T,_=h,v=m,y=p;break;case 1:g=h,_=T,v=m,y=p;break;case 2:g=h,_=m,v=T,y=p;break;default:g=h,_=m,v=p,y=T}let E=this._ellipsoidLocalRayOrigin;E[0]=-e,E[1]=-t,E[2]=-n,a(E,E,-g,-_,-v,y);let D=this._ellipsoidLocalRayDir;D[0]=r,D[1]=i,D[2]=o,a(D,D,-g,-_,-v,y);let O=w[c&255],k=w[c>>>8&255],A=w[c>>>16],j=E[0]*O,M=E[1]*k,N=E[2]*A,P=j*j+M*M+N*N;if(P<=1)return 0;let F=D[0]*O,I=D[1]*k,L=D[2]*A,R=F*F+I*I+L*L,z=j*F+M*I+N*L;if(z>0)return C;let B=z*z-R*(P-1);return B<0?C:(-z-Math.sqrt(B))/R}getElevationRange(e){return this._bvh.getElevationRangeIntersectingSphere(e)??new g(0,0)}}function y(e){return e.dist!=null&&e.point!=null}class b{constructor(){this.point=null,this.dist=null,this.normal=null,this.outwardDirection=null,this.layerViewUid=``}}const x=511,S=Math.SQRT1_2/511,C=-1,w=(()=>{let e=new Float64Array(256);for(let t=0;t<e.length;t++)e[t]=Math.exp(10-t/16)/3;return e})();export{v as GaussianSplatIntersectionHandler};