@math.gl/core 3.6.3 → 4.0.0-alpha.2
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/dist/classes/base/math-array.d.ts +5 -4
- package/dist/classes/base/math-array.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/base/math-array.js +8 -3
- package/dist/classes/base/math-array.js.map +1 -0
- package/dist/classes/base/matrix.d.ts +2 -2
- package/dist/classes/base/matrix.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/base/matrix.js +4 -4
- package/dist/classes/base/matrix.js.map +1 -0
- package/dist/classes/base/vector.d.ts +2 -2
- package/dist/classes/base/vector.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/base/vector.js +4 -4
- package/dist/classes/base/vector.js.map +1 -0
- package/dist/classes/euler.d.ts +4 -4
- package/dist/classes/euler.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/euler.js +6 -6
- package/dist/classes/euler.js.map +1 -0
- package/dist/classes/matrix3.d.ts +5 -2
- package/dist/classes/matrix3.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/matrix3.js +20 -20
- package/dist/classes/matrix3.js.map +1 -0
- package/dist/classes/matrix4.d.ts +2 -2
- package/dist/classes/matrix4.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/matrix4.js +27 -27
- package/dist/classes/matrix4.js.map +1 -0
- package/dist/classes/pose.d.ts +4 -4
- package/dist/classes/pose.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/pose.js +4 -4
- package/dist/classes/pose.js.map +1 -0
- package/dist/classes/quaternion.d.ts +2 -2
- package/dist/classes/quaternion.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/quaternion.js +26 -26
- package/dist/classes/quaternion.js.map +1 -0
- package/dist/classes/spherical-coordinates.d.ts +2 -2
- package/dist/classes/spherical-coordinates.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/spherical-coordinates.js +5 -5
- package/dist/classes/spherical-coordinates.js.map +1 -0
- package/dist/classes/vector2.d.ts +2 -2
- package/dist/classes/vector2.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/vector2.js +10 -10
- package/dist/classes/vector2.js.map +1 -0
- package/dist/classes/vector3.d.ts +2 -2
- package/dist/classes/vector3.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/vector3.js +14 -14
- package/dist/classes/vector3.js.map +1 -0
- package/dist/classes/vector4.d.ts +3 -3
- package/dist/classes/vector4.d.ts.map +1 -1
- package/dist/{esm/classes → classes}/vector4.js +8 -8
- package/dist/classes/vector4.js.map +1 -0
- package/dist/gl-matrix/common.d.ts +38 -0
- package/dist/gl-matrix/common.d.ts.map +1 -0
- package/dist/gl-matrix/common.js +19 -0
- package/dist/gl-matrix/common.js.map +1 -0
- package/dist/gl-matrix/mat3.d.ts +295 -0
- package/dist/gl-matrix/mat3.d.ts.map +1 -0
- package/dist/gl-matrix/mat3.js +489 -0
- package/dist/gl-matrix/mat3.js.map +1 -0
- package/dist/gl-matrix/mat4.d.ts +577 -0
- package/dist/gl-matrix/mat4.d.ts.map +1 -0
- package/dist/gl-matrix/mat4.js +1455 -0
- package/dist/gl-matrix/mat4.js.map +1 -0
- package/dist/gl-matrix/quat.d.ts +357 -0
- package/dist/gl-matrix/quat.d.ts.map +1 -0
- package/dist/gl-matrix/quat.js +315 -0
- package/dist/gl-matrix/quat.js.map +1 -0
- package/dist/gl-matrix/vec2.d.ts +373 -0
- package/dist/gl-matrix/vec2.d.ts.map +1 -0
- package/dist/gl-matrix/vec2.js +257 -0
- package/dist/gl-matrix/vec2.js.map +1 -0
- package/dist/gl-matrix/vec3.d.ts +416 -0
- package/dist/gl-matrix/vec3.d.ts.map +1 -0
- package/dist/gl-matrix/vec3.js +384 -0
- package/dist/gl-matrix/vec3.js.map +1 -0
- package/dist/gl-matrix/vec4.d.ts +340 -0
- package/dist/gl-matrix/vec4.d.ts.map +1 -0
- package/dist/gl-matrix/vec4.js +334 -0
- package/dist/gl-matrix/vec4.js.map +1 -0
- package/dist/gl-matrix/wip/index.d.ts +5 -0
- package/dist/gl-matrix/wip/index.d.ts.map +1 -0
- package/dist/gl-matrix/wip/index.js +12 -0
- package/dist/gl-matrix/wip/index.js.map +1 -0
- package/dist/gl-matrix/wip/mat2.d.ts +229 -0
- package/dist/gl-matrix/wip/mat2.d.ts.map +1 -0
- package/dist/gl-matrix/wip/mat2.js +208 -0
- package/dist/gl-matrix/wip/mat2.js.map +1 -0
- package/dist/gl-matrix/wip/mat2d.d.ts +244 -0
- package/dist/gl-matrix/wip/mat2d.d.ts.map +1 -0
- package/dist/gl-matrix/wip/mat2d.js +251 -0
- package/dist/gl-matrix/wip/mat2d.js.map +1 -0
- package/dist/gl-matrix/wip/quat2.d.ts +352 -0
- package/dist/gl-matrix/wip/quat2.d.ts.map +1 -0
- package/dist/gl-matrix/wip/quat2.js +482 -0
- package/dist/gl-matrix/wip/quat2.js.map +1 -0
- package/dist/gl-matrix/wip/types.d.js +2 -0
- package/dist/{esm/lib/gl-matrix.d.js.map → gl-matrix/wip/types.d.js.map} +1 -1
- package/dist/index.cjs +3788 -0
- package/dist/index.d.ts +15 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/assert.d.ts +1 -1
- package/dist/lib/assert.d.ts.map +1 -1
- package/dist/lib/assert.js +6 -0
- package/dist/lib/assert.js.map +1 -0
- package/dist/lib/common.d.ts +10 -5
- package/dist/lib/common.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/common.js +11 -9
- package/dist/lib/common.js.map +1 -0
- package/dist/lib/gl-matrix-extras.js.map +1 -0
- package/dist/lib/math-utils.d.ts +24 -27
- package/dist/lib/math-utils.d.ts.map +1 -1
- package/dist/lib/math-utils.js +25 -0
- package/dist/lib/math-utils.js.map +1 -0
- package/dist/lib/validators.d.ts +1 -1
- package/dist/lib/validators.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/validators.js +2 -2
- package/dist/lib/validators.js.map +1 -0
- package/package.json +6 -6
- package/src/classes/base/math-array.ts +16 -8
- package/src/classes/base/matrix.ts +7 -4
- package/src/classes/base/vector.ts +4 -4
- package/src/classes/euler.ts +9 -8
- package/src/classes/matrix3.ts +37 -24
- package/src/classes/matrix4.ts +48 -29
- package/src/classes/pose.ts +4 -4
- package/src/classes/quaternion.ts +54 -32
- package/src/classes/spherical-coordinates.ts +5 -4
- package/src/classes/vector2.ts +13 -9
- package/src/classes/vector3.ts +26 -12
- package/src/classes/vector4.ts +14 -10
- package/src/gl-matrix/common.js +58 -0
- package/src/gl-matrix/mat3.js +842 -0
- package/src/gl-matrix/mat4.js +2169 -0
- package/src/gl-matrix/quat.ts +789 -0
- package/src/gl-matrix/vec2.js +629 -0
- package/src/gl-matrix/vec3.js +827 -0
- package/src/gl-matrix/vec4.js +675 -0
- package/src/gl-matrix/wip/index.js +15 -0
- package/src/gl-matrix/wip/mat2.js +442 -0
- package/src/gl-matrix/wip/mat2d.js +505 -0
- package/src/gl-matrix/wip/quat2.ts +886 -0
- package/src/gl-matrix/wip/types.d.ts +93 -0
- package/src/index.ts +16 -14
- package/src/lib/assert.ts +1 -1
- package/src/lib/common.ts +31 -19
- package/src/lib/math-utils.ts +24 -26
- package/src/lib/validators.ts +3 -3
- package/dist/es5/classes/base/math-array.js +0 -348
- package/dist/es5/classes/base/math-array.js.map +0 -1
- package/dist/es5/classes/base/matrix.js +0 -108
- package/dist/es5/classes/base/matrix.js.map +0 -1
- package/dist/es5/classes/base/vector.js +0 -210
- package/dist/es5/classes/base/vector.js.map +0 -1
- package/dist/es5/classes/euler.js +0 -654
- package/dist/es5/classes/euler.js.map +0 -1
- package/dist/es5/classes/matrix3.js +0 -284
- package/dist/es5/classes/matrix3.js.map +0 -1
- package/dist/es5/classes/matrix4.js +0 -574
- package/dist/es5/classes/matrix4.js.map +0 -1
- package/dist/es5/classes/pose.js +0 -159
- package/dist/es5/classes/pose.js.map +0 -1
- package/dist/es5/classes/quaternion.js +0 -323
- package/dist/es5/classes/quaternion.js.map +0 -1
- package/dist/es5/classes/spherical-coordinates.js +0 -208
- package/dist/es5/classes/spherical-coordinates.js.map +0 -1
- package/dist/es5/classes/vector2.js +0 -156
- package/dist/es5/classes/vector2.js.map +0 -1
- package/dist/es5/classes/vector3.js +0 -213
- package/dist/es5/classes/vector3.js.map +0 -1
- package/dist/es5/classes/vector4.js +0 -185
- package/dist/es5/classes/vector4.js.map +0 -1
- package/dist/es5/docs/README.md +0 -0
- package/dist/es5/index.js +0 -236
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/assert.js +0 -13
- package/dist/es5/lib/assert.js.map +0 -1
- package/dist/es5/lib/common.js +0 -255
- package/dist/es5/lib/common.js.map +0 -1
- package/dist/es5/lib/gl-matrix-extras.js +0 -61
- package/dist/es5/lib/gl-matrix-extras.js.map +0 -1
- package/dist/es5/lib/gl-matrix.d.js +0 -2
- package/dist/es5/lib/math-utils.js +0 -34
- package/dist/es5/lib/math-utils.js.map +0 -1
- package/dist/es5/lib/validators.js +0 -53
- package/dist/es5/lib/validators.js.map +0 -1
- package/dist/esm/classes/base/math-array.js.map +0 -1
- package/dist/esm/classes/base/matrix.js.map +0 -1
- package/dist/esm/classes/base/vector.js.map +0 -1
- package/dist/esm/classes/euler.js.map +0 -1
- package/dist/esm/classes/matrix3.js.map +0 -1
- package/dist/esm/classes/matrix4.js.map +0 -1
- package/dist/esm/classes/pose.js.map +0 -1
- package/dist/esm/classes/quaternion.js.map +0 -1
- package/dist/esm/classes/spherical-coordinates.js.map +0 -1
- package/dist/esm/classes/vector2.js.map +0 -1
- package/dist/esm/classes/vector3.js.map +0 -1
- package/dist/esm/classes/vector4.js.map +0 -1
- package/dist/esm/docs/README.md +0 -0
- package/dist/esm/index.js +0 -16
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/assert.js +0 -6
- package/dist/esm/lib/assert.js.map +0 -1
- package/dist/esm/lib/common.js.map +0 -1
- package/dist/esm/lib/gl-matrix-extras.js.map +0 -1
- package/dist/esm/lib/math-utils.js +0 -27
- package/dist/esm/lib/math-utils.js.map +0 -1
- package/dist/esm/lib/validators.js.map +0 -1
- package/src/docs/README.md +0 -0
- /package/dist/{esm/lib → lib}/gl-matrix-extras.js +0 -0
- /package/dist/{esm/lib → lib}/gl-matrix.d.js +0 -0
- /package/dist/{es5/lib → lib}/gl-matrix.d.js.map +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3788 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// src/index.ts
|
|
34
|
+
var src_exports = {};
|
|
35
|
+
__export(src_exports, {
|
|
36
|
+
Euler: () => Euler,
|
|
37
|
+
Matrix3: () => Matrix3,
|
|
38
|
+
Matrix4: () => Matrix4,
|
|
39
|
+
Pose: () => Pose,
|
|
40
|
+
Quaternion: () => Quaternion,
|
|
41
|
+
SphericalCoordinates: () => SphericalCoordinates,
|
|
42
|
+
Vector2: () => Vector2,
|
|
43
|
+
Vector3: () => Vector3,
|
|
44
|
+
Vector4: () => Vector4,
|
|
45
|
+
_Euler: () => Euler,
|
|
46
|
+
_MathUtils: () => math_utils_exports,
|
|
47
|
+
_Pose: () => Pose,
|
|
48
|
+
_SphericalCoordinates: () => SphericalCoordinates,
|
|
49
|
+
acos: () => acos,
|
|
50
|
+
asin: () => asin,
|
|
51
|
+
assert: () => assert,
|
|
52
|
+
atan: () => atan,
|
|
53
|
+
clamp: () => clamp,
|
|
54
|
+
clone: () => clone,
|
|
55
|
+
config: () => config,
|
|
56
|
+
configure: () => configure,
|
|
57
|
+
cos: () => cos,
|
|
58
|
+
degrees: () => degrees,
|
|
59
|
+
equals: () => equals,
|
|
60
|
+
exactEquals: () => exactEquals,
|
|
61
|
+
formatValue: () => formatValue,
|
|
62
|
+
isArray: () => isArray,
|
|
63
|
+
lerp: () => lerp,
|
|
64
|
+
radians: () => radians,
|
|
65
|
+
sin: () => sin,
|
|
66
|
+
tan: () => tan,
|
|
67
|
+
toDegrees: () => toDegrees,
|
|
68
|
+
toRadians: () => toRadians,
|
|
69
|
+
withEpsilon: () => withEpsilon
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(src_exports);
|
|
72
|
+
|
|
73
|
+
// src/lib/common.ts
|
|
74
|
+
var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
|
|
75
|
+
var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
|
|
76
|
+
var DEFAULT_CONFIG = {
|
|
77
|
+
EPSILON: 1e-12,
|
|
78
|
+
debug: false,
|
|
79
|
+
precision: 4,
|
|
80
|
+
printTypes: false,
|
|
81
|
+
printDegrees: false,
|
|
82
|
+
printRowMajor: true,
|
|
83
|
+
_cartographicRadians: false
|
|
84
|
+
};
|
|
85
|
+
globalThis.mathgl = globalThis.mathgl || { config: __spreadValues({}, DEFAULT_CONFIG) };
|
|
86
|
+
var config = globalThis.mathgl.config;
|
|
87
|
+
function configure(options) {
|
|
88
|
+
Object.assign(config, options);
|
|
89
|
+
return config;
|
|
90
|
+
}
|
|
91
|
+
function formatValue(value, { precision = config.precision } = {}) {
|
|
92
|
+
value = round(value);
|
|
93
|
+
return `${parseFloat(value.toPrecision(precision))}`;
|
|
94
|
+
}
|
|
95
|
+
function isArray(value) {
|
|
96
|
+
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
97
|
+
}
|
|
98
|
+
function clone(array) {
|
|
99
|
+
return "clone" in array ? array.clone() : array.slice();
|
|
100
|
+
}
|
|
101
|
+
function toRadians(degrees2) {
|
|
102
|
+
return radians(degrees2);
|
|
103
|
+
}
|
|
104
|
+
function toDegrees(radians2) {
|
|
105
|
+
return degrees(radians2);
|
|
106
|
+
}
|
|
107
|
+
function radians(degrees2, result) {
|
|
108
|
+
return map(degrees2, (degrees3) => degrees3 * DEGREES_TO_RADIANS, result);
|
|
109
|
+
}
|
|
110
|
+
function degrees(radians2, result) {
|
|
111
|
+
return map(radians2, (radians3) => radians3 * RADIANS_TO_DEGREES, result);
|
|
112
|
+
}
|
|
113
|
+
function sin(radians2, result) {
|
|
114
|
+
return map(radians2, (angle2) => Math.sin(angle2), result);
|
|
115
|
+
}
|
|
116
|
+
function cos(radians2, result) {
|
|
117
|
+
return map(radians2, (angle2) => Math.cos(angle2), result);
|
|
118
|
+
}
|
|
119
|
+
function tan(radians2, result) {
|
|
120
|
+
return map(radians2, (angle2) => Math.tan(angle2), result);
|
|
121
|
+
}
|
|
122
|
+
function asin(radians2, result) {
|
|
123
|
+
return map(radians2, (angle2) => Math.asin(angle2), result);
|
|
124
|
+
}
|
|
125
|
+
function acos(radians2, result) {
|
|
126
|
+
return map(radians2, (angle2) => Math.acos(angle2), result);
|
|
127
|
+
}
|
|
128
|
+
function atan(radians2, result) {
|
|
129
|
+
return map(radians2, (angle2) => Math.atan(angle2), result);
|
|
130
|
+
}
|
|
131
|
+
function clamp(value, min, max) {
|
|
132
|
+
return map(value, (value2) => Math.max(min, Math.min(max, value2)));
|
|
133
|
+
}
|
|
134
|
+
function lerp(a, b, t) {
|
|
135
|
+
if (isArray(a)) {
|
|
136
|
+
return a.map((ai, i) => lerp(ai, b[i], t));
|
|
137
|
+
}
|
|
138
|
+
return t * b + (1 - t) * a;
|
|
139
|
+
}
|
|
140
|
+
function equals(a, b, epsilon) {
|
|
141
|
+
const oldEpsilon = config.EPSILON;
|
|
142
|
+
if (epsilon) {
|
|
143
|
+
config.EPSILON = epsilon;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
if (a === b) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (isArray(a) && isArray(b)) {
|
|
150
|
+
if (a.length !== b.length) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
for (let i = 0; i < a.length; ++i) {
|
|
154
|
+
if (!equals(a[i], b[i])) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
if (a && a.equals) {
|
|
161
|
+
return a.equals(b);
|
|
162
|
+
}
|
|
163
|
+
if (b && b.equals) {
|
|
164
|
+
return b.equals(a);
|
|
165
|
+
}
|
|
166
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
167
|
+
return Math.abs(a - b) <= config.EPSILON * Math.max(1, Math.abs(a), Math.abs(b));
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
} finally {
|
|
171
|
+
config.EPSILON = oldEpsilon;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function exactEquals(a, b) {
|
|
175
|
+
if (a === b) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
if (a && typeof a === "object" && b && typeof b === "object") {
|
|
179
|
+
if (a.constructor !== b.constructor) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
if (a.exactEquals) {
|
|
183
|
+
return a.exactEquals(b);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (isArray(a) && isArray(b)) {
|
|
187
|
+
if (a.length !== b.length) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
for (let i = 0; i < a.length; ++i) {
|
|
191
|
+
if (!exactEquals(a[i], b[i])) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
function withEpsilon(epsilon, func) {
|
|
200
|
+
const oldPrecision = config.EPSILON;
|
|
201
|
+
config.EPSILON = epsilon;
|
|
202
|
+
let value;
|
|
203
|
+
try {
|
|
204
|
+
value = func();
|
|
205
|
+
} finally {
|
|
206
|
+
config.EPSILON = oldPrecision;
|
|
207
|
+
}
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
function round(value) {
|
|
211
|
+
return Math.round(value / config.EPSILON) * config.EPSILON;
|
|
212
|
+
}
|
|
213
|
+
function duplicateArray(array) {
|
|
214
|
+
return array.clone ? array.clone() : new Array(array.length);
|
|
215
|
+
}
|
|
216
|
+
function map(value, func, result) {
|
|
217
|
+
if (isArray(value)) {
|
|
218
|
+
const array = value;
|
|
219
|
+
result = result || duplicateArray(array);
|
|
220
|
+
for (let i = 0; i < result.length && i < array.length; ++i) {
|
|
221
|
+
const val = typeof value === "number" ? value : value[i];
|
|
222
|
+
result[i] = func(val, i, result);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
return func(value);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/classes/base/math-array.ts
|
|
230
|
+
var MathArray = class extends Array {
|
|
231
|
+
clone() {
|
|
232
|
+
return new this.constructor().copy(this);
|
|
233
|
+
}
|
|
234
|
+
fromArray(array, offset = 0) {
|
|
235
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
236
|
+
this[i] = array[i + offset];
|
|
237
|
+
}
|
|
238
|
+
return this.check();
|
|
239
|
+
}
|
|
240
|
+
toArray(targetArray = [], offset = 0) {
|
|
241
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
242
|
+
targetArray[offset + i] = this[i];
|
|
243
|
+
}
|
|
244
|
+
return targetArray;
|
|
245
|
+
}
|
|
246
|
+
toObject(targetObject) {
|
|
247
|
+
return targetObject;
|
|
248
|
+
}
|
|
249
|
+
from(arrayOrObject) {
|
|
250
|
+
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : this.fromObject(arrayOrObject);
|
|
251
|
+
}
|
|
252
|
+
to(arrayOrObject) {
|
|
253
|
+
if (arrayOrObject === this) {
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
|
|
257
|
+
}
|
|
258
|
+
toTarget(target) {
|
|
259
|
+
return target ? this.to(target) : this;
|
|
260
|
+
}
|
|
261
|
+
toFloat32Array() {
|
|
262
|
+
return new Float32Array(this);
|
|
263
|
+
}
|
|
264
|
+
toString() {
|
|
265
|
+
return this.formatString(config);
|
|
266
|
+
}
|
|
267
|
+
formatString(opts) {
|
|
268
|
+
let string = "";
|
|
269
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
270
|
+
string += (i > 0 ? ", " : "") + formatValue(this[i], opts);
|
|
271
|
+
}
|
|
272
|
+
return `${opts.printTypes ? this.constructor.name : ""}[${string}]`;
|
|
273
|
+
}
|
|
274
|
+
equals(array) {
|
|
275
|
+
if (!array || this.length !== array.length) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
279
|
+
if (!equals(this[i], array[i])) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
exactEquals(array) {
|
|
286
|
+
if (!array || this.length !== array.length) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
290
|
+
if (this[i] !== array[i]) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
negate() {
|
|
297
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
298
|
+
this[i] = -this[i];
|
|
299
|
+
}
|
|
300
|
+
return this.check();
|
|
301
|
+
}
|
|
302
|
+
lerp(a, b, t) {
|
|
303
|
+
if (t === void 0) {
|
|
304
|
+
return this.lerp(this, a, b);
|
|
305
|
+
}
|
|
306
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
307
|
+
const ai = a[i];
|
|
308
|
+
const endValue = typeof b === "number" ? b : b[i];
|
|
309
|
+
this[i] = ai + t * (endValue - ai);
|
|
310
|
+
}
|
|
311
|
+
return this.check();
|
|
312
|
+
}
|
|
313
|
+
min(vector) {
|
|
314
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
315
|
+
this[i] = Math.min(vector[i], this[i]);
|
|
316
|
+
}
|
|
317
|
+
return this.check();
|
|
318
|
+
}
|
|
319
|
+
max(vector) {
|
|
320
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
321
|
+
this[i] = Math.max(vector[i], this[i]);
|
|
322
|
+
}
|
|
323
|
+
return this.check();
|
|
324
|
+
}
|
|
325
|
+
clamp(minVector, maxVector) {
|
|
326
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
327
|
+
this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
|
|
328
|
+
}
|
|
329
|
+
return this.check();
|
|
330
|
+
}
|
|
331
|
+
add(...vectors) {
|
|
332
|
+
for (const vector of vectors) {
|
|
333
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
334
|
+
this[i] += vector[i];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return this.check();
|
|
338
|
+
}
|
|
339
|
+
subtract(...vectors) {
|
|
340
|
+
for (const vector of vectors) {
|
|
341
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
342
|
+
this[i] -= vector[i];
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return this.check();
|
|
346
|
+
}
|
|
347
|
+
scale(scale5) {
|
|
348
|
+
if (typeof scale5 === "number") {
|
|
349
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
350
|
+
this[i] *= scale5;
|
|
351
|
+
}
|
|
352
|
+
} else {
|
|
353
|
+
for (let i = 0; i < this.ELEMENTS && i < scale5.length; ++i) {
|
|
354
|
+
this[i] *= scale5[i];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return this.check();
|
|
358
|
+
}
|
|
359
|
+
multiplyByScalar(scalar) {
|
|
360
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
361
|
+
this[i] *= scalar;
|
|
362
|
+
}
|
|
363
|
+
return this.check();
|
|
364
|
+
}
|
|
365
|
+
check() {
|
|
366
|
+
if (config.debug && !this.validate()) {
|
|
367
|
+
throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
|
|
368
|
+
}
|
|
369
|
+
return this;
|
|
370
|
+
}
|
|
371
|
+
validate() {
|
|
372
|
+
let valid = this.length === this.ELEMENTS;
|
|
373
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
374
|
+
valid = valid && Number.isFinite(this[i]);
|
|
375
|
+
}
|
|
376
|
+
return valid;
|
|
377
|
+
}
|
|
378
|
+
sub(a) {
|
|
379
|
+
return this.subtract(a);
|
|
380
|
+
}
|
|
381
|
+
setScalar(a) {
|
|
382
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
383
|
+
this[i] = a;
|
|
384
|
+
}
|
|
385
|
+
return this.check();
|
|
386
|
+
}
|
|
387
|
+
addScalar(a) {
|
|
388
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
389
|
+
this[i] += a;
|
|
390
|
+
}
|
|
391
|
+
return this.check();
|
|
392
|
+
}
|
|
393
|
+
subScalar(a) {
|
|
394
|
+
return this.addScalar(-a);
|
|
395
|
+
}
|
|
396
|
+
multiplyScalar(scalar) {
|
|
397
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
398
|
+
this[i] *= scalar;
|
|
399
|
+
}
|
|
400
|
+
return this.check();
|
|
401
|
+
}
|
|
402
|
+
divideScalar(a) {
|
|
403
|
+
return this.multiplyByScalar(1 / a);
|
|
404
|
+
}
|
|
405
|
+
clampScalar(min, max) {
|
|
406
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
407
|
+
this[i] = Math.min(Math.max(this[i], min), max);
|
|
408
|
+
}
|
|
409
|
+
return this.check();
|
|
410
|
+
}
|
|
411
|
+
get elements() {
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
// src/lib/validators.ts
|
|
417
|
+
function validateVector(v, length4) {
|
|
418
|
+
if (v.length !== length4) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
for (let i = 0; i < v.length; ++i) {
|
|
422
|
+
if (!Number.isFinite(v[i])) {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
function checkNumber(value) {
|
|
429
|
+
if (!Number.isFinite(value)) {
|
|
430
|
+
throw new Error(`Invalid number ${JSON.stringify(value)}`);
|
|
431
|
+
}
|
|
432
|
+
return value;
|
|
433
|
+
}
|
|
434
|
+
function checkVector(v, length4, callerName = "") {
|
|
435
|
+
if (config.debug && !validateVector(v, length4)) {
|
|
436
|
+
throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
|
|
437
|
+
}
|
|
438
|
+
return v;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/lib/assert.ts
|
|
442
|
+
function assert(condition, message) {
|
|
443
|
+
if (!condition) {
|
|
444
|
+
throw new Error(`math.gl assertion ${message}`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// src/classes/base/vector.ts
|
|
449
|
+
var Vector = class extends MathArray {
|
|
450
|
+
get x() {
|
|
451
|
+
return this[0];
|
|
452
|
+
}
|
|
453
|
+
set x(value) {
|
|
454
|
+
this[0] = checkNumber(value);
|
|
455
|
+
}
|
|
456
|
+
get y() {
|
|
457
|
+
return this[1];
|
|
458
|
+
}
|
|
459
|
+
set y(value) {
|
|
460
|
+
this[1] = checkNumber(value);
|
|
461
|
+
}
|
|
462
|
+
len() {
|
|
463
|
+
return Math.sqrt(this.lengthSquared());
|
|
464
|
+
}
|
|
465
|
+
magnitude() {
|
|
466
|
+
return this.len();
|
|
467
|
+
}
|
|
468
|
+
lengthSquared() {
|
|
469
|
+
let length4 = 0;
|
|
470
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
471
|
+
length4 += this[i] * this[i];
|
|
472
|
+
}
|
|
473
|
+
return length4;
|
|
474
|
+
}
|
|
475
|
+
magnitudeSquared() {
|
|
476
|
+
return this.lengthSquared();
|
|
477
|
+
}
|
|
478
|
+
distance(mathArray) {
|
|
479
|
+
return Math.sqrt(this.distanceSquared(mathArray));
|
|
480
|
+
}
|
|
481
|
+
distanceSquared(mathArray) {
|
|
482
|
+
let length4 = 0;
|
|
483
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
484
|
+
const dist = this[i] - mathArray[i];
|
|
485
|
+
length4 += dist * dist;
|
|
486
|
+
}
|
|
487
|
+
return checkNumber(length4);
|
|
488
|
+
}
|
|
489
|
+
dot(mathArray) {
|
|
490
|
+
let product = 0;
|
|
491
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
492
|
+
product += this[i] * mathArray[i];
|
|
493
|
+
}
|
|
494
|
+
return checkNumber(product);
|
|
495
|
+
}
|
|
496
|
+
normalize() {
|
|
497
|
+
const length4 = this.magnitude();
|
|
498
|
+
if (length4 !== 0) {
|
|
499
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
500
|
+
this[i] /= length4;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return this.check();
|
|
504
|
+
}
|
|
505
|
+
multiply(...vectors) {
|
|
506
|
+
for (const vector of vectors) {
|
|
507
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
508
|
+
this[i] *= vector[i];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return this.check();
|
|
512
|
+
}
|
|
513
|
+
divide(...vectors) {
|
|
514
|
+
for (const vector of vectors) {
|
|
515
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
516
|
+
this[i] /= vector[i];
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return this.check();
|
|
520
|
+
}
|
|
521
|
+
lengthSq() {
|
|
522
|
+
return this.lengthSquared();
|
|
523
|
+
}
|
|
524
|
+
distanceTo(vector) {
|
|
525
|
+
return this.distance(vector);
|
|
526
|
+
}
|
|
527
|
+
distanceToSquared(vector) {
|
|
528
|
+
return this.distanceSquared(vector);
|
|
529
|
+
}
|
|
530
|
+
getComponent(i) {
|
|
531
|
+
assert(i >= 0 && i < this.ELEMENTS, "index is out of range");
|
|
532
|
+
return checkNumber(this[i]);
|
|
533
|
+
}
|
|
534
|
+
setComponent(i, value) {
|
|
535
|
+
assert(i >= 0 && i < this.ELEMENTS, "index is out of range");
|
|
536
|
+
this[i] = value;
|
|
537
|
+
return this.check();
|
|
538
|
+
}
|
|
539
|
+
addVectors(a, b) {
|
|
540
|
+
return this.copy(a).add(b);
|
|
541
|
+
}
|
|
542
|
+
subVectors(a, b) {
|
|
543
|
+
return this.copy(a).subtract(b);
|
|
544
|
+
}
|
|
545
|
+
multiplyVectors(a, b) {
|
|
546
|
+
return this.copy(a).multiply(b);
|
|
547
|
+
}
|
|
548
|
+
addScaledVector(a, b) {
|
|
549
|
+
return this.add(new this.constructor(a).multiplyScalar(b));
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
// src/gl-matrix/common.js
|
|
554
|
+
var EPSILON = 1e-6;
|
|
555
|
+
var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
|
|
556
|
+
var degree = Math.PI / 180;
|
|
557
|
+
|
|
558
|
+
// src/gl-matrix/vec2.js
|
|
559
|
+
function create() {
|
|
560
|
+
const out = new ARRAY_TYPE(2);
|
|
561
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
562
|
+
out[0] = 0;
|
|
563
|
+
out[1] = 0;
|
|
564
|
+
}
|
|
565
|
+
return out;
|
|
566
|
+
}
|
|
567
|
+
function transformMat2(out, a, m) {
|
|
568
|
+
const x = a[0];
|
|
569
|
+
const y = a[1];
|
|
570
|
+
out[0] = m[0] * x + m[2] * y;
|
|
571
|
+
out[1] = m[1] * x + m[3] * y;
|
|
572
|
+
return out;
|
|
573
|
+
}
|
|
574
|
+
function transformMat2d(out, a, m) {
|
|
575
|
+
const x = a[0];
|
|
576
|
+
const y = a[1];
|
|
577
|
+
out[0] = m[0] * x + m[2] * y + m[4];
|
|
578
|
+
out[1] = m[1] * x + m[3] * y + m[5];
|
|
579
|
+
return out;
|
|
580
|
+
}
|
|
581
|
+
function transformMat3(out, a, m) {
|
|
582
|
+
const x = a[0];
|
|
583
|
+
const y = a[1];
|
|
584
|
+
out[0] = m[0] * x + m[3] * y + m[6];
|
|
585
|
+
out[1] = m[1] * x + m[4] * y + m[7];
|
|
586
|
+
return out;
|
|
587
|
+
}
|
|
588
|
+
function transformMat4(out, a, m) {
|
|
589
|
+
const x = a[0];
|
|
590
|
+
const y = a[1];
|
|
591
|
+
out[0] = m[0] * x + m[4] * y + m[12];
|
|
592
|
+
out[1] = m[1] * x + m[5] * y + m[13];
|
|
593
|
+
return out;
|
|
594
|
+
}
|
|
595
|
+
var forEach = function() {
|
|
596
|
+
const vec = create();
|
|
597
|
+
return function(a, stride, offset, count, fn, arg) {
|
|
598
|
+
let i;
|
|
599
|
+
let l;
|
|
600
|
+
if (!stride) {
|
|
601
|
+
stride = 2;
|
|
602
|
+
}
|
|
603
|
+
if (!offset) {
|
|
604
|
+
offset = 0;
|
|
605
|
+
}
|
|
606
|
+
if (count) {
|
|
607
|
+
l = Math.min(count * stride + offset, a.length);
|
|
608
|
+
} else {
|
|
609
|
+
l = a.length;
|
|
610
|
+
}
|
|
611
|
+
for (i = offset; i < l; i += stride) {
|
|
612
|
+
vec[0] = a[i];
|
|
613
|
+
vec[1] = a[i + 1];
|
|
614
|
+
fn(vec, vec, arg);
|
|
615
|
+
a[i] = vec[0];
|
|
616
|
+
a[i + 1] = vec[1];
|
|
617
|
+
}
|
|
618
|
+
return a;
|
|
619
|
+
};
|
|
620
|
+
}();
|
|
621
|
+
|
|
622
|
+
// src/lib/gl-matrix-extras.ts
|
|
623
|
+
function vec2_transformMat4AsVector(out, a, m) {
|
|
624
|
+
const x = a[0];
|
|
625
|
+
const y = a[1];
|
|
626
|
+
const w = m[3] * x + m[7] * y || 1;
|
|
627
|
+
out[0] = (m[0] * x + m[4] * y) / w;
|
|
628
|
+
out[1] = (m[1] * x + m[5] * y) / w;
|
|
629
|
+
return out;
|
|
630
|
+
}
|
|
631
|
+
function vec3_transformMat4AsVector(out, a, m) {
|
|
632
|
+
const x = a[0];
|
|
633
|
+
const y = a[1];
|
|
634
|
+
const z = a[2];
|
|
635
|
+
const w = m[3] * x + m[7] * y + m[11] * z || 1;
|
|
636
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z) / w;
|
|
637
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z) / w;
|
|
638
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z) / w;
|
|
639
|
+
return out;
|
|
640
|
+
}
|
|
641
|
+
function vec3_transformMat2(out, a, m) {
|
|
642
|
+
const x = a[0];
|
|
643
|
+
const y = a[1];
|
|
644
|
+
out[0] = m[0] * x + m[2] * y;
|
|
645
|
+
out[1] = m[1] * x + m[3] * y;
|
|
646
|
+
out[2] = a[2];
|
|
647
|
+
return out;
|
|
648
|
+
}
|
|
649
|
+
function vec4_transformMat2(out, a, m) {
|
|
650
|
+
const x = a[0];
|
|
651
|
+
const y = a[1];
|
|
652
|
+
out[0] = m[0] * x + m[2] * y;
|
|
653
|
+
out[1] = m[1] * x + m[3] * y;
|
|
654
|
+
out[2] = a[2];
|
|
655
|
+
out[3] = a[3];
|
|
656
|
+
return out;
|
|
657
|
+
}
|
|
658
|
+
function vec4_transformMat3(out, a, m) {
|
|
659
|
+
const x = a[0];
|
|
660
|
+
const y = a[1];
|
|
661
|
+
const z = a[2];
|
|
662
|
+
out[0] = m[0] * x + m[3] * y + m[6] * z;
|
|
663
|
+
out[1] = m[1] * x + m[4] * y + m[7] * z;
|
|
664
|
+
out[2] = m[2] * x + m[5] * y + m[8] * z;
|
|
665
|
+
out[3] = a[3];
|
|
666
|
+
return out;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// src/classes/vector2.ts
|
|
670
|
+
var Vector2 = class extends Vector {
|
|
671
|
+
constructor(x = 0, y = 0) {
|
|
672
|
+
super(2);
|
|
673
|
+
if (isArray(x) && arguments.length === 1) {
|
|
674
|
+
this.copy(x);
|
|
675
|
+
} else {
|
|
676
|
+
if (config.debug) {
|
|
677
|
+
checkNumber(x);
|
|
678
|
+
checkNumber(y);
|
|
679
|
+
}
|
|
680
|
+
this[0] = x;
|
|
681
|
+
this[1] = y;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
set(x, y) {
|
|
685
|
+
this[0] = x;
|
|
686
|
+
this[1] = y;
|
|
687
|
+
return this.check();
|
|
688
|
+
}
|
|
689
|
+
copy(array) {
|
|
690
|
+
this[0] = array[0];
|
|
691
|
+
this[1] = array[1];
|
|
692
|
+
return this.check();
|
|
693
|
+
}
|
|
694
|
+
fromObject(object) {
|
|
695
|
+
if (config.debug) {
|
|
696
|
+
checkNumber(object.x);
|
|
697
|
+
checkNumber(object.y);
|
|
698
|
+
}
|
|
699
|
+
this[0] = object.x;
|
|
700
|
+
this[1] = object.y;
|
|
701
|
+
return this.check();
|
|
702
|
+
}
|
|
703
|
+
toObject(object) {
|
|
704
|
+
object.x = this[0];
|
|
705
|
+
object.y = this[1];
|
|
706
|
+
return object;
|
|
707
|
+
}
|
|
708
|
+
get ELEMENTS() {
|
|
709
|
+
return 2;
|
|
710
|
+
}
|
|
711
|
+
horizontalAngle() {
|
|
712
|
+
return Math.atan2(this.y, this.x);
|
|
713
|
+
}
|
|
714
|
+
verticalAngle() {
|
|
715
|
+
return Math.atan2(this.x, this.y);
|
|
716
|
+
}
|
|
717
|
+
transform(matrix4) {
|
|
718
|
+
return this.transformAsPoint(matrix4);
|
|
719
|
+
}
|
|
720
|
+
transformAsPoint(matrix4) {
|
|
721
|
+
transformMat4(this, this, matrix4);
|
|
722
|
+
return this.check();
|
|
723
|
+
}
|
|
724
|
+
transformAsVector(matrix4) {
|
|
725
|
+
vec2_transformMat4AsVector(this, this, matrix4);
|
|
726
|
+
return this.check();
|
|
727
|
+
}
|
|
728
|
+
transformByMatrix3(matrix3) {
|
|
729
|
+
transformMat3(this, this, matrix3);
|
|
730
|
+
return this.check();
|
|
731
|
+
}
|
|
732
|
+
transformByMatrix2x3(matrix2x3) {
|
|
733
|
+
transformMat2d(this, this, matrix2x3);
|
|
734
|
+
return this.check();
|
|
735
|
+
}
|
|
736
|
+
transformByMatrix2(matrix2) {
|
|
737
|
+
transformMat2(this, this, matrix2);
|
|
738
|
+
return this.check();
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
// src/gl-matrix/vec3.js
|
|
743
|
+
function create2() {
|
|
744
|
+
const out = new ARRAY_TYPE(3);
|
|
745
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
746
|
+
out[0] = 0;
|
|
747
|
+
out[1] = 0;
|
|
748
|
+
out[2] = 0;
|
|
749
|
+
}
|
|
750
|
+
return out;
|
|
751
|
+
}
|
|
752
|
+
function length(a) {
|
|
753
|
+
const x = a[0];
|
|
754
|
+
const y = a[1];
|
|
755
|
+
const z = a[2];
|
|
756
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
757
|
+
}
|
|
758
|
+
function fromValues(x, y, z) {
|
|
759
|
+
const out = new ARRAY_TYPE(3);
|
|
760
|
+
out[0] = x;
|
|
761
|
+
out[1] = y;
|
|
762
|
+
out[2] = z;
|
|
763
|
+
return out;
|
|
764
|
+
}
|
|
765
|
+
function normalize(out, a) {
|
|
766
|
+
const x = a[0];
|
|
767
|
+
const y = a[1];
|
|
768
|
+
const z = a[2];
|
|
769
|
+
let len2 = x * x + y * y + z * z;
|
|
770
|
+
if (len2 > 0) {
|
|
771
|
+
len2 = 1 / Math.sqrt(len2);
|
|
772
|
+
}
|
|
773
|
+
out[0] = a[0] * len2;
|
|
774
|
+
out[1] = a[1] * len2;
|
|
775
|
+
out[2] = a[2] * len2;
|
|
776
|
+
return out;
|
|
777
|
+
}
|
|
778
|
+
function dot(a, b) {
|
|
779
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
780
|
+
}
|
|
781
|
+
function cross(out, a, b) {
|
|
782
|
+
const ax = a[0];
|
|
783
|
+
const ay = a[1];
|
|
784
|
+
const az = a[2];
|
|
785
|
+
const bx = b[0];
|
|
786
|
+
const by = b[1];
|
|
787
|
+
const bz = b[2];
|
|
788
|
+
out[0] = ay * bz - az * by;
|
|
789
|
+
out[1] = az * bx - ax * bz;
|
|
790
|
+
out[2] = ax * by - ay * bx;
|
|
791
|
+
return out;
|
|
792
|
+
}
|
|
793
|
+
function transformMat42(out, a, m) {
|
|
794
|
+
const x = a[0];
|
|
795
|
+
const y = a[1];
|
|
796
|
+
const z = a[2];
|
|
797
|
+
let w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
798
|
+
w = w || 1;
|
|
799
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
|
|
800
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
|
|
801
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
|
|
802
|
+
return out;
|
|
803
|
+
}
|
|
804
|
+
function transformMat32(out, a, m) {
|
|
805
|
+
const x = a[0];
|
|
806
|
+
const y = a[1];
|
|
807
|
+
const z = a[2];
|
|
808
|
+
out[0] = x * m[0] + y * m[3] + z * m[6];
|
|
809
|
+
out[1] = x * m[1] + y * m[4] + z * m[7];
|
|
810
|
+
out[2] = x * m[2] + y * m[5] + z * m[8];
|
|
811
|
+
return out;
|
|
812
|
+
}
|
|
813
|
+
function transformQuat(out, a, q) {
|
|
814
|
+
const qx = q[0];
|
|
815
|
+
const qy = q[1];
|
|
816
|
+
const qz = q[2];
|
|
817
|
+
const qw = q[3];
|
|
818
|
+
const x = a[0];
|
|
819
|
+
const y = a[1];
|
|
820
|
+
const z = a[2];
|
|
821
|
+
let uvx = qy * z - qz * y;
|
|
822
|
+
let uvy = qz * x - qx * z;
|
|
823
|
+
let uvz = qx * y - qy * x;
|
|
824
|
+
let uuvx = qy * uvz - qz * uvy;
|
|
825
|
+
let uuvy = qz * uvx - qx * uvz;
|
|
826
|
+
let uuvz = qx * uvy - qy * uvx;
|
|
827
|
+
const w2 = qw * 2;
|
|
828
|
+
uvx *= w2;
|
|
829
|
+
uvy *= w2;
|
|
830
|
+
uvz *= w2;
|
|
831
|
+
uuvx *= 2;
|
|
832
|
+
uuvy *= 2;
|
|
833
|
+
uuvz *= 2;
|
|
834
|
+
out[0] = x + uvx + uuvx;
|
|
835
|
+
out[1] = y + uvy + uuvy;
|
|
836
|
+
out[2] = z + uvz + uuvz;
|
|
837
|
+
return out;
|
|
838
|
+
}
|
|
839
|
+
function rotateX(out, a, b, rad) {
|
|
840
|
+
const p = [];
|
|
841
|
+
const r = [];
|
|
842
|
+
p[0] = a[0] - b[0];
|
|
843
|
+
p[1] = a[1] - b[1];
|
|
844
|
+
p[2] = a[2] - b[2];
|
|
845
|
+
r[0] = p[0];
|
|
846
|
+
r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
|
|
847
|
+
r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad);
|
|
848
|
+
out[0] = r[0] + b[0];
|
|
849
|
+
out[1] = r[1] + b[1];
|
|
850
|
+
out[2] = r[2] + b[2];
|
|
851
|
+
return out;
|
|
852
|
+
}
|
|
853
|
+
function rotateY(out, a, b, rad) {
|
|
854
|
+
const p = [];
|
|
855
|
+
const r = [];
|
|
856
|
+
p[0] = a[0] - b[0];
|
|
857
|
+
p[1] = a[1] - b[1];
|
|
858
|
+
p[2] = a[2] - b[2];
|
|
859
|
+
r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
|
|
860
|
+
r[1] = p[1];
|
|
861
|
+
r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad);
|
|
862
|
+
out[0] = r[0] + b[0];
|
|
863
|
+
out[1] = r[1] + b[1];
|
|
864
|
+
out[2] = r[2] + b[2];
|
|
865
|
+
return out;
|
|
866
|
+
}
|
|
867
|
+
function rotateZ(out, a, b, rad) {
|
|
868
|
+
const p = [];
|
|
869
|
+
const r = [];
|
|
870
|
+
p[0] = a[0] - b[0];
|
|
871
|
+
p[1] = a[1] - b[1];
|
|
872
|
+
p[2] = a[2] - b[2];
|
|
873
|
+
r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
|
|
874
|
+
r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
|
|
875
|
+
r[2] = p[2];
|
|
876
|
+
out[0] = r[0] + b[0];
|
|
877
|
+
out[1] = r[1] + b[1];
|
|
878
|
+
out[2] = r[2] + b[2];
|
|
879
|
+
return out;
|
|
880
|
+
}
|
|
881
|
+
function angle(a, b) {
|
|
882
|
+
const ax = a[0];
|
|
883
|
+
const ay = a[1];
|
|
884
|
+
const az = a[2];
|
|
885
|
+
const bx = b[0];
|
|
886
|
+
const by = b[1];
|
|
887
|
+
const bz = b[2];
|
|
888
|
+
const mag = Math.sqrt((ax * ax + ay * ay + az * az) * (bx * bx + by * by + bz * bz));
|
|
889
|
+
const cosine = mag && dot(a, b) / mag;
|
|
890
|
+
return Math.acos(Math.min(Math.max(cosine, -1), 1));
|
|
891
|
+
}
|
|
892
|
+
var len = length;
|
|
893
|
+
var forEach2 = function() {
|
|
894
|
+
const vec = create2();
|
|
895
|
+
return function(a, stride, offset, count, fn, arg) {
|
|
896
|
+
let i;
|
|
897
|
+
let l;
|
|
898
|
+
if (!stride) {
|
|
899
|
+
stride = 3;
|
|
900
|
+
}
|
|
901
|
+
if (!offset) {
|
|
902
|
+
offset = 0;
|
|
903
|
+
}
|
|
904
|
+
if (count) {
|
|
905
|
+
l = Math.min(count * stride + offset, a.length);
|
|
906
|
+
} else {
|
|
907
|
+
l = a.length;
|
|
908
|
+
}
|
|
909
|
+
for (i = offset; i < l; i += stride) {
|
|
910
|
+
vec[0] = a[i];
|
|
911
|
+
vec[1] = a[i + 1];
|
|
912
|
+
vec[2] = a[i + 2];
|
|
913
|
+
fn(vec, vec, arg);
|
|
914
|
+
a[i] = vec[0];
|
|
915
|
+
a[i + 1] = vec[1];
|
|
916
|
+
a[i + 2] = vec[2];
|
|
917
|
+
}
|
|
918
|
+
return a;
|
|
919
|
+
};
|
|
920
|
+
}();
|
|
921
|
+
|
|
922
|
+
// src/classes/vector3.ts
|
|
923
|
+
var ORIGIN = [0, 0, 0];
|
|
924
|
+
var ZERO;
|
|
925
|
+
var Vector3 = class extends Vector {
|
|
926
|
+
static get ZERO() {
|
|
927
|
+
if (!ZERO) {
|
|
928
|
+
ZERO = new Vector3(0, 0, 0);
|
|
929
|
+
Object.freeze(ZERO);
|
|
930
|
+
}
|
|
931
|
+
return ZERO;
|
|
932
|
+
}
|
|
933
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
934
|
+
super(-0, -0, -0);
|
|
935
|
+
if (arguments.length === 1 && isArray(x)) {
|
|
936
|
+
this.copy(x);
|
|
937
|
+
} else {
|
|
938
|
+
if (config.debug) {
|
|
939
|
+
checkNumber(x);
|
|
940
|
+
checkNumber(y);
|
|
941
|
+
checkNumber(z);
|
|
942
|
+
}
|
|
943
|
+
this[0] = x;
|
|
944
|
+
this[1] = y;
|
|
945
|
+
this[2] = z;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
set(x, y, z) {
|
|
949
|
+
this[0] = x;
|
|
950
|
+
this[1] = y;
|
|
951
|
+
this[2] = z;
|
|
952
|
+
return this.check();
|
|
953
|
+
}
|
|
954
|
+
copy(array) {
|
|
955
|
+
this[0] = array[0];
|
|
956
|
+
this[1] = array[1];
|
|
957
|
+
this[2] = array[2];
|
|
958
|
+
return this.check();
|
|
959
|
+
}
|
|
960
|
+
fromObject(object) {
|
|
961
|
+
if (config.debug) {
|
|
962
|
+
checkNumber(object.x);
|
|
963
|
+
checkNumber(object.y);
|
|
964
|
+
checkNumber(object.z);
|
|
965
|
+
}
|
|
966
|
+
this[0] = object.x;
|
|
967
|
+
this[1] = object.y;
|
|
968
|
+
this[2] = object.z;
|
|
969
|
+
return this.check();
|
|
970
|
+
}
|
|
971
|
+
toObject(object) {
|
|
972
|
+
object.x = this[0];
|
|
973
|
+
object.y = this[1];
|
|
974
|
+
object.z = this[2];
|
|
975
|
+
return object;
|
|
976
|
+
}
|
|
977
|
+
get ELEMENTS() {
|
|
978
|
+
return 3;
|
|
979
|
+
}
|
|
980
|
+
get z() {
|
|
981
|
+
return this[2];
|
|
982
|
+
}
|
|
983
|
+
set z(value) {
|
|
984
|
+
this[2] = checkNumber(value);
|
|
985
|
+
}
|
|
986
|
+
angle(vector) {
|
|
987
|
+
return angle(this, vector);
|
|
988
|
+
}
|
|
989
|
+
cross(vector) {
|
|
990
|
+
cross(this, this, vector);
|
|
991
|
+
return this.check();
|
|
992
|
+
}
|
|
993
|
+
rotateX({ radians: radians2, origin = ORIGIN }) {
|
|
994
|
+
rotateX(this, this, origin, radians2);
|
|
995
|
+
return this.check();
|
|
996
|
+
}
|
|
997
|
+
rotateY({ radians: radians2, origin = ORIGIN }) {
|
|
998
|
+
rotateY(this, this, origin, radians2);
|
|
999
|
+
return this.check();
|
|
1000
|
+
}
|
|
1001
|
+
rotateZ({ radians: radians2, origin = ORIGIN }) {
|
|
1002
|
+
rotateZ(this, this, origin, radians2);
|
|
1003
|
+
return this.check();
|
|
1004
|
+
}
|
|
1005
|
+
transform(matrix4) {
|
|
1006
|
+
return this.transformAsPoint(matrix4);
|
|
1007
|
+
}
|
|
1008
|
+
transformAsPoint(matrix4) {
|
|
1009
|
+
transformMat42(this, this, matrix4);
|
|
1010
|
+
return this.check();
|
|
1011
|
+
}
|
|
1012
|
+
transformAsVector(matrix4) {
|
|
1013
|
+
vec3_transformMat4AsVector(this, this, matrix4);
|
|
1014
|
+
return this.check();
|
|
1015
|
+
}
|
|
1016
|
+
transformByMatrix3(matrix3) {
|
|
1017
|
+
transformMat32(this, this, matrix3);
|
|
1018
|
+
return this.check();
|
|
1019
|
+
}
|
|
1020
|
+
transformByMatrix2(matrix2) {
|
|
1021
|
+
vec3_transformMat2(this, this, matrix2);
|
|
1022
|
+
return this.check();
|
|
1023
|
+
}
|
|
1024
|
+
transformByQuaternion(quaternion) {
|
|
1025
|
+
transformQuat(this, this, quaternion);
|
|
1026
|
+
return this.check();
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// src/classes/vector4.ts
|
|
1031
|
+
var ZERO2;
|
|
1032
|
+
var Vector4 = class extends Vector {
|
|
1033
|
+
static get ZERO() {
|
|
1034
|
+
if (!ZERO2) {
|
|
1035
|
+
ZERO2 = new Vector4(0, 0, 0, 0);
|
|
1036
|
+
Object.freeze(ZERO2);
|
|
1037
|
+
}
|
|
1038
|
+
return ZERO2;
|
|
1039
|
+
}
|
|
1040
|
+
constructor(x = 0, y = 0, z = 0, w = 0) {
|
|
1041
|
+
super(-0, -0, -0, -0);
|
|
1042
|
+
if (isArray(x) && arguments.length === 1) {
|
|
1043
|
+
this.copy(x);
|
|
1044
|
+
} else {
|
|
1045
|
+
if (config.debug) {
|
|
1046
|
+
checkNumber(x);
|
|
1047
|
+
checkNumber(y);
|
|
1048
|
+
checkNumber(z);
|
|
1049
|
+
checkNumber(w);
|
|
1050
|
+
}
|
|
1051
|
+
this[0] = x;
|
|
1052
|
+
this[1] = y;
|
|
1053
|
+
this[2] = z;
|
|
1054
|
+
this[3] = w;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
set(x, y, z, w) {
|
|
1058
|
+
this[0] = x;
|
|
1059
|
+
this[1] = y;
|
|
1060
|
+
this[2] = z;
|
|
1061
|
+
this[3] = w;
|
|
1062
|
+
return this.check();
|
|
1063
|
+
}
|
|
1064
|
+
copy(array) {
|
|
1065
|
+
this[0] = array[0];
|
|
1066
|
+
this[1] = array[1];
|
|
1067
|
+
this[2] = array[2];
|
|
1068
|
+
this[3] = array[3];
|
|
1069
|
+
return this.check();
|
|
1070
|
+
}
|
|
1071
|
+
fromObject(object) {
|
|
1072
|
+
if (config.debug) {
|
|
1073
|
+
checkNumber(object.x);
|
|
1074
|
+
checkNumber(object.y);
|
|
1075
|
+
checkNumber(object.z);
|
|
1076
|
+
checkNumber(object.w);
|
|
1077
|
+
}
|
|
1078
|
+
this[0] = object.x;
|
|
1079
|
+
this[1] = object.y;
|
|
1080
|
+
this[2] = object.z;
|
|
1081
|
+
this[3] = object.w;
|
|
1082
|
+
return this;
|
|
1083
|
+
}
|
|
1084
|
+
toObject(object) {
|
|
1085
|
+
object.x = this[0];
|
|
1086
|
+
object.y = this[1];
|
|
1087
|
+
object.z = this[2];
|
|
1088
|
+
object.w = this[3];
|
|
1089
|
+
return object;
|
|
1090
|
+
}
|
|
1091
|
+
get ELEMENTS() {
|
|
1092
|
+
return 4;
|
|
1093
|
+
}
|
|
1094
|
+
get z() {
|
|
1095
|
+
return this[2];
|
|
1096
|
+
}
|
|
1097
|
+
set z(value) {
|
|
1098
|
+
this[2] = checkNumber(value);
|
|
1099
|
+
}
|
|
1100
|
+
get w() {
|
|
1101
|
+
return this[3];
|
|
1102
|
+
}
|
|
1103
|
+
set w(value) {
|
|
1104
|
+
this[3] = checkNumber(value);
|
|
1105
|
+
}
|
|
1106
|
+
transform(matrix4) {
|
|
1107
|
+
transformMat42(this, this, matrix4);
|
|
1108
|
+
return this.check();
|
|
1109
|
+
}
|
|
1110
|
+
transformByMatrix3(matrix3) {
|
|
1111
|
+
vec4_transformMat3(this, this, matrix3);
|
|
1112
|
+
return this.check();
|
|
1113
|
+
}
|
|
1114
|
+
transformByMatrix2(matrix2) {
|
|
1115
|
+
vec4_transformMat2(this, this, matrix2);
|
|
1116
|
+
return this.check();
|
|
1117
|
+
}
|
|
1118
|
+
transformByQuaternion(quaternion) {
|
|
1119
|
+
transformQuat(this, this, quaternion);
|
|
1120
|
+
return this.check();
|
|
1121
|
+
}
|
|
1122
|
+
applyMatrix4(m) {
|
|
1123
|
+
m.transform(this, this);
|
|
1124
|
+
return this;
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
// src/classes/base/matrix.ts
|
|
1129
|
+
var Matrix = class extends MathArray {
|
|
1130
|
+
toString() {
|
|
1131
|
+
let string = "[";
|
|
1132
|
+
if (config.printRowMajor) {
|
|
1133
|
+
string += "row-major:";
|
|
1134
|
+
for (let row = 0; row < this.RANK; ++row) {
|
|
1135
|
+
for (let col = 0; col < this.RANK; ++col) {
|
|
1136
|
+
string += ` ${this[col * this.RANK + row]}`;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
} else {
|
|
1140
|
+
string += "column-major:";
|
|
1141
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1142
|
+
string += ` ${this[i]}`;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
string += "]";
|
|
1146
|
+
return string;
|
|
1147
|
+
}
|
|
1148
|
+
getElementIndex(row, col) {
|
|
1149
|
+
return col * this.RANK + row;
|
|
1150
|
+
}
|
|
1151
|
+
getElement(row, col) {
|
|
1152
|
+
return this[col * this.RANK + row];
|
|
1153
|
+
}
|
|
1154
|
+
setElement(row, col, value) {
|
|
1155
|
+
this[col * this.RANK + row] = checkNumber(value);
|
|
1156
|
+
return this;
|
|
1157
|
+
}
|
|
1158
|
+
getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) {
|
|
1159
|
+
const firstIndex = columnIndex * this.RANK;
|
|
1160
|
+
for (let i = 0; i < this.RANK; ++i) {
|
|
1161
|
+
result[i] = this[firstIndex + i];
|
|
1162
|
+
}
|
|
1163
|
+
return result;
|
|
1164
|
+
}
|
|
1165
|
+
setColumn(columnIndex, columnVector) {
|
|
1166
|
+
const firstIndex = columnIndex * this.RANK;
|
|
1167
|
+
for (let i = 0; i < this.RANK; ++i) {
|
|
1168
|
+
this[firstIndex + i] = columnVector[i];
|
|
1169
|
+
}
|
|
1170
|
+
return this;
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
// src/gl-matrix/mat3.js
|
|
1175
|
+
function create3() {
|
|
1176
|
+
const out = new ARRAY_TYPE(9);
|
|
1177
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
1178
|
+
out[1] = 0;
|
|
1179
|
+
out[2] = 0;
|
|
1180
|
+
out[3] = 0;
|
|
1181
|
+
out[5] = 0;
|
|
1182
|
+
out[6] = 0;
|
|
1183
|
+
out[7] = 0;
|
|
1184
|
+
}
|
|
1185
|
+
out[0] = 1;
|
|
1186
|
+
out[4] = 1;
|
|
1187
|
+
out[8] = 1;
|
|
1188
|
+
return out;
|
|
1189
|
+
}
|
|
1190
|
+
function transpose(out, a) {
|
|
1191
|
+
if (out === a) {
|
|
1192
|
+
const a01 = a[1];
|
|
1193
|
+
const a02 = a[2];
|
|
1194
|
+
const a12 = a[5];
|
|
1195
|
+
out[1] = a[3];
|
|
1196
|
+
out[2] = a[6];
|
|
1197
|
+
out[3] = a01;
|
|
1198
|
+
out[5] = a[7];
|
|
1199
|
+
out[6] = a02;
|
|
1200
|
+
out[7] = a12;
|
|
1201
|
+
} else {
|
|
1202
|
+
out[0] = a[0];
|
|
1203
|
+
out[1] = a[3];
|
|
1204
|
+
out[2] = a[6];
|
|
1205
|
+
out[3] = a[1];
|
|
1206
|
+
out[4] = a[4];
|
|
1207
|
+
out[5] = a[7];
|
|
1208
|
+
out[6] = a[2];
|
|
1209
|
+
out[7] = a[5];
|
|
1210
|
+
out[8] = a[8];
|
|
1211
|
+
}
|
|
1212
|
+
return out;
|
|
1213
|
+
}
|
|
1214
|
+
function invert(out, a) {
|
|
1215
|
+
const a00 = a[0];
|
|
1216
|
+
const a01 = a[1];
|
|
1217
|
+
const a02 = a[2];
|
|
1218
|
+
const a10 = a[3];
|
|
1219
|
+
const a11 = a[4];
|
|
1220
|
+
const a12 = a[5];
|
|
1221
|
+
const a20 = a[6];
|
|
1222
|
+
const a21 = a[7];
|
|
1223
|
+
const a22 = a[8];
|
|
1224
|
+
const b01 = a22 * a11 - a12 * a21;
|
|
1225
|
+
const b11 = -a22 * a10 + a12 * a20;
|
|
1226
|
+
const b21 = a21 * a10 - a11 * a20;
|
|
1227
|
+
let det = a00 * b01 + a01 * b11 + a02 * b21;
|
|
1228
|
+
if (!det) {
|
|
1229
|
+
return null;
|
|
1230
|
+
}
|
|
1231
|
+
det = 1 / det;
|
|
1232
|
+
out[0] = b01 * det;
|
|
1233
|
+
out[1] = (-a22 * a01 + a02 * a21) * det;
|
|
1234
|
+
out[2] = (a12 * a01 - a02 * a11) * det;
|
|
1235
|
+
out[3] = b11 * det;
|
|
1236
|
+
out[4] = (a22 * a00 - a02 * a20) * det;
|
|
1237
|
+
out[5] = (-a12 * a00 + a02 * a10) * det;
|
|
1238
|
+
out[6] = b21 * det;
|
|
1239
|
+
out[7] = (-a21 * a00 + a01 * a20) * det;
|
|
1240
|
+
out[8] = (a11 * a00 - a01 * a10) * det;
|
|
1241
|
+
return out;
|
|
1242
|
+
}
|
|
1243
|
+
function determinant(a) {
|
|
1244
|
+
const a00 = a[0];
|
|
1245
|
+
const a01 = a[1];
|
|
1246
|
+
const a02 = a[2];
|
|
1247
|
+
const a10 = a[3];
|
|
1248
|
+
const a11 = a[4];
|
|
1249
|
+
const a12 = a[5];
|
|
1250
|
+
const a20 = a[6];
|
|
1251
|
+
const a21 = a[7];
|
|
1252
|
+
const a22 = a[8];
|
|
1253
|
+
return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
|
|
1254
|
+
}
|
|
1255
|
+
function multiply(out, a, b) {
|
|
1256
|
+
const a00 = a[0];
|
|
1257
|
+
const a01 = a[1];
|
|
1258
|
+
const a02 = a[2];
|
|
1259
|
+
const a10 = a[3];
|
|
1260
|
+
const a11 = a[4];
|
|
1261
|
+
const a12 = a[5];
|
|
1262
|
+
const a20 = a[6];
|
|
1263
|
+
const a21 = a[7];
|
|
1264
|
+
const a22 = a[8];
|
|
1265
|
+
const b00 = b[0];
|
|
1266
|
+
const b01 = b[1];
|
|
1267
|
+
const b02 = b[2];
|
|
1268
|
+
const b10 = b[3];
|
|
1269
|
+
const b11 = b[4];
|
|
1270
|
+
const b12 = b[5];
|
|
1271
|
+
const b20 = b[6];
|
|
1272
|
+
const b21 = b[7];
|
|
1273
|
+
const b22 = b[8];
|
|
1274
|
+
out[0] = b00 * a00 + b01 * a10 + b02 * a20;
|
|
1275
|
+
out[1] = b00 * a01 + b01 * a11 + b02 * a21;
|
|
1276
|
+
out[2] = b00 * a02 + b01 * a12 + b02 * a22;
|
|
1277
|
+
out[3] = b10 * a00 + b11 * a10 + b12 * a20;
|
|
1278
|
+
out[4] = b10 * a01 + b11 * a11 + b12 * a21;
|
|
1279
|
+
out[5] = b10 * a02 + b11 * a12 + b12 * a22;
|
|
1280
|
+
out[6] = b20 * a00 + b21 * a10 + b22 * a20;
|
|
1281
|
+
out[7] = b20 * a01 + b21 * a11 + b22 * a21;
|
|
1282
|
+
out[8] = b20 * a02 + b21 * a12 + b22 * a22;
|
|
1283
|
+
return out;
|
|
1284
|
+
}
|
|
1285
|
+
function translate(out, a, v) {
|
|
1286
|
+
const a00 = a[0];
|
|
1287
|
+
const a01 = a[1];
|
|
1288
|
+
const a02 = a[2];
|
|
1289
|
+
const a10 = a[3];
|
|
1290
|
+
const a11 = a[4];
|
|
1291
|
+
const a12 = a[5];
|
|
1292
|
+
const a20 = a[6];
|
|
1293
|
+
const a21 = a[7];
|
|
1294
|
+
const a22 = a[8];
|
|
1295
|
+
const x = v[0];
|
|
1296
|
+
const y = v[1];
|
|
1297
|
+
out[0] = a00;
|
|
1298
|
+
out[1] = a01;
|
|
1299
|
+
out[2] = a02;
|
|
1300
|
+
out[3] = a10;
|
|
1301
|
+
out[4] = a11;
|
|
1302
|
+
out[5] = a12;
|
|
1303
|
+
out[6] = x * a00 + y * a10 + a20;
|
|
1304
|
+
out[7] = x * a01 + y * a11 + a21;
|
|
1305
|
+
out[8] = x * a02 + y * a12 + a22;
|
|
1306
|
+
return out;
|
|
1307
|
+
}
|
|
1308
|
+
function rotate(out, a, rad) {
|
|
1309
|
+
const a00 = a[0];
|
|
1310
|
+
const a01 = a[1];
|
|
1311
|
+
const a02 = a[2];
|
|
1312
|
+
const a10 = a[3];
|
|
1313
|
+
const a11 = a[4];
|
|
1314
|
+
const a12 = a[5];
|
|
1315
|
+
const a20 = a[6];
|
|
1316
|
+
const a21 = a[7];
|
|
1317
|
+
const a22 = a[8];
|
|
1318
|
+
const s = Math.sin(rad);
|
|
1319
|
+
const c = Math.cos(rad);
|
|
1320
|
+
out[0] = c * a00 + s * a10;
|
|
1321
|
+
out[1] = c * a01 + s * a11;
|
|
1322
|
+
out[2] = c * a02 + s * a12;
|
|
1323
|
+
out[3] = c * a10 - s * a00;
|
|
1324
|
+
out[4] = c * a11 - s * a01;
|
|
1325
|
+
out[5] = c * a12 - s * a02;
|
|
1326
|
+
out[6] = a20;
|
|
1327
|
+
out[7] = a21;
|
|
1328
|
+
out[8] = a22;
|
|
1329
|
+
return out;
|
|
1330
|
+
}
|
|
1331
|
+
function scale(out, a, v) {
|
|
1332
|
+
const x = v[0];
|
|
1333
|
+
const y = v[1];
|
|
1334
|
+
out[0] = x * a[0];
|
|
1335
|
+
out[1] = x * a[1];
|
|
1336
|
+
out[2] = x * a[2];
|
|
1337
|
+
out[3] = y * a[3];
|
|
1338
|
+
out[4] = y * a[4];
|
|
1339
|
+
out[5] = y * a[5];
|
|
1340
|
+
out[6] = a[6];
|
|
1341
|
+
out[7] = a[7];
|
|
1342
|
+
out[8] = a[8];
|
|
1343
|
+
return out;
|
|
1344
|
+
}
|
|
1345
|
+
function fromQuat(out, q) {
|
|
1346
|
+
const x = q[0];
|
|
1347
|
+
const y = q[1];
|
|
1348
|
+
const z = q[2];
|
|
1349
|
+
const w = q[3];
|
|
1350
|
+
const x2 = x + x;
|
|
1351
|
+
const y2 = y + y;
|
|
1352
|
+
const z2 = z + z;
|
|
1353
|
+
const xx = x * x2;
|
|
1354
|
+
const yx = y * x2;
|
|
1355
|
+
const yy = y * y2;
|
|
1356
|
+
const zx = z * x2;
|
|
1357
|
+
const zy = z * y2;
|
|
1358
|
+
const zz = z * z2;
|
|
1359
|
+
const wx = w * x2;
|
|
1360
|
+
const wy = w * y2;
|
|
1361
|
+
const wz = w * z2;
|
|
1362
|
+
out[0] = 1 - yy - zz;
|
|
1363
|
+
out[3] = yx - wz;
|
|
1364
|
+
out[6] = zx + wy;
|
|
1365
|
+
out[1] = yx + wz;
|
|
1366
|
+
out[4] = 1 - xx - zz;
|
|
1367
|
+
out[7] = zy - wx;
|
|
1368
|
+
out[2] = zx - wy;
|
|
1369
|
+
out[5] = zy + wx;
|
|
1370
|
+
out[8] = 1 - xx - yy;
|
|
1371
|
+
return out;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// src/classes/matrix3.ts
|
|
1375
|
+
var INDICES = /* @__PURE__ */ ((INDICES3) => {
|
|
1376
|
+
INDICES3[INDICES3["COL0ROW0"] = 0] = "COL0ROW0";
|
|
1377
|
+
INDICES3[INDICES3["COL0ROW1"] = 1] = "COL0ROW1";
|
|
1378
|
+
INDICES3[INDICES3["COL0ROW2"] = 2] = "COL0ROW2";
|
|
1379
|
+
INDICES3[INDICES3["COL1ROW0"] = 3] = "COL1ROW0";
|
|
1380
|
+
INDICES3[INDICES3["COL1ROW1"] = 4] = "COL1ROW1";
|
|
1381
|
+
INDICES3[INDICES3["COL1ROW2"] = 5] = "COL1ROW2";
|
|
1382
|
+
INDICES3[INDICES3["COL2ROW0"] = 6] = "COL2ROW0";
|
|
1383
|
+
INDICES3[INDICES3["COL2ROW1"] = 7] = "COL2ROW1";
|
|
1384
|
+
INDICES3[INDICES3["COL2ROW2"] = 8] = "COL2ROW2";
|
|
1385
|
+
return INDICES3;
|
|
1386
|
+
})(INDICES || {});
|
|
1387
|
+
var IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
1388
|
+
var Matrix3 = class extends Matrix {
|
|
1389
|
+
static get IDENTITY() {
|
|
1390
|
+
return getIdentityMatrix();
|
|
1391
|
+
}
|
|
1392
|
+
static get ZERO() {
|
|
1393
|
+
return getZeroMatrix();
|
|
1394
|
+
}
|
|
1395
|
+
get ELEMENTS() {
|
|
1396
|
+
return 9;
|
|
1397
|
+
}
|
|
1398
|
+
get RANK() {
|
|
1399
|
+
return 3;
|
|
1400
|
+
}
|
|
1401
|
+
get INDICES() {
|
|
1402
|
+
return INDICES;
|
|
1403
|
+
}
|
|
1404
|
+
constructor(array, ...args) {
|
|
1405
|
+
super(-0, -0, -0, -0, -0, -0, -0, -0, -0);
|
|
1406
|
+
if (arguments.length === 1 && Array.isArray(array)) {
|
|
1407
|
+
this.copy(array);
|
|
1408
|
+
} else if (args.length > 0) {
|
|
1409
|
+
this.copy([array, ...args]);
|
|
1410
|
+
} else {
|
|
1411
|
+
this.identity();
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
copy(array) {
|
|
1415
|
+
this[0] = array[0];
|
|
1416
|
+
this[1] = array[1];
|
|
1417
|
+
this[2] = array[2];
|
|
1418
|
+
this[3] = array[3];
|
|
1419
|
+
this[4] = array[4];
|
|
1420
|
+
this[5] = array[5];
|
|
1421
|
+
this[6] = array[6];
|
|
1422
|
+
this[7] = array[7];
|
|
1423
|
+
this[8] = array[8];
|
|
1424
|
+
return this.check();
|
|
1425
|
+
}
|
|
1426
|
+
identity() {
|
|
1427
|
+
return this.copy(IDENTITY_MATRIX);
|
|
1428
|
+
}
|
|
1429
|
+
fromObject(object) {
|
|
1430
|
+
return this.check();
|
|
1431
|
+
}
|
|
1432
|
+
fromQuaternion(q) {
|
|
1433
|
+
fromQuat(this, q);
|
|
1434
|
+
return this.check();
|
|
1435
|
+
}
|
|
1436
|
+
set(m00, m10, m20, m01, m11, m21, m02, m12, m22) {
|
|
1437
|
+
this[0] = m00;
|
|
1438
|
+
this[1] = m10;
|
|
1439
|
+
this[2] = m20;
|
|
1440
|
+
this[3] = m01;
|
|
1441
|
+
this[4] = m11;
|
|
1442
|
+
this[5] = m21;
|
|
1443
|
+
this[6] = m02;
|
|
1444
|
+
this[7] = m12;
|
|
1445
|
+
this[8] = m22;
|
|
1446
|
+
return this.check();
|
|
1447
|
+
}
|
|
1448
|
+
setRowMajor(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
|
|
1449
|
+
this[0] = m00;
|
|
1450
|
+
this[1] = m10;
|
|
1451
|
+
this[2] = m20;
|
|
1452
|
+
this[3] = m01;
|
|
1453
|
+
this[4] = m11;
|
|
1454
|
+
this[5] = m21;
|
|
1455
|
+
this[6] = m02;
|
|
1456
|
+
this[7] = m12;
|
|
1457
|
+
this[8] = m22;
|
|
1458
|
+
return this.check();
|
|
1459
|
+
}
|
|
1460
|
+
determinant() {
|
|
1461
|
+
return determinant(this);
|
|
1462
|
+
}
|
|
1463
|
+
transpose() {
|
|
1464
|
+
transpose(this, this);
|
|
1465
|
+
return this.check();
|
|
1466
|
+
}
|
|
1467
|
+
invert() {
|
|
1468
|
+
invert(this, this);
|
|
1469
|
+
return this.check();
|
|
1470
|
+
}
|
|
1471
|
+
multiplyLeft(a) {
|
|
1472
|
+
multiply(this, a, this);
|
|
1473
|
+
return this.check();
|
|
1474
|
+
}
|
|
1475
|
+
multiplyRight(a) {
|
|
1476
|
+
multiply(this, this, a);
|
|
1477
|
+
return this.check();
|
|
1478
|
+
}
|
|
1479
|
+
rotate(radians2) {
|
|
1480
|
+
rotate(this, this, radians2);
|
|
1481
|
+
return this.check();
|
|
1482
|
+
}
|
|
1483
|
+
scale(factor) {
|
|
1484
|
+
if (Array.isArray(factor)) {
|
|
1485
|
+
scale(this, this, factor);
|
|
1486
|
+
} else {
|
|
1487
|
+
scale(this, this, [factor, factor]);
|
|
1488
|
+
}
|
|
1489
|
+
return this.check();
|
|
1490
|
+
}
|
|
1491
|
+
translate(vec) {
|
|
1492
|
+
translate(this, this, vec);
|
|
1493
|
+
return this.check();
|
|
1494
|
+
}
|
|
1495
|
+
transform(vector, result) {
|
|
1496
|
+
let out;
|
|
1497
|
+
switch (vector.length) {
|
|
1498
|
+
case 2:
|
|
1499
|
+
out = transformMat3(result || [-0, -0], vector, this);
|
|
1500
|
+
break;
|
|
1501
|
+
case 3:
|
|
1502
|
+
out = transformMat32(result || [-0, -0, -0], vector, this);
|
|
1503
|
+
break;
|
|
1504
|
+
case 4:
|
|
1505
|
+
out = vec4_transformMat3(result || [-0, -0, -0, -0], vector, this);
|
|
1506
|
+
break;
|
|
1507
|
+
default:
|
|
1508
|
+
throw new Error("Illegal vector");
|
|
1509
|
+
}
|
|
1510
|
+
checkVector(out, vector.length);
|
|
1511
|
+
return out;
|
|
1512
|
+
}
|
|
1513
|
+
transformVector(vector, result) {
|
|
1514
|
+
return this.transform(vector, result);
|
|
1515
|
+
}
|
|
1516
|
+
transformVector2(vector, result) {
|
|
1517
|
+
return this.transform(vector, result);
|
|
1518
|
+
}
|
|
1519
|
+
transformVector3(vector, result) {
|
|
1520
|
+
return this.transform(vector, result);
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
var ZERO_MATRIX3;
|
|
1524
|
+
var IDENTITY_MATRIX3 = null;
|
|
1525
|
+
function getZeroMatrix() {
|
|
1526
|
+
if (!ZERO_MATRIX3) {
|
|
1527
|
+
ZERO_MATRIX3 = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
1528
|
+
Object.freeze(ZERO_MATRIX3);
|
|
1529
|
+
}
|
|
1530
|
+
return ZERO_MATRIX3;
|
|
1531
|
+
}
|
|
1532
|
+
function getIdentityMatrix() {
|
|
1533
|
+
if (!IDENTITY_MATRIX3) {
|
|
1534
|
+
IDENTITY_MATRIX3 = new Matrix3();
|
|
1535
|
+
Object.freeze(IDENTITY_MATRIX3);
|
|
1536
|
+
}
|
|
1537
|
+
return IDENTITY_MATRIX3;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
// src/gl-matrix/mat4.js
|
|
1541
|
+
function identity(out) {
|
|
1542
|
+
out[0] = 1;
|
|
1543
|
+
out[1] = 0;
|
|
1544
|
+
out[2] = 0;
|
|
1545
|
+
out[3] = 0;
|
|
1546
|
+
out[4] = 0;
|
|
1547
|
+
out[5] = 1;
|
|
1548
|
+
out[6] = 0;
|
|
1549
|
+
out[7] = 0;
|
|
1550
|
+
out[8] = 0;
|
|
1551
|
+
out[9] = 0;
|
|
1552
|
+
out[10] = 1;
|
|
1553
|
+
out[11] = 0;
|
|
1554
|
+
out[12] = 0;
|
|
1555
|
+
out[13] = 0;
|
|
1556
|
+
out[14] = 0;
|
|
1557
|
+
out[15] = 1;
|
|
1558
|
+
return out;
|
|
1559
|
+
}
|
|
1560
|
+
function transpose2(out, a) {
|
|
1561
|
+
if (out === a) {
|
|
1562
|
+
const a01 = a[1];
|
|
1563
|
+
const a02 = a[2];
|
|
1564
|
+
const a03 = a[3];
|
|
1565
|
+
const a12 = a[6];
|
|
1566
|
+
const a13 = a[7];
|
|
1567
|
+
const a23 = a[11];
|
|
1568
|
+
out[1] = a[4];
|
|
1569
|
+
out[2] = a[8];
|
|
1570
|
+
out[3] = a[12];
|
|
1571
|
+
out[4] = a01;
|
|
1572
|
+
out[6] = a[9];
|
|
1573
|
+
out[7] = a[13];
|
|
1574
|
+
out[8] = a02;
|
|
1575
|
+
out[9] = a12;
|
|
1576
|
+
out[11] = a[14];
|
|
1577
|
+
out[12] = a03;
|
|
1578
|
+
out[13] = a13;
|
|
1579
|
+
out[14] = a23;
|
|
1580
|
+
} else {
|
|
1581
|
+
out[0] = a[0];
|
|
1582
|
+
out[1] = a[4];
|
|
1583
|
+
out[2] = a[8];
|
|
1584
|
+
out[3] = a[12];
|
|
1585
|
+
out[4] = a[1];
|
|
1586
|
+
out[5] = a[5];
|
|
1587
|
+
out[6] = a[9];
|
|
1588
|
+
out[7] = a[13];
|
|
1589
|
+
out[8] = a[2];
|
|
1590
|
+
out[9] = a[6];
|
|
1591
|
+
out[10] = a[10];
|
|
1592
|
+
out[11] = a[14];
|
|
1593
|
+
out[12] = a[3];
|
|
1594
|
+
out[13] = a[7];
|
|
1595
|
+
out[14] = a[11];
|
|
1596
|
+
out[15] = a[15];
|
|
1597
|
+
}
|
|
1598
|
+
return out;
|
|
1599
|
+
}
|
|
1600
|
+
function invert2(out, a) {
|
|
1601
|
+
const a00 = a[0];
|
|
1602
|
+
const a01 = a[1];
|
|
1603
|
+
const a02 = a[2];
|
|
1604
|
+
const a03 = a[3];
|
|
1605
|
+
const a10 = a[4];
|
|
1606
|
+
const a11 = a[5];
|
|
1607
|
+
const a12 = a[6];
|
|
1608
|
+
const a13 = a[7];
|
|
1609
|
+
const a20 = a[8];
|
|
1610
|
+
const a21 = a[9];
|
|
1611
|
+
const a22 = a[10];
|
|
1612
|
+
const a23 = a[11];
|
|
1613
|
+
const a30 = a[12];
|
|
1614
|
+
const a31 = a[13];
|
|
1615
|
+
const a32 = a[14];
|
|
1616
|
+
const a33 = a[15];
|
|
1617
|
+
const b00 = a00 * a11 - a01 * a10;
|
|
1618
|
+
const b01 = a00 * a12 - a02 * a10;
|
|
1619
|
+
const b02 = a00 * a13 - a03 * a10;
|
|
1620
|
+
const b03 = a01 * a12 - a02 * a11;
|
|
1621
|
+
const b04 = a01 * a13 - a03 * a11;
|
|
1622
|
+
const b05 = a02 * a13 - a03 * a12;
|
|
1623
|
+
const b06 = a20 * a31 - a21 * a30;
|
|
1624
|
+
const b07 = a20 * a32 - a22 * a30;
|
|
1625
|
+
const b08 = a20 * a33 - a23 * a30;
|
|
1626
|
+
const b09 = a21 * a32 - a22 * a31;
|
|
1627
|
+
const b10 = a21 * a33 - a23 * a31;
|
|
1628
|
+
const b11 = a22 * a33 - a23 * a32;
|
|
1629
|
+
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
1630
|
+
if (!det) {
|
|
1631
|
+
return null;
|
|
1632
|
+
}
|
|
1633
|
+
det = 1 / det;
|
|
1634
|
+
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
|
1635
|
+
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
|
1636
|
+
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
|
1637
|
+
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
|
1638
|
+
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
|
1639
|
+
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
|
1640
|
+
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
1641
|
+
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
|
1642
|
+
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
|
1643
|
+
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
|
1644
|
+
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
1645
|
+
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
|
1646
|
+
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
|
1647
|
+
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
|
1648
|
+
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
|
1649
|
+
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
|
1650
|
+
return out;
|
|
1651
|
+
}
|
|
1652
|
+
function determinant2(a) {
|
|
1653
|
+
const a00 = a[0];
|
|
1654
|
+
const a01 = a[1];
|
|
1655
|
+
const a02 = a[2];
|
|
1656
|
+
const a03 = a[3];
|
|
1657
|
+
const a10 = a[4];
|
|
1658
|
+
const a11 = a[5];
|
|
1659
|
+
const a12 = a[6];
|
|
1660
|
+
const a13 = a[7];
|
|
1661
|
+
const a20 = a[8];
|
|
1662
|
+
const a21 = a[9];
|
|
1663
|
+
const a22 = a[10];
|
|
1664
|
+
const a23 = a[11];
|
|
1665
|
+
const a30 = a[12];
|
|
1666
|
+
const a31 = a[13];
|
|
1667
|
+
const a32 = a[14];
|
|
1668
|
+
const a33 = a[15];
|
|
1669
|
+
const b0 = a00 * a11 - a01 * a10;
|
|
1670
|
+
const b1 = a00 * a12 - a02 * a10;
|
|
1671
|
+
const b2 = a01 * a12 - a02 * a11;
|
|
1672
|
+
const b3 = a20 * a31 - a21 * a30;
|
|
1673
|
+
const b4 = a20 * a32 - a22 * a30;
|
|
1674
|
+
const b5 = a21 * a32 - a22 * a31;
|
|
1675
|
+
const b6 = a00 * b5 - a01 * b4 + a02 * b3;
|
|
1676
|
+
const b7 = a10 * b5 - a11 * b4 + a12 * b3;
|
|
1677
|
+
const b8 = a20 * b2 - a21 * b1 + a22 * b0;
|
|
1678
|
+
const b9 = a30 * b2 - a31 * b1 + a32 * b0;
|
|
1679
|
+
return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
|
|
1680
|
+
}
|
|
1681
|
+
function multiply2(out, a, b) {
|
|
1682
|
+
const a00 = a[0];
|
|
1683
|
+
const a01 = a[1];
|
|
1684
|
+
const a02 = a[2];
|
|
1685
|
+
const a03 = a[3];
|
|
1686
|
+
const a10 = a[4];
|
|
1687
|
+
const a11 = a[5];
|
|
1688
|
+
const a12 = a[6];
|
|
1689
|
+
const a13 = a[7];
|
|
1690
|
+
const a20 = a[8];
|
|
1691
|
+
const a21 = a[9];
|
|
1692
|
+
const a22 = a[10];
|
|
1693
|
+
const a23 = a[11];
|
|
1694
|
+
const a30 = a[12];
|
|
1695
|
+
const a31 = a[13];
|
|
1696
|
+
const a32 = a[14];
|
|
1697
|
+
const a33 = a[15];
|
|
1698
|
+
let b0 = b[0];
|
|
1699
|
+
let b1 = b[1];
|
|
1700
|
+
let b2 = b[2];
|
|
1701
|
+
let b3 = b[3];
|
|
1702
|
+
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
1703
|
+
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
1704
|
+
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
1705
|
+
out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
1706
|
+
b0 = b[4];
|
|
1707
|
+
b1 = b[5];
|
|
1708
|
+
b2 = b[6];
|
|
1709
|
+
b3 = b[7];
|
|
1710
|
+
out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
1711
|
+
out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
1712
|
+
out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
1713
|
+
out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
1714
|
+
b0 = b[8];
|
|
1715
|
+
b1 = b[9];
|
|
1716
|
+
b2 = b[10];
|
|
1717
|
+
b3 = b[11];
|
|
1718
|
+
out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
1719
|
+
out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
1720
|
+
out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
1721
|
+
out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
1722
|
+
b0 = b[12];
|
|
1723
|
+
b1 = b[13];
|
|
1724
|
+
b2 = b[14];
|
|
1725
|
+
b3 = b[15];
|
|
1726
|
+
out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
1727
|
+
out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
1728
|
+
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
1729
|
+
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
1730
|
+
return out;
|
|
1731
|
+
}
|
|
1732
|
+
function translate2(out, a, v) {
|
|
1733
|
+
const x = v[0];
|
|
1734
|
+
const y = v[1];
|
|
1735
|
+
const z = v[2];
|
|
1736
|
+
let a00;
|
|
1737
|
+
let a01;
|
|
1738
|
+
let a02;
|
|
1739
|
+
let a03;
|
|
1740
|
+
let a10;
|
|
1741
|
+
let a11;
|
|
1742
|
+
let a12;
|
|
1743
|
+
let a13;
|
|
1744
|
+
let a20;
|
|
1745
|
+
let a21;
|
|
1746
|
+
let a22;
|
|
1747
|
+
let a23;
|
|
1748
|
+
if (a === out) {
|
|
1749
|
+
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
|
1750
|
+
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
|
1751
|
+
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
|
1752
|
+
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
|
1753
|
+
} else {
|
|
1754
|
+
a00 = a[0];
|
|
1755
|
+
a01 = a[1];
|
|
1756
|
+
a02 = a[2];
|
|
1757
|
+
a03 = a[3];
|
|
1758
|
+
a10 = a[4];
|
|
1759
|
+
a11 = a[5];
|
|
1760
|
+
a12 = a[6];
|
|
1761
|
+
a13 = a[7];
|
|
1762
|
+
a20 = a[8];
|
|
1763
|
+
a21 = a[9];
|
|
1764
|
+
a22 = a[10];
|
|
1765
|
+
a23 = a[11];
|
|
1766
|
+
out[0] = a00;
|
|
1767
|
+
out[1] = a01;
|
|
1768
|
+
out[2] = a02;
|
|
1769
|
+
out[3] = a03;
|
|
1770
|
+
out[4] = a10;
|
|
1771
|
+
out[5] = a11;
|
|
1772
|
+
out[6] = a12;
|
|
1773
|
+
out[7] = a13;
|
|
1774
|
+
out[8] = a20;
|
|
1775
|
+
out[9] = a21;
|
|
1776
|
+
out[10] = a22;
|
|
1777
|
+
out[11] = a23;
|
|
1778
|
+
out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
|
1779
|
+
out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
|
1780
|
+
out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
|
1781
|
+
out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
|
1782
|
+
}
|
|
1783
|
+
return out;
|
|
1784
|
+
}
|
|
1785
|
+
function scale2(out, a, v) {
|
|
1786
|
+
const x = v[0];
|
|
1787
|
+
const y = v[1];
|
|
1788
|
+
const z = v[2];
|
|
1789
|
+
out[0] = a[0] * x;
|
|
1790
|
+
out[1] = a[1] * x;
|
|
1791
|
+
out[2] = a[2] * x;
|
|
1792
|
+
out[3] = a[3] * x;
|
|
1793
|
+
out[4] = a[4] * y;
|
|
1794
|
+
out[5] = a[5] * y;
|
|
1795
|
+
out[6] = a[6] * y;
|
|
1796
|
+
out[7] = a[7] * y;
|
|
1797
|
+
out[8] = a[8] * z;
|
|
1798
|
+
out[9] = a[9] * z;
|
|
1799
|
+
out[10] = a[10] * z;
|
|
1800
|
+
out[11] = a[11] * z;
|
|
1801
|
+
out[12] = a[12];
|
|
1802
|
+
out[13] = a[13];
|
|
1803
|
+
out[14] = a[14];
|
|
1804
|
+
out[15] = a[15];
|
|
1805
|
+
return out;
|
|
1806
|
+
}
|
|
1807
|
+
function rotate2(out, a, rad, axis) {
|
|
1808
|
+
let x = axis[0];
|
|
1809
|
+
let y = axis[1];
|
|
1810
|
+
let z = axis[2];
|
|
1811
|
+
let len2 = Math.sqrt(x * x + y * y + z * z);
|
|
1812
|
+
let c;
|
|
1813
|
+
let s;
|
|
1814
|
+
let t;
|
|
1815
|
+
let a00;
|
|
1816
|
+
let a01;
|
|
1817
|
+
let a02;
|
|
1818
|
+
let a03;
|
|
1819
|
+
let a10;
|
|
1820
|
+
let a11;
|
|
1821
|
+
let a12;
|
|
1822
|
+
let a13;
|
|
1823
|
+
let a20;
|
|
1824
|
+
let a21;
|
|
1825
|
+
let a22;
|
|
1826
|
+
let a23;
|
|
1827
|
+
let b00;
|
|
1828
|
+
let b01;
|
|
1829
|
+
let b02;
|
|
1830
|
+
let b10;
|
|
1831
|
+
let b11;
|
|
1832
|
+
let b12;
|
|
1833
|
+
let b20;
|
|
1834
|
+
let b21;
|
|
1835
|
+
let b22;
|
|
1836
|
+
if (len2 < EPSILON) {
|
|
1837
|
+
return null;
|
|
1838
|
+
}
|
|
1839
|
+
len2 = 1 / len2;
|
|
1840
|
+
x *= len2;
|
|
1841
|
+
y *= len2;
|
|
1842
|
+
z *= len2;
|
|
1843
|
+
s = Math.sin(rad);
|
|
1844
|
+
c = Math.cos(rad);
|
|
1845
|
+
t = 1 - c;
|
|
1846
|
+
a00 = a[0];
|
|
1847
|
+
a01 = a[1];
|
|
1848
|
+
a02 = a[2];
|
|
1849
|
+
a03 = a[3];
|
|
1850
|
+
a10 = a[4];
|
|
1851
|
+
a11 = a[5];
|
|
1852
|
+
a12 = a[6];
|
|
1853
|
+
a13 = a[7];
|
|
1854
|
+
a20 = a[8];
|
|
1855
|
+
a21 = a[9];
|
|
1856
|
+
a22 = a[10];
|
|
1857
|
+
a23 = a[11];
|
|
1858
|
+
b00 = x * x * t + c;
|
|
1859
|
+
b01 = y * x * t + z * s;
|
|
1860
|
+
b02 = z * x * t - y * s;
|
|
1861
|
+
b10 = x * y * t - z * s;
|
|
1862
|
+
b11 = y * y * t + c;
|
|
1863
|
+
b12 = z * y * t + x * s;
|
|
1864
|
+
b20 = x * z * t + y * s;
|
|
1865
|
+
b21 = y * z * t - x * s;
|
|
1866
|
+
b22 = z * z * t + c;
|
|
1867
|
+
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
1868
|
+
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
1869
|
+
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
1870
|
+
out[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
|
1871
|
+
out[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
|
1872
|
+
out[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
|
1873
|
+
out[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
|
1874
|
+
out[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
|
1875
|
+
out[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
|
1876
|
+
out[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
|
1877
|
+
out[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
|
1878
|
+
out[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
|
1879
|
+
if (a !== out) {
|
|
1880
|
+
out[12] = a[12];
|
|
1881
|
+
out[13] = a[13];
|
|
1882
|
+
out[14] = a[14];
|
|
1883
|
+
out[15] = a[15];
|
|
1884
|
+
}
|
|
1885
|
+
return out;
|
|
1886
|
+
}
|
|
1887
|
+
function rotateX2(out, a, rad) {
|
|
1888
|
+
const s = Math.sin(rad);
|
|
1889
|
+
const c = Math.cos(rad);
|
|
1890
|
+
const a10 = a[4];
|
|
1891
|
+
const a11 = a[5];
|
|
1892
|
+
const a12 = a[6];
|
|
1893
|
+
const a13 = a[7];
|
|
1894
|
+
const a20 = a[8];
|
|
1895
|
+
const a21 = a[9];
|
|
1896
|
+
const a22 = a[10];
|
|
1897
|
+
const a23 = a[11];
|
|
1898
|
+
if (a !== out) {
|
|
1899
|
+
out[0] = a[0];
|
|
1900
|
+
out[1] = a[1];
|
|
1901
|
+
out[2] = a[2];
|
|
1902
|
+
out[3] = a[3];
|
|
1903
|
+
out[12] = a[12];
|
|
1904
|
+
out[13] = a[13];
|
|
1905
|
+
out[14] = a[14];
|
|
1906
|
+
out[15] = a[15];
|
|
1907
|
+
}
|
|
1908
|
+
out[4] = a10 * c + a20 * s;
|
|
1909
|
+
out[5] = a11 * c + a21 * s;
|
|
1910
|
+
out[6] = a12 * c + a22 * s;
|
|
1911
|
+
out[7] = a13 * c + a23 * s;
|
|
1912
|
+
out[8] = a20 * c - a10 * s;
|
|
1913
|
+
out[9] = a21 * c - a11 * s;
|
|
1914
|
+
out[10] = a22 * c - a12 * s;
|
|
1915
|
+
out[11] = a23 * c - a13 * s;
|
|
1916
|
+
return out;
|
|
1917
|
+
}
|
|
1918
|
+
function rotateY2(out, a, rad) {
|
|
1919
|
+
const s = Math.sin(rad);
|
|
1920
|
+
const c = Math.cos(rad);
|
|
1921
|
+
const a00 = a[0];
|
|
1922
|
+
const a01 = a[1];
|
|
1923
|
+
const a02 = a[2];
|
|
1924
|
+
const a03 = a[3];
|
|
1925
|
+
const a20 = a[8];
|
|
1926
|
+
const a21 = a[9];
|
|
1927
|
+
const a22 = a[10];
|
|
1928
|
+
const a23 = a[11];
|
|
1929
|
+
if (a !== out) {
|
|
1930
|
+
out[4] = a[4];
|
|
1931
|
+
out[5] = a[5];
|
|
1932
|
+
out[6] = a[6];
|
|
1933
|
+
out[7] = a[7];
|
|
1934
|
+
out[12] = a[12];
|
|
1935
|
+
out[13] = a[13];
|
|
1936
|
+
out[14] = a[14];
|
|
1937
|
+
out[15] = a[15];
|
|
1938
|
+
}
|
|
1939
|
+
out[0] = a00 * c - a20 * s;
|
|
1940
|
+
out[1] = a01 * c - a21 * s;
|
|
1941
|
+
out[2] = a02 * c - a22 * s;
|
|
1942
|
+
out[3] = a03 * c - a23 * s;
|
|
1943
|
+
out[8] = a00 * s + a20 * c;
|
|
1944
|
+
out[9] = a01 * s + a21 * c;
|
|
1945
|
+
out[10] = a02 * s + a22 * c;
|
|
1946
|
+
out[11] = a03 * s + a23 * c;
|
|
1947
|
+
return out;
|
|
1948
|
+
}
|
|
1949
|
+
function rotateZ2(out, a, rad) {
|
|
1950
|
+
const s = Math.sin(rad);
|
|
1951
|
+
const c = Math.cos(rad);
|
|
1952
|
+
const a00 = a[0];
|
|
1953
|
+
const a01 = a[1];
|
|
1954
|
+
const a02 = a[2];
|
|
1955
|
+
const a03 = a[3];
|
|
1956
|
+
const a10 = a[4];
|
|
1957
|
+
const a11 = a[5];
|
|
1958
|
+
const a12 = a[6];
|
|
1959
|
+
const a13 = a[7];
|
|
1960
|
+
if (a !== out) {
|
|
1961
|
+
out[8] = a[8];
|
|
1962
|
+
out[9] = a[9];
|
|
1963
|
+
out[10] = a[10];
|
|
1964
|
+
out[11] = a[11];
|
|
1965
|
+
out[12] = a[12];
|
|
1966
|
+
out[13] = a[13];
|
|
1967
|
+
out[14] = a[14];
|
|
1968
|
+
out[15] = a[15];
|
|
1969
|
+
}
|
|
1970
|
+
out[0] = a00 * c + a10 * s;
|
|
1971
|
+
out[1] = a01 * c + a11 * s;
|
|
1972
|
+
out[2] = a02 * c + a12 * s;
|
|
1973
|
+
out[3] = a03 * c + a13 * s;
|
|
1974
|
+
out[4] = a10 * c - a00 * s;
|
|
1975
|
+
out[5] = a11 * c - a01 * s;
|
|
1976
|
+
out[6] = a12 * c - a02 * s;
|
|
1977
|
+
out[7] = a13 * c - a03 * s;
|
|
1978
|
+
return out;
|
|
1979
|
+
}
|
|
1980
|
+
function fromQuat2(out, q) {
|
|
1981
|
+
const x = q[0];
|
|
1982
|
+
const y = q[1];
|
|
1983
|
+
const z = q[2];
|
|
1984
|
+
const w = q[3];
|
|
1985
|
+
const x2 = x + x;
|
|
1986
|
+
const y2 = y + y;
|
|
1987
|
+
const z2 = z + z;
|
|
1988
|
+
const xx = x * x2;
|
|
1989
|
+
const yx = y * x2;
|
|
1990
|
+
const yy = y * y2;
|
|
1991
|
+
const zx = z * x2;
|
|
1992
|
+
const zy = z * y2;
|
|
1993
|
+
const zz = z * z2;
|
|
1994
|
+
const wx = w * x2;
|
|
1995
|
+
const wy = w * y2;
|
|
1996
|
+
const wz = w * z2;
|
|
1997
|
+
out[0] = 1 - yy - zz;
|
|
1998
|
+
out[1] = yx + wz;
|
|
1999
|
+
out[2] = zx - wy;
|
|
2000
|
+
out[3] = 0;
|
|
2001
|
+
out[4] = yx - wz;
|
|
2002
|
+
out[5] = 1 - xx - zz;
|
|
2003
|
+
out[6] = zy + wx;
|
|
2004
|
+
out[7] = 0;
|
|
2005
|
+
out[8] = zx + wy;
|
|
2006
|
+
out[9] = zy - wx;
|
|
2007
|
+
out[10] = 1 - xx - yy;
|
|
2008
|
+
out[11] = 0;
|
|
2009
|
+
out[12] = 0;
|
|
2010
|
+
out[13] = 0;
|
|
2011
|
+
out[14] = 0;
|
|
2012
|
+
out[15] = 1;
|
|
2013
|
+
return out;
|
|
2014
|
+
}
|
|
2015
|
+
function frustum(out, left, right, bottom, top, near, far) {
|
|
2016
|
+
const rl = 1 / (right - left);
|
|
2017
|
+
const tb = 1 / (top - bottom);
|
|
2018
|
+
const nf = 1 / (near - far);
|
|
2019
|
+
out[0] = near * 2 * rl;
|
|
2020
|
+
out[1] = 0;
|
|
2021
|
+
out[2] = 0;
|
|
2022
|
+
out[3] = 0;
|
|
2023
|
+
out[4] = 0;
|
|
2024
|
+
out[5] = near * 2 * tb;
|
|
2025
|
+
out[6] = 0;
|
|
2026
|
+
out[7] = 0;
|
|
2027
|
+
out[8] = (right + left) * rl;
|
|
2028
|
+
out[9] = (top + bottom) * tb;
|
|
2029
|
+
out[10] = (far + near) * nf;
|
|
2030
|
+
out[11] = -1;
|
|
2031
|
+
out[12] = 0;
|
|
2032
|
+
out[13] = 0;
|
|
2033
|
+
out[14] = far * near * 2 * nf;
|
|
2034
|
+
out[15] = 0;
|
|
2035
|
+
return out;
|
|
2036
|
+
}
|
|
2037
|
+
function perspectiveNO(out, fovy, aspect, near, far) {
|
|
2038
|
+
const f = 1 / Math.tan(fovy / 2);
|
|
2039
|
+
out[0] = f / aspect;
|
|
2040
|
+
out[1] = 0;
|
|
2041
|
+
out[2] = 0;
|
|
2042
|
+
out[3] = 0;
|
|
2043
|
+
out[4] = 0;
|
|
2044
|
+
out[5] = f;
|
|
2045
|
+
out[6] = 0;
|
|
2046
|
+
out[7] = 0;
|
|
2047
|
+
out[8] = 0;
|
|
2048
|
+
out[9] = 0;
|
|
2049
|
+
out[11] = -1;
|
|
2050
|
+
out[12] = 0;
|
|
2051
|
+
out[13] = 0;
|
|
2052
|
+
out[15] = 0;
|
|
2053
|
+
if (far != null && far !== Infinity) {
|
|
2054
|
+
const nf = 1 / (near - far);
|
|
2055
|
+
out[10] = (far + near) * nf;
|
|
2056
|
+
out[14] = 2 * far * near * nf;
|
|
2057
|
+
} else {
|
|
2058
|
+
out[10] = -1;
|
|
2059
|
+
out[14] = -2 * near;
|
|
2060
|
+
}
|
|
2061
|
+
return out;
|
|
2062
|
+
}
|
|
2063
|
+
var perspective = perspectiveNO;
|
|
2064
|
+
function orthoNO(out, left, right, bottom, top, near, far) {
|
|
2065
|
+
const lr = 1 / (left - right);
|
|
2066
|
+
const bt = 1 / (bottom - top);
|
|
2067
|
+
const nf = 1 / (near - far);
|
|
2068
|
+
out[0] = -2 * lr;
|
|
2069
|
+
out[1] = 0;
|
|
2070
|
+
out[2] = 0;
|
|
2071
|
+
out[3] = 0;
|
|
2072
|
+
out[4] = 0;
|
|
2073
|
+
out[5] = -2 * bt;
|
|
2074
|
+
out[6] = 0;
|
|
2075
|
+
out[7] = 0;
|
|
2076
|
+
out[8] = 0;
|
|
2077
|
+
out[9] = 0;
|
|
2078
|
+
out[10] = 2 * nf;
|
|
2079
|
+
out[11] = 0;
|
|
2080
|
+
out[12] = (left + right) * lr;
|
|
2081
|
+
out[13] = (top + bottom) * bt;
|
|
2082
|
+
out[14] = (far + near) * nf;
|
|
2083
|
+
out[15] = 1;
|
|
2084
|
+
return out;
|
|
2085
|
+
}
|
|
2086
|
+
var ortho = orthoNO;
|
|
2087
|
+
function lookAt(out, eye, center, up) {
|
|
2088
|
+
let len2;
|
|
2089
|
+
let x0;
|
|
2090
|
+
let x1;
|
|
2091
|
+
let x2;
|
|
2092
|
+
let y0;
|
|
2093
|
+
let y1;
|
|
2094
|
+
let y2;
|
|
2095
|
+
let z0;
|
|
2096
|
+
let z1;
|
|
2097
|
+
let z2;
|
|
2098
|
+
const eyex = eye[0];
|
|
2099
|
+
const eyey = eye[1];
|
|
2100
|
+
const eyez = eye[2];
|
|
2101
|
+
const upx = up[0];
|
|
2102
|
+
const upy = up[1];
|
|
2103
|
+
const upz = up[2];
|
|
2104
|
+
const centerx = center[0];
|
|
2105
|
+
const centery = center[1];
|
|
2106
|
+
const centerz = center[2];
|
|
2107
|
+
if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {
|
|
2108
|
+
return identity(out);
|
|
2109
|
+
}
|
|
2110
|
+
z0 = eyex - centerx;
|
|
2111
|
+
z1 = eyey - centery;
|
|
2112
|
+
z2 = eyez - centerz;
|
|
2113
|
+
len2 = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
|
|
2114
|
+
z0 *= len2;
|
|
2115
|
+
z1 *= len2;
|
|
2116
|
+
z2 *= len2;
|
|
2117
|
+
x0 = upy * z2 - upz * z1;
|
|
2118
|
+
x1 = upz * z0 - upx * z2;
|
|
2119
|
+
x2 = upx * z1 - upy * z0;
|
|
2120
|
+
len2 = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
|
|
2121
|
+
if (!len2) {
|
|
2122
|
+
x0 = 0;
|
|
2123
|
+
x1 = 0;
|
|
2124
|
+
x2 = 0;
|
|
2125
|
+
} else {
|
|
2126
|
+
len2 = 1 / len2;
|
|
2127
|
+
x0 *= len2;
|
|
2128
|
+
x1 *= len2;
|
|
2129
|
+
x2 *= len2;
|
|
2130
|
+
}
|
|
2131
|
+
y0 = z1 * x2 - z2 * x1;
|
|
2132
|
+
y1 = z2 * x0 - z0 * x2;
|
|
2133
|
+
y2 = z0 * x1 - z1 * x0;
|
|
2134
|
+
len2 = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
|
|
2135
|
+
if (!len2) {
|
|
2136
|
+
y0 = 0;
|
|
2137
|
+
y1 = 0;
|
|
2138
|
+
y2 = 0;
|
|
2139
|
+
} else {
|
|
2140
|
+
len2 = 1 / len2;
|
|
2141
|
+
y0 *= len2;
|
|
2142
|
+
y1 *= len2;
|
|
2143
|
+
y2 *= len2;
|
|
2144
|
+
}
|
|
2145
|
+
out[0] = x0;
|
|
2146
|
+
out[1] = y0;
|
|
2147
|
+
out[2] = z0;
|
|
2148
|
+
out[3] = 0;
|
|
2149
|
+
out[4] = x1;
|
|
2150
|
+
out[5] = y1;
|
|
2151
|
+
out[6] = z1;
|
|
2152
|
+
out[7] = 0;
|
|
2153
|
+
out[8] = x2;
|
|
2154
|
+
out[9] = y2;
|
|
2155
|
+
out[10] = z2;
|
|
2156
|
+
out[11] = 0;
|
|
2157
|
+
out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
|
|
2158
|
+
out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
|
|
2159
|
+
out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
|
|
2160
|
+
out[15] = 1;
|
|
2161
|
+
return out;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
// src/classes/matrix4.ts
|
|
2165
|
+
var INDICES2 = /* @__PURE__ */ ((INDICES3) => {
|
|
2166
|
+
INDICES3[INDICES3["COL0ROW0"] = 0] = "COL0ROW0";
|
|
2167
|
+
INDICES3[INDICES3["COL0ROW1"] = 1] = "COL0ROW1";
|
|
2168
|
+
INDICES3[INDICES3["COL0ROW2"] = 2] = "COL0ROW2";
|
|
2169
|
+
INDICES3[INDICES3["COL0ROW3"] = 3] = "COL0ROW3";
|
|
2170
|
+
INDICES3[INDICES3["COL1ROW0"] = 4] = "COL1ROW0";
|
|
2171
|
+
INDICES3[INDICES3["COL1ROW1"] = 5] = "COL1ROW1";
|
|
2172
|
+
INDICES3[INDICES3["COL1ROW2"] = 6] = "COL1ROW2";
|
|
2173
|
+
INDICES3[INDICES3["COL1ROW3"] = 7] = "COL1ROW3";
|
|
2174
|
+
INDICES3[INDICES3["COL2ROW0"] = 8] = "COL2ROW0";
|
|
2175
|
+
INDICES3[INDICES3["COL2ROW1"] = 9] = "COL2ROW1";
|
|
2176
|
+
INDICES3[INDICES3["COL2ROW2"] = 10] = "COL2ROW2";
|
|
2177
|
+
INDICES3[INDICES3["COL2ROW3"] = 11] = "COL2ROW3";
|
|
2178
|
+
INDICES3[INDICES3["COL3ROW0"] = 12] = "COL3ROW0";
|
|
2179
|
+
INDICES3[INDICES3["COL3ROW1"] = 13] = "COL3ROW1";
|
|
2180
|
+
INDICES3[INDICES3["COL3ROW2"] = 14] = "COL3ROW2";
|
|
2181
|
+
INDICES3[INDICES3["COL3ROW3"] = 15] = "COL3ROW3";
|
|
2182
|
+
return INDICES3;
|
|
2183
|
+
})(INDICES2 || {});
|
|
2184
|
+
var DEFAULT_FOVY = 45 * Math.PI / 180;
|
|
2185
|
+
var DEFAULT_ASPECT = 1;
|
|
2186
|
+
var DEFAULT_NEAR = 0.1;
|
|
2187
|
+
var DEFAULT_FAR = 500;
|
|
2188
|
+
var IDENTITY_MATRIX2 = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
2189
|
+
var Matrix4 = class extends Matrix {
|
|
2190
|
+
static get IDENTITY() {
|
|
2191
|
+
return getIdentityMatrix2();
|
|
2192
|
+
}
|
|
2193
|
+
static get ZERO() {
|
|
2194
|
+
return getZeroMatrix2();
|
|
2195
|
+
}
|
|
2196
|
+
get ELEMENTS() {
|
|
2197
|
+
return 16;
|
|
2198
|
+
}
|
|
2199
|
+
get RANK() {
|
|
2200
|
+
return 4;
|
|
2201
|
+
}
|
|
2202
|
+
get INDICES() {
|
|
2203
|
+
return INDICES2;
|
|
2204
|
+
}
|
|
2205
|
+
constructor(array) {
|
|
2206
|
+
super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
|
|
2207
|
+
if (arguments.length === 1 && Array.isArray(array)) {
|
|
2208
|
+
this.copy(array);
|
|
2209
|
+
} else {
|
|
2210
|
+
this.identity();
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
copy(array) {
|
|
2214
|
+
this[0] = array[0];
|
|
2215
|
+
this[1] = array[1];
|
|
2216
|
+
this[2] = array[2];
|
|
2217
|
+
this[3] = array[3];
|
|
2218
|
+
this[4] = array[4];
|
|
2219
|
+
this[5] = array[5];
|
|
2220
|
+
this[6] = array[6];
|
|
2221
|
+
this[7] = array[7];
|
|
2222
|
+
this[8] = array[8];
|
|
2223
|
+
this[9] = array[9];
|
|
2224
|
+
this[10] = array[10];
|
|
2225
|
+
this[11] = array[11];
|
|
2226
|
+
this[12] = array[12];
|
|
2227
|
+
this[13] = array[13];
|
|
2228
|
+
this[14] = array[14];
|
|
2229
|
+
this[15] = array[15];
|
|
2230
|
+
return this.check();
|
|
2231
|
+
}
|
|
2232
|
+
set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
|
|
2233
|
+
this[0] = m00;
|
|
2234
|
+
this[1] = m10;
|
|
2235
|
+
this[2] = m20;
|
|
2236
|
+
this[3] = m30;
|
|
2237
|
+
this[4] = m01;
|
|
2238
|
+
this[5] = m11;
|
|
2239
|
+
this[6] = m21;
|
|
2240
|
+
this[7] = m31;
|
|
2241
|
+
this[8] = m02;
|
|
2242
|
+
this[9] = m12;
|
|
2243
|
+
this[10] = m22;
|
|
2244
|
+
this[11] = m32;
|
|
2245
|
+
this[12] = m03;
|
|
2246
|
+
this[13] = m13;
|
|
2247
|
+
this[14] = m23;
|
|
2248
|
+
this[15] = m33;
|
|
2249
|
+
return this.check();
|
|
2250
|
+
}
|
|
2251
|
+
setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
2252
|
+
this[0] = m00;
|
|
2253
|
+
this[1] = m10;
|
|
2254
|
+
this[2] = m20;
|
|
2255
|
+
this[3] = m30;
|
|
2256
|
+
this[4] = m01;
|
|
2257
|
+
this[5] = m11;
|
|
2258
|
+
this[6] = m21;
|
|
2259
|
+
this[7] = m31;
|
|
2260
|
+
this[8] = m02;
|
|
2261
|
+
this[9] = m12;
|
|
2262
|
+
this[10] = m22;
|
|
2263
|
+
this[11] = m32;
|
|
2264
|
+
this[12] = m03;
|
|
2265
|
+
this[13] = m13;
|
|
2266
|
+
this[14] = m23;
|
|
2267
|
+
this[15] = m33;
|
|
2268
|
+
return this.check();
|
|
2269
|
+
}
|
|
2270
|
+
toRowMajor(result) {
|
|
2271
|
+
result[0] = this[0];
|
|
2272
|
+
result[1] = this[4];
|
|
2273
|
+
result[2] = this[8];
|
|
2274
|
+
result[3] = this[12];
|
|
2275
|
+
result[4] = this[1];
|
|
2276
|
+
result[5] = this[5];
|
|
2277
|
+
result[6] = this[9];
|
|
2278
|
+
result[7] = this[13];
|
|
2279
|
+
result[8] = this[2];
|
|
2280
|
+
result[9] = this[6];
|
|
2281
|
+
result[10] = this[10];
|
|
2282
|
+
result[11] = this[14];
|
|
2283
|
+
result[12] = this[3];
|
|
2284
|
+
result[13] = this[7];
|
|
2285
|
+
result[14] = this[11];
|
|
2286
|
+
result[15] = this[15];
|
|
2287
|
+
return result;
|
|
2288
|
+
}
|
|
2289
|
+
identity() {
|
|
2290
|
+
return this.copy(IDENTITY_MATRIX2);
|
|
2291
|
+
}
|
|
2292
|
+
fromObject(object) {
|
|
2293
|
+
return this.check();
|
|
2294
|
+
}
|
|
2295
|
+
fromQuaternion(quaternion) {
|
|
2296
|
+
fromQuat2(this, quaternion);
|
|
2297
|
+
return this.check();
|
|
2298
|
+
}
|
|
2299
|
+
frustum(view) {
|
|
2300
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
2301
|
+
if (far === Infinity) {
|
|
2302
|
+
computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
|
|
2303
|
+
} else {
|
|
2304
|
+
frustum(this, left, right, bottom, top, near, far);
|
|
2305
|
+
}
|
|
2306
|
+
return this.check();
|
|
2307
|
+
}
|
|
2308
|
+
lookAt(view) {
|
|
2309
|
+
const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
|
|
2310
|
+
lookAt(this, eye, center, up);
|
|
2311
|
+
return this.check();
|
|
2312
|
+
}
|
|
2313
|
+
ortho(view) {
|
|
2314
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
2315
|
+
ortho(this, left, right, bottom, top, near, far);
|
|
2316
|
+
return this.check();
|
|
2317
|
+
}
|
|
2318
|
+
orthographic(view) {
|
|
2319
|
+
const {
|
|
2320
|
+
fovy = DEFAULT_FOVY,
|
|
2321
|
+
aspect = DEFAULT_ASPECT,
|
|
2322
|
+
focalDistance = 1,
|
|
2323
|
+
near = DEFAULT_NEAR,
|
|
2324
|
+
far = DEFAULT_FAR
|
|
2325
|
+
} = view;
|
|
2326
|
+
checkRadians(fovy);
|
|
2327
|
+
const halfY = fovy / 2;
|
|
2328
|
+
const top = focalDistance * Math.tan(halfY);
|
|
2329
|
+
const right = top * aspect;
|
|
2330
|
+
return this.ortho({
|
|
2331
|
+
left: -right,
|
|
2332
|
+
right,
|
|
2333
|
+
bottom: -top,
|
|
2334
|
+
top,
|
|
2335
|
+
near,
|
|
2336
|
+
far
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
perspective(view) {
|
|
2340
|
+
const { fovy = 45 * Math.PI / 180, aspect = 1, near = 0.1, far = 500 } = view;
|
|
2341
|
+
checkRadians(fovy);
|
|
2342
|
+
perspective(this, fovy, aspect, near, far);
|
|
2343
|
+
return this.check();
|
|
2344
|
+
}
|
|
2345
|
+
determinant() {
|
|
2346
|
+
return determinant2(this);
|
|
2347
|
+
}
|
|
2348
|
+
getScale(result = [-0, -0, -0]) {
|
|
2349
|
+
result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
|
|
2350
|
+
result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
|
|
2351
|
+
result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
|
|
2352
|
+
return result;
|
|
2353
|
+
}
|
|
2354
|
+
getTranslation(result = [-0, -0, -0]) {
|
|
2355
|
+
result[0] = this[12];
|
|
2356
|
+
result[1] = this[13];
|
|
2357
|
+
result[2] = this[14];
|
|
2358
|
+
return result;
|
|
2359
|
+
}
|
|
2360
|
+
getRotation(result, scaleResult) {
|
|
2361
|
+
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
2362
|
+
scaleResult = scaleResult || [-0, -0, -0];
|
|
2363
|
+
const scale5 = this.getScale(scaleResult);
|
|
2364
|
+
const inverseScale0 = 1 / scale5[0];
|
|
2365
|
+
const inverseScale1 = 1 / scale5[1];
|
|
2366
|
+
const inverseScale2 = 1 / scale5[2];
|
|
2367
|
+
result[0] = this[0] * inverseScale0;
|
|
2368
|
+
result[1] = this[1] * inverseScale1;
|
|
2369
|
+
result[2] = this[2] * inverseScale2;
|
|
2370
|
+
result[3] = 0;
|
|
2371
|
+
result[4] = this[4] * inverseScale0;
|
|
2372
|
+
result[5] = this[5] * inverseScale1;
|
|
2373
|
+
result[6] = this[6] * inverseScale2;
|
|
2374
|
+
result[7] = 0;
|
|
2375
|
+
result[8] = this[8] * inverseScale0;
|
|
2376
|
+
result[9] = this[9] * inverseScale1;
|
|
2377
|
+
result[10] = this[10] * inverseScale2;
|
|
2378
|
+
result[11] = 0;
|
|
2379
|
+
result[12] = 0;
|
|
2380
|
+
result[13] = 0;
|
|
2381
|
+
result[14] = 0;
|
|
2382
|
+
result[15] = 1;
|
|
2383
|
+
return result;
|
|
2384
|
+
}
|
|
2385
|
+
getRotationMatrix3(result, scaleResult) {
|
|
2386
|
+
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
2387
|
+
scaleResult = scaleResult || [-0, -0, -0];
|
|
2388
|
+
const scale5 = this.getScale(scaleResult);
|
|
2389
|
+
const inverseScale0 = 1 / scale5[0];
|
|
2390
|
+
const inverseScale1 = 1 / scale5[1];
|
|
2391
|
+
const inverseScale2 = 1 / scale5[2];
|
|
2392
|
+
result[0] = this[0] * inverseScale0;
|
|
2393
|
+
result[1] = this[1] * inverseScale1;
|
|
2394
|
+
result[2] = this[2] * inverseScale2;
|
|
2395
|
+
result[3] = this[4] * inverseScale0;
|
|
2396
|
+
result[4] = this[5] * inverseScale1;
|
|
2397
|
+
result[5] = this[6] * inverseScale2;
|
|
2398
|
+
result[6] = this[8] * inverseScale0;
|
|
2399
|
+
result[7] = this[9] * inverseScale1;
|
|
2400
|
+
result[8] = this[10] * inverseScale2;
|
|
2401
|
+
return result;
|
|
2402
|
+
}
|
|
2403
|
+
transpose() {
|
|
2404
|
+
transpose2(this, this);
|
|
2405
|
+
return this.check();
|
|
2406
|
+
}
|
|
2407
|
+
invert() {
|
|
2408
|
+
invert2(this, this);
|
|
2409
|
+
return this.check();
|
|
2410
|
+
}
|
|
2411
|
+
multiplyLeft(a) {
|
|
2412
|
+
multiply2(this, a, this);
|
|
2413
|
+
return this.check();
|
|
2414
|
+
}
|
|
2415
|
+
multiplyRight(a) {
|
|
2416
|
+
multiply2(this, this, a);
|
|
2417
|
+
return this.check();
|
|
2418
|
+
}
|
|
2419
|
+
rotateX(radians2) {
|
|
2420
|
+
rotateX2(this, this, radians2);
|
|
2421
|
+
return this.check();
|
|
2422
|
+
}
|
|
2423
|
+
rotateY(radians2) {
|
|
2424
|
+
rotateY2(this, this, radians2);
|
|
2425
|
+
return this.check();
|
|
2426
|
+
}
|
|
2427
|
+
rotateZ(radians2) {
|
|
2428
|
+
rotateZ2(this, this, radians2);
|
|
2429
|
+
return this.check();
|
|
2430
|
+
}
|
|
2431
|
+
rotateXYZ(angleXYZ) {
|
|
2432
|
+
return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
|
|
2433
|
+
}
|
|
2434
|
+
rotateAxis(radians2, axis) {
|
|
2435
|
+
rotate2(this, this, radians2, axis);
|
|
2436
|
+
return this.check();
|
|
2437
|
+
}
|
|
2438
|
+
scale(factor) {
|
|
2439
|
+
scale2(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
|
|
2440
|
+
return this.check();
|
|
2441
|
+
}
|
|
2442
|
+
translate(vector) {
|
|
2443
|
+
translate2(this, this, vector);
|
|
2444
|
+
return this.check();
|
|
2445
|
+
}
|
|
2446
|
+
transform(vector, result) {
|
|
2447
|
+
if (vector.length === 4) {
|
|
2448
|
+
result = transformMat42(result || [-0, -0, -0, -0], vector, this);
|
|
2449
|
+
checkVector(result, 4);
|
|
2450
|
+
return result;
|
|
2451
|
+
}
|
|
2452
|
+
return this.transformAsPoint(vector, result);
|
|
2453
|
+
}
|
|
2454
|
+
transformAsPoint(vector, result) {
|
|
2455
|
+
const { length: length4 } = vector;
|
|
2456
|
+
let out;
|
|
2457
|
+
switch (length4) {
|
|
2458
|
+
case 2:
|
|
2459
|
+
out = transformMat4(result || [-0, -0], vector, this);
|
|
2460
|
+
break;
|
|
2461
|
+
case 3:
|
|
2462
|
+
out = transformMat42(result || [-0, -0, -0], vector, this);
|
|
2463
|
+
break;
|
|
2464
|
+
default:
|
|
2465
|
+
throw new Error("Illegal vector");
|
|
2466
|
+
}
|
|
2467
|
+
checkVector(out, vector.length);
|
|
2468
|
+
return out;
|
|
2469
|
+
}
|
|
2470
|
+
transformAsVector(vector, result) {
|
|
2471
|
+
let out;
|
|
2472
|
+
switch (vector.length) {
|
|
2473
|
+
case 2:
|
|
2474
|
+
out = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
|
|
2475
|
+
break;
|
|
2476
|
+
case 3:
|
|
2477
|
+
out = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
|
|
2478
|
+
break;
|
|
2479
|
+
default:
|
|
2480
|
+
throw new Error("Illegal vector");
|
|
2481
|
+
}
|
|
2482
|
+
checkVector(out, vector.length);
|
|
2483
|
+
return out;
|
|
2484
|
+
}
|
|
2485
|
+
transformPoint(vector, result) {
|
|
2486
|
+
return this.transformAsPoint(vector, result);
|
|
2487
|
+
}
|
|
2488
|
+
transformVector(vector, result) {
|
|
2489
|
+
return this.transformAsPoint(vector, result);
|
|
2490
|
+
}
|
|
2491
|
+
transformDirection(vector, result) {
|
|
2492
|
+
return this.transformAsVector(vector, result);
|
|
2493
|
+
}
|
|
2494
|
+
makeRotationX(radians2) {
|
|
2495
|
+
return this.identity().rotateX(radians2);
|
|
2496
|
+
}
|
|
2497
|
+
makeTranslation(x, y, z) {
|
|
2498
|
+
return this.identity().translate([x, y, z]);
|
|
2499
|
+
}
|
|
2500
|
+
};
|
|
2501
|
+
var ZERO3;
|
|
2502
|
+
var IDENTITY;
|
|
2503
|
+
function getZeroMatrix2() {
|
|
2504
|
+
if (!ZERO3) {
|
|
2505
|
+
ZERO3 = new Matrix4([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
2506
|
+
Object.freeze(ZERO3);
|
|
2507
|
+
}
|
|
2508
|
+
return ZERO3;
|
|
2509
|
+
}
|
|
2510
|
+
function getIdentityMatrix2() {
|
|
2511
|
+
if (!IDENTITY) {
|
|
2512
|
+
IDENTITY = new Matrix4();
|
|
2513
|
+
Object.freeze(IDENTITY);
|
|
2514
|
+
}
|
|
2515
|
+
return IDENTITY;
|
|
2516
|
+
}
|
|
2517
|
+
function checkRadians(possiblyDegrees) {
|
|
2518
|
+
if (possiblyDegrees > Math.PI * 2) {
|
|
2519
|
+
throw Error("expected radians");
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
function computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
|
|
2523
|
+
const column0Row0 = 2 * near / (right - left);
|
|
2524
|
+
const column1Row1 = 2 * near / (top - bottom);
|
|
2525
|
+
const column2Row0 = (right + left) / (right - left);
|
|
2526
|
+
const column2Row1 = (top + bottom) / (top - bottom);
|
|
2527
|
+
const column2Row2 = -1;
|
|
2528
|
+
const column2Row3 = -1;
|
|
2529
|
+
const column3Row2 = -2 * near;
|
|
2530
|
+
result[0] = column0Row0;
|
|
2531
|
+
result[1] = 0;
|
|
2532
|
+
result[2] = 0;
|
|
2533
|
+
result[3] = 0;
|
|
2534
|
+
result[4] = 0;
|
|
2535
|
+
result[5] = column1Row1;
|
|
2536
|
+
result[6] = 0;
|
|
2537
|
+
result[7] = 0;
|
|
2538
|
+
result[8] = column2Row0;
|
|
2539
|
+
result[9] = column2Row1;
|
|
2540
|
+
result[10] = column2Row2;
|
|
2541
|
+
result[11] = column2Row3;
|
|
2542
|
+
result[12] = 0;
|
|
2543
|
+
result[13] = 0;
|
|
2544
|
+
result[14] = column3Row2;
|
|
2545
|
+
result[15] = 0;
|
|
2546
|
+
return result;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
// src/gl-matrix/vec4.js
|
|
2550
|
+
function create4() {
|
|
2551
|
+
const out = new ARRAY_TYPE(4);
|
|
2552
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
2553
|
+
out[0] = 0;
|
|
2554
|
+
out[1] = 0;
|
|
2555
|
+
out[2] = 0;
|
|
2556
|
+
out[3] = 0;
|
|
2557
|
+
}
|
|
2558
|
+
return out;
|
|
2559
|
+
}
|
|
2560
|
+
function add(out, a, b) {
|
|
2561
|
+
out[0] = a[0] + b[0];
|
|
2562
|
+
out[1] = a[1] + b[1];
|
|
2563
|
+
out[2] = a[2] + b[2];
|
|
2564
|
+
out[3] = a[3] + b[3];
|
|
2565
|
+
return out;
|
|
2566
|
+
}
|
|
2567
|
+
function scale3(out, a, b) {
|
|
2568
|
+
out[0] = a[0] * b;
|
|
2569
|
+
out[1] = a[1] * b;
|
|
2570
|
+
out[2] = a[2] * b;
|
|
2571
|
+
out[3] = a[3] * b;
|
|
2572
|
+
return out;
|
|
2573
|
+
}
|
|
2574
|
+
function length2(a) {
|
|
2575
|
+
const x = a[0];
|
|
2576
|
+
const y = a[1];
|
|
2577
|
+
const z = a[2];
|
|
2578
|
+
const w = a[3];
|
|
2579
|
+
return Math.sqrt(x * x + y * y + z * z + w * w);
|
|
2580
|
+
}
|
|
2581
|
+
function squaredLength(a) {
|
|
2582
|
+
const x = a[0];
|
|
2583
|
+
const y = a[1];
|
|
2584
|
+
const z = a[2];
|
|
2585
|
+
const w = a[3];
|
|
2586
|
+
return x * x + y * y + z * z + w * w;
|
|
2587
|
+
}
|
|
2588
|
+
function normalize2(out, a) {
|
|
2589
|
+
const x = a[0];
|
|
2590
|
+
const y = a[1];
|
|
2591
|
+
const z = a[2];
|
|
2592
|
+
const w = a[3];
|
|
2593
|
+
let len2 = x * x + y * y + z * z + w * w;
|
|
2594
|
+
if (len2 > 0) {
|
|
2595
|
+
len2 = 1 / Math.sqrt(len2);
|
|
2596
|
+
}
|
|
2597
|
+
out[0] = x * len2;
|
|
2598
|
+
out[1] = y * len2;
|
|
2599
|
+
out[2] = z * len2;
|
|
2600
|
+
out[3] = w * len2;
|
|
2601
|
+
return out;
|
|
2602
|
+
}
|
|
2603
|
+
function dot2(a, b) {
|
|
2604
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
2605
|
+
}
|
|
2606
|
+
function lerp2(out, a, b, t) {
|
|
2607
|
+
const ax = a[0];
|
|
2608
|
+
const ay = a[1];
|
|
2609
|
+
const az = a[2];
|
|
2610
|
+
const aw = a[3];
|
|
2611
|
+
out[0] = ax + t * (b[0] - ax);
|
|
2612
|
+
out[1] = ay + t * (b[1] - ay);
|
|
2613
|
+
out[2] = az + t * (b[2] - az);
|
|
2614
|
+
out[3] = aw + t * (b[3] - aw);
|
|
2615
|
+
return out;
|
|
2616
|
+
}
|
|
2617
|
+
function transformQuat2(out, a, q) {
|
|
2618
|
+
const x = a[0];
|
|
2619
|
+
const y = a[1];
|
|
2620
|
+
const z = a[2];
|
|
2621
|
+
const qx = q[0];
|
|
2622
|
+
const qy = q[1];
|
|
2623
|
+
const qz = q[2];
|
|
2624
|
+
const qw = q[3];
|
|
2625
|
+
const ix = qw * x + qy * z - qz * y;
|
|
2626
|
+
const iy = qw * y + qz * x - qx * z;
|
|
2627
|
+
const iz = qw * z + qx * y - qy * x;
|
|
2628
|
+
const iw = -qx * x - qy * y - qz * z;
|
|
2629
|
+
out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
2630
|
+
out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
2631
|
+
out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
2632
|
+
out[3] = a[3];
|
|
2633
|
+
return out;
|
|
2634
|
+
}
|
|
2635
|
+
var forEach3 = function() {
|
|
2636
|
+
const vec = create4();
|
|
2637
|
+
return function(a, stride, offset, count, fn, arg) {
|
|
2638
|
+
let i;
|
|
2639
|
+
let l;
|
|
2640
|
+
if (!stride) {
|
|
2641
|
+
stride = 4;
|
|
2642
|
+
}
|
|
2643
|
+
if (!offset) {
|
|
2644
|
+
offset = 0;
|
|
2645
|
+
}
|
|
2646
|
+
if (count) {
|
|
2647
|
+
l = Math.min(count * stride + offset, a.length);
|
|
2648
|
+
} else {
|
|
2649
|
+
l = a.length;
|
|
2650
|
+
}
|
|
2651
|
+
for (i = offset; i < l; i += stride) {
|
|
2652
|
+
vec[0] = a[i];
|
|
2653
|
+
vec[1] = a[i + 1];
|
|
2654
|
+
vec[2] = a[i + 2];
|
|
2655
|
+
vec[3] = a[i + 3];
|
|
2656
|
+
fn(vec, vec, arg);
|
|
2657
|
+
a[i] = vec[0];
|
|
2658
|
+
a[i + 1] = vec[1];
|
|
2659
|
+
a[i + 2] = vec[2];
|
|
2660
|
+
a[i + 3] = vec[3];
|
|
2661
|
+
}
|
|
2662
|
+
return a;
|
|
2663
|
+
};
|
|
2664
|
+
}();
|
|
2665
|
+
|
|
2666
|
+
// src/gl-matrix/quat.ts
|
|
2667
|
+
function create5() {
|
|
2668
|
+
const out = new ARRAY_TYPE(4);
|
|
2669
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
2670
|
+
out[0] = 0;
|
|
2671
|
+
out[1] = 0;
|
|
2672
|
+
out[2] = 0;
|
|
2673
|
+
}
|
|
2674
|
+
out[3] = 1;
|
|
2675
|
+
return out;
|
|
2676
|
+
}
|
|
2677
|
+
function identity2(out) {
|
|
2678
|
+
out[0] = 0;
|
|
2679
|
+
out[1] = 0;
|
|
2680
|
+
out[2] = 0;
|
|
2681
|
+
out[3] = 1;
|
|
2682
|
+
return out;
|
|
2683
|
+
}
|
|
2684
|
+
function setAxisAngle(out, axis, rad) {
|
|
2685
|
+
rad = rad * 0.5;
|
|
2686
|
+
const s = Math.sin(rad);
|
|
2687
|
+
out[0] = s * axis[0];
|
|
2688
|
+
out[1] = s * axis[1];
|
|
2689
|
+
out[2] = s * axis[2];
|
|
2690
|
+
out[3] = Math.cos(rad);
|
|
2691
|
+
return out;
|
|
2692
|
+
}
|
|
2693
|
+
function multiply3(out, a, b) {
|
|
2694
|
+
const ax = a[0];
|
|
2695
|
+
const ay = a[1];
|
|
2696
|
+
const az = a[2];
|
|
2697
|
+
const aw = a[3];
|
|
2698
|
+
const bx = b[0];
|
|
2699
|
+
const by = b[1];
|
|
2700
|
+
const bz = b[2];
|
|
2701
|
+
const bw = b[3];
|
|
2702
|
+
out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
|
2703
|
+
out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
|
2704
|
+
out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
|
2705
|
+
out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
|
2706
|
+
return out;
|
|
2707
|
+
}
|
|
2708
|
+
function rotateX3(out, a, rad) {
|
|
2709
|
+
rad *= 0.5;
|
|
2710
|
+
const ax = a[0];
|
|
2711
|
+
const ay = a[1];
|
|
2712
|
+
const az = a[2];
|
|
2713
|
+
const aw = a[3];
|
|
2714
|
+
const bx = Math.sin(rad);
|
|
2715
|
+
const bw = Math.cos(rad);
|
|
2716
|
+
out[0] = ax * bw + aw * bx;
|
|
2717
|
+
out[1] = ay * bw + az * bx;
|
|
2718
|
+
out[2] = az * bw - ay * bx;
|
|
2719
|
+
out[3] = aw * bw - ax * bx;
|
|
2720
|
+
return out;
|
|
2721
|
+
}
|
|
2722
|
+
function rotateY3(out, a, rad) {
|
|
2723
|
+
rad *= 0.5;
|
|
2724
|
+
const ax = a[0];
|
|
2725
|
+
const ay = a[1];
|
|
2726
|
+
const az = a[2];
|
|
2727
|
+
const aw = a[3];
|
|
2728
|
+
const by = Math.sin(rad);
|
|
2729
|
+
const bw = Math.cos(rad);
|
|
2730
|
+
out[0] = ax * bw - az * by;
|
|
2731
|
+
out[1] = ay * bw + aw * by;
|
|
2732
|
+
out[2] = az * bw + ax * by;
|
|
2733
|
+
out[3] = aw * bw - ay * by;
|
|
2734
|
+
return out;
|
|
2735
|
+
}
|
|
2736
|
+
function rotateZ3(out, a, rad) {
|
|
2737
|
+
rad *= 0.5;
|
|
2738
|
+
const ax = a[0];
|
|
2739
|
+
const ay = a[1];
|
|
2740
|
+
const az = a[2];
|
|
2741
|
+
const aw = a[3];
|
|
2742
|
+
const bz = Math.sin(rad);
|
|
2743
|
+
const bw = Math.cos(rad);
|
|
2744
|
+
out[0] = ax * bw + ay * bz;
|
|
2745
|
+
out[1] = ay * bw - ax * bz;
|
|
2746
|
+
out[2] = az * bw + aw * bz;
|
|
2747
|
+
out[3] = aw * bw - az * bz;
|
|
2748
|
+
return out;
|
|
2749
|
+
}
|
|
2750
|
+
function calculateW(out, a) {
|
|
2751
|
+
const x = a[0];
|
|
2752
|
+
const y = a[1];
|
|
2753
|
+
const z = a[2];
|
|
2754
|
+
out[0] = x;
|
|
2755
|
+
out[1] = y;
|
|
2756
|
+
out[2] = z;
|
|
2757
|
+
out[3] = Math.sqrt(Math.abs(1 - x * x - y * y - z * z));
|
|
2758
|
+
return out;
|
|
2759
|
+
}
|
|
2760
|
+
function slerp(out, a, b, t) {
|
|
2761
|
+
const ax = a[0];
|
|
2762
|
+
const ay = a[1];
|
|
2763
|
+
const az = a[2];
|
|
2764
|
+
const aw = a[3];
|
|
2765
|
+
let bx = b[0];
|
|
2766
|
+
let by = b[1];
|
|
2767
|
+
let bz = b[2];
|
|
2768
|
+
let bw = b[3];
|
|
2769
|
+
let cosom;
|
|
2770
|
+
let omega;
|
|
2771
|
+
let scale0;
|
|
2772
|
+
let scale1;
|
|
2773
|
+
let sinom;
|
|
2774
|
+
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
2775
|
+
if (cosom < 0) {
|
|
2776
|
+
cosom = -cosom;
|
|
2777
|
+
bx = -bx;
|
|
2778
|
+
by = -by;
|
|
2779
|
+
bz = -bz;
|
|
2780
|
+
bw = -bw;
|
|
2781
|
+
}
|
|
2782
|
+
if (1 - cosom > EPSILON) {
|
|
2783
|
+
omega = Math.acos(cosom);
|
|
2784
|
+
sinom = Math.sin(omega);
|
|
2785
|
+
scale0 = Math.sin((1 - t) * omega) / sinom;
|
|
2786
|
+
scale1 = Math.sin(t * omega) / sinom;
|
|
2787
|
+
} else {
|
|
2788
|
+
scale0 = 1 - t;
|
|
2789
|
+
scale1 = t;
|
|
2790
|
+
}
|
|
2791
|
+
out[0] = scale0 * ax + scale1 * bx;
|
|
2792
|
+
out[1] = scale0 * ay + scale1 * by;
|
|
2793
|
+
out[2] = scale0 * az + scale1 * bz;
|
|
2794
|
+
out[3] = scale0 * aw + scale1 * bw;
|
|
2795
|
+
return out;
|
|
2796
|
+
}
|
|
2797
|
+
function invert3(out, a) {
|
|
2798
|
+
const a0 = a[0];
|
|
2799
|
+
const a1 = a[1];
|
|
2800
|
+
const a2 = a[2];
|
|
2801
|
+
const a3 = a[3];
|
|
2802
|
+
const dot4 = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
|
|
2803
|
+
const invDot = dot4 ? 1 / dot4 : 0;
|
|
2804
|
+
out[0] = -a0 * invDot;
|
|
2805
|
+
out[1] = -a1 * invDot;
|
|
2806
|
+
out[2] = -a2 * invDot;
|
|
2807
|
+
out[3] = a3 * invDot;
|
|
2808
|
+
return out;
|
|
2809
|
+
}
|
|
2810
|
+
function conjugate(out, a) {
|
|
2811
|
+
out[0] = -a[0];
|
|
2812
|
+
out[1] = -a[1];
|
|
2813
|
+
out[2] = -a[2];
|
|
2814
|
+
out[3] = a[3];
|
|
2815
|
+
return out;
|
|
2816
|
+
}
|
|
2817
|
+
function fromMat3(out, m) {
|
|
2818
|
+
const fTrace = m[0] + m[4] + m[8];
|
|
2819
|
+
let fRoot;
|
|
2820
|
+
if (fTrace > 0) {
|
|
2821
|
+
fRoot = Math.sqrt(fTrace + 1);
|
|
2822
|
+
out[3] = 0.5 * fRoot;
|
|
2823
|
+
fRoot = 0.5 / fRoot;
|
|
2824
|
+
out[0] = (m[5] - m[7]) * fRoot;
|
|
2825
|
+
out[1] = (m[6] - m[2]) * fRoot;
|
|
2826
|
+
out[2] = (m[1] - m[3]) * fRoot;
|
|
2827
|
+
} else {
|
|
2828
|
+
let i = 0;
|
|
2829
|
+
if (m[4] > m[0])
|
|
2830
|
+
i = 1;
|
|
2831
|
+
if (m[8] > m[i * 3 + i])
|
|
2832
|
+
i = 2;
|
|
2833
|
+
const j = (i + 1) % 3;
|
|
2834
|
+
const k = (i + 2) % 3;
|
|
2835
|
+
fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1);
|
|
2836
|
+
out[i] = 0.5 * fRoot;
|
|
2837
|
+
fRoot = 0.5 / fRoot;
|
|
2838
|
+
out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
|
|
2839
|
+
out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
|
|
2840
|
+
out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
|
|
2841
|
+
}
|
|
2842
|
+
return out;
|
|
2843
|
+
}
|
|
2844
|
+
var add2 = add;
|
|
2845
|
+
var scale4 = scale3;
|
|
2846
|
+
var dot3 = dot2;
|
|
2847
|
+
var lerp3 = lerp2;
|
|
2848
|
+
var length3 = length2;
|
|
2849
|
+
var squaredLength2 = squaredLength;
|
|
2850
|
+
var normalize3 = normalize2;
|
|
2851
|
+
var rotationTo = function() {
|
|
2852
|
+
const tmpvec3 = create2();
|
|
2853
|
+
const xUnitVec3 = fromValues(1, 0, 0);
|
|
2854
|
+
const yUnitVec3 = fromValues(0, 1, 0);
|
|
2855
|
+
return function(out, a, b) {
|
|
2856
|
+
const dot4 = dot(a, b);
|
|
2857
|
+
if (dot4 < -0.999999) {
|
|
2858
|
+
cross(tmpvec3, xUnitVec3, a);
|
|
2859
|
+
if (len(tmpvec3) < 1e-6)
|
|
2860
|
+
cross(tmpvec3, yUnitVec3, a);
|
|
2861
|
+
normalize(tmpvec3, tmpvec3);
|
|
2862
|
+
setAxisAngle(out, tmpvec3, Math.PI);
|
|
2863
|
+
return out;
|
|
2864
|
+
} else if (dot4 > 0.999999) {
|
|
2865
|
+
out[0] = 0;
|
|
2866
|
+
out[1] = 0;
|
|
2867
|
+
out[2] = 0;
|
|
2868
|
+
out[3] = 1;
|
|
2869
|
+
return out;
|
|
2870
|
+
}
|
|
2871
|
+
cross(tmpvec3, a, b);
|
|
2872
|
+
out[0] = tmpvec3[0];
|
|
2873
|
+
out[1] = tmpvec3[1];
|
|
2874
|
+
out[2] = tmpvec3[2];
|
|
2875
|
+
out[3] = 1 + dot4;
|
|
2876
|
+
return normalize3(out, out);
|
|
2877
|
+
};
|
|
2878
|
+
}();
|
|
2879
|
+
var sqlerp = function() {
|
|
2880
|
+
const temp1 = create5();
|
|
2881
|
+
const temp2 = create5();
|
|
2882
|
+
return function(out, a, b, c, d, t) {
|
|
2883
|
+
slerp(temp1, a, d, t);
|
|
2884
|
+
slerp(temp2, b, c, t);
|
|
2885
|
+
slerp(out, temp1, temp2, 2 * t * (1 - t));
|
|
2886
|
+
return out;
|
|
2887
|
+
};
|
|
2888
|
+
}();
|
|
2889
|
+
var setAxes = function() {
|
|
2890
|
+
const matr = create3();
|
|
2891
|
+
return function(out, view, right, up) {
|
|
2892
|
+
matr[0] = right[0];
|
|
2893
|
+
matr[3] = right[1];
|
|
2894
|
+
matr[6] = right[2];
|
|
2895
|
+
matr[1] = up[0];
|
|
2896
|
+
matr[4] = up[1];
|
|
2897
|
+
matr[7] = up[2];
|
|
2898
|
+
matr[2] = -view[0];
|
|
2899
|
+
matr[5] = -view[1];
|
|
2900
|
+
matr[8] = -view[2];
|
|
2901
|
+
return normalize3(out, fromMat3(out, matr));
|
|
2902
|
+
};
|
|
2903
|
+
}();
|
|
2904
|
+
|
|
2905
|
+
// src/classes/quaternion.ts
|
|
2906
|
+
var IDENTITY_QUATERNION = [0, 0, 0, 1];
|
|
2907
|
+
var Quaternion = class extends MathArray {
|
|
2908
|
+
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
2909
|
+
super(-0, -0, -0, -0);
|
|
2910
|
+
if (Array.isArray(x) && arguments.length === 1) {
|
|
2911
|
+
this.copy(x);
|
|
2912
|
+
} else {
|
|
2913
|
+
this.set(x, y, z, w);
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
copy(array) {
|
|
2917
|
+
this[0] = array[0];
|
|
2918
|
+
this[1] = array[1];
|
|
2919
|
+
this[2] = array[2];
|
|
2920
|
+
this[3] = array[3];
|
|
2921
|
+
return this.check();
|
|
2922
|
+
}
|
|
2923
|
+
set(x, y, z, w) {
|
|
2924
|
+
this[0] = x;
|
|
2925
|
+
this[1] = y;
|
|
2926
|
+
this[2] = z;
|
|
2927
|
+
this[3] = w;
|
|
2928
|
+
return this.check();
|
|
2929
|
+
}
|
|
2930
|
+
fromObject(object) {
|
|
2931
|
+
this[0] = object.x;
|
|
2932
|
+
this[1] = object.y;
|
|
2933
|
+
this[2] = object.z;
|
|
2934
|
+
this[3] = object.w;
|
|
2935
|
+
return this.check();
|
|
2936
|
+
}
|
|
2937
|
+
fromMatrix3(m) {
|
|
2938
|
+
fromMat3(this, m);
|
|
2939
|
+
return this.check();
|
|
2940
|
+
}
|
|
2941
|
+
fromAxisRotation(axis, rad) {
|
|
2942
|
+
setAxisAngle(this, axis, rad);
|
|
2943
|
+
return this.check();
|
|
2944
|
+
}
|
|
2945
|
+
identity() {
|
|
2946
|
+
identity2(this);
|
|
2947
|
+
return this.check();
|
|
2948
|
+
}
|
|
2949
|
+
setAxisAngle(axis, rad) {
|
|
2950
|
+
return this.fromAxisRotation(axis, rad);
|
|
2951
|
+
}
|
|
2952
|
+
get ELEMENTS() {
|
|
2953
|
+
return 4;
|
|
2954
|
+
}
|
|
2955
|
+
get x() {
|
|
2956
|
+
return this[0];
|
|
2957
|
+
}
|
|
2958
|
+
set x(value) {
|
|
2959
|
+
this[0] = checkNumber(value);
|
|
2960
|
+
}
|
|
2961
|
+
get y() {
|
|
2962
|
+
return this[1];
|
|
2963
|
+
}
|
|
2964
|
+
set y(value) {
|
|
2965
|
+
this[1] = checkNumber(value);
|
|
2966
|
+
}
|
|
2967
|
+
get z() {
|
|
2968
|
+
return this[2];
|
|
2969
|
+
}
|
|
2970
|
+
set z(value) {
|
|
2971
|
+
this[2] = checkNumber(value);
|
|
2972
|
+
}
|
|
2973
|
+
get w() {
|
|
2974
|
+
return this[3];
|
|
2975
|
+
}
|
|
2976
|
+
set w(value) {
|
|
2977
|
+
this[3] = checkNumber(value);
|
|
2978
|
+
}
|
|
2979
|
+
len() {
|
|
2980
|
+
return length3(this);
|
|
2981
|
+
}
|
|
2982
|
+
lengthSquared() {
|
|
2983
|
+
return squaredLength2(this);
|
|
2984
|
+
}
|
|
2985
|
+
dot(a) {
|
|
2986
|
+
return dot3(this, a);
|
|
2987
|
+
}
|
|
2988
|
+
rotationTo(vectorA, vectorB) {
|
|
2989
|
+
rotationTo(this, vectorA, vectorB);
|
|
2990
|
+
return this.check();
|
|
2991
|
+
}
|
|
2992
|
+
add(a) {
|
|
2993
|
+
add2(this, this, a);
|
|
2994
|
+
return this.check();
|
|
2995
|
+
}
|
|
2996
|
+
calculateW() {
|
|
2997
|
+
calculateW(this, this);
|
|
2998
|
+
return this.check();
|
|
2999
|
+
}
|
|
3000
|
+
conjugate() {
|
|
3001
|
+
conjugate(this, this);
|
|
3002
|
+
return this.check();
|
|
3003
|
+
}
|
|
3004
|
+
invert() {
|
|
3005
|
+
invert3(this, this);
|
|
3006
|
+
return this.check();
|
|
3007
|
+
}
|
|
3008
|
+
lerp(a, b, t) {
|
|
3009
|
+
if (t === void 0) {
|
|
3010
|
+
return this.lerp(this, a, b);
|
|
3011
|
+
}
|
|
3012
|
+
lerp3(this, a, b, t);
|
|
3013
|
+
return this.check();
|
|
3014
|
+
}
|
|
3015
|
+
multiplyRight(a) {
|
|
3016
|
+
multiply3(this, this, a);
|
|
3017
|
+
return this.check();
|
|
3018
|
+
}
|
|
3019
|
+
multiplyLeft(a) {
|
|
3020
|
+
multiply3(this, a, this);
|
|
3021
|
+
return this.check();
|
|
3022
|
+
}
|
|
3023
|
+
normalize() {
|
|
3024
|
+
const length4 = this.len();
|
|
3025
|
+
const l = length4 > 0 ? 1 / length4 : 0;
|
|
3026
|
+
this[0] = this[0] * l;
|
|
3027
|
+
this[1] = this[1] * l;
|
|
3028
|
+
this[2] = this[2] * l;
|
|
3029
|
+
this[3] = this[3] * l;
|
|
3030
|
+
if (length4 === 0) {
|
|
3031
|
+
this[3] = 1;
|
|
3032
|
+
}
|
|
3033
|
+
return this.check();
|
|
3034
|
+
}
|
|
3035
|
+
rotateX(rad) {
|
|
3036
|
+
rotateX3(this, this, rad);
|
|
3037
|
+
return this.check();
|
|
3038
|
+
}
|
|
3039
|
+
rotateY(rad) {
|
|
3040
|
+
rotateY3(this, this, rad);
|
|
3041
|
+
return this.check();
|
|
3042
|
+
}
|
|
3043
|
+
rotateZ(rad) {
|
|
3044
|
+
rotateZ3(this, this, rad);
|
|
3045
|
+
return this.check();
|
|
3046
|
+
}
|
|
3047
|
+
scale(b) {
|
|
3048
|
+
scale4(this, this, b);
|
|
3049
|
+
return this.check();
|
|
3050
|
+
}
|
|
3051
|
+
slerp(arg0, arg1, arg2) {
|
|
3052
|
+
let start;
|
|
3053
|
+
let target;
|
|
3054
|
+
let ratio;
|
|
3055
|
+
switch (arguments.length) {
|
|
3056
|
+
case 1:
|
|
3057
|
+
({
|
|
3058
|
+
start = IDENTITY_QUATERNION,
|
|
3059
|
+
target,
|
|
3060
|
+
ratio
|
|
3061
|
+
} = arg0);
|
|
3062
|
+
break;
|
|
3063
|
+
case 2:
|
|
3064
|
+
start = this;
|
|
3065
|
+
target = arg0;
|
|
3066
|
+
ratio = arg1;
|
|
3067
|
+
break;
|
|
3068
|
+
default:
|
|
3069
|
+
start = arg0;
|
|
3070
|
+
target = arg1;
|
|
3071
|
+
ratio = arg2;
|
|
3072
|
+
}
|
|
3073
|
+
slerp(this, start, target, ratio);
|
|
3074
|
+
return this.check();
|
|
3075
|
+
}
|
|
3076
|
+
transformVector4(vector, result = new Vector4()) {
|
|
3077
|
+
transformQuat2(result, vector, this);
|
|
3078
|
+
return checkVector(result, 4);
|
|
3079
|
+
}
|
|
3080
|
+
lengthSq() {
|
|
3081
|
+
return this.lengthSquared();
|
|
3082
|
+
}
|
|
3083
|
+
setFromAxisAngle(axis, rad) {
|
|
3084
|
+
return this.setAxisAngle(axis, rad);
|
|
3085
|
+
}
|
|
3086
|
+
premultiply(a) {
|
|
3087
|
+
return this.multiplyLeft(a);
|
|
3088
|
+
}
|
|
3089
|
+
multiply(a) {
|
|
3090
|
+
return this.multiplyRight(a);
|
|
3091
|
+
}
|
|
3092
|
+
};
|
|
3093
|
+
|
|
3094
|
+
// src/classes/spherical-coordinates.ts
|
|
3095
|
+
var EPSILON2 = 1e-6;
|
|
3096
|
+
var EARTH_RADIUS_METERS = 6371e3;
|
|
3097
|
+
var SphericalCoordinates = class {
|
|
3098
|
+
constructor({
|
|
3099
|
+
phi = 0,
|
|
3100
|
+
theta = 0,
|
|
3101
|
+
radius = 1,
|
|
3102
|
+
bearing,
|
|
3103
|
+
pitch,
|
|
3104
|
+
altitude,
|
|
3105
|
+
radiusScale = EARTH_RADIUS_METERS
|
|
3106
|
+
} = {}) {
|
|
3107
|
+
this.phi = phi;
|
|
3108
|
+
this.theta = theta;
|
|
3109
|
+
this.radius = radius || altitude || 1;
|
|
3110
|
+
this.radiusScale = radiusScale || 1;
|
|
3111
|
+
if (bearing !== void 0) {
|
|
3112
|
+
this.bearing = bearing;
|
|
3113
|
+
}
|
|
3114
|
+
if (pitch !== void 0) {
|
|
3115
|
+
this.pitch = pitch;
|
|
3116
|
+
}
|
|
3117
|
+
this.check();
|
|
3118
|
+
}
|
|
3119
|
+
toString() {
|
|
3120
|
+
return this.formatString(config);
|
|
3121
|
+
}
|
|
3122
|
+
formatString({ printTypes = false }) {
|
|
3123
|
+
const f = formatValue;
|
|
3124
|
+
return `${printTypes ? "Spherical" : ""}[rho:${f(this.radius)},theta:${f(this.theta)},phi:${f(this.phi)}]`;
|
|
3125
|
+
}
|
|
3126
|
+
equals(other) {
|
|
3127
|
+
return equals(this.radius, other.radius) && equals(this.theta, other.theta) && equals(this.phi, other.phi);
|
|
3128
|
+
}
|
|
3129
|
+
exactEquals(other) {
|
|
3130
|
+
return this.radius === other.radius && this.theta === other.theta && this.phi === other.phi;
|
|
3131
|
+
}
|
|
3132
|
+
get bearing() {
|
|
3133
|
+
return 180 - degrees(this.phi);
|
|
3134
|
+
}
|
|
3135
|
+
set bearing(v) {
|
|
3136
|
+
this.phi = Math.PI - radians(v);
|
|
3137
|
+
}
|
|
3138
|
+
get pitch() {
|
|
3139
|
+
return degrees(this.theta);
|
|
3140
|
+
}
|
|
3141
|
+
set pitch(v) {
|
|
3142
|
+
this.theta = radians(v);
|
|
3143
|
+
}
|
|
3144
|
+
get longitude() {
|
|
3145
|
+
return degrees(this.phi);
|
|
3146
|
+
}
|
|
3147
|
+
get latitude() {
|
|
3148
|
+
return degrees(this.theta);
|
|
3149
|
+
}
|
|
3150
|
+
get lng() {
|
|
3151
|
+
return degrees(this.phi);
|
|
3152
|
+
}
|
|
3153
|
+
get lat() {
|
|
3154
|
+
return degrees(this.theta);
|
|
3155
|
+
}
|
|
3156
|
+
get z() {
|
|
3157
|
+
return (this.radius - 1) * this.radiusScale;
|
|
3158
|
+
}
|
|
3159
|
+
set(radius, phi, theta) {
|
|
3160
|
+
this.radius = radius;
|
|
3161
|
+
this.phi = phi;
|
|
3162
|
+
this.theta = theta;
|
|
3163
|
+
return this.check();
|
|
3164
|
+
}
|
|
3165
|
+
clone() {
|
|
3166
|
+
return new SphericalCoordinates().copy(this);
|
|
3167
|
+
}
|
|
3168
|
+
copy(other) {
|
|
3169
|
+
this.radius = other.radius;
|
|
3170
|
+
this.phi = other.phi;
|
|
3171
|
+
this.theta = other.theta;
|
|
3172
|
+
return this.check();
|
|
3173
|
+
}
|
|
3174
|
+
fromLngLatZ([lng, lat, z]) {
|
|
3175
|
+
this.radius = 1 + z / this.radiusScale;
|
|
3176
|
+
this.phi = radians(lat);
|
|
3177
|
+
this.theta = radians(lng);
|
|
3178
|
+
return this.check();
|
|
3179
|
+
}
|
|
3180
|
+
fromVector3(v) {
|
|
3181
|
+
this.radius = length(v);
|
|
3182
|
+
if (this.radius > 0) {
|
|
3183
|
+
this.theta = Math.atan2(v[0], v[1]);
|
|
3184
|
+
this.phi = Math.acos(clamp(v[2] / this.radius, -1, 1));
|
|
3185
|
+
}
|
|
3186
|
+
return this.check();
|
|
3187
|
+
}
|
|
3188
|
+
toVector3() {
|
|
3189
|
+
return new Vector3(0, 0, this.radius).rotateX({ radians: this.theta }).rotateZ({ radians: this.phi });
|
|
3190
|
+
}
|
|
3191
|
+
makeSafe() {
|
|
3192
|
+
this.phi = Math.max(EPSILON2, Math.min(Math.PI - EPSILON2, this.phi));
|
|
3193
|
+
return this;
|
|
3194
|
+
}
|
|
3195
|
+
check() {
|
|
3196
|
+
if (!Number.isFinite(this.phi) || !Number.isFinite(this.theta) || !(this.radius > 0)) {
|
|
3197
|
+
throw new Error("SphericalCoordinates: some fields set to invalid numbers");
|
|
3198
|
+
}
|
|
3199
|
+
return this;
|
|
3200
|
+
}
|
|
3201
|
+
};
|
|
3202
|
+
|
|
3203
|
+
// src/classes/euler.ts
|
|
3204
|
+
var ERR_UNKNOWN_ORDER = "Unknown Euler angle order";
|
|
3205
|
+
var ALMOST_ONE = 0.99999;
|
|
3206
|
+
var RotationOrder = /* @__PURE__ */ ((RotationOrder2) => {
|
|
3207
|
+
RotationOrder2[RotationOrder2["ZYX"] = 0] = "ZYX";
|
|
3208
|
+
RotationOrder2[RotationOrder2["YXZ"] = 1] = "YXZ";
|
|
3209
|
+
RotationOrder2[RotationOrder2["XZY"] = 2] = "XZY";
|
|
3210
|
+
RotationOrder2[RotationOrder2["ZXY"] = 3] = "ZXY";
|
|
3211
|
+
RotationOrder2[RotationOrder2["YZX"] = 4] = "YZX";
|
|
3212
|
+
RotationOrder2[RotationOrder2["XYZ"] = 5] = "XYZ";
|
|
3213
|
+
return RotationOrder2;
|
|
3214
|
+
})(RotationOrder || {});
|
|
3215
|
+
var Euler = class extends MathArray {
|
|
3216
|
+
static get ZYX() {
|
|
3217
|
+
return 0 /* ZYX */;
|
|
3218
|
+
}
|
|
3219
|
+
static get YXZ() {
|
|
3220
|
+
return 1 /* YXZ */;
|
|
3221
|
+
}
|
|
3222
|
+
static get XZY() {
|
|
3223
|
+
return 2 /* XZY */;
|
|
3224
|
+
}
|
|
3225
|
+
static get ZXY() {
|
|
3226
|
+
return 3 /* ZXY */;
|
|
3227
|
+
}
|
|
3228
|
+
static get YZX() {
|
|
3229
|
+
return 4 /* YZX */;
|
|
3230
|
+
}
|
|
3231
|
+
static get XYZ() {
|
|
3232
|
+
return 5 /* XYZ */;
|
|
3233
|
+
}
|
|
3234
|
+
static get RollPitchYaw() {
|
|
3235
|
+
return 0 /* ZYX */;
|
|
3236
|
+
}
|
|
3237
|
+
static get DefaultOrder() {
|
|
3238
|
+
return 0 /* ZYX */;
|
|
3239
|
+
}
|
|
3240
|
+
static get RotationOrders() {
|
|
3241
|
+
return RotationOrder;
|
|
3242
|
+
}
|
|
3243
|
+
static rotationOrder(order) {
|
|
3244
|
+
return RotationOrder[order];
|
|
3245
|
+
}
|
|
3246
|
+
get ELEMENTS() {
|
|
3247
|
+
return 4;
|
|
3248
|
+
}
|
|
3249
|
+
constructor(x = 0, y = 0, z = 0, order = Euler.DefaultOrder) {
|
|
3250
|
+
super(-0, -0, -0, -0);
|
|
3251
|
+
if (arguments.length > 0 && Array.isArray(arguments[0])) {
|
|
3252
|
+
this.fromVector3(...arguments);
|
|
3253
|
+
} else {
|
|
3254
|
+
this.set(x, y, z, order);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
fromQuaternion(quaternion) {
|
|
3258
|
+
const [x, y, z, w] = quaternion;
|
|
3259
|
+
const ysqr = y * y;
|
|
3260
|
+
const t0 = -2 * (ysqr + z * z) + 1;
|
|
3261
|
+
const t1 = 2 * (x * y + w * z);
|
|
3262
|
+
let t2 = -2 * (x * z - w * y);
|
|
3263
|
+
const t3 = 2 * (y * z + w * x);
|
|
3264
|
+
const t4 = -2 * (x * x + ysqr) + 1;
|
|
3265
|
+
t2 = t2 > 1 ? 1 : t2;
|
|
3266
|
+
t2 = t2 < -1 ? -1 : t2;
|
|
3267
|
+
const roll = Math.atan2(t3, t4);
|
|
3268
|
+
const pitch = Math.asin(t2);
|
|
3269
|
+
const yaw = Math.atan2(t1, t0);
|
|
3270
|
+
return this.set(roll, pitch, yaw, Euler.RollPitchYaw);
|
|
3271
|
+
}
|
|
3272
|
+
fromObject(object) {
|
|
3273
|
+
throw new Error("not implemented");
|
|
3274
|
+
}
|
|
3275
|
+
copy(array) {
|
|
3276
|
+
this[0] = array[0];
|
|
3277
|
+
this[1] = array[1];
|
|
3278
|
+
this[2] = array[2];
|
|
3279
|
+
this[3] = Number.isFinite(array[3]) || this.order;
|
|
3280
|
+
return this.check();
|
|
3281
|
+
}
|
|
3282
|
+
set(x = 0, y = 0, z = 0, order) {
|
|
3283
|
+
this[0] = x;
|
|
3284
|
+
this[1] = y;
|
|
3285
|
+
this[2] = z;
|
|
3286
|
+
this[3] = Number.isFinite(order) ? order : this[3];
|
|
3287
|
+
return this.check();
|
|
3288
|
+
}
|
|
3289
|
+
validate() {
|
|
3290
|
+
return validateOrder(this[3]) && Number.isFinite(this[0]) && Number.isFinite(this[1]) && Number.isFinite(this[2]);
|
|
3291
|
+
}
|
|
3292
|
+
toArray(array = [], offset = 0) {
|
|
3293
|
+
array[offset] = this[0];
|
|
3294
|
+
array[offset + 1] = this[1];
|
|
3295
|
+
array[offset + 2] = this[2];
|
|
3296
|
+
return array;
|
|
3297
|
+
}
|
|
3298
|
+
toArray4(array = [], offset = 0) {
|
|
3299
|
+
array[offset] = this[0];
|
|
3300
|
+
array[offset + 1] = this[1];
|
|
3301
|
+
array[offset + 2] = this[2];
|
|
3302
|
+
array[offset + 3] = this[3];
|
|
3303
|
+
return array;
|
|
3304
|
+
}
|
|
3305
|
+
toVector3(result = [-0, -0, -0]) {
|
|
3306
|
+
result[0] = this[0];
|
|
3307
|
+
result[1] = this[1];
|
|
3308
|
+
result[2] = this[2];
|
|
3309
|
+
return result;
|
|
3310
|
+
}
|
|
3311
|
+
get x() {
|
|
3312
|
+
return this[0];
|
|
3313
|
+
}
|
|
3314
|
+
set x(value) {
|
|
3315
|
+
this[0] = checkNumber(value);
|
|
3316
|
+
}
|
|
3317
|
+
get y() {
|
|
3318
|
+
return this[1];
|
|
3319
|
+
}
|
|
3320
|
+
set y(value) {
|
|
3321
|
+
this[1] = checkNumber(value);
|
|
3322
|
+
}
|
|
3323
|
+
get z() {
|
|
3324
|
+
return this[2];
|
|
3325
|
+
}
|
|
3326
|
+
set z(value) {
|
|
3327
|
+
this[2] = checkNumber(value);
|
|
3328
|
+
}
|
|
3329
|
+
get alpha() {
|
|
3330
|
+
return this[0];
|
|
3331
|
+
}
|
|
3332
|
+
set alpha(value) {
|
|
3333
|
+
this[0] = checkNumber(value);
|
|
3334
|
+
}
|
|
3335
|
+
get beta() {
|
|
3336
|
+
return this[1];
|
|
3337
|
+
}
|
|
3338
|
+
set beta(value) {
|
|
3339
|
+
this[1] = checkNumber(value);
|
|
3340
|
+
}
|
|
3341
|
+
get gamma() {
|
|
3342
|
+
return this[2];
|
|
3343
|
+
}
|
|
3344
|
+
set gamma(value) {
|
|
3345
|
+
this[2] = checkNumber(value);
|
|
3346
|
+
}
|
|
3347
|
+
get phi() {
|
|
3348
|
+
return this[0];
|
|
3349
|
+
}
|
|
3350
|
+
set phi(value) {
|
|
3351
|
+
this[0] = checkNumber(value);
|
|
3352
|
+
}
|
|
3353
|
+
get theta() {
|
|
3354
|
+
return this[1];
|
|
3355
|
+
}
|
|
3356
|
+
set theta(value) {
|
|
3357
|
+
this[1] = checkNumber(value);
|
|
3358
|
+
}
|
|
3359
|
+
get psi() {
|
|
3360
|
+
return this[2];
|
|
3361
|
+
}
|
|
3362
|
+
set psi(value) {
|
|
3363
|
+
this[2] = checkNumber(value);
|
|
3364
|
+
}
|
|
3365
|
+
get roll() {
|
|
3366
|
+
return this[0];
|
|
3367
|
+
}
|
|
3368
|
+
set roll(value) {
|
|
3369
|
+
this[0] = checkNumber(value);
|
|
3370
|
+
}
|
|
3371
|
+
get pitch() {
|
|
3372
|
+
return this[1];
|
|
3373
|
+
}
|
|
3374
|
+
set pitch(value) {
|
|
3375
|
+
this[1] = checkNumber(value);
|
|
3376
|
+
}
|
|
3377
|
+
get yaw() {
|
|
3378
|
+
return this[2];
|
|
3379
|
+
}
|
|
3380
|
+
set yaw(value) {
|
|
3381
|
+
this[2] = checkNumber(value);
|
|
3382
|
+
}
|
|
3383
|
+
get order() {
|
|
3384
|
+
return this[3];
|
|
3385
|
+
}
|
|
3386
|
+
set order(value) {
|
|
3387
|
+
this[3] = checkOrder(value);
|
|
3388
|
+
}
|
|
3389
|
+
fromVector3(v, order) {
|
|
3390
|
+
return this.set(v[0], v[1], v[2], Number.isFinite(order) ? order : this[3]);
|
|
3391
|
+
}
|
|
3392
|
+
fromArray(array, offset = 0) {
|
|
3393
|
+
this[0] = array[0 + offset];
|
|
3394
|
+
this[1] = array[1 + offset];
|
|
3395
|
+
this[2] = array[2 + offset];
|
|
3396
|
+
if (array[3] !== void 0) {
|
|
3397
|
+
this[3] = array[3];
|
|
3398
|
+
}
|
|
3399
|
+
return this.check();
|
|
3400
|
+
}
|
|
3401
|
+
fromRollPitchYaw(roll, pitch, yaw) {
|
|
3402
|
+
return this.set(roll, pitch, yaw, 0 /* ZYX */);
|
|
3403
|
+
}
|
|
3404
|
+
fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
3405
|
+
this._fromRotationMatrix(m, order);
|
|
3406
|
+
return this.check();
|
|
3407
|
+
}
|
|
3408
|
+
getRotationMatrix(m) {
|
|
3409
|
+
return this._getRotationMatrix(m);
|
|
3410
|
+
}
|
|
3411
|
+
getQuaternion() {
|
|
3412
|
+
const q = new Quaternion();
|
|
3413
|
+
switch (this[3]) {
|
|
3414
|
+
case 5 /* XYZ */:
|
|
3415
|
+
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
|
|
3416
|
+
case 1 /* YXZ */:
|
|
3417
|
+
return q.rotateY(this[0]).rotateX(this[1]).rotateZ(this[2]);
|
|
3418
|
+
case 3 /* ZXY */:
|
|
3419
|
+
return q.rotateZ(this[0]).rotateX(this[1]).rotateY(this[2]);
|
|
3420
|
+
case 0 /* ZYX */:
|
|
3421
|
+
return q.rotateZ(this[0]).rotateY(this[1]).rotateX(this[2]);
|
|
3422
|
+
case 4 /* YZX */:
|
|
3423
|
+
return q.rotateY(this[0]).rotateZ(this[1]).rotateX(this[2]);
|
|
3424
|
+
case 2 /* XZY */:
|
|
3425
|
+
return q.rotateX(this[0]).rotateZ(this[1]).rotateY(this[2]);
|
|
3426
|
+
default:
|
|
3427
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
_fromRotationMatrix(m, order = Euler.DefaultOrder) {
|
|
3431
|
+
const m11 = m[0], m12 = m[4], m13 = m[8];
|
|
3432
|
+
const m21 = m[1], m22 = m[5], m23 = m[9];
|
|
3433
|
+
const m31 = m[2], m32 = m[6], m33 = m[10];
|
|
3434
|
+
order = order || this[3];
|
|
3435
|
+
switch (order) {
|
|
3436
|
+
case Euler.XYZ:
|
|
3437
|
+
this[1] = Math.asin(clamp(m13, -1, 1));
|
|
3438
|
+
if (Math.abs(m13) < ALMOST_ONE) {
|
|
3439
|
+
this[0] = Math.atan2(-m23, m33);
|
|
3440
|
+
this[2] = Math.atan2(-m12, m11);
|
|
3441
|
+
} else {
|
|
3442
|
+
this[0] = Math.atan2(m32, m22);
|
|
3443
|
+
this[2] = 0;
|
|
3444
|
+
}
|
|
3445
|
+
break;
|
|
3446
|
+
case Euler.YXZ:
|
|
3447
|
+
this[0] = Math.asin(-clamp(m23, -1, 1));
|
|
3448
|
+
if (Math.abs(m23) < ALMOST_ONE) {
|
|
3449
|
+
this[1] = Math.atan2(m13, m33);
|
|
3450
|
+
this[2] = Math.atan2(m21, m22);
|
|
3451
|
+
} else {
|
|
3452
|
+
this[1] = Math.atan2(-m31, m11);
|
|
3453
|
+
this[2] = 0;
|
|
3454
|
+
}
|
|
3455
|
+
break;
|
|
3456
|
+
case Euler.ZXY:
|
|
3457
|
+
this[0] = Math.asin(clamp(m32, -1, 1));
|
|
3458
|
+
if (Math.abs(m32) < ALMOST_ONE) {
|
|
3459
|
+
this[1] = Math.atan2(-m31, m33);
|
|
3460
|
+
this[2] = Math.atan2(-m12, m22);
|
|
3461
|
+
} else {
|
|
3462
|
+
this[1] = 0;
|
|
3463
|
+
this[2] = Math.atan2(m21, m11);
|
|
3464
|
+
}
|
|
3465
|
+
break;
|
|
3466
|
+
case Euler.ZYX:
|
|
3467
|
+
this[1] = Math.asin(-clamp(m31, -1, 1));
|
|
3468
|
+
if (Math.abs(m31) < ALMOST_ONE) {
|
|
3469
|
+
this[0] = Math.atan2(m32, m33);
|
|
3470
|
+
this[2] = Math.atan2(m21, m11);
|
|
3471
|
+
} else {
|
|
3472
|
+
this[0] = 0;
|
|
3473
|
+
this[2] = Math.atan2(-m12, m22);
|
|
3474
|
+
}
|
|
3475
|
+
break;
|
|
3476
|
+
case Euler.YZX:
|
|
3477
|
+
this[2] = Math.asin(clamp(m21, -1, 1));
|
|
3478
|
+
if (Math.abs(m21) < ALMOST_ONE) {
|
|
3479
|
+
this[0] = Math.atan2(-m23, m22);
|
|
3480
|
+
this[1] = Math.atan2(-m31, m11);
|
|
3481
|
+
} else {
|
|
3482
|
+
this[0] = 0;
|
|
3483
|
+
this[1] = Math.atan2(m13, m33);
|
|
3484
|
+
}
|
|
3485
|
+
break;
|
|
3486
|
+
case Euler.XZY:
|
|
3487
|
+
this[2] = Math.asin(-clamp(m12, -1, 1));
|
|
3488
|
+
if (Math.abs(m12) < ALMOST_ONE) {
|
|
3489
|
+
this[0] = Math.atan2(m32, m22);
|
|
3490
|
+
this[1] = Math.atan2(m13, m11);
|
|
3491
|
+
} else {
|
|
3492
|
+
this[0] = Math.atan2(-m23, m33);
|
|
3493
|
+
this[1] = 0;
|
|
3494
|
+
}
|
|
3495
|
+
break;
|
|
3496
|
+
default:
|
|
3497
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
3498
|
+
}
|
|
3499
|
+
this[3] = order;
|
|
3500
|
+
return this;
|
|
3501
|
+
}
|
|
3502
|
+
_getRotationMatrix(result) {
|
|
3503
|
+
const te = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
3504
|
+
const x = this.x, y = this.y, z = this.z;
|
|
3505
|
+
const a = Math.cos(x);
|
|
3506
|
+
const c = Math.cos(y);
|
|
3507
|
+
const e = Math.cos(z);
|
|
3508
|
+
const b = Math.sin(x);
|
|
3509
|
+
const d = Math.sin(y);
|
|
3510
|
+
const f = Math.sin(z);
|
|
3511
|
+
switch (this[3]) {
|
|
3512
|
+
case Euler.XYZ: {
|
|
3513
|
+
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
3514
|
+
te[0] = c * e;
|
|
3515
|
+
te[4] = -c * f;
|
|
3516
|
+
te[8] = d;
|
|
3517
|
+
te[1] = af + be * d;
|
|
3518
|
+
te[5] = ae - bf * d;
|
|
3519
|
+
te[9] = -b * c;
|
|
3520
|
+
te[2] = bf - ae * d;
|
|
3521
|
+
te[6] = be + af * d;
|
|
3522
|
+
te[10] = a * c;
|
|
3523
|
+
break;
|
|
3524
|
+
}
|
|
3525
|
+
case Euler.YXZ: {
|
|
3526
|
+
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
3527
|
+
te[0] = ce + df * b;
|
|
3528
|
+
te[4] = de * b - cf;
|
|
3529
|
+
te[8] = a * d;
|
|
3530
|
+
te[1] = a * f;
|
|
3531
|
+
te[5] = a * e;
|
|
3532
|
+
te[9] = -b;
|
|
3533
|
+
te[2] = cf * b - de;
|
|
3534
|
+
te[6] = df + ce * b;
|
|
3535
|
+
te[10] = a * c;
|
|
3536
|
+
break;
|
|
3537
|
+
}
|
|
3538
|
+
case Euler.ZXY: {
|
|
3539
|
+
const ce = c * e, cf = c * f, de = d * e, df = d * f;
|
|
3540
|
+
te[0] = ce - df * b;
|
|
3541
|
+
te[4] = -a * f;
|
|
3542
|
+
te[8] = de + cf * b;
|
|
3543
|
+
te[1] = cf + de * b;
|
|
3544
|
+
te[5] = a * e;
|
|
3545
|
+
te[9] = df - ce * b;
|
|
3546
|
+
te[2] = -a * d;
|
|
3547
|
+
te[6] = b;
|
|
3548
|
+
te[10] = a * c;
|
|
3549
|
+
break;
|
|
3550
|
+
}
|
|
3551
|
+
case Euler.ZYX: {
|
|
3552
|
+
const ae = a * e, af = a * f, be = b * e, bf = b * f;
|
|
3553
|
+
te[0] = c * e;
|
|
3554
|
+
te[4] = be * d - af;
|
|
3555
|
+
te[8] = ae * d + bf;
|
|
3556
|
+
te[1] = c * f;
|
|
3557
|
+
te[5] = bf * d + ae;
|
|
3558
|
+
te[9] = af * d - be;
|
|
3559
|
+
te[2] = -d;
|
|
3560
|
+
te[6] = b * c;
|
|
3561
|
+
te[10] = a * c;
|
|
3562
|
+
break;
|
|
3563
|
+
}
|
|
3564
|
+
case Euler.YZX: {
|
|
3565
|
+
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
3566
|
+
te[0] = c * e;
|
|
3567
|
+
te[4] = bd - ac * f;
|
|
3568
|
+
te[8] = bc * f + ad;
|
|
3569
|
+
te[1] = f;
|
|
3570
|
+
te[5] = a * e;
|
|
3571
|
+
te[9] = -b * e;
|
|
3572
|
+
te[2] = -d * e;
|
|
3573
|
+
te[6] = ad * f + bc;
|
|
3574
|
+
te[10] = ac - bd * f;
|
|
3575
|
+
break;
|
|
3576
|
+
}
|
|
3577
|
+
case Euler.XZY: {
|
|
3578
|
+
const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
|
3579
|
+
te[0] = c * e;
|
|
3580
|
+
te[4] = -f;
|
|
3581
|
+
te[8] = d * e;
|
|
3582
|
+
te[1] = ac * f + bd;
|
|
3583
|
+
te[5] = a * e;
|
|
3584
|
+
te[9] = ad * f - bc;
|
|
3585
|
+
te[2] = bc * f - ad;
|
|
3586
|
+
te[6] = b * e;
|
|
3587
|
+
te[10] = bd * f + ac;
|
|
3588
|
+
break;
|
|
3589
|
+
}
|
|
3590
|
+
default:
|
|
3591
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
3592
|
+
}
|
|
3593
|
+
te[3] = 0;
|
|
3594
|
+
te[7] = 0;
|
|
3595
|
+
te[11] = 0;
|
|
3596
|
+
te[12] = 0;
|
|
3597
|
+
te[13] = 0;
|
|
3598
|
+
te[14] = 0;
|
|
3599
|
+
te[15] = 1;
|
|
3600
|
+
return te;
|
|
3601
|
+
}
|
|
3602
|
+
toQuaternion() {
|
|
3603
|
+
const cy = Math.cos(this.yaw * 0.5);
|
|
3604
|
+
const sy = Math.sin(this.yaw * 0.5);
|
|
3605
|
+
const cr = Math.cos(this.roll * 0.5);
|
|
3606
|
+
const sr = Math.sin(this.roll * 0.5);
|
|
3607
|
+
const cp = Math.cos(this.pitch * 0.5);
|
|
3608
|
+
const sp = Math.sin(this.pitch * 0.5);
|
|
3609
|
+
const w = cy * cr * cp + sy * sr * sp;
|
|
3610
|
+
const x = cy * sr * cp - sy * cr * sp;
|
|
3611
|
+
const y = cy * cr * sp + sy * sr * cp;
|
|
3612
|
+
const z = sy * cr * cp - cy * sr * sp;
|
|
3613
|
+
return new Quaternion(x, y, z, w);
|
|
3614
|
+
}
|
|
3615
|
+
};
|
|
3616
|
+
function validateOrder(value) {
|
|
3617
|
+
return value >= 0 && value < 6;
|
|
3618
|
+
}
|
|
3619
|
+
function checkOrder(value) {
|
|
3620
|
+
if (value < 0 && value >= 6) {
|
|
3621
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
3622
|
+
}
|
|
3623
|
+
return value;
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3626
|
+
// src/classes/pose.ts
|
|
3627
|
+
var Pose = class {
|
|
3628
|
+
constructor({
|
|
3629
|
+
x = 0,
|
|
3630
|
+
y = 0,
|
|
3631
|
+
z = 0,
|
|
3632
|
+
roll = 0,
|
|
3633
|
+
pitch = 0,
|
|
3634
|
+
yaw = 0,
|
|
3635
|
+
position,
|
|
3636
|
+
orientation
|
|
3637
|
+
} = {}) {
|
|
3638
|
+
if (Array.isArray(position) && position.length === 3) {
|
|
3639
|
+
this.position = new Vector3(position);
|
|
3640
|
+
} else {
|
|
3641
|
+
this.position = new Vector3(x, y, z);
|
|
3642
|
+
}
|
|
3643
|
+
if (Array.isArray(orientation) && orientation.length === 4) {
|
|
3644
|
+
this.orientation = new Euler(orientation, orientation[3]);
|
|
3645
|
+
} else {
|
|
3646
|
+
this.orientation = new Euler(roll, pitch, yaw, Euler.RollPitchYaw);
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
get x() {
|
|
3650
|
+
return this.position.x;
|
|
3651
|
+
}
|
|
3652
|
+
set x(value) {
|
|
3653
|
+
this.position.x = value;
|
|
3654
|
+
}
|
|
3655
|
+
get y() {
|
|
3656
|
+
return this.position.y;
|
|
3657
|
+
}
|
|
3658
|
+
set y(value) {
|
|
3659
|
+
this.position.y = value;
|
|
3660
|
+
}
|
|
3661
|
+
get z() {
|
|
3662
|
+
return this.position.z;
|
|
3663
|
+
}
|
|
3664
|
+
set z(value) {
|
|
3665
|
+
this.position.z = value;
|
|
3666
|
+
}
|
|
3667
|
+
get roll() {
|
|
3668
|
+
return this.orientation.roll;
|
|
3669
|
+
}
|
|
3670
|
+
set roll(value) {
|
|
3671
|
+
this.orientation.roll = value;
|
|
3672
|
+
}
|
|
3673
|
+
get pitch() {
|
|
3674
|
+
return this.orientation.pitch;
|
|
3675
|
+
}
|
|
3676
|
+
set pitch(value) {
|
|
3677
|
+
this.orientation.pitch = value;
|
|
3678
|
+
}
|
|
3679
|
+
get yaw() {
|
|
3680
|
+
return this.orientation.yaw;
|
|
3681
|
+
}
|
|
3682
|
+
set yaw(value) {
|
|
3683
|
+
this.orientation.yaw = value;
|
|
3684
|
+
}
|
|
3685
|
+
getPosition() {
|
|
3686
|
+
return this.position;
|
|
3687
|
+
}
|
|
3688
|
+
getOrientation() {
|
|
3689
|
+
return this.orientation;
|
|
3690
|
+
}
|
|
3691
|
+
equals(pose) {
|
|
3692
|
+
if (!pose) {
|
|
3693
|
+
return false;
|
|
3694
|
+
}
|
|
3695
|
+
return this.position.equals(pose.position) && this.orientation.equals(pose.orientation);
|
|
3696
|
+
}
|
|
3697
|
+
exactEquals(pose) {
|
|
3698
|
+
if (!pose) {
|
|
3699
|
+
return false;
|
|
3700
|
+
}
|
|
3701
|
+
return this.position.exactEquals(pose.position) && this.orientation.exactEquals(pose.orientation);
|
|
3702
|
+
}
|
|
3703
|
+
getTransformationMatrix() {
|
|
3704
|
+
const sr = Math.sin(this.roll);
|
|
3705
|
+
const sp = Math.sin(this.pitch);
|
|
3706
|
+
const sw = Math.sin(this.yaw);
|
|
3707
|
+
const cr = Math.cos(this.roll);
|
|
3708
|
+
const cp = Math.cos(this.pitch);
|
|
3709
|
+
const cw = Math.cos(this.yaw);
|
|
3710
|
+
return new Matrix4().setRowMajor(
|
|
3711
|
+
cw * cp,
|
|
3712
|
+
-sw * cr + cw * sp * sr,
|
|
3713
|
+
sw * sr + cw * sp * cr,
|
|
3714
|
+
this.x,
|
|
3715
|
+
sw * cp,
|
|
3716
|
+
cw * cr + sw * sp * sr,
|
|
3717
|
+
-cw * sr + sw * sp * cr,
|
|
3718
|
+
this.y,
|
|
3719
|
+
-sp,
|
|
3720
|
+
cp * sr,
|
|
3721
|
+
cp * cr,
|
|
3722
|
+
this.z,
|
|
3723
|
+
0,
|
|
3724
|
+
0,
|
|
3725
|
+
0,
|
|
3726
|
+
1
|
|
3727
|
+
);
|
|
3728
|
+
}
|
|
3729
|
+
getTransformationMatrixFromPose(pose) {
|
|
3730
|
+
return new Matrix4().multiplyRight(this.getTransformationMatrix()).multiplyRight(pose.getTransformationMatrix().invert());
|
|
3731
|
+
}
|
|
3732
|
+
getTransformationMatrixToPose(pose) {
|
|
3733
|
+
return new Matrix4().multiplyRight(pose.getTransformationMatrix()).multiplyRight(this.getTransformationMatrix().invert());
|
|
3734
|
+
}
|
|
3735
|
+
};
|
|
3736
|
+
|
|
3737
|
+
// src/lib/math-utils.ts
|
|
3738
|
+
var math_utils_exports = {};
|
|
3739
|
+
__export(math_utils_exports, {
|
|
3740
|
+
EPSILON1: () => EPSILON1,
|
|
3741
|
+
EPSILON10: () => EPSILON10,
|
|
3742
|
+
EPSILON11: () => EPSILON11,
|
|
3743
|
+
EPSILON12: () => EPSILON12,
|
|
3744
|
+
EPSILON13: () => EPSILON13,
|
|
3745
|
+
EPSILON14: () => EPSILON14,
|
|
3746
|
+
EPSILON15: () => EPSILON15,
|
|
3747
|
+
EPSILON16: () => EPSILON16,
|
|
3748
|
+
EPSILON17: () => EPSILON17,
|
|
3749
|
+
EPSILON18: () => EPSILON18,
|
|
3750
|
+
EPSILON19: () => EPSILON19,
|
|
3751
|
+
EPSILON2: () => EPSILON22,
|
|
3752
|
+
EPSILON20: () => EPSILON20,
|
|
3753
|
+
EPSILON3: () => EPSILON3,
|
|
3754
|
+
EPSILON4: () => EPSILON4,
|
|
3755
|
+
EPSILON5: () => EPSILON5,
|
|
3756
|
+
EPSILON6: () => EPSILON6,
|
|
3757
|
+
EPSILON7: () => EPSILON7,
|
|
3758
|
+
EPSILON8: () => EPSILON8,
|
|
3759
|
+
EPSILON9: () => EPSILON9,
|
|
3760
|
+
PI_OVER_FOUR: () => PI_OVER_FOUR,
|
|
3761
|
+
PI_OVER_SIX: () => PI_OVER_SIX,
|
|
3762
|
+
PI_OVER_TWO: () => PI_OVER_TWO,
|
|
3763
|
+
TWO_PI: () => TWO_PI
|
|
3764
|
+
});
|
|
3765
|
+
var EPSILON1 = 0.1;
|
|
3766
|
+
var EPSILON22 = 0.01;
|
|
3767
|
+
var EPSILON3 = 1e-3;
|
|
3768
|
+
var EPSILON4 = 1e-4;
|
|
3769
|
+
var EPSILON5 = 1e-5;
|
|
3770
|
+
var EPSILON6 = 1e-6;
|
|
3771
|
+
var EPSILON7 = 1e-7;
|
|
3772
|
+
var EPSILON8 = 1e-8;
|
|
3773
|
+
var EPSILON9 = 1e-9;
|
|
3774
|
+
var EPSILON10 = 1e-10;
|
|
3775
|
+
var EPSILON11 = 1e-11;
|
|
3776
|
+
var EPSILON12 = 1e-12;
|
|
3777
|
+
var EPSILON13 = 1e-13;
|
|
3778
|
+
var EPSILON14 = 1e-14;
|
|
3779
|
+
var EPSILON15 = 1e-15;
|
|
3780
|
+
var EPSILON16 = 1e-16;
|
|
3781
|
+
var EPSILON17 = 1e-17;
|
|
3782
|
+
var EPSILON18 = 1e-18;
|
|
3783
|
+
var EPSILON19 = 1e-19;
|
|
3784
|
+
var EPSILON20 = 1e-20;
|
|
3785
|
+
var PI_OVER_TWO = Math.PI / 2;
|
|
3786
|
+
var PI_OVER_FOUR = Math.PI / 4;
|
|
3787
|
+
var PI_OVER_SIX = Math.PI / 6;
|
|
3788
|
+
var TWO_PI = Math.PI * 2;
|