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