@pirireis/webglobeplugins 0.0.1
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/arrowfield/adaptor.js +11 -0
- package/arrowfield/index.js +4 -0
- package/arrowfield/plugin.js +128 -0
- package/compassrose/compassrose.js +394 -0
- package/compassrose/index.js +2 -0
- package/heatwavemaps/index.js +4 -0
- package/heatwavemaps/isobar/objectarraylabels.js +247 -0
- package/heatwavemaps/isobar/plugin.js +337 -0
- package/heatwavemaps/isobar/quadtreecontours.js +338 -0
- package/heatwavemaps/plugins/heatwaveglobeshell.js +257 -0
- package/index.js +8 -0
- package/package.json +7 -0
- package/programs/arrowfield/index.js +2 -0
- package/programs/arrowfield/logic.js +284 -0
- package/programs/arrowfield/object.js +89 -0
- package/programs/float2legendwithratio/index.js +3 -0
- package/programs/float2legendwithratio/logic.js +189 -0
- package/programs/float2legendwithratio/object.js +132 -0
- package/programs/globeshell/index.js +2 -0
- package/programs/globeshell/noise/noises.js +0 -0
- package/programs/globeshell/wiggle/index.js +6 -0
- package/programs/globeshell/wiggle/logic.js +374 -0
- package/programs/globeshell/wiggle/object.js +94 -0
- package/programs/helpers/blender/index.js +0 -0
- package/programs/helpers/blender/program.js +91 -0
- package/programs/helpers/fadeaway/index.js +3 -0
- package/programs/helpers/fadeaway/logic.js +76 -0
- package/programs/helpers/fadeaway/object.js +20 -0
- package/programs/helpers/index.js +2 -0
- package/programs/index.js +21 -0
- package/programs/programcache.js +119 -0
- package/programs/rings/distancering/circleflatprogram.js +135 -0
- package/programs/rings/distancering/circlepaddysharedbuffer.js +502 -0
- package/programs/rings/distancering/index.js +5 -0
- package/programs/rings/distancering/paddyflatprogram.js +131 -0
- package/programs/rings/distancering/shader.js +0 -0
- package/programs/rings/index.js +9 -0
- package/programs/totems/camerauniformblock.js +129 -0
- package/programs/totems/index.js +2 -0
- package/programs/util.js +17 -0
- package/programs/vectorfields/index.js +3 -0
- package/programs/vectorfields/logics/drawrectangleparticles.js +125 -0
- package/programs/vectorfields/logics/index.js +5 -0
- package/programs/vectorfields/logics/pixelbased.js +161 -0
- package/programs/vectorfields/logics/ubo.js +64 -0
- package/programs/vectorfields/pingpongbuffermanager.js +80 -0
- package/rangerings/index.js +3 -0
- package/rangerings/rangerings.js +88 -0
- package/timetracks/adaptors.js +133 -0
- package/timetracks/index.js +3 -0
- package/timetracks/plugin.js +304 -0
- package/timetracks/program.js +850 -0
- package/timetracks/programpoint.js +168 -0
- package/util/datamanager/datamanager.js +168 -0
- package/util/datamanager/index.js +3 -0
- package/util/datamanager/pointcoordinatesdatacalculator.js +133 -0
- package/util/datamanager/pointcoordsmeta.js +22 -0
- package/util/geometry/geodatafromtexture.js +52 -0
- package/util/geometry/index.js +44 -0
- package/util/index.js +13 -0
- package/util/jshelpers/index.js +1 -0
- package/util/jshelpers/timefilters.js +32 -0
- package/util/jshelpers/timemethods.js +19 -0
- package/util/programs/index.js +2 -0
- package/util/programs/shapesonglobe.js +248 -0
- package/util/programs/supersampletotextures.js +142 -0
- package/util/programs/texturetoglobe.js +203 -0
- package/util/shaderfunctions/geometrytransformations.js +129 -0
- package/util/shaderfunctions/index.js +2 -0
- package/util/shaderfunctions/nodata.js +10 -0
- package/util/shaderfunctions/noisefunctions.js +44 -0
- package/util/webglobe/gldefaultstates.js +4 -0
- package/util/webglobe/index.js +2 -0
- package/util/webglobe/rasteroverlay.js +96 -0
- package/util/webglobjectbuilders.js +256 -0
- package/waveparticles/adaptor.js +16 -0
- package/waveparticles/index.js +4 -0
- package/waveparticles/plugin.js +281 -0
- package/wind/imagetovectorfieldandmagnitude.js +39 -0
- package/wind/index.js +7 -0
- package/wind/plugin.js +1032 -0
- package/wind/vectorfieldimage.js +27 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ring data model
|
|
3
|
+
* [centerX, centerY, range, padding, r, g, b, a, hide]
|
|
4
|
+
*
|
|
5
|
+
* Buffer is initialized with ring capacity and buffer is created with that capacity. It might be called buffer orphaning.
|
|
6
|
+
*
|
|
7
|
+
* */
|
|
8
|
+
const RING_SIZE = 9;
|
|
9
|
+
|
|
10
|
+
export default class {
|
|
11
|
+
/**
|
|
12
|
+
* @param {WebGL2RenderingContext} gl
|
|
13
|
+
* @param {Object} options
|
|
14
|
+
* @param {Number} options.initialRingCapacity
|
|
15
|
+
* @param {String} options.bufferType - "static" or "dynamic"
|
|
16
|
+
* */
|
|
17
|
+
constructor(gl, globe, { initialRingCapacity = 20, bufferType = "static", implicitExtentionRate = 1.2 } = {}) {
|
|
18
|
+
this.gl = gl;
|
|
19
|
+
this.globe = globe;
|
|
20
|
+
this._capacity = initialRingCapacity;
|
|
21
|
+
this._ringCounter = 0;
|
|
22
|
+
this._length = 0;
|
|
23
|
+
|
|
24
|
+
this._centerMap = new Map(); // key, new MAP(x,y, rings:[])
|
|
25
|
+
this._ringOffsets = new Map();
|
|
26
|
+
this._removedRingsOffsetStack = [];
|
|
27
|
+
|
|
28
|
+
this._bufferType = gl[bufferType.toUpperCase()];
|
|
29
|
+
this.implicitExtentionRate = implicitExtentionRate;
|
|
30
|
+
this.buffer = gl.createBuffer();
|
|
31
|
+
|
|
32
|
+
{ // initilize data
|
|
33
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
|
|
34
|
+
gl.bufferData(gl.ARRAY_BUFFER, initialRingCapacity * 4 * RING_SIZE, this._bufferType);
|
|
35
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
this._circleVAO = gl.createVertexArray();
|
|
40
|
+
gl.bindVertexArray(this._circleVAO);
|
|
41
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
|
|
42
|
+
gl.enableVertexAttribArray(0);
|
|
43
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, RING_SIZE * 4, 0);
|
|
44
|
+
gl.enableVertexAttribArray(1);
|
|
45
|
+
gl.vertexAttribPointer(1, 1, gl.FLOAT, false, RING_SIZE * 4, 2 * 4);
|
|
46
|
+
gl.enableVertexAttribArray(2);
|
|
47
|
+
gl.vertexAttribPointer(2, 4, gl.FLOAT, false, RING_SIZE * 4, 4 * 4);
|
|
48
|
+
gl.enableVertexAttribArray(3);
|
|
49
|
+
gl.vertexAttribPointer(3, 3, gl.FLOAT, false, RING_SIZE * 4, 8 * 4);
|
|
50
|
+
|
|
51
|
+
// set divisors to 1
|
|
52
|
+
gl.vertexAttribDivisor(0, 1);
|
|
53
|
+
gl.vertexAttribDivisor(1, 1);
|
|
54
|
+
gl.vertexAttribDivisor(2, 1);
|
|
55
|
+
gl.vertexAttribDivisor(3, 1);
|
|
56
|
+
gl.bindVertexArray(null);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
{
|
|
60
|
+
this._paddingVAO = gl.createVertexArray();
|
|
61
|
+
gl.bindVertexArray(this._paddingVAO);
|
|
62
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
|
|
63
|
+
gl.enableVertexAttribArray(0);
|
|
64
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, RING_SIZE * 4, 0);
|
|
65
|
+
gl.enableVertexAttribArray(1);
|
|
66
|
+
gl.vertexAttribPointer(1, 1, gl.FLOAT, false, RING_SIZE * 4, 2 * 4);
|
|
67
|
+
gl.enableVertexAttribArray(2);
|
|
68
|
+
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, RING_SIZE * 4, 3 * 4);
|
|
69
|
+
gl.enableVertexAttribArray(3);
|
|
70
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, RING_SIZE * 4, 4 * 4);
|
|
71
|
+
gl.enableVertexAttribArray(4);
|
|
72
|
+
gl.vertexAttribPointer(4, 3, gl.FLOAT, false, RING_SIZE * 4, 8 * 4);
|
|
73
|
+
gl.vertexAttribDivisor(0, 1);
|
|
74
|
+
gl.vertexAttribDivisor(1, 1);
|
|
75
|
+
gl.vertexAttribDivisor(2, 1);
|
|
76
|
+
gl.vertexAttribDivisor(3, 1);
|
|
77
|
+
gl.vertexAttribDivisor(4, 1);
|
|
78
|
+
gl.bindVertexArray(null);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {String} centerID
|
|
84
|
+
* @param {Object} options
|
|
85
|
+
* @param {Number} options.x
|
|
86
|
+
* @param {Number} options.y
|
|
87
|
+
* */
|
|
88
|
+
registerCenter(centerID, { x = 0, y = 0 } = {}) {
|
|
89
|
+
this._centerMap.set(centerID, new Map(
|
|
90
|
+
[
|
|
91
|
+
["x", x],
|
|
92
|
+
["y", y],
|
|
93
|
+
["rings", []] // ring keys
|
|
94
|
+
]
|
|
95
|
+
));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* @param {null | number} newCapacity if null, vacuum defragmentation is applied -> capacity is set to the current ring count
|
|
101
|
+
*/
|
|
102
|
+
defrag(newCapacity = null) {
|
|
103
|
+
const { _removedRingsOffsetStack, _ringOffsets } = this;
|
|
104
|
+
_removedRingsOffsetStack.sort();
|
|
105
|
+
this._capacity = newCapacity || this._ringCounter;
|
|
106
|
+
const arrayToLoad = new Float32Array(this._capacity * RING_SIZE);
|
|
107
|
+
const bufferData = this._getBufferData();
|
|
108
|
+
let arrayOffset = 0;
|
|
109
|
+
const newRingOffsets = new Map();
|
|
110
|
+
for (const [key, offset] of _ringOffsets) {
|
|
111
|
+
const ringOffset = offset / 4
|
|
112
|
+
const ringData = bufferData.slice(ringOffset, ringOffset + RING_SIZE);
|
|
113
|
+
arrayToLoad.set(ringData, arrayOffset);
|
|
114
|
+
newRingOffsets.set(key, arrayOffset * 4);
|
|
115
|
+
arrayOffset += RING_SIZE;
|
|
116
|
+
}
|
|
117
|
+
const { gl, buffer } = this;
|
|
118
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
119
|
+
gl.bufferData(gl.ARRAY_BUFFER, arrayToLoad, this._bufferType);
|
|
120
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
121
|
+
this._ringOffsets = newRingOffsets;
|
|
122
|
+
this._removedRingsOffsetStack = [];
|
|
123
|
+
this._length = this._ringCounter;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
extendBuffer(newCapacity) {
|
|
127
|
+
if (this._capacity >= newCapacity) {
|
|
128
|
+
console.warn("New capacity is smaller than the current capacity");
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this._capacity = newCapacity;
|
|
132
|
+
const { gl, buffer } = this;
|
|
133
|
+
const bufferData = this._getBufferData();
|
|
134
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
135
|
+
gl.bufferData(gl.ARRAY_BUFFER, newCapacity * RING_SIZE * 4, this._bufferType);
|
|
136
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
137
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
checkCapacity(sizeLeft = 1) {
|
|
141
|
+
return sizeLeft <= this._capacity - this._ringCounter;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
capacityLeft() {
|
|
145
|
+
return this._capacity - this._ringCounter;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get capacity() {
|
|
149
|
+
return this._capacity;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get length() {
|
|
153
|
+
return this._length;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
get ringCount() {
|
|
157
|
+
return this._ringCounter;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @typedef centerIdringIdRadiusPaddingRgbaHide
|
|
163
|
+
* @property {String} centerID
|
|
164
|
+
* @property {String} ringID
|
|
165
|
+
* @property {Number} radius
|
|
166
|
+
* @property {Number} padding
|
|
167
|
+
* @property {Array<Number>} rgba - [r,g,b,a]
|
|
168
|
+
* @param {Array<centerIdringIdRadiusPaddingRgbaHide>} centerIdringIdRadiusPaddingRgbaHideList
|
|
169
|
+
* */
|
|
170
|
+
insertRings(centerIdringIdRadiusPaddingRgbaHideList) {
|
|
171
|
+
{ // capacity check
|
|
172
|
+
this._implicitExtendBufferInNeed(centerIdringIdRadiusPaddingRgbaHideList.length);
|
|
173
|
+
}
|
|
174
|
+
const { gl, buffer } = this;
|
|
175
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
176
|
+
for (let { centerID, ringID, radius, padding, rgba, hide = false } of centerIdringIdRadiusPaddingRgbaHideList) {
|
|
177
|
+
if (!this._centerMap.has(centerID)) {
|
|
178
|
+
console.warn("Center is not registered yet");
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const x = this._centerMap.get(centerID).get("x");
|
|
182
|
+
const y = this._centerMap.get(centerID).get("y");
|
|
183
|
+
const bufferData = new Float32Array([x, y, radius, padding, ...rgba, hide ? 1 : 0]);
|
|
184
|
+
const key = this._ringKey(centerID, ringID);
|
|
185
|
+
let offset;
|
|
186
|
+
if (!this._ringOffsets.has(key)) {
|
|
187
|
+
offset = this._nextBufferOffset();
|
|
188
|
+
this._ringOffsets.set(key, offset);
|
|
189
|
+
this._centerMap.get(centerID).get("rings").push(key);
|
|
190
|
+
} else {
|
|
191
|
+
offset = this._ringOffsets.get(key);
|
|
192
|
+
}
|
|
193
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
|
|
194
|
+
}
|
|
195
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
196
|
+
this.globe.DrawRender();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @typedef centerIDringID
|
|
202
|
+
* @property {String} centerID
|
|
203
|
+
* @property {String} ringID
|
|
204
|
+
* @param {Array<centerIDringID>} centerIDringIDs
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
removeRings(centerIDringIDs) {
|
|
208
|
+
const { gl, buffer } = this;
|
|
209
|
+
const zero = new Float32Array([0]);
|
|
210
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
211
|
+
for (let { centerID, ringID } of centerIDringIDs) {
|
|
212
|
+
if (!this._centerMap.has(centerID)) {
|
|
213
|
+
console.warn("Center is not registered yet");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const key = this._ringKey(centerID, ringID);
|
|
217
|
+
if (!this._ringOffsets.has(key)) {
|
|
218
|
+
console.warn("Ring is not registered yet");
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const offset = this._ringOffsets.get(key);
|
|
222
|
+
this._removedRingsOffsetStack.push(offset);
|
|
223
|
+
this._ringOffsets.delete(key);
|
|
224
|
+
// set range to 0, 3rd index of float32array
|
|
225
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset + 8, zero);
|
|
226
|
+
this._centerMap.get(centerID).get("rings").splice(this._centerMap.get(centerID).get("rings").indexOf(key), 1);
|
|
227
|
+
this._ringCounter--;
|
|
228
|
+
}
|
|
229
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
230
|
+
this.globe.DrawRender();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @param {Array<string>} centerIDs
|
|
235
|
+
* */
|
|
236
|
+
removeCenters(centerIDs) {
|
|
237
|
+
const { gl, buffer } = this;
|
|
238
|
+
const zero = new Float32Array([0]);
|
|
239
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
240
|
+
for (let centerID of centerIDs) {
|
|
241
|
+
if (!this._centerMap.has(centerID)) {
|
|
242
|
+
console.warn("Center is not registered yet");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const center = this._centerMap.get(centerID);
|
|
246
|
+
const rings = center.get("rings");
|
|
247
|
+
for (let i = 0; i < rings.length; i++) {
|
|
248
|
+
// set range to 0, 3rd index of float32array
|
|
249
|
+
const offset = this._ringOffsets.get(rings[i]);
|
|
250
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset + 8, zero);
|
|
251
|
+
this._removedRingsOffsetStack.push(offset);
|
|
252
|
+
this._ringOffsets.delete(rings[i]);
|
|
253
|
+
}
|
|
254
|
+
this._ringCounter -= rings.length;
|
|
255
|
+
this._centerMap.delete(centerID);
|
|
256
|
+
}
|
|
257
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
258
|
+
this.globe.DrawRender();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @typedef centerIDxyList
|
|
264
|
+
* @property {String} centerID
|
|
265
|
+
* @property {Number} x mercator x
|
|
266
|
+
* @property {Number} y mercator y
|
|
267
|
+
* @param {*} centerIDxyList
|
|
268
|
+
*/
|
|
269
|
+
updateCentersXY(centerIDxyList) {
|
|
270
|
+
const { gl, buffer } = this;
|
|
271
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
272
|
+
for (let { centerID, x, y } of centerIDxyList) {
|
|
273
|
+
const center = this._centerMap.get(centerID);
|
|
274
|
+
center.set("x", x);
|
|
275
|
+
center.set("y", y);
|
|
276
|
+
const xyBlock = new Float32Array([x, y]);
|
|
277
|
+
const rings = center.get("rings");
|
|
278
|
+
for (let i = 0; i < rings.length; i++) {
|
|
279
|
+
const offset = this._ringOffsets.get(rings[i]);
|
|
280
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, xyBlock);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
284
|
+
this.globe.DrawRender();
|
|
285
|
+
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
*
|
|
291
|
+
* @typedef centerData
|
|
292
|
+
* @property {String} centerID
|
|
293
|
+
* @property {Array<Number>} rgba - [r,g,b,a] - default undefined
|
|
294
|
+
* @property {Number} padding - default undefined
|
|
295
|
+
* @property {Boolean} hide - default undefined
|
|
296
|
+
* @param {Array<centerData>} centerDatas
|
|
297
|
+
* @returns
|
|
298
|
+
*/
|
|
299
|
+
updateCenters(centerDatas) {
|
|
300
|
+
const { gl, buffer } = this;
|
|
301
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
302
|
+
for (let { centerID, padding, rgba, hide } of centerDatas) {
|
|
303
|
+
const rings = this._centerMap.get(centerID).get("rings");
|
|
304
|
+
for (let i = 0; i < rings.length; i++) {
|
|
305
|
+
const offset = this._ringOffsets.get(rings[i]);
|
|
306
|
+
if (padding !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset + 12, new Float32Array([padding]));
|
|
307
|
+
if (rgba !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset + 16, new Float32Array(rgba));
|
|
308
|
+
if (hide !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset + 32, new Float32Array([hide ? 1 : 0]));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
312
|
+
this.globe.DrawRender();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
insertBulk(rangeRingDatas) {
|
|
318
|
+
const { gl, buffer } = this;
|
|
319
|
+
{ // capacity check
|
|
320
|
+
let incomingRingSize = 0;
|
|
321
|
+
for (let { rings } of rangeRingDatas) {
|
|
322
|
+
incomingRingSize += rings.length;
|
|
323
|
+
// It should check if ring is already registered but for now it is not implemented.
|
|
324
|
+
// Reasons: increase in complexity and performance
|
|
325
|
+
}
|
|
326
|
+
this._implicitExtendBufferInNeed(incomingRingSize);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
330
|
+
for (let { centerID, x, y, rings } of rangeRingDatas) {
|
|
331
|
+
if (!this._centerMap.has(centerID)) {
|
|
332
|
+
this.registerCenter(centerID, { x, y })
|
|
333
|
+
} else {
|
|
334
|
+
const rings = this._centerMap.get(centerID).get("rings");
|
|
335
|
+
const xy = new Float32Array([x, y]);
|
|
336
|
+
for (let i = 0; i < rings.length; i++) {
|
|
337
|
+
const offset = this._ringOffsets.get(rings[i]);
|
|
338
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, xy);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (let { ringID, radius, padding, rgba, hide = false } of rings) {
|
|
342
|
+
const key = this._ringKey(centerID, ringID);
|
|
343
|
+
const bufferData = new Float32Array([x, y, radius, padding, ...rgba, hide ? 1 : 0]);
|
|
344
|
+
if (!this._ringOffsets.has(key)) {
|
|
345
|
+
const offset = this._nextBufferOffset();
|
|
346
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
|
|
347
|
+
|
|
348
|
+
this._ringOffsets.set(key, offset);
|
|
349
|
+
this._centerMap.get(centerID).get("rings").push(key);
|
|
350
|
+
} else {
|
|
351
|
+
const offset = this._ringOffsets.get(key);
|
|
352
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
|
|
353
|
+
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
}
|
|
358
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
359
|
+
this.globe.DrawRender();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
updateRing(centerID, ringID, { radius, padding, rgba, hide } = {}) {
|
|
363
|
+
if (!this._centerMap.has(centerID)) {
|
|
364
|
+
console.warn("Center is not registered yet");
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const key = this._ringKey(centerID, ringID);
|
|
368
|
+
if (!this._ringOffsets.has(key)) {
|
|
369
|
+
console.warn("Ring is not registered yet");
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (!this.checkCapacity()) {
|
|
373
|
+
this._implicitExtendBufferInNeed(1);
|
|
374
|
+
}
|
|
375
|
+
const { gl, buffer } = this;
|
|
376
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
377
|
+
const offset = this._ringOffsets.get(key);
|
|
378
|
+
if (radius !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset + 8, new Float32Array([radius]));
|
|
379
|
+
if (padding !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset + 12, new Float32Array([padding]));
|
|
380
|
+
if (rgba !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset + 16, new Float32Array(rgba));
|
|
381
|
+
if (hide !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset + 32, new Float32Array([hide ? 1 : 0]));
|
|
382
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
383
|
+
this.globe.DrawRender();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
// ----------------- INTERNAL METHODS ----------------- //
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
bindCircleVAO() {
|
|
391
|
+
this.gl.bindVertexArray(this._circleVAO);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
bindPaddingVAO() {
|
|
395
|
+
this.gl.bindVertexArray(this._paddingVAO);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
free() {
|
|
400
|
+
this.gl.deleteBuffer(this.buffer);
|
|
401
|
+
this.gl.deleteVertexArray(this._circleVAO);
|
|
402
|
+
this.gl.deleteVertexArray(this._paddingVAO);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ----------------- PRIVATE METHODS ----------------- //
|
|
406
|
+
|
|
407
|
+
_getBufferData() {
|
|
408
|
+
const { gl, buffer } = this;
|
|
409
|
+
const size = new Float32Array(this._length * RING_SIZE);
|
|
410
|
+
const bufferData = new Float32Array(size);
|
|
411
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
412
|
+
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
413
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
414
|
+
return bufferData;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
_ringKey(centerID, ringID) {
|
|
418
|
+
return `C=${centerID},R=${ringID}`;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
_nextBufferOffset() {
|
|
424
|
+
if (!this.checkCapacity()) {
|
|
425
|
+
throw new Error("Buffer is full");
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
let offset;
|
|
429
|
+
if (this._removedRingsOffsetStack.length > 0) {
|
|
430
|
+
offset = this._removedRingsOffsetStack.pop();
|
|
431
|
+
} else {
|
|
432
|
+
offset = this._ringCounter * RING_SIZE * 4;
|
|
433
|
+
this._length++;
|
|
434
|
+
}
|
|
435
|
+
this._ringCounter++;
|
|
436
|
+
return offset;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
_implicitExtendBufferInNeed(incomingRingSize) {
|
|
441
|
+
console.log("implicitExtendBufferInNeed", { incomingRingSize, "capacity left": this.capacityLeft(), "capacity": this._capacity, "ring counter": this._ringCounter });
|
|
442
|
+
const overCapacity = incomingRingSize - this.capacityLeft();
|
|
443
|
+
if (overCapacity <= 0) return;
|
|
444
|
+
const newCapacity = Math.ceil((this._capacity + overCapacity) * this.implicitExtentionRate);
|
|
445
|
+
this.extendBuffer(newCapacity);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
async readRing(centerID, ringID) {
|
|
450
|
+
const key = this._ringKey(centerID, ringID);
|
|
451
|
+
if (!this._ringOffsets.has(key)) {
|
|
452
|
+
console.warn("Ring is not registered yet");
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const offset = this._ringOffsets.get(key);
|
|
456
|
+
const { gl, buffer } = this;
|
|
457
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
458
|
+
const bufferData = new Float32Array(9);
|
|
459
|
+
gl.getBufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
|
|
460
|
+
return {
|
|
461
|
+
centerX: bufferData[0],
|
|
462
|
+
centerY: bufferData[1],
|
|
463
|
+
range: bufferData[2],
|
|
464
|
+
padding: bufferData[3],
|
|
465
|
+
rgba: [bufferData[4], bufferData[5], bufferData[6], bufferData[7]],
|
|
466
|
+
hide: bufferData[8]
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* TODOS:
|
|
474
|
+
* - bulk ring registration. This must be managed here to avoid binding and unbinding buffer multiple times
|
|
475
|
+
* - bulk centers and rings registration
|
|
476
|
+
*
|
|
477
|
+
* - Check capacity on extend buffer and collect garbage
|
|
478
|
+
* - set length to the filled part of the buffer. used for draw calls
|
|
479
|
+
* */
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* collectGarbage with Defragmantation
|
|
483
|
+
* Basic idea: on unregistration the last ring is moved to the removed ring's place. length is decreased by 1
|
|
484
|
+
* Optimization: Reading buffer is expensive. So bulk defragmentation is needed to work with this approach
|
|
485
|
+
* */
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Documentation
|
|
491
|
+
*
|
|
492
|
+
* Methods:
|
|
493
|
+
* - insertRings(centerIdringIdRadiusPaddingRgbaHide)
|
|
494
|
+
* - removeRings(centerIDringIDs)
|
|
495
|
+
* - removeCenters(centerIDs)
|
|
496
|
+
* - updateCentersXY(centerIDxyList)
|
|
497
|
+
* - updateCenters(centerDatas)
|
|
498
|
+
* - insertBulk(rangeRingDatas)
|
|
499
|
+
* - updateRing(centerID, ringID, { radius, padding, rgba, hide })
|
|
500
|
+
* - readRing(centerID, ringID)
|
|
501
|
+
*
|
|
502
|
+
*/
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createProgram, shaderfunctions } from "../../../util";
|
|
2
|
+
import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
|
|
3
|
+
import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
|
|
4
|
+
|
|
5
|
+
const vertexShader = `#version 300 es ` +
|
|
6
|
+
shaderfunctions.PI +
|
|
7
|
+
shaderfunctions.R +
|
|
8
|
+
shaderfunctions.POLE +
|
|
9
|
+
CameraUniformBlockString +
|
|
10
|
+
shaderfunctions.mercatorXYTo2DPoint +
|
|
11
|
+
shaderfunctions.longLatRadToMercator +
|
|
12
|
+
shaderfunctions.longLatRadToCartesian3D +
|
|
13
|
+
shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
|
|
14
|
+
shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
|
|
15
|
+
shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
|
|
16
|
+
|
|
17
|
+
in vec2 center;
|
|
18
|
+
in float radius;
|
|
19
|
+
in float pad_range;
|
|
20
|
+
in vec4 color;
|
|
21
|
+
in float flag;
|
|
22
|
+
|
|
23
|
+
uniform int compass;
|
|
24
|
+
uniform float pad_count;
|
|
25
|
+
|
|
26
|
+
out vec2 v_limp;
|
|
27
|
+
out vec4 v_color;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
void main() {
|
|
31
|
+
if( flag == 1.0 || radius == 0.0 ) return; // 1.0 is hide
|
|
32
|
+
v_color = color;
|
|
33
|
+
gl_PointSize = 2.0;
|
|
34
|
+
|
|
35
|
+
float odd = mod(float(gl_VertexID), 2.0);
|
|
36
|
+
float index = (float(gl_VertexID)- odd ) / 2.0;
|
|
37
|
+
float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
|
|
38
|
+
float radius_ = radius - (pad_range * odd);
|
|
39
|
+
|
|
40
|
+
if ( is3D){
|
|
41
|
+
gl_Position = projection * view * vec4(
|
|
42
|
+
circleLimpFromLongLatRadCenterCartesian3D( center, radius_, angle) - translate, 1.0);
|
|
43
|
+
v_limp = vec2(0.0, 0.0);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
vec2 limp;
|
|
47
|
+
if ( compass == 1 ){
|
|
48
|
+
limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
|
|
49
|
+
} else {
|
|
50
|
+
limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
|
|
51
|
+
}
|
|
52
|
+
v_limp = limp;
|
|
53
|
+
gl_Position = mercatorXYTo2DPoint(limp);
|
|
54
|
+
}`;
|
|
55
|
+
|
|
56
|
+
const fragmentShader = `#version 300 es
|
|
57
|
+
precision highp float; `+
|
|
58
|
+
shaderfunctions.POLE + `
|
|
59
|
+
in vec4 v_color;
|
|
60
|
+
in vec2 v_limp;
|
|
61
|
+
out vec4 outColor;
|
|
62
|
+
void main() {
|
|
63
|
+
if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
|
|
64
|
+
outColor = v_color;
|
|
65
|
+
}`;
|
|
66
|
+
|
|
67
|
+
class Logic {
|
|
68
|
+
constructor(globe) {
|
|
69
|
+
this.globe = globe;
|
|
70
|
+
this.gl = globe.gl;
|
|
71
|
+
this.program = createProgram(this.gl, vertexShader, fragmentShader);
|
|
72
|
+
{ // bind positions so bufferManager can use them
|
|
73
|
+
this.gl.bindAttribLocation(this.program, 0, "center");
|
|
74
|
+
this.gl.bindAttribLocation(this.program, 1, "radius");
|
|
75
|
+
this.gl.bindAttribLocation(this.program, 2, "pad_range");
|
|
76
|
+
this.gl.bindAttribLocation(this.program, 3, "color");
|
|
77
|
+
this.gl.bindAttribLocation(this.program, 4, "flag");
|
|
78
|
+
}
|
|
79
|
+
this.cameraBlockBindingPoint = 0;
|
|
80
|
+
const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
|
|
81
|
+
this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
|
|
82
|
+
this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
|
|
83
|
+
this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
|
|
84
|
+
|
|
85
|
+
this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
|
|
89
|
+
this.gl.useProgram(this.program);
|
|
90
|
+
this.gl.uniform1i(this._compassLocation, 1);
|
|
91
|
+
this.gl.useProgram(currentProgram);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
draw(attrBufferManager, padCount, compass) {
|
|
98
|
+
const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
|
|
99
|
+
gl.useProgram(program);
|
|
100
|
+
attrBufferManager.bindPaddingVAO();
|
|
101
|
+
cameraBlockTotem.bind(cameraBlockBindingPoint);
|
|
102
|
+
// draw instanced
|
|
103
|
+
gl.uniform1f(_padCountLocation, padCount);
|
|
104
|
+
gl.uniform1i(_compassLocation, compass);
|
|
105
|
+
gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
|
|
106
|
+
gl.bindVertexArray(null);
|
|
107
|
+
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
free() {
|
|
111
|
+
this.gl.deleteProgram(this.program);
|
|
112
|
+
globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
export default class {
|
|
119
|
+
constructor(globe, gl) {
|
|
120
|
+
this.gl = gl;
|
|
121
|
+
this.logic = noRegisterGlobeProgramCache.getProgram(globe, Logic);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
draw(attrBufferManager, padCount, compass) {
|
|
125
|
+
this.logic.draw(attrBufferManager, padCount, compass);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
free() {
|
|
129
|
+
noRegisterGlobeProgramCache.releaseProgram(this.gl, Logic);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import CirclePaddySharedBuffer from './distancering/circlepaddysharedbuffer';
|
|
2
|
+
import CircleFlatProgram from './distancering/circleflatprogram';
|
|
3
|
+
import PaddyFlatProgram from './distancering/paddyflatprogram';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
CirclePaddySharedBuffer,
|
|
7
|
+
CircleFlatProgram,
|
|
8
|
+
PaddyFlatProgram,
|
|
9
|
+
};
|