@pirireis/webglobeplugins 0.9.6 → 0.9.7

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.
Files changed (226) hide show
  1. package/package.json +5 -2
  2. package/Math/angle-calculation.js +0 -14
  3. package/Math/arc.ts +0 -76
  4. package/Math/bounds/line-bbox.js +0 -225
  5. package/Math/constants.ts +0 -11
  6. package/Math/frustum/camera.ts +0 -32
  7. package/Math/frustum/from-globeinfo.ts +0 -63
  8. package/Math/frustum/types.ts +0 -11
  9. package/Math/globe-util/horizon-plane.ts +0 -137
  10. package/Math/index.js +0 -0
  11. package/Math/juction/arc-plane.ts +0 -114
  12. package/Math/juction/line-sphere.ts +0 -30
  13. package/Math/juction/plane-plane.ts +0 -66
  14. package/Math/line.ts +0 -70
  15. package/Math/matrix4.ts +0 -0
  16. package/Math/methods.js +0 -237
  17. package/Math/plane.ts +0 -86
  18. package/Math/quaternion.ts +0 -120
  19. package/Math/roadmap.md +0 -10
  20. package/Math/types.ts +0 -45
  21. package/Math/utils.js +0 -3
  22. package/Math/vec3.ts +0 -155
  23. package/algorithms/search-binary.js +0 -14
  24. package/altitude-locator/adaptors.js +0 -0
  25. package/altitude-locator/draw-subset-obj.js +0 -27
  26. package/altitude-locator/keymethod.js +0 -0
  27. package/altitude-locator/plugin.js +0 -439
  28. package/altitude-locator/types.js +0 -26
  29. package/arrowfield/adaptor.js +0 -11
  30. package/arrowfield/index.js +0 -3
  31. package/arrowfield/plugin.js +0 -128
  32. package/bearing-line/index.js +0 -2
  33. package/bearing-line/plugin.js +0 -512
  34. package/circle-line-chain/chain-list-map.js +0 -221
  35. package/circle-line-chain/init.js +0 -0
  36. package/circle-line-chain/plugin.js +0 -469
  37. package/circle-line-chain/readme.md +0 -57
  38. package/circle-line-chain/util.js +0 -1
  39. package/compass-rose/compass-rose-padding-flat.js +0 -266
  40. package/compass-rose/compass-text-writer.js +0 -173
  41. package/compass-rose/index.js +0 -3
  42. package/compassrose/compassrose.js +0 -341
  43. package/compassrose/index.js +0 -2
  44. package/depth-locator/readme.md +0 -26
  45. package/globe-types.ts +0 -13
  46. package/heatwave/index.js +0 -4
  47. package/heatwave/isobar/objectarraylabels.js +0 -247
  48. package/heatwave/isobar/plugin.js +0 -340
  49. package/heatwave/isobar/quadtreecontours.js +0 -336
  50. package/heatwave/plugins/heatwaveglobeshell.js +0 -258
  51. package/jest.config.js +0 -6
  52. package/partialrings/buffer-manager.js +0 -89
  53. package/partialrings/goals.md +0 -17
  54. package/partialrings/index.js +0 -3
  55. package/partialrings/plugin.js +0 -160
  56. package/partialrings/program.js +0 -324
  57. package/pin/pin-object-array.js +0 -381
  58. package/pin/pin-point-totem.js +0 -77
  59. package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +0 -78
  60. package/point-heat-map/index.js +0 -0
  61. package/point-heat-map/plugin-webworker.js +0 -151
  62. package/point-heat-map/point-to-heat-map-flow.js +0 -150
  63. package/point-heat-map/readme.md +0 -15
  64. package/point-tracks/key-methods.js +0 -3
  65. package/point-tracks/plugin.js +0 -394
  66. package/programs/arrowfield/index.js +0 -2
  67. package/programs/arrowfield/logic.js +0 -286
  68. package/programs/arrowfield/object.js +0 -89
  69. package/programs/data2legend/density-to-legend.js +0 -115
  70. package/programs/data2legend/point-to-density-texture.js +0 -114
  71. package/programs/float2legendwithratio/index.js +0 -3
  72. package/programs/float2legendwithratio/logic.js +0 -194
  73. package/programs/float2legendwithratio/object.js +0 -141
  74. package/programs/globe-util/is-globe-moved.js +0 -27
  75. package/programs/globeshell/index.js +0 -2
  76. package/programs/globeshell/noise/noises.js +0 -0
  77. package/programs/globeshell/wiggle/index.js +0 -6
  78. package/programs/globeshell/wiggle/logic.js +0 -371
  79. package/programs/globeshell/wiggle/object.js +0 -93
  80. package/programs/helpers/blender/index.js +0 -0
  81. package/programs/helpers/blender/program.js +0 -91
  82. package/programs/helpers/fadeaway/index.js +0 -3
  83. package/programs/helpers/fadeaway/logic.js +0 -76
  84. package/programs/helpers/fadeaway/object.js +0 -20
  85. package/programs/helpers/index.js +0 -2
  86. package/programs/index.js +0 -21
  87. package/programs/interface.ts +0 -7
  88. package/programs/line-on-globe/angled-line.js +0 -206
  89. package/programs/line-on-globe/circle-accurate-3d.js +0 -167
  90. package/programs/line-on-globe/circle-accurate-flat.js +0 -262
  91. package/programs/line-on-globe/circle-accurate.js +0 -202
  92. package/programs/line-on-globe/circle.js +0 -191
  93. package/programs/line-on-globe/degree-padding-around-circle-3d.js +0 -188
  94. package/programs/line-on-globe/index.js +0 -0
  95. package/programs/line-on-globe/lines-color-instanced-flat.js +0 -151
  96. package/programs/line-on-globe/linestrip.ts +0 -228
  97. package/programs/line-on-globe/naive-accurate-flexible.js +0 -239
  98. package/programs/line-on-globe/to-the-surface.js +0 -129
  99. package/programs/line-on-globe/util.js +0 -8
  100. package/programs/picking/pickable-renderer.js +0 -216
  101. package/programs/point-on-globe/element-globe-surface-glow.js +0 -168
  102. package/programs/point-on-globe/element-point-glow.js +0 -184
  103. package/programs/point-on-globe/square-pixel-point.js +0 -189
  104. package/programs/programcache.ts +0 -131
  105. package/programs/rings/distancering/circleflatprogram.js +0 -136
  106. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +0 -378
  107. package/programs/rings/distancering/circlepaddysharedbuffer.js +0 -420
  108. package/programs/rings/distancering/index.js +0 -5
  109. package/programs/rings/distancering/paddyflatprogram.js +0 -146
  110. package/programs/rings/distancering/paddyflatprogram2d.js +0 -150
  111. package/programs/rings/distancering/paddyflatprogram3d.js +0 -146
  112. package/programs/rings/distancering/shader.js +0 -0
  113. package/programs/rings/index.js +0 -1
  114. package/programs/rings/partial-ring/piece-of-pie.js +0 -315
  115. package/programs/totems/camerauniformblock.d.ts +0 -48
  116. package/programs/totems/camerauniformblock.js +0 -197
  117. package/programs/totems/canvas-webglobe-info.js +0 -136
  118. package/programs/totems/gpu-selection-uniform-block.js +0 -132
  119. package/programs/totems/index.ts +0 -2
  120. package/programs/two-d/pixel-circle.js +0 -0
  121. package/programs/two-d/pixel-padding-for-compass.js +0 -174
  122. package/programs/util.js +0 -20
  123. package/programs/vectorfields/index.js +0 -3
  124. package/programs/vectorfields/logics/drawrectangleparticles.js +0 -125
  125. package/programs/vectorfields/logics/index.js +0 -5
  126. package/programs/vectorfields/logics/pixelbased.js +0 -161
  127. package/programs/vectorfields/logics/ubo.js +0 -64
  128. package/programs/vectorfields/pingpongbuffermanager.js +0 -80
  129. package/publish.bat +0 -60
  130. package/rangerings/enum.js +0 -3
  131. package/rangerings/index.js +0 -5
  132. package/rangerings/plugin.js +0 -649
  133. package/rangerings/rangeringangletext.js +0 -368
  134. package/rangerings/ring-account.js +0 -129
  135. package/shaders/fragment-toy/firework.js +0 -55
  136. package/shaders/fragment-toy/singularity.js +0 -59
  137. package/shape-on-terrain/arc/naive/plugin.ts +0 -304
  138. package/shape-on-terrain/goal.md +0 -12
  139. package/tests/Math/junction/arc-plane.test.ts +0 -133
  140. package/tests/Math/junction/plane-plane.test.ts +0 -82
  141. package/tests/Math/plane.test.ts +0 -43
  142. package/tests/Math/vec3.test.ts +0 -14
  143. package/timetracks/adaptors-line-strip.js +0 -80
  144. package/timetracks/adaptors.js +0 -133
  145. package/timetracks/index.js +0 -6
  146. package/timetracks/plugin-line-strip.js +0 -295
  147. package/timetracks/plugin.js +0 -304
  148. package/timetracks/program-line-strip.js +0 -688
  149. package/timetracks/program.js +0 -850
  150. package/timetracks/programpoint-line-strip.js +0 -175
  151. package/timetracks/programpoint.js +0 -168
  152. package/timetracks/readme.md +0 -1
  153. package/tsconfig.json +0 -22
  154. package/types.ts +0 -17
  155. package/util/account/bufferoffsetmanager.js +0 -209
  156. package/util/account/index.js +0 -6
  157. package/util/account/single-attribute-buffer-management/buffer-manager.ts +0 -119
  158. package/util/account/single-attribute-buffer-management/buffer-orchestrator.ts +0 -173
  159. package/util/account/single-attribute-buffer-management/index.ts +0 -13
  160. package/util/account/single-attribute-buffer-management/object-store.ts +0 -65
  161. package/util/account/single-attribute-buffer-management/types.ts +0 -39
  162. package/util/account/util.js +0 -22
  163. package/util/algorithms/index.js +0 -0
  164. package/util/algorithms/search-binary.js +0 -26
  165. package/util/check/get.js +0 -13
  166. package/util/check/index.js +0 -0
  167. package/util/check/typecheck.js +0 -39
  168. package/util/geometry/index.js +0 -53
  169. package/util/gl-util/buffer/attribute-loader.ts +0 -85
  170. package/util/gl-util/buffer/index.ts +0 -6
  171. package/util/gl-util/buffer/types.ts +0 -13
  172. package/util/gl-util/draw-options/methods.ts +0 -66
  173. package/util/gl-util/draw-options/types.ts +0 -28
  174. package/util/gl-util/uniform-block/manager.ts +0 -187
  175. package/util/gl-util/uniform-block/roadmap.md +0 -70
  176. package/util/gl-util/uniform-block/shader.js +0 -0
  177. package/util/gl-util/uniform-block/types.ts +0 -27
  178. package/util/heatwavedatamanager/datamanager.js +0 -168
  179. package/util/heatwavedatamanager/index.js +0 -3
  180. package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +0 -133
  181. package/util/heatwavedatamanager/pointcoordsmeta.js +0 -22
  182. package/util/index.js +0 -13
  183. package/util/interpolation/index.js +0 -0
  184. package/util/interpolation/timetrack/index.js +0 -9
  185. package/util/interpolation/timetrack/timetrack-interpolator.js +0 -88
  186. package/util/interpolation/timetrack/web-worker-str.js +0 -180
  187. package/util/interpolation/timetrack/web-worker.js +0 -51
  188. package/util/jshelpers/data-filler.js +0 -19
  189. package/util/jshelpers/equality.js +0 -17
  190. package/util/jshelpers/index.js +0 -1
  191. package/util/jshelpers/timefilters.js +0 -32
  192. package/util/picking/fence.js +0 -46
  193. package/util/picking/picker-displayer.js +0 -177
  194. package/util/programs/draw-texture-on-canvas.js +0 -102
  195. package/util/programs/index.js +0 -1
  196. package/util/programs/shapesonglobe.js +0 -246
  197. package/util/programs/supersampletotextures.js +0 -142
  198. package/util/programs/texturetoglobe.js +0 -203
  199. package/util/shaderfunctions/geometrytransformations.ts +0 -388
  200. package/util/shaderfunctions/index.js +0 -2
  201. package/util/shaderfunctions/nodata.js +0 -10
  202. package/util/shaderfunctions/noisefunctions.js +0 -44
  203. package/util/surface-line-data/arc-bboxes.ts +0 -42
  204. package/util/surface-line-data/arcs-to-cuts.js +0 -74
  205. package/util/surface-line-data/cut-arc.js +0 -0
  206. package/util/surface-line-data/flow.ts +0 -52
  207. package/util/surface-line-data/rbush-manager.js +0 -0
  208. package/util/surface-line-data/types.ts +0 -27
  209. package/util/surface-line-data/web-worker.js +0 -0
  210. package/util/webglobe/gldefaultstates.js +0 -5
  211. package/util/webglobe/index.js +0 -2
  212. package/util/webglobe/rasteroverlay.js +0 -96
  213. package/util/webglobjectbuilders.ts +0 -456
  214. package/util/webglobjectbuilders1.js +0 -271
  215. package/waveparticles/adaptor.js +0 -16
  216. package/waveparticles/index.js +0 -3
  217. package/waveparticles/plugin.js +0 -313
  218. package/wind/imagetovectorfieldandmagnitude.js +0 -39
  219. package/wind/index.js +0 -5
  220. package/wind/plugin.js +0 -1057
  221. package/wind/vectorfieldimage.js +0 -27
  222. package/write-text/attached-text-writer.js +0 -105
  223. package/write-text/context-text.js +0 -125
  224. package/write-text/context-text3.js +0 -178
  225. package/write-text/index.js +0 -1
  226. package/write-text/writer-plugin.js +0 -7
