@pirireis/webglobeplugins 1.0.2 → 1.0.3

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 (259) hide show
  1. package/Math/{angle-calculation.ts → angle-calculation.js} +14 -18
  2. package/Math/{arc-cdf-points.ts → arc-cdf-points.js} +272 -329
  3. package/Math/{arc-generate-points-exponantial.ts → arc-generate-points-exponantial.js} +254 -299
  4. package/Math/{arc.ts → arc.js} +292 -421
  5. package/Math/bounds/line-bbox.js +186 -225
  6. package/Math/{circle-cdf-points.ts → circle-cdf-points.js} +78 -143
  7. package/Math/{circle.ts → circle.js} +33 -49
  8. package/Math/{constants.ts → constants.js} +4 -12
  9. package/Math/contour/{quadtreecontours.ts → quadtreecontours.js} +300 -371
  10. package/Math/contour/quadtreecontours1.js +298 -336
  11. package/Math/{finite-line-2d.ts → finite-line-2d.js} +58 -68
  12. package/Math/{haversine.ts → haversine.js} +22 -33
  13. package/Math/index.js +1 -0
  14. package/Math/juction/{arc-plane.ts → arc-plane.js} +143 -203
  15. package/Math/juction/{line-sphere.ts → line-sphere.js} +22 -32
  16. package/Math/juction/{plane-plane.ts → plane-plane.js} +53 -62
  17. package/Math/{line.ts → line.js} +52 -84
  18. package/Math/matrix4.js +1 -0
  19. package/Math/{methods.ts → methods.js} +126 -182
  20. package/Math/{plane.ts → plane.js} +56 -92
  21. package/Math/{quaternion.ts → quaternion.js} +106 -128
  22. package/Math/templete-shapes/{grid-visually-equal.ts → grid-visually-equal.js} +65 -118
  23. package/Math/tessellation/constants.js +1 -0
  24. package/Math/tessellation/{methods.ts → methods.js} +49 -79
  25. package/Math/tessellation/{nearest-value-padding.ts → nearest-value-padding.js} +112 -147
  26. package/Math/tessellation/{spherical-triangle-area.ts → spherical-triangle-area.js} +99 -127
  27. package/Math/tessellation/{tile-merger.ts → tile-merger.js} +429 -578
  28. package/Math/tessellation/{triangle-tessellation.ts → triangle-tessellation.js} +386 -533
  29. package/Math/tessellation/types.js +1 -0
  30. package/Math/types.js +1 -0
  31. package/Math/utils.js +2 -3
  32. package/Math/{vec3.ts → vec3.js} +155 -227
  33. package/Math/{xyz-tile.ts → xyz-tile.js} +18 -26
  34. package/algorithms/search-binary.js +16 -14
  35. package/altitude-locator/adaptors.js +1 -0
  36. package/altitude-locator/keymethod.js +1 -0
  37. package/altitude-locator/plugin.js +344 -445
  38. package/altitude-locator/types.js +21 -26
  39. package/compass-rose/compass-rose-padding-flat.js +230 -274
  40. package/compass-rose/{compass-text-writer.ts → compass-text-writer.js} +155 -210
  41. package/compass-rose/index.js +3 -3
  42. package/{constants.ts → constants.js} +6 -8
  43. package/heatwave/datamanager.js +149 -168
  44. package/heatwave/heatwave.js +206 -261
  45. package/heatwave/index.js +5 -5
  46. package/heatwave/isobar.js +303 -340
  47. package/heatwave/{texture-point-sampler.ts → texture-point-sampler.js} +187 -220
  48. package/investigation-tools/draw/tiles/adapters.js +67 -0
  49. package/investigation-tools/draw/tiles/{tiles.ts → tiles.js} +128 -162
  50. package/jest.config.js +7 -6
  51. package/package.json +1 -1
  52. package/pin/pin-object-array1.js +300 -381
  53. package/pin/pin-point-totem1.js +60 -77
  54. package/programs/arrowfield/arrow-field.js +60 -89
  55. package/programs/arrowfield/logic.js +141 -173
  56. package/programs/data2legend/density-to-legend.js +68 -86
  57. package/programs/data2legend/point-to-density-texture.js +67 -84
  58. package/programs/float2legendwithratio/index.js +2 -3
  59. package/programs/float2legendwithratio/logic.js +118 -144
  60. package/programs/float2legendwithratio/object.js +104 -141
  61. package/programs/helpers/blender.js +58 -73
  62. package/programs/helpers/{fadeaway.ts → fadeaway.js} +60 -73
  63. package/programs/index.js +20 -19
  64. package/programs/line-on-globe/circle-accurate-3d.js +85 -112
  65. package/programs/line-on-globe/circle-accurate-flat.js +148 -200
  66. package/programs/line-on-globe/degree-padding-around-circle-3d.js +102 -134
  67. package/programs/line-on-globe/index.js +1 -0
  68. package/programs/line-on-globe/lines-color-instanced-flat.js +80 -99
  69. package/programs/line-on-globe/linestrip/data.js +4 -0
  70. package/programs/line-on-globe/linestrip/{linestrip.ts → linestrip.js} +93 -152
  71. package/programs/line-on-globe/{naive-accurate-flexible.ts → naive-accurate-flexible.js} +126 -175
  72. package/programs/line-on-globe/util.js +5 -8
  73. package/programs/picking/pickable-polygon-renderer.js +98 -129
  74. package/programs/picking/pickable-renderer.js +98 -130
  75. package/programs/point-on-globe/element-globe-surface-glow.js +93 -122
  76. package/programs/point-on-globe/element-point-glow.js +80 -114
  77. package/programs/point-on-globe/square-pixel-point.js +121 -139
  78. package/programs/polygon-on-globe/{texture-dem-triangles.ts → texture-dem-triangles.js} +163 -207
  79. package/programs/{programcache.ts → programcache.js} +126 -134
  80. package/programs/rings/index.js +1 -1
  81. package/programs/rings/partial-ring/{piece-of-pie.ts → piece-of-pie.js} +152 -222
  82. package/programs/totems/camera-totem-attactment-interface.js +1 -0
  83. package/programs/totems/{camerauniformblock.ts → camerauniformblock.js} +225 -310
  84. package/programs/totems/{canvas-webglobe-info.ts → canvas-webglobe-info.js} +132 -147
  85. package/programs/totems/{dem-textures-manager.ts → dem-textures-manager.js} +257 -360
  86. package/programs/totems/{globe-changes.ts → globe-changes.js} +59 -79
  87. package/programs/totems/gpu-selection-uniform-block.js +99 -127
  88. package/programs/totems/{index.ts → index.js} +2 -2
  89. package/programs/two-d/pixel-padding-for-compass.js +87 -101
  90. package/programs/util.js +14 -19
  91. package/programs/vectorfields/logics/{constants.ts → constants.js} +4 -5
  92. package/programs/vectorfields/logics/{drawrectangleparticles.ts → drawrectangleparticles.js} +80 -115
  93. package/programs/vectorfields/logics/index.js +2 -4
  94. package/programs/vectorfields/logics/particle-ubo.js +16 -0
  95. package/programs/vectorfields/logics/{pixelbased.ts → pixelbased.js} +86 -115
  96. package/programs/vectorfields/logics/ubo.js +51 -57
  97. package/programs/vectorfields/{pingpongbuffermanager.ts → pingpongbuffermanager.js} +99 -113
  98. package/range-tools-on-terrain/bearing-line/{adapters.ts → adapters.js} +114 -154
  99. package/range-tools-on-terrain/bearing-line/{plugin.ts → plugin.js} +457 -569
  100. package/range-tools-on-terrain/bearing-line/types.js +1 -0
  101. package/range-tools-on-terrain/circle-line-chain/{adapters.ts → adapters.js} +85 -104
  102. package/range-tools-on-terrain/circle-line-chain/{chain-list-map.ts → chain-list-map.js} +382 -446
  103. package/range-tools-on-terrain/circle-line-chain/{plugin.ts → plugin.js} +464 -607
  104. package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
  105. package/range-tools-on-terrain/range-ring/{adapters.ts → adapters.js} +93 -114
  106. package/range-tools-on-terrain/range-ring/{enum.ts → enum.js} +2 -2
  107. package/range-tools-on-terrain/range-ring/{plugin.ts → plugin.js} +377 -444
  108. package/range-tools-on-terrain/range-ring/rangeringangletext.js +331 -0
  109. package/range-tools-on-terrain/range-ring/types.js +9 -0
  110. package/semiplugins/interface.js +1 -0
  111. package/semiplugins/lightweight/{line-plugin.ts → line-plugin.js} +221 -342
  112. package/semiplugins/lightweight/{piece-of-pie-plugin.ts → piece-of-pie-plugin.js} +200 -275
  113. package/semiplugins/shape-on-terrain/{arc-plugin.ts → arc-plugin.js} +481 -616
  114. package/semiplugins/shape-on-terrain/{circle-plugin.ts → circle-plugin.js} +444 -588
  115. package/semiplugins/shape-on-terrain/{padding-1-degree.ts → padding-1-degree.js} +539 -713
  116. package/semiplugins/shape-on-terrain/terrain-polygon/{adapters.ts → adapters.js} +55 -69
  117. package/semiplugins/shape-on-terrain/terrain-polygon/data/{cache.ts → cache.js} +102 -149
  118. package/semiplugins/shape-on-terrain/terrain-polygon/data/{index-polygon-map.ts → index-polygon-map.js} +45 -58
  119. package/semiplugins/shape-on-terrain/terrain-polygon/data/{manager.ts → manager.js} +4 -4
  120. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +177 -196
  121. package/semiplugins/shape-on-terrain/terrain-polygon/data/{polygon-to-triangles.ts → polygon-to-triangles.js} +100 -144
  122. package/semiplugins/shape-on-terrain/terrain-polygon/data/{random.ts → random.js} +121 -165
  123. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.js +1 -0
  124. package/semiplugins/shape-on-terrain/terrain-polygon/data/{worker-contact.ts → worker-contact.js} +63 -81
  125. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +125 -146
  126. package/semiplugins/shape-on-terrain/terrain-polygon/{terrain-polygon.ts → terrain-polygon.js} +219 -265
  127. package/semiplugins/shape-on-terrain/terrain-polygon/types.js +8 -0
  128. package/semiplugins/shell/bbox-renderer/index.js +2 -0
  129. package/semiplugins/shell/bbox-renderer/{logic.ts → logic.js} +209 -273
  130. package/semiplugins/shell/bbox-renderer/object.js +75 -0
  131. package/semiplugins/type.js +1 -0
  132. package/semiplugins/utility/{container-plugin.ts → container-plugin.js} +94 -126
  133. package/semiplugins/utility/{object-pass-container-plugin.ts → object-pass-container-plugin.js} +80 -101
  134. package/shaders/fragment-toy/firework.js +1 -1
  135. package/shaders/fragment-toy/singularity.js +2 -5
  136. package/tracks/point-heat-map/adaptors/timetracksplugin-format-to-this.js +63 -78
  137. package/tracks/point-heat-map/index.js +1 -0
  138. package/tracks/point-heat-map/plugin-webworker.js +121 -148
  139. package/tracks/point-heat-map/point-to-heat-map-flow.js +121 -150
  140. package/tracks/point-tracks/key-methods.js +2 -3
  141. package/tracks/point-tracks/plugin.js +401 -487
  142. package/tracks/timetracks/adaptors-line-strip.js +65 -79
  143. package/tracks/timetracks/plugin-line-strip.js +240 -295
  144. package/tracks/timetracks/program-line-strip.js +411 -495
  145. package/tracks/timetracks/programpoint-line-strip.js +109 -137
  146. package/types.js +19 -0
  147. package/util/account/bufferoffsetmanager.js +176 -209
  148. package/util/account/create-buffermap-orchastration.js +39 -0
  149. package/util/account/index.js +3 -6
  150. package/util/account/single-attribute-buffer-management/{buffer-manager.ts → buffer-manager.js} +119 -151
  151. package/util/account/single-attribute-buffer-management/{buffer-orchestrator.ts → buffer-orchestrator.js} +212 -238
  152. package/util/account/single-attribute-buffer-management/{buffer-orchestrator1.ts → buffer-orchestrator1.js} +159 -184
  153. package/util/account/single-attribute-buffer-management/{index.ts → index.js} +4 -11
  154. package/util/account/single-attribute-buffer-management/{object-store.ts → object-store.js} +55 -76
  155. package/util/account/single-attribute-buffer-management/types.js +1 -0
  156. package/util/account/util.js +18 -22
  157. package/util/algorithms/index.js +1 -0
  158. package/util/algorithms/search-binary.js +25 -26
  159. package/util/build-strategy/{static-dynamic.ts → static-dynamic.js} +41 -50
  160. package/util/check/index.js +1 -0
  161. package/util/check/typecheck.js +66 -0
  162. package/util/{frame-counter-trigger.ts → frame-counter-trigger.js} +84 -99
  163. package/util/geometry/{index.ts → index.js} +121 -155
  164. package/util/gl-util/buffer/{attribute-loader.ts → attribute-loader.js} +62 -84
  165. package/util/gl-util/buffer/{index.ts → index.js} +3 -6
  166. package/util/gl-util/draw-options/{methods.ts → methods.js} +32 -47
  167. package/util/gl-util/uniform-block/{manager.ts → manager.js} +200 -232
  168. package/util/{globe-default-gl-states.ts → globe-default-gl-states.js} +4 -5
  169. package/util/{helper-methods.ts → helper-methods.js} +8 -9
  170. package/util/index.js +10 -9
  171. package/util/interpolation/index.js +1 -0
  172. package/util/interpolation/timetrack/index.js +2 -9
  173. package/util/interpolation/timetrack/timetrack-interpolator.js +79 -94
  174. package/util/interpolation/timetrack/web-worker.js +46 -51
  175. package/util/picking/{fence.ts → fence.js} +43 -47
  176. package/util/picking/{picker-displayer.ts → picker-displayer.js} +176 -226
  177. package/util/programs/draw-from-pixel-coords.js +164 -201
  178. package/util/programs/{draw-texture-on-canvas.ts → draw-texture-on-canvas.js} +69 -91
  179. package/util/programs/supersampletotextures.js +97 -130
  180. package/util/programs/texturetoglobe.js +128 -153
  181. package/util/shaderfunctions/{geometrytransformations.ts → geometrytransformations.js} +44 -106
  182. package/util/shaderfunctions/index.js +2 -2
  183. package/util/shaderfunctions/nodata.js +2 -4
  184. package/util/shaderfunctions/noisefunctions.js +7 -10
  185. package/util/{webglobjectbuilders.ts → webglobjectbuilders.js} +358 -446
  186. package/vectorfield/arrowfield/adaptor.js +11 -11
  187. package/vectorfield/arrowfield/index.js +3 -3
  188. package/vectorfield/arrowfield/plugin.js +83 -128
  189. package/vectorfield/waveparticles/adaptor.js +15 -16
  190. package/vectorfield/waveparticles/index.js +3 -3
  191. package/vectorfield/waveparticles/{plugin.ts → plugin.js} +415 -506
  192. package/vectorfield/wind/adapters/{image-to-fields.ts → image-to-fields.js} +61 -74
  193. package/vectorfield/wind/adapters/types.js +1 -0
  194. package/vectorfield/wind/{imagetovectorfieldandmagnitude.ts → imagetovectorfieldandmagnitude.js} +53 -78
  195. package/vectorfield/wind/index.js +5 -5
  196. package/vectorfield/wind/{plugin-persistant copy.ts → plugin-persistant copy.js } +364 -461
  197. package/vectorfield/wind/{plugin-persistant.ts → plugin-persistant.js} +375 -483
  198. package/vectorfield/wind/plugin.js +685 -883
  199. package/vectorfield/wind/vectorfieldimage.js +23 -27
  200. package/write-text/{context-text-bulk.ts → context-text-bulk.js} +200 -285
  201. package/write-text/context-text3.js +167 -0
  202. package/write-text/{context-text4.ts → context-text4.js} +146 -231
  203. package/write-text/context-textDELETE.js +94 -125
  204. package/write-text/objectarraylabels/{index.ts → index.js} +2 -2
  205. package/write-text/objectarraylabels/objectarraylabels.js +200 -247
  206. package/Math/matrix4.ts +0 -0
  207. package/Math/mesh/mapbox-delaunay.d.ts +0 -74
  208. package/Math/roadmap.md +0 -10
  209. package/Math/tessellation/constants.ts +0 -1
  210. package/Math/tessellation/roadmap.md +0 -48
  211. package/Math/tessellation/types.ts +0 -1
  212. package/Math/types.ts +0 -68
  213. package/investigation-tools/draw/tiles/adapters.ts +0 -133
  214. package/programs/line-on-globe/linestrip/data.ts +0 -29
  215. package/programs/polygon-on-globe/roadmap.md +0 -8
  216. package/programs/totems/camera-totem-attactment-interface.ts +0 -4
  217. package/programs/vectorfields/logics/particle-ubo.ts +0 -23
  218. package/publish.bat +0 -62
  219. package/range-tools-on-terrain/bearing-line/types.ts +0 -65
  220. package/range-tools-on-terrain/circle-line-chain/types.ts +0 -43
  221. package/range-tools-on-terrain/range-ring/rangeringangletext.ts +0 -396
  222. package/range-tools-on-terrain/range-ring/types.ts +0 -30
  223. package/semiplugins/interface.ts +0 -14
  224. package/semiplugins/shape-on-terrain/goal.md +0 -12
  225. package/semiplugins/shape-on-terrain/terrain-polygon/data/cache-shortcuts.md +0 -20
  226. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.ts +0 -209
  227. package/semiplugins/shape-on-terrain/terrain-polygon/data/readme.md +0 -5
  228. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.ts +0 -37
  229. package/semiplugins/shape-on-terrain/terrain-polygon/notes.md +0 -90
  230. package/semiplugins/shape-on-terrain/terrain-polygon/types.ts +0 -69
  231. package/semiplugins/shell/bbox-renderer/index.ts +0 -2
  232. package/semiplugins/shell/bbox-renderer/object.ts +0 -129
  233. package/semiplugins/type.ts +0 -8
  234. package/terrain-plugin.mmd +0 -83
  235. package/tests/Math/arc-sampling-test.js +0 -367
  236. package/tests/Math/arc-sampling-test.ts +0 -429
  237. package/tests/Math/arc.test.ts +0 -77
  238. package/tests/Math/junction/arc-limit.test.ts +0 -7
  239. package/tests/Math/junction/arc-plane-points.test.ts +0 -196
  240. package/tests/Math/junction/arc-plane.test.ts +0 -172
  241. package/tests/Math/junction/line-sphere.test.ts +0 -127
  242. package/tests/Math/junction/plane-plane.test.ts +0 -91
  243. package/tests/Math/plane-test.ts +0 -17
  244. package/tests/Math/plane.test.ts +0 -43
  245. package/tests/Math/vec3.test.ts +0 -33
  246. package/tracks/point-heat-map/readme.md +0 -15
  247. package/tracks/timetracks/readme.md +0 -1
  248. package/tsconfig.json +0 -22
  249. package/types/@pirireis/webglobe.d.ts +0 -102
  250. package/types/delaunator.d.ts +0 -40
  251. package/types/earcut.d.ts +0 -11
  252. package/types/rbush.d.ts +0 -57
  253. package/types.ts +0 -319
  254. package/util/account/create-buffermap-orchastration.ts +0 -85
  255. package/util/account/single-attribute-buffer-management/types.ts +0 -43
  256. package/util/check/typecheck.ts +0 -74
  257. package/vectorfield/wind/adapters/types.ts +0 -12
  258. package/write-text/context-text3.ts +0 -252
  259. package/write-text/objectarraylabels/objectarraylabels.d.ts +0 -72
