@pirireis/webglobeplugins 0.9.6 → 0.9.8

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 (304) hide show
  1. package/{Math → dist/Math}/angle-calculation.js +15 -14
  2. package/dist/Math/arc.js +65 -0
  3. package/{Math → dist/Math}/bounds/line-bbox.js +188 -225
  4. package/dist/Math/constants.js +9 -0
  5. package/{Math/frustum/camera.ts → dist/Math/frustum/camera.js} +24 -32
  6. package/{Math/frustum/from-globeinfo.ts → dist/Math/frustum/from-globeinfo.js} +48 -63
  7. package/dist/Math/frustum/types.js +2 -0
  8. package/{Math/globe-util/horizon-plane.ts → dist/Math/globe-util/horizon-plane.js} +112 -137
  9. package/dist/Math/index.js +1 -0
  10. package/dist/Math/juction/arc-plane.js +83 -0
  11. package/dist/Math/juction/line-sphere.js +25 -0
  12. package/{Math/juction/plane-plane.ts → dist/Math/juction/plane-plane.js} +58 -66
  13. package/dist/Math/line.js +56 -0
  14. package/dist/Math/matrix4.js +1 -0
  15. package/{Math → dist/Math}/methods.js +201 -237
  16. package/dist/Math/plane.js +60 -0
  17. package/{Math/quaternion.ts → dist/Math/quaternion.js} +104 -120
  18. package/dist/Math/types.js +2 -0
  19. package/dist/Math/utils.js +4 -0
  20. package/{Math/vec3.ts → dist/Math/vec3.js} +126 -155
  21. package/dist/algorithms/search-binary.js +19 -0
  22. package/dist/altitude-locator/adaptors.js +1 -0
  23. package/{altitude-locator → dist/altitude-locator}/draw-subset-obj.js +18 -27
  24. package/dist/altitude-locator/keymethod.js +1 -0
  25. package/{altitude-locator → dist/altitude-locator}/plugin.js +341 -439
  26. package/{altitude-locator → dist/altitude-locator}/types.js +23 -26
  27. package/{arrowfield → dist/arrowfield}/adaptor.js +14 -11
  28. package/dist/arrowfield/index.js +10 -0
  29. package/{arrowfield → dist/arrowfield}/plugin.js +86 -128
  30. package/dist/bearing-line/index.js +8 -0
  31. package/{bearing-line → dist/bearing-line}/plugin.js +449 -512
  32. package/{circle-line-chain → dist/circle-line-chain}/chain-list-map.js +205 -221
  33. package/dist/circle-line-chain/init.js +1 -0
  34. package/{circle-line-chain → dist/circle-line-chain}/plugin.js +424 -469
  35. package/dist/circle-line-chain/util.js +5 -0
  36. package/{compass-rose → dist/compass-rose}/compass-rose-padding-flat.js +225 -266
  37. package/{compass-rose → dist/compass-rose}/compass-text-writer.js +153 -173
  38. package/dist/compass-rose/index.js +7 -0
  39. package/{compassrose → dist/compassrose}/compassrose.js +296 -341
  40. package/dist/compassrose/index.js +8 -0
  41. package/dist/globe-types.js +1 -0
  42. package/dist/heatwave/index.js +10 -0
  43. package/{heatwave → dist/heatwave}/isobar/objectarraylabels.js +202 -247
  44. package/{heatwave → dist/heatwave}/isobar/plugin.js +343 -340
  45. package/{heatwave → dist/heatwave}/isobar/quadtreecontours.js +300 -336
  46. package/{heatwave → dist/heatwave}/plugins/heatwaveglobeshell.js +206 -258
  47. package/dist/index.js +58 -0
  48. package/{jest.config.js → dist/jest.config.js} +7 -6
  49. package/{partialrings → dist/partialrings}/buffer-manager.js +81 -89
  50. package/dist/partialrings/index.js +41 -0
  51. package/{partialrings → dist/partialrings}/plugin.js +135 -160
  52. package/{partialrings → dist/partialrings}/program.js +204 -242
  53. package/{pin → dist/pin}/pin-object-array.js +305 -381
  54. package/{pin → dist/pin}/pin-point-totem.js +60 -77
  55. package/{point-heat-map → dist/point-heat-map}/adaptors/timetracksplugin-format-to-this.js +66 -78
  56. package/dist/point-heat-map/index.js +1 -0
  57. package/{point-heat-map → dist/point-heat-map}/plugin-webworker.js +126 -151
  58. package/{point-heat-map → dist/point-heat-map}/point-to-heat-map-flow.js +127 -150
  59. package/dist/point-tracks/key-methods.js +5 -0
  60. package/{point-tracks → dist/point-tracks}/plugin.js +338 -394
  61. package/dist/programs/arrowfield/index.js +7 -0
  62. package/{programs → dist/programs}/arrowfield/logic.js +144 -173
  63. package/{programs → dist/programs}/arrowfield/object.js +66 -89
  64. package/{programs → dist/programs}/data2legend/density-to-legend.js +76 -90
  65. package/{programs → dist/programs}/data2legend/point-to-density-texture.js +76 -90
  66. package/dist/programs/float2legendwithratio/index.js +8 -0
  67. package/{programs → dist/programs}/float2legendwithratio/logic.js +122 -145
  68. package/{programs → dist/programs}/float2legendwithratio/object.js +110 -141
  69. package/{programs → dist/programs}/globe-util/is-globe-moved.js +21 -27
  70. package/dist/programs/globeshell/index.js +8 -0
  71. package/dist/programs/globeshell/noise/noises.js +1 -0
  72. package/dist/programs/globeshell/wiggle/index.js +8 -0
  73. package/{programs → dist/programs}/globeshell/wiggle/logic.js +246 -272
  74. package/{programs → dist/programs}/globeshell/wiggle/object.js +72 -93
  75. package/dist/programs/helpers/blender/index.js +1 -0
  76. package/{programs → dist/programs}/helpers/blender/program.js +61 -73
  77. package/dist/programs/helpers/fadeaway/index.js +7 -0
  78. package/{programs → dist/programs}/helpers/fadeaway/logic.js +49 -53
  79. package/dist/programs/helpers/fadeaway/object.js +20 -0
  80. package/dist/programs/helpers/index.js +8 -0
  81. package/dist/programs/index.js +58 -0
  82. package/dist/programs/interface.js +1 -0
  83. package/{programs → dist/programs}/line-on-globe/angled-line.js +125 -155
  84. package/{programs → dist/programs}/line-on-globe/circle-accurate-3d.js +95 -121
  85. package/{programs → dist/programs}/line-on-globe/circle-accurate-flat.js +158 -204
  86. package/{programs → dist/programs}/line-on-globe/circle-accurate.js +117 -141
  87. package/{programs → dist/programs}/line-on-globe/circle.js +111 -135
  88. package/{programs → dist/programs}/line-on-globe/degree-padding-around-circle-3d.js +111 -140
  89. package/dist/programs/line-on-globe/index.js +1 -0
  90. package/{programs → dist/programs}/line-on-globe/lines-color-instanced-flat.js +91 -106
  91. package/{programs/line-on-globe/linestrip.ts → dist/programs/line-on-globe/linestrip.js} +108 -165
  92. package/{programs → dist/programs}/line-on-globe/naive-accurate-flexible.js +127 -171
  93. package/{programs → dist/programs}/line-on-globe/to-the-surface.js +83 -101
  94. package/dist/programs/line-on-globe/util.js +8 -0
  95. package/{programs → dist/programs}/picking/pickable-renderer.js +107 -135
  96. package/{programs → dist/programs}/point-on-globe/element-globe-surface-glow.js +101 -127
  97. package/{programs → dist/programs}/point-on-globe/element-point-glow.js +88 -119
  98. package/{programs → dist/programs}/point-on-globe/square-pixel-point.js +126 -141
  99. package/{programs/programcache.ts → dist/programs/programcache.js} +131 -131
  100. package/{programs → dist/programs}/rings/distancering/circleflatprogram.js +115 -95
  101. package/{programs → dist/programs}/rings/distancering/circlepaddingfreeangleprogram.js +320 -329
  102. package/{programs → dist/programs}/rings/distancering/circlepaddysharedbuffer.js +357 -420
  103. package/dist/programs/rings/distancering/index.js +14 -0
  104. package/{programs → dist/programs}/rings/distancering/paddyflatprogram.js +120 -94
  105. package/{programs → dist/programs}/rings/distancering/paddyflatprogram2d.js +122 -98
  106. package/{programs → dist/programs}/rings/distancering/paddyflatprogram3d.js +120 -94
  107. package/dist/programs/rings/distancering/shader.js +1 -0
  108. package/dist/programs/rings/index.js +17 -0
  109. package/{programs → dist/programs}/rings/partial-ring/piece-of-pie.js +181 -221
  110. package/{programs → dist/programs}/totems/camerauniformblock.js +147 -184
  111. package/{programs → dist/programs}/totems/canvas-webglobe-info.js +102 -128
  112. package/{programs → dist/programs}/totems/gpu-selection-uniform-block.js +104 -128
  113. package/dist/programs/totems/index.js +40 -0
  114. package/dist/programs/two-d/pixel-circle.js +1 -0
  115. package/{programs → dist/programs}/two-d/pixel-padding-for-compass.js +101 -113
  116. package/{programs → dist/programs}/util.js +17 -20
  117. package/dist/programs/vectorfields/index.js +23 -0
  118. package/{programs → dist/programs}/vectorfields/logics/drawrectangleparticles.js +65 -83
  119. package/dist/programs/vectorfields/logics/index.js +12 -0
  120. package/{programs → dist/programs}/vectorfields/logics/pixelbased.js +84 -103
  121. package/{programs → dist/programs}/vectorfields/logics/ubo.js +55 -56
  122. package/{programs → dist/programs}/vectorfields/pingpongbuffermanager.js +76 -80
  123. package/dist/rangerings/enum.js +5 -0
  124. package/dist/rangerings/index.js +15 -0
  125. package/{rangerings → dist/rangerings}/plugin.js +560 -649
  126. package/{rangerings → dist/rangerings}/rangeringangletext.js +329 -368
  127. package/{rangerings → dist/rangerings}/ring-account.js +117 -129
  128. package/{shaders → dist/shaders}/fragment-toy/firework.js +5 -2
  129. package/{shaders → dist/shaders}/fragment-toy/singularity.js +5 -5
  130. package/{shape-on-terrain/arc/naive/plugin.ts → dist/shape-on-terrain/arc/naive/plugin.js} +252 -304
  131. package/{timetracks → dist/timetracks}/adaptors-line-strip.js +71 -80
  132. package/{timetracks → dist/timetracks}/adaptors.js +122 -133
  133. package/dist/timetracks/index.js +19 -0
  134. package/{timetracks → dist/timetracks}/plugin-line-strip.js +250 -295
  135. package/{timetracks → dist/timetracks}/plugin.js +258 -304
  136. package/{timetracks → dist/timetracks}/program-line-strip.js +416 -493
  137. package/{timetracks → dist/timetracks}/program.js +464 -542
  138. package/{timetracks → dist/timetracks}/programpoint-line-strip.js +101 -122
  139. package/{timetracks → dist/timetracks}/programpoint.js +101 -122
  140. package/{types.ts → dist/types.js} +15 -17
  141. package/{util → dist/util}/account/bufferoffsetmanager.js +179 -209
  142. package/dist/util/account/index.js +23 -0
  143. package/{util/account/single-attribute-buffer-management/buffer-manager.ts → dist/util/account/single-attribute-buffer-management/buffer-manager.js} +108 -119
  144. package/{util/account/single-attribute-buffer-management/buffer-orchestrator.ts → dist/util/account/single-attribute-buffer-management/buffer-orchestrator.js} +150 -173
  145. package/dist/util/account/single-attribute-buffer-management/index.js +9 -0
  146. package/{util/account/single-attribute-buffer-management/object-store.ts → dist/util/account/single-attribute-buffer-management/object-store.js} +51 -65
  147. package/dist/util/account/single-attribute-buffer-management/types.js +2 -0
  148. package/{util → dist/util}/account/util.js +22 -22
  149. package/dist/util/algorithms/index.js +1 -0
  150. package/{util → dist/util}/algorithms/search-binary.js +28 -26
  151. package/dist/util/check/get.js +18 -0
  152. package/dist/util/check/index.js +1 -0
  153. package/dist/util/check/typecheck.js +49 -0
  154. package/{util → dist/util}/geometry/index.js +51 -53
  155. package/{util/gl-util/buffer/attribute-loader.ts → dist/util/gl-util/buffer/attribute-loader.js} +69 -85
  156. package/dist/util/gl-util/buffer/index.js +6 -0
  157. package/dist/util/gl-util/buffer/types.js +1 -0
  158. package/dist/util/gl-util/draw-options/methods.js +38 -0
  159. package/dist/util/gl-util/draw-options/types.js +15 -0
  160. package/{util/gl-util/uniform-block/manager.ts → dist/util/gl-util/uniform-block/manager.js} +156 -187
  161. package/dist/util/gl-util/uniform-block/shader.js +1 -0
  162. package/dist/util/gl-util/uniform-block/types.js +8 -0
  163. package/{util → dist/util}/heatwavedatamanager/datamanager.js +152 -168
  164. package/dist/util/heatwavedatamanager/index.js +10 -0
  165. package/{util → dist/util}/heatwavedatamanager/pointcoordinatesdatacalculator.js +122 -133
  166. package/{util → dist/util}/heatwavedatamanager/pointcoordsmeta.js +20 -22
  167. package/dist/util/index.js +57 -0
  168. package/dist/util/interpolation/index.js +1 -0
  169. package/dist/util/interpolation/timetrack/index.js +5 -0
  170. package/{util → dist/util}/interpolation/timetrack/timetrack-interpolator.js +79 -88
  171. package/{util → dist/util}/interpolation/timetrack/web-worker-str.js +5 -2
  172. package/{util → dist/util}/interpolation/timetrack/web-worker.js +48 -51
  173. package/{util → dist/util}/jshelpers/data-filler.js +20 -19
  174. package/{util → dist/util}/jshelpers/equality.js +20 -17
  175. package/dist/util/jshelpers/index.js +37 -0
  176. package/{util → dist/util}/jshelpers/timefilters.js +32 -32
  177. package/{util → dist/util}/picking/fence.js +46 -46
  178. package/{util → dist/util}/picking/picker-displayer.js +139 -177
  179. package/{util → dist/util}/programs/draw-texture-on-canvas.js +69 -82
  180. package/dist/util/programs/index.js +17 -0
  181. package/{util → dist/util}/programs/shapesonglobe.js +174 -206
  182. package/{util → dist/util}/programs/supersampletotextures.js +103 -132
  183. package/{util → dist/util}/programs/texturetoglobe.js +133 -154
  184. package/{util/shaderfunctions/geometrytransformations.ts → dist/util/shaderfunctions/geometrytransformations.js} +68 -116
  185. package/dist/util/shaderfunctions/index.js +18 -0
  186. package/{util → dist/util}/shaderfunctions/nodata.js +5 -4
  187. package/{util → dist/util}/shaderfunctions/noisefunctions.js +9 -10
  188. package/{util/surface-line-data/arc-bboxes.ts → dist/util/surface-line-data/arc-bboxes.js} +25 -42
  189. package/{util → dist/util}/surface-line-data/arcs-to-cuts.js +50 -74
  190. package/dist/util/surface-line-data/cut-arc.js +1 -0
  191. package/{util/surface-line-data/flow.ts → dist/util/surface-line-data/flow.js} +28 -52
  192. package/dist/util/surface-line-data/rbush-manager.js +1 -0
  193. package/dist/util/surface-line-data/types.js +1 -0
  194. package/dist/util/surface-line-data/web-worker.js +1 -0
  195. package/dist/util/webglobe/gldefaultstates.js +7 -0
  196. package/dist/util/webglobe/index.js +18 -0
  197. package/{util → dist/util}/webglobe/rasteroverlay.js +78 -96
  198. package/{util/webglobjectbuilders.ts → dist/util/webglobjectbuilders.js} +388 -456
  199. package/{util → dist/util}/webglobjectbuilders1.js +237 -271
  200. package/{waveparticles → dist/waveparticles}/adaptor.js +17 -16
  201. package/dist/waveparticles/index.js +10 -0
  202. package/{waveparticles → dist/waveparticles}/plugin.js +266 -313
  203. package/{wind → dist/wind}/imagetovectorfieldandmagnitude.js +35 -39
  204. package/dist/wind/index.js +14 -0
  205. package/{wind → dist/wind}/plugin.js +681 -812
  206. package/{wind → dist/wind}/vectorfieldimage.js +25 -27
  207. package/{write-text → dist/write-text}/attached-text-writer.js +91 -105
  208. package/{write-text → dist/write-text}/context-text.js +98 -125
  209. package/{write-text → dist/write-text}/context-text3.js +155 -178
  210. package/dist/write-text/index.js +5 -0
  211. package/{write-text → dist/write-text}/writer-plugin.js +8 -7
  212. package/package.json +5 -2
  213. package/Math/arc.ts +0 -76
  214. package/Math/constants.ts +0 -11
  215. package/Math/frustum/types.ts +0 -11
  216. package/Math/index.js +0 -0
  217. package/Math/juction/arc-plane.ts +0 -114
  218. package/Math/juction/line-sphere.ts +0 -30
  219. package/Math/line.ts +0 -70
  220. package/Math/matrix4.ts +0 -0
  221. package/Math/plane.ts +0 -86
  222. package/Math/roadmap.md +0 -10
  223. package/Math/types.ts +0 -45
  224. package/Math/utils.js +0 -3
  225. package/algorithms/search-binary.js +0 -14
  226. package/altitude-locator/adaptors.js +0 -0
  227. package/altitude-locator/keymethod.js +0 -0
  228. package/arrowfield/index.js +0 -3
  229. package/bearing-line/index.js +0 -2
  230. package/circle-line-chain/init.js +0 -0
  231. package/circle-line-chain/readme.md +0 -57
  232. package/circle-line-chain/util.js +0 -1
  233. package/compass-rose/index.js +0 -3
  234. package/compassrose/index.js +0 -2
  235. package/depth-locator/readme.md +0 -26
  236. package/globe-types.ts +0 -13
  237. package/heatwave/index.js +0 -4
  238. package/partialrings/goals.md +0 -17
  239. package/partialrings/index.js +0 -3
  240. package/point-heat-map/index.js +0 -0
  241. package/point-heat-map/readme.md +0 -15
  242. package/point-tracks/key-methods.js +0 -3
  243. package/programs/arrowfield/index.js +0 -2
  244. package/programs/float2legendwithratio/index.js +0 -3
  245. package/programs/globeshell/index.js +0 -2
  246. package/programs/globeshell/noise/noises.js +0 -0
  247. package/programs/globeshell/wiggle/index.js +0 -6
  248. package/programs/helpers/blender/index.js +0 -0
  249. package/programs/helpers/fadeaway/index.js +0 -3
  250. package/programs/helpers/fadeaway/object.js +0 -20
  251. package/programs/helpers/index.js +0 -2
  252. package/programs/index.js +0 -21
  253. package/programs/interface.ts +0 -7
  254. package/programs/line-on-globe/index.js +0 -0
  255. package/programs/line-on-globe/util.js +0 -8
  256. package/programs/rings/distancering/index.js +0 -5
  257. package/programs/rings/distancering/shader.js +0 -0
  258. package/programs/rings/index.js +0 -1
  259. package/programs/totems/camerauniformblock.d.ts +0 -48
  260. package/programs/totems/index.ts +0 -2
  261. package/programs/two-d/pixel-circle.js +0 -0
  262. package/programs/vectorfields/index.js +0 -3
  263. package/programs/vectorfields/logics/index.js +0 -5
  264. package/publish.bat +0 -60
  265. package/rangerings/enum.js +0 -3
  266. package/rangerings/index.js +0 -5
  267. package/shape-on-terrain/goal.md +0 -12
  268. package/tests/Math/junction/arc-plane.test.ts +0 -133
  269. package/tests/Math/junction/plane-plane.test.ts +0 -82
  270. package/tests/Math/plane.test.ts +0 -43
  271. package/tests/Math/vec3.test.ts +0 -14
  272. package/timetracks/index.js +0 -6
  273. package/timetracks/readme.md +0 -1
  274. package/tsconfig.json +0 -22
  275. package/util/account/index.js +0 -6
  276. package/util/account/single-attribute-buffer-management/index.ts +0 -13
  277. package/util/account/single-attribute-buffer-management/types.ts +0 -39
  278. package/util/algorithms/index.js +0 -0
  279. package/util/check/get.js +0 -13
  280. package/util/check/index.js +0 -0
  281. package/util/check/typecheck.js +0 -39
  282. package/util/gl-util/buffer/index.ts +0 -6
  283. package/util/gl-util/buffer/types.ts +0 -13
  284. package/util/gl-util/draw-options/methods.ts +0 -66
  285. package/util/gl-util/draw-options/types.ts +0 -28
  286. package/util/gl-util/uniform-block/roadmap.md +0 -70
  287. package/util/gl-util/uniform-block/shader.js +0 -0
  288. package/util/gl-util/uniform-block/types.ts +0 -27
  289. package/util/heatwavedatamanager/index.js +0 -3
  290. package/util/index.js +0 -13
  291. package/util/interpolation/index.js +0 -0
  292. package/util/interpolation/timetrack/index.js +0 -9
  293. package/util/jshelpers/index.js +0 -1
  294. package/util/programs/index.js +0 -1
  295. package/util/shaderfunctions/index.js +0 -2
  296. package/util/surface-line-data/cut-arc.js +0 -0
  297. package/util/surface-line-data/rbush-manager.js +0 -0
  298. package/util/surface-line-data/types.ts +0 -27
  299. package/util/surface-line-data/web-worker.js +0 -0
  300. package/util/webglobe/gldefaultstates.js +0 -5
  301. package/util/webglobe/index.js +0 -2
  302. package/waveparticles/index.js +0 -3
  303. package/wind/index.js +0 -5
  304. package/write-text/index.js +0 -1