@@ -1,96 +0,0 @@
1
- /**
2
- * Iceride bir canvas uretir ve degisiklikler bu kanvasta yapilir
3
- */
4
-
5
- // this class loads texture to raster overlay
6
- class RasterOverlayLoader {
7
- constructor(id, globe, { opacity = 1.0, minLon = -180, minLat = -90, maxLon = 180, maxLat = 90, beforeObject = null, canvas = null, callBack = null } = {}) {
8
-
9
- this.canvas = canvas || document.createElement('canvas');
10
- this.gl = this.canvas.getContext('webgl2');
11
- this.globe = globe;
12
- this.id = id;
13
- this._opacity = opacity;
14
- this.bbox = { ll: { x: minLon, y: minLat }, ur: { x: maxLon, y: maxLat } };
15
-
16
- this._beforeObject = beforeObject;
17
-
18
- this._isProcessing = false;
19
- this._callBack = callBack;
20
-
21
- }
22
-
23
- getGL() {
24
- return this.gl;
25
- }
26
-
27
- getCanvasURL() {
28
- return this.canvas.toDataURL();
29
- }
30
-
31
- setBBox(minLon, minLat, maxLon, maxLat) {
32
- this.bbox = { ll: { x: minLon, y: minLat }, ur: { x: maxLon, y: maxLat } };
33
- this.draw();
34
- }
35
-
36
- setCanvasWidthHeight(width, height) {
37
- this.canvas.width = width;
38
- this.canvas.height = height;
39
- this.gl.viewport(0, 0, width, height);
40
- }
41
-
42
-
43
- draw() {
44
- if (!this._isProcessing) {
45
- requestAnimationFrame(this._draw.bind(this));
46
- this._isProcessing = true;
47
- }
48
- }
49
-
50
-
51
- _draw() {
52
- this.globe.api_DeleteImageOverlay(this.id);
53
- const id = this.id;
54
- const imgUrl = this.getCanvasURL()
55
- const bbox = this.bbox
56
- const opacity = this._opacity
57
- const rotDeg = 0
58
- const color = null
59
- const beforeObject = this._beforeObject
60
- const callback = this._callBack || function () { };
61
- this.globe.api_AddImageOverlay(id, imgUrl, bbox, color, opacity, rotDeg, beforeObject, callback);
62
- this._isProcessing = false;
63
- }
64
-
65
- setBeforeObject(beforeObject) {
66
- this._beforeObject = beforeObject;
67
- this.draw();
68
- }
69
-
70
- setCallback(callback) {
71
- this._callBack = callback;
72
- }
73
-
74
- setOpacity(opacity) {
75
- if (opacity < 0 || opacity > 1) { return; }
76
- this._opacity = opacity;
77
- this.globe.api_SetImageOverlayColor(this.id, null, opacity)
78
- }
79
-
80
-
81
- free() {
82
- this.globe.api_DeleteImageOverlay(this.id);
83
- }
84
-
85
-
86
- on() {
87
- this.draw();
88
- }
89
-
90
- off() {
91
- this.globe.api_DeleteImageOverlay(this.id);
92
- }
93
-
94
- }
95
-
96
- export { RasterOverlayLoader };
@@ -1,456 +0,0 @@
1
- /**
2
- * Creates and compiles a WebGL shader.
3
- * @param gl The WebGL2RenderingContext.
4
- * @param type The type of shader (e.g., gl.VERTEX_SHADER or gl.FRAGMENT_SHADER).
5
- * @param source The GLSL source code for the shader.
6
- * @returns The compiled WebGLShader.
7
- * @throws An error if shader compilation fails.
8
- */
9
- export function createShader(gl: WebGL2RenderingContext, type: GLenum, source: string): WebGLShader {
10
- const shader = gl.createShader(type);
11
- if (!shader) {
12
- throw new Error("Failed to create WebGLShader.");
13
- }
14
-
15
- gl.shaderSource(shader, source);
16
- gl.compileShader(shader);
17
-
18
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
19
- const errorLog = gl.getShaderInfoLog(shader);
20
- const shaderType = type === gl.VERTEX_SHADER ? 'VERTEX_SHADER' : 'FRAGMENT_SHADER';
21
- const sourceWithLineNumbers = source.split('\n').map((line, i) => `${i + 1}: ${line}`).join('\n');
22
- gl.deleteShader(shader); // Clean up the failed shader
23
- throw new Error(`Error compiling ${shaderType}:\n${errorLog}\nSource:\n${sourceWithLineNumbers}`);
24
- }
25
-
26
- return shader;
27
- }
28
-
29
-
30
- /**
31
- * Creates, compiles, and links a WebGL program from vertex and fragment shader sources.
32
- * Note: This function logs errors to the console and returns `undefined` on failure.
33
- * Consider using `createProgramWrapper` for more robust error handling.
34
- * @param gl The WebGL2RenderingContext.
35
- * @param vertexSource The GLSL source code for the vertex shader.
36
- * @param fragmentSource The GLSL source code for the fragment shader.
37
- * @returns The linked WebGLProgram, or `undefined` if compilation or linking fails.
38
- */
39
- export function createProgram(gl: WebGL2RenderingContext, vertexSource: string, fragmentSource: string): WebGLProgram | undefined {
40
- const program = gl.createProgram();
41
- if (!program) {
42
- console.error("Failed to create WebGLProgram.");
43
- return undefined;
44
- }
45
-
46
- let vertexShader: WebGLShader | undefined;
47
- let fragmentShader: WebGLShader | undefined;
48
-
49
- try {
50
- vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
51
- fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
52
- } catch (e: any) { // Catching errors from createShader
53
- console.error(e.message);
54
- gl.deleteProgram(program); // Clean up the program if shaders failed
55
- return undefined;
56
- }
57
-
58
- gl.attachShader(program, vertexShader);
59
- gl.attachShader(program, fragmentShader);
60
- gl.linkProgram(program);
61
-
62
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
63
- console.error("Failed to link WebGL program:", gl.getProgramInfoLog(program));
64
- gl.deleteProgram(program);
65
- gl.deleteShader(vertexShader);
66
- gl.deleteShader(fragmentShader);
67
- return undefined;
68
- }
69
-
70
- // Detach and delete shaders after linking to free up resources
71
- gl.detachShader(program, vertexShader);
72
- gl.detachShader(program, fragmentShader);
73
- gl.deleteShader(vertexShader);
74
- gl.deleteShader(fragmentShader);
75
-
76
- return program;
77
- }
78
-
79
-
80
- /**
81
- * Interface for the program wrapper object returned by `createProgramWrapper`.
82
- * It includes the `program` itself, and dynamically added properties for attribute and uniform locations.
83
- */
84
- export interface ProgramWrapper extends WebGLProgram {
85
- program: WebGLProgram;
86
- [key: string]: WebGLProgram | number | WebGLUniformLocation | null; // Allow dynamic properties for attributes/uniforms
87
- }
88
-
89
- /**
90
- * Creates, links a WebGL program, and wraps it with convenience properties
91
- * for attribute and uniform locations.
92
- * @param gl The WebGL2RenderingContext.
93
- * @param vertexSource The GLSL source code for the vertex shader.
94
- * @param fragmentSource The GLSL source code for the fragment shader.
95
- * @returns A ProgramWrapper object containing the WebGLProgram and its active attribute/uniform locations.
96
- * @throws An error if shader compilation or program linking fails.
97
- */
98
- export function createProgramWrapper(gl: WebGL2RenderingContext, vertexSource: string, fragmentSource: string): ProgramWrapper {
99
- const program = gl.createProgram();
100
- if (!program) {
101
- throw new Error("Failed to create WebGLProgram.");
102
- }
103
-
104
- const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
105
- const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
106
-
107
- gl.attachShader(program, vertexShader);
108
- gl.attachShader(program, fragmentShader);
109
-
110
- gl.linkProgram(program);
111
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
112
- const errorLog = gl.getProgramInfoLog(program);
113
- gl.deleteProgram(program);
114
- gl.deleteShader(vertexShader);
115
- gl.deleteShader(fragmentShader);
116
- throw new Error(`Error linking program:\n${errorLog}`);
117
- }
118
-
119
- // Detach and delete shaders after linking
120
- gl.detachShader(program, vertexShader);
121
- gl.detachShader(program, fragmentShader);
122
- gl.deleteShader(vertexShader);
123
- gl.deleteShader(fragmentShader);
124
-
125
- // Using an object literal for dynamic properties
126
- const wrapper: ProgramWrapper = { program: program };
127
-
128
- const numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
129
- for (let i = 0; i < numAttributes; i++) {
130
- const attribute = gl.getActiveAttrib(program, i);
131
- if (attribute) {
132
- wrapper[attribute.name] = gl.getAttribLocation(program, attribute.name);
133
- }
134
- }
135
-
136
- const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
137
- for (let i = 0; i < numUniforms; i++) {
138
- const uniform = gl.getActiveUniform(program, i);
139
- if (uniform) {
140
- wrapper[uniform.name] = gl.getUniformLocation(program, uniform.name);
141
- }
142
- }
143
-
144
- return wrapper;
145
- }
146
-
147
-
148
- /**
149
- * Creates and configures a WebGL texture.
150
- * @param gl The WebGL2RenderingContext.
151
- * @param filter The texture filter (e.g., gl.LINEAR, gl.NEAREST).
152
- * @param data The image data (e.g., ImageData, HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageBitmap, or Uint8Array).
153
- * @param width The width of the texture (required if data is Uint8Array).
154
- * @param height The height of the texture (required if data is Uint8Array).
155
- * @returns The created WebGLTexture.
156
- * @throws An error if texture creation fails.
157
- */
158
- export function createTexture(
159
- gl: WebGL2RenderingContext,
160
- filter: GLenum,
161
- data: TexImageSource | Uint8Array | null | any,
162
- width?: number,
163
- height?: number
164
- ): WebGLTexture {
165
- const texture = gl.createTexture();
166
- if (!texture) {
167
- throw new Error("Failed to create WebGLTexture.");
168
- }
169
- gl.bindTexture(gl.TEXTURE_2D, texture);
170
-
171
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
172
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
173
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
174
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
175
-
176
- if (data instanceof Uint8Array) {
177
- if (width === undefined || height === undefined) {
178
- throw new Error("Width and height must be provided when data is Uint8Array.");
179
- }
180
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
181
- } else {
182
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, data);
183
- }
184
- gl.bindTexture(gl.TEXTURE_2D, null);
185
- return texture;
186
- }
187
-
188
-
189
- /**
190
- * Binds a WebGL texture to a specific texture unit.
191
- * @param gl The WebGL2RenderingContext.
192
- * @param texture The WebGLTexture to bind.
193
- * @param unit The texture unit to activate (e.g., 0 for TEXTURE0, 1 for TEXTURE1).
194
- */
195
- export function bindTexture(gl: WebGL2RenderingContext, texture: WebGLTexture | null, unit: number): void {
196
- gl.activeTexture(gl.TEXTURE0 + unit);
197
- gl.bindTexture(gl.TEXTURE_2D, texture);
198
- }
199
-
200
-
201
- /**
202
- * Creates a WebGL buffer and uploads data to it.
203
- * @param gl The WebGL2RenderingContext.
204
- * @param data The data to upload to the buffer (e.g., Float32Array, Uint16Array).
205
- * @returns The created WebGLBuffer.
206
- * @throws An error if buffer creation fails.
207
- */
208
- export function createBuffer(gl: WebGL2RenderingContext, data: BufferSource): WebGLBuffer {
209
- const buffer = gl.createBuffer();
210
- if (!buffer) {
211
- throw new Error("Failed to create WebGLBuffer.");
212
- }
213
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
214
- gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
215
- return buffer;
216
- }
217
-
218
-
219
-
220
- /**
221
- * Binds a buffer to a specific attribute location and configures the vertex attribute pointer.
222
- * @param gl The WebGL2RenderingContext.
223
- * @param buffer The WebGLBuffer to bind.
224
- * @param attribute The attribute location (e.g., from `gl.getAttribLocation`).
225
- * @param numComponents The number of components per vertex attribute (e.g., 2 for vec2, 3 for vec3).
226
- */
227
- export function bindAttribute(gl: WebGL2RenderingContext, buffer: WebGLBuffer | null, attribute: GLint, numComponents: GLint): void {
228
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
229
- gl.enableVertexAttribArray(attribute);
230
- gl.vertexAttribPointer(attribute, numComponents, gl.FLOAT, false, 0, 0);
231
- }
232
-
233
-
234
- /**
235
- * Binds a WebGL framebuffer and optionally attaches a texture to it.
236
- * @param gl The WebGL2RenderingContext.
237
- * @param framebuffer The WebGLFramebuffer to bind.
238
- * @param texture The WebGLTexture to attach to the framebuffer's COLOR_ATTACHMENT0, or `null` to unbind.
239
- */
240
- export function bindFramebuffer(gl: WebGL2RenderingContext, framebuffer: WebGLFramebuffer | null, texture: WebGLTexture | null): void {
241
- gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
242
- if (texture) {
243
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
244
- }
245
- }
246
-
247
-
248
- /**
249
- * Decodes a base64 encoded string into a Uint8Array.
250
- * @param data The base64 encoded string.
251
- * @returns A Uint8Array containing the decoded bytes.
252
- */
253
- export function decodeBase64(data: string): Uint8Array {
254
- const binary_string = atob(data);
255
- const len = binary_string.length;
256
- const bytes = new Uint8Array(len);
257
- for (let i = 0; i < len; i++) {
258
- bytes[i] = binary_string.charCodeAt(i);
259
- }
260
- return bytes;
261
- }
262
-
263
-
264
- /**
265
- * Creates an HTMLImageElement from a base64 encoded image string.
266
- * @param encodedData The base64 encoded image data (e.g., "iVBORw0KGgo...").
267
- * @returns An HTMLImageElement with the image data loaded.
268
- */
269
- export function createImageFromBase64(encodedData: string): HTMLImageElement {
270
- const bytes = decodeBase64(encodedData);
271
- const blob = new Blob([bytes.buffer], { type: "image/png" });
272
- const urlCreator = window.URL || window.webkitURL;
273
- const imageUrl = urlCreator.createObjectURL(blob);
274
- const image = new Image();
275
- image.src = imageUrl;
276
- // Revoke the object URL after the image has loaded to free up memory
277
- image.onload = () => urlCreator.revokeObjectURL(imageUrl);
278
- return image;
279
- }
280
-
281
-
282
- /**
283
- * Creates a 1x256 pixel color ramp (gradient) as a Uint8Array.
284
- * @param colors An object where keys are stop positions (0.0-1.0) and values are CSS color strings (e.g., { "0.0": "#RRGGBB", "0.5": "rgba(R,G,B,A)" }).
285
- * @returns A Uint8Array representing the RGBA pixel data of the 1x256 color ramp.
286
- */
287
- export function getColorRamp(colors: { [stop: string]: string }): Uint8Array {
288
- const canvas = document.createElement('canvas');
289
- const ctx = canvas.getContext('2d');
290
-
291
- if (!ctx) {
292
- throw new Error("Failed to get 2D rendering context for canvas.");
293
- }
294
-
295
- canvas.width = 256;
296
- canvas.height = 1;
297
-
298
- const gradient = ctx.createLinearGradient(0, 0, 256, 0);
299
-
300
- for (const stop in colors) {
301
- // Ensure the stop is a valid number, although `addColorStop` can parse strings,
302
- // explicit conversion is safer for object keys if they come from arbitrary sources.
303
- const stopValue = parseFloat(stop);
304
- if (isNaN(stopValue)) {
305
- console.warn(`Invalid stop value for color ramp: ${stop}. Skipping.`);
306
- continue;
307
- }
308
- gradient.addColorStop(stopValue, colors[stop]);
309
- }
310
-
311
- ctx.fillStyle = gradient;
312
- ctx.fillRect(0, 0, 256, 1);
313
-
314
- return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
315
- }
316
-
317
-
318
- /**
319
- * Creates a 1x256 pixel discrete color ramp as a Uint8Array.
320
- * This ramp features sharp transitions between colors at specified thresholds.
321
- * @param values An array of CSS color strings.
322
- * @param thresholds An array of stop positions (0.0-1.0) for the colors.
323
- * @returns A Uint8Array representing the RGBA pixel data of the 1x256 discrete color ramp.
324
- */
325
- export function getColorRampDiscrate(values: string[], thresholds: number[]): Uint8Array {
326
- const canvas = document.createElement('canvas');
327
- const ctx = canvas.getContext('2d');
328
-
329
- if (!ctx) {
330
- throw new Error("Failed to get 2D rendering context for canvas.");
331
- }
332
-
333
- canvas.width = 256;
334
- canvas.height = 1;
335
-
336
- const gap = 1.0 / 256; // Represents one pixel width in normalized coordinates
337
-
338
- const gradient = ctx.createLinearGradient(0, 0, 256, 0);
339
-
340
- for (let i = 0; i < thresholds.length - 1; i++) {
341
- gradient.addColorStop(thresholds[i], values[i]);
342
- // Create a sharp transition by setting the next stop just before the next threshold
343
- gradient.addColorStop(Math.max(0, thresholds[i + 1] - gap), values[i]);
344
- }
345
- // Add the final color for the last segment
346
- gradient.addColorStop(thresholds[thresholds.length - 1], values[values.length - 1]);
347
-
348
- ctx.fillStyle = gradient;
349
- ctx.fillRect(0, 0, 256, 1);
350
-
351
- return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
352
- }
353
-
354
-
355
- /**
356
- * Creates a 1x256 pixel interpolated color ramp (smooth gradient) as a Uint8Array.
357
- * @param values An array of CSS color strings.
358
- * @param thresholds An array of stop positions (0.0-1.0) for the colors.
359
- * @returns A Uint8Array representing the RGBA pixel data of the 1x256 interpolated color ramp.
360
- */
361
- export function getColorRampInterpolated(values: string[], thresholds: number[]): Uint8Array {
362
- const canvas = document.createElement('canvas');
363
- const ctx = canvas.getContext('2d');
364
-
365
- if (!ctx) {
366
- throw new Error("Failed to get 2D rendering context for canvas.");
367
- }
368
-
369
- canvas.width = 256;
370
- canvas.height = 1;
371
-
372
- const gradient = ctx.createLinearGradient(0, 0, 256, 0);
373
-
374
- for (let i = 0; i < thresholds.length; i++) {
375
- gradient.addColorStop(thresholds[i], values[i]);
376
- }
377
-
378
- ctx.fillStyle = gradient;
379
- ctx.fillRect(0, 0, 256, 1);
380
-
381
- return new Uint8Array(ctx.getImageData(0, 0, 256, 1).data);
382
- }
383
-
384
-
385
- /**
386
- * Creates a 1x256 pixel color ramp based on the specified mode (discrete or interpolated).
387
- * @param values An array of color hex values (e.g., ["#ff0000", "#00ff00", "#0000ff"]).
388
- * @param thresholds An array of thresholds (0.0-1.0) for the colors.
389
- * @param mode The ramp mode: "discrete" for sharp transitions, "interpolated" for smooth transitions (default).
390
- * @returns A Uint8Array representing the RGBA pixel data of the 1x256 color ramp.
391
- * @throws An error if an invalid mode is provided.
392
- */
393
- export function getColorRampModed(values: string[], thresholds: number[], mode: "discrete" | "interpolated" = "interpolated"): Uint8Array {
394
- if (mode === "discrete") {
395
- return getColorRampDiscrate(values, thresholds);
396
- } else if (mode === "interpolated") {
397
- return getColorRampInterpolated(values, thresholds);
398
- } else {
399
- throw new Error("mode is not valid. Expected 'discrete' or 'interpolated'.");
400
- }
401
- }
402
-
403
-
404
-
405
- /**
406
- * Returns a default interpolated color ramp commonly used for visualizations.
407
- * @returns A Uint8Array representing the RGBA pixel data of the default 1x256 color ramp.
408
- */
409
- export function defaultColorRamp(): Uint8Array {
410
- const defaultRampColors: { [stop: string]: string } = {
411
- "0.0": '#5e4fa2',
412
- "0.15": '#3288bd',
413
- "0.20": '#66c2a5',
414
- "0.25": '#66c2a5',
415
- "0.3": '#abdda4',
416
- "0.4": '#e6f598',
417
- "0.5": '#fee08b',
418
- "0.6": '#fdae61',
419
- "0.7": '#f46d43',
420
- "1.0": '#ff1e13'
421
- };
422
- return getColorRamp(defaultRampColors);
423
- }
424
-
425
-
426
-
427
- /**
428
- * A method decorator that reloads the current WebGL program after the decorated method executes.
429
- * This is useful for ensuring the correct program is active after a method might change it.
430
- * @returns A method decorator function.
431
- */
432
- export function reloadCurrentGLProgram() {
433
- return function (target: any, key: string, descriptor: PropertyDescriptor) {
434
- const originalMethod = descriptor.value;
435
-
436
- // Ensure the target has a 'gl' property of type WebGL2RenderingContext
437
- if (!('gl' in target) || !(target.gl instanceof WebGL2RenderingContext)) {
438
- console.warn(`Decorator 'reloadCurrentGLProgram' applied to a method where 'this.gl' is not a WebGL2RenderingContext. This may not function as expected.`);
439
- // Optionally, throw an error here if strictness is desired
440
- }
441
-
442
- descriptor.value = function (this: { gl: WebGL2RenderingContext } & any, ...args: any[]) {
443
- const gl = this.gl;
444
- if (!gl) {
445
- console.error("reloadCurrentGLProgram decorator: 'gl' context not found on 'this'.");
446
- return originalMethod.apply(this, args);
447
- }
448
-
449
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
450
- originalMethod.apply(this, args);
451
- gl.useProgram(currentProgram);
452
- };
453
-
454
- return descriptor;
455
- };
456
- }