@pirireis/webglobeplugins 0.6.49-a → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Math/angle-calculation.js +4 -2
- package/Math/methods.js +196 -0
- package/index.js +2 -1
- package/package.json +1 -1
- package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +78 -0
- package/point-heat-map/index.js +3 -0
- package/point-heat-map/plugin-webworker.js +166 -0
- package/point-heat-map/plugin.js +134 -0
- package/point-heat-map/point-to-heat-map-flow.js +155 -0
- package/point-heat-map/readme.md +15 -0
- package/programs/data2legend/density-to-legend.js +115 -0
- package/programs/data2legend/point-to-density-texture.js +114 -0
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +4 -4
- package/timetracks/adaptors-line-strip.js +1 -1
- package/timetracks/program-line-strip.js +1 -1
- package/timetracks/program.js +1 -1
- package/timetracks/programpoint-line-strip.js +1 -1
- package/timetracks/programpoint.js +1 -1
- package/timetracks/readme.md +1 -0
- package/util/algorithms/index.js +0 -0
- package/util/algorithms/search-binary.js +26 -0
- package/util/interpolation/index.js +0 -0
- package/util/interpolation/timetrack/index.js +9 -0
- package/util/interpolation/timetrack/timetrack-interpolator.js +89 -0
- package/util/interpolation/timetrack/web-worker-str.js +176 -0
- package/util/interpolation/timetrack/web-worker.js +46 -0
- package/util/programs/draw-texture-on-canvas.js +103 -0
- package/util/programs/texturetoglobe.js +1 -1
- package/util/webglobe/gldefaultstates.js +2 -1
- package/waveparticles/plugin.js +0 -2
- package/wind/index.js +0 -2
- package/wind/plugin.js +1 -1
- package/write-text/context-text3.js +1 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const webworkerStr = `
|
|
2
|
+
|
|
3
|
+
const WORLD_RADIUS_3D = 6378.137;
|
|
4
|
+
const WORLD_RADIUS_MERCATOR = 6378136.99911;
|
|
5
|
+
|
|
6
|
+
const dot3 = (a, b) => {
|
|
7
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const sphericalLinearInterpolation_UnitVector = (normalizedA, normalizedB, ratio) => {
|
|
11
|
+
const theta = Math.acos(dot3(normalizedA, normalizedB));
|
|
12
|
+
if (theta < 0.000001) return normalizedA; // CALIBRATE?
|
|
13
|
+
const sinTheta = Math.sin(theta);
|
|
14
|
+
const result = [
|
|
15
|
+
(Math.sin((1.0 - ratio) * theta) * normalizedA[0] + Math.sin(ratio * theta) * normalizedB[0]) / sinTheta,
|
|
16
|
+
(Math.sin((1.0 - ratio) * theta) * normalizedA[1] + Math.sin(ratio * theta) * normalizedB[1]) / sinTheta,
|
|
17
|
+
(Math.sin((1.0 - ratio) * theta) * normalizedA[2] + Math.sin(ratio * theta) * normalizedB[2]) / sinTheta
|
|
18
|
+
];
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const radianToMercator = (xy) => {
|
|
23
|
+
return [WORLD_RADIUS_MERCATOR * xy[0], WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + xy[1] / 2))];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const cartesian3dToRadian = (cartesian) => {
|
|
28
|
+
const x = cartesian[0];
|
|
29
|
+
const y = cartesian[1];
|
|
30
|
+
const z = cartesian[2];
|
|
31
|
+
// const length = Math.sqrt(x * x + y * y + z * z);
|
|
32
|
+
const long = Math.atan2(y, x);
|
|
33
|
+
const lat = Math.asin(z)// length);
|
|
34
|
+
return [long, lat];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const sphericalLinearInterpolation_Mercator = (normalizedA, normalizedB, ratio) => {
|
|
39
|
+
const unitVector = sphericalLinearInterpolation_UnitVector(normalizedA, normalizedB, ratio);
|
|
40
|
+
const angles = cartesian3dToRadian(unitVector);
|
|
41
|
+
return radianToMercator(angles);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const sphericalLinearInterpolation_Cartesian3d = (a, b, ratio) => {
|
|
45
|
+
const unitVector = sphericalLinearInterpolation_UnitVector(a, b, ratio);
|
|
46
|
+
const height = a[3] + (b[3] - a[3]) * ratio;
|
|
47
|
+
return [unitVector[0] * height, unitVector[1] * height, unitVector[2] * height];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const findFirstIndexInRange = (container, value) => {
|
|
51
|
+
let start = 0;
|
|
52
|
+
let end = container.length - 1;
|
|
53
|
+
let mid = 0;
|
|
54
|
+
while (start <= end) {
|
|
55
|
+
mid = Math.floor((start + end) / 2);
|
|
56
|
+
if (container[mid] <= value && value <= container[mid + 1]) return mid;
|
|
57
|
+
if (container[mid] < value) start = mid + 1;
|
|
58
|
+
else end = mid - 1;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const GEOMETRY = Object.freeze({
|
|
64
|
+
CARTESIAN3D: 0,
|
|
65
|
+
MERCATOR: 1,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
class TimeTrackInterpolator {
|
|
69
|
+
/**
|
|
70
|
+
* @typedef Timetrack
|
|
71
|
+
* @property {Array<vec4>}} coordinates [x,y,z, length]
|
|
72
|
+
* @property {Array<Number>} times
|
|
73
|
+
* @param {Array<Timetrack>} timeTracks
|
|
74
|
+
*/
|
|
75
|
+
constructor({ timeTracks, bbox = null, geometry = GEOMETRY.CARTESIAN3D } = {}) {
|
|
76
|
+
this.timeTracks = null;
|
|
77
|
+
this.timeTracksStartTimes = null;
|
|
78
|
+
this.geometry = geometry;
|
|
79
|
+
if (timeTracks) this.setTimetracks(timeTracks);
|
|
80
|
+
if (bbox) this.setBbox(bbox);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
setGeometry(geometry) {
|
|
85
|
+
if (geometry !== GEOMETRY.CARTESIAN3D && geometry !== GEOMETRY.MERCATOR) {
|
|
86
|
+
throw new Error('Invalid geometry');
|
|
87
|
+
}
|
|
88
|
+
this.geometry = geometry;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setTimetracks(timeTracks) {
|
|
92
|
+
console.log("timetracks:", timeTracks);
|
|
93
|
+
this.timeTracks = timeTracks;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
interpolate(time) {
|
|
98
|
+
const { timeTracks, geometry } = this;
|
|
99
|
+
if (!timeTracks) { return null; }
|
|
100
|
+
const resultArray = [];
|
|
101
|
+
const info = {
|
|
102
|
+
outOfRange: 0,
|
|
103
|
+
processed: 0,
|
|
104
|
+
}
|
|
105
|
+
for (let i = 0; i < timeTracks.length; i++) {
|
|
106
|
+
const { times, coordinates } = timeTracks[i];
|
|
107
|
+
|
|
108
|
+
if (times[times.length - 1] < time) continue;
|
|
109
|
+
info.processed++;
|
|
110
|
+
const timeIndex = findFirstIndexInRange(times, time);
|
|
111
|
+
if (timeIndex === null) { info.outOfRange++; continue; }
|
|
112
|
+
const timeFraction = (time - times[timeIndex]) / (times[timeIndex + 1] - times[timeIndex]);
|
|
113
|
+
const interpolated = (geometry === GEOMETRY.CARTESIAN3D) ?
|
|
114
|
+
sphericalLinearInterpolation_Cartesian3d(coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction) :
|
|
115
|
+
sphericalLinearInterpolation_Mercator(coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction);
|
|
116
|
+
resultArray.push(...interpolated);
|
|
117
|
+
}
|
|
118
|
+
return new Float32Array(resultArray);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
// implicit methods
|
|
123
|
+
|
|
124
|
+
_orderTimeTracks() {
|
|
125
|
+
this.timeTracks.sort((a, b) => a.times[0] - b.times[0]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_setStartTimes() {
|
|
129
|
+
this.timeTracksStartTimes = this.timeTracks.map(tt => tt.times[0]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const interpolator = new TimeTrackInterpolator({ geometry: GEOMETRY.CARTESIAN3D });
|
|
134
|
+
|
|
135
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
136
|
+
self.onmessage = function (e) {
|
|
137
|
+
|
|
138
|
+
const { geometry = null, timeTracks = null, time = null } = e.data;
|
|
139
|
+
|
|
140
|
+
if (geometry !== null) {
|
|
141
|
+
try {
|
|
142
|
+
interpolator.setGeometry(geometry);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
145
|
+
self.postMessage({ error: error.message });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (timeTracks !== null) {
|
|
151
|
+
try {
|
|
152
|
+
interpolator.setTimetracks(timeTracks);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
155
|
+
self.postMessage({ error: error.message });
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (time !== null) {
|
|
161
|
+
try {
|
|
162
|
+
const result = interpolator.interpolate(time);
|
|
163
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
164
|
+
self.postMessage(result, [result.buffer]);
|
|
165
|
+
return;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
168
|
+
self.postMessage({ error: error.message });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
173
|
+
self.postMessage(true);
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
export { webworkerStr };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { TimeTrackInterpolator, GEOMETRY } from './timetrack-interpolator';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const interpolator = new TimeTrackInterpolator({ geometry: GEOMETRY.CARTESIAN3D });
|
|
5
|
+
|
|
6
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
7
|
+
self.onmessage = function (e) {
|
|
8
|
+
|
|
9
|
+
const { geometry = null, timeTracks = null, time = null } = e.data;
|
|
10
|
+
|
|
11
|
+
if (geometry !== null) {
|
|
12
|
+
try {
|
|
13
|
+
interpolator.setGeometry(geometry);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
16
|
+
self.postMessage({ error: error.message });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (timeTracks !== null) {
|
|
22
|
+
try {
|
|
23
|
+
interpolator.setTimetracks(timeTracks);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
26
|
+
self.postMessage({ error: error.message });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (time !== null) {
|
|
32
|
+
try {
|
|
33
|
+
const result = interpolator.interpolate(time);
|
|
34
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
35
|
+
self.postMessage(result, [result.buffer]);
|
|
36
|
+
return;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
39
|
+
self.postMessage({ error: error.message });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/* eslint-disable-next-line no-restricted-globals */
|
|
44
|
+
self.postMessage(true);
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createProgram } from "../webglobjectbuilders";
|
|
2
|
+
import { noRegisterGlobeProgramCache } from "../../programs";
|
|
3
|
+
// import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../../programs/totems";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const vs = `#version 300 es
|
|
7
|
+
precision highp float;
|
|
8
|
+
|
|
9
|
+
in vec2 a_position;
|
|
10
|
+
out vec2 v_texcoord;
|
|
11
|
+
|
|
12
|
+
void main() {
|
|
13
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
14
|
+
v_texcoord = a_position * 0.5 + 0.5;
|
|
15
|
+
}`;
|
|
16
|
+
|
|
17
|
+
const fs = `#version 300 es
|
|
18
|
+
precision highp float;
|
|
19
|
+
|
|
20
|
+
uniform sampler2D u_texture;
|
|
21
|
+
uniform float u_opacity;
|
|
22
|
+
in vec2 v_texcoord;
|
|
23
|
+
out vec4 fragColor;
|
|
24
|
+
|
|
25
|
+
void main() {
|
|
26
|
+
fragColor = texture(u_texture, v_texcoord);
|
|
27
|
+
fragColor.a *= u_opacity;
|
|
28
|
+
}`;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class TextureOnCanvasProgram {
|
|
33
|
+
constructor(globe) {
|
|
34
|
+
this.globe = globe;
|
|
35
|
+
this.gl = globe.gl;
|
|
36
|
+
|
|
37
|
+
this.vao = this.gl.createVertexArray();
|
|
38
|
+
this.buffer = this.gl.createBuffer();
|
|
39
|
+
this.gl.bindVertexArray(this.vao);
|
|
40
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffer);
|
|
41
|
+
this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array([
|
|
42
|
+
-1, -1,
|
|
43
|
+
1, -1,
|
|
44
|
+
1, 1,
|
|
45
|
+
-1, 1
|
|
46
|
+
]), this.gl.STATIC_DRAW);
|
|
47
|
+
this.gl.enableVertexAttribArray(0);
|
|
48
|
+
this.gl.vertexAttribPointer(0, 2, this.gl.FLOAT, false, 0, 0);
|
|
49
|
+
this.gl.bindVertexArray(null);
|
|
50
|
+
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);
|
|
51
|
+
|
|
52
|
+
this.program = createProgram(this.gl, vs, fs);
|
|
53
|
+
|
|
54
|
+
{
|
|
55
|
+
const { gl, program } = this;
|
|
56
|
+
this.uniforms = {
|
|
57
|
+
texture: gl.getUniformLocation(program, "u_texture"),
|
|
58
|
+
opacity: gl.getUniformLocation(program, "u_opacity"),
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
{
|
|
62
|
+
this._lastOpacity = 1.0;
|
|
63
|
+
const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
|
|
64
|
+
this.gl.useProgram(this.program);
|
|
65
|
+
this.gl.uniform1f(this.uniforms.opacity, this._lastOpacity);
|
|
66
|
+
this.gl.useProgram(currentProgram);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
draw(texture, { opacity = 1.0 } = {}) {
|
|
72
|
+
|
|
73
|
+
const { gl, program, uniforms, vao } = this;
|
|
74
|
+
gl.useProgram(program);
|
|
75
|
+
gl.bindVertexArray(vao);
|
|
76
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
77
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
78
|
+
gl.uniform1i(uniforms.texture, 0);
|
|
79
|
+
if (this._lastOpacity !== opacity) {
|
|
80
|
+
gl.uniform1f(uniforms.opacity, opacity);
|
|
81
|
+
this._lastOpacity = opacity;
|
|
82
|
+
}
|
|
83
|
+
gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
|
|
84
|
+
gl.bindVertexArray(null);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
free() {
|
|
88
|
+
if (this._isFreed) return;
|
|
89
|
+
this.gl.deleteVertexArray(this.vao);
|
|
90
|
+
this.gl.deleteBuffer(this.buffer);
|
|
91
|
+
this.gl.deleteProgram(this.program);
|
|
92
|
+
this._isFreed = true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const textureOnCanvasProgramCache = Object.freeze({
|
|
98
|
+
get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, TextureOnCanvasProgram),
|
|
99
|
+
release: (program) => noRegisterGlobeProgramCache.releaseProgram(program)
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export { textureOnCanvasProgramCache };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
export function defaultblendfunction(gl) {
|
|
3
|
-
gl.
|
|
3
|
+
gl.blendEquation(gl.FUNC_ADD); // TODO: TESTING THIS
|
|
4
|
+
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
4
5
|
}
|
package/waveparticles/plugin.js
CHANGED
|
@@ -54,8 +54,6 @@ export default class Plugin {
|
|
|
54
54
|
this.gl = gl;
|
|
55
55
|
this.moveParticle = new MoveParticle(gl);
|
|
56
56
|
this.drawParticle = new DrawParticle(gl);
|
|
57
|
-
// this.moveParticle = glProgramCache.getProgram(gl, MoveParticle); // TODO: create with glProgramCache and free later on.
|
|
58
|
-
// this.drawParticle = glProgramCache.getProgram(gl, DrawParticle);
|
|
59
57
|
|
|
60
58
|
|
|
61
59
|
this.fadeAway = new FadeAway(gl);
|
package/wind/index.js
CHANGED
|
@@ -3,5 +3,3 @@ import createVectorFieldImage from "./vectorfieldimage";
|
|
|
3
3
|
import imageToMagnitude from "./imagetovectorfieldandmagnitude";
|
|
4
4
|
import { createImageFromBase64 } from "../util/webglobjectbuilders";
|
|
5
5
|
export { createVectorFieldImage, imageToMagnitude, WindPlugin, createImageFromBase64 };
|
|
6
|
-
|
|
7
|
-
// TODO: image resmindeki degerlerden ruzgar siddetinin magnitudunun hesaplanip float32array donderen bir fonksiyonun yazilmasi gerekiyor
|
package/wind/plugin.js
CHANGED
|
@@ -486,7 +486,7 @@ export default class WindPlugin {
|
|
|
486
486
|
if (gl == null) {
|
|
487
487
|
throw new Error("wind plugin. setColorRampFromService is called before plugin is registered.");
|
|
488
488
|
}
|
|
489
|
-
const { thresholds, values } = legendData;
|
|
489
|
+
const { thresholds, values } = legendData;
|
|
490
490
|
if (thresholds.length == 0 || values.length == 0) {
|
|
491
491
|
return;
|
|
492
492
|
}
|