@math.gl/core 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/classes/base/math-array.d.ts +1 -2
  2. package/dist/classes/base/math-array.js +220 -266
  3. package/dist/classes/base/matrix.d.ts +1 -2
  4. package/dist/classes/base/matrix.js +52 -53
  5. package/dist/classes/base/vector.d.ts +1 -2
  6. package/dist/classes/base/vector.js +121 -135
  7. package/dist/classes/euler.d.ts +2 -3
  8. package/dist/classes/euler.js +462 -533
  9. package/dist/classes/matrix3.d.ts +2 -3
  10. package/dist/classes/matrix3.js +185 -190
  11. package/dist/classes/matrix4.d.ts +1 -2
  12. package/dist/classes/matrix4.js +516 -452
  13. package/dist/classes/pose.d.ts +4 -5
  14. package/dist/classes/pose.js +104 -119
  15. package/dist/classes/quaternion.d.ts +1 -2
  16. package/dist/classes/quaternion.js +257 -233
  17. package/dist/classes/spherical-coordinates.d.ts +3 -4
  18. package/dist/classes/spherical-coordinates.js +138 -147
  19. package/dist/classes/vector2.d.ts +1 -2
  20. package/dist/classes/vector2.js +101 -85
  21. package/dist/classes/vector3.d.ts +1 -2
  22. package/dist/classes/vector3.js +125 -136
  23. package/dist/classes/vector4.d.ts +2 -3
  24. package/dist/classes/vector4.js +106 -114
  25. package/dist/gl-matrix/common.d.ts +0 -1
  26. package/dist/gl-matrix/common.js +38 -6
  27. package/dist/gl-matrix/mat3.d.ts +0 -1
  28. package/dist/gl-matrix/mat3.js +699 -425
  29. package/dist/gl-matrix/mat4.d.ts +0 -1
  30. package/dist/gl-matrix/mat4.js +1879 -1339
  31. package/dist/gl-matrix/quat.d.ts +0 -1
  32. package/dist/gl-matrix/quat.js +655 -257
  33. package/dist/gl-matrix/vec2.d.ts +0 -1
  34. package/dist/gl-matrix/vec2.js +529 -212
  35. package/dist/gl-matrix/vec3.d.ts +0 -1
  36. package/dist/gl-matrix/vec3.js +703 -335
  37. package/dist/gl-matrix/vec4.d.ts +0 -1
  38. package/dist/gl-matrix/vec4.js +579 -293
  39. package/dist/gl-matrix/wip/index.d.ts +3 -4
  40. package/dist/gl-matrix/wip/index.js +2 -1
  41. package/dist/gl-matrix/wip/mat2.d.ts +0 -1
  42. package/dist/gl-matrix/wip/mat2.js +333 -157
  43. package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
  44. package/dist/gl-matrix/wip/mat2d.js +377 -202
  45. package/dist/gl-matrix/wip/quat2.d.ts +0 -1
  46. package/dist/gl-matrix/wip/quat2.js +647 -409
  47. package/dist/index.cjs +60 -100
  48. package/dist/index.cjs.map +7 -0
  49. package/dist/index.d.ts +21 -22
  50. package/dist/index.js +23 -16
  51. package/dist/lib/assert.d.ts +0 -1
  52. package/dist/lib/assert.js +3 -4
  53. package/dist/lib/common.d.ts +2 -3
  54. package/dist/lib/common.js +163 -134
  55. package/dist/lib/gl-matrix-extras.d.ts +0 -1
  56. package/dist/lib/gl-matrix-extras.js +39 -36
  57. package/dist/lib/math-utils.d.ts +0 -1
  58. package/dist/lib/math-utils.js +2 -1
  59. package/dist/lib/validators.d.ts +0 -1
  60. package/dist/lib/validators.js +22 -25
  61. package/package.json +5 -6
  62. package/src/classes/matrix3.ts +1 -1
  63. package/dist/classes/base/math-array.d.ts.map +0 -1
  64. package/dist/classes/base/math-array.js.map +0 -1
  65. package/dist/classes/base/matrix.d.ts.map +0 -1
  66. package/dist/classes/base/matrix.js.map +0 -1
  67. package/dist/classes/base/vector.d.ts.map +0 -1
  68. package/dist/classes/base/vector.js.map +0 -1
  69. package/dist/classes/euler.d.ts.map +0 -1
  70. package/dist/classes/euler.js.map +0 -1
  71. package/dist/classes/matrix3.d.ts.map +0 -1
  72. package/dist/classes/matrix3.js.map +0 -1
  73. package/dist/classes/matrix4.d.ts.map +0 -1
  74. package/dist/classes/matrix4.js.map +0 -1
  75. package/dist/classes/pose.d.ts.map +0 -1
  76. package/dist/classes/pose.js.map +0 -1
  77. package/dist/classes/quaternion.d.ts.map +0 -1
  78. package/dist/classes/quaternion.js.map +0 -1
  79. package/dist/classes/spherical-coordinates.d.ts.map +0 -1
  80. package/dist/classes/spherical-coordinates.js.map +0 -1
  81. package/dist/classes/vector2.d.ts.map +0 -1
  82. package/dist/classes/vector2.js.map +0 -1
  83. package/dist/classes/vector3.d.ts.map +0 -1
  84. package/dist/classes/vector3.js.map +0 -1
  85. package/dist/classes/vector4.d.ts.map +0 -1
  86. package/dist/classes/vector4.js.map +0 -1
  87. package/dist/gl-matrix/common.d.ts.map +0 -1
  88. package/dist/gl-matrix/common.js.map +0 -1
  89. package/dist/gl-matrix/mat3.d.ts.map +0 -1
  90. package/dist/gl-matrix/mat3.js.map +0 -1
  91. package/dist/gl-matrix/mat4.d.ts.map +0 -1
  92. package/dist/gl-matrix/mat4.js.map +0 -1
  93. package/dist/gl-matrix/quat.d.ts.map +0 -1
  94. package/dist/gl-matrix/quat.js.map +0 -1
  95. package/dist/gl-matrix/vec2.d.ts.map +0 -1
  96. package/dist/gl-matrix/vec2.js.map +0 -1
  97. package/dist/gl-matrix/vec3.d.ts.map +0 -1
  98. package/dist/gl-matrix/vec3.js.map +0 -1
  99. package/dist/gl-matrix/vec4.d.ts.map +0 -1
  100. package/dist/gl-matrix/vec4.js.map +0 -1
  101. package/dist/gl-matrix/wip/index.d.ts.map +0 -1
  102. package/dist/gl-matrix/wip/index.js.map +0 -1
  103. package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
  104. package/dist/gl-matrix/wip/mat2.js.map +0 -1
  105. package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
  106. package/dist/gl-matrix/wip/mat2d.js.map +0 -1
  107. package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
  108. package/dist/gl-matrix/wip/quat2.js.map +0 -1
  109. package/dist/gl-matrix/wip/types.d.js +0 -2
  110. package/dist/gl-matrix/wip/types.d.js.map +0 -1
  111. package/dist/index.d.ts.map +0 -1
  112. package/dist/index.js.map +0 -1
  113. package/dist/lib/assert.d.ts.map +0 -1
  114. package/dist/lib/assert.js.map +0 -1
  115. package/dist/lib/common.d.ts.map +0 -1
  116. package/dist/lib/common.js.map +0 -1
  117. package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
  118. package/dist/lib/gl-matrix-extras.js.map +0 -1
  119. package/dist/lib/gl-matrix.d.js +0 -2
  120. package/dist/lib/gl-matrix.d.js.map +0 -1
  121. package/dist/lib/math-utils.d.ts.map +0 -1
  122. package/dist/lib/math-utils.js.map +0 -1
  123. package/dist/lib/validators.d.ts.map +0 -1
  124. package/dist/lib/validators.js.map +0 -1
