@pirireis/webglobeplugins 0.9.6 → 0.9.7

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