@pirireis/webglobeplugins 1.1.11 → 1.1.13

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -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 && wrapper.lastBBOXData === null)
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: undefined,
182
- variativeColorsOn: undefined,
183
- arcState: undefined,
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
@@ -11,9 +11,21 @@ export class TerrainPolygonSemiPlugin {
11
11
  _options = {
12
12
  drawEdges: true,
13
13
  pickable: false,
14
+ pickablePause: false,
14
15
  variativeColorsOn: false,
15
- defaultColor: [0.5, 0.5, 1, 1],
16
- pickedColor: [1, 0, 0, 1],
16
+ polygonStyle: {
17
+ defaultColor: [0.5, 0.5, 1, 1],
18
+ pickedColor: [1, 0, 0, 1],
19
+ opacity: 1.0,
20
+ useDefaultColor: false,
21
+ },
22
+ edgeStyle: {
23
+ defaultColor: [1, 1, 0, 1],
24
+ pickedColor: [1, 0, 0, 1],
25
+ opacity: 1.0,
26
+ useDefaultColor: true,
27
+ },
28
+ // Global opacity multiplier applied on top of style opacities
17
29
  opacity: 1.0,
18
30
  showTesselationPoints: false,
19
31
  };
@@ -37,7 +49,7 @@ export class TerrainPolygonSemiPlugin {
37
49
  },
38
50
  drawMode: WebGL2RenderingContext.POINTS,
39
51
  elementBufferIndexType: WebGL2RenderingContext.UNSIGNED_INT,
40
- elementBuffer: WebGLBuffer = null,
52
+ elementBuffer: null,
41
53
  };
42
54
  _drawRealEdgeArcs = {
43
55
  drawRange: {
@@ -46,7 +58,7 @@ export class TerrainPolygonSemiPlugin {
46
58
  },
47
59
  drawMode: WebGL2RenderingContext.LINE_STRIP,
48
60
  elementBufferIndexType: WebGL2RenderingContext.UNSIGNED_INT,
49
- elementBuffer: WebGLBuffer = null,
61
+ elementBuffer: null,
50
62
  };
51
63
  _drawRangeIndexParams = {
52
64
  drawRange: {
@@ -55,14 +67,36 @@ export class TerrainPolygonSemiPlugin {
55
67
  },
56
68
  drawMode: WebGL2RenderingContext.TRIANGLES,
57
69
  elementBufferIndexType: WebGL2RenderingContext.UNSIGNED_INT,
58
- elementBuffer: WebGLBuffer = null,
70
+ elementBuffer: null,
59
71
  };
60
72
  constructor(id, options = {}) {
61
73
  this.id = id;
62
- this._options = { ...this._options, ...options };
74
+ this._options = {
75
+ ...this._options,
76
+ ...options,
77
+ polygonStyle: {
78
+ ...this._options.polygonStyle,
79
+ ...(options.polygonStyle ?? {}),
80
+ },
81
+ edgeStyle: {
82
+ ...this._options.edgeStyle,
83
+ ...(options.edgeStyle ?? {}),
84
+ },
85
+ };
63
86
  console.log("TerrainPolygonSemiPlugin options:", this._options);
64
87
  }
65
88
  ;
89
+ _effectiveOpacity(target) {
90
+ if (target === "polygon") {
91
+ return new Float32Array([this._options.opacity * this._options.polygonStyle.opacity]);
92
+ }
93
+ else if (target === "edgeArc") {
94
+ return new Float32Array([this._options.opacity * this._options.edgeStyle.opacity]);
95
+ }
96
+ else {
97
+ throw new Error(`Unknown target ${target} for _effectiveOpacity, must be "polygon" or "edgeArc"`);
98
+ }
99
+ }
66
100
  init(globe, gl) {
67
101
  this.globe = globe;
68
102
  this._drawRangeIndexParams.drawMode = globe.gl.TRIANGLES;
@@ -72,18 +106,19 @@ export class TerrainPolygonSemiPlugin {
72
106
  this._vec3Buffer = gl.createBuffer();
73
107
  this._mercatorXYBuffer = gl.createBuffer();
74
108
  this._uboHandler = this._program.createUBO();
75
- this._uboHandler.updateSingle("opacity", new Float32Array([this._options.opacity]));
76
- this._uboHandler.updateSingle("defaultColor", new Float32Array(this._options.defaultColor));
109
+ this._uboHandler.updateSingle("opacity", this._effectiveOpacity("polygon"));
110
+ this._uboHandler.updateSingle("defaultColor", new Float32Array(this._options.polygonStyle.defaultColor));
77
111
  if (this._options.pickable) {
78
112
  this._pickIndexBuffer = gl.createBuffer();
79
113
  this._pickerDisplayer = new PickerDisplayer(this.globe, "R32I");
80
114
  this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
81
- this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.pickedColor));
115
+ this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
82
116
  }
83
117
  if (this._options.drawEdges) {
84
118
  this._uboForRealEdgeArcs = this._program.createUBO();
85
- this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array([1, 1, 0, 1]));
119
+ this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
86
120
  this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([1]));
121
+ this._uboForRealEdgeArcs.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
87
122
  this._drawRealEdgeArcs.elementBuffer = gl.createBuffer();
88
123
  }
