@pirireis/webglobeplugins 0.17.1 → 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.
Files changed (67) hide show
  1. package/Math/haversine.js +22 -0
  2. package/Math/methods.js +15 -2
  3. package/Math/tessellation/methods.js +4 -1
  4. package/Math/tessellation/nearest-value-padding.js +112 -0
  5. package/Math/tessellation/spherical-triangle-area.js +99 -0
  6. package/Math/tessellation/tile-merger.js +346 -215
  7. package/Math/tessellation/triangle-tessellation.js +381 -9
  8. package/Math/vec3.js +4 -0
  9. package/Math/xyz-tile.js +18 -0
  10. package/altitude-locator/plugin.js +1 -2
  11. package/investigation-tools/draw/tiles/adapters.js +2 -2
  12. package/investigation-tools/draw/tiles/tiles.js +2 -2
  13. package/package.json +1 -1
  14. package/programs/helpers/fadeaway.js +6 -1
  15. package/programs/point-on-globe/square-pixel-point.js +1 -0
  16. package/programs/polygon-on-globe/texture-dem-triangles.js +94 -116
  17. package/programs/totems/camera-totem-attactment-interface.js +1 -0
  18. package/programs/totems/camerauniformblock.js +33 -22
  19. package/programs/totems/dem-textures-manager.js +265 -0
  20. package/programs/vectorfields/logics/drawrectangleparticles.js +51 -18
  21. package/programs/vectorfields/logics/{ubo-new.js → particle-ubo.js} +5 -14
  22. package/programs/vectorfields/logics/pixelbased.js +42 -36
  23. package/programs/vectorfields/pingpongbuffermanager.js +34 -8
  24. package/semiplugins/shape-on-terrain/terrain-polygon/adapters.js +55 -0
  25. package/semiplugins/shape-on-terrain/terrain-polygon/data/cache.js +102 -0
  26. package/semiplugins/shape-on-terrain/terrain-polygon/data/index-polygon-map.js +45 -0
  27. package/semiplugins/shape-on-terrain/terrain-polygon/data/manager.js +4 -0
  28. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +177 -0
  29. package/semiplugins/shape-on-terrain/terrain-polygon/data/polygon-to-triangles.js +100 -0
  30. package/semiplugins/shape-on-terrain/terrain-polygon/data/random.js +121 -0
  31. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.js +1 -0
  32. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker-contact.js +63 -0
  33. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +125 -0
  34. package/semiplugins/shape-on-terrain/terrain-polygon/terrain-polygon.js +219 -0
  35. package/semiplugins/shape-on-terrain/terrain-polygon/types.js +8 -0
  36. package/semiplugins/shell/bbox-renderer/logic.js +18 -58
  37. package/semiplugins/shell/bbox-renderer/object.js +19 -9
  38. package/tracks/point-heat-map/point-to-heat-map-flow.js +1 -1
  39. package/tracks/point-tracks/plugin.js +13 -6
  40. package/tracks/timetracks/program-line-strip.js +1 -1
  41. package/util/account/single-attribute-buffer-management/buffer-manager.js +5 -3
  42. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +2 -2
  43. package/util/gl-util/uniform-block/manager.js +20 -10
  44. package/util/helper-methods.js +8 -0
  45. package/util/picking/fence.js +4 -2
  46. package/util/picking/picker-displayer.js +51 -9
  47. package/util/programs/draw-texture-on-canvas.js +18 -15
  48. package/util/shaderfunctions/geometrytransformations.js +67 -1
  49. package/vectorfield/waveparticles/plugin.js +241 -116
  50. package/vectorfield/wind/adapters/image-to-fields.js +61 -0
  51. package/vectorfield/wind/adapters/types.js +1 -0
  52. package/vectorfield/wind/imagetovectorfieldandmagnitude.js +6 -9
  53. package/vectorfield/wind/plugin-persistant copy.js +364 -0
  54. package/vectorfield/wind/plugin-persistant.js +375 -0
  55. package/vectorfield/wind/plugin.js +1 -1
  56. package/Math/tessellation/earcut/adapters.js +0 -37
  57. package/Math/tessellation/hybrid-triangle-tessellation-meta.js +0 -123
  58. package/Math/tessellation/shred-input.js +0 -18
  59. package/Math/tessellation/tiler.js +0 -50
  60. package/Math/tessellation/triangle-tessellation-meta.js +0 -523
  61. package/programs/polygon-on-globe/texture-dem-triangle-test-plugin-triangle.js +0 -328
  62. package/programs/vectorfields/logics/drawrectangleparticles1.js +0 -112
  63. package/semiplugins/shape-on-terrain/terrain-cover/texture-dem-cover.js +0 -1
  64. package/util/gl-util/uniform-block/types.js +0 -1
  65. package/util/webglobe/index.js +0 -2
  66. /package/Math/tessellation/{zoom-catch.js → constants.js} +0 -0
  67. /package/util/{webglobe/gldefaultstates.js → globe-default-gl-states.js} +0 -0