@@ -1,616 +1,481 @@
1
- import { SemiPluginInterface, } from "../interface";
2
- import { Vec3, LongLat, Arc } from "../../Math/types";
3
- import { Globe, Meter, UBOHandler, PluginInterface, Color, Radian, BUFFER_TYPE, ElevationMode, GlobeChanges, UpdateColor } from "../../types";
4
- // import { ArcOnTerrainPluginOptions } from "./type";
5
- import { LineStripProgramCache, LineProgram } from "../../programs/line-on-globe/linestrip/linestrip";
6
- import { createBufferAndReadInfo } from "../../util/gl-util/buffer/attribute-loader";
7
- import { BufferManagersMap, BufferManager, BufferOrchestrator } from "../../util/account/single-attribute-buffer-management/index";
8
- import { globe3Dcoordinates, globe2Dcoordinates, RADIAN } from "../../Math/methods";
9
- import { generateArcPoints, evenlySpacedArcPoints } from "../../Math/arc-cdf-points";
10
- import { StaticDynamicState, StaticDynamicStrategy } from "../../util/build-strategy/static-dynamic";
11
- import { opacityCheck } from "../../util/check/typecheck";
12
- import { FrameCounterTrigger } from "../../util/frame-counter-trigger";
13
- import * as vec3 from "../../Math/vec3";
14
-
15
- import * as arc from "../../Math/arc";
16
-
17
- import { CameraUniformBlockTotem, CameraUniformBlockTotemCache } from "../../programs/totems/camerauniformblock";
18
- import { WORLD_RADIUS_3D } from "../../Math/constants";
19
-
20
-
21
- const DYNAMIC_STRATEGY_START_LOD = 12;
22
-
23
- const INITAL_CAPACITY = 10;
24
- const _attractionPoint = [0, 0, 0] as Vec3;
25
- const _start = [0, 0, 0] as Vec3;
26
- const _end = [0, 0, 0] as Vec3;
27
- const _0arc = arc.create([1, 0, 0] as Vec3, [0, 1, 0] as Vec3); // zero arc for intersection tests
28
-
29
-
30
- export type ArcOnTerrainPluginOptions = {
31
- variativeColorsOn: boolean; // If true, arcs can have variative colors
32
- defaultColor: Color; // Default color in RGBA format
33
- defaultHeightFromGroundIn3D: Meter; // Default height from ground in 3D view
34
- flatViewOn: boolean; // If true, arcs are drawn in 2D flat view
35
- globeViewOn: boolean; // If true, arcs are drawn in 3D globe view
36
- // variativeColorsOn: boolean; // If true, arcs can have variative colors
37
- // defaultColor: [number, number, number, number]; // Default color in RGBA format
38
- // defaultHeightFromGroundIn3D: number; // Default height from ground in 3D view
39
- vertexCount: number; // Number of vertices per arc,
40
- cameraAttractionIsOn: boolean; // If true, camera attraction is enabled else evenly distributed arc points are used
41
- bufferType?: BUFFER_TYPE; // Buffer type for WebGL
42
- isMSL: boolean; // If true, the arc is drawn in MSL (Mean Sea Level) mode
43
- };
44
-
45
-
46
- export type ArcInput = {
47
- key: string,
48
- start: LongLat,
49
- end: LongLat,
50
- color: Color, // 0-1
51
- height?: Meter | null // height from ground in 3D view, null for default
52
- msl?: boolean | null
53
- }
54
-
55
-
56
- function createArc(start: LongLat, end: LongLat): Arc {
57
- vec3.fromLongLatToUnitVector(_start, [start[0] * RADIAN, start[1] * RADIAN]);
58
- vec3.fromLongLatToUnitVector(_end, [end[0] * RADIAN, end[1] * RADIAN]);
59
- return arc.create(_start, _end);
60
- }
61
- export class ArcOnTerrainPlugin implements PluginInterface, SemiPluginInterface, ElevationMode, UpdateColor {
62
- public id: string;
63
- private program: LineProgram | null = null;
64
- private bufferManagersMap: BufferManagersMap | null = null;
65
- private bufferOrchestrator: BufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
66
- private _opacity: number = 1;
67
- private _arcUBOHandler: UBOHandler | null = null;
68
- private _vao: WebGLVertexArrayObject | null = null;
69
- globe: any | null = null;
70
- private gl: WebGL2RenderingContext | null = null;
71
- private _arcMap: Map<string, [Arc, ArcInput]>;
72
- private _cameraUniformBlock: CameraUniformBlockTotem | null = null;
73
- private _staticDynamicStrategy: StaticDynamicStrategy | null = null;
74
- private _options: ArcOnTerrainPluginOptions;
75
- private _coordinaateBufferKeysForUpdate: string[] = [];
76
- private _freed: boolean = false;
77
- private _frameCounterTrigger: FrameCounterTrigger | null = null;
78
- constructor(id: string, {
79
- globeViewOn = true, // If true, arcs are drawn in 3D globe view
80
- flatViewOn = true, // If true, arcs are drawn in 2D flat view
81
- variativeColorsOn = false,
82
- defaultColor = [0.1, 0.1, 1, 1], // Default color in RGBA format
83
- defaultHeightFromGroundIn3D = 30.0, // Default height from ground in
84
- vertexCount = 70, // Number of vertices per arc
85
- cameraAttractionIsOn = true, // If true, camera attraction is enabled else evenly distributed arc points are used
86
- bufferType = "STREAM_DRAW",
87
- isMSL = false
88
- }: Partial<ArcOnTerrainPluginOptions> = {}) {
89
- this.id = id;
90
- this._arcMap = new Map();
91
- this._options = {
92
- globeViewOn: globeViewOn ? true : false,
93
- flatViewOn: flatViewOn ? true : false,
94
- variativeColorsOn: variativeColorsOn ? true : false,
95
- defaultColor: defaultColor ? defaultColor : [0.1, 0.1, 1, 1],
96
- defaultHeightFromGroundIn3D: defaultHeightFromGroundIn3D ? defaultHeightFromGroundIn3D : 30.0,
97
- vertexCount: vertexCount ? vertexCount : 70,
98
- cameraAttractionIsOn: cameraAttractionIsOn ? true : false,
99
- bufferType: bufferType ? bufferType : "STREAM_DRAW",
100
- isMSL: isMSL ? true : false
101
- };
102
-
103
- }
104
-
105
- increaseSpace(amount: number): void {
106
- if (this._freed) {
107
- console.warn("Plugin is freed, cannot increase space");
108
- return;
109
- }
110
- if (this.globe === null) {
111
- console.warn("Globe is not initialized.");
112
- return;
113
- }
114
- if (typeof amount !== "number" || amount <= 0) {
115
- console.warn("Invalid amount, must be a positive number");
116
- return;
117
- }
118
- this.bufferOrchestrator.ensureSpace(amount, this.bufferManagersMap!);
119
- }
120
-
121
- insertBulk(arcs: ArcInput[]) {
122
- const keys = [];
123
- let newItemCount = 0;
124
- for (let arcInput of arcs) {
125
- const { key, start, end } = arcInput;
126
- if (this._arcMap.has(key)) {
127
- this._arcMap.delete(key); // Remove old arc
128
- } else {
129
- newItemCount++;
130
- }
131
- const _arc = createArc(start, end);
132
- this._arcMap.set(key, [_arc, arcInput]); // Always set new color
133
- keys.push(key);
134
- }
135
- this.bufferOrchestrator.ensureSpace(newItemCount, this.bufferManagersMap!);
136
- this._buildArcs(keys);
137
- if (this._options.variativeColorsOn) {
138
- this.__fillColors(keys);
139
- }
140
- this.globe.DrawRender();
141
- }
142
-
143
-
144
- updateCoordinates(items: Pick<ArcInput, "key" | "start" | "end">[]): void {
145
- if (this._freed) {
146
- console.warn("Plugin is freed, cannot update coordinates");
147
- return;
148
- }
149
- if (this.globe === null || this.gl === null) {
150
- console.warn("Globe or WebGL context is not initialized, cannot update coordinates");
151
- return;
152
- }
153
- const updateKeys = []
154
- for (const { key, start, end } of items) {
155
- const arcInput = this._arcMap.get(key);
156
- if (!arcInput) {
157
- console.warn(`Arc with key ${key} not found in arcMap.`);
158
- continue;
159
- }
160
- const _arc = createArc(start, end);
161
- arc.copy(arcInput[0], _arc); // Update the arc in the map
162
- // Update the arc in the buffer
163
- updateKeys.push(key);
164
- }
165
- this._buildArcs(updateKeys);
166
-
167
- this.globe.DrawRender();
168
- }
169
-
170
-
171
- deleteBulk(keys: string[]) {
172
- if (!this.bufferOrchestrator || !this.bufferManagersMap || !this.globe) {
173
- console.warn("Buffer orchestrator or buffer manager map is not initialized.");
174
- return;
175
- }
176
- for (const key of keys) {
177
- if (this._arcMap.has(key)) {
178
- this._arcMap.delete(key);
179
- } else {
180
- console.warn(`Arc with key ${key} not found in arcMap.`);
181
- }
182
- }
183
- this.bufferOrchestrator.deleteBulk(keys, this.bufferManagersMap);
184
- this.globe.DrawRender();
185
- }
186
-
187
-
188
- deleteAll() {
189
- if (!this.bufferOrchestrator || !this.bufferManagersMap || !this.globe) {
190
- console.warn("Buffer orchestrator or buffer manager map is not initialized.");
191
- return;
192
- }
193
- this.bufferOrchestrator.resetWithCapacity(this.bufferManagersMap, this._arcMap.size);
194
- this._arcMap.clear();
195
- this.globe.DrawRender();
196
- }
197
-
198
-
199
-
200
- updateColors(keyColorCouples: { key: string, color: Color }[], drawRender: boolean = true) {
201
- if (this._freed) {
202
- console.warn("Plugin is freed, cannot update color");
203
- return;
204
- }
205
- if (this._options.variativeColorsOn === false) {
206
- console.warn("Variative colors are not enabled in this plugin. Create another instance with variativeColorsOn: true to use this feature.");
207
- return;
208
- }
209
-
210
- const { bufferOrchestrator, bufferManagersMap } = this;
211
- if (!bufferOrchestrator || !bufferManagersMap) {
212
- console.warn("Buffer orchestrator or buffer manager map is not initialized.");
213
- return;
214
- }
215
-
216
- for (const { key, color } of keyColorCouples) {
217
-
218
- const arcInput = this._arcMap.get(key)
219
- if (!arcInput) {
220
- console.warn(`Arc with key ${key} not found in arcMap.`);
221
- return;
222
- }
223
-
224
- arcInput[1].color = color as Color; // Update the color in the arc map
225
- bufferOrchestrator.updateBulk(
226
- [{ key: key, color: color }],
227
- bufferManagersMap, ["color"]
228
- );
229
- }
230
- if (drawRender) {
231
- this.globe.DrawRender();
232
- }
233
- }
234
-
235
-
236
- setPluginOpacity(opacity: number, drawRender: boolean = false): void {
237
- if (!this.globe || !this.gl) {
238
- console.warn("Globe or WebGL context is not initialized.");
239
- return;
240
- }
241
- opacityCheck(opacity)
242
- this._opacity = opacity;
243
-
244
- if (drawRender) {
245
- this.globe.DrawRender();
246
- }
247
- }
248
-
249
-
250
-
251
-
252
-
253
-
254
- setDefaultColor(color: Color, drawRender = false): void {
255
- if (!this.globe || !this.gl) {
256
- console.warn("Globe or WebGL context is not initialized.");
257
- return;
258
- }
259
- this._options.defaultColor = color;
260
- this._arcUBOHandler?.updateSingle("u_color", new Float32Array(color));
261
-
262
- if (drawRender) {
263
- this.globe.DrawRender();
264
- }
265
- }
266
-
267
-
268
- setElevationMode(mode: "msl" | "agl"): void {
269
- switch (mode) {
270
- case "msl":
271
- this._options.isMSL = true;
272
- break;
273
- case "agl":
274
- this._options.isMSL = false;
275
- break;
276
- default:
277
- throw new Error(`Unknown elevation mode: ${mode}`);
278
- }
279
- this._buildArcs(); // can be async
280
- this.globe.DrawRender();
281
- }
282
-
283
-
284
- setCameraAttraction(isOn: boolean) {
285
- if (!this.globe || !this.gl) {
286
- console.warn("Globe or WebGL context is not initialized.");
287
- return;
288
- }
289
- this._options.cameraAttractionIsOn = isOn;
290
- this.globe.DrawRender();
291
- }
292
-
293
-
294
- init(globe: Globe, gl: WebGL2RenderingContext) {
295
- this.globe = globe;
296
- this.gl = gl;
297
-
298
-
299
- this._frameCounterTrigger = new FrameCounterTrigger(globe, 15, 1000, (globeChanges: GlobeChanges) => {
300
- if (this._freed) return;
301
- this.__buildDynamicArcs();
302
- });
303
-
304
- this.program = LineStripProgramCache.get(globe) as LineProgram;
305
-
306
- this._staticDynamicStrategy = new StaticDynamicStrategy(globe, DYNAMIC_STRATEGY_START_LOD, () => {
307
- this.__buildStaticArcs();
308
- }); // Initialize static-dynamic strategy with a transition level of 8
309
-
310
- this._cameraUniformBlock = CameraUniformBlockTotemCache.get(globe);
311
-
312
- this._fillbufferManagersMap();
313
-
314
- this.bufferOrchestrator = new BufferOrchestrator();
315
-
316
- this._arcUBOHandler = this.program.createUBO();
317
- this._arcUBOHandler.update(new Map([
318
- ["u_color", new Float32Array(this._options.defaultColor)],
319
- ]));
320
- }
321
-
322
-
323
- draw3D() {
324
- // Drawing logic here
325
- if (!this.globe || !this.gl) {
326
- console.warn("Globe or WebGL context is not initialized.");
327
- return;
328
- }
329
- const globe = this.globe as Globe;
330
- this._staticDynamicStrategy?.updateState();
331
- // if (globe.api_IsScreenMoving()) {
332
- // this._buildArcs(); // can be async
333
- // }
334
- this._frameCounterTrigger?.trigger();
335
- const { gl, program, bufferOrchestrator, _vao, _arcUBOHandler, } = this;
336
- if (!gl || !program || !bufferOrchestrator || !_vao || !_arcUBOHandler) {
337
- console.warn("WebGL context, program, or buffer orchestrator is not initialized.");
338
- return;
339
- }
340
-
341
- gl.disable(gl.DEPTH_TEST);
342
-
343
- const currentGeometry = globe.api_GetCurrentGeometry();
344
- if ((currentGeometry === 0 && !this._options.globeViewOn) || (currentGeometry === 1 && !this._options.flatViewOn)) return;
345
-
346
- const drawOptions = {
347
- drawRange: {
348
- first: 0,
349
- count: bufferOrchestrator.length * (this._options.vertexCount + 1)
350
- },
351
- indexes: null
352
- }
353
-
354
- program.draw(
355
- _vao,
356
- drawOptions,
357
- this._opacity,
358
- _arcUBOHandler
359
- );
360
- gl.enable(gl.DEPTH_TEST);
361
- }
362
-
363
-
364
- _buildArcs(subSetIDs: string[] | null = null) {
365
- const state = this._staticDynamicStrategy?.getState();
366
- if (state === StaticDynamicState.DYNAMIC) {
367
- this.__buildDynamicArcs(subSetIDs);
368
- } else if (subSetIDs || state === StaticDynamicState.TO_STATIC) {
369
- this.__buildStaticArcs(subSetIDs);
370
- }
371
- }
372
-
373
-
374
-
375
- __buildStaticArcs(subSetIDs: string[] | null = null) {
376
- const { globe, _arcMap, _cameraUniformBlock, bufferManagersMap, bufferOrchestrator } = this;
377
- if (!globe || !_cameraUniformBlock || !bufferManagersMap || !bufferOrchestrator) {
378
- console.warn("Globe or camera uniform block is not initialized.");
379
- return;
380
- }
381
-
382
- const bufferKey = [this.globe!.api_GetCurrentGeometry() === 0 ? "position3d" : "position2d"]
383
- if (!this.bufferManagersMap?.has(bufferKey[0])) return;
384
-
385
- const longLat = [0, 0] as [number, number];
386
- const longLatArr = new Float32Array(2 * this._options.vertexCount);
387
-
388
- const data: [{
389
- key: string,
390
- longLatArr: Float32Array,
391
- height: Meter | null
392
- color?: Color
393
- msl?: boolean | null
394
- }] = [{
395
- key: "staticArcs",
396
- longLatArr: longLatArr,
397
- height: null,
398
- color: this._options.defaultColor,
399
- msl: null
400
- }];
401
-
402
- let keys;
403
- if (subSetIDs === null) {
404
- keys = _arcMap.keys();
405
- } else {
406
- keys = subSetIDs;
407
- }
408
-
409
-
410
- for (const key of keys) {
411
- const [arcInstance, arcInput] = _arcMap.get(key) as [Arc, ArcInput];
412
- arc.copy(_0arc, arcInstance);
413
- const generatedPoints = evenlySpacedArcPoints(_0arc.p0, _0arc.normal, _0arc.coverAngle as Radian, this._options.vertexCount);
414
-
415
- for (let i = 0; i < generatedPoints.length; i++) {
416
- const point = generatedPoints[i];
417
- vec3.fromUnitVectorToLongLat(longLat, point);
418
- longLatArr.set([longLat[0] / RADIAN, longLat[1] / RADIAN], i * 2);
419
- }
420
-
421
- data[0].key = key;
422
- data[0].height = arcInput.height ?? this._options.defaultHeightFromGroundIn3D;
423
- data[0].color = arcInput.color ?? this._options.defaultColor;
424
- data[0].msl = arcInput.msl ?? null;
425
-
426
- this.bufferOrchestrator.insertBulk(data, bufferManagersMap,
427
- bufferKey
428
- );
429
- }
430
- }
431
-
432
-
433
- __buildDynamicArcs(subSetIDs: string[] | null = null) {
434
-
435
- const { globe, _arcMap, _cameraUniformBlock, bufferManagersMap } = this;
436
- if (!globe || !_cameraUniformBlock || !bufferManagersMap) {
437
- console.warn("Globe or camera uniform block is not initialized.");
438
- return;
439
- }
440
- const bufferKey = [
441
- this.globe!.api_GetCurrentGeometry() === 0 ? "position3d" : "position2d"
442
- ]
443
- if (!this.bufferManagersMap?.has(bufferKey[0])) return;
444
-
445
- const { cameraAttractionIsOn } = this._options;
446
-
447
- const lookAtPosition = _cameraUniformBlock.getLookAtVector();
448
- const cameraPosition = _cameraUniformBlock.getCameraVector();
449
- vec3.divideScalar(cameraPosition, cameraPosition, WORLD_RADIUS_3D);
450
-
451
- vec3.add(cameraPosition, cameraPosition, lookAtPosition);
452
- // vec3.normalize(cameraPosition, cameraPosition);
453
- vec3.divideScalar(cameraPosition, cameraPosition, 2);
454
- // vec3.multiplyScalar(cameraPosition, cameraPosition, 1.3);
455
-
456
-
457
-
458
- const _attractionStrength = (() => {
459
- const lod = globe.api_GetCurrentLODWithDecimal();
460
- if (lod < 11) {
461
- return 1;
462
- }
463
- return lod * (lod - 8.5);
464
- })();
465
-
466
- const result = [];
467
- const longLat = [0, 0] as [number, number];
468
-
469
- let keys;
470
- if (subSetIDs === null) {
471
- keys = _arcMap.keys();
472
- } else {
473
- keys = subSetIDs;
474
- }
475
-
476
- for (const key of keys) {
477
- const [arcInstance, arcInput] = _arcMap.get(key) as [Arc, ArcInput];
478
- arc.copy(_0arc, arcInstance);
479
- const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPosition);
480
- if (!isOnArc) {
481
- if (vec3.distanceSquared(cameraPosition, _0arc.p0) < vec3.distanceSquared(cameraPosition, _0arc.p1)) {
482
- vec3.copy(_attractionPoint, _0arc.p0)
483
- } else {
484
- vec3.copy(_attractionPoint, _0arc.p1);
485
- }
486
- }
487
- const generatedPoints = cameraAttractionIsOn ?
488
- generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, this._options.vertexCount, _attractionStrength)
489
- : evenlySpacedArcPoints(_0arc.p0, _0arc.normal, _0arc.coverAngle as Radian, this._options.vertexCount);
490
- const longLatArr = new Float32Array(2 * this._options.vertexCount);
491
- for (let i = 0; i < generatedPoints.length; i++) {
492
- const point = generatedPoints[i];
493
- vec3.fromUnitVectorToLongLat(longLat, point);
494
- longLatArr.set([longLat[0] / RADIAN, longLat[1] / RADIAN], i * 2);
495
- }
496
- result.push({
497
- key: key,
498
- longLatArr: longLatArr,
499
- height: arcInput.height ?? this._options.defaultHeightFromGroundIn3D,
500
- msl: arcInput.msl ?? null
501
- })
502
- }
503
- // this.bufferOrchestrator.resetWithCapacity(bufferManagersMap, result.length);
504
-
505
- this.bufferOrchestrator.insertBulk(result, bufferManagersMap, bufferKey);
506
- }
507
-
508
-
509
- _fillbufferManagersMap() {
510
- const { gl, globe } = this;
511
- if (!gl || !globe) {
512
- console.warn("WebGL context or globe is not initialized.");
513
- return;
514
- }
515
- const g2D = globe2Dcoordinates(globe);
516
- const { flatViewOn, globeViewOn, variativeColorsOn } = this._options;
517
- this.bufferManagersMap = new Map();
518
- if (globeViewOn) {
519
- this.bufferManagersMap.set("position3d", {
520
- bufferManager: new BufferManager(gl, 3 * (this._options.vertexCount + 1), { bufferType: "STREAM_DRAW", initialCapacity: INITAL_CAPACITY }),
521
- adaptor: (item: any) => {
522
- const { longLatArr, height = this._options.defaultHeightFromGroundIn3D, msl = this._options.isMSL } = item;
523
- const result = globe3Dcoordinates(globe, longLatArr, height, msl, { paddingCount: 1 });
524
- return result;
525
- }
526
- });
527
- }
528
-
529
- if (flatViewOn) {
530
- this.bufferManagersMap.set("position2d", {
531
- bufferManager: new BufferManager(gl, 2 * (this._options.vertexCount + 1), { bufferType: "STREAM_DRAW", initialCapacity: INITAL_CAPACITY }),
532
- adaptor: (item: any) => {
533
- const { longLatArr } = item;
534
- return g2D(longLatArr, { paddingCount: 1 });
535
- }
536
- });
537
- }
538
-
539
- if (this._options.variativeColorsOn) {
540
- const _colorArray = new Float32Array(4 * (this._options.vertexCount + 1)); // TODO: this could cause data races or unexpected overwrites.
541
- this.bufferManagersMap.set("color", {
542
- bufferManager: new BufferManager(gl, 4 * (this._options.vertexCount + 1), { bufferType: "STREAM_DRAW", initialCapacity: INITAL_CAPACITY }),
543
- adaptor: (item: any) => {
544
- // Calculate color based on radius
545
- if (item.color) {
546
- for (let i = 0; i < this._options.vertexCount; i++) {
547
- _colorArray.set(item.color, 4 * i); // Fill color for each vertex
548
- }
549
- return _colorArray
550
- } else {
551
- return _colorArray.fill(-1, 0, 4 * (this._options.vertexCount)); // Fill with -1 if no color is provided
552
- }
553
- }
554
- });
555
- }
556
-
557
- const bufferObjects = [
558
- globeViewOn ? "position3d" : null,
559
- flatViewOn ? "position2d" : null,
560
- variativeColorsOn ? "color" : null
561
- ].map(
562
- (key) => {
563
- if (!key) return null;
564
- this._coordinaateBufferKeysForUpdate.push(key);
565
- // @ts-ignore
566
- const bufferManager = this.bufferManagersMap.get(key).bufferManager;
567
- // @ts-ignore
568
- return createBufferAndReadInfo(bufferManager.buffer);
569
- }
570
- )
571
-
572
-
573
- // @ts-ignore
574
- this._vao = this.program.createVAO(
575
- bufferObjects[0], // position3d
576
- bufferObjects[1], // position2d
577
- bufferObjects[2] // color
578
- );
579
- }
580
-
581
-
582
- __fillColors(subSetIDs: string[]) {
583
- if (this._options.variativeColorsOn === false) return;
584
- const data: [ArcInput] = [null!];
585
- for (const id of subSetIDs) {
586
- data[0] = this._arcMap.get(id)![1];
587
- this.bufferOrchestrator.insertBulk(
588
- data,
589
- this.bufferManagersMap!,
590
- ["color"]
591
- );
592
- }
593
- }
594
-
595
-
596
- free() {
597
- if (this._freed) {
598
- console.warn("Plugin already freed");
599
- return;
600
- }
601
- if (!this.gl || !this.program) {
602
- console.warn("WebGL context or program is not initialized.");
603
- return;
604
- }
605
- this._arcUBOHandler?.free();
606
- this.bufferManagersMap?.forEach((manager) => {
607
- manager.bufferManager.free();
608
- });
609
- CameraUniformBlockTotemCache.release(this.globe as Globe);
610
- LineStripProgramCache.release(this.globe as Globe);
611
- this.gl = null;
612
- this.globe = null;
613
- this._arcMap.clear();
614
- this._coordinaateBufferKeysForUpdate = [];
615
- }
616
- }
1
+ // import { ArcOnTerrainPluginOptions } from "./type";
2
+ import { LineStripProgramCache } from "../../programs/line-on-globe/linestrip/linestrip";
3
+ import { createBufferAndReadInfo } from "../../util/gl-util/buffer/attribute-loader";
4
+ import { BufferManager, BufferOrchestrator } from "../../util/account/single-attribute-buffer-management/index";
5
+ import { globe3Dcoordinates, globe2Dcoordinates, RADIAN } from "../../Math/methods";
6
+ import { generateArcPoints, evenlySpacedArcPoints } from "../../Math/arc-cdf-points";
7
+ import { StaticDynamicState, StaticDynamicStrategy } from "../../util/build-strategy/static-dynamic";
8
+ import { opacityCheck } from "../../util/check/typecheck";
9
+ import { FrameCounterTrigger } from "../../util/frame-counter-trigger";
10
+ import * as vec3 from "../../Math/vec3";
11
+ import * as arc from "../../Math/arc";
12
+ import { CameraUniformBlockTotemCache } from "../../programs/totems/camerauniformblock";
13
+ import { WORLD_RADIUS_3D } from "../../Math/constants";
14
+ const DYNAMIC_STRATEGY_START_LOD = 12;
15
+ const INITAL_CAPACITY = 10;
16
+ const _attractionPoint = [0, 0, 0];
17
+ const _start = [0, 0, 0];
18
+ const _end = [0, 0, 0];
19
+ const _0arc = arc.create([1, 0, 0], [0, 1, 0]); // zero arc for intersection tests
20
+ function createArc(start, end) {
21
+ vec3.fromLongLatToUnitVector(_start, [start[0] * RADIAN, start[1] * RADIAN]);
22
+ vec3.fromLongLatToUnitVector(_end, [end[0] * RADIAN, end[1] * RADIAN]);
23
+ return arc.create(_start, _end);
24
+ }
25
+ export class ArcOnTerrainPlugin {
26
+ id;
27
+ program = null;
28
+ bufferManagersMap = null;
29
+ bufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
30
+ _opacity = 1;
31
+ _arcUBOHandler = null;
32
+ _vao = null;
33
+ globe = null;
34
+ gl = null;
35
+ _arcMap;
36
+ _cameraUniformBlock = null;
37
+ _staticDynamicStrategy = null;
38
+ _options;
39
+ _coordinaateBufferKeysForUpdate = [];
40
+ _freed = false;
41
+ _frameCounterTrigger = null;
42
+ constructor(id, { globeViewOn = true, // If true, arcs are drawn in 3D globe view
43
+ flatViewOn = true, // If true, arcs are drawn in 2D flat view
44
+ variativeColorsOn = false, defaultColor = [0.1, 0.1, 1, 1], // Default color in RGBA format
45
+ defaultHeightFromGroundIn3D = 30.0, // Default height from ground in
46
+ vertexCount = 70, // Number of vertices per arc
47
+ cameraAttractionIsOn = true, // If true, camera attraction is enabled else evenly distributed arc points are used
48
+ bufferType = "STREAM_DRAW", isMSL = false } = {}) {
49
+ this.id = id;
50
+ this._arcMap = new Map();
51
+ this._options = {
52
+ globeViewOn: globeViewOn ? true : false,
53
+ flatViewOn: flatViewOn ? true : false,
54
+ variativeColorsOn: variativeColorsOn ? true : false,
55
+ defaultColor: defaultColor ? defaultColor : [0.1, 0.1, 1, 1],
56
+ defaultHeightFromGroundIn3D: defaultHeightFromGroundIn3D ? defaultHeightFromGroundIn3D : 30.0,
57
+ vertexCount: vertexCount ? vertexCount : 70,
58
+ cameraAttractionIsOn: cameraAttractionIsOn ? true : false,
59
+ bufferType: bufferType ? bufferType : "STREAM_DRAW",
60
+ isMSL: isMSL ? true : false
61
+ };
62
+ }
63
+ increaseSpace(amount) {
64
+ if (this._freed) {
65
+ console.warn("Plugin is freed, cannot increase space");
66
+ return;
67
+ }
68
+ if (this.globe === null) {
69
+ console.warn("Globe is not initialized.");
70
+ return;
71
+ }
72
+ if (typeof amount !== "number" || amount <= 0) {
73
+ console.warn("Invalid amount, must be a positive number");
74
+ return;
75
+ }
76
+ this.bufferOrchestrator.ensureSpace(amount, this.bufferManagersMap);
77
+ }
78
+ insertBulk(arcs) {
79
+ const keys = [];
80
+ let newItemCount = 0;
81
+ for (let arcInput of arcs) {
82
+ const { key, start, end } = arcInput;
83
+ if (this._arcMap.has(key)) {
84
+ this._arcMap.delete(key); // Remove old arc
85
+ }
86
+ else {
87
+ newItemCount++;
88
+ }
89
+ const _arc = createArc(start, end);
90
+ this._arcMap.set(key, [_arc, arcInput]); // Always set new color
91
+ keys.push(key);
92
+ }
93
+ this.bufferOrchestrator.ensureSpace(newItemCount, this.bufferManagersMap);
94
+ this._buildArcs(keys);
95
+ if (this._options.variativeColorsOn) {
96
+ this.__fillColors(keys);
97
+ }
98
+ this.globe.DrawRender();
99
+ }
100
+ updateCoordinates(items) {
101
+ if (this._freed) {
102
+ console.warn("Plugin is freed, cannot update coordinates");
103
+ return;
104
+ }
105
+ if (this.globe === null || this.gl === null) {
106
+ console.warn("Globe or WebGL context is not initialized, cannot update coordinates");
107
+ return;
108
+ }
109
+ const updateKeys = [];
110
+ for (const { key, start, end } of items) {
111
+ const arcInput = this._arcMap.get(key);
112
+ if (!arcInput) {
113
+ console.warn(`Arc with key ${key} not found in arcMap.`);
114
+ continue;
115
+ }
116
+ const _arc = createArc(start, end);
117
+ arc.copy(arcInput[0], _arc); // Update the arc in the map
118
+ // Update the arc in the buffer
119
+ updateKeys.push(key);
120
+ }
121
+ this._buildArcs(updateKeys);
122
+ this.globe.DrawRender();
123
+ }
124
+ deleteBulk(keys) {
125
+ if (!this.bufferOrchestrator || !this.bufferManagersMap || !this.globe) {
126
+ console.warn("Buffer orchestrator or buffer manager map is not initialized.");
127
+ return;
128
+ }
129
+ for (const key of keys) {
130
+ if (this._arcMap.has(key)) {
131
+ this._arcMap.delete(key);
132
+ }
133
+ else {
134
+ console.warn(`Arc with key ${key} not found in arcMap.`);
135
+ }
136
+ }
137
+ this.bufferOrchestrator.deleteBulk(keys, this.bufferManagersMap);
138
+ this.globe.DrawRender();
139
+ }
140
+ deleteAll() {
141
+ if (!this.bufferOrchestrator || !this.bufferManagersMap || !this.globe) {
142
+ console.warn("Buffer orchestrator or buffer manager map is not initialized.");
143
+ return;
144
+ }
145
+ this.bufferOrchestrator.resetWithCapacity(this.bufferManagersMap, this._arcMap.size);
146
+ this._arcMap.clear();
147
+ this.globe.DrawRender();
148
+ }
149
+ updateColors(keyColorCouples, drawRender = true) {
150
+ if (this._freed) {
151
+ console.warn("Plugin is freed, cannot update color");
152
+ return;
153
+ }
154
+ if (this._options.variativeColorsOn === false) {
155
+ console.warn("Variative colors are not enabled in this plugin. Create another instance with variativeColorsOn: true to use this feature.");
156
+ return;
157
+ }
158
+ const { bufferOrchestrator, bufferManagersMap } = this;
159
+ if (!bufferOrchestrator || !bufferManagersMap) {
160
+ console.warn("Buffer orchestrator or buffer manager map is not initialized.");
161
+ return;
162
+ }
163
+ for (const { key, color } of keyColorCouples) {
164
+ const arcInput = this._arcMap.get(key);
165
+ if (!arcInput) {
166
+ console.warn(`Arc with key ${key} not found in arcMap.`);
167
+ return;
168
+ }
169
+ arcInput[1].color = color; // Update the color in the arc map
170
+ bufferOrchestrator.updateBulk([{ key: key, color: color }], bufferManagersMap, ["color"]);
171
+ }
172
+ if (drawRender) {
173
+ this.globe.DrawRender();
174
+ }
175
+ }
176
+ setPluginOpacity(opacity, drawRender = false) {
177
+ if (!this.globe || !this.gl) {
178
+ console.warn("Globe or WebGL context is not initialized.");
179
+ return;
180
+ }
181
+ opacityCheck(opacity);
182
+ this._opacity = opacity;
183
+ if (drawRender) {
184
+ this.globe.DrawRender();
185
+ }
186
+ }
187
+ setDefaultColor(color, drawRender = false) {
188
+ if (!this.globe || !this.gl) {
189
+ console.warn("Globe or WebGL context is not initialized.");
190
+ return;
191
+ }
192
+ this._options.defaultColor = color;
193
+ this._arcUBOHandler?.updateSingle("u_color", new Float32Array(color));
194
+ if (drawRender) {
195
+ this.globe.DrawRender();
196
+ }
197
+ }
198
+ setElevationMode(mode) {
199
+ switch (mode) {
200
+ case "msl":
201
+ this._options.isMSL = true;
202
+ break;
203
+ case "agl":
204
+ this._options.isMSL = false;
205
+ break;
206
+ default:
207
+ throw new Error(`Unknown elevation mode: ${mode}`);
208
+ }
209
+ this._buildArcs(); // can be async
210
+ this.globe.DrawRender();
211
+ }
212
+ setCameraAttraction(isOn) {
213
+ if (!this.globe || !this.gl) {
214
+ console.warn("Globe or WebGL context is not initialized.");
215
+ return;
216
+ }
217
+ this._options.cameraAttractionIsOn = isOn;
218
+ this.globe.DrawRender();
219
+ }
220
+ init(globe, gl) {
221
+ this.globe = globe;
222
+ this.gl = gl;
223
+ this._frameCounterTrigger = new FrameCounterTrigger(globe, 15, 1000, (globeChanges) => {
224
+ if (this._freed)
225
+ return;
226
+ this.__buildDynamicArcs();
227
+ });
228
+ this.program = LineStripProgramCache.get(globe);
229
+ this._staticDynamicStrategy = new StaticDynamicStrategy(globe, DYNAMIC_STRATEGY_START_LOD, () => {
230
+ this.__buildStaticArcs();
231
+ }); // Initialize static-dynamic strategy with a transition level of 8
232
+ this._cameraUniformBlock = CameraUniformBlockTotemCache.get(globe);
233
+ this._fillbufferManagersMap();
234
+ this.bufferOrchestrator = new BufferOrchestrator();
235
+ this._arcUBOHandler = this.program.createUBO();
236
+ this._arcUBOHandler.update(new Map([
237
+ ["u_color", new Float32Array(this._options.defaultColor)],
238
+ ]));
239
+ }
240
+ draw3D() {
241
+ // Drawing logic here
242
+ if (!this.globe || !this.gl) {
243
+ console.warn("Globe or WebGL context is not initialized.");
244
+ return;
245
+ }
246
+ const globe = this.globe;
247
+ this._staticDynamicStrategy?.updateState();
248
+ // if (globe.api_IsScreenMoving()) {
249
+ // this._buildArcs(); // can be async
250
+ // }
251
+ this._frameCounterTrigger?.trigger();
252
+ const { gl, program, bufferOrchestrator, _vao, _arcUBOHandler, } = this;
253
+ if (!gl || !program || !bufferOrchestrator || !_vao || !_arcUBOHandler) {
254
+ console.warn("WebGL context, program, or buffer orchestrator is not initialized.");
255
+ return;
256
+ }
257
+ gl.disable(gl.DEPTH_TEST);
258
+ const currentGeometry = globe.api_GetCurrentGeometry();
259
+ if ((currentGeometry === 0 && !this._options.globeViewOn) || (currentGeometry === 1 && !this._options.flatViewOn))
260
+ return;
261
+ const drawOptions = {
262
+ drawRange: {
263
+ first: 0,
264
+ count: bufferOrchestrator.length * (this._options.vertexCount + 1)
265
+ },
266
+ indexes: null
267
+ };
268
+ program.draw(_vao, drawOptions, this._opacity, _arcUBOHandler);
269
+ gl.enable(gl.DEPTH_TEST);
270
+ }
271
+ _buildArcs(subSetIDs = null) {
272
+ const state = this._staticDynamicStrategy?.getState();
273
+ if (state === StaticDynamicState.DYNAMIC) {
274
+ this.__buildDynamicArcs(subSetIDs);
275
+ }
276
+ else if (subSetIDs || state === StaticDynamicState.TO_STATIC) {
277
+ this.__buildStaticArcs(subSetIDs);
278
+ }
279
+ }
280
+ __buildStaticArcs(subSetIDs = null) {
281
+ const { globe, _arcMap, _cameraUniformBlock, bufferManagersMap, bufferOrchestrator } = this;
282
+ if (!globe || !_cameraUniformBlock || !bufferManagersMap || !bufferOrchestrator) {
283
+ console.warn("Globe or camera uniform block is not initialized.");
284
+ return;
285
+ }
286
+ const bufferKey = [this.globe.api_GetCurrentGeometry() === 0 ? "position3d" : "position2d"];
287
+ if (!this.bufferManagersMap?.has(bufferKey[0]))
288
+ return;
289
+ const longLat = [0, 0];
290
+ const longLatArr = new Float32Array(2 * this._options.vertexCount);
291
+ const data = [{
292
+ key: "staticArcs",
293
+ longLatArr: longLatArr,
294
+ height: null,
295
+ color: this._options.defaultColor,
296
+ msl: null
297
+ }];
298
+ let keys;
299
+ if (subSetIDs === null) {
300
+ keys = _arcMap.keys();
301
+ }
302
+ else {
303
+ keys = subSetIDs;
304
+ }
305
+ for (const key of keys) {
306
+ const [arcInstance, arcInput] = _arcMap.get(key);
307
+ arc.copy(_0arc, arcInstance);
308
+ const generatedPoints = evenlySpacedArcPoints(_0arc.p0, _0arc.normal, _0arc.coverAngle, this._options.vertexCount);
309
+ for (let i = 0; i < generatedPoints.length; i++) {
310
+ const point = generatedPoints[i];
311
+ vec3.fromUnitVectorToLongLat(longLat, point);
312
+ longLatArr.set([longLat[0] / RADIAN, longLat[1] / RADIAN], i * 2);
313
+ }
314
+ data[0].key = key;
315
+ data[0].height = arcInput.height ?? this._options.defaultHeightFromGroundIn3D;
316
+ data[0].color = arcInput.color ?? this._options.defaultColor;
317
+ data[0].msl = arcInput.msl ?? null;
318
+ this.bufferOrchestrator.insertBulk(data, bufferManagersMap, bufferKey);
319
+ }
320
+ }
321
+ __buildDynamicArcs(subSetIDs = null) {
322
+ const { globe, _arcMap, _cameraUniformBlock, bufferManagersMap } = this;
323
+ if (!globe || !_cameraUniformBlock || !bufferManagersMap) {
324
+ console.warn("Globe or camera uniform block is not initialized.");
325
+ return;
326
+ }
327
+ const bufferKey = [
328
+ this.globe.api_GetCurrentGeometry() === 0 ? "position3d" : "position2d"
329
+ ];
330
+ if (!this.bufferManagersMap?.has(bufferKey[0]))
331
+ return;
332
+ const { cameraAttractionIsOn } = this._options;
333
+ const lookAtPosition = _cameraUniformBlock.getLookAtVector();
334
+ const cameraPosition = _cameraUniformBlock.getCameraVector();
335
+ vec3.divideScalar(cameraPosition, cameraPosition, WORLD_RADIUS_3D);
336
+ vec3.add(cameraPosition, cameraPosition, lookAtPosition);
337
+ // vec3.normalize(cameraPosition, cameraPosition);
338
+ vec3.divideScalar(cameraPosition, cameraPosition, 2);
339
+ // vec3.multiplyScalar(cameraPosition, cameraPosition, 1.3);
340
+ const _attractionStrength = (() => {
341
+ const lod = globe.api_GetCurrentLODWithDecimal();
342
+ if (lod < 11) {
343
+ return 1;
344
+ }
345
+ return lod * (lod - 8.5);
346
+ })();
347
+ const result = [];
348
+ const longLat = [0, 0];
349
+ let keys;
350
+ if (subSetIDs === null) {
351
+ keys = _arcMap.keys();
352
+ }
353
+ else {
354
+ keys = subSetIDs;
355
+ }
356
+ for (const key of keys) {
357
+ const [arcInstance, arcInput] = _arcMap.get(key);
358
+ arc.copy(_0arc, arcInstance);
359
+ const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPosition);
360
+ if (!isOnArc) {
361
+ if (vec3.distanceSquared(cameraPosition, _0arc.p0) < vec3.distanceSquared(cameraPosition, _0arc.p1)) {
362
+ vec3.copy(_attractionPoint, _0arc.p0);
363
+ }
364
+ else {
365
+ vec3.copy(_attractionPoint, _0arc.p1);
366
+ }
367
+ }
368
+ const generatedPoints = cameraAttractionIsOn ?
369
+ generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, this._options.vertexCount, _attractionStrength)
370
+ : evenlySpacedArcPoints(_0arc.p0, _0arc.normal, _0arc.coverAngle, this._options.vertexCount);
371
+ const longLatArr = new Float32Array(2 * this._options.vertexCount);
372
+ for (let i = 0; i < generatedPoints.length; i++) {
373
+ const point = generatedPoints[i];
374
+ vec3.fromUnitVectorToLongLat(longLat, point);
375
+ longLatArr.set([longLat[0] / RADIAN, longLat[1] / RADIAN], i * 2);
376
+ }
377
+ result.push({
378
+ key: key,
379
+ longLatArr: longLatArr,
380
+ height: arcInput.height ?? this._options.defaultHeightFromGroundIn3D,
381
+ msl: arcInput.msl ?? null
382
+ });
383
+ }
384
+ // this.bufferOrchestrator.resetWithCapacity(bufferManagersMap, result.length);
385
+ this.bufferOrchestrator.insertBulk(result, bufferManagersMap, bufferKey);
386
+ }
387
+ _fillbufferManagersMap() {
388
+ const { gl, globe } = this;
389
+ if (!gl || !globe) {
390
+ console.warn("WebGL context or globe is not initialized.");
391
+ return;
392
+ }
393
+ const g2D = globe2Dcoordinates(globe);
394
+ const { flatViewOn, globeViewOn, variativeColorsOn } = this._options;
395
+ this.bufferManagersMap = new Map();
396
+ if (globeViewOn) {
397
+ this.bufferManagersMap.set("position3d", {
398
+ bufferManager: new BufferManager(gl, 3 * (this._options.vertexCount + 1), { bufferType: "STREAM_DRAW", initialCapacity: INITAL_CAPACITY }),
399
+ adaptor: (item) => {
400
+ const { longLatArr, height = this._options.defaultHeightFromGroundIn3D, msl = this._options.isMSL } = item;
401
+ const result = globe3Dcoordinates(globe, longLatArr, height, msl, { paddingCount: 1 });
402
+ return result;
403
+ }
404
+ });
405
+ }
406
+ if (flatViewOn) {
407
+ this.bufferManagersMap.set("position2d", {
408
+ bufferManager: new BufferManager(gl, 2 * (this._options.vertexCount + 1), { bufferType: "STREAM_DRAW", initialCapacity: INITAL_CAPACITY }),
409
+ adaptor: (item) => {
410
+ const { longLatArr } = item;
411
+ return g2D(longLatArr, { paddingCount: 1 });
412
+ }
413
+ });
414
+ }
415
+ if (this._options.variativeColorsOn) {
416
+ const _colorArray = new Float32Array(4 * (this._options.vertexCount + 1)); // TODO: this could cause data races or unexpected overwrites.
417
+ this.bufferManagersMap.set("color", {
418
+ bufferManager: new BufferManager(gl, 4 * (this._options.vertexCount + 1), { bufferType: "STREAM_DRAW", initialCapacity: INITAL_CAPACITY }),
419
+ adaptor: (item) => {
420
+ // Calculate color based on radius
421
+ if (item.color) {
422
+ for (let i = 0; i < this._options.vertexCount; i++) {
423
+ _colorArray.set(item.color, 4 * i); // Fill color for each vertex
424
+ }
425
+ return _colorArray;
426
+ }
427
+ else {
428
+ return _colorArray.fill(-1, 0, 4 * (this._options.vertexCount)); // Fill with -1 if no color is provided
429
+ }
430
+ }
431
+ });
432
+ }
433
+ const bufferObjects = [
434
+ globeViewOn ? "position3d" : null,
435
+ flatViewOn ? "position2d" : null,
436
+ variativeColorsOn ? "color" : null
437
+ ].map((key) => {
438
+ if (!key)
439
+ return null;
440
+ this._coordinaateBufferKeysForUpdate.push(key);
441
+ // @ts-ignore
442
+ const bufferManager = this.bufferManagersMap.get(key).bufferManager;
443
+ // @ts-ignore
444
+ return createBufferAndReadInfo(bufferManager.buffer);
445
+ });
446
+ // @ts-ignore
447
+ this._vao = this.program.createVAO(bufferObjects[0], // position3d
448
+ bufferObjects[1], // position2d
449
+ bufferObjects[2] // color
450
+ );
451
+ }
452
+ __fillColors(subSetIDs) {
453
+ if (this._options.variativeColorsOn === false)
454
+ return;
455
+ const data = [null];
456
+ for (const id of subSetIDs) {
457
+ data[0] = this._arcMap.get(id)[1];
458
+ this.bufferOrchestrator.insertBulk(data, this.bufferManagersMap, ["color"]);
459
+ }
460
+ }
461
+ free() {
462
+ if (this._freed) {
463
+ console.warn("Plugin already freed");
464
+ return;
465
+ }
466
+ if (!this.gl || !this.program) {
467
+ console.warn("WebGL context or program is not initialized.");
468
+ return;
469
+ }
470
+ this._arcUBOHandler?.free();
471
+ this.bufferManagersMap?.forEach((manager) => {
472
+ manager.bufferManager.free();
473
+ });
474
+ CameraUniformBlockTotemCache.release(this.globe);
475
+ LineStripProgramCache.release(this.globe);
476
+ this.gl = null;
477
+ this.globe = null;
478
+ this._arcMap.clear();
479
+ this._coordinaateBufferKeysForUpdate = [];
480
+ }
481
+ }