@pirireis/webglobeplugins 0.6.14 → 0.6.15

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.
@@ -0,0 +1,406 @@
1
+ import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
2
+ import { CircleCache } from '../programs/line-on-globe/circle';
3
+ import { LineToTheOriginCache } from "../programs/line-on-globe/to-the-origin"
4
+ import { BufferOrchestrator, BufferManager } from "../util/account";
5
+ import { ChainListMap } from "./chain-list-map";
6
+ import { mapGetOrThrow } from "../util/check/get";
7
+ import { keyMethod } from "./util";
8
+ import { ContextTextWriter3 } from '../write-text/context-text3';
9
+ // TODO: Add update buffer and update text mehods on add, delete, update methods
10
+
11
+
12
+ /**
13
+ * Insert info to chain list map (nodes and properties)
14
+ *
15
+ * ask chain list map for text data
16
+ * ask chain list map for buffer data
17
+ *
18
+ *
19
+ * addNode
20
+ * insertBulk
21
+ * deleteChain
22
+ * deleteNodes
23
+ * updateCoordinates()
24
+ * updateChainProperties
25
+ */
26
+
27
+
28
+ /**
29
+ * @typedef StyleProperties
30
+ * @property {[0-1,0-1,0-1,0-1]} rgba
31
+ * @property { 0-1 } dashOpacity
32
+ * @property { 0-1 } dashRatio
33
+ * @property {0-360} circleDashAngle
34
+ * @property {Array<node>} nodes
35
+ */
36
+
37
+ const radian = Math.PI / 180;
38
+
39
+ export class CircleLineChainPlugin {
40
+ /**
41
+ *
42
+ * @param {*} id
43
+ * @param {Map<[key, ContextTextWriter3]} textContextWriterInjectionMap //import { ContextTextWriter3 } from "@pirireis/webglobeplugins/write-text/context-text3";
44
+ */
45
+ constructor(id, {
46
+ drawCircleOn = true,
47
+ textContextWriterInjectionMap = new Map(),
48
+ textDataPreAdaptor = null
49
+ } = {}) {
50
+ this.id = id;
51
+ this._checkTextContextWriterInjectionMap(textContextWriterInjectionMap);
52
+ this._textContextWriterInjectionMap = textContextWriterInjectionMap;
53
+ this._textContextWriterInjectionMap.forEach((writer) => writer.setKeyAdaptor((v, i, c, properties) => v.__identity__));
54
+ this._opacity = 1;
55
+ this._chainListMap = new ChainListMap(keyMethod);
56
+ this.bufferOrchestrator = new BufferOrchestrator({ capacity: 10 });
57
+ this._drawCircleOn = drawCircleOn;
58
+ this._textDataPreAdaptor = textDataPreAdaptor;
59
+ }
60
+
61
+ // init
62
+
63
+ init(globe, gl) {
64
+ this.gl = gl;
65
+ this.globe = globe
66
+ this._initOrchestrations()
67
+ }
68
+
69
+ _checkTextContextWriterInjectionMap(textContextWriterInjectionMap) {
70
+ if (!(textContextWriterInjectionMap instanceof Map)) throw new Error("textContextWriterInjectionMap is not an instance of Map");
71
+ textContextWriterInjectionMap.forEach((v) => {
72
+ if (!(v instanceof ContextTextWriter3)) throw new Error("textContextWriterInjectionMap element is not an instance of ContextTextWriter3");
73
+ });
74
+ }
75
+
76
+ _initOrchestrations() {
77
+ const { gl, globe } = this;
78
+ this.lineProgram = LineOnGlobeCache.get(globe);
79
+ this.circleProgram = CircleCache.get(globe);
80
+ this.lineToTheOriginProgram = LineToTheOriginCache.get(globe);
81
+ {
82
+ // createBuffers
83
+ const bufferType = "DYNAMIC_DRAW";
84
+ const initialCapacity = this.bufferOrchestrator.capacity;
85
+ this.bufferManagersCompMap = new Map(
86
+ [
87
+ ["centerCoords2d", {
88
+ 'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
89
+ 'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.long, item.lat)),
90
+ }],
91
+ ["centerCoords3d", {
92
+ 'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
93
+ 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
94
+ }],
95
+ ["targetCoords2d", {
96
+ 'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
97
+ 'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.targetLong, item.targetLat)),
98
+ }],
99
+ ["targetCoords3d", {
100
+ 'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
101
+ 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.targetLong, item.targetLat, 0, 0)),
102
+ }],
103
+ ["rgba", {
104
+ 'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
105
+ 'adaptor': (item) => {
106
+ if (item.lineProperties?.rgba) return new Float32Array(item.lineProperties.rgba);
107
+ return new Float32Array(item.chainProperties.rgba);
108
+ }
109
+ }],
110
+ ["bigRadius", {
111
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
112
+ 'adaptor': (item) => new Float32Array([item.bigRadius])
113
+ }],
114
+ ["dashRatio", {
115
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
116
+ 'adaptor': (item) => new Float32Array([item.chainProperties.dashRatio])
117
+ }],
118
+
119
+ ["dashOpacity", {
120
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
121
+ 'adaptor': (item) => new Float32Array([item.chainProperties.dashOpacity])
122
+ }],
123
+ ["circleDashAngle", {
124
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
125
+ 'adaptor': (item) => {
126
+ if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
127
+ return new Float32Array([item.chainProperties.circleDashAngle / 360]);
128
+ }
129
+ }],
130
+ ["rgbaCircle", {
131
+ "bufferManager": new BufferManager(gl, 4, { bufferType, initialCapacity }),
132
+ "adaptor": (item) => {
133
+ if (item.circleProperties?.rgba) return new Float32Array(item.circleProperties.rgba);
134
+ return new Float32Array(item.chainProperties.rgba);
135
+ }
136
+ }]
137
+ ]
138
+ );
139
+ // (startPotisionBufferObj, endPositionBufferObj, dashRatioBufferObj, colorBufferObj)
140
+ const obj = function (bufferManagerComp) {
141
+ return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
142
+ };
143
+ this.lineVao = this.lineProgram.createVAO(
144
+ ...['centerCoords2d', 'centerCoords3d', 'targetCoords2d', 'targetCoords3d', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
145
+ // this.circleVao = this.circleProgram.createVAO(
146
+ // ...["centerCoords", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
147
+ // this.toOriginVao = this.lineToTheOriginProgram.createVAO(
148
+ // ...["targetCoords", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key))));
149
+ }
150
+
151
+ }
152
+
153
+
154
+ // API
155
+ setDrawCircleOn(bool) {
156
+ if (typeof bool !== 'boolean') throw new Error("setDrawCircleOn parameter must be a boolean");
157
+ this._drawCircleOn = bool;
158
+ this.globe.DrawRender();
159
+ }
160
+ // -- update bulk family
161
+ /**
162
+ *
163
+ * @param {Array<chain>} data
164
+ * @typedef chain
165
+ * @property {string} chainKey
166
+ * @property {Array<node>} nodes
167
+ * @typedef {Object} node
168
+ * @property {string} key
169
+ * @property {number} long
170
+ * @property {number} lat
171
+ */
172
+ updateCoordinatesBulk(data, { textWriterIDs = [] } = {}) {
173
+ // update implicit data structure
174
+ // find keys to update.. (inserted data and the radius of "from")
175
+ // updateBuffers
176
+ // update text
177
+ const chainKeys = [];
178
+ for (const chain of data) {
179
+ chainKeys.push(chain.chainKey);
180
+ chain.nodes.forEach((node) => {
181
+ this._chainListMap.updateCoordsinatesOfNode(node, chain.chainKey);
182
+ });
183
+ }
184
+ this._reconstructChains(chainKeys);
185
+ this._updateTexts(chainKeys, textWriterIDs);
186
+ }
187
+
188
+
189
+ /**
190
+ *
191
+ * @param {*} chainKey
192
+ * @param {Array<{nodeKey, circleProperties:Map[propertyName ,value], lineProperties:Map[propertyName ,value] }} propertyMap
193
+ */
194
+ updateNodesProperties(chainKey, nodesAndPropertyMap, { textWriterIDs = [] } = {}) {
195
+ this._chainListMap.updateNodesProperties(chainKey, nodesAndPropertyMap)
196
+ this._reconstructChains([chainKey]);
197
+ this._updateTexts([chainKey], textWriterIDs);
198
+ this.globe.DrawRender();
199
+ }
200
+
201
+ /**
202
+ *
203
+ * @param {*} chainKey
204
+ * @param {Map<propertyName ,value} propertyMap
205
+ */
206
+ updateChainProperties(chainKey, propertyMap, { textWriterIDs = [] } = {}) {
207
+ this._chainListMap.updateChainProperties(chainKey, propertyMap);
208
+ this._reconstructChains([chainKey]);
209
+ if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
210
+ }
211
+
212
+ // ---- insertBulk family
213
+ /**
214
+ *
215
+ * @param {Array<chain>} data
216
+ * @typedef chain
217
+ * @property {string} chainKey
218
+ * @property {StyleProperties} chainProperties
219
+
220
+ * } chainProperties
221
+ *
222
+ * @typedef {Object} node
223
+ * @property {string} key
224
+ * @property {number} long
225
+ * @property {number} lat
226
+ * @property {StyleProperties} circleProperties
227
+ */
228
+ insertBulk(data, { textWriterIDs = [] } = []) {
229
+ // first insert everything to implicit structure,
230
+ // then iterate over data again to update text
231
+ // let _reconstractChainBufferData method interact with data and bufferOrchestrator.
232
+ const chainKeysToConstruct = [];
233
+
234
+ for (const { chainKey, chainProperties, nodes } of data) {
235
+ this._chainListMap.setChain(chainKey, nodes);
236
+ this._chainListMap.setChainProperties(chainKey, chainProperties);
237
+ chainKeysToConstruct.push(chainKey);
238
+ }
239
+ this._reconstructChains(chainKeysToConstruct);
240
+ if (textWriterIDs) this._updateTexts(chainKeysToConstruct, textWriterIDs);
241
+ this.globe.DrawRender();
242
+ }
243
+
244
+ /**
245
+ *
246
+ * @param {{key, long, lat}} node
247
+ * @param {*} chainKey
248
+ * @param {*} theNodeKeyFront | node key of the next node, null places to the last
249
+ */
250
+ addNode(node, chainKey, { theNodeKeyFront = null, textWriterIDs = [] } = {}) {
251
+ // TODO: if before object is null update the last two elements of the chain only.
252
+ this._chainListMap.addNode(node, chainKey, theNodeKeyFront);
253
+ if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
254
+ this._reconstructChains([chainKey]);
255
+ this.globe.DrawRender();
256
+
257
+ }
258
+
259
+
260
+
261
+ updateNodeCoordinates(node, chainKey, { textWriterIDs = [] } = {}) {
262
+ this._chainListMap.updateCoordsinatesOfNode(node, chainKey);
263
+ if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
264
+ this._reconstructChains([chainKey]);
265
+ this.globe.DrawRender();
266
+ }
267
+
268
+
269
+
270
+ setOpacity(opacity) {
271
+ if (typeof opacity !== 'number') throw new Error("opacity must be a number");
272
+ if (opacity < 0 || 1 < opacity) throw new Error("opacity must be between 0-1");
273
+ this._textContextWriterInjectionMap.forEach((writer) => writer.setOpacity(opacity));
274
+ this._opacity = opacity;
275
+ this.globe.DrawRender();
276
+ }
277
+
278
+
279
+
280
+ getChain(chainKey) {
281
+ this._chainListMap.getChain(chainKey);
282
+ }
283
+
284
+ /**
285
+ *
286
+ * @param {*} chainKeys
287
+ */
288
+ deleteChains(chainKeys) {
289
+ const bufferKeys = [];
290
+ for (const chainKey of chainKeys) {
291
+ bufferKeys.push(...this._chainListMap.deleteChainAndReturnChainKeys(chainKey));
292
+ }
293
+ this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
294
+ this._updateTexts(chainKeys, this._textContextWriterInjectionMap.keys());
295
+ this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
296
+ this.globe.DrawRender();
297
+ }
298
+
299
+
300
+ /**
301
+ *
302
+ * @param {Array<{chainKey, nodeKeys:[]} keysAndNodes
303
+ */
304
+ deleteNodes(keysAndNodes, { textWriterIDs = [] } = {}) {
305
+ const bufferKeys = [];
306
+ const chainKeysToReconstuct = [];
307
+ keysAndNodes.forEach(({ chainKey, nodeKeys }) => {
308
+ bufferKeys.push(...this._chainListMap.deleteNodesBelongToAChain(chainKey, nodeKeys));
309
+ chainKeysToReconstuct.push(chainKey);
310
+ });
311
+ this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
312
+ this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
313
+ this._reconstructChains(chainKeysToReconstuct);
314
+ this._updateTexts(chainKeysToReconstuct, textWriterIDs);
315
+ this.globe.DrawRender();
316
+
317
+ }
318
+
319
+
320
+ updateText(textWriterIDs) {
321
+ const chainKeyIterator = this._chainListMap.getAllChainKeysIterator();
322
+ this._updateTexts(chainKeyIterator, textWriterIDs);
323
+ }
324
+
325
+
326
+ // implicit
327
+
328
+ _updateTexts(chainKeys, textWriterIDs) {
329
+ if (textWriterIDs.length === 0) return;
330
+ const textWriters = textWriterGetOrThrow(this._textContextWriterInjectionMap, textWriterIDs)
331
+ chainKeys.forEach((chainKey) => {
332
+ this._chainListMap.textUpdate(chainKey, textWriters, this._textDataPreAdaptor);
333
+ })
334
+ }
335
+
336
+
337
+ _reconstructChains(chainKeys) {
338
+ const { globe } = this;
339
+ // this.lineVao = this.lineProgram.createVAO(
340
+ // ...['centerCoords', 'targetCoords', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
341
+ // this.circleVao = this.circleProgram.createVAO(
342
+ // ...["centerCoords", "bigRadius", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
343
+ // }
344
+
345
+ const radiusM = radiusMethod(globe);
346
+ const callback = (v, i, array, chainProperties) => {
347
+ if (i == array.length - 1) return null;
348
+ return {
349
+ chainProperties: chainProperties,
350
+ bigRadius: radiusM(v, i, array),
351
+ targetLong: array[i + 1].long,
352
+ targetLat: array[i + 1].lat,
353
+ long: v.long,
354
+ lat: v.lat,
355
+ lineProperties: v.lineProperties,
356
+ circleProperties: v.circleProperties,
357
+ key: v.__identity__
358
+ }
359
+ }
360
+ const bulkData = [];
361
+ chainKeys.forEach((k) => {
362
+ this._chainListMap.calculateBufferPropertiesChain(k, callback, bulkData);
363
+ })
364
+
365
+ this._insertBulk(bulkData);
366
+ }
367
+
368
+
369
+ _insertBulk(bulkData) {
370
+ this.bufferOrchestrator.insertBulk(bulkData, this.bufferManagersCompMap);
371
+ this.globe.DrawRender();
372
+ }
373
+
374
+
375
+ // GLOBE API
376
+ //TODO:
377
+ free() {
378
+ if (this.isFreed) return;
379
+ this.bufferManagersCompMap.forEach(({ bufferManager }) => {
380
+ bufferManager.free();
381
+ })
382
+ LineOnGlobeCache.release(this.globe);
383
+ CircleCache.release(this.globe);
384
+ this.lineProgram = null;
385
+ this.circleProgram = null;
386
+ this.isFreed = true;
387
+ }
388
+
389
+ draw3D() {
390
+ const { gl, globe } = this;
391
+ gl.disable(gl.DEPTH_TEST);
392
+ this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
393
+ if (this._drawCircleOn) this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
394
+ this._textContextWriterInjectionMap.forEach((writer) => writer.draw());
395
+ gl.enable(gl.DEPTH_TEST);
396
+ this.lineToTheOriginProgram.draw(this.toOriginVao, this.bufferOrchestrator.length, this._opacity);
397
+ }
398
+ }
399
+
400
+
401
+
402
+ const radiusMethod = (globe) => (v, i, array) => {
403
+ return globe.Math.GetDist3D(v.long, v.lat, array[i + 1].long, array[i + 1].lat)
404
+ }
405
+
406
+ const textWriterGetOrThrow = mapGetOrThrow("textWriterIds is invalid")
@@ -179,7 +179,10 @@ export class PixelPaddingCompassPlugin {
179
179
  }
