@pirireis/webglobeplugins 0.0.1

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 (82) hide show
  1. package/arrowfield/adaptor.js +11 -0
  2. package/arrowfield/index.js +4 -0
  3. package/arrowfield/plugin.js +128 -0
  4. package/compassrose/compassrose.js +394 -0
  5. package/compassrose/index.js +2 -0
  6. package/heatwavemaps/index.js +4 -0
  7. package/heatwavemaps/isobar/objectarraylabels.js +247 -0
  8. package/heatwavemaps/isobar/plugin.js +337 -0
  9. package/heatwavemaps/isobar/quadtreecontours.js +338 -0
  10. package/heatwavemaps/plugins/heatwaveglobeshell.js +257 -0
  11. package/index.js +8 -0
  12. package/package.json +7 -0
  13. package/programs/arrowfield/index.js +2 -0
  14. package/programs/arrowfield/logic.js +284 -0
  15. package/programs/arrowfield/object.js +89 -0
  16. package/programs/float2legendwithratio/index.js +3 -0
  17. package/programs/float2legendwithratio/logic.js +189 -0
  18. package/programs/float2legendwithratio/object.js +132 -0
  19. package/programs/globeshell/index.js +2 -0
  20. package/programs/globeshell/noise/noises.js +0 -0
  21. package/programs/globeshell/wiggle/index.js +6 -0
  22. package/programs/globeshell/wiggle/logic.js +374 -0
  23. package/programs/globeshell/wiggle/object.js +94 -0
  24. package/programs/helpers/blender/index.js +0 -0
  25. package/programs/helpers/blender/program.js +91 -0
  26. package/programs/helpers/fadeaway/index.js +3 -0
  27. package/programs/helpers/fadeaway/logic.js +76 -0
  28. package/programs/helpers/fadeaway/object.js +20 -0
  29. package/programs/helpers/index.js +2 -0
  30. package/programs/index.js +21 -0
  31. package/programs/programcache.js +119 -0
  32. package/programs/rings/distancering/circleflatprogram.js +135 -0
  33. package/programs/rings/distancering/circlepaddysharedbuffer.js +502 -0
  34. package/programs/rings/distancering/index.js +5 -0
  35. package/programs/rings/distancering/paddyflatprogram.js +131 -0
  36. package/programs/rings/distancering/shader.js +0 -0
  37. package/programs/rings/index.js +9 -0
  38. package/programs/totems/camerauniformblock.js +129 -0
  39. package/programs/totems/index.js +2 -0
  40. package/programs/util.js +17 -0
  41. package/programs/vectorfields/index.js +3 -0
  42. package/programs/vectorfields/logics/drawrectangleparticles.js +125 -0
  43. package/programs/vectorfields/logics/index.js +5 -0
  44. package/programs/vectorfields/logics/pixelbased.js +161 -0
  45. package/programs/vectorfields/logics/ubo.js +64 -0
  46. package/programs/vectorfields/pingpongbuffermanager.js +80 -0
  47. package/rangerings/index.js +3 -0
  48. package/rangerings/rangerings.js +88 -0
  49. package/timetracks/adaptors.js +133 -0
  50. package/timetracks/index.js +3 -0
  51. package/timetracks/plugin.js +304 -0
  52. package/timetracks/program.js +850 -0
  53. package/timetracks/programpoint.js +168 -0
  54. package/util/datamanager/datamanager.js +168 -0
  55. package/util/datamanager/index.js +3 -0
  56. package/util/datamanager/pointcoordinatesdatacalculator.js +133 -0
  57. package/util/datamanager/pointcoordsmeta.js +22 -0
  58. package/util/geometry/geodatafromtexture.js +52 -0
  59. package/util/geometry/index.js +44 -0
  60. package/util/index.js +13 -0
  61. package/util/jshelpers/index.js +1 -0
  62. package/util/jshelpers/timefilters.js +32 -0
  63. package/util/jshelpers/timemethods.js +19 -0
  64. package/util/programs/index.js +2 -0
  65. package/util/programs/shapesonglobe.js +248 -0
  66. package/util/programs/supersampletotextures.js +142 -0
  67. package/util/programs/texturetoglobe.js +203 -0
  68. package/util/shaderfunctions/geometrytransformations.js +129 -0
  69. package/util/shaderfunctions/index.js +2 -0
  70. package/util/shaderfunctions/nodata.js +10 -0
  71. package/util/shaderfunctions/noisefunctions.js +44 -0
  72. package/util/webglobe/gldefaultstates.js +4 -0
  73. package/util/webglobe/index.js +2 -0
  74. package/util/webglobe/rasteroverlay.js +96 -0
  75. package/util/webglobjectbuilders.js +256 -0
  76. package/waveparticles/adaptor.js +16 -0
  77. package/waveparticles/index.js +4 -0
  78. package/waveparticles/plugin.js +281 -0
  79. package/wind/imagetovectorfieldandmagnitude.js +39 -0
  80. package/wind/index.js +7 -0
  81. package/wind/plugin.js +1032 -0
  82. package/wind/vectorfieldimage.js +27 -0
