@pirireis/webglobeplugins 0.10.8-alpha → 0.10.9-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.9-alpha",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -64,22 +64,6 @@ export default class Plugin {
64
64
  this.setEscapeValue(this._escapeValue);
65
65
  this.____drawIndex = 0;
66
66
  }
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
67
  draw3D() {
84
68
  if (this._isFreed)
85
69
  return;
@@ -132,19 +116,6 @@ export default class Plugin {
132
116
  }
133
117
  this._fullCycleStepCount = value;
134
118
  }
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
119
  // TODO: free all resources
149
120
  free() {
150
121
  if (this._isFreed) {
@@ -204,44 +175,6 @@ export default class Plugin {
204
175
  this._escapeValue = value;
205
176
  this.waveUbo.updateSingle("escape_value", value);
206
177
  }
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
178
  setDrawTextureMaxPixelOnDimension(value) {
246
179
  this._drawTextureMaxPixelOnDimension = value;
247
180
  this._drawTextureResolution = this._drawTextureSizeFromBbox(this._globeshellparameters);
@@ -273,13 +206,14 @@ export default class Plugin {
273
206
  this.globeShellWiggle.setOpacity(value);
274
207
  }
275
208
  setParticleDimensions(tail, wing) {
276
- if (0 < tail || 0 < wing) {
277
- console.error("tail and wing must be greater than 0");
278
- }
279
- else {
209
+ if (0 < tail && 0 < wing) {
280
210
  this.waveUbo.updateSingle("tail_wing_base_limp", new Float32Array([tail, wing]));
281
211
  ;
282
212
  }
213
+ else {
214
+ console.error("tail and wing must be positive numbers");
215
+ return;
216
+ }
283
217
  }
284
218
  setParticleColor(color) {
285
219
  if (color.length !== 3) {
@@ -296,4 +230,71 @@ export default class Plugin {
296
230
  this.waveUbo.updateSingle("draw_texture_size", new Float32Array([this._drawTextureResolution.width, this._drawTextureResolution.height]));
297
231
  this._drawTextures = [this._createDrawTexture(), this._createDrawTexture()];
298
232
  }
233
+ __readAndWriteTextureData() {
234
+ const { gl, _rgVectorFieldTexture, _dataWidth, _dataHeight } = this;
235
+ // Step 1: Bind the texture to a framebuffer
236
+ // Step 2: Read the texture data into a Float32Array
237
+ gl.bindTexture(gl.TEXTURE_2D, _rgVectorFieldTexture);
238
+ const textureData = new Float32Array(_dataWidth * _dataHeight * 2); // RG32F has 2 components per pixel
239
+ gl.readPixels(0, 0, _dataWidth, _dataHeight, gl.RG, gl.FLOAT, textureData);
240
+ gl.bindTexture(gl.TEXTURE_2D, null);
241
+ // Step 3: Create a new texture and write the data back
242
+ // Step 4: Clean up
243
+ gl.deleteTexture(this._rgVectorFieldTexture);
244
+ // Replace the old texture with the new one
245
+ this._rgVectorFieldTexture = this._createRGTexture();
246
+ this.setVectorFieldData(textureData);
247
+ }
248
+ _drawTextureSizeFromBbox({ minLon, minLat, maxLon, maxLat }) {
249
+ let horizon;
250
+ if (minLon > 0 && maxLon < 0) {
251
+ horizon = 360 - minLon + maxLon;
252
+ }
253
+ else {
254
+ horizon = maxLon - minLon;
255
+ }
256
+ const vertical = maxLat - minLat;
257
+ let width, height;
258
+ if (horizon > vertical) {
259
+ width = this._drawTextureMaxPixelOnDimension;
260
+ height = Math.floor(this._drawTextureMaxPixelOnDimension * vertical / horizon);
261
+ }
262
+ else {
263
+ height = this._drawTextureMaxPixelOnDimension;
264
+ width = Math.floor(this._drawTextureMaxPixelOnDimension * horizon / vertical);
265
+ }
266
+ return {
267
+ width,
268
+ height
269
+ };
270
+ }
271
+ _createRGTexture() {
272
+ const { gl, _dataWidth, _dataHeight, } = this;
273
+ const texture = gl.createTexture();
274
+ // R32F
275
+ gl.bindTexture(gl.TEXTURE_2D, texture);
276
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, _dataWidth, _dataHeight, 0, gl.RG, gl.FLOAT, null);
277
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
278
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
279
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
280
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
281
+ gl.bindTexture(gl.TEXTURE_2D, null);
282
+ return texture;
283
+ }
284
+ _createDrawTexture() {
285
+ const gl = this.gl;
286
+ const texture = gl.createTexture();
287
+ gl.bindTexture(gl.TEXTURE_2D, texture);
288
+ // gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2200, 2200, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
289
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this._drawTextureResolution.width, this._drawTextureResolution.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
290
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
291
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
292
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
293
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
294
+ gl.bindTexture(gl.TEXTURE_2D, null);
295
+ return texture;
296
+ }
297
+ _step() {
298
+ this._stepIndex = (this._stepIndex + 1) % this._fullCycleStepCount;
299
+ }
299
300
  }