@@ -1,45 +1,76 @@
1
- /**
2
- * Author: Toprak Nihat Deniz Ozturk
3
- */
4
-
5
-
6
- import * as util from "../util";
7
- import imageToMagnitude from "./imagetovectorfieldandmagnitude";
8
- import { PointCoordinatesDataCalculator } from "../util";
9
- /**
10
- * Shader Dökümanı:
11
- * * Vektör alan haritasında kaçış değeri
12
- * texture2D(u_wind, pos).rg == vec2(0.0, 0.0) değerini kaçış için kullandım.
13
- * Deniz rüzgarları gibi haritalarda kara için rg değerleri 0.0 oluyor.
14
- * Gerçek bir partikülün rg == vec2(0.0, 0.0) değerinde olma olasılığı düşük.
15
- * Hem yatay ve hem dikey boyutta en düşük değere sahip olmalı.
16
- *
17
-
18
- *
19
- */
20
-
21
-
22
- /**
23
- * @typedef {Object} WindData for setWindDataWithImageBase64
24
- * @property {string} image - base64 encoded image
25
- * @property {number} width - image width
26
- * @property {number} height - image height
27
- * @property {number} uMin - minimum u value
28
- * @property {number} vMin - minimum v value
29
- * @property {number} uMax - maximum u value
30
- * @property {number} vMax - maximum v value
31
- * @property {Array} bbox - bounding box [minLon, minLat, maxLon, maxLat]
32
- * @property {LegendData} legendData - legend data
33
-
34
- */
35
-
36
-
37
- /**
38
- * @typedef {Object} LegendData
39
- * @property {Array} thresholds - list of integers
40
- * @property {Array} values - list of colors
41
- */
42
-
1
+ "use strict";
2
+ /**
3
+ * Author: Toprak Nihat Deniz Ozturk
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ const util = __importStar(require("../util"));
43
+ const imagetovectorfieldandmagnitude_1 = __importDefault(require("./imagetovectorfieldandmagnitude"));
44
+ const util_1 = require("../util");
45
+ /**
46
+ * Shader Dökümanı:
47
+ * * Vektör alan haritasında kaçış değeri
48
+ * texture2D(u_wind, pos).rg == vec2(0.0, 0.0) değerini kaçış için kullandım.
49
+ * Deniz rüzgarları gibi haritalarda kara için rg değerleri 0.0 oluyor.
50
+ * Gerçek bir partikülün rg == vec2(0.0, 0.0) değerinde olma olasılığı düşük.
51
+ * Hem yatay ve hem dikey boyutta en düşük değere sahip olmalı.
52
+ *
53
+
54
+ *
55
+ */
56
+ /**
57
+ * @typedef {Object} WindData for setWindDataWithImageBase64
58
+ * @property {string} image - base64 encoded image
59
+ * @property {number} width - image width
60
+ * @property {number} height - image height
61
+ * @property {number} uMin - minimum u value
62
+ * @property {number} vMin - minimum v value
63
+ * @property {number} uMax - maximum u value
64
+ * @property {number} vMax - maximum v value
65
+ * @property {Array} bbox - bounding box [minLon, minLat, maxLon, maxLat]
66
+ * @property {LegendData} legendData - legend data
67
+
68
+ */
69
+ /**
70
+ * @typedef {Object} LegendData
71
+ * @property {Array} thresholds - list of integers
72
+ * @property {Array} values - list of colors
73
+ */
43
74
  const quadVert = `
44
75
  precision mediump float;
45
76
 
@@ -50,8 +81,7 @@ varying vec2 v_tex_pos;
50
81
  void main() {
51
82
  v_tex_pos = a_pos;
52
83
  gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);
53
- }`;
54
-
84
+ }`;
55
85
  const screenFrag = `precision mediump float;
