@pirireis/webglobeplugins 0.9.14 → 0.10.0-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.
@@ -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
+ });
@@ -3,45 +3,46 @@
3
3
  // import "../../../programs/interface";
4
4
  // import { createBufferAndReadInfo } from '../../../util/gl-util/buffer/attribute-loader';
5
5
  // import { populateFloat32Array } from "../../../util/jshelpers/data-filler";
6
- // import { BufferManagement, BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
6
+ // import { BufferManagementMap, BufferManager, BufferOrchestrator } from "../../../util/account/single-attribute-buffer-management/index";
7
7
  // import { globe3Dcoordinates, globe2Dcoordinates, RADIANS } from "../../../Math/methods";
8
- // import { Vector3D } from "../../../Math/vector3d";
9
- // import { Arc } from "../../../Math/arc";
10
- // import { Plane } from "../../../Math/plane";
8
+ // import { Vec3, Plane, Arc } from "../../../Math/types";
9
+ // import * as vec3 from "../../../Math/vec3";
10
+ // import * as plane from "../../../Math/plane";
11
+ // import * as arc from "../../../Math/arc";
11
12
  // import { arcFrustumPlanesIntersection } from "../../../Math/intersections/arc-frustum-planes";
12
13
  // import { CameraUniformBlockTotemCache, CameraUniformBlockTotem } from "../../../programs/totems/camerauniformblock";
13
14
  // import { FrustumPlanes } from "../../../Math/frustum/types";
14
15
  // const VERTEX_COUNT = 360;
15
16
  // const INITAL_CAPACITY = 10;
16
- // const _0vector = new Vector3D();
17
- // const _0arc = new Arc();
17
+ // const _0vector = [0, 0, 0] as Vec3;
18
+ // const _0arc = arcCreate([1, 0, 0] as Vec3, [0, 1, 0] as Vec3); // zero arc for intersection tests
18
19
  // // window add properties
19
20
  // declare global {
20
21
  // interface Window {
21
- // startPoint: Vector3D;
22
- // endPoint: Vector3D;
22
+ // startPoint: Vec3;
23
+ // endPoint: Vec3;
23
24
  // }
24
25
  // }
25
26
  // let interval = 1;
26
- // const testVec = new Vector3D(0, 0, 1);
27
- // testVec.setFromLongLat(30 * RADIANS, 30 * RADIANS);
27
+ // const testVec = [0, 0, 0] as Vec3;
28
+ // testVec.fromL(30 * RADIANS, 30 * RADIANS);
28
29
  // console.log("testVec", testVec.x, testVec.y, testVec.z);
29
- // testVec.setFromLongLat(50 * RADIANS, 50 * RADIANS);
30
+ // testVec.fromL(50 * RADIANS, 50 * RADIANS);
30
31
  // console.log("testVec", testVec.x, testVec.y, testVec.z);
31
32
  // export class NaiveLineOnTerrainPlugin {
32
33
  // public id: string;
33
- // private program: ProgramInterface;
34
- // private _bufferManagersCompMap: BufferManagement;
35
- // private _bufferManagersCompMapTest: BufferManagement;
34
+ // private program: ProgramInterface | null = null;
35
+ // private _bufferManagersCompMap: BufferManagementMap | null = null;
36
+ // private _bufferManagersCompMapTest: BufferManagementMap | null = null;
36
37
  // private _bufferOrchestrator: BufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
37
38
  // private _testOrchestrator: BufferOrchestrator = new BufferOrchestrator({ capacity: INITAL_CAPACITY });
38
39
  // private _opacity: number = 1;
39
- // private _arcUBOHandler: UBOHandler;
40
- // private _vao: WebGLVertexArrayObject;
41
- // private _vaoAllTest: WebGLVertexArrayObject;
42
- // private _ubohandlerAllTest: UBOHandler;
43
- // private globe: any;
44
- // private gl: WebGL2RenderingContext;
40
+ // private _arcUBOHandler: UBOHandler | null = null;
41
+ // private _vao: WebGLVertexArrayObject | null = null;
42
+ // private _vaoAllTest: WebGLVertexArrayObject | null = null;
43
+ // private _ubohandlerAllTest: UBOHandler | null = null;
44
+ // private globe: any | null = null;
45
+ // private gl: WebGL2RenderingContext | null = null;
45
46
  // private _arcMap: Map<string, Arc>;
46
47
  // private _arcMapTest: Map<string, Arc>;
47
48
  // private _screenPlane: Plane = new Plane();
@@ -161,7 +162,7 @@
161
162
  // // updatePlane
162
163
  // const { globe, _arcMap } = this;
163
164
  // const planes = this._cameraUniformBlock.getFrustumPlanes() as FrustumPlanes;
