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