iwer 1.1.1 → 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 +119 -38
- package/build/iwer.min.js +1 -1
- package/build/iwer.module.js +119 -38
- 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 +25 -4
- package/lib/device/XRDevice.d.ts.map +1 -1
- package/lib/device/XRDevice.js +50 -7
- 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 +13 -8
- 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,10 +2924,15 @@
|
|
|
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
|
+
}
|
|
2923
2932
|
if (this[P_SESSION].mode === 'immersive-ar') {
|
|
2924
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
2933
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
2925
2934
|
if (sem) {
|
|
2926
|
-
sem.render(
|
|
2935
|
+
sem.render(time);
|
|
2927
2936
|
}
|
|
2928
2937
|
}
|
|
2929
2938
|
if (this[P_SESSION].enabledFeatures.includes('anchors')) {
|
|
@@ -3014,7 +3023,7 @@
|
|
|
3014
3023
|
},
|
|
3015
3024
|
trackedPlanes: new Map(),
|
|
3016
3025
|
updateTrackedPlanes: (frame) => {
|
|
3017
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3026
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3018
3027
|
if (!sem) {
|
|
3019
3028
|
return;
|
|
3020
3029
|
}
|
|
@@ -3028,7 +3037,7 @@
|
|
|
3028
3037
|
let xrPlane = this[P_SESSION].trackedPlanes.get(plane);
|
|
3029
3038
|
if (!xrPlane) {
|
|
3030
3039
|
const planeSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, plane.transform.matrix);
|
|
3031
|
-
xrPlane = new XRPlane(plane, planeSpace, plane.polygon);
|
|
3040
|
+
xrPlane = new XRPlane(plane, planeSpace, plane.polygon, plane.semanticLabel);
|
|
3032
3041
|
this[P_SESSION].trackedPlanes.set(plane, xrPlane);
|
|
3033
3042
|
}
|
|
3034
3043
|
xrPlane[P_PLANE].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3038,7 +3047,7 @@
|
|
|
3038
3047
|
},
|
|
3039
3048
|
trackedMeshes: new Map(),
|
|
3040
3049
|
updateTrackedMeshes: (frame) => {
|
|
3041
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3050
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3042
3051
|
if (!sem) {
|
|
3043
3052
|
return;
|
|
3044
3053
|
}
|
|
@@ -3052,7 +3061,7 @@
|
|
|
3052
3061
|
let xrMesh = this[P_SESSION].trackedMeshes.get(mesh);
|
|
3053
3062
|
if (!xrMesh) {
|
|
3054
3063
|
const meshSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, mesh.transform.matrix);
|
|
3055
|
-
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices);
|
|
3064
|
+
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices, mesh.semanticLabel);
|
|
3056
3065
|
this[P_SESSION].trackedMeshes.set(mesh, xrMesh);
|
|
3057
3066
|
}
|
|
3058
3067
|
xrMesh[P_MESH].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3062,7 +3071,7 @@
|
|
|
3062
3071
|
},
|
|
3063
3072
|
hitTestSources: new Set(),
|
|
3064
3073
|
computeHitTestResults: (frame) => {
|
|
3065
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3074
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3066
3075
|
if (!sem)
|
|
3067
3076
|
return;
|
|
3068
3077
|
const globalSpace = this[P_SESSION].device[P_DEVICE].globalSpace;
|
|
@@ -3296,7 +3305,7 @@
|
|
|
3296
3305
|
else if (this[P_SESSION].ended) {
|
|
3297
3306
|
reject(new DOMException('XRSession has already ended.', 'InvalidStateError'));
|
|
3298
3307
|
}
|
|
3299
|
-
else if (!this[P_SESSION].device[P_DEVICE].
|
|
3308
|
+
else if (!this[P_SESSION].device[P_DEVICE].sem) {
|
|
3300
3309
|
reject(new DOMException('Synthethic Environment Module required for emulating hit-test', 'OperationError'));
|
|
3301
3310
|
}
|
|
3302
3311
|
else {
|
|
@@ -4611,7 +4620,7 @@
|
|
|
4611
4620
|
}
|
|
4612
4621
|
}
|
|
4613
4622
|
|
|
4614
|
-
const VERSION = "
|
|
4623
|
+
const VERSION = "2.0.0";
|
|
4615
4624
|
|
|
4616
4625
|
/**
|
|
4617
4626
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -4639,28 +4648,9 @@
|
|
|
4639
4648
|
class XRSystem extends EventTarget {
|
|
4640
4649
|
constructor(device) {
|
|
4641
4650
|
super();
|
|
4642
|
-
this[P_SYSTEM] = {
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
isSessionSupported(mode) {
|
|
4646
|
-
return new Promise((resolve, _reject) => {
|
|
4647
|
-
if (mode === 'inline') {
|
|
4648
|
-
resolve(true);
|
|
4649
|
-
}
|
|
4650
|
-
else {
|
|
4651
|
-
// Check for spatial tracking permission if necessary
|
|
4652
|
-
resolve(this[P_SYSTEM].device.supportedSessionModes.includes(mode));
|
|
4653
|
-
}
|
|
4654
|
-
});
|
|
4655
|
-
}
|
|
4656
|
-
requestSession(mode, options = {}) {
|
|
4657
|
-
return new Promise((resolve, reject) => {
|
|
4658
|
-
this.isSessionSupported(mode)
|
|
4659
|
-
.then((isSupported) => {
|
|
4660
|
-
if (!isSupported) {
|
|
4661
|
-
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4662
|
-
return;
|
|
4663
|
-
}
|
|
4651
|
+
this[P_SYSTEM] = {
|
|
4652
|
+
device,
|
|
4653
|
+
grantSession: ({ resolve, reject, mode, options }) => {
|
|
4664
4654
|
// Check for active sessions and other constraints here
|
|
4665
4655
|
if (this[P_SYSTEM].activeSession) {
|
|
4666
4656
|
reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
|
|
@@ -4692,6 +4682,54 @@
|
|
|
4692
4682
|
this[P_SYSTEM].activeSession = undefined;
|
|
4693
4683
|
});
|
|
4694
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
|
+
};
|
|
4695
4733
|
})
|
|
4696
4734
|
.catch(reject);
|
|
4697
4735
|
});
|
|
@@ -4735,6 +4773,10 @@
|
|
|
4735
4773
|
headsetQuaternion: new Quaternion(),
|
|
4736
4774
|
stereoEnabled: false,
|
|
4737
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;
|
|
4738
4780
|
/**
|
|
4739
4781
|
* XRDevice is not a standard API class outlined in the WebXR Device API Specifications
|
|
4740
4782
|
* Instead, it serves as an user-facing interface to control the emulated XR Device
|
|
@@ -4742,6 +4784,7 @@
|
|
|
4742
4784
|
class XRDevice {
|
|
4743
4785
|
constructor(deviceConfig, deviceOptions = {}) {
|
|
4744
4786
|
var _a, _b, _c, _d, _e, _f;
|
|
4787
|
+
this.version = VERSION;
|
|
4745
4788
|
const globalSpace = new GlobalSpace();
|
|
4746
4789
|
const viewerSpace = new XRReferenceSpace(XRReferenceSpaceType.Viewer, globalSpace);
|
|
4747
4790
|
const viewSpaces = {
|
|
@@ -4827,8 +4870,17 @@
|
|
|
4827
4870
|
// backup canvas data
|
|
4828
4871
|
const canvas = baseLayer.context.canvas;
|
|
4829
4872
|
if (canvas.parentElement !== this[P_DEVICE].canvasContainer) {
|
|
4830
|
-
const
|
|
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;
|
|
4831
4882
|
if (sem) {
|
|
4883
|
+
sem.environmentCanvas.style.zIndex = Z_INDEX_SEM_CANVAS.toString();
|
|
4832
4884
|
this[P_DEVICE].canvasContainer.appendChild(sem.environmentCanvas);
|
|
4833
4885
|
}
|
|
4834
4886
|
this[P_DEVICE].canvasData = {
|
|
@@ -4836,7 +4888,9 @@
|
|
|
4836
4888
|
parent: canvas.parentElement,
|
|
4837
4889
|
width: canvas.width,
|
|
4838
4890
|
height: canvas.height,
|
|
4891
|
+
zIndex: canvas.style.zIndex,
|
|
4839
4892
|
};
|
|
4893
|
+
canvas.style.zIndex = Z_INDEX_APP_CANVAS.toString();
|
|
4840
4894
|
this[P_DEVICE].canvasContainer.appendChild(canvas);
|
|
4841
4895
|
document.body.appendChild(this[P_DEVICE].canvasContainer);
|
|
4842
4896
|
}
|
|
@@ -4845,16 +4899,22 @@
|
|
|
4845
4899
|
},
|
|
4846
4900
|
onSessionEnd: () => {
|
|
4847
4901
|
if (this[P_DEVICE].canvasData) {
|
|
4848
|
-
const { canvas, parent, width, height } = this[P_DEVICE].canvasData;
|
|
4902
|
+
const { canvas, parent, width, height, zIndex } = this[P_DEVICE].canvasData;
|
|
4849
4903
|
canvas.width = width;
|
|
4850
4904
|
canvas.height = height;
|
|
4905
|
+
canvas.style.zIndex = zIndex;
|
|
4851
4906
|
if (parent) {
|
|
4852
4907
|
parent.appendChild(canvas);
|
|
4853
4908
|
}
|
|
4854
4909
|
else {
|
|
4855
4910
|
this[P_DEVICE].canvasContainer.removeChild(canvas);
|
|
4856
4911
|
}
|
|
4857
|
-
const
|
|
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;
|
|
4858
4918
|
if (sem) {
|
|
4859
4919
|
this[P_DEVICE].canvasContainer.removeChild(sem.environmentCanvas);
|
|
4860
4920
|
}
|
|
@@ -4944,8 +5004,11 @@
|
|
|
4944
5004
|
globalObject['XRInputSourcesChangeEvent'] = XRInputSourcesChangeEvent;
|
|
4945
5005
|
globalObject['XRReferenceSpaceEvent'] = XRReferenceSpaceEvent;
|
|
4946
5006
|
}
|
|
4947
|
-
|
|
4948
|
-
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);
|
|
4949
5012
|
}
|
|
4950
5013
|
get supportedSessionModes() {
|
|
4951
5014
|
return this[P_DEVICE].supportedSessionModes;
|
|
@@ -5052,6 +5115,21 @@
|
|
|
5052
5115
|
var _a;
|
|
5053
5116
|
return (_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM].activeSession;
|
|
5054
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
|
+
}
|
|
5055
5133
|
recenter() {
|
|
5056
5134
|
const deltaVec = new Vector3(-this.position.x, 0, -this.position.z);
|
|
5057
5135
|
const forward = new Vector3(0, 0, -1).applyQuaternion(this.quaternion);
|
|
@@ -5087,8 +5165,11 @@
|
|
|
5087
5165
|
this[P_DEVICE].actionPlayer = new ActionPlayer(refSpace, recording, this[P_DEVICE].ipd);
|
|
5088
5166
|
return this[P_DEVICE].actionPlayer;
|
|
5089
5167
|
}
|
|
5090
|
-
get
|
|
5091
|
-
return this[P_DEVICE].
|
|
5168
|
+
get devui() {
|
|
5169
|
+
return this[P_DEVICE].devui;
|
|
5170
|
+
}
|
|
5171
|
+
get sem() {
|
|
5172
|
+
return this[P_DEVICE].sem;
|
|
5092
5173
|
}
|
|
5093
5174
|
}
|
|
5094
5175
|
|