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