@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,60 +1,39 @@
1
- /**
2
- * Author: Toprak Nihat Deniz Ozturk
3
- */
4
-
5
-
6
-
7
- import {
8
- createImageFromBase64,
9
- createProgramWrapper,
10
- createTexture,
11
- createBuffer,
12
- bindAttribute,
13
- bindFramebuffer,
14
- bindTexture,
15
- getColorRamp
16
- } from "../../util/webglobjectbuilders";
17
- import { defaultblendfunction } from "../../util/globe-default-gl-states";
18
-
19
- import imageToMagnitude, { imageToRadianAngle } from "./imagetovectorfieldandmagnitude";
20
- import { TexturePointSampler } from "../../heatwave/texture-point-sampler";
21
- /**
22
- * Shader Dökümanı:
23
- * * Vektör alan haritasında kaçış değeri
24
- * texture2D(u_wind, pos).rg == vec2(0.0, 0.0) değerini kaçış için kullandım.
25
- * Deniz rüzgarları gibi haritalarda kara için rg değerleri 0.0 oluyor.
26
- * Gerçek bir partikülün rg == vec2(0.0, 0.0) değerinde olma olasılığı düşük.
27
- * Hem yatay ve hem dikey boyutta en düşük değere sahip olmalı.
28
- *
29
-
30
- *
31
- */
32
-
33
-
34
- /**
35
- * @typedef {Object} WindData for setWindDataWithImageBase64
36
- * @property {string} image - base64 encoded image
37
- * @property {number} width - image width
38
- * @property {number} height - image height
39
- * @property {number} uMin - minimum u value
40
- * @property {number} vMin - minimum v value
41
- * @property {number} uMax - maximum u value
42
- * @property {number} vMax - maximum v value
43
- * @property {Array} bbox - bounding box [minLon, minLat, maxLon, maxLat]
44
- * @property {LegendData} legendData - legend data
45
-
46
- */
47
-
48
-
49
- /**
50
- * @typedef {Object} LegendData
51
- * @property {Array} thresholds - list of integers
52
- * @property {Array} values - list of colors
53
- */
54
-
55
-
56
-
57
-
1
+ /**
2
+ * Author: Toprak Nihat Deniz Ozturk
3
+ */
4
+ import { createImageFromBase64, createProgramWrapper, createTexture, createBuffer, bindAttribute, bindFramebuffer, bindTexture, getColorRamp } from "../../util/webglobjectbuilders";
5
+ import { defaultblendfunction } from "../../util/globe-default-gl-states";
6
+ import imageToMagnitude, { imageToRadianAngle } from "./imagetovectorfieldandmagnitude";
7
+ import { TexturePointSampler } from "../../heatwave/texture-point-sampler";
8
+ /**
9
+ * Shader Dökümanı:
10
+ * * Vektör alan haritasında kaçış değeri
11
+ * texture2D(u_wind, pos).rg == vec2(0.0, 0.0) değerini kaçış için kullandım.
12
+ * Deniz rüzgarları gibi haritalarda kara için rg değerleri 0.0 oluyor.
13
+ * Gerçek bir partikülün rg == vec2(0.0, 0.0) değerinde olma olasılığı düşük.
14
+ * Hem yatay ve hem dikey boyutta en düşük değere sahip olmalı.
15
+ *
16
+
17
+ *
18
+ */
19
+ /**
20
+ * @typedef {Object} WindData for setWindDataWithImageBase64
21
+ * @property {string} image - base64 encoded image
22
+ * @property {number} width - image width
23
+ * @property {number} height - image height
24
+ * @property {number} uMin - minimum u value
25
+ * @property {number} vMin - minimum v value
26
+ * @property {number} uMax - maximum u value
27
+ * @property {number} vMax - maximum v value
28
+ * @property {Array} bbox - bounding box [minLon, minLat, maxLon, maxLat]
29
+ * @property {LegendData} legendData - legend data
30
+
31
+ */
32
+ /**
33
+ * @typedef {Object} LegendData
34
+ * @property {Array} thresholds - list of integers
35
+ * @property {Array} values - list of colors
36
+ */
58
37
  const quadVert = `
59
38
  precision mediump float;
60
39
 
@@ -65,8 +44,7 @@ varying vec2 v_tex_pos;
65
44
  void main() {
66
45
  v_tex_pos = a_pos;
67
46
  gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);
68
- }`;
69
-
47
+ }`;
70
48
  const screenFrag = `precision mediump float;
71
49
 
72
50
  uniform sampler2D u_screen;
@@ -83,8 +61,7 @@ void main() {
83
61
  gl_FragColor = vec4( floor(255.0 * color * u_opacity) / 255.0);
84
62
  }
85
63
 
86
- `;
87
-
64
+ `;
88
65
  const updateFrag = `
89
66
  precision highp float;
90
67
 
@@ -157,9 +134,7 @@ void main() {
157
134
  fract(pos * 255.0),
158
135
  floor(pos * 255.0) / 255.0);
159
136
  }
160
- `;
161
-
162
-
137
+ `;
163
138
  const drawFrag = `precision mediump float;
164
139
 
165
140
  uniform sampler2D u_wind;
@@ -202,9 +177,7 @@ void main() {
202
177
 
203
178
  gl_FragColor = texture2D(u_color_ramp, ramp_pos) * u_base_opacity;
204
179
  }
205
- `;
206
-
207
-
180
+ `;
208
181
  const drawSphereVert = `
209
182
  precision mediump float;
210
183
 
@@ -266,8 +239,7 @@ void main() {
266
239
  gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(pos - uTranslate, 1.0);
267
240
  gl_PointSize = u_point_size;
268
241
 
269
- }`;
270
-
242
+ }`;
271
243
  const drawFlatVert = `
272
244
  precision mediump float;
273
245
 
