@pirireis/webglobeplugins 1.1.18 → 1.1.20

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.
@@ -288,17 +288,17 @@ export function partialTessellation(triangleMeta, limits, innerCuts, calculateRe
288
288
  */
289
289
  const _f32 = /*@__PURE__*/ new Float32Array(1);
290
290
  const _u32 = /*@__PURE__*/ new Uint32Array(_f32.buffer);
291
- const float32Bits = (n) => {
292
- _f32[0] = n;
293
- return _u32[0];
294
- };
291
+ // const float32Bits = (n: number): number => {
292
+ // _f32[0] = n;
293
+ // return _u32[0];
294
+ // };
295
295
  const addPoint = (longLat, vec3, edgeIndex) => {
296
296
  const xy = radianToMercatorXY(longLat);
297
297
  const x = Math.fround(xy[0]);
298
298
  const y = Math.fround(xy[1]);
299
299
  // Use float32 bit patterns for an exact, stable key.
300
- // const key = `${xy[0].toFixed(12)},${xy[1].toFixed(12)}`;
301
- const key = `${float32Bits(x)},${float32Bits(y)}`;
300
+ const key = `${xy[0].toFixed(8)},${xy[1].toFixed(8)}`;
301
+ // const key = `${float32Bits(x)},${float32Bits(y)}`;
302
302
  let index = pointMap.get(key);
303
303
  if (index !== undefined) {
304
304
  if (edgeIndex !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -18,12 +18,13 @@ const uniformBindingPoints = {
18
18
  export const IndexAttributeEscapeValue = -1;
19
19
  const styleBlockManager = new UniformBlockManager('Style', [
20
20
  { name: "defaultColor", type: "vec4", value: new Float32Array([0.0, 0.0, 0.0, 0.0]) },
21
- { name: "pickedColor", type: "vec4", value: new Float32Array([0, 0, 0, 0]) },
21
+ { name: "hoverColor", type: "vec4", value: new Float32Array([0, 0, 0, 0]) },
22
22
  { name: "u_pointSize", type: "float", value: new Float32Array([6.0]) },
23
23
  { name: "opacity", type: "float", value: new Float32Array([1.0]) },
24
- { name: "private_isPickedOn", type: "bool", value: new Float32Array([0]) },
25
24
  { name: "private_pickedIndex", type: "uint", value: new Uint32Array([0]) },
25
+ { name: "private_isPickedOn", type: "bool", value: new Float32Array([0]) },
26
26
  { name: "useDefaultColor", type: "bool", value: new Float32Array([0]) },
27
+ { name: "private_changeHoverColor", type: "bool", value: new Float32Array([1]) },
27
28
  ], uniformBindingPoints.style);
28
29
  const vertexShaderSource = `#version 300 es
29
30
  #pragma vscode_glsllint_stage : vert
@@ -91,8 +92,8 @@ void main() {
91
92
  }
92
93
 
93
94
  if (private_isPickedOn == true){
94
- if (a_index == private_pickedIndex) {
95
- v_color = pickedColor;
95
+ if (a_index == private_pickedIndex && private_changeHoverColor == true ) {
96
+ v_color = hoverColor;
96
97
  }
97
98
  v_index = a_index;
98
99
  }
@@ -15,13 +15,15 @@ export class TerrainPolygonSemiPlugin {
15
15
  variativeColorsOn: false,
16
16
  polygonStyle: {
17
17
  defaultColor: [0.5, 0.5, 1, 1],
18
- pickedColor: [1, 0, 0, 1],
18
+ changeColorOnHover: true,
19
+ hoverColor: [1, 0, 0, 1],
19
20
  opacity: 1.0,
20
21
  useDefaultColor: false,
21
22
  },
22
23
  edgeStyle: {
23
24
  defaultColor: [1, 1, 0, 1],
24
- pickedColor: [1, 0, 0, 1],
25
+ hoverColor: [1, 0, 0, 1],
26
+ changeColorOnHover: true,
25
27
  opacity: 1.0,
26
28
  useDefaultColor: true,
27
29
  },
@@ -112,7 +114,8 @@ export class TerrainPolygonSemiPlugin {
112
114
  this._pickIndexBuffer = gl.createBuffer();
113
115
  this._pickerDisplayer = new PickerDisplayer(this.globe, "R16UI");
114
116
  this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
115
- this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
117
+ this._uboHandler.updateSingle("hoverColor", new Float32Array(this._options.polygonStyle.hoverColor));
118
+ this._uboHandler.updateSingle("private_changeHoverColor", new Float32Array([this._options.polygonStyle.changeColorOnHover ? 1 : 0]));
116
119
  }
117
120
  else {
118
121
  this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([0.0]));
@@ -123,6 +126,7 @@ export class TerrainPolygonSemiPlugin {
123
126
  this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([1]));
124
127
  this._uboForRealEdgeArcs.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
125
128
  this._uboForRealEdgeArcs.updateSingle("private_isPickedOn", new Float32Array([0.0]));
129
+ this._uboForRealEdgeArcs.updateSingle("private_changeHoverColor", new Float32Array([this._options.edgeStyle.changeColorOnHover ? 1 : 0]));
126
130
  this._drawRealEdgeArcs.elementBuffer = gl.createBuffer();
127
131
  }
128
132
  if (this._options.variativeColorsOn) {
@@ -175,32 +179,22 @@ export class TerrainPolygonSemiPlugin {
175
179
  if (name.startsWith("private_")) {
176
180
  throw new Error(`Cannot set private uniform ${name}`);
177
181
  }
178
- const isStyleKey = name === "defaultColor" || name === "pickedColor" || name === "opacity" || name === "useDefaultColor";
179
- let targetUBO;
180
- if (target === "polygon") {
181
- targetUBO = this._uboHandler;
182
- }
183
- else if (target === "edgeArc") {
184
- targetUBO = this._uboForRealEdgeArcs;
185
- }
186
- else {
187
- console.warn(`Unknown target ${target} for setUniform, must be "polygon" or "edgeArc"`);
188
- return;
189
- }
182
+ const isStyleKey = name === "defaultColor" || name === "hoverColor" || name === "opacity" || name === "useDefaultColor";
183
+ const ubo = this.__getUBO(target);
190
184
  if (isStyleKey) {
191
185
  const prev = this._options.polygonStyle[name];
192
186
  if (prev === value)
193
187
  return;
194
188
  this._options.polygonStyle[name] = value;
195
189
  if (name === "opacity") {
196
- targetUBO.updateSingle("opacity", this._effectiveOpacity(target));
190
+ ubo.updateSingle("opacity", this._effectiveOpacity(target));
197
191
  }
198
192
  else {
199
- targetUBO.updateSingle(name, value);
193
+ ubo.updateSingle(name, value);
200
194
  }
201
195
  }
202
196
  else {
203
- targetUBO.updateSingle(name, value);
197
+ ubo.updateSingle(name, value);
204
198
  }
205
199
  this.globe.DrawRender();
206
200
  }
@@ -212,7 +206,7 @@ export class TerrainPolygonSemiPlugin {
212
206
  this._uboForRealEdgeArcs = this._program.createUBO();
213
207
  this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
214
208
  this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([this._options.edgeStyle.useDefaultColor ? 1 : 0]));
215
- this._uboForRealEdgeArcs.updateSingle("pickedColor", new Float32Array(this._options.edgeStyle.pickedColor));
209
+ this._uboForRealEdgeArcs.updateSingle("hoverColor", new Float32Array(this._options.edgeStyle.hoverColor));
216
210
  this._uboForRealEdgeArcs.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
217
211
  this._drawRealEdgeArcs.elementBuffer = this.globe.gl.createBuffer();
218
212
  }
@@ -226,6 +220,15 @@ export class TerrainPolygonSemiPlugin {
226
220
  this._options.drawEdges = state;
227
221
  this.globe.DrawRender();
228
222
  }
223
+ setUsePickedColorState(state, target = "polygon") {
224
+ const oldState = this._options[`${target}Style`].changePickedColor;
225
+ if (oldState === state)
226
+ return;
227
+ this._options[`${target}Style`].changePickedColor = state;
228
+ const ubo = this.__getUBO(target);
229
+ ubo.updateSingle("private_changeHoverColor", new Float32Array([state ? 1 : 0]));
230
+ this.globe.DrawRender();
231
+ }
229
232
  setOpacity(opacity) {
230
233
  if (this._options.opacity !== opacity) {
231
234
  this._options.opacity = opacity;
@@ -234,6 +237,15 @@ export class TerrainPolygonSemiPlugin {
234
237
  this.globe.DrawRender();
235
238
  }
236
239
  }
240
+ setChangeColorOnHoverState(state, target = "polygon") {
241
+ const oldState = this._options[`${target}Style`].changeHoverColor;
242
+ if (oldState === state)
243
+ return;
244
+ this._options[`${target}Style`].changeHoverColor = state;
245
+ const ubo = this.__getUBO(target);
246
+ ubo.updateSingle("private_changeHoverColor", new Float32Array([state ? 1 : 0]));
247
+ this.globe.DrawRender();
248
+ }
237
249
  setPausePickableState(state) {
238
250
  if (this._options.pickable === false) {
239
251
  throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
@@ -254,7 +266,7 @@ export class TerrainPolygonSemiPlugin {
254
266
  if (oldState === false && state === true) {
255
267
  this._pickIndexBuffer = this.globe.gl.createBuffer();
256
268
  this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
257
- this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
269
+ this._uboHandler.updateSingle("hoverColor", new Float32Array(this._options.polygonStyle.hoverColor));
258
270
  this._pickerDisplayer = new PickerDisplayer(this.globe, "R32I");
259
271
  }
260
272
  else if (oldState === true && state === false) {
@@ -418,6 +430,19 @@ export class TerrainPolygonSemiPlugin {
418
430
  this.insertBulk(TestRecords.get(recordName));
419
431
  }
420
432
  }
433
+ __getUBO(target = "polygon") {
434
+ let targetUBO;
435
+ if (target === "polygon") {
436
+ targetUBO = this._uboHandler;
437
+ }
438
+ else if (target === "edgeArc") {
439
+ targetUBO = this._uboForRealEdgeArcs;
440
+ }
441
+ else {
442
+ throw new Error(`unknown target ${target} for __getUBO, must be "polygon" or "edgeArc"`);
443
+ }
444
+ return targetUBO;
445
+ }
421
446
  }
422
447
  function inputCheck(input) {
423
448
  if (!input.geometry || !Array.isArray(input.geometry) || input.geometry.length === 0) {
@@ -94,10 +94,9 @@ const setConstantAttribute = (gl, index, size, values, typeInfo) => {
94
94
  gl.vertexAttrib4f(index, v[0], v[1], v[2], v[3]);
95
95
  };
96
96
  function resetAttributeDefault(gl, index) {
97
- gl.vertexAttrib4f(index, 1, 0, 0, 1);
97
+ gl.vertexAttrib4f(index, 0, 0, 0, 1);
98
98
  }
99
99
  function setDefaultAttributeValues(gl, index, size, escapeValues, typeInfo) {
100
- // gl.disableVertexAttribArray(index);
101
100
  setConstantAttribute(gl, index, size, escapeValues, DATA_TYPE_MAP[typeInfo]);
102
101
  }
103
102
  export { attributeLoader, createBufferAndReadInfo, resetAttributeDefault, setDefaultAttributeValues };