89
124
  if (this._options.variativeColorsOn) {
@@ -137,31 +172,101 @@ export class TerrainPolygonSemiPlugin {
137
172
  if (name.startsWith("private_")) {
138
173
  throw new Error(`Cannot set private uniform ${name}`);
139
174
  }
140
- if (this._options.hasOwnProperty(name)) {
141
- if (this._options[name] === value) {
142
- return;
143
- }
144
- this._options[name] = value;
145
- }
175
+ const isStyleKey = name === "defaultColor" || name === "pickedColor" || name === "opacity" || name === "useDefaultColor";
176
+ let targetUBO;
146
177
  if (target === "polygon") {
147
- this._uboHandler.updateSingle(name, value);
178
+ targetUBO = this._uboHandler;
148
179
  }
149
180
  else if (target === "edgeArc") {
150
- this._uboForRealEdgeArcs?.updateSingle(name, value);
181
+ targetUBO = this._uboForRealEdgeArcs;
151
182
  }
152
183
  else {
153
184
  console.warn(`Unknown target ${target} for setUniform, must be "polygon" or "edgeArc"`);
185
+ return;
186
+ }
187
+ if (isStyleKey) {
188
+ const prev = this._options.polygonStyle[name];
189
+ if (prev === value)
190
+ return;
191
+ this._options.polygonStyle[name] = value;
192
+ if (name === "opacity") {
193
+ targetUBO.updateSingle("opacity", this._effectiveOpacity(target));
194
+ }
195
+ else {
196
+ targetUBO.updateSingle(name, value);
197
+ }
198
+ }
199
+ else {
200
+ targetUBO.updateSingle(name, value);
154
201
  }
155
202
  this.globe.DrawRender();
156
203
  }
204
+ setDrawEdgesState(state) {
205
+ const oldState = this._options.drawEdges;
206
+ if (oldState === state)
207
+ return;
208
+ if (oldState === false && state === true) {
209
+ this._uboForRealEdgeArcs = this._program.createUBO();
210
+ this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
211
+ this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([this._options.edgeStyle.useDefaultColor ? 1 : 0]));
212
+ this._uboForRealEdgeArcs.updateSingle("pickedColor", new Float32Array(this._options.edgeStyle.pickedColor));
213
+ this._uboForRealEdgeArcs.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
214
+ this._drawRealEdgeArcs.elementBuffer = this.globe.gl.createBuffer();
215
+ }
216
+ else if (oldState === true && state === false) {
217
+ this._uboForRealEdgeArcs?.free();
218
+ this._uboForRealEdgeArcs = null;
219
+ this.globe.gl.deleteBuffer(this._drawRealEdgeArcs.elementBuffer);
220
+ this._drawRealEdgeArcs.elementBuffer = null;
221
+ }
222
+ this._workerContact.setDrawEdgesState(state);
223
+ this._options.drawEdges = state;
224
+ this.globe.DrawRender();
225
+ }
157
226
  setOpacity(opacity) {
158
227
  if (this._options.opacity !== opacity) {
159
228
  this._options.opacity = opacity;
160
- this._uboHandler.updateSingle("opacity", new Float32Array([opacity]));
161
- this._uboForRealEdgeArcs?.updateSingle("opacity", new Float32Array([opacity]));
229
+ this._uboHandler.updateSingle("opacity", this._effectiveOpacity("polygon"));
230
+ this._uboForRealEdgeArcs?.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
162
231
  this.globe.DrawRender();
163
232
  }
164
233
  }
234
+ setPausePickableState(state) {
235
+ if (this._options.pickable === false) {
236
+ throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
237
+ }
238
+ const oldState = this._options.pickablePause;
239
+ if (oldState === state)
240
+ return;
241
+ this._options.pickablePause = state;
242
+ // dont initialize anything. just set private_isPickedOn uniform
243
+ this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([state ? 0.0 : 1.0]));
244
+ this.globe.DrawRender();
245
+ }
246
+ setPickableState(state) {
247
+ throw new Error("setPickableState is buggy. use setPausePickableState instead.");
248
+ const oldState = this._options.pickable;
249
+ if (oldState === state)
250
+ return;
251
+ if (oldState === false && state === true) {
252
+ this._pickIndexBuffer = this.globe.gl.createBuffer();
253
+ this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
254
+ this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
255
+ this._pickerDisplayer = new PickerDisplayer(this.globe, "R32I");
256
+ }
257
+ else if (oldState === true && state === false) {
258
+ this.globe.gl.deleteBuffer(this._pickIndexBuffer);
259
+ this._pickIndexBuffer = null;
260
+ this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([0.0]));
261
+ this._uboHandler.updateSingle("private_pickedIndex", new Float32Array([-1]));
262
+ this._pickerDisplayer?.free();
263
+ this._pickerDisplayer = null;
264
+ this._lastPickedPolygon = null;
265
+ }
266
+ this._options.pickable = state;
267
+ this._workerContact.setPickableState(state);
268
+ this.globe.DrawRender();
269
+ }
165
270
  getPickedPolygon() {
166
271
  if (this._options.pickable === false) {
167
272
  throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
@@ -297,7 +402,7 @@ export class TerrainPolygonSemiPlugin {
297
402
  if (this._options.showTesselationPoints) {
298
403
  this._program.draw(this._vao, this._drawPointsRangeIndexParams, this._uboHandler);
299
404
  }
300
- if (this._pickerDisplayer) {
405
+ if (this._pickerDisplayer && !this._options.pickablePause) {
301
406
  this._pickerDisplayer.bindFBO();
302
407
  this._pickerDisplayer.clearTextures();
303
408
  // gl.enable(gl.DEPTH_TEST);
@@ -305,7 +410,7 @@ export class TerrainPolygonSemiPlugin {
305
410
  gl.frontFace(gl.CW);
306
411
  this._program.draw(this._vao, this._drawRangeIndexParams, this._uboHandler);
307
412
  gl.frontFace(gl.CCW);
308
- if (this._pickerDisplayer) {
413
+ if (this._pickerDisplayer && !this._options.pickablePause) {
309
414
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
310
415
  this._pickerDisplayer.drawColorTexture();
311
416
  this._selfSelect();