164
- // //
165
+ // //
165
166
  // const cameraPostition = new Vector3D();
166
167
  // cameraPostition.copy(globe.Fp as Vector3D).normalize();
167
168
  // // calculateHorizonPlane(globe, _screenPlane, this.fieldOfView);
@@ -27,10 +27,10 @@ export default class PointCoordinatesDataCalculator {
27
27
  }
28
28
  if (!this._isInBBox(long, lat))
29
29
  return false;
30
- const meta = this._metaCalculater.getFlooredMeta(long, lat);
31
- this._pointObjects[key] = pointObject(long, lat, meta.index, callback);
30
+ const index = this._metaCalculater.getFlooredIndex(long, lat);
31
+ this._pointObjects[key] = pointObject(long, lat, index, callback);
32
32
  if (this._texture0 && this._texture1) {
33
- const { data0, data1, interpolated } = this._findAPoint(meta.index);
33
+ const { data0, data1, interpolated } = this._findAPoint(index);
34
34
  callback(data0, data1, interpolated);
35
35
  }
36
36
  return true;
@@ -51,9 +51,9 @@ export default class PointCoordinatesDataCalculator {
51
51
  return false;
52
52
  this._pointObjects[key].long = long;
53
53
  this._pointObjects[key].lat = lat;
54
- const meta = this._metaCalculater.getFlooredMeta(long, lat);
55
- this._pointObjects[key].posIndex = meta.index;
56
- const { data0, data1, interpolated } = this._findAPoint(meta.index);
54
+ const index = this._metaCalculater.getFlooredMeta(long, lat);
55
+ this._pointObjects[key].posIndex = index;
56
+ const { data0, data1, interpolated } = this._findAPoint(index);
57
57
  this._pointObjects[key].callback(data0, data1, interpolated);
58
58
  return true;
59
59
  }