@@ -317,817 +289,647 @@ void main() {
317
289
  gl_Position = uProjectionMatrix * vec4(normalizedX * u_scrWH.x, (1.0 - normalizedY) * u_scrWH.y, 0.0, 1.0);
318
290
 
319
291
  gl_PointSize = u_point_size;
320
- }`;
321
-
322
-
323
-
324
- const defaultRampColors = [
325
- [0.0, '#5e4fa2'],
326
- [0.08, '#3288bd'],
327
- [0.2, '#66c2a5'],
328
- [0.3, '#abdda4'],
329
- [0.4, '#e6f598'],
330
- [0.5, '#fee08b'],
331
- [0.6, '#fdae61'],
332
- [0.7, '#f46d43'],
333
- [1.0, '#d53e4f']
334
-
335
- ];
336
-
337
-
338
- const windyLegendData = {
339
- "thresholds": [0, 3, 3, 5, 5, 7, 10, 10, 13, 15, 15, 17, 20, 20, 25, 25, 30],
340
- // 0 5 10 20 30 40 60
341
- // "thresholds": [0, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 40, 60],
342
- "values": [
343
- "#6271B8",
344
- "#6271B8",
345
- "#6271B8",
346
- "#6271B8",
347
- "#3D6EA3",
348
- "#4A94AA",
349
- "#4A9294",
350
- "#4D8E7C",
351
- "#4CA44C",
352
- "#67A436",
353
- "#A28740",
354
- "#A26D5C",
355
- "#8D3F5C",
356
- "#974B91",
357
- "#5F64A0",
358
- "#5B88A1",
359
- "#5B88A1"
360
- ]
361
- };
362
-
363
-
364
- export default class WindPlugin {
365
-
366
- /**
367
- * @param {String} id
368
- * @param {Object} windDataMeta
369
- * @param {number} windDataMeta.width - image width
370
- * @param {number} windDataMeta.height - image height
371
- * @param {Array} windDataMeta.bbox - bounding box [minLon, minLat, maxLon, maxLat]
372
- * @param {Object} options
373
- * @param {number} options.fadeOpacity - how fast the particle trails fade on each frame | between 0 - 1 | default 0.746
374
- * @param {number} options.speedFactor - how fast the particles move | between 0 - 1 | default 0.6
375
- * @param {number} options.dropRate - how often the particles move to a random place | between 0 - 1 | default 0.007
376
- * @param {number} options.dropRateBump - drop rate increase relative to individual particle speed
377
- * @param {number} options.baseOpacity - opacity of drawn particle trails | between 0 - 1 | default 1.0
378
- * @param {number} options.pointSize - draw size of each particle | positive number | default 2.0
379
- * @param {number} options.minSpeed - minimum speed value | positive number | default 0.0
380
- * @param {number} options.maxSpeed - maximum speed value | positive number | default 1000.0
381
- * @param {number} options.height - height of the particles | number | default 0.0
382
- * @param {number} numParticles - number of particles | positive integer
383
- * @param {LegendData} options.legendData - legend data
384
- */
385
- constructor(id,
386
- windDataMeta,
387
- {
388
- fadeOpacity = 0.746,
389
- speedFactor = 0.6,
390
- dropRate = 0.007,
391
- dropRateBump = 0.001,
392
- baseOpacity = 1.0,
393
- pointSize = 2.0,
394
- minSpeed = 0.0,
395
- maxSpeed = 1000.0,
396
- height = 0.0,
397
- numParticles = 40000,
398
- legendData = windyLegendData
399
- } = {}) {
400
-
401
- this.id = id;
402
- this._windDataMeta = windDataMeta;
403
- this.globe = null;
404
- this.gl = null;
405
-
406
-
407
- this._screenMoved = false;
408
- this.projMatrix = null;
409
- this.modelviewMatrix = null;
410
- this.transPos = new Float32Array([0, 0, 0]);
411
- this.windData = null;
412
-
413
- this._fadeOpacity = fadeOpacity;
414
- this._speedFactor = speedFactor;
415
- this._dropRate = dropRate;
416
- this._dropRateBump = dropRateBump;
417
- this._baseOpacity = baseOpacity;
418
- this._pointSize = pointSize;
419
- this._minSpeed = minSpeed;
420
- this._maxSpeed = maxSpeed;
421
- this._height = height;
422
- this._numParticles = numParticles;
423
- this._legendData = legendData;
424
-
425
- this.lastdatas = [[], [], { x: 0, y: 0, z: 0 }];
426
-
427
- this._drawParticles = this._drawParticlesSphere
428
-
429
- this._lastLOD = 0;
430
- }
431
-
432
- // Uniforms are loaded once, on initiation and when they are changed.
433
-
434
- set height(value) {
435
- this._height = value;
436
- this._loadHeight();
437
- }
438
-
439
-
440
- set minSpeed(value) {
441
- this._minSpeed = value;
442
- this._loadMinMaxSpeed();
443
- }
444
-
445
-
446
- set maxSpeed(value) {
447
- this._maxSpeed = value;
448
- this._loadMinMaxSpeed();
449
- }
450
-
451
-
452
- set fadeOpacity(value) {
453
- this._fadeOpacity = value;
454
- this._loadFadeOpacity();
455
- }
456
-
457
-
458
- set speedFactor(value) {
459
- this._speedFactor = value;
460
- this._loadSpeedFactor()
461
- }
462
-
463
-
464
- set dropRate(value) {
465
- this._dropRate = value;
466
- this._loadDropRate();
467
- }
468
-
469
-
470
- set dropRateBump(value) {
471
- this._dropRateBump = value;
472
- this._loadDropRateBump();
473
- }
474
-
475
-
476
- set baseOpacity(value) {
477
- this._baseOpacity = value;
478
- this._loadBaseOpacity();
479
- }
480
-
481
-
482
- set pointSize(value) {
483
- this._pointSize = value;
484
- this._loadPointSize();
485
- }
486
-
487
-
488
-
489
-
490
- // Color ramp methods.
491
- // Color ramp is used to colorize the particles according to their speed.
492
- // Legend max value is used to normalize the speed values.
493
-
494
- setColorRamp(colors) {
495
- // lookup texture for colorizing the particles according to their speed
496
- if (this.gl == null) {
497
- return;
498
- }
499
- this.colorRampTexture = createTexture(this.gl, this.gl.LINEAR, getColorRamp(colors), 16, 16);
500
- }
501
-
502
- setColorRampDefault() {
503
- const { uMax, uMin, vMax, vMin } = this.windData;
504
- const maxSpeed = Math.sqrt(
505
- uMax * uMax + vMax * vMax
506
- )
507
- const minSpeed = Math.sqrt(
508
- uMin * uMin + vMin * vMin
509
- )
510
- // console.log("maxSpeed", maxSpeed, "minSpeed", minSpeed);
511
- this._rampMax = maxSpeed > minSpeed ? maxSpeed : minSpeed;
512
- this._loadRampMax();
513
- this.setColorRamp(defaultRampColors);
514
-
515
- }
516
-
517
- /**
518
- *
519
- * @param {*} legendData
520
- * @param {Array} legendData.thresholds - list of integers
521
- * @param {Array} legendData.values - list of colors in hex format like #ff0000 (alpha is not included)
522
- *
523
- */
524
- setLegend(legendData) {
525
- const { gl } = this;
526
- if (gl === null) {
527
- throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
528
- }
529
- const { thresholds, values } = legendData;
530
- if (thresholds.length === 0 || values.length === 0) {
531
- return;
532
- }
533
- thresholds.push(thresholds[thresholds.length - 1]);
534
- values.push(values[values.length - 1]);
535
-
536
- const maxVelocity = thresholds[thresholds.length - 1];
537
-
538
- const colors = [];
539
- for (let i = 0; i < thresholds.length; i++) {
540
- colors.push([
541
- thresholds[i] / maxVelocity,
542
- values[i]
543
- ]);
544
- }
545
- const colorRamp = getColorRamp(colors);
546
- this.colorRampTexture = createTexture(gl, gl.LINEAR, colorRamp, 16, 16);
547
- this._rampMax = maxVelocity;
548
- this._loadRampMax();
549
- }
550
-
551
-
552
-
553
-
554
- // particle coordinates are encoded into RGBA texture
555
-
556
- set numParticles(numParticles) {
557
- const gl = this.gl;
558
- // we create a square texture where each pixel will hold a particle position encoded as RGBA
559
- const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(numParticles));
560
- this._numParticles = particleRes * particleRes;
561
-
562
- const particleState = new Uint8Array(this._numParticles * 4);
563
- for (let i = 0; i < particleState.length; i++) {
564
- particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
565
- }
566
- // textures to hold the particle state for the current and the next frame
567
- this.particleStateTexture0 = createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
568
- this.particleStateTexture1 = createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
569
-
570
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
571
- gl.useProgram(this.updateProgram.program);
572
- gl.uniform1f(this.updateProgram.u_wind_res, this.particleStateResolution);
573
- gl.useProgram(this.drawSphereProgram.program);
574
- gl.uniform1f(this.drawSphereProgram.u_particles_res, this.particleStateResolution);
575
- gl.useProgram(this.drawFlatProgram.program);
576
- gl.uniform1f(this.drawFlatProgram.u_particles_res, this.particleStateResolution);
577
- gl.useProgram(currentProgram);
578
-
579
- // console.log("numParticles", this._numParticles);
580
- const particleIndices = new Float32Array(this._numParticles);
581
- for (let i = 0; i < this._numParticles; i++) particleIndices[i] = i;
582
- this.particleIndexBuffer = createBuffer(gl, particleIndices);
583
- }
584
-
585
-
586
- get numParticles() {
587
- return this._numParticles;
588
- }
589
-
590
- // Vector field texture is used to calculate the particle movement.
591
- /**
592
- * @param {Object} windData
593
- * @param {HTMLImageElement} windData.image - image element
594
-
595
- * @param {number} windData.uMin - minimum u value
596
- * @param {number} windData.vMin - minimum v value
597
- * @param {number} windData.uMax - maximum u value
598
- * @param {number} windData.vMax - maximum v value
599
- */
600
- setWind(windData) {
601
- if (windData === null) {
602
- return;
603
- }
604
- const windDataMeta = this._windDataMeta;
605
- const gl = this.gl;
606
- this.windData = windData;
607
- this.windTexture = createTexture(gl, gl.LINEAR, windData.image);
608
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
609
- gl.useProgram(this.updateProgram.program);
610
-
611
- gl.uniform2f(this.updateProgram.u_wind_res, windDataMeta.width, windDataMeta.height);
612
- gl.uniform2f(this.updateProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
613
- gl.uniform2f(this.updateProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
614
- this.setGeometry();
615
- console.log("windData bbox", windData.bbox);
616
- const minXY = this._latLongToPixelXY(windDataMeta.bbox[1], windDataMeta.bbox[0]);
617
- const maxXY = this._latLongToPixelXY(windDataMeta.bbox[3], windDataMeta.bbox[2]);
618
- this._loadBoundingBoxData(minXY.x, minXY.y, maxXY.x, maxXY.y);
619
-
620
- gl.useProgram(currentProgram);
621
-
622
-
623
- this._setCoorcinatesDataCalculatorData();
624
- this.resize();
625
- }
626
-
627
- // Vector field texture is used to calculate the particle movement.
628
- /**
629
- * @param {Object} windData
630
- * @param {BaseInt64} windData.image - image element
631
- * @param {number} windData.width - image width
632
- * @param {number} windData.height - image height
633
- * @param {number} windData.uMin - minimum u value
634
- * @param {number} windData.vMin - minimum v value
635
- * @param {number} windData.uMax - maximum u value
636
- * @param {number} windData.vMax - maximum v value
637
- * @param {Array} windData.bbox - bounding box [minLon, minLat, maxLon, maxLat]
638
- */
639
- setWindDataWithImageBase64(windData) {
640
- const image = createImageFromBase64(windData.image)
641
- image.onload = () => {
642
- windData.image = image;
643
- this.setWind(windData);
644
- }
645
- }
646
-
647
- /**
648
- * @param
649
- * @returns
650
- */
651
- getTexturePointSampler(type = `magnitude`) {
652
- if (type === `magnitude`) {
653
- if (!this.texturePointSampler) {
654
- this._createTexturePointSampler();
655
- this._setCoorcinatesDataCalculatorData();
656
- }
657
- return this.texturePointSampler;
658
- } else if (type === `angle`) {
659
- if (!this.texturePointSamplerAngle) {
660
- this._createTexturePointSamplerAngle();
661
- this._setCoorcinatesDataCalculatorData();
662
-
663
- }
664
- return this.texturePointSamplerAngle;
665
- } else {
666
- throw new Error(`WindPlugin.getTexturePointSampler: type must be either 'magnitude' or 'angle'.`);
667
- }
668
-
669
- }
670
-
671
-
672
- _createTexturePointSamplerAngle() {
673
- const { bbox, width, height } = this._windDataMeta
674
- this.texturePointSamplerAngle = new TexturePointSampler(bbox, width, height);
675
- }
676
-
677
- _createTexturePointSampler() {
678
- const { bbox, width, height } = this._windDataMeta;
679
- this.texturePointSampler = new TexturePointSampler(bbox, width, height);
680
- }
681
-
682
-
683
- _setCoorcinatesDataCalculatorData() {
684
- if (!this.windData) {
685
- return;
686
- }
687
- if (this.texturePointSamplerAngle) {
688
- const angle = imageToRadianAngle(this.windData);
689
- this.texturePointSamplerAngle.updateTextureData(0, angle, angle);
690
- }
691
- if (this.texturePointSampler) {
692
- const magnitude = imageToMagnitude(this.windData);
693
- this.texturePointSampler.updateTextureData(0, magnitude, magnitude);
694
- }
695
- }
696
-
697
-
698
- // -----------------------------------------------
699
- // --- inner methods ---
700
- // -----------------------------------------------
701
-
702
- _latLongToPixelXY(latitude, longitude) {
703
- return {
704
- x: (longitude + 180) / 360,
705
- y: (90 - latitude) / 180
706
- };
707
- }
708
-
709
- _loadBoundingBoxData(minX, minY, maxX, maxY) {
710
- // console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY)
711
- const gl = this.gl;
712
-
713
- const bboxMatrix = new Float32Array([
714
- maxX - minX, 0, 0,
715
- 0, maxY - minY, 0,
716
- minX, minY, 1
717
- ])
718
-
719
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
720
- gl.useProgram(this.drawSphereProgram.program);
721
- gl.uniformMatrix3fv(this.drawSphereProgram.u_bbox_matrix, false, bboxMatrix);
722
- gl.useProgram(this.drawFlatProgram.program);
723
- gl.uniformMatrix3fv(this.drawFlatProgram.u_bbox_matrix, false, bboxMatrix);
724
- gl.useProgram(currentProgram);
725
-
726
- }
727
-
728
- // When the screen is moved, the particles are reset to random positions.
729
- // During movement plugin should not draw the particles.
730
-
731
- _doDraw() {
732
- const globe = this.globe;
733
- if (this.windData === null) {
734
- return false;
735
- }
736
- if (globe.api_IsScreenMoving() || this._lastLOD !== globe.api_GetCurrentLODWithDecimal()) {
737
- if (!this._screenMoved) {
738
- this._screenMoved = true;
739
- }
740
- this._lastLOD = globe.api_GetCurrentLODWithDecimal();
741
- return false;
742
- } else {
743
- if (this._screenMoved) {
744
- this._loadSpeedFactor();
745
- this.resize();
746
- this._screenMoved = false;
747
- }
748
- return true;
749
- }
750
- }
751
-
752
-
753
- _draw() {
754
- const gl = this.gl;
755
- this._drawScreen();
756
- this._updateParticles();
757
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
758
- }
759
-
760
-
761
- // globe calls `draw3D` method on each frame
762
- draw3D(projMatrix, modelviewMatrix, transPos) {
763
- const gl = this.gl;
764
- if (this._doDraw()) {
765
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
766
- this.transPos.set([transPos.x, transPos.y, transPos.z], 0);
767
- this.projMatrix = projMatrix;
768
- this.modelviewMatrix = modelviewMatrix;
769
-
770
- gl.activeTexture(gl.TEXTURE0);
771
- const depthTest = gl.isEnabled(gl.DEPTH_TEST);
772
- if (depthTest) gl.disable(gl.DEPTH_TEST);
773
- // if (gl.disable(gl.STENCIL_TEST); //
774
- this._draw();
775
- if (depthTest) gl.enable(gl.DEPTH_TEST);
776
-
777
-
778
- // test visuals
779
- // gl.viewport(0, 0, 100, 100);
780
- // this._drawTexture(this.windTexture, 1.0);
781
- // gl.viewport(0, 100, 100, 100);
782
- // this._drawTexture(this.particleStateTexture0, 1.0);
783
- // gl.viewport(0, 200, 100, 100);
784
- // this._drawTexture(this.colorRampTexture, 1.0);
785
-
786
- this._resetMachineStates();
787
- this.globe.DrawRender();
788
- }
789
-
790
- }
791
-
792
- _drawScreen() {
793
- const { gl, globe } = this;
794
-
795
- bindTexture(gl, this.windTexture, 0);
796
- bindTexture(gl, this.particleStateTexture0, 1);
797
-
798
- // draw the screen into a temporary framebuffer to retain it as the background on the next frame
799
- bindFramebuffer(gl, this.framebuffer, this.screenTexture);
800
- gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
801
- gl.enable(gl.BLEND);
802
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); // non-premultiplied alpha
803
- this._drawTexture(this.backgroundTexture, this._fadeOpacity);
804
-
805
- this._drawParticles();
806
-
807
- bindFramebuffer(gl, null);
808
- this._drawTexture(this.screenTexture, 1.0);
809
- // gl.disable(gl.BLEND);
810
- // save the current screen as the background for the next frame
811
- const temp = this.backgroundTexture;
812
- this.backgroundTexture = this.screenTexture;
813
- this.screenTexture = temp;
814
-
815
-
816
-
817
- }
818
-
819
-
820
- _drawTexture(texture, opacity) {
821
- const gl = this.gl;
822
- const program = this.screenProgram;
823
- gl.useProgram(program.program);
824
-
825
- bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
826
- bindTexture(gl, texture, 2);
827
- gl.uniform1i(program.u_screen, 2);
828
- gl.uniform1f(program.u_opacity, opacity);
829
-
830
- gl.drawArrays(gl.TRIANGLES, 0, 6);
831
-
832
-
833
- gl.bindTexture(gl.TEXTURE_2D, null);
834
- gl.activeTexture(gl.TEXTURE0);
835
-
836
- }
837
-
838
- _loadRampMax() {
839
- const { gl } = this;
840
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
841
- // console.log("load ramp max", this._rampMax);
842
- gl.useProgram(this.drawSphereProgram.program);
843
- gl.uniform1f(this.drawSphereProgram.u_color_ramp_max, this._rampMax);
844
- gl.useProgram(this.drawFlatProgram.program);
845
- gl.uniform1f(this.drawFlatProgram.u_color_ramp_max, this._rampMax);
846
- gl.useProgram(currentProgram);
847
- }
848
-
849
-
850
- _drawParticlesSphere() {
851
-
852
- const { gl, projMatrix, modelviewMatrix, transPos } = this;
853
- const program = this.drawSphereProgram;
854
- gl.useProgram(program.program);
855
-
856
- bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
857
- bindTexture(gl, this.colorRampTexture, 2);
858
-
859
- gl.uniform1i(program.u_wind, 0);
860
- gl.uniform1i(program.u_particles, 1);
861
- gl.uniform1i(program.u_color_ramp, 2);
862
-
863
- gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
864
- gl.uniformMatrix4fv(program.uModelViewMatrix, false, modelviewMatrix);
865
- gl.uniform3fv(program.uTranslate, transPos);
866
-
867
- gl.drawArrays(gl.POINTS, 0, this._numParticles);
868
- }
869
-
870
-
871
- _drawParticlesFlat() {
872
- const { gl, transPos, projMatrix, globe } = this;
873
- const program = this.drawFlatProgram;
874
- gl.useProgram(program.program);
875
-
876
- bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
877
- bindTexture(gl, this.colorRampTexture, 2);
878
-
879
- gl.uniform1i(program.u_wind, 0);
880
- gl.uniform1i(program.u_particles, 1);
881
- gl.uniform1i(program.u_color_ramp, 2);
882
-
883
- gl.uniform2f(program.u_scrWH, globe.api_ScrW(), globe.api_ScrH());
884
- const { width, height } = globe.api_GetCurrentWorldWH();
885
- gl.uniform2f(program.u_mapWH, width, height);
886
-
887
- gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
888
- gl.uniform3fv(program.uTranslate, transPos);
889
-
890
- gl.drawArrays(gl.POINTS, 0, this._numParticles);
891
- }
892
-
893
- // globe calls `setGeometry` method on map projection change. FLAT or SPHERE
894
-
895
- setGeometry() {
896
- if (this.windData === null) {
897
- return;
898
- }
899
- const { globe, gl } = this;
900
- const geometry = globe.api_GetCurrentGeometry()
901
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
902
- if (geometry === globe.api_GeometryTypes().SPHERE) {
903
- this._drawParticles = this._drawParticlesSphere;
904
- gl.useProgram(this.drawSphereProgram.program);
905
- gl.uniform2f(this.drawSphereProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
906
- gl.uniform2f(this.drawSphereProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
907
- } else if (geometry === globe.api_GeometryTypes().FLAT) {
908
- this._drawParticles = this._drawParticlesFlat;
909
- gl.useProgram(this.drawFlatProgram.program);
910
- gl.uniform2f(this.drawFlatProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
911
- gl.uniform2f(this.drawFlatProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
912
- } else {
913
- alert("Geometry is not supported");
914
- }
915
- gl.useProgram(currentProgram);
916
- this.resize();
917
- }
918
-
919
- _updateParticles() {
920
- const gl = this.gl;
921
- const program = this.updateProgram;
922
- gl.disable(gl.BLEND);
923
-
924
- gl.useProgram(program.program);
925
- gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
926
-
927
- bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
928
-
929
- gl.uniform1i(program.u_wind, 0);
930
- gl.uniform1i(program.u_particles, 1);
931
-
932
- bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
933
-
934
- gl.uniform1f(program.u_rand_seed, Math.random());
935
-
936
- bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
937
-
938
- gl.drawArrays(gl.TRIANGLES, 0, 6);
939
-
940
- // swap the particle state textures so the new one becomes the current one
941
- const temp = this.particleStateTexture0;
942
- this.particleStateTexture0 = this.particleStateTexture1;
943
- this.particleStateTexture1 = temp;
944
-
945
- // Add this line to restore the viewport
946
-
947
- gl.viewport(0, 0, this.globe.api_ScrW(), this.globe.api_ScrH());
948
- }
949
-
950
-
951
-
952
- _resetMachineStates() {
953
- const { gl, globe } = this;
954
-
955
- // Unbind all textures
956
- for (let i = 0; i < 3; i++) {
957
- gl.activeTexture(gl.TEXTURE0 + i);
958
- gl.bindTexture(gl.TEXTURE_2D, null);
959
- }
960
- gl.activeTexture(gl.TEXTURE0);
961
-
962
- // Unbind buffers
963
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
964
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
965
- gl.bindVertexArray(null); // Add this line
966
- gl.enable(gl.BLEND);
967
- defaultblendfunction(gl);
968
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
969
- gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
970
- }
971
-
972
-
973
- _loadHeight() {
974
- const { gl, drawSphereProgram } = this;
975
- if (gl == null) return;
976
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
977
- gl.useProgram(drawSphereProgram.program);
978
- gl.uniform1f(drawSphereProgram.u_height, this._height);
979
- gl.useProgram(currentProgram);
980
- }
981
-
982
-
983
- _loadMinMaxSpeed() {
984
- const { gl, drawSphereProgram, drawFlatProgram } = this;
985
- if (gl == null) return;
986
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
987
- gl.useProgram(drawSphereProgram.program);
988
- gl.uniform1f(drawSphereProgram.u_min_speed, this._minSpeed);
989
- gl.uniform1f(drawSphereProgram.u_max_speed, this._maxSpeed);
990
- gl.useProgram(drawFlatProgram.program);
991
- gl.uniform1f(drawFlatProgram.u_min_speed, this._minSpeed);
992
- gl.uniform1f(drawFlatProgram.u_max_speed, this._maxSpeed);
993
- gl.useProgram(currentProgram);
994
- }
995
-
996
- _loadFadeOpacity() {
997
- const { gl, screenProgram } = this;
998
- if (gl == null) {
999
- return;
1000
- }
1001
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
1002
- gl.useProgram(screenProgram.program);
1003
- gl.uniform1f(screenProgram.u_opacity, this._fadeOpacity);
1004
- gl.useProgram(currentProgram);
1005
-
1006
- }
1007
-
1008
- _loadSpeedFactor() {
1009
- const { gl, globe, updateProgram } = this;
1010
- if (gl == null) {
1011
- return;
1012
- }
1013
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
1014
- gl.useProgram(updateProgram.program);
1015
- gl.uniform1f(updateProgram.u_speed_factor, this._speedFactor / Math.ceil(Math.sqrt(globe.api_GetCurrentLOD())));
1016
- gl.useProgram(currentProgram);
1017
- }
1018
-
1019
- _loadDropRate() {
1020
- const { gl, updateProgram } = this;
1021
- if (gl == null) {
1022
- return;
1023
- }
1024
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
1025
- gl.useProgram(updateProgram.program);
1026
- gl.uniform1f(updateProgram.u_drop_rate, this._dropRate);
1027
- gl.useProgram(currentProgram);
1028
- }
1029
-
1030
- _loadDropRateBump() {
1031
- const { gl, updateProgram } = this;
1032
- if (gl == null) {
1033
- return;
1034
- }
1035
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
1036
- gl.useProgram(updateProgram.program);
1037
- gl.uniform1f(updateProgram.u_drop_rate_bump, this._dropRateBump);
1038
- gl.useProgram(currentProgram);
1039
- }
1040
-
1041
-
1042
- _loadBaseOpacity() {
1043
- const { gl, drawSphereProgram, drawFlatProgram } = this;
1044
- if (gl == null) {
1045
- return;
1046
- }
1047
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
1048
- gl.useProgram(drawSphereProgram.program);
1049
- gl.uniform1f(drawSphereProgram.u_base_opacity, this._baseOpacity);
1050
- gl.useProgram(drawFlatProgram.program);
1051
- gl.uniform1f(drawFlatProgram.u_base_opacity, this._baseOpacity);
1052
- gl.useProgram(currentProgram);
1053
- }
1054
-
1055
-
1056
- _loadPointSize() {
1057
- const { gl, drawSphereProgram, drawFlatProgram } = this;
1058
- if (gl == null) {
1059
- return;
1060
- }
1061
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
1062
- gl.useProgram(drawSphereProgram.program);
1063
- gl.uniform1f(drawSphereProgram.u_point_size, this._pointSize);
1064
- gl.useProgram(drawFlatProgram.program);
1065
- gl.uniform1f(drawFlatProgram.u_point_size, this._pointSize);
1066
- gl.useProgram(currentProgram);
1067
- }
1068
-
1069
-
1070
- // globe plugin init methodu
1071
- init(globe, gl) {
1072
- // console.log("init wind plugin")
1073
- this.globe = globe;
1074
- this.gl = gl;
1075
-
1076
- this.drawSphereProgram = createProgramWrapper(gl, drawSphereVert, drawFrag);
1077
- this.screenProgram = createProgramWrapper(gl, quadVert, screenFrag);
1078
- this.updateProgram = createProgramWrapper(gl, quadVert, updateFrag);
1079
-
1080
- this.drawFlatProgram = createProgramWrapper(gl, drawFlatVert, drawFrag);
1081
- this.quadBuffer = createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
1082
- this.framebuffer = gl.createFramebuffer();
1083
-
1084
- this._loadFadeOpacity();
1085
- this._loadSpeedFactor();
1086
- this._loadDropRate();
1087
- this._loadDropRateBump();
1088
- this._loadBaseOpacity();
1089
- this._loadPointSize();
1090
- this._loadMinMaxSpeed();
1091
- this._loadHeight();
1092
-
1093
-
1094
- if (this._legendData != null) {
1095
- this.setLegend(this._legendData);
1096
- }
1097
- this.numParticles = this._numParticles;
1098
- this.resize();
1099
- }
1100
-
1101
- resize(a, b) {
1102
- const { gl, globe } = this;
1103
-
1104
- const emptyPixels = new Uint8Array(globe.api_ScrW() * globe.api_ScrH() * 4);
1105
- // screen textures to hold the drawn screen for the previous and the current frame
1106
- this.backgroundTexture = createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
1107
- this.screenTexture = createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
1108
- gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
1109
-
1110
- }
1111
-
1112
-
1113
- // globe calls this `free` on plugin object unregistration
1114
-
1115
- free() {
1116
- const gl = this.gl;
1117
- gl.deleteBuffer(this.quadBuffer);
1118
- gl.deleteFramebuffer(this.framebuffer);
1119
- gl.deleteTexture(this.backgroundTexture);
1120
- gl.deleteTexture(this.screenTexture);
1121
- gl.deleteTexture(this.particleStateTexture0);
1122
- gl.deleteTexture(this.particleStateTexture1);
1123
- gl.deleteTexture(this.windTexture);
1124
- gl.deleteTexture(this.colorRampTexture);
1125
- gl.deleteProgram(this.drawSphereProgram.program);
1126
- gl.deleteProgram(this.screenProgram.program);
1127
- gl.deleteProgram(this.updateProgram.program);
1128
- gl.deleteProgram(this.drawFlatProgram.program);
1129
- gl.deleteBuffer(this.particleIndexBuffer);
1130
-
1131
- }
1132
- }
1133
-
292
+ }`;
293
+ const defaultRampColors = [
294
+ [0.0, '#5e4fa2'],
295
+ [0.08, '#3288bd'],
296
+ [0.2, '#66c2a5'],
297
+ [0.3, '#abdda4'],
298
+ [0.4, '#e6f598'],
299
+ [0.5, '#fee08b'],
300
+ [0.6, '#fdae61'],
301
+ [0.7, '#f46d43'],
302
+ [1.0, '#d53e4f']
303
+ ];
304
+ const windyLegendData = {
305
+ "thresholds": [0, 3, 3, 5, 5, 7, 10, 10, 13, 15, 15, 17, 20, 20, 25, 25, 30],
306
+ // 0 5 10 20 30 40 60
307
+ // "thresholds": [0, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 40, 60],
308
+ "values": [
309
+ "#6271B8",
310
+ "#6271B8",
311
+ "#6271B8",
312
+ "#6271B8",
313
+ "#3D6EA3",
314
+ "#4A94AA",
315
+ "#4A9294",
316
+ "#4D8E7C",
317
+ "#4CA44C",
318
+ "#67A436",
319
+ "#A28740",
320
+ "#A26D5C",
321
+ "#8D3F5C",
322
+ "#974B91",
323
+ "#5F64A0",
324
+ "#5B88A1",
325
+ "#5B88A1"
326
+ ]
327
+ };
328
+ export default class WindPlugin {
329
+ /**
330
+ * @param {String} id
331
+ * @param {Object} windDataMeta
332
+ * @param {number} windDataMeta.width - image width
333
+ * @param {number} windDataMeta.height - image height
334
+ * @param {Array} windDataMeta.bbox - bounding box [minLon, minLat, maxLon, maxLat]
335
+ * @param {Object} options
336
+ * @param {number} options.fadeOpacity - how fast the particle trails fade on each frame | between 0 - 1 | default 0.746
337
+ * @param {number} options.speedFactor - how fast the particles move | between 0 - 1 | default 0.6
338
+ * @param {number} options.dropRate - how often the particles move to a random place | between 0 - 1 | default 0.007
339
+ * @param {number} options.dropRateBump - drop rate increase relative to individual particle speed
340
+ * @param {number} options.baseOpacity - opacity of drawn particle trails | between 0 - 1 | default 1.0
341
+ * @param {number} options.pointSize - draw size of each particle | positive number | default 2.0
342
+ * @param {number} options.minSpeed - minimum speed value | positive number | default 0.0
343
+ * @param {number} options.maxSpeed - maximum speed value | positive number | default 1000.0
344
+ * @param {number} options.height - height of the particles | number | default 0.0
345
+ * @param {number} numParticles - number of particles | positive integer
346
+ * @param {LegendData} options.legendData - legend data
347
+ */
348
+ constructor(id, windDataMeta, { fadeOpacity = 0.746, speedFactor = 0.6, dropRate = 0.007, dropRateBump = 0.001, baseOpacity = 1.0, pointSize = 2.0, minSpeed = 0.0, maxSpeed = 1000.0, height = 0.0, numParticles = 40000, legendData = windyLegendData } = {}) {
349
+ this.id = id;
350
+ this._windDataMeta = windDataMeta;
351
+ this.globe = null;
352
+ this.gl = null;
353
+ this._screenMoved = false;
354
+ this.projMatrix = null;
355
+ this.modelviewMatrix = null;
356
+ this.transPos = new Float32Array([0, 0, 0]);
357
+ this.windData = null;
358
+ this._fadeOpacity = fadeOpacity;
359
+ this._speedFactor = speedFactor;
360
+ this._dropRate = dropRate;
361
+ this._dropRateBump = dropRateBump;
362
+ this._baseOpacity = baseOpacity;
363
+ this._pointSize = pointSize;
364
+ this._minSpeed = minSpeed;
365
+ this._maxSpeed = maxSpeed;
366
+ this._height = height;
367
+ this._numParticles = numParticles;
368
+ this._legendData = legendData;
369
+ this.lastdatas = [[], [], { x: 0, y: 0, z: 0 }];
370
+ this._drawParticles = this._drawParticlesSphere;
371
+ this._lastLOD = 0;
372
+ }
373
+ // Uniforms are loaded once, on initiation and when they are changed.
374
+ set height(value) {
375
+ this._height = value;
376
+ this._loadHeight();
377
+ }
378
+ set minSpeed(value) {
379
+ this._minSpeed = value;
380
+ this._loadMinMaxSpeed();
381
+ }
382
+ set maxSpeed(value) {
383
+ this._maxSpeed = value;
384
+ this._loadMinMaxSpeed();
385
+ }
386
+ set fadeOpacity(value) {
387
+ this._fadeOpacity = value;
388
+ this._loadFadeOpacity();
389
+ }
390
+ set speedFactor(value) {
391
+ this._speedFactor = value;
392
+ this._loadSpeedFactor();
393
+ }
394
+ set dropRate(value) {
395
+ this._dropRate = value;
396
+ this._loadDropRate();
397
+ }
398
+ set dropRateBump(value) {
399
+ this._dropRateBump = value;
400
+ this._loadDropRateBump();
401
+ }
402
+ set baseOpacity(value) {
403
+ this._baseOpacity = value;
404
+ this._loadBaseOpacity();
405
+ }
406
+ set pointSize(value) {
407
+ this._pointSize = value;
408
+ this._loadPointSize();
409
+ }
410
+ // Color ramp methods.
411
+ // Color ramp is used to colorize the particles according to their speed.
412
+ // Legend max value is used to normalize the speed values.
413
+ setColorRamp(colors) {
414
+ // lookup texture for colorizing the particles according to their speed
415
+ if (this.gl == null) {
416
+ return;
417
+ }
418
+ this.colorRampTexture = createTexture(this.gl, this.gl.LINEAR, getColorRamp(colors), 16, 16);
419
+ }
420
+ setColorRampDefault() {
421
+ const { uMax, uMin, vMax, vMin } = this.windData;
422
+ const maxSpeed = Math.sqrt(uMax * uMax + vMax * vMax);
423
+ const minSpeed = Math.sqrt(uMin * uMin + vMin * vMin);
424
+ // console.log("maxSpeed", maxSpeed, "minSpeed", minSpeed);
425
+ this._rampMax = maxSpeed > minSpeed ? maxSpeed : minSpeed;
426
+ this._loadRampMax();
427
+ this.setColorRamp(defaultRampColors);
428
+ }
429
+ /**
430
+ *
431
+ * @param {*} legendData
432
+ * @param {Array} legendData.thresholds - list of integers
433
+ * @param {Array} legendData.values - list of colors in hex format like #ff0000 (alpha is not included)
434
+ *
435
+ */
436
+ setLegend(legendData) {
437
+ const { gl } = this;
438
+ if (gl === null) {
439
+ throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
440
+ }
441
+ const { thresholds, values } = legendData;
442
+ if (thresholds.length === 0 || values.length === 0) {
443
+ return;
444
+ }
445
+ thresholds.push(thresholds[thresholds.length - 1]);
446
+ values.push(values[values.length - 1]);
447
+ const maxVelocity = thresholds[thresholds.length - 1];
448
+ const colors = [];
449
+ for (let i = 0; i < thresholds.length; i++) {
450
+ colors.push([
451
+ thresholds[i] / maxVelocity,
452
+ values[i]
453
+ ]);
454
+ }
455
+ const colorRamp = getColorRamp(colors);
456
+ this.colorRampTexture = createTexture(gl, gl.LINEAR, colorRamp, 16, 16);
457
+ this._rampMax = maxVelocity;
458
+ this._loadRampMax();
459
+ }
460
+ // particle coordinates are encoded into RGBA texture
461
+ set numParticles(numParticles) {
462
+ const gl = this.gl;
463
+ // we create a square texture where each pixel will hold a particle position encoded as RGBA
464
+ const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(numParticles));
465
+ this._numParticles = particleRes * particleRes;
466
+ const particleState = new Uint8Array(this._numParticles * 4);
467
+ for (let i = 0; i < particleState.length; i++) {
468
+ particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
469
+ }
470
+ // textures to hold the particle state for the current and the next frame
471
+ this.particleStateTexture0 = createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
472
+ this.particleStateTexture1 = createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
473
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
474
+ gl.useProgram(this.updateProgram.program);
475
+ gl.uniform1f(this.updateProgram.u_wind_res, this.particleStateResolution);
476
+ gl.useProgram(this.drawSphereProgram.program);
477
+ gl.uniform1f(this.drawSphereProgram.u_particles_res, this.particleStateResolution);
478
+ gl.useProgram(this.drawFlatProgram.program);
479
+ gl.uniform1f(this.drawFlatProgram.u_particles_res, this.particleStateResolution);
480
+ gl.useProgram(currentProgram);
481
+ // console.log("numParticles", this._numParticles);
482
+ const particleIndices = new Float32Array(this._numParticles);
483
+ for (let i = 0; i < this._numParticles; i++)
484
+ particleIndices[i] = i;
485
+ this.particleIndexBuffer = createBuffer(gl, particleIndices);
486
+ }
487
+ get numParticles() {
488
+ return this._numParticles;
489
+ }
490
+ // Vector field texture is used to calculate the particle movement.
491
+ /**
492
+ * @param {Object} windData
493
+ * @param {HTMLImageElement} windData.image - image element
494
+
495
+ * @param {number} windData.uMin - minimum u value
496
+ * @param {number} windData.vMin - minimum v value
497
+ * @param {number} windData.uMax - maximum u value
498
+ * @param {number} windData.vMax - maximum v value
499
+ */
500
+ setWind(windData) {
501
+ if (windData === null) {
502
+ return;
503
+ }
504
+ const windDataMeta = this._windDataMeta;
505
+ const gl = this.gl;
506
+ this.windData = windData;
507
+ this.windTexture = createTexture(gl, gl.LINEAR, windData.image);
508
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
509
+ gl.useProgram(this.updateProgram.program);
510
+ gl.uniform2f(this.updateProgram.u_wind_res, windDataMeta.width, windDataMeta.height);
511
+ gl.uniform2f(this.updateProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
512
+ gl.uniform2f(this.updateProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
513
+ this.setGeometry();
514
+ console.log("windData bbox", windData.bbox);
515
+ const minXY = this._latLongToPixelXY(windDataMeta.bbox[1], windDataMeta.bbox[0]);
516
+ const maxXY = this._latLongToPixelXY(windDataMeta.bbox[3], windDataMeta.bbox[2]);
517
+ this._loadBoundingBoxData(minXY.x, minXY.y, maxXY.x, maxXY.y);
518
+ gl.useProgram(currentProgram);
519
+ this._setCoorcinatesDataCalculatorData();
520
+ this.resize();
521
+ }
522
+ // Vector field texture is used to calculate the particle movement.
523
+ /**
524
+ * @param {Object} windData
525
+ * @param {BaseInt64} windData.image - image element
526
+ * @param {number} windData.width - image width
527
+ * @param {number} windData.height - image height
528
+ * @param {number} windData.uMin - minimum u value
529
+ * @param {number} windData.vMin - minimum v value
530
+ * @param {number} windData.uMax - maximum u value
531
+ * @param {number} windData.vMax - maximum v value
532
+ * @param {Array} windData.bbox - bounding box [minLon, minLat, maxLon, maxLat]
533
+ */
534
+ setWindDataWithImageBase64(windData) {
535
+ const image = createImageFromBase64(windData.image);
536
+ image.onload = () => {
537
+ windData.image = image;
538
+ this.setWind(windData);
539
+ };
540
+ }
541
+ /**
542
+ * @param
543
+ * @returns
544
+ */
545
+ getTexturePointSampler(type = `magnitude`) {
546
+ if (type === `magnitude`) {
547
+ if (!this.texturePointSampler) {
548
+ this._createTexturePointSampler();
549
+ this._setCoorcinatesDataCalculatorData();
550
+ }
551
+ return this.texturePointSampler;
552
+ }
553
+ else if (type === `angle`) {
554
+ if (!this.texturePointSamplerAngle) {
555
+ this._createTexturePointSamplerAngle();
556
+ this._setCoorcinatesDataCalculatorData();
557
+ }
558
+ return this.texturePointSamplerAngle;
559
+ }
560
+ else {
561
+ throw new Error(`WindPlugin.getTexturePointSampler: type must be either 'magnitude' or 'angle'.`);
562
+ }
563
+ }
564
+ _createTexturePointSamplerAngle() {
565
+ const { bbox, width, height } = this._windDataMeta;
566
+ this.texturePointSamplerAngle = new TexturePointSampler(bbox, width, height);
567
+ }
568
+ _createTexturePointSampler() {
569
+ const { bbox, width, height } = this._windDataMeta;
570
+ this.texturePointSampler = new TexturePointSampler(bbox, width, height);
571
+ }
572
+ _setCoorcinatesDataCalculatorData() {
573
+ if (!this.windData) {
574
+ return;
575
+ }
576
+ if (this.texturePointSamplerAngle) {
577
+ const angle = imageToRadianAngle(this.windData);
578
+ this.texturePointSamplerAngle.updateTextureData(0, angle, angle);
579
+ }
580
+ if (this.texturePointSampler) {
581
+ const magnitude = imageToMagnitude(this.windData);
582
+ this.texturePointSampler.updateTextureData(0, magnitude, magnitude);
583
+ }
584
+ }
585
+ // -----------------------------------------------
586
+ // --- inner methods ---
587
+ // -----------------------------------------------
588
+ _latLongToPixelXY(latitude, longitude) {
589
+ return {
590
+ x: (longitude + 180) / 360,
591
+ y: (90 - latitude) / 180
592
+ };
593
+ }
594
+ _loadBoundingBoxData(minX, minY, maxX, maxY) {
595
+ // console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY)
596
+ const gl = this.gl;
597
+ const bboxMatrix = new Float32Array([
598
+ maxX - minX, 0, 0,
599
+ 0, maxY - minY, 0,
600
+ minX, minY, 1
601
+ ]);
602
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
603
+ gl.useProgram(this.drawSphereProgram.program);
604
+ gl.uniformMatrix3fv(this.drawSphereProgram.u_bbox_matrix, false, bboxMatrix);
605
+ gl.useProgram(this.drawFlatProgram.program);
606
+ gl.uniformMatrix3fv(this.drawFlatProgram.u_bbox_matrix, false, bboxMatrix);
607
+ gl.useProgram(currentProgram);
608
+ }
609
+ // When the screen is moved, the particles are reset to random positions.
610
+ // During movement plugin should not draw the particles.
611
+ _doDraw() {
612
+ const globe = this.globe;
613
+ if (this.windData === null) {
614
+ return false;
615
+ }
616
+ if (globe.api_IsScreenMoving() || this._lastLOD !== globe.api_GetCurrentLODWithDecimal()) {
617
+ if (!this._screenMoved) {
618
+ this._screenMoved = true;
619
+ }
620
+ this._lastLOD = globe.api_GetCurrentLODWithDecimal();
621
+ return false;
622
+ }
623
+ else {
624
+ if (this._screenMoved) {
625
+ this._loadSpeedFactor();
626
+ this.resize();
627
+ this._screenMoved = false;
628
+ }
629
+ return true;
630
+ }
631
+ }
632
+ _draw() {
633
+ const gl = this.gl;
634
+ this._drawScreen();
635
+ this._updateParticles();
636
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
637
+ }
638
+ // globe calls `draw3D` method on each frame
639
+ draw3D(projMatrix, modelviewMatrix, transPos) {
640
+ const gl = this.gl;
641
+ if (this._doDraw()) {
642
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
643
+ this.transPos.set([transPos.x, transPos.y, transPos.z], 0);
644
+ this.projMatrix = projMatrix;
645
+ this.modelviewMatrix = modelviewMatrix;
646
+ gl.activeTexture(gl.TEXTURE0);
647
+ const depthTest = gl.isEnabled(gl.DEPTH_TEST);
648
+ if (depthTest)
649
+ gl.disable(gl.DEPTH_TEST);
650
+ // if (gl.disable(gl.STENCIL_TEST); //
651
+ this._draw();
652
+ if (depthTest)
653
+ gl.enable(gl.DEPTH_TEST);
654
+ // test visuals
655
+ // gl.viewport(0, 0, 100, 100);
656
+ // this._drawTexture(this.windTexture, 1.0);
657
+ // gl.viewport(0, 100, 100, 100);
658
+ // this._drawTexture(this.particleStateTexture0, 1.0);
659
+ // gl.viewport(0, 200, 100, 100);
660
+ // this._drawTexture(this.colorRampTexture, 1.0);
661
+ this._resetMachineStates();
662
+ this.globe.DrawRender();
663
+ }
664
+ }
665
+ _drawScreen() {
666
+ const { gl, globe } = this;
667
+ bindTexture(gl, this.windTexture, 0);
668
+ bindTexture(gl, this.particleStateTexture0, 1);
669
+ // draw the screen into a temporary framebuffer to retain it as the background on the next frame
670
+ bindFramebuffer(gl, this.framebuffer, this.screenTexture);
671
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
672
+ gl.enable(gl.BLEND);
673
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); // non-premultiplied alpha
674
+ this._drawTexture(this.backgroundTexture, this._fadeOpacity);
675
+ this._drawParticles();
676
+ bindFramebuffer(gl, null);
677
+ this._drawTexture(this.screenTexture, 1.0);
678
+ // gl.disable(gl.BLEND);
679
+ // save the current screen as the background for the next frame
680
+ const temp = this.backgroundTexture;
681
+ this.backgroundTexture = this.screenTexture;
682
+ this.screenTexture = temp;
683
+ }
684
+ _drawTexture(texture, opacity) {
685
+ const gl = this.gl;
686
+ const program = this.screenProgram;
687
+ gl.useProgram(program.program);
688
+ bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
689
+ bindTexture(gl, texture, 2);
690
+ gl.uniform1i(program.u_screen, 2);
691
+ gl.uniform1f(program.u_opacity, opacity);
692
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
693
+ gl.bindTexture(gl.TEXTURE_2D, null);
694
+ gl.activeTexture(gl.TEXTURE0);
695
+ }
696
+ _loadRampMax() {
697
+ const { gl } = this;
698
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
699
+ // console.log("load ramp max", this._rampMax);
700
+ gl.useProgram(this.drawSphereProgram.program);
701
+ gl.uniform1f(this.drawSphereProgram.u_color_ramp_max, this._rampMax);
702
+ gl.useProgram(this.drawFlatProgram.program);
703
+ gl.uniform1f(this.drawFlatProgram.u_color_ramp_max, this._rampMax);
704
+ gl.useProgram(currentProgram);
705
+ }
706
+ _drawParticlesSphere() {
707
+ const { gl, projMatrix, modelviewMatrix, transPos } = this;
708
+ const program = this.drawSphereProgram;
709
+ gl.useProgram(program.program);
710
+ bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
711
+ bindTexture(gl, this.colorRampTexture, 2);
712
+ gl.uniform1i(program.u_wind, 0);
713
+ gl.uniform1i(program.u_particles, 1);
714
+ gl.uniform1i(program.u_color_ramp, 2);
715
+ gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
716
+ gl.uniformMatrix4fv(program.uModelViewMatrix, false, modelviewMatrix);
717
+ gl.uniform3fv(program.uTranslate, transPos);
718
+ gl.drawArrays(gl.POINTS, 0, this._numParticles);
719
+ }
720
+ _drawParticlesFlat() {
721
+ const { gl, transPos, projMatrix, globe } = this;
722
+ const program = this.drawFlatProgram;
723
+ gl.useProgram(program.program);
724
+ bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
725
+ bindTexture(gl, this.colorRampTexture, 2);
726
+ gl.uniform1i(program.u_wind, 0);
727
+ gl.uniform1i(program.u_particles, 1);
728
+ gl.uniform1i(program.u_color_ramp, 2);
729
+ gl.uniform2f(program.u_scrWH, globe.api_ScrW(), globe.api_ScrH());
730
+ const { width, height } = globe.api_GetCurrentWorldWH();
731
+ gl.uniform2f(program.u_mapWH, width, height);
732
+ gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
733
+ gl.uniform3fv(program.uTranslate, transPos);
734
+ gl.drawArrays(gl.POINTS, 0, this._numParticles);
735
+ }
736
+ // globe calls `setGeometry` method on map projection change. FLAT or SPHERE
737
+ setGeometry() {
738
+ if (this.windData === null) {
739
+ return;
740
+ }
741
+ const { globe, gl } = this;
742
+ const geometry = globe.api_GetCurrentGeometry();
743
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
744
+ if (geometry === globe.api_GeometryTypes().SPHERE) {
745
+ this._drawParticles = this._drawParticlesSphere;
746
+ gl.useProgram(this.drawSphereProgram.program);
747
+ gl.uniform2f(this.drawSphereProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
748
+ gl.uniform2f(this.drawSphereProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
749
+ }
750
+ else if (geometry === globe.api_GeometryTypes().FLAT) {
751
+ this._drawParticles = this._drawParticlesFlat;
752
+ gl.useProgram(this.drawFlatProgram.program);
753
+ gl.uniform2f(this.drawFlatProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
754
+ gl.uniform2f(this.drawFlatProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
755
+ }
756
+ else {
757
+ alert("Geometry is not supported");
758
+ }
759
+ gl.useProgram(currentProgram);
760
+ this.resize();
761
+ }
762
+ _updateParticles() {
763
+ const gl = this.gl;
764
+ const program = this.updateProgram;
765
+ gl.disable(gl.BLEND);
766
+ gl.useProgram(program.program);
767
+ gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
768
+ bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
769
+ gl.uniform1i(program.u_wind, 0);
770
+ gl.uniform1i(program.u_particles, 1);
771
+ bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
772
+ gl.uniform1f(program.u_rand_seed, Math.random());
773
+ bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
774
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
775
+ // swap the particle state textures so the new one becomes the current one
776
+ const temp = this.particleStateTexture0;
777
+ this.particleStateTexture0 = this.particleStateTexture1;
778
+ this.particleStateTexture1 = temp;
779
+ // Add this line to restore the viewport
780
+ gl.viewport(0, 0, this.globe.api_ScrW(), this.globe.api_ScrH());
781
+ }
782
+ _resetMachineStates() {
783
+ const { gl, globe } = this;
784
+ // Unbind all textures
785
+ for (let i = 0; i < 3; i++) {
786
+ gl.activeTexture(gl.TEXTURE0 + i);
787
+ gl.bindTexture(gl.TEXTURE_2D, null);
788
+ }
789
+ gl.activeTexture(gl.TEXTURE0);
790
+ // Unbind buffers
791
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
792
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
793
+ gl.bindVertexArray(null); // Add this line
794
+ gl.enable(gl.BLEND);
795
+ defaultblendfunction(gl);
796
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
797
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
798
+ }
799
+ _loadHeight() {
800
+ const { gl, drawSphereProgram } = this;
801
+ if (gl == null)
802
+ return;
803
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
804
+ gl.useProgram(drawSphereProgram.program);
805
+ gl.uniform1f(drawSphereProgram.u_height, this._height);
806
+ gl.useProgram(currentProgram);
807
+ }
808
+ _loadMinMaxSpeed() {
809
+ const { gl, drawSphereProgram, drawFlatProgram } = this;
810
+ if (gl == null)
811
+ return;
812
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
813
+ gl.useProgram(drawSphereProgram.program);
814
+ gl.uniform1f(drawSphereProgram.u_min_speed, this._minSpeed);
815
+ gl.uniform1f(drawSphereProgram.u_max_speed, this._maxSpeed);
816
+ gl.useProgram(drawFlatProgram.program);
817
+ gl.uniform1f(drawFlatProgram.u_min_speed, this._minSpeed);
818
+ gl.uniform1f(drawFlatProgram.u_max_speed, this._maxSpeed);
819
+ gl.useProgram(currentProgram);
820
+ }
821
+ _loadFadeOpacity() {
822
+ const { gl, screenProgram } = this;
823
+ if (gl == null) {
824
+ return;
825
+ }
826
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
827
+ gl.useProgram(screenProgram.program);
828
+ gl.uniform1f(screenProgram.u_opacity, this._fadeOpacity);
829
+ gl.useProgram(currentProgram);
830
+ }
831
+ _loadSpeedFactor() {
832
+ const { gl, globe, updateProgram } = this;
833
+ if (gl == null) {
834
+ return;
835
+ }
836
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
837
+ gl.useProgram(updateProgram.program);
838
+ gl.uniform1f(updateProgram.u_speed_factor, this._speedFactor / Math.ceil(Math.sqrt(globe.api_GetCurrentLOD())));
839
+ gl.useProgram(currentProgram);
840
+ }
841
+ _loadDropRate() {
842
+ const { gl, updateProgram } = this;
843
+ if (gl == null) {
844
+ return;
845
+ }
846
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
847
+ gl.useProgram(updateProgram.program);
848
+ gl.uniform1f(updateProgram.u_drop_rate, this._dropRate);
849
+ gl.useProgram(currentProgram);
850
+ }
851
+ _loadDropRateBump() {
852
+ const { gl, updateProgram } = this;
853
+ if (gl == null) {
854
+ return;
855
+ }
856
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
857
+ gl.useProgram(updateProgram.program);
858
+ gl.uniform1f(updateProgram.u_drop_rate_bump, this._dropRateBump);
859
+ gl.useProgram(currentProgram);
860
+ }
861
+ _loadBaseOpacity() {
862
+ const { gl, drawSphereProgram, drawFlatProgram } = this;
863
+ if (gl == null) {
864
+ return;
865
+ }
866
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
867
+ gl.useProgram(drawSphereProgram.program);
868
+ gl.uniform1f(drawSphereProgram.u_base_opacity, this._baseOpacity);
869
+ gl.useProgram(drawFlatProgram.program);
870
+ gl.uniform1f(drawFlatProgram.u_base_opacity, this._baseOpacity);
871
+ gl.useProgram(currentProgram);
872
+ }
873
+ _loadPointSize() {
874
+ const { gl, drawSphereProgram, drawFlatProgram } = this;
875
+ if (gl == null) {
876
+ return;
877
+ }
878
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
879
+ gl.useProgram(drawSphereProgram.program);
880
+ gl.uniform1f(drawSphereProgram.u_point_size, this._pointSize);
881
+ gl.useProgram(drawFlatProgram.program);
882
+ gl.uniform1f(drawFlatProgram.u_point_size, this._pointSize);
883
+ gl.useProgram(currentProgram);
884
+ }
885
+ // globe plugin init methodu
886
+ init(globe, gl) {
887
+ // console.log("init wind plugin")
888
+ this.globe = globe;
889
+ this.gl = gl;
890
+ this.drawSphereProgram = createProgramWrapper(gl, drawSphereVert, drawFrag);
891
+ this.screenProgram = createProgramWrapper(gl, quadVert, screenFrag);
892
+ this.updateProgram = createProgramWrapper(gl, quadVert, updateFrag);
893
+ this.drawFlatProgram = createProgramWrapper(gl, drawFlatVert, drawFrag);
894
+ this.quadBuffer = createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
895
+ this.framebuffer = gl.createFramebuffer();
896
+ this._loadFadeOpacity();
897
+ this._loadSpeedFactor();
898
+ this._loadDropRate();
899
+ this._loadDropRateBump();
900
+ this._loadBaseOpacity();
901
+ this._loadPointSize();
902
+ this._loadMinMaxSpeed();
903
+ this._loadHeight();
904
+ if (this._legendData != null) {
905
+ this.setLegend(this._legendData);
906
+ }
907
+ this.numParticles = this._numParticles;
908
+ this.resize();
909
+ }
910
+ resize(a, b) {
911
+ const { gl, globe } = this;
912
+ const emptyPixels = new Uint8Array(globe.api_ScrW() * globe.api_ScrH() * 4);
913
+ // screen textures to hold the drawn screen for the previous and the current frame
914
+ this.backgroundTexture = createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
915
+ this.screenTexture = createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
916
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
917
+ }
918
+ // globe calls this `free` on plugin object unregistration
919
+ free() {
920
+ const gl = this.gl;
921
+ gl.deleteBuffer(this.quadBuffer);
922
+ gl.deleteFramebuffer(this.framebuffer);
923
+ gl.deleteTexture(this.backgroundTexture);
924
+ gl.deleteTexture(this.screenTexture);
925
+ gl.deleteTexture(this.particleStateTexture0);
926
+ gl.deleteTexture(this.particleStateTexture1);
927
+ gl.deleteTexture(this.windTexture);
928
+ gl.deleteTexture(this.colorRampTexture);
929
+ gl.deleteProgram(this.drawSphereProgram.program);
930
+ gl.deleteProgram(this.screenProgram.program);
931
+ gl.deleteProgram(this.updateProgram.program);
932
+ gl.deleteProgram(this.drawFlatProgram.program);
933
+ gl.deleteBuffer(this.particleIndexBuffer);
934
+ }
935
+ }