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