@@ -1,19 +1,27 @@
1
1
  import { createProgram } from "../../util/webglobjectbuilders";
2
2
  import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totems/camerauniformblock";
3
- import { cartesian3DToGLPosition, } from "../../util/shaderfunctions/geometrytransformations";
4
- import { isPointInBBox } from "../../util/shaderfunctions/geometrytransformations";
3
+ import { DemTextureManagerCache, DEM_TEXTURE_BLOCK_STRING } from "../totems/dem-textures-manager";
4
+ import { cartesian3DToGLPosition, mercatorXYToGLPosition, POLE_BY_PI } from "../../util/shaderfunctions/geometrytransformations";
5
+ import { relativeBBoxPositionRadian } from "../../util/shaderfunctions/geometrytransformations";
5
6
  import { drawArrays } from "../../util/gl-util/draw-options/methods";
6
7
  import { attributeLoader } from "../../util/gl-util/buffer/attribute-loader";
7
8
  import { WORLD_RADIUS_3D } from "../../Math/constants";
8
9
  import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
10
+ // const ESCAPE_VALUE = 0.123456;
9
11
  const uniformBindingPoints = {
10
12
  camera: 0,
11
13
  style: 1,
14
+ dem: 2,
15
+ selection: 3,
12
16
  };
17
+ export const IndexAttributeEscapeValue = -1;
13
18
  const styleBlockManager = new UniformBlockManager('Style', [
14
- { name: "u_color", type: "vec4", value: new Float32Array([0.0, 0.0, 0.0, 0.0]) },
15
- { name: "u_pointSize", type: "float", value: new Float32Array([1.0]) },
16
- { name: "u_opacity", type: "float", value: new Float32Array([1.0]) },
19
+ { name: "defaultColor", type: "vec4", value: new Float32Array([0.0, 0.0, 0.0, 0.0]) },
20
+ { name: "pickedColor", type: "vec4", value: new Float32Array([0, 0, 0, 0]) },
21
+ { name: "u_pointSize", type: "float", value: new Float32Array([6.0]) },
22
+ { name: "opacity", type: "float", value: new Float32Array([1.0]) },
23
+ { name: "private_isPickedOn", type: "float", value: new Float32Array([0]) },
24
+ { name: "private_pickedIndex", type: "float", value: new Float32Array([0]) },
17
25
  ], uniformBindingPoints.style);
