@pirireis/webglobeplugins 0.6.18 → 0.6.19
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/bearing-line/plugin-flat-old.js +500 -0
- package/bearing-line/plugin.js +97 -25
- package/circle-line-chain/plugin.js +60 -8
- package/circle-line-chain/plugin_newer_old.js +406 -0
- package/package.json +1 -1
- package/programs/line-on-globe/circle-accurate-3d.js +185 -0
- package/programs/line-on-globe/circle-accurate-flat.js +200 -0
- package/programs/line-on-globe/circle-accurate.js +2 -0
- package/programs/rings/partial-ring/piece-of-pie.js +3 -3
- package/util/jshelpers/data-filler.js +19 -0
- package/util/shaderfunctions/geometrytransformations.js +8 -3
- package/write-text/context-text3.js +4 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate';
|
|
2
|
+
import { CircleCache } from '../programs/line-on-globe/circle-accurate';
|
|
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
|
+
...["centerCoords2d", "centerCoords3d", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
|
|
147
|
+
this.toOriginVao = this.lineToTheOriginProgram.createVAO(
|
|
148
|
+
...["targetCoords3d", "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
|
+
this.lineToTheOriginProgram.draw(this.toOriginVao, this.bufferOrchestrator.length, this._opacity);
|
|
396
|
+
gl.enable(gl.DEPTH_TEST);
|
|
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")
|
package/package.json
CHANGED
|
@@ -0,0 +1,185 @@
|
|
|
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 vec3 center_position3d;
|
|
39
|
+
in float radius;
|
|
40
|
+
in vec4 color;
|
|
41
|
+
in float dash_ratio;
|
|
42
|
+
in float dash_opacity;
|
|
43
|
+
|
|
44
|
+
out float interpolation;
|
|
45
|
+
out vec4 v_color;
|
|
46
|
+
out float v_dash_ratio;
|
|
47
|
+
out float v_dash_opacity;
|
|
48
|
+
out vec2 v_limp;
|
|
49
|
+
void main() {
|
|
50
|
+
interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
|
|
51
|
+
if ( is3D ) {
|
|
52
|
+
float angle = PI * 2.0 * interpolation;
|
|
53
|
+
vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(center_position3d, radius, angle);
|
|
54
|
+
gl_Position = cartesian3DToGLPosition(position);
|
|
55
|
+
v_limp = vec2(0.0, 0.0);
|
|
56
|
+
} else {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
v_dash_ratio = dash_ratio;
|
|
60
|
+
v_dash_opacity = dash_opacity;
|
|
61
|
+
v_color = color;
|
|
62
|
+
gl_PointSize = 3.0;
|
|
63
|
+
|
|
64
|
+
}`
|
|
65
|
+
|
|
66
|
+
const fragmentShaderSource = `#version 300 es
|
|
67
|
+
${POLE}
|
|
68
|
+
precision highp float;
|
|
69
|
+
uniform float opacity;
|
|
70
|
+
in vec4 v_color;
|
|
71
|
+
in float v_dash_ratio;
|
|
72
|
+
in float v_dash_opacity;
|
|
73
|
+
in float interpolation;
|
|
74
|
+
in vec2 v_limp;
|
|
75
|
+
out vec4 color;
|
|
76
|
+
void main() {
|
|
77
|
+
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; }
|
|
78
|
+
color = v_color;
|
|
79
|
+
color.a *= opacity;
|
|
80
|
+
if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
|
|
81
|
+
if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
|
|
82
|
+
color.a *= v_dash_opacity;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class Logic {
|
|
90
|
+
|
|
91
|
+
constructor(globe) {
|
|
92
|
+
this.globe = globe;
|
|
93
|
+
this.gl = globe.gl;
|
|
94
|
+
this._lastOpacity = 1.0;
|
|
95
|
+
|
|
96
|
+
this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
|
|
97
|
+
|
|
98
|
+
const { gl, program } = this;
|
|
99
|
+
this.program.uniforms = {
|
|
100
|
+
opacity: gl.getUniformLocation(program, "opacity")
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
{ // initial uniform values
|
|
104
|
+
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
105
|
+
gl.useProgram(program);
|
|
106
|
+
gl.uniform1f(program.uniforms.opacity, 1.0);
|
|
107
|
+
gl.useProgram(currentProgram);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
{ // assign attribute locations
|
|
111
|
+
gl.bindAttribLocation(program, 0, "center_position3d");
|
|
112
|
+
gl.bindAttribLocation(program, 1, "radius");
|
|
113
|
+
gl.bindAttribLocation(program, 2, "color");
|
|
114
|
+
gl.bindAttribLocation(program, 2, "dash_ratio");
|
|
115
|
+
gl.bindAttribLocation(program, 3, "dash_opacity");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this.cameraBindingPoint = 0;
|
|
119
|
+
this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
|
|
120
|
+
const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
121
|
+
gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
createVAO(center3dObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
|
|
125
|
+
const { gl } = this;
|
|
126
|
+
const vao = gl.createVertexArray();
|
|
127
|
+
const divisor = 1;
|
|
128
|
+
gl.bindVertexArray(vao);
|
|
129
|
+
{ // make this a function end import from account module.
|
|
130
|
+
const { buffer, stride = 0, offset = 0 } = center3dObj;
|
|
131
|
+
vaoAttributeLoader(gl, buffer, 0, 3, stride, offset, divisor);
|
|
132
|
+
}
|
|
133
|
+
{
|
|
134
|
+
const { buffer, stride = 0, offset = 0 } = radiusObj;
|
|
135
|
+
vaoAttributeLoader(gl, buffer, 1, 1, stride, offset, divisor);
|
|
136
|
+
}
|
|
137
|
+
{
|
|
138
|
+
const { buffer, stride = 0, offset = 0 } = colorObj;
|
|
139
|
+
vaoAttributeLoader(gl, buffer, 2, 4, stride, offset, divisor);
|
|
140
|
+
}
|
|
141
|
+
{
|
|
142
|
+
const { buffer, stride = 0, offset = 0 } = dashRatioObj;
|
|
143
|
+
vaoAttributeLoader(gl, buffer, 3, 1, stride, offset, divisor);
|
|
144
|
+
}
|
|
145
|
+
{
|
|
146
|
+
const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
|
|
147
|
+
vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
|
|
148
|
+
}
|
|
149
|
+
gl.bindVertexArray(null);
|
|
150
|
+
gl.bindVertexArray(null);
|
|
151
|
+
return vao;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
draw(vao, length, opacity) {
|
|
155
|
+
const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
|
|
156
|
+
gl.useProgram(program);
|
|
157
|
+
|
|
158
|
+
if (this._lastOpacity !== opacity) {
|
|
159
|
+
gl.uniform1f(program.uniforms.opacity, opacity);
|
|
160
|
+
this._lastOpacity = opacity;
|
|
161
|
+
}
|
|
162
|
+
gl.bindVertexArray(vao);
|
|
163
|
+
cameraBlockTotem.bind(cameraBindingPoint);
|
|
164
|
+
gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
|
|
165
|
+
// gl.drawArraysInstanced(gl.POINTS, 0, EDGE_COUNT_ON_SPHERE + 1, length);
|
|
166
|
+
cameraBlockTotem.unbind(cameraBindingPoint);
|
|
167
|
+
gl.bindVertexArray(null);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
free() {
|
|
173
|
+
if (this.isFreed) return;
|
|
174
|
+
CameraUniformBlockTotemCache.release(this.globe);
|
|
175
|
+
this.gl.deleteProgram(this.program);
|
|
176
|
+
this.isFreed = true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
export const CircleCache = Object.freeze({
|
|
183
|
+
get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
|
|
184
|
+
release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
|
|
185
|
+
});
|