@pirireis/webglobeplugins 0.9.9 → 0.9.11

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 (212) hide show
  1. package/Math/angle-calculation.js +15 -0
  2. package/Math/arc.js +65 -0
  3. package/Math/bounds/line-bbox.js +190 -0
  4. package/Math/constants.js +9 -0
  5. package/Math/frustum/camera.js +24 -0
  6. package/Math/frustum/from-globeinfo.js +48 -0
  7. package/Math/frustum/types.js +2 -0
  8. package/Math/globe-util/horizon-plane.js +112 -0
  9. package/Math/index.js +1 -0
  10. package/Math/juction/arc-plane.js +83 -0
  11. package/Math/juction/line-sphere.js +25 -0
  12. package/Math/juction/plane-plane.js +58 -0
  13. package/Math/line.js +58 -0
  14. package/Math/matrix4.js +1 -0
  15. package/Math/methods.js +206 -0
  16. package/Math/plane.js +62 -0
  17. package/Math/quaternion.js +108 -0
  18. package/Math/types.js +2 -0
  19. package/Math/utils.js +4 -0
  20. package/Math/vec3.js +129 -0
  21. package/algorithms/search-binary.js +19 -0
  22. package/altitude-locator/adaptors.js +1 -0
  23. package/altitude-locator/draw-subset-obj.js +19 -0
  24. package/altitude-locator/keymethod.js +1 -0
  25. package/altitude-locator/plugin.js +357 -0
  26. package/altitude-locator/types.js +23 -0
  27. package/arrowfield/adaptor.js +15 -0
  28. package/arrowfield/index.js +10 -0
  29. package/arrowfield/plugin.js +89 -0
  30. package/bearing-line/index.js +8 -0
  31. package/bearing-line/plugin.js +474 -0
  32. package/circle-line-chain/chain-list-map.js +211 -0
  33. package/circle-line-chain/init.js +1 -0
  34. package/circle-line-chain/plugin.js +449 -0
  35. package/circle-line-chain/util.js +5 -0
  36. package/compass-rose/compass-rose-padding-flat.js +247 -0
  37. package/compass-rose/compass-text-writer.js +161 -0
  38. package/compass-rose/index.js +7 -0
  39. package/compassrose/compassrose.js +300 -0
  40. package/compassrose/index.js +8 -0
  41. package/globe-types.js +1 -0
  42. package/heatwave/index.js +10 -0
  43. package/heatwave/isobar/objectarraylabels.js +206 -0
  44. package/heatwave/isobar/plugin.js +362 -0
  45. package/heatwave/isobar/quadtreecontours.js +316 -0
  46. package/heatwave/plugins/heatwaveglobeshell.js +224 -0
  47. package/index.js +11 -11
  48. package/jest.config.js +7 -0
  49. package/package.json +4 -4
  50. package/partialrings/buffer-manager.js +113 -0
  51. package/partialrings/index.js +41 -0
  52. package/partialrings/plugin.js +171 -0
  53. package/partialrings/program.js +197 -0
  54. package/pin/pin-object-array.js +308 -0
  55. package/pin/pin-point-totem.js +61 -0
  56. package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +66 -0
  57. package/point-heat-map/index.js +1 -0
  58. package/point-heat-map/plugin-webworker.js +131 -0
  59. package/point-heat-map/point-to-heat-map-flow.js +129 -0
  60. package/point-tracks/key-methods.js +5 -0
  61. package/point-tracks/plugin.js +353 -0
  62. package/programs/arrowfield/index.js +7 -0
  63. package/programs/arrowfield/logic.js +149 -0
  64. package/programs/arrowfield/object.js +68 -0
  65. package/programs/data2legend/density-to-legend.js +77 -0
  66. package/programs/data2legend/point-to-density-texture.js +75 -0
  67. package/programs/float2legendwithratio/index.js +8 -0
  68. package/programs/float2legendwithratio/logic.js +125 -0
  69. package/programs/float2legendwithratio/object.js +113 -0
  70. package/programs/globe-util/is-globe-moved.js +22 -0
  71. package/programs/globeshell/index.js +8 -0
  72. package/programs/globeshell/noise/noises.js +1 -0
  73. package/programs/globeshell/wiggle/index.js +8 -0
  74. package/programs/globeshell/wiggle/logic.js +252 -0
  75. package/programs/globeshell/wiggle/object.js +74 -0
  76. package/programs/helpers/blender/index.js +1 -0
  77. package/programs/helpers/blender/program.js +62 -0
  78. package/programs/helpers/fadeaway/index.js +7 -0
  79. package/programs/helpers/fadeaway/logic.js +50 -0
  80. package/programs/helpers/fadeaway/object.js +21 -0
  81. package/programs/helpers/index.js +8 -0
  82. package/programs/index.js +58 -0
  83. package/programs/interface.js +1 -0
  84. package/programs/line-on-globe/angled-line.js +117 -0
  85. package/programs/line-on-globe/circle-accurate-3d.js +91 -0
  86. package/programs/line-on-globe/circle-accurate-flat.js +158 -0
  87. package/programs/line-on-globe/circle-accurate.js +108 -0
  88. package/programs/line-on-globe/circle.js +102 -0
  89. package/programs/line-on-globe/degree-padding-around-circle-3d.js +109 -0
  90. package/programs/line-on-globe/index.js +1 -0
  91. package/programs/line-on-globe/lines-color-instanced-flat.js +91 -0
  92. package/programs/line-on-globe/linestrip.js +110 -0
  93. package/programs/line-on-globe/naive-accurate-flexible.js +125 -0
  94. package/programs/line-on-globe/to-the-surface.js +82 -0
  95. package/programs/line-on-globe/util.js +8 -0
  96. package/programs/picking/pickable-renderer.js +104 -0
  97. package/programs/point-on-globe/element-globe-surface-glow.js +102 -0
  98. package/programs/point-on-globe/element-point-glow.js +85 -0
  99. package/programs/point-on-globe/square-pixel-point.js +125 -0
  100. package/programs/programcache.js +131 -0
  101. package/programs/rings/distancering/circleflatprogram.js +114 -0
  102. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +358 -0
  103. package/programs/rings/distancering/circlepaddysharedbuffer.js +433 -0
  104. package/programs/rings/distancering/index.js +14 -0
  105. package/programs/rings/distancering/paddyflatprogram.js +119 -0
  106. package/programs/rings/distancering/paddyflatprogram2d.js +121 -0
  107. package/programs/rings/distancering/paddyflatprogram3d.js +119 -0
  108. package/programs/rings/distancering/shader.js +1 -0
  109. package/programs/rings/index.js +17 -0
  110. package/programs/rings/partial-ring/piece-of-pie.js +173 -0
  111. package/programs/totems/camerauniformblock.js +147 -0
  112. package/programs/totems/canvas-webglobe-info.js +102 -0
  113. package/programs/totems/gpu-selection-uniform-block.js +104 -0
  114. package/programs/totems/index.js +40 -0
  115. package/programs/two-d/pixel-circle.js +1 -0
  116. package/programs/two-d/pixel-padding-for-compass.js +101 -0
  117. package/programs/util.js +18 -0
  118. package/programs/vectorfields/index.js +23 -0
  119. package/programs/vectorfields/logics/drawrectangleparticles.js +66 -0
  120. package/programs/vectorfields/logics/index.js +12 -0
  121. package/programs/vectorfields/logics/pixelbased.js +86 -0
  122. package/programs/vectorfields/logics/ubo.js +57 -0
  123. package/programs/vectorfields/pingpongbuffermanager.js +80 -0
  124. package/rangerings/enum.js +5 -0
  125. package/rangerings/index.js +15 -0
  126. package/rangerings/plugin.js +610 -0
  127. package/rangerings/rangeringangletext.js +341 -0
  128. package/rangerings/ring-account.js +134 -0
  129. package/shaders/fragment-toy/firework.js +4 -0
  130. package/shaders/fragment-toy/singularity.js +5 -0
  131. package/shape-on-terrain/arc/naive/plugin.js +252 -0
  132. package/timetracks/adaptors-line-strip.js +82 -0
  133. package/timetracks/adaptors.js +136 -0
  134. package/timetracks/index.js +19 -0
  135. package/timetracks/plugin-line-strip.js +254 -0
  136. package/timetracks/plugin.js +262 -0
  137. package/timetracks/program-line-strip.js +418 -0
  138. package/timetracks/program.js +466 -0
  139. package/timetracks/programpoint-line-strip.js +101 -0
  140. package/timetracks/programpoint.js +101 -0
  141. package/types.js +15 -0
  142. package/util/account/bufferoffsetmanager.js +202 -0
  143. package/util/account/index.js +23 -0
  144. package/util/account/single-attribute-buffer-management/buffer-manager.js +112 -0
  145. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +180 -0
  146. package/util/account/single-attribute-buffer-management/index.js +9 -0
  147. package/util/account/single-attribute-buffer-management/object-store.js +53 -0
  148. package/util/account/single-attribute-buffer-management/types.js +2 -0
  149. package/util/account/util.js +24 -0
  150. package/util/algorithms/index.js +1 -0
  151. package/util/algorithms/search-binary.js +28 -0
  152. package/util/check/get.js +18 -0
  153. package/util/check/index.js +1 -0
  154. package/util/check/typecheck.js +51 -0
  155. package/util/geometry/index.js +53 -0
  156. package/util/gl-util/buffer/attribute-loader.js +81 -0
  157. package/util/gl-util/buffer/index.js +6 -0
  158. package/util/gl-util/buffer/types.js +1 -0
  159. package/util/gl-util/draw-options/methods.js +38 -0
  160. package/util/gl-util/draw-options/types.js +15 -0
  161. package/util/gl-util/uniform-block/manager.js +168 -0
  162. package/util/gl-util/uniform-block/shader.js +1 -0
  163. package/util/gl-util/uniform-block/types.js +8 -0
  164. package/util/heatwavedatamanager/datamanager.js +212 -0
  165. package/util/heatwavedatamanager/index.js +10 -0
  166. package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +125 -0
  167. package/util/heatwavedatamanager/pointcoordsmeta.js +21 -0
  168. package/util/index.js +57 -0
  169. package/util/interpolation/index.js +1 -0
  170. package/util/interpolation/timetrack/index.js +5 -0
  171. package/util/interpolation/timetrack/timetrack-interpolator.js +81 -0
  172. package/util/interpolation/timetrack/web-worker-str.js +5 -0
  173. package/util/interpolation/timetrack/web-worker.js +48 -0
  174. package/util/jshelpers/data-filler.js +20 -0
  175. package/util/jshelpers/equality.js +20 -0
  176. package/util/jshelpers/index.js +37 -0
  177. package/util/jshelpers/timefilters.js +32 -0
  178. package/util/picking/fence.js +46 -0
  179. package/util/picking/picker-displayer.js +145 -0
  180. package/util/programs/draw-texture-on-canvas.js +71 -0
  181. package/util/programs/index.js +17 -0
  182. package/util/programs/shapesonglobe.js +174 -0
  183. package/util/programs/supersampletotextures.js +107 -0
  184. package/util/programs/texturetoglobe.js +132 -0
  185. package/util/shaderfunctions/geometrytransformations.js +45 -0
  186. package/util/shaderfunctions/index.js +18 -0
  187. package/util/shaderfunctions/nodata.js +5 -0
  188. package/util/shaderfunctions/noisefunctions.js +13 -0
  189. package/util/surface-line-data/arc-bboxes.js +25 -0
  190. package/util/surface-line-data/arcs-to-cuts.js +53 -0
  191. package/util/surface-line-data/cut-arc.js +1 -0
  192. package/util/surface-line-data/flow.js +28 -0
  193. package/util/surface-line-data/rbush-manager.js +1 -0
  194. package/util/surface-line-data/types.js +1 -0
  195. package/util/surface-line-data/web-worker.js +1 -0
  196. package/util/webglobe/gldefaultstates.js +7 -0
  197. package/util/webglobe/index.js +18 -0
  198. package/util/webglobe/rasteroverlay.js +80 -0
  199. package/util/webglobjectbuilders.js +393 -0
  200. package/util/webglobjectbuilders1.js +238 -0
  201. package/waveparticles/adaptor.js +18 -0
  202. package/waveparticles/index.js +10 -0
  203. package/waveparticles/plugin.js +271 -0
  204. package/wind/imagetovectorfieldandmagnitude.js +35 -0
  205. package/wind/index.js +14 -0
  206. package/wind/plugin.js +724 -0
  207. package/wind/vectorfieldimage.js +25 -0
  208. package/write-text/attached-text-writer.js +93 -0
  209. package/write-text/context-text.js +105 -0
  210. package/write-text/context-text3.js +160 -0
  211. package/write-text/index.js +5 -0
  212. package/write-text/writer-plugin.js +8 -0
