@galacean/engine-xr-webxr 1.6.8 → 1.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js ADDED
@@ -0,0 +1,3620 @@
1
+ import { XRTrackedInputDevice, XRTrackingState, XRInputEventType, XRTargetRayMode, XRFeatureType, XRRequestTrackingState, XRPlaneMode } from '@galacean/engine-xr';
2
+
3
+ function _defineProperties$1(target, props) {
4
+ for (var i = 0; i < props.length; i++) {
5
+ var descriptor = props[i];
6
+ descriptor.enumerable = descriptor.enumerable || false;
7
+ descriptor.configurable = true;
8
+
9
+ if ("value" in descriptor) descriptor.writable = true;
10
+
11
+ Object.defineProperty(target, descriptor.key, descriptor);
12
+ }
13
+ }
14
+ function _create_class$1(Constructor, protoProps, staticProps) {
15
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
16
+ if (staticProps) _defineProperties$1(Constructor, staticProps);
17
+
18
+ return Constructor;
19
+ }
20
+
21
+ function _set_prototype_of(o, p) {
22
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
23
+ o.__proto__ = p;
24
+
25
+ return o;
26
+ };
27
+
28
+ return _set_prototype_of(o, p);
29
+ }
30
+
31
+ function _inherits(subClass, superClass) {
32
+ if (typeof superClass !== "function" && superClass !== null) {
33
+ throw new TypeError("Super expression must either be null or a function");
34
+ }
35
+
36
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
37
+
38
+ if (superClass) _set_prototype_of(subClass, superClass);
39
+ }
40
+
41
+ /******************************************************************************
42
+ Copyright (c) Microsoft Corporation.
43
+
44
+ Permission to use, copy, modify, and/or distribute this software for any
45
+ purpose with or without fee is hereby granted.
46
+
47
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
48
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
49
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
50
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
51
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
52
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
53
+ PERFORMANCE OF THIS SOFTWARE.
54
+ ***************************************************************************** */
55
+
56
+ function __decorate(decorators, target, key, desc) {
57
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
58
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
59
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
60
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
61
+ }
62
+
63
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
64
+ var e = new Error(message);
65
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
66
+ };
67
+
68
+ function _is_native_reflect_construct() {
69
+ // Since Reflect.construct can't be properly polyfilled, some
70
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
71
+ // Those polyfills don't allow us to subclass built-ins, so we need to
72
+ // use our fallback implementation.
73
+ try {
74
+ // If the internal slots aren't set, this throws an error similar to
75
+ // TypeError: this is not a Boolean object.
76
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
77
+ } catch (_) {}
78
+ return (_is_native_reflect_construct = function() {
79
+ return !!result;
80
+ })();
81
+ }
82
+
83
+ function _construct(Parent, args, Class) {
84
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
85
+ else {
86
+ _construct = function construct(Parent, args, Class) {
87
+ var a = [null];
88
+ a.push.apply(a, args);
89
+ var Constructor = Function.bind.apply(Parent, a);
90
+ var instance = new Constructor();
91
+
92
+ if (Class) _set_prototype_of(instance, Class.prototype);
93
+
94
+ return instance;
95
+ };
96
+ }
97
+
98
+ return _construct.apply(null, arguments);
99
+ }
100
+
101
+ function parseXRMode(mode) {
102
+ switch(mode){
103
+ case 1:
104
+ return "immersive-ar";
105
+ case 2:
106
+ return "immersive-vr";
107
+ default:
108
+ return null;
109
+ }
110
+ }
111
+ function getInputSource(inputSource) {
112
+ var type;
113
+ switch(inputSource.targetRayMode){
114
+ case "gaze":
115
+ break;
116
+ case "screen":
117
+ return XRTrackedInputDevice.Controller;
118
+ case "tracked-pointer":
119
+ if (inputSource.hand) {
120
+ switch(inputSource.handedness){
121
+ case "left":
122
+ return XRTrackedInputDevice.LeftHand;
123
+ case "right":
124
+ return XRTrackedInputDevice.RightHand;
125
+ }
126
+ } else {
127
+ switch(inputSource.handedness){
128
+ case "left":
129
+ return XRTrackedInputDevice.LeftController;
130
+ case "right":
131
+ return XRTrackedInputDevice.RightController;
132
+ }
133
+ }
134
+ break;
135
+ }
136
+ return type;
137
+ }
138
+ function viewToCamera(type) {
139
+ switch(type){
140
+ case "left":
141
+ return XRTrackedInputDevice.LeftCamera;
142
+ case "right":
143
+ return XRTrackedInputDevice.RightCamera;
144
+ default:
145
+ return XRTrackedInputDevice.Camera;
146
+ }
147
+ }
148
+
149
+ function _defineProperties(target, props) {
150
+ for(var i = 0; i < props.length; i++){
151
+ var descriptor = props[i];
152
+ descriptor.enumerable = descriptor.enumerable || false;
153
+ descriptor.configurable = true;
154
+ if ("value" in descriptor) descriptor.writable = true;
155
+ Object.defineProperty(target, descriptor.key, descriptor);
156
+ }
157
+ }
158
+ function _create_class(Constructor, protoProps, staticProps) {
159
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
160
+ if (staticProps) _defineProperties(Constructor, staticProps);
161
+ return Constructor;
162
+ }
163
+ /**
164
+ * Common utility methods for math operations.
165
+ */ var MathUtil = /*#__PURE__*/ function() {
166
+ function MathUtil() {}
167
+ /**
168
+ * Clamps the specified value.
169
+ * @param v - The specified value
170
+ * @param min - The min value
171
+ * @param max - The max value
172
+ * @returns The result of clamping a value between min and max
173
+ */ MathUtil.clamp = function clamp(v, min, max) {
174
+ return Math.max(min, Math.min(max, v));
175
+ };
176
+ /**
177
+ * Checks if a and b are almost equals.
178
+ * The absolute value of the difference between a and b is close to zero.
179
+ * @param a - The left value to compare
180
+ * @param b - The right value to compare
181
+ * @returns True if a almost equal to b, false otherwise
182
+ */ MathUtil.equals = function equals(a, b) {
183
+ return Math.abs(a - b) <= MathUtil.zeroTolerance;
184
+ };
185
+ /**
186
+ * Determines whether the specified v is pow2.
187
+ * @param v - The specified v
188
+ * @returns True if the specified v is pow2, false otherwise
189
+ */ MathUtil.isPowerOf2 = function isPowerOf2(v) {
190
+ return (v & v - 1) === 0;
191
+ };
192
+ /**
193
+ * Modify the specified r from radian to degree.
194
+ * @param r - The specified r
195
+ * @returns The degree value
196
+ */ MathUtil.radianToDegree = function radianToDegree(r) {
197
+ return r * MathUtil.radToDegreeFactor;
198
+ };
199
+ /**
200
+ * Modify the specified d from degree to radian.
201
+ * @param d - The specified d
202
+ * @returns The radian value
203
+ */ MathUtil.degreeToRadian = function degreeToRadian(d) {
204
+ return d * MathUtil.degreeToRadFactor;
205
+ };
206
+ /**
207
+ * Linearly interpolate between two values
208
+ * @param start - Specify the start of the range in which to interpolate
209
+ * @param end - Specify the end of the range in which to interpolate
210
+ * @param t - The blend amount where 0 returns start and 1 end
211
+ * @returns The result of linear blending between start and end
212
+ */ MathUtil.lerp = function lerp(start, end, t) {
213
+ return start + (end - start) * t;
214
+ };
215
+ return MathUtil;
216
+ }();
217
+ /** The value for which all absolute numbers smaller than are considered equal to zero. */ MathUtil.zeroTolerance = 1e-6;
218
+ /** The conversion factor that radian to degree. */ MathUtil.radToDegreeFactor = 180 / Math.PI;
219
+ /** The conversion factor that degree to radian. */ MathUtil.degreeToRadFactor = Math.PI / 180;
220
+ /**
221
+ * Describes a 3D-vector.
222
+ */ var Vector3 = /*#__PURE__*/ function() {
223
+ function Vector3(x, y, z) {
224
+ if (x === void 0) x = 0;
225
+ if (y === void 0) y = 0;
226
+ if (z === void 0) z = 0;
227
+ /** @internal */ this._onValueChanged = null;
228
+ this._x = x;
229
+ this._y = y;
230
+ this._z = z;
231
+ }
232
+ var _proto = Vector3.prototype;
233
+ /**
234
+ * Set the value of this vector.
235
+ * @param x - The x component of the vector
236
+ * @param y - The y component of the vector
237
+ * @param z - The z component of the vector
238
+ * @returns This vector
239
+ */ _proto.set = function set(x, y, z) {
240
+ this._x = x;
241
+ this._y = y;
242
+ this._z = z;
243
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
244
+ return this;
245
+ };
246
+ /**
247
+ * Determines the sum of this vector and the specified vector.
248
+ * @param right - The specified vector
249
+ * @returns This vector
250
+ */ _proto.add = function add(right) {
251
+ this._x += right._x;
252
+ this._y += right._y;
253
+ this._z += right._z;
254
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
255
+ return this;
256
+ };
257
+ /**
258
+ * Determines the difference of this vector and the specified vector.
259
+ * @param right - The specified vector
260
+ * @returns This vector
261
+ */ _proto.subtract = function subtract(right) {
262
+ this._x -= right._x;
263
+ this._y -= right._y;
264
+ this._z -= right._z;
265
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
266
+ return this;
267
+ };
268
+ /**
269
+ * Determines the product of this vector and the specified vector.
270
+ * @param right - The specified vector
271
+ * @returns This vector
272
+ */ _proto.multiply = function multiply(right) {
273
+ this._x *= right._x;
274
+ this._y *= right._y;
275
+ this._z *= right._z;
276
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
277
+ return this;
278
+ };
279
+ /**
280
+ * Determines the divisor of this vector and the specified vector.
281
+ * @param right - The specified vector
282
+ * @returns This vector
283
+ */ _proto.divide = function divide(right) {
284
+ this._x /= right._x;
285
+ this._y /= right._y;
286
+ this._z /= right._z;
287
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
288
+ return this;
289
+ };
290
+ /**
291
+ * Calculate the length of this vector.
292
+ * @returns The length of this vector
293
+ */ _proto.length = function length() {
294
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z;
295
+ return Math.sqrt(_x * _x + _y * _y + _z * _z);
296
+ };
297
+ /**
298
+ * Calculate the squared length of this vector.
299
+ * @returns The squared length of this vector
300
+ */ _proto.lengthSquared = function lengthSquared() {
301
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z;
302
+ return _x * _x + _y * _y + _z * _z;
303
+ };
304
+ /**
305
+ * Reverses the direction of this vector.
306
+ * @returns This vector
307
+ */ _proto.negate = function negate() {
308
+ this._x = -this._x;
309
+ this._y = -this._y;
310
+ this._z = -this._z;
311
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
312
+ return this;
313
+ };
314
+ /**
315
+ * Converts this vector into a unit vector.
316
+ * @returns This vector
317
+ */ _proto.normalize = function normalize() {
318
+ Vector3.normalize(this, this);
319
+ return this;
320
+ };
321
+ /**
322
+ * Scale this vector by the given value.
323
+ * @param s - The amount by which to scale the vector
324
+ * @returns This vector
325
+ */ _proto.scale = function scale(s) {
326
+ this._x *= s;
327
+ this._y *= s;
328
+ this._z *= s;
329
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
330
+ return this;
331
+ };
332
+ /**
333
+ * This vector performs a normal transformation using the given 4x4 matrix.
334
+ * @remarks
335
+ * A normal transform performs the transformation with the assumption that the w component
336
+ * is zero. This causes the fourth row and fourth column of the matrix to be unused. The
337
+ * end result is a vector that is not translated, but all other transformation properties
338
+ * apply. This is often preferred for normal vectors as normals purely represent direction
339
+ * rather than location because normal vectors should not be translated.
340
+ * @param m - The transform matrix
341
+ * @returns This vector
342
+ */ _proto.transformNormal = function transformNormal(m) {
343
+ Vector3.transformNormal(this, m, this);
344
+ return this;
345
+ };
346
+ /**
347
+ * This vector performs a transformation using the given 4x4 matrix.
348
+ * @param m - The transform matrix
349
+ * @returns This vector
350
+ */ _proto.transformToVec3 = function transformToVec3(m) {
351
+ Vector3.transformToVec3(this, m, this);
352
+ return this;
353
+ };
354
+ /**
355
+ * This vector performs a coordinate transformation using the given 4x4 matrix.
356
+ * @remarks
357
+ * A coordinate transform performs the transformation with the assumption that the w component
358
+ * is one. The four dimensional vector obtained from the transformation operation has each
359
+ * component in the vector divided by the w component. This forces the w-component to be one and
360
+ * therefore makes the vector homogeneous. The homogeneous vector is often preferred when working
361
+ * with coordinates as the w component can safely be ignored.
362
+ * @param m - The transform matrix
363
+ * @returns This vector
364
+ */ _proto.transformCoordinate = function transformCoordinate(m) {
365
+ Vector3.transformCoordinate(this, m, this);
366
+ return this;
367
+ };
368
+ /**
369
+ * This vector performs a transformation using the given quaternion.
370
+ * @param quaternion - The transform quaternion
371
+ * @returns This vector
372
+ */ _proto.transformByQuat = function transformByQuat(quaternion) {
373
+ Vector3.transformByQuat(this, quaternion, this);
374
+ return this;
375
+ };
376
+ /**
377
+ * Creates a clone of this vector.
378
+ * @returns A clone of this vector
379
+ */ _proto.clone = function clone() {
380
+ return new Vector3(this._x, this._y, this._z);
381
+ };
382
+ /**
383
+ * Copy from vector3 like object.
384
+ * @param source - Vector3 like object.
385
+ * @returns This vector
386
+ */ _proto.copyFrom = function copyFrom(source) {
387
+ this._x = source.x;
388
+ this._y = source.y;
389
+ this._z = source.z;
390
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
391
+ return this;
392
+ };
393
+ /**
394
+ * Copy to vector3 like object.
395
+ * @param target - Vector3 like object
396
+ * @returns This Vector3 like object
397
+ */ _proto.copyTo = function copyTo(target) {
398
+ target.x = this._x;
399
+ target.y = this._y;
400
+ target.z = this._z;
401
+ return target;
402
+ };
403
+ /**
404
+ * Copy the value of this vector from an array.
405
+ * @param array - The array
406
+ * @param offset - The start offset of the array
407
+ * @returns This vector
408
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
409
+ if (offset === void 0) offset = 0;
410
+ this._x = array[offset];
411
+ this._y = array[offset + 1];
412
+ this._z = array[offset + 2];
413
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
414
+ return this;
415
+ };
416
+ /**
417
+ * Copy the value of this vector to an array.
418
+ * @param out - The array
419
+ * @param outOffset - The start offset of the array
420
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
421
+ if (outOffset === void 0) outOffset = 0;
422
+ out[outOffset] = this._x;
423
+ out[outOffset + 1] = this._y;
424
+ out[outOffset + 2] = this._z;
425
+ };
426
+ /**
427
+ * Serialize this vector to a JSON representation.
428
+ * @returns A JSON representation of this vector
429
+ */ _proto.toJSON = function toJSON() {
430
+ return {
431
+ x: this._x,
432
+ y: this._y,
433
+ z: this._z
434
+ };
435
+ };
436
+ /**
437
+ * Determines the sum of two vectors.
438
+ * @param left - The first vector to add
439
+ * @param right - The second vector to add
440
+ * @param out - The sum of two vectors
441
+ */ Vector3.add = function add(left, right, out) {
442
+ out._x = left._x + right._x;
443
+ out._y = left._y + right._y;
444
+ out._z = left._z + right._z;
445
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
446
+ };
447
+ /**
448
+ * Determines the difference between two vectors.
449
+ * @param left - The first vector to subtract
450
+ * @param right - The second vector to subtract
451
+ * @param out - The difference between two vectors
452
+ */ Vector3.subtract = function subtract(left, right, out) {
453
+ out._x = left._x - right._x;
454
+ out._y = left._y - right._y;
455
+ out._z = left._z - right._z;
456
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
457
+ };
458
+ /**
459
+ * Determines the product of two vectors.
460
+ * @param left - The first vector to multiply
461
+ * @param right - The second vector to multiply
462
+ * @param out - The product of two vectors
463
+ */ Vector3.multiply = function multiply(left, right, out) {
464
+ out._x = left._x * right._x;
465
+ out._y = left._y * right._y;
466
+ out._z = left._z * right._z;
467
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
468
+ };
469
+ /**
470
+ * Determines the divisor of two vectors.
471
+ * @param left - The first vector to divide
472
+ * @param right - The second vector to divide
473
+ * @param out - The divisor of two vectors
474
+ */ Vector3.divide = function divide(left, right, out) {
475
+ out._x = left._x / right._x;
476
+ out._y = left._y / right._y;
477
+ out._z = left._z / right._z;
478
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
479
+ };
480
+ /**
481
+ * Determines the dot product of two vectors.
482
+ * @param left - The first vector to dot
483
+ * @param right - The second vector to dot
484
+ * @returns The dot product of two vectors
485
+ */ Vector3.dot = function dot(left, right) {
486
+ return left._x * right._x + left._y * right._y + left._z * right._z;
487
+ };
488
+ /**
489
+ * Determines the cross product of two vectors.
490
+ * @param left - The first vector to cross
491
+ * @param right - The second vector to cross
492
+ * @param out - The cross product of two vectors
493
+ */ Vector3.cross = function cross(left, right, out) {
494
+ var ax = left._x;
495
+ var ay = left._y;
496
+ var az = left._z;
497
+ var bx = right._x;
498
+ var by = right._y;
499
+ var bz = right._z;
500
+ out.set(ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx);
501
+ };
502
+ /**
503
+ * Determines the distance of two vectors.
504
+ * @param a - The first vector
505
+ * @param b - The second vector
506
+ * @returns The distance of two vectors
507
+ */ Vector3.distance = function distance(a, b) {
508
+ var x = b._x - a._x;
509
+ var y = b._y - a._y;
510
+ var z = b._z - a._z;
511
+ return Math.sqrt(x * x + y * y + z * z);
512
+ };
513
+ /**
514
+ * Determines the squared distance of two vectors.
515
+ * @param a - The first vector
516
+ * @param b - The second vector
517
+ * @returns The squared distance of two vectors
518
+ */ Vector3.distanceSquared = function distanceSquared(a, b) {
519
+ var x = b._x - a._x;
520
+ var y = b._y - a._y;
521
+ var z = b._z - a._z;
522
+ return x * x + y * y + z * z;
523
+ };
524
+ /**
525
+ * Determines whether the specified vectors are equals.
526
+ * @param left - The first vector to compare
527
+ * @param right - The second vector to compare
528
+ * @returns True if the specified vectors are equals, false otherwise
529
+ */ Vector3.equals = function equals(left, right) {
530
+ return MathUtil.equals(left._x, right._x) && MathUtil.equals(left._y, right._y) && MathUtil.equals(left._z, right._z);
531
+ };
532
+ /**
533
+ * Performs a linear interpolation between two vectors.
534
+ * @param start - The first vector
535
+ * @param end - The second vector
536
+ * @param t - The blend amount where 0 returns start and 1 end
537
+ * @param out - The result of linear blending between two vectors
538
+ */ Vector3.lerp = function lerp(start, end, t, out) {
539
+ var _x = start._x, _y = start._y, _z = start._z;
540
+ out._x = _x + (end._x - _x) * t;
541
+ out._y = _y + (end._y - _y) * t;
542
+ out._z = _z + (end._z - _z) * t;
543
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
544
+ };
545
+ /**
546
+ * Calculate a vector containing the largest components of the specified vectors.
547
+ * @param left - The first vector
548
+ * @param right - The second vector
549
+ * @param out - The vector containing the largest components of the specified vectors
550
+ */ Vector3.max = function max(left, right, out) {
551
+ out._x = Math.max(left._x, right._x);
552
+ out._y = Math.max(left._y, right._y);
553
+ out._z = Math.max(left._z, right._z);
554
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
555
+ };
556
+ /**
557
+ * Calculate a vector containing the smallest components of the specified vectors.
558
+ * @param left - The first vector
559
+ * @param right - The second vector
560
+ * @param out - The vector containing the smallest components of the specified vectors
561
+ */ Vector3.min = function min(left, right, out) {
562
+ out._x = Math.min(left._x, right._x);
563
+ out._y = Math.min(left._y, right._y);
564
+ out._z = Math.min(left._z, right._z);
565
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
566
+ };
567
+ /**
568
+ * Reverses the direction of a given vector.
569
+ * @param a - The vector to negate
570
+ * @param out - The vector facing in the opposite direction
571
+ */ Vector3.negate = function negate(a, out) {
572
+ out._x = -a._x;
573
+ out._y = -a._y;
574
+ out._z = -a._z;
575
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
576
+ };
577
+ /**
578
+ * Converts the vector into a unit vector.
579
+ * @param a - The vector to normalize
580
+ * @param out - The normalized vector
581
+ */ Vector3.normalize = function normalize(a, out) {
582
+ var _x = a._x, _y = a._y, _z = a._z;
583
+ var len = Math.sqrt(_x * _x + _y * _y + _z * _z);
584
+ if (len > MathUtil.zeroTolerance) {
585
+ len = 1 / len;
586
+ out.set(_x * len, _y * len, _z * len);
587
+ }
588
+ };
589
+ /**
590
+ * Scale a vector by the given value.
591
+ * @param a - The vector to scale
592
+ * @param s - The amount by which to scale the vector
593
+ * @param out - The scaled vector
594
+ */ Vector3.scale = function scale(a, s, out) {
595
+ out._x = a._x * s;
596
+ out._y = a._y * s;
597
+ out._z = a._z * s;
598
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
599
+ };
600
+ /**
601
+ * Performs a normal transformation using the given 4x4 matrix.
602
+ * @remarks
603
+ * A normal transform performs the transformation with the assumption that the w component
604
+ * is zero. This causes the fourth row and fourth column of the matrix to be unused. The
605
+ * end result is a vector that is not translated, but all other transformation properties
606
+ * apply. This is often preferred for normal vectors as normals purely represent direction
607
+ * rather than location because normal vectors should not be translated.
608
+ * @param v - The normal vector to transform
609
+ * @param m - The transform matrix
610
+ * @param out - The transformed normal
611
+ */ Vector3.transformNormal = function transformNormal(v, m, out) {
612
+ var _x = v._x, _y = v._y, _z = v._z;
613
+ var e = m.elements;
614
+ out._x = _x * e[0] + _y * e[4] + _z * e[8];
615
+ out._y = _x * e[1] + _y * e[5] + _z * e[9];
616
+ out._z = _x * e[2] + _y * e[6] + _z * e[10];
617
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
618
+ };
619
+ /**
620
+ * Performs a transformation using the given 4x4 matrix.
621
+ * @param v - The vector to transform
622
+ * @param m - The transform matrix
623
+ * @param out - The transformed vector3
624
+ */ Vector3.transformToVec3 = function transformToVec3(v, m, out) {
625
+ var _x = v._x, _y = v._y, _z = v._z;
626
+ var e = m.elements;
627
+ out._x = _x * e[0] + _y * e[4] + _z * e[8] + e[12];
628
+ out._y = _x * e[1] + _y * e[5] + _z * e[9] + e[13];
629
+ out._z = _x * e[2] + _y * e[6] + _z * e[10] + e[14];
630
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
631
+ };
632
+ /**
633
+ * Performs a transformation from vector3 to vector4 using the given 4x4 matrix.
634
+ * @param v - The vector to transform
635
+ * @param m - The transform matrix
636
+ * @param out - The transformed vector4
637
+ */ Vector3.transformToVec4 = function transformToVec4(v, m, out) {
638
+ var _x = v._x, _y = v._y, _z = v._z;
639
+ var e = m.elements;
640
+ out._x = _x * e[0] + _y * e[4] + _z * e[8] + e[12];
641
+ out._y = _x * e[1] + _y * e[5] + _z * e[9] + e[13];
642
+ out._z = _x * e[2] + _y * e[6] + _z * e[10] + e[14];
643
+ out._w = _x * e[3] + _y * e[7] + _z * e[11] + e[15];
644
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
645
+ };
646
+ /**
647
+ * Performs a coordinate transformation using the given 4x4 matrix.
648
+ *
649
+ * @remarks
650
+ * A coordinate transform performs the transformation with the assumption that the w component
651
+ * is one. The four dimensional vector obtained from the transformation operation has each
652
+ * component in the vector divided by the w component. This forces the w-component to be one and
653
+ * therefore makes the vector homogeneous. The homogeneous vector is often preferred when working
654
+ * with coordinates as the w component can safely be ignored.
655
+ * @param v - The coordinate vector to transform
656
+ * @param m - The transform matrix
657
+ * @param out - The transformed coordinates
658
+ */ Vector3.transformCoordinate = function transformCoordinate(v, m, out) {
659
+ var _x = v._x, _y = v._y, _z = v._z;
660
+ var e = m.elements;
661
+ var w = _x * e[3] + _y * e[7] + _z * e[11] + e[15];
662
+ w = 1.0 / w;
663
+ out._x = (_x * e[0] + _y * e[4] + _z * e[8] + e[12]) * w;
664
+ out._y = (_x * e[1] + _y * e[5] + _z * e[9] + e[13]) * w;
665
+ out._z = (_x * e[2] + _y * e[6] + _z * e[10] + e[14]) * w;
666
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
667
+ };
668
+ /**
669
+ * Performs a transformation using the given quaternion.
670
+ * @param v - The vector to transform
671
+ * @param quaternion - The transform quaternion
672
+ * @param out - The transformed vector
673
+ */ Vector3.transformByQuat = function transformByQuat(v, quaternion, out) {
674
+ var _x = v._x, _y = v._y, _z = v._z;
675
+ var qx = quaternion._x, qy = quaternion._y, qz = quaternion._z, qw = quaternion._w;
676
+ // calculate quat * vec
677
+ var ix = qw * _x + qy * _z - qz * _y;
678
+ var iy = qw * _y + qz * _x - qx * _z;
679
+ var iz = qw * _z + qx * _y - qy * _x;
680
+ var iw = -qx * _x - qy * _y - qz * _z;
681
+ // calculate result * inverse quat
682
+ out._x = ix * qw - iw * qx - iy * qz + iz * qy;
683
+ out._y = iy * qw - iw * qy - iz * qx + ix * qz;
684
+ out._z = iz * qw - iw * qz - ix * qy + iy * qx;
685
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
686
+ };
687
+ _create_class(Vector3, [
688
+ {
689
+ key: "x",
690
+ get: /**
691
+ * The x component of the vector.
692
+ */ function get() {
693
+ return this._x;
694
+ },
695
+ set: function set(value) {
696
+ this._x = value;
697
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
698
+ }
699
+ },
700
+ {
701
+ key: "y",
702
+ get: /**
703
+ * The y component of the vector.
704
+ */ function get() {
705
+ return this._y;
706
+ },
707
+ set: function set(value) {
708
+ this._y = value;
709
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
710
+ }
711
+ },
712
+ {
713
+ key: "z",
714
+ get: /**
715
+ * The z component of the vector.
716
+ */ function get() {
717
+ return this._z;
718
+ },
719
+ set: function set(value) {
720
+ this._z = value;
721
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
722
+ }
723
+ }
724
+ ]);
725
+ return Vector3;
726
+ }();
727
+ /** @internal */ Vector3._zero = new Vector3(0.0, 0.0, 0.0);
728
+ /** @internal */ Vector3._one = new Vector3(1.0, 1.0, 1.0);
729
+ new Vector3();
730
+ new Vector3();
731
+ new Vector3();
732
+ new Vector3();
733
+ new Vector3();
734
+ new Vector3();
735
+ /**
736
+ * Represents a 3x3 mathematical matrix.
737
+ */ var Matrix3x3 = /*#__PURE__*/ function() {
738
+ function Matrix3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33) {
739
+ if (m11 === void 0) m11 = 1;
740
+ if (m12 === void 0) m12 = 0;
741
+ if (m13 === void 0) m13 = 0;
742
+ if (m21 === void 0) m21 = 0;
743
+ if (m22 === void 0) m22 = 1;
744
+ if (m23 === void 0) m23 = 0;
745
+ if (m31 === void 0) m31 = 0;
746
+ if (m32 === void 0) m32 = 0;
747
+ if (m33 === void 0) m33 = 1;
748
+ /**
749
+ * An array containing the elements of the matrix (column matrix).
750
+ * @remarks
751
+ * elements[0] first column and first row value m11
752
+ * elements[1] first column and second row value m12
753
+ * elements[2] first column and third row value m13
754
+ * elements[3] second column and first row value m21
755
+ * and so on
756
+ */ this.elements = new Float32Array(9);
757
+ var e = this.elements;
758
+ e[0] = m11;
759
+ e[1] = m12;
760
+ e[2] = m13;
761
+ e[3] = m21;
762
+ e[4] = m22;
763
+ e[5] = m23;
764
+ e[6] = m31;
765
+ e[7] = m32;
766
+ e[8] = m33;
767
+ }
768
+ var _proto = Matrix3x3.prototype;
769
+ /**
770
+ * Set the value of this matrix, and return this matrix.
771
+ * @param m11
772
+ * @param m12
773
+ * @param m13
774
+ * @param m21
775
+ * @param m22
776
+ * @param m23
777
+ * @param m31
778
+ * @param m32
779
+ * @param m33
780
+ * @returns This matrix
781
+ */ _proto.set = function set(m11, m12, m13, m21, m22, m23, m31, m32, m33) {
782
+ var e = this.elements;
783
+ e[0] = m11;
784
+ e[1] = m12;
785
+ e[2] = m13;
786
+ e[3] = m21;
787
+ e[4] = m22;
788
+ e[5] = m23;
789
+ e[6] = m31;
790
+ e[7] = m32;
791
+ e[8] = m33;
792
+ return this;
793
+ };
794
+ /**
795
+ * Determines the sum of this matrix and the specified matrix.
796
+ * @param right - The specified matrix
797
+ * @returns This matrix that store the sum of the two matrices
798
+ */ _proto.add = function add(right) {
799
+ Matrix3x3.add(this, right, this);
800
+ return this;
801
+ };
802
+ /**
803
+ * Determines the difference between this matrix and the specified matrix.
804
+ * @param right - The specified matrix
805
+ * @returns This matrix that store the difference between the two matrices
806
+ */ _proto.subtract = function subtract(right) {
807
+ Matrix3x3.subtract(this, right, this);
808
+ return this;
809
+ };
810
+ /**
811
+ * Determines the product of this matrix and the specified matrix.
812
+ * @param right - The specified matrix
813
+ * @returns This matrix that store the product of the two matrices
814
+ */ _proto.multiply = function multiply(right) {
815
+ Matrix3x3.multiply(this, right, this);
816
+ return this;
817
+ };
818
+ /**
819
+ * Calculate a determinant of this matrix.
820
+ * @returns The determinant of this matrix
821
+ */ _proto.determinant = function determinant() {
822
+ var e = this.elements;
823
+ var a11 = e[0], a12 = e[1], a13 = e[2];
824
+ var a21 = e[3], a22 = e[4], a23 = e[5];
825
+ var a31 = e[6], a32 = e[7], a33 = e[8];
826
+ var b12 = a33 * a22 - a23 * a32;
827
+ var b22 = -a33 * a21 + a23 * a31;
828
+ var b32 = a32 * a21 - a22 * a31;
829
+ return a11 * b12 + a12 * b22 + a13 * b32;
830
+ };
831
+ /**
832
+ * Identity this matrix.
833
+ * @returns This matrix after identity
834
+ */ _proto.identity = function identity() {
835
+ var e = this.elements;
836
+ e[0] = 1;
837
+ e[1] = 0;
838
+ e[2] = 0;
839
+ e[3] = 0;
840
+ e[4] = 1;
841
+ e[5] = 0;
842
+ e[6] = 0;
843
+ e[7] = 0;
844
+ e[8] = 1;
845
+ return this;
846
+ };
847
+ /**
848
+ * Invert the matrix.
849
+ * @returns The matrix after invert
850
+ */ _proto.invert = function invert() {
851
+ Matrix3x3.invert(this, this);
852
+ return this;
853
+ };
854
+ /**
855
+ * This matrix rotates around an angle.
856
+ * @param r - The rotation angle in radians
857
+ * @returns This matrix after rotate
858
+ */ _proto.rotate = function rotate(r) {
859
+ Matrix3x3.rotate(this, r, this);
860
+ return this;
861
+ };
862
+ /**
863
+ * Scale this matrix by a given vector.
864
+ * @param s - The given vector
865
+ * @returns This matrix after scale
866
+ */ _proto.scale = function scale(s) {
867
+ Matrix3x3.scale(this, s, this);
868
+ return this;
869
+ };
870
+ /**
871
+ * Translate this matrix by a given vector.
872
+ * @param translation - The given vector
873
+ * @returns This matrix after translate
874
+ */ _proto.translate = function translate(translation) {
875
+ Matrix3x3.translate(this, translation, this);
876
+ return this;
877
+ };
878
+ /**
879
+ * Calculate the transpose of this matrix.
880
+ * @returns This matrix after transpose
881
+ */ _proto.transpose = function transpose() {
882
+ Matrix3x3.transpose(this, this);
883
+ return this;
884
+ };
885
+ /**
886
+ * Creates a clone of this matrix.
887
+ * @returns A clone of this matrix
888
+ */ _proto.clone = function clone() {
889
+ var e = this.elements;
890
+ var ret = new Matrix3x3(e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8]);
891
+ return ret;
892
+ };
893
+ /**
894
+ * Copy this matrix from the specified matrix.
895
+ * @param source - The specified matrix
896
+ * @returns This matrix
897
+ */ _proto.copyFrom = function copyFrom(source) {
898
+ var e = this.elements;
899
+ var se = source.elements;
900
+ e[0] = se[0];
901
+ e[1] = se[1];
902
+ e[2] = se[2];
903
+ e[3] = se[3];
904
+ e[4] = se[4];
905
+ e[5] = se[5];
906
+ e[6] = se[6];
907
+ e[7] = se[7];
908
+ e[8] = se[8];
909
+ return this;
910
+ };
911
+ /**
912
+ * Copy the value of this matrix from an array.
913
+ * @param array - The array
914
+ * @param offset - The start offset of the array
915
+ * @returns This matrix
916
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
917
+ if (offset === void 0) offset = 0;
918
+ var srce = this.elements;
919
+ for(var i = 0; i < 12; i++){
920
+ srce[i] = array[i + offset];
921
+ }
922
+ return this;
923
+ };
924
+ /**
925
+ * Copy the value of this matrix to an array.
926
+ * @param out - The array
927
+ * @param outOffset - The start offset of the array
928
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
929
+ if (outOffset === void 0) outOffset = 0;
930
+ var e = this.elements;
931
+ out[outOffset] = e[0];
932
+ out[outOffset + 1] = e[1];
933
+ out[outOffset + 2] = e[2];
934
+ out[outOffset + 3] = e[3];
935
+ out[outOffset + 4] = e[4];
936
+ out[outOffset + 5] = e[5];
937
+ out[outOffset + 6] = e[6];
938
+ out[outOffset + 7] = e[7];
939
+ out[outOffset + 8] = e[8];
940
+ };
941
+ /**
942
+ * Copy the value of this 3x3 matrix from the specified 4x4 matrix.
943
+ * upper-left principle
944
+ * @param source - The specified 4x4 matrix
945
+ * @returns This 3x3 matrix
946
+ */ _proto.copyFromMatrix = function copyFromMatrix(source) {
947
+ var ae = source.elements;
948
+ var e = this.elements;
949
+ e[0] = ae[0];
950
+ e[1] = ae[1];
951
+ e[2] = ae[2];
952
+ e[3] = ae[4];
953
+ e[4] = ae[5];
954
+ e[5] = ae[6];
955
+ e[6] = ae[8];
956
+ e[7] = ae[9];
957
+ e[8] = ae[10];
958
+ return this;
959
+ };
960
+ /**
961
+ * Determines the sum of two matrices.
962
+ * @param left - The first matrix to add
963
+ * @param right - The second matrix to add
964
+ * @param out - The sum of two matrices
965
+ */ Matrix3x3.add = function add(left, right, out) {
966
+ var le = left.elements;
967
+ var re = right.elements;
968
+ var oe = out.elements;
969
+ oe[0] = le[0] + re[0];
970
+ oe[1] = le[1] + re[1];
971
+ oe[2] = le[2] + re[2];
972
+ oe[3] = le[3] + re[3];
973
+ oe[4] = le[4] + re[4];
974
+ oe[5] = le[5] + re[5];
975
+ oe[6] = le[6] + re[6];
976
+ oe[7] = le[7] + re[7];
977
+ oe[8] = le[8] + re[8];
978
+ };
979
+ /**
980
+ * Determines the difference between two matrices.
981
+ * @param left - The first matrix to subtract
982
+ * @param right - The second matrix to subtract
983
+ * @param out - The difference between two matrices
984
+ */ Matrix3x3.subtract = function subtract(left, right, out) {
985
+ var le = left.elements;
986
+ var re = right.elements;
987
+ var oe = out.elements;
988
+ oe[0] = le[0] - re[0];
989
+ oe[1] = le[1] - re[1];
990
+ oe[2] = le[2] - re[2];
991
+ oe[3] = le[3] - re[3];
992
+ oe[4] = le[4] - re[4];
993
+ oe[5] = le[5] - re[5];
994
+ oe[6] = le[6] - re[6];
995
+ oe[7] = le[7] - re[7];
996
+ oe[8] = le[8] - re[8];
997
+ };
998
+ /**
999
+ * Determines the product of two matrices.
1000
+ * @param left - The first matrix to multiply
1001
+ * @param right - The second matrix to multiply
1002
+ * @param out - The product of two matrices
1003
+ */ Matrix3x3.multiply = function multiply(left, right, out) {
1004
+ var le = left.elements;
1005
+ var re = right.elements;
1006
+ var oe = out.elements;
1007
+ var l11 = le[0], l12 = le[1], l13 = le[2];
1008
+ var l21 = le[3], l22 = le[4], l23 = le[5];
1009
+ var l31 = le[6], l32 = le[7], l33 = le[8];
1010
+ var r11 = re[0], r12 = re[1], r13 = re[2];
1011
+ var r21 = re[3], r22 = re[4], r23 = re[5];
1012
+ var r31 = re[6], r32 = re[7], r33 = re[8];
1013
+ oe[0] = l11 * r11 + l21 * r12 + l31 * r13;
1014
+ oe[1] = l12 * r11 + l22 * r12 + l32 * r13;
1015
+ oe[2] = l13 * r11 + l23 * r12 + l33 * r13;
1016
+ oe[3] = l11 * r21 + l21 * r22 + l31 * r23;
1017
+ oe[4] = l12 * r21 + l22 * r22 + l32 * r23;
1018
+ oe[5] = l13 * r21 + l23 * r22 + l33 * r23;
1019
+ oe[6] = l11 * r31 + l21 * r32 + l31 * r33;
1020
+ oe[7] = l12 * r31 + l22 * r32 + l32 * r33;
1021
+ oe[8] = l13 * r31 + l23 * r32 + l33 * r33;
1022
+ };
1023
+ /**
1024
+ * Determines whether the specified matrices are equals.
1025
+ * @param left - The first matrix to compare
1026
+ * @param right - The second matrix to compare
1027
+ * @returns True if the specified matrices are equals, false otherwise
1028
+ */ Matrix3x3.equals = function equals(left, right) {
1029
+ var le = left.elements;
1030
+ var re = right.elements;
1031
+ 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]);
1032
+ };
1033
+ /**
1034
+ * Performs a linear interpolation between two matrices.
1035
+ * @param start - The first matrix
1036
+ * @param end - The second matrix
1037
+ * @param t - The blend amount where 0 returns start and 1 end
1038
+ * @param out - The result of linear blending between two matrices
1039
+ */ Matrix3x3.lerp = function lerp(start, end, t, out) {
1040
+ var se = start.elements;
1041
+ var ee = end.elements;
1042
+ var oe = out.elements;
1043
+ var inv = 1.0 - t;
1044
+ oe[0] = se[0] * inv + ee[0] * t;
1045
+ oe[1] = se[1] * inv + ee[1] * t;
1046
+ oe[2] = se[2] * inv + ee[2] * t;
1047
+ oe[3] = se[3] * inv + ee[3] * t;
1048
+ oe[4] = se[4] * inv + ee[4] * t;
1049
+ oe[5] = se[5] * inv + ee[5] * t;
1050
+ oe[6] = se[6] * inv + ee[6] * t;
1051
+ oe[7] = se[7] * inv + ee[7] * t;
1052
+ oe[8] = se[8] * inv + ee[8] * t;
1053
+ };
1054
+ /**
1055
+ * Calculate a rotation matrix from a quaternion.
1056
+ * @param quaternion - The quaternion used to calculate the matrix
1057
+ * @param out - The calculated rotation matrix
1058
+ */ Matrix3x3.rotationQuaternion = function rotationQuaternion(quaternion, out) {
1059
+ var oe = out.elements;
1060
+ var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
1061
+ var x2 = x + x;
1062
+ var y2 = y + y;
1063
+ var z2 = z + z;
1064
+ var xx = x * x2;
1065
+ var yx = y * x2;
1066
+ var yy = y * y2;
1067
+ var zx = z * x2;
1068
+ var zy = z * y2;
1069
+ var zz = z * z2;
1070
+ var wx = w * x2;
1071
+ var wy = w * y2;
1072
+ var wz = w * z2;
1073
+ oe[0] = 1 - yy - zz;
1074
+ oe[3] = yx - wz;
1075
+ oe[6] = zx + wy;
1076
+ oe[1] = yx + wz;
1077
+ oe[4] = 1 - xx - zz;
1078
+ oe[7] = zy - wx;
1079
+ oe[2] = zx - wy;
1080
+ oe[5] = zy + wx;
1081
+ oe[8] = 1 - xx - yy;
1082
+ };
1083
+ /**
1084
+ * Calculate a matrix from scale vector.
1085
+ * @param s - The scale vector
1086
+ * @param out - The calculated matrix
1087
+ */ Matrix3x3.scaling = function scaling(s, out) {
1088
+ var oe = out.elements;
1089
+ oe[0] = s._x;
1090
+ oe[1] = 0;
1091
+ oe[2] = 0;
1092
+ oe[3] = 0;
1093
+ oe[4] = s._y;
1094
+ oe[5] = 0;
1095
+ oe[6] = 0;
1096
+ oe[7] = 0;
1097
+ oe[8] = 1;
1098
+ };
1099
+ /**
1100
+ * Calculate a matrix from translation vector.
1101
+ * @param translation - The translation vector
1102
+ * @param out - The calculated matrix
1103
+ */ Matrix3x3.translation = function translation(translation, out) {
1104
+ var oe = out.elements;
1105
+ oe[0] = 1;
1106
+ oe[1] = 0;
1107
+ oe[2] = 0;
1108
+ oe[3] = 0;
1109
+ oe[4] = 1;
1110
+ oe[5] = 0;
1111
+ oe[6] = translation._x;
1112
+ oe[7] = translation._y;
1113
+ oe[8] = 1;
1114
+ };
1115
+ /**
1116
+ * Calculate the inverse of the specified matrix.
1117
+ * @param a - The matrix whose inverse is to be calculated
1118
+ * @param out - The inverse of the specified matrix
1119
+ */ Matrix3x3.invert = function invert(a, out) {
1120
+ var ae = a.elements;
1121
+ var oe = out.elements;
1122
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2];
1123
+ var a21 = ae[3], a22 = ae[4], a23 = ae[5];
1124
+ var a31 = ae[6], a32 = ae[7], a33 = ae[8];
1125
+ var b12 = a33 * a22 - a23 * a32;
1126
+ var b22 = -a33 * a21 + a23 * a31;
1127
+ var b32 = a32 * a21 - a22 * a31;
1128
+ var det = a11 * b12 + a12 * b22 + a13 * b32;
1129
+ if (!det) {
1130
+ return;
1131
+ }
1132
+ det = 1.0 / det;
1133
+ oe[0] = b12 * det;
1134
+ oe[1] = (-a33 * a12 + a13 * a32) * det;
1135
+ oe[2] = (a23 * a12 - a13 * a22) * det;
1136
+ oe[3] = b22 * det;
1137
+ oe[4] = (a33 * a11 - a13 * a31) * det;
1138
+ oe[5] = (-a23 * a11 + a13 * a21) * det;
1139
+ oe[6] = b32 * det;
1140
+ oe[7] = (-a32 * a11 + a12 * a31) * det;
1141
+ oe[8] = (a22 * a11 - a12 * a21) * det;
1142
+ };
1143
+ /**
1144
+ * Calculate a 3x3 normal matrix from a 4x4 matrix.
1145
+ * @remarks The calculation process is the transpose matrix of the inverse matrix.
1146
+ * @param mat4 - The 4x4 matrix
1147
+ * @param out - THe 3x3 normal matrix
1148
+ */ Matrix3x3.normalMatrix = function normalMatrix(mat4, out) {
1149
+ var ae = mat4.elements;
1150
+ var oe = out.elements;
1151
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2], a14 = ae[3];
1152
+ var a21 = ae[4], a22 = ae[5], a23 = ae[6], a24 = ae[7];
1153
+ var a31 = ae[8], a32 = ae[9], a33 = ae[10], a34 = ae[11];
1154
+ var a41 = ae[12], a42 = ae[13], a43 = ae[14], a44 = ae[15];
1155
+ var b00 = a11 * a22 - a12 * a21;
1156
+ var b01 = a11 * a23 - a13 * a21;
1157
+ var b02 = a11 * a24 - a14 * a21;
1158
+ var b03 = a12 * a23 - a13 * a22;
1159
+ var b04 = a12 * a24 - a14 * a22;
1160
+ var b05 = a13 * a24 - a14 * a23;
1161
+ var b06 = a31 * a42 - a32 * a41;
1162
+ var b07 = a31 * a43 - a33 * a41;
1163
+ var b08 = a31 * a44 - a34 * a41;
1164
+ var b09 = a32 * a43 - a33 * a42;
1165
+ var b10 = a32 * a44 - a34 * a42;
1166
+ var b11 = a33 * a44 - a34 * a43;
1167
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1168
+ if (!det) {
1169
+ return null;
1170
+ }
1171
+ det = 1.0 / det;
1172
+ oe[0] = (a22 * b11 - a23 * b10 + a24 * b09) * det;
1173
+ oe[1] = (a23 * b08 - a21 * b11 - a24 * b07) * det;
1174
+ oe[2] = (a21 * b10 - a22 * b08 + a24 * b06) * det;
1175
+ oe[3] = (a13 * b10 - a12 * b11 - a14 * b09) * det;
1176
+ oe[4] = (a11 * b11 - a13 * b08 + a14 * b07) * det;
1177
+ oe[5] = (a12 * b08 - a11 * b10 - a14 * b06) * det;
1178
+ oe[6] = (a42 * b05 - a43 * b04 + a44 * b03) * det;
1179
+ oe[7] = (a43 * b02 - a41 * b05 - a44 * b01) * det;
1180
+ oe[8] = (a41 * b04 - a42 * b02 + a44 * b00) * det;
1181
+ };
1182
+ /**
1183
+ * The specified matrix rotates around an angle.
1184
+ * @param a - The specified matrix
1185
+ * @param r - The rotation angle in radians
1186
+ * @param out - The rotated matrix
1187
+ */ Matrix3x3.rotate = function rotate(a, r, out) {
1188
+ var ae = a.elements;
1189
+ var oe = out.elements;
1190
+ var s = Math.sin(r);
1191
+ var c = Math.cos(r);
1192
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2];
1193
+ var a21 = ae[3], a22 = ae[4], a23 = ae[5];
1194
+ var a31 = ae[6], a32 = ae[7], a33 = ae[8];
1195
+ oe[0] = c * a11 + s * a21;
1196
+ oe[1] = c * a12 + s * a22;
1197
+ oe[2] = c * a13 + s * a23;
1198
+ oe[3] = c * a21 - s * a11;
1199
+ oe[4] = c * a22 - s * a12;
1200
+ oe[5] = c * a23 - s * a13;
1201
+ oe[6] = a31;
1202
+ oe[7] = a32;
1203
+ oe[8] = a33;
1204
+ };
1205
+ /**
1206
+ * Scale a matrix by a given vector.
1207
+ * @param m - The matrix
1208
+ * @param s - The given vector
1209
+ * @param out - The scaled matrix
1210
+ */ Matrix3x3.scale = function scale(m, s, out) {
1211
+ var x = s._x, y = s._y;
1212
+ var ae = m.elements;
1213
+ var oe = out.elements;
1214
+ oe[0] = x * ae[0];
1215
+ oe[1] = x * ae[1];
1216
+ oe[2] = x * ae[2];
1217
+ oe[3] = y * ae[3];
1218
+ oe[4] = y * ae[4];
1219
+ oe[5] = y * ae[5];
1220
+ oe[6] = ae[6];
1221
+ oe[7] = ae[7];
1222
+ oe[8] = ae[8];
1223
+ };
1224
+ /**
1225
+ * Translate a matrix by a given vector.
1226
+ * @param m - The matrix
1227
+ * @param translation - The given vector
1228
+ * @param out - The translated matrix
1229
+ */ Matrix3x3.translate = function translate(m, translation, out) {
1230
+ var x = translation._x, y = translation._y;
1231
+ var ae = m.elements;
1232
+ var oe = out.elements;
1233
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2];
1234
+ var a21 = ae[3], a22 = ae[4], a23 = ae[5];
1235
+ var a31 = ae[6], a32 = ae[7], a33 = ae[8];
1236
+ oe[0] = a11;
1237
+ oe[1] = a12;
1238
+ oe[2] = a13;
1239
+ oe[3] = a21;
1240
+ oe[4] = a22;
1241
+ oe[5] = a23;
1242
+ oe[6] = x * a11 + y * a21 + a31;
1243
+ oe[7] = x * a12 + y * a22 + a32;
1244
+ oe[8] = x * a13 + y * a23 + a33;
1245
+ };
1246
+ /**
1247
+ * Calculate the transpose of the specified matrix.
1248
+ * @param a - The specified matrix
1249
+ * @param out - The transpose of the specified matrix
1250
+ */ Matrix3x3.transpose = function transpose(a, out) {
1251
+ var ae = a.elements;
1252
+ var oe = out.elements;
1253
+ if (out === a) {
1254
+ var a12 = ae[1];
1255
+ var a13 = ae[2];
1256
+ var a23 = ae[5];
1257
+ oe[1] = ae[3];
1258
+ oe[2] = ae[6];
1259
+ oe[3] = a12;
1260
+ oe[5] = ae[7];
1261
+ oe[6] = a13;
1262
+ oe[7] = a23;
1263
+ } else {
1264
+ oe[0] = ae[0];
1265
+ oe[1] = ae[3];
1266
+ oe[2] = ae[6];
1267
+ oe[3] = ae[1];
1268
+ oe[4] = ae[4];
1269
+ oe[5] = ae[7];
1270
+ oe[6] = ae[2];
1271
+ oe[7] = ae[5];
1272
+ oe[8] = ae[8];
1273
+ }
1274
+ };
1275
+ return Matrix3x3;
1276
+ }();
1277
+ /**
1278
+ * Represents a four dimensional mathematical quaternion.
1279
+ */ var Quaternion = /*#__PURE__*/ function() {
1280
+ function Quaternion(x, y, z, w) {
1281
+ if (x === void 0) x = 0;
1282
+ if (y === void 0) y = 0;
1283
+ if (z === void 0) z = 0;
1284
+ if (w === void 0) w = 1;
1285
+ /** @internal */ this._onValueChanged = null;
1286
+ this._x = x;
1287
+ this._y = y;
1288
+ this._z = z;
1289
+ this._w = w;
1290
+ }
1291
+ var _proto = Quaternion.prototype;
1292
+ /**
1293
+ * Set the value of this quaternion, and return this quaternion.
1294
+ * @param x - The x component of the quaternion
1295
+ * @param y - The y component of the quaternion
1296
+ * @param z - The z component of the quaternion
1297
+ * @param w - The w component of the quaternion
1298
+ * @returns This quaternion
1299
+ */ _proto.set = function set(x, y, z, w) {
1300
+ this._x = x;
1301
+ this._y = y;
1302
+ this._z = z;
1303
+ this._w = w;
1304
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1305
+ return this;
1306
+ };
1307
+ /**
1308
+ * Transforms this quaternion into its conjugated version.
1309
+ * @returns This quaternion
1310
+ */ _proto.conjugate = function conjugate() {
1311
+ this._x *= -1;
1312
+ this._y *= -1;
1313
+ this._z *= -1;
1314
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1315
+ return this;
1316
+ };
1317
+ /**
1318
+ * Get the rotation axis and rotation angle of the quaternion (unit: radians).
1319
+ * @param out - The axis as an output parameter
1320
+ * @returns The rotation angle (unit: radians)
1321
+ */ _proto.getAxisAngle = function getAxisAngle(out) {
1322
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z;
1323
+ var length = _x * _x + _y * _y + _z * _z;
1324
+ if (length < MathUtil.zeroTolerance) {
1325
+ out._x = 1;
1326
+ out._y = 0;
1327
+ out._z = 0;
1328
+ return 0;
1329
+ } else {
1330
+ var inv = 1.0 / length;
1331
+ out._x = this._x * inv;
1332
+ out._y = this._y * inv;
1333
+ out._z = this._z * inv;
1334
+ return Math.acos(this._w) * 2.0;
1335
+ }
1336
+ };
1337
+ /**
1338
+ * Identity this quaternion.
1339
+ * @returns This quaternion after identity
1340
+ */ _proto.identity = function identity() {
1341
+ this._x = 0;
1342
+ this._y = 0;
1343
+ this._z = 0;
1344
+ this._w = 1;
1345
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1346
+ return this;
1347
+ };
1348
+ /**
1349
+ * Calculate the length of this quaternion.
1350
+ * @returns The length of this quaternion
1351
+ */ _proto.length = function length() {
1352
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
1353
+ return Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
1354
+ };
1355
+ /**
1356
+ * Calculates the squared length of this quaternion.
1357
+ * @returns The squared length of this quaternion
1358
+ */ _proto.lengthSquared = function lengthSquared() {
1359
+ var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
1360
+ return _x * _x + _y * _y + _z * _z + _w * _w;
1361
+ };
1362
+ /**
1363
+ * Converts this quaternion into a unit quaternion.
1364
+ * @returns This quaternion
1365
+ */ _proto.normalize = function normalize() {
1366
+ Quaternion.normalize(this, this);
1367
+ return this;
1368
+ };
1369
+ /**
1370
+ * Get the euler of this quaternion.
1371
+ * @param out - The euler (in radians) as an output parameter
1372
+ * @returns Euler x->pitch y->yaw z->roll
1373
+ */ _proto.toEuler = function toEuler(out) {
1374
+ this._toYawPitchRoll(out);
1375
+ var t = out._x;
1376
+ out._x = out._y;
1377
+ out._y = t;
1378
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1379
+ return out;
1380
+ };
1381
+ /**
1382
+ * Get the euler of this quaternion.
1383
+ * @param out - The euler (in radians) as an output parameter
1384
+ * @returns Euler x->yaw y->pitch z->roll
1385
+ */ _proto.toYawPitchRoll = function toYawPitchRoll(out) {
1386
+ this._toYawPitchRoll(out);
1387
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1388
+ return out;
1389
+ };
1390
+ /**
1391
+ * Calculate this quaternion rotate around X axis.
1392
+ * @param rad - The rotation angle in radians
1393
+ * @returns This quaternion
1394
+ */ _proto.rotateX = function rotateX(rad) {
1395
+ Quaternion.rotateX(this, rad, this);
1396
+ return this;
1397
+ };
1398
+ /**
1399
+ * Calculate this quaternion rotate around Y axis.
1400
+ * @param rad - The rotation angle in radians
1401
+ * @returns This quaternion
1402
+ */ _proto.rotateY = function rotateY(rad) {
1403
+ Quaternion.rotateY(this, rad, this);
1404
+ return this;
1405
+ };
1406
+ /**
1407
+ * Calculate this quaternion rotate around Z axis.
1408
+ * @param rad - The rotation angle in radians
1409
+ * @returns This quaternion
1410
+ */ _proto.rotateZ = function rotateZ(rad) {
1411
+ Quaternion.rotateZ(this, rad, this);
1412
+ return this;
1413
+ };
1414
+ /**
1415
+ * Calculate this quaternion rotates around an arbitrary axis.
1416
+ * @param axis - The axis
1417
+ * @param rad - The rotation angle in radians
1418
+ * @returns This quaternion
1419
+ */ _proto.rotationAxisAngle = function rotationAxisAngle(axis, rad) {
1420
+ Quaternion.rotationAxisAngle(axis, rad, this);
1421
+ return this;
1422
+ };
1423
+ /**
1424
+ * Determines the product of this quaternion and the specified quaternion.
1425
+ * @param quat - The specified quaternion
1426
+ * @returns The product of the two quaternions
1427
+ */ _proto.multiply = function multiply(quat) {
1428
+ Quaternion.multiply(this, quat, this);
1429
+ return this;
1430
+ };
1431
+ /**
1432
+ * Invert this quaternion.
1433
+ * @returns This quaternion after invert
1434
+ */ _proto.invert = function invert() {
1435
+ Quaternion.invert(this, this);
1436
+ return this;
1437
+ };
1438
+ /**
1439
+ * Determines the dot product of this quaternion and the specified quaternion.
1440
+ * @param quat - The specified quaternion
1441
+ * @returns The dot product of two quaternions
1442
+ */ _proto.dot = function dot(quat) {
1443
+ return Quaternion.dot(this, quat);
1444
+ };
1445
+ /**
1446
+ * Performs a linear blend between this quaternion and the specified quaternion.
1447
+ * @param quat - The specified quaternion
1448
+ * @param t - The blend amount where 0 returns this and 1 quat
1449
+ * @returns - The result of linear blending between two quaternions
1450
+ */ _proto.lerp = function lerp(quat, t) {
1451
+ Quaternion.lerp(this, quat, t, this);
1452
+ return this;
1453
+ };
1454
+ /**
1455
+ * Calculate this quaternion rotation around an arbitrary axis.
1456
+ * @param axis - The axis
1457
+ * @param rad - The rotation angle in radians
1458
+ * @returns This quaternion
1459
+ */ _proto.rotateAxisAngle = function rotateAxisAngle(axis, rad) {
1460
+ Quaternion._tempQuat1.rotationAxisAngle(axis, rad);
1461
+ this.multiply(Quaternion._tempQuat1);
1462
+ return this;
1463
+ };
1464
+ /**
1465
+ * Creates a clone of this quaternion.
1466
+ * @returns A clone of this quaternion
1467
+ */ _proto.clone = function clone() {
1468
+ return new Quaternion(this._x, this._y, this._z, this._w);
1469
+ };
1470
+ /**
1471
+ * Copy this quaternion from the specified quaternion.
1472
+ * @param source - The specified quaternion
1473
+ * @returns This quaternion
1474
+ */ _proto.copyFrom = function copyFrom(source) {
1475
+ this._x = source.x;
1476
+ this._y = source.y;
1477
+ this._z = source.z;
1478
+ this._w = source.w;
1479
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1480
+ return this;
1481
+ };
1482
+ /**
1483
+ * Copy this quaternion to the specified quaternion.
1484
+ * @param target - The specified quaternion
1485
+ * @returns This specified quaternion
1486
+ */ _proto.copyTo = function copyTo(target) {
1487
+ target.x = this._x;
1488
+ target.y = this._y;
1489
+ target.z = this._z;
1490
+ target.w = this._w;
1491
+ return target;
1492
+ };
1493
+ /**
1494
+ * Copy the value of this quaternion from an array.
1495
+ * @param array - The array
1496
+ * @param offset - The start offset of the array
1497
+ * @returns This quaternion
1498
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
1499
+ if (offset === void 0) offset = 0;
1500
+ this._x = array[offset];
1501
+ this._y = array[offset + 1];
1502
+ this._z = array[offset + 2];
1503
+ this._w = array[offset + 3];
1504
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1505
+ return this;
1506
+ };
1507
+ /**
1508
+ * Copy the value of this quaternion to an array.
1509
+ * @param out - The array
1510
+ * @param outOffset - The start offset of the array
1511
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
1512
+ if (outOffset === void 0) outOffset = 0;
1513
+ out[outOffset] = this._x;
1514
+ out[outOffset + 1] = this._y;
1515
+ out[outOffset + 2] = this._z;
1516
+ out[outOffset + 3] = this._w;
1517
+ };
1518
+ /**
1519
+ * Serialize this quaternion to a JSON representation.
1520
+ * @returns A JSON Object representation of this quaternion
1521
+ */ _proto.toJSON = function toJSON() {
1522
+ return {
1523
+ x: this._x,
1524
+ y: this._y,
1525
+ z: this._z,
1526
+ w: this._w
1527
+ };
1528
+ };
1529
+ _proto._toYawPitchRoll = function _toYawPitchRoll(out) {
1530
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
1531
+ var _this = this, x = _this._x, y = _this._y, z = _this._z, w = _this._w;
1532
+ var xx = x * x;
1533
+ var yy = y * y;
1534
+ var zz = z * z;
1535
+ var ww = w * w;
1536
+ var unit = xx + yy + zz + ww;
1537
+ var test = 2 * (x * w - y * z);
1538
+ if (test > (1 - MathUtil.zeroTolerance) * unit) {
1539
+ out._x = Math.atan2(2.0 * (w * y - x * z), xx + ww - yy - zz);
1540
+ out._y = Math.PI / 2;
1541
+ out._z = 0;
1542
+ } else if (test < -(1 - MathUtil.zeroTolerance) * unit) {
1543
+ out._x = Math.atan2(2.0 * (w * y - x * z), xx + ww - yy - zz);
1544
+ out._y = -Math.PI / 2;
1545
+ out._z = 0;
1546
+ } else {
1547
+ out._x = Math.atan2(2.0 * (z * x + y * w), zz + ww - yy - xx);
1548
+ out._y = Math.asin(test / unit);
1549
+ out._z = Math.atan2(2.0 * (x * y + z * w), yy + ww - zz - xx);
1550
+ }
1551
+ };
1552
+ /**
1553
+ * Determines the sum of two quaternions.
1554
+ * @param left - The first quaternion to add
1555
+ * @param right - The second quaternion to add
1556
+ * @param out - The sum of two quaternions
1557
+ */ Quaternion.add = function add(left, right, out) {
1558
+ out._x = left._x + right._x;
1559
+ out._y = left._y + right._y;
1560
+ out._z = left._z + right._z;
1561
+ out._w = left._w + right._w;
1562
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1563
+ };
1564
+ /**
1565
+ * Determines the product of two quaternions.
1566
+ * @param left - The first quaternion to multiply
1567
+ * @param right - The second quaternion to multiply
1568
+ * @param out - The product of two quaternions
1569
+ */ Quaternion.multiply = function multiply(left, right, out) {
1570
+ var ax = left._x, ay = left._y, az = left._z, aw = left._w;
1571
+ var bx = right._x, by = right._y, bz = right._z, bw = right._w;
1572
+ out._x = ax * bw + aw * bx + ay * bz - az * by;
1573
+ out._y = ay * bw + aw * by + az * bx - ax * bz;
1574
+ out._z = az * bw + aw * bz + ax * by - ay * bx;
1575
+ out._w = aw * bw - ax * bx - ay * by - az * bz;
1576
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1577
+ };
1578
+ /**
1579
+ * Calculate quaternion that contains conjugated version of the specified quaternion.
1580
+ * @param a - The specified quaternion
1581
+ * @param out - The conjugate version of the specified quaternion
1582
+ */ Quaternion.conjugate = function conjugate(a, out) {
1583
+ out._x = -a._x;
1584
+ out._y = -a._y;
1585
+ out._z = -a._z;
1586
+ out._w = a._w;
1587
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1588
+ };
1589
+ /**
1590
+ * Determines the dot product of two quaternions.
1591
+ * @param left - The first quaternion to dot
1592
+ * @param right - The second quaternion to dot
1593
+ * @returns The dot product of two quaternions
1594
+ */ Quaternion.dot = function dot(left, right) {
1595
+ return left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;
1596
+ };
1597
+ /**
1598
+ * Determines whether the specified quaternions are equals.
1599
+ * @param left - The first quaternion to compare
1600
+ * @param right - The second quaternion to compare
1601
+ * @returns True if the specified quaternions are equals, false otherwise
1602
+ */ Quaternion.equals = function equals(left, right) {
1603
+ 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);
1604
+ };
1605
+ /**
1606
+ * Calculate a quaternion rotates around an arbitrary axis.
1607
+ * @param axis - The axis
1608
+ * @param rad - The rotation angle in radians
1609
+ * @param out - The quaternion after rotate
1610
+ */ Quaternion.rotationAxisAngle = function rotationAxisAngle(axis, rad, out) {
1611
+ var normalAxis = Quaternion._tempVector3;
1612
+ Vector3.normalize(axis, normalAxis);
1613
+ rad *= 0.5;
1614
+ var s = Math.sin(rad);
1615
+ out._x = normalAxis._x * s;
1616
+ out._y = normalAxis._y * s;
1617
+ out._z = normalAxis._z * s;
1618
+ out._w = Math.cos(rad);
1619
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1620
+ };
1621
+ /**
1622
+ * Calculate a quaternion rotates around x, y, z axis (pitch/yaw/roll).
1623
+ * @param x - The radian of rotation around X (pitch)
1624
+ * @param y - The radian of rotation around Y (yaw)
1625
+ * @param z - The radian of rotation around Z (roll)
1626
+ * @param out - The calculated quaternion
1627
+ */ Quaternion.rotationEuler = function rotationEuler(x, y, z, out) {
1628
+ Quaternion.rotationYawPitchRoll(y, x, z, out);
1629
+ };
1630
+ /**
1631
+ * Calculate a quaternion from the specified yaw, pitch and roll angles.
1632
+ * @param yaw - Yaw around the y axis in radians
1633
+ * @param pitch - Pitch around the x axis in radians
1634
+ * @param roll - Roll around the z axis in radians
1635
+ * @param out - The calculated quaternion
1636
+ */ Quaternion.rotationYawPitchRoll = function rotationYawPitchRoll(yaw, pitch, roll, out) {
1637
+ var halfRoll = roll * 0.5;
1638
+ var halfPitch = pitch * 0.5;
1639
+ var halfYaw = yaw * 0.5;
1640
+ var sinRoll = Math.sin(halfRoll);
1641
+ var cosRoll = Math.cos(halfRoll);
1642
+ var sinPitch = Math.sin(halfPitch);
1643
+ var cosPitch = Math.cos(halfPitch);
1644
+ var sinYaw = Math.sin(halfYaw);
1645
+ var cosYaw = Math.cos(halfYaw);
1646
+ var cosYawPitch = cosYaw * cosPitch;
1647
+ var sinYawPitch = sinYaw * sinPitch;
1648
+ out._x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;
1649
+ out._y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
1650
+ out._z = cosYawPitch * sinRoll - sinYawPitch * cosRoll;
1651
+ out._w = cosYawPitch * cosRoll + sinYawPitch * sinRoll;
1652
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1653
+ };
1654
+ /**
1655
+ * Calculate a quaternion from the specified 3x3 matrix.
1656
+ * @param m - The specified 3x3 matrix
1657
+ * @param out - The calculated quaternion
1658
+ */ Quaternion.rotationMatrix3x3 = function rotationMatrix3x3(m, out) {
1659
+ var me = m.elements;
1660
+ var m11 = me[0], m12 = me[1], m13 = me[2];
1661
+ var m21 = me[3], m22 = me[4], m23 = me[5];
1662
+ var m31 = me[6], m32 = me[7], m33 = me[8];
1663
+ var scale = m11 + m22 + m33;
1664
+ var sqrt, half;
1665
+ if (scale > 0) {
1666
+ sqrt = Math.sqrt(scale + 1.0);
1667
+ out._w = sqrt * 0.5;
1668
+ sqrt = 0.5 / sqrt;
1669
+ out._x = (m23 - m32) * sqrt;
1670
+ out._y = (m31 - m13) * sqrt;
1671
+ out._z = (m12 - m21) * sqrt;
1672
+ } else if (m11 >= m22 && m11 >= m33) {
1673
+ sqrt = Math.sqrt(1.0 + m11 - m22 - m33);
1674
+ half = 0.5 / sqrt;
1675
+ out._x = 0.5 * sqrt;
1676
+ out._y = (m12 + m21) * half;
1677
+ out._z = (m13 + m31) * half;
1678
+ out._w = (m23 - m32) * half;
1679
+ } else if (m22 > m33) {
1680
+ sqrt = Math.sqrt(1.0 + m22 - m11 - m33);
1681
+ half = 0.5 / sqrt;
1682
+ out._x = (m21 + m12) * half;
1683
+ out._y = 0.5 * sqrt;
1684
+ out._z = (m32 + m23) * half;
1685
+ out._w = (m31 - m13) * half;
1686
+ } else {
1687
+ sqrt = Math.sqrt(1.0 + m33 - m11 - m22);
1688
+ half = 0.5 / sqrt;
1689
+ out._x = (m13 + m31) * half;
1690
+ out._y = (m23 + m32) * half;
1691
+ out._z = 0.5 * sqrt;
1692
+ out._w = (m12 - m21) * half;
1693
+ }
1694
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1695
+ };
1696
+ /**
1697
+ * Calculate the inverse of the specified quaternion.
1698
+ * @param a - The quaternion whose inverse is to be calculated
1699
+ * @param out - The inverse of the specified quaternion
1700
+ */ Quaternion.invert = function invert(a, out) {
1701
+ var x = a._x, y = a._y, z = a._z, w = a._w;
1702
+ var dot = x * x + y * y + z * z + w * w;
1703
+ if (dot > MathUtil.zeroTolerance) {
1704
+ var invDot = 1.0 / dot;
1705
+ out._x = -x * invDot;
1706
+ out._y = -y * invDot;
1707
+ out._z = -z * invDot;
1708
+ out._w = w * invDot;
1709
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1710
+ }
1711
+ };
1712
+ /**
1713
+ * Performs a linear blend between two quaternions.
1714
+ * @param start - The first quaternion
1715
+ * @param end - The second quaternion
1716
+ * @param t - The blend amount where 0 returns start and 1 end
1717
+ * @param out - The result of linear blending between two quaternions
1718
+ */ Quaternion.lerp = function lerp(start, end, t, out) {
1719
+ var inv = 1.0 - t;
1720
+ if (Quaternion.dot(start, end) >= 0) {
1721
+ out._x = start._x * inv + end._x * t;
1722
+ out._y = start._y * inv + end._y * t;
1723
+ out._z = start._z * inv + end._z * t;
1724
+ out._w = start._w * inv + end._w * t;
1725
+ } else {
1726
+ out._x = start._x * inv - end._x * t;
1727
+ out._y = start._y * inv - end._y * t;
1728
+ out._z = start._z * inv - end._z * t;
1729
+ out._w = start._w * inv - end._w * t;
1730
+ }
1731
+ out.normalize();
1732
+ };
1733
+ /**
1734
+ * Performs a spherical linear blend between two quaternions.
1735
+ * @param start - The first quaternion
1736
+ * @param end - The second quaternion
1737
+ * @param amount - The blend amount where 0 returns start and 1 end
1738
+ * @param out - The result of spherical linear blending between two quaternions
1739
+ */ Quaternion.slerp = function slerp(start, end, amount, out) {
1740
+ var opposite;
1741
+ var inverse;
1742
+ var dot = Quaternion.dot(start, end);
1743
+ if (Math.abs(dot) > 1.0 - MathUtil.zeroTolerance) {
1744
+ inverse = 1.0 - amount;
1745
+ opposite = amount * Math.sign(dot);
1746
+ } else {
1747
+ var acos = Math.acos(Math.abs(dot));
1748
+ var invSin = 1.0 / Math.sin(acos);
1749
+ inverse = Math.sin((1.0 - amount) * acos) * invSin;
1750
+ opposite = Math.sin(amount * acos) * invSin * Math.sign(dot);
1751
+ }
1752
+ out.x = inverse * start.x + opposite * end.x;
1753
+ out.y = inverse * start.y + opposite * end.y;
1754
+ out.z = inverse * start.z + opposite * end.z;
1755
+ out.w = inverse * start.w + opposite * end.w;
1756
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1757
+ };
1758
+ /**
1759
+ * Scales the specified quaternion magnitude to unit length.
1760
+ * @param a - The specified quaternion
1761
+ * @param out - The normalized quaternion
1762
+ */ Quaternion.normalize = function normalize(a, out) {
1763
+ var _x = a._x, _y = a._y, _z = a._z, _w = a._w;
1764
+ var len = Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
1765
+ if (len > MathUtil.zeroTolerance) {
1766
+ len = 1 / len;
1767
+ out._x = _x * len;
1768
+ out._y = _y * len;
1769
+ out._z = _z * len;
1770
+ out._w = _w * len;
1771
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1772
+ }
1773
+ };
1774
+ /**
1775
+ * Calculate a quaternion rotate around X axis.
1776
+ * @param rad - The rotation angle in radians
1777
+ * @param out - The calculated quaternion
1778
+ */ Quaternion.rotationX = function rotationX(rad, out) {
1779
+ rad *= 0.5;
1780
+ var s = Math.sin(rad);
1781
+ var c = Math.cos(rad);
1782
+ out._x = s;
1783
+ out._y = 0;
1784
+ out._z = 0;
1785
+ out._w = c;
1786
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1787
+ };
1788
+ /**
1789
+ * Calculate a quaternion rotate around Y axis.
1790
+ * @param rad - The rotation angle in radians
1791
+ * @param out - The calculated quaternion
1792
+ */ Quaternion.rotationY = function rotationY(rad, out) {
1793
+ rad *= 0.5;
1794
+ var s = Math.sin(rad);
1795
+ var c = Math.cos(rad);
1796
+ out._x = 0;
1797
+ out._y = s;
1798
+ out._z = 0;
1799
+ out._w = c;
1800
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1801
+ };
1802
+ /**
1803
+ * Calculate a quaternion rotate around Z axis.
1804
+ * @param rad - The rotation angle in radians
1805
+ * @param out - The calculated quaternion
1806
+ */ Quaternion.rotationZ = function rotationZ(rad, out) {
1807
+ rad *= 0.5;
1808
+ var s = Math.sin(rad);
1809
+ var c = Math.cos(rad);
1810
+ out._x = 0;
1811
+ out._y = 0;
1812
+ out._z = s;
1813
+ out._w = c;
1814
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1815
+ };
1816
+ /**
1817
+ * Calculate a quaternion that the specified quaternion rotate around X axis.
1818
+ * @param quaternion - The specified quaternion
1819
+ * @param rad - The rotation angle in radians
1820
+ * @param out - The calculated quaternion
1821
+ */ Quaternion.rotateX = function rotateX(quaternion, rad, out) {
1822
+ var _x = quaternion._x, _y = quaternion._y, _z = quaternion._z, _w = quaternion._w;
1823
+ rad *= 0.5;
1824
+ var bx = Math.sin(rad);
1825
+ var bw = Math.cos(rad);
1826
+ out._x = _x * bw + _w * bx;
1827
+ out._y = _y * bw + _z * bx;
1828
+ out._z = _z * bw - _y * bx;
1829
+ out._w = _w * bw - _x * bx;
1830
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1831
+ };
1832
+ /**
1833
+ * Calculate a quaternion that the specified quaternion rotate around Y axis.
1834
+ * @param quaternion - The specified quaternion
1835
+ * @param rad - The rotation angle in radians
1836
+ * @param out - The calculated quaternion
1837
+ */ Quaternion.rotateY = function rotateY(quaternion, rad, out) {
1838
+ var _x = quaternion._x, _y = quaternion._y, _z = quaternion._z, _w = quaternion._w;
1839
+ rad *= 0.5;
1840
+ var by = Math.sin(rad);
1841
+ var bw = Math.cos(rad);
1842
+ out._x = _x * bw - _z * by;
1843
+ out._y = _y * bw + _w * by;
1844
+ out._z = _z * bw + _x * by;
1845
+ out._w = _w * bw - _y * by;
1846
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1847
+ };
1848
+ /**
1849
+ * Calculate a quaternion that the specified quaternion rotate around Z axis.
1850
+ * @param quaternion - The specified quaternion
1851
+ * @param rad - The rotation angle in radians
1852
+ * @param out - The calculated quaternion
1853
+ */ Quaternion.rotateZ = function rotateZ(quaternion, rad, out) {
1854
+ var _x = quaternion._x, _y = quaternion._y, _z = quaternion._z, _w = quaternion._w;
1855
+ rad *= 0.5;
1856
+ var bz = Math.sin(rad);
1857
+ var bw = Math.cos(rad);
1858
+ out._x = _x * bw + _y * bz;
1859
+ out._y = _y * bw - _x * bz;
1860
+ out._z = _z * bw + _w * bz;
1861
+ out._w = _w * bw - _z * bz;
1862
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1863
+ };
1864
+ /**
1865
+ * Scale a quaternion by a given number.
1866
+ * @param a - The quaternion
1867
+ * @param s - The given number
1868
+ * @param out - The scaled quaternion
1869
+ */ Quaternion.scale = function scale(a, s, out) {
1870
+ out._x = a._x * s;
1871
+ out._y = a._y * s;
1872
+ out._z = a._z * s;
1873
+ out._w = a._w * s;
1874
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
1875
+ };
1876
+ _create_class(Quaternion, [
1877
+ {
1878
+ key: "x",
1879
+ get: /**
1880
+ * The x component of the quaternion.
1881
+ */ function get() {
1882
+ return this._x;
1883
+ },
1884
+ set: function set(value) {
1885
+ this._x = value;
1886
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1887
+ }
1888
+ },
1889
+ {
1890
+ key: "y",
1891
+ get: /**
1892
+ * The y component of the quaternion.
1893
+ */ function get() {
1894
+ return this._y;
1895
+ },
1896
+ set: function set(value) {
1897
+ this._y = value;
1898
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1899
+ }
1900
+ },
1901
+ {
1902
+ key: "z",
1903
+ get: /**
1904
+ * The z component of the quaternion.
1905
+ */ function get() {
1906
+ return this._z;
1907
+ },
1908
+ set: function set(value) {
1909
+ this._z = value;
1910
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1911
+ }
1912
+ },
1913
+ {
1914
+ key: "normalized",
1915
+ get: /**
1916
+ * Indicting whether this instance is normalized.
1917
+ */ function get() {
1918
+ return Math.abs(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w - 1) < MathUtil.zeroTolerance;
1919
+ }
1920
+ },
1921
+ {
1922
+ key: "w",
1923
+ get: /**
1924
+ * The w component of the quaternion.
1925
+ */ function get() {
1926
+ return this._w;
1927
+ },
1928
+ set: function set(value) {
1929
+ this._w = value;
1930
+ this._onValueChanged == null ? void 0 : this._onValueChanged.call(this);
1931
+ }
1932
+ }
1933
+ ]);
1934
+ return Quaternion;
1935
+ }();
1936
+ /** @internal */ Quaternion._tempVector3 = new Vector3();
1937
+ /** @internal */ Quaternion._tempQuat1 = new Quaternion();
1938
+ /**
1939
+ * Represents a 4x4 mathematical matrix.
1940
+ */ var Matrix = /*#__PURE__*/ function() {
1941
+ function Matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
1942
+ if (m11 === void 0) m11 = 1;
1943
+ if (m12 === void 0) m12 = 0;
1944
+ if (m13 === void 0) m13 = 0;
1945
+ if (m14 === void 0) m14 = 0;
1946
+ if (m21 === void 0) m21 = 0;
1947
+ if (m22 === void 0) m22 = 1;
1948
+ if (m23 === void 0) m23 = 0;
1949
+ if (m24 === void 0) m24 = 0;
1950
+ if (m31 === void 0) m31 = 0;
1951
+ if (m32 === void 0) m32 = 0;
1952
+ if (m33 === void 0) m33 = 1;
1953
+ if (m34 === void 0) m34 = 0;
1954
+ if (m41 === void 0) m41 = 0;
1955
+ if (m42 === void 0) m42 = 0;
1956
+ if (m43 === void 0) m43 = 0;
1957
+ if (m44 === void 0) m44 = 1;
1958
+ /**
1959
+ * An array containing the elements of the matrix (column matrix).
1960
+ * @remarks
1961
+ * elements[0] first column and first row value m11
1962
+ * elements[1] first column and second row value m12
1963
+ * elements[2] first column and third row value m13
1964
+ * elements[3] first column and fourth row value m14
1965
+ * elements[4] second column and first row value m21
1966
+ * and so on
1967
+ */ this.elements = new Float32Array(16);
1968
+ var e = this.elements;
1969
+ e[0] = m11;
1970
+ e[1] = m12;
1971
+ e[2] = m13;
1972
+ e[3] = m14;
1973
+ e[4] = m21;
1974
+ e[5] = m22;
1975
+ e[6] = m23;
1976
+ e[7] = m24;
1977
+ e[8] = m31;
1978
+ e[9] = m32;
1979
+ e[10] = m33;
1980
+ e[11] = m34;
1981
+ e[12] = m41;
1982
+ e[13] = m42;
1983
+ e[14] = m43;
1984
+ e[15] = m44;
1985
+ }
1986
+ var _proto = Matrix.prototype;
1987
+ /**
1988
+ * Set the value of this matrix, and return this matrix.
1989
+ * @param m11 - column 1, row 1
1990
+ * @param m12 - column 1, row 2
1991
+ * @param m13 - column 1, row 3
1992
+ * @param m14 - column 1, row 4
1993
+ * @param m21 - column 2, row 1
1994
+ * @param m22 - column 2, row 2
1995
+ * @param m23 - column 2, row 3
1996
+ * @param m24 - column 2, row 4
1997
+ * @param m31 - column 3, row 1
1998
+ * @param m32 - column 3, row 2
1999
+ * @param m33 - column 3, row 3
2000
+ * @param m34 - column 3, row 4
2001
+ * @param m41 - column 4, row 1
2002
+ * @param m42 - column 4, row 2
2003
+ * @param m43 - column 4, row 3
2004
+ * @param m44 - column 4, row 4
2005
+ * @returns This matrix
2006
+ */ _proto.set = function set(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
2007
+ var e = this.elements;
2008
+ e[0] = m11;
2009
+ e[1] = m12;
2010
+ e[2] = m13;
2011
+ e[3] = m14;
2012
+ e[4] = m21;
2013
+ e[5] = m22;
2014
+ e[6] = m23;
2015
+ e[7] = m24;
2016
+ e[8] = m31;
2017
+ e[9] = m32;
2018
+ e[10] = m33;
2019
+ e[11] = m34;
2020
+ e[12] = m41;
2021
+ e[13] = m42;
2022
+ e[14] = m43;
2023
+ e[15] = m44;
2024
+ return this;
2025
+ };
2026
+ /**
2027
+ * Determines the product of this matrix and the specified matrix.
2028
+ * @param right - The specified matrix
2029
+ * @returns This matrix that store the product of the two matrices
2030
+ */ _proto.multiply = function multiply(right) {
2031
+ Matrix.multiply(this, right, this);
2032
+ return this;
2033
+ };
2034
+ /**
2035
+ * Calculate a determinant of this matrix.
2036
+ * @returns The determinant of this matrix
2037
+ */ _proto.determinant = function determinant() {
2038
+ var e = this.elements;
2039
+ var a11 = e[0], a12 = e[1], a13 = e[2], a14 = e[3];
2040
+ var a21 = e[4], a22 = e[5], a23 = e[6], a24 = e[7];
2041
+ var a31 = e[8], a32 = e[9], a33 = e[10], a34 = e[11];
2042
+ var a41 = e[12], a42 = e[13], a43 = e[14], a44 = e[15];
2043
+ var b00 = a11 * a22 - a12 * a21;
2044
+ var b01 = a11 * a23 - a13 * a21;
2045
+ var b02 = a11 * a24 - a14 * a21;
2046
+ var b03 = a12 * a23 - a13 * a22;
2047
+ var b04 = a12 * a24 - a14 * a22;
2048
+ var b05 = a13 * a24 - a14 * a23;
2049
+ var b06 = a31 * a42 - a32 * a41;
2050
+ var b07 = a31 * a43 - a33 * a41;
2051
+ var b08 = a31 * a44 - a34 * a41;
2052
+ var b09 = a32 * a43 - a33 * a42;
2053
+ var b10 = a32 * a44 - a34 * a42;
2054
+ var b11 = a33 * a44 - a34 * a43;
2055
+ // Calculate the determinant
2056
+ return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
2057
+ };
2058
+ /**
2059
+ * Decompose this matrix to translation, rotation and scale elements.
2060
+ * @param translation - Translation vector as an output parameter
2061
+ * @param rotation - Rotation quaternion as an output parameter
2062
+ * @param scale - Scale vector as an output parameter
2063
+ * @returns True if this matrix can be decomposed, false otherwise
2064
+ */ _proto.decompose = function decompose(translation, rotation, scale) {
2065
+ var rm = Matrix._tempMat30;
2066
+ var e = this.elements;
2067
+ var rme = rm.elements;
2068
+ var m11 = e[0];
2069
+ var m12 = e[1];
2070
+ var m13 = e[2];
2071
+ var m21 = e[4];
2072
+ var m22 = e[5];
2073
+ var m23 = e[6];
2074
+ var m31 = e[8];
2075
+ var m32 = e[9];
2076
+ var m33 = e[10];
2077
+ translation.set(e[12], e[13], e[14]);
2078
+ var sx = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
2079
+ var sy = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
2080
+ var sz = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
2081
+ if (this.determinant() < 0) sx = -sx;
2082
+ scale.set(sx, sy, sz);
2083
+ if (Math.abs(sx) < MathUtil.zeroTolerance || Math.abs(sy) < MathUtil.zeroTolerance || Math.abs(sz) < MathUtil.zeroTolerance) {
2084
+ rotation.identity();
2085
+ return false;
2086
+ } else {
2087
+ var invSX = 1 / sx;
2088
+ var invSY = 1 / sy;
2089
+ var invSZ = 1 / sz;
2090
+ rme[0] = m11 * invSX;
2091
+ rme[1] = m12 * invSX;
2092
+ rme[2] = m13 * invSX;
2093
+ rme[3] = m21 * invSY;
2094
+ rme[4] = m22 * invSY;
2095
+ rme[5] = m23 * invSY;
2096
+ rme[6] = m31 * invSZ;
2097
+ rme[7] = m32 * invSZ;
2098
+ rme[8] = m33 * invSZ;
2099
+ Quaternion.rotationMatrix3x3(rm, rotation);
2100
+ return true;
2101
+ }
2102
+ };
2103
+ /**
2104
+ * Get rotation from this matrix.
2105
+ * @param out - Rotation quaternion as an output parameter
2106
+ * @returns The out
2107
+ */ _proto.getRotation = function getRotation(out) {
2108
+ var e = this.elements;
2109
+ var trace = e[0] + e[5] + e[10];
2110
+ if (trace > MathUtil.zeroTolerance) {
2111
+ var s = Math.sqrt(trace + 1.0) * 2;
2112
+ out._w = 0.25 * s;
2113
+ out._x = (e[6] - e[9]) / s;
2114
+ out._y = (e[8] - e[2]) / s;
2115
+ out._z = (e[1] - e[4]) / s;
2116
+ } else if (e[0] > e[5] && e[0] > e[10]) {
2117
+ var s1 = Math.sqrt(1.0 + e[0] - e[5] - e[10]) * 2;
2118
+ out._w = (e[6] - e[9]) / s1;
2119
+ out._x = 0.25 * s1;
2120
+ out._y = (e[1] + e[4]) / s1;
2121
+ out._z = (e[8] + e[2]) / s1;
2122
+ } else if (e[5] > e[10]) {
2123
+ var s2 = Math.sqrt(1.0 + e[5] - e[0] - e[10]) * 2;
2124
+ out._w = (e[8] - e[2]) / s2;
2125
+ out._x = (e[1] + e[4]) / s2;
2126
+ out._y = 0.25 * s2;
2127
+ out._z = (e[6] + e[9]) / s2;
2128
+ } else {
2129
+ var s3 = Math.sqrt(1.0 + e[10] - e[0] - e[5]) * 2;
2130
+ out._w = (e[1] - e[4]) / s3;
2131
+ out._x = (e[8] + e[2]) / s3;
2132
+ out._y = (e[6] + e[9]) / s3;
2133
+ out._z = 0.25 * s3;
2134
+ }
2135
+ out._onValueChanged == null ? void 0 : out._onValueChanged.call(out);
2136
+ return out;
2137
+ };
2138
+ /**
2139
+ * Get scale from this matrix.
2140
+ * @param out - Scale vector as an output parameter
2141
+ * @returns The out
2142
+ */ _proto.getScaling = function getScaling(out) {
2143
+ //getScale()
2144
+ var e = this.elements;
2145
+ var m11 = e[0], m12 = e[1], m13 = e[2];
2146
+ var m21 = e[4], m22 = e[5], m23 = e[6];
2147
+ var m31 = e[8], m32 = e[9], m33 = e[10];
2148
+ 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));
2149
+ return out;
2150
+ };
2151
+ /**
2152
+ * Get translation from this matrix.
2153
+ * @param out - Translation vector as an output parameter
2154
+ * @returns The out
2155
+ */ _proto.getTranslation = function getTranslation(out) {
2156
+ var e = this.elements;
2157
+ out.set(e[12], e[13], e[14]);
2158
+ return out;
2159
+ };
2160
+ /**
2161
+ * Identity this matrix.
2162
+ * @returns This matrix after identity
2163
+ */ _proto.identity = function identity() {
2164
+ var e = this.elements;
2165
+ e[0] = 1;
2166
+ e[1] = 0;
2167
+ e[2] = 0;
2168
+ e[3] = 0;
2169
+ e[4] = 0;
2170
+ e[5] = 1;
2171
+ e[6] = 0;
2172
+ e[7] = 0;
2173
+ e[8] = 0;
2174
+ e[9] = 0;
2175
+ e[10] = 1;
2176
+ e[11] = 0;
2177
+ e[12] = 0;
2178
+ e[13] = 0;
2179
+ e[14] = 0;
2180
+ e[15] = 1;
2181
+ return this;
2182
+ };
2183
+ /**
2184
+ * Invert the matrix.
2185
+ * @returns The matrix after invert
2186
+ */ _proto.invert = function invert() {
2187
+ Matrix.invert(this, this);
2188
+ return this;
2189
+ };
2190
+ /**
2191
+ * This matrix rotates around an arbitrary axis.
2192
+ * @param axis - The axis
2193
+ * @param r - The rotation angle in radians
2194
+ * @returns This matrix after rotate
2195
+ */ _proto.rotateAxisAngle = function rotateAxisAngle(axis, r) {
2196
+ Matrix.rotateAxisAngle(this, axis, r, this);
2197
+ return this;
2198
+ };
2199
+ /**
2200
+ * Scale this matrix by a given vector.
2201
+ * @param s - The given vector
2202
+ * @returns This matrix after scale
2203
+ */ _proto.scale = function scale(s) {
2204
+ Matrix.scale(this, s, this);
2205
+ return this;
2206
+ };
2207
+ /**
2208
+ * Translate this matrix by a given vector.
2209
+ * @param v - The given vector
2210
+ * @returns This matrix after translate
2211
+ */ _proto.translate = function translate(v) {
2212
+ Matrix.translate(this, v, this);
2213
+ return this;
2214
+ };
2215
+ /**
2216
+ * Calculate the transpose of this matrix.
2217
+ * @returns This matrix after transpose
2218
+ */ _proto.transpose = function transpose() {
2219
+ Matrix.transpose(this, this);
2220
+ return this;
2221
+ };
2222
+ /**
2223
+ * Creates a clone of this matrix.
2224
+ * @returns A clone of this matrix
2225
+ */ _proto.clone = function clone() {
2226
+ var e = this.elements;
2227
+ 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]);
2228
+ return ret;
2229
+ };
2230
+ /**
2231
+ * Copy this matrix from the specified matrix.
2232
+ * @param source - The specified matrix
2233
+ * @returns This matrix
2234
+ */ _proto.copyFrom = function copyFrom(source) {
2235
+ var e = this.elements;
2236
+ var se = source.elements;
2237
+ e[0] = se[0];
2238
+ e[1] = se[1];
2239
+ e[2] = se[2];
2240
+ e[3] = se[3];
2241
+ e[4] = se[4];
2242
+ e[5] = se[5];
2243
+ e[6] = se[6];
2244
+ e[7] = se[7];
2245
+ e[8] = se[8];
2246
+ e[9] = se[9];
2247
+ e[10] = se[10];
2248
+ e[11] = se[11];
2249
+ e[12] = se[12];
2250
+ e[13] = se[13];
2251
+ e[14] = se[14];
2252
+ e[15] = se[15];
2253
+ return this;
2254
+ };
2255
+ /**
2256
+ * Copy the value of this matrix from an array.
2257
+ * @param array - The array
2258
+ * @param offset - The start offset of the array
2259
+ * @returns This matrix
2260
+ */ _proto.copyFromArray = function copyFromArray(array, offset) {
2261
+ if (offset === void 0) offset = 0;
2262
+ var srce = this.elements;
2263
+ for(var i = 0; i < 16; i++){
2264
+ srce[i] = array[i + offset];
2265
+ }
2266
+ return this;
2267
+ };
2268
+ /**
2269
+ * Copy the value of this matrix to an array.
2270
+ * @param out - The array
2271
+ * @param outOffset - The start offset of the array
2272
+ */ _proto.copyToArray = function copyToArray(out, outOffset) {
2273
+ if (outOffset === void 0) outOffset = 0;
2274
+ var e = this.elements;
2275
+ out[outOffset] = e[0];
2276
+ out[outOffset + 1] = e[1];
2277
+ out[outOffset + 2] = e[2];
2278
+ out[outOffset + 3] = e[3];
2279
+ out[outOffset + 4] = e[4];
2280
+ out[outOffset + 5] = e[5];
2281
+ out[outOffset + 6] = e[6];
2282
+ out[outOffset + 7] = e[7];
2283
+ out[outOffset + 8] = e[8];
2284
+ out[outOffset + 9] = e[9];
2285
+ out[outOffset + 10] = e[10];
2286
+ out[outOffset + 11] = e[11];
2287
+ out[outOffset + 12] = e[12];
2288
+ out[outOffset + 13] = e[13];
2289
+ out[outOffset + 14] = e[14];
2290
+ out[outOffset + 15] = e[15];
2291
+ };
2292
+ /**
2293
+ * Determines the product of two matrices.
2294
+ * @param left - The first matrix to multiply
2295
+ * @param right - The second matrix to multiply
2296
+ * @param out - The product of the two matrices
2297
+ */ Matrix.multiply = function multiply(left, right, out) {
2298
+ var le = left.elements;
2299
+ var re = right.elements;
2300
+ var oe = out.elements;
2301
+ // prettier-ignore
2302
+ 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];
2303
+ // prettier-ignore
2304
+ 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];
2305
+ oe[0] = l11 * r11 + l21 * r12 + l31 * r13 + l41 * r14;
2306
+ oe[1] = l12 * r11 + l22 * r12 + l32 * r13 + l42 * r14;
2307
+ oe[2] = l13 * r11 + l23 * r12 + l33 * r13 + l43 * r14;
2308
+ oe[3] = l14 * r11 + l24 * r12 + l34 * r13 + l44 * r14;
2309
+ oe[4] = l11 * r21 + l21 * r22 + l31 * r23 + l41 * r24;
2310
+ oe[5] = l12 * r21 + l22 * r22 + l32 * r23 + l42 * r24;
2311
+ oe[6] = l13 * r21 + l23 * r22 + l33 * r23 + l43 * r24;
2312
+ oe[7] = l14 * r21 + l24 * r22 + l34 * r23 + l44 * r24;
2313
+ oe[8] = l11 * r31 + l21 * r32 + l31 * r33 + l41 * r34;
2314
+ oe[9] = l12 * r31 + l22 * r32 + l32 * r33 + l42 * r34;
2315
+ oe[10] = l13 * r31 + l23 * r32 + l33 * r33 + l43 * r34;
2316
+ oe[11] = l14 * r31 + l24 * r32 + l34 * r33 + l44 * r34;
2317
+ oe[12] = l11 * r41 + l21 * r42 + l31 * r43 + l41 * r44;
2318
+ oe[13] = l12 * r41 + l22 * r42 + l32 * r43 + l42 * r44;
2319
+ oe[14] = l13 * r41 + l23 * r42 + l33 * r43 + l43 * r44;
2320
+ oe[15] = l14 * r41 + l24 * r42 + l34 * r43 + l44 * r44;
2321
+ };
2322
+ /**
2323
+ * Determines whether the specified matrices are equals.
2324
+ * @param left - The first matrix to compare
2325
+ * @param right - The second matrix to compare
2326
+ * @returns True if the specified matrices are equals, false otherwise
2327
+ */ Matrix.equals = function equals(left, right) {
2328
+ var le = left.elements;
2329
+ var re = right.elements;
2330
+ 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]);
2331
+ };
2332
+ /**
2333
+ * Performs a linear interpolation between two matrices.
2334
+ * @param start - The first matrix
2335
+ * @param end - The second matrix
2336
+ * @param t - The blend amount where 0 returns start and 1 end
2337
+ * @param out - The result of linear blending between two matrices
2338
+ */ Matrix.lerp = function lerp(start, end, t, out) {
2339
+ var se = start.elements;
2340
+ var ee = end.elements;
2341
+ var oe = out.elements;
2342
+ var inv = 1.0 - t;
2343
+ oe[0] = se[0] * inv + ee[0] * t;
2344
+ oe[1] = se[1] * inv + ee[1] * t;
2345
+ oe[2] = se[2] * inv + ee[2] * t;
2346
+ oe[3] = se[3] * inv + ee[3] * t;
2347
+ oe[4] = se[4] * inv + ee[4] * t;
2348
+ oe[5] = se[5] * inv + ee[5] * t;
2349
+ oe[6] = se[6] * inv + ee[6] * t;
2350
+ oe[7] = se[7] * inv + ee[7] * t;
2351
+ oe[8] = se[8] * inv + ee[8] * t;
2352
+ oe[9] = se[9] * inv + ee[9] * t;
2353
+ oe[10] = se[10] * inv + ee[10] * t;
2354
+ oe[11] = se[11] * inv + ee[11] * t;
2355
+ oe[12] = se[12] * inv + ee[12] * t;
2356
+ oe[13] = se[13] * inv + ee[13] * t;
2357
+ oe[14] = se[14] * inv + ee[14] * t;
2358
+ oe[15] = se[15] * inv + ee[15] * t;
2359
+ };
2360
+ /**
2361
+ * Determines the sum of two matrices.
2362
+ * @param left - The first matrix to add
2363
+ * @param right - The second matrix to add
2364
+ * @param out - The sum of two matrices
2365
+ */ Matrix.add = function add(left, right, out) {
2366
+ var le = left.elements;
2367
+ var re = right.elements;
2368
+ var oe = out.elements;
2369
+ oe[0] = le[0] + re[0];
2370
+ oe[1] = le[1] + re[1];
2371
+ oe[2] = le[2] + re[2];
2372
+ oe[3] = le[3] + re[3];
2373
+ oe[4] = le[4] + re[4];
2374
+ oe[5] = le[5] + re[5];
2375
+ oe[6] = le[6] + re[6];
2376
+ oe[7] = le[7] + re[7];
2377
+ oe[8] = le[8] + re[8];
2378
+ oe[9] = le[9] + re[9];
2379
+ oe[10] = le[10] + re[10];
2380
+ oe[11] = le[11] + re[11];
2381
+ oe[12] = le[12] + re[12];
2382
+ oe[13] = le[13] + re[13];
2383
+ oe[14] = le[14] + re[14];
2384
+ oe[15] = le[15] + re[15];
2385
+ };
2386
+ /**
2387
+ * Multiplies a matrix by a scalar.
2388
+ * @param source - The matrix to multiply
2389
+ * @param scalar - The scalar to multiply
2390
+ * @param out - The result of multiplying a matrix by a scalar
2391
+ */ Matrix.multiplyScalar = function multiplyScalar(source, scalar, out) {
2392
+ var se = source.elements;
2393
+ var oe = out.elements;
2394
+ oe[0] = se[0] * scalar;
2395
+ oe[1] = se[1] * scalar;
2396
+ oe[2] = se[2] * scalar;
2397
+ oe[3] = se[3] * scalar;
2398
+ oe[4] = se[4] * scalar;
2399
+ oe[5] = se[5] * scalar;
2400
+ oe[6] = se[6] * scalar;
2401
+ oe[7] = se[7] * scalar;
2402
+ oe[8] = se[8] * scalar;
2403
+ oe[9] = se[9] * scalar;
2404
+ oe[10] = se[10] * scalar;
2405
+ oe[11] = se[11] * scalar;
2406
+ oe[12] = se[12] * scalar;
2407
+ oe[13] = se[13] * scalar;
2408
+ oe[14] = se[14] * scalar;
2409
+ oe[15] = se[15] * scalar;
2410
+ };
2411
+ /**
2412
+ * Calculate a rotation matrix from a quaternion.
2413
+ * @param quaternion - The quaternion used to calculate the matrix
2414
+ * @param out - The calculated rotation matrix
2415
+ */ Matrix.rotationQuaternion = function rotationQuaternion(quaternion, out) {
2416
+ var oe = out.elements;
2417
+ var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
2418
+ var x2 = x + x;
2419
+ var y2 = y + y;
2420
+ var z2 = z + z;
2421
+ var xx = x * x2;
2422
+ var yx = y * x2;
2423
+ var yy = y * y2;
2424
+ var zx = z * x2;
2425
+ var zy = z * y2;
2426
+ var zz = z * z2;
2427
+ var wx = w * x2;
2428
+ var wy = w * y2;
2429
+ var wz = w * z2;
2430
+ oe[0] = 1 - yy - zz;
2431
+ oe[1] = yx + wz;
2432
+ oe[2] = zx - wy;
2433
+ oe[3] = 0;
2434
+ oe[4] = yx - wz;
2435
+ oe[5] = 1 - xx - zz;
2436
+ oe[6] = zy + wx;
2437
+ oe[7] = 0;
2438
+ oe[8] = zx + wy;
2439
+ oe[9] = zy - wx;
2440
+ oe[10] = 1 - xx - yy;
2441
+ oe[11] = 0;
2442
+ oe[12] = 0;
2443
+ oe[13] = 0;
2444
+ oe[14] = 0;
2445
+ oe[15] = 1;
2446
+ };
2447
+ /**
2448
+ * Calculate a matrix rotates around an arbitrary axis.
2449
+ * @param axis - The axis
2450
+ * @param r - The rotation angle in radians
2451
+ * @param out - The matrix after rotate
2452
+ */ Matrix.rotationAxisAngle = function rotationAxisAngle(axis, r, out) {
2453
+ var oe = out.elements;
2454
+ var x = axis._x, y = axis._y, z = axis._z;
2455
+ var len = Math.sqrt(x * x + y * y + z * z);
2456
+ var s, c, t;
2457
+ if (Math.abs(len) < MathUtil.zeroTolerance) {
2458
+ return;
2459
+ }
2460
+ len = 1 / len;
2461
+ x *= len;
2462
+ y *= len;
2463
+ z *= len;
2464
+ s = Math.sin(r);
2465
+ c = Math.cos(r);
2466
+ t = 1 - c;
2467
+ // Perform rotation-specific matrix multiplication
2468
+ oe[0] = x * x * t + c;
2469
+ oe[1] = y * x * t + z * s;
2470
+ oe[2] = z * x * t - y * s;
2471
+ oe[3] = 0;
2472
+ oe[4] = x * y * t - z * s;
2473
+ oe[5] = y * y * t + c;
2474
+ oe[6] = z * y * t + x * s;
2475
+ oe[7] = 0;
2476
+ oe[8] = x * z * t + y * s;
2477
+ oe[9] = y * z * t - x * s;
2478
+ oe[10] = z * z * t + c;
2479
+ oe[11] = 0;
2480
+ oe[12] = 0;
2481
+ oe[13] = 0;
2482
+ oe[14] = 0;
2483
+ oe[15] = 1;
2484
+ };
2485
+ /**
2486
+ * Calculate a matrix from a quaternion and a translation.
2487
+ * @param quaternion - The quaternion used to calculate the matrix
2488
+ * @param translation - The translation used to calculate the matrix
2489
+ * @param out - The calculated matrix
2490
+ */ Matrix.rotationTranslation = function rotationTranslation(quaternion, translation, out) {
2491
+ Matrix.rotationQuaternion(quaternion, out);
2492
+ var oe = out.elements;
2493
+ oe[12] = translation._x;
2494
+ oe[13] = translation._y;
2495
+ oe[14] = translation._z;
2496
+ };
2497
+ /**
2498
+ * Calculate an affine matrix.
2499
+ * @param scale - The scale used to calculate matrix
2500
+ * @param rotation - The rotation used to calculate matrix
2501
+ * @param translation - The translation used to calculate matrix
2502
+ * @param out - The calculated matrix
2503
+ */ Matrix.affineTransformation = function affineTransformation(scale, rotation, translation, out) {
2504
+ var oe = out.elements;
2505
+ var x = rotation._x, y = rotation._y, z = rotation._z, w = rotation._w;
2506
+ var x2 = x + x;
2507
+ var y2 = y + y;
2508
+ var z2 = z + z;
2509
+ var xx = x * x2;
2510
+ var xy = x * y2;
2511
+ var xz = x * z2;
2512
+ var yy = y * y2;
2513
+ var yz = y * z2;
2514
+ var zz = z * z2;
2515
+ var wx = w * x2;
2516
+ var wy = w * y2;
2517
+ var wz = w * z2;
2518
+ var sx = scale._x;
2519
+ var sy = scale._y;
2520
+ var sz = scale._z;
2521
+ oe[0] = (1 - (yy + zz)) * sx;
2522
+ oe[1] = (xy + wz) * sx;
2523
+ oe[2] = (xz - wy) * sx;
2524
+ oe[3] = 0;
2525
+ oe[4] = (xy - wz) * sy;
2526
+ oe[5] = (1 - (xx + zz)) * sy;
2527
+ oe[6] = (yz + wx) * sy;
2528
+ oe[7] = 0;
2529
+ oe[8] = (xz + wy) * sz;
2530
+ oe[9] = (yz - wx) * sz;
2531
+ oe[10] = (1 - (xx + yy)) * sz;
2532
+ oe[11] = 0;
2533
+ oe[12] = translation._x;
2534
+ oe[13] = translation._y;
2535
+ oe[14] = translation._z;
2536
+ oe[15] = 1;
2537
+ };
2538
+ /**
2539
+ * Calculate a matrix from scale vector.
2540
+ * @param s - The scale vector
2541
+ * @param out - The calculated matrix
2542
+ */ Matrix.scaling = function scaling(s, out) {
2543
+ var oe = out.elements;
2544
+ oe[0] = s._x;
2545
+ oe[1] = 0;
2546
+ oe[2] = 0;
2547
+ oe[3] = 0;
2548
+ oe[4] = 0;
2549
+ oe[5] = s._y;
2550
+ oe[6] = 0;
2551
+ oe[7] = 0;
2552
+ oe[8] = 0;
2553
+ oe[9] = 0;
2554
+ oe[10] = s._z;
2555
+ oe[11] = 0;
2556
+ oe[12] = 0;
2557
+ oe[13] = 0;
2558
+ oe[14] = 0;
2559
+ oe[15] = 1;
2560
+ };
2561
+ /**
2562
+ * Calculate a matrix from translation vector.
2563
+ * @param translation - The translation vector
2564
+ * @param out - The calculated matrix
2565
+ */ Matrix.translation = function translation(translation, out) {
2566
+ var oe = out.elements;
2567
+ oe[0] = 1;
2568
+ oe[1] = 0;
2569
+ oe[2] = 0;
2570
+ oe[3] = 0;
2571
+ oe[4] = 0;
2572
+ oe[5] = 1;
2573
+ oe[6] = 0;
2574
+ oe[7] = 0;
2575
+ oe[8] = 0;
2576
+ oe[9] = 0;
2577
+ oe[10] = 1;
2578
+ oe[11] = 0;
2579
+ oe[12] = translation._x;
2580
+ oe[13] = translation._y;
2581
+ oe[14] = translation._z;
2582
+ oe[15] = 1;
2583
+ };
2584
+ /**
2585
+ * Calculate the inverse of the specified matrix.
2586
+ * @param a - The matrix whose inverse is to be calculated
2587
+ * @param out - The inverse of the specified matrix
2588
+ */ Matrix.invert = function invert(a, out) {
2589
+ var ae = a.elements;
2590
+ var oe = out.elements;
2591
+ var a11 = ae[0], a12 = ae[1], a13 = ae[2], a14 = ae[3];
2592
+ var a21 = ae[4], a22 = ae[5], a23 = ae[6], a24 = ae[7];
2593
+ var a31 = ae[8], a32 = ae[9], a33 = ae[10], a34 = ae[11];
2594
+ var a41 = ae[12], a42 = ae[13], a43 = ae[14], a44 = ae[15];
2595
+ var b00 = a11 * a22 - a12 * a21;
2596
+ var b01 = a11 * a23 - a13 * a21;
2597
+ var b02 = a11 * a24 - a14 * a21;
2598
+ var b03 = a12 * a23 - a13 * a22;
2599
+ var b04 = a12 * a24 - a14 * a22;
2600
+ var b05 = a13 * a24 - a14 * a23;
2601
+ var b06 = a31 * a42 - a32 * a41;
2602
+ var b07 = a31 * a43 - a33 * a41;
2603
+ var b08 = a31 * a44 - a34 * a41;
2604
+ var b09 = a32 * a43 - a33 * a42;
2605
+ var b10 = a32 * a44 - a34 * a42;
2606
+ var b11 = a33 * a44 - a34 * a43;
2607
+ var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
2608
+ if (!det) {
2609
+ return null;
2610
+ }
2611
+ det = 1.0 / det;
2612
+ oe[0] = (a22 * b11 - a23 * b10 + a24 * b09) * det;
2613
+ oe[1] = (a13 * b10 - a12 * b11 - a14 * b09) * det;
2614
+ oe[2] = (a42 * b05 - a43 * b04 + a44 * b03) * det;
2615
+ oe[3] = (a33 * b04 - a32 * b05 - a34 * b03) * det;
2616
+ oe[4] = (a23 * b08 - a21 * b11 - a24 * b07) * det;
2617
+ oe[5] = (a11 * b11 - a13 * b08 + a14 * b07) * det;
2618
+ oe[6] = (a43 * b02 - a41 * b05 - a44 * b01) * det;
2619
+ oe[7] = (a31 * b05 - a33 * b02 + a34 * b01) * det;
2620
+ oe[8] = (a21 * b10 - a22 * b08 + a24 * b06) * det;
2621
+ oe[9] = (a12 * b08 - a11 * b10 - a14 * b06) * det;
2622
+ oe[10] = (a41 * b04 - a42 * b02 + a44 * b00) * det;
2623
+ oe[11] = (a32 * b02 - a31 * b04 - a34 * b00) * det;
2624
+ oe[12] = (a22 * b07 - a21 * b09 - a23 * b06) * det;
2625
+ oe[13] = (a11 * b09 - a12 * b07 + a13 * b06) * det;
2626
+ oe[14] = (a42 * b01 - a41 * b03 - a43 * b00) * det;
2627
+ oe[15] = (a31 * b03 - a32 * b01 + a33 * b00) * det;
2628
+ };
2629
+ /**
2630
+ * Calculate a right-handed look-at matrix.
2631
+ * @param eye - The position of the viewer's eye
2632
+ * @param target - The camera look-at target
2633
+ * @param up - The camera's up vector
2634
+ * @param out - The calculated look-at matrix
2635
+ */ Matrix.lookAt = function lookAt(eye, target, up, out) {
2636
+ var oe = out.elements;
2637
+ var xAxis = Matrix._tempVec30;
2638
+ var yAxis = Matrix._tempVec31;
2639
+ var zAxis = Matrix._tempVec32;
2640
+ Vector3.subtract(eye, target, zAxis);
2641
+ zAxis.normalize();
2642
+ Vector3.cross(up, zAxis, xAxis);
2643
+ xAxis.normalize();
2644
+ Vector3.cross(zAxis, xAxis, yAxis);
2645
+ oe[0] = xAxis._x;
2646
+ oe[1] = yAxis._x;
2647
+ oe[2] = zAxis._x;
2648
+ oe[3] = 0;
2649
+ oe[4] = xAxis._y;
2650
+ oe[5] = yAxis._y;
2651
+ oe[6] = zAxis._y;
2652
+ oe[7] = 0;
2653
+ oe[8] = xAxis._z;
2654
+ oe[9] = yAxis._z;
2655
+ oe[10] = zAxis._z;
2656
+ oe[11] = 0;
2657
+ oe[12] = -Vector3.dot(xAxis, eye);
2658
+ oe[13] = -Vector3.dot(yAxis, eye);
2659
+ oe[14] = -Vector3.dot(zAxis, eye);
2660
+ oe[15] = 1;
2661
+ };
2662
+ /**
2663
+ * Calculate an orthographic projection matrix.
2664
+ * @param left - The left edge of the viewing
2665
+ * @param right - The right edge of the viewing
2666
+ * @param bottom - The bottom edge of the viewing
2667
+ * @param top - The top edge of the viewing
2668
+ * @param near - The depth of the near plane
2669
+ * @param far - The depth of the far plane
2670
+ * @param out - The calculated orthographic projection matrix
2671
+ */ Matrix.ortho = function ortho(left, right, bottom, top, near, far, out) {
2672
+ var oe = out.elements;
2673
+ var lr = 1 / (left - right);
2674
+ var bt = 1 / (bottom - top);
2675
+ var nf = 1 / (near - far);
2676
+ oe[0] = -2 * lr;
2677
+ oe[1] = 0;
2678
+ oe[2] = 0;
2679
+ oe[3] = 0;
2680
+ oe[4] = 0;
2681
+ oe[5] = -2 * bt;
2682
+ oe[6] = 0;
2683
+ oe[7] = 0;
2684
+ oe[8] = 0;
2685
+ oe[9] = 0;
2686
+ oe[10] = 2 * nf;
2687
+ oe[11] = 0;
2688
+ oe[12] = (left + right) * lr;
2689
+ oe[13] = (top + bottom) * bt;
2690
+ oe[14] = (far + near) * nf;
2691
+ oe[15] = 1;
2692
+ };
2693
+ /**
2694
+ * Calculate a perspective projection matrix.
2695
+ * @param fovY - Field of view in the y direction, in radians
2696
+ * @param aspect - Aspect ratio, defined as view space width divided by height
2697
+ * @param near - The depth of the near plane
2698
+ * @param far - The depth of the far plane
2699
+ * @param out - The calculated perspective projection matrix
2700
+ */ Matrix.perspective = function perspective(fovY, aspect, near, far, out) {
2701
+ var oe = out.elements;
2702
+ var f = 1.0 / Math.tan(fovY / 2);
2703
+ var nf = 1 / (near - far);
2704
+ oe[0] = f / aspect;
2705
+ oe[1] = 0;
2706
+ oe[2] = 0;
2707
+ oe[3] = 0;
2708
+ oe[4] = 0;
2709
+ oe[5] = f;
2710
+ oe[6] = 0;
2711
+ oe[7] = 0;
2712
+ oe[8] = 0;
2713
+ oe[9] = 0;
2714
+ oe[10] = (far + near) * nf;
2715
+ oe[11] = -1;
2716
+ oe[12] = 0;
2717
+ oe[13] = 0;
2718
+ oe[14] = 2 * far * near * nf;
2719
+ oe[15] = 0;
2720
+ };
2721
+ /**
2722
+ * The specified matrix rotates around an arbitrary axis.
2723
+ * @param m - The specified matrix
2724
+ * @param axis - The axis
2725
+ * @param r - The rotation angle in radians
2726
+ * @param out - The rotated matrix
2727
+ */ Matrix.rotateAxisAngle = function rotateAxisAngle(m, axis, r, out) {
2728
+ var x = axis._x, y = axis._y, z = axis._z;
2729
+ var len = Math.sqrt(x * x + y * y + z * z);
2730
+ if (Math.abs(len) < MathUtil.zeroTolerance) {
2731
+ return;
2732
+ }
2733
+ var me = m.elements;
2734
+ var oe = out.elements;
2735
+ var s, c, t;
2736
+ len = 1 / len;
2737
+ x *= len;
2738
+ y *= len;
2739
+ z *= len;
2740
+ s = Math.sin(r);
2741
+ c = Math.cos(r);
2742
+ t = 1 - c;
2743
+ var a11 = me[0], a12 = me[1], a13 = me[2], a14 = me[3];
2744
+ var a21 = me[4], a22 = me[5], a23 = me[6], a24 = me[7];
2745
+ var a31 = me[8], a32 = me[9], a33 = me[10], a34 = me[11];
2746
+ // Construct the elements of the rotation matrix
2747
+ var b11 = x * x * t + c;
2748
+ var b12 = y * x * t + z * s;
2749
+ var b13 = z * x * t - y * s;
2750
+ var b21 = x * y * t - z * s;
2751
+ var b22 = y * y * t + c;
2752
+ var b23 = z * y * t + x * s;
2753
+ var b31 = x * z * t + y * s;
2754
+ var b32 = y * z * t - x * s;
2755
+ var b33 = z * z * t + c;
2756
+ // Perform rotation-specific matrix multiplication
2757
+ oe[0] = a11 * b11 + a21 * b12 + a31 * b13;
2758
+ oe[1] = a12 * b11 + a22 * b12 + a32 * b13;
2759
+ oe[2] = a13 * b11 + a23 * b12 + a33 * b13;
2760
+ oe[3] = a14 * b11 + a24 * b12 + a34 * b13;
2761
+ oe[4] = a11 * b21 + a21 * b22 + a31 * b23;
2762
+ oe[5] = a12 * b21 + a22 * b22 + a32 * b23;
2763
+ oe[6] = a13 * b21 + a23 * b22 + a33 * b23;
2764
+ oe[7] = a14 * b21 + a24 * b22 + a34 * b23;
2765
+ oe[8] = a11 * b31 + a21 * b32 + a31 * b33;
2766
+ oe[9] = a12 * b31 + a22 * b32 + a32 * b33;
2767
+ oe[10] = a13 * b31 + a23 * b32 + a33 * b33;
2768
+ oe[11] = a14 * b31 + a24 * b32 + a34 * b33;
2769
+ if (m !== out) {
2770
+ // If the source and destination differ, copy the unchanged last row
2771
+ oe[12] = me[12];
2772
+ oe[13] = me[13];
2773
+ oe[14] = me[14];
2774
+ oe[15] = me[15];
2775
+ }
2776
+ };
2777
+ /**
2778
+ * Scale a matrix by a given vector.
2779
+ * @param m - The matrix
2780
+ * @param s - The given vector
2781
+ * @param out - The scaled matrix
2782
+ */ Matrix.scale = function scale(m, s, out) {
2783
+ var me = m.elements;
2784
+ var oe = out.elements;
2785
+ var x = s._x, y = s._y, z = s._z;
2786
+ oe[0] = me[0] * x;
2787
+ oe[1] = me[1] * x;
2788
+ oe[2] = me[2] * x;
2789
+ oe[3] = me[3] * x;
2790
+ oe[4] = me[4] * y;
2791
+ oe[5] = me[5] * y;
2792
+ oe[6] = me[6] * y;
2793
+ oe[7] = me[7] * y;
2794
+ oe[8] = me[8] * z;
2795
+ oe[9] = me[9] * z;
2796
+ oe[10] = me[10] * z;
2797
+ oe[11] = me[11] * z;
2798
+ oe[12] = me[12];
2799
+ oe[13] = me[13];
2800
+ oe[14] = me[14];
2801
+ oe[15] = me[15];
2802
+ };
2803
+ /**
2804
+ * Translate a matrix by a given vector.
2805
+ * @param m - The matrix
2806
+ * @param v - The given vector
2807
+ * @param out - The translated matrix
2808
+ */ Matrix.translate = function translate(m, v, out) {
2809
+ var me = m.elements;
2810
+ var oe = out.elements;
2811
+ var x = v._x, y = v._y, z = v._z;
2812
+ if (m === out) {
2813
+ oe[12] = me[0] * x + me[4] * y + me[8] * z + me[12];
2814
+ oe[13] = me[1] * x + me[5] * y + me[9] * z + me[13];
2815
+ oe[14] = me[2] * x + me[6] * y + me[10] * z + me[14];
2816
+ oe[15] = me[3] * x + me[7] * y + me[11] * z + me[15];
2817
+ } else {
2818
+ var a11 = me[0], a12 = me[1], a13 = me[2], a14 = me[3];
2819
+ var a21 = me[4], a22 = me[5], a23 = me[6], a24 = me[7];
2820
+ var a31 = me[8], a32 = me[9], a33 = me[10], a34 = me[11];
2821
+ oe[0] = a11, oe[1] = a12, oe[2] = a13, oe[3] = a14;
2822
+ oe[4] = a21, oe[5] = a22, oe[6] = a23, oe[7] = a24;
2823
+ oe[8] = a31, oe[9] = a32, oe[10] = a33, oe[11] = a34;
2824
+ oe[12] = a11 * x + a21 * y + a31 * z + me[12];
2825
+ oe[13] = a12 * x + a22 * y + a32 * z + me[13];
2826
+ oe[14] = a13 * x + a23 * y + a33 * z + me[14];
2827
+ oe[15] = a14 * x + a24 * y + a34 * z + me[15];
2828
+ }
2829
+ };
2830
+ /**
2831
+ * Calculate the transpose of the specified matrix.
2832
+ * @param a - The specified matrix
2833
+ * @param out - The transpose of the specified matrix
2834
+ */ Matrix.transpose = function transpose(a, out) {
2835
+ var ae = a.elements;
2836
+ var oe = out.elements;
2837
+ if (out === a) {
2838
+ var a12 = ae[1];
2839
+ var a13 = ae[2];
2840
+ var a14 = ae[3];
2841
+ var a23 = ae[6];
2842
+ var a24 = ae[7];
2843
+ var a34 = ae[11];
2844
+ oe[1] = ae[4];
2845
+ oe[2] = ae[8];
2846
+ oe[3] = ae[12];
2847
+ oe[4] = a12;
2848
+ oe[6] = ae[9];
2849
+ oe[7] = ae[13];
2850
+ oe[8] = a13;
2851
+ oe[9] = a23;
2852
+ oe[11] = ae[14];
2853
+ oe[12] = a14;
2854
+ oe[13] = a24;
2855
+ oe[14] = a34;
2856
+ } else {
2857
+ oe[0] = ae[0];
2858
+ oe[1] = ae[4];
2859
+ oe[2] = ae[8];
2860
+ oe[3] = ae[12];
2861
+ oe[4] = ae[1];
2862
+ oe[5] = ae[5];
2863
+ oe[6] = ae[9];
2864
+ oe[7] = ae[13];
2865
+ oe[8] = ae[2];
2866
+ oe[9] = ae[6];
2867
+ oe[10] = ae[10];
2868
+ oe[11] = ae[14];
2869
+ oe[12] = ae[3];
2870
+ oe[13] = ae[7];
2871
+ oe[14] = ae[11];
2872
+ oe[15] = ae[15];
2873
+ }
2874
+ };
2875
+ return Matrix;
2876
+ }();
2877
+ Matrix._tempVec30 = new Vector3();
2878
+ Matrix._tempVec31 = new Vector3();
2879
+ Matrix._tempVec32 = new Vector3();
2880
+ Matrix._tempMat30 = new Matrix3x3();
2881
+ /** @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);
2882
+
2883
+ var WebXRFrame = /*#__PURE__*/ function() {
2884
+ function WebXRFrame(session) {
2885
+ this._session = session;
2886
+ }
2887
+ var _proto = WebXRFrame.prototype;
2888
+ _proto.updateInputs = function updateInputs(inputs) {
2889
+ if (!this._platformFrame) return;
2890
+ this._updateController(inputs);
2891
+ this._updateCamera(inputs);
2892
+ };
2893
+ _proto._updateController = function _updateController(inputs) {
2894
+ var _this = this, frame = _this._platformFrame;
2895
+ var _this__session = this._session, session = _this__session._platformSession, referenceSpace = _this__session._platformReferenceSpace;
2896
+ var inputSources = session.inputSources;
2897
+ for(var i = 0, n = inputSources.length; i < n; i++){
2898
+ var inputSource = inputSources[i];
2899
+ var type = getInputSource(inputSource);
2900
+ var input = inputs[type];
2901
+ switch(inputSource.targetRayMode){
2902
+ case "screen":
2903
+ case "tracked-pointer":
2904
+ var gripSpace = inputSource.gripSpace, targetRaySpace = inputSource.targetRaySpace;
2905
+ if (gripSpace) {
2906
+ var _frame_getPose = frame.getPose(gripSpace, referenceSpace), transform = _frame_getPose.transform, emulatedPosition = _frame_getPose.emulatedPosition;
2907
+ if (transform) {
2908
+ var gripPose = input.gripPose;
2909
+ gripPose.matrix.copyFromArray(transform.matrix);
2910
+ gripPose.position.copyFrom(transform.position);
2911
+ gripPose.rotation.copyFrom(transform.orientation);
2912
+ }
2913
+ input.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2914
+ }
2915
+ if (targetRaySpace) {
2916
+ var _frame_getPose1 = frame.getPose(targetRaySpace, referenceSpace), transform1 = _frame_getPose1.transform, emulatedPosition1 = _frame_getPose1.emulatedPosition;
2917
+ if (transform1) {
2918
+ var targetRayPose = input.targetRayPose;
2919
+ targetRayPose.matrix.copyFromArray(transform1.matrix);
2920
+ targetRayPose.position.copyFrom(transform1.position);
2921
+ targetRayPose.rotation.copyFrom(transform1.orientation);
2922
+ input.trackingState = emulatedPosition1 ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2923
+ }
2924
+ }
2925
+ break;
2926
+ }
2927
+ }
2928
+ };
2929
+ _proto._updateCamera = function _updateCamera(inputs) {
2930
+ var _this = this, frame = _this._platformFrame;
2931
+ var _this__session = this._session, referenceSpace = _this__session._platformReferenceSpace, layer = _this__session._platformLayer, framebufferWidth = _this__session.framebufferWidth, framebufferHeight = _this__session.framebufferHeight;
2932
+ var viewerPose = frame.getViewerPose(referenceSpace);
2933
+ if (viewerPose) {
2934
+ var hadUpdateCenterViewer = false;
2935
+ var views = viewerPose.views, emulatedPosition = viewerPose.emulatedPosition;
2936
+ for(var i = 0, n = views.length; i < n; i++){
2937
+ var view = views[i];
2938
+ var type = viewToCamera(view.eye);
2939
+ var transform = views[i].transform;
2940
+ if (type === XRTrackedInputDevice.Camera) {
2941
+ hadUpdateCenterViewer || (hadUpdateCenterViewer = true);
2942
+ }
2943
+ var xrCamera = inputs[type];
2944
+ var pose = xrCamera.pose;
2945
+ pose.matrix.copyFromArray(transform.matrix);
2946
+ pose.position.copyFrom(transform.position);
2947
+ pose.rotation.copyFrom(transform.orientation);
2948
+ xrCamera.projectionMatrix.copyFromArray(view.projectionMatrix);
2949
+ xrCamera.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2950
+ var xrViewport = layer.getViewport(view);
2951
+ var width = xrViewport.width / framebufferWidth;
2952
+ var height = xrViewport.height / framebufferHeight;
2953
+ var x = xrViewport.x / framebufferWidth;
2954
+ var y = 1 - xrViewport.y / framebufferHeight - height;
2955
+ xrCamera.viewport.set(x, y, width, height);
2956
+ }
2957
+ if (!hadUpdateCenterViewer) {
2958
+ var leftCameraDevice = inputs[XRTrackedInputDevice.LeftCamera];
2959
+ var rightCameraDevice = inputs[XRTrackedInputDevice.RightCamera];
2960
+ var cameraDevice = inputs[XRTrackedInputDevice.Camera];
2961
+ var leftCameraPose = leftCameraDevice.pose;
2962
+ var rightCameraPose = rightCameraDevice.pose;
2963
+ var cameraPose = cameraDevice.pose;
2964
+ cameraPose.rotation.copyFrom(leftCameraPose.rotation);
2965
+ var position = cameraPose.position, matrix = cameraPose.matrix;
2966
+ Vector3.add(leftCameraPose.position, rightCameraPose.position, position);
2967
+ position.scale(0.5);
2968
+ matrix.copyFrom(leftCameraPose.matrix);
2969
+ var elements = matrix.elements;
2970
+ elements[12] = position.x;
2971
+ elements[13] = position.y;
2972
+ elements[14] = position.z;
2973
+ cameraDevice.projectionMatrix.copyFrom(leftCameraDevice.projectionMatrix);
2974
+ cameraDevice.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2975
+ cameraDevice.viewport = leftCameraDevice.viewport.width && leftCameraDevice.viewport.height ? leftCameraDevice.viewport : rightCameraDevice.viewport;
2976
+ }
2977
+ }
2978
+ };
2979
+ return WebXRFrame;
2980
+ }();
2981
+
2982
+ var WebXRSession = /*#__PURE__*/ function() {
2983
+ function WebXRSession(session, layer, referenceSpace) {
2984
+ this._events = [];
2985
+ this._screenPointers = [];
2986
+ this._inputEventTypeMap = {
2987
+ selectstart: XRInputEventType.SelectStart,
2988
+ select: XRInputEventType.Select,
2989
+ selectend: XRInputEventType.SelectEnd,
2990
+ squeezestart: XRInputEventType.SqueezeStart,
2991
+ squeeze: XRInputEventType.Squeeze,
2992
+ squeezeend: XRInputEventType.SqueezeEnd
2993
+ };
2994
+ this._targetRayModeMap = {
2995
+ gaze: XRTargetRayMode.Gaze,
2996
+ "tracked-pointer": XRTargetRayMode.TrackedPointer,
2997
+ screen: XRTargetRayMode.Screen
2998
+ };
2999
+ this._frame = new WebXRFrame(this);
3000
+ this._platformSession = session;
3001
+ this._platformLayer = layer;
3002
+ this._platformReferenceSpace = referenceSpace;
3003
+ var xrRequestAnimationFrame = session.requestAnimationFrame.bind(session);
3004
+ var onFrame = (function(time, frame, callback) {
3005
+ this._frame._platformFrame = frame;
3006
+ callback(time);
3007
+ }).bind(this);
3008
+ this.requestAnimationFrame = function(callback) {
3009
+ return xrRequestAnimationFrame(function(time, frame) {
3010
+ onFrame(time, frame, callback);
3011
+ });
3012
+ };
3013
+ this.cancelAnimationFrame = session.cancelAnimationFrame.bind(session);
3014
+ this._onSessionEvent = this._onSessionEvent.bind(this);
3015
+ this._onSessionExit = this._onSessionExit.bind(this);
3016
+ }
3017
+ var _proto = WebXRSession.prototype;
3018
+ _proto.getFixedFoveation = function getFixedFoveation() {
3019
+ return this._platformLayer.fixedFoveation;
3020
+ };
3021
+ _proto.setFixedFoveation = function setFixedFoveation(value) {
3022
+ this._platformLayer.fixedFoveation = value;
3023
+ };
3024
+ _proto.start = function start() {};
3025
+ _proto.stop = function stop() {
3026
+ this._frame._platformFrame = null;
3027
+ };
3028
+ _proto.end = function end() {
3029
+ this._frame._platformFrame = null;
3030
+ return this._platformSession.end();
3031
+ };
3032
+ _proto.setSessionExitCallBack = function setSessionExitCallBack(onSessionExitCallBack) {
3033
+ this._onSessionExitCallBack = onSessionExitCallBack;
3034
+ };
3035
+ _proto.addEventListener = function addEventListener() {
3036
+ var _this = this, onSessionEvent = _this._onSessionEvent, session = _this._platformSession;
3037
+ session.addEventListener("select", onSessionEvent);
3038
+ session.addEventListener("selectstart", onSessionEvent);
3039
+ session.addEventListener("selectend", onSessionEvent);
3040
+ session.addEventListener("squeeze", onSessionEvent);
3041
+ session.addEventListener("squeezestart", onSessionEvent);
3042
+ session.addEventListener("squeezeend", onSessionEvent);
3043
+ session.addEventListener("end", this._onSessionExit);
3044
+ };
3045
+ _proto.removeEventListener = function removeEventListener() {
3046
+ var _this = this, onSessionEvent = _this._onSessionEvent, session = _this._platformSession;
3047
+ session.removeEventListener("select", onSessionEvent);
3048
+ session.removeEventListener("selectstart", onSessionEvent);
3049
+ session.removeEventListener("selectend", onSessionEvent);
3050
+ session.removeEventListener("squeeze", onSessionEvent);
3051
+ session.removeEventListener("squeezestart", onSessionEvent);
3052
+ session.removeEventListener("squeezeend", onSessionEvent);
3053
+ session.removeEventListener("end", this._onSessionExit);
3054
+ this._events.length = 0;
3055
+ };
3056
+ _proto.resetEvents = function resetEvents() {
3057
+ this._events.length = 0;
3058
+ };
3059
+ _proto._onSessionExit = function _onSessionExit() {
3060
+ if (this._onSessionExitCallBack) {
3061
+ this._onSessionExitCallBack();
3062
+ this._onSessionExitCallBack = null;
3063
+ }
3064
+ };
3065
+ _proto._onSessionEvent = function _onSessionEvent(inputSourceEvent) {
3066
+ var inputSource = inputSourceEvent.inputSource;
3067
+ var event = {
3068
+ type: this._inputEventTypeMap[inputSourceEvent.type],
3069
+ input: getInputSource(inputSource),
3070
+ targetRayMode: this._targetRayModeMap[inputSource.targetRayMode]
3071
+ };
3072
+ if (event.targetRayMode === XRTargetRayMode.Screen) {
3073
+ var _this = this, screenPointers = _this._screenPointers;
3074
+ var axes = inputSource.gamepad.axes;
3075
+ event.x = axes[0];
3076
+ event.y = axes[1];
3077
+ switch(event.type){
3078
+ case XRInputEventType.SelectStart:
3079
+ var idx = -1;
3080
+ var emptyIdx = -1;
3081
+ for(var i = screenPointers.length - 1; i >= 0; i--){
3082
+ var pointer = screenPointers[i];
3083
+ if (pointer === inputSource) {
3084
+ idx = i;
3085
+ break;
3086
+ }
3087
+ if (!pointer) {
3088
+ emptyIdx = i;
3089
+ }
3090
+ }
3091
+ if (idx === -1) {
3092
+ if (emptyIdx === -1) {
3093
+ idx = screenPointers.push(inputSource) - 1;
3094
+ } else {
3095
+ idx = emptyIdx;
3096
+ screenPointers[emptyIdx] = inputSource;
3097
+ }
3098
+ }
3099
+ event.id = idx;
3100
+ break;
3101
+ case XRInputEventType.SelectEnd:
3102
+ for(var i1 = screenPointers.length - 1; i1 >= 0; i1--){
3103
+ if (screenPointers[i1] === inputSource) {
3104
+ screenPointers[i1] = null;
3105
+ event.id = i1;
3106
+ }
3107
+ }
3108
+ break;
3109
+ }
3110
+ }
3111
+ this._events.push(event);
3112
+ };
3113
+ _create_class$1(WebXRSession, [
3114
+ {
3115
+ key: "frame",
3116
+ get: function get() {
3117
+ return this._frame;
3118
+ }
3119
+ },
3120
+ {
3121
+ key: "framebuffer",
3122
+ get: function get() {
3123
+ return this._platformLayer.framebuffer;
3124
+ }
3125
+ },
3126
+ {
3127
+ key: "framebufferWidth",
3128
+ get: function get() {
3129
+ return this._platformLayer.framebufferWidth;
3130
+ }
3131
+ },
3132
+ {
3133
+ key: "framebufferHeight",
3134
+ get: function get() {
3135
+ return this._platformLayer.framebufferHeight;
3136
+ }
3137
+ },
3138
+ {
3139
+ key: "frameRate",
3140
+ get: function get() {
3141
+ return this._platformSession.frameRate;
3142
+ }
3143
+ },
3144
+ {
3145
+ key: "supportedFrameRates",
3146
+ get: function get() {
3147
+ return this._platformSession.supportedFrameRates;
3148
+ }
3149
+ },
3150
+ {
3151
+ key: "events",
3152
+ get: function get() {
3153
+ var _this = this, events = _this._events;
3154
+ // Select event does not dispatch the move event, so we need to simulate dispatching the move here.
3155
+ var _this1 = this, screenPointers = _this1._screenPointers;
3156
+ for(var i = 0; i < screenPointers.length; i++){
3157
+ var inputSource = screenPointers[i];
3158
+ if (!inputSource) continue;
3159
+ var axes = inputSource.gamepad.axes;
3160
+ var event = {
3161
+ type: XRInputEventType.Select,
3162
+ targetRayMode: XRTargetRayMode.Screen,
3163
+ input: XRTrackedInputDevice.Controller,
3164
+ id: i,
3165
+ x: axes[0],
3166
+ y: axes[1]
3167
+ };
3168
+ events.push(event);
3169
+ }
3170
+ return events;
3171
+ }
3172
+ }
3173
+ ]);
3174
+ return WebXRSession;
3175
+ }();
3176
+
3177
+ var WebXRDevice = /*#__PURE__*/ function() {
3178
+ function WebXRDevice() {}
3179
+ var _proto = WebXRDevice.prototype;
3180
+ _proto.isSupportedSessionMode = function isSupportedSessionMode(mode) {
3181
+ return new Promise(function(resolve, reject) {
3182
+ if (!window.isSecureContext) {
3183
+ reject(new Error("WebXR is available only in secure contexts (HTTPS)."));
3184
+ return;
3185
+ }
3186
+ if (!navigator.xr) {
3187
+ reject(new Error("WebXR isn't available"));
3188
+ return;
3189
+ }
3190
+ navigator.xr.isSessionSupported(parseXRMode(mode)).then(function(isSupported) {
3191
+ isSupported ? resolve() : reject(new Error("The current context doesn't support WebXR."));
3192
+ });
3193
+ });
3194
+ };
3195
+ _proto.isSupportedFeature = function isSupportedFeature(type) {
3196
+ switch(type){
3197
+ case XRFeatureType.HitTest:
3198
+ case XRFeatureType.PlaneTracking:
3199
+ return typeof XRPlane !== "undefined";
3200
+ case XRFeatureType.AnchorTracking:
3201
+ return typeof XRAnchor !== "undefined";
3202
+ case XRFeatureType.ImageTracking:
3203
+ // @ts-ignore
3204
+ return typeof XRImageTrackingResult !== "undefined";
3205
+ }
3206
+ };
3207
+ _proto.createPlatformFeature = function createPlatformFeature(type) {
3208
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
3209
+ args[_key - 1] = arguments[_key];
3210
+ }
3211
+ var platformFeatureConstructor = WebXRDevice._platformFeatureMap[type];
3212
+ return platformFeatureConstructor ? _construct(platformFeatureConstructor, [].concat(args)) : null;
3213
+ };
3214
+ _proto.requestSession = function requestSession(rhi, mode, platformFeatures) {
3215
+ return new Promise(function(resolve, reject) {
3216
+ var sessionMode = parseXRMode(mode);
3217
+ var options = {
3218
+ requiredFeatures: [
3219
+ "local"
3220
+ ],
3221
+ optionalFeatures: []
3222
+ };
3223
+ var promiseArr = [];
3224
+ for(var i = 0, n = platformFeatures.length; i < n; i++){
3225
+ var promise = platformFeatures[i]._assembleOptions(options);
3226
+ promise && promiseArr.push(promise);
3227
+ }
3228
+ Promise.all(promiseArr).then(function() {
3229
+ navigator.xr.requestSession(sessionMode, options).then(function(session) {
3230
+ var gl = rhi.gl;
3231
+ var attributes = gl.getContextAttributes();
3232
+ if (!attributes) {
3233
+ reject(Error("GetContextAttributes Error!"));
3234
+ }
3235
+ gl.makeXRCompatible().then(function() {
3236
+ var scaleFactor = XRWebGLLayer.getNativeFramebufferScaleFactor(session);
3237
+ var layer;
3238
+ if (session.renderState.layers === undefined || !!!rhi.isWebGL2) {
3239
+ var layerInit = {
3240
+ antialias: session.renderState.layers === undefined ? attributes.antialias : true,
3241
+ alpha: true,
3242
+ depth: attributes.depth,
3243
+ stencil: attributes.stencil,
3244
+ framebufferScaleFactor: scaleFactor
3245
+ };
3246
+ layer = new XRWebGLLayer(session, gl, layerInit);
3247
+ session.updateRenderState({
3248
+ baseLayer: layer
3249
+ });
3250
+ } else {
3251
+ layer = new XRWebGLLayer(session, gl);
3252
+ session.updateRenderState({
3253
+ layers: [
3254
+ layer
3255
+ ]
3256
+ });
3257
+ }
3258
+ session.requestReferenceSpace("local").then(function(referenceSpace) {
3259
+ resolve(new WebXRSession(session, layer, referenceSpace));
3260
+ }, reject);
3261
+ }, reject);
3262
+ }, reject);
3263
+ }, reject);
3264
+ });
3265
+ };
3266
+ return WebXRDevice;
3267
+ }();
3268
+ /** @internal */ WebXRDevice._platformFeatureMap = [];
3269
+ function registerXRPlatformFeature(type) {
3270
+ return function(platformFeatureConstructor) {
3271
+ WebXRDevice._platformFeatureMap[type] = platformFeatureConstructor;
3272
+ };
3273
+ }
3274
+
3275
+ /**
3276
+ * @internal
3277
+ */ var WebXRFeature = function WebXRFeature() {
3278
+ };
3279
+
3280
+ /**
3281
+ * @internal
3282
+ */ var WebXRTrackableFeature = /*#__PURE__*/ function(WebXRFeature) {
3283
+ _inherits(WebXRTrackableFeature, WebXRFeature);
3284
+ function WebXRTrackableFeature() {
3285
+ return WebXRFeature.apply(this, arguments) || this;
3286
+ }
3287
+ var _proto = WebXRTrackableFeature.prototype;
3288
+ _proto.onAddRequestTracking = function onAddRequestTracking(requestTracking) {};
3289
+ _proto.onDelRequestTracking = function onDelRequestTracking(requestTracking) {
3290
+ requestTracking.state = XRRequestTrackingState.Destroyed;
3291
+ };
3292
+ _create_class$1(WebXRTrackableFeature, [
3293
+ {
3294
+ key: "canModifyRequestTrackingAfterInit",
3295
+ get: function get() {
3296
+ return false;
3297
+ }
3298
+ }
3299
+ ]);
3300
+ return WebXRTrackableFeature;
3301
+ }(WebXRFeature);
3302
+
3303
+ var WebXRAnchorTracking = /*#__PURE__*/ function(WebXRTrackableFeature) {
3304
+ _inherits(WebXRAnchorTracking, WebXRTrackableFeature);
3305
+ function WebXRAnchorTracking() {
3306
+ return WebXRTrackableFeature.apply(this, arguments) || this;
3307
+ }
3308
+ var _proto = WebXRAnchorTracking.prototype;
3309
+ _proto.checkAvailable = function checkAvailable(session, frame, requestTrackings) {
3310
+ if (!frame._platformFrame) return false;
3311
+ for(var i = 0, n = requestTrackings.length; i < n; i++){
3312
+ var requestTracking = requestTrackings[i];
3313
+ if (requestTracking.state === XRRequestTrackingState.None) {
3314
+ this._addAnchor(session, frame, requestTracking);
3315
+ }
3316
+ }
3317
+ return true;
3318
+ };
3319
+ _proto.getTrackedResult = function getTrackedResult(session, frame, requestTrackings) {
3320
+ var platformReferenceSpace = session._platformReferenceSpace;
3321
+ var platformFrame = frame._platformFrame;
3322
+ var trackedAnchors = platformFrame.trackedAnchors;
3323
+ for(var i = 0, n = requestTrackings.length; i < n; i++){
3324
+ var requestTracking = requestTrackings[i];
3325
+ if (requestTracking.state !== XRRequestTrackingState.Resolved) continue;
3326
+ var tracked = requestTracking.tracked[0];
3327
+ if (trackedAnchors.has(requestTracking.xrAnchor)) {
3328
+ var emulated = this._updateTrackedAnchor(platformFrame, platformReferenceSpace, requestTracking);
3329
+ if (emulated) {
3330
+ if (tracked.state === XRTrackingState.Tracking) {
3331
+ tracked.state = XRTrackingState.TrackingLost;
3332
+ }
3333
+ } else {
3334
+ tracked.state = XRTrackingState.Tracking;
3335
+ }
3336
+ } else {
3337
+ tracked.state = XRTrackingState.NotTracking;
3338
+ }
3339
+ }
3340
+ };
3341
+ _proto.onDelRequestTracking = function onDelRequestTracking(requestTracking) {
3342
+ switch(requestTracking.state){
3343
+ case XRRequestTrackingState.Submitted:
3344
+ requestTracking.state = XRRequestTrackingState.WaitingDestroy;
3345
+ break;
3346
+ case XRRequestTrackingState.Resolved:
3347
+ requestTracking.xrAnchor.delete();
3348
+ requestTracking.state = XRRequestTrackingState.Destroyed;
3349
+ break;
3350
+ default:
3351
+ requestTracking.state = XRRequestTrackingState.Destroyed;
3352
+ break;
3353
+ }
3354
+ };
3355
+ /**
3356
+ * @internal
3357
+ */ _proto._assembleOptions = function _assembleOptions(options) {
3358
+ options.optionalFeatures.push("anchors");
3359
+ };
3360
+ _proto._addAnchor = function _addAnchor(session, frame, requestTracking) {
3361
+ if (!session || !frame) {
3362
+ return;
3363
+ }
3364
+ requestTracking.state = XRRequestTrackingState.Submitted;
3365
+ var position = requestTracking.position, rotation = requestTracking.rotation;
3366
+ var platformFrame = frame._platformFrame;
3367
+ var platformReferenceSpace = session._platformReferenceSpace;
3368
+ platformFrame.createAnchor(new XRRigidTransform({
3369
+ x: position.x,
3370
+ y: position.y,
3371
+ z: position.z
3372
+ }, {
3373
+ x: rotation.x,
3374
+ y: rotation.y,
3375
+ z: rotation.z,
3376
+ w: rotation.w
3377
+ }), platformReferenceSpace).then(function(xrAnchor) {
3378
+ if (requestTracking.state === XRRequestTrackingState.WaitingDestroy) {
3379
+ xrAnchor.delete();
3380
+ requestTracking.state = XRRequestTrackingState.Destroyed;
3381
+ } else {
3382
+ requestTracking.xrAnchor = xrAnchor;
3383
+ requestTracking.state = XRRequestTrackingState.Resolved;
3384
+ }
3385
+ }, function() {
3386
+ if (requestTracking.state === XRRequestTrackingState.WaitingDestroy) {
3387
+ requestTracking.state = XRRequestTrackingState.Destroyed;
3388
+ } else {
3389
+ requestTracking.state = XRRequestTrackingState.Rejected;
3390
+ }
3391
+ });
3392
+ };
3393
+ _proto._updateTrackedAnchor = function _updateTrackedAnchor(frame, space, requestTracking) {
3394
+ var xrAnchor = requestTracking.xrAnchor;
3395
+ var xrPose = frame.getPose(xrAnchor.anchorSpace, space);
3396
+ var transform = xrPose.transform;
3397
+ var pose = requestTracking.tracked[0].pose;
3398
+ pose.matrix.copyFromArray(transform.matrix);
3399
+ pose.rotation.copyFrom(transform.orientation);
3400
+ pose.position.copyFrom(transform.position);
3401
+ return xrPose.emulatedPosition;
3402
+ };
3403
+ _create_class$1(WebXRAnchorTracking, [
3404
+ {
3405
+ key: "canModifyRequestTrackingAfterInit",
3406
+ get: function get() {
3407
+ return true;
3408
+ }
3409
+ }
3410
+ ]);
3411
+ return WebXRAnchorTracking;
3412
+ }(WebXRTrackableFeature);
3413
+ WebXRAnchorTracking = __decorate([
3414
+ registerXRPlatformFeature(XRFeatureType.AnchorTracking)
3415
+ ], WebXRAnchorTracking);
3416
+
3417
+ var WebXRImageTracking = /*#__PURE__*/ function(WebXRTrackableFeature) {
3418
+ _inherits(WebXRImageTracking, WebXRTrackableFeature);
3419
+ function WebXRImageTracking(images) {
3420
+ var _this;
3421
+ _this = WebXRTrackableFeature.call(this) || this, _this._trackingScoreStatus = 0, _this._tempIdx = 0, _this._tempArr = [];
3422
+ _this._images = images;
3423
+ return _this;
3424
+ }
3425
+ var _proto = WebXRImageTracking.prototype;
3426
+ _proto.checkAvailable = function checkAvailable(session, frame, requestTrackings) {
3427
+ if (!frame._platformFrame) return false;
3428
+ switch(this._trackingScoreStatus){
3429
+ case 0:
3430
+ this._requestTrackingScore(session, requestTrackings);
3431
+ return false;
3432
+ case 1:
3433
+ return false;
3434
+ }
3435
+ return true;
3436
+ };
3437
+ _proto.getTrackedResult = function getTrackedResult(session, frame, requestTrackings, generateTracked) {
3438
+ var platformReferenceSpace = session._platformReferenceSpace;
3439
+ var platformFrame = frame._platformFrame;
3440
+ var _this = this, tempArr = _this._tempArr;
3441
+ var idx = ++this._tempIdx;
3442
+ // @ts-ignore
3443
+ var trackingResults = platformFrame.getImageTrackingResults();
3444
+ for(var i = 0, n = trackingResults.length; i < n; i++){
3445
+ var trackingResult = trackingResults[i];
3446
+ var index = trackingResult.index;
3447
+ var requestTrackingImage = requestTrackings[index];
3448
+ if (requestTrackingImage) {
3449
+ var tracked = requestTrackingImage.tracked[0];
3450
+ if (!tracked) {
3451
+ tracked = requestTrackingImage.tracked[0] = generateTracked();
3452
+ tracked.referenceImage = requestTrackingImage.image;
3453
+ }
3454
+ if (trackingResult.trackingState === "tracked") {
3455
+ this._updateTrackedImage(platformFrame, platformReferenceSpace, tracked, trackingResult);
3456
+ tracked.state = XRTrackingState.Tracking;
3457
+ } else {
3458
+ tracked.state = XRTrackingState.TrackingLost;
3459
+ }
3460
+ tempArr[index] = idx;
3461
+ } else {
3462
+ console.warn("Images can not find " + index);
3463
+ }
3464
+ }
3465
+ for(var i1 = 0, n1 = requestTrackings.length; i1 < n1; i1++){
3466
+ if (tempArr[i1] < idx) requestTrackings[i1].tracked[0].state = XRTrackingState.NotTracking;
3467
+ }
3468
+ };
3469
+ _proto.onAddRequestTracking = function onAddRequestTracking(requestTracking) {
3470
+ requestTracking.state = XRRequestTrackingState.Submitted;
3471
+ };
3472
+ /**
3473
+ * @internal
3474
+ */ _proto._assembleOptions = function _assembleOptions(options) {
3475
+ options.optionalFeatures.push("image-tracking");
3476
+ var _this = this, images = _this._images;
3477
+ var promiseArr = [];
3478
+ if (images) {
3479
+ for(var i = 0, n = images.length; i < n; i++){
3480
+ var referenceImage = images[i];
3481
+ var imageSource = images[i].imageSource;
3482
+ if (!imageSource) {
3483
+ return Promise.reject(new Error("referenceImage[" + referenceImage.name + "].src is null"));
3484
+ } else {
3485
+ promiseArr.push(createImageBitmap(imageSource));
3486
+ }
3487
+ }
3488
+ return new Promise(function(resolve, reject) {
3489
+ // @ts-ignore
3490
+ var trackedImages = options.trackedImages = [];
3491
+ Promise.all(promiseArr).then(function(bitmaps) {
3492
+ for(var i = 0, n = bitmaps.length; i < n; i++){
3493
+ trackedImages.push({
3494
+ image: bitmaps[i],
3495
+ widthInMeters: images[i].physicalWidth
3496
+ });
3497
+ }
3498
+ resolve();
3499
+ }, reject);
3500
+ });
3501
+ } else {
3502
+ return Promise.reject(new Error("Images.length is 0"));
3503
+ }
3504
+ };
3505
+ _proto._requestTrackingScore = function _requestTrackingScore(session, requestTrackings) {
3506
+ var _this = this;
3507
+ this._trackingScoreStatus = 1;
3508
+ session._platformSession// @ts-ignore
3509
+ .getTrackedImageScores().then(function(trackingScores) {
3510
+ if (trackingScores) {
3511
+ for(var i = 0, n = trackingScores.length; i < n; i++){
3512
+ var trackingScore = trackingScores[i];
3513
+ var requestTracking = requestTrackings[i];
3514
+ if (trackingScore === "trackable") {
3515
+ _this._trackingScoreStatus = 2;
3516
+ requestTracking.state = XRRequestTrackingState.Resolved;
3517
+ } else {
3518
+ requestTracking.state = XRRequestTrackingState.Rejected;
3519
+ console.warn(requestTracking.image.name, " unTrackable");
3520
+ }
3521
+ }
3522
+ }
3523
+ });
3524
+ };
3525
+ _proto._updateTrackedImage = function _updateTrackedImage(frame, space, trackedImage, trackingResult) {
3526
+ var pose = trackedImage.pose;
3527
+ var transform = frame.getPose(trackingResult.imageSpace, space).transform;
3528
+ pose.matrix.copyFromArray(transform.matrix);
3529
+ pose.rotation.copyFrom(transform.orientation);
3530
+ pose.position.copyFrom(transform.position);
3531
+ trackedImage.measuredPhysicalWidth = trackingResult.measuredWidthInMeters;
3532
+ };
3533
+ return WebXRImageTracking;
3534
+ }(WebXRTrackableFeature);
3535
+ WebXRImageTracking = __decorate([
3536
+ registerXRPlatformFeature(XRFeatureType.ImageTracking)
3537
+ ], WebXRImageTracking);
3538
+
3539
+ var WebXRPlaneTracking = /*#__PURE__*/ function(WebXRTrackableFeature) {
3540
+ _inherits(WebXRPlaneTracking, WebXRTrackableFeature);
3541
+ function WebXRPlaneTracking(detectedMode) {
3542
+ var _this;
3543
+ _this = WebXRTrackableFeature.call(this) || this;
3544
+ if (detectedMode !== XRPlaneMode.EveryThing) {
3545
+ console.warn("WebXR only support XRPlaneMode.EveryThing");
3546
+ }
3547
+ return _this;
3548
+ }
3549
+ var _proto = WebXRPlaneTracking.prototype;
3550
+ _proto.checkAvailable = function checkAvailable(session, frame, requestTrackings) {
3551
+ return !!frame._platformFrame;
3552
+ };
3553
+ _proto.getTrackedResult = function getTrackedResult(session, frame, requestTrackings, generateTracked) {
3554
+ var _this = this;
3555
+ var _platformFrame_worldInformation;
3556
+ var platformReferenceSpace = session._platformReferenceSpace;
3557
+ var platformFrame = frame._platformFrame;
3558
+ // @ts-ignore
3559
+ var detectedPlanes = platformFrame.detectedPlanes || ((_platformFrame_worldInformation = platformFrame.worldInformation) == null ? void 0 : _platformFrame_worldInformation.detectedPlanes);
3560
+ var tracked = requestTrackings[0].tracked;
3561
+ for(var i = 0, n = tracked.length; i < n; i++){
3562
+ var trackedPlane = tracked[i];
3563
+ if (detectedPlanes.has(trackedPlane.xrPlane)) {
3564
+ trackedPlane.state = XRTrackingState.Tracking;
3565
+ this._updatePlane(platformFrame, platformReferenceSpace, trackedPlane);
3566
+ } else {
3567
+ trackedPlane.state = XRTrackingState.NotTracking;
3568
+ }
3569
+ }
3570
+ var _this1 = this, lastDetectedPlanes = _this1._lastDetectedPlanes;
3571
+ detectedPlanes.forEach(function(xrPlane) {
3572
+ if (!(lastDetectedPlanes == null ? void 0 : lastDetectedPlanes.has(xrPlane))) {
3573
+ var plane = generateTracked();
3574
+ plane.xrPlane = xrPlane;
3575
+ plane.lastChangedTime = -1;
3576
+ _this._updatePlane(platformFrame, platformReferenceSpace, plane);
3577
+ tracked.push(plane);
3578
+ }
3579
+ });
3580
+ this._lastDetectedPlanes = detectedPlanes;
3581
+ };
3582
+ _proto.onAddRequestTracking = function onAddRequestTracking(requestTracking) {
3583
+ requestTracking.state = XRRequestTrackingState.Resolved;
3584
+ };
3585
+ /**
3586
+ * @internal
3587
+ */ _proto._assembleOptions = function _assembleOptions(options) {
3588
+ options.optionalFeatures.push("plane-detection");
3589
+ };
3590
+ _proto._updatePlane = function _updatePlane(frame, space, trackedPlane) {
3591
+ var pose = trackedPlane.pose, polygon = trackedPlane.polygon, xrPlane = trackedPlane.xrPlane;
3592
+ var planePose = frame.getPose(xrPlane.planeSpace, space);
3593
+ if (!planePose) return;
3594
+ var transform = planePose.transform, emulatedPosition = planePose.emulatedPosition;
3595
+ trackedPlane.state = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
3596
+ trackedPlane.planeMode = xrPlane.orientation === "horizontal" ? XRPlaneMode.Horizontal : XRPlaneMode.Vertical;
3597
+ if (trackedPlane.lastChangedTime < xrPlane.lastChangedTime) {
3598
+ trackedPlane.lastChangedTime = xrPlane.lastChangedTime;
3599
+ trackedPlane.attributesDirty = true;
3600
+ var oriPolygon = xrPlane.polygon;
3601
+ for(var i = 0, n = polygon.length = oriPolygon.length; i < n; i++){
3602
+ var _polygon, _i;
3603
+ ((_polygon = polygon)[_i = i] || (_polygon[_i] = new Vector3())).copyFrom(oriPolygon[i]);
3604
+ }
3605
+ } else {
3606
+ trackedPlane.attributesDirty = false;
3607
+ }
3608
+ pose.rotation.copyFrom(transform.orientation);
3609
+ pose.position.copyFrom(transform.position);
3610
+ pose.matrix.copyFromArray(transform.matrix);
3611
+ pose.inverseMatrix.copyFromArray(transform.inverse.matrix);
3612
+ };
3613
+ return WebXRPlaneTracking;
3614
+ }(WebXRTrackableFeature);
3615
+ WebXRPlaneTracking = __decorate([
3616
+ registerXRPlatformFeature(XRFeatureType.PlaneTracking)
3617
+ ], WebXRPlaneTracking);
3618
+
3619
+ export { WebXRDevice };
3620
+ //# sourceMappingURL=module.js.map