@pirireis/webglobeplugins 0.9.11 → 0.9.12
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.
- package/Math/angle-calculation.js +8 -8
- package/Math/arc.js +18 -18
- package/Math/bounds/line-bbox.js +78 -80
- package/Math/constants.js +3 -3
- package/Math/juction/arc-plane.js +23 -23
- package/Math/juction/line-sphere.js +11 -11
- package/Math/juction/plane-plane.js +11 -11
- package/Math/line.js +14 -16
- package/Math/methods.js +65 -70
- package/Math/plane.js +16 -18
- package/Math/quaternion.js +45 -49
- package/Math/utils.js +2 -2
- package/Math/vec3.js +42 -45
- package/algorithms/search-binary.js +4 -4
- package/altitude-locator/draw-subset-obj.js +7 -8
- package/altitude-locator/plugin.js +98 -114
- package/arrowfield/adaptor.js +3 -4
- package/arrowfield/index.js +2 -2
- package/arrowfield/plugin.js +62 -65
- package/bearing-line/index.js +1 -1
- package/bearing-line/plugin.js +200 -226
- package/circle-line-chain/chain-list-map.js +82 -88
- package/circle-line-chain/plugin.js +134 -165
- package/circle-line-chain/util.js +1 -1
- package/compass-rose/compass-rose-padding-flat.js +108 -133
- package/compass-rose/compass-text-writer.js +62 -70
- package/compass-rose/index.js +2 -2
- package/compassrose/compassrose.js +46 -50
- package/compassrose/index.js +1 -1
- package/heatwave/index.js +2 -2
- package/heatwave/isobar/objectarraylabels.js +44 -48
- package/heatwave/isobar/plugin.js +104 -123
- package/heatwave/isobar/quadtreecontours.js +76 -92
- package/heatwave/plugins/heatwaveglobeshell.js +69 -87
- package/index.js +11 -11
- package/package.json +1 -1
- package/partialrings/buffer-manager.js +32 -64
- package/partialrings/index.js +1 -1
- package/partialrings/plugin.js +48 -84
- package/partialrings/program.js +136 -47
- package/pin/pin-object-array.js +83 -86
- package/pin/pin-point-totem.js +21 -22
- package/point-heat-map/adaptors/timetracksplugin-format-to-this.js +10 -10
- package/point-heat-map/plugin-webworker.js +40 -45
- package/point-heat-map/point-to-heat-map-flow.js +40 -42
- package/point-tracks/key-methods.js +1 -1
- package/point-tracks/plugin.js +137 -162
- package/programs/arrowfield/index.js +1 -1
- package/programs/arrowfield/logic.js +170 -62
- package/programs/arrowfield/object.js +33 -35
- package/programs/data2legend/density-to-legend.js +45 -21
- package/programs/data2legend/point-to-density-texture.js +52 -27
- package/programs/float2legendwithratio/index.js +1 -1
- package/programs/float2legendwithratio/logic.js +88 -42
- package/programs/float2legendwithratio/object.js +43 -46
- package/programs/globe-util/is-globe-moved.js +10 -11
- package/programs/globeshell/index.js +1 -1
- package/programs/globeshell/wiggle/index.js +1 -1
- package/programs/globeshell/wiggle/logic.js +191 -98
- package/programs/globeshell/wiggle/object.js +33 -35
- package/programs/helpers/blender/program.js +36 -19
- package/programs/helpers/fadeaway/index.js +1 -1
- package/programs/helpers/fadeaway/logic.js +35 -13
- package/programs/helpers/fadeaway/object.js +9 -10
- package/programs/helpers/index.js +1 -1
- package/programs/index.js +8 -8
- package/programs/line-on-globe/angled-line.js +91 -32
- package/programs/line-on-globe/circle-accurate-3d.js +82 -32
- package/programs/line-on-globe/circle-accurate-flat.js +108 -50
- package/programs/line-on-globe/circle-accurate.js +103 -33
- package/programs/line-on-globe/circle.js +97 -32
- package/programs/line-on-globe/degree-padding-around-circle-3d.js +83 -33
- package/programs/line-on-globe/lines-color-instanced-flat.js +79 -34
- package/programs/line-on-globe/linestrip.js +111 -45
- package/programs/line-on-globe/naive-accurate-flexible.js +120 -50
- package/programs/line-on-globe/to-the-surface.js +58 -29
- package/programs/line-on-globe/util.js +1 -1
- package/programs/picking/pickable-renderer.js +117 -33
- package/programs/point-on-globe/element-globe-surface-glow.js +78 -38
- package/programs/point-on-globe/element-point-glow.js +103 -35
- package/programs/point-on-globe/square-pixel-point.js +76 -27
- package/programs/programcache.js +13 -13
- package/programs/rings/distancering/circleflatprogram.js +63 -21
- package/programs/rings/distancering/circlepaddingfreeangleprogram.js +156 -145
- package/programs/rings/distancering/circlepaddysharedbuffer.js +121 -197
- package/programs/rings/distancering/index.js +4 -4
- package/programs/rings/distancering/paddyflatprogram.js +73 -20
- package/programs/rings/distancering/paddyflatprogram2d.js +75 -22
- package/programs/rings/distancering/paddyflatprogram3d.js +73 -20
- package/programs/rings/partial-ring/piece-of-pie.js +137 -35
- package/programs/totems/camerauniformblock.js +64 -51
- package/programs/totems/canvas-webglobe-info.js +48 -40
- package/programs/totems/gpu-selection-uniform-block.js +44 -40
- package/programs/totems/index.js +1 -1
- package/programs/two-d/pixel-padding-for-compass.js +90 -29
- package/programs/util.js +6 -7
- package/programs/vectorfields/index.js +1 -1
- package/programs/vectorfields/logics/drawrectangleparticles.js +70 -29
- package/programs/vectorfields/logics/index.js +3 -3
- package/programs/vectorfields/logics/pixelbased.js +91 -35
- package/programs/vectorfields/logics/ubo.js +31 -25
- package/programs/vectorfields/pingpongbuffermanager.js +30 -34
- package/rangerings/index.js +4 -4
- package/rangerings/plugin.js +202 -258
- package/rangerings/rangeringangletext.js +108 -120
- package/rangerings/ring-account.js +52 -69
- package/shaders/fragment-toy/firework.js +55 -1
- package/shaders/fragment-toy/singularity.js +55 -1
- package/timetracks/adaptors-line-strip.js +26 -37
- package/timetracks/adaptors.js +47 -61
- package/timetracks/index.js +4 -4
- package/timetracks/plugin-line-strip.js +63 -71
- package/timetracks/plugin.js +69 -77
- package/timetracks/program-line-strip.js +296 -103
- package/timetracks/program.js +419 -113
- package/timetracks/programpoint-line-strip.js +97 -44
- package/timetracks/programpoint.js +90 -44
- package/util/account/bufferoffsetmanager.js +72 -95
- package/util/account/index.js +1 -1
- package/util/account/single-attribute-buffer-management/buffer-manager.js +44 -44
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +68 -94
- package/util/account/single-attribute-buffer-management/index.js +3 -3
- package/util/account/single-attribute-buffer-management/object-store.js +29 -30
- package/util/account/util.js +2 -4
- package/util/algorithms/search-binary.js +4 -4
- package/util/check/get.js +5 -5
- package/util/check/typecheck.js +13 -15
- package/util/geometry/index.js +9 -11
- package/util/gl-util/buffer/attribute-loader.js +8 -20
- package/util/gl-util/buffer/index.js +1 -1
- package/util/gl-util/draw-options/methods.js +8 -9
- package/util/gl-util/uniform-block/manager.js +67 -67
- package/util/heatwavedatamanager/datamanager.js +56 -116
- package/util/heatwavedatamanager/index.js +2 -2
- package/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +37 -40
- package/util/heatwavedatamanager/pointcoordsmeta.js +9 -10
- package/util/index.js +6 -6
- package/util/interpolation/timetrack/index.js +1 -1
- package/util/interpolation/timetrack/timetrack-interpolator.js +27 -29
- package/util/interpolation/timetrack/web-worker-str.js +179 -1
- package/util/interpolation/timetrack/web-worker.js +4 -4
- package/util/jshelpers/data-filler.js +7 -7
- package/util/jshelpers/timefilters.js +7 -7
- package/util/picking/fence.js +7 -7
- package/util/picking/picker-displayer.js +46 -52
- package/util/programs/draw-texture-on-canvas.js +39 -21
- package/util/programs/shapesonglobe.js +104 -64
- package/util/programs/supersampletotextures.js +45 -39
- package/util/programs/texturetoglobe.js +98 -48
- package/util/shaderfunctions/geometrytransformations.js +322 -27
- package/util/shaderfunctions/nodata.js +7 -1
- package/util/shaderfunctions/noisefunctions.js +39 -9
- package/util/surface-line-data/arcs-to-cuts.js +20 -23
- package/util/webglobe/rasteroverlay.js +35 -37
- package/util/webglobjectbuilders.js +55 -60
- package/util/webglobjectbuilders1.js +48 -49
- package/waveparticles/adaptor.js +6 -7
- package/waveparticles/index.js +2 -2
- package/waveparticles/plugin.js +79 -84
- package/wind/imagetovectorfieldandmagnitude.js +15 -15
- package/wind/index.js +4 -4
- package/wind/plugin.js +453 -251
- package/wind/vectorfieldimage.js +5 -5
- package/write-text/attached-text-writer.js +46 -48
- package/write-text/context-text.js +51 -58
- package/write-text/context-text3.js +69 -74
package/Math/methods.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.globe2Dcoordinates = exports.globe3Dcoordinates = exports.pixelXYLenghtToUnitVectorWithHeight = exports.wgs84ToMercator = exports.wgs84ToCartesian3d = exports.wgs84ToUnitVector = exports.sphericalLinearInterpolation_Cartesian3d = exports.sphericalLinearInterpolation_Mercator = exports.sphericalLinearInterpolation_UnitVector = exports.radianToCartesian3d = exports.radianToMercator = exports.cartesian3dToRadian = exports.length3 = exports.dot3 = exports.normalize3 = exports.RADIANS = void 0;
|
|
4
|
-
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {Array<number>} vec3 [x, y, z]
|
|
7
7
|
* @typedef {Array<number>} vec2 [x, y]
|
|
@@ -12,14 +12,14 @@ var constants_1 = require("./constants");
|
|
|
12
12
|
// *********************************************************
|
|
13
13
|
// **************** VECTOR OPERATIONS **********************
|
|
14
14
|
// *********************************************************
|
|
15
|
-
|
|
15
|
+
const RADIANS = Math.PI / 180;
|
|
16
16
|
exports.RADIANS = RADIANS;
|
|
17
17
|
/**
|
|
18
18
|
* @param {vec3} a
|
|
19
19
|
* @returns {vec3}
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const normalize3 = (a) => {
|
|
22
|
+
const len = length3(a);
|
|
23
23
|
return [a[0] / len, a[1] / len, a[2] / len];
|
|
24
24
|
};
|
|
25
25
|
exports.normalize3 = normalize3;
|
|
@@ -28,7 +28,7 @@ exports.normalize3 = normalize3;
|
|
|
28
28
|
* @param {vec3} b
|
|
29
29
|
* @returns {number}
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
const dot3 = (a, b) => {
|
|
32
32
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
33
33
|
};
|
|
34
34
|
exports.dot3 = dot3;
|
|
@@ -36,7 +36,7 @@ exports.dot3 = dot3;
|
|
|
36
36
|
* @param {vec3} a
|
|
37
37
|
* @returns {number}
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
const length3 = (a) => {
|
|
40
40
|
return Math.sqrt(dot3(a, a));
|
|
41
41
|
};
|
|
42
42
|
exports.length3 = length3;
|
|
@@ -47,13 +47,13 @@ exports.length3 = length3;
|
|
|
47
47
|
* @param {vec3} cartesian
|
|
48
48
|
* @returns {vec2} long lat in radians
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
const cartesian3dToRadian = (cartesian) => {
|
|
51
|
+
const x = cartesian[0];
|
|
52
|
+
const y = cartesian[1];
|
|
53
|
+
const z = cartesian[2];
|
|
54
54
|
// const length = Math.sqrt(x * x + y * y + z * z);
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const long = Math.atan2(y, x);
|
|
56
|
+
const lat = Math.asin(z); // length);
|
|
57
57
|
return [long, lat];
|
|
58
58
|
};
|
|
59
59
|
exports.cartesian3dToRadian = cartesian3dToRadian;
|
|
@@ -61,7 +61,7 @@ exports.cartesian3dToRadian = cartesian3dToRadian;
|
|
|
61
61
|
* @param {vec2} xy long lat in radians
|
|
62
62
|
* @returns {vec2} long lat in mercator meters
|
|
63
63
|
*/
|
|
64
|
-
|
|
64
|
+
const radianToMercator = (xy) => {
|
|
65
65
|
return [constants_1.WORLD_RADIUS_MERCATOR * xy[0], constants_1.WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + xy[1] / 2))];
|
|
66
66
|
};
|
|
67
67
|
exports.radianToMercator = radianToMercator;
|
|
@@ -69,10 +69,10 @@ exports.radianToMercator = radianToMercator;
|
|
|
69
69
|
* @param {vec2} xy long lat radians
|
|
70
70
|
* @returns {vec3} cartesian
|
|
71
71
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const radianToCartesian3d = (xy) => {
|
|
73
|
+
const x = Math.cos(xy[1]) * Math.cos(xy[0]);
|
|
74
|
+
const y = Math.cos(xy[1]) * Math.sin(xy[0]);
|
|
75
|
+
const z = -Math.sin(xy[1]);
|
|
76
76
|
return [x, y, z];
|
|
77
77
|
};
|
|
78
78
|
exports.radianToCartesian3d = radianToCartesian3d;
|
|
@@ -85,12 +85,12 @@ exports.radianToCartesian3d = radianToCartesian3d;
|
|
|
85
85
|
* @param {fraction} ratio
|
|
86
86
|
* @returns {vec3}
|
|
87
87
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
const sphericalLinearInterpolation_UnitVector = (normalizedA, normalizedB, ratio) => {
|
|
89
|
+
const theta = Math.acos(dot3(normalizedA, normalizedB));
|
|
90
90
|
if (theta < 0.000001)
|
|
91
91
|
return normalizedA; // CALIBRATE?
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const sinTheta = Math.sin(theta);
|
|
93
|
+
const result = [
|
|
94
94
|
(Math.sin((1.0 - ratio) * theta) * normalizedA[0] + Math.sin(ratio * theta) * normalizedB[0]) / sinTheta,
|
|
95
95
|
(Math.sin((1.0 - ratio) * theta) * normalizedA[1] + Math.sin(ratio * theta) * normalizedB[1]) / sinTheta,
|
|
96
96
|
(Math.sin((1.0 - ratio) * theta) * normalizedA[2] + Math.sin(ratio * theta) * normalizedB[2]) / sinTheta
|
|
@@ -104,9 +104,9 @@ exports.sphericalLinearInterpolation_UnitVector = sphericalLinearInterpolation_U
|
|
|
104
104
|
* @param {fraction} ratio
|
|
105
105
|
* @returns
|
|
106
106
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const sphericalLinearInterpolation_Mercator = (normalizedA, normalizedB, ratio) => {
|
|
108
|
+
const unitVector = sphericalLinearInterpolation_UnitVector(normalizedA, normalizedB, ratio);
|
|
109
|
+
const angles = cartesian3dToRadian(unitVector);
|
|
110
110
|
return radianToMercator(angles);
|
|
111
111
|
};
|
|
112
112
|
exports.sphericalLinearInterpolation_Mercator = sphericalLinearInterpolation_Mercator;
|
|
@@ -115,9 +115,9 @@ exports.sphericalLinearInterpolation_Mercator = sphericalLinearInterpolation_Mer
|
|
|
115
115
|
* @param {vec4} b vec3 unit vector and length
|
|
116
116
|
* @param {fraction} ratio
|
|
117
117
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
const sphericalLinearInterpolation_Cartesian3d = (a, b, ratio) => {
|
|
119
|
+
const unitVector = sphericalLinearInterpolation_UnitVector(a, b, ratio);
|
|
120
|
+
const height = a[3] + (b[3] - a[3]) * ratio;
|
|
121
121
|
return [unitVector[0] * height, unitVector[1] * height, unitVector[2] * height];
|
|
122
122
|
};
|
|
123
123
|
exports.sphericalLinearInterpolation_Cartesian3d = sphericalLinearInterpolation_Cartesian3d;
|
|
@@ -126,12 +126,12 @@ exports.sphericalLinearInterpolation_Cartesian3d = sphericalLinearInterpolation_
|
|
|
126
126
|
* @param {wgs84} coordinates
|
|
127
127
|
* @returns {vec3}
|
|
128
128
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
const wgs84ToUnitVector = (coordinates) => {
|
|
130
|
+
const long = coordinates[0] * RADIANS;
|
|
131
|
+
const lat = coordinates[1] * RADIANS;
|
|
132
|
+
const x = Math.cos(lat) * Math.cos(long);
|
|
133
|
+
const y = Math.cos(lat) * Math.sin(long);
|
|
134
|
+
const z = Math.sin(lat);
|
|
135
135
|
return [x, y, z];
|
|
136
136
|
};
|
|
137
137
|
exports.wgs84ToUnitVector = wgs84ToUnitVector;
|
|
@@ -141,13 +141,13 @@ exports.wgs84ToUnitVector = wgs84ToUnitVector;
|
|
|
141
141
|
* @param {number} height
|
|
142
142
|
* @returns {vec3} cartesian3D
|
|
143
143
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
const wgs84ToCartesian3d = (long, lat, height) => {
|
|
145
|
+
const longRad = long * RADIANS;
|
|
146
|
+
const latRad = lat * RADIANS;
|
|
147
|
+
const x = Math.cos(latRad) * Math.cos(longRad);
|
|
148
|
+
const y = Math.cos(latRad) * Math.sin(longRad);
|
|
149
|
+
const z = Math.sin(latRad);
|
|
150
|
+
const radius = constants_1.WORLD_RADIUS_3D + height;
|
|
151
151
|
return [x * radius, y * radius, z * radius];
|
|
152
152
|
};
|
|
153
153
|
exports.wgs84ToCartesian3d = wgs84ToCartesian3d;
|
|
@@ -156,7 +156,7 @@ exports.wgs84ToCartesian3d = wgs84ToCartesian3d;
|
|
|
156
156
|
* @param {number} lat
|
|
157
157
|
* @returns {vec2} mercator
|
|
158
158
|
*/
|
|
159
|
-
|
|
159
|
+
const wgs84ToMercator = (long, lat) => {
|
|
160
160
|
return [constants_1.WORLD_RADIUS_MERCATOR * long * RADIANS, constants_1.WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + lat * RADIANS / 2))];
|
|
161
161
|
};
|
|
162
162
|
exports.wgs84ToMercator = wgs84ToMercator;
|
|
@@ -164,43 +164,38 @@ exports.wgs84ToMercator = wgs84ToMercator;
|
|
|
164
164
|
* @param {vec2} pixelXY
|
|
165
165
|
* @returns {vec2} long lat in radians
|
|
166
166
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
const pixelXYToRadians = (pixelXY) => {
|
|
168
|
+
const long = (2.0 * pixelXY[0] - 1.0) * Math.PI;
|
|
169
|
+
const lat = (2.0 * pixelXY[1] - 1.0) * Math.PI / 2.0;
|
|
170
170
|
return [long, lat];
|
|
171
171
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
const pixelXYLenghtToUnitVectorWithHeight = (pixelXYHeight) => {
|
|
173
|
+
const [long, lat] = pixelXYToRadians(pixelXYHeight);
|
|
174
|
+
const radius = constants_1.WORLD_RADIUS_3D + pixelXYHeight[2];
|
|
175
175
|
return radianToCartesian3d([long, lat]).concat(radius);
|
|
176
176
|
};
|
|
177
177
|
exports.pixelXYLenghtToUnitVectorWithHeight = pixelXYLenghtToUnitVectorWithHeight;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
result.set(xyz, i * 3);
|
|
189
|
-
}
|
|
190
|
-
return result;
|
|
191
|
-
};
|
|
178
|
+
const globe3Dcoordinates = (globe, height = 0) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
179
|
+
const len = longlats.length / 2;
|
|
180
|
+
const result = new Float32Array(len * 3 + paddingCount * 3).fill(paddingValue);
|
|
181
|
+
for (let i = 0; i < len; i++) {
|
|
182
|
+
const long = longlats[i * 2];
|
|
183
|
+
const lat = longlats[i * 2 + 1];
|
|
184
|
+
const xyz = globe.api_GetCartesian3DPoint(long, lat, height, 0);
|
|
185
|
+
result.set(xyz, i * 3);
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
192
188
|
};
|
|
193
189
|
exports.globe3Dcoordinates = globe3Dcoordinates;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var xyz = globe.api_GetMercator2DPoint(long, lat);
|
|
190
|
+
const globe2Dcoordinates = (globe) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
191
|
+
const len = longlats.length / 2;
|
|
192
|
+
const result = new Float32Array(len * 2 + paddingCount * 2).fill(paddingValue);
|
|
193
|
+
for (let i = 0; i < len; i++) {
|
|
194
|
+
const long = longlats[i * 2];
|
|
195
|
+
const lat = longlats[i * 2 + 1];
|
|
196
|
+
const xyz = globe.api_GetMercator2DPoint(long, lat);
|
|
202
197
|
result.set(xyz, i * 2);
|
|
203
198
|
}
|
|
204
199
|
return result;
|
|
205
|
-
};
|
|
200
|
+
};
|
|
206
201
|
exports.globe2Dcoordinates = globe2Dcoordinates;
|
package/Math/plane.js
CHANGED
|
@@ -1,62 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.plane = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const vec3_1 = require("./vec3");
|
|
6
|
+
const _0vector = /*@__PURE__*/ vec3_1.vec3.create(0, 0, 0);
|
|
7
|
+
const _1vector = /*@__PURE__*/ vec3_1.vec3.create(1, 1, 1);
|
|
8
8
|
exports.plane = Object.freeze({
|
|
9
|
-
create
|
|
10
|
-
if (normal === void 0) { normal = vec3_1.vec3.create(); }
|
|
11
|
-
if (distance === void 0) { distance = 0; }
|
|
9
|
+
create(normal = vec3_1.vec3.create(), distance = 0) {
|
|
12
10
|
return {
|
|
13
11
|
normal: vec3_1.vec3.clone(normal),
|
|
14
12
|
distance: distance
|
|
15
13
|
};
|
|
16
14
|
},
|
|
17
|
-
set
|
|
15
|
+
set(out, normal, distance) {
|
|
18
16
|
vec3_1.vec3.copy(out.normal, normal);
|
|
19
17
|
out.distance = distance;
|
|
20
18
|
return out;
|
|
21
19
|
},
|
|
22
|
-
fromValues
|
|
20
|
+
fromValues(out, nx, ny, nz, distance) {
|
|
23
21
|
vec3_1.vec3.set(out.normal, nx, ny, nz);
|
|
24
22
|
out.distance = distance;
|
|
25
23
|
},
|
|
26
|
-
copy
|
|
24
|
+
copy(out, a) {
|
|
27
25
|
vec3_1.vec3.copy(out.normal, a.normal);
|
|
28
26
|
out.distance = a.distance;
|
|
29
27
|
return out;
|
|
30
28
|
},
|
|
31
|
-
clone
|
|
29
|
+
clone(a) {
|
|
32
30
|
return {
|
|
33
31
|
normal: vec3_1.vec3.clone(a.normal),
|
|
34
32
|
distance: a.distance
|
|
35
33
|
};
|
|
36
34
|
},
|
|
37
|
-
distanceToPoint
|
|
35
|
+
distanceToPoint(plane, point) {
|
|
38
36
|
return vec3_1.vec3.dot(plane.normal, point) - plane.distance;
|
|
39
37
|
},
|
|
40
|
-
projectPoint
|
|
41
|
-
|
|
38
|
+
projectPoint(out, plane, point) {
|
|
39
|
+
const distance = this.distanceToPoint(plane, point);
|
|
42
40
|
vec3_1.vec3.multiplyScalar(out, plane.normal, distance);
|
|
43
41
|
vec3_1.vec3.subtract(out, point, out);
|
|
44
42
|
},
|
|
45
|
-
equals
|
|
43
|
+
equals(plane, other) {
|
|
46
44
|
return vec3_1.vec3.equals(plane.normal, other.normal) && Math.abs(plane.distance - other.distance) < constants_1.EPSILON;
|
|
47
45
|
},
|
|
48
|
-
fromNormalAndCoplanarPoint
|
|
46
|
+
fromNormalAndCoplanarPoint(out, normal, point) {
|
|
49
47
|
vec3_1.vec3.copy(out.normal, normal);
|
|
50
48
|
out.distance = vec3_1.vec3.dot(point, normal);
|
|
51
49
|
},
|
|
52
|
-
fromPoints
|
|
50
|
+
fromPoints(out, a, b, c) {
|
|
53
51
|
vec3_1.vec3.subtract(_0vector, b, a);
|
|
54
52
|
vec3_1.vec3.subtract(_1vector, c, a);
|
|
55
53
|
vec3_1.vec3.cross(out.normal, _0vector, _1vector);
|
|
56
54
|
vec3_1.vec3.normalize(out.normal, out.normal);
|
|
57
55
|
out.distance = vec3_1.vec3.dot(out.normal, a);
|
|
58
56
|
},
|
|
59
|
-
getUnitSphereRadiusAngle
|
|
57
|
+
getUnitSphereRadiusAngle(plane) {
|
|
60
58
|
return Math.acos(Math.max(Math.min(plane.distance, 1), -1));
|
|
61
59
|
}
|
|
62
60
|
});
|
package/Math/quaternion.js
CHANGED
|
@@ -1,79 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.quaternion = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const vec3_1 = require("./vec3");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
6
|
exports.quaternion = Object.freeze({
|
|
7
|
-
create
|
|
8
|
-
if (x === void 0) { x = 0; }
|
|
9
|
-
if (y === void 0) { y = 0; }
|
|
10
|
-
if (z === void 0) { z = 0; }
|
|
11
|
-
if (w === void 0) { w = 1; }
|
|
7
|
+
create(x = 0, y = 0, z = 0, w = 1) {
|
|
12
8
|
return [x, y, z, w];
|
|
13
9
|
},
|
|
14
|
-
set
|
|
10
|
+
set(out, x, y, z, w) {
|
|
15
11
|
out[0] = x;
|
|
16
12
|
out[1] = y;
|
|
17
13
|
out[2] = z;
|
|
18
14
|
out[3] = w;
|
|
19
15
|
},
|
|
20
|
-
copy
|
|
16
|
+
copy(out, a) {
|
|
21
17
|
out[0] = a[0];
|
|
22
18
|
out[1] = a[1];
|
|
23
19
|
out[2] = a[2];
|
|
24
20
|
out[3] = a[3];
|
|
25
21
|
},
|
|
26
|
-
clone
|
|
22
|
+
clone(a) {
|
|
27
23
|
return [a[0], a[1], a[2], a[3]];
|
|
28
24
|
},
|
|
29
|
-
multiply
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
multiply(out, a, b) {
|
|
26
|
+
const x = a[0] * b[3] + a[3] * b[0] + a[1] * b[2] - a[2] * b[1];
|
|
27
|
+
const y = a[1] * b[3] + a[3] * b[1] + a[2] * b[0] - a[0] * b[2];
|
|
28
|
+
const z = a[2] * b[3] + a[3] * b[2] + a[0] * b[1] - a[1] * b[0];
|
|
29
|
+
const w = a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2];
|
|
34
30
|
this.set(out, x, y, z, w);
|
|
35
31
|
return out;
|
|
36
32
|
},
|
|
37
|
-
randomUnit
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
randomUnit(out) {
|
|
34
|
+
const u1 = Math.random();
|
|
35
|
+
const u2 = Math.random();
|
|
36
|
+
const u3 = Math.random();
|
|
37
|
+
const sqrt1MinusU1 = Math.sqrt(1 - u1);
|
|
38
|
+
const sqrtU1 = Math.sqrt(u1);
|
|
39
|
+
const x = sqrt1MinusU1 * Math.sin(2 * Math.PI * u2);
|
|
40
|
+
const y = sqrt1MinusU1 * Math.cos(2 * Math.PI * u2);
|
|
41
|
+
const z = sqrtU1 * Math.sin(2 * Math.PI * u3);
|
|
42
|
+
const w = sqrtU1 * Math.cos(2 * Math.PI * u3);
|
|
47
43
|
this.set(out, x, y, z, w);
|
|
48
44
|
this.normalize(out, out);
|
|
49
45
|
return out;
|
|
50
46
|
},
|
|
51
|
-
rotateQuaternion
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
rotateQuaternion(out, a, b) {
|
|
48
|
+
const x = a[0] * b[3] + a[3] * b[0] + a[1] * b[2] - a[2] * b[1];
|
|
49
|
+
const y = a[1] * b[3] + a[3] * b[1] + a[2] * b[0] - a[0] * b[2];
|
|
50
|
+
const z = a[2] * b[3] + a[3] * b[2] + a[0] * b[1] - a[1] * b[0];
|
|
51
|
+
const w = a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2];
|
|
56
52
|
this.set(out, x, y, z, w);
|
|
57
53
|
this.normalize(out, out);
|
|
58
54
|
},
|
|
59
|
-
lengthSquared
|
|
55
|
+
lengthSquared(a) {
|
|
60
56
|
return a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3];
|
|
61
57
|
},
|
|
62
|
-
length
|
|
58
|
+
length(a) {
|
|
63
59
|
return Math.sqrt(this.lengthSquared(a));
|
|
64
60
|
},
|
|
65
|
-
normalize
|
|
66
|
-
|
|
61
|
+
normalize(out, input) {
|
|
62
|
+
const len = Math.sqrt(this.lengthSquared(input));
|
|
67
63
|
if (len < constants_1.EPSILON) {
|
|
68
64
|
this.set(out, 0, 0, 0, 1);
|
|
69
65
|
}
|
|
70
66
|
else {
|
|
71
|
-
|
|
67
|
+
const invLen = 1 / len;
|
|
72
68
|
this.set(out, input[0] * invLen, input[1] * invLen, input[2] * invLen, input[3] * invLen);
|
|
73
69
|
}
|
|
74
70
|
},
|
|
75
|
-
fromUnitVectors
|
|
76
|
-
|
|
71
|
+
fromUnitVectors(out, from, to) {
|
|
72
|
+
const d = vec3_1.vec3.dot(from, to) + 1;
|
|
77
73
|
if (d < constants_1.EPSILON) {
|
|
78
74
|
if (Math.abs(from[0]) > Math.abs(from[2])) {
|
|
79
75
|
this.set(out, -from[1], from[0], 0, 0);
|
|
@@ -83,26 +79,26 @@ exports.quaternion = Object.freeze({
|
|
|
83
79
|
}
|
|
84
80
|
}
|
|
85
81
|
else {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
const x = from[1] * to[2] - from[2] * to[1];
|
|
83
|
+
const y = from[2] * to[0] - from[0] * to[2];
|
|
84
|
+
const z = from[0] * to[1] - from[1] * to[0];
|
|
89
85
|
this.set(out, x, y, z, d);
|
|
90
86
|
}
|
|
91
87
|
},
|
|
92
|
-
fromTwoQuaternions
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
fromTwoQuaternions(out, from, to) {
|
|
89
|
+
const x = from[0] * to[3] + from[3] * to[0] + from[1] * to[2] - from[2] * to[1];
|
|
90
|
+
const y = from[1] * to[3] + from[3] * to[1] + from[2] * to[0] - from[0] * to[2];
|
|
91
|
+
const z = from[2] * to[3] + from[3] * to[2] + from[0] * to[1] - from[1] * to[0];
|
|
92
|
+
const w = from[3] * to[3] - from[0] * to[0] - from[1] * to[1] - from[2] * to[2];
|
|
97
93
|
this.set(out, x, y, z, w);
|
|
98
94
|
this.normalize(out, out);
|
|
99
95
|
},
|
|
100
|
-
conjugate
|
|
96
|
+
conjugate(out, a) {
|
|
101
97
|
this.set(out, -a[0], -a[1], -a[2], a[3]);
|
|
102
98
|
},
|
|
103
|
-
fromAxisAngle
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
fromAxisAngle(out, axis, angle) {
|
|
100
|
+
const halfAngle = angle / 2;
|
|
101
|
+
const s = Math.sin(halfAngle);
|
|
106
102
|
this.set(out, axis[0] * s, axis[1] * s, axis[2] * s, Math.cos(halfAngle));
|
|
107
103
|
},
|
|
108
104
|
});
|
package/Math/utils.js
CHANGED
package/Math/vec3.js
CHANGED
|
@@ -1,56 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.vec3 = void 0;
|
|
4
|
-
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
5
|
exports.vec3 = Object.freeze({
|
|
6
|
-
create
|
|
7
|
-
if (x === void 0) { x = 0; }
|
|
8
|
-
if (y === void 0) { y = 0; }
|
|
9
|
-
if (z === void 0) { z = 1; }
|
|
6
|
+
create(x = 0, y = 0, z = 1) {
|
|
10
7
|
return [x, y, z];
|
|
11
8
|
},
|
|
12
|
-
set
|
|
9
|
+
set(out, x, y, z) {
|
|
13
10
|
out[0] = x;
|
|
14
11
|
out[1] = y;
|
|
15
12
|
out[2] = z;
|
|
16
13
|
},
|
|
17
|
-
clone
|
|
14
|
+
clone(a) {
|
|
18
15
|
return [a[0], a[1], a[2]];
|
|
19
16
|
},
|
|
20
|
-
copy
|
|
17
|
+
copy(out, a) {
|
|
21
18
|
out[0] = a[0];
|
|
22
19
|
out[1] = a[1];
|
|
23
20
|
out[2] = a[2];
|
|
24
21
|
return out;
|
|
25
22
|
},
|
|
26
|
-
add
|
|
23
|
+
add(out, a, b) {
|
|
27
24
|
out[0] = a[0] + b[0];
|
|
28
25
|
out[1] = a[1] + b[1];
|
|
29
26
|
out[2] = a[2] + b[2];
|
|
30
27
|
return out;
|
|
31
28
|
},
|
|
32
|
-
subtract
|
|
29
|
+
subtract(out, a, b) {
|
|
33
30
|
out[0] = a[0] - b[0];
|
|
34
31
|
out[1] = a[1] - b[1];
|
|
35
32
|
out[2] = a[2] - b[2];
|
|
36
33
|
},
|
|
37
|
-
dot
|
|
34
|
+
dot(a, b) {
|
|
38
35
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
39
36
|
},
|
|
40
|
-
cross
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
cross(out, a, b) {
|
|
38
|
+
const x = a[1] * b[2] - a[2] * b[1];
|
|
39
|
+
const y = a[2] * b[0] - a[0] * b[2];
|
|
40
|
+
const z = a[0] * b[1] - a[1] * b[0];
|
|
44
41
|
out[0] = x;
|
|
45
42
|
out[1] = y;
|
|
46
43
|
out[2] = z;
|
|
47
44
|
},
|
|
48
|
-
multiplyScalar
|
|
45
|
+
multiplyScalar(out, a, b) {
|
|
49
46
|
out[0] = a[0] * b;
|
|
50
47
|
out[1] = a[1] * b;
|
|
51
48
|
out[2] = a[2] * b;
|
|
52
49
|
},
|
|
53
|
-
divideScalar
|
|
50
|
+
divideScalar(out, a, b) {
|
|
54
51
|
if (b === 0) {
|
|
55
52
|
throw new Error('Division by zero');
|
|
56
53
|
}
|
|
@@ -58,14 +55,14 @@ exports.vec3 = Object.freeze({
|
|
|
58
55
|
out[1] = a[1] / b;
|
|
59
56
|
out[2] = a[2] / b;
|
|
60
57
|
},
|
|
61
|
-
lengthSquared
|
|
58
|
+
lengthSquared(a) {
|
|
62
59
|
return a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
|
|
63
60
|
},
|
|
64
|
-
length
|
|
61
|
+
length(a) {
|
|
65
62
|
return Math.sqrt(this.lengthSquared(a));
|
|
66
63
|
},
|
|
67
|
-
normalize
|
|
68
|
-
|
|
64
|
+
normalize(outVec, inVec) {
|
|
65
|
+
const len = this.length(inVec);
|
|
69
66
|
if (len === 0) {
|
|
70
67
|
throw new Error('Cannot normalize a zero vector');
|
|
71
68
|
}
|
|
@@ -73,57 +70,57 @@ exports.vec3 = Object.freeze({
|
|
|
73
70
|
outVec[1] = inVec[1] / len;
|
|
74
71
|
outVec[2] = inVec[2] / len;
|
|
75
72
|
},
|
|
76
|
-
distanceSquared
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
distanceSquared(a, b) {
|
|
74
|
+
const dx = a[0] - b[0];
|
|
75
|
+
const dy = a[1] - b[1];
|
|
76
|
+
const dz = a[2] - b[2];
|
|
80
77
|
return dx * dx + dy * dy + dz * dz;
|
|
81
78
|
},
|
|
82
|
-
distance
|
|
79
|
+
distance(a, b) {
|
|
83
80
|
return Math.sqrt(this.distanceSquared(a, b));
|
|
84
81
|
},
|
|
85
|
-
equals
|
|
82
|
+
equals(a, b) {
|
|
86
83
|
return (Math.abs(a[0] - b[0]) < constants_1.EPSILON &&
|
|
87
84
|
Math.abs(a[1] - b[1]) < constants_1.EPSILON &&
|
|
88
85
|
Math.abs(a[2] - b[2]) < constants_1.EPSILON);
|
|
89
86
|
},
|
|
90
|
-
toUnitVectorLongLat
|
|
91
|
-
|
|
87
|
+
toUnitVectorLongLat(out, a) {
|
|
88
|
+
const len = this.length(a); // TODO Might drop length check
|
|
92
89
|
if (len === 0) {
|
|
93
90
|
throw new Error('Cannot convert a zero vector to unit vector');
|
|
94
91
|
}
|
|
95
92
|
out[0] = Math.atan2(a[1], a[0]); // Longitude
|
|
96
93
|
out[1] = Math.asin(a[2] / len); // Latitude
|
|
97
94
|
},
|
|
98
|
-
fromUnitVectorLongLat
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
fromUnitVectorLongLat(out, longLat) {
|
|
96
|
+
const longitude = longLat[0];
|
|
97
|
+
const latitude = longLat[1];
|
|
98
|
+
const cosLat = Math.cos(latitude);
|
|
102
99
|
out[0] = cosLat * Math.cos(longitude);
|
|
103
100
|
out[1] = cosLat * Math.sin(longitude);
|
|
104
101
|
out[2] = Math.sin(latitude);
|
|
105
102
|
},
|
|
106
|
-
applyQuaternion
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
applyQuaternion(out, a, q) {
|
|
104
|
+
const x = a[0], y = a[1], z = a[2];
|
|
105
|
+
const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
|
|
109
106
|
// Calculate the quaternion multiplication
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
const ix = qw * x + qy * z - qz * y;
|
|
108
|
+
const iy = qw * y + qz * x - qx * z;
|
|
109
|
+
const iz = qw * z + qx * y - qy * x;
|
|
110
|
+
const iw = -qx * x - qy * y - qz * z;
|
|
114
111
|
// Apply the quaternion to the vector
|
|
115
112
|
out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
116
113
|
out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
117
114
|
out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
118
115
|
},
|
|
119
|
-
randomUnit
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
randomUnit(out) {
|
|
117
|
+
const theta = Math.random() * 2 * Math.PI;
|
|
118
|
+
const phi = Math.acos(2 * Math.random() - 1);
|
|
122
119
|
out[0] = Math.sin(phi) * Math.cos(theta);
|
|
123
120
|
out[1] = Math.sin(phi) * Math.sin(theta);
|
|
124
121
|
out[2] = Math.cos(phi);
|
|
125
122
|
},
|
|
126
|
-
str
|
|
127
|
-
return
|
|
123
|
+
str(a) {
|
|
124
|
+
return `Vec3(${a[0].toFixed(2)}, ${a[1].toFixed(2)}, ${a[2].toFixed(2)})`;
|
|
128
125
|
}
|
|
129
126
|
});
|