@pirireis/webglobeplugins 0.0.4 → 0.0.6
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/index.js +2 -1
- package/package.json +1 -1
- package/partialrings/goals.md +15 -0
- package/partialrings/index.js +3 -0
- package/partialrings/plugin.js +174 -0
- package/partialrings/program.js +246 -0
- package/programs/rings/distancering/circleflatprogram.js +2 -2
- package/programs/rings/distancering/circlepaddingfreeangleprogram.js +382 -0
- package/programs/rings/distancering/circlepaddysharedbuffer.js +74 -93
- package/programs/rings/distancering/index.js +2 -2
- package/programs/rings/distancering/paddyflatprogram.js +5 -2
- package/rangerings/index.js +2 -2
- package/rangerings/rangerings.js +93 -14
- package/util/account/bufferoffsetmanager.js +179 -0
- package/util/account/index.js +3 -0
- package/util/shaderfunctions/geometrytransformations.js +2 -2
package/rangerings/rangerings.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { rings } from "../programs";
|
|
2
2
|
|
|
3
|
+
import { PaddingFreeAngleCache } from "../programs/rings/distancering";
|
|
3
4
|
const { CircleFlatProgram, PaddyFlatProgram, CirclePaddySharedBuffer } = rings;
|
|
4
5
|
|
|
5
6
|
|
|
@@ -16,27 +17,31 @@ const { CircleFlatProgram, PaddyFlatProgram, CirclePaddySharedBuffer } = rings;
|
|
|
16
17
|
*
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Boylelikle bir pluginin iki bufferManageri yonetmesi gerekmez.
|
|
23
|
-
*/
|
|
20
|
+
|
|
21
|
+
export const ENUM_HIDE = Object.freeze({ SHOW: 0, HIDE: 1, HIDE_1_DEGREE_PADDINGS: 2 });
|
|
22
|
+
|
|
24
23
|
|
|
25
24
|
export default class {
|
|
26
25
|
|
|
27
|
-
constructor(id,
|
|
26
|
+
constructor(id, paddingOn = true, compass = 1, circleEdgeCount = 360) {
|
|
28
27
|
this.id = id;
|
|
29
28
|
this.compass = compass;
|
|
30
|
-
this.padCount = padCount;
|
|
31
29
|
this.circleEdgeCount = circleEdgeCount;
|
|
30
|
+
this._paddingOn = paddingOn;
|
|
32
31
|
this.bufferManager = null;
|
|
33
32
|
}
|
|
34
33
|
|
|
34
|
+
setPaddingOn(paddingOn) {
|
|
35
|
+
this._paddingOn = paddingOn;
|
|
36
|
+
}
|
|
37
|
+
|
|
35
38
|
init(globe, gl) {
|
|
36
39
|
this.gl = gl;
|
|
37
40
|
this.globe = globe;
|
|
38
41
|
this.circleFlatProgram = new CircleFlatProgram(globe, gl);
|
|
39
42
|
this.paddyFlatProgram = new PaddyFlatProgram(globe, gl);
|
|
43
|
+
|
|
44
|
+
this.paddingFreeAngleProgram = PaddingFreeAngleCache.getProgram(globe);
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
free() {
|
|
@@ -49,14 +54,16 @@ export default class {
|
|
|
49
54
|
|
|
50
55
|
|
|
51
56
|
draw3D() {
|
|
52
|
-
const { circleFlatProgram, paddyFlatProgram, padCount, bufferManager, compass, gl, circleEdgeCount } = this;
|
|
57
|
+
const { circleFlatProgram, paddyFlatProgram, padCount, paddingFreeAngleProgram, bufferManager, compass, gl, circleEdgeCount, paddingBufferManager } = this;
|
|
53
58
|
// if (globe.api_GetCurrentGeometry() === 0) return; // do not draw in 3D mode
|
|
54
59
|
if (this.bufferManager !== null && bufferManager.length > 0) {
|
|
55
60
|
gl.disable(gl.DEPTH_TEST);
|
|
56
61
|
// gl.enable(gl.BLEND);
|
|
57
62
|
// gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
58
63
|
circleFlatProgram.draw(bufferManager, compass, circleEdgeCount);
|
|
59
|
-
paddyFlatProgram.draw(bufferManager,
|
|
64
|
+
if (this._paddingOn) paddyFlatProgram.draw(bufferManager, 360, compass);
|
|
65
|
+
paddingFreeAngleProgram.draw(paddingBufferManager, compass);
|
|
66
|
+
|
|
60
67
|
gl.enable(gl.DEPTH_TEST);
|
|
61
68
|
}
|
|
62
69
|
}
|
|
@@ -77,12 +84,84 @@ export default class {
|
|
|
77
84
|
initilizeBufferManager(initialRingCapacity, bufferDrawType) {
|
|
78
85
|
const { gl, globe } = this
|
|
79
86
|
this.bufferDrawType = bufferDrawType;
|
|
80
|
-
this.bufferManager = new CirclePaddySharedBuffer(gl, globe, { bufferType:
|
|
81
|
-
|
|
87
|
+
this.bufferManager = new CirclePaddySharedBuffer(gl, globe, { bufferType: bufferDrawType, initialRingCapacity: initialRingCapacity });
|
|
88
|
+
this.paddingBufferManager = this.paddingFreeAngleProgram.initilizeBufferManager({ bufferType: bufferDrawType, initialRingCapacity });
|
|
82
89
|
}
|
|
83
90
|
|
|
84
|
-
getBufferManager() {
|
|
85
|
-
|
|
91
|
+
// getBufferManager() {
|
|
92
|
+
// return this.bufferManager;
|
|
93
|
+
// }
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @typedef {Array<{ringID, radius, paddingRange}>} rings
|
|
99
|
+
* @param {Array<centerID:string, x:number, y:number, paddingAngles:Array<number>, rgba:[4number], rings:rings} items
|
|
100
|
+
*/
|
|
101
|
+
insertBulk(items) {
|
|
102
|
+
const insertData = ringItemsToCircleBufferInsertDataAdaptor(items);
|
|
103
|
+
|
|
104
|
+
this.bufferManager.insertBulk(insertData);
|
|
105
|
+
this.paddingBufferManager.insertBulk(items);
|
|
106
|
+
this.globe.DrawRender();
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
|
|
109
|
+
|
|
110
|
+
updateCentersXY(items) {
|
|
111
|
+
this.bufferManager.updateCentersXY(items);
|
|
112
|
+
this.paddingBufferManager.updateCentersXY(items);
|
|
113
|
+
this.globe.DrawRender();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
updateCentersColor(centerColors) {
|
|
118
|
+
this.bufferManager.updateCentersColor(centerColors);
|
|
119
|
+
this.paddingBufferManager.updateCentersColor(centerColors);
|
|
120
|
+
this.globe.DrawRender();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
// TODO: test
|
|
125
|
+
removeCenters(centerIds) {
|
|
126
|
+
|
|
127
|
+
this.bufferManager.removeCenters(centerIds);
|
|
128
|
+
this.paddingBufferManager.removeCenters(centerIds);
|
|
129
|
+
// this.bufferManager.defrag();
|
|
130
|
+
// this.paddingBufferManager.defrag();
|
|
131
|
+
this.globe.DrawRender();
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//TODO: test
|
|
136
|
+
updateCentersHide(centerHides) {
|
|
137
|
+
this.bufferManager.updateCentersHide(centerHides);
|
|
138
|
+
this.paddingBufferManager.updateCentersHide(centerHides);
|
|
139
|
+
this.globe.DrawRender();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const ringItemsToCircleBufferInsertDataAdaptor = (ringItems) => {
|
|
145
|
+
|
|
146
|
+
const result = [];
|
|
147
|
+
for (const { centerID, x, y, paddingAngles, rgba, rings, hide = 0 } of ringItems) {
|
|
148
|
+
const resultRings = [];
|
|
149
|
+
for (const { ringID, radius, padding } of rings) {
|
|
150
|
+
resultRings.push({
|
|
151
|
+
ringID,
|
|
152
|
+
radius,
|
|
153
|
+
padding: padding / 7,
|
|
154
|
+
rgba,
|
|
155
|
+
hide
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
result.push({
|
|
160
|
+
centerID,
|
|
161
|
+
x,
|
|
162
|
+
y,
|
|
163
|
+
rings: resultRings
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BufferOffsetManager
|
|
3
|
+
* Purpose: To manage the offset of the buffer. Plus extend and defrag the buffer.
|
|
4
|
+
* -------------------------------------------------------------------------------------------------------------------------------------------
|
|
5
|
+
* Functions:
|
|
6
|
+
* 1. getOffet(key) : return the offset of the key if not found return false.
|
|
7
|
+
* 2. setOffset(key, offset) : set the offset of the key.
|
|
8
|
+
* 3. nextOffset() : return the next available offset if not return false.
|
|
9
|
+
* 4. delete(key) : delete the key and return true if not found return false.
|
|
10
|
+
* 5. defragBuffer(gl, buffer, bufferType, newCapacity = null) : defrag the buffer. if newCapacity is not provided the buffer is vacumed.
|
|
11
|
+
* 6. extendBuffer(gl, buffer, bufferType, newCapacity) : extend the buffer.
|
|
12
|
+
* -------------------------------------------------------------------------------------------------------------------------------------------
|
|
13
|
+
* What this class does NOT do:
|
|
14
|
+
* ADD, DELETE, READ
|
|
15
|
+
* ADD, inputs needs to be turn into a block and put into buffer. Bulk will be more performant.
|
|
16
|
+
* DELETE, might be a set to single byte to indicate the tombstone.
|
|
17
|
+
* READ, most of the time is not needed to be read, unless for defraging.
|
|
18
|
+
* This unpredicatable behavior is not handled by this class.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export default class {
|
|
22
|
+
constructor(itemSize, { capacity = 10, bufferType = "STATIC_DRAW" } = {}) {
|
|
23
|
+
this.itemSize = itemSize;
|
|
24
|
+
this.bufferType = bufferType;
|
|
25
|
+
this.offSetMap = new Map();
|
|
26
|
+
this.tombstoneOffSet = [];
|
|
27
|
+
this._capacity = capacity;
|
|
28
|
+
this._length = 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get length() {
|
|
32
|
+
return this._length;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get capacity() {
|
|
36
|
+
return this._capacity;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
getOffset(key) {
|
|
41
|
+
return this.offSetMap.get(key);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setOffset(key, offset) {
|
|
45
|
+
this.offSetMap.set(key, offset);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
nextOffset() {
|
|
49
|
+
if (this.tombstoneOffSet.length > 0) {
|
|
50
|
+
const offset = this.tombstoneOffSet.pop();
|
|
51
|
+
return offset;
|
|
52
|
+
}
|
|
53
|
+
if (this._length < this._capacity) {
|
|
54
|
+
return this._length++ * this.itemSize * 4;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get spaceLeft() {
|
|
60
|
+
return this._capacity - (this._length - this.tombstoneOffSet.length);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get itemCount() {
|
|
64
|
+
return this._length - this.tombstoneOffSet.length;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
deleteFromAccount(key) {
|
|
68
|
+
const offSet = this.offSetMap.get(key);
|
|
69
|
+
if (offSet !== undefined) {
|
|
70
|
+
this.tombstoneOffSet.push(offSet);
|
|
71
|
+
this.offSetMap.delete(key);
|
|
72
|
+
return true;
|
|
73
|
+
} else {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
offsetMapIterator() { // can be used for defraging the real buffer.
|
|
81
|
+
return this.offSetMap.entries();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// TODO: this is broken
|
|
85
|
+
defrag(newCapacity = null) {
|
|
86
|
+
const { gl, buffer, bufferType } = this;
|
|
87
|
+
if (gl === undefined || buffer === undefined || bufferType === undefined) {
|
|
88
|
+
throw new Error("gl, buffer, bufferType are required");
|
|
89
|
+
}
|
|
90
|
+
const itemSize = this.itemSize;
|
|
91
|
+
const itemCount = this.itemCount;
|
|
92
|
+
const capacity = (newCapacity && newCapacity > itemCount) ? newCapacity : itemCount;
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
const newArray = new Float32Array(itemCount * itemSize);
|
|
96
|
+
|
|
97
|
+
const bufferData = this._getBufferData();
|
|
98
|
+
let newOffSet = 0;
|
|
99
|
+
const newOffSetMap = new Map();
|
|
100
|
+
for (const [key, offSet] of this.offSetMap) {
|
|
101
|
+
const itemOffSet = offSet / 4;
|
|
102
|
+
newArray.set(bufferData.slice(itemOffSet, itemOffSet + itemSize), newOffSet);
|
|
103
|
+
// this.offSetMap.set(key, newOffSet * 4);
|
|
104
|
+
newOffSetMap.set(key, newOffSet * 4);
|
|
105
|
+
newOffSet += itemSize;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
109
|
+
gl.bufferData(gl.ARRAY_BUFFER, capacity * itemSize * 4, gl[bufferType]);
|
|
110
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, newArray);
|
|
111
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
112
|
+
|
|
113
|
+
this._capacity = capacity;
|
|
114
|
+
this.tombstoneOffSet = [];
|
|
115
|
+
this.offSetMap = newOffSetMap;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
extendBuffer(gl, buffer, bufferType, newCapacity) {
|
|
120
|
+
const itemSize = this.itemSize;
|
|
121
|
+
const bufferData = this._getBufferData();
|
|
122
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
123
|
+
gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
|
|
124
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
125
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
126
|
+
this._capacity = newCapacity;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
/** implicit methods to be used by the child class */
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @typedef {Float32Array} payload
|
|
135
|
+
* @param {Array<{key, payload}>} items
|
|
136
|
+
* @param {number} partOffset
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
139
|
+
_updatePartial(items, partOffset, gl, buffer) {
|
|
140
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
141
|
+
const partStart = partOffset * 4;
|
|
142
|
+
for (let { key, payload } of items) {
|
|
143
|
+
let offset = this.getOffset(key);
|
|
144
|
+
if (offset !== undefined) {
|
|
145
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset + partStart, payload);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_getBufferData() {
|
|
152
|
+
const { gl, buffer } = this;
|
|
153
|
+
const size = new Float32Array(this.length * this.itemSize);
|
|
154
|
+
const bufferData = new Float32Array(size);
|
|
155
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
156
|
+
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
157
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
158
|
+
return bufferData;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
_removeFromBuffer(keys) {
|
|
164
|
+
const { gl, buffer } = this;
|
|
165
|
+
const emptyBlock = new Float32Array(this.itemSize).fill(0)
|
|
166
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
167
|
+
for (let key of keys) {
|
|
168
|
+
let offset = this.getOffset(key);
|
|
169
|
+
if (offset !== undefined) {
|
|
170
|
+
this.deleteFromAccount(key);
|
|
171
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, emptyBlock);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
@@ -21,7 +21,7 @@ export const PI = `
|
|
|
21
21
|
#endif
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
|
-
export const POLE_BY_PI = `
|
|
24
|
+
export const POLE_BY_PI = `
|
|
25
25
|
#ifndef POLE_BY_PI
|
|
26
26
|
#define POLE_BY_PI 6378136.99911
|
|
27
27
|
#endif
|
|
@@ -29,7 +29,7 @@ export const POLE_BY_PI = `
|
|
|
29
29
|
|
|
30
30
|
export const R_3D = `
|
|
31
31
|
#ifndef R_3D
|
|
32
|
-
#define R_3D 6378.
|
|
32
|
+
#define R_3D 6378.137699911
|
|
33
33
|
#endif
|
|
34
34
|
`;
|
|
35
35
|
|