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