@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,281 @@
1
+ import { GlobeShellWiggle } from "../programs";
2
+ import { defaultblendfunction } from "../util";
3
+ import { vectorfield } from "../programs";
4
+ import { FadeAway } from "../programs";
5
+ const { PixelBasedMove, DrawRectangleParticles, PingPongBufferManager, WaveParticalUboManager } = vectorfield;
6
+ const MoveParticle = PixelBasedMove;
7
+ const DrawParticle = DrawRectangleParticles;
8
+
9
+ /**
10
+ * STEPS:
11
+ * 1. move particle | buffers: read b1 write b2 | swap buffers b1 <-> b2
12
+ * 2. draw particles | read b1 to drawTexture1 |
13
+ * 3. globe shell drawTexture1
14
+ * 4. fade drawTexture1 to drawTexture2 | swap textures
15
+ *
16
+ */
17
+
18
+ const MAX_PIXELS_ON_DIMENSION = 2200;
19
+
20
+
21
+
22
+ export default class Plugin {
23
+ constructor(id, { fadeOpacity = 0.83, opacity = 0.75, minLon = -180, minLat = -90, maxLon = 180, maxLat = 90, patricleCount = 8000, dataWidth, dataHeight, drawTextureMaxPixelOnDimension = MAX_PIXELS_ON_DIMENSION } = {}) {
24
+
25
+ this.id = id;
26
+ this.globe = null;
27
+ this.gl = null;
28
+ this.moveParticle = null;
29
+ this.drawParticle = null;
30
+ this.bufferManager = null;
31
+ this._rgVectorFieldTexture = null;
32
+ this.globeShellWiggle = null;
33
+ this.waveUbo = null;
34
+ this._drawTextureResolution = {};
35
+ this._frameBuffer = null;
36
+ this._fadeOpacity = fadeOpacity;
37
+ this._opacity = opacity;
38
+ this._particleCount = patricleCount;
39
+ this._dataWidth = dataWidth;
40
+ this._dataHeight = dataHeight;
41
+ this._drawTextureMaxPixelOnDimension = drawTextureMaxPixelOnDimension;
42
+ this._globeshellparameters = {
43
+ minLon,
44
+ maxLon,
45
+ minLat,
46
+ maxLat,
47
+ }
48
+ this._stepIndex = 0;
49
+ this._fullCycleStepCount = 3;
50
+ }
51
+
52
+ init(globe, gl) {
53
+ this.globe = globe;
54
+ this.gl = gl;
55
+ this.moveParticle = new MoveParticle(gl);
56
+ this.drawParticle = new DrawParticle(gl);
57
+ // this.moveParticle = glProgramCache.getProgram(gl, MoveParticle); // TODO: create with glProgramCache and free later on.
58
+ // this.drawParticle = glProgramCache.getProgram(gl, DrawParticle);
59
+
60
+
61
+ this.fadeAway = new FadeAway(gl);
62
+
63
+ this.globeShellWiggle = new GlobeShellWiggle(gl, globe, this._globeshellparameters);
64
+ const inPositionLocation = this.moveParticle.getInPositionLocation();
65
+ this.bufferManager = new PingPongBufferManager(gl, this._particleCount, inPositionLocation);
66
+
67
+ this._rgVectorFieldTexture = this._createRGTexture();
68
+
69
+ this.waveUbo = new WaveParticalUboManager(gl, 0);
70
+
71
+ this._drawTextures = [this._createDrawTexture(), this._createDrawTexture()];
72
+ this._frameBuffer = gl.createFramebuffer();
73
+ this.setBBox(this._globeshellparameters);
74
+ this.setOpacity(this._opacity);
75
+ this.____drawIndex = 0;
76
+
77
+ }
78
+
79
+ _createDrawTexture() {
80
+ const gl = this.gl
81
+ const texture = gl.createTexture();
82
+ gl.bindTexture(gl.TEXTURE_2D, texture);
83
+ // gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2200, 2200, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
84
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._drawTextureResolution.width, this._drawTextureResolution.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
85
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
86
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
87
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
88
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
89
+ gl.bindTexture(gl.TEXTURE_2D, null);
90
+ return texture;
91
+ }
92
+
93
+
94
+ _step() {
95
+ this._stepIndex = (this._stepIndex + 1) % this._fullCycleStepCount;
96
+ }
97
+
98
+ draw3D() {
99
+ const { gl, moveParticle, drawParticle, bufferManager, globeShellWiggle, waveUbo, fadeAway, _rgVectorFieldTexture } = this;
100
+
101
+ gl.disable(gl.DEPTH_TEST);
102
+ if (this._stepIndex === 0) {
103
+ waveUbo.update({ random_seed: Math.random() });
104
+ moveParticle.move(bufferManager, _rgVectorFieldTexture, waveUbo);
105
+ // 1s swap buffer b1 <-> b2
106
+ bufferManager.swap();
107
+ } else if (this._stepIndex === 1) {
108
+ this.____drawIndex = 1 - this.____drawIndex;
109
+ const canvasWidth = gl.canvas.width;
110
+ const canvasHeight = gl.canvas.height;
111
+ // gl.viewport(0, 0, 2200, 2200);
112
+ gl.viewport(0, 0, this._drawTextureResolution.width, this._drawTextureResolution.height);
113
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
114
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._drawTextures[this.____drawIndex], 0);
115
+ drawParticle.draw(bufferManager, _rgVectorFieldTexture, waveUbo);
116
+ // 2s bound frame buffer to null
117
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
118
+ gl.viewport(0, 0, canvasWidth, canvasHeight);
119
+ } else {
120
+ const canvasWidth = gl.canvas.width;
121
+ const canvasHeight = gl.canvas.height;
122
+ // gl.viewport(0, 0, 2200, 2200);
123
+ gl.viewport(0, 0, this._drawTextureResolution.width, this._drawTextureResolution.height);
124
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
125
+ gl.enable(gl.BLEND);
126
+ // gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
127
+ gl.blendFunc(gl.ONE, gl.ZERO)
128
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._drawTextures[1 - this.____drawIndex], 0);
129
+ fadeAway.draw(this._drawTextures[this.____drawIndex], this._fadeOpacity);
130
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
131
+ defaultblendfunction(gl);
132
+ gl.viewport(0, 0, canvasWidth, canvasHeight);
133
+ }
134
+
135
+ globeShellWiggle.setTexture(this._drawTextures[this.____drawIndex]);
136
+ globeShellWiggle.draw();
137
+ this._step();
138
+ gl.enable(gl.DEPTH_TEST);
139
+ }
140
+
141
+
142
+ setCycleStepCount(value) {
143
+ if (value < 3) {
144
+ this._fullCycleStepCount = 3;
145
+ }
146
+ this._fullCycleStepCount = value;
147
+ }
148
+
149
+ _createRGTexture() {
150
+ const { gl, _dataWidth, _dataHeight } = this;
151
+ const texture = gl.createTexture();
152
+ // R32F
153
+ gl.bindTexture(gl.TEXTURE_2D, texture);
154
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, _dataWidth, _dataHeight, 0, gl.RG, gl.FLOAT, null);
155
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
156
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
157
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
158
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
159
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
160
+
161
+ gl.bindTexture(gl.TEXTURE_2D, null);
162
+ return texture;
163
+ }
164
+
165
+ // TODO: free all resources
166
+ free() {
167
+ const { gl, fadeAway, globeShellWiggle, _rgVectorFieldTexture, bufferManager, waveUbo, _drawTextures, _frameBuffer } = this;
168
+ fadeAway.free();
169
+ globeShellWiggle.free();
170
+ gl.deleteTexture(_rgVectorFieldTexture);
171
+ // glProgramCache.releaseProgram(gl, MoveParticle);
172
+ this.moveParticle.free();
173
+ this.moveParticle = null
174
+ // glProgramCache.releaseProgram(gl, DrawParticle);
175
+ this.drawParticle.free();
176
+ this.drawParticle = null
177
+ bufferManager.free();
178
+ waveUbo.free();
179
+ _drawTextures.forEach(texture => gl.deleteTexture(texture));
180
+ gl.deleteFramebuffer(_frameBuffer);
181
+ }
182
+
183
+
184
+ // setters
185
+ setParticleCount(value) {
186
+ this._particleCount = value;
187
+ this.bufferManager.setParticleCount(value);
188
+ }
189
+
190
+
191
+ setVectorFieldData(data, dataWidth = null, dataHeight = null) {
192
+ if (dataWidth !== null && dataHeight !== null) {
193
+ this._dataWidth = dataWidth;
194
+ this._dataHeight = dataHeight;
195
+ }
196
+ const { gl, _dataWidth, _dataHeight } = this;
197
+ gl.bindTexture(gl.TEXTURE_2D, this._rgVectorFieldTexture);
198
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, _dataWidth, _dataHeight, 0, gl.RG, gl.FLOAT, data);
199
+ gl.bindTexture(gl.TEXTURE_2D, null);
200
+ }
201
+
202
+
203
+ setHeight(value) {
204
+ this.globeShellWiggle.setHeight(value);
205
+ }
206
+
207
+ setDropRate(value) {
208
+ this.waveUbo.update({ drop_rate: value });
209
+ }
210
+
211
+
212
+
213
+ _drawTextureSizeFromBbox({ minLon, minLat, maxLon, maxLat }) {
214
+ let horizon;
215
+ if (minLon > 0 && maxLon < 0) {
216
+ horizon = 360 - minLon + maxLon;
217
+ } else {
218
+ horizon = maxLon - minLon;
219
+ }
220
+ const vertical = maxLat - minLat;
221
+ let width, height;
222
+ if (horizon > vertical) {
223
+ width = this._drawTextureMaxPixelOnDimension;
224
+ height = Math.floor(this._drawTextureMaxPixelOnDimension * vertical / horizon);
225
+ } else {
226
+ height = this._drawTextureMaxPixelOnDimension;
227
+ width = Math.floor(this._drawTextureMaxPixelOnDimension * horizon / vertical);
228
+ }
229
+ return {
230
+ width,
231
+ height
232
+ }
233
+
234
+ }
235
+
236
+
237
+ setDrawTextureMaxPixelOnDimension(value) {
238
+ this._drawTextureMaxPixelOnDimension = value;
239
+ this._drawTextureResolution = this._drawTextureSizeFromBbox(this._globeshellparameters);
240
+ this.waveUbo.update({ draw_texture_size: [this._drawTextureResolution.width, this._drawTextureResolution.height] });
241
+ this._drawTextures = [this._createDrawTexture(), this._createDrawTexture()];
242
+ }
243
+
244
+ setParticleSpeed(value) {
245
+ this.waveUbo.update({ range: value });
246
+ }
247
+
248
+ setFadeOpacity(value) {
249
+ this._fadeOpacity = value;
250
+ }
251
+
252
+ setOpacity(value) {
253
+ this.globeShellWiggle.setOpacity(value);
254
+ }
255
+
256
+ setParticleDimensions(tail, wing) {
257
+ if (0 < tail || 0 < wing) {
258
+ this.waveUbo.update({ base_limp: [tail, wing] });
259
+ } else {
260
+ console.error("tail and wing must be greater than 0");
261
+ }
262
+ }
263
+
264
+ setParticleColor(color) {
265
+ if (color.length !== 3) {
266
+ console.error("color must be an array of rgb elements");
267
+ return;
268
+ }
269
+ this.waveUbo.update({ color });
270
+ }
271
+
272
+
273
+ setBBox({ minLon, minLat, maxLon, maxLat }) {
274
+ this._globeshellparameters = { minLon, minLat, maxLon, maxLat };
275
+ this.globeShellWiggle.setBBox({ minLon, minLat, maxLon, maxLat });
276
+ this._drawTextureResolution = this._drawTextureSizeFromBbox({ minLon, minLat, maxLon, maxLat });
277
+ this.waveUbo.update({ draw_texture_size: [this._drawTextureResolution.width, this._drawTextureResolution.height] });
278
+ this._drawTextures = [this._createDrawTexture(), this._createDrawTexture()];
279
+ }
280
+ }
281
+
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @param {ImageData} imageData
3
+ * image
4
+ * uMax
5
+ * vMax
6
+ * height
7
+ * width
8
+ * @returns {Float32Array}
9
+ */
10
+ export default function imageToMagnitude(imageData) {
11
+ const { image, uMax, vMax, uMin, vMin, height, width } = imageData;
12
+
13
+
14
+
15
+ const canvas = document.createElement('canvas');
16
+ const ctx = canvas.getContext('2d');
17
+ canvas.width = width;
18
+ canvas.height = height;
19
+ ctx.drawImage(image, 0, 0, width, height);
20
+ const img = ctx.getImageData(0, 0, width, height);
21
+ const data = img.data;
22
+
23
+ const magnitudeArray = new Float32Array(height * width);
24
+
25
+ const uDiff = uMax - uMin;
26
+ const vDiff = vMax - vMin;
27
+
28
+ for (let i = 0; i < data.length; i += 4) {
29
+ const r = data[i];
30
+ const g = data[i + 1];
31
+ const u = uMin + (uDiff * r) / 255;
32
+ const v = vMin + (vDiff * g) / 255;
33
+ const magnitude = Math.sqrt(u * u + v * v);
34
+ const index = i / 4;
35
+ magnitudeArray[index] = magnitude;
36
+ }
37
+
38
+ return magnitudeArray;
39
+ }
package/wind/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import WindPlugin from "./plugin";
2
+ import createVectorFieldImage from "./vectorfieldimage";
3
+ import imageToMagnitude from "./imagetovectorfieldandmagnitude";
4
+
5
+ export { createVectorFieldImage, imageToMagnitude, WindPlugin };
6
+
7
+ // TODO: image resmindeki degerlerden ruzgar siddetinin magnitudunun hesaplanip float32array donderen bir fonksiyonun yazilmasi gerekiyor