@pirireis/webglobeplugins 1.1.10 → 1.1.12
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/package.json
CHANGED
|
@@ -5,6 +5,7 @@ const _workers = [];
|
|
|
5
5
|
const _workerMap = new Map();
|
|
6
6
|
let _maxWorkers = 4;
|
|
7
7
|
let _nextWorkerIndex = 0;
|
|
8
|
+
let _stateChanged = false;
|
|
8
9
|
let _pickableState;
|
|
9
10
|
let _arcState;
|
|
10
11
|
let _variativeColorsOn;
|
|
@@ -174,13 +175,16 @@ function mergeAndSendResults() {
|
|
|
174
175
|
function sendToSubWorker(wrapper) {
|
|
175
176
|
if (wrapper.inProgress)
|
|
176
177
|
return false;
|
|
177
|
-
if (wrapper.insertDeleteQueue.length === 0 &&
|
|
178
|
+
if (wrapper.insertDeleteQueue.length === 0 &&
|
|
179
|
+
wrapper.lastBBOXData === null &&
|
|
180
|
+
!_stateChanged)
|
|
178
181
|
return false;
|
|
182
|
+
_stateChanged = false;
|
|
179
183
|
wrapper.inProgress = true;
|
|
180
184
|
wrapper.worker.postMessage({
|
|
181
|
-
pickableState:
|
|
182
|
-
variativeColorsOn:
|
|
183
|
-
arcState:
|
|
185
|
+
pickableState: _pickableState,
|
|
186
|
+
variativeColorsOn: _variativeColorsOn,
|
|
187
|
+
arcState: _arcState,
|
|
184
188
|
bboxes: wrapper.lastBBOXData,
|
|
185
189
|
insertDeleteQueue: wrapper.insertDeleteQueue,
|
|
186
190
|
});
|
|
@@ -215,6 +219,18 @@ self.onmessage = (event) => {
|
|
|
215
219
|
for (const w of _workers)
|
|
216
220
|
w.lastBBOXData = bboxes;
|
|
217
221
|
}
|
|
222
|
+
if (arcState !== undefined && arcState !== _arcState) {
|
|
223
|
+
_arcState = arcState;
|
|
224
|
+
_stateChanged = true;
|
|
225
|
+
}
|
|
226
|
+
if (pickableState !== undefined && pickableState !== _pickableState) {
|
|
227
|
+
_pickableState = pickableState;
|
|
228
|
+
_stateChanged = true;
|
|
229
|
+
}
|
|
230
|
+
if (variativeColorsOn !== undefined && variativeColorsOn !== _variativeColorsOn) {
|
|
231
|
+
_variativeColorsOn = variativeColorsOn;
|
|
232
|
+
_stateChanged = true;
|
|
233
|
+
}
|
|
218
234
|
if (insertDeleteQueue && insertDeleteQueue.length > 0) {
|
|
219
235
|
if (insertDeleteQueue[0] === "__CLEAR_ALL_ITEMS__") {
|
|
220
236
|
_workerMap.clear();
|
|
@@ -46,6 +46,18 @@ export class WorkerContact {
|
|
|
46
46
|
this.demTextureManager.unregister(this);
|
|
47
47
|
this._masterWorker.terminate();
|
|
48
48
|
}
|
|
49
|
+
setDrawEdgesState(state) {
|
|
50
|
+
this._options.drawEdges = state;
|
|
51
|
+
this._masterWorker.postMessage({
|
|
52
|
+
arcState: state
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
setPickableState(state) {
|
|
56
|
+
this._options.pickable = state;
|
|
57
|
+
this._masterWorker.postMessage({
|
|
58
|
+
pickableState: state
|
|
59
|
+
});
|
|
60
|
+
}
|
|
49
61
|
insertBulk(polygons) {
|
|
50
62
|
this._masterWorker.postMessage({
|
|
51
63
|
insertDeleteQueue: polygons
|
|
@@ -12,8 +12,17 @@ export class TerrainPolygonSemiPlugin {
|
|
|
12
12
|
drawEdges: true,
|
|
13
13
|
pickable: false,
|
|
14
14
|
variativeColorsOn: false,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
polygonStyle: {
|
|
16
|
+
defaultColor: [0.5, 0.5, 1, 1],
|
|
17
|
+
pickedColor: [1, 0, 0, 1],
|
|
18
|
+
opacity: 1.0,
|
|
19
|
+
},
|
|
20
|
+
edgeStyle: {
|
|
21
|
+
defaultColor: [1, 1, 0, 1],
|
|
22
|
+
pickedColor: [1, 0, 0, 1],
|
|
23
|
+
opacity: 1.0,
|
|
24
|
+
},
|
|
25
|
+
// Global opacity multiplier applied on top of style opacities
|
|
17
26
|
opacity: 1.0,
|
|
18
27
|
showTesselationPoints: false,
|
|
19
28
|
};
|
|
@@ -37,7 +46,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
37
46
|
},
|
|
38
47
|
drawMode: WebGL2RenderingContext.POINTS,
|
|
39
48
|
elementBufferIndexType: WebGL2RenderingContext.UNSIGNED_INT,
|
|
40
|
-
elementBuffer:
|
|
49
|
+
elementBuffer: null,
|
|
41
50
|
};
|
|
42
51
|
_drawRealEdgeArcs = {
|
|
43
52
|
drawRange: {
|
|
@@ -46,7 +55,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
46
55
|
},
|
|
47
56
|
drawMode: WebGL2RenderingContext.LINE_STRIP,
|
|
48
57
|
elementBufferIndexType: WebGL2RenderingContext.UNSIGNED_INT,
|
|
49
|
-
elementBuffer:
|
|
58
|
+
elementBuffer: null,
|
|
50
59
|
};
|
|
51
60
|
_drawRangeIndexParams = {
|
|
52
61
|
drawRange: {
|
|
@@ -55,14 +64,31 @@ export class TerrainPolygonSemiPlugin {
|
|
|
55
64
|
},
|
|
56
65
|
drawMode: WebGL2RenderingContext.TRIANGLES,
|
|
57
66
|
elementBufferIndexType: WebGL2RenderingContext.UNSIGNED_INT,
|
|
58
|
-
elementBuffer:
|
|
67
|
+
elementBuffer: null,
|
|
59
68
|
};
|
|
60
69
|
constructor(id, options = {}) {
|
|
61
70
|
this.id = id;
|
|
62
|
-
this._options = {
|
|
71
|
+
this._options = {
|
|
72
|
+
...this._options,
|
|
73
|
+
...options,
|
|
74
|
+
polygonStyle: {
|
|
75
|
+
...this._options.polygonStyle,
|
|
76
|
+
...(options.polygonStyle ?? {}),
|
|
77
|
+
},
|
|
78
|
+
edgeStyle: {
|
|
79
|
+
...this._options.edgeStyle,
|
|
80
|
+
...(options.edgeStyle ?? {}),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
63
83
|
console.log("TerrainPolygonSemiPlugin options:", this._options);
|
|
64
84
|
}
|
|
65
85
|
;
|
|
86
|
+
_effectivePolygonOpacity() {
|
|
87
|
+
return this._options.opacity * this._options.polygonStyle.opacity;
|
|
88
|
+
}
|
|
89
|
+
_effectiveEdgeOpacity() {
|
|
90
|
+
return this._options.opacity * this._options.edgeStyle.opacity;
|
|
91
|
+
}
|
|
66
92
|
init(globe, gl) {
|
|
67
93
|
this.globe = globe;
|
|
68
94
|
this._drawRangeIndexParams.drawMode = globe.gl.TRIANGLES;
|
|
@@ -72,18 +98,19 @@ export class TerrainPolygonSemiPlugin {
|
|
|
72
98
|
this._vec3Buffer = gl.createBuffer();
|
|
73
99
|
this._mercatorXYBuffer = gl.createBuffer();
|
|
74
100
|
this._uboHandler = this._program.createUBO();
|
|
75
|
-
this._uboHandler.updateSingle("opacity", new Float32Array([this.
|
|
76
|
-
this._uboHandler.updateSingle("defaultColor", new Float32Array(this._options.defaultColor));
|
|
101
|
+
this._uboHandler.updateSingle("opacity", new Float32Array([this._effectivePolygonOpacity()]));
|
|
102
|
+
this._uboHandler.updateSingle("defaultColor", new Float32Array(this._options.polygonStyle.defaultColor));
|
|
77
103
|
if (this._options.pickable) {
|
|
78
104
|
this._pickIndexBuffer = gl.createBuffer();
|
|
79
105
|
this._pickerDisplayer = new PickerDisplayer(this.globe, "R32I");
|
|
80
106
|
this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
|
|
81
|
-
this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.pickedColor));
|
|
107
|
+
this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
|
|
82
108
|
}
|
|
83
109
|
if (this._options.drawEdges) {
|
|
84
110
|
this._uboForRealEdgeArcs = this._program.createUBO();
|
|
85
|
-
this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(
|
|
111
|
+
this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
|
|
86
112
|
this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([1]));
|
|
113
|
+
this._uboForRealEdgeArcs.updateSingle("opacity", new Float32Array([this._effectiveEdgeOpacity()]));
|
|
87
114
|
this._drawRealEdgeArcs.elementBuffer = gl.createBuffer();
|
|
88
115
|
}
|
|
89
116
|
if (this._options.variativeColorsOn) {
|
|
@@ -137,31 +164,118 @@ export class TerrainPolygonSemiPlugin {
|
|
|
137
164
|
if (name.startsWith("private_")) {
|
|
138
165
|
throw new Error(`Cannot set private uniform ${name}`);
|
|
139
166
|
}
|
|
140
|
-
|
|
141
|
-
if (this._options[name] === value) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
this._options[name] = value;
|
|
145
|
-
}
|
|
167
|
+
const isStyleKey = name === "defaultColor" || name === "pickedColor" || name === "opacity";
|
|
146
168
|
if (target === "polygon") {
|
|
147
|
-
|
|
169
|
+
if (isStyleKey) {
|
|
170
|
+
const prev = this._options.polygonStyle[name];
|
|
171
|
+
if (prev === value)
|
|
172
|
+
return;
|
|
173
|
+
this._options.polygonStyle[name] = value;
|
|
174
|
+
if (name === "opacity") {
|
|
175
|
+
this._uboHandler.updateSingle("opacity", new Float32Array([this._effectivePolygonOpacity()]));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this._uboHandler.updateSingle(name, value);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
this._uboHandler.updateSingle(name, value);
|
|
183
|
+
}
|
|
148
184
|
}
|
|
149
185
|
else if (target === "edgeArc") {
|
|
150
|
-
|
|
186
|
+
if (isStyleKey) {
|
|
187
|
+
const prev = this._options.edgeStyle[name];
|
|
188
|
+
if (prev === value)
|
|
189
|
+
return;
|
|
190
|
+
this._options.edgeStyle[name] = value;
|
|
191
|
+
if (name === "opacity") {
|
|
192
|
+
this._uboForRealEdgeArcs?.updateSingle("opacity", new Float32Array([this._effectiveEdgeOpacity()]));
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
this._uboForRealEdgeArcs?.updateSingle(name, value);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
this._uboForRealEdgeArcs?.updateSingle(name, value);
|
|
200
|
+
}
|
|
151
201
|
}
|
|
152
202
|
else {
|
|
153
203
|
console.warn(`Unknown target ${target} for setUniform, must be "polygon" or "edgeArc"`);
|
|
154
204
|
}
|
|
155
205
|
this.globe.DrawRender();
|
|
156
206
|
}
|
|
207
|
+
setDrawEdgesState(state, options = {}) {
|
|
208
|
+
const oldState = this._options.drawEdges;
|
|
209
|
+
if (oldState === state)
|
|
210
|
+
return;
|
|
211
|
+
if (options?.defaultColor) {
|
|
212
|
+
this._options.edgeStyle.defaultColor = options.defaultColor;
|
|
213
|
+
}
|
|
214
|
+
if (options?.pickedColor) {
|
|
215
|
+
this._options.edgeStyle.pickedColor = options.pickedColor;
|
|
216
|
+
}
|
|
217
|
+
if (options?.opacity !== undefined) {
|
|
218
|
+
this._options.edgeStyle.opacity = options.opacity;
|
|
219
|
+
}
|
|
220
|
+
if (oldState === false && state === true) {
|
|
221
|
+
this._uboForRealEdgeArcs = this._program.createUBO();
|
|
222
|
+
this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
|
|
223
|
+
this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([1]));
|
|
224
|
+
this._uboForRealEdgeArcs.updateSingle("opacity", new Float32Array([this._effectiveEdgeOpacity()]));
|
|
225
|
+
this._drawRealEdgeArcs.elementBuffer = this.globe.gl.createBuffer();
|
|
226
|
+
}
|
|
227
|
+
else if (oldState === true && state === false) {
|
|
228
|
+
this._uboForRealEdgeArcs?.free();
|
|
229
|
+
this._uboForRealEdgeArcs = null;
|
|
230
|
+
this.globe.gl.deleteBuffer(this._drawRealEdgeArcs.elementBuffer);
|
|
231
|
+
this._drawRealEdgeArcs.elementBuffer = null;
|
|
232
|
+
}
|
|
233
|
+
this._workerContact.setDrawEdgesState(state);
|
|
234
|
+
this._options.drawEdges = state;
|
|
235
|
+
this.globe.DrawRender();
|
|
236
|
+
}
|
|
157
237
|
setOpacity(opacity) {
|
|
158
238
|
if (this._options.opacity !== opacity) {
|
|
159
239
|
this._options.opacity = opacity;
|
|
160
|
-
this._uboHandler.updateSingle("opacity", new Float32Array([
|
|
161
|
-
this._uboForRealEdgeArcs?.updateSingle("opacity", new Float32Array([
|
|
240
|
+
this._uboHandler.updateSingle("opacity", new Float32Array([this._effectivePolygonOpacity()]));
|
|
241
|
+
this._uboForRealEdgeArcs?.updateSingle("opacity", new Float32Array([this._effectiveEdgeOpacity()]));
|
|
162
242
|
this.globe.DrawRender();
|
|
163
243
|
}
|
|
164
244
|
}
|
|
245
|
+
setPickableState(state) {
|
|
246
|
+
const oldState = this._options.pickable;
|
|
247
|
+
if (oldState === state)
|
|
248
|
+
return;
|
|
249
|
+
if (oldState === false && state === true) {
|
|
250
|
+
// this._pickIndexBuffer = this.globe.gl.createBuffer();
|
|
251
|
+
this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
|
|
252
|
+
this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
|
|
253
|
+
// this._pickerDisplayer = new PickerDisplayer(this.globe, "R32I");
|
|
254
|
+
}
|
|
255
|
+
else if (oldState === true && state === false) {
|
|
256
|
+
// this.globe.gl.deleteBuffer(this._pickIndexBuffer!);
|
|
257
|
+
// this._pickIndexBuffer = null;
|
|
258
|
+
this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([0.0]));
|
|
259
|
+
// this._pickerDisplayer?.free();
|
|
260
|
+
// this._pickerDisplayer = null;
|
|
261
|
+
// this._lastPickedPolygon = null;
|
|
262
|
+
}
|
|
263
|
+
this._options.pickable = state;
|
|
264
|
+
this._workerContact.setPickableState(state);
|
|
265
|
+
this.globe.DrawRender();
|
|
266
|
+
}
|
|
267
|
+
getPickedPolygon() {
|
|
268
|
+
if (this._options.pickable === false) {
|
|
269
|
+
throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
|
|
270
|
+
}
|
|
271
|
+
return this._lastPickedPolygon;
|
|
272
|
+
}
|
|
273
|
+
getPolygon(key) {
|
|
274
|
+
const index = this._indexPolygonMap['_polygonKeyMap'].get(key);
|
|
275
|
+
if (index === undefined)
|
|
276
|
+
return null;
|
|
277
|
+
return this._indexPolygonMap.get(index);
|
|
278
|
+
}
|
|
165
279
|
setBuffers(data) {
|
|
166
280
|
const gl = this.globe.gl;
|
|
167
281
|
const posVertexCount = Math.floor(data.vec3s.length / 3);
|
|
@@ -175,26 +289,28 @@ export class TerrainPolygonSemiPlugin {
|
|
|
175
289
|
}
|
|
176
290
|
// Guard against invalid indices referencing beyond uploaded attribute buffers.
|
|
177
291
|
// This prevents ANGLE "Vertex buffer is not big enough for the draw call" errors.
|
|
178
|
-
let maxTriangleIndex = -1;
|
|
179
|
-
for (let i = 0; i < data.indices.length; i++) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
292
|
+
// let maxTriangleIndex = -1;
|
|
293
|
+
// // for (let i = 0; i < data.indices.length; i++) {
|
|
294
|
+
// // const v = data.indices[i];
|
|
295
|
+
// // if (v > maxTriangleIndex) maxTriangleIndex = v;
|
|
296
|
+
// // }
|
|
297
|
+
// const trianglesInvalid = safeVertexCount === 0 || maxTriangleIndex >= safeVertexCount;
|
|
298
|
+
// if (trianglesInvalid) {
|
|
299
|
+
// console.warn(
|
|
300
|
+
// "TerrainPolygonSemiPlugin: skipping draw due to invalid vertex/index sizing",
|
|
301
|
+
// {
|
|
302
|
+
// posVertexCount,
|
|
303
|
+
// xyVertexCount,
|
|
304
|
+
// safeVertexCount,
|
|
305
|
+
// indicesLength: data.indices.length,
|
|
306
|
+
// maxTriangleIndex,
|
|
307
|
+
// pickIndicesLength: data.pickIndices?.length ?? null,
|
|
308
|
+
// variativeColorsLength: data.variativeColors?.length ?? null,
|
|
309
|
+
// }
|
|
310
|
+
// );
|
|
311
|
+
// this._drawRangeIndexParams.drawRange.count = 0;
|
|
312
|
+
// this._drawPointsRangeIndexParams.drawRange.count = 0;
|
|
313
|
+
// }
|
|
198
314
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._elementArrayBuffer);
|
|
199
315
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data.indices, gl.STREAM_DRAW);
|
|
200
316
|
gl.bindBuffer(gl.ARRAY_BUFFER, this._vec3Buffer);
|
|
@@ -240,18 +356,6 @@ export class TerrainPolygonSemiPlugin {
|
|
|
240
356
|
this._drawPointsRangeIndexParams.drawRange.count = data.indices.length;
|
|
241
357
|
this.globe.DrawRender();
|
|
242
358
|
}
|
|
243
|
-
getPickedPolygon() {
|
|
244
|
-
if (this._options.pickable === false) {
|
|
245
|
-
throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
|
|
246
|
-
}
|
|
247
|
-
return this._lastPickedPolygon;
|
|
248
|
-
}
|
|
249
|
-
getPolygon(key) {
|
|
250
|
-
const index = this._indexPolygonMap['_polygonKeyMap'].get(key);
|
|
251
|
-
if (index === undefined)
|
|
252
|
-
return null;
|
|
253
|
-
return this._indexPolygonMap.get(index);
|
|
254
|
-
}
|
|
255
359
|
_selfSelect() {
|
|
256
360
|
const { globe, _pickerDisplayer } = this;
|
|
257
361
|
const pos = globe.api_GetMousePos();
|
|
@@ -295,7 +399,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
295
399
|
if (this._options.showTesselationPoints) {
|
|
296
400
|
this._program.draw(this._vao, this._drawPointsRangeIndexParams, this._uboHandler);
|
|
297
401
|
}
|
|
298
|
-
if (this._pickerDisplayer) {
|
|
402
|
+
if (this._pickerDisplayer && this._options.pickable) {
|
|
299
403
|
this._pickerDisplayer.bindFBO();
|
|
300
404
|
this._pickerDisplayer.clearTextures();
|
|
301
405
|
// gl.enable(gl.DEPTH_TEST);
|
|
@@ -303,7 +407,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
303
407
|
gl.frontFace(gl.CW);
|
|
304
408
|
this._program.draw(this._vao, this._drawRangeIndexParams, this._uboHandler);
|
|
305
409
|
gl.frontFace(gl.CCW);
|
|
306
|
-
if (this._pickerDisplayer) {
|
|
410
|
+
if (this._pickerDisplayer && this._options.pickable) {
|
|
307
411
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
308
412
|
this._pickerDisplayer.drawColorTexture();
|
|
309
413
|
this._selfSelect();
|