@pirireis/webglobeplugins 0.9.14 → 0.9.15

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.9.14",
3
+ "version": "0.9.15",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
package/programs/index.js CHANGED
@@ -3,7 +3,7 @@ import { GlobeShellWiggle } from "./globeshell/wiggle";
3
3
  import { CameraUniformBlockTotem, CameraUniformBlockString } from "./totems/index";
4
4
  import ArrowField from "./arrowfield";
5
5
  import { glProgramCache, globeProgramCache, noRegisterGlobeProgramCache } from "./programcache";
6
- import * as vectorfield from "./vectorfields";
6
+ import * as vectorfield from "./vectorfields/index";
7
7
  import { FadeAway } from "./helpers";
8
8
  import * as rings from "./rings";
9
9
  export { Float2LegendWithRatio, GlobeShellWiggle, ArrowField, CameraUniformBlockTotem, CameraUniformBlockString, glProgramCache, globeProgramCache, noRegisterGlobeProgramCache, vectorfield, FadeAway, rings };
@@ -88,17 +88,11 @@ class Logic {
88
88
  this.program = null;
89
89
  }
90
90
  }
91
- export default class {
92
- constructor(gl) {
93
- this.gl = gl;
94
- this.logic = glProgramCache.getProgram(gl, Logic);
95
- }
96
- draw(bufferManager, vectorTexture, uboManager) {
97
- this.logic.draw(bufferManager, vectorTexture, uboManager);
91
+ export const drawRectangleParticlesProgramCache = Object.freeze({
92
+ getProgram: (gl) => {
93
+ return glProgramCache.getProgram(gl, Logic);
94
+ },
95
+ releaseProgram: (gl) => {
96
+ glProgramCache.releaseProgram(gl, Logic);
98
97
  }
99
- free() {
100
- glProgramCache.releaseProgram(this.gl, Logic);
101
- this.logic = null;
102
- this.gl = null;
103
- }
104
- }
98
+ });
@@ -1,4 +1,2 @@
1
- import PixelBasedMove from './pixelbased';
2
- import DrawRectangleParticles from './drawrectangleparticles';
3
1
  import { WaveParticalUboManager } from './ubo';
4
- export { PixelBasedMove, DrawRectangleParticles, WaveParticalUboManager };
2
+ export { WaveParticalUboManager };
@@ -120,20 +120,11 @@ class Logic {
120
120
  return this.gl.getAttribLocation(this.program, 'in_position');
121
121
  }
122
122
  }