18
26
  const vertexShaderSource = `#version 300 es
19
27
  #pragma vscode_glsllint_stage : vert
@@ -22,84 +30,106 @@ precision highp float;
22
30
  precision highp sampler2DArray;
23
31
 
24
32
  ${CameraUniformBlockString}
25
-
33
+ ${POLE_BY_PI}
26
34
  ${cartesian3DToGLPosition}
35
+ ${mercatorXYToGLPosition}
36
+
37
+ ${DEM_TEXTURE_BLOCK_STRING}
38
+
27
39
  in vec3 a_position;
28
40
  in vec2 a_xy;
29
- uniform sampler2DArray u_demTexture; // <-- changed from array to single
30
- uniform vec4 u_demTextureBBOX[6];
31
- uniform vec2 u_textureDataCoverRatio[6];
32
- uniform int u_breakLoopIndex;
41
+ in float a_index;
42
+ in vec4 a_color;
33
43
 
34
44
  ${styleBlockManager.glslCode()}
35
- // Todo: light direction.
45
+
36
46
  out vec4 v_color;
47
+ flat out int v_index;
37
48
 
49
+ ${relativeBBoxPositionRadian}
38
50
 
39
- ${isPointInBBox}
40
51
 
41
52
  void main() {
42
-
43
- float elevation = ${WORLD_RADIUS_3D}; // default elevation at sea level
53
+ float elevation = ${WORLD_RADIUS_3D};
44
54
  float altitude = 0.0;
45
- v_color = vec4(1.0, 1.0, 1.0, 1.0); // default color white
55
+ v_color = (a_color.a != -1.0) ? a_color : defaultColor;
56
+
57
+ if (is3D == true) {
58
+ for (int i = 0; i < 6; i++) {
59
+ if( i == u_breakLoopIndex - 1 ) {
60
+ break;
61
+ }
62
+ vec2 uv = relativeBBoxPositionRadian(a_xy, u_demTextureBBOX[i]);
63
+ if (uv.x != -1.0) {
64
+ uv.y = 1.0 - uv.y; // flip y coordinate
65
+ // rescale and transform uv to fit in the texture data cover bbox
66
+ uv *= u_textureDataCoverRatio[i].xy;
46
67
 
47
- for (int i = 0; i < 6; i++) {
48
- if (isPointInBBox(a_xy, u_demTextureBBOX[i])) {
49
- vec2 uv = (a_xy - u_demTextureBBOX[i].xy) / (u_demTextureBBOX[i].zw - u_demTextureBBOX[i].xy);
50
- // uv.y = 1.0 - uv.y; // flip y coordinate
51
- // rescale and transform uv to fit in the texture data cover bbox
52
- uv *= u_textureDataCoverRatio[i];
53
- altitude = texture(u_demTexture, vec3(uv, float(i))).r;
54
- if (altitude != 0.0) {
68
+ //
69
+ altitude = texture(u_demTexture, vec3(uv, float(i))).r;
55
70
  break;
56
71
  }
57
72
  }
58
- }
59
- if (u_color.a > 0.0) {
60
- v_color = u_color;
73
+ vec3 position = a_position * (elevation + altitude);
74
+ gl_Position = cartesian3DToGLPosition(position);
61
75
  } else {
62
- if ( altitude > 0.00001 ) {
63
- v_color = mix(vec4(1.0, 1.0, 1.0, 1.0), vec4(1.0, 0.2, 0.2, 1.0), altitude / 2.0); // color from white to red based on altitude
64
- } else {
65
- // white
66
- v_color = vec4(1.0, 1.0, 1.0, 0.5);
76
+ vec2 mercatorXY = a_xy * POLE_BY_PI;
77
+ gl_Position = mercatorXYToGLPosition(mercatorXY);
78
+ }
79
+
80
+ if (private_isPickedOn == 1.0){
81
+ if (a_index == private_pickedIndex) {
82
+ v_color = pickedColor;
67
83
  }
84
+ v_index = int(a_index + 0.5); // +0.5 to avoid rounding issues
68
85
  }
69
- v_color.a *= u_opacity;
70
- vec3 position = a_position * (elevation + altitude * 2.0);
71
- gl_Position = cartesian3DToGLPosition(position);
72
- gl_PointSize = 6.0; //u_pointSize;
86
+
87
+
88
+ v_color.a *= opacity;
89
+ gl_PointSize = u_pointSize;
73
90
  }
74
91
  `;
