@pirireis/webglobeplugins 0.7.1 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -16,26 +16,14 @@ class PointHeatmapPlugin {
16
16
  this._legendTexture = null;
17
17
 
18
18
  this._throttleListener = null;
19
-
20
- try {
21
-
22
- this.timeTrackInterpolationWorker = new Worker(
23
- new URL(
24
- '../util/interpolation/timetrack/web-worker.js',
25
- import.meta.url
26
- ), { type: 'module' }
27
- );
28
- } catch (e) {
29
- console.log(e);
30
- const blob = new Blob([webworkerStr], { type: 'application/javascript' });
31
- this.timeTrackInterpolationWorker = new Worker(URL.createObjectURL(blob), { type: 'module' });
32
- }
19
+ const blob = new Blob([webworkerStr], { type: 'application/javascript' });
20
+ this.timeTrackInterpolationWorker = new Worker(URL.createObjectURL(blob), { type: 'module' });
33
21
  this.timeTrackInterpolationWorker.onmessage = (e) => {
34
22
  if (e.data.error) {
35
23
  throw new Error(e.data.error);
36
24
  }
37
25
  if (e.data === true) {
38
- onInterpolationComplete()
26
+ onInterpolationComplete();
39
27
  }
40
28
  if (e.data instanceof Float32Array) {
41
29
  this.flow.setData(e.data);
@@ -13,7 +13,7 @@ class PointHeatmapFlow {
13
13
  this.gl = globe.gl;
14
14
  this.pointToDensityProgram = pointToDensityTextureCache.get(globe);
15
15
  this.densityToLegendProgram = densityToLegendProgramCache.get(globe);
16
- this.testTextureProgram = textureOnCanvasProgramCache.get(globe);
16
+ // this.testTextureProgram = textureOnCanvasProgramCache.get(globe);
17
17
  this._lookInfo = globe.api_GetCurrentLookInfo();
18
18
  const { gl } = this;
19
19
  {
@@ -51,11 +51,11 @@ class PointHeatmapFlow {
51
51
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
52
52
  }
53
53
  defaultblendfunction(gl);
54
- gl.viewport(0, 0, 400, 400);
55
- this.testTextureProgram.draw(legendTexture, 1.0);
56
- gl.viewport(0, 400, 400, 400);
57
- this.testTextureProgram.draw(this.densityTexture, 1.0);
58
- gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
54
+ // gl.viewport(0, 0, 400, 400);
55
+ // this.testTextureProgram.draw(legendTexture, 1.0);
56
+ // gl.viewport(0, 400, 400, 400);
57
+ // this.testTextureProgram.draw(this.densityTexture, 1.0);
58
+ // gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
59
59
  this._drawLegend(legendTexture, opacity);
60
60
  }
61
61
 
@@ -0,0 +1,3 @@
1
+ const pointKeyMeyhod = (trackId, pointID) => `${trackId}-${pointID}`;
2
+
3
+ export { pointKeyMeyhod };
@@ -0,0 +1,80 @@
1
+ import { BufferOrchestrator, BufferManager } from "../util/account";
2
+
3
+
4
+ /**
5
+ *
6
+ * @typedef { long ,lat, height, ID } Point
7
+ * @typedef {Array<Point>, rgba, TrackID} Track
8
+ */
9
+
10
+ class PointTracksPlugin {
11
+
12
+ constructor(id, { } = {}) {
13
+ this.id = id;
14
+ this._isFreed = false;
15
+ this._tracksInfoMap = new Map();
16
+
17
+ this.program = null
18
+ }
19
+
20
+
21
+ init(globe, gl) {
22
+
23
+ this.globe = globe;
24
+ this.gl = gl;
25
+
26
+ this._initBufferManagers();
27
+ }
28
+
29
+ _initBufferManagers() {
30
+
31
+
32
+ const { gl } = this;
33
+ const initialCapacity = 10;
34
+
35
+ this._bufferOrchestrator = new BufferOrchestrator({ initialCapacity });
36
+ this._bufferManagersMap = new Map(
37
+ [
38
+ ["pos3D", new BufferManager(gl, 3, { bufferType: gl.ARRAY_BUFFER, initialCapacity })],
39
+ ["pos2D", new BufferManager(gl, 2, { bufferType: gl.ARRAY_BUFFER, initialCapacity })],
40
+ ["rgba", new BufferManager(gl, 4, { bufferType: gl.ARRAY_BUFFER, initialCapacity })],
41
+ ]
42
+ );
43
+
44
+ this._vao = this.program.createVAO(
45
+ this._bufferManagersMap.get("pos3D"),
46
+ this._bufferManagersMap.get("pos2D"),
47
+ this._bufferManagersMap.get("rgba"),
48
+ );
49
+
50
+
51
+ }
52
+
53
+
54
+
55
+ /**
56
+ *
57
+ * @param {Array<Track>} tracks
58
+ *
59
+ * @returns
60
+ */
61
+ insertBulk(tracks) {
62
+ const { _bufferManagersMap, _bufferOrchestrator, _tracksInfoMap } = this;
63
+
64
+ const { pos3DIndex, pos2DIndex, rgbaIndex } = _bufferOrchestrator.insertBulk(tracks);
65
+ const trackID = tracks[0].trackID;
66
+ _tracksInfoMap.set(trackID, { pos3DIndex, pos2DIndex, rgbaIndex });
67
+ return trackID;
68
+ }
69
+
70
+
71
+ free() {
72
+ if (this._isFreed) return;
73
+ this._isFreed = true;
74
+ }
75
+
76
+
77
+
78
+
79
+
80
+ }
@@ -0,0 +1,148 @@
1
+ import { createProgram } from "../../util";
2
+ import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totems";
3
+ import { mercatorXYToGLPosition, cartesian3DToGLPosition } from "../../util/shaderfunctions/geometrytransformations";
4
+ import { noRegisterGlobeProgramCache } from "../programcache";
5
+
6
+
7
+ const vs = `#version 300 es
8
+ ${CameraUniformBlockString}
9
+ ${mercatorXYToGLPosition}
10
+ ${cartesian3DToGLPosition}
11
+ precision highp float;
12
+ precision highp int;
13
+
14
+ uniform int hovered_instanceID;
15
+
16
+ in vec3 pos3D;
17
+ in vec2 pos2D;
18
+ in vec4 rgba;
19
+
20
+
21
+ flat out highp int vInstanceID;
22
+
23
+
24
+ out vec4 v_rgba;
25
+
26
+ void main() {
27
+
28
+ if(is3D){
29
+ gl_Position = cartesian3DToGLPosition(pos3D);
30
+ }
31
+ else{
32
+ gl_Position = mercatorXYToGLPosition(pos2D);
33
+ }
34
+ if (hovered_instanceID == gl_InstanceID) {
35
+ gl_PointSize = 3.0;
36
+ } else {
37
+ gl_PointSize = 1.0;
38
+ v_rgba = rgba;
39
+ }`;
40
+
41
+ const fs = `#version 300 es
42
+ precision highp float;
43
+
44
+ uniform opacity;
45
+
46
+ flat in highp int vInstanceID;
47
+
48
+ in vec4 v_rgba;
49
+
50
+ layout(location = 0) out vec4 fragColor;
51
+ layout(location = 1) out int instanceID;
52
+
53
+ void main() {
54
+ fragColor = v_rgba;
55
+ fragColor.a *= opacity;
56
+ instanceID = vInstanceID;
57
+ }`;
58
+
59
+
60
+ class PointOnGlobeProgram {
61
+
62
+ constructor(globe) {
63
+
64
+ this.globe = globe;
65
+ this.gl = globe.gl;
66
+
67
+ this.program = createProgram(this.gl, vs, fs);
68
+
69
+ const { gl, program } = this;
70
+
71
+ this.uniforms = {
72
+ opacity: gl.getUniformLocation(program, "opacity"),
73
+ }
74
+
75
+ { // assign attribute locations
76
+ gl.bindAttribLocation(program, 0, "pos3D");
77
+ gl.bindAttribLocation(program, 1, "pos2D");
78
+ gl.bindAttribLocation(program, 2, "rgba");
79
+ }
80
+
81
+ { // arrange camera uniform block
82
+ this.cameraBlockBingingPoint = 0;
83
+ this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
84
+ const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
85
+ gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBingingPoint);
86
+ }
87
+ }
88
+
89
+
90
+ createVAO(pos3DBuffer, pos2DBuffer, rgbaBuffer) {
91
+ const { gl } = this;
92
+ const vao = gl.createVertexArray();
93
+ gl.bindVertexArray(vao);
94
+
95
+ {
96
+ gl.bindBuffer(gl.ARRAY_BUFFER, pos3DBuffer);
97
+ gl.enableVertexAttribArray(0);
98
+ gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
99
+ }
100
+ {
101
+ gl.bindBuffer(gl.ARRAY_BUFFER, pos2DBuffer);
102
+ gl.enableVertexAttribArray(1);
103
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
104
+ }
105
+ {
106
+ gl.bindBuffer(gl.ARRAY_BUFFER, rgbaBuffer);
107
+ gl.enableVertexAttribArray(2);
108
+ gl.vertexAttribPointer(2, 4, gl.FLOAT, false, 0, 0);
109
+ }
110
+
111
+ gl.bindVertexArray(null);
112
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
113
+ return vao;
114
+ }
115
+
116
+ draw(vao, length, { opacity = 1.0, frameBuffer = null } = {}) {
117
+ if (length === 0 || opacity === 0) return;
118
+ const { gl, program, uniforms } = this;
119
+ gl.useProgram(program);
120
+ gl.uniform1f(uniforms.opacity, opacity);
121
+ gl.bindVertexArray(vao);
122
+ if (frameBuffer) {
123
+ gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
124
+ gl.
125
+ gl.drawArrays(gl.POINTS, 0, length);
126
+ }
127
+ this.cameraBlockTotem.bind(this.cameraBlockBingingPoint);
128
+ gl.drawArrays(gl.POINTS, 0, length);
129
+ this.cameraBlockTotem.unbind(this.cameraBlockBingingPoint);
130
+ gl.bindVertexArray(null);
131
+ }
132
+
133
+ free() {
134
+ if (this._isFreed) return;
135
+ const { gl, globe } = this;
136
+ CameraUniformBlockTotemCache.release(globe);
137
+ gl.deleteProgram(this.program);
138
+ this._isFreed = true;
139
+ }
140
+ }
141
+
142
+
143
+ const pointOnGlobeProgramCache = Object.freeze({
144
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, PointOnGlobeProgram),
145
+ release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, PointOnGlobeProgram)
146
+ });
147
+
148
+ export { pointOnGlobeProgramCache };
@@ -190,36 +190,36 @@ export default class TrackGlowLineProgram {
190
190
  const gl = this.gl;
191
191
 
192
192
  const vertexShader = `#version 300 es
193
- precision highp float;
193
+ precision highp float;
194
194
 
195
- in vec2 a_position;
195
+ in vec2 a_position;
196
196
 
197
- out vec2 v_texcoord;
197
+ out vec2 v_texcoord;
198
198
 
199
- void main() {
200
- gl_Position = vec4(a_position, 0.0, 1.0);
201
- v_texcoord = a_position.xy * 0.5 + 0.5;
202
- }
199
+ void main() {
200
+ gl_Position = vec4(a_position, 0.0, 1.0);
201
+ v_texcoord = a_position.xy * 0.5 + 0.5;
202
+ }
203
203
  `;
204
204
 
205
205
  const fragmentShader = `#version 300 es
206
- precision highp float;
206
+ precision highp float;
207
207
 
208
- in vec2 v_texcoord;
208
+ in vec2 v_texcoord;
209
209
 
210
- uniform sampler2D u_main_texture;
211
-
210
+ uniform sampler2D u_main_texture;
212
211
 
213
- uniform float u_final_alpha_ratio;
214
212
 
215
- out vec4 outColor;
213
+ uniform float u_final_alpha_ratio;
216
214
 
217
- void main() {
215
+ out vec4 outColor;
218
216
 
219
- vec4 hdrColor = texture(u_main_texture, v_texcoord);
220
- outColor = hdrColor;
221
- outColor.a *= u_final_alpha_ratio;
222
- }
217
+ void main() {
218
+
219
+ vec4 hdrColor = texture(u_main_texture, v_texcoord);
220
+ outColor = hdrColor;
221
+ outColor.a *= u_final_alpha_ratio;
222
+ }
223
223
  `;
224
224
  const program = createProgram(this.gl, vertexShader, fragmentShader);
225
225
 
@@ -253,41 +253,41 @@ export default class TrackGlowLineProgram {
253
253
  const gl = this.gl;
254
254
 
255
255
  const vertexShader = `#version 300 es
256
- precision highp float;
256
+ precision highp float;
257
257
 
258
- in vec2 a_position;
258
+ in vec2 a_position;
259
259
 
260
- out vec2 v_texcoord;
260
+ out vec2 v_texcoord;
261
261
 
262
- void main() {
263
- gl_Position = vec4(a_position, 0.0, 1.0);
264
- v_texcoord = a_position.xy * 0.5 + 0.5;
265
- }
262
+ void main() {
263
+ gl_Position = vec4(a_position, 0.0, 1.0);
264
+ v_texcoord = a_position.xy * 0.5 + 0.5;
265
+ }
266
266
  `;
267
267
 
268
268
  const fragmentShader = `#version 300 es
269
- precision highp float;
269
+ precision highp float;
270
270
 
271
- in vec2 v_texcoord;
271
+ in vec2 v_texcoord;
272
272
 
273
- uniform sampler2D u_main_texture;
274
- uniform sampler2D u_bloom_texture;
273
+ uniform sampler2D u_main_texture;
274
+ uniform sampler2D u_bloom_texture;
275
275
 
276
- uniform float u_exposure;
277
- uniform float u_gamma;
278
- uniform float u_final_alpha_ratio;
276
+ uniform float u_exposure;
277
+ uniform float u_gamma;
278
+ uniform float u_final_alpha_ratio;
279
279
 
280
- out vec4 outColor;
280
+ out vec4 outColor;
281
281
 
282
- void main() {
282
+ void main() {
283
283
 
284
- vec4 hdrColor = texture(u_main_texture, v_texcoord);
285
- vec4 bloomColor = texture(u_bloom_texture, v_texcoord);
286
- vec4 result = hdrColor + bloomColor * u_exposure;
287
- result = pow(result, vec4(1.0 / u_gamma));
288
- result.a *= u_final_alpha_ratio;
289
- outColor = result;
290
- }
284
+ vec4 hdrColor = texture(u_main_texture, v_texcoord);
285
+ vec4 bloomColor = texture(u_bloom_texture, v_texcoord);
286
+ vec4 result = hdrColor + bloomColor * u_exposure;
287
+ result = pow(result, vec4(1.0 / u_gamma));
288
+ result.a *= u_final_alpha_ratio;
289
+ outColor = result;
290
+ }
291
291
  `;
292
292
  const program = createProgram(this.gl, vertexShader, fragmentShader);
293
293
 
@@ -577,7 +577,7 @@ void main() {
577
577
 
578
578
  const texture = gl.createTexture();
579
579
  gl.bindTexture(gl.TEXTURE_2D, texture);
580
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); // UNSIGNED_BYTE
580
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); // UNSIGNED_BYTE
581
581
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
582
582
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
583
583
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@@ -589,11 +589,11 @@ void main() {
589
589
  _resetTexture() {
590
590
  const { gl, _width, _height } = this;
591
591
  gl.bindTexture(gl.TEXTURE_2D, this._middleTexture); // UNSIGNED_BYTE
592
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
592
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
593
593
  gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[0]);
594
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
594
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
595
595
  gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[1]);
596
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
596
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
597
597
  gl.bindTexture(gl.TEXTURE_2D, null);
598
598
  }
599
599
 
@@ -160,6 +160,11 @@ self.onmessage = function (e) {
160
160
  if (time !== null) {
161
161
  try {
162
162
  const result = interpolator.interpolate(time);
163
+ if(result === null) {
164
+ /* eslint-disable-next-line no-restricted-globals */
165
+ self.postMessage({ error: 'No TimeTracks Data' });
166
+ return;
167
+ }
163
168
  /* eslint-disable-next-line no-restricted-globals */
164
169
  self.postMessage(result, [result.buffer]);
165
170
  return;
@@ -31,6 +31,11 @@ self.onmessage = function (e) {
31
31
  if (time !== null) {
32
32
  try {
33
33
  const result = interpolator.interpolate(time);
34
+ if (result === null) {
35
+ /* eslint-disable-next-line no-restricted-globals */
36
+ self.postMessage({ error: 'No TimeTracks Data' });
37
+ return;
38
+ }
34
39
  /* eslint-disable-next-line no-restricted-globals */
35
40
  self.postMessage(result, [result.buffer]);
36
41
  return;