@pirireis/webglobeplugins 0.11.1-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.
Files changed (38) hide show
  1. package/Math/arc-cdf-points.js +252 -0
  2. package/Math/{arc-generate-points.js → arc-generate-points copy.js } +4 -0
  3. package/Math/arc-generate-points-exponantial.js +254 -0
  4. package/Math/arc.js +5 -5
  5. package/Math/circle-cdf-points.js +247 -0
  6. package/Math/circle.js +39 -0
  7. package/Math/methods.js +13 -3
  8. package/Math/vec3.js +3 -3
  9. package/package.json +1 -1
  10. package/programs/line-on-globe/circle-accurate.js +176 -175
  11. package/programs/line-on-globe/circle.js +166 -164
  12. package/programs/line-on-globe/linestrip/data.js +4 -0
  13. package/programs/line-on-globe/{linestrip.js → linestrip/linestrip.js} +38 -39
  14. package/programs/line-on-globe/to-the-surface.js +111 -109
  15. package/programs/rings/distancering/circleflatprogram.js +116 -120
  16. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +1 -1
  17. package/programs/rings/distancering/circlepaddysharedbuffer.js +368 -354
  18. package/programs/rings/distancering/index.js +6 -5
  19. package/programs/rings/distancering/paddyflatprogram.js +127 -136
  20. package/programs/rings/distancering/paddyflatprogram2d.js +129 -138
  21. package/programs/rings/distancering/paddyflatprogram3d.js +128 -136
  22. package/programs/totems/camerauniformblock.js +35 -8
  23. package/programs/totems/canvas-webglobe-info.js +55 -20
  24. package/programs/totems/{camerauniformblock copy.js → canvas-webglobe-info1.js} +11 -76
  25. package/programs/vectorfields/logics/pixelbased.js +4 -20
  26. package/shape-on-terrain/arc/naive/plugin.js +249 -288
  27. package/shape-on-terrain/circle/plugin.js +284 -0
  28. package/shape-on-terrain/type.js +1 -0
  29. package/util/account/index.js +2 -2
  30. package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -3
  31. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +2 -2
  32. package/util/build-strategy/general-strategy.js +62 -0
  33. package/util/build-strategy/static-dynamic.js +31 -0
  34. package/util/gl-util/draw-options/types.js +1 -1
  35. package/globe-types.js +0 -1
  36. package/programs/interface.js +0 -1
  37. package/programs/rings/distancering/shader.js +0 -1
  38. package/programs/totems/camerauniformblock1.js +0 -171