@@ -1,478 +1,542 @@
1
+ // Copyright (c) 2017 Uber Technologies, Inc.
2
+ // MIT License
1
3
  import { Matrix } from "./base/matrix.js";
2
4
  import { checkVector } from "../lib/validators.js";
5
+ /* eslint-disable camelcase */
3
6
  import { vec2_transformMat4AsVector, vec3_transformMat4AsVector } from "../lib/gl-matrix-extras.js";
7
+ // @ts-ignore gl-matrix types...
4
8
  import { fromQuat as mat4_fromQuat, frustum as mat4_frustum, lookAt as mat4_lookAt, ortho as mat4_ortho, perspective as mat4_perspective, determinant as mat4_determinant, transpose as mat4_transpose, invert as mat4_invert, multiply as mat4_multiply, rotateX as mat4_rotateX, rotateY as mat4_rotateY, rotateZ as mat4_rotateZ, rotate as mat4_rotate, scale as mat4_scale, translate as mat4_translate } from "../gl-matrix/mat4.js";
5
9
  import { transformMat4 as vec2_transformMat4 } from "../gl-matrix/vec2.js";
6
10
  import { transformMat4 as vec3_transformMat4 } from "../gl-matrix/vec3.js";
7
11
  import { transformMat4 as vec4_transformMat4 } from "../gl-matrix/vec4.js";
8
12
  var INDICES;
