@pirireis/webglobeplugins 1.5.5 → 1.6.1

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.5.5",
3
+ "version": "1.6.1",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -15,4 +15,4 @@
15
15
  "peerDependencies": {
16
16
  "@pirireis/webglobe": "6.2.51^"
17
17
  }
18
- }
18
+ }
@@ -263,7 +263,6 @@ export class ArcOnTerrainPlugin {
263
263
  indexes: null
264
264
  };
265
265
  program.draw(_attributeLoader, drawOptions, this._opacity, _arcUBOHandler);
266
- console.log("draw3d arc");
267
266
  gl.enable(gl.DEPTH_TEST);
268
267
  }
269
268
  _buildArcs(subSetIDs = null) {
@@ -69,6 +69,10 @@ export default class Plugin {
69
69
  _ableToUseSpeedField = false;
70
70
  _initialSpeedFieldData = null;
71
71
  __adaptiveOpacity = 1;
72
+ // Holds the framebuffer the globe was rendering into when draw3D was called.
73
+ // The globe may render to its own FBO (e.g. for depth-buffered 3D mode), so the
74
+ // plugin must restore it instead of forcing the default framebuffer (null).
75
+ _prevFBO = null;
72
76
  constructor(id, options) {
73
77
  this.id = id;
74
78
  this.options = { ...this.options, ...options };
@@ -116,7 +120,6 @@ export default class Plugin {
116
120
  }
117
121
  if (this.options.useSpeedTexture) {
118
122
  this.waveUbo.updateSingle("use_magnitude_field", new Float32Array([1]));
119
- console.log("use speed texture");
120
123
  if (this._initialSpeedFieldData) {
121
124
  this.setSpeedField(this._initialSpeedFieldData);
122
125
  this._initialSpeedFieldData = null;
@@ -142,9 +145,13 @@ export default class Plugin {
142
145
  draw3D() {
143
146
  if (this._isFreed)
144
147
  return;
145
- const { gl, moveParticle, drawParticle, bufferManager, globeShellWiggle, waveUbo, fadeAway, _rgVectorFieldTexture } = this;
148
+ const { gl, moveParticle, drawParticle, bufferManager, globeShellWiggle, waveUbo, fadeAway, _rgVectorFieldTexture, globe } = this;
146
149
  if (!gl || !bufferManager || !globeShellWiggle || !waveUbo || !fadeAway || !_rgVectorFieldTexture)
147
150
  return;
151
+ // Save the framebuffer the globe is currently rendering into and restore it
152
+ // when we are done. The globe may render to its own FBO (3D depth-buffered
153
+ // mode), so we must not force the default framebuffer (null).
154
+ this._prevFBO = gl.getParameter(gl.FRAMEBUFFER_BINDING);
148
155
  gl.disable(gl.DEPTH_TEST);
149
156
  switch (this._stepIndex) {
150
157
  case 0:
@@ -158,8 +165,8 @@ export default class Plugin {
158
165
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
159
166
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._drawTextures[this.____drawIndex], 0);
160
167
  drawParticle.draw(bufferManager, _rgVectorFieldTexture, waveUbo, this._colorFieldTexture, this._speedFieldTexture);
161
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
162
- gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
168
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._prevFBO);
169
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
163
170
  break;
164
171
  case 2:
165
172
  gl.viewport(0, 0, this._drawTextureResolution.width, this._drawTextureResolution.height);
@@ -168,15 +175,17 @@ export default class Plugin {
168
175
  gl.blendFunc(gl.ONE, gl.ZERO);
169
176
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._drawTextures[1 - this.____drawIndex], 0);
170
177
  fadeAway.draw(this._drawTextures[this.____drawIndex], this.options.fadeOpacity);
171
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
178
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._prevFBO);
172
179
  defaultblendfunction(gl);
173
- gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
180
+ gl.viewport(0, 0, globe.api_ScrW(), globe.api_ScrH());
174
181
  break;
175
182
  }
176
183
  globeShellWiggle.setTexture(this._drawTextures[this.____drawIndex]);
177
184
  globeShellWiggle.draw();
178
185
  this._step();
179
186
  gl.enable(gl.DEPTH_TEST);
187
+ // Restore the globe's framebuffer in case any internal step changed it.
188
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._prevFBO);
180
189
  }
181
190
  setCycleStepCount(value) {
182
191
  if (value < 3) {
@@ -339,7 +348,6 @@ export default class Plugin {
339
348
  console.error("Speed field data length does not match the specified dataWidth and dataHeight.");
340
349
  return;
341
350
  }
342
- console.log(data);
343
351
  gl.bindTexture(gl.TEXTURE_2D, this._speedFieldTexture);
344
352
  gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this.options.flipY);
345
353
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, this.options.dataWidth, this.options.dataHeight, 0, gl.RED, gl.FLOAT, data);
@@ -357,7 +365,6 @@ export default class Plugin {
357
365
  this.waveUbo?.updateSingle("min_magnitude_threshold", new Float32Array([value]));
358
366
  }
359
367
  setMaxSpeedThreshold(value) {
360
- console.log("setMaxSpeedThreshold called with value:", value);
361
368
  this.options.maxSpeedThreshold = value;
362
369
  this.waveUbo?.updateSingle("max_magnitude_threshold", new Float32Array([value]));
363
370
  }
@@ -425,7 +425,6 @@ export default class WindPlugin {
425
425
  const { uMax, uMin, vMax, vMin } = this.windData;
426
426
  const maxSpeed = Math.sqrt(uMax * uMax + vMax * vMax);
427
427
  const minSpeed = Math.sqrt(uMin * uMin + vMin * vMin);
428
- // console.log("maxSpeed", maxSpeed, "minSpeed", minSpeed);
429
428
  this._rampMax = maxSpeed > minSpeed ? maxSpeed : minSpeed;
430
429
  this._loadRampMax();
431
430
  this.setColorRamp(defaultRampColors);
@@ -482,7 +481,6 @@ export default class WindPlugin {
482
481
  gl.useProgram(this.drawFlatProgram.program);
483
482
  gl.uniform1f(this.drawFlatProgram.u_particles_res, this.particleStateResolution);
484
483
  gl.useProgram(currentProgram);
485
- // console.log("numParticles", this._numParticles);
486
484
  const particleIndices = new Float32Array(this._numParticles);
487
485
  for (let i = 0; i < this._numParticles; i++)
488
486
  particleIndices[i] = i;
@@ -596,7 +594,6 @@ export default class WindPlugin {
596
594
  };
597
595
  }
598
596
  _loadBoundingBoxData(minX, minY, maxX, maxY) {
599
- // console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY)
600
597
  const gl = this.gl;
601
598
  const bboxMatrix = new Float32Array([
602
599
  maxX - minX, 0, 0,
@@ -703,7 +700,6 @@ export default class WindPlugin {
703
700
  _loadRampMax() {
704
701
  const { gl } = this;
705
702
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
706
- // console.log("load ramp max", this._rampMax);
707
703
  gl.useProgram(this.drawSphereProgram.program);
708
704
  gl.uniform1f(this.drawSphereProgram.u_color_ramp_max, this._rampMax);
709
705
  gl.useProgram(this.drawFlatProgram.program);
@@ -894,7 +890,6 @@ export default class WindPlugin {
894
890
  }
895
891
  // globe plugin init methodu
896
892
  init(globe, gl) {
897
- // console.log("init wind plugin")
898
893
  this.globe = globe;
899
894
  this.gl = gl;
900
895
  this.drawSphereProgram = createProgramWrapper(gl, drawSphereVert, drawFrag);