@@ -0,0 +1,6 @@
1
+ import GlobeShellWiggle from './object'
2
+
3
+ export {
4
+ GlobeShellWiggle
5
+
6
+ }
@@ -0,0 +1,374 @@
1
+ import { createProgram } from '../../../util';
2
+
3
+
4
+
5
+ export default class {
6
+ constructor() {
7
+ this.id = "GlobeShellProgram";
8
+ this.description = "This program implements flyweight pattern for globe." +
9
+ "At globes draw3D call stack, this program should be prior to any program that uses it." +
10
+ "draw3D method of this object only sets Projetion, ModelView and Translate matrices and if the mode is 2D mapWH .";
11
+
12
+ }
13
+
14
+ init(globe, gl) {
15
+ this.gl = gl;
16
+ this.globe = globe;
17
+ this.programWrapper = this._createProgramWrapper();
18
+ this._transformArray = new Float32Array(3);
19
+ this.setGeometry();
20
+ this.resize();
21
+ this.updateTime(0);
22
+ this.setMesh({ xRes: 64, yRes: 64, eastWestTied: false });
23
+ }
24
+
25
+ _createProgramWrapper() {
26
+ const vertexShader = `#version 300 es
27
+ #define R 6378.137
28
+ #define PI 3.1415926535897932384626433832795
29
+ #define POLE 20037508.34
30
+ #define POLE_BY_PI 6366198.2
31
+ #define HALF_PI 1.5707963267948966192313216916398
32
+
33
+ uniform vec2 u_mesh_resolution;
34
+
35
+ layout(std140) uniform ShellBlock {
36
+ vec2 u_grid_offset_rad;
37
+ vec2 u_grid_size_rad;
38
+ float u_height;
39
+ float u_wiggle;
40
+ float u_time;
41
+ float u_opacity;
42
+ };
43
+
44
+
45
+ uniform mat4 u_model_view_matrix;
46
+ uniform mat4 u_projection_matrix;
47
+ uniform vec3 u_translate;
48
+
49
+
50
+ uniform vec2 u_mapWH;
51
+ uniform vec2 u_scrWH;
52
+
53
+
54
+ uniform bool u_is3D; // TODO: Calculate 2 position from resolution, u_grid_size_rad and u_grid_offset_rad
55
+
56
+ out float v_opacity;
57
+ out vec2 v_texture_coordinate;
58
+
59
+
60
+ vec2 f_texCoord(){
61
+
62
+ float x = mod( float(gl_VertexID), u_mesh_resolution.x ) / ( u_mesh_resolution.x - 1.0);
63
+ float y = floor( float(gl_VertexID) / u_mesh_resolution.x ) / ( u_mesh_resolution.y - 1.0);
64
+ return vec2(x, y);
65
+ //return vec2( fract( float(gl_VertexID) / u_mesh_resolution.x ), floor(float(gl_VertexID) / u_mesh_resolution.x) / u_mesh_resolution.y);
66
+ }
67
+
68
+ vec3 f_onSphere(vec2 texCoord){
69
+ float vert = (texCoord.y * u_grid_size_rad.y ) + u_grid_offset_rad.y;
70
+ float hor = (texCoord.x * u_grid_size_rad.x ) + u_grid_offset_rad.x;
71
+ float x = sin(vert) * cos(hor);
72
+ float y = sin(vert) * sin(hor);
73
+ float z = cos(vert);
74
+ return vec3(x, y, z);
75
+ }
76
+
77
+ vec2 f_onFlat(vec2 texCoord){
78
+ float x = (texCoord.x * u_grid_size_rad.x ) + u_grid_offset_rad.x;
79
+ float y = (texCoord.y * u_grid_size_rad.y ) + u_grid_offset_rad.y;
80
+
81
+
82
+ float mercX = x * POLE_BY_PI;
83
+ float mercY = log(tan(HALF_PI - y / 2.0 )) * POLE_BY_PI;
84
+
85
+ float normX = ( mercX - u_translate.x ) / u_mapWH.x;
86
+ float normY = ( mercY - u_translate.y ) / u_mapWH.y;
87
+ return vec2(normX, normY);
88
+ }
89
+
90
+ vec3 f_position(vec3 unit_sphere_pos, float wiggle){
91
+ return unit_sphere_pos * (R + u_height + wiggle);
92
+ }
93
+
94
+ float f_wiggle(vec2 texCoord){
95
+ float s_contrib = 0.6*sin(texCoord.x*2.0*PI + 3.0*u_time);
96
+ float t_contrib = 0.8*cos(texCoord.y*4.1 + 5.0*u_time);
97
+ return u_wiggle * s_contrib * t_contrib * sin(texCoord.y*PI*2.0);
98
+ }
99
+
100
+ void main() {
101
+ vec2 texCoord = f_texCoord();
102
+ if (u_is3D){
103
+ vec3 unit_sphere_pos = f_onSphere(texCoord);
104
+ float wiggle = f_wiggle(texCoord);
105
+ vec3 position = f_position(unit_sphere_pos, wiggle);
106
+ gl_Position = u_projection_matrix * u_model_view_matrix * vec4(position - u_translate, 1.0);
107
+ } else {
108
+ vec2 position = f_onFlat(texCoord);
109
+ gl_Position = u_projection_matrix * vec4(
110
+ position.x * u_scrWH.x,
111
+ (1.0 - position.y) * u_scrWH.y,
112
+ 0.0,
113
+ 1.0);
114
+ }
115
+ v_texture_coordinate = texCoord;
116
+ v_opacity = u_opacity;
117
+ }
118
+ `;
119
+
120
+ const fragmentShader = `#version 300 es
121
+ precision lowp float;
122
+ in vec2 v_texture_coordinate;
123
+ in float v_opacity;
124
+ uniform sampler2D u_texture;
125
+ out vec4 outColor;
126
+
127
+
128
+ void main() {
129
+ outColor = texture(u_texture, v_texture_coordinate);
130
+ outColor.a *= v_opacity;
131
+ }`;
132
+
133
+ const gl = this.gl;
134
+ const program = createProgram(gl, vertexShader, fragmentShader);
135
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
136
+ gl.useProgram(program);
137
+ this.shellBlockBindingPoint = 0;
138
+ const shellBlockIndex = gl.getUniformBlockIndex(program, "ShellBlock");
139
+ gl.uniformBlockBinding(program, shellBlockIndex, this.shellBlockBindingPoint);
140
+ gl.useProgram(currentProgram);
141
+
142
+ return {
143
+ program,
144
+ u_model_view_matrix: gl.getUniformLocation(program, "u_model_view_matrix"),
145
+ u_projection_matrix: gl.getUniformLocation(program, "u_projection_matrix"),
146
+ u_translate: gl.getUniformLocation(program, "u_translate"),
147
+ u_is3D: gl.getUniformLocation(program, "u_is3D"),
148
+ u_scrWH: gl.getUniformLocation(program, "u_scrWH"),
149
+ u_mapWH: gl.getUniformLocation(program, "u_mapWH"),
150
+ u_texture: gl.getUniformLocation(program, "u_texture"),
151
+ u_mesh_resolution: gl.getUniformLocation(program, "u_mesh_resolution"),
152
+ }
153
+ }
154
+
155
+ // this method implements data part of flyweight pattern
156
+ getShellBlockBufferManager() {
157
+ return new ShellBlockManager(this.gl)
158
+ }
159
+
160
+ updateTime(time) {
161
+ const { gl, programWrapper } = this;
162
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
163
+ gl.useProgram(programWrapper.program);
164
+ gl.uniform1f(this.programWrapper.u_time, time);
165
+ gl.useProgram(currentProgram);
166
+ }
167
+
168
+ setRotationAndTranslation(uProjectionMatrix, uModelViewMatrix, uTranslate, resetCurrentProgram = false) {
169
+ const gl = this.gl;
170
+ let currentProgram = null;
171
+ if (resetCurrentProgram) { currentProgram = gl.getParameter(gl.CURRENT_PROGRAM) };
172
+ gl.useProgram(this.programWrapper.program);
173
+ gl.uniformMatrix4fv(this.programWrapper.u_projection_matrix, false, uProjectionMatrix);
174
+ gl.uniformMatrix4fv(this.programWrapper.u_model_view_matrix, false, uModelViewMatrix);
175
+ this._transformArray.set([uTranslate.x, uTranslate.y, uTranslate.z], 0);
176
+ gl.uniform3fv(this.programWrapper.u_translate, this._transformArray);
177
+ if (resetCurrentProgram) gl.useProgram(currentProgram);
178
+ }
179
+
180
+
181
+ setGeometry() {
182
+ const { globe, gl } = this;
183
+ const { u_is3D, u_scrWH, program } = this.programWrapper;
184
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
185
+ const is3D = this.globe.api_GetCurrentGeometry() === 0;
186
+ gl.useProgram(program);
187
+ if (globe.api_GetCurrentGeometry() === globe.api_GeometryTypes().FLAT) {
188
+ gl.uniform2f(u_scrWH, globe.api_ScrW(), globe.api_ScrH());
189
+ }
190
+ gl.uniform1i(u_is3D, is3D);
191
+ gl.useProgram(currentProgram);
192
+ }
193
+
194
+
195
+ resize() {
196
+ const { gl, globe } = this;
197
+ if (!globe) return;
198
+ const { program, u_scrWH } = this.programWrapper;
199
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
200
+ gl.useProgram(program);
201
+ if (globe.api_GetCurrentGeometry() === globe.api_GeometryTypes().FLAT) {
202
+ gl.uniform2f(u_scrWH, globe.api_ScrW(), globe.api_ScrH());
203
+ }
204
+ gl.useProgram(currentProgram);
205
+ }
206
+
207
+ // only sets data does not draw
208
+ draw3D(uProjectionMatrix, uModelViewMatrix, uTranslate) {
209
+ const { gl, globe } = this;
210
+ const { program, u_model_view_matrix, u_projection_matrix, u_translate } = this.programWrapper;
211
+ gl.disable(gl.DEPTH_TEST);
212
+ gl.useProgram(program);
213
+ gl.uniformMatrix4fv(u_projection_matrix, false, uProjectionMatrix);
214
+ gl.uniformMatrix4fv(u_model_view_matrix, false, uModelViewMatrix);
215
+ // this._transformArray.set([], 0);
216
+ gl.uniform3f(u_translate, uTranslate.x, uTranslate.y, uTranslate.z);
217
+
218
+ if (globe.api_GetCurrentGeometry() === 1) {
219
+ const { width, height } = globe.api_GetCurrentWorldWH();
220
+ gl.uniform2fv(this.programWrapper.u_mapWH, [width, height]);
221
+ }
222
+ gl.enable(gl.DEPTH_TEST);
223
+ }
224
+
225
+
226
+ draw(texture, shellBlockDataManager, drawLines = false) {
227
+ const { gl, programWrapper, _vao, _drawCount } = this;
228
+ const { program, u_texture, u_time } = programWrapper;
229
+ gl.useProgram(program);
230
+ gl.bindVertexArray(_vao);
231
+ gl.activeTexture(gl.TEXTURE0);
232
+ gl.bindTexture(gl.TEXTURE_2D, texture);
233
+ gl.uniform1i(u_texture, 0);
234
+ shellBlockDataManager.bind();
235
+ if (drawLines) gl.drawElements(gl.LINES, _drawCount, gl.UNSIGNED_SHORT, 0);
236
+ gl.drawElements(gl.TRIANGLES, _drawCount, gl.UNSIGNED_SHORT, 0);
237
+ shellBlockDataManager.unbind();
238
+ gl.bindVertexArray(null);
239
+ }
240
+
241
+
242
+ free() {
243
+ const { gl, programWrapper, _vao, _indexBuffer } = this;
244
+ gl.deleteBuffer(_indexBuffer);
245
+ gl.deleteVertexArray(_vao);
246
+ gl.deleteProgram(programWrapper.program);
247
+ }
248
+
249
+
250
+ setMesh({ xRes, yRes, eastWestTied }) {
251
+ this._xRes = xRes;
252
+ this._yRes = yRes;
253
+ const { _vao } = this._meshUP(xRes, yRes, eastWestTied);
254
+ this._vao = _vao;
255
+ this._setUMeshResolution(xRes, yRes);
256
+ }
257
+
258
+ _setUMeshResolution(xRes, yRes) {
259
+ const { gl, programWrapper } = this;
260
+ const { u_mesh_resolution } = programWrapper;
261
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
262
+ gl.useProgram(programWrapper.program);
263
+ gl.uniform2f(u_mesh_resolution, xRes, yRes);
264
+ gl.useProgram(currentProgram);
265
+ this._drawCount = 6 * ((xRes - 1) * (yRes - 1));
266
+ }
267
+
268
+ _meshUP(xRes, yRes, eastWestTied) {
269
+ this._drawCount = 6 * ((xRes - 1) * (yRes - 1))
270
+ const indices = new Uint16Array(this._drawCount);
271
+ {
272
+ let indicesIndex = 0;
273
+ let index = 0;
274
+ for (let j = 0; j < yRes - 1; j++) {
275
+ for (let i = 0; i < xRes - 1; i++) {
276
+ const ind = index + i;
277
+ indices[indicesIndex++] = ind + xRes;
278
+ indices[indicesIndex++] = ind + 1;
279
+ indices[indicesIndex++] = ind;
280
+ indices[indicesIndex++] = ind + xRes + 1;
281
+ indices[indicesIndex++] = ind + 1;
282
+ indices[indicesIndex++] = ind + xRes;
283
+ }
284
+ index += xRes;
285
+ }
286
+ if (eastWestTied) {
287
+ let left = (yRes - 1);
288
+ let right = 0;
289
+ for (let i = 0; i < xRes - 1; i++) {
290
+ indices[indicesIndex++] = left + xRes;
291
+ indices[indicesIndex++] = right;
292
+ indices[indicesIndex++] = left;
293
+ indices[indicesIndex++] = right + xRes;
294
+ indices[indicesIndex++] = right;
295
+ indices[indicesIndex++] = left + xRes;
296
+ left += xRes;
297
+ right += xRes;
298
+ }
299
+ }
300
+ }
301
+ const gl = this.gl;
302
+ const _vao = gl.createVertexArray();
303
+ gl.bindVertexArray(_vao);
304
+ const indexBuffer = gl.createBuffer();
305
+ this._indexBuffer = indexBuffer;
306
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
307
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
308
+ gl.bindVertexArray(null);
309
+ return { _vao };
310
+ }
311
+
312
+ }
313
+
314
+
315
+ class ShellBlockManager {
316
+ constructor(gl) {
317
+ this.gl = gl;
318
+ this.buffer = gl.createBuffer();
319
+ gl.bindBuffer(gl.UNIFORM_BUFFER, this.buffer);
320
+ gl.bufferData(gl.UNIFORM_BUFFER, 32, gl.DYNAMIC_DRAW);
321
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
322
+ }
323
+
324
+ update(
325
+ {
326
+ gridSizeRad = null,
327
+ gridOffsetRad = null,
328
+ height = null,
329
+ wiggleInKM = null,
330
+ innerTime = null,
331
+ opacity = null } = {}) {
332
+ const { gl, buffer } = this;
333
+ gl.bindBuffer(gl.UNIFORM_BUFFER, buffer);
334
+
335
+ if (gridOffsetRad !== null) {
336
+ const offset = new Float32Array(gridOffsetRad);
337
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 0, offset);
338
+ }
339
+ if (gridSizeRad !== null) {
340
+ const size = new Float32Array(gridSizeRad);
341
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 8, size);
342
+ }
343
+ if (height !== null) {
344
+ const heightArray = new Float32Array([height]);
345
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 16, heightArray);
346
+ }
347
+ if (wiggleInKM !== null) {
348
+ const wiggleArray = new Float32Array([wiggleInKM]);
349
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 20, wiggleArray);
350
+ }
351
+ if (innerTime !== null) {
352
+ const innerTimeArray = new Float32Array([innerTime]);
353
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 24, innerTimeArray);
354
+ }
355
+ if (opacity !== null) {
356
+ if (opacity < 0 || opacity > 1) { console.warn('Invalid opacity value'); return; }
357
+ const op = new Float32Array([opacity]);
358
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 28, op);
359
+ }
360
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
361
+ }
362
+ bind() {
363
+ const { gl, buffer } = this;
364
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, this.shellBlockBindingPoint, buffer);
365
+ }
366
+ free() {
367
+ const { gl, buffer } = this;
368
+ gl.deleteBuffer(buffer);
369
+ }
370
+ unbind() {
371
+ const { gl } = this;
372
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, this.shellBlockBindingPoint, null);
373
+ }
374
+ }
@@ -0,0 +1,94 @@
1
+
2
+ import { globeProgramCache } from '../../programcache';
3
+ import GlobeShellProgram from './logic';
4
+
5
+ export default class GlobeShell {
6
+ constructor(gl, globe,
7
+ {
8
+ minLon = -180,
9
+ maxLon = 180,
10
+ minLat = -90,
11
+ maxLat = 90,
12
+ height = 0,
13
+ u_opacity = 1,
14
+ wiggleInKM = 0,
15
+ wiggleSpeed = 0,
16
+ eastWestTied,
17
+ } = {}) {
18
+ this.gl = gl;
19
+ this.globe = globe;
20
+ this.program = globeProgramCache.getProgram(globe, GlobeShellProgram);
21
+ this.shellBlockManager = this.program.getShellBlockBufferManager()
22
+ this.update = this.shellBlockManager.update.bind(this.shellBlockManager);
23
+ this.innerTime = 0;
24
+ this.setBBox({ minLon, maxLon, minLat, maxLat })
25
+ this.setOpacity(u_opacity);
26
+ this.setHeight(height);
27
+ this.setWiggle({ wiggleSpeed, wiggleInKM });
28
+ }
29
+
30
+
31
+ setTexture(texture) {
32
+ this.texture = texture;
33
+ this.globe.DrawRender();
34
+ }
35
+
36
+
37
+
38
+ setHeight(height) {
39
+ this.shellBlockManager.update({ height });
40
+ this.globe.DrawRender();
41
+ }
42
+
43
+ setOpacity(opacity) {
44
+ this.shellBlockManager.update({ opacity });
45
+ this.globe.DrawRender();
46
+ }
47
+
48
+ setBBox({ minLon = -180, maxLon = 180, minLat = -90, maxLat = 90 } = {}) {
49
+ this.bbox = { minLon, maxLon, minLat, maxLat };
50
+ // x
51
+ const horOffset = (minLon) * Math.PI / 180;
52
+ const horSize = (maxLon - minLon) * Math.PI / 180;
53
+ // y
54
+ const vertOffset = (90 - maxLat) * Math.PI / 180;
55
+ const vertSize = (maxLat - minLat) * Math.PI / 180;
56
+
57
+ const offset_rad = new Float32Array([horOffset, vertOffset]);
58
+ const size_rad = new Float32Array([horSize, vertSize]);
59
+ this.shellBlockManager.update({ gridSizeRad: size_rad, gridOffsetRad: offset_rad });
60
+ this.globe.DrawRender();
61
+ }
62
+
63
+ setWiggle({ wiggleSpeed = null, wiggleInKM = null }) {
64
+ if (wiggleInKM !== null) this.wiggleInKM = wiggleInKM;
65
+ if (wiggleSpeed !== null) this.wiggleSpeed = wiggleSpeed;
66
+ this.shellBlockManager.update({ wiggleInKM });
67
+
68
+ }
69
+
70
+
71
+ /**
72
+ *
73
+ * @param {*} program modelView, projection, translate, mapWH, scrWH, should be set before calling this function
74
+ */
75
+ draw() {
76
+ this.program.draw(
77
+ this.texture,
78
+ this.shellBlockManager,
79
+ );
80
+ if (this.wiggleInKM > 0 && this.wiggleSpeed > 0) {
81
+ this.innerTime += this.wiggleSpeed;
82
+ this.shellBlockManager.update({ innerTime: this.innerTime });
83
+ this.globe.DrawRender();
84
+ }
85
+ }
86
+
87
+
88
+ free() {
89
+ // TODO: What else to free. Does textures and buffers need to be freed?
90
+ globeProgramCache.releaseProgram(this.globe, GlobeShellProgram);
91
+ this.shellBlockManager.free();
92
+ }
93
+
94
+ }
File without changes
@@ -0,0 +1,91 @@
1
+ import { createProgram } from "../util";
2
+
3
+
4
+ /**
5
+ * Blends two float32textures with given ratio.
6
+ */
7
+
8
+ const vertexShader = `#version 300 es
9
+ in vec2 a_position;
10
+ out vec2 v_texCoord;
11
+ void main() {
12
+ gl_Position = vec4(a_position, 0.0, 1.0);
13
+ v_texCoord = a_position * 0.5 + 0.5;
14
+ }
15
+ `;
16
+
17
+ const fragmentShader = `#version 300 es
18
+ uniform sampler2D u_texture0;
19
+ uniform sampler2D u_texture1;
20
+ uniform float u_ratio;
21
+ in v_texCoord;
22
+ out vec4 outColor;
23
+ void main() {
24
+ vec4 color0 = texture(u_texture0, v_texCoord);
25
+ vec4 color1 = texture(u_texture1, v_texCoord);
26
+ outColor = mix(color0, color1, u_ratio);
27
+ }
28
+ `;
29
+
30
+ export default class BlenderProgram {
31
+ constructor(gl) {
32
+ this.gl = gl;
33
+ this.programWrapper = this._createProgramWrapper();
34
+ }
35
+
36
+
37
+
38
+ _craeteProgramWrapper() {
39
+
40
+ const gl = this.gl;
41
+
42
+ const program = createProgram(gl, vertexShader, fragmentShader);
43
+
44
+ this.vao = gl.createVertexArray();
45
+ gl.bindVertexArray(this.vao);
46
+ this._buffer = gl.createBuffer();
47
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._buffer);
48
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
49
+ -1, -1,
50
+ 1, -1,
51
+ -1, 1,
52
+ -1, 1,
53
+ 1, -1,
54
+ 1, 1,
55
+ ]), gl.STATIC_DRAW);
56
+ gl.enableVertexAttribArray(0);
57
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
58
+ gl.bindVertexArray(null);
59
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
60
+ return { program, uniforms: { u_texture0: gl.getUniformLocation(program, 'u_texture0'), u_texture1: gl.getUniformLocation(program, 'u_texture1'), u_ratio: gl.getUniformLocation(program, 'u_ratio') } };
61
+ }
62
+
63
+ draw(ratio, texture0, texture1) {
64
+ const gl = this.gl;
65
+ gl.useProgram(this.programWrapper.program);
66
+ gl.bindVertexArray(this.vao);
67
+ gl.activeTexture(gl.TEXTURE1);
68
+ gl.bindTexture(gl.TEXTURE_2D, texture1);
69
+ gl.uniform1i(this.programWrapper.uniforms.u_texture1, 1);
70
+ gl.activeTexture(gl.TEXTURE0);
71
+ gl.bindTexture(gl.TEXTURE_2D, texture0);
72
+ gl.uniform1i(this.programWrapper.uniforms.u_texture0, 0);
73
+ gl.uniform1f(this.programWrapper.uniforms.u_ratio, ratio);
74
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
75
+ gl.bindVertexArray(null);
76
+ }
77
+
78
+ createFloat32Texture(width, height) {
79
+ const gl = this.gl;
80
+ const texture = gl.createTexture();
81
+ gl.bindTexture(gl.TEXTURE_2D, texture);
82
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, width, height, 0, gl.RED, gl.FLOAT, null);
83
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
84
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
85
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
86
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
87
+ return texture;
88
+ }
89
+ }
90
+
91
+
@@ -0,0 +1,3 @@
1
+ import FadeAway from './object';
2
+
3
+ export default FadeAway;
@@ -0,0 +1,76 @@
1
+ import { createProgram } from "../../../util";
2
+
3
+
4
+ const vertexShaderSource = `#version 300 es
5
+ precision highp float;
6
+ in vec2 a_position;
7
+ out vec2 v_texCoord;
8
+ void main() {
9
+ gl_Position = vec4(a_position, 0.0, 1.0);
10
+ v_texCoord = a_position * 0.5 + vec2(0.5);
11
+ }
12
+ `;
13
+
14
+ const fragmentShaderSource = `#version 300 es
15
+ precision highp float;
16
+ uniform float opacity;
17
+ uniform sampler2D u_texture;
18
+ in vec2 v_texCoord;
19
+ out vec4 outColor;
20
+ void main() {
21
+
22
+ vec4 color = texture(u_texture, v_texCoord);
23
+ if (color.a <= 0.2) {
24
+ outColor = vec4(0.0);
25
+ return;
26
+ }
27
+ outColor = vec4(color.rgb, color.a * opacity);
28
+ }
29
+ `
30
+
31
+ export default class FadeAwayProgram {
32
+ constructor(gl) {
33
+ this.gl = gl;
34
+ this.program = createProgram(gl, vertexShaderSource, fragmentShaderSource);
35
+ this.vao = gl.createVertexArray();
36
+ gl.bindVertexArray(this.vao);
37
+ this._buffer = gl.createBuffer();
38
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._buffer);
39
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
40
+ -1, -1,
41
+ 1, -1,
42
+ -1, 1,
43
+ -1, 1,
44
+ 1, -1,
45
+ 1, 1,
46
+ ]), gl.STATIC_DRAW);
47
+ gl.enableVertexAttribArray(0);
48
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
49
+ gl.bindVertexArray(null);
50
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
51
+
52
+ this.uniforms = {
53
+ u_texture: gl.getUniformLocation(this.program, 'u_texture'),
54
+ opacity: gl.getUniformLocation(this.program, 'opacity')
55
+ };
56
+ }
57
+
58
+ draw(texture, opacity) {
59
+ const { gl, vao, uniforms, program } = this;
60
+ gl.useProgram(program);
61
+ gl.bindVertexArray(vao);
62
+ gl.uniform1f(uniforms.opacity, opacity);
63
+ gl.uniform1i(uniforms.u_texture, 0);
64
+ gl.activeTexture(gl.TEXTURE0);
65
+ gl.bindTexture(gl.TEXTURE_2D, texture);
66
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
67
+ gl.bindVertexArray(null);
68
+ }
69
+
70
+ free() {
71
+ const { gl, vao, _buffer, program } = this;
72
+ gl.deleteVertexArray(vao);
73
+ gl.deleteProgram(program);
74
+ gl.deleteBuffer(_buffer);
75
+ }
76
+ }
@@ -0,0 +1,20 @@
1
+
2
+ import { glProgramCache } from "../../programcache";
3
+ import FadeAwayProgram from "./logic";
4
+
5
+ export default class FadeAway {
6
+
7
+ constructor(gl) {
8
+ this.gl = gl;
9
+ this.program = glProgramCache.getProgram(gl, FadeAwayProgram);
10
+ }
11
+
12
+ draw(sourceTexture, opacity) {
13
+ this.program.draw(sourceTexture, opacity);
14
+ }
15
+
16
+
17
+ free() {
18
+ glProgramCache.releaseProgram(FadeAwayProgram);
19
+ }
20
+ }
@@ -0,0 +1,2 @@
1
+ import FadeAway from './fadeaway';
2
+ export { FadeAway };
@@ -0,0 +1,21 @@
1
+ import { Float2LegendWithRatio } from "./float2legendwithratio";
2
+ import { GlobeShellWiggle } from "./globeshell/wiggle";
3
+ import { CameraUniformBlockTotem, CameraUniformBlockString } from "./totems/index";
4
+ import ArrowField from "./arrowfield";
5
+ import { glProgramCache, globeProgramCache, noRegisterGlobeProgramCache } from "./programcache";
6
+ import * as vectorfield from "./vectorfields";
7
+ import { FadeAway } from "./helpers";
8
+ import rings from "./rings";
9
+ export {
10
+ Float2LegendWithRatio,
11
+ GlobeShellWiggle,
12
+ ArrowField,
13
+ CameraUniformBlockTotem,
14
+ CameraUniformBlockString,
15
+ glProgramCache,
16
+ globeProgramCache,
17
+ noRegisterGlobeProgramCache,
18
+ vectorfield,
19
+ FadeAway,
20
+ rings
21
+ };