iwer 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/iwer.js +412 -1291
- package/build/iwer.min.js +52 -11
- package/build/iwer.module.js +412 -1291
- package/build/iwer.module.min.js +52 -11
- package/lib/action/ActionPlayer.d.ts.map +1 -1
- package/lib/action/ActionPlayer.js.map +1 -1
- package/lib/action/ActionRecorder.d.ts.map +1 -1
- package/lib/action/ActionRecorder.js +1 -1
- package/lib/action/ActionRecorder.js.map +1 -1
- package/lib/anchors/XRAnchor.d.ts.map +1 -1
- package/lib/anchors/XRAnchor.js.map +1 -1
- package/lib/device/XRController.d.ts.map +1 -1
- package/lib/device/XRController.js.map +1 -1
- package/lib/device/XRDevice.d.ts +1 -1
- package/lib/device/XRDevice.d.ts.map +1 -1
- package/lib/device/XRDevice.js +8 -3
- package/lib/device/XRDevice.js.map +1 -1
- package/lib/device/XRHandInput.d.ts.map +1 -1
- package/lib/device/XRHandInput.js.map +1 -1
- package/lib/device/XRTrackedInput.d.ts.map +1 -1
- package/lib/device/XRTrackedInput.js.map +1 -1
- package/lib/device/configs/controller/meta.js.map +1 -1
- package/lib/device/configs/hand/pinch.js.map +1 -1
- package/lib/device/configs/hand/point.js.map +1 -1
- package/lib/device/configs/hand/relaxed.js.map +1 -1
- package/lib/device/configs/headset/meta.js.map +1 -1
- package/lib/events/XRInputSourceEvent.d.ts.map +1 -1
- package/lib/events/XRInputSourceEvent.js.map +1 -1
- package/lib/events/XRInputSourcesChangeEvent.d.ts.map +1 -1
- package/lib/events/XRInputSourcesChangeEvent.js.map +1 -1
- package/lib/events/XRReferenceSpaceEvent.d.ts.map +1 -1
- package/lib/events/XRReferenceSpaceEvent.js.map +1 -1
- package/lib/events/XRSessionEvent.d.ts.map +1 -1
- package/lib/events/XRSessionEvent.js.map +1 -1
- package/lib/frameloop/XRFrame.d.ts.map +1 -1
- package/lib/frameloop/XRFrame.js.map +1 -1
- package/lib/gamepad/Gamepad.d.ts.map +1 -1
- package/lib/gamepad/Gamepad.js.map +1 -1
- package/lib/hittest/XRHitTest.d.ts.map +1 -1
- package/lib/hittest/XRHitTest.js.map +1 -1
- package/lib/hittest/XRRay.d.ts.map +1 -1
- package/lib/hittest/XRRay.js.map +1 -1
- package/lib/initialization/XRSystem.d.ts.map +1 -1
- package/lib/initialization/XRSystem.js.map +1 -1
- package/lib/input/XRHand.d.ts.map +1 -1
- package/lib/input/XRHand.js.map +1 -1
- package/lib/input/XRInputSource.d.ts.map +1 -1
- package/lib/input/XRInputSource.js.map +1 -1
- package/lib/labels/labels.d.ts.map +1 -1
- package/lib/labels/labels.js.map +1 -1
- package/lib/layers/XRWebGLLayer.d.ts.map +1 -1
- package/lib/layers/XRWebGLLayer.js.map +1 -1
- package/lib/meshes/XRMesh.d.ts.map +1 -1
- package/lib/meshes/XRMesh.js.map +1 -1
- package/lib/planes/XRPlane.d.ts.map +1 -1
- package/lib/planes/XRPlane.js.map +1 -1
- package/lib/pose/XRJointPose.d.ts.map +1 -1
- package/lib/pose/XRJointPose.js.map +1 -1
- package/lib/pose/XRPose.d.ts.map +1 -1
- package/lib/pose/XRPose.js.map +1 -1
- package/lib/pose/XRViewerPose.d.ts.map +1 -1
- package/lib/pose/XRViewerPose.js.map +1 -1
- package/lib/primitives/XRRigidTransform.d.ts.map +1 -1
- package/lib/primitives/XRRigidTransform.js.map +1 -1
- package/lib/session/XRRenderState.d.ts.map +1 -1
- package/lib/session/XRRenderState.js.map +1 -1
- package/lib/session/XRSession.d.ts.map +1 -1
- package/lib/session/XRSession.js.map +1 -1
- package/lib/spaces/XRJointSpace.d.ts.map +1 -1
- package/lib/spaces/XRJointSpace.js.map +1 -1
- package/lib/spaces/XRReferenceSpace.d.ts.map +1 -1
- package/lib/spaces/XRReferenceSpace.js.map +1 -1
- package/lib/spaces/XRSpace.d.ts.map +1 -1
- package/lib/spaces/XRSpace.js.map +1 -1
- package/lib/utils/Math.d.ts.map +1 -1
- package/lib/utils/Math.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/views/XRView.d.ts.map +1 -1
- package/lib/views/XRView.js.map +1 -1
- package/lib/views/XRViewport.d.ts.map +1 -1
- package/lib/views/XRViewport.js.map +1 -1
- package/package.json +61 -61
package/build/iwer.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
// Configuration Constants
|
|
13
13
|
var EPSILON = 0.000001;
|
|
14
|
-
var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
|
|
14
|
+
var ARRAY_TYPE$1 = typeof Float32Array !== "undefined" ? Float32Array : Array;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* 3x3 Matrix
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
*
|
|
24
24
|
* @returns {mat3} a new 3x3 matrix
|
|
25
25
|
*/
|
|
26
|
-
function create$
|
|
27
|
-
var out = new ARRAY_TYPE(9);
|
|
28
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
26
|
+
function create$6() {
|
|
27
|
+
var out = new ARRAY_TYPE$1(9);
|
|
28
|
+
if (ARRAY_TYPE$1 != Float32Array) {
|
|
29
29
|
out[1] = 0;
|
|
30
30
|
out[2] = 0;
|
|
31
31
|
out[3] = 0;
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
*
|
|
50
50
|
* @returns {mat4} a new 4x4 matrix
|
|
51
51
|
*/
|
|
52
|
-
function create$
|
|
53
|
-
var out = new ARRAY_TYPE(16);
|
|
54
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
52
|
+
function create$5() {
|
|
53
|
+
var out = new ARRAY_TYPE$1(16);
|
|
54
|
+
if (ARRAY_TYPE$1 != Float32Array) {
|
|
55
55
|
out[1] = 0;
|
|
56
56
|
out[2] = 0;
|
|
57
57
|
out[3] = 0;
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
* @returns {mat4} a new 4x4 matrix
|
|
80
80
|
*/
|
|
81
81
|
function clone(a) {
|
|
82
|
-
var out = new ARRAY_TYPE(16);
|
|
82
|
+
var out = new ARRAY_TYPE$1(16);
|
|
83
83
|
out[0] = a[0];
|
|
84
84
|
out[1] = a[1];
|
|
85
85
|
out[2] = a[2];
|
|
@@ -222,7 +222,7 @@
|
|
|
222
222
|
* @param {ReadonlyMat4} b the second operand
|
|
223
223
|
* @returns {mat4} out
|
|
224
224
|
*/
|
|
225
|
-
function multiply$
|
|
225
|
+
function multiply$2(out, a, b) {
|
|
226
226
|
var a00 = a[0],
|
|
227
227
|
a01 = a[1],
|
|
228
228
|
a02 = a[2],
|
|
@@ -460,7 +460,7 @@
|
|
|
460
460
|
* @return {quat} out
|
|
461
461
|
*/
|
|
462
462
|
function getRotation(out, mat) {
|
|
463
|
-
var scaling = new ARRAY_TYPE(3);
|
|
463
|
+
var scaling = new ARRAY_TYPE$1(3);
|
|
464
464
|
getScaling(scaling, mat);
|
|
465
465
|
var is1 = 1 / scaling[0];
|
|
466
466
|
var is2 = 1 / scaling[1];
|
|
@@ -561,50 +561,6 @@
|
|
|
561
561
|
return out;
|
|
562
562
|
}
|
|
563
563
|
|
|
564
|
-
/**
|
|
565
|
-
* Calculates a 4x4 matrix from the given quaternion
|
|
566
|
-
*
|
|
567
|
-
* @param {mat4} out mat4 receiving operation result
|
|
568
|
-
* @param {ReadonlyQuat} q Quaternion to create matrix from
|
|
569
|
-
*
|
|
570
|
-
* @returns {mat4} out
|
|
571
|
-
*/
|
|
572
|
-
function fromQuat(out, q) {
|
|
573
|
-
var x = q[0],
|
|
574
|
-
y = q[1],
|
|
575
|
-
z = q[2],
|
|
576
|
-
w = q[3];
|
|
577
|
-
var x2 = x + x;
|
|
578
|
-
var y2 = y + y;
|
|
579
|
-
var z2 = z + z;
|
|
580
|
-
var xx = x * x2;
|
|
581
|
-
var yx = y * x2;
|
|
582
|
-
var yy = y * y2;
|
|
583
|
-
var zx = z * x2;
|
|
584
|
-
var zy = z * y2;
|
|
585
|
-
var zz = z * z2;
|
|
586
|
-
var wx = w * x2;
|
|
587
|
-
var wy = w * y2;
|
|
588
|
-
var wz = w * z2;
|
|
589
|
-
out[0] = 1 - yy - zz;
|
|
590
|
-
out[1] = yx + wz;
|
|
591
|
-
out[2] = zx - wy;
|
|
592
|
-
out[3] = 0;
|
|
593
|
-
out[4] = yx - wz;
|
|
594
|
-
out[5] = 1 - xx - zz;
|
|
595
|
-
out[6] = zy + wx;
|
|
596
|
-
out[7] = 0;
|
|
597
|
-
out[8] = zx + wy;
|
|
598
|
-
out[9] = zy - wx;
|
|
599
|
-
out[10] = 1 - xx - yy;
|
|
600
|
-
out[11] = 0;
|
|
601
|
-
out[12] = 0;
|
|
602
|
-
out[13] = 0;
|
|
603
|
-
out[14] = 0;
|
|
604
|
-
out[15] = 1;
|
|
605
|
-
return out;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
564
|
/**
|
|
609
565
|
* Generates a perspective projection matrix with the given bounds.
|
|
610
566
|
* The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
|
|
@@ -661,9 +617,9 @@
|
|
|
661
617
|
*
|
|
662
618
|
* @returns {vec3} a new 3D vector
|
|
663
619
|
*/
|
|
664
|
-
function create$
|
|
665
|
-
var out = new ARRAY_TYPE(3);
|
|
666
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
620
|
+
function create$4() {
|
|
621
|
+
var out = new ARRAY_TYPE$1(3);
|
|
622
|
+
if (ARRAY_TYPE$1 != Float32Array) {
|
|
667
623
|
out[0] = 0;
|
|
668
624
|
out[1] = 0;
|
|
669
625
|
out[2] = 0;
|
|
@@ -693,7 +649,7 @@
|
|
|
693
649
|
* @returns {vec3} a new 3D vector
|
|
694
650
|
*/
|
|
695
651
|
function fromValues$2(x, y, z) {
|
|
696
|
-
var out = new ARRAY_TYPE(3);
|
|
652
|
+
var out = new ARRAY_TYPE$1(3);
|
|
697
653
|
out[0] = x;
|
|
698
654
|
out[1] = y;
|
|
699
655
|
out[2] = z;
|
|
@@ -875,7 +831,7 @@
|
|
|
875
831
|
* @function
|
|
876
832
|
*/
|
|
877
833
|
(function () {
|
|
878
|
-
var vec = create$
|
|
834
|
+
var vec = create$4();
|
|
879
835
|
return function (a, stride, offset, count, fn, arg) {
|
|
880
836
|
var i, l;
|
|
881
837
|
if (!stride) {
|
|
@@ -912,9 +868,9 @@
|
|
|
912
868
|
*
|
|
913
869
|
* @returns {vec4} a new 4D vector
|
|
914
870
|
*/
|
|
915
|
-
function create$
|
|
916
|
-
var out = new ARRAY_TYPE(4);
|
|
917
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
871
|
+
function create$3() {
|
|
872
|
+
var out = new ARRAY_TYPE$1(4);
|
|
873
|
+
if (ARRAY_TYPE$1 != Float32Array) {
|
|
918
874
|
out[0] = 0;
|
|
919
875
|
out[1] = 0;
|
|
920
876
|
out[2] = 0;
|
|
@@ -933,7 +889,7 @@
|
|
|
933
889
|
* @returns {vec4} a new 4D vector
|
|
934
890
|
*/
|
|
935
891
|
function fromValues$1(x, y, z, w) {
|
|
936
|
-
var out = new ARRAY_TYPE(4);
|
|
892
|
+
var out = new ARRAY_TYPE$1(4);
|
|
937
893
|
out[0] = x;
|
|
938
894
|
out[1] = y;
|
|
939
895
|
out[2] = z;
|
|
@@ -1030,7 +986,7 @@
|
|
|
1030
986
|
* @function
|
|
1031
987
|
*/
|
|
1032
988
|
(function () {
|
|
1033
|
-
var vec = create$
|
|
989
|
+
var vec = create$3();
|
|
1034
990
|
return function (a, stride, offset, count, fn, arg) {
|
|
1035
991
|
var i, l;
|
|
1036
992
|
if (!stride) {
|
|
@@ -1069,9 +1025,9 @@
|
|
|
1069
1025
|
*
|
|
1070
1026
|
* @returns {quat} a new quaternion
|
|
1071
1027
|
*/
|
|
1072
|
-
function create$
|
|
1073
|
-
var out = new ARRAY_TYPE(4);
|
|
1074
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
1028
|
+
function create$2() {
|
|
1029
|
+
var out = new ARRAY_TYPE$1(4);
|
|
1030
|
+
if (ARRAY_TYPE$1 != Float32Array) {
|
|
1075
1031
|
out[0] = 0;
|
|
1076
1032
|
out[1] = 0;
|
|
1077
1033
|
out[2] = 0;
|
|
@@ -1107,7 +1063,7 @@
|
|
|
1107
1063
|
* @param {ReadonlyQuat} b the second operand
|
|
1108
1064
|
* @returns {quat} out
|
|
1109
1065
|
*/
|
|
1110
|
-
function multiply(out, a, b) {
|
|
1066
|
+
function multiply$1(out, a, b) {
|
|
1111
1067
|
var ax = a[0],
|
|
1112
1068
|
ay = a[1],
|
|
1113
1069
|
az = a[2],
|
|
@@ -1290,7 +1246,7 @@
|
|
|
1290
1246
|
* @returns {quat} out
|
|
1291
1247
|
*/
|
|
1292
1248
|
(function () {
|
|
1293
|
-
var tmpvec3 = create$
|
|
1249
|
+
var tmpvec3 = create$4();
|
|
1294
1250
|
var xUnitVec3 = fromValues$2(1, 0, 0);
|
|
1295
1251
|
var yUnitVec3 = fromValues$2(0, 1, 0);
|
|
1296
1252
|
return function (out, a, b) {
|
|
@@ -1330,8 +1286,8 @@
|
|
|
1330
1286
|
* @returns {quat} out
|
|
1331
1287
|
*/
|
|
1332
1288
|
(function () {
|
|
1333
|
-
var temp1 = create$
|
|
1334
|
-
var temp2 = create$
|
|
1289
|
+
var temp1 = create$2();
|
|
1290
|
+
var temp2 = create$2();
|
|
1335
1291
|
return function (out, a, b, c, d, t) {
|
|
1336
1292
|
slerp(temp1, a, d, t);
|
|
1337
1293
|
slerp(temp2, b, c, t);
|
|
@@ -1351,7 +1307,7 @@
|
|
|
1351
1307
|
* @returns {quat} out
|
|
1352
1308
|
*/
|
|
1353
1309
|
(function () {
|
|
1354
|
-
var matr = create$
|
|
1310
|
+
var matr = create$6();
|
|
1355
1311
|
return function (out, view, right, up) {
|
|
1356
1312
|
matr[0] = right[0];
|
|
1357
1313
|
matr[3] = right[1];
|
|
@@ -1366,63 +1322,6 @@
|
|
|
1366
1322
|
};
|
|
1367
1323
|
})();
|
|
1368
1324
|
|
|
1369
|
-
/**
|
|
1370
|
-
* 2 Dimensional Vector
|
|
1371
|
-
* @module vec2
|
|
1372
|
-
*/
|
|
1373
|
-
|
|
1374
|
-
/**
|
|
1375
|
-
* Creates a new, empty vec2
|
|
1376
|
-
*
|
|
1377
|
-
* @returns {vec2} a new 2D vector
|
|
1378
|
-
*/
|
|
1379
|
-
function create() {
|
|
1380
|
-
var out = new ARRAY_TYPE(2);
|
|
1381
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
1382
|
-
out[0] = 0;
|
|
1383
|
-
out[1] = 0;
|
|
1384
|
-
}
|
|
1385
|
-
return out;
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
/**
|
|
1389
|
-
* Perform some operation over an array of vec2s.
|
|
1390
|
-
*
|
|
1391
|
-
* @param {Array} a the array of vectors to iterate over
|
|
1392
|
-
* @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
|
|
1393
|
-
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
1394
|
-
* @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
|
|
1395
|
-
* @param {Function} fn Function to call for each vector in the array
|
|
1396
|
-
* @param {Object} [arg] additional argument to pass to fn
|
|
1397
|
-
* @returns {Array} a
|
|
1398
|
-
* @function
|
|
1399
|
-
*/
|
|
1400
|
-
(function () {
|
|
1401
|
-
var vec = create();
|
|
1402
|
-
return function (a, stride, offset, count, fn, arg) {
|
|
1403
|
-
var i, l;
|
|
1404
|
-
if (!stride) {
|
|
1405
|
-
stride = 2;
|
|
1406
|
-
}
|
|
1407
|
-
if (!offset) {
|
|
1408
|
-
offset = 0;
|
|
1409
|
-
}
|
|
1410
|
-
if (count) {
|
|
1411
|
-
l = Math.min(count * stride + offset, a.length);
|
|
1412
|
-
} else {
|
|
1413
|
-
l = a.length;
|
|
1414
|
-
}
|
|
1415
|
-
for (i = offset; i < l; i += stride) {
|
|
1416
|
-
vec[0] = a[i];
|
|
1417
|
-
vec[1] = a[i + 1];
|
|
1418
|
-
fn(vec, vec, arg);
|
|
1419
|
-
a[i] = vec[0];
|
|
1420
|
-
a[i + 1] = vec[1];
|
|
1421
|
-
}
|
|
1422
|
-
return a;
|
|
1423
|
-
};
|
|
1424
|
-
})();
|
|
1425
|
-
|
|
1426
1325
|
/**
|
|
1427
1326
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1428
1327
|
*
|
|
@@ -1468,14 +1367,14 @@
|
|
|
1468
1367
|
super();
|
|
1469
1368
|
this[P_SPACE] = {
|
|
1470
1369
|
parentSpace,
|
|
1471
|
-
offsetMatrix: offsetMatrix ? clone(offsetMatrix) : create$
|
|
1370
|
+
offsetMatrix: offsetMatrix ? clone(offsetMatrix) : create$5(),
|
|
1472
1371
|
emulated: true,
|
|
1473
1372
|
};
|
|
1474
1373
|
}
|
|
1475
1374
|
}
|
|
1476
1375
|
class GlobalSpace extends XRSpace {
|
|
1477
1376
|
constructor() {
|
|
1478
|
-
super(undefined, create$
|
|
1377
|
+
super(undefined, create$5()); // GlobalSpace has no parent
|
|
1479
1378
|
}
|
|
1480
1379
|
}
|
|
1481
1380
|
class XRSpaceUtils {
|
|
@@ -1487,7 +1386,7 @@
|
|
|
1487
1386
|
// Update the rotation component of the offsetMatrix of a given XRSpace using a quaternion
|
|
1488
1387
|
static updateOffsetQuaternion(space, quaternion) {
|
|
1489
1388
|
const offsetMatrix = space[P_SPACE].offsetMatrix;
|
|
1490
|
-
const translation = create$
|
|
1389
|
+
const translation = create$4();
|
|
1491
1390
|
getTranslation(translation, offsetMatrix);
|
|
1492
1391
|
fromRotationTranslation(offsetMatrix, quaternion, translation);
|
|
1493
1392
|
}
|
|
@@ -1497,11 +1396,11 @@
|
|
|
1497
1396
|
copy$3(offsetMatrix, matrix);
|
|
1498
1397
|
}
|
|
1499
1398
|
// Calculate the global offset matrix for a given XRSpace
|
|
1500
|
-
static calculateGlobalOffsetMatrix(space, globalOffset = create$
|
|
1399
|
+
static calculateGlobalOffsetMatrix(space, globalOffset = create$5()) {
|
|
1501
1400
|
const parentOffset = space[P_SPACE].parentSpace
|
|
1502
1401
|
? XRSpaceUtils.calculateGlobalOffsetMatrix(space[P_SPACE].parentSpace)
|
|
1503
|
-
: create$
|
|
1504
|
-
multiply$
|
|
1402
|
+
: create$5(); // Identity matrix for GlobalSpace
|
|
1403
|
+
multiply$2(globalOffset, parentOffset, space[P_SPACE].offsetMatrix);
|
|
1505
1404
|
return globalOffset;
|
|
1506
1405
|
}
|
|
1507
1406
|
}
|
|
@@ -1519,7 +1418,7 @@
|
|
|
1519
1418
|
class Vector3 {
|
|
1520
1419
|
constructor(x = 0, y = 0, z = 0) {
|
|
1521
1420
|
this.vec3 = fromValues$2(x, y, z);
|
|
1522
|
-
this.tempVec3 = create$
|
|
1421
|
+
this.tempVec3 = create$4();
|
|
1523
1422
|
}
|
|
1524
1423
|
get x() {
|
|
1525
1424
|
return this.vec3[0];
|
|
@@ -1581,7 +1480,7 @@
|
|
|
1581
1480
|
class Quaternion {
|
|
1582
1481
|
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
1583
1482
|
this.quat = fromValues(x, y, z, w);
|
|
1584
|
-
this.tempQuat = create$
|
|
1483
|
+
this.tempQuat = create$2();
|
|
1585
1484
|
}
|
|
1586
1485
|
get x() {
|
|
1587
1486
|
return this.quat[0];
|
|
@@ -1630,7 +1529,7 @@
|
|
|
1630
1529
|
}
|
|
1631
1530
|
multiply(q) {
|
|
1632
1531
|
copy(this.tempQuat, this.quat);
|
|
1633
|
-
multiply(this.quat, this.tempQuat, q.quat);
|
|
1532
|
+
multiply$1(this.quat, this.tempQuat, q.quat);
|
|
1634
1533
|
return this;
|
|
1635
1534
|
}
|
|
1636
1535
|
setFromAxisAngle(axis, angle) {
|
|
@@ -2256,14 +2155,14 @@
|
|
|
2256
2155
|
constructor(position, orientation) {
|
|
2257
2156
|
// Default values
|
|
2258
2157
|
const defaultPosition = fromValues$2(0, 0, 0);
|
|
2259
|
-
const defaultOrientation = create$
|
|
2158
|
+
const defaultOrientation = create$2();
|
|
2260
2159
|
this[P_RIGID_TRANSFORM] = {
|
|
2261
|
-
matrix: create$
|
|
2160
|
+
matrix: create$5(),
|
|
2262
2161
|
position: position
|
|
2263
2162
|
? fromValues$2(position.x, position.y, position.z)
|
|
2264
2163
|
: defaultPosition,
|
|
2265
2164
|
orientation: orientation
|
|
2266
|
-
? normalize(create$
|
|
2165
|
+
? normalize(create$2(), fromValues(orientation.x, orientation.y, orientation.z, orientation.w))
|
|
2267
2166
|
: defaultOrientation,
|
|
2268
2167
|
inverse: null,
|
|
2269
2168
|
};
|
|
@@ -2285,14 +2184,14 @@
|
|
|
2285
2184
|
}
|
|
2286
2185
|
get inverse() {
|
|
2287
2186
|
if (!this[P_RIGID_TRANSFORM].inverse) {
|
|
2288
|
-
const invMatrix = create$
|
|
2187
|
+
const invMatrix = create$5();
|
|
2289
2188
|
if (!invert(invMatrix, this[P_RIGID_TRANSFORM].matrix)) {
|
|
2290
2189
|
throw new Error('Matrix is not invertible.');
|
|
2291
2190
|
}
|
|
2292
2191
|
// Decomposing the inverse matrix into position and orientation
|
|
2293
|
-
let invPosition = create$
|
|
2192
|
+
let invPosition = create$4();
|
|
2294
2193
|
getTranslation(invPosition, invMatrix);
|
|
2295
|
-
let invOrientation = create$
|
|
2194
|
+
let invOrientation = create$2();
|
|
2296
2195
|
getRotation(invOrientation, invMatrix);
|
|
2297
2196
|
// Creating a new XRRigidTransform for the inverse
|
|
2298
2197
|
this[P_RIGID_TRANSFORM].inverse = new XRRigidTransform(new DOMPointReadOnly(invPosition[0], invPosition[1], invPosition[2], 1), new DOMPointReadOnly(invOrientation[0], invOrientation[1], invOrientation[2], invOrientation[3]));
|
|
@@ -2318,8 +2217,8 @@
|
|
|
2318
2217
|
if (origin instanceof XRRigidTransform) {
|
|
2319
2218
|
const transform = origin;
|
|
2320
2219
|
const matrix = transform.matrix;
|
|
2321
|
-
const originVec4 = set$1(create$
|
|
2322
|
-
const directionVec4 = set$1(create$
|
|
2220
|
+
const originVec4 = set$1(create$3(), _origin.x, _origin.y, _origin.z, _origin.w);
|
|
2221
|
+
const directionVec4 = set$1(create$3(), _direction.x, _direction.y, _direction.z, _direction.w);
|
|
2323
2222
|
transformMat4(originVec4, originVec4, matrix);
|
|
2324
2223
|
transformMat4(directionVec4, directionVec4, matrix);
|
|
2325
2224
|
_origin.x = originVec4[0];
|
|
@@ -2371,23 +2270,23 @@
|
|
|
2371
2270
|
if (this[P_RAY].matrix) {
|
|
2372
2271
|
return this[P_RAY].matrix;
|
|
2373
2272
|
}
|
|
2374
|
-
const z = set$2(create$
|
|
2375
|
-
const origin = set$2(create$
|
|
2376
|
-
const direction = set$2(create$
|
|
2377
|
-
const axis = cross(create$
|
|
2273
|
+
const z = set$2(create$4(), 0, 0, -1);
|
|
2274
|
+
const origin = set$2(create$4(), this[P_RAY].origin.x, this[P_RAY].origin.y, this[P_RAY].origin.z);
|
|
2275
|
+
const direction = set$2(create$4(), this[P_RAY].direction.x, this[P_RAY].direction.y, this[P_RAY].direction.z);
|
|
2276
|
+
const axis = cross(create$4(), direction, z);
|
|
2378
2277
|
const cosAngle = dot(direction, z);
|
|
2379
|
-
const rotation = create$
|
|
2278
|
+
const rotation = create$5();
|
|
2380
2279
|
if (cosAngle > -1 && cosAngle < 1) {
|
|
2381
2280
|
fromRotation(rotation, Math.acos(cosAngle), axis);
|
|
2382
2281
|
}
|
|
2383
2282
|
else if (cosAngle === -1) {
|
|
2384
|
-
fromRotation(rotation, Math.acos(cosAngle), set$2(create$
|
|
2283
|
+
fromRotation(rotation, Math.acos(cosAngle), set$2(create$4(), 1, 0, 0));
|
|
2385
2284
|
}
|
|
2386
2285
|
else {
|
|
2387
2286
|
identity(rotation);
|
|
2388
2287
|
}
|
|
2389
|
-
const translation = fromTranslation(create$
|
|
2390
|
-
const matrix = multiply$
|
|
2288
|
+
const translation = fromTranslation(create$5(), origin);
|
|
2289
|
+
const matrix = multiply$2(create$5(), translation, rotation);
|
|
2391
2290
|
this[P_RAY].matrix = new Float32Array(matrix);
|
|
2392
2291
|
return this[P_RAY].matrix;
|
|
2393
2292
|
}
|
|
@@ -2654,14 +2553,14 @@
|
|
|
2654
2553
|
* This source code is licensed under the MIT license found in the
|
|
2655
2554
|
* LICENSE file in the root directory of this source tree.
|
|
2656
2555
|
*/
|
|
2657
|
-
const spaceGlobalMatrix = create$
|
|
2658
|
-
const baseSpaceGlobalMatrix = create$
|
|
2659
|
-
const baseSpaceGlobalMatrixInverse = create$
|
|
2556
|
+
const spaceGlobalMatrix = create$5();
|
|
2557
|
+
const baseSpaceGlobalMatrix = create$5();
|
|
2558
|
+
const baseSpaceGlobalMatrixInverse = create$5();
|
|
2660
2559
|
const getOffsetMatrix = (offsetMatrix, space, baseSpace) => {
|
|
2661
2560
|
XRSpaceUtils.calculateGlobalOffsetMatrix(space, spaceGlobalMatrix);
|
|
2662
2561
|
XRSpaceUtils.calculateGlobalOffsetMatrix(baseSpace, baseSpaceGlobalMatrix);
|
|
2663
2562
|
invert(baseSpaceGlobalMatrixInverse, baseSpaceGlobalMatrix);
|
|
2664
|
-
multiply$
|
|
2563
|
+
multiply$2(offsetMatrix, baseSpaceGlobalMatrixInverse, spaceGlobalMatrix);
|
|
2665
2564
|
};
|
|
2666
2565
|
class XRFrame {
|
|
2667
2566
|
constructor(session, id, active, animationFrame, predictedDisplayTime) {
|
|
@@ -2671,7 +2570,7 @@
|
|
|
2671
2570
|
active,
|
|
2672
2571
|
animationFrame,
|
|
2673
2572
|
predictedDisplayTime,
|
|
2674
|
-
tempMat4: create$
|
|
2573
|
+
tempMat4: create$5(),
|
|
2675
2574
|
detectedPlanes: new XRPlaneSet(),
|
|
2676
2575
|
detectedMeshes: new XRMeshSet(),
|
|
2677
2576
|
trackedAnchors: session[P_SESSION].frameTrackedAnchors,
|
|
@@ -2689,9 +2588,9 @@
|
|
|
2689
2588
|
throw new DOMException('XRFrame access outside the callback that produced it is invalid.', 'InvalidStateError');
|
|
2690
2589
|
}
|
|
2691
2590
|
getOffsetMatrix(this[P_FRAME].tempMat4, space, baseSpace);
|
|
2692
|
-
const position = create$
|
|
2591
|
+
const position = create$4();
|
|
2693
2592
|
getTranslation(position, this[P_FRAME].tempMat4);
|
|
2694
|
-
const orientation = create$
|
|
2593
|
+
const orientation = create$2();
|
|
2695
2594
|
getRotation(orientation, this[P_FRAME].tempMat4);
|
|
2696
2595
|
return new XRPose(new XRRigidTransform({ x: position[0], y: position[1], z: position[2], w: 1.0 }, {
|
|
2697
2596
|
x: orientation[0],
|
|
@@ -2842,9 +2741,9 @@
|
|
|
2842
2741
|
isSystemKeyboardSupported: false,
|
|
2843
2742
|
ended: false,
|
|
2844
2743
|
projectionMatrices: {
|
|
2845
|
-
[XREye.Left]: create$
|
|
2846
|
-
[XREye.Right]: create$
|
|
2847
|
-
[XREye.None]: create$
|
|
2744
|
+
[XREye.Left]: create$5(),
|
|
2745
|
+
[XREye.Right]: create$5(),
|
|
2746
|
+
[XREye.None]: create$5(),
|
|
2848
2747
|
},
|
|
2849
2748
|
getProjectionMatrix: (eye) => {
|
|
2850
2749
|
return this[P_SESSION].projectionMatrices[eye];
|
|
@@ -3093,8 +2992,8 @@
|
|
|
3093
2992
|
const sourceSpace = hitTestSource[P_HIT_TEST].space;
|
|
3094
2993
|
const sourceGlobalOffset = XRSpaceUtils.calculateGlobalOffsetMatrix(sourceSpace);
|
|
3095
2994
|
const rayLocalOffset = hitTestSource[P_HIT_TEST].offsetRay.matrix;
|
|
3096
|
-
const rayGlobalOffset = create$
|
|
3097
|
-
multiply$
|
|
2995
|
+
const rayGlobalOffset = create$5();
|
|
2996
|
+
multiply$2(rayGlobalOffset, sourceGlobalOffset, rayLocalOffset);
|
|
3098
2997
|
const hitTestResults = [];
|
|
3099
2998
|
sem.computeHitTestResults(rayGlobalOffset).forEach((matrix) => {
|
|
3100
2999
|
const offsetSpace = new XRSpace(globalSpace, matrix);
|
|
@@ -4266,15 +4165,15 @@
|
|
|
4266
4165
|
buttons: [{ id: 'pinch', type: 'analog', eventTrigger: 'select' }],
|
|
4267
4166
|
axes: [],
|
|
4268
4167
|
};
|
|
4269
|
-
const fromPosition = create$
|
|
4270
|
-
const fromQuaternion = create$
|
|
4271
|
-
const fromScale = create$
|
|
4272
|
-
const toPosition = create$
|
|
4273
|
-
const toQuaternion = create$
|
|
4274
|
-
const toScale = create$
|
|
4275
|
-
const interpolatedPosition = create$
|
|
4276
|
-
const interpolatedQuaternion = create$
|
|
4277
|
-
const interpolatedScale = create$
|
|
4168
|
+
const fromPosition = create$4();
|
|
4169
|
+
const fromQuaternion = create$2();
|
|
4170
|
+
const fromScale = create$4();
|
|
4171
|
+
const toPosition = create$4();
|
|
4172
|
+
const toQuaternion = create$2();
|
|
4173
|
+
const toScale = create$4();
|
|
4174
|
+
const interpolatedPosition = create$4();
|
|
4175
|
+
const interpolatedQuaternion = create$2();
|
|
4176
|
+
const interpolatedScale = create$4();
|
|
4278
4177
|
const interpolateMatrix = (out, fromMatrix, toMatrix, alpha) => {
|
|
4279
4178
|
getTranslation(fromPosition, fromMatrix);
|
|
4280
4179
|
getRotation(fromQuaternion, fromMatrix);
|
|
@@ -4467,8 +4366,8 @@
|
|
|
4467
4366
|
playing: false,
|
|
4468
4367
|
viewerSpace,
|
|
4469
4368
|
viewSpaces,
|
|
4470
|
-
vec3: create$
|
|
4471
|
-
quat: create$
|
|
4369
|
+
vec3: create$4(),
|
|
4370
|
+
quat: create$2(),
|
|
4472
4371
|
};
|
|
4473
4372
|
fromTranslation(this[P_ACTION_PLAYER].viewSpaces[XREye.Left][P_SPACE].offsetMatrix, fromValues$2(-ipd / 2, 0, 0));
|
|
4474
4373
|
fromTranslation(this[P_ACTION_PLAYER].viewSpaces[XREye.Right][P_SPACE].offsetMatrix, fromValues$2(ipd / 2, 0, 0));
|
|
@@ -4634,7 +4533,7 @@
|
|
|
4634
4533
|
}
|
|
4635
4534
|
}
|
|
4636
4535
|
|
|
4637
|
-
const VERSION = "2.1.
|
|
4536
|
+
const VERSION = "2.1.1";
|
|
4638
4537
|
|
|
4639
4538
|
/**
|
|
4640
4539
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -4775,21 +4674,48 @@
|
|
|
4775
4674
|
}
|
|
4776
4675
|
|
|
4777
4676
|
/**
|
|
4778
|
-
*
|
|
4677
|
+
* @license
|
|
4678
|
+
* webxr-layers-polyfill
|
|
4679
|
+
* Version 1.1.0
|
|
4680
|
+
* Copyright (c) 2021 Facebook, Inc. and its affiliates.
|
|
4779
4681
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4780
4682
|
* you may not use this file except in compliance with the License.
|
|
4781
4683
|
* You may obtain a copy of the License at
|
|
4782
|
-
*
|
|
4684
|
+
*
|
|
4783
4685
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4784
|
-
*
|
|
4686
|
+
*
|
|
4785
4687
|
* Unless required by applicable law or agreed to in writing, software
|
|
4786
4688
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4787
4689
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4788
4690
|
* See the License for the specific language governing permissions and
|
|
4789
4691
|
* limitations under the License.
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4692
|
+
*/
|
|
4693
|
+
|
|
4694
|
+
/**
|
|
4695
|
+
* @license
|
|
4696
|
+
* gl-matrix
|
|
4697
|
+
* Version 3.4.3
|
|
4698
|
+
* Copyright (c) 2015-2021, Brandon Jones, Colin MacKenzie IV.
|
|
4699
|
+
*
|
|
4700
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4701
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
4702
|
+
* in the Software without restriction, including without limitation the rights
|
|
4703
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
4704
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
4705
|
+
* furnished to do so, subject to the following conditions:
|
|
4706
|
+
*
|
|
4707
|
+
* The above copyright notice and this permission notice shall be included in
|
|
4708
|
+
* all copies or substantial portions of the Software.
|
|
4709
|
+
*
|
|
4710
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
4711
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
4712
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
4713
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
4714
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
4715
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
4716
|
+
* THE SOFTWARE.
|
|
4717
|
+
*/
|
|
4718
|
+
|
|
4793
4719
|
var XRTextureType;
|
|
4794
4720
|
(function (XRTextureType) {
|
|
4795
4721
|
XRTextureType["texture"] = "texture";
|
|
@@ -4804,39 +4730,10 @@
|
|
|
4804
4730
|
XRLayerLayout["stereo-top-bottom"] = "stereo-top-bottom";
|
|
4805
4731
|
})(XRLayerLayout || (XRLayerLayout = {}));
|
|
4806
4732
|
|
|
4807
|
-
/**
|
|
4808
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4809
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4810
|
-
* you may not use this file except in compliance with the License.
|
|
4811
|
-
* You may obtain a copy of the License at
|
|
4812
|
-
*
|
|
4813
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4814
|
-
*
|
|
4815
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4816
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4817
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4818
|
-
* See the License for the specific language governing permissions and
|
|
4819
|
-
* limitations under the License.
|
|
4820
|
-
*/
|
|
4821
|
-
/// <reference types="webxr" />
|
|
4822
4733
|
const isReferenceSpace = (arg) => {
|
|
4823
4734
|
return arg && typeof arg.getOffsetReferenceSpace === 'function';
|
|
4824
4735
|
};
|
|
4825
4736
|
|
|
4826
|
-
/**
|
|
4827
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4828
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4829
|
-
* you may not use this file except in compliance with the License.
|
|
4830
|
-
* You may obtain a copy of the License at
|
|
4831
|
-
*
|
|
4832
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4833
|
-
*
|
|
4834
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4835
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4836
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4837
|
-
* See the License for the specific language governing permissions and
|
|
4838
|
-
* limitations under the License.
|
|
4839
|
-
*/
|
|
4840
4737
|
const getGlobal = () => {
|
|
4841
4738
|
return typeof global !== 'undefined'
|
|
4842
4739
|
? global
|
|
@@ -4847,31 +4744,6 @@
|
|
|
4847
4744
|
: {};
|
|
4848
4745
|
};
|
|
4849
4746
|
|
|
4850
|
-
/**
|
|
4851
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4852
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4853
|
-
* you may not use this file except in compliance with the License.
|
|
4854
|
-
* You may obtain a copy of the License at
|
|
4855
|
-
*
|
|
4856
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4857
|
-
*
|
|
4858
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4859
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4860
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4861
|
-
* See the License for the specific language governing permissions and
|
|
4862
|
-
* limitations under the License.
|
|
4863
|
-
*/
|
|
4864
|
-
/**
|
|
4865
|
-
* In WebGL2, internalFormat and format no longer need to be the same, but
|
|
4866
|
-
* must be defined very specifically. This is a helper utility that, given a sized or unsized format,
|
|
4867
|
-
* returns both formats as well as the type for that format.
|
|
4868
|
-
* See https://registry.khronos.org/webgl/specs/latest/2.0/#TEXTURE_TYPES_FORMATS_FROM_DOM_ELEMENTS_TABLE
|
|
4869
|
-
* or https://webgl2fundamentals.org/webgl/lessons/webgl-data-textures.html for more information.
|
|
4870
|
-
*
|
|
4871
|
-
* @param context WebGL2 Rendering context used for the enums
|
|
4872
|
-
* @param providedFormat The provided format (sized or unsized) to retrieve other formats for
|
|
4873
|
-
* @returns
|
|
4874
|
-
*/
|
|
4875
4747
|
const getFormatsFromInternalFormat = (context, providedFormat) => {
|
|
4876
4748
|
switch (providedFormat) {
|
|
4877
4749
|
case context.RGBA8:
|
|
@@ -5043,8 +4915,6 @@
|
|
|
5043
4915
|
textureFormat: context.DEPTH_STENCIL,
|
|
5044
4916
|
type: context.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
5045
4917
|
};
|
|
5046
|
-
// DEPTH_COMPONENT and DEPTH_STENCIL are invalid internalFormats,
|
|
5047
|
-
// so we have to account for those too
|
|
5048
4918
|
case context.DEPTH_COMPONENT:
|
|
5049
4919
|
return getFormatsFromInternalFormat(context, context.DEPTH_COMPONENT24);
|
|
5050
4920
|
case context.DEPTH_STENCIL:
|
|
@@ -5064,20 +4934,6 @@
|
|
|
5064
4934
|
}
|
|
5065
4935
|
};
|
|
5066
4936
|
|
|
5067
|
-
/**
|
|
5068
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5069
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5070
|
-
* you may not use this file except in compliance with the License.
|
|
5071
|
-
* You may obtain a copy of the License at
|
|
5072
|
-
*
|
|
5073
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5074
|
-
*
|
|
5075
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5076
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5077
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5078
|
-
* See the License for the specific language governing permissions and
|
|
5079
|
-
* limitations under the License.
|
|
5080
|
-
*/
|
|
5081
4937
|
class XRCompositionLayerPolyfill {
|
|
5082
4938
|
constructor() {
|
|
5083
4939
|
this._hasRunDeferredInitialize = false;
|
|
@@ -5093,25 +4949,16 @@
|
|
|
5093
4949
|
destroy() {
|
|
5094
4950
|
this._colorTextures = [];
|
|
5095
4951
|
this._depthStencilTextures = [];
|
|
5096
|
-
// destroy underlying GL attachments
|
|
5097
4952
|
}
|
|
5098
|
-
// EventTarget things. Figure this out from the WebXR polyfill!
|
|
5099
4953
|
addEventListener(type, listener, options) { }
|
|
5100
|
-
/**
|
|
5101
|
-
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
|
|
5102
|
-
*/
|
|
5103
4954
|
dispatchEvent(event) {
|
|
5104
4955
|
return false;
|
|
5105
4956
|
}
|
|
5106
|
-
/**
|
|
5107
|
-
* Removes the event listener in target's event listener list with the same type, callback, and options.
|
|
5108
|
-
*/
|
|
5109
4957
|
removeEventListener(type, callback, options) { }
|
|
5110
4958
|
getContext() {
|
|
5111
4959
|
return this.context;
|
|
5112
4960
|
}
|
|
5113
4961
|
getTextureType() {
|
|
5114
|
-
// override this please
|
|
5115
4962
|
throw new Error('Unimplemented');
|
|
5116
4963
|
}
|
|
5117
4964
|
get colorTextures() {
|
|
@@ -5120,11 +4967,9 @@
|
|
|
5120
4967
|
get depthStencilTextures() {
|
|
5121
4968
|
return this._depthStencilTextures;
|
|
5122
4969
|
}
|
|
5123
|
-
// POLYFILL ONLY: Get metadata for textures
|
|
5124
4970
|
get colorTexturesMeta() {
|
|
5125
4971
|
return this._texturesMeta;
|
|
5126
4972
|
}
|
|
5127
|
-
// POLYFILL ONLY: Get media source for media layers
|
|
5128
4973
|
get media() {
|
|
5129
4974
|
if (!this.isMediaLayer()) {
|
|
5130
4975
|
console.warn('Attempted to retrieve media from a non-media layer');
|
|
@@ -5136,15 +4981,11 @@
|
|
|
5136
4981
|
textureType === XRTextureType['texture-array']) {
|
|
5137
4982
|
throw new TypeError();
|
|
5138
4983
|
}
|
|
5139
|
-
// UNIMPLEMENTED: If textureType is "texture-array" and not all of the session’s views in the list of views have the same recommended WebGL texture resolution,
|
|
5140
|
-
// throw a NotSupportedError and abort these steps.
|
|
5141
4984
|
if (layout === XRLayerLayout.mono) {
|
|
5142
4985
|
return layout;
|
|
5143
4986
|
}
|
|
5144
4987
|
if (layout === XRLayerLayout.default) {
|
|
5145
|
-
|
|
5146
|
-
if (this.session.internalViews &&
|
|
5147
|
-
this.session.internalViews.length === 1) {
|
|
4988
|
+
if (this.session.internalViews && this.session.internalViews.length === 1) {
|
|
5148
4989
|
return XRLayerLayout['mono'];
|
|
5149
4990
|
}
|
|
5150
4991
|
if (textureType === XRTextureType['texture-array']) {
|
|
@@ -5152,61 +4993,36 @@
|
|
|
5152
4993
|
}
|
|
5153
4994
|
}
|
|
5154
4995
|
if (layout === XRLayerLayout.default || layout === XRLayerLayout.stereo) {
|
|
5155
|
-
// If the user agent prefers "stereo-left-right" layout, return "stereo-left-right" and abort these steps.
|
|
5156
4996
|
return XRLayerLayout['stereo-left-right'];
|
|
5157
|
-
// If the user agent prefers "stereo-top-bottom" layout, return "stereo-top-bottom" and abort these steps.
|
|
5158
4997
|
}
|
|
5159
4998
|
return layout;
|
|
5160
4999
|
}
|
|
5161
|
-
// projection and cube layers are never media layers
|
|
5162
5000
|
isMediaLayer() {
|
|
5163
5001
|
return this._media !== null;
|
|
5164
5002
|
}
|
|
5165
|
-
// LAZY INITIALIZATION
|
|
5166
|
-
////////////////////////
|
|
5167
|
-
// override this to initialize things, assuming that session.views already exists
|
|
5168
5003
|
_deferredInitialize() { }
|
|
5169
|
-
// Call this to run deferred initialize
|
|
5170
|
-
// do not override it
|
|
5171
5004
|
initializeIfNeeded() {
|
|
5172
|
-
// OVERRIDE THIS
|
|
5173
5005
|
if (!this._hasRunDeferredInitialize) {
|
|
5174
5006
|
this._hasRunDeferredInitialize = true;
|
|
5175
5007
|
this._deferredInitialize();
|
|
5176
5008
|
}
|
|
5177
5009
|
}
|
|
5178
|
-
// ALLOCATING TEXTURES
|
|
5179
|
-
// NOTE: Projection layers override this behavior
|
|
5180
|
-
///////////////////////////////////////////////////
|
|
5181
|
-
// https://www.w3.org/TR/webxrlayers-1/#allocate-color-textures
|
|
5182
5010
|
_allocateColorTexturesInternal(textureType, init) {
|
|
5183
5011
|
let session = this.session;
|
|
5184
5012
|
let views = session.internalViews;
|
|
5185
5013
|
if (!views || views.length === 0) {
|
|
5186
|
-
// can't allocate if there are no views
|
|
5187
5014
|
console.warn("We can't allocate color textures without views");
|
|
5188
5015
|
return;
|
|
5189
5016
|
}
|
|
5190
|
-
// TODO UNIMPLEMENTED: If init’s mipLevels is smaller than 1, throw a InvalidStateError and abort these steps.
|
|
5191
|
-
// TODO UNIMPLEMENTED: If init’s mipLevels is larger than 1 and viewPixelWidth and viewPixelHeight are not powers of 2,
|
|
5192
|
-
// throw a InvalidStateError and abort these steps
|
|
5193
|
-
// POLYFILL ONLY: initialize layout if we haven't already
|
|
5194
5017
|
this.initializeIfNeeded();
|
|
5195
|
-
// UNIMPLEMENTED: If init’s colorFormat is not in the list of color formats
|
|
5196
|
-
// for non-projection layers, throw a NotSupportedError and abort these steps.
|
|
5197
5018
|
if (this.layout === XRLayerLayout.mono) {
|
|
5198
5019
|
if (textureType === XRTextureType['texture-array']) {
|
|
5199
|
-
// Initialize array with 1 new instance of an opaque texture in the relevant realm of this context created
|
|
5200
|
-
// as a TEXTURE_2D_ARRAY texture with 1 internal texture using context and init’s colorFormat, mipLevels, viewPixelWidth and viewPixelHeight values.
|
|
5201
5020
|
const newTexture = this._createNewColorTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.colorFormat);
|
|
5202
5021
|
this._texturesMeta = [newTexture];
|
|
5203
5022
|
this._colorTextures = [newTexture.texture];
|
|
5204
5023
|
return;
|
|
5205
5024
|
}
|
|
5206
5025
|
else {
|
|
5207
|
-
// Initialize array with 1 new instance of an opaque texture in the relevant realm of context created as a
|
|
5208
|
-
// TEXTURE_2D texture with context and
|
|
5209
|
-
// init’s colorFormat, mipLevels, viewPixelWidth and viewPixelHeight values.
|
|
5210
5026
|
const newTexture = this._createNewColorTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.colorFormat);
|
|
5211
5027
|
this._texturesMeta = [newTexture];
|
|
5212
5028
|
this._colorTextures = [newTexture.texture];
|
|
@@ -5215,10 +5031,6 @@
|
|
|
5215
5031
|
}
|
|
5216
5032
|
else if (this.layout === XRLayerLayout.stereo) {
|
|
5217
5033
|
if (textureType === XRTextureType['texture-array']) {
|
|
5218
|
-
// Initialize array with 1 new instance of an opaque texture in the relevant realm of context created as a
|
|
5219
|
-
// TEXTURE_2D_ARRAY texture with 2 layers using context and init’s colorFormat, mipLevels, viewPixelWidth and viewPixelHeight values.
|
|
5220
|
-
// TODO: use a new createNewColorTextureArray function for this!
|
|
5221
|
-
// See https://github.com/WebGLSamples/WebGL2Samples/blob/master/samples/texture_2d_array.html#L145-L160
|
|
5222
5034
|
const newTexture = this._createNewColorTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.colorFormat, 2);
|
|
5223
5035
|
this._texturesMeta = [newTexture];
|
|
5224
5036
|
this._colorTextures = [newTexture.texture];
|
|
@@ -5256,9 +5068,6 @@
|
|
|
5256
5068
|
if (init.mipLevels < 1) {
|
|
5257
5069
|
throw new Error('Invalid miplevel. Miplevel needs to be >= 1');
|
|
5258
5070
|
}
|
|
5259
|
-
// UNIMPLEMENTED: If init’s mipLevels is larger than 1 and
|
|
5260
|
-
// viewPixelWidth and viewPixelHeight are not powers of 2,
|
|
5261
|
-
// throw a InvalidStateError and abort these steps.
|
|
5262
5071
|
if (this.layout === XRLayerLayout.mono) {
|
|
5263
5072
|
if (textureType === XRTextureType['texture-array']) {
|
|
5264
5073
|
const newTexture = this._createNewDepthStencilTexture(init.viewPixelWidth, init.viewPixelHeight, textureType, init.depthFormat);
|
|
@@ -5299,11 +5108,9 @@
|
|
|
5299
5108
|
return this._createGenericPolyfillTexture(textureType, width, height, colorFormat, 0, layers);
|
|
5300
5109
|
}
|
|
5301
5110
|
_createNewDepthStencilTexture(width, height, textureType, depthFormat, layers = 1) {
|
|
5302
|
-
// If we have layers and are a texture-array, do that instead.
|
|
5303
5111
|
return this._createGenericPolyfillTexture(textureType, width, height, depthFormat, 0, layers);
|
|
5304
5112
|
}
|
|
5305
5113
|
_createGenericPolyfillTexture(textureType, width, height, textureFormat, mipmapLevel = 0, numLayers = 1) {
|
|
5306
|
-
// CHECKS FOR CORRECTNESS
|
|
5307
5114
|
if (textureType === XRTextureType['texture-array'] && numLayers <= 1) {
|
|
5308
5115
|
console.warn('creating a texture array with a single layer...');
|
|
5309
5116
|
}
|
|
@@ -5311,10 +5118,6 @@
|
|
|
5311
5118
|
this.context instanceof WebGLRenderingContext) {
|
|
5312
5119
|
throw new Error('WebGL 1 does not support texture array');
|
|
5313
5120
|
}
|
|
5314
|
-
// AUTO-ANTIALIASING DETECTION
|
|
5315
|
-
const autoSamples = this._getAutoSampleCount();
|
|
5316
|
-
const useAutoAA = autoSamples > 1;
|
|
5317
|
-
// CREATE THE TEXTURE AND SURROUNDING METADATA
|
|
5318
5121
|
let texture = this.context.createTexture();
|
|
5319
5122
|
let textureMeta = {
|
|
5320
5123
|
width,
|
|
@@ -5323,14 +5126,7 @@
|
|
|
5323
5126
|
type: textureType,
|
|
5324
5127
|
textureFormat: textureFormat,
|
|
5325
5128
|
texture,
|
|
5326
|
-
// Add internal MSAA tracking
|
|
5327
|
-
_msaaFramebuffer: null,
|
|
5328
|
-
_resolveFramebuffer: null,
|
|
5329
|
-
_autoAntialiasing: useAutoAA,
|
|
5330
|
-
_samples: autoSamples,
|
|
5331
5129
|
};
|
|
5332
|
-
// DEPTH_COMPONENT is not a valid internalFormat in WebGL2.
|
|
5333
|
-
// https://stackoverflow.com/a/60703526
|
|
5334
5130
|
let internalFormat = textureFormat;
|
|
5335
5131
|
let texImageType = this.context.UNSIGNED_BYTE;
|
|
5336
5132
|
if (this.context instanceof WebGL2RenderingContext) {
|
|
@@ -5340,20 +5136,16 @@
|
|
|
5340
5136
|
texImageType = expectedFormats.type;
|
|
5341
5137
|
}
|
|
5342
5138
|
else {
|
|
5343
|
-
// WebGL1 specific code
|
|
5344
5139
|
if (textureFormat === this.context.DEPTH_COMPONENT) {
|
|
5345
5140
|
texImageType = this.context.UNSIGNED_INT;
|
|
5346
5141
|
}
|
|
5347
5142
|
if (textureFormat === this.context.DEPTH_STENCIL) {
|
|
5348
|
-
// this only exists if we have the WEBGL_depth_texture extension, but
|
|
5349
|
-
// we assume that we must have it in order to get this far.
|
|
5350
5143
|
texImageType = this.context.UNSIGNED_INT_24_8_WEBGL;
|
|
5351
5144
|
}
|
|
5352
5145
|
}
|
|
5353
5146
|
if (textureType === XRTextureType['texture-array'] &&
|
|
5354
5147
|
this.context instanceof WebGL2RenderingContext) {
|
|
5355
5148
|
console.warn('texture-array layers are supported...questionably in the polyfill at the moment. Use at your own risk.');
|
|
5356
|
-
// create a 2d texture array
|
|
5357
5149
|
const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_2D_ARRAY);
|
|
5358
5150
|
this.context.bindTexture(this.context.TEXTURE_2D_ARRAY, texture);
|
|
5359
5151
|
if (this._getSupportedDepthFormats().indexOf(textureFormat) >= 0) {
|
|
@@ -5365,27 +5157,11 @@
|
|
|
5365
5157
|
this.context.bindTexture(this.context.TEXTURE_2D_ARRAY, existingTextureBinding);
|
|
5366
5158
|
}
|
|
5367
5159
|
else {
|
|
5368
|
-
// regular texture 2d
|
|
5369
5160
|
const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_2D);
|
|
5370
5161
|
this.context.bindTexture(this.context.TEXTURE_2D, texture);
|
|
5371
5162
|
this.context.texImage2D(this.context.TEXTURE_2D, 0, internalFormat, width, height, 0, textureFormat, texImageType, null);
|
|
5372
5163
|
this.context.bindTexture(this.context.TEXTURE_2D, existingTextureBinding);
|
|
5373
5164
|
}
|
|
5374
|
-
// AUTO-ENABLE MSAA FOR DESKTOP - but only for color textures, not depth
|
|
5375
|
-
if (useAutoAA && this.context instanceof WebGL2RenderingContext) {
|
|
5376
|
-
const isDepthTexture = this._getSupportedDepthFormats().indexOf(textureFormat) >= 0;
|
|
5377
|
-
if (!isDepthTexture) {
|
|
5378
|
-
try {
|
|
5379
|
-
this._createAutoMSAAFramebuffers(textureMeta, width, height, internalFormat);
|
|
5380
|
-
console.log(`Auto-enabled ${autoSamples}x MSAA for layer texture (${width}x${height})`);
|
|
5381
|
-
}
|
|
5382
|
-
catch (error) {
|
|
5383
|
-
console.warn('Failed to create MSAA framebuffers, falling back to non-AA:', error);
|
|
5384
|
-
textureMeta._autoAntialiasing = false;
|
|
5385
|
-
textureMeta._samples = 1;
|
|
5386
|
-
}
|
|
5387
|
-
}
|
|
5388
|
-
}
|
|
5389
5165
|
return textureMeta;
|
|
5390
5166
|
}
|
|
5391
5167
|
_getSupportedDepthFormats() {
|
|
@@ -5401,117 +5177,37 @@
|
|
|
5401
5177
|
}
|
|
5402
5178
|
return supportedDepthFormats;
|
|
5403
5179
|
}
|
|
5404
|
-
// AUTO-ANTIALIASING HELPERS FOR DESKTOP
|
|
5405
|
-
////////////////////////////////////////////
|
|
5406
|
-
_shouldAutoEnableAntialiasing() {
|
|
5407
|
-
// Auto-enable AA for desktop environments (IWER)
|
|
5408
|
-
// Option 1: Check for IWER specifically
|
|
5409
|
-
if (typeof window.IWER !== 'undefined') {
|
|
5410
|
-
return true;
|
|
5411
|
-
}
|
|
5412
|
-
// Option 2: Detect desktop via user agent (more general)
|
|
5413
|
-
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
5414
|
-
if (isMobile) {
|
|
5415
|
-
return false;
|
|
5416
|
-
}
|
|
5417
|
-
// Option 3: Only enable if WebGL2 supports MSAA
|
|
5418
|
-
if (!(this.context instanceof WebGL2RenderingContext)) {
|
|
5419
|
-
return false;
|
|
5420
|
-
}
|
|
5421
|
-
// Check if MSAA is actually supported
|
|
5422
|
-
const maxSamples = this.context.getParameter(this.context.MAX_SAMPLES);
|
|
5423
|
-
return maxSamples > 1;
|
|
5424
|
-
}
|
|
5425
|
-
_getAutoSampleCount() {
|
|
5426
|
-
if (!this._shouldAutoEnableAntialiasing())
|
|
5427
|
-
return 1;
|
|
5428
|
-
// Get max samples supported, but cap at reasonable level
|
|
5429
|
-
const maxSamples = this.context.getParameter(this.context.MAX_SAMPLES);
|
|
5430
|
-
return Math.min(maxSamples, 4); // Use 4x MSAA as reasonable default
|
|
5431
|
-
}
|
|
5432
|
-
_createAutoMSAAFramebuffers(textureMeta, width, height, colorFormat, depthFormat) {
|
|
5433
|
-
const gl = this.context;
|
|
5434
|
-
// Create MSAA color renderbuffer
|
|
5435
|
-
const colorRenderbuffer = gl.createRenderbuffer();
|
|
5436
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, colorRenderbuffer);
|
|
5437
|
-
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, textureMeta._samples, colorFormat, width, height);
|
|
5438
|
-
// Create MSAA depth renderbuffer (if depth format provided)
|
|
5439
|
-
let depthRenderbuffer = null;
|
|
5440
|
-
if (depthFormat) {
|
|
5441
|
-
depthRenderbuffer = gl.createRenderbuffer();
|
|
5442
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, depthRenderbuffer);
|
|
5443
|
-
gl.renderbufferStorageMultisample(gl.RENDERBUFFER, textureMeta._samples, depthFormat, width, height);
|
|
5444
|
-
}
|
|
5445
|
-
// Create MSAA framebuffer
|
|
5446
|
-
const msaaFramebuffer = gl.createFramebuffer();
|
|
5447
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, msaaFramebuffer);
|
|
5448
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorRenderbuffer);
|
|
5449
|
-
if (depthRenderbuffer) {
|
|
5450
|
-
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRenderbuffer);
|
|
5451
|
-
}
|
|
5452
|
-
// Create resolve framebuffer (uses the regular texture)
|
|
5453
|
-
const resolveFramebuffer = gl.createFramebuffer();
|
|
5454
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, resolveFramebuffer);
|
|
5455
|
-
if (textureMeta.type === XRTextureType['texture-array']) {
|
|
5456
|
-
// For texture arrays, attach the first layer
|
|
5457
|
-
gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, textureMeta.texture, 0, 0);
|
|
5458
|
-
}
|
|
5459
|
-
else {
|
|
5460
|
-
// For regular textures
|
|
5461
|
-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textureMeta.texture, 0);
|
|
5462
|
-
}
|
|
5463
|
-
// Store for later use
|
|
5464
|
-
textureMeta._msaaFramebuffer = msaaFramebuffer;
|
|
5465
|
-
textureMeta._resolveFramebuffer = resolveFramebuffer;
|
|
5466
|
-
// Clean up bindings
|
|
5467
|
-
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
|
|
5468
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
5469
|
-
}
|
|
5470
5180
|
}
|
|
5471
5181
|
|
|
5472
|
-
/**
|
|
5473
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5474
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5475
|
-
* you may not use this file except in compliance with the License.
|
|
5476
|
-
* You may obtain a copy of the License at
|
|
5477
|
-
*
|
|
5478
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5479
|
-
*
|
|
5480
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5481
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5482
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5483
|
-
* See the License for the specific language governing permissions and
|
|
5484
|
-
* limitations under the License.
|
|
5485
|
-
*/
|
|
5486
5182
|
const defaultCylinderLayerInit = {
|
|
5487
5183
|
colorFormat: 0x1908,
|
|
5488
5184
|
mipLevels: 1,
|
|
5489
5185
|
layout: XRLayerLayout.mono,
|
|
5490
5186
|
isStatic: false,
|
|
5491
|
-
space: null,
|
|
5492
|
-
viewPixelHeight: 0,
|
|
5493
|
-
viewPixelWidth: 0,
|
|
5187
|
+
space: null,
|
|
5188
|
+
viewPixelHeight: 0,
|
|
5189
|
+
viewPixelWidth: 0,
|
|
5494
5190
|
textureType: XRTextureType.texture,
|
|
5495
5191
|
radius: 2.0,
|
|
5496
|
-
centralAngle: 0.78539,
|
|
5192
|
+
centralAngle: 0.78539,
|
|
5497
5193
|
aspectRatio: 2.0,
|
|
5498
5194
|
};
|
|
5499
5195
|
const defaultMediaCylinderLayerInit = {
|
|
5500
5196
|
layout: XRLayerLayout.mono,
|
|
5501
5197
|
invertStereo: false,
|
|
5502
|
-
space: null,
|
|
5198
|
+
space: null,
|
|
5503
5199
|
radius: 2.0,
|
|
5504
|
-
centralAngle: 0.78539,
|
|
5200
|
+
centralAngle: 0.78539,
|
|
5505
5201
|
};
|
|
5506
5202
|
class XRCylinderLayer extends XRCompositionLayerPolyfill {
|
|
5507
5203
|
constructor(init, media) {
|
|
5508
5204
|
super();
|
|
5509
|
-
this._media = media
|
|
5205
|
+
this._media = media !== null && media !== void 0 ? media : null;
|
|
5510
5206
|
if (this.isMediaLayer()) {
|
|
5511
|
-
this.init = {
|
|
5207
|
+
this.init = Object.assign(Object.assign({}, defaultMediaCylinderLayerInit), init);
|
|
5512
5208
|
}
|
|
5513
5209
|
else {
|
|
5514
|
-
this.init = {
|
|
5210
|
+
this.init = Object.assign(Object.assign({}, defaultCylinderLayerInit), init);
|
|
5515
5211
|
}
|
|
5516
5212
|
this.radius = this.init.radius;
|
|
5517
5213
|
this.centralAngle = this.init.centralAngle;
|
|
@@ -5563,7 +5259,6 @@
|
|
|
5563
5259
|
}
|
|
5564
5260
|
return this._depthStencilTextures;
|
|
5565
5261
|
}
|
|
5566
|
-
// POLYFILL ONLY: Get metadata for textures
|
|
5567
5262
|
get colorTexturesMeta() {
|
|
5568
5263
|
if (this.isMediaLayer()) {
|
|
5569
5264
|
throw new Error('Media layers do not have associated textures');
|
|
@@ -5574,68 +5269,51 @@
|
|
|
5574
5269
|
return this._texturesMeta;
|
|
5575
5270
|
}
|
|
5576
5271
|
get width() {
|
|
5577
|
-
// circumference of the arc
|
|
5578
5272
|
const circumference = 2 * this.radius * Math.PI;
|
|
5579
5273
|
const percentage = this.centralAngle / (2 * Math.PI);
|
|
5580
5274
|
return circumference * percentage;
|
|
5581
5275
|
}
|
|
5582
5276
|
get height() {
|
|
5583
|
-
// aspect ratio is width / height
|
|
5584
5277
|
return this.width / this.aspectRatio;
|
|
5585
5278
|
}
|
|
5586
5279
|
}
|
|
5587
5280
|
|
|
5588
|
-
/**
|
|
5589
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5590
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5591
|
-
* you may not use this file except in compliance with the License.
|
|
5592
|
-
* You may obtain a copy of the License at
|
|
5593
|
-
*
|
|
5594
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5595
|
-
*
|
|
5596
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5597
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5598
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5599
|
-
* See the License for the specific language governing permissions and
|
|
5600
|
-
* limitations under the License.
|
|
5601
|
-
*/
|
|
5602
5281
|
const defaultEquirectLayerInit = {
|
|
5603
5282
|
colorFormat: 0x1908,
|
|
5604
5283
|
mipLevels: 1,
|
|
5605
5284
|
layout: XRLayerLayout.mono,
|
|
5606
5285
|
isStatic: false,
|
|
5607
|
-
space: null,
|
|
5608
|
-
viewPixelHeight: 0,
|
|
5609
|
-
viewPixelWidth: 0,
|
|
5286
|
+
space: null,
|
|
5287
|
+
viewPixelHeight: 0,
|
|
5288
|
+
viewPixelWidth: 0,
|
|
5610
5289
|
textureType: XRTextureType.texture,
|
|
5611
5290
|
radius: 0,
|
|
5612
|
-
centralHorizontalAngle: 6.28318,
|
|
5613
|
-
upperVerticalAngle: 1.570795,
|
|
5614
|
-
lowerVerticalAngle: -1.570795,
|
|
5291
|
+
centralHorizontalAngle: 6.28318,
|
|
5292
|
+
upperVerticalAngle: 1.570795,
|
|
5293
|
+
lowerVerticalAngle: -1.570795,
|
|
5615
5294
|
};
|
|
5616
5295
|
const defaultMediaEquirectLayerInit = {
|
|
5617
|
-
space: null,
|
|
5296
|
+
space: null,
|
|
5618
5297
|
layout: XRLayerLayout.mono,
|
|
5619
5298
|
invertStereo: false,
|
|
5620
5299
|
radius: 0,
|
|
5621
|
-
centralHorizontalAngle: 6.28318,
|
|
5622
|
-
upperVerticalAngle: 1.570795,
|
|
5623
|
-
lowerVerticalAngle: -1.570795,
|
|
5300
|
+
centralHorizontalAngle: 6.28318,
|
|
5301
|
+
upperVerticalAngle: 1.570795,
|
|
5302
|
+
lowerVerticalAngle: -1.570795,
|
|
5624
5303
|
};
|
|
5625
5304
|
class XREquirectLayer extends XRCompositionLayerPolyfill {
|
|
5626
5305
|
constructor(init, media) {
|
|
5627
5306
|
super();
|
|
5628
|
-
this._media = media
|
|
5307
|
+
this._media = media !== null && media !== void 0 ? media : null;
|
|
5629
5308
|
if (this.isMediaLayer()) {
|
|
5630
|
-
this.init = {
|
|
5309
|
+
this.init = Object.assign(Object.assign({}, defaultMediaEquirectLayerInit), init);
|
|
5631
5310
|
}
|
|
5632
5311
|
else {
|
|
5633
|
-
this.init = {
|
|
5312
|
+
this.init = Object.assign(Object.assign({}, defaultEquirectLayerInit), init);
|
|
5634
5313
|
}
|
|
5635
5314
|
if (!isReferenceSpace(this.init.space)) {
|
|
5636
5315
|
throw new TypeError("Equirect layer's space needs to be an XRReferenceSpace");
|
|
5637
5316
|
}
|
|
5638
|
-
// UNIMPLEMENTED: If init's space has a type of 'viewer', throw TypeError and abort these steps.
|
|
5639
5317
|
this.radius = this.init.radius;
|
|
5640
5318
|
this.centralHorizontalAngle = this.init.centralHorizontalAngle;
|
|
5641
5319
|
this.upperVerticalAngle = this.init.upperVerticalAngle;
|
|
@@ -5687,7 +5365,6 @@
|
|
|
5687
5365
|
}
|
|
5688
5366
|
return this._depthStencilTextures;
|
|
5689
5367
|
}
|
|
5690
|
-
// POLYFILL ONLY: Get metadata for textures
|
|
5691
5368
|
get colorTexturesMeta() {
|
|
5692
5369
|
if (this.isMediaLayer()) {
|
|
5693
5370
|
throw new Error('Media layers do not have associated textures');
|
|
@@ -5699,47 +5376,32 @@
|
|
|
5699
5376
|
}
|
|
5700
5377
|
}
|
|
5701
5378
|
|
|
5702
|
-
/**
|
|
5703
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5704
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5705
|
-
* you may not use this file except in compliance with the License.
|
|
5706
|
-
* You may obtain a copy of the License at
|
|
5707
|
-
*
|
|
5708
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5709
|
-
*
|
|
5710
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5711
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5712
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5713
|
-
* See the License for the specific language governing permissions and
|
|
5714
|
-
* limitations under the License.
|
|
5715
|
-
*/
|
|
5716
5379
|
const defaultQuadLayerInit = {
|
|
5717
5380
|
colorFormat: 0x1908,
|
|
5718
5381
|
mipLevels: 1,
|
|
5719
5382
|
layout: XRLayerLayout.mono,
|
|
5720
5383
|
isStatic: false,
|
|
5721
|
-
space: null,
|
|
5722
|
-
viewPixelHeight: 0,
|
|
5723
|
-
viewPixelWidth: 0,
|
|
5384
|
+
space: null,
|
|
5385
|
+
viewPixelHeight: 0,
|
|
5386
|
+
viewPixelWidth: 0,
|
|
5724
5387
|
textureType: XRTextureType.texture,
|
|
5725
5388
|
width: 1.0,
|
|
5726
5389
|
height: 1.0,
|
|
5727
5390
|
};
|
|
5728
5391
|
const defaultMediaQuadLayerInit = {
|
|
5729
|
-
space: null,
|
|
5392
|
+
space: null,
|
|
5730
5393
|
layout: XRLayerLayout.mono,
|
|
5731
5394
|
invertStereo: false,
|
|
5732
5395
|
};
|
|
5733
5396
|
class XRQuadLayer extends XRCompositionLayerPolyfill {
|
|
5734
|
-
// media should only be added if it's a media layer...
|
|
5735
5397
|
constructor(init, media) {
|
|
5736
5398
|
super();
|
|
5737
|
-
this._media = media
|
|
5399
|
+
this._media = media !== null && media !== void 0 ? media : null;
|
|
5738
5400
|
if (this.isMediaLayer()) {
|
|
5739
|
-
this.init = {
|
|
5401
|
+
this.init = Object.assign(Object.assign({}, defaultMediaQuadLayerInit), init);
|
|
5740
5402
|
}
|
|
5741
5403
|
else {
|
|
5742
|
-
this.init = {
|
|
5404
|
+
this.init = Object.assign(Object.assign({}, defaultQuadLayerInit), init);
|
|
5743
5405
|
}
|
|
5744
5406
|
this.width = this.init.width;
|
|
5745
5407
|
this.height = this.init.height;
|
|
@@ -5765,7 +5427,6 @@
|
|
|
5765
5427
|
if (this.isMediaLayer()) {
|
|
5766
5428
|
return XRTextureType.texture;
|
|
5767
5429
|
}
|
|
5768
|
-
// override this please
|
|
5769
5430
|
return this.init.textureType;
|
|
5770
5431
|
}
|
|
5771
5432
|
_deferredInitialize() {
|
|
@@ -5791,7 +5452,6 @@
|
|
|
5791
5452
|
}
|
|
5792
5453
|
return this._depthStencilTextures;
|
|
5793
5454
|
}
|
|
5794
|
-
// POLYFILL ONLY: Get metadata for textures
|
|
5795
5455
|
get colorTexturesMeta() {
|
|
5796
5456
|
if (this.isMediaLayer()) {
|
|
5797
5457
|
throw new Error('Media layers do not have associated textures');
|
|
@@ -5803,27 +5463,12 @@
|
|
|
5803
5463
|
}
|
|
5804
5464
|
}
|
|
5805
5465
|
|
|
5806
|
-
/**
|
|
5807
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5808
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5809
|
-
* you may not use this file except in compliance with the License.
|
|
5810
|
-
* You may obtain a copy of the License at
|
|
5811
|
-
*
|
|
5812
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5813
|
-
*
|
|
5814
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5815
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5816
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5817
|
-
* See the License for the specific language governing permissions and
|
|
5818
|
-
* limitations under the License.
|
|
5819
|
-
*/
|
|
5820
5466
|
class XRMediaBindingPolyfill {
|
|
5821
5467
|
constructor(session) {
|
|
5822
5468
|
this.session = session;
|
|
5823
5469
|
if (this.session.ended) {
|
|
5824
5470
|
throw new Error('Session has ended');
|
|
5825
5471
|
}
|
|
5826
|
-
// UNIMPLEMENTED: If session is not an immersive session, throw an InvalidStateError and abort these steps.
|
|
5827
5472
|
}
|
|
5828
5473
|
createQuadLayer(video, init) {
|
|
5829
5474
|
if (this.session.ended) {
|
|
@@ -5873,7 +5518,6 @@
|
|
|
5873
5518
|
if (!isReferenceSpace(init.space)) {
|
|
5874
5519
|
throw new Error("Media Equirect layer's space must be of type XRReferenceSpace");
|
|
5875
5520
|
}
|
|
5876
|
-
// UNIMPLEMENTED: If init’s space has a type of "viewer", throw InvalidStateError and abort these steps.
|
|
5877
5521
|
let layer = new XREquirectLayer(init, video);
|
|
5878
5522
|
layer.needsRedraw = false;
|
|
5879
5523
|
layer.initialize(this.session);
|
|
@@ -5892,34 +5536,19 @@
|
|
|
5892
5536
|
}
|
|
5893
5537
|
}
|
|
5894
5538
|
|
|
5895
|
-
/**
|
|
5896
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5897
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5898
|
-
* you may not use this file except in compliance with the License.
|
|
5899
|
-
* You may obtain a copy of the License at
|
|
5900
|
-
*
|
|
5901
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5902
|
-
*
|
|
5903
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
5904
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5905
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5906
|
-
* See the License for the specific language governing permissions and
|
|
5907
|
-
* limitations under the License.
|
|
5908
|
-
*/
|
|
5909
5539
|
const defaultXRProjectionLayerInit = {
|
|
5910
5540
|
textureType: XRTextureType.texture,
|
|
5911
5541
|
colorFormat: 0x1908,
|
|
5912
5542
|
depthFormat: 0x1902,
|
|
5913
|
-
scaleFactor: 1.
|
|
5543
|
+
scaleFactor: 1.0,
|
|
5914
5544
|
};
|
|
5915
5545
|
class XRProjectionLayer extends XRCompositionLayerPolyfill {
|
|
5916
5546
|
constructor(init = defaultXRProjectionLayerInit) {
|
|
5917
5547
|
super();
|
|
5918
|
-
this.init = {
|
|
5548
|
+
this.init = Object.assign(Object.assign({}, defaultXRProjectionLayerInit), init);
|
|
5919
5549
|
}
|
|
5920
5550
|
initialize(session, context) {
|
|
5921
5551
|
super.initialize(session, context);
|
|
5922
|
-
// POLYFILL ONLY: initialize layout
|
|
5923
5552
|
this.initializeIfNeeded();
|
|
5924
5553
|
let baseLayer = session.getBaseLayer();
|
|
5925
5554
|
this.textureWidth = baseLayer.framebufferWidth * this.init.scaleFactor;
|
|
@@ -5937,38 +5566,20 @@
|
|
|
5937
5566
|
let session = this.session;
|
|
5938
5567
|
let views = session.internalViews;
|
|
5939
5568
|
if (!views || views.length === 0) {
|
|
5940
|
-
// can't allocate if there are no views
|
|
5941
5569
|
console.warn("We can't allocate color textures without views");
|
|
5942
5570
|
return;
|
|
5943
5571
|
}
|
|
5944
5572
|
let baseLayer = session.getBaseLayer();
|
|
5945
5573
|
let numViews = views.length;
|
|
5946
|
-
let width;
|
|
5574
|
+
let width = baseLayer.framebufferWidth * this.init.scaleFactor / views.length;
|
|
5947
5575
|
let height = baseLayer.framebufferHeight * this.init.scaleFactor;
|
|
5948
|
-
|
|
5949
|
-
// Only divide by views.length for separate textures per view
|
|
5950
|
-
if (this.init.textureType === XRTextureType['texture-array']) {
|
|
5951
|
-
width = baseLayer.framebufferWidth * this.init.scaleFactor;
|
|
5952
|
-
}
|
|
5953
|
-
else {
|
|
5954
|
-
width =
|
|
5955
|
-
(baseLayer.framebufferWidth * this.init.scaleFactor) / views.length;
|
|
5956
|
-
}
|
|
5957
|
-
if (this.layout === XRLayerLayout.mono ||
|
|
5958
|
-
this.layout === XRLayerLayout.default) {
|
|
5576
|
+
if (this.layout === XRLayerLayout.mono || this.layout === XRLayerLayout.default) {
|
|
5959
5577
|
if (this.init.textureType === XRTextureType['texture-array']) {
|
|
5960
|
-
// UNIMPLEMENTED: If the session’s views in the list of views don’t all have the same recommended WebGL texture resolution excluding the secondary views,
|
|
5961
|
-
// throw a NotSupportedError and abort these steps.
|
|
5962
|
-
// Initialize array with 1 new instance of an opaque texture in the relevant realm of context created as a TEXTURE_2D_ARRAY texture
|
|
5963
|
-
// with numViews layers using context, textureFormat, width and height.
|
|
5964
5578
|
let texture = this._createNewColorTexture(width, height, XRTextureType['texture-array'], this.init.colorFormat, numViews);
|
|
5965
5579
|
polyFillArray = [texture];
|
|
5966
5580
|
}
|
|
5967
5581
|
else {
|
|
5968
5582
|
for (let view of views) {
|
|
5969
|
-
// let texture be a new instance of an opaque texture
|
|
5970
|
-
// in the relevant realm of context created as a TEXTURE_2D texture
|
|
5971
|
-
// with context, textureFormat, width and height
|
|
5972
5583
|
let texture = this._createNewColorTexture(width, height, XRTextureType.texture, this.init.colorFormat);
|
|
5973
5584
|
polyFillArray.push(texture);
|
|
5974
5585
|
}
|
|
@@ -5995,16 +5606,12 @@
|
|
|
5995
5606
|
let session = this.session;
|
|
5996
5607
|
let views = session.internalViews;
|
|
5997
5608
|
if (!views || views.length === 0) {
|
|
5998
|
-
// can't allocate if there are no views
|
|
5999
5609
|
return;
|
|
6000
5610
|
}
|
|
6001
|
-
// if textureFormat is a 0 abort steps.
|
|
6002
5611
|
if (this.init.depthFormat === 0) {
|
|
6003
5612
|
this._depthStencilTextures = [];
|
|
6004
5613
|
return;
|
|
6005
5614
|
}
|
|
6006
|
-
// If context is a WebGLRenderingContext and the WEBGL_depth_texture extension
|
|
6007
|
-
// is not enabled in context, return array and abort these steps.
|
|
6008
5615
|
if (this.context instanceof WebGLRenderingContext) {
|
|
6009
5616
|
let depthExtension = this.context.getExtension('WEBGL_depth_texture');
|
|
6010
5617
|
if (!depthExtension) {
|
|
@@ -6012,9 +5619,6 @@
|
|
|
6012
5619
|
return;
|
|
6013
5620
|
}
|
|
6014
5621
|
}
|
|
6015
|
-
// UNIMPLEMENTED: If textureFormat is not in the list of depth formats for projection layers,
|
|
6016
|
-
// throw a NotSupportedError and abort these steps.
|
|
6017
|
-
// INITIALIZE EVERYTHING
|
|
6018
5622
|
let array = [];
|
|
6019
5623
|
let polyFillArray = [];
|
|
6020
5624
|
const createTextureArray = () => {
|
|
@@ -6023,38 +5627,18 @@
|
|
|
6023
5627
|
array.push(tex.texture);
|
|
6024
5628
|
}
|
|
6025
5629
|
};
|
|
6026
|
-
// POLYFILL ONLY: initialize layout if we haven't already
|
|
6027
5630
|
this.initializeIfNeeded();
|
|
6028
5631
|
let baseLayer = session.getBaseLayer();
|
|
6029
5632
|
let numViews = views.length;
|
|
6030
|
-
let width;
|
|
5633
|
+
let width = baseLayer.framebufferWidth * this.init.scaleFactor / views.length;
|
|
6031
5634
|
let height = baseLayer.framebufferHeight * this.init.scaleFactor;
|
|
6032
|
-
|
|
6033
|
-
// Only divide by views.length for separate textures per view
|
|
6034
|
-
if (this.init.textureType === XRTextureType['texture-array']) {
|
|
6035
|
-
width = baseLayer.framebufferWidth * this.init.scaleFactor;
|
|
6036
|
-
}
|
|
6037
|
-
else {
|
|
6038
|
-
width =
|
|
6039
|
-
(baseLayer.framebufferWidth * this.init.scaleFactor) / views.length;
|
|
6040
|
-
}
|
|
6041
|
-
if (this.layout === XRLayerLayout.mono ||
|
|
6042
|
-
this.layout === XRLayerLayout.default) {
|
|
5635
|
+
if (this.layout === XRLayerLayout.mono || this.layout === XRLayerLayout.default) {
|
|
6043
5636
|
if (this.init.textureType === XRTextureType['texture-array']) {
|
|
6044
|
-
// UNIMPLEMENTED: If the session’s views in the list of views don’t all have the same
|
|
6045
|
-
// recommended WebGL texture resolution excluding the secondary views,
|
|
6046
|
-
// throw a NotSupportedError and abort these steps.
|
|
6047
|
-
// Initialize array with 1 new instance of an opaque texture in the relevant realm of
|
|
6048
|
-
// context created as a TEXTURE_2D_ARRAY texture
|
|
6049
|
-
// with numViews layers using context, textureFormat, width and height.
|
|
6050
5637
|
let texture = this._createNewDepthStencilTexture(width, height, this.init.textureType, this.init.depthFormat, numViews);
|
|
6051
5638
|
polyFillArray = [texture];
|
|
6052
5639
|
}
|
|
6053
5640
|
else {
|
|
6054
5641
|
for (let view of views) {
|
|
6055
|
-
// let texture be a new instance of an opaque texture
|
|
6056
|
-
// in the relevant realm of context created as a TEXTURE_2D texture
|
|
6057
|
-
// with context, textureFormat, width and height
|
|
6058
5642
|
let texture = this._createNewDepthStencilTexture(width, height, this.init.textureType, this.init.depthFormat);
|
|
6059
5643
|
polyFillArray.push(texture);
|
|
6060
5644
|
}
|
|
@@ -6097,29 +5681,17 @@
|
|
|
6097
5681
|
return this.init.textureType;
|
|
6098
5682
|
}
|
|
6099
5683
|
_deferredInitialize() {
|
|
6100
|
-
// initialize layer.isStatic = false
|
|
6101
5684
|
this.isStatic = false;
|
|
6102
|
-
// Some browsers use the depth for reprojection
|
|
6103
5685
|
this.ignoreDepthValues = false;
|
|
6104
|
-
// layer's fixedFoveation should be 0
|
|
6105
5686
|
this.fixedFoveation = 0;
|
|
6106
|
-
// let layout be the result of determining the layout attribute with init’s textureType, context and "default".
|
|
6107
5687
|
let layout = this.determineLayoutAttribute(this.init.textureType, this.context, XRLayerLayout.default);
|
|
6108
|
-
// initialize layer's layout to the created layout
|
|
6109
5688
|
this.layout = layout;
|
|
6110
5689
|
this.needsRedraw = true;
|
|
6111
|
-
// Let maximum scalefactor be the result of determining the maximum scalefactor with session, context and layout.
|
|
6112
5690
|
let maxScaleFactor = this.determineMaximumScaleFactor();
|
|
6113
|
-
|
|
6114
|
-
// This respects the user's choice and doesn't automatically scale up.
|
|
6115
|
-
let conservativeScaleFactor = Math.min(this.init.scaleFactor, maxScaleFactor);
|
|
6116
|
-
// If scaleFactor is larger than maximum scalefactor, set scaleFactor to maximum scalefactor.
|
|
6117
|
-
this.init.scaleFactor;
|
|
6118
|
-
let scaleFactor = conservativeScaleFactor;
|
|
5691
|
+
let scaleFactor = Math.min(this.init.scaleFactor, maxScaleFactor);
|
|
6119
5692
|
this.init.scaleFactor = scaleFactor;
|
|
6120
5693
|
}
|
|
6121
5694
|
determineMaximumScaleFactor() {
|
|
6122
|
-
// Let largest width be the largest width of the recommended WebGL texture resolution from the session's list of views excluding the secondary views.
|
|
6123
5695
|
let baseLayer = this.session.getBaseLayer(this.context);
|
|
6124
5696
|
let largestWidth = baseLayer.framebufferWidth;
|
|
6125
5697
|
let largestHeight = baseLayer.framebufferHeight;
|
|
@@ -6131,40 +5703,20 @@
|
|
|
6131
5703
|
}
|
|
6132
5704
|
let largestViewDimension = Math.max(largestWidth, largestHeight);
|
|
6133
5705
|
let largestTextureDimension = this.context.getParameter(this.context.MAX_TEXTURE_SIZE);
|
|
6134
|
-
|
|
6135
|
-
return maxScaleFactor;
|
|
5706
|
+
return largestTextureDimension / largestViewDimension;
|
|
6136
5707
|
}
|
|
6137
5708
|
}
|
|
6138
5709
|
|
|
6139
|
-
/**
|
|
6140
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6141
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6142
|
-
* you may not use this file except in compliance with the License.
|
|
6143
|
-
* You may obtain a copy of the License at
|
|
6144
|
-
*
|
|
6145
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
6146
|
-
*
|
|
6147
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
6148
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
6149
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
6150
|
-
* See the License for the specific language governing permissions and
|
|
6151
|
-
* limitations under the License.
|
|
6152
|
-
*/
|
|
6153
5710
|
const initializeViewport = (viewport, texture, layout, offset, numViews) => {
|
|
6154
5711
|
let x = 0;
|
|
6155
5712
|
let y = 0;
|
|
6156
5713
|
let width = texture.width;
|
|
6157
5714
|
let height = texture.height;
|
|
6158
|
-
// If layout is "stereo-left-right":
|
|
6159
|
-
// Set viewport’s x to the pixel width of texture multiplied by offset and divided by num.
|
|
6160
|
-
// Set viewport’s width to the pixel width of subimage’s texture divided by num.
|
|
6161
5715
|
if (layout === XRLayerLayout['stereo-left-right']) {
|
|
6162
5716
|
x = (texture.width * offset) / numViews;
|
|
6163
5717
|
width = texture.width / numViews;
|
|
6164
5718
|
}
|
|
6165
5719
|
else if (layout === XRLayerLayout['stereo-top-bottom']) {
|
|
6166
|
-
// Set viewport’s y to the pixel height of texture multiplied by offset and divided by num.
|
|
6167
|
-
// Set viewport’s height to the pixel height of subimage’s texture divided by num.
|
|
6168
5720
|
y = (texture.height * offset) / numViews;
|
|
6169
5721
|
height = texture.height / numViews;
|
|
6170
5722
|
}
|
|
@@ -6174,59 +5726,31 @@
|
|
|
6174
5726
|
viewport.height = height;
|
|
6175
5727
|
};
|
|
6176
5728
|
|
|
6177
|
-
/**
|
|
6178
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6179
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6180
|
-
* you may not use this file except in compliance with the License.
|
|
6181
|
-
* You may obtain a copy of the License at
|
|
6182
|
-
*
|
|
6183
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
6184
|
-
*
|
|
6185
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
6186
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
6187
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
6188
|
-
* See the License for the specific language governing permissions and
|
|
6189
|
-
* limitations under the License.
|
|
6190
|
-
*/
|
|
6191
5729
|
const compileShader = (gl, shaderSource, shaderType) => {
|
|
6192
|
-
// Create the shader object
|
|
6193
5730
|
var shader = gl.createShader(shaderType);
|
|
6194
|
-
// Set the shader source code.
|
|
6195
5731
|
gl.shaderSource(shader, shaderSource);
|
|
6196
|
-
// Compile the shader
|
|
6197
5732
|
gl.compileShader(shader);
|
|
6198
|
-
// Check if it compiled
|
|
6199
5733
|
var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
|
6200
5734
|
if (!success) {
|
|
6201
|
-
// Something went wrong during compilation; get the error
|
|
6202
5735
|
throw 'could not compile shader:' + gl.getShaderInfoLog(shader);
|
|
6203
5736
|
}
|
|
6204
5737
|
return shader;
|
|
6205
5738
|
};
|
|
6206
|
-
/**
|
|
6207
|
-
* Creates a program from 2 shaders.
|
|
6208
|
-
*/
|
|
6209
5739
|
const createProgram = (gl, vertexShader, fragmentShader) => {
|
|
6210
|
-
// create a program.
|
|
6211
5740
|
const program = gl.createProgram();
|
|
6212
5741
|
const compiledVS = compileShader(gl, vertexShader, gl.VERTEX_SHADER);
|
|
6213
5742
|
const compiledFS = compileShader(gl, fragmentShader, gl.FRAGMENT_SHADER);
|
|
6214
|
-
// attach the shaders.
|
|
6215
5743
|
gl.attachShader(program, compiledVS);
|
|
6216
5744
|
gl.attachShader(program, compiledFS);
|
|
6217
5745
|
gl.deleteShader(compiledVS);
|
|
6218
5746
|
gl.deleteShader(compiledFS);
|
|
6219
|
-
// link the program.
|
|
6220
5747
|
gl.linkProgram(program);
|
|
6221
|
-
// Check if it linked.
|
|
6222
5748
|
var success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
|
6223
5749
|
if (!success) {
|
|
6224
|
-
// something went wrong with the link
|
|
6225
5750
|
throw 'program failed to link:' + gl.getProgramInfoLog(program);
|
|
6226
5751
|
}
|
|
6227
5752
|
return program;
|
|
6228
5753
|
};
|
|
6229
|
-
// USED FOR PROJECTION RENDERER
|
|
6230
5754
|
const setRectangle = (gl, x, y, width, height) => {
|
|
6231
5755
|
var x1 = x;
|
|
6232
5756
|
var x2 = x + width;
|
|
@@ -6234,7 +5758,6 @@
|
|
|
6234
5758
|
var y2 = y + height;
|
|
6235
5759
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([x1, y1, x2, y1, x1, y2, x1, y2, x2, y1, x2, y2]), gl.DYNAMIC_DRAW);
|
|
6236
5760
|
};
|
|
6237
|
-
// VAO support
|
|
6238
5761
|
const applyVAOExtension = (gl) => {
|
|
6239
5762
|
if (gl instanceof WebGL2RenderingContext) {
|
|
6240
5763
|
return gl;
|
|
@@ -6252,23 +5775,8 @@
|
|
|
6252
5775
|
};
|
|
6253
5776
|
};
|
|
6254
5777
|
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6258
|
-
* you may not use this file except in compliance with the License.
|
|
6259
|
-
* You may obtain a copy of the License at
|
|
6260
|
-
*
|
|
6261
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
6262
|
-
*
|
|
6263
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
6264
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
6265
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
6266
|
-
* See the License for the specific language governing permissions and
|
|
6267
|
-
* limitations under the License.
|
|
6268
|
-
*/
|
|
6269
|
-
// template tagging for syntax highlight
|
|
6270
|
-
const glsl$2 = (x) => x;
|
|
6271
|
-
const vertexShader$2 = glsl$2 `
|
|
5778
|
+
const glsl = (x) => x;
|
|
5779
|
+
const vertexShader = glsl `
|
|
6272
5780
|
attribute vec2 a_position;
|
|
6273
5781
|
attribute vec2 a_texCoord;
|
|
6274
5782
|
|
|
@@ -6291,7 +5799,7 @@ void main() {
|
|
|
6291
5799
|
v_texCoord = a_texCoord;
|
|
6292
5800
|
}
|
|
6293
5801
|
`;
|
|
6294
|
-
const fragmentShader
|
|
5802
|
+
const fragmentShader = glsl `
|
|
6295
5803
|
precision mediump float;
|
|
6296
5804
|
|
|
6297
5805
|
// our texture
|
|
@@ -6309,7 +5817,7 @@ void main() {
|
|
|
6309
5817
|
constructor(layer, context) {
|
|
6310
5818
|
this.gl = context;
|
|
6311
5819
|
this.layer = layer;
|
|
6312
|
-
this.program = createProgram(this.gl, vertexShader
|
|
5820
|
+
this.program = createProgram(this.gl, vertexShader, fragmentShader);
|
|
6313
5821
|
this.programInfo = {
|
|
6314
5822
|
attribLocations: {
|
|
6315
5823
|
a_position: this.gl.getAttribLocation(this.program, 'a_position'),
|
|
@@ -6322,14 +5830,12 @@ void main() {
|
|
|
6322
5830
|
let gl = this.gl;
|
|
6323
5831
|
let baseLayer = session.getBaseLayer();
|
|
6324
5832
|
gl.viewport(0, 0, baseLayer.framebufferWidth, baseLayer.framebufferHeight);
|
|
6325
|
-
// get texture type of layer
|
|
6326
5833
|
const textureType = this.layer.getTextureType();
|
|
6327
5834
|
const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D);
|
|
6328
5835
|
const existingActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
|
|
6329
5836
|
if (textureType === XRTextureType.texture) {
|
|
6330
5837
|
gl.activeTexture(gl.TEXTURE0);
|
|
6331
5838
|
gl.bindTexture(gl.TEXTURE_2D, this.layer.colorTextures[0]);
|
|
6332
|
-
// Set the parameters so we can render any size image.
|
|
6333
5839
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
6334
5840
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
6335
5841
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
@@ -6357,7 +5863,6 @@ This is probably an error with the polyfill itself; please file an issue on Gith
|
|
|
6357
5863
|
const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
6358
5864
|
gl.useProgram(this.program);
|
|
6359
5865
|
this.vaoGl.bindVertexArray(this.vao);
|
|
6360
|
-
// Draw the rectangle.
|
|
6361
5866
|
var primitiveType = gl.TRIANGLES;
|
|
6362
5867
|
var offset = 0;
|
|
6363
5868
|
var count = 6;
|
|
@@ -6365,8 +5870,6 @@ This is probably an error with the polyfill itself; please file an issue on Gith
|
|
|
6365
5870
|
this.vaoGl.bindVertexArray(null);
|
|
6366
5871
|
gl.useProgram(existingProgram);
|
|
6367
5872
|
}
|
|
6368
|
-
// this is used only for stereo-left-right and stereo-top-bottom layers, and is used to render
|
|
6369
|
-
// a part of a texture to a view.
|
|
6370
5873
|
_renderInternalStereo(view) {
|
|
6371
5874
|
if (view.eye === 'none') {
|
|
6372
5875
|
return this._renderInternal();
|
|
@@ -6375,10 +5878,7 @@ This is probably an error with the polyfill itself; please file an issue on Gith
|
|
|
6375
5878
|
this.vaoGl.bindVertexArray(this.vao);
|
|
6376
5879
|
const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
6377
5880
|
gl.useProgram(this.program);
|
|
6378
|
-
// set position array and texture array
|
|
6379
|
-
// we have to set the texture buffer data for every eye
|
|
6380
5881
|
this._setStereoTextureBuffer(view.eye === 'right' ? 1 : 0);
|
|
6381
|
-
// Draw the shape
|
|
6382
5882
|
var primitiveType = gl.TRIANGLES;
|
|
6383
5883
|
var offset = 0;
|
|
6384
5884
|
var count = 6;
|
|
@@ -6389,29 +5889,23 @@ This is probably an error with the polyfill itself; please file an issue on Gith
|
|
|
6389
5889
|
_createVAOs() {
|
|
6390
5890
|
this._createTextureUVs();
|
|
6391
5891
|
let gl = this.gl;
|
|
6392
|
-
// makes sure that VAOs are usable on both WebGL1 and WebGL2
|
|
6393
5892
|
this.vaoGl = applyVAOExtension(gl);
|
|
6394
|
-
// position
|
|
6395
5893
|
let positionBuffer = gl.createBuffer();
|
|
6396
5894
|
this.vao = this.vaoGl.createVertexArray();
|
|
6397
5895
|
this.vaoGl.bindVertexArray(this.vao);
|
|
6398
5896
|
gl.enableVertexAttribArray(this.programInfo.attribLocations.a_position);
|
|
6399
5897
|
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
6400
5898
|
setRectangle(gl, 0, 0, 1.0, 1.0);
|
|
6401
|
-
|
|
6402
|
-
let
|
|
6403
|
-
let
|
|
6404
|
-
let
|
|
6405
|
-
let
|
|
6406
|
-
let offset = 0; // start at the beginning of the buffer
|
|
5899
|
+
let size = 2;
|
|
5900
|
+
let type = gl.FLOAT;
|
|
5901
|
+
let normalize = false;
|
|
5902
|
+
let stride = 0;
|
|
5903
|
+
let offset = 0;
|
|
6407
5904
|
gl.vertexAttribPointer(this.programInfo.attribLocations.a_position, size, type, normalize, stride, offset);
|
|
6408
|
-
// textures
|
|
6409
5905
|
this.texcoordBuffer = gl.createBuffer();
|
|
6410
5906
|
gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
|
|
6411
5907
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
6412
5908
|
gl.bufferData(gl.ARRAY_BUFFER, this.texturePoints, gl.DYNAMIC_DRAW);
|
|
6413
|
-
// we can reset size, type, etc. here, but for projection
|
|
6414
|
-
// layers they are the same between texture and position.
|
|
6415
5909
|
gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
|
|
6416
5910
|
this.vaoGl.bindVertexArray(null);
|
|
6417
5911
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
@@ -6419,23 +5913,31 @@ This is probably an error with the polyfill itself; please file an issue on Gith
|
|
|
6419
5913
|
_setStereoTextureBuffer(index) {
|
|
6420
5914
|
let gl = this.gl;
|
|
6421
5915
|
gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
|
|
6422
|
-
// bind the texcoord buffer.
|
|
6423
5916
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
6424
5917
|
gl.bufferData(gl.ARRAY_BUFFER, this.stereoTexturePoints[index], gl.STATIC_DRAW);
|
|
6425
|
-
|
|
6426
|
-
var
|
|
6427
|
-
var
|
|
6428
|
-
var
|
|
6429
|
-
var
|
|
6430
|
-
var offset = 0; // start at the beginning of the buffer
|
|
5918
|
+
var size = 2;
|
|
5919
|
+
var type = gl.FLOAT;
|
|
5920
|
+
var normalize = false;
|
|
5921
|
+
var stride = 0;
|
|
5922
|
+
var offset = 0;
|
|
6431
5923
|
gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
|
|
6432
5924
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
6433
5925
|
}
|
|
6434
5926
|
_createTextureUVs() {
|
|
6435
5927
|
this.texturePoints = new Float32Array([
|
|
6436
|
-
0.0,
|
|
5928
|
+
0.0,
|
|
5929
|
+
0.0,
|
|
5930
|
+
1.0,
|
|
5931
|
+
0.0,
|
|
5932
|
+
0.0,
|
|
5933
|
+
1.0,
|
|
5934
|
+
0.0,
|
|
5935
|
+
1.0,
|
|
5936
|
+
1.0,
|
|
5937
|
+
0.0,
|
|
5938
|
+
1.0,
|
|
5939
|
+
1.0,
|
|
6437
5940
|
]);
|
|
6438
|
-
// calculate stereo layers if needed
|
|
6439
5941
|
const viewport = {
|
|
6440
5942
|
x: 0,
|
|
6441
5943
|
y: 0,
|
|
@@ -6450,9 +5952,8 @@ This is probably an error with the polyfill itself; please file an issue on Gith
|
|
|
6450
5952
|
this.stereoTexturePoints[1] = this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0], this.texturePoints, viewport);
|
|
6451
5953
|
}
|
|
6452
5954
|
}
|
|
6453
|
-
// used in stereo-left-right and stereo-top-down layers to obtain UVs on a part of a texture
|
|
6454
5955
|
_offsetTextureUVsByRect(texture, inArray, textureRect) {
|
|
6455
|
-
textureRect = textureRect
|
|
5956
|
+
textureRect = textureRect !== null && textureRect !== void 0 ? textureRect : {
|
|
6456
5957
|
x: 0,
|
|
6457
5958
|
y: 0,
|
|
6458
5959
|
width: texture.width,
|
|
@@ -6478,7 +5979,7 @@ This is probably an error with the polyfill itself; please file an issue on Gith
|
|
|
6478
5979
|
this.layer.layout === XRLayerLayout['stereo-top-bottom']);
|
|
6479
5980
|
}
|
|
6480
5981
|
}
|
|
6481
|
-
const texArrayVertexShader
|
|
5982
|
+
const texArrayVertexShader = glsl `#version 300 es
|
|
6482
5983
|
|
|
6483
5984
|
in vec2 a_position;
|
|
6484
5985
|
in vec2 a_texCoord;
|
|
@@ -6502,7 +6003,7 @@ void main() {
|
|
|
6502
6003
|
v_texCoord = a_texCoord;
|
|
6503
6004
|
}
|
|
6504
6005
|
`;
|
|
6505
|
-
const texArrayFragmentShader
|
|
6006
|
+
const texArrayFragmentShader = glsl `#version 300 es
|
|
6506
6007
|
precision mediump float;
|
|
6507
6008
|
precision mediump int;
|
|
6508
6009
|
precision mediump sampler2DArray;
|
|
@@ -6520,15 +6021,11 @@ void main() {
|
|
|
6520
6021
|
}
|
|
6521
6022
|
|
|
6522
6023
|
`;
|
|
6523
|
-
// texture-arrays only exist on webgl2, so we can assume that we can
|
|
6524
|
-
// use all the new features
|
|
6525
6024
|
class ProjectionTextureArrayRenderer extends ProjectionRenderer {
|
|
6526
6025
|
constructor(layer, context) {
|
|
6527
6026
|
super(layer, context);
|
|
6528
|
-
|
|
6529
|
-
this.program = createProgram(this.gl, texArrayVertexShader$1, texArrayFragmentShader$1);
|
|
6027
|
+
this.program = createProgram(this.gl, texArrayVertexShader, texArrayFragmentShader);
|
|
6530
6028
|
this._createVAOs();
|
|
6531
|
-
// uniform
|
|
6532
6029
|
this.u_layerInfo = this.gl.getUniformLocation(this.program, 'u_layer');
|
|
6533
6030
|
}
|
|
6534
6031
|
render(session) {
|
|
@@ -6538,7 +6035,6 @@ void main() {
|
|
|
6538
6035
|
throw new Error('Using texture array projection renderer on a layer without texture array.');
|
|
6539
6036
|
}
|
|
6540
6037
|
let baseLayer = session.getBaseLayer();
|
|
6541
|
-
// get texture type of layer
|
|
6542
6038
|
const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D_ARRAY);
|
|
6543
6039
|
gl.bindTexture(gl.TEXTURE_2D_ARRAY, this.layer.colorTextures[0]);
|
|
6544
6040
|
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
@@ -6557,7 +6053,6 @@ void main() {
|
|
|
6557
6053
|
gl.useProgram(this.program);
|
|
6558
6054
|
gl.bindVertexArray(this.vao);
|
|
6559
6055
|
gl.uniform1i(this.u_layerInfo, layer);
|
|
6560
|
-
// Draw the rectangle.
|
|
6561
6056
|
var primitiveType = gl.TRIANGLES;
|
|
6562
6057
|
var offset = 0;
|
|
6563
6058
|
var count = 6;
|
|
@@ -6575,21 +6070,159 @@ void main() {
|
|
|
6575
6070
|
return new ProjectionRenderer(layer, context);
|
|
6576
6071
|
};
|
|
6577
6072
|
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6073
|
+
var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
6074
|
+
if (!Math.hypot) Math.hypot = function () {
|
|
6075
|
+
var y = 0,
|
|
6076
|
+
i = arguments.length;
|
|
6077
|
+
while (i--) {
|
|
6078
|
+
y += arguments[i] * arguments[i];
|
|
6079
|
+
}
|
|
6080
|
+
return Math.sqrt(y);
|
|
6081
|
+
};
|
|
6082
|
+
|
|
6083
|
+
function create() {
|
|
6084
|
+
var out = new ARRAY_TYPE(16);
|
|
6085
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
6086
|
+
out[1] = 0;
|
|
6087
|
+
out[2] = 0;
|
|
6088
|
+
out[3] = 0;
|
|
6089
|
+
out[4] = 0;
|
|
6090
|
+
out[6] = 0;
|
|
6091
|
+
out[7] = 0;
|
|
6092
|
+
out[8] = 0;
|
|
6093
|
+
out[9] = 0;
|
|
6094
|
+
out[11] = 0;
|
|
6095
|
+
out[12] = 0;
|
|
6096
|
+
out[13] = 0;
|
|
6097
|
+
out[14] = 0;
|
|
6098
|
+
}
|
|
6099
|
+
out[0] = 1;
|
|
6100
|
+
out[5] = 1;
|
|
6101
|
+
out[10] = 1;
|
|
6102
|
+
out[15] = 1;
|
|
6103
|
+
return out;
|
|
6104
|
+
}
|
|
6105
|
+
function multiply(out, a, b) {
|
|
6106
|
+
var a00 = a[0],
|
|
6107
|
+
a01 = a[1],
|
|
6108
|
+
a02 = a[2],
|
|
6109
|
+
a03 = a[3];
|
|
6110
|
+
var a10 = a[4],
|
|
6111
|
+
a11 = a[5],
|
|
6112
|
+
a12 = a[6],
|
|
6113
|
+
a13 = a[7];
|
|
6114
|
+
var a20 = a[8],
|
|
6115
|
+
a21 = a[9],
|
|
6116
|
+
a22 = a[10],
|
|
6117
|
+
a23 = a[11];
|
|
6118
|
+
var a30 = a[12],
|
|
6119
|
+
a31 = a[13],
|
|
6120
|
+
a32 = a[14],
|
|
6121
|
+
a33 = a[15];
|
|
6122
|
+
var b0 = b[0],
|
|
6123
|
+
b1 = b[1],
|
|
6124
|
+
b2 = b[2],
|
|
6125
|
+
b3 = b[3];
|
|
6126
|
+
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
6127
|
+
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
6128
|
+
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
6129
|
+
out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
6130
|
+
b0 = b[4];
|
|
6131
|
+
b1 = b[5];
|
|
6132
|
+
b2 = b[6];
|
|
6133
|
+
b3 = b[7];
|
|
6134
|
+
out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
6135
|
+
out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
6136
|
+
out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
6137
|
+
out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
6138
|
+
b0 = b[8];
|
|
6139
|
+
b1 = b[9];
|
|
6140
|
+
b2 = b[10];
|
|
6141
|
+
b3 = b[11];
|
|
6142
|
+
out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
6143
|
+
out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
6144
|
+
out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
6145
|
+
out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
6146
|
+
b0 = b[12];
|
|
6147
|
+
b1 = b[13];
|
|
6148
|
+
b2 = b[14];
|
|
6149
|
+
b3 = b[15];
|
|
6150
|
+
out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
6151
|
+
out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
6152
|
+
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
6153
|
+
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
6154
|
+
return out;
|
|
6155
|
+
}
|
|
6156
|
+
function fromQuat(out, q) {
|
|
6157
|
+
var x = q[0],
|
|
6158
|
+
y = q[1],
|
|
6159
|
+
z = q[2],
|
|
6160
|
+
w = q[3];
|
|
6161
|
+
var x2 = x + x;
|
|
6162
|
+
var y2 = y + y;
|
|
6163
|
+
var z2 = z + z;
|
|
6164
|
+
var xx = x * x2;
|
|
6165
|
+
var yx = y * x2;
|
|
6166
|
+
var yy = y * y2;
|
|
6167
|
+
var zx = z * x2;
|
|
6168
|
+
var zy = z * y2;
|
|
6169
|
+
var zz = z * z2;
|
|
6170
|
+
var wx = w * x2;
|
|
6171
|
+
var wy = w * y2;
|
|
6172
|
+
var wz = w * z2;
|
|
6173
|
+
out[0] = 1 - yy - zz;
|
|
6174
|
+
out[1] = yx + wz;
|
|
6175
|
+
out[2] = zx - wy;
|
|
6176
|
+
out[3] = 0;
|
|
6177
|
+
out[4] = yx - wz;
|
|
6178
|
+
out[5] = 1 - xx - zz;
|
|
6179
|
+
out[6] = zy + wx;
|
|
6180
|
+
out[7] = 0;
|
|
6181
|
+
out[8] = zx + wy;
|
|
6182
|
+
out[9] = zy - wx;
|
|
6183
|
+
out[10] = 1 - xx - yy;
|
|
6184
|
+
out[11] = 0;
|
|
6185
|
+
out[12] = 0;
|
|
6186
|
+
out[13] = 0;
|
|
6187
|
+
out[14] = 0;
|
|
6188
|
+
out[15] = 1;
|
|
6189
|
+
return out;
|
|
6190
|
+
}
|
|
6191
|
+
|
|
6192
|
+
function create$1() {
|
|
6193
|
+
var out = new ARRAY_TYPE(2);
|
|
6194
|
+
if (ARRAY_TYPE != Float32Array) {
|
|
6195
|
+
out[0] = 0;
|
|
6196
|
+
out[1] = 0;
|
|
6197
|
+
}
|
|
6198
|
+
return out;
|
|
6199
|
+
}
|
|
6200
|
+
(function () {
|
|
6201
|
+
var vec = create$1();
|
|
6202
|
+
return function (a, stride, offset, count, fn, arg) {
|
|
6203
|
+
var i, l;
|
|
6204
|
+
if (!stride) {
|
|
6205
|
+
stride = 2;
|
|
6206
|
+
}
|
|
6207
|
+
if (!offset) {
|
|
6208
|
+
offset = 0;
|
|
6209
|
+
}
|
|
6210
|
+
if (count) {
|
|
6211
|
+
l = Math.min(count * stride + offset, a.length);
|
|
6212
|
+
} else {
|
|
6213
|
+
l = a.length;
|
|
6214
|
+
}
|
|
6215
|
+
for (i = offset; i < l; i += stride) {
|
|
6216
|
+
vec[0] = a[i];
|
|
6217
|
+
vec[1] = a[i + 1];
|
|
6218
|
+
fn(vec, vec, arg);
|
|
6219
|
+
a[i] = vec[0];
|
|
6220
|
+
a[i + 1] = vec[1];
|
|
6221
|
+
}
|
|
6222
|
+
return a;
|
|
6223
|
+
};
|
|
6224
|
+
})();
|
|
6225
|
+
|
|
6593
6226
|
const glsl$1 = (x) => x;
|
|
6594
6227
|
const vertexShader$1 = glsl$1 `
|
|
6595
6228
|
attribute vec4 a_position;
|
|
@@ -6624,8 +6257,7 @@ void main() {
|
|
|
6624
6257
|
// gl_FragColor = vec4(1.0, 0, 0, 1.0);
|
|
6625
6258
|
}
|
|
6626
6259
|
`;
|
|
6627
|
-
|
|
6628
|
-
const texArrayVertexShader = glsl$1 `#version 300 es
|
|
6260
|
+
const texArrayVertexShader$1 = glsl$1 `#version 300 es
|
|
6629
6261
|
|
|
6630
6262
|
in vec4 a_position;
|
|
6631
6263
|
in vec2 a_texCoord;
|
|
@@ -6644,7 +6276,7 @@ void main() {
|
|
|
6644
6276
|
v_texCoord = a_texCoord;
|
|
6645
6277
|
}
|
|
6646
6278
|
`;
|
|
6647
|
-
const texArrayFragmentShader = glsl$1 `#version 300 es
|
|
6279
|
+
const texArrayFragmentShader$1 = glsl$1 `#version 300 es
|
|
6648
6280
|
precision mediump float;
|
|
6649
6281
|
precision mediump int;
|
|
6650
6282
|
precision mediump sampler2DArray;
|
|
@@ -6662,7 +6294,6 @@ void main() {
|
|
|
6662
6294
|
}
|
|
6663
6295
|
|
|
6664
6296
|
`;
|
|
6665
|
-
// used for everything except Projection and Cube layers
|
|
6666
6297
|
class CompositionLayerRenderer {
|
|
6667
6298
|
constructor(layer, context) {
|
|
6668
6299
|
this.usesTextureArrayShaders = false;
|
|
@@ -6671,21 +6302,17 @@ void main() {
|
|
|
6671
6302
|
this.gl = context;
|
|
6672
6303
|
this.layer = layer;
|
|
6673
6304
|
let gl = this.gl;
|
|
6674
|
-
this.transformMatrix = create
|
|
6675
|
-
// if we are WebGL 2 and texture type is texture-array, we are using
|
|
6676
|
-
// the texture array GLES 3.0 shaders
|
|
6305
|
+
this.transformMatrix = create();
|
|
6677
6306
|
if (context instanceof WebGL2RenderingContext &&
|
|
6678
6307
|
this.layer.getTextureType() === XRTextureType['texture-array']) {
|
|
6679
6308
|
this.usesTextureArrayShaders = true;
|
|
6680
6309
|
}
|
|
6681
|
-
// create the program
|
|
6682
6310
|
if (this.usesTextureArrayShaders) {
|
|
6683
|
-
this.program = createProgram(gl, texArrayVertexShader, texArrayFragmentShader);
|
|
6311
|
+
this.program = createProgram(gl, texArrayVertexShader$1, texArrayFragmentShader$1);
|
|
6684
6312
|
}
|
|
6685
6313
|
else {
|
|
6686
6314
|
this.program = createProgram(gl, vertexShader$1, fragmentShader$1);
|
|
6687
6315
|
}
|
|
6688
|
-
// create program info
|
|
6689
6316
|
this.programInfo = {
|
|
6690
6317
|
attribLocations: {
|
|
6691
6318
|
a_position: gl.getAttribLocation(this.program, 'a_position'),
|
|
@@ -6709,15 +6336,8 @@ void main() {
|
|
|
6709
6336
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.savedVaoState.arrayBuffer);
|
|
6710
6337
|
this.savedVaoState.vao = this.savedVaoState.arrayBuffer = null;
|
|
6711
6338
|
}
|
|
6712
|
-
/**
|
|
6713
|
-
* Initializes the renderer. This should be run in the constructor of derived renderers.
|
|
6714
|
-
* The reason why it isn't just in the constructor of the base renderer is because creating
|
|
6715
|
-
* geometry may require additional computation in the derived class, which would run after a
|
|
6716
|
-
* super() call.
|
|
6717
|
-
*/
|
|
6718
6339
|
initialize() {
|
|
6719
6340
|
let gl = this.gl;
|
|
6720
|
-
// create media textures if needed
|
|
6721
6341
|
if (this.layer.isMediaLayer()) {
|
|
6722
6342
|
this.mediaTexture = gl.createTexture();
|
|
6723
6343
|
this.mediaTexturePolyfill = {
|
|
@@ -6732,15 +6352,11 @@ void main() {
|
|
|
6732
6352
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.layer.media.videoWidth, this.layer.media.videoHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
6733
6353
|
gl.bindTexture(gl.TEXTURE_2D, existingTextureBinding);
|
|
6734
6354
|
}
|
|
6735
|
-
// setup geometry and VAO
|
|
6736
6355
|
this._createVAOs();
|
|
6737
6356
|
}
|
|
6738
6357
|
render(session, frame) {
|
|
6739
6358
|
this.saveVaoState();
|
|
6740
6359
|
let gl = this.gl;
|
|
6741
|
-
// set viewport
|
|
6742
|
-
// we already rendered the views into the layer's color textures
|
|
6743
|
-
// so we can just render them all into the baselayer
|
|
6744
6360
|
let baseLayer = session.getBaseLayer();
|
|
6745
6361
|
let basePose = frame.getViewerPose(session.getReferenceSpace());
|
|
6746
6362
|
const existingActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
|
|
@@ -6755,11 +6371,8 @@ void main() {
|
|
|
6755
6371
|
if (this.layer.isMediaLayer()) {
|
|
6756
6372
|
throw new Error('This should never happen. Media layers should never be created with texture-array');
|
|
6757
6373
|
}
|
|
6758
|
-
// if we're using texture-array, there is always only a single entry in layer.colorTextures
|
|
6759
|
-
// and instead we use the layers uniform to render out individual pieces.
|
|
6760
6374
|
const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D_ARRAY);
|
|
6761
6375
|
gl.bindTexture(gl.TEXTURE_2D_ARRAY, this.layer.colorTextures[0]);
|
|
6762
|
-
// generate mips for static layers
|
|
6763
6376
|
if (this.layer.isStatic) {
|
|
6764
6377
|
if (this.layer.needsRedraw === true) {
|
|
6765
6378
|
gl.generateMipmap(gl.TEXTURE_2D_ARRAY);
|
|
@@ -6773,16 +6386,12 @@ void main() {
|
|
|
6773
6386
|
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, this.hasMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
|
|
6774
6387
|
let layer = 0;
|
|
6775
6388
|
if (this.layer.layout === XRLayerLayout.stereo) {
|
|
6776
|
-
// STEREO CASE - we only have multiple layers if we have a stereo layer, in which case
|
|
6777
|
-
// the right eye should use layer 1.
|
|
6778
6389
|
switch (view.eye) {
|
|
6779
6390
|
case 'right':
|
|
6780
6391
|
layer = 1;
|
|
6781
6392
|
break;
|
|
6782
6393
|
}
|
|
6783
6394
|
}
|
|
6784
|
-
// for stereo-left-right and stereo-top-bottom, we need to update
|
|
6785
|
-
// the texture UVs to get the correct slice of texture
|
|
6786
6395
|
if (this._shouldUseStereoTexturePoints()) {
|
|
6787
6396
|
this._renderInternalStereo(session, frame, view, layer);
|
|
6788
6397
|
}
|
|
@@ -6795,13 +6404,11 @@ void main() {
|
|
|
6795
6404
|
else {
|
|
6796
6405
|
const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_2D);
|
|
6797
6406
|
if (this.layer.isMediaLayer()) {
|
|
6798
|
-
// we have to bind the media to gl instead!
|
|
6799
6407
|
gl.bindTexture(gl.TEXTURE_2D, this.mediaTexture);
|
|
6800
6408
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
6801
6409
|
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.layer.media.videoWidth, this.layer.media.videoHeight, gl.RGBA, gl.UNSIGNED_BYTE, this.layer.media);
|
|
6802
6410
|
}
|
|
6803
6411
|
else if (this.layer.layout === XRLayerLayout.stereo) {
|
|
6804
|
-
// STEREO CASE - we have to pull out the multiple textures from the texture array
|
|
6805
6412
|
switch (view.eye) {
|
|
6806
6413
|
case 'right':
|
|
6807
6414
|
gl.bindTexture(gl.TEXTURE_2D, this.layer.colorTextures[1]);
|
|
@@ -6811,10 +6418,8 @@ void main() {
|
|
|
6811
6418
|
}
|
|
6812
6419
|
}
|
|
6813
6420
|
else {
|
|
6814
|
-
// for mono and split-screen stereo, we only have the one texture
|
|
6815
6421
|
gl.bindTexture(gl.TEXTURE_2D, this.layer.colorTextures[0]);
|
|
6816
6422
|
}
|
|
6817
|
-
// generate mips for static layers
|
|
6818
6423
|
if (this.layer.isStatic) {
|
|
6819
6424
|
if (this.layer.needsRedraw === true) {
|
|
6820
6425
|
gl.generateMipmap(gl.TEXTURE_2D);
|
|
@@ -6824,13 +6429,10 @@ void main() {
|
|
|
6824
6429
|
else {
|
|
6825
6430
|
this.hasMipmap = this.layer.mipLevels > 0;
|
|
6826
6431
|
}
|
|
6827
|
-
// Set the parameters so we can render any size image.
|
|
6828
6432
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
6829
6433
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
6830
6434
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.hasMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
|
|
6831
6435
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.hasMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
|
|
6832
|
-
// for stereo-left-right and stereo-top-bottom, we need to update
|
|
6833
|
-
// the texture UVs to get the correct slice of texture
|
|
6834
6436
|
if (this._shouldUseStereoTexturePoints()) {
|
|
6835
6437
|
this._renderInternalStereo(session, frame, view);
|
|
6836
6438
|
}
|
|
@@ -6843,19 +6445,14 @@ void main() {
|
|
|
6843
6445
|
}
|
|
6844
6446
|
this.restoreVaoState();
|
|
6845
6447
|
}
|
|
6846
|
-
// override this to set position values!
|
|
6847
6448
|
createPositionPoints() {
|
|
6848
6449
|
return new Float32Array([]);
|
|
6849
6450
|
}
|
|
6850
|
-
// override this to set texture coords!
|
|
6851
6451
|
createTextureUVs() {
|
|
6852
6452
|
return new Float32Array([]);
|
|
6853
6453
|
}
|
|
6854
|
-
// STEREO RENDERING FUNCTIONS
|
|
6855
|
-
////////////////////////////////
|
|
6856
|
-
// used in stereo-left-right and stereo-top-down layers to obtain UVs on a part of a texture
|
|
6857
6454
|
_offsetTextureUVsByRect(texture, inArray, textureRect) {
|
|
6858
|
-
textureRect = textureRect
|
|
6455
|
+
textureRect = textureRect !== null && textureRect !== void 0 ? textureRect : {
|
|
6859
6456
|
x: 0,
|
|
6860
6457
|
y: 0,
|
|
6861
6458
|
width: texture.width,
|
|
@@ -6880,30 +6477,22 @@ void main() {
|
|
|
6880
6477
|
return (this.layer.layout === XRLayerLayout['stereo-left-right'] ||
|
|
6881
6478
|
this.layer.layout === XRLayerLayout['stereo-top-bottom']);
|
|
6882
6479
|
}
|
|
6883
|
-
// NOTE: this does not initialize any data!
|
|
6884
|
-
// TODO: this is probably more efficient as a separate shader.
|
|
6885
6480
|
_setStereoTextureBuffer(index) {
|
|
6886
6481
|
let gl = this.gl;
|
|
6887
6482
|
gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
|
|
6888
|
-
// bind the texcoord buffer.
|
|
6889
6483
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
6890
6484
|
gl.bufferData(gl.ARRAY_BUFFER, this.stereoTexturePoints[index], gl.STATIC_DRAW);
|
|
6891
|
-
|
|
6892
|
-
var
|
|
6893
|
-
var
|
|
6894
|
-
var
|
|
6895
|
-
var
|
|
6896
|
-
var offset = 0; // start at the beginning of the buffer
|
|
6485
|
+
var size = 2;
|
|
6486
|
+
var type = gl.FLOAT;
|
|
6487
|
+
var normalize = false;
|
|
6488
|
+
var stride = 0;
|
|
6489
|
+
var offset = 0;
|
|
6897
6490
|
gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
|
|
6898
6491
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
6899
6492
|
}
|
|
6900
|
-
// INITIALIZATION
|
|
6901
|
-
// THESE FUNCTIONS ARE CALLED IN CONSTRUCTOR
|
|
6902
|
-
//////////////////////////////////////////////
|
|
6903
6493
|
_recalculateVertices() {
|
|
6904
6494
|
this.positionPoints = this.createPositionPoints();
|
|
6905
6495
|
this.texturePoints = this.createTextureUVs();
|
|
6906
|
-
// calculate stereo layers if needed
|
|
6907
6496
|
const viewport = {
|
|
6908
6497
|
x: 0,
|
|
6909
6498
|
y: 0,
|
|
@@ -6917,9 +6506,6 @@ void main() {
|
|
|
6917
6506
|
this.stereoTexturePoints[0] = this._offsetTextureUVsByRect(this.mediaTexturePolyfill, this.texturePoints, viewport);
|
|
6918
6507
|
initializeViewport(viewport, this.mediaTexturePolyfill, this.layer.layout, 1, 2);
|
|
6919
6508
|
this.stereoTexturePoints[1] = this._offsetTextureUVsByRect(this.mediaTexturePolyfill, this.texturePoints, viewport);
|
|
6920
|
-
// the texture is expected to be flipped on the y axis, which for top-down stereo causes
|
|
6921
|
-
// left-right eye positions to be flipped too. So we fix that by switching the eye location
|
|
6922
|
-
// in the texture
|
|
6923
6509
|
if (this.layer.layout === XRLayerLayout['stereo-top-bottom']) {
|
|
6924
6510
|
[this.stereoTexturePoints[0], this.stereoTexturePoints[1]] = [
|
|
6925
6511
|
this.stereoTexturePoints[1],
|
|
@@ -6932,9 +6518,6 @@ void main() {
|
|
|
6932
6518
|
this.stereoTexturePoints[0] = this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0], this.texturePoints, viewport);
|
|
6933
6519
|
initializeViewport(viewport, this.layer.colorTexturesMeta[0], this.layer.layout, 1, 2);
|
|
6934
6520
|
this.stereoTexturePoints[1] = this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0], this.texturePoints, viewport);
|
|
6935
|
-
// the texture is expected to be flipped on the y axis, which for top-down stereo causes
|
|
6936
|
-
// left-right eye positions to be flipped too. So we fix that by switching the eye location
|
|
6937
|
-
// in the texture
|
|
6938
6521
|
if (this.layer.layout === XRLayerLayout['stereo-top-bottom']) {
|
|
6939
6522
|
[this.stereoTexturePoints[0], this.stereoTexturePoints[1]] = [
|
|
6940
6523
|
this.stereoTexturePoints[1],
|
|
@@ -6946,66 +6529,44 @@ void main() {
|
|
|
6946
6529
|
_createVAOs() {
|
|
6947
6530
|
this._recalculateVertices();
|
|
6948
6531
|
let gl = this.gl;
|
|
6949
|
-
// makes sure that VAOs are usable on both WebGL1 and WebGL2
|
|
6950
6532
|
this.vaoGl = applyVAOExtension(gl);
|
|
6951
|
-
// push vao existing vao state
|
|
6952
6533
|
this.saveVaoState();
|
|
6953
|
-
// position
|
|
6954
6534
|
let positionBuffer = gl.createBuffer();
|
|
6955
6535
|
this.vao = this.vaoGl.createVertexArray();
|
|
6956
6536
|
this.vaoGl.bindVertexArray(this.vao);
|
|
6957
|
-
// Turn on the position attribute
|
|
6958
6537
|
gl.enableVertexAttribArray(this.programInfo.attribLocations.a_position);
|
|
6959
|
-
// Bind the position buffer.
|
|
6960
6538
|
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
6961
6539
|
const positions = this.positionPoints;
|
|
6962
6540
|
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
|
|
6963
|
-
|
|
6964
|
-
var
|
|
6965
|
-
var
|
|
6966
|
-
var
|
|
6967
|
-
var
|
|
6968
|
-
var offset = 0; // start at the beginning of the buffer
|
|
6541
|
+
var size = 3;
|
|
6542
|
+
var type = gl.FLOAT;
|
|
6543
|
+
var normalize = false;
|
|
6544
|
+
var stride = 0;
|
|
6545
|
+
var offset = 0;
|
|
6969
6546
|
gl.vertexAttribPointer(this.programInfo.attribLocations.a_position, size, type, normalize, stride, offset);
|
|
6970
|
-
// textures
|
|
6971
6547
|
gl.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord);
|
|
6972
6548
|
this.texcoordBuffer = gl.createBuffer();
|
|
6973
|
-
// bind the texcoord buffer.
|
|
6974
6549
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
|
|
6975
6550
|
gl.bufferData(gl.ARRAY_BUFFER, this.texturePoints, gl.STATIC_DRAW);
|
|
6976
|
-
|
|
6977
|
-
var
|
|
6978
|
-
var
|
|
6979
|
-
var
|
|
6980
|
-
var
|
|
6981
|
-
var offset = 0; // start at the beginning of the buffer
|
|
6551
|
+
var size = 2;
|
|
6552
|
+
var type = gl.FLOAT;
|
|
6553
|
+
var normalize = false;
|
|
6554
|
+
var stride = 0;
|
|
6555
|
+
var offset = 0;
|
|
6982
6556
|
gl.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord, size, type, normalize, stride, offset);
|
|
6983
|
-
// pop vao state
|
|
6984
6557
|
this.restoreVaoState();
|
|
6985
6558
|
}
|
|
6986
|
-
// RENDERING
|
|
6987
|
-
/////////////////
|
|
6988
|
-
/**
|
|
6989
|
-
* @param frame
|
|
6990
|
-
* @param view
|
|
6991
|
-
* @param layer only relevant for texture_arrays - used to determine which layer to render from.
|
|
6992
|
-
*/
|
|
6993
6559
|
_renderInternal(session, frame, view, layer) {
|
|
6994
6560
|
let gl = this.gl;
|
|
6995
|
-
// Tell it to use our program (pair of shaders)
|
|
6996
6561
|
const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
6997
6562
|
gl.useProgram(this.program);
|
|
6998
6563
|
this.vaoGl.bindVertexArray(this.vao);
|
|
6999
|
-
// LAYER
|
|
7000
6564
|
if (this.usesTextureArrayShaders) {
|
|
7001
6565
|
gl.uniform1i(this.programInfo.uniformLocations.u_layer, layer);
|
|
7002
6566
|
}
|
|
7003
|
-
// MATRIX
|
|
7004
|
-
// set matrix
|
|
7005
6567
|
this._setTransformMatrix(session, frame, view);
|
|
7006
6568
|
gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix, false, this.transformMatrix);
|
|
7007
6569
|
gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix, false, view.projectionMatrix);
|
|
7008
|
-
// Draw the shape
|
|
7009
6570
|
var primitiveType = gl.TRIANGLES;
|
|
7010
6571
|
var offset = 0;
|
|
7011
6572
|
var count = this.positionPoints.length / 3;
|
|
@@ -7013,32 +6574,21 @@ void main() {
|
|
|
7013
6574
|
this.vaoGl.bindVertexArray(null);
|
|
7014
6575
|
gl.useProgram(existingProgram);
|
|
7015
6576
|
}
|
|
7016
|
-
// this is used only for stereo-left-right and stereo-top-bottom layers, and is used to render
|
|
7017
|
-
// a part of a texture to a view.
|
|
7018
6577
|
_renderInternalStereo(session, frame, view, layer) {
|
|
7019
6578
|
if (view.eye === 'none') {
|
|
7020
6579
|
return this._renderInternal(session, frame, view);
|
|
7021
6580
|
}
|
|
7022
6581
|
let gl = this.gl;
|
|
7023
6582
|
this.vaoGl.bindVertexArray(this.vao);
|
|
7024
|
-
// Tell it to use our program (pair of shaders)
|
|
7025
6583
|
const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
7026
6584
|
gl.useProgram(this.program);
|
|
7027
|
-
// set position array and texture array
|
|
7028
|
-
// we have to set the texture buffer data for every eye
|
|
7029
6585
|
this._setStereoTextureBuffer(view.eye === 'right' ? 1 : 0);
|
|
7030
|
-
// LAYER
|
|
7031
6586
|
if (this.usesTextureArrayShaders) {
|
|
7032
6587
|
gl.uniform1i(this.programInfo.uniformLocations.u_layer, layer);
|
|
7033
6588
|
}
|
|
7034
|
-
// MATRIX
|
|
7035
|
-
// set matrix
|
|
7036
6589
|
this._setTransformMatrix(session, frame, view);
|
|
7037
|
-
// we want the inverse, taken from the explainer:
|
|
7038
|
-
// https://immersive-web.github.io/webxr/explainer.html#viewer-tracking-with-webgl
|
|
7039
6590
|
gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix, false, this.transformMatrix);
|
|
7040
6591
|
gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix, false, view.projectionMatrix);
|
|
7041
|
-
// Draw the shape
|
|
7042
6592
|
var primitiveType = gl.TRIANGLES;
|
|
7043
6593
|
var offset = 0;
|
|
7044
6594
|
var count = this.positionPoints.length / 3;
|
|
@@ -7048,26 +6598,11 @@ void main() {
|
|
|
7048
6598
|
}
|
|
7049
6599
|
_setTransformMatrix(session, frame, view) {
|
|
7050
6600
|
let objPose = frame.getPose(this.layer.space, session.getReferenceSpace());
|
|
7051
|
-
multiply
|
|
7052
|
-
|
|
7053
|
-
multiply$1(this.transformMatrix, view.transform.inverse.matrix, this.transformMatrix);
|
|
6601
|
+
multiply(this.transformMatrix, objPose.transform.matrix, this.layer.transform.matrix);
|
|
6602
|
+
multiply(this.transformMatrix, view.transform.inverse.matrix, this.transformMatrix);
|
|
7054
6603
|
}
|
|
7055
6604
|
}
|
|
7056
6605
|
|
|
7057
|
-
/**
|
|
7058
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7059
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7060
|
-
* you may not use this file except in compliance with the License.
|
|
7061
|
-
* You may obtain a copy of the License at
|
|
7062
|
-
*
|
|
7063
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7064
|
-
*
|
|
7065
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7066
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7067
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7068
|
-
* See the License for the specific language governing permissions and
|
|
7069
|
-
* limitations under the License.
|
|
7070
|
-
*/
|
|
7071
6606
|
class QuadRenderer extends CompositionLayerRenderer {
|
|
7072
6607
|
constructor(layer, context) {
|
|
7073
6608
|
super(layer, context);
|
|
@@ -7078,27 +6613,21 @@ void main() {
|
|
|
7078
6613
|
const height = this.layer.height;
|
|
7079
6614
|
const z = 0;
|
|
7080
6615
|
const positions = [
|
|
7081
|
-
// bottom left
|
|
7082
6616
|
-width,
|
|
7083
6617
|
-height,
|
|
7084
6618
|
z,
|
|
7085
|
-
// bottom right
|
|
7086
6619
|
width,
|
|
7087
6620
|
-height,
|
|
7088
6621
|
z,
|
|
7089
|
-
// top left
|
|
7090
6622
|
-width,
|
|
7091
6623
|
height,
|
|
7092
6624
|
z,
|
|
7093
|
-
// top left
|
|
7094
6625
|
-width,
|
|
7095
6626
|
height,
|
|
7096
6627
|
z,
|
|
7097
|
-
// bottom right
|
|
7098
6628
|
width,
|
|
7099
6629
|
-height,
|
|
7100
6630
|
z,
|
|
7101
|
-
// top right
|
|
7102
6631
|
width,
|
|
7103
6632
|
height,
|
|
7104
6633
|
z,
|
|
@@ -7106,26 +6635,10 @@ void main() {
|
|
|
7106
6635
|
return new Float32Array(positions);
|
|
7107
6636
|
}
|
|
7108
6637
|
createTextureUVs() {
|
|
7109
|
-
return new Float32Array([
|
|
7110
|
-
0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
|
|
7111
|
-
]);
|
|
6638
|
+
return new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]);
|
|
7112
6639
|
}
|
|
7113
6640
|
}
|
|
7114
6641
|
|
|
7115
|
-
/**
|
|
7116
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7117
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7118
|
-
* you may not use this file except in compliance with the License.
|
|
7119
|
-
* You may obtain a copy of the License at
|
|
7120
|
-
*
|
|
7121
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7122
|
-
*
|
|
7123
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7124
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7125
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7126
|
-
* See the License for the specific language governing permissions and
|
|
7127
|
-
* limitations under the License.
|
|
7128
|
-
*/
|
|
7129
6642
|
class CylinderRenderer extends CompositionLayerRenderer {
|
|
7130
6643
|
constructor(layer, context) {
|
|
7131
6644
|
super(layer, context);
|
|
@@ -7134,41 +6647,31 @@ void main() {
|
|
|
7134
6647
|
}
|
|
7135
6648
|
createPositionPoints() {
|
|
7136
6649
|
const positions = [];
|
|
7137
|
-
// assume the central point is (0, 0, 0)
|
|
7138
6650
|
const angle = this.layer.centralAngle;
|
|
7139
6651
|
const height = this.layer.height;
|
|
7140
6652
|
const radius = this.layer.radius;
|
|
7141
6653
|
const radiansPerSegment = angle / this.segments;
|
|
7142
6654
|
const theta = Math.PI / 2 - angle / 2;
|
|
7143
6655
|
const unitCirclePositions = [];
|
|
7144
|
-
|
|
7145
|
-
const firstUnitPoint = create();
|
|
6656
|
+
const firstUnitPoint = create$1();
|
|
7146
6657
|
firstUnitPoint[0] = radius * Math.cos(theta);
|
|
7147
6658
|
firstUnitPoint[1] = -radius * Math.sin(theta);
|
|
7148
6659
|
unitCirclePositions.push(firstUnitPoint);
|
|
7149
6660
|
for (let i = 0; i < this.segments; i++) {
|
|
7150
|
-
const nextPoint = create();
|
|
6661
|
+
const nextPoint = create$1();
|
|
7151
6662
|
nextPoint[0] = radius * Math.cos(theta + radiansPerSegment * (i + 1));
|
|
7152
6663
|
nextPoint[1] = -radius * Math.sin(theta + radiansPerSegment * (i + 1));
|
|
7153
6664
|
unitCirclePositions.push(nextPoint);
|
|
7154
6665
|
}
|
|
7155
|
-
// flip the array to get the segments on the unit circle
|
|
7156
6666
|
unitCirclePositions.reverse();
|
|
7157
6667
|
for (let i = 0; i < this.segments; i++) {
|
|
7158
6668
|
const u = unitCirclePositions[i];
|
|
7159
6669
|
const v = unitCirclePositions[i + 1];
|
|
7160
|
-
// we need six points per quad:
|
|
7161
|
-
// bottom left
|
|
7162
6670
|
positions.push(u[0], -height / 2, u[1]);
|
|
7163
|
-
// bottom right
|
|
7164
6671
|
positions.push(v[0], -height / 2, v[1]);
|
|
7165
|
-
//top left
|
|
7166
6672
|
positions.push(u[0], height / 2, u[1]);
|
|
7167
|
-
//top left
|
|
7168
6673
|
positions.push(u[0], height / 2, u[1]);
|
|
7169
|
-
// bottom right
|
|
7170
6674
|
positions.push(v[0], -height / 2, v[1]);
|
|
7171
|
-
// top right
|
|
7172
6675
|
positions.push(v[0], height / 2, v[1]);
|
|
7173
6676
|
}
|
|
7174
6677
|
return new Float32Array(positions);
|
|
@@ -7176,41 +6679,20 @@ void main() {
|
|
|
7176
6679
|
createTextureUVs() {
|
|
7177
6680
|
let textureUVs = [];
|
|
7178
6681
|
const texturePercent = 1.0 / this.segments;
|
|
7179
|
-
// texture UVs are 2D. We still need 6 vertices per quad.
|
|
7180
6682
|
for (let i = 0; i < this.segments; i++) {
|
|
7181
6683
|
let leftX = texturePercent * i;
|
|
7182
6684
|
let rightX = texturePercent * (i + 1);
|
|
7183
|
-
// bottom left
|
|
7184
6685
|
textureUVs.push(leftX, 0);
|
|
7185
|
-
// bottom right
|
|
7186
6686
|
textureUVs.push(rightX, 0);
|
|
7187
|
-
// top left
|
|
7188
6687
|
textureUVs.push(leftX, 1);
|
|
7189
|
-
// top left
|
|
7190
6688
|
textureUVs.push(leftX, 1);
|
|
7191
|
-
// bottom right
|
|
7192
6689
|
textureUVs.push(rightX, 0);
|
|
7193
|
-
// top right
|
|
7194
6690
|
textureUVs.push(rightX, 1);
|
|
7195
6691
|
}
|
|
7196
6692
|
return new Float32Array(textureUVs);
|
|
7197
6693
|
}
|
|
7198
6694
|
}
|
|
7199
6695
|
|
|
7200
|
-
/**
|
|
7201
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7202
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7203
|
-
* you may not use this file except in compliance with the License.
|
|
7204
|
-
* You may obtain a copy of the License at
|
|
7205
|
-
*
|
|
7206
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7207
|
-
*
|
|
7208
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7209
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7210
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7211
|
-
* See the License for the specific language governing permissions and
|
|
7212
|
-
* limitations under the License.
|
|
7213
|
-
*/
|
|
7214
6696
|
class EquirectRenderer extends CompositionLayerRenderer {
|
|
7215
6697
|
constructor(layer, context) {
|
|
7216
6698
|
super(layer, context);
|
|
@@ -7223,25 +6705,18 @@ void main() {
|
|
|
7223
6705
|
if (radius === 0) {
|
|
7224
6706
|
radius = 25;
|
|
7225
6707
|
}
|
|
7226
|
-
// TODO investigate why a bigger radius doesn't work
|
|
7227
6708
|
if (radius > 25) {
|
|
7228
6709
|
radius = 25;
|
|
7229
6710
|
}
|
|
7230
|
-
// this uses spherical coordinates.
|
|
7231
|
-
// theta = the 'horizontal' axis, spanning the x and z axes Note that negative z is forward
|
|
7232
|
-
// phi = the 'vertical' axis, going up and down the y axis.
|
|
7233
6711
|
const horizAngle = this.layer.centralHorizontalAngle;
|
|
7234
|
-
// phi (vertical) values need to be mapped from 0 to pi, where 0 is the top
|
|
7235
|
-
// of the sphere and pi is the bottom. So we do that here...
|
|
7236
6712
|
const phi1 = this.layer.upperVerticalAngle + Math.PI / 2;
|
|
7237
6713
|
const phi2 = this.layer.lowerVerticalAngle + Math.PI / 2;
|
|
7238
|
-
const startPhi = phi1;
|
|
7239
|
-
const endPhi = phi2;
|
|
7240
|
-
const startTheta = Math.PI / 2 - horizAngle / 2;
|
|
7241
|
-
const endTheta = startTheta + horizAngle;
|
|
6714
|
+
const startPhi = phi1;
|
|
6715
|
+
const endPhi = phi2;
|
|
6716
|
+
const startTheta = Math.PI / 2 - horizAngle / 2;
|
|
6717
|
+
const endTheta = startTheta + horizAngle;
|
|
7242
6718
|
const phiRange = endPhi - startPhi;
|
|
7243
6719
|
const thetaRange = endTheta - startTheta;
|
|
7244
|
-
// base points
|
|
7245
6720
|
const basePoints = [];
|
|
7246
6721
|
for (let y = 0; y <= this.segmentsPerAxis; y++) {
|
|
7247
6722
|
for (let x = 0; x <= this.segmentsPerAxis; x++) {
|
|
@@ -7252,29 +6727,18 @@ void main() {
|
|
|
7252
6727
|
let phi = phiRange * v + startPhi;
|
|
7253
6728
|
const ux = Math.cos(theta) * Math.sin(phi);
|
|
7254
6729
|
const uy = Math.cos(phi);
|
|
7255
|
-
// this is negative because negative z is forward...
|
|
7256
6730
|
const uz = -Math.sin(theta) * Math.sin(phi);
|
|
7257
6731
|
basePoints.push([r * ux, r * uy, r * uz]);
|
|
7258
6732
|
}
|
|
7259
6733
|
}
|
|
7260
|
-
// now we have all the points of the sphere in...something of an order.
|
|
7261
|
-
// let's convert it to positions
|
|
7262
|
-
// if we decide to change the x and y, this should be the x
|
|
7263
6734
|
const numVertsAround = this.segmentsPerAxis + 1;
|
|
7264
6735
|
for (let x = 0; x < this.segmentsPerAxis; x++) {
|
|
7265
6736
|
for (let y = 0; y < this.segmentsPerAxis; y++) {
|
|
7266
|
-
// create the quad from those four points
|
|
7267
|
-
// bottom left
|
|
7268
6737
|
positions.push(...basePoints[y * numVertsAround + x]);
|
|
7269
|
-
// bottom right
|
|
7270
6738
|
positions.push(...basePoints[y * numVertsAround + x + 1]);
|
|
7271
|
-
//top left
|
|
7272
6739
|
positions.push(...basePoints[(y + 1) * numVertsAround + x]);
|
|
7273
|
-
//top left
|
|
7274
6740
|
positions.push(...basePoints[(y + 1) * numVertsAround + x]);
|
|
7275
|
-
// bottom right
|
|
7276
6741
|
positions.push(...basePoints[y * numVertsAround + x + 1]);
|
|
7277
|
-
// top right
|
|
7278
6742
|
positions.push(...basePoints[(y + 1) * numVertsAround + x + 1]);
|
|
7279
6743
|
}
|
|
7280
6744
|
}
|
|
@@ -7293,17 +6757,11 @@ void main() {
|
|
|
7293
6757
|
const numVertsAround = this.segmentsPerAxis + 1;
|
|
7294
6758
|
for (let x = 0; x < this.segmentsPerAxis; x++) {
|
|
7295
6759
|
for (let y = 0; y < this.segmentsPerAxis; y++) {
|
|
7296
|
-
// bottom left
|
|
7297
6760
|
triUVs.push(...baseUVs[y * numVertsAround + x]);
|
|
7298
|
-
// bottom right
|
|
7299
6761
|
triUVs.push(...baseUVs[y * numVertsAround + x + 1]);
|
|
7300
|
-
//top left
|
|
7301
6762
|
triUVs.push(...baseUVs[(y + 1) * numVertsAround + x]);
|
|
7302
|
-
//top left
|
|
7303
6763
|
triUVs.push(...baseUVs[(y + 1) * numVertsAround + x]);
|
|
7304
|
-
// bottom right
|
|
7305
6764
|
triUVs.push(...baseUVs[y * numVertsAround + x + 1]);
|
|
7306
|
-
// top right
|
|
7307
6765
|
triUVs.push(...baseUVs[(y + 1) * numVertsAround + x + 1]);
|
|
7308
6766
|
}
|
|
7309
6767
|
}
|
|
@@ -7311,28 +6769,14 @@ void main() {
|
|
|
7311
6769
|
}
|
|
7312
6770
|
}
|
|
7313
6771
|
|
|
7314
|
-
/**
|
|
7315
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7316
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7317
|
-
* you may not use this file except in compliance with the License.
|
|
7318
|
-
* You may obtain a copy of the License at
|
|
7319
|
-
*
|
|
7320
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7321
|
-
*
|
|
7322
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7323
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7324
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7325
|
-
* See the License for the specific language governing permissions and
|
|
7326
|
-
* limitations under the License.
|
|
7327
|
-
*/
|
|
7328
6772
|
const defaultCubeLayerInit = {
|
|
7329
6773
|
colorFormat: 0x1908,
|
|
7330
6774
|
mipLevels: 1,
|
|
7331
6775
|
layout: XRLayerLayout.mono,
|
|
7332
6776
|
isStatic: false,
|
|
7333
|
-
space: null,
|
|
7334
|
-
viewPixelHeight: 0,
|
|
7335
|
-
viewPixelWidth: 0,
|
|
6777
|
+
space: null,
|
|
6778
|
+
viewPixelHeight: 0,
|
|
6779
|
+
viewPixelWidth: 0,
|
|
7336
6780
|
};
|
|
7337
6781
|
class XRCubeLayer extends XRCompositionLayerPolyfill {
|
|
7338
6782
|
constructor(init = defaultCubeLayerInit) {
|
|
@@ -7340,8 +6784,7 @@ void main() {
|
|
|
7340
6784
|
if (!isReferenceSpace(init.space)) {
|
|
7341
6785
|
throw new TypeError("XRCubeLayer's space needs to be an XRReferenceSpace");
|
|
7342
6786
|
}
|
|
7343
|
-
|
|
7344
|
-
this.init = { ...defaultCubeLayerInit, ...init };
|
|
6787
|
+
this.init = Object.assign(Object.assign({}, defaultCubeLayerInit), init);
|
|
7345
6788
|
this.space = this.init.space;
|
|
7346
6789
|
this.isStatic = this.init.isStatic;
|
|
7347
6790
|
if (this.init.orientation) {
|
|
@@ -7386,8 +6829,6 @@ void main() {
|
|
|
7386
6829
|
if (!this.init.depthFormat) {
|
|
7387
6830
|
return;
|
|
7388
6831
|
}
|
|
7389
|
-
// If context is a WebGLRenderingContext and the WEBGL_depth_texture extension
|
|
7390
|
-
// is not enabled in context, throw TypeError
|
|
7391
6832
|
if (this.context instanceof WebGLRenderingContext) {
|
|
7392
6833
|
let depthExtension = this.context.getExtension('WEBGL_depth_texture');
|
|
7393
6834
|
if (!depthExtension) {
|
|
@@ -7418,7 +6859,6 @@ void main() {
|
|
|
7418
6859
|
};
|
|
7419
6860
|
const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);
|
|
7420
6861
|
this.context.bindTexture(this.context.TEXTURE_CUBE_MAP, texture);
|
|
7421
|
-
// initialize size for all the sides of the cubemap
|
|
7422
6862
|
for (let i = 0; i < 6; i++) {
|
|
7423
6863
|
this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, textureMeta.textureFormat, textureMeta.width, textureMeta.height, 0, textureMeta.textureFormat, this.context.UNSIGNED_BYTE, null);
|
|
7424
6864
|
}
|
|
@@ -7437,8 +6877,6 @@ void main() {
|
|
|
7437
6877
|
};
|
|
7438
6878
|
const existingTextureBinding = this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);
|
|
7439
6879
|
this.context.bindTexture(this.context.TEXTURE_CUBE_MAP, texture);
|
|
7440
|
-
// DEPTH_COMPONENT is not a valid internalFormat in WebGL2.
|
|
7441
|
-
// https://stackoverflow.com/a/60703526
|
|
7442
6880
|
let internalFormat = this.init.depthFormat;
|
|
7443
6881
|
if (this.context instanceof WebGL2RenderingContext) {
|
|
7444
6882
|
if (internalFormat === this.context.DEPTH_COMPONENT) {
|
|
@@ -7448,7 +6886,6 @@ void main() {
|
|
|
7448
6886
|
internalFormat = this.context.DEPTH24_STENCIL8;
|
|
7449
6887
|
}
|
|
7450
6888
|
}
|
|
7451
|
-
// initialize size for all the sides of the cubemap
|
|
7452
6889
|
for (let i = 0; i < 6; i++) {
|
|
7453
6890
|
this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, textureMeta.width, textureMeta.height, 0, textureMeta.textureFormat, this.context.UNSIGNED_INT, null);
|
|
7454
6891
|
}
|
|
@@ -7460,23 +6897,8 @@ void main() {
|
|
|
7460
6897
|
}
|
|
7461
6898
|
}
|
|
7462
6899
|
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7466
|
-
* you may not use this file except in compliance with the License.
|
|
7467
|
-
* You may obtain a copy of the License at
|
|
7468
|
-
*
|
|
7469
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7470
|
-
*
|
|
7471
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7472
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7473
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7474
|
-
* See the License for the specific language governing permissions and
|
|
7475
|
-
* limitations under the License.
|
|
7476
|
-
*/
|
|
7477
|
-
// template tagging for syntax highlight
|
|
7478
|
-
const glsl = (x) => x;
|
|
7479
|
-
const vertexShader = glsl `
|
|
6900
|
+
const glsl$2 = (x) => x;
|
|
6901
|
+
const vertexShader$2 = glsl$2 `
|
|
7480
6902
|
attribute vec4 a_position;
|
|
7481
6903
|
uniform mat4 u_projectionMatrix;
|
|
7482
6904
|
uniform mat4 u_matrix;
|
|
@@ -7488,7 +6910,7 @@ void main() {
|
|
|
7488
6910
|
v_normal = normalize(a_position.xyz);
|
|
7489
6911
|
}
|
|
7490
6912
|
`;
|
|
7491
|
-
const fragmentShader = glsl `
|
|
6913
|
+
const fragmentShader$2 = glsl$2 `
|
|
7492
6914
|
precision mediump float;
|
|
7493
6915
|
|
|
7494
6916
|
varying vec3 v_normal;
|
|
@@ -7499,18 +6921,14 @@ void main() {
|
|
|
7499
6921
|
gl_FragColor = textureCube(u_texture, normalize(v_normal));
|
|
7500
6922
|
}
|
|
7501
6923
|
`;
|
|
7502
|
-
// see https://webglfundamentals.org/webgl/lessons/webgl-cube-maps.html
|
|
7503
|
-
// and https://github.com/xdsopl/webgl/blob/master/cubemap.html
|
|
7504
6924
|
class CubeRenderer {
|
|
7505
6925
|
constructor(layer, gl) {
|
|
7506
6926
|
this.savedVaoState = { vao: null, arrayBuffer: null };
|
|
7507
6927
|
this.hasMipmap = false;
|
|
7508
6928
|
this.layer = layer;
|
|
7509
6929
|
this.gl = gl;
|
|
7510
|
-
this.transformMatrix = create
|
|
7511
|
-
|
|
7512
|
-
this.program = createProgram(gl, vertexShader, fragmentShader);
|
|
7513
|
-
// create program info
|
|
6930
|
+
this.transformMatrix = create();
|
|
6931
|
+
this.program = createProgram(gl, vertexShader$2, fragmentShader$2);
|
|
7514
6932
|
this.programInfo = {
|
|
7515
6933
|
attribLocations: {
|
|
7516
6934
|
a_position: gl.getAttribLocation(this.program, 'a_position'),
|
|
@@ -7521,7 +6939,6 @@ void main() {
|
|
|
7521
6939
|
u_projectionMatrix: gl.getUniformLocation(this.program, 'u_projectionMatrix'),
|
|
7522
6940
|
},
|
|
7523
6941
|
};
|
|
7524
|
-
// setup geometry and VAO
|
|
7525
6942
|
this._createVAOs();
|
|
7526
6943
|
}
|
|
7527
6944
|
saveVaoState() {
|
|
@@ -7544,7 +6961,6 @@ void main() {
|
|
|
7544
6961
|
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
|
7545
6962
|
gl.activeTexture(gl.TEXTURE0);
|
|
7546
6963
|
const existingTextureBinding = gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP);
|
|
7547
|
-
// STEREO CASE: 0 is left eye, 1 is right eye
|
|
7548
6964
|
if (this.layer.layout === XRLayerLayout.stereo) {
|
|
7549
6965
|
const index = view.eye === 'right' ? 1 : 0;
|
|
7550
6966
|
gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.layer.colorTextures[index]);
|
|
@@ -7552,7 +6968,6 @@ void main() {
|
|
|
7552
6968
|
else {
|
|
7553
6969
|
gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.layer.colorTextures[0]);
|
|
7554
6970
|
}
|
|
7555
|
-
// generate mips for static layers
|
|
7556
6971
|
if (this.layer.isStatic) {
|
|
7557
6972
|
if (this.layer.needsRedraw === true) {
|
|
7558
6973
|
gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
|
|
@@ -7570,10 +6985,8 @@ void main() {
|
|
|
7570
6985
|
}
|
|
7571
6986
|
this.restoreVaoState();
|
|
7572
6987
|
}
|
|
7573
|
-
// override this to set position values!
|
|
7574
6988
|
createPositionPoints() {
|
|
7575
6989
|
const w = 0.5;
|
|
7576
|
-
// prettier-ignore
|
|
7577
6990
|
const positions = [
|
|
7578
6991
|
-w, -w, -w,
|
|
7579
6992
|
-w, w, -w,
|
|
@@ -7619,9 +7032,6 @@ void main() {
|
|
|
7619
7032
|
const existingProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
7620
7033
|
gl.useProgram(this.program);
|
|
7621
7034
|
this.vaoGl.bindVertexArray(this.vao);
|
|
7622
|
-
// MATRIX
|
|
7623
|
-
// set matrix
|
|
7624
|
-
// apply only the orientation of the pose and the layer to the transform matrix.
|
|
7625
7035
|
fromQuat(this.transformMatrix, [
|
|
7626
7036
|
orientation.x,
|
|
7627
7037
|
orientation.y,
|
|
@@ -7629,7 +7039,7 @@ void main() {
|
|
|
7629
7039
|
orientation.w,
|
|
7630
7040
|
]);
|
|
7631
7041
|
if (!this._poseOrientationMatrix) {
|
|
7632
|
-
this._poseOrientationMatrix = create
|
|
7042
|
+
this._poseOrientationMatrix = create();
|
|
7633
7043
|
}
|
|
7634
7044
|
fromQuat(this._poseOrientationMatrix, [
|
|
7635
7045
|
view.transform.inverse.orientation.x,
|
|
@@ -7637,13 +7047,10 @@ void main() {
|
|
|
7637
7047
|
view.transform.inverse.orientation.z,
|
|
7638
7048
|
view.transform.inverse.orientation.w,
|
|
7639
7049
|
]);
|
|
7640
|
-
multiply
|
|
7050
|
+
multiply(this.transformMatrix, this.transformMatrix, this._poseOrientationMatrix);
|
|
7641
7051
|
gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix, false, this.transformMatrix);
|
|
7642
7052
|
gl.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix, false, view.projectionMatrix);
|
|
7643
|
-
// TEXTURE
|
|
7644
|
-
// Tell the shader to use texture unit 0 for u_texture
|
|
7645
7053
|
gl.uniform1i(this.programInfo.uniformLocations.u_texture, 0);
|
|
7646
|
-
// Draw the shape
|
|
7647
7054
|
var primitiveType = gl.TRIANGLES;
|
|
7648
7055
|
var offset = 0;
|
|
7649
7056
|
var count = this.positionPoints.length / 3;
|
|
@@ -7657,46 +7064,25 @@ void main() {
|
|
|
7657
7064
|
_createVAOs() {
|
|
7658
7065
|
this._recalculateVertices();
|
|
7659
7066
|
let gl = this.gl;
|
|
7660
|
-
// makes sure that VAOs are usable on both WebGL1 and WebGL2
|
|
7661
7067
|
this.vaoGl = applyVAOExtension(gl);
|
|
7662
7068
|
this.saveVaoState();
|
|
7663
|
-
// position
|
|
7664
7069
|
let positionBuffer = gl.createBuffer();
|
|
7665
7070
|
this.vao = this.vaoGl.createVertexArray();
|
|
7666
7071
|
this.vaoGl.bindVertexArray(this.vao);
|
|
7667
|
-
// Turn on the position attribute
|
|
7668
7072
|
gl.enableVertexAttribArray(this.programInfo.attribLocations.a_position);
|
|
7669
|
-
// Bind the position buffer.
|
|
7670
7073
|
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
7671
7074
|
const positions = this.positionPoints;
|
|
7672
7075
|
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
|
|
7673
|
-
|
|
7674
|
-
var
|
|
7675
|
-
var
|
|
7676
|
-
var
|
|
7677
|
-
var
|
|
7678
|
-
var offset = 0; // start at the beginning of the buffer
|
|
7076
|
+
var size = 3;
|
|
7077
|
+
var type = gl.FLOAT;
|
|
7078
|
+
var normalize = false;
|
|
7079
|
+
var stride = 0;
|
|
7080
|
+
var offset = 0;
|
|
7679
7081
|
gl.vertexAttribPointer(this.programInfo.attribLocations.a_position, size, type, normalize, stride, offset);
|
|
7680
7082
|
this.restoreVaoState();
|
|
7681
7083
|
}
|
|
7682
7084
|
}
|
|
7683
7085
|
|
|
7684
|
-
/**
|
|
7685
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7686
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7687
|
-
* you may not use this file except in compliance with the License.
|
|
7688
|
-
* You may obtain a copy of the License at
|
|
7689
|
-
*
|
|
7690
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7691
|
-
*
|
|
7692
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
7693
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
7694
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
7695
|
-
* See the License for the specific language governing permissions and
|
|
7696
|
-
* limitations under the License.
|
|
7697
|
-
*/
|
|
7698
|
-
// type here to avoid trying to include XRWebGLLayer from the webxr package
|
|
7699
|
-
// because XRWebGLLayer was defined as a class, not an interface.
|
|
7700
7086
|
class XRSessionWithLayer {
|
|
7701
7087
|
constructor() {
|
|
7702
7088
|
this.mode = 'inline';
|
|
@@ -7704,11 +7090,9 @@ void main() {
|
|
|
7704
7090
|
this.views = [];
|
|
7705
7091
|
this.initializedViews = false;
|
|
7706
7092
|
this.isPolyfillActive = false;
|
|
7707
|
-
// TASK QUEUE
|
|
7708
7093
|
this.taskQueue = [];
|
|
7709
7094
|
}
|
|
7710
7095
|
requestAnimationFrame(animationFrameCallback) {
|
|
7711
|
-
// if we don't have a pose, get the pose
|
|
7712
7096
|
if (!this.injectedFrameCallback) {
|
|
7713
7097
|
this.injectedFrameCallback = (time, frame) => {
|
|
7714
7098
|
let gl = this.context;
|
|
@@ -7719,7 +7103,6 @@ void main() {
|
|
|
7719
7103
|
this.initializedViews = true;
|
|
7720
7104
|
}
|
|
7721
7105
|
}
|
|
7722
|
-
// Layers MUST be cleared to (0, 0, 0, 0) at the beginning of the frame
|
|
7723
7106
|
if (this.isPolyfillActive && this.initializedViews) {
|
|
7724
7107
|
if (!this.tempFramebuffer) {
|
|
7725
7108
|
this.tempFramebuffer = gl.createFramebuffer();
|
|
@@ -7729,30 +7112,15 @@ void main() {
|
|
|
7729
7112
|
const existingFrameBuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
|
7730
7113
|
gl.clearColor(0, 0, 0, 0);
|
|
7731
7114
|
for (let layer of this.layers) {
|
|
7732
|
-
// TODO: spec says all of them should be cleared, but clearing quad layers causes the layer
|
|
7733
|
-
// to disappear...
|
|
7734
7115
|
if (!(layer instanceof XRProjectionLayer)) {
|
|
7735
7116
|
continue;
|
|
7736
7117
|
}
|
|
7737
|
-
// Skip if layer textures aren't allocated yet
|
|
7738
|
-
if (!layer.colorTextures || !layer.colorTexturesMeta || layer.colorTextures.length === 0) {
|
|
7739
|
-
continue;
|
|
7740
|
-
}
|
|
7741
|
-
// clear color textures
|
|
7742
7118
|
for (let i = 0; i < layer.colorTextures.length; i++) {
|
|
7743
7119
|
let textureType = layer.colorTexturesMeta[i].type;
|
|
7744
|
-
let textureMeta = layer.colorTexturesMeta[i];
|
|
7745
7120
|
if (textureType === XRTextureType['texture-array']) ;
|
|
7746
|
-
else if (textureMeta._autoAntialiasing && textureMeta._msaaFramebuffer) {
|
|
7747
|
-
// For MSAA textures, clear the MSAA framebuffer directly
|
|
7748
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, textureMeta._msaaFramebuffer);
|
|
7749
|
-
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
7750
|
-
}
|
|
7751
7121
|
else {
|
|
7752
|
-
// Regular texture clearing (original logic)
|
|
7753
7122
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, layer.colorTextures[i], 0);
|
|
7754
|
-
if (layer.depthStencilTextures &&
|
|
7755
|
-
i < layer.depthStencilTextures.length) {
|
|
7123
|
+
if (layer.depthStencilTextures && i < layer.depthStencilTextures.length) {
|
|
7756
7124
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, layer.depthStencilTextures[i], 0);
|
|
7757
7125
|
}
|
|
7758
7126
|
else {
|
|
@@ -7762,18 +7130,11 @@ void main() {
|
|
|
7762
7130
|
}
|
|
7763
7131
|
}
|
|
7764
7132
|
}
|
|
7765
|
-
// set framebuffer back before rendering anything
|
|
7766
7133
|
gl.bindFramebuffer(gl.FRAMEBUFFER, existingFrameBuffer);
|
|
7767
7134
|
gl.clearColor(existingClearColor[0], existingClearColor[1], existingClearColor[2], existingClearColor[3]);
|
|
7768
7135
|
}
|
|
7769
7136
|
animationFrameCallback(time, frame);
|
|
7770
|
-
// AUTO-RESOLVE MSAA FRAMEBUFFERS AFTER USER RENDERING
|
|
7771
|
-
if (this.isPolyfillActive && this.initializedViews) {
|
|
7772
|
-
this._autoResolveMSAAFramebuffers();
|
|
7773
|
-
}
|
|
7774
|
-
// render the layers
|
|
7775
7137
|
if (this.isPolyfillActive && this.initializedViews) {
|
|
7776
|
-
// store values so we can reset it after our rendering pass.
|
|
7777
7138
|
let prevBlend = gl.isEnabled(gl.BLEND);
|
|
7778
7139
|
let prevDepthTest = gl.isEnabled(gl.DEPTH_TEST);
|
|
7779
7140
|
let prevCullFace = gl.isEnabled(gl.CULL_FACE);
|
|
@@ -7782,8 +7143,6 @@ void main() {
|
|
|
7782
7143
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this.getBaseLayer().framebuffer);
|
|
7783
7144
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
7784
7145
|
gl.clearColor(existingClearColor[0], existingClearColor[1], existingClearColor[2], existingClearColor[3]);
|
|
7785
|
-
// you need to enable gl.BLEND for the
|
|
7786
|
-
// blend function to operate. And for alpha to multiply.
|
|
7787
7146
|
gl.enable(gl.BLEND);
|
|
7788
7147
|
gl.disable(gl.DEPTH_TEST);
|
|
7789
7148
|
gl.disable(gl.CULL_FACE);
|
|
@@ -7792,13 +7151,10 @@ void main() {
|
|
|
7792
7151
|
let prevBlendDestRGB = gl.getParameter(gl.BLEND_DST_RGB);
|
|
7793
7152
|
let prevBlendDestAlpha = gl.getParameter(gl.BLEND_DST_ALPHA);
|
|
7794
7153
|
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
7795
|
-
// get all layers!
|
|
7796
7154
|
for (let layer of this.layers) {
|
|
7797
7155
|
if (!this.renderers) {
|
|
7798
7156
|
this.renderers = new WeakMap();
|
|
7799
7157
|
}
|
|
7800
|
-
// if it's not a media layer, we need to render a normal WebGL Layer
|
|
7801
|
-
// which involves using custom shaders per layer type.
|
|
7802
7158
|
if (layer instanceof XRProjectionLayer) {
|
|
7803
7159
|
if (!this.renderers.has(layer)) {
|
|
7804
7160
|
this.renderers.set(layer, createProjectionRenderer(layer, this.context));
|
|
@@ -7835,14 +7191,10 @@ void main() {
|
|
|
7835
7191
|
renderer.render(this, frame);
|
|
7836
7192
|
}
|
|
7837
7193
|
else {
|
|
7838
|
-
// XRWebGLLayer
|
|
7839
7194
|
const webglLayer = layer;
|
|
7840
7195
|
if (webglLayer.framebuffer === null) {
|
|
7841
|
-
// webglLayer is the same as the base layer, so we skip it since
|
|
7842
|
-
// we rendered into the framebuffer already.
|
|
7843
7196
|
continue;
|
|
7844
7197
|
}
|
|
7845
|
-
// TODO: test this, because this is totally untested.
|
|
7846
7198
|
if (gl instanceof WebGL2RenderingContext) {
|
|
7847
7199
|
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, webglLayer.framebuffer);
|
|
7848
7200
|
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this.getBaseLayer().framebuffer);
|
|
@@ -7853,7 +7205,6 @@ void main() {
|
|
|
7853
7205
|
}
|
|
7854
7206
|
}
|
|
7855
7207
|
}
|
|
7856
|
-
// restore previous settings
|
|
7857
7208
|
if (!prevBlend) {
|
|
7858
7209
|
gl.disable(gl.BLEND);
|
|
7859
7210
|
}
|
|
@@ -7863,10 +7214,8 @@ void main() {
|
|
|
7863
7214
|
if (prevCullFace) {
|
|
7864
7215
|
gl.enable(gl.CULL_FACE);
|
|
7865
7216
|
}
|
|
7866
|
-
// restore previous blendFunc
|
|
7867
7217
|
gl.blendFuncSeparate(prevBlendSrcRGB, prevBlendDestRGB, prevBlendSrcAlpha, prevBlendDestAlpha);
|
|
7868
7218
|
gl.bindFramebuffer(gl.FRAMEBUFFER, existingFrameBuffer);
|
|
7869
|
-
// run task queue
|
|
7870
7219
|
while (this.taskQueue.length > 0) {
|
|
7871
7220
|
const task = this.taskQueue.shift();
|
|
7872
7221
|
task();
|
|
@@ -7876,10 +7225,6 @@ void main() {
|
|
|
7876
7225
|
}
|
|
7877
7226
|
this._requestAnimationFrame(this.injectedFrameCallback);
|
|
7878
7227
|
}
|
|
7879
|
-
// An implementation of session.updateRenderState({ layers: [...layers] });
|
|
7880
|
-
// that overrides layers and sets the baseLayer to one that is custom created in this
|
|
7881
|
-
// polyfilled session, and then adds the contents of the other layers onto that base layer
|
|
7882
|
-
// and saves the custom layers as state on the object
|
|
7883
7228
|
updateRenderState(XRRenderStateInit) {
|
|
7884
7229
|
this.existingBaseLayer = XRRenderStateInit.baseLayer;
|
|
7885
7230
|
if (XRRenderStateInit.layers) {
|
|
@@ -7888,14 +7233,8 @@ void main() {
|
|
|
7888
7233
|
if (!this.activeRenderState) {
|
|
7889
7234
|
this.createActiveRenderState();
|
|
7890
7235
|
}
|
|
7891
|
-
this.activeRenderState = {
|
|
7892
|
-
...this.activeRenderState,
|
|
7893
|
-
...XRRenderStateInit,
|
|
7894
|
-
};
|
|
7236
|
+
this.activeRenderState = Object.assign(Object.assign({}, this.activeRenderState), XRRenderStateInit);
|
|
7895
7237
|
if (!XRRenderStateInit.layers) {
|
|
7896
|
-
// no layer information in this renderState, so we don't need to update
|
|
7897
|
-
// context or the renderState object before passing it to the underlying
|
|
7898
|
-
// updateRenderState function.
|
|
7899
7238
|
this._updateRenderState(XRRenderStateInit);
|
|
7900
7239
|
return;
|
|
7901
7240
|
}
|
|
@@ -7913,48 +7252,31 @@ void main() {
|
|
|
7913
7252
|
const canvas = document.createElement('canvas');
|
|
7914
7253
|
context = canvas.getContext('webgl2', { xrCompatible: true });
|
|
7915
7254
|
if (!context) {
|
|
7916
|
-
// fallback to webgl 1 if 2 is not supported.
|
|
7917
|
-
// the session only creates the context if there are only
|
|
7918
|
-
// media layers, so this should work regardless.
|
|
7919
7255
|
context = canvas.getContext('webgl', { xrCompatible: true });
|
|
7920
7256
|
}
|
|
7921
7257
|
if (!context) {
|
|
7922
|
-
// we don't support webGL at all...this is a failure case.
|
|
7923
|
-
// though, we probably should've errored out long before reaching this.
|
|
7924
7258
|
throw new Error('No webGL support detected.');
|
|
7925
7259
|
}
|
|
7926
7260
|
document.body.appendChild(context.canvas);
|
|
7927
|
-
// TODO: Figure out if we actually need to resize the canvas.
|
|
7928
7261
|
function onResize() {
|
|
7929
|
-
context.canvas.width =
|
|
7930
|
-
|
|
7931
|
-
context.canvas.height =
|
|
7932
|
-
context.canvas.clientHeight * window.devicePixelRatio;
|
|
7262
|
+
context.canvas.width = context.canvas.clientWidth * window.devicePixelRatio;
|
|
7263
|
+
context.canvas.height = context.canvas.clientHeight * window.devicePixelRatio;
|
|
7933
7264
|
}
|
|
7934
7265
|
window.addEventListener('resize', onResize);
|
|
7935
7266
|
onResize();
|
|
7936
7267
|
}
|
|
7937
7268
|
this.createInternalLayer(context);
|
|
7938
7269
|
this.isPolyfillActive = true;
|
|
7939
|
-
|
|
7940
|
-
this._updateRenderState({
|
|
7941
|
-
...layerRenderStateInit,
|
|
7942
|
-
baseLayer: this.internalLayer,
|
|
7943
|
-
});
|
|
7270
|
+
this._updateRenderState(Object.assign(Object.assign({}, layerRenderStateInit), { baseLayer: this.internalLayer }));
|
|
7944
7271
|
}
|
|
7945
|
-
// POLYFILL SPECIFIC
|
|
7946
|
-
// called on requestSession to make sure polyfilled XRSession has
|
|
7947
|
-
// access to some assumed default views.
|
|
7948
7272
|
initializeSession(mode) {
|
|
7949
7273
|
this.mode = mode;
|
|
7950
|
-
// temporary reference space to grab views
|
|
7951
7274
|
this
|
|
7952
7275
|
.requestReferenceSpace('local')
|
|
7953
7276
|
.then((refSpace) => {
|
|
7954
7277
|
this.referenceSpace = refSpace;
|
|
7955
7278
|
})
|
|
7956
7279
|
.catch((e) => {
|
|
7957
|
-
// do nothing.
|
|
7958
7280
|
});
|
|
7959
7281
|
this.requestReferenceSpace('viewer').then((viewerSpace) => {
|
|
7960
7282
|
this.viewerSpace = viewerSpace;
|
|
@@ -7962,7 +7284,6 @@ void main() {
|
|
|
7962
7284
|
}
|
|
7963
7285
|
getBaseLayer(context) {
|
|
7964
7286
|
if (!this.internalLayer && !this.existingBaseLayer && context) {
|
|
7965
|
-
// TODO: this might be buggy if the context has changed...
|
|
7966
7287
|
this.createInternalLayer(context);
|
|
7967
7288
|
}
|
|
7968
7289
|
return this.internalLayer || this.existingBaseLayer;
|
|
@@ -8008,16 +7329,11 @@ void main() {
|
|
|
8008
7329
|
return this.internalLayer;
|
|
8009
7330
|
}
|
|
8010
7331
|
setContext(context) {
|
|
8011
|
-
// reset everything that depends on context
|
|
8012
7332
|
this.context = context;
|
|
8013
7333
|
this.tempFramebuffer = context.createFramebuffer();
|
|
8014
7334
|
this.renderers = new WeakMap();
|
|
8015
7335
|
}
|
|
8016
7336
|
createActiveRenderState() {
|
|
8017
|
-
// this code ensures that we return an object that follows the interface for XRRenderState
|
|
8018
|
-
// with the layers array added, regardless of whether we're on device or in emulator
|
|
8019
|
-
// since sometimes XRRenderState is a native object, and other times it's a symbol, and
|
|
8020
|
-
// other times defined as a plain JS object.
|
|
8021
7337
|
const _global = getGlobal();
|
|
8022
7338
|
let prototypeNames = Object.getOwnPropertyNames(_global.XRRenderState.prototype);
|
|
8023
7339
|
const renderStateClone = {};
|
|
@@ -8027,55 +7343,8 @@ void main() {
|
|
|
8027
7343
|
renderStateClone.layers = [];
|
|
8028
7344
|
this.activeRenderState = renderStateClone;
|
|
8029
7345
|
}
|
|
8030
|
-
// AUTO-RESOLVE MSAA FRAMEBUFFERS FOR DESKTOP ANTIALIASING
|
|
8031
|
-
_autoResolveMSAAFramebuffers() {
|
|
8032
|
-
const gl = this.context;
|
|
8033
|
-
if (!gl || !(gl instanceof WebGL2RenderingContext)) {
|
|
8034
|
-
return;
|
|
8035
|
-
}
|
|
8036
|
-
// Find all layers that need MSAA resolving
|
|
8037
|
-
for (let layer of this.layers) {
|
|
8038
|
-
if (layer instanceof XRCompositionLayerPolyfill) {
|
|
8039
|
-
// Check each texture meta for auto-antialiasing
|
|
8040
|
-
if (layer.colorTexturesMeta) {
|
|
8041
|
-
for (let textureMeta of layer.colorTexturesMeta) {
|
|
8042
|
-
if (textureMeta._autoAntialiasing &&
|
|
8043
|
-
textureMeta._msaaFramebuffer &&
|
|
8044
|
-
textureMeta._resolveFramebuffer) {
|
|
8045
|
-
try {
|
|
8046
|
-
// Resolve MSAA to final texture
|
|
8047
|
-
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, textureMeta._msaaFramebuffer);
|
|
8048
|
-
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, textureMeta._resolveFramebuffer);
|
|
8049
|
-
gl.blitFramebuffer(0, 0, textureMeta.width, textureMeta.height, 0, 0, textureMeta.width, textureMeta.height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
|
|
8050
|
-
}
|
|
8051
|
-
catch (error) {
|
|
8052
|
-
console.warn('Failed to resolve MSAA framebuffer:', error);
|
|
8053
|
-
}
|
|
8054
|
-
}
|
|
8055
|
-
}
|
|
8056
|
-
}
|
|
8057
|
-
}
|
|
8058
|
-
}
|
|
8059
|
-
// Clean up bindings
|
|
8060
|
-
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
|
|
8061
|
-
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
|
|
8062
|
-
}
|
|
8063
7346
|
}
|
|
8064
7347
|
|
|
8065
|
-
/**
|
|
8066
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
8067
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8068
|
-
* you may not use this file except in compliance with the License.
|
|
8069
|
-
* You may obtain a copy of the License at
|
|
8070
|
-
*
|
|
8071
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8072
|
-
*
|
|
8073
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
8074
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8075
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8076
|
-
* See the License for the specific language governing permissions and
|
|
8077
|
-
* limitations under the License.
|
|
8078
|
-
*/
|
|
8079
7348
|
class XRWebGLSubImagePolyfill {
|
|
8080
7349
|
constructor() {
|
|
8081
7350
|
this.viewport = {
|
|
@@ -8087,20 +7356,6 @@ void main() {
|
|
|
8087
7356
|
}
|
|
8088
7357
|
}
|
|
8089
7358
|
|
|
8090
|
-
/**
|
|
8091
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
8092
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8093
|
-
* you may not use this file except in compliance with the License.
|
|
8094
|
-
* You may obtain a copy of the License at
|
|
8095
|
-
*
|
|
8096
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8097
|
-
*
|
|
8098
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
8099
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8100
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8101
|
-
* See the License for the specific language governing permissions and
|
|
8102
|
-
* limitations under the License.
|
|
8103
|
-
*/
|
|
8104
7359
|
class XRWebGLBindingPolyfill {
|
|
8105
7360
|
constructor(session, context) {
|
|
8106
7361
|
this.session = session;
|
|
@@ -8115,13 +7370,7 @@ void main() {
|
|
|
8115
7370
|
if (this.context.isContextLost()) {
|
|
8116
7371
|
throw new Error('context is lost');
|
|
8117
7372
|
}
|
|
8118
|
-
// initialize a composition layer on layer with session and context
|
|
8119
7373
|
layer.initialize(this.session, this.context);
|
|
8120
|
-
// POLYFILL ONLY: all the initialization in between here happens on the XRProjectionLayer object, since some of the steps need to be deferred until
|
|
8121
|
-
// the views are available
|
|
8122
|
-
// UNIMPLEMENTED: Everything with secondary views. The polyfill ignores them.
|
|
8123
|
-
// UNIMPLEMENTED: Allocate and initialize resources compatible with session’s XR device, including GPU accessible memory buffers, as required to support the compositing of layer.
|
|
8124
|
-
// UNIMPLEMENTED: If layer’s resources were unable to be created for any reason, throw an OperationError and abort these steps.
|
|
8125
7374
|
return layer;
|
|
8126
7375
|
}
|
|
8127
7376
|
createQuadLayer(init = defaultQuadLayerInit) {
|
|
@@ -8136,7 +7385,6 @@ void main() {
|
|
|
8136
7385
|
}
|
|
8137
7386
|
const layer = new XRQuadLayer(init);
|
|
8138
7387
|
layer.initialize(this.session, this.context);
|
|
8139
|
-
// everything else is created in the layer's deferred initialize step.
|
|
8140
7388
|
return layer;
|
|
8141
7389
|
}
|
|
8142
7390
|
createCylinderLayer(init = defaultCylinderLayerInit) {
|
|
@@ -8151,7 +7399,6 @@ void main() {
|
|
|
8151
7399
|
}
|
|
8152
7400
|
const layer = new XRCylinderLayer(init);
|
|
8153
7401
|
layer.initialize(this.session, this.context);
|
|
8154
|
-
// everything else is created in the layer's deferred initialize step
|
|
8155
7402
|
return layer;
|
|
8156
7403
|
}
|
|
8157
7404
|
createEquirectLayer(init = defaultEquirectLayerInit) {
|
|
@@ -8167,10 +7414,8 @@ void main() {
|
|
|
8167
7414
|
if (!isReferenceSpace(init.space)) {
|
|
8168
7415
|
throw new TypeError('Equirect layer requires an XRReferenceSpace');
|
|
8169
7416
|
}
|
|
8170
|
-
// UNIMPLEMENTED: If init’s space has a type of "viewer", throw TypeError and abort these steps.
|
|
8171
7417
|
let layer = new XREquirectLayer(init);
|
|
8172
7418
|
layer.initialize(this.session, this.context);
|
|
8173
|
-
// everything else is created in the layer's deferred initialize step
|
|
8174
7419
|
return layer;
|
|
8175
7420
|
}
|
|
8176
7421
|
createCubeLayer(init) {
|
|
@@ -8186,19 +7431,14 @@ void main() {
|
|
|
8186
7431
|
if (!isReferenceSpace(init.space)) {
|
|
8187
7432
|
throw new TypeError('XRCubeLayer requires a space of type XRReferenceSpace');
|
|
8188
7433
|
}
|
|
8189
|
-
// UNIMPLEMENTED: If init’s space has a type of "viewer", throw TypeError and abort these steps.
|
|
8190
7434
|
let layer = new XRCubeLayer(init);
|
|
8191
|
-
// set up color and depth textures, which doesn't need to be asynchronous
|
|
8192
|
-
// this happens in layer.initialize
|
|
8193
7435
|
layer.initialize(this.session, this.context);
|
|
8194
7436
|
return layer;
|
|
8195
7437
|
}
|
|
8196
7438
|
getSubImage(layer, frame, eye = 'none') {
|
|
8197
|
-
if (layer.isStatic && layer.needsRedraw === false) {
|
|
7439
|
+
if (layer.isStatic && (layer.needsRedraw === false)) {
|
|
8198
7440
|
throw new Error('Invalid state for subimage creation');
|
|
8199
7441
|
}
|
|
8200
|
-
// if getSubImage was called previously with same binding, layer, and eye, the
|
|
8201
|
-
// user agent may return the same subimage as returned by earlier call
|
|
8202
7442
|
let existingSubImage = this.subImageCache.tryGetCachedSubImage(this.context, layer, eye);
|
|
8203
7443
|
if (existingSubImage) {
|
|
8204
7444
|
return existingSubImage;
|
|
@@ -8222,9 +7462,6 @@ void main() {
|
|
|
8222
7462
|
index = 1;
|
|
8223
7463
|
}
|
|
8224
7464
|
}
|
|
8225
|
-
// UNIMPLEMENTED: If validate the state of the XRWebGLSubImage creation function with layer and frame is false,
|
|
8226
|
-
// throw an InvalidStateError and abort these steps.
|
|
8227
|
-
// if layer is created with textureType 'texture-array'
|
|
8228
7465
|
if (layer.getTextureType() === XRTextureType['texture-array']) {
|
|
8229
7466
|
subimage.imageIndex = index;
|
|
8230
7467
|
}
|
|
@@ -8232,7 +7469,6 @@ void main() {
|
|
|
8232
7469
|
subimage.imageIndex = 0;
|
|
8233
7470
|
}
|
|
8234
7471
|
let _textureIndex = 0;
|
|
8235
|
-
// initialize colorTexture
|
|
8236
7472
|
if (layer.getTextureType() === XRTextureType.texture) {
|
|
8237
7473
|
subimage.colorTexture = layer.colorTextures[index];
|
|
8238
7474
|
_textureIndex = index;
|
|
@@ -8241,12 +7477,6 @@ void main() {
|
|
|
8241
7477
|
subimage.colorTexture = layer.colorTextures[0];
|
|
8242
7478
|
_textureIndex = 0;
|
|
8243
7479
|
}
|
|
8244
|
-
// Add Three.js expected properties for multiview compatibility
|
|
8245
|
-
if (subimage.colorTexture && typeof subimage.colorTexture === 'object') {
|
|
8246
|
-
subimage.colorTexture.isWebGLMultiviewRenderTarget =
|
|
8247
|
-
layer.getTextureType() === XRTextureType['texture-array'];
|
|
8248
|
-
}
|
|
8249
|
-
// initialize depthStencilTexture
|
|
8250
7480
|
if (!layer.depthStencilTextures || !layer.depthStencilTextures.length) {
|
|
8251
7481
|
subimage.depthStencilTexture = null;
|
|
8252
7482
|
}
|
|
@@ -8256,14 +7486,6 @@ void main() {
|
|
|
8256
7486
|
else {
|
|
8257
7487
|
subimage.depthStencilTexture = layer.depthStencilTextures[0];
|
|
8258
7488
|
}
|
|
8259
|
-
// Add Three.js expected properties for multiview compatibility
|
|
8260
|
-
if (subimage.depthStencilTexture &&
|
|
8261
|
-
typeof subimage.depthStencilTexture === 'object') {
|
|
8262
|
-
subimage.depthStencilTexture.isWebGLMultiviewRenderTarget =
|
|
8263
|
-
layer.getTextureType() === XRTextureType['texture-array'];
|
|
8264
|
-
}
|
|
8265
|
-
// Set subimage’s textureWidth to the pixel width of subimage’s colorTexture.
|
|
8266
|
-
// Set subimage’s textureHeight to the pixel height of subimage’s colorTexture.
|
|
8267
7489
|
const layerMeta = layer.colorTexturesMeta[_textureIndex];
|
|
8268
7490
|
subimage.textureWidth = layerMeta.width;
|
|
8269
7491
|
subimage.textureHeight = layerMeta.height;
|
|
@@ -8272,62 +7494,32 @@ void main() {
|
|
|
8272
7494
|
layer.layout === XRLayerLayout['stereo-top-bottom']) {
|
|
8273
7495
|
viewsPerTexture = 2;
|
|
8274
7496
|
}
|
|
8275
|
-
// Run initialize viewport on subimage's viewport with subimage’s colorTexture, layer’s layout, index and num.
|
|
8276
|
-
// https://immersive-web.github.io/layers/#initialize-the-viewport
|
|
8277
7497
|
initializeViewport(subimage.viewport, layerMeta, layer.layout, index, viewsPerTexture);
|
|
8278
|
-
// queue task to set needsRedraw to false
|
|
8279
7498
|
this.session.queueTask(() => {
|
|
8280
7499
|
layer.needsRedraw = false;
|
|
8281
7500
|
});
|
|
8282
7501
|
this.subImageCache.cacheSubImage(subimage, this.context, layer, eye);
|
|
8283
7502
|
return subimage;
|
|
8284
7503
|
}
|
|
8285
|
-
// This is mostly used for rendering to projection layers!
|
|
8286
|
-
// https://immersive-web.github.io/layers/#dom-xrwebglbinding-getviewsubimage
|
|
8287
7504
|
getViewSubImage(layer, view) {
|
|
8288
|
-
// if getViewSubImage was called previously with same binding, layer, and view, the
|
|
8289
|
-
// user agent may return the same subimage as returned by earlier call
|
|
8290
7505
|
let existingSubImage = this.subImageCache.tryGetCachedViewSubImage(this.context, layer, view);
|
|
8291
7506
|
if (existingSubImage) {
|
|
8292
7507
|
return existingSubImage;
|
|
8293
7508
|
}
|
|
8294
7509
|
let subimage = new XRWebGLSubImagePolyfill();
|
|
8295
|
-
// UNIMPLEMENTED: let frame be the view's frame
|
|
8296
|
-
// how do we get that?
|
|
8297
7510
|
let session = this.session;
|
|
8298
7511
|
if (!session.internalViews || !session.internalViews.length) {
|
|
8299
|
-
console.warn('
|
|
8300
|
-
// Return a placeholder subimage with safe defaults
|
|
8301
|
-
subimage.imageIndex = 0;
|
|
8302
|
-
// Create dummy texture objects that won't cause null reference errors
|
|
8303
|
-
const dummyColorTexture = {
|
|
8304
|
-
isWebGLMultiviewRenderTarget: false
|
|
8305
|
-
};
|
|
8306
|
-
const dummyDepthTexture = {
|
|
8307
|
-
isWebGLMultiviewRenderTarget: false
|
|
8308
|
-
};
|
|
8309
|
-
subimage.colorTexture = dummyColorTexture;
|
|
8310
|
-
subimage.depthStencilTexture = dummyDepthTexture;
|
|
8311
|
-
subimage.textureWidth = 1024; // Safe default
|
|
8312
|
-
subimage.textureHeight = 1024; // Safe default
|
|
8313
|
-
subimage.viewport = { x: 0, y: 0, width: 1024, height: 1024 };
|
|
7512
|
+
console.warn('Tried to get view sub image before we have any views');
|
|
8314
7513
|
return subimage;
|
|
8315
7514
|
}
|
|
8316
|
-
// UNIMPLEMENTED: If validate the state of the XRWebGLSubImage creation function with layer and frame is false,
|
|
8317
|
-
// throw an InvalidStateError and abort these steps.
|
|
8318
|
-
// UNIMPLEMENTED: if view's active flag is false, throw InvalidStateError
|
|
8319
|
-
// not relevant?
|
|
8320
|
-
// let index be the offset in the session's list of views.
|
|
8321
7515
|
let index = session.getViewIndex(view);
|
|
8322
7516
|
let _textureIndex = 0;
|
|
8323
|
-
// initialize imageIndex
|
|
8324
7517
|
if (layer.getTextureType() === XRTextureType['texture-array']) {
|
|
8325
7518
|
subimage.imageIndex = index;
|
|
8326
7519
|
}
|
|
8327
7520
|
else {
|
|
8328
7521
|
subimage.imageIndex = 0;
|
|
8329
7522
|
}
|
|
8330
|
-
// Initialize colorTexture
|
|
8331
7523
|
if (layer.layout === XRLayerLayout.default &&
|
|
8332
7524
|
layer.getTextureType() === XRTextureType.texture) {
|
|
8333
7525
|
subimage.colorTexture = layer.colorTextures[index];
|
|
@@ -8337,25 +7529,6 @@ void main() {
|
|
|
8337
7529
|
subimage.colorTexture = layer.colorTextures[0];
|
|
8338
7530
|
_textureIndex = 0;
|
|
8339
7531
|
}
|
|
8340
|
-
// TRANSPARENT MSAA: Use MSAA framebuffer for rendering if available
|
|
8341
|
-
const textureMeta = layer.colorTexturesMeta[_textureIndex];
|
|
8342
|
-
if (textureMeta._autoAntialiasing && textureMeta._msaaFramebuffer) {
|
|
8343
|
-
// For rendering, applications will bind to the MSAA framebuffer
|
|
8344
|
-
subimage.framebuffer = textureMeta._msaaFramebuffer;
|
|
8345
|
-
// Mark this subimage as needing resolve after rendering
|
|
8346
|
-
subimage._needsResolve = true;
|
|
8347
|
-
subimage._resolveFromFramebuffer = textureMeta._msaaFramebuffer;
|
|
8348
|
-
subimage._resolveToFramebuffer = textureMeta._resolveFramebuffer;
|
|
8349
|
-
subimage._textureMeta = textureMeta;
|
|
8350
|
-
// The colorTexture still points to the final resolved texture for read operations
|
|
8351
|
-
// This maintains API compatibility
|
|
8352
|
-
}
|
|
8353
|
-
// Add Three.js expected properties for multiview compatibility
|
|
8354
|
-
if (subimage.colorTexture && typeof subimage.colorTexture === 'object') {
|
|
8355
|
-
subimage.colorTexture.isWebGLMultiviewRenderTarget =
|
|
8356
|
-
layer.getTextureType() === XRTextureType['texture-array'];
|
|
8357
|
-
}
|
|
8358
|
-
// initialize depthStencilTexture
|
|
8359
7532
|
if (layer.depthStencilTextures.length === 0) {
|
|
8360
7533
|
subimage.depthStencilTexture = null;
|
|
8361
7534
|
}
|
|
@@ -8366,18 +7539,8 @@ void main() {
|
|
|
8366
7539
|
else {
|
|
8367
7540
|
subimage.depthStencilTexture = layer.depthStencilTextures[0];
|
|
8368
7541
|
}
|
|
8369
|
-
// Add Three.js expected properties for multiview compatibility
|
|
8370
|
-
if (subimage.depthStencilTexture &&
|
|
8371
|
-
typeof subimage.depthStencilTexture === 'object') {
|
|
8372
|
-
subimage.depthStencilTexture.isWebGLMultiviewRenderTarget =
|
|
8373
|
-
layer.getTextureType() === XRTextureType['texture-array'];
|
|
8374
|
-
}
|
|
8375
|
-
// Set subimage’s textureWidth to the pixel width of subimage’s colorTexture.
|
|
8376
|
-
// Set subimage’s textureHeight to the pixel height of subimage’s colorTexture.
|
|
8377
7542
|
subimage.textureWidth = layer.colorTexturesMeta[_textureIndex].width;
|
|
8378
7543
|
subimage.textureHeight = layer.colorTexturesMeta[_textureIndex].height;
|
|
8379
|
-
// Run initialize viewport on subimage's viewport with subimage’s colorTexture, layer’s layout, index and num.
|
|
8380
|
-
// https://immersive-web.github.io/layers/#initialize-the-viewport
|
|
8381
7544
|
initializeViewport(subimage.viewport, layer.colorTexturesMeta[_textureIndex], layer.layout, index, session.internalViews.length);
|
|
8382
7545
|
layer.needsRedraw = false;
|
|
8383
7546
|
this.subImageCache.cacheViewSubImage(subimage, this.context, layer, view);
|
|
@@ -8415,7 +7578,8 @@ void main() {
|
|
|
8415
7578
|
this.cache.set(context, layerMap);
|
|
8416
7579
|
}
|
|
8417
7580
|
tryGetCachedSubImage(context, layer, eye) {
|
|
8418
|
-
|
|
7581
|
+
var _a, _b;
|
|
7582
|
+
return (_b = (_a = this.cache.get(context)) === null || _a === void 0 ? void 0 : _a.get(layer)) === null || _b === void 0 ? void 0 : _b.get(eye);
|
|
8419
7583
|
}
|
|
8420
7584
|
cacheViewSubImage(subimage, context, layer, view) {
|
|
8421
7585
|
let viewMap = new Map();
|
|
@@ -8425,56 +7589,22 @@ void main() {
|
|
|
8425
7589
|
this.viewCache.set(context, layerMap);
|
|
8426
7590
|
}
|
|
8427
7591
|
tryGetCachedViewSubImage(context, layer, view) {
|
|
8428
|
-
|
|
7592
|
+
var _a, _b;
|
|
7593
|
+
return (_b = (_a = this.viewCache.get(context)) === null || _a === void 0 ? void 0 : _a.get(layer)) === null || _b === void 0 ? void 0 : _b.get(view);
|
|
8429
7594
|
}
|
|
8430
7595
|
}
|
|
8431
7596
|
|
|
8432
|
-
/**
|
|
8433
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
8434
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8435
|
-
* you may not use this file except in compliance with the License.
|
|
8436
|
-
* You may obtain a copy of the License at
|
|
8437
|
-
*
|
|
8438
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8439
|
-
*
|
|
8440
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
8441
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8442
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8443
|
-
* See the License for the specific language governing permissions and
|
|
8444
|
-
* limitations under the License.
|
|
8445
|
-
*/
|
|
8446
7597
|
const isLayersNativelySupported = (global) => {
|
|
8447
7598
|
if (!global.navigator.xr) {
|
|
8448
7599
|
return false;
|
|
8449
7600
|
}
|
|
8450
|
-
// we currently key off of the existence of both
|
|
8451
|
-
// XRWebGLBinding and XRMedia binding, because certain browsers
|
|
8452
|
-
// may implement one and not the other.
|
|
8453
|
-
// If either are missing, we need the whole polyfill, unfortunately;
|
|
8454
|
-
// the way that the polyfilled XRSession handles layers assumes that all layers
|
|
8455
|
-
// need to be polyfilled.
|
|
8456
7601
|
if (global.XRMediaBinding && global.XRWebGLBinding) {
|
|
8457
7602
|
return true;
|
|
8458
7603
|
}
|
|
8459
7604
|
return false;
|
|
8460
7605
|
};
|
|
8461
7606
|
|
|
8462
|
-
|
|
8463
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
8464
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8465
|
-
* you may not use this file except in compliance with the License.
|
|
8466
|
-
* You may obtain a copy of the License at
|
|
8467
|
-
*
|
|
8468
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8469
|
-
*
|
|
8470
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
8471
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
8472
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
8473
|
-
* See the License for the specific language governing permissions and
|
|
8474
|
-
* limitations under the License.
|
|
8475
|
-
*/
|
|
8476
|
-
/// <reference types="webxr" />
|
|
8477
|
-
let WebXRLayersPolyfill$1 = class WebXRLayersPolyfill {
|
|
7607
|
+
class WebXRLayersPolyfill {
|
|
8478
7608
|
constructor() {
|
|
8479
7609
|
this.injected = false;
|
|
8480
7610
|
const _global = getGlobal();
|
|
@@ -8488,7 +7618,6 @@ void main() {
|
|
|
8488
7618
|
console.warn('Polyfill has already been injected...');
|
|
8489
7619
|
}
|
|
8490
7620
|
if (isLayersNativelySupported(global)) {
|
|
8491
|
-
// we don't need to polyfill anything, so leave things untouched
|
|
8492
7621
|
return;
|
|
8493
7622
|
}
|
|
8494
7623
|
this._polyfillRequiredLayersFeature(global);
|
|
@@ -8503,24 +7632,15 @@ void main() {
|
|
|
8503
7632
|
global.XRSession.prototype._requestAnimationFrame =
|
|
8504
7633
|
global.XRSession.prototype.requestAnimationFrame;
|
|
8505
7634
|
let renderStateGetter = Object.getOwnPropertyDescriptor(global.XRSession.prototype, 'renderState');
|
|
8506
|
-
|
|
8507
|
-
Object.defineProperty(global.XRSession.prototype, '_renderState', renderStateGetter);
|
|
8508
|
-
}
|
|
7635
|
+
Object.defineProperty(global.XRSession.prototype, '_renderState', renderStateGetter);
|
|
8509
7636
|
let polyfillRenderStateGetter = Object.getOwnPropertyDescriptor(XRSessionWithLayer.prototype, 'renderState');
|
|
8510
|
-
|
|
8511
|
-
Object.defineProperty(global.XRSession.prototype, 'renderState', polyfillRenderStateGetter);
|
|
8512
|
-
}
|
|
8513
|
-
// this lets us grab all the functions and getters from XRSesssionWithLayer and put them into XRSession
|
|
7637
|
+
Object.defineProperty(global.XRSession.prototype, 'renderState', polyfillRenderStateGetter);
|
|
8514
7638
|
let prototypeNames = Object.getOwnPropertyNames(XRSessionWithLayer.prototype);
|
|
8515
7639
|
for (let item of prototypeNames) {
|
|
8516
7640
|
let propertyDescriptor = Object.getOwnPropertyDescriptor(XRSessionWithLayer.prototype, item);
|
|
8517
|
-
|
|
8518
|
-
Object.defineProperty(global.XRSession.prototype, item, propertyDescriptor);
|
|
8519
|
-
}
|
|
7641
|
+
Object.defineProperty(global.XRSession.prototype, item, propertyDescriptor);
|
|
8520
7642
|
}
|
|
8521
7643
|
}
|
|
8522
|
-
// This is a glorious hack to remove the 'layers' string from requiredFeatures so that XRSystem doesn't
|
|
8523
|
-
// throw an error when we try to request a session.
|
|
8524
7644
|
_polyfillRequiredLayersFeature(global) {
|
|
8525
7645
|
const existingRequestSession = global.navigator.xr.requestSession;
|
|
8526
7646
|
Object.defineProperty(global.navigator.xr, 'requestSessionInternal', { writable: true });
|
|
@@ -8528,14 +7648,12 @@ void main() {
|
|
|
8528
7648
|
const newRequestSession = (sessionMode, sessionInit) => {
|
|
8529
7649
|
const modifiedSessionPromise = (mode, init) => {
|
|
8530
7650
|
return global.navigator.xr.requestSessionInternal(mode, init).then((session) => {
|
|
8531
|
-
// create internal required variables
|
|
8532
7651
|
Object.assign(session, new XRSessionWithLayer());
|
|
8533
7652
|
let polyfilledSession = session;
|
|
8534
7653
|
polyfilledSession.initializeSession(sessionMode);
|
|
8535
7654
|
return Promise.resolve(polyfilledSession);
|
|
8536
7655
|
});
|
|
8537
7656
|
};
|
|
8538
|
-
// we don't have to do anything if we aren't in VR or don't require layers
|
|
8539
7657
|
if (sessionMode !== 'immersive-vr') {
|
|
8540
7658
|
return modifiedSessionPromise(sessionMode, sessionInit);
|
|
8541
7659
|
}
|
|
@@ -8543,9 +7661,7 @@ void main() {
|
|
|
8543
7661
|
return modifiedSessionPromise(sessionMode, sessionInit);
|
|
8544
7662
|
}
|
|
8545
7663
|
if (sessionInit.requiredFeatures && sessionInit.requiredFeatures.indexOf('layers') > -1) {
|
|
8546
|
-
|
|
8547
|
-
const sessionInitClone = { ...sessionInit };
|
|
8548
|
-
// remove layers from the requiredFeatures
|
|
7664
|
+
const sessionInitClone = Object.assign({}, sessionInit);
|
|
8549
7665
|
const reqFeatures = [...sessionInit.requiredFeatures];
|
|
8550
7666
|
const layersIndex = reqFeatures.indexOf('layers');
|
|
8551
7667
|
reqFeatures.splice(layersIndex, 1);
|
|
@@ -8557,7 +7673,7 @@ void main() {
|
|
|
8557
7673
|
Object.defineProperty(global.navigator.xr, 'requestSession', { writable: true });
|
|
8558
7674
|
global.navigator.xr.requestSession = newRequestSession;
|
|
8559
7675
|
}
|
|
8560
|
-
}
|
|
7676
|
+
}
|
|
8561
7677
|
|
|
8562
7678
|
/**
|
|
8563
7679
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -8638,7 +7754,7 @@ void main() {
|
|
|
8638
7754
|
visibilityState: 'visible',
|
|
8639
7755
|
pendingVisibilityState: null,
|
|
8640
7756
|
xrSystem: null,
|
|
8641
|
-
matrix: create$
|
|
7757
|
+
matrix: create$5(),
|
|
8642
7758
|
globalSpace,
|
|
8643
7759
|
viewerSpace,
|
|
8644
7760
|
viewSpaces,
|
|
@@ -8806,7 +7922,7 @@ void main() {
|
|
|
8806
7922
|
globalObject['XRInputSourcesChangeEvent'] = XRInputSourcesChangeEvent;
|
|
8807
7923
|
globalObject['XRReferenceSpaceEvent'] = XRReferenceSpaceEvent;
|
|
8808
7924
|
if (polyfillLayers) {
|
|
8809
|
-
new WebXRLayersPolyfill
|
|
7925
|
+
new WebXRLayersPolyfill();
|
|
8810
7926
|
}
|
|
8811
7927
|
else {
|
|
8812
7928
|
globalObject['XRMediaBinding'] = undefined;
|
|
@@ -8932,11 +8048,16 @@ void main() {
|
|
|
8932
8048
|
return this[P_DEVICE].name;
|
|
8933
8049
|
}
|
|
8934
8050
|
grantOfferedSession() {
|
|
8935
|
-
|
|
8936
|
-
const pSystem =
|
|
8051
|
+
const xrSystem = this[P_DEVICE].xrSystem;
|
|
8052
|
+
const pSystem = xrSystem === null || xrSystem === void 0 ? void 0 : xrSystem[P_SYSTEM];
|
|
8937
8053
|
if (pSystem && pSystem.offeredSessionConfig) {
|
|
8938
|
-
pSystem.
|
|
8054
|
+
const { resolve, reject, mode, options } = pSystem.offeredSessionConfig;
|
|
8055
|
+
// Clear the offered session config first
|
|
8939
8056
|
pSystem.offeredSessionConfig = undefined;
|
|
8057
|
+
// Use the same requestSession flow to ensure identical behavior
|
|
8058
|
+
xrSystem.requestSession(mode, options)
|
|
8059
|
+
.then(resolve)
|
|
8060
|
+
.catch(reject);
|
|
8940
8061
|
}
|
|
8941
8062
|
}
|
|
8942
8063
|
recenter() {
|
|
@@ -9255,7 +8376,7 @@ void main() {
|
|
|
9255
8376
|
*/
|
|
9256
8377
|
const compress = (arr) => {
|
|
9257
8378
|
const out = [];
|
|
9258
|
-
arr.forEach((num) => {
|
|
8379
|
+
Array.from(arr).forEach((num) => {
|
|
9259
8380
|
out.push(parseFloat(num.toFixed(3)));
|
|
9260
8381
|
});
|
|
9261
8382
|
return out;
|
|
@@ -9278,8 +8399,8 @@ void main() {
|
|
|
9278
8399
|
const viewerMatrix = (_a = frame.getViewerPose(this[P_ACTION_RECORDER].refSpace)) === null || _a === void 0 ? void 0 : _a.transform.matrix;
|
|
9279
8400
|
if (!viewerMatrix)
|
|
9280
8401
|
return;
|
|
9281
|
-
const position = getTranslation(create$
|
|
9282
|
-
const quaternion = getRotation(create$
|
|
8402
|
+
const position = getTranslation(create$4(), viewerMatrix);
|
|
8403
|
+
const quaternion = getRotation(create$2(), viewerMatrix);
|
|
9283
8404
|
const actionFrame = {
|
|
9284
8405
|
timeStamp,
|
|
9285
8406
|
position,
|
|
@@ -9313,8 +8434,8 @@ void main() {
|
|
|
9313
8434
|
const schema = this[P_ACTION_RECORDER].schemaMap.get(index);
|
|
9314
8435
|
const targetRayMatrix = (_a = frame.getPose(inputSource.targetRaySpace, this[P_ACTION_RECORDER].refSpace)) === null || _a === void 0 ? void 0 : _a.transform.matrix;
|
|
9315
8436
|
if (targetRayMatrix) {
|
|
9316
|
-
const targetRayPosition = getTranslation(create$
|
|
9317
|
-
const targetRayQuaternion = getRotation(create$
|
|
8437
|
+
const targetRayPosition = getTranslation(create$4(), targetRayMatrix);
|
|
8438
|
+
const targetRayQuaternion = getRotation(create$2(), targetRayMatrix);
|
|
9318
8439
|
const inputFrame = {
|
|
9319
8440
|
index,
|
|
9320
8441
|
targetRayTransform: {
|
|
@@ -9325,8 +8446,8 @@ void main() {
|
|
|
9325
8446
|
if (schema.hasGrip) {
|
|
9326
8447
|
const gripMatrix = (_b = frame.getPose(inputSource.gripSpace, this[P_ACTION_RECORDER].refSpace)) === null || _b === void 0 ? void 0 : _b.transform.matrix;
|
|
9327
8448
|
if (gripMatrix) {
|
|
9328
|
-
const position = getTranslation(create$
|
|
9329
|
-
const quaternion = getRotation(create$
|
|
8449
|
+
const position = getTranslation(create$4(), gripMatrix);
|
|
8450
|
+
const quaternion = getRotation(create$2(), gripMatrix);
|
|
9330
8451
|
inputFrame.gripTransform = {
|
|
9331
8452
|
position,
|
|
9332
8453
|
quaternion,
|
|
@@ -9345,8 +8466,8 @@ void main() {
|
|
|
9345
8466
|
for (let offset = 0; offset < 25; offset++) {
|
|
9346
8467
|
const jointMatrix = this[P_ACTION_RECORDER].jointTransforms.slice(offset * 16, (offset + 1) * 16);
|
|
9347
8468
|
const radius = this[P_ACTION_RECORDER].jointRadii[offset];
|
|
9348
|
-
const position = getTranslation(create$
|
|
9349
|
-
const quaternion = getRotation(create$
|
|
8469
|
+
const position = getTranslation(create$4(), jointMatrix);
|
|
8470
|
+
const quaternion = getRotation(create$2(), jointMatrix);
|
|
9350
8471
|
const jointName = jointSpaces[offset].jointName;
|
|
9351
8472
|
hand[jointName] = { position, quaternion, radius };
|
|
9352
8473
|
}
|