iwer 1.1.1 → 2.0.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 +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 +26 -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.module.js
CHANGED
|
@@ -1904,12 +1904,16 @@ class XRController extends XRTrackedInput {
|
|
|
1904
1904
|
const inputSource = new XRInputSource(handedness, XRTargetRayMode.TrackedPointer, profiles, targetRaySpace, new Gamepad(controllerConfig.layout[handedness].gamepad), gripSpace);
|
|
1905
1905
|
super(inputSource);
|
|
1906
1906
|
this[P_CONTROLLER] = {
|
|
1907
|
+
profileId: controllerConfig.profileId,
|
|
1907
1908
|
gamepadConfig: controllerConfig.layout[handedness].gamepad,
|
|
1908
1909
|
};
|
|
1909
1910
|
}
|
|
1910
1911
|
get gamepadConfig() {
|
|
1911
1912
|
return this[P_CONTROLLER].gamepadConfig;
|
|
1912
1913
|
}
|
|
1914
|
+
get profileId() {
|
|
1915
|
+
return this[P_CONTROLLER].profileId;
|
|
1916
|
+
}
|
|
1913
1917
|
updateButtonValue(id, value) {
|
|
1914
1918
|
if (value > 1 || value < 0) {
|
|
1915
1919
|
console.warn(`Out-of-range value ${value} provided for button ${id}.`);
|
|
@@ -2914,10 +2918,15 @@ class XRSession extends EventTarget {
|
|
|
2914
2918
|
perspective(this[P_SESSION].projectionMatrices[XREye.None], this[P_SESSION].renderState.inlineVerticalFieldOfView, aspect, depthNear, depthFar);
|
|
2915
2919
|
}
|
|
2916
2920
|
const frame = new XRFrame(this, this[P_SESSION].frameHandle, true, true, performance.now());
|
|
2921
|
+
const time = performance.now();
|
|
2922
|
+
const devui = this[P_SESSION].device[P_DEVICE].devui;
|
|
2923
|
+
if (devui) {
|
|
2924
|
+
devui.render(time);
|
|
2925
|
+
}
|
|
2917
2926
|
if (this[P_SESSION].mode === 'immersive-ar') {
|
|
2918
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
2927
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
2919
2928
|
if (sem) {
|
|
2920
|
-
sem.render(
|
|
2929
|
+
sem.render(time);
|
|
2921
2930
|
}
|
|
2922
2931
|
}
|
|
2923
2932
|
if (this[P_SESSION].enabledFeatures.includes('anchors')) {
|
|
@@ -3008,7 +3017,7 @@ class XRSession extends EventTarget {
|
|
|
3008
3017
|
},
|
|
3009
3018
|
trackedPlanes: new Map(),
|
|
3010
3019
|
updateTrackedPlanes: (frame) => {
|
|
3011
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3020
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3012
3021
|
if (!sem) {
|
|
3013
3022
|
return;
|
|
3014
3023
|
}
|
|
@@ -3022,7 +3031,7 @@ class XRSession extends EventTarget {
|
|
|
3022
3031
|
let xrPlane = this[P_SESSION].trackedPlanes.get(plane);
|
|
3023
3032
|
if (!xrPlane) {
|
|
3024
3033
|
const planeSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, plane.transform.matrix);
|
|
3025
|
-
xrPlane = new XRPlane(plane, planeSpace, plane.polygon);
|
|
3034
|
+
xrPlane = new XRPlane(plane, planeSpace, plane.polygon, plane.semanticLabel);
|
|
3026
3035
|
this[P_SESSION].trackedPlanes.set(plane, xrPlane);
|
|
3027
3036
|
}
|
|
3028
3037
|
xrPlane[P_PLANE].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3032,7 +3041,7 @@ class XRSession extends EventTarget {
|
|
|
3032
3041
|
},
|
|
3033
3042
|
trackedMeshes: new Map(),
|
|
3034
3043
|
updateTrackedMeshes: (frame) => {
|
|
3035
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3044
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3036
3045
|
if (!sem) {
|
|
3037
3046
|
return;
|
|
3038
3047
|
}
|
|
@@ -3046,7 +3055,7 @@ class XRSession extends EventTarget {
|
|
|
3046
3055
|
let xrMesh = this[P_SESSION].trackedMeshes.get(mesh);
|
|
3047
3056
|
if (!xrMesh) {
|
|
3048
3057
|
const meshSpace = new XRSpace(this[P_SESSION].device[P_DEVICE].globalSpace, mesh.transform.matrix);
|
|
3049
|
-
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices);
|
|
3058
|
+
xrMesh = new XRMesh(mesh, meshSpace, mesh.vertices, mesh.indices, mesh.semanticLabel);
|
|
3050
3059
|
this[P_SESSION].trackedMeshes.set(mesh, xrMesh);
|
|
3051
3060
|
}
|
|
3052
3061
|
xrMesh[P_MESH].lastChangedTime = frame.predictedDisplayTime;
|
|
@@ -3056,7 +3065,7 @@ class XRSession extends EventTarget {
|
|
|
3056
3065
|
},
|
|
3057
3066
|
hitTestSources: new Set(),
|
|
3058
3067
|
computeHitTestResults: (frame) => {
|
|
3059
|
-
const sem = this[P_SESSION].device[P_DEVICE].
|
|
3068
|
+
const sem = this[P_SESSION].device[P_DEVICE].sem;
|
|
3060
3069
|
if (!sem)
|
|
3061
3070
|
return;
|
|
3062
3071
|
const globalSpace = this[P_SESSION].device[P_DEVICE].globalSpace;
|
|
@@ -3290,7 +3299,7 @@ class XRSession extends EventTarget {
|
|
|
3290
3299
|
else if (this[P_SESSION].ended) {
|
|
3291
3300
|
reject(new DOMException('XRSession has already ended.', 'InvalidStateError'));
|
|
3292
3301
|
}
|
|
3293
|
-
else if (!this[P_SESSION].device[P_DEVICE].
|
|
3302
|
+
else if (!this[P_SESSION].device[P_DEVICE].sem) {
|
|
3294
3303
|
reject(new DOMException('Synthethic Environment Module required for emulating hit-test', 'OperationError'));
|
|
3295
3304
|
}
|
|
3296
3305
|
else {
|
|
@@ -4605,7 +4614,7 @@ class ActionPlayer {
|
|
|
4605
4614
|
}
|
|
4606
4615
|
}
|
|
4607
4616
|
|
|
4608
|
-
const VERSION = "
|
|
4617
|
+
const VERSION = "2.0.1";
|
|
4609
4618
|
|
|
4610
4619
|
/**
|
|
4611
4620
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -4633,28 +4642,9 @@ class XRReferenceSpaceEvent extends Event {
|
|
|
4633
4642
|
class XRSystem extends EventTarget {
|
|
4634
4643
|
constructor(device) {
|
|
4635
4644
|
super();
|
|
4636
|
-
this[P_SYSTEM] = {
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
isSessionSupported(mode) {
|
|
4640
|
-
return new Promise((resolve, _reject) => {
|
|
4641
|
-
if (mode === 'inline') {
|
|
4642
|
-
resolve(true);
|
|
4643
|
-
}
|
|
4644
|
-
else {
|
|
4645
|
-
// Check for spatial tracking permission if necessary
|
|
4646
|
-
resolve(this[P_SYSTEM].device.supportedSessionModes.includes(mode));
|
|
4647
|
-
}
|
|
4648
|
-
});
|
|
4649
|
-
}
|
|
4650
|
-
requestSession(mode, options = {}) {
|
|
4651
|
-
return new Promise((resolve, reject) => {
|
|
4652
|
-
this.isSessionSupported(mode)
|
|
4653
|
-
.then((isSupported) => {
|
|
4654
|
-
if (!isSupported) {
|
|
4655
|
-
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4656
|
-
return;
|
|
4657
|
-
}
|
|
4645
|
+
this[P_SYSTEM] = {
|
|
4646
|
+
device,
|
|
4647
|
+
grantSession: ({ resolve, reject, mode, options }) => {
|
|
4658
4648
|
// Check for active sessions and other constraints here
|
|
4659
4649
|
if (this[P_SYSTEM].activeSession) {
|
|
4660
4650
|
reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
|
|
@@ -4686,6 +4676,54 @@ class XRSystem extends EventTarget {
|
|
|
4686
4676
|
this[P_SYSTEM].activeSession = undefined;
|
|
4687
4677
|
});
|
|
4688
4678
|
resolve(session);
|
|
4679
|
+
},
|
|
4680
|
+
};
|
|
4681
|
+
// Initialize device change monitoring here if applicable
|
|
4682
|
+
}
|
|
4683
|
+
isSessionSupported(mode) {
|
|
4684
|
+
return new Promise((resolve, _reject) => {
|
|
4685
|
+
if (mode === 'inline') {
|
|
4686
|
+
resolve(true);
|
|
4687
|
+
}
|
|
4688
|
+
else {
|
|
4689
|
+
// Check for spatial tracking permission if necessary
|
|
4690
|
+
resolve(this[P_SYSTEM].device.supportedSessionModes.includes(mode));
|
|
4691
|
+
}
|
|
4692
|
+
});
|
|
4693
|
+
}
|
|
4694
|
+
requestSession(mode, options = {}) {
|
|
4695
|
+
return new Promise((resolve, reject) => {
|
|
4696
|
+
this.isSessionSupported(mode)
|
|
4697
|
+
.then((isSupported) => {
|
|
4698
|
+
if (!isSupported) {
|
|
4699
|
+
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4700
|
+
return;
|
|
4701
|
+
}
|
|
4702
|
+
const sessionGrantConfig = {
|
|
4703
|
+
resolve,
|
|
4704
|
+
reject,
|
|
4705
|
+
mode,
|
|
4706
|
+
options,
|
|
4707
|
+
};
|
|
4708
|
+
this[P_SYSTEM].grantSession(sessionGrantConfig);
|
|
4709
|
+
})
|
|
4710
|
+
.catch(reject);
|
|
4711
|
+
});
|
|
4712
|
+
}
|
|
4713
|
+
offerSession(mode, options = {}) {
|
|
4714
|
+
return new Promise((resolve, reject) => {
|
|
4715
|
+
this.isSessionSupported(mode)
|
|
4716
|
+
.then((isSupported) => {
|
|
4717
|
+
if (!isSupported) {
|
|
4718
|
+
reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
|
|
4719
|
+
return;
|
|
4720
|
+
}
|
|
4721
|
+
this[P_SYSTEM].offeredSessionConfig = {
|
|
4722
|
+
resolve,
|
|
4723
|
+
reject,
|
|
4724
|
+
mode,
|
|
4725
|
+
options,
|
|
4726
|
+
};
|
|
4689
4727
|
})
|
|
4690
4728
|
.catch(reject);
|
|
4691
4729
|
});
|
|
@@ -4729,6 +4767,10 @@ const DEFAULTS = {
|
|
|
4729
4767
|
headsetQuaternion: new Quaternion(),
|
|
4730
4768
|
stereoEnabled: false,
|
|
4731
4769
|
};
|
|
4770
|
+
const Z_INDEX_SEM_CANVAS = 1;
|
|
4771
|
+
const Z_INDEX_APP_CANVAS = 2;
|
|
4772
|
+
const Z_INDEX_DEVUI_CANVAS = 3;
|
|
4773
|
+
const Z_INDEX_DEVUI_CONTAINER = 4;
|
|
4732
4774
|
/**
|
|
4733
4775
|
* XRDevice is not a standard API class outlined in the WebXR Device API Specifications
|
|
4734
4776
|
* Instead, it serves as an user-facing interface to control the emulated XR Device
|
|
@@ -4736,6 +4778,7 @@ const DEFAULTS = {
|
|
|
4736
4778
|
class XRDevice {
|
|
4737
4779
|
constructor(deviceConfig, deviceOptions = {}) {
|
|
4738
4780
|
var _a, _b, _c, _d, _e, _f;
|
|
4781
|
+
this.version = VERSION;
|
|
4739
4782
|
const globalSpace = new GlobalSpace();
|
|
4740
4783
|
const viewerSpace = new XRReferenceSpace(XRReferenceSpaceType.Viewer, globalSpace);
|
|
4741
4784
|
const viewSpaces = {
|
|
@@ -4821,8 +4864,17 @@ class XRDevice {
|
|
|
4821
4864
|
// backup canvas data
|
|
4822
4865
|
const canvas = baseLayer.context.canvas;
|
|
4823
4866
|
if (canvas.parentElement !== this[P_DEVICE].canvasContainer) {
|
|
4824
|
-
const
|
|
4867
|
+
const devui = this[P_DEVICE].devui;
|
|
4868
|
+
if (devui) {
|
|
4869
|
+
const { devUICanvas, devUIContainer } = devui;
|
|
4870
|
+
devUICanvas.style.zIndex = Z_INDEX_DEVUI_CANVAS.toString();
|
|
4871
|
+
devUIContainer.style.zIndex = Z_INDEX_DEVUI_CONTAINER.toString();
|
|
4872
|
+
this[P_DEVICE].canvasContainer.appendChild(devui.devUICanvas);
|
|
4873
|
+
this[P_DEVICE].canvasContainer.appendChild(devui.devUIContainer);
|
|
4874
|
+
}
|
|
4875
|
+
const sem = this[P_DEVICE].sem;
|
|
4825
4876
|
if (sem) {
|
|
4877
|
+
sem.environmentCanvas.style.zIndex = Z_INDEX_SEM_CANVAS.toString();
|
|
4826
4878
|
this[P_DEVICE].canvasContainer.appendChild(sem.environmentCanvas);
|
|
4827
4879
|
}
|
|
4828
4880
|
this[P_DEVICE].canvasData = {
|
|
@@ -4830,7 +4882,9 @@ class XRDevice {
|
|
|
4830
4882
|
parent: canvas.parentElement,
|
|
4831
4883
|
width: canvas.width,
|
|
4832
4884
|
height: canvas.height,
|
|
4885
|
+
zIndex: canvas.style.zIndex,
|
|
4833
4886
|
};
|
|
4887
|
+
canvas.style.zIndex = Z_INDEX_APP_CANVAS.toString();
|
|
4834
4888
|
this[P_DEVICE].canvasContainer.appendChild(canvas);
|
|
4835
4889
|
document.body.appendChild(this[P_DEVICE].canvasContainer);
|
|
4836
4890
|
}
|
|
@@ -4839,16 +4893,22 @@ class XRDevice {
|
|
|
4839
4893
|
},
|
|
4840
4894
|
onSessionEnd: () => {
|
|
4841
4895
|
if (this[P_DEVICE].canvasData) {
|
|
4842
|
-
const { canvas, parent, width, height } = this[P_DEVICE].canvasData;
|
|
4896
|
+
const { canvas, parent, width, height, zIndex } = this[P_DEVICE].canvasData;
|
|
4843
4897
|
canvas.width = width;
|
|
4844
4898
|
canvas.height = height;
|
|
4899
|
+
canvas.style.zIndex = zIndex;
|
|
4845
4900
|
if (parent) {
|
|
4846
4901
|
parent.appendChild(canvas);
|
|
4847
4902
|
}
|
|
4848
4903
|
else {
|
|
4849
4904
|
this[P_DEVICE].canvasContainer.removeChild(canvas);
|
|
4850
4905
|
}
|
|
4851
|
-
const
|
|
4906
|
+
const devui = this[P_DEVICE].devui;
|
|
4907
|
+
if (devui) {
|
|
4908
|
+
this[P_DEVICE].canvasContainer.removeChild(devui.devUICanvas);
|
|
4909
|
+
this[P_DEVICE].canvasContainer.removeChild(devui.devUIContainer);
|
|
4910
|
+
}
|
|
4911
|
+
const sem = this[P_DEVICE].sem;
|
|
4852
4912
|
if (sem) {
|
|
4853
4913
|
this[P_DEVICE].canvasContainer.removeChild(sem.environmentCanvas);
|
|
4854
4914
|
}
|
|
@@ -4938,8 +4998,11 @@ class XRDevice {
|
|
|
4938
4998
|
globalObject['XRInputSourcesChangeEvent'] = XRInputSourcesChangeEvent;
|
|
4939
4999
|
globalObject['XRReferenceSpaceEvent'] = XRReferenceSpaceEvent;
|
|
4940
5000
|
}
|
|
4941
|
-
|
|
4942
|
-
this[P_DEVICE].
|
|
5001
|
+
installDevUI(devUIConstructor) {
|
|
5002
|
+
this[P_DEVICE].devui = new devUIConstructor(this);
|
|
5003
|
+
}
|
|
5004
|
+
installSEM(semConstructor) {
|
|
5005
|
+
this[P_DEVICE].sem = new semConstructor(this);
|
|
4943
5006
|
}
|
|
4944
5007
|
get supportedSessionModes() {
|
|
4945
5008
|
return this[P_DEVICE].supportedSessionModes;
|
|
@@ -5046,6 +5109,21 @@ class XRDevice {
|
|
|
5046
5109
|
var _a;
|
|
5047
5110
|
return (_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM].activeSession;
|
|
5048
5111
|
}
|
|
5112
|
+
get sessionOffered() {
|
|
5113
|
+
var _a;
|
|
5114
|
+
return Boolean((_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM].offeredSessionConfig);
|
|
5115
|
+
}
|
|
5116
|
+
get name() {
|
|
5117
|
+
return this[P_DEVICE].name;
|
|
5118
|
+
}
|
|
5119
|
+
grantOfferedSession() {
|
|
5120
|
+
var _a;
|
|
5121
|
+
const pSystem = (_a = this[P_DEVICE].xrSystem) === null || _a === void 0 ? void 0 : _a[P_SYSTEM];
|
|
5122
|
+
if (pSystem && pSystem.offeredSessionConfig) {
|
|
5123
|
+
pSystem.grantSession(pSystem.offeredSessionConfig);
|
|
5124
|
+
pSystem.offeredSessionConfig = undefined;
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5049
5127
|
recenter() {
|
|
5050
5128
|
const deltaVec = new Vector3(-this.position.x, 0, -this.position.z);
|
|
5051
5129
|
const forward = new Vector3(0, 0, -1).applyQuaternion(this.quaternion);
|
|
@@ -5081,8 +5159,11 @@ class XRDevice {
|
|
|
5081
5159
|
this[P_DEVICE].actionPlayer = new ActionPlayer(refSpace, recording, this[P_DEVICE].ipd);
|
|
5082
5160
|
return this[P_DEVICE].actionPlayer;
|
|
5083
5161
|
}
|
|
5084
|
-
get
|
|
5085
|
-
return this[P_DEVICE].
|
|
5162
|
+
get devui() {
|
|
5163
|
+
return this[P_DEVICE].devui;
|
|
5164
|
+
}
|
|
5165
|
+
get sem() {
|
|
5166
|
+
return this[P_DEVICE].sem;
|
|
5086
5167
|
}
|
|
5087
5168
|
}
|
|
5088
5169
|
|