forked from immersive-web/webxr-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webxr-polyfill.js
6176 lines (5989 loc) · 270 KB
/
webxr-polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @license
* webxr-polyfill
* Copyright (c) 2017 Google
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @license
* cardboard-vr-display
* Copyright (c) 2015-2017 Google
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @license
* webvr-polyfill-dpdb
* Copyright (c) 2017 Google
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @license
* wglu-preserve-state
* Copyright (c) 2016, Brandon Jones.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @license
* nosleep.js
* Copyright (c) 2017, Rich Tibbett
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.WebXRPolyfill = factory());
}(this, (function () { 'use strict';
var _global = typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var PRIVATE = Symbol('@@webxr-polyfill/EventTarget');
var EventTarget = function () {
function EventTarget() {
classCallCheck(this, EventTarget);
this[PRIVATE] = {
listeners: new Map()
};
}
createClass(EventTarget, [{
key: 'addEventListener',
value: function addEventListener(type, listener) {
if (typeof type !== 'string') {
throw new Error('`type` must be a string');
}
if (typeof listener !== 'function') {
throw new Error('`listener` must be a function');
}
var typedListeners = this[PRIVATE].listeners.get(type) || [];
typedListeners.push(listener);
this[PRIVATE].listeners.set(type, typedListeners);
}
}, {
key: 'removeEventListener',
value: function removeEventListener(type, listener) {
if (typeof type !== 'string') {
throw new Error('`type` must be a string');
}
if (typeof listener !== 'function') {
throw new Error('`listener` must be a function');
}
var typedListeners = this[PRIVATE].listeners.get(type) || [];
for (var i = typedListeners.length; i >= 0; i--) {
if (typedListeners[i] === listener) {
typedListeners.pop();
}
}
}
}, {
key: 'dispatchEvent',
value: function dispatchEvent(type, event) {
var typedListeners = this[PRIVATE].listeners.get(type) || [];
var queue = [];
for (var i = 0; i < typedListeners.length; i++) {
queue[i] = typedListeners[i];
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var listener = _step.value;
listener(event);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (typeof this['on' + type] === 'function') {
this['on' + type](event);
}
}
}]);
return EventTarget;
}();
var PRIVATE$1 = Symbol('@@webxr-polyfill/XR');
var XR = function (_EventTarget) {
inherits(XR, _EventTarget);
function XR(device) {
classCallCheck(this, XR);
var _this = possibleConstructorReturn(this, (XR.__proto__ || Object.getPrototypeOf(XR)).call(this));
_this[PRIVATE$1] = {
device: device
};
return _this;
}
createClass(XR, [{
key: 'requestDevice',
value: function requestDevice() {
return new Promise(function ($return, $error) {
var device;
return Promise.resolve(this[PRIVATE$1].device).then(function ($await_1) {
try {
device = $await_1;
if (device) {
return $return(device);
}
return $error(new Error('NotFoundError'));
} catch ($boundEx) {
return $error($boundEx);
}
}.bind(this), $error);
}.bind(this));
}
}]);
return XR;
}(EventTarget);
var now = void 0;
if ('performance' in _global === false) {
var startTime = Date.now();
now = function now() {
return Date.now() - startTime;
};
} else {
now = function now() {
return performance.now();
};
}
var now$1 = now;
var PRIVATE$2 = Symbol('@@webxr-polyfill/XRPresentationContext');
var XRPresentationContext = function () {
function XRPresentationContext(canvas, ctx, glAttribs) {
classCallCheck(this, XRPresentationContext);
this[PRIVATE$2] = { canvas: canvas, ctx: ctx, glAttribs: glAttribs };
Object.assign(this, ctx);
}
createClass(XRPresentationContext, [{
key: 'canvas',
get: function get$$1() {
return this[PRIVATE$2].canvas;
}
}]);
return XRPresentationContext;
}();
var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
var degree = Math.PI / 180;
function create() {
var out = new ARRAY_TYPE(16);
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;
return out;
}
function copy(out, a) {
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
out[4] = a[4];
out[5] = a[5];
out[6] = a[6];
out[7] = a[7];
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
return out;
}
function identity(out) {
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;
return out;
}
function invert(out, a) {
var a00 = a[0],
a01 = a[1],
a02 = a[2],
a03 = a[3];
var a10 = a[4],
a11 = a[5],
a12 = a[6],
a13 = a[7];
var a20 = a[8],
a21 = a[9],
a22 = a[10],
a23 = a[11];
var a30 = a[12],
a31 = a[13],
a32 = a[14],
a33 = a[15];
var b00 = a00 * a11 - a01 * a10;
var b01 = a00 * a12 - a02 * a10;
var b02 = a00 * a13 - a03 * a10;
var b03 = a01 * a12 - a02 * a11;
var b04 = a01 * a13 - a03 * a11;
var b05 = a02 * a13 - a03 * a12;
var b06 = a20 * a31 - a21 * a30;
var b07 = a20 * a32 - a22 * a30;
var b08 = a20 * a33 - a23 * a30;
var b09 = a21 * a32 - a22 * a31;
var b10 = a21 * a33 - a23 * a31;
var b11 = a22 * a33 - a23 * a32;
var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
if (!det) {
return null;
}
det = 1.0 / det;
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
return out;
}
function multiply(out, a, b) {
var a00 = a[0],
a01 = a[1],
a02 = a[2],
a03 = a[3];
var a10 = a[4],
a11 = a[5],
a12 = a[6],
a13 = a[7];
var a20 = a[8],
a21 = a[9],
a22 = a[10],
a23 = a[11];
var a30 = a[12],
a31 = a[13],
a32 = a[14],
a33 = a[15];
var b0 = b[0],
b1 = b[1],
b2 = b[2],
b3 = b[3];
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
b0 = b[4];b1 = b[5];b2 = b[6];b3 = b[7];
out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
b0 = b[8];b1 = b[9];b2 = b[10];b3 = b[11];
out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
b0 = b[12];b1 = b[13];b2 = b[14];b3 = b[15];
out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
return out;
}
function fromRotationTranslation(out, q, v) {
var x = q[0],
y = q[1],
z = q[2],
w = q[3];
var x2 = x + x;
var y2 = y + y;
var z2 = z + z;
var xx = x * x2;
var xy = x * y2;
var xz = x * z2;
var yy = y * y2;
var yz = y * z2;
var zz = z * z2;
var wx = w * x2;
var wy = w * y2;
var wz = w * z2;
out[0] = 1 - (yy + zz);
out[1] = xy + wz;
out[2] = xz - wy;
out[3] = 0;
out[4] = xy - wz;
out[5] = 1 - (xx + zz);
out[6] = yz + wx;
out[7] = 0;
out[8] = xz + wy;
out[9] = yz - wx;
out[10] = 1 - (xx + yy);
out[11] = 0;
out[12] = v[0];
out[13] = v[1];
out[14] = v[2];
out[15] = 1;
return out;
}
function getTranslation(out, mat) {
out[0] = mat[12];
out[1] = mat[13];
out[2] = mat[14];
return out;
}
function getRotation(out, mat) {
var trace = mat[0] + mat[5] + mat[10];
var S = 0;
if (trace > 0) {
S = Math.sqrt(trace + 1.0) * 2;
out[3] = 0.25 * S;
out[0] = (mat[6] - mat[9]) / S;
out[1] = (mat[8] - mat[2]) / S;
out[2] = (mat[1] - mat[4]) / S;
} else if (mat[0] > mat[5] && mat[0] > mat[10]) {
S = Math.sqrt(1.0 + mat[0] - mat[5] - mat[10]) * 2;
out[3] = (mat[6] - mat[9]) / S;
out[0] = 0.25 * S;
out[1] = (mat[1] + mat[4]) / S;
out[2] = (mat[8] + mat[2]) / S;
} else if (mat[5] > mat[10]) {
S = Math.sqrt(1.0 + mat[5] - mat[0] - mat[10]) * 2;
out[3] = (mat[8] - mat[2]) / S;
out[0] = (mat[1] + mat[4]) / S;
out[1] = 0.25 * S;
out[2] = (mat[6] + mat[9]) / S;
} else {
S = Math.sqrt(1.0 + mat[10] - mat[0] - mat[5]) * 2;
out[3] = (mat[1] - mat[4]) / S;
out[0] = (mat[8] + mat[2]) / S;
out[1] = (mat[6] + mat[9]) / S;
out[2] = 0.25 * S;
}
return out;
}
function perspective(out, fovy, aspect, near, far) {
var f = 1.0 / Math.tan(fovy / 2);
var nf = 1 / (near - far);
out[0] = f / aspect;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = f;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = (far + near) * nf;
out[11] = -1;
out[12] = 0;
out[13] = 0;
out[14] = 2 * far * near * nf;
out[15] = 0;
return out;
}
var PRIVATE$3 = Symbol('@@webxr-polyfill/XRDevicePose');
var XRDevicePose = function () {
function XRDevicePose(polyfill) {
classCallCheck(this, XRDevicePose);
this[PRIVATE$3] = {
polyfill: polyfill,
leftViewMatrix: identity(new Float32Array(16)),
rightViewMatrix: identity(new Float32Array(16)),
poseModelMatrix: identity(new Float32Array(16))
};
}
createClass(XRDevicePose, [{
key: 'getViewMatrix',
value: function getViewMatrix(view) {
switch (view.eye) {
case 'left':
return this[PRIVATE$3].leftViewMatrix;
case 'right':
return this[PRIVATE$3].rightViewMatrix;
}
throw new Error('view is not a valid XREye');
}
}, {
key: 'updateFromFrameOfReference',
value: function updateFromFrameOfReference(frameOfRef) {
var pose = this[PRIVATE$3].polyfill.getBasePoseMatrix();
var leftViewMatrix = this[PRIVATE$3].polyfill.getBaseViewMatrix('left');
var rightViewMatrix = this[PRIVATE$3].polyfill.getBaseViewMatrix('right');
if (pose) {
frameOfRef.transformBasePoseMatrix(this[PRIVATE$3].poseModelMatrix, pose);
}
if (leftViewMatrix && rightViewMatrix) {
frameOfRef.transformBaseViewMatrix(this[PRIVATE$3].leftViewMatrix, leftViewMatrix, this[PRIVATE$3].poseModelMatrix);
frameOfRef.transformBaseViewMatrix(this[PRIVATE$3].rightViewMatrix, rightViewMatrix, this[PRIVATE$3].poseModelMatrix);
}
}
}, {
key: 'poseModelMatrix',
get: function get$$1() {
return this[PRIVATE$3].poseModelMatrix;
}
}]);
return XRDevicePose;
}();
var PRIVATE$4 = Symbol('@@webxr-polyfill/XRViewport');
var XRViewport = function () {
function XRViewport(target) {
classCallCheck(this, XRViewport);
this[PRIVATE$4] = { target: target };
}
createClass(XRViewport, [{
key: 'x',
get: function get$$1() {
return this[PRIVATE$4].target.x;
}
}, {
key: 'y',
get: function get$$1() {
return this[PRIVATE$4].target.y;
}
}, {
key: 'width',
get: function get$$1() {
return this[PRIVATE$4].target.width;
}
}, {
key: 'height',
get: function get$$1() {
return this[PRIVATE$4].target.height;
}
}]);
return XRViewport;
}();
var XREyes = ['left', 'right'];
var PRIVATE$5 = Symbol('@@webxr-polyfill/XRView');
var XRView = function () {
function XRView(polyfill, eye, sessionId) {
classCallCheck(this, XRView);
if (!XREyes.includes(eye)) {
throw new Error('XREye must be one of: ' + XREyes);
}
var temp = Object.create(null);
var viewport = new XRViewport(temp);
this[PRIVATE$5] = {
polyfill: polyfill,
eye: eye,
viewport: viewport,
temp: temp,
sessionId: sessionId
};
}
createClass(XRView, [{
key: '_getViewport',
value: function _getViewport(layer) {
var viewport = this[PRIVATE$5].viewport;
if (this[PRIVATE$5].polyfill.getViewport(this[PRIVATE$5].sessionId, this.eye, layer, this[PRIVATE$5].temp)) {
return this[PRIVATE$5].viewport;
}
return undefined;
}
}, {
key: 'eye',
get: function get$$1() {
return this[PRIVATE$5].eye;
}
}, {
key: 'projectionMatrix',
get: function get$$1() {
return this[PRIVATE$5].polyfill.getProjectionMatrix(this.eye);
}
}]);
return XRView;
}();
var PRIVATE$6 = Symbol('@@webxr-polyfill/XRFrame');
var XRFrame = function () {
function XRFrame(polyfill, session, sessionId) {
classCallCheck(this, XRFrame);
var devicePose = new XRDevicePose(polyfill);
var views = [new XRView(polyfill, 'left', sessionId)];
if (session.immersive) {
views.push(new XRView(polyfill, 'right', sessionId));
}
this[PRIVATE$6] = {
polyfill: polyfill,
devicePose: devicePose,
views: views,
session: session
};
}
createClass(XRFrame, [{
key: 'getDevicePose',
value: function getDevicePose(coordinateSystem) {
this[PRIVATE$6].devicePose.updateFromFrameOfReference(coordinateSystem);
return this[PRIVATE$6].devicePose;
}
}, {
key: 'getInputPose',
value: function getInputPose(inputSource, coordinateSystem) {
return this[PRIVATE$6].polyfill.getInputPose(inputSource, coordinateSystem);
}
}, {
key: 'session',
get: function get$$1() {
return this[PRIVATE$6].session;
}
}, {
key: 'views',
get: function get$$1() {
return this[PRIVATE$6].views;
}
}]);
return XRFrame;
}();
var PRIVATE$7 = Symbol('@@webxr-polyfill/XRStageBoundsPoint');
var XRStageBoundsPoint = function () {
function XRStageBoundsPoint(x, z) {
classCallCheck(this, XRStageBoundsPoint);
this[PRIVATE$7] = { x: x, z: z };
}
createClass(XRStageBoundsPoint, [{
key: 'x',
get: function get$$1() {
return this[PRIVATE$7].x;
}
}, {
key: 'z',
get: function get$$1() {
return this[PRIVATE$7].z;
}
}]);
return XRStageBoundsPoint;
}();
var PRIVATE$8 = Symbol('@@webxr-polyfill/XRStageBounds');
var XRStageBounds = function () {
function XRStageBounds(boundsData) {
classCallCheck(this, XRStageBounds);
var geometry = [];
for (var i = 0; i < boundsData.length; i += 2) {
geometry.push(new XRStageBoundsPoint(boundsData[i], boundsData[i + 1]));
}
this[PRIVATE$8] = { geometry: geometry };
}
createClass(XRStageBounds, [{
key: 'geometry',
get: function get$$1() {
return this[PRIVATE$8].geometry;
}
}]);
return XRStageBounds;
}();
var XRCoordinateSystem = function () {
function XRCoordinateSystem() {
classCallCheck(this, XRCoordinateSystem);
}
createClass(XRCoordinateSystem, [{
key: 'getTransformTo',
value: function getTransformTo(other) {
throw new Error('Not yet supported');
}
}]);
return XRCoordinateSystem;
}();
var DEFAULT_EMULATION_HEIGHT = 1.6;
var PRIVATE$9 = Symbol('@@webxr-polyfill/XRFrameOfReference');
var XRFrameOfReferenceTypes = ['head-model', 'eye-level', 'stage'];
var XRFrameOfReferenceOptions = Object.freeze({
disableStageEmulation: false,
stageEmulationHeight: 0
});
var XRFrameOfReference = function (_XRCoordinateSystem) {
inherits(XRFrameOfReference, _XRCoordinateSystem);
function XRFrameOfReference(polyfill, type, options, transform, bounds) {
classCallCheck(this, XRFrameOfReference);
options = Object.assign({}, XRFrameOfReferenceOptions, options);
if (!XRFrameOfReferenceTypes.includes(type)) {
throw new Error('XRFrameOfReferenceType must be one of ' + XRFrameOfReferenceTypes);
}
var _this = possibleConstructorReturn(this, (XRFrameOfReference.__proto__ || Object.getPrototypeOf(XRFrameOfReference)).call(this));
if (type === 'stage' && options.disableStageEmulation && !transform) {
throw new Error('XRFrameOfReference cannot use \'stage\' type, if disabling emulation and platform does not provide');
}
var _options = options,
disableStageEmulation = _options.disableStageEmulation,
stageEmulationHeight = _options.stageEmulationHeight;
var emulatedHeight = 0;
if (type === 'stage' && !transform) {
emulatedHeight = stageEmulationHeight !== 0 ? stageEmulationHeight : DEFAULT_EMULATION_HEIGHT;
}
if (type === 'stage' && !transform) {
transform = identity(new Float32Array(16));
transform[13] = emulatedHeight;
}
_this[PRIVATE$9] = {
disableStageEmulation: disableStageEmulation,
stageEmulationHeight: stageEmulationHeight,
emulatedHeight: emulatedHeight,
type: type,
transform: transform,
polyfill: polyfill,
bounds: bounds
};
_this.onboundschange = undefined;
return _this;
}
createClass(XRFrameOfReference, [{
key: 'transformBasePoseMatrix',
value: function transformBasePoseMatrix(out, pose) {
if (this[PRIVATE$9].transform) {
multiply(out, this[PRIVATE$9].transform, pose);
return;
}
switch (this.type) {
case 'head-model':
if (out !== pose) {
copy(out, pose);
}
out[12] = out[13] = out[14] = 0;
return;
case 'eye-level':
if (out !== pose) {
copy(out, pose);
}
return;
}
}
}, {
key: 'transformBaseViewMatrix',
value: function transformBaseViewMatrix(out, view) {
var frameOfRef = this[PRIVATE$9].transform;
if (frameOfRef) {
invert(out, frameOfRef);
multiply(out, view, out);
}
else if (this.type === 'head-model') {
invert(out, view);
out[12] = 0;
out[13] = 0;
out[14] = 0;
invert(out, out);
return out;
}
else {
copy(out, view);
}
return out;
}
}, {
key: 'bounds',
get: function get$$1() {
return this[PRIVATE$9].bounds;
}
}, {
key: 'emulatedHeight',
get: function get$$1() {
return this[PRIVATE$9].emulatedHeight;
}
}, {
key: 'type',
get: function get$$1() {
return this[PRIVATE$9].type;
}
}]);
return XRFrameOfReference;
}(XRCoordinateSystem);
var PRIVATE$10 = Symbol('@@webxr-polyfill/XRSession');
var XRSessionCreationOptions = Object.freeze({
immersive: false,
outputContext: undefined
});
var validateSessionOptions = function validateSessionOptions(options) {
var immersive = options.immersive,
outputContext = options.outputContext;
if (!immersive && !outputContext) {
return false;
}
if (outputContext !== undefined && !(outputContext instanceof XRPresentationContext)) {
return false;
}
return true;
};
var XRSession = function (_EventTarget) {
inherits(XRSession, _EventTarget);
function XRSession(polyfill, device, sessionOptions, id) {
classCallCheck(this, XRSession);
sessionOptions = Object.assign({}, XRSessionCreationOptions, sessionOptions);
var _this = possibleConstructorReturn(this, (XRSession.__proto__ || Object.getPrototypeOf(XRSession)).call(this));
var _sessionOptions = sessionOptions,
immersive = _sessionOptions.immersive,
outputContext = _sessionOptions.outputContext;
_this[PRIVATE$10] = {
polyfill: polyfill,
device: device,
immersive: immersive,
outputContext: outputContext,
ended: false,
suspended: false,
suspendedCallback: null,
id: id
};
var frame = new XRFrame(polyfill, _this, _this[PRIVATE$10].id);
_this[PRIVATE$10].frame = frame;
_this[PRIVATE$10].onPresentationEnd = function (sessionId) {
if (sessionId !== _this[PRIVATE$10].id) {
_this[PRIVATE$10].suspended = false;
_this.dispatchEvent('focus', { session: _this });
var suspendedCallback = _this[PRIVATE$10].suspendedCallback;
_this[PRIVATE$10].suspendedCallback = null;
if (suspendedCallback) {
_this.requestAnimationFrame(suspendedCallback);
}
return;
}
_this[PRIVATE$10].ended = true;
polyfill.removeEventListener('@webvr-polyfill/vr-present-end', _this[PRIVATE$10].onPresentationEnd);
polyfill.removeEventListener('@webvr-polyfill/vr-present-start', _this[PRIVATE$10].onPresentationStart);
polyfill.removeEventListener('@@webvr-polyfill/input-select-start', _this[PRIVATE$10].onSelectStart);
polyfill.removeEventListener('@@webvr-polyfill/input-select-end', _this[PRIVATE$10].onSelectEnd);
_this.dispatchEvent('end', { session: _this });
};
polyfill.addEventListener('@@webxr-polyfill/vr-present-end', _this[PRIVATE$10].onPresentationEnd);
_this[PRIVATE$10].onPresentationStart = function (sessionId) {
if (sessionId === _this[PRIVATE$10].id) {
return;
}
_this[PRIVATE$10].suspended = true;
_this.dispatchEvent('blur', { session: _this });
};
polyfill.addEventListener('@@webxr-polyfill/vr-present-start', _this[PRIVATE$10].onPresentationStart);
_this[PRIVATE$10].onSelectStart = function (evt) {
if (evt.sessionId !== _this[PRIVATE$10].id) {
return;
}
_this.dispatchEvent('selectstart', {
frame: _this[PRIVATE$10].frame,
inputSource: evt.inputSource
});
};
polyfill.addEventListener('@@webxr-polyfill/input-select-start', _this[PRIVATE$10].onSelectStart);
_this[PRIVATE$10].onSelectEnd = function (evt) {
if (evt.sessionId !== _this[PRIVATE$10].id) {
return;
}
_this.dispatchEvent('selectend', {
frame: _this[PRIVATE$10].frame,
inputSource: evt.inputSource
});
_this.dispatchEvent('select', {
frame: _this[PRIVATE$10].frame,
inputSource: evt.inputSource
});
};
polyfill.addEventListener('@@webxr-polyfill/input-select-end', _this[PRIVATE$10].onSelectEnd);
_this.onblur = undefined;
_this.onfocus = undefined;
_this.onresetpose = undefined;
_this.onend = undefined;
_this.onselect = undefined;
_this.onselectstart = undefined;
_this.onselectend = undefined;
return _this;
}
createClass(XRSession, [{
key: 'requestFrameOfReference',
value: function requestFrameOfReference(type) {
var $args = arguments;return new Promise(function ($return, $error) {
var options, transform, bounds;
options = $args.length > 1 && $args[1] !== undefined ? $args[1] : {};
if (this[PRIVATE$10].ended) {