@@ -1,4 +1,9 @@
1
1
  export default class PointCoordsMeta {
2
+ _bbox;
3
+ _width;
4
+ _height;
5
+ _xRatio;
6
+ _yRatio;
2
7
  constructor(bbox, width, height) {
3
8
  this._bbox = bbox;
4
9
  this._width = width;
@@ -6,12 +11,12 @@ export default class PointCoordsMeta {
6
11
  this._xRatio = this._width / (this._bbox[2] - this._bbox[0]);
7
12
  this._yRatio = this._height / (this._bbox[3] - this._bbox[1]);
8
13
  }
9
- getFlooredMeta(long, lat) {
14
+ getFlooredIndex(long, lat) {
10
15
  let x = (long - this._bbox[0]) * this._xRatio;
11
16
  let y = (this._bbox[3] - lat) * this._yRatio;
12
17
  x = x > 0 ? x - 1 : 0;
13
18
  y = y > 0 ? y - 1 : 0;
14
19
  const index = Math.floor(y) * this._width + Math.floor(x);
15
- return { index };
20
+ return index;
16
21
  }
17
22
  }
@@ -0,0 +1,160 @@
1
+ import PointCoordsMeta from "./pointcoordsmeta";
2
+ const pointObject = (long, lat, posIndex, callback) => {
3
+ return { long, lat, posIndex, callback };
4
+ };
5
+ export class TexturePointSampler {
6
+ _bbox;
7
+ _width;
8
+ _height;
9
+ _textureCount;
10
+ _metaCalculater;
11
+ _pointObjects;
12
+ _textures;
13
+ _ratio;
14
+ _isReady = false;
15
+ constructor(bbox, width, height, textureCount = 2) {
16
+ this._pointObjects = new Map();
17
+ this._ratio = 0.0;
18
+ this._bbox = bbox;
19
+ this._width = width;
20
+ this._height = height;
21
+ this._textureCount = textureCount;
22
+ this._metaCalculater = new PointCoordsMeta(bbox, width, height);
23
+ this._textures = new Array(textureCount).fill(null);
24
+ this._isReady = false;
25
+ }
26
+ setTextureCount(textureCount) {
27
+ if (textureCount !== 1 && textureCount !== 2) {
28
+ throw new Error("Texture count must be 1 or 2");
29
+ }
30
+ this._textureCount = textureCount;
31
+ this._isReady = false; // Reset readiness when changing texture count
32
+ }
33
+ registerPoint(key, long, lat, callback) {
34
+ if (key in this._pointObjects) {
35
+ console.warn("key already registered, old one is unregistered");
36
+ this.unregisterPoint(key);
37
+ }
38
+ if (!this._isInBBox(long, lat))
39
+ return false;
40
+ const index = this._metaCalculater.getFlooredIndex(long, lat);
41
+ this._pointObjects.set(key, pointObject(long, lat, index, callback));
42
+ if (this._isReady) {
43
+ this._findAndSend(key);
44
+ }
45
+ return true;
46
+ }
47
+ unregisterPoint(key) {
48
+ return this._pointObjects.delete(key);
49
+ }
50
+ updatePoint(key, long, lat) {
51
+ const pointObject = this._pointObjects.get(key);
52
+ if (!pointObject) {
53
+ console.warn("Point not registered, use registerPoint first");
54
+ return false;
55
+ }
56
+ if (!this._isInBBox(long, lat)) {
57
+ console.warn("Point is out of bbox, use registerPoint with valid coordinates");
58
+ pointObject.callback(null, null, null);
59
+ return false;
60
+ }
61
+ ;
62
+ pointObject.long = long;
63
+ pointObject.lat = lat;
64
+ const index = this._metaCalculater.getFlooredIndex(long, lat);
65
+ pointObject.posIndex = index;
66
+ this._findAndSend(key);
67
+ return true;
68
+ }
69
+ updateTextureData(ratio, textureData0 = null, textureData1 = null) {
70
+ if (this._textureCount === 1) {
71
+ if (textureData0 === null) {
72
+ this._isReady = false;
73
+ }
74
+ else {
75
+ this._textures[0] = textureData0;
76
+ this._isReady = true;
77
+ }
78
+ }
79
+ else if (this._textureCount === 2) {
80
+ if (textureData0 === null || textureData1 === null) {
81
+ this._isReady = false;
82
+ }
83
+ else {
84
+ this._textures[0] = textureData0;
85
+ this._textures[1] = textureData1;
86
+ this._isReady = true;
87
+ }
88
+ }
89
+ else {
90
+ throw new Error("Invalid texture count, must be 1 or 2");
91
+ }
92
+ this.updateRatio(ratio);
93
+ }
94
+ updateRatio(ratio) {
95
+ if (ratio < 0 || ratio > 1) {
96
+ console.warn("Ratio must be between 0 and 1");
97
+ ratio = Math.max(0, Math.min(1, ratio)); // Clamp the ratio
98
+ }
99
+ this._ratio = ratio;
100
+ this._pushPointCallbackAll();
101
+ }
102
+ flush(callEmptyCallback = false) {
103
+ if (callEmptyCallback) {
104
+ for (const [key, { callback }] of this._pointObjects.entries()) {
105
+ callback(null, null, null);
106
+ }
107
+ }
108
+ this._pointObjects.clear();
109
+ }
110
+ // ------- PRIVATE METHODS -------
111
+ _isInBBox(long, lat) {
112
+ return lat >= this._bbox[1] && lat <= this._bbox[3] && long >= this._bbox[0] && long <= this._bbox[2];
113
+ }
114
+ _findAndSend(key) {
115
+ const pointObject = this._pointObjects.get(key);
116
+ if (!pointObject) {
117
+ console.warn("Point not registered, use registerPoint first");
118
+ return;
119
+ }
120
+ const { posIndex, callback } = pointObject;
121
+ const data0 = this._textures[0][posIndex];
122
+ if (this._textureCount === 1) {
123
+ callback(data0, null, data0);
124
+ }
125
+ else if (this._textureCount === 2) {
126
+ const data1 = this._textures[1][posIndex];
127
+ const interpolated = data0 * (1 - this._ratio) + data1 * this._ratio;
128
+ callback(data0, data1, interpolated);
129
+ }
130
+ }
131
+ _pushPointCallbackAll() {
132
+ if (this._isReady) {
133
+ for (const key of this._pointObjects.keys()) {
134
+ this._findAndSend(key);
135
+ }
136
+ }
137
+ else {
138
+ for (const [key, { callback }] of this._pointObjects.entries()) {
139
+ callback(null, null, null);
140
+ }
141
+ }
142
+ }
143
+ }
144
+ // function test() {
145
+ // const cp = window.plugin.getPointCoordinatesDataCalculator();
146
+ // const bbox = [-15, 25, 70, 60];
147
+ // cp.registerPoint("left up", -15, 60, (data0, data1, interpolated) => {
148
+ // console.log("left up", data0, data1, interpolated);
149
+ // });
150
+ // cp.registerPoint("right up", 70, 60, (data0, data1, interpolated) => {
151
+ // console.log("right up", data0, data1, interpolated);
152
+ // });
153
+ // cp.registerPoint("left down", -15, 25, (data0, data1, interpolated) => {
154
+ // console.log("right down", data0, data1, interpolated);
155
+ // });
156
+ // cp.registerPoint("right down", 70, 25, (data0, data1, interpolated) => {
157
+ // console.log("right down", data0, data1, interpolated);
158
+ // });
159
+ // return cp;
160
+ // }
@@ -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();