@pirireis/webglobeplugins 0.12.0-alpha → 0.14.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.
Files changed (68) hide show
  1. package/Math/arc-cdf-points.js +20 -0
  2. package/Math/arc-generate-points copy.js +1 -0
  3. package/Math/arc.js +21 -8
  4. package/Math/circle-cdf-points.js +0 -2
  5. package/Math/circle.js +35 -16
  6. package/Math/templete-shapes/grid-visually-equal.js +66 -0
  7. package/altitude-locator/plugin.js +3 -2
  8. package/bearing-line/plugin.js +1 -2
  9. package/circle-line-chain/plugin.js +4 -7
  10. package/compass-rose/compass-rose-padding-flat.js +12 -0
  11. package/package.json +1 -1
  12. package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
  13. package/programs/line-on-globe/linestrip/data.js +4 -0
  14. package/programs/line-on-globe/{linestrip.js → linestrip/linestrip.js} +37 -35
  15. package/programs/line-on-globe/naive-accurate-flexible.js +23 -16
  16. package/programs/picking/pickable-renderer.js +1 -2
  17. package/programs/rings/distancering/circleflatprogram.js +116 -120
  18. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +1 -1
  19. package/programs/rings/distancering/circlepaddysharedbuffer.js +368 -354
  20. package/programs/rings/distancering/index.js +6 -5
  21. package/programs/rings/distancering/paddyflatprogram.js +127 -136
  22. package/programs/rings/distancering/paddyflatprogram2d.js +129 -138
  23. package/programs/rings/distancering/paddyflatprogram3d.js +128 -136
  24. package/programs/rings/partial-ring/piece-of-pie copy.js +286 -0
  25. package/programs/rings/partial-ring/piece-of-pie.js +26 -13
  26. package/programs/totems/camerauniformblock.js +1 -1
  27. package/programs/totems/index.js +1 -1
  28. package/programs/vectorfields/logics/pixelbased.js +5 -21
  29. package/range-tools-on-terrain/bearing-line/adapters.js +111 -0
  30. package/range-tools-on-terrain/bearing-line/plugin.js +360 -0
  31. package/range-tools-on-terrain/bearing-line/types.js +1 -0
  32. package/range-tools-on-terrain/circle-line-chain/adapters.js +83 -0
  33. package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +351 -0
  34. package/range-tools-on-terrain/circle-line-chain/plugin.js +389 -0
  35. package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
  36. package/range-tools-on-terrain/range-ring/adapters.js +25 -0
  37. package/range-tools-on-terrain/range-ring/plugin.js +31 -0
  38. package/range-tools-on-terrain/range-ring/types.js +1 -0
  39. package/rangerings/plugin.js +7 -11
  40. package/semiplugins/lightweight/line-plugin.js +195 -0
  41. package/semiplugins/lightweight/piece-of-pie-plugin.js +175 -0
  42. package/semiplugins/shape-on-terrain/arc-plugin.js +368 -0
  43. package/{shape-on-terrain/circle/plugin.js → semiplugins/shape-on-terrain/circle-plugin.js} +129 -68
  44. package/semiplugins/shape-on-terrain/derived/padding-plugin.js +96 -0
  45. package/semiplugins/type.js +1 -0
  46. package/types.js +0 -11
  47. package/util/account/create-buffermap-orchastration.js +39 -0
  48. package/util/account/index.js +2 -2
  49. package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -3
  50. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +14 -3
  51. package/util/build-strategy/static-dynamic.js +1 -1
  52. package/util/check/typecheck.js +15 -1
  53. package/util/geometry/index.js +3 -2
  54. package/util/gl-util/buffer/attribute-loader.js +2 -5
  55. package/util/gl-util/draw-options/methods.js +4 -5
  56. package/util/webglobjectbuilders.js +4 -9
  57. package/write-text/context-text3.js +17 -0
  58. package/write-text/context-text3old.js +152 -0
  59. package/programs/line-on-globe/circle-accurate.js +0 -175
  60. package/programs/line-on-globe/circle.js +0 -164
  61. package/programs/line-on-globe/to-the-surface.js +0 -109
  62. package/programs/rings/distancering/shader.js +0 -1
  63. package/programs/totems/canvas-webglobe-info1.js +0 -106
  64. package/shape-on-terrain/arc/naive/plugin.js +0 -205
  65. package/util/check/get.js +0 -14
  66. package/util/gl-util/buffer/types.js +0 -1
  67. package/util/gl-util/draw-options/types.js +0 -15
  68. package/util/webglobjectbuilders1.js +0 -219