75
92
  const fragmentShaderSource = `#version 300 es
76
93
  #pragma vscode_glsllint_stage : frag
77
94
 
95
+
96
+
78
97
  precision highp float;
79
- in vec4 v_color;
80
- out vec4 outColor;
98
+ precision highp int;
99
+
100
+
101
+ in vec4 v_color; // color from vertex shader
102
+ flat in int v_index; // index from vertex shader
103
+ layout(location = 0) out vec4 outColor;
104
+ layout(location = 1) out int outIndex;
105
+
81
106
  void main() {
82
107
  outColor = v_color;
108
+ outIndex = v_index;
83
109
  }
84
110
  `;
85
111
  function resCalculation(sourceResolution, mergeCount) {
86
112
  return sourceResolution + (mergeCount - 1) * (sourceResolution - 1);
87
113
  }
88
- const RESOLUTION = resCalculation(5, 12); // 5 is tile dimension length, 12 is merge count
114
+ const RESOLUTION = resCalculation(5, 20); // 5 is tile dimension length, 12 is merge count
89
115
  export class TextureDemTriangles {
90
116
  globe;
91
117
  gl;
92
118
  program;
93
119
  // Later an injection will handle demTextures and demTextureBBOX
94
- texture;
120
+ // texture: WebGLTexture;
95
121
  // demTextures: WebGLTexture[] = [];
96
122
  // demTextureBBOX: Float32Array = new Float32Array(6 * 4); // 6 bounding boxes
97
123
  cameraUniformBlock;
124
+ demTextureManager;
125
+ _defaultSelectionUBO;
98
126
  _publishedUBOs = [];
99
127
  locations = {
100
128
  attributes: {
101
129
  a_position: -1,
102
130
  a_xy: -1,
131
+ a_index: -1,
132
+ a_color: -1,
103
133
  },
104
134
  uniforms: {
105
135
  u_demTexture: -1,
@@ -115,9 +145,12 @@ export class TextureDemTriangles {
115
145
  this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
116
146
  this.cameraUniformBlock = CameraUniformBlockTotemCache.get(this.globe);
117
147
  this.cameraUniformBlock.assignBindingPoint(this.program, uniformBindingPoints.camera);
148
+ styleBlockManager.assignBindingPoint(this.gl, this.program);
118
149
  // get attribute locations
119
150
  this.locations.attributes.a_position = this.gl.getAttribLocation(this.program, 'a_position');
120
151
  this.locations.attributes.a_xy = this.gl.getAttribLocation(this.program, 'a_xy');
152
+ this.locations.attributes.a_index = this.gl.getAttribLocation(this.program, 'a_index');
153
+ this.locations.attributes.a_color = this.gl.getAttribLocation(this.program, 'a_color');
121
154
  // get uniform locations
122
155
  this.locations.uniforms.u_demTexture = this.gl.getUniformLocation(this.program, 'u_demTexture');
123
156
  this.locations.uniforms.u_demTextureBBOX = this.gl.getUniformLocation(this.program, 'u_demTextureBBOX');
@@ -125,75 +158,24 @@ export class TextureDemTriangles {
125
158
  this.locations.uniforms.u_breakLoopIndex = this.gl.getUniformLocation(this.program, 'u_breakLoopIndex');
126
159
  this.locations.uniforms.u_style = this.gl.getUniformBlockIndex(this.program, 'Style');
127
160
  this.gl.uniformBlockBinding(this.program, this.locations.uniforms.u_style, uniformBindingPoints.style);
128
- // create 3d texture
129
- const texture = this.gl.createTexture();
130
- this.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY, texture);
131
- // Calculate correct size: tileDimensionLength + (mergeCount - 1) * (tileDimensionLength - 1)
132
- // For tileDimensionLength=5, mergeCount=8: 5 + 7*4 = RESOLUTION
133
- this.gl.texStorage3D(this.gl.TEXTURE_2D_ARRAY, 1, this.gl.R32F, RESOLUTION, RESOLUTION, 6);
134
- // set texture parameters
135
- const ext = this.gl.getExtension('OES_texture_float_linear');
136
- console.log('OES_texture_float_linear extension:', ext);
137
- this.gl.texParameteri(this.gl.TEXTURE_2D_ARRAY, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
138
- this.gl.texParameteri(this.gl.TEXTURE_2D_ARRAY, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
139
- this.gl.texParameteri(this.gl.TEXTURE_2D_ARRAY, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
140
- this.gl.texParameteri(this.gl.TEXTURE_2D_ARRAY, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
141
- this.gl.bindTexture(this.gl.TEXTURE_2D_ARRAY, null);
142
- this.texture = texture;
161
+ this.demTextureManager = DemTextureManagerCache.get(this.globe);
162
+ this.demTextureManager.assignBindingPoint(this.program, uniformBindingPoints.dem);
143
163
  }
144
- createVAO(pos3dBufferInfo, longLatBufferInfo) {
164
+ createVAO(pos3dBufferInfo, longLatBufferInfo, indexBufferInfo, variativeColorBuffer) {
145
165
  const vao = this.gl.createVertexArray();
146
166
  this.gl.bindVertexArray(vao);
147
167
  attributeLoader(this.gl, pos3dBufferInfo, this.locations.attributes.a_position, 3);
148
168
  attributeLoader(this.gl, longLatBufferInfo, this.locations.attributes.a_xy, 2);
169
+ attributeLoader(this.gl, indexBufferInfo, this.locations.attributes.a_index, 1, {
170
+ escapeValues: [IndexAttributeEscapeValue],
171
+ normalized: false,
172
+ });
173
+ attributeLoader(this.gl, variativeColorBuffer, this.locations.attributes.a_color, 4, {
174
+ escapeValues: [IndexAttributeEscapeValue, IndexAttributeEscapeValue, IndexAttributeEscapeValue, IndexAttributeEscapeValue]
175
+ });
149
176
  this.gl.bindVertexArray(null);
150
177
  return vao;
151
178
  }
152
- setDemTextures(demTexturesData, demTextureBBOX, coverRatio) {
153
- // Add validation for maximum layers
154
- const maxLayers = this.gl.getParameter(this.gl.MAX_ARRAY_TEXTURE_LAYERS);
155
- if (demTexturesData.length > Math.min(maxLayers, 6)) {
156
- console.error(`Too many DEM textures: ${demTexturesData.length}, max supported: ${Math.min(maxLayers, 6)}`);
157
- return;
158
- }
159
- // bind textures to texture units
160
- const gl = this.gl;
161
- gl.bindTexture(gl.TEXTURE_2D_ARRAY, this.texture);
162
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
163
- // turn off premultiply alpha
164
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
165
- // bind and upload each texture to the 3D texture array
166
- for (let i = 0; i < demTexturesData.length; i++) {
167
- const data = demTexturesData[i];
168
- if (data.length === RESOLUTION * RESOLUTION) { // <-- FIXED
169
- gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, i, RESOLUTION, RESOLUTION, 1, gl.RED, gl.FLOAT, new Float32Array(data));
170
- }
171
- else {
172
- console.warn(`DEM texture ${i} has incorrect size: ${data.length}, expected: ${RESOLUTION * RESOLUTION}`);
173
- }
174
- }
175
- // set uniform for texture units
176
- const bboxVec4Array = new Float32Array(6 * 4);
177
- for (let i = 0; i < demTextureBBOX.length; i++) {
178
- const bbox = demTextureBBOX[i];
179
- bboxVec4Array[i * 4 + 0] = bbox.ll[0];
180
- bboxVec4Array[i * 4 + 1] = bbox.ll[1];
181
- bboxVec4Array[i * 4 + 2] = bbox.ur[0];
182
- bboxVec4Array[i * 4 + 3] = bbox.ur[1];
183
- }
184
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
185
- gl.useProgram(this.program);
186
- gl.uniform4fv(this.locations.uniforms.u_demTextureBBOX, bboxVec4Array);
187
- if (coverRatio) {
188
- gl.uniform2fv(this.locations.uniforms.u_textureDataCoverRatio, new Float32Array(coverRatio.flatMap(ratio => [ratio.x, ratio.y])));
189
- }
190
- else {
191
- gl.uniform2fv(this.locations.uniforms.u_textureDataCoverRatio, new Float32Array(12).fill(1.0));
192
- }
193
- gl.bindTexture(gl.TEXTURE_2D_ARRAY, null);
194
- gl.uniform1i(this.locations.uniforms.u_breakLoopIndex, demTexturesData.length);
195
- gl.useProgram(currentProgram);
196
- }
197
179
  createUBO(bufferReadType = "STATIC_DRAW") {
198
180
  const ubo = styleBlockManager.createUBO(this.gl, bufferReadType);
199
181
  this._publishedUBOs.push(ubo);
@@ -201,31 +183,27 @@ export class TextureDemTriangles {
201
183
  }
202
184
  free() {
203
185
  this.gl.deleteProgram(this.program);
204
- this.gl.deleteTexture(this.texture);
186
+ // this.gl.deleteTexture(this.texture);
205
187
  this._publishedUBOs.forEach(ubo => ubo.free());
206
188
  this._publishedUBOs = [];
189
+ DemTextureManagerCache.release(this.globe);
207
190
  CameraUniformBlockTotemCache.release(this.globe);
208
191
  }
209
192
  draw(vao, drawOptions, ubo) {
210
193
  const gl = this.gl;
211
194
  gl.useProgram(this.program);
212
195
  this.cameraUniformBlock.bind(uniformBindingPoints.camera);
213
- // TURN OFF flip y for texture
214
- // gl.disable(gl.DEPTH_TEST);
215
- // gl.depthMask(false);
216
- // gl.depthRange(0.0, 0.01); // Use near 1% of depth range
217
- // Step 3: Optionally: Set depth func to ALWAYS (to ignore previous depth)
218
- // This ensures your new geometry passes depth test regardless of prior depth values
219
- gl.activeTexture(gl.TEXTURE0);
220
- gl.bindTexture(gl.TEXTURE_2D_ARRAY, this.texture);
221
- gl.uniform1i(this.locations.uniforms.u_demTexture, 0); // texture unit 0
222
- // bind VAO and draw
196
+ this.demTextureManager.bindData(0, uniformBindingPoints.dem);
223
197
  gl.bindVertexArray(vao);
224
- // bind UBO for style
225
198
  ubo.bind();
226
- drawOnTopBegin(gl);
227
- drawArrays(gl, gl.POINTS, drawOptions);
228
- drawOnTopEnd(gl);
199
+ if (this.globe.api_GetCurrentLODWithDecimal() < 14.5) {
200
+ drawOnTopBegin(gl);
201
+ }
202
+ drawArrays(gl, gl.TRIANGLES, drawOptions);
203
+ if (this.globe.api_GetCurrentLODWithDecimal() < 14.5) {
204
+ drawOnTopEnd(gl);
205
+ }
206
+ this.demTextureManager.unbindData(0, uniformBindingPoints.dem);
229
207
  gl.bindVertexArray(null);
230
208
  gl.bindTexture(gl.TEXTURE_2D_ARRAY, null);
231
209
  gl.useProgram(null);
@@ -235,7 +213,7 @@ export class TextureDemTriangles {
235
213
  _getUniformBlockOffset(name) {
236
214
  // hardcoded offsets based on std140 layout rules
237
215
  const offsets = {
238
- 'u_color': 0,
216
+ 'defaultColor': 0,
239
217
  };
240
218
  const result = offsets[name];
241
219
  if (result === undefined) {
@@ -4,19 +4,21 @@ import { RADIAN } from "../../Math/methods";
4
4
  import { GlobeChangeObserver } from "./globe-changes";
5
5
  export const CameraUniformBlockString = `
6
6
  layout(std140) uniform CameraUniformBlock {
7
- mat4 view; // 64 bytes 0
8
- mat4 projection; // 64 bytes 64
9
- vec3 translate; // 12 bytes 128
10
- bool is3D; // 4 bytes 140
11
- vec2 mapWH; // 8 bytes 144
12
- vec2 screenWH; // 8 bytes 152
13
- float z_level; // 4 bytes 160 | 164
14
- float world_distance; // 4 bytes 164
15
- float world_tilt; // 4 bytes 168
16
- float world_north_angle; // 4 bytes 172
17
- vec2 world_center_radian; // 8 bytes 176 | 184
18
- }; // 14 lines
7
+ mat4 view; // 64 bytes 0
8
+ mat4 projection; // 64 bytes 64
9
+ vec3 translate; // 12 bytes 128
10
+ bool is3D; // 4 bytes 140
11
+ vec2 mapWH; // 8 bytes 144
12
+ vec2 screenWH; // 8 bytes 152
13
+ float z_level; // 4 bytes 160
14
+ float world_distance; // 4 bytes 164
15
+ float world_tilt; // 4 bytes 168
16
+ float world_north_angle; // 4 bytes 172
17
+ vec2 world_center_radian; // 8 bytes 176
18
+ float NaN; // padding to 16 bytes 184
19
+ }; // 188 bytes total
19
20
  `;
21
+ // TODO: Remove NaN
20
22
  const Radian = Math.PI / 180.0;
21
23
  const _0vec3 = [0, 0, 0];
22
24
  export class CameraUniformBlockTotem {
@@ -32,11 +34,13 @@ export class CameraUniformBlockTotem {
32
34
  // _frustumPlanes: any; // Uncomment and type if used
33
35
  _aproximatedLOD = -1;
34
36
  _globeChangeObserver = null;
37
+ attachments = new Set();
35
38
  constructor() {
36
39
  this.id = "CameraUniformBlockTotem";
37
- this.description =
38
- `Sets a uniform block and provides buffer for it. The following is the glsl uniform block:` +
39
- CameraUniformBlockString;
40
+ this.description = `Provides and updates camera related uniform block
41
+ Should be on top of DrawOrder.
42
+ Attachments can register to process right after camera data is updated without creating other plugins listed on DrawOrder
43
+ The following is the glsl uniform block: ${CameraUniformBlockString}`;
40
44
  this.gl = null;
41
45
  this.globe = null;
42
46
  this.ubo = null;
@@ -65,6 +69,8 @@ export class CameraUniformBlockTotem {
65
69
  // 184 bytes in reality. Overflow on linux for some reason. So, 200 bytes.
66
70
  gl.bufferData(gl.UNIFORM_BUFFER, 200, gl.STREAM_DRAW);
67
71
  gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
72
+ // assign NaN to padding float
73
+ gl.bufferSubData(gl.UNIFORM_BUFFER, 184, new Float32Array([NaN]));
68
74
  gl.bindBuffer(gl.UNIFORM_BUFFER, null);
69
75
  return ubo;
70
76
  }
@@ -127,6 +133,9 @@ export class CameraUniformBlockTotem {
127
133
  this._isMovedParams.lastLod = currentLOD;
128
134
  this.__setCameraVectors();
129
135
  // this._calculateAproximatedLOD();
136
+ for (const attachment of this.attachments) {
137
+ attachment.update();
138
+ }
130
139
  }
131
140
  __setCameraVectors() {
132
141
  if (!this.globe) {
@@ -192,17 +201,19 @@ export class CameraUniformBlockTotem {
192
201
  getGlobeChanges() {
193
202
  return this._globeChangeObserver?.getChanges();
194
203
  }
195
- // getApproximatedLOD(): number {
196
- // return this._aproximatedLOD;
197
- // }
198
- // _calculateAproximatedLOD(){
199
- // const globe = this.globe!;
200
- // this._aproximatedLOD = approximatedZoomLevel(globe)
201
- // }
204
+ registerAttachment(attachment) {
205
+ this.attachments.add(attachment);
206
+ }
207
+ unregisterAttachment(attachment) {
208
+ this.attachments.delete(attachment);
209
+ }
202
210
  free() {
203
211
  const gl = this.gl;
204
212
  const ubo = this.ubo;
205
213
  gl.deleteBuffer(ubo);
214
+ if (this.attachments.size > 0) {
215
+ throw new Error("There are still attachments registered to CameraUniformBlockTotem during free()");
216
+ }
206
217
  }
207
218
  readBuffer() {
208
219
  const gl = this.gl;