@@ -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){
@@ -80,11 +64,11 @@ void main(){
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,289 +1,250 @@
1
- "use strict";
2
- // import { LineStripProgramCache } from "../../../programs/line-on-globe/linestrip"
3
- // import "../../../programs/interface";
4
- // import { createBufferAndReadInfo } from '../../../util/gl-util/buffer/attribute-loader';
1
+ import { LineStripProgramCache } from "../../../programs/line-on-globe/linestrip/linestrip";
2
+ import { createBufferAndReadInfo } from '../../../util/gl-util/buffer/attribute-loader';
5
3
  // import { populateFloat32Array } from "../../../util/jshelpers/data-filler";
6
- // import { BufferManagementMap, BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
7
- // import { globe3Dcoordinates, globe2Dcoordinates, RADIANS } from "../../../Math/methods";
8
- // import { generateArcPoints } from "../../../Math/arc-generate-points";
9
- // import { Vec3, Plane, Arc } from "../../../Math/types";
10
- // import * as vec3 from "../../../Math/vec3";
11
- // import * as plane from "../../../Math/plane";
12
- // import * as arc from "../../../Math/arc";
13
- // // import { arcFrustumPlanesIntersection } from "../../../Math/intersections/arc-frustum-planes";
14
- // import CameraUniformBlockTotem, { CameraUniformBlockTotemCache } from "../../../programs/totems/camerauniformblock";
15
- // import { FrustumPlanes } from "../../../Math/frustum/types";
16
- // const VERTEX_COUNT = 360;
17
- // const INITAL_CAPACITY = 10;
18
- // const _0vector = [0, 0, 0] as Vec3;
19
- // const _attractionPoint = [0, 0, 0] as Vec3;
20
- // const _start = [0, 0, 0] as Vec3;
21
- // const _end = [0, 0, 0] as Vec3;
22
- // const _0arc = arc.create([1, 0, 0] as Vec3, [0, 1, 0] as Vec3); // zero arc for intersection tests
23
- // // window add properties
24
- // declare global {
25
- // interface Window {
26
- // startPoint: Vec3;
27
- // endPoint: Vec3;
28
- // }
29
- // }
30
- // let interval = 1;
31
- // export class NaiveLineOnTerrainPlugin {
32
- // public id: string;
33
- // private program: ProgramInterface | null = null;
34
- // private _bufferManagersCompMap: BufferManagementMap | null = null;
35
- // private _bufferManagersCompMapTest: BufferManagementMap | null = null;
36
- // private _bufferOrchestrator: BufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
37
- // private _testOrchestrator: BufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
38
- // private _opacity: number = 1;
39
- // private _arcUBOHandler: UBOHandler | null = null;
40
- // private _vao: WebGLVertexArrayObject | null = null;
41
- // private _vaoAllTest: WebGLVertexArrayObject | null = null;
42
- // private _ubohandlerAllTest: UBOHandler | null = null;
43
- // private globe: any | null = null;
44
- // private gl: WebGL2RenderingContext | null = null;
45
- // private _arcMap: Map<string, Arc>;
46
- // private _arcMapTest: Map<string, Arc>;
47
- // private _screenPlane: Plane = { normal: [0, 0, 1] as Vec3, distance: 0 } as Plane;
48
- // private _doBuild: boolean = false
49
- // private _cameraUniformBlock: CameraUniformBlockTotem | null = null;
50
- // private _attractionStrength: number = 50;
51
- // public fieldOfView = 50 * RADIANS; // 50 degrees in radians
52
- // constructor(id: string) {
53
- // this.id = id;
54
- // this._arcMap = new Map();
55
- // this._arcMapTest = new Map();
56
- // }
57
- // insertArcFromLongLat(key: string, startPoint: { long: number, lat: number }, endPoint: { long: number, lat: number }) {
58
- // if (this._arcMap.has(key)) {
59
- // this._arcMap.delete(key);
60
- // }
61
- // vec3.fromUnitVectorLongLat(_start, [startPoint.long * RADIANS, startPoint.lat * RADIANS]);
62
- // vec3.fromUnitVectorLongLat(_end, [endPoint.long * RADIANS, endPoint.lat * RADIANS]);
63
- // window.startPoint = _start;
64
- // window.endPoint = _end;
65
- // const _arc = arc.create(_start, _end);
66
- // this._arcMap.set(key, _arc);
67
- // this._arcMapTest.set(key, arc.clone(_arc));
68
- // // const longLatArr = new Float32Array(2 * VERTEX_COUNT);
69
- // // //
70
- // // const _3Dpoints = generateArcPoints(_start, _end, VERTEX_COUNT);
71
- // // const longLat = {
72
- // // long: 1,
73
- // // lat: 1
74
- // // };
75
- // // for (let i = 0; i < _3Dpoints.length / 3; i++) {
76
- // // _0vector.set(_3Dpoints[i * 3], _3Dpoints[i * 3 + 1], _3Dpoints[i * 3 + 2]).toLongLat(longLat);
77
- // // longLatArr.set([longLat.long / RADIANS, longLat.lat / RADIANS], i * 2);
78
- // // }
79
- // // const result = [{
80
- // // key: key,
81
- // // longLatArr: longLatArr,
82
- // // }
83
- // // ]
84
- // // this._testOrchestrator.insertBulk(result, this._bufferManagersCompMapTest);
85
- // this._doBuild = true;
86
- // this.globe.DrawRender();
87
- // }
88
- // init(globe: any, gl: WebGL2RenderingContext) {
89
- // this.globe = globe;
90
- // this.gl = gl;
91
- // this.program = LineStripProgramCache.get(globe);
92
- // const g3D = globe3Dcoordinates(globe, 30);
93
- // const g2D = globe2Dcoordinates(globe);
94
- // this._cameraUniformBlock = CameraUniformBlockTotemCache.get(globe);
95
- // this._bufferManagersCompMap = new Map(
96
- // [
97
- // ["position3d", {
98
- // bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
99
- // adaptor: (item: any) => {
100
- // const { longLatArr } = item;
101
- // const result = g3D(longLatArr, { paddingCount: 1 });
102
- // // console.log("result", result);
103
- // return result;
104
- // }
105
- // }],
106
- // ["position2d", {
107
- // bufferManager: new BufferManager(gl, 2 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
108
- // adaptor: (item: any) => {
109
- // const { longLatArr } = item;
110
- // return g2D(longLatArr, { paddingCount: 1 });
111
- // }
112
- // }
113
- // ],
114
- // ]
115
- // );
116
- // this._bufferManagersCompMapTest = new Map([
117
- // ["positionTest3d", {
118
- // bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
119
- // adaptor: (item: any) => {
120
- // const { longLatArr } = item;
121
- // const result = g3D(longLatArr, { paddingCount: 1 });
122
- // return result;
123
- // }
124
- // }],
125
- // ["positionTest2d", {
126
- // bufferManager: new BufferManager(gl, 2 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
127
- // adaptor: (item: any) => {
128
- // const { longLatArr } = item;
129
- // return g2D(longLatArr, { paddingCount: 1 });
130
- // }
131
- // }
132
- // ]
133
- // ]
134
- // );
135
- // this._bufferOrchestrator = new BufferOrchestrator();
136
- // this._arcUBOHandler = this.program.createUBO();
137
- // this._arcUBOHandler.update(new Map([
138
- // ["u_color", new Float32Array([1, 0, 0, 1])],
139
- // ]));
140
- // this._ubohandlerAllTest = this.program.createUBO();
141
- // this._ubohandlerAllTest.update(new Map([
142
- // ["u_color", new Float32Array([0, 0, 1, 1])],
143
- // ]));
144
- // this._vao = this.program.createVAO(
145
- // createBufferAndReadInfo(this._bufferManagersCompMap.get("position3d")?.bufferManager.buffer as WebGLBuffer),
146
- // createBufferAndReadInfo(this._bufferManagersCompMap.get("position2d")?.bufferManager.buffer as WebGLBuffer),
147
- // null,
148
- // null,
149
- // null,
150
- // );
151
- // this._vaoAllTest = this.program.createVAO(
152
- // createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest3d")?.bufferManager.buffer as WebGLBuffer),
153
- // createBufferAndReadInfo(this._bufferManagersCompMapTest.get("positionTest2d")?.bufferManager.buffer as WebGLBuffer),
154
- // null,
155
- // null,
156
- // null,
157
- // );
158
- // }
159
- // setFieldOfView(fieldOfView: number) {
160
- // this.fieldOfView = fieldOfView * RADIANS; // convert degrees to radians
161
- // this.globe.DrawRender();
162
- // }
163
- // _buildArcs() {
164
- // const { globe, _arcMap, _cameraUniformBlock } = this;
165
- // const cameraPositionNormalized = _cameraUniformBlock.getCameraPositionNormalized() as Vec3;
166
- // const result = [];
167
- // const longLat = [0, 0] as [number, number];
168
- // for (const [key, arcInstance] of _arcMap) {
169
- // arc.copy(_0arc, arcInstance);
170
- // const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPositionNormalized);
171
- // if (!isOnArc) {
172
- // vec3.distanceSquared(cameraPositionNormalized, _0arc.p0) < vec3.distanceSquared(cameraPositionNormalized, _0arc.p1) ?
173
- // vec3.copy(_attractionPoint, _0arc.p0) : vec3.copy(_attractionPoint, _0arc.p1);
174
- // }
175
- // const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, this._attractionStrength);
176
- // const longLatArr = new Float32Array(2 * VERTEX_COUNT);
177
- // for (let i = 0; i < generatedPoints.length; i++) {
178
- // const point = generatedPoints[i];
179
- // vec3.toUnitVectorLongLat(longLat, point);
180
- // longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
181
- // }
182
- // result.push({
183
- // key: key,
184
- // longLatArr: longLatArr,
185
- // })
186
- // }
187
- // this._bufferOrchestrator.resetWithCapacity(this._bufferManagersCompMap, result.length);
188
- // this._bufferOrchestrator.insertBulk(result, this._bufferManagersCompMap);
189
- // this._doBuild = false; // reset build flag
190
- // this._checkIfCorrupted(); // check if any arc is corrupted
191
- // }
192
- // setAttractionStrength(strength: number) {
193
- // this._attractionStrength = strength;
194
- // this._doBuild = true; // trigger rebuild
195
- // this.globe.DrawRender();
196
- // }
197
- // // _buildArcs() {
198
- // // // updatePlane
199
- // // const { globe, _arcMap } = this;
200
- // // const planes = this._cameraUniformBlock.getFrustumPlanes() as FrustumPlanes;
201
- // // //
202
- // // const cameraPostition = new Vector3D();
203
- // // cameraPostition.copy(globe.Fp as Vector3D).normalize();
204
- // // // calculateHorizonPlane(globe, _screenPlane, this.fieldOfView);
205
- // // const result = [];
206
- // // const longLat = {
207
- // // long: 1,
208
- // // lat: 1
209
- // // }
210
- // // let counter = 0;
211
- // // for (const [key, arc] of _arcMap) {
212
- // // // const isArc = arc.intersectionMedium(_screenPlane, _0arc) as Arc;
213
- // // _0arc.copy(arc);
214
- // // const isArc = arcFrustumPlanesIntersection(_0arc, planes, _0arc);
215
- // // if (!isArc) {
216
- // // continue;
217
- // // }
218
- // // counter++;
219
- // // const longLatArr = new Float32Array(2 * VERTEX_COUNT);
220
- // // // const _3Dpoints = _0arc.populatePoints3DInRespectToCamera(cameraPostition, VERTEX_COUNT);
221
- // // const _3Dpoints = _0arc.populatePoints3D(VERTEX_COUNT);
222
- // // for (let i = 0; i < _3Dpoints.length / 3; i++) {
223
- // // _0vector.set(_3Dpoints[i * 3], _3Dpoints[i * 3 + 1], _3Dpoints[i * 3 + 2]).toLongLat(longLat);
224
- // // longLatArr.set([longLat.long / RADIANS, longLat.lat / RADIANS], i * 2);
225
- // // }
226
- // // result.push({
227
- // // key: key,
228
- // // longLatArr: longLatArr,
229
- // // });
230
- // // // if (!arc.imaginaryPlane.equals(_0arc.imaginaryPlane) || !arc.imaginaryPlane.equalsReverseOriantation(_0arc.imaginaryPlane)) {
231
- // // // // console.log("Arc with key", key, "has imaginary plane equal to the original arc's imaginary plane.");
232
- // // // throw new Error("The arc segment is not on the parent arc")
233
- // // // }
234
- // // }
235
- // // interval += 1;
236
- // // if (interval === 100) {
237
- // // interval = 1;
238
- // // console.log("Arc count on screen:", counter);
239
- // // }
240
- // // // update buffer
241
- // // this._bufferOrchestrator.resetWithCapacity(this._bufferManagersCompMap, result.length);
242
- // // this._bufferOrchestrator.insertBulk(result, this._bufferManagersCompMap);
243
- // // this._doBuild = false;
244
- // // this._checkIfCorrupted(); // check if any arc is corrupted
245
- // // }
246
- // draw3D() {
247
- // // Drawing logic here
248
- // this._buildArcs() // can be async
249
- // const { gl, program, _bufferOrchestrator } = this;
250
- // gl.disable(gl.DEPTH_TEST);
251
- // const drawOptionTest = {
252
- // drawRange: {
253
- // first: 0,
254
- // count: this._testOrchestrator.length * (VERTEX_COUNT + 1)
255
- // },
256
- // indexes: null
257
- // }
258
- // program.draw(
259
- // this._vaoAllTest,
260
- // drawOptionTest,
261
- // this._opacity,
262
- // this._ubohandlerAllTest
263
- // );
264
- // const drawOptions = {
265
- // drawRange: {
266
- // first: 0,
267
- // count: _bufferOrchestrator.length * (VERTEX_COUNT + 1)
268
- // },
269
- // indexes: null
270
- // }
271
- // program.draw(
272
- // this._vao,
273
- // drawOptions,
274
- // this._opacity,
275
- // this._arcUBOHandler
276
- // );
277
- // gl.enable(gl.DEPTH_TEST);
278
- // }
279
- // _checkIfCorrupted() {
280
- // for (const [key, arc] of this._arcMap) {
281
- // if (!arc.p0.equals(arc.p1)) {
282
- // continue; // valid arc
283
- // }
284
- // console.warn(`Arc with key ${key} is corrupted: p0 and p1 are the same point.`);
285
- // // this._arcMap.delete(key);
286
- // // this._arcMapTest.delete(key);
287
- // }
288
- // }
289
- // }
4
+ import { BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
5
+ import { globe3Dcoordinates, globe2Dcoordinates, RADIANS } from "../../../Math/methods";
6
+ import { generateArcPoints } from "../../../Math/arc-cdf-points";
7
+ import { StaticDynamicState, StaticDynamicStrategy } from "../../../util/build-strategy/static-dynamic";
8
+ import * as vec3 from "../../../Math/vec3";
9
+ import * as arc from "../../../Math/arc";
10
+ import { CameraUniformBlockTotemCache } from "../../../programs/totems/camerauniformblock";
11
+ import { WORLD_RADIUS_3D } from "../../../Math/constants";
12
+ const VERTEX_COUNT = 70;
13
+ const INITAL_CAPACITY = 10;
14
+ const _attractionPoint = [0, 0, 0];
15
+ const _start = [0, 0, 0];
16
+ const _end = [0, 0, 0];
17
+ const _0arc = arc.create([1, 0, 0], [0, 1, 0]); // zero arc for intersection tests
18
+ const _colorArray = new Float32Array(4); // For color buffer
19
+ export class NaiveLineOnTerrainPlugin {
20
+ id;
21
+ program = null;
22
+ bufferManagerMap = null;
23
+ _bufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
24
+ _opacity = 1;
25
+ _arcUBOHandler = null;
26
+ _vao = null;
27
+ globe = null;
28
+ gl = null;
29
+ _arcMap;
30
+ _cameraUniformBlock = null;
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) {
38
+ this.id = id;
39
+ this._arcMap = new Map();
40
+ if (drawStyleOptions) {
41
+ this._styleOptions = drawStyleOptions;
42
+ }
43
+ }
44
+ insertArcFromLongLat(key, startPoint, endPoint, height = null) {
45
+ if (this._arcMap.has(key)) {
46
+ this._arcMap.delete(key);
47
+ }
48
+ vec3.fromLongLatToUnitVector(_start, [startPoint.long * RADIANS, startPoint.lat * RADIANS]);
49
+ vec3.fromLongLatToUnitVector(_end, [endPoint.long * RADIANS, endPoint.lat * RADIANS]);
50
+ const _arc = arc.create(_start, _end);
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
+ }
56
+ this.globe.DrawRender();
57
+ }
58
+ deleteArcs(keys) {
59
+ for (const key of keys) {
60
+ if (this._arcMap.has(key)) {
61
+ this._arcMap.delete(key);
62
+ }
63
+ }
64
+ // DELETE FROM BUFFER IF not DYNAMIC state
65
+ this.globe.DrawRender();
66
+ }
67
+ init(globe, gl) {
68
+ this.globe = globe;
69
+ this.gl = gl;
70
+ this.program = LineStripProgramCache.get(globe);
71
+ this._staticDynamicStrategy = new StaticDynamicStrategy(globe, 8); // Initialize static-dynamic strategy with a transition level of 8
72
+ const g2D = globe2Dcoordinates(globe);
73
+ this._cameraUniformBlock = CameraUniformBlockTotemCache.get(globe);
74
+ this._staticDynamicStrategy = new StaticDynamicStrategy(globe, 8); // Initialize static-dynamic strategy with a transition level of 8
75
+ this.bufferManagerMap = new Map([
76
+ ["position3d", {
77
+ bufferManager: new BufferManager(gl, 3 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
78
+ adaptor: (item) => {
79
+ const { longLatArr, height = this._styleOptions.defaultHeightFromGroundIn3D } = item;
80
+ const result = globe3Dcoordinates(globe, height)(longLatArr, { paddingCount: 1 });
81
+ // console.log("result", result);
82
+ return result;
83
+ }
84
+ }],
85
+ ["position2d", {
86
+ bufferManager: new BufferManager(gl, 2 * (VERTEX_COUNT + 1), { bufferType: "DYNAMIC_DRAW", initialCapacity: INITAL_CAPACITY }),
87
+ adaptor: (item) => {
88
+ const { longLatArr } = item;
89
+ return g2D(longLatArr, { paddingCount: 1 });
90
+ }
91
+ }
92
+ ],
93
+ ]);
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;
103
+ }
104
+ else {
105
+ return this._styleOptions.defaultColor;
106
+ }
107
+ }
108
+ });
109
+ }
110
+ this._bufferOrchestrator = new BufferOrchestrator();
111
+ this._arcUBOHandler = this.program.createUBO();
112
+ this._arcUBOHandler.update(new Map([
113
+ ["u_color", new Float32Array([1, 0, 0, 1])],
114
+ ]));
115
+ this._vao = this.program.createVAO(createBufferAndReadInfo(this.bufferManagerMap.get("position3d")?.bufferManager.buffer), createBufferAndReadInfo(this.bufferManagerMap.get("position2d")?.bufferManager.buffer), null);
116
+ }
117
+ draw3D() {
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();
124
+ this._buildArcs(); // can be async
125
+ const { gl, program, _bufferOrchestrator, _vao, _arcUBOHandler, } = this;
126
+ if (!gl || !program || !_bufferOrchestrator || !_vao || !_arcUBOHandler) {
127
+ console.warn("WebGL context, program, or buffer orchestrator is not initialized.");
128
+ return;
129
+ }
130
+ gl.disable(gl.DEPTH_TEST);
131
+ const drawOptions = {
132
+ drawRange: {
133
+ first: 0,
134
+ count: _bufferOrchestrator.length * (VERTEX_COUNT + 1)
135
+ },
136
+ indexes: null
137
+ };
138
+ program.draw(_vao, drawOptions, this._opacity, _arcUBOHandler);
139
+ gl.enable(gl.DEPTH_TEST);
140
+ }
141
+ _buildArcs() {
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) {
201
+ console.warn("Globe or camera uniform block is not initialized.");
202
+ return;
203
+ }
204
+ const lookAtPosition = _cameraUniformBlock.getLookAtVector();
205
+ const cameraPosition = _cameraUniformBlock.getCameraVector();
206
+ vec3.divideScalar(cameraPosition, cameraPosition, WORLD_RADIUS_3D);
207
+ vec3.add(cameraPosition, cameraPosition, lookAtPosition);
208
+ // vec3.normalize(cameraPosition, cameraPosition);
209
+ vec3.divideScalar(cameraPosition, cameraPosition, 2);
210
+ // vec3.multiplyScalar(cameraPosition, cameraPosition, 1.3);
211
+ const _attractionStrength = (() => {
212
+ const lod = globe.api_GetCurrentLODWithDecimal();
213
+ if (lod < 11) {
214
+ return 1;
215
+ }
216
+ return lod * (lod - 8.5);
217
+ })();
218
+ console.log("Attraction strength: ", _attractionStrength);
219
+ const result = [];
220
+ const longLat = [0, 0];
221
+ for (const [key, [arcInstance, height]] of _arcMap) {
222
+ arc.copy(_0arc, arcInstance);
223
+ const isOnArc = arc.closestPoint(_attractionPoint, _0arc, cameraPosition);
224
+ if (!isOnArc) {
225
+ if (vec3.distanceSquared(cameraPosition, _0arc.p0) < vec3.distanceSquared(cameraPosition, _0arc.p1)) {
226
+ vec3.copy(_attractionPoint, _0arc.p0);
227
+ }
228
+ else {
229
+ vec3.copy(_attractionPoint, _0arc.p1);
230
+ }
231
+ }
232
+ const generatedPoints = generateArcPoints(_0arc.p0, _0arc.p1, _0arc.normal, _attractionPoint, VERTEX_COUNT, _attractionStrength);
233
+ const longLatArr = new Float32Array(2 * VERTEX_COUNT);
234
+ for (let i = 0; i < generatedPoints.length; i++) {
235
+ const point = generatedPoints[i];
236
+ vec3.fromUnitVectorToLongLat(longLat, point);
237
+ longLatArr.set([longLat[0] / RADIANS, longLat[1] / RADIANS], i * 2);
238
+ }
239
+ result.push({
240
+ key: key,
241
+ longLatArr: longLatArr,
242
+ height: height
243
+ });
244
+ }
245
+ this._bufferOrchestrator.resetWithCapacity(bufferManagerMap, result.length);
246
+ this._bufferOrchestrator.insertBulk(result, bufferManagerMap);
247
+ }
248
+ _buildStaticArc() {
249
+ }
250
+ }