@galacean/engine-math 0.9.0-beta.80

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.
@@ -0,0 +1,4813 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Defines how the bounding volumes intersects or contain one another.
7
+ */ exports.ContainmentType = void 0;
8
+ (function(ContainmentType) {
9
+ ContainmentType[ContainmentType[/** Indicates that there is no overlap between two bounding volumes. */ "Disjoint"] = 0] = "Disjoint";
10
+ ContainmentType[ContainmentType[/** Indicates that one bounding volume completely contains another volume. */ "Contains"] = 1] = "Contains";
11
+ ContainmentType[ContainmentType[/** Indicates that bounding volumes partially overlap one another. */ "Intersects"] = 2] = "Intersects";
12
+ })(exports.ContainmentType || (exports.ContainmentType = {}));
13
+
14
+ /**
15
+ * Defines the intersection between a plane and a bounding volume.
16
+ */ exports.PlaneIntersectionType = void 0;
17
+ (function(PlaneIntersectionType) {
18
+ PlaneIntersectionType[PlaneIntersectionType[/** There is no intersection, the bounding volume is in the back of the plane. */ "Back"] = 0] = "Back";
19
+ PlaneIntersectionType[PlaneIntersectionType[/** There is no intersection, the bounding volume is in the front of the plane. */ "Front"] = 1] = "Front";
20
+ PlaneIntersectionType[PlaneIntersectionType[/** The plane is intersected. */ "Intersecting"] = 2] = "Intersecting";
21
+ })(exports.PlaneIntersectionType || (exports.PlaneIntersectionType = {}));
22
+
23
+ /**
24
+ * Frustum face
25
+ */ exports.FrustumFace = void 0;
26
+ (function(FrustumFace) {
27
+ FrustumFace[FrustumFace[/** Near face */ "Near"] = 0] = "Near";
28
+ FrustumFace[FrustumFace[/** Far face */ "Far"] = 1] = "Far";
29
+ FrustumFace[FrustumFace[/** Left face */ "Left"] = 2] = "Left";
30
+ FrustumFace[FrustumFace[/** Right face */ "Right"] = 3] = "Right";
31
+ FrustumFace[FrustumFace[/** Bottom face */ "Bottom"] = 4] = "Bottom";
32
+ FrustumFace[FrustumFace[/** Top face */ "Top"] = 5] = "Top";
33
+ })(exports.FrustumFace || (exports.FrustumFace = {}));
34
+
35
+ function _defineProperties(target, props) {
36
+ for (var i = 0; i < props.length; i++) {
37
+ var descriptor = props[i];
38
+ descriptor.enumerable = descriptor.enumerable || false;
39
+ descriptor.configurable = true;
40
+ if ("value" in descriptor) descriptor.writable = true;
41
+ Object.defineProperty(target, descriptor.key, descriptor);
42
+ }
43
+ }
44
+
45
+ function _createClass(Constructor, protoProps, staticProps) {
46
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
47
+ if (staticProps) _defineProperties(Constructor, staticProps);
48
+ return Constructor;
49
+ }
50
+
51
+ /**
52
+ * Common utility methods for math operations.
53
+ */ var MathUtil = /*#__PURE__*/ function() {
54
+ function MathUtil() {}
55
+ /**
56
+ * Clamps the specified value.
57
+ * @param v - The specified value
58
+ * @param min - The min value
59
+ * @param max - The max value
60
+ * @returns The result of clamping a value between min and max
61
+ */ MathUtil.clamp = function clamp(v, min, max) {
62
+ return Math.max(min, Math.min(max, v));
63
+ };
64
+ /**
65
+ * Checks if a and b are almost equals.
66
+ * The absolute value of the difference between a and b is close to zero.
67
+ * @param a - The left value to compare
68
+ * @param b - The right value to compare
69
+ * @returns True if a almost equal to b, false otherwise
70
+ */ MathUtil.equals = function equals(a, b) {
71
+ return Math.abs(a - b) <= MathUtil.zeroTolerance;
72
+ };
73
+ /**
74
+ * Determines whether the specified v is pow2.
75
+ * @param v - The specified v
76
+ * @returns True if the specified v is pow2, false otherwise
77
+ */ MathUtil.isPowerOf2 = function isPowerOf2(v) {
78
+ return (v & v - 1) === 0;
79
+ };
80
+ /**
81
+ * Modify the specified r from radian to degree.
82
+ * @param r - The specified r
83
+ * @returns The degree value
84
+ */ MathUtil.radianToDegree = function radianToDegree(r) {
85
+ return r * MathUtil.radToDegreeFactor;
86
+ };
87
+ /**
88
+ * Modify the specified d from degree to radian.
89
+ * @param d - The specified d
90
+ * @returns The radian value
91
+ */ MathUtil.degreeToRadian = function degreeToRadian(d) {
92
+ return d * MathUtil.degreeToRadFactor;
93
+ };
94
+ return MathUtil;
95
+ }();
96
+ /** The value for which all absolute numbers smaller than are considered equal to zero. */ MathUtil.zeroTolerance = 1e-6;
97
+ /** The conversion factor that radian to degree. */ MathUtil.radToDegreeFactor = 180 / Math.PI;
98
+ /** The conversion factor that degree to radian. */ MathUtil.degreeToRadFactor = Math.PI / 180;
99
+
100
+ /**
101
+ * Describes a 3D-vector.
102
+ */ var Vector3 = /*#__PURE__*/ function() {
103
+ function Vector3(x, y, z) {
104
+ if (x === void 0) x = 0;
105
+ if (y === void 0) y = 0;
106
+ if (z === void 0) z = 0;
107
+ /** @internal */ this._onValueChanged = null;
108
+ this._x = x;
109
+ this._y = y;
110
+ this._z = z;
111
+ }
112
+ var _proto = Vector3.prototype;
113
+ /**
114
+ * Set the value of this vector.
115
+ * @param x - The x component of the vector
116
+ * @param y - The y component of the vector
117
+ * @param z - The z component of the vector
118
+ * @returns This vector
119
+ */ _proto.set = function set(x, y, z) {
120
+ this._x = x;
121
+ this._y = y;
122
+ this._z = z;
123
+ this._onValueChanged && this._onValueChanged();
124
+ return this;
125
+ };
126
+ /**
127
+ * Determines the sum of this vector and the specified vector.
128
+ * @param right - The specified vector
129
+ * @returns This vector
130
+ */ _proto.add = function add(right) {
131
+ this._x += right._x;
132
+ this._y += right._y;
133
+ this._z += right._z;
134
+ this._onValueChanged && this._onValueChanged();
135
+ return this;
136
+ };
137
+ /**
138
+ * Determines the difference of this vector and the specified vector.
139
+ * @param right - The specified vector
140
+ * @returns This vector
141
+ */ _proto.subtract = function subtract(right) {
142
+ this._x -= right._x;
143
+ this._y -= right._y;
144
+ this._z -= right._z;
145
+ this._onValueChanged && this._onValueChanged();
146
+ return this;
147
+ };
148
+ /**
149
+ * Determines the product of this vector and the specified vector.
150
+ * @param right - The specified vector
151
+ * @returns This vector
152
+ */ _proto.multiply = function multiply(right) {
153
+ this._x *= right._x;
154
+ this._y *= right._y;
155
+ this._z *= right._z;
156
+ this._onValueChanged && this._onValueChanged();
157
+ return this;
158
+ };
159
+ /**
160
+ * Determines the divisor of this vector and the specified vector.
161
+ * @param right - The specified vector
162
+ * @returns This vector
163
+ */ _proto.divide = function divide(right) {
164
+ this._x /= right._x;
165
+ this._y /= right._y;
166
+ this._z /= right._z;
167
+ this._onValueChanged && this._onValueChanged();
168
+ return this;
169
+ };
170
+ /**
171
+ * Calculate the length of this vector.
172
+ * @returns The length of this vector
173
+ */ _proto.length = function length() {
174
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z;
175
+ return Math.sqrt(_x * _x + _y * _y + _z * _z);
176
+ };
177
+ /**
178
+ * Calculate the squared length of this vector.
179
+ * @returns The squared length of this vector
180
+ */ _proto.lengthSquared = function lengthSquared() {
181
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z;
182
+ return _x * _x + _y * _y + _z * _z;
183
+ };
184
+ /**
185
+ * Reverses the direction of this vector.
186
+ * @returns This vector
187
+ */ _proto.negate = function negate() {
188
+ this._x = -this._x;
189
+ this._y = -this._y;
190
+ this._z = -this._z;
191
+ this._onValueChanged && this._onValueChanged();
192
+ return this;
193
+ };
194
+ /**
195
+ * Converts this vector into a unit vector.
196
+ * @returns This vector
197
+ */ _proto.normalize = function normalize() {
198
+ Vector3.normalize(this, this);
199
+ return this;
200
+ };
201
+ /**
202
+ * Scale this vector by the given value.
203
+ * @param s - The amount by which to scale the vector
204
+ * @returns This vector
205
+ */ _proto.scale = function scale(s) {
206
+ this._x *= s;
207
+ this._y *= s;
208
+ this._z *= s;
209
+ this._onValueChanged && this._onValueChanged();
210
+ return this;
211
+ };
212
+ /**
213
+ * This vector performs a normal transformation using the given 4x4 matrix.
214
+ * @remarks
215
+ * A normal transform performs the transformation with the assumption that the w component
216
+ * is zero. This causes the fourth row and fourth column of the matrix to be unused. The
217
+ * end result is a vector that is not translated, but all other transformation properties
218
+ * apply. This is often preferred for normal vectors as normals purely represent direction
219
+ * rather than location because normal vectors should not be translated.
220
+ * @param m - The transform matrix
221
+ * @returns This vector
222
+ */ _proto.transformNormal = function transformNormal(m) {
223
+ Vector3.transformNormal(this, m, this);
224
+ return this;
225
+ };
226
+ /**
227
+ * This vector performs a transformation using the given 4x4 matrix.
228
+ * @param m - The transform matrix
229
+ * @returns This vector
230
+ */ _proto.transformToVec3 = function transformToVec3(m) {
231
+ Vector3.transformToVec3(this, m, this);
232
+ return this;
233
+ };
234
+ /**
235
+ * This vector performs a coordinate transformation using the given 4x4 matrix.
236
+ * @remarks
237
+ * A coordinate transform performs the transformation with the assumption that the w component
238
+ * is one. The four dimensional vector obtained from the transformation operation has each
239
+ * component in the vector divided by the w component. This forces the w-component to be one and
240
+ * therefore makes the vector homogeneous. The homogeneous vector is often preferred when working
241
+ * with coordinates as the w component can safely be ignored.
242
+ * @param m - The transform matrix
243
+ * @returns This vector
244
+ */ _proto.transformCoordinate = function transformCoordinate(m) {
245
+ Vector3.transformCoordinate(this, m, this);
246
+ return this;
247
+ };
248
+ /**
249
+ * This vector performs a transformation using the given quaternion.
250
+ * @param quaternion - The transform quaternion
251
+ * @returns This vector
252
+ */ _proto.transformByQuat = function transformByQuat(quaternion) {
253
+ Vector3.transformByQuat(this, quaternion, this);
254
+ return this;
255
+ };
256
+ /**
257
+ * Creates a clone of this vector.
258
+ * @returns A clone of this vector
259
+ */ _proto.clone = function clone() {
260
+ return new Vector3(this._x, this._y, this._z);
261
+ };
262
+ /**
263
+ * Copy from vector3 like object.
264
+ * @param source - Vector3 like object.
265
+ * @returns This vector
266
+ */ _proto.copyFrom = function copyFrom(source) {
267
+ this._x = source.x;
268
+ this._y = source.y;
269
+ this._z = source.z;
270
+ this._onValueChanged && this._onValueChanged();
271
+ return this;
272
+ };
273
+ /**
274
+ * Copy the value of this vector from an array.
275
+ * @param array - The array
276
+ * @param offset - The start offset of the array
277
+ * @returns This vector
278
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
279
+ if (offset === void 0) offset = 0;
280
+ this._x = array[offset];
281
+ this._y = array[offset + 1];
282
+ this._z = array[offset + 2];
283
+ this._onValueChanged && this._onValueChanged();
284
+ return this;
285
+ };
286
+ /**
287
+ * Copy the value of this vector to an array.
288
+ * @param out - The array
289
+ * @param outOffset - The start offset of the array
290
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
291
+ if (outOffset === void 0) outOffset = 0;
292
+ out[outOffset] = this._x;
293
+ out[outOffset + 1] = this._y;
294
+ out[outOffset + 2] = this._z;
295
+ };
296
+ /**
297
+ * Serialize this vector to a JSON representation.
298
+ * @returns A JSON representation of this vector
299
+ */ _proto.toJSON = function toJSON() {
300
+ return {
301
+ x: this._x,
302
+ y: this._y,
303
+ z: this._z
304
+ };
305
+ };
306
+ /**
307
+ * Determines the sum of two vectors.
308
+ * @param left - The first vector to add
309
+ * @param right - The second vector to add
310
+ * @param out - The sum of two vectors
311
+ */ Vector3.add = function add(left, right, out) {
312
+ out._x = left._x + right._x;
313
+ out._y = left._y + right._y;
314
+ out._z = left._z + right._z;
315
+ out._onValueChanged && out._onValueChanged();
316
+ };
317
+ /**
318
+ * Determines the difference between two vectors.
319
+ * @param left - The first vector to subtract
320
+ * @param right - The second vector to subtract
321
+ * @param out - The difference between two vectors
322
+ */ Vector3.subtract = function subtract(left, right, out) {
323
+ out._x = left._x - right._x;
324
+ out._y = left._y - right._y;
325
+ out._z = left._z - right._z;
326
+ out._onValueChanged && out._onValueChanged();
327
+ };
328
+ /**
329
+ * Determines the product of two vectors.
330
+ * @param left - The first vector to multiply
331
+ * @param right - The second vector to multiply
332
+ * @param out - The product of two vectors
333
+ */ Vector3.multiply = function multiply(left, right, out) {
334
+ out._x = left._x * right._x;
335
+ out._y = left._y * right._y;
336
+ out._z = left._z * right._z;
337
+ out._onValueChanged && out._onValueChanged();
338
+ };
339
+ /**
340
+ * Determines the divisor of two vectors.
341
+ * @param left - The first vector to divide
342
+ * @param right - The second vector to divide
343
+ * @param out - The divisor of two vectors
344
+ */ Vector3.divide = function divide(left, right, out) {
345
+ out._x = left._x / right._x;
346
+ out._y = left._y / right._y;
347
+ out._z = left._z / right._z;
348
+ out._onValueChanged && out._onValueChanged();
349
+ };
350
+ /**
351
+ * Determines the dot product of two vectors.
352
+ * @param left - The first vector to dot
353
+ * @param right - The second vector to dot
354
+ * @returns The dot product of two vectors
355
+ */ Vector3.dot = function dot(left, right) {
356
+ return left._x * right._x + left._y * right._y + left._z * right._z;
357
+ };
358
+ /**
359
+ * Determines the cross product of two vectors.
360
+ * @param left - The first vector to cross
361
+ * @param right - The second vector to cross
362
+ * @param out - The cross product of two vectors
363
+ */ Vector3.cross = function cross(left, right, out) {
364
+ var ax = left._x;
365
+ var ay = left._y;
366
+ var az = left._z;
367
+ var bx = right._x;
368
+ var by = right._y;
369
+ var bz = right._z;
370
+ out.set(ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx);
371
+ };
372
+ /**
373
+ * Determines the distance of two vectors.
374
+ * @param a - The first vector
375
+ * @param b - The second vector
376
+ * @returns The distance of two vectors
377
+ */ Vector3.distance = function distance(a, b) {
378
+ var x = b._x - a._x;
379
+ var y = b._y - a._y;
380
+ var z = b._z - a._z;
381
+ return Math.sqrt(x * x + y * y + z * z);
382
+ };
383
+ /**
384
+ * Determines the squared distance of two vectors.
385
+ * @param a - The first vector
386
+ * @param b - The second vector
387
+ * @returns The squared distance of two vectors
388
+ */ Vector3.distanceSquared = function distanceSquared(a, b) {
389
+ var x = b._x - a._x;
390
+ var y = b._y - a._y;
391
+ var z = b._z - a._z;
392
+ return x * x + y * y + z * z;
393
+ };
394
+ /**
395
+ * Determines whether the specified vectors are equals.
396
+ * @param left - The first vector to compare
397
+ * @param right - The second vector to compare
398
+ * @returns True if the specified vectors are equals, false otherwise
399
+ */ Vector3.equals = function equals(left, right) {
400
+ return MathUtil.equals(left._x, right._x) && MathUtil.equals(left._y, right._y) && MathUtil.equals(left._z, right._z);
401
+ };
402
+ /**
403
+ * Performs a linear interpolation between two vectors.
404
+ * @param start - The first vector
405
+ * @param end - The second vector
406
+ * @param t - The blend amount where 0 returns start and 1 end
407
+ * @param out - The result of linear blending between two vectors
408
+ */ Vector3.lerp = function lerp(start, end, t, out) {
409
+ var _x = start._x, _y = start._y, _z = start._z;
410
+ out._x = _x + (end._x - _x) * t;
411
+ out._y = _y + (end._y - _y) * t;
412
+ out._z = _z + (end._z - _z) * t;
413
+ out._onValueChanged && out._onValueChanged();
414
+ };
415
+ /**
416
+ * Calculate a vector containing the largest components of the specified vectors.
417
+ * @param left - The first vector
418
+ * @param right - The second vector
419
+ * @param out - The vector containing the largest components of the specified vectors
420
+ */ Vector3.max = function max(left, right, out) {
421
+ out._x = Math.max(left._x, right._x);
422
+ out._y = Math.max(left._y, right._y);
423
+ out._z = Math.max(left._z, right._z);
424
+ out._onValueChanged && out._onValueChanged();
425
+ };
426
+ /**
427
+ * Calculate a vector containing the smallest components of the specified vectors.
428
+ * @param left - The first vector
429
+ * @param right - The second vector
430
+ * @param out - The vector containing the smallest components of the specified vectors
431
+ */ Vector3.min = function min(left, right, out) {
432
+ out._x = Math.min(left._x, right._x);
433
+ out._y = Math.min(left._y, right._y);
434
+ out._z = Math.min(left._z, right._z);
435
+ out._onValueChanged && out._onValueChanged();
436
+ };
437
+ /**
438
+ * Reverses the direction of a given vector.
439
+ * @param a - The vector to negate
440
+ * @param out - The vector facing in the opposite direction
441
+ */ Vector3.negate = function negate(a, out) {
442
+ out._x = -a._x;
443
+ out._y = -a._y;
444
+ out._z = -a._z;
445
+ out._onValueChanged && out._onValueChanged();
446
+ };
447
+ /**
448
+ * Converts the vector into a unit vector.
449
+ * @param a - The vector to normalize
450
+ * @param out - The normalized vector
451
+ */ Vector3.normalize = function normalize(a, out) {
452
+ var _x = a._x, _y = a._y, _z = a._z;
453
+ var len = Math.sqrt(_x * _x + _y * _y + _z * _z);
454
+ if (len > MathUtil.zeroTolerance) {
455
+ len = 1 / len;
456
+ out.set(_x * len, _y * len, _z * len);
457
+ }
458
+ };
459
+ /**
460
+ * Scale a vector by the given value.
461
+ * @param a - The vector to scale
462
+ * @param s - The amount by which to scale the vector
463
+ * @param out - The scaled vector
464
+ */ Vector3.scale = function scale(a, s, out) {
465
+ out._x = a._x * s;
466
+ out._y = a._y * s;
467
+ out._z = a._z * s;
468
+ out._onValueChanged && out._onValueChanged();
469
+ };
470
+ /**
471
+ * Performs a normal transformation using the given 4x4 matrix.
472
+ * @remarks
473
+ * A normal transform performs the transformation with the assumption that the w component
474
+ * is zero. This causes the fourth row and fourth column of the matrix to be unused. The
475
+ * end result is a vector that is not translated, but all other transformation properties
476
+ * apply. This is often preferred for normal vectors as normals purely represent direction
477
+ * rather than location because normal vectors should not be translated.
478
+ * @param v - The normal vector to transform
479
+ * @param m - The transform matrix
480
+ * @param out - The transformed normal
481
+ */ Vector3.transformNormal = function transformNormal(v, m, out) {
482
+ var _x = v._x, _y = v._y, _z = v._z;
483
+ var e = m.elements;
484
+ out._x = _x * e[0] + _y * e[4] + _z * e[8];
485
+ out._y = _x * e[1] + _y * e[5] + _z * e[9];
486
+ out._z = _x * e[2] + _y * e[6] + _z * e[10];
487
+ out._onValueChanged && out._onValueChanged();
488
+ };
489
+ /**
490
+ * Performs a transformation using the given 4x4 matrix.
491
+ * @param v - The vector to transform
492
+ * @param m - The transform matrix
493
+ * @param out - The transformed vector3
494
+ */ Vector3.transformToVec3 = function transformToVec3(v, m, out) {
495
+ var _x = v._x, _y = v._y, _z = v._z;
496
+ var e = m.elements;
497
+ out._x = _x * e[0] + _y * e[4] + _z * e[8] + e[12];
498
+ out._y = _x * e[1] + _y * e[5] + _z * e[9] + e[13];
499
+ out._z = _x * e[2] + _y * e[6] + _z * e[10] + e[14];
500
+ out._onValueChanged && out._onValueChanged();
501
+ };
502
+ /**
503
+ * Performs a transformation from vector3 to vector4 using the given 4x4 matrix.
504
+ * @param v - The vector to transform
505
+ * @param m - The transform matrix
506
+ * @param out - The transformed vector4
507
+ */ Vector3.transformToVec4 = function transformToVec4(v, m, out) {
508
+ var _x = v._x, _y = v._y, _z = v._z;
509
+ var e = m.elements;
510
+ out._x = _x * e[0] + _y * e[4] + _z * e[8] + e[12];
511
+ out._y = _x * e[1] + _y * e[5] + _z * e[9] + e[13];
512
+ out._z = _x * e[2] + _y * e[6] + _z * e[10] + e[14];
513
+ out._w = _x * e[3] + _y * e[7] + _z * e[11] + e[15];
514
+ out._onValueChanged && out._onValueChanged();
515
+ };
516
+ /**
517
+ * Performs a coordinate transformation using the given 4x4 matrix.
518
+ *
519
+ * @remarks
520
+ * A coordinate transform performs the transformation with the assumption that the w component
521
+ * is one. The four dimensional vector obtained from the transformation operation has each
522
+ * component in the vector divided by the w component. This forces the w-component to be one and
523
+ * therefore makes the vector homogeneous. The homogeneous vector is often preferred when working
524
+ * with coordinates as the w component can safely be ignored.
525
+ * @param v - The coordinate vector to transform
526
+ * @param m - The transform matrix
527
+ * @param out - The transformed coordinates
528
+ */ Vector3.transformCoordinate = function transformCoordinate(v, m, out) {
529
+ var _x = v._x, _y = v._y, _z = v._z;
530
+ var e = m.elements;
531
+ var w = _x * e[3] + _y * e[7] + _z * e[11] + e[15];
532
+ w = 1.0 / w;
533
+ out._x = (_x * e[0] + _y * e[4] + _z * e[8] + e[12]) * w;
534
+ out._y = (_x * e[1] + _y * e[5] + _z * e[9] + e[13]) * w;
535
+ out._z = (_x * e[2] + _y * e[6] + _z * e[10] + e[14]) * w;
536
+ out._onValueChanged && out._onValueChanged();
537
+ };
538
+ /**
539
+ * Performs a transformation using the given quaternion.
540
+ * @param v - The vector to transform
541
+ * @param quaternion - The transform quaternion
542
+ * @param out - The transformed vector
543
+ */ Vector3.transformByQuat = function transformByQuat(v, quaternion, out) {
544
+ var _x = v._x, _y = v._y, _z = v._z;
545
+ var qx = quaternion._x, qy = quaternion._y, qz = quaternion._z, qw = quaternion._w;
546
+ // calculate quat * vec
547
+ var ix = qw * _x + qy * _z - qz * _y;
548
+ var iy = qw * _y + qz * _x - qx * _z;
549
+ var iz = qw * _z + qx * _y - qy * _x;
550
+ var iw = -qx * _x - qy * _y - qz * _z;
551
+ // calculate result * inverse quat
552
+ out._x = ix * qw - iw * qx - iy * qz + iz * qy;
553
+ out._y = iy * qw - iw * qy - iz * qx + ix * qz;
554
+ out._z = iz * qw - iw * qz - ix * qy + iy * qx;
555
+ out._onValueChanged && out._onValueChanged();
556
+ };
557
+ _createClass(Vector3, [
558
+ {
559
+ key: "x",
560
+ get: /**
561
+ * The x component of the vector.
562
+ */ function get() {
563
+ return this._x;
564
+ },
565
+ set: function set(value) {
566
+ this._x = value;
567
+ this._onValueChanged && this._onValueChanged();
568
+ }
569
+ },
570
+ {
571
+ key: "y",
572
+ get: /**
573
+ * The y component of the vector.
574
+ */ function get() {
575
+ return this._y;
576
+ },
577
+ set: function set(value) {
578
+ this._y = value;
579
+ this._onValueChanged && this._onValueChanged();
580
+ }
581
+ },
582
+ {
583
+ key: "z",
584
+ get: /**
585
+ * The z component of the vector.
586
+ */ function get() {
587
+ return this._z;
588
+ },
589
+ set: function set(value) {
590
+ this._z = value;
591
+ this._onValueChanged && this._onValueChanged();
592
+ }
593
+ }
594
+ ]);
595
+ return Vector3;
596
+ }();
597
+ /** @internal */ Vector3._zero = new Vector3(0.0, 0.0, 0.0);
598
+ /** @internal */ Vector3._one = new Vector3(1.0, 1.0, 1.0);
599
+
600
+ /**
601
+ * A bounding sphere.
602
+ * */ var BoundingSphere = /*#__PURE__*/ function() {
603
+ function BoundingSphere(center, radius) {
604
+ if (center === void 0) center = null;
605
+ if (radius === void 0) radius = 0;
606
+ /** The center point of the sphere. */ this.center = new Vector3();
607
+ /** The radius of the sphere. */ this.radius = 0;
608
+ center && this.center.copyFrom(center);
609
+ this.radius = radius;
610
+ }
611
+ var _proto = BoundingSphere.prototype;
612
+ /**
613
+ * Creates a clone of this sphere.
614
+ * @returns A clone of this sphere
615
+ */ _proto.clone = function clone() {
616
+ return new BoundingSphere(this.center, this.radius);
617
+ };
618
+ /**
619
+ * Copy this sphere from the specified sphere.
620
+ * @param source - The specified sphere
621
+ * @returns This sphere
622
+ */ _proto.copyFrom = function copyFrom(source) {
623
+ this.center.copyFrom(source.center);
624
+ this.radius = source.radius;
625
+ return this;
626
+ };
627
+ /**
628
+ * Calculate a bounding sphere that fully contains the given points.
629
+ * @param points - The given points
630
+ * @param out - The calculated bounding sphere
631
+ */ BoundingSphere.fromPoints = function fromPoints(points, out) {
632
+ if (!points || points.length === 0) {
633
+ throw new Error("points must be array and length must > 0");
634
+ }
635
+ var len = points.length;
636
+ var center = BoundingSphere._tempVec30;
637
+ center.x = center.y = center.z = 0;
638
+ // Calculate the center of the sphere.
639
+ for(var i = 0; i < len; ++i){
640
+ Vector3.add(points[i], center, center);
641
+ }
642
+ // The center of the sphere.
643
+ Vector3.scale(center, 1 / len, out.center);
644
+ // Calculate the radius of the sphere.
645
+ var radius = 0.0;
646
+ for(var i1 = 0; i1 < len; ++i1){
647
+ var distance = Vector3.distanceSquared(center, points[i1]);
648
+ distance > radius && (radius = distance);
649
+ }
650
+ // The radius of the sphere.
651
+ out.radius = Math.sqrt(radius);
652
+ };
653
+ /**
654
+ * Calculate a bounding sphere from a given box.
655
+ * @param box - The given box
656
+ * @param out - The calculated bounding sphere
657
+ */ BoundingSphere.fromBox = function fromBox(box, out) {
658
+ var center = out.center;
659
+ var min = box.min, max = box.max;
660
+ center.x = (min.x + max.x) * 0.5;
661
+ center.y = (min.y + max.y) * 0.5;
662
+ center.z = (min.z + max.z) * 0.5;
663
+ out.radius = Vector3.distance(center, max);
664
+ };
665
+ return BoundingSphere;
666
+ }();
667
+ BoundingSphere._tempVec30 = new Vector3();
668
+
669
+ /**
670
+ * Axis Aligned Bound Box (AABB).
671
+ */ var BoundingBox = /*#__PURE__*/ function() {
672
+ function BoundingBox(min, max) {
673
+ if (min === void 0) min = null;
674
+ if (max === void 0) max = null;
675
+ /** The minimum point of the box. */ this.min = new Vector3();
676
+ /** The maximum point of the box. */ this.max = new Vector3();
677
+ min && this.min.copyFrom(min);
678
+ max && this.max.copyFrom(max);
679
+ }
680
+ var _proto = BoundingBox.prototype;
681
+ /**
682
+ * Get the center point of this bounding box.
683
+ * @param out - The center point of this bounding box
684
+ * @returns The center point of this bounding box
685
+ */ _proto.getCenter = function getCenter(out) {
686
+ Vector3.add(this.min, this.max, out);
687
+ Vector3.scale(out, 0.5, out);
688
+ return out;
689
+ };
690
+ /**
691
+ * Get the extent of this bounding box.
692
+ * @param out - The extent of this bounding box
693
+ * @returns The extent of this bounding box
694
+ */ _proto.getExtent = function getExtent(out) {
695
+ Vector3.subtract(this.max, this.min, out);
696
+ Vector3.scale(out, 0.5, out);
697
+ return out;
698
+ };
699
+ /**
700
+ * Get the eight corners of this bounding box.
701
+ * @param out - An array of points representing the eight corners of this bounding box
702
+ * @returns An array of points representing the eight corners of this bounding box
703
+ */ _proto.getCorners = function getCorners(out) {
704
+ if (out === void 0) out = [];
705
+ var _this = this, min = _this.min, max = _this.max;
706
+ var minX = min.x;
707
+ var minY = min.y;
708
+ var minZ = min.z;
709
+ var maxX = max.x;
710
+ var maxY = max.y;
711
+ var maxZ = max.z;
712
+ var len = out.length;
713
+ // The array length is less than 8 to make up
714
+ if (len < 8) {
715
+ for(var i = 0, l = 8 - len; i < l; ++i){
716
+ out[len + i] = new Vector3();
717
+ }
718
+ }
719
+ out[0].set(minX, maxY, maxZ);
720
+ out[1].set(maxX, maxY, maxZ);
721
+ out[2].set(maxX, minY, maxZ);
722
+ out[3].set(minX, minY, maxZ);
723
+ out[4].set(minX, maxY, minZ);
724
+ out[5].set(maxX, maxY, minZ);
725
+ out[6].set(maxX, minY, minZ);
726
+ out[7].set(minX, minY, minZ);
727
+ return out;
728
+ };
729
+ /**
730
+ * Transform a bounding box.
731
+ * @param matrix - The transform to apply to the bounding box
732
+ * @returns The transformed bounding box
733
+ */ _proto.transform = function transform(matrix) {
734
+ BoundingBox.transform(this, matrix, this);
735
+ return this;
736
+ };
737
+ /**
738
+ * Creates a clone of this box.
739
+ * @returns A clone of this box
740
+ */ _proto.clone = function clone() {
741
+ return new BoundingBox(this.min, this.max);
742
+ };
743
+ /**
744
+ * Copy this bounding box from the specified box.
745
+ * @param source - The specified box
746
+ * @returns This bounding box
747
+ */ _proto.copyFrom = function copyFrom(source) {
748
+ this.min.copyFrom(source.min);
749
+ this.max.copyFrom(source.max);
750
+ return this;
751
+ };
752
+ /**
753
+ * Calculate a bounding box from the center point and the extent of the bounding box.
754
+ * @param center - The center point
755
+ * @param extent - The extent of the bounding box
756
+ * @param out - The calculated bounding box
757
+ */ BoundingBox.fromCenterAndExtent = function fromCenterAndExtent(center, extent, out) {
758
+ Vector3.subtract(center, extent, out.min);
759
+ Vector3.add(center, extent, out.max);
760
+ };
761
+ /**
762
+ * Calculate a bounding box that fully contains the given points.
763
+ * @param points - The given points
764
+ * @param out - The calculated bounding box
765
+ */ BoundingBox.fromPoints = function fromPoints(points, out) {
766
+ if (!points || points.length === 0) {
767
+ throw new Error("points must be array and length must > 0");
768
+ }
769
+ var min = out.min, max = out.max;
770
+ min.x = min.y = min.z = Number.MAX_VALUE;
771
+ max.x = max.y = max.z = -Number.MAX_VALUE;
772
+ for(var i = 0, l = points.length; i < l; ++i){
773
+ var point = points[i];
774
+ Vector3.min(min, point, min);
775
+ Vector3.max(max, point, max);
776
+ }
777
+ };
778
+ /**
779
+ * Calculate a bounding box from a given sphere.
780
+ * @param sphere - The given sphere
781
+ * @param out - The calculated bounding box
782
+ */ BoundingBox.fromSphere = function fromSphere(sphere, out) {
783
+ var center = sphere.center, radius = sphere.radius;
784
+ var min = out.min, max = out.max;
785
+ min.x = center.x - radius;
786
+ min.y = center.y - radius;
787
+ min.z = center.z - radius;
788
+ max.x = center.x + radius;
789
+ max.y = center.y + radius;
790
+ max.z = center.z + radius;
791
+ };
792
+ /**
793
+ * Transform a bounding box.
794
+ * @param source - The original bounding box
795
+ * @param matrix - The transform to apply to the bounding box
796
+ * @param out - The transformed bounding box
797
+ */ BoundingBox.transform = function transform(source, matrix, out) {
798
+ // https://zeux.io/2010/10/17/aabb-from-obb-with-component-wise-abs/
799
+ var center = BoundingBox._tempVec30;
800
+ var extent = BoundingBox._tempVec31;
801
+ source.getCenter(center);
802
+ source.getExtent(extent);
803
+ Vector3.transformCoordinate(center, matrix, center);
804
+ var x = extent.x, y = extent.y, z = extent.z;
805
+ var e = matrix.elements;
806
+ extent.x = Math.abs(x * e[0]) + Math.abs(y * e[4]) + Math.abs(z * e[8]);
807
+ extent.y = Math.abs(x * e[1]) + Math.abs(y * e[5]) + Math.abs(z * e[9]);
808
+ extent.z = Math.abs(x * e[2]) + Math.abs(y * e[6]) + Math.abs(z * e[10]);
809
+ // set min、max
810
+ Vector3.subtract(center, extent, out.min);
811
+ Vector3.add(center, extent, out.max);
812
+ };
813
+ /**
814
+ * Calculate a bounding box that is as large as the total combined area of the two specified boxes.
815
+ * @param box1 - The first box to merge
816
+ * @param box2 - The second box to merge
817
+ * @param out - The merged bounding box
818
+ * @returns The merged bounding box
819
+ */ BoundingBox.merge = function merge(box1, box2, out) {
820
+ Vector3.min(box1.min, box2.min, out.min);
821
+ Vector3.max(box1.max, box2.max, out.max);
822
+ return out;
823
+ };
824
+ return BoundingBox;
825
+ }();
826
+ BoundingBox._tempVec30 = new Vector3();
827
+ BoundingBox._tempVec31 = new Vector3();
828
+
829
+ /**
830
+ * Contains static methods to help in determining intersections, containment, etc.
831
+ */ var CollisionUtil = /*#__PURE__*/ function() {
832
+ function CollisionUtil() {}
833
+ /**
834
+ * Calculate the intersection point of three plane.
835
+ * @param p1 - Plane 1
836
+ * @param p2 - Plane 2
837
+ * @param p3 - Plane 3
838
+ * @param out - intersection point
839
+ */ CollisionUtil.intersectionPointThreePlanes = function intersectionPointThreePlanes(p1, p2, p3, out) {
840
+ var p1Nor = p1.normal;
841
+ var p2Nor = p2.normal;
842
+ var p3Nor = p3.normal;
843
+ Vector3.cross(p2Nor, p3Nor, CollisionUtil._tempVec30);
844
+ Vector3.cross(p3Nor, p1Nor, CollisionUtil._tempVec31);
845
+ Vector3.cross(p1Nor, p2Nor, CollisionUtil._tempVec32);
846
+ var a = -Vector3.dot(p1Nor, CollisionUtil._tempVec30);
847
+ var b = -Vector3.dot(p2Nor, CollisionUtil._tempVec31);
848
+ var c = -Vector3.dot(p3Nor, CollisionUtil._tempVec32);
849
+ Vector3.scale(CollisionUtil._tempVec30, p1.distance / a, CollisionUtil._tempVec30);
850
+ Vector3.scale(CollisionUtil._tempVec31, p2.distance / b, CollisionUtil._tempVec31);
851
+ Vector3.scale(CollisionUtil._tempVec32, p3.distance / c, CollisionUtil._tempVec32);
852
+ Vector3.add(CollisionUtil._tempVec30, CollisionUtil._tempVec31, out);
853
+ Vector3.add(out, CollisionUtil._tempVec32, out);
854
+ };
855
+ /**
856
+ * Calculate the distance from a point to a plane.
857
+ * @param plane - The plane
858
+ * @param point - The point
859
+ * @returns The distance from a point to a plane
860
+ */ CollisionUtil.distancePlaneAndPoint = function distancePlaneAndPoint(plane, point) {
861
+ return Vector3.dot(plane.normal, point) + plane.distance;
862
+ };
863
+ /**
864
+ * Get the intersection type between a plane and a point.
865
+ * @param plane - The plane
866
+ * @param point - The point
867
+ * @returns The intersection type
868
+ */ CollisionUtil.intersectsPlaneAndPoint = function intersectsPlaneAndPoint(plane, point) {
869
+ var distance = CollisionUtil.distancePlaneAndPoint(plane, point);
870
+ if (distance > 0) {
871
+ return exports.PlaneIntersectionType.Front;
872
+ }
873
+ if (distance < 0) {
874
+ return exports.PlaneIntersectionType.Back;
875
+ }
876
+ return exports.PlaneIntersectionType.Intersecting;
877
+ };
878
+ /**
879
+ * Get the intersection type between a plane and a box (AABB).
880
+ * @param plane - The plane
881
+ * @param box - The box
882
+ * @returns The intersection type
883
+ */ CollisionUtil.intersectsPlaneAndBox = function intersectsPlaneAndBox(plane, box) {
884
+ var min = box.min, max = box.max;
885
+ var normal = plane.normal;
886
+ var front = CollisionUtil._tempVec30;
887
+ var back = CollisionUtil._tempVec31;
888
+ if (normal.x >= 0) {
889
+ front.x = max.x;
890
+ back.x = min.x;
891
+ } else {
892
+ front.x = min.x;
893
+ back.x = max.x;
894
+ }
895
+ if (normal.y >= 0) {
896
+ front.y = max.y;
897
+ back.y = min.y;
898
+ } else {
899
+ front.y = min.y;
900
+ back.y = max.y;
901
+ }
902
+ if (normal.z >= 0) {
903
+ front.z = max.z;
904
+ back.z = min.z;
905
+ } else {
906
+ front.z = min.z;
907
+ back.z = max.z;
908
+ }
909
+ if (CollisionUtil.distancePlaneAndPoint(plane, front) < 0) {
910
+ return exports.PlaneIntersectionType.Back;
911
+ }
912
+ if (CollisionUtil.distancePlaneAndPoint(plane, back) > 0) {
913
+ return exports.PlaneIntersectionType.Front;
914
+ }
915
+ return exports.PlaneIntersectionType.Intersecting;
916
+ };
917
+ /**
918
+ * Get the intersection type between a plane and a sphere.
919
+ * @param plane - The plane
920
+ * @param sphere - The sphere
921
+ * @returns The intersection type
922
+ */ CollisionUtil.intersectsPlaneAndSphere = function intersectsPlaneAndSphere(plane, sphere) {
923
+ var center = sphere.center, radius = sphere.radius;
924
+ var distance = CollisionUtil.distancePlaneAndPoint(plane, center);
925
+ if (distance > radius) {
926
+ return exports.PlaneIntersectionType.Front;
927
+ }
928
+ if (distance < -radius) {
929
+ return exports.PlaneIntersectionType.Back;
930
+ }
931
+ return exports.PlaneIntersectionType.Intersecting;
932
+ };
933
+ /**
934
+ * Get the intersection type between a ray and a plane.
935
+ * @param ray - The ray
936
+ * @param plane - The plane
937
+ * @returns The distance from ray to plane if intersecting, -1 otherwise
938
+ */ CollisionUtil.intersectsRayAndPlane = function intersectsRayAndPlane(ray, plane) {
939
+ var normal = plane.normal;
940
+ var zeroTolerance = MathUtil.zeroTolerance;
941
+ var dir = Vector3.dot(normal, ray.direction);
942
+ // Parallel
943
+ if (Math.abs(dir) < zeroTolerance) {
944
+ return -1;
945
+ }
946
+ var position = Vector3.dot(normal, ray.origin);
947
+ var distance = (-plane.distance - position) / dir;
948
+ if (distance < 0) {
949
+ if (distance < -zeroTolerance) {
950
+ return -1;
951
+ }
952
+ distance = 0;
953
+ }
954
+ return distance;
955
+ };
956
+ /**
957
+ * Get the intersection type between a ray and a box (AABB).
958
+ * @param ray - The ray
959
+ * @param box - The box
960
+ * @returns The distance from ray to box if intersecting, -1 otherwise
961
+ */ CollisionUtil.intersectsRayAndBox = function intersectsRayAndBox(ray, box) {
962
+ var zeroTolerance = MathUtil.zeroTolerance;
963
+ var origin = ray.origin, direction = ray.direction;
964
+ var min = box.min, max = box.max;
965
+ var dirX = direction.x;
966
+ var dirY = direction.y;
967
+ var dirZ = direction.z;
968
+ var oriX = origin.x;
969
+ var oriY = origin.y;
970
+ var oriZ = origin.z;
971
+ var distance = 0;
972
+ var tmax = Number.MAX_VALUE;
973
+ if (Math.abs(dirX) < zeroTolerance) {
974
+ if (oriX < min.x || oriX > max.x) {
975
+ return -1;
976
+ }
977
+ } else {
978
+ var inverse = 1.0 / dirX;
979
+ var t1 = (min.x - oriX) * inverse;
980
+ var t2 = (max.x - oriX) * inverse;
981
+ if (t1 > t2) {
982
+ var temp = t1;
983
+ t1 = t2;
984
+ t2 = temp;
985
+ }
986
+ distance = Math.max(t1, distance);
987
+ tmax = Math.min(t2, tmax);
988
+ if (distance > tmax) {
989
+ return -1;
990
+ }
991
+ }
992
+ if (Math.abs(dirY) < zeroTolerance) {
993
+ if (oriY < min.y || oriY > max.y) {
994
+ return -1;
995
+ }
996
+ } else {
997
+ var inverse1 = 1.0 / dirY;
998
+ var t11 = (min.y - oriY) * inverse1;
999
+ var t21 = (max.y - oriY) * inverse1;
1000
+ if (t11 > t21) {
1001
+ var temp1 = t11;
1002
+ t11 = t21;
1003
+ t21 = temp1;
1004
+ }
1005
+ distance = Math.max(t11, distance);
1006
+ tmax = Math.min(t21, tmax);
1007
+ if (distance > tmax) {
1008
+ return -1;
1009
+ }
1010
+ }
1011
+ if (Math.abs(dirZ) < zeroTolerance) {
1012
+ if (oriZ < min.z || oriZ > max.z) {
1013
+ return -1;
1014
+ }
1015
+ } else {
1016
+ var inverse2 = 1.0 / dirZ;
1017
+ var t12 = (min.z - oriZ) * inverse2;
1018
+ var t22 = (max.z - oriZ) * inverse2;
1019
+ if (t12 > t22) {
1020
+ var temp2 = t12;
1021
+ t12 = t22;
1022
+ t22 = temp2;
1023
+ }
1024
+ distance = Math.max(t12, distance);
1025
+ tmax = Math.min(t22, tmax);
1026
+ if (distance > tmax) {
1027
+ return -1;
1028
+ }
1029
+ }
1030
+ return distance;
1031
+ };
1032
+ /**
1033
+ * Get the intersection type between a ray and a sphere.
1034
+ * @param ray - The ray
1035
+ * @param sphere - The sphere
1036
+ * @returns The distance from ray to sphere if intersecting, -1 otherwise
1037
+ */ CollisionUtil.intersectsRayAndSphere = function intersectsRayAndSphere(ray, sphere) {
1038
+ var origin = ray.origin, direction = ray.direction;
1039
+ var center = sphere.center, radius = sphere.radius;
1040
+ var m = CollisionUtil._tempVec30;
1041
+ Vector3.subtract(origin, center, m);
1042
+ var b = Vector3.dot(m, direction);
1043
+ var c = Vector3.dot(m, m) - radius * radius;
1044
+ if (b > 0 && c > 0) {
1045
+ return -1;
1046
+ }
1047
+ var discriminant = b * b - c;
1048
+ if (discriminant < 0) {
1049
+ return -1;
1050
+ }
1051
+ var distance = -b - Math.sqrt(discriminant);
1052
+ if (distance < 0) {
1053
+ distance = 0;
1054
+ }
1055
+ return distance;
1056
+ };
1057
+ /**
1058
+ * Check whether the boxes intersect.
1059
+ * @param boxA - The first box to check
1060
+ * @param boxB - The second box to check
1061
+ * @returns True if the boxes intersect, false otherwise
1062
+ */ CollisionUtil.intersectsBoxAndBox = function intersectsBoxAndBox(boxA, boxB) {
1063
+ if (boxA.min.x > boxB.max.x || boxB.min.x > boxA.max.x) {
1064
+ return false;
1065
+ }
1066
+ if (boxA.min.y > boxB.max.y || boxB.min.y > boxA.max.y) {
1067
+ return false;
1068
+ }
1069
+ return !(boxA.min.z > boxB.max.z || boxB.min.z > boxA.max.z);
1070
+ };
1071
+ /**
1072
+ * Check whether the spheres intersect.
1073
+ * @param sphereA - The first sphere to check
1074
+ * @param sphereB - The second sphere to check
1075
+ * @returns True if the spheres intersect, false otherwise
1076
+ */ CollisionUtil.intersectsSphereAndSphere = function intersectsSphereAndSphere(sphereA, sphereB) {
1077
+ var radiisum = sphereA.radius + sphereB.radius;
1078
+ return Vector3.distanceSquared(sphereA.center, sphereB.center) < radiisum * radiisum;
1079
+ };
1080
+ /**
1081
+ * Check whether the sphere and the box intersect.
1082
+ * @param sphere - The sphere to check
1083
+ * @param box - The box to check
1084
+ * @returns True if the sphere and the box intersect, false otherwise
1085
+ */ CollisionUtil.intersectsSphereAndBox = function intersectsSphereAndBox(sphere, box) {
1086
+ var center = sphere.center;
1087
+ var max = box.max;
1088
+ var min = box.min;
1089
+ var closestPoint = CollisionUtil._tempVec30;
1090
+ closestPoint.set(Math.max(min.x, Math.min(center.x, max.x)), Math.max(min.y, Math.min(center.y, max.y)), Math.max(min.z, Math.min(center.z, max.z)));
1091
+ var distance = Vector3.distanceSquared(center, closestPoint);
1092
+ return distance <= sphere.radius * sphere.radius;
1093
+ };
1094
+ /**
1095
+ * Get whether or not a specified bounding box intersects with this frustum (Contains or Intersects).
1096
+ * @param frustum - The frustum
1097
+ * @param box - The box
1098
+ * @returns True if bounding box intersects with this frustum, false otherwise
1099
+ */ CollisionUtil.intersectsFrustumAndBox = function intersectsFrustumAndBox(frustum, box) {
1100
+ var min = box.min, max = box.max;
1101
+ var p = CollisionUtil._tempVec30;
1102
+ for(var i = 0; i < 6; ++i){
1103
+ var plane = frustum.getPlane(i);
1104
+ var normal = plane.normal;
1105
+ p.set(normal.x >= 0 ? max.x : min.x, normal.y >= 0 ? max.y : min.y, normal.z >= 0 ? max.z : min.z);
1106
+ if (Vector3.dot(normal, p) < -plane.distance) {
1107
+ return false;
1108
+ }
1109
+ }
1110
+ return true;
1111
+ };
1112
+ /**
1113
+ * Get the containment type between a frustum and a box (AABB).
1114
+ * @param frustum - The frustum
1115
+ * @param box - The box
1116
+ * @returns The containment type
1117
+ */ CollisionUtil.frustumContainsBox = function frustumContainsBox(frustum, box) {
1118
+ var min = box.min, max = box.max;
1119
+ var p = CollisionUtil._tempVec30;
1120
+ var n = CollisionUtil._tempVec31;
1121
+ var result = exports.ContainmentType.Contains;
1122
+ for(var i = 0; i < 6; ++i){
1123
+ var plane = frustum.getPlane(i);
1124
+ var normal = plane.normal;
1125
+ if (normal.x >= 0) {
1126
+ p.x = max.x;
1127
+ n.x = min.x;
1128
+ } else {
1129
+ p.x = min.x;
1130
+ n.x = max.x;
1131
+ }
1132
+ if (normal.y >= 0) {
1133
+ p.y = max.y;
1134
+ n.y = min.y;
1135
+ } else {
1136
+ p.y = min.y;
1137
+ n.y = max.y;
1138
+ }
1139
+ if (normal.z >= 0) {
1140
+ p.z = max.z;
1141
+ n.z = min.z;
1142
+ } else {
1143
+ p.z = min.z;
1144
+ n.z = max.z;
1145
+ }
1146
+ if (CollisionUtil.intersectsPlaneAndPoint(plane, p) === exports.PlaneIntersectionType.Back) {
1147
+ return exports.ContainmentType.Disjoint;
1148
+ }
1149
+ if (CollisionUtil.intersectsPlaneAndPoint(plane, n) === exports.PlaneIntersectionType.Back) {
1150
+ result = exports.ContainmentType.Intersects;
1151
+ }
1152
+ }
1153
+ return result;
1154
+ };
1155
+ /**
1156
+ * Get the containment type between a frustum and a sphere.
1157
+ * @param frustum - The frustum
1158
+ * @param sphere - The sphere
1159
+ * @returns The containment type
1160
+ */ CollisionUtil.frustumContainsSphere = function frustumContainsSphere(frustum, sphere) {
1161
+ var result = exports.ContainmentType.Contains;
1162
+ for(var i = 0; i < 6; ++i){
1163
+ var plane = frustum.getPlane(i);
1164
+ var intersectionType = CollisionUtil.intersectsPlaneAndSphere(plane, sphere);
1165
+ if (intersectionType === exports.PlaneIntersectionType.Back) {
1166
+ return exports.ContainmentType.Disjoint;
1167
+ } else if (intersectionType === exports.PlaneIntersectionType.Intersecting) {
1168
+ result = exports.ContainmentType.Intersects;
1169
+ break;
1170
+ }
1171
+ }
1172
+ return result;
1173
+ };
1174
+ return CollisionUtil;
1175
+ }();
1176
+ CollisionUtil._tempVec30 = new Vector3();
1177
+ CollisionUtil._tempVec31 = new Vector3();
1178
+ CollisionUtil._tempVec32 = new Vector3();
1179
+
1180
+ /**
1181
+ * Represents a plane in three-dimensional space.
1182
+ */ var Plane = /*#__PURE__*/ function() {
1183
+ function Plane(normal, distance) {
1184
+ if (normal === void 0) normal = null;
1185
+ if (distance === void 0) distance = 0;
1186
+ /** The normal of the plane. */ this.normal = new Vector3();
1187
+ /** The distance of the plane along its normal to the origin. */ this.distance = 0;
1188
+ normal && this.normal.copyFrom(normal);
1189
+ this.distance = distance;
1190
+ }
1191
+ var _proto = Plane.prototype;
1192
+ /**
1193
+ * Normalize the normal vector of this plane.
1194
+ * @returns The plane after normalize
1195
+ */ _proto.normalize = function normalize() {
1196
+ Plane.normalize(this, this);
1197
+ return this;
1198
+ };
1199
+ /**
1200
+ * Creates a clone of this plane.
1201
+ * @returns A clone of this plane
1202
+ */ _proto.clone = function clone() {
1203
+ var out = new Plane();
1204
+ out.copyFrom(this);
1205
+ return out;
1206
+ };
1207
+ /**
1208
+ * Copy this plane from the specified plane.
1209
+ * @param source - The specified plane
1210
+ * @returns This plane
1211
+ */ _proto.copyFrom = function copyFrom(source) {
1212
+ this.normal.copyFrom(source.normal);
1213
+ this.distance = source.distance;
1214
+ return this;
1215
+ };
1216
+ /**
1217
+ * Normalize the normal vector of the specified plane.
1218
+ * @param p - The specified plane
1219
+ * @param out - A normalized version of the specified plane
1220
+ */ Plane.normalize = function normalize(p, out) {
1221
+ var normal = p.normal;
1222
+ var factor = 1.0 / normal.length();
1223
+ Vector3.scale(normal, factor, out.normal);
1224
+ out.distance = p.distance * factor;
1225
+ };
1226
+ /**
1227
+ * Calculate the plane that contains the three specified points.
1228
+ * @param point0 - The first point
1229
+ * @param point1 - The second point
1230
+ * @param point2 - The third point
1231
+ * @param out - The calculated plane
1232
+ */ Plane.fromPoints = function fromPoints(point0, point1, point2, out) {
1233
+ var x0 = point0.x;
1234
+ var y0 = point0.y;
1235
+ var z0 = point0.z;
1236
+ var x1 = point1.x - x0;
1237
+ var y1 = point1.y - y0;
1238
+ var z1 = point1.z - z0;
1239
+ var x2 = point2.x - x0;
1240
+ var y2 = point2.y - y0;
1241
+ var z2 = point2.z - z0;
1242
+ var yz = y1 * z2 - z1 * y2;
1243
+ var xz = z1 * x2 - x1 * z2;
1244
+ var xy = x1 * y2 - y1 * x2;
1245
+ var invPyth = 1.0 / Math.sqrt(yz * yz + xz * xz + xy * xy);
1246
+ var x = yz * invPyth;
1247
+ var y = xz * invPyth;
1248
+ var z = xy * invPyth;
1249
+ var normal = out.normal;
1250
+ normal.x = x;
1251
+ normal.y = y;
1252
+ normal.z = z;
1253
+ out.distance = -(x * x0 + y * y0 + z * z0);
1254
+ };
1255
+ return Plane;
1256
+ }();
1257
+
1258
+ /**
1259
+ * A bounding frustum.
1260
+ */ var BoundingFrustum = /*#__PURE__*/ function() {
1261
+ function BoundingFrustum(matrix) {
1262
+ if (matrix === void 0) matrix = null;
1263
+ this.near = new Plane();
1264
+ this.far = new Plane();
1265
+ this.left = new Plane();
1266
+ this.right = new Plane();
1267
+ this.top = new Plane();
1268
+ this.bottom = new Plane();
1269
+ matrix && this.calculateFromMatrix(matrix);
1270
+ }
1271
+ var _proto = BoundingFrustum.prototype;
1272
+ /**
1273
+ * Get the plane by the given frustum face.
1274
+ * @param face - The frustum face
1275
+ * @returns The plane get
1276
+ */ _proto.getPlane = function getPlane(face) {
1277
+ switch(face){
1278
+ case exports.FrustumFace.Near:
1279
+ return this.near;
1280
+ case exports.FrustumFace.Far:
1281
+ return this.far;
1282
+ case exports.FrustumFace.Left:
1283
+ return this.left;
1284
+ case exports.FrustumFace.Right:
1285
+ return this.right;
1286
+ case exports.FrustumFace.Bottom:
1287
+ return this.bottom;
1288
+ case exports.FrustumFace.Top:
1289
+ return this.top;
1290
+ default:
1291
+ return null;
1292
+ }
1293
+ };
1294
+ /**
1295
+ * Update all planes from the given matrix.
1296
+ * @param matrix - The given view-projection matrix
1297
+ */ _proto.calculateFromMatrix = function calculateFromMatrix(matrix) {
1298
+ var me = matrix.elements;
1299
+ var m11 = me[0];
1300
+ var m12 = me[1];
1301
+ var m13 = me[2];
1302
+ var m14 = me[3];
1303
+ var m21 = me[4];
1304
+ var m22 = me[5];
1305
+ var m23 = me[6];
1306
+ var m24 = me[7];
1307
+ var m31 = me[8];
1308
+ var m32 = me[9];
1309
+ var m33 = me[10];
1310
+ var m34 = me[11];
1311
+ var m41 = me[12];
1312
+ var m42 = me[13];
1313
+ var m43 = me[14];
1314
+ var m44 = me[15];
1315
+ // near
1316
+ var nearNormal = this.near.normal;
1317
+ nearNormal.set(m14 + m13, m24 + m23, m34 + m33);
1318
+ this.near.distance = m44 + m43;
1319
+ this.near.normalize();
1320
+ // far
1321
+ var farNormal = this.far.normal;
1322
+ farNormal.set(m14 - m13, m24 - m23, m34 - m33);
1323
+ this.far.distance = m44 - m43;
1324
+ this.far.normalize();
1325
+ // left
1326
+ var leftNormal = this.left.normal;
1327
+ leftNormal.set(m14 + m11, m24 + m21, m34 + m31);
1328
+ this.left.distance = m44 + m41;
1329
+ this.left.normalize();
1330
+ // right
1331
+ var rightNormal = this.right.normal;
1332
+ rightNormal.set(m14 - m11, m24 - m21, m34 - m31);
1333
+ this.right.distance = m44 - m41;
1334
+ this.right.normalize();
1335
+ // bottom
1336
+ var bottomNormal = this.bottom.normal;
1337
+ bottomNormal.set(m14 + m12, m24 + m22, m34 + m32);
1338
+ this.bottom.distance = m44 + m42;
1339
+ this.bottom.normalize();
1340
+ // top
1341
+ var topNormal = this.top.normal;
1342
+ topNormal.set(m14 - m12, m24 - m22, m34 - m32);
1343
+ this.top.distance = m44 - m42;
1344
+ this.top.normalize();
1345
+ };
1346
+ /**
1347
+ * Get whether or not a specified bounding box intersects with this frustum (Contains or Intersects).
1348
+ * @param box - The box for testing
1349
+ * @returns True if bounding box intersects with this frustum, false otherwise
1350
+ */ _proto.intersectsBox = function intersectsBox(box) {
1351
+ return CollisionUtil.intersectsFrustumAndBox(this, box);
1352
+ };
1353
+ /**
1354
+ * Get whether or not a specified bounding sphere intersects with this frustum (Contains or Intersects).
1355
+ * @param sphere - The sphere for testing
1356
+ * @returns True if bounding sphere intersects with this frustum, false otherwise
1357
+ */ _proto.intersectsSphere = function intersectsSphere(sphere) {
1358
+ return CollisionUtil.frustumContainsSphere(this, sphere) !== exports.ContainmentType.Disjoint;
1359
+ };
1360
+ /**
1361
+ * Creates a clone of this frustum.
1362
+ * @returns A clone of this frustum
1363
+ */ _proto.clone = function clone() {
1364
+ var out = new BoundingFrustum();
1365
+ out.copyFrom(this);
1366
+ return out;
1367
+ };
1368
+ /**
1369
+ * Copy this frustum from the specified frustum.
1370
+ * @param source - The specified frustum
1371
+ * @returns This frustum
1372
+ */ _proto.copyFrom = function copyFrom(source) {
1373
+ this.near.copyFrom(source.near);
1374
+ this.far.copyFrom(source.far);
1375
+ this.left.copyFrom(source.left);
1376
+ this.right.copyFrom(source.right);
1377
+ this.bottom.copyFrom(source.bottom);
1378
+ this.top.copyFrom(source.top);
1379
+ return this;
1380
+ };
1381
+ return BoundingFrustum;
1382
+ }();
1383
+
1384
+ /**
1385
+ * Represents a 3x3 mathematical matrix.
1386
+ */ var Matrix3x3 = /*#__PURE__*/ function() {
1387
+ function Matrix3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33) {
1388
+ if (m11 === void 0) m11 = 1;
1389
+ if (m12 === void 0) m12 = 0;
1390
+ if (m13 === void 0) m13 = 0;
1391
+ if (m21 === void 0) m21 = 0;
1392
+ if (m22 === void 0) m22 = 1;
1393
+ if (m23 === void 0) m23 = 0;
1394
+ if (m31 === void 0) m31 = 0;
1395
+ if (m32 === void 0) m32 = 0;
1396
+ if (m33 === void 0) m33 = 1;
1397
+ /**
1398
+ * An array containing the elements of the matrix (column matrix).
1399
+ * @remarks
1400
+ * elements[0] first column and first row value m11
1401
+ * elements[1] first column and second row value m12
1402
+ * elements[2] first column and third row value m13
1403
+ * elements[3] second column and first row value m21
1404
+ * and so on
1405
+ */ this.elements = new Float32Array(9);
1406
+ var e = this.elements;
1407
+ e[0] = m11;
1408
+ e[1] = m12;
1409
+ e[2] = m13;
1410
+ e[3] = m21;
1411
+ e[4] = m22;
1412
+ e[5] = m23;
1413
+ e[6] = m31;
1414
+ e[7] = m32;
1415
+ e[8] = m33;
1416
+ }
1417
+ var _proto = Matrix3x3.prototype;
1418
+ /**
1419
+ * Set the value of this matrix, and return this matrix.
1420
+ * @param m11
1421
+ * @param m12
1422
+ * @param m13
1423
+ * @param m21
1424
+ * @param m22
1425
+ * @param m23
1426
+ * @param m31
1427
+ * @param m32
1428
+ * @param m33
1429
+ * @returns This matrix
1430
+ */ _proto.set = function set(m11, m12, m13, m21, m22, m23, m31, m32, m33) {
1431
+ var e = this.elements;
1432
+ e[0] = m11;
1433
+ e[1] = m12;
1434
+ e[2] = m13;
1435
+ e[3] = m21;
1436
+ e[4] = m22;
1437
+ e[5] = m23;
1438
+ e[6] = m31;
1439
+ e[7] = m32;
1440
+ e[8] = m33;
1441
+ return this;
1442
+ };
1443
+ /**
1444
+ * Determines the sum of this matrix and the specified matrix.
1445
+ * @param right - The specified matrix
1446
+ * @returns This matrix that store the sum of the two matrices
1447
+ */ _proto.add = function add(right) {
1448
+ Matrix3x3.add(this, right, this);
1449
+ return this;
1450
+ };
1451
+ /**
1452
+ * Determines the difference between this matrix and the specified matrix.
1453
+ * @param right - The specified matrix
1454
+ * @returns This matrix that store the difference between the two matrices
1455
+ */ _proto.subtract = function subtract(right) {
1456
+ Matrix3x3.subtract(this, right, this);
1457
+ return this;
1458
+ };
1459
+ /**
1460
+ * Determines the product of this matrix and the specified matrix.
1461
+ * @param right - The specified matrix
1462
+ * @returns This matrix that store the product of the two matrices
1463
+ */ _proto.multiply = function multiply(right) {
1464
+ Matrix3x3.multiply(this, right, this);
1465
+ return this;
1466
+ };
1467
+ /**
1468
+ * Calculate a determinant of this matrix.
1469
+ * @returns The determinant of this matrix
1470
+ */ _proto.determinant = function determinant() {
1471
+ var e = this.elements;
1472
+ var a11 = e[0], a12 = e[1], a13 = e[2];
1473
+ var a21 = e[3], a22 = e[4], a23 = e[5];
1474
+ var a31 = e[6], a32 = e[7], a33 = e[8];
1475
+ var b12 = a33 * a22 - a23 * a32;
1476
+ var b22 = -a33 * a21 + a23 * a31;
1477
+ var b32 = a32 * a21 - a22 * a31;
1478
+ return a11 * b12 + a12 * b22 + a13 * b32;
1479
+ };
1480
+ /**
1481
+ * Identity this matrix.
1482
+ * @returns This matrix after identity
1483
+ */ _proto.identity = function identity() {
1484
+ var e = this.elements;
1485
+ e[0] = 1;
1486
+ e[1] = 0;
1487
+ e[2] = 0;
1488
+ e[3] = 0;
1489
+ e[4] = 1;
1490
+ e[5] = 0;
1491
+ e[6] = 0;
1492
+ e[7] = 0;
1493
+ e[8] = 1;
1494
+ return this;
1495
+ };
1496
+ /**
1497
+ * Invert the matrix.
1498
+ * @returns The matrix after invert
1499
+ */ _proto.invert = function invert() {
1500
+ Matrix3x3.invert(this, this);
1501
+ return this;
1502
+ };
1503
+ /**
1504
+ * This matrix rotates around an angle.
1505
+ * @param r - The rotation angle in radians
1506
+ * @returns This matrix after rotate
1507
+ */ _proto.rotate = function rotate(r) {
1508
+ Matrix3x3.rotate(this, r, this);
1509
+ return this;
1510
+ };
1511
+ /**
1512
+ * Scale this matrix by a given vector.
1513
+ * @param s - The given vector
1514
+ * @returns This matrix after scale
1515
+ */ _proto.scale = function scale(s) {
1516
+ Matrix3x3.scale(this, s, this);
1517
+ return this;
1518
+ };
1519
+ /**
1520
+ * Translate this matrix by a given vector.
1521
+ * @param translation - The given vector
1522
+ * @returns This matrix after translate
1523
+ */ _proto.translate = function translate(translation) {
1524
+ Matrix3x3.translate(this, translation, this);
1525
+ return this;
1526
+ };
1527
+ /**
1528
+ * Calculate the transpose of this matrix.
1529
+ * @returns This matrix after transpose
1530
+ */ _proto.transpose = function transpose() {
1531
+ Matrix3x3.transpose(this, this);
1532
+ return this;
1533
+ };
1534
+ /**
1535
+ * Creates a clone of this matrix.
1536
+ * @returns A clone of this matrix
1537
+ */ _proto.clone = function clone() {
1538
+ var e = this.elements;
1539
+ var ret = new Matrix3x3(e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8]);
1540
+ return ret;
1541
+ };
1542
+ /**
1543
+ * Copy this matrix from the specified matrix.
1544
+ * @param source - The specified matrix
1545
+ * @returns This matrix
1546
+ */ _proto.copyFrom = function copyFrom(source) {
1547
+ var e = this.elements;
1548
+ var se = source.elements;
1549
+ e[0] = se[0];
1550
+ e[1] = se[1];
1551
+ e[2] = se[2];
1552
+ e[3] = se[3];
1553
+ e[4] = se[4];
1554
+ e[5] = se[5];
1555
+ e[6] = se[6];
1556
+ e[7] = se[7];
1557
+ e[8] = se[8];
1558
+ return this;
1559
+ };
1560
+ /**
1561
+ * Copy the value of this matrix from an array.
1562
+ * @param array - The array
1563
+ * @param offset - The start offset of the array
1564
+ * @returns This matrix
1565
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
1566
+ if (offset === void 0) offset = 0;
1567
+ var srce = this.elements;
1568
+ for(var i = 0; i < 12; i++){
1569
+ srce[i] = array[i + offset];
1570
+ }
1571
+ return this;
1572
+ };
1573
+ /**
1574
+ * Copy the value of this matrix to an array.
1575
+ * @param out - The array
1576
+ * @param outOffset - The start offset of the array
1577
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
1578
+ if (outOffset === void 0) outOffset = 0;
1579
+ var e = this.elements;
1580
+ out[outOffset] = e[0];
1581
+ out[outOffset + 1] = e[1];
1582
+ out[outOffset + 2] = e[2];
1583
+ out[outOffset + 3] = e[3];
1584
+ out[outOffset + 4] = e[4];
1585
+ out[outOffset + 5] = e[5];
1586
+ out[outOffset + 6] = e[6];
1587
+ out[outOffset + 7] = e[7];
1588
+ out[outOffset + 8] = e[8];
1589
+ };
1590
+ /**
1591
+ * Copy the value of this 3x3 matrix from the specified 4x4 matrix.
1592
+ * upper-left principle
1593
+ * @param source - The specified 4x4 matrix
1594
+ * @returns This 3x3 matrix
1595
+ */ _proto.copyFromMatrix = function copyFromMatrix(source) {
1596
+ var ae = source.elements;
1597
+ var e = this.elements;
1598
+ e[0] = ae[0];
1599
+ e[1] = ae[1];
1600
+ e[2] = ae[2];
1601
+ e[3] = ae[4];
1602
+ e[4] = ae[5];
1603
+ e[5] = ae[6];
1604
+ e[6] = ae[8];
1605
+ e[7] = ae[9];
1606
+ e[8] = ae[10];
1607
+ return this;
1608
+ };
1609
+ /**
1610
+ * Determines the sum of two matrices.
1611
+ * @param left - The first matrix to add
1612
+ * @param right - The second matrix to add
1613
+ * @param out - The sum of two matrices
1614
+ */ Matrix3x3.add = function add(left, right, out) {
1615
+ var le = left.elements;
1616
+ var re = right.elements;
1617
+ var oe = out.elements;
1618
+ oe[0] = le[0] + re[0];
1619
+ oe[1] = le[1] + re[1];
1620
+ oe[2] = le[2] + re[2];
1621
+ oe[3] = le[3] + re[3];
1622
+ oe[4] = le[4] + re[4];
1623
+ oe[5] = le[5] + re[5];
1624
+ oe[6] = le[6] + re[6];
1625
+ oe[7] = le[7] + re[7];
1626
+ oe[8] = le[8] + re[8];
1627
+ };
1628
+ /**
1629
+ * Determines the difference between two matrices.
1630
+ * @param left - The first matrix to subtract
1631
+ * @param right - The second matrix to subtract
1632
+ * @param out - The difference between two matrices
1633
+ */ Matrix3x3.subtract = function subtract(left, right, out) {
1634
+ var le = left.elements;
1635
+ var re = right.elements;
1636
+ var oe = out.elements;
1637
+ oe[0] = le[0] - re[0];
1638
+ oe[1] = le[1] - re[1];
1639
+ oe[2] = le[2] - re[2];
1640
+ oe[3] = le[3] - re[3];
1641
+ oe[4] = le[4] - re[4];
1642
+ oe[5] = le[5] - re[5];
1643
+ oe[6] = le[6] - re[6];
1644
+ oe[7] = le[7] - re[7];
1645
+ oe[8] = le[8] - re[8];
1646
+ };
1647
+ /**
1648
+ * Determines the product of two matrices.
1649
+ * @param left - The first matrix to multiply
1650
+ * @param right - The second matrix to multiply
1651
+ * @param out - The product of two matrices
1652
+ */ Matrix3x3.multiply = function multiply(left, right, out) {
1653
+ var le = left.elements;
1654
+ var re = right.elements;
1655
+ var oe = out.elements;
1656
+ var l11 = le[0], l12 = le[1], l13 = le[2];
1657
+ var l21 = le[3], l22 = le[4], l23 = le[5];
1658
+ var l31 = le[6], l32 = le[7], l33 = le[8];
1659
+ var r11 = re[0], r12 = re[1], r13 = re[2];
1660
+ var r21 = re[3], r22 = re[4], r23 = re[5];
1661
+ var r31 = re[6], r32 = re[7], r33 = re[8];
1662
+ oe[0] = l11 * r11 + l21 * r12 + l31 * r13;
1663
+ oe[1] = l12 * r11 + l22 * r12 + l32 * r13;
1664
+ oe[2] = l13 * r11 + l23 * r12 + l33 * r13;
1665
+ oe[3] = l11 * r21 + l21 * r22 + l31 * r23;
1666
+ oe[4] = l12 * r21 + l22 * r22 + l32 * r23;
1667
+ oe[5] = l13 * r21 + l23 * r22 + l33 * r23;
1668
+ oe[6] = l11 * r31 + l21 * r32 + l31 * r33;
1669
+ oe[7] = l12 * r31 + l22 * r32 + l32 * r33;
1670
+ oe[8] = l13 * r31 + l23 * r32 + l33 * r33;
1671
+ };
1672
+ /**
1673
+ * Determines whether the specified matrices are equals.
1674
+ * @param left - The first matrix to compare
1675
+ * @param right - The second matrix to compare
1676
+ * @returns True if the specified matrices are equals, false otherwise
1677
+ */ Matrix3x3.equals = function equals(left, right) {
1678
+ var le = left.elements;
1679
+ var re = right.elements;
1680
+ return MathUtil.equals(le[0], re[0]) && MathUtil.equals(le[1], re[1]) && MathUtil.equals(le[2], re[2]) && MathUtil.equals(le[3], re[3]) && MathUtil.equals(le[4], re[4]) && MathUtil.equals(le[5], re[5]) && MathUtil.equals(le[6], re[6]) && MathUtil.equals(le[7], re[7]) && MathUtil.equals(le[8], re[8]);
1681
+ };
1682
+ /**
1683
+ * Performs a linear interpolation between two matrices.
1684
+ * @param start - The first matrix
1685
+ * @param end - The second matrix
1686
+ * @param t - The blend amount where 0 returns start and 1 end
1687
+ * @param out - The result of linear blending between two matrices
1688
+ */ Matrix3x3.lerp = function lerp(start, end, t, out) {
1689
+ var se = start.elements;
1690
+ var ee = end.elements;
1691
+ var oe = out.elements;
1692
+ var inv = 1.0 - t;
1693
+ oe[0] = se[0] * inv + ee[0] * t;
1694
+ oe[1] = se[1] * inv + ee[1] * t;
1695
+ oe[2] = se[2] * inv + ee[2] * t;
1696
+ oe[3] = se[3] * inv + ee[3] * t;
1697
+ oe[4] = se[4] * inv + ee[4] * t;
1698
+ oe[5] = se[5] * inv + ee[5] * t;
1699
+ oe[6] = se[6] * inv + ee[6] * t;
1700
+ oe[7] = se[7] * inv + ee[7] * t;
1701
+ oe[8] = se[8] * inv + ee[8] * t;
1702
+ };
1703
+ /**
1704
+ * Calculate a rotation matrix from a quaternion.
1705
+ * @param quaternion - The quaternion used to calculate the matrix
1706
+ * @param out - The calculated rotation matrix
1707
+ */ Matrix3x3.rotationQuaternion = function rotationQuaternion(quaternion, out) {
1708
+ var oe = out.elements;
1709
+ var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
1710
+ var x2 = x + x;
1711
+ var y2 = y + y;
1712
+ var z2 = z + z;
1713
+ var xx = x * x2;
1714
+ var yx = y * x2;
1715
+ var yy = y * y2;
1716
+ var zx = z * x2;
1717
+ var zy = z * y2;
1718
+ var zz = z * z2;
1719
+ var wx = w * x2;
1720
+ var wy = w * y2;
1721
+ var wz = w * z2;
1722
+ oe[0] = 1 - yy - zz;
1723
+ oe[3] = yx - wz;
1724
+ oe[6] = zx + wy;
1725
+ oe[1] = yx + wz;
1726
+ oe[4] = 1 - xx - zz;
1727
+ oe[7] = zy - wx;
1728
+ oe[2] = zx - wy;
1729
+ oe[5] = zy + wx;
1730
+ oe[8] = 1 - xx - yy;
1731
+ };
1732
+ /**
1733
+ * Calculate a matrix from scale vector.
1734
+ * @param s - The scale vector
1735
+ * @param out - The calculated matrix
1736
+ */ Matrix3x3.scaling = function scaling(s, out) {
1737
+ var oe = out.elements;
1738
+ oe[0] = s._x;
1739
+ oe[1] = 0;
1740
+ oe[2] = 0;
1741
+ oe[3] = 0;
1742
+ oe[4] = s._y;
1743
+ oe[5] = 0;
1744
+ oe[6] = 0;
1745
+ oe[7] = 0;
1746
+ oe[8] = 1;
1747
+ };
1748
+ /**
1749
+ * Calculate a matrix from translation vector.
1750
+ * @param translation - The translation vector
1751
+ * @param out - The calculated matrix
1752
+ */ Matrix3x3.translation = function translation(translation, out) {
1753
+ var oe = out.elements;
1754
+ oe[0] = 1;
1755
+ oe[1] = 0;
1756
+ oe[2] = 0;
1757
+ oe[3] = 0;
1758
+ oe[4] = 1;
1759
+ oe[5] = 0;
1760
+ oe[6] = translation._x;
1761
+ oe[7] = translation._y;
1762
+ oe[8] = 1;
1763
+ };
1764
+ /**
1765
+ * Calculate the inverse of the specified matrix.
1766
+ * @param a - The matrix whose inverse is to be calculated
1767
+ * @param out - The inverse of the specified matrix
1768
+ */ Matrix3x3.invert = function invert(a, out) {
1769
+ var ae = a.elements;
1770
+ var oe = out.elements;
1771
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2];
1772
+ var a21 = ae[3], a22 = ae[4], a23 = ae[5];
1773
+ var a31 = ae[6], a32 = ae[7], a33 = ae[8];
1774
+ var b12 = a33 * a22 - a23 * a32;
1775
+ var b22 = -a33 * a21 + a23 * a31;
1776
+ var b32 = a32 * a21 - a22 * a31;
1777
+ var det = a11 * b12 + a12 * b22 + a13 * b32;
1778
+ if (!det) {
1779
+ return;
1780
+ }
1781
+ det = 1.0 / det;
1782
+ oe[0] = b12 * det;
1783
+ oe[1] = (-a33 * a12 + a13 * a32) * det;
1784
+ oe[2] = (a23 * a12 - a13 * a22) * det;
1785
+ oe[3] = b22 * det;
1786
+ oe[4] = (a33 * a11 - a13 * a31) * det;
1787
+ oe[5] = (-a23 * a11 + a13 * a21) * det;
1788
+ oe[6] = b32 * det;
1789
+ oe[7] = (-a32 * a11 + a12 * a31) * det;
1790
+ oe[8] = (a22 * a11 - a12 * a21) * det;
1791
+ };
1792
+ /**
1793
+ * Calculate a 3x3 normal matrix from a 4x4 matrix.
1794
+ * @remarks The calculation process is the transpose matrix of the inverse matrix.
1795
+ * @param mat4 - The 4x4 matrix
1796
+ * @param out - THe 3x3 normal matrix
1797
+ */ Matrix3x3.normalMatrix = function normalMatrix(mat4, out) {
1798
+ var ae = mat4.elements;
1799
+ var oe = out.elements;
1800
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2], a14 = ae[3];
1801
+ var a21 = ae[4], a22 = ae[5], a23 = ae[6], a24 = ae[7];
1802
+ var a31 = ae[8], a32 = ae[9], a33 = ae[10], a34 = ae[11];
1803
+ var a41 = ae[12], a42 = ae[13], a43 = ae[14], a44 = ae[15];
1804
+ var b00 = a11 * a22 - a12 * a21;
1805
+ var b01 = a11 * a23 - a13 * a21;
1806
+ var b02 = a11 * a24 - a14 * a21;
1807
+ var b03 = a12 * a23 - a13 * a22;
1808
+ var b04 = a12 * a24 - a14 * a22;
1809
+ var b05 = a13 * a24 - a14 * a23;
1810
+ var b06 = a31 * a42 - a32 * a41;
1811
+ var b07 = a31 * a43 - a33 * a41;
1812
+ var b08 = a31 * a44 - a34 * a41;
1813
+ var b09 = a32 * a43 - a33 * a42;
1814
+ var b10 = a32 * a44 - a34 * a42;
1815
+ var b11 = a33 * a44 - a34 * a43;
1816
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1817
+ if (!det) {
1818
+ return null;
1819
+ }
1820
+ det = 1.0 / det;
1821
+ oe[0] = (a22 * b11 - a23 * b10 + a24 * b09) * det;
1822
+ oe[1] = (a23 * b08 - a21 * b11 - a24 * b07) * det;
1823
+ oe[2] = (a21 * b10 - a22 * b08 + a24 * b06) * det;
1824
+ oe[3] = (a13 * b10 - a12 * b11 - a14 * b09) * det;
1825
+ oe[4] = (a11 * b11 - a13 * b08 + a14 * b07) * det;
1826
+ oe[5] = (a12 * b08 - a11 * b10 - a14 * b06) * det;
1827
+ oe[6] = (a42 * b05 - a43 * b04 + a44 * b03) * det;
1828
+ oe[7] = (a43 * b02 - a41 * b05 - a44 * b01) * det;
1829
+ oe[8] = (a41 * b04 - a42 * b02 + a44 * b00) * det;
1830
+ };
1831
+ /**
1832
+ * The specified matrix rotates around an angle.
1833
+ * @param a - The specified matrix
1834
+ * @param r - The rotation angle in radians
1835
+ * @param out - The rotated matrix
1836
+ */ Matrix3x3.rotate = function rotate(a, r, out) {
1837
+ var ae = a.elements;
1838
+ var oe = out.elements;
1839
+ var s = Math.sin(r);
1840
+ var c = Math.cos(r);
1841
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2];
1842
+ var a21 = ae[3], a22 = ae[4], a23 = ae[5];
1843
+ var a31 = ae[6], a32 = ae[7], a33 = ae[8];
1844
+ oe[0] = c * a11 + s * a21;
1845
+ oe[1] = c * a12 + s * a22;
1846
+ oe[2] = c * a13 + s * a23;
1847
+ oe[3] = c * a21 - s * a11;
1848
+ oe[4] = c * a22 - s * a12;
1849
+ oe[5] = c * a23 - s * a13;
1850
+ oe[6] = a31;
1851
+ oe[7] = a32;
1852
+ oe[8] = a33;
1853
+ };
1854
+ /**
1855
+ * Scale a matrix by a given vector.
1856
+ * @param m - The matrix
1857
+ * @param s - The given vector
1858
+ * @param out - The scaled matrix
1859
+ */ Matrix3x3.scale = function scale(m, s, out) {
1860
+ var x = s._x, y = s._y;
1861
+ var ae = m.elements;
1862
+ var oe = out.elements;
1863
+ oe[0] = x * ae[0];
1864
+ oe[1] = x * ae[1];
1865
+ oe[2] = x * ae[2];
1866
+ oe[3] = y * ae[3];
1867
+ oe[4] = y * ae[4];
1868
+ oe[5] = y * ae[5];
1869
+ oe[6] = ae[6];
1870
+ oe[7] = ae[7];
1871
+ oe[8] = ae[8];
1872
+ };
1873
+ /**
1874
+ * Translate a matrix by a given vector.
1875
+ * @param m - The matrix
1876
+ * @param translation - The given vector
1877
+ * @param out - The translated matrix
1878
+ */ Matrix3x3.translate = function translate(m, translation, out) {
1879
+ var x = translation._x, y = translation._y;
1880
+ var ae = m.elements;
1881
+ var oe = out.elements;
1882
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2];
1883
+ var a21 = ae[3], a22 = ae[4], a23 = ae[5];
1884
+ var a31 = ae[6], a32 = ae[7], a33 = ae[8];
1885
+ oe[0] = a11;
1886
+ oe[1] = a12;
1887
+ oe[2] = a13;
1888
+ oe[3] = a21;
1889
+ oe[4] = a22;
1890
+ oe[5] = a23;
1891
+ oe[6] = x * a11 + y * a21 + a31;
1892
+ oe[7] = x * a12 + y * a22 + a32;
1893
+ oe[8] = x * a13 + y * a23 + a33;
1894
+ };
1895
+ /**
1896
+ * Calculate the transpose of the specified matrix.
1897
+ * @param a - The specified matrix
1898
+ * @param out - The transpose of the specified matrix
1899
+ */ Matrix3x3.transpose = function transpose(a, out) {
1900
+ var ae = a.elements;
1901
+ var oe = out.elements;
1902
+ if (out === a) {
1903
+ var a12 = ae[1];
1904
+ var a13 = ae[2];
1905
+ var a23 = ae[5];
1906
+ oe[1] = ae[3];
1907
+ oe[2] = ae[6];
1908
+ oe[3] = a12;
1909
+ oe[5] = ae[7];
1910
+ oe[6] = a13;
1911
+ oe[7] = a23;
1912
+ } else {
1913
+ oe[0] = ae[0];
1914
+ oe[1] = ae[3];
1915
+ oe[2] = ae[6];
1916
+ oe[3] = ae[1];
1917
+ oe[4] = ae[4];
1918
+ oe[5] = ae[7];
1919
+ oe[6] = ae[2];
1920
+ oe[7] = ae[5];
1921
+ oe[8] = ae[8];
1922
+ }
1923
+ };
1924
+ return Matrix3x3;
1925
+ }();
1926
+
1927
+ /**
1928
+ * Represents a four dimensional mathematical quaternion.
1929
+ */ var Quaternion = /*#__PURE__*/ function() {
1930
+ function Quaternion(x, y, z, w) {
1931
+ if (x === void 0) x = 0;
1932
+ if (y === void 0) y = 0;
1933
+ if (z === void 0) z = 0;
1934
+ if (w === void 0) w = 1;
1935
+ /** @internal */ this._onValueChanged = null;
1936
+ this._x = x;
1937
+ this._y = y;
1938
+ this._z = z;
1939
+ this._w = w;
1940
+ }
1941
+ var _proto = Quaternion.prototype;
1942
+ /**
1943
+ * Set the value of this quaternion, and return this quaternion.
1944
+ * @param x - The x component of the quaternion
1945
+ * @param y - The y component of the quaternion
1946
+ * @param z - The z component of the quaternion
1947
+ * @param w - The w component of the quaternion
1948
+ * @returns This quaternion
1949
+ */ _proto.set = function set(x, y, z, w) {
1950
+ this._x = x;
1951
+ this._y = y;
1952
+ this._z = z;
1953
+ this._w = w;
1954
+ this._onValueChanged && this._onValueChanged();
1955
+ return this;
1956
+ };
1957
+ /**
1958
+ * Transforms this quaternion into its conjugated version.
1959
+ * @returns This quaternion
1960
+ */ _proto.conjugate = function conjugate() {
1961
+ this._x *= -1;
1962
+ this._y *= -1;
1963
+ this._z *= -1;
1964
+ this._onValueChanged && this._onValueChanged();
1965
+ return this;
1966
+ };
1967
+ /**
1968
+ * Get the rotation axis and rotation angle of the quaternion (unit: radians).
1969
+ * @param out - The axis as an output parameter
1970
+ * @returns The rotation angle (unit: radians)
1971
+ */ _proto.getAxisAngle = function getAxisAngle(out) {
1972
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z;
1973
+ var length = _x * _x + _y * _y + _z * _z;
1974
+ if (length < MathUtil.zeroTolerance) {
1975
+ out._x = 1;
1976
+ out._y = 0;
1977
+ out._z = 0;
1978
+ return 0;
1979
+ } else {
1980
+ var inv = 1.0 / length;
1981
+ out._x = this._x * inv;
1982
+ out._y = this._y * inv;
1983
+ out._z = this._z * inv;
1984
+ return Math.acos(this._w) * 2.0;
1985
+ }
1986
+ };
1987
+ /**
1988
+ * Identity this quaternion.
1989
+ * @returns This quaternion after identity
1990
+ */ _proto.identity = function identity() {
1991
+ this._x = 0;
1992
+ this._y = 0;
1993
+ this._z = 0;
1994
+ this._w = 1;
1995
+ this._onValueChanged && this._onValueChanged();
1996
+ return this;
1997
+ };
1998
+ /**
1999
+ * Calculate the length of this quaternion.
2000
+ * @returns The length of this quaternion
2001
+ */ _proto.length = function length() {
2002
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
2003
+ return Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
2004
+ };
2005
+ /**
2006
+ * Calculates the squared length of this quaternion.
2007
+ * @returns The squared length of this quaternion
2008
+ */ _proto.lengthSquared = function lengthSquared() {
2009
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
2010
+ return _x * _x + _y * _y + _z * _z + _w * _w;
2011
+ };
2012
+ /**
2013
+ * Converts this quaternion into a unit quaternion.
2014
+ * @returns This quaternion
2015
+ */ _proto.normalize = function normalize() {
2016
+ Quaternion.normalize(this, this);
2017
+ return this;
2018
+ };
2019
+ /**
2020
+ * Get the euler of this quaternion.
2021
+ * @param out - The euler (in radians) as an output parameter
2022
+ * @returns Euler x->pitch y->yaw z->roll
2023
+ */ _proto.toEuler = function toEuler(out) {
2024
+ this._toYawPitchRoll(out);
2025
+ var t = out._x;
2026
+ out._x = out._y;
2027
+ out._y = t;
2028
+ out._onValueChanged && out._onValueChanged();
2029
+ return out;
2030
+ };
2031
+ /**
2032
+ * Get the euler of this quaternion.
2033
+ * @param out - The euler (in radians) as an output parameter
2034
+ * @returns Euler x->yaw y->pitch z->roll
2035
+ */ _proto.toYawPitchRoll = function toYawPitchRoll(out) {
2036
+ this._toYawPitchRoll(out);
2037
+ out._onValueChanged && out._onValueChanged();
2038
+ return out;
2039
+ };
2040
+ /**
2041
+ * Calculate this quaternion rotate around X axis.
2042
+ * @param rad - The rotation angle in radians
2043
+ * @returns This quaternion
2044
+ */ _proto.rotateX = function rotateX(rad) {
2045
+ Quaternion.rotateX(this, rad, this);
2046
+ return this;
2047
+ };
2048
+ /**
2049
+ * Calculate this quaternion rotate around Y axis.
2050
+ * @param rad - The rotation angle in radians
2051
+ * @returns This quaternion
2052
+ */ _proto.rotateY = function rotateY(rad) {
2053
+ Quaternion.rotateY(this, rad, this);
2054
+ return this;
2055
+ };
2056
+ /**
2057
+ * Calculate this quaternion rotate around Z axis.
2058
+ * @param rad - The rotation angle in radians
2059
+ * @returns This quaternion
2060
+ */ _proto.rotateZ = function rotateZ(rad) {
2061
+ Quaternion.rotateZ(this, rad, this);
2062
+ return this;
2063
+ };
2064
+ /**
2065
+ * Calculate this quaternion rotates around an arbitrary axis.
2066
+ * @param axis - The axis
2067
+ * @param rad - The rotation angle in radians
2068
+ * @returns This quaternion
2069
+ */ _proto.rotationAxisAngle = function rotationAxisAngle(axis, rad) {
2070
+ Quaternion.rotationAxisAngle(axis, rad, this);
2071
+ return this;
2072
+ };
2073
+ /**
2074
+ * Determines the product of this quaternion and the specified quaternion.
2075
+ * @param quat - The specified quaternion
2076
+ * @returns The product of the two quaternions
2077
+ */ _proto.multiply = function multiply(quat) {
2078
+ Quaternion.multiply(this, quat, this);
2079
+ return this;
2080
+ };
2081
+ /**
2082
+ * Invert this quaternion.
2083
+ * @returns This quaternion after invert
2084
+ */ _proto.invert = function invert() {
2085
+ Quaternion.invert(this, this);
2086
+ return this;
2087
+ };
2088
+ /**
2089
+ * Determines the dot product of this quaternion and the specified quaternion.
2090
+ * @param quat - The specified quaternion
2091
+ * @returns The dot product of two quaternions
2092
+ */ _proto.dot = function dot(quat) {
2093
+ return Quaternion.dot(this, quat);
2094
+ };
2095
+ /**
2096
+ * Performs a linear blend between this quaternion and the specified quaternion.
2097
+ * @param quat - The specified quaternion
2098
+ * @param t - The blend amount where 0 returns this and 1 quat
2099
+ * @returns - The result of linear blending between two quaternions
2100
+ */ _proto.lerp = function lerp(quat, t) {
2101
+ Quaternion.lerp(this, quat, t, this);
2102
+ return this;
2103
+ };
2104
+ /**
2105
+ * Calculate this quaternion rotation around an arbitrary axis.
2106
+ * @param axis - The axis
2107
+ * @param rad - The rotation angle in radians
2108
+ * @returns This quaternion
2109
+ */ _proto.rotateAxisAngle = function rotateAxisAngle(axis, rad) {
2110
+ Quaternion._tempQuat1.rotationAxisAngle(axis, rad);
2111
+ this.multiply(Quaternion._tempQuat1);
2112
+ return this;
2113
+ };
2114
+ /**
2115
+ * Creates a clone of this quaternion.
2116
+ * @returns A clone of this quaternion
2117
+ */ _proto.clone = function clone() {
2118
+ return new Quaternion(this._x, this._y, this._z, this._w);
2119
+ };
2120
+ /**
2121
+ * Copy this quaternion from the specified quaternion.
2122
+ * @param source - The specified quaternion
2123
+ * @returns This quaternion
2124
+ */ _proto.copyFrom = function copyFrom(source) {
2125
+ this._x = source.x;
2126
+ this._y = source.y;
2127
+ this._z = source.z;
2128
+ this._w = source.w;
2129
+ this._onValueChanged && this._onValueChanged();
2130
+ return this;
2131
+ };
2132
+ /**
2133
+ * Copy the value of this quaternion from an array.
2134
+ * @param array - The array
2135
+ * @param offset - The start offset of the array
2136
+ * @returns This quaternion
2137
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
2138
+ if (offset === void 0) offset = 0;
2139
+ this._x = array[offset];
2140
+ this._y = array[offset + 1];
2141
+ this._z = array[offset + 2];
2142
+ this._w = array[offset + 3];
2143
+ this._onValueChanged && this._onValueChanged();
2144
+ return this;
2145
+ };
2146
+ /**
2147
+ * Copy the value of this quaternion to an array.
2148
+ * @param out - The array
2149
+ * @param outOffset - The start offset of the array
2150
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
2151
+ if (outOffset === void 0) outOffset = 0;
2152
+ out[outOffset] = this._x;
2153
+ out[outOffset + 1] = this._y;
2154
+ out[outOffset + 2] = this._z;
2155
+ out[outOffset + 3] = this._w;
2156
+ };
2157
+ /**
2158
+ * Serialize this quaternion to a JSON representation.
2159
+ * @returns A JSON Object representation of this quaternion
2160
+ */ _proto.toJSON = function toJSON() {
2161
+ return {
2162
+ x: this._x,
2163
+ y: this._y,
2164
+ z: this._z,
2165
+ w: this._w
2166
+ };
2167
+ };
2168
+ _proto._toYawPitchRoll = function _toYawPitchRoll(out) {
2169
+ // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
2170
+ var _this = this, x = _this._x, y = _this._y, z = _this._z, w = _this._w;
2171
+ var xx = x * x;
2172
+ var sinP = 2.0 * (x * w - y * z);
2173
+ // use 90 degrees if out of range
2174
+ out._y = Math.abs(sinP) >= 1 ? Math.sign(sinP) * (Math.PI / 2) : Math.asin(sinP);
2175
+ out._x = Math.atan2(2.0 * (z * x + y * w), 1.0 - 2.0 * (y * y + xx));
2176
+ out._z = Math.atan2(2.0 * (x * y + z * w), 1.0 - 2.0 * (z * z + xx));
2177
+ };
2178
+ /**
2179
+ * Determines the sum of two quaternions.
2180
+ * @param left - The first quaternion to add
2181
+ * @param right - The second quaternion to add
2182
+ * @param out - The sum of two quaternions
2183
+ */ Quaternion.add = function add(left, right, out) {
2184
+ out._x = left._x + right._x;
2185
+ out._y = left._y + right._y;
2186
+ out._z = left._z + right._z;
2187
+ out._w = left._w + right._w;
2188
+ out._onValueChanged && out._onValueChanged();
2189
+ };
2190
+ /**
2191
+ * Determines the product of two quaternions.
2192
+ * @param left - The first quaternion to multiply
2193
+ * @param right - The second quaternion to multiply
2194
+ * @param out - The product of two quaternions
2195
+ */ Quaternion.multiply = function multiply(left, right, out) {
2196
+ var ax = left._x, ay = left._y, az = left._z, aw = left._w;
2197
+ var bx = right._x, by = right._y, bz = right._z, bw = right._w;
2198
+ out._x = ax * bw + aw * bx + ay * bz - az * by;
2199
+ out._y = ay * bw + aw * by + az * bx - ax * bz;
2200
+ out._z = az * bw + aw * bz + ax * by - ay * bx;
2201
+ out._w = aw * bw - ax * bx - ay * by - az * bz;
2202
+ out._onValueChanged && out._onValueChanged();
2203
+ };
2204
+ /**
2205
+ * Calculate quaternion that contains conjugated version of the specified quaternion.
2206
+ * @param a - The specified quaternion
2207
+ * @param out - The conjugate version of the specified quaternion
2208
+ */ Quaternion.conjugate = function conjugate(a, out) {
2209
+ out._x = -a._x;
2210
+ out._y = -a._y;
2211
+ out._z = -a._z;
2212
+ out._w = a._w;
2213
+ out._onValueChanged && out._onValueChanged();
2214
+ };
2215
+ /**
2216
+ * Determines the dot product of two quaternions.
2217
+ * @param left - The first quaternion to dot
2218
+ * @param right - The second quaternion to dot
2219
+ * @returns The dot product of two quaternions
2220
+ */ Quaternion.dot = function dot(left, right) {
2221
+ return left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;
2222
+ };
2223
+ /**
2224
+ * Determines whether the specified quaternions are equals.
2225
+ * @param left - The first quaternion to compare
2226
+ * @param right - The second quaternion to compare
2227
+ * @returns True if the specified quaternions are equals, false otherwise
2228
+ */ Quaternion.equals = function equals(left, right) {
2229
+ return MathUtil.equals(left._x, right._x) && MathUtil.equals(left._y, right._y) && MathUtil.equals(left._z, right._z) && MathUtil.equals(left._w, right._w);
2230
+ };
2231
+ /**
2232
+ * Calculate a quaternion rotates around an arbitrary axis.
2233
+ * @param axis - The axis
2234
+ * @param rad - The rotation angle in radians
2235
+ * @param out - The quaternion after rotate
2236
+ */ Quaternion.rotationAxisAngle = function rotationAxisAngle(axis, rad, out) {
2237
+ var normalAxis = Quaternion._tempVector3;
2238
+ Vector3.normalize(axis, normalAxis);
2239
+ rad *= 0.5;
2240
+ var s = Math.sin(rad);
2241
+ out._x = normalAxis._x * s;
2242
+ out._y = normalAxis._y * s;
2243
+ out._z = normalAxis._z * s;
2244
+ out._w = Math.cos(rad);
2245
+ out._onValueChanged && out._onValueChanged();
2246
+ };
2247
+ /**
2248
+ * Calculate a quaternion rotates around x, y, z axis (pitch/yaw/roll).
2249
+ * @param x - The radian of rotation around X (pitch)
2250
+ * @param y - The radian of rotation around Y (yaw)
2251
+ * @param z - The radian of rotation around Z (roll)
2252
+ * @param out - The calculated quaternion
2253
+ */ Quaternion.rotationEuler = function rotationEuler(x, y, z, out) {
2254
+ Quaternion.rotationYawPitchRoll(y, x, z, out);
2255
+ };
2256
+ /**
2257
+ * Calculate a quaternion from the specified yaw, pitch and roll angles.
2258
+ * @param yaw - Yaw around the y axis in radians
2259
+ * @param pitch - Pitch around the x axis in radians
2260
+ * @param roll - Roll around the z axis in radians
2261
+ * @param out - The calculated quaternion
2262
+ */ Quaternion.rotationYawPitchRoll = function rotationYawPitchRoll(yaw, pitch, roll, out) {
2263
+ var halfRoll = roll * 0.5;
2264
+ var halfPitch = pitch * 0.5;
2265
+ var halfYaw = yaw * 0.5;
2266
+ var sinRoll = Math.sin(halfRoll);
2267
+ var cosRoll = Math.cos(halfRoll);
2268
+ var sinPitch = Math.sin(halfPitch);
2269
+ var cosPitch = Math.cos(halfPitch);
2270
+ var sinYaw = Math.sin(halfYaw);
2271
+ var cosYaw = Math.cos(halfYaw);
2272
+ var cosYawPitch = cosYaw * cosPitch;
2273
+ var sinYawPitch = sinYaw * sinPitch;
2274
+ out._x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;
2275
+ out._y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
2276
+ out._z = cosYawPitch * sinRoll - sinYawPitch * cosRoll;
2277
+ out._w = cosYawPitch * cosRoll + sinYawPitch * sinRoll;
2278
+ out._onValueChanged && out._onValueChanged();
2279
+ };
2280
+ /**
2281
+ * Calculate a quaternion from the specified 3x3 matrix.
2282
+ * @param m - The specified 3x3 matrix
2283
+ * @param out - The calculated quaternion
2284
+ */ Quaternion.rotationMatrix3x3 = function rotationMatrix3x3(m, out) {
2285
+ var me = m.elements;
2286
+ var m11 = me[0], m12 = me[1], m13 = me[2];
2287
+ var m21 = me[3], m22 = me[4], m23 = me[5];
2288
+ var m31 = me[6], m32 = me[7], m33 = me[8];
2289
+ var scale = m11 + m22 + m33;
2290
+ var sqrt, half;
2291
+ if (scale > 0) {
2292
+ sqrt = Math.sqrt(scale + 1.0);
2293
+ out._w = sqrt * 0.5;
2294
+ sqrt = 0.5 / sqrt;
2295
+ out._x = (m23 - m32) * sqrt;
2296
+ out._y = (m31 - m13) * sqrt;
2297
+ out._z = (m12 - m21) * sqrt;
2298
+ } else if (m11 >= m22 && m11 >= m33) {
2299
+ sqrt = Math.sqrt(1.0 + m11 - m22 - m33);
2300
+ half = 0.5 / sqrt;
2301
+ out._x = 0.5 * sqrt;
2302
+ out._y = (m12 + m21) * half;
2303
+ out._z = (m13 + m31) * half;
2304
+ out._w = (m23 - m32) * half;
2305
+ } else if (m22 > m33) {
2306
+ sqrt = Math.sqrt(1.0 + m22 - m11 - m33);
2307
+ half = 0.5 / sqrt;
2308
+ out._x = (m21 + m12) * half;
2309
+ out._y = 0.5 * sqrt;
2310
+ out._z = (m32 + m23) * half;
2311
+ out._w = (m31 - m13) * half;
2312
+ } else {
2313
+ sqrt = Math.sqrt(1.0 + m33 - m11 - m22);
2314
+ half = 0.5 / sqrt;
2315
+ out._x = (m13 + m31) * half;
2316
+ out._y = (m23 + m32) * half;
2317
+ out._z = 0.5 * sqrt;
2318
+ out._w = (m12 - m21) * half;
2319
+ }
2320
+ out._onValueChanged && out._onValueChanged();
2321
+ };
2322
+ /**
2323
+ * Calculate the inverse of the specified quaternion.
2324
+ * @param a - The quaternion whose inverse is to be calculated
2325
+ * @param out - The inverse of the specified quaternion
2326
+ */ Quaternion.invert = function invert(a, out) {
2327
+ var x = a._x, y = a._y, z = a._z, w = a._w;
2328
+ var dot = x * x + y * y + z * z + w * w;
2329
+ if (dot > MathUtil.zeroTolerance) {
2330
+ var invDot = 1.0 / dot;
2331
+ out._x = -x * invDot;
2332
+ out._y = -y * invDot;
2333
+ out._z = -z * invDot;
2334
+ out._w = w * invDot;
2335
+ out._onValueChanged && out._onValueChanged();
2336
+ }
2337
+ };
2338
+ /**
2339
+ * Performs a linear blend between two quaternions.
2340
+ * @param start - The first quaternion
2341
+ * @param end - The second quaternion
2342
+ * @param t - The blend amount where 0 returns start and 1 end
2343
+ * @param out - The result of linear blending between two quaternions
2344
+ */ Quaternion.lerp = function lerp(start, end, t, out) {
2345
+ var inv = 1.0 - t;
2346
+ if (Quaternion.dot(start, end) >= 0) {
2347
+ out._x = start._x * inv + end._x * t;
2348
+ out._y = start._y * inv + end._y * t;
2349
+ out._z = start._z * inv + end._z * t;
2350
+ out._w = start._w * inv + end._w * t;
2351
+ } else {
2352
+ out._x = start._x * inv - end._x * t;
2353
+ out._y = start._y * inv - end._y * t;
2354
+ out._z = start._z * inv - end._z * t;
2355
+ out._w = start._w * inv - end._w * t;
2356
+ }
2357
+ out.normalize();
2358
+ };
2359
+ /**
2360
+ * Performs a spherical linear blend between two quaternions.
2361
+ * @param start - The first quaternion
2362
+ * @param end - The second quaternion
2363
+ * @param amount - The blend amount where 0 returns start and 1 end
2364
+ * @param out - The result of spherical linear blending between two quaternions
2365
+ */ Quaternion.slerp = function slerp(start, end, amount, out) {
2366
+ var opposite;
2367
+ var inverse;
2368
+ var dot = Quaternion.dot(start, end);
2369
+ if (Math.abs(dot) > 1.0 - MathUtil.zeroTolerance) {
2370
+ inverse = 1.0 - amount;
2371
+ opposite = amount * Math.sign(dot);
2372
+ } else {
2373
+ var acos = Math.acos(Math.abs(dot));
2374
+ var invSin = 1.0 / Math.sin(acos);
2375
+ inverse = Math.sin((1.0 - amount) * acos) * invSin;
2376
+ opposite = Math.sin(amount * acos) * invSin * Math.sign(dot);
2377
+ }
2378
+ out.x = inverse * start.x + opposite * end.x;
2379
+ out.y = inverse * start.y + opposite * end.y;
2380
+ out.z = inverse * start.z + opposite * end.z;
2381
+ out.w = inverse * start.w + opposite * end.w;
2382
+ out._onValueChanged && out._onValueChanged();
2383
+ };
2384
+ /**
2385
+ * Scales the specified quaternion magnitude to unit length.
2386
+ * @param a - The specified quaternion
2387
+ * @param out - The normalized quaternion
2388
+ */ Quaternion.normalize = function normalize(a, out) {
2389
+ var _x = a._x, _y = a._y, _z = a._z, _w = a._w;
2390
+ var len = Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
2391
+ if (len > MathUtil.zeroTolerance) {
2392
+ len = 1 / len;
2393
+ out._x = _x * len;
2394
+ out._y = _y * len;
2395
+ out._z = _z * len;
2396
+ out._w = _w * len;
2397
+ out._onValueChanged && out._onValueChanged();
2398
+ }
2399
+ };
2400
+ /**
2401
+ * Calculate a quaternion rotate around X axis.
2402
+ * @param rad - The rotation angle in radians
2403
+ * @param out - The calculated quaternion
2404
+ */ Quaternion.rotationX = function rotationX(rad, out) {
2405
+ rad *= 0.5;
2406
+ var s = Math.sin(rad);
2407
+ var c = Math.cos(rad);
2408
+ out._x = s;
2409
+ out._y = 0;
2410
+ out._z = 0;
2411
+ out._w = c;
2412
+ out._onValueChanged && out._onValueChanged();
2413
+ };
2414
+ /**
2415
+ * Calculate a quaternion rotate around Y axis.
2416
+ * @param rad - The rotation angle in radians
2417
+ * @param out - The calculated quaternion
2418
+ */ Quaternion.rotationY = function rotationY(rad, out) {
2419
+ rad *= 0.5;
2420
+ var s = Math.sin(rad);
2421
+ var c = Math.cos(rad);
2422
+ out._x = 0;
2423
+ out._y = s;
2424
+ out._z = 0;
2425
+ out._w = c;
2426
+ out._onValueChanged && out._onValueChanged();
2427
+ };
2428
+ /**
2429
+ * Calculate a quaternion rotate around Z axis.
2430
+ * @param rad - The rotation angle in radians
2431
+ * @param out - The calculated quaternion
2432
+ */ Quaternion.rotationZ = function rotationZ(rad, out) {
2433
+ rad *= 0.5;
2434
+ var s = Math.sin(rad);
2435
+ var c = Math.cos(rad);
2436
+ out._x = 0;
2437
+ out._y = 0;
2438
+ out._z = s;
2439
+ out._w = c;
2440
+ out._onValueChanged && out._onValueChanged();
2441
+ };
2442
+ /**
2443
+ * Calculate a quaternion that the specified quaternion rotate around X axis.
2444
+ * @param quaternion - The specified quaternion
2445
+ * @param rad - The rotation angle in radians
2446
+ * @param out - The calculated quaternion
2447
+ */ Quaternion.rotateX = function rotateX(quaternion, rad, out) {
2448
+ var _x = quaternion._x, _y = quaternion._y, _z = quaternion._z, _w = quaternion._w;
2449
+ rad *= 0.5;
2450
+ var bx = Math.sin(rad);
2451
+ var bw = Math.cos(rad);
2452
+ out._x = _x * bw + _w * bx;
2453
+ out._y = _y * bw + _z * bx;
2454
+ out._z = _z * bw - _y * bx;
2455
+ out._w = _w * bw - _x * bx;
2456
+ out._onValueChanged && out._onValueChanged();
2457
+ };
2458
+ /**
2459
+ * Calculate a quaternion that the specified quaternion rotate around Y axis.
2460
+ * @param quaternion - The specified quaternion
2461
+ * @param rad - The rotation angle in radians
2462
+ * @param out - The calculated quaternion
2463
+ */ Quaternion.rotateY = function rotateY(quaternion, rad, out) {
2464
+ var _x = quaternion._x, _y = quaternion._y, _z = quaternion._z, _w = quaternion._w;
2465
+ rad *= 0.5;
2466
+ var by = Math.sin(rad);
2467
+ var bw = Math.cos(rad);
2468
+ out._x = _x * bw - _z * by;
2469
+ out._y = _y * bw + _w * by;
2470
+ out._z = _z * bw + _x * by;
2471
+ out._w = _w * bw - _y * by;
2472
+ out._onValueChanged && out._onValueChanged();
2473
+ };
2474
+ /**
2475
+ * Calculate a quaternion that the specified quaternion rotate around Z axis.
2476
+ * @param quaternion - The specified quaternion
2477
+ * @param rad - The rotation angle in radians
2478
+ * @param out - The calculated quaternion
2479
+ */ Quaternion.rotateZ = function rotateZ(quaternion, rad, out) {
2480
+ var _x = quaternion._x, _y = quaternion._y, _z = quaternion._z, _w = quaternion._w;
2481
+ rad *= 0.5;
2482
+ var bz = Math.sin(rad);
2483
+ var bw = Math.cos(rad);
2484
+ out._x = _x * bw + _y * bz;
2485
+ out._y = _y * bw - _x * bz;
2486
+ out._z = _z * bw + _w * bz;
2487
+ out._w = _w * bw - _z * bz;
2488
+ out._onValueChanged && out._onValueChanged();
2489
+ };
2490
+ /**
2491
+ * Scale a quaternion by a given number.
2492
+ * @param a - The quaternion
2493
+ * @param s - The given number
2494
+ * @param out - The scaled quaternion
2495
+ */ Quaternion.scale = function scale(a, s, out) {
2496
+ out._x = a._x * s;
2497
+ out._y = a._y * s;
2498
+ out._z = a._z * s;
2499
+ out._w = a._w * s;
2500
+ out._onValueChanged && out._onValueChanged();
2501
+ };
2502
+ _createClass(Quaternion, [
2503
+ {
2504
+ key: "x",
2505
+ get: /**
2506
+ * The x component of the quaternion.
2507
+ */ function get() {
2508
+ return this._x;
2509
+ },
2510
+ set: function set(value) {
2511
+ this._x = value;
2512
+ this._onValueChanged && this._onValueChanged();
2513
+ }
2514
+ },
2515
+ {
2516
+ key: "y",
2517
+ get: /**
2518
+ * The y component of the quaternion.
2519
+ */ function get() {
2520
+ return this._y;
2521
+ },
2522
+ set: function set(value) {
2523
+ this._y = value;
2524
+ this._onValueChanged && this._onValueChanged();
2525
+ }
2526
+ },
2527
+ {
2528
+ key: "z",
2529
+ get: /**
2530
+ * The z component of the quaternion.
2531
+ */ function get() {
2532
+ return this._z;
2533
+ },
2534
+ set: function set(value) {
2535
+ this._z = value;
2536
+ this._onValueChanged && this._onValueChanged();
2537
+ }
2538
+ },
2539
+ {
2540
+ key: "normalized",
2541
+ get: /**
2542
+ * Indicting whether this instance is normalized.
2543
+ */ function get() {
2544
+ return Math.abs(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w - 1) < MathUtil.zeroTolerance;
2545
+ }
2546
+ },
2547
+ {
2548
+ key: "w",
2549
+ get: /**
2550
+ * The w component of the quaternion.
2551
+ */ function get() {
2552
+ return this._w;
2553
+ },
2554
+ set: function set(value) {
2555
+ this._w = value;
2556
+ this._onValueChanged && this._onValueChanged();
2557
+ }
2558
+ }
2559
+ ]);
2560
+ return Quaternion;
2561
+ }();
2562
+ /** @internal */ Quaternion._tempVector3 = new Vector3();
2563
+ /** @internal */ Quaternion._tempQuat1 = new Quaternion();
2564
+
2565
+ /**
2566
+ * Represents a 4x4 mathematical matrix.
2567
+ */ var Matrix = /*#__PURE__*/ function() {
2568
+ function Matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
2569
+ if (m11 === void 0) m11 = 1;
2570
+ if (m12 === void 0) m12 = 0;
2571
+ if (m13 === void 0) m13 = 0;
2572
+ if (m14 === void 0) m14 = 0;
2573
+ if (m21 === void 0) m21 = 0;
2574
+ if (m22 === void 0) m22 = 1;
2575
+ if (m23 === void 0) m23 = 0;
2576
+ if (m24 === void 0) m24 = 0;
2577
+ if (m31 === void 0) m31 = 0;
2578
+ if (m32 === void 0) m32 = 0;
2579
+ if (m33 === void 0) m33 = 1;
2580
+ if (m34 === void 0) m34 = 0;
2581
+ if (m41 === void 0) m41 = 0;
2582
+ if (m42 === void 0) m42 = 0;
2583
+ if (m43 === void 0) m43 = 0;
2584
+ if (m44 === void 0) m44 = 1;
2585
+ /**
2586
+ * An array containing the elements of the matrix (column matrix).
2587
+ * @remarks
2588
+ * elements[0] first column and first row value m11
2589
+ * elements[1] first column and second row value m12
2590
+ * elements[2] first column and third row value m13
2591
+ * elements[3] first column and fourth row value m14
2592
+ * elements[4] second column and first row value m21
2593
+ * and so on
2594
+ */ this.elements = new Float32Array(16);
2595
+ var e = this.elements;
2596
+ e[0] = m11;
2597
+ e[1] = m12;
2598
+ e[2] = m13;
2599
+ e[3] = m14;
2600
+ e[4] = m21;
2601
+ e[5] = m22;
2602
+ e[6] = m23;
2603
+ e[7] = m24;
2604
+ e[8] = m31;
2605
+ e[9] = m32;
2606
+ e[10] = m33;
2607
+ e[11] = m34;
2608
+ e[12] = m41;
2609
+ e[13] = m42;
2610
+ e[14] = m43;
2611
+ e[15] = m44;
2612
+ }
2613
+ var _proto = Matrix.prototype;
2614
+ /**
2615
+ * Set the value of this matrix, and return this matrix.
2616
+ * @param m11 - column 1, row 1
2617
+ * @param m12 - column 1, row 2
2618
+ * @param m13 - column 1, row 3
2619
+ * @param m14 - column 1, row 4
2620
+ * @param m21 - column 2, row 1
2621
+ * @param m22 - column 2, row 2
2622
+ * @param m23 - column 2, row 3
2623
+ * @param m24 - column 2, row 4
2624
+ * @param m31 - column 3, row 1
2625
+ * @param m32 - column 3, row 2
2626
+ * @param m33 - column 3, row 3
2627
+ * @param m34 - column 3, row 4
2628
+ * @param m41 - column 4, row 1
2629
+ * @param m42 - column 4, row 2
2630
+ * @param m43 - column 4, row 3
2631
+ * @param m44 - column 4, row 4
2632
+ * @returns This matrix
2633
+ */ _proto.set = function set(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
2634
+ var e = this.elements;
2635
+ e[0] = m11;
2636
+ e[1] = m12;
2637
+ e[2] = m13;
2638
+ e[3] = m14;
2639
+ e[4] = m21;
2640
+ e[5] = m22;
2641
+ e[6] = m23;
2642
+ e[7] = m24;
2643
+ e[8] = m31;
2644
+ e[9] = m32;
2645
+ e[10] = m33;
2646
+ e[11] = m34;
2647
+ e[12] = m41;
2648
+ e[13] = m42;
2649
+ e[14] = m43;
2650
+ e[15] = m44;
2651
+ return this;
2652
+ };
2653
+ /**
2654
+ * Determines the product of this matrix and the specified matrix.
2655
+ * @param right - The specified matrix
2656
+ * @returns This matrix that store the product of the two matrices
2657
+ */ _proto.multiply = function multiply(right) {
2658
+ Matrix.multiply(this, right, this);
2659
+ return this;
2660
+ };
2661
+ /**
2662
+ * Calculate a determinant of this matrix.
2663
+ * @returns The determinant of this matrix
2664
+ */ _proto.determinant = function determinant() {
2665
+ var e = this.elements;
2666
+ var a11 = e[0], a12 = e[1], a13 = e[2], a14 = e[3];
2667
+ var a21 = e[4], a22 = e[5], a23 = e[6], a24 = e[7];
2668
+ var a31 = e[8], a32 = e[9], a33 = e[10], a34 = e[11];
2669
+ var a41 = e[12], a42 = e[13], a43 = e[14], a44 = e[15];
2670
+ var b00 = a11 * a22 - a12 * a21;
2671
+ var b01 = a11 * a23 - a13 * a21;
2672
+ var b02 = a11 * a24 - a14 * a21;
2673
+ var b03 = a12 * a23 - a13 * a22;
2674
+ var b04 = a12 * a24 - a14 * a22;
2675
+ var b05 = a13 * a24 - a14 * a23;
2676
+ var b06 = a31 * a42 - a32 * a41;
2677
+ var b07 = a31 * a43 - a33 * a41;
2678
+ var b08 = a31 * a44 - a34 * a41;
2679
+ var b09 = a32 * a43 - a33 * a42;
2680
+ var b10 = a32 * a44 - a34 * a42;
2681
+ var b11 = a33 * a44 - a34 * a43;
2682
+ // Calculate the determinant
2683
+ return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
2684
+ };
2685
+ /**
2686
+ * Decompose this matrix to translation, rotation and scale elements.
2687
+ * @param translation - Translation vector as an output parameter
2688
+ * @param rotation - Rotation quaternion as an output parameter
2689
+ * @param scale - Scale vector as an output parameter
2690
+ * @returns True if this matrix can be decomposed, false otherwise
2691
+ */ _proto.decompose = function decompose(translation, rotation, scale) {
2692
+ var rm = Matrix._tempMat30;
2693
+ var e = this.elements;
2694
+ var rme = rm.elements;
2695
+ var m11 = e[0];
2696
+ var m12 = e[1];
2697
+ var m13 = e[2];
2698
+ var m14 = e[3];
2699
+ var m21 = e[4];
2700
+ var m22 = e[5];
2701
+ var m23 = e[6];
2702
+ var m24 = e[7];
2703
+ var m31 = e[8];
2704
+ var m32 = e[9];
2705
+ var m33 = e[10];
2706
+ var m34 = e[11];
2707
+ translation.set(e[12], e[13], e[14]);
2708
+ var xs = Math.sign(m11 * m12 * m13 * m14) < 0 ? -1 : 1;
2709
+ var ys = Math.sign(m21 * m22 * m23 * m24) < 0 ? -1 : 1;
2710
+ var zs = Math.sign(m31 * m32 * m33 * m34) < 0 ? -1 : 1;
2711
+ var sx = xs * Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
2712
+ var sy = ys * Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
2713
+ var sz = zs * Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
2714
+ scale.set(sx, sy, sz);
2715
+ if (Math.abs(sx) < MathUtil.zeroTolerance || Math.abs(sy) < MathUtil.zeroTolerance || Math.abs(sz) < MathUtil.zeroTolerance) {
2716
+ rotation.identity();
2717
+ return false;
2718
+ } else {
2719
+ var invSX = 1 / sx;
2720
+ var invSY = 1 / sy;
2721
+ var invSZ = 1 / sz;
2722
+ rme[0] = m11 * invSX;
2723
+ rme[1] = m12 * invSX;
2724
+ rme[2] = m13 * invSX;
2725
+ rme[3] = m21 * invSY;
2726
+ rme[4] = m22 * invSY;
2727
+ rme[5] = m23 * invSY;
2728
+ rme[6] = m31 * invSZ;
2729
+ rme[7] = m32 * invSZ;
2730
+ rme[8] = m33 * invSZ;
2731
+ Quaternion.rotationMatrix3x3(rm, rotation);
2732
+ return true;
2733
+ }
2734
+ };
2735
+ /**
2736
+ * Get rotation from this matrix.
2737
+ * @param out - Rotation quaternion as an output parameter
2738
+ * @returns The out
2739
+ */ _proto.getRotation = function getRotation(out) {
2740
+ var e = this.elements;
2741
+ var trace = e[0] + e[5] + e[10];
2742
+ if (trace > MathUtil.zeroTolerance) {
2743
+ var s = Math.sqrt(trace + 1.0) * 2;
2744
+ out._w = 0.25 * s;
2745
+ out._x = (e[6] - e[9]) / s;
2746
+ out._y = (e[8] - e[2]) / s;
2747
+ out._z = (e[1] - e[4]) / s;
2748
+ } else if (e[0] > e[5] && e[0] > e[10]) {
2749
+ var s1 = Math.sqrt(1.0 + e[0] - e[5] - e[10]) * 2;
2750
+ out._w = (e[6] - e[9]) / s1;
2751
+ out._x = 0.25 * s1;
2752
+ out._y = (e[1] + e[4]) / s1;
2753
+ out._z = (e[8] + e[2]) / s1;
2754
+ } else if (e[5] > e[10]) {
2755
+ var s2 = Math.sqrt(1.0 + e[5] - e[0] - e[10]) * 2;
2756
+ out._w = (e[8] - e[2]) / s2;
2757
+ out._x = (e[1] + e[4]) / s2;
2758
+ out._y = 0.25 * s2;
2759
+ out._z = (e[6] + e[9]) / s2;
2760
+ } else {
2761
+ var s3 = Math.sqrt(1.0 + e[10] - e[0] - e[5]) * 2;
2762
+ out._w = (e[1] - e[4]) / s3;
2763
+ out._x = (e[8] + e[2]) / s3;
2764
+ out._y = (e[6] + e[9]) / s3;
2765
+ out._z = 0.25 * s3;
2766
+ }
2767
+ out._onValueChanged && out._onValueChanged();
2768
+ return out;
2769
+ };
2770
+ /**
2771
+ * Get scale from this matrix.
2772
+ * @param out - Scale vector as an output parameter
2773
+ * @returns The out
2774
+ */ _proto.getScaling = function getScaling(out) {
2775
+ //getScale()
2776
+ var e = this.elements;
2777
+ var m11 = e[0], m12 = e[1], m13 = e[2];
2778
+ var m21 = e[4], m22 = e[5], m23 = e[6];
2779
+ var m31 = e[8], m32 = e[9], m33 = e[10];
2780
+ out.set(Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13), Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23), Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33));
2781
+ return out;
2782
+ };
2783
+ /**
2784
+ * Get translation from this matrix.
2785
+ * @param out - Translation vector as an output parameter
2786
+ * @returns The out
2787
+ */ _proto.getTranslation = function getTranslation(out) {
2788
+ var e = this.elements;
2789
+ out.set(e[12], e[13], e[14]);
2790
+ return out;
2791
+ };
2792
+ /**
2793
+ * Identity this matrix.
2794
+ * @returns This matrix after identity
2795
+ */ _proto.identity = function identity() {
2796
+ var e = this.elements;
2797
+ e[0] = 1;
2798
+ e[1] = 0;
2799
+ e[2] = 0;
2800
+ e[3] = 0;
2801
+ e[4] = 0;
2802
+ e[5] = 1;
2803
+ e[6] = 0;
2804
+ e[7] = 0;
2805
+ e[8] = 0;
2806
+ e[9] = 0;
2807
+ e[10] = 1;
2808
+ e[11] = 0;
2809
+ e[12] = 0;
2810
+ e[13] = 0;
2811
+ e[14] = 0;
2812
+ e[15] = 1;
2813
+ return this;
2814
+ };
2815
+ /**
2816
+ * Invert the matrix.
2817
+ * @returns The matrix after invert
2818
+ */ _proto.invert = function invert() {
2819
+ Matrix.invert(this, this);
2820
+ return this;
2821
+ };
2822
+ /**
2823
+ * This matrix rotates around an arbitrary axis.
2824
+ * @param axis - The axis
2825
+ * @param r - The rotation angle in radians
2826
+ * @returns This matrix after rotate
2827
+ */ _proto.rotateAxisAngle = function rotateAxisAngle(axis, r) {
2828
+ Matrix.rotateAxisAngle(this, axis, r, this);
2829
+ return this;
2830
+ };
2831
+ /**
2832
+ * Scale this matrix by a given vector.
2833
+ * @param s - The given vector
2834
+ * @returns This matrix after scale
2835
+ */ _proto.scale = function scale(s) {
2836
+ Matrix.scale(this, s, this);
2837
+ return this;
2838
+ };
2839
+ /**
2840
+ * Translate this matrix by a given vector.
2841
+ * @param v - The given vector
2842
+ * @returns This matrix after translate
2843
+ */ _proto.translate = function translate(v) {
2844
+ Matrix.translate(this, v, this);
2845
+ return this;
2846
+ };
2847
+ /**
2848
+ * Calculate the transpose of this matrix.
2849
+ * @returns This matrix after transpose
2850
+ */ _proto.transpose = function transpose() {
2851
+ Matrix.transpose(this, this);
2852
+ return this;
2853
+ };
2854
+ /**
2855
+ * Creates a clone of this matrix.
2856
+ * @returns A clone of this matrix
2857
+ */ _proto.clone = function clone() {
2858
+ var e = this.elements;
2859
+ var ret = new Matrix(e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8], e[9], e[10], e[11], e[12], e[13], e[14], e[15]);
2860
+ return ret;
2861
+ };
2862
+ /**
2863
+ * Copy this matrix from the specified matrix.
2864
+ * @param source - The specified matrix
2865
+ * @returns This matrix
2866
+ */ _proto.copyFrom = function copyFrom(source) {
2867
+ var e = this.elements;
2868
+ var se = source.elements;
2869
+ e[0] = se[0];
2870
+ e[1] = se[1];
2871
+ e[2] = se[2];
2872
+ e[3] = se[3];
2873
+ e[4] = se[4];
2874
+ e[5] = se[5];
2875
+ e[6] = se[6];
2876
+ e[7] = se[7];
2877
+ e[8] = se[8];
2878
+ e[9] = se[9];
2879
+ e[10] = se[10];
2880
+ e[11] = se[11];
2881
+ e[12] = se[12];
2882
+ e[13] = se[13];
2883
+ e[14] = se[14];
2884
+ e[15] = se[15];
2885
+ return this;
2886
+ };
2887
+ /**
2888
+ * Copy the value of this matrix from an array.
2889
+ * @param array - The array
2890
+ * @param offset - The start offset of the array
2891
+ * @returns This matrix
2892
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
2893
+ if (offset === void 0) offset = 0;
2894
+ var srce = this.elements;
2895
+ for(var i = 0; i < 16; i++){
2896
+ srce[i] = array[i + offset];
2897
+ }
2898
+ return this;
2899
+ };
2900
+ /**
2901
+ * Copy the value of this matrix to an array.
2902
+ * @param out - The array
2903
+ * @param outOffset - The start offset of the array
2904
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
2905
+ if (outOffset === void 0) outOffset = 0;
2906
+ var e = this.elements;
2907
+ out[outOffset] = e[0];
2908
+ out[outOffset + 1] = e[1];
2909
+ out[outOffset + 2] = e[2];
2910
+ out[outOffset + 3] = e[3];
2911
+ out[outOffset + 4] = e[4];
2912
+ out[outOffset + 5] = e[5];
2913
+ out[outOffset + 6] = e[6];
2914
+ out[outOffset + 7] = e[7];
2915
+ out[outOffset + 8] = e[8];
2916
+ out[outOffset + 9] = e[9];
2917
+ out[outOffset + 10] = e[10];
2918
+ out[outOffset + 11] = e[11];
2919
+ out[outOffset + 12] = e[12];
2920
+ out[outOffset + 13] = e[13];
2921
+ out[outOffset + 14] = e[14];
2922
+ out[outOffset + 15] = e[15];
2923
+ };
2924
+ /**
2925
+ * Determines the product of two matrices.
2926
+ * @param left - The first matrix to multiply
2927
+ * @param right - The second matrix to multiply
2928
+ * @param out - The product of the two matrices
2929
+ */ Matrix.multiply = function multiply(left, right, out) {
2930
+ var le = left.elements;
2931
+ var re = right.elements;
2932
+ var oe = out.elements;
2933
+ // prettier-ignore
2934
+ var l11 = le[0], l12 = le[1], l13 = le[2], l14 = le[3], l21 = le[4], l22 = le[5], l23 = le[6], l24 = le[7], l31 = le[8], l32 = le[9], l33 = le[10], l34 = le[11], l41 = le[12], l42 = le[13], l43 = le[14], l44 = le[15];
2935
+ // prettier-ignore
2936
+ var r11 = re[0], r12 = re[1], r13 = re[2], r14 = re[3], r21 = re[4], r22 = re[5], r23 = re[6], r24 = re[7], r31 = re[8], r32 = re[9], r33 = re[10], r34 = re[11], r41 = re[12], r42 = re[13], r43 = re[14], r44 = re[15];
2937
+ oe[0] = l11 * r11 + l21 * r12 + l31 * r13 + l41 * r14;
2938
+ oe[1] = l12 * r11 + l22 * r12 + l32 * r13 + l42 * r14;
2939
+ oe[2] = l13 * r11 + l23 * r12 + l33 * r13 + l43 * r14;
2940
+ oe[3] = l14 * r11 + l24 * r12 + l34 * r13 + l44 * r14;
2941
+ oe[4] = l11 * r21 + l21 * r22 + l31 * r23 + l41 * r24;
2942
+ oe[5] = l12 * r21 + l22 * r22 + l32 * r23 + l42 * r24;
2943
+ oe[6] = l13 * r21 + l23 * r22 + l33 * r23 + l43 * r24;
2944
+ oe[7] = l14 * r21 + l24 * r22 + l34 * r23 + l44 * r24;
2945
+ oe[8] = l11 * r31 + l21 * r32 + l31 * r33 + l41 * r34;
2946
+ oe[9] = l12 * r31 + l22 * r32 + l32 * r33 + l42 * r34;
2947
+ oe[10] = l13 * r31 + l23 * r32 + l33 * r33 + l43 * r34;
2948
+ oe[11] = l14 * r31 + l24 * r32 + l34 * r33 + l44 * r34;
2949
+ oe[12] = l11 * r41 + l21 * r42 + l31 * r43 + l41 * r44;
2950
+ oe[13] = l12 * r41 + l22 * r42 + l32 * r43 + l42 * r44;
2951
+ oe[14] = l13 * r41 + l23 * r42 + l33 * r43 + l43 * r44;
2952
+ oe[15] = l14 * r41 + l24 * r42 + l34 * r43 + l44 * r44;
2953
+ };
2954
+ /**
2955
+ * Determines whether the specified matrices are equals.
2956
+ * @param left - The first matrix to compare
2957
+ * @param right - The second matrix to compare
2958
+ * @returns True if the specified matrices are equals, false otherwise
2959
+ */ Matrix.equals = function equals(left, right) {
2960
+ var le = left.elements;
2961
+ var re = right.elements;
2962
+ return MathUtil.equals(le[0], re[0]) && MathUtil.equals(le[1], re[1]) && MathUtil.equals(le[2], re[2]) && MathUtil.equals(le[3], re[3]) && MathUtil.equals(le[4], re[4]) && MathUtil.equals(le[5], re[5]) && MathUtil.equals(le[6], re[6]) && MathUtil.equals(le[7], re[7]) && MathUtil.equals(le[8], re[8]) && MathUtil.equals(le[9], re[9]) && MathUtil.equals(le[10], re[10]) && MathUtil.equals(le[11], re[11]) && MathUtil.equals(le[12], re[12]) && MathUtil.equals(le[13], re[13]) && MathUtil.equals(le[14], re[14]) && MathUtil.equals(le[15], re[15]);
2963
+ };
2964
+ /**
2965
+ * Performs a linear interpolation between two matrices.
2966
+ * @param start - The first matrix
2967
+ * @param end - The second matrix
2968
+ * @param t - The blend amount where 0 returns start and 1 end
2969
+ * @param out - The result of linear blending between two matrices
2970
+ */ Matrix.lerp = function lerp(start, end, t, out) {
2971
+ var se = start.elements;
2972
+ var ee = end.elements;
2973
+ var oe = out.elements;
2974
+ var inv = 1.0 - t;
2975
+ oe[0] = se[0] * inv + ee[0] * t;
2976
+ oe[1] = se[1] * inv + ee[1] * t;
2977
+ oe[2] = se[2] * inv + ee[2] * t;
2978
+ oe[3] = se[3] * inv + ee[3] * t;
2979
+ oe[4] = se[4] * inv + ee[4] * t;
2980
+ oe[5] = se[5] * inv + ee[5] * t;
2981
+ oe[6] = se[6] * inv + ee[6] * t;
2982
+ oe[7] = se[7] * inv + ee[7] * t;
2983
+ oe[8] = se[8] * inv + ee[8] * t;
2984
+ oe[9] = se[9] * inv + ee[9] * t;
2985
+ oe[10] = se[10] * inv + ee[10] * t;
2986
+ oe[11] = se[11] * inv + ee[11] * t;
2987
+ oe[12] = se[12] * inv + ee[12] * t;
2988
+ oe[13] = se[13] * inv + ee[13] * t;
2989
+ oe[14] = se[14] * inv + ee[14] * t;
2990
+ oe[15] = se[15] * inv + ee[15] * t;
2991
+ };
2992
+ /**
2993
+ * Determines the sum of two matrices.
2994
+ * @param left - The first matrix to add
2995
+ * @param right - The second matrix to add
2996
+ * @param out - The sum of two matrices
2997
+ */ Matrix.add = function add(left, right, out) {
2998
+ var le = left.elements;
2999
+ var re = right.elements;
3000
+ var oe = out.elements;
3001
+ oe[0] = le[0] + re[0];
3002
+ oe[1] = le[1] + re[1];
3003
+ oe[2] = le[2] + re[2];
3004
+ oe[3] = le[3] + re[3];
3005
+ oe[4] = le[4] + re[4];
3006
+ oe[5] = le[5] + re[5];
3007
+ oe[6] = le[6] + re[6];
3008
+ oe[7] = le[7] + re[7];
3009
+ oe[8] = le[8] + re[8];
3010
+ oe[9] = le[9] + re[9];
3011
+ oe[10] = le[10] + re[10];
3012
+ oe[11] = le[11] + re[11];
3013
+ oe[12] = le[12] + re[12];
3014
+ oe[13] = le[13] + re[13];
3015
+ oe[14] = le[14] + re[14];
3016
+ oe[15] = le[15] + re[15];
3017
+ };
3018
+ /**
3019
+ * Multiplies a matrix by a scalar.
3020
+ * @param source - The matrix to multiply
3021
+ * @param scalar - The scalar to multiply
3022
+ * @param out - The result of multiplying a matrix by a scalar
3023
+ */ Matrix.multiplyScalar = function multiplyScalar(source, scalar, out) {
3024
+ var se = source.elements;
3025
+ var oe = out.elements;
3026
+ oe[0] = se[0] * scalar;
3027
+ oe[1] = se[1] * scalar;
3028
+ oe[2] = se[2] * scalar;
3029
+ oe[3] = se[3] * scalar;
3030
+ oe[4] = se[4] * scalar;
3031
+ oe[5] = se[5] * scalar;
3032
+ oe[6] = se[6] * scalar;
3033
+ oe[7] = se[7] * scalar;
3034
+ oe[8] = se[8] * scalar;
3035
+ oe[9] = se[9] * scalar;
3036
+ oe[10] = se[10] * scalar;
3037
+ oe[11] = se[11] * scalar;
3038
+ oe[12] = se[12] * scalar;
3039
+ oe[13] = se[13] * scalar;
3040
+ oe[14] = se[14] * scalar;
3041
+ oe[15] = se[15] * scalar;
3042
+ };
3043
+ /**
3044
+ * Calculate a rotation matrix from a quaternion.
3045
+ * @param quaternion - The quaternion used to calculate the matrix
3046
+ * @param out - The calculated rotation matrix
3047
+ */ Matrix.rotationQuaternion = function rotationQuaternion(quaternion, out) {
3048
+ var oe = out.elements;
3049
+ var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
3050
+ var x2 = x + x;
3051
+ var y2 = y + y;
3052
+ var z2 = z + z;
3053
+ var xx = x * x2;
3054
+ var yx = y * x2;
3055
+ var yy = y * y2;
3056
+ var zx = z * x2;
3057
+ var zy = z * y2;
3058
+ var zz = z * z2;
3059
+ var wx = w * x2;
3060
+ var wy = w * y2;
3061
+ var wz = w * z2;
3062
+ oe[0] = 1 - yy - zz;
3063
+ oe[1] = yx + wz;
3064
+ oe[2] = zx - wy;
3065
+ oe[3] = 0;
3066
+ oe[4] = yx - wz;
3067
+ oe[5] = 1 - xx - zz;
3068
+ oe[6] = zy + wx;
3069
+ oe[7] = 0;
3070
+ oe[8] = zx + wy;
3071
+ oe[9] = zy - wx;
3072
+ oe[10] = 1 - xx - yy;
3073
+ oe[11] = 0;
3074
+ oe[12] = 0;
3075
+ oe[13] = 0;
3076
+ oe[14] = 0;
3077
+ oe[15] = 1;
3078
+ };
3079
+ /**
3080
+ * Calculate a matrix rotates around an arbitrary axis.
3081
+ * @param axis - The axis
3082
+ * @param r - The rotation angle in radians
3083
+ * @param out - The matrix after rotate
3084
+ */ Matrix.rotationAxisAngle = function rotationAxisAngle(axis, r, out) {
3085
+ var oe = out.elements;
3086
+ var x = axis._x, y = axis._y, z = axis._z;
3087
+ var len = Math.sqrt(x * x + y * y + z * z);
3088
+ var s, c, t;
3089
+ if (Math.abs(len) < MathUtil.zeroTolerance) {
3090
+ return;
3091
+ }
3092
+ len = 1 / len;
3093
+ x *= len;
3094
+ y *= len;
3095
+ z *= len;
3096
+ s = Math.sin(r);
3097
+ c = Math.cos(r);
3098
+ t = 1 - c;
3099
+ // Perform rotation-specific matrix multiplication
3100
+ oe[0] = x * x * t + c;
3101
+ oe[1] = y * x * t + z * s;
3102
+ oe[2] = z * x * t - y * s;
3103
+ oe[3] = 0;
3104
+ oe[4] = x * y * t - z * s;
3105
+ oe[5] = y * y * t + c;
3106
+ oe[6] = z * y * t + x * s;
3107
+ oe[7] = 0;
3108
+ oe[8] = x * z * t + y * s;
3109
+ oe[9] = y * z * t - x * s;
3110
+ oe[10] = z * z * t + c;
3111
+ oe[11] = 0;
3112
+ oe[12] = 0;
3113
+ oe[13] = 0;
3114
+ oe[14] = 0;
3115
+ oe[15] = 1;
3116
+ };
3117
+ /**
3118
+ * Calculate a matrix from a quaternion and a translation.
3119
+ * @param quaternion - The quaternion used to calculate the matrix
3120
+ * @param translation - The translation used to calculate the matrix
3121
+ * @param out - The calculated matrix
3122
+ */ Matrix.rotationTranslation = function rotationTranslation(quaternion, translation, out) {
3123
+ Matrix.rotationQuaternion(quaternion, out);
3124
+ var oe = out.elements;
3125
+ oe[12] = translation._x;
3126
+ oe[13] = translation._y;
3127
+ oe[14] = translation._z;
3128
+ };
3129
+ /**
3130
+ * Calculate an affine matrix.
3131
+ * @param scale - The scale used to calculate matrix
3132
+ * @param rotation - The rotation used to calculate matrix
3133
+ * @param translation - The translation used to calculate matrix
3134
+ * @param out - The calculated matrix
3135
+ */ Matrix.affineTransformation = function affineTransformation(scale, rotation, translation, out) {
3136
+ var oe = out.elements;
3137
+ var x = rotation._x, y = rotation._y, z = rotation._z, w = rotation._w;
3138
+ var x2 = x + x;
3139
+ var y2 = y + y;
3140
+ var z2 = z + z;
3141
+ var xx = x * x2;
3142
+ var xy = x * y2;
3143
+ var xz = x * z2;
3144
+ var yy = y * y2;
3145
+ var yz = y * z2;
3146
+ var zz = z * z2;
3147
+ var wx = w * x2;
3148
+ var wy = w * y2;
3149
+ var wz = w * z2;
3150
+ var sx = scale._x;
3151
+ var sy = scale._y;
3152
+ var sz = scale._z;
3153
+ oe[0] = (1 - (yy + zz)) * sx;
3154
+ oe[1] = (xy + wz) * sx;
3155
+ oe[2] = (xz - wy) * sx;
3156
+ oe[3] = 0;
3157
+ oe[4] = (xy - wz) * sy;
3158
+ oe[5] = (1 - (xx + zz)) * sy;
3159
+ oe[6] = (yz + wx) * sy;
3160
+ oe[7] = 0;
3161
+ oe[8] = (xz + wy) * sz;
3162
+ oe[9] = (yz - wx) * sz;
3163
+ oe[10] = (1 - (xx + yy)) * sz;
3164
+ oe[11] = 0;
3165
+ oe[12] = translation._x;
3166
+ oe[13] = translation._y;
3167
+ oe[14] = translation._z;
3168
+ oe[15] = 1;
3169
+ };
3170
+ /**
3171
+ * Calculate a matrix from scale vector.
3172
+ * @param s - The scale vector
3173
+ * @param out - The calculated matrix
3174
+ */ Matrix.scaling = function scaling(s, out) {
3175
+ var oe = out.elements;
3176
+ oe[0] = s._x;
3177
+ oe[1] = 0;
3178
+ oe[2] = 0;
3179
+ oe[3] = 0;
3180
+ oe[4] = 0;
3181
+ oe[5] = s._y;
3182
+ oe[6] = 0;
3183
+ oe[7] = 0;
3184
+ oe[8] = 0;
3185
+ oe[9] = 0;
3186
+ oe[10] = s._z;
3187
+ oe[11] = 0;
3188
+ oe[12] = 0;
3189
+ oe[13] = 0;
3190
+ oe[14] = 0;
3191
+ oe[15] = 1;
3192
+ };
3193
+ /**
3194
+ * Calculate a matrix from translation vector.
3195
+ * @param translation - The translation vector
3196
+ * @param out - The calculated matrix
3197
+ */ Matrix.translation = function translation(translation, out) {
3198
+ var oe = out.elements;
3199
+ oe[0] = 1;
3200
+ oe[1] = 0;
3201
+ oe[2] = 0;
3202
+ oe[3] = 0;
3203
+ oe[4] = 0;
3204
+ oe[5] = 1;
3205
+ oe[6] = 0;
3206
+ oe[7] = 0;
3207
+ oe[8] = 0;
3208
+ oe[9] = 0;
3209
+ oe[10] = 1;
3210
+ oe[11] = 0;
3211
+ oe[12] = translation._x;
3212
+ oe[13] = translation._y;
3213
+ oe[14] = translation._z;
3214
+ oe[15] = 1;
3215
+ };
3216
+ /**
3217
+ * Calculate the inverse of the specified matrix.
3218
+ * @param a - The matrix whose inverse is to be calculated
3219
+ * @param out - The inverse of the specified matrix
3220
+ */ Matrix.invert = function invert(a, out) {
3221
+ var ae = a.elements;
3222
+ var oe = out.elements;
3223
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2], a14 = ae[3];
3224
+ var a21 = ae[4], a22 = ae[5], a23 = ae[6], a24 = ae[7];
3225
+ var a31 = ae[8], a32 = ae[9], a33 = ae[10], a34 = ae[11];
3226
+ var a41 = ae[12], a42 = ae[13], a43 = ae[14], a44 = ae[15];
3227
+ var b00 = a11 * a22 - a12 * a21;
3228
+ var b01 = a11 * a23 - a13 * a21;
3229
+ var b02 = a11 * a24 - a14 * a21;
3230
+ var b03 = a12 * a23 - a13 * a22;
3231
+ var b04 = a12 * a24 - a14 * a22;
3232
+ var b05 = a13 * a24 - a14 * a23;
3233
+ var b06 = a31 * a42 - a32 * a41;
3234
+ var b07 = a31 * a43 - a33 * a41;
3235
+ var b08 = a31 * a44 - a34 * a41;
3236
+ var b09 = a32 * a43 - a33 * a42;
3237
+ var b10 = a32 * a44 - a34 * a42;
3238
+ var b11 = a33 * a44 - a34 * a43;
3239
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
3240
+ if (!det) {
3241
+ return null;
3242
+ }
3243
+ det = 1.0 / det;
3244
+ oe[0] = (a22 * b11 - a23 * b10 + a24 * b09) * det;
3245
+ oe[1] = (a13 * b10 - a12 * b11 - a14 * b09) * det;
3246
+ oe[2] = (a42 * b05 - a43 * b04 + a44 * b03) * det;
3247
+ oe[3] = (a33 * b04 - a32 * b05 - a34 * b03) * det;
3248
+ oe[4] = (a23 * b08 - a21 * b11 - a24 * b07) * det;
3249
+ oe[5] = (a11 * b11 - a13 * b08 + a14 * b07) * det;
3250
+ oe[6] = (a43 * b02 - a41 * b05 - a44 * b01) * det;
3251
+ oe[7] = (a31 * b05 - a33 * b02 + a34 * b01) * det;
3252
+ oe[8] = (a21 * b10 - a22 * b08 + a24 * b06) * det;
3253
+ oe[9] = (a12 * b08 - a11 * b10 - a14 * b06) * det;
3254
+ oe[10] = (a41 * b04 - a42 * b02 + a44 * b00) * det;
3255
+ oe[11] = (a32 * b02 - a31 * b04 - a34 * b00) * det;
3256
+ oe[12] = (a22 * b07 - a21 * b09 - a23 * b06) * det;
3257
+ oe[13] = (a11 * b09 - a12 * b07 + a13 * b06) * det;
3258
+ oe[14] = (a42 * b01 - a41 * b03 - a43 * b00) * det;
3259
+ oe[15] = (a31 * b03 - a32 * b01 + a33 * b00) * det;
3260
+ };
3261
+ /**
3262
+ * Calculate a right-handed look-at matrix.
3263
+ * @param eye - The position of the viewer's eye
3264
+ * @param target - The camera look-at target
3265
+ * @param up - The camera's up vector
3266
+ * @param out - The calculated look-at matrix
3267
+ */ Matrix.lookAt = function lookAt(eye, target, up, out) {
3268
+ var oe = out.elements;
3269
+ var xAxis = Matrix._tempVec30;
3270
+ var yAxis = Matrix._tempVec31;
3271
+ var zAxis = Matrix._tempVec32;
3272
+ Vector3.subtract(eye, target, zAxis);
3273
+ zAxis.normalize();
3274
+ Vector3.cross(up, zAxis, xAxis);
3275
+ xAxis.normalize();
3276
+ Vector3.cross(zAxis, xAxis, yAxis);
3277
+ oe[0] = xAxis._x;
3278
+ oe[1] = yAxis._x;
3279
+ oe[2] = zAxis._x;
3280
+ oe[3] = 0;
3281
+ oe[4] = xAxis._y;
3282
+ oe[5] = yAxis._y;
3283
+ oe[6] = zAxis._y;
3284
+ oe[7] = 0;
3285
+ oe[8] = xAxis._z;
3286
+ oe[9] = yAxis._z;
3287
+ oe[10] = zAxis._z;
3288
+ oe[11] = 0;
3289
+ oe[12] = -Vector3.dot(xAxis, eye);
3290
+ oe[13] = -Vector3.dot(yAxis, eye);
3291
+ oe[14] = -Vector3.dot(zAxis, eye);
3292
+ oe[15] = 1;
3293
+ };
3294
+ /**
3295
+ * Calculate an orthographic projection matrix.
3296
+ * @param left - The left edge of the viewing
3297
+ * @param right - The right edge of the viewing
3298
+ * @param bottom - The bottom edge of the viewing
3299
+ * @param top - The top edge of the viewing
3300
+ * @param near - The depth of the near plane
3301
+ * @param far - The depth of the far plane
3302
+ * @param out - The calculated orthographic projection matrix
3303
+ */ Matrix.ortho = function ortho(left, right, bottom, top, near, far, out) {
3304
+ var oe = out.elements;
3305
+ var lr = 1 / (left - right);
3306
+ var bt = 1 / (bottom - top);
3307
+ var nf = 1 / (near - far);
3308
+ oe[0] = -2 * lr;
3309
+ oe[1] = 0;
3310
+ oe[2] = 0;
3311
+ oe[3] = 0;
3312
+ oe[4] = 0;
3313
+ oe[5] = -2 * bt;
3314
+ oe[6] = 0;
3315
+ oe[7] = 0;
3316
+ oe[8] = 0;
3317
+ oe[9] = 0;
3318
+ oe[10] = 2 * nf;
3319
+ oe[11] = 0;
3320
+ oe[12] = (left + right) * lr;
3321
+ oe[13] = (top + bottom) * bt;
3322
+ oe[14] = (far + near) * nf;
3323
+ oe[15] = 1;
3324
+ };
3325
+ /**
3326
+ * Calculate a perspective projection matrix.
3327
+ * @param fovY - Field of view in the y direction, in radians
3328
+ * @param aspect - Aspect ratio, defined as view space width divided by height
3329
+ * @param near - The depth of the near plane
3330
+ * @param far - The depth of the far plane
3331
+ * @param out - The calculated perspective projection matrix
3332
+ */ Matrix.perspective = function perspective(fovY, aspect, near, far, out) {
3333
+ var oe = out.elements;
3334
+ var f = 1.0 / Math.tan(fovY / 2);
3335
+ var nf = 1 / (near - far);
3336
+ oe[0] = f / aspect;
3337
+ oe[1] = 0;
3338
+ oe[2] = 0;
3339
+ oe[3] = 0;
3340
+ oe[4] = 0;
3341
+ oe[5] = f;
3342
+ oe[6] = 0;
3343
+ oe[7] = 0;
3344
+ oe[8] = 0;
3345
+ oe[9] = 0;
3346
+ oe[10] = (far + near) * nf;
3347
+ oe[11] = -1;
3348
+ oe[12] = 0;
3349
+ oe[13] = 0;
3350
+ oe[14] = 2 * far * near * nf;
3351
+ oe[15] = 0;
3352
+ };
3353
+ /**
3354
+ * The specified matrix rotates around an arbitrary axis.
3355
+ * @param m - The specified matrix
3356
+ * @param axis - The axis
3357
+ * @param r - The rotation angle in radians
3358
+ * @param out - The rotated matrix
3359
+ */ Matrix.rotateAxisAngle = function rotateAxisAngle(m, axis, r, out) {
3360
+ var x = axis._x, y = axis._y, z = axis._z;
3361
+ var len = Math.sqrt(x * x + y * y + z * z);
3362
+ if (Math.abs(len) < MathUtil.zeroTolerance) {
3363
+ return;
3364
+ }
3365
+ var me = m.elements;
3366
+ var oe = out.elements;
3367
+ var s, c, t;
3368
+ len = 1 / len;
3369
+ x *= len;
3370
+ y *= len;
3371
+ z *= len;
3372
+ s = Math.sin(r);
3373
+ c = Math.cos(r);
3374
+ t = 1 - c;
3375
+ var a11 = me[0], a12 = me[1], a13 = me[2], a14 = me[3];
3376
+ var a21 = me[4], a22 = me[5], a23 = me[6], a24 = me[7];
3377
+ var a31 = me[8], a32 = me[9], a33 = me[10], a34 = me[11];
3378
+ // Construct the elements of the rotation matrix
3379
+ var b11 = x * x * t + c;
3380
+ var b12 = y * x * t + z * s;
3381
+ var b13 = z * x * t - y * s;
3382
+ var b21 = x * y * t - z * s;
3383
+ var b22 = y * y * t + c;
3384
+ var b23 = z * y * t + x * s;
3385
+ var b31 = x * z * t + y * s;
3386
+ var b32 = y * z * t - x * s;
3387
+ var b33 = z * z * t + c;
3388
+ // Perform rotation-specific matrix multiplication
3389
+ oe[0] = a11 * b11 + a21 * b12 + a31 * b13;
3390
+ oe[1] = a12 * b11 + a22 * b12 + a32 * b13;
3391
+ oe[2] = a13 * b11 + a23 * b12 + a33 * b13;
3392
+ oe[3] = a14 * b11 + a24 * b12 + a34 * b13;
3393
+ oe[4] = a11 * b21 + a21 * b22 + a31 * b23;
3394
+ oe[5] = a12 * b21 + a22 * b22 + a32 * b23;
3395
+ oe[6] = a13 * b21 + a23 * b22 + a33 * b23;
3396
+ oe[7] = a14 * b21 + a24 * b22 + a34 * b23;
3397
+ oe[8] = a11 * b31 + a21 * b32 + a31 * b33;
3398
+ oe[9] = a12 * b31 + a22 * b32 + a32 * b33;
3399
+ oe[10] = a13 * b31 + a23 * b32 + a33 * b33;
3400
+ oe[11] = a14 * b31 + a24 * b32 + a34 * b33;
3401
+ if (m !== out) {
3402
+ // If the source and destination differ, copy the unchanged last row
3403
+ oe[12] = me[12];
3404
+ oe[13] = me[13];
3405
+ oe[14] = me[14];
3406
+ oe[15] = me[15];
3407
+ }
3408
+ };
3409
+ /**
3410
+ * Scale a matrix by a given vector.
3411
+ * @param m - The matrix
3412
+ * @param s - The given vector
3413
+ * @param out - The scaled matrix
3414
+ */ Matrix.scale = function scale(m, s, out) {
3415
+ var me = m.elements;
3416
+ var oe = out.elements;
3417
+ var x = s._x, y = s._y, z = s._z;
3418
+ oe[0] = me[0] * x;
3419
+ oe[1] = me[1] * x;
3420
+ oe[2] = me[2] * x;
3421
+ oe[3] = me[3] * x;
3422
+ oe[4] = me[4] * y;
3423
+ oe[5] = me[5] * y;
3424
+ oe[6] = me[6] * y;
3425
+ oe[7] = me[7] * y;
3426
+ oe[8] = me[8] * z;
3427
+ oe[9] = me[9] * z;
3428
+ oe[10] = me[10] * z;
3429
+ oe[11] = me[11] * z;
3430
+ oe[12] = me[12];
3431
+ oe[13] = me[13];
3432
+ oe[14] = me[14];
3433
+ oe[15] = me[15];
3434
+ };
3435
+ /**
3436
+ * Translate a matrix by a given vector.
3437
+ * @param m - The matrix
3438
+ * @param v - The given vector
3439
+ * @param out - The translated matrix
3440
+ */ Matrix.translate = function translate(m, v, out) {
3441
+ var me = m.elements;
3442
+ var oe = out.elements;
3443
+ var x = v._x, y = v._y, z = v._z;
3444
+ if (m === out) {
3445
+ oe[12] = me[0] * x + me[4] * y + me[8] * z + me[12];
3446
+ oe[13] = me[1] * x + me[5] * y + me[9] * z + me[13];
3447
+ oe[14] = me[2] * x + me[6] * y + me[10] * z + me[14];
3448
+ oe[15] = me[3] * x + me[7] * y + me[11] * z + me[15];
3449
+ } else {
3450
+ var a11 = me[0], a12 = me[1], a13 = me[2], a14 = me[3];
3451
+ var a21 = me[4], a22 = me[5], a23 = me[6], a24 = me[7];
3452
+ var a31 = me[8], a32 = me[9], a33 = me[10], a34 = me[11];
3453
+ oe[0] = a11, oe[1] = a12, oe[2] = a13, oe[3] = a14;
3454
+ oe[4] = a21, oe[5] = a22, oe[6] = a23, oe[7] = a24;
3455
+ oe[8] = a31, oe[9] = a32, oe[10] = a33, oe[11] = a34;
3456
+ oe[12] = a11 * x + a21 * y + a31 * z + me[12];
3457
+ oe[13] = a12 * x + a22 * y + a32 * z + me[13];
3458
+ oe[14] = a13 * x + a23 * y + a33 * z + me[14];
3459
+ oe[15] = a14 * x + a24 * y + a34 * z + me[15];
3460
+ }
3461
+ };
3462
+ /**
3463
+ * Calculate the transpose of the specified matrix.
3464
+ * @param a - The specified matrix
3465
+ * @param out - The transpose of the specified matrix
3466
+ */ Matrix.transpose = function transpose(a, out) {
3467
+ var ae = a.elements;
3468
+ var oe = out.elements;
3469
+ if (out === a) {
3470
+ var a12 = ae[1];
3471
+ var a13 = ae[2];
3472
+ var a14 = ae[3];
3473
+ var a23 = ae[6];
3474
+ var a24 = ae[7];
3475
+ var a34 = ae[11];
3476
+ oe[1] = ae[4];
3477
+ oe[2] = ae[8];
3478
+ oe[3] = ae[12];
3479
+ oe[4] = a12;
3480
+ oe[6] = ae[9];
3481
+ oe[7] = ae[13];
3482
+ oe[8] = a13;
3483
+ oe[9] = a23;
3484
+ oe[11] = ae[14];
3485
+ oe[12] = a14;
3486
+ oe[13] = a24;
3487
+ oe[14] = a34;
3488
+ } else {
3489
+ oe[0] = ae[0];
3490
+ oe[1] = ae[4];
3491
+ oe[2] = ae[8];
3492
+ oe[3] = ae[12];
3493
+ oe[4] = ae[1];
3494
+ oe[5] = ae[5];
3495
+ oe[6] = ae[9];
3496
+ oe[7] = ae[13];
3497
+ oe[8] = ae[2];
3498
+ oe[9] = ae[6];
3499
+ oe[10] = ae[10];
3500
+ oe[11] = ae[14];
3501
+ oe[12] = ae[3];
3502
+ oe[13] = ae[7];
3503
+ oe[14] = ae[11];
3504
+ oe[15] = ae[15];
3505
+ }
3506
+ };
3507
+ return Matrix;
3508
+ }();
3509
+ Matrix._tempVec30 = new Vector3();
3510
+ Matrix._tempVec31 = new Vector3();
3511
+ Matrix._tempVec32 = new Vector3();
3512
+ Matrix._tempMat30 = new Matrix3x3();
3513
+ /** @internal Identity matrix. */ Matrix._identity = new Matrix(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
3514
+
3515
+ /**
3516
+ * Represents a ray with an origin and a direction in 3D space.
3517
+ */ var Ray = /*#__PURE__*/ function() {
3518
+ function Ray(origin, direction) {
3519
+ if (origin === void 0) origin = null;
3520
+ if (direction === void 0) direction = null;
3521
+ /** The origin of the ray. */ this.origin = new Vector3();
3522
+ /** The normalized direction of the ray. */ this.direction = new Vector3();
3523
+ origin && this.origin.copyFrom(origin);
3524
+ direction && this.direction.copyFrom(direction);
3525
+ }
3526
+ var _proto = Ray.prototype;
3527
+ /**
3528
+ * Check if this ray intersects the specified plane.
3529
+ * @param plane - The specified plane
3530
+ * @returns The distance from this ray to the specified plane if intersecting, -1 otherwise
3531
+ */ _proto.intersectPlane = function intersectPlane(plane) {
3532
+ return CollisionUtil.intersectsRayAndPlane(this, plane);
3533
+ };
3534
+ /**
3535
+ * Check if this ray intersects the specified sphere.
3536
+ * @param sphere - The specified sphere
3537
+ * @returns The distance from this ray to the specified sphere if intersecting, -1 otherwise
3538
+ */ _proto.intersectSphere = function intersectSphere(sphere) {
3539
+ return CollisionUtil.intersectsRayAndSphere(this, sphere);
3540
+ };
3541
+ /**
3542
+ * Check if this ray intersects the specified box (AABB).
3543
+ * @param box - The specified box
3544
+ * @returns The distance from this ray to the specified box if intersecting, -1 otherwise
3545
+ */ _proto.intersectBox = function intersectBox(box) {
3546
+ return CollisionUtil.intersectsRayAndBox(this, box);
3547
+ };
3548
+ /**
3549
+ * The coordinates of the specified distance from the origin in the ray direction.
3550
+ * @param distance - The specified distance
3551
+ * @param out - The coordinates as an output parameter
3552
+ * @returns The out
3553
+ */ _proto.getPoint = function getPoint(distance, out) {
3554
+ Vector3.scale(this.direction, distance, out);
3555
+ return out.add(this.origin);
3556
+ };
3557
+ return Ray;
3558
+ }();
3559
+
3560
+ /**
3561
+ * Describes a 2D-vector.
3562
+ */ var Vector2 = /*#__PURE__*/ function() {
3563
+ function Vector2(x, y) {
3564
+ if (x === void 0) x = 0;
3565
+ if (y === void 0) y = 0;
3566
+ /** @internal */ this._onValueChanged = null;
3567
+ this._x = x;
3568
+ this._y = y;
3569
+ }
3570
+ var _proto = Vector2.prototype;
3571
+ /**
3572
+ * Set the value of this vector.
3573
+ * @param x - The x component of the vector
3574
+ * @param y - The y component of the vector
3575
+ * @returns This vector
3576
+ */ _proto.set = function set(x, y) {
3577
+ this._x = x;
3578
+ this._y = y;
3579
+ this._onValueChanged && this._onValueChanged();
3580
+ return this;
3581
+ };
3582
+ /**
3583
+ * Determines the sum of this vector and the specified vector.
3584
+ * @param right - The specified vector
3585
+ * @returns This vector
3586
+ */ _proto.add = function add(right) {
3587
+ this._x += right._x;
3588
+ this._y += right._y;
3589
+ this._onValueChanged && this._onValueChanged();
3590
+ return this;
3591
+ };
3592
+ /**
3593
+ * Determines the difference of this vector and the specified vector.
3594
+ * @param right - The specified vector
3595
+ * @returns This vector
3596
+ */ _proto.subtract = function subtract(right) {
3597
+ this._x -= right._x;
3598
+ this._y -= right._y;
3599
+ this._onValueChanged && this._onValueChanged();
3600
+ return this;
3601
+ };
3602
+ /**
3603
+ * Determines the product of this vector and the specified vector.
3604
+ * @param right - The specified vector
3605
+ * @returns This vector
3606
+ */ _proto.multiply = function multiply(right) {
3607
+ this._x *= right._x;
3608
+ this._y *= right._y;
3609
+ this._onValueChanged && this._onValueChanged();
3610
+ return this;
3611
+ };
3612
+ /**
3613
+ * Determines the divisor of this vector and the specified vector.
3614
+ * @param right - The specified vector
3615
+ * @returns This vector
3616
+ */ _proto.divide = function divide(right) {
3617
+ this._x /= right._x;
3618
+ this._y /= right._y;
3619
+ this._onValueChanged && this._onValueChanged();
3620
+ return this;
3621
+ };
3622
+ /**
3623
+ * Calculate the length of this vector.
3624
+ * @returns The length of this vector
3625
+ */ _proto.length = function length() {
3626
+ var _this = this, _x = _this._x, _y = _this._y;
3627
+ return Math.sqrt(_x * _x + _y * _y);
3628
+ };
3629
+ /**
3630
+ * Calculate the squared length of this vector.
3631
+ * @returns The squared length of this vector
3632
+ */ _proto.lengthSquared = function lengthSquared() {
3633
+ var _this = this, _x = _this._x, _y = _this._y;
3634
+ return _x * _x + _y * _y;
3635
+ };
3636
+ /**
3637
+ * Reverses the direction of this vector.
3638
+ * @returns This vector
3639
+ */ _proto.negate = function negate() {
3640
+ this._x = -this._x;
3641
+ this._y = -this._y;
3642
+ this._onValueChanged && this._onValueChanged();
3643
+ return this;
3644
+ };
3645
+ /**
3646
+ * Converts this vector into a unit vector.
3647
+ * @returns This vector
3648
+ */ _proto.normalize = function normalize() {
3649
+ Vector2.normalize(this, this);
3650
+ return this;
3651
+ };
3652
+ /**
3653
+ * Scale this vector by the given value.
3654
+ * @param s - The amount by which to scale the vector
3655
+ * @returns This vector
3656
+ */ _proto.scale = function scale(s) {
3657
+ this._x *= s;
3658
+ this._y *= s;
3659
+ this._onValueChanged && this._onValueChanged();
3660
+ return this;
3661
+ };
3662
+ /**
3663
+ * Creates a clone of this vector.
3664
+ * @returns A clone of this vector
3665
+ */ _proto.clone = function clone() {
3666
+ return new Vector2(this._x, this._y);
3667
+ };
3668
+ /**
3669
+ * Copy from vector2 like object.
3670
+ * @param source - Vector2 like object
3671
+ * @returns This vector
3672
+ */ _proto.copyFrom = function copyFrom(source) {
3673
+ this._x = source.x;
3674
+ this._y = source.y;
3675
+ this._onValueChanged && this._onValueChanged();
3676
+ return this;
3677
+ };
3678
+ /**
3679
+ * Copy the value of this vector from an array.
3680
+ * @param array - The array
3681
+ * @param offset - The start offset of the array
3682
+ * @returns This vector
3683
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
3684
+ if (offset === void 0) offset = 0;
3685
+ this._x = array[offset];
3686
+ this._y = array[offset + 1];
3687
+ this._onValueChanged && this._onValueChanged();
3688
+ return this;
3689
+ };
3690
+ /**
3691
+ * Copy the value of this vector to an array.
3692
+ * @param out - The array
3693
+ * @param outOffset - The start offset of the array
3694
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
3695
+ if (outOffset === void 0) outOffset = 0;
3696
+ out[outOffset] = this._x;
3697
+ out[outOffset + 1] = this._y;
3698
+ };
3699
+ /**
3700
+ * Serialize this vector to a JSON representation.
3701
+ * @returns A JSON representation of this vector
3702
+ */ _proto.toJSON = function toJSON() {
3703
+ return {
3704
+ x: this._x,
3705
+ y: this._y
3706
+ };
3707
+ };
3708
+ /**
3709
+ * Determines the sum of two vectors.
3710
+ * @param left - The first vector to add
3711
+ * @param right - The second vector to add
3712
+ * @param out - The sum of two vectors
3713
+ */ Vector2.add = function add(left, right, out) {
3714
+ out._x = left._x + right._x;
3715
+ out._y = left._y + right._y;
3716
+ out._onValueChanged && out._onValueChanged();
3717
+ };
3718
+ /**
3719
+ * Determines the difference between two vectors.
3720
+ * @param left - The first vector to subtract
3721
+ * @param right - The second vector to subtract
3722
+ * @param out - The difference between two vectors
3723
+ */ Vector2.subtract = function subtract(left, right, out) {
3724
+ out._x = left._x - right._x;
3725
+ out._y = left._y - right._y;
3726
+ out._onValueChanged && out._onValueChanged();
3727
+ };
3728
+ /**
3729
+ * Determines the product of two vectors.
3730
+ * @param left - The first vector to multiply
3731
+ * @param right - The second vector to multiply
3732
+ * @param out - The product of two vectors
3733
+ */ Vector2.multiply = function multiply(left, right, out) {
3734
+ out._x = left._x * right._x;
3735
+ out._y = left._y * right._y;
3736
+ out._onValueChanged && out._onValueChanged();
3737
+ };
3738
+ /**
3739
+ * Determines the divisor of two vectors.
3740
+ * @param left - The first vector to divide
3741
+ * @param right - The second vector to divide
3742
+ * @param out - The divisor of two vectors
3743
+ */ Vector2.divide = function divide(left, right, out) {
3744
+ out._x = left._x / right._x;
3745
+ out._y = left._y / right._y;
3746
+ out._onValueChanged && out._onValueChanged();
3747
+ };
3748
+ /**
3749
+ * Determines the dot product of two vectors.
3750
+ * @param left - The first vector to dot
3751
+ * @param right - The second vector to dot
3752
+ * @returns The dot product of two vectors
3753
+ */ Vector2.dot = function dot(left, right) {
3754
+ return left._x * right._x + left._y * right._y;
3755
+ };
3756
+ /**
3757
+ * Determines the distance of two vectors.
3758
+ * @param left - The first vector
3759
+ * @param right - The second vector
3760
+ * @returns The distance of two vectors
3761
+ */ Vector2.distance = function distance(left, right) {
3762
+ var x = right._x - left._x;
3763
+ var y = right._y - left._y;
3764
+ return Math.sqrt(x * x + y * y);
3765
+ };
3766
+ /**
3767
+ * Determines the squared distance of two vectors.
3768
+ * @param left - The first vector
3769
+ * @param right - The second vector
3770
+ * @returns The squared distance of two vectors
3771
+ */ Vector2.distanceSquared = function distanceSquared(left, right) {
3772
+ var x = right._x - left._x;
3773
+ var y = right._y - left._y;
3774
+ return x * x + y * y;
3775
+ };
3776
+ /**
3777
+ * Determines whether the specified vectors are equals.
3778
+ * @param left - The first vector to compare
3779
+ * @param right - The second vector to compare
3780
+ * @returns True if the specified vectors are equals, false otherwise
3781
+ */ Vector2.equals = function equals(left, right) {
3782
+ return MathUtil.equals(left._x, right._x) && MathUtil.equals(left._y, right._y);
3783
+ };
3784
+ /**
3785
+ * Performs a linear interpolation between two vectors.
3786
+ * @param left - The first vector
3787
+ * @param right - The second vector
3788
+ * @param t - The blend amount where 0 returns left and 1 right
3789
+ * @param out - The result of linear blending between two vectors
3790
+ */ Vector2.lerp = function lerp(left, right, t, out) {
3791
+ var _x = left._x, _y = left._y;
3792
+ out._x = _x + (right._x - _x) * t;
3793
+ out._y = _y + (right._y - _y) * t;
3794
+ out._onValueChanged && out._onValueChanged();
3795
+ };
3796
+ /**
3797
+ * Calculate a vector containing the largest components of the specified vectors.
3798
+ * @param left - The first vector
3799
+ * @param right - The second vector
3800
+ * @param out - The vector containing the largest components of the specified vectors
3801
+ */ Vector2.max = function max(left, right, out) {
3802
+ out._x = Math.max(left._x, right._x);
3803
+ out._y = Math.max(left._y, right._y);
3804
+ out._onValueChanged && out._onValueChanged();
3805
+ };
3806
+ /**
3807
+ * Calculate a vector containing the smallest components of the specified vectors.
3808
+ * @param left - The first vector
3809
+ * @param right - The second vector
3810
+ * @param out - The vector containing the smallest components of the specified vectors
3811
+ */ Vector2.min = function min(left, right, out) {
3812
+ out._x = Math.min(left._x, right._x);
3813
+ out._y = Math.min(left._y, right._y);
3814
+ out._onValueChanged && out._onValueChanged();
3815
+ };
3816
+ /**
3817
+ * Reverses the direction of a given vector.
3818
+ * @param left - The vector to negate
3819
+ * @param out - The vector facing in the opposite direction
3820
+ */ Vector2.negate = function negate(left, out) {
3821
+ out._x = -left._x;
3822
+ out._y = -left._y;
3823
+ out._onValueChanged && out._onValueChanged();
3824
+ };
3825
+ /**
3826
+ * Converts the vector into a unit vector.
3827
+ * @param left - The vector to normalize
3828
+ * @param out - The normalized vector
3829
+ */ Vector2.normalize = function normalize(left, out) {
3830
+ var _x = left._x, _y = left._y;
3831
+ var len = Math.sqrt(_x * _x + _y * _y);
3832
+ if (len > MathUtil.zeroTolerance) {
3833
+ len = 1 / len;
3834
+ out._x = _x * len;
3835
+ out._y = _y * len;
3836
+ out._onValueChanged && out._onValueChanged();
3837
+ }
3838
+ };
3839
+ /**
3840
+ * Scale a vector by the given value.
3841
+ * @param left - The vector to scale
3842
+ * @param s - The amount by which to scale the vector
3843
+ * @param out - The scaled vector
3844
+ */ Vector2.scale = function scale(left, s, out) {
3845
+ out._x = left._x * s;
3846
+ out._y = left._y * s;
3847
+ out._onValueChanged && out._onValueChanged();
3848
+ };
3849
+ _createClass(Vector2, [
3850
+ {
3851
+ key: "x",
3852
+ get: /**
3853
+ * The x component of the vector.
3854
+ */ function get() {
3855
+ return this._x;
3856
+ },
3857
+ set: function set(value) {
3858
+ this._x = value;
3859
+ this._onValueChanged && this._onValueChanged();
3860
+ }
3861
+ },
3862
+ {
3863
+ key: "y",
3864
+ get: /**
3865
+ * The y component of the vector.
3866
+ */ function get() {
3867
+ return this._y;
3868
+ },
3869
+ set: function set(value) {
3870
+ this._y = value;
3871
+ this._onValueChanged && this._onValueChanged();
3872
+ }
3873
+ }
3874
+ ]);
3875
+ return Vector2;
3876
+ }();
3877
+ /** @internal */ Vector2._zero = new Vector2(0.0, 0.0);
3878
+ /** @internal */ Vector2._one = new Vector2(1.0, 1.0);
3879
+
3880
+ /**
3881
+ * Describes a 4D-vector.
3882
+ */ var Vector4 = /*#__PURE__*/ function() {
3883
+ function Vector4(x, y, z, w) {
3884
+ if (x === void 0) x = 0;
3885
+ if (y === void 0) y = 0;
3886
+ if (z === void 0) z = 0;
3887
+ if (w === void 0) w = 0;
3888
+ /** @internal */ this._onValueChanged = null;
3889
+ this._x = x;
3890
+ this._y = y;
3891
+ this._z = z;
3892
+ this._w = w;
3893
+ }
3894
+ var _proto = Vector4.prototype;
3895
+ /**
3896
+ * Set the value of this vector.
3897
+ * @param x - The x component of the vector
3898
+ * @param y - The y component of the vector
3899
+ * @param z - The z component of the vector
3900
+ * @param w - The w component of the vector
3901
+ * @returns This vector
3902
+ */ _proto.set = function set(x, y, z, w) {
3903
+ this._x = x;
3904
+ this._y = y;
3905
+ this._z = z;
3906
+ this._w = w;
3907
+ this._onValueChanged && this._onValueChanged();
3908
+ return this;
3909
+ };
3910
+ /**
3911
+ * Determines the sum of this vector and the specified vector.
3912
+ * @param right - The specified vector
3913
+ * @returns This vector
3914
+ */ _proto.add = function add(right) {
3915
+ this._x += right._x;
3916
+ this._y += right._y;
3917
+ this._z += right._z;
3918
+ this._w += right._w;
3919
+ this._onValueChanged && this._onValueChanged();
3920
+ return this;
3921
+ };
3922
+ /**
3923
+ * Determines the difference of this vector and the specified vector.
3924
+ * @param right - the specified vector
3925
+ * @returns This vector
3926
+ */ _proto.subtract = function subtract(right) {
3927
+ this._x -= right._x;
3928
+ this._y -= right._y;
3929
+ this._z -= right._z;
3930
+ this._w -= right._w;
3931
+ this._onValueChanged && this._onValueChanged();
3932
+ return this;
3933
+ };
3934
+ /**
3935
+ * Determines the product of this vector and the specified vector.
3936
+ * @param right - the specified vector
3937
+ * @returns This vector
3938
+ */ _proto.multiply = function multiply(right) {
3939
+ this._x *= right._x;
3940
+ this._y *= right._y;
3941
+ this._z *= right._z;
3942
+ this._w *= right._w;
3943
+ this._onValueChanged && this._onValueChanged();
3944
+ return this;
3945
+ };
3946
+ /**
3947
+ * Determines the divisor of this vector and the specified vector.
3948
+ * @param right - the specified vector
3949
+ * @returns This vector
3950
+ */ _proto.divide = function divide(right) {
3951
+ this._x /= right._x;
3952
+ this._y /= right._y;
3953
+ this._z /= right._z;
3954
+ this._w /= right._w;
3955
+ this._onValueChanged && this._onValueChanged();
3956
+ return this;
3957
+ };
3958
+ /**
3959
+ * Calculate the length of this vector.
3960
+ * @returns The length of this vector
3961
+ */ _proto.length = function length() {
3962
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
3963
+ return Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
3964
+ };
3965
+ /**
3966
+ * Calculate the squared length of this vector.
3967
+ * @returns The squared length of this vector
3968
+ */ _proto.lengthSquared = function lengthSquared() {
3969
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
3970
+ return _x * _x + _y * _y + _z * _z + _w * _w;
3971
+ };
3972
+ /**
3973
+ * Reverses the direction of this vector.
3974
+ * @returns This vector
3975
+ */ _proto.negate = function negate() {
3976
+ this._x = -this._x;
3977
+ this._y = -this._y;
3978
+ this._z = -this._z;
3979
+ this._w = -this._w;
3980
+ this._onValueChanged && this._onValueChanged();
3981
+ return this;
3982
+ };
3983
+ /**
3984
+ * Converts this vector into a unit vector.
3985
+ * @returns This vector
3986
+ */ _proto.normalize = function normalize() {
3987
+ Vector4.normalize(this, this);
3988
+ return this;
3989
+ };
3990
+ /**
3991
+ * Scale this vector by the given value.
3992
+ * @param s - The amount by which to scale the vector
3993
+ * @returns This vector
3994
+ */ _proto.scale = function scale(s) {
3995
+ this._x *= s;
3996
+ this._y *= s;
3997
+ this._z *= s;
3998
+ this._w *= s;
3999
+ this._onValueChanged && this._onValueChanged();
4000
+ return this;
4001
+ };
4002
+ /**
4003
+ * Creates a clone of this vector.
4004
+ * @returns A clone of this vector
4005
+ */ _proto.clone = function clone() {
4006
+ var ret = new Vector4(this._x, this._y, this._z, this._w);
4007
+ return ret;
4008
+ };
4009
+ /**
4010
+ * Copy from vector3 like object.
4011
+ * @param source - Vector3 like object.
4012
+ * @returns This vector
4013
+ */ _proto.copyFrom = function copyFrom(source) {
4014
+ this._x = source.x;
4015
+ this._y = source.y;
4016
+ this._z = source.z;
4017
+ this._w = source.w;
4018
+ this._onValueChanged && this._onValueChanged();
4019
+ return this;
4020
+ };
4021
+ /**
4022
+ * Copy the value of this vector by an array.
4023
+ * @param array - The array
4024
+ * @param offset - The start offset of the array
4025
+ * @returns This vector
4026
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
4027
+ if (offset === void 0) offset = 0;
4028
+ this._x = array[offset];
4029
+ this._y = array[offset + 1];
4030
+ this._z = array[offset + 2];
4031
+ this._w = array[offset + 3];
4032
+ this._onValueChanged && this._onValueChanged();
4033
+ return this;
4034
+ };
4035
+ /**
4036
+ * Copy the value of this vector to an array.
4037
+ * @param out - The array
4038
+ * @param outOffset - The start offset of the array
4039
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
4040
+ if (outOffset === void 0) outOffset = 0;
4041
+ out[outOffset] = this._x;
4042
+ out[outOffset + 1] = this._y;
4043
+ out[outOffset + 2] = this._z;
4044
+ out[outOffset + 3] = this._w;
4045
+ };
4046
+ /**
4047
+ * Serialize this vector to a JSON representation.
4048
+ * @returns A JSON representation of this vector
4049
+ */ _proto.toJSON = function toJSON() {
4050
+ return {
4051
+ x: this._x,
4052
+ y: this._y,
4053
+ z: this._z,
4054
+ w: this._w
4055
+ };
4056
+ };
4057
+ /**
4058
+ * Determines the sum of two vectors.
4059
+ * @param left - The first vector to add
4060
+ * @param right - The second vector to add
4061
+ * @param out - The sum of two vectors
4062
+ */ Vector4.add = function add(left, right, out) {
4063
+ out._x = left._x + right._x;
4064
+ out._y = left._y + right._y;
4065
+ out._z = left._z + right._z;
4066
+ out._w = left._w + right._w;
4067
+ out._onValueChanged && out._onValueChanged();
4068
+ };
4069
+ /**
4070
+ * Determines the difference between two vectors.
4071
+ * @param left - The first vector to subtract
4072
+ * @param right - The second vector to subtract
4073
+ * @param out - The difference between two vectors
4074
+ */ Vector4.subtract = function subtract(left, right, out) {
4075
+ out._x = left._x - right._x;
4076
+ out._y = left._y - right._y;
4077
+ out._z = left._z - right._z;
4078
+ out._w = left._w - right._w;
4079
+ out._onValueChanged && out._onValueChanged();
4080
+ };
4081
+ /**
4082
+ * Determines the product of two vectors.
4083
+ * @param left - The first vector to multiply
4084
+ * @param right - The second vector to multiply
4085
+ * @param out - The product of two vectors
4086
+ */ Vector4.multiply = function multiply(left, right, out) {
4087
+ out._x = left._x * right._x;
4088
+ out._y = left._y * right._y;
4089
+ out._z = left._z * right._z;
4090
+ out._w = left._w * right._w;
4091
+ out._onValueChanged && out._onValueChanged();
4092
+ };
4093
+ /**
4094
+ * Determines the divisor of two vectors.
4095
+ * @param left - The first vector to divide
4096
+ * @param right - The second vector to divide
4097
+ * @param out - The divisor of two vectors
4098
+ */ Vector4.divide = function divide(left, right, out) {
4099
+ out._x = left._x / right._x;
4100
+ out._y = left._y / right._y;
4101
+ out._z = left._z / right._z;
4102
+ out._w = left._w / right._w;
4103
+ out._onValueChanged && out._onValueChanged();
4104
+ };
4105
+ /**
4106
+ * Determines the dot product of two vectors.
4107
+ * @param left - The first vector to dot
4108
+ * @param right - The second vector to dot
4109
+ * @returns The dot product of two vectors
4110
+ */ Vector4.dot = function dot(left, right) {
4111
+ return left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;
4112
+ };
4113
+ /**
4114
+ * Determines the distance of two vectors.
4115
+ * @param a - The first vector
4116
+ * @param b - The second vector
4117
+ * @returns The distance of two vectors
4118
+ */ Vector4.distance = function distance(a, b) {
4119
+ var x = b._x - a._x;
4120
+ var y = b._y - a._y;
4121
+ var z = b._z - a._z;
4122
+ var w = b._w - a._w;
4123
+ return Math.sqrt(x * x + y * y + z * z + w * w);
4124
+ };
4125
+ /**
4126
+ * Determines the squared distance of two vectors.
4127
+ * @param a - The first vector
4128
+ * @param b - The second vector
4129
+ * @returns The squared distance of two vectors
4130
+ */ Vector4.distanceSquared = function distanceSquared(a, b) {
4131
+ var x = b._x - a._x;
4132
+ var y = b._y - a._y;
4133
+ var z = b._z - a._z;
4134
+ var w = b._w - a._w;
4135
+ return x * x + y * y + z * z + w * w;
4136
+ };
4137
+ /**
4138
+ * Determines whether the specified vectors are equals.
4139
+ * @param left - The first vector to compare
4140
+ * @param right - The second vector to compare
4141
+ * @returns True if the specified vectors are equals, false otherwise
4142
+ */ Vector4.equals = function equals(left, right) {
4143
+ return MathUtil.equals(left._x, right._x) && MathUtil.equals(left._y, right._y) && MathUtil.equals(left._z, right._z) && MathUtil.equals(left._w, right._w);
4144
+ };
4145
+ /**
4146
+ * Performs a linear interpolation between two vectors.
4147
+ * @param start - The first vector
4148
+ * @param end - The second vector
4149
+ * @param t - The blend amount where 0 returns start and 1 end
4150
+ * @param out - The result of linear blending between two vectors
4151
+ */ Vector4.lerp = function lerp(start, end, t, out) {
4152
+ var _x = start._x, _y = start._y, _z = start._z, _w = start._w;
4153
+ out._x = _x + (end._x - _x) * t;
4154
+ out._y = _y + (end._y - _y) * t;
4155
+ out._z = _z + (end._z - _z) * t;
4156
+ out._w = _w + (end._w - _w) * t;
4157
+ out._onValueChanged && out._onValueChanged();
4158
+ };
4159
+ /**
4160
+ * Calculate a vector containing the largest components of the specified vectors.
4161
+ * @param left - The first vector
4162
+ * @param right - The second vector
4163
+ * @param out - The vector containing the largest components of the specified vectors
4164
+ */ Vector4.max = function max(left, right, out) {
4165
+ out._x = Math.max(left._x, right._x);
4166
+ out._y = Math.max(left._y, right._y);
4167
+ out._z = Math.max(left._z, right._z);
4168
+ out._w = Math.max(left._w, right._w);
4169
+ out._onValueChanged && out._onValueChanged();
4170
+ };
4171
+ /**
4172
+ * Calculate a vector containing the smallest components of the specified vectors.
4173
+ * @param left - The first vector
4174
+ * @param right - The second vector
4175
+ * @param out - The vector containing the smallest components of the specified vectors
4176
+ */ Vector4.min = function min(left, right, out) {
4177
+ out._x = Math.min(left._x, right._x);
4178
+ out._y = Math.min(left._y, right._y);
4179
+ out._z = Math.min(left._z, right._z);
4180
+ out._w = Math.min(left._w, right._w);
4181
+ out._onValueChanged && out._onValueChanged();
4182
+ };
4183
+ /**
4184
+ * Reverses the direction of a given vector.
4185
+ * @param a - The vector to negate
4186
+ * @param out - The vector facing in the opposite direction
4187
+ */ Vector4.negate = function negate(a, out) {
4188
+ out._x = -a._x;
4189
+ out._y = -a._y;
4190
+ out._z = -a._z;
4191
+ out._w = -a._w;
4192
+ out._onValueChanged && out._onValueChanged();
4193
+ };
4194
+ /**
4195
+ * Converts the vector into a unit vector.
4196
+ * @param a - The vector to normalize
4197
+ * @param out - The normalized vector
4198
+ */ Vector4.normalize = function normalize(a, out) {
4199
+ var _x = a._x, _y = a._y, _z = a._z, _w = a._w;
4200
+ var len = Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
4201
+ if (len > MathUtil.zeroTolerance) {
4202
+ len = 1 / len;
4203
+ out._x = _x * len;
4204
+ out._y = _y * len;
4205
+ out._z = _z * len;
4206
+ out._w = _w * len;
4207
+ out._onValueChanged && out._onValueChanged();
4208
+ }
4209
+ };
4210
+ /**
4211
+ * Scale a vector by the given value.
4212
+ * @param a - The vector to scale
4213
+ * @param s - The amount by which to scale the vector
4214
+ * @param out - The scaled vector
4215
+ */ Vector4.scale = function scale(a, s, out) {
4216
+ out._x = a._x * s;
4217
+ out._y = a._y * s;
4218
+ out._z = a._z * s;
4219
+ out._w = a._w * s;
4220
+ out._onValueChanged && out._onValueChanged();
4221
+ };
4222
+ /**
4223
+ * Performs a transformation using the given 4x4 matrix.
4224
+ * @param v - The vector to transform
4225
+ * @param m - The transform matrix
4226
+ * @param out - The transformed vector3
4227
+ */ Vector4.transform = function transform(v, m, out) {
4228
+ var _x = v._x, _y = v._y, _z = v._z, _w = v._w;
4229
+ var e = m.elements;
4230
+ out._x = _x * e[0] + _y * e[4] + _z * e[8] + _w * e[12];
4231
+ out._y = _x * e[1] + _y * e[5] + _z * e[9] + _w * e[13];
4232
+ out._z = _x * e[2] + _y * e[6] + _z * e[10] + _w * e[14];
4233
+ out._w = _x * e[3] + _y * e[7] + _z * e[11] + _w * e[15];
4234
+ out._onValueChanged && out._onValueChanged();
4235
+ };
4236
+ /**
4237
+ * Performs a transformation using the given quaternion.
4238
+ * @param v - The vector to transform
4239
+ * @param q - The transform quaternion
4240
+ * @param out - The transformed vector
4241
+ */ Vector4.transformByQuat = function transformByQuat(v, q, out) {
4242
+ var x = v._x, y = v._y, z = v._z, w = v._w;
4243
+ var qx = q._x;
4244
+ var qy = q._y;
4245
+ var qz = q._z;
4246
+ var qw = q._w;
4247
+ // calculate quat * vec
4248
+ var ix = qw * x + qy * z - qz * y;
4249
+ var iy = qw * y + qz * x - qx * z;
4250
+ var iz = qw * z + qx * y - qy * x;
4251
+ var iw = -qx * x - qy * y - qz * z;
4252
+ // calculate result * inverse quat
4253
+ out._x = ix * qw - iw * qx - iy * qz + iz * qy;
4254
+ out._y = iy * qw - iw * qy - iz * qx + ix * qz;
4255
+ out._z = iz * qw - iw * qz - ix * qy + iy * qx;
4256
+ out._w = w;
4257
+ out._onValueChanged && out._onValueChanged();
4258
+ };
4259
+ _createClass(Vector4, [
4260
+ {
4261
+ key: "x",
4262
+ get: /**
4263
+ * The x component of the vector.
4264
+ */ function get() {
4265
+ return this._x;
4266
+ },
4267
+ set: function set(value) {
4268
+ this._x = value;
4269
+ this._onValueChanged && this._onValueChanged();
4270
+ }
4271
+ },
4272
+ {
4273
+ key: "y",
4274
+ get: /**
4275
+ * The y component of the vector.
4276
+ */ function get() {
4277
+ return this._y;
4278
+ },
4279
+ set: function set(value) {
4280
+ this._y = value;
4281
+ this._onValueChanged && this._onValueChanged();
4282
+ }
4283
+ },
4284
+ {
4285
+ key: "z",
4286
+ get: /**
4287
+ * The z component of the vector.
4288
+ */ function get() {
4289
+ return this._z;
4290
+ },
4291
+ set: function set(value) {
4292
+ this._z = value;
4293
+ this._onValueChanged && this._onValueChanged();
4294
+ }
4295
+ },
4296
+ {
4297
+ key: "w",
4298
+ get: /**
4299
+ * The w component of the vector.
4300
+ */ function get() {
4301
+ return this._w;
4302
+ },
4303
+ set: function set(value) {
4304
+ this._w = value;
4305
+ this._onValueChanged && this._onValueChanged();
4306
+ }
4307
+ }
4308
+ ]);
4309
+ return Vector4;
4310
+ }();
4311
+ /** @internal */ Vector4._zero = new Vector4(0.0, 0.0, 0.0, 0.0);
4312
+ /** @internal */ Vector4._one = new Vector4(1.0, 1.0, 1.0, 1.0);
4313
+
4314
+ /**
4315
+ * Describes a color in the from of RGBA (in order: R, G, B, A).
4316
+ */ var Color = /*#__PURE__*/ function() {
4317
+ function Color(r, g, b, a) {
4318
+ if (r === void 0) r = 1;
4319
+ if (g === void 0) g = 1;
4320
+ if (b === void 0) b = 1;
4321
+ if (a === void 0) a = 1;
4322
+ /** @internal */ this._onValueChanged = null;
4323
+ this._r = r;
4324
+ this._g = g;
4325
+ this._b = b;
4326
+ this._a = a;
4327
+ }
4328
+ var _proto = Color.prototype;
4329
+ /**
4330
+ * Set the value of this color.
4331
+ * @param r - The red component of the color
4332
+ * @param g - The green component of the color
4333
+ * @param b - The blue component of the color
4334
+ * @param a - The alpha component of the color
4335
+ * @returns This color.
4336
+ */ _proto.set = function set(r, g, b, a) {
4337
+ this._r = r;
4338
+ this._g = g;
4339
+ this._b = b;
4340
+ this._a = a;
4341
+ this._onValueChanged && this._onValueChanged();
4342
+ return this;
4343
+ };
4344
+ /**
4345
+ * Determines the sum of this color and the specified color.
4346
+ * @param color - The specified color
4347
+ * @returns The added color
4348
+ */ _proto.add = function add(color) {
4349
+ this._r += color._r;
4350
+ this._g += color._g;
4351
+ this._b += color._b;
4352
+ this._a += color._a;
4353
+ this._onValueChanged && this._onValueChanged();
4354
+ return this;
4355
+ };
4356
+ /**
4357
+ * Scale this color by the given value.
4358
+ * @param s - The amount by which to scale the color
4359
+ * @returns The scaled color
4360
+ */ _proto.scale = function scale(s) {
4361
+ this._r *= s;
4362
+ this._g *= s;
4363
+ this._b *= s;
4364
+ this._a *= s;
4365
+ this._onValueChanged && this._onValueChanged();
4366
+ return this;
4367
+ };
4368
+ /**
4369
+ * Creates a clone of this color.
4370
+ * @returns A clone of this color
4371
+ */ _proto.clone = function clone() {
4372
+ var ret = new Color(this._r, this._g, this._b, this._a);
4373
+ return ret;
4374
+ };
4375
+ /**
4376
+ * Copy from color like object.
4377
+ * @param source - Color like object.
4378
+ * @returns This vector
4379
+ */ _proto.copyFrom = function copyFrom(source) {
4380
+ this._r = source.r;
4381
+ this._g = source.g;
4382
+ this._b = source.b;
4383
+ this._a = source.a;
4384
+ this._onValueChanged && this._onValueChanged();
4385
+ return this;
4386
+ };
4387
+ /**
4388
+ * Modify components (r, g, b) of this color from gamma space to linear space.
4389
+ * @param out - The color in linear space
4390
+ * @returns The color in linear space
4391
+ */ _proto.toLinear = function toLinear(out) {
4392
+ out._r = Color.gammaToLinearSpace(this._r);
4393
+ out._g = Color.gammaToLinearSpace(this._g);
4394
+ out._b = Color.gammaToLinearSpace(this._b);
4395
+ this._onValueChanged && this._onValueChanged();
4396
+ return out;
4397
+ };
4398
+ /**
4399
+ * Modify components (r, g, b) of this color from linear space to gamma space.
4400
+ * @param out - The color in gamma space
4401
+ * @returns The color in gamma space
4402
+ */ _proto.toGamma = function toGamma(out) {
4403
+ out._r = Color.linearToGammaSpace(this._r);
4404
+ out._g = Color.linearToGammaSpace(this._g);
4405
+ out._b = Color.linearToGammaSpace(this._b);
4406
+ this._onValueChanged && this._onValueChanged();
4407
+ return out;
4408
+ };
4409
+ /**
4410
+ * Gets the brightness.
4411
+ * @returns The Hue-Saturation-Brightness (HSB) saturation for this
4412
+ */ _proto.getBrightness = function getBrightness() {
4413
+ var r = this.r;
4414
+ var g = this.g;
4415
+ var b = this.b;
4416
+ var max = r;
4417
+ var min = r;
4418
+ if (g > max) max = g;
4419
+ if (b > max) max = b;
4420
+ if (g < min) min = g;
4421
+ if (b < min) min = b;
4422
+ return (max + min) / 2;
4423
+ };
4424
+ /**
4425
+ * Serialize this color to a JSON representation.
4426
+ * @return A JSON representation of this color
4427
+ */ _proto.toJSON = function toJSON() {
4428
+ return {
4429
+ r: this._r,
4430
+ g: this._g,
4431
+ b: this._b,
4432
+ a: this._a
4433
+ };
4434
+ };
4435
+ /**
4436
+ * Modify a value from the gamma space to the linear space.
4437
+ * @param value - The value in gamma space
4438
+ * @returns The value in linear space
4439
+ */ Color.gammaToLinearSpace = function gammaToLinearSpace(value) {
4440
+ // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_sRGB.txt
4441
+ // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_sRGB_decode.txt
4442
+ if (value <= 0.0) return 0.0;
4443
+ else if (value <= 0.04045) return value / 12.92;
4444
+ else if (value < 1.0) return Math.pow((value + 0.055) / 1.055, 2.4);
4445
+ else return Math.pow(value, 2.4);
4446
+ };
4447
+ /**
4448
+ * Modify a value from the linear space to the gamma space.
4449
+ * @param value - The value in linear space
4450
+ * @returns The value in gamma space
4451
+ */ Color.linearToGammaSpace = function linearToGammaSpace(value) {
4452
+ // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_sRGB.txt
4453
+ // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_sRGB_decode.txt
4454
+ if (value <= 0.0) return 0.0;
4455
+ else if (value < 0.0031308) return 12.92 * value;
4456
+ else if (value < 1.0) return 1.055 * Math.pow(value, 0.41666) - 0.055;
4457
+ else return Math.pow(value, 0.41666);
4458
+ };
4459
+ /**
4460
+ * Determines whether the specified colors are equals.
4461
+ * @param left - The first color to compare
4462
+ * @param right - The second color to compare
4463
+ * @returns True if the specified colors are equals, false otherwise
4464
+ */ Color.equals = function equals(left, right) {
4465
+ return MathUtil.equals(left._r, right._r) && MathUtil.equals(left._g, right._g) && MathUtil.equals(left._b, right._b) && MathUtil.equals(left._a, right._a);
4466
+ };
4467
+ /**
4468
+ * Determines the sum of two colors.
4469
+ * @param left - The first color to add
4470
+ * @param right - The second color to add
4471
+ * @param out - The sum of two colors
4472
+ * @returns The added color
4473
+ */ Color.add = function add(left, right, out) {
4474
+ out._r = left._r + right._r;
4475
+ out._g = left._g + right._g;
4476
+ out._b = left._b + right._b;
4477
+ out._a = left._a + right._a;
4478
+ out._onValueChanged && out._onValueChanged();
4479
+ return out;
4480
+ };
4481
+ /**
4482
+ * Determines the difference between two colors.
4483
+ * @param left - The first color to subtract
4484
+ * @param right - The second color to subtract
4485
+ * @param out - The difference between two colors
4486
+ */ Color.subtract = function subtract(left, right, out) {
4487
+ out._r = left._r - right._r;
4488
+ out._g = left._g - right._g;
4489
+ out._b = left._b - right._b;
4490
+ out._a = left._a - right._a;
4491
+ out._onValueChanged && out._onValueChanged();
4492
+ };
4493
+ /**
4494
+ * Scale a color by the given value.
4495
+ * @param left - The color to scale
4496
+ * @param s - The amount by which to scale the color
4497
+ * @param out - The scaled color
4498
+ * @returns The scaled color
4499
+ */ Color.scale = function scale(left, s, out) {
4500
+ out._r = left._r * s;
4501
+ out._g = left._g * s;
4502
+ out._b = left._b * s;
4503
+ out._a = left._a * s;
4504
+ out._onValueChanged && out._onValueChanged();
4505
+ return out;
4506
+ };
4507
+ /**
4508
+ * Performs a linear interpolation between two color.
4509
+ * @param start - The first color
4510
+ * @param end - The second color
4511
+ * @param t - The blend amount where 0 returns start and 1 end
4512
+ * @param out - The result of linear blending between two color
4513
+ */ Color.lerp = function lerp(start, end, t, out) {
4514
+ var _r = start._r, _g = start._g, _b = start._b, _a = start._a;
4515
+ out._r = _r + (end._r - _r) * t;
4516
+ out._g = _g + (end._g - _g) * t;
4517
+ out._b = _b + (end._b - _b) * t;
4518
+ out._a = _a + (end._a - _a) * t;
4519
+ out._onValueChanged && out._onValueChanged();
4520
+ return out;
4521
+ };
4522
+ _createClass(Color, [
4523
+ {
4524
+ key: "r",
4525
+ get: /**
4526
+ * The red component of the color, 0~1.
4527
+ */ function get() {
4528
+ return this._r;
4529
+ },
4530
+ set: function set(value) {
4531
+ this._r = value;
4532
+ this._onValueChanged && this._onValueChanged();
4533
+ }
4534
+ },
4535
+ {
4536
+ key: "g",
4537
+ get: /**
4538
+ * The green component of the color, 0~1.
4539
+ */ function get() {
4540
+ return this._g;
4541
+ },
4542
+ set: function set(value) {
4543
+ this._g = value;
4544
+ this._onValueChanged && this._onValueChanged();
4545
+ }
4546
+ },
4547
+ {
4548
+ key: "b",
4549
+ get: /**
4550
+ * The blue component of the color, 0~1.
4551
+ */ function get() {
4552
+ return this._b;
4553
+ },
4554
+ set: function set(value) {
4555
+ this._b = value;
4556
+ this._onValueChanged && this._onValueChanged();
4557
+ }
4558
+ },
4559
+ {
4560
+ key: "a",
4561
+ get: /**
4562
+ * The alpha component of the color, 0~1.
4563
+ */ function get() {
4564
+ return this._a;
4565
+ },
4566
+ set: function set(value) {
4567
+ this._a = value;
4568
+ this._onValueChanged && this._onValueChanged();
4569
+ }
4570
+ }
4571
+ ]);
4572
+ return Color;
4573
+ }();
4574
+
4575
+ // A 2d rectangle defined by x and y position, width and height.
4576
+ var Rect = /*#__PURE__*/ function() {
4577
+ function Rect(x, y, width, height) {
4578
+ if (x === void 0) x = 0;
4579
+ if (y === void 0) y = 0;
4580
+ if (width === void 0) width = 0;
4581
+ if (height === void 0) height = 0;
4582
+ this.x = x;
4583
+ this.y = y;
4584
+ this.width = width;
4585
+ this.height = height;
4586
+ }
4587
+ var _proto = Rect.prototype;
4588
+ /**
4589
+ * Set the value of this rectangle.
4590
+ * @param x - The x coordinate of the rectangle
4591
+ * @param y - The y coordinate of the rectangle
4592
+ * @param width - The width of the rectangle, measured from the x position
4593
+ * @param height - The height of the rectangle, measured from the y position
4594
+ * @returns This rectangle
4595
+ */ _proto.set = function set(x, y, width, height) {
4596
+ this.x = x;
4597
+ this.y = y;
4598
+ this.width = width;
4599
+ this.height = height;
4600
+ return this;
4601
+ };
4602
+ /**
4603
+ * Creates a clone of this rect.
4604
+ * @returns A clone of this rect
4605
+ */ _proto.clone = function clone() {
4606
+ return new Rect(this.x, this.y, this.width, this.height);
4607
+ };
4608
+ /**
4609
+ * Copy this rect from the specified rect.
4610
+ * @param source - The specified rect
4611
+ * @returns This rect
4612
+ */ _proto.copyFrom = function copyFrom(source) {
4613
+ this.x = source.x;
4614
+ this.y = source.y;
4615
+ this.width = source.width;
4616
+ this.height = source.height;
4617
+ return this;
4618
+ };
4619
+ return Rect;
4620
+ }();
4621
+
4622
+ /**
4623
+ * Use SH3 to represent irradiance environment maps efficiently, allowing for interactive rendering of diffuse objects under distant illumination.
4624
+ * @remarks
4625
+ * https://graphics.stanford.edu/papers/envmap/envmap.pdf
4626
+ * http://www.ppsloan.org/publications/StupidSH36.pdf
4627
+ * https://google.github.io/filament/Filament.md.html#annex/sphericalharmonics
4628
+ */ var SphericalHarmonics3 = /*#__PURE__*/ function() {
4629
+ function SphericalHarmonics3() {
4630
+ /** The coefficients of SphericalHarmonics3. */ this.coefficients = new Float32Array(27);
4631
+ }
4632
+ var _proto = SphericalHarmonics3.prototype;
4633
+ /**
4634
+ * Add light to SphericalHarmonics3.
4635
+ * @param direction - Light direction
4636
+ * @param color - Light color
4637
+ * @param deltaSolidAngle - The delta solid angle of the light
4638
+ */ _proto.addLight = function addLight(direction, color, deltaSolidAngle) {
4639
+ /**
4640
+ * Implements `EvalSHBasis` from [Projection from Cube maps] in http://www.ppsloan.org/publications/StupidSH36.pdf.
4641
+ *
4642
+ * Basis constants
4643
+ * 0: Math.sqrt(1/(4 * Math.PI))
4644
+ *
4645
+ * 1: -Math.sqrt(3 / (4 * Math.PI))
4646
+ * 2: Math.sqrt(3 / (4 * Math.PI))
4647
+ * 3: -Math.sqrt(3 / (4 * Math.PI))
4648
+ *
4649
+ * 4: Math.sqrt(15 / (4 * Math.PI))
4650
+ * 5: -Math.sqrt(15 / (4 * Math.PI))
4651
+ * 6: Math.sqrt(5 / (16 * Math.PI))
4652
+ * 7: -Math.sqrt(15 / (4 * Math.PI))
4653
+ * 8: Math.sqrt(15 / (16 * Math.PI))
4654
+ */ color.scale(deltaSolidAngle);
4655
+ var coe = this.coefficients;
4656
+ var x = direction._x, y = direction._y, z = direction._z;
4657
+ var r = color.r, g = color.g, b = color.b;
4658
+ var bv0 = 0.282095; // basis0 = 0.886227
4659
+ var bv1 = -0.488603 * y; // basis1 = -0.488603
4660
+ var bv2 = 0.488603 * z; // basis2 = 0.488603
4661
+ var bv3 = -0.488603 * x; // basis3 = -0.488603
4662
+ var bv4 = 1.092548 * (x * y); // basis4 = 1.092548
4663
+ var bv5 = -1.092548 * (y * z); // basis5 = -1.092548
4664
+ var bv6 = 0.315392 * (3 * z * z - 1); // basis6 = 0.315392
4665
+ var bv7 = -1.092548 * (x * z); // basis7 = -1.092548
4666
+ var bv8 = 0.546274 * (x * x - y * y); // basis8 = 0.546274
4667
+ coe[0] += r * bv0, coe[1] += g * bv0, coe[2] += b * bv0;
4668
+ coe[3] += r * bv1, coe[4] += g * bv1, coe[5] += b * bv1;
4669
+ coe[6] += r * bv2, coe[7] += g * bv2, coe[8] += b * bv2;
4670
+ coe[9] += r * bv3, coe[10] += g * bv3, coe[11] += b * bv3;
4671
+ coe[12] += r * bv4, coe[13] += g * bv4, coe[14] += b * bv4;
4672
+ coe[15] += r * bv5, coe[16] += g * bv5, coe[17] += b * bv5;
4673
+ coe[18] += r * bv6, coe[19] += g * bv6, coe[20] += b * bv6;
4674
+ coe[21] += r * bv7, coe[22] += g * bv7, coe[23] += b * bv7;
4675
+ coe[24] += r * bv8, coe[25] += g * bv8, coe[26] += b * bv8;
4676
+ };
4677
+ /**
4678
+ * Evaluates the color for the specified direction.
4679
+ * @param direction - Specified direction
4680
+ * @param out - Out color
4681
+ */ _proto.evaluate = function evaluate(direction, out) {
4682
+ /**
4683
+ * Equations based on data from: http://ppsloan.org/publications/StupidSH36.pdf
4684
+ *
4685
+ *
4686
+ * Basis constants
4687
+ * 0: Math.sqrt(1/(4 * Math.PI))
4688
+ *
4689
+ * 1: -Math.sqrt(3 / (4 * Math.PI))
4690
+ * 2: Math.sqrt(3 / (4 * Math.PI))
4691
+ * 3: -Math.sqrt(3 / (4 * Math.PI))
4692
+ *
4693
+ * 4: Math.sqrt(15 / (4 * Math.PI))
4694
+ * 5: -Math.sqrt(15 / (4 * Math.PI))
4695
+ * 6: Math.sqrt(5 / (16 * Math.PI))
4696
+ * 7: -Math.sqrt(15 / (4 * Math.PI))
4697
+ * 8: Math.sqrt(15 / (16 * Math.PI))
4698
+ *
4699
+ *
4700
+ * Convolution kernel
4701
+ * 0: Math.PI
4702
+ * 1: (2 * Math.PI) / 3
4703
+ * 2: Math.PI / 4
4704
+ */ var coe = this.coefficients;
4705
+ var x = direction._x, y = direction._y, z = direction._z;
4706
+ var bv0 = 0.886227; // kernel0 * basis0 = 0.886227
4707
+ var bv1 = -1.023327 * y; // kernel1 * basis1 = -1.023327
4708
+ var bv2 = 1.023327 * z; // kernel1 * basis2 = 1.023327
4709
+ var bv3 = -1.023327 * x; // kernel1 * basis3 = -1.023327
4710
+ var bv4 = 0.858086 * y * x; // kernel2 * basis4 = 0.858086
4711
+ var bv5 = -0.858086 * y * z; // kernel2 * basis5 = -0.858086
4712
+ var bv6 = 0.247708 * (3 * z * z - 1); // kernel2 * basis6 = 0.247708
4713
+ var bv7 = -0.858086 * z * x; // kernel2 * basis7 = -0.858086
4714
+ var bv8 = 0.429042 * (x * x - y * y); // kernel2 * basis8 = 0.429042
4715
+ // l0
4716
+ var r = coe[0] * bv0;
4717
+ var g = coe[1] * bv0;
4718
+ var b = coe[2] * bv0;
4719
+ // l1
4720
+ r += coe[3] * bv1 + coe[6] * bv2 + coe[9] * bv3;
4721
+ g += coe[4] * bv1 + coe[7] * bv2 + coe[10] * bv3;
4722
+ b += coe[5] * bv1 + coe[8] * bv2 + coe[11] * bv3;
4723
+ // l2
4724
+ r += coe[12] * bv4 + coe[15] * bv5 + coe[18] * bv6 + coe[21] * bv7 + coe[24] * bv8;
4725
+ g += coe[13] * bv4 + coe[16] * bv5 + coe[19] * bv6 + coe[22] * bv7 + coe[25] * bv8;
4726
+ b += coe[14] * bv4 + coe[17] * bv5 + coe[20] * bv6 + coe[23] * bv7 + coe[26] * bv8;
4727
+ out.set(r, g, b, 1.0);
4728
+ return out;
4729
+ };
4730
+ /**
4731
+ * Scale the coefficients.
4732
+ * @param s - The amount by which to scale the SphericalHarmonics3
4733
+ */ _proto.scale = function scale(s) {
4734
+ var src = this.coefficients;
4735
+ src[0] *= s, src[1] *= s, src[2] *= s;
4736
+ src[3] *= s, src[4] *= s, src[5] *= s;
4737
+ src[6] *= s, src[7] *= s, src[8] *= s;
4738
+ src[9] *= s, src[10] *= s, src[11] *= s;
4739
+ src[12] *= s, src[13] *= s, src[14] *= s;
4740
+ src[15] *= s, src[16] *= s, src[17] *= s;
4741
+ src[18] *= s, src[19] *= s, src[20] *= s;
4742
+ src[21] *= s, src[22] *= s, src[23] *= s;
4743
+ src[24] *= s, src[25] *= s, src[26] *= s;
4744
+ };
4745
+ /**
4746
+ * Creates a clone of this SphericalHarmonics3.
4747
+ * @returns A clone of this SphericalHarmonics3
4748
+ */ _proto.clone = function clone() {
4749
+ var sh = new SphericalHarmonics3();
4750
+ sh.copyFrom(this);
4751
+ return sh;
4752
+ };
4753
+ /**
4754
+ * Copy this SphericalHarmonics3 from the specified SphericalHarmonics3.
4755
+ * @param source - The specified SphericalHarmonics3
4756
+ * @returns This SphericalHarmonics3
4757
+ */ _proto.copyFrom = function copyFrom(source) {
4758
+ source.copyToArray(this.coefficients);
4759
+ return this;
4760
+ };
4761
+ /**
4762
+ * Copy the value of this spherical harmonics from an array.
4763
+ * @param array - The array
4764
+ * @param offset - The start offset of the array
4765
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
4766
+ if (offset === void 0) offset = 0;
4767
+ var s = this.coefficients;
4768
+ s[0] = array[offset], s[1] = array[1 + offset], s[2] = array[2 + offset];
4769
+ s[3] = array[3 + offset], s[4] = array[4 + offset], s[5] = array[5 + offset];
4770
+ s[6] = array[6 + offset], s[7] = array[7 + offset], s[8] = array[8 + offset];
4771
+ s[9] = array[9 + offset], s[10] = array[10 + offset], s[11] = array[11 + offset];
4772
+ s[12] = array[12 + offset], s[13] = array[13 + offset], s[14] = array[14 + offset];
4773
+ s[15] = array[15 + offset], s[16] = array[16 + offset], s[17] = array[17 + offset];
4774
+ s[18] = array[18 + offset], s[19] = array[19 + offset], s[20] = array[20 + offset];
4775
+ s[21] = array[21 + offset], s[22] = array[22 + offset], s[23] = array[23 + offset];
4776
+ s[24] = array[24 + offset], s[25] = array[25 + offset], s[26] = array[26 + offset];
4777
+ };
4778
+ /**
4779
+ * Copy the value of this spherical harmonics to an array.
4780
+ * @param out - The array
4781
+ * @param outOffset - The start offset of the array
4782
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
4783
+ if (outOffset === void 0) outOffset = 0;
4784
+ var s = this.coefficients;
4785
+ out[0 + outOffset] = s[0], out[1 + outOffset] = s[1], out[2 + outOffset] = s[2];
4786
+ out[3 + outOffset] = s[3], out[4 + outOffset] = s[4], out[5 + outOffset] = s[5];
4787
+ out[6 + outOffset] = s[6], out[7 + outOffset] = s[7], out[8 + outOffset] = s[8];
4788
+ out[9 + outOffset] = s[9], out[10 + outOffset] = s[10], out[11 + outOffset] = s[11];
4789
+ out[12 + outOffset] = s[12], out[13 + outOffset] = s[13], out[14 + outOffset] = s[14];
4790
+ out[15 + outOffset] = s[15], out[16 + outOffset] = s[16], out[17 + outOffset] = s[17];
4791
+ out[18 + outOffset] = s[18], out[19 + outOffset] = s[19], out[20 + outOffset] = s[20];
4792
+ out[21 + outOffset] = s[21], out[22 + outOffset] = s[22], out[23 + outOffset] = s[23];
4793
+ out[24 + outOffset] = s[24], out[25 + outOffset] = s[25], out[26 + outOffset] = s[26];
4794
+ };
4795
+ return SphericalHarmonics3;
4796
+ }();
4797
+
4798
+ exports.BoundingBox = BoundingBox;
4799
+ exports.BoundingFrustum = BoundingFrustum;
4800
+ exports.BoundingSphere = BoundingSphere;
4801
+ exports.CollisionUtil = CollisionUtil;
4802
+ exports.Color = Color;
4803
+ exports.MathUtil = MathUtil;
4804
+ exports.Matrix = Matrix;
4805
+ exports.Matrix3x3 = Matrix3x3;
4806
+ exports.Plane = Plane;
4807
+ exports.Quaternion = Quaternion;
4808
+ exports.Ray = Ray;
4809
+ exports.Rect = Rect;
4810
+ exports.SphericalHarmonics3 = SphericalHarmonics3;
4811
+ exports.Vector2 = Vector2;
4812
+ exports.Vector3 = Vector3;
4813
+ exports.Vector4 = Vector4;