package/wind/plugin.js ADDED
@@ -0,0 +1,724 @@
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
+ var util = __importStar(require("../util"));
43
+ var imagetovectorfieldandmagnitude_1 = __importDefault(require("./imagetovectorfieldandmagnitude"));
44
+ var 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
+ */
74
+ var quadVert = "\nprecision mediump float;\n\nattribute vec2 a_pos;\n\nvarying vec2 v_tex_pos;\n\nvoid main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);\n}";
75
+ var screenFrag = "precision mediump float;\n\nuniform sampler2D u_screen;\nuniform float u_opacity;\n\nvarying vec2 v_tex_pos;\n\nvoid main() {\n vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);\n // a hack to guarantee opacity fade out even with a value close to 1.0\n gl_FragColor = vec4( floor(255.0 * color * u_opacity) / 255.0);\n}\n\n";
76
+ var updateFrag = "\nprecision highp float;\n\nuniform sampler2D u_particles;\nuniform sampler2D u_wind;\nuniform vec2 u_wind_res;\nuniform vec2 u_wind_min;\nuniform vec2 u_wind_max;\nuniform float u_rand_seed;\nuniform float u_speed_factor;\nuniform float u_drop_rate;\nuniform float u_drop_rate_bump;\n\nvarying vec2 v_tex_pos;\n\n// pseudo-random generator\nconst vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);\nfloat rand(const vec2 co) {\n float t = dot(rand_constants.xy, co);\n return fract(sin(t) * (rand_constants.z + t));\n}\n\n// wind speed lookup; use manual bilinear filtering based on 4 adjacent pixels for smooth interpolation\nvec2 lookup_wind(const vec2 uv) {\n // return texture2D(u_wind, uv).rg; // lower-res hardware filtering\n vec2 px = 1.0 / u_wind_res;\n vec2 vc = (floor(uv * u_wind_res)) * px;\n vec2 f = fract(uv * u_wind_res);\n vec2 tl = texture2D(u_wind, vc).rg;\n vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;\n vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;\n vec2 br = texture2D(u_wind, vc + px).rg;\n return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);\n}\n\nvoid main() {\n vec4 color = texture2D(u_particles, v_tex_pos);\n vec2 pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a); // decode particle position from pixel RGBA\n\n if ( texture2D(u_wind, pos).rg == vec2(0.0, 0.0) ) {\n discard;\n }\n\n vec2 velocity = mix(u_wind_min, u_wind_max, lookup_wind(pos));\n float speed_t = length(velocity) / length(u_wind_max);\n\n // take EPSG:4236 distortion into account for calculating where the particle moved\n // float distortion = 1.0; //cos(radians(pos.y * 180.0 - 90.0));\n // vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.0001 * u_speed_factor;\n vec2 offset = vec2(velocity.x, velocity.y) * 0.0001 * u_speed_factor;\n\n // update particle position, wrapping around the date line\n pos = fract(1.0 + pos + offset);\n\n // a random seed to use for the particle drop\n vec2 seed = (pos + v_tex_pos) * u_rand_seed;\n\n // drop rate is a chance a particle will restart at random position, to avoid degeneration\n float drop_rate = u_drop_rate + speed_t * u_drop_rate_bump;\n float drop = step(1.0 - drop_rate, rand(seed));\n\n vec2 random_pos = vec2(\n rand(seed + 1.3),\n rand(seed + 2.1));\n pos = mix(pos, random_pos, drop);\n\n // encode the new particle position back into RGBA\n gl_FragColor = vec4(\n fract(pos * 255.0),\n floor(pos * 255.0) / 255.0);\n}\n";
77
+ var drawFrag = "precision mediump float;\n\nuniform sampler2D u_wind;\nuniform vec2 u_wind_min;\nuniform vec2 u_wind_max;\nuniform sampler2D u_color_ramp;\nuniform float u_color_ramp_max;\nuniform float u_base_opacity;\n\nuniform float u_min_speed;\nuniform float u_max_speed;\n\nvarying vec2 v_particle_pos;\n\nvoid main() {\n \n\n if ( texture2D(u_wind, v_particle_pos).rg == vec2(0.0, 0.0) ) {\n discard;\n }\n vec2 velocity = mix(u_wind_min, u_wind_max, texture2D(u_wind, v_particle_pos).rg);\n float speed = length(velocity);\n if (speed < u_min_speed || speed > u_max_speed) {\n discard;\n }\n if (speed >= u_color_ramp_max) {\n gl_FragColor = texture2D(u_color_ramp, \n vec2( 0.99999 , 0.0001 )) * u_base_opacity;\n return;\n }\n\n float speed_t = speed / u_color_ramp_max; // length(u_wind_max); // \n // color ramp olusturulan method finalde texture ters \u00E7evriliyor. bu y\u00FCzden speed_t 1.0 - speed_t oluyor.\n speed_t = 1.0 - speed_t;\n // color ramp is encoded in a 16.0 x 16.0 texture\n vec2 ramp_pos = vec2(\n fract(16.0 * speed_t),\n floor(16.0 * speed_t) / 16.0);\n\n\n gl_FragColor = texture2D(u_color_ramp, ramp_pos) * u_base_opacity;\n}\n";
78
+ var drawSphereVert = "\nprecision mediump float;\n\nattribute float a_index;\n\nuniform float u_point_size;\nuniform sampler2D u_particles;\nuniform float u_particles_res;\n\nuniform float u_height;\n\nvarying vec2 v_particle_pos;\nvarying float v_z;\n\nuniform mat3 u_bbox_matrix;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform vec3 uTranslate;\n\nconst float PI = 3.141592653589793;\nconst float R = 6378.137;\n\nvec3 cartesian3DPoint( float longRad, float latRad, float height) {\n float radius = R + height;\n float x = radius * sin(latRad) * cos(longRad);\n float y = radius * sin(latRad) * sin(longRad);\n float z = radius * cos(latRad);\n return vec3(\n x, \n y, \n z) ;\n}\n\nvoid main() {\n vec4 color = texture2D(u_particles, vec2(\n fract(a_index / u_particles_res),\n floor(a_index / u_particles_res) / u_particles_res));\n\n v_particle_pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a);\n \n\n if ( v_particle_pos.y < 0.0265 || v_particle_pos.y > 0.9735 ) {\n gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);\n return;\n }\n vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);\n \n\n float xRad = PI * (2.0 * pos.x - 1.0);\n float yRad = pos.y * PI;\n\n pos = cartesian3DPoint(xRad, yRad, u_height);\n gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(pos - uTranslate, 1.0);\n gl_PointSize = u_point_size;\n\n}";
79
+ var drawFlatVert = "\nprecision mediump float;\n\nuniform mat3 u_bbox_matrix;\n\nuniform vec3 uTranslate;\n// uniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nattribute float a_index;\nuniform sampler2D u_particles;\nuniform float u_particles_res;\nuniform float u_point_size;\nuniform vec2 u_mapWH;\nuniform vec2 u_scrWH;\n\nvarying vec2 v_particle_pos;\n\nconst float PI = 3.141592653589793;\nconst float POLE = 20037508.34;\nconst float POLE_BY_PI = POLE / PI;\nconst float HALF_PI = PI / 2.0;\n\n\nvoid main() {\n\n vec4 color = texture2D(u_particles, vec2(\n fract(a_index / u_particles_res),\n floor(a_index / u_particles_res) / u_particles_res));\n\n v_particle_pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a);\n\n if ( v_particle_pos.y < 0.0265 || v_particle_pos.y > 0.9735 ) {\n gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);\n return;\n }\n vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);\n \n float x = (2.0 * pos.x - 1.0);\n float mercator_x = x * POLE;\n float mercator_y = log( tan( ( 1.0 - pos.y ) * HALF_PI ) ) * POLE_BY_PI;\n\n float normalizedX = ( mercator_x - uTranslate.x) / u_mapWH.x;\n float normalizedY = ( mercator_y - uTranslate.y) / u_mapWH.y;\n gl_Position = uProjectionMatrix * vec4(normalizedX * u_scrWH.x, (1.0 - normalizedY) * u_scrWH.y, 0.0, 1.0);\n\n gl_PointSize = u_point_size;\n}";
80
+ var defaultRampColors = [
81
+ [0.0, '#5e4fa2'],
82
+ [0.08, '#3288bd'],
83
+ [0.2, '#66c2a5'],
84
+ [0.3, '#abdda4'],
85
+ [0.4, '#e6f598'],
86
+ [0.5, '#fee08b'],
87
+ [0.6, '#fdae61'],
88
+ [0.7, '#f46d43'],
89
+ [1.0, '#d53e4f']
90
+ ];
91
+ var windyLegendData = {
92
+ "thresholds": [0, 3, 3, 5, 5, 7, 10, 10, 13, 15, 15, 17, 20, 20, 25, 25, 30],
93
+ // 0 5 10 20 30 40 60
94
+ // "thresholds": [0, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25, 30, 30, 35, 40, 60],
95
+ "values": [
96
+ "#6271B8",
97
+ "#6271B8",
98
+ "#6271B8",
99
+ "#6271B8",
100
+ "#3D6EA3",
101
+ "#4A94AA",
102
+ "#4A9294",
103
+ "#4D8E7C",
104
+ "#4CA44C",
105
+ "#67A436",
106
+ "#A28740",
107
+ "#A26D5C",
108
+ "#8D3F5C",
109
+ "#974B91",
110
+ "#5F64A0",
111
+ "#5B88A1",
112
+ "#5B88A1"
113
+ ]
114
+ };
115
+ var WindPlugin = /** @class */ (function () {
116
+ /**
117
+ * @param {String} id
118
+ * @param {Object} windDataMeta
119
+ * @param {number} windDataMeta.width - image width
120
+ * @param {number} windDataMeta.height - image height
121
+ * @param {Array} windDataMeta.bbox - bounding box [minLon, minLat, maxLon, maxLat]
122
+ * @param {Object} options
123
+ * @param {number} options.fadeOpacity - how fast the particle trails fade on each frame | between 0 - 1 | default 0.746
124
+ * @param {number} options.speedFactor - how fast the particles move | between 0 - 1 | default 0.6
125
+ * @param {number} options.dropRate - how often the particles move to a random place | between 0 - 1 | default 0.007
126
+ * @param {number} options.dropRateBump - drop rate increase relative to individual particle speed
127
+ * @param {number} options.baseOpacity - opacity of drawn particle trails | between 0 - 1 | default 1.0
128
+ * @param {number} options.pointSize - draw size of each particle | positive number | default 2.0
129
+ * @param {number} options.minSpeed - minimum speed value | positive number | default 0.0
130
+ * @param {number} options.maxSpeed - maximum speed value | positive number | default 1000.0
131
+ * @param {number} options.height - height of the particles | number | default 0.0
132
+ * @param {number} numParticles - number of particles | positive integer
133
+ * @param {LegendData} options.legendData - legend data
134
+ */
135
+ function WindPlugin(id, windDataMeta, _a) {
136
+ var _b = _a === void 0 ? {} : _a, _c = _b.fadeOpacity, fadeOpacity = _c === void 0 ? 0.746 : _c, _d = _b.speedFactor, speedFactor = _d === void 0 ? 0.6 : _d, _e = _b.dropRate, dropRate = _e === void 0 ? 0.007 : _e, _f = _b.dropRateBump, dropRateBump = _f === void 0 ? 0.001 : _f, _g = _b.baseOpacity, baseOpacity = _g === void 0 ? 1.0 : _g, _h = _b.pointSize, pointSize = _h === void 0 ? 2.0 : _h, _j = _b.minSpeed, minSpeed = _j === void 0 ? 0.0 : _j, _k = _b.maxSpeed, maxSpeed = _k === void 0 ? 1000.0 : _k, _l = _b.height, height = _l === void 0 ? 0.0 : _l, _m = _b.numParticles, numParticles = _m === void 0 ? 40000 : _m, _o = _b.legendData, legendData = _o === void 0 ? windyLegendData : _o;
137
+ this.id = id;
138
+ this._windDataMeta = windDataMeta;
139
+ this.globe = null;
140
+ this.gl = null;
141
+ this._screenMoved = false;
142
+ this.projMatrix = null;
143
+ this.modelviewMatrix = null;
144
+ this.transPos = new Float32Array([0, 0, 0]);
145
+ this.windData = null;
146
+ this._fadeOpacity = fadeOpacity;
147
+ this._speedFactor = speedFactor;
148
+ this._dropRate = dropRate;
149
+ this._dropRateBump = dropRateBump;
150
+ this._baseOpacity = baseOpacity;
151
+ this._pointSize = pointSize;
152
+ this._minSpeed = minSpeed;
153
+ this._maxSpeed = maxSpeed;
154
+ this._height = height;
155
+ this._numParticles = numParticles;
156
+ this._legendData = legendData;
157
+ this.lastdatas = [[], [], { x: 0, y: 0, z: 0 }];
158
+ this._drawParticles = this._drawParticlesSphere;
159
+ this._lastLOD = 0;
160
+ }
161
+ Object.defineProperty(WindPlugin.prototype, "height", {
162
+ // Uniforms are loaded once, on initiation and when they are changed.
163
+ set: function (value) {
164
+ this._height = value;
165
+ this._loadHeight();
166
+ },
167
+ enumerable: false,
168
+ configurable: true
169
+ });
170
+ Object.defineProperty(WindPlugin.prototype, "minSpeed", {
171
+ set: function (value) {
172
+ this._minSpeed = value;
173
+ this._loadMinMaxSpeed();
174
+ },
175
+ enumerable: false,
176
+ configurable: true
177
+ });
178
+ Object.defineProperty(WindPlugin.prototype, "maxSpeed", {
179
+ set: function (value) {
180
+ this._maxSpeed = value;
181
+ this._loadMinMaxSpeed();
182
+ },
183
+ enumerable: false,
184
+ configurable: true
185
+ });
186
+ Object.defineProperty(WindPlugin.prototype, "fadeOpacity", {
187
+ set: function (value) {
188
+ this._fadeOpacity = value;
189
+ this._loadFadeOpacity();
190
+ },
191
+ enumerable: false,
192
+ configurable: true
193
+ });
194
+ Object.defineProperty(WindPlugin.prototype, "speedFactor", {
195
+ set: function (value) {
196
+ this._speedFactor = value;
197
+ this._loadSpeedFactor();
198
+ },
199
+ enumerable: false,
200
+ configurable: true
201
+ });
202
+ Object.defineProperty(WindPlugin.prototype, "dropRate", {
203
+ set: function (value) {
204
+ this._dropRate = value;
205
+ this._loadDropRate();
206
+ },
207
+ enumerable: false,
208
+ configurable: true
209
+ });
210
+ Object.defineProperty(WindPlugin.prototype, "dropRateBump", {
211
+ set: function (value) {
212
+ this._dropRateBump = value;
213
+ this._loadDropRateBump();
214
+ },
215
+ enumerable: false,
216
+ configurable: true
217
+ });
218
+ Object.defineProperty(WindPlugin.prototype, "baseOpacity", {
219
+ set: function (value) {
220
+ this._baseOpacity = value;
221
+ this._loadBaseOpacity();
222
+ },
223
+ enumerable: false,
224
+ configurable: true
225
+ });
226
+ Object.defineProperty(WindPlugin.prototype, "pointSize", {
227
+ set: function (value) {
228
+ this._pointSize = value;
229
+ this._loadPointSize();
230
+ },
231
+ enumerable: false,
232
+ configurable: true
233
+ });
234
+ // Color ramp methods.
235
+ // Color ramp is used to colorize the particles according to their speed.
236
+ // Legend max value is used to normalize the speed values.
237
+ WindPlugin.prototype.setColorRamp = function (colors) {
238
+ // lookup texture for colorizing the particles according to their speed
239
+ if (this.gl == null) {
240
+ return;
241
+ }
242
+ this.colorRampTexture = util.createTexture(this.gl, this.gl.LINEAR, util.getColorRamp(colors), 16, 16);
243
+ };
244
+ WindPlugin.prototype.setColorRampDefault = function () {
245
+ var _a = this.windData, uMax = _a.uMax, uMin = _a.uMin, vMax = _a.vMax, vMin = _a.vMin;
246
+ var maxSpeed = Math.sqrt(uMax * uMax + vMax * vMax);
247
+ var minSpeed = Math.sqrt(uMin * uMin + vMin * vMin);
248
+ // console.log("maxSpeed", maxSpeed, "minSpeed", minSpeed);
249
+ this._rampMax = maxSpeed > minSpeed ? maxSpeed : minSpeed;
250
+ this._loadRampMax();
251
+ this.setColorRamp(defaultRampColors);
252
+ };
253
+ /**
254
+ *
255
+ * @param {*} legendData
256
+ * @param {Array} legendData.thresholds - list of integers
257
+ * @param {Array} legendData.values - list of colors in hex format like #ff0000 (alpha is not included)
258
+ *
259
+ */
260
+ WindPlugin.prototype.setLegend = function (legendData) {
261
+ var gl = this.gl;
262
+ if (gl === null) {
263
+ throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
264
+ }
265
+ var thresholds = legendData.thresholds, values = legendData.values;
266
+ if (thresholds.length === 0 || values.length === 0) {
267
+ return;
268
+ }
269
+ thresholds.push(thresholds[thresholds.length - 1]);
270
+ values.push(values[values.length - 1]);
271
+ var maxVelocity = thresholds[thresholds.length - 1];
272
+ var colors = [];
273
+ for (var i = 0; i < thresholds.length; i++) {
274
+ colors.push([
275
+ thresholds[i] / maxVelocity,
276
+ values[i]
277
+ ]);
278
+ }
279
+ var colorRamp = util.getColorRamp(colors);
280
+ this.colorRampTexture = util.createTexture(gl, gl.LINEAR, colorRamp, 16, 16);
281
+ this._rampMax = maxVelocity;
282
+ this._loadRampMax();
283
+ };
284
+ Object.defineProperty(WindPlugin.prototype, "numParticles", {
285
+ get: function () {
286
+ return this._numParticles;
287
+ },
288
+ // particle coordinates are encoded into RGBA texture
289
+ set: function (numParticles) {
290
+ var gl = this.gl;
291
+ // we create a square texture where each pixel will hold a particle position encoded as RGBA
292
+ var particleRes = this.particleStateResolution = Math.ceil(Math.sqrt(numParticles));
293
+ this._numParticles = particleRes * particleRes;
294
+ var particleState = new Uint8Array(this._numParticles * 4);
295
+ for (var i = 0; i < particleState.length; i++) {
296
+ particleState[i] = Math.floor(Math.random() * 256); // randomize the initial particle positions
297
+ }
298
+ // textures to hold the particle state for the current and the next frame
299
+ this.particleStateTexture0 = util.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
300
+ this.particleStateTexture1 = util.createTexture(gl, gl.NEAREST, particleState, particleRes, particleRes);
301
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
302
+ gl.useProgram(this.updateProgram.program);
303
+ gl.uniform1f(this.updateProgram.u_wind_res, this.particleStateResolution);
304
+ gl.useProgram(this.drawSphereProgram.program);
305
+ gl.uniform1f(this.drawSphereProgram.u_particles_res, this.particleStateResolution);
306
+ gl.useProgram(this.drawFlatProgram.program);
307
+ gl.uniform1f(this.drawFlatProgram.u_particles_res, this.particleStateResolution);
308
+ gl.useProgram(currentProgram);
309
+ // console.log("numParticles", this._numParticles);
310
+ var particleIndices = new Float32Array(this._numParticles);
311
+ for (var i = 0; i < this._numParticles; i++)
312
+ particleIndices[i] = i;
313
+ this.particleIndexBuffer = util.createBuffer(gl, particleIndices);
314
+ },
315
+ enumerable: false,
316
+ configurable: true
317
+ });
318
+ // Vector field texture is used to calculate the particle movement.
319
+ /**
320
+ * @param {Object} windData
321
+ * @param {HTMLImageElement} windData.image - image element
322
+
323
+ * @param {number} windData.uMin - minimum u value
324
+ * @param {number} windData.vMin - minimum v value
325
+ * @param {number} windData.uMax - maximum u value
326
+ * @param {number} windData.vMax - maximum v value
327
+ */
328
+ WindPlugin.prototype.setWind = function (windData) {
329
+ if (windData === null) {
330
+ return;
331
+ }
332
+ var windDataMeta = this._windDataMeta;
333
+ var gl = this.gl;
334
+ this.windData = windData;
335
+ this.windTexture = util.createTexture(gl, gl.LINEAR, windData.image);
336
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
337
+ gl.useProgram(this.updateProgram.program);
338
+ gl.uniform2f(this.updateProgram.u_wind_res, windDataMeta.width, windDataMeta.height);
339
+ gl.uniform2f(this.updateProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
340
+ gl.uniform2f(this.updateProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
341
+ this.setGeometry();
342
+ var minXY = this._latLongToPixelXY(windDataMeta.bbox[1], windDataMeta.bbox[0]);
343
+ var maxXY = this._latLongToPixelXY(windDataMeta.bbox[3], windDataMeta.bbox[2]);
344
+ this._loadBoundingBoxData(minXY.x, minXY.y, maxXY.x, maxXY.y);
345
+ gl.useProgram(currentProgram);
346
+ this._setCoorcinatesDataCalculatorData();
347
+ this.resize();
348
+ };
349
+ // Vector field texture is used to calculate the particle movement.
350
+ /**
351
+ * @param {Object} windData
352
+ * @param {BaseInt64} windData.image - image element
353
+ * @param {number} windData.width - image width
354
+ * @param {number} windData.height - image height
355
+ * @param {number} windData.uMin - minimum u value
356
+ * @param {number} windData.vMin - minimum v value
357
+ * @param {number} windData.uMax - maximum u value
358
+ * @param {number} windData.vMax - maximum v value
359
+ * @param {Array} windData.bbox - bounding box [minLon, minLat, maxLon, maxLat]
360
+ */
361
+ WindPlugin.prototype.setWindDataWithImageBase64 = function (windData) {
362
+ var _this = this;
363
+ var image = util.createImageFromBase64(windData.image);
364
+ image.onload = function () {
365
+ windData.image = image;
366
+ _this.setWind(windData);
367
+ };
368
+ };
369
+ WindPlugin.prototype.getPointCoordinatesDataCalculator = function () {
370
+ if (!this.coordinatesDataCalculator)
371
+ this._createPointCoordinatesDataCalculator();
372
+ return this.coordinatesDataCalculator;
373
+ };
374
+ WindPlugin.prototype._createPointCoordinatesDataCalculator = function () {
375
+ var _a = this._windDataMeta, bbox = _a.bbox, width = _a.width, height = _a.height;
376
+ this.coordinatesDataCalculator = new util_1.PointCoordinatesDataCalculator(bbox, width, height);
377
+ this._setCoorcinatesDataCalculatorData();
378
+ };
379
+ WindPlugin.prototype._setCoorcinatesDataCalculatorData = function () {
380
+ if (!this.windData || !this.coordinatesDataCalculator) {
381
+ return;
382
+ }
383
+ var magnitude = (0, imagetovectorfieldandmagnitude_1.default)(this.windData);
384
+ this.coordinatesDataCalculator.updateData(0, magnitude, magnitude);
385
+ };
386
+ // -----------------------------------------------
387
+ // --- inner methods ---
388
+ // -----------------------------------------------
389
+ WindPlugin.prototype._latLongToPixelXY = function (latitude, longitude) {
390
+ return {
391
+ x: (longitude + 180) / 360,
392
+ y: (90 - latitude) / 180
393
+ };
394
+ };
395
+ WindPlugin.prototype._loadBoundingBoxData = function (minX, minY, maxX, maxY) {
396
+ // console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY)
397
+ var gl = this.gl;
398
+ var bboxMatrix = new Float32Array([
399
+ maxX - minX, 0, 0,
400
+ 0, maxY - minY, 0,
401
+ minX, minY, 1
402
+ ]);
403
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
404
+ gl.useProgram(this.drawSphereProgram.program);
405
+ gl.uniformMatrix3fv(this.drawSphereProgram.u_bbox_matrix, false, bboxMatrix);
406
+ gl.useProgram(this.drawFlatProgram.program);
407
+ gl.uniformMatrix3fv(this.drawFlatProgram.u_bbox_matrix, false, bboxMatrix);
408
+ gl.useProgram(currentProgram);
409
+ };
410
+ // When the screen is moved, the particles are reset to random positions.
411
+ // During movement plugin should not draw the particles.
412
+ WindPlugin.prototype._doDraw = function () {
413
+ var globe = this.globe;
414
+ if (this.windData === null) {
415
+ return false;
416
+ }
417
+ if (globe.api_IsScreenMoving() || this._lastLOD !== globe.api_GetCurrentLODWithDecimal()) {
418
+ if (!this._screenMoved) {
419
+ this._screenMoved = true;
420
+ }
421
+ this._lastLOD = globe.api_GetCurrentLODWithDecimal();
422
+ return false;
423
+ }
424
+ else {
425
+ if (this._screenMoved) {
426
+ this._loadSpeedFactor();
427
+ this.resize();
428
+ this._screenMoved = false;
429
+ }
430
+ return true;
431
+ }
432
+ };
433
+ WindPlugin.prototype._draw = function () {
434
+ var gl = this.gl;
435
+ this._drawScreen();
436
+ this._updateParticles();
437
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
438
+ };
439
+ // globe calls `draw3D` method on each frame
440
+ WindPlugin.prototype.draw3D = function (projMatrix, modelviewMatrix, transPos) {
441
+ var gl = this.gl;
442
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
443
+ this.transPos.set([transPos.x, transPos.y, transPos.z], 0);
444
+ this.projMatrix = projMatrix;
445
+ this.modelviewMatrix = modelviewMatrix;
446
+ gl.activeTexture(gl.TEXTURE0);
447
+ if (this._doDraw()) {
448
+ var depthTest = gl.isEnabled(gl.DEPTH_TEST);
449
+ if (depthTest)
450
+ gl.disable(gl.DEPTH_TEST);
451
+ // if (gl.disable(gl.STENCIL_TEST); //
452
+ this._draw();
453
+ if (depthTest)
454
+ gl.enable(gl.DEPTH_TEST);
455
+ }
456
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
457
+ // test visuals
458
+ // gl.viewport(0, 0, 100, 100);
459
+ // this._drawTexture(this.windTexture, 1.0);
460
+ // gl.viewport(0, 100, 100, 100);
461
+ // this._drawTexture(this.particleStateTexture0, 1.0);
462
+ // gl.viewport(0, 200, 100, 100);
463
+ // this._drawTexture(this.colorRampTexture, 1.0);
464
+ this._resetMachineStates();
465
+ this.globe.DrawRender();
466
+ };
467
+ WindPlugin.prototype._drawScreen = function () {
468
+ var _a = this, gl = _a.gl, globe = _a.globe;
469
+ util.bindTexture(gl, this.windTexture, 0);
470
+ util.bindTexture(gl, this.particleStateTexture0, 1);
471
+ // draw the screen into a temporary framebuffer to retain it as the background on the next frame
472
+ util.bindFramebuffer(gl, this.framebuffer, this.screenTexture);
473
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
474
+ gl.enable(gl.BLEND);
475
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); // non-premultiplied alpha
476
+ this._drawTexture(this.backgroundTexture, this._fadeOpacity);
477
+ this._drawParticles();
478
+ util.bindFramebuffer(gl, null);
479
+ this._drawTexture(this.screenTexture, 1.0);
480
+ gl.disable(gl.BLEND);
481
+ // save the current screen as the background for the next frame
482
+ var temp = this.backgroundTexture;
483
+ this.backgroundTexture = this.screenTexture;
484
+ this.screenTexture = temp;
485
+ };
486
+ WindPlugin.prototype._drawTexture = function (texture, opacity) {
487
+ var gl = this.gl;
488
+ var program = this.screenProgram;
489
+ gl.useProgram(program.program);
490
+ util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
491
+ util.bindTexture(gl, texture, 2);
492
+ gl.uniform1i(program.u_screen, 2);
493
+ gl.uniform1f(program.u_opacity, opacity);
494
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
495
+ };
496
+ WindPlugin.prototype._loadRampMax = function () {
497
+ var gl = this.gl;
498
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
499
+ // console.log("load ramp max", this._rampMax);
500
+ gl.useProgram(this.drawSphereProgram.program);
501
+ gl.uniform1f(this.drawSphereProgram.u_color_ramp_max, this._rampMax);
502
+ gl.useProgram(this.drawFlatProgram.program);
503
+ gl.uniform1f(this.drawFlatProgram.u_color_ramp_max, this._rampMax);
504
+ gl.useProgram(currentProgram);
505
+ };
506
+ WindPlugin.prototype._drawParticlesSphere = function () {
507
+ var _a = this, gl = _a.gl, projMatrix = _a.projMatrix, modelviewMatrix = _a.modelviewMatrix, transPos = _a.transPos;
508
+ var program = this.drawSphereProgram;
509
+ gl.useProgram(program.program);
510
+ util.bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
511
+ util.bindTexture(gl, this.colorRampTexture, 2);
512
+ gl.uniform1i(program.u_wind, 0);
513
+ gl.uniform1i(program.u_particles, 1);
514
+ gl.uniform1i(program.u_color_ramp, 2);
515
+ gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
516
+ gl.uniformMatrix4fv(program.uModelViewMatrix, false, modelviewMatrix);
517
+ gl.uniform3fv(program.uTranslate, transPos);
518
+ gl.drawArrays(gl.POINTS, 0, this._numParticles);
519
+ };
520
+ WindPlugin.prototype._drawParticlesFlat = function () {
521
+ var _a = this, gl = _a.gl, transPos = _a.transPos, projMatrix = _a.projMatrix, globe = _a.globe;
522
+ var program = this.drawFlatProgram;
523
+ gl.useProgram(program.program);
524
+ util.bindAttribute(gl, this.particleIndexBuffer, program.a_index, 1);
525
+ util.bindTexture(gl, this.colorRampTexture, 2);
526
+ gl.uniform1i(program.u_wind, 0);
527
+ gl.uniform1i(program.u_particles, 1);
528
+ gl.uniform1i(program.u_color_ramp, 2);
529
+ gl.uniform2f(program.u_scrWH, globe.api_ScrW(), globe.api_ScrH());
530
+ var _b = globe.api_GetCurrentWorldWH(), width = _b.width, height = _b.height;
531
+ gl.uniform2f(program.u_mapWH, width, height);
532
+ gl.uniformMatrix4fv(program.uProjectionMatrix, false, projMatrix);
533
+ gl.uniform3fv(program.uTranslate, transPos);
534
+ gl.drawArrays(gl.POINTS, 0, this._numParticles);
535
+ };
536
+ // globe calls `setGeometry` method on map projection change. FLAT or SPHERE
537
+ WindPlugin.prototype.setGeometry = function () {
538
+ if (this.windData === null) {
539
+ return;
540
+ }
541
+ var _a = this, globe = _a.globe, gl = _a.gl;
542
+ var geometry = globe.api_GetCurrentGeometry();
543
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
544
+ if (geometry === globe.api_GeometryTypes().SPHERE) {
545
+ this._drawParticles = this._drawParticlesSphere;
546
+ gl.useProgram(this.drawSphereProgram.program);
547
+ gl.uniform2f(this.drawSphereProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
548
+ gl.uniform2f(this.drawSphereProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
549
+ }
550
+ else if (geometry === globe.api_GeometryTypes().FLAT) {
551
+ this._drawParticles = this._drawParticlesFlat;
552
+ gl.useProgram(this.drawFlatProgram.program);
553
+ gl.uniform2f(this.drawFlatProgram.u_wind_min, this.windData.uMin, this.windData.vMin);
554
+ gl.uniform2f(this.drawFlatProgram.u_wind_max, this.windData.uMax, this.windData.vMax);
555
+ }
556
+ else {
557
+ alert("Geometry is not supported");
558
+ }
559
+ gl.useProgram(currentProgram);
560
+ this.resize();
561
+ };
562
+ WindPlugin.prototype._updateParticles = function () {
563
+ var gl = this.gl;
564
+ var program = this.updateProgram;
565
+ gl.useProgram(program.program);
566
+ gl.viewport(0, 0, this.particleStateResolution, this.particleStateResolution);
567
+ util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
568
+ gl.uniform1i(program.u_wind, 0);
569
+ gl.uniform1i(program.u_particles, 1);
570
+ util.bindAttribute(gl, this.quadBuffer, program.a_pos, 2);
571
+ gl.uniform1f(program.u_rand_seed, Math.random());
572
+ util.bindFramebuffer(gl, this.framebuffer, this.particleStateTexture1);
573
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
574
+ // swap the particle state textures so the new one becomes the current one
575
+ var temp = this.particleStateTexture0;
576
+ this.particleStateTexture0 = this.particleStateTexture1;
577
+ this.particleStateTexture1 = temp;
578
+ };
579
+ WindPlugin.prototype._resetMachineStates = function () {
580
+ var _a = this, gl = _a.gl, globe = _a.globe;
581
+ // gl.disable(gl.DEPTH_TEST);
582
+ // gl.disable(gl.STENCIL_TEST);
583
+ gl.activeTexture(gl.TEXTURE0);
584
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
585
+ };
586
+ WindPlugin.prototype._loadHeight = function () {
587
+ var _a = this, gl = _a.gl, drawSphereProgram = _a.drawSphereProgram;
588
+ if (gl == null)
589
+ return;
590
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
591
+ gl.useProgram(drawSphereProgram.program);
592
+ gl.uniform1f(drawSphereProgram.u_height, this._height);
593
+ gl.useProgram(currentProgram);
594
+ };
595
+ WindPlugin.prototype._loadMinMaxSpeed = function () {
596
+ var _a = this, gl = _a.gl, drawSphereProgram = _a.drawSphereProgram, drawFlatProgram = _a.drawFlatProgram;
597
+ if (gl == null)
598
+ return;
599
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
600
+ gl.useProgram(drawSphereProgram.program);
601
+ gl.uniform1f(drawSphereProgram.u_min_speed, this._minSpeed);
602
+ gl.uniform1f(drawSphereProgram.u_max_speed, this._maxSpeed);
603
+ gl.useProgram(drawFlatProgram.program);
604
+ gl.uniform1f(drawFlatProgram.u_min_speed, this._minSpeed);
605
+ gl.uniform1f(drawFlatProgram.u_max_speed, this._maxSpeed);
606
+ gl.useProgram(currentProgram);
607
+ };
608
+ WindPlugin.prototype._loadFadeOpacity = function () {
609
+ var _a = this, gl = _a.gl, screenProgram = _a.screenProgram;
610
+ if (gl == null) {
611
+ return;
612
+ }
613
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
614
+ gl.useProgram(screenProgram.program);
615
+ gl.uniform1f(screenProgram.u_opacity, this._fadeOpacity);
616
+ gl.useProgram(currentProgram);
617
+ };
618
+ WindPlugin.prototype._loadSpeedFactor = function () {
619
+ var _a = this, gl = _a.gl, globe = _a.globe, updateProgram = _a.updateProgram;
620
+ if (gl == null) {
621
+ return;
622
+ }
623
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
624
+ gl.useProgram(updateProgram.program);
625
+ gl.uniform1f(updateProgram.u_speed_factor, this._speedFactor / Math.ceil(Math.sqrt(globe.api_GetCurrentLOD())));
626
+ gl.useProgram(currentProgram);
627
+ };
628
+ WindPlugin.prototype._loadDropRate = function () {
629
+ var _a = this, gl = _a.gl, updateProgram = _a.updateProgram;
630
+ if (gl == null) {
631
+ return;
632
+ }
633
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
634
+ gl.useProgram(updateProgram.program);
635
+ gl.uniform1f(updateProgram.u_drop_rate, this._dropRate);
636
+ gl.useProgram(currentProgram);
637
+ };
638
+ WindPlugin.prototype._loadDropRateBump = function () {
639
+ var _a = this, gl = _a.gl, updateProgram = _a.updateProgram;
640
+ if (gl == null) {
641
+ return;
642
+ }
643
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
644
+ gl.useProgram(updateProgram.program);
645
+ gl.uniform1f(updateProgram.u_drop_rate_bump, this._dropRateBump);
646
+ gl.useProgram(currentProgram);
647
+ };
648
+ WindPlugin.prototype._loadBaseOpacity = function () {
649
+ var _a = this, gl = _a.gl, drawSphereProgram = _a.drawSphereProgram, drawFlatProgram = _a.drawFlatProgram;
650
+ if (gl == null) {
651
+ return;
652
+ }
653
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
654
+ gl.useProgram(drawSphereProgram.program);
655
+ gl.uniform1f(drawSphereProgram.u_base_opacity, this._baseOpacity);
656
+ gl.useProgram(drawFlatProgram.program);
657
+ gl.uniform1f(drawFlatProgram.u_base_opacity, this._baseOpacity);
658
+ gl.useProgram(currentProgram);
659
+ };
660
+ WindPlugin.prototype._loadPointSize = function () {
661
+ var _a = this, gl = _a.gl, drawSphereProgram = _a.drawSphereProgram, drawFlatProgram = _a.drawFlatProgram;
662
+ if (gl == null) {
663
+ return;
664
+ }
665
+ var currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
666
+ gl.useProgram(drawSphereProgram.program);
667
+ gl.uniform1f(drawSphereProgram.u_point_size, this._pointSize);
668
+ gl.useProgram(drawFlatProgram.program);
669
+ gl.uniform1f(drawFlatProgram.u_point_size, this._pointSize);
670
+ gl.useProgram(currentProgram);
671
+ };
672
+ // globe plugin init methodu
673
+ WindPlugin.prototype.init = function (globe, gl) {
674
+ // console.log("init wind plugin")
675
+ this.globe = globe;
676
+ this.gl = gl;
677
+ this.drawSphereProgram = util.createProgramWrapper(gl, drawSphereVert, drawFrag);
678
+ this.screenProgram = util.createProgramWrapper(gl, quadVert, screenFrag);
679
+ this.updateProgram = util.createProgramWrapper(gl, quadVert, updateFrag);
680
+ this.drawFlatProgram = util.createProgramWrapper(gl, drawFlatVert, drawFrag);
681
+ this.quadBuffer = util.createBuffer(gl, new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]));
682
+ this.framebuffer = gl.createFramebuffer();
683
+ this._loadFadeOpacity();
684
+ this._loadSpeedFactor();
685
+ this._loadDropRate();
686
+ this._loadDropRateBump();
687
+ this._loadBaseOpacity();
688
+ this._loadPointSize();
689
+ this._loadMinMaxSpeed();
690
+ this._loadHeight();
691
+ if (this._legendData != null) {
692
+ this.setLegend(this._legendData);
693
+ }
694
+ this.numParticles = this._numParticles;
695
+ this.resize();
696
+ };
697
+ WindPlugin.prototype.resize = function (a, b) {
698
+ var _a = this, gl = _a.gl, globe = _a.globe;
699
+ var emptyPixels = new Uint8Array(globe.api_ScrW() * globe.api_ScrH() * 4);
700
+ // screen textures to hold the drawn screen for the previous and the current frame
701
+ this.backgroundTexture = util.createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
702
+ this.screenTexture = util.createTexture(gl, gl.LINEAR, emptyPixels, globe.api_ScrW(), globe.api_ScrH());
703
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
704
+ };
705
+ // globe calls this `free` on plugin object unregistration
706
+ WindPlugin.prototype.free = function () {
707
+ var gl = this.gl;
708
+ gl.deleteBuffer(this.quadBuffer);
709
+ gl.deleteFramebuffer(this.framebuffer);
710
+ gl.deleteTexture(this.backgroundTexture);
711
+ gl.deleteTexture(this.screenTexture);
712
+ gl.deleteTexture(this.particleStateTexture0);
713
+ gl.deleteTexture(this.particleStateTexture1);
714
+ gl.deleteTexture(this.windTexture);
715
+ gl.deleteTexture(this.colorRampTexture);
716
+ gl.deleteProgram(this.drawSphereProgram.program);
717
+ gl.deleteProgram(this.screenProgram.program);
718
+ gl.deleteProgram(this.updateProgram.program);
719
+ gl.deleteProgram(this.drawFlatProgram.program);
720
+ gl.deleteBuffer(this.particleIndexBuffer);
721
+ };
722
+ return WindPlugin;
723
+ }());
724
+ exports.default = WindPlugin;