iwer 1.1.0 → 2.0.0
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 +150 -32
- package/build/iwer.min.js +1 -1
- package/build/iwer.module.js +150 -32
- package/build/iwer.module.min.js +1 -1
- package/lib/device/XRController.d.ts +2 -0
- package/lib/device/XRController.d.ts.map +1 -1
- package/lib/device/XRController.js +4 -0
- package/lib/device/XRController.js.map +1 -1
- package/lib/device/XRDevice.d.ts +32 -2
- package/lib/device/XRDevice.d.ts.map +1 -1
- package/lib/device/XRDevice.js +65 -3
- package/lib/device/XRDevice.js.map +1 -1
- package/lib/initialization/XRSystem.d.ts +10 -0
- package/lib/initialization/XRSystem.d.ts.map +1 -1
- package/lib/initialization/XRSystem.js +51 -22
- package/lib/initialization/XRSystem.js.map +1 -1
- package/lib/session/XRSession.d.ts.map +1 -1
- package/lib/session/XRSession.js +29 -6
- package/lib/session/XRSession.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.js
CHANGED
|
@@ -1910,12 +1910,16 @@
|
|
|
1910
1910
|
const inputSource = new XRInputSource(handedness, XRTargetRayMode.TrackedPointer, profiles, targetRaySpace, new Gamepad(controllerConfig.layout[handedness].gamepad), gripSpace);
|
|
1911
1911
|
super(inputSource);
|
|
1912
1912
|
this[P_CONTROLLER] = {
|
|
1913
|
+
profileId: controllerConfig.profileId,
|
|
1913
1914
|
gamepadConfig: controllerConfig.layout[handedness].gamepad,
|
|
1914
1915
|
};
|
|
1915
1916
|
}
|
|
1916
1917
|
get gamepadConfig() {
|
|
1917
1918
|
return this[P_CONTROLLER].gamepadConfig;
|
|
1918
1919
|
}
|
|
1920
|
+
get profileId() {
|
|
1921
|
+
return this[P_CONTROLLER].profileId;
|
|
1922
|
+
}
|
|
1919
1923
|
updateButtonValue(id, value) {
|
|
1920
1924
|
if (value > 1 || value < 0) {
|
|
1921
1925
|
console.warn(`Out-of-range value ${value} provided for button ${id}.`);
|
|
@@ -2920,6 +2924,17 @@
|
|
|
2920
2924
|
perspective(this[P_SESSION].projectionMatrices[XREye.None], this[P_SESSION].renderState.inlineVerticalFieldOfView, aspect, depthNear, depthFar);
|
|
2921
2925
|
}
|
|
2922
2926
|
const frame = new XRFrame(this, this[P_SESSION].frameHandle, true, true, performance.now());
|
|
2927
|
+
const time = performance.now();
|
|
2928
|
+
const devui = this[P_SESSION].device[P_DEVICE].devui;
|
|
2929
|
+
if (devui) {
|
|
2930
|
+
devui.render(time);
|
|
2931
|
+
}
|
|
2932
|
+
if (this[P_SESSION].mode === 'immersive-ar') {
|
|
2933
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
2934
|
+
if (sem) {
|
|
2935
|
+
sem.render(time);
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2923
2938
|
if (this[P_SESSION].enabledFeatures.includes('anchors')) {
|
|
2924
2939
|
this[P_SESSION].updateTrackedAnchors();
|
|
2925
2940
|
}
|
|
@@ -3008,15 +3023,21 @@
|
|
|
3008
3023
|
},
|
|
3009
3024
|
trackedPlanes: new Map(),
|
|
3010
3025
|
updateTrackedPlanes: (frame) => {
|
|
3011
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3026
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3012
3027
|
if (!sem) {
|
|
3013
3028
|
return;
|
|
3014
3029
|
}
|
|
3030
|
+
const trackedPlanes = Array.from(this[P_SESSION].trackedPlanes.keys());
|
|
3031
|
+
trackedPlanes.forEach((plane) => {
|
|
3032
|
+
if (!sem.trackedPlanes.has(plane)) {
|
|
3033
|
+
this[P_SESSION].trackedPlanes.delete(plane);
|
|
3034
|
+
}
|
|
3035
|
+
});
|
|
3015
3036
|
sem.trackedPlanes.forEach((plane) => {
|
|
3016
3037
|
let xrPlane = this[P_SESSION].trackedPlanes.get(plane);
|
|
3017
3038
|
if (!xrPlane) {
|
|
3018
3039
|
const planeSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, plane.transform.matrix);
|
|
3019
|
-
xrPlane = new XRPlane(plane, planeSpace, plane.polygon);
|
|
3040
|
+
xrPlane = new XRPlane(plane, planeSpace, plane.polygon, plane.semanticLabel);
|
|
3020
3041
|
this[P_SESSION].trackedPlanes.set(plane, xrPlane);
|
|
3021
3042
|
}
|
|
3022
3043
|
xrPlane[P_PLANE].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3026,15 +3047,21 @@
|
|
|
3026
3047
|
},
|
|
3027
3048
|
trackedMeshes: new Map(),
|
|
3028
3049
|
updateTrackedMeshes: (frame) => {
|
|
3029
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3050
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3030
3051
|
if (!sem) {
|
|
3031
3052
|
return;
|
|
3032
3053
|
}
|
|
3054
|
+
const trackedMeshes = Array.from(this[P_SESSION].trackedMeshes.keys());
|
|
3055
|
+
trackedMeshes.forEach((mesh) => {
|
|
3056
|
+
if (!sem.trackedMeshes.has(mesh)) {
|
|
3057
|
+
this[P_SESSION].trackedMeshes.delete(mesh);
|
|
3058
|
+
}
|
|
3059
|
+
});
|
|
3033
3060
|
sem.trackedMeshes.forEach((mesh) => {
|
|
3034
3061
|
let xrMesh = this[P_SESSION].trackedMeshes.get(mesh);
|
|
3035
3062
|
if (!xrMesh) {
|
|
3036
3063
|
const meshSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, mesh.transform.matrix);
|
|
3037
|
-
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices);
|
|
3064
|
+
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices, mesh.semanticLabel);
|
|
3038
3065
|
this[P_SESSION].trackedMeshes.set(mesh, xrMesh);
|
|
3039
3066
|
}
|
|
3040
3067
|
xrMesh[P_MESH].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3044,7 +3071,7 @@
|
|
|
3044
3071
|
},
|
|
3045
3072
|
hitTestSources: new Set(),
|
|
3046
3073
|
computeHitTestResults: (frame) => {
|
|
3047
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3074
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3048
3075
|
if (!sem)
|
|
3049
3076
|
return;
|
|
3050
3077
|
const globalSpace = this[P_SESSION].device[P_DEVICE].globalSpace;
|
|
@@ -3278,7 +3305,7 @@
|
|
|
3278
3305
|
else if (this[P_SESSION].ended) {
|
|
3279
3306
|
reject(new DOMException('XRSession has already ended.', 'InvalidStateError'));
|
|
3280
3307
|
}
|
|
3281
|
-
else if (!this[P_SESSION].device[P_DEVICE].
|
|
3308
|
+
else if (!this[P_SESSION].device[P_DEVICE].sem) {
|
|
3282
3309
|
reject(new DOMException('Synthethic Environment Module required for emulating hit-test', 'OperationError'));
|
|
3283
3310
|
}
|
|
3284
3311
|
else {
|
|
@@ -4593,7 +4620,7 @@
|
|
|
4593
4620
|
}
|
|
4594
4621
|
}
|
|
4595
4622
|
|
|
4596
|
-
const VERSION = "
|
|
4623
|
+
const VERSION = "2.0.0";
|
|
4597
4624
|
|
|
4598
4625
|
/**
|
|
4599
4626
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -4621,28 +4648,9 @@
|
|
|
4621
4648
|
class XRSystem extends EventTarget {
|
|
4622
4649
|
constructor(device) {
|
|
4623
4650
|
super();
|
|
4624
|
-
this[P_SYSTEM] = {
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
isSessionSupported(mode) {
|
|
4628
|
-
return new Promise((resolve, _reject) => {
|
|
4629
|
-
if (mode === 'inline') {
|
|
4630
|
-
resolve(true);
|
|
4631
|
-
}
|
|
4632
|
-
else {
|
|
4633
|
-
// Check for spatial tracking permission if necessary
|
|
4634
|
-
resolve(this[P_SYSTEM].device.supportedSessionModes.includes(mode));
|
|
4635
|
-
}
|
|
4636
|
-
});
|
|
4637
|
-
}
|
|
4638
|
-
requestSession(mode, options = {}) {
|
|
4639
|
-
return new Promise((resolve, reject) => {
|
|
4640
|
-
this.isSessionSupported(mode)
|
|
4641
|
-
.then((isSupported) => {
|
|
4642
|
-
if (!isSupported) {
|
|
4643
|
-
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4644
|
-
return;
|
|
4645
|
-
}
|
|
4651
|
+
this[P_SYSTEM] = {
|
|
4652
|
+
device,
|
|
4653
|
+
grantSession: ({ resolve, reject, mode, options }) => {
|
|
4646
4654
|
// Check for active sessions and other constraints here
|
|
4647
4655
|
if (this[P_SYSTEM].activeSession) {
|
|
4648
4656
|
reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
|
|
@@ -4674,6 +4682,54 @@
|
|
|
4674
4682
|
this[P_SYSTEM].activeSession = undefined;
|
|
4675
4683
|
});
|
|
4676
4684
|
resolve(session);
|
|
4685
|
+
},
|
|
4686
|
+
};
|
|
4687
|
+
// Initialize device change monitoring here if applicable
|
|
4688
|
+
}
|
|
4689
|
+
isSessionSupported(mode) {
|
|
4690
|
+
return new Promise((resolve, _reject) => {
|
|
4691
|
+
if (mode === 'inline') {
|
|
4692
|
+
resolve(true);
|
|
4693
|
+
}
|
|
4694
|
+
else {
|
|
4695
|
+
// Check for spatial tracking permission if necessary
|
|
4696
|
+
resolve(this[P_SYSTEM].device.supportedSessionModes.includes(mode));
|
|
4697
|
+
}
|
|
4698
|
+
});
|
|
4699
|
+
}
|
|
4700
|
+
requestSession(mode, options = {}) {
|
|
4701
|
+
return new Promise((resolve, reject) => {
|
|
4702
|
+
this.isSessionSupported(mode)
|
|
4703
|
+
.then((isSupported) => {
|
|
4704
|
+
if (!isSupported) {
|
|
4705
|
+
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4706
|
+
return;
|
|
4707
|
+
}
|
|
4708
|
+
const sessionGrantConfig = {
|
|
4709
|
+
resolve,
|
|
4710
|
+
reject,
|
|
4711
|
+
mode,
|
|
4712
|
+
options,
|
|
4713
|
+
};
|
|
4714
|
+
this[P_SYSTEM].grantSession(sessionGrantConfig);
|
|
4715
|
+
})
|
|
4716
|
+
.catch(reject);
|
|
4717
|
+
});
|
|
4718
|
+
}
|
|
4719
|
+
offerSession(mode, options = {}) {
|
|
4720
|
+
return new Promise((resolve, reject) => {
|
|
4721
|
+
this.isSessionSupported(mode)
|
|
4722
|
+
.then((isSupported) => {
|
|
4723
|
+
if (!isSupported) {
|
|
4724
|
+
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4725
|
+
return;
|
|
4726
|
+
}
|
|
4727
|
+
this[P_SYSTEM].offeredSessionConfig = {
|
|
4728
|
+
resolve,
|
|
4729
|
+
reject,
|
|
4730
|
+
mode,
|
|
4731
|
+
options,
|
|
4732
|
+
};
|
|
4677
4733
|
})
|
|
4678
4734
|
.catch(reject);
|
|
4679
4735
|
});
|
|
@@ -4717,6 +4773,10 @@
|
|
|
4717
4773
|
headsetQuaternion: new Quaternion(),
|
|
4718
4774
|
stereoEnabled: false,
|
|
4719
4775
|
};
|
|
4776
|
+
const Z_INDEX_SEM_CANVAS = 1;
|
|
4777
|
+
const Z_INDEX_APP_CANVAS = 2;
|
|
4778
|
+
const Z_INDEX_DEVUI_CANVAS = 3;
|
|
4779
|
+
const Z_INDEX_DEVUI_CONTAINER = 4;
|
|
4720
4780
|
/**
|
|
4721
4781
|
* XRDevice is not a standard API class outlined in the WebXR Device API Specifications
|
|
4722
4782
|
* Instead, it serves as an user-facing interface to control the emulated XR Device
|
|
@@ -4724,6 +4784,7 @@
|
|
|
4724
4784
|
class XRDevice {
|
|
4725
4785
|
constructor(deviceConfig, deviceOptions = {}) {
|
|
4726
4786
|
var _a, _b, _c, _d, _e, _f;
|
|
4787
|
+
this.version = VERSION;
|
|
4727
4788
|
const globalSpace = new GlobalSpace();
|
|
4728
4789
|
const viewerSpace = new XRReferenceSpace(XRReferenceSpaceType.Viewer, globalSpace);
|
|
4729
4790
|
const viewSpaces = {
|
|
@@ -4809,12 +4870,27 @@
|
|
|
4809
4870
|
// backup canvas data
|
|
4810
4871
|
const canvas = baseLayer.context.canvas;
|
|
4811
4872
|
if (canvas.parentElement !== this[P_DEVICE].canvasContainer) {
|
|
4873
|
+
const devui = this[P_DEVICE].devui;
|
|
4874
|
+
if (devui) {
|
|
4875
|
+
const { devUICanvas, devUIContainer } = devui;
|
|
4876
|
+
devUICanvas.style.zIndex = Z_INDEX_DEVUI_CANVAS.toString();
|
|
4877
|
+
devUIContainer.style.zIndex = Z_INDEX_DEVUI_CONTAINER.toString();
|
|
4878
|
+
this[P_DEVICE].canvasContainer.appendChild(devui.devUICanvas);
|
|
4879
|
+
this[P_DEVICE].canvasContainer.appendChild(devui.devUIContainer);
|
|
4880
|
+
}
|
|
4881
|
+
const sem = this[P_DEVICE].sem;
|
|
4882
|
+
if (sem) {
|
|
4883
|
+
sem.environmentCanvas.style.zIndex = Z_INDEX_SEM_CANVAS.toString();
|
|
4884
|
+
this[P_DEVICE].canvasContainer.appendChild(sem.environmentCanvas);
|
|
4885
|
+
}
|
|
4812
4886
|
this[P_DEVICE].canvasData = {
|
|
4813
4887
|
canvas,
|
|
4814
4888
|
parent: canvas.parentElement,
|
|
4815
4889
|
width: canvas.width,
|
|
4816
4890
|
height: canvas.height,
|
|
4891
|
+
zIndex: canvas.style.zIndex,
|
|
4817
4892
|
};
|
|
4893
|
+
canvas.style.zIndex = Z_INDEX_APP_CANVAS.toString();
|
|
4818
4894
|
this[P_DEVICE].canvasContainer.appendChild(canvas);
|
|
4819
4895
|
document.body.appendChild(this[P_DEVICE].canvasContainer);
|
|
4820
4896
|
}
|
|
@@ -4823,16 +4899,27 @@
|
|
|
4823
4899
|
},
|
|
4824
4900
|
onSessionEnd: () => {
|
|
4825
4901
|
if (this[P_DEVICE].canvasData) {
|
|
4826
|
-
const { canvas, parent, width, height } = this[P_DEVICE].canvasData;
|
|
4902
|
+
const { canvas, parent, width, height, zIndex } = this[P_DEVICE].canvasData;
|
|
4827
4903
|
canvas.width = width;
|
|
4828
4904
|
canvas.height = height;
|
|
4905
|
+
canvas.style.zIndex = zIndex;
|
|
4829
4906
|
if (parent) {
|
|
4830
4907
|
parent.appendChild(canvas);
|
|
4831
4908
|
}
|
|
4832
4909
|
else {
|
|
4833
4910
|
this[P_DEVICE].canvasContainer.removeChild(canvas);
|
|
4834
4911
|
}
|
|
4912
|
+
const devui = this[P_DEVICE].devui;
|
|
4913
|
+
if (devui) {
|
|
4914
|
+
this[P_DEVICE].canvasContainer.removeChild(devui.devUICanvas);
|
|
4915
|
+
this[P_DEVICE].canvasContainer.removeChild(devui.devUIContainer);
|
|
4916
|
+
}
|
|
4917
|
+
const sem = this[P_DEVICE].sem;
|
|
4918
|
+
if (sem) {
|
|
4919
|
+
this[P_DEVICE].canvasContainer.removeChild(sem.environmentCanvas);
|
|
4920
|
+
}
|
|
4835
4921
|
document.body.removeChild(this[P_DEVICE].canvasContainer);
|
|
4922
|
+
this[P_DEVICE].canvasData = undefined;
|
|
4836
4923
|
window.dispatchEvent(new Event('resize'));
|
|
4837
4924
|
}
|
|
4838
4925
|
},
|
|
@@ -4917,8 +5004,11 @@
|
|
|
4917
5004
|
globalObject['XRInputSourcesChangeEvent'] = XRInputSourcesChangeEvent;
|
|
4918
5005
|
globalObject['XRReferenceSpaceEvent'] = XRReferenceSpaceEvent;
|
|
4919
5006
|
}
|
|
4920
|
-
|
|
4921
|
-
this[P_DEVICE].
|
|
5007
|
+
installDevUI(devUIConstructor) {
|
|
5008
|
+
this[P_DEVICE].devui = new devUIConstructor(this);
|
|
5009
|
+
}
|
|
5010
|
+
installSEM(semConstructor) {
|
|
5011
|
+
this[P_DEVICE].sem = new semConstructor(this);
|
|
4922
5012
|
}
|
|
4923
5013
|
get supportedSessionModes() {
|
|
4924
5014
|
return this[P_DEVICE].supportedSessionModes;
|
|
@@ -5014,10 +5104,32 @@
|
|
|
5014
5104
|
get canvasContainer() {
|
|
5015
5105
|
return this[P_DEVICE].canvasContainer;
|
|
5016
5106
|
}
|
|
5107
|
+
get canvasDimensions() {
|
|
5108
|
+
if (this[P_DEVICE].canvasData) {
|
|
5109
|
+
const { width, height } = this[P_DEVICE].canvasData.canvas;
|
|
5110
|
+
return { width, height };
|
|
5111
|
+
}
|
|
5112
|
+
return;
|
|
5113
|
+
}
|
|
5017
5114
|
get activeSession() {
|
|
5018
5115
|
var _a;
|
|
5019
5116
|
return (_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM].activeSession;
|
|
5020
5117
|
}
|
|
5118
|
+
get sessionOffered() {
|
|
5119
|
+
var _a;
|
|
5120
|
+
return Boolean((_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM].offeredSessionConfig);
|
|
5121
|
+
}
|
|
5122
|
+
get name() {
|
|
5123
|
+
return this[P_DEVICE].name;
|
|
5124
|
+
}
|
|
5125
|
+
grantOfferedSession() {
|
|
5126
|
+
var _a;
|
|
5127
|
+
const pSystem = (_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM];
|
|
5128
|
+
if (pSystem && pSystem.offeredSessionConfig) {
|
|
5129
|
+
pSystem.grantSession(pSystem.offeredSessionConfig);
|
|
5130
|
+
pSystem.offeredSessionConfig = undefined;
|
|
5131
|
+
}
|
|
5132
|
+
}
|
|
5021
5133
|
recenter() {
|
|
5022
5134
|
const deltaVec = new Vector3(-this.position.x, 0, -this.position.z);
|
|
5023
5135
|
const forward = new Vector3(0, 0, -1).applyQuaternion(this.quaternion);
|
|
@@ -5053,6 +5165,12 @@
|
|
|
5053
5165
|
this[P_DEVICE].actionPlayer = new ActionPlayer(refSpace, recording, this[P_DEVICE].ipd);
|
|
5054
5166
|
return this[P_DEVICE].actionPlayer;
|
|
5055
5167
|
}
|
|
5168
|
+
get devui() {
|
|
5169
|
+
return this[P_DEVICE].devui;
|
|
5170
|
+
}
|
|
5171
|
+
get sem() {
|
|
5172
|
+
return this[P_DEVICE].sem;
|
|
5173
|
+
}
|
|
5056
5174
|
}
|
|
5057
5175
|
|
|
5058
5176
|
/**
|