@pirireis/webglobeplugins 1.1.11 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
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
@@ -12,8 +12,17 @@ export class TerrainPolygonSemiPlugin {
12
12
  drawEdges: true,
13
13
  pickable: false,
14
14
  variativeColorsOn: false,
15
- defaultColor: [0.5, 0.5, 1, 1],
16
- pickedColor: [1, 0, 0, 1],
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: WebGLBuffer = null,
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: WebGLBuffer = null,
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: WebGLBuffer = null,
67
+ elementBuffer: null,
59
68
  };
60
69
  constructor(id, options = {}) {
61
70
  this.id = id;
62
- this._options = { ...this._options, ...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._options.opacity]));
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([1, 1, 0, 1]));
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,106 @@ export class TerrainPolygonSemiPlugin {
137
164
  if (name.startsWith("private_")) {
138
165
  throw new Error(`Cannot set private uniform ${name}`);
139
166
  }
140
- if (this._options.hasOwnProperty(name)) {
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
- this._uboHandler.updateSingle(name, value);
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
- this._uboForRealEdgeArcs?.updateSingle(name, value);
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([opacity]));
161
- this._uboForRealEdgeArcs?.updateSingle("opacity", new Float32Array([opacity]));
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
+ }
165
267
  getPickedPolygon() {
166
268
  if (this._options.pickable === false) {
167
269
  throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
@@ -297,7 +399,7 @@ export class TerrainPolygonSemiPlugin {
297
399
  if (this._options.showTesselationPoints) {
298
400
  this._program.draw(this._vao, this._drawPointsRangeIndexParams, this._uboHandler);
299
401
  }
300
- if (this._pickerDisplayer) {
402
+ if (this._pickerDisplayer && this._options.pickable) {
301
403
  this._pickerDisplayer.bindFBO();
302
404
  this._pickerDisplayer.clearTextures();
303
405
  // gl.enable(gl.DEPTH_TEST);
@@ -305,7 +407,7 @@ export class TerrainPolygonSemiPlugin {
305
407
  gl.frontFace(gl.CW);
306
408
  this._program.draw(this._vao, this._drawRangeIndexParams, this._uboHandler);
307
409
  gl.frontFace(gl.CCW);
308
- if (this._pickerDisplayer) {
410
+ if (this._pickerDisplayer && this._options.pickable) {
309
411
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
310
412
  this._pickerDisplayer.drawColorTexture();
311
413
  this._selfSelect();