123
- export default class {
124
- constructor(gl) {
125
- this.gl = gl;
126
- this.logic = glProgramCache.getProgram(gl, Logic);
127
- }
128
- move(bufferManager, vectorTexture, uboManager) {
129
- this.logic.move(bufferManager, vectorTexture, uboManager);
130
- }
131
- free() {
132
- glProgramCache.releaseProgram(this.gl, Logic);
133
- this.program = null;
134
- this.gl = null;
123
+ export const pixelBasedMoveProgramCache = Object.freeze({
124
+ getProgram: (gl) => {
125
+ return glProgramCache.getProgram(gl, Logic);
126
+ },
127
+ releaseProgram: (gl) => {
128
+ glProgramCache.releaseProgram(gl, Logic);
135
129
  }
136
- getInPositionLocation() {
137
- return this.logic.getInPositionLocation();
138
- }
139
- }
130
+ });
@@ -241,14 +241,7 @@ export function getColorRamp(colors) {
241
241
  canvas.height = 1;
242
242
  const gradient = ctx.createLinearGradient(0, 0, 256, 0);
243
243
  for (const stop in colors) {
244
- // Ensure the stop is a valid number, although `addColorStop` can parse strings,
245
- // explicit conversion is safer for object keys if they come from arbitrary sources.
246
- const stopValue = parseFloat(stop);
247
- if (isNaN(stopValue)) {
248
- console.warn(`Invalid stop value for color ramp: ${stop}. Skipping.`);
249
- continue;
250
- }
251
- gradient.addColorStop(stopValue, colors[stop]);
244
+ gradient.addColorStop(colors[stop][0], colors[stop][1]);
252
245
  }
253
246
  ctx.fillStyle = gradient;
254
247
  ctx.fillRect(0, 0, 256, 1);
@@ -328,18 +321,18 @@ export function getColorRampModed(values, thresholds, mode = "interpolated") {
328
321
  * @returns A Uint8Array representing the RGBA pixel data of the default 1x256 color ramp.
329
322
  */
330
323
  export function defaultColorRamp() {
331
- const defaultRampColors = {
332
- "0.0": '#5e4fa2',
333
- "0.15": '#3288bd',
334
- "0.20": '#66c2a5',
335
- "0.25": '#66c2a5',
336
- "0.3": '#abdda4',
337
- "0.4": '#e6f598',
338
- "0.5": '#fee08b',
339
- "0.6": '#fdae61',
340
- "0.7": '#f46d43',
341
- "1.0": '#ff1e13'
342
- };
324
+ const defaultRampColors = [
325
+ [0.0, '#5e4fa2'],
326
+ [0.15, '#3288bd'],
327
+ [0.20, '#66c2a5'],
328
+ [0.25, '#66c2a5'],
329
+ [0.3, '#abdda4'],
330
+ [0.4, '#e6f598'],
331
+ [0.5, '#fee08b'],
332
+ [0.6, '#fdae61'],
333
+ [0.7, '#f46d43'],
334
+ [1.0, '#ff1e13']
335
+ ];
343
336
  return getColorRamp(defaultRampColors);
344
337
  }
345
338
  /**
@@ -1,10 +1,10 @@
1
1
  import { GlobeShellWiggle } from "../programs";
2
2
  import { defaultblendfunction } from "../util";
3
- import { vectorfield } from "../programs";
3
+ import { vectorfield } from "../programs/index";
4
+ import { pixelBasedMoveProgramCache } from "../programs/vectorfields/logics/pixelbased";
5
+ import { drawRectangleParticlesProgramCache } from "../programs/vectorfields/logics/drawrectangleparticles";
4
6
  import { FadeAway } from "../programs";
5
- const { PixelBasedMove, DrawRectangleParticles, PingPongBufferManager, WaveParticalUboManager } = vectorfield;
6
- const MoveParticle = PixelBasedMove;
7
- const DrawParticle = DrawRectangleParticles;
7
+ const { PingPongBufferManager, WaveParticalUboManager } = vectorfield;
8
8
  /**
9
9
  * STEPS:
10
10
  * 1. move particle | buffers: read b1 write b2 | swap buffers b1 <-> b2
@@ -47,8 +47,8 @@ export default class Plugin {
47
47
  init(globe, gl) {
48
48
  this.globe = globe;
49
49
  this.gl = gl;
50
- this.moveParticle = new MoveParticle(gl);
51
- this.drawParticle = new DrawParticle(gl);
50
+ this.moveParticle = pixelBasedMoveProgramCache.getProgram(gl);
51
+ this.drawParticle = drawRectangleParticlesProgramCache.getProgram(gl);
52
52
  this.fadeAway = new FadeAway(gl);
53
53
  this.globeShellWiggle = new GlobeShellWiggle(gl, globe, this._globeshellparameters);
54
54
  const inPositionLocation = this.moveParticle.getInPositionLocation();
@@ -142,16 +142,21 @@ export default class Plugin {
142
142
  }
143
143
  // TODO: free all resources
144
144
  free() {
145
- const { gl, fadeAway, globeShellWiggle, _rgVectorFieldTexture, bufferManager, waveUbo, _drawTextures, _frameBuffer } = this;
145
+ if (this._isFreed) {
146
+ console.warn("WaveParticle plugin is already freed");
147
+ return;
148
+ }
149
+ ;
146
150
  this._isFreed = true;
151
+ const { gl, fadeAway, globeShellWiggle, _rgVectorFieldTexture, bufferManager, waveUbo, _drawTextures, _frameBuffer } = this;
147
152
  fadeAway.free();
148
153
  globeShellWiggle.free();
149
154
  gl.deleteTexture(_rgVectorFieldTexture);
150
155
  // glProgramCache.releaseProgram(gl, MoveParticle);
151
- this.moveParticle.free();
156
+ pixelBasedMoveProgramCache.getProgram(gl);
152
157
  this.moveParticle = null;
153
158
  // glProgramCache.releaseProgram(gl, DrawParticle);
154
- this.drawParticle.free();
159
+ drawRectangleParticlesProgramCache.getProgram(gl);
155
160
  this.drawParticle = null;
156
161
  bufferManager.free();
157
162
  waveUbo.free();