56
86
 
57
87
  uniform sampler2D u_screen;
@@ -65,8 +95,7 @@ void main() {
65
95
  gl_FragColor = vec4( floor(255.0 * color * u_opacity) / 255.0);
66
96
  }
67
97
 
68
- `;
69
-
98
+ `;
70
99
  const updateFrag = `
71
100
  precision highp float;
72
101
 
@@ -140,9 +169,7 @@ void main() {
140
169
  fract(pos * 255.0),
141
170
  floor(pos * 255.0) / 255.0);
142
171
  }
143
- `;
144
-
145
-
172
+ `;
146
173
  const drawFrag = `precision mediump float;
147
174
 
148
175
  uniform sampler2D u_wind;
@@ -185,9 +212,7 @@ void main() {
185
212
 
186
213
  gl_FragColor = texture2D(u_color_ramp, ramp_pos) * u_base_opacity;
187
214
  }
188
- `;
189
-
190
-
215
+ `;
191
216
  const drawSphereVert = `
192
217
  precision mediump float;
193
218
 
@@ -246,8 +271,7 @@ void main() {
246
271
  gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(pos - uTranslate, 1.0);
247
272
  gl_PointSize = u_point_size;
248
273
 
249
- }`;
250
-
274
+ }`;
251
275
  const drawFlatVert = `
252
276
  precision mediump float;
253
277
 
