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