@pirireis/webglobeplugins 1.1.12 → 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
|
@@ -11,16 +11,19 @@ export class TerrainPolygonSemiPlugin {
|
|
|
11
11
|
_options = {
|
|
12
12
|
drawEdges: true,
|
|
13
13
|
pickable: false,
|
|
14
|
+
pickablePause: false,
|
|
14
15
|
variativeColorsOn: false,
|
|
15
16
|
polygonStyle: {
|
|
16
17
|
defaultColor: [0.5, 0.5, 1, 1],
|
|
17
18
|
pickedColor: [1, 0, 0, 1],
|
|
18
19
|
opacity: 1.0,
|
|
20
|
+
useDefaultColor: false,
|
|
19
21
|
},
|
|
20
22
|
edgeStyle: {
|
|
21
23
|
defaultColor: [1, 1, 0, 1],
|
|
22
24
|
pickedColor: [1, 0, 0, 1],
|
|
23
25
|
opacity: 1.0,
|
|
26
|
+
useDefaultColor: true,
|
|
24
27
|
},
|
|
25
28
|
// Global opacity multiplier applied on top of style opacities
|
|
26
29
|
opacity: 1.0,
|
|
@@ -83,11 +86,16 @@ export class TerrainPolygonSemiPlugin {
|
|
|
83
86
|
console.log("TerrainPolygonSemiPlugin options:", this._options);
|
|
84
87
|
}
|
|
85
88
|
;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
}
|
|
91
99
|
}
|
|
92
100
|
init(globe, gl) {
|
|
93
101
|
this.globe = globe;
|
|
@@ -98,7 +106,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
98
106
|
this._vec3Buffer = gl.createBuffer();
|
|
99
107
|
this._mercatorXYBuffer = gl.createBuffer();
|
|
100
108
|
this._uboHandler = this._program.createUBO();
|
|
101
|
-
this._uboHandler.updateSingle("opacity",
|
|
109
|
+
this._uboHandler.updateSingle("opacity", this._effectiveOpacity("polygon"));
|
|
102
110
|
this._uboHandler.updateSingle("defaultColor", new Float32Array(this._options.polygonStyle.defaultColor));
|
|
103
111
|
if (this._options.pickable) {
|
|
104
112
|
this._pickIndexBuffer = gl.createBuffer();
|
|
@@ -110,7 +118,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
110
118
|
this._uboForRealEdgeArcs = this._program.createUBO();
|
|
111
119
|
this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
|
|
112
120
|
this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([1]));
|
|
113
|
-
this._uboForRealEdgeArcs.updateSingle("opacity",
|
|
121
|
+
this._uboForRealEdgeArcs.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
|
|
114
122
|
this._drawRealEdgeArcs.elementBuffer = gl.createBuffer();
|
|
115
123
|
}
|
|
116
124
|
if (this._options.variativeColorsOn) {
|
|
@@ -164,64 +172,45 @@ export class TerrainPolygonSemiPlugin {
|
|
|
164
172
|
if (name.startsWith("private_")) {
|
|
165
173
|
throw new Error(`Cannot set private uniform ${name}`);
|
|
166
174
|
}
|
|
167
|
-
const isStyleKey = name === "defaultColor" || name === "pickedColor" || name === "opacity";
|
|
175
|
+
const isStyleKey = name === "defaultColor" || name === "pickedColor" || name === "opacity" || name === "useDefaultColor";
|
|
176
|
+
let targetUBO;
|
|
168
177
|
if (target === "polygon") {
|
|
169
|
-
|
|
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
|
-
}
|
|
178
|
+
targetUBO = this._uboHandler;
|
|
184
179
|
}
|
|
185
180
|
else if (target === "edgeArc") {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
181
|
+
targetUBO = this._uboForRealEdgeArcs;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
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));
|
|
197
194
|
}
|
|
198
195
|
else {
|
|
199
|
-
|
|
196
|
+
targetUBO.updateSingle(name, value);
|
|
200
197
|
}
|
|
201
198
|
}
|
|
202
199
|
else {
|
|
203
|
-
|
|
200
|
+
targetUBO.updateSingle(name, value);
|
|
204
201
|
}
|
|
205
202
|
this.globe.DrawRender();
|
|
206
203
|
}
|
|
207
|
-
setDrawEdgesState(state
|
|
204
|
+
setDrawEdgesState(state) {
|
|
208
205
|
const oldState = this._options.drawEdges;
|
|
209
206
|
if (oldState === state)
|
|
210
207
|
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
208
|
if (oldState === false && state === true) {
|
|
221
209
|
this._uboForRealEdgeArcs = this._program.createUBO();
|
|
222
210
|
this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
|
|
223
|
-
this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([1]));
|
|
224
|
-
this._uboForRealEdgeArcs.updateSingle("
|
|
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"));
|
|
225
214
|
this._drawRealEdgeArcs.elementBuffer = this.globe.gl.createBuffer();
|
|
226
215
|
}
|
|
227
216
|
else if (oldState === true && state === false) {
|
|
@@ -237,28 +226,42 @@ export class TerrainPolygonSemiPlugin {
|
|
|
237
226
|
setOpacity(opacity) {
|
|
238
227
|
if (this._options.opacity !== opacity) {
|
|
239
228
|
this._options.opacity = opacity;
|
|
240
|
-
this._uboHandler.updateSingle("opacity",
|
|
241
|
-
this._uboForRealEdgeArcs?.updateSingle("opacity",
|
|
229
|
+
this._uboHandler.updateSingle("opacity", this._effectiveOpacity("polygon"));
|
|
230
|
+
this._uboForRealEdgeArcs?.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
|
|
242
231
|
this.globe.DrawRender();
|
|
243
232
|
}
|
|
244
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
|
+
}
|
|
245
246
|
setPickableState(state) {
|
|
247
|
+
throw new Error("setPickableState is buggy. use setPausePickableState instead.");
|
|
246
248
|
const oldState = this._options.pickable;
|
|
247
249
|
if (oldState === state)
|
|
248
250
|
return;
|
|
249
251
|
if (oldState === false && state === true) {
|
|
250
|
-
|
|
252
|
+
this._pickIndexBuffer = this.globe.gl.createBuffer();
|
|
251
253
|
this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
|
|
252
254
|
this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
|
|
253
|
-
|
|
255
|
+
this._pickerDisplayer = new PickerDisplayer(this.globe, "R32I");
|
|
254
256
|
}
|
|
255
257
|
else if (oldState === true && state === false) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
+
this.globe.gl.deleteBuffer(this._pickIndexBuffer);
|
|
259
|
+
this._pickIndexBuffer = null;
|
|
258
260
|
this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([0.0]));
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
261
|
+
this._uboHandler.updateSingle("private_pickedIndex", new Float32Array([-1]));
|
|
262
|
+
this._pickerDisplayer?.free();
|
|
263
|
+
this._pickerDisplayer = null;
|
|
264
|
+
this._lastPickedPolygon = null;
|
|
262
265
|
}
|
|
263
266
|
this._options.pickable = state;
|
|
264
267
|
this._workerContact.setPickableState(state);
|
|
@@ -399,7 +402,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
399
402
|
if (this._options.showTesselationPoints) {
|
|
400
403
|
this._program.draw(this._vao, this._drawPointsRangeIndexParams, this._uboHandler);
|
|
401
404
|
}
|
|
402
|
-
if (this._pickerDisplayer && this._options.
|
|
405
|
+
if (this._pickerDisplayer && !this._options.pickablePause) {
|
|
403
406
|
this._pickerDisplayer.bindFBO();
|
|
404
407
|
this._pickerDisplayer.clearTextures();
|
|
405
408
|
// gl.enable(gl.DEPTH_TEST);
|
|
@@ -407,7 +410,7 @@ export class TerrainPolygonSemiPlugin {
|
|
|
407
410
|
gl.frontFace(gl.CW);
|
|
408
411
|
this._program.draw(this._vao, this._drawRangeIndexParams, this._uboHandler);
|
|
409
412
|
gl.frontFace(gl.CCW);
|
|
410
|
-
if (this._pickerDisplayer && this._options.
|
|
413
|
+
if (this._pickerDisplayer && !this._options.pickablePause) {
|
|
411
414
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
412
415
|
this._pickerDisplayer.drawColorTexture();
|
|
413
416
|
this._selfSelect();
|