9
-
10
13
  (function (INDICES) {
11
- INDICES[INDICES["COL0ROW0"] = 0] = "COL0ROW0";
12
- INDICES[INDICES["COL0ROW1"] = 1] = "COL0ROW1";
13
- INDICES[INDICES["COL0ROW2"] = 2] = "COL0ROW2";
14
- INDICES[INDICES["COL0ROW3"] = 3] = "COL0ROW3";
15
- INDICES[INDICES["COL1ROW0"] = 4] = "COL1ROW0";
16
- INDICES[INDICES["COL1ROW1"] = 5] = "COL1ROW1";
17
- INDICES[INDICES["COL1ROW2"] = 6] = "COL1ROW2";
18
- INDICES[INDICES["COL1ROW3"] = 7] = "COL1ROW3";
19
- INDICES[INDICES["COL2ROW0"] = 8] = "COL2ROW0";
20
- INDICES[INDICES["COL2ROW1"] = 9] = "COL2ROW1";
21
- INDICES[INDICES["COL2ROW2"] = 10] = "COL2ROW2";
22
- INDICES[INDICES["COL2ROW3"] = 11] = "COL2ROW3";
23
- INDICES[INDICES["COL3ROW0"] = 12] = "COL3ROW0";
24
- INDICES[INDICES["COL3ROW1"] = 13] = "COL3ROW1";
25
- INDICES[INDICES["COL3ROW2"] = 14] = "COL3ROW2";
26
- INDICES[INDICES["COL3ROW3"] = 15] = "COL3ROW3";
14
+ INDICES[INDICES["COL0ROW0"] = 0] = "COL0ROW0";
15
+ INDICES[INDICES["COL0ROW1"] = 1] = "COL0ROW1";
16
+ INDICES[INDICES["COL0ROW2"] = 2] = "COL0ROW2";
17
+ INDICES[INDICES["COL0ROW3"] = 3] = "COL0ROW3";
18
+ INDICES[INDICES["COL1ROW0"] = 4] = "COL1ROW0";
19
+ INDICES[INDICES["COL1ROW1"] = 5] = "COL1ROW1";
20
+ INDICES[INDICES["COL1ROW2"] = 6] = "COL1ROW2";
21
+ INDICES[INDICES["COL1ROW3"] = 7] = "COL1ROW3";
22
+ INDICES[INDICES["COL2ROW0"] = 8] = "COL2ROW0";
23
+ INDICES[INDICES["COL2ROW1"] = 9] = "COL2ROW1";
24
+ INDICES[INDICES["COL2ROW2"] = 10] = "COL2ROW2";
25
+ INDICES[INDICES["COL2ROW3"] = 11] = "COL2ROW3";
26
+ INDICES[INDICES["COL3ROW0"] = 12] = "COL3ROW0";
27
+ INDICES[INDICES["COL3ROW1"] = 13] = "COL3ROW1";
28
+ INDICES[INDICES["COL3ROW2"] = 14] = "COL3ROW2";
29
+ INDICES[INDICES["COL3ROW3"] = 15] = "COL3ROW3";
27
30
  })(INDICES || (INDICES = {}));
28
-
29
- const DEFAULT_FOVY = 45 * Math.PI / 180;
31
+ const DEFAULT_FOVY = (45 * Math.PI) / 180;
30
32
  const DEFAULT_ASPECT = 1;
31
33
  const DEFAULT_NEAR = 0.1;
32
34
  const DEFAULT_FAR = 500;
33
35
  const IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
