@pirireis/webglobeplugins 0.9.9 → 0.9.10

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 (211) hide show
  1. package/Math/angle-calculation.js +15 -0
  2. package/Math/arc.js +65 -0
  3. package/Math/bounds/line-bbox.js +188 -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 +56 -0
  14. package/Math/matrix4.js +1 -0
  15. package/Math/methods.js +201 -0
  16. package/Math/plane.js +60 -0
  17. package/Math/quaternion.js +104 -0
  18. package/Math/types.js +2 -0
  19. package/Math/utils.js +4 -0
  20. package/Math/vec3.js +126 -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 +18 -0
  24. package/altitude-locator/keymethod.js +1 -0
  25. package/altitude-locator/plugin.js +341 -0
  26. package/altitude-locator/types.js +23 -0
  27. package/arrowfield/adaptor.js +14 -0
  28. package/arrowfield/index.js +10 -0
  29. package/arrowfield/plugin.js +86 -0
  30. package/bearing-line/index.js +8 -0
  31. package/bearing-line/plugin.js +449 -0
  32. package/circle-line-chain/chain-list-map.js +205 -0
  33. package/circle-line-chain/init.js +1 -0
  34. package/circle-line-chain/plugin.js +424 -0
  35. package/circle-line-chain/util.js +5 -0
  36. package/compass-rose/compass-rose-padding-flat.js +225 -0
  37. package/compass-rose/compass-text-writer.js +153 -0
  38. package/compass-rose/index.js +7 -0
  39. package/compassrose/compassrose.js +296 -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 +202 -0
  44. package/heatwave/isobar/plugin.js +343 -0
  45. package/heatwave/isobar/quadtreecontours.js +300 -0
  46. package/heatwave/plugins/heatwaveglobeshell.js +206 -0
  47. package/jest.config.js +7 -0
  48. package/package.json +4 -4
  49. package/partialrings/buffer-manager.js +81 -0
  50. package/partialrings/index.js +41 -0
  51. package/partialrings/plugin.js +135 -0
  52. package/partialrings/program.js +286 -0
  53. package/pin/pin-object-array.js +305 -0
  54. package/pin/pin-point-totem.js +60 -0
  55. package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +66 -0
  56. package/point-heat-map/index.js +1 -0
  57. package/point-heat-map/plugin-webworker.js +126 -0
  58. package/point-heat-map/point-to-heat-map-flow.js +127 -0
  59. package/point-tracks/key-methods.js +5 -0
  60. package/point-tracks/plugin.js +338 -0
  61. package/programs/arrowfield/index.js +7 -0
  62. package/programs/arrowfield/logic.js +257 -0
  63. package/programs/arrowfield/object.js +66 -0
  64. package/programs/data2legend/density-to-legend.js +101 -0
  65. package/programs/data2legend/point-to-density-texture.js +100 -0
  66. package/programs/float2legendwithratio/index.js +8 -0
  67. package/programs/float2legendwithratio/logic.js +171 -0
  68. package/programs/float2legendwithratio/object.js +110 -0
  69. package/programs/globe-util/is-globe-moved.js +21 -0
  70. package/programs/globeshell/index.js +8 -0
  71. package/programs/globeshell/noise/noises.js +1 -0
  72. package/programs/globeshell/wiggle/index.js +8 -0
  73. package/programs/globeshell/wiggle/logic.js +345 -0
  74. package/programs/globeshell/wiggle/object.js +72 -0
  75. package/programs/helpers/blender/index.js +1 -0
  76. package/programs/helpers/blender/program.js +79 -0
  77. package/programs/helpers/fadeaway/index.js +7 -0
  78. package/programs/helpers/fadeaway/logic.js +72 -0
  79. package/programs/helpers/fadeaway/object.js +20 -0
  80. package/programs/helpers/index.js +8 -0
  81. package/programs/index.js +58 -0
  82. package/programs/interface.js +1 -0
  83. package/programs/line-on-globe/angled-line.js +176 -0
  84. package/programs/line-on-globe/circle-accurate-3d.js +141 -0
  85. package/programs/line-on-globe/circle-accurate-flat.js +216 -0
  86. package/programs/line-on-globe/circle-accurate.js +178 -0
  87. package/programs/line-on-globe/circle.js +167 -0
  88. package/programs/line-on-globe/degree-padding-around-circle-3d.js +159 -0
  89. package/programs/line-on-globe/index.js +1 -0
  90. package/programs/line-on-globe/lines-color-instanced-flat.js +136 -0
  91. package/programs/line-on-globe/linestrip.js +171 -0
  92. package/programs/line-on-globe/naive-accurate-flexible.js +195 -0
  93. package/programs/line-on-globe/to-the-surface.js +111 -0
  94. package/programs/line-on-globe/util.js +8 -0
  95. package/programs/picking/pickable-renderer.js +188 -0
  96. package/programs/point-on-globe/element-globe-surface-glow.js +142 -0
  97. package/programs/point-on-globe/element-point-glow.js +153 -0
  98. package/programs/point-on-globe/square-pixel-point.js +174 -0
  99. package/programs/programcache.js +131 -0
  100. package/programs/rings/distancering/circleflatprogram.js +156 -0
  101. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +369 -0
  102. package/programs/rings/distancering/circlepaddysharedbuffer.js +357 -0
  103. package/programs/rings/distancering/index.js +14 -0
  104. package/programs/rings/distancering/paddyflatprogram.js +172 -0
  105. package/programs/rings/distancering/paddyflatprogram2d.js +174 -0
  106. package/programs/rings/distancering/paddyflatprogram3d.js +172 -0
  107. package/programs/rings/distancering/shader.js +1 -0
  108. package/programs/rings/index.js +17 -0
  109. package/programs/rings/partial-ring/piece-of-pie.js +275 -0
  110. package/programs/totems/camerauniformblock.js +160 -0
  111. package/programs/totems/canvas-webglobe-info.js +110 -0
  112. package/programs/totems/gpu-selection-uniform-block.js +108 -0
  113. package/programs/totems/index.js +40 -0
  114. package/programs/two-d/pixel-circle.js +1 -0
  115. package/programs/two-d/pixel-padding-for-compass.js +162 -0
  116. package/programs/util.js +17 -0
  117. package/programs/vectorfields/index.js +23 -0
  118. package/programs/vectorfields/logics/drawrectangleparticles.js +107 -0
  119. package/programs/vectorfields/logics/index.js +12 -0
  120. package/programs/vectorfields/logics/pixelbased.js +142 -0
  121. package/programs/vectorfields/logics/ubo.js +63 -0
  122. package/programs/vectorfields/pingpongbuffermanager.js +76 -0
  123. package/rangerings/enum.js +5 -0
  124. package/rangerings/index.js +15 -0
  125. package/rangerings/plugin.js +560 -0
  126. package/rangerings/rangeringangletext.js +329 -0
  127. package/rangerings/ring-account.js +117 -0
  128. package/shaders/fragment-toy/firework.js +58 -0
  129. package/shaders/fragment-toy/singularity.js +59 -0
  130. package/shape-on-terrain/arc/naive/plugin.js +252 -0
  131. package/timetracks/adaptors-line-strip.js +71 -0
  132. package/timetracks/adaptors.js +122 -0
  133. package/timetracks/index.js +19 -0
  134. package/timetracks/plugin-line-strip.js +250 -0
  135. package/timetracks/plugin.js +258 -0
  136. package/timetracks/program-line-strip.js +611 -0
  137. package/timetracks/program.js +772 -0
  138. package/timetracks/programpoint-line-strip.js +154 -0
  139. package/timetracks/programpoint.js +147 -0
  140. package/types.js +15 -0
  141. package/util/account/bufferoffsetmanager.js +179 -0
  142. package/util/account/index.js +23 -0
  143. package/util/account/single-attribute-buffer-management/buffer-manager.js +108 -0
  144. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +150 -0
  145. package/util/account/single-attribute-buffer-management/index.js +9 -0
  146. package/util/account/single-attribute-buffer-management/object-store.js +51 -0
  147. package/util/account/single-attribute-buffer-management/types.js +2 -0
  148. package/util/account/util.js +22 -0
  149. package/util/algorithms/index.js +1 -0
  150. package/util/algorithms/search-binary.js +28 -0
  151. package/util/check/get.js +18 -0
  152. package/util/check/index.js +1 -0
  153. package/util/check/typecheck.js +49 -0
  154. package/util/geometry/index.js +51 -0
  155. package/util/gl-util/buffer/attribute-loader.js +69 -0
  156. package/util/gl-util/buffer/index.js +6 -0
  157. package/util/gl-util/buffer/types.js +1 -0
  158. package/util/gl-util/draw-options/methods.js +38 -0
  159. package/util/gl-util/draw-options/types.js +15 -0
  160. package/util/gl-util/uniform-block/manager.js +156 -0
  161. package/util/gl-util/uniform-block/shader.js +1 -0
  162. package/util/gl-util/uniform-block/types.js +8 -0
  163. package/util/heatwavedatamanager/datamanager.js +152 -0
  164. package/util/heatwavedatamanager/index.js +10 -0
  165. package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +122 -0
  166. package/util/heatwavedatamanager/pointcoordsmeta.js +20 -0
  167. package/util/index.js +57 -0
  168. package/util/interpolation/index.js +1 -0
  169. package/util/interpolation/timetrack/index.js +5 -0
  170. package/util/interpolation/timetrack/timetrack-interpolator.js +79 -0
  171. package/util/interpolation/timetrack/web-worker-str.js +183 -0
  172. package/util/interpolation/timetrack/web-worker.js +48 -0
  173. package/util/jshelpers/data-filler.js +20 -0
  174. package/util/jshelpers/equality.js +20 -0
  175. package/util/jshelpers/index.js +37 -0
  176. package/util/jshelpers/timefilters.js +32 -0
  177. package/util/picking/fence.js +46 -0
  178. package/util/picking/picker-displayer.js +139 -0
  179. package/util/programs/draw-texture-on-canvas.js +89 -0
  180. package/util/programs/index.js +17 -0
  181. package/util/programs/shapesonglobe.js +214 -0
  182. package/util/programs/supersampletotextures.js +113 -0
  183. package/util/programs/texturetoglobe.js +182 -0
  184. package/util/shaderfunctions/geometrytransformations.js +340 -0
  185. package/util/shaderfunctions/index.js +18 -0
  186. package/util/shaderfunctions/nodata.js +11 -0
  187. package/util/shaderfunctions/noisefunctions.js +43 -0
  188. package/util/surface-line-data/arc-bboxes.js +25 -0
  189. package/util/surface-line-data/arcs-to-cuts.js +50 -0
  190. package/util/surface-line-data/cut-arc.js +1 -0
  191. package/util/surface-line-data/flow.js +28 -0
  192. package/util/surface-line-data/rbush-manager.js +1 -0
  193. package/util/surface-line-data/types.js +1 -0
  194. package/util/surface-line-data/web-worker.js +1 -0
  195. package/util/webglobe/gldefaultstates.js +7 -0
  196. package/util/webglobe/index.js +18 -0
  197. package/util/webglobe/rasteroverlay.js +78 -0
  198. package/util/webglobjectbuilders.js +388 -0
  199. package/util/webglobjectbuilders1.js +237 -0
  200. package/waveparticles/adaptor.js +17 -0
  201. package/waveparticles/index.js +10 -0
  202. package/waveparticles/plugin.js +266 -0
  203. package/wind/imagetovectorfieldandmagnitude.js +35 -0
  204. package/wind/index.js +14 -0
  205. package/wind/plugin.js +926 -0
  206. package/wind/vectorfieldimage.js +25 -0
  207. package/write-text/attached-text-writer.js +91 -0
  208. package/write-text/context-text.js +98 -0
  209. package/write-text/context-text3.js +155 -0
  210. package/write-text/index.js +5 -0
  211. package/write-text/writer-plugin.js +8 -0
