iwer 1.0.1 → 1.0.2
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/README.md +11 -1
- package/build/iwer.js +216 -199
- package/build/iwer.min.js +1 -1
- package/build/iwer.module.js +216 -199
- package/build/iwer.module.min.js +1 -1
- package/lib/device/XRController.d.ts +6 -1
- package/lib/device/XRController.d.ts.map +1 -1
- package/lib/device/XRController.js +16 -5
- package/lib/device/XRController.js.map +1 -1
- package/lib/device/XRDevice.d.ts +4 -1
- package/lib/device/XRDevice.d.ts.map +1 -1
- package/lib/device/XRDevice.js +8 -2
- package/lib/device/XRDevice.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/build/iwer.module.js
CHANGED
|
@@ -1281,11 +1281,11 @@ var normalize = normalize$1;
|
|
|
1281
1281
|
* This source code is licensed under the MIT license found in the
|
|
1282
1282
|
* LICENSE file in the root directory of this source tree.
|
|
1283
1283
|
*/
|
|
1284
|
-
const PRIVATE$
|
|
1284
|
+
const PRIVATE$l = Symbol('@immersive-web-emulation-runtime/xr-space');
|
|
1285
1285
|
class XRSpace extends EventTarget {
|
|
1286
1286
|
constructor(parentSpace, offsetMatrix) {
|
|
1287
1287
|
super();
|
|
1288
|
-
this[PRIVATE$
|
|
1288
|
+
this[PRIVATE$l] = {
|
|
1289
1289
|
parentSpace,
|
|
1290
1290
|
offsetMatrix: offsetMatrix ? clone(offsetMatrix) : create$3(),
|
|
1291
1291
|
emulated: true,
|
|
@@ -1300,27 +1300,27 @@ class GlobalSpace extends XRSpace {
|
|
|
1300
1300
|
class XRSpaceUtils {
|
|
1301
1301
|
// Update the position component of the offsetMatrix of a given XRSpace
|
|
1302
1302
|
static updateOffsetPosition(space, position) {
|
|
1303
|
-
const offsetMatrix = space[PRIVATE$
|
|
1303
|
+
const offsetMatrix = space[PRIVATE$l].offsetMatrix;
|
|
1304
1304
|
fromTranslation(offsetMatrix, position);
|
|
1305
1305
|
}
|
|
1306
1306
|
// Update the rotation component of the offsetMatrix of a given XRSpace using a quaternion
|
|
1307
1307
|
static updateOffsetQuaternion(space, quaternion) {
|
|
1308
|
-
const offsetMatrix = space[PRIVATE$
|
|
1308
|
+
const offsetMatrix = space[PRIVATE$l].offsetMatrix;
|
|
1309
1309
|
const translation = create$2();
|
|
1310
1310
|
getTranslation(translation, offsetMatrix);
|
|
1311
1311
|
fromRotationTranslation(offsetMatrix, quaternion, translation);
|
|
1312
1312
|
}
|
|
1313
1313
|
// Update the offsetMatrix of a given XRSpace directly
|
|
1314
1314
|
static updateOffsetMatrix(space, matrix) {
|
|
1315
|
-
const offsetMatrix = space[PRIVATE$
|
|
1315
|
+
const offsetMatrix = space[PRIVATE$l].offsetMatrix;
|
|
1316
1316
|
copy$3(offsetMatrix, matrix);
|
|
1317
1317
|
}
|
|
1318
1318
|
// Calculate the global offset matrix for a given XRSpace
|
|
1319
1319
|
static calculateGlobalOffsetMatrix(space, globalOffset = create$3()) {
|
|
1320
|
-
const parentOffset = space[PRIVATE$
|
|
1321
|
-
? XRSpaceUtils.calculateGlobalOffsetMatrix(space[PRIVATE$
|
|
1320
|
+
const parentOffset = space[PRIVATE$l].parentSpace
|
|
1321
|
+
? XRSpaceUtils.calculateGlobalOffsetMatrix(space[PRIVATE$l].parentSpace)
|
|
1322
1322
|
: create$3(); // Identity matrix for GlobalSpace
|
|
1323
|
-
multiply$1(globalOffset, parentOffset, space[PRIVATE$
|
|
1323
|
+
multiply$1(globalOffset, parentOffset, space[PRIVATE$l].offsetMatrix);
|
|
1324
1324
|
return globalOffset;
|
|
1325
1325
|
}
|
|
1326
1326
|
}
|
|
@@ -1464,7 +1464,7 @@ class Quaternion {
|
|
|
1464
1464
|
* This source code is licensed under the MIT license found in the
|
|
1465
1465
|
* LICENSE file in the root directory of this source tree.
|
|
1466
1466
|
*/
|
|
1467
|
-
const PRIVATE$
|
|
1467
|
+
const PRIVATE$k = Symbol('@immersive-web-emulation-runtime/gamepad');
|
|
1468
1468
|
var GamepadMappingType;
|
|
1469
1469
|
(function (GamepadMappingType) {
|
|
1470
1470
|
GamepadMappingType["None"] = "";
|
|
@@ -1473,7 +1473,7 @@ var GamepadMappingType;
|
|
|
1473
1473
|
})(GamepadMappingType || (GamepadMappingType = {}));
|
|
1474
1474
|
class GamepadButton {
|
|
1475
1475
|
constructor(type, eventTrigger) {
|
|
1476
|
-
this[PRIVATE$
|
|
1476
|
+
this[PRIVATE$k] = {
|
|
1477
1477
|
type,
|
|
1478
1478
|
eventTrigger,
|
|
1479
1479
|
pressed: false,
|
|
@@ -1484,23 +1484,23 @@ class GamepadButton {
|
|
|
1484
1484
|
};
|
|
1485
1485
|
}
|
|
1486
1486
|
get pressed() {
|
|
1487
|
-
if (this[PRIVATE$
|
|
1488
|
-
return this[PRIVATE$
|
|
1487
|
+
if (this[PRIVATE$k].type === 'manual') {
|
|
1488
|
+
return this[PRIVATE$k].pressed;
|
|
1489
1489
|
}
|
|
1490
1490
|
else {
|
|
1491
|
-
return this[PRIVATE$
|
|
1491
|
+
return this[PRIVATE$k].value > 0;
|
|
1492
1492
|
}
|
|
1493
1493
|
}
|
|
1494
1494
|
get touched() {
|
|
1495
|
-
if (this[PRIVATE$
|
|
1496
|
-
return this[PRIVATE$
|
|
1495
|
+
if (this[PRIVATE$k].type === 'manual') {
|
|
1496
|
+
return this[PRIVATE$k].touched;
|
|
1497
1497
|
}
|
|
1498
1498
|
else {
|
|
1499
|
-
return this[PRIVATE$
|
|
1499
|
+
return this[PRIVATE$k].touched || this.pressed;
|
|
1500
1500
|
}
|
|
1501
1501
|
}
|
|
1502
1502
|
get value() {
|
|
1503
|
-
return this[PRIVATE$
|
|
1503
|
+
return this[PRIVATE$k].value;
|
|
1504
1504
|
}
|
|
1505
1505
|
}
|
|
1506
1506
|
class EmptyGamepadButton {
|
|
@@ -1512,7 +1512,7 @@ class EmptyGamepadButton {
|
|
|
1512
1512
|
}
|
|
1513
1513
|
class Gamepad {
|
|
1514
1514
|
constructor(gamepadConfig, id = '', index = -1) {
|
|
1515
|
-
this[PRIVATE$
|
|
1515
|
+
this[PRIVATE$k] = {
|
|
1516
1516
|
id,
|
|
1517
1517
|
index,
|
|
1518
1518
|
connected: false,
|
|
@@ -1527,43 +1527,43 @@ class Gamepad {
|
|
|
1527
1527
|
gamepadConfig.buttons.forEach((buttonConfig) => {
|
|
1528
1528
|
var _a;
|
|
1529
1529
|
if (buttonConfig === null) {
|
|
1530
|
-
this[PRIVATE$
|
|
1530
|
+
this[PRIVATE$k].buttonsSequence.push(null);
|
|
1531
1531
|
}
|
|
1532
1532
|
else {
|
|
1533
|
-
this[PRIVATE$
|
|
1534
|
-
this[PRIVATE$
|
|
1533
|
+
this[PRIVATE$k].buttonsSequence.push(buttonConfig.id);
|
|
1534
|
+
this[PRIVATE$k].buttonsMap[buttonConfig.id] = new GamepadButton(buttonConfig.type, (_a = buttonConfig.eventTrigger) !== null && _a !== void 0 ? _a : null);
|
|
1535
1535
|
}
|
|
1536
1536
|
});
|
|
1537
1537
|
gamepadConfig.axes.forEach((axisConfig) => {
|
|
1538
1538
|
if (axisConfig === null) {
|
|
1539
|
-
this[PRIVATE$
|
|
1539
|
+
this[PRIVATE$k].axesSequence.push(null);
|
|
1540
1540
|
}
|
|
1541
1541
|
else {
|
|
1542
|
-
this[PRIVATE$
|
|
1543
|
-
if (!this[PRIVATE$
|
|
1544
|
-
this[PRIVATE$
|
|
1542
|
+
this[PRIVATE$k].axesSequence.push(axisConfig.id + axisConfig.type);
|
|
1543
|
+
if (!this[PRIVATE$k].axesMap[axisConfig.id]) {
|
|
1544
|
+
this[PRIVATE$k].axesMap[axisConfig.id] = { x: 0, y: 0 };
|
|
1545
1545
|
}
|
|
1546
1546
|
}
|
|
1547
1547
|
});
|
|
1548
1548
|
}
|
|
1549
1549
|
get id() {
|
|
1550
|
-
return this[PRIVATE$
|
|
1550
|
+
return this[PRIVATE$k].id;
|
|
1551
1551
|
}
|
|
1552
1552
|
get index() {
|
|
1553
|
-
return this[PRIVATE$
|
|
1553
|
+
return this[PRIVATE$k].index;
|
|
1554
1554
|
}
|
|
1555
1555
|
get connected() {
|
|
1556
|
-
return this[PRIVATE$
|
|
1556
|
+
return this[PRIVATE$k].connected;
|
|
1557
1557
|
}
|
|
1558
1558
|
get timestamp() {
|
|
1559
|
-
return this[PRIVATE$
|
|
1559
|
+
return this[PRIVATE$k].timestamp;
|
|
1560
1560
|
}
|
|
1561
1561
|
get mapping() {
|
|
1562
|
-
return this[PRIVATE$
|
|
1562
|
+
return this[PRIVATE$k].mapping;
|
|
1563
1563
|
}
|
|
1564
1564
|
get axes() {
|
|
1565
1565
|
const axes = [];
|
|
1566
|
-
this[PRIVATE$
|
|
1566
|
+
this[PRIVATE$k].axesSequence.forEach((id) => {
|
|
1567
1567
|
if (id === null) {
|
|
1568
1568
|
axes.push(null);
|
|
1569
1569
|
}
|
|
@@ -1573,17 +1573,17 @@ class Gamepad {
|
|
|
1573
1573
|
axes.push(
|
|
1574
1574
|
// if axis type is manual, then return the x value
|
|
1575
1575
|
axisType === 'y-axis'
|
|
1576
|
-
? this[PRIVATE$
|
|
1577
|
-
: this[PRIVATE$
|
|
1576
|
+
? this[PRIVATE$k].axesMap[axisId].y
|
|
1577
|
+
: this[PRIVATE$k].axesMap[axisId].x);
|
|
1578
1578
|
}
|
|
1579
1579
|
});
|
|
1580
1580
|
return axes;
|
|
1581
1581
|
}
|
|
1582
1582
|
get buttons() {
|
|
1583
|
-
return this[PRIVATE$
|
|
1583
|
+
return this[PRIVATE$k].buttonsSequence.map((id) => id === null ? new EmptyGamepadButton() : this[PRIVATE$k].buttonsMap[id]);
|
|
1584
1584
|
}
|
|
1585
1585
|
get hapticActuators() {
|
|
1586
|
-
return this[PRIVATE$
|
|
1586
|
+
return this[PRIVATE$k].hapticActuators;
|
|
1587
1587
|
}
|
|
1588
1588
|
get vibrationActuator() {
|
|
1589
1589
|
return null;
|
|
@@ -1611,10 +1611,10 @@ var XRTargetRayMode;
|
|
|
1611
1611
|
})(XRTargetRayMode || (XRTargetRayMode = {}));
|
|
1612
1612
|
class XRInputSourceArray extends Array {
|
|
1613
1613
|
}
|
|
1614
|
-
const PRIVATE$
|
|
1614
|
+
const PRIVATE$j = Symbol('@immersive-web-emulation-runtime/xr-input-source');
|
|
1615
1615
|
class XRInputSource {
|
|
1616
1616
|
constructor(handedness, targetRayMode, profiles, targetRaySpace, gamepad, gripSpace, hand) {
|
|
1617
|
-
this[PRIVATE$
|
|
1617
|
+
this[PRIVATE$j] = {
|
|
1618
1618
|
handedness,
|
|
1619
1619
|
targetRayMode,
|
|
1620
1620
|
targetRaySpace,
|
|
@@ -1625,25 +1625,25 @@ class XRInputSource {
|
|
|
1625
1625
|
};
|
|
1626
1626
|
}
|
|
1627
1627
|
get handedness() {
|
|
1628
|
-
return this[PRIVATE$
|
|
1628
|
+
return this[PRIVATE$j].handedness;
|
|
1629
1629
|
}
|
|
1630
1630
|
get targetRayMode() {
|
|
1631
|
-
return this[PRIVATE$
|
|
1631
|
+
return this[PRIVATE$j].targetRayMode;
|
|
1632
1632
|
}
|
|
1633
1633
|
get targetRaySpace() {
|
|
1634
|
-
return this[PRIVATE$
|
|
1634
|
+
return this[PRIVATE$j].targetRaySpace;
|
|
1635
1635
|
}
|
|
1636
1636
|
get gripSpace() {
|
|
1637
|
-
return this[PRIVATE$
|
|
1637
|
+
return this[PRIVATE$j].gripSpace;
|
|
1638
1638
|
}
|
|
1639
1639
|
get profiles() {
|
|
1640
|
-
return this[PRIVATE$
|
|
1640
|
+
return this[PRIVATE$j].profiles;
|
|
1641
1641
|
}
|
|
1642
1642
|
get gamepad() {
|
|
1643
|
-
return this[PRIVATE$
|
|
1643
|
+
return this[PRIVATE$j].gamepad;
|
|
1644
1644
|
}
|
|
1645
1645
|
get hand() {
|
|
1646
|
-
return this[PRIVATE$
|
|
1646
|
+
return this[PRIVATE$j].hand;
|
|
1647
1647
|
}
|
|
1648
1648
|
}
|
|
1649
1649
|
|
|
@@ -1673,7 +1673,7 @@ class XRInputSourceEvent extends Event {
|
|
|
1673
1673
|
* This source code is licensed under the MIT license found in the
|
|
1674
1674
|
* LICENSE file in the root directory of this source tree.
|
|
1675
1675
|
*/
|
|
1676
|
-
const PRIVATE$
|
|
1676
|
+
const PRIVATE$i = Symbol('@immersive-web-emulation-runtime/xr-tracked-input');
|
|
1677
1677
|
const DEFAULT_TRANSFORM = {
|
|
1678
1678
|
[XRHandedness.Left]: {
|
|
1679
1679
|
position: new Vector3(-0.25, 1.5, -0.4),
|
|
@@ -1690,7 +1690,7 @@ const DEFAULT_TRANSFORM = {
|
|
|
1690
1690
|
};
|
|
1691
1691
|
class XRTrackedInput {
|
|
1692
1692
|
constructor(inputSource) {
|
|
1693
|
-
this[PRIVATE$
|
|
1693
|
+
this[PRIVATE$i] = {
|
|
1694
1694
|
inputSource,
|
|
1695
1695
|
position: DEFAULT_TRANSFORM[inputSource.handedness].position.clone(),
|
|
1696
1696
|
quaternion: DEFAULT_TRANSFORM[inputSource.handedness].quaternion.clone(),
|
|
@@ -1700,59 +1700,59 @@ class XRTrackedInput {
|
|
|
1700
1700
|
};
|
|
1701
1701
|
}
|
|
1702
1702
|
get position() {
|
|
1703
|
-
return this[PRIVATE$
|
|
1703
|
+
return this[PRIVATE$i].position;
|
|
1704
1704
|
}
|
|
1705
1705
|
get quaternion() {
|
|
1706
|
-
return this[PRIVATE$
|
|
1706
|
+
return this[PRIVATE$i].quaternion;
|
|
1707
1707
|
}
|
|
1708
1708
|
get inputSource() {
|
|
1709
|
-
return this[PRIVATE$
|
|
1709
|
+
return this[PRIVATE$i].inputSource;
|
|
1710
1710
|
}
|
|
1711
1711
|
get connected() {
|
|
1712
|
-
return this[PRIVATE$
|
|
1712
|
+
return this[PRIVATE$i].connected;
|
|
1713
1713
|
}
|
|
1714
1714
|
set connected(value) {
|
|
1715
|
-
this[PRIVATE$
|
|
1716
|
-
this[PRIVATE$
|
|
1715
|
+
this[PRIVATE$i].connected = value;
|
|
1716
|
+
this[PRIVATE$i].inputSource.gamepad[PRIVATE$k].connected = value;
|
|
1717
1717
|
}
|
|
1718
1718
|
onFrameStart(frame) {
|
|
1719
|
-
const targetRaySpace = this[PRIVATE$
|
|
1720
|
-
fromRotationTranslation(targetRaySpace[PRIVATE$
|
|
1719
|
+
const targetRaySpace = this[PRIVATE$i].inputSource.targetRaySpace;
|
|
1720
|
+
fromRotationTranslation(targetRaySpace[PRIVATE$l].offsetMatrix, this[PRIVATE$i].quaternion.quat, this[PRIVATE$i].position.vec3);
|
|
1721
1721
|
const session = frame.session;
|
|
1722
|
-
this[PRIVATE$
|
|
1722
|
+
this[PRIVATE$i].inputSource.gamepad.buttons.forEach((button) => {
|
|
1723
1723
|
if (button instanceof GamepadButton) {
|
|
1724
1724
|
// apply pending values and record last frame values
|
|
1725
|
-
button[PRIVATE$
|
|
1726
|
-
if (button[PRIVATE$
|
|
1727
|
-
button[PRIVATE$
|
|
1728
|
-
button[PRIVATE$
|
|
1725
|
+
button[PRIVATE$k].lastFrameValue = button[PRIVATE$k].value;
|
|
1726
|
+
if (button[PRIVATE$k].pendingValue != null) {
|
|
1727
|
+
button[PRIVATE$k].value = button[PRIVATE$k].pendingValue;
|
|
1728
|
+
button[PRIVATE$k].pendingValue = null;
|
|
1729
1729
|
}
|
|
1730
1730
|
// trigger input source events
|
|
1731
|
-
if (button[PRIVATE$
|
|
1732
|
-
if (button[PRIVATE$
|
|
1733
|
-
button[PRIVATE$
|
|
1734
|
-
session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$
|
|
1731
|
+
if (button[PRIVATE$k].eventTrigger != null) {
|
|
1732
|
+
if (button[PRIVATE$k].lastFrameValue === 0 &&
|
|
1733
|
+
button[PRIVATE$k].value > 0) {
|
|
1734
|
+
session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$k].eventTrigger, {
|
|
1735
1735
|
frame,
|
|
1736
|
-
inputSource: this[PRIVATE$
|
|
1736
|
+
inputSource: this[PRIVATE$i].inputSource,
|
|
1737
1737
|
}));
|
|
1738
|
-
session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$
|
|
1738
|
+
session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$k].eventTrigger + 'start', {
|
|
1739
1739
|
frame,
|
|
1740
|
-
inputSource: this[PRIVATE$
|
|
1740
|
+
inputSource: this[PRIVATE$i].inputSource,
|
|
1741
1741
|
}));
|
|
1742
1742
|
}
|
|
1743
|
-
else if (button[PRIVATE$
|
|
1744
|
-
button[PRIVATE$
|
|
1745
|
-
session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$
|
|
1743
|
+
else if (button[PRIVATE$k].lastFrameValue > 0 &&
|
|
1744
|
+
button[PRIVATE$k].value === 0) {
|
|
1745
|
+
session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$k].eventTrigger + 'end', {
|
|
1746
1746
|
frame,
|
|
1747
|
-
inputSource: this[PRIVATE$
|
|
1747
|
+
inputSource: this[PRIVATE$i].inputSource,
|
|
1748
1748
|
}));
|
|
1749
1749
|
}
|
|
1750
1750
|
}
|
|
1751
1751
|
}
|
|
1752
1752
|
});
|
|
1753
|
-
this[PRIVATE$
|
|
1754
|
-
this.connected !== this[PRIVATE$
|
|
1755
|
-
this[PRIVATE$
|
|
1753
|
+
this[PRIVATE$i].inputSourceChanged =
|
|
1754
|
+
this.connected !== this[PRIVATE$i].lastFrameConnected;
|
|
1755
|
+
this[PRIVATE$i].lastFrameConnected = this.connected;
|
|
1756
1756
|
}
|
|
1757
1757
|
}
|
|
1758
1758
|
|
|
@@ -1762,6 +1762,7 @@ class XRTrackedInput {
|
|
|
1762
1762
|
* This source code is licensed under the MIT license found in the
|
|
1763
1763
|
* LICENSE file in the root directory of this source tree.
|
|
1764
1764
|
*/
|
|
1765
|
+
const PRIVATE$h = Symbol('@immersive-web-emulation-runtime/xr-controller');
|
|
1765
1766
|
class XRController extends XRTrackedInput {
|
|
1766
1767
|
constructor(controllerConfig, handedness, globalSpace) {
|
|
1767
1768
|
if (!controllerConfig.layout[handedness]) {
|
|
@@ -1777,30 +1778,38 @@ class XRController extends XRTrackedInput {
|
|
|
1777
1778
|
];
|
|
1778
1779
|
const inputSource = new XRInputSource(handedness, XRTargetRayMode.TrackedPointer, profiles, targetRaySpace, new Gamepad(controllerConfig.layout[handedness].gamepad), gripSpace);
|
|
1779
1780
|
super(inputSource);
|
|
1781
|
+
this[PRIVATE$h] = {
|
|
1782
|
+
gamepadConfig: controllerConfig.layout[handedness].gamepad,
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
get gamepadConfig() {
|
|
1786
|
+
return this[PRIVATE$h].gamepadConfig;
|
|
1780
1787
|
}
|
|
1781
1788
|
updateButtonValue(id, value) {
|
|
1782
1789
|
if (value > 1 || value < 0) {
|
|
1783
1790
|
console.warn(`Out-of-range value ${value} provided for button ${id}.`);
|
|
1784
1791
|
return;
|
|
1785
1792
|
}
|
|
1786
|
-
const gamepadButton = this[PRIVATE$
|
|
1793
|
+
const gamepadButton = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
|
|
1794
|
+
.buttonsMap[id];
|
|
1787
1795
|
if (gamepadButton) {
|
|
1788
|
-
if (gamepadButton[PRIVATE$
|
|
1796
|
+
if (gamepadButton[PRIVATE$k].type === 'binary' &&
|
|
1789
1797
|
value != 1 &&
|
|
1790
1798
|
value != 0) {
|
|
1791
1799
|
console.warn(`Non-binary value ${value} provided for binary button ${id}.`);
|
|
1792
1800
|
return;
|
|
1793
1801
|
}
|
|
1794
|
-
gamepadButton[PRIVATE$
|
|
1802
|
+
gamepadButton[PRIVATE$k].pendingValue = value;
|
|
1795
1803
|
}
|
|
1796
1804
|
else {
|
|
1797
1805
|
console.warn(`Current controller does not have button ${id}.`);
|
|
1798
1806
|
}
|
|
1799
1807
|
}
|
|
1800
1808
|
updateButtonTouch(id, touched) {
|
|
1801
|
-
const gamepadButton = this[PRIVATE$
|
|
1809
|
+
const gamepadButton = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
|
|
1810
|
+
.buttonsMap[id];
|
|
1802
1811
|
if (gamepadButton) {
|
|
1803
|
-
gamepadButton[PRIVATE$
|
|
1812
|
+
gamepadButton[PRIVATE$k].touched = touched;
|
|
1804
1813
|
}
|
|
1805
1814
|
else {
|
|
1806
1815
|
console.warn(`Current controller does not have button ${id}.`);
|
|
@@ -1811,7 +1820,8 @@ class XRController extends XRTrackedInput {
|
|
|
1811
1820
|
console.warn(`Out-of-range value ${value} provided for ${id} axes.`);
|
|
1812
1821
|
return;
|
|
1813
1822
|
}
|
|
1814
|
-
const axesById = this[PRIVATE$
|
|
1823
|
+
const axesById = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
|
|
1824
|
+
.axesMap[id];
|
|
1815
1825
|
if (axesById) {
|
|
1816
1826
|
if (type === 'x-axis') {
|
|
1817
1827
|
axesById.x = value;
|
|
@@ -1829,7 +1839,8 @@ class XRController extends XRTrackedInput {
|
|
|
1829
1839
|
console.warn(`Out-of-range value x:${x}, y:${y} provided for ${id} axes.`);
|
|
1830
1840
|
return;
|
|
1831
1841
|
}
|
|
1832
|
-
const axesById = this[PRIVATE$
|
|
1842
|
+
const axesById = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
|
|
1843
|
+
.axesMap[id];
|
|
1833
1844
|
if (axesById) {
|
|
1834
1845
|
axesById.x = x;
|
|
1835
1846
|
axesById.y = y;
|
|
@@ -2764,20 +2775,20 @@ class XRHandInput extends XRTrackedInput {
|
|
|
2764
2775
|
const targetJointMatrix = targetPose.jointTransforms[jointName].offsetMatrix;
|
|
2765
2776
|
const pinchJointMatrix = pinchPose.jointTransforms[jointName].offsetMatrix;
|
|
2766
2777
|
const jointSpace = this.inputSource.hand.get(jointName);
|
|
2767
|
-
interpolateMatrix(jointSpace[PRIVATE$
|
|
2778
|
+
interpolateMatrix(jointSpace[PRIVATE$l].offsetMatrix, targetJointMatrix, pinchJointMatrix, this.pinchValue);
|
|
2768
2779
|
if (this.inputSource.handedness === XRHandedness.Right) {
|
|
2769
|
-
mirrorMatrixToRight(jointSpace[PRIVATE$
|
|
2780
|
+
mirrorMatrixToRight(jointSpace[PRIVATE$l].offsetMatrix);
|
|
2770
2781
|
}
|
|
2771
2782
|
jointSpace[PRIVATE$f].radius =
|
|
2772
2783
|
(1 - this.pinchValue) * targetPose.jointTransforms[jointName].radius +
|
|
2773
2784
|
this.pinchValue * pinchPose.jointTransforms[jointName].radius;
|
|
2774
2785
|
});
|
|
2775
2786
|
if (targetPose.gripOffsetMatrix && pinchPose.gripOffsetMatrix) {
|
|
2776
|
-
interpolateMatrix(this.inputSource.gripSpace[PRIVATE$
|
|
2787
|
+
interpolateMatrix(this.inputSource.gripSpace[PRIVATE$l].offsetMatrix, targetPose.gripOffsetMatrix, pinchPose.gripOffsetMatrix, this.pinchValue);
|
|
2777
2788
|
}
|
|
2778
2789
|
}
|
|
2779
2790
|
get pinchValue() {
|
|
2780
|
-
return this[PRIVATE$
|
|
2791
|
+
return this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
|
|
2781
2792
|
.buttonsMap['pinch'].value;
|
|
2782
2793
|
}
|
|
2783
2794
|
updatePinchValue(value) {
|
|
@@ -2785,9 +2796,9 @@ class XRHandInput extends XRTrackedInput {
|
|
|
2785
2796
|
console.warn(`Out-of-range value ${value} provided for pinch`);
|
|
2786
2797
|
return;
|
|
2787
2798
|
}
|
|
2788
|
-
const gamepadButton = this[PRIVATE$
|
|
2799
|
+
const gamepadButton = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
|
|
2789
2800
|
.buttonsMap['pinch'];
|
|
2790
|
-
gamepadButton[PRIVATE$
|
|
2801
|
+
gamepadButton[PRIVATE$k].pendingValue = value;
|
|
2791
2802
|
}
|
|
2792
2803
|
onFrameStart(frame) {
|
|
2793
2804
|
super.onFrameStart(frame);
|
|
@@ -2998,7 +3009,7 @@ class XRFrame {
|
|
|
2998
3009
|
y: orientation[1],
|
|
2999
3010
|
z: orientation[2],
|
|
3000
3011
|
w: orientation[3],
|
|
3001
|
-
}), space[PRIVATE$
|
|
3012
|
+
}), space[PRIVATE$l].emulated);
|
|
3002
3013
|
}
|
|
3003
3014
|
getViewerPose(referenceSpace) {
|
|
3004
3015
|
if (!this[PRIVATE$9].animationFrame) {
|
|
@@ -3464,7 +3475,7 @@ class XRSession extends EventTarget {
|
|
|
3464
3475
|
break;
|
|
3465
3476
|
case XRReferenceSpaceType.Local:
|
|
3466
3477
|
// creating an XRReferenceSpace with the current headset transform in global space
|
|
3467
|
-
referenceSpace = new XRReferenceSpace(type, this[PRIVATE$6].device[PRIVATE$1].globalSpace, this[PRIVATE$6].device.viewerSpace[PRIVATE$
|
|
3478
|
+
referenceSpace = new XRReferenceSpace(type, this[PRIVATE$6].device[PRIVATE$1].globalSpace, this[PRIVATE$6].device.viewerSpace[PRIVATE$l].offsetMatrix);
|
|
3468
3479
|
break;
|
|
3469
3480
|
case XRReferenceSpaceType.LocalFloor:
|
|
3470
3481
|
case XRReferenceSpaceType.BoundedFloor:
|
|
@@ -3730,7 +3741,76 @@ class XRWebGLLayer extends XRLayer {
|
|
|
3730
3741
|
* This source code is licensed under the MIT license found in the
|
|
3731
3742
|
* LICENSE file in the root directory of this source tree.
|
|
3732
3743
|
*/
|
|
3733
|
-
const PRIVATE$4 = Symbol('@immersive-web-emulation-runtime/
|
|
3744
|
+
const PRIVATE$4 = Symbol('@immersive-web-emulation-runtime/xr-system');
|
|
3745
|
+
class XRSystem extends EventTarget {
|
|
3746
|
+
constructor(device) {
|
|
3747
|
+
super();
|
|
3748
|
+
this[PRIVATE$4] = { device };
|
|
3749
|
+
// Initialize device change monitoring here if applicable
|
|
3750
|
+
}
|
|
3751
|
+
isSessionSupported(mode) {
|
|
3752
|
+
return new Promise((resolve, _reject) => {
|
|
3753
|
+
if (mode === XRSessionMode.Inline) {
|
|
3754
|
+
resolve(true);
|
|
3755
|
+
}
|
|
3756
|
+
else {
|
|
3757
|
+
// Check for spatial tracking permission if necessary
|
|
3758
|
+
resolve(this[PRIVATE$4].device.supportedSessionModes.includes(mode));
|
|
3759
|
+
}
|
|
3760
|
+
});
|
|
3761
|
+
}
|
|
3762
|
+
requestSession(mode, options = {}) {
|
|
3763
|
+
return new Promise((resolve, reject) => {
|
|
3764
|
+
this.isSessionSupported(mode)
|
|
3765
|
+
.then((isSupported) => {
|
|
3766
|
+
if (!isSupported) {
|
|
3767
|
+
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
3768
|
+
return;
|
|
3769
|
+
}
|
|
3770
|
+
// Check for active sessions and other constraints here
|
|
3771
|
+
if (this[PRIVATE$4].activeSession) {
|
|
3772
|
+
reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
|
|
3773
|
+
return;
|
|
3774
|
+
}
|
|
3775
|
+
// Handle required and optional features
|
|
3776
|
+
const { requiredFeatures = [], optionalFeatures = [] } = options;
|
|
3777
|
+
const { supportedFeatures } = this[PRIVATE$4].device;
|
|
3778
|
+
// Check if all required features are supported
|
|
3779
|
+
const allRequiredSupported = requiredFeatures.every((feature) => supportedFeatures.includes(feature));
|
|
3780
|
+
if (!allRequiredSupported) {
|
|
3781
|
+
reject(new Error('One or more required features are not supported by the device.'));
|
|
3782
|
+
return;
|
|
3783
|
+
}
|
|
3784
|
+
// Filter out unsupported optional features
|
|
3785
|
+
const supportedOptionalFeatures = optionalFeatures.filter((feature) => supportedFeatures.includes(feature));
|
|
3786
|
+
// Combine required and supported optional features into enabled features
|
|
3787
|
+
const enabledFeatures = Array.from(new Set([
|
|
3788
|
+
...requiredFeatures,
|
|
3789
|
+
...supportedOptionalFeatures,
|
|
3790
|
+
WebXRFeatures.Viewer,
|
|
3791
|
+
WebXRFeatures.Local,
|
|
3792
|
+
]));
|
|
3793
|
+
// Proceed with session creation
|
|
3794
|
+
const session = new XRSession(this[PRIVATE$4].device, mode, enabledFeatures);
|
|
3795
|
+
this[PRIVATE$4].activeSession = session;
|
|
3796
|
+
// Listen for session end to clear the active session
|
|
3797
|
+
session.addEventListener('end', () => {
|
|
3798
|
+
this[PRIVATE$4].activeSession = undefined;
|
|
3799
|
+
});
|
|
3800
|
+
resolve(session);
|
|
3801
|
+
})
|
|
3802
|
+
.catch(reject);
|
|
3803
|
+
});
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
/**
|
|
3808
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3809
|
+
*
|
|
3810
|
+
* This source code is licensed under the MIT license found in the
|
|
3811
|
+
* LICENSE file in the root directory of this source tree.
|
|
3812
|
+
*/
|
|
3813
|
+
const PRIVATE$3 = Symbol('@immersive-web-emulation-runtime/action-player');
|
|
3734
3814
|
class ActionPlayer {
|
|
3735
3815
|
constructor(refSpace, recording, ipd) {
|
|
3736
3816
|
const { schema, frames } = recording;
|
|
@@ -3743,7 +3823,7 @@ class ActionPlayer {
|
|
|
3743
3823
|
[XREye.Right]: new XRSpace(viewerSpace),
|
|
3744
3824
|
[XREye.None]: new XRSpace(viewerSpace),
|
|
3745
3825
|
};
|
|
3746
|
-
this[PRIVATE$
|
|
3826
|
+
this[PRIVATE$3] = {
|
|
3747
3827
|
refSpace,
|
|
3748
3828
|
inputSources: new Map(),
|
|
3749
3829
|
inputSchemas: new Map(),
|
|
@@ -3758,8 +3838,8 @@ class ActionPlayer {
|
|
|
3758
3838
|
vec3: create$2(),
|
|
3759
3839
|
quat: create(),
|
|
3760
3840
|
};
|
|
3761
|
-
fromTranslation(this[PRIVATE$
|
|
3762
|
-
fromTranslation(this[PRIVATE$
|
|
3841
|
+
fromTranslation(this[PRIVATE$3].viewSpaces[XREye.Left][PRIVATE$l].offsetMatrix, fromValues$2(-ipd / 2, 0, 0));
|
|
3842
|
+
fromTranslation(this[PRIVATE$3].viewSpaces[XREye.Right][PRIVATE$l].offsetMatrix, fromValues$2(ipd / 2, 0, 0));
|
|
3763
3843
|
schema.forEach((schemaEntry) => {
|
|
3764
3844
|
const index = schemaEntry[0];
|
|
3765
3845
|
const schema = schemaEntry[1];
|
|
@@ -3788,53 +3868,53 @@ class ActionPlayer {
|
|
|
3788
3868
|
});
|
|
3789
3869
|
}
|
|
3790
3870
|
const inputSource = new XRInputSource(schema.handedness, schema.targetRayMode, schema.profiles, targetRaySpace, gamepad, schema.hasGrip ? new XRSpace(refSpace) : undefined, schema.hasHand ? hand : undefined);
|
|
3791
|
-
this[PRIVATE$
|
|
3871
|
+
this[PRIVATE$3].inputSources.set(index, {
|
|
3792
3872
|
active: false,
|
|
3793
3873
|
source: inputSource,
|
|
3794
3874
|
});
|
|
3795
|
-
this[PRIVATE$
|
|
3875
|
+
this[PRIVATE$3].inputSchemas.set(index, schema);
|
|
3796
3876
|
});
|
|
3797
3877
|
}
|
|
3798
3878
|
play() {
|
|
3799
|
-
this[PRIVATE$
|
|
3800
|
-
this[PRIVATE$
|
|
3801
|
-
this[PRIVATE$
|
|
3802
|
-
this[PRIVATE$
|
|
3879
|
+
this[PRIVATE$3].recordedFramePointer = 0;
|
|
3880
|
+
this[PRIVATE$3].playbackTime = this[PRIVATE$3].startingTimeStamp;
|
|
3881
|
+
this[PRIVATE$3].playing = true;
|
|
3882
|
+
this[PRIVATE$3].actualTimeStamp = performance.now();
|
|
3803
3883
|
}
|
|
3804
3884
|
stop() {
|
|
3805
|
-
this[PRIVATE$
|
|
3885
|
+
this[PRIVATE$3].playing = false;
|
|
3806
3886
|
}
|
|
3807
3887
|
get playing() {
|
|
3808
|
-
return this[PRIVATE$
|
|
3888
|
+
return this[PRIVATE$3].playing;
|
|
3809
3889
|
}
|
|
3810
3890
|
get viewerSpace() {
|
|
3811
|
-
return this[PRIVATE$
|
|
3891
|
+
return this[PRIVATE$3].viewerSpace;
|
|
3812
3892
|
}
|
|
3813
3893
|
get viewSpaces() {
|
|
3814
|
-
return this[PRIVATE$
|
|
3894
|
+
return this[PRIVATE$3].viewSpaces;
|
|
3815
3895
|
}
|
|
3816
3896
|
get inputSources() {
|
|
3817
|
-
return Array.from(this[PRIVATE$
|
|
3897
|
+
return Array.from(this[PRIVATE$3].inputSources.values())
|
|
3818
3898
|
.filter((wrapper) => wrapper.active)
|
|
3819
3899
|
.map((wrapper) => wrapper.source);
|
|
3820
3900
|
}
|
|
3821
3901
|
playFrame() {
|
|
3822
3902
|
const now = performance.now();
|
|
3823
|
-
const delta = now - this[PRIVATE$
|
|
3824
|
-
this[PRIVATE$
|
|
3825
|
-
this[PRIVATE$
|
|
3826
|
-
if (this[PRIVATE$
|
|
3903
|
+
const delta = now - this[PRIVATE$3].actualTimeStamp;
|
|
3904
|
+
this[PRIVATE$3].actualTimeStamp = now;
|
|
3905
|
+
this[PRIVATE$3].playbackTime += delta;
|
|
3906
|
+
if (this[PRIVATE$3].playbackTime > this[PRIVATE$3].endingTimeStamp) {
|
|
3827
3907
|
this.stop();
|
|
3828
3908
|
return;
|
|
3829
3909
|
}
|
|
3830
|
-
while (this[PRIVATE$
|
|
3831
|
-
this[PRIVATE$
|
|
3910
|
+
while (this[PRIVATE$3].frames[this[PRIVATE$3].recordedFramePointer + 1][0] < this[PRIVATE$3].playbackTime) {
|
|
3911
|
+
this[PRIVATE$3].recordedFramePointer++;
|
|
3832
3912
|
}
|
|
3833
|
-
const lastFrameData = this[PRIVATE$
|
|
3834
|
-
const nextFrameData = this[PRIVATE$
|
|
3835
|
-
const alpha = (this[PRIVATE$
|
|
3913
|
+
const lastFrameData = this[PRIVATE$3].frames[this[PRIVATE$3].recordedFramePointer];
|
|
3914
|
+
const nextFrameData = this[PRIVATE$3].frames[this[PRIVATE$3].recordedFramePointer + 1];
|
|
3915
|
+
const alpha = (this[PRIVATE$3].playbackTime - lastFrameData[0]) /
|
|
3836
3916
|
(nextFrameData[0] - lastFrameData[0]);
|
|
3837
|
-
this.updateXRSpaceFromMergedFrames(this[PRIVATE$
|
|
3917
|
+
this.updateXRSpaceFromMergedFrames(this[PRIVATE$3].viewerSpace, lastFrameData.slice(1, 8), nextFrameData.slice(1, 8), alpha);
|
|
3838
3918
|
const lastFrameInputs = new Map();
|
|
3839
3919
|
for (let i = 8; i < lastFrameData.length; i++) {
|
|
3840
3920
|
const { index, inputData } = this.processRawInputData(lastFrameData[i]);
|
|
@@ -3845,13 +3925,13 @@ class ActionPlayer {
|
|
|
3845
3925
|
const { index, inputData } = this.processRawInputData(nextFrameData[i]);
|
|
3846
3926
|
nextFrameInputs.set(index, inputData);
|
|
3847
3927
|
}
|
|
3848
|
-
this[PRIVATE$
|
|
3928
|
+
this[PRIVATE$3].inputSources.forEach((sourceWrapper) => {
|
|
3849
3929
|
sourceWrapper.active = false;
|
|
3850
3930
|
});
|
|
3851
3931
|
nextFrameInputs.forEach((inputData, index) => {
|
|
3852
|
-
this[PRIVATE$
|
|
3853
|
-
const inputSource = this[PRIVATE$
|
|
3854
|
-
const schema = this[PRIVATE$
|
|
3932
|
+
this[PRIVATE$3].inputSources.get(index).active = true;
|
|
3933
|
+
const inputSource = this[PRIVATE$3].inputSources.get(index).source;
|
|
3934
|
+
const schema = this[PRIVATE$3].inputSchemas.get(index);
|
|
3855
3935
|
this.updateInputSource(inputSource, schema, lastFrameInputs.has(index) ? lastFrameInputs.get(index) : inputData, inputData, alpha);
|
|
3856
3936
|
});
|
|
3857
3937
|
}
|
|
@@ -3876,16 +3956,16 @@ class ActionPlayer {
|
|
|
3876
3956
|
const gamepad = inputSource.gamepad;
|
|
3877
3957
|
nextInputData.buttons.forEach((states, index) => {
|
|
3878
3958
|
const gamepadButton = gamepad.buttons[index];
|
|
3879
|
-
gamepadButton[PRIVATE$
|
|
3880
|
-
gamepadButton[PRIVATE$
|
|
3959
|
+
gamepadButton[PRIVATE$k].pressed = states[0] === 1 ? true : false;
|
|
3960
|
+
gamepadButton[PRIVATE$k].touched = states[1] === 1 ? true : false;
|
|
3881
3961
|
const lastValue = lastInputData.buttons[index][2];
|
|
3882
3962
|
const nextValue = states[2];
|
|
3883
|
-
gamepadButton[PRIVATE$
|
|
3963
|
+
gamepadButton[PRIVATE$k].value =
|
|
3884
3964
|
(nextValue - lastValue) * alpha + lastValue;
|
|
3885
3965
|
});
|
|
3886
3966
|
nextInputData.axes.forEach((nextValue, index) => {
|
|
3887
3967
|
const lastValue = lastInputData.axes[index];
|
|
3888
|
-
gamepad[PRIVATE$
|
|
3968
|
+
gamepad[PRIVATE$k].axesMap[index.toString()].x =
|
|
3889
3969
|
(nextValue - lastValue) * alpha + lastValue;
|
|
3890
3970
|
});
|
|
3891
3971
|
}
|
|
@@ -3895,13 +3975,13 @@ class ActionPlayer {
|
|
|
3895
3975
|
const f1q = fromValues(lastTransform[3], lastTransform[4], lastTransform[5], lastTransform[6]);
|
|
3896
3976
|
const f2p = fromValues$2(nextTransform[0], nextTransform[1], nextTransform[2]);
|
|
3897
3977
|
const f2q = fromValues(nextTransform[3], nextTransform[4], nextTransform[5], nextTransform[6]);
|
|
3898
|
-
lerp(this[PRIVATE$
|
|
3899
|
-
slerp(this[PRIVATE$
|
|
3900
|
-
fromRotationTranslation(space[PRIVATE$
|
|
3978
|
+
lerp(this[PRIVATE$3].vec3, f1p, f2p, alpha);
|
|
3979
|
+
slerp(this[PRIVATE$3].quat, f1q, f2q, alpha);
|
|
3980
|
+
fromRotationTranslation(space[PRIVATE$l].offsetMatrix, this[PRIVATE$3].quat, this[PRIVATE$3].vec3);
|
|
3901
3981
|
}
|
|
3902
3982
|
processRawInputData(inputDataRaw) {
|
|
3903
3983
|
const index = inputDataRaw[0];
|
|
3904
|
-
const schema = this[PRIVATE$
|
|
3984
|
+
const schema = this[PRIVATE$3].inputSchemas.get(index);
|
|
3905
3985
|
const targetRayTransform = inputDataRaw.slice(1, 8);
|
|
3906
3986
|
const inputData = { targetRayTransform };
|
|
3907
3987
|
let dataCounter = 8;
|
|
@@ -3920,7 +4000,7 @@ class ActionPlayer {
|
|
|
3920
4000
|
}
|
|
3921
4001
|
}
|
|
3922
4002
|
|
|
3923
|
-
const VERSION = "1.0.
|
|
4003
|
+
const VERSION = "1.0.2";
|
|
3924
4004
|
|
|
3925
4005
|
/**
|
|
3926
4006
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -3939,75 +4019,6 @@ class XRReferenceSpaceEvent extends Event {
|
|
|
3939
4019
|
}
|
|
3940
4020
|
}
|
|
3941
4021
|
|
|
3942
|
-
/**
|
|
3943
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3944
|
-
*
|
|
3945
|
-
* This source code is licensed under the MIT license found in the
|
|
3946
|
-
* LICENSE file in the root directory of this source tree.
|
|
3947
|
-
*/
|
|
3948
|
-
const PRIVATE$3 = Symbol('@immersive-web-emulation-runtime/xr-system');
|
|
3949
|
-
class XRSystem extends EventTarget {
|
|
3950
|
-
constructor(device) {
|
|
3951
|
-
super();
|
|
3952
|
-
this[PRIVATE$3] = { device };
|
|
3953
|
-
// Initialize device change monitoring here if applicable
|
|
3954
|
-
}
|
|
3955
|
-
isSessionSupported(mode) {
|
|
3956
|
-
return new Promise((resolve, _reject) => {
|
|
3957
|
-
if (mode === XRSessionMode.Inline) {
|
|
3958
|
-
resolve(true);
|
|
3959
|
-
}
|
|
3960
|
-
else {
|
|
3961
|
-
// Check for spatial tracking permission if necessary
|
|
3962
|
-
resolve(this[PRIVATE$3].device.supportedSessionModes.includes(mode));
|
|
3963
|
-
}
|
|
3964
|
-
});
|
|
3965
|
-
}
|
|
3966
|
-
requestSession(mode, options = {}) {
|
|
3967
|
-
return new Promise((resolve, reject) => {
|
|
3968
|
-
this.isSessionSupported(mode)
|
|
3969
|
-
.then((isSupported) => {
|
|
3970
|
-
if (!isSupported) {
|
|
3971
|
-
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
3972
|
-
return;
|
|
3973
|
-
}
|
|
3974
|
-
// Check for active sessions and other constraints here
|
|
3975
|
-
if (this[PRIVATE$3].activeSession) {
|
|
3976
|
-
reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
|
|
3977
|
-
return;
|
|
3978
|
-
}
|
|
3979
|
-
// Handle required and optional features
|
|
3980
|
-
const { requiredFeatures = [], optionalFeatures = [] } = options;
|
|
3981
|
-
const { supportedFeatures } = this[PRIVATE$3].device;
|
|
3982
|
-
// Check if all required features are supported
|
|
3983
|
-
const allRequiredSupported = requiredFeatures.every((feature) => supportedFeatures.includes(feature));
|
|
3984
|
-
if (!allRequiredSupported) {
|
|
3985
|
-
reject(new Error('One or more required features are not supported by the device.'));
|
|
3986
|
-
return;
|
|
3987
|
-
}
|
|
3988
|
-
// Filter out unsupported optional features
|
|
3989
|
-
const supportedOptionalFeatures = optionalFeatures.filter((feature) => supportedFeatures.includes(feature));
|
|
3990
|
-
// Combine required and supported optional features into enabled features
|
|
3991
|
-
const enabledFeatures = Array.from(new Set([
|
|
3992
|
-
...requiredFeatures,
|
|
3993
|
-
...supportedOptionalFeatures,
|
|
3994
|
-
WebXRFeatures.Viewer,
|
|
3995
|
-
WebXRFeatures.Local,
|
|
3996
|
-
]));
|
|
3997
|
-
// Proceed with session creation
|
|
3998
|
-
const session = new XRSession(this[PRIVATE$3].device, mode, enabledFeatures);
|
|
3999
|
-
this[PRIVATE$3].activeSession = session;
|
|
4000
|
-
// Listen for session end to clear the active session
|
|
4001
|
-
session.addEventListener('end', () => {
|
|
4002
|
-
this[PRIVATE$3].activeSession = undefined;
|
|
4003
|
-
});
|
|
4004
|
-
resolve(session);
|
|
4005
|
-
})
|
|
4006
|
-
.catch(reject);
|
|
4007
|
-
});
|
|
4008
|
-
}
|
|
4009
|
-
}
|
|
4010
|
-
|
|
4011
4022
|
/**
|
|
4012
4023
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4013
4024
|
*
|
|
@@ -4120,6 +4131,7 @@ class XRDevice {
|
|
|
4120
4131
|
pendingReferenceSpaceReset: false,
|
|
4121
4132
|
visibilityState: XRVisibilityState.Visible,
|
|
4122
4133
|
pendingVisibilityState: null,
|
|
4134
|
+
xrSystem: null,
|
|
4123
4135
|
matrix: create$3(),
|
|
4124
4136
|
globalSpace,
|
|
4125
4137
|
viewerSpace,
|
|
@@ -4140,10 +4152,10 @@ class XRDevice {
|
|
|
4140
4152
|
updateViews: () => {
|
|
4141
4153
|
// update viewerSpace
|
|
4142
4154
|
const viewerSpace = this[PRIVATE$1].viewerSpace;
|
|
4143
|
-
fromRotationTranslation(viewerSpace[PRIVATE$
|
|
4155
|
+
fromRotationTranslation(viewerSpace[PRIVATE$l].offsetMatrix, this[PRIVATE$1].quaternion.quat, this[PRIVATE$1].position.vec3);
|
|
4144
4156
|
// update viewSpaces
|
|
4145
|
-
fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Left][PRIVATE$
|
|
4146
|
-
fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Right][PRIVATE$
|
|
4157
|
+
fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Left][PRIVATE$l].offsetMatrix, fromValues$2(-this[PRIVATE$1].ipd / 2, 0, 0));
|
|
4158
|
+
fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Right][PRIVATE$l].offsetMatrix, fromValues$2(this[PRIVATE$1].ipd / 2, 0, 0));
|
|
4147
4159
|
},
|
|
4148
4160
|
onBaseLayerSet: (baseLayer) => {
|
|
4149
4161
|
if (!baseLayer)
|
|
@@ -4225,8 +4237,9 @@ class XRDevice {
|
|
|
4225
4237
|
},
|
|
4226
4238
|
configurable: true,
|
|
4227
4239
|
});
|
|
4240
|
+
this[PRIVATE$1].xrSystem = new XRSystem(this);
|
|
4228
4241
|
Object.defineProperty(globalThis.navigator, 'xr', {
|
|
4229
|
-
value:
|
|
4242
|
+
value: this[PRIVATE$1].xrSystem,
|
|
4230
4243
|
configurable: true,
|
|
4231
4244
|
});
|
|
4232
4245
|
Object.defineProperty(navigator, 'userAgent', {
|
|
@@ -4352,6 +4365,10 @@ class XRDevice {
|
|
|
4352
4365
|
get canvasContainer() {
|
|
4353
4366
|
return this[PRIVATE$1].canvasContainer;
|
|
4354
4367
|
}
|
|
4368
|
+
get activeSession() {
|
|
4369
|
+
var _a;
|
|
4370
|
+
return (_a = this[PRIVATE$1].xrSystem) === null || _a === void 0 ? void 0 : _a[PRIVATE$4].activeSession;
|
|
4371
|
+
}
|
|
4355
4372
|
recenter() {
|
|
4356
4373
|
const deltaVec = new Vector3(-this.position.x, 0, -this.position.z);
|
|
4357
4374
|
const forward = new Vector3(0, 0, -1).applyQuaternion(this.quaternion);
|