@pirireis/webglobeplugins 0.9.9 → 0.9.10

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 (211) hide show
  1. package/Math/angle-calculation.js +15 -0
  2. package/Math/arc.js +65 -0
  3. package/Math/bounds/line-bbox.js +188 -0
  4. package/Math/constants.js +9 -0
  5. package/Math/frustum/camera.js +24 -0
  6. package/Math/frustum/from-globeinfo.js +48 -0
  7. package/Math/frustum/types.js +2 -0
  8. package/Math/globe-util/horizon-plane.js +112 -0
  9. package/Math/index.js +1 -0
  10. package/Math/juction/arc-plane.js +83 -0
  11. package/Math/juction/line-sphere.js +25 -0
  12. package/Math/juction/plane-plane.js +58 -0
  13. package/Math/line.js +56 -0
  14. package/Math/matrix4.js +1 -0
  15. package/Math/methods.js +201 -0
  16. package/Math/plane.js +60 -0
  17. package/Math/quaternion.js +104 -0
  18. package/Math/types.js +2 -0
  19. package/Math/utils.js +4 -0
  20. package/Math/vec3.js +126 -0
  21. package/algorithms/search-binary.js +19 -0
  22. package/altitude-locator/adaptors.js +1 -0
  23. package/altitude-locator/draw-subset-obj.js +18 -0
  24. package/altitude-locator/keymethod.js +1 -0
  25. package/altitude-locator/plugin.js +341 -0
  26. package/altitude-locator/types.js +23 -0
  27. package/arrowfield/adaptor.js +14 -0
  28. package/arrowfield/index.js +10 -0
  29. package/arrowfield/plugin.js +86 -0
  30. package/bearing-line/index.js +8 -0
  31. package/bearing-line/plugin.js +449 -0
  32. package/circle-line-chain/chain-list-map.js +205 -0
  33. package/circle-line-chain/init.js +1 -0
  34. package/circle-line-chain/plugin.js +424 -0
  35. package/circle-line-chain/util.js +5 -0
  36. package/compass-rose/compass-rose-padding-flat.js +225 -0
  37. package/compass-rose/compass-text-writer.js +153 -0
  38. package/compass-rose/index.js +7 -0
  39. package/compassrose/compassrose.js +296 -0
  40. package/compassrose/index.js +8 -0
  41. package/globe-types.js +1 -0
  42. package/heatwave/index.js +10 -0
  43. package/heatwave/isobar/objectarraylabels.js +202 -0
  44. package/heatwave/isobar/plugin.js +343 -0
  45. package/heatwave/isobar/quadtreecontours.js +300 -0
  46. package/heatwave/plugins/heatwaveglobeshell.js +206 -0
  47. package/jest.config.js +7 -0
  48. package/package.json +4 -4
  49. package/partialrings/buffer-manager.js +81 -0
  50. package/partialrings/index.js +41 -0
  51. package/partialrings/plugin.js +135 -0
  52. package/partialrings/program.js +286 -0
  53. package/pin/pin-object-array.js +305 -0
  54. package/pin/pin-point-totem.js +60 -0
  55. package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +66 -0
  56. package/point-heat-map/index.js +1 -0
  57. package/point-heat-map/plugin-webworker.js +126 -0
  58. package/point-heat-map/point-to-heat-map-flow.js +127 -0
  59. package/point-tracks/key-methods.js +5 -0
  60. package/point-tracks/plugin.js +338 -0
  61. package/programs/arrowfield/index.js +7 -0
  62. package/programs/arrowfield/logic.js +257 -0
  63. package/programs/arrowfield/object.js +66 -0
  64. package/programs/data2legend/density-to-legend.js +101 -0
  65. package/programs/data2legend/point-to-density-texture.js +100 -0
  66. package/programs/float2legendwithratio/index.js +8 -0
  67. package/programs/float2legendwithratio/logic.js +171 -0
  68. package/programs/float2legendwithratio/object.js +110 -0
  69. package/programs/globe-util/is-globe-moved.js +21 -0
  70. package/programs/globeshell/index.js +8 -0
  71. package/programs/globeshell/noise/noises.js +1 -0
  72. package/programs/globeshell/wiggle/index.js +8 -0
  73. package/programs/globeshell/wiggle/logic.js +345 -0
  74. package/programs/globeshell/wiggle/object.js +72 -0
  75. package/programs/helpers/blender/index.js +1 -0
  76. package/programs/helpers/blender/program.js +79 -0
  77. package/programs/helpers/fadeaway/index.js +7 -0
  78. package/programs/helpers/fadeaway/logic.js +72 -0
  79. package/programs/helpers/fadeaway/object.js +20 -0
  80. package/programs/helpers/index.js +8 -0
  81. package/programs/index.js +58 -0
  82. package/programs/interface.js +1 -0
  83. package/programs/line-on-globe/angled-line.js +176 -0
  84. package/programs/line-on-globe/circle-accurate-3d.js +141 -0
  85. package/programs/line-on-globe/circle-accurate-flat.js +216 -0
  86. package/programs/line-on-globe/circle-accurate.js +178 -0
  87. package/programs/line-on-globe/circle.js +167 -0
  88. package/programs/line-on-globe/degree-padding-around-circle-3d.js +159 -0
  89. package/programs/line-on-globe/index.js +1 -0
  90. package/programs/line-on-globe/lines-color-instanced-flat.js +136 -0
  91. package/programs/line-on-globe/linestrip.js +171 -0
  92. package/programs/line-on-globe/naive-accurate-flexible.js +195 -0
  93. package/programs/line-on-globe/to-the-surface.js +111 -0
  94. package/programs/line-on-globe/util.js +8 -0
  95. package/programs/picking/pickable-renderer.js +188 -0
  96. package/programs/point-on-globe/element-globe-surface-glow.js +142 -0
  97. package/programs/point-on-globe/element-point-glow.js +153 -0
  98. package/programs/point-on-globe/square-pixel-point.js +174 -0
  99. package/programs/programcache.js +131 -0
  100. package/programs/rings/distancering/circleflatprogram.js +156 -0
  101. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +369 -0
  102. package/programs/rings/distancering/circlepaddysharedbuffer.js +357 -0
  103. package/programs/rings/distancering/index.js +14 -0
  104. package/programs/rings/distancering/paddyflatprogram.js +172 -0
  105. package/programs/rings/distancering/paddyflatprogram2d.js +174 -0
  106. package/programs/rings/distancering/paddyflatprogram3d.js +172 -0
  107. package/programs/rings/distancering/shader.js +1 -0
  108. package/programs/rings/index.js +17 -0
  109. package/programs/rings/partial-ring/piece-of-pie.js +275 -0
  110. package/programs/totems/camerauniformblock.js +160 -0
  111. package/programs/totems/canvas-webglobe-info.js +110 -0
  112. package/programs/totems/gpu-selection-uniform-block.js +108 -0
  113. package/programs/totems/index.js +40 -0
  114. package/programs/two-d/pixel-circle.js +1 -0
  115. package/programs/two-d/pixel-padding-for-compass.js +162 -0
  116. package/programs/util.js +17 -0
  117. package/programs/vectorfields/index.js +23 -0
  118. package/programs/vectorfields/logics/drawrectangleparticles.js +107 -0
  119. package/programs/vectorfields/logics/index.js +12 -0
  120. package/programs/vectorfields/logics/pixelbased.js +142 -0
  121. package/programs/vectorfields/logics/ubo.js +63 -0
  122. package/programs/vectorfields/pingpongbuffermanager.js +76 -0
  123. package/rangerings/enum.js +5 -0
  124. package/rangerings/index.js +15 -0
  125. package/rangerings/plugin.js +560 -0
  126. package/rangerings/rangeringangletext.js +329 -0
  127. package/rangerings/ring-account.js +117 -0
  128. package/shaders/fragment-toy/firework.js +58 -0
  129. package/shaders/fragment-toy/singularity.js +59 -0
  130. package/shape-on-terrain/arc/naive/plugin.js +252 -0
  131. package/timetracks/adaptors-line-strip.js +71 -0
  132. package/timetracks/adaptors.js +122 -0
  133. package/timetracks/index.js +19 -0
  134. package/timetracks/plugin-line-strip.js +250 -0
  135. package/timetracks/plugin.js +258 -0
  136. package/timetracks/program-line-strip.js +611 -0
  137. package/timetracks/program.js +772 -0
  138. package/timetracks/programpoint-line-strip.js +154 -0
  139. package/timetracks/programpoint.js +147 -0
  140. package/types.js +15 -0
  141. package/util/account/bufferoffsetmanager.js +179 -0
  142. package/util/account/index.js +23 -0
  143. package/util/account/single-attribute-buffer-management/buffer-manager.js +108 -0
  144. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +150 -0
  145. package/util/account/single-attribute-buffer-management/index.js +9 -0
  146. package/util/account/single-attribute-buffer-management/object-store.js +51 -0
  147. package/util/account/single-attribute-buffer-management/types.js +2 -0
  148. package/util/account/util.js +22 -0
  149. package/util/algorithms/index.js +1 -0
  150. package/util/algorithms/search-binary.js +28 -0
  151. package/util/check/get.js +18 -0
  152. package/util/check/index.js +1 -0
  153. package/util/check/typecheck.js +49 -0
  154. package/util/geometry/index.js +51 -0
  155. package/util/gl-util/buffer/attribute-loader.js +69 -0
  156. package/util/gl-util/buffer/index.js +6 -0
  157. package/util/gl-util/buffer/types.js +1 -0
  158. package/util/gl-util/draw-options/methods.js +38 -0
  159. package/util/gl-util/draw-options/types.js +15 -0
  160. package/util/gl-util/uniform-block/manager.js +156 -0
  161. package/util/gl-util/uniform-block/shader.js +1 -0
  162. package/util/gl-util/uniform-block/types.js +8 -0
  163. package/util/heatwavedatamanager/datamanager.js +152 -0
  164. package/util/heatwavedatamanager/index.js +10 -0
  165. package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +122 -0
  166. package/util/heatwavedatamanager/pointcoordsmeta.js +20 -0
  167. package/util/index.js +57 -0
  168. package/util/interpolation/index.js +1 -0
  169. package/util/interpolation/timetrack/index.js +5 -0
  170. package/util/interpolation/timetrack/timetrack-interpolator.js +79 -0
  171. package/util/interpolation/timetrack/web-worker-str.js +183 -0
  172. package/util/interpolation/timetrack/web-worker.js +48 -0
  173. package/util/jshelpers/data-filler.js +20 -0
  174. package/util/jshelpers/equality.js +20 -0
  175. package/util/jshelpers/index.js +37 -0
  176. package/util/jshelpers/timefilters.js +32 -0
  177. package/util/picking/fence.js +46 -0
  178. package/util/picking/picker-displayer.js +139 -0
  179. package/util/programs/draw-texture-on-canvas.js +89 -0
  180. package/util/programs/index.js +17 -0
  181. package/util/programs/shapesonglobe.js +214 -0
  182. package/util/programs/supersampletotextures.js +113 -0
  183. package/util/programs/texturetoglobe.js +182 -0
  184. package/util/shaderfunctions/geometrytransformations.js +340 -0
  185. package/util/shaderfunctions/index.js +18 -0
  186. package/util/shaderfunctions/nodata.js +11 -0
  187. package/util/shaderfunctions/noisefunctions.js +43 -0
  188. package/util/surface-line-data/arc-bboxes.js +25 -0
  189. package/util/surface-line-data/arcs-to-cuts.js +50 -0
  190. package/util/surface-line-data/cut-arc.js +1 -0
  191. package/util/surface-line-data/flow.js +28 -0
  192. package/util/surface-line-data/rbush-manager.js +1 -0
  193. package/util/surface-line-data/types.js +1 -0
  194. package/util/surface-line-data/web-worker.js +1 -0
  195. package/util/webglobe/gldefaultstates.js +7 -0
  196. package/util/webglobe/index.js +18 -0
  197. package/util/webglobe/rasteroverlay.js +78 -0
  198. package/util/webglobjectbuilders.js +388 -0
  199. package/util/webglobjectbuilders1.js +237 -0
  200. package/waveparticles/adaptor.js +17 -0
  201. package/waveparticles/index.js +10 -0
  202. package/waveparticles/plugin.js +266 -0
  203. package/wind/imagetovectorfieldandmagnitude.js +35 -0
  204. package/wind/index.js +14 -0
  205. package/wind/plugin.js +926 -0
  206. package/wind/vectorfieldimage.js +25 -0
  207. package/write-text/attached-text-writer.js +91 -0
  208. package/write-text/context-text.js +98 -0
  209. package/write-text/context-text3.js +155 -0
  210. package/write-text/index.js +5 -0
  211. package/write-text/writer-plugin.js +8 -0
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webworkerStr = void 0;
4
+ const webworkerStr = `
5
+
6
+ const WORLD_RADIUS_3D = 6378.137;
7
+ const WORLD_RADIUS_MERCATOR = 6378136.99911;
8
+
9
+ const dot3 = (a, b) => {
10
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
11
+ }
12
+
13
+ const sphericalLinearInterpolation_UnitVector = (normalizedA, normalizedB, ratio) => {
14
+ const theta = Math.acos(dot3(normalizedA, normalizedB));
15
+ if (theta < 0.000001) return normalizedA; // CALIBRATE?
16
+ const sinTheta = Math.sin(theta);
17
+ const result = [
18
+ (Math.sin((1.0 - ratio) * theta) * normalizedA[0] + Math.sin(ratio * theta) * normalizedB[0]) / sinTheta,
19
+ (Math.sin((1.0 - ratio) * theta) * normalizedA[1] + Math.sin(ratio * theta) * normalizedB[1]) / sinTheta,
20
+ (Math.sin((1.0 - ratio) * theta) * normalizedA[2] + Math.sin(ratio * theta) * normalizedB[2]) / sinTheta
21
+ ];
22
+ return result;
23
+ }
24
+
25
+ const radianToMercator = (xy) => {
26
+ return [WORLD_RADIUS_MERCATOR * xy[0], WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + xy[1] / 2))];
27
+ }
28
+
29
+
30
+ const cartesian3dToRadian = (cartesian) => {
31
+ const x = cartesian[0];
32
+ const y = cartesian[1];
33
+ const z = cartesian[2];
34
+ // const length = Math.sqrt(x * x + y * y + z * z);
35
+ const long = Math.atan2(y, x);
36
+ const lat = Math.asin(z)// length);
37
+ return [long, lat];
38
+ }
39
+
40
+
41
+ const sphericalLinearInterpolation_Mercator = (normalizedA, normalizedB, ratio) => {
42
+ const unitVector = sphericalLinearInterpolation_UnitVector(normalizedA, normalizedB, ratio);
43
+ const angles = cartesian3dToRadian(unitVector);
44
+ return radianToMercator(angles);
45
+ }
46
+
47
+ const sphericalLinearInterpolation_Cartesian3d = (a, b, ratio) => {
48
+ const unitVector = sphericalLinearInterpolation_UnitVector(a, b, ratio);
49
+ const height = a[3] + (b[3] - a[3]) * ratio;
50
+ return [unitVector[0] * height, unitVector[1] * height, unitVector[2] * height];
51
+ }
52
+
53
+ const findFirstIndexInRange = (container, value) => {
54
+ let start = 0;
55
+ let end = container.length - 1;
56
+ let mid = 0;
57
+ while (start <= end) {
58
+ mid = Math.floor((start + end) / 2);
59
+ if (container[mid] <= value && value <= container[mid + 1]) return mid;
60
+ if (container[mid] < value) start = mid + 1;
61
+ else end = mid - 1;
62
+ }
63
+ return null;
64
+ }
65
+
66
+ const GEOMETRY = Object.freeze({
67
+ CARTESIAN3D: 0,
68
+ MERCATOR: 1,
69
+ });
70
+
71
+ class TimeTrackInterpolator {
72
+ /**
73
+ * @typedef Timetrack
74
+ * @property {Array<vec4>}} coordinates [x,y,z, length]
75
+ * @property {Array<Number>} times
76
+ * @param {Array<Timetrack>} timeTracks
77
+ */
78
+ constructor({ timeTracks, bbox = null, geometry = GEOMETRY.CARTESIAN3D } = {}) {
79
+ this.timeTracks = null;
80
+ this.timeTracksStartTimes = null;
81
+ this.geometry = geometry;
82
+ if (timeTracks) this.setTimetracks(timeTracks);
83
+ if (bbox) this.setBbox(bbox);
84
+ }
85
+
86
+
87
+ setGeometry(geometry) {
88
+ if (geometry !== GEOMETRY.CARTESIAN3D && geometry !== GEOMETRY.MERCATOR) {
89
+ throw new Error('Invalid geometry');
90
+ }
91
+ this.geometry = geometry;
92
+ }
93
+
94
+ setTimetracks(timeTracks) {
95
+ this.timeTracks = timeTracks;
96
+ }
97
+
98
+
99
+ interpolate(time) {
100
+ const { timeTracks, geometry } = this;
101
+ if (!timeTracks) { return null; }
102
+ const resultArray = [];
103
+ const info = {
104
+ outOfRange: 0,
105
+ processed: 0,
106
+ }
107
+ for (let i = 0; i < timeTracks.length; i++) {
108
+ const { times, coordinates } = timeTracks[i];
109
+
110
+ if (times[times.length - 1] < time) continue;
111
+ info.processed++;
112
+ const timeIndex = findFirstIndexInRange(times, time);
113
+ if (timeIndex === null) { info.outOfRange++; continue; }
114
+ const timeFraction = (time - times[timeIndex]) / (times[timeIndex + 1] - times[timeIndex]);
115
+ const interpolated = (geometry === GEOMETRY.CARTESIAN3D) ?
116
+ sphericalLinearInterpolation_Cartesian3d(coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction) :
117
+ sphericalLinearInterpolation_Mercator(coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction);
118
+ resultArray.push(...interpolated);
119
+ }
120
+ return new Float32Array(resultArray);
121
+ }
122
+
123
+
124
+ // implicit methods
125
+
126
+ _orderTimeTracks() {
127
+ this.timeTracks.sort((a, b) => a.times[0] - b.times[0]);
128
+ }
129
+
130
+ _setStartTimes() {
131
+ this.timeTracksStartTimes = this.timeTracks.map(tt => tt.times[0]);
132
+ }
133
+ }
134
+
135
+ const interpolator = new TimeTrackInterpolator({ geometry: GEOMETRY.CARTESIAN3D });
136
+
137
+ /* eslint-disable-next-line no-restricted-globals */
138
+ self.onmessage = function (e) {
139
+
140
+ const { geometry = null, timeTracks = null, time = null } = e.data;
141
+
142
+ if (geometry !== null) {
143
+ try {
144
+ interpolator.setGeometry(geometry);
145
+ } catch (error) {
146
+ /* eslint-disable-next-line no-restricted-globals */
147
+ self.postMessage({ error: error.message });
148
+ return;
149
+ }
150
+ }
151
+
152
+ if (timeTracks !== null) {
153
+ try {
154
+ interpolator.setTimetracks(timeTracks);
155
+ } catch (error) {
156
+ /* eslint-disable-next-line no-restricted-globals */
157
+ self.postMessage({ error: error.message });
158
+ return;
159
+ }
160
+ }
161
+
162
+ if (time !== null) {
163
+ try {
164
+ const result = interpolator.interpolate(time);
165
+ if(result === null) {
166
+ /* eslint-disable-next-line no-restricted-globals */
167
+ self.postMessage({ error: 'No TimeTracks Data' });
168
+ return;
169
+ }
170
+ /* eslint-disable-next-line no-restricted-globals */
171
+ self.postMessage(result, [result.buffer]);
172
+ return;
173
+ } catch (error) {
174
+ /* eslint-disable-next-line no-restricted-globals */
175
+ self.postMessage({ error: error.message });
176
+ return;
177
+ }
178
+ }
179
+ /* eslint-disable-next-line no-restricted-globals */
180
+ self.postMessage(true);
181
+ }
182
+ `;
183
+ exports.webworkerStr = webworkerStr;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const timetrack_interpolator_1 = require("./timetrack-interpolator");
4
+ const interpolator = new timetrack_interpolator_1.TimeTrackInterpolator({ geometry: timetrack_interpolator_1.GEOMETRY.CARTESIAN3D });
5
+ /* eslint-disable-next-line no-restricted-globals */
6
+ self.onmessage = function (e) {
7
+ const { geometry = null, timeTracks = null, time = null } = e.data;
8
+ if (geometry !== null) {
9
+ try {
10
+ interpolator.setGeometry(geometry);
11
+ }
12
+ catch (error) {
13
+ /* eslint-disable-next-line no-restricted-globals */
14
+ self.postMessage({ error: error.message });
15
+ return;
16
+ }
17
+ }
18
+ if (timeTracks !== null) {
19
+ try {
20
+ interpolator.setTimetracks(timeTracks);
21
+ }
22
+ catch (error) {
23
+ /* eslint-disable-next-line no-restricted-globals */
24
+ self.postMessage({ error: error.message });
25
+ return;
26
+ }
27
+ }
28
+ if (time !== null) {
29
+ try {
30
+ const result = interpolator.interpolate(time);
31
+ if (result === null) {
32
+ /* eslint-disable-next-line no-restricted-globals */
33
+ self.postMessage({ error: 'No TimeTracks Data' });
34
+ return;
35
+ }
36
+ /* eslint-disable-next-line no-restricted-globals */
37
+ self.postMessage(result, [result.buffer]);
38
+ return;
39
+ }
40
+ catch (error) {
41
+ /* eslint-disable-next-line no-restricted-globals */
42
+ self.postMessage({ error: error.message });
43
+ return;
44
+ }
45
+ }
46
+ /* eslint-disable-next-line no-restricted-globals */
47
+ self.postMessage(true);
48
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.populateFloat32Array = void 0;
4
+ const populateFloat32Array = Object.freeze({
5
+ fillFloat32Array: (length, data) => {
6
+ const result = new Float32Array(length);
7
+ result.fill(data);
8
+ return result;
9
+ },
10
+ fillWithListData: (length, listdata) => {
11
+ const result = new Float32Array(length * listdata.length);
12
+ let offset = 0;
13
+ for (let i = 0; i < length; i++) {
14
+ result.set(listdata, offset);
15
+ offset += listdata.length;
16
+ }
17
+ return result;
18
+ }
19
+ });
20
+ exports.populateFloat32Array = populateFloat32Array;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.arraysEqual = arraysEqual;
4
+ function arraysEqual(a, b) {
5
+ if (a === b)
6
+ return true;
7
+ if (a == null || b == null)
8
+ return false;
9
+ if (a.length !== b.length)
10
+ return false;
11
+ // If you don't care about the order of the elements inside
12
+ // the array, you should sort both arrays here.
13
+ // Please note that calling sort on an array will modify that array.
14
+ // you might want to clone your array first.
15
+ for (var i = 0; i < a.length; ++i) {
16
+ if (a[i] !== b[i])
17
+ return false;
18
+ }
19
+ return true;
20
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.timefilters = void 0;
37
+ exports.timefilters = __importStar(require("./timefilters"));
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.instantDebounce = instantDebounce;
4
+ // TODO: fix logic error in instantDebounce
5
+ function instantDebounce(func, delay) {
6
+ let timeout = null;
7
+ let lastArgs = null;
8
+ let runAtEnd = false;
9
+ const timeoutMethod = () => {
10
+ setTimeout(() => {
11
+ if (runAtEnd) {
12
+ func(...lastArgs);
13
+ lastArgs = null;
14
+ // console.log("processed with delay")
15
+ runAtEnd = false;
16
+ }
17
+ timeout = null;
18
+ }, delay);
19
+ };
20
+ return function () {
21
+ if (timeout) {
22
+ lastArgs = arguments;
23
+ runAtEnd = true;
24
+ return;
25
+ }
26
+ else {
27
+ func(...args);
28
+ // console.log("processed instantly")
29
+ timeout = timeoutMethod();
30
+ }
31
+ };
32
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fence = void 0;
4
+ const fence = (gl) => new Promise((resolve, reject) => {
5
+ // This will create a fence. If this follows a `readPixels()` call, then it
6
+ // will signal to WebGL that the read instruction should be asynchronous.
7
+ // This means JS can continue to work on other tasks while the read instruction
8
+ // completes.
9
+ const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
10
+ gl.flush();
11
+ // There are TWO possible ways to check on the status of a WebGLSync object.
12
+ // 1. This will check it using clientWaitSync()
13
+ const checkStatus_v1 = () => {
14
+ const status = gl.clientWaitSync(sync, 0, 0);
15
+ // There are four possible values for status:
16
+ // a. ALREADY_SIGNALED and CONDITION_SATISFIED (done)
17
+ // b. TIMEOUT_EXPIRED (check again later)
18
+ // c. WAIT_FAILED (there was an error)
19
+ if (status === gl.TIMEOUT_EXPIRED) {
20
+ setTimeout(checkStatus_v1, 1);
21
+ }
22
+ else if (status === gl.ALREADY_SIGNALED || status === gl.CONDITION_SATISFIED) {
23
+ gl.deleteSync(sync);
24
+ resolve();
25
+ }
26
+ else {
27
+ gl.deleteSync(sync);
28
+ reject(new Error('Fence did not resolve normally for some reason'));
29
+ }
30
+ };
31
+ // 2. This will check with getSyncParameter(s, gl.SYNC_STATUS)
32
+ const checkStatus_v2 = () => {
33
+ const status = gl.getSyncParameter(sync, gl.SYNC_STATUS);
34
+ // There are only two possible values for status: SIGNALED and UNSIGNALED
35
+ // Note that there is no `error` signal, so there is no reason to use `reject()` here
36
+ if (status === gl.SIGNALED) {
37
+ gl.deleteSync(sync);
38
+ resolve();
39
+ }
40
+ else {
41
+ setTimeout(checkStatus_v2, 1);
42
+ }
43
+ };
44
+ setTimeout(checkStatus_v2, 1);
45
+ });
46
+ exports.fence = fence;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ /**
3
+ * add implicit texture display program for color
4
+ * add fence on query return and return id.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PickerDisplayer = void 0;
8
+ const draw_texture_on_canvas_1 = require("../programs/draw-texture-on-canvas");
9
+ const fence_1 = require("./fence");
10
+ const ESCAPE_VALUE = -1;
11
+ class PickerDisplayer {
12
+ constructor(globe) {
13
+ this.globe = globe;
14
+ this.gl = globe.gl;
15
+ const gl = this.gl;
16
+ this.colorTexture = gl.createTexture(); // bind to color attachment 0
17
+ this.indexTexture = gl.createTexture(); // bind to color attachment 1
18
+ this.fbo = gl.createFramebuffer();
19
+ this._pbo = undefined;
20
+ this._pboSize = 0;
21
+ this.resize();
22
+ this.displayer = draw_texture_on_canvas_1.textureOnCanvasProgramCache.get(this.gl);
23
+ }
24
+ resize(width = null, height = null) {
25
+ if (width === null || height === null) {
26
+ width = this.globe.api_ScrW();
27
+ height = this.globe.api_ScrH();
28
+ }
29
+ const { gl, colorTexture, indexTexture } = this;
30
+ gl.deleteTexture(colorTexture);
31
+ gl.deleteTexture(indexTexture);
32
+ const colorTextureNew = gl.createTexture();
33
+ gl.bindTexture(gl.TEXTURE_2D, colorTextureNew);
34
+ gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, width, height);
35
+ const indexTextureNew = gl.createTexture();
36
+ gl.bindTexture(gl.TEXTURE_2D, indexTextureNew);
37
+ // gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R16I, width, height);
38
+ gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R32I, width, height);
39
+ gl.bindTexture(gl.TEXTURE_2D, null);
40
+ this.colorTexture = colorTextureNew;
41
+ this.indexTexture = indexTextureNew;
42
+ }
43
+ clearTextures() {
44
+ const { gl, colorTexture, indexTexture } = this;
45
+ gl.activeTexture(gl.TEXTURE1);
46
+ gl.bindTexture(gl.TEXTURE_2D, indexTexture);
47
+ gl.clearBufferiv(gl.COLOR, 1, new Int32Array([-1, -1, -1, -1]));
48
+ gl.activeTexture(gl.TEXTURE0);
49
+ gl.bindTexture(gl.TEXTURE_2D, colorTexture);
50
+ gl.clearBufferfv(gl.COLOR, 0, new Float32Array([0, 0, 0, 0]));
51
+ }
52
+ // call before drawing the scene with gl picker shader
53
+ bindFBO() {
54
+ const { gl, colorTexture, indexTexture, fbo } = this;
55
+ gl.activeTexture(gl.TEXTURE1);
56
+ gl.bindTexture(gl.TEXTURE_2D, indexTexture);
57
+ gl.activeTexture(gl.TEXTURE0);
58
+ gl.bindTexture(gl.TEXTURE_2D, colorTexture);
59
+ { // bind framebuffer
60
+ gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
61
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.colorTexture, 0);
62
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, this.indexTexture, 0);
63
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1]);
64
+ }
65
+ }
66
+ // call after drawing the scene with gl picker shader
67
+ drawColorTexture() {
68
+ const { colorTexture } = this;
69
+ this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);
70
+ this.displayer.draw(colorTexture);
71
+ }
72
+ pickXY(x, y, selectionPointFilling = 1, callback = () => { }) {
73
+ const size = Math.pow(1 + 2 * selectionPointFilling, 2);
74
+ this._pick(size, x - selectionPointFilling, y - selectionPointFilling, 1 + 2 * selectionPointFilling, 1 + 2 * selectionPointFilling, callback);
75
+ }
76
+ pickBbox(left, top, right, bottom, callback) {
77
+ const size = (right - left) * (bottom - top) * 4;
78
+ this._pick(size, left, top, right - left, bottom - top, callback);
79
+ }
80
+ _pick(size, startX, startY, lengthX, lengthY, callback) {
81
+ if (this._inProgress)
82
+ return false;
83
+ this._inProgress = true;
84
+ this._initHoldBuffer(size * 4);
85
+ const { gl, _pbo } = this;
86
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, _pbo);
87
+ this.bindFBO();
88
+ gl.readBuffer(gl.COLOR_ATTACHMENT1); // This is the attachment we want to read
89
+ gl.readPixels(// This will read the pixels to the buffer asynchronously
90
+ startX, startY, lengthX, lengthY, gl.RED_INTEGER, gl.INT, 0);
91
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
92
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
93
+ (0, fence_1.fence)(this.gl).then(() => {
94
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, _pbo);
95
+ // const data = new Int16Array(size);
96
+ const data = new Int32Array(size);
97
+ gl.getBufferSubData(gl.PIXEL_PACK_BUFFER, 0, data);
98
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
99
+ const result = this._pickFromBuffer(data, size);
100
+ callback(result);
101
+ // gl.deleteBuffer(pbo);
102
+ this._inProgress = false;
103
+ });
104
+ return true;
105
+ }
106
+ _pickFromBuffer(array, size) {
107
+ const selectedObjects = new Set();
108
+ for (let i = 0; i < size; i += 1) {
109
+ const id = array[i];
110
+ if (id !== ESCAPE_VALUE) {
111
+ selectedObjects.add(id);
112
+ }
113
+ }
114
+ return selectedObjects;
115
+ }
116
+ _initHoldBuffer(size) {
117
+ if (this._pbo && this._pboSize >= size) {
118
+ return;
119
+ }
120
+ const { gl } = this;
121
+ const pbo = gl.createBuffer();
122
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, pbo);
123
+ gl.bufferData(gl.PIXEL_PACK_BUFFER, size, gl.STREAM_READ);
124
+ gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
125
+ this._pboSize = size;
126
+ if (this._pbo !== undefined) {
127
+ gl.deleteBuffer(this._pbo);
128
+ }
129
+ this._pbo = pbo;
130
+ }
131
+ free() {
132
+ const { gl, colorTexture, indexTexture, fbo } = this;
133
+ gl.deleteTexture(colorTexture);
134
+ gl.deleteTexture(indexTexture);
135
+ gl.deleteFramebuffer(fbo);
136
+ draw_texture_on_canvas_1.textureOnCanvasProgramCache.release(this.gl);
137
+ }
138
+ }
139
+ exports.PickerDisplayer = PickerDisplayer;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.textureOnCanvasProgramCache = void 0;
4
+ const webglobjectbuilders_1 = require("../webglobjectbuilders");
5
+ const programs_1 = require("../../programs");
6
+ // import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../../programs/totems";
7
+ const vs = `#version 300 es
8
+ precision highp float;
9
+
10
+ in vec2 a_position;
11
+ out vec2 v_texcoord;
12
+
13
+ void main() {
14
+ gl_Position = vec4(a_position, 0.0, 1.0);
15
+ v_texcoord = a_position * 0.5 + 0.5;
16
+ }`;
17
+ const fs = `#version 300 es
18
+ precision highp float;
19
+
20
+ uniform sampler2D u_texture;
21
+ uniform float u_opacity;
22
+ in vec2 v_texcoord;
23
+ out vec4 fragColor;
24
+
25
+ void main() {
26
+ fragColor = texture(u_texture, v_texcoord);
27
+ fragColor.a *= u_opacity;
28
+ }`;
29
+ class TextureOnCanvasProgram {
30
+ constructor(gl) {
31
+ this.gl = gl;
32
+ this.vao = this.gl.createVertexArray();
33
+ this.buffer = this.gl.createBuffer();
34
+ this.gl.bindVertexArray(this.vao);
35
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffer);
36
+ this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array([
37
+ -1, -1,
38
+ 1, -1,
39
+ 1, 1,
40
+ -1, 1
41
+ ]), this.gl.STATIC_DRAW);
42
+ this.gl.enableVertexAttribArray(0);
43
+ this.gl.vertexAttribPointer(0, 2, this.gl.FLOAT, false, 0, 0);
44
+ this.gl.bindVertexArray(null);
45
+ this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);
46
+ this.program = (0, webglobjectbuilders_1.createProgram)(this.gl, vs, fs);
47
+ {
48
+ const { gl, program } = this;
49
+ this.uniforms = {
50
+ texture: gl.getUniformLocation(program, "u_texture"),
51
+ opacity: gl.getUniformLocation(program, "u_opacity"),
52
+ };
53
+ }
54
+ {
55
+ this._lastOpacity = 1.0;
56
+ const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
57
+ this.gl.useProgram(this.program);
58
+ this.gl.uniform1f(this.uniforms.opacity, this._lastOpacity);
59
+ this.gl.useProgram(currentProgram);
60
+ }
61
+ }
62
+ draw(texture, { opacity = 1.0 } = {}) {
63
+ const { gl, program, uniforms, vao } = this;
64
+ gl.useProgram(program);
65
+ gl.bindVertexArray(vao);
66
+ gl.activeTexture(gl.TEXTURE0);
67
+ gl.bindTexture(gl.TEXTURE_2D, texture);
68
+ gl.uniform1i(uniforms.texture, 0);
69
+ if (this._lastOpacity !== opacity) {
70
+ gl.uniform1f(uniforms.opacity, opacity);
71
+ this._lastOpacity = opacity;
72
+ }
73
+ gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
74
+ gl.bindVertexArray(null);
75
+ }
76
+ free() {
77
+ if (this._isFreed)
78
+ return;
79
+ this.gl.deleteVertexArray(this.vao);
80
+ this.gl.deleteBuffer(this.buffer);
81
+ this.gl.deleteProgram(this.program);
82
+ this._isFreed = true;
83
+ }
84
+ }
85
+ const textureOnCanvasProgramCache = Object.freeze({
86
+ get: (gl) => programs_1.glProgramCache.getProgram(gl, TextureOnCanvasProgram),
87
+ release: (gl) => programs_1.glProgramCache.releaseProgram(gl, TextureOnCanvasProgram)
88
+ });
89
+ exports.textureOnCanvasProgramCache = textureOnCanvasProgramCache;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./shapesonglobe"), exports);