36
+ /** 4x4 matrix */
34
37
  export class Matrix4 extends Matrix {
35
- static get IDENTITY() {
36
- return getIdentityMatrix();
37
- }
38
-
39
- static get ZERO() {
40
- return getZeroMatrix();
41
- }
42
-
43
- get ELEMENTS() {
44
- return 16;
45
- }
46
-
47
- get RANK() {
48
- return 4;
49
- }
50
-
51
- get INDICES() {
52
- return INDICES;
53
- }
54
-
55
- constructor(array) {
56
- super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
57
-
58
- if (arguments.length === 1 && Array.isArray(array)) {
59
- this.copy(array);
60
- } else {
61
- this.identity();
62
- }
63
- }
64
-
65
- copy(array) {
66
- this[0] = array[0];
67
- this[1] = array[1];
68
- this[2] = array[2];
69
- this[3] = array[3];
70
- this[4] = array[4];
71
- this[5] = array[5];
72
- this[6] = array[6];
73
- this[7] = array[7];
74
- this[8] = array[8];
75
- this[9] = array[9];
76
- this[10] = array[10];
77
- this[11] = array[11];
78
- this[12] = array[12];
79
- this[13] = array[13];
80
- this[14] = array[14];
81
- this[15] = array[15];
82
- return this.check();
83
- }
84
-
85
- set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
86
- this[0] = m00;
87
- this[1] = m10;
88
- this[2] = m20;
89
- this[3] = m30;
90
- this[4] = m01;
91
- this[5] = m11;
92
- this[6] = m21;
93
- this[7] = m31;
94
- this[8] = m02;
95
- this[9] = m12;
96
- this[10] = m22;
97
- this[11] = m32;
98
- this[12] = m03;
99
- this[13] = m13;
100
- this[14] = m23;
101
- this[15] = m33;
102
- return this.check();
103
- }
104
-
105
- setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
106
- this[0] = m00;
107
- this[1] = m10;
108
- this[2] = m20;
109
- this[3] = m30;
110
- this[4] = m01;
111
- this[5] = m11;
112
- this[6] = m21;
113
- this[7] = m31;
114
- this[8] = m02;
115
- this[9] = m12;
116
- this[10] = m22;
117
- this[11] = m32;
118
- this[12] = m03;
119
- this[13] = m13;
120
- this[14] = m23;
121
- this[15] = m33;
122
- return this.check();
123
- }
124
-
125
- toRowMajor(result) {
126
- result[0] = this[0];
127
- result[1] = this[4];
128
- result[2] = this[8];
129
- result[3] = this[12];
130
- result[4] = this[1];
131
- result[5] = this[5];
132
- result[6] = this[9];
133
- result[7] = this[13];
134
- result[8] = this[2];
135
- result[9] = this[6];
136
- result[10] = this[10];
137
- result[11] = this[14];
138
- result[12] = this[3];
139
- result[13] = this[7];
140
- result[14] = this[11];
141
- result[15] = this[15];
142
- return result;
143
- }
144
-
145
- identity() {
146
- return this.copy(IDENTITY_MATRIX);
147
- }
148
-
149
- fromObject(object) {
150
- return this.check();
151
- }
152
-
153
- fromQuaternion(quaternion) {
154
- mat4_fromQuat(this, quaternion);
155
- return this.check();
156
- }
157
-
158
- frustum(view) {
159
- const {
160
- left,
161
- right,
162
- bottom,
163
- top,
164
- near = DEFAULT_NEAR,
165
- far = DEFAULT_FAR
166
- } = view;
167
-
168
- if (far === Infinity) {
169
- computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
170
- } else {
171
- mat4_frustum(this, left, right, bottom, top, near, far);
172
- }
173
-
174
- return this.check();
175
- }
176
-
177
- lookAt(view) {
178
- const {
179
- eye,
180
- center = [0, 0, 0],
181
- up = [0, 1, 0]
182
- } = view;
183
- mat4_lookAt(this, eye, center, up);
184
- return this.check();
185
- }
186
-
187
- ortho(view) {
188
- const {
189
- left,
190
- right,
191
- bottom,
192
- top,
193
- near = DEFAULT_NEAR,
194
- far = DEFAULT_FAR
195
- } = view;
196
- mat4_ortho(this, left, right, bottom, top, near, far);
197
- return this.check();
198
- }
199
-
200
- orthographic(view) {
201
- const {
202
- fovy = DEFAULT_FOVY,
203
- aspect = DEFAULT_ASPECT,
204
- focalDistance = 1,
205
- near = DEFAULT_NEAR,
206
- far = DEFAULT_FAR
207
- } = view;
208
- checkRadians(fovy);
209
- const halfY = fovy / 2;
210
- const top = focalDistance * Math.tan(halfY);
211
- const right = top * aspect;
212
- return this.ortho({
213
- left: -right,
214
- right,
215
- bottom: -top,
216
- top,
217
- near,
218
- far
219
- });
220
- }
221
-
222
- perspective(view) {
223
- const {
224
- fovy = 45 * Math.PI / 180,
225
- aspect = 1,
226
- near = 0.1,
227
- far = 500
228
- } = view;
229
- checkRadians(fovy);
230
- mat4_perspective(this, fovy, aspect, near, far);
231
- return this.check();
232
- }
233
-
234
- determinant() {
235
- return mat4_determinant(this);
236
- }
237
-
238
- getScale(result = [-0, -0, -0]) {
239
- result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
240
- result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
241
- result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
242
- return result;
243
- }
244
-
245
- getTranslation(result = [-0, -0, -0]) {
246
- result[0] = this[12];
247
- result[1] = this[13];
248
- result[2] = this[14];
249
- return result;
250
- }
251
-
252
- getRotation(result, scaleResult) {
253
- result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
254
- scaleResult = scaleResult || [-0, -0, -0];
255
- const scale = this.getScale(scaleResult);
256
- const inverseScale0 = 1 / scale[0];
257
- const inverseScale1 = 1 / scale[1];
258
- const inverseScale2 = 1 / scale[2];
259
- result[0] = this[0] * inverseScale0;
260
- result[1] = this[1] * inverseScale1;
261
- result[2] = this[2] * inverseScale2;
262
- result[3] = 0;
263
- result[4] = this[4] * inverseScale0;
264
- result[5] = this[5] * inverseScale1;
265
- result[6] = this[6] * inverseScale2;
266
- result[7] = 0;
267
- result[8] = this[8] * inverseScale0;
268
- result[9] = this[9] * inverseScale1;
269
- result[10] = this[10] * inverseScale2;
270
- result[11] = 0;
271
- result[12] = 0;
272
- result[13] = 0;
273
- result[14] = 0;
274
- result[15] = 1;
275
- return result;
276
- }
277
-
278
- getRotationMatrix3(result, scaleResult) {
279
- result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
280
- scaleResult = scaleResult || [-0, -0, -0];
281
- const scale = this.getScale(scaleResult);
282
- const inverseScale0 = 1 / scale[0];
283
- const inverseScale1 = 1 / scale[1];
284
- const inverseScale2 = 1 / scale[2];
285
- result[0] = this[0] * inverseScale0;
286
- result[1] = this[1] * inverseScale1;
287
- result[2] = this[2] * inverseScale2;
288
- result[3] = this[4] * inverseScale0;
289
- result[4] = this[5] * inverseScale1;
290
- result[5] = this[6] * inverseScale2;
291
- result[6] = this[8] * inverseScale0;
292
- result[7] = this[9] * inverseScale1;
293
- result[8] = this[10] * inverseScale2;
294
- return result;
295
- }
296
-
297
- transpose() {
298
- mat4_transpose(this, this);
299
- return this.check();
300
- }
301
-
302
- invert() {
303
- mat4_invert(this, this);
304
- return this.check();
305
- }
306
-
307
- multiplyLeft(a) {
308
- mat4_multiply(this, a, this);
309
- return this.check();
310
- }
311
-
312
- multiplyRight(a) {
313
- mat4_multiply(this, this, a);
314
- return this.check();
315
- }
316
-
317
- rotateX(radians) {
318
- mat4_rotateX(this, this, radians);
319
- return this.check();
320
- }
321
-
322
- rotateY(radians) {
323
- mat4_rotateY(this, this, radians);
324
- return this.check();
325
- }
326
-
327
- rotateZ(radians) {
328
- mat4_rotateZ(this, this, radians);
329
- return this.check();
330
- }
331
-
332
- rotateXYZ(angleXYZ) {
333
- return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
334
- }
335
-
336
- rotateAxis(radians, axis) {
337
- mat4_rotate(this, this, radians, axis);
338
- return this.check();
339
- }
340
-
341
- scale(factor) {
342
- mat4_scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
343
- return this.check();
344
- }
345
-
346
- translate(vector) {
347
- mat4_translate(this, this, vector);
348
- return this.check();
349
- }
350
-
351
- transform(vector, result) {
352
- if (vector.length === 4) {
353
- result = vec4_transformMat4(result || [-0, -0, -0, -0], vector, this);
354
- checkVector(result, 4);
355
- return result;
356
- }
357
-
358
- return this.transformAsPoint(vector, result);
359
- }
360
-
361
- transformAsPoint(vector, result) {
362
- const {
363
- length
364
- } = vector;
365
- let out;
366
-
367
- switch (length) {
368
- case 2:
369
- out = vec2_transformMat4(result || [-0, -0], vector, this);
370
- break;
371
-
372
- case 3:
373
- out = vec3_transformMat4(result || [-0, -0, -0], vector, this);
374
- break;
375
-
376
- default:
377
- throw new Error('Illegal vector');
378
- }
379
-
380
- checkVector(out, vector.length);
381
- return out;
382
- }
383
-
384
- transformAsVector(vector, result) {
385
- let out;
386
-
387
- switch (vector.length) {
388
- case 2:
389
- out = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
390
- break;
391
-
392
- case 3:
393
- out = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
394
- break;
395
-
396
- default:
397
- throw new Error('Illegal vector');
398
- }
399
-
400
- checkVector(out, vector.length);
401
- return out;
402
- }
403
-
404
- transformPoint(vector, result) {
405
- return this.transformAsPoint(vector, result);
406
- }
407
-
408
- transformVector(vector, result) {
409
- return this.transformAsPoint(vector, result);
410
- }
411
-
412
- transformDirection(vector, result) {
413
- return this.transformAsVector(vector, result);
414
- }
415
-
416
- makeRotationX(radians) {
417
- return this.identity().rotateX(radians);
418
- }
419
-
420
- makeTranslation(x, y, z) {
421
- return this.identity().translate([x, y, z]);
422
- }
423
-
38
+ static get IDENTITY() {
39
+ return getIdentityMatrix();
40
+ }
41
+ static get ZERO() {
42
+ return getZeroMatrix();
43
+ }
44
+ get ELEMENTS() {
45
+ return 16;
46
+ }
47
+ get RANK() {
48
+ return 4;
49
+ }
50
+ get INDICES() {
51
+ return INDICES;
52
+ }
53
+ constructor(array) {
54
+ // PERF NOTE: initialize elements as double precision numbers
55
+ super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
56
+ if (arguments.length === 1 && Array.isArray(array)) {
57
+ this.copy(array);
58
+ }
59
+ else {
60
+ this.identity();
61
+ }
62
+ }
63
+ copy(array) {
64
+ this[0] = array[0];
65
+ this[1] = array[1];
66
+ this[2] = array[2];
67
+ this[3] = array[3];
68
+ this[4] = array[4];
69
+ this[5] = array[5];
70
+ this[6] = array[6];
71
+ this[7] = array[7];
72
+ this[8] = array[8];
73
+ this[9] = array[9];
74
+ this[10] = array[10];
75
+ this[11] = array[11];
76
+ this[12] = array[12];
77
+ this[13] = array[13];
78
+ this[14] = array[14];
79
+ this[15] = array[15];
80
+ return this.check();
81
+ }
82
+ // eslint-disable-next-line max-params
83
+ set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
84
+ this[0] = m00;
85
+ this[1] = m10;
86
+ this[2] = m20;
87
+ this[3] = m30;
88
+ this[4] = m01;
89
+ this[5] = m11;
90
+ this[6] = m21;
91
+ this[7] = m31;
92
+ this[8] = m02;
93
+ this[9] = m12;
94
+ this[10] = m22;
95
+ this[11] = m32;
96
+ this[12] = m03;
97
+ this[13] = m13;
98
+ this[14] = m23;
99
+ this[15] = m33;
100
+ return this.check();
101
+ }
102
+ // accepts row major order, stores as column major
103
+ // eslint-disable-next-line max-params
104
+ setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
105
+ this[0] = m00;
106
+ this[1] = m10;
107
+ this[2] = m20;
108
+ this[3] = m30;
109
+ this[4] = m01;
110
+ this[5] = m11;
111
+ this[6] = m21;
112
+ this[7] = m31;
113
+ this[8] = m02;
114
+ this[9] = m12;
115
+ this[10] = m22;
116
+ this[11] = m32;
117
+ this[12] = m03;
118
+ this[13] = m13;
119
+ this[14] = m23;
120
+ this[15] = m33;
121
+ return this.check();
122
+ }
123
+ toRowMajor(result) {
124
+ result[0] = this[0];
125
+ result[1] = this[4];
126
+ result[2] = this[8];
127
+ result[3] = this[12];
128
+ result[4] = this[1];
129
+ result[5] = this[5];
130
+ result[6] = this[9];
131
+ result[7] = this[13];
132
+ result[8] = this[2];
133
+ result[9] = this[6];
134
+ result[10] = this[10];
135
+ result[11] = this[14];
136
+ result[12] = this[3];
137
+ result[13] = this[7];
138
+ result[14] = this[11];
139
+ result[15] = this[15];
140
+ return result;
141
+ }
142
+ // Constructors
143
+ /** Set to identity matrix */
144
+ identity() {
145
+ return this.copy(IDENTITY_MATRIX);
146
+ }
147
+ /**
148
+ *
149
+ * @param object
150
+ * @returns self
151
+ */
152
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
153
+ fromObject(object) {
154
+ return this.check();
155
+ }
156
+ /**
157
+ * Calculates a 4x4 matrix from the given quaternion
158
+ * @param quaternion Quaternion to create matrix from
159
+ * @returns self
160
+ */
161
+ fromQuaternion(quaternion) {
162
+ mat4_fromQuat(this, quaternion);
163
+ return this.check();
164
+ }
165
+ /**
166
+ * Generates a frustum matrix with the given bounds
167
+ * @param view.left - Left bound of the frustum
168
+ * @param view.right - Right bound of the frustum
169
+ * @param view.bottom - Bottom bound of the frustum
170
+ * @param view.top - Top bound of the frustum
171
+ * @param view.near - Near bound of the frustum
172
+ * @param view.far - Far bound of the frustum. Can be set to Infinity.
173
+ * @returns self
174
+ */
175
+ frustum(view) {
176
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
177
+ if (far === Infinity) {
178
+ computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
179
+ }
180
+ else {
181
+ mat4_frustum(this, left, right, bottom, top, near, far);
182
+ }
183
+ return this.check();
184
+ }
185
+ /**
186
+ * Generates a look-at matrix with the given eye position, focal point,
187
+ * and up axis
188
+ * @param view.eye - (vector) Position of the viewer
189
+ * @param view.center - (vector) Point the viewer is looking at
190
+ * @param view.up - (vector) Up axis
191
+ * @returns self
192
+ */
193
+ lookAt(view) {
194
+ const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
195
+ mat4_lookAt(this, eye, center, up);
196
+ return this.check();
197
+ }
198
+ /**
199
+ * Generates a orthogonal projection matrix with the given bounds
200
+ * from "traditional" view space parameters
201
+ * @param view.left - Left bound of the frustum
202
+ * @param view.right number Right bound of the frustum
203
+ * @param view.bottom - Bottom bound of the frustum
204
+ * @param view.top number Top bound of the frustum
205
+ * @param view.near - Near bound of the frustum
206
+ * @param view.far number Far bound of the frustum
207
+ * @returns self
208
+ */
209
+ ortho(view) {
210
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
211
+ mat4_ortho(this, left, right, bottom, top, near, far);
212
+ return this.check();
213
+ }
214
+ /**
215
+ * Generates an orthogonal projection matrix with the same parameters
216
+ * as a perspective matrix (plus focalDistance)
217
+ * @param view.fovy Vertical field of view in radians
218
+ * @param view.aspect Aspect ratio. Typically viewport width / viewport height
219
+ * @param view.focalDistance Distance in the view frustum used for extent calculations
220
+ * @param view.near Near bound of the frustum
221
+ * @param view.far Far bound of the frustum
222
+ * @returns self
223
+ */
224
+ orthographic(view) {
225
+ const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
226
+ checkRadians(fovy);
227
+ const halfY = fovy / 2;
228
+ const top = focalDistance * Math.tan(halfY); // focus_plane is the distance from the camera
229
+ const right = top * aspect;
230
+ return this.ortho({
231
+ left: -right,
232
+ right,
233
+ bottom: -top,
234
+ top,
235
+ near,
236
+ far
237
+ });
238
+ }
239
+ /**
240
+ * Generates a perspective projection matrix with the given bounds
241
+ * @param view.fovy Vertical field of view in radians
242
+ * @param view.aspect Aspect ratio. typically viewport width/height
243
+ * @param view.near Near bound of the frustum
244
+ * @param view.far Far bound of the frustum
245
+ * @returns self
246
+ */
247
+ perspective(view) {
248
+ const { fovy = (45 * Math.PI) / 180, aspect = 1, near = 0.1, far = 500 } = view;
249
+ checkRadians(fovy);
250
+ mat4_perspective(this, fovy, aspect, near, far);
251
+ return this.check();
252
+ }
253
+ // Accessors
254
+ determinant() {
255
+ return mat4_determinant(this);
256
+ }
257
+ /**
258
+ * Extracts the non-uniform scale assuming the matrix is an affine transformation.
259
+ * The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
260
+ * @param result
261
+ * @returns self
262
+ */
263
+ getScale(result = [-0, -0, -0]) {
264
+ // explicit is faster than hypot...
265
+ result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
266
+ result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
267
+ result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
268
+ // result[0] = Math.hypot(this[0], this[1], this[2]);
269
+ // result[1] = Math.hypot(this[4], this[5], this[6]);
270
+ // result[2] = Math.hypot(this[8], this[9], this[10]);
271
+ return result;
272
+ }
273
+ /**
274
+ * Gets the translation portion, assuming the matrix is a affine transformation matrix.
275
+ * @param result
276
+ * @returns self
277
+ */
278
+ getTranslation(result = [-0, -0, -0]) {
279
+ result[0] = this[12];
280
+ result[1] = this[13];
281
+ result[2] = this[14];
282
+ return result;
283
+ }
284
+ /**
285
+ * Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
286
+ * @param result
287
+ * @param scaleResult
288
+ * @returns self
289
+ */
290
+ getRotation(result, scaleResult) {
291
+ result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
292
+ scaleResult = scaleResult || [-0, -0, -0];
293
+ const scale = this.getScale(scaleResult);
294
+ const inverseScale0 = 1 / scale[0];
295
+ const inverseScale1 = 1 / scale[1];
296
+ const inverseScale2 = 1 / scale[2];
297
+ result[0] = this[0] * inverseScale0;
298
+ result[1] = this[1] * inverseScale1;
299
+ result[2] = this[2] * inverseScale2;
300
+ result[3] = 0;
301
+ result[4] = this[4] * inverseScale0;
302
+ result[5] = this[5] * inverseScale1;
303
+ result[6] = this[6] * inverseScale2;
304
+ result[7] = 0;
305
+ result[8] = this[8] * inverseScale0;
306
+ result[9] = this[9] * inverseScale1;
307
+ result[10] = this[10] * inverseScale2;
308
+ result[11] = 0;
309
+ result[12] = 0;
310
+ result[13] = 0;
311
+ result[14] = 0;
312
+ result[15] = 1;
313
+ return result;
314
+ }
315
+ /**
316
+ *
317
+ * @param result
318
+ * @param scaleResult
319
+ * @returns self
320
+ */
321
+ getRotationMatrix3(result, scaleResult) {
322
+ result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
323
+ scaleResult = scaleResult || [-0, -0, -0];
324
+ const scale = this.getScale(scaleResult);
325
+ const inverseScale0 = 1 / scale[0];
326
+ const inverseScale1 = 1 / scale[1];
327
+ const inverseScale2 = 1 / scale[2];
328
+ result[0] = this[0] * inverseScale0;
329
+ result[1] = this[1] * inverseScale1;
330
+ result[2] = this[2] * inverseScale2;
331
+ result[3] = this[4] * inverseScale0;
332
+ result[4] = this[5] * inverseScale1;
333
+ result[5] = this[6] * inverseScale2;
334
+ result[6] = this[8] * inverseScale0;
335
+ result[7] = this[9] * inverseScale1;
336
+ result[8] = this[10] * inverseScale2;
337
+ return result;
338
+ }
339
+ // Modifiers
340
+ transpose() {
341
+ mat4_transpose(this, this);
342
+ return this.check();
343
+ }
344
+ invert() {
345
+ mat4_invert(this, this);
346
+ return this.check();
347
+ }
348
+ // Operations
349
+ multiplyLeft(a) {
350
+ mat4_multiply(this, a, this);
351
+ return this.check();
352
+ }
353
+ multiplyRight(a) {
354
+ mat4_multiply(this, this, a);
355
+ return this.check();
356
+ }
357
+ // Rotates a matrix by the given angle around the X axis
358
+ rotateX(radians) {
359
+ mat4_rotateX(this, this, radians);
360
+ // mat4_rotate(this, this, radians, [1, 0, 0]);
361
+ return this.check();
362
+ }
363
+ // Rotates a matrix by the given angle around the Y axis.
364
+ rotateY(radians) {
365
+ mat4_rotateY(this, this, radians);
366
+ // mat4_rotate(this, this, radians, [0, 1, 0]);
367
+ return this.check();
368
+ }
369
+ /**
370
+ * Rotates a matrix by the given angle around the Z axis.
371
+ * @param radians
372
+ * @returns self
373
+ */
374
+ rotateZ(radians) {
375
+ mat4_rotateZ(this, this, radians);
376
+ // mat4_rotate(this, this, radians, [0, 0, 1]);
377
+ return this.check();
378
+ }
379
+ /**
380
+ *
381
+ * @param param0
382
+ * @returns self
383
+ */
384
+ rotateXYZ(angleXYZ) {
385
+ return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
386
+ }
387
+ /**
388
+ *
389
+ * @param radians
390
+ * @param axis
391
+ * @returns self
392
+ */
393
+ rotateAxis(radians, axis) {
394
+ mat4_rotate(this, this, radians, axis);
395
+ return this.check();
396
+ }
397
+ /**
398
+ *
399
+ * @param factor
400
+ * @returns self
401
+ */
402
+ scale(factor) {
403
+ mat4_scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
404
+ return this.check();
405
+ }
406
+ /**
407
+ *
408
+ * @param vec
409
+ * @returns self
410
+ */
411
+ translate(vector) {
412
+ mat4_translate(this, this, vector);
413
+ return this.check();
414
+ }
415
+ // Transforms
416
+ /**
417
+ * Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
418
+ * @param vector
419
+ * @param result
420
+ * @returns self
421
+ */
422
+ transform(vector, result) {
423
+ if (vector.length === 4) {
424
+ result = vec4_transformMat4(result || [-0, -0, -0, -0], vector, this);
425
+ checkVector(result, 4);
426
+ return result;
427
+ }
428
+ return this.transformAsPoint(vector, result);
429
+ }
430
+ /**
431
+ * Transforms any 2 or 3 element array as point (w implicitly 1)
432
+ * @param vector
433
+ * @param result
434
+ * @returns self
435
+ */
436
+ transformAsPoint(vector, result) {
437
+ const { length } = vector;
438
+ let out;
439
+ switch (length) {
440
+ case 2:
441
+ out = vec2_transformMat4(result || [-0, -0], vector, this);
442
+ break;
443
+ case 3:
444
+ out = vec3_transformMat4(result || [-0, -0, -0], vector, this);
445
+ break;
446
+ default:
447
+ throw new Error('Illegal vector');
448
+ }
449
+ checkVector(out, vector.length);
450
+ return out;
451
+ }
452
+ /**
453
+ * Transforms any 2 or 3 element array as vector (w implicitly 0)
454
+ * @param vector
455
+ * @param result
456
+ * @returns self
457
+ */
458
+ transformAsVector(vector, result) {
459
+ let out;
460
+ switch (vector.length) {
461
+ case 2:
462
+ out = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
463
+ break;
464
+ case 3:
465
+ out = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
466
+ break;
467
+ default:
468
+ throw new Error('Illegal vector');
469
+ }
470
+ checkVector(out, vector.length);
471
+ return out;
472
+ }
473
+ /** @deprecated */
474
+ transformPoint(vector, result) {
475
+ return this.transformAsPoint(vector, result);
476
+ }
477
+ /** @deprecated */
478
+ transformVector(vector, result) {
479
+ return this.transformAsPoint(vector, result);
480
+ }
481
+ /** @deprecated */
482
+ transformDirection(vector, result) {
483
+ return this.transformAsVector(vector, result);
484
+ }
485
+ // three.js math API compatibility
486
+ makeRotationX(radians) {
487
+ return this.identity().rotateX(radians);
488
+ }
489
+ makeTranslation(x, y, z) {
490
+ return this.identity().translate([x, y, z]);
491
+ }
424
492
  }
