@pirireis/webglobeplugins 0.12.0-alpha → 0.13.0-alpha

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.
@@ -1,136 +1,128 @@
1
- import { createProgram, shaderfunctions } from "../../../util";
2
- import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
3
- import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
4
- const vertexShader = `#version 300 es ` +
5
- shaderfunctions.PI +
6
- shaderfunctions.R +
7
- shaderfunctions.POLE +
8
- CameraUniformBlockString +
9
- shaderfunctions.mercatorXYToGLPosition +
10
- shaderfunctions.longLatRadToMercator +
11
- shaderfunctions.longLatRadToCartesian3D +
12
- shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
13
- shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
14
- shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistancePadding +
15
- shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
16
-
17
- in vec2 center;
18
- in float radius;
19
- in float pad_range;
20
- in vec4 color;
21
- in float flag;
22
-
23
- uniform int compass;
24
- uniform float pad_count;
25
-
26
- uniform float opacity;
27
-
28
-
29
- out vec2 v_limp;
30
- out vec4 v_color;
31
-
32
-
33
- void main() {
34
-
35
- float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
36
- if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
37
- v_color = vec4(color.rgb, color.a * alpha_padding * opacity);
38
-
39
- gl_PointSize = 2.0;
40
-
41
- float odd = mod(float(gl_VertexID), 2.0);
42
- float index = (float(gl_VertexID)- odd ) / 2.0;
43
- float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
44
- float radius_ = radius - (pad_range * odd);
45
-
46
- if ( is3D){
47
- gl_Position = projection * view * vec4(
48
- circleLimpFromLongLatRadCenterCartesian3D( center, radius_, angle) - translate, 1.0);
49
- v_limp = vec2(0.0, 0.0);
50
- return;
51
- }
52
- vec2 limp;
53
- if ( compass == 1 ){
54
- limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
55
- } else {
56
- // limp = circleLimpFromLongLatRadCenterMercatorRealDistancePadding(center, radius_, angle);
57
- limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
58
- }
59
- v_limp = limp;
60
- gl_Position = mercatorXYToGLPosition(limp);
61
- }`;
62
- const fragmentShader = `#version 300 es
63
- precision highp float; ` +
64
- shaderfunctions.POLE + `
65
- in vec4 v_color;
66
- in vec2 v_limp;
67
- out vec4 outColor;
68
- void main() {
69
- if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
70
- outColor = v_color;
71
- }`;
72
- class Logic {
73
- constructor(globe) {
74
- this.globe = globe;
75
- this.gl = globe.gl;
76
- this.program = createProgram(this.gl, vertexShader, fragmentShader);
77
- { // bind positions so bufferManager can use them
78
- this.gl.bindAttribLocation(this.program, 0, "center");
79
- this.gl.bindAttribLocation(this.program, 1, "radius");
80
- this.gl.bindAttribLocation(this.program, 2, "pad_range");
81
- this.gl.bindAttribLocation(this.program, 3, "color");
82
- this.gl.bindAttribLocation(this.program, 4, "flag");
83
- }
84
- this.cameraBlockBindingPoint = 0;
85
- const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
86
- this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
87
- this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
88
- this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
89
- this._opacityLocation = this.gl.getUniformLocation(this.program, "opacity");
90
- this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
91
- this._compassMode = 1;
92
- this._opacity = 1.0;
93
- this._padCount = 360;
94
- {
95
- const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
96
- this.gl.useProgram(this.program);
97
- this.gl.uniform1i(this._compassLocation, 1);
98
- this.gl.uniform1f(this._opacityLocation, 1.0);
99
- this.gl.uniform1f(this._padCountLocation, 360);
100
- this.gl.useProgram(currentProgram);
101
- }
102
- }
103
- draw(attrBufferManager, padCount, compass, opacity) {
104
- const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
105
- gl.useProgram(program);
106
- attrBufferManager.bindPaddingVAO();
107
- cameraBlockTotem.bind(cameraBlockBindingPoint);
108
- // draw instanced
109
- if (padCount !== this._padCount) {
110
- this._padCount = padCount;
111
- // console.log("padCount", padCount);
112
- gl.uniform1f(_padCountLocation, padCount);
113
- }
114
- if (compass !== this._compassMode) {
115
- // console.log("compass", compass);
116
- gl.uniform1i(_compassLocation, compass);
117
- this._compassMode = compass;
118
- }
119
- if (opacity !== this._opacity) {
120
- // console.log("opacity", opacity);
121
- this._opacity = opacity;
122
- gl.uniform1f(this._opacityLocation, opacity);
123
- }
124
- gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
125
- gl.bindVertexArray(null);
126
- cameraBlockTotem.unbind(cameraBlockBindingPoint);
127
- }
128
- free() {
129
- this.gl.deleteProgram(this.program);
130
- globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
131
- }
132
- }
133
- export const PaddingProgramCache = Object.freeze({
134
- getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic); },
135
- releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic); }
136
- });
1
+ "use strict";
2
+ // TODO: Delete this file if it is not needed anymore.
3
+ // import { createProgram, shaderfunctions } from "../../../util";
4
+ // import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
5
+ // import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
6
+ // const vertexShader = `#version 300 es ` +
7
+ // shaderfunctions.PI +
8
+ // shaderfunctions.R +
9
+ // shaderfunctions.POLE +
10
+ // CameraUniformBlockString +
11
+ // shaderfunctions.mercatorXYToGLPosition +
12
+ // shaderfunctions.longLatRadToMercator +
13
+ // shaderfunctions.longLatRadToCartesian3D +
14
+ // shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
15
+ // shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
16
+ // shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistancePadding +
17
+ // shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
18
+ // in vec2 center;
19
+ // in float radius;
20
+ // in float pad_range;
21
+ // in vec4 color;
22
+ // in float flag;
23
+ // uniform int compass;
24
+ // uniform float pad_count;
25
+ // uniform float opacity;
26
+ // out vec2 v_limp;
27
+ // out vec4 v_color;
28
+ // void main() {
29
+ // float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
30
+ // if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
31
+ // v_color = vec4(color.rgb, color.a * alpha_padding * opacity);
32
+ // gl_PointSize = 2.0;
33
+ // float odd = mod(float(gl_VertexID), 2.0);
34
+ // float index = (float(gl_VertexID)- odd ) / 2.0;
35
+ // float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
36
+ // float radius_ = radius - (pad_range * odd);
37
+ // if ( is3D){
38
+ // gl_Position = projection * view * vec4(
39
+ // circleLimpFromLongLatRadCenterCartesian3D( center, radius_, angle) - translate, 1.0);
40
+ // v_limp = vec2(0.0, 0.0);
41
+ // return;
42
+ // }
43
+ // vec2 limp;
44
+ // if ( compass == 1 ){
45
+ // limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
46
+ // } else {
47
+ // // limp = circleLimpFromLongLatRadCenterMercatorRealDistancePadding(center, radius_, angle);
48
+ // limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
49
+ // }
50
+ // v_limp = limp;
51
+ // gl_Position = mercatorXYToGLPosition(limp);
52
+ // }`;
53
+ // const fragmentShader = `#version 300 es
54
+ // precision highp float; `+
55
+ // shaderfunctions.POLE + `
56
+ // in vec4 v_color;
57
+ // in vec2 v_limp;
58
+ // out vec4 outColor;
59
+ // void main() {
60
+ // if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
61
+ // outColor = v_color;
62
+ // }`;
63
+ // class Logic {
64
+ // constructor(globe) {
65
+ // this.globe = globe;
66
+ // this.gl = globe.gl;
67
+ // this.program = createProgram(this.gl, vertexShader, fragmentShader);
68
+ // { // bind positions so bufferManager can use them
69
+ // this.gl.bindAttribLocation(this.program, 0, "center");
70
+ // this.gl.bindAttribLocation(this.program, 1, "radius");
71
+ // this.gl.bindAttribLocation(this.program, 2, "pad_range");
72
+ // this.gl.bindAttribLocation(this.program, 3, "color");
73
+ // this.gl.bindAttribLocation(this.program, 4, "flag");
74
+ // }
75
+ // this.cameraBlockBindingPoint = 0;
76
+ // const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
77
+ // this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
78
+ // this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
79
+ // this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
80
+ // this._opacityLocation = this.gl.getUniformLocation(this.program, "opacity");
81
+ // this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
82
+ // this._compassMode = 1;
83
+ // this._opacity = 1.0;
84
+ // this._padCount = 360;
85
+ // {
86
+ // const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
87
+ // this.gl.useProgram(this.program);
88
+ // this.gl.uniform1i(this._compassLocation, 1);
89
+ // this.gl.uniform1f(this._opacityLocation, 1.0);
90
+ // this.gl.uniform1f(this._padCountLocation, 360)
91
+ // this.gl.useProgram(currentProgram);
92
+ // }
93
+ // }
94
+ // draw(attrBufferManager, padCount, compass, opacity) {
95
+ // const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
96
+ // gl.useProgram(program);
97
+ // attrBufferManager.bindPaddingVAO();
98
+ // cameraBlockTotem.bind(cameraBlockBindingPoint);
99
+ // // draw instanced
100
+ // if (padCount !== this._padCount) {
101
+ // this._padCount = padCount;
102
+ // // console.log("padCount", padCount);
103
+ // gl.uniform1f(_padCountLocation, padCount);
104
+ // }
105
+ // if (compass !== this._compassMode) {
106
+ // // console.log("compass", compass);
107
+ // gl.uniform1i(_compassLocation, compass);
108
+ // this._compassMode = compass;
109
+ // }
110
+ // if (opacity !== this._opacity) {
111
+ // // console.log("opacity", opacity);
112
+ // this._opacity = opacity;
113
+ // gl.uniform1f(this._opacityLocation, opacity);
114
+ // }
115
+ // gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
116
+ // gl.bindVertexArray(null);
117
+ // cameraBlockTotem.unbind(cameraBlockBindingPoint);
118
+ // }
119
+ // free() {
120
+ // this.gl.deleteProgram(this.program);
121
+ // globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
122
+ // }
123
+ // }
124
+ // //
125
+ // export const PaddingProgramCache = Object.freeze({
126
+ // getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
127
+ // releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
128
+ // })
@@ -34,7 +34,7 @@ vec2 read_value(const vec2 uv) {
34
34
  return value;
35
35
  }
