@pirireis/webglobeplugins 0.10.8-alpha → 0.10.10-alpha

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": "0.10.8-alpha",
3
+ "version": "0.10.10-alpha",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -122,6 +122,7 @@ export class TexturePointSampler {
122
122
  const { posIndex, callback } = pointObject;
123
123
  if (posIndex === -1 || !this._isReady || this._ratio < 0 || this._ratio > 1) {
124
124
  callback(null, null, null);
125
+ return;
125
126
  }
126
127
  const data0 = this._textures[0][posIndex];
127
128
  if (this._textureCount === 1) {
@@ -16,7 +16,7 @@ const { PingPongBufferManager, WaveParticalUboManager } = vectorfield;
16
16
  */
17
17
  const MAX_PIXELS_ON_DIMENSION = 2200;
18
18
  export default class Plugin {
19
- constructor(id, { dataWidth, dataHeight, fadeOpacity = 0.83, opacity = 0.75, minLon = -180, minLat = -90, maxLon = 180, maxLat = 90, escapeValue = -9999, patricleCount = 8000, flipY = true, drawTextureMaxPixelOnDimension = MAX_PIXELS_ON_DIMENSION } = {}) {
19
+ constructor(id, { dataWidth, dataHeight, fadeOpacity = 0.83, opacity = 0.75, minLon = -180, minLat = -90, maxLon = 180, maxLat = 90, patricleCount = 8000, flipY = true, drawTextureMaxPixelOnDimension = MAX_PIXELS_ON_DIMENSION } = {}) {
20
20
  this.id = id;
21
21
  this.globe = null;
22
22
  this.gl = null;
@@ -34,7 +34,6 @@ export default class Plugin {
34
34
  this._particleCount = patricleCount;
35
35
  this._dataWidth = dataWidth;
36
36
  this._dataHeight = dataHeight;
37
- this._escapeValue = escapeValue;
38
37
  this._drawTextureMaxPixelOnDimension = drawTextureMaxPixelOnDimension;
39
38
  this._globeshellparameters = {
40
39
  minLon,
@@ -61,25 +60,8 @@ export default class Plugin {
61
60
  this._frameBuffer = gl.createFramebuffer();
62
61
  this.setBBox(this._globeshellparameters);
63
62
  this.setOpacity(this._opacity);
64
- this.setEscapeValue(this._escapeValue);
65
63
  this.____drawIndex = 0;
66
64
  }
67
- _createDrawTexture() {
68
- const gl = this.gl;
69
- const texture = gl.createTexture();
70
- gl.bindTexture(gl.TEXTURE_2D, texture);
71
- // gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2200, 2200, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
72
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._drawTextureResolution.width, this._drawTextureResolution.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
73
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
74
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
75
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
76
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
77
- gl.bindTexture(gl.TEXTURE_2D, null);
78
- return texture;
79
- }
80
- _step() {
81
- this._stepIndex = (this._stepIndex + 1) % this._fullCycleStepCount;
82
- }
83
65
  draw3D() {
84
66
  if (this._isFreed)
85
67
  return;
@@ -132,19 +114,6 @@ export default class Plugin {
132
114
  }
133
115
  this._fullCycleStepCount = value;
134
116
  }
135
- _createRGTexture() {
136
- const { gl, _dataWidth, _dataHeight, } = this;
137
- const texture = gl.createTexture();
138
- // R32F
139
- gl.bindTexture(gl.TEXTURE_2D, texture);
140
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, _dataWidth, _dataHeight, 0, gl.RG, gl.FLOAT, null);
141
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
142
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
143
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
144
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
145
- gl.bindTexture(gl.TEXTURE_2D, null);
146
- return texture;
147
- }
148
117
  // TODO: free all resources
149
118
  free() {
150
119
  if (this._isFreed) {
@@ -196,52 +165,6 @@ export default class Plugin {
196
165
  this.waveUbo.updateSingle("drop_rate", new Float32Array([value]));
197
166
  ;
198
167
  }
199
- setEscapeValue(value) {
200
- if (typeof value !== 'number') {
201
- console.error("escape value must be a number");
202
- return;
203
- }
204
- this._escapeValue = value;
205
- this.waveUbo.updateSingle("escape_value", value);
206
- }
207
- __readAndWriteTextureData() {
208
- const { gl, _rgVectorFieldTexture, _dataWidth, _dataHeight } = this;
209
- // Step 1: Bind the texture to a framebuffer
210
- // Step 2: Read the texture data into a Float32Array
211
- gl.bindTexture(gl.TEXTURE_2D, _rgVectorFieldTexture);
212
- const textureData = new Float32Array(_dataWidth * _dataHeight * 2); // RG32F has 2 components per pixel
213
- gl.readPixels(0, 0, _dataWidth, _dataHeight, gl.RG, gl.FLOAT, textureData);
214
- gl.bindTexture(gl.TEXTURE_2D, null);
215
- // Step 3: Create a new texture and write the data back
216
- // Step 4: Clean up
217
- gl.deleteTexture(this._rgVectorFieldTexture);
218
- // Replace the old texture with the new one
219
- this._rgVectorFieldTexture = this._createRGTexture();
220
- this.setVectorFieldData(textureData);
221
- }
222
- _drawTextureSizeFromBbox({ minLon, minLat, maxLon, maxLat }) {
223
- let horizon;
224
- if (minLon > 0 && maxLon < 0) {
225
- horizon = 360 - minLon + maxLon;
226
- }
227
- else {
228
- horizon = maxLon - minLon;
229
- }
230
- const vertical = maxLat - minLat;
231
- let width, height;
232
- if (horizon > vertical) {
233
- width = this._drawTextureMaxPixelOnDimension;
234
- height = Math.floor(this._drawTextureMaxPixelOnDimension * vertical / horizon);
235
- }
236
- else {
237
- height = this._drawTextureMaxPixelOnDimension;
238
- width = Math.floor(this._drawTextureMaxPixelOnDimension * horizon / vertical);
239
- }
240
- return {
241
- width,
242
- height
243
- };
244
- }
245
168
  setDrawTextureMaxPixelOnDimension(value) {
246
169
  this._drawTextureMaxPixelOnDimension = value;
247
170
  this._drawTextureResolution = this._drawTextureSizeFromBbox(this._globeshellparameters);
@@ -273,13 +196,14 @@ export default class Plugin {
273
196
  this.globeShellWiggle.setOpacity(value);
274
197
  }
275
198
  setParticleDimensions(tail, wing) {
276
- if (0 < tail || 0 < wing) {
277
- console.error("tail and wing must be greater than 0");
278
- }
279
- else {
199
+ if (0 < tail && 0 < wing) {
280
200
  this.waveUbo.updateSingle("tail_wing_base_limp", new Float32Array([tail, wing]));
281
201
  ;
282
202
  }
203
+ else {
204
+ console.error("tail and wing must be positive numbers");
205
+ return;
206
+ }
283
207
  }
284
208
  setParticleColor(color) {
285
209
  if (color.length !== 3) {
@@ -296,4 +220,71 @@ export default class Plugin {
296
220
  this.waveUbo.updateSingle("draw_texture_size", new Float32Array([this._drawTextureResolution.width, this._drawTextureResolution.height]));
297
221
  this._drawTextures = [this._createDrawTexture(), this._createDrawTexture()];
298
222
  }
223
+ __readAndWriteTextureData() {
224
+ const { gl, _rgVectorFieldTexture, _dataWidth, _dataHeight } = this;
225
+ // Step 1: Bind the texture to a framebuffer
226
+ // Step 2: Read the texture data into a Float32Array
227
+ gl.bindTexture(gl.TEXTURE_2D, _rgVectorFieldTexture);
228
+ const textureData = new Float32Array(_dataWidth * _dataHeight * 2); // RG32F has 2 components per pixel
229
+ gl.readPixels(0, 0, _dataWidth, _dataHeight, gl.RG, gl.FLOAT, textureData);
230
+ gl.bindTexture(gl.TEXTURE_2D, null);
231
+ // Step 3: Create a new texture and write the data back
232
+ // Step 4: Clean up
233
+ gl.deleteTexture(this._rgVectorFieldTexture);
234
+ // Replace the old texture with the new one
235
+ this._rgVectorFieldTexture = this._createRGTexture();
236
+ this.setVectorFieldData(textureData);
237
+ }
238
+ _drawTextureSizeFromBbox({ minLon, minLat, maxLon, maxLat }) {
239
+ let horizon;
240
+ if (minLon > 0 && maxLon < 0) {
241
+ horizon = 360 - minLon + maxLon;
242
+ }
243
+ else {
244
+ horizon = maxLon - minLon;
245
+ }
246
+ const vertical = maxLat - minLat;
247
+ let width, height;
248
+ if (horizon > vertical) {
249
+ width = this._drawTextureMaxPixelOnDimension;
250
+ height = Math.floor(this._drawTextureMaxPixelOnDimension * vertical / horizon);
251
+ }
252
+ else {
253
+ height = this._drawTextureMaxPixelOnDimension;
254
+ width = Math.floor(this._drawTextureMaxPixelOnDimension * horizon / vertical);
255
+ }
256
+ return {
257
+ width,
258
+ height
259
+ };
260
+ }
261
+ _createRGTexture() {
262
+ const { gl, _dataWidth, _dataHeight, } = this;
263
+ const texture = gl.createTexture();
264
+ // R32F
265
+ gl.bindTexture(gl.TEXTURE_2D, texture);
266
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, _dataWidth, _dataHeight, 0, gl.RG, gl.FLOAT, null);
267
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
268
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
269
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
270
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
271
+ gl.bindTexture(gl.TEXTURE_2D, null);
272
+ return texture;
273
+ }
274
+ _createDrawTexture() {
275
+ const gl = this.gl;
276
+ const texture = gl.createTexture();
277
+ gl.bindTexture(gl.TEXTURE_2D, texture);
278
+ // gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2200, 2200, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
279
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._drawTextureResolution.width, this._drawTextureResolution.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
280
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
281
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
282
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
283
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
284
+ gl.bindTexture(gl.TEXTURE_2D, null);
285
+ return texture;
286
+ }
287
+ _step() {
288
+ this._stepIndex = (this._stepIndex + 1) % this._fullCycleStepCount;
289
+ }
299
290
  }