180
180
 
181
181
  free() {
182
-
182
+ this.compassMap.free();
183
+ this.bufferManagersCompMap.forEach(v => {
184
+ v.bufferManager.free();
185
+ })
183
186
 
184
187
  }
185
188
  }
@@ -203,6 +206,13 @@ class CompassMap {
203
206
  this.propertyMemory.delete(key);
204
207
  }
205
208
 
209
+ free() {
210
+ this.coordsMemory.clear();
211
+ this.propertyMemory.clear();
212
+ this.coordsMemory = null;
213
+ this.propertyMemory = null;
214
+ }
215
+
206
216
  query(globe, writer) {
207
217
  const { coordsMemory, propertyMemory } = this;
208
218
  const defaultProperties = this.parent.defaultProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.14",
3
+ "version": "0.6.15",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -0,0 +1,219 @@
1
+ import { CameraUniformBlockString, CameraUniformBlockTotem } from "../totems";
2
+ import { pointsOnSphereBetween, POLE, R_3D, mercatorXYToGLPosition, cartesian3DToGLPosition } from "../../util/shaderfunctions/geometrytransformations";
3
+ import { createProgram } from "../../util";
4
+ import { noRegisterGlobeProgramCache, globeProgramCache } from "../programcache";
5
+ import BufferOffsetManger from "../../util/account/bufferoffsetmanager";
6
+ import { programCache } from "../rings/distancering/circleflatprogram";
7
+
8
+ const GLOBE_MIDPOINT_COUNT = 100;
9
+ const ITEM_SIZE = 9;
10
+
11
+ const vertexShader = `#version 300 es
12
+ precision highp float;
13
+ ${R_3D}
14
+ ${CameraUniformBlockString}
15
+ ${pointsOnSphereBetween}
16
+ ${mercatorXYToGLPosition}
17
+ ${cartesian3DToGLPosition}
18
+
19
+ in vec2 start_position;
20
+ in vec3 start_poisition3d;
21
+ in vec2 end_position;
22
+ in vec3 end_position3;
23
+ in float dash_ratio;
24
+ in vec4 color;
25
+ in float dash_opacity;
26
+ out vec4 v_color;
27
+ out vec2 v_limp;
28
+ out float interpolation;
29
+ out float v_dash_ratio;
30
+ out float v_dash_opacity;
31
+
32
+
33
+ void main() {
34
+ vec2 longLat;
35
+ if (is3D) {
36
+ interpolation = float(gl_VertexID) / ${GLOBE_MIDPOINT_COUNT - 1}.0;
37
+ vec3 cartesian = pointsOnSphereBetween(start_poisition3d, end_position3, interpolation) * R_3D;
38
+ gl_Position = cartesian3DToGLPosition(cartesian);
39
+ v_limp = vec2(0.0, 0.0);
40
+ } else {
41
+ interpolation = float(gl_VertexID);
42
+ if (gl_VertexID % 2 == 0) {
43
+ longLat = start_position;
44
+ } else {
45
+ longLat = end_position;
46
+ }
47
+ v_limp = longLat;
48
+ gl_Position = mercatorXYToGLPosition(longLat);
49
+ }
50
+ // if ( gl_VertexID % 2 == 0) {v_color = color;}
51
+ // else {v_color = vec4(0.0, 0.0, 0.0, 0.0);}
52
+ v_color = color;
53
+ v_dash_ratio = dash_ratio;
54
+ v_dash_opacity = dash_opacity;
55
+ }
56
+ `;
57
+
58
+ const fragmentShader = `#version 300 es
59
+ ${POLE}
60
+ precision highp float;
61
+ uniform float opacity;
62
+ in vec4 v_color;
63
+ out vec4 color;
64
+ in float interpolation;
65
+ in float v_dash_ratio;
66
+ in vec2 v_limp;
67
+ in float v_dash_opacity;
68
+ void main() {
69
+ if (v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE) { discard; }
70
+ color = v_color;
71
+ color.a *= opacity;
72
+ if ( v_dash_ratio >= 1.0 ) { return; }
73
+ if (interpolation > 0.95) { return; }
74
+ if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5) { color.a *= v_dash_opacity; }
75
+
76
+ }
77
+ `;
78
+
79
+
80
+ class Logic {
81
+
82
+ constructor(globe) {
83
+ this.globe = globe;
84
+ this.gl = globe.gl;
85
+ this.program = createProgram(this.gl, vertexShader, fragmentShader);
86
+ this._lastOpacity = 1.0;
87
+ const { gl, program } = this;
88
+ {
89
+ // assign attribute locations
90
+ gl.bindAttribLocation(program, 0, "start_position");
91
+ gl.bindAttribLocation(program, 1, "start_position3d");
92
+ gl.bindAttribLocation(program, 2, "end_position");
93
+ gl.bindAttribLocation(program, 3, "end_position3d");
94
+ gl.bindAttribLocation(program, 4, "dash_ratio");
95
+ gl.bindAttribLocation(program, 5, "color");
96
+ gl.bindAttribLocation(program, 6, "dash_opacity");
97
+ }
98
+
99
+ {
100
+ this._opacityLocation = gl.getUniformLocation(program, "opacity");
101
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
102
+ gl.useProgram(program);
103
+ gl.uniform1f(this._opacityLocation, this._lastOpacity);
104
+ gl.useProgram(currentProgram);
105
+
106
+ }
107
+
108
+ this.cameraBlockBindingPoint = 0;
109
+ const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
110
+ this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
111
+ gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
112
+
113
+
114
+ }
115
+
116
+
117
+ draw(vao, length, opacity) {
118
+ const { gl, program, globe, cameraBlockTotem, cameraBlockBindingPoint } = this;
119
+ gl.useProgram(program);
120
+ cameraBlockTotem.bind(cameraBlockBindingPoint);
121
+ gl.bindVertexArray(vao);
122
+ if (opacity !== this._lastOpacity) {
123
+ gl.uniform1f(this._opacityLocation, opacity);
124
+ this._lastOpacity = opacity;
125
+ }
126
+ const drawCount = globe.api_GetCurrentGeometry() === 0 ? GLOBE_MIDPOINT_COUNT : 2;
127
+ // gl.disable(gl.DEPTH_TEST);
128
+ gl.drawArraysInstanced(gl.LINE_STRIP, 0, drawCount, length);
129
+ gl.bindVertexArray(null);
130
+ cameraBlockTotem.unbind(cameraBlockBindingPoint);
131
+ // gl.enable(gl.DEPTH_TEST);
132
+ }
133
+
134
+ //
135
+ createVAO(
136
+ startPotisionBufferObj, startPotision3DBufferObj,
137
+ endPositionBufferObj, endPosition3DBufferObj,
138
+ dashRatioBufferObj,
139
+ dashOpacityBufferObj,
140
+ colorBufferObj) {
141
+ const { gl } = this;
142
+ const vao = gl.createVertexArray();
143
+ gl.bindVertexArray(vao);
144
+ {
145
+ const { buffer, stride = 0, offset = 0 } = startPotisionBufferObj;
146
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
147
+ gl.enableVertexAttribArray(0);
148
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, stride, offset);
149
+ gl.vertexAttribDivisor(0, 1);
150
+ }
151
+ {
152
+ const { buffer, stride = 0, offset = 0 } = startPotision3DBufferObj;
153
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
154
+ gl.enableVertexAttribArray(1);
155
+ gl.vertexAttribPointer(1, 3, gl.FLOAT, false, stride, offset);
156
+ gl.vertexAttribDivisor(1, 1);
157
+ }
158
+ {
159
+
160
+ const { buffer, stride = 0, offset = 0 } = endPositionBufferObj;
161
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
162
+ gl.enableVertexAttribArray(2);
163
+ gl.vertexAttribPointer(2, 2, gl.FLOAT, false, stride, offset);
164
+ gl.vertexAttribDivisor(2, 1);
165
+ }
166
+ {
167
+
168
+ const { buffer, stride = 0, offset = 0 } = endPosition3DBufferObj;
169
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
170
+ gl.enableVertexAttribArray(3);
171
+ gl.vertexAttribPointer(3, 3, gl.FLOAT, false, stride, offset);
172
+ gl.vertexAttribDivisor(3, 1);
173
+ }
174
+ {
175
+ const { buffer, stride = 0, offset = 0 } = dashRatioBufferObj;
176
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
177
+ gl.enableVertexAttribArray(4);
178
+ gl.vertexAttribPointer(4, 1, gl.FLOAT, false, stride, offset);
179
+ gl.vertexAttribDivisor(4, 1);
180
+ }
181
+
182
+ {
183
+ const { buffer, stride = 0, offset = 0 } = colorBufferObj;
184
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
185
+ gl.enableVertexAttribArray(5);
186
+ gl.vertexAttribPointer(5, 4, gl.FLOAT, false, stride, offset);
187
+ gl.vertexAttribDivisor(5, 1);
188
+ }
189
+
190
+ {
191
+ const { buffer, stride = 0, offset = 0 } = dashOpacityBufferObj;
192
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
193
+ gl.enableVertexAttribArray(6);
194
+ gl.vertexAttribPointer(6, 1, gl.FLOAT, false, stride, offset);
195
+ gl.vertexAttribDivisor(6, 1);
196
+ }
197
+
198
+ gl.bindVertexArray(null);
199
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
200
+ return vao;
201
+
202
+ }
203
+
204
+
205
+ free() {
206
+ if (this.isFreed) return;
207
+ programCache.releaseProgram(this.globe, CameraUniformBlockTotem);
208
+ this.gl.deleteProgram(this.program);
209
+ this.isFreed = true;
210
+ }
211
+ }
212
+
213
+
214
+
215
+ export const LineOnGlobeCache = Object.freeze({
216
+ get: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
217
+ release: (globe) => { return noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
218
+ });
219
+
@@ -53,11 +53,8 @@ vec2 adjust_pos(vec2 pos) {
53
53
  void main(){
54
54
  vec3 c = coord_opacity();
55
55
  gl_Position = vec4( adjust_pos(c.xy), 0.0, 1.0);
56
- // gl_Position = vec4( 0.0, 0.0, 0.0, 1.0);
57
56
  v_rgba = rgba;
58
57
  v_rgba.a *= plugin_opacity;
59
- // float opacity = (float((gl_VertexID + 179) % 720 ) / (${vertexCount}.0)) / 1.5 + 0.5;
60
- v_rgba.a *= c.z;
61
58
  gl_PointSize = 10.0;
62
59
  }
63
60
  `
@@ -289,4 +289,24 @@ float realDistanceOnSphereR1(vec2 longLat1, vec2 longLat2) {
289
289
  float c = 2.0 * atan(sqrt(a), sqrt(1.0 - a));
290
290
  return c;
291
291
  }
292
- `;
292
+ `;
293
+
294
+ const pointsOnSphereBetween = `vec3 pointsOnSphereBetween(vec3 a, vec3 b, float ratio) {
295
+ // Normalize the input points to ensure they are on the unit sphere
296
+ a = normalize(a);
297
+ b = normalize(b);
298
+
299
+ // Compute the angle between the points
300
+ float theta = acos(dot(a, b));
301
+
302
+ // Compute the interpolated point using spherical linear interpolation (slerp)
303
+ vec3 result = (sin((1.0 - ratio) * theta) * a + sin(ratio * theta) * b) / sin(theta);
304
+
305
+ // Return the normalized result to ensure it lies on the sphere
306
+ return normalize(result);
307
+ }`
308
+
309
+ export {
310
+ pointsOnSphereBetween
311
+
312
+ }