@pirireis/webglobeplugins 0.9.15 → 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.
@@ -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
+ // }