@galacean/engine-math 0.0.0-experimental-animator-additive.1

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