@@ -0,0 +1,195 @@
1
+ import { LineOnGlobeCache } from "../../programs/line-on-globe/naive-accurate-flexible";
2
+ import { BufferMapOrchestrator } from "../../util/account/create-buffermap-orchastration";
3
+ import { sphereCoord } from "../../util/geometry/index";
4
+ import { constraintFloat } from "../../util/check/typecheck";
5
+ export class LinePlugin {
6
+ id;
7
+ globe = null;
8
+ gl = null;
9
+ program = null;
10
+ vao = null;
11
+ _options;
12
+ _uboHandler = null;
13
+ _bufferOrchestrator = null;
14
+ _freed = false;
15
+ constructor(id, { flatViewOn = true, globeViewOn = true, variativeColorsOn = false, defaultColor = [1, 1, 1, 1], dashedLineOpacityVariativeOn = false, dashedLineRatioVariativeOn = false, bufferType = "DYNAMIC_DRAW", opacity = 1.0 } = {}) {
16
+ this.id = id;
17
+ this._options = {
18
+ flatViewOn,
19
+ globeViewOn,
20
+ variativeColorsOn,
21
+ defaultColor,
22
+ dashedLineOpacityVariativeOn,
23
+ dashedLineRatioVariativeOn,
24
+ bufferType,
25
+ opacity
26
+ };
27
+ }
28
+ init(globe, gl) {
29
+ this.globe = globe;
30
+ this.gl = gl;
31
+ this.program = LineOnGlobeCache.get(globe);
32
+ this._uboHandler = this.program.createUBO();
33
+ this._bufferOrchestrator = new BufferMapOrchestrator(gl, this._createBufferDetailsMap(), 10 // initial capacity
34
+ );
35
+ this.vao = this.program.createVAO(...this._createSelectBufferNames().map((key) => {
36
+ if (key === null) {
37
+ return null;
38
+ }
39
+ const bufferManagerComp = this._bufferOrchestrator?.bufferManagersMap.get(key);
40
+ if (bufferManagerComp === undefined) {
41
+ throw new Error(`Buffer key ${key} does not exist in bufferManagersMap`);
42
+ }
43
+ const { bufferManager } = bufferManagerComp;
44
+ return {
45
+ stride: 0,
46
+ offset: 0,
47
+ buffer: bufferManager.buffer
48
+ };
49
+ }));
50
+ }
51
+ // PLUGIN INTERFACE METHODS
52
+ insertBulk(items) {
53
+ const { _bufferOrchestrator, globe } = this;
54
+ if (!_bufferOrchestrator || !globe) {
55
+ throw new Error("Buffer orchestrator or globe is not initialized.");
56
+ }
57
+ _bufferOrchestrator.insertBulk(items);
58
+ this.globe?.DrawRender();
59
+ }
60
+ deleteBulk(keys) {
61
+ const { _bufferOrchestrator, globe } = this;
62
+ if (!_bufferOrchestrator || !globe) {
63
+ throw new Error("Buffer orchestrator or globe is not initialized.");
64
+ }
65
+ _bufferOrchestrator.deleteBulk(keys);
66
+ this.globe?.DrawRender();
67
+ }
68
+ setPluginOpacity(opacity) {
69
+ constraintFloat(opacity, 0, 1);
70
+ this._options.opacity = opacity;
71
+ this.globe?.DrawRender();
72
+ }
73
+ setPluginDashedLineRatio(ratio) {
74
+ constraintFloat(ratio, 0, 1);
75
+ this._uboHandler?.updateSingle("dashed_line_ratio", new Float32Array([ratio]));
76
+ this.globe?.DrawRender();
77
+ }
78
+ setPluginDashLineOpacity(opacity) {
79
+ constraintFloat(opacity, 0, 1);
80
+ this._options.dashedLineOpacityVariativeOn = true;
81
+ this._options.defaultColor[3] = opacity; // Update the default color's alpha channel
82
+ this.globe?.DrawRender();
83
+ }
84
+ // GLOBE INTERACTION METHODS
85
+ draw3D() {
86
+ if (this._freed) {
87
+ console.warn("Plugin has been freed, cannot draw.");
88
+ }
89
+ ;
90
+ if (!this.globe || !this.gl || !this.program || !this.vao) {
91
+ throw new Error("Globe, GL context or program is not initialized.");
92
+ }
93
+ const { _bufferOrchestrator, _options, _uboHandler, vao } = this;
94
+ if (!_bufferOrchestrator || !_bufferOrchestrator || !_uboHandler) {
95
+ throw new Error("Buffer orchestrator is not initialized.");
96
+ }
97
+ const { bufferOrchestrator } = _bufferOrchestrator;
98
+ const { flatViewOn, globeViewOn, opacity } = _options;
99
+ const drawOptions = {
100
+ drawRange: {
101
+ first: 0,
102
+ count: bufferOrchestrator.length
103
+ }
104
+ };
105
+ this.gl.disable(this.gl.DEPTH_TEST); // Disable depth test for lines
106
+ const currentGeometry = this.globe.api_GetCurrentGeometry();
107
+ if (currentGeometry === 0 && globeViewOn) {
108
+ // @ts-ignore
109
+ this.program.draw(vao, drawOptions, opacity, _uboHandler);
110
+ }
111
+ else if (currentGeometry === 1 && flatViewOn) {
112
+ // @ts-ignore
113
+ this.program.draw(vao, drawOptions, opacity, _uboHandler);
114
+ }
115
+ this.gl.enable(this.gl.DEPTH_TEST); // Re-enable depth test after drawing
116
+ }
117
+ free() {
118
+ if (this._freed)
119
+ return;
120
+ // TODO: FILL
121
+ this._bufferOrchestrator?.free();
122
+ this._uboHandler?.free();
123
+ LineOnGlobeCache.release(this.globe);
124
+ this._freed = true;
125
+ }
126
+ // IMPLICIT INTERFACE METHODS
127
+ _createBufferDetailsMap() {
128
+ const globe = this.globe;
129
+ const { flatViewOn, globeViewOn, variativeColorsOn, dashedLineOpacityVariativeOn, dashedLineRatioVariativeOn, bufferType = "DYNAMIC_DRAW" } = this._options;
130
+ const m = new Map();
131
+ if (flatViewOn) {
132
+ m.set("start_position", {
133
+ itemSize: 2,
134
+ bufferType: bufferType, // TODO: Ask User?
135
+ buffer: null,
136
+ adaptor: (item) => {
137
+ const result = new Float32Array(globe.api_GetMercator2DPoint(item.start[0], item.start[1]));
138
+ return result;
139
+ }
140
+ });
141
+ m.set("end_position", {
142
+ itemSize: 2,
143
+ bufferType: bufferType,
144
+ buffer: null,
145
+ adaptor: (item) => new Float32Array(globe.api_GetMercator2DPoint(item.end[0], item.end[1]))
146
+ });
147
+ }
148
+ if (globeViewOn) {
149
+ m.set("start_position_3d", {
150
+ itemSize: 3,
151
+ bufferType: bufferType,
152
+ adaptor: (item) => sphereCoord(item.start[0], item.start[1], globe, item.start_altitude || 0)
153
+ });
154
+ m.set("end_position_3d", {
155
+ itemSize: 3,
156
+ bufferType: bufferType,
157
+ adaptor: (item) => sphereCoord(item.end[0], item.end[1], globe, item.end_altitude || 0)
158
+ });
159
+ }
160
+ if (variativeColorsOn) {
161
+ m.set("color", {
162
+ itemSize: 4,
163
+ bufferType: bufferType,
164
+ adaptor: (item) => new Float32Array(item.color !== undefined ? item.color : [-1, -1, -1, -1])
165
+ });
166
+ }
167
+ if (dashedLineOpacityVariativeOn) {
168
+ m.set("dashed_line_opacity", {
169
+ itemSize: 1,
170
+ bufferType: bufferType,
171
+ adaptor: (item) => new Float32Array(item.dashed_line_opacity !== undefined ? [item.dashed_line_opacity] : [-1])
172
+ });
173
+ }
174
+ if (dashedLineRatioVariativeOn) {
175
+ m.set("dashed_line_ratio", {
176
+ itemSize: 1,
177
+ bufferType: bufferType,
178
+ adaptor: (item) => new Float32Array(item.dashed_line_ratio !== undefined ? [item.dashed_line_ratio] : [-1])
179
+ });
180
+ }
181
+ return m;
182
+ }
183
+ _createSelectBufferNames() {
184
+ const { flatViewOn, globeViewOn, variativeColorsOn, dashedLineOpacityVariativeOn, dashedLineRatioVariativeOn } = this._options;
185
+ return [
186
+ flatViewOn ? "start_position" : null,
187
+ globeViewOn ? "start_position_3d" : null,
188
+ flatViewOn ? "end_position" : null,
189
+ globeViewOn ? "end_position_3d" : null,
190
+ dashedLineOpacityVariativeOn ? "dashed_line_opacity" : null,
191
+ dashedLineRatioVariativeOn ? "dashed_line_ratio" : null,
192
+ variativeColorsOn ? "color" : null
193
+ ];
194
+ }
195
+ }
@@ -0,0 +1,175 @@
1
+ import { PieceOfPieProgramCache } from "../../programs/rings/partial-ring/piece-of-pie";
2
+ import { BufferManager, BufferOrchestrator } from "../../util/account/single-attribute-buffer-management/index";
3
+ import { sphereCoord } from "../../util/geometry/index";
4
+ import { opacityCheck } from "../../util/check/typecheck";
5
+ const INITIAL_CAPACITY = 10; // Initial capacity for the buffer orchestrator
6
+ const EDGE_COUNT = 100; // Number of edges for the pie chart
7
+ const Radians = Math.PI / 180; // Conversion factor from degrees to radians
8
+ export class PieceOfPiePlugin {
9
+ id;
10
+ _isFreed = false;
11
+ globe = null;
12
+ gl = null;
13
+ program = null;
14
+ vao = null;
15
+ bufferManagersMap = null;
16
+ bufferOrchestrator = new BufferOrchestrator({ capacity: INITIAL_CAPACITY });
17
+ drawMode = "BOTH";
18
+ opacity = 1;
19
+ _pluginOptions = {
20
+ bufferType: "STATIC_DRAW",
21
+ initialCapacity: INITIAL_CAPACITY,
22
+ defaultAltitude: 0, // Default altitude is ground level
23
+ };
24
+ constructor(id, options = {}) {
25
+ this.id = id;
26
+ options.bufferType && (this._pluginOptions.bufferType = options.bufferType);
27
+ options.initialCapacity && (this._pluginOptions.initialCapacity = options.initialCapacity);
28
+ options.defaultAltitude && (this._pluginOptions.defaultAltitude = options.defaultAltitude);
29
+ }
30
+ insertBulk(items) {
31
+ this.bufferOrchestrator.insertBulk(items, this.bufferManagersMap);
32
+ this.globe?.DrawRender();
33
+ }
34
+ deleteBulk(keys) {
35
+ this.bufferOrchestrator.deleteBulk(keys, this.bufferManagersMap);
36
+ this.globe?.DrawRender();
37
+ }
38
+ setPluginOpacity(opacity) {
39
+ opacityCheck(opacity);
40
+ this.opacity = opacity;
41
+ this.globe?.DrawRender();
42
+ }
43
+ setDrawMode(drawMode) {
44
+ if (drawMode !== "TRIANGLE_FAN" && drawMode !== "LINE_STRIP" && drawMode !== "BOTH") {
45
+ throw new Error("Invalid draw mode. Use 'TRIANGLE_FAN' or 'LINE_STRIP'.");
46
+ }
47
+ this.drawMode = drawMode;
48
+ this.globe?.DrawRender();
49
+ }
50
+ _createBufferManagersMap() {
51
+ const { gl, globe, _pluginOptions } = this;
52
+ const { bufferType, initialCapacity } = _pluginOptions;
53
+ if (!gl || !globe) {
54
+ throw new Error("Globe and WebGL context must be initialized before creating buffer management map.");
55
+ }
56
+ const bufferManagersMap = new Map([
57
+ ["centerCoords2d", {
58
+ bufferManager: new BufferManager(this.gl, 2, { bufferType: bufferType, initialCapacity }),
59
+ adaptor: (item) => new Float32Array(globe.api_GetMercator2DPoint(item.center[0], item.center[1])),
60
+ }],
61
+ ["centerCoords3d", {
62
+ bufferManager: new BufferManager(gl, 3, { bufferType, initialCapacity }),
63
+ adaptor: (item) => sphereCoord(item.center[0], item.center[1], globe, (item.altitude ?? this._pluginOptions.defaultAltitude) / 1000)
64
+ }],
65
+ ["startAngle2d", {
66
+ bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
67
+ adaptor: (item) => {
68
+ if (item.startAngle2D === undefined) {
69
+ return new Float32Array([0]); // Default angle if not provided
70
+ }
71
+ return new Float32Array([(item.startAngle2D) * Radians]);
72
+ }
73
+ }],
74
+ ["tailAngle2d", {
75
+ bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
76
+ adaptor: (item) => {
77
+ if (item.coverAngle2D === undefined) {
78
+ return new Float32Array([0]); // Default angle if not provided
79
+ }
80
+ return new Float32Array([item.coverAngle2D * Radians]);
81
+ }
82
+ }],
83
+ ["startAngle3d", {
84
+ bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
85
+ adaptor: (item) => {
86
+ if (item.startAngle3D === undefined) {
87
+ return new Float32Array([0]); // Default angle if not provided
88
+ }
89
+ return new Float32Array([item.startAngle3D * Radians]);
90
+ }
91
+ }],
92
+ ["tailAngle3d", {
93
+ bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
94
+ adaptor: (item) => {
95
+ if (item.coverAngle3D === undefined) {
96
+ return new Float32Array([0]); // Default angle if not provided
97
+ }
98
+ return new Float32Array([item.coverAngle3D * Radians]);
99
+ }
100
+ }],
101
+ ["fillingMode", {
102
+ bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
103
+ adaptor: (item) => new Float32Array([item.fillingMode ?? 0])
104
+ }],
105
+ ["rgba", {
106
+ bufferManager: new BufferManager(gl, 4, { bufferType, initialCapacity }),
107
+ adaptor: (item) => {
108
+ if (!item.color || item.color.length === 0) {
109
+ return new Float32Array([1, 1, 1, 1]); // Default color if none provided
110
+ }
111
+ return new Float32Array(item.color);
112
+ }
113
+ }
114
+ ],
115
+ ["radius", {
116
+ bufferManager: new BufferManager(gl, 1, { bufferType, initialCapacity }),
117
+ adaptor: (item) => new Float32Array([item.radius])
118
+ }],
119
+ ]);
120
+ this.bufferManagersMap = bufferManagersMap;
121
+ }
122
+ init(globe, gl) {
123
+ this.globe = globe;
124
+ this.gl = gl;
125
+ this.program = PieceOfPieProgramCache.get(globe);
126
+ this._createBufferManagersMap();
127
+ this.vao = this.program.createVAO(
128
+ //@ts-ignore
129
+ ...['centerCoords2d',
130
+ 'centerCoords3d',
131
+ 'startAngle2d',
132
+ 'tailAngle2d',
133
+ 'startAngle3d',
134
+ 'tailAngle3d',
135
+ 'rgba',
136
+ 'radius',
137
+ 'fillingMode'].map((name) => {
138
+ const buffer = this.bufferManagersMap?.get(name)?.bufferManager.buffer;
139
+ return {
140
+ buffer: buffer,
141
+ stride: 0,
142
+ offset: 0,
143
+ };
144
+ }));
145
+ }
146
+ draw3D() {
147
+ if (!this.gl || !this.program || !this.vao || !this.globe) {
148
+ console.warn("PieChartPlugin is not initialized properly.");
149
+ return;
150
+ }
151
+ const length = this.bufferOrchestrator.length;
152
+ console.log("Drawing PieChartPlugin with length:", length);
153
+ this.gl.disable(this.gl.DEPTH_TEST);
154
+ if (this.drawMode === "BOTH") {
155
+ this.program?.draw(length, this.vao, EDGE_COUNT, this.opacity, "LINE_STRIP");
156
+ this.program?.draw(length, this.vao, EDGE_COUNT, this.opacity, "TRIANGLE_FAN");
157
+ }
158
+ else {
159
+ this.program?.draw(length, this.vao, EDGE_COUNT, this.opacity, this.drawMode);
160
+ }
161
+ this.gl.enable(this.gl.DEPTH_TEST);
162
+ }
163
+ free() {
164
+ if (this._isFreed) {
165
+ console.warn("PieChartPlugin is already freed.");
166
+ return;
167
+ }
168
+ PieceOfPieProgramCache.release(this.globe);
169
+ this.gl?.deleteVertexArray(this.vao);
170
+ this._isFreed = true;
171
+ this.globe = null;
172
+ this.gl = null;
173
+ this.program = null;
174
+ }
175
+ }