@@ -297,761 +321,606 @@ void main() {
297
321
  gl_Position = uProjectionMatrix * vec4(normalizedX * u_scrWH.x, (1.0 - normalizedY) * u_scrWH.y, 0.0, 1.0);
298
322
 
299
323
  gl_PointSize = u_point_size;
300
- }`;
301
-
302
-
303
-
304
- const defaultRampColors = [
305
- [0.0, '#5e4fa2'],
306
- [0.08, '#3288bd'],
307
- [0.2, '#66c2a5'],
308
- [0.3, '#abdda4'],
309
- [0.4, '#e6f598'],
310
- [0.5, '#fee08b'],
311
- [0.6, '#fdae61'],
312
- [0.7, '#f46d43'],
313
- [1.0, '#d53e4f']
314
-
315
- ];
316
-
317
-
318
- const windyLegendData = {
319
- "thresholds": [0, 3, 3, 5, 5, 7, 10, 10, 13, 15, 15, 17, 20, 20, 25, 25, 30],
320
- // 0 5 10 20 30 40 60
321
- // "thresholds": [0, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 40, 60],
322
- "values": [
323
- "#6271B8",
324
- "#6271B8",
325
- "#6271B8",
326
- "#6271B8",
327
- "#3D6EA3",
328
- "#4A94AA",
329
- "#4A9294",
330
- "#4D8E7C",
331
- "#4CA44C",
332
- "#67A436",
333
- "#A28740",
334
- "#A26D5C",
335
- "#8D3F5C",
336
- "#974B91",
337
- "#5F64A0",
338
- "#5B88A1",
339
- "#5B88A1"
340
- ]
341
- };
342
-
343
-
344
- export default class WindPlugin {
345
-
346
- /**
347
- * @param {String} id
348
- * @param {Object} windDataMeta
349
- * @param {number} windDataMeta.width - image width
350
- * @param {number} windDataMeta.height - image height
351
- * @param {Array} windDataMeta.bbox - bounding box [minLon, minLat, maxLon, maxLat]
352
- * @param {Object} options
353
- * @param {number} options.fadeOpacity - how fast the particle trails fade on each frame | between 0 - 1 | default 0.746
354
- * @param {number} options.speedFactor - how fast the particles move | between 0 - 1 | default 0.6
355
- * @param {number} options.dropRate - how often the particles move to a random place | between 0 - 1 | default 0.007
356
- * @param {number} options.dropRateBump - drop rate increase relative to individual particle speed
357
- * @param {number} options.baseOpacity - opacity of drawn particle trails | between 0 - 1 | default 1.0
358
- * @param {number} options.pointSize - draw size of each particle | positive number | default 2.0
359
- * @param {number} options.minSpeed - minimum speed value | positive number | default 0.0
360
- * @param {number} options.maxSpeed - maximum speed value | positive number | default 1000.0
361
- * @param {number} options.height - height of the particles | number | default 0.0
362
- * @param {number} numParticles - number of particles | positive integer
363
- * @param {LegendData} options.legendData - legend data
364
- */
365
- constructor(id,
366
- windDataMeta,
367
- {
368
- fadeOpacity = 0.746,
369
- speedFactor = 0.6,
370
- dropRate = 0.007,
371
- dropRateBump = 0.001,
372
- baseOpacity = 1.0,
373
- pointSize = 2.0,
374
- minSpeed = 0.0,
375
- maxSpeed = 1000.0,
376
- height = 0.0,
377
- numParticles = 40000,
378
- legendData = windyLegendData
379
- } = {}) {
380
-
381
- this.id = id;
382
- this._windDataMeta = windDataMeta;
383
- this.globe = null;
384
- this.gl = null;
385
-
386
-
387
- this._screenMoved = false;
388
- this.projMatrix = null;
389
- this.modelviewMatrix = null;
390
- this.transPos = new Float32Array([0, 0, 0]);
391
- this.windData = null;
392
-
393
- this._fadeOpacity = fadeOpacity;
394
- this._speedFactor = speedFactor;
395
- this._dropRate = dropRate;
396
- this._dropRateBump = dropRateBump;
397
- this._baseOpacity = baseOpacity;
398
- this._pointSize = pointSize;
399
- this._minSpeed = minSpeed;
400
- this._maxSpeed = maxSpeed;
401
- this._height = height;
402
- this._numParticles = numParticles;
403
- this._legendData = legendData;
404
-
405
- this.lastdatas = [[], [], { x: 0, y: 0, z: 0 }];
406
-
407
- this._drawParticles = this._drawParticlesSphere
408
-
409
- this._lastLOD = 0;
410
- }
411
-
412
- // Uniforms are loaded once, on initiation and when they are changed.
413
-
414
- set height(value) {
415
- this._height = value;
416
- this._loadHeight();
417
- }
418
-
419
-
420
- set minSpeed(value) {
421
- this._minSpeed = value;
422
- this._loadMinMaxSpeed();
423
- }
424
-
425
-
426
- set maxSpeed(value) {
427
- this._maxSpeed = value;
428
- this._loadMinMaxSpeed();
429
- }
430
-
431
-
432
- set fadeOpacity(value) {
433
- this._fadeOpacity = value;
434
- this._loadFadeOpacity();
435
- }
436
-
437
-
438
- set speedFactor(value) {
439
- this._speedFactor = value;
440
- this._loadSpeedFactor()
441
- }
442
-
443
-
444
- set dropRate(value) {
445
- this._dropRate = value;
446
- this._loadDropRate();
447
- }
448
-
449
-
450
- set dropRateBump(value) {
451
- this._dropRateBump = value;
452
- this._loadDropRateBump();
453
- }
454
-
455
-
456
- set baseOpacity(value) {
457
- this._baseOpacity = value;
458
- this._loadBaseOpacity();
459
- }
460
-
461
-
462
- set pointSize(value) {
463
- this._pointSize = value;
464
- this._loadPointSize();
465
- }
466
-
467
-
468
-
469
-
470
- // Color ramp methods.
471
- // Color ramp is used to colorize the particles according to their speed.
472
- // Legend max value is used to normalize the speed values.
473
-
474
- setColorRamp(colors) {
475
- // lookup texture for colorizing the particles according to their speed
476
- if (this.gl == null) {
477
- return;
478
- }
479
- this.colorRampTexture = util.createTexture(this.gl, this.gl.LINEAR, util.getColorRamp(colors), 16, 16);
480
- }
481
-
482
- setColorRampDefault() {
483
- const { uMax, uMin, vMax, vMin } = this.windData;
484
- const maxSpeed = Math.sqrt(
485
- uMax * uMax + vMax * vMax
486
- )
487
- const minSpeed = Math.sqrt(
488
- uMin * uMin + vMin * vMin
489
- )
490
- // console.log("maxSpeed", maxSpeed, "minSpeed", minSpeed);
491
- this._rampMax = maxSpeed > minSpeed ? maxSpeed : minSpeed;
492
- this._loadRampMax();
493
- this.setColorRamp(defaultRampColors);
494
-
495
- }
496
-
497
- /**
498
- *
499
- * @param {*} legendData
500
- * @param {Array} legendData.thresholds - list of integers
501
- * @param {Array} legendData.values - list of colors in hex format like #ff0000 (alpha is not included)
502
- *
503
- */
504
- setLegend(legendData) {
505
- const { gl } = this;
506
- if (gl === null) {
507
- throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
508
- }
509
- const { thresholds, values } = legendData;
510
- if (thresholds.length === 0 || values.length === 0) {
511
- return;
512
- }
513
- thresholds.push(thresholds[thresholds.length - 1]);
514
- values.push(values[values.length - 1]);
515
-
516
- const maxVelocity = thresholds[thresholds.length - 1];
517
-
518
- const colors = [];
519
- for (let i = 0; i < thresholds.length; i++) {
520
- colors.push([
521
- thresholds[i] / maxVelocity,
522
- values[i]
523
- ]);
524
- }
525
- const colorRamp = util.getColorRamp(colors);
526
- this.colorRampTexture = util.createTexture(gl, gl.LINEAR, colorRamp, 16, 16);
527
- this._rampMax = maxVelocity;
528
- this._loadRampMax();
529
- }
530
-
531
-
532
-
533
-
534
- // particle coordinates are encoded into RGBA texture
535
-
536
- set numParticles(numParticles) {
537
- const gl = this.gl;
538
- // we create a square texture where each pixel will hold a particle position encoded as RGBA
539
- const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(numParticles));
540
- this._numParticles = particleRes * particleRes;
541
-
542
- const particleState = new Uint8Array(this._numParticles * 4);
543
- for (let i = 0; i < particleState.length; i++) {
544
- particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
545
- }
546
- // textures to hold the particle state for the current and the next frame
547
- this.particleStateTexture0 = util.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
548
- this.particleStateTexture1 = util.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
549
-
550
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
551
- gl.useProgram(this.updateProgram.program);
552
- gl.uniform1f(this.updateProgram.u_wind_res, this.particleStateResolution);
553
- gl.useProgram(this.drawSphereProgram.program);
554
- gl.uniform1f(this.drawSphereProgram.u_particles_res, this.particleStateResolution);
555
- gl.useProgram(this.drawFlatProgram.program);
556
- gl.uniform1f(this.drawFlatProgram.u_particles_res, this.particleStateResolution);
557
- gl.useProgram(currentProgram);
558
-
559
- // console.log("numParticles", this._numParticles);
560
- const particleIndices = new Float32Array(this._numParticles);
561
- for (let i = 0; i < this._numParticles; i++) particleIndices[i] = i;
562
- this.particleIndexBuffer = util.createBuffer(gl, particleIndices);
563
- }
564
-
565
-
566
- get numParticles() {
567
- return this._numParticles;
568
- }
569
-
570
- // Vector field texture is used to calculate the particle movement.
571
- /**
572
- * @param {Object} windData
573
- * @param {HTMLImageElement} windData.image - image element
574
-
575
- * @param {number} windData.uMin - minimum u value
576
- * @param {number} windData.vMin - minimum v value
577
- * @param {number} windData.uMax - maximum u value
578
- * @param {number} windData.vMax - maximum v value
579
- */
580
- setWind(windData) {
581
- if (windData === null) {
582
- return;
583
- }
584
- const windDataMeta = this._windDataMeta;
585
- const gl = this.gl;
586
- this.windData = windData;
587
- this.windTexture = util.createTexture(gl, gl.LINEAR, windData.image);
588
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
589
- gl.useProgram(this.updateProgram.program);
590
-
591
- gl.uniform2f(this.updateProgram.u_wind_res, windDataMeta.width, windDataMeta.height);
592
- gl.uniform2f(this.updateProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
593
- gl.uniform2f(this.updateProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
594
- this.setGeometry();
595
- const minXY = this._latLongToPixelXY(windDataMeta.bbox[1], windDataMeta.bbox[0]);
596
- const maxXY = this._latLongToPixelXY(windDataMeta.bbox[3], windDataMeta.bbox[2]);
597
- this._loadBoundingBoxData(minXY.x, minXY.y, maxXY.x, maxXY.y);
598
-
599
- gl.useProgram(currentProgram);
600
-
601
-
602
- this._setCoorcinatesDataCalculatorData();
603
- this.resize();
604
- }
605
-
606
- // Vector field texture is used to calculate the particle movement.
607
- /**
608
- * @param {Object} windData
609
- * @param {BaseInt64} windData.image - image element
610
- * @param {number} windData.width - image width
611
- * @param {number} windData.height - image height
612
- * @param {number} windData.uMin - minimum u value
613
- * @param {number} windData.vMin - minimum v value
614
- * @param {number} windData.uMax - maximum u value
615
- * @param {number} windData.vMax - maximum v value
616
- * @param {Array} windData.bbox - bounding box [minLon, minLat, maxLon, maxLat]
617
- */
618
- setWindDataWithImageBase64(windData) {
619
- const image = util.createImageFromBase64(windData.image)
620
- image.onload = () => {
621
- windData.image = image;
622
- this.setWind(windData);
623
- }
624
- }
625
-
626
- getPointCoordinatesDataCalculator() {
627
- if (!this.coordinatesDataCalculator) this._createPointCoordinatesDataCalculator();
628
- return this.coordinatesDataCalculator;
629
- }
630
-
631
-
632
- _createPointCoordinatesDataCalculator() {
633
- const { bbox, width, height } = this._windDataMeta;
634
- this.coordinatesDataCalculator = new PointCoordinatesDataCalculator(bbox, width, height);
635
- this._setCoorcinatesDataCalculatorData();
636
- }
637
-
638
-
639
- _setCoorcinatesDataCalculatorData() {
640
- if (!this.windData || !this.coordinatesDataCalculator) {
641
- return;
642
- }
643
- const magnitude = imageToMagnitude(this.windData);
644
- this.coordinatesDataCalculator.updateData(0, magnitude, magnitude);
645
- }
646
-
647
-
648
- // -----------------------------------------------
649
- // --- inner methods ---
650
- // -----------------------------------------------
651
-
652
- _latLongToPixelXY(latitude, longitude) {
653
- return {
654
- x: (longitude + 180) / 360,
655
- y: (90 - latitude) / 180
656
- };
657
- }
658
-
659
- _loadBoundingBoxData(minX, minY, maxX, maxY) {
660
- // console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY)
661
- const gl = this.gl;
662
-
663
- const bboxMatrix = new Float32Array([
664
- maxX - minX, 0, 0,
665
- 0, maxY - minY, 0,
666
- minX, minY, 1
667
- ])
668
-
669
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
670
- gl.useProgram(this.drawSphereProgram.program);
671
- gl.uniformMatrix3fv(this.drawSphereProgram.u_bbox_matrix, false, bboxMatrix);
672
- gl.useProgram(this.drawFlatProgram.program);
673
- gl.uniformMatrix3fv(this.drawFlatProgram.u_bbox_matrix, false, bboxMatrix);
674
- gl.useProgram(currentProgram);
675
-
676
- }
677
-
678
- // When the screen is moved, the particles are reset to random positions.
679
- // During movement plugin should not draw the particles.
680
-
681
- _doDraw() {
682
- const globe = this.globe;
683
- if (this.windData === null) {
684
- return false;
685
- }
686
- if (globe.api_IsScreenMoving() || this._lastLOD !== globe.api_GetCurrentLODWithDecimal()) {
687
- if (!this._screenMoved) {
688
- this._screenMoved = true;
689
- }
690
- this._lastLOD = globe.api_GetCurrentLODWithDecimal();
691
- return false;
692
- } else {
693
- if (this._screenMoved) {
694
- this._loadSpeedFactor();
695
- this.resize();
696
- this._screenMoved = false;
697
- }
698
- return true;
699
- }
700
- }
701
-
702
-
703
- _draw() {
704
- const gl = this.gl;
705
- this._drawScreen();
706
- this._updateParticles();
707
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
708
- }
709
-
710
-
711
- // globe calls `draw3D` method on each frame
712
- draw3D(projMatrix, modelviewMatrix, transPos) {
713
- const gl = this.gl;
714
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
715
- this.transPos.set([transPos.x, transPos.y, transPos.z], 0);
716
- this.projMatrix = projMatrix;
717
- this.modelviewMatrix = modelviewMatrix;
718
-
719
- gl.activeTexture(gl.TEXTURE0);
720
- if (this._doDraw()) {
721
- const depthTest = gl.isEnabled(gl.DEPTH_TEST);
722
- if (depthTest) gl.disable(gl.DEPTH_TEST);
723
- // if (gl.disable(gl.STENCIL_TEST); //
724
- this._draw();
725
- if (depthTest) gl.enable(gl.DEPTH_TEST);
726
-
727
- }
728
-
729
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
730
-
731
- // test visuals
732
- // gl.viewport(0, 0, 100, 100);
733
- // this._drawTexture(this.windTexture, 1.0);
734
- // gl.viewport(0, 100, 100, 100);
735
- // this._drawTexture(this.particleStateTexture0, 1.0);
736
- // gl.viewport(0, 200, 100, 100);
737
- // this._drawTexture(this.colorRampTexture, 1.0);
738
-
739
- this._resetMachineStates();
740
- this.globe.DrawRender();
741
- }
742
-
743
- _drawScreen() {
744
- const { gl, globe } = this;
745
-
746
- util.bindTexture(gl, this.windTexture, 0);
747
- util.bindTexture(gl, this.particleStateTexture0, 1);
748
-
749
- // draw the screen into a temporary framebuffer to retain it as the background on the next frame
750
- util.bindFramebuffer(gl, this.framebuffer, this.screenTexture);
751
- gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
752
- gl.enable(gl.BLEND);
753
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); // non-premultiplied alpha
754
- this._drawTexture(this.backgroundTexture, this._fadeOpacity);
755
-
756
- this._drawParticles();
757
-
758
- util.bindFramebuffer(gl, null);
759
- this._drawTexture(this.screenTexture, 1.0);
760
- gl.disable(gl.BLEND);
761
- // save the current screen as the background for the next frame
762
- const temp = this.backgroundTexture;
763
- this.backgroundTexture = this.screenTexture;
764
- this.screenTexture = temp;
765
-
766
- }
767
-
768
-
769
- _drawTexture(texture, opacity) {
770
- const gl = this.gl;
771
- const program = this.screenProgram;
772
- gl.useProgram(program.program);
773
-
774
- util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
775
- util.bindTexture(gl, texture, 2);
776
- gl.uniform1i(program.u_screen, 2);
777
- gl.uniform1f(program.u_opacity, opacity);
778
-
779
- gl.drawArrays(gl.TRIANGLES, 0, 6);
780
- }
781
-
782
- _loadRampMax() {
783
- const { gl } = this;
784
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
785
- // console.log("load ramp max", this._rampMax);
786
- gl.useProgram(this.drawSphereProgram.program);
787
- gl.uniform1f(this.drawSphereProgram.u_color_ramp_max, this._rampMax);
788
- gl.useProgram(this.drawFlatProgram.program);
789
- gl.uniform1f(this.drawFlatProgram.u_color_ramp_max, this._rampMax);
790
- gl.useProgram(currentProgram);
791
- }
792
-
793
-
794
- _drawParticlesSphere() {
795
-
796
- const { gl, projMatrix, modelviewMatrix, transPos } = this;
797
- const program = this.drawSphereProgram;
798
- gl.useProgram(program.program);
799
-
800
- util.bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
801
- util.bindTexture(gl, this.colorRampTexture, 2);
802
-
803
- gl.uniform1i(program.u_wind, 0);
804
- gl.uniform1i(program.u_particles, 1);
805
- gl.uniform1i(program.u_color_ramp, 2);
806
-
807
- gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
808
- gl.uniformMatrix4fv(program.uModelViewMatrix, false, modelviewMatrix);
809
- gl.uniform3fv(program.uTranslate, transPos);
810
-
811
- gl.drawArrays(gl.POINTS, 0, this._numParticles);
812
- }
813
-
814
-
815
- _drawParticlesFlat() {
816
- const { gl, transPos, projMatrix, globe } = this;
817
- const program = this.drawFlatProgram;
818
- gl.useProgram(program.program);
819
-
820
- util.bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
821
- util.bindTexture(gl, this.colorRampTexture, 2);
822
-
823
- gl.uniform1i(program.u_wind, 0);
824
- gl.uniform1i(program.u_particles, 1);
825
- gl.uniform1i(program.u_color_ramp, 2);
826
-
827
- gl.uniform2f(program.u_scrWH, globe.api_ScrW(), globe.api_ScrH());
828
- const { width, height } = globe.api_GetCurrentWorldWH();
829
- gl.uniform2f(program.u_mapWH, width, height);
830
-
831
- gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
832
- gl.uniform3fv(program.uTranslate, transPos);
833
-
834
- gl.drawArrays(gl.POINTS, 0, this._numParticles);
835
- }
836
-
837
- // globe calls `setGeometry` method on map projection change. FLAT or SPHERE
838
-
839
- setGeometry() {
840
- if (this.windData === null) {
841
- return;
842
- }
843
- const { globe, gl } = this;
844
- const geometry = globe.api_GetCurrentGeometry()
845
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
846
- if (geometry === globe.api_GeometryTypes().SPHERE) {
847
- this._drawParticles = this._drawParticlesSphere;
848
- gl.useProgram(this.drawSphereProgram.program);
849
- gl.uniform2f(this.drawSphereProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
850
- gl.uniform2f(this.drawSphereProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
851
- } else if (geometry === globe.api_GeometryTypes().FLAT) {
852
- this._drawParticles = this._drawParticlesFlat;
853
- gl.useProgram(this.drawFlatProgram.program);
854
- gl.uniform2f(this.drawFlatProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
855
- gl.uniform2f(this.drawFlatProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
856
- } else {
857
- alert("Geometry is not supported");
858
- }
859
- gl.useProgram(currentProgram);
860
- this.resize();
861
- }
862
-
863
- _updateParticles() {
864
- const gl = this.gl;
865
- const program = this.updateProgram;
866
- gl.useProgram(program.program);
867
- gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
868
-
869
- util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
870
-
871
- gl.uniform1i(program.u_wind, 0);
872
- gl.uniform1i(program.u_particles, 1);
873
-
874
- util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
875
-
876
- gl.uniform1f(program.u_rand_seed, Math.random());
877
-
878
- util.bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
879
-
880
- gl.drawArrays(gl.TRIANGLES, 0, 6);
881
-
882
- // swap the particle state textures so the new one becomes the current one
883
- const temp = this.particleStateTexture0;
884
- this.particleStateTexture0 = this.particleStateTexture1;
885
- this.particleStateTexture1 = temp;
886
- }
887
-
888
- _resetMachineStates() {
889
- const { gl, globe } = this;
890
- // gl.disable(gl.DEPTH_TEST);
891
- // gl.disable(gl.STENCIL_TEST);
892
- gl.activeTexture(gl.TEXTURE0);
893
- gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
894
- }
895
-
896
-
897
- _loadHeight() {
898
- const { gl, drawSphereProgram } = this;
899
- if (gl == null) return;
900
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
901
- gl.useProgram(drawSphereProgram.program);
902
- gl.uniform1f(drawSphereProgram.u_height, this._height);
903
- gl.useProgram(currentProgram);
904
- }
905
-
906
-
907
- _loadMinMaxSpeed() {
908
- const { gl, drawSphereProgram, drawFlatProgram } = this;
909
- if (gl == null) return;
910
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
911
- gl.useProgram(drawSphereProgram.program);
912
- gl.uniform1f(drawSphereProgram.u_min_speed, this._minSpeed);
913
- gl.uniform1f(drawSphereProgram.u_max_speed, this._maxSpeed);
914
- gl.useProgram(drawFlatProgram.program);
915
- gl.uniform1f(drawFlatProgram.u_min_speed, this._minSpeed);
916
- gl.uniform1f(drawFlatProgram.u_max_speed, this._maxSpeed);
917
- gl.useProgram(currentProgram);
918
- }
919
-
920
- _loadFadeOpacity() {
921
- const { gl, screenProgram } = this;
922
- if (gl == null) {
923
- return;
924
- }
925
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
926
- gl.useProgram(screenProgram.program);
927
- gl.uniform1f(screenProgram.u_opacity, this._fadeOpacity);
928
- gl.useProgram(currentProgram);
929
-
930
- }
931
-
932
- _loadSpeedFactor() {
933
- const { gl, globe, updateProgram } = this;
934
- if (gl == null) {
935
- return;
936
- }
937
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
938
- gl.useProgram(updateProgram.program);
939
- gl.uniform1f(updateProgram.u_speed_factor, this._speedFactor / Math.ceil(Math.sqrt(globe.api_GetCurrentLOD())));
940
- gl.useProgram(currentProgram);
941
- }
942
-
943
- _loadDropRate() {
944
- const { gl, updateProgram } = this;
945
- if (gl == null) {
946
- return;
947
- }
948
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
949
- gl.useProgram(updateProgram.program);
950
- gl.uniform1f(updateProgram.u_drop_rate, this._dropRate);
951
- gl.useProgram(currentProgram);
952
- }
953
-
954
- _loadDropRateBump() {
955
- const { gl, updateProgram } = this;
956
- if (gl == null) {
957
- return;
958
- }
959
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
960
- gl.useProgram(updateProgram.program);
961
- gl.uniform1f(updateProgram.u_drop_rate_bump, this._dropRateBump);
962
- gl.useProgram(currentProgram);
963
- }
964
-
965
-
966
- _loadBaseOpacity() {
967
- const { gl, drawSphereProgram, drawFlatProgram } = this;
968
- if (gl == null) {
969
- return;
970
- }
971
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
972
- gl.useProgram(drawSphereProgram.program);
973
- gl.uniform1f(drawSphereProgram.u_base_opacity, this._baseOpacity);
974
- gl.useProgram(drawFlatProgram.program);
975
- gl.uniform1f(drawFlatProgram.u_base_opacity, this._baseOpacity);
976
- gl.useProgram(currentProgram);
977
- }
978
-
979
-
980
- _loadPointSize() {
981
- const { gl, drawSphereProgram, drawFlatProgram } = this;
982
- if (gl == null) {
983
- return;
984
- }
985
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
986
- gl.useProgram(drawSphereProgram.program);
987
- gl.uniform1f(drawSphereProgram.u_point_size, this._pointSize);
988
- gl.useProgram(drawFlatProgram.program);
989
- gl.uniform1f(drawFlatProgram.u_point_size, this._pointSize);
990
- gl.useProgram(currentProgram);
991
- }
992
-
993
-
994
- // globe plugin init methodu
995
- init(globe, gl) {
996
- // console.log("init wind plugin")
997
- this.globe = globe;
998
- this.gl = gl;
999
-
1000
- this.drawSphereProgram = util.createProgramWrapper(gl, drawSphereVert, drawFrag);
1001
- this.screenProgram = util.createProgramWrapper(gl, quadVert, screenFrag);
1002
- this.updateProgram = util.createProgramWrapper(gl, quadVert, updateFrag);
1003
-
1004
- this.drawFlatProgram = util.createProgramWrapper(gl, drawFlatVert, drawFrag);
1005
- this.quadBuffer = util.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
1006
- this.framebuffer = gl.createFramebuffer();
1007
-
1008
- this._loadFadeOpacity();
1009
- this._loadSpeedFactor();
1010
- this._loadDropRate();
1011
- this._loadDropRateBump();
1012
- this._loadBaseOpacity();
1013
- this._loadPointSize();
1014
- this._loadMinMaxSpeed();
1015
- this._loadHeight();
1016
-
1017
-
1018
- if (this._legendData != null) {
1019
- this.setLegend(this._legendData);
1020
- }
1021
- this.numParticles = this._numParticles;
1022
- this.resize();
1023
- }
1024
-
1025
- resize(a, b) {
1026
- const { gl, globe } = this;
1027
-
1028
- const emptyPixels = new Uint8Array(globe.api_ScrW() * globe.api_ScrH() * 4);
1029
- // screen textures to hold the drawn screen for the previous and the current frame
1030
- this.backgroundTexture = util.createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
1031
- this.screenTexture = util.createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
1032
- gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
1033
-
1034
- }
1035
-
1036
-
1037
- // globe calls this `free` on plugin object unregistration
1038
-
1039
- free() {
1040
- const gl = this.gl;
1041
- gl.deleteBuffer(this.quadBuffer);
1042
- gl.deleteFramebuffer(this.framebuffer);
1043
- gl.deleteTexture(this.backgroundTexture);
1044
- gl.deleteTexture(this.screenTexture);
1045
- gl.deleteTexture(this.particleStateTexture0);
1046
- gl.deleteTexture(this.particleStateTexture1);
1047
- gl.deleteTexture(this.windTexture);
1048
- gl.deleteTexture(this.colorRampTexture);
1049
- gl.deleteProgram(this.drawSphereProgram.program);
1050
- gl.deleteProgram(this.screenProgram.program);
1051
- gl.deleteProgram(this.updateProgram.program);
1052
- gl.deleteProgram(this.drawFlatProgram.program);
1053
- gl.deleteBuffer(this.particleIndexBuffer);
1054
-
1055
- }
1056
- }
1057
-
324
+ }`;
325
+ const defaultRampColors = [
326
+ [0.0, '#5e4fa2'],
327
+ [0.08, '#3288bd'],
328
+ [0.2, '#66c2a5'],
329
+ [0.3, '#abdda4'],
330
+ [0.4, '#e6f598'],
331
+ [0.5, '#fee08b'],
332
+ [0.6, '#fdae61'],
333
+ [0.7, '#f46d43'],
334
+ [1.0, '#d53e4f']
335
+ ];
336
+ const windyLegendData = {
337
+ "thresholds": [0, 3, 3, 5, 5, 7, 10, 10, 13, 15, 15, 17, 20, 20, 25, 25, 30],
338
+ // 0 5 10 20 30 40 60
339
+ // "thresholds": [0, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 40, 60],
340
+ "values": [
341
+ "#6271B8",
342
+ "#6271B8",
343
+ "#6271B8",
344
+ "#6271B8",
345
+ "#3D6EA3",
346
+ "#4A94AA",
347
+ "#4A9294",
348
+ "#4D8E7C",
349
+ "#4CA44C",
350
+ "#67A436",
351
+ "#A28740",
352
+ "#A26D5C",
353
+ "#8D3F5C",
354
+ "#974B91",
355
+ "#5F64A0",
356
+ "#5B88A1",
357
+ "#5B88A1"
358
+ ]
359
+ };
360
+ class WindPlugin {
361
+ /**
362
+ * @param {String} id
363
+ * @param {Object} windDataMeta
364
+ * @param {number} windDataMeta.width - image width
365
+ * @param {number} windDataMeta.height - image height
366
+ * @param {Array} windDataMeta.bbox - bounding box [minLon, minLat, maxLon, maxLat]
367
+ * @param {Object} options
368
+ * @param {number} options.fadeOpacity - how fast the particle trails fade on each frame | between 0 - 1 | default 0.746
369
+ * @param {number} options.speedFactor - how fast the particles move | between 0 - 1 | default 0.6
370
+ * @param {number} options.dropRate - how often the particles move to a random place | between 0 - 1 | default 0.007
371
+ * @param {number} options.dropRateBump - drop rate increase relative to individual particle speed
372
+ * @param {number} options.baseOpacity - opacity of drawn particle trails | between 0 - 1 | default 1.0
373
+ * @param {number} options.pointSize - draw size of each particle | positive number | default 2.0
374
+ * @param {number} options.minSpeed - minimum speed value | positive number | default 0.0
375
+ * @param {number} options.maxSpeed - maximum speed value | positive number | default 1000.0
376
+ * @param {number} options.height - height of the particles | number | default 0.0
377
+ * @param {number} numParticles - number of particles | positive integer
378
+ * @param {LegendData} options.legendData - legend data
379
+ */
380
+ 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 } = {}) {
381
+ this.id = id;
382
+ this._windDataMeta = windDataMeta;
383
+ this.globe = null;
384
+ this.gl = null;
385
+ this._screenMoved = false;
386
+ this.projMatrix = null;
387
+ this.modelviewMatrix = null;
388
+ this.transPos = new Float32Array([0, 0, 0]);
389
+ this.windData = null;
390
+ this._fadeOpacity = fadeOpacity;
391
+ this._speedFactor = speedFactor;
392
+ this._dropRate = dropRate;
393
+ this._dropRateBump = dropRateBump;
394
+ this._baseOpacity = baseOpacity;
395
+ this._pointSize = pointSize;
396
+ this._minSpeed = minSpeed;
397
+ this._maxSpeed = maxSpeed;
398
+ this._height = height;
399
+ this._numParticles = numParticles;
400
+ this._legendData = legendData;
401
+ this.lastdatas = [[], [], { x: 0, y: 0, z: 0 }];
402
+ this._drawParticles = this._drawParticlesSphere;
403
+ this._lastLOD = 0;
404
+ }
405
+ // Uniforms are loaded once, on initiation and when they are changed.
406
+ set height(value) {
407
+ this._height = value;
408
+ this._loadHeight();
409
+ }
410
+ set minSpeed(value) {
411
+ this._minSpeed = value;
412
+ this._loadMinMaxSpeed();
413
+ }
414
+ set maxSpeed(value) {
415
+ this._maxSpeed = value;
416
+ this._loadMinMaxSpeed();
417
+ }
418
+ set fadeOpacity(value) {
419
+ this._fadeOpacity = value;
420
+ this._loadFadeOpacity();
421
+ }
422
+ set speedFactor(value) {
423
+ this._speedFactor = value;
424
+ this._loadSpeedFactor();
425
+ }
426
+ set dropRate(value) {
427
+ this._dropRate = value;
428
+ this._loadDropRate();
429
+ }
430
+ set dropRateBump(value) {
431
+ this._dropRateBump = value;
432
+ this._loadDropRateBump();
433
+ }
434
+ set baseOpacity(value) {
435
+ this._baseOpacity = value;
436
+ this._loadBaseOpacity();
437
+ }
438
+ set pointSize(value) {
439
+ this._pointSize = value;
440
+ this._loadPointSize();
441
+ }
442
+ // Color ramp methods.
443
+ // Color ramp is used to colorize the particles according to their speed.
444
+ // Legend max value is used to normalize the speed values.
445
+ setColorRamp(colors) {
446
+ // lookup texture for colorizing the particles according to their speed
447
+ if (this.gl == null) {
448
+ return;
449
+ }
450
+ this.colorRampTexture = util.createTexture(this.gl, this.gl.LINEAR, util.getColorRamp(colors), 16, 16);
451
+ }
452
+ setColorRampDefault() {
453
+ const { uMax, uMin, vMax, vMin } = this.windData;
454
+ const maxSpeed = Math.sqrt(uMax * uMax + vMax * vMax);
455
+ const minSpeed = Math.sqrt(uMin * uMin + vMin * vMin);
456
+ // console.log("maxSpeed", maxSpeed, "minSpeed", minSpeed);
457
+ this._rampMax = maxSpeed > minSpeed ? maxSpeed : minSpeed;
458
+ this._loadRampMax();
459
+ this.setColorRamp(defaultRampColors);
460
+ }
461
+ /**
462
+ *
463
+ * @param {*} legendData
464
+ * @param {Array} legendData.thresholds - list of integers
465
+ * @param {Array} legendData.values - list of colors in hex format like #ff0000 (alpha is not included)
466
+ *
467
+ */
468
+ setLegend(legendData) {
469
+ const { gl } = this;
470
+ if (gl === null) {
471
+ throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
472
+ }
473
+ const { thresholds, values } = legendData;
474
+ if (thresholds.length === 0 || values.length === 0) {
475
+ return;
476
+ }
477
+ thresholds.push(thresholds[thresholds.length - 1]);
478
+ values.push(values[values.length - 1]);
479
+ const maxVelocity = thresholds[thresholds.length - 1];
480
+ const colors = [];
481
+ for (let i = 0; i < thresholds.length; i++) {
482
+ colors.push([
483
+ thresholds[i] / maxVelocity,
484
+ values[i]
485
+ ]);
486
+ }
487
+ const colorRamp = util.getColorRamp(colors);
488
+ this.colorRampTexture = util.createTexture(gl, gl.LINEAR, colorRamp, 16, 16);
489
+ this._rampMax = maxVelocity;
490
+ this._loadRampMax();
491
+ }
492
+ // particle coordinates are encoded into RGBA texture
493
+ set numParticles(numParticles) {
494
+ const gl = this.gl;
495
+ // we create a square texture where each pixel will hold a particle position encoded as RGBA
496
+ const particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(numParticles));
497
+ this._numParticles = particleRes * particleRes;
498
+ const particleState = new Uint8Array(this._numParticles * 4);
499
+ for (let i = 0; i < particleState.length; i++) {
500
+ particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
501
+ }
502
+ // textures to hold the particle state for the current and the next frame
503
+ this.particleStateTexture0 = util.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
504
+ this.particleStateTexture1 = util.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
505
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
506
+ gl.useProgram(this.updateProgram.program);
507
+ gl.uniform1f(this.updateProgram.u_wind_res, this.particleStateResolution);
508
+ gl.useProgram(this.drawSphereProgram.program);
509
+ gl.uniform1f(this.drawSphereProgram.u_particles_res, this.particleStateResolution);
510
+ gl.useProgram(this.drawFlatProgram.program);
511
+ gl.uniform1f(this.drawFlatProgram.u_particles_res, this.particleStateResolution);
512
+ gl.useProgram(currentProgram);
513
+ // console.log("numParticles", this._numParticles);
514
+ const particleIndices = new Float32Array(this._numParticles);
515
+ for (let i = 0; i < this._numParticles; i++)
516
+ particleIndices[i] = i;
517
+ this.particleIndexBuffer = util.createBuffer(gl, particleIndices);
518
+ }
519
+ get numParticles() {
520
+ return this._numParticles;
521
+ }
522
+ // Vector field texture is used to calculate the particle movement.
523
+ /**
524
+ * @param {Object} windData
525
+ * @param {HTMLImageElement} windData.image - image element
526
+
527
+ * @param {number} windData.uMin - minimum u value
528
+ * @param {number} windData.vMin - minimum v value
529
+ * @param {number} windData.uMax - maximum u value
530
+ * @param {number} windData.vMax - maximum v value
531
+ */
532
+ setWind(windData) {
533
+ if (windData === null) {
534
+ return;
535
+ }
536
+ const windDataMeta = this._windDataMeta;
537
+ const gl = this.gl;
538
+ this.windData = windData;
539
+ this.windTexture = util.createTexture(gl, gl.LINEAR, windData.image);
540
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
541
+ gl.useProgram(this.updateProgram.program);
542
+ gl.uniform2f(this.updateProgram.u_wind_res, windDataMeta.width, windDataMeta.height);
543
+ gl.uniform2f(this.updateProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
544
+ gl.uniform2f(this.updateProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
545
+ this.setGeometry();
546
+ const minXY = this._latLongToPixelXY(windDataMeta.bbox[1], windDataMeta.bbox[0]);
547
+ const maxXY = this._latLongToPixelXY(windDataMeta.bbox[3], windDataMeta.bbox[2]);
548
+ this._loadBoundingBoxData(minXY.x, minXY.y, maxXY.x, maxXY.y);
549
+ gl.useProgram(currentProgram);
550
+ this._setCoorcinatesDataCalculatorData();
551
+ this.resize();
552
+ }
553
+ // Vector field texture is used to calculate the particle movement.
554
+ /**
555
+ * @param {Object} windData
556
+ * @param {BaseInt64} windData.image - image element
557
+ * @param {number} windData.width - image width
558
+ * @param {number} windData.height - image height
559
+ * @param {number} windData.uMin - minimum u value
560
+ * @param {number} windData.vMin - minimum v value
561
+ * @param {number} windData.uMax - maximum u value
562
+ * @param {number} windData.vMax - maximum v value
563
+ * @param {Array} windData.bbox - bounding box [minLon, minLat, maxLon, maxLat]
564
+ */
565
+ setWindDataWithImageBase64(windData) {
566
+ const image = util.createImageFromBase64(windData.image);
567
+ image.onload = () => {
568
+ windData.image = image;
569
+ this.setWind(windData);
570
+ };
571
+ }
572
+ getPointCoordinatesDataCalculator() {
573
+ if (!this.coordinatesDataCalculator)
574
+ this._createPointCoordinatesDataCalculator();
575
+ return this.coordinatesDataCalculator;
576
+ }
577
+ _createPointCoordinatesDataCalculator() {
578
+ const { bbox, width, height } = this._windDataMeta;
579
+ this.coordinatesDataCalculator = new util_1.PointCoordinatesDataCalculator(bbox, width, height);
580
+ this._setCoorcinatesDataCalculatorData();
581
+ }
582
+ _setCoorcinatesDataCalculatorData() {
583
+ if (!this.windData || !this.coordinatesDataCalculator) {
584
+ return;
585
+ }
586
+ const magnitude = (0, imagetovectorfieldandmagnitude_1.default)(this.windData);
587
+ this.coordinatesDataCalculator.updateData(0, magnitude, magnitude);
588
+ }
589
+ // -----------------------------------------------
590
+ // --- inner methods ---
591
+ // -----------------------------------------------
592
+ _latLongToPixelXY(latitude, longitude) {
593
+ return {
594
+ x: (longitude + 180) / 360,
595
+ y: (90 - latitude) / 180
596
+ };
597
+ }
598
+ _loadBoundingBoxData(minX, minY, maxX, maxY) {
599
+ // console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY)
600
+ const gl = this.gl;
601
+ const bboxMatrix = new Float32Array([
602
+ maxX - minX, 0, 0,
603
+ 0, maxY - minY, 0,
604
+ minX, minY, 1
605
+ ]);
606
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
607
+ gl.useProgram(this.drawSphereProgram.program);
608
+ gl.uniformMatrix3fv(this.drawSphereProgram.u_bbox_matrix, false, bboxMatrix);
609
+ gl.useProgram(this.drawFlatProgram.program);
610
+ gl.uniformMatrix3fv(this.drawFlatProgram.u_bbox_matrix, false, bboxMatrix);
611
+ gl.useProgram(currentProgram);
612
+ }
613
+ // When the screen is moved, the particles are reset to random positions.
614
+ // During movement plugin should not draw the particles.
615
+ _doDraw() {
616
+ const globe = this.globe;
617
+ if (this.windData === null) {
618
+ return false;
619
+ }
620
+ if (globe.api_IsScreenMoving() || this._lastLOD !== globe.api_GetCurrentLODWithDecimal()) {
621
+ if (!this._screenMoved) {
622
+ this._screenMoved = true;
623
+ }
624
+ this._lastLOD = globe.api_GetCurrentLODWithDecimal();
625
+ return false;
626
+ }
627
+ else {
628
+ if (this._screenMoved) {
629
+ this._loadSpeedFactor();
630
+ this.resize();
631
+ this._screenMoved = false;
632
+ }
633
+ return true;
634
+ }
635
+ }
636
+ _draw() {
637
+ const gl = this.gl;
638
+ this._drawScreen();
639
+ this._updateParticles();
640
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
641
+ }
642
+ // globe calls `draw3D` method on each frame
643
+ draw3D(projMatrix, modelviewMatrix, transPos) {
644
+ const gl = this.gl;
645
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
646
+ this.transPos.set([transPos.x, transPos.y, transPos.z], 0);
647
+ this.projMatrix = projMatrix;
648
+ this.modelviewMatrix = modelviewMatrix;
649
+ gl.activeTexture(gl.TEXTURE0);
650
+ if (this._doDraw()) {
651
+ const depthTest = gl.isEnabled(gl.DEPTH_TEST);
652
+ if (depthTest)
653
+ gl.disable(gl.DEPTH_TEST);
654
+ // if (gl.disable(gl.STENCIL_TEST); //
655
+ this._draw();
656
+ if (depthTest)
657
+ gl.enable(gl.DEPTH_TEST);
658
+ }
659
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
660
+ // test visuals
661
+ // gl.viewport(0, 0, 100, 100);
662
+ // this._drawTexture(this.windTexture, 1.0);
663
+ // gl.viewport(0, 100, 100, 100);
664
+ // this._drawTexture(this.particleStateTexture0, 1.0);
665
+ // gl.viewport(0, 200, 100, 100);
666
+ // this._drawTexture(this.colorRampTexture, 1.0);
667
+ this._resetMachineStates();
668
+ this.globe.DrawRender();
669
+ }
670
+ _drawScreen() {
671
+ const { gl, globe } = this;
672
+ util.bindTexture(gl, this.windTexture, 0);
673
+ util.bindTexture(gl, this.particleStateTexture0, 1);
674
+ // draw the screen into a temporary framebuffer to retain it as the background on the next frame
675
+ util.bindFramebuffer(gl, this.framebuffer, this.screenTexture);
676
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
677
+ gl.enable(gl.BLEND);
678
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); // non-premultiplied alpha
679
+ this._drawTexture(this.backgroundTexture, this._fadeOpacity);
680
+ this._drawParticles();
681
+ util.bindFramebuffer(gl, null);
682
+ this._drawTexture(this.screenTexture, 1.0);
683
+ gl.disable(gl.BLEND);
684
+ // save the current screen as the background for the next frame
685
+ const temp = this.backgroundTexture;
686
+ this.backgroundTexture = this.screenTexture;
687
+ this.screenTexture = temp;
688
+ }
689
+ _drawTexture(texture, opacity) {
690
+ const gl = this.gl;
691
+ const program = this.screenProgram;
692
+ gl.useProgram(program.program);
693
+ util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
694
+ util.bindTexture(gl, texture, 2);
695
+ gl.uniform1i(program.u_screen, 2);
696
+ gl.uniform1f(program.u_opacity, opacity);
697
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
698
+ }
699
+ _loadRampMax() {
700
+ const { gl } = this;
701
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
702
+ // console.log("load ramp max", this._rampMax);
703
+ gl.useProgram(this.drawSphereProgram.program);
704
+ gl.uniform1f(this.drawSphereProgram.u_color_ramp_max, this._rampMax);
705
+ gl.useProgram(this.drawFlatProgram.program);
706
+ gl.uniform1f(this.drawFlatProgram.u_color_ramp_max, this._rampMax);
707
+ gl.useProgram(currentProgram);
708
+ }
709
+ _drawParticlesSphere() {
710
+ const { gl, projMatrix, modelviewMatrix, transPos } = this;
711
+ const program = this.drawSphereProgram;
712
+ gl.useProgram(program.program);
713
+ util.bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
714
+ util.bindTexture(gl, this.colorRampTexture, 2);
715
+ gl.uniform1i(program.u_wind, 0);
716
+ gl.uniform1i(program.u_particles, 1);
717
+ gl.uniform1i(program.u_color_ramp, 2);
718
+ gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
719
+ gl.uniformMatrix4fv(program.uModelViewMatrix, false, modelviewMatrix);
720
+ gl.uniform3fv(program.uTranslate, transPos);
721
+ gl.drawArrays(gl.POINTS, 0, this._numParticles);
722
+ }
723
+ _drawParticlesFlat() {
724
+ const { gl, transPos, projMatrix, globe } = this;
725
+ const program = this.drawFlatProgram;
726
+ gl.useProgram(program.program);
727
+ util.bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
728
+ util.bindTexture(gl, this.colorRampTexture, 2);
729
+ gl.uniform1i(program.u_wind, 0);
730
+ gl.uniform1i(program.u_particles, 1);
731
+ gl.uniform1i(program.u_color_ramp, 2);
732
+ gl.uniform2f(program.u_scrWH, globe.api_ScrW(), globe.api_ScrH());
733
+ const { width, height } = globe.api_GetCurrentWorldWH();
734
+ gl.uniform2f(program.u_mapWH, width, height);
735
+ gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
736
+ gl.uniform3fv(program.uTranslate, transPos);
737
+ gl.drawArrays(gl.POINTS, 0, this._numParticles);
738
+ }
739
+ // globe calls `setGeometry` method on map projection change. FLAT or SPHERE
740
+ setGeometry() {
741
+ if (this.windData === null) {
742
+ return;
743
+ }
744
+ const { globe, gl } = this;
745
+ const geometry = globe.api_GetCurrentGeometry();
746
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
747
+ if (geometry === globe.api_GeometryTypes().SPHERE) {
748
+ this._drawParticles = this._drawParticlesSphere;
749
+ gl.useProgram(this.drawSphereProgram.program);
750
+ gl.uniform2f(this.drawSphereProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
751
+ gl.uniform2f(this.drawSphereProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
752
+ }
753
+ else if (geometry === globe.api_GeometryTypes().FLAT) {
754
+ this._drawParticles = this._drawParticlesFlat;
755
+ gl.useProgram(this.drawFlatProgram.program);
756
+ gl.uniform2f(this.drawFlatProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
757
+ gl.uniform2f(this.drawFlatProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
758
+ }
759
+ else {
760
+ alert("Geometry is not supported");
761
+ }
762
+ gl.useProgram(currentProgram);
763
+ this.resize();
764
+ }
765
+ _updateParticles() {
766
+ const gl = this.gl;
767
+ const program = this.updateProgram;
768
+ gl.useProgram(program.program);
769
+ gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
770
+ util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
771
+ gl.uniform1i(program.u_wind, 0);
772
+ gl.uniform1i(program.u_particles, 1);
773
+ util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
774
+ gl.uniform1f(program.u_rand_seed, Math.random());
775
+ util.bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
776
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
777
+ // swap the particle state textures so the new one becomes the current one
778
+ const temp = this.particleStateTexture0;
779
+ this.particleStateTexture0 = this.particleStateTexture1;
780
+ this.particleStateTexture1 = temp;
781
+ }
782
+ _resetMachineStates() {
783
+ const { gl, globe } = this;
784
+ // gl.disable(gl.DEPTH_TEST);
785
+ // gl.disable(gl.STENCIL_TEST);
786
+ gl.activeTexture(gl.TEXTURE0);
787
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
788
+ }
789
+ _loadHeight() {
790
+ const { gl, drawSphereProgram } = this;
791
+ if (gl == null)
792
+ return;
793
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
794
+ gl.useProgram(drawSphereProgram.program);
795
+ gl.uniform1f(drawSphereProgram.u_height, this._height);
796
+ gl.useProgram(currentProgram);
797
+ }
798
+ _loadMinMaxSpeed() {
799
+ const { gl, drawSphereProgram, drawFlatProgram } = this;
800
+ if (gl == null)
801
+ return;
802
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
803
+ gl.useProgram(drawSphereProgram.program);
804
+ gl.uniform1f(drawSphereProgram.u_min_speed, this._minSpeed);
805
+ gl.uniform1f(drawSphereProgram.u_max_speed, this._maxSpeed);
806
+ gl.useProgram(drawFlatProgram.program);
807
+ gl.uniform1f(drawFlatProgram.u_min_speed, this._minSpeed);
808
+ gl.uniform1f(drawFlatProgram.u_max_speed, this._maxSpeed);
809
+ gl.useProgram(currentProgram);
810
+ }
811
+ _loadFadeOpacity() {
812
+ const { gl, screenProgram } = this;
813
+ if (gl == null) {
814
+ return;
815
+ }
816
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
817
+ gl.useProgram(screenProgram.program);
818
+ gl.uniform1f(screenProgram.u_opacity, this._fadeOpacity);
819
+ gl.useProgram(currentProgram);
820
+ }
821
+ _loadSpeedFactor() {
822
+ const { gl, globe, updateProgram } = this;
823
+ if (gl == null) {
824
+ return;
825
+ }
826
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
827
+ gl.useProgram(updateProgram.program);
828
+ gl.uniform1f(updateProgram.u_speed_factor, this._speedFactor / Math.ceil(Math.sqrt(globe.api_GetCurrentLOD())));
829
+ gl.useProgram(currentProgram);
830
+ }
831
+ _loadDropRate() {
832
+ const { gl, 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_drop_rate, this._dropRate);
839
+ gl.useProgram(currentProgram);
840
+ }
841
+ _loadDropRateBump() {
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_bump, this._dropRateBump);
849
+ gl.useProgram(currentProgram);
850
+ }
851
+ _loadBaseOpacity() {
852
+ const { gl, drawSphereProgram, drawFlatProgram } = this;
853
+ if (gl == null) {
854
+ return;
855
+ }
856
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
857
+ gl.useProgram(drawSphereProgram.program);
858
+ gl.uniform1f(drawSphereProgram.u_base_opacity, this._baseOpacity);
859
+ gl.useProgram(drawFlatProgram.program);
860
+ gl.uniform1f(drawFlatProgram.u_base_opacity, this._baseOpacity);
861
+ gl.useProgram(currentProgram);
862
+ }
863
+ _loadPointSize() {
864
+ const { gl, drawSphereProgram, drawFlatProgram } = this;
865
+ if (gl == null) {
866
+ return;
867
+ }
868
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
869
+ gl.useProgram(drawSphereProgram.program);
870
+ gl.uniform1f(drawSphereProgram.u_point_size, this._pointSize);
871
+ gl.useProgram(drawFlatProgram.program);
872
+ gl.uniform1f(drawFlatProgram.u_point_size, this._pointSize);
873
+ gl.useProgram(currentProgram);
874
+ }
875
+ // globe plugin init methodu
876
+ init(globe, gl) {
877
+ // console.log("init wind plugin")
878
+ this.globe = globe;
879
+ this.gl = gl;
880
+ this.drawSphereProgram = util.createProgramWrapper(gl, drawSphereVert, drawFrag);
881
+ this.screenProgram = util.createProgramWrapper(gl, quadVert, screenFrag);
882
+ this.updateProgram = util.createProgramWrapper(gl, quadVert, updateFrag);
883
+ this.drawFlatProgram = util.createProgramWrapper(gl, drawFlatVert, drawFrag);
884
+ this.quadBuffer = util.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
885
+ this.framebuffer = gl.createFramebuffer();
886
+ this._loadFadeOpacity();
887
+ this._loadSpeedFactor();
888
+ this._loadDropRate();
889
+ this._loadDropRateBump();
890
+ this._loadBaseOpacity();
891
+ this._loadPointSize();
892
+ this._loadMinMaxSpeed();
893
+ this._loadHeight();
894
+ if (this._legendData != null) {
895
+ this.setLegend(this._legendData);
896
+ }
897
+ this.numParticles = this._numParticles;
898
+ this.resize();
899
+ }
900
+ resize(a, b) {
901
+ const { gl, globe } = this;
902
+ const emptyPixels = new Uint8Array(globe.api_ScrW() * globe.api_ScrH() * 4);
903
+ // screen textures to hold the drawn screen for the previous and the current frame
904
+ this.backgroundTexture = util.createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
905
+ this.screenTexture = util.createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
906
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
907
+ }
908
+ // globe calls this `free` on plugin object unregistration
909
+ free() {
910
+ const gl = this.gl;
911
+ gl.deleteBuffer(this.quadBuffer);
912
+ gl.deleteFramebuffer(this.framebuffer);
913
+ gl.deleteTexture(this.backgroundTexture);
914
+ gl.deleteTexture(this.screenTexture);
915
+ gl.deleteTexture(this.particleStateTexture0);
916
+ gl.deleteTexture(this.particleStateTexture1);
917
+ gl.deleteTexture(this.windTexture);
918
+ gl.deleteTexture(this.colorRampTexture);
919
+ gl.deleteProgram(this.drawSphereProgram.program);
920
+ gl.deleteProgram(this.screenProgram.program);
921
+ gl.deleteProgram(this.updateProgram.program);
922
+ gl.deleteProgram(this.drawFlatProgram.program);
923
+ gl.deleteBuffer(this.particleIndexBuffer);
924
+ }
925
+ }
926
+ exports.default = WindPlugin;