493
+ // TODO initializing static members directly is an option, but make sure no tree-shaking issues
425
494
  let ZERO;
426
495
  let IDENTITY;
427
-
428
496
  function getZeroMatrix() {
429
- if (!ZERO) {
430
- ZERO = new Matrix4([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
431
- Object.freeze(ZERO);
432
- }
433
-
434
- return ZERO;
497
+ if (!ZERO) {
498
+ ZERO = new Matrix4([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
499
+ Object.freeze(ZERO);
500
+ }
501
+ return ZERO;
435
502
  }
436
-
437
503
  function getIdentityMatrix() {
438
- if (!IDENTITY) {
439
- IDENTITY = new Matrix4();
440
- Object.freeze(IDENTITY);
441
- }
442
-
443
- return IDENTITY;
504
+ if (!IDENTITY) {
505
+ IDENTITY = new Matrix4();
506
+ Object.freeze(IDENTITY);
507
+ }
508
+ return IDENTITY;
444
509
  }
445
-
510
+ // HELPER FUNCTIONS
446
511
  function checkRadians(possiblyDegrees) {
447
- if (possiblyDegrees > Math.PI * 2) {
448
- throw Error('expected radians');
449
- }
512
+ if (possiblyDegrees > Math.PI * 2) {
513
+ throw Error('expected radians');
514
+ }
450
515
  }
451
-
516
+ // eslint-disable-next-line max-params
452
517
  function computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
453
- const column0Row0 = 2 * near / (right - left);
454
- const column1Row1 = 2 * near / (top - bottom);
455
- const column2Row0 = (right + left) / (right - left);
456
- const column2Row1 = (top + bottom) / (top - bottom);
457
- const column2Row2 = -1;
458
- const column2Row3 = -1;
459
- const column3Row2 = -2 * near;
460
- result[0] = column0Row0;
461
- result[1] = 0;
462
- result[2] = 0;
463
- result[3] = 0;
464
- result[4] = 0;
465
- result[5] = column1Row1;
466
- result[6] = 0;
467
- result[7] = 0;
468
- result[8] = column2Row0;
469
- result[9] = column2Row1;
470
- result[10] = column2Row2;
471
- result[11] = column2Row3;
472
- result[12] = 0;
473
- result[13] = 0;
474
- result[14] = column3Row2;
475
- result[15] = 0;
476
- return result;
518
+ const column0Row0 = (2 * near) / (right - left);
519
+ const column1Row1 = (2 * near) / (top - bottom);
520
+ const column2Row0 = (right + left) / (right - left);
521
+ const column2Row1 = (top + bottom) / (top - bottom);
522
+ const column2Row2 = -1;
523
+ const column2Row3 = -1;
524
+ const column3Row2 = -2 * near;
525
+ result[0] = column0Row0;
526
+ result[1] = 0;
527
+ result[2] = 0;
528
+ result[3] = 0;
529
+ result[4] = 0;
530
+ result[5] = column1Row1;
531
+ result[6] = 0;
532
+ result[7] = 0;
533
+ result[8] = column2Row0;
534
+ result[9] = column2Row1;
535
+ result[10] = column2Row2;
536
+ result[11] = column2Row3;
537
+ result[12] = 0;
538
+ result[13] = 0;
539
+ result[14] = column3Row2;
540
+ result[15] = 0;
541
+ return result;
477
542
  }
478
- //# sourceMappingURL=matrix4.js.map