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