36
36
 
37
- vec2 lookup_wind(const vec2 uv) { // gerek kalmayabilir. sampler linear methodu ayni isi yapiyor
37
+ vec2 lookup_wind(const vec2 uv) {
38
38
  // return texture(vector_field, uv).rg; // lower-res hardware filtering
39
39
  vec2 res = vec2(textureSize(vector_field, 0));
40
40
  vec2 px = 1.0 / res;
@@ -49,23 +49,7 @@ vec2 lookup_wind(const vec2 uv) { // gerek kalmayabilir. sampler linear methodu
49
49
  }
50
50
 
51
51
 
52
- vec2 lookup_wind2(const vec2 uv) { // gerek kalmayabilir. sampler linear methodu ayni isi yapiyor
53
- // return texture(vector_field, uv).rg; // lower-res hardware filtering
54
- vec2 res = vec2(textureSize(vector_field, 0));
55
- if (res.x == escape_value || res.y == escape_value){ return vec2(0.0);}
56
- vec2 px = 1.0 / res;
57
- vec2 vc = (floor(uv * res)) * px;
58
- vec2 f = fract(uv * res);
59
- vec2 tl = texture(vector_field, vc).rg;
60
- vec2 tr = texture(vector_field, vc + vec2(px.x, 0)).rg;
61
- vec2 bl = texture(vector_field, vc + vec2(0, px.y)).rg;
62
- vec2 br = texture(vector_field, vc + px).rg;
63
- if (tl.x == 0.0 && tl.y == 0.0){ return vec2(0.0);}
64
- if (tr.x == 0.0 && tr.y == 0.0){ return vec2(0.0);}
65
- if (bl.x == 0.0 && bl.y == 0.0){ return vec2(0.0);}
66
- if (br.x == 0.0 && br.y == 0.0){ return vec2(0.0);}
67
- return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);
68
- }
52
+
69
53
 
70
54
 
71
55
  vec2 random_position(vec2 st){
@@ -74,17 +58,17 @@ vec2 random_position(vec2 st){
74
58
 
75
59
 
76
60
  void main(){
77
- vec2 vec = -lookup_wind(in_position).xy;
61
+ vec2 vec = lookup_wind(in_position).xy;
78
62
  if (vec.x == 0.0 && vec.y == 0.0){
79
63
  out_position = random_position(in_position);
80
64
  return;
81
65
  }
82
66
  float random_value = random(in_position + random_seed);
83
- if (random_value < drop_rate){ //TODO: more sophisticated drop out mechanism mi
67
+ if (random_value < drop_rate){
84
68
  out_position = random_position(in_position);
85
69
  return;
86
70
  }
87
- out_position = in_position - (vec / draw_texture_size) * range; //*0.0014
71
+ out_position = in_position + (vec / draw_texture_size) * range;
88
72
  }
89
73
  `;
90
74
  const fragmentShaderSource = `#version 300 es
@@ -1,55 +1,58 @@
1
- import { LineStripProgramCache } from "../../../programs/line-on-globe/linestrip";
1
+ import { LineStripProgramCache } from "../../../programs/line-on-globe/linestrip/linestrip";
2
2
  import { createBufferAndReadInfo } from '../../../util/gl-util/buffer/attribute-loader';
3
3
  // import { populateFloat32Array } from "../../../util/jshelpers/data-filler";
4
4
  import { BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
5
5
  import { globe3Dcoordinates, globe2Dcoordinates, RADIANS } from "../../../Math/methods";
6
6
  import { generateArcPoints } from "../../../Math/arc-cdf-points";
7
+ import { StaticDynamicState, StaticDynamicStrategy } from "../../../util/build-strategy/static-dynamic";
7
8
  import * as vec3 from "../../../Math/vec3";
8
9
  import * as arc from "../../../Math/arc";
9
10
  import { CameraUniformBlockTotemCache } from "../../../programs/totems/camerauniformblock";
10
11
  import { WORLD_RADIUS_3D } from "../../../Math/constants";
11
12
  const VERTEX_COUNT = 70;
12
13
  const INITAL_CAPACITY = 10;
13
- const _0vector = [0, 0, 0];
14
14
  const _attractionPoint = [0, 0, 0];
15
15
  const _start = [0, 0, 0];
16
16
  const _end = [0, 0, 0];
17
17
  const _0arc = arc.create([1, 0, 0], [0, 1, 0]); // zero arc for intersection tests
18
- let interval = 1;
18
+ const _colorArray = new Float32Array(4); // For color buffer
19
19
  export class NaiveLineOnTerrainPlugin {
20
20
  id;
21
21
  program = null;
22
- _bufferManagersCompMap = null;
23
- _bufferManagersCompMapTest = null;
22
+ bufferManagerMap = null;
24
23
  _bufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
25
- _testOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
26
24
  _opacity = 1;
27
25
  _arcUBOHandler = null;
28
26
  _vao = null;
29
- _vaoAllTest = null;
30
- _ubohandlerAllTest = null;
31
27
  globe = null;
32
28
  gl = null;
33
29
  _arcMap;
34
- _arcMapTest;
35
- _doBuild = false;
36
30
  _cameraUniformBlock = null;
37
- _attractionStrength = 8;
38
- constructor(id) {
31
+ _staticDynamicStrategy = null;
32
+ _styleOptions = {
33
+ variativeColorsOn: false,
34
+ defaultColor: [0.1, 0.1, 1, 1], // Default color in RGBA format
35
+ defaultHeightFromGroundIn3D: 30.0 // Default height from ground in
36
+ };
37
+ constructor(id, drawStyleOptions = null) {
39
38
  this.id = id;
40
39
  this._arcMap = new Map();
41
- this._arcMapTest = new Map();
40
+ if (drawStyleOptions) {
41
+ this._styleOptions = drawStyleOptions;
42
+ }
42
43
  }
43
- insertArcFromLongLat(key, startPoint, endPoint) {
44
+ insertArcFromLongLat(key, startPoint, endPoint, height = null) {
44
45
  if (this._arcMap.has(key)) {
45
46
  this._arcMap.delete(key);
46
47
  }
47
48
  vec3.fromLongLatToUnitVector(_start, [startPoint.long * RADIANS, startPoint.lat * RADIANS]);
48
49
  vec3.fromLongLatToUnitVector(_end, [endPoint.long * RADIANS, endPoint.lat * RADIANS]);
49
50
  const _arc = arc.create(_start, _end);
50
- this._arcMap.set(key, _arc);
51
- this._arcMapTest.set(key, arc.clone(_arc));
52
- this._doBuild = true;
51
+ this._arcMap.set(key, [_arc, height]);
52
+ // TODO: insert into buffer if NOT DYNAMIC state
53
+ if (this._staticDynamicStrategy?.getState() !== StaticDynamicState.DYNAMIC) {
54
+ this.__buildStaticArcs([key]);
55
+ }
53
56
  this.globe.DrawRender();
54
57
  }
55
58
  deleteArcs(keys) {
@@ -58,22 +61,23 @@ export class NaiveLineOnTerrainPlugin {
58
61
  this._arcMap.delete(key);
59
62
  }
60
63
  }
61
- this._doBuild = true;
64
+ // DELETE FROM BUFFER IF not DYNAMIC state
62
65
  this.globe.DrawRender();
63
66
  }
64
67
  init(globe, gl) {
65
68
  this.globe = globe;
66
69
  this.gl = gl;
67
70
  this.program = LineStripProgramCache.get(globe);
68
- const g3D = globe3Dcoordinates(globe, 30);
71
+ this._staticDynamicStrategy = new StaticDynamicStrategy(globe, 8); // Initialize static-dynamic strategy with a transition level of 8
69
72
  const g2D = globe2Dcoordinates(globe);
70
73
  this._cameraUniformBlock = CameraUniformBlockTotemCache.get(globe);
71
- this._bufferManagersCompMap = new Map([
74
+ this._staticDynamicStrategy = new StaticDynamicStrategy(globe, 8); // Initialize static-dynamic strategy with a transition level of 8
75
+ this.bufferManagerMap = new Map([
72
76
  ["position3d", {
73
77
  bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
74
78
  adaptor: (item) => {
75
- const { longLatArr } = item;
76
- const result = g3D(longLatArr, { paddingCount: 1 });
79
+ const { longLatArr, height = this._styleOptions.defaultHeightFromGroundIn3D } = item;
80
+ const result = globe3Dcoordinates(globe, height)(longLatArr, { paddingCount: 1 });
77
81
  // console.log("result", result);
78
82
  return result;
79
83
  }
@@ -87,42 +91,39 @@ export class NaiveLineOnTerrainPlugin {
87
91
  }
88
92
  ],
89
93
  ]);
90
- this._bufferManagersCompMapTest = new Map([
91
- ["positionTest3d", {
92
- bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
93
- adaptor: (item) => {
94
- const { longLatArr } = item;
95
- const result = g3D(longLatArr, { paddingCount: 1 });
96
- return result;
94
+ if (this._styleOptions.variativeColorsOn) {
95
+ this.bufferManagerMap.set("color", {
96
+ bufferManager: new BufferManager(gl, 4, { initialCapacity: INITAL_CAPACITY }),
97
+ adaptor: (item) => {
98
+ const { radius } = item;
99
+ // Calculate color based on radius
100
+ if (item.color) {
101
+ _colorArray.set(item.color);
102
+ return _colorArray;
97
103
  }
98
- }],
99
- ["positionTest2d", {
100
- bufferManager: new BufferManager(gl, 2 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
101
- adaptor: (item) => {
102
- const { longLatArr } = item;
103
- return g2D(longLatArr, { paddingCount: 1 });
104
+ else {
105
+ return this._styleOptions.defaultColor;
104
106
  }
105
107
  }
106
- ]
107
- ]);
108
+ });
109
+ }
108
110
  this._bufferOrchestrator = new BufferOrchestrator();
109
111
  this._arcUBOHandler = this.program.createUBO();
110
112
  this._arcUBOHandler.update(new Map([
111
113
  ["u_color", new Float32Array([1, 0, 0, 1])],
112
114
  ]));
113
- this._ubohandlerAllTest = this.program.createUBO();
114
- this._ubohandlerAllTest.update(new Map([
115
- ["u_color", new Float32Array([0, 0, 1, 1])],
116
- ]));
117
- this._vao = this.program.createVAO(createBufferAndReadInfo(this._bufferManagersCompMap.get("position3d")?.bufferManager.buffer), createBufferAndReadInfo(this._bufferManagersCompMap.get("position2d")?.bufferManager.buffer), null, null, null);
118
- this._vaoAllTest = this.program.createVAO(createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest3d")?.bufferManager.buffer), createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest2d")?.bufferManager.buffer), null, null, null);
115
+ this._vao = this.program.createVAO(createBufferAndReadInfo(this.bufferManagerMap.get("position3d")?.bufferManager.buffer), createBufferAndReadInfo(this.bufferManagerMap.get("position2d")?.bufferManager.buffer), null);
119
116
  }
120
117
  draw3D() {
121
118
  // Drawing logic here
119
+ if (!this.globe || !this.gl) {
120
+ console.warn("Globe or WebGL context is not initialized.");
121
+ return;
122
+ }
123
+ this._staticDynamicStrategy?.updateState();
122
124
  this._buildArcs(); // can be async
123
- const { gl, program, _bufferOrchestrator, _vao, _arcUBOHandler, _vaoAllTest, _ubohandlerAllTest, _testOrchestrator } = this;
124
- if (!gl || !program || !_bufferOrchestrator || !_vao || !_arcUBOHandler
125
- || !_vaoAllTest || !_ubohandlerAllTest || !_testOrchestrator) {
125
+ const { gl, program, _bufferOrchestrator, _vao, _arcUBOHandler, } = this;
126
+ if (!gl || !program || !_bufferOrchestrator || !_vao || !_arcUBOHandler) {
126
127
  console.warn("WebGL context, program, or buffer orchestrator is not initialized.");
127
128
  return;
128
129
  }
@@ -138,10 +139,65 @@ export class NaiveLineOnTerrainPlugin {
138
139
  gl.enable(gl.DEPTH_TEST);
139
140
  }
140
141
  _buildArcs() {
141
- if (!this._doBuild)
142
- return; // if not needed to build, return early
143
- const { globe, _arcMap, _cameraUniformBlock, _bufferManagersCompMap } = this;
144
- if (!globe || !_cameraUniformBlock || !_bufferManagersCompMap) {
142
+ const state = this._staticDynamicStrategy?.getState();
143
+ if (state === StaticDynamicState.TO_STATIC) {
144
+ this.__buildStaticArcs();
145
+ }
146
+ else if (state === StaticDynamicState.DYNAMIC) {
147
+ this.__buildArcs();
148
+ }
149
+ }
150
+ __buildStaticArcs(keys = []) {
151
+ const { globe, _arcMap, _cameraUniformBlock, bufferManagerMap, _bufferOrchestrator } = this;
152
+ if (!globe || !_cameraUniformBlock || !bufferManagerMap || !_bufferOrchestrator) {
153
+ console.warn("Globe or camera uniform block is not initialized.");
154
+ return;
155
+ }
156
+ const longLat = [0, 0];
157
+ const _attractionStrength = 0;
158
+ const longLatArr = new Float32Array(2 * VERTEX_COUNT);
159
+ const data = [{
160
+ key: "staticArcs",
161
+ longLatArr: longLatArr,
162
+ height: null
163
+ }];
164
+ if (keys.length == 0) {
165
+ for (const [key, [arcInstance, height]] of _arcMap) {
166
+ arc.copy(_0arc, arcInstance);
167
+ const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, _attractionStrength);
168
+ for (let i = 0; i < generatedPoints.length; i++) {
169
+ const point = generatedPoints[i];
170
+ vec3.fromUnitVectorToLongLat(longLat, point);
171
+ longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
172
+ }
173
+ data[0].key = key;
174
+ data[0].height = height;
175
+ this._bufferOrchestrator.insertBulk(data, bufferManagerMap);
176
+ }
177
+ }
178
+ else {
179
+ for (let key of keys) {
180
+ if (!_arcMap.has(key)) {
181
+ console.warn(`Arc with key ${key} not found in arcMap.`);
182
+ continue;
183
+ }
184
+ const [arcInstance, height] = _arcMap.get(key);
185
+ arc.copy(_0arc, arcInstance);
186
+ const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, _attractionStrength);
187
+ for (let i = 0; i < generatedPoints.length; i++) {
188
+ const point = generatedPoints[i];
189
+ vec3.fromUnitVectorToLongLat(longLat, point);
190
+ longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
191
+ }
192
+ data[0].key = key;
193
+ data[0].height = height;
194
+ this._bufferOrchestrator.insertBulk(data, bufferManagerMap);
195
+ }
196
+ }
197
+ }
198
+ __buildArcs() {
199
+ const { globe, _arcMap, _cameraUniformBlock, bufferManagerMap } = this;
200
+ if (!globe || !_cameraUniformBlock || !bufferManagerMap) {
145
201
  console.warn("Globe or camera uniform block is not initialized.");
146
202
  return;
147
203
  }
@@ -162,7 +218,7 @@ export class NaiveLineOnTerrainPlugin {
162
218
  console.log("Attraction strength: ", _attractionStrength);
163
219
  const result = [];
164
220
  const longLat = [0, 0];
165
- for (const [key, arcInstance] of _arcMap) {
221
+ for (const [key, [arcInstance, height]] of _arcMap) {
166
222
  arc.copy(_0arc, arcInstance);
167
223
  const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPosition);
168
224
  if (!isOnArc) {
@@ -183,23 +239,12 @@ export class NaiveLineOnTerrainPlugin {
183
239
  result.push({
184
240
  key: key,
185
241
  longLatArr: longLatArr,
242
+ height: height
186
243
  });
187
244
  }
188
- this._bufferOrchestrator.resetWithCapacity(_bufferManagersCompMap, result.length);
189
- this._bufferOrchestrator.insertBulk(result, _bufferManagersCompMap);
190
- this._doBuild = false; // reset build flag
191
- this._checkIfCorrupted(); // check if any arc is corrupted
245
+ this._bufferOrchestrator.resetWithCapacity(bufferManagerMap, result.length);
246
+ this._bufferOrchestrator.insertBulk(result, bufferManagerMap);
192
247
  }
193
- _checkIfCorrupted() {
194
- for (const [key, arcInstance] of this._arcMap) {
195
- const copyarc = this._arcMapTest.get(key);
196
- if (!copyarc) {
197
- console.warn(`Arc with key ${key} is missing in the test map.`);
198
- continue;
199
- }
200
- if (!arc.equals(arcInstance, copyarc)) {
201
- console.warn(`Arc with key ${key} is corrupted: p0 and p1 are the same point.`);
202
- }
203
- }
248
+ _buildStaticArc() {
204
249
  }
205
250
  }