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