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