package/wind/plugin.js ADDED
@@ -0,0 +1,926 @@
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
+ */
74
+ const quadVert = `
75
+ precision mediump float;
76
+
77
+ attribute vec2 a_pos;
78
+
79
+ varying vec2 v_tex_pos;
80
+
81
+ void main() {
82
+ v_tex_pos = a_pos;
83
+ gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);
84
+ }`;
85
+ const screenFrag = `precision mediump float;
86
+
87
+ uniform sampler2D u_screen;
88
+ uniform float u_opacity;
89
+
90
+ varying vec2 v_tex_pos;
91
+
92
+ void main() {
93
+ vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);
94
+ // a hack to guarantee opacity fade out even with a value close to 1.0
95
+ gl_FragColor = vec4( floor(255.0 * color * u_opacity) / 255.0);
96
+ }
97
+
98
+ `;
99
+ const updateFrag = `
100
+ precision highp float;
101
+
102
+ uniform sampler2D u_particles;
103
+ uniform sampler2D u_wind;
104
+ uniform vec2 u_wind_res;
105
+ uniform vec2 u_wind_min;
106
+ uniform vec2 u_wind_max;
107
+ uniform float u_rand_seed;
108
+ uniform float u_speed_factor;
109
+ uniform float u_drop_rate;
110
+ uniform float u_drop_rate_bump;
111
+
112
+ varying vec2 v_tex_pos;
113
+
114
+ // pseudo-random generator
115
+ const vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);
116
+ float rand(const vec2 co) {
117
+ float t = dot(rand_constants.xy, co);
118
+ return fract(sin(t) * (rand_constants.z + t));
119
+ }
120
+
121
+ // wind speed lookup; use manual bilinear filtering based on 4 adjacent pixels for smooth interpolation
122
+ vec2 lookup_wind(const vec2 uv) {
123
+ // return texture2D(u_wind, uv).rg; // lower-res hardware filtering
124
+ vec2 px = 1.0 / u_wind_res;
125
+ vec2 vc = (floor(uv * u_wind_res)) * px;
126
+ vec2 f = fract(uv * u_wind_res);
127
+ vec2 tl = texture2D(u_wind, vc).rg;
128
+ vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;
129
+ vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;
130
+ vec2 br = texture2D(u_wind, vc + px).rg;
131
+ return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);
132
+ }
133
+
134
+ void main() {
135
+ vec4 color = texture2D(u_particles, v_tex_pos);
136
+ vec2 pos = vec2(
137
+ color.r / 255.0 + color.b,
138
+ color.g / 255.0 + color.a); // decode particle position from pixel RGBA
139
+
140
+ if ( texture2D(u_wind, pos).rg == vec2(0.0, 0.0) ) {
141
+ discard;
142
+ }
143
+
144
+ vec2 velocity = mix(u_wind_min, u_wind_max, lookup_wind(pos));
145
+ float speed_t = length(velocity) / length(u_wind_max);
146
+
147
+ // take EPSG:4236 distortion into account for calculating where the particle moved
148
+ // float distortion = 1.0; //cos(radians(pos.y * 180.0 - 90.0));
149
+ // vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.0001 * u_speed_factor;
150
+ vec2 offset = vec2(velocity.x, velocity.y) * 0.0001 * u_speed_factor;
151
+
152
+ // update particle position, wrapping around the date line
153
+ pos = fract(1.0 + pos + offset);
154
+
155
+ // a random seed to use for the particle drop
156
+ vec2 seed = (pos + v_tex_pos) * u_rand_seed;
157
+
158
+ // drop rate is a chance a particle will restart at random position, to avoid degeneration
159
+ float drop_rate = u_drop_rate + speed_t * u_drop_rate_bump;
160
+ float drop = step(1.0 - drop_rate, rand(seed));
161
+
162
+ vec2 random_pos = vec2(
163
+ rand(seed + 1.3),
164
+ rand(seed + 2.1));
165
+ pos = mix(pos, random_pos, drop);
166
+
167
+ // encode the new particle position back into RGBA
168
+ gl_FragColor = vec4(
169
+ fract(pos * 255.0),
170
+ floor(pos * 255.0) / 255.0);
171
+ }
172
+ `;
173
+ const drawFrag = `precision mediump float;
174
+
175
+ uniform sampler2D u_wind;
176
+ uniform vec2 u_wind_min;
177
+ uniform vec2 u_wind_max;
178
+ uniform sampler2D u_color_ramp;
179
+ uniform float u_color_ramp_max;
180
+ uniform float u_base_opacity;
181
+
182
+ uniform float u_min_speed;
183
+ uniform float u_max_speed;
184
+
185
+ varying vec2 v_particle_pos;
186
+
187
+ void main() {
188
+
189
+
190
+ if ( texture2D(u_wind, v_particle_pos).rg == vec2(0.0, 0.0) ) {
191
+ discard;
192
+ }
193
+ vec2 velocity = mix(u_wind_min, u_wind_max, texture2D(u_wind, v_particle_pos).rg);
194
+ float speed = length(velocity);
195
+ if (speed < u_min_speed || speed > u_max_speed) {
196
+ discard;
197
+ }
198
+ if (speed >= u_color_ramp_max) {
199
+ gl_FragColor = texture2D(u_color_ramp,
200
+ vec2( 0.99999 , 0.0001 )) * u_base_opacity;
201
+ return;
202
+ }
203
+
204
+ float speed_t = speed / u_color_ramp_max; // length(u_wind_max); //
205
+ // color ramp olusturulan method finalde texture ters çevriliyor. bu yüzden speed_t 1.0 - speed_t oluyor.
206
+ speed_t = 1.0 - speed_t;
207
+ // color ramp is encoded in a 16.0 x 16.0 texture
208
+ vec2 ramp_pos = vec2(
209
+ fract(16.0 * speed_t),
210
+ floor(16.0 * speed_t) / 16.0);
211
+
212
+
213
+ gl_FragColor = texture2D(u_color_ramp, ramp_pos) * u_base_opacity;
214
+ }
215
+ `;
216
+ const drawSphereVert = `
217
+ precision mediump float;
218
+
219
+ attribute float a_index;
220
+
221
+ uniform float u_point_size;
222
+ uniform sampler2D u_particles;
223
+ uniform float u_particles_res;
224
+
225
+ uniform float u_height;
226
+
227
+ varying vec2 v_particle_pos;
228
+ varying float v_z;
229
+
230
+ uniform mat3 u_bbox_matrix;
231
+
232
+ uniform mat4 uModelViewMatrix;
233
+ uniform mat4 uProjectionMatrix;
234
+ uniform vec3 uTranslate;
235
+
236
+ const float PI = 3.141592653589793;
237
+ const float R = 6378.137;
238
+
239
+ vec3 cartesian3DPoint( float longRad, float latRad, float height) {
240
+ float radius = R + height;
241
+ float x = radius * sin(latRad) * cos(longRad);
242
+ float y = radius * sin(latRad) * sin(longRad);
243
+ float z = radius * cos(latRad);
244
+ return vec3(
245
+ x,
246
+ y,
247
+ z) ;
248
+ }
249
+
250
+ void main() {
251
+ vec4 color = texture2D(u_particles, vec2(
252
+ fract(a_index / u_particles_res),
253
+ floor(a_index / u_particles_res) / u_particles_res));
254
+
255
+ v_particle_pos = vec2(
256
+ color.r / 255.0 + color.b,
257
+ color.g / 255.0 + color.a);
258
+
259
+
260
+ if ( v_particle_pos.y < 0.0265 || v_particle_pos.y > 0.9735 ) {
261
+ gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
262
+ return;
263
+ }
264
+ vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);
265
+
266
+
267
+ float xRad = PI * (2.0 * pos.x - 1.0);
268
+ float yRad = pos.y * PI;
269
+
270
+ pos = cartesian3DPoint(xRad, yRad, u_height);
271
+ gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(pos - uTranslate, 1.0);
272
+ gl_PointSize = u_point_size;
273
+
274
+ }`;
275
+ const drawFlatVert = `
276
+ precision mediump float;
277
+
278
+ uniform mat3 u_bbox_matrix;
279
+
280
+ uniform vec3 uTranslate;
281
+ // uniform mat4 uModelViewMatrix;
282
+ uniform mat4 uProjectionMatrix;
283
+
284
+ attribute float a_index;
285
+ uniform sampler2D u_particles;
286
+ uniform float u_particles_res;
287
+ uniform float u_point_size;
288
+ uniform vec2 u_mapWH;
289
+ uniform vec2 u_scrWH;
290
+
291
+ varying vec2 v_particle_pos;
292
+
293
+ const float PI = 3.141592653589793;
294
+ const float POLE = 20037508.34;
295
+ const float POLE_BY_PI = POLE / PI;
296
+ const float HALF_PI = PI / 2.0;
297
+
298
+
299
+ void main() {
300
+
301
+ vec4 color = texture2D(u_particles, vec2(
302
+ fract(a_index / u_particles_res),
303
+ floor(a_index / u_particles_res) / u_particles_res));
304
+
305
+ v_particle_pos = vec2(
306
+ color.r / 255.0 + color.b,
307
+ color.g / 255.0 + color.a);
308
+
309
+ if ( v_particle_pos.y < 0.0265 || v_particle_pos.y > 0.9735 ) {
310
+ gl_Position = vec4(-2.0, -2.0, -2.0, 1.0);
311
+ return;
312
+ }
313
+ vec3 pos = u_bbox_matrix * vec3(v_particle_pos.x, v_particle_pos.y, 1.0);
314
+
315
+ float x = (2.0 * pos.x - 1.0);
316
+ float mercator_x = x * POLE;
317
+ float mercator_y = log( tan( ( 1.0 - pos.y ) * HALF_PI ) ) * POLE_BY_PI;
318
+
319
+ float normalizedX = ( mercator_x - uTranslate.x) / u_mapWH.x;
320
+ float normalizedY = ( mercator_y - uTranslate.y) / u_mapWH.y;
321
+ gl_Position = uProjectionMatrix * vec4(normalizedX * u_scrWH.x, (1.0 - normalizedY) * u_scrWH.y, 0.0, 1.0);
322
+
323
+ gl_PointSize = u_point_size;
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;