@pirireis/webglobeplugins 0.6.14 → 0.6.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/circle-line-chain/plugin.js +18 -10
- package/circle-line-chain/plugin_old.js +398 -0
- package/compass-rose/compass-rose-padding-flat.js +11 -1
- package/package.json +1 -1
- package/programs/line-on-globe/circle-accurate.js +195 -0
- package/programs/line-on-globe/naive-accurate.js +219 -0
- package/programs/two-d/pixel-padding-for-compass.js +0 -3
- package/util/shaderfunctions/geometrytransformations.js +68 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
|
|
2
|
-
import { CircleCache } from '../programs/line-on-globe/circle';
|
|
1
|
+
import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
|
|
2
|
+
import { CircleCache } from '../programs/line-on-globe/circle-accurate';
|
|
3
3
|
import { LineToTheOriginCache } from "../programs/line-on-globe/to-the-origin"
|
|
4
4
|
import { BufferOrchestrator, BufferManager } from "../util/account";
|
|
5
5
|
import { ChainListMap } from "./chain-list-map";
|
|
@@ -84,13 +84,21 @@ export class CircleLineChainPlugin {
|
|
|
84
84
|
const initialCapacity = this.bufferOrchestrator.capacity;
|
|
85
85
|
this.bufferManagersCompMap = new Map(
|
|
86
86
|
[
|
|
87
|
-
["
|
|
87
|
+
["centerCoords2d", {
|
|
88
88
|
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
89
|
-
'adaptor': (item) => new Float32Array(
|
|
89
|
+
'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.long, item.lat)),
|
|
90
90
|
}],
|
|
91
|
-
["
|
|
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", {
|
|
92
96
|
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
93
|
-
'adaptor': (item) => new Float32Array(
|
|
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)),
|
|
94
102
|
}],
|
|
95
103
|
["rgba", {
|
|
96
104
|
'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
|
|
@@ -133,11 +141,11 @@ export class CircleLineChainPlugin {
|
|
|
133
141
|
return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
|
|
134
142
|
};
|
|
135
143
|
this.lineVao = this.lineProgram.createVAO(
|
|
136
|
-
...['
|
|
144
|
+
...['centerCoords2d', 'centerCoords3d', 'targetCoords2d', 'targetCoords3d', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
137
145
|
this.circleVao = this.circleProgram.createVAO(
|
|
138
|
-
...["
|
|
139
|
-
this.toOriginVao = this.lineToTheOriginProgram.createVAO(
|
|
140
|
-
|
|
146
|
+
...["centerCoords2d", "centerCoords3d", "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))));
|
|
141
149
|
}
|
|
142
150
|
|
|
143
151
|
}
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
|
|
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
|
+
["centerCoords", {
|
|
88
|
+
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
89
|
+
'adaptor': (item) => new Float32Array([radian * item.long, radian * item.lat]),
|
|
90
|
+
}],
|
|
91
|
+
["targetCoords", {
|
|
92
|
+
'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
|
93
|
+
'adaptor': (item) => new Float32Array([radian * item.targetLong, radian * item.targetLat])
|
|
94
|
+
}],
|
|
95
|
+
["rgba", {
|
|
96
|
+
'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
|
|
97
|
+
'adaptor': (item) => {
|
|
98
|
+
if (item.lineProperties?.rgba) return new Float32Array(item.lineProperties.rgba);
|
|
99
|
+
return new Float32Array(item.chainProperties.rgba);
|
|
100
|
+
}
|
|
101
|
+
}],
|
|
102
|
+
["bigRadius", {
|
|
103
|
+
'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
|
|
104
|
+
'adaptor': (item) => new Float32Array([item.bigRadius])
|
|
105
|
+
}],
|
|
106
|
+
["dashRatio", {
|
|
107
|
+
'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
|
|
108
|
+
'adaptor': (item) => new Float32Array([item.chainProperties.dashRatio])
|
|
109
|
+
}],
|
|
110
|
+
|
|
111
|
+
["dashOpacity", {
|
|
112
|
+
'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
|
|
113
|
+
'adaptor': (item) => new Float32Array([item.chainProperties.dashOpacity])
|
|
114
|
+
}],
|
|
115
|
+
["circleDashAngle", {
|
|
116
|
+
'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
|
|
117
|
+
'adaptor': (item) => {
|
|
118
|
+
if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
|
|
119
|
+
return new Float32Array([item.chainProperties.circleDashAngle / 360]);
|
|
120
|
+
}
|
|
121
|
+
}],
|
|
122
|
+
["rgbaCircle", {
|
|
123
|
+
"bufferManager": new BufferManager(gl, 4, { bufferType, initialCapacity }),
|
|
124
|
+
"adaptor": (item) => {
|
|
125
|
+
if (item.circleProperties?.rgba) return new Float32Array(item.circleProperties.rgba);
|
|
126
|
+
return new Float32Array(item.chainProperties.rgba);
|
|
127
|
+
}
|
|
128
|
+
}]
|
|
129
|
+
]
|
|
130
|
+
);
|
|
131
|
+
// (startPotisionBufferObj, endPositionBufferObj, dashRatioBufferObj, colorBufferObj)
|
|
132
|
+
const obj = function (bufferManagerComp) {
|
|
133
|
+
return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
|
|
134
|
+
};
|
|
135
|
+
this.lineVao = this.lineProgram.createVAO(
|
|
136
|
+
...['centerCoords', 'targetCoords', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
137
|
+
this.circleVao = this.circleProgram.createVAO(
|
|
138
|
+
...["centerCoords", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
139
|
+
this.toOriginVao = this.lineToTheOriginProgram.createVAO(
|
|
140
|
+
...["targetCoords", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// API
|
|
147
|
+
setDrawCircleOn(bool) {
|
|
148
|
+
if (typeof bool !== 'boolean') throw new Error("setDrawCircleOn parameter must be a boolean");
|
|
149
|
+
this._drawCircleOn = bool;
|
|
150
|
+
this.globe.DrawRender();
|
|
151
|
+
}
|
|
152
|
+
// -- update bulk family
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
155
|
+
* @param {Array<chain>} data
|
|
156
|
+
* @typedef chain
|
|
157
|
+
* @property {string} chainKey
|
|
158
|
+
* @property {Array<node>} nodes
|
|
159
|
+
* @typedef {Object} node
|
|
160
|
+
* @property {string} key
|
|
161
|
+
* @property {number} long
|
|
162
|
+
* @property {number} lat
|
|
163
|
+
*/
|
|
164
|
+
updateCoordinatesBulk(data, { textWriterIDs = [] } = {}) {
|
|
165
|
+
// update implicit data structure
|
|
166
|
+
// find keys to update.. (inserted data and the radius of "from")
|
|
167
|
+
// updateBuffers
|
|
168
|
+
// update text
|
|
169
|
+
const chainKeys = [];
|
|
170
|
+
for (const chain of data) {
|
|
171
|
+
chainKeys.push(chain.chainKey);
|
|
172
|
+
chain.nodes.forEach((node) => {
|
|
173
|
+
this._chainListMap.updateCoordsinatesOfNode(node, chain.chainKey);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
this._reconstructChains(chainKeys);
|
|
177
|
+
this._updateTexts(chainKeys, textWriterIDs);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
* @param {*} chainKey
|
|
184
|
+
* @param {Array<{nodeKey, circleProperties:Map[propertyName ,value], lineProperties:Map[propertyName ,value] }} propertyMap
|
|
185
|
+
*/
|
|
186
|
+
updateNodesProperties(chainKey, nodesAndPropertyMap, { textWriterIDs = [] } = {}) {
|
|
187
|
+
this._chainListMap.updateNodesProperties(chainKey, nodesAndPropertyMap)
|
|
188
|
+
this._reconstructChains([chainKey]);
|
|
189
|
+
this._updateTexts([chainKey], textWriterIDs);
|
|
190
|
+
this.globe.DrawRender();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
*
|
|
195
|
+
* @param {*} chainKey
|
|
196
|
+
* @param {Map<propertyName ,value} propertyMap
|
|
197
|
+
*/
|
|
198
|
+
updateChainProperties(chainKey, propertyMap, { textWriterIDs = [] } = {}) {
|
|
199
|
+
this._chainListMap.updateChainProperties(chainKey, propertyMap);
|
|
200
|
+
this._reconstructChains([chainKey]);
|
|
201
|
+
if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ---- insertBulk family
|
|
205
|
+
/**
|
|
206
|
+
*
|
|
207
|
+
* @param {Array<chain>} data
|
|
208
|
+
* @typedef chain
|
|
209
|
+
* @property {string} chainKey
|
|
210
|
+
* @property {StyleProperties} chainProperties
|
|
211
|
+
|
|
212
|
+
* } chainProperties
|
|
213
|
+
*
|
|
214
|
+
* @typedef {Object} node
|
|
215
|
+
* @property {string} key
|
|
216
|
+
* @property {number} long
|
|
217
|
+
* @property {number} lat
|
|
218
|
+
* @property {StyleProperties} circleProperties
|
|
219
|
+
*/
|
|
220
|
+
insertBulk(data, { textWriterIDs = [] } = []) {
|
|
221
|
+
// first insert everything to implicit structure,
|
|
222
|
+
// then iterate over data again to update text
|
|
223
|
+
// let _reconstractChainBufferData method interact with data and bufferOrchestrator.
|
|
224
|
+
const chainKeysToConstruct = [];
|
|
225
|
+
|
|
226
|
+
for (const { chainKey, chainProperties, nodes } of data) {
|
|
227
|
+
this._chainListMap.setChain(chainKey, nodes);
|
|
228
|
+
this._chainListMap.setChainProperties(chainKey, chainProperties);
|
|
229
|
+
chainKeysToConstruct.push(chainKey);
|
|
230
|
+
}
|
|
231
|
+
this._reconstructChains(chainKeysToConstruct);
|
|
232
|
+
if (textWriterIDs) this._updateTexts(chainKeysToConstruct, textWriterIDs);
|
|
233
|
+
this.globe.DrawRender();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
*
|
|
238
|
+
* @param {{key, long, lat}} node
|
|
239
|
+
* @param {*} chainKey
|
|
240
|
+
* @param {*} theNodeKeyFront | node key of the next node, null places to the last
|
|
241
|
+
*/
|
|
242
|
+
addNode(node, chainKey, { theNodeKeyFront = null, textWriterIDs = [] } = {}) {
|
|
243
|
+
// TODO: if before object is null update the last two elements of the chain only.
|
|
244
|
+
this._chainListMap.addNode(node, chainKey, theNodeKeyFront);
|
|
245
|
+
if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
|
|
246
|
+
this._reconstructChains([chainKey]);
|
|
247
|
+
this.globe.DrawRender();
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
updateNodeCoordinates(node, chainKey, { textWriterIDs = [] } = {}) {
|
|
254
|
+
this._chainListMap.updateCoordsinatesOfNode(node, chainKey);
|
|
255
|
+
if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
|
|
256
|
+
this._reconstructChains([chainKey]);
|
|
257
|
+
this.globe.DrawRender();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
setOpacity(opacity) {
|
|
263
|
+
if (typeof opacity !== 'number') throw new Error("opacity must be a number");
|
|
264
|
+
if (opacity < 0 || 1 < opacity) throw new Error("opacity must be between 0-1");
|
|
265
|
+
this._textContextWriterInjectionMap.forEach((writer) => writer.setOpacity(opacity));
|
|
266
|
+
this._opacity = opacity;
|
|
267
|
+
this.globe.DrawRender();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
getChain(chainKey) {
|
|
273
|
+
this._chainListMap.getChain(chainKey);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
* @param {*} chainKeys
|
|
279
|
+
*/
|
|
280
|
+
deleteChains(chainKeys) {
|
|
281
|
+
const bufferKeys = [];
|
|
282
|
+
for (const chainKey of chainKeys) {
|
|
283
|
+
bufferKeys.push(...this._chainListMap.deleteChainAndReturnChainKeys(chainKey));
|
|
284
|
+
}
|
|
285
|
+
this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
|
|
286
|
+
this._updateTexts(chainKeys, this._textContextWriterInjectionMap.keys());
|
|
287
|
+
this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
|
|
288
|
+
this.globe.DrawRender();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
*
|
|
294
|
+
* @param {Array<{chainKey, nodeKeys:[]} keysAndNodes
|
|
295
|
+
*/
|
|
296
|
+
deleteNodes(keysAndNodes, { textWriterIDs = [] } = {}) {
|
|
297
|
+
const bufferKeys = [];
|
|
298
|
+
const chainKeysToReconstuct = [];
|
|
299
|
+
keysAndNodes.forEach(({ chainKey, nodeKeys }) => {
|
|
300
|
+
bufferKeys.push(...this._chainListMap.deleteNodesBelongToAChain(chainKey, nodeKeys));
|
|
301
|
+
chainKeysToReconstuct.push(chainKey);
|
|
302
|
+
});
|
|
303
|
+
this._textContextWriterInjectionMap.forEach((writer) => writer.deleteTextBulk(bufferKeys));
|
|
304
|
+
this.bufferOrchestrator.deleteBulk(bufferKeys, this.bufferManagersCompMap);
|
|
305
|
+
this._reconstructChains(chainKeysToReconstuct);
|
|
306
|
+
this._updateTexts(chainKeysToReconstuct, textWriterIDs);
|
|
307
|
+
this.globe.DrawRender();
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
updateText(textWriterIDs) {
|
|
313
|
+
const chainKeyIterator = this._chainListMap.getAllChainKeysIterator();
|
|
314
|
+
this._updateTexts(chainKeyIterator, textWriterIDs);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
// implicit
|
|
319
|
+
|
|
320
|
+
_updateTexts(chainKeys, textWriterIDs) {
|
|
321
|
+
if (textWriterIDs.length === 0) return;
|
|
322
|
+
const textWriters = textWriterGetOrThrow(this._textContextWriterInjectionMap, textWriterIDs)
|
|
323
|
+
chainKeys.forEach((chainKey) => {
|
|
324
|
+
this._chainListMap.textUpdate(chainKey, textWriters, this._textDataPreAdaptor);
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
_reconstructChains(chainKeys) {
|
|
330
|
+
const { globe } = this;
|
|
331
|
+
// this.lineVao = this.lineProgram.createVAO(
|
|
332
|
+
// ...['centerCoords', 'targetCoords', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
333
|
+
// this.circleVao = this.circleProgram.createVAO(
|
|
334
|
+
// ...["centerCoords", "bigRadius", "rgba", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
335
|
+
// }
|
|
336
|
+
|
|
337
|
+
const radiusM = radiusMethod(globe);
|
|
338
|
+
const callback = (v, i, array, chainProperties) => {
|
|
339
|
+
if (i == array.length - 1) return null;
|
|
340
|
+
return {
|
|
341
|
+
chainProperties: chainProperties,
|
|
342
|
+
bigRadius: radiusM(v, i, array),
|
|
343
|
+
targetLong: array[i + 1].long,
|
|
344
|
+
targetLat: array[i + 1].lat,
|
|
345
|
+
long: v.long,
|
|
346
|
+
lat: v.lat,
|
|
347
|
+
lineProperties: v.lineProperties,
|
|
348
|
+
circleProperties: v.circleProperties,
|
|
349
|
+
key: v.__identity__
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const bulkData = [];
|
|
353
|
+
chainKeys.forEach((k) => {
|
|
354
|
+
this._chainListMap.calculateBufferPropertiesChain(k, callback, bulkData);
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
this._insertBulk(bulkData);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
_insertBulk(bulkData) {
|
|
362
|
+
this.bufferOrchestrator.insertBulk(bulkData, this.bufferManagersCompMap);
|
|
363
|
+
this.globe.DrawRender();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
// GLOBE API
|
|
368
|
+
//TODO:
|
|
369
|
+
free() {
|
|
370
|
+
if (this.isFreed) return;
|
|
371
|
+
this.bufferManagersCompMap.forEach(({ bufferManager }) => {
|
|
372
|
+
bufferManager.free();
|
|
373
|
+
})
|
|
374
|
+
LineOnGlobeCache.release(this.globe);
|
|
375
|
+
CircleCache.release(this.globe);
|
|
376
|
+
this.lineProgram = null;
|
|
377
|
+
this.circleProgram = null;
|
|
378
|
+
this.isFreed = true;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
draw3D() {
|
|
382
|
+
const { gl, globe } = this;
|
|
383
|
+
gl.disable(gl.DEPTH_TEST);
|
|
384
|
+
this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
|
|
385
|
+
if (this._drawCircleOn) this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
|
|
386
|
+
this._textContextWriterInjectionMap.forEach((writer) => writer.draw());
|
|
387
|
+
gl.enable(gl.DEPTH_TEST);
|
|
388
|
+
this.lineToTheOriginProgram.draw(this.toOriginVao, this.bufferOrchestrator.length, this._opacity);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
const radiusMethod = (globe) => (v, i, array) => {
|
|
395
|
+
return globe.Math.GetDist3D(v.long, v.lat, array[i + 1].long, array[i + 1].lat)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
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
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { createProgram } from "../../util/webglobjectbuilders";
|
|
2
|
+
import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/camerauniformblock";
|
|
3
|
+
import { noRegisterGlobeProgramCache } from "../programcache";
|
|
4
|
+
import { vaoAttributeLoader } from "../../util/account/util";
|
|
5
|
+
import {
|
|
6
|
+
longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1,
|
|
7
|
+
circleLimpFromLongLatRadCenterCartesian3D_accurate,
|
|
8
|
+
circleLimpFromLongLatRadCenterMercatorCompass_accurate,
|
|
9
|
+
circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
|
|
10
|
+
POLE
|
|
11
|
+
} from "../../util/shaderfunctions/geometrytransformations";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* TODO:
|
|
16
|
+
* 1. integrate geometry functions for radius angle and center
|
|
17
|
+
* 2. integrate attributes
|
|
18
|
+
*
|
|
19
|
+
* TODO:
|
|
20
|
+
* center_position is too small or doenst loaded as expected.
|
|
21
|
+
*/
|
|
22
|
+
const EDGE_COUNT_ON_SPHERE = 360;
|
|
23
|
+
|
|
24
|
+
const vertexShaderSource = `#version 300 es
|
|
25
|
+
precision highp float;
|
|
26
|
+
${CameraUniformBlockString}
|
|
27
|
+
${longLatRadToMercator}
|
|
28
|
+
${longLatRadToCartesian3D}
|
|
29
|
+
${cartesian3DToGLPosition}
|
|
30
|
+
${mercatorXYToGLPosition}
|
|
31
|
+
${realDistanceOnSphereR1}
|
|
32
|
+
${circleLimpFromLongLatRadCenterCartesian3D_accurate}
|
|
33
|
+
${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
|
|
34
|
+
${circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate}
|
|
35
|
+
|
|
36
|
+
uniform float edge_count;
|
|
37
|
+
|
|
38
|
+
in vec2 center_position;
|
|
39
|
+
in vec3 center_position3d;
|
|
40
|
+
in float radius;
|
|
41
|
+
in vec4 color;
|
|
42
|
+
in float dash_ratio;
|
|
43
|
+
in float dash_opacity;
|
|
44
|
+
|
|
45
|
+
out float interpolation;
|
|
46
|
+
out vec4 v_color;
|
|
47
|
+
out float v_dash_ratio;
|
|
48
|
+
out float v_dash_opacity;
|
|
49
|
+
out vec2 v_limp;
|
|
50
|
+
void main() {
|
|
51
|
+
interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
|
|
52
|
+
float angle = PI * 2.0 * interpolation;
|
|
53
|
+
if ( is3D ) {
|
|
54
|
+
|
|
55
|
+
vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(center_position3d, radius, angle);
|
|
56
|
+
|
|
57
|
+
gl_Position = cartesian3DToGLPosition(position);
|
|
58
|
+
v_limp = vec2(0.0, 0.0);
|
|
59
|
+
} else {
|
|
60
|
+
vec2 position;
|
|
61
|
+
position = circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate( center_position, radius, angle);
|
|
62
|
+
v_limp = position;
|
|
63
|
+
gl_Position = mercatorXYToGLPosition( position);
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
v_dash_ratio = dash_ratio;
|
|
67
|
+
v_dash_opacity = dash_opacity;
|
|
68
|
+
v_color = color;
|
|
69
|
+
|
|
70
|
+
}`
|
|
71
|
+
|
|
72
|
+
const fragmentShaderSource = `#version 300 es
|
|
73
|
+
${POLE}
|
|
74
|
+
precision highp float;
|
|
75
|
+
uniform float opacity;
|
|
76
|
+
in vec4 v_color;
|
|
77
|
+
in float v_dash_ratio;
|
|
78
|
+
in float v_dash_opacity;
|
|
79
|
+
in float interpolation;
|
|
80
|
+
in vec2 v_limp;
|
|
81
|
+
out vec4 color;
|
|
82
|
+
void main() {
|
|
83
|
+
if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ color = vec4(0.0,0.0,0.0,0.0); return; }
|
|
84
|
+
color = v_color;
|
|
85
|
+
color.a *= opacity;
|
|
86
|
+
if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
|
|
87
|
+
if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
|
|
88
|
+
color.a *= v_dash_opacity;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class Logic {
|
|
96
|
+
|
|
97
|
+
constructor(globe) {
|
|
98
|
+
this.globe = globe;
|
|
99
|
+
this.gl = globe.gl;
|
|
100
|
+
this._lastOpacity = 1.0;
|
|
101
|
+
|
|
102
|
+
this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
|
|
103
|
+
|
|
104
|
+
const { gl, program } = this;
|
|
105
|
+
this.program.uniforms = {
|
|
106
|
+
opacity: gl.getUniformLocation(program, "opacity")
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
{ // initial uniform values
|
|
110
|
+
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
111
|
+
gl.useProgram(program);
|
|
112
|
+
gl.uniform1f(program.uniforms.opacity, 1.0);
|
|
113
|
+
gl.useProgram(currentProgram);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
{ // assign attribute locations
|
|
117
|
+
gl.bindAttribLocation(program, 0, "center_position");
|
|
118
|
+
gl.bindAttribLocation(program, 1, "center_position3d");
|
|
119
|
+
gl.bindAttribLocation(program, 2, "radius");
|
|
120
|
+
gl.bindAttribLocation(program, 3, "color");
|
|
121
|
+
gl.bindAttribLocation(program, 4, "dash_ratio");
|
|
122
|
+
gl.bindAttribLocation(program, 5, "dash_opacity");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.cameraBindingPoint = 0;
|
|
126
|
+
this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
|
|
127
|
+
const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
128
|
+
gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
createVAO(centerObj, center3dObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
|
|
132
|
+
const { gl } = this;
|
|
133
|
+
const vao = gl.createVertexArray();
|
|
134
|
+
const divisor = 1;
|
|
135
|
+
gl.bindVertexArray(vao);
|
|
136
|
+
{ // make this a function end import from account module.
|
|
137
|
+
const { buffer, stride = 0, offset = 0 } = centerObj;
|
|
138
|
+
vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, divisor);
|
|
139
|
+
}
|
|
140
|
+
{ // make this a function end import from account module.
|
|
141
|
+
const { buffer, stride = 0, offset = 0 } = center3dObj;
|
|
142
|
+
vaoAttributeLoader(gl, buffer, 1, 3, stride, offset, divisor);
|
|
143
|
+
}
|
|
144
|
+
{
|
|
145
|
+
const { buffer, stride = 0, offset = 0 } = radiusObj;
|
|
146
|
+
vaoAttributeLoader(gl, buffer, 2, 1, stride, offset, divisor);
|
|
147
|
+
}
|
|
148
|
+
{
|
|
149
|
+
const { buffer, stride = 0, offset = 0 } = colorObj;
|
|
150
|
+
vaoAttributeLoader(gl, buffer, 3, 4, stride, offset, divisor);
|
|
151
|
+
}
|
|
152
|
+
{
|
|
153
|
+
const { buffer, stride = 0, offset = 0 } = dashRatioObj;
|
|
154
|
+
vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
|
|
155
|
+
}
|
|
156
|
+
{
|
|
157
|
+
const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
|
|
158
|
+
vaoAttributeLoader(gl, buffer, 5, 1, stride, offset, divisor);
|
|
159
|
+
}
|
|
160
|
+
gl.bindVertexArray(null);
|
|
161
|
+
gl.bindVertexArray(null);
|
|
162
|
+
return vao;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
draw(vao, length, opacity) {
|
|
166
|
+
const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
|
|
167
|
+
gl.useProgram(program);
|
|
168
|
+
|
|
169
|
+
if (this._lastOpacity !== opacity) {
|
|
170
|
+
gl.uniform1f(program.uniforms.opacity, opacity);
|
|
171
|
+
this._lastOpacity = opacity;
|
|
172
|
+
}
|
|
173
|
+
gl.bindVertexArray(vao);
|
|
174
|
+
cameraBlockTotem.bind(cameraBindingPoint);
|
|
175
|
+
gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
|
|
176
|
+
cameraBlockTotem.unbind(cameraBindingPoint);
|
|
177
|
+
gl.bindVertexArray(null);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
free() {
|
|
183
|
+
if (this.isFreed) return;
|
|
184
|
+
CameraUniformBlockTotemCache.release(this.globe);
|
|
185
|
+
this.gl.deleteProgram(this.program);
|
|
186
|
+
this.isFreed = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
export const CircleCache = Object.freeze({
|
|
193
|
+
get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
|
|
194
|
+
release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
|
|
195
|
+
});
|
|
@@ -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
|
`
|
|
@@ -118,6 +118,8 @@ vec3 circleLimpFromLongLatRadCenterCartesian3D( vec2 center, float radius, float
|
|
|
118
118
|
}
|
|
119
119
|
`;
|
|
120
120
|
|
|
121
|
+
|
|
122
|
+
|
|
121
123
|
// TODO: Make it precise. Y axis is not correct.
|
|
122
124
|
|
|
123
125
|
export const circleLimpFromLongLatRadCenterMercatorRealDistanceNew = PI + `
|
|
@@ -289,4 +291,69 @@ float realDistanceOnSphereR1(vec2 longLat1, vec2 longLat2) {
|
|
|
289
291
|
float c = 2.0 * atan(sqrt(a), sqrt(1.0 - a));
|
|
290
292
|
return c;
|
|
291
293
|
}
|
|
292
|
-
`;
|
|
294
|
+
`;
|
|
295
|
+
|
|
296
|
+
const pointsOnSphereBetween = `vec3 pointsOnSphereBetween(vec3 a, vec3 b, float ratio) {
|
|
297
|
+
// Normalize the input points to ensure they are on the unit sphere
|
|
298
|
+
a = normalize(a);
|
|
299
|
+
b = normalize(b);
|
|
300
|
+
|
|
301
|
+
// Compute the angle between the points
|
|
302
|
+
float theta = acos(dot(a, b));
|
|
303
|
+
|
|
304
|
+
// Compute the interpolated point using spherical linear interpolation (slerp)
|
|
305
|
+
vec3 result = (sin((1.0 - ratio) * theta) * a + sin(ratio * theta) * b) / sin(theta);
|
|
306
|
+
|
|
307
|
+
// Return the normalized result to ensure it lies on the sphere
|
|
308
|
+
return normalize(result);
|
|
309
|
+
}`
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
const circleLimpFromLongLatRadCenterCartesian3D_accurate = R + `
|
|
313
|
+
vec3 circleLimpFromLongLatRadCenterCartesian3D_accurate( vec3 geoW, float radius, float angle) {
|
|
314
|
+
vec3 normal = normalize(geoW);
|
|
315
|
+
vec3 tangent1 = cross(normal, vec3(0.0, 0.0, -1.0));
|
|
316
|
+
if ( length(tangent1) < 0.1 ){ tangent1 = cross(normal, vec3(0.0, -1.0, 0.0)); }
|
|
317
|
+
tangent1 = normalize(tangent1);
|
|
318
|
+
// rotate tangent with given angle
|
|
319
|
+
tangent1 = cos(angle) * tangent1 - sin(angle) * cross(normal, tangent1);
|
|
320
|
+
float radius_in_angle = radius/R;
|
|
321
|
+
float projected_radius = sin(radius_in_angle) * R / 1000.0;
|
|
322
|
+
return (geoW * cos(radius_in_angle))+ tangent1 * projected_radius;
|
|
323
|
+
}`;
|
|
324
|
+
|
|
325
|
+
const circleLimpFromLongLatRadCenterMercatorCompass_accurate = `
|
|
326
|
+
vec2 circleLimpFromLongLatRadCenterMercatorCompass_accurate(vec2 center, float radius, float angle){
|
|
327
|
+
float y = -sin(angle) * radius + center.y;
|
|
328
|
+
float x = cos(angle) * radius + center.x;
|
|
329
|
+
return vec2(x, y);
|
|
330
|
+
} `;
|
|
331
|
+
|
|
332
|
+
//TODO make it work...
|
|
333
|
+
const circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate = PI + `
|
|
334
|
+
vec2 circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate(vec2 mercator_center, float radius, float angle) {
|
|
335
|
+
vec2 center = vec2(mercator_center.x /6378137.0 , asin(tanh(mercator_center.y / 6378137.0 )));
|
|
336
|
+
float ang = angle + PI / 2.0; // Shift angle to align with +x axis
|
|
337
|
+
float r = radius / R;
|
|
338
|
+
float cos_r = cos(r);
|
|
339
|
+
float sin_r = sin(r);
|
|
340
|
+
|
|
341
|
+
float sin_lat = sin(center.y) * cos_r + cos(center.y) * sin_r * cos(ang);
|
|
342
|
+
float lat = asin(sin_lat);
|
|
343
|
+
|
|
344
|
+
float delta_long = atan(sin(ang) * sin_r * cos(center.y), cos_r - sin(center.y) * sin_lat);
|
|
345
|
+
float longi = center.x + delta_long;
|
|
346
|
+
|
|
347
|
+
return vec2(
|
|
348
|
+
R * longi,
|
|
349
|
+
R * log(tan(PI / 4.0 + lat / 2.0))
|
|
350
|
+
);
|
|
351
|
+
}`;
|
|
352
|
+
|
|
353
|
+
export {
|
|
354
|
+
pointsOnSphereBetween,
|
|
355
|
+
circleLimpFromLongLatRadCenterCartesian3D_accurate,
|
|
356
|
+
circleLimpFromLongLatRadCenterMercatorCompass_accurate,
|
|
357
|
+
circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate
|
|
358
|
+
|
|
359
|
+
}
|