@arcgis/core 6.0.0-next.23 → 6.0.0-next.24

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 (237) hide show
  1. package/Graphic.d.ts +47 -14
  2. package/PopupTemplate.js +1 -1
  3. package/WebScene.d.ts +3 -0
  4. package/arcade/functions/string.js +1 -1
  5. package/assets/esri/core/workers/RemoteClient.js +1 -1
  6. package/assets/esri/core/workers/chunks/{db9921fbda556f142c4a.js → 04d55ed51e8b2683c4b4.js} +1 -1
  7. package/assets/esri/core/workers/chunks/{435b90168f79c5587a07.js → 04ecf15524ff3838c01c.js} +1 -1
  8. package/assets/esri/core/workers/chunks/{e2f42aec02bff33b25dd.js → 09300e74e5b014ce6269.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{fcb86d24fc7e0666b564.js → 096b2bf1c0d69d27f20c.js} +1 -1
  10. package/assets/esri/core/workers/chunks/{612345f17f5eeb99ea8f.js → 0d9c4c6c571ce26d356b.js} +1 -1
  11. package/assets/esri/core/workers/chunks/{0f725cf79ce00e790a7d.js → 1168bc5c9f0a7e1f63a2.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{12a7997a40c77f5c9160.js → 151e5799ede763a03ee2.js} +1 -1
  13. package/assets/esri/core/workers/chunks/{a64446a3328a7323e307.js → 173f89c55a5c79ff065b.js} +1 -1
  14. package/assets/esri/core/workers/chunks/{8715661a838361d4211a.js → 1b24a40c0fa197014873.js} +1 -1
  15. package/assets/esri/core/workers/chunks/{ca0d4ce453d8eb35467d.js → 277263466837e1673f56.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{b1d989b72203113a06fe.js → 2a36fe3f3f257a779a1b.js} +1 -1
  17. package/assets/esri/core/workers/chunks/{ffcb99693182a621a93e.js → 2cf8172be83b10b11bdc.js} +1 -1
  18. package/assets/esri/core/workers/chunks/{fcaf9450642fcef83286.js → 3048e74e6246324ce6fc.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{95b82cbbe355266c65d7.js → 30af63b3b750142faadb.js} +1 -1
  20. package/assets/esri/core/workers/chunks/30dcf2cfb31cb70de7df.js +1 -0
  21. package/assets/esri/core/workers/chunks/{9f0a973a0dd28953ce25.js → 371e2ddb88cc6b9a41e8.js} +1 -1
  22. package/assets/esri/core/workers/chunks/3fd5c3cd8457ddc68798.js +1 -0
  23. package/assets/esri/core/workers/chunks/{62fec1816907f070f079.js → 3fe04f13215474accb09.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{f47fe4433b05fca5c3ad.js → 42f6194633c2d879c8da.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{cddc3e285f763ccf33c2.js → 4869e097261ded90b8bb.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{d8a7eba588d374b2f961.js → 4bb9a5f4ca944d3fc206.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{8052da8be251c3ff2176.js → 4d93bed14945e3d34d5c.js} +1 -1
  28. package/assets/esri/core/workers/chunks/{65cb5e39c467a35621ca.js → 56e903ccef66cbe18f92.js} +1 -1
  29. package/assets/esri/core/workers/chunks/{44d5508042cacdfcac47.js → 58da3f8cf0f7f6a7e4fa.js} +1 -1
  30. package/assets/esri/core/workers/chunks/{bc915fb182d463d804e6.js → 5c04835b0b52461183cd.js} +1 -1
  31. package/assets/esri/core/workers/chunks/{7e8611cb709f105946f5.js → 6061232c96e11eb7b25d.js} +1 -1
  32. package/assets/esri/core/workers/chunks/{1e514e1c9aabefa04201.js → 64382363d6dc04ff1eac.js} +1 -1
  33. package/assets/esri/core/workers/chunks/{c82daefb193aae895bc0.js → 67e06d606c7fd2064adf.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{434a8ba841a59e0deab9.js → 67e533748435253aaba6.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{feb41abc03d677df6f73.js → 6b9961261241fdce0e94.js} +1 -1
  36. package/assets/esri/core/workers/chunks/{949bee7b304e625a7891.js → 6db0f8fe1402643fbe1a.js} +1 -1
  37. package/assets/esri/core/workers/chunks/{96c4ea9cfa3930f1c3fb.js → 6f1d6453184e0a1530ad.js} +1 -1
  38. package/assets/esri/core/workers/chunks/6f897b4e7ddd1dd1672b.js +1 -0
  39. package/assets/esri/core/workers/chunks/{0049b66ccbfb168caa76.js → 7124ad8dc5ad40dc66f3.js} +1 -1
  40. package/assets/esri/core/workers/chunks/{6e107ce73633de8ac257.js → 72f4dad65e16a7d7c58f.js} +1 -1
  41. package/assets/esri/core/workers/chunks/{0df9a906f7823c23d426.js → 7566321c6a2913f2852b.js} +1 -1
  42. package/assets/esri/core/workers/chunks/{c4ddac23bd649d24f3f2.js → 75d551a449bba61ce238.js} +1 -1
  43. package/assets/esri/core/workers/chunks/{af349c7bc8ef41a0e1bd.js → 7748c2886d0122b40eeb.js} +1 -1
  44. package/assets/esri/core/workers/chunks/{b4c3ec081874b49ff89b.js → 78fbe330f16bdbdb886e.js} +1 -1
  45. package/assets/esri/core/workers/chunks/79483c05867ba1386f5a.js +1 -0
  46. package/assets/esri/core/workers/chunks/7b482afb9fd1229f5707.js +1 -0
  47. package/assets/esri/core/workers/chunks/7c631e2947243e2c9bde.js +1 -0
  48. package/assets/esri/core/workers/chunks/7db9e615e60d824eac1b.js +1 -0
  49. package/assets/esri/core/workers/chunks/{8a7b02037151767542f1.js → 7dbf4c7480bf9c72820d.js} +1 -1
  50. package/assets/esri/core/workers/chunks/{64b360625c68cb863a08.js → 84940d8e14caf5a27e04.js} +1 -1
  51. package/assets/esri/core/workers/chunks/{1b1d3f6916d2cb751435.js → 87177e0f82e8a6ae3189.js} +1 -1
  52. package/assets/esri/core/workers/chunks/{5cb26bbaa08114aec5ce.js → 89cc1a5539b82fb46216.js} +1 -1
  53. package/assets/esri/core/workers/chunks/{9d40786c5ceface786ba.js → 8a485130781b49dbf608.js} +1 -1
  54. package/assets/esri/core/workers/chunks/8b5dcc4282772bf6b675.js +1 -0
  55. package/assets/esri/core/workers/chunks/{8c12269d26f5a4c753cb.js → 8ebaf5754e86a45b0497.js} +1 -1
  56. package/assets/esri/core/workers/chunks/{542e5640ea1b80ef801a.js → 9189dfe19a2a2ccd5173.js} +1 -1
  57. package/assets/esri/core/workers/chunks/{67a35155b8b4d36f171e.js → 926e0a3827eaf16ca8b4.js} +1 -1
  58. package/assets/esri/core/workers/chunks/{dc1761cba0454fda3cf9.js → 9630234267098115de4d.js} +1 -1
  59. package/assets/esri/core/workers/chunks/{10d80e793019dfb45ca2.js → 987424121cf30b0f3c50.js} +1 -1
  60. package/assets/esri/core/workers/chunks/9afc87474cef1fc4fe4a.js +1 -0
  61. package/assets/esri/core/workers/chunks/{facd1ff23203fed67686.js → 9b048f80c2d28d527373.js} +1 -1
  62. package/assets/esri/core/workers/chunks/9dd48e75b4e8d9811d81.js +1 -0
  63. package/assets/esri/core/workers/chunks/{ee08ae5b73439a1ff666.js → a163c6005aba3378edaa.js} +1 -1
  64. package/assets/esri/core/workers/chunks/{517106048980a3cbe072.js → a4b822ee45810c4c292a.js} +1 -1
  65. package/assets/esri/core/workers/chunks/{092e311cb7aea92a6a26.js → acb265a22be5e12f38e5.js} +1 -1
  66. package/assets/esri/core/workers/chunks/{1a411ddae7a47015370c.js → acf4737ba509cbd73cce.js} +1 -1
  67. package/assets/esri/core/workers/chunks/{d247dd53788d512b9c9f.js → af3c6794334626b94f00.js} +1 -1
  68. package/assets/esri/core/workers/chunks/{532e9cda8ac3601d8892.js → b12acf1f694f82e00df9.js} +1 -1
  69. package/assets/esri/core/workers/chunks/{636cd05abfbdff19029e.js → ba3d5abff65aefcb8dee.js} +1 -1
  70. package/assets/esri/core/workers/chunks/{504184828048310a052c.js → bdc221d94300c225665a.js} +1 -1
  71. package/assets/esri/core/workers/chunks/c0eb27263f608dc3684b.js +1 -0
  72. package/assets/esri/core/workers/chunks/c2318c014e97ba519be8.js +1 -0
  73. package/assets/esri/core/workers/chunks/{7f8e327acad48c9e75ea.js → c62237c344e341619341.js} +1 -1
  74. package/assets/esri/core/workers/chunks/{a2ad3e620c98e2b2eb06.js → cd355baab983033c3ef0.js} +1 -1
  75. package/assets/esri/core/workers/chunks/{7be6d621a0d1e33dfff4.js → d070fcb73ce274ab80e4.js} +1 -1
  76. package/assets/esri/core/workers/chunks/{6d41444b46677aa762a7.js → db41490bd39d863305bf.js} +1 -1
  77. package/assets/esri/core/workers/chunks/{fc5a36e54929e03efa86.js → dba5f44c4e4a3f075df2.js} +1 -1
  78. package/assets/esri/core/workers/chunks/{3e30b96a8c75bd5b9ae2.js → ddc95cdac6c06fc4794c.js} +1 -1
  79. package/assets/esri/core/workers/chunks/{a5c8f9f5be4ef5063b42.js → df26ec0b508cf4716e0a.js} +1 -1
  80. package/assets/esri/core/workers/chunks/{f426da2210888cc264b4.js → e83f9abee611c5b80009.js} +1 -1
  81. package/assets/esri/core/workers/chunks/{8487727f1197cf7dbf50.js → ef12fa3574d4cbf8b084.js} +1 -1
  82. package/assets/esri/core/workers/chunks/f10c883eb26330e3421c.js +1 -0
  83. package/assets/esri/core/workers/chunks/f46e92c67986c8c09bdd.js +1 -0
  84. package/assets/esri/core/workers/chunks/{709e019885822b1f6f3e.js → f905f1a1aa4c123cbe83.js} +1 -1
  85. package/assets/esri/core/workers/chunks/{5b91e2dffdc84c006539.js → fb37f0848196c28b7fd7.js} +1 -1
  86. package/assets/esri/libs/librust-parquet/pkg/parquet_bg.wasm +0 -0
  87. package/assets/esri/libs/librust-text/pkg/text_bg.wasm +0 -0
  88. package/chunks/MultiPathImpl.js +1 -1
  89. package/chunks/OperatorProximityGeodesic.js +1 -1
  90. package/chunks/basis_encoder.js +1 -1
  91. package/chunks/basis_transcoder.js +1 -1
  92. package/chunks/draco_mesh_decoder.js +1 -1
  93. package/chunks/dxt_encoder.js +1 -1
  94. package/chunks/i3s.js +1 -1
  95. package/chunks/lclayout.js +1 -1
  96. package/chunks/lerc-wasm.js +1 -1
  97. package/chunks/libtess-f32.js +1 -1
  98. package/chunks/libtess-f64.js +1 -1
  99. package/chunks/lyr3DMain.js +1 -1
  100. package/chunks/lyr3DWorker.js +1 -1
  101. package/chunks/parquet.js +1 -1
  102. package/chunks/qb3-wasm.js +1 -1
  103. package/chunks/rbush.js +1 -1
  104. package/chunks/text.js +1 -1
  105. package/chunks/vxlLayer.js +1 -1
  106. package/config.js +1 -1
  107. package/core/workers/WorkerFallback.js +4 -2
  108. package/core/workers/workerFactory.js +1 -1
  109. package/core/workers/workers.js +4 -2
  110. package/geometry/support/labelPoint.js +1 -1
  111. package/graphic/AnnotationFeatureGraphicOrigin.d.ts +49 -9
  112. package/graphic/BuildingGraphicOrigin.d.ts +49 -0
  113. package/graphic/CSVGraphicOrigin.d.ts +42 -9
  114. package/graphic/CatalogGraphicOrigin.d.ts +42 -9
  115. package/graphic/DimensionFeatureGraphicOrigin.d.ts +42 -9
  116. package/graphic/FeatureGraphicOrigin.d.ts +42 -9
  117. package/graphic/GeoJSONGraphicOrigin.d.ts +42 -9
  118. package/graphic/GeoRSSGraphicOrigin.d.ts +42 -9
  119. package/graphic/GraphicOrigin.d.ts +52 -12
  120. package/graphic/ImageryGraphicOrigin.d.ts +42 -9
  121. package/graphic/ImageryTileGraphicOrigin.d.ts +42 -9
  122. package/graphic/KMLGraphicOrigin.d.ts +47 -10
  123. package/graphic/KnowledgeGraphGraphicOrigin.d.ts +49 -1
  124. package/graphic/LinkChartGraphicOrigin.d.ts +49 -1
  125. package/graphic/MapImageGraphicOrigin.d.ts +49 -1
  126. package/graphic/MapNotesGraphicOrigin.d.ts +48 -1
  127. package/graphic/OGCFeatureGraphicOrigin.d.ts +42 -9
  128. package/graphic/OrientedImageryGraphicOrigin.d.ts +42 -9
  129. package/graphic/ParquetGraphicOrigin.d.ts +42 -9
  130. package/graphic/PointCloudGraphicOrigin.d.ts +43 -0
  131. package/graphic/SceneGraphicOrigin.d.ts +43 -0
  132. package/graphic/SketchGraphicOrigin.d.ts +43 -0
  133. package/graphic/StreamGraphicOrigin.d.ts +43 -0
  134. package/graphic/SubtypeGroupGraphicOrigin.d.ts +49 -1
  135. package/graphic/TileGraphicOrigin.d.ts +49 -1
  136. package/graphic/VectorTileGraphicOrigin.d.ts +43 -14
  137. package/graphic/VoxelGraphicOrigin.d.ts +43 -0
  138. package/graphic/WCSGraphicOrigin.d.ts +43 -0
  139. package/graphic/WFSGraphicOrigin.d.ts +42 -9
  140. package/graphic/getGraphicOriginTitle.d.ts +21 -3
  141. package/kernel.js +1 -1
  142. package/layers/GaussianSplatLayer.d.ts +2 -1
  143. package/layers/ParquetLayer.d.ts +24 -1
  144. package/layers/ParquetLayer.js +1 -1
  145. package/layers/mixins/ReloadableLayer.js +1 -1
  146. package/layers/orientedImagery/transformations/utils.js +1 -1
  147. package/layers/save/featureLayerUtils.js +1 -1
  148. package/layers/save/imageryUtils.js +1 -1
  149. package/layers/save/mapImageLayerUtils.js +1 -1
  150. package/layers/save/mediaLayerUtils.js +1 -1
  151. package/layers/save/parquetLayerUtils.js +2 -0
  152. package/layers/save/streamLayerUtils.js +1 -1
  153. package/layers/support/LabelClass.d.ts +8 -2
  154. package/layers/support/layersMapping.js +1 -1
  155. package/layers/support/rasterJobHelper.js +1 -1
  156. package/layers/video/VideoController.js +5 -5
  157. package/package.json +2 -2
  158. package/popup/content.js +1 -1
  159. package/portal/schemas/definitions.js +1 -1
  160. package/portal/schemas/webScene.js +1 -1
  161. package/rest/query/operations/pbfDehydratedFeatureSet.js +1 -1
  162. package/rest/query/operations/pbfFlatFeatureSet.js +1 -1
  163. package/rest/query/operations/pbfJSONFeatureSet.js +1 -1
  164. package/undoredo/support/ApplySet.js +1 -1
  165. package/views/2d/engine/flow/ProcessingTimeEstimate.js +1 -1
  166. package/views/2d/engine/vectorTiles/VectorTileContainer.js +1 -1
  167. package/views/2d/engine/vectorTiles/buckets/SymbolBucket.js +1 -1
  168. package/views/2d/engine/webgl/mesh/templates/shapingUtils.js +1 -1
  169. package/views/2d/engine/webgl/shaderGraph/techniques/markers/MarkerMeshWriter.js +1 -1
  170. package/views/3d/interactive/editingTools/reshape/ReshapeOperation.js +1 -1
  171. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  172. package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
  173. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  174. package/views/3d/layers/graphics/ElevationAligners.js +1 -1
  175. package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
  176. package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
  177. package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
  178. package/views/3d/layers/graphics/LabelParameters.js +1 -1
  179. package/views/3d/layers/graphics/Labeler.js +1 -1
  180. package/views/3d/layers/graphics/elevationAlignmentUtils.js +1 -1
  181. package/views/3d/layers/graphics/pointUtils.js +1 -1
  182. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  183. package/views/3d/layers/i3s/I3SOverrides.js +1 -1
  184. package/views/3d/layers/support/Tiles3DBVH.js +1 -1
  185. package/views/3d/layers/support/featureTileQuery3D.js +1 -1
  186. package/views/3d/state/controllers/ZoomControllerLocal.js +1 -1
  187. package/views/3d/state/controllers/ZoomStepControllerLocal.js +1 -1
  188. package/views/3d/state/helpers/SceneIntersectionHelper.js +1 -1
  189. package/views/3d/state/utils/groundNavigationUtils.js +1 -1
  190. package/views/3d/state/utils/navigationUtils.js +1 -1
  191. package/views/3d/terrain/TerrainRenderer.js +1 -1
  192. package/views/3d/terrain/TerrainSurface.js +1 -1
  193. package/views/3d/webgl-engine/effects/magnifier/Magnifier.js +1 -1
  194. package/views/3d/webgl-engine/effects/shadowAccumulation/ShadowCastRenderer.js +1 -1
  195. package/views/3d/webgl-engine/lib/RenderingContext.js +1 -1
  196. package/views/3d/webgl-engine/lib/TextureRepository.js +1 -1
  197. package/views/3d/webgl-engine/lib/depthRangeUtils.js +1 -1
  198. package/views/3d/webgl-engine/lib/screenPolygonTriangleIntersections.js +1 -1
  199. package/views/3d/webgl-engine/materials/ColorMaterial.js +1 -1
  200. package/views/3d/webgl-engine/materials/DefaultMaterial.js +1 -1
  201. package/views/3d/webgl-engine/materials/PathMaterial.js +1 -1
  202. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  203. package/views/3d/webgl-engine/materials/TriangleMaterial.js +1 -1
  204. package/views/3d/webgl-engine/materials/internal/worldSizedRibbonLineIntersectionUtils.js +1 -1
  205. package/views/DOMContainer.js +1 -1
  206. package/views/draw/SegmentDrawAction.js +1 -1
  207. package/views/interactive/snapping/SnappingManagerPool.js +1 -1
  208. package/views/interactive/tooltip/content/TooltipContent.js +1 -1
  209. package/views/interactive/tooltip/fields/TooltipField.js +1 -1
  210. package/views/support/LayerViewManager.js +1 -1
  211. package/views/support/ScheduledQueueProcessor.js +1 -1
  212. package/views/support/screenshotUtils.js +1 -1
  213. package/views/ui/UI.js +1 -1
  214. package/webdoc/support/webdocSaveUtils.js +1 -1
  215. package/webscene/Slide.d.ts +1 -2
  216. package/widgets/Editor/UpdateRecordWorkflow.js +1 -1
  217. package/widgets/Feature/FeatureRelationship/FeatureRelationshipViewModel.js +1 -1
  218. package/widgets/FeatureForm/UtilityNetworkAssociationAddAssociationViewModel.js +1 -1
  219. package/widgets/FeatureTable/RelationshipColumn.js +1 -1
  220. package/widgets/OrientedImageryViewer/ImageMeasurementWorker.js +1 -1
  221. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  222. package/widgets/OrientedImageryViewer/imageMeasurementUtils.js +1 -1
  223. package/widgets/OrientedImageryViewer/services/ImageMeasurementService.js +1 -1
  224. package/widgets/Sketch/SketchViewModel.js +1 -1
  225. package/assets/esri/core/workers/chunks/14d5d219e7fe017f23f0.js +0 -1
  226. package/assets/esri/core/workers/chunks/42753cf4965a94bc91ca.js +0 -1
  227. package/assets/esri/core/workers/chunks/42e985a576d7aaeed0cf.js +0 -1
  228. package/assets/esri/core/workers/chunks/5046214dd32029cb733d.js +0 -1
  229. package/assets/esri/core/workers/chunks/58865772bed48141a56a.js +0 -1
  230. package/assets/esri/core/workers/chunks/72e6d594b7262430ae55.js +0 -1
  231. package/assets/esri/core/workers/chunks/7d11710e1586a3d75887.js +0 -1
  232. package/assets/esri/core/workers/chunks/8f74d92ac69714b9fd4e.js +0 -1
  233. package/assets/esri/core/workers/chunks/947674b2ca8be65b9bcc.js +0 -1
  234. package/assets/esri/core/workers/chunks/9e7c4eda135c4911b268.js +0 -1
  235. package/assets/esri/core/workers/chunks/a09d2e1e2540921e4717.js +0 -1
  236. package/assets/esri/core/workers/chunks/dfa5f1311806473e473f.js +0 -1
  237. package/assets/esri/core/workers/chunks/fc76aff0f7d95e517d8f.js +0 -1
@@ -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{removeUnordered as n}from"../../../../../core/arrayUtils.js";import{EventEmitter as r}from"../../../../../core/Evented.js";import i from"../../../../../core/Handles.js";import{makeHandle as a,handlesGroup as o,destroyHandle as s}from"../../../../../core/handleUtils.js";import"../../../../../core/has.js";import{destroyMaybe as c,removeMaybe as l}from"../../../../../core/maybe.js";import{initial as u,on as d,watch as f,syncAndInitial as p,when as m,sync as h}from"../../../../../core/reactiveUtils.js";import{property as g,subclass as _}from"../../../../../core/accessorSupport/decorators.js";import{IDENTITY as v}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{length as y,subtract as b,lerp as x,set as ee,add as te,scale as ne}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as re,create as ie}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as ae}from"../../../../../core/support/UpdatingHandles.js";import oe from"../../../../../geometry/Point.js";import se from"../../../../../geometry/Polyline.js";import{projectPoint as ce}from"../../../../../geometry/projectionUtils.js";import le from"../../../../../geometry/SpatialReference.js";import{makeDehydratedPoint as ue}from"../../../../../layers/graphics/dehydratedPoint.js";import{getZForElevationMode as de}from"../../../../../support/elevationInfoUtils.js";import{isVolumetricSymbol as fe}from"../../../../../symbols/support/utils.js";import{Manipulator3D as S}from"../../Manipulator3D.js";import{createManipulatorMaterials as C,createSphereGeometryAsOffsets as w,placeAtObject as pe,screenSizeManipulatorSettings as me}from"../../manipulatorUtils.js";import{RenderObject as T}from"../../RenderObject.js";import{SegmentLabels3D as he}from"../../SegmentLabels3D.js";import{SnappingVisualizer3D as ge}from"../../SnappingVisualizer3D.js";import{screenToMapXYAtLocation as E,screenToRenderPlaneFromEvent as _e,convertToMapCoordinates as ve}from"../dragEventPipeline3D.js";import{orientation as ye}from"../geometryUtils.js";import{canMoveZOperations as D}from"../manipulatorUtils.js";import{Settings as be}from"../settings.js";import{createVisualElements as xe}from"../visualElementUtils.js";import{discRadiusSmall as Se}from"../manipulations/config.js";import{MoveManipulation as O}from"../manipulations/MoveManipulation.js";import{MoveXYObjectManipulation as Ce}from"../manipulations/MoveXYObjectManipulation.js";import{getMapPointAtEdgeOffsetManipulatorElevation as k,createEdgeOffsetIntersectionPlane as A,createEdgeOffsetOperation as j,edgeOffsetRotationMatrix as we,screenEdgeLengthSquared as Te,getDistanceInGeometrySR as Ee}from"./edgeOffsetUtils.js";import{createTooltipInfos as De,connectTooltipToManipulatedObject as Oe,getUpdatedTranslateObjectTooltipInfo as ke,getUpdatedEdgeOffsetTooltipInfo as M}from"./reshapeTooltipUtils3D.js";import{OutlineVisualElement as N}from"../../visualElements/OutlineVisualElement.js";import{createElevationUpdateHandle as Ae}from"../../../support/elevationUpdateUtils.js";import{createExtrudedTriangle as P}from"../../../webgl-engine/lib/GeometryUtil.js";import{mouseButtons as F}from"../../../../input/mouseButtons.js";import{sceneSnappingAtLocation as I,addMapDelta as L,createManipulatorDragEventPipeline as R,dragAtLocation as z,addScreenDelta as je}from"../../../../interactive/dragEventPipeline.js";import{tooltipKeys as Me}from"../../../../interactive/keybindings.js";import{SnappingContext as B}from"../../../../interactive/snapping/SnappingContext.js";import{createSnapDragEventPipelineStep as V}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{makeTooltip as Ne,enterInputModeIfAvailable as H}from"../../../../interactive/tooltip/tooltipCommonUtils.js";import{GeometryWorkerHandle as Pe}from"../../../../support/GeometryWorkerHandle.js";const U=Symbol(),W=Symbol(),Fe=Symbol(),G=Symbol();let K=class extends t{get _movingManipulatorsHidden(){return this.hasHandles(G)}get _operations(){return this.object.operations}constructor(e){super(e),this._selectedIndex=0,this._manipulatorHandles=new i,this._manipulatorInfos=[],this._numGrabbing=0,this._numDragging=0,this._reshapeEventState=0,this._pendingEdgeOffsetInfo=null,this._updatingHandles=new ae,this._recreatingManipulators=!1,this._settings=new be({getTheme:()=>this.view.effectiveTheme}),this.events=new r,this.activeTooltipInfo=null,this._measurementWorker=new Pe({preloadGeodetic:!0}),this._vertexLaserLineVisualElement=null,this._tooltipCallbacks={onBeforeReshape:()=>this.tool.endDrag(),onReshapeStart:()=>this._updateEventState(2),onReshape:()=>this.events.emit(`reshape`,{type:`reshape`,object:this.object}),onReshapeStop:()=>this._updateEventState(0,{forceEnd:!0}),onMoveStart:()=>this._updateEventState(1),onMove:()=>this.events.emit(`move`,{type:`move`,object:this.object,dx:0,dy:0}),onMoveStop:()=>this._updateEventState(0,{forceEnd:!0})}}initialize(){let{view:e}=this,t=this._settings.manipulators,n=t.vertex;this.tooltipInfos=De(this._toolOptions,e),this._vertexManipulatorMaterials=C({color:n.color.toUnitRGBA(),outlineColor:n.outlineColor.toUnitRGBA(),focusedOutlineColor:n.focusedOutlineColor.toUnitRGBA(),screenSize:n,renderOccluded:n.renderOccluded});let r=t.edge;this._edgeManipulatorMaterials=C({color:r.color.toUnitRGBA(),outlineColor:r.outlineColor.toUnitRGBA(),screenSize:r,renderOccluded:r.renderOccluded});let i=t.edgeOffset;this._edgeOffsetManipulatorMaterials=C({color:i.color.toUnitRGBA(),focusedColor:i.focusedColor.toUnitRGBA(),renderOccluded:i.renderOccluded,shaded:!1});let a=t.selected;this._selectedManipulatorMaterials=C({color:a.color.toUnitRGBA(),outlineColor:a.outlineColor.toUnitRGBA(),focusedOutlineColor:a.focusedOutlineColor.toUnitRGBA(),screenSize:a,renderOccluded:a.renderOccluded}),this.tooltip=Ne(()=>({view:e,options:this._toolOptions.tooltips})),this.addHandles([this._updatingHandles.add(()=>{let e=this._settings.manipulators;return{vertexSettings:e.vertex,edgeSettings:e.edge,edgeOffsetSettings:e.edgeOffset,selectedSettings:e.selected}},({vertexSettings:e,edgeSettings:t,edgeOffsetSettings:n,selectedSettings:r})=>{e.applyColor(this._vertexManipulatorMaterials.material),e.applyOutline(this._vertexManipulatorMaterials.outlineMaterial),e.applyFocusedOutline(this._vertexManipulatorMaterials.focusedMaterial),t.applyColor(this._edgeManipulatorMaterials.material),t.applyOutline(this._edgeManipulatorMaterials.outlineMaterial),n.applyColor(this._edgeOffsetManipulatorMaterials.material),n.applyFocused(this._edgeOffsetManipulatorMaterials.focusedMaterial),r.applyColor(this._selectedManipulatorMaterials.material),r.applyOutline(this._selectedManipulatorMaterials.outlineMaterial),r.applyFocusedOutline(this._selectedManipulatorMaterials.focusedMaterial)}),this._updatingHandles.add(()=>this.object.visible,e=>{for(let t of this._manipulatorInfos)t.manipulator.available=e,Y(t)&&(t.edgeManipulator.available=e)}),this._updatingHandles.add(()=>this._numGrabbing+this._numDragging===0,e=>this._toggleAutoHideManipulators(e)),this._updatingHandles.add(()=>({labels:this._segmentLabels,enabled:this._toolOptions.labels.enabled,edgeOffsetEnabled:this.enableEdgeOffset}),({labels:e,enabled:t,edgeOffsetEnabled:n})=>{e!=null&&(e.visible=t,e.edgeDistance=n?`far`:`default`)},u),Oe(this.tooltip,this.object,()=>this._tooltipsContext,this._updatingHandles),this._updatingHandles.add(()=>this.tooltip.mode,(e,t)=>{t===`input`&&e!==`input`&&this._resetTooltip()}),d(()=>this._operations,`vertex-update`,e=>this._updateManipulatorPositions(e.vertices),{onListenerAdd:()=>this._recreateManipulators()}),d(()=>this._operations?.data,`change`,e=>{(e.operation===`undo`||e.operation===`redo`)&&this._recreateManipulators()})])}destroy(){this._removeManipulators(),this._updatingHandles.destroy(),this._segmentLabels=c(this._segmentLabels),this.tooltip=c(this.tooltip),this._measurementWorker.destroy()}get updating(){return this._updatingHandles.updating||!!this._segmentLabels?.updating}get manipulators(){return this.tool.manipulators}get view(){return this.tool.view}get object(){return this.tool.object}get enableZShape(){return this.tool.enableZShape}get enableDeleteVertices(){return this.tool.enableDeleteVertices}get enableZVertex(){return this.tool.enableZVertex}get autoHideManipulators(){return this.tool.autoHideManipulators}get enableMoveObject(){return this.tool.enableMoveObject}get enableMidpoints(){return this.tool.enableMidpoints}get enableEdgeOffset(){return this.tool.enableEdgeOffset}get _toolOptions(){return this.tool.toolOptions}get _accentColor(){return this.view.effectiveTheme.accentColor}enterInputModeIfAvailable(e){return e.type!==`key-down`||e.key!==Me.enterInputMode?!1:this.activeTooltipInfo?.type===`reshape-edge-offset`?this._enterInputModeDuringEdgeOffset(e):H(e,this.tooltip)?(this.tool.endDrag(),!0):!1}removeSelectedVertices(){let e=this._manipulatorInfos.filter(e=>e.manipulator.selected&&e.type===`vertex`);return this._removeVertices(e),e.length}onManipulatorSelectionChanged(){this.events.emit(`manipulators-changed`)}_removeManipulators(){this._manipulatorHandles.removeAll(),this.removeHandles(W),this.removeHandles(G),this._moveManipulation=c(this._moveManipulation),this._objectMoveManipulation=c(this._objectMoveManipulation),this.manipulators.removeAll(),this._manipulatorInfos=[],this._numGrabbing=0,this._numDragging=0}_createManipulators(e){if(this._operations==null)return;let t=this.object.elevationInfo;for(let{vertices:n,segments:r,index:i}of this._operations.data.parts){let a=e?.byPartIndex.get(i);for(let e of n){let n=a?.has(e.index);this._createVertexOrEdgeManipulator(e,t,n)}for(let e of r)e.type===`line`&&this._createVertexOrEdgeManipulator(e,t)}this._createObjectMoveManipulation(),this._createMoveManipulation(t),this._createVisualElements()}recordUndo(e){this._operations?.recordUndo(e,!0)}get canRedo(){return this._operations?.canRedo??!1}get canUndo(){return this._operations?.canUndo??!1}redo(){return this._operations?.redo()}undo(){return this.events.emit(`undo`),this._operations?.undo()}_recreateManipulators(){if(!this._recreatingManipulators){if(this._recreatingManipulators=!0,this._removeManipulators(),this._resetTooltip(),this._operations&&this._segmentLabels?.context?.editGeometryOperations===this._operations||(this._segmentLabels=c(this._segmentLabels)),this._createManipulators(),!this._segmentLabels&&this._operations){let e=this._toolOptions.labels;this._segmentLabels=new he({context:{view:this.view,editGeometryOperations:this._operations,elevationInfo:this.object.elevationInfo,labelOptions:e},visible:e.enabled})}this._recreatingManipulators=!1}}_perObjectManipulatorDragAction(e,t){if(t.action===`end`)return t;let n=0,r=[],i=e===1&&this._someVerticesSelected;for(let e of this._manipulatorInfos)e.type===`vertex`&&(e.manipulator.grabbing||i&&!e.manipulator.selected||r.push(e),n++);if(r.length===n){if(i||this._hideReshapeControls(),this._moveVertices(r,t),this._updateEventState(1),this.destroyed)return t;this.events.emit(`move`,{type:`move`,dx:t.screenDeltaX,dy:t.screenDeltaY,object:this.object})}else{if(this._moveVertices(r,t),this._updateEventState(2),this.destroyed)return t;this.events.emit(`reshape`,{type:`reshape`,object:this.object})}return t}_hideReshapeControls(){this._movingManipulatorsHidden||this.addHandles([this._hideReshapeManipulators(),this._moveManipulation.hideManipulatorsExceptGrabbedGroup(),a(()=>this._forEachVertex(e=>this._updateManipulatorPosition(e)))],G)}_showReshapeControls(){this.removeHandles(G)}_shouldHideReshapeControlsOnGrab(e){return this._objectMoveManipulation.hasManipulator(e)||this._moveManipulation.hasManipulator(e)&&!this._someVerticesSelected}get _canShowReshapeControls(){return!this._objectMoveManipulation.grabbing&&(!this._moveManipulation.grabbing||this._someVerticesSelected)}_hideManipulatorsForEdgeOffset(e){let t=this._manipulatorInfos.filter(Y).find(t=>t.manipulator===e||t.edgeManipulator===e);t!=null&&(this.removeHandles(W),this.addHandles([this._moveManipulation.hideManipulators(),this._hideReshapeManipulators(t)],W))}_hideReshapeManipulators(e){return o(this._manipulatorInfos.flatMap(t=>t===e?null:[t.manipulator.disableDisplay(),Y(t)?t.edgeManipulator.disableDisplay():null]))}_toggleAutoHideManipulators(e){this.autoHideManipulators&&(e?this.removeHandles(U):this.tool.manipulators.forEach(({manipulator:e})=>{let t=e.disableDisplay?.();t&&this.addHandles(t,U)}))}_isMultiVertexSelection(){return this._manipulatorInfos.reduce((e,t)=>t.type===`vertex`&&t.manipulator.selected?e+1:e,0)>1}_perVertexManipulatorDragAction(e){if(this._updateEventState(2),this.destroyed)return;let{mapDeltaX:t,mapDeltaY:n,mapDeltaZ:r}=e;if(!t&&!n&&!r)return;let i=[];this._forEachVertex(t=>{let{selected:n,grabbing:r}=t.manipulator;(n&&!r||t===e.info)&&i.push(t)}),this._moveVertices(i,e,1),this.events.emit(`reshape`,{type:`reshape`,object:this.object})}_updateEventState(e,t={}){if(e===this._reshapeEventState)return!1;switch(e){case 0:if(!t.forceEnd&&(this._numGrabbing!==0||this._numDragging!==0))return!1;switch(this._reshapeEventState){case 1:this._showReshapeControls(),this.events.emit(`move`,{type:`move-stop`,dx:0,dy:0,object:this.object});break;case 2:this.events.emit(`reshape`,{type:`reshape-stop`,object:this.object})}break;case 1:switch(this._reshapeEventState){case 0:this.events.emit(`move`,{type:`move-start`,dx:0,dy:0,object:this.object});break;case 2:this.events.emit(`reshape`,{type:`reshape-stop`,object:this.object}),this.destroyed||this.events.emit(`move`,{type:`move-start`,dx:0,dy:0,object:this.object})}break;case 2:switch(this._reshapeEventState){case 0:this.events.emit(`reshape`,{type:`reshape-start`,object:this.object});break;case 1:this._showReshapeControls(),this.events.emit(`move`,{type:`move-stop`,dx:0,dy:0,object:this.object}),this.destroyed||this.events.emit(`reshape`,{type:`reshape-start`,object:this.object})}}if(this.destroyed)return!1;let n=this._reshapeEventState!==e;return this._reshapeEventState=e,n}_createObjectMoveManipulation(){let{tool:e,view:t,object:n,_operations:r}=this;if(r){if(this._objectMoveManipulation=new Ce({tool:e,view:t,object:n}),this.enableMoveObject){let e=null;this._manipulatorHandles.add(this._objectMoveManipulation.createDragPipeline((t,n,i)=>{n.next(e=>this._trackNumDragging(e)).next(t=>(t.action===`start`&&(e=r.createUndoGroup()),t)).next(e=>this._perObjectManipulatorDragAction(0,e)).next(e=>(this._updateTranslateObjectTooltip(0,e),e)).next(t=>{t.action===`end`&&(this._showReshapeControls(),this._resetTooltip(),e=l(e))}),i.next(()=>this._onDragCancel(!0,()=>e=l(e)))})),this._objectMoveManipulation.forEachManipulator(e=>this._manipulatorHandles.add(this._watchAndUpdateGrabState(e,!1)))}else this._objectMoveManipulation.forEachManipulator(e=>{e.grabbable=!1,e.cursor=null});this._objectMoveManipulation.forEachManipulator(e=>this._manipulatorHandles.add(e.events.on(`immediate-click`,e=>{this._manipulatorInfos.some(e=>e.manipulator.selected)?this._clearSelection():this.events.emit(`immediate-click`,{...e,object:this.object}),e.stopPropagation()})))}}_createMoveManipulation(e){let{object:t,tool:n,view:r,_operations:i}=this;if(!i)return;this._moveManipulation=new O({tool:n,view:r,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:this.enableZShape&&D(t.operations,t.elevationInfo),snapToScene:!1,radius:O.radiusForSymbol(t.graphic?.symbol)}),this._moveManipulation.forEachManipulator(e=>this.addHandles([e.events.on(`immediate-click`,t=>{!this._moveManipulation.zManipulation.hasManipulator(e)&&!this._manipulatorInfos.some(e=>e.manipulator.selected)&&this.events.emit(`immediate-click`,{...t,object:this.object}),t.stopPropagation()}),this._watchAndUpdateGrabState(e,!1)]));let a=e=>t=>{this.addHandles([t.events.on(`focus-changed`,({action:t})=>{t===`focus`?this._updateTranslateTooltip(e):this._resetTooltip()})])};this._moveManipulation.xyManipulation.forEachManipulator(a(0)),this._moveManipulation.xyAxisManipulation.forEachManipulator(a(1)),this._moveManipulation.zManipulation.forEachManipulator(a(2)),this._moveManipulation.elevationInfo={mode:`absolute-height`,offset:0};let o=i.data.spatialReference;this.addHandles([this._moveManipulation.createDragPipeline((r,a,o,s,c)=>{let{snappingStep:l,cancelSnapping:u}=V({predicate:e=>!!e.info,snappingManager:n.snappingManager,snappingContext:new B({editGeometryOperations:i,elevationInfo:e,pointer:c,excludeFeature:t.graphic,visualizer:new ge}),updatingHandles:this._updatingHandles,useZ:!1});return s=s.next(e=>(this._onDragCancel(),e)).next(u),o=o.next(e=>this._trackNumDragging(e)).next(e=>{let t=this._manipulatorInfos.filter(e=>e.type===`vertex`&&e.manipulator.selected);return e.manipulatorType===1&&t.length===1?{...e,info:t[0],snapOrigin:t[0].handle.pos}:e}).next(I(this.view,e,t.graphic??void 0)).next(...l).next(L()).next(e=>this._perObjectManipulatorDragAction(1,e)).next(e=>(e.action===`end`&&this._showReshapeControls(),this._updateTranslateTooltip(r,e),e)),{steps:o,cancel:s}},e,o,t.graphic),this._updatingHandles.add(()=>t.visible,()=>this._updateMoveManipulationPosition(),u),t.on(`committed`,()=>{this._recreatingManipulators||this._updateMoveManipulationPosition()}),this._updatingHandles.add(()=>t.isDraped,e=>{this._updateMoveManipulationPosition(),this.removeHandles(Fe),e&&this.addHandles(Ae({view:this.view,geometry:()=>t.graphic?.geometry,elevationInfo:t.elevationInfo,onElevationChanges:()=>this._updateMoveManipulationPosition()}),Fe)},u)])}_createVisualElements(){let{object:e,view:t}=this,n=xe({view:t,object:e,forEachManipulator:e=>{if(!(this.destroyed||this._recreatingManipulators)){this._objectMoveManipulation.forEachManipulator(e),this._moveManipulation.forEachManipulator(e);for(let t of this._manipulatorInfos)e(t.manipulator,1)}},onManipulatorsChanged:e=>this.events.on(`manipulators-changed`,e)});n!=null&&(this._outlineVisualElement=n.visualElement instanceof N?n.visualElement:null);let r=this._outlineVisualElement;if(r!=null){let t=()=>{e.isDraped||this._updateMoveManipulationPosition()};this._manipulatorHandles.add(d(()=>r.events,`attachment-origin-changed`,t,{onListenerAdd:t}))}this._manipulatorHandles.add(n)}_createEdgeOffsetManipulator(e,t=this.object.elevationInfo){let n=this.view,r=this._operations;if(e.part.vertices.length<=2||!r)return null;let i=r.data.spatialReference,a=this._settings.manipulators.edgeOffset,s=a.size/2,c=s+a.collisionPadding,l=s/c,u=l/2,d=l*Math.sqrt(3)/2,{height:f,offset:p}=a,{material:m,focusedMaterial:h}=this._edgeOffsetManipulatorMaterials;if(!this._edgeOffsetManipulatorGeometryInside){let e=P(m,d,u,u,f,p);this._edgeOffsetManipulatorGeometryInside=e}if(!this._edgeOffsetManipulatorGeometryOutside){let e=P(m,-d,u,u,f,-p);this._edgeOffsetManipulatorGeometryOutside=e}let g=[new T(this._edgeOffsetManipulatorGeometryInside.instantiate(),1),new T(this._edgeOffsetManipulatorGeometryInside.instantiate({material:h}),2),new T(this._edgeOffsetManipulatorGeometryOutside.instantiate(),1),new T(this._edgeOffsetManipulatorGeometryOutside.instantiate({material:h}),2)],_=new S({view:n,renderObjects:g,elevationInfo:t.mode===`on-the-ground`&&!fe(this.object.graphic?.symbol)?t:{mode:`absolute-height`,offset:0},worldOriented:!1,focusMultiplier:1,radius:c,available:this.object.visible,collisionType:{type:`disc`,direction:re(0,0,1)},collisionPriority:1,metadata:{deleting:!1},location:J(i)}),v=new S({view:n,worldSized:!0,worldOriented:!1,available:this.object.visible,collisionPriority:-10,cursor:this.enableMoveObject?`move`:`default`,metadata:{deleting:!1},location:J(i)}),y={manipulator:_,handle:e,locationUpdateHandle:null,type:`edge`,selectedIndex:0,edgeManipulator:v,visibilityHandle:null};this._autoHideEdgeOffsetManipulator(y,a.minSquaredEdgeLength);let b=()=>this._updateEdgeOffsetManipulator(y);b(),y.locationUpdateHandle=o([e.leftVertex,e.rightVertex].map(e=>this._getManipulatorInfoFromHandle(e)?.manipulator.events.on(`location-update`,b)));let x=e=>{this._manipulatorInfos.some(e=>e.manipulator.selected)?this._clearSelection():this.events.emit(`immediate-click`,{...e,object:this.object}),e.stopPropagation()};return this._manipulatorHandles.add([y.locationUpdateHandle,this._watchAndUpdateGrabState(_,!0),this._watchAndUpdateGrabState(v,!0),R(_,this._createEdgeOffsetPipeline(y,t,r)),R(v,this._createEdgePipeline(y,t,r)),v.events.on(`immediate-click`,x),_.events.on(`immediate-click`,x),_.events.on(`focus-changed`,()=>this._resetTooltip()),_.events.on(`grab-changed`,({screenPoint:e,action:t})=>{y.grabMapPoint=t===`start`?k(e,this.view,this.object,y):null})],_),this._manipulatorInfos.push(y),this.manipulators.addMany([_,v]),this.events.emit(`manipulators-changed`),y}_autoHideEdgeOffsetManipulator(e,t){let n=e.manipulator,r=e.edgeManipulator,i=()=>{e.visibilityHandle=l(e.visibilityHandle);let i=this._getManipulatorInfoFromHandle(e.handle.leftVertex),s=this._getManipulatorInfoFromHandle(e.handle.rightVertex),c=i!=null&&s!=null&&Te(i.manipulator.renderLocation,s.manipulator.renderLocation,this.view.state.camera)<t;(!n.focused&&!r.focused||c)&&(n.grabbable=!c,r.grabbable=!c,e.visibilityHandle=o([n.disableDisplay(),a(()=>{n.grabbable=!0,r.grabbable=this.enableMoveObject})]))};this._manipulatorHandles.add([n.events.on(`focus-changed`,i),r.events.on(`focus-changed`,i),a(()=>{l(e.visibilityHandle),r.metadata.deleting=!0,this.manipulators.remove(r)})],n),i()}_updateEdgeOffsetManipulator(e){if(!this._operations)return;this._updateManipulatorPosition(e);let{coordinateHelper:t}=this._operations.data,n=A(this.view,e.manipulator.elevationAlignedLocation,j(t,e.handle,e.manipulator.elevationInfo)),r=this._getManipulatorInfoFromHandle(e.handle.leftVertex),i=this._getManipulatorInfoFromHandle(e.handle.rightVertex);if(r==null||i==null)return;let a=r.manipulator.renderLocation,o=i.manipulator.renderLocation,s=n==null?v:we(n,a,o);e.manipulator.modelTransform=s,e.edgeManipulator.elevationAlignedLocation=e.manipulator.elevationAlignedLocation,e.edgeManipulator.modelTransform=s;let c=y(b(Z,a,o))/2;e.edgeManipulator.collisionType={type:`line`,paths:[[[-c,0,0],[c,0,0]]]}}_createEdgePipeline(e,t,n){return(r,i,a,o)=>{if(o===`touch`)this._createEdgeOffsetPipeline(e,t,n)(r,i,a);else if(this.enableMoveObject){let e=this.object.graphic,o=n.data.spatialReference,{elevationAlignedLocation:s}=r;i.next(e=>this._trackNumDragging(e)).next(z(this.view,s)).next(E(this.view,s,t,o,e)).next(je()).next(L()).next(e=>this._perObjectManipulatorDragAction(0,e)).next(e=>(this._updateTranslateObjectTooltip(0,e),e)).next(e=>{e.action===`end`&&(this._showReshapeControls(),this._resetTooltip())}),a.next(()=>this._onDragCancel(!r.metadata.deleting))}}}_createEdgeOffsetPipeline(e,t,n){return(r,i,a)=>{let o=this._pendingEdgeOffsetInfo;if(o?.manipulatorInfo===e&&o.mode!==`drag`){a.execute({action:`cancel`});return}this._clearSelection();let{initializeStep:s,cleanup:c}=this._initializeEdgeOffset(e,t,n,a),l=this._applyEdgeOffsetStep(e);i.next(e=>this._trackNumDragging(e)).next(z(this.view,r.elevationAlignedLocation)).next(s).next(_e(this.view)).next(ve(this.view,n.data.spatialReference)).next(L()).next(Ie()).next(e=>this._pendingEdgeOffsetInfo?e:l(e)).next(e=>{e.action===`end`&&!this._pendingEdgeOffsetInfo&&c()}),a.next(()=>{this._exitEdgeOffsetInputMode(),r.metadata.deleting||(c(),this._onDragCancel())})}}_initializeEdgeOffset(e,t,n,r){let{view:i,object:a}=this,s=j(n.data.coordinateHelper,e.handle,t),c=n.createUndoGroup(),u=A(i,e.manipulator.elevationAlignedLocation,s);this._splitEdgesBeforeEdgeOffset(e,s),this._selectEdgeOffsetArrow(e,s);let d,f=()=>{this._cleanEdgeOffsetCollapsedEdges(e,n),d=l(d)},p=this.events.on(`undo`,f);return d=o([this._initializeEdgeOffsetVisualElement(e,a,t,n),c,p,this._connectEdgeOffsetTooltip(e,s,n,()=>{r.execute({action:`cancel`})})]),{initializeStep:e=>s==null||u==null?(f(),null):{...e,operation:s,plane:u},cleanup:f}}_initializeEdgeOffsetVisualElement(e,t,n,r){let i=()=>new se({paths:[[e.handle.leftVertex.pos,e.handle.rightVertex.pos]],spatialReference:r.data.spatialReference}),a=new N({view:this.view,isDraped:t.isDraped,geometry:i(),elevationInfo:n,width:this._settings.visualElements.lineObjects.outline.width,attached:!1,isDecoration:!0}),c=o([f(()=>({color:this._accentColor,draped:t.isDraped}),({color:e,draped:t})=>{a.color=e.toUnitRGBA(),a.isDraped=t},p),t.on(`committed`,()=>{a.geometry=i()}),s(a)]);return a.attached=!0,c}_applyEdgeOffsetStep(e){return t=>(this.destroyed||t.operation==null||!this._operations||(this._updateEventState(2),t.signedDistance==null?this._resetTooltip():((t.mapDeltaX||t.mapDeltaY||t.mapDeltaZ)&&(this._offsetEdge(e,t.operation,t.signedDistance),this.events.emit(`reshape`,{type:`reshape`,object:this.object})),this._updateEdgeOffsetTooltip(t))),t)}_cleanEdgeOffsetCollapsedEdges(e,t){let n=e.handle.leftVertex.leftSegment?.leftVertex,r=e.handle.leftVertex,i=e.handle.rightVertex.rightSegment?.rightVertex,a=e.handle.rightVertex,o=t.data.coordinateHelper,s=this.view.pixelSizeAt(o.vectorToDehydratedPoint(r.pos),o.spatialReference),c=[];if(n&&o.distance(n.pos,r.pos)<Le){let e=this._getManipulatorInfoFromHandle(r);e!=null&&c.push(e)}if(o.distance(r.pos,a.pos)<s||i&&o.distance(i.pos,a.pos)<Le){let e=this._getManipulatorInfoFromHandle(a);e!=null&&c.push(e)}c.length&&this._removeVertices(c)}_enterInputModeDuringEdgeOffset(e){let t=this._findActiveEdgeOffsetManipulatorInfo();return t&&H(e,this.tooltip)?t.manipulator.dragging?(this._pendingEdgeOffsetInfo={manipulatorInfo:t,mode:`drag`},!0):(this._clearSelection(),this._pendingEdgeOffsetInfo={manipulatorInfo:t,mode:`hover`},this._connectEdgeOffsetTooltipOnHover(t),!0):!1}_exitEdgeOffsetInputMode(){this.tooltip&&(this._pendingEdgeOffsetInfo=null,this._resetTooltip(),this.tooltip.exitInputMode())}_findActiveEdgeOffsetManipulatorInfo(){return this._manipulatorInfos.filter(Y).find(({manipulator:e})=>e.hovering||e.grabbing||e.dragging)}_connectEdgeOffsetTooltipOnHover(e){let{_operations:t,object:n}=this;if(!t)return;let{elevationInfo:r}=n,i=j(t.data.coordinateHelper,e.handle,r);this._selectEdgeOffsetArrow(e,i),this.addHandles([this._initializeEdgeOffsetVisualElement(e,n,r,t),this._connectEdgeOffsetTooltip(e,i,t,()=>{this.removeHandles(i),this._exitEdgeOffsetInputMode()})],i)}_splitEdgesBeforeEdgeOffset(e,t){if(t.requiresSplitEdgeLeft){let t=this._getManipulatorInfoFromHandle(e.handle.leftVertex.leftSegment);t!=null&&this._splitEdgeManipulator(t,1)}if(t.requiresSplitEdgeRight){let t=this._getManipulatorInfoFromHandle(e.handle.rightVertex.rightSegment);t!=null&&this._splitEdgeManipulator(t,0)}}_selectEdgeOffsetArrow(e,t){let n=e.grabMapPoint??k(this.view.inputManager?.latestPointerInfo?.location,this.view,this.object,e);n&&t.selectArrowFromStartPoint(n)}_connectEdgeOffsetTooltip(e,t,n,r){let i=()=>this.tooltipInfos.edgeOffset.distance.actual,a=i=>{r(),queueMicrotask(()=>{this.view.focus();let r=n.createUndoGroup();this._tooltipCallbacks.onReshapeStart?.(),this._splitEdgesBeforeEdgeOffset(e,t),this._offsetEdge(e,t,Ee(i,e.manipulator.location,t,n)),this._tooltipCallbacks.onReshape?.(),this._tooltipCallbacks.onReshapeStop?.(),this._cleanEdgeOffsetCollapsedEdges(e,n),r.remove()})},s=()=>{let e=i();e==null?r():a(e)};return o([m(()=>this.tooltip&&!this.tooltip.focused,()=>s(),h),this.tooltip.on(`discard`,r),this.tooltip.on(`commit`,e=>{e.type===`commit-and-exit`&&s()})])}_createVertexOrEdgeManipulator(e,t=this.object.elevationInfo,n=!1){let r=this.view,i=this._operations;if(!i)return null;let a=i.data.type,s=i.data.spatialReference;if(e.type===`line`){if(this.enableEdgeOffset)return this._createEdgeOffsetManipulator(e,t);if(!this.enableMidpoints)return null}if(this._vertexManipulatorGeometry==null||this._vertexManipulatorOutlineGeometry==null){let{material:e,outlineMaterial:t}=this._vertexManipulatorMaterials;this._vertexManipulatorGeometry=w(e),this._vertexManipulatorOutlineGeometry=w(t)}if(this._edgeManipulatorGeometry==null||this._edgeManipulatorOutlineGeometry==null){let{material:e,outlineMaterial:t}=this._edgeManipulatorMaterials;this._edgeManipulatorGeometry=w(e),this._edgeManipulatorOutlineGeometry=w(t)}let c=this._vertexManipulatorGeometry,u=this._vertexManipulatorOutlineGeometry,d=[];if(a!==`point`&&a!==`mesh`){d.push(new T(c.instantiate(),Q|4),new T(u.instantiate(),Q|5),new T(u.instantiate({material:this._vertexManipulatorMaterials.focusedMaterial}),Q|6));{let{material:e,outlineMaterial:t,focusedMaterial:n}=this._selectedManipulatorMaterials;d.push(new T(c.instantiate({material:e}),8),new T(u.instantiate({material:t}),9),new T(u.instantiate({material:n}),10))}}if(this.enableMidpoints){let{material:e,focusedMaterial:t}=this._vertexManipulatorMaterials,n=this._edgeManipulatorGeometry,r=this._edgeManipulatorOutlineGeometry,i=$|6,a=$|5;d.push(new T(n.instantiate({material:e}),i),new T(r.instantiate({material:t}),i),new T(n.instantiate(),a),new T(r.instantiate(),a))}let f=e.type===`vertex`,p=new S({view:r,renderObjects:d,elevationInfo:t,focusMultiplier:1,touchMultiplier:1,usePreciseLocalOrigin:a===`point`||a===`mesh`,available:this.object.visible,metadata:{deleting:!1},location:J(s),...me});p.selected=n,this._setTypeSpecificManipulatorSettings(p,e,t);let m=f?{manipulator:p,handle:e,type:`vertex`,selectedIndex:0}:{manipulator:p,handle:e,locationUpdateHandle:null,type:`edge`,selectedIndex:0};if(this._manipulatorInfos.push(m),this.manipulators.add(p),this._updateManipulatorPosition(m),m.type===`edge`){let e=[];for(let t of[m.handle.leftVertex,m.handle.rightVertex]){let n=this._getManipulatorInfoFromHandle(t);n!=null&&e.push(n.manipulator.events.on(`location-update`,()=>this._updateManipulatorPosition(m)))}m.locationUpdateHandle=o(e),this._manipulatorHandles.add(m.locationUpdateHandle,p)}this._manipulatorHandles.add(this._watchAndUpdateGrabState(p,!0),p);let h=R(p,(e,n,a,o)=>{let c=null,{snappingStep:u,cancelSnapping:d}=V({predicate:()=>!this._isMultiVertexSelection(),snappingManager:this.tool.snappingManager,snappingContext:new B({editGeometryOperations:i,elevationInfo:t,pointer:o,excludeFeature:this.object.graphic,visualizer:new ge}),updatingHandles:this._updatingHandles,useZ:this.tool.snapToScene});a.next(t=>(this._onDragCancel(!e.metadata.deleting,()=>c=l(c)),t)).next(d);let{elevationAlignedLocation:f}=e,p=this.object.graphic??void 0,h=this.tool.snapToScene?this._screenToSceneMapForVertexDrag(t,i,p):E(r,f,t,s,p);n.next(e=>this._trackNumDragging(e)).next(e=>{if(e.action===`start`&&i&&(c=i.createUndoGroup()),m.type===`edge`){let t=this._splitEdgeManipulator(m);return{...e,info:t,snapOrigin:t.handle.pos}}return{...e,info:m,snapOrigin:m.handle.pos}}).next(z(r,f)).next(h).next(I(r,t,p)).next(...u).next(L()).next(e=>{this._perVertexManipulatorDragAction(e),e.action===`end`&&(c=l(c)),this._resetTooltip()})});return this._manipulatorHandles.add([h,p.events.on(`immediate-click`,e=>this._manipulatorClickCallback(e,m)),p.events.on(`select-changed`,()=>{m.selectedIndex=++this._selectedIndex,this._updateMoveManipulationPosition(),this._resetTooltip()}),p.events.on(`focus-changed`,()=>{this._resetTooltip()})],p),this.events.emit(`manipulators-changed`),m}_screenToSceneMapForVertexDrag(e,t,n){let{view:r}=this,{coordinateHelper:i,spatialReference:a}=t.data,o=null;return t=>{if(t.action===`start`&&(o=i.vectorToPoint(t.snapOrigin)),o==null)return null;let s=r.toMap(t.screenEnd,{exclude:n,excludeLabels:!0});return s==null||(s.z=de(s,r,e),!ce(s,s,a))?null:{...t,mapStart:o,mapEnd:s}}}_trackNumDragging(e){switch(e.action){case`start`:this._numDragging++;break;case`end`:this._numDragging--}return e}_onDragCancel(e=!0,t){switch(this._numDragging--,e&&this.undo(),this.tool.snappingManager?.doneSnapping(),this._showReshapeControls(),this._resetTooltip(),this._reshapeEventState){case 0:break;case 1:this.events.emit(`move`,{type:`move`,dx:0,dy:0,object:this.object});break;case 2:this.events.emit(`reshape`,{type:`reshape`,object:this.object})}t?.(),!this.destroyed&&this._updateEventState(0)}_setTypeSpecificManipulatorSettings(e,t,n){let r=this._settings;switch(t.type){case`vertex`:{e.selectable=!0,e.cursor=`move`,e.collisionPriority=2,e.elevationInfo=n;let t=this._operations?.data.type;e.interactive=t!=null&&t!==`point`&&t!==`mesh`;let{size:i,collisionPadding:a}=r.manipulators.vertex;e.radius=i/2+a,e.state=Q;break}case`line`:{e.state=$,e.selectable=!1,e.cursor=`copy`,e.collisionPriority=2;let{size:t,collisionPadding:i}=r.manipulators.edge;e.radius=t/2+i,e.elevationInfo=n.mode===`on-the-ground`&&!fe(this.object.graphic?.symbol)?n:{mode:`absolute-height`,offset:0};break}}}_watchAndUpdateGrabState(e,t){return e.events.on(`grab-changed`,n=>{this._onGrabStateChanged(e,t,n.action,n.pointerType)})}_onGrabStateChanged(e,t,n,r=`mouse`){if(!this._recreatingManipulators){if(n===`start`)t&&this._updateSelection(e),this._numGrabbing++,this._shouldHideReshapeControlsOnGrab(e)&&this._hideReshapeControls(),this._hideManipulatorsForEdgeOffset(e);else if(this._numGrabbing--,this.removeHandles(W),this._updateEventState(0),this._canShowReshapeControls&&this._showReshapeControls(),this.destroyed)return;this._moveManipulation.interactive=!this._numGrabbing,(r!==`touch`||this.enableEdgeOffset)&&(this._manipulatorInfos.forEach(e=>{let{manipulator:t}=e,n=this._operations?.data.type;t.interactive=t.grabbing||!this._numGrabbing&&n!=null&&n!==`point`&&n!==`mesh`,Y(e)&&(e.edgeManipulator.interactive=e.edgeManipulator.grabbing||!this._numGrabbing)}),this._objectMoveManipulation.forEachManipulator(e=>{e.interactive=e.grabbing||!this._numGrabbing}))}}_clearSelection(){for(let e of this._manipulatorInfos)e.manipulator.grabbing||(e.manipulator.selected=!1);this._pendingEdgeOffsetInfo=null}_updateSelection(e){e.grabbing&&!e.selected&&e.selectable&&(this._clearSelection(),e.selected=!0,this.events.emit(`manipulators-changed`))}_removeManipulator(e){e!=null&&(e.manipulator.metadata.deleting=!0,this.manipulators.remove(e.manipulator),this._manipulatorHandles.remove(e.manipulator),n(this._manipulatorInfos,e),this.events.emit(`manipulators-changed`),this._resetTooltip())}_getManipulatorInfoFromHandle(e){return this._manipulatorInfos.find(t=>t.handle===e)}_updateManipulatorPositions(e){if(!this._movingManipulatorsHidden)for(let t of e)this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(t))}_updateManipulatorPosition(e){let t=this._operations;if(e!=null&&t){if(e.type===`vertex`)e.manipulator.location=t.data.coordinateHelper.vectorToDehydratedPoint(e.handle.pos,X),e.manipulator.grabbing&&this._vertexLaserLineVisualElement!=null&&(this._vertexLaserLineVisualElement.visualElement.intersectsWorldUpAtLocation=e.manipulator.renderLocation);else if(e.type===`edge`){let n=this._getManipulatorInfoFromHandle(e.handle.leftVertex),r=this._getManipulatorInfoFromHandle(e.handle.rightVertex);if(n==null||r==null)return;let i=n.manipulator,a=r.manipulator;if(e.manipulator.elevationInfo?.mode===`on-the-ground`){let n=i.location,r=a.location,o=.5,s=n.x+o*(r.x-n.x),c=n.y+o*(r.y-n.y),l=n.hasZ&&r.hasZ?0:void 0;e.manipulator.location=ue(s,c,l,t.data.spatialReference)}else x(Z,i.renderLocation,a.renderLocation,.5),e.manipulator.renderLocation=Z}}}_splitEdgeManipulator(e,t=.5){let n=this._operations,r=n.splitSegment(e.handle,t).createdVertex;e.locationUpdateHandle=l(e.locationUpdateHandle);let i=this.object.elevationInfo,a;this.enableEdgeOffset?(this._removeManipulator(e),a=this._createVertexOrEdgeManipulator(r)):(a=e,a.handle=r,a.type=`vertex`,this._setTypeSpecificManipulatorSettings(e.manipulator,e.handle,i)),r.leftSegment?.type===`line`&&this._createVertexOrEdgeManipulator(r.leftSegment),r.rightSegment?.type===`line`&&this._createVertexOrEdgeManipulator(r.rightSegment),this._updateManipulatorPosition(a),this.enableEdgeOffset||this._resetTooltip(),this._updateSelection(e.manipulator);let o=this._updateEventState(2),s=n.data.coordinateHelper.vectorToArray(a.handle.pos),c=n.data.parts.indexOf(r.part);return this.events.emit(`vertex-add`,{type:`vertex-add`,object:this.object,vertices:[{coordinates:s,componentIndex:c,vertexIndex:r.index}],added:s}),o&&this._updateEventState(0),a}_updateMoveManipulationPosition(){let e=ee(Z,0,0,0),t=0,n=!1,r=null,i=null;for(let a of this._manipulatorInfos)a.type===`vertex`&&(a.manipulator.selected?(t++,te(e,e,a.manipulator.renderLocation),r==null||a.selectedIndex>r.selectedIndex?(i=r,r=a):(i==null||a.selectedIndex>i.selectedIndex)&&(i=a)):n=!0);let a=this.object,o=this._operations?.data.geometry;if(t===0){let e=a.visible&&this.enableMoveObject;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e,this._moveManipulation.zManipulation.available=e&&this.enableZShape&&D(this._operations,a.elevationInfo),this._moveManipulation.angle=ye(o),this._moveManipulation.radius=O.radiusForSymbol(a.graphic?.symbol)}else{let e=a.visible;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.zManipulation.available=e&&this.enableZVertex&&D(this._operations,this.object.elevationInfo),this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e&&t!==1;let n=0;if(r!=null){let e=r.handle.pos,t=i==null?r.handle.leftSegment?.leftVertex?r.handle.leftSegment.leftVertex.pos:null:i.handle.pos,a=i==null&&r.handle.rightSegment?.rightVertex?r.handle.rightSegment.rightVertex.pos:null;t&&a?this._moveManipulation.xyAxisManipulation.available=!1:t?n=q(t,e):a&&(n=q(e,a))}this._moveManipulation.angle=n,this._moveManipulation.radius=Se}t!==0&&n?(ne(e,e,1/t),X.spatialReference=this._operations.data.spatialReference,X.hasZ=!0,this.view.renderCoordsHelper.fromRenderCoords(e,X),this._moveManipulation.elevationAlignedLocation=X):this._outlineVisualElement!=null&&!this.object.isDraped&&this._outlineVisualElement.attachmentOrigin!=null?this._moveManipulation.elevationAlignedLocation=this._outlineVisualElement.attachmentOrigin:pe(this._moveManipulation,this.object)}_removeVertices(e){let t=[],n=this._operations;if(!n)return;let r=e.filter(e=>e.type===`vertex`&&n.canRemoveVertex(e.handle.part));if(r.length>0){let e=this._createBeforeVertexRemoveEvent(r);if(this.events.emit(`before-vertex-remove`,e),e.defaultPrevented)return}for(let e of r){let r=e.handle.part;if(n.canRemoveVertex(r)){t.push(e.handle),this._removeManipulator(e),this._removeManipulator(this._getManipulatorInfoFromHandle(e.handle.leftSegment)),this._removeManipulator(this._getManipulatorInfoFromHandle(e.handle.rightSegment));let i=n.removeVertices([e.handle]).removedVertices?.[0].createdSegment;i&&i.type===`line`?this._createVertexOrEdgeManipulator(i):this.enableEdgeOffset&&r.vertices.length<=2&&this._removeManipulator(this._getManipulatorInfoFromHandle(r.segments[0]))}}if(t.length>0){let e=t.map(e=>{let t=n.data.parts.indexOf(e.part);return{coordinates:n.data.coordinateHelper.vectorToArray(e.pos),componentIndex:t,vertexIndex:e.index}}),r=this._updateEventState(2);if(this.destroyed||(this.events.emit(`vertex-remove`,{type:`vertex-remove`,object:this.object,removed:e.map(e=>e.coordinates),vertices:e}),this.destroyed)||r&&(this._updateEventState(0),this.destroyed))return;this._updateMoveManipulationPosition()}}_createBeforeVertexRemoveEvent(e){let t=this._operations,n=e.map(e=>{let n=t.data.parts.indexOf(e.handle.part);return{coordinates:t.data.coordinateHelper.vectorToArray(e.handle.pos),componentIndex:n,vertexIndex:e.handle.index}}),r=!1;return{type:`before-vertex-remove`,object:this.object,removed:n.map(e=>e.coordinates),vertices:n,get defaultPrevented(){return r},preventDefault(){r=!0}}}_moveVertices(e,t,n=t.action===`start`?0:1){let r=this._operations;if(r&&(e.length>0&&r.moveVertices(e.map(e=>e.handle),t.mapDeltaX,t.mapDeltaY,t.mapDeltaZ,n),!this._movingManipulatorsHidden))for(let t of e)this._updateManipulatorPosition(t)}_offsetEdge(e,t,n){if(!this._operations)return;let r=t.clone();r.distance=n,this._operations.updateVertices([e.handle.leftVertex,e.handle.rightVertex],r),this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.leftVertex)),this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.rightVertex))}_manipulatorClickCallback(e,t){e.shiftKey||this._clearSelection(),t.type===`vertex`&&(t.manipulator.selected=!t.manipulator.selected,this.enableDeleteVertices&&e.button===F.Right&&this._removeVertices([t])),t.type===`edge`&&e.button===F.Left&&this._splitEdgeManipulator(t),e.stopPropagation()}_updateTranslateTooltip(e,t){this._defaultTooltipInfo==null?this._updateTranslateObjectTooltip(e,t):this._resetTooltip()}_updateTranslateObjectTooltip(e,t){this._pendingEdgeOffsetInfo||(this.activeTooltipInfo=ke(e,t,this._tooltipsContext,this._updatingHandles))}_updateEdgeOffsetTooltip(e){this._pendingEdgeOffsetInfo||(this.activeTooltipInfo=M(this.object,e,this._tooltipsContext,this._updatingHandles))}_resetTooltip(){let e=this.activeTooltipInfo;if(this._pendingEdgeOffsetInfo&&e?.type===`reshape-edge-offset`)return;let t=null;t=this._pendingEdgeOffsetInfo||this._findActiveEdgeOffsetManipulatorInfo()!=null?M(this.object,null,this._tooltipsContext,this._updatingHandles):this._defaultTooltipInfo,t!==e&&(e==null||t==null||this.tooltip.mode!==`input`)&&(this.activeTooltipInfo=t)}get _defaultTooltipInfo(){switch(this._operations?.data.type){case`polyline`:case`polygon`:return this._selectedVertexManipulatorInfo?this.tooltipInfos.selectedVertex:null;case`point`:case`mesh`:return this.tooltipInfos.movePoint;default:return null}}get _selectedVertexManipulatorInfo(){let e=this._manipulatorInfos.filter(e=>e.type===`vertex`&&e.manipulator.selected);return e.length===1?e[0]:null}get _someVerticesSelected(){return this._manipulatorInfos.some(e=>e.type===`vertex`&&e.manipulator.selected)}_forEachVertex(e){for(let t of this._manipulatorInfos)t.type===`vertex`&&e(t)}get _tooltipsContext(){let{tooltipInfos:e,activeTooltipInfo:t}=this;return{toolOptions:this._toolOptions,tooltipInfos:e,activeTooltipInfo:t,selectedVertexManipulatorInfo:this._selectedVertexManipulatorInfo,callbacks:this._tooltipCallbacks,measurementWorker:this._measurementWorker}}get test(){}};e([g()],K.prototype,`_numGrabbing`,void 0),e([g()],K.prototype,`_numDragging`,void 0),e([g()],K.prototype,`_pendingEdgeOffsetInfo`,void 0),e([g()],K.prototype,`_operations`,null),e([g()],K.prototype,`_segmentLabels`,void 0),e([g({constructOnly:!0})],K.prototype,`tool`,void 0),e([g()],K.prototype,`tooltip`,void 0),e([g()],K.prototype,`activeTooltipInfo`,void 0),e([g({readOnly:!0})],K.prototype,`updating`,null),e([g()],K.prototype,`manipulators`,null),e([g()],K.prototype,`view`,null),e([g()],K.prototype,`object`,null),e([g()],K.prototype,`enableZShape`,null),e([g()],K.prototype,`enableDeleteVertices`,null),e([g()],K.prototype,`enableZVertex`,null),e([g()],K.prototype,`autoHideManipulators`,null),e([g()],K.prototype,`enableMoveObject`,null),e([g()],K.prototype,`enableMidpoints`,null),e([g()],K.prototype,`enableEdgeOffset`,null),e([g()],K.prototype,`_toolOptions`,null),e([g()],K.prototype,`_accentColor`,null),e([g()],K.prototype,`_tooltipsContext`,null),K=e([_(`esri.views.3d.interactive.editingTools.reshape.ReshapeOperation`)],K);function Ie(){return e=>{let{operation:t,mapEnd:n}=e;return t==null||n==null?e:{...e,signedDistance:t.signedDistanceToPoint(n)}}}function q(e,t){return Math.atan2(t[1]-e[1],t[0]-e[0])+Math.PI/2}function J(e){return new oe({x:0,y:0,z:0,spatialReference:e})}function Y(e){return e.type===`edge`&&`edgeManipulator`in e}const X=ue(0,0,void 0,le.WGS84),Z=ie(),Le=1e-6,Q=16,$=32;export{K as ReshapeOperation};
2
+ import{__decorate as e}from"tslib";import t from"../../../../../core/Accessor.js";import{removeUnordered as n}from"../../../../../core/arrayUtils.js";import{EventEmitter as r}from"../../../../../core/Evented.js";import i from"../../../../../core/Handles.js";import{makeHandle as a,handlesGroup as o,destroyHandle as s}from"../../../../../core/handleUtils.js";import"../../../../../core/has.js";import{destroyMaybe as c,removeMaybe as l}from"../../../../../core/maybe.js";import{initial as u,on as d,watch as f,syncAndInitial as p,when as m,sync as h}from"../../../../../core/reactiveUtils.js";import{property as g,subclass as _}from"../../../../../core/accessorSupport/decorators.js";import{IDENTITY as v}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{length as y,subtract as b,lerp as x,set as ee,add as te,scale as ne}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as re,create as ie}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{UpdatingHandles as ae}from"../../../../../core/support/UpdatingHandles.js";import oe from"../../../../../geometry/Point.js";import se from"../../../../../geometry/Polyline.js";import{projectPoint as ce}from"../../../../../geometry/projectionUtils.js";import le from"../../../../../geometry/SpatialReference.js";import{makeDehydratedPoint as ue}from"../../../../../layers/graphics/dehydratedPoint.js";import{getZForElevationMode as de}from"../../../../../support/elevationInfoUtils.js";import{isVolumetricSymbol as fe}from"../../../../../symbols/support/utils.js";import{Manipulator3D as S}from"../../Manipulator3D.js";import{createManipulatorMaterials as C,createSphereGeometryAsOffsets as w,placeAtObject as pe,screenSizeManipulatorSettings as me}from"../../manipulatorUtils.js";import{RenderObject as T}from"../../RenderObject.js";import{SegmentLabels3D as he}from"../../SegmentLabels3D.js";import{SnappingVisualizer3D as ge}from"../../SnappingVisualizer3D.js";import{screenToMapXYAtLocation as E,screenToRenderPlaneFromEvent as _e,convertToMapCoordinates as ve}from"../dragEventPipeline3D.js";import{orientation as ye}from"../geometryUtils.js";import{canMoveZOperations as D}from"../manipulatorUtils.js";import{Settings as be}from"../settings.js";import{createVisualElements as xe}from"../visualElementUtils.js";import{discRadiusSmall as Se}from"../manipulations/config.js";import{MoveManipulation as O}from"../manipulations/MoveManipulation.js";import{MoveXYObjectManipulation as Ce}from"../manipulations/MoveXYObjectManipulation.js";import{getMapPointAtEdgeOffsetManipulatorElevation as k,createEdgeOffsetIntersectionPlane as A,createEdgeOffsetOperation as j,edgeOffsetRotationMatrix as we,screenEdgeLengthSquared as Te,getDistanceInGeometrySR as Ee}from"./edgeOffsetUtils.js";import{createTooltipInfos as De,connectTooltipToManipulatedObject as Oe,getUpdatedTranslateObjectTooltipInfo as ke,getUpdatedEdgeOffsetTooltipInfo as M}from"./reshapeTooltipUtils3D.js";import{OutlineVisualElement as N}from"../../visualElements/OutlineVisualElement.js";import{createElevationUpdateHandle as Ae}from"../../../support/elevationUpdateUtils.js";import{createExtrudedTriangle as P}from"../../../webgl-engine/lib/GeometryUtil.js";import{mouseButtons as F}from"../../../../input/mouseButtons.js";import{sceneSnappingAtLocation as I,addMapDelta as L,createManipulatorDragEventPipeline as R,dragAtLocation as z,addScreenDelta as je}from"../../../../interactive/dragEventPipeline.js";import{tooltipKeys as Me}from"../../../../interactive/keybindings.js";import{SnappingContext as B}from"../../../../interactive/snapping/SnappingContext.js";import{createSnapDragEventPipelineStep as V}from"../../../../interactive/snapping/SnappingDragPipelineStep.js";import{makeTooltip as Ne,enterInputModeIfAvailable as H}from"../../../../interactive/tooltip/tooltipCommonUtils.js";import{GeometryWorkerHandle as Pe}from"../../../../support/GeometryWorkerHandle.js";const U=Symbol(),W=Symbol(),Fe=Symbol(),G=Symbol();let K=class extends t{get _movingManipulatorsHidden(){return this.hasHandles(G)}get _operations(){return this.object.operations}constructor(e){super(e),this._selectedIndex=0,this._manipulatorHandles=new i,this._manipulatorInfos=[],this._numGrabbing=0,this._numDragging=0,this._reshapeEventState=0,this._pendingEdgeOffsetInfo=null,this._updatingHandles=new ae,this._recreatingManipulators=!1,this._settings=new be({getTheme:()=>this.view.effectiveTheme}),this.events=new r,this.activeTooltipInfo=null,this._measurementWorker=new Pe({preloadGeodetic:!0}),this._vertexLaserLineVisualElement=null,this._tooltipCallbacks={onBeforeReshape:()=>this.tool.endDrag(),onReshapeStart:()=>this._updateEventState(2),onReshape:()=>this.events.emit(`reshape`,{type:`reshape`,object:this.object}),onReshapeStop:()=>this._updateEventState(0,{forceEnd:!0}),onMoveStart:()=>this._updateEventState(1),onMove:()=>this.events.emit(`move`,{type:`move`,object:this.object,dx:0,dy:0}),onMoveStop:()=>this._updateEventState(0,{forceEnd:!0})}}initialize(){let{view:e}=this,t=this._settings.manipulators,n=t.vertex;this.tooltipInfos=De(this._toolOptions,e),this._vertexManipulatorMaterials=C({color:n.color.toUnitRGBA(),outlineColor:n.outlineColor.toUnitRGBA(),focusedOutlineColor:n.focusedOutlineColor.toUnitRGBA(),screenSize:n,renderOccluded:n.renderOccluded});let r=t.edge;this._edgeManipulatorMaterials=C({color:r.color.toUnitRGBA(),outlineColor:r.outlineColor.toUnitRGBA(),screenSize:r,renderOccluded:r.renderOccluded});let i=t.edgeOffset;this._edgeOffsetManipulatorMaterials=C({color:i.color.toUnitRGBA(),focusedColor:i.focusedColor.toUnitRGBA(),renderOccluded:i.renderOccluded,shaded:!1});let a=t.selected;this._selectedManipulatorMaterials=C({color:a.color.toUnitRGBA(),outlineColor:a.outlineColor.toUnitRGBA(),focusedOutlineColor:a.focusedOutlineColor.toUnitRGBA(),screenSize:a,renderOccluded:a.renderOccluded}),this.tooltip=Ne(()=>({view:e,options:this._toolOptions.tooltips})),this.addHandles([this._updatingHandles.add(()=>{let e=this._settings.manipulators;return{vertexSettings:e.vertex,edgeSettings:e.edge,edgeOffsetSettings:e.edgeOffset,selectedSettings:e.selected}},({vertexSettings:e,edgeSettings:t,edgeOffsetSettings:n,selectedSettings:r})=>{e.applyColor(this._vertexManipulatorMaterials.material),e.applyOutline(this._vertexManipulatorMaterials.outlineMaterial),e.applyFocusedOutline(this._vertexManipulatorMaterials.focusedMaterial),t.applyColor(this._edgeManipulatorMaterials.material),t.applyOutline(this._edgeManipulatorMaterials.outlineMaterial),n.applyColor(this._edgeOffsetManipulatorMaterials.material),n.applyFocused(this._edgeOffsetManipulatorMaterials.focusedMaterial),r.applyColor(this._selectedManipulatorMaterials.material),r.applyOutline(this._selectedManipulatorMaterials.outlineMaterial),r.applyFocusedOutline(this._selectedManipulatorMaterials.focusedMaterial)}),this._updatingHandles.add(()=>this.object.visible,e=>{for(let t of this._manipulatorInfos)t.manipulator.available=e,Y(t)&&(t.edgeManipulator.available=e)}),this._updatingHandles.add(()=>this._numGrabbing+this._numDragging===0,e=>this._toggleAutoHideManipulators(e)),this._updatingHandles.add(()=>({labels:this._segmentLabels,enabled:this._toolOptions.labels.enabled,edgeOffsetEnabled:this.enableEdgeOffset}),({labels:e,enabled:t,edgeOffsetEnabled:n})=>{e!=null&&(e.visible=t,e.edgeDistance=n?`far`:`default`)},u),Oe(this.tooltip,this.object,()=>this._tooltipsContext,this._updatingHandles),this._updatingHandles.add(()=>this.tooltip.mode,(e,t)=>{t===`input`&&e!==`input`&&this._resetTooltip()}),d(()=>this._operations,`vertex-update`,e=>this._updateManipulatorPositions(e.vertices),{onListenerAdd:()=>this._recreateManipulators()}),d(()=>this._operations?.data,`change`,e=>{(e.operation===`undo`||e.operation===`redo`)&&this._recreateManipulators()})])}destroy(){this._removeManipulators(),this._updatingHandles.destroy(),this._segmentLabels=c(this._segmentLabels),this.tooltip=c(this.tooltip),this._measurementWorker.destroy()}get updating(){return this._updatingHandles.updating||!!this._segmentLabels?.updating}get manipulators(){return this.tool.manipulators}get view(){return this.tool.view}get object(){return this.tool.object}get enableZShape(){return this.tool.enableZShape}get enableDeleteVertices(){return this.tool.enableDeleteVertices}get enableZVertex(){return this.tool.enableZVertex}get autoHideManipulators(){return this.tool.autoHideManipulators}get enableMoveObject(){return this.tool.enableMoveObject}get enableMidpoints(){return this.tool.enableMidpoints}get enableEdgeOffset(){return this.tool.enableEdgeOffset}get _toolOptions(){return this.tool.toolOptions}get _accentColor(){return this.view.effectiveTheme.accentColor}enterInputModeIfAvailable(e){return e.type!==`key-down`||e.key!==Me.enterInputMode?!1:this.activeTooltipInfo?.type===`reshape-edge-offset`?this._enterInputModeDuringEdgeOffset(e):H(e,this.tooltip)?(this.tool.endDrag(),!0):!1}removeSelectedVertices(){let e=this._manipulatorInfos.filter(e=>e.manipulator.selected&&e.type===`vertex`);return this._removeVertices(e),e.length}onManipulatorSelectionChanged(){this.events.emit(`manipulators-changed`)}_removeManipulators(){this._manipulatorHandles.removeAll(),this.removeHandles(W),this.removeHandles(G),this._moveManipulation=c(this._moveManipulation),this._objectMoveManipulation=c(this._objectMoveManipulation),this.manipulators.removeAll(),this._manipulatorInfos=[],this._numGrabbing=0,this._numDragging=0}_createManipulators(e){if(this._operations==null)return;let t=this.object.elevationInfo;for(let{vertices:n,segments:r,index:i}of this._operations.data.parts){let a=e?.byPartIndex.get(i);for(let e of n){let n=a?.has(e.index);this._createVertexOrEdgeManipulator(e,t,n)}for(let e of r)e.type===`line`&&this._createVertexOrEdgeManipulator(e,t)}this._createObjectMoveManipulation(),this._createMoveManipulation(t),this._createVisualElements()}recordUndo(e){this._operations?.recordUndo(e,!0)}get canRedo(){return this._operations?.canRedo??!1}get canUndo(){return this._operations?.canUndo??!1}redo(){return this._operations?.redo()}undo(){return this.events.emit(`undo`),this._operations?.undo()}_recreateManipulators(){if(!this._recreatingManipulators){if(this._recreatingManipulators=!0,this._removeManipulators(),this._resetTooltip(),this._operations&&this._segmentLabels?.context?.editGeometryOperations===this._operations||(this._segmentLabels=c(this._segmentLabels)),this._createManipulators(),!this._segmentLabels&&this._operations){let e=this._toolOptions.labels;this._segmentLabels=new he({context:{view:this.view,editGeometryOperations:this._operations,elevationInfo:this.object.elevationInfo,labelOptions:e},visible:e.enabled})}this._recreatingManipulators=!1}}_perObjectManipulatorDragAction(e,t){if(t.action===`end`)return t;let n=0,r=[],i=e===1&&this._someVerticesSelected;for(let e of this._manipulatorInfos)e.type===`vertex`&&(e.manipulator.grabbing||i&&!e.manipulator.selected||r.push(e),n++);if(r.length===n){if(i||this._hideReshapeControls(),this._moveVertices(r,t),this._updateEventState(1),this.destroyed)return t;this.events.emit(`move`,{type:`move`,dx:t.screenDeltaX,dy:t.screenDeltaY,object:this.object})}else{if(this._moveVertices(r,t),this._updateEventState(2),this.destroyed)return t;this.events.emit(`reshape`,{type:`reshape`,object:this.object})}return t}_hideReshapeControls(){this._movingManipulatorsHidden||this.addHandles([this._hideReshapeManipulators(),this._moveManipulation.hideManipulatorsExceptGrabbedGroup(),a(()=>this._forEachVertex(e=>this._updateManipulatorPosition(e)))],G)}_showReshapeControls(){this.removeHandles(G)}_shouldHideReshapeControlsOnGrab(e){return this._objectMoveManipulation.hasManipulator(e)||this._moveManipulation.hasManipulator(e)&&!this._someVerticesSelected}get _canShowReshapeControls(){return!this._objectMoveManipulation.grabbing&&(!this._moveManipulation.grabbing||this._someVerticesSelected)}_hideManipulatorsForEdgeOffset(e){let t=this._manipulatorInfos.filter(Y).find(t=>t.manipulator===e||t.edgeManipulator===e);t!=null&&(this.removeHandles(W),this.addHandles([this._moveManipulation.hideManipulators(),this._hideReshapeManipulators(t)],W))}_hideReshapeManipulators(e){return o(this._manipulatorInfos.flatMap(t=>t===e?null:[t.manipulator.disableDisplay(),Y(t)?t.edgeManipulator.disableDisplay():null]))}_toggleAutoHideManipulators(e){this.autoHideManipulators&&(e?this.removeHandles(U):this.tool.manipulators.forEach(({manipulator:e})=>{let t=e.disableDisplay?.();t&&this.addHandles(t,U)}))}_isMultiVertexSelection(){return this._manipulatorInfos.reduce((e,t)=>t.type===`vertex`&&t.manipulator.selected?e+1:e,0)>1}_perVertexManipulatorDragAction(e){if(this._updateEventState(2),this.destroyed)return;let{mapDeltaX:t,mapDeltaY:n,mapDeltaZ:r}=e;if(!t&&!n&&!r)return;let i=[];this._forEachVertex(t=>{let{selected:n,grabbing:r}=t.manipulator;(n&&!r||t===e.info)&&i.push(t)}),this._moveVertices(i,e,1),this.events.emit(`reshape`,{type:`reshape`,object:this.object})}_updateEventState(e,t={}){if(e===this._reshapeEventState)return!1;switch(e){case 0:if(!t.forceEnd&&(this._numGrabbing!==0||this._numDragging!==0))return!1;switch(this._reshapeEventState){case 1:this._showReshapeControls(),this.events.emit(`move`,{type:`move-stop`,dx:0,dy:0,object:this.object});break;case 2:this.events.emit(`reshape`,{type:`reshape-stop`,object:this.object})}break;case 1:switch(this._reshapeEventState){case 0:this.events.emit(`move`,{type:`move-start`,dx:0,dy:0,object:this.object});break;case 2:this.events.emit(`reshape`,{type:`reshape-stop`,object:this.object}),this.destroyed||this.events.emit(`move`,{type:`move-start`,dx:0,dy:0,object:this.object})}break;case 2:switch(this._reshapeEventState){case 0:this.events.emit(`reshape`,{type:`reshape-start`,object:this.object});break;case 1:this._showReshapeControls(),this.events.emit(`move`,{type:`move-stop`,dx:0,dy:0,object:this.object}),this.destroyed||this.events.emit(`reshape`,{type:`reshape-start`,object:this.object})}}if(this.destroyed)return!1;let n=this._reshapeEventState!==e;return this._reshapeEventState=e,n}_createObjectMoveManipulation(){let{tool:e,view:t,object:n,_operations:r}=this;if(r){if(this._objectMoveManipulation=new Ce({tool:e,view:t,object:n}),this.enableMoveObject){let e=null;this._manipulatorHandles.add(this._objectMoveManipulation.createDragPipeline((t,n,i)=>{n.next(e=>this._trackNumDragging(e)).next(t=>(t.action===`start`&&(e=r.createUndoGroup()),t)).next(e=>this._perObjectManipulatorDragAction(0,e)).next(e=>(this._updateTranslateObjectTooltip(0,e),e)).next(t=>{t.action===`end`&&(this._showReshapeControls(),this._resetTooltip(),e=l(e))}),i.next(()=>this._onDragCancel(!0,()=>e=l(e)))})),this._objectMoveManipulation.forEachManipulator(e=>this._manipulatorHandles.add(this._watchAndUpdateGrabState(e,!1)))}else this._objectMoveManipulation.forEachManipulator(e=>{e.grabbable=!1,e.cursor=null});this._objectMoveManipulation.forEachManipulator(e=>this._manipulatorHandles.add(e.events.on(`immediate-click`,e=>{this._manipulatorInfos.some(e=>e.manipulator.selected)?this._clearSelection():this.events.emit(`immediate-click`,{...e,object:this.object}),e.stopPropagation()})))}}_createMoveManipulation(e){let{object:t,tool:n,view:r,_operations:i}=this;if(!i)return;this._moveManipulation=new O({tool:n,view:r,xyAvailable:!0,xyAxisAvailable:!0,zAvailable:this.enableZShape&&D(t.operations,t.elevationInfo),snapToScene:!1,radius:O.radiusForSymbol(t.graphic?.symbol)}),this._moveManipulation.forEachManipulator(e=>this.addHandles([e.events.on(`immediate-click`,t=>{!this._moveManipulation.zManipulation.hasManipulator(e)&&!this._manipulatorInfos.some(e=>e.manipulator.selected)&&this.events.emit(`immediate-click`,{...t,object:this.object}),t.stopPropagation()}),this._watchAndUpdateGrabState(e,!1)]));let a=e=>t=>{this.addHandles([t.events.on(`focus-changed`,({action:t})=>{t===`focus`?this._updateTranslateTooltip(e):this._resetTooltip()})])};this._moveManipulation.xyManipulation.forEachManipulator(a(0)),this._moveManipulation.xyAxisManipulation.forEachManipulator(a(1)),this._moveManipulation.zManipulation.forEachManipulator(a(2)),this._moveManipulation.elevationInfo={mode:`absolute-height`,offset:0};let o=i.data.spatialReference;this.addHandles([this._moveManipulation.createDragPipeline((r,a,o,s,c)=>{let{snappingStep:l,cancelSnapping:u}=V({predicate:e=>!!e.info,snappingManager:n.snappingManager,snappingContext:new B({editGeometryOperations:i,elevationInfo:e,pointer:c,excludeFeature:t.graphic,visualizer:new ge}),updatingHandles:this._updatingHandles,useZ:!1});return s=s.next(e=>(this._onDragCancel(),e)).next(u),o=o.next(e=>this._trackNumDragging(e)).next(e=>{let t=this._manipulatorInfos.filter(e=>e.type===`vertex`&&e.manipulator.selected);return e.manipulatorType===1&&t.length===1?{...e,info:t[0],snapOrigin:t[0].handle.pos}:e}).next(I(this.view,e,t.graphic??void 0)).next(...l).next(L()).next(e=>this._perObjectManipulatorDragAction(1,e)).next(e=>(e.action===`end`&&this._showReshapeControls(),this._updateTranslateTooltip(r,e),e)),{steps:o,cancel:s}},e,o,t.graphic),this._updatingHandles.add(()=>t.visible,()=>this._updateMoveManipulationPosition(),u),t.on(`committed`,()=>{this._recreatingManipulators||this._updateMoveManipulationPosition()}),this._updatingHandles.add(()=>t.isDraped,e=>{this._updateMoveManipulationPosition(),this.removeHandles(Fe),e&&this.addHandles(Ae({view:this.view,geometry:()=>t.graphic?.geometry,elevationInfo:t.elevationInfo,onElevationChanges:()=>this._updateMoveManipulationPosition()}),Fe)},u)])}_createVisualElements(){let{object:e,view:t}=this,n=xe({view:t,object:e,forEachManipulator:e=>{if(!(this.destroyed||this._recreatingManipulators)){this._objectMoveManipulation.forEachManipulator(e),this._moveManipulation.forEachManipulator(e);for(let t of this._manipulatorInfos)e(t.manipulator,1)}},onManipulatorsChanged:e=>this.events.on(`manipulators-changed`,e)});n!=null&&(this._outlineVisualElement=n.visualElement instanceof N?n.visualElement:null);let r=this._outlineVisualElement;if(r!=null){let t=()=>{e.isDraped||this._updateMoveManipulationPosition()};this._manipulatorHandles.add(d(()=>r.events,`attachment-origin-changed`,t,{onListenerAdd:t}))}this._manipulatorHandles.add(n)}_createEdgeOffsetManipulator(e,t=this.object.elevationInfo){let n=this.view,r=this._operations;if(e.part.vertices.length<=2||!r)return null;let i=r.data.spatialReference,a=this._settings.manipulators.edgeOffset,s=a.size/2,c=s+a.collisionPadding,l=s/c,u=l/2,d=l*Math.sqrt(3)/2,{height:f,offset:p}=a,{material:m,focusedMaterial:h}=this._edgeOffsetManipulatorMaterials;if(!this._edgeOffsetManipulatorGeometryInside){let e=P(m,d,u,u,f,p);this._edgeOffsetManipulatorGeometryInside=e}if(!this._edgeOffsetManipulatorGeometryOutside){let e=P(m,-d,u,u,f,-p);this._edgeOffsetManipulatorGeometryOutside=e}let g=[new T(this._edgeOffsetManipulatorGeometryInside.instantiate(),1),new T(this._edgeOffsetManipulatorGeometryInside.instantiate({material:h}),2),new T(this._edgeOffsetManipulatorGeometryOutside.instantiate(),1),new T(this._edgeOffsetManipulatorGeometryOutside.instantiate({material:h}),2)],_=new S({view:n,renderObjects:g,elevationInfo:t.mode===`on-the-ground`&&!fe(this.object.graphic?.symbol)?t:{mode:`absolute-height`,offset:0},worldOriented:!1,focusMultiplier:1,radius:c,available:this.object.visible,collisionType:{type:`disc`,direction:re(0,0,1)},collisionPriority:1,metadata:{deleting:!1},location:J(i)}),v=new S({view:n,worldSized:!0,worldOriented:!1,available:this.object.visible,collisionPriority:-10,cursor:this.enableMoveObject?`move`:`default`,metadata:{deleting:!1},location:J(i)}),y={manipulator:_,handle:e,locationUpdateHandle:null,type:`edge`,selectedIndex:0,edgeManipulator:v,visibilityHandle:null};this._autoHideEdgeOffsetManipulator(y,a.minSquaredEdgeLength);let b=()=>this._updateEdgeOffsetManipulator(y);b(),y.locationUpdateHandle=o([e.leftVertex,e.rightVertex].map(e=>this._getManipulatorInfoFromHandle(e)?.manipulator.events.on(`location-update`,b)));let x=e=>{this._manipulatorInfos.some(e=>e.manipulator.selected)?this._clearSelection():this.events.emit(`immediate-click`,{...e,object:this.object}),e.stopPropagation()};return this._manipulatorHandles.add([y.locationUpdateHandle,this._watchAndUpdateGrabState(_,!0),this._watchAndUpdateGrabState(v,!0),R(_,this._createEdgeOffsetPipeline(y,t,r)),R(v,this._createEdgePipeline(y,t,r)),v.events.on(`immediate-click`,x),_.events.on(`immediate-click`,x),_.events.on(`focus-changed`,()=>this._resetTooltip()),_.events.on(`grab-changed`,({screenPoint:e,action:t})=>{y.grabMapPoint=t===`start`?k(e,this.view,this.object,y):null})],_),this._manipulatorInfos.push(y),this.manipulators.addMany([_,v]),this.events.emit(`manipulators-changed`),y}_autoHideEdgeOffsetManipulator(e,t){let n=e.manipulator,r=e.edgeManipulator,i=()=>{e.visibilityHandle=l(e.visibilityHandle);let i=this._getManipulatorInfoFromHandle(e.handle.leftVertex),s=this._getManipulatorInfoFromHandle(e.handle.rightVertex),c=i!=null&&s!=null&&Te(i.manipulator.renderLocation,s.manipulator.renderLocation,this.view.state.camera)<t;(!n.focused&&!r.focused||c)&&(n.grabbable=!c,r.grabbable=!c,e.visibilityHandle=o([n.disableDisplay(),a(()=>{n.grabbable=!0,r.grabbable=this.enableMoveObject})]))};this._manipulatorHandles.add([n.events.on(`focus-changed`,i),r.events.on(`focus-changed`,i),a(()=>{l(e.visibilityHandle),r.metadata.deleting=!0,this.manipulators.remove(r)})],n),i()}_updateEdgeOffsetManipulator(e){if(!this._operations)return;this._updateManipulatorPosition(e);let{coordinateHelper:t}=this._operations.data,n=A(this.view,e.manipulator.elevationAlignedLocation,j(t,e.handle,e.manipulator.elevationInfo)),r=this._getManipulatorInfoFromHandle(e.handle.leftVertex),i=this._getManipulatorInfoFromHandle(e.handle.rightVertex);if(r==null||i==null)return;let a=r.manipulator.renderLocation,o=i.manipulator.renderLocation,s=n==null?v:we(n,a,o);e.manipulator.modelTransform=s,e.edgeManipulator.elevationAlignedLocation=e.manipulator.elevationAlignedLocation,e.edgeManipulator.modelTransform=s;let c=y(b(Z,a,o))/2;e.edgeManipulator.collisionType={type:`line`,paths:[[[-c,0,0],[c,0,0]]]}}_createEdgePipeline(e,t,n){return(r,i,a,o)=>{if(o===`touch`)this._createEdgeOffsetPipeline(e,t,n)(r,i,a);else if(this.enableMoveObject){let e=this.object.graphic,o=n.data.spatialReference,{elevationAlignedLocation:s}=r;i.next(e=>this._trackNumDragging(e)).next(z(this.view,s)).next(E(this.view,s,t,o,e)).next(je()).next(L()).next(e=>this._perObjectManipulatorDragAction(0,e)).next(e=>(this._updateTranslateObjectTooltip(0,e),e)).next(e=>{e.action===`end`&&(this._showReshapeControls(),this._resetTooltip())}),a.next(()=>this._onDragCancel(!r.metadata.deleting))}}}_createEdgeOffsetPipeline(e,t,n){return(r,i,a)=>{let o=this._pendingEdgeOffsetInfo;if(o?.manipulatorInfo===e&&o.mode!==`drag`){a.execute({action:`cancel`});return}this._clearSelection();let{initializeStep:s,cleanup:c}=this._initializeEdgeOffset(e,t,n,a),l=this._applyEdgeOffsetStep(e);i.next(e=>this._trackNumDragging(e)).next(z(this.view,r.elevationAlignedLocation)).next(s).next(_e(this.view)).next(ve(this.view,n.data.spatialReference)).next(L()).next(Ie()).next(e=>this._pendingEdgeOffsetInfo?e:l(e)).next(e=>{e.action===`end`&&!this._pendingEdgeOffsetInfo&&c()}),a.next(()=>{this._exitEdgeOffsetInputMode(),r.metadata.deleting||(c(),this._onDragCancel())})}}_initializeEdgeOffset(e,t,n,r){let{view:i,object:a}=this,s=j(n.data.coordinateHelper,e.handle,t),c=n.createUndoGroup(),u=A(i,e.manipulator.elevationAlignedLocation,s);this._splitEdgesBeforeEdgeOffset(e,s),this._selectEdgeOffsetArrow(e,s);let d,f=()=>{this._cleanEdgeOffsetCollapsedEdges(e,n),d=l(d)},p=this.events.on(`undo`,f);return d=o([this._initializeEdgeOffsetVisualElement(e,a,t,n),c,p,this._connectEdgeOffsetTooltip(e,s,n,()=>{r.execute({action:`cancel`})})]),{initializeStep:e=>s==null||u==null?(f(),null):{...e,operation:s,plane:u},cleanup:f}}_initializeEdgeOffsetVisualElement(e,t,n,r){let i=()=>new se({paths:[[e.handle.leftVertex.pos,e.handle.rightVertex.pos]],spatialReference:r.data.spatialReference}),a=new N({view:this.view,isDraped:t.isDraped,geometry:i(),elevationInfo:n,width:this._settings.visualElements.lineObjects.outline.width,attached:!1,isDecoration:!0}),c=o([f(()=>({color:this._accentColor,draped:t.isDraped}),({color:e,draped:t})=>{a.color=e.toUnitRGBA(),a.isDraped=t},p),t.on(`committed`,()=>{a.geometry=i()}),s(a)]);return a.attached=!0,c}_applyEdgeOffsetStep(e){return t=>(this.destroyed||t.operation==null||!this._operations||(this._updateEventState(2),t.signedDistance==null?this._resetTooltip():((t.mapDeltaX||t.mapDeltaY||t.mapDeltaZ)&&(this._offsetEdge(e,t.operation,t.signedDistance),this.events.emit(`reshape`,{type:`reshape`,object:this.object})),this._updateEdgeOffsetTooltip(t))),t)}_cleanEdgeOffsetCollapsedEdges(e,t){let n=e.handle.leftVertex.leftSegment?.leftVertex,r=e.handle.leftVertex,i=e.handle.rightVertex.rightSegment?.rightVertex,a=e.handle.rightVertex,o=t.data.coordinateHelper,s=this.view.pixelSizeAt(o.vectorToDehydratedPoint(r.pos),o.spatialReference),c=[];if(n&&o.distance(n.pos,r.pos)<Le){let e=this._getManipulatorInfoFromHandle(r);e!=null&&c.push(e)}if(o.distance(r.pos,a.pos)<s||i&&o.distance(i.pos,a.pos)<Le){let e=this._getManipulatorInfoFromHandle(a);e!=null&&c.push(e)}c.length&&this._removeVertices(c)}_enterInputModeDuringEdgeOffset(e){let t=this._findActiveEdgeOffsetManipulatorInfo();return t&&H(e,this.tooltip)?t.manipulator.dragging?(this._pendingEdgeOffsetInfo={manipulatorInfo:t,mode:`drag`},!0):(this._clearSelection(),this._pendingEdgeOffsetInfo={manipulatorInfo:t,mode:`hover`},this._connectEdgeOffsetTooltipOnHover(t),!0):!1}_exitEdgeOffsetInputMode(){this.tooltip&&(this._pendingEdgeOffsetInfo=null,this._resetTooltip(),this.tooltip.exitInputMode())}_findActiveEdgeOffsetManipulatorInfo(){return this._manipulatorInfos.filter(Y).find(({manipulator:e})=>e.hovering||e.grabbing||e.dragging)}_connectEdgeOffsetTooltipOnHover(e){let{_operations:t,object:n}=this;if(!t)return;let{elevationInfo:r}=n,i=j(t.data.coordinateHelper,e.handle,r);this._selectEdgeOffsetArrow(e,i),this.addHandles([this._initializeEdgeOffsetVisualElement(e,n,r,t),this._connectEdgeOffsetTooltip(e,i,t,()=>{this.removeHandles(i),this._exitEdgeOffsetInputMode()})],i)}_splitEdgesBeforeEdgeOffset(e,t){if(t.requiresSplitEdgeLeft){let t=this._getManipulatorInfoFromHandle(e.handle.leftVertex.leftSegment);t!=null&&this._splitEdgeManipulator(t,1)}if(t.requiresSplitEdgeRight){let t=this._getManipulatorInfoFromHandle(e.handle.rightVertex.rightSegment);t!=null&&this._splitEdgeManipulator(t,0)}}_selectEdgeOffsetArrow(e,t){let n=e.grabMapPoint??k(this.view.inputManager?.latestPointerInfo?.location,this.view,this.object,e);n&&t.selectArrowFromStartPoint(n)}_connectEdgeOffsetTooltip(e,t,n,r){let i=()=>this.tooltipInfos.edgeOffset.distance.actual,a=i=>{r(),queueMicrotask(()=>{this.view.focus();let r=n.createUndoGroup();this._tooltipCallbacks.onReshapeStart?.(),this._splitEdgesBeforeEdgeOffset(e,t),this._offsetEdge(e,t,Ee(i,e.manipulator.location,t,n)),this._tooltipCallbacks.onReshape?.(),this._tooltipCallbacks.onReshapeStop?.(),this._cleanEdgeOffsetCollapsedEdges(e,n),r.remove()})},s=()=>{let e=i();e==null?r():a(e)};return o([m(()=>this.tooltip&&!this.tooltip.focused,()=>s(),h),this.tooltip.on(`discard`,r),this.tooltip.on(`commit`,e=>{e.type===`commit-and-exit`&&s()})])}_createVertexOrEdgeManipulator(e,t=this.object.elevationInfo,n=!1){let r=this.view,i=this._operations;if(!i)return null;let a=i.data.type,s=i.data.spatialReference;if(e.type===`line`){if(this.enableEdgeOffset)return this._createEdgeOffsetManipulator(e,t);if(!this.enableMidpoints)return null}if(this._vertexManipulatorGeometry==null||this._vertexManipulatorOutlineGeometry==null){let{material:e,outlineMaterial:t}=this._vertexManipulatorMaterials;this._vertexManipulatorGeometry=w(e),this._vertexManipulatorOutlineGeometry=w(t)}if(this._edgeManipulatorGeometry==null||this._edgeManipulatorOutlineGeometry==null){let{material:e,outlineMaterial:t}=this._edgeManipulatorMaterials;this._edgeManipulatorGeometry=w(e),this._edgeManipulatorOutlineGeometry=w(t)}let c=this._vertexManipulatorGeometry,u=this._vertexManipulatorOutlineGeometry,d=[];if(a!==`point`&&a!==`mesh`){d.push(new T(c.instantiate(),Q|4),new T(u.instantiate(),Q|5),new T(u.instantiate({material:this._vertexManipulatorMaterials.focusedMaterial}),Q|6));{let{material:e,outlineMaterial:t,focusedMaterial:n}=this._selectedManipulatorMaterials;d.push(new T(c.instantiate({material:e}),8),new T(u.instantiate({material:t}),9),new T(u.instantiate({material:n}),10))}}if(this.enableMidpoints){let{material:e,focusedMaterial:t}=this._vertexManipulatorMaterials,n=this._edgeManipulatorGeometry,r=this._edgeManipulatorOutlineGeometry,i=$|6,a=$|5;d.push(new T(n.instantiate({material:e}),i),new T(r.instantiate({material:t}),i),new T(n.instantiate(),a),new T(r.instantiate(),a))}let f=e.type===`vertex`,p=new S({view:r,renderObjects:d,elevationInfo:t,focusMultiplier:1,touchMultiplier:1,usePreciseLocalOrigin:a===`point`||a===`mesh`,available:this.object.visible,metadata:{deleting:!1},location:J(s),...me});p.selected=n,this._setTypeSpecificManipulatorSettings(p,e,t);let m=f?{manipulator:p,handle:e,type:`vertex`,selectedIndex:0}:{manipulator:p,handle:e,locationUpdateHandle:null,type:`edge`,selectedIndex:0};if(this._manipulatorInfos.push(m),this.manipulators.add(p),this._updateManipulatorPosition(m),m.type===`edge`){let e=[];for(let t of[m.handle.leftVertex,m.handle.rightVertex]){let n=this._getManipulatorInfoFromHandle(t);n!=null&&e.push(n.manipulator.events.on(`location-update`,()=>this._updateManipulatorPosition(m)))}m.locationUpdateHandle=o(e),this._manipulatorHandles.add(m.locationUpdateHandle,p)}this._manipulatorHandles.add(this._watchAndUpdateGrabState(p,!0),p);let h=R(p,(e,n,a,o)=>{let c=null,{snappingStep:u,cancelSnapping:d}=V({predicate:()=>!this._isMultiVertexSelection(),snappingManager:this.tool.snappingManager,snappingContext:new B({editGeometryOperations:i,elevationInfo:t,pointer:o,excludeFeature:this.object.graphic,visualizer:new ge}),updatingHandles:this._updatingHandles,useZ:this.tool.snapToScene});a.next(t=>(this._onDragCancel(!e.metadata.deleting,()=>c=l(c)),t)).next(d);let{elevationAlignedLocation:f}=e,p=this.object.graphic??void 0,h=this.tool.snapToScene?this._screenToSceneMapForVertexDrag(t,i,p):E(r,f,t,s,p);n.next(e=>this._trackNumDragging(e)).next(e=>{if(e.action===`start`&&i&&(c=i.createUndoGroup()),m.type===`edge`){let t=this._splitEdgeManipulator(m);return{...e,info:t,snapOrigin:t.handle.pos}}return{...e,info:m,snapOrigin:m.handle.pos}}).next(z(r,f)).next(h).next(I(r,t,p)).next(...u).next(L()).next(e=>{this._perVertexManipulatorDragAction(e),e.action===`end`&&(c=l(c)),this._resetTooltip()})});return this._manipulatorHandles.add([h,p.events.on(`immediate-click`,e=>this._manipulatorClickCallback(e,m)),p.events.on(`select-changed`,()=>{m.selectedIndex=++this._selectedIndex,this._updateMoveManipulationPosition(),this._resetTooltip()}),p.events.on(`focus-changed`,()=>{this._resetTooltip()})],p),this.events.emit(`manipulators-changed`),m}_screenToSceneMapForVertexDrag(e,t,n){let{view:r}=this,{coordinateHelper:i,spatialReference:a}=t.data,o=null;return t=>{if(t.action===`start`&&(o=i.vectorToPoint(t.snapOrigin)),o==null)return null;let s=r.toMap(t.screenEnd,{exclude:n,excludeLabels:!0});return s==null||(s.z=de(s,r,e),!ce(s,s,a))?null:{...t,mapStart:o,mapEnd:s}}}_trackNumDragging(e){switch(e.action){case`start`:this._numDragging++;break;case`end`:this._numDragging--}return e}_onDragCancel(e=!0,t){switch(this._numDragging--,e&&this.undo(),this.tool.snappingManager?.doneSnapping(),this._showReshapeControls(),this._resetTooltip(),this._reshapeEventState){case 0:break;case 1:this.events.emit(`move`,{type:`move`,dx:0,dy:0,object:this.object});break;case 2:this.events.emit(`reshape`,{type:`reshape`,object:this.object})}t?.(),this.destroyed||this._updateEventState(0)}_setTypeSpecificManipulatorSettings(e,t,n){let r=this._settings;switch(t.type){case`vertex`:{e.selectable=!0,e.cursor=`move`,e.collisionPriority=2,e.elevationInfo=n;let t=this._operations?.data.type;e.interactive=t!=null&&t!==`point`&&t!==`mesh`;let{size:i,collisionPadding:a}=r.manipulators.vertex;e.radius=i/2+a,e.state=Q;break}case`line`:{e.state=$,e.selectable=!1,e.cursor=`copy`,e.collisionPriority=2;let{size:t,collisionPadding:i}=r.manipulators.edge;e.radius=t/2+i,e.elevationInfo=n.mode===`on-the-ground`&&!fe(this.object.graphic?.symbol)?n:{mode:`absolute-height`,offset:0};break}}}_watchAndUpdateGrabState(e,t){return e.events.on(`grab-changed`,n=>{this._onGrabStateChanged(e,t,n.action,n.pointerType)})}_onGrabStateChanged(e,t,n,r=`mouse`){if(!this._recreatingManipulators){if(n===`start`)t&&this._updateSelection(e),this._numGrabbing++,this._shouldHideReshapeControlsOnGrab(e)&&this._hideReshapeControls(),this._hideManipulatorsForEdgeOffset(e);else if(this._numGrabbing--,this.removeHandles(W),this._updateEventState(0),this._canShowReshapeControls&&this._showReshapeControls(),this.destroyed)return;this._moveManipulation.interactive=!this._numGrabbing,(r!==`touch`||this.enableEdgeOffset)&&(this._manipulatorInfos.forEach(e=>{let{manipulator:t}=e,n=this._operations?.data.type;t.interactive=t.grabbing||!this._numGrabbing&&n!=null&&n!==`point`&&n!==`mesh`,Y(e)&&(e.edgeManipulator.interactive=e.edgeManipulator.grabbing||!this._numGrabbing)}),this._objectMoveManipulation.forEachManipulator(e=>{e.interactive=e.grabbing||!this._numGrabbing}))}}_clearSelection(){for(let e of this._manipulatorInfos)e.manipulator.grabbing||(e.manipulator.selected=!1);this._pendingEdgeOffsetInfo=null}_updateSelection(e){e.grabbing&&!e.selected&&e.selectable&&(this._clearSelection(),e.selected=!0,this.events.emit(`manipulators-changed`))}_removeManipulator(e){e!=null&&(e.manipulator.metadata.deleting=!0,this.manipulators.remove(e.manipulator),this._manipulatorHandles.remove(e.manipulator),n(this._manipulatorInfos,e),this.events.emit(`manipulators-changed`),this._resetTooltip())}_getManipulatorInfoFromHandle(e){return this._manipulatorInfos.find(t=>t.handle===e)}_updateManipulatorPositions(e){if(!this._movingManipulatorsHidden)for(let t of e)this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(t))}_updateManipulatorPosition(e){let t=this._operations;if(e!=null&&t){if(e.type===`vertex`)e.manipulator.location=t.data.coordinateHelper.vectorToDehydratedPoint(e.handle.pos,X),e.manipulator.grabbing&&this._vertexLaserLineVisualElement!=null&&(this._vertexLaserLineVisualElement.visualElement.intersectsWorldUpAtLocation=e.manipulator.renderLocation);else if(e.type===`edge`){let n=this._getManipulatorInfoFromHandle(e.handle.leftVertex),r=this._getManipulatorInfoFromHandle(e.handle.rightVertex);if(n==null||r==null)return;let i=n.manipulator,a=r.manipulator;if(e.manipulator.elevationInfo?.mode===`on-the-ground`){let n=i.location,r=a.location,o=.5,s=n.x+o*(r.x-n.x),c=n.y+o*(r.y-n.y),l=n.hasZ&&r.hasZ?0:void 0;e.manipulator.location=ue(s,c,l,t.data.spatialReference)}else x(Z,i.renderLocation,a.renderLocation,.5),e.manipulator.renderLocation=Z}}}_splitEdgeManipulator(e,t=.5){let n=this._operations,r=n.splitSegment(e.handle,t).createdVertex;e.locationUpdateHandle=l(e.locationUpdateHandle);let i=this.object.elevationInfo,a;this.enableEdgeOffset?(this._removeManipulator(e),a=this._createVertexOrEdgeManipulator(r)):(a=e,a.handle=r,a.type=`vertex`,this._setTypeSpecificManipulatorSettings(e.manipulator,e.handle,i)),r.leftSegment?.type===`line`&&this._createVertexOrEdgeManipulator(r.leftSegment),r.rightSegment?.type===`line`&&this._createVertexOrEdgeManipulator(r.rightSegment),this._updateManipulatorPosition(a),this.enableEdgeOffset||this._resetTooltip(),this._updateSelection(e.manipulator);let o=this._updateEventState(2),s=n.data.coordinateHelper.vectorToArray(a.handle.pos),c=n.data.parts.indexOf(r.part);return this.events.emit(`vertex-add`,{type:`vertex-add`,object:this.object,vertices:[{coordinates:s,componentIndex:c,vertexIndex:r.index}],added:s}),o&&this._updateEventState(0),a}_updateMoveManipulationPosition(){let e=ee(Z,0,0,0),t=0,n=!1,r=null,i=null;for(let a of this._manipulatorInfos)a.type===`vertex`&&(a.manipulator.selected?(t++,te(e,e,a.manipulator.renderLocation),r==null||a.selectedIndex>r.selectedIndex?(i=r,r=a):(i==null||a.selectedIndex>i.selectedIndex)&&(i=a)):n=!0);let a=this.object,o=this._operations?.data.geometry;if(t===0){let e=a.visible&&this.enableMoveObject;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e,this._moveManipulation.zManipulation.available=e&&this.enableZShape&&D(this._operations,a.elevationInfo),this._moveManipulation.angle=ye(o),this._moveManipulation.radius=O.radiusForSymbol(a.graphic?.symbol)}else{let e=a.visible;this._moveManipulation.xyManipulation.available=e,this._moveManipulation.xyAxisManipulation.available=e,this._moveManipulation.zManipulation.available=e&&this.enableZVertex&&D(this._operations,this.object.elevationInfo),this._moveManipulation.xyAxisManipulation.orthogonalAvailable=e&&t!==1;let n=0;if(r!=null){let e=r.handle.pos,t=i==null?r.handle.leftSegment?.leftVertex?r.handle.leftSegment.leftVertex.pos:null:i.handle.pos,a=i==null&&r.handle.rightSegment?.rightVertex?r.handle.rightSegment.rightVertex.pos:null;t&&a?this._moveManipulation.xyAxisManipulation.available=!1:t?n=q(t,e):a&&(n=q(e,a))}this._moveManipulation.angle=n,this._moveManipulation.radius=Se}t!==0&&n?(ne(e,e,1/t),X.spatialReference=this._operations.data.spatialReference,X.hasZ=!0,this.view.renderCoordsHelper.fromRenderCoords(e,X),this._moveManipulation.elevationAlignedLocation=X):this._outlineVisualElement!=null&&!this.object.isDraped&&this._outlineVisualElement.attachmentOrigin!=null?this._moveManipulation.elevationAlignedLocation=this._outlineVisualElement.attachmentOrigin:pe(this._moveManipulation,this.object)}_removeVertices(e){let t=[],n=this._operations;if(!n)return;let r=e.filter(e=>e.type===`vertex`&&n.canRemoveVertex(e.handle.part));if(r.length>0){let e=this._createBeforeVertexRemoveEvent(r);if(this.events.emit(`before-vertex-remove`,e),e.defaultPrevented)return}for(let e of r){let r=e.handle.part;if(n.canRemoveVertex(r)){t.push(e.handle),this._removeManipulator(e),this._removeManipulator(this._getManipulatorInfoFromHandle(e.handle.leftSegment)),this._removeManipulator(this._getManipulatorInfoFromHandle(e.handle.rightSegment));let i=n.removeVertices([e.handle]).removedVertices?.[0].createdSegment;i&&i.type===`line`?this._createVertexOrEdgeManipulator(i):this.enableEdgeOffset&&r.vertices.length<=2&&this._removeManipulator(this._getManipulatorInfoFromHandle(r.segments[0]))}}if(t.length>0){let e=t.map(e=>{let t=n.data.parts.indexOf(e.part);return{coordinates:n.data.coordinateHelper.vectorToArray(e.pos),componentIndex:t,vertexIndex:e.index}}),r=this._updateEventState(2);if(this.destroyed||(this.events.emit(`vertex-remove`,{type:`vertex-remove`,object:this.object,removed:e.map(e=>e.coordinates),vertices:e}),this.destroyed)||r&&(this._updateEventState(0),this.destroyed))return;this._updateMoveManipulationPosition()}}_createBeforeVertexRemoveEvent(e){let t=this._operations,n=e.map(e=>{let n=t.data.parts.indexOf(e.handle.part);return{coordinates:t.data.coordinateHelper.vectorToArray(e.handle.pos),componentIndex:n,vertexIndex:e.handle.index}}),r=!1;return{type:`before-vertex-remove`,object:this.object,removed:n.map(e=>e.coordinates),vertices:n,get defaultPrevented(){return r},preventDefault(){r=!0}}}_moveVertices(e,t,n=t.action===`start`?0:1){let r=this._operations;if(r&&(e.length>0&&r.moveVertices(e.map(e=>e.handle),t.mapDeltaX,t.mapDeltaY,t.mapDeltaZ,n),!this._movingManipulatorsHidden))for(let t of e)this._updateManipulatorPosition(t)}_offsetEdge(e,t,n){if(!this._operations)return;let r=t.clone();r.distance=n,this._operations.updateVertices([e.handle.leftVertex,e.handle.rightVertex],r),this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.leftVertex)),this._updateManipulatorPosition(this._getManipulatorInfoFromHandle(e.handle.rightVertex))}_manipulatorClickCallback(e,t){e.shiftKey||this._clearSelection(),t.type===`vertex`&&(t.manipulator.selected=!t.manipulator.selected,this.enableDeleteVertices&&e.button===F.Right&&this._removeVertices([t])),t.type===`edge`&&e.button===F.Left&&this._splitEdgeManipulator(t),e.stopPropagation()}_updateTranslateTooltip(e,t){this._defaultTooltipInfo==null?this._updateTranslateObjectTooltip(e,t):this._resetTooltip()}_updateTranslateObjectTooltip(e,t){this._pendingEdgeOffsetInfo||(this.activeTooltipInfo=ke(e,t,this._tooltipsContext,this._updatingHandles))}_updateEdgeOffsetTooltip(e){this._pendingEdgeOffsetInfo||(this.activeTooltipInfo=M(this.object,e,this._tooltipsContext,this._updatingHandles))}_resetTooltip(){let e=this.activeTooltipInfo;if(this._pendingEdgeOffsetInfo&&e?.type===`reshape-edge-offset`)return;let t=null;t=this._pendingEdgeOffsetInfo||this._findActiveEdgeOffsetManipulatorInfo()!=null?M(this.object,null,this._tooltipsContext,this._updatingHandles):this._defaultTooltipInfo,t!==e&&(e==null||t==null||this.tooltip.mode!==`input`)&&(this.activeTooltipInfo=t)}get _defaultTooltipInfo(){switch(this._operations?.data.type){case`polyline`:case`polygon`:return this._selectedVertexManipulatorInfo?this.tooltipInfos.selectedVertex:null;case`point`:case`mesh`:return this.tooltipInfos.movePoint;default:return null}}get _selectedVertexManipulatorInfo(){let e=this._manipulatorInfos.filter(e=>e.type===`vertex`&&e.manipulator.selected);return e.length===1?e[0]:null}get _someVerticesSelected(){return this._manipulatorInfos.some(e=>e.type===`vertex`&&e.manipulator.selected)}_forEachVertex(e){for(let t of this._manipulatorInfos)t.type===`vertex`&&e(t)}get _tooltipsContext(){let{tooltipInfos:e,activeTooltipInfo:t}=this;return{toolOptions:this._toolOptions,tooltipInfos:e,activeTooltipInfo:t,selectedVertexManipulatorInfo:this._selectedVertexManipulatorInfo,callbacks:this._tooltipCallbacks,measurementWorker:this._measurementWorker}}get test(){}};e([g()],K.prototype,`_numGrabbing`,void 0),e([g()],K.prototype,`_numDragging`,void 0),e([g()],K.prototype,`_pendingEdgeOffsetInfo`,void 0),e([g()],K.prototype,`_operations`,null),e([g()],K.prototype,`_segmentLabels`,void 0),e([g({constructOnly:!0})],K.prototype,`tool`,void 0),e([g()],K.prototype,`tooltip`,void 0),e([g()],K.prototype,`activeTooltipInfo`,void 0),e([g({readOnly:!0})],K.prototype,`updating`,null),e([g()],K.prototype,`manipulators`,null),e([g()],K.prototype,`view`,null),e([g()],K.prototype,`object`,null),e([g()],K.prototype,`enableZShape`,null),e([g()],K.prototype,`enableDeleteVertices`,null),e([g()],K.prototype,`enableZVertex`,null),e([g()],K.prototype,`autoHideManipulators`,null),e([g()],K.prototype,`enableMoveObject`,null),e([g()],K.prototype,`enableMidpoints`,null),e([g()],K.prototype,`enableEdgeOffset`,null),e([g()],K.prototype,`_toolOptions`,null),e([g()],K.prototype,`_accentColor`,null),e([g()],K.prototype,`_tooltipsContext`,null),K=e([_(`esri.views.3d.interactive.editingTools.reshape.ReshapeOperation`)],K);function Ie(){return e=>{let{operation:t,mapEnd:n}=e;return t==null||n==null?e:{...e,signedDistance:t.signedDistanceToPoint(n)}}}function q(e,t){return Math.atan2(t[1]-e[1],t[0]-e[0])+Math.PI/2}function J(e){return new oe({x:0,y:0,z:0,spatialReference:e})}function Y(e){return e.type===`edge`&&`edgeManipulator`in e}const X=ue(0,0,void 0,le.WGS84),Z=ie(),Le=1e-6,Q=16,$=32;export{K as ReshapeOperation};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import has from"../../../core/has.js";import t from"../../../core/Logger.js";import{abortMaybe as n,destroyMaybe as r,removeMaybe as i}from"../../../core/maybe.js";import{throwIfAborted as a,createAbortError as o}from"../../../core/promiseUtils.js";import{initial as s,whenOnce as c,watch as l,when as u}from"../../../core/reactiveUtils.js";import{schedule as d}from"../../../core/scheduling.js";import{isUint8Array as f,isFloat32Array as p,isUint32Array as m,isUint16Array as h}from"../../../core/typedArrayUtil.js";import{unitFromRESTJSON as g,convertUnit as _}from"../../../core/units.js";import{property as v,subclass as y}from"../../../core/accessorSupport/decorators.js";import{fromMat4 as b,invert as x}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as S,IDENTITY as C}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as T}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{normalize as E,sub as D,dot as O,set as k}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as A,freeze as j,clone as ee,ZEROS as te,fromValues as ne}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as re,clone as ie,ONES as ae}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isMoon as oe,isMars as se,getReferenceEllipsoid as M,SphericalECEFSpatialReferenceLike as ce}from"../../../geometry/ellipsoidUtils.js";import le from"../../../geometry/HeightModelInfo.js";import{computeTranslationToOriginAndRotation as ue}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{localLinearScaleFactors as de}from"../../../geometry/projection/localLinearScaleFactors.js";import{projectVectorToVector as fe}from"../../../geometry/projection/projectVectorToVector.js";import{create as pe}from"../../../geometry/support/aaBoundingRect.js";import{isCompatible as me}from"../../../geometry/support/heightModelInfoUtils.js";import{isInEffectiveScaleRange as he,validateScaleRange as N}from"../../../geometry/support/scaleUtils.js";import{isPlateCarree as P,isWebMercator as F,equals as I,isGeographic as L,isCGCS2000 as R}from"../../../geometry/support/spatialReferenceUtils.js";import z from"../../../geometry/support/WKIDUnitConversion.js";import{BufferViewVec4u8 as ge,BufferViewVec3u8 as _e,BufferViewVec2f as ve,BufferViewVec3f as B,BufferViewUint32 as V,BufferViewUint16 as H}from"../../../geometry/support/buffer/BufferView.js";import{nullId as U}from"../../../layers/ILyr3DWasmPerSceneView.js";import ye from"../../../layers/support/SceneModification.js";import{getHeightModelInfoFromVCS as be,validateEntity3D as xe,makeCacheKey as W}from"../../../layers/support/tiles3DUtils.js";import{getElevationOffsetInMeters as G}from"../../../support/elevationInfoUtils.js";import{IntegratedMesh3DTilesLayerWorkerHandle as Se}from"./IntegratedMesh3DTilesLayerWorkerHandle.js";import{LayerView3D as Ce}from"./LayerView3D.js";import{Lyr3DViewPerformanceInfo as we}from"./Lyr3DViewPerformanceInfo.js";import{addLayerViewToWasm as Te,removeLayerViewFromWasm as Ee,getLyr3DWasm as De}from"./Lyr3DWasm.js";import{toWasmModification as Oe}from"./SceneLayerWorkerHandle.js";import{LayerElevationProvider as ke}from"./i3s/LayerElevationProvider.js";import{IntegratedMesh3DTilesLayerView3DSymbol as Ae}from"./support/integratedMesh3DTilesLayerViewInstanceUtils.js";import{primTypeConversion as je,alphaModeConversion as Me,faceCullingConversion as Ne,wrapModeConversion as Pe}from"./support/lyr3dTypeConversions.js";import{makeScheduleFunction as Fe}from"./support/makeScheduleFunction.js";import{Tiles3DMeshIntersectionHandler as Ie}from"./support/Tiles3DMeshIntersectionHandler.js";import{Frustum as Le}from"../state/Frustum.js";import{ElevationRange as K}from"../support/ElevationRange.js";import{toBoundingRect as Re}from"../support/extentUtils.js";import{Obb as ze}from"../support/orientedBoundingBox.js";import{glLayout as Be}from"../support/buffer/glUtil.js";import{getGroundTransparencyModeFromOpacity as Ve}from"../terrain/TransparencyMode.js";import{ComponentGeometryParameters as He,SourceGeometry as Ue}from"../webgl-engine/collections/Component/SourceGeometry.js";import{Transform as We}from"../webgl-engine/collections/Component/Transform.js";import{RenderTexture as Ge}from"../webgl-engine/core/material/RenderTexture.js";import{ManagedTexture as Ke}from"../webgl-engine/lib/ManagedTexture.js";import{compressNormals as qe}from"../webgl-engine/lib/Normals.js";import{advancedMRRFactors as q}from"../webgl-engine/materials/pbrUtils.js";import Je from"../../layers/LayerView.js";import{spatialReferenceIncompatibleError as Ye}from"../../support/layerViewUtils.js";import{TaskPriority as Xe}from"../../support/Scheduler.js";import{CompressedTextureFormat as J,SizedPixelFormat as Y}from"../../webgl/enums.js";import{alphaCutoff as X}from"../../../webscene/support/AlphaCutoff.js";var Z;function Ze(e,t,n){if(t===`image/vnd-ms.dds`)switch(n){case`Dxt1`:return J.COMPRESSED_RGB_S3TC_DXT1_EXT;case`Dxt5`:return J.COMPRESSED_RGBA_S3TC_DXT5_EXT;default:return null}if(t===`image/ktx`)return n===`Etc1`?J.COMPRESSED_RGB8_ETC2:null;switch(e){case 33319:return Y.RG8;case 6407:return Y.RGB8;case 6408:return Y.RGBA8;case 6403:return Y.R8;default:return null}}let Q=class extends Ce(Je){static{Z=Ae}constructor(e){super(e),this[Z]=!0,this.type=`integrated-mesh-3dtiles`,this.skipHeightModelInfoValidation=!0,this.freeze=!1,this._modifications=[],this._visibleGeometryChangedSchedulerHandle=null,this._initializationController=null,this._wasmLayerId=-1,this._metersPerVCSUnit=1,this.ignoresMemoryFactor=!1,this._usedMemory=0,this._cacheMemory=0,this._useEsriCrs=!1,this.fullExtentInLocalViewSpatialReference=null,this._applySSAO=!has(`disable-feature:im-ssao`),this._imShading=!!has(`enable-feature:im-shading`),this._imVertexNormals=!!has(`enable-feature:im-vertex-normals`),this._lyrHandleToObjects=new Map,this._visibleObjects=new Set,this._loadedObjects=new Set,this._dbgFlags=new Set;let t=e.view.resourceController;this._memCache=t.memoryController.newCache(`IM3DTiles-${this.uid}`,e=>this._deletePerObjectData(e)),this._replacesTerrain=e.layer.replacesTerrain,this._frameTask=t.scheduler.registerTask(Xe.TILES3D,this),this._frustum=new Le(e.view.renderCoordsHelper)}tryRecycleWith(e,t){return this.canRecycleWith(e)?e.load(t).then(()=>{a(t);let n=this.layer.queryElevationCallback;this.layer=e,this.layer.queryElevationCallback=n}):null}canRecycleWith(e){return e.url===this.layer.url&&e.type===`integrated-mesh-3dtiles`&&e.replacesTerrain===this._replacesTerrain}initialize(){this._dbg(2,`Tiles3DLayerView3D initialize() called`);let{view:e}=this;this._workerHandle=new Se(Fe(e.resourceController)),this._updatingHandles.add(()=>this.layer.modifications,()=>this._loadModifications(),s),this.addResolvingPromise(this._initializeAsync(e))}async _initializeAsync(e){this._initializationController=new AbortController;let{signal:t}=this._initializationController;if(await c(()=>e?.defaultsFromMap.heightModelInfoReady,t),a(t),!this._canProjectWithoutEngine())throw Ye(`layer`,this.layer.spatialReference.wkid,e.renderSpatialReference?.wkid);this._wasmLayerId=await Te(this,t),a(t);let n=new Ie(this);this._intersectionHandler=n,e.sceneIntersectionHelper.addIntersectionHandler(n),this._elevationProvider=new ke({view:e,layerElevationSource:this,intersectionHandler:n});let r=this._getElevationContext();e.elevationProvider.register(r,this._elevationProvider),this._updatingHandles.add(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChange(e)),this._updatingHandles.add(()=>this._modifications,()=>this._modificationsChanged()),this._updatingHandles.add(()=>this.fullOpacity,()=>this._opacityChange()),this._updatingHandles.add(()=>e.overlayManager.renderer.isEmpty,()=>this._opacityChange()),this._updatingHandles.add(()=>e.clippingArea,()=>this._clippingAreaChanged(),s),this._updatingHandles.add(()=>e.state.contentCamera,()=>this._cameraChanged(),s),this._updatingHandles.add(()=>this.layer.isUsedAsGroundLayer,()=>this._groundUsageChanged()),e.overlayManager.registerDrapeTarget(this),this.addHandles([l(()=>this.layer.elevationInfo,e=>this._elevationInfoChanged(e)),u(()=>this.fullOpacity,()=>this._opacityChange()),l(()=>this.suspended,e=>this._wasm?.setEnabled(this,!e),s),l(()=>this.freeze,e=>{e?this._wasm?.incrementFrozenLayerViewCount(this):(this._wasm?.decrementFrozenLayerViewCount(this),this._cameraChanged())})]),this._initializationController=null,this.addHandles(l(()=>this._replacesTerrain&&!!this._wasm?.isTerrainReady||!this._replacesTerrain&&!!has(`enable-feature:im-as-ground`)&&this.layer.isUsedAsGroundLayer,e=>{this.layer.queryElevationCallback=e?(e,t)=>this._queryElevation(e,t):null},s))}destroy(){if(this.freeze=!1,this._initializationController=n(this._initializationController),this._dbg(2,`Tiles3DLayerView3D destroy() called`),this._workerHandle?.destroyContextAndSelf(this.uid),Ee(this),this.layer.queryElevationCallback=null,this._intersectionHandler&&=(this.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),this._intersectionHandler.destroy(),null),this._elevationProvider){let e=Array.from(this._lyrHandleToObjects.values()),t=e.reduce((e,{componentObjects:t})=>e+t.length,0);this._elevationProvider.notifyObjectsChangedFunctional(t,t=>{for(let{componentObjects:n}of e)for(let{obb:e}of n)if(!t(e))return}),this.view.elevationProvider.unregister(this._elevationProvider),this._elevationProvider=null}this.view.overlayManager.unregisterDrapeTarget(this),this._lyrHandleToObjects.forEach(e=>this.freeObject(e)),this._lyrHandleToObjects.clear(),this._visibleObjects.clear(),this._loadedObjects.clear(),this._usedMemory=0,this._cacheMemory=0,this._memCache.destroy(),this._frameTask.remove(),this._updatingHandles=r(this._updatingHandles),this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=i(this._visibleGeometryChangedSchedulerHandle)}get usedAsGround(){return this.layer.isUsedAsGroundLayer}get replacesTerrain(){return this._replacesTerrain}get fullOpacity(){return has(`enable-feature:im-as-ground`)?this.usedAsGround?this.view.map.ground.opacity:this.layer.opacity:this.replacesTerrain?this.view.map.ground.opacity:1}get opaque(){return this._groundTransparencyMode===0}get invisible(){return this._groundTransparencyMode===3}get _groundTransparencyMode(){return(has(`enable-feature:im-as-ground`)?!this.usedAsGround:!this._replacesTerrain)?0:Ve(this.fullOpacity,this.view.overlayManager.renderer.isEmpty)}get _renderOpacity(){switch(this._groundTransparencyMode){case 3:return 0;case 2:return X;default:return this.fullOpacity}}get hasModifications(){return this._modifications&&this._modifications.length>0}_opacityChange(){let e=this._renderOpacity,t=this._groundTransparencyMode;this.forEachComponentObject(n=>this._collection.updateObjectOpacity(n,e,t))}_getElevationContext(){return this.replacesTerrain?0:has(`enable-feature:im-as-ground`)?this.usedAsGround?1:2:1}_groundUsageChanged(){let e=this._getElevationContext();this.view.elevationProvider.unregister(this._elevationProvider),this.view.elevationProvider.register(e,this._elevationProvider),this._intersectionHandler.isGround=!has(`enable-feature:im-as-ground`)||this.usedAsGround,this._intersectionHandler.slicePlaneEnabled=this.slicePlaneEnabled&&!this.replacesTerrain,this.view.overlayManager.unregisterDrapeTarget(this),this.view.overlayManager.registerDrapeTarget(this),this._loadModifications();let t=has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,n=this._renderOpacity,r=this._groundTransparencyMode;this.forEachComponentObject(e=>e.updateMaterial({isGround:t,opacity:n,groundTransparencyMode:r}))}_cameraChanged(){if(this.freeze)return;let e=this._frustum;e.update(this.view.state.contentCamera);let t=this._visibleObjects,n=!1;this._loadedObjects.forEach(r=>{let i=r.obb?.intersectsFrustum(e)??!1;i!==r.isVisible&&(r.isVisible=i,i?t.add(r):t.delete(r),r.componentObjects.forEach(e=>this._collection.setObjectVisibility(e,i)),n||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(i,r.elevationRange))}),n&&this._setVisibleElevationRangeDirty()}intersect(e,t,n,r){this._intersectionHandler.intersectRay(e,t,n,r,null,!1)}get ready(){return!this.replacesTerrain||!!this._wasm?.isTerrainReady}_modificationsChanged(){let e=this.useEsriCrs?this.layer.supportedSpatialReferences[1]:this.layer.supportedSpatialReferences[0],t=Oe(this._layerClippingArea,this._modifications,e,this.view.state.isGlobal);this._wasm?.setMeshModifications(this,t)}_clippingAreaChanged(){let e=this.layer.spatialReference,t=pe();this._layerClippingArea=Re(this.view.clippingArea,t,e)?t:null,this._modificationsChanged()}_visibleGeometryChanged(){this._visibleGeometryChangedSchedulerHandle??=d(()=>{this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=null})}_slicePlaneEnabledChange(e){this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e&&!this.replacesTerrain),this.forEachComponentObject(t=>t.updateMaterial({slicePlaneEnabled:e}))}_elevationInfoChanged(e){this._wasm?.setLayerOffset(this,G(e))}get _wasm(){return De(this.view)}_queryElevation(e,t){return this.destroying||this.destroyed?Promise.reject(o()):this._wasm?.queryElevation(this,e,t)??Promise.reject(o())}get wasmLayerId(){return this._wasmLayerId}get metersPerVCSUnit(){return this._metersPerVCSUnit}get usedMemory(){return this._usedMemory}get unloadedMemory(){return 0}get cachedMemory(){return this._cacheMemory}get useEsriCrs(){return this._useEsriCrs}get visibleAtCurrentScale(){return this.replacesTerrain||he(this.layer.effectiveScaleRange,this.view.scale)}canResume(){let e=this.layer&&`effectiveScaleRange`in this.layer?this.layer.effectiveScaleRange:null;return this.visible&&this.layer?.loaded&&this.parent&&!this.parent.suspended&&this.view?.ready&&(this.replacesTerrain||N(e)&&this.visibleAtCurrentScale)&&this.visibleAtCurrentTimeExtent||!1}get performanceInfo(){let e=0,t=0,n=0,r=0,i=0,a=0;return this._lyrHandleToObjects.forEach(o=>{o.isLoaded?(e+=o.textureMemoryUsage,t+=o.vboMemoryUsage,i++):(n+=o.textureMemoryUsage,r+=o.vboMemoryUsage,a++)}),new we(this.usedMemory,i,a,$(t),$(e),$(r),$(n))}_canProjectWithoutEngine(){if(this.view.state.viewingMode===1||P(this.view.renderSpatialReference)||F(this.view.renderSpatialReference))return!0;if(this.layer.esriCrsSpatialReference&&I(this.layer.esriCrsSpatialReference,this.view.renderSpatialReference)){if(this.layer.esriCrsSpatialReference.vcsWkid===115700)return!1;let e=be(this.layer.esriCrsSpatialReference);if(!e){let t=this.layer.esriCrsSpatialReference,n=L(t),r=`meters`;!n&&t.wkid&&t.wkid!==-1&&(r=g(z.units[z[t.wkid]])),r&&(e=new le({heightModel:`gravity-related-height`,heightUnit:r}))}let t=this.view.heightModelInfo;return this._useEsriCrs=me(e,t,!1)===0,this._useEsriCrs&&(e&&(this._metersPerVCSUnit=_(1,e.heightUnit,`meters`)),this.fullExtentInLocalViewSpatialReference=this.layer.esriCrsFullExtent),this._useEsriCrs}return!1}get _stage(){return this.view.stage}get _collection(){return this._stage.renderView.componentObjectCollection}get elevationProvider(){return this._elevationProvider}get elevationOffset(){return G(this.layer.elevationInfo)}get elevationRange(){let e=this.fullExtent;return e?.zmin&&e?.zmax?new K(e.zmin,e.zmax):null}getElevationRange(e){return this._intersectionHandler.getElevationRange(e)}get visibleElevationRange(){let e=new K;this._visibleObjects.size===0?e.setElevationRangeValues(0,0):(e.setElevationRangeValues(1/0,-1/0),this._forEachRelevantVisibleTile(t=>e.expandElevationRange(t.elevationRange)),e.minElevation===1/0&&e.setElevationRangeValues(0,0));let t=this._get(`visibleElevationRange`);return t&&t.minElevation===e.minElevation&&t.maxElevation===e.maxElevation?t:e}_setVisibleElevationRangeDirty(){this.notifyChange(`visibleElevationRange`)}_forEachRelevantVisibleTile(e){let{view:t}=this,{spatialReference:n}=t,r=n.isWGS84||n.isWebMercator||R(n)||oe(n)||se(n);if(this.view.state.isGlobal||!r)return this.forEachVisibleTile(e);let i=M(n).radius,{eye:a,viewForward:o,near:s}=t.state.contentCamera,c=E(A(),o),l=Math.max(a[2],500),u=l+i,d=Math.sqrt(u**2-i**2),f=Math.abs(Math.atan2(d,i))*i,p=l>.5*i?.5*Math.PI*i:f,m=A();this.forEachVisibleTile(t=>{let{mbsRadius:n,mbsCenter:r}=t;if(n<0)return;D(m,r,a);let i=O(m,c);Math.abs(i)<p&&i+n>s&&i-n<p&&e(t)})}get fullExtent(){return this.layer.fullExtent}forEachComponentObject(e){this._forEachObject(this._lyrHandleToObjects.values(),e)}forEachVisibleTile(e){for(let t of this._visibleObjects)e(t)}forEachTile(e){for(let t of this._loadedObjects)e(t)}forEachVisibleComponentObject(e){this._forEachObject(this._visibleObjects,e)}_forEachObject(e,t){for(let{componentObjects:n}of e)for(let e of n)t(e)}get drapeTargetType(){return has(`enable-feature:im-as-ground`)?+!this.usedAsGround:+!this.replacesTerrain}isUpdating(){let e=this._wasm;return!this.freeze&&this._wasmLayerId>=0&&e!=null&&e.isUpdating(this._wasmLayerId)}get readyToRun(){return!!this._frameTask?.readyToRun}runTask(e){this._frameTask.processQueue(e)}updatingFlagChanged(){this.notifyChange(`updating`)}async createRenderable(e){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable called after destroy`);let{entity3d:t}=e;if(!xe(t))throw Error(`entity3D not valid`);let n=new Map,r;try{r=this._createPrimitiveTextureBundles(t,n)}catch(e){throw n.forEach(e=>this._stage?.removeTexture(e)),e}let i=null;try{if(i=await this._createRenderableMain(t,r),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable aborted due to destroyed instance`);let{tileObb:a,componentObjects:o,elevationRange:s}=i,c=0,l=0,u=0;for(let e of o){let{texture:t,textureMetallicRoughness:n,textureEmissive:r,textureOcclusion:i,textureNormal:a}=e.renderable.drawParameters;c+=(t?.usedMemory??0)+(n?.usedMemory??0)+(r?.usedMemory??0)+(i?.usedMemory??0)+(a?.usedMemory??0),l+=this._collection.getObjectGPUMemoryUsage(e),u+=e.intersectionGeometry.usedMemory}let d=Array.from(n.values()),f=new $e(e.handle,o,d,u,l,c,a,e.stableNodeId,e.nodeDepth,s);return this._lyrHandleToObjects.set(e.handle,f),()=>{this._memCache.put(W(f.handle),f);let{usedMemory:e}=f;return this._cacheMemory+=e,{memUsageBytes:e}}}catch(e){throw r.forEach(e=>e.cleanup()),i?.componentObjects.forEach(e=>this._collection.destroyObject(e)),n.forEach(e=>this._stage?.removeTexture(e)),e}}_createPrimitiveTextureBundles(e,t){let n=[];try{let r=e.desc.geometry;for(let i of e.validPrimitiveIndices){let a=r.prims[i].materialId,o=e.desc.materials?.materials&&a!=null&&a!==U?e.desc.materials.materials[a]:null,s=Promise.resolve(tt),c=null,l=null,u=null,d=null,f=null;if(o){let n=o.lightingModel===`Pbr`;c=this._getTexture(o.baseColorTex,e,t),l=n?this._getTexture(o.metalTex,e,t):null,u=n?this._getTexture(o.emissiveTex,e,t):null,d=n?this._getTexture(o.occlusionTex,e,t):null,f=n?this._getTexture(o.normalTex,e,t):null;let r=[c,l,u,d,f].map(e=>e?.loadPromise??null);s=Promise.all(r)}n.push(new nt(s,c,l,u,d,f))}}catch(e){throw n.forEach(e=>e.cleanup()),e}return n}async _createRenderableMain(e,t){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain called after destroy`);let n=[],r=e.desc,i=j(...e.origin),a=this.view.groundView.spatialReference,o=this.view.state.isGlobal,s=C;if(o){let e=w();ue(ce,i,e,a),s=b(S(),e)}let c=et(r.obb),l=o?M(this.view.spatialReference).radius:0,u=[];try{let d=-1;for(let n of e.validPrimitiveIndices){d+=1;let i=r.geometry.prims[n],a=t[d];if(this._dbgFlags.has(2)&&this._dbg(2,JSON.stringify(i)),je[i.ptype]==null){this._dbg(2,`[Unsupported Feature] Unsupported primitive mode (`+i.ptype+`). Skipping primitive.`),a.cleanup();continue}let{positionView:o,normalsData:s,colorView:c,texCoord0Data:l,indicesView:f}=this._getBufferViews(i,e);if(o==null||f==null){a.cleanup();continue}let p=o.count,m=(e,t)=>e!=null&&e!==p?(this._dbg(3,`${t} !== numPos. Skipping primitive.`),!1):!0;!m(l==null?void 0:l.length/2,`numTexcoord`)||!m(c?.count,`numColors`)||!m(s?.length,`normals`)?a.cleanup():u.push({componentIndex:d,positionView:o,indicesView:f,texCoord0Data:l,colorView:c,normalsData:s})}let f=s!==C,p=f?x(S(),s)??C:C,{vertexProcessingOutputs:m,obbHalfSizeAccumulator:h,elevationRange:g}=await this._workerHandle.processTiles3DVertices(u,i,l,o,s,c,this._imVertexNormals&&!this.usedAsGround);if(this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);let _=r.materials;if(await Promise.all(t.map(e=>e.materialPromise)),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);m.length>0&&c.setHalfSize(h);for(let o of m){let{componentIndex:s,positionView:l,indicesView:u,layout:d,textureCoordinateType:m,interleavedVertexData:h,indices:g}=o,v=e.validPrimitiveIndices[s],y=r.geometry.prims[v],b=t[s],x=c.clone(),S=Be(d),C=new Uint32Array([0,u.typedBuffer.length]),w=new He(S,this._imShading?2:0,m,f?2:0),T=new Ue({interleavedVertexData:h,vertexCount:h.byteLength/S[0].stride,indexData:g},{positions:l.typedBuffer,indices:u.typedBuffer},C,w),E=this.view.renderSpatialReference,D=A(),O=[1,1,1];de(i,E,O,a)||this._dbg(3,`Unsupported coordinate system for IM overlay`),fe(i,E,D,a);let k=this._createComponentMaterialInitParameters(_,y.materialId,b);k.baseColorTexture||this._dbg(3,`No colour texture 1`);let j=this._collection.createObject({toMapSpace:re(D[0],D[1],O[0],O[1]),transform:new We(i,p),obb:x,geometry:T,elevationAlignable:!1},k);n.push(j)}let{fullExtent:v}=this.layer;return v?.hasZ&&v.zmax&&v.zmin&&(g.minElevation=Math.max(g.minElevation,v.zmin),g.maxElevation=Math.min(g.maxElevation,v.zmax)),{tileObb:c,componentObjects:n,elevationRange:g}}catch(e){throw n.forEach(e=>this._collection.destroyObject(e)),e}}_createComponentMaterialInitParameters(e,t,n){let r=e?.materials!=null&&t!=null&&t!==U?e.materials[t]:null,i=1,a=r?.baseColorTex?.imageId;if(a!=null&&e&&Array.isArray(e.images)&&a>=0&&a<e.images.length){let t=e.images[a];t.alpha&&(i=Me[t.alpha])}let o=(r==null?`Unlit`:r.lightingModel)===`Pbr`,s=ae,c=X,l=!1,u=2,d=ne(0,0,0),f=ee(q),p=n.baseColorTexture,m=n.metallicRoughnessTexture,h=n.emissionTexture,g=n.occlusionTexture,_=n.normalTexture;return r&&(s=ie(r.baseColorFactor),c=r.alphaCutoff??X,o&&(k(f,r.metallicFactor,r.roughnessFactor,0),r.emissiveFactor&&(d=r.emissiveFactor)),l=r.isDoubleSided,u=Ne[r.faceCulling??`NotSet`]),{isIntegratedMesh:!0,baseColor:s,textureAlphaCutoff:c,mrrFactors:f,baseColorTexture:p,metallicRoughnessTexture:m,normalTexture:_,occlusionTexture:g,emissionTexture:h,hasParametersFromSource:!1,sphereDepthInterpolate:this.layer.hasGoogleUrl,alphaDiscardMode:i,doubleSided:l,cullFace:u,isGround:has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,groundTransparencyMode:this._groundTransparencyMode,emissiveBaseColor:d,usePBR:o,slicePlaneEnabled:this.slicePlaneEnabled,opacity:this._renderOpacity,polygonOffset:0,ellipsoidMode:1,applySSAO:this._applySSAO}}freeRenderable(e){let t=this._lyrHandleToObjects.get(e);t?(t.isLoaded?(this._loadedObjects.delete(t),this._visibleObjects.delete(t),this._intersectionHandler.removeTile(t),this._usedMemory-=t.usedMemory):this._cacheMemory-=t.usedMemory,this.freeObject(t),this._lyrHandleToObjects.delete(e)):this._dbg(3,`freeRendedrable on non-existent renderable ${e}`)}freeObject(e){let t=W(e.handle);this._memCache.pop(t),e.textures.forEach(e=>this._stage.removeTexture(e)),e.componentObjects.forEach(e=>this._collection.destroyObject(e))}setRenderableVisibility(e,t,n){if(this.destroyed||this.destroying)return;let r=this._frustum,i=[],a=!1,o=!1;for(let s=0;s<n;++s){if(!t[s])continue;let n=e[s],c=this._lyrHandleToObjects.get(n);if(c){if(c.isLoaded){this._dbg(3,`Already loaded object marked loaded again ${c.stableNodeId}`);continue}a=!0,c.isLoaded=!0,this._loadedObjects.add(c),this._intersectionHandler.addTile(c),this._usedMemory+=c.usedMemory,this._cacheMemory-=c.usedMemory;let e=c.obb?.intersectsFrustum(r)??!0;c.isVisible=e,e&&(this._visibleObjects.add(c),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(e,c.elevationRange)),i.push(c.obb),c.componentObjects.forEach(t=>{this._collection.setObjectVisibility(t,e)}),this._memCache.pop(W(n))}else this._dbg(3,`Tried to mark Non existent object ${n} as loaded`)}for(let r=0;r<n;++r){let n=e[r];if(t[r])continue;let a=this._lyrHandleToObjects.get(n);if(a){if(!a.isLoaded){this._dbg(3,`Tried to unload not-loaded object ${a.stableNodeId}`);continue}let e=a.isVisible;this._visibleObjects.delete(a),a.isVisible=!1,a.isLoaded=!1,this._loadedObjects.delete(a),this._intersectionHandler.removeTile(a),e&&(this._visibleGeometryChanged(),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(!1,a.elevationRange)),this._usedMemory-=a.usedMemory,this._cacheMemory+=a.usedMemory,i.push(a.obb),a.componentObjects.forEach(e=>{this._collection.setObjectVisibility(e,!1)}),this._memCache.put(W(n),a)}else this._dbg(3,`Tried to mark Non existent object ${n} as not loaded`)}a&&this._visibleGeometryChanged(),i.length>0&&this._elevationProvider.notifyObjectsChanged(i),o&&this._setVisibleElevationRangeDirty()}setLodPixelThreshold(e){this._wasm?.setLodPixelThreshold(this,e)}_isVisibileElevationRangeModifiedByChangedTileVisbility(e,t){let{visibleElevationRange:n}=this,{minElevation:r,maxElevation:i}=t;return e?r<n.minElevation||i>n.maxElevation:r===n.minElevation||i===n.maxElevation}_getTexture(e,t,n){let r=e&&t.desc.materials?.images?.[e.imageId];if(!r||r.data==null||r.data===U)return null;let i=t.assets[r.data];if(!i||i.byteCount<1||i.dataType!==`U8`)return null;let a=n.get(r)??this._createTexture(e,r,i,n);return a?new Ge(this._stage.renderView.textures,a.id):null}_createTexture(e,t,n,r){let i=this._stage.renderView.renderingContext.parameters.maxMaxAnisotropy,a=t.mipCount?!0:i>1,o=Pe[e.wrapMode??`None`],s=t.alpha?6408:6407,c=new Uint8Array(n.data.buffer,0,n.byteCount),l=null,u=null,d=null;switch(t.format){case`Raw`:t.pixelFormat===`R8`?(l=c,s=6403,u=``):t.pixelFormat===`Rg8`||t.pixelFormat===`Ga8`?(l=c,s=33319,u=``):t.pixelFormat===`Rgb8`?(l=c,s=6407,u=``):t.pixelFormat===`Rgba8`&&(l=c,s=6408,u=``);break;case`Dxt1`:l=c,s=6407,u=`image/vnd-ms.dds`;break;case`Dxt5`:l=c,s=6408,u=`image/vnd-ms.dds`;break;case`Basis`:l=c,s=6407,u=`image/ktx2`;break;case`Etc1`:l=c,s=6407,u=`image/ktx`;break;case`Png`:u=`image/png`,d=document.createElement(`img`);break;case`Jpeg`:u=`image/jpeg`,d=document.createElement(`img`);break;case`Etc2`:u=`image/ktx`,d=document.createElement(`img`);break;case`Astc`:this._dbg(3,`Astc texture not supported`);break;case`Pvrtc`:this._dbg(3,`Pvrtc texture not supported`)}if(d&&u){let e=d,t=URL.createObjectURL(new Blob([c],{type:u})),n=()=>{URL.revokeObjectURL(t),e.removeEventListener(`load`,n),e.removeEventListener(`error`,n)};e.addEventListener(`load`,n),e.addEventListener(`error`,n),e.src=t,l=e}if(l&&u!=null){let e=Ze(s,u,t.format),n=new Ke(l,{mipmap:a,maxAnisotropy:i,encoding:u,wrap:o,pixelFormat:s,internalFormat:e??void 0,immutable:e!=null,noUnpackFlip:!0,width:t.mip0Width,height:t.mip0Height});return this._stage.addTexture(n),r.set(t,n),n}return null}_getBufferViews(e,t){let n,r,i,a;for(let o=0;o<e.atrbs.length;o++){let s=e.atrbs[o],c=t.assets[s.assetId];if(!c)continue;let l=c.data.buffer,u=c.byteCount;try{switch(s.sem){case`Position`:c.ncomp!==3||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Position (`+c+`)`):n=new B(l,0,void 0,u);break;case`Normal`:if(c.ncomp!==3||c.dataType!==`F32`||!p(c.data))this._dbg(3,`[Unsupported Feature] Unsupported view for Normal (`+c+`)`);else{let e=new B(l,0,void 0,u);a=new Uint32Array(e.count),qe(e.typedBuffer,new Int16Array(a.buffer,a.byteOffset,a.length*2))}break;case`TexCoord`:c.ncomp!==2||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Texcoord (`+c+`)`):i===void 0&&(i=new ve(l,0,void 0,u).typedBuffer);break;case`Color`:c.dataType===`U8`&&f(c.data)&&(c.ncomp===4?r=new ge(l,0,void 0,u):c.ncomp===3&&(r=new _e(l,0,void 0,u))),r??this._dbg(3,`[Unsupported Feature] Unsupported view for Color (`+c+`)`);break;case`FeatureIndex`:break;default:this._dbg(2,`[Unsupported Feature] Unsupported semantic (`+s.sem+`). Skipping vertex attribute.`)}}catch(e){this._dbg(2,`Error Creating buffer (`+e+`). Skipping vertex attribute.`)}}let o,s=!1;if(e.index!=null&&e.index!==U){let n=t.assets[e.index];if(!n)s=!0;else{let e=n.byteCount;switch(n.dataType){case`U16`:n.ncomp===1&&h(n.data)&&(o=new H(n.data.buffer,0,void 0,e));break;case`U32`:n.ncomp===1&&m(n.data)&&(o=new V(n.data.buffer,0,void 0,e))}s=!o}}if(!s&&o==null&&n!=null){let e=n.count;o=o=e<65535?new H(new Uint16Array(e).buffer):new V(new Uint32Array(e).buffer);for(let t=0;t<e;t++)o.set(t,t)}return{positionView:n,colorView:r,texCoord0Data:i,indicesView:o,normalsData:a}}_loadModifications(){if(this.removeHandles(`modifications`),this.layer.modifications==null){this._modifications=[];return}let e=this.layer.modifications;this.addHandles(this._updatingHandles.addOnCollectionChange(()=>e,()=>{this._modifications=e.filter(e=>!(this.usedAsGround&&e.type!==`replace`)).toArray(),this._modifications.length<e.length&&t.getLogger(this).info(`Ground layers only support replace modifications. Other modification types have been ignored.`)},s),`modifications`)}_deletePerObjectData(e){this._wasm?.onRenderableEvicted(this,e.handle,e.usedMemory),this.freeRenderable(e.handle)}_dbg(e,n){this._dbgFlags.has(e)&&(e===3?t.getLogger(this).error(n):t.getLogger(this).warn(n))}};e([v()],Q.prototype,`freeze`,void 0),e([v()],Q.prototype,`fullOpacity`,null),e([v()],Q.prototype,`opaque`,null),e([v()],Q.prototype,`invisible`,null),e([v({readOnly:!0})],Q.prototype,`ready`,null),e([v({type:[ye]})],Q.prototype,`_modifications`,void 0),e([v()],Q.prototype,`_visibleGeometryChangedSchedulerHandle`,void 0),e([v()],Q.prototype,`layer`,void 0),e([v({readOnly:!0})],Q.prototype,`visibleAtCurrentScale`,null),e([v({readOnly:!0})],Q.prototype,`_collection`,null),e([v()],Q.prototype,`elevationOffset`,null),e([v({readOnly:!0})],Q.prototype,`visibleElevationRange`,null),e([v()],Q.prototype,`fullExtentInLocalViewSpatialReference`,void 0),Q=e([y(`esri.views.3d.layers.IntegratedMesh3DTilesLayerView3D`)],Q);const Qe=Q;class $e{constructor(e,t,n,r,i,a,o,s,c,l){this.handle=e,this.componentObjects=t,this.textures=n,this.cpuMemoryUsage=r,this.vboMemoryUsage=i,this.textureMemoryUsage=a,this.obb=o,this.stableNodeId=s,this.nodeDepth=c,this.elevationRange=l,this.bvhIntersectionGeneration=0,this.isLoaded=!1,this.isVisible=!1;let u=A();o?.getCenter(u),this._obbCenterX=u[0],this._obbCenterY=u[1],this._obbCenterZ=u[2];let d=o?.radius??-1;this._obbRadius=d,this._obbRadiusSquared=d*d,this._obbShortestHalfsize=o?Math.min(o.halfSizeX,o.halfSizeY,o.halfSizeZ):0,this._mbsCenter=o?o.getCenter(A()):te}get usedMemory(){return this.textureMemoryUsage+this.vboMemoryUsage+this.cpuMemoryUsage}get mbsRadius(){return this._obbRadius}get mbsCenter(){return this._mbsCenter}boundingVolumeIntersectsRay(e,t){if(!this.obb)return!0;let{_obbCenterX:n,_obbCenterY:r,_obbCenterZ:i}=this,a=n-e[0],o=r-e[1],s=i-e[2],c=a*t[0]+o*t[1]+s*t[2];return a*a+o*o+s*s-c*c<=this._obbRadiusSquared&&this.obb.intersectRay(e,t)}boundingVolumeIntersectsSphere(e){let t=this._obbRadius;if(t<0)return!0;let n=e.center,r=e.radius,i=t+r,a=this._obbCenterX-n[0];if(a>i)return!1;let o=this._obbCenterY-n[1];if(o>i)return!1;let s=this._obbCenterZ-n[2];if(s>i)return!1;let c=a*a+o*o+s*s;if(c>i*i)return!1;if(c<=(this._obbShortestHalfsize+r)**2)return!0;let l=r-t;return l>0&&c<=l*l?!0:this.obb?.intersectSphere(e)??!0}}function $(e){return Math.round(e/1048.576)/1e3}function et(e){return new ze(e.center,e.halfSize,T(...e.quaternion))}const tt=[];class nt{constructor(e,t,n,r,i,a){this.materialPromise=e,this.baseColorTexture=t,this.metallicRoughnessTexture=n,this.emissionTexture=r,this.occlusionTexture=i,this.normalTexture=a}cleanup(){this.baseColorTexture?.dispose(),this.metallicRoughnessTexture?.dispose(),this.emissionTexture?.dispose(),this.occlusionTexture?.dispose(),this.normalTexture?.dispose()}}export{Qe as default};
2
+ import{__decorate as e}from"tslib";import has from"../../../core/has.js";import t from"../../../core/Logger.js";import{abortMaybe as n,destroyMaybe as r,removeMaybe as i}from"../../../core/maybe.js";import{throwIfAborted as a,createAbortError as o}from"../../../core/promiseUtils.js";import{initial as s,whenOnce as c,watch as l,when as u}from"../../../core/reactiveUtils.js";import{schedule as d}from"../../../core/scheduling.js";import{isUint8Array as f,isFloat32Array as p,isUint32Array as m,isUint16Array as h}from"../../../core/typedArrayUtil.js";import{unitFromRESTJSON as g,convertUnit as _}from"../../../core/units.js";import{property as v,subclass as y}from"../../../core/accessorSupport/decorators.js";import{fromMat4 as b,invert as x}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as S,IDENTITY as C}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as T}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{normalize as E,sub as D,dot as O,set as k}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as A,freeze as j,clone as ee,ZEROS as te,fromValues as ne}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as re,clone as ie,ONES as ae}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isMoon as oe,isMars as se,getReferenceEllipsoid as M,SphericalECEFSpatialReferenceLike as ce}from"../../../geometry/ellipsoidUtils.js";import le from"../../../geometry/HeightModelInfo.js";import{computeTranslationToOriginAndRotation as ue}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{localLinearScaleFactors as de}from"../../../geometry/projection/localLinearScaleFactors.js";import{projectVectorToVector as fe}from"../../../geometry/projection/projectVectorToVector.js";import{create as pe}from"../../../geometry/support/aaBoundingRect.js";import{isCompatible as me}from"../../../geometry/support/heightModelInfoUtils.js";import{isInEffectiveScaleRange as he,validateScaleRange as N}from"../../../geometry/support/scaleUtils.js";import{isPlateCarree as P,isWebMercator as F,equals as I,isGeographic as L,isCGCS2000 as R}from"../../../geometry/support/spatialReferenceUtils.js";import z from"../../../geometry/support/WKIDUnitConversion.js";import{BufferViewVec4u8 as ge,BufferViewVec3u8 as _e,BufferViewVec2f as ve,BufferViewVec3f as B,BufferViewUint32 as V,BufferViewUint16 as H}from"../../../geometry/support/buffer/BufferView.js";import{nullId as U}from"../../../layers/ILyr3DWasmPerSceneView.js";import ye from"../../../layers/support/SceneModification.js";import{getHeightModelInfoFromVCS as be,validateEntity3D as xe,makeCacheKey as W}from"../../../layers/support/tiles3DUtils.js";import{getElevationOffsetInMeters as G}from"../../../support/elevationInfoUtils.js";import{IntegratedMesh3DTilesLayerWorkerHandle as Se}from"./IntegratedMesh3DTilesLayerWorkerHandle.js";import{LayerView3D as Ce}from"./LayerView3D.js";import{Lyr3DViewPerformanceInfo as we}from"./Lyr3DViewPerformanceInfo.js";import{addLayerViewToWasm as Te,removeLayerViewFromWasm as Ee,getLyr3DWasm as De}from"./Lyr3DWasm.js";import{toWasmModification as Oe}from"./SceneLayerWorkerHandle.js";import{LayerElevationProvider as ke}from"./i3s/LayerElevationProvider.js";import{IntegratedMesh3DTilesLayerView3DSymbol as Ae}from"./support/integratedMesh3DTilesLayerViewInstanceUtils.js";import{primTypeConversion as je,alphaModeConversion as Me,faceCullingConversion as Ne,wrapModeConversion as Pe}from"./support/lyr3dTypeConversions.js";import{makeScheduleFunction as Fe}from"./support/makeScheduleFunction.js";import{Tiles3DMeshIntersectionHandler as Ie}from"./support/Tiles3DMeshIntersectionHandler.js";import{Frustum as Le}from"../state/Frustum.js";import{ElevationRange as K}from"../support/ElevationRange.js";import{toBoundingRect as Re}from"../support/extentUtils.js";import{Obb as ze}from"../support/orientedBoundingBox.js";import{glLayout as Be}from"../support/buffer/glUtil.js";import{getGroundTransparencyModeFromOpacity as Ve}from"../terrain/TransparencyMode.js";import{ComponentGeometryParameters as He,SourceGeometry as Ue}from"../webgl-engine/collections/Component/SourceGeometry.js";import{Transform as We}from"../webgl-engine/collections/Component/Transform.js";import{RenderTexture as Ge}from"../webgl-engine/core/material/RenderTexture.js";import{ManagedTexture as Ke}from"../webgl-engine/lib/ManagedTexture.js";import{compressNormals as qe}from"../webgl-engine/lib/Normals.js";import{advancedMRRFactors as q}from"../webgl-engine/materials/pbrUtils.js";import Je from"../../layers/LayerView.js";import{spatialReferenceIncompatibleError as Ye}from"../../support/layerViewUtils.js";import{TaskPriority as Xe}from"../../support/Scheduler.js";import{CompressedTextureFormat as J,SizedPixelFormat as Y}from"../../webgl/enums.js";import{alphaCutoff as X}from"../../../webscene/support/AlphaCutoff.js";var Z;function Ze(e,t,n){if(t===`image/vnd-ms.dds`)switch(n){case`Dxt1`:return J.COMPRESSED_RGB_S3TC_DXT1_EXT;case`Dxt5`:return J.COMPRESSED_RGBA_S3TC_DXT5_EXT;default:return null}if(t===`image/ktx`)return n===`Etc1`?J.COMPRESSED_RGB8_ETC2:null;switch(e){case 33319:return Y.RG8;case 6407:return Y.RGB8;case 6408:return Y.RGBA8;case 6403:return Y.R8;default:return null}}let Q=class extends Ce(Je){static{Z=Ae}constructor(e){super(e),this[Z]=!0,this.type=`integrated-mesh-3dtiles`,this.skipHeightModelInfoValidation=!0,this.freeze=!1,this._modifications=[],this._visibleGeometryChangedSchedulerHandle=null,this._initializationController=null,this._wasmLayerId=-1,this._metersPerVCSUnit=1,this.ignoresMemoryFactor=!1,this._usedMemory=0,this._cacheMemory=0,this._useEsriCrs=!1,this.fullExtentInLocalViewSpatialReference=null,this._applySSAO=!has(`disable-feature:im-ssao`),this._imShading=!!has(`enable-feature:im-shading`),this._imVertexNormals=!!has(`enable-feature:im-vertex-normals`),this._lyrHandleToObjects=new Map,this._visibleObjects=new Set,this._loadedObjects=new Set,this._dbgFlags=new Set;let t=e.view.resourceController;this._memCache=t.memoryController.newCache(`IM3DTiles-${this.uid}`,e=>this._deletePerObjectData(e)),this._replacesTerrain=e.layer.replacesTerrain,this._frameTask=t.scheduler.registerTask(Xe.TILES3D,this),this._frustum=new Le(e.view.renderCoordsHelper)}tryRecycleWith(e,t){return this.canRecycleWith(e)?e.load(t).then(()=>{a(t);let n=this.layer.queryElevationCallback;this.layer=e,this.layer.queryElevationCallback=n}):null}canRecycleWith(e){return e.url===this.layer.url&&e.type===`integrated-mesh-3dtiles`&&e.replacesTerrain===this._replacesTerrain}initialize(){this._dbg(2,`Tiles3DLayerView3D initialize() called`);let{view:e}=this;this._workerHandle=new Se(Fe(e.resourceController)),this._updatingHandles.add(()=>this.layer.modifications,()=>this._loadModifications(),s),this.addResolvingPromise(this._initializeAsync(e))}async _initializeAsync(e){this._initializationController=new AbortController;let{signal:t}=this._initializationController;if(await c(()=>e?.defaultsFromMap.heightModelInfoReady,t),a(t),!this._canProjectWithoutEngine())throw Ye(`layer`,this.layer.spatialReference.wkid,e.renderSpatialReference?.wkid);this._wasmLayerId=await Te(this,t),a(t);let n=new Ie(this);this._intersectionHandler=n,e.sceneIntersectionHelper.addIntersectionHandler(n),this._elevationProvider=new ke({view:e,layerElevationSource:this,intersectionHandler:n});let r=this._getElevationContext();e.elevationProvider.register(r,this._elevationProvider),this._updatingHandles.add(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChange(e)),this._updatingHandles.add(()=>this._modifications,()=>this._modificationsChanged()),this._updatingHandles.add(()=>this.fullOpacity,()=>this._opacityChange()),this._updatingHandles.add(()=>e.overlayManager.renderer.isEmpty,()=>this._opacityChange()),this._updatingHandles.add(()=>e.clippingArea,()=>this._clippingAreaChanged(),s),this._updatingHandles.add(()=>e.state.contentCamera,()=>this._cameraChanged(),s),this._updatingHandles.add(()=>this.layer.isUsedAsGroundLayer,()=>this._groundUsageChanged()),e.overlayManager.registerDrapeTarget(this),this.addHandles([l(()=>this.layer.elevationInfo,e=>this._elevationInfoChanged(e)),u(()=>this.fullOpacity,()=>this._opacityChange()),l(()=>this.suspended,e=>this._wasm?.setEnabled(this,!e),s),l(()=>this.freeze,e=>{e?this._wasm?.incrementFrozenLayerViewCount(this):(this._wasm?.decrementFrozenLayerViewCount(this),this._cameraChanged())})]),this._initializationController=null,this.addHandles(l(()=>this._replacesTerrain&&!!this._wasm?.isTerrainReady||!this._replacesTerrain&&!!has(`enable-feature:im-as-ground`)&&this.layer.isUsedAsGroundLayer,e=>{this.layer.queryElevationCallback=e?(e,t)=>this._queryElevation(e,t):null},s))}destroy(){if(this.freeze=!1,this._initializationController=n(this._initializationController),this._dbg(2,`Tiles3DLayerView3D destroy() called`),this._workerHandle?.destroyContextAndSelf(this.uid),Ee(this),this.layer.queryElevationCallback=null,this._intersectionHandler&&=(this.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),this._intersectionHandler.destroy(),null),this._elevationProvider){let e=Array.from(this._lyrHandleToObjects.values()),t=e.reduce((e,{componentObjects:t})=>e+t.length,0);this._elevationProvider.notifyObjectsChangedFunctional(t,t=>{for(let{componentObjects:n}of e)for(let{obb:e}of n)if(!t(e))return}),this.view.elevationProvider.unregister(this._elevationProvider),this._elevationProvider=null}this.view.overlayManager.unregisterDrapeTarget(this),this._lyrHandleToObjects.forEach(e=>this.freeObject(e)),this._lyrHandleToObjects.clear(),this._visibleObjects.clear(),this._loadedObjects.clear(),this._usedMemory=0,this._cacheMemory=0,this._memCache.destroy(),this._frameTask.remove(),this._updatingHandles=r(this._updatingHandles),this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=i(this._visibleGeometryChangedSchedulerHandle)}get usedAsGround(){return this.layer.isUsedAsGroundLayer}get replacesTerrain(){return this._replacesTerrain}get fullOpacity(){return has(`enable-feature:im-as-ground`)?this.usedAsGround?this.view.map.ground.opacity:this.layer.opacity:this.replacesTerrain?this.view.map.ground.opacity:1}get opaque(){return this._groundTransparencyMode===0}get invisible(){return this._groundTransparencyMode===3}get _groundTransparencyMode(){return(has(`enable-feature:im-as-ground`)?!this.usedAsGround:!this._replacesTerrain)?0:Ve(this.fullOpacity,this.view.overlayManager.renderer.isEmpty)}get _renderOpacity(){switch(this._groundTransparencyMode){case 3:return 0;case 2:return X;default:return this.fullOpacity}}get hasModifications(){return this._modifications&&this._modifications.length>0}_opacityChange(){let e=this._renderOpacity,t=this._groundTransparencyMode;this.forEachComponentObject(n=>this._collection.updateObjectOpacity(n,e,t))}_getElevationContext(){return this.replacesTerrain?0:has(`enable-feature:im-as-ground`)?this.usedAsGround?1:2:1}_groundUsageChanged(){let e=this._getElevationContext();this.view.elevationProvider.unregister(this._elevationProvider),this.view.elevationProvider.register(e,this._elevationProvider),this._intersectionHandler.isGround=!has(`enable-feature:im-as-ground`)||this.usedAsGround,this._intersectionHandler.slicePlaneEnabled=this.slicePlaneEnabled&&!this.replacesTerrain,this.view.overlayManager.unregisterDrapeTarget(this),this.view.overlayManager.registerDrapeTarget(this),this._loadModifications();let t=has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,n=this._renderOpacity,r=this._groundTransparencyMode;this.forEachComponentObject(e=>e.updateMaterial({isGround:t,opacity:n,groundTransparencyMode:r}))}_cameraChanged(){if(this.freeze)return;let e=this._frustum;e.update(this.view.state.contentCamera);let t=this._visibleObjects,n=!1;this._loadedObjects.forEach(r=>{let i=r.obb?.intersectsFrustum(e)??!1;i!==r.isVisible&&(r.isVisible=i,i?t.add(r):t.delete(r),r.componentObjects.forEach(e=>this._collection.setObjectVisibility(e,i)),n||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(i,r.elevationRange))}),n&&this._setVisibleElevationRangeDirty()}intersect(e,t,n,r){this._intersectionHandler.intersectRay(e,t,n,r,null,!1)}get ready(){return!this.replacesTerrain||!!this._wasm?.isTerrainReady}_modificationsChanged(){let e=this.useEsriCrs?this.layer.supportedSpatialReferences[1]:this.layer.supportedSpatialReferences[0],t=Oe(this._layerClippingArea,this._modifications,e,this.view.state.isGlobal);this._wasm?.setMeshModifications(this,t)}_clippingAreaChanged(){let e=this.layer.spatialReference,t=pe();this._layerClippingArea=Re(this.view.clippingArea,t,e)?t:null,this._modificationsChanged()}_visibleGeometryChanged(){this._visibleGeometryChangedSchedulerHandle??=d(()=>{this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=null})}_slicePlaneEnabledChange(e){this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e&&!this.replacesTerrain),this.forEachComponentObject(t=>t.updateMaterial({slicePlaneEnabled:e}))}_elevationInfoChanged(e){this._wasm?.setLayerOffset(this,G(e))}get _wasm(){return De(this.view)}_queryElevation(e,t){return this.destroying||this.destroyed?Promise.reject(o()):this._wasm?.queryElevation(this,e,t)??Promise.reject(o())}get wasmLayerId(){return this._wasmLayerId}get metersPerVCSUnit(){return this._metersPerVCSUnit}get usedMemory(){return this._usedMemory}get unloadedMemory(){return 0}get cachedMemory(){return this._cacheMemory}get useEsriCrs(){return this._useEsriCrs}get visibleAtCurrentScale(){return this.replacesTerrain||he(this.layer.effectiveScaleRange,this.view.scale)}canResume(){let e=this.layer&&`effectiveScaleRange`in this.layer?this.layer.effectiveScaleRange:null;return this.visible&&this.layer?.loaded&&this.parent&&!this.parent.suspended&&this.view?.ready&&(this.replacesTerrain||N(e)&&this.visibleAtCurrentScale)&&this.visibleAtCurrentTimeExtent||!1}get performanceInfo(){let e=0,t=0,n=0,r=0,i=0,a=0;return this._lyrHandleToObjects.forEach(o=>{o.isLoaded?(e+=o.textureMemoryUsage,t+=o.vboMemoryUsage,i++):(n+=o.textureMemoryUsage,r+=o.vboMemoryUsage,a++)}),new we(this.usedMemory,i,a,$(t),$(e),$(r),$(n))}_canProjectWithoutEngine(){if(this.view.state.viewingMode===1||P(this.view.renderSpatialReference)||F(this.view.renderSpatialReference))return!0;if(this.layer.esriCrsSpatialReference&&I(this.layer.esriCrsSpatialReference,this.view.renderSpatialReference)){if(this.layer.esriCrsSpatialReference.vcsWkid===115700)return!1;let e=be(this.layer.esriCrsSpatialReference);if(!e){let t=this.layer.esriCrsSpatialReference,n=L(t),r=`meters`;!n&&t.wkid&&t.wkid!==-1&&(r=g(z.units[z[t.wkid]])),r&&(e=new le({heightModel:`gravity-related-height`,heightUnit:r}))}let t=this.view.heightModelInfo;return this._useEsriCrs=me(e,t,!1)===0,this._useEsriCrs&&(e&&(this._metersPerVCSUnit=_(1,e.heightUnit,`meters`)),this.fullExtentInLocalViewSpatialReference=this.layer.esriCrsFullExtent),this._useEsriCrs}return!1}get _stage(){return this.view.stage}get _collection(){return this._stage.renderView.componentObjectCollection}get elevationProvider(){return this._elevationProvider}get elevationOffset(){return G(this.layer.elevationInfo)}get elevationRange(){let e=this.fullExtent;return e?.zmin&&e?.zmax?new K(e.zmin,e.zmax):null}getElevationRange(e){return this._intersectionHandler.getElevationRange(e)}get visibleElevationRange(){let e=new K;this._visibleObjects.size===0?e.setElevationRangeValues(0,0):(e.setElevationRangeValues(1/0,-1/0),this._forEachRelevantVisibleTile(t=>e.expandElevationRange(t.elevationRange)),e.minElevation===1/0&&e.setElevationRangeValues(0,0));let t=this._get(`visibleElevationRange`);return t&&t.minElevation===e.minElevation&&t.maxElevation===e.maxElevation?t:e}_setVisibleElevationRangeDirty(){this.notifyChange(`visibleElevationRange`)}_forEachRelevantVisibleTile(e){let{view:t}=this,{spatialReference:n}=t,r=n.isWGS84||n.isWebMercator||R(n)||oe(n)||se(n);if(this.view.state.isGlobal||!r)return this.forEachVisibleTile(e);let i=M(n).radius,{eye:a,viewForward:o,near:s}=t.state.contentCamera,c=E(A(),o),l=Math.max(a[2],500),u=l+i,d=Math.sqrt(u**2-i**2),f=Math.abs(Math.atan2(d,i))*i,p=l>.5*i?.5*Math.PI*i:f,m=A();this.forEachVisibleTile(t=>{let{mbsRadius:n,mbsCenter:r}=t;if(n<0)return;D(m,r,a);let i=O(m,c);Math.abs(i)<p&&i+n>s&&i-n<p&&e(t)})}get fullExtent(){return this.layer.fullExtent}forEachComponentObject(e){this._forEachObject(this._lyrHandleToObjects.values(),e)}forEachVisibleTile(e){for(let t of this._visibleObjects)e(t)}forEachTile(e){for(let t of this._loadedObjects)e(t)}forEachVisibleComponentObject(e){this._forEachObject(this._visibleObjects,e)}_forEachObject(e,t){for(let{componentObjects:n}of e)for(let e of n)t(e)}get drapeTargetType(){return has(`enable-feature:im-as-ground`)?+!this.usedAsGround:+!this.replacesTerrain}isUpdating(){let e=this._wasm;return!this.freeze&&this._wasmLayerId>=0&&e!=null&&e.isUpdating(this._wasmLayerId)}get readyToRun(){return!!this._frameTask?.readyToRun}runTask(e){this._frameTask.processQueue(e)}updatingFlagChanged(){this.notifyChange(`updating`)}async createRenderable(e){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable called after destroy`);let{entity3d:t}=e;if(!xe(t))throw Error(`entity3D not valid`);let n=new Map,r;try{r=this._createPrimitiveTextureBundles(t,n)}catch(e){throw n.forEach(e=>this._stage?.removeTexture(e)),e}let i=null;try{if(i=await this._createRenderableMain(t,r),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable aborted due to destroyed instance`);let{tileObb:a,componentObjects:o,elevationRange:s}=i,c=0,l=0,u=0;for(let e of o){let{texture:t,textureMetallicRoughness:n,textureEmissive:r,textureOcclusion:i,textureNormal:a}=e.renderable.drawParameters;c+=(t?.usedMemory??0)+(n?.usedMemory??0)+(r?.usedMemory??0)+(i?.usedMemory??0)+(a?.usedMemory??0),l+=this._collection.getObjectGPUMemoryUsage(e),u+=e.intersectionGeometry.usedMemory}let d=Array.from(n.values()),f=new $e(e.handle,o,d,u,l,c,a,e.stableNodeId,e.nodeDepth,s);return this._lyrHandleToObjects.set(e.handle,f),()=>{this._memCache.put(W(f.handle),f);let{usedMemory:e}=f;return this._cacheMemory+=e,{memUsageBytes:e}}}catch(e){throw r.forEach(e=>e.cleanup()),i?.componentObjects.forEach(e=>this._collection.destroyObject(e)),n.forEach(e=>this._stage?.removeTexture(e)),e}}_createPrimitiveTextureBundles(e,t){let n=[];try{let r=e.desc.geometry;for(let i of e.validPrimitiveIndices){let a=r.prims[i].materialId,o=e.desc.materials?.materials&&a!=null&&a!==U?e.desc.materials.materials[a]:null,s=Promise.resolve(tt),c=null,l=null,u=null,d=null,f=null;if(o){let n=o.lightingModel===`Pbr`;c=this._getTexture(o.baseColorTex,e,t),l=n?this._getTexture(o.metalTex,e,t):null,u=n?this._getTexture(o.emissiveTex,e,t):null,d=n?this._getTexture(o.occlusionTex,e,t):null,f=n?this._getTexture(o.normalTex,e,t):null;let r=[c,l,u,d,f].map(e=>e?.loadPromise??null);s=Promise.all(r)}n.push(new nt(s,c,l,u,d,f))}}catch(e){throw n.forEach(e=>e.cleanup()),e}return n}async _createRenderableMain(e,t){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain called after destroy`);let n=[],r=e.desc,i=j(...e.origin),a=this.view.groundView.spatialReference,o=this.view.state.isGlobal,s=C;if(o){let e=w();ue(ce,i,e,a),s=b(S(),e)}let c=et(r.obb),l=o?M(this.view.spatialReference).radius:0,u=[];try{let d=-1;for(let n of e.validPrimitiveIndices){d+=1;let i=r.geometry.prims[n],a=t[d];if(this._dbgFlags.has(2)&&this._dbg(2,JSON.stringify(i)),je[i.ptype]==null){this._dbg(2,`[Unsupported Feature] Unsupported primitive mode (`+i.ptype+`). Skipping primitive.`),a.cleanup();continue}let{positionView:o,normalsData:s,colorView:c,texCoord0Data:l,indicesView:f}=this._getBufferViews(i,e);if(o==null||f==null){a.cleanup();continue}let p=o.count,m=(e,t)=>e!=null&&e!==p?(this._dbg(3,`${t} !== numPos. Skipping primitive.`),!1):!0;!m(l==null?void 0:l.length/2,`numTexcoord`)||!m(c?.count,`numColors`)||!m(s?.length,`normals`)?a.cleanup():u.push({componentIndex:d,positionView:o,indicesView:f,texCoord0Data:l,colorView:c,normalsData:s})}let f=s!==C,p=f?x(S(),s)??C:C,{vertexProcessingOutputs:m,obbHalfSizeAccumulator:h,elevationRange:g}=await this._workerHandle.processTiles3DVertices(u,i,l,o,s,c,this._imVertexNormals&&!this.usedAsGround);if(this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);let _=r.materials;if(await Promise.all(t.map(e=>e.materialPromise)),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);m.length>0&&c.setHalfSize(h);for(let o of m){let{componentIndex:s,positionView:l,indicesView:u,layout:d,textureCoordinateType:m,interleavedVertexData:h,indices:g}=o,v=e.validPrimitiveIndices[s],y=r.geometry.prims[v],b=t[s],x=c.clone(),S=Be(d),C=new Uint32Array([0,u.typedBuffer.length]),w=new He(S,this._imShading?2:0,m,f?2:0),T=new Ue({interleavedVertexData:h,vertexCount:h.byteLength/S[0].stride,indexData:g},{positions:l.typedBuffer,indices:u.typedBuffer},C,w),E=this.view.renderSpatialReference,D=A(),O=[1,1,1];de(i,E,O,a)||this._dbg(3,`Unsupported coordinate system for IM overlay`),fe(i,E,D,a);let k=this._createComponentMaterialInitParameters(_,y.materialId,b);k.baseColorTexture||this._dbg(3,`No colour texture 1`);let j=this._collection.createObject({toMapSpace:re(D[0],D[1],O[0],O[1]),transform:new We(i,p),obb:x,geometry:T,elevationAlignable:!1},k);n.push(j)}let{fullExtent:v}=this.layer;return v?.hasZ&&v.zmax&&v.zmin&&(g.minElevation=Math.max(g.minElevation,v.zmin),g.maxElevation=Math.min(g.maxElevation,v.zmax)),{tileObb:c,componentObjects:n,elevationRange:g}}catch(e){throw n.forEach(e=>this._collection.destroyObject(e)),e}}_createComponentMaterialInitParameters(e,t,n){let r=e?.materials!=null&&t!=null&&t!==U?e.materials[t]:null,i=1,a=r?.baseColorTex?.imageId;if(a!=null&&e&&Array.isArray(e.images)&&a>=0&&a<e.images.length){let t=e.images[a];t.alpha&&(i=Me[t.alpha])}let o=(r==null?`Unlit`:r.lightingModel)===`Pbr`,s=ae,c=X,l=!1,u=2,d=ne(0,0,0),f=ee(q),p=n.baseColorTexture,m=n.metallicRoughnessTexture,h=n.emissionTexture,g=n.occlusionTexture,_=n.normalTexture;return r&&(s=ie(r.baseColorFactor),c=r.alphaCutoff??X,o&&(k(f,r.metallicFactor,r.roughnessFactor,0),r.emissiveFactor&&(d=r.emissiveFactor)),l=r.isDoubleSided,u=Ne[r.faceCulling??`NotSet`]),{isIntegratedMesh:!0,baseColor:s,textureAlphaCutoff:c,mrrFactors:f,baseColorTexture:p,metallicRoughnessTexture:m,normalTexture:_,occlusionTexture:g,emissionTexture:h,hasParametersFromSource:!1,sphereDepthInterpolate:this.layer.hasGoogleUrl,alphaDiscardMode:i,doubleSided:l,cullFace:u,isGround:has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,groundTransparencyMode:this._groundTransparencyMode,emissiveBaseColor:d,usePBR:o,slicePlaneEnabled:this.slicePlaneEnabled,opacity:this._renderOpacity,polygonOffset:0,ellipsoidMode:1,applySSAO:this._applySSAO}}freeRenderable(e){let t=this._lyrHandleToObjects.get(e);t?(t.isLoaded?(this._loadedObjects.delete(t),this._visibleObjects.delete(t),this._intersectionHandler.removeTile(t),this._usedMemory-=t.usedMemory):this._cacheMemory-=t.usedMemory,this.freeObject(t),this._lyrHandleToObjects.delete(e)):this._dbg(3,`freeRendedrable on non-existent renderable ${e}`)}freeObject(e){let t=W(e.handle);this._memCache.pop(t),e.textures.forEach(e=>this._stage.removeTexture(e)),e.componentObjects.forEach(e=>this._collection.destroyObject(e))}setRenderableVisibility(e,t,n){if(this.destroyed||this.destroying)return;let r=this._frustum,i=[],a=!1,o=!1;for(let s=0;s<n;++s){if(!t[s])continue;let n=e[s],c=this._lyrHandleToObjects.get(n);if(c){if(c.isLoaded){this._dbg(3,`Already loaded object marked loaded again ${c.stableNodeId}`);continue}a=!0,c.isLoaded=!0,this._loadedObjects.add(c),this._intersectionHandler.addTile(c),this._usedMemory+=c.usedMemory,this._cacheMemory-=c.usedMemory;let e=c.obb?.intersectsFrustum(r)??!0;c.isVisible=e,e&&(this._visibleObjects.add(c),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(e,c.elevationRange)),i.push(c.obb),c.componentObjects.forEach(t=>{this._collection.setObjectVisibility(t,e)}),this._memCache.pop(W(n))}else this._dbg(3,`Tried to mark Non existent object ${n} as loaded`)}for(let r=0;r<n;++r){let n=e[r];if(t[r])continue;let a=this._lyrHandleToObjects.get(n);if(a){if(!a.isLoaded){this._dbg(3,`Tried to unload not-loaded object ${a.stableNodeId}`);continue}let e=a.isVisible;this._visibleObjects.delete(a),a.isVisible=!1,a.isLoaded=!1,this._loadedObjects.delete(a),this._intersectionHandler.removeTile(a),e&&(this._visibleGeometryChanged(),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(!1,a.elevationRange)),this._usedMemory-=a.usedMemory,this._cacheMemory+=a.usedMemory,i.push(a.obb),a.componentObjects.forEach(e=>{this._collection.setObjectVisibility(e,!1)}),this._memCache.put(W(n),a)}else this._dbg(3,`Tried to mark Non existent object ${n} as not loaded`)}a&&this._visibleGeometryChanged(),i.length>0&&this._elevationProvider.notifyObjectsChanged(i),o&&this._setVisibleElevationRangeDirty()}setLodPixelThreshold(e){this._wasm?.setLodPixelThreshold(this,e)}_isVisibileElevationRangeModifiedByChangedTileVisbility(e,t){let{visibleElevationRange:n}=this,{minElevation:r,maxElevation:i}=t;return e?r<n.minElevation||i>n.maxElevation:r===n.minElevation||i===n.maxElevation}_getTexture(e,t,n){let r=e&&t.desc.materials?.images?.[e.imageId];if(!r||r.data==null||r.data===U)return null;let i=t.assets[r.data];if(!i||i.byteCount<1||i.dataType!==`U8`)return null;let a=n.get(r)??this._createTexture(e,r,i,n);return a?new Ge(this._stage.renderView.textures,a.id):null}_createTexture(e,n,r,i){let a=this._stage.renderView.renderingContext.parameters.maxMaxAnisotropy,o=n.mipCount?!0:a>1,s=Pe[e.wrapMode??`None`],c=n.alpha?6408:6407,l=new Uint8Array(r.data.buffer,0,r.byteCount),u=null,d=null;switch(n.format){case`Raw`:if(n.pixelFormat===`R8`)u=l,c=6403,d=``;else if(n.pixelFormat===`Rg8`||n.pixelFormat===`Ga8`)u=l,c=33319,d=``;else if(n.pixelFormat===`Rgb8`)u=l,c=6407,d=``;else if(n.pixelFormat===`Rgba8`)u=l,c=6408,d=``;else return t.getLogger(this).error(`Raw texture pixel format ${n.pixelFormat} not supported`),null;break;case`Dxt1`:u=l,c=6407,d=`image/vnd-ms.dds`;break;case`Dxt5`:u=l,c=6408,d=`image/vnd-ms.dds`;break;case`Basis`:u=l,c=6407,d=`image/ktx2`;break;case`Etc1`:u=l,c=6407,d=`image/ktx`;break;default:return t.getLogger(this).error(`${n.format} texture not supported`),null}if(u&&d!=null){let e=Ze(c,d,n.format),t=new Ke(u,{mipmap:o,maxAnisotropy:a,encoding:d,wrap:s,pixelFormat:c,internalFormat:e??void 0,immutable:e!=null,noUnpackFlip:!0,width:n.mip0Width,height:n.mip0Height});return this._stage.addTexture(t),i.set(n,t),t}return null}_getBufferViews(e,t){let n,r,i,a;for(let o=0;o<e.atrbs.length;o++){let s=e.atrbs[o],c=t.assets[s.assetId];if(!c)continue;let l=c.data.buffer,u=c.byteCount;try{switch(s.sem){case`Position`:c.ncomp!==3||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Position (`+c+`)`):n=new B(l,0,void 0,u);break;case`Normal`:if(c.ncomp!==3||c.dataType!==`F32`||!p(c.data))this._dbg(3,`[Unsupported Feature] Unsupported view for Normal (`+c+`)`);else{let e=new B(l,0,void 0,u);a=new Uint32Array(e.count),qe(e.typedBuffer,new Int16Array(a.buffer,a.byteOffset,a.length*2))}break;case`TexCoord`:c.ncomp!==2||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Texcoord (`+c+`)`):i===void 0&&(i=new ve(l,0,void 0,u).typedBuffer);break;case`Color`:c.dataType===`U8`&&f(c.data)&&(c.ncomp===4?r=new ge(l,0,void 0,u):c.ncomp===3&&(r=new _e(l,0,void 0,u))),r??this._dbg(3,`[Unsupported Feature] Unsupported view for Color (`+c+`)`);break;case`FeatureIndex`:break;default:this._dbg(2,`[Unsupported Feature] Unsupported semantic (`+s.sem+`). Skipping vertex attribute.`)}}catch(e){this._dbg(2,`Error Creating buffer (`+e+`). Skipping vertex attribute.`)}}let o,s=!1;if(e.index!=null&&e.index!==U){let n=t.assets[e.index];if(!n)s=!0;else{let e=n.byteCount;switch(n.dataType){case`U16`:n.ncomp===1&&h(n.data)&&(o=new H(n.data.buffer,0,void 0,e));break;case`U32`:n.ncomp===1&&m(n.data)&&(o=new V(n.data.buffer,0,void 0,e))}s=!o}}if(!s&&o==null&&n!=null){let e=n.count;o=o=e<65535?new H(new Uint16Array(e).buffer):new V(new Uint32Array(e).buffer);for(let t=0;t<e;t++)o.set(t,t)}return{positionView:n,colorView:r,texCoord0Data:i,indicesView:o,normalsData:a}}_loadModifications(){if(this.removeHandles(`modifications`),this.layer.modifications==null){this._modifications=[];return}let e=this.layer.modifications;this.addHandles(this._updatingHandles.addOnCollectionChange(()=>e,()=>{this._modifications=e.filter(e=>!(this.usedAsGround&&e.type!==`replace`)).toArray(),this._modifications.length<e.length&&t.getLogger(this).info(`Ground layers only support replace modifications. Other modification types have been ignored.`)},s),`modifications`)}_deletePerObjectData(e){this._wasm?.onRenderableEvicted(this,e.handle,e.usedMemory),this.freeRenderable(e.handle)}_dbg(e,n){this._dbgFlags.has(e)&&(e===3?t.getLogger(this).error(n):t.getLogger(this).warn(n))}};e([v()],Q.prototype,`freeze`,void 0),e([v()],Q.prototype,`fullOpacity`,null),e([v()],Q.prototype,`opaque`,null),e([v()],Q.prototype,`invisible`,null),e([v({readOnly:!0})],Q.prototype,`ready`,null),e([v({type:[ye]})],Q.prototype,`_modifications`,void 0),e([v()],Q.prototype,`_visibleGeometryChangedSchedulerHandle`,void 0),e([v()],Q.prototype,`layer`,void 0),e([v({readOnly:!0})],Q.prototype,`visibleAtCurrentScale`,null),e([v({readOnly:!0})],Q.prototype,`_collection`,null),e([v()],Q.prototype,`elevationOffset`,null),e([v({readOnly:!0})],Q.prototype,`visibleElevationRange`,null),e([v()],Q.prototype,`fullExtentInLocalViewSpatialReference`,void 0),Q=e([y(`esri.views.3d.layers.IntegratedMesh3DTilesLayerView3D`)],Q);const Qe=Q;class $e{constructor(e,t,n,r,i,a,o,s,c,l){this.handle=e,this.componentObjects=t,this.textures=n,this.cpuMemoryUsage=r,this.vboMemoryUsage=i,this.textureMemoryUsage=a,this.obb=o,this.stableNodeId=s,this.nodeDepth=c,this.elevationRange=l,this.bvhIntersectionGeneration=0,this.isLoaded=!1,this.isVisible=!1;let u=A();o?.getCenter(u),this._obbCenterX=u[0],this._obbCenterY=u[1],this._obbCenterZ=u[2];let d=o?.radius??-1;this._obbRadius=d,this._obbRadiusSquared=d*d,this._obbShortestHalfsize=o?Math.min(o.halfSizeX,o.halfSizeY,o.halfSizeZ):0,this._mbsCenter=o?o.getCenter(A()):te}get usedMemory(){return this.textureMemoryUsage+this.vboMemoryUsage+this.cpuMemoryUsage}get mbsRadius(){return this._obbRadius}get mbsCenter(){return this._mbsCenter}boundingVolumeIntersectsRay(e,t){if(!this.obb)return!0;let{_obbCenterX:n,_obbCenterY:r,_obbCenterZ:i}=this,a=n-e[0],o=r-e[1],s=i-e[2],c=a*t[0]+o*t[1]+s*t[2];return a*a+o*o+s*s-c*c<=this._obbRadiusSquared&&this.obb.intersectRay(e,t)}boundingVolumeIntersectsSphere(e){let t=this._obbRadius;if(t<0)return!0;let n=e.center,r=e.radius,i=t+r,a=this._obbCenterX-n[0];if(a>i)return!1;let o=this._obbCenterY-n[1];if(o>i)return!1;let s=this._obbCenterZ-n[2];if(s>i)return!1;let c=a*a+o*o+s*s;if(c>i*i)return!1;if(c<=(this._obbShortestHalfsize+r)**2)return!0;let l=r-t;return l>0&&c<=l*l?!0:this.obb?.intersectSphere(e)??!0}}function $(e){return Math.round(e/1048.576)/1e3}function et(e){return new ze(e.center,e.halfSize,T(...e.quaternion))}const tt=[];class nt{constructor(e,t,n,r,i,a){this.materialPromise=e,this.baseColorTexture=t,this.metallicRoughnessTexture=n,this.emissionTexture=r,this.occlusionTexture=i,this.normalTexture=a}cleanup(){this.baseColorTexture?.dispose(),this.metallicRoughnessTexture?.dispose(),this.emissionTexture?.dispose(),this.occlusionTexture?.dispose(),this.normalTexture?.dispose()}}export{Qe 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"../../../core/has.js";import t from"../../../core/Logger.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{estimateNumberArrayMemory as r}from"../../../core/memoryEstimations.js";import{throwIfAborted as i}from"../../../core/promiseUtils.js";import{initial as a,watch as o,sync as s}from"../../../core/reactiveUtils.js";import{generateUID as c}from"../../../core/uid.js";import{property as l,subclass as u}from"../../../core/accessorSupport/decorators.js";import{set as d}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as f,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBuffer as m}from"../../../geometry/projection/projectBuffer.js";import{projectVectorToVector as h}from"../../../geometry/projection/projectVectorToVector.js";import{extentContainsCoords3D as g,extentContainsCoords2D as _}from"../../../geometry/support/contains.js";import{newDoubleArray as v,doubleArrayFrom as ee}from"../../../geometry/support/DoubleArray.js";import{isInEffectiveScaleRange as te}from"../../../geometry/support/scaleUtils.js";import{getGeometryZScaler as ne}from"../../../geometry/support/zscale.js";import{fallbackObjectIDAttribute as re}from"../../../layers/LayerConstants.js";import{estimateSize as ie}from"../../../layers/graphics/dehydratedFeatures.js";import{ImmutableDehydratedPoint as y}from"../../../layers/graphics/dehydratedPoint.js";import{hydrateGraphic as b}from"../../../layers/graphics/hydratedFeatures.js";import x from"../../../layers/graphics/controllers/I3SOnDemandController.js";import ae from"../../../layers/support/FeatureFilter.js";import{I3SExtractChanges as S}from"../../../layers/support/I3SExtractChanges.js";import C from"../../../rest/support/Query.js";import{isBasemapLayerView as oe}from"../../../support/basemapUtils.js";import{isGraphic as se}from"../../../support/graphicInstanceUtils.js";import{I3SPointsWorkerHandle as w}from"./I3SPointsWorkerHandle.js";import{LayerView3D as ce}from"./LayerView3D.js";import{Graphics3DFeatureProcessor as T}from"./graphics/Graphics3DFeatureProcessor.js";import{QueryEngine as E}from"./graphics/QueryEngine.js";import{QueryEngineContext as D}from"./graphics/QueryEngineContext.js";import{createInteractiveEditSession as O,normalizeEditResultsEvent as k,processAttributeEdits as A}from"./i3s/featureEditing.js";import{getCachedAttributeValue as j}from"./i3s/I3SBinaryReader.js";import{I3SGraphicsMap as M}from"./i3s/I3SGraphicsMap.js";import{I3SOverrides as N}from"./i3s/I3SOverrides.js";import{checkRecyclable as P,checkSpatialReferences as F,containsDraco as I,whenGraphicAttributes as L}from"./i3s/I3SUtil.js";import{attributeLookup as R}from"./support/attributeUtils.js";import{DefinitionExpressionSceneLayerView as z}from"./support/DefinitionExpressionSceneLayerView.js";import{defineFieldProperties as B}from"./support/fieldProperties.js";import{normalizeHighlightTarget as V,emptyHighlightHandle as H,isObjectId as U}from"./support/highlightUtils.js";import{LayerViewPerformanceInfo as le}from"./support/LayerViewPerformanceInfo.js";import{PopupSceneLayerView as W}from"./support/PopupSceneLayerView.js";import{SceneLayerViewRequiredFields as ue}from"./support/SceneLayerViewRequiredFields.js";import{TemporalSceneLayerView as de}from"./support/TemporalSceneLayerView.js";import{debugFlags as G}from"../support/debugFlags.js";import{compute as fe}from"../support/orientedBoundingBox.js";import{updatingProgress as pe}from"../support/updatingProperties.js";import{Vertices as me}from"../webgl-engine/lib/Attribute.js";import he from"../../layers/SceneLayerView.js";import{hasPopupTemplate as ge}from"../../layers/support/popupUtils.js";import{getHighlightName as _e}from"../../support/highlightOptionsUtils.js";import{hasLayerBasedScaleVisibility as K}from"../../support/layerViewUtils.js";import{TaskPriority as ve}from"../../support/Scheduler.js";const q=B();class ye{constructor(e,t,n,r){this.graphics=e,this.featureIds=t,this.attributeInfo=n,this.node=r}get usedMemory(){return this.graphics.reduce((e,t)=>ie(t)+e,r(this.featureIds)+1024)}}let J=class extends de(z(W(ce(he)))){constructor(){super(...arguments),this.type=`scene-layer-graphics-3d`,this._queryEngine=null,this._memCache=null,this._interactiveEditingSessions=new Map,this._pendingEditsQueue=Promise.resolve(),this.loadedGraphics=new M((e,t,n)=>Se(e,t,n),e=>this.processor.graphicsCore.recreateGraphics(e),this.logError),this.holeFilling=`always`,this.progressiveLoadFactor=1,this.supportsHeightUnitConversion=!0,this._coordinatesOutsideExtentErrors=0,this._maxCoordinatesOutsideExtentErrors=20}tryRecycleWith(e,t){return e.url!==this.layer.url||!this._i3sOverrides.isEmpty?null:e.load(t).then(()=>{i(t),P(this.layer,e,this._i3sOverrides),this.layer=e,this._reinitializeOverrides(),n(this._queryEngine),this._setupQueryEngine(),this.processor.resetObjectStates()})}initialize(){this.addResolvingPromise(this.layer.indexInfo),this._reinitializeOverrides(),F(this.layer,this.view.spatialReference,this.view.viewingMode),this._fieldsHelper=new ue({layerView:this}),this._updatingHandles.add(()=>this.layer.rangeInfos,e=>this._rangeInfosChanged(e),a),this._updatingHandles.add(()=>this.layer.renderer,(e,t)=>this._rendererChange(e,t)),this._updatingHandles.add(()=>[this.parsedDefinitionExpression,this.layer.excludeObjectIds],()=>this._filterChange()),this._set(`processor`,new T({owner:this,preferredUpdatePolicy:0,scaleVisibilityEnabled:!K(),filterVisibilityEnabled:!0,timeExtentEnabled:!1,frustumVisibilityEnabled:!1,elevationAlignmentEnabled:!0,elevationFeatureExpressionEnabled:!1,setUidToIdOnAdd:!1,dataExtent:this.layer.fullExtent,updateClippingExtent:e=>this._updateClippingExtent(e)})),this.processor.elevationAlignment?.events.on(`invalidate-elevation`,({extent:e,spatialReference:t})=>this._controller.updateElevationChanged(e,t)),this.supportsHeightUnitConversion&&(this._verticalScale=ne(`point`,this.layer.spatialReference,this.view.spatialReference)),this.addResolvingPromise(this.processor.when()),this._memCache=this.view.resourceController.memoryController.newCache(`psl-${this.uid}`),this._controller=new x({layerView:this}),I(this.layer.geometryDefinitions)&&(this._workerHandle=new w(e=>this.view.resourceController.immediate.schedule(e))),this.addHandles(this.layer.on(`apply-edits`,e=>this._updatingHandles.addPromise(e.result))),this.addHandles([this.layer.on(`edits`,e=>{let t=this._pendingEditsQueue.then(()=>this._handleEdits(e)).then();this._pendingEditsQueue=t,this._updatingHandles.consumePromise(t)}),o(()=>G.I3S_TREE_SHOW_TILES,e=>{if(e&&!this._treeDebugger){let e=this._controller.crsIndex;import(`./support/I3STreeDebugger.js`).then(({I3STreeDebugger:t})=>{!this._treeDebugger&&G.I3S_TREE_SHOW_TILES&&(this._treeDebugger=new t({lv:this,view:this.view,nodeSR:e}))})}else!e&&this._treeDebugger&&!G.I3S_TREE_SHOW_TILES&&(this._treeDebugger.destroy(),this._treeDebugger=null)},a)]),this.when(()=>{this._setupQueryEngine(),this._updatingHandles.add(()=>this.availableFields,()=>this._queryEngine?.clear(),s),this._updatingHandles.add(()=>this.maximumNumberOfFeatures,e=>this._controller.featureTarget=e,a),this._updatingHandles.add(()=>this.suspended,e=>{e&&this._removeAllNodeData()})}).catch(()=>{})}_reinitializeOverrides(){this._i3sOverrides?.destroy(),this._extractChanges?.destroy();let{layer:e}=this,t=this.view.resourceController?.memoryController;this._extractChanges=new S({layer:e}),this._i3sOverrides=new N({view:this.view,layer:e,memoryController:t,extractChanges:this._extractChanges})}destroy(){this._treeDebugger=n(this._treeDebugger),this._i3sOverrides=n(this._i3sOverrides),this._extractChanges=n(this._extractChanges),this._set(`processor`,n(this.processor)),this._controller=n(this._controller),this._queryEngine=n(this._queryEngine),this._workerHandle=n(this._workerHandle),this._memCache=n(this._memCache),this.loadedGraphics.clear(),this._fieldsHelper=n(this._fieldsHelper)}get layerViewUid(){return this.uid}get updatingProgressValue(){return this._controller?.updatingProgress??1}get visibleAtCurrentScale(){return K()?te(this.layer.effectiveScaleRange,this.view.scale):!this.processor?.scaleVisibilitySuspended}get requiredFields(){return this._fieldsHelper?.requiredFields??[]}get maximumNumberOfFeatures(){return this.processor?.graphicsCore?.displayFeatureLimit?.maximumNumberOfFeatures??0}set maximumNumberOfFeatures(e){e==null?(this._clearOverride(`maximumNumberOfFeatures`),this._controller.fixedFeatureTarget=!1):(this._override(`maximumNumberOfFeatures`,e),this._controller.fixedFeatureTarget=!0)}get maximumNumberOfFeaturesExceeded(){return!this.suspended&&!!this._controller?.useMaximumNumberOfFeatures&&!this._controller.leavesReached}get _excludeObjectIds(){return new Set(this.layer.excludeObjectIds)}get lodFactor(){return this.layer.semantic===`Labels`?1:this.view.qualitySettings.sceneService.pointLoDFactor}get hasM(){return!1}get hasZ(){return!0}get contentVisible(){return!this.suspended&&!!this._controller?.rootNodeVisible}get legendEnabled(){return this.contentVisible&&this.layer?.legendEnabled===!0}get _graphicOrigin(){return this.layer.graphicOrigin}async whenGraphicAttributes(e,t){return L(this.layer,e,this._getObjectIdField(),t,()=>[...this.loadedGraphics.nodes()])}getHit(e){if(!this.loadedGraphics)return null;let t=b(this.loadedGraphics.find(t=>t.uid===e),this.layer,this._graphicOrigin),n=this._getObjectIdField();return t?.attributes?.[n]==null?null:{type:`graphic`,graphic:t,layer:t.layer}}whenGraphicBounds(e,t){return this.processor.whenGraphicBounds(e,t)}computeAttachmentOrigin(e,t){return this.processor.computeAttachmentOrigin(e,t)}isUpdating(){return!!(this._controller?.updating||this.processor?.updating||this._fieldsHelper?.updating||this.layerFilterUpdating)}highlight(e,t){let n=_e(t),r=this.layer.objectIdField,i=V(e);if(i.length===0)return H;if(se(i[0])){let e=i;if(R(this.layer.fieldsIndex,e[0].attributes,r)!=null){let t=e.map(e=>R(this.layer.fieldsIndex,e.attributes,r));return this.processor.highlightByObjectIds(t,r,n)}return this.processor.highlightByGraphics(e,n)}return U(i[0])?this.processor.highlightByObjectIds(i,r,n):H}get updatePolicy(){return this.processor.graphicsCore.effectiveUpdatePolicy}createInteractiveEditSession(e){return O(this._attributeEditingContext,e)}async _decompressBinaryPointData(e,t){let n={geometryBuffer:e.geometryBuffer};this._workerHandle??=new w(e=>this.view.resourceController.immediate.schedule(e));let r=await this._workerHandle.invoke(n,t);if(r==null)throw Error(`Failed to decompress Draco point data`);return{positionData:r.positions,featureIds:r.featureIds}}async addNode(e,n,r){if(!Y(n)&&!xe(n))throw Error();if(this.loadedGraphics.hasNode(e.index)){t.getLogger(this).error(`I3S node `+e.id+` already added`);return}let i=this.layer.fullExtent==null?null:Ce(this.layer.fullExtent.clone(),.5),{featureIds:a,pointPositions:o}=Y(n)?await this._extractBinaryPointPositions(e,n,r):this._extractLegacyPointPositions(n),s=[];this._validatePositions(e,a,o,i,s);let c=this._controller.crsVertex,l=this.view.spatialReference;m(o,c,0,o,l,0,a.length);let u=Y(n)?e.level:0,d=this._createGraphics(a,o,e.index,u),f=new ye(d,a,n.attributeDataInfo,e);if(await this._i3sOverrides.applyAttributeOverrides(f.featureIds,n.attributeDataInfo,r),e.numFeatures=f.graphics.length,this._updateNodeMemory(e),X(f),s.length>0&&(this._computeObb(e,s,c),this._controller.updateVisibility(e.index)),!this._controller.isGeometryVisible(e)){this._cacheNodeData(f);return}if(this._verticalScale!=null)for(let e of f.graphics)this._verticalScale(e.geometry);let p=this.view.stage.renderView.olidRenderHelper;if(p){let e=oe(this.view,this.uid);for(let t=0;t<f.featureIds.length;t++){let n=f.featureIds[t];p.setUidToObjectAndLayerId(n,f.graphics[t].uid,this.layer.id,this.uid,this.layer.popupEnabled&&!e&&ge(this.layer,this.view.popup?.defaultPopupTemplateEnabled),f.node.resources.attributes,t)}}this.loadedGraphics.addNode(e.index,f),this._controller.updateLoadStatus(e.index,!0),this._filterNode(f),this._treeDebugger&&this._treeDebugger.update()}_computeObb(e,t,n){let r=this._controller.crsIndex,i=r.isGeographic?this.view.renderSpatialReference:r;m(t,n,0,t,i,0),e.serviceObbInIndexSR=fe(new me(t,3)),r.isGeographic&&(h(e.serviceObbInIndexSR.getCenter(Z),i,Z,r),e.serviceObbInIndexSR.setCenter(Z))}isNodeLoaded(e){return this.loadedGraphics.hasNode(e)}isNodeReloading(){return!1}updateNodeState(){}getNodeComponentHandle(){}async _extractBinaryPointPositions(e,t,n){let r=await this._decompressBinaryPointData(t,n),i=r.positionData,a=i.length/3,o=v(a*3),s=e.serviceObbInIndexSR==null?f:e.serviceObbInIndexSR.getCenter(Te),c=Math.abs(s[2])*2**-20;for(let e=0;e<a;e++){let t=e*3;o[t]=i[t]+s[0],o[t+1]=i[t+1]+s[1],o[t+2]=i[t+2]+s[2],Math.abs(o[t+2])<c&&(o[t+2]=0)}return{featureIds:r.featureIds?ee(r.featureIds):[],pointPositions:o}}_extractLegacyPointPositions(e){let t=e.pointData.length,n=v(3*t),r=[];for(let i=0;i<t;i++){let t=e.pointData[i],a=t.featureDataPosition,o=a.length,s=t.geometries?.[0]??we[o],c=t.featureIds[0];if(s.type!==`Embedded`||s.params.type!==`points`||o<2||o>3)continue;let l=s.params.vertexAttributes?.position??[0,0,0],u=r.length*3;n[u]=a[0]+l[0],n[u+1]=a[1]+l[1],n[u+2]=o===3?a[2]+l[2]:NaN,r.push(c)}return{featureIds:r,pointPositions:n}}_validatePositions(e,n,r,i,a){if(i==null&&e.serviceObbInIndexSR)return;let o=n.length;for(let n=0;n<o;n++){let o=n*3;d(Z,r[o],r[o+1],r[o+2]);let s=!Number.isNaN(r[2]);i!=null&&(s?!g(i,Z):!_(i,Z))&&(this._coordinatesOutsideExtentErrors<this._maxCoordinatesOutsideExtentErrors&&t.getLogger(this).error(`Service Error: Coordinates outside of layer extent`),this._coordinatesOutsideExtentErrors+1===this._maxCoordinatesOutsideExtentErrors&&t.getLogger(this).error(`Maximum number of errors reached. Further errors are ignored.`),this._coordinatesOutsideExtentErrors++),e.serviceObbInIndexSR||a.push(Z[0],Z[1],Z[2])}}_createGraphics(e,t,n,r){let i=e.length,a=this._getObjectIdField(),o=this.processor.graphicsCore,s=[],l=this.view.spatialReference;for(let u=0;u<i;u++){let i=e[u],d={};i!=null&&(d[a]=i);let f=i??c(),p=u*3,m=isNaN(t[p+2])?void 0:t[p+2],h=new y(l,t[p],t[p+1],m),g=this.loadedGraphics.get(f);if(g!=null)(g.level==null||g.level<r)&&(Q.property=`geometry`,Q.graphic=g,Q.oldValue=g.geometry,Q.newValue=h,g.geometry=h,g.level=r,o.graphicUpdateHandler(Q),$()),s.push(g);else{let e=c();s.push({objectId:f,uid:e,geometry:h,attributes:d,visible:!0,nodeIndex:n,level:r})}}return s}_updateNodeMemory(e){e.memory=4096+(e.numFeatures??0)*this.processor.graphicsCore.usedMemoryPerGraphic}_cacheNodeData(e){this._memCache.put(this._getMemCacheKey(e.node),e)}_getMemCacheKey(e){return`${e.index}`}_removeAllNodeData(){this.loadedGraphics.forEachNode((e,t)=>{if(e){let t=e.node;this._updateNodeMemory(t),this._cacheNodeData(e)}this._controller.updateLoadStatus(t,!1)}),this._treeDebugger&&this._treeDebugger.update(),this.loadedGraphics.clear()}removeNode(e){let t=this._removeNodeStageData(e);t&&(this._updateNodeMemory(t.node),this._cacheNodeData(t))}_removeNodeStageData(e){let t=this.loadedGraphics.getNode(e);return t==null?null:(this._controller.updateLoadStatus(e,!1),this.loadedGraphics.removeNode(e),this._treeDebugger&&this._treeDebugger.update(),t)}async loadCachedNodeData(e){return this._memCache?.pop(this._getMemCacheKey(e))}async addCachedNodeData(e,n,r,i){this.loadedGraphics.hasNode(e.index)?t.getLogger(this).error(`I3S node `+e.id+` already added`):(await this._i3sOverrides.applyAttributeOverrides(n.featureIds,r,i),n.attributeInfo=r,this.loadedGraphics.addNode(e.index,n),this._controller.updateLoadStatus(e.index,!0),this._updateNodeMemory(e),X(n),this._filterNode(n),this._treeDebugger&&this._treeDebugger.update())}getLoadedNodeIds(){let e=[];return this.loadedGraphics.forEachNode(t=>e.push(t.node.id)),e.sort()}getVisibleNodes(){let e=[];return this.loadedGraphics.forEachNode(t=>e.push(t.node)),e}getLoadedNodeIndices(e){this.loadedGraphics.forEachNode((t,n)=>e.push(n))}getLoadedAttributes(e){let t=this.loadedGraphics.getNode(e);if(t?.attributeInfo!=null)return t.attributeInfo.loadedAttributes}getAttributeData(e){let t=this.loadedGraphics.getNode(e);if(t?.attributeInfo!=null)return t.attributeInfo.attributeData}_setAttributeData(e,t){let n=this.loadedGraphics.getNode(e);n?.attributeInfo!=null&&(n.attributeInfo.attributeData=t,this._attributeValuesChanged(n))}async updateAttributes(e,t,n){let r=this.loadedGraphics.getNode(e);r!=null&&(await this._i3sOverrides.applyAttributeOverrides(r.featureIds,t,n),r.attributeInfo=t,this._attributeValuesChanged(r))}_attributeValuesChanged(e){X(e),this._filterNode(e);let{processor:t}=this,{graphicsCore:n}=t;if(n.labelsEnabled){let t=e.node.index,r=[];e.graphics.forEach(e=>e.nodeIndex===t&&r.push(e.uid)),n.updateLabelingInfo(r)}t.refreshFilter()}_updateClippingExtent(e){return this._controller&&this._controller.updateClippingArea(e),!1}_getObjectIdField(){return this.layer.objectIdField||re}_getGlobalIdField(){return this.layer.globalIdField}async _rendererChange(e,t){let{layer:{fieldsIndex:n}}=this,r=new Set,i;e?(await e.collectRequiredFields(r,n),i=Array.from(r).sort()):i=[],r.clear();let a;t?(await t.collectRequiredFields(r,n),a=Array.from(r).sort()):a=[],!(i.length===a.length&&i.every((e,t)=>i[t]===a[t]))&&this._reloadAllNodes()}_rangeInfosChanged(e){e!=null&&e.length>0&&t.getLogger(this).warn(`Unsupported property: rangeInfos are currently only serialized to and from web scenes but do not affect rendering.`)}_filterChange(){this.loadedGraphics.forEachNode(e=>this._filterNode(e))}_reloadAllNodes(){this._removeAllNodeData(),this._controller&&this._controller.restartNodeLoading()}_filterNode(e){let t=this.parsedDefinitionExpression,n=this._excludeObjectIds,r=this._getObjectIdField();for(let i of e.graphics){let e=i.visible,a=this._evaluateClause(t,i),o=!n.has(i.attributes[r]);i.visible=a&&o,e!==i.visible&&(Q.graphic=i,Q.property=`visible`,Q.oldValue=e,Q.newValue=i.visible,this.processor.graphicsCore.graphicUpdateHandler(Q),$())}}createQuery(){let e={outFields:[`*`],returnGeometry:!0,outSpatialReference:this.view.spatialReference};return this.filter?.createQuery(e)??new C(e)}queryFeatures(e,t){return this._queryEngine.executeQuery(this._ensureQuery(e),t?.signal)}queryObjectIds(e,t){return this._queryEngine.executeQueryForIds(this._ensureQuery(e),t?.signal)}queryFeatureCount(e,t){return this._queryEngine.executeQueryForCount(this._ensureQuery(e),t?.signal)}queryExtent(e,t){return this._queryEngine.executeQueryForExtent(this._ensureQuery(e),t?.signal)}_ensureQuery(e){return this._addDefinitionExpressionToQuery(e==null?this.createQuery():C.from(e))}_setupQueryEngine(){let{layer:e,view:t,hasM:n,hasZ:r}=this,{spatialReference:i,resourceController:a}=t,o=new D(i,e,a,()=>this.processor.featureStore,r,n,()=>this.availableFields);this._queryEngine=new E({context:o,priority:ve.FEATURE_QUERY_ENGINE})}get usedMemory(){return this.processor?.graphicsCore?.usedMemory??0}get unloadedMemory(){return((this._controller?.unloadedMemoryEstimate??0)+(this.processor?.graphicsCore?.unprocessedMemoryEstimate??0))*.8}get ignoresMemoryFactor(){return this._controller&&this._controller.fixedFeatureTarget}async _handleEdits(e){let t=this._attributeEditingContext,n=await k(t,e);A(t,n)}get _attributeEditingContext(){let e=this._getObjectIdField(),t=this._getGlobalIdField();return{sessions:this._interactiveEditingSessions,fieldsIndex:this.layer.fieldsIndex,objectIdField:e,globalIdField:t,forEachNode:e=>this.loadedGraphics.forEachNode(t=>e(t.node,t.featureIds)),attributeStorageInfo:this.layer.attributeStorageInfo??[],i3sOverrides:this._i3sOverrides,getAttributeData:e=>this.getAttributeData(e),setAttributeData:(t,n,r)=>{this._setAttributeData(t,n);let i=this.loadedGraphics.getNode(t);if(r!=null){let t=this.loadedGraphics.get(r.attributes[e]);t!=null&&this.processor.graphicsCore.recreateGraphics([t])}else i!=null&&this.processor.graphicsCore.recreateGraphics(i.graphics)},clearMemCache:()=>{}}}get performanceInfo(){return new le(this.usedMemory,this.loadedGraphics.length,-1,this.maximumNumberOfFeatures,this.loadedGraphics.nodeCount,this.processor.graphicsCore.performanceInfo)}get test(){}};e([l()],J.prototype,`processor`,void 0),e([l({type:ae})],J.prototype,`filter`,void 0),e([l()],J.prototype,`loadedGraphics`,void 0),e([l()],J.prototype,`layerViewUid`,null),e([l()],J.prototype,`_controller`,void 0),e([l()],J.prototype,`updating`,void 0),e([l()],J.prototype,`suspended`,void 0),e([l(pe)],J.prototype,`updatingProgress`,void 0),e([l()],J.prototype,`updatingProgressValue`,null),e([l({readOnly:!0})],J.prototype,`visibleAtCurrentScale`,null),e([l(q.requiredFields)],J.prototype,`requiredFields`,null),e([l(q.availableFields)],J.prototype,`availableFields`,void 0),e([l()],J.prototype,`_fieldsHelper`,void 0),e([l({type:Number})],J.prototype,`maximumNumberOfFeatures`,null),e([l({readOnly:!0})],J.prototype,`maximumNumberOfFeaturesExceeded`,null),e([l()],J.prototype,`_excludeObjectIds`,null),e([l({readOnly:!0})],J.prototype,`lodFactor`,null),e([l({readOnly:!0})],J.prototype,`hasM`,null),e([l({readOnly:!0})],J.prototype,`hasZ`,null),e([l()],J.prototype,`contentVisible`,null),e([l({readOnly:!0})],J.prototype,`legendEnabled`,null),e([l()],J.prototype,`_graphicOrigin`,null),J=e([u(`esri.views.3d.layers.SceneLayerGraphicsView3D`)],J);const be=J;function xe(e){return`pointData`in e}function Y(e){return`geometryBuffer`in e&&e.geometryBuffer!==null}function Se(e,t,n){let r=t.attributeInfo;if(r?.loadedAttributes==null||r.attributeData==null)return!1;let i=!1;for(let{name:t}of r.loadedAttributes)if(r.attributeData[t]){let a=j(r.attributeData[t],n);a!==e.attributes[t]&&(e.attributes[t]=a,i=!0)}return i}function X(e){let t=e.attributeInfo;if(t?.loadedAttributes==null||t.attributeData==null)return;let n=e.node.index;for(let r=0;r<e.graphics.length;r++){let i=e.graphics[r];if(i.nodeIndex===n){i.attributes||={};for(let{name:e}of t.loadedAttributes)t.attributeData[e]&&(i.attributes[e]=j(t.attributeData[e],r))}}}function Ce(e,t){return e.xmin-=t,e.ymin-=t,e.xmax+=t,e.ymax+=t,e.zmin!=null&&e.zmax!=null&&(e.zmin-=t,e.zmax+=t),e.mmin!=null&&e.mmax!=null&&(e.mmin-=t,e.mmax+=t),e}const we={2:{type:`Embedded`,params:{type:`points`,vertexAttributes:{position:[0,0]}}},3:{type:`Embedded`,params:{type:`points`,vertexAttributes:{position:[0,0,0]}}}},Z=p(),Q={graphic:null,property:null,oldValue:null,newValue:null},Te=p();function $(){Q.graphic=null,Q.property=null,Q.oldValue=null,Q.newValue=null}export{be as default};
2
+ import{__decorate as e}from"tslib";import"../../../core/has.js";import t from"../../../core/Logger.js";import{destroyMaybe as n}from"../../../core/maybe.js";import{estimateNumberArrayMemory as r}from"../../../core/memoryEstimations.js";import{throwIfAborted as i}from"../../../core/promiseUtils.js";import{initial as a,watch as o,sync as s}from"../../../core/reactiveUtils.js";import{generateUID as c}from"../../../core/uid.js";import{property as l,subclass as u}from"../../../core/accessorSupport/decorators.js";import{set as d}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as f,create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectBuffer as m}from"../../../geometry/projection/projectBuffer.js";import{projectVectorToVector as h}from"../../../geometry/projection/projectVectorToVector.js";import{extentContainsCoords3D as g,extentContainsCoords2D as _}from"../../../geometry/support/contains.js";import{newDoubleArray as v,doubleArrayFrom as ee}from"../../../geometry/support/DoubleArray.js";import{isInEffectiveScaleRange as te}from"../../../geometry/support/scaleUtils.js";import{getGeometryZScaler as ne}from"../../../geometry/support/zscale.js";import{fallbackObjectIDAttribute as re}from"../../../layers/LayerConstants.js";import{estimateSize as ie}from"../../../layers/graphics/dehydratedFeatures.js";import{ImmutableDehydratedPoint as y}from"../../../layers/graphics/dehydratedPoint.js";import{hydrateGraphic as b}from"../../../layers/graphics/hydratedFeatures.js";import x from"../../../layers/graphics/controllers/I3SOnDemandController.js";import ae from"../../../layers/support/FeatureFilter.js";import{I3SExtractChanges as S}from"../../../layers/support/I3SExtractChanges.js";import C from"../../../rest/support/Query.js";import{isBasemapLayerView as oe}from"../../../support/basemapUtils.js";import{isGraphic as se}from"../../../support/graphicInstanceUtils.js";import{I3SPointsWorkerHandle as w}from"./I3SPointsWorkerHandle.js";import{LayerView3D as ce}from"./LayerView3D.js";import{Graphics3DFeatureProcessor as T}from"./graphics/Graphics3DFeatureProcessor.js";import{QueryEngine as E}from"./graphics/QueryEngine.js";import{QueryEngineContext as D}from"./graphics/QueryEngineContext.js";import{createInteractiveEditSession as O,normalizeEditResultsEvent as k,processAttributeEdits as A}from"./i3s/featureEditing.js";import{getCachedAttributeValue as j}from"./i3s/I3SBinaryReader.js";import{I3SGraphicsMap as M}from"./i3s/I3SGraphicsMap.js";import{I3SOverrides as N}from"./i3s/I3SOverrides.js";import{checkRecyclable as P,checkSpatialReferences as F,containsDraco as I,whenGraphicAttributes as L}from"./i3s/I3SUtil.js";import{attributeLookup as R}from"./support/attributeUtils.js";import{DefinitionExpressionSceneLayerView as z}from"./support/DefinitionExpressionSceneLayerView.js";import{defineFieldProperties as B}from"./support/fieldProperties.js";import{normalizeHighlightTarget as V,emptyHighlightHandle as H,isObjectId as U}from"./support/highlightUtils.js";import{LayerViewPerformanceInfo as le}from"./support/LayerViewPerformanceInfo.js";import{PopupSceneLayerView as W}from"./support/PopupSceneLayerView.js";import{SceneLayerViewRequiredFields as ue}from"./support/SceneLayerViewRequiredFields.js";import{TemporalSceneLayerView as de}from"./support/TemporalSceneLayerView.js";import{debugFlags as G}from"../support/debugFlags.js";import{compute as fe}from"../support/orientedBoundingBox.js";import{updatingProgress as pe}from"../support/updatingProperties.js";import{Vertices as me}from"../webgl-engine/lib/Attribute.js";import he from"../../layers/SceneLayerView.js";import{hasPopupTemplate as ge}from"../../layers/support/popupUtils.js";import{getHighlightName as _e}from"../../support/highlightOptionsUtils.js";import{hasLayerBasedScaleVisibility as K}from"../../support/layerViewUtils.js";import{TaskPriority as ve}from"../../support/Scheduler.js";const q=B();class ye{constructor(e,t,n,r){this.graphics=e,this.featureIds=t,this.attributeInfo=n,this.node=r}get usedMemory(){return this.graphics.reduce((e,t)=>ie(t)+e,r(this.featureIds)+1024)}}let J=class extends de(z(W(ce(he)))){constructor(){super(...arguments),this.type=`scene-layer-graphics-3d`,this._queryEngine=null,this._memCache=null,this._interactiveEditingSessions=new Map,this._pendingEditsQueue=Promise.resolve(),this.loadedGraphics=new M((e,t,n)=>Se(e,t,n),e=>this.processor.graphicsCore.recreateGraphics(e),this.logError),this.holeFilling=`always`,this.progressiveLoadFactor=1,this.supportsHeightUnitConversion=!0,this._coordinatesOutsideExtentErrors=0,this._maxCoordinatesOutsideExtentErrors=20}tryRecycleWith(e,t){return e.url!==this.layer.url||!this._i3sOverrides.isEmpty?null:e.load(t).then(()=>{i(t),P(this.layer,e,this._i3sOverrides),this.layer=e,this._reinitializeOverrides(),n(this._queryEngine),this._setupQueryEngine(),this.processor.resetObjectStates()})}initialize(){this.addResolvingPromise(this.layer.indexInfo),this._reinitializeOverrides(),F(this.layer,this.view.spatialReference,this.view.viewingMode),this._fieldsHelper=new ue({layerView:this}),this._updatingHandles.add(()=>this.layer.rangeInfos,e=>this._rangeInfosChanged(e),a),this._updatingHandles.add(()=>this.layer.renderer,(e,t)=>this._rendererChange(e,t)),this._updatingHandles.add(()=>[this.parsedDefinitionExpression,this.layer.excludeObjectIds],()=>this._filterChange()),this._set(`processor`,new T({owner:this,preferredUpdatePolicy:0,scaleVisibilityEnabled:!K(),filterVisibilityEnabled:!0,timeExtentEnabled:!1,frustumVisibilityEnabled:!1,elevationAlignmentEnabled:!0,elevationFeatureExpressionEnabled:!1,setUidToIdOnAdd:!1,dataExtent:this.layer.fullExtent,updateClippingExtent:e=>this._updateClippingExtent(e)})),this.processor.elevationAlignment?.events.on(`invalidate-elevation`,({extent:e,spatialReference:t})=>this._controller.updateElevationChanged(e,t)),this.supportsHeightUnitConversion&&(this._verticalScale=ne(`point`,this.layer.spatialReference,this.view.spatialReference)),this.addResolvingPromise(this.processor.when()),this._memCache=this.view.resourceController.memoryController.newCache(`psl-${this.uid}`),this._controller=new x({layerView:this}),I(this.layer.geometryDefinitions)&&(this._workerHandle=new w(e=>this.view.resourceController.immediate.schedule(e))),this.addHandles(this.layer.on(`apply-edits`,e=>this._updatingHandles.addPromise(e.result))),this.addHandles([this.layer.on(`edits`,e=>{let t=this._pendingEditsQueue.then(()=>this._handleEdits(e)).then();this._pendingEditsQueue=t,this._updatingHandles.consumePromise(t)}),o(()=>G.I3S_TREE_SHOW_TILES,e=>{if(e&&!this._treeDebugger){let e=this._controller.crsIndex;import(`./support/I3STreeDebugger.js`).then(({I3STreeDebugger:t})=>{!this._treeDebugger&&G.I3S_TREE_SHOW_TILES&&(this._treeDebugger=new t({lv:this,view:this.view,nodeSR:e}))})}else!e&&this._treeDebugger&&!G.I3S_TREE_SHOW_TILES&&(this._treeDebugger.destroy(),this._treeDebugger=null)},a)]),this.when(()=>{this._setupQueryEngine(),this._updatingHandles.add(()=>this.availableFields,()=>this._queryEngine?.clear(),s),this._updatingHandles.add(()=>this.maximumNumberOfFeatures,e=>this._controller.featureTarget=e,a),this._updatingHandles.add(()=>this.suspended,e=>{e&&this._removeAllNodeData()})}).catch(()=>{})}_reinitializeOverrides(){this._i3sOverrides?.destroy(),this._extractChanges?.destroy();let{layer:e}=this,t=this.view.resourceController?.memoryController;this._extractChanges=new S({layer:e}),this._i3sOverrides=new N({view:this.view,layer:e,memoryController:t,extractChanges:this._extractChanges})}destroy(){this._treeDebugger=n(this._treeDebugger),this._i3sOverrides=n(this._i3sOverrides),this._extractChanges=n(this._extractChanges),this._set(`processor`,n(this.processor)),this._controller=n(this._controller),this._queryEngine=n(this._queryEngine),this._workerHandle=n(this._workerHandle),this._memCache=n(this._memCache),this.loadedGraphics.clear(),this._fieldsHelper=n(this._fieldsHelper)}get layerViewUid(){return this.uid}get updatingProgressValue(){return this._controller?.updatingProgress??1}get visibleAtCurrentScale(){return K()?te(this.layer.effectiveScaleRange,this.view.scale):!this.processor?.scaleVisibilitySuspended}get requiredFields(){return this._fieldsHelper?.requiredFields??[]}get maximumNumberOfFeatures(){return this.processor?.graphicsCore?.displayFeatureLimit?.maximumNumberOfFeatures??0}set maximumNumberOfFeatures(e){e==null?(this._clearOverride(`maximumNumberOfFeatures`),this._controller.fixedFeatureTarget=!1):(this._override(`maximumNumberOfFeatures`,e),this._controller.fixedFeatureTarget=!0)}get maximumNumberOfFeaturesExceeded(){return!this.suspended&&!!this._controller?.useMaximumNumberOfFeatures&&!this._controller.leavesReached}get _excludeObjectIds(){return new Set(this.layer.excludeObjectIds)}get lodFactor(){return this.layer.semantic===`Labels`?1:this.view.qualitySettings.sceneService.pointLoDFactor}get hasM(){return!1}get hasZ(){return!0}get contentVisible(){return!this.suspended&&!!this._controller?.rootNodeVisible}get legendEnabled(){return this.contentVisible&&this.layer?.legendEnabled===!0}get _graphicOrigin(){return this.layer.graphicOrigin}async whenGraphicAttributes(e,t){return L(this.layer,e,this._getObjectIdField(),t,()=>[...this.loadedGraphics.nodes()])}getHit(e){if(!this.loadedGraphics)return null;let t=b(this.loadedGraphics.find(t=>t.uid===e),this.layer,this._graphicOrigin),n=this._getObjectIdField();return t?.attributes?.[n]==null?null:{type:`graphic`,graphic:t,layer:t.layer}}whenGraphicBounds(e,t){return this.processor.whenGraphicBounds(e,t)}computeAttachmentOrigin(e,t){return this.processor.computeAttachmentOrigin(e,t)}isUpdating(){return!!(this._controller?.updating||this.processor?.updating||this._fieldsHelper?.updating||this.layerFilterUpdating)}highlight(e,t){let n=_e(t),r=this.layer.objectIdField,i=V(e);if(i.length===0)return H;if(se(i[0])){let e=i;if(R(this.layer.fieldsIndex,e[0].attributes,r)!=null){let t=e.map(e=>R(this.layer.fieldsIndex,e.attributes,r));return this.processor.highlightByObjectIds(t,r,n)}return this.processor.highlightByGraphics(e,n)}return U(i[0])?this.processor.highlightByObjectIds(i,r,n):H}get updatePolicy(){return this.processor.graphicsCore.effectiveUpdatePolicy}createInteractiveEditSession(e){return O(this._attributeEditingContext,e)}async _decompressBinaryPointData(e,t){let n={geometryBuffer:e.geometryBuffer};this._workerHandle??=new w(e=>this.view.resourceController.immediate.schedule(e));let r=await this._workerHandle.invoke(n,t);if(r==null)throw Error(`Failed to decompress Draco point data`);return{positionData:r.positions,featureIds:r.featureIds}}async addNode(e,n,r){if(!Y(n)&&!xe(n))throw Error();if(this.loadedGraphics.hasNode(e.index)){t.getLogger(this).error(`I3S node `+e.id+` already added`);return}let i=this.layer.fullExtent==null?null:Ce(this.layer.fullExtent.clone(),.5),{featureIds:a,pointPositions:o}=Y(n)?await this._extractBinaryPointPositions(e,n,r):this._extractLegacyPointPositions(n),s=[];this._validatePositions(e,a,o,i,s);let c=this._controller.crsVertex,l=this.view.spatialReference;m(o,c,0,o,l,0,a.length);let u=Y(n)?e.level:0,d=this._createGraphics(a,o,e.index,u),f=new ye(d,a,n.attributeDataInfo,e);if(await this._i3sOverrides.applyAttributeOverrides(f.featureIds,n.attributeDataInfo,r),e.numFeatures=f.graphics.length,this._updateNodeMemory(e),X(f),s.length>0&&(this._computeObb(e,s,c),this._controller.updateVisibility(e.index)),!this._controller.isGeometryVisible(e)){this._cacheNodeData(f);return}if(this._verticalScale!=null)for(let e of f.graphics)this._verticalScale(e.geometry);let p=this.view.stage.renderView.olidRenderHelper;if(p){let e=oe(this.view,this.uid);for(let t=0;t<f.featureIds.length;t++){let n=f.featureIds[t];p.setUidToObjectAndLayerId(n,f.graphics[t].uid,this.layer.id,this.uid,this.layer.popupEnabled&&!e&&ge(this.layer,this.view.popup?.defaultPopupTemplateEnabled),f.node.resources.attributes,t)}}this.loadedGraphics.addNode(e.index,f),this._controller.updateLoadStatus(e.index,!0),this._filterNode(f),this._treeDebugger&&this._treeDebugger.update()}_computeObb(e,t,n){let r=this._controller.crsIndex,i=r.isGeographic?this.view.renderSpatialReference:r;m(t,n,0,t,i,0),e.serviceObbInIndexSR=fe(new me(t,3)),r.isGeographic&&(h(e.serviceObbInIndexSR.getCenter(Z),i,Z,r),e.serviceObbInIndexSR.setCenter(Z))}isNodeLoaded(e){return this.loadedGraphics.hasNode(e)}isNodeReloading(){return!1}updateNodeState(){}getNodeComponentHandle(){}async _extractBinaryPointPositions(e,t,n){let r=await this._decompressBinaryPointData(t,n),i=r.positionData,a=i.length/3,o=v(a*3),s=e.serviceObbInIndexSR==null?f:e.serviceObbInIndexSR.getCenter(Te),c=Math.abs(s[2])*2**-20;for(let e=0;e<a;e++){let t=e*3;o[t]=i[t]+s[0],o[t+1]=i[t+1]+s[1],o[t+2]=i[t+2]+s[2],Math.abs(o[t+2])<c&&(o[t+2]=0)}return{featureIds:r.featureIds?ee(r.featureIds):[],pointPositions:o}}_extractLegacyPointPositions(e){let t=e.pointData.length,n=v(3*t),r=[];for(let i=0;i<t;i++){let t=e.pointData[i],a=t.featureDataPosition,o=a.length,s=t.geometries?.[0]??we[o],c=t.featureIds[0];if(s.type!==`Embedded`||s.params.type!==`points`||o<2||o>3)continue;let l=s.params.vertexAttributes?.position??[0,0,0],u=r.length*3;n[u]=a[0]+l[0],n[u+1]=a[1]+l[1],n[u+2]=o===3?a[2]+l[2]:NaN,r.push(c)}return{featureIds:r,pointPositions:n}}_validatePositions(e,n,r,i,a){if(i==null&&e.serviceObbInIndexSR)return;let o=n.length;for(let n=0;n<o;n++){let o=n*3;d(Z,r[o],r[o+1],r[o+2]);let s=!Number.isNaN(r[2]);i!=null&&(s?!g(i,Z):!_(i,Z))&&(this._coordinatesOutsideExtentErrors<this._maxCoordinatesOutsideExtentErrors&&t.getLogger(this).error(`Service Error: Coordinates outside of layer extent`),this._coordinatesOutsideExtentErrors+1===this._maxCoordinatesOutsideExtentErrors&&t.getLogger(this).error(`Maximum number of errors reached. Further errors are ignored.`),this._coordinatesOutsideExtentErrors++),e.serviceObbInIndexSR||a.push(Z[0],Z[1],Z[2])}}_createGraphics(e,t,n,r){let i=e.length,a=this._getObjectIdField(),o=this.processor.graphicsCore,s=[],l=this.view.spatialReference;for(let u=0;u<i;u++){let i=e[u],d={};i!=null&&(d[a]=i);let f=i??c(),p=u*3,m=isNaN(t[p+2])?void 0:t[p+2],h=new y(l,t[p],t[p+1],m),g=this.loadedGraphics.get(f);if(g!=null)(g.level==null||g.level<r)&&(Q.property=`geometry`,Q.graphic=g,Q.oldValue=g.geometry,Q.newValue=h,g.geometry=h,g.level=r,o.graphicUpdateHandler(Q),$()),s.push(g);else{let e=c();s.push({objectId:f,uid:e,geometry:h,attributes:d,visible:!0,nodeIndex:n,level:r})}}return s}_updateNodeMemory(e){e.memory=4096+(e.numFeatures??0)*this.processor.graphicsCore.usedMemoryPerGraphic}_cacheNodeData(e){this._memCache.put(this._getMemCacheKey(e.node),e)}_getMemCacheKey(e){return`${e.index}`}_removeAllNodeData(){this.loadedGraphics.forEachNode((e,t)=>{if(e){let t=e.node;this._updateNodeMemory(t),this._cacheNodeData(e)}this._controller.updateLoadStatus(t,!1)}),this._treeDebugger&&this._treeDebugger.update(),this.loadedGraphics.clear()}removeNode(e){let t=this._removeNodeStageData(e);t&&(this._updateNodeMemory(t.node),this._cacheNodeData(t))}_removeNodeStageData(e){let t=this.loadedGraphics.getNode(e);return t==null?null:(this._controller.updateLoadStatus(e,!1),this.loadedGraphics.removeNode(e),this._treeDebugger&&this._treeDebugger.update(),t)}async loadCachedNodeData(e){return this._memCache?.pop(this._getMemCacheKey(e))}async addCachedNodeData(e,n,r,i){this.loadedGraphics.hasNode(e.index)?t.getLogger(this).error(`I3S node `+e.id+` already added`):(await this._i3sOverrides.applyAttributeOverrides(n.featureIds,r,i),n.attributeInfo=r,this.loadedGraphics.addNode(e.index,n),this._controller.updateLoadStatus(e.index,!0),this._updateNodeMemory(e),X(n),this._filterNode(n),this._treeDebugger&&this._treeDebugger.update())}getLoadedNodeIds(){let e=[];return this.loadedGraphics.forEachNode(t=>e.push(t.node.id)),e.sort()}getVisibleNodes(){let e=[];return this.loadedGraphics.forEachNode(t=>e.push(t.node)),e}getLoadedNodeIndices(e){this.loadedGraphics.forEachNode((t,n)=>e.push(n))}getLoadedAttributes(e){let t=this.loadedGraphics.getNode(e);if(t?.attributeInfo!=null)return t.attributeInfo.loadedAttributes}getAttributeData(e){let t=this.loadedGraphics.getNode(e);if(t?.attributeInfo!=null)return t.attributeInfo.attributeData}_setAttributeData(e,t){let n=this.loadedGraphics.getNode(e);n?.attributeInfo!=null&&(n.attributeInfo.attributeData=t,this._attributeValuesChanged(n))}async updateAttributes(e,t,n){let r=this.loadedGraphics.getNode(e);r!=null&&(await this._i3sOverrides.applyAttributeOverrides(r.featureIds,t,n),r.attributeInfo=t,this._attributeValuesChanged(r))}_attributeValuesChanged(e){X(e),this._filterNode(e);let{processor:t}=this,{graphicsCore:n}=t;if(n.labelsEnabled){let t=e.node.index,r=[];e.graphics.forEach(e=>e.nodeIndex===t&&r.push(e.uid)),n.updateLabelingInfo(r)}t.refreshFilter()}_updateClippingExtent(e){return this._controller&&this._controller.updateClippingArea(e),!1}_getObjectIdField(){return this.layer.objectIdField||re}_getGlobalIdField(){return this.layer.globalIdField}async _rendererChange(e,t){let{layer:{fieldsIndex:n}}=this,r=new Set,i;e?(await e.collectRequiredFields(r,n),i=Array.from(r).sort()):i=[],r.clear();let a;t?(await t.collectRequiredFields(r,n),a=Array.from(r).sort()):a=[],i.length===a.length&&i.every((e,t)=>i[t]===a[t])||this._reloadAllNodes()}_rangeInfosChanged(e){e!=null&&e.length>0&&t.getLogger(this).warn(`Unsupported property: rangeInfos are currently only serialized to and from web scenes but do not affect rendering.`)}_filterChange(){this.loadedGraphics.forEachNode(e=>this._filterNode(e))}_reloadAllNodes(){this._removeAllNodeData(),this._controller&&this._controller.restartNodeLoading()}_filterNode(e){let t=this.parsedDefinitionExpression,n=this._excludeObjectIds,r=this._getObjectIdField();for(let i of e.graphics){let e=i.visible,a=this._evaluateClause(t,i),o=!n.has(i.attributes[r]);i.visible=a&&o,e!==i.visible&&(Q.graphic=i,Q.property=`visible`,Q.oldValue=e,Q.newValue=i.visible,this.processor.graphicsCore.graphicUpdateHandler(Q),$())}}createQuery(){let e={outFields:[`*`],returnGeometry:!0,outSpatialReference:this.view.spatialReference};return this.filter?.createQuery(e)??new C(e)}queryFeatures(e,t){return this._queryEngine.executeQuery(this._ensureQuery(e),t?.signal)}queryObjectIds(e,t){return this._queryEngine.executeQueryForIds(this._ensureQuery(e),t?.signal)}queryFeatureCount(e,t){return this._queryEngine.executeQueryForCount(this._ensureQuery(e),t?.signal)}queryExtent(e,t){return this._queryEngine.executeQueryForExtent(this._ensureQuery(e),t?.signal)}_ensureQuery(e){return this._addDefinitionExpressionToQuery(e==null?this.createQuery():C.from(e))}_setupQueryEngine(){let{layer:e,view:t,hasM:n,hasZ:r}=this,{spatialReference:i,resourceController:a}=t,o=new D(i,e,a,()=>this.processor.featureStore,r,n,()=>this.availableFields);this._queryEngine=new E({context:o,priority:ve.FEATURE_QUERY_ENGINE})}get usedMemory(){return this.processor?.graphicsCore?.usedMemory??0}get unloadedMemory(){return((this._controller?.unloadedMemoryEstimate??0)+(this.processor?.graphicsCore?.unprocessedMemoryEstimate??0))*.8}get ignoresMemoryFactor(){return this._controller&&this._controller.fixedFeatureTarget}async _handleEdits(e){let t=this._attributeEditingContext,n=await k(t,e);A(t,n)}get _attributeEditingContext(){let e=this._getObjectIdField(),t=this._getGlobalIdField();return{sessions:this._interactiveEditingSessions,fieldsIndex:this.layer.fieldsIndex,objectIdField:e,globalIdField:t,forEachNode:e=>this.loadedGraphics.forEachNode(t=>e(t.node,t.featureIds)),attributeStorageInfo:this.layer.attributeStorageInfo??[],i3sOverrides:this._i3sOverrides,getAttributeData:e=>this.getAttributeData(e),setAttributeData:(t,n,r)=>{this._setAttributeData(t,n);let i=this.loadedGraphics.getNode(t);if(r!=null){let t=this.loadedGraphics.get(r.attributes[e]);t!=null&&this.processor.graphicsCore.recreateGraphics([t])}else i!=null&&this.processor.graphicsCore.recreateGraphics(i.graphics)},clearMemCache:()=>{}}}get performanceInfo(){return new le(this.usedMemory,this.loadedGraphics.length,-1,this.maximumNumberOfFeatures,this.loadedGraphics.nodeCount,this.processor.graphicsCore.performanceInfo)}get test(){}};e([l()],J.prototype,`processor`,void 0),e([l({type:ae})],J.prototype,`filter`,void 0),e([l()],J.prototype,`loadedGraphics`,void 0),e([l()],J.prototype,`layerViewUid`,null),e([l()],J.prototype,`_controller`,void 0),e([l()],J.prototype,`updating`,void 0),e([l()],J.prototype,`suspended`,void 0),e([l(pe)],J.prototype,`updatingProgress`,void 0),e([l()],J.prototype,`updatingProgressValue`,null),e([l({readOnly:!0})],J.prototype,`visibleAtCurrentScale`,null),e([l(q.requiredFields)],J.prototype,`requiredFields`,null),e([l(q.availableFields)],J.prototype,`availableFields`,void 0),e([l()],J.prototype,`_fieldsHelper`,void 0),e([l({type:Number})],J.prototype,`maximumNumberOfFeatures`,null),e([l({readOnly:!0})],J.prototype,`maximumNumberOfFeaturesExceeded`,null),e([l()],J.prototype,`_excludeObjectIds`,null),e([l({readOnly:!0})],J.prototype,`lodFactor`,null),e([l({readOnly:!0})],J.prototype,`hasM`,null),e([l({readOnly:!0})],J.prototype,`hasZ`,null),e([l()],J.prototype,`contentVisible`,null),e([l({readOnly:!0})],J.prototype,`legendEnabled`,null),e([l()],J.prototype,`_graphicOrigin`,null),J=e([u(`esri.views.3d.layers.SceneLayerGraphicsView3D`)],J);const be=J;function xe(e){return`pointData`in e}function Y(e){return`geometryBuffer`in e&&e.geometryBuffer!==null}function Se(e,t,n){let r=t.attributeInfo;if(r?.loadedAttributes==null||r.attributeData==null)return!1;let i=!1;for(let{name:t}of r.loadedAttributes)if(r.attributeData[t]){let a=j(r.attributeData[t],n);a!==e.attributes[t]&&(e.attributes[t]=a,i=!0)}return i}function X(e){let t=e.attributeInfo;if(t?.loadedAttributes==null||t.attributeData==null)return;let n=e.node.index;for(let r=0;r<e.graphics.length;r++){let i=e.graphics[r];if(i.nodeIndex===n){i.attributes||={};for(let{name:e}of t.loadedAttributes)t.attributeData[e]&&(i.attributes[e]=j(t.attributeData[e],r))}}}function Ce(e,t){return e.xmin-=t,e.ymin-=t,e.xmax+=t,e.ymax+=t,e.zmin!=null&&e.zmax!=null&&(e.zmin-=t,e.zmax+=t),e.mmin!=null&&e.mmax!=null&&(e.mmin-=t,e.mmax+=t),e}const we={2:{type:`Embedded`,params:{type:`points`,vertexAttributes:{position:[0,0]}}},3:{type:`Embedded`,params:{type:`points`,vertexAttributes:{position:[0,0,0]}}}},Z=p(),Q={graphic:null,property:null,oldValue:null,newValue:null},Te=p();function $(){Q.graphic=null,Q.property=null,Q.oldValue=null,Q.newValue=null}export{be 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 t from"../../../../core/Accessor.js";import{lerp as n}from"../../../../core/mathUtils.js";import{destroyMaybe as r}from"../../../../core/maybe.js";import{property as i,subclass as a}from"../../../../core/accessorSupport/decorators.js";import{transpose as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{transformMat4 as l,scale as u,round as d,copy as f,set as p}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as m,create as h}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as g,transformMat4 as _,scale as v}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{create as y}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as b}from"../../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as ee}from"../../../../geometry/ellipsoidUtils.js";import{create as x,empty as te,copy as S,offset as C,width as w,height as ne,expand as T}from"../../../../geometry/support/aaBoundingRect.js";import{h as E,c as re,a as ie}from"../../../../chunks/boundedPlane.js";import{create as D}from"../../../../geometry/support/ray.js";import{Sphere as O,sphereCSO as k}from"../../../../geometry/support/sphere.js";import{InternalRenderCategory as A}from"../../webgl.js";import{DeconflictAABR as j}from"./DeconflictAABR.js";import{prepare as M,drawPoly as N}from"./deconflictorDebug.js";import{isSymbolLayerWithTransparencyMode as P}from"./transparencyUtils.js";import F from"../../webgl/RenderCamera.js";import{getVec3AttributeView as I,getScalarAttributeView as L}from"../../webgl-engine/lib/attributeViewUtils.js";import{GPUPointOcclusionQuery as R}from"../../webgl-engine/lib/GPUPointOcclusionQuery.js";import{SeparateScreenSizePerspectiveEvaluators as z}from"../../webgl-engine/lib/screenSizePerspectiveUtils.js";import{HUDMaterial as B}from"../../webgl-engine/materials/HUDMaterial.js";import{Yield as V}from"../../../support/Yield.js";const H=h(),U=h(),W=h(),G=h(),K=y(),q=y(),J=h(),Y=s(),ae=new O,X=D(),oe=h(),Z=x();class se{constructor(e){this.id=e,this.aabr=x(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.culled=!1,this.visible=!1,this.priority=0}}function ce(e,t){let n=e.distanceToOccluder!==0&&e.distance>e.distanceToOccluder,r=t.distanceToOccluder!==0&&t.distance>t.distanceToOccluder;return n===r?e.priority===t.priority?e.distance===t.distance?e.visible===t.visible?e.id-t.id:+t.visible-e.visible:e.distance-t.distance:t.priority-e.priority:+n-r}class le{constructor(e,t){this.graphics3DGraphic=e,this.slicePlaneEnabled=t,this._info=null,this._labelInfo=null}ensureInfo(e){let t=this.getInfo(e);return t||(t=new se(this.graphics3DGraphic.graphic.uid),this._setInfo(e,t)),t}getInfo(e){return e===16?this._labelInfo:this._info}removeInfo(e){this._setInfo(e,null)}_setInfo(e,t){e===16?this._labelInfo=t:this._info=t}}class Q{constructor(){this.camera=new F,this.slicePlane=re(),this.slicePlaneEnabled=!1}copyFrom(e){this.camera.equals(e.camera)||this.camera.copyFrom(e.camera),ie(e.slicePlane,this.slicePlane),this.slicePlaneEnabled=e.slicePlaneEnabled}}let $=class extends t{get dirty(){return this._dirty}get state(){return this._state}constructor(e){super(e),this._dirty=!1,this._viewState=new Q,this._state=0,this._checkOcclusion=new Map,this._active=new Map,this._checkOcclusionIterator=null,this._activeIterator=null,this._occlusionQueryUids=[],this._updatingHandles=new b,this._deconflictor=new j((e,t)=>{e.visible=t,this._setGraphicVisibility(this._active.get(e.id),t)},(e,t)=>e.id!==t.id,ce),this._baseOccludedVisibility=10,this._altitudeFactor=2,this._minAltitudeDifference=100}initialize(){this._updatingHandles.add(()=>(this.view?.map?.ground?.opacity??0)>0,()=>this.setDirty()),this._updatingHandles.add(()=>this.view.ready,()=>{this._occlusionQuery=null,this._opaqueOcclusionQuery=null,this.setDirty()})}destroy(){this._occlusionQuery=null,this._opaqueOcclusionQuery=null,this._updatingHandles.destroy(),this._deconflictor.destroy(),this._checkOcclusion.clear(),this._active.clear()}setDirty(){!this._dirty&&(this._active.size>0||this._checkOcclusion.size>0)&&(this._dirty=!0,this.notifyChange(`_readyToRun`))}setPriority(e,t){let n=this._active.get(e.graphic.uid)?.getInfo(this.visibilityGroup);n&&(n.priority=t)}get _readyToRun(){return this._state!==0||this._dirty}get updating(){return this._readyToRun||this._updatingHandles.updating}get updatingProgress(){if(!this.updating)return 1;let e=this._state/5;return this._dirty?e*.5:e}get readyToRun(){return this.view.ready&&this.view.state!=null&&this._readyToRun}get usedMemory(){return this._occlusionQuery?.usedMemory??0+(this._occlusionQueryUids?.length??0)*4}runTask(e){switch(this._state){case 0:this._startUpdate(),e.madeProgress();case 1:if(this._state=1,!this._processCheckOcclusion(e))return;case 2:if(this._state=2,!(this._occlusionQuery?.done??!0)||!(this._opaqueOcclusionQuery?.done??!0))return V;this._readOcclusionQueryResult(),e.madeProgress();case 3:if(this._state=3,!this._collectActiveGraphics(e))return;case 4:if(this._state=4,this._deconflictor.run(e),!this._deconflictor.done)return;default:this._state=0,this.notifyChange(`_readyToRun`)}}setGraphicsActive(e,t){t?e.forEach(e=>this.addToActiveGraphics(e)):e.forEach(e=>this.removeFromActiveGraphics(e))}isSupportedLayer(e){if(e==null||!(`hiddenIfDeconflicted`in e)||!e.hiddenIfDeconflicted)return!1;let t=e.stageObject;return(t?.geometries.length??0)===1&&t?.geometries[0]?.material instanceof B}_startUpdate(){M(this.view),this._dirty=!1,this._viewState.copyFrom(this.viewState);let{fullWidth:e,fullHeight:t}=this._viewState.camera;this._deconflictor.reset(e,t),this._resetIterators(),this._occlusionQueryUids.length=0,!this._checkOcclusion.size&&(this._occlusionQuery=r(this._occlusionQuery),this._opaqueOcclusionQuery=r(this._opaqueOcclusionQuery))}addToActiveGraphics(e){e.ensureInfo(this.visibilityGroup),this._active.set(e.graphics3DGraphic.graphic.uid,e),this.setDirty()}removeFromActiveGraphics(e){this._active.get(e.graphics3DGraphic.graphic.uid)===e&&(ue(e,this.visibilityGroup),e.removeInfo(this.visibilityGroup),this._active.delete(e.graphics3DGraphic.graphic.uid),this.setDirty())}addToCheckOcclusion(e){this._checkOcclusion.set(e.graphics3DGraphic.graphic.uid,e),this.setDirty()}removeFromCheckOcclusion(e){this._checkOcclusion.get(e.graphics3DGraphic.graphic.uid)===e&&this._checkOcclusion.delete(e.graphics3DGraphic.graphic.uid)}_processCheckOcclusion(e){if(this._checkOcclusion.size===0)return!0;let t=this._ensureCheckOcclusionIterator(),n=this._viewState.camera,i=o(Y,n.viewInverseTransposeMatrix),a=this.view.map.ground.opacity>0,s=this.view.viewingMode===`global`&&a&&n.relativeElevation>0?ae:null,c=0;s!=null&&(l(s.center,m,n.viewMatrix),s.radius=ee(this.view.spatialReference).radius,c=k.distanceToSilhouette(s,m));let u=x();for(;;){if(e.done)return!1;e.madeProgress();let r=t.next();if(r.done===!0)break;let a=r.value,o=a.graphics3DGraphic;if(o.destroyed||!o.isVisible(1,8))continue;let d=me(o,this.visibilityGroup),f=null,p=!0,m=!1;for(let e of d){if(!this.isSupportedLayer(e))continue;f=he,this._projectHudLayer(e,n,f),te(u);let t=e.stageObject.geometries[0].material;if(this._expandBoundingRect(u,n,e,t,f),f.isOutsideScreen||this._isCulledBySlice(a,f.positionWorld)||s!=null&&pe(f,s,c)){p=!1;break}f.altitude=this.view.renderCoordsHelper.getAltitude(f.positionWorld);let r=a.ensureInfo(this.visibilityGroup);if(r.altitude=f.altitude,r.distance=f.distance,r.distanceToOccluder=f.distanceToOccluder,r.culled=!1,S(r.aabr,u),!e.occlusionCheck)break;l(U,f.positionView,i);let d=this._ensureOcclusionQuery(),h=this._ensureOpaqueOcclusionQuery();this._occlusionQueryUids.length===0&&(this._initOcclusionQuery(d),this._initOcclusionQuery(h));let g=d.addPosition(U),_=h.addPosition(U);if(g===this._occlusionQueryUids.length&&_===g){let t=e.adaptiveOcclusion;this._occlusionQueryUids.push(t?-o.graphic.uid:o.graphic.uid),m=!0}break}let h=this._active.has(o.graphic.uid);if(!h&&!m)this._setGraphicVisibility(a,p);else if(h&&(!p||!f)){let e=a.ensureInfo(this.visibilityGroup);e.visible=!f,e.culled=!0}}return this._checkOcclusionIterator=null,this._occlusionQueryUids.length||(this._occlusionQuery=r(this._occlusionQuery),this._opaqueOcclusionQuery=r(this._opaqueOcclusionQuery)),this._occlusionQuery?.start(),this._opaqueOcclusionQuery?.start(),!0}_readOcclusionQueryResult(){if(!this._occlusionQuery||!this._occlusionQueryUids.length)return;let e=this._viewState.camera,t=this.view.renderCoordsHelper.getAltitude(e.eye);for(let e=0;e<this._occlusionQueryUids.length;e++){let n=this._occlusionQueryUids[e],r=Math.abs(n),i=n<0,a=this._checkOcclusion.get(r);if(!a)continue;let o=this._occlusionQuery.getOcclusion(e)??-1,s=this._opaqueOcclusionQuery?.getOcclusion(e)??-1,c=a.getInfo(this.visibilityGroup);c&&(c.distanceToOccluder=o>0?c.distance-o:0);let l=s===0||s>0&&this._occludedVisibility(c?c.distance-s:0,c?.distance??s,c?.altitude??0,t,i),u=o===0||o>0&&this._occludedVisibility(c?.distanceToOccluder??0,c?.distance??o,c?.altitude??0,t,i),d=l||u;d&&this._setTransparentMode(a,l&&!u),this._active.has(r)?c&&(c.culled=!d,c.visible=d):this._setGraphicVisibility(a,d)}this._occlusionQueryUids.length=0}_collectActiveGraphics(e){let t=this._ensureActiveGraphicsIterator(),n=this.visibilityGroup===16;for(;!e.done;){e.madeProgress();let r=t.next();if(r.done===!0)return this._activeIterator=null,!0;let i=r.value,a=i.getInfo(this.visibilityGroup);if(!a)continue;let o=!n||i.graphics3DGraphic.isVisible();!o||a.culled?(N(a.aabr,!1,!0),this._setGraphicVisibility(i,o&&a.visible)):this._deconflictor.add(a)}return!1}_occludedVisibility(e,t,n,r,i=!0){let a=Math.max(this._minAltitudeDifference,Math.abs(n-r))-this._minAltitudeDifference,o=i?this._baseOccludedVisibility+this._altitudeFactor*a:0;return e===0||t-e<=o}_resetIterators(){this._checkOcclusionIterator=null,this._activeIterator=null}_ensureCheckOcclusionIterator(){return this._checkOcclusionIterator??=this._checkOcclusion.values(),this._checkOcclusionIterator}_ensureActiveGraphicsIterator(){return this._activeIterator??=this._active.values(),this._activeIterator}_initOcclusionQuery(e){if(!e)return;let{camera:t}=this._viewState,n=Math.max(2,2+Math.round(Math.log2(Math.abs(t.relativeElevation))));u(H,this._viewState.camera.eye,2**-n),u(H,d(H,H),2**n),e.init(this._checkOcclusion.size,H)}_ensureOcclusionQuery(){return this._occlusionQuery??=new R({view:this.view}),this._occlusionQuery}_ensureOpaqueOcclusionQuery(){return this._opaqueOcclusionQuery??=new R({view:this.view,category:A.OPAQUE_OCCLUSION_QUERY}),this._opaqueOcclusionQuery}_getNumVisible(e){return this._checkOcclusion.values().reduce((t,n)=>t+ +!!n.getInfo(e)?.visible,0)}_projectHudLayer(e,t,n){let r=e.stageObject,i=r.geometries[0],a=i.material;f(U,r.boundingVolumeWorldSpace.sphere.center),l(H,U,t.viewMatrix);let o=I(i,`normal`).getVec(0,W),s=I(i,`centerOffset`)?.getVec(0,G)??m,c=L(i,`groundDistance`).get(0);a.applyShaderOffsets(U,H,o,r.transformation,s,c,t,n.screenSizePerspectiveEvaluators),g(K,H[0],H[1],H[2],1),_(q,K,t.projectionMatrix),u(n.positionNDC,q,1/q[3]),a.applyShaderOffsetsNDC(n.positionNDC,s,c,t,n.positionNDC,J),n.distanceWithoutPolygonOffset=t.depthNDCToWorld(J[2]),n.distance=J[2]===n.positionNDC[2]?n.distanceWithoutPolygonOffset:t.depthNDCToWorld(n.positionNDC[2]),g(q,n.positionNDC[0],n.positionNDC[1],n.positionNDC[2],1),_(K,q,t.inverseProjectionMatrix),v(K,K,1/K[3]),p(n.positionView,K[0],K[1],K[2]),f(n.positionWorld,U)}_isCulledBySlice(e,t){return e.slicePlaneEnabled&&this._viewState.slicePlaneEnabled&&E(this._viewState.slicePlane,t)}_expandBoundingRect(e,t,r,i,{positionNDC:a,screenSizePerspectiveEvaluators:o}){let s=r.getScreenSize(de);o.evaluator.applyVec2(s,s),s[0]*=t.pixelRatio,s[1]*=t.pixelRatio;let c=C(i.calculateRelativeScreenBounds(s,o.alignmentEvaluator.apply(t.pixelRatio),Z),n(0,t.fullWidth,.5+.5*a[0]),n(0,t.fullHeight,.5+.5*a[1])),l=this.marginFactor;if(l!==0){let e=l*Math.min(w(c),ne(c));c[0]-=e,c[1]-=e,c[2]+=e,c[3]+=e}T(e,c,e)}_setGraphicVisibility(e,t){let n=e?.graphics3DGraphic;n&&!n.destroyed&&(n.setVisibilityFlag(this.visibilityGroup,8,t),this.visibilityGroup===16&&this.view.labeler.setLabelGraphicVisibility(n,t))}_setTransparentMode(e,t){let n=e?.graphics3DGraphic;if(n&&!n.destroyed)for(let e of n.layers){if(e?.type!==`object3d`&&e?.type!==`buffer`)continue;let{graphics3DSymbolLayer:n}=e;P(n)&&n.updateTransparentMode(e,t)}}};e([i({constructOnly:!0})],$.prototype,`view`,void 0),e([i({type:Boolean,readOnly:!0})],$.prototype,`_readyToRun`,null),e([i({type:Boolean,readOnly:!0})],$.prototype,`updating`,null),e([i({readOnly:!0})],$.prototype,`_updatingHandles`,void 0),$=e([a(`esri.views.3d.layers.graphics.Deconflictor`)],$);function ue(e,t){let n=e.graphics3DGraphic;n.destroyed||n.setVisibilityFlag(t,8,!0)}const de=c();class fe{constructor(){this.positionWorld=h(),this.positionView=h(),this.positionNDC=h(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.distanceWithoutPolygonOffset=0,this.screenSizePerspectiveEvaluators=new z}get isOutsideScreen(){let e=this.positionNDC;return e[0]<-1||e[1]<-1||e[2]<-1||e[0]>=1||e[1]>=1||e[2]>=1}}function pe(e,t,n){return f(X.direction,e.positionView),p(X.origin,0,0,0),t.intersectRay(X,oe)?e.distanceWithoutPolygonOffset>n:!1}function me(e,t){return t===16?e.labelLayers:e.layers}const he=new fe;export{$ as Deconflictor,le as DeconflictorGraphic,Q as DeconflictorViewState};
2
+ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{lerp as n}from"../../../../core/mathUtils.js";import{destroyMaybe as r}from"../../../../core/maybe.js";import{property as i,subclass as a}from"../../../../core/accessorSupport/decorators.js";import{transpose as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{transformMat4 as l,scale as u,round as d,copy as f,set as p}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as m,create as h}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as g,transformMat4 as _,scale as v}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{create as y}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as b}from"../../../../core/support/UpdatingHandles.js";import{getReferenceEllipsoid as ee}from"../../../../geometry/ellipsoidUtils.js";import{create as x,empty as te,copy as S,offset as C,width as w,height as ne,expand as T}from"../../../../geometry/support/aaBoundingRect.js";import{h as E,c as re,a as ie}from"../../../../chunks/boundedPlane.js";import{create as D}from"../../../../geometry/support/ray.js";import{Sphere as O,sphereCSO as k}from"../../../../geometry/support/sphere.js";import{InternalRenderCategory as A}from"../../webgl.js";import{DeconflictAABR as j}from"./DeconflictAABR.js";import{prepare as M,drawPoly as N}from"./deconflictorDebug.js";import{isSymbolLayerWithTransparencyMode as P}from"./transparencyUtils.js";import F from"../../webgl/RenderCamera.js";import{getVec3AttributeView as I,getScalarAttributeView as L}from"../../webgl-engine/lib/attributeViewUtils.js";import{GPUPointOcclusionQuery as R}from"../../webgl-engine/lib/GPUPointOcclusionQuery.js";import{SeparateScreenSizePerspectiveEvaluators as z}from"../../webgl-engine/lib/screenSizePerspectiveUtils.js";import{HUDMaterial as B}from"../../webgl-engine/materials/HUDMaterial.js";import{Yield as V}from"../../../support/Yield.js";const H=h(),U=h(),W=h(),G=h(),K=y(),q=y(),J=h(),Y=s(),ae=new O,X=D(),oe=h(),Z=x();class se{constructor(e){this.id=e,this.aabr=x(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.culled=!1,this.visible=!1,this.priority=0}}function ce(e,t){let n=e.distanceToOccluder!==0&&e.distance>e.distanceToOccluder,r=t.distanceToOccluder!==0&&t.distance>t.distanceToOccluder;return n===r?e.priority===t.priority?e.distance===t.distance?e.visible===t.visible?e.id-t.id:+t.visible-e.visible:e.distance-t.distance:t.priority-e.priority:+n-r}class le{constructor(e,t){this.graphics3DGraphic=e,this.slicePlaneEnabled=t,this._info=null,this._labelInfo=null}ensureInfo(e){let t=this.getInfo(e);return t||(t=new se(this.graphics3DGraphic.graphic.uid),this._setInfo(e,t)),t}getInfo(e){return e===16?this._labelInfo:this._info}removeInfo(e){this._setInfo(e,null)}_setInfo(e,t){e===16?this._labelInfo=t:this._info=t}}class Q{constructor(){this.camera=new F,this.slicePlane=re(),this.slicePlaneEnabled=!1}copyFrom(e){this.camera.equals(e.camera)||this.camera.copyFrom(e.camera),ie(e.slicePlane,this.slicePlane),this.slicePlaneEnabled=e.slicePlaneEnabled}}let $=class extends t{get dirty(){return this._dirty}get state(){return this._state}constructor(e){super(e),this._dirty=!1,this._viewState=new Q,this._state=0,this._checkOcclusion=new Map,this._active=new Map,this._checkOcclusionIterator=null,this._activeIterator=null,this._occlusionQueryUids=[],this._updatingHandles=new b,this._deconflictor=new j((e,t)=>{e.visible=t,this._setGraphicVisibility(this._active.get(e.id),t)},(e,t)=>e.id!==t.id,ce),this._baseOccludedVisibility=10,this._altitudeFactor=2,this._minAltitudeDifference=100}initialize(){this._updatingHandles.add(()=>(this.view?.map?.ground?.opacity??0)>0,()=>this.setDirty()),this._updatingHandles.add(()=>this.view.ready,()=>{this._occlusionQuery=null,this._opaqueOcclusionQuery=null,this.setDirty()})}destroy(){this._occlusionQuery=null,this._opaqueOcclusionQuery=null,this._updatingHandles.destroy(),this._deconflictor.destroy(),this._checkOcclusion.clear(),this._active.clear()}setDirty(){!this._dirty&&(this._active.size>0||this._checkOcclusion.size>0)&&(this._dirty=!0,this.notifyChange(`_readyToRun`))}setPriority(e,t){let n=this._active.get(e.graphic.uid)?.getInfo(this.visibilityGroup);n&&(n.priority=t)}get _readyToRun(){return this._state!==0||this._dirty}get updating(){return this._readyToRun||this._updatingHandles.updating}get updatingProgress(){if(!this.updating)return 1;let e=this._state/5;return this._dirty?e*.5:e}get readyToRun(){return this.view.ready&&this.view.state!=null&&this._readyToRun}get usedMemory(){return this._occlusionQuery?.usedMemory??0+(this._occlusionQueryUids?.length??0)*4}runTask(e){switch(this._state){case 0:this._startUpdate(),e.madeProgress();case 1:if(this._state=1,!this._processCheckOcclusion(e))return;case 2:if(this._state=2,!(this._occlusionQuery?.done??!0)||!(this._opaqueOcclusionQuery?.done??!0))return V;this._readOcclusionQueryResult(),e.madeProgress();case 3:if(this._state=3,!this._collectActiveGraphics(e))return;case 4:if(this._state=4,this._deconflictor.run(e),!this._deconflictor.done)return;default:this._state=0,this.notifyChange(`_readyToRun`)}}setGraphicsActive(e,t){t?e.forEach(e=>this.addToActiveGraphics(e)):e.forEach(e=>this.removeFromActiveGraphics(e))}isSupportedLayer(e){if(e==null||!(`hiddenIfDeconflicted`in e)||!e.hiddenIfDeconflicted)return!1;let t=e.stageObject;return(t?.geometries.length??0)===1&&t?.geometries[0]?.material instanceof B}_startUpdate(){M(this.view),this._dirty=!1,this._viewState.copyFrom(this.viewState);let{fullWidth:e,fullHeight:t}=this._viewState.camera;this._deconflictor.reset(e,t),this._resetIterators(),this._occlusionQueryUids.length=0,this._checkOcclusion.size||(this._occlusionQuery=r(this._occlusionQuery),this._opaqueOcclusionQuery=r(this._opaqueOcclusionQuery))}addToActiveGraphics(e){e.ensureInfo(this.visibilityGroup),this._active.set(e.graphics3DGraphic.graphic.uid,e),this.setDirty()}removeFromActiveGraphics(e){this._active.get(e.graphics3DGraphic.graphic.uid)===e&&(ue(e,this.visibilityGroup),e.removeInfo(this.visibilityGroup),this._active.delete(e.graphics3DGraphic.graphic.uid),this.setDirty())}addToCheckOcclusion(e){this._checkOcclusion.set(e.graphics3DGraphic.graphic.uid,e),this.setDirty()}removeFromCheckOcclusion(e){this._checkOcclusion.get(e.graphics3DGraphic.graphic.uid)===e&&this._checkOcclusion.delete(e.graphics3DGraphic.graphic.uid)}_processCheckOcclusion(e){if(this._checkOcclusion.size===0)return!0;let t=this._ensureCheckOcclusionIterator(),n=this._viewState.camera,i=o(Y,n.viewInverseTransposeMatrix),a=this.view.map.ground.opacity>0,s=this.view.viewingMode===`global`&&a&&n.relativeElevation>0?ae:null,c=0;s!=null&&(l(s.center,m,n.viewMatrix),s.radius=ee(this.view.spatialReference).radius,c=k.distanceToSilhouette(s,m));let u=x();for(;;){if(e.done)return!1;e.madeProgress();let r=t.next();if(r.done===!0)break;let a=r.value,o=a.graphics3DGraphic;if(o.destroyed||!o.isVisible(1,8))continue;let d=me(o,this.visibilityGroup),f=null,p=!0,m=!1;for(let e of d){if(!this.isSupportedLayer(e))continue;f=he,this._projectHudLayer(e,n,f),te(u);let t=e.stageObject.geometries[0].material;if(this._expandBoundingRect(u,n,e,t,f),f.isOutsideScreen||this._isCulledBySlice(a,f.positionWorld)||s!=null&&pe(f,s,c)){p=!1;break}f.altitude=this.view.renderCoordsHelper.getAltitude(f.positionWorld);let r=a.ensureInfo(this.visibilityGroup);if(r.altitude=f.altitude,r.distance=f.distance,r.distanceToOccluder=f.distanceToOccluder,r.culled=!1,S(r.aabr,u),!e.occlusionCheck)break;l(U,f.positionView,i);let d=this._ensureOcclusionQuery(),h=this._ensureOpaqueOcclusionQuery();this._occlusionQueryUids.length===0&&(this._initOcclusionQuery(d),this._initOcclusionQuery(h));let g=d.addPosition(U),_=h.addPosition(U);if(g===this._occlusionQueryUids.length&&_===g){let t=e.adaptiveOcclusion;this._occlusionQueryUids.push(t?-o.graphic.uid:o.graphic.uid),m=!0}break}let h=this._active.has(o.graphic.uid);if(!h&&!m)this._setGraphicVisibility(a,p);else if(h&&(!p||!f)){let e=a.ensureInfo(this.visibilityGroup);e.visible=!f,e.culled=!0}}return this._checkOcclusionIterator=null,this._occlusionQueryUids.length||(this._occlusionQuery=r(this._occlusionQuery),this._opaqueOcclusionQuery=r(this._opaqueOcclusionQuery)),this._occlusionQuery?.start(),this._opaqueOcclusionQuery?.start(),!0}_readOcclusionQueryResult(){if(!this._occlusionQuery||!this._occlusionQueryUids.length)return;let e=this._viewState.camera,t=this.view.renderCoordsHelper.getAltitude(e.eye);for(let e=0;e<this._occlusionQueryUids.length;e++){let n=this._occlusionQueryUids[e],r=Math.abs(n),i=n<0,a=this._checkOcclusion.get(r);if(!a)continue;let o=this._occlusionQuery.getOcclusion(e)??-1,s=this._opaqueOcclusionQuery?.getOcclusion(e)??-1,c=a.getInfo(this.visibilityGroup);c&&(c.distanceToOccluder=o>0?c.distance-o:0);let l=s===0||s>0&&this._occludedVisibility(c?c.distance-s:0,c?.distance??s,c?.altitude??0,t,i),u=o===0||o>0&&this._occludedVisibility(c?.distanceToOccluder??0,c?.distance??o,c?.altitude??0,t,i),d=l||u;d&&this._setTransparentMode(a,l&&!u),this._active.has(r)?c&&(c.culled=!d,c.visible=d):this._setGraphicVisibility(a,d)}this._occlusionQueryUids.length=0}_collectActiveGraphics(e){let t=this._ensureActiveGraphicsIterator(),n=this.visibilityGroup===16;for(;!e.done;){e.madeProgress();let r=t.next();if(r.done===!0)return this._activeIterator=null,!0;let i=r.value,a=i.getInfo(this.visibilityGroup);if(!a)continue;let o=!n||i.graphics3DGraphic.isVisible();!o||a.culled?(N(a.aabr,!1,!0),this._setGraphicVisibility(i,o&&a.visible)):this._deconflictor.add(a)}return!1}_occludedVisibility(e,t,n,r,i=!0){let a=Math.max(this._minAltitudeDifference,Math.abs(n-r))-this._minAltitudeDifference,o=i?this._baseOccludedVisibility+this._altitudeFactor*a:0;return e===0||t-e<=o}_resetIterators(){this._checkOcclusionIterator=null,this._activeIterator=null}_ensureCheckOcclusionIterator(){return this._checkOcclusionIterator??=this._checkOcclusion.values(),this._checkOcclusionIterator}_ensureActiveGraphicsIterator(){return this._activeIterator??=this._active.values(),this._activeIterator}_initOcclusionQuery(e){if(!e)return;let{camera:t}=this._viewState,n=Math.max(2,2+Math.round(Math.log2(Math.abs(t.relativeElevation))));u(H,this._viewState.camera.eye,2**-n),u(H,d(H,H),2**n),e.init(this._checkOcclusion.size,H)}_ensureOcclusionQuery(){return this._occlusionQuery??=new R({view:this.view}),this._occlusionQuery}_ensureOpaqueOcclusionQuery(){return this._opaqueOcclusionQuery??=new R({view:this.view,category:A.OPAQUE_OCCLUSION_QUERY}),this._opaqueOcclusionQuery}_getNumVisible(e){return this._checkOcclusion.values().reduce((t,n)=>t+ +!!n.getInfo(e)?.visible,0)}_projectHudLayer(e,t,n){let r=e.stageObject,i=r.geometries[0],a=i.material;f(U,r.boundingVolumeWorldSpace.sphere.center),l(H,U,t.viewMatrix);let o=I(i,`normal`).getVec(0,W),s=I(i,`centerOffset`)?.getVec(0,G)??m,c=L(i,`groundDistance`).get(0);a.applyShaderOffsets(U,H,o,r.transformation,s,c,t,n.screenSizePerspectiveEvaluators),g(K,H[0],H[1],H[2],1),_(q,K,t.projectionMatrix),u(n.positionNDC,q,1/q[3]),a.applyShaderOffsetsNDC(n.positionNDC,s,c,t,n.positionNDC,J),n.distanceWithoutPolygonOffset=t.depthNDCToWorld(J[2]),n.distance=J[2]===n.positionNDC[2]?n.distanceWithoutPolygonOffset:t.depthNDCToWorld(n.positionNDC[2]),g(q,n.positionNDC[0],n.positionNDC[1],n.positionNDC[2],1),_(K,q,t.inverseProjectionMatrix),v(K,K,1/K[3]),p(n.positionView,K[0],K[1],K[2]),f(n.positionWorld,U)}_isCulledBySlice(e,t){return e.slicePlaneEnabled&&this._viewState.slicePlaneEnabled&&E(this._viewState.slicePlane,t)}_expandBoundingRect(e,t,r,i,{positionNDC:a,screenSizePerspectiveEvaluators:o}){let s=r.getScreenSize(de);o.evaluator.applyVec2(s,s),s[0]*=t.pixelRatio,s[1]*=t.pixelRatio;let c=C(i.calculateRelativeScreenBounds(s,o.alignmentEvaluator.apply(t.pixelRatio),Z),n(0,t.fullWidth,.5+.5*a[0]),n(0,t.fullHeight,.5+.5*a[1])),l=this.marginFactor;if(l!==0){let e=l*Math.min(w(c),ne(c));c[0]-=e,c[1]-=e,c[2]+=e,c[3]+=e}T(e,c,e)}_setGraphicVisibility(e,t){let n=e?.graphics3DGraphic;n&&!n.destroyed&&(n.setVisibilityFlag(this.visibilityGroup,8,t),this.visibilityGroup===16&&this.view.labeler.setLabelGraphicVisibility(n,t))}_setTransparentMode(e,t){let n=e?.graphics3DGraphic;if(n&&!n.destroyed)for(let e of n.layers){if(e?.type!==`object3d`&&e?.type!==`buffer`)continue;let{graphics3DSymbolLayer:n}=e;P(n)&&n.updateTransparentMode(e,t)}}};e([i({constructOnly:!0})],$.prototype,`view`,void 0),e([i({type:Boolean,readOnly:!0})],$.prototype,`_readyToRun`,null),e([i({type:Boolean,readOnly:!0})],$.prototype,`updating`,null),e([i({readOnly:!0})],$.prototype,`_updatingHandles`,void 0),$=e([a(`esri.views.3d.layers.graphics.Deconflictor`)],$);function ue(e,t){let n=e.graphics3DGraphic;n.destroyed||n.setVisibilityFlag(t,8,!0)}const de=c();class fe{constructor(){this.positionWorld=h(),this.positionView=h(),this.positionNDC=h(),this.altitude=0,this.distance=0,this.distanceToOccluder=0,this.distanceWithoutPolygonOffset=0,this.screenSizePerspectiveEvaluators=new z}get isOutsideScreen(){let e=this.positionNDC;return e[0]<-1||e[1]<-1||e[2]<-1||e[0]>=1||e[1]>=1||e[2]>=1}}function pe(e,t,n){return f(X.direction,e.positionView),p(X.origin,0,0,0),t.intersectRay(X,oe)?e.distanceWithoutPolygonOffset>n:!1}function me(e,t){return t===16?e.labelLayers:e.layers}const he=new fe;export{$ as Deconflictor,le as DeconflictorGraphic,Q as DeconflictorViewState};